1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2016, 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;
41 with Lib.Xref; use Lib.Xref;
42 with Namet.Sp; use Namet.Sp;
43 with Nlists; use Nlists;
44 with Nmake; use Nmake;
45 with Output; use Output;
46 with Restrict; use Restrict;
47 with Rident; use Rident;
48 with Rtsfind; use Rtsfind;
50 with Sem_Aux; use Sem_Aux;
51 with Sem_Attr; use Sem_Attr;
52 with Sem_Ch6; use Sem_Ch6;
53 with Sem_Ch8; use Sem_Ch8;
54 with Sem_Disp; use Sem_Disp;
55 with Sem_Eval; use Sem_Eval;
56 with Sem_Prag; use Sem_Prag;
57 with Sem_Res; use Sem_Res;
58 with Sem_Warn; use Sem_Warn;
59 with Sem_Type; use Sem_Type;
60 with Sinfo; use Sinfo;
61 with Sinput; use Sinput;
62 with Stand; use Stand;
64 with Stringt; use Stringt;
65 with Targparm; use Targparm;
66 with Tbuild; use Tbuild;
67 with Ttypes; use Ttypes;
68 with Uname; use Uname;
70 with GNAT.HTable; use GNAT.HTable;
72 package body Sem_Util is
74 ----------------------------------------
75 -- Global Variables for New_Copy_Tree --
76 ----------------------------------------
78 -- These global variables are used by New_Copy_Tree. See description of the
79 -- body of this subprogram for details. Global variables can be safely used
80 -- by New_Copy_Tree, since there is no case of a recursive call from the
81 -- processing inside New_Copy_Tree.
83 NCT_Hash_Threshold : constant := 20;
84 -- If there are more than this number of pairs of entries in the map, then
85 -- Hash_Tables_Used will be set, and the hash tables will be initialized
86 -- and used for the searches.
88 NCT_Hash_Tables_Used : Boolean := False;
89 -- Set to True if hash tables are in use
91 NCT_Table_Entries : Nat := 0;
92 -- Count entries in table to see if threshold is reached
94 NCT_Hash_Table_Setup : Boolean := False;
95 -- Set to True if hash table contains data. We set this True if we setup
96 -- the hash table with data, and leave it set permanently from then on,
97 -- this is a signal that second and subsequent users of the hash table
98 -- must clear the old entries before reuse.
100 subtype NCT_Header_Num is Int range 0 .. 511;
101 -- Defines range of headers in hash tables (512 headers)
103 -----------------------
104 -- Local Subprograms --
105 -----------------------
107 function Build_Component_Subtype
110 T : Entity_Id) return Node_Id;
111 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
112 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
113 -- Loc is the source location, T is the original subtype.
115 function Has_Enabled_Property
116 (Item_Id : Entity_Id;
117 Property : Name_Id) return Boolean;
118 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
119 -- Determine whether an abstract state or a variable denoted by entity
120 -- Item_Id has enabled property Property.
122 function Has_Null_Extension (T : Entity_Id) return Boolean;
123 -- T is a derived tagged type. Check whether the type extension is null.
124 -- If the parent type is fully initialized, T can be treated as such.
126 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
127 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
128 -- with discriminants whose default values are static, examine only the
129 -- components in the selected variant to determine whether all of them
132 ------------------------------
133 -- Abstract_Interface_List --
134 ------------------------------
136 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
140 if Is_Concurrent_Type (Typ) then
142 -- If we are dealing with a synchronized subtype, go to the base
143 -- type, whose declaration has the interface list.
145 -- Shouldn't this be Declaration_Node???
147 Nod := Parent (Base_Type (Typ));
149 if Nkind (Nod) = N_Full_Type_Declaration then
153 elsif Ekind (Typ) = E_Record_Type_With_Private then
154 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
155 Nod := Type_Definition (Parent (Typ));
157 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
158 if Present (Full_View (Typ))
160 Nkind (Parent (Full_View (Typ))) = N_Full_Type_Declaration
162 Nod := Type_Definition (Parent (Full_View (Typ)));
164 -- If the full-view is not available we cannot do anything else
165 -- here (the source has errors).
171 -- Support for generic formals with interfaces is still missing ???
173 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
178 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
182 elsif Ekind (Typ) = E_Record_Subtype then
183 Nod := Type_Definition (Parent (Etype (Typ)));
185 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
187 -- Recurse, because parent may still be a private extension. Also
188 -- note that the full view of the subtype or the full view of its
189 -- base type may (both) be unavailable.
191 return Abstract_Interface_List (Etype (Typ));
193 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
194 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
195 Nod := Formal_Type_Definition (Parent (Typ));
197 Nod := Type_Definition (Parent (Typ));
201 return Interface_List (Nod);
202 end Abstract_Interface_List;
204 --------------------------------
205 -- Add_Access_Type_To_Process --
206 --------------------------------
208 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
212 Ensure_Freeze_Node (E);
213 L := Access_Types_To_Process (Freeze_Node (E));
217 Set_Access_Types_To_Process (Freeze_Node (E), L);
221 end Add_Access_Type_To_Process;
223 --------------------------
224 -- Add_Block_Identifier --
225 --------------------------
227 procedure Add_Block_Identifier (N : Node_Id; Id : out Entity_Id) is
228 Loc : constant Source_Ptr := Sloc (N);
231 pragma Assert (Nkind (N) = N_Block_Statement);
233 -- The block already has a label, return its entity
235 if Present (Identifier (N)) then
236 Id := Entity (Identifier (N));
238 -- Create a new block label and set its attributes
241 Id := New_Internal_Entity (E_Block, Current_Scope, Loc, 'B');
242 Set_Etype (Id, Standard_Void_Type);
245 Set_Identifier (N, New_Occurrence_Of (Id, Loc));
246 Set_Block_Node (Id, Identifier (N));
248 end Add_Block_Identifier;
250 ----------------------------
251 -- Add_Global_Declaration --
252 ----------------------------
254 procedure Add_Global_Declaration (N : Node_Id) is
255 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
258 if No (Declarations (Aux_Node)) then
259 Set_Declarations (Aux_Node, New_List);
262 Append_To (Declarations (Aux_Node), N);
264 end Add_Global_Declaration;
266 --------------------------------
267 -- Address_Integer_Convert_OK --
268 --------------------------------
270 function Address_Integer_Convert_OK (T1, T2 : Entity_Id) return Boolean is
272 if Allow_Integer_Address
273 and then ((Is_Descendant_Of_Address (T1)
274 and then Is_Private_Type (T1)
275 and then Is_Integer_Type (T2))
277 (Is_Descendant_Of_Address (T2)
278 and then Is_Private_Type (T2)
279 and then Is_Integer_Type (T1)))
285 end Address_Integer_Convert_OK;
291 function Address_Value (N : Node_Id) return Node_Id is
296 -- For constant, get constant expression
298 if Is_Entity_Name (Expr)
299 and then Ekind (Entity (Expr)) = E_Constant
301 Expr := Constant_Value (Entity (Expr));
303 -- For unchecked conversion, get result to convert
305 elsif Nkind (Expr) = N_Unchecked_Type_Conversion then
306 Expr := Expression (Expr);
308 -- For (common case) of To_Address call, get argument
310 elsif Nkind (Expr) = N_Function_Call
311 and then Is_Entity_Name (Name (Expr))
312 and then Is_RTE (Entity (Name (Expr)), RE_To_Address)
314 Expr := First (Parameter_Associations (Expr));
316 if Nkind (Expr) = N_Parameter_Association then
317 Expr := Explicit_Actual_Parameter (Expr);
320 -- We finally have the real expression
334 -- For now, just 8/16/32/64
336 function Addressable (V : Uint) return Boolean is
338 return V = Uint_8 or else
344 function Addressable (V : Int) return Boolean is
352 ---------------------------------
353 -- Aggregate_Constraint_Checks --
354 ---------------------------------
356 procedure Aggregate_Constraint_Checks
358 Check_Typ : Entity_Id)
360 Exp_Typ : constant Entity_Id := Etype (Exp);
363 if Raises_Constraint_Error (Exp) then
367 -- Ada 2005 (AI-230): Generate a conversion to an anonymous access
368 -- component's type to force the appropriate accessibility checks.
370 -- Ada 2005 (AI-231): Generate conversion to the null-excluding type to
371 -- force the corresponding run-time check
373 if Is_Access_Type (Check_Typ)
374 and then Is_Local_Anonymous_Access (Check_Typ)
376 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
377 Analyze_And_Resolve (Exp, Check_Typ);
378 Check_Unset_Reference (Exp);
381 -- What follows is really expansion activity, so check that expansion
382 -- is on and is allowed. In GNATprove mode, we also want check flags to
383 -- be added in the tree, so that the formal verification can rely on
384 -- those to be present. In GNATprove mode for formal verification, some
385 -- treatment typically only done during expansion needs to be performed
386 -- on the tree, but it should not be applied inside generics. Otherwise,
387 -- this breaks the name resolution mechanism for generic instances.
389 if not Expander_Active
390 and (Inside_A_Generic or not Full_Analysis or not GNATprove_Mode)
395 if Is_Access_Type (Check_Typ)
396 and then Can_Never_Be_Null (Check_Typ)
397 and then not Can_Never_Be_Null (Exp_Typ)
399 Install_Null_Excluding_Check (Exp);
402 -- First check if we have to insert discriminant checks
404 if Has_Discriminants (Exp_Typ) then
405 Apply_Discriminant_Check (Exp, Check_Typ);
407 -- Next emit length checks for array aggregates
409 elsif Is_Array_Type (Exp_Typ) then
410 Apply_Length_Check (Exp, Check_Typ);
412 -- Finally emit scalar and string checks. If we are dealing with a
413 -- scalar literal we need to check by hand because the Etype of
414 -- literals is not necessarily correct.
416 elsif Is_Scalar_Type (Exp_Typ)
417 and then Compile_Time_Known_Value (Exp)
419 if Is_Out_Of_Range (Exp, Base_Type (Check_Typ)) then
420 Apply_Compile_Time_Constraint_Error
421 (Exp, "value not in range of}??", CE_Range_Check_Failed,
422 Ent => Base_Type (Check_Typ),
423 Typ => Base_Type (Check_Typ));
425 elsif Is_Out_Of_Range (Exp, Check_Typ) then
426 Apply_Compile_Time_Constraint_Error
427 (Exp, "value not in range of}??", CE_Range_Check_Failed,
431 elsif not Range_Checks_Suppressed (Check_Typ) then
432 Apply_Scalar_Range_Check (Exp, Check_Typ);
435 -- Verify that target type is also scalar, to prevent view anomalies
436 -- in instantiations.
438 elsif (Is_Scalar_Type (Exp_Typ)
439 or else Nkind (Exp) = N_String_Literal)
440 and then Is_Scalar_Type (Check_Typ)
441 and then Exp_Typ /= Check_Typ
443 if Is_Entity_Name (Exp)
444 and then Ekind (Entity (Exp)) = E_Constant
446 -- If expression is a constant, it is worthwhile checking whether
447 -- it is a bound of the type.
449 if (Is_Entity_Name (Type_Low_Bound (Check_Typ))
450 and then Entity (Exp) = Entity (Type_Low_Bound (Check_Typ)))
452 (Is_Entity_Name (Type_High_Bound (Check_Typ))
453 and then Entity (Exp) = Entity (Type_High_Bound (Check_Typ)))
458 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
459 Analyze_And_Resolve (Exp, Check_Typ);
460 Check_Unset_Reference (Exp);
463 -- Could use a comment on this case ???
466 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
467 Analyze_And_Resolve (Exp, Check_Typ);
468 Check_Unset_Reference (Exp);
472 end Aggregate_Constraint_Checks;
474 -----------------------
475 -- Alignment_In_Bits --
476 -----------------------
478 function Alignment_In_Bits (E : Entity_Id) return Uint is
480 return Alignment (E) * System_Storage_Unit;
481 end Alignment_In_Bits;
483 --------------------------------------
484 -- All_Composite_Constraints_Static --
485 --------------------------------------
487 function All_Composite_Constraints_Static
488 (Constr : Node_Id) return Boolean
491 if No (Constr) or else Error_Posted (Constr) then
495 case Nkind (Constr) is
497 if Nkind (Constr) in N_Has_Entity
498 and then Present (Entity (Constr))
500 if Is_Type (Entity (Constr)) then
502 not Is_Discrete_Type (Entity (Constr))
503 or else Is_OK_Static_Subtype (Entity (Constr));
506 elsif Nkind (Constr) = N_Range then
508 Is_OK_Static_Expression (Low_Bound (Constr))
510 Is_OK_Static_Expression (High_Bound (Constr));
512 elsif Nkind (Constr) = N_Attribute_Reference
513 and then Attribute_Name (Constr) = Name_Range
516 Is_OK_Static_Expression
517 (Type_Low_Bound (Etype (Prefix (Constr))))
519 Is_OK_Static_Expression
520 (Type_High_Bound (Etype (Prefix (Constr))));
524 not Present (Etype (Constr)) -- previous error
525 or else not Is_Discrete_Type (Etype (Constr))
526 or else Is_OK_Static_Expression (Constr);
528 when N_Discriminant_Association =>
529 return All_Composite_Constraints_Static (Expression (Constr));
531 when N_Range_Constraint =>
533 All_Composite_Constraints_Static (Range_Expression (Constr));
535 when N_Index_Or_Discriminant_Constraint =>
537 One_Cstr : Entity_Id;
539 One_Cstr := First (Constraints (Constr));
540 while Present (One_Cstr) loop
541 if not All_Composite_Constraints_Static (One_Cstr) then
551 when N_Subtype_Indication =>
553 All_Composite_Constraints_Static (Subtype_Mark (Constr))
555 All_Composite_Constraints_Static (Constraint (Constr));
560 end All_Composite_Constraints_Static;
562 ---------------------------------
563 -- Append_Inherited_Subprogram --
564 ---------------------------------
566 procedure Append_Inherited_Subprogram (S : Entity_Id) is
567 Par : constant Entity_Id := Alias (S);
568 -- The parent subprogram
570 Scop : constant Entity_Id := Scope (Par);
571 -- The scope of definition of the parent subprogram
573 Typ : constant Entity_Id := Defining_Entity (Parent (S));
574 -- The derived type of which S is a primitive operation
580 if Ekind (Current_Scope) = E_Package
581 and then In_Private_Part (Current_Scope)
582 and then Has_Private_Declaration (Typ)
583 and then Is_Tagged_Type (Typ)
584 and then Scop = Current_Scope
586 -- The inherited operation is available at the earliest place after
587 -- the derived type declaration ( RM 7.3.1 (6/1)). This is only
588 -- relevant for type extensions. If the parent operation appears
589 -- after the type extension, the operation is not visible.
592 (Visible_Declarations
593 (Package_Specification (Current_Scope)));
594 while Present (Decl) loop
595 if Nkind (Decl) = N_Private_Extension_Declaration
596 and then Defining_Entity (Decl) = Typ
598 if Sloc (Decl) > Sloc (Par) then
599 Next_E := Next_Entity (Par);
600 Set_Next_Entity (Par, S);
601 Set_Next_Entity (S, Next_E);
613 -- If partial view is not a type extension, or it appears before the
614 -- subprogram declaration, insert normally at end of entity list.
616 Append_Entity (S, Current_Scope);
617 end Append_Inherited_Subprogram;
619 -----------------------------------------
620 -- Apply_Compile_Time_Constraint_Error --
621 -----------------------------------------
623 procedure Apply_Compile_Time_Constraint_Error
626 Reason : RT_Exception_Code;
627 Ent : Entity_Id := Empty;
628 Typ : Entity_Id := Empty;
629 Loc : Source_Ptr := No_Location;
630 Rep : Boolean := True;
631 Warn : Boolean := False)
633 Stat : constant Boolean := Is_Static_Expression (N);
634 R_Stat : constant Node_Id :=
635 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
646 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
648 -- In GNATprove mode, do not replace the node with an exception raised.
649 -- In such a case, either the call to Compile_Time_Constraint_Error
650 -- issues an error which stops analysis, or it issues a warning in
651 -- a few cases where a suitable check flag is set for GNATprove to
652 -- generate a check message.
654 if not Rep or GNATprove_Mode then
658 -- Now we replace the node by an N_Raise_Constraint_Error node
659 -- This does not need reanalyzing, so set it as analyzed now.
662 Set_Analyzed (N, True);
665 Set_Raises_Constraint_Error (N);
667 -- Now deal with possible local raise handling
669 Possible_Local_Raise (N, Standard_Constraint_Error);
671 -- If the original expression was marked as static, the result is
672 -- still marked as static, but the Raises_Constraint_Error flag is
673 -- always set so that further static evaluation is not attempted.
676 Set_Is_Static_Expression (N);
678 end Apply_Compile_Time_Constraint_Error;
680 ---------------------------
681 -- Async_Readers_Enabled --
682 ---------------------------
684 function Async_Readers_Enabled (Id : Entity_Id) return Boolean is
686 return Has_Enabled_Property (Id, Name_Async_Readers);
687 end Async_Readers_Enabled;
689 ---------------------------
690 -- Async_Writers_Enabled --
691 ---------------------------
693 function Async_Writers_Enabled (Id : Entity_Id) return Boolean is
695 return Has_Enabled_Property (Id, Name_Async_Writers);
696 end Async_Writers_Enabled;
698 --------------------------------------
699 -- Available_Full_View_Of_Component --
700 --------------------------------------
702 function Available_Full_View_Of_Component (T : Entity_Id) return Boolean is
703 ST : constant Entity_Id := Scope (T);
704 SCT : constant Entity_Id := Scope (Component_Type (T));
706 return In_Open_Scopes (ST)
707 and then In_Open_Scopes (SCT)
708 and then Scope_Depth (ST) >= Scope_Depth (SCT);
709 end Available_Full_View_Of_Component;
715 procedure Bad_Attribute
718 Warn : Boolean := False)
721 Error_Msg_Warn := Warn;
722 Error_Msg_N ("unrecognized attribute&<<", N);
724 -- Check for possible misspelling
726 Error_Msg_Name_1 := First_Attribute_Name;
727 while Error_Msg_Name_1 <= Last_Attribute_Name loop
728 if Is_Bad_Spelling_Of (Nam, Error_Msg_Name_1) then
729 Error_Msg_N -- CODEFIX
730 ("\possible misspelling of %<<", N);
734 Error_Msg_Name_1 := Error_Msg_Name_1 + 1;
738 --------------------------------
739 -- Bad_Predicated_Subtype_Use --
740 --------------------------------
742 procedure Bad_Predicated_Subtype_Use
746 Suggest_Static : Boolean := False)
751 -- Avoid cascaded errors
753 if Error_Posted (N) then
757 if Inside_A_Generic then
758 Gen := Current_Scope;
759 while Present (Gen) and then Ekind (Gen) /= E_Generic_Package loop
767 if Is_Generic_Formal (Typ) and then Is_Discrete_Type (Typ) then
768 Set_No_Predicate_On_Actual (Typ);
771 elsif Has_Predicates (Typ) then
772 if Is_Generic_Actual_Type (Typ) then
774 -- The restriction on loop parameters is only that the type
775 -- should have no dynamic predicates.
777 if Nkind (Parent (N)) = N_Loop_Parameter_Specification
778 and then not Has_Dynamic_Predicate_Aspect (Typ)
779 and then Is_OK_Static_Subtype (Typ)
784 Gen := Current_Scope;
785 while not Is_Generic_Instance (Gen) loop
789 pragma Assert (Present (Gen));
791 if Ekind (Gen) = E_Package and then In_Package_Body (Gen) then
792 Error_Msg_Warn := SPARK_Mode /= On;
793 Error_Msg_FE (Msg & "<<", N, Typ);
794 Error_Msg_F ("\Program_Error [<<", N);
797 Make_Raise_Program_Error (Sloc (N),
798 Reason => PE_Bad_Predicated_Generic_Type));
801 Error_Msg_FE (Msg & "<<", N, Typ);
805 Error_Msg_FE (Msg, N, Typ);
808 -- Emit an optional suggestion on how to remedy the error if the
809 -- context warrants it.
811 if Suggest_Static and then Has_Static_Predicate (Typ) then
812 Error_Msg_FE ("\predicate of & should be marked static", N, Typ);
815 end Bad_Predicated_Subtype_Use;
817 -----------------------------------------
818 -- Bad_Unordered_Enumeration_Reference --
819 -----------------------------------------
821 function Bad_Unordered_Enumeration_Reference
823 T : Entity_Id) return Boolean
826 return Is_Enumeration_Type (T)
827 and then Warn_On_Unordered_Enumeration_Type
828 and then not Is_Generic_Type (T)
829 and then Comes_From_Source (N)
830 and then not Has_Pragma_Ordered (T)
831 and then not In_Same_Extended_Unit (N, T);
832 end Bad_Unordered_Enumeration_Reference;
834 --------------------------
835 -- Build_Actual_Subtype --
836 --------------------------
838 function Build_Actual_Subtype
840 N : Node_Or_Entity_Id) return Node_Id
843 -- Normally Sloc (N), but may point to corresponding body in some cases
845 Constraints : List_Id;
851 Disc_Type : Entity_Id;
857 if Nkind (N) = N_Defining_Identifier then
858 Obj := New_Occurrence_Of (N, Loc);
860 -- If this is a formal parameter of a subprogram declaration, and
861 -- we are compiling the body, we want the declaration for the
862 -- actual subtype to carry the source position of the body, to
863 -- prevent anomalies in gdb when stepping through the code.
865 if Is_Formal (N) then
867 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
869 if Nkind (Decl) = N_Subprogram_Declaration
870 and then Present (Corresponding_Body (Decl))
872 Loc := Sloc (Corresponding_Body (Decl));
881 if Is_Array_Type (T) then
882 Constraints := New_List;
883 for J in 1 .. Number_Dimensions (T) loop
885 -- Build an array subtype declaration with the nominal subtype and
886 -- the bounds of the actual. Add the declaration in front of the
887 -- local declarations for the subprogram, for analysis before any
888 -- reference to the formal in the body.
891 Make_Attribute_Reference (Loc,
893 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
894 Attribute_Name => Name_First,
895 Expressions => New_List (
896 Make_Integer_Literal (Loc, J)));
899 Make_Attribute_Reference (Loc,
901 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
902 Attribute_Name => Name_Last,
903 Expressions => New_List (
904 Make_Integer_Literal (Loc, J)));
906 Append (Make_Range (Loc, Lo, Hi), Constraints);
909 -- If the type has unknown discriminants there is no constrained
910 -- subtype to build. This is never called for a formal or for a
911 -- lhs, so returning the type is ok ???
913 elsif Has_Unknown_Discriminants (T) then
917 Constraints := New_List;
919 -- Type T is a generic derived type, inherit the discriminants from
922 if Is_Private_Type (T)
923 and then No (Full_View (T))
925 -- T was flagged as an error if it was declared as a formal
926 -- derived type with known discriminants. In this case there
927 -- is no need to look at the parent type since T already carries
928 -- its own discriminants.
930 and then not Error_Posted (T)
932 Disc_Type := Etype (Base_Type (T));
937 Discr := First_Discriminant (Disc_Type);
938 while Present (Discr) loop
939 Append_To (Constraints,
940 Make_Selected_Component (Loc,
942 Duplicate_Subexpr_No_Checks (Obj),
943 Selector_Name => New_Occurrence_Of (Discr, Loc)));
944 Next_Discriminant (Discr);
948 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
949 Set_Is_Internal (Subt);
952 Make_Subtype_Declaration (Loc,
953 Defining_Identifier => Subt,
954 Subtype_Indication =>
955 Make_Subtype_Indication (Loc,
956 Subtype_Mark => New_Occurrence_Of (T, Loc),
958 Make_Index_Or_Discriminant_Constraint (Loc,
959 Constraints => Constraints)));
961 Mark_Rewrite_Insertion (Decl);
963 end Build_Actual_Subtype;
965 ---------------------------------------
966 -- Build_Actual_Subtype_Of_Component --
967 ---------------------------------------
969 function Build_Actual_Subtype_Of_Component
971 N : Node_Id) return Node_Id
973 Loc : constant Source_Ptr := Sloc (N);
974 P : constant Node_Id := Prefix (N);
977 Index_Typ : Entity_Id;
979 Desig_Typ : Entity_Id;
980 -- This is either a copy of T, or if T is an access type, then it is
981 -- the directly designated type of this access type.
983 function Build_Actual_Array_Constraint return List_Id;
984 -- If one or more of the bounds of the component depends on
985 -- discriminants, build actual constraint using the discriminants
988 function Build_Actual_Record_Constraint return List_Id;
989 -- Similar to previous one, for discriminated components constrained
990 -- by the discriminant of the enclosing object.
992 -----------------------------------
993 -- Build_Actual_Array_Constraint --
994 -----------------------------------
996 function Build_Actual_Array_Constraint return List_Id is
997 Constraints : constant List_Id := New_List;
1005 Indx := First_Index (Desig_Typ);
1006 while Present (Indx) loop
1007 Old_Lo := Type_Low_Bound (Etype (Indx));
1008 Old_Hi := Type_High_Bound (Etype (Indx));
1010 if Denotes_Discriminant (Old_Lo) then
1012 Make_Selected_Component (Loc,
1013 Prefix => New_Copy_Tree (P),
1014 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
1017 Lo := New_Copy_Tree (Old_Lo);
1019 -- The new bound will be reanalyzed in the enclosing
1020 -- declaration. For literal bounds that come from a type
1021 -- declaration, the type of the context must be imposed, so
1022 -- insure that analysis will take place. For non-universal
1023 -- types this is not strictly necessary.
1025 Set_Analyzed (Lo, False);
1028 if Denotes_Discriminant (Old_Hi) then
1030 Make_Selected_Component (Loc,
1031 Prefix => New_Copy_Tree (P),
1032 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
1035 Hi := New_Copy_Tree (Old_Hi);
1036 Set_Analyzed (Hi, False);
1039 Append (Make_Range (Loc, Lo, Hi), Constraints);
1044 end Build_Actual_Array_Constraint;
1046 ------------------------------------
1047 -- Build_Actual_Record_Constraint --
1048 ------------------------------------
1050 function Build_Actual_Record_Constraint return List_Id is
1051 Constraints : constant List_Id := New_List;
1056 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1057 while Present (D) loop
1058 if Denotes_Discriminant (Node (D)) then
1059 D_Val := Make_Selected_Component (Loc,
1060 Prefix => New_Copy_Tree (P),
1061 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
1064 D_Val := New_Copy_Tree (Node (D));
1067 Append (D_Val, Constraints);
1072 end Build_Actual_Record_Constraint;
1074 -- Start of processing for Build_Actual_Subtype_Of_Component
1077 -- Why the test for Spec_Expression mode here???
1079 if In_Spec_Expression then
1082 -- More comments for the rest of this body would be good ???
1084 elsif Nkind (N) = N_Explicit_Dereference then
1085 if Is_Composite_Type (T)
1086 and then not Is_Constrained (T)
1087 and then not (Is_Class_Wide_Type (T)
1088 and then Is_Constrained (Root_Type (T)))
1089 and then not Has_Unknown_Discriminants (T)
1091 -- If the type of the dereference is already constrained, it is an
1094 if Is_Array_Type (Etype (N))
1095 and then Is_Constrained (Etype (N))
1099 Remove_Side_Effects (P);
1100 return Build_Actual_Subtype (T, N);
1107 if Ekind (T) = E_Access_Subtype then
1108 Desig_Typ := Designated_Type (T);
1113 if Ekind (Desig_Typ) = E_Array_Subtype then
1114 Id := First_Index (Desig_Typ);
1115 while Present (Id) loop
1116 Index_Typ := Underlying_Type (Etype (Id));
1118 if Denotes_Discriminant (Type_Low_Bound (Index_Typ))
1120 Denotes_Discriminant (Type_High_Bound (Index_Typ))
1122 Remove_Side_Effects (P);
1124 Build_Component_Subtype
1125 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
1131 elsif Is_Composite_Type (Desig_Typ)
1132 and then Has_Discriminants (Desig_Typ)
1133 and then not Has_Unknown_Discriminants (Desig_Typ)
1135 if Is_Private_Type (Desig_Typ)
1136 and then No (Discriminant_Constraint (Desig_Typ))
1138 Desig_Typ := Full_View (Desig_Typ);
1141 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1142 while Present (D) loop
1143 if Denotes_Discriminant (Node (D)) then
1144 Remove_Side_Effects (P);
1146 Build_Component_Subtype (
1147 Build_Actual_Record_Constraint, Loc, Base_Type (T));
1154 -- If none of the above, the actual and nominal subtypes are the same
1157 end Build_Actual_Subtype_Of_Component;
1159 -----------------------------
1160 -- Build_Component_Subtype --
1161 -----------------------------
1163 function Build_Component_Subtype
1166 T : Entity_Id) return Node_Id
1172 -- Unchecked_Union components do not require component subtypes
1174 if Is_Unchecked_Union (T) then
1178 Subt := Make_Temporary (Loc, 'S');
1179 Set_Is_Internal (Subt);
1182 Make_Subtype_Declaration (Loc,
1183 Defining_Identifier => Subt,
1184 Subtype_Indication =>
1185 Make_Subtype_Indication (Loc,
1186 Subtype_Mark => New_Occurrence_Of (Base_Type (T), Loc),
1188 Make_Index_Or_Discriminant_Constraint (Loc,
1189 Constraints => C)));
1191 Mark_Rewrite_Insertion (Decl);
1193 end Build_Component_Subtype;
1195 ---------------------------
1196 -- Build_Default_Subtype --
1197 ---------------------------
1199 function Build_Default_Subtype
1201 N : Node_Id) return Entity_Id
1203 Loc : constant Source_Ptr := Sloc (N);
1207 -- The base type that is to be constrained by the defaults
1210 if not Has_Discriminants (T) or else Is_Constrained (T) then
1214 Bas := Base_Type (T);
1216 -- If T is non-private but its base type is private, this is the
1217 -- completion of a subtype declaration whose parent type is private
1218 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1219 -- are to be found in the full view of the base. Check that the private
1220 -- status of T and its base differ.
1222 if Is_Private_Type (Bas)
1223 and then not Is_Private_Type (T)
1224 and then Present (Full_View (Bas))
1226 Bas := Full_View (Bas);
1229 Disc := First_Discriminant (T);
1231 if No (Discriminant_Default_Value (Disc)) then
1236 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
1237 Constraints : constant List_Id := New_List;
1241 while Present (Disc) loop
1242 Append_To (Constraints,
1243 New_Copy_Tree (Discriminant_Default_Value (Disc)));
1244 Next_Discriminant (Disc);
1248 Make_Subtype_Declaration (Loc,
1249 Defining_Identifier => Act,
1250 Subtype_Indication =>
1251 Make_Subtype_Indication (Loc,
1252 Subtype_Mark => New_Occurrence_Of (Bas, Loc),
1254 Make_Index_Or_Discriminant_Constraint (Loc,
1255 Constraints => Constraints)));
1257 Insert_Action (N, Decl);
1259 -- If the context is a component declaration the subtype declaration
1260 -- will be analyzed when the enclosing type is frozen, otherwise do
1263 if Ekind (Current_Scope) /= E_Record_Type then
1269 end Build_Default_Subtype;
1271 --------------------------------------------
1272 -- Build_Discriminal_Subtype_Of_Component --
1273 --------------------------------------------
1275 function Build_Discriminal_Subtype_Of_Component
1276 (T : Entity_Id) return Node_Id
1278 Loc : constant Source_Ptr := Sloc (T);
1282 function Build_Discriminal_Array_Constraint return List_Id;
1283 -- If one or more of the bounds of the component depends on
1284 -- discriminants, build actual constraint using the discriminants
1287 function Build_Discriminal_Record_Constraint return List_Id;
1288 -- Similar to previous one, for discriminated components constrained by
1289 -- the discriminant of the enclosing object.
1291 ----------------------------------------
1292 -- Build_Discriminal_Array_Constraint --
1293 ----------------------------------------
1295 function Build_Discriminal_Array_Constraint return List_Id is
1296 Constraints : constant List_Id := New_List;
1304 Indx := First_Index (T);
1305 while Present (Indx) loop
1306 Old_Lo := Type_Low_Bound (Etype (Indx));
1307 Old_Hi := Type_High_Bound (Etype (Indx));
1309 if Denotes_Discriminant (Old_Lo) then
1310 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
1313 Lo := New_Copy_Tree (Old_Lo);
1316 if Denotes_Discriminant (Old_Hi) then
1317 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
1320 Hi := New_Copy_Tree (Old_Hi);
1323 Append (Make_Range (Loc, Lo, Hi), Constraints);
1328 end Build_Discriminal_Array_Constraint;
1330 -----------------------------------------
1331 -- Build_Discriminal_Record_Constraint --
1332 -----------------------------------------
1334 function Build_Discriminal_Record_Constraint return List_Id is
1335 Constraints : constant List_Id := New_List;
1340 D := First_Elmt (Discriminant_Constraint (T));
1341 while Present (D) loop
1342 if Denotes_Discriminant (Node (D)) then
1344 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
1346 D_Val := New_Copy_Tree (Node (D));
1349 Append (D_Val, Constraints);
1354 end Build_Discriminal_Record_Constraint;
1356 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1359 if Ekind (T) = E_Array_Subtype then
1360 Id := First_Index (T);
1361 while Present (Id) loop
1362 if Denotes_Discriminant (Type_Low_Bound (Etype (Id)))
1364 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
1366 return Build_Component_Subtype
1367 (Build_Discriminal_Array_Constraint, Loc, T);
1373 elsif Ekind (T) = E_Record_Subtype
1374 and then Has_Discriminants (T)
1375 and then not Has_Unknown_Discriminants (T)
1377 D := First_Elmt (Discriminant_Constraint (T));
1378 while Present (D) loop
1379 if Denotes_Discriminant (Node (D)) then
1380 return Build_Component_Subtype
1381 (Build_Discriminal_Record_Constraint, Loc, T);
1388 -- If none of the above, the actual and nominal subtypes are the same
1391 end Build_Discriminal_Subtype_Of_Component;
1393 ------------------------------
1394 -- Build_Elaboration_Entity --
1395 ------------------------------
1397 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
1398 Loc : constant Source_Ptr := Sloc (N);
1400 Elab_Ent : Entity_Id;
1402 procedure Set_Package_Name (Ent : Entity_Id);
1403 -- Given an entity, sets the fully qualified name of the entity in
1404 -- Name_Buffer, with components separated by double underscores. This
1405 -- is a recursive routine that climbs the scope chain to Standard.
1407 ----------------------
1408 -- Set_Package_Name --
1409 ----------------------
1411 procedure Set_Package_Name (Ent : Entity_Id) is
1413 if Scope (Ent) /= Standard_Standard then
1414 Set_Package_Name (Scope (Ent));
1417 Nam : constant String := Get_Name_String (Chars (Ent));
1419 Name_Buffer (Name_Len + 1) := '_';
1420 Name_Buffer (Name_Len + 2) := '_';
1421 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
1422 Name_Len := Name_Len + Nam'Length + 2;
1426 Get_Name_String (Chars (Ent));
1428 end Set_Package_Name;
1430 -- Start of processing for Build_Elaboration_Entity
1433 -- Ignore call if already constructed
1435 if Present (Elaboration_Entity (Spec_Id)) then
1438 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1439 -- no role in analysis.
1441 elsif ASIS_Mode then
1444 -- See if we need elaboration entity.
1446 -- We always need an elaboration entity when preserving control flow, as
1447 -- we want to remain explicit about the unit's elaboration order.
1449 elsif Opt.Suppress_Control_Flow_Optimizations then
1452 -- We always need an elaboration entity for the dynamic elaboration
1453 -- model, since it is needed to properly generate the PE exception for
1454 -- access before elaboration.
1456 elsif Dynamic_Elaboration_Checks then
1459 -- For the static model, we don't need the elaboration counter if this
1460 -- unit is sure to have no elaboration code, since that means there
1461 -- is no elaboration unit to be called. Note that we can't just decide
1462 -- after the fact by looking to see whether there was elaboration code,
1463 -- because that's too late to make this decision.
1465 elsif Restriction_Active (No_Elaboration_Code) then
1468 -- Similarly, for the static model, we can skip the elaboration counter
1469 -- if we have the No_Multiple_Elaboration restriction, since for the
1470 -- static model, that's the only purpose of the counter (to avoid
1471 -- multiple elaboration).
1473 elsif Restriction_Active (No_Multiple_Elaboration) then
1477 -- Here we need the elaboration entity
1479 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1480 -- name with dots replaced by double underscore. We have to manually
1481 -- construct this name, since it will be elaborated in the outer scope,
1482 -- and thus will not have the unit name automatically prepended.
1484 Set_Package_Name (Spec_Id);
1485 Add_Str_To_Name_Buffer ("_E");
1487 -- Create elaboration counter
1489 Elab_Ent := Make_Defining_Identifier (Loc, Chars => Name_Find);
1490 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
1493 Make_Object_Declaration (Loc,
1494 Defining_Identifier => Elab_Ent,
1495 Object_Definition =>
1496 New_Occurrence_Of (Standard_Short_Integer, Loc),
1497 Expression => Make_Integer_Literal (Loc, Uint_0));
1499 Push_Scope (Standard_Standard);
1500 Add_Global_Declaration (Decl);
1503 -- Reset True_Constant indication, since we will indeed assign a value
1504 -- to the variable in the binder main. We also kill the Current_Value
1505 -- and Last_Assignment fields for the same reason.
1507 Set_Is_True_Constant (Elab_Ent, False);
1508 Set_Current_Value (Elab_Ent, Empty);
1509 Set_Last_Assignment (Elab_Ent, Empty);
1511 -- We do not want any further qualification of the name (if we did not
1512 -- do this, we would pick up the name of the generic package in the case
1513 -- of a library level generic instantiation).
1515 Set_Has_Qualified_Name (Elab_Ent);
1516 Set_Has_Fully_Qualified_Name (Elab_Ent);
1517 end Build_Elaboration_Entity;
1519 --------------------------------
1520 -- Build_Explicit_Dereference --
1521 --------------------------------
1523 procedure Build_Explicit_Dereference
1527 Loc : constant Source_Ptr := Sloc (Expr);
1532 -- An entity of a type with a reference aspect is overloaded with
1533 -- both interpretations: with and without the dereference. Now that
1534 -- the dereference is made explicit, set the type of the node properly,
1535 -- to prevent anomalies in the backend. Same if the expression is an
1536 -- overloaded function call whose return type has a reference aspect.
1538 if Is_Entity_Name (Expr) then
1539 Set_Etype (Expr, Etype (Entity (Expr)));
1541 -- The designated entity will not be examined again when resolving
1542 -- the dereference, so generate a reference to it now.
1544 Generate_Reference (Entity (Expr), Expr);
1546 elsif Nkind (Expr) = N_Function_Call then
1548 -- If the name of the indexing function is overloaded, locate the one
1549 -- whose return type has an implicit dereference on the desired
1550 -- discriminant, and set entity and type of function call.
1552 if Is_Overloaded (Name (Expr)) then
1553 Get_First_Interp (Name (Expr), I, It);
1555 while Present (It.Nam) loop
1556 if Ekind ((It.Typ)) = E_Record_Type
1557 and then First_Entity ((It.Typ)) = Disc
1559 Set_Entity (Name (Expr), It.Nam);
1560 Set_Etype (Name (Expr), Etype (It.Nam));
1564 Get_Next_Interp (I, It);
1568 -- Set type of call from resolved function name.
1570 Set_Etype (Expr, Etype (Name (Expr)));
1573 Set_Is_Overloaded (Expr, False);
1575 -- The expression will often be a generalized indexing that yields a
1576 -- container element that is then dereferenced, in which case the
1577 -- generalized indexing call is also non-overloaded.
1579 if Nkind (Expr) = N_Indexed_Component
1580 and then Present (Generalized_Indexing (Expr))
1582 Set_Is_Overloaded (Generalized_Indexing (Expr), False);
1586 Make_Explicit_Dereference (Loc,
1588 Make_Selected_Component (Loc,
1589 Prefix => Relocate_Node (Expr),
1590 Selector_Name => New_Occurrence_Of (Disc, Loc))));
1591 Set_Etype (Prefix (Expr), Etype (Disc));
1592 Set_Etype (Expr, Designated_Type (Etype (Disc)));
1593 end Build_Explicit_Dereference;
1595 -----------------------------------
1596 -- Cannot_Raise_Constraint_Error --
1597 -----------------------------------
1599 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
1601 if Compile_Time_Known_Value (Expr) then
1604 elsif Do_Range_Check (Expr) then
1607 elsif Raises_Constraint_Error (Expr) then
1611 case Nkind (Expr) is
1612 when N_Identifier =>
1615 when N_Expanded_Name =>
1618 when N_Selected_Component =>
1619 return not Do_Discriminant_Check (Expr);
1621 when N_Attribute_Reference =>
1622 if Do_Overflow_Check (Expr) then
1625 elsif No (Expressions (Expr)) then
1633 N := First (Expressions (Expr));
1634 while Present (N) loop
1635 if Cannot_Raise_Constraint_Error (N) then
1646 when N_Type_Conversion =>
1647 if Do_Overflow_Check (Expr)
1648 or else Do_Length_Check (Expr)
1649 or else Do_Tag_Check (Expr)
1653 return Cannot_Raise_Constraint_Error (Expression (Expr));
1656 when N_Unchecked_Type_Conversion =>
1657 return Cannot_Raise_Constraint_Error (Expression (Expr));
1660 if Do_Overflow_Check (Expr) then
1663 return Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1670 if Do_Division_Check (Expr)
1672 Do_Overflow_Check (Expr)
1677 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1679 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1698 N_Op_Shift_Right_Arithmetic |
1702 if Do_Overflow_Check (Expr) then
1706 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1708 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1715 end Cannot_Raise_Constraint_Error;
1717 -----------------------------
1718 -- Check_Part_Of_Reference --
1719 -----------------------------
1721 procedure Check_Part_Of_Reference (Var_Id : Entity_Id; Ref : Node_Id) is
1722 Conc_Typ : constant Entity_Id := Encapsulating_State (Var_Id);
1724 OK_Use : Boolean := False;
1727 Spec_Id : Entity_Id;
1730 -- Traverse the parent chain looking for a suitable context for the
1731 -- reference to the concurrent constituent.
1733 Par := Parent (Ref);
1734 while Present (Par) loop
1735 if Nkind (Par) = N_Pragma then
1736 Prag_Nam := Pragma_Name (Par);
1738 -- A concurrent constituent is allowed to appear in pragmas
1739 -- Initial_Condition and Initializes as this is part of the
1740 -- elaboration checks for the constituent (SPARK RM 9.3).
1742 if Nam_In (Prag_Nam, Name_Initial_Condition, Name_Initializes) then
1746 -- When the reference appears within pragma Depends or Global,
1747 -- check whether the pragma applies to a single task type. Note
1748 -- that the pragma is not encapsulated by the type definition,
1749 -- but this is still a valid context.
1751 elsif Nam_In (Prag_Nam, Name_Depends, Name_Global) then
1752 Decl := Find_Related_Declaration_Or_Body (Par);
1754 if Nkind (Decl) = N_Object_Declaration
1755 and then Defining_Entity (Decl) = Conc_Typ
1762 -- The reference appears somewhere in the definition of the single
1763 -- protected/task type (SPARK RM 9.3).
1765 elsif Nkind_In (Par, N_Single_Protected_Declaration,
1766 N_Single_Task_Declaration)
1767 and then Defining_Entity (Par) = Conc_Typ
1772 -- The reference appears within the expanded declaration or the body
1773 -- of the single protected/task type (SPARK RM 9.3).
1775 elsif Nkind_In (Par, N_Protected_Body,
1776 N_Protected_Type_Declaration,
1778 N_Task_Type_Declaration)
1780 Spec_Id := Unique_Defining_Entity (Par);
1782 if Present (Anonymous_Object (Spec_Id))
1783 and then Anonymous_Object (Spec_Id) = Conc_Typ
1789 -- The reference has been relocated within an internally generated
1790 -- package or subprogram. Assume that the reference is legal as the
1791 -- real check was already performed in the original context of the
1794 elsif Nkind_In (Par, N_Package_Body,
1795 N_Package_Declaration,
1797 N_Subprogram_Declaration)
1798 and then not Comes_From_Source (Par)
1803 -- The reference has been relocated to an inlined body for GNATprove.
1804 -- Assume that the reference is legal as the real check was already
1805 -- performed in the original context of the reference.
1807 elsif GNATprove_Mode
1808 and then Nkind (Par) = N_Subprogram_Body
1809 and then Chars (Defining_Entity (Par)) = Name_uParent
1815 Par := Parent (Par);
1818 -- The reference is illegal as it appears outside the definition or
1819 -- body of the single protected/task type.
1823 ("reference to variable & cannot appear in this context",
1825 Error_Msg_Name_1 := Chars (Var_Id);
1827 if Ekind (Conc_Typ) = E_Protected_Type then
1829 ("\% is constituent of single protected type &", Ref, Conc_Typ);
1832 ("\% is constituent of single task type &", Ref, Conc_Typ);
1835 end Check_Part_Of_Reference;
1837 -----------------------------------------
1838 -- Check_Dynamically_Tagged_Expression --
1839 -----------------------------------------
1841 procedure Check_Dynamically_Tagged_Expression
1844 Related_Nod : Node_Id)
1847 pragma Assert (Is_Tagged_Type (Typ));
1849 -- In order to avoid spurious errors when analyzing the expanded code,
1850 -- this check is done only for nodes that come from source and for
1851 -- actuals of generic instantiations.
1853 if (Comes_From_Source (Related_Nod)
1854 or else In_Generic_Actual (Expr))
1855 and then (Is_Class_Wide_Type (Etype (Expr))
1856 or else Is_Dynamically_Tagged (Expr))
1857 and then Is_Tagged_Type (Typ)
1858 and then not Is_Class_Wide_Type (Typ)
1860 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
1862 end Check_Dynamically_Tagged_Expression;
1864 --------------------------
1865 -- Check_Fully_Declared --
1866 --------------------------
1868 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
1870 if Ekind (T) = E_Incomplete_Type then
1872 -- Ada 2005 (AI-50217): If the type is available through a limited
1873 -- with_clause, verify that its full view has been analyzed.
1875 if From_Limited_With (T)
1876 and then Present (Non_Limited_View (T))
1877 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1879 -- The non-limited view is fully declared
1885 ("premature usage of incomplete}", N, First_Subtype (T));
1888 -- Need comments for these tests ???
1890 elsif Has_Private_Component (T)
1891 and then not Is_Generic_Type (Root_Type (T))
1892 and then not In_Spec_Expression
1894 -- Special case: if T is the anonymous type created for a single
1895 -- task or protected object, use the name of the source object.
1897 if Is_Concurrent_Type (T)
1898 and then not Comes_From_Source (T)
1899 and then Nkind (N) = N_Object_Declaration
1902 ("type of& has incomplete component",
1903 N, Defining_Identifier (N));
1906 ("premature usage of incomplete}",
1907 N, First_Subtype (T));
1910 end Check_Fully_Declared;
1912 -------------------------------------------
1913 -- Check_Function_With_Address_Parameter --
1914 -------------------------------------------
1916 procedure Check_Function_With_Address_Parameter (Subp_Id : Entity_Id) is
1921 F := First_Formal (Subp_Id);
1922 while Present (F) loop
1925 if Is_Private_Type (T) and then Present (Full_View (T)) then
1929 if Is_Descendant_Of_Address (T) or else Is_Limited_Type (T) then
1930 Set_Is_Pure (Subp_Id, False);
1936 end Check_Function_With_Address_Parameter;
1938 -------------------------------------
1939 -- Check_Function_Writable_Actuals --
1940 -------------------------------------
1942 procedure Check_Function_Writable_Actuals (N : Node_Id) is
1943 Writable_Actuals_List : Elist_Id := No_Elist;
1944 Identifiers_List : Elist_Id := No_Elist;
1945 Aggr_Error_Node : Node_Id := Empty;
1946 Error_Node : Node_Id := Empty;
1948 procedure Collect_Identifiers (N : Node_Id);
1949 -- In a single traversal of subtree N collect in Writable_Actuals_List
1950 -- all the actuals of functions with writable actuals, and in the list
1951 -- Identifiers_List collect all the identifiers that are not actuals of
1952 -- functions with writable actuals. If a writable actual is referenced
1953 -- twice as writable actual then Error_Node is set to reference its
1954 -- second occurrence, the error is reported, and the tree traversal
1957 function Get_Function_Id (Call : Node_Id) return Entity_Id;
1958 -- Return the entity associated with the function call
1960 procedure Preanalyze_Without_Errors (N : Node_Id);
1961 -- Preanalyze N without reporting errors. Very dubious, you can't just
1962 -- go analyzing things more than once???
1964 -------------------------
1965 -- Collect_Identifiers --
1966 -------------------------
1968 procedure Collect_Identifiers (N : Node_Id) is
1970 function Check_Node (N : Node_Id) return Traverse_Result;
1971 -- Process a single node during the tree traversal to collect the
1972 -- writable actuals of functions and all the identifiers which are
1973 -- not writable actuals of functions.
1975 function Contains (List : Elist_Id; N : Node_Id) return Boolean;
1976 -- Returns True if List has a node whose Entity is Entity (N)
1978 -------------------------
1979 -- Check_Function_Call --
1980 -------------------------
1982 function Check_Node (N : Node_Id) return Traverse_Result is
1983 Is_Writable_Actual : Boolean := False;
1987 if Nkind (N) = N_Identifier then
1989 -- No analysis possible if the entity is not decorated
1991 if No (Entity (N)) then
1994 -- Don't collect identifiers of packages, called functions, etc
1996 elsif Ekind_In (Entity (N), E_Package,
2003 -- For rewritten nodes, continue the traversal in the original
2004 -- subtree. Needed to handle aggregates in original expressions
2005 -- extracted from the tree by Remove_Side_Effects.
2007 elsif Is_Rewrite_Substitution (N) then
2008 Collect_Identifiers (Original_Node (N));
2011 -- For now we skip aggregate discriminants, since they require
2012 -- performing the analysis in two phases to identify conflicts:
2013 -- first one analyzing discriminants and second one analyzing
2014 -- the rest of components (since at run time, discriminants are
2015 -- evaluated prior to components): too much computation cost
2016 -- to identify a corner case???
2018 elsif Nkind (Parent (N)) = N_Component_Association
2019 and then Nkind_In (Parent (Parent (N)),
2021 N_Extension_Aggregate)
2024 Choice : constant Node_Id := First (Choices (Parent (N)));
2027 if Ekind (Entity (N)) = E_Discriminant then
2030 elsif Expression (Parent (N)) = N
2031 and then Nkind (Choice) = N_Identifier
2032 and then Ekind (Entity (Choice)) = E_Discriminant
2038 -- Analyze if N is a writable actual of a function
2040 elsif Nkind (Parent (N)) = N_Function_Call then
2042 Call : constant Node_Id := Parent (N);
2047 Id := Get_Function_Id (Call);
2049 -- In case of previous error, no check is possible
2055 if Ekind_In (Id, E_Function, E_Generic_Function)
2056 and then Has_Out_Or_In_Out_Parameter (Id)
2058 Formal := First_Formal (Id);
2059 Actual := First_Actual (Call);
2060 while Present (Actual) and then Present (Formal) loop
2062 if Ekind_In (Formal, E_Out_Parameter,
2065 Is_Writable_Actual := True;
2071 Next_Formal (Formal);
2072 Next_Actual (Actual);
2078 if Is_Writable_Actual then
2080 -- Skip checking the error in non-elementary types since
2081 -- RM 6.4.1(6.15/3) is restricted to elementary types, but
2082 -- store this actual in Writable_Actuals_List since it is
2083 -- needed to perform checks on other constructs that have
2084 -- arbitrary order of evaluation (for example, aggregates).
2086 if not Is_Elementary_Type (Etype (N)) then
2087 if not Contains (Writable_Actuals_List, N) then
2088 Append_New_Elmt (N, To => Writable_Actuals_List);
2091 -- Second occurrence of an elementary type writable actual
2093 elsif Contains (Writable_Actuals_List, N) then
2095 -- Report the error on the second occurrence of the
2096 -- identifier. We cannot assume that N is the second
2097 -- occurrence (according to their location in the
2098 -- sources), since Traverse_Func walks through Field2
2099 -- last (see comment in the body of Traverse_Func).
2105 Elmt := First_Elmt (Writable_Actuals_List);
2106 while Present (Elmt)
2107 and then Entity (Node (Elmt)) /= Entity (N)
2112 if Sloc (N) > Sloc (Node (Elmt)) then
2115 Error_Node := Node (Elmt);
2119 ("value may be affected by call to & "
2120 & "because order of evaluation is arbitrary",
2125 -- First occurrence of a elementary type writable actual
2128 Append_New_Elmt (N, To => Writable_Actuals_List);
2132 if Identifiers_List = No_Elist then
2133 Identifiers_List := New_Elmt_List;
2136 Append_Unique_Elmt (N, Identifiers_List);
2149 N : Node_Id) return Boolean
2151 pragma Assert (Nkind (N) in N_Has_Entity);
2156 if List = No_Elist then
2160 Elmt := First_Elmt (List);
2161 while Present (Elmt) loop
2162 if Entity (Node (Elmt)) = Entity (N) then
2176 procedure Do_Traversal is new Traverse_Proc (Check_Node);
2177 -- The traversal procedure
2179 -- Start of processing for Collect_Identifiers
2182 if Present (Error_Node) then
2186 if Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
2191 end Collect_Identifiers;
2193 ---------------------
2194 -- Get_Function_Id --
2195 ---------------------
2197 function Get_Function_Id (Call : Node_Id) return Entity_Id is
2198 Nam : constant Node_Id := Name (Call);
2202 if Nkind (Nam) = N_Explicit_Dereference then
2204 pragma Assert (Ekind (Id) = E_Subprogram_Type);
2206 elsif Nkind (Nam) = N_Selected_Component then
2207 Id := Entity (Selector_Name (Nam));
2209 elsif Nkind (Nam) = N_Indexed_Component then
2210 Id := Entity (Selector_Name (Prefix (Nam)));
2217 end Get_Function_Id;
2219 -------------------------------
2220 -- Preanalyze_Without_Errors --
2221 -------------------------------
2223 procedure Preanalyze_Without_Errors (N : Node_Id) is
2224 Status : constant Boolean := Get_Ignore_Errors;
2226 Set_Ignore_Errors (True);
2228 Set_Ignore_Errors (Status);
2229 end Preanalyze_Without_Errors;
2231 -- Start of processing for Check_Function_Writable_Actuals
2234 -- The check only applies to Ada 2012 code on which Check_Actuals has
2235 -- been set, and only to constructs that have multiple constituents
2236 -- whose order of evaluation is not specified by the language.
2238 if Ada_Version < Ada_2012
2239 or else not Check_Actuals (N)
2240 or else (not (Nkind (N) in N_Op)
2241 and then not (Nkind (N) in N_Membership_Test)
2242 and then not Nkind_In (N, N_Range,
2244 N_Extension_Aggregate,
2245 N_Full_Type_Declaration,
2247 N_Procedure_Call_Statement,
2248 N_Entry_Call_Statement))
2249 or else (Nkind (N) = N_Full_Type_Declaration
2250 and then not Is_Record_Type (Defining_Identifier (N)))
2252 -- In addition, this check only applies to source code, not to code
2253 -- generated by constraint checks.
2255 or else not Comes_From_Source (N)
2260 -- If a construct C has two or more direct constituents that are names
2261 -- or expressions whose evaluation may occur in an arbitrary order, at
2262 -- least one of which contains a function call with an in out or out
2263 -- parameter, then the construct is legal only if: for each name N that
2264 -- is passed as a parameter of mode in out or out to some inner function
2265 -- call C2 (not including the construct C itself), there is no other
2266 -- name anywhere within a direct constituent of the construct C other
2267 -- than the one containing C2, that is known to refer to the same
2268 -- object (RM 6.4.1(6.17/3)).
2272 Collect_Identifiers (Low_Bound (N));
2273 Collect_Identifiers (High_Bound (N));
2275 when N_Op | N_Membership_Test =>
2280 Collect_Identifiers (Left_Opnd (N));
2282 if Present (Right_Opnd (N)) then
2283 Collect_Identifiers (Right_Opnd (N));
2286 if Nkind_In (N, N_In, N_Not_In)
2287 and then Present (Alternatives (N))
2289 Expr := First (Alternatives (N));
2290 while Present (Expr) loop
2291 Collect_Identifiers (Expr);
2298 when N_Full_Type_Declaration =>
2300 function Get_Record_Part (N : Node_Id) return Node_Id;
2301 -- Return the record part of this record type definition
2303 function Get_Record_Part (N : Node_Id) return Node_Id is
2304 Type_Def : constant Node_Id := Type_Definition (N);
2306 if Nkind (Type_Def) = N_Derived_Type_Definition then
2307 return Record_Extension_Part (Type_Def);
2311 end Get_Record_Part;
2314 Def_Id : Entity_Id := Defining_Identifier (N);
2315 Rec : Node_Id := Get_Record_Part (N);
2318 -- No need to perform any analysis if the record has no
2321 if No (Rec) or else No (Component_List (Rec)) then
2325 -- Collect the identifiers starting from the deepest
2326 -- derivation. Done to report the error in the deepest
2330 if Present (Component_List (Rec)) then
2331 Comp := First (Component_Items (Component_List (Rec)));
2332 while Present (Comp) loop
2333 if Nkind (Comp) = N_Component_Declaration
2334 and then Present (Expression (Comp))
2336 Collect_Identifiers (Expression (Comp));
2343 exit when No (Underlying_Type (Etype (Def_Id)))
2344 or else Base_Type (Underlying_Type (Etype (Def_Id)))
2347 Def_Id := Base_Type (Underlying_Type (Etype (Def_Id)));
2348 Rec := Get_Record_Part (Parent (Def_Id));
2352 when N_Subprogram_Call |
2353 N_Entry_Call_Statement =>
2355 Id : constant Entity_Id := Get_Function_Id (N);
2360 Formal := First_Formal (Id);
2361 Actual := First_Actual (N);
2362 while Present (Actual) and then Present (Formal) loop
2363 if Ekind_In (Formal, E_Out_Parameter,
2366 Collect_Identifiers (Actual);
2369 Next_Formal (Formal);
2370 Next_Actual (Actual);
2375 N_Extension_Aggregate =>
2379 Comp_Expr : Node_Id;
2382 -- Handle the N_Others_Choice of array aggregates with static
2383 -- bounds. There is no need to perform this analysis in
2384 -- aggregates without static bounds since we cannot evaluate
2385 -- if the N_Others_Choice covers several elements. There is
2386 -- no need to handle the N_Others choice of record aggregates
2387 -- since at this stage it has been already expanded by
2388 -- Resolve_Record_Aggregate.
2390 if Is_Array_Type (Etype (N))
2391 and then Nkind (N) = N_Aggregate
2392 and then Present (Aggregate_Bounds (N))
2393 and then Compile_Time_Known_Bounds (Etype (N))
2394 and then Expr_Value (High_Bound (Aggregate_Bounds (N)))
2396 Expr_Value (Low_Bound (Aggregate_Bounds (N)))
2399 Count_Components : Uint := Uint_0;
2400 Num_Components : Uint;
2401 Others_Assoc : Node_Id;
2402 Others_Choice : Node_Id := Empty;
2403 Others_Box_Present : Boolean := False;
2406 -- Count positional associations
2408 if Present (Expressions (N)) then
2409 Comp_Expr := First (Expressions (N));
2410 while Present (Comp_Expr) loop
2411 Count_Components := Count_Components + 1;
2416 -- Count the rest of elements and locate the N_Others
2419 Assoc := First (Component_Associations (N));
2420 while Present (Assoc) loop
2421 Choice := First (Choices (Assoc));
2422 while Present (Choice) loop
2423 if Nkind (Choice) = N_Others_Choice then
2424 Others_Assoc := Assoc;
2425 Others_Choice := Choice;
2426 Others_Box_Present := Box_Present (Assoc);
2428 -- Count several components
2430 elsif Nkind_In (Choice, N_Range,
2431 N_Subtype_Indication)
2432 or else (Is_Entity_Name (Choice)
2433 and then Is_Type (Entity (Choice)))
2438 Get_Index_Bounds (Choice, L, H);
2440 (Compile_Time_Known_Value (L)
2441 and then Compile_Time_Known_Value (H));
2444 + Expr_Value (H) - Expr_Value (L) + 1;
2447 -- Count single component. No other case available
2448 -- since we are handling an aggregate with static
2452 pragma Assert (Is_OK_Static_Expression (Choice)
2453 or else Nkind (Choice) = N_Identifier
2454 or else Nkind (Choice) = N_Integer_Literal);
2456 Count_Components := Count_Components + 1;
2466 Expr_Value (High_Bound (Aggregate_Bounds (N))) -
2467 Expr_Value (Low_Bound (Aggregate_Bounds (N))) + 1;
2469 pragma Assert (Count_Components <= Num_Components);
2471 -- Handle the N_Others choice if it covers several
2474 if Present (Others_Choice)
2475 and then (Num_Components - Count_Components) > 1
2477 if not Others_Box_Present then
2479 -- At this stage, if expansion is active, the
2480 -- expression of the others choice has not been
2481 -- analyzed. Hence we generate a duplicate and
2482 -- we analyze it silently to have available the
2483 -- minimum decoration required to collect the
2486 if not Expander_Active then
2487 Comp_Expr := Expression (Others_Assoc);
2490 New_Copy_Tree (Expression (Others_Assoc));
2491 Preanalyze_Without_Errors (Comp_Expr);
2494 Collect_Identifiers (Comp_Expr);
2496 if Writable_Actuals_List /= No_Elist then
2498 -- As suggested by Robert, at current stage we
2499 -- report occurrences of this case as warnings.
2502 ("writable function parameter may affect "
2503 & "value in other component because order "
2504 & "of evaluation is unspecified??",
2505 Node (First_Elmt (Writable_Actuals_List)));
2511 -- For an array aggregate, a discrete_choice_list that has
2512 -- a nonstatic range is considered as two or more separate
2513 -- occurrences of the expression (RM 6.4.1(20/3)).
2515 elsif Is_Array_Type (Etype (N))
2516 and then Nkind (N) = N_Aggregate
2517 and then Present (Aggregate_Bounds (N))
2518 and then not Compile_Time_Known_Bounds (Etype (N))
2520 -- Collect identifiers found in the dynamic bounds
2523 Count_Components : Natural := 0;
2524 Low, High : Node_Id;
2527 Assoc := First (Component_Associations (N));
2528 while Present (Assoc) loop
2529 Choice := First (Choices (Assoc));
2530 while Present (Choice) loop
2531 if Nkind_In (Choice, N_Range,
2532 N_Subtype_Indication)
2533 or else (Is_Entity_Name (Choice)
2534 and then Is_Type (Entity (Choice)))
2536 Get_Index_Bounds (Choice, Low, High);
2538 if not Compile_Time_Known_Value (Low) then
2539 Collect_Identifiers (Low);
2541 if No (Aggr_Error_Node) then
2542 Aggr_Error_Node := Low;
2546 if not Compile_Time_Known_Value (High) then
2547 Collect_Identifiers (High);
2549 if No (Aggr_Error_Node) then
2550 Aggr_Error_Node := High;
2554 -- The RM rule is violated if there is more than
2555 -- a single choice in a component association.
2558 Count_Components := Count_Components + 1;
2560 if No (Aggr_Error_Node)
2561 and then Count_Components > 1
2563 Aggr_Error_Node := Choice;
2566 if not Compile_Time_Known_Value (Choice) then
2567 Collect_Identifiers (Choice);
2579 -- Handle ancestor part of extension aggregates
2581 if Nkind (N) = N_Extension_Aggregate then
2582 Collect_Identifiers (Ancestor_Part (N));
2585 -- Handle positional associations
2587 if Present (Expressions (N)) then
2588 Comp_Expr := First (Expressions (N));
2589 while Present (Comp_Expr) loop
2590 if not Is_OK_Static_Expression (Comp_Expr) then
2591 Collect_Identifiers (Comp_Expr);
2598 -- Handle discrete associations
2600 if Present (Component_Associations (N)) then
2601 Assoc := First (Component_Associations (N));
2602 while Present (Assoc) loop
2604 if not Box_Present (Assoc) then
2605 Choice := First (Choices (Assoc));
2606 while Present (Choice) loop
2608 -- For now we skip discriminants since it requires
2609 -- performing the analysis in two phases: first one
2610 -- analyzing discriminants and second one analyzing
2611 -- the rest of components since discriminants are
2612 -- evaluated prior to components: too much extra
2613 -- work to detect a corner case???
2615 if Nkind (Choice) in N_Has_Entity
2616 and then Present (Entity (Choice))
2617 and then Ekind (Entity (Choice)) = E_Discriminant
2621 elsif Box_Present (Assoc) then
2625 if not Analyzed (Expression (Assoc)) then
2627 New_Copy_Tree (Expression (Assoc));
2628 Set_Parent (Comp_Expr, Parent (N));
2629 Preanalyze_Without_Errors (Comp_Expr);
2631 Comp_Expr := Expression (Assoc);
2634 Collect_Identifiers (Comp_Expr);
2650 -- No further action needed if we already reported an error
2652 if Present (Error_Node) then
2656 -- Check violation of RM 6.20/3 in aggregates
2658 if Present (Aggr_Error_Node)
2659 and then Writable_Actuals_List /= No_Elist
2662 ("value may be affected by call in other component because they "
2663 & "are evaluated in unspecified order",
2664 Node (First_Elmt (Writable_Actuals_List)));
2668 -- Check if some writable argument of a function is referenced
2670 if Writable_Actuals_List /= No_Elist
2671 and then Identifiers_List /= No_Elist
2678 Elmt_1 := First_Elmt (Writable_Actuals_List);
2679 while Present (Elmt_1) loop
2680 Elmt_2 := First_Elmt (Identifiers_List);
2681 while Present (Elmt_2) loop
2682 if Entity (Node (Elmt_1)) = Entity (Node (Elmt_2)) then
2683 case Nkind (Parent (Node (Elmt_2))) is
2685 N_Component_Association |
2686 N_Component_Declaration =>
2688 ("value may be affected by call in other "
2689 & "component because they are evaluated "
2690 & "in unspecified order",
2693 when N_In | N_Not_In =>
2695 ("value may be affected by call in other "
2696 & "alternative because they are evaluated "
2697 & "in unspecified order",
2702 ("value of actual may be affected by call in "
2703 & "other actual because they are evaluated "
2704 & "in unspecified order",
2716 end Check_Function_Writable_Actuals;
2718 --------------------------------
2719 -- Check_Implicit_Dereference --
2720 --------------------------------
2722 procedure Check_Implicit_Dereference (N : Node_Id; Typ : Entity_Id) is
2728 if Nkind (N) = N_Indexed_Component
2729 and then Present (Generalized_Indexing (N))
2731 Nam := Generalized_Indexing (N);
2736 if Ada_Version < Ada_2012
2737 or else not Has_Implicit_Dereference (Base_Type (Typ))
2741 elsif not Comes_From_Source (N)
2742 and then Nkind (N) /= N_Indexed_Component
2746 elsif Is_Entity_Name (Nam) and then Is_Type (Entity (Nam)) then
2750 Disc := First_Discriminant (Typ);
2751 while Present (Disc) loop
2752 if Has_Implicit_Dereference (Disc) then
2753 Desig := Designated_Type (Etype (Disc));
2754 Add_One_Interp (Nam, Disc, Desig);
2756 -- If the node is a generalized indexing, add interpretation
2757 -- to that node as well, for subsequent resolution.
2759 if Nkind (N) = N_Indexed_Component then
2760 Add_One_Interp (N, Disc, Desig);
2763 -- If the operation comes from a generic unit and the context
2764 -- is a selected component, the selector name may be global
2765 -- and set in the instance already. Remove the entity to
2766 -- force resolution of the selected component, and the
2767 -- generation of an explicit dereference if needed.
2770 and then Nkind (Parent (Nam)) = N_Selected_Component
2772 Set_Entity (Selector_Name (Parent (Nam)), Empty);
2778 Next_Discriminant (Disc);
2781 end Check_Implicit_Dereference;
2783 ----------------------------------
2784 -- Check_Internal_Protected_Use --
2785 ----------------------------------
2787 procedure Check_Internal_Protected_Use (N : Node_Id; Nam : Entity_Id) is
2793 while Present (S) loop
2794 if S = Standard_Standard then
2797 elsif Ekind (S) = E_Function
2798 and then Ekind (Scope (S)) = E_Protected_Type
2807 if Scope (Nam) = Prot and then Ekind (Nam) /= E_Function then
2809 -- An indirect function call (e.g. a callback within a protected
2810 -- function body) is not statically illegal. If the access type is
2811 -- anonymous and is the type of an access parameter, the scope of Nam
2812 -- will be the protected type, but it is not a protected operation.
2814 if Ekind (Nam) = E_Subprogram_Type
2816 Nkind (Associated_Node_For_Itype (Nam)) = N_Function_Specification
2820 elsif Nkind (N) = N_Subprogram_Renaming_Declaration then
2822 ("within protected function cannot use protected "
2823 & "procedure in renaming or as generic actual", N);
2825 elsif Nkind (N) = N_Attribute_Reference then
2827 ("within protected function cannot take access of "
2828 & " protected procedure", N);
2832 ("within protected function, protected object is constant", N);
2834 ("\cannot call operation that may modify it", N);
2837 end Check_Internal_Protected_Use;
2839 ---------------------------------------
2840 -- Check_Later_Vs_Basic_Declarations --
2841 ---------------------------------------
2843 procedure Check_Later_Vs_Basic_Declarations
2845 During_Parsing : Boolean)
2847 Body_Sloc : Source_Ptr;
2850 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
2851 -- Return whether Decl is considered as a declarative item.
2852 -- When During_Parsing is True, the semantics of Ada 83 is followed.
2853 -- When During_Parsing is False, the semantics of SPARK is followed.
2855 -------------------------------
2856 -- Is_Later_Declarative_Item --
2857 -------------------------------
2859 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
2861 if Nkind (Decl) in N_Later_Decl_Item then
2864 elsif Nkind (Decl) = N_Pragma then
2867 elsif During_Parsing then
2870 -- In SPARK, a package declaration is not considered as a later
2871 -- declarative item.
2873 elsif Nkind (Decl) = N_Package_Declaration then
2876 -- In SPARK, a renaming is considered as a later declarative item
2878 elsif Nkind (Decl) in N_Renaming_Declaration then
2884 end Is_Later_Declarative_Item;
2886 -- Start of processing for Check_Later_Vs_Basic_Declarations
2889 Decl := First (Decls);
2891 -- Loop through sequence of basic declarative items
2893 Outer : while Present (Decl) loop
2894 if not Nkind_In (Decl, N_Subprogram_Body, N_Package_Body, N_Task_Body)
2895 and then Nkind (Decl) not in N_Body_Stub
2899 -- Once a body is encountered, we only allow later declarative
2900 -- items. The inner loop checks the rest of the list.
2903 Body_Sloc := Sloc (Decl);
2905 Inner : while Present (Decl) loop
2906 if not Is_Later_Declarative_Item (Decl) then
2907 if During_Parsing then
2908 if Ada_Version = Ada_83 then
2909 Error_Msg_Sloc := Body_Sloc;
2911 ("(Ada 83) decl cannot appear after body#", Decl);
2914 Error_Msg_Sloc := Body_Sloc;
2915 Check_SPARK_05_Restriction
2916 ("decl cannot appear after body#", Decl);
2924 end Check_Later_Vs_Basic_Declarations;
2926 ---------------------------
2927 -- Check_No_Hidden_State --
2928 ---------------------------
2930 procedure Check_No_Hidden_State (Id : Entity_Id) is
2931 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean;
2932 -- Determine whether the entity of a package denoted by Pkg has a null
2935 -----------------------------
2936 -- Has_Null_Abstract_State --
2937 -----------------------------
2939 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean is
2940 States : constant Elist_Id := Abstract_States (Pkg);
2943 -- Check first available state of related package. A null abstract
2944 -- state always appears as the sole element of the state list.
2948 and then Is_Null_State (Node (First_Elmt (States)));
2949 end Has_Null_Abstract_State;
2953 Context : Entity_Id := Empty;
2954 Not_Visible : Boolean := False;
2957 -- Start of processing for Check_No_Hidden_State
2960 pragma Assert (Ekind_In (Id, E_Abstract_State, E_Variable));
2962 -- Find the proper context where the object or state appears
2965 while Present (Scop) loop
2968 -- Keep track of the context's visibility
2970 Not_Visible := Not_Visible or else In_Private_Part (Context);
2972 -- Prevent the search from going too far
2974 if Context = Standard_Standard then
2977 -- Objects and states that appear immediately within a subprogram or
2978 -- inside a construct nested within a subprogram do not introduce a
2979 -- hidden state. They behave as local variable declarations.
2981 elsif Is_Subprogram (Context) then
2984 -- When examining a package body, use the entity of the spec as it
2985 -- carries the abstract state declarations.
2987 elsif Ekind (Context) = E_Package_Body then
2988 Context := Spec_Entity (Context);
2991 -- Stop the traversal when a package subject to a null abstract state
2994 if Ekind_In (Context, E_Generic_Package, E_Package)
2995 and then Has_Null_Abstract_State (Context)
3000 Scop := Scope (Scop);
3003 -- At this point we know that there is at least one package with a null
3004 -- abstract state in visibility. Emit an error message unconditionally
3005 -- if the entity being processed is a state because the placement of the
3006 -- related package is irrelevant. This is not the case for objects as
3007 -- the intermediate context matters.
3009 if Present (Context)
3010 and then (Ekind (Id) = E_Abstract_State or else Not_Visible)
3012 Error_Msg_N ("cannot introduce hidden state &", Id);
3013 Error_Msg_NE ("\package & has null abstract state", Id, Context);
3015 end Check_No_Hidden_State;
3017 ----------------------------------------
3018 -- Check_Nonvolatile_Function_Profile --
3019 ----------------------------------------
3021 procedure Check_Nonvolatile_Function_Profile (Func_Id : Entity_Id) is
3025 -- Inspect all formal parameters
3027 Formal := First_Formal (Func_Id);
3028 while Present (Formal) loop
3029 if Is_Effectively_Volatile (Etype (Formal)) then
3031 ("nonvolatile function & cannot have a volatile parameter",
3035 Next_Formal (Formal);
3038 -- Inspect the return type
3040 if Is_Effectively_Volatile (Etype (Func_Id)) then
3042 ("nonvolatile function & cannot have a volatile return type",
3043 Result_Definition (Parent (Func_Id)), Func_Id);
3045 end Check_Nonvolatile_Function_Profile;
3047 ------------------------------------------
3048 -- Check_Potentially_Blocking_Operation --
3049 ------------------------------------------
3051 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
3055 -- N is one of the potentially blocking operations listed in 9.5.1(8).
3056 -- When pragma Detect_Blocking is active, the run time will raise
3057 -- Program_Error. Here we only issue a warning, since we generally
3058 -- support the use of potentially blocking operations in the absence
3061 -- Indirect blocking through a subprogram call cannot be diagnosed
3062 -- statically without interprocedural analysis, so we do not attempt
3065 S := Scope (Current_Scope);
3066 while Present (S) and then S /= Standard_Standard loop
3067 if Is_Protected_Type (S) then
3069 ("potentially blocking operation in protected operation??", N);
3075 end Check_Potentially_Blocking_Operation;
3077 ---------------------------------
3078 -- Check_Result_And_Post_State --
3079 ---------------------------------
3081 procedure Check_Result_And_Post_State (Subp_Id : Entity_Id) is
3082 procedure Check_Result_And_Post_State_In_Pragma
3084 Result_Seen : in out Boolean);
3085 -- Determine whether pragma Prag mentions attribute 'Result and whether
3086 -- the pragma contains an expression that evaluates differently in pre-
3087 -- and post-state. Prag is a [refined] postcondition or a contract-cases
3088 -- pragma. Result_Seen is set when the pragma mentions attribute 'Result
3090 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean;
3091 -- Determine whether subprogram Subp_Id contains at least one IN OUT
3092 -- formal parameter.
3094 -------------------------------------------
3095 -- Check_Result_And_Post_State_In_Pragma --
3096 -------------------------------------------
3098 procedure Check_Result_And_Post_State_In_Pragma
3100 Result_Seen : in out Boolean)
3102 procedure Check_Expression (Expr : Node_Id);
3103 -- Perform the 'Result and post-state checks on a given expression
3105 function Is_Function_Result (N : Node_Id) return Traverse_Result;
3106 -- Attempt to find attribute 'Result in a subtree denoted by N
3108 function Is_Trivial_Boolean (N : Node_Id) return Boolean;
3109 -- Determine whether source node N denotes "True" or "False"
3111 function Mentions_Post_State (N : Node_Id) return Boolean;
3112 -- Determine whether a subtree denoted by N mentions any construct
3113 -- that denotes a post-state.
3115 procedure Check_Function_Result is
3116 new Traverse_Proc (Is_Function_Result);
3118 ----------------------
3119 -- Check_Expression --
3120 ----------------------
3122 procedure Check_Expression (Expr : Node_Id) is
3124 if not Is_Trivial_Boolean (Expr) then
3125 Check_Function_Result (Expr);
3127 if not Mentions_Post_State (Expr) then
3128 if Pragma_Name (Prag) = Name_Contract_Cases then
3130 ("contract case does not check the outcome of calling "
3131 & "&?T?", Expr, Subp_Id);
3133 elsif Pragma_Name (Prag) = Name_Refined_Post then
3135 ("refined postcondition does not check the outcome of "
3136 & "calling &?T?", Prag, Subp_Id);
3140 ("postcondition does not check the outcome of calling "
3141 & "&?T?", Prag, Subp_Id);
3145 end Check_Expression;
3147 ------------------------
3148 -- Is_Function_Result --
3149 ------------------------
3151 function Is_Function_Result (N : Node_Id) return Traverse_Result is
3153 if Is_Attribute_Result (N) then
3154 Result_Seen := True;
3157 -- Continue the traversal
3162 end Is_Function_Result;
3164 ------------------------
3165 -- Is_Trivial_Boolean --
3166 ------------------------
3168 function Is_Trivial_Boolean (N : Node_Id) return Boolean is
3171 Comes_From_Source (N)
3172 and then Is_Entity_Name (N)
3173 and then (Entity (N) = Standard_True
3175 Entity (N) = Standard_False);
3176 end Is_Trivial_Boolean;
3178 -------------------------
3179 -- Mentions_Post_State --
3180 -------------------------
3182 function Mentions_Post_State (N : Node_Id) return Boolean is
3183 Post_State_Seen : Boolean := False;
3185 function Is_Post_State (N : Node_Id) return Traverse_Result;
3186 -- Attempt to find a construct that denotes a post-state. If this
3187 -- is the case, set flag Post_State_Seen.
3193 function Is_Post_State (N : Node_Id) return Traverse_Result is
3197 if Nkind_In (N, N_Explicit_Dereference, N_Function_Call) then
3198 Post_State_Seen := True;
3201 elsif Nkind_In (N, N_Expanded_Name, N_Identifier) then
3204 -- The entity may be modifiable through an implicit
3208 or else Ekind (Ent) in Assignable_Kind
3209 or else (Is_Access_Type (Etype (Ent))
3210 and then Nkind (Parent (N)) =
3211 N_Selected_Component)
3213 Post_State_Seen := True;
3217 elsif Nkind (N) = N_Attribute_Reference then
3218 if Attribute_Name (N) = Name_Old then
3221 elsif Attribute_Name (N) = Name_Result then
3222 Post_State_Seen := True;
3230 procedure Find_Post_State is new Traverse_Proc (Is_Post_State);
3232 -- Start of processing for Mentions_Post_State
3235 Find_Post_State (N);
3237 return Post_State_Seen;
3238 end Mentions_Post_State;
3242 Expr : constant Node_Id :=
3244 (First (Pragma_Argument_Associations (Prag)));
3245 Nam : constant Name_Id := Pragma_Name (Prag);
3248 -- Start of processing for Check_Result_And_Post_State_In_Pragma
3251 -- Examine all consequences
3253 if Nam = Name_Contract_Cases then
3254 CCase := First (Component_Associations (Expr));
3255 while Present (CCase) loop
3256 Check_Expression (Expression (CCase));
3261 -- Examine the expression of a postcondition
3263 else pragma Assert (Nam_In (Nam, Name_Postcondition,
3264 Name_Refined_Post));
3265 Check_Expression (Expr);
3267 end Check_Result_And_Post_State_In_Pragma;
3269 --------------------------
3270 -- Has_In_Out_Parameter --
3271 --------------------------
3273 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean is
3277 -- Traverse the formals looking for an IN OUT parameter
3279 Formal := First_Formal (Subp_Id);
3280 while Present (Formal) loop
3281 if Ekind (Formal) = E_In_Out_Parameter then
3285 Next_Formal (Formal);
3289 end Has_In_Out_Parameter;
3293 Items : constant Node_Id := Contract (Subp_Id);
3294 Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id);
3295 Case_Prag : Node_Id := Empty;
3296 Post_Prag : Node_Id := Empty;
3298 Seen_In_Case : Boolean := False;
3299 Seen_In_Post : Boolean := False;
3300 Spec_Id : Entity_Id;
3302 -- Start of processing for Check_Result_And_Post_State
3305 -- The lack of attribute 'Result or a post-state is classified as a
3306 -- suspicious contract. Do not perform the check if the corresponding
3307 -- swich is not set.
3309 if not Warn_On_Suspicious_Contract then
3312 -- Nothing to do if there is no contract
3314 elsif No (Items) then
3318 -- Retrieve the entity of the subprogram spec (if any)
3320 if Nkind (Subp_Decl) = N_Subprogram_Body
3321 and then Present (Corresponding_Spec (Subp_Decl))
3323 Spec_Id := Corresponding_Spec (Subp_Decl);
3325 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
3326 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
3328 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
3334 -- Examine all postconditions for attribute 'Result and a post-state
3336 Prag := Pre_Post_Conditions (Items);
3337 while Present (Prag) loop
3338 if Nam_In (Pragma_Name_Unmapped (Prag),
3339 Name_Postcondition, Name_Refined_Post)
3340 and then not Error_Posted (Prag)
3343 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Post);
3346 Prag := Next_Pragma (Prag);
3349 -- Examine the contract cases of the subprogram for attribute 'Result
3350 -- and a post-state.
3352 Prag := Contract_Test_Cases (Items);
3353 while Present (Prag) loop
3354 if Pragma_Name (Prag) = Name_Contract_Cases
3355 and then not Error_Posted (Prag)
3358 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Case);
3361 Prag := Next_Pragma (Prag);
3364 -- Do not emit any errors if the subprogram is not a function
3366 if not Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
3369 -- Regardless of whether the function has postconditions or contract
3370 -- cases, or whether they mention attribute 'Result, an IN OUT formal
3371 -- parameter is always treated as a result.
3373 elsif Has_In_Out_Parameter (Spec_Id) then
3376 -- The function has both a postcondition and contract cases and they do
3377 -- not mention attribute 'Result.
3379 elsif Present (Case_Prag)
3380 and then not Seen_In_Case
3381 and then Present (Post_Prag)
3382 and then not Seen_In_Post
3385 ("neither postcondition nor contract cases mention function "
3386 & "result?T?", Post_Prag);
3388 -- The function has contract cases only and they do not mention
3389 -- attribute 'Result.
3391 elsif Present (Case_Prag) and then not Seen_In_Case then
3392 Error_Msg_N ("contract cases do not mention result?T?", Case_Prag);
3394 -- The function has postconditions only and they do not mention
3395 -- attribute 'Result.
3397 elsif Present (Post_Prag) and then not Seen_In_Post then
3399 ("postcondition does not mention function result?T?", Post_Prag);
3401 end Check_Result_And_Post_State;
3403 -----------------------------
3404 -- Check_State_Refinements --
3405 -----------------------------
3407 procedure Check_State_Refinements
3409 Is_Main_Unit : Boolean := False)
3411 procedure Check_Package (Pack : Node_Id);
3412 -- Verify that all abstract states of a [generic] package denoted by its
3413 -- declarative node Pack have proper refinement. Recursively verify the
3414 -- visible and private declarations of the [generic] package for other
3417 procedure Check_Packages_In (Decls : List_Id);
3418 -- Seek out [generic] package declarations within declarative list Decls
3419 -- and verify the status of their abstract state refinement.
3421 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean;
3422 -- Determine whether construct N is subject to pragma SPARK_Mode Off
3428 procedure Check_Package (Pack : Node_Id) is
3429 Body_Id : constant Entity_Id := Corresponding_Body (Pack);
3430 Spec : constant Node_Id := Specification (Pack);
3431 States : constant Elist_Id :=
3432 Abstract_States (Defining_Entity (Pack));
3434 State_Elmt : Elmt_Id;
3435 State_Id : Entity_Id;
3438 -- Do not verify proper state refinement when the package is subject
3439 -- to pragma SPARK_Mode Off because this disables the requirement for
3440 -- state refinement.
3442 if SPARK_Mode_Is_Off (Pack) then
3445 -- State refinement can only occur in a completing packge body. Do
3446 -- not verify proper state refinement when the body is subject to
3447 -- pragma SPARK_Mode Off because this disables the requirement for
3448 -- state refinement.
3450 elsif Present (Body_Id)
3451 and then SPARK_Mode_Is_Off (Unit_Declaration_Node (Body_Id))
3455 -- Do not verify proper state refinement when the package is an
3456 -- instance as this check was already performed in the generic.
3458 elsif Present (Generic_Parent (Spec)) then
3461 -- Otherwise examine the contents of the package
3464 if Present (States) then
3465 State_Elmt := First_Elmt (States);
3466 while Present (State_Elmt) loop
3467 State_Id := Node (State_Elmt);
3469 -- Emit an error when a non-null state lacks any form of
3472 if not Is_Null_State (State_Id)
3473 and then not Has_Null_Refinement (State_Id)
3474 and then not Has_Non_Null_Refinement (State_Id)
3476 Error_Msg_N ("state & requires refinement", State_Id);
3479 Next_Elmt (State_Elmt);
3483 Check_Packages_In (Visible_Declarations (Spec));
3484 Check_Packages_In (Private_Declarations (Spec));
3488 -----------------------
3489 -- Check_Packages_In --
3490 -----------------------
3492 procedure Check_Packages_In (Decls : List_Id) is
3496 if Present (Decls) then
3497 Decl := First (Decls);
3498 while Present (Decl) loop
3499 if Nkind_In (Decl, N_Generic_Package_Declaration,
3500 N_Package_Declaration)
3502 Check_Package (Decl);
3508 end Check_Packages_In;
3510 -----------------------
3511 -- SPARK_Mode_Is_Off --
3512 -----------------------
3514 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean is
3515 Prag : constant Node_Id := SPARK_Pragma (Defining_Entity (N));
3519 Present (Prag) and then Get_SPARK_Mode_From_Annotation (Prag) = Off;
3520 end SPARK_Mode_Is_Off;
3522 -- Start of processing for Check_State_Refinements
3525 -- A block may declare a nested package
3527 if Nkind (Context) = N_Block_Statement then
3528 Check_Packages_In (Declarations (Context));
3530 -- An entry, protected, subprogram, or task body may declare a nested
3533 elsif Nkind_In (Context, N_Entry_Body,
3538 -- Do not verify proper state refinement when the body is subject to
3539 -- pragma SPARK_Mode Off because this disables the requirement for
3540 -- state refinement.
3542 if not SPARK_Mode_Is_Off (Context) then
3543 Check_Packages_In (Declarations (Context));
3546 -- A package body may declare a nested package
3548 elsif Nkind (Context) = N_Package_Body then
3549 Check_Package (Unit_Declaration_Node (Corresponding_Spec (Context)));
3551 -- Do not verify proper state refinement when the body is subject to
3552 -- pragma SPARK_Mode Off because this disables the requirement for
3553 -- state refinement.
3555 if not SPARK_Mode_Is_Off (Context) then
3556 Check_Packages_In (Declarations (Context));
3559 -- A library level [generic] package may declare a nested package
3561 elsif Nkind_In (Context, N_Generic_Package_Declaration,
3562 N_Package_Declaration)
3563 and then Is_Main_Unit
3565 Check_Package (Context);
3567 end Check_State_Refinements;
3569 ------------------------------
3570 -- Check_Unprotected_Access --
3571 ------------------------------
3573 procedure Check_Unprotected_Access
3577 Cont_Encl_Typ : Entity_Id;
3578 Pref_Encl_Typ : Entity_Id;
3580 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
3581 -- Check whether Obj is a private component of a protected object.
3582 -- Return the protected type where the component resides, Empty
3585 function Is_Public_Operation return Boolean;
3586 -- Verify that the enclosing operation is callable from outside the
3587 -- protected object, to minimize false positives.
3589 ------------------------------
3590 -- Enclosing_Protected_Type --
3591 ------------------------------
3593 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
3595 if Is_Entity_Name (Obj) then
3597 Ent : Entity_Id := Entity (Obj);
3600 -- The object can be a renaming of a private component, use
3601 -- the original record component.
3603 if Is_Prival (Ent) then
3604 Ent := Prival_Link (Ent);
3607 if Is_Protected_Type (Scope (Ent)) then
3613 -- For indexed and selected components, recursively check the prefix
3615 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
3616 return Enclosing_Protected_Type (Prefix (Obj));
3618 -- The object does not denote a protected component
3623 end Enclosing_Protected_Type;
3625 -------------------------
3626 -- Is_Public_Operation --
3627 -------------------------
3629 function Is_Public_Operation return Boolean is
3635 while Present (S) and then S /= Pref_Encl_Typ loop
3636 if Scope (S) = Pref_Encl_Typ then
3637 E := First_Entity (Pref_Encl_Typ);
3639 and then E /= First_Private_Entity (Pref_Encl_Typ)
3653 end Is_Public_Operation;
3655 -- Start of processing for Check_Unprotected_Access
3658 if Nkind (Expr) = N_Attribute_Reference
3659 and then Attribute_Name (Expr) = Name_Unchecked_Access
3661 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
3662 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
3664 -- Check whether we are trying to export a protected component to a
3665 -- context with an equal or lower access level.
3667 if Present (Pref_Encl_Typ)
3668 and then No (Cont_Encl_Typ)
3669 and then Is_Public_Operation
3670 and then Scope_Depth (Pref_Encl_Typ) >=
3671 Object_Access_Level (Context)
3674 ("??possible unprotected access to protected data", Expr);
3677 end Check_Unprotected_Access;
3679 ------------------------------
3680 -- Check_Unused_Body_States --
3681 ------------------------------
3683 procedure Check_Unused_Body_States (Body_Id : Entity_Id) is
3684 procedure Process_Refinement_Clause
3687 -- Inspect all constituents of refinement clause Clause and remove any
3688 -- matches from body state list States.
3690 procedure Report_Unused_Body_States (States : Elist_Id);
3691 -- Emit errors for each abstract state or object found in list States
3693 -------------------------------
3694 -- Process_Refinement_Clause --
3695 -------------------------------
3697 procedure Process_Refinement_Clause
3701 procedure Process_Constituent (Constit : Node_Id);
3702 -- Remove constituent Constit from body state list States
3704 -------------------------
3705 -- Process_Constituent --
3706 -------------------------
3708 procedure Process_Constituent (Constit : Node_Id) is
3709 Constit_Id : Entity_Id;
3712 -- Guard against illegal constituents. Only abstract states and
3713 -- objects can appear on the right hand side of a refinement.
3715 if Is_Entity_Name (Constit) then
3716 Constit_Id := Entity_Of (Constit);
3718 if Present (Constit_Id)
3719 and then Ekind_In (Constit_Id, E_Abstract_State,
3723 Remove (States, Constit_Id);
3726 end Process_Constituent;
3732 -- Start of processing for Process_Refinement_Clause
3735 if Nkind (Clause) = N_Component_Association then
3736 Constit := Expression (Clause);
3738 -- Multiple constituents appear as an aggregate
3740 if Nkind (Constit) = N_Aggregate then
3741 Constit := First (Expressions (Constit));
3742 while Present (Constit) loop
3743 Process_Constituent (Constit);
3747 -- Various forms of a single constituent
3750 Process_Constituent (Constit);
3753 end Process_Refinement_Clause;
3755 -------------------------------
3756 -- Report_Unused_Body_States --
3757 -------------------------------
3759 procedure Report_Unused_Body_States (States : Elist_Id) is
3760 Posted : Boolean := False;
3761 State_Elmt : Elmt_Id;
3762 State_Id : Entity_Id;
3765 if Present (States) then
3766 State_Elmt := First_Elmt (States);
3767 while Present (State_Elmt) loop
3768 State_Id := Node (State_Elmt);
3770 -- Constants are part of the hidden state of a package, but the
3771 -- compiler cannot determine whether they have variable input
3772 -- (SPARK RM 7.1.1(2)) and cannot classify them properly as a
3773 -- hidden state. Do not emit an error when a constant does not
3774 -- participate in a state refinement, even though it acts as a
3777 if Ekind (State_Id) = E_Constant then
3780 -- Generate an error message of the form:
3782 -- body of package ... has unused hidden states
3783 -- abstract state ... defined at ...
3784 -- variable ... defined at ...
3790 ("body of package & has unused hidden states", Body_Id);
3793 Error_Msg_Sloc := Sloc (State_Id);
3795 if Ekind (State_Id) = E_Abstract_State then
3797 ("\abstract state & defined #", Body_Id, State_Id);
3800 SPARK_Msg_NE ("\variable & defined #", Body_Id, State_Id);
3804 Next_Elmt (State_Elmt);
3807 end Report_Unused_Body_States;
3811 Prag : constant Node_Id := Get_Pragma (Body_Id, Pragma_Refined_State);
3812 Spec_Id : constant Entity_Id := Spec_Entity (Body_Id);
3816 -- Start of processing for Check_Unused_Body_States
3819 -- Inspect the clauses of pragma Refined_State and determine whether all
3820 -- visible states declared within the package body participate in the
3823 if Present (Prag) then
3824 Clause := Expression (Get_Argument (Prag, Spec_Id));
3825 States := Collect_Body_States (Body_Id);
3827 -- Multiple non-null state refinements appear as an aggregate
3829 if Nkind (Clause) = N_Aggregate then
3830 Clause := First (Component_Associations (Clause));
3831 while Present (Clause) loop
3832 Process_Refinement_Clause (Clause, States);
3836 -- Various forms of a single state refinement
3839 Process_Refinement_Clause (Clause, States);
3842 -- Ensure that all abstract states and objects declared in the
3843 -- package body state space are utilized as constituents.
3845 Report_Unused_Body_States (States);
3847 end Check_Unused_Body_States;
3849 -------------------------
3850 -- Collect_Body_States --
3851 -------------------------
3853 function Collect_Body_States (Body_Id : Entity_Id) return Elist_Id is
3854 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean;
3855 -- Determine whether object Obj_Id is a suitable visible state of a
3858 procedure Collect_Visible_States
3859 (Pack_Id : Entity_Id;
3860 States : in out Elist_Id);
3861 -- Gather the entities of all abstract states and objects declared in
3862 -- the visible state space of package Pack_Id.
3864 ----------------------------
3865 -- Collect_Visible_States --
3866 ----------------------------
3868 procedure Collect_Visible_States
3869 (Pack_Id : Entity_Id;
3870 States : in out Elist_Id)
3872 Item_Id : Entity_Id;
3875 -- Traverse the entity chain of the package and inspect all visible
3878 Item_Id := First_Entity (Pack_Id);
3879 while Present (Item_Id) and then not In_Private_Part (Item_Id) loop
3881 -- Do not consider internally generated items as those cannot be
3882 -- named and participate in refinement.
3884 if not Comes_From_Source (Item_Id) then
3887 elsif Ekind (Item_Id) = E_Abstract_State then
3888 Append_New_Elmt (Item_Id, States);
3890 elsif Ekind_In (Item_Id, E_Constant, E_Variable)
3891 and then Is_Visible_Object (Item_Id)
3893 Append_New_Elmt (Item_Id, States);
3895 -- Recursively gather the visible states of a nested package
3897 elsif Ekind (Item_Id) = E_Package then
3898 Collect_Visible_States (Item_Id, States);
3901 Next_Entity (Item_Id);
3903 end Collect_Visible_States;
3905 -----------------------
3906 -- Is_Visible_Object --
3907 -----------------------
3909 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean is
3911 -- Objects that map generic formals to their actuals are not visible
3912 -- from outside the generic instantiation.
3914 if Present (Corresponding_Generic_Association
3915 (Declaration_Node (Obj_Id)))
3919 -- Constituents of a single protected/task type act as components of
3920 -- the type and are not visible from outside the type.
3922 elsif Ekind (Obj_Id) = E_Variable
3923 and then Present (Encapsulating_State (Obj_Id))
3924 and then Is_Single_Concurrent_Object (Encapsulating_State (Obj_Id))
3931 end Is_Visible_Object;
3935 Body_Decl : constant Node_Id := Unit_Declaration_Node (Body_Id);
3937 Item_Id : Entity_Id;
3938 States : Elist_Id := No_Elist;
3940 -- Start of processing for Collect_Body_States
3943 -- Inspect the declarations of the body looking for source objects,
3944 -- packages and package instantiations. Note that even though this
3945 -- processing is very similar to Collect_Visible_States, a package
3946 -- body does not have a First/Next_Entity list.
3948 Decl := First (Declarations (Body_Decl));
3949 while Present (Decl) loop
3951 -- Capture source objects as internally generated temporaries cannot
3952 -- be named and participate in refinement.
3954 if Nkind (Decl) = N_Object_Declaration then
3955 Item_Id := Defining_Entity (Decl);
3957 if Comes_From_Source (Item_Id)
3958 and then Is_Visible_Object (Item_Id)
3960 Append_New_Elmt (Item_Id, States);
3963 -- Capture the visible abstract states and objects of a source
3964 -- package [instantiation].
3966 elsif Nkind (Decl) = N_Package_Declaration then
3967 Item_Id := Defining_Entity (Decl);
3969 if Comes_From_Source (Item_Id) then
3970 Collect_Visible_States (Item_Id, States);
3978 end Collect_Body_States;
3980 ------------------------
3981 -- Collect_Interfaces --
3982 ------------------------
3984 procedure Collect_Interfaces
3986 Ifaces_List : out Elist_Id;
3987 Exclude_Parents : Boolean := False;
3988 Use_Full_View : Boolean := True)
3990 procedure Collect (Typ : Entity_Id);
3991 -- Subsidiary subprogram used to traverse the whole list
3992 -- of directly and indirectly implemented interfaces
3998 procedure Collect (Typ : Entity_Id) is
3999 Ancestor : Entity_Id;
4007 -- Handle private types and subtypes
4010 and then Is_Private_Type (Typ)
4011 and then Present (Full_View (Typ))
4013 Full_T := Full_View (Typ);
4015 if Ekind (Full_T) = E_Record_Subtype then
4016 Full_T := Etype (Typ);
4018 if Present (Full_View (Full_T)) then
4019 Full_T := Full_View (Full_T);
4024 -- Include the ancestor if we are generating the whole list of
4025 -- abstract interfaces.
4027 if Etype (Full_T) /= Typ
4029 -- Protect the frontend against wrong sources. For example:
4032 -- type A is tagged null record;
4033 -- type B is new A with private;
4034 -- type C is new A with private;
4036 -- type B is new C with null record;
4037 -- type C is new B with null record;
4040 and then Etype (Full_T) /= T
4042 Ancestor := Etype (Full_T);
4045 if Is_Interface (Ancestor) and then not Exclude_Parents then
4046 Append_Unique_Elmt (Ancestor, Ifaces_List);
4050 -- Traverse the graph of ancestor interfaces
4052 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
4053 Id := First (Abstract_Interface_List (Full_T));
4054 while Present (Id) loop
4055 Iface := Etype (Id);
4057 -- Protect against wrong uses. For example:
4058 -- type I is interface;
4059 -- type O is tagged null record;
4060 -- type Wrong is new I and O with null record; -- ERROR
4062 if Is_Interface (Iface) then
4064 and then Etype (T) /= T
4065 and then Interface_Present_In_Ancestor (Etype (T), Iface)
4070 Append_Unique_Elmt (Iface, Ifaces_List);
4079 -- Start of processing for Collect_Interfaces
4082 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
4083 Ifaces_List := New_Elmt_List;
4085 end Collect_Interfaces;
4087 ----------------------------------
4088 -- Collect_Interface_Components --
4089 ----------------------------------
4091 procedure Collect_Interface_Components
4092 (Tagged_Type : Entity_Id;
4093 Components_List : out Elist_Id)
4095 procedure Collect (Typ : Entity_Id);
4096 -- Subsidiary subprogram used to climb to the parents
4102 procedure Collect (Typ : Entity_Id) is
4103 Tag_Comp : Entity_Id;
4104 Parent_Typ : Entity_Id;
4107 -- Handle private types
4109 if Present (Full_View (Etype (Typ))) then
4110 Parent_Typ := Full_View (Etype (Typ));
4112 Parent_Typ := Etype (Typ);
4115 if Parent_Typ /= Typ
4117 -- Protect the frontend against wrong sources. For example:
4120 -- type A is tagged null record;
4121 -- type B is new A with private;
4122 -- type C is new A with private;
4124 -- type B is new C with null record;
4125 -- type C is new B with null record;
4128 and then Parent_Typ /= Tagged_Type
4130 Collect (Parent_Typ);
4133 -- Collect the components containing tags of secondary dispatch
4136 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
4137 while Present (Tag_Comp) loop
4138 pragma Assert (Present (Related_Type (Tag_Comp)));
4139 Append_Elmt (Tag_Comp, Components_List);
4141 Tag_Comp := Next_Tag_Component (Tag_Comp);
4145 -- Start of processing for Collect_Interface_Components
4148 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
4149 and then Is_Tagged_Type (Tagged_Type));
4151 Components_List := New_Elmt_List;
4152 Collect (Tagged_Type);
4153 end Collect_Interface_Components;
4155 -----------------------------
4156 -- Collect_Interfaces_Info --
4157 -----------------------------
4159 procedure Collect_Interfaces_Info
4161 Ifaces_List : out Elist_Id;
4162 Components_List : out Elist_Id;
4163 Tags_List : out Elist_Id)
4165 Comps_List : Elist_Id;
4166 Comp_Elmt : Elmt_Id;
4167 Comp_Iface : Entity_Id;
4168 Iface_Elmt : Elmt_Id;
4171 function Search_Tag (Iface : Entity_Id) return Entity_Id;
4172 -- Search for the secondary tag associated with the interface type
4173 -- Iface that is implemented by T.
4179 function Search_Tag (Iface : Entity_Id) return Entity_Id is
4182 if not Is_CPP_Class (T) then
4183 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
4185 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
4189 and then Is_Tag (Node (ADT))
4190 and then Related_Type (Node (ADT)) /= Iface
4192 -- Skip secondary dispatch table referencing thunks to user
4193 -- defined primitives covered by this interface.
4195 pragma Assert (Has_Suffix (Node (ADT), 'P'));
4198 -- Skip secondary dispatch tables of Ada types
4200 if not Is_CPP_Class (T) then
4202 -- Skip secondary dispatch table referencing thunks to
4203 -- predefined primitives.
4205 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
4208 -- Skip secondary dispatch table referencing user-defined
4209 -- primitives covered by this interface.
4211 pragma Assert (Has_Suffix (Node (ADT), 'D'));
4214 -- Skip secondary dispatch table referencing predefined
4217 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
4222 pragma Assert (Is_Tag (Node (ADT)));
4226 -- Start of processing for Collect_Interfaces_Info
4229 Collect_Interfaces (T, Ifaces_List);
4230 Collect_Interface_Components (T, Comps_List);
4232 -- Search for the record component and tag associated with each
4233 -- interface type of T.
4235 Components_List := New_Elmt_List;
4236 Tags_List := New_Elmt_List;
4238 Iface_Elmt := First_Elmt (Ifaces_List);
4239 while Present (Iface_Elmt) loop
4240 Iface := Node (Iface_Elmt);
4242 -- Associate the primary tag component and the primary dispatch table
4243 -- with all the interfaces that are parents of T
4245 if Is_Ancestor (Iface, T, Use_Full_View => True) then
4246 Append_Elmt (First_Tag_Component (T), Components_List);
4247 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
4249 -- Otherwise search for the tag component and secondary dispatch
4253 Comp_Elmt := First_Elmt (Comps_List);
4254 while Present (Comp_Elmt) loop
4255 Comp_Iface := Related_Type (Node (Comp_Elmt));
4257 if Comp_Iface = Iface
4258 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
4260 Append_Elmt (Node (Comp_Elmt), Components_List);
4261 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
4265 Next_Elmt (Comp_Elmt);
4267 pragma Assert (Present (Comp_Elmt));
4270 Next_Elmt (Iface_Elmt);
4272 end Collect_Interfaces_Info;
4274 ---------------------
4275 -- Collect_Parents --
4276 ---------------------
4278 procedure Collect_Parents
4280 List : out Elist_Id;
4281 Use_Full_View : Boolean := True)
4283 Current_Typ : Entity_Id := T;
4284 Parent_Typ : Entity_Id;
4287 List := New_Elmt_List;
4289 -- No action if the if the type has no parents
4291 if T = Etype (T) then
4296 Parent_Typ := Etype (Current_Typ);
4298 if Is_Private_Type (Parent_Typ)
4299 and then Present (Full_View (Parent_Typ))
4300 and then Use_Full_View
4302 Parent_Typ := Full_View (Base_Type (Parent_Typ));
4305 Append_Elmt (Parent_Typ, List);
4307 exit when Parent_Typ = Current_Typ;
4308 Current_Typ := Parent_Typ;
4310 end Collect_Parents;
4312 ----------------------------------
4313 -- Collect_Primitive_Operations --
4314 ----------------------------------
4316 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
4317 B_Type : constant Entity_Id := Base_Type (T);
4318 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
4319 B_Scope : Entity_Id := Scope (B_Type);
4323 Is_Type_In_Pkg : Boolean;
4324 Formal_Derived : Boolean := False;
4327 function Match (E : Entity_Id) return Boolean;
4328 -- True if E's base type is B_Type, or E is of an anonymous access type
4329 -- and the base type of its designated type is B_Type.
4335 function Match (E : Entity_Id) return Boolean is
4336 Etyp : Entity_Id := Etype (E);
4339 if Ekind (Etyp) = E_Anonymous_Access_Type then
4340 Etyp := Designated_Type (Etyp);
4343 -- In Ada 2012 a primitive operation may have a formal of an
4344 -- incomplete view of the parent type.
4346 return Base_Type (Etyp) = B_Type
4348 (Ada_Version >= Ada_2012
4349 and then Ekind (Etyp) = E_Incomplete_Type
4350 and then Full_View (Etyp) = B_Type);
4353 -- Start of processing for Collect_Primitive_Operations
4356 -- For tagged types, the primitive operations are collected as they
4357 -- are declared, and held in an explicit list which is simply returned.
4359 if Is_Tagged_Type (B_Type) then
4360 return Primitive_Operations (B_Type);
4362 -- An untagged generic type that is a derived type inherits the
4363 -- primitive operations of its parent type. Other formal types only
4364 -- have predefined operators, which are not explicitly represented.
4366 elsif Is_Generic_Type (B_Type) then
4367 if Nkind (B_Decl) = N_Formal_Type_Declaration
4368 and then Nkind (Formal_Type_Definition (B_Decl)) =
4369 N_Formal_Derived_Type_Definition
4371 Formal_Derived := True;
4373 return New_Elmt_List;
4377 Op_List := New_Elmt_List;
4379 if B_Scope = Standard_Standard then
4380 if B_Type = Standard_String then
4381 Append_Elmt (Standard_Op_Concat, Op_List);
4383 elsif B_Type = Standard_Wide_String then
4384 Append_Elmt (Standard_Op_Concatw, Op_List);
4390 -- Locate the primitive subprograms of the type
4393 -- The primitive operations appear after the base type, except
4394 -- if the derivation happens within the private part of B_Scope
4395 -- and the type is a private type, in which case both the type
4396 -- and some primitive operations may appear before the base
4397 -- type, and the list of candidates starts after the type.
4399 if In_Open_Scopes (B_Scope)
4400 and then Scope (T) = B_Scope
4401 and then In_Private_Part (B_Scope)
4403 Id := Next_Entity (T);
4405 -- In Ada 2012, If the type has an incomplete partial view, there
4406 -- may be primitive operations declared before the full view, so
4407 -- we need to start scanning from the incomplete view, which is
4408 -- earlier on the entity chain.
4410 elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration
4411 and then Present (Incomplete_View (Parent (B_Type)))
4413 Id := Defining_Entity (Incomplete_View (Parent (B_Type)));
4415 -- If T is a derived from a type with an incomplete view declared
4416 -- elsewhere, that incomplete view is irrelevant, we want the
4417 -- operations in the scope of T.
4419 if Scope (Id) /= Scope (B_Type) then
4420 Id := Next_Entity (B_Type);
4424 Id := Next_Entity (B_Type);
4427 -- Set flag if this is a type in a package spec
4430 Is_Package_Or_Generic_Package (B_Scope)
4432 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
4435 while Present (Id) loop
4437 -- Test whether the result type or any of the parameter types of
4438 -- each subprogram following the type match that type when the
4439 -- type is declared in a package spec, is a derived type, or the
4440 -- subprogram is marked as primitive. (The Is_Primitive test is
4441 -- needed to find primitives of nonderived types in declarative
4442 -- parts that happen to override the predefined "=" operator.)
4444 -- Note that generic formal subprograms are not considered to be
4445 -- primitive operations and thus are never inherited.
4447 if Is_Overloadable (Id)
4448 and then (Is_Type_In_Pkg
4449 or else Is_Derived_Type (B_Type)
4450 or else Is_Primitive (Id))
4451 and then Nkind (Parent (Parent (Id)))
4452 not in N_Formal_Subprogram_Declaration
4460 Formal := First_Formal (Id);
4461 while Present (Formal) loop
4462 if Match (Formal) then
4467 Next_Formal (Formal);
4471 -- For a formal derived type, the only primitives are the ones
4472 -- inherited from the parent type. Operations appearing in the
4473 -- package declaration are not primitive for it.
4476 and then (not Formal_Derived or else Present (Alias (Id)))
4478 -- In the special case of an equality operator aliased to
4479 -- an overriding dispatching equality belonging to the same
4480 -- type, we don't include it in the list of primitives.
4481 -- This avoids inheriting multiple equality operators when
4482 -- deriving from untagged private types whose full type is
4483 -- tagged, which can otherwise cause ambiguities. Note that
4484 -- this should only happen for this kind of untagged parent
4485 -- type, since normally dispatching operations are inherited
4486 -- using the type's Primitive_Operations list.
4488 if Chars (Id) = Name_Op_Eq
4489 and then Is_Dispatching_Operation (Id)
4490 and then Present (Alias (Id))
4491 and then Present (Overridden_Operation (Alias (Id)))
4492 and then Base_Type (Etype (First_Entity (Id))) =
4493 Base_Type (Etype (First_Entity (Alias (Id))))
4497 -- Include the subprogram in the list of primitives
4500 Append_Elmt (Id, Op_List);
4507 -- For a type declared in System, some of its operations may
4508 -- appear in the target-specific extension to System.
4511 and then B_Scope = RTU_Entity (System)
4512 and then Present_System_Aux
4514 B_Scope := System_Aux_Id;
4515 Id := First_Entity (System_Aux_Id);
4521 end Collect_Primitive_Operations;
4523 -----------------------------------
4524 -- Compile_Time_Constraint_Error --
4525 -----------------------------------
4527 function Compile_Time_Constraint_Error
4530 Ent : Entity_Id := Empty;
4531 Loc : Source_Ptr := No_Location;
4532 Warn : Boolean := False) return Node_Id
4534 Msgc : String (1 .. Msg'Length + 3);
4535 -- Copy of message, with room for possible ?? or << and ! at end
4541 -- Start of processing for Compile_Time_Constraint_Error
4544 -- If this is a warning, convert it into an error if we are in code
4545 -- subject to SPARK_Mode being set On, unless Warn is True to force a
4546 -- warning. The rationale is that a compile-time constraint error should
4547 -- lead to an error instead of a warning when SPARK_Mode is On, but in
4548 -- a few cases we prefer to issue a warning and generate both a suitable
4549 -- run-time error in GNAT and a suitable check message in GNATprove.
4550 -- Those cases are those that likely correspond to deactivated SPARK
4551 -- code, so that this kind of code can be compiled and analyzed instead
4552 -- of being rejected.
4554 Error_Msg_Warn := Warn or SPARK_Mode /= On;
4556 -- A static constraint error in an instance body is not a fatal error.
4557 -- we choose to inhibit the message altogether, because there is no
4558 -- obvious node (for now) on which to post it. On the other hand the
4559 -- offending node must be replaced with a constraint_error in any case.
4561 -- No messages are generated if we already posted an error on this node
4563 if not Error_Posted (N) then
4564 if Loc /= No_Location then
4570 -- Copy message to Msgc, converting any ? in the message into
4571 -- < instead, so that we have an error in GNATprove mode.
4575 for J in 1 .. Msgl loop
4576 if Msg (J) = '?' and then (J = 1 or else Msg (J - 1) /= ''') then
4579 Msgc (J) := Msg (J);
4583 -- Message is a warning, even in Ada 95 case
4585 if Msg (Msg'Last) = '?' or else Msg (Msg'Last) = '<' then
4588 -- In Ada 83, all messages are warnings. In the private part and
4589 -- the body of an instance, constraint_checks are only warnings.
4590 -- We also make this a warning if the Warn parameter is set.
4593 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
4601 elsif In_Instance_Not_Visible then
4608 -- Otherwise we have a real error message (Ada 95 static case)
4609 -- and we make this an unconditional message. Note that in the
4610 -- warning case we do not make the message unconditional, it seems
4611 -- quite reasonable to delete messages like this (about exceptions
4612 -- that will be raised) in dead code.
4620 -- One more test, skip the warning if the related expression is
4621 -- statically unevaluated, since we don't want to warn about what
4622 -- will happen when something is evaluated if it never will be
4625 if not Is_Statically_Unevaluated (N) then
4626 if Present (Ent) then
4627 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
4629 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
4634 -- Check whether the context is an Init_Proc
4636 if Inside_Init_Proc then
4638 Conc_Typ : constant Entity_Id :=
4639 Corresponding_Concurrent_Type
4640 (Entity (Parameter_Type (First
4641 (Parameter_Specifications
4642 (Parent (Current_Scope))))));
4645 -- Don't complain if the corresponding concurrent type
4646 -- doesn't come from source (i.e. a single task/protected
4649 if Present (Conc_Typ)
4650 and then not Comes_From_Source (Conc_Typ)
4653 ("\& [<<", N, Standard_Constraint_Error, Eloc);
4656 if GNATprove_Mode then
4658 ("\& would have been raised for objects of this "
4659 & "type", N, Standard_Constraint_Error, Eloc);
4662 ("\& will be raised for objects of this type??",
4663 N, Standard_Constraint_Error, Eloc);
4669 Error_Msg_NEL ("\& [<<", N, Standard_Constraint_Error, Eloc);
4673 Error_Msg ("\static expression fails Constraint_Check", Eloc);
4674 Set_Error_Posted (N);
4680 end Compile_Time_Constraint_Error;
4682 -----------------------
4683 -- Conditional_Delay --
4684 -----------------------
4686 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
4688 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
4689 Set_Has_Delayed_Freeze (New_Ent);
4691 end Conditional_Delay;
4693 ----------------------------
4694 -- Contains_Refined_State --
4695 ----------------------------
4697 function Contains_Refined_State (Prag : Node_Id) return Boolean is
4698 function Has_State_In_Dependency (List : Node_Id) return Boolean;
4699 -- Determine whether a dependency list mentions a state with a visible
4702 function Has_State_In_Global (List : Node_Id) return Boolean;
4703 -- Determine whether a global list mentions a state with a visible
4706 function Is_Refined_State (Item : Node_Id) return Boolean;
4707 -- Determine whether Item is a reference to an abstract state with a
4708 -- visible refinement.
4710 -----------------------------
4711 -- Has_State_In_Dependency --
4712 -----------------------------
4714 function Has_State_In_Dependency (List : Node_Id) return Boolean is
4719 -- A null dependency list does not mention any states
4721 if Nkind (List) = N_Null then
4724 -- Dependency clauses appear as component associations of an
4727 elsif Nkind (List) = N_Aggregate
4728 and then Present (Component_Associations (List))
4730 Clause := First (Component_Associations (List));
4731 while Present (Clause) loop
4733 -- Inspect the outputs of a dependency clause
4735 Output := First (Choices (Clause));
4736 while Present (Output) loop
4737 if Is_Refined_State (Output) then
4744 -- Inspect the outputs of a dependency clause
4746 if Is_Refined_State (Expression (Clause)) then
4753 -- If we get here, then none of the dependency clauses mention a
4754 -- state with visible refinement.
4758 -- An illegal pragma managed to sneak in
4761 raise Program_Error;
4763 end Has_State_In_Dependency;
4765 -------------------------
4766 -- Has_State_In_Global --
4767 -------------------------
4769 function Has_State_In_Global (List : Node_Id) return Boolean is
4773 -- A null global list does not mention any states
4775 if Nkind (List) = N_Null then
4778 -- Simple global list or moded global list declaration
4780 elsif Nkind (List) = N_Aggregate then
4782 -- The declaration of a simple global list appear as a collection
4785 if Present (Expressions (List)) then
4786 Item := First (Expressions (List));
4787 while Present (Item) loop
4788 if Is_Refined_State (Item) then
4795 -- The declaration of a moded global list appears as a collection
4796 -- of component associations where individual choices denote
4800 Item := First (Component_Associations (List));
4801 while Present (Item) loop
4802 if Has_State_In_Global (Expression (Item)) then
4810 -- If we get here, then the simple/moded global list did not
4811 -- mention any states with a visible refinement.
4815 -- Single global item declaration
4817 elsif Is_Entity_Name (List) then
4818 return Is_Refined_State (List);
4820 -- An illegal pragma managed to sneak in
4823 raise Program_Error;
4825 end Has_State_In_Global;
4827 ----------------------
4828 -- Is_Refined_State --
4829 ----------------------
4831 function Is_Refined_State (Item : Node_Id) return Boolean is
4833 Item_Id : Entity_Id;
4836 if Nkind (Item) = N_Null then
4839 -- States cannot be subject to attribute 'Result. This case arises
4840 -- in dependency relations.
4842 elsif Nkind (Item) = N_Attribute_Reference
4843 and then Attribute_Name (Item) = Name_Result
4847 -- Multiple items appear as an aggregate. This case arises in
4848 -- dependency relations.
4850 elsif Nkind (Item) = N_Aggregate
4851 and then Present (Expressions (Item))
4853 Elmt := First (Expressions (Item));
4854 while Present (Elmt) loop
4855 if Is_Refined_State (Elmt) then
4862 -- If we get here, then none of the inputs or outputs reference a
4863 -- state with visible refinement.
4870 Item_Id := Entity_Of (Item);
4874 and then Ekind (Item_Id) = E_Abstract_State
4875 and then Has_Visible_Refinement (Item_Id);
4877 end Is_Refined_State;
4881 Arg : constant Node_Id :=
4882 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
4883 Nam : constant Name_Id := Pragma_Name (Prag);
4885 -- Start of processing for Contains_Refined_State
4888 if Nam = Name_Depends then
4889 return Has_State_In_Dependency (Arg);
4891 else pragma Assert (Nam = Name_Global);
4892 return Has_State_In_Global (Arg);
4894 end Contains_Refined_State;
4896 -------------------------
4897 -- Copy_Component_List --
4898 -------------------------
4900 function Copy_Component_List
4902 Loc : Source_Ptr) return List_Id
4905 Comps : constant List_Id := New_List;
4908 Comp := First_Component (Underlying_Type (R_Typ));
4909 while Present (Comp) loop
4910 if Comes_From_Source (Comp) then
4912 Comp_Decl : constant Node_Id := Declaration_Node (Comp);
4915 Make_Component_Declaration (Loc,
4916 Defining_Identifier =>
4917 Make_Defining_Identifier (Loc, Chars (Comp)),
4918 Component_Definition =>
4920 (Component_Definition (Comp_Decl), New_Sloc => Loc)));
4924 Next_Component (Comp);
4928 end Copy_Component_List;
4930 -------------------------
4931 -- Copy_Parameter_List --
4932 -------------------------
4934 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
4935 Loc : constant Source_Ptr := Sloc (Subp_Id);
4940 if No (First_Formal (Subp_Id)) then
4944 Formal := First_Formal (Subp_Id);
4945 while Present (Formal) loop
4947 Make_Parameter_Specification (Loc,
4948 Defining_Identifier =>
4949 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
4950 In_Present => In_Present (Parent (Formal)),
4951 Out_Present => Out_Present (Parent (Formal)),
4953 New_Occurrence_Of (Etype (Formal), Loc),
4955 New_Copy_Tree (Expression (Parent (Formal)))));
4957 Next_Formal (Formal);
4962 end Copy_Parameter_List;
4964 --------------------------
4965 -- Copy_Subprogram_Spec --
4966 --------------------------
4968 function Copy_Subprogram_Spec (Spec : Node_Id) return Node_Id is
4970 Formal_Spec : Node_Id;
4974 -- The structure of the original tree must be replicated without any
4975 -- alterations. Use New_Copy_Tree for this purpose.
4977 Result := New_Copy_Tree (Spec);
4979 -- Create a new entity for the defining unit name
4981 Def_Id := Defining_Unit_Name (Result);
4982 Set_Defining_Unit_Name (Result,
4983 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
4985 -- Create new entities for the formal parameters
4987 if Present (Parameter_Specifications (Result)) then
4988 Formal_Spec := First (Parameter_Specifications (Result));
4989 while Present (Formal_Spec) loop
4990 Def_Id := Defining_Identifier (Formal_Spec);
4991 Set_Defining_Identifier (Formal_Spec,
4992 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
4999 end Copy_Subprogram_Spec;
5001 --------------------------------
5002 -- Corresponding_Generic_Type --
5003 --------------------------------
5005 function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id is
5011 if not Is_Generic_Actual_Type (T) then
5014 -- If the actual is the actual of an enclosing instance, resolution
5015 -- was correct in the generic.
5017 elsif Nkind (Parent (T)) = N_Subtype_Declaration
5018 and then Is_Entity_Name (Subtype_Indication (Parent (T)))
5020 Is_Generic_Actual_Type (Entity (Subtype_Indication (Parent (T))))
5027 if Is_Wrapper_Package (Inst) then
5028 Inst := Related_Instance (Inst);
5033 (Specification (Unit_Declaration_Node (Inst)));
5035 -- Generic actual has the same name as the corresponding formal
5037 Typ := First_Entity (Gen);
5038 while Present (Typ) loop
5039 if Chars (Typ) = Chars (T) then
5048 end Corresponding_Generic_Type;
5050 --------------------
5051 -- Current_Entity --
5052 --------------------
5054 -- The currently visible definition for a given identifier is the
5055 -- one most chained at the start of the visibility chain, i.e. the
5056 -- one that is referenced by the Node_Id value of the name of the
5057 -- given identifier.
5059 function Current_Entity (N : Node_Id) return Entity_Id is
5061 return Get_Name_Entity_Id (Chars (N));
5064 -----------------------------
5065 -- Current_Entity_In_Scope --
5066 -----------------------------
5068 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
5070 CS : constant Entity_Id := Current_Scope;
5072 Transient_Case : constant Boolean := Scope_Is_Transient;
5075 E := Get_Name_Entity_Id (Chars (N));
5077 and then Scope (E) /= CS
5078 and then (not Transient_Case or else Scope (E) /= Scope (CS))
5084 end Current_Entity_In_Scope;
5090 function Current_Scope return Entity_Id is
5092 if Scope_Stack.Last = -1 then
5093 return Standard_Standard;
5096 C : constant Entity_Id :=
5097 Scope_Stack.Table (Scope_Stack.Last).Entity;
5102 return Standard_Standard;
5108 ----------------------------
5109 -- Current_Scope_No_Loops --
5110 ----------------------------
5112 function Current_Scope_No_Loops return Entity_Id is
5116 -- Examine the scope stack starting from the current scope and skip any
5117 -- internally generated loops.
5120 while Present (S) and then S /= Standard_Standard loop
5121 if Ekind (S) = E_Loop and then not Comes_From_Source (S) then
5129 end Current_Scope_No_Loops;
5131 ------------------------
5132 -- Current_Subprogram --
5133 ------------------------
5135 function Current_Subprogram return Entity_Id is
5136 Scop : constant Entity_Id := Current_Scope;
5138 if Is_Subprogram_Or_Generic_Subprogram (Scop) then
5141 return Enclosing_Subprogram (Scop);
5143 end Current_Subprogram;
5145 ----------------------------------
5146 -- Deepest_Type_Access_Level --
5147 ----------------------------------
5149 function Deepest_Type_Access_Level (Typ : Entity_Id) return Uint is
5151 if Ekind (Typ) = E_Anonymous_Access_Type
5152 and then not Is_Local_Anonymous_Access (Typ)
5153 and then Nkind (Associated_Node_For_Itype (Typ)) = N_Object_Declaration
5155 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
5159 Scope_Depth (Enclosing_Dynamic_Scope
5160 (Defining_Identifier
5161 (Associated_Node_For_Itype (Typ))));
5163 -- For generic formal type, return Int'Last (infinite).
5164 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
5166 elsif Is_Generic_Type (Root_Type (Typ)) then
5167 return UI_From_Int (Int'Last);
5170 return Type_Access_Level (Typ);
5172 end Deepest_Type_Access_Level;
5174 ---------------------
5175 -- Defining_Entity --
5176 ---------------------
5178 function Defining_Entity
5180 Empty_On_Errors : Boolean := False) return Entity_Id
5182 Err : Entity_Id := Empty;
5186 when N_Abstract_Subprogram_Declaration |
5187 N_Expression_Function |
5188 N_Formal_Subprogram_Declaration |
5189 N_Generic_Package_Declaration |
5190 N_Generic_Subprogram_Declaration |
5191 N_Package_Declaration |
5193 N_Subprogram_Body_Stub |
5194 N_Subprogram_Declaration |
5195 N_Subprogram_Renaming_Declaration
5197 return Defining_Entity (Specification (N));
5199 when N_Component_Declaration |
5200 N_Defining_Program_Unit_Name |
5201 N_Discriminant_Specification |
5203 N_Entry_Declaration |
5204 N_Entry_Index_Specification |
5205 N_Exception_Declaration |
5206 N_Exception_Renaming_Declaration |
5207 N_Formal_Object_Declaration |
5208 N_Formal_Package_Declaration |
5209 N_Formal_Type_Declaration |
5210 N_Full_Type_Declaration |
5211 N_Implicit_Label_Declaration |
5212 N_Incomplete_Type_Declaration |
5213 N_Loop_Parameter_Specification |
5214 N_Number_Declaration |
5215 N_Object_Declaration |
5216 N_Object_Renaming_Declaration |
5217 N_Package_Body_Stub |
5218 N_Parameter_Specification |
5219 N_Private_Extension_Declaration |
5220 N_Private_Type_Declaration |
5222 N_Protected_Body_Stub |
5223 N_Protected_Type_Declaration |
5224 N_Single_Protected_Declaration |
5225 N_Single_Task_Declaration |
5226 N_Subtype_Declaration |
5229 N_Task_Type_Declaration
5231 return Defining_Identifier (N);
5234 return Defining_Entity (Proper_Body (N));
5236 when N_Function_Instantiation |
5237 N_Function_Specification |
5238 N_Generic_Function_Renaming_Declaration |
5239 N_Generic_Package_Renaming_Declaration |
5240 N_Generic_Procedure_Renaming_Declaration |
5242 N_Package_Instantiation |
5243 N_Package_Renaming_Declaration |
5244 N_Package_Specification |
5245 N_Procedure_Instantiation |
5246 N_Procedure_Specification
5249 Nam : constant Node_Id := Defining_Unit_Name (N);
5252 if Nkind (Nam) in N_Entity then
5255 -- For Error, make up a name and attach to declaration so we
5256 -- can continue semantic analysis.
5258 elsif Nam = Error then
5259 if Empty_On_Errors then
5262 Err := Make_Temporary (Sloc (N), 'T');
5263 Set_Defining_Unit_Name (N, Err);
5268 -- If not an entity, get defining identifier
5271 return Defining_Identifier (Nam);
5275 when N_Block_Statement |
5277 return Entity (Identifier (N));
5280 if Empty_On_Errors then
5283 raise Program_Error;
5287 end Defining_Entity;
5289 --------------------------
5290 -- Denotes_Discriminant --
5291 --------------------------
5293 function Denotes_Discriminant
5295 Check_Concurrent : Boolean := False) return Boolean
5300 if not Is_Entity_Name (N) or else No (Entity (N)) then
5306 -- If we are checking for a protected type, the discriminant may have
5307 -- been rewritten as the corresponding discriminal of the original type
5308 -- or of the corresponding concurrent record, depending on whether we
5309 -- are in the spec or body of the protected type.
5311 return Ekind (E) = E_Discriminant
5314 and then Ekind (E) = E_In_Parameter
5315 and then Present (Discriminal_Link (E))
5317 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
5319 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
5320 end Denotes_Discriminant;
5322 -------------------------
5323 -- Denotes_Same_Object --
5324 -------------------------
5326 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
5327 Obj1 : Node_Id := A1;
5328 Obj2 : Node_Id := A2;
5330 function Has_Prefix (N : Node_Id) return Boolean;
5331 -- Return True if N has attribute Prefix
5333 function Is_Renaming (N : Node_Id) return Boolean;
5334 -- Return true if N names a renaming entity
5336 function Is_Valid_Renaming (N : Node_Id) return Boolean;
5337 -- For renamings, return False if the prefix of any dereference within
5338 -- the renamed object_name is a variable, or any expression within the
5339 -- renamed object_name contains references to variables or calls on
5340 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
5346 function Has_Prefix (N : Node_Id) return Boolean is
5350 N_Attribute_Reference,
5352 N_Explicit_Dereference,
5353 N_Indexed_Component,
5355 N_Selected_Component,
5363 function Is_Renaming (N : Node_Id) return Boolean is
5365 return Is_Entity_Name (N)
5366 and then Present (Renamed_Entity (Entity (N)));
5369 -----------------------
5370 -- Is_Valid_Renaming --
5371 -----------------------
5373 function Is_Valid_Renaming (N : Node_Id) return Boolean is
5375 function Check_Renaming (N : Node_Id) return Boolean;
5376 -- Recursive function used to traverse all the prefixes of N
5378 function Check_Renaming (N : Node_Id) return Boolean is
5381 and then not Check_Renaming (Renamed_Entity (Entity (N)))
5386 if Nkind (N) = N_Indexed_Component then
5391 Indx := First (Expressions (N));
5392 while Present (Indx) loop
5393 if not Is_OK_Static_Expression (Indx) then
5402 if Has_Prefix (N) then
5404 P : constant Node_Id := Prefix (N);
5407 if Nkind (N) = N_Explicit_Dereference
5408 and then Is_Variable (P)
5412 elsif Is_Entity_Name (P)
5413 and then Ekind (Entity (P)) = E_Function
5417 elsif Nkind (P) = N_Function_Call then
5421 -- Recursion to continue traversing the prefix of the
5422 -- renaming expression
5424 return Check_Renaming (P);
5431 -- Start of processing for Is_Valid_Renaming
5434 return Check_Renaming (N);
5435 end Is_Valid_Renaming;
5437 -- Start of processing for Denotes_Same_Object
5440 -- Both names statically denote the same stand-alone object or parameter
5441 -- (RM 6.4.1(6.5/3))
5443 if Is_Entity_Name (Obj1)
5444 and then Is_Entity_Name (Obj2)
5445 and then Entity (Obj1) = Entity (Obj2)
5450 -- For renamings, the prefix of any dereference within the renamed
5451 -- object_name is not a variable, and any expression within the
5452 -- renamed object_name contains no references to variables nor
5453 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
5455 if Is_Renaming (Obj1) then
5456 if Is_Valid_Renaming (Obj1) then
5457 Obj1 := Renamed_Entity (Entity (Obj1));
5463 if Is_Renaming (Obj2) then
5464 if Is_Valid_Renaming (Obj2) then
5465 Obj2 := Renamed_Entity (Entity (Obj2));
5471 -- No match if not same node kind (such cases are handled by
5472 -- Denotes_Same_Prefix)
5474 if Nkind (Obj1) /= Nkind (Obj2) then
5477 -- After handling valid renamings, one of the two names statically
5478 -- denoted a renaming declaration whose renamed object_name is known
5479 -- to denote the same object as the other (RM 6.4.1(6.10/3))
5481 elsif Is_Entity_Name (Obj1) then
5482 if Is_Entity_Name (Obj2) then
5483 return Entity (Obj1) = Entity (Obj2);
5488 -- Both names are selected_components, their prefixes are known to
5489 -- denote the same object, and their selector_names denote the same
5490 -- component (RM 6.4.1(6.6/3)).
5492 elsif Nkind (Obj1) = N_Selected_Component then
5493 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
5495 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
5497 -- Both names are dereferences and the dereferenced names are known to
5498 -- denote the same object (RM 6.4.1(6.7/3))
5500 elsif Nkind (Obj1) = N_Explicit_Dereference then
5501 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
5503 -- Both names are indexed_components, their prefixes are known to denote
5504 -- the same object, and each of the pairs of corresponding index values
5505 -- are either both static expressions with the same static value or both
5506 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
5508 elsif Nkind (Obj1) = N_Indexed_Component then
5509 if not Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
5517 Indx1 := First (Expressions (Obj1));
5518 Indx2 := First (Expressions (Obj2));
5519 while Present (Indx1) loop
5521 -- Indexes must denote the same static value or same object
5523 if Is_OK_Static_Expression (Indx1) then
5524 if not Is_OK_Static_Expression (Indx2) then
5527 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
5531 elsif not Denotes_Same_Object (Indx1, Indx2) then
5543 -- Both names are slices, their prefixes are known to denote the same
5544 -- object, and the two slices have statically matching index constraints
5545 -- (RM 6.4.1(6.9/3))
5547 elsif Nkind (Obj1) = N_Slice
5548 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
5551 Lo1, Lo2, Hi1, Hi2 : Node_Id;
5554 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
5555 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
5557 -- Check whether bounds are statically identical. There is no
5558 -- attempt to detect partial overlap of slices.
5560 return Denotes_Same_Object (Lo1, Lo2)
5562 Denotes_Same_Object (Hi1, Hi2);
5565 -- In the recursion, literals appear as indexes
5567 elsif Nkind (Obj1) = N_Integer_Literal
5569 Nkind (Obj2) = N_Integer_Literal
5571 return Intval (Obj1) = Intval (Obj2);
5576 end Denotes_Same_Object;
5578 -------------------------
5579 -- Denotes_Same_Prefix --
5580 -------------------------
5582 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
5584 if Is_Entity_Name (A1) then
5585 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
5586 and then not Is_Access_Type (Etype (A1))
5588 return Denotes_Same_Object (A1, Prefix (A2))
5589 or else Denotes_Same_Prefix (A1, Prefix (A2));
5594 elsif Is_Entity_Name (A2) then
5595 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
5597 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
5599 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
5602 Root1, Root2 : Node_Id;
5603 Depth1, Depth2 : Nat := 0;
5606 Root1 := Prefix (A1);
5607 while not Is_Entity_Name (Root1) loop
5609 (Root1, N_Selected_Component, N_Indexed_Component)
5613 Root1 := Prefix (Root1);
5616 Depth1 := Depth1 + 1;
5619 Root2 := Prefix (A2);
5620 while not Is_Entity_Name (Root2) loop
5621 if not Nkind_In (Root2, N_Selected_Component,
5622 N_Indexed_Component)
5626 Root2 := Prefix (Root2);
5629 Depth2 := Depth2 + 1;
5632 -- If both have the same depth and they do not denote the same
5633 -- object, they are disjoint and no warning is needed.
5635 if Depth1 = Depth2 then
5638 elsif Depth1 > Depth2 then
5639 Root1 := Prefix (A1);
5640 for J in 1 .. Depth1 - Depth2 - 1 loop
5641 Root1 := Prefix (Root1);
5644 return Denotes_Same_Object (Root1, A2);
5647 Root2 := Prefix (A2);
5648 for J in 1 .. Depth2 - Depth1 - 1 loop
5649 Root2 := Prefix (Root2);
5652 return Denotes_Same_Object (A1, Root2);
5659 end Denotes_Same_Prefix;
5661 ----------------------
5662 -- Denotes_Variable --
5663 ----------------------
5665 function Denotes_Variable (N : Node_Id) return Boolean is
5667 return Is_Variable (N) and then Paren_Count (N) = 0;
5668 end Denotes_Variable;
5670 -----------------------------
5671 -- Depends_On_Discriminant --
5672 -----------------------------
5674 function Depends_On_Discriminant (N : Node_Id) return Boolean is
5679 Get_Index_Bounds (N, L, H);
5680 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
5681 end Depends_On_Discriminant;
5683 -------------------------
5684 -- Designate_Same_Unit --
5685 -------------------------
5687 function Designate_Same_Unit
5689 Name2 : Node_Id) return Boolean
5691 K1 : constant Node_Kind := Nkind (Name1);
5692 K2 : constant Node_Kind := Nkind (Name2);
5694 function Prefix_Node (N : Node_Id) return Node_Id;
5695 -- Returns the parent unit name node of a defining program unit name
5696 -- or the prefix if N is a selected component or an expanded name.
5698 function Select_Node (N : Node_Id) return Node_Id;
5699 -- Returns the defining identifier node of a defining program unit
5700 -- name or the selector node if N is a selected component or an
5707 function Prefix_Node (N : Node_Id) return Node_Id is
5709 if Nkind (N) = N_Defining_Program_Unit_Name then
5720 function Select_Node (N : Node_Id) return Node_Id is
5722 if Nkind (N) = N_Defining_Program_Unit_Name then
5723 return Defining_Identifier (N);
5725 return Selector_Name (N);
5729 -- Start of processing for Designate_Same_Unit
5732 if Nkind_In (K1, N_Identifier, N_Defining_Identifier)
5734 Nkind_In (K2, N_Identifier, N_Defining_Identifier)
5736 return Chars (Name1) = Chars (Name2);
5738 elsif Nkind_In (K1, N_Expanded_Name,
5739 N_Selected_Component,
5740 N_Defining_Program_Unit_Name)
5742 Nkind_In (K2, N_Expanded_Name,
5743 N_Selected_Component,
5744 N_Defining_Program_Unit_Name)
5747 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
5749 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
5754 end Designate_Same_Unit;
5756 ------------------------------------------
5757 -- function Dynamic_Accessibility_Level --
5758 ------------------------------------------
5760 function Dynamic_Accessibility_Level (Expr : Node_Id) return Node_Id is
5762 Loc : constant Source_Ptr := Sloc (Expr);
5764 function Make_Level_Literal (Level : Uint) return Node_Id;
5765 -- Construct an integer literal representing an accessibility level
5766 -- with its type set to Natural.
5768 ------------------------
5769 -- Make_Level_Literal --
5770 ------------------------
5772 function Make_Level_Literal (Level : Uint) return Node_Id is
5773 Result : constant Node_Id := Make_Integer_Literal (Loc, Level);
5775 Set_Etype (Result, Standard_Natural);
5777 end Make_Level_Literal;
5779 -- Start of processing for Dynamic_Accessibility_Level
5782 if Is_Entity_Name (Expr) then
5785 if Present (Renamed_Object (E)) then
5786 return Dynamic_Accessibility_Level (Renamed_Object (E));
5789 if Is_Formal (E) or else Ekind_In (E, E_Variable, E_Constant) then
5790 if Present (Extra_Accessibility (E)) then
5791 return New_Occurrence_Of (Extra_Accessibility (E), Loc);
5796 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
5798 case Nkind (Expr) is
5800 -- For access discriminant, the level of the enclosing object
5802 when N_Selected_Component =>
5803 if Ekind (Entity (Selector_Name (Expr))) = E_Discriminant
5804 and then Ekind (Etype (Entity (Selector_Name (Expr)))) =
5805 E_Anonymous_Access_Type
5807 return Make_Level_Literal (Object_Access_Level (Expr));
5810 when N_Attribute_Reference =>
5811 case Get_Attribute_Id (Attribute_Name (Expr)) is
5813 -- For X'Access, the level of the prefix X
5815 when Attribute_Access =>
5816 return Make_Level_Literal
5817 (Object_Access_Level (Prefix (Expr)));
5819 -- Treat the unchecked attributes as library-level
5821 when Attribute_Unchecked_Access |
5822 Attribute_Unrestricted_Access =>
5823 return Make_Level_Literal (Scope_Depth (Standard_Standard));
5825 -- No other access-valued attributes
5828 raise Program_Error;
5833 -- Unimplemented: depends on context. As an actual parameter where
5834 -- formal type is anonymous, use
5835 -- Scope_Depth (Current_Scope) + 1.
5836 -- For other cases, see 3.10.2(14/3) and following. ???
5840 when N_Type_Conversion =>
5841 if not Is_Local_Anonymous_Access (Etype (Expr)) then
5843 -- Handle type conversions introduced for a rename of an
5844 -- Ada 2012 stand-alone object of an anonymous access type.
5846 return Dynamic_Accessibility_Level (Expression (Expr));
5853 return Make_Level_Literal (Type_Access_Level (Etype (Expr)));
5854 end Dynamic_Accessibility_Level;
5856 -----------------------------------
5857 -- Effective_Extra_Accessibility --
5858 -----------------------------------
5860 function Effective_Extra_Accessibility (Id : Entity_Id) return Entity_Id is
5862 if Present (Renamed_Object (Id))
5863 and then Is_Entity_Name (Renamed_Object (Id))
5865 return Effective_Extra_Accessibility (Entity (Renamed_Object (Id)));
5867 return Extra_Accessibility (Id);
5869 end Effective_Extra_Accessibility;
5871 -----------------------------
5872 -- Effective_Reads_Enabled --
5873 -----------------------------
5875 function Effective_Reads_Enabled (Id : Entity_Id) return Boolean is
5877 return Has_Enabled_Property (Id, Name_Effective_Reads);
5878 end Effective_Reads_Enabled;
5880 ------------------------------
5881 -- Effective_Writes_Enabled --
5882 ------------------------------
5884 function Effective_Writes_Enabled (Id : Entity_Id) return Boolean is
5886 return Has_Enabled_Property (Id, Name_Effective_Writes);
5887 end Effective_Writes_Enabled;
5889 ------------------------------
5890 -- Enclosing_Comp_Unit_Node --
5891 ------------------------------
5893 function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id is
5894 Current_Node : Node_Id;
5898 while Present (Current_Node)
5899 and then Nkind (Current_Node) /= N_Compilation_Unit
5901 Current_Node := Parent (Current_Node);
5904 if Nkind (Current_Node) /= N_Compilation_Unit then
5907 return Current_Node;
5909 end Enclosing_Comp_Unit_Node;
5911 --------------------------
5912 -- Enclosing_CPP_Parent --
5913 --------------------------
5915 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
5916 Parent_Typ : Entity_Id := Typ;
5919 while not Is_CPP_Class (Parent_Typ)
5920 and then Etype (Parent_Typ) /= Parent_Typ
5922 Parent_Typ := Etype (Parent_Typ);
5924 if Is_Private_Type (Parent_Typ) then
5925 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5929 pragma Assert (Is_CPP_Class (Parent_Typ));
5931 end Enclosing_CPP_Parent;
5933 ---------------------------
5934 -- Enclosing_Declaration --
5935 ---------------------------
5937 function Enclosing_Declaration (N : Node_Id) return Node_Id is
5938 Decl : Node_Id := N;
5941 while Present (Decl)
5942 and then not (Nkind (Decl) in N_Declaration
5944 Nkind (Decl) in N_Later_Decl_Item)
5946 Decl := Parent (Decl);
5950 end Enclosing_Declaration;
5952 ----------------------------
5953 -- Enclosing_Generic_Body --
5954 ----------------------------
5956 function Enclosing_Generic_Body
5957 (N : Node_Id) return Node_Id
5965 while Present (P) loop
5966 if Nkind (P) = N_Package_Body
5967 or else Nkind (P) = N_Subprogram_Body
5969 Spec := Corresponding_Spec (P);
5971 if Present (Spec) then
5972 Decl := Unit_Declaration_Node (Spec);
5974 if Nkind (Decl) = N_Generic_Package_Declaration
5975 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
5986 end Enclosing_Generic_Body;
5988 ----------------------------
5989 -- Enclosing_Generic_Unit --
5990 ----------------------------
5992 function Enclosing_Generic_Unit
5993 (N : Node_Id) return Node_Id
6001 while Present (P) loop
6002 if Nkind (P) = N_Generic_Package_Declaration
6003 or else Nkind (P) = N_Generic_Subprogram_Declaration
6007 elsif Nkind (P) = N_Package_Body
6008 or else Nkind (P) = N_Subprogram_Body
6010 Spec := Corresponding_Spec (P);
6012 if Present (Spec) then
6013 Decl := Unit_Declaration_Node (Spec);
6015 if Nkind (Decl) = N_Generic_Package_Declaration
6016 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
6027 end Enclosing_Generic_Unit;
6029 -------------------------------
6030 -- Enclosing_Lib_Unit_Entity --
6031 -------------------------------
6033 function Enclosing_Lib_Unit_Entity
6034 (E : Entity_Id := Current_Scope) return Entity_Id
6036 Unit_Entity : Entity_Id;
6039 -- Look for enclosing library unit entity by following scope links.
6040 -- Equivalent to, but faster than indexing through the scope stack.
6043 while (Present (Scope (Unit_Entity))
6044 and then Scope (Unit_Entity) /= Standard_Standard)
6045 and not Is_Child_Unit (Unit_Entity)
6047 Unit_Entity := Scope (Unit_Entity);
6051 end Enclosing_Lib_Unit_Entity;
6053 -----------------------------
6054 -- Enclosing_Lib_Unit_Node --
6055 -----------------------------
6057 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
6058 Encl_Unit : Node_Id;
6061 Encl_Unit := Enclosing_Comp_Unit_Node (N);
6062 while Present (Encl_Unit)
6063 and then Nkind (Unit (Encl_Unit)) = N_Subunit
6065 Encl_Unit := Library_Unit (Encl_Unit);
6068 pragma Assert (Nkind (Encl_Unit) = N_Compilation_Unit);
6070 end Enclosing_Lib_Unit_Node;
6072 -----------------------
6073 -- Enclosing_Package --
6074 -----------------------
6076 function Enclosing_Package (E : Entity_Id) return Entity_Id is
6077 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
6080 if Dynamic_Scope = Standard_Standard then
6081 return Standard_Standard;
6083 elsif Dynamic_Scope = Empty then
6086 elsif Ekind_In (Dynamic_Scope, E_Package, E_Package_Body,
6089 return Dynamic_Scope;
6092 return Enclosing_Package (Dynamic_Scope);
6094 end Enclosing_Package;
6096 -------------------------------------
6097 -- Enclosing_Package_Or_Subprogram --
6098 -------------------------------------
6100 function Enclosing_Package_Or_Subprogram (E : Entity_Id) return Entity_Id is
6105 while Present (S) loop
6106 if Is_Package_Or_Generic_Package (S)
6107 or else Ekind (S) = E_Package_Body
6111 elsif Is_Subprogram_Or_Generic_Subprogram (S)
6112 or else Ekind (S) = E_Subprogram_Body
6122 end Enclosing_Package_Or_Subprogram;
6124 --------------------------
6125 -- Enclosing_Subprogram --
6126 --------------------------
6128 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
6129 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
6132 if Dynamic_Scope = Standard_Standard then
6135 elsif Dynamic_Scope = Empty then
6138 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
6139 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
6141 elsif Ekind (Dynamic_Scope) = E_Block
6142 or else Ekind (Dynamic_Scope) = E_Return_Statement
6144 return Enclosing_Subprogram (Dynamic_Scope);
6146 elsif Ekind (Dynamic_Scope) = E_Task_Type then
6147 return Get_Task_Body_Procedure (Dynamic_Scope);
6149 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
6150 and then Present (Full_View (Dynamic_Scope))
6151 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
6153 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
6155 -- No body is generated if the protected operation is eliminated
6157 elsif Convention (Dynamic_Scope) = Convention_Protected
6158 and then not Is_Eliminated (Dynamic_Scope)
6159 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
6161 return Protected_Body_Subprogram (Dynamic_Scope);
6164 return Dynamic_Scope;
6166 end Enclosing_Subprogram;
6168 ------------------------
6169 -- Ensure_Freeze_Node --
6170 ------------------------
6172 procedure Ensure_Freeze_Node (E : Entity_Id) is
6175 if No (Freeze_Node (E)) then
6176 FN := Make_Freeze_Entity (Sloc (E));
6177 Set_Has_Delayed_Freeze (E);
6178 Set_Freeze_Node (E, FN);
6179 Set_Access_Types_To_Process (FN, No_Elist);
6180 Set_TSS_Elist (FN, No_Elist);
6183 end Ensure_Freeze_Node;
6189 procedure Enter_Name (Def_Id : Entity_Id) is
6190 C : constant Entity_Id := Current_Entity (Def_Id);
6191 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
6192 S : constant Entity_Id := Current_Scope;
6195 Generate_Definition (Def_Id);
6197 -- Add new name to current scope declarations. Check for duplicate
6198 -- declaration, which may or may not be a genuine error.
6202 -- Case of previous entity entered because of a missing declaration
6203 -- or else a bad subtype indication. Best is to use the new entity,
6204 -- and make the previous one invisible.
6206 if Etype (E) = Any_Type then
6207 Set_Is_Immediately_Visible (E, False);
6209 -- Case of renaming declaration constructed for package instances.
6210 -- if there is an explicit declaration with the same identifier,
6211 -- the renaming is not immediately visible any longer, but remains
6212 -- visible through selected component notation.
6214 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
6215 and then not Comes_From_Source (E)
6217 Set_Is_Immediately_Visible (E, False);
6219 -- The new entity may be the package renaming, which has the same
6220 -- same name as a generic formal which has been seen already.
6222 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
6223 and then not Comes_From_Source (Def_Id)
6225 Set_Is_Immediately_Visible (E, False);
6227 -- For a fat pointer corresponding to a remote access to subprogram,
6228 -- we use the same identifier as the RAS type, so that the proper
6229 -- name appears in the stub. This type is only retrieved through
6230 -- the RAS type and never by visibility, and is not added to the
6231 -- visibility list (see below).
6233 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
6234 and then Ekind (Def_Id) = E_Record_Type
6235 and then Present (Corresponding_Remote_Type (Def_Id))
6239 -- Case of an implicit operation or derived literal. The new entity
6240 -- hides the implicit one, which is removed from all visibility,
6241 -- i.e. the entity list of its scope, and homonym chain of its name.
6243 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
6244 or else Is_Internal (E)
6247 Decl : constant Node_Id := Parent (E);
6249 Prev_Vis : Entity_Id;
6252 -- If E is an implicit declaration, it cannot be the first
6253 -- entity in the scope.
6255 Prev := First_Entity (Current_Scope);
6256 while Present (Prev) and then Next_Entity (Prev) /= E loop
6262 -- If E is not on the entity chain of the current scope,
6263 -- it is an implicit declaration in the generic formal
6264 -- part of a generic subprogram. When analyzing the body,
6265 -- the generic formals are visible but not on the entity
6266 -- chain of the subprogram. The new entity will become
6267 -- the visible one in the body.
6270 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
6274 Set_Next_Entity (Prev, Next_Entity (E));
6276 if No (Next_Entity (Prev)) then
6277 Set_Last_Entity (Current_Scope, Prev);
6280 if E = Current_Entity (E) then
6284 Prev_Vis := Current_Entity (E);
6285 while Homonym (Prev_Vis) /= E loop
6286 Prev_Vis := Homonym (Prev_Vis);
6290 if Present (Prev_Vis) then
6292 -- Skip E in the visibility chain
6294 Set_Homonym (Prev_Vis, Homonym (E));
6297 Set_Name_Entity_Id (Chars (E), Homonym (E));
6302 -- This section of code could use a comment ???
6304 elsif Present (Etype (E))
6305 and then Is_Concurrent_Type (Etype (E))
6310 -- If the homograph is a protected component renaming, it should not
6311 -- be hiding the current entity. Such renamings are treated as weak
6314 elsif Is_Prival (E) then
6315 Set_Is_Immediately_Visible (E, False);
6317 -- In this case the current entity is a protected component renaming.
6318 -- Perform minimal decoration by setting the scope and return since
6319 -- the prival should not be hiding other visible entities.
6321 elsif Is_Prival (Def_Id) then
6322 Set_Scope (Def_Id, Current_Scope);
6325 -- Analogous to privals, the discriminal generated for an entry index
6326 -- parameter acts as a weak declaration. Perform minimal decoration
6327 -- to avoid bogus errors.
6329 elsif Is_Discriminal (Def_Id)
6330 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
6332 Set_Scope (Def_Id, Current_Scope);
6335 -- In the body or private part of an instance, a type extension may
6336 -- introduce a component with the same name as that of an actual. The
6337 -- legality rule is not enforced, but the semantics of the full type
6338 -- with two components of same name are not clear at this point???
6340 elsif In_Instance_Not_Visible then
6343 -- When compiling a package body, some child units may have become
6344 -- visible. They cannot conflict with local entities that hide them.
6346 elsif Is_Child_Unit (E)
6347 and then In_Open_Scopes (Scope (E))
6348 and then not Is_Immediately_Visible (E)
6352 -- Conversely, with front-end inlining we may compile the parent body
6353 -- first, and a child unit subsequently. The context is now the
6354 -- parent spec, and body entities are not visible.
6356 elsif Is_Child_Unit (Def_Id)
6357 and then Is_Package_Body_Entity (E)
6358 and then not In_Package_Body (Current_Scope)
6362 -- Case of genuine duplicate declaration
6365 Error_Msg_Sloc := Sloc (E);
6367 -- If the previous declaration is an incomplete type declaration
6368 -- this may be an attempt to complete it with a private type. The
6369 -- following avoids confusing cascaded errors.
6371 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
6372 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
6375 ("incomplete type cannot be completed with a private " &
6376 "declaration", Parent (Def_Id));
6377 Set_Is_Immediately_Visible (E, False);
6378 Set_Full_View (E, Def_Id);
6380 -- An inherited component of a record conflicts with a new
6381 -- discriminant. The discriminant is inserted first in the scope,
6382 -- but the error should be posted on it, not on the component.
6384 elsif Ekind (E) = E_Discriminant
6385 and then Present (Scope (Def_Id))
6386 and then Scope (Def_Id) /= Current_Scope
6388 Error_Msg_Sloc := Sloc (Def_Id);
6389 Error_Msg_N ("& conflicts with declaration#", E);
6392 -- If the name of the unit appears in its own context clause, a
6393 -- dummy package with the name has already been created, and the
6394 -- error emitted. Try to continue quietly.
6396 elsif Error_Posted (E)
6397 and then Sloc (E) = No_Location
6398 and then Nkind (Parent (E)) = N_Package_Specification
6399 and then Current_Scope = Standard_Standard
6401 Set_Scope (Def_Id, Current_Scope);
6405 Error_Msg_N ("& conflicts with declaration#", Def_Id);
6407 -- Avoid cascaded messages with duplicate components in
6410 if Ekind_In (E, E_Component, E_Discriminant) then
6415 if Nkind (Parent (Parent (Def_Id))) =
6416 N_Generic_Subprogram_Declaration
6418 Defining_Entity (Specification (Parent (Parent (Def_Id))))
6420 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
6423 -- If entity is in standard, then we are in trouble, because it
6424 -- means that we have a library package with a duplicated name.
6425 -- That's hard to recover from, so abort.
6427 if S = Standard_Standard then
6428 raise Unrecoverable_Error;
6430 -- Otherwise we continue with the declaration. Having two
6431 -- identical declarations should not cause us too much trouble.
6439 -- If we fall through, declaration is OK, at least OK enough to continue
6441 -- If Def_Id is a discriminant or a record component we are in the midst
6442 -- of inheriting components in a derived record definition. Preserve
6443 -- their Ekind and Etype.
6445 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
6448 -- If a type is already set, leave it alone (happens when a type
6449 -- declaration is reanalyzed following a call to the optimizer).
6451 elsif Present (Etype (Def_Id)) then
6454 -- Otherwise, the kind E_Void insures that premature uses of the entity
6455 -- will be detected. Any_Type insures that no cascaded errors will occur
6458 Set_Ekind (Def_Id, E_Void);
6459 Set_Etype (Def_Id, Any_Type);
6462 -- Inherited discriminants and components in derived record types are
6463 -- immediately visible. Itypes are not.
6465 -- Unless the Itype is for a record type with a corresponding remote
6466 -- type (what is that about, it was not commented ???)
6468 if Ekind_In (Def_Id, E_Discriminant, E_Component)
6470 ((not Is_Record_Type (Def_Id)
6471 or else No (Corresponding_Remote_Type (Def_Id)))
6472 and then not Is_Itype (Def_Id))
6474 Set_Is_Immediately_Visible (Def_Id);
6475 Set_Current_Entity (Def_Id);
6478 Set_Homonym (Def_Id, C);
6479 Append_Entity (Def_Id, S);
6480 Set_Public_Status (Def_Id);
6482 -- Declaring a homonym is not allowed in SPARK ...
6484 if Present (C) and then Restriction_Check_Required (SPARK_05) then
6486 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
6487 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
6488 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
6491 -- ... unless the new declaration is in a subprogram, and the
6492 -- visible declaration is a variable declaration or a parameter
6493 -- specification outside that subprogram.
6495 if Present (Enclosing_Subp)
6496 and then Nkind_In (Parent (C), N_Object_Declaration,
6497 N_Parameter_Specification)
6498 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
6502 -- ... or the new declaration is in a package, and the visible
6503 -- declaration occurs outside that package.
6505 elsif Present (Enclosing_Pack)
6506 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
6510 -- ... or the new declaration is a component declaration in a
6511 -- record type definition.
6513 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
6516 -- Don't issue error for non-source entities
6518 elsif Comes_From_Source (Def_Id)
6519 and then Comes_From_Source (C)
6521 Error_Msg_Sloc := Sloc (C);
6522 Check_SPARK_05_Restriction
6523 ("redeclaration of identifier &#", Def_Id);
6528 -- Warn if new entity hides an old one
6530 if Warn_On_Hiding and then Present (C)
6532 -- Don't warn for record components since they always have a well
6533 -- defined scope which does not confuse other uses. Note that in
6534 -- some cases, Ekind has not been set yet.
6536 and then Ekind (C) /= E_Component
6537 and then Ekind (C) /= E_Discriminant
6538 and then Nkind (Parent (C)) /= N_Component_Declaration
6539 and then Ekind (Def_Id) /= E_Component
6540 and then Ekind (Def_Id) /= E_Discriminant
6541 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
6543 -- Don't warn for one character variables. It is too common to use
6544 -- such variables as locals and will just cause too many false hits.
6546 and then Length_Of_Name (Chars (C)) /= 1
6548 -- Don't warn for non-source entities
6550 and then Comes_From_Source (C)
6551 and then Comes_From_Source (Def_Id)
6553 -- Don't warn unless entity in question is in extended main source
6555 and then In_Extended_Main_Source_Unit (Def_Id)
6557 -- Finally, the hidden entity must be either immediately visible or
6558 -- use visible (i.e. from a used package).
6561 (Is_Immediately_Visible (C)
6563 Is_Potentially_Use_Visible (C))
6565 Error_Msg_Sloc := Sloc (C);
6566 Error_Msg_N ("declaration hides &#?h?", Def_Id);
6574 function Entity_Of (N : Node_Id) return Entity_Id is
6580 if Is_Entity_Name (N) then
6583 -- Follow a possible chain of renamings to reach the root renamed
6587 and then Is_Object (Id)
6588 and then Present (Renamed_Object (Id))
6590 if Is_Entity_Name (Renamed_Object (Id)) then
6591 Id := Entity (Renamed_Object (Id));
6602 --------------------------
6603 -- Explain_Limited_Type --
6604 --------------------------
6606 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
6610 -- For array, component type must be limited
6612 if Is_Array_Type (T) then
6613 Error_Msg_Node_2 := T;
6615 ("\component type& of type& is limited", N, Component_Type (T));
6616 Explain_Limited_Type (Component_Type (T), N);
6618 elsif Is_Record_Type (T) then
6620 -- No need for extra messages if explicit limited record
6622 if Is_Limited_Record (Base_Type (T)) then
6626 -- Otherwise find a limited component. Check only components that
6627 -- come from source, or inherited components that appear in the
6628 -- source of the ancestor.
6630 C := First_Component (T);
6631 while Present (C) loop
6632 if Is_Limited_Type (Etype (C))
6634 (Comes_From_Source (C)
6636 (Present (Original_Record_Component (C))
6638 Comes_From_Source (Original_Record_Component (C))))
6640 Error_Msg_Node_2 := T;
6641 Error_Msg_NE ("\component& of type& has limited type", N, C);
6642 Explain_Limited_Type (Etype (C), N);
6649 -- The type may be declared explicitly limited, even if no component
6650 -- of it is limited, in which case we fall out of the loop.
6653 end Explain_Limited_Type;
6655 -------------------------------
6656 -- Extensions_Visible_Status --
6657 -------------------------------
6659 function Extensions_Visible_Status
6660 (Id : Entity_Id) return Extensions_Visible_Mode
6669 -- When a formal parameter is subject to Extensions_Visible, the pragma
6670 -- is stored in the contract of related subprogram.
6672 if Is_Formal (Id) then
6675 elsif Is_Subprogram_Or_Generic_Subprogram (Id) then
6678 -- No other construct carries this pragma
6681 return Extensions_Visible_None;
6684 Prag := Get_Pragma (Subp, Pragma_Extensions_Visible);
6686 -- In certain cases analysis may request the Extensions_Visible status
6687 -- of an expression function before the pragma has been analyzed yet.
6688 -- Inspect the declarative items after the expression function looking
6689 -- for the pragma (if any).
6691 if No (Prag) and then Is_Expression_Function (Subp) then
6692 Decl := Next (Unit_Declaration_Node (Subp));
6693 while Present (Decl) loop
6694 if Nkind (Decl) = N_Pragma
6695 and then Pragma_Name (Decl) = Name_Extensions_Visible
6700 -- A source construct ends the region where Extensions_Visible may
6701 -- appear, stop the traversal. An expanded expression function is
6702 -- no longer a source construct, but it must still be recognized.
6704 elsif Comes_From_Source (Decl)
6706 (Nkind_In (Decl, N_Subprogram_Body,
6707 N_Subprogram_Declaration)
6708 and then Is_Expression_Function (Defining_Entity (Decl)))
6717 -- Extract the value from the Boolean expression (if any)
6719 if Present (Prag) then
6720 Arg := First (Pragma_Argument_Associations (Prag));
6722 if Present (Arg) then
6723 Expr := Get_Pragma_Arg (Arg);
6725 -- When the associated subprogram is an expression function, the
6726 -- argument of the pragma may not have been analyzed.
6728 if not Analyzed (Expr) then
6729 Preanalyze_And_Resolve (Expr, Standard_Boolean);
6732 -- Guard against cascading errors when the argument of pragma
6733 -- Extensions_Visible is not a valid static Boolean expression.
6735 if Error_Posted (Expr) then
6736 return Extensions_Visible_None;
6738 elsif Is_True (Expr_Value (Expr)) then
6739 return Extensions_Visible_True;
6742 return Extensions_Visible_False;
6745 -- Otherwise the aspect or pragma defaults to True
6748 return Extensions_Visible_True;
6751 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
6752 -- directly specified. In SPARK code, its value defaults to "False".
6754 elsif SPARK_Mode = On then
6755 return Extensions_Visible_False;
6757 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
6761 return Extensions_Visible_True;
6763 end Extensions_Visible_Status;
6769 procedure Find_Actual
6771 Formal : out Entity_Id;
6774 Context : constant Node_Id := Parent (N);
6779 if Nkind_In (Context, N_Indexed_Component, N_Selected_Component)
6780 and then N = Prefix (Context)
6782 Find_Actual (Context, Formal, Call);
6785 elsif Nkind (Context) = N_Parameter_Association
6786 and then N = Explicit_Actual_Parameter (Context)
6788 Call := Parent (Context);
6790 elsif Nkind_In (Context, N_Entry_Call_Statement,
6792 N_Procedure_Call_Statement)
6802 -- If we have a call to a subprogram look for the parameter. Note that
6803 -- we exclude overloaded calls, since we don't know enough to be sure
6804 -- of giving the right answer in this case.
6806 if Nkind_In (Call, N_Entry_Call_Statement,
6808 N_Procedure_Call_Statement)
6810 Call_Nam := Name (Call);
6812 -- A call to a protected or task entry appears as a selected
6813 -- component rather than an expanded name.
6815 if Nkind (Call_Nam) = N_Selected_Component then
6816 Call_Nam := Selector_Name (Call_Nam);
6819 if Is_Entity_Name (Call_Nam)
6820 and then Present (Entity (Call_Nam))
6821 and then Is_Overloadable (Entity (Call_Nam))
6822 and then not Is_Overloaded (Call_Nam)
6824 -- If node is name in call it is not an actual
6826 if N = Call_Nam then
6832 -- Fall here if we are definitely a parameter
6834 Actual := First_Actual (Call);
6835 Formal := First_Formal (Entity (Call_Nam));
6836 while Present (Formal) and then Present (Actual) loop
6840 -- An actual that is the prefix in a prefixed call may have
6841 -- been rewritten in the call, after the deferred reference
6842 -- was collected. Check if sloc and kinds and names match.
6844 elsif Sloc (Actual) = Sloc (N)
6845 and then Nkind (Actual) = N_Identifier
6846 and then Nkind (Actual) = Nkind (N)
6847 and then Chars (Actual) = Chars (N)
6852 Actual := Next_Actual (Actual);
6853 Formal := Next_Formal (Formal);
6859 -- Fall through here if we did not find matching actual
6865 ---------------------------
6866 -- Find_Body_Discriminal --
6867 ---------------------------
6869 function Find_Body_Discriminal
6870 (Spec_Discriminant : Entity_Id) return Entity_Id
6876 -- If expansion is suppressed, then the scope can be the concurrent type
6877 -- itself rather than a corresponding concurrent record type.
6879 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
6880 Tsk := Scope (Spec_Discriminant);
6883 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
6885 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
6888 -- Find discriminant of original concurrent type, and use its current
6889 -- discriminal, which is the renaming within the task/protected body.
6891 Disc := First_Discriminant (Tsk);
6892 while Present (Disc) loop
6893 if Chars (Disc) = Chars (Spec_Discriminant) then
6894 return Discriminal (Disc);
6897 Next_Discriminant (Disc);
6900 -- That loop should always succeed in finding a matching entry and
6901 -- returning. Fatal error if not.
6903 raise Program_Error;
6904 end Find_Body_Discriminal;
6906 -------------------------------------
6907 -- Find_Corresponding_Discriminant --
6908 -------------------------------------
6910 function Find_Corresponding_Discriminant
6912 Typ : Entity_Id) return Entity_Id
6914 Par_Disc : Entity_Id;
6915 Old_Disc : Entity_Id;
6916 New_Disc : Entity_Id;
6919 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
6921 -- The original type may currently be private, and the discriminant
6922 -- only appear on its full view.
6924 if Is_Private_Type (Scope (Par_Disc))
6925 and then not Has_Discriminants (Scope (Par_Disc))
6926 and then Present (Full_View (Scope (Par_Disc)))
6928 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
6930 Old_Disc := First_Discriminant (Scope (Par_Disc));
6933 if Is_Class_Wide_Type (Typ) then
6934 New_Disc := First_Discriminant (Root_Type (Typ));
6936 New_Disc := First_Discriminant (Typ);
6939 while Present (Old_Disc) and then Present (New_Disc) loop
6940 if Old_Disc = Par_Disc then
6944 Next_Discriminant (Old_Disc);
6945 Next_Discriminant (New_Disc);
6948 -- Should always find it
6950 raise Program_Error;
6951 end Find_Corresponding_Discriminant;
6953 ----------------------------------
6954 -- Find_Enclosing_Iterator_Loop --
6955 ----------------------------------
6957 function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id is
6962 -- Traverse the scope chain looking for an iterator loop. Such loops are
6963 -- usually transformed into blocks, hence the use of Original_Node.
6966 while Present (S) and then S /= Standard_Standard loop
6967 if Ekind (S) = E_Loop
6968 and then Nkind (Parent (S)) = N_Implicit_Label_Declaration
6970 Constr := Original_Node (Label_Construct (Parent (S)));
6972 if Nkind (Constr) = N_Loop_Statement
6973 and then Present (Iteration_Scheme (Constr))
6974 and then Nkind (Iterator_Specification
6975 (Iteration_Scheme (Constr))) =
6976 N_Iterator_Specification
6986 end Find_Enclosing_Iterator_Loop;
6988 ------------------------------------
6989 -- Find_Loop_In_Conditional_Block --
6990 ------------------------------------
6992 function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is
6998 if Nkind (Stmt) = N_If_Statement then
6999 Stmt := First (Then_Statements (Stmt));
7002 pragma Assert (Nkind (Stmt) = N_Block_Statement);
7004 -- Inspect the statements of the conditional block. In general the loop
7005 -- should be the first statement in the statement sequence of the block,
7006 -- but the finalization machinery may have introduced extra object
7009 Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
7010 while Present (Stmt) loop
7011 if Nkind (Stmt) = N_Loop_Statement then
7018 -- The expansion of attribute 'Loop_Entry produced a malformed block
7020 raise Program_Error;
7021 end Find_Loop_In_Conditional_Block;
7023 --------------------------
7024 -- Find_Overlaid_Entity --
7025 --------------------------
7027 procedure Find_Overlaid_Entity
7029 Ent : out Entity_Id;
7035 -- We are looking for one of the two following forms:
7037 -- for X'Address use Y'Address
7041 -- Const : constant Address := expr;
7043 -- for X'Address use Const;
7045 -- In the second case, the expr is either Y'Address, or recursively a
7046 -- constant that eventually references Y'Address.
7051 if Nkind (N) = N_Attribute_Definition_Clause
7052 and then Chars (N) = Name_Address
7054 Expr := Expression (N);
7056 -- This loop checks the form of the expression for Y'Address,
7057 -- using recursion to deal with intermediate constants.
7060 -- Check for Y'Address
7062 if Nkind (Expr) = N_Attribute_Reference
7063 and then Attribute_Name (Expr) = Name_Address
7065 Expr := Prefix (Expr);
7068 -- Check for Const where Const is a constant entity
7070 elsif Is_Entity_Name (Expr)
7071 and then Ekind (Entity (Expr)) = E_Constant
7073 Expr := Constant_Value (Entity (Expr));
7075 -- Anything else does not need checking
7082 -- This loop checks the form of the prefix for an entity, using
7083 -- recursion to deal with intermediate components.
7086 -- Check for Y where Y is an entity
7088 if Is_Entity_Name (Expr) then
7089 Ent := Entity (Expr);
7092 -- Check for components
7095 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component)
7097 Expr := Prefix (Expr);
7100 -- Anything else does not need checking
7107 end Find_Overlaid_Entity;
7109 -------------------------
7110 -- Find_Parameter_Type --
7111 -------------------------
7113 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
7115 if Nkind (Param) /= N_Parameter_Specification then
7118 -- For an access parameter, obtain the type from the formal entity
7119 -- itself, because access to subprogram nodes do not carry a type.
7120 -- Shouldn't we always use the formal entity ???
7122 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
7123 return Etype (Defining_Identifier (Param));
7126 return Etype (Parameter_Type (Param));
7128 end Find_Parameter_Type;
7130 -----------------------------------
7131 -- Find_Placement_In_State_Space --
7132 -----------------------------------
7134 procedure Find_Placement_In_State_Space
7135 (Item_Id : Entity_Id;
7136 Placement : out State_Space_Kind;
7137 Pack_Id : out Entity_Id)
7139 Context : Entity_Id;
7142 -- Assume that the item does not appear in the state space of a package
7144 Placement := Not_In_Package;
7147 -- Climb the scope stack and examine the enclosing context
7149 Context := Scope (Item_Id);
7150 while Present (Context) and then Context /= Standard_Standard loop
7151 if Ekind (Context) = E_Package then
7154 -- A package body is a cut off point for the traversal as the item
7155 -- cannot be visible to the outside from this point on. Note that
7156 -- this test must be done first as a body is also classified as a
7159 if In_Package_Body (Context) then
7160 Placement := Body_State_Space;
7163 -- The private part of a package is a cut off point for the
7164 -- traversal as the item cannot be visible to the outside from
7167 elsif In_Private_Part (Context) then
7168 Placement := Private_State_Space;
7171 -- When the item appears in the visible state space of a package,
7172 -- continue to climb the scope stack as this may not be the final
7176 Placement := Visible_State_Space;
7178 -- The visible state space of a child unit acts as the proper
7179 -- placement of an item.
7181 if Is_Child_Unit (Context) then
7186 -- The item or its enclosing package appear in a construct that has
7190 Placement := Not_In_Package;
7194 Context := Scope (Context);
7196 end Find_Placement_In_State_Space;
7198 ------------------------
7199 -- Find_Specific_Type --
7200 ------------------------
7202 function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
7203 Typ : Entity_Id := Root_Type (CW);
7206 if Ekind (Typ) = E_Incomplete_Type then
7207 if From_Limited_With (Typ) then
7208 Typ := Non_Limited_View (Typ);
7210 Typ := Full_View (Typ);
7214 if Is_Private_Type (Typ)
7215 and then not Is_Tagged_Type (Typ)
7216 and then Present (Full_View (Typ))
7218 return Full_View (Typ);
7222 end Find_Specific_Type;
7224 -----------------------------
7225 -- Find_Static_Alternative --
7226 -----------------------------
7228 function Find_Static_Alternative (N : Node_Id) return Node_Id is
7229 Expr : constant Node_Id := Expression (N);
7230 Val : constant Uint := Expr_Value (Expr);
7235 Alt := First (Alternatives (N));
7238 if Nkind (Alt) /= N_Pragma then
7239 Choice := First (Discrete_Choices (Alt));
7240 while Present (Choice) loop
7242 -- Others choice, always matches
7244 if Nkind (Choice) = N_Others_Choice then
7247 -- Range, check if value is in the range
7249 elsif Nkind (Choice) = N_Range then
7251 Val >= Expr_Value (Low_Bound (Choice))
7253 Val <= Expr_Value (High_Bound (Choice));
7255 -- Choice is a subtype name. Note that we know it must
7256 -- be a static subtype, since otherwise it would have
7257 -- been diagnosed as illegal.
7259 elsif Is_Entity_Name (Choice)
7260 and then Is_Type (Entity (Choice))
7262 exit Search when Is_In_Range (Expr, Etype (Choice),
7263 Assume_Valid => False);
7265 -- Choice is a subtype indication
7267 elsif Nkind (Choice) = N_Subtype_Indication then
7269 C : constant Node_Id := Constraint (Choice);
7270 R : constant Node_Id := Range_Expression (C);
7274 Val >= Expr_Value (Low_Bound (R))
7276 Val <= Expr_Value (High_Bound (R));
7279 -- Choice is a simple expression
7282 exit Search when Val = Expr_Value (Choice);
7290 pragma Assert (Present (Alt));
7293 -- The above loop *must* terminate by finding a match, since
7294 -- we know the case statement is valid, and the value of the
7295 -- expression is known at compile time. When we fall out of
7296 -- the loop, Alt points to the alternative that we know will
7297 -- be selected at run time.
7300 end Find_Static_Alternative;
7306 function First_Actual (Node : Node_Id) return Node_Id is
7310 if No (Parameter_Associations (Node)) then
7314 N := First (Parameter_Associations (Node));
7316 if Nkind (N) = N_Parameter_Association then
7317 return First_Named_Actual (Node);
7327 function Fix_Msg (Id : Entity_Id; Msg : String) return String is
7328 Is_Task : constant Boolean :=
7329 Ekind_In (Id, E_Task_Body, E_Task_Type)
7330 or else Is_Single_Task_Object (Id);
7331 Msg_Last : constant Natural := Msg'Last;
7332 Msg_Index : Natural;
7333 Res : String (Msg'Range) := (others => ' ');
7334 Res_Index : Natural;
7337 -- Copy all characters from the input message Msg to result Res with
7338 -- suitable replacements.
7340 Msg_Index := Msg'First;
7341 Res_Index := Res'First;
7342 while Msg_Index <= Msg_Last loop
7344 -- Replace "subprogram" with a different word
7346 if Msg_Index <= Msg_Last - 10
7347 and then Msg (Msg_Index .. Msg_Index + 9) = "subprogram"
7349 if Ekind_In (Id, E_Entry, E_Entry_Family) then
7350 Res (Res_Index .. Res_Index + 4) := "entry";
7351 Res_Index := Res_Index + 5;
7354 Res (Res_Index .. Res_Index + 8) := "task type";
7355 Res_Index := Res_Index + 9;
7358 Res (Res_Index .. Res_Index + 9) := "subprogram";
7359 Res_Index := Res_Index + 10;
7362 Msg_Index := Msg_Index + 10;
7364 -- Replace "protected" with a different word
7366 elsif Msg_Index <= Msg_Last - 9
7367 and then Msg (Msg_Index .. Msg_Index + 8) = "protected"
7370 Res (Res_Index .. Res_Index + 3) := "task";
7371 Res_Index := Res_Index + 4;
7372 Msg_Index := Msg_Index + 9;
7374 -- Otherwise copy the character
7377 Res (Res_Index) := Msg (Msg_Index);
7378 Msg_Index := Msg_Index + 1;
7379 Res_Index := Res_Index + 1;
7383 return Res (Res'First .. Res_Index - 1);
7386 -----------------------
7387 -- Gather_Components --
7388 -----------------------
7390 procedure Gather_Components
7392 Comp_List : Node_Id;
7393 Governed_By : List_Id;
7395 Report_Errors : out Boolean)
7399 Discrete_Choice : Node_Id;
7400 Comp_Item : Node_Id;
7402 Discrim : Entity_Id;
7403 Discrim_Name : Node_Id;
7404 Discrim_Value : Node_Id;
7407 Report_Errors := False;
7409 if No (Comp_List) or else Null_Present (Comp_List) then
7412 elsif Present (Component_Items (Comp_List)) then
7413 Comp_Item := First (Component_Items (Comp_List));
7419 while Present (Comp_Item) loop
7421 -- Skip the tag of a tagged record, the interface tags, as well
7422 -- as all items that are not user components (anonymous types,
7423 -- rep clauses, Parent field, controller field).
7425 if Nkind (Comp_Item) = N_Component_Declaration then
7427 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
7429 if not Is_Tag (Comp) and then Chars (Comp) /= Name_uParent then
7430 Append_Elmt (Comp, Into);
7438 if No (Variant_Part (Comp_List)) then
7441 Discrim_Name := Name (Variant_Part (Comp_List));
7442 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
7445 -- Look for the discriminant that governs this variant part.
7446 -- The discriminant *must* be in the Governed_By List
7448 Assoc := First (Governed_By);
7449 Find_Constraint : loop
7450 Discrim := First (Choices (Assoc));
7451 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
7452 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
7454 Chars (Corresponding_Discriminant (Entity (Discrim))) =
7455 Chars (Discrim_Name))
7456 or else Chars (Original_Record_Component (Entity (Discrim)))
7457 = Chars (Discrim_Name);
7459 if No (Next (Assoc)) then
7460 if not Is_Constrained (Typ)
7461 and then Is_Derived_Type (Typ)
7462 and then Present (Stored_Constraint (Typ))
7464 -- If the type is a tagged type with inherited discriminants,
7465 -- use the stored constraint on the parent in order to find
7466 -- the values of discriminants that are otherwise hidden by an
7467 -- explicit constraint. Renamed discriminants are handled in
7470 -- If several parent discriminants are renamed by a single
7471 -- discriminant of the derived type, the call to obtain the
7472 -- Corresponding_Discriminant field only retrieves the last
7473 -- of them. We recover the constraint on the others from the
7474 -- Stored_Constraint as well.
7481 D := First_Discriminant (Etype (Typ));
7482 C := First_Elmt (Stored_Constraint (Typ));
7483 while Present (D) and then Present (C) loop
7484 if Chars (Discrim_Name) = Chars (D) then
7485 if Is_Entity_Name (Node (C))
7486 and then Entity (Node (C)) = Entity (Discrim)
7488 -- D is renamed by Discrim, whose value is given in
7495 Make_Component_Association (Sloc (Typ),
7497 (New_Occurrence_Of (D, Sloc (Typ))),
7498 Duplicate_Subexpr_No_Checks (Node (C)));
7500 exit Find_Constraint;
7503 Next_Discriminant (D);
7510 if No (Next (Assoc)) then
7511 Error_Msg_NE (" missing value for discriminant&",
7512 First (Governed_By), Discrim_Name);
7513 Report_Errors := True;
7518 end loop Find_Constraint;
7520 Discrim_Value := Expression (Assoc);
7522 if not Is_OK_Static_Expression (Discrim_Value) then
7524 -- If the variant part is governed by a discriminant of the type
7525 -- this is an error. If the variant part and the discriminant are
7526 -- inherited from an ancestor this is legal (AI05-120) unless the
7527 -- components are being gathered for an aggregate, in which case
7528 -- the caller must check Report_Errors.
7530 if Scope (Original_Record_Component
7531 ((Entity (First (Choices (Assoc)))))) = Typ
7534 ("value for discriminant & must be static!",
7535 Discrim_Value, Discrim);
7536 Why_Not_Static (Discrim_Value);
7539 Report_Errors := True;
7543 Search_For_Discriminant_Value : declare
7549 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
7552 Find_Discrete_Value : while Present (Variant) loop
7553 Discrete_Choice := First (Discrete_Choices (Variant));
7554 while Present (Discrete_Choice) loop
7555 exit Find_Discrete_Value when
7556 Nkind (Discrete_Choice) = N_Others_Choice;
7558 Get_Index_Bounds (Discrete_Choice, Low, High);
7560 UI_Low := Expr_Value (Low);
7561 UI_High := Expr_Value (High);
7563 exit Find_Discrete_Value when
7564 UI_Low <= UI_Discrim_Value
7566 UI_High >= UI_Discrim_Value;
7568 Next (Discrete_Choice);
7571 Next_Non_Pragma (Variant);
7572 end loop Find_Discrete_Value;
7573 end Search_For_Discriminant_Value;
7575 -- The case statement must include a variant that corresponds to the
7576 -- value of the discriminant, unless the discriminant type has a
7577 -- static predicate. In that case the absence of an others_choice that
7578 -- would cover this value becomes a run-time error (3.8,1 (21.1/2)).
7581 and then not Has_Static_Predicate (Etype (Discrim_Name))
7584 ("value of discriminant & is out of range", Discrim_Value, Discrim);
7585 Report_Errors := True;
7589 -- If we have found the corresponding choice, recursively add its
7590 -- components to the Into list. The nested components are part of
7591 -- the same record type.
7593 if Present (Variant) then
7595 (Typ, Component_List (Variant), Governed_By, Into, Report_Errors);
7597 end Gather_Components;
7599 ------------------------
7600 -- Get_Actual_Subtype --
7601 ------------------------
7603 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
7604 Typ : constant Entity_Id := Etype (N);
7605 Utyp : Entity_Id := Underlying_Type (Typ);
7614 -- If what we have is an identifier that references a subprogram
7615 -- formal, or a variable or constant object, then we get the actual
7616 -- subtype from the referenced entity if one has been built.
7618 if Nkind (N) = N_Identifier
7620 (Is_Formal (Entity (N))
7621 or else Ekind (Entity (N)) = E_Constant
7622 or else Ekind (Entity (N)) = E_Variable)
7623 and then Present (Actual_Subtype (Entity (N)))
7625 return Actual_Subtype (Entity (N));
7627 -- Actual subtype of unchecked union is always itself. We never need
7628 -- the "real" actual subtype. If we did, we couldn't get it anyway
7629 -- because the discriminant is not available. The restrictions on
7630 -- Unchecked_Union are designed to make sure that this is OK.
7632 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
7635 -- Here for the unconstrained case, we must find actual subtype
7636 -- No actual subtype is available, so we must build it on the fly.
7638 -- Checking the type, not the underlying type, for constrainedness
7639 -- seems to be necessary. Maybe all the tests should be on the type???
7641 elsif (not Is_Constrained (Typ))
7642 and then (Is_Array_Type (Utyp)
7643 or else (Is_Record_Type (Utyp)
7644 and then Has_Discriminants (Utyp)))
7645 and then not Has_Unknown_Discriminants (Utyp)
7646 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
7648 -- Nothing to do if in spec expression (why not???)
7650 if In_Spec_Expression then
7653 elsif Is_Private_Type (Typ) and then not Has_Discriminants (Typ) then
7655 -- If the type has no discriminants, there is no subtype to
7656 -- build, even if the underlying type is discriminated.
7660 -- Else build the actual subtype
7663 Decl := Build_Actual_Subtype (Typ, N);
7664 Atyp := Defining_Identifier (Decl);
7666 -- If Build_Actual_Subtype generated a new declaration then use it
7670 -- The actual subtype is an Itype, so analyze the declaration,
7671 -- but do not attach it to the tree, to get the type defined.
7673 Set_Parent (Decl, N);
7674 Set_Is_Itype (Atyp);
7675 Analyze (Decl, Suppress => All_Checks);
7676 Set_Associated_Node_For_Itype (Atyp, N);
7677 Set_Has_Delayed_Freeze (Atyp, False);
7679 -- We need to freeze the actual subtype immediately. This is
7680 -- needed, because otherwise this Itype will not get frozen
7681 -- at all, and it is always safe to freeze on creation because
7682 -- any associated types must be frozen at this point.
7684 Freeze_Itype (Atyp, N);
7687 -- Otherwise we did not build a declaration, so return original
7694 -- For all remaining cases, the actual subtype is the same as
7695 -- the nominal type.
7700 end Get_Actual_Subtype;
7702 -------------------------------------
7703 -- Get_Actual_Subtype_If_Available --
7704 -------------------------------------
7706 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
7707 Typ : constant Entity_Id := Etype (N);
7710 -- If what we have is an identifier that references a subprogram
7711 -- formal, or a variable or constant object, then we get the actual
7712 -- subtype from the referenced entity if one has been built.
7714 if Nkind (N) = N_Identifier
7716 (Is_Formal (Entity (N))
7717 or else Ekind (Entity (N)) = E_Constant
7718 or else Ekind (Entity (N)) = E_Variable)
7719 and then Present (Actual_Subtype (Entity (N)))
7721 return Actual_Subtype (Entity (N));
7723 -- Otherwise the Etype of N is returned unchanged
7728 end Get_Actual_Subtype_If_Available;
7730 ------------------------
7731 -- Get_Body_From_Stub --
7732 ------------------------
7734 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
7736 return Proper_Body (Unit (Library_Unit (N)));
7737 end Get_Body_From_Stub;
7739 ---------------------
7740 -- Get_Cursor_Type --
7741 ---------------------
7743 function Get_Cursor_Type
7745 Typ : Entity_Id) return Entity_Id
7749 First_Op : Entity_Id;
7753 -- If error already detected, return
7755 if Error_Posted (Aspect) then
7759 -- The cursor type for an Iterable aspect is the return type of a
7760 -- non-overloaded First primitive operation. Locate association for
7763 Assoc := First (Component_Associations (Expression (Aspect)));
7765 while Present (Assoc) loop
7766 if Chars (First (Choices (Assoc))) = Name_First then
7767 First_Op := Expression (Assoc);
7774 if First_Op = Any_Id then
7775 Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
7781 -- Locate function with desired name and profile in scope of type
7782 -- In the rare case where the type is an integer type, a base type
7783 -- is created for it, check that the base type of the first formal
7784 -- of First matches the base type of the domain.
7786 Func := First_Entity (Scope (Typ));
7787 while Present (Func) loop
7788 if Chars (Func) = Chars (First_Op)
7789 and then Ekind (Func) = E_Function
7790 and then Present (First_Formal (Func))
7791 and then Base_Type (Etype (First_Formal (Func))) = Base_Type (Typ)
7792 and then No (Next_Formal (First_Formal (Func)))
7794 if Cursor /= Any_Type then
7796 ("Operation First for iterable type must be unique", Aspect);
7799 Cursor := Etype (Func);
7806 -- If not found, no way to resolve remaining primitives.
7808 if Cursor = Any_Type then
7810 ("No legal primitive operation First for Iterable type", Aspect);
7814 end Get_Cursor_Type;
7816 function Get_Cursor_Type (Typ : Entity_Id) return Entity_Id is
7818 return Etype (Get_Iterable_Type_Primitive (Typ, Name_First));
7819 end Get_Cursor_Type;
7821 -------------------------------
7822 -- Get_Default_External_Name --
7823 -------------------------------
7825 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
7827 Get_Decoded_Name_String (Chars (E));
7829 if Opt.External_Name_Imp_Casing = Uppercase then
7830 Set_Casing (All_Upper_Case);
7832 Set_Casing (All_Lower_Case);
7836 Make_String_Literal (Sloc (E),
7837 Strval => String_From_Name_Buffer);
7838 end Get_Default_External_Name;
7840 --------------------------
7841 -- Get_Enclosing_Object --
7842 --------------------------
7844 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
7846 if Is_Entity_Name (N) then
7850 when N_Indexed_Component |
7852 N_Selected_Component =>
7854 -- If not generating code, a dereference may be left implicit.
7855 -- In thoses cases, return Empty.
7857 if Is_Access_Type (Etype (Prefix (N))) then
7860 return Get_Enclosing_Object (Prefix (N));
7863 when N_Type_Conversion =>
7864 return Get_Enclosing_Object (Expression (N));
7870 end Get_Enclosing_Object;
7872 ---------------------------
7873 -- Get_Enum_Lit_From_Pos --
7874 ---------------------------
7876 function Get_Enum_Lit_From_Pos
7879 Loc : Source_Ptr) return Node_Id
7881 Btyp : Entity_Id := Base_Type (T);
7886 -- In the case where the literal is of type Character, Wide_Character
7887 -- or Wide_Wide_Character or of a type derived from them, there needs
7888 -- to be some special handling since there is no explicit chain of
7889 -- literals to search. Instead, an N_Character_Literal node is created
7890 -- with the appropriate Char_Code and Chars fields.
7892 if Is_Standard_Character_Type (T) then
7893 Set_Character_Literal_Name (UI_To_CC (Pos));
7896 Make_Character_Literal (Loc,
7898 Char_Literal_Value => Pos);
7900 -- For all other cases, we have a complete table of literals, and
7901 -- we simply iterate through the chain of literal until the one
7902 -- with the desired position value is found.
7905 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
7906 Btyp := Full_View (Btyp);
7909 Lit := First_Literal (Btyp);
7910 for J in 1 .. UI_To_Int (Pos) loop
7913 -- If Lit is Empty, Pos is not in range, so raise Constraint_Error
7914 -- inside the loop to avoid calling Next_Literal on Empty.
7917 raise Constraint_Error;
7921 -- Create a new node from Lit, with source location provided by Loc
7922 -- if not equal to No_Location, or by copying the source location of
7927 if LLoc = No_Location then
7931 return New_Occurrence_Of (Lit, LLoc);
7933 end Get_Enum_Lit_From_Pos;
7935 ------------------------
7936 -- Get_Generic_Entity --
7937 ------------------------
7939 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
7940 Ent : constant Entity_Id := Entity (Name (N));
7942 if Present (Renamed_Object (Ent)) then
7943 return Renamed_Object (Ent);
7947 end Get_Generic_Entity;
7949 -------------------------------------
7950 -- Get_Incomplete_View_Of_Ancestor --
7951 -------------------------------------
7953 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
7954 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
7955 Par_Scope : Entity_Id;
7956 Par_Type : Entity_Id;
7959 -- The incomplete view of an ancestor is only relevant for private
7960 -- derived types in child units.
7962 if not Is_Derived_Type (E)
7963 or else not Is_Child_Unit (Cur_Unit)
7968 Par_Scope := Scope (Cur_Unit);
7969 if No (Par_Scope) then
7973 Par_Type := Etype (Base_Type (E));
7975 -- Traverse list of ancestor types until we find one declared in
7976 -- a parent or grandparent unit (two levels seem sufficient).
7978 while Present (Par_Type) loop
7979 if Scope (Par_Type) = Par_Scope
7980 or else Scope (Par_Type) = Scope (Par_Scope)
7984 elsif not Is_Derived_Type (Par_Type) then
7988 Par_Type := Etype (Base_Type (Par_Type));
7992 -- If none found, there is no relevant ancestor type.
7996 end Get_Incomplete_View_Of_Ancestor;
7998 ----------------------
7999 -- Get_Index_Bounds --
8000 ----------------------
8002 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
8003 Kind : constant Node_Kind := Nkind (N);
8007 if Kind = N_Range then
8009 H := High_Bound (N);
8011 elsif Kind = N_Subtype_Indication then
8012 R := Range_Expression (Constraint (N));
8020 L := Low_Bound (Range_Expression (Constraint (N)));
8021 H := High_Bound (Range_Expression (Constraint (N)));
8024 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
8025 if Error_Posted (Scalar_Range (Entity (N))) then
8029 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
8030 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
8033 L := Low_Bound (Scalar_Range (Entity (N)));
8034 H := High_Bound (Scalar_Range (Entity (N)));
8038 -- N is an expression, indicating a range with one value
8043 end Get_Index_Bounds;
8045 ---------------------------------
8046 -- Get_Iterable_Type_Primitive --
8047 ---------------------------------
8049 function Get_Iterable_Type_Primitive
8051 Nam : Name_Id) return Entity_Id
8053 Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
8061 Assoc := First (Component_Associations (Funcs));
8062 while Present (Assoc) loop
8063 if Chars (First (Choices (Assoc))) = Nam then
8064 return Entity (Expression (Assoc));
8067 Assoc := Next (Assoc);
8072 end Get_Iterable_Type_Primitive;
8074 ----------------------------------
8075 -- Get_Library_Unit_Name_string --
8076 ----------------------------------
8078 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
8079 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
8082 Get_Unit_Name_String (Unit_Name_Id);
8084 -- Remove seven last character (" (spec)" or " (body)")
8086 Name_Len := Name_Len - 7;
8087 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
8088 end Get_Library_Unit_Name_String;
8090 --------------------------
8091 -- Get_Max_Queue_Length --
8092 --------------------------
8094 function Get_Max_Queue_Length (Id : Entity_Id) return Uint is
8095 pragma Assert (Is_Entry (Id));
8096 Prag : constant Entity_Id := Get_Pragma (Id, Pragma_Max_Queue_Length);
8099 -- A value of 0 represents no maximum specified, and entries and entry
8100 -- families with no Max_Queue_Length aspect or pragma default to it.
8102 if not Present (Prag) then
8106 return Intval (Expression (First (Pragma_Argument_Associations (Prag))));
8107 end Get_Max_Queue_Length;
8109 ------------------------
8110 -- Get_Name_Entity_Id --
8111 ------------------------
8113 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
8115 return Entity_Id (Get_Name_Table_Int (Id));
8116 end Get_Name_Entity_Id;
8118 ------------------------------
8119 -- Get_Name_From_CTC_Pragma --
8120 ------------------------------
8122 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
8123 Arg : constant Node_Id :=
8124 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
8126 return Strval (Expr_Value_S (Arg));
8127 end Get_Name_From_CTC_Pragma;
8129 -----------------------
8130 -- Get_Parent_Entity --
8131 -----------------------
8133 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
8135 if Nkind (Unit) = N_Package_Body
8136 and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
8138 return Defining_Entity
8139 (Specification (Instance_Spec (Original_Node (Unit))));
8140 elsif Nkind (Unit) = N_Package_Instantiation then
8141 return Defining_Entity (Specification (Instance_Spec (Unit)));
8143 return Defining_Entity (Unit);
8145 end Get_Parent_Entity;
8151 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
8153 return Get_Pragma_Id (Pragma_Name_Unmapped (N));
8156 ------------------------
8157 -- Get_Qualified_Name --
8158 ------------------------
8160 function Get_Qualified_Name
8162 Suffix : Entity_Id := Empty) return Name_Id
8164 Suffix_Nam : Name_Id := No_Name;
8167 if Present (Suffix) then
8168 Suffix_Nam := Chars (Suffix);
8171 return Get_Qualified_Name (Chars (Id), Suffix_Nam, Scope (Id));
8172 end Get_Qualified_Name;
8174 function Get_Qualified_Name
8176 Suffix : Name_Id := No_Name;
8177 Scop : Entity_Id := Current_Scope) return Name_Id
8179 procedure Add_Scope (S : Entity_Id);
8180 -- Add the fully qualified form of scope S to the name buffer. The
8188 procedure Add_Scope (S : Entity_Id) is
8193 elsif S = Standard_Standard then
8197 Add_Scope (Scope (S));
8198 Get_Name_String_And_Append (Chars (S));
8199 Add_Str_To_Name_Buffer ("__");
8203 -- Start of processing for Get_Qualified_Name
8209 -- Append the base name after all scopes have been chained
8211 Get_Name_String_And_Append (Nam);
8213 -- Append the suffix (if present)
8215 if Suffix /= No_Name then
8216 Add_Str_To_Name_Buffer ("__");
8217 Get_Name_String_And_Append (Suffix);
8221 end Get_Qualified_Name;
8223 -----------------------
8224 -- Get_Reason_String --
8225 -----------------------
8227 procedure Get_Reason_String (N : Node_Id) is
8229 if Nkind (N) = N_String_Literal then
8230 Store_String_Chars (Strval (N));
8232 elsif Nkind (N) = N_Op_Concat then
8233 Get_Reason_String (Left_Opnd (N));
8234 Get_Reason_String (Right_Opnd (N));
8236 -- If not of required form, error
8240 ("Reason for pragma Warnings has wrong form", N);
8242 ("\must be string literal or concatenation of string literals", N);
8245 end Get_Reason_String;
8247 --------------------------------
8248 -- Get_Reference_Discriminant --
8249 --------------------------------
8251 function Get_Reference_Discriminant (Typ : Entity_Id) return Entity_Id is
8255 D := First_Discriminant (Typ);
8256 while Present (D) loop
8257 if Has_Implicit_Dereference (D) then
8260 Next_Discriminant (D);
8264 end Get_Reference_Discriminant;
8266 ---------------------------
8267 -- Get_Referenced_Object --
8268 ---------------------------
8270 function Get_Referenced_Object (N : Node_Id) return Node_Id is
8275 while Is_Entity_Name (R)
8276 and then Present (Renamed_Object (Entity (R)))
8278 R := Renamed_Object (Entity (R));
8282 end Get_Referenced_Object;
8284 ------------------------
8285 -- Get_Renamed_Entity --
8286 ------------------------
8288 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
8293 while Present (Renamed_Entity (R)) loop
8294 R := Renamed_Entity (R);
8298 end Get_Renamed_Entity;
8300 -----------------------
8301 -- Get_Return_Object --
8302 -----------------------
8304 function Get_Return_Object (N : Node_Id) return Entity_Id is
8308 Decl := First (Return_Object_Declarations (N));
8309 while Present (Decl) loop
8310 exit when Nkind (Decl) = N_Object_Declaration
8311 and then Is_Return_Object (Defining_Identifier (Decl));
8315 pragma Assert (Present (Decl));
8316 return Defining_Identifier (Decl);
8317 end Get_Return_Object;
8319 ---------------------------
8320 -- Get_Subprogram_Entity --
8321 ---------------------------
8323 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
8325 Subp_Id : Entity_Id;
8328 if Nkind (Nod) = N_Accept_Statement then
8329 Subp := Entry_Direct_Name (Nod);
8331 elsif Nkind (Nod) = N_Slice then
8332 Subp := Prefix (Nod);
8338 -- Strip the subprogram call
8341 if Nkind_In (Subp, N_Explicit_Dereference,
8342 N_Indexed_Component,
8343 N_Selected_Component)
8345 Subp := Prefix (Subp);
8347 elsif Nkind_In (Subp, N_Type_Conversion,
8348 N_Unchecked_Type_Conversion)
8350 Subp := Expression (Subp);
8357 -- Extract the entity of the subprogram call
8359 if Is_Entity_Name (Subp) then
8360 Subp_Id := Entity (Subp);
8362 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
8363 Subp_Id := Directly_Designated_Type (Subp_Id);
8366 if Is_Subprogram (Subp_Id) then
8372 -- The search did not find a construct that denotes a subprogram
8377 end Get_Subprogram_Entity;
8379 -----------------------------
8380 -- Get_Task_Body_Procedure --
8381 -----------------------------
8383 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
8385 -- Note: A task type may be the completion of a private type with
8386 -- discriminants. When performing elaboration checks on a task
8387 -- declaration, the current view of the type may be the private one,
8388 -- and the procedure that holds the body of the task is held in its
8391 -- This is an odd function, why not have Task_Body_Procedure do
8392 -- the following digging???
8394 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
8395 end Get_Task_Body_Procedure;
8397 -------------------------
8398 -- Get_User_Defined_Eq --
8399 -------------------------
8401 function Get_User_Defined_Eq (E : Entity_Id) return Entity_Id is
8406 Prim := First_Elmt (Collect_Primitive_Operations (E));
8407 while Present (Prim) loop
8410 if Chars (Op) = Name_Op_Eq
8411 and then Etype (Op) = Standard_Boolean
8412 and then Etype (First_Formal (Op)) = E
8413 and then Etype (Next_Formal (First_Formal (Op))) = E
8422 end Get_User_Defined_Eq;
8430 Priv_Typ : out Entity_Id;
8431 Full_Typ : out Entity_Id;
8432 Full_Base : out Entity_Id;
8433 CRec_Typ : out Entity_Id)
8435 IP_View : Entity_Id;
8438 -- Assume that none of the views can be recovered
8445 -- The input type is the corresponding record type of a protected or a
8448 if Ekind (Typ) = E_Record_Type
8449 and then Is_Concurrent_Record_Type (Typ)
8452 Full_Typ := Corresponding_Concurrent_Type (CRec_Typ);
8453 Full_Base := Base_Type (Full_Typ);
8454 Priv_Typ := Incomplete_Or_Partial_View (Full_Typ);
8456 -- Otherwise the input type denotes an arbitrary type
8459 IP_View := Incomplete_Or_Partial_View (Typ);
8461 -- The input type denotes the full view of a private type
8463 if Present (IP_View) then
8464 Priv_Typ := IP_View;
8467 -- The input type is a private type
8469 elsif Is_Private_Type (Typ) then
8471 Full_Typ := Full_View (Priv_Typ);
8473 -- Otherwise the input type does not have any views
8479 if Present (Full_Typ) then
8480 Full_Base := Base_Type (Full_Typ);
8482 if Ekind_In (Full_Typ, E_Protected_Type, E_Task_Type) then
8483 CRec_Typ := Corresponding_Record_Type (Full_Typ);
8489 -----------------------
8490 -- Has_Access_Values --
8491 -----------------------
8493 function Has_Access_Values (T : Entity_Id) return Boolean is
8494 Typ : constant Entity_Id := Underlying_Type (T);
8497 -- Case of a private type which is not completed yet. This can only
8498 -- happen in the case of a generic format type appearing directly, or
8499 -- as a component of the type to which this function is being applied
8500 -- at the top level. Return False in this case, since we certainly do
8501 -- not know that the type contains access types.
8506 elsif Is_Access_Type (Typ) then
8509 elsif Is_Array_Type (Typ) then
8510 return Has_Access_Values (Component_Type (Typ));
8512 elsif Is_Record_Type (Typ) then
8517 -- Loop to Check components
8519 Comp := First_Component_Or_Discriminant (Typ);
8520 while Present (Comp) loop
8522 -- Check for access component, tag field does not count, even
8523 -- though it is implemented internally using an access type.
8525 if Has_Access_Values (Etype (Comp))
8526 and then Chars (Comp) /= Name_uTag
8531 Next_Component_Or_Discriminant (Comp);
8540 end Has_Access_Values;
8542 ------------------------------
8543 -- Has_Compatible_Alignment --
8544 ------------------------------
8546 function Has_Compatible_Alignment
8549 Layout_Done : Boolean) return Alignment_Result
8551 function Has_Compatible_Alignment_Internal
8554 Layout_Done : Boolean;
8555 Default : Alignment_Result) return Alignment_Result;
8556 -- This is the internal recursive function that actually does the work.
8557 -- There is one additional parameter, which says what the result should
8558 -- be if no alignment information is found, and there is no definite
8559 -- indication of compatible alignments. At the outer level, this is set
8560 -- to Unknown, but for internal recursive calls in the case where types
8561 -- are known to be correct, it is set to Known_Compatible.
8563 ---------------------------------------
8564 -- Has_Compatible_Alignment_Internal --
8565 ---------------------------------------
8567 function Has_Compatible_Alignment_Internal
8570 Layout_Done : Boolean;
8571 Default : Alignment_Result) return Alignment_Result
8573 Result : Alignment_Result := Known_Compatible;
8574 -- Holds the current status of the result. Note that once a value of
8575 -- Known_Incompatible is set, it is sticky and does not get changed
8576 -- to Unknown (the value in Result only gets worse as we go along,
8579 Offs : Uint := No_Uint;
8580 -- Set to a factor of the offset from the base object when Expr is a
8581 -- selected or indexed component, based on Component_Bit_Offset and
8582 -- Component_Size respectively. A negative value is used to represent
8583 -- a value which is not known at compile time.
8585 procedure Check_Prefix;
8586 -- Checks the prefix recursively in the case where the expression
8587 -- is an indexed or selected component.
8589 procedure Set_Result (R : Alignment_Result);
8590 -- If R represents a worse outcome (unknown instead of known
8591 -- compatible, or known incompatible), then set Result to R.
8597 procedure Check_Prefix is
8599 -- The subtlety here is that in doing a recursive call to check
8600 -- the prefix, we have to decide what to do in the case where we
8601 -- don't find any specific indication of an alignment problem.
8603 -- At the outer level, we normally set Unknown as the result in
8604 -- this case, since we can only set Known_Compatible if we really
8605 -- know that the alignment value is OK, but for the recursive
8606 -- call, in the case where the types match, and we have not
8607 -- specified a peculiar alignment for the object, we are only
8608 -- concerned about suspicious rep clauses, the default case does
8609 -- not affect us, since the compiler will, in the absence of such
8610 -- rep clauses, ensure that the alignment is correct.
8612 if Default = Known_Compatible
8614 (Etype (Obj) = Etype (Expr)
8615 and then (Unknown_Alignment (Obj)
8617 Alignment (Obj) = Alignment (Etype (Obj))))
8620 (Has_Compatible_Alignment_Internal
8621 (Obj, Prefix (Expr), Layout_Done, Known_Compatible));
8623 -- In all other cases, we need a full check on the prefix
8627 (Has_Compatible_Alignment_Internal
8628 (Obj, Prefix (Expr), Layout_Done, Unknown));
8636 procedure Set_Result (R : Alignment_Result) is
8643 -- Start of processing for Has_Compatible_Alignment_Internal
8646 -- If Expr is a selected component, we must make sure there is no
8647 -- potentially troublesome component clause and that the record is
8648 -- not packed if the layout is not done.
8650 if Nkind (Expr) = N_Selected_Component then
8652 -- Packing generates unknown alignment if layout is not done
8654 if Is_Packed (Etype (Prefix (Expr))) and then not Layout_Done then
8655 Set_Result (Unknown);
8658 -- Check prefix and component offset
8661 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
8663 -- If Expr is an indexed component, we must make sure there is no
8664 -- potentially troublesome Component_Size clause and that the array
8665 -- is not bit-packed if the layout is not done.
8667 elsif Nkind (Expr) = N_Indexed_Component then
8669 Typ : constant Entity_Id := Etype (Prefix (Expr));
8672 -- Packing generates unknown alignment if layout is not done
8674 if Is_Bit_Packed_Array (Typ) and then not Layout_Done then
8675 Set_Result (Unknown);
8678 -- Check prefix and component offset (or at least size)
8681 Offs := Indexed_Component_Bit_Offset (Expr);
8682 if Offs = No_Uint then
8683 Offs := Component_Size (Typ);
8688 -- If we have a null offset, the result is entirely determined by
8689 -- the base object and has already been computed recursively.
8691 if Offs = Uint_0 then
8694 -- Case where we know the alignment of the object
8696 elsif Known_Alignment (Obj) then
8698 ObjA : constant Uint := Alignment (Obj);
8699 ExpA : Uint := No_Uint;
8700 SizA : Uint := No_Uint;
8703 -- If alignment of Obj is 1, then we are always OK
8706 Set_Result (Known_Compatible);
8708 -- Alignment of Obj is greater than 1, so we need to check
8711 -- If we have an offset, see if it is compatible
8713 if Offs /= No_Uint and Offs > Uint_0 then
8714 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
8715 Set_Result (Known_Incompatible);
8718 -- See if Expr is an object with known alignment
8720 elsif Is_Entity_Name (Expr)
8721 and then Known_Alignment (Entity (Expr))
8723 ExpA := Alignment (Entity (Expr));
8725 -- Otherwise, we can use the alignment of the type of
8726 -- Expr given that we already checked for
8727 -- discombobulating rep clauses for the cases of indexed
8728 -- and selected components above.
8730 elsif Known_Alignment (Etype (Expr)) then
8731 ExpA := Alignment (Etype (Expr));
8733 -- Otherwise the alignment is unknown
8736 Set_Result (Default);
8739 -- If we got an alignment, see if it is acceptable
8741 if ExpA /= No_Uint and then ExpA < ObjA then
8742 Set_Result (Known_Incompatible);
8745 -- If Expr is not a piece of a larger object, see if size
8746 -- is given. If so, check that it is not too small for the
8747 -- required alignment.
8749 if Offs /= No_Uint then
8752 -- See if Expr is an object with known size
8754 elsif Is_Entity_Name (Expr)
8755 and then Known_Static_Esize (Entity (Expr))
8757 SizA := Esize (Entity (Expr));
8759 -- Otherwise, we check the object size of the Expr type
8761 elsif Known_Static_Esize (Etype (Expr)) then
8762 SizA := Esize (Etype (Expr));
8765 -- If we got a size, see if it is a multiple of the Obj
8766 -- alignment, if not, then the alignment cannot be
8767 -- acceptable, since the size is always a multiple of the
8770 if SizA /= No_Uint then
8771 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
8772 Set_Result (Known_Incompatible);
8778 -- If we do not know required alignment, any non-zero offset is a
8779 -- potential problem (but certainly may be OK, so result is unknown).
8781 elsif Offs /= No_Uint then
8782 Set_Result (Unknown);
8784 -- If we can't find the result by direct comparison of alignment
8785 -- values, then there is still one case that we can determine known
8786 -- result, and that is when we can determine that the types are the
8787 -- same, and no alignments are specified. Then we known that the
8788 -- alignments are compatible, even if we don't know the alignment
8789 -- value in the front end.
8791 elsif Etype (Obj) = Etype (Expr) then
8793 -- Types are the same, but we have to check for possible size
8794 -- and alignments on the Expr object that may make the alignment
8795 -- different, even though the types are the same.
8797 if Is_Entity_Name (Expr) then
8799 -- First check alignment of the Expr object. Any alignment less
8800 -- than Maximum_Alignment is worrisome since this is the case
8801 -- where we do not know the alignment of Obj.
8803 if Known_Alignment (Entity (Expr))
8804 and then UI_To_Int (Alignment (Entity (Expr))) <
8805 Ttypes.Maximum_Alignment
8807 Set_Result (Unknown);
8809 -- Now check size of Expr object. Any size that is not an
8810 -- even multiple of Maximum_Alignment is also worrisome
8811 -- since it may cause the alignment of the object to be less
8812 -- than the alignment of the type.
8814 elsif Known_Static_Esize (Entity (Expr))
8816 (UI_To_Int (Esize (Entity (Expr))) mod
8817 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
8820 Set_Result (Unknown);
8822 -- Otherwise same type is decisive
8825 Set_Result (Known_Compatible);
8829 -- Another case to deal with is when there is an explicit size or
8830 -- alignment clause when the types are not the same. If so, then the
8831 -- result is Unknown. We don't need to do this test if the Default is
8832 -- Unknown, since that result will be set in any case.
8834 elsif Default /= Unknown
8835 and then (Has_Size_Clause (Etype (Expr))
8837 Has_Alignment_Clause (Etype (Expr)))
8839 Set_Result (Unknown);
8841 -- If no indication found, set default
8844 Set_Result (Default);
8847 -- Return worst result found
8850 end Has_Compatible_Alignment_Internal;
8852 -- Start of processing for Has_Compatible_Alignment
8855 -- If Obj has no specified alignment, then set alignment from the type
8856 -- alignment. Perhaps we should always do this, but for sure we should
8857 -- do it when there is an address clause since we can do more if the
8858 -- alignment is known.
8860 if Unknown_Alignment (Obj) then
8861 Set_Alignment (Obj, Alignment (Etype (Obj)));
8864 -- Now do the internal call that does all the work
8867 Has_Compatible_Alignment_Internal (Obj, Expr, Layout_Done, Unknown);
8868 end Has_Compatible_Alignment;
8870 ----------------------
8871 -- Has_Declarations --
8872 ----------------------
8874 function Has_Declarations (N : Node_Id) return Boolean is
8876 return Nkind_In (Nkind (N), N_Accept_Statement,
8878 N_Compilation_Unit_Aux,
8884 N_Package_Specification);
8885 end Has_Declarations;
8887 ---------------------------------
8888 -- Has_Defaulted_Discriminants --
8889 ---------------------------------
8891 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
8893 return Has_Discriminants (Typ)
8894 and then Present (First_Discriminant (Typ))
8895 and then Present (Discriminant_Default_Value
8896 (First_Discriminant (Typ)));
8897 end Has_Defaulted_Discriminants;
8903 function Has_Denormals (E : Entity_Id) return Boolean is
8905 return Is_Floating_Point_Type (E) and then Denorm_On_Target;
8908 -------------------------------------------
8909 -- Has_Discriminant_Dependent_Constraint --
8910 -------------------------------------------
8912 function Has_Discriminant_Dependent_Constraint
8913 (Comp : Entity_Id) return Boolean
8915 Comp_Decl : constant Node_Id := Parent (Comp);
8916 Subt_Indic : Node_Id;
8921 -- Discriminants can't depend on discriminants
8923 if Ekind (Comp) = E_Discriminant then
8927 Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl));
8929 if Nkind (Subt_Indic) = N_Subtype_Indication then
8930 Constr := Constraint (Subt_Indic);
8932 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
8933 Assn := First (Constraints (Constr));
8934 while Present (Assn) loop
8935 case Nkind (Assn) is
8936 when N_Subtype_Indication |
8940 if Depends_On_Discriminant (Assn) then
8944 when N_Discriminant_Association =>
8945 if Depends_On_Discriminant (Expression (Assn)) then
8960 end Has_Discriminant_Dependent_Constraint;
8962 --------------------------------------
8963 -- Has_Effectively_Volatile_Profile --
8964 --------------------------------------
8966 function Has_Effectively_Volatile_Profile
8967 (Subp_Id : Entity_Id) return Boolean
8972 -- Inspect the formal parameters looking for an effectively volatile
8975 Formal := First_Formal (Subp_Id);
8976 while Present (Formal) loop
8977 if Is_Effectively_Volatile (Etype (Formal)) then
8981 Next_Formal (Formal);
8984 -- Inspect the return type of functions
8986 if Ekind_In (Subp_Id, E_Function, E_Generic_Function)
8987 and then Is_Effectively_Volatile (Etype (Subp_Id))
8993 end Has_Effectively_Volatile_Profile;
8995 --------------------------
8996 -- Has_Enabled_Property --
8997 --------------------------
8999 function Has_Enabled_Property
9000 (Item_Id : Entity_Id;
9001 Property : Name_Id) return Boolean
9003 function State_Has_Enabled_Property return Boolean;
9004 -- Determine whether a state denoted by Item_Id has the property enabled
9006 function Variable_Has_Enabled_Property return Boolean;
9007 -- Determine whether a variable denoted by Item_Id has the property
9010 --------------------------------
9011 -- State_Has_Enabled_Property --
9012 --------------------------------
9014 function State_Has_Enabled_Property return Boolean is
9015 Decl : constant Node_Id := Parent (Item_Id);
9023 -- The declaration of an external abstract state appears as an
9024 -- extension aggregate. If this is not the case, properties can never
9027 if Nkind (Decl) /= N_Extension_Aggregate then
9031 -- When External appears as a simple option, it automatically enables
9034 Opt := First (Expressions (Decl));
9035 while Present (Opt) loop
9036 if Nkind (Opt) = N_Identifier
9037 and then Chars (Opt) = Name_External
9045 -- When External specifies particular properties, inspect those and
9046 -- find the desired one (if any).
9048 Opt := First (Component_Associations (Decl));
9049 while Present (Opt) loop
9050 Opt_Nam := First (Choices (Opt));
9052 if Nkind (Opt_Nam) = N_Identifier
9053 and then Chars (Opt_Nam) = Name_External
9055 Props := Expression (Opt);
9057 -- Multiple properties appear as an aggregate
9059 if Nkind (Props) = N_Aggregate then
9061 -- Simple property form
9063 Prop := First (Expressions (Props));
9064 while Present (Prop) loop
9065 if Chars (Prop) = Property then
9072 -- Property with expression form
9074 Prop := First (Component_Associations (Props));
9075 while Present (Prop) loop
9076 Prop_Nam := First (Choices (Prop));
9078 -- The property can be represented in two ways:
9079 -- others => <value>
9080 -- <property> => <value>
9082 if Nkind (Prop_Nam) = N_Others_Choice
9083 or else (Nkind (Prop_Nam) = N_Identifier
9084 and then Chars (Prop_Nam) = Property)
9086 return Is_True (Expr_Value (Expression (Prop)));
9095 return Chars (Props) = Property;
9103 end State_Has_Enabled_Property;
9105 -----------------------------------
9106 -- Variable_Has_Enabled_Property --
9107 -----------------------------------
9109 function Variable_Has_Enabled_Property return Boolean is
9110 function Is_Enabled (Prag : Node_Id) return Boolean;
9111 -- Determine whether property pragma Prag (if present) denotes an
9112 -- enabled property.
9118 function Is_Enabled (Prag : Node_Id) return Boolean is
9122 if Present (Prag) then
9123 Arg1 := First (Pragma_Argument_Associations (Prag));
9125 -- The pragma has an optional Boolean expression, the related
9126 -- property is enabled only when the expression evaluates to
9129 if Present (Arg1) then
9130 return Is_True (Expr_Value (Get_Pragma_Arg (Arg1)));
9132 -- Otherwise the lack of expression enables the property by
9139 -- The property was never set in the first place
9148 AR : constant Node_Id :=
9149 Get_Pragma (Item_Id, Pragma_Async_Readers);
9150 AW : constant Node_Id :=
9151 Get_Pragma (Item_Id, Pragma_Async_Writers);
9152 ER : constant Node_Id :=
9153 Get_Pragma (Item_Id, Pragma_Effective_Reads);
9154 EW : constant Node_Id :=
9155 Get_Pragma (Item_Id, Pragma_Effective_Writes);
9157 -- Start of processing for Variable_Has_Enabled_Property
9160 -- A non-effectively volatile object can never possess external
9163 if not Is_Effectively_Volatile (Item_Id) then
9166 -- External properties related to variables come in two flavors -
9167 -- explicit and implicit. The explicit case is characterized by the
9168 -- presence of a property pragma with an optional Boolean flag. The
9169 -- property is enabled when the flag evaluates to True or the flag is
9170 -- missing altogether.
9172 elsif Property = Name_Async_Readers and then Is_Enabled (AR) then
9175 elsif Property = Name_Async_Writers and then Is_Enabled (AW) then
9178 elsif Property = Name_Effective_Reads and then Is_Enabled (ER) then
9181 elsif Property = Name_Effective_Writes and then Is_Enabled (EW) then
9184 -- The implicit case lacks all property pragmas
9186 elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then
9192 end Variable_Has_Enabled_Property;
9194 -- Start of processing for Has_Enabled_Property
9197 -- Abstract states and variables have a flexible scheme of specifying
9198 -- external properties.
9200 if Ekind (Item_Id) = E_Abstract_State then
9201 return State_Has_Enabled_Property;
9203 elsif Ekind (Item_Id) = E_Variable then
9204 return Variable_Has_Enabled_Property;
9206 -- Otherwise a property is enabled when the related item is effectively
9210 return Is_Effectively_Volatile (Item_Id);
9212 end Has_Enabled_Property;
9214 -------------------------------------
9215 -- Has_Full_Default_Initialization --
9216 -------------------------------------
9218 function Has_Full_Default_Initialization (Typ : Entity_Id) return Boolean is
9223 -- A type subject to pragma Default_Initial_Condition is fully default
9224 -- initialized when the pragma appears with a non-null argument. Since
9225 -- any type may act as the full view of a private type, this check must
9226 -- be performed prior to the specialized tests below.
9228 if Has_DIC (Typ) then
9229 Prag := Get_Pragma (Typ, Pragma_Default_Initial_Condition);
9230 pragma Assert (Present (Prag));
9232 return Is_Verifiable_DIC_Pragma (Prag);
9235 -- A scalar type is fully default initialized if it is subject to aspect
9238 if Is_Scalar_Type (Typ) then
9239 return Has_Default_Aspect (Typ);
9241 -- An array type is fully default initialized if its element type is
9242 -- scalar and the array type carries aspect Default_Component_Value or
9243 -- the element type is fully default initialized.
9245 elsif Is_Array_Type (Typ) then
9247 Has_Default_Aspect (Typ)
9248 or else Has_Full_Default_Initialization (Component_Type (Typ));
9250 -- A protected type, record type, or type extension is fully default
9251 -- initialized if all its components either carry an initialization
9252 -- expression or have a type that is fully default initialized. The
9253 -- parent type of a type extension must be fully default initialized.
9255 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
9257 -- Inspect all entities defined in the scope of the type, looking for
9258 -- uninitialized components.
9260 Comp := First_Entity (Typ);
9261 while Present (Comp) loop
9262 if Ekind (Comp) = E_Component
9263 and then Comes_From_Source (Comp)
9264 and then No (Expression (Parent (Comp)))
9265 and then not Has_Full_Default_Initialization (Etype (Comp))
9273 -- Ensure that the parent type of a type extension is fully default
9276 if Etype (Typ) /= Typ
9277 and then not Has_Full_Default_Initialization (Etype (Typ))
9282 -- If we get here, then all components and parent portion are fully
9283 -- default initialized.
9287 -- A task type is fully default initialized by default
9289 elsif Is_Task_Type (Typ) then
9292 -- Otherwise the type is not fully default initialized
9297 end Has_Full_Default_Initialization;
9299 --------------------
9300 -- Has_Infinities --
9301 --------------------
9303 function Has_Infinities (E : Entity_Id) return Boolean is
9306 Is_Floating_Point_Type (E)
9307 and then Nkind (Scalar_Range (E)) = N_Range
9308 and then Includes_Infinities (Scalar_Range (E));
9311 --------------------
9312 -- Has_Interfaces --
9313 --------------------
9315 function Has_Interfaces
9317 Use_Full_View : Boolean := True) return Boolean
9319 Typ : Entity_Id := Base_Type (T);
9322 -- Handle concurrent types
9324 if Is_Concurrent_Type (Typ) then
9325 Typ := Corresponding_Record_Type (Typ);
9328 if not Present (Typ)
9329 or else not Is_Record_Type (Typ)
9330 or else not Is_Tagged_Type (Typ)
9335 -- Handle private types
9337 if Use_Full_View and then Present (Full_View (Typ)) then
9338 Typ := Full_View (Typ);
9341 -- Handle concurrent record types
9343 if Is_Concurrent_Record_Type (Typ)
9344 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
9350 if Is_Interface (Typ)
9352 (Is_Record_Type (Typ)
9353 and then Present (Interfaces (Typ))
9354 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
9359 exit when Etype (Typ) = Typ
9361 -- Handle private types
9363 or else (Present (Full_View (Etype (Typ)))
9364 and then Full_View (Etype (Typ)) = Typ)
9366 -- Protect frontend against wrong sources with cyclic derivations
9368 or else Etype (Typ) = T;
9370 -- Climb to the ancestor type handling private types
9372 if Present (Full_View (Etype (Typ))) then
9373 Typ := Full_View (Etype (Typ));
9382 --------------------------
9383 -- Has_Max_Queue_Length --
9384 --------------------------
9386 function Has_Max_Queue_Length (Id : Entity_Id) return Boolean is
9389 Ekind (Id) = E_Entry
9390 and then Present (Get_Pragma (Id, Pragma_Max_Queue_Length));
9391 end Has_Max_Queue_Length;
9393 ---------------------------------
9394 -- Has_No_Obvious_Side_Effects --
9395 ---------------------------------
9397 function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
9399 -- For now handle literals, constants, and non-volatile variables and
9400 -- expressions combining these with operators or short circuit forms.
9402 if Nkind (N) in N_Numeric_Or_String_Literal then
9405 elsif Nkind (N) = N_Character_Literal then
9408 elsif Nkind (N) in N_Unary_Op then
9409 return Has_No_Obvious_Side_Effects (Right_Opnd (N));
9411 elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
9412 return Has_No_Obvious_Side_Effects (Left_Opnd (N))
9414 Has_No_Obvious_Side_Effects (Right_Opnd (N));
9416 elsif Nkind (N) = N_Expression_With_Actions
9417 and then Is_Empty_List (Actions (N))
9419 return Has_No_Obvious_Side_Effects (Expression (N));
9421 elsif Nkind (N) in N_Has_Entity then
9422 return Present (Entity (N))
9423 and then Ekind_In (Entity (N), E_Variable,
9425 E_Enumeration_Literal,
9429 and then not Is_Volatile (Entity (N));
9434 end Has_No_Obvious_Side_Effects;
9436 -----------------------------
9437 -- Has_Non_Null_Refinement --
9438 -----------------------------
9440 function Has_Non_Null_Refinement (Id : Entity_Id) return Boolean is
9441 Constits : Elist_Id;
9444 pragma Assert (Ekind (Id) = E_Abstract_State);
9445 Constits := Refinement_Constituents (Id);
9447 -- For a refinement to be non-null, the first constituent must be
9448 -- anything other than null.
9452 and then Nkind (Node (First_Elmt (Constits))) /= N_Null;
9453 end Has_Non_Null_Refinement;
9459 function Has_Null_Body (Proc_Id : Entity_Id) return Boolean is
9460 Body_Id : Entity_Id;
9467 Spec := Parent (Proc_Id);
9468 Decl := Parent (Spec);
9470 -- Retrieve the entity of the procedure body (e.g. invariant proc).
9472 if Nkind (Spec) = N_Procedure_Specification
9473 and then Nkind (Decl) = N_Subprogram_Declaration
9475 Body_Id := Corresponding_Body (Decl);
9477 -- The body acts as a spec
9483 -- The body will be generated later
9485 if No (Body_Id) then
9489 Spec := Parent (Body_Id);
9490 Decl := Parent (Spec);
9493 (Nkind (Spec) = N_Procedure_Specification
9494 and then Nkind (Decl) = N_Subprogram_Body);
9496 Stmt1 := First (Statements (Handled_Statement_Sequence (Decl)));
9498 -- Look for a null statement followed by an optional return
9501 if Nkind (Stmt1) = N_Null_Statement then
9502 Stmt2 := Next (Stmt1);
9504 if Present (Stmt2) then
9505 return Nkind (Stmt2) = N_Simple_Return_Statement;
9514 ------------------------
9515 -- Has_Null_Exclusion --
9516 ------------------------
9518 function Has_Null_Exclusion (N : Node_Id) return Boolean is
9521 when N_Access_Definition |
9522 N_Access_Function_Definition |
9523 N_Access_Procedure_Definition |
9524 N_Access_To_Object_Definition |
9526 N_Derived_Type_Definition |
9527 N_Function_Specification |
9528 N_Subtype_Declaration =>
9529 return Null_Exclusion_Present (N);
9531 when N_Component_Definition |
9532 N_Formal_Object_Declaration |
9533 N_Object_Renaming_Declaration =>
9534 if Present (Subtype_Mark (N)) then
9535 return Null_Exclusion_Present (N);
9536 else pragma Assert (Present (Access_Definition (N)));
9537 return Null_Exclusion_Present (Access_Definition (N));
9540 when N_Discriminant_Specification =>
9541 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
9542 return Null_Exclusion_Present (Discriminant_Type (N));
9544 return Null_Exclusion_Present (N);
9547 when N_Object_Declaration =>
9548 if Nkind (Object_Definition (N)) = N_Access_Definition then
9549 return Null_Exclusion_Present (Object_Definition (N));
9551 return Null_Exclusion_Present (N);
9554 when N_Parameter_Specification =>
9555 if Nkind (Parameter_Type (N)) = N_Access_Definition then
9556 return Null_Exclusion_Present (Parameter_Type (N));
9558 return Null_Exclusion_Present (N);
9565 end Has_Null_Exclusion;
9567 ------------------------
9568 -- Has_Null_Extension --
9569 ------------------------
9571 function Has_Null_Extension (T : Entity_Id) return Boolean is
9572 B : constant Entity_Id := Base_Type (T);
9577 if Nkind (Parent (B)) = N_Full_Type_Declaration
9578 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
9580 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
9582 if Present (Ext) then
9583 if Null_Present (Ext) then
9586 Comps := Component_List (Ext);
9588 -- The null component list is rewritten during analysis to
9589 -- include the parent component. Any other component indicates
9590 -- that the extension was not originally null.
9592 return Null_Present (Comps)
9593 or else No (Next (First (Component_Items (Comps))));
9602 end Has_Null_Extension;
9604 -------------------------
9605 -- Has_Null_Refinement --
9606 -------------------------
9608 function Has_Null_Refinement (Id : Entity_Id) return Boolean is
9609 Constits : Elist_Id;
9612 pragma Assert (Ekind (Id) = E_Abstract_State);
9613 Constits := Refinement_Constituents (Id);
9615 -- For a refinement to be null, the state's sole constituent must be a
9620 and then Nkind (Node (First_Elmt (Constits))) = N_Null;
9621 end Has_Null_Refinement;
9623 -------------------------------
9624 -- Has_Overriding_Initialize --
9625 -------------------------------
9627 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
9628 BT : constant Entity_Id := Base_Type (T);
9632 if Is_Controlled (BT) then
9633 if Is_RTU (Scope (BT), Ada_Finalization) then
9636 elsif Present (Primitive_Operations (BT)) then
9637 P := First_Elmt (Primitive_Operations (BT));
9638 while Present (P) loop
9640 Init : constant Entity_Id := Node (P);
9641 Formal : constant Entity_Id := First_Formal (Init);
9643 if Ekind (Init) = E_Procedure
9644 and then Chars (Init) = Name_Initialize
9645 and then Comes_From_Source (Init)
9646 and then Present (Formal)
9647 and then Etype (Formal) = BT
9648 and then No (Next_Formal (Formal))
9649 and then (Ada_Version < Ada_2012
9650 or else not Null_Present (Parent (Init)))
9660 -- Here if type itself does not have a non-null Initialize operation:
9661 -- check immediate ancestor.
9663 if Is_Derived_Type (BT)
9664 and then Has_Overriding_Initialize (Etype (BT))
9671 end Has_Overriding_Initialize;
9673 --------------------------------------
9674 -- Has_Preelaborable_Initialization --
9675 --------------------------------------
9677 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
9680 procedure Check_Components (E : Entity_Id);
9681 -- Check component/discriminant chain, sets Has_PE False if a component
9682 -- or discriminant does not meet the preelaborable initialization rules.
9684 ----------------------
9685 -- Check_Components --
9686 ----------------------
9688 procedure Check_Components (E : Entity_Id) is
9692 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
9693 -- Returns True if and only if the expression denoted by N does not
9694 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
9696 ---------------------------------
9697 -- Is_Preelaborable_Expression --
9698 ---------------------------------
9700 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
9704 Comp_Type : Entity_Id;
9705 Is_Array_Aggr : Boolean;
9708 if Is_OK_Static_Expression (N) then
9711 elsif Nkind (N) = N_Null then
9714 -- Attributes are allowed in general, even if their prefix is a
9715 -- formal type. (It seems that certain attributes known not to be
9716 -- static might not be allowed, but there are no rules to prevent
9719 elsif Nkind (N) = N_Attribute_Reference then
9722 -- The name of a discriminant evaluated within its parent type is
9723 -- defined to be preelaborable (10.2.1(8)). Note that we test for
9724 -- names that denote discriminals as well as discriminants to
9725 -- catch references occurring within init procs.
9727 elsif Is_Entity_Name (N)
9729 (Ekind (Entity (N)) = E_Discriminant
9730 or else (Ekind_In (Entity (N), E_Constant, E_In_Parameter)
9731 and then Present (Discriminal_Link (Entity (N)))))
9735 elsif Nkind (N) = N_Qualified_Expression then
9736 return Is_Preelaborable_Expression (Expression (N));
9738 -- For aggregates we have to check that each of the associations
9739 -- is preelaborable.
9741 elsif Nkind_In (N, N_Aggregate, N_Extension_Aggregate) then
9742 Is_Array_Aggr := Is_Array_Type (Etype (N));
9744 if Is_Array_Aggr then
9745 Comp_Type := Component_Type (Etype (N));
9748 -- Check the ancestor part of extension aggregates, which must
9749 -- be either the name of a type that has preelaborable init or
9750 -- an expression that is preelaborable.
9752 if Nkind (N) = N_Extension_Aggregate then
9754 Anc_Part : constant Node_Id := Ancestor_Part (N);
9757 if Is_Entity_Name (Anc_Part)
9758 and then Is_Type (Entity (Anc_Part))
9760 if not Has_Preelaborable_Initialization
9766 elsif not Is_Preelaborable_Expression (Anc_Part) then
9772 -- Check positional associations
9774 Exp := First (Expressions (N));
9775 while Present (Exp) loop
9776 if not Is_Preelaborable_Expression (Exp) then
9783 -- Check named associations
9785 Assn := First (Component_Associations (N));
9786 while Present (Assn) loop
9787 Choice := First (Choices (Assn));
9788 while Present (Choice) loop
9789 if Is_Array_Aggr then
9790 if Nkind (Choice) = N_Others_Choice then
9793 elsif Nkind (Choice) = N_Range then
9794 if not Is_OK_Static_Range (Choice) then
9798 elsif not Is_OK_Static_Expression (Choice) then
9803 Comp_Type := Etype (Choice);
9809 -- If the association has a <> at this point, then we have
9810 -- to check whether the component's type has preelaborable
9811 -- initialization. Note that this only occurs when the
9812 -- association's corresponding component does not have a
9813 -- default expression, the latter case having already been
9814 -- expanded as an expression for the association.
9816 if Box_Present (Assn) then
9817 if not Has_Preelaborable_Initialization (Comp_Type) then
9821 -- In the expression case we check whether the expression
9822 -- is preelaborable.
9825 not Is_Preelaborable_Expression (Expression (Assn))
9833 -- If we get here then aggregate as a whole is preelaborable
9837 -- All other cases are not preelaborable
9842 end Is_Preelaborable_Expression;
9844 -- Start of processing for Check_Components
9847 -- Loop through entities of record or protected type
9850 while Present (Ent) loop
9852 -- We are interested only in components and discriminants
9859 -- Get default expression if any. If there is no declaration
9860 -- node, it means we have an internal entity. The parent and
9861 -- tag fields are examples of such entities. For such cases,
9862 -- we just test the type of the entity.
9864 if Present (Declaration_Node (Ent)) then
9865 Exp := Expression (Declaration_Node (Ent));
9868 when E_Discriminant =>
9870 -- Note: for a renamed discriminant, the Declaration_Node
9871 -- may point to the one from the ancestor, and have a
9872 -- different expression, so use the proper attribute to
9873 -- retrieve the expression from the derived constraint.
9875 Exp := Discriminant_Default_Value (Ent);
9878 goto Check_Next_Entity;
9881 -- A component has PI if it has no default expression and the
9882 -- component type has PI.
9885 if not Has_Preelaborable_Initialization (Etype (Ent)) then
9890 -- Require the default expression to be preelaborable
9892 elsif not Is_Preelaborable_Expression (Exp) then
9897 <<Check_Next_Entity>>
9900 end Check_Components;
9902 -- Start of processing for Has_Preelaborable_Initialization
9905 -- Immediate return if already marked as known preelaborable init. This
9906 -- covers types for which this function has already been called once
9907 -- and returned True (in which case the result is cached), and also
9908 -- types to which a pragma Preelaborable_Initialization applies.
9910 if Known_To_Have_Preelab_Init (E) then
9914 -- If the type is a subtype representing a generic actual type, then
9915 -- test whether its base type has preelaborable initialization since
9916 -- the subtype representing the actual does not inherit this attribute
9917 -- from the actual or formal. (but maybe it should???)
9919 if Is_Generic_Actual_Type (E) then
9920 return Has_Preelaborable_Initialization (Base_Type (E));
9923 -- All elementary types have preelaborable initialization
9925 if Is_Elementary_Type (E) then
9928 -- Array types have PI if the component type has PI
9930 elsif Is_Array_Type (E) then
9931 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
9933 -- A derived type has preelaborable initialization if its parent type
9934 -- has preelaborable initialization and (in the case of a derived record
9935 -- extension) if the non-inherited components all have preelaborable
9936 -- initialization. However, a user-defined controlled type with an
9937 -- overriding Initialize procedure does not have preelaborable
9940 elsif Is_Derived_Type (E) then
9942 -- If the derived type is a private extension then it doesn't have
9943 -- preelaborable initialization.
9945 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
9949 -- First check whether ancestor type has preelaborable initialization
9951 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
9953 -- If OK, check extension components (if any)
9955 if Has_PE and then Is_Record_Type (E) then
9956 Check_Components (First_Entity (E));
9959 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
9960 -- with a user defined Initialize procedure does not have PI. If
9961 -- the type is untagged, the control primitives come from a component
9962 -- that has already been checked.
9965 and then Is_Controlled (E)
9966 and then Is_Tagged_Type (E)
9967 and then Has_Overriding_Initialize (E)
9972 -- Private types not derived from a type having preelaborable init and
9973 -- that are not marked with pragma Preelaborable_Initialization do not
9974 -- have preelaborable initialization.
9976 elsif Is_Private_Type (E) then
9979 -- Record type has PI if it is non private and all components have PI
9981 elsif Is_Record_Type (E) then
9983 Check_Components (First_Entity (E));
9985 -- Protected types must not have entries, and components must meet
9986 -- same set of rules as for record components.
9988 elsif Is_Protected_Type (E) then
9989 if Has_Entries (E) then
9993 Check_Components (First_Entity (E));
9994 Check_Components (First_Private_Entity (E));
9997 -- Type System.Address always has preelaborable initialization
9999 elsif Is_RTE (E, RE_Address) then
10002 -- In all other cases, type does not have preelaborable initialization
10008 -- If type has preelaborable initialization, cache result
10011 Set_Known_To_Have_Preelab_Init (E);
10015 end Has_Preelaborable_Initialization;
10017 ---------------------------
10018 -- Has_Private_Component --
10019 ---------------------------
10021 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
10022 Btype : Entity_Id := Base_Type (Type_Id);
10023 Component : Entity_Id;
10026 if Error_Posted (Type_Id)
10027 or else Error_Posted (Btype)
10032 if Is_Class_Wide_Type (Btype) then
10033 Btype := Root_Type (Btype);
10036 if Is_Private_Type (Btype) then
10038 UT : constant Entity_Id := Underlying_Type (Btype);
10041 if No (Full_View (Btype)) then
10042 return not Is_Generic_Type (Btype)
10044 not Is_Generic_Type (Root_Type (Btype));
10046 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
10049 return not Is_Frozen (UT) and then Has_Private_Component (UT);
10053 elsif Is_Array_Type (Btype) then
10054 return Has_Private_Component (Component_Type (Btype));
10056 elsif Is_Record_Type (Btype) then
10057 Component := First_Component (Btype);
10058 while Present (Component) loop
10059 if Has_Private_Component (Etype (Component)) then
10063 Next_Component (Component);
10068 elsif Is_Protected_Type (Btype)
10069 and then Present (Corresponding_Record_Type (Btype))
10071 return Has_Private_Component (Corresponding_Record_Type (Btype));
10076 end Has_Private_Component;
10078 ----------------------
10079 -- Has_Signed_Zeros --
10080 ----------------------
10082 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
10084 return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target;
10085 end Has_Signed_Zeros;
10087 ------------------------------
10088 -- Has_Significant_Contract --
10089 ------------------------------
10091 function Has_Significant_Contract (Subp_Id : Entity_Id) return Boolean is
10092 Subp_Nam : constant Name_Id := Chars (Subp_Id);
10095 -- _Finalizer procedure
10097 if Subp_Nam = Name_uFinalizer then
10100 -- _Postconditions procedure
10102 elsif Subp_Nam = Name_uPostconditions then
10105 -- Predicate function
10107 elsif Ekind (Subp_Id) = E_Function
10108 and then Is_Predicate_Function (Subp_Id)
10114 elsif Get_TSS_Name (Subp_Id) /= TSS_Null then
10120 end Has_Significant_Contract;
10122 -----------------------------
10123 -- Has_Static_Array_Bounds --
10124 -----------------------------
10126 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
10127 Ndims : constant Nat := Number_Dimensions (Typ);
10134 -- Unconstrained types do not have static bounds
10136 if not Is_Constrained (Typ) then
10140 -- First treat string literals specially, as the lower bound and length
10141 -- of string literals are not stored like those of arrays.
10143 -- A string literal always has static bounds
10145 if Ekind (Typ) = E_String_Literal_Subtype then
10149 -- Treat all dimensions in turn
10151 Index := First_Index (Typ);
10152 for Indx in 1 .. Ndims loop
10154 -- In case of an illegal index which is not a discrete type, return
10155 -- that the type is not static.
10157 if not Is_Discrete_Type (Etype (Index))
10158 or else Etype (Index) = Any_Type
10163 Get_Index_Bounds (Index, Low, High);
10165 if Error_Posted (Low) or else Error_Posted (High) then
10169 if Is_OK_Static_Expression (Low)
10171 Is_OK_Static_Expression (High)
10181 -- If we fall through the loop, all indexes matched
10184 end Has_Static_Array_Bounds;
10190 function Has_Stream (T : Entity_Id) return Boolean is
10197 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
10200 elsif Is_Array_Type (T) then
10201 return Has_Stream (Component_Type (T));
10203 elsif Is_Record_Type (T) then
10204 E := First_Component (T);
10205 while Present (E) loop
10206 if Has_Stream (Etype (E)) then
10209 Next_Component (E);
10215 elsif Is_Private_Type (T) then
10216 return Has_Stream (Underlying_Type (T));
10227 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
10229 Get_Name_String (Chars (E));
10230 return Name_Buffer (Name_Len) = Suffix;
10237 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
10239 Get_Name_String (Chars (E));
10240 Add_Char_To_Name_Buffer (Suffix);
10244 -------------------
10245 -- Remove_Suffix --
10246 -------------------
10248 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
10250 pragma Assert (Has_Suffix (E, Suffix));
10251 Get_Name_String (Chars (E));
10252 Name_Len := Name_Len - 1;
10256 ----------------------------------
10257 -- Replace_Null_By_Null_Address --
10258 ----------------------------------
10260 procedure Replace_Null_By_Null_Address (N : Node_Id) is
10261 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id);
10262 -- Replace operand Op with a reference to Null_Address when the operand
10263 -- denotes a null Address. Other_Op denotes the other operand.
10265 --------------------------
10266 -- Replace_Null_Operand --
10267 --------------------------
10269 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id) is
10271 -- Check the type of the complementary operand since the N_Null node
10272 -- has not been decorated yet.
10274 if Nkind (Op) = N_Null
10275 and then Is_Descendant_Of_Address (Etype (Other_Op))
10277 Rewrite (Op, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (Op)));
10279 end Replace_Null_Operand;
10281 -- Start of processing for Replace_Null_By_Null_Address
10284 pragma Assert (Relaxed_RM_Semantics);
10285 pragma Assert (Nkind_In (N, N_Null,
10293 if Nkind (N) = N_Null then
10294 Rewrite (N, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (N)));
10298 L : constant Node_Id := Left_Opnd (N);
10299 R : constant Node_Id := Right_Opnd (N);
10302 Replace_Null_Operand (L, Other_Op => R);
10303 Replace_Null_Operand (R, Other_Op => L);
10306 end Replace_Null_By_Null_Address;
10308 --------------------------
10309 -- Has_Tagged_Component --
10310 --------------------------
10312 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
10316 if Is_Private_Type (Typ) and then Present (Underlying_Type (Typ)) then
10317 return Has_Tagged_Component (Underlying_Type (Typ));
10319 elsif Is_Array_Type (Typ) then
10320 return Has_Tagged_Component (Component_Type (Typ));
10322 elsif Is_Tagged_Type (Typ) then
10325 elsif Is_Record_Type (Typ) then
10326 Comp := First_Component (Typ);
10327 while Present (Comp) loop
10328 if Has_Tagged_Component (Etype (Comp)) then
10332 Next_Component (Comp);
10340 end Has_Tagged_Component;
10342 -----------------------------
10343 -- Has_Undefined_Reference --
10344 -----------------------------
10346 function Has_Undefined_Reference (Expr : Node_Id) return Boolean is
10347 Has_Undef_Ref : Boolean := False;
10348 -- Flag set when expression Expr contains at least one undefined
10351 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result;
10352 -- Determine whether N denotes a reference and if it does, whether it is
10355 ----------------------------
10356 -- Is_Undefined_Reference --
10357 ----------------------------
10359 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result is
10361 if Is_Entity_Name (N)
10362 and then Present (Entity (N))
10363 and then Entity (N) = Any_Id
10365 Has_Undef_Ref := True;
10370 end Is_Undefined_Reference;
10372 procedure Find_Undefined_References is
10373 new Traverse_Proc (Is_Undefined_Reference);
10375 -- Start of processing for Has_Undefined_Reference
10378 Find_Undefined_References (Expr);
10380 return Has_Undef_Ref;
10381 end Has_Undefined_Reference;
10383 ----------------------------
10384 -- Has_Volatile_Component --
10385 ----------------------------
10387 function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
10391 if Has_Volatile_Components (Typ) then
10394 elsif Is_Array_Type (Typ) then
10395 return Is_Volatile (Component_Type (Typ));
10397 elsif Is_Record_Type (Typ) then
10398 Comp := First_Component (Typ);
10399 while Present (Comp) loop
10400 if Is_Volatile_Object (Comp) then
10404 Comp := Next_Component (Comp);
10409 end Has_Volatile_Component;
10411 -------------------------
10412 -- Implementation_Kind --
10413 -------------------------
10415 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
10416 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
10419 pragma Assert (Present (Impl_Prag));
10420 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
10421 return Chars (Get_Pragma_Arg (Arg));
10422 end Implementation_Kind;
10424 --------------------------
10425 -- Implements_Interface --
10426 --------------------------
10428 function Implements_Interface
10429 (Typ_Ent : Entity_Id;
10430 Iface_Ent : Entity_Id;
10431 Exclude_Parents : Boolean := False) return Boolean
10433 Ifaces_List : Elist_Id;
10435 Iface : Entity_Id := Base_Type (Iface_Ent);
10436 Typ : Entity_Id := Base_Type (Typ_Ent);
10439 if Is_Class_Wide_Type (Typ) then
10440 Typ := Root_Type (Typ);
10443 if not Has_Interfaces (Typ) then
10447 if Is_Class_Wide_Type (Iface) then
10448 Iface := Root_Type (Iface);
10451 Collect_Interfaces (Typ, Ifaces_List);
10453 Elmt := First_Elmt (Ifaces_List);
10454 while Present (Elmt) loop
10455 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
10456 and then Exclude_Parents
10460 elsif Node (Elmt) = Iface then
10468 end Implements_Interface;
10470 ------------------------------------
10471 -- In_Assertion_Expression_Pragma --
10472 ------------------------------------
10474 function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is
10476 Prag : Node_Id := Empty;
10479 -- Climb the parent chain looking for an enclosing pragma
10482 while Present (Par) loop
10483 if Nkind (Par) = N_Pragma then
10487 -- Precondition-like pragmas are expanded into if statements, check
10488 -- the original node instead.
10490 elsif Nkind (Original_Node (Par)) = N_Pragma then
10491 Prag := Original_Node (Par);
10494 -- The expansion of attribute 'Old generates a constant to capture
10495 -- the result of the prefix. If the parent traversal reaches
10496 -- one of these constants, then the node technically came from a
10497 -- postcondition-like pragma. Note that the Ekind is not tested here
10498 -- because N may be the expression of an object declaration which is
10499 -- currently being analyzed. Such objects carry Ekind of E_Void.
10501 elsif Nkind (Par) = N_Object_Declaration
10502 and then Constant_Present (Par)
10503 and then Stores_Attribute_Old_Prefix (Defining_Entity (Par))
10507 -- Prevent the search from going too far
10509 elsif Is_Body_Or_Package_Declaration (Par) then
10513 Par := Parent (Par);
10518 and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag));
10519 end In_Assertion_Expression_Pragma;
10525 function In_Instance return Boolean is
10526 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
10530 S := Current_Scope;
10531 while Present (S) and then S /= Standard_Standard loop
10532 if Ekind_In (S, E_Function, E_Package, E_Procedure)
10533 and then Is_Generic_Instance (S)
10535 -- A child instance is always compiled in the context of a parent
10536 -- instance. Nevertheless, the actuals are not analyzed in an
10537 -- instance context. We detect this case by examining the current
10538 -- compilation unit, which must be a child instance, and checking
10539 -- that it is not currently on the scope stack.
10541 if Is_Child_Unit (Curr_Unit)
10542 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
10543 N_Package_Instantiation
10544 and then not In_Open_Scopes (Curr_Unit)
10558 ----------------------
10559 -- In_Instance_Body --
10560 ----------------------
10562 function In_Instance_Body return Boolean is
10566 S := Current_Scope;
10567 while Present (S) and then S /= Standard_Standard loop
10568 if Ekind_In (S, E_Function, E_Procedure)
10569 and then Is_Generic_Instance (S)
10573 elsif Ekind (S) = E_Package
10574 and then In_Package_Body (S)
10575 and then Is_Generic_Instance (S)
10584 end In_Instance_Body;
10586 -----------------------------
10587 -- In_Instance_Not_Visible --
10588 -----------------------------
10590 function In_Instance_Not_Visible return Boolean is
10594 S := Current_Scope;
10595 while Present (S) and then S /= Standard_Standard loop
10596 if Ekind_In (S, E_Function, E_Procedure)
10597 and then Is_Generic_Instance (S)
10601 elsif Ekind (S) = E_Package
10602 and then (In_Package_Body (S) or else In_Private_Part (S))
10603 and then Is_Generic_Instance (S)
10612 end In_Instance_Not_Visible;
10614 ------------------------------
10615 -- In_Instance_Visible_Part --
10616 ------------------------------
10618 function In_Instance_Visible_Part return Boolean is
10622 S := Current_Scope;
10623 while Present (S) and then S /= Standard_Standard loop
10624 if Ekind (S) = E_Package
10625 and then Is_Generic_Instance (S)
10626 and then not In_Package_Body (S)
10627 and then not In_Private_Part (S)
10636 end In_Instance_Visible_Part;
10638 ---------------------
10639 -- In_Package_Body --
10640 ---------------------
10642 function In_Package_Body return Boolean is
10646 S := Current_Scope;
10647 while Present (S) and then S /= Standard_Standard loop
10648 if Ekind (S) = E_Package and then In_Package_Body (S) then
10656 end In_Package_Body;
10658 --------------------------------
10659 -- In_Parameter_Specification --
10660 --------------------------------
10662 function In_Parameter_Specification (N : Node_Id) return Boolean is
10667 while Present (PN) loop
10668 if Nkind (PN) = N_Parameter_Specification then
10676 end In_Parameter_Specification;
10678 --------------------------
10679 -- In_Pragma_Expression --
10680 --------------------------
10682 function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean is
10689 elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
10695 end In_Pragma_Expression;
10697 ---------------------------
10698 -- In_Pre_Post_Condition --
10699 ---------------------------
10701 function In_Pre_Post_Condition (N : Node_Id) return Boolean is
10703 Prag : Node_Id := Empty;
10704 Prag_Id : Pragma_Id;
10707 -- Climb the parent chain looking for an enclosing pragma
10710 while Present (Par) loop
10711 if Nkind (Par) = N_Pragma then
10715 -- Prevent the search from going too far
10717 elsif Is_Body_Or_Package_Declaration (Par) then
10721 Par := Parent (Par);
10724 if Present (Prag) then
10725 Prag_Id := Get_Pragma_Id (Prag);
10728 Prag_Id = Pragma_Post
10729 or else Prag_Id = Pragma_Post_Class
10730 or else Prag_Id = Pragma_Postcondition
10731 or else Prag_Id = Pragma_Pre
10732 or else Prag_Id = Pragma_Pre_Class
10733 or else Prag_Id = Pragma_Precondition;
10735 -- Otherwise the node is not enclosed by a pre/postcondition pragma
10740 end In_Pre_Post_Condition;
10742 -------------------------------------
10743 -- In_Reverse_Storage_Order_Object --
10744 -------------------------------------
10746 function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
10748 Btyp : Entity_Id := Empty;
10751 -- Climb up indexed components
10755 case Nkind (Pref) is
10756 when N_Selected_Component =>
10757 Pref := Prefix (Pref);
10760 when N_Indexed_Component =>
10761 Pref := Prefix (Pref);
10769 if Present (Pref) then
10770 Btyp := Base_Type (Etype (Pref));
10773 return Present (Btyp)
10774 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
10775 and then Reverse_Storage_Order (Btyp);
10776 end In_Reverse_Storage_Order_Object;
10778 --------------------------------------
10779 -- In_Subprogram_Or_Concurrent_Unit --
10780 --------------------------------------
10782 function In_Subprogram_Or_Concurrent_Unit return Boolean is
10787 -- Use scope chain to check successively outer scopes
10789 E := Current_Scope;
10793 if K in Subprogram_Kind
10794 or else K in Concurrent_Kind
10795 or else K in Generic_Subprogram_Kind
10799 elsif E = Standard_Standard then
10805 end In_Subprogram_Or_Concurrent_Unit;
10807 ---------------------
10808 -- In_Visible_Part --
10809 ---------------------
10811 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
10813 return Is_Package_Or_Generic_Package (Scope_Id)
10814 and then In_Open_Scopes (Scope_Id)
10815 and then not In_Package_Body (Scope_Id)
10816 and then not In_Private_Part (Scope_Id);
10817 end In_Visible_Part;
10819 --------------------------------
10820 -- Incomplete_Or_Partial_View --
10821 --------------------------------
10823 function Incomplete_Or_Partial_View (Id : Entity_Id) return Entity_Id is
10824 function Inspect_Decls
10826 Taft : Boolean := False) return Entity_Id;
10827 -- Check whether a declarative region contains the incomplete or partial
10830 -------------------
10831 -- Inspect_Decls --
10832 -------------------
10834 function Inspect_Decls
10836 Taft : Boolean := False) return Entity_Id
10842 Decl := First (Decls);
10843 while Present (Decl) loop
10846 -- The partial view of a Taft-amendment type is an incomplete
10850 if Nkind (Decl) = N_Incomplete_Type_Declaration then
10851 Match := Defining_Identifier (Decl);
10854 -- Otherwise look for a private type whose full view matches the
10855 -- input type. Note that this checks full_type_declaration nodes
10856 -- to account for derivations from a private type where the type
10857 -- declaration hold the partial view and the full view is an
10860 elsif Nkind_In (Decl, N_Full_Type_Declaration,
10861 N_Private_Extension_Declaration,
10862 N_Private_Type_Declaration)
10864 Match := Defining_Identifier (Decl);
10867 -- Guard against unanalyzed entities
10870 and then Is_Type (Match)
10871 and then Present (Full_View (Match))
10872 and then Full_View (Match) = Id
10887 -- Start of processing for Incomplete_Or_Partial_View
10890 -- Deferred constant or incomplete type case
10892 Prev := Current_Entity_In_Scope (Id);
10895 and then (Is_Incomplete_Type (Prev) or else Ekind (Prev) = E_Constant)
10896 and then Present (Full_View (Prev))
10897 and then Full_View (Prev) = Id
10902 -- Private or Taft amendment type case
10905 Pkg : constant Entity_Id := Scope (Id);
10906 Pkg_Decl : Node_Id := Pkg;
10910 and then Ekind_In (Pkg, E_Generic_Package, E_Package)
10912 while Nkind (Pkg_Decl) /= N_Package_Specification loop
10913 Pkg_Decl := Parent (Pkg_Decl);
10916 -- It is knows that Typ has a private view, look for it in the
10917 -- visible declarations of the enclosing scope. A special case
10918 -- of this is when the two views have been exchanged - the full
10919 -- appears earlier than the private.
10921 if Has_Private_Declaration (Id) then
10922 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
10924 -- Exchanged view case, look in the private declarations
10927 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
10932 -- Otherwise if this is the package body, then Typ is a potential
10933 -- Taft amendment type. The incomplete view should be located in
10934 -- the private declarations of the enclosing scope.
10936 elsif In_Package_Body (Pkg) then
10937 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
10942 -- The type has no incomplete or private view
10945 end Incomplete_Or_Partial_View;
10947 ----------------------------------
10948 -- Indexed_Component_Bit_Offset --
10949 ----------------------------------
10951 function Indexed_Component_Bit_Offset (N : Node_Id) return Uint is
10952 Exp : constant Node_Id := First (Expressions (N));
10953 Typ : constant Entity_Id := Etype (Prefix (N));
10954 Off : constant Uint := Component_Size (Typ);
10958 -- Return early if the component size is not known or variable
10960 if Off = No_Uint or else Off < Uint_0 then
10964 -- Deal with the degenerate case of an empty component
10966 if Off = Uint_0 then
10970 -- Check that both the index value and the low bound are known
10972 if not Compile_Time_Known_Value (Exp) then
10976 Ind := First_Index (Typ);
10981 if Nkind (Ind) = N_Subtype_Indication then
10982 Ind := Constraint (Ind);
10984 if Nkind (Ind) = N_Range_Constraint then
10985 Ind := Range_Expression (Ind);
10989 if Nkind (Ind) /= N_Range
10990 or else not Compile_Time_Known_Value (Low_Bound (Ind))
10995 -- Return the scaled offset
10997 return Off * (Expr_Value (Exp) - Expr_Value (Low_Bound ((Ind))));
10998 end Indexed_Component_Bit_Offset;
11000 ----------------------------
11001 -- Inherit_Rep_Item_Chain --
11002 ----------------------------
11004 procedure Inherit_Rep_Item_Chain (Typ : Entity_Id; From_Typ : Entity_Id) is
11006 Next_Item : Node_Id;
11009 -- There are several inheritance scenarios to consider depending on
11010 -- whether both types have rep item chains and whether the destination
11011 -- type already inherits part of the source type's rep item chain.
11013 -- 1) The source type lacks a rep item chain
11014 -- From_Typ ---> Empty
11016 -- Typ --------> Item (or Empty)
11018 -- In this case inheritance cannot take place because there are no items
11021 -- 2) The destination type lacks a rep item chain
11022 -- From_Typ ---> Item ---> ...
11024 -- Typ --------> Empty
11026 -- Inheritance takes place by setting the First_Rep_Item of the
11027 -- destination type to the First_Rep_Item of the source type.
11028 -- From_Typ ---> Item ---> ...
11030 -- Typ -----------+
11032 -- 3.1) Both source and destination types have at least one rep item.
11033 -- The destination type does NOT inherit a rep item from the source
11035 -- From_Typ ---> Item ---> Item
11037 -- Typ --------> Item ---> Item
11039 -- Inheritance takes place by setting the Next_Rep_Item of the last item
11040 -- of the destination type to the First_Rep_Item of the source type.
11041 -- From_Typ -------------------> Item ---> Item
11043 -- Typ --------> Item ---> Item --+
11045 -- 3.2) Both source and destination types have at least one rep item.
11046 -- The destination type DOES inherit part of the rep item chain of the
11048 -- From_Typ ---> Item ---> Item ---> Item
11050 -- Typ --------> Item ------+
11052 -- This rare case arises when the full view of a private extension must
11053 -- inherit the rep item chain from the full view of its parent type and
11054 -- the full view of the parent type contains extra rep items. Currently
11055 -- only invariants may lead to such form of inheritance.
11057 -- type From_Typ is tagged private
11058 -- with Type_Invariant'Class => Item_2;
11060 -- type Typ is new From_Typ with private
11061 -- with Type_Invariant => Item_4;
11063 -- At this point the rep item chains contain the following items
11065 -- From_Typ -----------> Item_2 ---> Item_3
11067 -- Typ --------> Item_4 --+
11069 -- The full views of both types may introduce extra invariants
11071 -- type From_Typ is tagged null record
11072 -- with Type_Invariant => Item_1;
11074 -- type Typ is new From_Typ with null record;
11076 -- The full view of Typ would have to inherit any new rep items added to
11077 -- the full view of From_Typ.
11079 -- From_Typ -----------> Item_1 ---> Item_2 ---> Item_3
11081 -- Typ --------> Item_4 --+
11083 -- To achieve this form of inheritance, the destination type must first
11084 -- sever the link between its own rep chain and that of the source type,
11085 -- then inheritance 3.1 takes place.
11087 -- Case 1: The source type lacks a rep item chain
11089 if No (First_Rep_Item (From_Typ)) then
11092 -- Case 2: The destination type lacks a rep item chain
11094 elsif No (First_Rep_Item (Typ)) then
11095 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
11097 -- Case 3: Both the source and destination types have at least one rep
11098 -- item. Traverse the rep item chain of the destination type to find the
11103 Next_Item := First_Rep_Item (Typ);
11104 while Present (Next_Item) loop
11106 -- Detect a link between the destination type's rep chain and that
11107 -- of the source type. There are two possibilities:
11112 -- From_Typ ---> Item_1 --->
11114 -- Typ -----------+
11121 -- From_Typ ---> Item_1 ---> Item_2 --->
11123 -- Typ --------> Item_3 ------+
11127 if Has_Rep_Item (From_Typ, Next_Item) then
11132 Next_Item := Next_Rep_Item (Next_Item);
11135 -- Inherit the source type's rep item chain
11137 if Present (Item) then
11138 Set_Next_Rep_Item (Item, First_Rep_Item (From_Typ));
11140 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
11143 end Inherit_Rep_Item_Chain;
11145 ---------------------------------
11146 -- Insert_Explicit_Dereference --
11147 ---------------------------------
11149 procedure Insert_Explicit_Dereference (N : Node_Id) is
11150 New_Prefix : constant Node_Id := Relocate_Node (N);
11151 Ent : Entity_Id := Empty;
11158 Save_Interps (N, New_Prefix);
11161 Make_Explicit_Dereference (Sloc (Parent (N)),
11162 Prefix => New_Prefix));
11164 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
11166 if Is_Overloaded (New_Prefix) then
11168 -- The dereference is also overloaded, and its interpretations are
11169 -- the designated types of the interpretations of the original node.
11171 Set_Etype (N, Any_Type);
11173 Get_First_Interp (New_Prefix, I, It);
11174 while Present (It.Nam) loop
11177 if Is_Access_Type (T) then
11178 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
11181 Get_Next_Interp (I, It);
11187 -- Prefix is unambiguous: mark the original prefix (which might
11188 -- Come_From_Source) as a reference, since the new (relocated) one
11189 -- won't be taken into account.
11191 if Is_Entity_Name (New_Prefix) then
11192 Ent := Entity (New_Prefix);
11193 Pref := New_Prefix;
11195 -- For a retrieval of a subcomponent of some composite object,
11196 -- retrieve the ultimate entity if there is one.
11198 elsif Nkind_In (New_Prefix, N_Selected_Component,
11199 N_Indexed_Component)
11201 Pref := Prefix (New_Prefix);
11202 while Present (Pref)
11203 and then Nkind_In (Pref, N_Selected_Component,
11204 N_Indexed_Component)
11206 Pref := Prefix (Pref);
11209 if Present (Pref) and then Is_Entity_Name (Pref) then
11210 Ent := Entity (Pref);
11214 -- Place the reference on the entity node
11216 if Present (Ent) then
11217 Generate_Reference (Ent, Pref);
11220 end Insert_Explicit_Dereference;
11222 ------------------------------------------
11223 -- Inspect_Deferred_Constant_Completion --
11224 ------------------------------------------
11226 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
11230 Decl := First (Decls);
11231 while Present (Decl) loop
11233 -- Deferred constant signature
11235 if Nkind (Decl) = N_Object_Declaration
11236 and then Constant_Present (Decl)
11237 and then No (Expression (Decl))
11239 -- No need to check internally generated constants
11241 and then Comes_From_Source (Decl)
11243 -- The constant is not completed. A full object declaration or a
11244 -- pragma Import complete a deferred constant.
11246 and then not Has_Completion (Defining_Identifier (Decl))
11249 ("constant declaration requires initialization expression",
11250 Defining_Identifier (Decl));
11253 Decl := Next (Decl);
11255 end Inspect_Deferred_Constant_Completion;
11257 -----------------------------
11258 -- Install_Generic_Formals --
11259 -----------------------------
11261 procedure Install_Generic_Formals (Subp_Id : Entity_Id) is
11265 pragma Assert (Is_Generic_Subprogram (Subp_Id));
11267 E := First_Entity (Subp_Id);
11268 while Present (E) loop
11269 Install_Entity (E);
11272 end Install_Generic_Formals;
11274 -----------------------------
11275 -- Is_Actual_Out_Parameter --
11276 -----------------------------
11278 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
11279 Formal : Entity_Id;
11282 Find_Actual (N, Formal, Call);
11283 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
11284 end Is_Actual_Out_Parameter;
11286 -------------------------
11287 -- Is_Actual_Parameter --
11288 -------------------------
11290 function Is_Actual_Parameter (N : Node_Id) return Boolean is
11291 PK : constant Node_Kind := Nkind (Parent (N));
11295 when N_Parameter_Association =>
11296 return N = Explicit_Actual_Parameter (Parent (N));
11298 when N_Subprogram_Call =>
11299 return Is_List_Member (N)
11301 List_Containing (N) = Parameter_Associations (Parent (N));
11306 end Is_Actual_Parameter;
11308 --------------------------------
11309 -- Is_Actual_Tagged_Parameter --
11310 --------------------------------
11312 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
11313 Formal : Entity_Id;
11316 Find_Actual (N, Formal, Call);
11317 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
11318 end Is_Actual_Tagged_Parameter;
11320 ---------------------
11321 -- Is_Aliased_View --
11322 ---------------------
11324 function Is_Aliased_View (Obj : Node_Id) return Boolean is
11328 if Is_Entity_Name (Obj) then
11335 or else (Present (Renamed_Object (E))
11336 and then Is_Aliased_View (Renamed_Object (E)))))
11338 or else ((Is_Formal (E)
11339 or else Ekind_In (E, E_Generic_In_Out_Parameter,
11340 E_Generic_In_Parameter))
11341 and then Is_Tagged_Type (Etype (E)))
11343 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
11345 -- Current instance of type, either directly or as rewritten
11346 -- reference to the current object.
11348 or else (Is_Entity_Name (Original_Node (Obj))
11349 and then Present (Entity (Original_Node (Obj)))
11350 and then Is_Type (Entity (Original_Node (Obj))))
11352 or else (Is_Type (E) and then E = Current_Scope)
11354 or else (Is_Incomplete_Or_Private_Type (E)
11355 and then Full_View (E) = Current_Scope)
11357 -- Ada 2012 AI05-0053: the return object of an extended return
11358 -- statement is aliased if its type is immutably limited.
11360 or else (Is_Return_Object (E)
11361 and then Is_Limited_View (Etype (E)));
11363 elsif Nkind (Obj) = N_Selected_Component then
11364 return Is_Aliased (Entity (Selector_Name (Obj)));
11366 elsif Nkind (Obj) = N_Indexed_Component then
11367 return Has_Aliased_Components (Etype (Prefix (Obj)))
11369 (Is_Access_Type (Etype (Prefix (Obj)))
11370 and then Has_Aliased_Components
11371 (Designated_Type (Etype (Prefix (Obj)))));
11373 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
11374 return Is_Tagged_Type (Etype (Obj))
11375 and then Is_Aliased_View (Expression (Obj));
11377 elsif Nkind (Obj) = N_Explicit_Dereference then
11378 return Nkind (Original_Node (Obj)) /= N_Function_Call;
11383 end Is_Aliased_View;
11385 -------------------------
11386 -- Is_Ancestor_Package --
11387 -------------------------
11389 function Is_Ancestor_Package
11391 E2 : Entity_Id) return Boolean
11397 while Present (Par) and then Par /= Standard_Standard loop
11402 Par := Scope (Par);
11406 end Is_Ancestor_Package;
11408 ----------------------
11409 -- Is_Atomic_Object --
11410 ----------------------
11412 function Is_Atomic_Object (N : Node_Id) return Boolean is
11414 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
11415 -- Determines if given object has atomic components
11417 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
11418 -- If prefix is an implicit dereference, examine designated type
11420 ----------------------
11421 -- Is_Atomic_Prefix --
11422 ----------------------
11424 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
11426 if Is_Access_Type (Etype (N)) then
11428 Has_Atomic_Components (Designated_Type (Etype (N)));
11430 return Object_Has_Atomic_Components (N);
11432 end Is_Atomic_Prefix;
11434 ----------------------------------
11435 -- Object_Has_Atomic_Components --
11436 ----------------------------------
11438 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
11440 if Has_Atomic_Components (Etype (N))
11441 or else Is_Atomic (Etype (N))
11445 elsif Is_Entity_Name (N)
11446 and then (Has_Atomic_Components (Entity (N))
11447 or else Is_Atomic (Entity (N)))
11451 elsif Nkind (N) = N_Selected_Component
11452 and then Is_Atomic (Entity (Selector_Name (N)))
11456 elsif Nkind (N) = N_Indexed_Component
11457 or else Nkind (N) = N_Selected_Component
11459 return Is_Atomic_Prefix (Prefix (N));
11464 end Object_Has_Atomic_Components;
11466 -- Start of processing for Is_Atomic_Object
11469 -- Predicate is not relevant to subprograms
11471 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
11474 elsif Is_Atomic (Etype (N))
11475 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
11479 elsif Nkind (N) = N_Selected_Component
11480 and then Is_Atomic (Entity (Selector_Name (N)))
11484 elsif Nkind (N) = N_Indexed_Component
11485 or else Nkind (N) = N_Selected_Component
11487 return Is_Atomic_Prefix (Prefix (N));
11492 end Is_Atomic_Object;
11494 -----------------------------
11495 -- Is_Atomic_Or_VFA_Object --
11496 -----------------------------
11498 function Is_Atomic_Or_VFA_Object (N : Node_Id) return Boolean is
11500 return Is_Atomic_Object (N)
11501 or else (Is_Object_Reference (N)
11502 and then Is_Entity_Name (N)
11503 and then (Is_Volatile_Full_Access (Entity (N))
11505 Is_Volatile_Full_Access (Etype (Entity (N)))));
11506 end Is_Atomic_Or_VFA_Object;
11508 -------------------------
11509 -- Is_Attribute_Result --
11510 -------------------------
11512 function Is_Attribute_Result (N : Node_Id) return Boolean is
11514 return Nkind (N) = N_Attribute_Reference
11515 and then Attribute_Name (N) = Name_Result;
11516 end Is_Attribute_Result;
11518 -------------------------
11519 -- Is_Attribute_Update --
11520 -------------------------
11522 function Is_Attribute_Update (N : Node_Id) return Boolean is
11524 return Nkind (N) = N_Attribute_Reference
11525 and then Attribute_Name (N) = Name_Update;
11526 end Is_Attribute_Update;
11528 ------------------------------------
11529 -- Is_Body_Or_Package_Declaration --
11530 ------------------------------------
11532 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
11534 return Nkind_In (N, N_Entry_Body,
11536 N_Package_Declaration,
11540 end Is_Body_Or_Package_Declaration;
11542 -----------------------
11543 -- Is_Bounded_String --
11544 -----------------------
11546 function Is_Bounded_String (T : Entity_Id) return Boolean is
11547 Under : constant Entity_Id := Underlying_Type (Root_Type (T));
11550 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
11551 -- Super_String, or one of the [Wide_]Wide_ versions. This will
11552 -- be True for all the Bounded_String types in instances of the
11553 -- Generic_Bounded_Length generics, and for types derived from those.
11555 return Present (Under)
11556 and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
11557 Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
11558 Is_RTE (Root_Type (Under), RO_WW_Super_String));
11559 end Is_Bounded_String;
11561 -------------------------
11562 -- Is_Child_Or_Sibling --
11563 -------------------------
11565 function Is_Child_Or_Sibling
11566 (Pack_1 : Entity_Id;
11567 Pack_2 : Entity_Id) return Boolean
11569 function Distance_From_Standard (Pack : Entity_Id) return Nat;
11570 -- Given an arbitrary package, return the number of "climbs" necessary
11571 -- to reach scope Standard_Standard.
11573 procedure Equalize_Depths
11574 (Pack : in out Entity_Id;
11575 Depth : in out Nat;
11576 Depth_To_Reach : Nat);
11577 -- Given an arbitrary package, its depth and a target depth to reach,
11578 -- climb the scope chain until the said depth is reached. The pointer
11579 -- to the package and its depth a modified during the climb.
11581 ----------------------------
11582 -- Distance_From_Standard --
11583 ----------------------------
11585 function Distance_From_Standard (Pack : Entity_Id) return Nat is
11592 while Present (Scop) and then Scop /= Standard_Standard loop
11594 Scop := Scope (Scop);
11598 end Distance_From_Standard;
11600 ---------------------
11601 -- Equalize_Depths --
11602 ---------------------
11604 procedure Equalize_Depths
11605 (Pack : in out Entity_Id;
11606 Depth : in out Nat;
11607 Depth_To_Reach : Nat)
11610 -- The package must be at a greater or equal depth
11612 if Depth < Depth_To_Reach then
11613 raise Program_Error;
11616 -- Climb the scope chain until the desired depth is reached
11618 while Present (Pack) and then Depth /= Depth_To_Reach loop
11619 Pack := Scope (Pack);
11620 Depth := Depth - 1;
11622 end Equalize_Depths;
11626 P_1 : Entity_Id := Pack_1;
11627 P_1_Child : Boolean := False;
11628 P_1_Depth : Nat := Distance_From_Standard (P_1);
11629 P_2 : Entity_Id := Pack_2;
11630 P_2_Child : Boolean := False;
11631 P_2_Depth : Nat := Distance_From_Standard (P_2);
11633 -- Start of processing for Is_Child_Or_Sibling
11637 (Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
11639 -- Both packages denote the same entity, therefore they cannot be
11640 -- children or siblings.
11645 -- One of the packages is at a deeper level than the other. Note that
11646 -- both may still come from differen hierarchies.
11654 elsif P_1_Depth > P_2_Depth then
11657 Depth => P_1_Depth,
11658 Depth_To_Reach => P_2_Depth);
11667 elsif P_2_Depth > P_1_Depth then
11670 Depth => P_2_Depth,
11671 Depth_To_Reach => P_1_Depth);
11675 -- At this stage the package pointers have been elevated to the same
11676 -- depth. If the related entities are the same, then one package is a
11677 -- potential child of the other:
11681 -- X became P_1 P_2 or vica versa
11687 return Is_Child_Unit (Pack_1);
11689 else pragma Assert (P_2_Child);
11690 return Is_Child_Unit (Pack_2);
11693 -- The packages may come from the same package chain or from entirely
11694 -- different hierarcies. To determine this, climb the scope stack until
11695 -- a common root is found.
11697 -- (root) (root 1) (root 2)
11702 while Present (P_1) and then Present (P_2) loop
11704 -- The two packages may be siblings
11707 return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2);
11710 P_1 := Scope (P_1);
11711 P_2 := Scope (P_2);
11716 end Is_Child_Or_Sibling;
11718 -----------------------------
11719 -- Is_Concurrent_Interface --
11720 -----------------------------
11722 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
11724 return Is_Interface (T)
11726 (Is_Protected_Interface (T)
11727 or else Is_Synchronized_Interface (T)
11728 or else Is_Task_Interface (T));
11729 end Is_Concurrent_Interface;
11731 -----------------------
11732 -- Is_Constant_Bound --
11733 -----------------------
11735 function Is_Constant_Bound (Exp : Node_Id) return Boolean is
11737 if Compile_Time_Known_Value (Exp) then
11740 elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
11741 return Is_Constant_Object (Entity (Exp))
11742 or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
11744 elsif Nkind (Exp) in N_Binary_Op then
11745 return Is_Constant_Bound (Left_Opnd (Exp))
11746 and then Is_Constant_Bound (Right_Opnd (Exp))
11747 and then Scope (Entity (Exp)) = Standard_Standard;
11752 end Is_Constant_Bound;
11754 ---------------------------
11755 -- Is_Container_Element --
11756 ---------------------------
11758 function Is_Container_Element (Exp : Node_Id) return Boolean is
11759 Loc : constant Source_Ptr := Sloc (Exp);
11760 Pref : constant Node_Id := Prefix (Exp);
11763 -- Call to an indexing aspect
11765 Cont_Typ : Entity_Id;
11766 -- The type of the container being accessed
11768 Elem_Typ : Entity_Id;
11769 -- Its element type
11771 Indexing : Entity_Id;
11772 Is_Const : Boolean;
11773 -- Indicates that constant indexing is used, and the element is thus
11776 Ref_Typ : Entity_Id;
11777 -- The reference type returned by the indexing operation
11780 -- If C is a container, in a context that imposes the element type of
11781 -- that container, the indexing notation C (X) is rewritten as:
11783 -- Indexing (C, X).Discr.all
11785 -- where Indexing is one of the indexing aspects of the container.
11786 -- If the context does not require a reference, the construct can be
11791 -- First, verify that the construct has the proper form
11793 if not Expander_Active then
11796 elsif Nkind (Pref) /= N_Selected_Component then
11799 elsif Nkind (Prefix (Pref)) /= N_Function_Call then
11803 Call := Prefix (Pref);
11804 Ref_Typ := Etype (Call);
11807 if not Has_Implicit_Dereference (Ref_Typ)
11808 or else No (First (Parameter_Associations (Call)))
11809 or else not Is_Entity_Name (Name (Call))
11814 -- Retrieve type of container object, and its iterator aspects
11816 Cont_Typ := Etype (First (Parameter_Associations (Call)));
11817 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Constant_Indexing);
11820 if No (Indexing) then
11822 -- Container should have at least one indexing operation
11826 elsif Entity (Name (Call)) /= Entity (Indexing) then
11828 -- This may be a variable indexing operation
11830 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Variable_Indexing);
11833 or else Entity (Name (Call)) /= Entity (Indexing)
11842 Elem_Typ := Find_Value_Of_Aspect (Cont_Typ, Aspect_Iterator_Element);
11844 if No (Elem_Typ) or else Entity (Elem_Typ) /= Etype (Exp) then
11848 -- Check that the expression is not the target of an assignment, in
11849 -- which case the rewriting is not possible.
11851 if not Is_Const then
11857 while Present (Par)
11859 if Nkind (Parent (Par)) = N_Assignment_Statement
11860 and then Par = Name (Parent (Par))
11864 -- A renaming produces a reference, and the transformation
11867 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
11871 (Nkind (Parent (Par)), N_Function_Call,
11872 N_Procedure_Call_Statement,
11873 N_Entry_Call_Statement)
11875 -- Check that the element is not part of an actual for an
11876 -- in-out parameter.
11883 F := First_Formal (Entity (Name (Parent (Par))));
11884 A := First (Parameter_Associations (Parent (Par)));
11885 while Present (F) loop
11886 if A = Par and then Ekind (F) /= E_In_Parameter then
11895 -- E_In_Parameter in a call: element is not modified.
11900 Par := Parent (Par);
11905 -- The expression has the proper form and the context requires the
11906 -- element type. Retrieve the Element function of the container and
11907 -- rewrite the construct as a call to it.
11913 Op := First_Elmt (Primitive_Operations (Cont_Typ));
11914 while Present (Op) loop
11915 exit when Chars (Node (Op)) = Name_Element;
11924 Make_Function_Call (Loc,
11925 Name => New_Occurrence_Of (Node (Op), Loc),
11926 Parameter_Associations => Parameter_Associations (Call)));
11927 Analyze_And_Resolve (Exp, Entity (Elem_Typ));
11931 end Is_Container_Element;
11933 ----------------------------
11934 -- Is_Contract_Annotation --
11935 ----------------------------
11937 function Is_Contract_Annotation (Item : Node_Id) return Boolean is
11939 return Is_Package_Contract_Annotation (Item)
11941 Is_Subprogram_Contract_Annotation (Item);
11942 end Is_Contract_Annotation;
11944 --------------------------------------
11945 -- Is_Controlling_Limited_Procedure --
11946 --------------------------------------
11948 function Is_Controlling_Limited_Procedure
11949 (Proc_Nam : Entity_Id) return Boolean
11951 Param_Typ : Entity_Id := Empty;
11954 if Ekind (Proc_Nam) = E_Procedure
11955 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
11957 Param_Typ := Etype (Parameter_Type (First (
11958 Parameter_Specifications (Parent (Proc_Nam)))));
11960 -- In this case where an Itype was created, the procedure call has been
11963 elsif Present (Associated_Node_For_Itype (Proc_Nam))
11964 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
11966 Present (Parameter_Associations
11967 (Associated_Node_For_Itype (Proc_Nam)))
11970 Etype (First (Parameter_Associations
11971 (Associated_Node_For_Itype (Proc_Nam))));
11974 if Present (Param_Typ) then
11976 Is_Interface (Param_Typ)
11977 and then Is_Limited_Record (Param_Typ);
11981 end Is_Controlling_Limited_Procedure;
11983 -----------------------------
11984 -- Is_CPP_Constructor_Call --
11985 -----------------------------
11987 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
11989 return Nkind (N) = N_Function_Call
11990 and then Is_CPP_Class (Etype (Etype (N)))
11991 and then Is_Constructor (Entity (Name (N)))
11992 and then Is_Imported (Entity (Name (N)));
11993 end Is_CPP_Constructor_Call;
11995 -------------------------
11996 -- Is_Current_Instance --
11997 -------------------------
11999 function Is_Current_Instance (N : Node_Id) return Boolean is
12000 Typ : constant Entity_Id := Entity (N);
12004 -- Simplest case: entity is a concurrent type and we are currently
12005 -- inside the body. This will eventually be expanded into a
12006 -- call to Self (for tasks) or _object (for protected objects).
12008 if Is_Concurrent_Type (Typ) and then In_Open_Scopes (Typ) then
12012 -- Check whether the context is a (sub)type declaration for the
12016 while Present (P) loop
12017 if Nkind_In (P, N_Full_Type_Declaration,
12018 N_Private_Type_Declaration,
12019 N_Subtype_Declaration)
12020 and then Comes_From_Source (P)
12021 and then Defining_Entity (P) = Typ
12025 -- A subtype name may appear in an aspect specification for a
12026 -- Predicate_Failure aspect, for which we do not construct a
12027 -- wrapper procedure. The subtype will be replaced by the
12028 -- expression being tested when the corresponding predicate
12029 -- check is expanded.
12031 elsif Nkind (P) = N_Aspect_Specification
12032 and then Nkind (Parent (P)) = N_Subtype_Declaration
12036 elsif Nkind (P) = N_Pragma
12038 Get_Pragma_Id (P) = Pragma_Predicate_Failure
12047 -- In any other context this is not a current occurrence
12050 end Is_Current_Instance;
12052 --------------------
12053 -- Is_Declaration --
12054 --------------------
12056 function Is_Declaration (N : Node_Id) return Boolean is
12059 when N_Abstract_Subprogram_Declaration |
12060 N_Exception_Declaration |
12061 N_Exception_Renaming_Declaration |
12062 N_Full_Type_Declaration |
12063 N_Generic_Function_Renaming_Declaration |
12064 N_Generic_Package_Declaration |
12065 N_Generic_Package_Renaming_Declaration |
12066 N_Generic_Procedure_Renaming_Declaration |
12067 N_Generic_Subprogram_Declaration |
12068 N_Number_Declaration |
12069 N_Object_Declaration |
12070 N_Object_Renaming_Declaration |
12071 N_Package_Declaration |
12072 N_Package_Renaming_Declaration |
12073 N_Private_Extension_Declaration |
12074 N_Private_Type_Declaration |
12075 N_Subprogram_Declaration |
12076 N_Subprogram_Renaming_Declaration |
12077 N_Subtype_Declaration =>
12083 end Is_Declaration;
12085 --------------------------------
12086 -- Is_Declared_Within_Variant --
12087 --------------------------------
12089 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
12090 Comp_Decl : constant Node_Id := Parent (Comp);
12091 Comp_List : constant Node_Id := Parent (Comp_Decl);
12093 return Nkind (Parent (Comp_List)) = N_Variant;
12094 end Is_Declared_Within_Variant;
12096 ----------------------------------------------
12097 -- Is_Dependent_Component_Of_Mutable_Object --
12098 ----------------------------------------------
12100 function Is_Dependent_Component_Of_Mutable_Object
12101 (Object : Node_Id) return Boolean
12104 Prefix_Type : Entity_Id;
12105 P_Aliased : Boolean := False;
12108 Deref : Node_Id := Object;
12109 -- Dereference node, in something like X.all.Y(2)
12111 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
12114 -- Find the dereference node if any
12116 while Nkind_In (Deref, N_Indexed_Component,
12117 N_Selected_Component,
12120 Deref := Prefix (Deref);
12123 -- Ada 2005: If we have a component or slice of a dereference,
12124 -- something like X.all.Y (2), and the type of X is access-to-constant,
12125 -- Is_Variable will return False, because it is indeed a constant
12126 -- view. But it might be a view of a variable object, so we want the
12127 -- following condition to be True in that case.
12129 if Is_Variable (Object)
12130 or else (Ada_Version >= Ada_2005
12131 and then Nkind (Deref) = N_Explicit_Dereference)
12133 if Nkind (Object) = N_Selected_Component then
12134 P := Prefix (Object);
12135 Prefix_Type := Etype (P);
12137 if Is_Entity_Name (P) then
12138 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
12139 Prefix_Type := Base_Type (Prefix_Type);
12142 if Is_Aliased (Entity (P)) then
12146 -- A discriminant check on a selected component may be expanded
12147 -- into a dereference when removing side-effects. Recover the
12148 -- original node and its type, which may be unconstrained.
12150 elsif Nkind (P) = N_Explicit_Dereference
12151 and then not (Comes_From_Source (P))
12153 P := Original_Node (P);
12154 Prefix_Type := Etype (P);
12157 -- Check for prefix being an aliased component???
12163 -- A heap object is constrained by its initial value
12165 -- Ada 2005 (AI-363): Always assume the object could be mutable in
12166 -- the dereferenced case, since the access value might denote an
12167 -- unconstrained aliased object, whereas in Ada 95 the designated
12168 -- object is guaranteed to be constrained. A worst-case assumption
12169 -- has to apply in Ada 2005 because we can't tell at compile
12170 -- time whether the object is "constrained by its initial value"
12171 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
12172 -- rules (these rules are acknowledged to need fixing).
12174 if Ada_Version < Ada_2005 then
12175 if Is_Access_Type (Prefix_Type)
12176 or else Nkind (P) = N_Explicit_Dereference
12181 else pragma Assert (Ada_Version >= Ada_2005);
12182 if Is_Access_Type (Prefix_Type) then
12184 -- If the access type is pool-specific, and there is no
12185 -- constrained partial view of the designated type, then the
12186 -- designated object is known to be constrained.
12188 if Ekind (Prefix_Type) = E_Access_Type
12189 and then not Object_Type_Has_Constrained_Partial_View
12190 (Typ => Designated_Type (Prefix_Type),
12191 Scop => Current_Scope)
12195 -- Otherwise (general access type, or there is a constrained
12196 -- partial view of the designated type), we need to check
12197 -- based on the designated type.
12200 Prefix_Type := Designated_Type (Prefix_Type);
12206 Original_Record_Component (Entity (Selector_Name (Object)));
12208 -- As per AI-0017, the renaming is illegal in a generic body, even
12209 -- if the subtype is indefinite.
12211 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
12213 if not Is_Constrained (Prefix_Type)
12214 and then (Is_Definite_Subtype (Prefix_Type)
12216 (Is_Generic_Type (Prefix_Type)
12217 and then Ekind (Current_Scope) = E_Generic_Package
12218 and then In_Package_Body (Current_Scope)))
12220 and then (Is_Declared_Within_Variant (Comp)
12221 or else Has_Discriminant_Dependent_Constraint (Comp))
12222 and then (not P_Aliased or else Ada_Version >= Ada_2005)
12226 -- If the prefix is of an access type at this point, then we want
12227 -- to return False, rather than calling this function recursively
12228 -- on the access object (which itself might be a discriminant-
12229 -- dependent component of some other object, but that isn't
12230 -- relevant to checking the object passed to us). This avoids
12231 -- issuing wrong errors when compiling with -gnatc, where there
12232 -- can be implicit dereferences that have not been expanded.
12234 elsif Is_Access_Type (Etype (Prefix (Object))) then
12239 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
12242 elsif Nkind (Object) = N_Indexed_Component
12243 or else Nkind (Object) = N_Slice
12245 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
12247 -- A type conversion that Is_Variable is a view conversion:
12248 -- go back to the denoted object.
12250 elsif Nkind (Object) = N_Type_Conversion then
12252 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
12257 end Is_Dependent_Component_Of_Mutable_Object;
12259 ---------------------
12260 -- Is_Dereferenced --
12261 ---------------------
12263 function Is_Dereferenced (N : Node_Id) return Boolean is
12264 P : constant Node_Id := Parent (N);
12266 return Nkind_In (P, N_Selected_Component,
12267 N_Explicit_Dereference,
12268 N_Indexed_Component,
12270 and then Prefix (P) = N;
12271 end Is_Dereferenced;
12273 ----------------------
12274 -- Is_Descendant_Of --
12275 ----------------------
12277 function Is_Descendant_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
12282 pragma Assert (Nkind (T1) in N_Entity);
12283 pragma Assert (Nkind (T2) in N_Entity);
12285 T := Base_Type (T1);
12287 -- Immediate return if the types match
12292 -- Comment needed here ???
12294 elsif Ekind (T) = E_Class_Wide_Type then
12295 return Etype (T) = T2;
12303 -- Done if we found the type we are looking for
12308 -- Done if no more derivations to check
12315 -- Following test catches error cases resulting from prev errors
12317 elsif No (Etyp) then
12320 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
12323 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
12327 T := Base_Type (Etyp);
12330 end Is_Descendant_Of;
12332 ----------------------------------------
12333 -- Is_Descendant_Of_Suspension_Object --
12334 ----------------------------------------
12336 function Is_Descendant_Of_Suspension_Object
12337 (Typ : Entity_Id) return Boolean
12339 Cur_Typ : Entity_Id;
12340 Par_Typ : Entity_Id;
12343 -- Climb the type derivation chain checking each parent type against
12344 -- Suspension_Object.
12346 Cur_Typ := Base_Type (Typ);
12347 while Present (Cur_Typ) loop
12348 Par_Typ := Etype (Cur_Typ);
12350 -- The current type is a match
12352 if Is_Suspension_Object (Cur_Typ) then
12355 -- Stop the traversal once the root of the derivation chain has been
12356 -- reached. In that case the current type is its own base type.
12358 elsif Cur_Typ = Par_Typ then
12362 Cur_Typ := Base_Type (Par_Typ);
12366 end Is_Descendant_Of_Suspension_Object;
12368 ---------------------------------------------
12369 -- Is_Double_Precision_Floating_Point_Type --
12370 ---------------------------------------------
12372 function Is_Double_Precision_Floating_Point_Type
12373 (E : Entity_Id) return Boolean is
12375 return Is_Floating_Point_Type (E)
12376 and then Machine_Radix_Value (E) = Uint_2
12377 and then Machine_Mantissa_Value (E) = UI_From_Int (53)
12378 and then Machine_Emax_Value (E) = Uint_2 ** Uint_10
12379 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_10);
12380 end Is_Double_Precision_Floating_Point_Type;
12382 -----------------------------
12383 -- Is_Effectively_Volatile --
12384 -----------------------------
12386 function Is_Effectively_Volatile (Id : Entity_Id) return Boolean is
12388 if Is_Type (Id) then
12390 -- An arbitrary type is effectively volatile when it is subject to
12391 -- pragma Atomic or Volatile.
12393 if Is_Volatile (Id) then
12396 -- An array type is effectively volatile when it is subject to pragma
12397 -- Atomic_Components or Volatile_Components or its component type is
12398 -- effectively volatile.
12400 elsif Is_Array_Type (Id) then
12402 Has_Volatile_Components (Id)
12404 Is_Effectively_Volatile (Component_Type (Base_Type (Id)));
12406 -- A protected type is always volatile
12408 elsif Is_Protected_Type (Id) then
12411 -- A descendant of Ada.Synchronous_Task_Control.Suspension_Object is
12412 -- automatically volatile.
12414 elsif Is_Descendant_Of_Suspension_Object (Id) then
12417 -- Otherwise the type is not effectively volatile
12423 -- Otherwise Id denotes an object
12428 or else Has_Volatile_Components (Id)
12429 or else Is_Effectively_Volatile (Etype (Id));
12431 end Is_Effectively_Volatile;
12433 ------------------------------------
12434 -- Is_Effectively_Volatile_Object --
12435 ------------------------------------
12437 function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean is
12439 if Is_Entity_Name (N) then
12440 return Is_Effectively_Volatile (Entity (N));
12442 elsif Nkind (N) = N_Indexed_Component then
12443 return Is_Effectively_Volatile_Object (Prefix (N));
12445 elsif Nkind (N) = N_Selected_Component then
12447 Is_Effectively_Volatile_Object (Prefix (N))
12449 Is_Effectively_Volatile_Object (Selector_Name (N));
12454 end Is_Effectively_Volatile_Object;
12456 -------------------
12457 -- Is_Entry_Body --
12458 -------------------
12460 function Is_Entry_Body (Id : Entity_Id) return Boolean is
12463 Ekind_In (Id, E_Entry, E_Entry_Family)
12464 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Body;
12467 --------------------------
12468 -- Is_Entry_Declaration --
12469 --------------------------
12471 function Is_Entry_Declaration (Id : Entity_Id) return Boolean is
12474 Ekind_In (Id, E_Entry, E_Entry_Family)
12475 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Declaration;
12476 end Is_Entry_Declaration;
12478 ------------------------------------
12479 -- Is_Expanded_Priority_Attribute --
12480 ------------------------------------
12482 function Is_Expanded_Priority_Attribute (E : Entity_Id) return Boolean is
12485 Nkind (E) = N_Function_Call
12486 and then not Configurable_Run_Time_Mode
12487 and then (Entity (Name (E)) = RTE (RE_Get_Ceiling)
12488 or else Entity (Name (E)) = RTE (RO_PE_Get_Ceiling));
12489 end Is_Expanded_Priority_Attribute;
12491 ----------------------------
12492 -- Is_Expression_Function --
12493 ----------------------------
12495 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
12497 if Ekind_In (Subp, E_Function, E_Subprogram_Body) then
12499 Nkind (Original_Node (Unit_Declaration_Node (Subp))) =
12500 N_Expression_Function;
12504 end Is_Expression_Function;
12506 ------------------------------------------
12507 -- Is_Expression_Function_Or_Completion --
12508 ------------------------------------------
12510 function Is_Expression_Function_Or_Completion
12511 (Subp : Entity_Id) return Boolean
12513 Subp_Decl : Node_Id;
12516 if Ekind (Subp) = E_Function then
12517 Subp_Decl := Unit_Declaration_Node (Subp);
12519 -- The function declaration is either an expression function or is
12520 -- completed by an expression function body.
12523 Is_Expression_Function (Subp)
12524 or else (Nkind (Subp_Decl) = N_Subprogram_Declaration
12525 and then Present (Corresponding_Body (Subp_Decl))
12526 and then Is_Expression_Function
12527 (Corresponding_Body (Subp_Decl)));
12529 elsif Ekind (Subp) = E_Subprogram_Body then
12530 return Is_Expression_Function (Subp);
12535 end Is_Expression_Function_Or_Completion;
12537 -----------------------
12538 -- Is_EVF_Expression --
12539 -----------------------
12541 function Is_EVF_Expression (N : Node_Id) return Boolean is
12542 Orig_N : constant Node_Id := Original_Node (N);
12548 -- Detect a reference to a formal parameter of a specific tagged type
12549 -- whose related subprogram is subject to pragma Expresions_Visible with
12552 if Is_Entity_Name (N) and then Present (Entity (N)) then
12557 and then Is_Specific_Tagged_Type (Etype (Id))
12558 and then Extensions_Visible_Status (Id) =
12559 Extensions_Visible_False;
12561 -- A case expression is an EVF expression when it contains at least one
12562 -- EVF dependent_expression. Note that a case expression may have been
12563 -- expanded, hence the use of Original_Node.
12565 elsif Nkind (Orig_N) = N_Case_Expression then
12566 Alt := First (Alternatives (Orig_N));
12567 while Present (Alt) loop
12568 if Is_EVF_Expression (Expression (Alt)) then
12575 -- An if expression is an EVF expression when it contains at least one
12576 -- EVF dependent_expression. Note that an if expression may have been
12577 -- expanded, hence the use of Original_Node.
12579 elsif Nkind (Orig_N) = N_If_Expression then
12580 Expr := Next (First (Expressions (Orig_N)));
12581 while Present (Expr) loop
12582 if Is_EVF_Expression (Expr) then
12589 -- A qualified expression or a type conversion is an EVF expression when
12590 -- its operand is an EVF expression.
12592 elsif Nkind_In (N, N_Qualified_Expression,
12593 N_Unchecked_Type_Conversion,
12596 return Is_EVF_Expression (Expression (N));
12598 -- Attributes 'Loop_Entry, 'Old, and 'Update are EVF expressions when
12599 -- their prefix denotes an EVF expression.
12601 elsif Nkind (N) = N_Attribute_Reference
12602 and then Nam_In (Attribute_Name (N), Name_Loop_Entry,
12606 return Is_EVF_Expression (Prefix (N));
12610 end Is_EVF_Expression;
12616 function Is_False (U : Uint) return Boolean is
12621 ---------------------------
12622 -- Is_Fixed_Model_Number --
12623 ---------------------------
12625 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
12626 S : constant Ureal := Small_Value (T);
12627 M : Urealp.Save_Mark;
12631 R := (U = UR_Trunc (U / S) * S);
12632 Urealp.Release (M);
12634 end Is_Fixed_Model_Number;
12636 -------------------------------
12637 -- Is_Fully_Initialized_Type --
12638 -------------------------------
12640 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
12644 if Is_Scalar_Type (Typ) then
12646 -- A scalar type with an aspect Default_Value is fully initialized
12648 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
12649 -- of a scalar type, but we don't take that into account here, since
12650 -- we don't want these to affect warnings.
12652 return Has_Default_Aspect (Typ);
12654 elsif Is_Access_Type (Typ) then
12657 elsif Is_Array_Type (Typ) then
12658 if Is_Fully_Initialized_Type (Component_Type (Typ))
12659 or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
12664 -- An interesting case, if we have a constrained type one of whose
12665 -- bounds is known to be null, then there are no elements to be
12666 -- initialized, so all the elements are initialized.
12668 if Is_Constrained (Typ) then
12671 Indx_Typ : Entity_Id;
12672 Lbd, Hbd : Node_Id;
12675 Indx := First_Index (Typ);
12676 while Present (Indx) loop
12677 if Etype (Indx) = Any_Type then
12680 -- If index is a range, use directly
12682 elsif Nkind (Indx) = N_Range then
12683 Lbd := Low_Bound (Indx);
12684 Hbd := High_Bound (Indx);
12687 Indx_Typ := Etype (Indx);
12689 if Is_Private_Type (Indx_Typ) then
12690 Indx_Typ := Full_View (Indx_Typ);
12693 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
12696 Lbd := Type_Low_Bound (Indx_Typ);
12697 Hbd := Type_High_Bound (Indx_Typ);
12701 if Compile_Time_Known_Value (Lbd)
12703 Compile_Time_Known_Value (Hbd)
12705 if Expr_Value (Hbd) < Expr_Value (Lbd) then
12715 -- If no null indexes, then type is not fully initialized
12721 elsif Is_Record_Type (Typ) then
12722 if Has_Discriminants (Typ)
12724 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
12725 and then Is_Fully_Initialized_Variant (Typ)
12730 -- We consider bounded string types to be fully initialized, because
12731 -- otherwise we get false alarms when the Data component is not
12732 -- default-initialized.
12734 if Is_Bounded_String (Typ) then
12738 -- Controlled records are considered to be fully initialized if
12739 -- there is a user defined Initialize routine. This may not be
12740 -- entirely correct, but as the spec notes, we are guessing here
12741 -- what is best from the point of view of issuing warnings.
12743 if Is_Controlled (Typ) then
12745 Utyp : constant Entity_Id := Underlying_Type (Typ);
12748 if Present (Utyp) then
12750 Init : constant Entity_Id :=
12751 (Find_Optional_Prim_Op
12752 (Underlying_Type (Typ), Name_Initialize));
12756 and then Comes_From_Source (Init)
12758 Is_Predefined_File_Name
12759 (File_Name (Get_Source_File_Index (Sloc (Init))))
12763 elsif Has_Null_Extension (Typ)
12765 Is_Fully_Initialized_Type
12766 (Etype (Base_Type (Typ)))
12775 -- Otherwise see if all record components are initialized
12781 Ent := First_Entity (Typ);
12782 while Present (Ent) loop
12783 if Ekind (Ent) = E_Component
12784 and then (No (Parent (Ent))
12785 or else No (Expression (Parent (Ent))))
12786 and then not Is_Fully_Initialized_Type (Etype (Ent))
12788 -- Special VM case for tag components, which need to be
12789 -- defined in this case, but are never initialized as VMs
12790 -- are using other dispatching mechanisms. Ignore this
12791 -- uninitialized case. Note that this applies both to the
12792 -- uTag entry and the main vtable pointer (CPP_Class case).
12794 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
12803 -- No uninitialized components, so type is fully initialized.
12804 -- Note that this catches the case of no components as well.
12808 elsif Is_Concurrent_Type (Typ) then
12811 elsif Is_Private_Type (Typ) then
12813 U : constant Entity_Id := Underlying_Type (Typ);
12819 return Is_Fully_Initialized_Type (U);
12826 end Is_Fully_Initialized_Type;
12828 ----------------------------------
12829 -- Is_Fully_Initialized_Variant --
12830 ----------------------------------
12832 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
12833 Loc : constant Source_Ptr := Sloc (Typ);
12834 Constraints : constant List_Id := New_List;
12835 Components : constant Elist_Id := New_Elmt_List;
12836 Comp_Elmt : Elmt_Id;
12838 Comp_List : Node_Id;
12840 Discr_Val : Node_Id;
12842 Report_Errors : Boolean;
12843 pragma Warnings (Off, Report_Errors);
12846 if Serious_Errors_Detected > 0 then
12850 if Is_Record_Type (Typ)
12851 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
12852 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
12854 Comp_List := Component_List (Type_Definition (Parent (Typ)));
12856 Discr := First_Discriminant (Typ);
12857 while Present (Discr) loop
12858 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
12859 Discr_Val := Expression (Parent (Discr));
12861 if Present (Discr_Val)
12862 and then Is_OK_Static_Expression (Discr_Val)
12864 Append_To (Constraints,
12865 Make_Component_Association (Loc,
12866 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
12867 Expression => New_Copy (Discr_Val)));
12875 Next_Discriminant (Discr);
12880 Comp_List => Comp_List,
12881 Governed_By => Constraints,
12882 Into => Components,
12883 Report_Errors => Report_Errors);
12885 -- Check that each component present is fully initialized
12887 Comp_Elmt := First_Elmt (Components);
12888 while Present (Comp_Elmt) loop
12889 Comp_Id := Node (Comp_Elmt);
12891 if Ekind (Comp_Id) = E_Component
12892 and then (No (Parent (Comp_Id))
12893 or else No (Expression (Parent (Comp_Id))))
12894 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
12899 Next_Elmt (Comp_Elmt);
12904 elsif Is_Private_Type (Typ) then
12906 U : constant Entity_Id := Underlying_Type (Typ);
12912 return Is_Fully_Initialized_Variant (U);
12919 end Is_Fully_Initialized_Variant;
12921 ------------------------------------
12922 -- Is_Generic_Declaration_Or_Body --
12923 ------------------------------------
12925 function Is_Generic_Declaration_Or_Body (Decl : Node_Id) return Boolean is
12926 Spec_Decl : Node_Id;
12929 -- Package/subprogram body
12931 if Nkind_In (Decl, N_Package_Body, N_Subprogram_Body)
12932 and then Present (Corresponding_Spec (Decl))
12934 Spec_Decl := Unit_Declaration_Node (Corresponding_Spec (Decl));
12936 -- Package/subprogram body stub
12938 elsif Nkind_In (Decl, N_Package_Body_Stub, N_Subprogram_Body_Stub)
12939 and then Present (Corresponding_Spec_Of_Stub (Decl))
12942 Unit_Declaration_Node (Corresponding_Spec_Of_Stub (Decl));
12950 -- Rather than inspecting the defining entity of the spec declaration,
12951 -- look at its Nkind. This takes care of the case where the analysis of
12952 -- a generic body modifies the Ekind of its spec to allow for recursive
12956 Nkind_In (Spec_Decl, N_Generic_Package_Declaration,
12957 N_Generic_Subprogram_Declaration);
12958 end Is_Generic_Declaration_Or_Body;
12960 ----------------------------
12961 -- Is_Inherited_Operation --
12962 ----------------------------
12964 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
12965 pragma Assert (Is_Overloadable (E));
12966 Kind : constant Node_Kind := Nkind (Parent (E));
12968 return Kind = N_Full_Type_Declaration
12969 or else Kind = N_Private_Extension_Declaration
12970 or else Kind = N_Subtype_Declaration
12971 or else (Ekind (E) = E_Enumeration_Literal
12972 and then Is_Derived_Type (Etype (E)));
12973 end Is_Inherited_Operation;
12975 -------------------------------------
12976 -- Is_Inherited_Operation_For_Type --
12977 -------------------------------------
12979 function Is_Inherited_Operation_For_Type
12981 Typ : Entity_Id) return Boolean
12984 -- Check that the operation has been created by the type declaration
12986 return Is_Inherited_Operation (E)
12987 and then Defining_Identifier (Parent (E)) = Typ;
12988 end Is_Inherited_Operation_For_Type;
12994 function Is_Iterator (Typ : Entity_Id) return Boolean is
12995 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean;
12996 -- Determine whether type Iter_Typ is a predefined forward or reversible
12999 ----------------------
13000 -- Denotes_Iterator --
13001 ----------------------
13003 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean is
13005 -- Check that the name matches, and that the ultimate ancestor is in
13006 -- a predefined unit, i.e the one that declares iterator interfaces.
13009 Nam_In (Chars (Iter_Typ), Name_Forward_Iterator,
13010 Name_Reversible_Iterator)
13011 and then Is_Predefined_File_Name
13012 (Unit_File_Name (Get_Source_Unit (Root_Type (Iter_Typ))));
13013 end Denotes_Iterator;
13017 Iface_Elmt : Elmt_Id;
13020 -- Start of processing for Is_Iterator
13023 -- The type may be a subtype of a descendant of the proper instance of
13024 -- the predefined interface type, so we must use the root type of the
13025 -- given type. The same is done for Is_Reversible_Iterator.
13027 if Is_Class_Wide_Type (Typ)
13028 and then Denotes_Iterator (Root_Type (Typ))
13032 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
13035 elsif Present (Find_Value_Of_Aspect (Typ, Aspect_Iterable)) then
13039 Collect_Interfaces (Typ, Ifaces);
13041 Iface_Elmt := First_Elmt (Ifaces);
13042 while Present (Iface_Elmt) loop
13043 if Denotes_Iterator (Node (Iface_Elmt)) then
13047 Next_Elmt (Iface_Elmt);
13054 ----------------------------
13055 -- Is_Iterator_Over_Array --
13056 ----------------------------
13058 function Is_Iterator_Over_Array (N : Node_Id) return Boolean is
13059 Container : constant Node_Id := Name (N);
13060 Container_Typ : constant Entity_Id := Base_Type (Etype (Container));
13062 return Is_Array_Type (Container_Typ);
13063 end Is_Iterator_Over_Array;
13069 -- We seem to have a lot of overlapping functions that do similar things
13070 -- (testing for left hand sides or lvalues???).
13072 function Is_LHS (N : Node_Id) return Is_LHS_Result is
13073 P : constant Node_Id := Parent (N);
13076 -- Return True if we are the left hand side of an assignment statement
13078 if Nkind (P) = N_Assignment_Statement then
13079 if Name (P) = N then
13085 -- Case of prefix of indexed or selected component or slice
13087 elsif Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
13088 and then N = Prefix (P)
13090 -- Here we have the case where the parent P is N.Q or N(Q .. R).
13091 -- If P is an LHS, then N is also effectively an LHS, but there
13092 -- is an important exception. If N is of an access type, then
13093 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
13094 -- case this makes N.all a left hand side but not N itself.
13096 -- If we don't know the type yet, this is the case where we return
13097 -- Unknown, since the answer depends on the type which is unknown.
13099 if No (Etype (N)) then
13102 -- We have an Etype set, so we can check it
13104 elsif Is_Access_Type (Etype (N)) then
13107 -- OK, not access type case, so just test whole expression
13113 -- All other cases are not left hand sides
13120 -----------------------------
13121 -- Is_Library_Level_Entity --
13122 -----------------------------
13124 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
13126 -- The following is a small optimization, and it also properly handles
13127 -- discriminals, which in task bodies might appear in expressions before
13128 -- the corresponding procedure has been created, and which therefore do
13129 -- not have an assigned scope.
13131 if Is_Formal (E) then
13135 -- Normal test is simply that the enclosing dynamic scope is Standard
13137 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
13138 end Is_Library_Level_Entity;
13140 --------------------------------
13141 -- Is_Limited_Class_Wide_Type --
13142 --------------------------------
13144 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
13147 Is_Class_Wide_Type (Typ)
13148 and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
13149 end Is_Limited_Class_Wide_Type;
13151 ---------------------------------
13152 -- Is_Local_Variable_Reference --
13153 ---------------------------------
13155 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
13157 if not Is_Entity_Name (Expr) then
13162 Ent : constant Entity_Id := Entity (Expr);
13163 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
13165 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
13168 return Present (Sub) and then Sub = Current_Subprogram;
13172 end Is_Local_Variable_Reference;
13174 ---------------------------------
13175 -- Is_Nontrivial_DIC_Procedure --
13176 ---------------------------------
13178 function Is_Nontrivial_DIC_Procedure (Id : Entity_Id) return Boolean is
13179 Body_Decl : Node_Id;
13183 if Ekind (Id) = E_Procedure and then Is_DIC_Procedure (Id) then
13185 Unit_Declaration_Node
13186 (Corresponding_Body (Unit_Declaration_Node (Id)));
13188 -- The body of the Default_Initial_Condition procedure must contain
13189 -- at least one statement, otherwise the generation of the subprogram
13192 pragma Assert (Present (Handled_Statement_Sequence (Body_Decl)));
13194 -- To qualify as nontrivial, the first statement of the procedure
13195 -- must be a check in the form of an if statement. If the original
13196 -- Default_Initial_Condition expression was folded, then the first
13197 -- statement is not a check.
13199 Stmt := First (Statements (Handled_Statement_Sequence (Body_Decl)));
13202 Nkind (Stmt) = N_If_Statement
13203 and then Nkind (Original_Node (Stmt)) = N_Pragma;
13207 end Is_Nontrivial_DIC_Procedure;
13209 -------------------------
13210 -- Is_Null_Record_Type --
13211 -------------------------
13213 function Is_Null_Record_Type (T : Entity_Id) return Boolean is
13214 Decl : constant Node_Id := Parent (T);
13216 return Nkind (Decl) = N_Full_Type_Declaration
13217 and then Nkind (Type_Definition (Decl)) = N_Record_Definition
13219 (No (Component_List (Type_Definition (Decl)))
13220 or else Null_Present (Component_List (Type_Definition (Decl))));
13221 end Is_Null_Record_Type;
13223 -------------------------
13224 -- Is_Object_Reference --
13225 -------------------------
13227 function Is_Object_Reference (N : Node_Id) return Boolean is
13228 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean;
13229 -- Determine whether N is the name of an internally-generated renaming
13231 --------------------------------------
13232 -- Is_Internally_Generated_Renaming --
13233 --------------------------------------
13235 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean is
13240 while Present (P) loop
13241 if Nkind (P) = N_Object_Renaming_Declaration then
13242 return not Comes_From_Source (P);
13243 elsif Is_List_Member (P) then
13251 end Is_Internally_Generated_Renaming;
13253 -- Start of processing for Is_Object_Reference
13256 if Is_Entity_Name (N) then
13257 return Present (Entity (N)) and then Is_Object (Entity (N));
13261 when N_Indexed_Component | N_Slice =>
13263 Is_Object_Reference (Prefix (N))
13264 or else Is_Access_Type (Etype (Prefix (N)));
13266 -- In Ada 95, a function call is a constant object; a procedure
13269 when N_Function_Call =>
13270 return Etype (N) /= Standard_Void_Type;
13272 -- Attributes 'Input, 'Loop_Entry, 'Old, and 'Result produce
13275 when N_Attribute_Reference =>
13277 Nam_In (Attribute_Name (N), Name_Input,
13282 when N_Selected_Component =>
13284 Is_Object_Reference (Selector_Name (N))
13286 (Is_Object_Reference (Prefix (N))
13287 or else Is_Access_Type (Etype (Prefix (N))));
13289 when N_Explicit_Dereference =>
13292 -- A view conversion of a tagged object is an object reference
13294 when N_Type_Conversion =>
13295 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
13296 and then Is_Tagged_Type (Etype (Expression (N)))
13297 and then Is_Object_Reference (Expression (N));
13299 -- An unchecked type conversion is considered to be an object if
13300 -- the operand is an object (this construction arises only as a
13301 -- result of expansion activities).
13303 when N_Unchecked_Type_Conversion =>
13306 -- Allow string literals to act as objects as long as they appear
13307 -- in internally-generated renamings. The expansion of iterators
13308 -- may generate such renamings when the range involves a string
13311 when N_String_Literal =>
13312 return Is_Internally_Generated_Renaming (Parent (N));
13314 -- AI05-0003: In Ada 2012 a qualified expression is a name.
13315 -- This allows disambiguation of function calls and the use
13316 -- of aggregates in more contexts.
13318 when N_Qualified_Expression =>
13319 if Ada_Version < Ada_2012 then
13322 return Is_Object_Reference (Expression (N))
13323 or else Nkind (Expression (N)) = N_Aggregate;
13330 end Is_Object_Reference;
13332 -----------------------------------
13333 -- Is_OK_Variable_For_Out_Formal --
13334 -----------------------------------
13336 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
13338 Note_Possible_Modification (AV, Sure => True);
13340 -- We must reject parenthesized variable names. Comes_From_Source is
13341 -- checked because there are currently cases where the compiler violates
13342 -- this rule (e.g. passing a task object to its controlled Initialize
13343 -- routine). This should be properly documented in sinfo???
13345 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
13348 -- A variable is always allowed
13350 elsif Is_Variable (AV) then
13353 -- Generalized indexing operations are rewritten as explicit
13354 -- dereferences, and it is only during resolution that we can
13355 -- check whether the context requires an access_to_variable type.
13357 elsif Nkind (AV) = N_Explicit_Dereference
13358 and then Ada_Version >= Ada_2012
13359 and then Nkind (Original_Node (AV)) = N_Indexed_Component
13360 and then Present (Etype (Original_Node (AV)))
13361 and then Has_Implicit_Dereference (Etype (Original_Node (AV)))
13363 return not Is_Access_Constant (Etype (Prefix (AV)));
13365 -- Unchecked conversions are allowed only if they come from the
13366 -- generated code, which sometimes uses unchecked conversions for out
13367 -- parameters in cases where code generation is unaffected. We tell
13368 -- source unchecked conversions by seeing if they are rewrites of
13369 -- an original Unchecked_Conversion function call, or of an explicit
13370 -- conversion of a function call or an aggregate (as may happen in the
13371 -- expansion of a packed array aggregate).
13373 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
13374 if Nkind_In (Original_Node (AV), N_Function_Call, N_Aggregate) then
13377 elsif Comes_From_Source (AV)
13378 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
13382 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
13383 return Is_OK_Variable_For_Out_Formal (Expression (AV));
13389 -- Normal type conversions are allowed if argument is a variable
13391 elsif Nkind (AV) = N_Type_Conversion then
13392 if Is_Variable (Expression (AV))
13393 and then Paren_Count (Expression (AV)) = 0
13395 Note_Possible_Modification (Expression (AV), Sure => True);
13398 -- We also allow a non-parenthesized expression that raises
13399 -- constraint error if it rewrites what used to be a variable
13401 elsif Raises_Constraint_Error (Expression (AV))
13402 and then Paren_Count (Expression (AV)) = 0
13403 and then Is_Variable (Original_Node (Expression (AV)))
13407 -- Type conversion of something other than a variable
13413 -- If this node is rewritten, then test the original form, if that is
13414 -- OK, then we consider the rewritten node OK (for example, if the
13415 -- original node is a conversion, then Is_Variable will not be true
13416 -- but we still want to allow the conversion if it converts a variable).
13418 elsif Original_Node (AV) /= AV then
13420 -- In Ada 2012, the explicit dereference may be a rewritten call to a
13421 -- Reference function.
13423 if Ada_Version >= Ada_2012
13424 and then Nkind (Original_Node (AV)) = N_Function_Call
13426 Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
13429 -- Check that this is not a constant reference.
13431 return not Is_Access_Constant (Etype (Prefix (AV)));
13433 elsif Has_Implicit_Dereference (Etype (Original_Node (AV))) then
13435 not Is_Access_Constant (Etype
13436 (Get_Reference_Discriminant (Etype (Original_Node (AV)))));
13439 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
13442 -- All other non-variables are rejected
13447 end Is_OK_Variable_For_Out_Formal;
13449 ----------------------------
13450 -- Is_OK_Volatile_Context --
13451 ----------------------------
13453 function Is_OK_Volatile_Context
13454 (Context : Node_Id;
13455 Obj_Ref : Node_Id) return Boolean
13457 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean;
13458 -- Determine whether an arbitrary node denotes a call to a protected
13459 -- entry, function, or procedure in prefixed form where the prefix is
13462 function Within_Check (Nod : Node_Id) return Boolean;
13463 -- Determine whether an arbitrary node appears in a check node
13465 function Within_Subprogram_Call (Nod : Node_Id) return Boolean;
13466 -- Determine whether an arbitrary node appears in an entry, function, or
13469 function Within_Volatile_Function (Id : Entity_Id) return Boolean;
13470 -- Determine whether an arbitrary entity appears in a volatile function
13472 ---------------------------------
13473 -- Is_Protected_Operation_Call --
13474 ---------------------------------
13476 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean is
13481 -- A call to a protected operations retains its selected component
13482 -- form as opposed to other prefixed calls that are transformed in
13485 if Nkind (Nod) = N_Selected_Component then
13486 Pref := Prefix (Nod);
13487 Subp := Selector_Name (Nod);
13491 and then Present (Etype (Pref))
13492 and then Is_Protected_Type (Etype (Pref))
13493 and then Is_Entity_Name (Subp)
13494 and then Present (Entity (Subp))
13495 and then Ekind_In (Entity (Subp), E_Entry,
13502 end Is_Protected_Operation_Call;
13508 function Within_Check (Nod : Node_Id) return Boolean is
13512 -- Climb the parent chain looking for a check node
13515 while Present (Par) loop
13516 if Nkind (Par) in N_Raise_xxx_Error then
13519 -- Prevent the search from going too far
13521 elsif Is_Body_Or_Package_Declaration (Par) then
13525 Par := Parent (Par);
13531 ----------------------------
13532 -- Within_Subprogram_Call --
13533 ----------------------------
13535 function Within_Subprogram_Call (Nod : Node_Id) return Boolean is
13539 -- Climb the parent chain looking for a function or procedure call
13542 while Present (Par) loop
13543 if Nkind_In (Par, N_Entry_Call_Statement,
13545 N_Procedure_Call_Statement)
13549 -- Prevent the search from going too far
13551 elsif Is_Body_Or_Package_Declaration (Par) then
13555 Par := Parent (Par);
13559 end Within_Subprogram_Call;
13561 ------------------------------
13562 -- Within_Volatile_Function --
13563 ------------------------------
13565 function Within_Volatile_Function (Id : Entity_Id) return Boolean is
13566 Func_Id : Entity_Id;
13569 -- Traverse the scope stack looking for a [generic] function
13572 while Present (Func_Id) and then Func_Id /= Standard_Standard loop
13573 if Ekind_In (Func_Id, E_Function, E_Generic_Function) then
13574 return Is_Volatile_Function (Func_Id);
13577 Func_Id := Scope (Func_Id);
13581 end Within_Volatile_Function;
13585 Obj_Id : Entity_Id;
13587 -- Start of processing for Is_OK_Volatile_Context
13590 -- The volatile object appears on either side of an assignment
13592 if Nkind (Context) = N_Assignment_Statement then
13595 -- The volatile object is part of the initialization expression of
13598 elsif Nkind (Context) = N_Object_Declaration
13599 and then Present (Expression (Context))
13600 and then Expression (Context) = Obj_Ref
13602 Obj_Id := Defining_Entity (Context);
13604 -- The volatile object acts as the initialization expression of an
13605 -- extended return statement. This is valid context as long as the
13606 -- function is volatile.
13608 if Is_Return_Object (Obj_Id) then
13609 return Within_Volatile_Function (Obj_Id);
13611 -- Otherwise this is a normal object initialization
13617 -- The volatile object acts as the name of a renaming declaration
13619 elsif Nkind (Context) = N_Object_Renaming_Declaration
13620 and then Name (Context) = Obj_Ref
13624 -- The volatile object appears as an actual parameter in a call to an
13625 -- instance of Unchecked_Conversion whose result is renamed.
13627 elsif Nkind (Context) = N_Function_Call
13628 and then Is_Entity_Name (Name (Context))
13629 and then Is_Unchecked_Conversion_Instance (Entity (Name (Context)))
13630 and then Nkind (Parent (Context)) = N_Object_Renaming_Declaration
13634 -- The volatile object is actually the prefix in a protected entry,
13635 -- function, or procedure call.
13637 elsif Is_Protected_Operation_Call (Context) then
13640 -- The volatile object appears as the expression of a simple return
13641 -- statement that applies to a volatile function.
13643 elsif Nkind (Context) = N_Simple_Return_Statement
13644 and then Expression (Context) = Obj_Ref
13647 Within_Volatile_Function (Return_Statement_Entity (Context));
13649 -- The volatile object appears as the prefix of a name occurring in a
13650 -- non-interfering context.
13652 elsif Nkind_In (Context, N_Attribute_Reference,
13653 N_Explicit_Dereference,
13654 N_Indexed_Component,
13655 N_Selected_Component,
13657 and then Prefix (Context) = Obj_Ref
13658 and then Is_OK_Volatile_Context
13659 (Context => Parent (Context),
13660 Obj_Ref => Context)
13664 -- The volatile object appears as the prefix of attributes Address,
13665 -- Alignment, Component_Size, First_Bit, Last_Bit, Position, Size,
13668 elsif Nkind (Context) = N_Attribute_Reference
13669 and then Prefix (Context) = Obj_Ref
13670 and then Nam_In (Attribute_Name (Context), Name_Address,
13672 Name_Component_Size,
13681 -- The volatile object appears as the expression of a type conversion
13682 -- occurring in a non-interfering context.
13684 elsif Nkind_In (Context, N_Type_Conversion,
13685 N_Unchecked_Type_Conversion)
13686 and then Expression (Context) = Obj_Ref
13687 and then Is_OK_Volatile_Context
13688 (Context => Parent (Context),
13689 Obj_Ref => Context)
13693 -- Allow references to volatile objects in various checks. This is not a
13694 -- direct SPARK 2014 requirement.
13696 elsif Within_Check (Context) then
13699 -- Assume that references to effectively volatile objects that appear
13700 -- as actual parameters in a subprogram call are always legal. A full
13701 -- legality check is done when the actuals are resolved (see routine
13702 -- Resolve_Actuals).
13704 elsif Within_Subprogram_Call (Context) then
13707 -- Otherwise the context is not suitable for an effectively volatile
13713 end Is_OK_Volatile_Context;
13715 ------------------------------------
13716 -- Is_Package_Contract_Annotation --
13717 ------------------------------------
13719 function Is_Package_Contract_Annotation (Item : Node_Id) return Boolean is
13723 if Nkind (Item) = N_Aspect_Specification then
13724 Nam := Chars (Identifier (Item));
13726 else pragma Assert (Nkind (Item) = N_Pragma);
13727 Nam := Pragma_Name (Item);
13730 return Nam = Name_Abstract_State
13731 or else Nam = Name_Initial_Condition
13732 or else Nam = Name_Initializes
13733 or else Nam = Name_Refined_State;
13734 end Is_Package_Contract_Annotation;
13736 -----------------------------------
13737 -- Is_Partially_Initialized_Type --
13738 -----------------------------------
13740 function Is_Partially_Initialized_Type
13742 Include_Implicit : Boolean := True) return Boolean
13745 if Is_Scalar_Type (Typ) then
13748 elsif Is_Access_Type (Typ) then
13749 return Include_Implicit;
13751 elsif Is_Array_Type (Typ) then
13753 -- If component type is partially initialized, so is array type
13755 if Is_Partially_Initialized_Type
13756 (Component_Type (Typ), Include_Implicit)
13760 -- Otherwise we are only partially initialized if we are fully
13761 -- initialized (this is the empty array case, no point in us
13762 -- duplicating that code here).
13765 return Is_Fully_Initialized_Type (Typ);
13768 elsif Is_Record_Type (Typ) then
13770 -- A discriminated type is always partially initialized if in
13773 if Has_Discriminants (Typ) and then Include_Implicit then
13776 -- A tagged type is always partially initialized
13778 elsif Is_Tagged_Type (Typ) then
13781 -- Case of non-discriminated record
13787 Component_Present : Boolean := False;
13788 -- Set True if at least one component is present. If no
13789 -- components are present, then record type is fully
13790 -- initialized (another odd case, like the null array).
13793 -- Loop through components
13795 Ent := First_Entity (Typ);
13796 while Present (Ent) loop
13797 if Ekind (Ent) = E_Component then
13798 Component_Present := True;
13800 -- If a component has an initialization expression then
13801 -- the enclosing record type is partially initialized
13803 if Present (Parent (Ent))
13804 and then Present (Expression (Parent (Ent)))
13808 -- If a component is of a type which is itself partially
13809 -- initialized, then the enclosing record type is also.
13811 elsif Is_Partially_Initialized_Type
13812 (Etype (Ent), Include_Implicit)
13821 -- No initialized components found. If we found any components
13822 -- they were all uninitialized so the result is false.
13824 if Component_Present then
13827 -- But if we found no components, then all the components are
13828 -- initialized so we consider the type to be initialized.
13836 -- Concurrent types are always fully initialized
13838 elsif Is_Concurrent_Type (Typ) then
13841 -- For a private type, go to underlying type. If there is no underlying
13842 -- type then just assume this partially initialized. Not clear if this
13843 -- can happen in a non-error case, but no harm in testing for this.
13845 elsif Is_Private_Type (Typ) then
13847 U : constant Entity_Id := Underlying_Type (Typ);
13852 return Is_Partially_Initialized_Type (U, Include_Implicit);
13856 -- For any other type (are there any?) assume partially initialized
13861 end Is_Partially_Initialized_Type;
13863 ------------------------------------
13864 -- Is_Potentially_Persistent_Type --
13865 ------------------------------------
13867 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
13872 -- For private type, test corresponding full type
13874 if Is_Private_Type (T) then
13875 return Is_Potentially_Persistent_Type (Full_View (T));
13877 -- Scalar types are potentially persistent
13879 elsif Is_Scalar_Type (T) then
13882 -- Record type is potentially persistent if not tagged and the types of
13883 -- all it components are potentially persistent, and no component has
13884 -- an initialization expression.
13886 elsif Is_Record_Type (T)
13887 and then not Is_Tagged_Type (T)
13888 and then not Is_Partially_Initialized_Type (T)
13890 Comp := First_Component (T);
13891 while Present (Comp) loop
13892 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
13895 Next_Entity (Comp);
13901 -- Array type is potentially persistent if its component type is
13902 -- potentially persistent and if all its constraints are static.
13904 elsif Is_Array_Type (T) then
13905 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
13909 Indx := First_Index (T);
13910 while Present (Indx) loop
13911 if not Is_OK_Static_Subtype (Etype (Indx)) then
13920 -- All other types are not potentially persistent
13925 end Is_Potentially_Persistent_Type;
13927 --------------------------------
13928 -- Is_Potentially_Unevaluated --
13929 --------------------------------
13931 function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is
13939 -- A postcondition whose expression is a short-circuit is broken down
13940 -- into individual aspects for better exception reporting. The original
13941 -- short-circuit expression is rewritten as the second operand, and an
13942 -- occurrence of 'Old in that operand is potentially unevaluated.
13943 -- See Sem_ch13.adb for details of this transformation.
13945 if Nkind (Original_Node (Par)) = N_And_Then then
13949 while not Nkind_In (Par, N_If_Expression,
13957 Par := Parent (Par);
13959 -- If the context is not an expression, or if is the result of
13960 -- expansion of an enclosing construct (such as another attribute)
13961 -- the predicate does not apply.
13963 if Nkind (Par) not in N_Subexpr
13964 or else not Comes_From_Source (Par)
13970 if Nkind (Par) = N_If_Expression then
13971 return Is_Elsif (Par) or else Expr /= First (Expressions (Par));
13973 elsif Nkind (Par) = N_Case_Expression then
13974 return Expr /= Expression (Par);
13976 elsif Nkind_In (Par, N_And_Then, N_Or_Else) then
13977 return Expr = Right_Opnd (Par);
13979 elsif Nkind_In (Par, N_In, N_Not_In) then
13980 return Expr /= Left_Opnd (Par);
13985 end Is_Potentially_Unevaluated;
13987 ---------------------------------
13988 -- Is_Protected_Self_Reference --
13989 ---------------------------------
13991 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
13993 function In_Access_Definition (N : Node_Id) return Boolean;
13994 -- Returns true if N belongs to an access definition
13996 --------------------------
13997 -- In_Access_Definition --
13998 --------------------------
14000 function In_Access_Definition (N : Node_Id) return Boolean is
14005 while Present (P) loop
14006 if Nkind (P) = N_Access_Definition then
14014 end In_Access_Definition;
14016 -- Start of processing for Is_Protected_Self_Reference
14019 -- Verify that prefix is analyzed and has the proper form. Note that
14020 -- the attributes Elab_Spec, Elab_Body, and Elab_Subp_Body, which also
14021 -- produce the address of an entity, do not analyze their prefix
14022 -- because they denote entities that are not necessarily visible.
14023 -- Neither of them can apply to a protected type.
14025 return Ada_Version >= Ada_2005
14026 and then Is_Entity_Name (N)
14027 and then Present (Entity (N))
14028 and then Is_Protected_Type (Entity (N))
14029 and then In_Open_Scopes (Entity (N))
14030 and then not In_Access_Definition (N);
14031 end Is_Protected_Self_Reference;
14033 -----------------------------
14034 -- Is_RCI_Pkg_Spec_Or_Body --
14035 -----------------------------
14037 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
14039 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
14040 -- Return True if the unit of Cunit is an RCI package declaration
14042 ---------------------------
14043 -- Is_RCI_Pkg_Decl_Cunit --
14044 ---------------------------
14046 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
14047 The_Unit : constant Node_Id := Unit (Cunit);
14050 if Nkind (The_Unit) /= N_Package_Declaration then
14054 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
14055 end Is_RCI_Pkg_Decl_Cunit;
14057 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
14060 return Is_RCI_Pkg_Decl_Cunit (Cunit)
14062 (Nkind (Unit (Cunit)) = N_Package_Body
14063 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
14064 end Is_RCI_Pkg_Spec_Or_Body;
14066 -----------------------------------------
14067 -- Is_Remote_Access_To_Class_Wide_Type --
14068 -----------------------------------------
14070 function Is_Remote_Access_To_Class_Wide_Type
14071 (E : Entity_Id) return Boolean
14074 -- A remote access to class-wide type is a general access to object type
14075 -- declared in the visible part of a Remote_Types or Remote_Call_
14078 return Ekind (E) = E_General_Access_Type
14079 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
14080 end Is_Remote_Access_To_Class_Wide_Type;
14082 -----------------------------------------
14083 -- Is_Remote_Access_To_Subprogram_Type --
14084 -----------------------------------------
14086 function Is_Remote_Access_To_Subprogram_Type
14087 (E : Entity_Id) return Boolean
14090 return (Ekind (E) = E_Access_Subprogram_Type
14091 or else (Ekind (E) = E_Record_Type
14092 and then Present (Corresponding_Remote_Type (E))))
14093 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
14094 end Is_Remote_Access_To_Subprogram_Type;
14096 --------------------
14097 -- Is_Remote_Call --
14098 --------------------
14100 function Is_Remote_Call (N : Node_Id) return Boolean is
14102 if Nkind (N) not in N_Subprogram_Call then
14104 -- An entry call cannot be remote
14108 elsif Nkind (Name (N)) in N_Has_Entity
14109 and then Is_Remote_Call_Interface (Entity (Name (N)))
14111 -- A subprogram declared in the spec of a RCI package is remote
14115 elsif Nkind (Name (N)) = N_Explicit_Dereference
14116 and then Is_Remote_Access_To_Subprogram_Type
14117 (Etype (Prefix (Name (N))))
14119 -- The dereference of a RAS is a remote call
14123 elsif Present (Controlling_Argument (N))
14124 and then Is_Remote_Access_To_Class_Wide_Type
14125 (Etype (Controlling_Argument (N)))
14127 -- Any primitive operation call with a controlling argument of
14128 -- a RACW type is a remote call.
14133 -- All other calls are local calls
14136 end Is_Remote_Call;
14138 ----------------------
14139 -- Is_Renamed_Entry --
14140 ----------------------
14142 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
14143 Orig_Node : Node_Id := Empty;
14144 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
14146 function Is_Entry (Nam : Node_Id) return Boolean;
14147 -- Determine whether Nam is an entry. Traverse selectors if there are
14148 -- nested selected components.
14154 function Is_Entry (Nam : Node_Id) return Boolean is
14156 if Nkind (Nam) = N_Selected_Component then
14157 return Is_Entry (Selector_Name (Nam));
14160 return Ekind (Entity (Nam)) = E_Entry;
14163 -- Start of processing for Is_Renamed_Entry
14166 if Present (Alias (Proc_Nam)) then
14167 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
14170 -- Look for a rewritten subprogram renaming declaration
14172 if Nkind (Subp_Decl) = N_Subprogram_Declaration
14173 and then Present (Original_Node (Subp_Decl))
14175 Orig_Node := Original_Node (Subp_Decl);
14178 -- The rewritten subprogram is actually an entry
14180 if Present (Orig_Node)
14181 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
14182 and then Is_Entry (Name (Orig_Node))
14188 end Is_Renamed_Entry;
14190 -----------------------------
14191 -- Is_Renaming_Declaration --
14192 -----------------------------
14194 function Is_Renaming_Declaration (N : Node_Id) return Boolean is
14197 when N_Exception_Renaming_Declaration |
14198 N_Generic_Function_Renaming_Declaration |
14199 N_Generic_Package_Renaming_Declaration |
14200 N_Generic_Procedure_Renaming_Declaration |
14201 N_Object_Renaming_Declaration |
14202 N_Package_Renaming_Declaration |
14203 N_Subprogram_Renaming_Declaration =>
14209 end Is_Renaming_Declaration;
14211 ----------------------------
14212 -- Is_Reversible_Iterator --
14213 ----------------------------
14215 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
14216 Ifaces_List : Elist_Id;
14217 Iface_Elmt : Elmt_Id;
14221 if Is_Class_Wide_Type (Typ)
14222 and then Chars (Root_Type (Typ)) = Name_Reversible_Iterator
14223 and then Is_Predefined_File_Name
14224 (Unit_File_Name (Get_Source_Unit (Root_Type (Typ))))
14228 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
14232 Collect_Interfaces (Typ, Ifaces_List);
14234 Iface_Elmt := First_Elmt (Ifaces_List);
14235 while Present (Iface_Elmt) loop
14236 Iface := Node (Iface_Elmt);
14237 if Chars (Iface) = Name_Reversible_Iterator
14239 Is_Predefined_File_Name
14240 (Unit_File_Name (Get_Source_Unit (Iface)))
14245 Next_Elmt (Iface_Elmt);
14250 end Is_Reversible_Iterator;
14252 ----------------------
14253 -- Is_Selector_Name --
14254 ----------------------
14256 function Is_Selector_Name (N : Node_Id) return Boolean is
14258 if not Is_List_Member (N) then
14260 P : constant Node_Id := Parent (N);
14262 return Nkind_In (P, N_Expanded_Name,
14263 N_Generic_Association,
14264 N_Parameter_Association,
14265 N_Selected_Component)
14266 and then Selector_Name (P) = N;
14271 L : constant List_Id := List_Containing (N);
14272 P : constant Node_Id := Parent (L);
14274 return (Nkind (P) = N_Discriminant_Association
14275 and then Selector_Names (P) = L)
14277 (Nkind (P) = N_Component_Association
14278 and then Choices (P) = L);
14281 end Is_Selector_Name;
14283 ---------------------------------
14284 -- Is_Single_Concurrent_Object --
14285 ---------------------------------
14287 function Is_Single_Concurrent_Object (Id : Entity_Id) return Boolean is
14290 Is_Single_Protected_Object (Id) or else Is_Single_Task_Object (Id);
14291 end Is_Single_Concurrent_Object;
14293 -------------------------------
14294 -- Is_Single_Concurrent_Type --
14295 -------------------------------
14297 function Is_Single_Concurrent_Type (Id : Entity_Id) return Boolean is
14300 Ekind_In (Id, E_Protected_Type, E_Task_Type)
14301 and then Is_Single_Concurrent_Type_Declaration
14302 (Declaration_Node (Id));
14303 end Is_Single_Concurrent_Type;
14305 -------------------------------------------
14306 -- Is_Single_Concurrent_Type_Declaration --
14307 -------------------------------------------
14309 function Is_Single_Concurrent_Type_Declaration
14310 (N : Node_Id) return Boolean
14313 return Nkind_In (Original_Node (N), N_Single_Protected_Declaration,
14314 N_Single_Task_Declaration);
14315 end Is_Single_Concurrent_Type_Declaration;
14317 ---------------------------------------------
14318 -- Is_Single_Precision_Floating_Point_Type --
14319 ---------------------------------------------
14321 function Is_Single_Precision_Floating_Point_Type
14322 (E : Entity_Id) return Boolean is
14324 return Is_Floating_Point_Type (E)
14325 and then Machine_Radix_Value (E) = Uint_2
14326 and then Machine_Mantissa_Value (E) = Uint_24
14327 and then Machine_Emax_Value (E) = Uint_2 ** Uint_7
14328 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_7);
14329 end Is_Single_Precision_Floating_Point_Type;
14331 --------------------------------
14332 -- Is_Single_Protected_Object --
14333 --------------------------------
14335 function Is_Single_Protected_Object (Id : Entity_Id) return Boolean is
14338 Ekind (Id) = E_Variable
14339 and then Ekind (Etype (Id)) = E_Protected_Type
14340 and then Is_Single_Concurrent_Type (Etype (Id));
14341 end Is_Single_Protected_Object;
14343 ---------------------------
14344 -- Is_Single_Task_Object --
14345 ---------------------------
14347 function Is_Single_Task_Object (Id : Entity_Id) return Boolean is
14350 Ekind (Id) = E_Variable
14351 and then Ekind (Etype (Id)) = E_Task_Type
14352 and then Is_Single_Concurrent_Type (Etype (Id));
14353 end Is_Single_Task_Object;
14355 -------------------------------------
14356 -- Is_SPARK_05_Initialization_Expr --
14357 -------------------------------------
14359 function Is_SPARK_05_Initialization_Expr (N : Node_Id) return Boolean is
14362 Comp_Assn : Node_Id;
14363 Orig_N : constant Node_Id := Original_Node (N);
14368 if not Comes_From_Source (Orig_N) then
14372 pragma Assert (Nkind (Orig_N) in N_Subexpr);
14374 case Nkind (Orig_N) is
14375 when N_Character_Literal |
14376 N_Integer_Literal |
14378 N_String_Literal =>
14381 when N_Identifier |
14383 if Is_Entity_Name (Orig_N)
14384 and then Present (Entity (Orig_N)) -- needed in some cases
14386 case Ekind (Entity (Orig_N)) is
14388 E_Enumeration_Literal |
14393 if Is_Type (Entity (Orig_N)) then
14401 when N_Qualified_Expression |
14402 N_Type_Conversion =>
14403 Is_Ok := Is_SPARK_05_Initialization_Expr (Expression (Orig_N));
14406 Is_Ok := Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
14410 N_Membership_Test =>
14411 Is_Ok := Is_SPARK_05_Initialization_Expr (Left_Opnd (Orig_N))
14413 Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
14416 N_Extension_Aggregate =>
14417 if Nkind (Orig_N) = N_Extension_Aggregate then
14419 Is_SPARK_05_Initialization_Expr (Ancestor_Part (Orig_N));
14422 Expr := First (Expressions (Orig_N));
14423 while Present (Expr) loop
14424 if not Is_SPARK_05_Initialization_Expr (Expr) then
14432 Comp_Assn := First (Component_Associations (Orig_N));
14433 while Present (Comp_Assn) loop
14434 Expr := Expression (Comp_Assn);
14436 -- Note: test for Present here needed for box assocation
14439 and then not Is_SPARK_05_Initialization_Expr (Expr)
14448 when N_Attribute_Reference =>
14449 if Nkind (Prefix (Orig_N)) in N_Subexpr then
14450 Is_Ok := Is_SPARK_05_Initialization_Expr (Prefix (Orig_N));
14453 Expr := First (Expressions (Orig_N));
14454 while Present (Expr) loop
14455 if not Is_SPARK_05_Initialization_Expr (Expr) then
14463 -- Selected components might be expanded named not yet resolved, so
14464 -- default on the safe side. (Eg on sparklex.ads)
14466 when N_Selected_Component =>
14475 end Is_SPARK_05_Initialization_Expr;
14477 ----------------------------------
14478 -- Is_SPARK_05_Object_Reference --
14479 ----------------------------------
14481 function Is_SPARK_05_Object_Reference (N : Node_Id) return Boolean is
14483 if Is_Entity_Name (N) then
14484 return Present (Entity (N))
14486 (Ekind_In (Entity (N), E_Constant, E_Variable)
14487 or else Ekind (Entity (N)) in Formal_Kind);
14491 when N_Selected_Component =>
14492 return Is_SPARK_05_Object_Reference (Prefix (N));
14498 end Is_SPARK_05_Object_Reference;
14500 -----------------------------
14501 -- Is_Specific_Tagged_Type --
14502 -----------------------------
14504 function Is_Specific_Tagged_Type (Typ : Entity_Id) return Boolean is
14505 Full_Typ : Entity_Id;
14508 -- Handle private types
14510 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
14511 Full_Typ := Full_View (Typ);
14516 -- A specific tagged type is a non-class-wide tagged type
14518 return Is_Tagged_Type (Full_Typ) and not Is_Class_Wide_Type (Full_Typ);
14519 end Is_Specific_Tagged_Type;
14525 function Is_Statement (N : Node_Id) return Boolean is
14528 Nkind (N) in N_Statement_Other_Than_Procedure_Call
14529 or else Nkind (N) = N_Procedure_Call_Statement;
14532 ---------------------------------------
14533 -- Is_Subprogram_Contract_Annotation --
14534 ---------------------------------------
14536 function Is_Subprogram_Contract_Annotation
14537 (Item : Node_Id) return Boolean
14542 if Nkind (Item) = N_Aspect_Specification then
14543 Nam := Chars (Identifier (Item));
14545 else pragma Assert (Nkind (Item) = N_Pragma);
14546 Nam := Pragma_Name (Item);
14549 return Nam = Name_Contract_Cases
14550 or else Nam = Name_Depends
14551 or else Nam = Name_Extensions_Visible
14552 or else Nam = Name_Global
14553 or else Nam = Name_Post
14554 or else Nam = Name_Post_Class
14555 or else Nam = Name_Postcondition
14556 or else Nam = Name_Pre
14557 or else Nam = Name_Pre_Class
14558 or else Nam = Name_Precondition
14559 or else Nam = Name_Refined_Depends
14560 or else Nam = Name_Refined_Global
14561 or else Nam = Name_Refined_Post
14562 or else Nam = Name_Test_Case;
14563 end Is_Subprogram_Contract_Annotation;
14565 --------------------------------------------------
14566 -- Is_Subprogram_Stub_Without_Prior_Declaration --
14567 --------------------------------------------------
14569 function Is_Subprogram_Stub_Without_Prior_Declaration
14570 (N : Node_Id) return Boolean
14573 -- A subprogram stub without prior declaration serves as declaration for
14574 -- the actual subprogram body. As such, it has an attached defining
14575 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
14577 return Nkind (N) = N_Subprogram_Body_Stub
14578 and then Ekind (Defining_Entity (N)) /= E_Subprogram_Body;
14579 end Is_Subprogram_Stub_Without_Prior_Declaration;
14581 --------------------------
14582 -- Is_Suspension_Object --
14583 --------------------------
14585 function Is_Suspension_Object (Id : Entity_Id) return Boolean is
14587 -- This approach does an exact name match rather than to rely on
14588 -- RTSfind. Routine Is_Effectively_Volatile is used by clients of the
14589 -- front end at point where all auxiliary tables are locked and any
14590 -- modifications to them are treated as violations. Do not tamper with
14591 -- the tables, instead examine the Chars fields of all the scopes of Id.
14594 Chars (Id) = Name_Suspension_Object
14595 and then Present (Scope (Id))
14596 and then Chars (Scope (Id)) = Name_Synchronous_Task_Control
14597 and then Present (Scope (Scope (Id)))
14598 and then Chars (Scope (Scope (Id))) = Name_Ada
14599 and then Present (Scope (Scope (Scope (Id))))
14600 and then Scope (Scope (Scope (Id))) = Standard_Standard;
14601 end Is_Suspension_Object;
14603 ----------------------------
14604 -- Is_Synchronized_Object --
14605 ----------------------------
14607 function Is_Synchronized_Object (Id : Entity_Id) return Boolean is
14611 if Is_Object (Id) then
14613 -- The object is synchronized if it is of a type that yields a
14614 -- synchronized object.
14616 if Yields_Synchronized_Object (Etype (Id)) then
14619 -- The object is synchronized if it is atomic and Async_Writers is
14622 elsif Is_Atomic (Id) and then Async_Writers_Enabled (Id) then
14625 -- A constant is a synchronized object by default
14627 elsif Ekind (Id) = E_Constant then
14630 -- A variable is a synchronized object if it is subject to pragma
14631 -- Constant_After_Elaboration.
14633 elsif Ekind (Id) = E_Variable then
14634 Prag := Get_Pragma (Id, Pragma_Constant_After_Elaboration);
14636 return Present (Prag) and then Is_Enabled_Pragma (Prag);
14640 -- Otherwise the input is not an object or it does not qualify as a
14641 -- synchronized object.
14644 end Is_Synchronized_Object;
14646 ---------------------------------
14647 -- Is_Synchronized_Tagged_Type --
14648 ---------------------------------
14650 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
14651 Kind : constant Entity_Kind := Ekind (Base_Type (E));
14654 -- A task or protected type derived from an interface is a tagged type.
14655 -- Such a tagged type is called a synchronized tagged type, as are
14656 -- synchronized interfaces and private extensions whose declaration
14657 -- includes the reserved word synchronized.
14659 return (Is_Tagged_Type (E)
14660 and then (Kind = E_Task_Type
14662 Kind = E_Protected_Type))
14665 and then Is_Synchronized_Interface (E))
14667 (Ekind (E) = E_Record_Type_With_Private
14668 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
14669 and then (Synchronized_Present (Parent (E))
14670 or else Is_Synchronized_Interface (Etype (E))));
14671 end Is_Synchronized_Tagged_Type;
14677 function Is_Transfer (N : Node_Id) return Boolean is
14678 Kind : constant Node_Kind := Nkind (N);
14681 if Kind = N_Simple_Return_Statement
14683 Kind = N_Extended_Return_Statement
14685 Kind = N_Goto_Statement
14687 Kind = N_Raise_Statement
14689 Kind = N_Requeue_Statement
14693 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
14694 and then No (Condition (N))
14698 elsif Kind = N_Procedure_Call_Statement
14699 and then Is_Entity_Name (Name (N))
14700 and then Present (Entity (Name (N)))
14701 and then No_Return (Entity (Name (N)))
14705 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
14717 function Is_True (U : Uint) return Boolean is
14722 --------------------------------------
14723 -- Is_Unchecked_Conversion_Instance --
14724 --------------------------------------
14726 function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is
14730 -- Look for a function whose generic parent is the predefined intrinsic
14731 -- function Unchecked_Conversion, or for one that renames such an
14734 if Ekind (Id) = E_Function then
14735 Par := Parent (Id);
14737 if Nkind (Par) = N_Function_Specification then
14738 Par := Generic_Parent (Par);
14740 if Present (Par) then
14742 Chars (Par) = Name_Unchecked_Conversion
14743 and then Is_Intrinsic_Subprogram (Par)
14744 and then Is_Predefined_File_Name
14745 (Unit_File_Name (Get_Source_Unit (Par)));
14748 Present (Alias (Id))
14749 and then Is_Unchecked_Conversion_Instance (Alias (Id));
14755 end Is_Unchecked_Conversion_Instance;
14757 -------------------------------
14758 -- Is_Universal_Numeric_Type --
14759 -------------------------------
14761 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
14763 return T = Universal_Integer or else T = Universal_Real;
14764 end Is_Universal_Numeric_Type;
14766 ----------------------------
14767 -- Is_Variable_Size_Array --
14768 ----------------------------
14770 function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
14774 pragma Assert (Is_Array_Type (E));
14776 -- Check if some index is initialized with a non-constant value
14778 Idx := First_Index (E);
14779 while Present (Idx) loop
14780 if Nkind (Idx) = N_Range then
14781 if not Is_Constant_Bound (Low_Bound (Idx))
14782 or else not Is_Constant_Bound (High_Bound (Idx))
14788 Idx := Next_Index (Idx);
14792 end Is_Variable_Size_Array;
14794 -----------------------------
14795 -- Is_Variable_Size_Record --
14796 -----------------------------
14798 function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
14800 Comp_Typ : Entity_Id;
14803 pragma Assert (Is_Record_Type (E));
14805 Comp := First_Entity (E);
14806 while Present (Comp) loop
14807 Comp_Typ := Etype (Comp);
14809 -- Recursive call if the record type has discriminants
14811 if Is_Record_Type (Comp_Typ)
14812 and then Has_Discriminants (Comp_Typ)
14813 and then Is_Variable_Size_Record (Comp_Typ)
14817 elsif Is_Array_Type (Comp_Typ)
14818 and then Is_Variable_Size_Array (Comp_Typ)
14823 Next_Entity (Comp);
14827 end Is_Variable_Size_Record;
14833 function Is_Variable
14835 Use_Original_Node : Boolean := True) return Boolean
14837 Orig_Node : Node_Id;
14839 function In_Protected_Function (E : Entity_Id) return Boolean;
14840 -- Within a protected function, the private components of the enclosing
14841 -- protected type are constants. A function nested within a (protected)
14842 -- procedure is not itself protected. Within the body of a protected
14843 -- function the current instance of the protected type is a constant.
14845 function Is_Variable_Prefix (P : Node_Id) return Boolean;
14846 -- Prefixes can involve implicit dereferences, in which case we must
14847 -- test for the case of a reference of a constant access type, which can
14848 -- can never be a variable.
14850 ---------------------------
14851 -- In_Protected_Function --
14852 ---------------------------
14854 function In_Protected_Function (E : Entity_Id) return Boolean is
14859 -- E is the current instance of a type
14861 if Is_Type (E) then
14870 if not Is_Protected_Type (Prot) then
14874 S := Current_Scope;
14875 while Present (S) and then S /= Prot loop
14876 if Ekind (S) = E_Function and then Scope (S) = Prot then
14885 end In_Protected_Function;
14887 ------------------------
14888 -- Is_Variable_Prefix --
14889 ------------------------
14891 function Is_Variable_Prefix (P : Node_Id) return Boolean is
14893 if Is_Access_Type (Etype (P)) then
14894 return not Is_Access_Constant (Root_Type (Etype (P)));
14896 -- For the case of an indexed component whose prefix has a packed
14897 -- array type, the prefix has been rewritten into a type conversion.
14898 -- Determine variable-ness from the converted expression.
14900 elsif Nkind (P) = N_Type_Conversion
14901 and then not Comes_From_Source (P)
14902 and then Is_Array_Type (Etype (P))
14903 and then Is_Packed (Etype (P))
14905 return Is_Variable (Expression (P));
14908 return Is_Variable (P);
14910 end Is_Variable_Prefix;
14912 -- Start of processing for Is_Variable
14915 -- Special check, allow x'Deref(expr) as a variable
14917 if Nkind (N) = N_Attribute_Reference
14918 and then Attribute_Name (N) = Name_Deref
14923 -- Check if we perform the test on the original node since this may be a
14924 -- test of syntactic categories which must not be disturbed by whatever
14925 -- rewriting might have occurred. For example, an aggregate, which is
14926 -- certainly NOT a variable, could be turned into a variable by
14929 if Use_Original_Node then
14930 Orig_Node := Original_Node (N);
14935 -- Definitely OK if Assignment_OK is set. Since this is something that
14936 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
14938 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
14941 -- Normally we go to the original node, but there is one exception where
14942 -- we use the rewritten node, namely when it is an explicit dereference.
14943 -- The generated code may rewrite a prefix which is an access type with
14944 -- an explicit dereference. The dereference is a variable, even though
14945 -- the original node may not be (since it could be a constant of the
14948 -- In Ada 2005 we have a further case to consider: the prefix may be a
14949 -- function call given in prefix notation. The original node appears to
14950 -- be a selected component, but we need to examine the call.
14952 elsif Nkind (N) = N_Explicit_Dereference
14953 and then Nkind (Orig_Node) /= N_Explicit_Dereference
14954 and then Present (Etype (Orig_Node))
14955 and then Is_Access_Type (Etype (Orig_Node))
14957 -- Note that if the prefix is an explicit dereference that does not
14958 -- come from source, we must check for a rewritten function call in
14959 -- prefixed notation before other forms of rewriting, to prevent a
14963 (Nkind (Orig_Node) = N_Function_Call
14964 and then not Is_Access_Constant (Etype (Prefix (N))))
14966 Is_Variable_Prefix (Original_Node (Prefix (N)));
14968 -- in Ada 2012, the dereference may have been added for a type with
14969 -- a declared implicit dereference aspect. Check that it is not an
14970 -- access to constant.
14972 elsif Nkind (N) = N_Explicit_Dereference
14973 and then Present (Etype (Orig_Node))
14974 and then Ada_Version >= Ada_2012
14975 and then Has_Implicit_Dereference (Etype (Orig_Node))
14977 return not Is_Access_Constant (Etype (Prefix (N)));
14979 -- A function call is never a variable
14981 elsif Nkind (N) = N_Function_Call then
14984 -- All remaining checks use the original node
14986 elsif Is_Entity_Name (Orig_Node)
14987 and then Present (Entity (Orig_Node))
14990 E : constant Entity_Id := Entity (Orig_Node);
14991 K : constant Entity_Kind := Ekind (E);
14994 return (K = E_Variable
14995 and then Nkind (Parent (E)) /= N_Exception_Handler)
14996 or else (K = E_Component
14997 and then not In_Protected_Function (E))
14998 or else K = E_Out_Parameter
14999 or else K = E_In_Out_Parameter
15000 or else K = E_Generic_In_Out_Parameter
15002 -- Current instance of type. If this is a protected type, check
15003 -- we are not within the body of one of its protected functions.
15005 or else (Is_Type (E)
15006 and then In_Open_Scopes (E)
15007 and then not In_Protected_Function (E))
15009 or else (Is_Incomplete_Or_Private_Type (E)
15010 and then In_Open_Scopes (Full_View (E)));
15014 case Nkind (Orig_Node) is
15015 when N_Indexed_Component | N_Slice =>
15016 return Is_Variable_Prefix (Prefix (Orig_Node));
15018 when N_Selected_Component =>
15019 return (Is_Variable (Selector_Name (Orig_Node))
15020 and then Is_Variable_Prefix (Prefix (Orig_Node)))
15022 (Nkind (N) = N_Expanded_Name
15023 and then Scope (Entity (N)) = Entity (Prefix (N)));
15025 -- For an explicit dereference, the type of the prefix cannot
15026 -- be an access to constant or an access to subprogram.
15028 when N_Explicit_Dereference =>
15030 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
15032 return Is_Access_Type (Typ)
15033 and then not Is_Access_Constant (Root_Type (Typ))
15034 and then Ekind (Typ) /= E_Access_Subprogram_Type;
15037 -- The type conversion is the case where we do not deal with the
15038 -- context dependent special case of an actual parameter. Thus
15039 -- the type conversion is only considered a variable for the
15040 -- purposes of this routine if the target type is tagged. However,
15041 -- a type conversion is considered to be a variable if it does not
15042 -- come from source (this deals for example with the conversions
15043 -- of expressions to their actual subtypes).
15045 when N_Type_Conversion =>
15046 return Is_Variable (Expression (Orig_Node))
15048 (not Comes_From_Source (Orig_Node)
15050 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
15052 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
15054 -- GNAT allows an unchecked type conversion as a variable. This
15055 -- only affects the generation of internal expanded code, since
15056 -- calls to instantiations of Unchecked_Conversion are never
15057 -- considered variables (since they are function calls).
15059 when N_Unchecked_Type_Conversion =>
15060 return Is_Variable (Expression (Orig_Node));
15068 ------------------------------
15069 -- Is_Verifiable_DIC_Pragma --
15070 ------------------------------
15072 function Is_Verifiable_DIC_Pragma (Prag : Node_Id) return Boolean is
15073 Args : constant List_Id := Pragma_Argument_Associations (Prag);
15076 -- To qualify as verifiable, a DIC pragma must have a non-null argument
15080 and then Nkind (Get_Pragma_Arg (First (Args))) /= N_Null;
15081 end Is_Verifiable_DIC_Pragma;
15083 ---------------------------
15084 -- Is_Visibly_Controlled --
15085 ---------------------------
15087 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
15088 Root : constant Entity_Id := Root_Type (T);
15090 return Chars (Scope (Root)) = Name_Finalization
15091 and then Chars (Scope (Scope (Root))) = Name_Ada
15092 and then Scope (Scope (Scope (Root))) = Standard_Standard;
15093 end Is_Visibly_Controlled;
15095 --------------------------
15096 -- Is_Volatile_Function --
15097 --------------------------
15099 function Is_Volatile_Function (Func_Id : Entity_Id) return Boolean is
15101 pragma Assert (Ekind_In (Func_Id, E_Function, E_Generic_Function));
15103 -- A function declared within a protected type is volatile
15105 if Is_Protected_Type (Scope (Func_Id)) then
15108 -- An instance of Ada.Unchecked_Conversion is a volatile function if
15109 -- either the source or the target are effectively volatile.
15111 elsif Is_Unchecked_Conversion_Instance (Func_Id)
15112 and then Has_Effectively_Volatile_Profile (Func_Id)
15116 -- Otherwise the function is treated as volatile if it is subject to
15117 -- enabled pragma Volatile_Function.
15121 Is_Enabled_Pragma (Get_Pragma (Func_Id, Pragma_Volatile_Function));
15123 end Is_Volatile_Function;
15125 ------------------------
15126 -- Is_Volatile_Object --
15127 ------------------------
15129 function Is_Volatile_Object (N : Node_Id) return Boolean is
15131 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
15132 -- If prefix is an implicit dereference, examine designated type
15134 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
15135 -- Determines if given object has volatile components
15137 ------------------------
15138 -- Is_Volatile_Prefix --
15139 ------------------------
15141 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
15142 Typ : constant Entity_Id := Etype (N);
15145 if Is_Access_Type (Typ) then
15147 Dtyp : constant Entity_Id := Designated_Type (Typ);
15150 return Is_Volatile (Dtyp)
15151 or else Has_Volatile_Components (Dtyp);
15155 return Object_Has_Volatile_Components (N);
15157 end Is_Volatile_Prefix;
15159 ------------------------------------
15160 -- Object_Has_Volatile_Components --
15161 ------------------------------------
15163 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
15164 Typ : constant Entity_Id := Etype (N);
15167 if Is_Volatile (Typ)
15168 or else Has_Volatile_Components (Typ)
15172 elsif Is_Entity_Name (N)
15173 and then (Has_Volatile_Components (Entity (N))
15174 or else Is_Volatile (Entity (N)))
15178 elsif Nkind (N) = N_Indexed_Component
15179 or else Nkind (N) = N_Selected_Component
15181 return Is_Volatile_Prefix (Prefix (N));
15186 end Object_Has_Volatile_Components;
15188 -- Start of processing for Is_Volatile_Object
15191 if Nkind (N) = N_Defining_Identifier then
15192 return Is_Volatile (N) or else Is_Volatile (Etype (N));
15194 elsif Nkind (N) = N_Expanded_Name then
15195 return Is_Volatile_Object (Entity (N));
15197 elsif Is_Volatile (Etype (N))
15198 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
15202 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component)
15203 and then Is_Volatile_Prefix (Prefix (N))
15207 elsif Nkind (N) = N_Selected_Component
15208 and then Is_Volatile (Entity (Selector_Name (N)))
15215 end Is_Volatile_Object;
15217 ---------------------------
15218 -- Itype_Has_Declaration --
15219 ---------------------------
15221 function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
15223 pragma Assert (Is_Itype (Id));
15224 return Present (Parent (Id))
15225 and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
15226 N_Subtype_Declaration)
15227 and then Defining_Entity (Parent (Id)) = Id;
15228 end Itype_Has_Declaration;
15230 -------------------------
15231 -- Kill_Current_Values --
15232 -------------------------
15234 procedure Kill_Current_Values
15236 Last_Assignment_Only : Boolean := False)
15239 if Is_Assignable (Ent) then
15240 Set_Last_Assignment (Ent, Empty);
15243 if Is_Object (Ent) then
15244 if not Last_Assignment_Only then
15246 Set_Current_Value (Ent, Empty);
15248 -- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
15249 -- for a constant. Once the constant is elaborated, its value is
15250 -- not changed, therefore the associated flags that describe the
15251 -- value should not be modified either.
15253 if Ekind (Ent) = E_Constant then
15256 -- Non-constant entities
15259 if not Can_Never_Be_Null (Ent) then
15260 Set_Is_Known_Non_Null (Ent, False);
15263 Set_Is_Known_Null (Ent, False);
15265 -- Reset the Is_Known_Valid flag unless the type is always
15266 -- valid. This does not apply to a loop parameter because its
15267 -- bounds are defined by the loop header and therefore always
15270 if not Is_Known_Valid (Etype (Ent))
15271 and then Ekind (Ent) /= E_Loop_Parameter
15273 Set_Is_Known_Valid (Ent, False);
15278 end Kill_Current_Values;
15280 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
15283 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
15284 -- Clear current value for entity E and all entities chained to E
15286 ------------------------------------------
15287 -- Kill_Current_Values_For_Entity_Chain --
15288 ------------------------------------------
15290 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
15294 while Present (Ent) loop
15295 Kill_Current_Values (Ent, Last_Assignment_Only);
15298 end Kill_Current_Values_For_Entity_Chain;
15300 -- Start of processing for Kill_Current_Values
15303 -- Kill all saved checks, a special case of killing saved values
15305 if not Last_Assignment_Only then
15309 -- Loop through relevant scopes, which includes the current scope and
15310 -- any parent scopes if the current scope is a block or a package.
15312 S := Current_Scope;
15315 -- Clear current values of all entities in current scope
15317 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
15319 -- If scope is a package, also clear current values of all private
15320 -- entities in the scope.
15322 if Is_Package_Or_Generic_Package (S)
15323 or else Is_Concurrent_Type (S)
15325 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
15328 -- If this is a not a subprogram, deal with parents
15330 if not Is_Subprogram (S) then
15332 exit Scope_Loop when S = Standard_Standard;
15336 end loop Scope_Loop;
15337 end Kill_Current_Values;
15339 --------------------------
15340 -- Kill_Size_Check_Code --
15341 --------------------------
15343 procedure Kill_Size_Check_Code (E : Entity_Id) is
15345 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
15346 and then Present (Size_Check_Code (E))
15348 Remove (Size_Check_Code (E));
15349 Set_Size_Check_Code (E, Empty);
15351 end Kill_Size_Check_Code;
15353 --------------------------
15354 -- Known_To_Be_Assigned --
15355 --------------------------
15357 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
15358 P : constant Node_Id := Parent (N);
15363 -- Test left side of assignment
15365 when N_Assignment_Statement =>
15366 return N = Name (P);
15368 -- Function call arguments are never lvalues
15370 when N_Function_Call =>
15373 -- Positional parameter for procedure or accept call
15375 when N_Procedure_Call_Statement |
15384 Proc := Get_Subprogram_Entity (P);
15390 -- If we are not a list member, something is strange, so
15391 -- be conservative and return False.
15393 if not Is_List_Member (N) then
15397 -- We are going to find the right formal by stepping forward
15398 -- through the formals, as we step backwards in the actuals.
15400 Form := First_Formal (Proc);
15403 -- If no formal, something is weird, so be conservative
15404 -- and return False.
15411 exit when No (Act);
15412 Next_Formal (Form);
15415 return Ekind (Form) /= E_In_Parameter;
15418 -- Named parameter for procedure or accept call
15420 when N_Parameter_Association =>
15426 Proc := Get_Subprogram_Entity (Parent (P));
15432 -- Loop through formals to find the one that matches
15434 Form := First_Formal (Proc);
15436 -- If no matching formal, that's peculiar, some kind of
15437 -- previous error, so return False to be conservative.
15438 -- Actually this also happens in legal code in the case
15439 -- where P is a parameter association for an Extra_Formal???
15445 -- Else test for match
15447 if Chars (Form) = Chars (Selector_Name (P)) then
15448 return Ekind (Form) /= E_In_Parameter;
15451 Next_Formal (Form);
15455 -- Test for appearing in a conversion that itself appears
15456 -- in an lvalue context, since this should be an lvalue.
15458 when N_Type_Conversion =>
15459 return Known_To_Be_Assigned (P);
15461 -- All other references are definitely not known to be modifications
15467 end Known_To_Be_Assigned;
15469 ---------------------------
15470 -- Last_Source_Statement --
15471 ---------------------------
15473 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
15477 N := Last (Statements (HSS));
15478 while Present (N) loop
15479 exit when Comes_From_Source (N);
15484 end Last_Source_Statement;
15486 ----------------------------------
15487 -- Matching_Static_Array_Bounds --
15488 ----------------------------------
15490 function Matching_Static_Array_Bounds
15492 R_Typ : Node_Id) return Boolean
15494 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
15495 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
15507 if L_Ndims /= R_Ndims then
15511 -- Unconstrained types do not have static bounds
15513 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
15517 -- First treat specially the first dimension, as the lower bound and
15518 -- length of string literals are not stored like those of arrays.
15520 if Ekind (L_Typ) = E_String_Literal_Subtype then
15521 L_Low := String_Literal_Low_Bound (L_Typ);
15522 L_Len := String_Literal_Length (L_Typ);
15524 L_Index := First_Index (L_Typ);
15525 Get_Index_Bounds (L_Index, L_Low, L_High);
15527 if Is_OK_Static_Expression (L_Low)
15529 Is_OK_Static_Expression (L_High)
15531 if Expr_Value (L_High) < Expr_Value (L_Low) then
15534 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
15541 if Ekind (R_Typ) = E_String_Literal_Subtype then
15542 R_Low := String_Literal_Low_Bound (R_Typ);
15543 R_Len := String_Literal_Length (R_Typ);
15545 R_Index := First_Index (R_Typ);
15546 Get_Index_Bounds (R_Index, R_Low, R_High);
15548 if Is_OK_Static_Expression (R_Low)
15550 Is_OK_Static_Expression (R_High)
15552 if Expr_Value (R_High) < Expr_Value (R_Low) then
15555 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
15562 if (Is_OK_Static_Expression (L_Low)
15564 Is_OK_Static_Expression (R_Low))
15565 and then Expr_Value (L_Low) = Expr_Value (R_Low)
15566 and then L_Len = R_Len
15573 -- Then treat all other dimensions
15575 for Indx in 2 .. L_Ndims loop
15579 Get_Index_Bounds (L_Index, L_Low, L_High);
15580 Get_Index_Bounds (R_Index, R_Low, R_High);
15582 if (Is_OK_Static_Expression (L_Low) and then
15583 Is_OK_Static_Expression (L_High) and then
15584 Is_OK_Static_Expression (R_Low) and then
15585 Is_OK_Static_Expression (R_High))
15586 and then (Expr_Value (L_Low) = Expr_Value (R_Low)
15588 Expr_Value (L_High) = Expr_Value (R_High))
15596 -- If we fall through the loop, all indexes matched
15599 end Matching_Static_Array_Bounds;
15601 -------------------
15602 -- May_Be_Lvalue --
15603 -------------------
15605 function May_Be_Lvalue (N : Node_Id) return Boolean is
15606 P : constant Node_Id := Parent (N);
15611 -- Test left side of assignment
15613 when N_Assignment_Statement =>
15614 return N = Name (P);
15616 -- Test prefix of component or attribute. Note that the prefix of an
15617 -- explicit or implicit dereference cannot be an l-value. In the case
15618 -- of a 'Read attribute, the reference can be an actual in the
15619 -- argument list of the attribute.
15621 when N_Attribute_Reference =>
15622 return (N = Prefix (P)
15623 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P)))
15625 Attribute_Name (P) = Name_Read;
15627 -- For an expanded name, the name is an lvalue if the expanded name
15628 -- is an lvalue, but the prefix is never an lvalue, since it is just
15629 -- the scope where the name is found.
15631 when N_Expanded_Name =>
15632 if N = Prefix (P) then
15633 return May_Be_Lvalue (P);
15638 -- For a selected component A.B, A is certainly an lvalue if A.B is.
15639 -- B is a little interesting, if we have A.B := 3, there is some
15640 -- discussion as to whether B is an lvalue or not, we choose to say
15641 -- it is. Note however that A is not an lvalue if it is of an access
15642 -- type since this is an implicit dereference.
15644 when N_Selected_Component =>
15646 and then Present (Etype (N))
15647 and then Is_Access_Type (Etype (N))
15651 return May_Be_Lvalue (P);
15654 -- For an indexed component or slice, the index or slice bounds is
15655 -- never an lvalue. The prefix is an lvalue if the indexed component
15656 -- or slice is an lvalue, except if it is an access type, where we
15657 -- have an implicit dereference.
15659 when N_Indexed_Component | N_Slice =>
15661 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
15665 return May_Be_Lvalue (P);
15668 -- Prefix of a reference is an lvalue if the reference is an lvalue
15670 when N_Reference =>
15671 return May_Be_Lvalue (P);
15673 -- Prefix of explicit dereference is never an lvalue
15675 when N_Explicit_Dereference =>
15678 -- Positional parameter for subprogram, entry, or accept call.
15679 -- In older versions of Ada function call arguments are never
15680 -- lvalues. In Ada 2012 functions can have in-out parameters.
15682 when N_Subprogram_Call |
15683 N_Entry_Call_Statement |
15686 if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
15690 -- The following mechanism is clumsy and fragile. A single flag
15691 -- set in Resolve_Actuals would be preferable ???
15699 Proc := Get_Subprogram_Entity (P);
15705 -- If we are not a list member, something is strange, so be
15706 -- conservative and return True.
15708 if not Is_List_Member (N) then
15712 -- We are going to find the right formal by stepping forward
15713 -- through the formals, as we step backwards in the actuals.
15715 Form := First_Formal (Proc);
15718 -- If no formal, something is weird, so be conservative and
15726 exit when No (Act);
15727 Next_Formal (Form);
15730 return Ekind (Form) /= E_In_Parameter;
15733 -- Named parameter for procedure or accept call
15735 when N_Parameter_Association =>
15741 Proc := Get_Subprogram_Entity (Parent (P));
15747 -- Loop through formals to find the one that matches
15749 Form := First_Formal (Proc);
15751 -- If no matching formal, that's peculiar, some kind of
15752 -- previous error, so return True to be conservative.
15753 -- Actually happens with legal code for an unresolved call
15754 -- where we may get the wrong homonym???
15760 -- Else test for match
15762 if Chars (Form) = Chars (Selector_Name (P)) then
15763 return Ekind (Form) /= E_In_Parameter;
15766 Next_Formal (Form);
15770 -- Test for appearing in a conversion that itself appears in an
15771 -- lvalue context, since this should be an lvalue.
15773 when N_Type_Conversion =>
15774 return May_Be_Lvalue (P);
15776 -- Test for appearance in object renaming declaration
15778 when N_Object_Renaming_Declaration =>
15781 -- All other references are definitely not lvalues
15789 -----------------------
15790 -- Mark_Coextensions --
15791 -----------------------
15793 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
15794 Is_Dynamic : Boolean;
15795 -- Indicates whether the context causes nested coextensions to be
15796 -- dynamic or static
15798 function Mark_Allocator (N : Node_Id) return Traverse_Result;
15799 -- Recognize an allocator node and label it as a dynamic coextension
15801 --------------------
15802 -- Mark_Allocator --
15803 --------------------
15805 function Mark_Allocator (N : Node_Id) return Traverse_Result is
15807 if Nkind (N) = N_Allocator then
15809 Set_Is_Dynamic_Coextension (N);
15811 -- If the allocator expression is potentially dynamic, it may
15812 -- be expanded out of order and require dynamic allocation
15813 -- anyway, so we treat the coextension itself as dynamic.
15814 -- Potential optimization ???
15816 elsif Nkind (Expression (N)) = N_Qualified_Expression
15817 and then Nkind (Expression (Expression (N))) = N_Op_Concat
15819 Set_Is_Dynamic_Coextension (N);
15821 Set_Is_Static_Coextension (N);
15826 end Mark_Allocator;
15828 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
15830 -- Start of processing for Mark_Coextensions
15833 -- An allocator that appears on the right-hand side of an assignment is
15834 -- treated as a potentially dynamic coextension when the right-hand side
15835 -- is an allocator or a qualified expression.
15837 -- Obj := new ...'(new Coextension ...);
15839 if Nkind (Context_Nod) = N_Assignment_Statement then
15841 Nkind_In (Expression (Context_Nod), N_Allocator,
15842 N_Qualified_Expression);
15844 -- An allocator that appears within the expression of a simple return
15845 -- statement is treated as a potentially dynamic coextension when the
15846 -- expression is either aggregate, allocator, or qualified expression.
15848 -- return (new Coextension ...);
15849 -- return new ...'(new Coextension ...);
15851 elsif Nkind (Context_Nod) = N_Simple_Return_Statement then
15853 Nkind_In (Expression (Context_Nod), N_Aggregate,
15855 N_Qualified_Expression);
15857 -- An alloctor that appears within the initialization expression of an
15858 -- object declaration is considered a potentially dynamic coextension
15859 -- when the initialization expression is an allocator or a qualified
15862 -- Obj : ... := new ...'(new Coextension ...);
15864 -- A similar case arises when the object declaration is part of an
15865 -- extended return statement.
15867 -- return Obj : ... := new ...'(new Coextension ...);
15868 -- return Obj : ... := (new Coextension ...);
15870 elsif Nkind (Context_Nod) = N_Object_Declaration then
15872 Nkind_In (Root_Nod, N_Allocator, N_Qualified_Expression)
15874 Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
15876 -- This routine should not be called with constructs that cannot contain
15880 raise Program_Error;
15883 Mark_Allocators (Root_Nod);
15884 end Mark_Coextensions;
15886 ----------------------
15887 -- Needs_One_Actual --
15888 ----------------------
15890 function Needs_One_Actual (E : Entity_Id) return Boolean is
15891 Formal : Entity_Id;
15894 -- Ada 2005 or later, and formals present
15896 if Ada_Version >= Ada_2005 and then Present (First_Formal (E)) then
15897 Formal := Next_Formal (First_Formal (E));
15898 while Present (Formal) loop
15899 if No (Default_Value (Formal)) then
15903 Next_Formal (Formal);
15908 -- Ada 83/95 or no formals
15913 end Needs_One_Actual;
15915 ------------------------
15916 -- New_Copy_List_Tree --
15917 ------------------------
15919 function New_Copy_List_Tree (List : List_Id) return List_Id is
15924 if List = No_List then
15931 while Present (E) loop
15932 Append (New_Copy_Tree (E), NL);
15938 end New_Copy_List_Tree;
15940 --------------------------------------------------
15941 -- New_Copy_Tree Auxiliary Data and Subprograms --
15942 --------------------------------------------------
15944 use Atree.Unchecked_Access;
15945 use Atree_Private_Part;
15947 -- Our approach here requires a two pass traversal of the tree. The
15948 -- first pass visits all nodes that eventually will be copied looking
15949 -- for defining Itypes. If any defining Itypes are found, then they are
15950 -- copied, and an entry is added to the replacement map. In the second
15951 -- phase, the tree is copied, using the replacement map to replace any
15952 -- Itype references within the copied tree.
15954 -- The following hash tables are used if the Map supplied has more
15955 -- than hash threshold entries to speed up access to the map. If
15956 -- there are fewer entries, then the map is searched sequentially
15957 -- (because setting up a hash table for only a few entries takes
15958 -- more time than it saves.
15960 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
15961 -- Hash function used for hash operations
15963 -------------------
15964 -- New_Copy_Hash --
15965 -------------------
15967 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
15969 return Nat (E) mod (NCT_Header_Num'Last + 1);
15976 -- The hash table NCT_Assoc associates old entities in the table
15977 -- with their corresponding new entities (i.e. the pairs of entries
15978 -- presented in the original Map argument are Key-Element pairs).
15980 package NCT_Assoc is new Simple_HTable (
15981 Header_Num => NCT_Header_Num,
15982 Element => Entity_Id,
15983 No_Element => Empty,
15985 Hash => New_Copy_Hash,
15986 Equal => Types."=");
15988 ---------------------
15989 -- NCT_Itype_Assoc --
15990 ---------------------
15992 -- The hash table NCT_Itype_Assoc contains entries only for those
15993 -- old nodes which have a non-empty Associated_Node_For_Itype set.
15994 -- The key is the associated node, and the element is the new node
15995 -- itself (NOT the associated node for the new node).
15997 package NCT_Itype_Assoc is new Simple_HTable (
15998 Header_Num => NCT_Header_Num,
15999 Element => Entity_Id,
16000 No_Element => Empty,
16002 Hash => New_Copy_Hash,
16003 Equal => Types."=");
16005 -------------------
16006 -- New_Copy_Tree --
16007 -------------------
16009 function New_Copy_Tree
16011 Map : Elist_Id := No_Elist;
16012 New_Sloc : Source_Ptr := No_Location;
16013 New_Scope : Entity_Id := Empty) return Node_Id
16015 Actual_Map : Elist_Id := Map;
16016 -- This is the actual map for the copy. It is initialized with the
16017 -- given elements, and then enlarged as required for Itypes that are
16018 -- copied during the first phase of the copy operation. The visit
16019 -- procedures add elements to this map as Itypes are encountered.
16020 -- The reason we cannot use Map directly, is that it may well be
16021 -- (and normally is) initialized to No_Elist, and if we have mapped
16022 -- entities, we have to reset it to point to a real Elist.
16024 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
16025 -- Called during second phase to map entities into their corresponding
16026 -- copies using Actual_Map. If the argument is not an entity, or is not
16027 -- in Actual_Map, then it is returned unchanged.
16029 procedure Build_NCT_Hash_Tables;
16030 -- Builds hash tables (number of elements >= threshold value)
16032 function Copy_Elist_With_Replacement
16033 (Old_Elist : Elist_Id) return Elist_Id;
16034 -- Called during second phase to copy element list doing replacements
16036 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
16037 -- Called during the second phase to process a copied Itype. The actual
16038 -- copy happened during the first phase (so that we could make the entry
16039 -- in the mapping), but we still have to deal with the descendants of
16040 -- the copied Itype and copy them where necessary.
16042 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
16043 -- Called during second phase to copy list doing replacements
16045 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
16046 -- Called during second phase to copy node doing replacements
16048 procedure Visit_Elist (E : Elist_Id);
16049 -- Called during first phase to visit all elements of an Elist
16051 procedure Visit_Field (F : Union_Id; N : Node_Id);
16052 -- Visit a single field, recursing to call Visit_Node or Visit_List
16053 -- if the field is a syntactic descendant of the current node (i.e.
16054 -- its parent is Node N).
16056 procedure Visit_Itype (Old_Itype : Entity_Id);
16057 -- Called during first phase to visit subsidiary fields of a defining
16058 -- Itype, and also create a copy and make an entry in the replacement
16059 -- map for the new copy.
16061 procedure Visit_List (L : List_Id);
16062 -- Called during first phase to visit all elements of a List
16064 procedure Visit_Node (N : Node_Or_Entity_Id);
16065 -- Called during first phase to visit a node and all its subtrees
16071 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
16076 if not Has_Extension (N) or else No (Actual_Map) then
16079 elsif NCT_Hash_Tables_Used then
16080 Ent := NCT_Assoc.Get (Entity_Id (N));
16082 if Present (Ent) then
16088 -- No hash table used, do serial search
16091 E := First_Elmt (Actual_Map);
16092 while Present (E) loop
16093 if Node (E) = N then
16094 return Node (Next_Elmt (E));
16096 E := Next_Elmt (Next_Elmt (E));
16104 ---------------------------
16105 -- Build_NCT_Hash_Tables --
16106 ---------------------------
16108 procedure Build_NCT_Hash_Tables is
16112 if NCT_Hash_Table_Setup then
16114 NCT_Itype_Assoc.Reset;
16117 Elmt := First_Elmt (Actual_Map);
16118 while Present (Elmt) loop
16119 Ent := Node (Elmt);
16121 -- Get new entity, and associate old and new
16124 NCT_Assoc.Set (Ent, Node (Elmt));
16126 if Is_Type (Ent) then
16128 Anode : constant Entity_Id :=
16129 Associated_Node_For_Itype (Ent);
16132 if Present (Anode) then
16134 -- Enter a link between the associated node of the
16135 -- old Itype and the new Itype, for updating later
16136 -- when node is copied.
16138 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
16146 NCT_Hash_Tables_Used := True;
16147 NCT_Hash_Table_Setup := True;
16148 end Build_NCT_Hash_Tables;
16150 ---------------------------------
16151 -- Copy_Elist_With_Replacement --
16152 ---------------------------------
16154 function Copy_Elist_With_Replacement
16155 (Old_Elist : Elist_Id) return Elist_Id
16158 New_Elist : Elist_Id;
16161 if No (Old_Elist) then
16165 New_Elist := New_Elmt_List;
16167 M := First_Elmt (Old_Elist);
16168 while Present (M) loop
16169 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
16175 end Copy_Elist_With_Replacement;
16177 ---------------------------------
16178 -- Copy_Itype_With_Replacement --
16179 ---------------------------------
16181 -- This routine exactly parallels its phase one analog Visit_Itype,
16183 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
16185 -- Translate Next_Entity, Scope, and Etype fields, in case they
16186 -- reference entities that have been mapped into copies.
16188 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
16189 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
16191 if Present (New_Scope) then
16192 Set_Scope (New_Itype, New_Scope);
16194 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
16197 -- Copy referenced fields
16199 if Is_Discrete_Type (New_Itype) then
16200 Set_Scalar_Range (New_Itype,
16201 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
16203 elsif Has_Discriminants (Base_Type (New_Itype)) then
16204 Set_Discriminant_Constraint (New_Itype,
16205 Copy_Elist_With_Replacement
16206 (Discriminant_Constraint (New_Itype)));
16208 elsif Is_Array_Type (New_Itype) then
16209 if Present (First_Index (New_Itype)) then
16210 Set_First_Index (New_Itype,
16211 First (Copy_List_With_Replacement
16212 (List_Containing (First_Index (New_Itype)))));
16215 if Is_Packed (New_Itype) then
16216 Set_Packed_Array_Impl_Type (New_Itype,
16217 Copy_Node_With_Replacement
16218 (Packed_Array_Impl_Type (New_Itype)));
16221 end Copy_Itype_With_Replacement;
16223 --------------------------------
16224 -- Copy_List_With_Replacement --
16225 --------------------------------
16227 function Copy_List_With_Replacement
16228 (Old_List : List_Id) return List_Id
16230 New_List : List_Id;
16234 if Old_List = No_List then
16238 New_List := Empty_List;
16240 E := First (Old_List);
16241 while Present (E) loop
16242 Append (Copy_Node_With_Replacement (E), New_List);
16248 end Copy_List_With_Replacement;
16250 --------------------------------
16251 -- Copy_Node_With_Replacement --
16252 --------------------------------
16254 function Copy_Node_With_Replacement
16255 (Old_Node : Node_Id) return Node_Id
16257 New_Node : Node_Id;
16259 procedure Adjust_Named_Associations
16260 (Old_Node : Node_Id;
16261 New_Node : Node_Id);
16262 -- If a call node has named associations, these are chained through
16263 -- the First_Named_Actual, Next_Named_Actual links. These must be
16264 -- propagated separately to the new parameter list, because these
16265 -- are not syntactic fields.
16267 function Copy_Field_With_Replacement
16268 (Field : Union_Id) return Union_Id;
16269 -- Given Field, which is a field of Old_Node, return a copy of it
16270 -- if it is a syntactic field (i.e. its parent is Node), setting
16271 -- the parent of the copy to poit to New_Node. Otherwise returns
16272 -- the field (possibly mapped if it is an entity).
16274 -------------------------------
16275 -- Adjust_Named_Associations --
16276 -------------------------------
16278 procedure Adjust_Named_Associations
16279 (Old_Node : Node_Id;
16280 New_Node : Node_Id)
16285 Old_Next : Node_Id;
16286 New_Next : Node_Id;
16289 Old_E := First (Parameter_Associations (Old_Node));
16290 New_E := First (Parameter_Associations (New_Node));
16291 while Present (Old_E) loop
16292 if Nkind (Old_E) = N_Parameter_Association
16293 and then Present (Next_Named_Actual (Old_E))
16295 if First_Named_Actual (Old_Node)
16296 = Explicit_Actual_Parameter (Old_E)
16298 Set_First_Named_Actual
16299 (New_Node, Explicit_Actual_Parameter (New_E));
16302 -- Now scan parameter list from the beginning,to locate
16303 -- next named actual, which can be out of order.
16305 Old_Next := First (Parameter_Associations (Old_Node));
16306 New_Next := First (Parameter_Associations (New_Node));
16308 while Nkind (Old_Next) /= N_Parameter_Association
16309 or else Explicit_Actual_Parameter (Old_Next) /=
16310 Next_Named_Actual (Old_E)
16316 Set_Next_Named_Actual
16317 (New_E, Explicit_Actual_Parameter (New_Next));
16323 end Adjust_Named_Associations;
16325 ---------------------------------
16326 -- Copy_Field_With_Replacement --
16327 ---------------------------------
16329 function Copy_Field_With_Replacement
16330 (Field : Union_Id) return Union_Id
16333 if Field = Union_Id (Empty) then
16336 elsif Field in Node_Range then
16338 Old_N : constant Node_Id := Node_Id (Field);
16342 -- If syntactic field, as indicated by the parent pointer
16343 -- being set, then copy the referenced node recursively.
16345 if Parent (Old_N) = Old_Node then
16346 New_N := Copy_Node_With_Replacement (Old_N);
16348 if New_N /= Old_N then
16349 Set_Parent (New_N, New_Node);
16352 -- For semantic fields, update possible entity reference
16353 -- from the replacement map.
16356 New_N := Assoc (Old_N);
16359 return Union_Id (New_N);
16362 elsif Field in List_Range then
16364 Old_L : constant List_Id := List_Id (Field);
16368 -- If syntactic field, as indicated by the parent pointer,
16369 -- then recursively copy the entire referenced list.
16371 if Parent (Old_L) = Old_Node then
16372 New_L := Copy_List_With_Replacement (Old_L);
16373 Set_Parent (New_L, New_Node);
16375 -- For semantic list, just returned unchanged
16381 return Union_Id (New_L);
16384 -- Anything other than a list or a node is returned unchanged
16389 end Copy_Field_With_Replacement;
16391 -- Start of processing for Copy_Node_With_Replacement
16394 if Old_Node <= Empty_Or_Error then
16397 elsif Has_Extension (Old_Node) then
16398 return Assoc (Old_Node);
16401 New_Node := New_Copy (Old_Node);
16403 -- If the node we are copying is the associated node of a
16404 -- previously copied Itype, then adjust the associated node
16405 -- of the copy of that Itype accordingly.
16407 if Present (Actual_Map) then
16413 -- Case of hash table used
16415 if NCT_Hash_Tables_Used then
16416 Ent := NCT_Itype_Assoc.Get (Old_Node);
16418 if Present (Ent) then
16419 Set_Associated_Node_For_Itype (Ent, New_Node);
16422 -- Case of no hash table used
16425 E := First_Elmt (Actual_Map);
16426 while Present (E) loop
16427 if Is_Itype (Node (E))
16429 Old_Node = Associated_Node_For_Itype (Node (E))
16431 Set_Associated_Node_For_Itype
16432 (Node (Next_Elmt (E)), New_Node);
16435 E := Next_Elmt (Next_Elmt (E));
16441 -- Recursively copy descendants
16444 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
16446 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
16448 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
16450 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
16452 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
16454 -- Adjust Sloc of new node if necessary
16456 if New_Sloc /= No_Location then
16457 Set_Sloc (New_Node, New_Sloc);
16459 -- If we adjust the Sloc, then we are essentially making a
16460 -- completely new node, so the Comes_From_Source flag should
16461 -- be reset to the proper default value.
16463 Set_Comes_From_Source
16464 (New_Node, Default_Node.Comes_From_Source);
16467 -- If the node is a call and has named associations, set the
16468 -- corresponding links in the copy.
16470 if Nkind_In (Old_Node, N_Entry_Call_Statement,
16472 N_Procedure_Call_Statement)
16473 and then Present (First_Named_Actual (Old_Node))
16475 Adjust_Named_Associations (Old_Node, New_Node);
16478 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
16479 -- The replacement mechanism applies to entities, and is not used
16480 -- here. Eventually we may need a more general graph-copying
16481 -- routine. For now, do a sequential search to find desired node.
16483 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
16484 and then Present (First_Real_Statement (Old_Node))
16487 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
16491 N1 := First (Statements (Old_Node));
16492 N2 := First (Statements (New_Node));
16494 while N1 /= Old_F loop
16499 Set_First_Real_Statement (New_Node, N2);
16504 -- All done, return copied node
16507 end Copy_Node_With_Replacement;
16513 procedure Visit_Elist (E : Elist_Id) is
16516 if Present (E) then
16517 Elmt := First_Elmt (E);
16519 while Elmt /= No_Elmt loop
16520 Visit_Node (Node (Elmt));
16530 procedure Visit_Field (F : Union_Id; N : Node_Id) is
16532 if F = Union_Id (Empty) then
16535 elsif F in Node_Range then
16537 -- Copy node if it is syntactic, i.e. its parent pointer is
16538 -- set to point to the field that referenced it (certain
16539 -- Itypes will also meet this criterion, which is fine, since
16540 -- these are clearly Itypes that do need to be copied, since
16541 -- we are copying their parent.)
16543 if Parent (Node_Id (F)) = N then
16544 Visit_Node (Node_Id (F));
16547 -- Another case, if we are pointing to an Itype, then we want
16548 -- to copy it if its associated node is somewhere in the tree
16551 -- Note: the exclusion of self-referential copies is just an
16552 -- optimization, since the search of the already copied list
16553 -- would catch it, but it is a common case (Etype pointing
16554 -- to itself for an Itype that is a base type).
16556 elsif Has_Extension (Node_Id (F))
16557 and then Is_Itype (Entity_Id (F))
16558 and then Node_Id (F) /= N
16564 P := Associated_Node_For_Itype (Node_Id (F));
16565 while Present (P) loop
16567 Visit_Node (Node_Id (F));
16574 -- An Itype whose parent is not being copied definitely
16575 -- should NOT be copied, since it does not belong in any
16576 -- sense to the copied subtree.
16582 elsif F in List_Range and then Parent (List_Id (F)) = N then
16583 Visit_List (List_Id (F));
16592 procedure Visit_Itype (Old_Itype : Entity_Id) is
16593 New_Itype : Entity_Id;
16598 -- Itypes that describe the designated type of access to subprograms
16599 -- have the structure of subprogram declarations, with signatures,
16600 -- etc. Either we duplicate the signatures completely, or choose to
16601 -- share such itypes, which is fine because their elaboration will
16602 -- have no side effects.
16604 if Ekind (Old_Itype) = E_Subprogram_Type then
16608 New_Itype := New_Copy (Old_Itype);
16610 -- The new Itype has all the attributes of the old one, and
16611 -- we just copy the contents of the entity. However, the back-end
16612 -- needs different names for debugging purposes, so we create a
16613 -- new internal name for it in all cases.
16615 Set_Chars (New_Itype, New_Internal_Name ('T'));
16617 -- If our associated node is an entity that has already been copied,
16618 -- then set the associated node of the copy to point to the right
16619 -- copy. If we have copied an Itype that is itself the associated
16620 -- node of some previously copied Itype, then we set the right
16621 -- pointer in the other direction.
16623 if Present (Actual_Map) then
16625 -- Case of hash tables used
16627 if NCT_Hash_Tables_Used then
16629 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
16631 if Present (Ent) then
16632 Set_Associated_Node_For_Itype (New_Itype, Ent);
16635 Ent := NCT_Itype_Assoc.Get (Old_Itype);
16636 if Present (Ent) then
16637 Set_Associated_Node_For_Itype (Ent, New_Itype);
16639 -- If the hash table has no association for this Itype and
16640 -- its associated node, enter one now.
16643 NCT_Itype_Assoc.Set
16644 (Associated_Node_For_Itype (Old_Itype), New_Itype);
16647 -- Case of hash tables not used
16650 E := First_Elmt (Actual_Map);
16651 while Present (E) loop
16652 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
16653 Set_Associated_Node_For_Itype
16654 (New_Itype, Node (Next_Elmt (E)));
16657 if Is_Type (Node (E))
16658 and then Old_Itype = Associated_Node_For_Itype (Node (E))
16660 Set_Associated_Node_For_Itype
16661 (Node (Next_Elmt (E)), New_Itype);
16664 E := Next_Elmt (Next_Elmt (E));
16669 if Present (Freeze_Node (New_Itype)) then
16670 Set_Is_Frozen (New_Itype, False);
16671 Set_Freeze_Node (New_Itype, Empty);
16674 -- Add new association to map
16676 if No (Actual_Map) then
16677 Actual_Map := New_Elmt_List;
16680 Append_Elmt (Old_Itype, Actual_Map);
16681 Append_Elmt (New_Itype, Actual_Map);
16683 if NCT_Hash_Tables_Used then
16684 NCT_Assoc.Set (Old_Itype, New_Itype);
16687 NCT_Table_Entries := NCT_Table_Entries + 1;
16689 if NCT_Table_Entries > NCT_Hash_Threshold then
16690 Build_NCT_Hash_Tables;
16694 -- If a record subtype is simply copied, the entity list will be
16695 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
16697 if Ekind_In (Old_Itype, E_Record_Subtype, E_Class_Wide_Subtype) then
16698 Set_Cloned_Subtype (New_Itype, Old_Itype);
16701 -- Visit descendants that eventually get copied
16703 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
16705 if Is_Discrete_Type (Old_Itype) then
16706 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
16708 elsif Has_Discriminants (Base_Type (Old_Itype)) then
16709 -- ??? This should involve call to Visit_Field
16710 Visit_Elist (Discriminant_Constraint (Old_Itype));
16712 elsif Is_Array_Type (Old_Itype) then
16713 if Present (First_Index (Old_Itype)) then
16714 Visit_Field (Union_Id (List_Containing
16715 (First_Index (Old_Itype))),
16719 if Is_Packed (Old_Itype) then
16720 Visit_Field (Union_Id (Packed_Array_Impl_Type (Old_Itype)),
16730 procedure Visit_List (L : List_Id) is
16733 if L /= No_List then
16736 while Present (N) loop
16747 procedure Visit_Node (N : Node_Or_Entity_Id) is
16749 -- Start of processing for Visit_Node
16752 -- Handle case of an Itype, which must be copied
16754 if Has_Extension (N) and then Is_Itype (N) then
16756 -- Nothing to do if already in the list. This can happen with an
16757 -- Itype entity that appears more than once in the tree.
16758 -- Note that we do not want to visit descendants in this case.
16760 -- Test for already in list when hash table is used
16762 if NCT_Hash_Tables_Used then
16763 if Present (NCT_Assoc.Get (Entity_Id (N))) then
16767 -- Test for already in list when hash table not used
16773 if Present (Actual_Map) then
16774 E := First_Elmt (Actual_Map);
16775 while Present (E) loop
16776 if Node (E) = N then
16779 E := Next_Elmt (Next_Elmt (E));
16789 -- Visit descendants
16791 Visit_Field (Field1 (N), N);
16792 Visit_Field (Field2 (N), N);
16793 Visit_Field (Field3 (N), N);
16794 Visit_Field (Field4 (N), N);
16795 Visit_Field (Field5 (N), N);
16798 -- Start of processing for New_Copy_Tree
16803 -- See if we should use hash table
16805 if No (Actual_Map) then
16806 NCT_Hash_Tables_Used := False;
16813 NCT_Table_Entries := 0;
16815 Elmt := First_Elmt (Actual_Map);
16816 while Present (Elmt) loop
16817 NCT_Table_Entries := NCT_Table_Entries + 1;
16822 if NCT_Table_Entries > NCT_Hash_Threshold then
16823 Build_NCT_Hash_Tables;
16825 NCT_Hash_Tables_Used := False;
16830 -- Hash table set up if required, now start phase one by visiting
16831 -- top node (we will recursively visit the descendants).
16833 Visit_Node (Source);
16835 -- Now the second phase of the copy can start. First we process
16836 -- all the mapped entities, copying their descendants.
16838 if Present (Actual_Map) then
16841 New_Itype : Entity_Id;
16843 Elmt := First_Elmt (Actual_Map);
16844 while Present (Elmt) loop
16846 New_Itype := Node (Elmt);
16848 if Is_Itype (New_Itype) then
16849 Copy_Itype_With_Replacement (New_Itype);
16856 -- Now we can copy the actual tree
16858 return Copy_Node_With_Replacement (Source);
16861 -------------------------
16862 -- New_External_Entity --
16863 -------------------------
16865 function New_External_Entity
16866 (Kind : Entity_Kind;
16867 Scope_Id : Entity_Id;
16868 Sloc_Value : Source_Ptr;
16869 Related_Id : Entity_Id;
16870 Suffix : Character;
16871 Suffix_Index : Nat := 0;
16872 Prefix : Character := ' ') return Entity_Id
16874 N : constant Entity_Id :=
16875 Make_Defining_Identifier (Sloc_Value,
16877 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
16880 Set_Ekind (N, Kind);
16881 Set_Is_Internal (N, True);
16882 Append_Entity (N, Scope_Id);
16883 Set_Public_Status (N);
16885 if Kind in Type_Kind then
16886 Init_Size_Align (N);
16890 end New_External_Entity;
16892 -------------------------
16893 -- New_Internal_Entity --
16894 -------------------------
16896 function New_Internal_Entity
16897 (Kind : Entity_Kind;
16898 Scope_Id : Entity_Id;
16899 Sloc_Value : Source_Ptr;
16900 Id_Char : Character) return Entity_Id
16902 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
16905 Set_Ekind (N, Kind);
16906 Set_Is_Internal (N, True);
16907 Append_Entity (N, Scope_Id);
16909 if Kind in Type_Kind then
16910 Init_Size_Align (N);
16914 end New_Internal_Entity;
16920 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
16924 -- If we are pointing at a positional parameter, it is a member of a
16925 -- node list (the list of parameters), and the next parameter is the
16926 -- next node on the list, unless we hit a parameter association, then
16927 -- we shift to using the chain whose head is the First_Named_Actual in
16928 -- the parent, and then is threaded using the Next_Named_Actual of the
16929 -- Parameter_Association. All this fiddling is because the original node
16930 -- list is in the textual call order, and what we need is the
16931 -- declaration order.
16933 if Is_List_Member (Actual_Id) then
16934 N := Next (Actual_Id);
16936 if Nkind (N) = N_Parameter_Association then
16937 return First_Named_Actual (Parent (Actual_Id));
16943 return Next_Named_Actual (Parent (Actual_Id));
16947 procedure Next_Actual (Actual_Id : in out Node_Id) is
16949 Actual_Id := Next_Actual (Actual_Id);
16952 -----------------------
16953 -- Normalize_Actuals --
16954 -----------------------
16956 -- Chain actuals according to formals of subprogram. If there are no named
16957 -- associations, the chain is simply the list of Parameter Associations,
16958 -- since the order is the same as the declaration order. If there are named
16959 -- associations, then the First_Named_Actual field in the N_Function_Call
16960 -- or N_Procedure_Call_Statement node points to the Parameter_Association
16961 -- node for the parameter that comes first in declaration order. The
16962 -- remaining named parameters are then chained in declaration order using
16963 -- Next_Named_Actual.
16965 -- This routine also verifies that the number of actuals is compatible with
16966 -- the number and default values of formals, but performs no type checking
16967 -- (type checking is done by the caller).
16969 -- If the matching succeeds, Success is set to True and the caller proceeds
16970 -- with type-checking. If the match is unsuccessful, then Success is set to
16971 -- False, and the caller attempts a different interpretation, if there is
16974 -- If the flag Report is on, the call is not overloaded, and a failure to
16975 -- match can be reported here, rather than in the caller.
16977 procedure Normalize_Actuals
16981 Success : out Boolean)
16983 Actuals : constant List_Id := Parameter_Associations (N);
16984 Actual : Node_Id := Empty;
16985 Formal : Entity_Id;
16986 Last : Node_Id := Empty;
16987 First_Named : Node_Id := Empty;
16990 Formals_To_Match : Integer := 0;
16991 Actuals_To_Match : Integer := 0;
16993 procedure Chain (A : Node_Id);
16994 -- Add named actual at the proper place in the list, using the
16995 -- Next_Named_Actual link.
16997 function Reporting return Boolean;
16998 -- Determines if an error is to be reported. To report an error, we
16999 -- need Report to be True, and also we do not report errors caused
17000 -- by calls to init procs that occur within other init procs. Such
17001 -- errors must always be cascaded errors, since if all the types are
17002 -- declared correctly, the compiler will certainly build decent calls.
17008 procedure Chain (A : Node_Id) is
17012 -- Call node points to first actual in list
17014 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
17017 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
17021 Set_Next_Named_Actual (Last, Empty);
17028 function Reporting return Boolean is
17033 elsif not Within_Init_Proc then
17036 elsif Is_Init_Proc (Entity (Name (N))) then
17044 -- Start of processing for Normalize_Actuals
17047 if Is_Access_Type (S) then
17049 -- The name in the call is a function call that returns an access
17050 -- to subprogram. The designated type has the list of formals.
17052 Formal := First_Formal (Designated_Type (S));
17054 Formal := First_Formal (S);
17057 while Present (Formal) loop
17058 Formals_To_Match := Formals_To_Match + 1;
17059 Next_Formal (Formal);
17062 -- Find if there is a named association, and verify that no positional
17063 -- associations appear after named ones.
17065 if Present (Actuals) then
17066 Actual := First (Actuals);
17069 while Present (Actual)
17070 and then Nkind (Actual) /= N_Parameter_Association
17072 Actuals_To_Match := Actuals_To_Match + 1;
17076 if No (Actual) and Actuals_To_Match = Formals_To_Match then
17078 -- Most common case: positional notation, no defaults
17083 elsif Actuals_To_Match > Formals_To_Match then
17085 -- Too many actuals: will not work
17088 if Is_Entity_Name (Name (N)) then
17089 Error_Msg_N ("too many arguments in call to&", Name (N));
17091 Error_Msg_N ("too many arguments in call", N);
17099 First_Named := Actual;
17101 while Present (Actual) loop
17102 if Nkind (Actual) /= N_Parameter_Association then
17104 ("positional parameters not allowed after named ones", Actual);
17109 Actuals_To_Match := Actuals_To_Match + 1;
17115 if Present (Actuals) then
17116 Actual := First (Actuals);
17119 Formal := First_Formal (S);
17120 while Present (Formal) loop
17122 -- Match the formals in order. If the corresponding actual is
17123 -- positional, nothing to do. Else scan the list of named actuals
17124 -- to find the one with the right name.
17126 if Present (Actual)
17127 and then Nkind (Actual) /= N_Parameter_Association
17130 Actuals_To_Match := Actuals_To_Match - 1;
17131 Formals_To_Match := Formals_To_Match - 1;
17134 -- For named parameters, search the list of actuals to find
17135 -- one that matches the next formal name.
17137 Actual := First_Named;
17139 while Present (Actual) loop
17140 if Chars (Selector_Name (Actual)) = Chars (Formal) then
17143 Actuals_To_Match := Actuals_To_Match - 1;
17144 Formals_To_Match := Formals_To_Match - 1;
17152 if Ekind (Formal) /= E_In_Parameter
17153 or else No (Default_Value (Formal))
17156 if (Comes_From_Source (S)
17157 or else Sloc (S) = Standard_Location)
17158 and then Is_Overloadable (S)
17162 Nkind_In (Parent (N), N_Procedure_Call_Statement,
17164 N_Parameter_Association)
17165 and then Ekind (S) /= E_Function
17167 Set_Etype (N, Etype (S));
17170 Error_Msg_Name_1 := Chars (S);
17171 Error_Msg_Sloc := Sloc (S);
17173 ("missing argument for parameter & "
17174 & "in call to % declared #", N, Formal);
17177 elsif Is_Overloadable (S) then
17178 Error_Msg_Name_1 := Chars (S);
17180 -- Point to type derivation that generated the
17183 Error_Msg_Sloc := Sloc (Parent (S));
17186 ("missing argument for parameter & "
17187 & "in call to % (inherited) #", N, Formal);
17191 ("missing argument for parameter &", N, Formal);
17199 Formals_To_Match := Formals_To_Match - 1;
17204 Next_Formal (Formal);
17207 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
17214 -- Find some superfluous named actual that did not get
17215 -- attached to the list of associations.
17217 Actual := First (Actuals);
17218 while Present (Actual) loop
17219 if Nkind (Actual) = N_Parameter_Association
17220 and then Actual /= Last
17221 and then No (Next_Named_Actual (Actual))
17223 -- A validity check may introduce a copy of a call that
17224 -- includes an extra actual (for example for an unrelated
17225 -- accessibility check). Check that the extra actual matches
17226 -- some extra formal, which must exist already because
17227 -- subprogram must be frozen at this point.
17229 if Present (Extra_Formals (S))
17230 and then not Comes_From_Source (Actual)
17231 and then Nkind (Actual) = N_Parameter_Association
17232 and then Chars (Extra_Formals (S)) =
17233 Chars (Selector_Name (Actual))
17238 ("unmatched actual & in call", Selector_Name (Actual));
17250 end Normalize_Actuals;
17252 --------------------------------
17253 -- Note_Possible_Modification --
17254 --------------------------------
17256 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
17257 Modification_Comes_From_Source : constant Boolean :=
17258 Comes_From_Source (Parent (N));
17264 -- Loop to find referenced entity, if there is one
17270 if Is_Entity_Name (Exp) then
17271 Ent := Entity (Exp);
17273 -- If the entity is missing, it is an undeclared identifier,
17274 -- and there is nothing to annotate.
17280 elsif Nkind (Exp) = N_Explicit_Dereference then
17282 P : constant Node_Id := Prefix (Exp);
17285 -- In formal verification mode, keep track of all reads and
17286 -- writes through explicit dereferences.
17288 if GNATprove_Mode then
17289 SPARK_Specific.Generate_Dereference (N, 'm');
17292 if Nkind (P) = N_Selected_Component
17293 and then Present (Entry_Formal (Entity (Selector_Name (P))))
17295 -- Case of a reference to an entry formal
17297 Ent := Entry_Formal (Entity (Selector_Name (P)));
17299 elsif Nkind (P) = N_Identifier
17300 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
17301 and then Present (Expression (Parent (Entity (P))))
17302 and then Nkind (Expression (Parent (Entity (P)))) =
17305 -- Case of a reference to a value on which side effects have
17308 Exp := Prefix (Expression (Parent (Entity (P))));
17316 elsif Nkind_In (Exp, N_Type_Conversion,
17317 N_Unchecked_Type_Conversion)
17319 Exp := Expression (Exp);
17322 elsif Nkind_In (Exp, N_Slice,
17323 N_Indexed_Component,
17324 N_Selected_Component)
17326 -- Special check, if the prefix is an access type, then return
17327 -- since we are modifying the thing pointed to, not the prefix.
17328 -- When we are expanding, most usually the prefix is replaced
17329 -- by an explicit dereference, and this test is not needed, but
17330 -- in some cases (notably -gnatc mode and generics) when we do
17331 -- not do full expansion, we need this special test.
17333 if Is_Access_Type (Etype (Prefix (Exp))) then
17336 -- Otherwise go to prefix and keep going
17339 Exp := Prefix (Exp);
17343 -- All other cases, not a modification
17349 -- Now look for entity being referenced
17351 if Present (Ent) then
17352 if Is_Object (Ent) then
17353 if Comes_From_Source (Exp)
17354 or else Modification_Comes_From_Source
17356 -- Give warning if pragma unmodified is given and we are
17357 -- sure this is a modification.
17359 if Has_Pragma_Unmodified (Ent) and then Sure then
17361 -- Note that the entity may be present only as a result
17362 -- of pragma Unused.
17364 if Has_Pragma_Unused (Ent) then
17365 Error_Msg_NE ("??pragma Unused given for &!", N, Ent);
17368 ("??pragma Unmodified given for &!", N, Ent);
17372 Set_Never_Set_In_Source (Ent, False);
17375 Set_Is_True_Constant (Ent, False);
17376 Set_Current_Value (Ent, Empty);
17377 Set_Is_Known_Null (Ent, False);
17379 if not Can_Never_Be_Null (Ent) then
17380 Set_Is_Known_Non_Null (Ent, False);
17383 -- Follow renaming chain
17385 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
17386 and then Present (Renamed_Object (Ent))
17388 Exp := Renamed_Object (Ent);
17390 -- If the entity is the loop variable in an iteration over
17391 -- a container, retrieve container expression to indicate
17392 -- possible modification.
17394 if Present (Related_Expression (Ent))
17395 and then Nkind (Parent (Related_Expression (Ent))) =
17396 N_Iterator_Specification
17398 Exp := Original_Node (Related_Expression (Ent));
17403 -- The expression may be the renaming of a subcomponent of an
17404 -- array or container. The assignment to the subcomponent is
17405 -- a modification of the container.
17407 elsif Comes_From_Source (Original_Node (Exp))
17408 and then Nkind_In (Original_Node (Exp), N_Selected_Component,
17409 N_Indexed_Component)
17411 Exp := Prefix (Original_Node (Exp));
17415 -- Generate a reference only if the assignment comes from
17416 -- source. This excludes, for example, calls to a dispatching
17417 -- assignment operation when the left-hand side is tagged. In
17418 -- GNATprove mode, we need those references also on generated
17419 -- code, as these are used to compute the local effects of
17422 if Modification_Comes_From_Source or GNATprove_Mode then
17423 Generate_Reference (Ent, Exp, 'm');
17425 -- If the target of the assignment is the bound variable
17426 -- in an iterator, indicate that the corresponding array
17427 -- or container is also modified.
17429 if Ada_Version >= Ada_2012
17430 and then Nkind (Parent (Ent)) = N_Iterator_Specification
17433 Domain : constant Node_Id := Name (Parent (Ent));
17436 -- TBD : in the full version of the construct, the
17437 -- domain of iteration can be given by an expression.
17439 if Is_Entity_Name (Domain) then
17440 Generate_Reference (Entity (Domain), Exp, 'm');
17441 Set_Is_True_Constant (Entity (Domain), False);
17442 Set_Never_Set_In_Source (Entity (Domain), False);
17451 -- If we are sure this is a modification from source, and we know
17452 -- this modifies a constant, then give an appropriate warning.
17455 and then Modification_Comes_From_Source
17456 and then Overlays_Constant (Ent)
17457 and then Address_Clause_Overlay_Warnings
17460 Addr : constant Node_Id := Address_Clause (Ent);
17465 Find_Overlaid_Entity (Addr, O_Ent, Off);
17467 Error_Msg_Sloc := Sloc (Addr);
17469 ("??constant& may be modified via address clause#",
17480 end Note_Possible_Modification;
17482 --------------------------------------
17483 -- Null_To_Null_Address_Convert_OK --
17484 --------------------------------------
17486 function Null_To_Null_Address_Convert_OK
17488 Typ : Entity_Id := Empty) return Boolean
17491 if not Relaxed_RM_Semantics then
17495 if Nkind (N) = N_Null then
17496 return Present (Typ) and then Is_Descendant_Of_Address (Typ);
17498 elsif Nkind_In (N, N_Op_Eq, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt, N_Op_Ne)
17501 L : constant Node_Id := Left_Opnd (N);
17502 R : constant Node_Id := Right_Opnd (N);
17505 -- We check the Etype of the complementary operand since the
17506 -- N_Null node is not decorated at this stage.
17509 ((Nkind (L) = N_Null
17510 and then Is_Descendant_Of_Address (Etype (R)))
17512 (Nkind (R) = N_Null
17513 and then Is_Descendant_Of_Address (Etype (L))));
17518 end Null_To_Null_Address_Convert_OK;
17520 -------------------------
17521 -- Object_Access_Level --
17522 -------------------------
17524 -- Returns the static accessibility level of the view denoted by Obj. Note
17525 -- that the value returned is the result of a call to Scope_Depth. Only
17526 -- scope depths associated with dynamic scopes can actually be returned.
17527 -- Since only relative levels matter for accessibility checking, the fact
17528 -- that the distance between successive levels of accessibility is not
17529 -- always one is immaterial (invariant: if level(E2) is deeper than
17530 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
17532 function Object_Access_Level (Obj : Node_Id) return Uint is
17533 function Is_Interface_Conversion (N : Node_Id) return Boolean;
17534 -- Determine whether N is a construct of the form
17535 -- Some_Type (Operand._tag'Address)
17536 -- This construct appears in the context of dispatching calls.
17538 function Reference_To (Obj : Node_Id) return Node_Id;
17539 -- An explicit dereference is created when removing side-effects from
17540 -- expressions for constraint checking purposes. In this case a local
17541 -- access type is created for it. The correct access level is that of
17542 -- the original source node. We detect this case by noting that the
17543 -- prefix of the dereference is created by an object declaration whose
17544 -- initial expression is a reference.
17546 -----------------------------
17547 -- Is_Interface_Conversion --
17548 -----------------------------
17550 function Is_Interface_Conversion (N : Node_Id) return Boolean is
17552 return Nkind (N) = N_Unchecked_Type_Conversion
17553 and then Nkind (Expression (N)) = N_Attribute_Reference
17554 and then Attribute_Name (Expression (N)) = Name_Address;
17555 end Is_Interface_Conversion;
17561 function Reference_To (Obj : Node_Id) return Node_Id is
17562 Pref : constant Node_Id := Prefix (Obj);
17564 if Is_Entity_Name (Pref)
17565 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
17566 and then Present (Expression (Parent (Entity (Pref))))
17567 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
17569 return (Prefix (Expression (Parent (Entity (Pref)))));
17579 -- Start of processing for Object_Access_Level
17582 if Nkind (Obj) = N_Defining_Identifier
17583 or else Is_Entity_Name (Obj)
17585 if Nkind (Obj) = N_Defining_Identifier then
17591 if Is_Prival (E) then
17592 E := Prival_Link (E);
17595 -- If E is a type then it denotes a current instance. For this case
17596 -- we add one to the normal accessibility level of the type to ensure
17597 -- that current instances are treated as always being deeper than
17598 -- than the level of any visible named access type (see 3.10.2(21)).
17600 if Is_Type (E) then
17601 return Type_Access_Level (E) + 1;
17603 elsif Present (Renamed_Object (E)) then
17604 return Object_Access_Level (Renamed_Object (E));
17606 -- Similarly, if E is a component of the current instance of a
17607 -- protected type, any instance of it is assumed to be at a deeper
17608 -- level than the type. For a protected object (whose type is an
17609 -- anonymous protected type) its components are at the same level
17610 -- as the type itself.
17612 elsif not Is_Overloadable (E)
17613 and then Ekind (Scope (E)) = E_Protected_Type
17614 and then Comes_From_Source (Scope (E))
17616 return Type_Access_Level (Scope (E)) + 1;
17619 -- Aliased formals of functions take their access level from the
17620 -- point of call, i.e. require a dynamic check. For static check
17621 -- purposes, this is smaller than the level of the subprogram
17622 -- itself. For procedures the aliased makes no difference.
17625 and then Is_Aliased (E)
17626 and then Ekind (Scope (E)) = E_Function
17628 return Type_Access_Level (Etype (E));
17631 return Scope_Depth (Enclosing_Dynamic_Scope (E));
17635 elsif Nkind (Obj) = N_Selected_Component then
17636 if Is_Access_Type (Etype (Prefix (Obj))) then
17637 return Type_Access_Level (Etype (Prefix (Obj)));
17639 return Object_Access_Level (Prefix (Obj));
17642 elsif Nkind (Obj) = N_Indexed_Component then
17643 if Is_Access_Type (Etype (Prefix (Obj))) then
17644 return Type_Access_Level (Etype (Prefix (Obj)));
17646 return Object_Access_Level (Prefix (Obj));
17649 elsif Nkind (Obj) = N_Explicit_Dereference then
17651 -- If the prefix is a selected access discriminant then we make a
17652 -- recursive call on the prefix, which will in turn check the level
17653 -- of the prefix object of the selected discriminant.
17655 -- In Ada 2012, if the discriminant has implicit dereference and
17656 -- the context is a selected component, treat this as an object of
17657 -- unknown scope (see below). This is necessary in compile-only mode;
17658 -- otherwise expansion will already have transformed the prefix into
17661 if Nkind (Prefix (Obj)) = N_Selected_Component
17662 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
17664 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
17666 (not Has_Implicit_Dereference
17667 (Entity (Selector_Name (Prefix (Obj))))
17668 or else Nkind (Parent (Obj)) /= N_Selected_Component)
17670 return Object_Access_Level (Prefix (Obj));
17672 -- Detect an interface conversion in the context of a dispatching
17673 -- call. Use the original form of the conversion to find the access
17674 -- level of the operand.
17676 elsif Is_Interface (Etype (Obj))
17677 and then Is_Interface_Conversion (Prefix (Obj))
17678 and then Nkind (Original_Node (Obj)) = N_Type_Conversion
17680 return Object_Access_Level (Original_Node (Obj));
17682 elsif not Comes_From_Source (Obj) then
17684 Ref : constant Node_Id := Reference_To (Obj);
17686 if Present (Ref) then
17687 return Object_Access_Level (Ref);
17689 return Type_Access_Level (Etype (Prefix (Obj)));
17694 return Type_Access_Level (Etype (Prefix (Obj)));
17697 elsif Nkind_In (Obj, N_Type_Conversion, N_Unchecked_Type_Conversion) then
17698 return Object_Access_Level (Expression (Obj));
17700 elsif Nkind (Obj) = N_Function_Call then
17702 -- Function results are objects, so we get either the access level of
17703 -- the function or, in the case of an indirect call, the level of the
17704 -- access-to-subprogram type. (This code is used for Ada 95, but it
17705 -- looks wrong, because it seems that we should be checking the level
17706 -- of the call itself, even for Ada 95. However, using the Ada 2005
17707 -- version of the code causes regressions in several tests that are
17708 -- compiled with -gnat95. ???)
17710 if Ada_Version < Ada_2005 then
17711 if Is_Entity_Name (Name (Obj)) then
17712 return Subprogram_Access_Level (Entity (Name (Obj)));
17714 return Type_Access_Level (Etype (Prefix (Name (Obj))));
17717 -- For Ada 2005, the level of the result object of a function call is
17718 -- defined to be the level of the call's innermost enclosing master.
17719 -- We determine that by querying the depth of the innermost enclosing
17723 Return_Master_Scope_Depth_Of_Call : declare
17725 function Innermost_Master_Scope_Depth
17726 (N : Node_Id) return Uint;
17727 -- Returns the scope depth of the given node's innermost
17728 -- enclosing dynamic scope (effectively the accessibility
17729 -- level of the innermost enclosing master).
17731 ----------------------------------
17732 -- Innermost_Master_Scope_Depth --
17733 ----------------------------------
17735 function Innermost_Master_Scope_Depth
17736 (N : Node_Id) return Uint
17738 Node_Par : Node_Id := Parent (N);
17741 -- Locate the nearest enclosing node (by traversing Parents)
17742 -- that Defining_Entity can be applied to, and return the
17743 -- depth of that entity's nearest enclosing dynamic scope.
17745 while Present (Node_Par) loop
17746 case Nkind (Node_Par) is
17747 when N_Component_Declaration |
17748 N_Entry_Declaration |
17749 N_Formal_Object_Declaration |
17750 N_Formal_Type_Declaration |
17751 N_Full_Type_Declaration |
17752 N_Incomplete_Type_Declaration |
17753 N_Loop_Parameter_Specification |
17754 N_Object_Declaration |
17755 N_Protected_Type_Declaration |
17756 N_Private_Extension_Declaration |
17757 N_Private_Type_Declaration |
17758 N_Subtype_Declaration |
17759 N_Function_Specification |
17760 N_Procedure_Specification |
17761 N_Task_Type_Declaration |
17763 N_Generic_Instantiation |
17765 N_Implicit_Label_Declaration |
17766 N_Package_Declaration |
17767 N_Single_Task_Declaration |
17768 N_Subprogram_Declaration |
17769 N_Generic_Declaration |
17770 N_Renaming_Declaration |
17771 N_Block_Statement |
17772 N_Formal_Subprogram_Declaration |
17773 N_Abstract_Subprogram_Declaration |
17775 N_Exception_Declaration |
17776 N_Formal_Package_Declaration |
17777 N_Number_Declaration |
17778 N_Package_Specification |
17779 N_Parameter_Specification |
17780 N_Single_Protected_Declaration |
17784 (Nearest_Dynamic_Scope
17785 (Defining_Entity (Node_Par)));
17791 Node_Par := Parent (Node_Par);
17794 pragma Assert (False);
17796 -- Should never reach the following return
17798 return Scope_Depth (Current_Scope) + 1;
17799 end Innermost_Master_Scope_Depth;
17801 -- Start of processing for Return_Master_Scope_Depth_Of_Call
17804 return Innermost_Master_Scope_Depth (Obj);
17805 end Return_Master_Scope_Depth_Of_Call;
17808 -- For convenience we handle qualified expressions, even though they
17809 -- aren't technically object names.
17811 elsif Nkind (Obj) = N_Qualified_Expression then
17812 return Object_Access_Level (Expression (Obj));
17814 -- Ditto for aggregates. They have the level of the temporary that
17815 -- will hold their value.
17817 elsif Nkind (Obj) = N_Aggregate then
17818 return Object_Access_Level (Current_Scope);
17820 -- Otherwise return the scope level of Standard. (If there are cases
17821 -- that fall through to this point they will be treated as having
17822 -- global accessibility for now. ???)
17825 return Scope_Depth (Standard_Standard);
17827 end Object_Access_Level;
17829 ---------------------------------
17830 -- Original_Aspect_Pragma_Name --
17831 ---------------------------------
17833 function Original_Aspect_Pragma_Name (N : Node_Id) return Name_Id is
17835 Item_Nam : Name_Id;
17838 pragma Assert (Nkind_In (N, N_Aspect_Specification, N_Pragma));
17842 -- The pragma was generated to emulate an aspect, use the original
17843 -- aspect specification.
17845 if Nkind (Item) = N_Pragma and then From_Aspect_Specification (Item) then
17846 Item := Corresponding_Aspect (Item);
17849 -- Retrieve the name of the aspect/pragma. Note that Pre, Pre_Class,
17850 -- Post and Post_Class rewrite their pragma identifier to preserve the
17852 -- ??? this is kludgey
17854 if Nkind (Item) = N_Pragma then
17855 Item_Nam := Chars (Original_Node (Pragma_Identifier (Item)));
17858 pragma Assert (Nkind (Item) = N_Aspect_Specification);
17859 Item_Nam := Chars (Identifier (Item));
17862 -- Deal with 'Class by converting the name to its _XXX form
17864 if Class_Present (Item) then
17865 if Item_Nam = Name_Invariant then
17866 Item_Nam := Name_uInvariant;
17868 elsif Item_Nam = Name_Post then
17869 Item_Nam := Name_uPost;
17871 elsif Item_Nam = Name_Pre then
17872 Item_Nam := Name_uPre;
17874 elsif Nam_In (Item_Nam, Name_Type_Invariant,
17875 Name_Type_Invariant_Class)
17877 Item_Nam := Name_uType_Invariant;
17879 -- Nothing to do for other cases (e.g. a Check that derived from
17880 -- Pre_Class and has the flag set). Also we do nothing if the name
17881 -- is already in special _xxx form.
17887 end Original_Aspect_Pragma_Name;
17889 --------------------------------------
17890 -- Original_Corresponding_Operation --
17891 --------------------------------------
17893 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
17895 Typ : constant Entity_Id := Find_Dispatching_Type (S);
17898 -- If S is an inherited primitive S2 the original corresponding
17899 -- operation of S is the original corresponding operation of S2
17901 if Present (Alias (S))
17902 and then Find_Dispatching_Type (Alias (S)) /= Typ
17904 return Original_Corresponding_Operation (Alias (S));
17906 -- If S overrides an inherited subprogram S2 the original corresponding
17907 -- operation of S is the original corresponding operation of S2
17909 elsif Present (Overridden_Operation (S)) then
17910 return Original_Corresponding_Operation (Overridden_Operation (S));
17912 -- otherwise it is S itself
17917 end Original_Corresponding_Operation;
17919 -------------------
17920 -- Output_Entity --
17921 -------------------
17923 procedure Output_Entity (Id : Entity_Id) is
17927 Scop := Scope (Id);
17929 -- The entity may lack a scope when it is in the process of being
17930 -- analyzed. Use the current scope as an approximation.
17933 Scop := Current_Scope;
17936 Output_Name (Chars (Id), Scop);
17943 procedure Output_Name (Nam : Name_Id; Scop : Entity_Id := Current_Scope) is
17947 (Get_Qualified_Name
17954 ----------------------
17955 -- Policy_In_Effect --
17956 ----------------------
17958 function Policy_In_Effect (Policy : Name_Id) return Name_Id is
17959 function Policy_In_List (List : Node_Id) return Name_Id;
17960 -- Determine the mode of a policy in a N_Pragma list
17962 --------------------
17963 -- Policy_In_List --
17964 --------------------
17966 function Policy_In_List (List : Node_Id) return Name_Id is
17973 while Present (Prag) loop
17974 Arg1 := First (Pragma_Argument_Associations (Prag));
17975 Arg2 := Next (Arg1);
17977 Arg1 := Get_Pragma_Arg (Arg1);
17978 Arg2 := Get_Pragma_Arg (Arg2);
17980 -- The current Check_Policy pragma matches the requested policy or
17981 -- appears in the single argument form (Assertion, policy_id).
17983 if Nam_In (Chars (Arg1), Name_Assertion, Policy) then
17984 return Chars (Arg2);
17987 Prag := Next_Pragma (Prag);
17991 end Policy_In_List;
17997 -- Start of processing for Policy_In_Effect
18000 if not Is_Valid_Assertion_Kind (Policy) then
18001 raise Program_Error;
18004 -- Inspect all policy pragmas that appear within scopes (if any)
18006 Kind := Policy_In_List (Check_Policy_List);
18008 -- Inspect all configuration policy pragmas (if any)
18010 if Kind = No_Name then
18011 Kind := Policy_In_List (Check_Policy_List_Config);
18014 -- The context lacks policy pragmas, determine the mode based on whether
18015 -- assertions are enabled at the configuration level. This ensures that
18016 -- the policy is preserved when analyzing generics.
18018 if Kind = No_Name then
18019 if Assertions_Enabled_Config then
18020 Kind := Name_Check;
18022 Kind := Name_Ignore;
18027 end Policy_In_Effect;
18029 ----------------------------------
18030 -- Predicate_Tests_On_Arguments --
18031 ----------------------------------
18033 function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean is
18035 -- Always test predicates on indirect call
18037 if Ekind (Subp) = E_Subprogram_Type then
18040 -- Do not test predicates on call to generated default Finalize, since
18041 -- we are not interested in whether something we are finalizing (and
18042 -- typically destroying) satisfies its predicates.
18044 elsif Chars (Subp) = Name_Finalize
18045 and then not Comes_From_Source (Subp)
18049 -- Do not test predicates on any internally generated routines
18051 elsif Is_Internal_Name (Chars (Subp)) then
18054 -- Do not test predicates on call to Init_Proc, since if needed the
18055 -- predicate test will occur at some other point.
18057 elsif Is_Init_Proc (Subp) then
18060 -- Do not test predicates on call to predicate function, since this
18061 -- would cause infinite recursion.
18063 elsif Ekind (Subp) = E_Function
18064 and then (Is_Predicate_Function (Subp)
18066 Is_Predicate_Function_M (Subp))
18070 -- For now, no other exceptions
18075 end Predicate_Tests_On_Arguments;
18077 -----------------------
18078 -- Private_Component --
18079 -----------------------
18081 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
18082 Ancestor : constant Entity_Id := Base_Type (Type_Id);
18084 function Trace_Components
18086 Check : Boolean) return Entity_Id;
18087 -- Recursive function that does the work, and checks against circular
18088 -- definition for each subcomponent type.
18090 ----------------------
18091 -- Trace_Components --
18092 ----------------------
18094 function Trace_Components
18096 Check : Boolean) return Entity_Id
18098 Btype : constant Entity_Id := Base_Type (T);
18099 Component : Entity_Id;
18101 Candidate : Entity_Id := Empty;
18104 if Check and then Btype = Ancestor then
18105 Error_Msg_N ("circular type definition", Type_Id);
18109 if Is_Private_Type (Btype) and then not Is_Generic_Type (Btype) then
18110 if Present (Full_View (Btype))
18111 and then Is_Record_Type (Full_View (Btype))
18112 and then not Is_Frozen (Btype)
18114 -- To indicate that the ancestor depends on a private type, the
18115 -- current Btype is sufficient. However, to check for circular
18116 -- definition we must recurse on the full view.
18118 Candidate := Trace_Components (Full_View (Btype), True);
18120 if Candidate = Any_Type then
18130 elsif Is_Array_Type (Btype) then
18131 return Trace_Components (Component_Type (Btype), True);
18133 elsif Is_Record_Type (Btype) then
18134 Component := First_Entity (Btype);
18135 while Present (Component)
18136 and then Comes_From_Source (Component)
18138 -- Skip anonymous types generated by constrained components
18140 if not Is_Type (Component) then
18141 P := Trace_Components (Etype (Component), True);
18143 if Present (P) then
18144 if P = Any_Type then
18152 Next_Entity (Component);
18160 end Trace_Components;
18162 -- Start of processing for Private_Component
18165 return Trace_Components (Type_Id, False);
18166 end Private_Component;
18168 ---------------------------
18169 -- Primitive_Names_Match --
18170 ---------------------------
18172 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
18173 function Non_Internal_Name (E : Entity_Id) return Name_Id;
18174 -- Given an internal name, returns the corresponding non-internal name
18176 ------------------------
18177 -- Non_Internal_Name --
18178 ------------------------
18180 function Non_Internal_Name (E : Entity_Id) return Name_Id is
18182 Get_Name_String (Chars (E));
18183 Name_Len := Name_Len - 1;
18185 end Non_Internal_Name;
18187 -- Start of processing for Primitive_Names_Match
18190 pragma Assert (Present (E1) and then Present (E2));
18192 return Chars (E1) = Chars (E2)
18194 (not Is_Internal_Name (Chars (E1))
18195 and then Is_Internal_Name (Chars (E2))
18196 and then Non_Internal_Name (E2) = Chars (E1))
18198 (not Is_Internal_Name (Chars (E2))
18199 and then Is_Internal_Name (Chars (E1))
18200 and then Non_Internal_Name (E1) = Chars (E2))
18202 (Is_Predefined_Dispatching_Operation (E1)
18203 and then Is_Predefined_Dispatching_Operation (E2)
18204 and then Same_TSS (E1, E2))
18206 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
18207 end Primitive_Names_Match;
18209 -----------------------
18210 -- Process_End_Label --
18211 -----------------------
18213 procedure Process_End_Label
18222 Label_Ref : Boolean;
18223 -- Set True if reference to end label itself is required
18226 -- Gets set to the operator symbol or identifier that references the
18227 -- entity Ent. For the child unit case, this is the identifier from the
18228 -- designator. For other cases, this is simply Endl.
18230 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
18231 -- N is an identifier node that appears as a parent unit reference in
18232 -- the case where Ent is a child unit. This procedure generates an
18233 -- appropriate cross-reference entry. E is the corresponding entity.
18235 -------------------------
18236 -- Generate_Parent_Ref --
18237 -------------------------
18239 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
18241 -- If names do not match, something weird, skip reference
18243 if Chars (E) = Chars (N) then
18245 -- Generate the reference. We do NOT consider this as a reference
18246 -- for unreferenced symbol purposes.
18248 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
18250 if Style_Check then
18251 Style.Check_Identifier (N, E);
18254 end Generate_Parent_Ref;
18256 -- Start of processing for Process_End_Label
18259 -- If no node, ignore. This happens in some error situations, and
18260 -- also for some internally generated structures where no end label
18261 -- references are required in any case.
18267 -- Nothing to do if no End_Label, happens for internally generated
18268 -- constructs where we don't want an end label reference anyway. Also
18269 -- nothing to do if Endl is a string literal, which means there was
18270 -- some prior error (bad operator symbol)
18272 Endl := End_Label (N);
18274 if No (Endl) or else Nkind (Endl) = N_String_Literal then
18278 -- Reference node is not in extended main source unit
18280 if not In_Extended_Main_Source_Unit (N) then
18282 -- Generally we do not collect references except for the extended
18283 -- main source unit. The one exception is the 'e' entry for a
18284 -- package spec, where it is useful for a client to have the
18285 -- ending information to define scopes.
18291 Label_Ref := False;
18293 -- For this case, we can ignore any parent references, but we
18294 -- need the package name itself for the 'e' entry.
18296 if Nkind (Endl) = N_Designator then
18297 Endl := Identifier (Endl);
18301 -- Reference is in extended main source unit
18306 -- For designator, generate references for the parent entries
18308 if Nkind (Endl) = N_Designator then
18310 -- Generate references for the prefix if the END line comes from
18311 -- source (otherwise we do not need these references) We climb the
18312 -- scope stack to find the expected entities.
18314 if Comes_From_Source (Endl) then
18315 Nam := Name (Endl);
18316 Scop := Current_Scope;
18317 while Nkind (Nam) = N_Selected_Component loop
18318 Scop := Scope (Scop);
18319 exit when No (Scop);
18320 Generate_Parent_Ref (Selector_Name (Nam), Scop);
18321 Nam := Prefix (Nam);
18324 if Present (Scop) then
18325 Generate_Parent_Ref (Nam, Scope (Scop));
18329 Endl := Identifier (Endl);
18333 -- If the end label is not for the given entity, then either we have
18334 -- some previous error, or this is a generic instantiation for which
18335 -- we do not need to make a cross-reference in this case anyway. In
18336 -- either case we simply ignore the call.
18338 if Chars (Ent) /= Chars (Endl) then
18342 -- If label was really there, then generate a normal reference and then
18343 -- adjust the location in the end label to point past the name (which
18344 -- should almost always be the semicolon).
18346 Loc := Sloc (Endl);
18348 if Comes_From_Source (Endl) then
18350 -- If a label reference is required, then do the style check and
18351 -- generate an l-type cross-reference entry for the label
18354 if Style_Check then
18355 Style.Check_Identifier (Endl, Ent);
18358 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
18361 -- Set the location to point past the label (normally this will
18362 -- mean the semicolon immediately following the label). This is
18363 -- done for the sake of the 'e' or 't' entry generated below.
18365 Get_Decoded_Name_String (Chars (Endl));
18366 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
18369 -- In SPARK mode, no missing label is allowed for packages and
18370 -- subprogram bodies. Detect those cases by testing whether
18371 -- Process_End_Label was called for a body (Typ = 't') or a package.
18373 if Restriction_Check_Required (SPARK_05)
18374 and then (Typ = 't' or else Ekind (Ent) = E_Package)
18376 Error_Msg_Node_1 := Endl;
18377 Check_SPARK_05_Restriction
18378 ("`END &` required", Endl, Force => True);
18382 -- Now generate the e/t reference
18384 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
18386 -- Restore Sloc, in case modified above, since we have an identifier
18387 -- and the normal Sloc should be left set in the tree.
18389 Set_Sloc (Endl, Loc);
18390 end Process_End_Label;
18392 --------------------------------
18393 -- Propagate_Concurrent_Flags --
18394 --------------------------------
18396 procedure Propagate_Concurrent_Flags
18398 Comp_Typ : Entity_Id)
18401 if Has_Task (Comp_Typ) then
18402 Set_Has_Task (Typ);
18405 if Has_Protected (Comp_Typ) then
18406 Set_Has_Protected (Typ);
18409 if Has_Timing_Event (Comp_Typ) then
18410 Set_Has_Timing_Event (Typ);
18412 end Propagate_Concurrent_Flags;
18414 ------------------------------
18415 -- Propagate_DIC_Attributes --
18416 ------------------------------
18418 procedure Propagate_DIC_Attributes
18420 From_Typ : Entity_Id)
18422 DIC_Proc : Entity_Id;
18425 if Present (Typ) and then Present (From_Typ) then
18426 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
18428 -- Nothing to do if both the source and the destination denote the
18431 if From_Typ = Typ then
18435 DIC_Proc := DIC_Procedure (From_Typ);
18437 -- The setting of the attributes is intentionally conservative. This
18438 -- prevents accidental clobbering of enabled attributes.
18440 if Has_Inherited_DIC (From_Typ)
18441 and then not Has_Inherited_DIC (Typ)
18443 Set_Has_Inherited_DIC (Typ);
18446 if Has_Own_DIC (From_Typ) and then not Has_Own_DIC (Typ) then
18447 Set_Has_Own_DIC (Typ);
18450 if Present (DIC_Proc) and then No (DIC_Procedure (Typ)) then
18451 Set_DIC_Procedure (Typ, DIC_Proc);
18454 end Propagate_DIC_Attributes;
18456 ------------------------------------
18457 -- Propagate_Invariant_Attributes --
18458 ------------------------------------
18460 procedure Propagate_Invariant_Attributes
18462 From_Typ : Entity_Id)
18464 Full_IP : Entity_Id;
18465 Part_IP : Entity_Id;
18468 if Present (Typ) and then Present (From_Typ) then
18469 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
18471 -- Nothing to do if both the source and the destination denote the
18474 if From_Typ = Typ then
18478 Full_IP := Invariant_Procedure (From_Typ);
18479 Part_IP := Partial_Invariant_Procedure (From_Typ);
18481 -- The setting of the attributes is intentionally conservative. This
18482 -- prevents accidental clobbering of enabled attributes.
18484 if Has_Inheritable_Invariants (From_Typ)
18485 and then not Has_Inheritable_Invariants (Typ)
18487 Set_Has_Inheritable_Invariants (Typ, True);
18490 if Has_Inherited_Invariants (From_Typ)
18491 and then not Has_Inherited_Invariants (Typ)
18493 Set_Has_Inherited_Invariants (Typ, True);
18496 if Has_Own_Invariants (From_Typ)
18497 and then not Has_Own_Invariants (Typ)
18499 Set_Has_Own_Invariants (Typ, True);
18502 if Present (Full_IP) and then No (Invariant_Procedure (Typ)) then
18503 Set_Invariant_Procedure (Typ, Full_IP);
18506 if Present (Part_IP) and then No (Partial_Invariant_Procedure (Typ))
18508 Set_Partial_Invariant_Procedure (Typ, Part_IP);
18511 end Propagate_Invariant_Attributes;
18513 ---------------------------------------
18514 -- Record_Possible_Part_Of_Reference --
18515 ---------------------------------------
18517 procedure Record_Possible_Part_Of_Reference
18518 (Var_Id : Entity_Id;
18521 Encap : constant Entity_Id := Encapsulating_State (Var_Id);
18525 -- The variable is a constituent of a single protected/task type. Such
18526 -- a variable acts as a component of the type and must appear within a
18527 -- specific region (SPARK RM 9.3). Instead of recording the reference,
18528 -- verify its legality now.
18530 if Present (Encap) and then Is_Single_Concurrent_Object (Encap) then
18531 Check_Part_Of_Reference (Var_Id, Ref);
18533 -- The variable is subject to pragma Part_Of and may eventually become a
18534 -- constituent of a single protected/task type. Record the reference to
18535 -- verify its placement when the contract of the variable is analyzed.
18537 elsif Present (Get_Pragma (Var_Id, Pragma_Part_Of)) then
18538 Refs := Part_Of_References (Var_Id);
18541 Refs := New_Elmt_List;
18542 Set_Part_Of_References (Var_Id, Refs);
18545 Append_Elmt (Ref, Refs);
18547 end Record_Possible_Part_Of_Reference;
18553 function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
18554 Seen : Boolean := False;
18556 function Is_Reference (N : Node_Id) return Traverse_Result;
18557 -- Determine whether node N denotes a reference to Id. If this is the
18558 -- case, set global flag Seen to True and stop the traversal.
18564 function Is_Reference (N : Node_Id) return Traverse_Result is
18566 if Is_Entity_Name (N)
18567 and then Present (Entity (N))
18568 and then Entity (N) = Id
18577 procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
18579 -- Start of processing for Referenced
18582 Inspect_Expression (Expr);
18586 ------------------------------------
18587 -- References_Generic_Formal_Type --
18588 ------------------------------------
18590 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
18592 function Process (N : Node_Id) return Traverse_Result;
18593 -- Process one node in search for generic formal type
18599 function Process (N : Node_Id) return Traverse_Result is
18601 if Nkind (N) in N_Has_Entity then
18603 E : constant Entity_Id := Entity (N);
18605 if Present (E) then
18606 if Is_Generic_Type (E) then
18608 elsif Present (Etype (E))
18609 and then Is_Generic_Type (Etype (E))
18620 function Traverse is new Traverse_Func (Process);
18621 -- Traverse tree to look for generic type
18624 if Inside_A_Generic then
18625 return Traverse (N) = Abandon;
18629 end References_Generic_Formal_Type;
18631 --------------------
18632 -- Remove_Homonym --
18633 --------------------
18635 procedure Remove_Homonym (E : Entity_Id) is
18636 Prev : Entity_Id := Empty;
18640 if E = Current_Entity (E) then
18641 if Present (Homonym (E)) then
18642 Set_Current_Entity (Homonym (E));
18644 Set_Name_Entity_Id (Chars (E), Empty);
18648 H := Current_Entity (E);
18649 while Present (H) and then H /= E loop
18654 -- If E is not on the homonym chain, nothing to do
18656 if Present (H) then
18657 Set_Homonym (Prev, Homonym (E));
18660 end Remove_Homonym;
18662 ------------------------------
18663 -- Remove_Overloaded_Entity --
18664 ------------------------------
18666 procedure Remove_Overloaded_Entity (Id : Entity_Id) is
18667 procedure Remove_Primitive_Of (Typ : Entity_Id);
18668 -- Remove primitive subprogram Id from the list of primitives that
18669 -- belong to type Typ.
18671 -------------------------
18672 -- Remove_Primitive_Of --
18673 -------------------------
18675 procedure Remove_Primitive_Of (Typ : Entity_Id) is
18679 if Is_Tagged_Type (Typ) then
18680 Prims := Direct_Primitive_Operations (Typ);
18682 if Present (Prims) then
18683 Remove (Prims, Id);
18686 end Remove_Primitive_Of;
18690 Scop : constant Entity_Id := Scope (Id);
18691 Formal : Entity_Id;
18692 Prev_Id : Entity_Id;
18694 -- Start of processing for Remove_Overloaded_Entity
18697 -- Remove the entity from the homonym chain. When the entity is the
18698 -- head of the chain, associate the entry in the name table with its
18699 -- homonym effectively making it the new head of the chain.
18701 if Current_Entity (Id) = Id then
18702 Set_Name_Entity_Id (Chars (Id), Homonym (Id));
18704 -- Otherwise link the previous and next homonyms
18707 Prev_Id := Current_Entity (Id);
18708 while Present (Prev_Id) and then Homonym (Prev_Id) /= Id loop
18709 Prev_Id := Homonym (Prev_Id);
18712 Set_Homonym (Prev_Id, Homonym (Id));
18715 -- Remove the entity from the scope entity chain. When the entity is
18716 -- the head of the chain, set the next entity as the new head of the
18719 if First_Entity (Scop) = Id then
18721 Set_First_Entity (Scop, Next_Entity (Id));
18723 -- Otherwise the entity is either in the middle of the chain or it acts
18724 -- as its tail. Traverse and link the previous and next entities.
18727 Prev_Id := First_Entity (Scop);
18728 while Present (Prev_Id) and then Next_Entity (Prev_Id) /= Id loop
18729 Next_Entity (Prev_Id);
18732 Set_Next_Entity (Prev_Id, Next_Entity (Id));
18735 -- Handle the case where the entity acts as the tail of the scope entity
18738 if Last_Entity (Scop) = Id then
18739 Set_Last_Entity (Scop, Prev_Id);
18742 -- The entity denotes a primitive subprogram. Remove it from the list of
18743 -- primitives of the associated controlling type.
18745 if Ekind_In (Id, E_Function, E_Procedure) and then Is_Primitive (Id) then
18746 Formal := First_Formal (Id);
18747 while Present (Formal) loop
18748 if Is_Controlling_Formal (Formal) then
18749 Remove_Primitive_Of (Etype (Formal));
18753 Next_Formal (Formal);
18756 if Ekind (Id) = E_Function and then Has_Controlling_Result (Id) then
18757 Remove_Primitive_Of (Etype (Id));
18760 end Remove_Overloaded_Entity;
18762 ---------------------
18763 -- Rep_To_Pos_Flag --
18764 ---------------------
18766 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
18768 return New_Occurrence_Of
18769 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
18770 end Rep_To_Pos_Flag;
18772 --------------------
18773 -- Require_Entity --
18774 --------------------
18776 procedure Require_Entity (N : Node_Id) is
18778 if Is_Entity_Name (N) and then No (Entity (N)) then
18779 if Total_Errors_Detected /= 0 then
18780 Set_Entity (N, Any_Id);
18782 raise Program_Error;
18785 end Require_Entity;
18787 ------------------------------
18788 -- Requires_Transient_Scope --
18789 ------------------------------
18791 -- A transient scope is required when variable-sized temporaries are
18792 -- allocated on the secondary stack, or when finalization actions must be
18793 -- generated before the next instruction.
18795 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
18796 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
18797 -- ???We retain the old and new algorithms for Requires_Transient_Scope for
18798 -- the time being. New_Requires_Transient_Scope is used by default; the
18799 -- debug switch -gnatdQ can be used to do Old_Requires_Transient_Scope
18800 -- instead. The intent is to use this temporarily to measure before/after
18801 -- efficiency. Note: when this temporary code is removed, the documentation
18802 -- of dQ in debug.adb should be removed.
18804 procedure Results_Differ (Id : Entity_Id);
18805 -- ???Debugging code. Called when the Old_ and New_ results differ. Will be
18806 -- removed when New_Requires_Transient_Scope becomes
18807 -- Requires_Transient_Scope and Old_Requires_Transient_Scope is eliminated.
18809 procedure Results_Differ (Id : Entity_Id) is
18811 if False then -- False to disable; True for debugging
18812 Treepr.Print_Tree_Node (Id);
18814 if Old_Requires_Transient_Scope (Id) =
18815 New_Requires_Transient_Scope (Id)
18817 raise Program_Error;
18820 end Results_Differ;
18822 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
18823 Old_Result : constant Boolean := Old_Requires_Transient_Scope (Id);
18826 if Debug_Flag_QQ then
18831 New_Result : constant Boolean := New_Requires_Transient_Scope (Id);
18834 -- Assert that we're not putting things on the secondary stack if we
18835 -- didn't before; we are trying to AVOID secondary stack when
18838 if not Old_Result then
18839 pragma Assert (not New_Result);
18843 if New_Result /= Old_Result then
18844 Results_Differ (Id);
18849 end Requires_Transient_Scope;
18851 ----------------------------------
18852 -- Old_Requires_Transient_Scope --
18853 ----------------------------------
18855 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
18856 Typ : constant Entity_Id := Underlying_Type (Id);
18859 -- This is a private type which is not completed yet. This can only
18860 -- happen in a default expression (of a formal parameter or of a
18861 -- record component). Do not expand transient scope in this case.
18866 -- Do not expand transient scope for non-existent procedure return
18868 elsif Typ = Standard_Void_Type then
18871 -- Elementary types do not require a transient scope
18873 elsif Is_Elementary_Type (Typ) then
18876 -- Generally, indefinite subtypes require a transient scope, since the
18877 -- back end cannot generate temporaries, since this is not a valid type
18878 -- for declaring an object. It might be possible to relax this in the
18879 -- future, e.g. by declaring the maximum possible space for the type.
18881 elsif not Is_Definite_Subtype (Typ) then
18884 -- Functions returning tagged types may dispatch on result so their
18885 -- returned value is allocated on the secondary stack. Controlled
18886 -- type temporaries need finalization.
18888 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
18893 elsif Is_Record_Type (Typ) then
18898 Comp := First_Entity (Typ);
18899 while Present (Comp) loop
18900 if Ekind (Comp) = E_Component then
18902 -- ???It's not clear we need a full recursive call to
18903 -- Old_Requires_Transient_Scope here. Note that the
18904 -- following can't happen.
18906 pragma Assert (Is_Definite_Subtype (Etype (Comp)));
18907 pragma Assert (not Has_Controlled_Component (Etype (Comp)));
18909 if Old_Requires_Transient_Scope (Etype (Comp)) then
18914 Next_Entity (Comp);
18920 -- String literal types never require transient scope
18922 elsif Ekind (Typ) = E_String_Literal_Subtype then
18925 -- Array type. Note that we already know that this is a constrained
18926 -- array, since unconstrained arrays will fail the indefinite test.
18928 elsif Is_Array_Type (Typ) then
18930 -- If component type requires a transient scope, the array does too
18932 if Old_Requires_Transient_Scope (Component_Type (Typ)) then
18935 -- Otherwise, we only need a transient scope if the size depends on
18936 -- the value of one or more discriminants.
18939 return Size_Depends_On_Discriminant (Typ);
18942 -- All other cases do not require a transient scope
18945 pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
18948 end Old_Requires_Transient_Scope;
18950 ----------------------------------
18951 -- New_Requires_Transient_Scope --
18952 ----------------------------------
18954 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
18956 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean;
18957 -- This is called for untagged records and protected types, with
18958 -- nondefaulted discriminants. Returns True if the size of function
18959 -- results is known at the call site, False otherwise. Returns False
18960 -- if there is a variant part that depends on the discriminants of
18961 -- this type, or if there is an array constrained by the discriminants
18962 -- of this type. ???Currently, this is overly conservative (the array
18963 -- could be nested inside some other record that is constrained by
18964 -- nondiscriminants). That is, the recursive calls are too conservative.
18966 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean;
18967 -- Returns True if Typ is a nonlimited record with defaulted
18968 -- discriminants whose max size makes it unsuitable for allocating on
18969 -- the primary stack.
18971 ------------------------------
18972 -- Caller_Known_Size_Record --
18973 ------------------------------
18975 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean is
18976 pragma Assert (Typ = Underlying_Type (Typ));
18979 if Has_Variant_Part (Typ) and then not Is_Definite_Subtype (Typ) then
18987 Comp := First_Entity (Typ);
18988 while Present (Comp) loop
18990 -- Only look at E_Component entities. No need to look at
18991 -- E_Discriminant entities, and we must ignore internal
18992 -- subtypes generated for constrained components.
18994 if Ekind (Comp) = E_Component then
18996 Comp_Type : constant Entity_Id :=
18997 Underlying_Type (Etype (Comp));
19000 if Is_Record_Type (Comp_Type)
19002 Is_Protected_Type (Comp_Type)
19004 if not Caller_Known_Size_Record (Comp_Type) then
19008 elsif Is_Array_Type (Comp_Type) then
19009 if Size_Depends_On_Discriminant (Comp_Type) then
19016 Next_Entity (Comp);
19021 end Caller_Known_Size_Record;
19023 ------------------------------
19024 -- Large_Max_Size_Mutable --
19025 ------------------------------
19027 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean is
19028 pragma Assert (Typ = Underlying_Type (Typ));
19030 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean;
19031 -- Returns true if the discrete type T has a large range
19033 ----------------------------
19034 -- Is_Large_Discrete_Type --
19035 ----------------------------
19037 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean is
19038 Threshold : constant Int := 16;
19039 -- Arbitrary threshold above which we consider it "large". We want
19040 -- a fairly large threshold, because these large types really
19041 -- shouldn't have default discriminants in the first place, in
19045 return UI_To_Int (RM_Size (T)) > Threshold;
19046 end Is_Large_Discrete_Type;
19049 if Is_Record_Type (Typ)
19050 and then not Is_Limited_View (Typ)
19051 and then Has_Defaulted_Discriminants (Typ)
19053 -- Loop through the components, looking for an array whose upper
19054 -- bound(s) depends on discriminants, where both the subtype of
19055 -- the discriminant and the index subtype are too large.
19061 Comp := First_Entity (Typ);
19062 while Present (Comp) loop
19063 if Ekind (Comp) = E_Component then
19065 Comp_Type : constant Entity_Id :=
19066 Underlying_Type (Etype (Comp));
19072 if Is_Array_Type (Comp_Type) then
19073 Indx := First_Index (Comp_Type);
19075 while Present (Indx) loop
19076 Ityp := Etype (Indx);
19077 Hi := Type_High_Bound (Ityp);
19079 if Nkind (Hi) = N_Identifier
19080 and then Ekind (Entity (Hi)) = E_Discriminant
19081 and then Is_Large_Discrete_Type (Ityp)
19082 and then Is_Large_Discrete_Type
19083 (Etype (Entity (Hi)))
19094 Next_Entity (Comp);
19100 end Large_Max_Size_Mutable;
19102 -- Local declarations
19104 Typ : constant Entity_Id := Underlying_Type (Id);
19106 -- Start of processing for New_Requires_Transient_Scope
19109 -- This is a private type which is not completed yet. This can only
19110 -- happen in a default expression (of a formal parameter or of a
19111 -- record component). Do not expand transient scope in this case.
19116 -- Do not expand transient scope for non-existent procedure return or
19117 -- string literal types.
19119 elsif Typ = Standard_Void_Type
19120 or else Ekind (Typ) = E_String_Literal_Subtype
19124 -- If Typ is a generic formal incomplete type, then we want to look at
19125 -- the actual type.
19127 elsif Ekind (Typ) = E_Record_Subtype
19128 and then Present (Cloned_Subtype (Typ))
19130 return New_Requires_Transient_Scope (Cloned_Subtype (Typ));
19132 -- Functions returning specific tagged types may dispatch on result, so
19133 -- their returned value is allocated on the secondary stack, even in the
19134 -- definite case. We must treat nondispatching functions the same way,
19135 -- because access-to-function types can point at both, so the calling
19136 -- conventions must be compatible. Is_Tagged_Type includes controlled
19137 -- types and class-wide types. Controlled type temporaries need
19140 -- ???It's not clear why we need to return noncontrolled types with
19141 -- controlled components on the secondary stack.
19143 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
19146 -- Untagged definite subtypes are known size. This includes all
19147 -- elementary [sub]types. Tasks are known size even if they have
19148 -- discriminants. So we return False here, with one exception:
19149 -- For a type like:
19150 -- type T (Last : Natural := 0) is
19151 -- X : String (1 .. Last);
19153 -- we return True. That's because for "P(F(...));", where F returns T,
19154 -- we don't know the size of the result at the call site, so if we
19155 -- allocated it on the primary stack, we would have to allocate the
19156 -- maximum size, which is way too big.
19158 elsif Is_Definite_Subtype (Typ) or else Is_Task_Type (Typ) then
19159 return Large_Max_Size_Mutable (Typ);
19161 -- Indefinite (discriminated) untagged record or protected type
19163 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
19164 return not Caller_Known_Size_Record (Typ);
19166 -- Unconstrained array
19169 pragma Assert (Is_Array_Type (Typ) and not Is_Definite_Subtype (Typ));
19172 end New_Requires_Transient_Scope;
19174 --------------------------
19175 -- Reset_Analyzed_Flags --
19176 --------------------------
19178 procedure Reset_Analyzed_Flags (N : Node_Id) is
19180 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
19181 -- Function used to reset Analyzed flags in tree. Note that we do
19182 -- not reset Analyzed flags in entities, since there is no need to
19183 -- reanalyze entities, and indeed, it is wrong to do so, since it
19184 -- can result in generating auxiliary stuff more than once.
19186 --------------------
19187 -- Clear_Analyzed --
19188 --------------------
19190 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
19192 if not Has_Extension (N) then
19193 Set_Analyzed (N, False);
19197 end Clear_Analyzed;
19199 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
19201 -- Start of processing for Reset_Analyzed_Flags
19204 Reset_Analyzed (N);
19205 end Reset_Analyzed_Flags;
19207 ------------------------
19208 -- Restore_SPARK_Mode --
19209 ------------------------
19211 procedure Restore_SPARK_Mode (Mode : SPARK_Mode_Type) is
19213 SPARK_Mode := Mode;
19214 end Restore_SPARK_Mode;
19216 --------------------------------
19217 -- Returns_Unconstrained_Type --
19218 --------------------------------
19220 function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
19222 return Ekind (Subp) = E_Function
19223 and then not Is_Scalar_Type (Etype (Subp))
19224 and then not Is_Access_Type (Etype (Subp))
19225 and then not Is_Constrained (Etype (Subp));
19226 end Returns_Unconstrained_Type;
19228 ----------------------------
19229 -- Root_Type_Of_Full_View --
19230 ----------------------------
19232 function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id is
19233 Rtyp : constant Entity_Id := Root_Type (T);
19236 -- The root type of the full view may itself be a private type. Keep
19237 -- looking for the ultimate derivation parent.
19239 if Is_Private_Type (Rtyp) and then Present (Full_View (Rtyp)) then
19240 return Root_Type_Of_Full_View (Full_View (Rtyp));
19244 end Root_Type_Of_Full_View;
19246 ---------------------------
19247 -- Safe_To_Capture_Value --
19248 ---------------------------
19250 function Safe_To_Capture_Value
19253 Cond : Boolean := False) return Boolean
19256 -- The only entities for which we track constant values are variables
19257 -- which are not renamings, constants, out parameters, and in out
19258 -- parameters, so check if we have this case.
19260 -- Note: it may seem odd to track constant values for constants, but in
19261 -- fact this routine is used for other purposes than simply capturing
19262 -- the value. In particular, the setting of Known[_Non]_Null.
19264 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
19266 Ekind_In (Ent, E_Constant, E_Out_Parameter, E_In_Out_Parameter)
19270 -- For conditionals, we also allow loop parameters and all formals,
19271 -- including in parameters.
19273 elsif Cond and then Ekind_In (Ent, E_Loop_Parameter, E_In_Parameter) then
19276 -- For all other cases, not just unsafe, but impossible to capture
19277 -- Current_Value, since the above are the only entities which have
19278 -- Current_Value fields.
19284 -- Skip if volatile or aliased, since funny things might be going on in
19285 -- these cases which we cannot necessarily track. Also skip any variable
19286 -- for which an address clause is given, or whose address is taken. Also
19287 -- never capture value of library level variables (an attempt to do so
19288 -- can occur in the case of package elaboration code).
19290 if Treat_As_Volatile (Ent)
19291 or else Is_Aliased (Ent)
19292 or else Present (Address_Clause (Ent))
19293 or else Address_Taken (Ent)
19294 or else (Is_Library_Level_Entity (Ent)
19295 and then Ekind (Ent) = E_Variable)
19300 -- OK, all above conditions are met. We also require that the scope of
19301 -- the reference be the same as the scope of the entity, not counting
19302 -- packages and blocks and loops.
19305 E_Scope : constant Entity_Id := Scope (Ent);
19306 R_Scope : Entity_Id;
19309 R_Scope := Current_Scope;
19310 while R_Scope /= Standard_Standard loop
19311 exit when R_Scope = E_Scope;
19313 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
19316 R_Scope := Scope (R_Scope);
19321 -- We also require that the reference does not appear in a context
19322 -- where it is not sure to be executed (i.e. a conditional context
19323 -- or an exception handler). We skip this if Cond is True, since the
19324 -- capturing of values from conditional tests handles this ok.
19337 -- Seems dubious that case expressions are not handled here ???
19340 while Present (P) loop
19341 if Nkind (P) = N_If_Statement
19342 or else Nkind (P) = N_Case_Statement
19343 or else (Nkind (P) in N_Short_Circuit
19344 and then Desc = Right_Opnd (P))
19345 or else (Nkind (P) = N_If_Expression
19346 and then Desc /= First (Expressions (P)))
19347 or else Nkind (P) = N_Exception_Handler
19348 or else Nkind (P) = N_Selective_Accept
19349 or else Nkind (P) = N_Conditional_Entry_Call
19350 or else Nkind (P) = N_Timed_Entry_Call
19351 or else Nkind (P) = N_Asynchronous_Select
19359 -- A special Ada 2012 case: the original node may be part
19360 -- of the else_actions of a conditional expression, in which
19361 -- case it might not have been expanded yet, and appears in
19362 -- a non-syntactic list of actions. In that case it is clearly
19363 -- not safe to save a value.
19366 and then Is_List_Member (Desc)
19367 and then No (Parent (List_Containing (Desc)))
19375 -- OK, looks safe to set value
19378 end Safe_To_Capture_Value;
19384 function Same_Name (N1, N2 : Node_Id) return Boolean is
19385 K1 : constant Node_Kind := Nkind (N1);
19386 K2 : constant Node_Kind := Nkind (N2);
19389 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
19390 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
19392 return Chars (N1) = Chars (N2);
19394 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
19395 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
19397 return Same_Name (Selector_Name (N1), Selector_Name (N2))
19398 and then Same_Name (Prefix (N1), Prefix (N2));
19409 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
19410 N1 : constant Node_Id := Original_Node (Node1);
19411 N2 : constant Node_Id := Original_Node (Node2);
19412 -- We do the tests on original nodes, since we are most interested
19413 -- in the original source, not any expansion that got in the way.
19415 K1 : constant Node_Kind := Nkind (N1);
19416 K2 : constant Node_Kind := Nkind (N2);
19419 -- First case, both are entities with same entity
19421 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
19423 EN1 : constant Entity_Id := Entity (N1);
19424 EN2 : constant Entity_Id := Entity (N2);
19426 if Present (EN1) and then Present (EN2)
19427 and then (Ekind_In (EN1, E_Variable, E_Constant)
19428 or else Is_Formal (EN1))
19436 -- Second case, selected component with same selector, same record
19438 if K1 = N_Selected_Component
19439 and then K2 = N_Selected_Component
19440 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
19442 return Same_Object (Prefix (N1), Prefix (N2));
19444 -- Third case, indexed component with same subscripts, same array
19446 elsif K1 = N_Indexed_Component
19447 and then K2 = N_Indexed_Component
19448 and then Same_Object (Prefix (N1), Prefix (N2))
19453 E1 := First (Expressions (N1));
19454 E2 := First (Expressions (N2));
19455 while Present (E1) loop
19456 if not Same_Value (E1, E2) then
19467 -- Fourth case, slice of same array with same bounds
19470 and then K2 = N_Slice
19471 and then Nkind (Discrete_Range (N1)) = N_Range
19472 and then Nkind (Discrete_Range (N2)) = N_Range
19473 and then Same_Value (Low_Bound (Discrete_Range (N1)),
19474 Low_Bound (Discrete_Range (N2)))
19475 and then Same_Value (High_Bound (Discrete_Range (N1)),
19476 High_Bound (Discrete_Range (N2)))
19478 return Same_Name (Prefix (N1), Prefix (N2));
19480 -- All other cases, not clearly the same object
19491 function Same_Type (T1, T2 : Entity_Id) return Boolean is
19496 elsif not Is_Constrained (T1)
19497 and then not Is_Constrained (T2)
19498 and then Base_Type (T1) = Base_Type (T2)
19502 -- For now don't bother with case of identical constraints, to be
19503 -- fiddled with later on perhaps (this is only used for optimization
19504 -- purposes, so it is not critical to do a best possible job)
19515 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
19517 if Compile_Time_Known_Value (Node1)
19518 and then Compile_Time_Known_Value (Node2)
19519 and then Expr_Value (Node1) = Expr_Value (Node2)
19522 elsif Same_Object (Node1, Node2) then
19529 -----------------------------
19530 -- Save_SPARK_Mode_And_Set --
19531 -----------------------------
19533 procedure Save_SPARK_Mode_And_Set
19534 (Context : Entity_Id;
19535 Mode : out SPARK_Mode_Type)
19538 -- Save the current mode in effect
19540 Mode := SPARK_Mode;
19542 -- Do not consider illegal or partially decorated constructs
19544 if Ekind (Context) = E_Void or else Error_Posted (Context) then
19547 elsif Present (SPARK_Pragma (Context)) then
19548 SPARK_Mode := Get_SPARK_Mode_From_Annotation (SPARK_Pragma (Context));
19550 end Save_SPARK_Mode_And_Set;
19552 -------------------------
19553 -- Scalar_Part_Present --
19554 -------------------------
19556 function Scalar_Part_Present (T : Entity_Id) return Boolean is
19560 if Is_Scalar_Type (T) then
19563 elsif Is_Array_Type (T) then
19564 return Scalar_Part_Present (Component_Type (T));
19566 elsif Is_Record_Type (T) or else Has_Discriminants (T) then
19567 C := First_Component_Or_Discriminant (T);
19568 while Present (C) loop
19569 if Scalar_Part_Present (Etype (C)) then
19572 Next_Component_Or_Discriminant (C);
19578 end Scalar_Part_Present;
19580 ------------------------
19581 -- Scope_Is_Transient --
19582 ------------------------
19584 function Scope_Is_Transient return Boolean is
19586 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
19587 end Scope_Is_Transient;
19593 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
19598 while Scop /= Standard_Standard loop
19599 Scop := Scope (Scop);
19601 if Scop = Scope2 then
19609 --------------------------
19610 -- Scope_Within_Or_Same --
19611 --------------------------
19613 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
19618 while Scop /= Standard_Standard loop
19619 if Scop = Scope2 then
19622 Scop := Scope (Scop);
19627 end Scope_Within_Or_Same;
19629 --------------------
19630 -- Set_Convention --
19631 --------------------
19633 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
19635 Basic_Set_Convention (E, Val);
19638 and then Is_Access_Subprogram_Type (Base_Type (E))
19639 and then Has_Foreign_Convention (E)
19642 -- A pragma Convention in an instance may apply to the subtype
19643 -- created for a formal, in which case we have already verified
19644 -- that conventions of actual and formal match and there is nothing
19645 -- to flag on the subtype.
19647 if In_Instance then
19650 Set_Can_Use_Internal_Rep (E, False);
19654 -- If E is an object or component, and the type of E is an anonymous
19655 -- access type with no convention set, then also set the convention of
19656 -- the anonymous access type. We do not do this for anonymous protected
19657 -- types, since protected types always have the default convention.
19659 if Present (Etype (E))
19660 and then (Is_Object (E)
19661 or else Ekind (E) = E_Component
19663 -- Allow E_Void (happens for pragma Convention appearing
19664 -- in the middle of a record applying to a component)
19666 or else Ekind (E) = E_Void)
19669 Typ : constant Entity_Id := Etype (E);
19672 if Ekind_In (Typ, E_Anonymous_Access_Type,
19673 E_Anonymous_Access_Subprogram_Type)
19674 and then not Has_Convention_Pragma (Typ)
19676 Basic_Set_Convention (Typ, Val);
19677 Set_Has_Convention_Pragma (Typ);
19679 -- And for the access subprogram type, deal similarly with the
19680 -- designated E_Subprogram_Type if it is also internal (which
19683 if Ekind (Typ) = E_Anonymous_Access_Subprogram_Type then
19685 Dtype : constant Entity_Id := Designated_Type (Typ);
19687 if Ekind (Dtype) = E_Subprogram_Type
19688 and then Is_Itype (Dtype)
19689 and then not Has_Convention_Pragma (Dtype)
19691 Basic_Set_Convention (Dtype, Val);
19692 Set_Has_Convention_Pragma (Dtype);
19699 end Set_Convention;
19701 ------------------------
19702 -- Set_Current_Entity --
19703 ------------------------
19705 -- The given entity is to be set as the currently visible definition of its
19706 -- associated name (i.e. the Node_Id associated with its name). All we have
19707 -- to do is to get the name from the identifier, and then set the
19708 -- associated Node_Id to point to the given entity.
19710 procedure Set_Current_Entity (E : Entity_Id) is
19712 Set_Name_Entity_Id (Chars (E), E);
19713 end Set_Current_Entity;
19715 ---------------------------
19716 -- Set_Debug_Info_Needed --
19717 ---------------------------
19719 procedure Set_Debug_Info_Needed (T : Entity_Id) is
19721 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
19722 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
19723 -- Used to set debug info in a related node if not set already
19725 --------------------------------------
19726 -- Set_Debug_Info_Needed_If_Not_Set --
19727 --------------------------------------
19729 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
19731 if Present (E) and then not Needs_Debug_Info (E) then
19732 Set_Debug_Info_Needed (E);
19734 -- For a private type, indicate that the full view also needs
19735 -- debug information.
19738 and then Is_Private_Type (E)
19739 and then Present (Full_View (E))
19741 Set_Debug_Info_Needed (Full_View (E));
19744 end Set_Debug_Info_Needed_If_Not_Set;
19746 -- Start of processing for Set_Debug_Info_Needed
19749 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
19750 -- indicates that Debug_Info_Needed is never required for the entity.
19751 -- Nothing to do if entity comes from a predefined file. Library files
19752 -- are compiled without debug information, but inlined bodies of these
19753 -- routines may appear in user code, and debug information on them ends
19754 -- up complicating debugging the user code.
19757 or else Debug_Info_Off (T)
19761 elsif In_Inlined_Body
19762 and then Is_Predefined_File_Name
19763 (Unit_File_Name (Get_Source_Unit (Sloc (T))))
19765 Set_Needs_Debug_Info (T, False);
19768 -- Set flag in entity itself. Note that we will go through the following
19769 -- circuitry even if the flag is already set on T. That's intentional,
19770 -- it makes sure that the flag will be set in subsidiary entities.
19772 Set_Needs_Debug_Info (T);
19774 -- Set flag on subsidiary entities if not set already
19776 if Is_Object (T) then
19777 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
19779 elsif Is_Type (T) then
19780 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
19782 if Is_Record_Type (T) then
19784 Ent : Entity_Id := First_Entity (T);
19786 while Present (Ent) loop
19787 Set_Debug_Info_Needed_If_Not_Set (Ent);
19792 -- For a class wide subtype, we also need debug information
19793 -- for the equivalent type.
19795 if Ekind (T) = E_Class_Wide_Subtype then
19796 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
19799 elsif Is_Array_Type (T) then
19800 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
19803 Indx : Node_Id := First_Index (T);
19805 while Present (Indx) loop
19806 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
19807 Indx := Next_Index (Indx);
19811 -- For a packed array type, we also need debug information for
19812 -- the type used to represent the packed array. Conversely, we
19813 -- also need it for the former if we need it for the latter.
19815 if Is_Packed (T) then
19816 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Impl_Type (T));
19819 if Is_Packed_Array_Impl_Type (T) then
19820 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
19823 elsif Is_Access_Type (T) then
19824 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
19826 elsif Is_Private_Type (T) then
19828 FV : constant Entity_Id := Full_View (T);
19831 Set_Debug_Info_Needed_If_Not_Set (FV);
19833 -- If the full view is itself a derived private type, we need
19834 -- debug information on its underlying type.
19837 and then Is_Private_Type (FV)
19838 and then Present (Underlying_Full_View (FV))
19840 Set_Needs_Debug_Info (Underlying_Full_View (FV));
19844 elsif Is_Protected_Type (T) then
19845 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
19847 elsif Is_Scalar_Type (T) then
19849 -- If the subrange bounds are materialized by dedicated constant
19850 -- objects, also include them in the debug info to make sure the
19851 -- debugger can properly use them.
19853 if Present (Scalar_Range (T))
19854 and then Nkind (Scalar_Range (T)) = N_Range
19857 Low_Bnd : constant Node_Id := Type_Low_Bound (T);
19858 High_Bnd : constant Node_Id := Type_High_Bound (T);
19861 if Is_Entity_Name (Low_Bnd) then
19862 Set_Debug_Info_Needed_If_Not_Set (Entity (Low_Bnd));
19865 if Is_Entity_Name (High_Bnd) then
19866 Set_Debug_Info_Needed_If_Not_Set (Entity (High_Bnd));
19872 end Set_Debug_Info_Needed;
19874 ----------------------------
19875 -- Set_Entity_With_Checks --
19876 ----------------------------
19878 procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id) is
19879 Val_Actual : Entity_Id;
19881 Post_Node : Node_Id;
19884 -- Unconditionally set the entity
19886 Set_Entity (N, Val);
19888 -- The node to post on is the selector in the case of an expanded name,
19889 -- and otherwise the node itself.
19891 if Nkind (N) = N_Expanded_Name then
19892 Post_Node := Selector_Name (N);
19897 -- Check for violation of No_Fixed_IO
19899 if Restriction_Check_Required (No_Fixed_IO)
19901 ((RTU_Loaded (Ada_Text_IO)
19902 and then (Is_RTE (Val, RE_Decimal_IO)
19904 Is_RTE (Val, RE_Fixed_IO)))
19907 (RTU_Loaded (Ada_Wide_Text_IO)
19908 and then (Is_RTE (Val, RO_WT_Decimal_IO)
19910 Is_RTE (Val, RO_WT_Fixed_IO)))
19913 (RTU_Loaded (Ada_Wide_Wide_Text_IO)
19914 and then (Is_RTE (Val, RO_WW_Decimal_IO)
19916 Is_RTE (Val, RO_WW_Fixed_IO))))
19918 -- A special extra check, don't complain about a reference from within
19919 -- the Ada.Interrupts package itself!
19921 and then not In_Same_Extended_Unit (N, Val)
19923 Check_Restriction (No_Fixed_IO, Post_Node);
19926 -- Remaining checks are only done on source nodes. Note that we test
19927 -- for violation of No_Fixed_IO even on non-source nodes, because the
19928 -- cases for checking violations of this restriction are instantiations
19929 -- where the reference in the instance has Comes_From_Source False.
19931 if not Comes_From_Source (N) then
19935 -- Check for violation of No_Abort_Statements, which is triggered by
19936 -- call to Ada.Task_Identification.Abort_Task.
19938 if Restriction_Check_Required (No_Abort_Statements)
19939 and then (Is_RTE (Val, RE_Abort_Task))
19941 -- A special extra check, don't complain about a reference from within
19942 -- the Ada.Task_Identification package itself!
19944 and then not In_Same_Extended_Unit (N, Val)
19946 Check_Restriction (No_Abort_Statements, Post_Node);
19949 if Val = Standard_Long_Long_Integer then
19950 Check_Restriction (No_Long_Long_Integers, Post_Node);
19953 -- Check for violation of No_Dynamic_Attachment
19955 if Restriction_Check_Required (No_Dynamic_Attachment)
19956 and then RTU_Loaded (Ada_Interrupts)
19957 and then (Is_RTE (Val, RE_Is_Reserved) or else
19958 Is_RTE (Val, RE_Is_Attached) or else
19959 Is_RTE (Val, RE_Current_Handler) or else
19960 Is_RTE (Val, RE_Attach_Handler) or else
19961 Is_RTE (Val, RE_Exchange_Handler) or else
19962 Is_RTE (Val, RE_Detach_Handler) or else
19963 Is_RTE (Val, RE_Reference))
19965 -- A special extra check, don't complain about a reference from within
19966 -- the Ada.Interrupts package itself!
19968 and then not In_Same_Extended_Unit (N, Val)
19970 Check_Restriction (No_Dynamic_Attachment, Post_Node);
19973 -- Check for No_Implementation_Identifiers
19975 if Restriction_Check_Required (No_Implementation_Identifiers) then
19977 -- We have an implementation defined entity if it is marked as
19978 -- implementation defined, or is defined in a package marked as
19979 -- implementation defined. However, library packages themselves
19980 -- are excluded (we don't want to flag Interfaces itself, just
19981 -- the entities within it).
19983 if (Is_Implementation_Defined (Val)
19985 (Present (Scope (Val))
19986 and then Is_Implementation_Defined (Scope (Val))))
19987 and then not (Ekind_In (Val, E_Package, E_Generic_Package)
19988 and then Is_Library_Level_Entity (Val))
19990 Check_Restriction (No_Implementation_Identifiers, Post_Node);
19994 -- Do the style check
19997 and then not Suppress_Style_Checks (Val)
19998 and then not In_Instance
20000 if Nkind (N) = N_Identifier then
20002 elsif Nkind (N) = N_Expanded_Name then
20003 Nod := Selector_Name (N);
20008 -- A special situation arises for derived operations, where we want
20009 -- to do the check against the parent (since the Sloc of the derived
20010 -- operation points to the derived type declaration itself).
20013 while not Comes_From_Source (Val_Actual)
20014 and then Nkind (Val_Actual) in N_Entity
20015 and then (Ekind (Val_Actual) = E_Enumeration_Literal
20016 or else Is_Subprogram_Or_Generic_Subprogram (Val_Actual))
20017 and then Present (Alias (Val_Actual))
20019 Val_Actual := Alias (Val_Actual);
20022 -- Renaming declarations for generic actuals do not come from source,
20023 -- and have a different name from that of the entity they rename, so
20024 -- there is no style check to perform here.
20026 if Chars (Nod) = Chars (Val_Actual) then
20027 Style.Check_Identifier (Nod, Val_Actual);
20031 Set_Entity (N, Val);
20032 end Set_Entity_With_Checks;
20034 ------------------------
20035 -- Set_Name_Entity_Id --
20036 ------------------------
20038 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
20040 Set_Name_Table_Int (Id, Int (Val));
20041 end Set_Name_Entity_Id;
20043 ---------------------
20044 -- Set_Next_Actual --
20045 ---------------------
20047 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
20049 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
20050 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
20052 end Set_Next_Actual;
20054 ----------------------------------
20055 -- Set_Optimize_Alignment_Flags --
20056 ----------------------------------
20058 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
20060 if Optimize_Alignment = 'S' then
20061 Set_Optimize_Alignment_Space (E);
20062 elsif Optimize_Alignment = 'T' then
20063 Set_Optimize_Alignment_Time (E);
20065 end Set_Optimize_Alignment_Flags;
20067 -----------------------
20068 -- Set_Public_Status --
20069 -----------------------
20071 procedure Set_Public_Status (Id : Entity_Id) is
20072 S : constant Entity_Id := Current_Scope;
20074 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
20075 -- Determines if E is defined within handled statement sequence or
20076 -- an if statement, returns True if so, False otherwise.
20078 ----------------------
20079 -- Within_HSS_Or_If --
20080 ----------------------
20082 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
20085 N := Declaration_Node (E);
20092 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
20098 end Within_HSS_Or_If;
20100 -- Start of processing for Set_Public_Status
20103 -- Everything in the scope of Standard is public
20105 if S = Standard_Standard then
20106 Set_Is_Public (Id);
20108 -- Entity is definitely not public if enclosing scope is not public
20110 elsif not Is_Public (S) then
20113 -- An object or function declaration that occurs in a handled sequence
20114 -- of statements or within an if statement is the declaration for a
20115 -- temporary object or local subprogram generated by the expander. It
20116 -- never needs to be made public and furthermore, making it public can
20117 -- cause back end problems.
20119 elsif Nkind_In (Parent (Id), N_Object_Declaration,
20120 N_Function_Specification)
20121 and then Within_HSS_Or_If (Id)
20125 -- Entities in public packages or records are public
20127 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
20128 Set_Is_Public (Id);
20130 -- The bounds of an entry family declaration can generate object
20131 -- declarations that are visible to the back-end, e.g. in the
20132 -- the declaration of a composite type that contains tasks.
20134 elsif Is_Concurrent_Type (S)
20135 and then not Has_Completion (S)
20136 and then Nkind (Parent (Id)) = N_Object_Declaration
20138 Set_Is_Public (Id);
20140 end Set_Public_Status;
20142 -----------------------------
20143 -- Set_Referenced_Modified --
20144 -----------------------------
20146 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
20150 -- Deal with indexed or selected component where prefix is modified
20152 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
20153 Pref := Prefix (N);
20155 -- If prefix is access type, then it is the designated object that is
20156 -- being modified, which means we have no entity to set the flag on.
20158 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
20161 -- Otherwise chase the prefix
20164 Set_Referenced_Modified (Pref, Out_Param);
20167 -- Otherwise see if we have an entity name (only other case to process)
20169 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
20170 Set_Referenced_As_LHS (Entity (N), not Out_Param);
20171 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
20173 end Set_Referenced_Modified;
20175 ----------------------------
20176 -- Set_Scope_Is_Transient --
20177 ----------------------------
20179 procedure Set_Scope_Is_Transient (V : Boolean := True) is
20181 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
20182 end Set_Scope_Is_Transient;
20184 -------------------
20185 -- Set_Size_Info --
20186 -------------------
20188 procedure Set_Size_Info (T1, T2 : Entity_Id) is
20190 -- We copy Esize, but not RM_Size, since in general RM_Size is
20191 -- subtype specific and does not get inherited by all subtypes.
20193 Set_Esize (T1, Esize (T2));
20194 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
20196 if Is_Discrete_Or_Fixed_Point_Type (T1)
20198 Is_Discrete_Or_Fixed_Point_Type (T2)
20200 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
20203 Set_Alignment (T1, Alignment (T2));
20206 --------------------
20207 -- Static_Boolean --
20208 --------------------
20210 function Static_Boolean (N : Node_Id) return Uint is
20212 Analyze_And_Resolve (N, Standard_Boolean);
20215 or else Error_Posted (N)
20216 or else Etype (N) = Any_Type
20221 if Is_OK_Static_Expression (N) then
20222 if not Raises_Constraint_Error (N) then
20223 return Expr_Value (N);
20228 elsif Etype (N) = Any_Type then
20232 Flag_Non_Static_Expr
20233 ("static boolean expression required here", N);
20236 end Static_Boolean;
20238 --------------------
20239 -- Static_Integer --
20240 --------------------
20242 function Static_Integer (N : Node_Id) return Uint is
20244 Analyze_And_Resolve (N, Any_Integer);
20247 or else Error_Posted (N)
20248 or else Etype (N) = Any_Type
20253 if Is_OK_Static_Expression (N) then
20254 if not Raises_Constraint_Error (N) then
20255 return Expr_Value (N);
20260 elsif Etype (N) = Any_Type then
20264 Flag_Non_Static_Expr
20265 ("static integer expression required here", N);
20268 end Static_Integer;
20270 --------------------------
20271 -- Statically_Different --
20272 --------------------------
20274 function Statically_Different (E1, E2 : Node_Id) return Boolean is
20275 R1 : constant Node_Id := Get_Referenced_Object (E1);
20276 R2 : constant Node_Id := Get_Referenced_Object (E2);
20278 return Is_Entity_Name (R1)
20279 and then Is_Entity_Name (R2)
20280 and then Entity (R1) /= Entity (R2)
20281 and then not Is_Formal (Entity (R1))
20282 and then not Is_Formal (Entity (R2));
20283 end Statically_Different;
20285 --------------------------------------
20286 -- Subject_To_Loop_Entry_Attributes --
20287 --------------------------------------
20289 function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
20295 -- The expansion mechanism transform a loop subject to at least one
20296 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
20297 -- the conditional part.
20299 if Nkind_In (Stmt, N_Block_Statement, N_If_Statement)
20300 and then Nkind (Original_Node (N)) = N_Loop_Statement
20302 Stmt := Original_Node (N);
20306 Nkind (Stmt) = N_Loop_Statement
20307 and then Present (Identifier (Stmt))
20308 and then Present (Entity (Identifier (Stmt)))
20309 and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
20310 end Subject_To_Loop_Entry_Attributes;
20312 -----------------------------
20313 -- Subprogram_Access_Level --
20314 -----------------------------
20316 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
20318 if Present (Alias (Subp)) then
20319 return Subprogram_Access_Level (Alias (Subp));
20321 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
20323 end Subprogram_Access_Level;
20325 -------------------------------
20326 -- Support_Atomic_Primitives --
20327 -------------------------------
20329 function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
20333 -- Verify the alignment of Typ is known
20335 if not Known_Alignment (Typ) then
20339 if Known_Static_Esize (Typ) then
20340 Size := UI_To_Int (Esize (Typ));
20342 -- If the Esize (Object_Size) is unknown at compile time, look at the
20343 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
20345 elsif Known_Static_RM_Size (Typ) then
20346 Size := UI_To_Int (RM_Size (Typ));
20348 -- Otherwise, the size is considered to be unknown.
20354 -- Check that the size of the component is 8, 16, 32, or 64 bits and
20355 -- that Typ is properly aligned.
20358 when 8 | 16 | 32 | 64 =>
20359 return Size = UI_To_Int (Alignment (Typ)) * 8;
20363 end Support_Atomic_Primitives;
20369 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
20371 if Debug_Flag_W then
20372 for J in 0 .. Scope_Stack.Last loop
20377 Write_Name (Chars (E));
20378 Write_Str (" from ");
20379 Write_Location (Sloc (N));
20384 -----------------------
20385 -- Transfer_Entities --
20386 -----------------------
20388 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
20389 procedure Set_Public_Status_Of (Id : Entity_Id);
20390 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
20391 -- Set_Public_Status. If successfull and Id denotes a record type, set
20392 -- the Is_Public attribute of its fields.
20394 --------------------------
20395 -- Set_Public_Status_Of --
20396 --------------------------
20398 procedure Set_Public_Status_Of (Id : Entity_Id) is
20402 if not Is_Public (Id) then
20403 Set_Public_Status (Id);
20405 -- When the input entity is a public record type, ensure that all
20406 -- its internal fields are also exposed to the linker. The fields
20407 -- of a class-wide type are never made public.
20410 and then Is_Record_Type (Id)
20411 and then not Is_Class_Wide_Type (Id)
20413 Field := First_Entity (Id);
20414 while Present (Field) loop
20415 Set_Is_Public (Field);
20416 Next_Entity (Field);
20420 end Set_Public_Status_Of;
20424 Full_Id : Entity_Id;
20427 -- Start of processing for Transfer_Entities
20430 Id := First_Entity (From);
20432 if Present (Id) then
20434 -- Merge the entity chain of the source scope with that of the
20435 -- destination scope.
20437 if Present (Last_Entity (To)) then
20438 Set_Next_Entity (Last_Entity (To), Id);
20440 Set_First_Entity (To, Id);
20443 Set_Last_Entity (To, Last_Entity (From));
20445 -- Inspect the entities of the source scope and update their Scope
20448 while Present (Id) loop
20449 Set_Scope (Id, To);
20450 Set_Public_Status_Of (Id);
20452 -- Handle an internally generated full view for a private type
20454 if Is_Private_Type (Id)
20455 and then Present (Full_View (Id))
20456 and then Is_Itype (Full_View (Id))
20458 Full_Id := Full_View (Id);
20460 Set_Scope (Full_Id, To);
20461 Set_Public_Status_Of (Full_Id);
20467 Set_First_Entity (From, Empty);
20468 Set_Last_Entity (From, Empty);
20470 end Transfer_Entities;
20472 -----------------------
20473 -- Type_Access_Level --
20474 -----------------------
20476 function Type_Access_Level (Typ : Entity_Id) return Uint is
20480 Btyp := Base_Type (Typ);
20482 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
20483 -- simply use the level where the type is declared. This is true for
20484 -- stand-alone object declarations, and for anonymous access types
20485 -- associated with components the level is the same as that of the
20486 -- enclosing composite type. However, special treatment is needed for
20487 -- the cases of access parameters, return objects of an anonymous access
20488 -- type, and, in Ada 95, access discriminants of limited types.
20490 if Is_Access_Type (Btyp) then
20491 if Ekind (Btyp) = E_Anonymous_Access_Type then
20493 -- If the type is a nonlocal anonymous access type (such as for
20494 -- an access parameter) we treat it as being declared at the
20495 -- library level to ensure that names such as X.all'access don't
20496 -- fail static accessibility checks.
20498 if not Is_Local_Anonymous_Access (Typ) then
20499 return Scope_Depth (Standard_Standard);
20501 -- If this is a return object, the accessibility level is that of
20502 -- the result subtype of the enclosing function. The test here is
20503 -- little complicated, because we have to account for extended
20504 -- return statements that have been rewritten as blocks, in which
20505 -- case we have to find and the Is_Return_Object attribute of the
20506 -- itype's associated object. It would be nice to find a way to
20507 -- simplify this test, but it doesn't seem worthwhile to add a new
20508 -- flag just for purposes of this test. ???
20510 elsif Ekind (Scope (Btyp)) = E_Return_Statement
20513 and then Nkind (Associated_Node_For_Itype (Btyp)) =
20514 N_Object_Declaration
20515 and then Is_Return_Object
20516 (Defining_Identifier
20517 (Associated_Node_For_Itype (Btyp))))
20523 Scop := Scope (Scope (Btyp));
20524 while Present (Scop) loop
20525 exit when Ekind (Scop) = E_Function;
20526 Scop := Scope (Scop);
20529 -- Treat the return object's type as having the level of the
20530 -- function's result subtype (as per RM05-6.5(5.3/2)).
20532 return Type_Access_Level (Etype (Scop));
20537 Btyp := Root_Type (Btyp);
20539 -- The accessibility level of anonymous access types associated with
20540 -- discriminants is that of the current instance of the type, and
20541 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
20543 -- AI-402: access discriminants have accessibility based on the
20544 -- object rather than the type in Ada 2005, so the above paragraph
20547 -- ??? Needs completion with rules from AI-416
20549 if Ada_Version <= Ada_95
20550 and then Ekind (Typ) = E_Anonymous_Access_Type
20551 and then Present (Associated_Node_For_Itype (Typ))
20552 and then Nkind (Associated_Node_For_Itype (Typ)) =
20553 N_Discriminant_Specification
20555 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
20559 -- Return library level for a generic formal type. This is done because
20560 -- RM(10.3.2) says that "The statically deeper relationship does not
20561 -- apply to ... a descendant of a generic formal type". Rather than
20562 -- checking at each point where a static accessibility check is
20563 -- performed to see if we are dealing with a formal type, this rule is
20564 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
20565 -- return extreme values for a formal type; Deepest_Type_Access_Level
20566 -- returns Int'Last. By calling the appropriate function from among the
20567 -- two, we ensure that the static accessibility check will pass if we
20568 -- happen to run into a formal type. More specifically, we should call
20569 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
20570 -- call occurs as part of a static accessibility check and the error
20571 -- case is the case where the type's level is too shallow (as opposed
20574 if Is_Generic_Type (Root_Type (Btyp)) then
20575 return Scope_Depth (Standard_Standard);
20578 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
20579 end Type_Access_Level;
20581 ------------------------------------
20582 -- Type_Without_Stream_Operation --
20583 ------------------------------------
20585 function Type_Without_Stream_Operation
20587 Op : TSS_Name_Type := TSS_Null) return Entity_Id
20589 BT : constant Entity_Id := Base_Type (T);
20590 Op_Missing : Boolean;
20593 if not Restriction_Active (No_Default_Stream_Attributes) then
20597 if Is_Elementary_Type (T) then
20598 if Op = TSS_Null then
20600 No (TSS (BT, TSS_Stream_Read))
20601 or else No (TSS (BT, TSS_Stream_Write));
20604 Op_Missing := No (TSS (BT, Op));
20613 elsif Is_Array_Type (T) then
20614 return Type_Without_Stream_Operation (Component_Type (T), Op);
20616 elsif Is_Record_Type (T) then
20622 Comp := First_Component (T);
20623 while Present (Comp) loop
20624 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
20626 if Present (C_Typ) then
20630 Next_Component (Comp);
20636 elsif Is_Private_Type (T) and then Present (Full_View (T)) then
20637 return Type_Without_Stream_Operation (Full_View (T), Op);
20641 end Type_Without_Stream_Operation;
20643 ----------------------------
20644 -- Unique_Defining_Entity --
20645 ----------------------------
20647 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
20649 return Unique_Entity (Defining_Entity (N));
20650 end Unique_Defining_Entity;
20652 -------------------
20653 -- Unique_Entity --
20654 -------------------
20656 function Unique_Entity (E : Entity_Id) return Entity_Id is
20657 U : Entity_Id := E;
20663 if Present (Full_View (E)) then
20664 U := Full_View (E);
20668 if Nkind (Parent (E)) = N_Entry_Body then
20670 Prot_Item : Entity_Id;
20671 Prot_Type : Entity_Id;
20674 if Ekind (E) = E_Entry then
20675 Prot_Type := Scope (E);
20677 -- Bodies of entry families are nested within an extra scope
20678 -- that contains an entry index declaration
20681 Prot_Type := Scope (Scope (E));
20684 pragma Assert (Ekind (Prot_Type) = E_Protected_Type);
20686 -- Traverse the entity list of the protected type and locate
20687 -- an entry declaration which matches the entry body.
20689 Prot_Item := First_Entity (Prot_Type);
20690 while Present (Prot_Item) loop
20691 if Ekind (Prot_Item) in Entry_Kind
20692 and then Corresponding_Body (Parent (Prot_Item)) = E
20698 Next_Entity (Prot_Item);
20703 when Formal_Kind =>
20704 if Present (Spec_Entity (E)) then
20705 U := Spec_Entity (E);
20708 when E_Package_Body =>
20711 if Nkind (P) = N_Defining_Program_Unit_Name then
20715 if Nkind (P) = N_Package_Body
20716 and then Present (Corresponding_Spec (P))
20718 U := Corresponding_Spec (P);
20720 elsif Nkind (P) = N_Package_Body_Stub
20721 and then Present (Corresponding_Spec_Of_Stub (P))
20723 U := Corresponding_Spec_Of_Stub (P);
20726 when E_Protected_Body =>
20729 if Nkind (P) = N_Protected_Body
20730 and then Present (Corresponding_Spec (P))
20732 U := Corresponding_Spec (P);
20734 elsif Nkind (P) = N_Protected_Body_Stub
20735 and then Present (Corresponding_Spec_Of_Stub (P))
20737 U := Corresponding_Spec_Of_Stub (P);
20739 if Is_Single_Protected_Object (U) then
20744 when E_Subprogram_Body =>
20747 if Nkind (P) = N_Defining_Program_Unit_Name then
20753 if Nkind (P) = N_Subprogram_Body
20754 and then Present (Corresponding_Spec (P))
20756 U := Corresponding_Spec (P);
20758 elsif Nkind (P) = N_Subprogram_Body_Stub
20759 and then Present (Corresponding_Spec_Of_Stub (P))
20761 U := Corresponding_Spec_Of_Stub (P);
20763 elsif Nkind (P) = N_Subprogram_Renaming_Declaration then
20764 U := Corresponding_Spec (P);
20767 when E_Task_Body =>
20770 if Nkind (P) = N_Task_Body
20771 and then Present (Corresponding_Spec (P))
20773 U := Corresponding_Spec (P);
20775 elsif Nkind (P) = N_Task_Body_Stub
20776 and then Present (Corresponding_Spec_Of_Stub (P))
20778 U := Corresponding_Spec_Of_Stub (P);
20780 if Is_Single_Task_Object (U) then
20786 if Present (Full_View (E)) then
20787 U := Full_View (E);
20801 function Unique_Name (E : Entity_Id) return String is
20803 -- Names of E_Subprogram_Body or E_Package_Body entities are not
20804 -- reliable, as they may not include the overloading suffix. Instead,
20805 -- when looking for the name of E or one of its enclosing scope, we get
20806 -- the name of the corresponding Unique_Entity.
20808 function Get_Scoped_Name (E : Entity_Id) return String;
20809 -- Return the name of E prefixed by all the names of the scopes to which
20810 -- E belongs, except for Standard.
20812 ---------------------
20813 -- Get_Scoped_Name --
20814 ---------------------
20816 function Get_Scoped_Name (E : Entity_Id) return String is
20817 Name : constant String := Get_Name_String (Chars (E));
20819 if Has_Fully_Qualified_Name (E)
20820 or else Scope (E) = Standard_Standard
20824 return Get_Scoped_Name (Unique_Entity (Scope (E))) & "__" & Name;
20826 end Get_Scoped_Name;
20828 -- Start of processing for Unique_Name
20831 if E = Standard_Standard then
20832 return Get_Name_String (Name_Standard);
20834 elsif Scope (E) = Standard_Standard
20835 and then not (Ekind (E) = E_Package or else Is_Subprogram (E))
20837 return Get_Name_String (Name_Standard) & "__" &
20838 Get_Name_String (Chars (E));
20840 elsif Ekind (E) = E_Enumeration_Literal then
20841 return Unique_Name (Etype (E)) & "__" & Get_Name_String (Chars (E));
20844 return Get_Scoped_Name (Unique_Entity (E));
20848 ---------------------
20849 -- Unit_Is_Visible --
20850 ---------------------
20852 function Unit_Is_Visible (U : Entity_Id) return Boolean is
20853 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
20854 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
20856 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
20857 -- For a child unit, check whether unit appears in a with_clause
20860 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
20861 -- Scan the context clause of one compilation unit looking for a
20862 -- with_clause for the unit in question.
20864 ----------------------------
20865 -- Unit_In_Parent_Context --
20866 ----------------------------
20868 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
20870 if Unit_In_Context (Par_Unit) then
20873 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
20874 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
20879 end Unit_In_Parent_Context;
20881 ---------------------
20882 -- Unit_In_Context --
20883 ---------------------
20885 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
20889 Clause := First (Context_Items (Comp_Unit));
20890 while Present (Clause) loop
20891 if Nkind (Clause) = N_With_Clause then
20892 if Library_Unit (Clause) = U then
20895 -- The with_clause may denote a renaming of the unit we are
20896 -- looking for, eg. Text_IO which renames Ada.Text_IO.
20899 Renamed_Entity (Entity (Name (Clause))) =
20900 Defining_Entity (Unit (U))
20910 end Unit_In_Context;
20912 -- Start of processing for Unit_Is_Visible
20915 -- The currrent unit is directly visible
20920 elsif Unit_In_Context (Curr) then
20923 -- If the current unit is a body, check the context of the spec
20925 elsif Nkind (Unit (Curr)) = N_Package_Body
20927 (Nkind (Unit (Curr)) = N_Subprogram_Body
20928 and then not Acts_As_Spec (Unit (Curr)))
20930 if Unit_In_Context (Library_Unit (Curr)) then
20935 -- If the spec is a child unit, examine the parents
20937 if Is_Child_Unit (Curr_Entity) then
20938 if Nkind (Unit (Curr)) in N_Unit_Body then
20940 Unit_In_Parent_Context
20941 (Parent_Spec (Unit (Library_Unit (Curr))));
20943 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
20949 end Unit_Is_Visible;
20951 ------------------------------
20952 -- Universal_Interpretation --
20953 ------------------------------
20955 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
20956 Index : Interp_Index;
20960 -- The argument may be a formal parameter of an operator or subprogram
20961 -- with multiple interpretations, or else an expression for an actual.
20963 if Nkind (Opnd) = N_Defining_Identifier
20964 or else not Is_Overloaded (Opnd)
20966 if Etype (Opnd) = Universal_Integer
20967 or else Etype (Opnd) = Universal_Real
20969 return Etype (Opnd);
20975 Get_First_Interp (Opnd, Index, It);
20976 while Present (It.Typ) loop
20977 if It.Typ = Universal_Integer
20978 or else It.Typ = Universal_Real
20983 Get_Next_Interp (Index, It);
20988 end Universal_Interpretation;
20994 function Unqualify (Expr : Node_Id) return Node_Id is
20996 -- Recurse to handle unlikely case of multiple levels of qualification
20998 if Nkind (Expr) = N_Qualified_Expression then
20999 return Unqualify (Expression (Expr));
21001 -- Normal case, not a qualified expression
21008 -----------------------
21009 -- Visible_Ancestors --
21010 -----------------------
21012 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
21018 pragma Assert (Is_Record_Type (Typ) and then Is_Tagged_Type (Typ));
21020 -- Collect all the parents and progenitors of Typ. If the full-view of
21021 -- private parents and progenitors is available then it is used to
21022 -- generate the list of visible ancestors; otherwise their partial
21023 -- view is added to the resulting list.
21028 Use_Full_View => True);
21032 Ifaces_List => List_2,
21033 Exclude_Parents => True,
21034 Use_Full_View => True);
21036 -- Join the two lists. Avoid duplications because an interface may
21037 -- simultaneously be parent and progenitor of a type.
21039 Elmt := First_Elmt (List_2);
21040 while Present (Elmt) loop
21041 Append_Unique_Elmt (Node (Elmt), List_1);
21046 end Visible_Ancestors;
21048 ----------------------
21049 -- Within_Init_Proc --
21050 ----------------------
21052 function Within_Init_Proc return Boolean is
21056 S := Current_Scope;
21057 while not Is_Overloadable (S) loop
21058 if S = Standard_Standard then
21065 return Is_Init_Proc (S);
21066 end Within_Init_Proc;
21072 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
21074 return Scope_Within_Or_Same (Scope (E), S);
21081 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
21082 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
21083 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
21085 Matching_Field : Entity_Id;
21086 -- Entity to give a more precise suggestion on how to write a one-
21087 -- element positional aggregate.
21089 function Has_One_Matching_Field return Boolean;
21090 -- Determines if Expec_Type is a record type with a single component or
21091 -- discriminant whose type matches the found type or is one dimensional
21092 -- array whose component type matches the found type. In the case of
21093 -- one discriminant, we ignore the variant parts. That's not accurate,
21094 -- but good enough for the warning.
21096 ----------------------------
21097 -- Has_One_Matching_Field --
21098 ----------------------------
21100 function Has_One_Matching_Field return Boolean is
21104 Matching_Field := Empty;
21106 if Is_Array_Type (Expec_Type)
21107 and then Number_Dimensions (Expec_Type) = 1
21108 and then Covers (Etype (Component_Type (Expec_Type)), Found_Type)
21110 -- Use type name if available. This excludes multidimensional
21111 -- arrays and anonymous arrays.
21113 if Comes_From_Source (Expec_Type) then
21114 Matching_Field := Expec_Type;
21116 -- For an assignment, use name of target
21118 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
21119 and then Is_Entity_Name (Name (Parent (Expr)))
21121 Matching_Field := Entity (Name (Parent (Expr)));
21126 elsif not Is_Record_Type (Expec_Type) then
21130 E := First_Entity (Expec_Type);
21135 elsif not Ekind_In (E, E_Discriminant, E_Component)
21136 or else Nam_In (Chars (E), Name_uTag, Name_uParent)
21145 if not Covers (Etype (E), Found_Type) then
21148 elsif Present (Next_Entity (E))
21149 and then (Ekind (E) = E_Component
21150 or else Ekind (Next_Entity (E)) = E_Discriminant)
21155 Matching_Field := E;
21159 end Has_One_Matching_Field;
21161 -- Start of processing for Wrong_Type
21164 -- Don't output message if either type is Any_Type, or if a message
21165 -- has already been posted for this node. We need to do the latter
21166 -- check explicitly (it is ordinarily done in Errout), because we
21167 -- are using ! to force the output of the error messages.
21169 if Expec_Type = Any_Type
21170 or else Found_Type = Any_Type
21171 or else Error_Posted (Expr)
21175 -- If one of the types is a Taft-Amendment type and the other it its
21176 -- completion, it must be an illegal use of a TAT in the spec, for
21177 -- which an error was already emitted. Avoid cascaded errors.
21179 elsif Is_Incomplete_Type (Expec_Type)
21180 and then Has_Completion_In_Body (Expec_Type)
21181 and then Full_View (Expec_Type) = Etype (Expr)
21185 elsif Is_Incomplete_Type (Etype (Expr))
21186 and then Has_Completion_In_Body (Etype (Expr))
21187 and then Full_View (Etype (Expr)) = Expec_Type
21191 -- In an instance, there is an ongoing problem with completion of
21192 -- type derived from private types. Their structure is what Gigi
21193 -- expects, but the Etype is the parent type rather than the
21194 -- derived private type itself. Do not flag error in this case. The
21195 -- private completion is an entity without a parent, like an Itype.
21196 -- Similarly, full and partial views may be incorrect in the instance.
21197 -- There is no simple way to insure that it is consistent ???
21199 -- A similar view discrepancy can happen in an inlined body, for the
21200 -- same reason: inserted body may be outside of the original package
21201 -- and only partial views are visible at the point of insertion.
21203 elsif In_Instance or else In_Inlined_Body then
21204 if Etype (Etype (Expr)) = Etype (Expected_Type)
21206 (Has_Private_Declaration (Expected_Type)
21207 or else Has_Private_Declaration (Etype (Expr)))
21208 and then No (Parent (Expected_Type))
21212 elsif Nkind (Parent (Expr)) = N_Qualified_Expression
21213 and then Entity (Subtype_Mark (Parent (Expr))) = Expected_Type
21217 elsif Is_Private_Type (Expected_Type)
21218 and then Present (Full_View (Expected_Type))
21219 and then Covers (Full_View (Expected_Type), Etype (Expr))
21223 -- Conversely, type of expression may be the private one
21225 elsif Is_Private_Type (Base_Type (Etype (Expr)))
21226 and then Full_View (Base_Type (Etype (Expr))) = Expected_Type
21232 -- An interesting special check. If the expression is parenthesized
21233 -- and its type corresponds to the type of the sole component of the
21234 -- expected record type, or to the component type of the expected one
21235 -- dimensional array type, then assume we have a bad aggregate attempt.
21237 if Nkind (Expr) in N_Subexpr
21238 and then Paren_Count (Expr) /= 0
21239 and then Has_One_Matching_Field
21241 Error_Msg_N ("positional aggregate cannot have one component", Expr);
21243 if Present (Matching_Field) then
21244 if Is_Array_Type (Expec_Type) then
21246 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
21249 ("\write instead `& ='> ...`", Expr, Matching_Field);
21253 -- Another special check, if we are looking for a pool-specific access
21254 -- type and we found an E_Access_Attribute_Type, then we have the case
21255 -- of an Access attribute being used in a context which needs a pool-
21256 -- specific type, which is never allowed. The one extra check we make
21257 -- is that the expected designated type covers the Found_Type.
21259 elsif Is_Access_Type (Expec_Type)
21260 and then Ekind (Found_Type) = E_Access_Attribute_Type
21261 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
21262 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
21264 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
21266 Error_Msg_N -- CODEFIX
21267 ("result must be general access type!", Expr);
21268 Error_Msg_NE -- CODEFIX
21269 ("add ALL to }!", Expr, Expec_Type);
21271 -- Another special check, if the expected type is an integer type,
21272 -- but the expression is of type System.Address, and the parent is
21273 -- an addition or subtraction operation whose left operand is the
21274 -- expression in question and whose right operand is of an integral
21275 -- type, then this is an attempt at address arithmetic, so give
21276 -- appropriate message.
21278 elsif Is_Integer_Type (Expec_Type)
21279 and then Is_RTE (Found_Type, RE_Address)
21280 and then Nkind_In (Parent (Expr), N_Op_Add, N_Op_Subtract)
21281 and then Expr = Left_Opnd (Parent (Expr))
21282 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
21285 ("address arithmetic not predefined in package System",
21288 ("\possible missing with/use of System.Storage_Elements",
21292 -- If the expected type is an anonymous access type, as for access
21293 -- parameters and discriminants, the error is on the designated types.
21295 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
21296 if Comes_From_Source (Expec_Type) then
21297 Error_Msg_NE ("expected}!", Expr, Expec_Type);
21300 ("expected an access type with designated}",
21301 Expr, Designated_Type (Expec_Type));
21304 if Is_Access_Type (Found_Type)
21305 and then not Comes_From_Source (Found_Type)
21308 ("\\found an access type with designated}!",
21309 Expr, Designated_Type (Found_Type));
21311 if From_Limited_With (Found_Type) then
21312 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
21313 Error_Msg_Qual_Level := 99;
21314 Error_Msg_NE -- CODEFIX
21315 ("\\missing `WITH &;", Expr, Scope (Found_Type));
21316 Error_Msg_Qual_Level := 0;
21318 Error_Msg_NE ("found}!", Expr, Found_Type);
21322 -- Normal case of one type found, some other type expected
21325 -- If the names of the two types are the same, see if some number
21326 -- of levels of qualification will help. Don't try more than three
21327 -- levels, and if we get to standard, it's no use (and probably
21328 -- represents an error in the compiler) Also do not bother with
21329 -- internal scope names.
21332 Expec_Scope : Entity_Id;
21333 Found_Scope : Entity_Id;
21336 Expec_Scope := Expec_Type;
21337 Found_Scope := Found_Type;
21339 for Levels in Nat range 0 .. 3 loop
21340 if Chars (Expec_Scope) /= Chars (Found_Scope) then
21341 Error_Msg_Qual_Level := Levels;
21345 Expec_Scope := Scope (Expec_Scope);
21346 Found_Scope := Scope (Found_Scope);
21348 exit when Expec_Scope = Standard_Standard
21349 or else Found_Scope = Standard_Standard
21350 or else not Comes_From_Source (Expec_Scope)
21351 or else not Comes_From_Source (Found_Scope);
21355 if Is_Record_Type (Expec_Type)
21356 and then Present (Corresponding_Remote_Type (Expec_Type))
21358 Error_Msg_NE ("expected}!", Expr,
21359 Corresponding_Remote_Type (Expec_Type));
21361 Error_Msg_NE ("expected}!", Expr, Expec_Type);
21364 if Is_Entity_Name (Expr)
21365 and then Is_Package_Or_Generic_Package (Entity (Expr))
21367 Error_Msg_N ("\\found package name!", Expr);
21369 elsif Is_Entity_Name (Expr)
21370 and then Ekind_In (Entity (Expr), E_Procedure, E_Generic_Procedure)
21372 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
21374 ("found procedure name, possibly missing Access attribute!",
21378 ("\\found procedure name instead of function!", Expr);
21381 elsif Nkind (Expr) = N_Function_Call
21382 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
21383 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
21384 and then No (Parameter_Associations (Expr))
21387 ("found function name, possibly missing Access attribute!",
21390 -- Catch common error: a prefix or infix operator which is not
21391 -- directly visible because the type isn't.
21393 elsif Nkind (Expr) in N_Op
21394 and then Is_Overloaded (Expr)
21395 and then not Is_Immediately_Visible (Expec_Type)
21396 and then not Is_Potentially_Use_Visible (Expec_Type)
21397 and then not In_Use (Expec_Type)
21398 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
21401 ("operator of the type is not directly visible!", Expr);
21403 elsif Ekind (Found_Type) = E_Void
21404 and then Present (Parent (Found_Type))
21405 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
21407 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
21410 Error_Msg_NE ("\\found}!", Expr, Found_Type);
21413 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
21414 -- of the same modular type, and (M1 and M2) = 0 was intended.
21416 if Expec_Type = Standard_Boolean
21417 and then Is_Modular_Integer_Type (Found_Type)
21418 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
21419 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
21422 Op : constant Node_Id := Right_Opnd (Parent (Expr));
21423 L : constant Node_Id := Left_Opnd (Op);
21424 R : constant Node_Id := Right_Opnd (Op);
21427 -- The case for the message is when the left operand of the
21428 -- comparison is the same modular type, or when it is an
21429 -- integer literal (or other universal integer expression),
21430 -- which would have been typed as the modular type if the
21431 -- parens had been there.
21433 if (Etype (L) = Found_Type
21435 Etype (L) = Universal_Integer)
21436 and then Is_Integer_Type (Etype (R))
21439 ("\\possible missing parens for modular operation", Expr);
21444 -- Reset error message qualification indication
21446 Error_Msg_Qual_Level := 0;
21450 --------------------------------
21451 -- Yields_Synchronized_Object --
21452 --------------------------------
21454 function Yields_Synchronized_Object (Typ : Entity_Id) return Boolean is
21455 Has_Sync_Comp : Boolean := False;
21459 -- An array type yields a synchronized object if its component type
21460 -- yields a synchronized object.
21462 if Is_Array_Type (Typ) then
21463 return Yields_Synchronized_Object (Component_Type (Typ));
21465 -- A descendant of type Ada.Synchronous_Task_Control.Suspension_Object
21466 -- yields a synchronized object by default.
21468 elsif Is_Descendant_Of_Suspension_Object (Typ) then
21471 -- A protected type yields a synchronized object by default
21473 elsif Is_Protected_Type (Typ) then
21476 -- A record type or type extension yields a synchronized object when its
21477 -- discriminants (if any) lack default values and all components are of
21478 -- a type that yelds a synchronized object.
21480 elsif Is_Record_Type (Typ) then
21482 -- Inspect all entities defined in the scope of the type, looking for
21483 -- components of a type that does not yeld a synchronized object or
21484 -- for discriminants with default values.
21486 Id := First_Entity (Typ);
21487 while Present (Id) loop
21488 if Comes_From_Source (Id) then
21489 if Ekind (Id) = E_Component then
21490 if Yields_Synchronized_Object (Etype (Id)) then
21491 Has_Sync_Comp := True;
21493 -- The component does not yield a synchronized object
21499 elsif Ekind (Id) = E_Discriminant
21500 and then Present (Expression (Parent (Id)))
21509 -- Ensure that the parent type of a type extension yields a
21510 -- synchronized object.
21512 if Etype (Typ) /= Typ
21513 and then not Yields_Synchronized_Object (Etype (Typ))
21518 -- If we get here, then all discriminants lack default values and all
21519 -- components are of a type that yields a synchronized object.
21521 return Has_Sync_Comp;
21523 -- A synchronized interface type yields a synchronized object by default
21525 elsif Is_Synchronized_Interface (Typ) then
21528 -- A task type yelds a synchronized object by default
21530 elsif Is_Task_Type (Typ) then
21533 -- Otherwise the type does not yield a synchronized object
21538 end Yields_Synchronized_Object;
21540 ---------------------------
21541 -- Yields_Universal_Type --
21542 ---------------------------
21544 function Yields_Universal_Type (N : Node_Id) return Boolean is
21546 -- Integer and real literals are of a universal type
21548 if Nkind_In (N, N_Integer_Literal, N_Real_Literal) then
21551 -- The values of certain attributes are of a universal type
21553 elsif Nkind (N) = N_Attribute_Reference then
21555 Universal_Type_Attribute (Get_Attribute_Id (Attribute_Name (N)));
21557 -- ??? There are possibly other cases to consider
21562 end Yields_Universal_Type;