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 -- Local Subprograms --
76 -----------------------
78 function Build_Component_Subtype
81 T : Entity_Id) return Node_Id;
82 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
83 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
84 -- Loc is the source location, T is the original subtype.
86 function Has_Enabled_Property
88 Property : Name_Id) return Boolean;
89 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
90 -- Determine whether an abstract state or a variable denoted by entity
91 -- Item_Id has enabled property Property.
93 function Has_Null_Extension (T : Entity_Id) return Boolean;
94 -- T is a derived tagged type. Check whether the type extension is null.
95 -- If the parent type is fully initialized, T can be treated as such.
97 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
98 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
99 -- with discriminants whose default values are static, examine only the
100 -- components in the selected variant to determine whether all of them
103 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
104 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
105 -- ???We retain the old and new algorithms for Requires_Transient_Scope for
106 -- the time being. New_Requires_Transient_Scope is used by default; the
107 -- debug switch -gnatdQ can be used to do Old_Requires_Transient_Scope
108 -- instead. The intent is to use this temporarily to measure before/after
109 -- efficiency. Note: when this temporary code is removed, the documentation
110 -- of dQ in debug.adb should be removed.
112 procedure Results_Differ
116 -- ???Debugging code. Called when the Old_Val and New_Val differ. This
117 -- routine will be removed eventially when New_Requires_Transient_Scope
118 -- becomes Requires_Transient_Scope and Old_Requires_Transient_Scope is
121 ------------------------------
122 -- Abstract_Interface_List --
123 ------------------------------
125 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
129 if Is_Concurrent_Type (Typ) then
131 -- If we are dealing with a synchronized subtype, go to the base
132 -- type, whose declaration has the interface list.
134 -- Shouldn't this be Declaration_Node???
136 Nod := Parent (Base_Type (Typ));
138 if Nkind (Nod) = N_Full_Type_Declaration then
142 elsif Ekind (Typ) = E_Record_Type_With_Private then
143 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
144 Nod := Type_Definition (Parent (Typ));
146 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
147 if Present (Full_View (Typ))
149 Nkind (Parent (Full_View (Typ))) = N_Full_Type_Declaration
151 Nod := Type_Definition (Parent (Full_View (Typ)));
153 -- If the full-view is not available we cannot do anything else
154 -- here (the source has errors).
160 -- Support for generic formals with interfaces is still missing ???
162 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
167 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
171 elsif Ekind (Typ) = E_Record_Subtype then
172 Nod := Type_Definition (Parent (Etype (Typ)));
174 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
176 -- Recurse, because parent may still be a private extension. Also
177 -- note that the full view of the subtype or the full view of its
178 -- base type may (both) be unavailable.
180 return Abstract_Interface_List (Etype (Typ));
182 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
183 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
184 Nod := Formal_Type_Definition (Parent (Typ));
186 Nod := Type_Definition (Parent (Typ));
190 return Interface_List (Nod);
191 end Abstract_Interface_List;
193 --------------------------------
194 -- Add_Access_Type_To_Process --
195 --------------------------------
197 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
201 Ensure_Freeze_Node (E);
202 L := Access_Types_To_Process (Freeze_Node (E));
206 Set_Access_Types_To_Process (Freeze_Node (E), L);
210 end Add_Access_Type_To_Process;
212 --------------------------
213 -- Add_Block_Identifier --
214 --------------------------
216 procedure Add_Block_Identifier (N : Node_Id; Id : out Entity_Id) is
217 Loc : constant Source_Ptr := Sloc (N);
220 pragma Assert (Nkind (N) = N_Block_Statement);
222 -- The block already has a label, return its entity
224 if Present (Identifier (N)) then
225 Id := Entity (Identifier (N));
227 -- Create a new block label and set its attributes
230 Id := New_Internal_Entity (E_Block, Current_Scope, Loc, 'B');
231 Set_Etype (Id, Standard_Void_Type);
234 Set_Identifier (N, New_Occurrence_Of (Id, Loc));
235 Set_Block_Node (Id, Identifier (N));
237 end Add_Block_Identifier;
239 ----------------------------
240 -- Add_Global_Declaration --
241 ----------------------------
243 procedure Add_Global_Declaration (N : Node_Id) is
244 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
247 if No (Declarations (Aux_Node)) then
248 Set_Declarations (Aux_Node, New_List);
251 Append_To (Declarations (Aux_Node), N);
253 end Add_Global_Declaration;
255 --------------------------------
256 -- Address_Integer_Convert_OK --
257 --------------------------------
259 function Address_Integer_Convert_OK (T1, T2 : Entity_Id) return Boolean is
261 if Allow_Integer_Address
262 and then ((Is_Descendant_Of_Address (T1)
263 and then Is_Private_Type (T1)
264 and then Is_Integer_Type (T2))
266 (Is_Descendant_Of_Address (T2)
267 and then Is_Private_Type (T2)
268 and then Is_Integer_Type (T1)))
274 end Address_Integer_Convert_OK;
280 function Address_Value (N : Node_Id) return Node_Id is
285 -- For constant, get constant expression
287 if Is_Entity_Name (Expr)
288 and then Ekind (Entity (Expr)) = E_Constant
290 Expr := Constant_Value (Entity (Expr));
292 -- For unchecked conversion, get result to convert
294 elsif Nkind (Expr) = N_Unchecked_Type_Conversion then
295 Expr := Expression (Expr);
297 -- For (common case) of To_Address call, get argument
299 elsif Nkind (Expr) = N_Function_Call
300 and then Is_Entity_Name (Name (Expr))
301 and then Is_RTE (Entity (Name (Expr)), RE_To_Address)
303 Expr := First (Parameter_Associations (Expr));
305 if Nkind (Expr) = N_Parameter_Association then
306 Expr := Explicit_Actual_Parameter (Expr);
309 -- We finally have the real expression
323 -- For now, just 8/16/32/64
325 function Addressable (V : Uint) return Boolean is
327 return V = Uint_8 or else
333 function Addressable (V : Int) return Boolean is
341 ---------------------------------
342 -- Aggregate_Constraint_Checks --
343 ---------------------------------
345 procedure Aggregate_Constraint_Checks
347 Check_Typ : Entity_Id)
349 Exp_Typ : constant Entity_Id := Etype (Exp);
352 if Raises_Constraint_Error (Exp) then
356 -- Ada 2005 (AI-230): Generate a conversion to an anonymous access
357 -- component's type to force the appropriate accessibility checks.
359 -- Ada 2005 (AI-231): Generate conversion to the null-excluding type to
360 -- force the corresponding run-time check
362 if Is_Access_Type (Check_Typ)
363 and then Is_Local_Anonymous_Access (Check_Typ)
365 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
366 Analyze_And_Resolve (Exp, Check_Typ);
367 Check_Unset_Reference (Exp);
370 -- What follows is really expansion activity, so check that expansion
371 -- is on and is allowed. In GNATprove mode, we also want check flags to
372 -- be added in the tree, so that the formal verification can rely on
373 -- those to be present. In GNATprove mode for formal verification, some
374 -- treatment typically only done during expansion needs to be performed
375 -- on the tree, but it should not be applied inside generics. Otherwise,
376 -- this breaks the name resolution mechanism for generic instances.
378 if not Expander_Active
379 and (Inside_A_Generic or not Full_Analysis or not GNATprove_Mode)
384 if Is_Access_Type (Check_Typ)
385 and then Can_Never_Be_Null (Check_Typ)
386 and then not Can_Never_Be_Null (Exp_Typ)
388 Install_Null_Excluding_Check (Exp);
391 -- First check if we have to insert discriminant checks
393 if Has_Discriminants (Exp_Typ) then
394 Apply_Discriminant_Check (Exp, Check_Typ);
396 -- Next emit length checks for array aggregates
398 elsif Is_Array_Type (Exp_Typ) then
399 Apply_Length_Check (Exp, Check_Typ);
401 -- Finally emit scalar and string checks. If we are dealing with a
402 -- scalar literal we need to check by hand because the Etype of
403 -- literals is not necessarily correct.
405 elsif Is_Scalar_Type (Exp_Typ)
406 and then Compile_Time_Known_Value (Exp)
408 if Is_Out_Of_Range (Exp, Base_Type (Check_Typ)) then
409 Apply_Compile_Time_Constraint_Error
410 (Exp, "value not in range of}??", CE_Range_Check_Failed,
411 Ent => Base_Type (Check_Typ),
412 Typ => Base_Type (Check_Typ));
414 elsif Is_Out_Of_Range (Exp, Check_Typ) then
415 Apply_Compile_Time_Constraint_Error
416 (Exp, "value not in range of}??", CE_Range_Check_Failed,
420 elsif not Range_Checks_Suppressed (Check_Typ) then
421 Apply_Scalar_Range_Check (Exp, Check_Typ);
424 -- Verify that target type is also scalar, to prevent view anomalies
425 -- in instantiations.
427 elsif (Is_Scalar_Type (Exp_Typ)
428 or else Nkind (Exp) = N_String_Literal)
429 and then Is_Scalar_Type (Check_Typ)
430 and then Exp_Typ /= Check_Typ
432 if Is_Entity_Name (Exp)
433 and then Ekind (Entity (Exp)) = E_Constant
435 -- If expression is a constant, it is worthwhile checking whether
436 -- it is a bound of the type.
438 if (Is_Entity_Name (Type_Low_Bound (Check_Typ))
439 and then Entity (Exp) = Entity (Type_Low_Bound (Check_Typ)))
441 (Is_Entity_Name (Type_High_Bound (Check_Typ))
442 and then Entity (Exp) = Entity (Type_High_Bound (Check_Typ)))
447 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
448 Analyze_And_Resolve (Exp, Check_Typ);
449 Check_Unset_Reference (Exp);
452 -- Could use a comment on this case ???
455 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
456 Analyze_And_Resolve (Exp, Check_Typ);
457 Check_Unset_Reference (Exp);
461 end Aggregate_Constraint_Checks;
463 -----------------------
464 -- Alignment_In_Bits --
465 -----------------------
467 function Alignment_In_Bits (E : Entity_Id) return Uint is
469 return Alignment (E) * System_Storage_Unit;
470 end Alignment_In_Bits;
472 --------------------------------------
473 -- All_Composite_Constraints_Static --
474 --------------------------------------
476 function All_Composite_Constraints_Static
477 (Constr : Node_Id) return Boolean
480 if No (Constr) or else Error_Posted (Constr) then
484 case Nkind (Constr) is
486 if Nkind (Constr) in N_Has_Entity
487 and then Present (Entity (Constr))
489 if Is_Type (Entity (Constr)) then
491 not Is_Discrete_Type (Entity (Constr))
492 or else Is_OK_Static_Subtype (Entity (Constr));
495 elsif Nkind (Constr) = N_Range then
497 Is_OK_Static_Expression (Low_Bound (Constr))
499 Is_OK_Static_Expression (High_Bound (Constr));
501 elsif Nkind (Constr) = N_Attribute_Reference
502 and then Attribute_Name (Constr) = Name_Range
505 Is_OK_Static_Expression
506 (Type_Low_Bound (Etype (Prefix (Constr))))
508 Is_OK_Static_Expression
509 (Type_High_Bound (Etype (Prefix (Constr))));
513 not Present (Etype (Constr)) -- previous error
514 or else not Is_Discrete_Type (Etype (Constr))
515 or else Is_OK_Static_Expression (Constr);
517 when N_Discriminant_Association =>
518 return All_Composite_Constraints_Static (Expression (Constr));
520 when N_Range_Constraint =>
522 All_Composite_Constraints_Static (Range_Expression (Constr));
524 when N_Index_Or_Discriminant_Constraint =>
526 One_Cstr : Entity_Id;
528 One_Cstr := First (Constraints (Constr));
529 while Present (One_Cstr) loop
530 if not All_Composite_Constraints_Static (One_Cstr) then
540 when N_Subtype_Indication =>
542 All_Composite_Constraints_Static (Subtype_Mark (Constr))
544 All_Composite_Constraints_Static (Constraint (Constr));
549 end All_Composite_Constraints_Static;
551 ---------------------------------
552 -- Append_Inherited_Subprogram --
553 ---------------------------------
555 procedure Append_Inherited_Subprogram (S : Entity_Id) is
556 Par : constant Entity_Id := Alias (S);
557 -- The parent subprogram
559 Scop : constant Entity_Id := Scope (Par);
560 -- The scope of definition of the parent subprogram
562 Typ : constant Entity_Id := Defining_Entity (Parent (S));
563 -- The derived type of which S is a primitive operation
569 if Ekind (Current_Scope) = E_Package
570 and then In_Private_Part (Current_Scope)
571 and then Has_Private_Declaration (Typ)
572 and then Is_Tagged_Type (Typ)
573 and then Scop = Current_Scope
575 -- The inherited operation is available at the earliest place after
576 -- the derived type declaration ( RM 7.3.1 (6/1)). This is only
577 -- relevant for type extensions. If the parent operation appears
578 -- after the type extension, the operation is not visible.
581 (Visible_Declarations
582 (Package_Specification (Current_Scope)));
583 while Present (Decl) loop
584 if Nkind (Decl) = N_Private_Extension_Declaration
585 and then Defining_Entity (Decl) = Typ
587 if Sloc (Decl) > Sloc (Par) then
588 Next_E := Next_Entity (Par);
589 Set_Next_Entity (Par, S);
590 Set_Next_Entity (S, Next_E);
602 -- If partial view is not a type extension, or it appears before the
603 -- subprogram declaration, insert normally at end of entity list.
605 Append_Entity (S, Current_Scope);
606 end Append_Inherited_Subprogram;
608 -----------------------------------------
609 -- Apply_Compile_Time_Constraint_Error --
610 -----------------------------------------
612 procedure Apply_Compile_Time_Constraint_Error
615 Reason : RT_Exception_Code;
616 Ent : Entity_Id := Empty;
617 Typ : Entity_Id := Empty;
618 Loc : Source_Ptr := No_Location;
619 Rep : Boolean := True;
620 Warn : Boolean := False)
622 Stat : constant Boolean := Is_Static_Expression (N);
623 R_Stat : constant Node_Id :=
624 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
635 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
637 -- In GNATprove mode, do not replace the node with an exception raised.
638 -- In such a case, either the call to Compile_Time_Constraint_Error
639 -- issues an error which stops analysis, or it issues a warning in
640 -- a few cases where a suitable check flag is set for GNATprove to
641 -- generate a check message.
643 if not Rep or GNATprove_Mode then
647 -- Now we replace the node by an N_Raise_Constraint_Error node
648 -- This does not need reanalyzing, so set it as analyzed now.
651 Set_Analyzed (N, True);
654 Set_Raises_Constraint_Error (N);
656 -- Now deal with possible local raise handling
658 Possible_Local_Raise (N, Standard_Constraint_Error);
660 -- If the original expression was marked as static, the result is
661 -- still marked as static, but the Raises_Constraint_Error flag is
662 -- always set so that further static evaluation is not attempted.
665 Set_Is_Static_Expression (N);
667 end Apply_Compile_Time_Constraint_Error;
669 ---------------------------
670 -- Async_Readers_Enabled --
671 ---------------------------
673 function Async_Readers_Enabled (Id : Entity_Id) return Boolean is
675 return Has_Enabled_Property (Id, Name_Async_Readers);
676 end Async_Readers_Enabled;
678 ---------------------------
679 -- Async_Writers_Enabled --
680 ---------------------------
682 function Async_Writers_Enabled (Id : Entity_Id) return Boolean is
684 return Has_Enabled_Property (Id, Name_Async_Writers);
685 end Async_Writers_Enabled;
687 --------------------------------------
688 -- Available_Full_View_Of_Component --
689 --------------------------------------
691 function Available_Full_View_Of_Component (T : Entity_Id) return Boolean is
692 ST : constant Entity_Id := Scope (T);
693 SCT : constant Entity_Id := Scope (Component_Type (T));
695 return In_Open_Scopes (ST)
696 and then In_Open_Scopes (SCT)
697 and then Scope_Depth (ST) >= Scope_Depth (SCT);
698 end Available_Full_View_Of_Component;
704 procedure Bad_Attribute
707 Warn : Boolean := False)
710 Error_Msg_Warn := Warn;
711 Error_Msg_N ("unrecognized attribute&<<", N);
713 -- Check for possible misspelling
715 Error_Msg_Name_1 := First_Attribute_Name;
716 while Error_Msg_Name_1 <= Last_Attribute_Name loop
717 if Is_Bad_Spelling_Of (Nam, Error_Msg_Name_1) then
718 Error_Msg_N -- CODEFIX
719 ("\possible misspelling of %<<", N);
723 Error_Msg_Name_1 := Error_Msg_Name_1 + 1;
727 --------------------------------
728 -- Bad_Predicated_Subtype_Use --
729 --------------------------------
731 procedure Bad_Predicated_Subtype_Use
735 Suggest_Static : Boolean := False)
740 -- Avoid cascaded errors
742 if Error_Posted (N) then
746 if Inside_A_Generic then
747 Gen := Current_Scope;
748 while Present (Gen) and then Ekind (Gen) /= E_Generic_Package loop
756 if Is_Generic_Formal (Typ) and then Is_Discrete_Type (Typ) then
757 Set_No_Predicate_On_Actual (Typ);
760 elsif Has_Predicates (Typ) then
761 if Is_Generic_Actual_Type (Typ) then
763 -- The restriction on loop parameters is only that the type
764 -- should have no dynamic predicates.
766 if Nkind (Parent (N)) = N_Loop_Parameter_Specification
767 and then not Has_Dynamic_Predicate_Aspect (Typ)
768 and then Is_OK_Static_Subtype (Typ)
773 Gen := Current_Scope;
774 while not Is_Generic_Instance (Gen) loop
778 pragma Assert (Present (Gen));
780 if Ekind (Gen) = E_Package and then In_Package_Body (Gen) then
781 Error_Msg_Warn := SPARK_Mode /= On;
782 Error_Msg_FE (Msg & "<<", N, Typ);
783 Error_Msg_F ("\Program_Error [<<", N);
786 Make_Raise_Program_Error (Sloc (N),
787 Reason => PE_Bad_Predicated_Generic_Type));
790 Error_Msg_FE (Msg & "<<", N, Typ);
794 Error_Msg_FE (Msg, N, Typ);
797 -- Emit an optional suggestion on how to remedy the error if the
798 -- context warrants it.
800 if Suggest_Static and then Has_Static_Predicate (Typ) then
801 Error_Msg_FE ("\predicate of & should be marked static", N, Typ);
804 end Bad_Predicated_Subtype_Use;
806 -----------------------------------------
807 -- Bad_Unordered_Enumeration_Reference --
808 -----------------------------------------
810 function Bad_Unordered_Enumeration_Reference
812 T : Entity_Id) return Boolean
815 return Is_Enumeration_Type (T)
816 and then Warn_On_Unordered_Enumeration_Type
817 and then not Is_Generic_Type (T)
818 and then Comes_From_Source (N)
819 and then not Has_Pragma_Ordered (T)
820 and then not In_Same_Extended_Unit (N, T);
821 end Bad_Unordered_Enumeration_Reference;
823 --------------------------
824 -- Build_Actual_Subtype --
825 --------------------------
827 function Build_Actual_Subtype
829 N : Node_Or_Entity_Id) return Node_Id
832 -- Normally Sloc (N), but may point to corresponding body in some cases
834 Constraints : List_Id;
840 Disc_Type : Entity_Id;
846 if Nkind (N) = N_Defining_Identifier then
847 Obj := New_Occurrence_Of (N, Loc);
849 -- If this is a formal parameter of a subprogram declaration, and
850 -- we are compiling the body, we want the declaration for the
851 -- actual subtype to carry the source position of the body, to
852 -- prevent anomalies in gdb when stepping through the code.
854 if Is_Formal (N) then
856 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
858 if Nkind (Decl) = N_Subprogram_Declaration
859 and then Present (Corresponding_Body (Decl))
861 Loc := Sloc (Corresponding_Body (Decl));
870 if Is_Array_Type (T) then
871 Constraints := New_List;
872 for J in 1 .. Number_Dimensions (T) loop
874 -- Build an array subtype declaration with the nominal subtype and
875 -- the bounds of the actual. Add the declaration in front of the
876 -- local declarations for the subprogram, for analysis before any
877 -- reference to the formal in the body.
880 Make_Attribute_Reference (Loc,
882 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
883 Attribute_Name => Name_First,
884 Expressions => New_List (
885 Make_Integer_Literal (Loc, J)));
888 Make_Attribute_Reference (Loc,
890 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
891 Attribute_Name => Name_Last,
892 Expressions => New_List (
893 Make_Integer_Literal (Loc, J)));
895 Append (Make_Range (Loc, Lo, Hi), Constraints);
898 -- If the type has unknown discriminants there is no constrained
899 -- subtype to build. This is never called for a formal or for a
900 -- lhs, so returning the type is ok ???
902 elsif Has_Unknown_Discriminants (T) then
906 Constraints := New_List;
908 -- Type T is a generic derived type, inherit the discriminants from
911 if Is_Private_Type (T)
912 and then No (Full_View (T))
914 -- T was flagged as an error if it was declared as a formal
915 -- derived type with known discriminants. In this case there
916 -- is no need to look at the parent type since T already carries
917 -- its own discriminants.
919 and then not Error_Posted (T)
921 Disc_Type := Etype (Base_Type (T));
926 Discr := First_Discriminant (Disc_Type);
927 while Present (Discr) loop
928 Append_To (Constraints,
929 Make_Selected_Component (Loc,
931 Duplicate_Subexpr_No_Checks (Obj),
932 Selector_Name => New_Occurrence_Of (Discr, Loc)));
933 Next_Discriminant (Discr);
937 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
938 Set_Is_Internal (Subt);
941 Make_Subtype_Declaration (Loc,
942 Defining_Identifier => Subt,
943 Subtype_Indication =>
944 Make_Subtype_Indication (Loc,
945 Subtype_Mark => New_Occurrence_Of (T, Loc),
947 Make_Index_Or_Discriminant_Constraint (Loc,
948 Constraints => Constraints)));
950 Mark_Rewrite_Insertion (Decl);
952 end Build_Actual_Subtype;
954 ---------------------------------------
955 -- Build_Actual_Subtype_Of_Component --
956 ---------------------------------------
958 function Build_Actual_Subtype_Of_Component
960 N : Node_Id) return Node_Id
962 Loc : constant Source_Ptr := Sloc (N);
963 P : constant Node_Id := Prefix (N);
966 Index_Typ : Entity_Id;
968 Desig_Typ : Entity_Id;
969 -- This is either a copy of T, or if T is an access type, then it is
970 -- the directly designated type of this access type.
972 function Build_Actual_Array_Constraint return List_Id;
973 -- If one or more of the bounds of the component depends on
974 -- discriminants, build actual constraint using the discriminants
977 function Build_Actual_Record_Constraint return List_Id;
978 -- Similar to previous one, for discriminated components constrained
979 -- by the discriminant of the enclosing object.
981 -----------------------------------
982 -- Build_Actual_Array_Constraint --
983 -----------------------------------
985 function Build_Actual_Array_Constraint return List_Id is
986 Constraints : constant List_Id := New_List;
994 Indx := First_Index (Desig_Typ);
995 while Present (Indx) loop
996 Old_Lo := Type_Low_Bound (Etype (Indx));
997 Old_Hi := Type_High_Bound (Etype (Indx));
999 if Denotes_Discriminant (Old_Lo) then
1001 Make_Selected_Component (Loc,
1002 Prefix => New_Copy_Tree (P),
1003 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
1006 Lo := New_Copy_Tree (Old_Lo);
1008 -- The new bound will be reanalyzed in the enclosing
1009 -- declaration. For literal bounds that come from a type
1010 -- declaration, the type of the context must be imposed, so
1011 -- insure that analysis will take place. For non-universal
1012 -- types this is not strictly necessary.
1014 Set_Analyzed (Lo, False);
1017 if Denotes_Discriminant (Old_Hi) then
1019 Make_Selected_Component (Loc,
1020 Prefix => New_Copy_Tree (P),
1021 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
1024 Hi := New_Copy_Tree (Old_Hi);
1025 Set_Analyzed (Hi, False);
1028 Append (Make_Range (Loc, Lo, Hi), Constraints);
1033 end Build_Actual_Array_Constraint;
1035 ------------------------------------
1036 -- Build_Actual_Record_Constraint --
1037 ------------------------------------
1039 function Build_Actual_Record_Constraint return List_Id is
1040 Constraints : constant List_Id := New_List;
1045 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1046 while Present (D) loop
1047 if Denotes_Discriminant (Node (D)) then
1048 D_Val := Make_Selected_Component (Loc,
1049 Prefix => New_Copy_Tree (P),
1050 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
1053 D_Val := New_Copy_Tree (Node (D));
1056 Append (D_Val, Constraints);
1061 end Build_Actual_Record_Constraint;
1063 -- Start of processing for Build_Actual_Subtype_Of_Component
1066 -- Why the test for Spec_Expression mode here???
1068 if In_Spec_Expression then
1071 -- More comments for the rest of this body would be good ???
1073 elsif Nkind (N) = N_Explicit_Dereference then
1074 if Is_Composite_Type (T)
1075 and then not Is_Constrained (T)
1076 and then not (Is_Class_Wide_Type (T)
1077 and then Is_Constrained (Root_Type (T)))
1078 and then not Has_Unknown_Discriminants (T)
1080 -- If the type of the dereference is already constrained, it is an
1083 if Is_Array_Type (Etype (N))
1084 and then Is_Constrained (Etype (N))
1088 Remove_Side_Effects (P);
1089 return Build_Actual_Subtype (T, N);
1096 if Ekind (T) = E_Access_Subtype then
1097 Desig_Typ := Designated_Type (T);
1102 if Ekind (Desig_Typ) = E_Array_Subtype then
1103 Id := First_Index (Desig_Typ);
1104 while Present (Id) loop
1105 Index_Typ := Underlying_Type (Etype (Id));
1107 if Denotes_Discriminant (Type_Low_Bound (Index_Typ))
1109 Denotes_Discriminant (Type_High_Bound (Index_Typ))
1111 Remove_Side_Effects (P);
1113 Build_Component_Subtype
1114 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
1120 elsif Is_Composite_Type (Desig_Typ)
1121 and then Has_Discriminants (Desig_Typ)
1122 and then not Has_Unknown_Discriminants (Desig_Typ)
1124 if Is_Private_Type (Desig_Typ)
1125 and then No (Discriminant_Constraint (Desig_Typ))
1127 Desig_Typ := Full_View (Desig_Typ);
1130 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1131 while Present (D) loop
1132 if Denotes_Discriminant (Node (D)) then
1133 Remove_Side_Effects (P);
1135 Build_Component_Subtype (
1136 Build_Actual_Record_Constraint, Loc, Base_Type (T));
1143 -- If none of the above, the actual and nominal subtypes are the same
1146 end Build_Actual_Subtype_Of_Component;
1148 -----------------------------
1149 -- Build_Component_Subtype --
1150 -----------------------------
1152 function Build_Component_Subtype
1155 T : Entity_Id) return Node_Id
1161 -- Unchecked_Union components do not require component subtypes
1163 if Is_Unchecked_Union (T) then
1167 Subt := Make_Temporary (Loc, 'S');
1168 Set_Is_Internal (Subt);
1171 Make_Subtype_Declaration (Loc,
1172 Defining_Identifier => Subt,
1173 Subtype_Indication =>
1174 Make_Subtype_Indication (Loc,
1175 Subtype_Mark => New_Occurrence_Of (Base_Type (T), Loc),
1177 Make_Index_Or_Discriminant_Constraint (Loc,
1178 Constraints => C)));
1180 Mark_Rewrite_Insertion (Decl);
1182 end Build_Component_Subtype;
1184 ---------------------------
1185 -- Build_Default_Subtype --
1186 ---------------------------
1188 function Build_Default_Subtype
1190 N : Node_Id) return Entity_Id
1192 Loc : constant Source_Ptr := Sloc (N);
1196 -- The base type that is to be constrained by the defaults
1199 if not Has_Discriminants (T) or else Is_Constrained (T) then
1203 Bas := Base_Type (T);
1205 -- If T is non-private but its base type is private, this is the
1206 -- completion of a subtype declaration whose parent type is private
1207 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1208 -- are to be found in the full view of the base. Check that the private
1209 -- status of T and its base differ.
1211 if Is_Private_Type (Bas)
1212 and then not Is_Private_Type (T)
1213 and then Present (Full_View (Bas))
1215 Bas := Full_View (Bas);
1218 Disc := First_Discriminant (T);
1220 if No (Discriminant_Default_Value (Disc)) then
1225 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
1226 Constraints : constant List_Id := New_List;
1230 while Present (Disc) loop
1231 Append_To (Constraints,
1232 New_Copy_Tree (Discriminant_Default_Value (Disc)));
1233 Next_Discriminant (Disc);
1237 Make_Subtype_Declaration (Loc,
1238 Defining_Identifier => Act,
1239 Subtype_Indication =>
1240 Make_Subtype_Indication (Loc,
1241 Subtype_Mark => New_Occurrence_Of (Bas, Loc),
1243 Make_Index_Or_Discriminant_Constraint (Loc,
1244 Constraints => Constraints)));
1246 Insert_Action (N, Decl);
1248 -- If the context is a component declaration the subtype declaration
1249 -- will be analyzed when the enclosing type is frozen, otherwise do
1252 if Ekind (Current_Scope) /= E_Record_Type then
1258 end Build_Default_Subtype;
1260 --------------------------------------------
1261 -- Build_Discriminal_Subtype_Of_Component --
1262 --------------------------------------------
1264 function Build_Discriminal_Subtype_Of_Component
1265 (T : Entity_Id) return Node_Id
1267 Loc : constant Source_Ptr := Sloc (T);
1271 function Build_Discriminal_Array_Constraint return List_Id;
1272 -- If one or more of the bounds of the component depends on
1273 -- discriminants, build actual constraint using the discriminants
1276 function Build_Discriminal_Record_Constraint return List_Id;
1277 -- Similar to previous one, for discriminated components constrained by
1278 -- the discriminant of the enclosing object.
1280 ----------------------------------------
1281 -- Build_Discriminal_Array_Constraint --
1282 ----------------------------------------
1284 function Build_Discriminal_Array_Constraint return List_Id is
1285 Constraints : constant List_Id := New_List;
1293 Indx := First_Index (T);
1294 while Present (Indx) loop
1295 Old_Lo := Type_Low_Bound (Etype (Indx));
1296 Old_Hi := Type_High_Bound (Etype (Indx));
1298 if Denotes_Discriminant (Old_Lo) then
1299 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
1302 Lo := New_Copy_Tree (Old_Lo);
1305 if Denotes_Discriminant (Old_Hi) then
1306 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
1309 Hi := New_Copy_Tree (Old_Hi);
1312 Append (Make_Range (Loc, Lo, Hi), Constraints);
1317 end Build_Discriminal_Array_Constraint;
1319 -----------------------------------------
1320 -- Build_Discriminal_Record_Constraint --
1321 -----------------------------------------
1323 function Build_Discriminal_Record_Constraint return List_Id is
1324 Constraints : constant List_Id := New_List;
1329 D := First_Elmt (Discriminant_Constraint (T));
1330 while Present (D) loop
1331 if Denotes_Discriminant (Node (D)) then
1333 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
1335 D_Val := New_Copy_Tree (Node (D));
1338 Append (D_Val, Constraints);
1343 end Build_Discriminal_Record_Constraint;
1345 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1348 if Ekind (T) = E_Array_Subtype then
1349 Id := First_Index (T);
1350 while Present (Id) loop
1351 if Denotes_Discriminant (Type_Low_Bound (Etype (Id)))
1353 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
1355 return Build_Component_Subtype
1356 (Build_Discriminal_Array_Constraint, Loc, T);
1362 elsif Ekind (T) = E_Record_Subtype
1363 and then Has_Discriminants (T)
1364 and then not Has_Unknown_Discriminants (T)
1366 D := First_Elmt (Discriminant_Constraint (T));
1367 while Present (D) loop
1368 if Denotes_Discriminant (Node (D)) then
1369 return Build_Component_Subtype
1370 (Build_Discriminal_Record_Constraint, Loc, T);
1377 -- If none of the above, the actual and nominal subtypes are the same
1380 end Build_Discriminal_Subtype_Of_Component;
1382 ------------------------------
1383 -- Build_Elaboration_Entity --
1384 ------------------------------
1386 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
1387 Loc : constant Source_Ptr := Sloc (N);
1389 Elab_Ent : Entity_Id;
1391 procedure Set_Package_Name (Ent : Entity_Id);
1392 -- Given an entity, sets the fully qualified name of the entity in
1393 -- Name_Buffer, with components separated by double underscores. This
1394 -- is a recursive routine that climbs the scope chain to Standard.
1396 ----------------------
1397 -- Set_Package_Name --
1398 ----------------------
1400 procedure Set_Package_Name (Ent : Entity_Id) is
1402 if Scope (Ent) /= Standard_Standard then
1403 Set_Package_Name (Scope (Ent));
1406 Nam : constant String := Get_Name_String (Chars (Ent));
1408 Name_Buffer (Name_Len + 1) := '_';
1409 Name_Buffer (Name_Len + 2) := '_';
1410 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
1411 Name_Len := Name_Len + Nam'Length + 2;
1415 Get_Name_String (Chars (Ent));
1417 end Set_Package_Name;
1419 -- Start of processing for Build_Elaboration_Entity
1422 -- Ignore call if already constructed
1424 if Present (Elaboration_Entity (Spec_Id)) then
1427 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1428 -- no role in analysis.
1430 elsif ASIS_Mode then
1433 -- See if we need elaboration entity.
1435 -- We always need an elaboration entity when preserving control flow, as
1436 -- we want to remain explicit about the unit's elaboration order.
1438 elsif Opt.Suppress_Control_Flow_Optimizations then
1441 -- We always need an elaboration entity for the dynamic elaboration
1442 -- model, since it is needed to properly generate the PE exception for
1443 -- access before elaboration.
1445 elsif Dynamic_Elaboration_Checks then
1448 -- For the static model, we don't need the elaboration counter if this
1449 -- unit is sure to have no elaboration code, since that means there
1450 -- is no elaboration unit to be called. Note that we can't just decide
1451 -- after the fact by looking to see whether there was elaboration code,
1452 -- because that's too late to make this decision.
1454 elsif Restriction_Active (No_Elaboration_Code) then
1457 -- Similarly, for the static model, we can skip the elaboration counter
1458 -- if we have the No_Multiple_Elaboration restriction, since for the
1459 -- static model, that's the only purpose of the counter (to avoid
1460 -- multiple elaboration).
1462 elsif Restriction_Active (No_Multiple_Elaboration) then
1466 -- Here we need the elaboration entity
1468 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1469 -- name with dots replaced by double underscore. We have to manually
1470 -- construct this name, since it will be elaborated in the outer scope,
1471 -- and thus will not have the unit name automatically prepended.
1473 Set_Package_Name (Spec_Id);
1474 Add_Str_To_Name_Buffer ("_E");
1476 -- Create elaboration counter
1478 Elab_Ent := Make_Defining_Identifier (Loc, Chars => Name_Find);
1479 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
1482 Make_Object_Declaration (Loc,
1483 Defining_Identifier => Elab_Ent,
1484 Object_Definition =>
1485 New_Occurrence_Of (Standard_Short_Integer, Loc),
1486 Expression => Make_Integer_Literal (Loc, Uint_0));
1488 Push_Scope (Standard_Standard);
1489 Add_Global_Declaration (Decl);
1492 -- Reset True_Constant indication, since we will indeed assign a value
1493 -- to the variable in the binder main. We also kill the Current_Value
1494 -- and Last_Assignment fields for the same reason.
1496 Set_Is_True_Constant (Elab_Ent, False);
1497 Set_Current_Value (Elab_Ent, Empty);
1498 Set_Last_Assignment (Elab_Ent, Empty);
1500 -- We do not want any further qualification of the name (if we did not
1501 -- do this, we would pick up the name of the generic package in the case
1502 -- of a library level generic instantiation).
1504 Set_Has_Qualified_Name (Elab_Ent);
1505 Set_Has_Fully_Qualified_Name (Elab_Ent);
1506 end Build_Elaboration_Entity;
1508 --------------------------------
1509 -- Build_Explicit_Dereference --
1510 --------------------------------
1512 procedure Build_Explicit_Dereference
1516 Loc : constant Source_Ptr := Sloc (Expr);
1521 -- An entity of a type with a reference aspect is overloaded with
1522 -- both interpretations: with and without the dereference. Now that
1523 -- the dereference is made explicit, set the type of the node properly,
1524 -- to prevent anomalies in the backend. Same if the expression is an
1525 -- overloaded function call whose return type has a reference aspect.
1527 if Is_Entity_Name (Expr) then
1528 Set_Etype (Expr, Etype (Entity (Expr)));
1530 -- The designated entity will not be examined again when resolving
1531 -- the dereference, so generate a reference to it now.
1533 Generate_Reference (Entity (Expr), Expr);
1535 elsif Nkind (Expr) = N_Function_Call then
1537 -- If the name of the indexing function is overloaded, locate the one
1538 -- whose return type has an implicit dereference on the desired
1539 -- discriminant, and set entity and type of function call.
1541 if Is_Overloaded (Name (Expr)) then
1542 Get_First_Interp (Name (Expr), I, It);
1544 while Present (It.Nam) loop
1545 if Ekind ((It.Typ)) = E_Record_Type
1546 and then First_Entity ((It.Typ)) = Disc
1548 Set_Entity (Name (Expr), It.Nam);
1549 Set_Etype (Name (Expr), Etype (It.Nam));
1553 Get_Next_Interp (I, It);
1557 -- Set type of call from resolved function name.
1559 Set_Etype (Expr, Etype (Name (Expr)));
1562 Set_Is_Overloaded (Expr, False);
1564 -- The expression will often be a generalized indexing that yields a
1565 -- container element that is then dereferenced, in which case the
1566 -- generalized indexing call is also non-overloaded.
1568 if Nkind (Expr) = N_Indexed_Component
1569 and then Present (Generalized_Indexing (Expr))
1571 Set_Is_Overloaded (Generalized_Indexing (Expr), False);
1575 Make_Explicit_Dereference (Loc,
1577 Make_Selected_Component (Loc,
1578 Prefix => Relocate_Node (Expr),
1579 Selector_Name => New_Occurrence_Of (Disc, Loc))));
1580 Set_Etype (Prefix (Expr), Etype (Disc));
1581 Set_Etype (Expr, Designated_Type (Etype (Disc)));
1582 end Build_Explicit_Dereference;
1584 -----------------------------------
1585 -- Cannot_Raise_Constraint_Error --
1586 -----------------------------------
1588 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
1590 if Compile_Time_Known_Value (Expr) then
1593 elsif Do_Range_Check (Expr) then
1596 elsif Raises_Constraint_Error (Expr) then
1600 case Nkind (Expr) is
1601 when N_Identifier =>
1604 when N_Expanded_Name =>
1607 when N_Selected_Component =>
1608 return not Do_Discriminant_Check (Expr);
1610 when N_Attribute_Reference =>
1611 if Do_Overflow_Check (Expr) then
1614 elsif No (Expressions (Expr)) then
1622 N := First (Expressions (Expr));
1623 while Present (N) loop
1624 if Cannot_Raise_Constraint_Error (N) then
1635 when N_Type_Conversion =>
1636 if Do_Overflow_Check (Expr)
1637 or else Do_Length_Check (Expr)
1638 or else Do_Tag_Check (Expr)
1642 return Cannot_Raise_Constraint_Error (Expression (Expr));
1645 when N_Unchecked_Type_Conversion =>
1646 return Cannot_Raise_Constraint_Error (Expression (Expr));
1649 if Do_Overflow_Check (Expr) then
1652 return Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1659 if Do_Division_Check (Expr)
1661 Do_Overflow_Check (Expr)
1666 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1668 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1687 | N_Op_Shift_Right_Arithmetic
1691 if Do_Overflow_Check (Expr) then
1695 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1697 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1704 end Cannot_Raise_Constraint_Error;
1706 -----------------------------
1707 -- Check_Part_Of_Reference --
1708 -----------------------------
1710 procedure Check_Part_Of_Reference (Var_Id : Entity_Id; Ref : Node_Id) is
1711 Conc_Typ : constant Entity_Id := Encapsulating_State (Var_Id);
1713 OK_Use : Boolean := False;
1716 Spec_Id : Entity_Id;
1719 -- Traverse the parent chain looking for a suitable context for the
1720 -- reference to the concurrent constituent.
1722 Par := Parent (Ref);
1723 while Present (Par) loop
1724 if Nkind (Par) = N_Pragma then
1725 Prag_Nam := Pragma_Name (Par);
1727 -- A concurrent constituent is allowed to appear in pragmas
1728 -- Initial_Condition and Initializes as this is part of the
1729 -- elaboration checks for the constituent (SPARK RM 9.3).
1731 if Nam_In (Prag_Nam, Name_Initial_Condition, Name_Initializes) then
1735 -- When the reference appears within pragma Depends or Global,
1736 -- check whether the pragma applies to a single task type. Note
1737 -- that the pragma is not encapsulated by the type definition,
1738 -- but this is still a valid context.
1740 elsif Nam_In (Prag_Nam, Name_Depends, Name_Global) then
1741 Decl := Find_Related_Declaration_Or_Body (Par);
1743 if Nkind (Decl) = N_Object_Declaration
1744 and then Defining_Entity (Decl) = Conc_Typ
1751 -- The reference appears somewhere in the definition of the single
1752 -- protected/task type (SPARK RM 9.3).
1754 elsif Nkind_In (Par, N_Single_Protected_Declaration,
1755 N_Single_Task_Declaration)
1756 and then Defining_Entity (Par) = Conc_Typ
1761 -- The reference appears within the expanded declaration or the body
1762 -- of the single protected/task type (SPARK RM 9.3).
1764 elsif Nkind_In (Par, N_Protected_Body,
1765 N_Protected_Type_Declaration,
1767 N_Task_Type_Declaration)
1769 Spec_Id := Unique_Defining_Entity (Par);
1771 if Present (Anonymous_Object (Spec_Id))
1772 and then Anonymous_Object (Spec_Id) = Conc_Typ
1778 -- The reference has been relocated within an internally generated
1779 -- package or subprogram. Assume that the reference is legal as the
1780 -- real check was already performed in the original context of the
1783 elsif Nkind_In (Par, N_Package_Body,
1784 N_Package_Declaration,
1786 N_Subprogram_Declaration)
1787 and then not Comes_From_Source (Par)
1792 -- The reference has been relocated to an inlined body for GNATprove.
1793 -- Assume that the reference is legal as the real check was already
1794 -- performed in the original context of the reference.
1796 elsif GNATprove_Mode
1797 and then Nkind (Par) = N_Subprogram_Body
1798 and then Chars (Defining_Entity (Par)) = Name_uParent
1804 Par := Parent (Par);
1807 -- The reference is illegal as it appears outside the definition or
1808 -- body of the single protected/task type.
1812 ("reference to variable & cannot appear in this context",
1814 Error_Msg_Name_1 := Chars (Var_Id);
1816 if Ekind (Conc_Typ) = E_Protected_Type then
1818 ("\% is constituent of single protected type &", Ref, Conc_Typ);
1821 ("\% is constituent of single task type &", Ref, Conc_Typ);
1824 end Check_Part_Of_Reference;
1826 -----------------------------------------
1827 -- Check_Dynamically_Tagged_Expression --
1828 -----------------------------------------
1830 procedure Check_Dynamically_Tagged_Expression
1833 Related_Nod : Node_Id)
1836 pragma Assert (Is_Tagged_Type (Typ));
1838 -- In order to avoid spurious errors when analyzing the expanded code,
1839 -- this check is done only for nodes that come from source and for
1840 -- actuals of generic instantiations.
1842 if (Comes_From_Source (Related_Nod)
1843 or else In_Generic_Actual (Expr))
1844 and then (Is_Class_Wide_Type (Etype (Expr))
1845 or else Is_Dynamically_Tagged (Expr))
1846 and then Is_Tagged_Type (Typ)
1847 and then not Is_Class_Wide_Type (Typ)
1849 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
1851 end Check_Dynamically_Tagged_Expression;
1853 --------------------------
1854 -- Check_Fully_Declared --
1855 --------------------------
1857 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
1859 if Ekind (T) = E_Incomplete_Type then
1861 -- Ada 2005 (AI-50217): If the type is available through a limited
1862 -- with_clause, verify that its full view has been analyzed.
1864 if From_Limited_With (T)
1865 and then Present (Non_Limited_View (T))
1866 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1868 -- The non-limited view is fully declared
1874 ("premature usage of incomplete}", N, First_Subtype (T));
1877 -- Need comments for these tests ???
1879 elsif Has_Private_Component (T)
1880 and then not Is_Generic_Type (Root_Type (T))
1881 and then not In_Spec_Expression
1883 -- Special case: if T is the anonymous type created for a single
1884 -- task or protected object, use the name of the source object.
1886 if Is_Concurrent_Type (T)
1887 and then not Comes_From_Source (T)
1888 and then Nkind (N) = N_Object_Declaration
1891 ("type of& has incomplete component",
1892 N, Defining_Identifier (N));
1895 ("premature usage of incomplete}",
1896 N, First_Subtype (T));
1899 end Check_Fully_Declared;
1901 -------------------------------------------
1902 -- Check_Function_With_Address_Parameter --
1903 -------------------------------------------
1905 procedure Check_Function_With_Address_Parameter (Subp_Id : Entity_Id) is
1910 F := First_Formal (Subp_Id);
1911 while Present (F) loop
1914 if Is_Private_Type (T) and then Present (Full_View (T)) then
1918 if Is_Descendant_Of_Address (T) or else Is_Limited_Type (T) then
1919 Set_Is_Pure (Subp_Id, False);
1925 end Check_Function_With_Address_Parameter;
1927 -------------------------------------
1928 -- Check_Function_Writable_Actuals --
1929 -------------------------------------
1931 procedure Check_Function_Writable_Actuals (N : Node_Id) is
1932 Writable_Actuals_List : Elist_Id := No_Elist;
1933 Identifiers_List : Elist_Id := No_Elist;
1934 Aggr_Error_Node : Node_Id := Empty;
1935 Error_Node : Node_Id := Empty;
1937 procedure Collect_Identifiers (N : Node_Id);
1938 -- In a single traversal of subtree N collect in Writable_Actuals_List
1939 -- all the actuals of functions with writable actuals, and in the list
1940 -- Identifiers_List collect all the identifiers that are not actuals of
1941 -- functions with writable actuals. If a writable actual is referenced
1942 -- twice as writable actual then Error_Node is set to reference its
1943 -- second occurrence, the error is reported, and the tree traversal
1946 function Get_Function_Id (Call : Node_Id) return Entity_Id;
1947 -- Return the entity associated with the function call
1949 procedure Preanalyze_Without_Errors (N : Node_Id);
1950 -- Preanalyze N without reporting errors. Very dubious, you can't just
1951 -- go analyzing things more than once???
1953 -------------------------
1954 -- Collect_Identifiers --
1955 -------------------------
1957 procedure Collect_Identifiers (N : Node_Id) is
1959 function Check_Node (N : Node_Id) return Traverse_Result;
1960 -- Process a single node during the tree traversal to collect the
1961 -- writable actuals of functions and all the identifiers which are
1962 -- not writable actuals of functions.
1964 function Contains (List : Elist_Id; N : Node_Id) return Boolean;
1965 -- Returns True if List has a node whose Entity is Entity (N)
1971 function Check_Node (N : Node_Id) return Traverse_Result is
1972 Is_Writable_Actual : Boolean := False;
1976 if Nkind (N) = N_Identifier then
1978 -- No analysis possible if the entity is not decorated
1980 if No (Entity (N)) then
1983 -- Don't collect identifiers of packages, called functions, etc
1985 elsif Ekind_In (Entity (N), E_Package,
1992 -- For rewritten nodes, continue the traversal in the original
1993 -- subtree. Needed to handle aggregates in original expressions
1994 -- extracted from the tree by Remove_Side_Effects.
1996 elsif Is_Rewrite_Substitution (N) then
1997 Collect_Identifiers (Original_Node (N));
2000 -- For now we skip aggregate discriminants, since they require
2001 -- performing the analysis in two phases to identify conflicts:
2002 -- first one analyzing discriminants and second one analyzing
2003 -- the rest of components (since at run time, discriminants are
2004 -- evaluated prior to components): too much computation cost
2005 -- to identify a corner case???
2007 elsif Nkind (Parent (N)) = N_Component_Association
2008 and then Nkind_In (Parent (Parent (N)),
2010 N_Extension_Aggregate)
2013 Choice : constant Node_Id := First (Choices (Parent (N)));
2016 if Ekind (Entity (N)) = E_Discriminant then
2019 elsif Expression (Parent (N)) = N
2020 and then Nkind (Choice) = N_Identifier
2021 and then Ekind (Entity (Choice)) = E_Discriminant
2027 -- Analyze if N is a writable actual of a function
2029 elsif Nkind (Parent (N)) = N_Function_Call then
2031 Call : constant Node_Id := Parent (N);
2036 Id := Get_Function_Id (Call);
2038 -- In case of previous error, no check is possible
2044 if Ekind_In (Id, E_Function, E_Generic_Function)
2045 and then Has_Out_Or_In_Out_Parameter (Id)
2047 Formal := First_Formal (Id);
2048 Actual := First_Actual (Call);
2049 while Present (Actual) and then Present (Formal) loop
2051 if Ekind_In (Formal, E_Out_Parameter,
2054 Is_Writable_Actual := True;
2060 Next_Formal (Formal);
2061 Next_Actual (Actual);
2067 if Is_Writable_Actual then
2069 -- Skip checking the error in non-elementary types since
2070 -- RM 6.4.1(6.15/3) is restricted to elementary types, but
2071 -- store this actual in Writable_Actuals_List since it is
2072 -- needed to perform checks on other constructs that have
2073 -- arbitrary order of evaluation (for example, aggregates).
2075 if not Is_Elementary_Type (Etype (N)) then
2076 if not Contains (Writable_Actuals_List, N) then
2077 Append_New_Elmt (N, To => Writable_Actuals_List);
2080 -- Second occurrence of an elementary type writable actual
2082 elsif Contains (Writable_Actuals_List, N) then
2084 -- Report the error on the second occurrence of the
2085 -- identifier. We cannot assume that N is the second
2086 -- occurrence (according to their location in the
2087 -- sources), since Traverse_Func walks through Field2
2088 -- last (see comment in the body of Traverse_Func).
2094 Elmt := First_Elmt (Writable_Actuals_List);
2095 while Present (Elmt)
2096 and then Entity (Node (Elmt)) /= Entity (N)
2101 if Sloc (N) > Sloc (Node (Elmt)) then
2104 Error_Node := Node (Elmt);
2108 ("value may be affected by call to & "
2109 & "because order of evaluation is arbitrary",
2114 -- First occurrence of a elementary type writable actual
2117 Append_New_Elmt (N, To => Writable_Actuals_List);
2121 if Identifiers_List = No_Elist then
2122 Identifiers_List := New_Elmt_List;
2125 Append_Unique_Elmt (N, Identifiers_List);
2138 N : Node_Id) return Boolean
2140 pragma Assert (Nkind (N) in N_Has_Entity);
2145 if List = No_Elist then
2149 Elmt := First_Elmt (List);
2150 while Present (Elmt) loop
2151 if Entity (Node (Elmt)) = Entity (N) then
2165 procedure Do_Traversal is new Traverse_Proc (Check_Node);
2166 -- The traversal procedure
2168 -- Start of processing for Collect_Identifiers
2171 if Present (Error_Node) then
2175 if Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
2180 end Collect_Identifiers;
2182 ---------------------
2183 -- Get_Function_Id --
2184 ---------------------
2186 function Get_Function_Id (Call : Node_Id) return Entity_Id is
2187 Nam : constant Node_Id := Name (Call);
2191 if Nkind (Nam) = N_Explicit_Dereference then
2193 pragma Assert (Ekind (Id) = E_Subprogram_Type);
2195 elsif Nkind (Nam) = N_Selected_Component then
2196 Id := Entity (Selector_Name (Nam));
2198 elsif Nkind (Nam) = N_Indexed_Component then
2199 Id := Entity (Selector_Name (Prefix (Nam)));
2206 end Get_Function_Id;
2208 -------------------------------
2209 -- Preanalyze_Without_Errors --
2210 -------------------------------
2212 procedure Preanalyze_Without_Errors (N : Node_Id) is
2213 Status : constant Boolean := Get_Ignore_Errors;
2215 Set_Ignore_Errors (True);
2217 Set_Ignore_Errors (Status);
2218 end Preanalyze_Without_Errors;
2220 -- Start of processing for Check_Function_Writable_Actuals
2223 -- The check only applies to Ada 2012 code on which Check_Actuals has
2224 -- been set, and only to constructs that have multiple constituents
2225 -- whose order of evaluation is not specified by the language.
2227 if Ada_Version < Ada_2012
2228 or else not Check_Actuals (N)
2229 or else (not (Nkind (N) in N_Op)
2230 and then not (Nkind (N) in N_Membership_Test)
2231 and then not Nkind_In (N, N_Range,
2233 N_Extension_Aggregate,
2234 N_Full_Type_Declaration,
2236 N_Procedure_Call_Statement,
2237 N_Entry_Call_Statement))
2238 or else (Nkind (N) = N_Full_Type_Declaration
2239 and then not Is_Record_Type (Defining_Identifier (N)))
2241 -- In addition, this check only applies to source code, not to code
2242 -- generated by constraint checks.
2244 or else not Comes_From_Source (N)
2249 -- If a construct C has two or more direct constituents that are names
2250 -- or expressions whose evaluation may occur in an arbitrary order, at
2251 -- least one of which contains a function call with an in out or out
2252 -- parameter, then the construct is legal only if: for each name N that
2253 -- is passed as a parameter of mode in out or out to some inner function
2254 -- call C2 (not including the construct C itself), there is no other
2255 -- name anywhere within a direct constituent of the construct C other
2256 -- than the one containing C2, that is known to refer to the same
2257 -- object (RM 6.4.1(6.17/3)).
2261 Collect_Identifiers (Low_Bound (N));
2262 Collect_Identifiers (High_Bound (N));
2264 when N_Membership_Test
2271 Collect_Identifiers (Left_Opnd (N));
2273 if Present (Right_Opnd (N)) then
2274 Collect_Identifiers (Right_Opnd (N));
2277 if Nkind_In (N, N_In, N_Not_In)
2278 and then Present (Alternatives (N))
2280 Expr := First (Alternatives (N));
2281 while Present (Expr) loop
2282 Collect_Identifiers (Expr);
2289 when N_Full_Type_Declaration =>
2291 function Get_Record_Part (N : Node_Id) return Node_Id;
2292 -- Return the record part of this record type definition
2294 function Get_Record_Part (N : Node_Id) return Node_Id is
2295 Type_Def : constant Node_Id := Type_Definition (N);
2297 if Nkind (Type_Def) = N_Derived_Type_Definition then
2298 return Record_Extension_Part (Type_Def);
2302 end Get_Record_Part;
2305 Def_Id : Entity_Id := Defining_Identifier (N);
2306 Rec : Node_Id := Get_Record_Part (N);
2309 -- No need to perform any analysis if the record has no
2312 if No (Rec) or else No (Component_List (Rec)) then
2316 -- Collect the identifiers starting from the deepest
2317 -- derivation. Done to report the error in the deepest
2321 if Present (Component_List (Rec)) then
2322 Comp := First (Component_Items (Component_List (Rec)));
2323 while Present (Comp) loop
2324 if Nkind (Comp) = N_Component_Declaration
2325 and then Present (Expression (Comp))
2327 Collect_Identifiers (Expression (Comp));
2334 exit when No (Underlying_Type (Etype (Def_Id)))
2335 or else Base_Type (Underlying_Type (Etype (Def_Id)))
2338 Def_Id := Base_Type (Underlying_Type (Etype (Def_Id)));
2339 Rec := Get_Record_Part (Parent (Def_Id));
2343 when N_Entry_Call_Statement
2347 Id : constant Entity_Id := Get_Function_Id (N);
2352 Formal := First_Formal (Id);
2353 Actual := First_Actual (N);
2354 while Present (Actual) and then Present (Formal) loop
2355 if Ekind_In (Formal, E_Out_Parameter,
2358 Collect_Identifiers (Actual);
2361 Next_Formal (Formal);
2362 Next_Actual (Actual);
2367 | N_Extension_Aggregate
2372 Comp_Expr : Node_Id;
2375 -- Handle the N_Others_Choice of array aggregates with static
2376 -- bounds. There is no need to perform this analysis in
2377 -- aggregates without static bounds since we cannot evaluate
2378 -- if the N_Others_Choice covers several elements. There is
2379 -- no need to handle the N_Others choice of record aggregates
2380 -- since at this stage it has been already expanded by
2381 -- Resolve_Record_Aggregate.
2383 if Is_Array_Type (Etype (N))
2384 and then Nkind (N) = N_Aggregate
2385 and then Present (Aggregate_Bounds (N))
2386 and then Compile_Time_Known_Bounds (Etype (N))
2387 and then Expr_Value (High_Bound (Aggregate_Bounds (N)))
2389 Expr_Value (Low_Bound (Aggregate_Bounds (N)))
2392 Count_Components : Uint := Uint_0;
2393 Num_Components : Uint;
2394 Others_Assoc : Node_Id;
2395 Others_Choice : Node_Id := Empty;
2396 Others_Box_Present : Boolean := False;
2399 -- Count positional associations
2401 if Present (Expressions (N)) then
2402 Comp_Expr := First (Expressions (N));
2403 while Present (Comp_Expr) loop
2404 Count_Components := Count_Components + 1;
2409 -- Count the rest of elements and locate the N_Others
2412 Assoc := First (Component_Associations (N));
2413 while Present (Assoc) loop
2414 Choice := First (Choices (Assoc));
2415 while Present (Choice) loop
2416 if Nkind (Choice) = N_Others_Choice then
2417 Others_Assoc := Assoc;
2418 Others_Choice := Choice;
2419 Others_Box_Present := Box_Present (Assoc);
2421 -- Count several components
2423 elsif Nkind_In (Choice, N_Range,
2424 N_Subtype_Indication)
2425 or else (Is_Entity_Name (Choice)
2426 and then Is_Type (Entity (Choice)))
2431 Get_Index_Bounds (Choice, L, H);
2433 (Compile_Time_Known_Value (L)
2434 and then Compile_Time_Known_Value (H));
2437 + Expr_Value (H) - Expr_Value (L) + 1;
2440 -- Count single component. No other case available
2441 -- since we are handling an aggregate with static
2445 pragma Assert (Is_OK_Static_Expression (Choice)
2446 or else Nkind (Choice) = N_Identifier
2447 or else Nkind (Choice) = N_Integer_Literal);
2449 Count_Components := Count_Components + 1;
2459 Expr_Value (High_Bound (Aggregate_Bounds (N))) -
2460 Expr_Value (Low_Bound (Aggregate_Bounds (N))) + 1;
2462 pragma Assert (Count_Components <= Num_Components);
2464 -- Handle the N_Others choice if it covers several
2467 if Present (Others_Choice)
2468 and then (Num_Components - Count_Components) > 1
2470 if not Others_Box_Present then
2472 -- At this stage, if expansion is active, the
2473 -- expression of the others choice has not been
2474 -- analyzed. Hence we generate a duplicate and
2475 -- we analyze it silently to have available the
2476 -- minimum decoration required to collect the
2479 if not Expander_Active then
2480 Comp_Expr := Expression (Others_Assoc);
2483 New_Copy_Tree (Expression (Others_Assoc));
2484 Preanalyze_Without_Errors (Comp_Expr);
2487 Collect_Identifiers (Comp_Expr);
2489 if Writable_Actuals_List /= No_Elist then
2491 -- As suggested by Robert, at current stage we
2492 -- report occurrences of this case as warnings.
2495 ("writable function parameter may affect "
2496 & "value in other component because order "
2497 & "of evaluation is unspecified??",
2498 Node (First_Elmt (Writable_Actuals_List)));
2504 -- For an array aggregate, a discrete_choice_list that has
2505 -- a nonstatic range is considered as two or more separate
2506 -- occurrences of the expression (RM 6.4.1(20/3)).
2508 elsif Is_Array_Type (Etype (N))
2509 and then Nkind (N) = N_Aggregate
2510 and then Present (Aggregate_Bounds (N))
2511 and then not Compile_Time_Known_Bounds (Etype (N))
2513 -- Collect identifiers found in the dynamic bounds
2516 Count_Components : Natural := 0;
2517 Low, High : Node_Id;
2520 Assoc := First (Component_Associations (N));
2521 while Present (Assoc) loop
2522 Choice := First (Choices (Assoc));
2523 while Present (Choice) loop
2524 if Nkind_In (Choice, N_Range,
2525 N_Subtype_Indication)
2526 or else (Is_Entity_Name (Choice)
2527 and then Is_Type (Entity (Choice)))
2529 Get_Index_Bounds (Choice, Low, High);
2531 if not Compile_Time_Known_Value (Low) then
2532 Collect_Identifiers (Low);
2534 if No (Aggr_Error_Node) then
2535 Aggr_Error_Node := Low;
2539 if not Compile_Time_Known_Value (High) then
2540 Collect_Identifiers (High);
2542 if No (Aggr_Error_Node) then
2543 Aggr_Error_Node := High;
2547 -- The RM rule is violated if there is more than
2548 -- a single choice in a component association.
2551 Count_Components := Count_Components + 1;
2553 if No (Aggr_Error_Node)
2554 and then Count_Components > 1
2556 Aggr_Error_Node := Choice;
2559 if not Compile_Time_Known_Value (Choice) then
2560 Collect_Identifiers (Choice);
2572 -- Handle ancestor part of extension aggregates
2574 if Nkind (N) = N_Extension_Aggregate then
2575 Collect_Identifiers (Ancestor_Part (N));
2578 -- Handle positional associations
2580 if Present (Expressions (N)) then
2581 Comp_Expr := First (Expressions (N));
2582 while Present (Comp_Expr) loop
2583 if not Is_OK_Static_Expression (Comp_Expr) then
2584 Collect_Identifiers (Comp_Expr);
2591 -- Handle discrete associations
2593 if Present (Component_Associations (N)) then
2594 Assoc := First (Component_Associations (N));
2595 while Present (Assoc) loop
2597 if not Box_Present (Assoc) then
2598 Choice := First (Choices (Assoc));
2599 while Present (Choice) loop
2601 -- For now we skip discriminants since it requires
2602 -- performing the analysis in two phases: first one
2603 -- analyzing discriminants and second one analyzing
2604 -- the rest of components since discriminants are
2605 -- evaluated prior to components: too much extra
2606 -- work to detect a corner case???
2608 if Nkind (Choice) in N_Has_Entity
2609 and then Present (Entity (Choice))
2610 and then Ekind (Entity (Choice)) = E_Discriminant
2614 elsif Box_Present (Assoc) then
2618 if not Analyzed (Expression (Assoc)) then
2620 New_Copy_Tree (Expression (Assoc));
2621 Set_Parent (Comp_Expr, Parent (N));
2622 Preanalyze_Without_Errors (Comp_Expr);
2624 Comp_Expr := Expression (Assoc);
2627 Collect_Identifiers (Comp_Expr);
2643 -- No further action needed if we already reported an error
2645 if Present (Error_Node) then
2649 -- Check violation of RM 6.20/3 in aggregates
2651 if Present (Aggr_Error_Node)
2652 and then Writable_Actuals_List /= No_Elist
2655 ("value may be affected by call in other component because they "
2656 & "are evaluated in unspecified order",
2657 Node (First_Elmt (Writable_Actuals_List)));
2661 -- Check if some writable argument of a function is referenced
2663 if Writable_Actuals_List /= No_Elist
2664 and then Identifiers_List /= No_Elist
2671 Elmt_1 := First_Elmt (Writable_Actuals_List);
2672 while Present (Elmt_1) loop
2673 Elmt_2 := First_Elmt (Identifiers_List);
2674 while Present (Elmt_2) loop
2675 if Entity (Node (Elmt_1)) = Entity (Node (Elmt_2)) then
2676 case Nkind (Parent (Node (Elmt_2))) is
2678 | N_Component_Association
2679 | N_Component_Declaration
2682 ("value may be affected by call in other "
2683 & "component because they are evaluated "
2684 & "in unspecified order",
2691 ("value may be affected by call in other "
2692 & "alternative because they are evaluated "
2693 & "in unspecified order",
2698 ("value of actual may be affected by call in "
2699 & "other actual because they are evaluated "
2700 & "in unspecified order",
2712 end Check_Function_Writable_Actuals;
2714 --------------------------------
2715 -- Check_Implicit_Dereference --
2716 --------------------------------
2718 procedure Check_Implicit_Dereference (N : Node_Id; Typ : Entity_Id) is
2724 if Nkind (N) = N_Indexed_Component
2725 and then Present (Generalized_Indexing (N))
2727 Nam := Generalized_Indexing (N);
2732 if Ada_Version < Ada_2012
2733 or else not Has_Implicit_Dereference (Base_Type (Typ))
2737 elsif not Comes_From_Source (N)
2738 and then Nkind (N) /= N_Indexed_Component
2742 elsif Is_Entity_Name (Nam) and then Is_Type (Entity (Nam)) then
2746 Disc := First_Discriminant (Typ);
2747 while Present (Disc) loop
2748 if Has_Implicit_Dereference (Disc) then
2749 Desig := Designated_Type (Etype (Disc));
2750 Add_One_Interp (Nam, Disc, Desig);
2752 -- If the node is a generalized indexing, add interpretation
2753 -- to that node as well, for subsequent resolution.
2755 if Nkind (N) = N_Indexed_Component then
2756 Add_One_Interp (N, Disc, Desig);
2759 -- If the operation comes from a generic unit and the context
2760 -- is a selected component, the selector name may be global
2761 -- and set in the instance already. Remove the entity to
2762 -- force resolution of the selected component, and the
2763 -- generation of an explicit dereference if needed.
2766 and then Nkind (Parent (Nam)) = N_Selected_Component
2768 Set_Entity (Selector_Name (Parent (Nam)), Empty);
2774 Next_Discriminant (Disc);
2777 end Check_Implicit_Dereference;
2779 ----------------------------------
2780 -- Check_Internal_Protected_Use --
2781 ----------------------------------
2783 procedure Check_Internal_Protected_Use (N : Node_Id; Nam : Entity_Id) is
2789 while Present (S) loop
2790 if S = Standard_Standard then
2793 elsif Ekind (S) = E_Function
2794 and then Ekind (Scope (S)) = E_Protected_Type
2803 if Scope (Nam) = Prot and then Ekind (Nam) /= E_Function then
2805 -- An indirect function call (e.g. a callback within a protected
2806 -- function body) is not statically illegal. If the access type is
2807 -- anonymous and is the type of an access parameter, the scope of Nam
2808 -- will be the protected type, but it is not a protected operation.
2810 if Ekind (Nam) = E_Subprogram_Type
2812 Nkind (Associated_Node_For_Itype (Nam)) = N_Function_Specification
2816 elsif Nkind (N) = N_Subprogram_Renaming_Declaration then
2818 ("within protected function cannot use protected "
2819 & "procedure in renaming or as generic actual", N);
2821 elsif Nkind (N) = N_Attribute_Reference then
2823 ("within protected function cannot take access of "
2824 & " protected procedure", N);
2828 ("within protected function, protected object is constant", N);
2830 ("\cannot call operation that may modify it", N);
2833 end Check_Internal_Protected_Use;
2835 ---------------------------------------
2836 -- Check_Later_Vs_Basic_Declarations --
2837 ---------------------------------------
2839 procedure Check_Later_Vs_Basic_Declarations
2841 During_Parsing : Boolean)
2843 Body_Sloc : Source_Ptr;
2846 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
2847 -- Return whether Decl is considered as a declarative item.
2848 -- When During_Parsing is True, the semantics of Ada 83 is followed.
2849 -- When During_Parsing is False, the semantics of SPARK is followed.
2851 -------------------------------
2852 -- Is_Later_Declarative_Item --
2853 -------------------------------
2855 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
2857 if Nkind (Decl) in N_Later_Decl_Item then
2860 elsif Nkind (Decl) = N_Pragma then
2863 elsif During_Parsing then
2866 -- In SPARK, a package declaration is not considered as a later
2867 -- declarative item.
2869 elsif Nkind (Decl) = N_Package_Declaration then
2872 -- In SPARK, a renaming is considered as a later declarative item
2874 elsif Nkind (Decl) in N_Renaming_Declaration then
2880 end Is_Later_Declarative_Item;
2882 -- Start of processing for Check_Later_Vs_Basic_Declarations
2885 Decl := First (Decls);
2887 -- Loop through sequence of basic declarative items
2889 Outer : while Present (Decl) loop
2890 if not Nkind_In (Decl, N_Subprogram_Body, N_Package_Body, N_Task_Body)
2891 and then Nkind (Decl) not in N_Body_Stub
2895 -- Once a body is encountered, we only allow later declarative
2896 -- items. The inner loop checks the rest of the list.
2899 Body_Sloc := Sloc (Decl);
2901 Inner : while Present (Decl) loop
2902 if not Is_Later_Declarative_Item (Decl) then
2903 if During_Parsing then
2904 if Ada_Version = Ada_83 then
2905 Error_Msg_Sloc := Body_Sloc;
2907 ("(Ada 83) decl cannot appear after body#", Decl);
2910 Error_Msg_Sloc := Body_Sloc;
2911 Check_SPARK_05_Restriction
2912 ("decl cannot appear after body#", Decl);
2920 end Check_Later_Vs_Basic_Declarations;
2922 ---------------------------
2923 -- Check_No_Hidden_State --
2924 ---------------------------
2926 procedure Check_No_Hidden_State (Id : Entity_Id) is
2927 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean;
2928 -- Determine whether the entity of a package denoted by Pkg has a null
2931 -----------------------------
2932 -- Has_Null_Abstract_State --
2933 -----------------------------
2935 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean is
2936 States : constant Elist_Id := Abstract_States (Pkg);
2939 -- Check first available state of related package. A null abstract
2940 -- state always appears as the sole element of the state list.
2944 and then Is_Null_State (Node (First_Elmt (States)));
2945 end Has_Null_Abstract_State;
2949 Context : Entity_Id := Empty;
2950 Not_Visible : Boolean := False;
2953 -- Start of processing for Check_No_Hidden_State
2956 pragma Assert (Ekind_In (Id, E_Abstract_State, E_Variable));
2958 -- Find the proper context where the object or state appears
2961 while Present (Scop) loop
2964 -- Keep track of the context's visibility
2966 Not_Visible := Not_Visible or else In_Private_Part (Context);
2968 -- Prevent the search from going too far
2970 if Context = Standard_Standard then
2973 -- Objects and states that appear immediately within a subprogram or
2974 -- inside a construct nested within a subprogram do not introduce a
2975 -- hidden state. They behave as local variable declarations.
2977 elsif Is_Subprogram (Context) then
2980 -- When examining a package body, use the entity of the spec as it
2981 -- carries the abstract state declarations.
2983 elsif Ekind (Context) = E_Package_Body then
2984 Context := Spec_Entity (Context);
2987 -- Stop the traversal when a package subject to a null abstract state
2990 if Ekind_In (Context, E_Generic_Package, E_Package)
2991 and then Has_Null_Abstract_State (Context)
2996 Scop := Scope (Scop);
2999 -- At this point we know that there is at least one package with a null
3000 -- abstract state in visibility. Emit an error message unconditionally
3001 -- if the entity being processed is a state because the placement of the
3002 -- related package is irrelevant. This is not the case for objects as
3003 -- the intermediate context matters.
3005 if Present (Context)
3006 and then (Ekind (Id) = E_Abstract_State or else Not_Visible)
3008 Error_Msg_N ("cannot introduce hidden state &", Id);
3009 Error_Msg_NE ("\package & has null abstract state", Id, Context);
3011 end Check_No_Hidden_State;
3013 ----------------------------------------
3014 -- Check_Nonvolatile_Function_Profile --
3015 ----------------------------------------
3017 procedure Check_Nonvolatile_Function_Profile (Func_Id : Entity_Id) is
3021 -- Inspect all formal parameters
3023 Formal := First_Formal (Func_Id);
3024 while Present (Formal) loop
3025 if Is_Effectively_Volatile (Etype (Formal)) then
3027 ("nonvolatile function & cannot have a volatile parameter",
3031 Next_Formal (Formal);
3034 -- Inspect the return type
3036 if Is_Effectively_Volatile (Etype (Func_Id)) then
3038 ("nonvolatile function & cannot have a volatile return type",
3039 Result_Definition (Parent (Func_Id)), Func_Id);
3041 end Check_Nonvolatile_Function_Profile;
3043 ------------------------------------------
3044 -- Check_Potentially_Blocking_Operation --
3045 ------------------------------------------
3047 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
3051 -- N is one of the potentially blocking operations listed in 9.5.1(8).
3052 -- When pragma Detect_Blocking is active, the run time will raise
3053 -- Program_Error. Here we only issue a warning, since we generally
3054 -- support the use of potentially blocking operations in the absence
3057 -- Indirect blocking through a subprogram call cannot be diagnosed
3058 -- statically without interprocedural analysis, so we do not attempt
3061 S := Scope (Current_Scope);
3062 while Present (S) and then S /= Standard_Standard loop
3063 if Is_Protected_Type (S) then
3065 ("potentially blocking operation in protected operation??", N);
3071 end Check_Potentially_Blocking_Operation;
3073 ---------------------------------
3074 -- Check_Result_And_Post_State --
3075 ---------------------------------
3077 procedure Check_Result_And_Post_State (Subp_Id : Entity_Id) is
3078 procedure Check_Result_And_Post_State_In_Pragma
3080 Result_Seen : in out Boolean);
3081 -- Determine whether pragma Prag mentions attribute 'Result and whether
3082 -- the pragma contains an expression that evaluates differently in pre-
3083 -- and post-state. Prag is a [refined] postcondition or a contract-cases
3084 -- pragma. Result_Seen is set when the pragma mentions attribute 'Result
3086 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean;
3087 -- Determine whether subprogram Subp_Id contains at least one IN OUT
3088 -- formal parameter.
3090 -------------------------------------------
3091 -- Check_Result_And_Post_State_In_Pragma --
3092 -------------------------------------------
3094 procedure Check_Result_And_Post_State_In_Pragma
3096 Result_Seen : in out Boolean)
3098 procedure Check_Expression (Expr : Node_Id);
3099 -- Perform the 'Result and post-state checks on a given expression
3101 function Is_Function_Result (N : Node_Id) return Traverse_Result;
3102 -- Attempt to find attribute 'Result in a subtree denoted by N
3104 function Is_Trivial_Boolean (N : Node_Id) return Boolean;
3105 -- Determine whether source node N denotes "True" or "False"
3107 function Mentions_Post_State (N : Node_Id) return Boolean;
3108 -- Determine whether a subtree denoted by N mentions any construct
3109 -- that denotes a post-state.
3111 procedure Check_Function_Result is
3112 new Traverse_Proc (Is_Function_Result);
3114 ----------------------
3115 -- Check_Expression --
3116 ----------------------
3118 procedure Check_Expression (Expr : Node_Id) is
3120 if not Is_Trivial_Boolean (Expr) then
3121 Check_Function_Result (Expr);
3123 if not Mentions_Post_State (Expr) then
3124 if Pragma_Name (Prag) = Name_Contract_Cases then
3126 ("contract case does not check the outcome of calling "
3127 & "&?T?", Expr, Subp_Id);
3129 elsif Pragma_Name (Prag) = Name_Refined_Post then
3131 ("refined postcondition does not check the outcome of "
3132 & "calling &?T?", Prag, Subp_Id);
3136 ("postcondition does not check the outcome of calling "
3137 & "&?T?", Prag, Subp_Id);
3141 end Check_Expression;
3143 ------------------------
3144 -- Is_Function_Result --
3145 ------------------------
3147 function Is_Function_Result (N : Node_Id) return Traverse_Result is
3149 if Is_Attribute_Result (N) then
3150 Result_Seen := True;
3153 -- Continue the traversal
3158 end Is_Function_Result;
3160 ------------------------
3161 -- Is_Trivial_Boolean --
3162 ------------------------
3164 function Is_Trivial_Boolean (N : Node_Id) return Boolean is
3167 Comes_From_Source (N)
3168 and then Is_Entity_Name (N)
3169 and then (Entity (N) = Standard_True
3171 Entity (N) = Standard_False);
3172 end Is_Trivial_Boolean;
3174 -------------------------
3175 -- Mentions_Post_State --
3176 -------------------------
3178 function Mentions_Post_State (N : Node_Id) return Boolean is
3179 Post_State_Seen : Boolean := False;
3181 function Is_Post_State (N : Node_Id) return Traverse_Result;
3182 -- Attempt to find a construct that denotes a post-state. If this
3183 -- is the case, set flag Post_State_Seen.
3189 function Is_Post_State (N : Node_Id) return Traverse_Result is
3193 if Nkind_In (N, N_Explicit_Dereference, N_Function_Call) then
3194 Post_State_Seen := True;
3197 elsif Nkind_In (N, N_Expanded_Name, N_Identifier) then
3200 -- The entity may be modifiable through an implicit
3204 or else Ekind (Ent) in Assignable_Kind
3205 or else (Is_Access_Type (Etype (Ent))
3206 and then Nkind (Parent (N)) =
3207 N_Selected_Component)
3209 Post_State_Seen := True;
3213 elsif Nkind (N) = N_Attribute_Reference then
3214 if Attribute_Name (N) = Name_Old then
3217 elsif Attribute_Name (N) = Name_Result then
3218 Post_State_Seen := True;
3226 procedure Find_Post_State is new Traverse_Proc (Is_Post_State);
3228 -- Start of processing for Mentions_Post_State
3231 Find_Post_State (N);
3233 return Post_State_Seen;
3234 end Mentions_Post_State;
3238 Expr : constant Node_Id :=
3240 (First (Pragma_Argument_Associations (Prag)));
3241 Nam : constant Name_Id := Pragma_Name (Prag);
3244 -- Start of processing for Check_Result_And_Post_State_In_Pragma
3247 -- Examine all consequences
3249 if Nam = Name_Contract_Cases then
3250 CCase := First (Component_Associations (Expr));
3251 while Present (CCase) loop
3252 Check_Expression (Expression (CCase));
3257 -- Examine the expression of a postcondition
3259 else pragma Assert (Nam_In (Nam, Name_Postcondition,
3260 Name_Refined_Post));
3261 Check_Expression (Expr);
3263 end Check_Result_And_Post_State_In_Pragma;
3265 --------------------------
3266 -- Has_In_Out_Parameter --
3267 --------------------------
3269 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean is
3273 -- Traverse the formals looking for an IN OUT parameter
3275 Formal := First_Formal (Subp_Id);
3276 while Present (Formal) loop
3277 if Ekind (Formal) = E_In_Out_Parameter then
3281 Next_Formal (Formal);
3285 end Has_In_Out_Parameter;
3289 Items : constant Node_Id := Contract (Subp_Id);
3290 Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id);
3291 Case_Prag : Node_Id := Empty;
3292 Post_Prag : Node_Id := Empty;
3294 Seen_In_Case : Boolean := False;
3295 Seen_In_Post : Boolean := False;
3296 Spec_Id : Entity_Id;
3298 -- Start of processing for Check_Result_And_Post_State
3301 -- The lack of attribute 'Result or a post-state is classified as a
3302 -- suspicious contract. Do not perform the check if the corresponding
3303 -- swich is not set.
3305 if not Warn_On_Suspicious_Contract then
3308 -- Nothing to do if there is no contract
3310 elsif No (Items) then
3314 -- Retrieve the entity of the subprogram spec (if any)
3316 if Nkind (Subp_Decl) = N_Subprogram_Body
3317 and then Present (Corresponding_Spec (Subp_Decl))
3319 Spec_Id := Corresponding_Spec (Subp_Decl);
3321 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
3322 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
3324 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
3330 -- Examine all postconditions for attribute 'Result and a post-state
3332 Prag := Pre_Post_Conditions (Items);
3333 while Present (Prag) loop
3334 if Nam_In (Pragma_Name_Unmapped (Prag),
3335 Name_Postcondition, Name_Refined_Post)
3336 and then not Error_Posted (Prag)
3339 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Post);
3342 Prag := Next_Pragma (Prag);
3345 -- Examine the contract cases of the subprogram for attribute 'Result
3346 -- and a post-state.
3348 Prag := Contract_Test_Cases (Items);
3349 while Present (Prag) loop
3350 if Pragma_Name (Prag) = Name_Contract_Cases
3351 and then not Error_Posted (Prag)
3354 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Case);
3357 Prag := Next_Pragma (Prag);
3360 -- Do not emit any errors if the subprogram is not a function
3362 if not Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
3365 -- Regardless of whether the function has postconditions or contract
3366 -- cases, or whether they mention attribute 'Result, an IN OUT formal
3367 -- parameter is always treated as a result.
3369 elsif Has_In_Out_Parameter (Spec_Id) then
3372 -- The function has both a postcondition and contract cases and they do
3373 -- not mention attribute 'Result.
3375 elsif Present (Case_Prag)
3376 and then not Seen_In_Case
3377 and then Present (Post_Prag)
3378 and then not Seen_In_Post
3381 ("neither postcondition nor contract cases mention function "
3382 & "result?T?", Post_Prag);
3384 -- The function has contract cases only and they do not mention
3385 -- attribute 'Result.
3387 elsif Present (Case_Prag) and then not Seen_In_Case then
3388 Error_Msg_N ("contract cases do not mention result?T?", Case_Prag);
3390 -- The function has postconditions only and they do not mention
3391 -- attribute 'Result.
3393 elsif Present (Post_Prag) and then not Seen_In_Post then
3395 ("postcondition does not mention function result?T?", Post_Prag);
3397 end Check_Result_And_Post_State;
3399 -----------------------------
3400 -- Check_State_Refinements --
3401 -----------------------------
3403 procedure Check_State_Refinements
3405 Is_Main_Unit : Boolean := False)
3407 procedure Check_Package (Pack : Node_Id);
3408 -- Verify that all abstract states of a [generic] package denoted by its
3409 -- declarative node Pack have proper refinement. Recursively verify the
3410 -- visible and private declarations of the [generic] package for other
3413 procedure Check_Packages_In (Decls : List_Id);
3414 -- Seek out [generic] package declarations within declarative list Decls
3415 -- and verify the status of their abstract state refinement.
3417 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean;
3418 -- Determine whether construct N is subject to pragma SPARK_Mode Off
3424 procedure Check_Package (Pack : Node_Id) is
3425 Body_Id : constant Entity_Id := Corresponding_Body (Pack);
3426 Spec : constant Node_Id := Specification (Pack);
3427 States : constant Elist_Id :=
3428 Abstract_States (Defining_Entity (Pack));
3430 State_Elmt : Elmt_Id;
3431 State_Id : Entity_Id;
3434 -- Do not verify proper state refinement when the package is subject
3435 -- to pragma SPARK_Mode Off because this disables the requirement for
3436 -- state refinement.
3438 if SPARK_Mode_Is_Off (Pack) then
3441 -- State refinement can only occur in a completing packge body. Do
3442 -- not verify proper state refinement when the body is subject to
3443 -- pragma SPARK_Mode Off because this disables the requirement for
3444 -- state refinement.
3446 elsif Present (Body_Id)
3447 and then SPARK_Mode_Is_Off (Unit_Declaration_Node (Body_Id))
3451 -- Do not verify proper state refinement when the package is an
3452 -- instance as this check was already performed in the generic.
3454 elsif Present (Generic_Parent (Spec)) then
3457 -- Otherwise examine the contents of the package
3460 if Present (States) then
3461 State_Elmt := First_Elmt (States);
3462 while Present (State_Elmt) loop
3463 State_Id := Node (State_Elmt);
3465 -- Emit an error when a non-null state lacks any form of
3468 if not Is_Null_State (State_Id)
3469 and then not Has_Null_Refinement (State_Id)
3470 and then not Has_Non_Null_Refinement (State_Id)
3472 Error_Msg_N ("state & requires refinement", State_Id);
3475 Next_Elmt (State_Elmt);
3479 Check_Packages_In (Visible_Declarations (Spec));
3480 Check_Packages_In (Private_Declarations (Spec));
3484 -----------------------
3485 -- Check_Packages_In --
3486 -----------------------
3488 procedure Check_Packages_In (Decls : List_Id) is
3492 if Present (Decls) then
3493 Decl := First (Decls);
3494 while Present (Decl) loop
3495 if Nkind_In (Decl, N_Generic_Package_Declaration,
3496 N_Package_Declaration)
3498 Check_Package (Decl);
3504 end Check_Packages_In;
3506 -----------------------
3507 -- SPARK_Mode_Is_Off --
3508 -----------------------
3510 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean is
3511 Prag : constant Node_Id := SPARK_Pragma (Defining_Entity (N));
3515 Present (Prag) and then Get_SPARK_Mode_From_Annotation (Prag) = Off;
3516 end SPARK_Mode_Is_Off;
3518 -- Start of processing for Check_State_Refinements
3521 -- A block may declare a nested package
3523 if Nkind (Context) = N_Block_Statement then
3524 Check_Packages_In (Declarations (Context));
3526 -- An entry, protected, subprogram, or task body may declare a nested
3529 elsif Nkind_In (Context, N_Entry_Body,
3534 -- Do not verify proper state refinement when the body is subject to
3535 -- pragma SPARK_Mode Off because this disables the requirement for
3536 -- state refinement.
3538 if not SPARK_Mode_Is_Off (Context) then
3539 Check_Packages_In (Declarations (Context));
3542 -- A package body may declare a nested package
3544 elsif Nkind (Context) = N_Package_Body then
3545 Check_Package (Unit_Declaration_Node (Corresponding_Spec (Context)));
3547 -- Do not verify proper state refinement when the body is subject to
3548 -- pragma SPARK_Mode Off because this disables the requirement for
3549 -- state refinement.
3551 if not SPARK_Mode_Is_Off (Context) then
3552 Check_Packages_In (Declarations (Context));
3555 -- A library level [generic] package may declare a nested package
3557 elsif Nkind_In (Context, N_Generic_Package_Declaration,
3558 N_Package_Declaration)
3559 and then Is_Main_Unit
3561 Check_Package (Context);
3563 end Check_State_Refinements;
3565 ------------------------------
3566 -- Check_Unprotected_Access --
3567 ------------------------------
3569 procedure Check_Unprotected_Access
3573 Cont_Encl_Typ : Entity_Id;
3574 Pref_Encl_Typ : Entity_Id;
3576 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
3577 -- Check whether Obj is a private component of a protected object.
3578 -- Return the protected type where the component resides, Empty
3581 function Is_Public_Operation return Boolean;
3582 -- Verify that the enclosing operation is callable from outside the
3583 -- protected object, to minimize false positives.
3585 ------------------------------
3586 -- Enclosing_Protected_Type --
3587 ------------------------------
3589 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
3591 if Is_Entity_Name (Obj) then
3593 Ent : Entity_Id := Entity (Obj);
3596 -- The object can be a renaming of a private component, use
3597 -- the original record component.
3599 if Is_Prival (Ent) then
3600 Ent := Prival_Link (Ent);
3603 if Is_Protected_Type (Scope (Ent)) then
3609 -- For indexed and selected components, recursively check the prefix
3611 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
3612 return Enclosing_Protected_Type (Prefix (Obj));
3614 -- The object does not denote a protected component
3619 end Enclosing_Protected_Type;
3621 -------------------------
3622 -- Is_Public_Operation --
3623 -------------------------
3625 function Is_Public_Operation return Boolean is
3631 while Present (S) and then S /= Pref_Encl_Typ loop
3632 if Scope (S) = Pref_Encl_Typ then
3633 E := First_Entity (Pref_Encl_Typ);
3635 and then E /= First_Private_Entity (Pref_Encl_Typ)
3649 end Is_Public_Operation;
3651 -- Start of processing for Check_Unprotected_Access
3654 if Nkind (Expr) = N_Attribute_Reference
3655 and then Attribute_Name (Expr) = Name_Unchecked_Access
3657 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
3658 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
3660 -- Check whether we are trying to export a protected component to a
3661 -- context with an equal or lower access level.
3663 if Present (Pref_Encl_Typ)
3664 and then No (Cont_Encl_Typ)
3665 and then Is_Public_Operation
3666 and then Scope_Depth (Pref_Encl_Typ) >=
3667 Object_Access_Level (Context)
3670 ("??possible unprotected access to protected data", Expr);
3673 end Check_Unprotected_Access;
3675 ------------------------------
3676 -- Check_Unused_Body_States --
3677 ------------------------------
3679 procedure Check_Unused_Body_States (Body_Id : Entity_Id) is
3680 procedure Process_Refinement_Clause
3683 -- Inspect all constituents of refinement clause Clause and remove any
3684 -- matches from body state list States.
3686 procedure Report_Unused_Body_States (States : Elist_Id);
3687 -- Emit errors for each abstract state or object found in list States
3689 -------------------------------
3690 -- Process_Refinement_Clause --
3691 -------------------------------
3693 procedure Process_Refinement_Clause
3697 procedure Process_Constituent (Constit : Node_Id);
3698 -- Remove constituent Constit from body state list States
3700 -------------------------
3701 -- Process_Constituent --
3702 -------------------------
3704 procedure Process_Constituent (Constit : Node_Id) is
3705 Constit_Id : Entity_Id;
3708 -- Guard against illegal constituents. Only abstract states and
3709 -- objects can appear on the right hand side of a refinement.
3711 if Is_Entity_Name (Constit) then
3712 Constit_Id := Entity_Of (Constit);
3714 if Present (Constit_Id)
3715 and then Ekind_In (Constit_Id, E_Abstract_State,
3719 Remove (States, Constit_Id);
3722 end Process_Constituent;
3728 -- Start of processing for Process_Refinement_Clause
3731 if Nkind (Clause) = N_Component_Association then
3732 Constit := Expression (Clause);
3734 -- Multiple constituents appear as an aggregate
3736 if Nkind (Constit) = N_Aggregate then
3737 Constit := First (Expressions (Constit));
3738 while Present (Constit) loop
3739 Process_Constituent (Constit);
3743 -- Various forms of a single constituent
3746 Process_Constituent (Constit);
3749 end Process_Refinement_Clause;
3751 -------------------------------
3752 -- Report_Unused_Body_States --
3753 -------------------------------
3755 procedure Report_Unused_Body_States (States : Elist_Id) is
3756 Posted : Boolean := False;
3757 State_Elmt : Elmt_Id;
3758 State_Id : Entity_Id;
3761 if Present (States) then
3762 State_Elmt := First_Elmt (States);
3763 while Present (State_Elmt) loop
3764 State_Id := Node (State_Elmt);
3766 -- Constants are part of the hidden state of a package, but the
3767 -- compiler cannot determine whether they have variable input
3768 -- (SPARK RM 7.1.1(2)) and cannot classify them properly as a
3769 -- hidden state. Do not emit an error when a constant does not
3770 -- participate in a state refinement, even though it acts as a
3773 if Ekind (State_Id) = E_Constant then
3776 -- Generate an error message of the form:
3778 -- body of package ... has unused hidden states
3779 -- abstract state ... defined at ...
3780 -- variable ... defined at ...
3786 ("body of package & has unused hidden states", Body_Id);
3789 Error_Msg_Sloc := Sloc (State_Id);
3791 if Ekind (State_Id) = E_Abstract_State then
3793 ("\abstract state & defined #", Body_Id, State_Id);
3796 SPARK_Msg_NE ("\variable & defined #", Body_Id, State_Id);
3800 Next_Elmt (State_Elmt);
3803 end Report_Unused_Body_States;
3807 Prag : constant Node_Id := Get_Pragma (Body_Id, Pragma_Refined_State);
3808 Spec_Id : constant Entity_Id := Spec_Entity (Body_Id);
3812 -- Start of processing for Check_Unused_Body_States
3815 -- Inspect the clauses of pragma Refined_State and determine whether all
3816 -- visible states declared within the package body participate in the
3819 if Present (Prag) then
3820 Clause := Expression (Get_Argument (Prag, Spec_Id));
3821 States := Collect_Body_States (Body_Id);
3823 -- Multiple non-null state refinements appear as an aggregate
3825 if Nkind (Clause) = N_Aggregate then
3826 Clause := First (Component_Associations (Clause));
3827 while Present (Clause) loop
3828 Process_Refinement_Clause (Clause, States);
3832 -- Various forms of a single state refinement
3835 Process_Refinement_Clause (Clause, States);
3838 -- Ensure that all abstract states and objects declared in the
3839 -- package body state space are utilized as constituents.
3841 Report_Unused_Body_States (States);
3843 end Check_Unused_Body_States;
3849 function Choice_List (N : Node_Id) return List_Id is
3851 if Nkind (N) = N_Iterated_Component_Association then
3852 return Discrete_Choices (N);
3858 -------------------------
3859 -- Collect_Body_States --
3860 -------------------------
3862 function Collect_Body_States (Body_Id : Entity_Id) return Elist_Id is
3863 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean;
3864 -- Determine whether object Obj_Id is a suitable visible state of a
3867 procedure Collect_Visible_States
3868 (Pack_Id : Entity_Id;
3869 States : in out Elist_Id);
3870 -- Gather the entities of all abstract states and objects declared in
3871 -- the visible state space of package Pack_Id.
3873 ----------------------------
3874 -- Collect_Visible_States --
3875 ----------------------------
3877 procedure Collect_Visible_States
3878 (Pack_Id : Entity_Id;
3879 States : in out Elist_Id)
3881 Item_Id : Entity_Id;
3884 -- Traverse the entity chain of the package and inspect all visible
3887 Item_Id := First_Entity (Pack_Id);
3888 while Present (Item_Id) and then not In_Private_Part (Item_Id) loop
3890 -- Do not consider internally generated items as those cannot be
3891 -- named and participate in refinement.
3893 if not Comes_From_Source (Item_Id) then
3896 elsif Ekind (Item_Id) = E_Abstract_State then
3897 Append_New_Elmt (Item_Id, States);
3899 elsif Ekind_In (Item_Id, E_Constant, E_Variable)
3900 and then Is_Visible_Object (Item_Id)
3902 Append_New_Elmt (Item_Id, States);
3904 -- Recursively gather the visible states of a nested package
3906 elsif Ekind (Item_Id) = E_Package then
3907 Collect_Visible_States (Item_Id, States);
3910 Next_Entity (Item_Id);
3912 end Collect_Visible_States;
3914 -----------------------
3915 -- Is_Visible_Object --
3916 -----------------------
3918 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean is
3920 -- Objects that map generic formals to their actuals are not visible
3921 -- from outside the generic instantiation.
3923 if Present (Corresponding_Generic_Association
3924 (Declaration_Node (Obj_Id)))
3928 -- Constituents of a single protected/task type act as components of
3929 -- the type and are not visible from outside the type.
3931 elsif Ekind (Obj_Id) = E_Variable
3932 and then Present (Encapsulating_State (Obj_Id))
3933 and then Is_Single_Concurrent_Object (Encapsulating_State (Obj_Id))
3940 end Is_Visible_Object;
3944 Body_Decl : constant Node_Id := Unit_Declaration_Node (Body_Id);
3946 Item_Id : Entity_Id;
3947 States : Elist_Id := No_Elist;
3949 -- Start of processing for Collect_Body_States
3952 -- Inspect the declarations of the body looking for source objects,
3953 -- packages and package instantiations. Note that even though this
3954 -- processing is very similar to Collect_Visible_States, a package
3955 -- body does not have a First/Next_Entity list.
3957 Decl := First (Declarations (Body_Decl));
3958 while Present (Decl) loop
3960 -- Capture source objects as internally generated temporaries cannot
3961 -- be named and participate in refinement.
3963 if Nkind (Decl) = N_Object_Declaration then
3964 Item_Id := Defining_Entity (Decl);
3966 if Comes_From_Source (Item_Id)
3967 and then Is_Visible_Object (Item_Id)
3969 Append_New_Elmt (Item_Id, States);
3972 -- Capture the visible abstract states and objects of a source
3973 -- package [instantiation].
3975 elsif Nkind (Decl) = N_Package_Declaration then
3976 Item_Id := Defining_Entity (Decl);
3978 if Comes_From_Source (Item_Id) then
3979 Collect_Visible_States (Item_Id, States);
3987 end Collect_Body_States;
3989 ------------------------
3990 -- Collect_Interfaces --
3991 ------------------------
3993 procedure Collect_Interfaces
3995 Ifaces_List : out Elist_Id;
3996 Exclude_Parents : Boolean := False;
3997 Use_Full_View : Boolean := True)
3999 procedure Collect (Typ : Entity_Id);
4000 -- Subsidiary subprogram used to traverse the whole list
4001 -- of directly and indirectly implemented interfaces
4007 procedure Collect (Typ : Entity_Id) is
4008 Ancestor : Entity_Id;
4016 -- Handle private types and subtypes
4019 and then Is_Private_Type (Typ)
4020 and then Present (Full_View (Typ))
4022 Full_T := Full_View (Typ);
4024 if Ekind (Full_T) = E_Record_Subtype then
4025 Full_T := Etype (Typ);
4027 if Present (Full_View (Full_T)) then
4028 Full_T := Full_View (Full_T);
4033 -- Include the ancestor if we are generating the whole list of
4034 -- abstract interfaces.
4036 if Etype (Full_T) /= Typ
4038 -- Protect the frontend against wrong sources. For example:
4041 -- type A is tagged null record;
4042 -- type B is new A with private;
4043 -- type C is new A with private;
4045 -- type B is new C with null record;
4046 -- type C is new B with null record;
4049 and then Etype (Full_T) /= T
4051 Ancestor := Etype (Full_T);
4054 if Is_Interface (Ancestor) and then not Exclude_Parents then
4055 Append_Unique_Elmt (Ancestor, Ifaces_List);
4059 -- Traverse the graph of ancestor interfaces
4061 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
4062 Id := First (Abstract_Interface_List (Full_T));
4063 while Present (Id) loop
4064 Iface := Etype (Id);
4066 -- Protect against wrong uses. For example:
4067 -- type I is interface;
4068 -- type O is tagged null record;
4069 -- type Wrong is new I and O with null record; -- ERROR
4071 if Is_Interface (Iface) then
4073 and then Etype (T) /= T
4074 and then Interface_Present_In_Ancestor (Etype (T), Iface)
4079 Append_Unique_Elmt (Iface, Ifaces_List);
4088 -- Start of processing for Collect_Interfaces
4091 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
4092 Ifaces_List := New_Elmt_List;
4094 end Collect_Interfaces;
4096 ----------------------------------
4097 -- Collect_Interface_Components --
4098 ----------------------------------
4100 procedure Collect_Interface_Components
4101 (Tagged_Type : Entity_Id;
4102 Components_List : out Elist_Id)
4104 procedure Collect (Typ : Entity_Id);
4105 -- Subsidiary subprogram used to climb to the parents
4111 procedure Collect (Typ : Entity_Id) is
4112 Tag_Comp : Entity_Id;
4113 Parent_Typ : Entity_Id;
4116 -- Handle private types
4118 if Present (Full_View (Etype (Typ))) then
4119 Parent_Typ := Full_View (Etype (Typ));
4121 Parent_Typ := Etype (Typ);
4124 if Parent_Typ /= Typ
4126 -- Protect the frontend against wrong sources. For example:
4129 -- type A is tagged null record;
4130 -- type B is new A with private;
4131 -- type C is new A with private;
4133 -- type B is new C with null record;
4134 -- type C is new B with null record;
4137 and then Parent_Typ /= Tagged_Type
4139 Collect (Parent_Typ);
4142 -- Collect the components containing tags of secondary dispatch
4145 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
4146 while Present (Tag_Comp) loop
4147 pragma Assert (Present (Related_Type (Tag_Comp)));
4148 Append_Elmt (Tag_Comp, Components_List);
4150 Tag_Comp := Next_Tag_Component (Tag_Comp);
4154 -- Start of processing for Collect_Interface_Components
4157 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
4158 and then Is_Tagged_Type (Tagged_Type));
4160 Components_List := New_Elmt_List;
4161 Collect (Tagged_Type);
4162 end Collect_Interface_Components;
4164 -----------------------------
4165 -- Collect_Interfaces_Info --
4166 -----------------------------
4168 procedure Collect_Interfaces_Info
4170 Ifaces_List : out Elist_Id;
4171 Components_List : out Elist_Id;
4172 Tags_List : out Elist_Id)
4174 Comps_List : Elist_Id;
4175 Comp_Elmt : Elmt_Id;
4176 Comp_Iface : Entity_Id;
4177 Iface_Elmt : Elmt_Id;
4180 function Search_Tag (Iface : Entity_Id) return Entity_Id;
4181 -- Search for the secondary tag associated with the interface type
4182 -- Iface that is implemented by T.
4188 function Search_Tag (Iface : Entity_Id) return Entity_Id is
4191 if not Is_CPP_Class (T) then
4192 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
4194 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
4198 and then Is_Tag (Node (ADT))
4199 and then Related_Type (Node (ADT)) /= Iface
4201 -- Skip secondary dispatch table referencing thunks to user
4202 -- defined primitives covered by this interface.
4204 pragma Assert (Has_Suffix (Node (ADT), 'P'));
4207 -- Skip secondary dispatch tables of Ada types
4209 if not Is_CPP_Class (T) then
4211 -- Skip secondary dispatch table referencing thunks to
4212 -- predefined primitives.
4214 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
4217 -- Skip secondary dispatch table referencing user-defined
4218 -- primitives covered by this interface.
4220 pragma Assert (Has_Suffix (Node (ADT), 'D'));
4223 -- Skip secondary dispatch table referencing predefined
4226 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
4231 pragma Assert (Is_Tag (Node (ADT)));
4235 -- Start of processing for Collect_Interfaces_Info
4238 Collect_Interfaces (T, Ifaces_List);
4239 Collect_Interface_Components (T, Comps_List);
4241 -- Search for the record component and tag associated with each
4242 -- interface type of T.
4244 Components_List := New_Elmt_List;
4245 Tags_List := New_Elmt_List;
4247 Iface_Elmt := First_Elmt (Ifaces_List);
4248 while Present (Iface_Elmt) loop
4249 Iface := Node (Iface_Elmt);
4251 -- Associate the primary tag component and the primary dispatch table
4252 -- with all the interfaces that are parents of T
4254 if Is_Ancestor (Iface, T, Use_Full_View => True) then
4255 Append_Elmt (First_Tag_Component (T), Components_List);
4256 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
4258 -- Otherwise search for the tag component and secondary dispatch
4262 Comp_Elmt := First_Elmt (Comps_List);
4263 while Present (Comp_Elmt) loop
4264 Comp_Iface := Related_Type (Node (Comp_Elmt));
4266 if Comp_Iface = Iface
4267 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
4269 Append_Elmt (Node (Comp_Elmt), Components_List);
4270 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
4274 Next_Elmt (Comp_Elmt);
4276 pragma Assert (Present (Comp_Elmt));
4279 Next_Elmt (Iface_Elmt);
4281 end Collect_Interfaces_Info;
4283 ---------------------
4284 -- Collect_Parents --
4285 ---------------------
4287 procedure Collect_Parents
4289 List : out Elist_Id;
4290 Use_Full_View : Boolean := True)
4292 Current_Typ : Entity_Id := T;
4293 Parent_Typ : Entity_Id;
4296 List := New_Elmt_List;
4298 -- No action if the if the type has no parents
4300 if T = Etype (T) then
4305 Parent_Typ := Etype (Current_Typ);
4307 if Is_Private_Type (Parent_Typ)
4308 and then Present (Full_View (Parent_Typ))
4309 and then Use_Full_View
4311 Parent_Typ := Full_View (Base_Type (Parent_Typ));
4314 Append_Elmt (Parent_Typ, List);
4316 exit when Parent_Typ = Current_Typ;
4317 Current_Typ := Parent_Typ;
4319 end Collect_Parents;
4321 ----------------------------------
4322 -- Collect_Primitive_Operations --
4323 ----------------------------------
4325 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
4326 B_Type : constant Entity_Id := Base_Type (T);
4327 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
4328 B_Scope : Entity_Id := Scope (B_Type);
4332 Is_Type_In_Pkg : Boolean;
4333 Formal_Derived : Boolean := False;
4336 function Match (E : Entity_Id) return Boolean;
4337 -- True if E's base type is B_Type, or E is of an anonymous access type
4338 -- and the base type of its designated type is B_Type.
4344 function Match (E : Entity_Id) return Boolean is
4345 Etyp : Entity_Id := Etype (E);
4348 if Ekind (Etyp) = E_Anonymous_Access_Type then
4349 Etyp := Designated_Type (Etyp);
4352 -- In Ada 2012 a primitive operation may have a formal of an
4353 -- incomplete view of the parent type.
4355 return Base_Type (Etyp) = B_Type
4357 (Ada_Version >= Ada_2012
4358 and then Ekind (Etyp) = E_Incomplete_Type
4359 and then Full_View (Etyp) = B_Type);
4362 -- Start of processing for Collect_Primitive_Operations
4365 -- For tagged types, the primitive operations are collected as they
4366 -- are declared, and held in an explicit list which is simply returned.
4368 if Is_Tagged_Type (B_Type) then
4369 return Primitive_Operations (B_Type);
4371 -- An untagged generic type that is a derived type inherits the
4372 -- primitive operations of its parent type. Other formal types only
4373 -- have predefined operators, which are not explicitly represented.
4375 elsif Is_Generic_Type (B_Type) then
4376 if Nkind (B_Decl) = N_Formal_Type_Declaration
4377 and then Nkind (Formal_Type_Definition (B_Decl)) =
4378 N_Formal_Derived_Type_Definition
4380 Formal_Derived := True;
4382 return New_Elmt_List;
4386 Op_List := New_Elmt_List;
4388 if B_Scope = Standard_Standard then
4389 if B_Type = Standard_String then
4390 Append_Elmt (Standard_Op_Concat, Op_List);
4392 elsif B_Type = Standard_Wide_String then
4393 Append_Elmt (Standard_Op_Concatw, Op_List);
4399 -- Locate the primitive subprograms of the type
4402 -- The primitive operations appear after the base type, except
4403 -- if the derivation happens within the private part of B_Scope
4404 -- and the type is a private type, in which case both the type
4405 -- and some primitive operations may appear before the base
4406 -- type, and the list of candidates starts after the type.
4408 if In_Open_Scopes (B_Scope)
4409 and then Scope (T) = B_Scope
4410 and then In_Private_Part (B_Scope)
4412 Id := Next_Entity (T);
4414 -- In Ada 2012, If the type has an incomplete partial view, there
4415 -- may be primitive operations declared before the full view, so
4416 -- we need to start scanning from the incomplete view, which is
4417 -- earlier on the entity chain.
4419 elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration
4420 and then Present (Incomplete_View (Parent (B_Type)))
4422 Id := Defining_Entity (Incomplete_View (Parent (B_Type)));
4424 -- If T is a derived from a type with an incomplete view declared
4425 -- elsewhere, that incomplete view is irrelevant, we want the
4426 -- operations in the scope of T.
4428 if Scope (Id) /= Scope (B_Type) then
4429 Id := Next_Entity (B_Type);
4433 Id := Next_Entity (B_Type);
4436 -- Set flag if this is a type in a package spec
4439 Is_Package_Or_Generic_Package (B_Scope)
4441 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
4444 while Present (Id) loop
4446 -- Test whether the result type or any of the parameter types of
4447 -- each subprogram following the type match that type when the
4448 -- type is declared in a package spec, is a derived type, or the
4449 -- subprogram is marked as primitive. (The Is_Primitive test is
4450 -- needed to find primitives of nonderived types in declarative
4451 -- parts that happen to override the predefined "=" operator.)
4453 -- Note that generic formal subprograms are not considered to be
4454 -- primitive operations and thus are never inherited.
4456 if Is_Overloadable (Id)
4457 and then (Is_Type_In_Pkg
4458 or else Is_Derived_Type (B_Type)
4459 or else Is_Primitive (Id))
4460 and then Nkind (Parent (Parent (Id)))
4461 not in N_Formal_Subprogram_Declaration
4469 Formal := First_Formal (Id);
4470 while Present (Formal) loop
4471 if Match (Formal) then
4476 Next_Formal (Formal);
4480 -- For a formal derived type, the only primitives are the ones
4481 -- inherited from the parent type. Operations appearing in the
4482 -- package declaration are not primitive for it.
4485 and then (not Formal_Derived or else Present (Alias (Id)))
4487 -- In the special case of an equality operator aliased to
4488 -- an overriding dispatching equality belonging to the same
4489 -- type, we don't include it in the list of primitives.
4490 -- This avoids inheriting multiple equality operators when
4491 -- deriving from untagged private types whose full type is
4492 -- tagged, which can otherwise cause ambiguities. Note that
4493 -- this should only happen for this kind of untagged parent
4494 -- type, since normally dispatching operations are inherited
4495 -- using the type's Primitive_Operations list.
4497 if Chars (Id) = Name_Op_Eq
4498 and then Is_Dispatching_Operation (Id)
4499 and then Present (Alias (Id))
4500 and then Present (Overridden_Operation (Alias (Id)))
4501 and then Base_Type (Etype (First_Entity (Id))) =
4502 Base_Type (Etype (First_Entity (Alias (Id))))
4506 -- Include the subprogram in the list of primitives
4509 Append_Elmt (Id, Op_List);
4516 -- For a type declared in System, some of its operations may
4517 -- appear in the target-specific extension to System.
4520 and then B_Scope = RTU_Entity (System)
4521 and then Present_System_Aux
4523 B_Scope := System_Aux_Id;
4524 Id := First_Entity (System_Aux_Id);
4530 end Collect_Primitive_Operations;
4532 -----------------------------------
4533 -- Compile_Time_Constraint_Error --
4534 -----------------------------------
4536 function Compile_Time_Constraint_Error
4539 Ent : Entity_Id := Empty;
4540 Loc : Source_Ptr := No_Location;
4541 Warn : Boolean := False) return Node_Id
4543 Msgc : String (1 .. Msg'Length + 3);
4544 -- Copy of message, with room for possible ?? or << and ! at end
4550 -- Start of processing for Compile_Time_Constraint_Error
4553 -- If this is a warning, convert it into an error if we are in code
4554 -- subject to SPARK_Mode being set On, unless Warn is True to force a
4555 -- warning. The rationale is that a compile-time constraint error should
4556 -- lead to an error instead of a warning when SPARK_Mode is On, but in
4557 -- a few cases we prefer to issue a warning and generate both a suitable
4558 -- run-time error in GNAT and a suitable check message in GNATprove.
4559 -- Those cases are those that likely correspond to deactivated SPARK
4560 -- code, so that this kind of code can be compiled and analyzed instead
4561 -- of being rejected.
4563 Error_Msg_Warn := Warn or SPARK_Mode /= On;
4565 -- A static constraint error in an instance body is not a fatal error.
4566 -- we choose to inhibit the message altogether, because there is no
4567 -- obvious node (for now) on which to post it. On the other hand the
4568 -- offending node must be replaced with a constraint_error in any case.
4570 -- No messages are generated if we already posted an error on this node
4572 if not Error_Posted (N) then
4573 if Loc /= No_Location then
4579 -- Copy message to Msgc, converting any ? in the message into
4580 -- < instead, so that we have an error in GNATprove mode.
4584 for J in 1 .. Msgl loop
4585 if Msg (J) = '?' and then (J = 1 or else Msg (J - 1) /= ''') then
4588 Msgc (J) := Msg (J);
4592 -- Message is a warning, even in Ada 95 case
4594 if Msg (Msg'Last) = '?' or else Msg (Msg'Last) = '<' then
4597 -- In Ada 83, all messages are warnings. In the private part and
4598 -- the body of an instance, constraint_checks are only warnings.
4599 -- We also make this a warning if the Warn parameter is set.
4602 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
4610 elsif In_Instance_Not_Visible then
4617 -- Otherwise we have a real error message (Ada 95 static case)
4618 -- and we make this an unconditional message. Note that in the
4619 -- warning case we do not make the message unconditional, it seems
4620 -- quite reasonable to delete messages like this (about exceptions
4621 -- that will be raised) in dead code.
4629 -- One more test, skip the warning if the related expression is
4630 -- statically unevaluated, since we don't want to warn about what
4631 -- will happen when something is evaluated if it never will be
4634 if not Is_Statically_Unevaluated (N) then
4635 if Present (Ent) then
4636 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
4638 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
4643 -- Check whether the context is an Init_Proc
4645 if Inside_Init_Proc then
4647 Conc_Typ : constant Entity_Id :=
4648 Corresponding_Concurrent_Type
4649 (Entity (Parameter_Type (First
4650 (Parameter_Specifications
4651 (Parent (Current_Scope))))));
4654 -- Don't complain if the corresponding concurrent type
4655 -- doesn't come from source (i.e. a single task/protected
4658 if Present (Conc_Typ)
4659 and then not Comes_From_Source (Conc_Typ)
4662 ("\& [<<", N, Standard_Constraint_Error, Eloc);
4665 if GNATprove_Mode then
4667 ("\& would have been raised for objects of this "
4668 & "type", N, Standard_Constraint_Error, Eloc);
4671 ("\& will be raised for objects of this type??",
4672 N, Standard_Constraint_Error, Eloc);
4678 Error_Msg_NEL ("\& [<<", N, Standard_Constraint_Error, Eloc);
4682 Error_Msg ("\static expression fails Constraint_Check", Eloc);
4683 Set_Error_Posted (N);
4689 end Compile_Time_Constraint_Error;
4691 -----------------------
4692 -- Conditional_Delay --
4693 -----------------------
4695 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
4697 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
4698 Set_Has_Delayed_Freeze (New_Ent);
4700 end Conditional_Delay;
4702 ----------------------------
4703 -- Contains_Refined_State --
4704 ----------------------------
4706 function Contains_Refined_State (Prag : Node_Id) return Boolean is
4707 function Has_State_In_Dependency (List : Node_Id) return Boolean;
4708 -- Determine whether a dependency list mentions a state with a visible
4711 function Has_State_In_Global (List : Node_Id) return Boolean;
4712 -- Determine whether a global list mentions a state with a visible
4715 function Is_Refined_State (Item : Node_Id) return Boolean;
4716 -- Determine whether Item is a reference to an abstract state with a
4717 -- visible refinement.
4719 -----------------------------
4720 -- Has_State_In_Dependency --
4721 -----------------------------
4723 function Has_State_In_Dependency (List : Node_Id) return Boolean is
4728 -- A null dependency list does not mention any states
4730 if Nkind (List) = N_Null then
4733 -- Dependency clauses appear as component associations of an
4736 elsif Nkind (List) = N_Aggregate
4737 and then Present (Component_Associations (List))
4739 Clause := First (Component_Associations (List));
4740 while Present (Clause) loop
4742 -- Inspect the outputs of a dependency clause
4744 Output := First (Choices (Clause));
4745 while Present (Output) loop
4746 if Is_Refined_State (Output) then
4753 -- Inspect the outputs of a dependency clause
4755 if Is_Refined_State (Expression (Clause)) then
4762 -- If we get here, then none of the dependency clauses mention a
4763 -- state with visible refinement.
4767 -- An illegal pragma managed to sneak in
4770 raise Program_Error;
4772 end Has_State_In_Dependency;
4774 -------------------------
4775 -- Has_State_In_Global --
4776 -------------------------
4778 function Has_State_In_Global (List : Node_Id) return Boolean is
4782 -- A null global list does not mention any states
4784 if Nkind (List) = N_Null then
4787 -- Simple global list or moded global list declaration
4789 elsif Nkind (List) = N_Aggregate then
4791 -- The declaration of a simple global list appear as a collection
4794 if Present (Expressions (List)) then
4795 Item := First (Expressions (List));
4796 while Present (Item) loop
4797 if Is_Refined_State (Item) then
4804 -- The declaration of a moded global list appears as a collection
4805 -- of component associations where individual choices denote
4809 Item := First (Component_Associations (List));
4810 while Present (Item) loop
4811 if Has_State_In_Global (Expression (Item)) then
4819 -- If we get here, then the simple/moded global list did not
4820 -- mention any states with a visible refinement.
4824 -- Single global item declaration
4826 elsif Is_Entity_Name (List) then
4827 return Is_Refined_State (List);
4829 -- An illegal pragma managed to sneak in
4832 raise Program_Error;
4834 end Has_State_In_Global;
4836 ----------------------
4837 -- Is_Refined_State --
4838 ----------------------
4840 function Is_Refined_State (Item : Node_Id) return Boolean is
4842 Item_Id : Entity_Id;
4845 if Nkind (Item) = N_Null then
4848 -- States cannot be subject to attribute 'Result. This case arises
4849 -- in dependency relations.
4851 elsif Nkind (Item) = N_Attribute_Reference
4852 and then Attribute_Name (Item) = Name_Result
4856 -- Multiple items appear as an aggregate. This case arises in
4857 -- dependency relations.
4859 elsif Nkind (Item) = N_Aggregate
4860 and then Present (Expressions (Item))
4862 Elmt := First (Expressions (Item));
4863 while Present (Elmt) loop
4864 if Is_Refined_State (Elmt) then
4871 -- If we get here, then none of the inputs or outputs reference a
4872 -- state with visible refinement.
4879 Item_Id := Entity_Of (Item);
4883 and then Ekind (Item_Id) = E_Abstract_State
4884 and then Has_Visible_Refinement (Item_Id);
4886 end Is_Refined_State;
4890 Arg : constant Node_Id :=
4891 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
4892 Nam : constant Name_Id := Pragma_Name (Prag);
4894 -- Start of processing for Contains_Refined_State
4897 if Nam = Name_Depends then
4898 return Has_State_In_Dependency (Arg);
4900 else pragma Assert (Nam = Name_Global);
4901 return Has_State_In_Global (Arg);
4903 end Contains_Refined_State;
4905 -------------------------
4906 -- Copy_Component_List --
4907 -------------------------
4909 function Copy_Component_List
4911 Loc : Source_Ptr) return List_Id
4914 Comps : constant List_Id := New_List;
4917 Comp := First_Component (Underlying_Type (R_Typ));
4918 while Present (Comp) loop
4919 if Comes_From_Source (Comp) then
4921 Comp_Decl : constant Node_Id := Declaration_Node (Comp);
4924 Make_Component_Declaration (Loc,
4925 Defining_Identifier =>
4926 Make_Defining_Identifier (Loc, Chars (Comp)),
4927 Component_Definition =>
4929 (Component_Definition (Comp_Decl), New_Sloc => Loc)));
4933 Next_Component (Comp);
4937 end Copy_Component_List;
4939 -------------------------
4940 -- Copy_Parameter_List --
4941 -------------------------
4943 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
4944 Loc : constant Source_Ptr := Sloc (Subp_Id);
4949 if No (First_Formal (Subp_Id)) then
4953 Formal := First_Formal (Subp_Id);
4954 while Present (Formal) loop
4956 Make_Parameter_Specification (Loc,
4957 Defining_Identifier =>
4958 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
4959 In_Present => In_Present (Parent (Formal)),
4960 Out_Present => Out_Present (Parent (Formal)),
4962 New_Occurrence_Of (Etype (Formal), Loc),
4964 New_Copy_Tree (Expression (Parent (Formal)))));
4966 Next_Formal (Formal);
4971 end Copy_Parameter_List;
4973 ----------------------------
4974 -- Copy_SPARK_Mode_Aspect --
4975 ----------------------------
4977 procedure Copy_SPARK_Mode_Aspect (From : Node_Id; To : Node_Id) is
4978 pragma Assert (not Has_Aspects (To));
4982 if Has_Aspects (From) then
4983 Asp := Find_Aspect (Defining_Entity (From), Aspect_SPARK_Mode);
4985 if Present (Asp) then
4986 Set_Aspect_Specifications (To, New_List (New_Copy_Tree (Asp)));
4987 Set_Has_Aspects (To, True);
4990 end Copy_SPARK_Mode_Aspect;
4992 --------------------------
4993 -- Copy_Subprogram_Spec --
4994 --------------------------
4996 function Copy_Subprogram_Spec (Spec : Node_Id) return Node_Id is
4998 Formal_Spec : Node_Id;
5002 -- The structure of the original tree must be replicated without any
5003 -- alterations. Use New_Copy_Tree for this purpose.
5005 Result := New_Copy_Tree (Spec);
5007 -- Create a new entity for the defining unit name
5009 Def_Id := Defining_Unit_Name (Result);
5010 Set_Defining_Unit_Name (Result,
5011 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
5013 -- Create new entities for the formal parameters
5015 if Present (Parameter_Specifications (Result)) then
5016 Formal_Spec := First (Parameter_Specifications (Result));
5017 while Present (Formal_Spec) loop
5018 Def_Id := Defining_Identifier (Formal_Spec);
5019 Set_Defining_Identifier (Formal_Spec,
5020 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
5027 end Copy_Subprogram_Spec;
5029 --------------------------------
5030 -- Corresponding_Generic_Type --
5031 --------------------------------
5033 function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id is
5039 if not Is_Generic_Actual_Type (T) then
5042 -- If the actual is the actual of an enclosing instance, resolution
5043 -- was correct in the generic.
5045 elsif Nkind (Parent (T)) = N_Subtype_Declaration
5046 and then Is_Entity_Name (Subtype_Indication (Parent (T)))
5048 Is_Generic_Actual_Type (Entity (Subtype_Indication (Parent (T))))
5055 if Is_Wrapper_Package (Inst) then
5056 Inst := Related_Instance (Inst);
5061 (Specification (Unit_Declaration_Node (Inst)));
5063 -- Generic actual has the same name as the corresponding formal
5065 Typ := First_Entity (Gen);
5066 while Present (Typ) loop
5067 if Chars (Typ) = Chars (T) then
5076 end Corresponding_Generic_Type;
5078 --------------------
5079 -- Current_Entity --
5080 --------------------
5082 -- The currently visible definition for a given identifier is the
5083 -- one most chained at the start of the visibility chain, i.e. the
5084 -- one that is referenced by the Node_Id value of the name of the
5085 -- given identifier.
5087 function Current_Entity (N : Node_Id) return Entity_Id is
5089 return Get_Name_Entity_Id (Chars (N));
5092 -----------------------------
5093 -- Current_Entity_In_Scope --
5094 -----------------------------
5096 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
5098 CS : constant Entity_Id := Current_Scope;
5100 Transient_Case : constant Boolean := Scope_Is_Transient;
5103 E := Get_Name_Entity_Id (Chars (N));
5105 and then Scope (E) /= CS
5106 and then (not Transient_Case or else Scope (E) /= Scope (CS))
5112 end Current_Entity_In_Scope;
5118 function Current_Scope return Entity_Id is
5120 if Scope_Stack.Last = -1 then
5121 return Standard_Standard;
5124 C : constant Entity_Id :=
5125 Scope_Stack.Table (Scope_Stack.Last).Entity;
5130 return Standard_Standard;
5136 ----------------------------
5137 -- Current_Scope_No_Loops --
5138 ----------------------------
5140 function Current_Scope_No_Loops return Entity_Id is
5144 -- Examine the scope stack starting from the current scope and skip any
5145 -- internally generated loops.
5148 while Present (S) and then S /= Standard_Standard loop
5149 if Ekind (S) = E_Loop and then not Comes_From_Source (S) then
5157 end Current_Scope_No_Loops;
5159 ------------------------
5160 -- Current_Subprogram --
5161 ------------------------
5163 function Current_Subprogram return Entity_Id is
5164 Scop : constant Entity_Id := Current_Scope;
5166 if Is_Subprogram_Or_Generic_Subprogram (Scop) then
5169 return Enclosing_Subprogram (Scop);
5171 end Current_Subprogram;
5173 ----------------------------------
5174 -- Deepest_Type_Access_Level --
5175 ----------------------------------
5177 function Deepest_Type_Access_Level (Typ : Entity_Id) return Uint is
5179 if Ekind (Typ) = E_Anonymous_Access_Type
5180 and then not Is_Local_Anonymous_Access (Typ)
5181 and then Nkind (Associated_Node_For_Itype (Typ)) = N_Object_Declaration
5183 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
5187 Scope_Depth (Enclosing_Dynamic_Scope
5188 (Defining_Identifier
5189 (Associated_Node_For_Itype (Typ))));
5191 -- For generic formal type, return Int'Last (infinite).
5192 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
5194 elsif Is_Generic_Type (Root_Type (Typ)) then
5195 return UI_From_Int (Int'Last);
5198 return Type_Access_Level (Typ);
5200 end Deepest_Type_Access_Level;
5202 ---------------------
5203 -- Defining_Entity --
5204 ---------------------
5206 function Defining_Entity
5208 Empty_On_Errors : Boolean := False) return Entity_Id
5210 Err : Entity_Id := Empty;
5214 when N_Abstract_Subprogram_Declaration
5215 | N_Expression_Function
5216 | N_Formal_Subprogram_Declaration
5217 | N_Generic_Package_Declaration
5218 | N_Generic_Subprogram_Declaration
5219 | N_Package_Declaration
5221 | N_Subprogram_Body_Stub
5222 | N_Subprogram_Declaration
5223 | N_Subprogram_Renaming_Declaration
5225 return Defining_Entity (Specification (N));
5227 when N_Component_Declaration
5228 | N_Defining_Program_Unit_Name
5229 | N_Discriminant_Specification
5231 | N_Entry_Declaration
5232 | N_Entry_Index_Specification
5233 | N_Exception_Declaration
5234 | N_Exception_Renaming_Declaration
5235 | N_Formal_Object_Declaration
5236 | N_Formal_Package_Declaration
5237 | N_Formal_Type_Declaration
5238 | N_Full_Type_Declaration
5239 | N_Implicit_Label_Declaration
5240 | N_Incomplete_Type_Declaration
5241 | N_Iterator_Specification
5242 | N_Loop_Parameter_Specification
5243 | N_Number_Declaration
5244 | N_Object_Declaration
5245 | N_Object_Renaming_Declaration
5246 | N_Package_Body_Stub
5247 | N_Parameter_Specification
5248 | N_Private_Extension_Declaration
5249 | N_Private_Type_Declaration
5251 | N_Protected_Body_Stub
5252 | N_Protected_Type_Declaration
5253 | N_Single_Protected_Declaration
5254 | N_Single_Task_Declaration
5255 | N_Subtype_Declaration
5258 | N_Task_Type_Declaration
5260 return Defining_Identifier (N);
5263 return Defining_Entity (Proper_Body (N));
5265 when N_Function_Instantiation
5266 | N_Function_Specification
5267 | N_Generic_Function_Renaming_Declaration
5268 | N_Generic_Package_Renaming_Declaration
5269 | N_Generic_Procedure_Renaming_Declaration
5271 | N_Package_Instantiation
5272 | N_Package_Renaming_Declaration
5273 | N_Package_Specification
5274 | N_Procedure_Instantiation
5275 | N_Procedure_Specification
5278 Nam : constant Node_Id := Defining_Unit_Name (N);
5281 if Nkind (Nam) in N_Entity then
5284 -- For Error, make up a name and attach to declaration so we
5285 -- can continue semantic analysis.
5287 elsif Nam = Error then
5288 if Empty_On_Errors then
5291 Err := Make_Temporary (Sloc (N), 'T');
5292 Set_Defining_Unit_Name (N, Err);
5297 -- If not an entity, get defining identifier
5300 return Defining_Identifier (Nam);
5304 when N_Block_Statement
5307 return Entity (Identifier (N));
5310 if Empty_On_Errors then
5313 raise Program_Error;
5316 end Defining_Entity;
5318 --------------------------
5319 -- Denotes_Discriminant --
5320 --------------------------
5322 function Denotes_Discriminant
5324 Check_Concurrent : Boolean := False) return Boolean
5329 if not Is_Entity_Name (N) or else No (Entity (N)) then
5335 -- If we are checking for a protected type, the discriminant may have
5336 -- been rewritten as the corresponding discriminal of the original type
5337 -- or of the corresponding concurrent record, depending on whether we
5338 -- are in the spec or body of the protected type.
5340 return Ekind (E) = E_Discriminant
5343 and then Ekind (E) = E_In_Parameter
5344 and then Present (Discriminal_Link (E))
5346 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
5348 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
5349 end Denotes_Discriminant;
5351 -------------------------
5352 -- Denotes_Same_Object --
5353 -------------------------
5355 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
5356 Obj1 : Node_Id := A1;
5357 Obj2 : Node_Id := A2;
5359 function Has_Prefix (N : Node_Id) return Boolean;
5360 -- Return True if N has attribute Prefix
5362 function Is_Renaming (N : Node_Id) return Boolean;
5363 -- Return true if N names a renaming entity
5365 function Is_Valid_Renaming (N : Node_Id) return Boolean;
5366 -- For renamings, return False if the prefix of any dereference within
5367 -- the renamed object_name is a variable, or any expression within the
5368 -- renamed object_name contains references to variables or calls on
5369 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
5375 function Has_Prefix (N : Node_Id) return Boolean is
5379 N_Attribute_Reference,
5381 N_Explicit_Dereference,
5382 N_Indexed_Component,
5384 N_Selected_Component,
5392 function Is_Renaming (N : Node_Id) return Boolean is
5394 return Is_Entity_Name (N)
5395 and then Present (Renamed_Entity (Entity (N)));
5398 -----------------------
5399 -- Is_Valid_Renaming --
5400 -----------------------
5402 function Is_Valid_Renaming (N : Node_Id) return Boolean is
5404 function Check_Renaming (N : Node_Id) return Boolean;
5405 -- Recursive function used to traverse all the prefixes of N
5407 function Check_Renaming (N : Node_Id) return Boolean is
5410 and then not Check_Renaming (Renamed_Entity (Entity (N)))
5415 if Nkind (N) = N_Indexed_Component then
5420 Indx := First (Expressions (N));
5421 while Present (Indx) loop
5422 if not Is_OK_Static_Expression (Indx) then
5431 if Has_Prefix (N) then
5433 P : constant Node_Id := Prefix (N);
5436 if Nkind (N) = N_Explicit_Dereference
5437 and then Is_Variable (P)
5441 elsif Is_Entity_Name (P)
5442 and then Ekind (Entity (P)) = E_Function
5446 elsif Nkind (P) = N_Function_Call then
5450 -- Recursion to continue traversing the prefix of the
5451 -- renaming expression
5453 return Check_Renaming (P);
5460 -- Start of processing for Is_Valid_Renaming
5463 return Check_Renaming (N);
5464 end Is_Valid_Renaming;
5466 -- Start of processing for Denotes_Same_Object
5469 -- Both names statically denote the same stand-alone object or parameter
5470 -- (RM 6.4.1(6.5/3))
5472 if Is_Entity_Name (Obj1)
5473 and then Is_Entity_Name (Obj2)
5474 and then Entity (Obj1) = Entity (Obj2)
5479 -- For renamings, the prefix of any dereference within the renamed
5480 -- object_name is not a variable, and any expression within the
5481 -- renamed object_name contains no references to variables nor
5482 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
5484 if Is_Renaming (Obj1) then
5485 if Is_Valid_Renaming (Obj1) then
5486 Obj1 := Renamed_Entity (Entity (Obj1));
5492 if Is_Renaming (Obj2) then
5493 if Is_Valid_Renaming (Obj2) then
5494 Obj2 := Renamed_Entity (Entity (Obj2));
5500 -- No match if not same node kind (such cases are handled by
5501 -- Denotes_Same_Prefix)
5503 if Nkind (Obj1) /= Nkind (Obj2) then
5506 -- After handling valid renamings, one of the two names statically
5507 -- denoted a renaming declaration whose renamed object_name is known
5508 -- to denote the same object as the other (RM 6.4.1(6.10/3))
5510 elsif Is_Entity_Name (Obj1) then
5511 if Is_Entity_Name (Obj2) then
5512 return Entity (Obj1) = Entity (Obj2);
5517 -- Both names are selected_components, their prefixes are known to
5518 -- denote the same object, and their selector_names denote the same
5519 -- component (RM 6.4.1(6.6/3)).
5521 elsif Nkind (Obj1) = N_Selected_Component then
5522 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
5524 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
5526 -- Both names are dereferences and the dereferenced names are known to
5527 -- denote the same object (RM 6.4.1(6.7/3))
5529 elsif Nkind (Obj1) = N_Explicit_Dereference then
5530 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
5532 -- Both names are indexed_components, their prefixes are known to denote
5533 -- the same object, and each of the pairs of corresponding index values
5534 -- are either both static expressions with the same static value or both
5535 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
5537 elsif Nkind (Obj1) = N_Indexed_Component then
5538 if not Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
5546 Indx1 := First (Expressions (Obj1));
5547 Indx2 := First (Expressions (Obj2));
5548 while Present (Indx1) loop
5550 -- Indexes must denote the same static value or same object
5552 if Is_OK_Static_Expression (Indx1) then
5553 if not Is_OK_Static_Expression (Indx2) then
5556 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
5560 elsif not Denotes_Same_Object (Indx1, Indx2) then
5572 -- Both names are slices, their prefixes are known to denote the same
5573 -- object, and the two slices have statically matching index constraints
5574 -- (RM 6.4.1(6.9/3))
5576 elsif Nkind (Obj1) = N_Slice
5577 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
5580 Lo1, Lo2, Hi1, Hi2 : Node_Id;
5583 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
5584 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
5586 -- Check whether bounds are statically identical. There is no
5587 -- attempt to detect partial overlap of slices.
5589 return Denotes_Same_Object (Lo1, Lo2)
5591 Denotes_Same_Object (Hi1, Hi2);
5594 -- In the recursion, literals appear as indexes
5596 elsif Nkind (Obj1) = N_Integer_Literal
5598 Nkind (Obj2) = N_Integer_Literal
5600 return Intval (Obj1) = Intval (Obj2);
5605 end Denotes_Same_Object;
5607 -------------------------
5608 -- Denotes_Same_Prefix --
5609 -------------------------
5611 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
5613 if Is_Entity_Name (A1) then
5614 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
5615 and then not Is_Access_Type (Etype (A1))
5617 return Denotes_Same_Object (A1, Prefix (A2))
5618 or else Denotes_Same_Prefix (A1, Prefix (A2));
5623 elsif Is_Entity_Name (A2) then
5624 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
5626 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
5628 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
5631 Root1, Root2 : Node_Id;
5632 Depth1, Depth2 : Nat := 0;
5635 Root1 := Prefix (A1);
5636 while not Is_Entity_Name (Root1) loop
5638 (Root1, N_Selected_Component, N_Indexed_Component)
5642 Root1 := Prefix (Root1);
5645 Depth1 := Depth1 + 1;
5648 Root2 := Prefix (A2);
5649 while not Is_Entity_Name (Root2) loop
5650 if not Nkind_In (Root2, N_Selected_Component,
5651 N_Indexed_Component)
5655 Root2 := Prefix (Root2);
5658 Depth2 := Depth2 + 1;
5661 -- If both have the same depth and they do not denote the same
5662 -- object, they are disjoint and no warning is needed.
5664 if Depth1 = Depth2 then
5667 elsif Depth1 > Depth2 then
5668 Root1 := Prefix (A1);
5669 for J in 1 .. Depth1 - Depth2 - 1 loop
5670 Root1 := Prefix (Root1);
5673 return Denotes_Same_Object (Root1, A2);
5676 Root2 := Prefix (A2);
5677 for J in 1 .. Depth2 - Depth1 - 1 loop
5678 Root2 := Prefix (Root2);
5681 return Denotes_Same_Object (A1, Root2);
5688 end Denotes_Same_Prefix;
5690 ----------------------
5691 -- Denotes_Variable --
5692 ----------------------
5694 function Denotes_Variable (N : Node_Id) return Boolean is
5696 return Is_Variable (N) and then Paren_Count (N) = 0;
5697 end Denotes_Variable;
5699 -----------------------------
5700 -- Depends_On_Discriminant --
5701 -----------------------------
5703 function Depends_On_Discriminant (N : Node_Id) return Boolean is
5708 Get_Index_Bounds (N, L, H);
5709 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
5710 end Depends_On_Discriminant;
5712 -------------------------
5713 -- Designate_Same_Unit --
5714 -------------------------
5716 function Designate_Same_Unit
5718 Name2 : Node_Id) return Boolean
5720 K1 : constant Node_Kind := Nkind (Name1);
5721 K2 : constant Node_Kind := Nkind (Name2);
5723 function Prefix_Node (N : Node_Id) return Node_Id;
5724 -- Returns the parent unit name node of a defining program unit name
5725 -- or the prefix if N is a selected component or an expanded name.
5727 function Select_Node (N : Node_Id) return Node_Id;
5728 -- Returns the defining identifier node of a defining program unit
5729 -- name or the selector node if N is a selected component or an
5736 function Prefix_Node (N : Node_Id) return Node_Id is
5738 if Nkind (N) = N_Defining_Program_Unit_Name then
5749 function Select_Node (N : Node_Id) return Node_Id is
5751 if Nkind (N) = N_Defining_Program_Unit_Name then
5752 return Defining_Identifier (N);
5754 return Selector_Name (N);
5758 -- Start of processing for Designate_Same_Unit
5761 if Nkind_In (K1, N_Identifier, N_Defining_Identifier)
5763 Nkind_In (K2, N_Identifier, N_Defining_Identifier)
5765 return Chars (Name1) = Chars (Name2);
5767 elsif Nkind_In (K1, N_Expanded_Name,
5768 N_Selected_Component,
5769 N_Defining_Program_Unit_Name)
5771 Nkind_In (K2, N_Expanded_Name,
5772 N_Selected_Component,
5773 N_Defining_Program_Unit_Name)
5776 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
5778 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
5783 end Designate_Same_Unit;
5785 ------------------------------------------
5786 -- function Dynamic_Accessibility_Level --
5787 ------------------------------------------
5789 function Dynamic_Accessibility_Level (Expr : Node_Id) return Node_Id is
5791 Loc : constant Source_Ptr := Sloc (Expr);
5793 function Make_Level_Literal (Level : Uint) return Node_Id;
5794 -- Construct an integer literal representing an accessibility level
5795 -- with its type set to Natural.
5797 ------------------------
5798 -- Make_Level_Literal --
5799 ------------------------
5801 function Make_Level_Literal (Level : Uint) return Node_Id is
5802 Result : constant Node_Id := Make_Integer_Literal (Loc, Level);
5804 Set_Etype (Result, Standard_Natural);
5806 end Make_Level_Literal;
5808 -- Start of processing for Dynamic_Accessibility_Level
5811 if Is_Entity_Name (Expr) then
5814 if Present (Renamed_Object (E)) then
5815 return Dynamic_Accessibility_Level (Renamed_Object (E));
5818 if Is_Formal (E) or else Ekind_In (E, E_Variable, E_Constant) then
5819 if Present (Extra_Accessibility (E)) then
5820 return New_Occurrence_Of (Extra_Accessibility (E), Loc);
5825 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
5827 case Nkind (Expr) is
5829 -- For access discriminant, the level of the enclosing object
5831 when N_Selected_Component =>
5832 if Ekind (Entity (Selector_Name (Expr))) = E_Discriminant
5833 and then Ekind (Etype (Entity (Selector_Name (Expr)))) =
5834 E_Anonymous_Access_Type
5836 return Make_Level_Literal (Object_Access_Level (Expr));
5839 when N_Attribute_Reference =>
5840 case Get_Attribute_Id (Attribute_Name (Expr)) is
5842 -- For X'Access, the level of the prefix X
5844 when Attribute_Access =>
5845 return Make_Level_Literal
5846 (Object_Access_Level (Prefix (Expr)));
5848 -- Treat the unchecked attributes as library-level
5850 when Attribute_Unchecked_Access
5851 | Attribute_Unrestricted_Access
5853 return Make_Level_Literal (Scope_Depth (Standard_Standard));
5855 -- No other access-valued attributes
5858 raise Program_Error;
5863 -- Unimplemented: depends on context. As an actual parameter where
5864 -- formal type is anonymous, use
5865 -- Scope_Depth (Current_Scope) + 1.
5866 -- For other cases, see 3.10.2(14/3) and following. ???
5870 when N_Type_Conversion =>
5871 if not Is_Local_Anonymous_Access (Etype (Expr)) then
5873 -- Handle type conversions introduced for a rename of an
5874 -- Ada 2012 stand-alone object of an anonymous access type.
5876 return Dynamic_Accessibility_Level (Expression (Expr));
5883 return Make_Level_Literal (Type_Access_Level (Etype (Expr)));
5884 end Dynamic_Accessibility_Level;
5886 -----------------------------------
5887 -- Effective_Extra_Accessibility --
5888 -----------------------------------
5890 function Effective_Extra_Accessibility (Id : Entity_Id) return Entity_Id is
5892 if Present (Renamed_Object (Id))
5893 and then Is_Entity_Name (Renamed_Object (Id))
5895 return Effective_Extra_Accessibility (Entity (Renamed_Object (Id)));
5897 return Extra_Accessibility (Id);
5899 end Effective_Extra_Accessibility;
5901 -----------------------------
5902 -- Effective_Reads_Enabled --
5903 -----------------------------
5905 function Effective_Reads_Enabled (Id : Entity_Id) return Boolean is
5907 return Has_Enabled_Property (Id, Name_Effective_Reads);
5908 end Effective_Reads_Enabled;
5910 ------------------------------
5911 -- Effective_Writes_Enabled --
5912 ------------------------------
5914 function Effective_Writes_Enabled (Id : Entity_Id) return Boolean is
5916 return Has_Enabled_Property (Id, Name_Effective_Writes);
5917 end Effective_Writes_Enabled;
5919 ------------------------------
5920 -- Enclosing_Comp_Unit_Node --
5921 ------------------------------
5923 function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id is
5924 Current_Node : Node_Id;
5928 while Present (Current_Node)
5929 and then Nkind (Current_Node) /= N_Compilation_Unit
5931 Current_Node := Parent (Current_Node);
5934 if Nkind (Current_Node) /= N_Compilation_Unit then
5937 return Current_Node;
5939 end Enclosing_Comp_Unit_Node;
5941 --------------------------
5942 -- Enclosing_CPP_Parent --
5943 --------------------------
5945 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
5946 Parent_Typ : Entity_Id := Typ;
5949 while not Is_CPP_Class (Parent_Typ)
5950 and then Etype (Parent_Typ) /= Parent_Typ
5952 Parent_Typ := Etype (Parent_Typ);
5954 if Is_Private_Type (Parent_Typ) then
5955 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5959 pragma Assert (Is_CPP_Class (Parent_Typ));
5961 end Enclosing_CPP_Parent;
5963 ---------------------------
5964 -- Enclosing_Declaration --
5965 ---------------------------
5967 function Enclosing_Declaration (N : Node_Id) return Node_Id is
5968 Decl : Node_Id := N;
5971 while Present (Decl)
5972 and then not (Nkind (Decl) in N_Declaration
5974 Nkind (Decl) in N_Later_Decl_Item)
5976 Decl := Parent (Decl);
5980 end Enclosing_Declaration;
5982 ----------------------------
5983 -- Enclosing_Generic_Body --
5984 ----------------------------
5986 function Enclosing_Generic_Body
5987 (N : Node_Id) return Node_Id
5995 while Present (P) loop
5996 if Nkind (P) = N_Package_Body
5997 or else Nkind (P) = N_Subprogram_Body
5999 Spec := Corresponding_Spec (P);
6001 if Present (Spec) then
6002 Decl := Unit_Declaration_Node (Spec);
6004 if Nkind (Decl) = N_Generic_Package_Declaration
6005 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
6016 end Enclosing_Generic_Body;
6018 ----------------------------
6019 -- Enclosing_Generic_Unit --
6020 ----------------------------
6022 function Enclosing_Generic_Unit
6023 (N : Node_Id) return Node_Id
6031 while Present (P) loop
6032 if Nkind (P) = N_Generic_Package_Declaration
6033 or else Nkind (P) = N_Generic_Subprogram_Declaration
6037 elsif Nkind (P) = N_Package_Body
6038 or else Nkind (P) = N_Subprogram_Body
6040 Spec := Corresponding_Spec (P);
6042 if Present (Spec) then
6043 Decl := Unit_Declaration_Node (Spec);
6045 if Nkind (Decl) = N_Generic_Package_Declaration
6046 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
6057 end Enclosing_Generic_Unit;
6059 -------------------------------
6060 -- Enclosing_Lib_Unit_Entity --
6061 -------------------------------
6063 function Enclosing_Lib_Unit_Entity
6064 (E : Entity_Id := Current_Scope) return Entity_Id
6066 Unit_Entity : Entity_Id;
6069 -- Look for enclosing library unit entity by following scope links.
6070 -- Equivalent to, but faster than indexing through the scope stack.
6073 while (Present (Scope (Unit_Entity))
6074 and then Scope (Unit_Entity) /= Standard_Standard)
6075 and not Is_Child_Unit (Unit_Entity)
6077 Unit_Entity := Scope (Unit_Entity);
6081 end Enclosing_Lib_Unit_Entity;
6083 -----------------------------
6084 -- Enclosing_Lib_Unit_Node --
6085 -----------------------------
6087 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
6088 Encl_Unit : Node_Id;
6091 Encl_Unit := Enclosing_Comp_Unit_Node (N);
6092 while Present (Encl_Unit)
6093 and then Nkind (Unit (Encl_Unit)) = N_Subunit
6095 Encl_Unit := Library_Unit (Encl_Unit);
6098 pragma Assert (Nkind (Encl_Unit) = N_Compilation_Unit);
6100 end Enclosing_Lib_Unit_Node;
6102 -----------------------
6103 -- Enclosing_Package --
6104 -----------------------
6106 function Enclosing_Package (E : Entity_Id) return Entity_Id is
6107 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
6110 if Dynamic_Scope = Standard_Standard then
6111 return Standard_Standard;
6113 elsif Dynamic_Scope = Empty then
6116 elsif Ekind_In (Dynamic_Scope, E_Package, E_Package_Body,
6119 return Dynamic_Scope;
6122 return Enclosing_Package (Dynamic_Scope);
6124 end Enclosing_Package;
6126 -------------------------------------
6127 -- Enclosing_Package_Or_Subprogram --
6128 -------------------------------------
6130 function Enclosing_Package_Or_Subprogram (E : Entity_Id) return Entity_Id is
6135 while Present (S) loop
6136 if Is_Package_Or_Generic_Package (S)
6137 or else Ekind (S) = E_Package_Body
6141 elsif Is_Subprogram_Or_Generic_Subprogram (S)
6142 or else Ekind (S) = E_Subprogram_Body
6152 end Enclosing_Package_Or_Subprogram;
6154 --------------------------
6155 -- Enclosing_Subprogram --
6156 --------------------------
6158 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
6159 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
6162 if Dynamic_Scope = Standard_Standard then
6165 elsif Dynamic_Scope = Empty then
6168 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
6169 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
6171 elsif Ekind (Dynamic_Scope) = E_Block
6172 or else Ekind (Dynamic_Scope) = E_Return_Statement
6174 return Enclosing_Subprogram (Dynamic_Scope);
6176 elsif Ekind (Dynamic_Scope) = E_Task_Type then
6177 return Get_Task_Body_Procedure (Dynamic_Scope);
6179 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
6180 and then Present (Full_View (Dynamic_Scope))
6181 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
6183 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
6185 -- No body is generated if the protected operation is eliminated
6187 elsif Convention (Dynamic_Scope) = Convention_Protected
6188 and then not Is_Eliminated (Dynamic_Scope)
6189 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
6191 return Protected_Body_Subprogram (Dynamic_Scope);
6194 return Dynamic_Scope;
6196 end Enclosing_Subprogram;
6198 ------------------------
6199 -- Ensure_Freeze_Node --
6200 ------------------------
6202 procedure Ensure_Freeze_Node (E : Entity_Id) is
6205 if No (Freeze_Node (E)) then
6206 FN := Make_Freeze_Entity (Sloc (E));
6207 Set_Has_Delayed_Freeze (E);
6208 Set_Freeze_Node (E, FN);
6209 Set_Access_Types_To_Process (FN, No_Elist);
6210 Set_TSS_Elist (FN, No_Elist);
6213 end Ensure_Freeze_Node;
6219 procedure Enter_Name (Def_Id : Entity_Id) is
6220 C : constant Entity_Id := Current_Entity (Def_Id);
6221 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
6222 S : constant Entity_Id := Current_Scope;
6225 Generate_Definition (Def_Id);
6227 -- Add new name to current scope declarations. Check for duplicate
6228 -- declaration, which may or may not be a genuine error.
6232 -- Case of previous entity entered because of a missing declaration
6233 -- or else a bad subtype indication. Best is to use the new entity,
6234 -- and make the previous one invisible.
6236 if Etype (E) = Any_Type then
6237 Set_Is_Immediately_Visible (E, False);
6239 -- Case of renaming declaration constructed for package instances.
6240 -- if there is an explicit declaration with the same identifier,
6241 -- the renaming is not immediately visible any longer, but remains
6242 -- visible through selected component notation.
6244 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
6245 and then not Comes_From_Source (E)
6247 Set_Is_Immediately_Visible (E, False);
6249 -- The new entity may be the package renaming, which has the same
6250 -- same name as a generic formal which has been seen already.
6252 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
6253 and then not Comes_From_Source (Def_Id)
6255 Set_Is_Immediately_Visible (E, False);
6257 -- For a fat pointer corresponding to a remote access to subprogram,
6258 -- we use the same identifier as the RAS type, so that the proper
6259 -- name appears in the stub. This type is only retrieved through
6260 -- the RAS type and never by visibility, and is not added to the
6261 -- visibility list (see below).
6263 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
6264 and then Ekind (Def_Id) = E_Record_Type
6265 and then Present (Corresponding_Remote_Type (Def_Id))
6269 -- Case of an implicit operation or derived literal. The new entity
6270 -- hides the implicit one, which is removed from all visibility,
6271 -- i.e. the entity list of its scope, and homonym chain of its name.
6273 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
6274 or else Is_Internal (E)
6277 Decl : constant Node_Id := Parent (E);
6279 Prev_Vis : Entity_Id;
6282 -- If E is an implicit declaration, it cannot be the first
6283 -- entity in the scope.
6285 Prev := First_Entity (Current_Scope);
6286 while Present (Prev) and then Next_Entity (Prev) /= E loop
6292 -- If E is not on the entity chain of the current scope,
6293 -- it is an implicit declaration in the generic formal
6294 -- part of a generic subprogram. When analyzing the body,
6295 -- the generic formals are visible but not on the entity
6296 -- chain of the subprogram. The new entity will become
6297 -- the visible one in the body.
6300 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
6304 Set_Next_Entity (Prev, Next_Entity (E));
6306 if No (Next_Entity (Prev)) then
6307 Set_Last_Entity (Current_Scope, Prev);
6310 if E = Current_Entity (E) then
6314 Prev_Vis := Current_Entity (E);
6315 while Homonym (Prev_Vis) /= E loop
6316 Prev_Vis := Homonym (Prev_Vis);
6320 if Present (Prev_Vis) then
6322 -- Skip E in the visibility chain
6324 Set_Homonym (Prev_Vis, Homonym (E));
6327 Set_Name_Entity_Id (Chars (E), Homonym (E));
6332 -- This section of code could use a comment ???
6334 elsif Present (Etype (E))
6335 and then Is_Concurrent_Type (Etype (E))
6340 -- If the homograph is a protected component renaming, it should not
6341 -- be hiding the current entity. Such renamings are treated as weak
6344 elsif Is_Prival (E) then
6345 Set_Is_Immediately_Visible (E, False);
6347 -- In this case the current entity is a protected component renaming.
6348 -- Perform minimal decoration by setting the scope and return since
6349 -- the prival should not be hiding other visible entities.
6351 elsif Is_Prival (Def_Id) then
6352 Set_Scope (Def_Id, Current_Scope);
6355 -- Analogous to privals, the discriminal generated for an entry index
6356 -- parameter acts as a weak declaration. Perform minimal decoration
6357 -- to avoid bogus errors.
6359 elsif Is_Discriminal (Def_Id)
6360 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
6362 Set_Scope (Def_Id, Current_Scope);
6365 -- In the body or private part of an instance, a type extension may
6366 -- introduce a component with the same name as that of an actual. The
6367 -- legality rule is not enforced, but the semantics of the full type
6368 -- with two components of same name are not clear at this point???
6370 elsif In_Instance_Not_Visible then
6373 -- When compiling a package body, some child units may have become
6374 -- visible. They cannot conflict with local entities that hide them.
6376 elsif Is_Child_Unit (E)
6377 and then In_Open_Scopes (Scope (E))
6378 and then not Is_Immediately_Visible (E)
6382 -- Conversely, with front-end inlining we may compile the parent body
6383 -- first, and a child unit subsequently. The context is now the
6384 -- parent spec, and body entities are not visible.
6386 elsif Is_Child_Unit (Def_Id)
6387 and then Is_Package_Body_Entity (E)
6388 and then not In_Package_Body (Current_Scope)
6392 -- Case of genuine duplicate declaration
6395 Error_Msg_Sloc := Sloc (E);
6397 -- If the previous declaration is an incomplete type declaration
6398 -- this may be an attempt to complete it with a private type. The
6399 -- following avoids confusing cascaded errors.
6401 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
6402 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
6405 ("incomplete type cannot be completed with a private " &
6406 "declaration", Parent (Def_Id));
6407 Set_Is_Immediately_Visible (E, False);
6408 Set_Full_View (E, Def_Id);
6410 -- An inherited component of a record conflicts with a new
6411 -- discriminant. The discriminant is inserted first in the scope,
6412 -- but the error should be posted on it, not on the component.
6414 elsif Ekind (E) = E_Discriminant
6415 and then Present (Scope (Def_Id))
6416 and then Scope (Def_Id) /= Current_Scope
6418 Error_Msg_Sloc := Sloc (Def_Id);
6419 Error_Msg_N ("& conflicts with declaration#", E);
6422 -- If the name of the unit appears in its own context clause, a
6423 -- dummy package with the name has already been created, and the
6424 -- error emitted. Try to continue quietly.
6426 elsif Error_Posted (E)
6427 and then Sloc (E) = No_Location
6428 and then Nkind (Parent (E)) = N_Package_Specification
6429 and then Current_Scope = Standard_Standard
6431 Set_Scope (Def_Id, Current_Scope);
6435 Error_Msg_N ("& conflicts with declaration#", Def_Id);
6437 -- Avoid cascaded messages with duplicate components in
6440 if Ekind_In (E, E_Component, E_Discriminant) then
6445 if Nkind (Parent (Parent (Def_Id))) =
6446 N_Generic_Subprogram_Declaration
6448 Defining_Entity (Specification (Parent (Parent (Def_Id))))
6450 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
6453 -- If entity is in standard, then we are in trouble, because it
6454 -- means that we have a library package with a duplicated name.
6455 -- That's hard to recover from, so abort.
6457 if S = Standard_Standard then
6458 raise Unrecoverable_Error;
6460 -- Otherwise we continue with the declaration. Having two
6461 -- identical declarations should not cause us too much trouble.
6469 -- If we fall through, declaration is OK, at least OK enough to continue
6471 -- If Def_Id is a discriminant or a record component we are in the midst
6472 -- of inheriting components in a derived record definition. Preserve
6473 -- their Ekind and Etype.
6475 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
6478 -- If a type is already set, leave it alone (happens when a type
6479 -- declaration is reanalyzed following a call to the optimizer).
6481 elsif Present (Etype (Def_Id)) then
6484 -- Otherwise, the kind E_Void insures that premature uses of the entity
6485 -- will be detected. Any_Type insures that no cascaded errors will occur
6488 Set_Ekind (Def_Id, E_Void);
6489 Set_Etype (Def_Id, Any_Type);
6492 -- Inherited discriminants and components in derived record types are
6493 -- immediately visible. Itypes are not.
6495 -- Unless the Itype is for a record type with a corresponding remote
6496 -- type (what is that about, it was not commented ???)
6498 if Ekind_In (Def_Id, E_Discriminant, E_Component)
6500 ((not Is_Record_Type (Def_Id)
6501 or else No (Corresponding_Remote_Type (Def_Id)))
6502 and then not Is_Itype (Def_Id))
6504 Set_Is_Immediately_Visible (Def_Id);
6505 Set_Current_Entity (Def_Id);
6508 Set_Homonym (Def_Id, C);
6509 Append_Entity (Def_Id, S);
6510 Set_Public_Status (Def_Id);
6512 -- Declaring a homonym is not allowed in SPARK ...
6514 if Present (C) and then Restriction_Check_Required (SPARK_05) then
6516 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
6517 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
6518 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
6521 -- ... unless the new declaration is in a subprogram, and the
6522 -- visible declaration is a variable declaration or a parameter
6523 -- specification outside that subprogram.
6525 if Present (Enclosing_Subp)
6526 and then Nkind_In (Parent (C), N_Object_Declaration,
6527 N_Parameter_Specification)
6528 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
6532 -- ... or the new declaration is in a package, and the visible
6533 -- declaration occurs outside that package.
6535 elsif Present (Enclosing_Pack)
6536 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
6540 -- ... or the new declaration is a component declaration in a
6541 -- record type definition.
6543 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
6546 -- Don't issue error for non-source entities
6548 elsif Comes_From_Source (Def_Id)
6549 and then Comes_From_Source (C)
6551 Error_Msg_Sloc := Sloc (C);
6552 Check_SPARK_05_Restriction
6553 ("redeclaration of identifier &#", Def_Id);
6558 -- Warn if new entity hides an old one
6560 if Warn_On_Hiding and then Present (C)
6562 -- Don't warn for record components since they always have a well
6563 -- defined scope which does not confuse other uses. Note that in
6564 -- some cases, Ekind has not been set yet.
6566 and then Ekind (C) /= E_Component
6567 and then Ekind (C) /= E_Discriminant
6568 and then Nkind (Parent (C)) /= N_Component_Declaration
6569 and then Ekind (Def_Id) /= E_Component
6570 and then Ekind (Def_Id) /= E_Discriminant
6571 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
6573 -- Don't warn for one character variables. It is too common to use
6574 -- such variables as locals and will just cause too many false hits.
6576 and then Length_Of_Name (Chars (C)) /= 1
6578 -- Don't warn for non-source entities
6580 and then Comes_From_Source (C)
6581 and then Comes_From_Source (Def_Id)
6583 -- Don't warn unless entity in question is in extended main source
6585 and then In_Extended_Main_Source_Unit (Def_Id)
6587 -- Finally, the hidden entity must be either immediately visible or
6588 -- use visible (i.e. from a used package).
6591 (Is_Immediately_Visible (C)
6593 Is_Potentially_Use_Visible (C))
6595 Error_Msg_Sloc := Sloc (C);
6596 Error_Msg_N ("declaration hides &#?h?", Def_Id);
6604 function Entity_Of (N : Node_Id) return Entity_Id is
6610 if Is_Entity_Name (N) then
6613 -- Follow a possible chain of renamings to reach the root renamed
6617 and then Is_Object (Id)
6618 and then Present (Renamed_Object (Id))
6620 if Is_Entity_Name (Renamed_Object (Id)) then
6621 Id := Entity (Renamed_Object (Id));
6632 --------------------------
6633 -- Explain_Limited_Type --
6634 --------------------------
6636 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
6640 -- For array, component type must be limited
6642 if Is_Array_Type (T) then
6643 Error_Msg_Node_2 := T;
6645 ("\component type& of type& is limited", N, Component_Type (T));
6646 Explain_Limited_Type (Component_Type (T), N);
6648 elsif Is_Record_Type (T) then
6650 -- No need for extra messages if explicit limited record
6652 if Is_Limited_Record (Base_Type (T)) then
6656 -- Otherwise find a limited component. Check only components that
6657 -- come from source, or inherited components that appear in the
6658 -- source of the ancestor.
6660 C := First_Component (T);
6661 while Present (C) loop
6662 if Is_Limited_Type (Etype (C))
6664 (Comes_From_Source (C)
6666 (Present (Original_Record_Component (C))
6668 Comes_From_Source (Original_Record_Component (C))))
6670 Error_Msg_Node_2 := T;
6671 Error_Msg_NE ("\component& of type& has limited type", N, C);
6672 Explain_Limited_Type (Etype (C), N);
6679 -- The type may be declared explicitly limited, even if no component
6680 -- of it is limited, in which case we fall out of the loop.
6683 end Explain_Limited_Type;
6685 ---------------------------------------
6686 -- Expression_Of_Expression_Function --
6687 ---------------------------------------
6689 function Expression_Of_Expression_Function
6690 (Subp : Entity_Id) return Node_Id
6692 Expr_Func : Node_Id;
6695 pragma Assert (Is_Expression_Function_Or_Completion (Subp));
6697 if Nkind (Original_Node (Subprogram_Spec (Subp))) =
6698 N_Expression_Function
6700 Expr_Func := Original_Node (Subprogram_Spec (Subp));
6702 elsif Nkind (Original_Node (Subprogram_Body (Subp))) =
6703 N_Expression_Function
6705 Expr_Func := Original_Node (Subprogram_Body (Subp));
6708 pragma Assert (False);
6712 return Original_Node (Expression (Expr_Func));
6713 end Expression_Of_Expression_Function;
6715 -------------------------------
6716 -- Extensions_Visible_Status --
6717 -------------------------------
6719 function Extensions_Visible_Status
6720 (Id : Entity_Id) return Extensions_Visible_Mode
6729 -- When a formal parameter is subject to Extensions_Visible, the pragma
6730 -- is stored in the contract of related subprogram.
6732 if Is_Formal (Id) then
6735 elsif Is_Subprogram_Or_Generic_Subprogram (Id) then
6738 -- No other construct carries this pragma
6741 return Extensions_Visible_None;
6744 Prag := Get_Pragma (Subp, Pragma_Extensions_Visible);
6746 -- In certain cases analysis may request the Extensions_Visible status
6747 -- of an expression function before the pragma has been analyzed yet.
6748 -- Inspect the declarative items after the expression function looking
6749 -- for the pragma (if any).
6751 if No (Prag) and then Is_Expression_Function (Subp) then
6752 Decl := Next (Unit_Declaration_Node (Subp));
6753 while Present (Decl) loop
6754 if Nkind (Decl) = N_Pragma
6755 and then Pragma_Name (Decl) = Name_Extensions_Visible
6760 -- A source construct ends the region where Extensions_Visible may
6761 -- appear, stop the traversal. An expanded expression function is
6762 -- no longer a source construct, but it must still be recognized.
6764 elsif Comes_From_Source (Decl)
6766 (Nkind_In (Decl, N_Subprogram_Body,
6767 N_Subprogram_Declaration)
6768 and then Is_Expression_Function (Defining_Entity (Decl)))
6777 -- Extract the value from the Boolean expression (if any)
6779 if Present (Prag) then
6780 Arg := First (Pragma_Argument_Associations (Prag));
6782 if Present (Arg) then
6783 Expr := Get_Pragma_Arg (Arg);
6785 -- When the associated subprogram is an expression function, the
6786 -- argument of the pragma may not have been analyzed.
6788 if not Analyzed (Expr) then
6789 Preanalyze_And_Resolve (Expr, Standard_Boolean);
6792 -- Guard against cascading errors when the argument of pragma
6793 -- Extensions_Visible is not a valid static Boolean expression.
6795 if Error_Posted (Expr) then
6796 return Extensions_Visible_None;
6798 elsif Is_True (Expr_Value (Expr)) then
6799 return Extensions_Visible_True;
6802 return Extensions_Visible_False;
6805 -- Otherwise the aspect or pragma defaults to True
6808 return Extensions_Visible_True;
6811 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
6812 -- directly specified. In SPARK code, its value defaults to "False".
6814 elsif SPARK_Mode = On then
6815 return Extensions_Visible_False;
6817 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
6821 return Extensions_Visible_True;
6823 end Extensions_Visible_Status;
6829 procedure Find_Actual
6831 Formal : out Entity_Id;
6834 Context : constant Node_Id := Parent (N);
6839 if Nkind_In (Context, N_Indexed_Component, N_Selected_Component)
6840 and then N = Prefix (Context)
6842 Find_Actual (Context, Formal, Call);
6845 elsif Nkind (Context) = N_Parameter_Association
6846 and then N = Explicit_Actual_Parameter (Context)
6848 Call := Parent (Context);
6850 elsif Nkind_In (Context, N_Entry_Call_Statement,
6852 N_Procedure_Call_Statement)
6862 -- If we have a call to a subprogram look for the parameter. Note that
6863 -- we exclude overloaded calls, since we don't know enough to be sure
6864 -- of giving the right answer in this case.
6866 if Nkind_In (Call, N_Entry_Call_Statement,
6868 N_Procedure_Call_Statement)
6870 Call_Nam := Name (Call);
6872 -- A call to a protected or task entry appears as a selected
6873 -- component rather than an expanded name.
6875 if Nkind (Call_Nam) = N_Selected_Component then
6876 Call_Nam := Selector_Name (Call_Nam);
6879 if Is_Entity_Name (Call_Nam)
6880 and then Present (Entity (Call_Nam))
6881 and then Is_Overloadable (Entity (Call_Nam))
6882 and then not Is_Overloaded (Call_Nam)
6884 -- If node is name in call it is not an actual
6886 if N = Call_Nam then
6892 -- Fall here if we are definitely a parameter
6894 Actual := First_Actual (Call);
6895 Formal := First_Formal (Entity (Call_Nam));
6896 while Present (Formal) and then Present (Actual) loop
6900 -- An actual that is the prefix in a prefixed call may have
6901 -- been rewritten in the call, after the deferred reference
6902 -- was collected. Check if sloc and kinds and names match.
6904 elsif Sloc (Actual) = Sloc (N)
6905 and then Nkind (Actual) = N_Identifier
6906 and then Nkind (Actual) = Nkind (N)
6907 and then Chars (Actual) = Chars (N)
6912 Actual := Next_Actual (Actual);
6913 Formal := Next_Formal (Formal);
6919 -- Fall through here if we did not find matching actual
6925 ---------------------------
6926 -- Find_Body_Discriminal --
6927 ---------------------------
6929 function Find_Body_Discriminal
6930 (Spec_Discriminant : Entity_Id) return Entity_Id
6936 -- If expansion is suppressed, then the scope can be the concurrent type
6937 -- itself rather than a corresponding concurrent record type.
6939 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
6940 Tsk := Scope (Spec_Discriminant);
6943 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
6945 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
6948 -- Find discriminant of original concurrent type, and use its current
6949 -- discriminal, which is the renaming within the task/protected body.
6951 Disc := First_Discriminant (Tsk);
6952 while Present (Disc) loop
6953 if Chars (Disc) = Chars (Spec_Discriminant) then
6954 return Discriminal (Disc);
6957 Next_Discriminant (Disc);
6960 -- That loop should always succeed in finding a matching entry and
6961 -- returning. Fatal error if not.
6963 raise Program_Error;
6964 end Find_Body_Discriminal;
6966 -------------------------------------
6967 -- Find_Corresponding_Discriminant --
6968 -------------------------------------
6970 function Find_Corresponding_Discriminant
6972 Typ : Entity_Id) return Entity_Id
6974 Par_Disc : Entity_Id;
6975 Old_Disc : Entity_Id;
6976 New_Disc : Entity_Id;
6979 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
6981 -- The original type may currently be private, and the discriminant
6982 -- only appear on its full view.
6984 if Is_Private_Type (Scope (Par_Disc))
6985 and then not Has_Discriminants (Scope (Par_Disc))
6986 and then Present (Full_View (Scope (Par_Disc)))
6988 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
6990 Old_Disc := First_Discriminant (Scope (Par_Disc));
6993 if Is_Class_Wide_Type (Typ) then
6994 New_Disc := First_Discriminant (Root_Type (Typ));
6996 New_Disc := First_Discriminant (Typ);
6999 while Present (Old_Disc) and then Present (New_Disc) loop
7000 if Old_Disc = Par_Disc then
7004 Next_Discriminant (Old_Disc);
7005 Next_Discriminant (New_Disc);
7008 -- Should always find it
7010 raise Program_Error;
7011 end Find_Corresponding_Discriminant;
7013 ----------------------------------
7014 -- Find_Enclosing_Iterator_Loop --
7015 ----------------------------------
7017 function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id is
7022 -- Traverse the scope chain looking for an iterator loop. Such loops are
7023 -- usually transformed into blocks, hence the use of Original_Node.
7026 while Present (S) and then S /= Standard_Standard loop
7027 if Ekind (S) = E_Loop
7028 and then Nkind (Parent (S)) = N_Implicit_Label_Declaration
7030 Constr := Original_Node (Label_Construct (Parent (S)));
7032 if Nkind (Constr) = N_Loop_Statement
7033 and then Present (Iteration_Scheme (Constr))
7034 and then Nkind (Iterator_Specification
7035 (Iteration_Scheme (Constr))) =
7036 N_Iterator_Specification
7046 end Find_Enclosing_Iterator_Loop;
7048 ------------------------------------
7049 -- Find_Loop_In_Conditional_Block --
7050 ------------------------------------
7052 function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is
7058 if Nkind (Stmt) = N_If_Statement then
7059 Stmt := First (Then_Statements (Stmt));
7062 pragma Assert (Nkind (Stmt) = N_Block_Statement);
7064 -- Inspect the statements of the conditional block. In general the loop
7065 -- should be the first statement in the statement sequence of the block,
7066 -- but the finalization machinery may have introduced extra object
7069 Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
7070 while Present (Stmt) loop
7071 if Nkind (Stmt) = N_Loop_Statement then
7078 -- The expansion of attribute 'Loop_Entry produced a malformed block
7080 raise Program_Error;
7081 end Find_Loop_In_Conditional_Block;
7083 --------------------------
7084 -- Find_Overlaid_Entity --
7085 --------------------------
7087 procedure Find_Overlaid_Entity
7089 Ent : out Entity_Id;
7095 -- We are looking for one of the two following forms:
7097 -- for X'Address use Y'Address
7101 -- Const : constant Address := expr;
7103 -- for X'Address use Const;
7105 -- In the second case, the expr is either Y'Address, or recursively a
7106 -- constant that eventually references Y'Address.
7111 if Nkind (N) = N_Attribute_Definition_Clause
7112 and then Chars (N) = Name_Address
7114 Expr := Expression (N);
7116 -- This loop checks the form of the expression for Y'Address,
7117 -- using recursion to deal with intermediate constants.
7120 -- Check for Y'Address
7122 if Nkind (Expr) = N_Attribute_Reference
7123 and then Attribute_Name (Expr) = Name_Address
7125 Expr := Prefix (Expr);
7128 -- Check for Const where Const is a constant entity
7130 elsif Is_Entity_Name (Expr)
7131 and then Ekind (Entity (Expr)) = E_Constant
7133 Expr := Constant_Value (Entity (Expr));
7135 -- Anything else does not need checking
7142 -- This loop checks the form of the prefix for an entity, using
7143 -- recursion to deal with intermediate components.
7146 -- Check for Y where Y is an entity
7148 if Is_Entity_Name (Expr) then
7149 Ent := Entity (Expr);
7152 -- Check for components
7155 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component)
7157 Expr := Prefix (Expr);
7160 -- Anything else does not need checking
7167 end Find_Overlaid_Entity;
7169 -------------------------
7170 -- Find_Parameter_Type --
7171 -------------------------
7173 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
7175 if Nkind (Param) /= N_Parameter_Specification then
7178 -- For an access parameter, obtain the type from the formal entity
7179 -- itself, because access to subprogram nodes do not carry a type.
7180 -- Shouldn't we always use the formal entity ???
7182 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
7183 return Etype (Defining_Identifier (Param));
7186 return Etype (Parameter_Type (Param));
7188 end Find_Parameter_Type;
7190 -----------------------------------
7191 -- Find_Placement_In_State_Space --
7192 -----------------------------------
7194 procedure Find_Placement_In_State_Space
7195 (Item_Id : Entity_Id;
7196 Placement : out State_Space_Kind;
7197 Pack_Id : out Entity_Id)
7199 Context : Entity_Id;
7202 -- Assume that the item does not appear in the state space of a package
7204 Placement := Not_In_Package;
7207 -- Climb the scope stack and examine the enclosing context
7209 Context := Scope (Item_Id);
7210 while Present (Context) and then Context /= Standard_Standard loop
7211 if Ekind (Context) = E_Package then
7214 -- A package body is a cut off point for the traversal as the item
7215 -- cannot be visible to the outside from this point on. Note that
7216 -- this test must be done first as a body is also classified as a
7219 if In_Package_Body (Context) then
7220 Placement := Body_State_Space;
7223 -- The private part of a package is a cut off point for the
7224 -- traversal as the item cannot be visible to the outside from
7227 elsif In_Private_Part (Context) then
7228 Placement := Private_State_Space;
7231 -- When the item appears in the visible state space of a package,
7232 -- continue to climb the scope stack as this may not be the final
7236 Placement := Visible_State_Space;
7238 -- The visible state space of a child unit acts as the proper
7239 -- placement of an item.
7241 if Is_Child_Unit (Context) then
7246 -- The item or its enclosing package appear in a construct that has
7250 Placement := Not_In_Package;
7254 Context := Scope (Context);
7256 end Find_Placement_In_State_Space;
7258 ------------------------
7259 -- Find_Specific_Type --
7260 ------------------------
7262 function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
7263 Typ : Entity_Id := Root_Type (CW);
7266 if Ekind (Typ) = E_Incomplete_Type then
7267 if From_Limited_With (Typ) then
7268 Typ := Non_Limited_View (Typ);
7270 Typ := Full_View (Typ);
7274 if Is_Private_Type (Typ)
7275 and then not Is_Tagged_Type (Typ)
7276 and then Present (Full_View (Typ))
7278 return Full_View (Typ);
7282 end Find_Specific_Type;
7284 -----------------------------
7285 -- Find_Static_Alternative --
7286 -----------------------------
7288 function Find_Static_Alternative (N : Node_Id) return Node_Id is
7289 Expr : constant Node_Id := Expression (N);
7290 Val : constant Uint := Expr_Value (Expr);
7295 Alt := First (Alternatives (N));
7298 if Nkind (Alt) /= N_Pragma then
7299 Choice := First (Discrete_Choices (Alt));
7300 while Present (Choice) loop
7302 -- Others choice, always matches
7304 if Nkind (Choice) = N_Others_Choice then
7307 -- Range, check if value is in the range
7309 elsif Nkind (Choice) = N_Range then
7311 Val >= Expr_Value (Low_Bound (Choice))
7313 Val <= Expr_Value (High_Bound (Choice));
7315 -- Choice is a subtype name. Note that we know it must
7316 -- be a static subtype, since otherwise it would have
7317 -- been diagnosed as illegal.
7319 elsif Is_Entity_Name (Choice)
7320 and then Is_Type (Entity (Choice))
7322 exit Search when Is_In_Range (Expr, Etype (Choice),
7323 Assume_Valid => False);
7325 -- Choice is a subtype indication
7327 elsif Nkind (Choice) = N_Subtype_Indication then
7329 C : constant Node_Id := Constraint (Choice);
7330 R : constant Node_Id := Range_Expression (C);
7334 Val >= Expr_Value (Low_Bound (R))
7336 Val <= Expr_Value (High_Bound (R));
7339 -- Choice is a simple expression
7342 exit Search when Val = Expr_Value (Choice);
7350 pragma Assert (Present (Alt));
7353 -- The above loop *must* terminate by finding a match, since we know the
7354 -- case statement is valid, and the value of the expression is known at
7355 -- compile time. When we fall out of the loop, Alt points to the
7356 -- alternative that we know will be selected at run time.
7359 end Find_Static_Alternative;
7365 function First_Actual (Node : Node_Id) return Node_Id is
7369 if No (Parameter_Associations (Node)) then
7373 N := First (Parameter_Associations (Node));
7375 if Nkind (N) = N_Parameter_Association then
7376 return First_Named_Actual (Node);
7386 function Fix_Msg (Id : Entity_Id; Msg : String) return String is
7387 Is_Task : constant Boolean :=
7388 Ekind_In (Id, E_Task_Body, E_Task_Type)
7389 or else Is_Single_Task_Object (Id);
7390 Msg_Last : constant Natural := Msg'Last;
7391 Msg_Index : Natural;
7392 Res : String (Msg'Range) := (others => ' ');
7393 Res_Index : Natural;
7396 -- Copy all characters from the input message Msg to result Res with
7397 -- suitable replacements.
7399 Msg_Index := Msg'First;
7400 Res_Index := Res'First;
7401 while Msg_Index <= Msg_Last loop
7403 -- Replace "subprogram" with a different word
7405 if Msg_Index <= Msg_Last - 10
7406 and then Msg (Msg_Index .. Msg_Index + 9) = "subprogram"
7408 if Ekind_In (Id, E_Entry, E_Entry_Family) then
7409 Res (Res_Index .. Res_Index + 4) := "entry";
7410 Res_Index := Res_Index + 5;
7413 Res (Res_Index .. Res_Index + 8) := "task type";
7414 Res_Index := Res_Index + 9;
7417 Res (Res_Index .. Res_Index + 9) := "subprogram";
7418 Res_Index := Res_Index + 10;
7421 Msg_Index := Msg_Index + 10;
7423 -- Replace "protected" with a different word
7425 elsif Msg_Index <= Msg_Last - 9
7426 and then Msg (Msg_Index .. Msg_Index + 8) = "protected"
7429 Res (Res_Index .. Res_Index + 3) := "task";
7430 Res_Index := Res_Index + 4;
7431 Msg_Index := Msg_Index + 9;
7433 -- Otherwise copy the character
7436 Res (Res_Index) := Msg (Msg_Index);
7437 Msg_Index := Msg_Index + 1;
7438 Res_Index := Res_Index + 1;
7442 return Res (Res'First .. Res_Index - 1);
7445 -----------------------
7446 -- Gather_Components --
7447 -----------------------
7449 procedure Gather_Components
7451 Comp_List : Node_Id;
7452 Governed_By : List_Id;
7454 Report_Errors : out Boolean)
7458 Discrete_Choice : Node_Id;
7459 Comp_Item : Node_Id;
7461 Discrim : Entity_Id;
7462 Discrim_Name : Node_Id;
7463 Discrim_Value : Node_Id;
7466 Report_Errors := False;
7468 if No (Comp_List) or else Null_Present (Comp_List) then
7471 elsif Present (Component_Items (Comp_List)) then
7472 Comp_Item := First (Component_Items (Comp_List));
7478 while Present (Comp_Item) loop
7480 -- Skip the tag of a tagged record, the interface tags, as well
7481 -- as all items that are not user components (anonymous types,
7482 -- rep clauses, Parent field, controller field).
7484 if Nkind (Comp_Item) = N_Component_Declaration then
7486 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
7488 if not Is_Tag (Comp) and then Chars (Comp) /= Name_uParent then
7489 Append_Elmt (Comp, Into);
7497 if No (Variant_Part (Comp_List)) then
7500 Discrim_Name := Name (Variant_Part (Comp_List));
7501 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
7504 -- Look for the discriminant that governs this variant part.
7505 -- The discriminant *must* be in the Governed_By List
7507 Assoc := First (Governed_By);
7508 Find_Constraint : loop
7509 Discrim := First (Choices (Assoc));
7510 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
7511 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
7513 Chars (Corresponding_Discriminant (Entity (Discrim))) =
7514 Chars (Discrim_Name))
7515 or else Chars (Original_Record_Component (Entity (Discrim)))
7516 = Chars (Discrim_Name);
7518 if No (Next (Assoc)) then
7519 if not Is_Constrained (Typ)
7520 and then Is_Derived_Type (Typ)
7521 and then Present (Stored_Constraint (Typ))
7523 -- If the type is a tagged type with inherited discriminants,
7524 -- use the stored constraint on the parent in order to find
7525 -- the values of discriminants that are otherwise hidden by an
7526 -- explicit constraint. Renamed discriminants are handled in
7529 -- If several parent discriminants are renamed by a single
7530 -- discriminant of the derived type, the call to obtain the
7531 -- Corresponding_Discriminant field only retrieves the last
7532 -- of them. We recover the constraint on the others from the
7533 -- Stored_Constraint as well.
7540 D := First_Discriminant (Etype (Typ));
7541 C := First_Elmt (Stored_Constraint (Typ));
7542 while Present (D) and then Present (C) loop
7543 if Chars (Discrim_Name) = Chars (D) then
7544 if Is_Entity_Name (Node (C))
7545 and then Entity (Node (C)) = Entity (Discrim)
7547 -- D is renamed by Discrim, whose value is given in
7554 Make_Component_Association (Sloc (Typ),
7556 (New_Occurrence_Of (D, Sloc (Typ))),
7557 Duplicate_Subexpr_No_Checks (Node (C)));
7559 exit Find_Constraint;
7562 Next_Discriminant (D);
7569 if No (Next (Assoc)) then
7570 Error_Msg_NE (" missing value for discriminant&",
7571 First (Governed_By), Discrim_Name);
7572 Report_Errors := True;
7577 end loop Find_Constraint;
7579 Discrim_Value := Expression (Assoc);
7581 if not Is_OK_Static_Expression (Discrim_Value) then
7583 -- If the variant part is governed by a discriminant of the type
7584 -- this is an error. If the variant part and the discriminant are
7585 -- inherited from an ancestor this is legal (AI05-120) unless the
7586 -- components are being gathered for an aggregate, in which case
7587 -- the caller must check Report_Errors.
7589 if Scope (Original_Record_Component
7590 ((Entity (First (Choices (Assoc)))))) = Typ
7593 ("value for discriminant & must be static!",
7594 Discrim_Value, Discrim);
7595 Why_Not_Static (Discrim_Value);
7598 Report_Errors := True;
7602 Search_For_Discriminant_Value : declare
7608 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
7611 Find_Discrete_Value : while Present (Variant) loop
7612 Discrete_Choice := First (Discrete_Choices (Variant));
7613 while Present (Discrete_Choice) loop
7614 exit Find_Discrete_Value when
7615 Nkind (Discrete_Choice) = N_Others_Choice;
7617 Get_Index_Bounds (Discrete_Choice, Low, High);
7619 UI_Low := Expr_Value (Low);
7620 UI_High := Expr_Value (High);
7622 exit Find_Discrete_Value when
7623 UI_Low <= UI_Discrim_Value
7625 UI_High >= UI_Discrim_Value;
7627 Next (Discrete_Choice);
7630 Next_Non_Pragma (Variant);
7631 end loop Find_Discrete_Value;
7632 end Search_For_Discriminant_Value;
7634 -- The case statement must include a variant that corresponds to the
7635 -- value of the discriminant, unless the discriminant type has a
7636 -- static predicate. In that case the absence of an others_choice that
7637 -- would cover this value becomes a run-time error (3.8,1 (21.1/2)).
7640 and then not Has_Static_Predicate (Etype (Discrim_Name))
7643 ("value of discriminant & is out of range", Discrim_Value, Discrim);
7644 Report_Errors := True;
7648 -- If we have found the corresponding choice, recursively add its
7649 -- components to the Into list. The nested components are part of
7650 -- the same record type.
7652 if Present (Variant) then
7654 (Typ, Component_List (Variant), Governed_By, Into, Report_Errors);
7656 end Gather_Components;
7658 ------------------------
7659 -- Get_Actual_Subtype --
7660 ------------------------
7662 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
7663 Typ : constant Entity_Id := Etype (N);
7664 Utyp : Entity_Id := Underlying_Type (Typ);
7673 -- If what we have is an identifier that references a subprogram
7674 -- formal, or a variable or constant object, then we get the actual
7675 -- subtype from the referenced entity if one has been built.
7677 if Nkind (N) = N_Identifier
7679 (Is_Formal (Entity (N))
7680 or else Ekind (Entity (N)) = E_Constant
7681 or else Ekind (Entity (N)) = E_Variable)
7682 and then Present (Actual_Subtype (Entity (N)))
7684 return Actual_Subtype (Entity (N));
7686 -- Actual subtype of unchecked union is always itself. We never need
7687 -- the "real" actual subtype. If we did, we couldn't get it anyway
7688 -- because the discriminant is not available. The restrictions on
7689 -- Unchecked_Union are designed to make sure that this is OK.
7691 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
7694 -- Here for the unconstrained case, we must find actual subtype
7695 -- No actual subtype is available, so we must build it on the fly.
7697 -- Checking the type, not the underlying type, for constrainedness
7698 -- seems to be necessary. Maybe all the tests should be on the type???
7700 elsif (not Is_Constrained (Typ))
7701 and then (Is_Array_Type (Utyp)
7702 or else (Is_Record_Type (Utyp)
7703 and then Has_Discriminants (Utyp)))
7704 and then not Has_Unknown_Discriminants (Utyp)
7705 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
7707 -- Nothing to do if in spec expression (why not???)
7709 if In_Spec_Expression then
7712 elsif Is_Private_Type (Typ) and then not Has_Discriminants (Typ) then
7714 -- If the type has no discriminants, there is no subtype to
7715 -- build, even if the underlying type is discriminated.
7719 -- Else build the actual subtype
7722 Decl := Build_Actual_Subtype (Typ, N);
7723 Atyp := Defining_Identifier (Decl);
7725 -- If Build_Actual_Subtype generated a new declaration then use it
7729 -- The actual subtype is an Itype, so analyze the declaration,
7730 -- but do not attach it to the tree, to get the type defined.
7732 Set_Parent (Decl, N);
7733 Set_Is_Itype (Atyp);
7734 Analyze (Decl, Suppress => All_Checks);
7735 Set_Associated_Node_For_Itype (Atyp, N);
7736 Set_Has_Delayed_Freeze (Atyp, False);
7738 -- We need to freeze the actual subtype immediately. This is
7739 -- needed, because otherwise this Itype will not get frozen
7740 -- at all, and it is always safe to freeze on creation because
7741 -- any associated types must be frozen at this point.
7743 Freeze_Itype (Atyp, N);
7746 -- Otherwise we did not build a declaration, so return original
7753 -- For all remaining cases, the actual subtype is the same as
7754 -- the nominal type.
7759 end Get_Actual_Subtype;
7761 -------------------------------------
7762 -- Get_Actual_Subtype_If_Available --
7763 -------------------------------------
7765 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
7766 Typ : constant Entity_Id := Etype (N);
7769 -- If what we have is an identifier that references a subprogram
7770 -- formal, or a variable or constant object, then we get the actual
7771 -- subtype from the referenced entity if one has been built.
7773 if Nkind (N) = N_Identifier
7775 (Is_Formal (Entity (N))
7776 or else Ekind (Entity (N)) = E_Constant
7777 or else Ekind (Entity (N)) = E_Variable)
7778 and then Present (Actual_Subtype (Entity (N)))
7780 return Actual_Subtype (Entity (N));
7782 -- Otherwise the Etype of N is returned unchanged
7787 end Get_Actual_Subtype_If_Available;
7789 ------------------------
7790 -- Get_Body_From_Stub --
7791 ------------------------
7793 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
7795 return Proper_Body (Unit (Library_Unit (N)));
7796 end Get_Body_From_Stub;
7798 ---------------------
7799 -- Get_Cursor_Type --
7800 ---------------------
7802 function Get_Cursor_Type
7804 Typ : Entity_Id) return Entity_Id
7808 First_Op : Entity_Id;
7812 -- If error already detected, return
7814 if Error_Posted (Aspect) then
7818 -- The cursor type for an Iterable aspect is the return type of a
7819 -- non-overloaded First primitive operation. Locate association for
7822 Assoc := First (Component_Associations (Expression (Aspect)));
7824 while Present (Assoc) loop
7825 if Chars (First (Choices (Assoc))) = Name_First then
7826 First_Op := Expression (Assoc);
7833 if First_Op = Any_Id then
7834 Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
7840 -- Locate function with desired name and profile in scope of type
7841 -- In the rare case where the type is an integer type, a base type
7842 -- is created for it, check that the base type of the first formal
7843 -- of First matches the base type of the domain.
7845 Func := First_Entity (Scope (Typ));
7846 while Present (Func) loop
7847 if Chars (Func) = Chars (First_Op)
7848 and then Ekind (Func) = E_Function
7849 and then Present (First_Formal (Func))
7850 and then Base_Type (Etype (First_Formal (Func))) = Base_Type (Typ)
7851 and then No (Next_Formal (First_Formal (Func)))
7853 if Cursor /= Any_Type then
7855 ("Operation First for iterable type must be unique", Aspect);
7858 Cursor := Etype (Func);
7865 -- If not found, no way to resolve remaining primitives.
7867 if Cursor = Any_Type then
7869 ("No legal primitive operation First for Iterable type", Aspect);
7873 end Get_Cursor_Type;
7875 function Get_Cursor_Type (Typ : Entity_Id) return Entity_Id is
7877 return Etype (Get_Iterable_Type_Primitive (Typ, Name_First));
7878 end Get_Cursor_Type;
7880 -------------------------------
7881 -- Get_Default_External_Name --
7882 -------------------------------
7884 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
7886 Get_Decoded_Name_String (Chars (E));
7888 if Opt.External_Name_Imp_Casing = Uppercase then
7889 Set_Casing (All_Upper_Case);
7891 Set_Casing (All_Lower_Case);
7895 Make_String_Literal (Sloc (E),
7896 Strval => String_From_Name_Buffer);
7897 end Get_Default_External_Name;
7899 --------------------------
7900 -- Get_Enclosing_Object --
7901 --------------------------
7903 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
7905 if Is_Entity_Name (N) then
7909 when N_Indexed_Component
7910 | N_Selected_Component
7913 -- If not generating code, a dereference may be left implicit.
7914 -- In thoses cases, return Empty.
7916 if Is_Access_Type (Etype (Prefix (N))) then
7919 return Get_Enclosing_Object (Prefix (N));
7922 when N_Type_Conversion =>
7923 return Get_Enclosing_Object (Expression (N));
7929 end Get_Enclosing_Object;
7931 ---------------------------
7932 -- Get_Enum_Lit_From_Pos --
7933 ---------------------------
7935 function Get_Enum_Lit_From_Pos
7938 Loc : Source_Ptr) return Node_Id
7940 Btyp : Entity_Id := Base_Type (T);
7945 -- In the case where the literal is of type Character, Wide_Character
7946 -- or Wide_Wide_Character or of a type derived from them, there needs
7947 -- to be some special handling since there is no explicit chain of
7948 -- literals to search. Instead, an N_Character_Literal node is created
7949 -- with the appropriate Char_Code and Chars fields.
7951 if Is_Standard_Character_Type (T) then
7952 Set_Character_Literal_Name (UI_To_CC (Pos));
7955 Make_Character_Literal (Loc,
7957 Char_Literal_Value => Pos);
7959 -- For all other cases, we have a complete table of literals, and
7960 -- we simply iterate through the chain of literal until the one
7961 -- with the desired position value is found.
7964 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
7965 Btyp := Full_View (Btyp);
7968 Lit := First_Literal (Btyp);
7969 for J in 1 .. UI_To_Int (Pos) loop
7972 -- If Lit is Empty, Pos is not in range, so raise Constraint_Error
7973 -- inside the loop to avoid calling Next_Literal on Empty.
7976 raise Constraint_Error;
7980 -- Create a new node from Lit, with source location provided by Loc
7981 -- if not equal to No_Location, or by copying the source location of
7986 if LLoc = No_Location then
7990 return New_Occurrence_Of (Lit, LLoc);
7992 end Get_Enum_Lit_From_Pos;
7994 ------------------------
7995 -- Get_Generic_Entity --
7996 ------------------------
7998 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
7999 Ent : constant Entity_Id := Entity (Name (N));
8001 if Present (Renamed_Object (Ent)) then
8002 return Renamed_Object (Ent);
8006 end Get_Generic_Entity;
8008 -------------------------------------
8009 -- Get_Incomplete_View_Of_Ancestor --
8010 -------------------------------------
8012 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
8013 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
8014 Par_Scope : Entity_Id;
8015 Par_Type : Entity_Id;
8018 -- The incomplete view of an ancestor is only relevant for private
8019 -- derived types in child units.
8021 if not Is_Derived_Type (E)
8022 or else not Is_Child_Unit (Cur_Unit)
8027 Par_Scope := Scope (Cur_Unit);
8028 if No (Par_Scope) then
8032 Par_Type := Etype (Base_Type (E));
8034 -- Traverse list of ancestor types until we find one declared in
8035 -- a parent or grandparent unit (two levels seem sufficient).
8037 while Present (Par_Type) loop
8038 if Scope (Par_Type) = Par_Scope
8039 or else Scope (Par_Type) = Scope (Par_Scope)
8043 elsif not Is_Derived_Type (Par_Type) then
8047 Par_Type := Etype (Base_Type (Par_Type));
8051 -- If none found, there is no relevant ancestor type.
8055 end Get_Incomplete_View_Of_Ancestor;
8057 ----------------------
8058 -- Get_Index_Bounds --
8059 ----------------------
8061 procedure Get_Index_Bounds
8065 Use_Full_View : Boolean := False)
8067 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id;
8068 -- Obtain the scalar range of type Typ. If flag Use_Full_View is set and
8069 -- Typ qualifies, the scalar range is obtained from the full view of the
8072 --------------------------
8073 -- Scalar_Range_Of_Type --
8074 --------------------------
8076 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id is
8077 T : Entity_Id := Typ;
8080 if Use_Full_View and then Present (Full_View (T)) then
8084 return Scalar_Range (T);
8085 end Scalar_Range_Of_Type;
8089 Kind : constant Node_Kind := Nkind (N);
8092 -- Start of processing for Get_Index_Bounds
8095 if Kind = N_Range then
8097 H := High_Bound (N);
8099 elsif Kind = N_Subtype_Indication then
8100 Rng := Range_Expression (Constraint (N));
8108 L := Low_Bound (Range_Expression (Constraint (N)));
8109 H := High_Bound (Range_Expression (Constraint (N)));
8112 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
8113 Rng := Scalar_Range_Of_Type (Entity (N));
8115 if Error_Posted (Rng) then
8119 elsif Nkind (Rng) = N_Subtype_Indication then
8120 Get_Index_Bounds (Rng, L, H);
8123 L := Low_Bound (Rng);
8124 H := High_Bound (Rng);
8128 -- N is an expression, indicating a range with one value
8133 end Get_Index_Bounds;
8135 ---------------------------------
8136 -- Get_Iterable_Type_Primitive --
8137 ---------------------------------
8139 function Get_Iterable_Type_Primitive
8141 Nam : Name_Id) return Entity_Id
8143 Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
8151 Assoc := First (Component_Associations (Funcs));
8152 while Present (Assoc) loop
8153 if Chars (First (Choices (Assoc))) = Nam then
8154 return Entity (Expression (Assoc));
8157 Assoc := Next (Assoc);
8162 end Get_Iterable_Type_Primitive;
8164 ----------------------------------
8165 -- Get_Library_Unit_Name_string --
8166 ----------------------------------
8168 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
8169 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
8172 Get_Unit_Name_String (Unit_Name_Id);
8174 -- Remove seven last character (" (spec)" or " (body)")
8176 Name_Len := Name_Len - 7;
8177 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
8178 end Get_Library_Unit_Name_String;
8180 --------------------------
8181 -- Get_Max_Queue_Length --
8182 --------------------------
8184 function Get_Max_Queue_Length (Id : Entity_Id) return Uint is
8185 pragma Assert (Is_Entry (Id));
8186 Prag : constant Entity_Id := Get_Pragma (Id, Pragma_Max_Queue_Length);
8189 -- A value of 0 represents no maximum specified, and entries and entry
8190 -- families with no Max_Queue_Length aspect or pragma default to it.
8192 if not Present (Prag) then
8196 return Intval (Expression (First (Pragma_Argument_Associations (Prag))));
8197 end Get_Max_Queue_Length;
8199 ------------------------
8200 -- Get_Name_Entity_Id --
8201 ------------------------
8203 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
8205 return Entity_Id (Get_Name_Table_Int (Id));
8206 end Get_Name_Entity_Id;
8208 ------------------------------
8209 -- Get_Name_From_CTC_Pragma --
8210 ------------------------------
8212 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
8213 Arg : constant Node_Id :=
8214 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
8216 return Strval (Expr_Value_S (Arg));
8217 end Get_Name_From_CTC_Pragma;
8219 -----------------------
8220 -- Get_Parent_Entity --
8221 -----------------------
8223 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
8225 if Nkind (Unit) = N_Package_Body
8226 and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
8228 return Defining_Entity
8229 (Specification (Instance_Spec (Original_Node (Unit))));
8230 elsif Nkind (Unit) = N_Package_Instantiation then
8231 return Defining_Entity (Specification (Instance_Spec (Unit)));
8233 return Defining_Entity (Unit);
8235 end Get_Parent_Entity;
8241 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
8243 return Get_Pragma_Id (Pragma_Name_Unmapped (N));
8246 ------------------------
8247 -- Get_Qualified_Name --
8248 ------------------------
8250 function Get_Qualified_Name
8252 Suffix : Entity_Id := Empty) return Name_Id
8254 Suffix_Nam : Name_Id := No_Name;
8257 if Present (Suffix) then
8258 Suffix_Nam := Chars (Suffix);
8261 return Get_Qualified_Name (Chars (Id), Suffix_Nam, Scope (Id));
8262 end Get_Qualified_Name;
8264 function Get_Qualified_Name
8266 Suffix : Name_Id := No_Name;
8267 Scop : Entity_Id := Current_Scope) return Name_Id
8269 procedure Add_Scope (S : Entity_Id);
8270 -- Add the fully qualified form of scope S to the name buffer. The
8278 procedure Add_Scope (S : Entity_Id) is
8283 elsif S = Standard_Standard then
8287 Add_Scope (Scope (S));
8288 Get_Name_String_And_Append (Chars (S));
8289 Add_Str_To_Name_Buffer ("__");
8293 -- Start of processing for Get_Qualified_Name
8299 -- Append the base name after all scopes have been chained
8301 Get_Name_String_And_Append (Nam);
8303 -- Append the suffix (if present)
8305 if Suffix /= No_Name then
8306 Add_Str_To_Name_Buffer ("__");
8307 Get_Name_String_And_Append (Suffix);
8311 end Get_Qualified_Name;
8313 -----------------------
8314 -- Get_Reason_String --
8315 -----------------------
8317 procedure Get_Reason_String (N : Node_Id) is
8319 if Nkind (N) = N_String_Literal then
8320 Store_String_Chars (Strval (N));
8322 elsif Nkind (N) = N_Op_Concat then
8323 Get_Reason_String (Left_Opnd (N));
8324 Get_Reason_String (Right_Opnd (N));
8326 -- If not of required form, error
8330 ("Reason for pragma Warnings has wrong form", N);
8332 ("\must be string literal or concatenation of string literals", N);
8335 end Get_Reason_String;
8337 --------------------------------
8338 -- Get_Reference_Discriminant --
8339 --------------------------------
8341 function Get_Reference_Discriminant (Typ : Entity_Id) return Entity_Id is
8345 D := First_Discriminant (Typ);
8346 while Present (D) loop
8347 if Has_Implicit_Dereference (D) then
8350 Next_Discriminant (D);
8354 end Get_Reference_Discriminant;
8356 ---------------------------
8357 -- Get_Referenced_Object --
8358 ---------------------------
8360 function Get_Referenced_Object (N : Node_Id) return Node_Id is
8365 while Is_Entity_Name (R)
8366 and then Present (Renamed_Object (Entity (R)))
8368 R := Renamed_Object (Entity (R));
8372 end Get_Referenced_Object;
8374 ------------------------
8375 -- Get_Renamed_Entity --
8376 ------------------------
8378 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
8383 while Present (Renamed_Entity (R)) loop
8384 R := Renamed_Entity (R);
8388 end Get_Renamed_Entity;
8390 -----------------------
8391 -- Get_Return_Object --
8392 -----------------------
8394 function Get_Return_Object (N : Node_Id) return Entity_Id is
8398 Decl := First (Return_Object_Declarations (N));
8399 while Present (Decl) loop
8400 exit when Nkind (Decl) = N_Object_Declaration
8401 and then Is_Return_Object (Defining_Identifier (Decl));
8405 pragma Assert (Present (Decl));
8406 return Defining_Identifier (Decl);
8407 end Get_Return_Object;
8409 ---------------------------
8410 -- Get_Subprogram_Entity --
8411 ---------------------------
8413 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
8415 Subp_Id : Entity_Id;
8418 if Nkind (Nod) = N_Accept_Statement then
8419 Subp := Entry_Direct_Name (Nod);
8421 elsif Nkind (Nod) = N_Slice then
8422 Subp := Prefix (Nod);
8428 -- Strip the subprogram call
8431 if Nkind_In (Subp, N_Explicit_Dereference,
8432 N_Indexed_Component,
8433 N_Selected_Component)
8435 Subp := Prefix (Subp);
8437 elsif Nkind_In (Subp, N_Type_Conversion,
8438 N_Unchecked_Type_Conversion)
8440 Subp := Expression (Subp);
8447 -- Extract the entity of the subprogram call
8449 if Is_Entity_Name (Subp) then
8450 Subp_Id := Entity (Subp);
8452 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
8453 Subp_Id := Directly_Designated_Type (Subp_Id);
8456 if Is_Subprogram (Subp_Id) then
8462 -- The search did not find a construct that denotes a subprogram
8467 end Get_Subprogram_Entity;
8469 -----------------------------
8470 -- Get_Task_Body_Procedure --
8471 -----------------------------
8473 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
8475 -- Note: A task type may be the completion of a private type with
8476 -- discriminants. When performing elaboration checks on a task
8477 -- declaration, the current view of the type may be the private one,
8478 -- and the procedure that holds the body of the task is held in its
8481 -- This is an odd function, why not have Task_Body_Procedure do
8482 -- the following digging???
8484 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
8485 end Get_Task_Body_Procedure;
8487 -------------------------
8488 -- Get_User_Defined_Eq --
8489 -------------------------
8491 function Get_User_Defined_Eq (E : Entity_Id) return Entity_Id is
8496 Prim := First_Elmt (Collect_Primitive_Operations (E));
8497 while Present (Prim) loop
8500 if Chars (Op) = Name_Op_Eq
8501 and then Etype (Op) = Standard_Boolean
8502 and then Etype (First_Formal (Op)) = E
8503 and then Etype (Next_Formal (First_Formal (Op))) = E
8512 end Get_User_Defined_Eq;
8520 Priv_Typ : out Entity_Id;
8521 Full_Typ : out Entity_Id;
8522 Full_Base : out Entity_Id;
8523 CRec_Typ : out Entity_Id)
8525 IP_View : Entity_Id;
8528 -- Assume that none of the views can be recovered
8535 -- The input type is the corresponding record type of a protected or a
8538 if Ekind (Typ) = E_Record_Type
8539 and then Is_Concurrent_Record_Type (Typ)
8542 Full_Typ := Corresponding_Concurrent_Type (CRec_Typ);
8543 Full_Base := Base_Type (Full_Typ);
8544 Priv_Typ := Incomplete_Or_Partial_View (Full_Typ);
8546 -- Otherwise the input type denotes an arbitrary type
8549 IP_View := Incomplete_Or_Partial_View (Typ);
8551 -- The input type denotes the full view of a private type
8553 if Present (IP_View) then
8554 Priv_Typ := IP_View;
8557 -- The input type is a private type
8559 elsif Is_Private_Type (Typ) then
8561 Full_Typ := Full_View (Priv_Typ);
8563 -- Otherwise the input type does not have any views
8569 if Present (Full_Typ) then
8570 Full_Base := Base_Type (Full_Typ);
8572 if Ekind_In (Full_Typ, E_Protected_Type, E_Task_Type) then
8573 CRec_Typ := Corresponding_Record_Type (Full_Typ);
8579 -----------------------
8580 -- Has_Access_Values --
8581 -----------------------
8583 function Has_Access_Values (T : Entity_Id) return Boolean is
8584 Typ : constant Entity_Id := Underlying_Type (T);
8587 -- Case of a private type which is not completed yet. This can only
8588 -- happen in the case of a generic format type appearing directly, or
8589 -- as a component of the type to which this function is being applied
8590 -- at the top level. Return False in this case, since we certainly do
8591 -- not know that the type contains access types.
8596 elsif Is_Access_Type (Typ) then
8599 elsif Is_Array_Type (Typ) then
8600 return Has_Access_Values (Component_Type (Typ));
8602 elsif Is_Record_Type (Typ) then
8607 -- Loop to Check components
8609 Comp := First_Component_Or_Discriminant (Typ);
8610 while Present (Comp) loop
8612 -- Check for access component, tag field does not count, even
8613 -- though it is implemented internally using an access type.
8615 if Has_Access_Values (Etype (Comp))
8616 and then Chars (Comp) /= Name_uTag
8621 Next_Component_Or_Discriminant (Comp);
8630 end Has_Access_Values;
8632 ------------------------------
8633 -- Has_Compatible_Alignment --
8634 ------------------------------
8636 function Has_Compatible_Alignment
8639 Layout_Done : Boolean) return Alignment_Result
8641 function Has_Compatible_Alignment_Internal
8644 Layout_Done : Boolean;
8645 Default : Alignment_Result) return Alignment_Result;
8646 -- This is the internal recursive function that actually does the work.
8647 -- There is one additional parameter, which says what the result should
8648 -- be if no alignment information is found, and there is no definite
8649 -- indication of compatible alignments. At the outer level, this is set
8650 -- to Unknown, but for internal recursive calls in the case where types
8651 -- are known to be correct, it is set to Known_Compatible.
8653 ---------------------------------------
8654 -- Has_Compatible_Alignment_Internal --
8655 ---------------------------------------
8657 function Has_Compatible_Alignment_Internal
8660 Layout_Done : Boolean;
8661 Default : Alignment_Result) return Alignment_Result
8663 Result : Alignment_Result := Known_Compatible;
8664 -- Holds the current status of the result. Note that once a value of
8665 -- Known_Incompatible is set, it is sticky and does not get changed
8666 -- to Unknown (the value in Result only gets worse as we go along,
8669 Offs : Uint := No_Uint;
8670 -- Set to a factor of the offset from the base object when Expr is a
8671 -- selected or indexed component, based on Component_Bit_Offset and
8672 -- Component_Size respectively. A negative value is used to represent
8673 -- a value which is not known at compile time.
8675 procedure Check_Prefix;
8676 -- Checks the prefix recursively in the case where the expression
8677 -- is an indexed or selected component.
8679 procedure Set_Result (R : Alignment_Result);
8680 -- If R represents a worse outcome (unknown instead of known
8681 -- compatible, or known incompatible), then set Result to R.
8687 procedure Check_Prefix is
8689 -- The subtlety here is that in doing a recursive call to check
8690 -- the prefix, we have to decide what to do in the case where we
8691 -- don't find any specific indication of an alignment problem.
8693 -- At the outer level, we normally set Unknown as the result in
8694 -- this case, since we can only set Known_Compatible if we really
8695 -- know that the alignment value is OK, but for the recursive
8696 -- call, in the case where the types match, and we have not
8697 -- specified a peculiar alignment for the object, we are only
8698 -- concerned about suspicious rep clauses, the default case does
8699 -- not affect us, since the compiler will, in the absence of such
8700 -- rep clauses, ensure that the alignment is correct.
8702 if Default = Known_Compatible
8704 (Etype (Obj) = Etype (Expr)
8705 and then (Unknown_Alignment (Obj)
8707 Alignment (Obj) = Alignment (Etype (Obj))))
8710 (Has_Compatible_Alignment_Internal
8711 (Obj, Prefix (Expr), Layout_Done, Known_Compatible));
8713 -- In all other cases, we need a full check on the prefix
8717 (Has_Compatible_Alignment_Internal
8718 (Obj, Prefix (Expr), Layout_Done, Unknown));
8726 procedure Set_Result (R : Alignment_Result) is
8733 -- Start of processing for Has_Compatible_Alignment_Internal
8736 -- If Expr is a selected component, we must make sure there is no
8737 -- potentially troublesome component clause and that the record is
8738 -- not packed if the layout is not done.
8740 if Nkind (Expr) = N_Selected_Component then
8742 -- Packing generates unknown alignment if layout is not done
8744 if Is_Packed (Etype (Prefix (Expr))) and then not Layout_Done then
8745 Set_Result (Unknown);
8748 -- Check prefix and component offset
8751 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
8753 -- If Expr is an indexed component, we must make sure there is no
8754 -- potentially troublesome Component_Size clause and that the array
8755 -- is not bit-packed if the layout is not done.
8757 elsif Nkind (Expr) = N_Indexed_Component then
8759 Typ : constant Entity_Id := Etype (Prefix (Expr));
8762 -- Packing generates unknown alignment if layout is not done
8764 if Is_Bit_Packed_Array (Typ) and then not Layout_Done then
8765 Set_Result (Unknown);
8768 -- Check prefix and component offset (or at least size)
8771 Offs := Indexed_Component_Bit_Offset (Expr);
8772 if Offs = No_Uint then
8773 Offs := Component_Size (Typ);
8778 -- If we have a null offset, the result is entirely determined by
8779 -- the base object and has already been computed recursively.
8781 if Offs = Uint_0 then
8784 -- Case where we know the alignment of the object
8786 elsif Known_Alignment (Obj) then
8788 ObjA : constant Uint := Alignment (Obj);
8789 ExpA : Uint := No_Uint;
8790 SizA : Uint := No_Uint;
8793 -- If alignment of Obj is 1, then we are always OK
8796 Set_Result (Known_Compatible);
8798 -- Alignment of Obj is greater than 1, so we need to check
8801 -- If we have an offset, see if it is compatible
8803 if Offs /= No_Uint and Offs > Uint_0 then
8804 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
8805 Set_Result (Known_Incompatible);
8808 -- See if Expr is an object with known alignment
8810 elsif Is_Entity_Name (Expr)
8811 and then Known_Alignment (Entity (Expr))
8813 ExpA := Alignment (Entity (Expr));
8815 -- Otherwise, we can use the alignment of the type of
8816 -- Expr given that we already checked for
8817 -- discombobulating rep clauses for the cases of indexed
8818 -- and selected components above.
8820 elsif Known_Alignment (Etype (Expr)) then
8821 ExpA := Alignment (Etype (Expr));
8823 -- Otherwise the alignment is unknown
8826 Set_Result (Default);
8829 -- If we got an alignment, see if it is acceptable
8831 if ExpA /= No_Uint and then ExpA < ObjA then
8832 Set_Result (Known_Incompatible);
8835 -- If Expr is not a piece of a larger object, see if size
8836 -- is given. If so, check that it is not too small for the
8837 -- required alignment.
8839 if Offs /= No_Uint then
8842 -- See if Expr is an object with known size
8844 elsif Is_Entity_Name (Expr)
8845 and then Known_Static_Esize (Entity (Expr))
8847 SizA := Esize (Entity (Expr));
8849 -- Otherwise, we check the object size of the Expr type
8851 elsif Known_Static_Esize (Etype (Expr)) then
8852 SizA := Esize (Etype (Expr));
8855 -- If we got a size, see if it is a multiple of the Obj
8856 -- alignment, if not, then the alignment cannot be
8857 -- acceptable, since the size is always a multiple of the
8860 if SizA /= No_Uint then
8861 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
8862 Set_Result (Known_Incompatible);
8868 -- If we do not know required alignment, any non-zero offset is a
8869 -- potential problem (but certainly may be OK, so result is unknown).
8871 elsif Offs /= No_Uint then
8872 Set_Result (Unknown);
8874 -- If we can't find the result by direct comparison of alignment
8875 -- values, then there is still one case that we can determine known
8876 -- result, and that is when we can determine that the types are the
8877 -- same, and no alignments are specified. Then we known that the
8878 -- alignments are compatible, even if we don't know the alignment
8879 -- value in the front end.
8881 elsif Etype (Obj) = Etype (Expr) then
8883 -- Types are the same, but we have to check for possible size
8884 -- and alignments on the Expr object that may make the alignment
8885 -- different, even though the types are the same.
8887 if Is_Entity_Name (Expr) then
8889 -- First check alignment of the Expr object. Any alignment less
8890 -- than Maximum_Alignment is worrisome since this is the case
8891 -- where we do not know the alignment of Obj.
8893 if Known_Alignment (Entity (Expr))
8894 and then UI_To_Int (Alignment (Entity (Expr))) <
8895 Ttypes.Maximum_Alignment
8897 Set_Result (Unknown);
8899 -- Now check size of Expr object. Any size that is not an
8900 -- even multiple of Maximum_Alignment is also worrisome
8901 -- since it may cause the alignment of the object to be less
8902 -- than the alignment of the type.
8904 elsif Known_Static_Esize (Entity (Expr))
8906 (UI_To_Int (Esize (Entity (Expr))) mod
8907 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
8910 Set_Result (Unknown);
8912 -- Otherwise same type is decisive
8915 Set_Result (Known_Compatible);
8919 -- Another case to deal with is when there is an explicit size or
8920 -- alignment clause when the types are not the same. If so, then the
8921 -- result is Unknown. We don't need to do this test if the Default is
8922 -- Unknown, since that result will be set in any case.
8924 elsif Default /= Unknown
8925 and then (Has_Size_Clause (Etype (Expr))
8927 Has_Alignment_Clause (Etype (Expr)))
8929 Set_Result (Unknown);
8931 -- If no indication found, set default
8934 Set_Result (Default);
8937 -- Return worst result found
8940 end Has_Compatible_Alignment_Internal;
8942 -- Start of processing for Has_Compatible_Alignment
8945 -- If Obj has no specified alignment, then set alignment from the type
8946 -- alignment. Perhaps we should always do this, but for sure we should
8947 -- do it when there is an address clause since we can do more if the
8948 -- alignment is known.
8950 if Unknown_Alignment (Obj) then
8951 Set_Alignment (Obj, Alignment (Etype (Obj)));
8954 -- Now do the internal call that does all the work
8957 Has_Compatible_Alignment_Internal (Obj, Expr, Layout_Done, Unknown);
8958 end Has_Compatible_Alignment;
8960 ----------------------
8961 -- Has_Declarations --
8962 ----------------------
8964 function Has_Declarations (N : Node_Id) return Boolean is
8966 return Nkind_In (Nkind (N), N_Accept_Statement,
8968 N_Compilation_Unit_Aux,
8974 N_Package_Specification);
8975 end Has_Declarations;
8977 ---------------------------------
8978 -- Has_Defaulted_Discriminants --
8979 ---------------------------------
8981 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
8983 return Has_Discriminants (Typ)
8984 and then Present (First_Discriminant (Typ))
8985 and then Present (Discriminant_Default_Value
8986 (First_Discriminant (Typ)));
8987 end Has_Defaulted_Discriminants;
8993 function Has_Denormals (E : Entity_Id) return Boolean is
8995 return Is_Floating_Point_Type (E) and then Denorm_On_Target;
8998 -------------------------------------------
8999 -- Has_Discriminant_Dependent_Constraint --
9000 -------------------------------------------
9002 function Has_Discriminant_Dependent_Constraint
9003 (Comp : Entity_Id) return Boolean
9005 Comp_Decl : constant Node_Id := Parent (Comp);
9006 Subt_Indic : Node_Id;
9011 -- Discriminants can't depend on discriminants
9013 if Ekind (Comp) = E_Discriminant then
9017 Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl));
9019 if Nkind (Subt_Indic) = N_Subtype_Indication then
9020 Constr := Constraint (Subt_Indic);
9022 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
9023 Assn := First (Constraints (Constr));
9024 while Present (Assn) loop
9025 case Nkind (Assn) is
9028 | N_Subtype_Indication
9030 if Depends_On_Discriminant (Assn) then
9034 when N_Discriminant_Association =>
9035 if Depends_On_Discriminant (Expression (Assn)) then
9050 end Has_Discriminant_Dependent_Constraint;
9052 --------------------------------------
9053 -- Has_Effectively_Volatile_Profile --
9054 --------------------------------------
9056 function Has_Effectively_Volatile_Profile
9057 (Subp_Id : Entity_Id) return Boolean
9062 -- Inspect the formal parameters looking for an effectively volatile
9065 Formal := First_Formal (Subp_Id);
9066 while Present (Formal) loop
9067 if Is_Effectively_Volatile (Etype (Formal)) then
9071 Next_Formal (Formal);
9074 -- Inspect the return type of functions
9076 if Ekind_In (Subp_Id, E_Function, E_Generic_Function)
9077 and then Is_Effectively_Volatile (Etype (Subp_Id))
9083 end Has_Effectively_Volatile_Profile;
9085 --------------------------
9086 -- Has_Enabled_Property --
9087 --------------------------
9089 function Has_Enabled_Property
9090 (Item_Id : Entity_Id;
9091 Property : Name_Id) return Boolean
9093 function Protected_Object_Has_Enabled_Property return Boolean;
9094 -- Determine whether a protected object denoted by Item_Id has the
9095 -- property enabled.
9097 function State_Has_Enabled_Property return Boolean;
9098 -- Determine whether a state denoted by Item_Id has the property enabled
9100 function Variable_Has_Enabled_Property return Boolean;
9101 -- Determine whether a variable denoted by Item_Id has the property
9104 -------------------------------------------
9105 -- Protected_Object_Has_Enabled_Property --
9106 -------------------------------------------
9108 function Protected_Object_Has_Enabled_Property return Boolean is
9109 Constits : constant Elist_Id := Part_Of_Constituents (Item_Id);
9110 Constit_Elmt : Elmt_Id;
9111 Constit_Id : Entity_Id;
9114 -- Protected objects always have the properties Async_Readers and
9115 -- Async_Writers (SPARK RM 7.1.2(16)).
9117 if Property = Name_Async_Readers
9118 or else Property = Name_Async_Writers
9122 -- Protected objects that have Part_Of components also inherit their
9123 -- properties Effective_Reads and Effective_Writes
9124 -- (SPARK RM 7.1.2(16)).
9126 elsif Present (Constits) then
9127 Constit_Elmt := First_Elmt (Constits);
9128 while Present (Constit_Elmt) loop
9129 Constit_Id := Node (Constit_Elmt);
9131 if Has_Enabled_Property (Constit_Id, Property) then
9135 Next_Elmt (Constit_Elmt);
9140 end Protected_Object_Has_Enabled_Property;
9142 --------------------------------
9143 -- State_Has_Enabled_Property --
9144 --------------------------------
9146 function State_Has_Enabled_Property return Boolean is
9147 Decl : constant Node_Id := Parent (Item_Id);
9155 -- The declaration of an external abstract state appears as an
9156 -- extension aggregate. If this is not the case, properties can never
9159 if Nkind (Decl) /= N_Extension_Aggregate then
9163 -- When External appears as a simple option, it automatically enables
9166 Opt := First (Expressions (Decl));
9167 while Present (Opt) loop
9168 if Nkind (Opt) = N_Identifier
9169 and then Chars (Opt) = Name_External
9177 -- When External specifies particular properties, inspect those and
9178 -- find the desired one (if any).
9180 Opt := First (Component_Associations (Decl));
9181 while Present (Opt) loop
9182 Opt_Nam := First (Choices (Opt));
9184 if Nkind (Opt_Nam) = N_Identifier
9185 and then Chars (Opt_Nam) = Name_External
9187 Props := Expression (Opt);
9189 -- Multiple properties appear as an aggregate
9191 if Nkind (Props) = N_Aggregate then
9193 -- Simple property form
9195 Prop := First (Expressions (Props));
9196 while Present (Prop) loop
9197 if Chars (Prop) = Property then
9204 -- Property with expression form
9206 Prop := First (Component_Associations (Props));
9207 while Present (Prop) loop
9208 Prop_Nam := First (Choices (Prop));
9210 -- The property can be represented in two ways:
9211 -- others => <value>
9212 -- <property> => <value>
9214 if Nkind (Prop_Nam) = N_Others_Choice
9215 or else (Nkind (Prop_Nam) = N_Identifier
9216 and then Chars (Prop_Nam) = Property)
9218 return Is_True (Expr_Value (Expression (Prop)));
9227 return Chars (Props) = Property;
9235 end State_Has_Enabled_Property;
9237 -----------------------------------
9238 -- Variable_Has_Enabled_Property --
9239 -----------------------------------
9241 function Variable_Has_Enabled_Property return Boolean is
9242 function Is_Enabled (Prag : Node_Id) return Boolean;
9243 -- Determine whether property pragma Prag (if present) denotes an
9244 -- enabled property.
9250 function Is_Enabled (Prag : Node_Id) return Boolean is
9254 if Present (Prag) then
9255 Arg1 := First (Pragma_Argument_Associations (Prag));
9257 -- The pragma has an optional Boolean expression, the related
9258 -- property is enabled only when the expression evaluates to
9261 if Present (Arg1) then
9262 return Is_True (Expr_Value (Get_Pragma_Arg (Arg1)));
9264 -- Otherwise the lack of expression enables the property by
9271 -- The property was never set in the first place
9280 AR : constant Node_Id :=
9281 Get_Pragma (Item_Id, Pragma_Async_Readers);
9282 AW : constant Node_Id :=
9283 Get_Pragma (Item_Id, Pragma_Async_Writers);
9284 ER : constant Node_Id :=
9285 Get_Pragma (Item_Id, Pragma_Effective_Reads);
9286 EW : constant Node_Id :=
9287 Get_Pragma (Item_Id, Pragma_Effective_Writes);
9289 -- Start of processing for Variable_Has_Enabled_Property
9292 -- A non-effectively volatile object can never possess external
9295 if not Is_Effectively_Volatile (Item_Id) then
9298 -- External properties related to variables come in two flavors -
9299 -- explicit and implicit. The explicit case is characterized by the
9300 -- presence of a property pragma with an optional Boolean flag. The
9301 -- property is enabled when the flag evaluates to True or the flag is
9302 -- missing altogether.
9304 elsif Property = Name_Async_Readers and then Is_Enabled (AR) then
9307 elsif Property = Name_Async_Writers and then Is_Enabled (AW) then
9310 elsif Property = Name_Effective_Reads and then Is_Enabled (ER) then
9313 elsif Property = Name_Effective_Writes and then Is_Enabled (EW) then
9316 -- The implicit case lacks all property pragmas
9318 elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then
9319 if Is_Protected_Type (Etype (Item_Id)) then
9320 return Protected_Object_Has_Enabled_Property;
9328 end Variable_Has_Enabled_Property;
9330 -- Start of processing for Has_Enabled_Property
9333 -- Abstract states and variables have a flexible scheme of specifying
9334 -- external properties.
9336 if Ekind (Item_Id) = E_Abstract_State then
9337 return State_Has_Enabled_Property;
9339 elsif Ekind (Item_Id) = E_Variable then
9340 return Variable_Has_Enabled_Property;
9342 -- By default, protected objects only have the properties Async_Readers
9343 -- and Async_Writers. If they have Part_Of components, they also inherit
9344 -- their properties Effective_Reads and Effective_Writes
9345 -- (SPARK RM 7.1.2(16)).
9347 elsif Ekind (Item_Id) = E_Protected_Object then
9348 return Protected_Object_Has_Enabled_Property;
9350 -- Otherwise a property is enabled when the related item is effectively
9354 return Is_Effectively_Volatile (Item_Id);
9356 end Has_Enabled_Property;
9358 -------------------------------------
9359 -- Has_Full_Default_Initialization --
9360 -------------------------------------
9362 function Has_Full_Default_Initialization (Typ : Entity_Id) return Boolean is
9367 -- A type subject to pragma Default_Initial_Condition is fully default
9368 -- initialized when the pragma appears with a non-null argument. Since
9369 -- any type may act as the full view of a private type, this check must
9370 -- be performed prior to the specialized tests below.
9372 if Has_DIC (Typ) then
9373 Prag := Get_Pragma (Typ, Pragma_Default_Initial_Condition);
9374 pragma Assert (Present (Prag));
9376 return Is_Verifiable_DIC_Pragma (Prag);
9379 -- A scalar type is fully default initialized if it is subject to aspect
9382 if Is_Scalar_Type (Typ) then
9383 return Has_Default_Aspect (Typ);
9385 -- An array type is fully default initialized if its element type is
9386 -- scalar and the array type carries aspect Default_Component_Value or
9387 -- the element type is fully default initialized.
9389 elsif Is_Array_Type (Typ) then
9391 Has_Default_Aspect (Typ)
9392 or else Has_Full_Default_Initialization (Component_Type (Typ));
9394 -- A protected type, record type, or type extension is fully default
9395 -- initialized if all its components either carry an initialization
9396 -- expression or have a type that is fully default initialized. The
9397 -- parent type of a type extension must be fully default initialized.
9399 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
9401 -- Inspect all entities defined in the scope of the type, looking for
9402 -- uninitialized components.
9404 Comp := First_Entity (Typ);
9405 while Present (Comp) loop
9406 if Ekind (Comp) = E_Component
9407 and then Comes_From_Source (Comp)
9408 and then No (Expression (Parent (Comp)))
9409 and then not Has_Full_Default_Initialization (Etype (Comp))
9417 -- Ensure that the parent type of a type extension is fully default
9420 if Etype (Typ) /= Typ
9421 and then not Has_Full_Default_Initialization (Etype (Typ))
9426 -- If we get here, then all components and parent portion are fully
9427 -- default initialized.
9431 -- A task type is fully default initialized by default
9433 elsif Is_Task_Type (Typ) then
9436 -- Otherwise the type is not fully default initialized
9441 end Has_Full_Default_Initialization;
9443 --------------------
9444 -- Has_Infinities --
9445 --------------------
9447 function Has_Infinities (E : Entity_Id) return Boolean is
9450 Is_Floating_Point_Type (E)
9451 and then Nkind (Scalar_Range (E)) = N_Range
9452 and then Includes_Infinities (Scalar_Range (E));
9455 --------------------
9456 -- Has_Interfaces --
9457 --------------------
9459 function Has_Interfaces
9461 Use_Full_View : Boolean := True) return Boolean
9463 Typ : Entity_Id := Base_Type (T);
9466 -- Handle concurrent types
9468 if Is_Concurrent_Type (Typ) then
9469 Typ := Corresponding_Record_Type (Typ);
9472 if not Present (Typ)
9473 or else not Is_Record_Type (Typ)
9474 or else not Is_Tagged_Type (Typ)
9479 -- Handle private types
9481 if Use_Full_View and then Present (Full_View (Typ)) then
9482 Typ := Full_View (Typ);
9485 -- Handle concurrent record types
9487 if Is_Concurrent_Record_Type (Typ)
9488 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
9494 if Is_Interface (Typ)
9496 (Is_Record_Type (Typ)
9497 and then Present (Interfaces (Typ))
9498 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
9503 exit when Etype (Typ) = Typ
9505 -- Handle private types
9507 or else (Present (Full_View (Etype (Typ)))
9508 and then Full_View (Etype (Typ)) = Typ)
9510 -- Protect frontend against wrong sources with cyclic derivations
9512 or else Etype (Typ) = T;
9514 -- Climb to the ancestor type handling private types
9516 if Present (Full_View (Etype (Typ))) then
9517 Typ := Full_View (Etype (Typ));
9526 --------------------------
9527 -- Has_Max_Queue_Length --
9528 --------------------------
9530 function Has_Max_Queue_Length (Id : Entity_Id) return Boolean is
9533 Ekind (Id) = E_Entry
9534 and then Present (Get_Pragma (Id, Pragma_Max_Queue_Length));
9535 end Has_Max_Queue_Length;
9537 ---------------------------------
9538 -- Has_No_Obvious_Side_Effects --
9539 ---------------------------------
9541 function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
9543 -- For now handle literals, constants, and non-volatile variables and
9544 -- expressions combining these with operators or short circuit forms.
9546 if Nkind (N) in N_Numeric_Or_String_Literal then
9549 elsif Nkind (N) = N_Character_Literal then
9552 elsif Nkind (N) in N_Unary_Op then
9553 return Has_No_Obvious_Side_Effects (Right_Opnd (N));
9555 elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
9556 return Has_No_Obvious_Side_Effects (Left_Opnd (N))
9558 Has_No_Obvious_Side_Effects (Right_Opnd (N));
9560 elsif Nkind (N) = N_Expression_With_Actions
9561 and then Is_Empty_List (Actions (N))
9563 return Has_No_Obvious_Side_Effects (Expression (N));
9565 elsif Nkind (N) in N_Has_Entity then
9566 return Present (Entity (N))
9567 and then Ekind_In (Entity (N), E_Variable,
9569 E_Enumeration_Literal,
9573 and then not Is_Volatile (Entity (N));
9578 end Has_No_Obvious_Side_Effects;
9580 -----------------------------
9581 -- Has_Non_Null_Refinement --
9582 -----------------------------
9584 function Has_Non_Null_Refinement (Id : Entity_Id) return Boolean is
9585 Constits : Elist_Id;
9588 pragma Assert (Ekind (Id) = E_Abstract_State);
9589 Constits := Refinement_Constituents (Id);
9591 -- For a refinement to be non-null, the first constituent must be
9592 -- anything other than null.
9596 and then Nkind (Node (First_Elmt (Constits))) /= N_Null;
9597 end Has_Non_Null_Refinement;
9603 function Has_Null_Body (Proc_Id : Entity_Id) return Boolean is
9604 Body_Id : Entity_Id;
9611 Spec := Parent (Proc_Id);
9612 Decl := Parent (Spec);
9614 -- Retrieve the entity of the procedure body (e.g. invariant proc).
9616 if Nkind (Spec) = N_Procedure_Specification
9617 and then Nkind (Decl) = N_Subprogram_Declaration
9619 Body_Id := Corresponding_Body (Decl);
9621 -- The body acts as a spec
9627 -- The body will be generated later
9629 if No (Body_Id) then
9633 Spec := Parent (Body_Id);
9634 Decl := Parent (Spec);
9637 (Nkind (Spec) = N_Procedure_Specification
9638 and then Nkind (Decl) = N_Subprogram_Body);
9640 Stmt1 := First (Statements (Handled_Statement_Sequence (Decl)));
9642 -- Look for a null statement followed by an optional return
9645 if Nkind (Stmt1) = N_Null_Statement then
9646 Stmt2 := Next (Stmt1);
9648 if Present (Stmt2) then
9649 return Nkind (Stmt2) = N_Simple_Return_Statement;
9658 ------------------------
9659 -- Has_Null_Exclusion --
9660 ------------------------
9662 function Has_Null_Exclusion (N : Node_Id) return Boolean is
9665 when N_Access_Definition
9666 | N_Access_Function_Definition
9667 | N_Access_Procedure_Definition
9668 | N_Access_To_Object_Definition
9670 | N_Derived_Type_Definition
9671 | N_Function_Specification
9672 | N_Subtype_Declaration
9674 return Null_Exclusion_Present (N);
9676 when N_Component_Definition
9677 | N_Formal_Object_Declaration
9678 | N_Object_Renaming_Declaration
9680 if Present (Subtype_Mark (N)) then
9681 return Null_Exclusion_Present (N);
9682 else pragma Assert (Present (Access_Definition (N)));
9683 return Null_Exclusion_Present (Access_Definition (N));
9686 when N_Discriminant_Specification =>
9687 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
9688 return Null_Exclusion_Present (Discriminant_Type (N));
9690 return Null_Exclusion_Present (N);
9693 when N_Object_Declaration =>
9694 if Nkind (Object_Definition (N)) = N_Access_Definition then
9695 return Null_Exclusion_Present (Object_Definition (N));
9697 return Null_Exclusion_Present (N);
9700 when N_Parameter_Specification =>
9701 if Nkind (Parameter_Type (N)) = N_Access_Definition then
9702 return Null_Exclusion_Present (Parameter_Type (N));
9704 return Null_Exclusion_Present (N);
9710 end Has_Null_Exclusion;
9712 ------------------------
9713 -- Has_Null_Extension --
9714 ------------------------
9716 function Has_Null_Extension (T : Entity_Id) return Boolean is
9717 B : constant Entity_Id := Base_Type (T);
9722 if Nkind (Parent (B)) = N_Full_Type_Declaration
9723 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
9725 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
9727 if Present (Ext) then
9728 if Null_Present (Ext) then
9731 Comps := Component_List (Ext);
9733 -- The null component list is rewritten during analysis to
9734 -- include the parent component. Any other component indicates
9735 -- that the extension was not originally null.
9737 return Null_Present (Comps)
9738 or else No (Next (First (Component_Items (Comps))));
9747 end Has_Null_Extension;
9749 -------------------------
9750 -- Has_Null_Refinement --
9751 -------------------------
9753 function Has_Null_Refinement (Id : Entity_Id) return Boolean is
9754 Constits : Elist_Id;
9757 pragma Assert (Ekind (Id) = E_Abstract_State);
9758 Constits := Refinement_Constituents (Id);
9760 -- For a refinement to be null, the state's sole constituent must be a
9765 and then Nkind (Node (First_Elmt (Constits))) = N_Null;
9766 end Has_Null_Refinement;
9768 -------------------------------
9769 -- Has_Overriding_Initialize --
9770 -------------------------------
9772 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
9773 BT : constant Entity_Id := Base_Type (T);
9777 if Is_Controlled (BT) then
9778 if Is_RTU (Scope (BT), Ada_Finalization) then
9781 elsif Present (Primitive_Operations (BT)) then
9782 P := First_Elmt (Primitive_Operations (BT));
9783 while Present (P) loop
9785 Init : constant Entity_Id := Node (P);
9786 Formal : constant Entity_Id := First_Formal (Init);
9788 if Ekind (Init) = E_Procedure
9789 and then Chars (Init) = Name_Initialize
9790 and then Comes_From_Source (Init)
9791 and then Present (Formal)
9792 and then Etype (Formal) = BT
9793 and then No (Next_Formal (Formal))
9794 and then (Ada_Version < Ada_2012
9795 or else not Null_Present (Parent (Init)))
9805 -- Here if type itself does not have a non-null Initialize operation:
9806 -- check immediate ancestor.
9808 if Is_Derived_Type (BT)
9809 and then Has_Overriding_Initialize (Etype (BT))
9816 end Has_Overriding_Initialize;
9818 --------------------------------------
9819 -- Has_Preelaborable_Initialization --
9820 --------------------------------------
9822 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
9825 procedure Check_Components (E : Entity_Id);
9826 -- Check component/discriminant chain, sets Has_PE False if a component
9827 -- or discriminant does not meet the preelaborable initialization rules.
9829 ----------------------
9830 -- Check_Components --
9831 ----------------------
9833 procedure Check_Components (E : Entity_Id) is
9837 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
9838 -- Returns True if and only if the expression denoted by N does not
9839 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
9841 ---------------------------------
9842 -- Is_Preelaborable_Expression --
9843 ---------------------------------
9845 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
9849 Comp_Type : Entity_Id;
9850 Is_Array_Aggr : Boolean;
9853 if Is_OK_Static_Expression (N) then
9856 elsif Nkind (N) = N_Null then
9859 -- Attributes are allowed in general, even if their prefix is a
9860 -- formal type. (It seems that certain attributes known not to be
9861 -- static might not be allowed, but there are no rules to prevent
9864 elsif Nkind (N) = N_Attribute_Reference then
9867 -- The name of a discriminant evaluated within its parent type is
9868 -- defined to be preelaborable (10.2.1(8)). Note that we test for
9869 -- names that denote discriminals as well as discriminants to
9870 -- catch references occurring within init procs.
9872 elsif Is_Entity_Name (N)
9874 (Ekind (Entity (N)) = E_Discriminant
9875 or else (Ekind_In (Entity (N), E_Constant, E_In_Parameter)
9876 and then Present (Discriminal_Link (Entity (N)))))
9880 elsif Nkind (N) = N_Qualified_Expression then
9881 return Is_Preelaborable_Expression (Expression (N));
9883 -- For aggregates we have to check that each of the associations
9884 -- is preelaborable.
9886 elsif Nkind_In (N, N_Aggregate, N_Extension_Aggregate) then
9887 Is_Array_Aggr := Is_Array_Type (Etype (N));
9889 if Is_Array_Aggr then
9890 Comp_Type := Component_Type (Etype (N));
9893 -- Check the ancestor part of extension aggregates, which must
9894 -- be either the name of a type that has preelaborable init or
9895 -- an expression that is preelaborable.
9897 if Nkind (N) = N_Extension_Aggregate then
9899 Anc_Part : constant Node_Id := Ancestor_Part (N);
9902 if Is_Entity_Name (Anc_Part)
9903 and then Is_Type (Entity (Anc_Part))
9905 if not Has_Preelaborable_Initialization
9911 elsif not Is_Preelaborable_Expression (Anc_Part) then
9917 -- Check positional associations
9919 Exp := First (Expressions (N));
9920 while Present (Exp) loop
9921 if not Is_Preelaborable_Expression (Exp) then
9928 -- Check named associations
9930 Assn := First (Component_Associations (N));
9931 while Present (Assn) loop
9932 Choice := First (Choices (Assn));
9933 while Present (Choice) loop
9934 if Is_Array_Aggr then
9935 if Nkind (Choice) = N_Others_Choice then
9938 elsif Nkind (Choice) = N_Range then
9939 if not Is_OK_Static_Range (Choice) then
9943 elsif not Is_OK_Static_Expression (Choice) then
9948 Comp_Type := Etype (Choice);
9954 -- If the association has a <> at this point, then we have
9955 -- to check whether the component's type has preelaborable
9956 -- initialization. Note that this only occurs when the
9957 -- association's corresponding component does not have a
9958 -- default expression, the latter case having already been
9959 -- expanded as an expression for the association.
9961 if Box_Present (Assn) then
9962 if not Has_Preelaborable_Initialization (Comp_Type) then
9966 -- In the expression case we check whether the expression
9967 -- is preelaborable.
9970 not Is_Preelaborable_Expression (Expression (Assn))
9978 -- If we get here then aggregate as a whole is preelaborable
9982 -- All other cases are not preelaborable
9987 end Is_Preelaborable_Expression;
9989 -- Start of processing for Check_Components
9992 -- Loop through entities of record or protected type
9995 while Present (Ent) loop
9997 -- We are interested only in components and discriminants
10001 case Ekind (Ent) is
10002 when E_Component =>
10004 -- Get default expression if any. If there is no declaration
10005 -- node, it means we have an internal entity. The parent and
10006 -- tag fields are examples of such entities. For such cases,
10007 -- we just test the type of the entity.
10009 if Present (Declaration_Node (Ent)) then
10010 Exp := Expression (Declaration_Node (Ent));
10013 when E_Discriminant =>
10015 -- Note: for a renamed discriminant, the Declaration_Node
10016 -- may point to the one from the ancestor, and have a
10017 -- different expression, so use the proper attribute to
10018 -- retrieve the expression from the derived constraint.
10020 Exp := Discriminant_Default_Value (Ent);
10023 goto Check_Next_Entity;
10026 -- A component has PI if it has no default expression and the
10027 -- component type has PI.
10030 if not Has_Preelaborable_Initialization (Etype (Ent)) then
10035 -- Require the default expression to be preelaborable
10037 elsif not Is_Preelaborable_Expression (Exp) then
10042 <<Check_Next_Entity>>
10045 end Check_Components;
10047 -- Start of processing for Has_Preelaborable_Initialization
10050 -- Immediate return if already marked as known preelaborable init. This
10051 -- covers types for which this function has already been called once
10052 -- and returned True (in which case the result is cached), and also
10053 -- types to which a pragma Preelaborable_Initialization applies.
10055 if Known_To_Have_Preelab_Init (E) then
10059 -- If the type is a subtype representing a generic actual type, then
10060 -- test whether its base type has preelaborable initialization since
10061 -- the subtype representing the actual does not inherit this attribute
10062 -- from the actual or formal. (but maybe it should???)
10064 if Is_Generic_Actual_Type (E) then
10065 return Has_Preelaborable_Initialization (Base_Type (E));
10068 -- All elementary types have preelaborable initialization
10070 if Is_Elementary_Type (E) then
10073 -- Array types have PI if the component type has PI
10075 elsif Is_Array_Type (E) then
10076 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
10078 -- A derived type has preelaborable initialization if its parent type
10079 -- has preelaborable initialization and (in the case of a derived record
10080 -- extension) if the non-inherited components all have preelaborable
10081 -- initialization. However, a user-defined controlled type with an
10082 -- overriding Initialize procedure does not have preelaborable
10085 elsif Is_Derived_Type (E) then
10087 -- If the derived type is a private extension then it doesn't have
10088 -- preelaborable initialization.
10090 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
10094 -- First check whether ancestor type has preelaborable initialization
10096 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
10098 -- If OK, check extension components (if any)
10100 if Has_PE and then Is_Record_Type (E) then
10101 Check_Components (First_Entity (E));
10104 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
10105 -- with a user defined Initialize procedure does not have PI. If
10106 -- the type is untagged, the control primitives come from a component
10107 -- that has already been checked.
10110 and then Is_Controlled (E)
10111 and then Is_Tagged_Type (E)
10112 and then Has_Overriding_Initialize (E)
10117 -- Private types not derived from a type having preelaborable init and
10118 -- that are not marked with pragma Preelaborable_Initialization do not
10119 -- have preelaborable initialization.
10121 elsif Is_Private_Type (E) then
10124 -- Record type has PI if it is non private and all components have PI
10126 elsif Is_Record_Type (E) then
10128 Check_Components (First_Entity (E));
10130 -- Protected types must not have entries, and components must meet
10131 -- same set of rules as for record components.
10133 elsif Is_Protected_Type (E) then
10134 if Has_Entries (E) then
10138 Check_Components (First_Entity (E));
10139 Check_Components (First_Private_Entity (E));
10142 -- Type System.Address always has preelaborable initialization
10144 elsif Is_RTE (E, RE_Address) then
10147 -- In all other cases, type does not have preelaborable initialization
10153 -- If type has preelaborable initialization, cache result
10156 Set_Known_To_Have_Preelab_Init (E);
10160 end Has_Preelaborable_Initialization;
10162 ---------------------------
10163 -- Has_Private_Component --
10164 ---------------------------
10166 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
10167 Btype : Entity_Id := Base_Type (Type_Id);
10168 Component : Entity_Id;
10171 if Error_Posted (Type_Id)
10172 or else Error_Posted (Btype)
10177 if Is_Class_Wide_Type (Btype) then
10178 Btype := Root_Type (Btype);
10181 if Is_Private_Type (Btype) then
10183 UT : constant Entity_Id := Underlying_Type (Btype);
10186 if No (Full_View (Btype)) then
10187 return not Is_Generic_Type (Btype)
10189 not Is_Generic_Type (Root_Type (Btype));
10191 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
10194 return not Is_Frozen (UT) and then Has_Private_Component (UT);
10198 elsif Is_Array_Type (Btype) then
10199 return Has_Private_Component (Component_Type (Btype));
10201 elsif Is_Record_Type (Btype) then
10202 Component := First_Component (Btype);
10203 while Present (Component) loop
10204 if Has_Private_Component (Etype (Component)) then
10208 Next_Component (Component);
10213 elsif Is_Protected_Type (Btype)
10214 and then Present (Corresponding_Record_Type (Btype))
10216 return Has_Private_Component (Corresponding_Record_Type (Btype));
10221 end Has_Private_Component;
10223 ----------------------
10224 -- Has_Signed_Zeros --
10225 ----------------------
10227 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
10229 return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target;
10230 end Has_Signed_Zeros;
10232 ------------------------------
10233 -- Has_Significant_Contract --
10234 ------------------------------
10236 function Has_Significant_Contract (Subp_Id : Entity_Id) return Boolean is
10237 Subp_Nam : constant Name_Id := Chars (Subp_Id);
10240 -- _Finalizer procedure
10242 if Subp_Nam = Name_uFinalizer then
10245 -- _Postconditions procedure
10247 elsif Subp_Nam = Name_uPostconditions then
10250 -- Predicate function
10252 elsif Ekind (Subp_Id) = E_Function
10253 and then Is_Predicate_Function (Subp_Id)
10259 elsif Get_TSS_Name (Subp_Id) /= TSS_Null then
10265 end Has_Significant_Contract;
10267 -----------------------------
10268 -- Has_Static_Array_Bounds --
10269 -----------------------------
10271 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
10272 Ndims : constant Nat := Number_Dimensions (Typ);
10279 -- Unconstrained types do not have static bounds
10281 if not Is_Constrained (Typ) then
10285 -- First treat string literals specially, as the lower bound and length
10286 -- of string literals are not stored like those of arrays.
10288 -- A string literal always has static bounds
10290 if Ekind (Typ) = E_String_Literal_Subtype then
10294 -- Treat all dimensions in turn
10296 Index := First_Index (Typ);
10297 for Indx in 1 .. Ndims loop
10299 -- In case of an illegal index which is not a discrete type, return
10300 -- that the type is not static.
10302 if not Is_Discrete_Type (Etype (Index))
10303 or else Etype (Index) = Any_Type
10308 Get_Index_Bounds (Index, Low, High);
10310 if Error_Posted (Low) or else Error_Posted (High) then
10314 if Is_OK_Static_Expression (Low)
10316 Is_OK_Static_Expression (High)
10326 -- If we fall through the loop, all indexes matched
10329 end Has_Static_Array_Bounds;
10335 function Has_Stream (T : Entity_Id) return Boolean is
10342 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
10345 elsif Is_Array_Type (T) then
10346 return Has_Stream (Component_Type (T));
10348 elsif Is_Record_Type (T) then
10349 E := First_Component (T);
10350 while Present (E) loop
10351 if Has_Stream (Etype (E)) then
10354 Next_Component (E);
10360 elsif Is_Private_Type (T) then
10361 return Has_Stream (Underlying_Type (T));
10372 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
10374 Get_Name_String (Chars (E));
10375 return Name_Buffer (Name_Len) = Suffix;
10382 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
10384 Get_Name_String (Chars (E));
10385 Add_Char_To_Name_Buffer (Suffix);
10389 -------------------
10390 -- Remove_Suffix --
10391 -------------------
10393 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
10395 pragma Assert (Has_Suffix (E, Suffix));
10396 Get_Name_String (Chars (E));
10397 Name_Len := Name_Len - 1;
10401 ----------------------------------
10402 -- Replace_Null_By_Null_Address --
10403 ----------------------------------
10405 procedure Replace_Null_By_Null_Address (N : Node_Id) is
10406 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id);
10407 -- Replace operand Op with a reference to Null_Address when the operand
10408 -- denotes a null Address. Other_Op denotes the other operand.
10410 --------------------------
10411 -- Replace_Null_Operand --
10412 --------------------------
10414 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id) is
10416 -- Check the type of the complementary operand since the N_Null node
10417 -- has not been decorated yet.
10419 if Nkind (Op) = N_Null
10420 and then Is_Descendant_Of_Address (Etype (Other_Op))
10422 Rewrite (Op, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (Op)));
10424 end Replace_Null_Operand;
10426 -- Start of processing for Replace_Null_By_Null_Address
10429 pragma Assert (Relaxed_RM_Semantics);
10430 pragma Assert (Nkind_In (N, N_Null,
10438 if Nkind (N) = N_Null then
10439 Rewrite (N, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (N)));
10443 L : constant Node_Id := Left_Opnd (N);
10444 R : constant Node_Id := Right_Opnd (N);
10447 Replace_Null_Operand (L, Other_Op => R);
10448 Replace_Null_Operand (R, Other_Op => L);
10451 end Replace_Null_By_Null_Address;
10453 --------------------------
10454 -- Has_Tagged_Component --
10455 --------------------------
10457 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
10461 if Is_Private_Type (Typ) and then Present (Underlying_Type (Typ)) then
10462 return Has_Tagged_Component (Underlying_Type (Typ));
10464 elsif Is_Array_Type (Typ) then
10465 return Has_Tagged_Component (Component_Type (Typ));
10467 elsif Is_Tagged_Type (Typ) then
10470 elsif Is_Record_Type (Typ) then
10471 Comp := First_Component (Typ);
10472 while Present (Comp) loop
10473 if Has_Tagged_Component (Etype (Comp)) then
10477 Next_Component (Comp);
10485 end Has_Tagged_Component;
10487 -----------------------------
10488 -- Has_Undefined_Reference --
10489 -----------------------------
10491 function Has_Undefined_Reference (Expr : Node_Id) return Boolean is
10492 Has_Undef_Ref : Boolean := False;
10493 -- Flag set when expression Expr contains at least one undefined
10496 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result;
10497 -- Determine whether N denotes a reference and if it does, whether it is
10500 ----------------------------
10501 -- Is_Undefined_Reference --
10502 ----------------------------
10504 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result is
10506 if Is_Entity_Name (N)
10507 and then Present (Entity (N))
10508 and then Entity (N) = Any_Id
10510 Has_Undef_Ref := True;
10515 end Is_Undefined_Reference;
10517 procedure Find_Undefined_References is
10518 new Traverse_Proc (Is_Undefined_Reference);
10520 -- Start of processing for Has_Undefined_Reference
10523 Find_Undefined_References (Expr);
10525 return Has_Undef_Ref;
10526 end Has_Undefined_Reference;
10528 ----------------------------
10529 -- Has_Volatile_Component --
10530 ----------------------------
10532 function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
10536 if Has_Volatile_Components (Typ) then
10539 elsif Is_Array_Type (Typ) then
10540 return Is_Volatile (Component_Type (Typ));
10542 elsif Is_Record_Type (Typ) then
10543 Comp := First_Component (Typ);
10544 while Present (Comp) loop
10545 if Is_Volatile_Object (Comp) then
10549 Comp := Next_Component (Comp);
10554 end Has_Volatile_Component;
10556 -------------------------
10557 -- Implementation_Kind --
10558 -------------------------
10560 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
10561 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
10564 pragma Assert (Present (Impl_Prag));
10565 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
10566 return Chars (Get_Pragma_Arg (Arg));
10567 end Implementation_Kind;
10569 --------------------------
10570 -- Implements_Interface --
10571 --------------------------
10573 function Implements_Interface
10574 (Typ_Ent : Entity_Id;
10575 Iface_Ent : Entity_Id;
10576 Exclude_Parents : Boolean := False) return Boolean
10578 Ifaces_List : Elist_Id;
10580 Iface : Entity_Id := Base_Type (Iface_Ent);
10581 Typ : Entity_Id := Base_Type (Typ_Ent);
10584 if Is_Class_Wide_Type (Typ) then
10585 Typ := Root_Type (Typ);
10588 if not Has_Interfaces (Typ) then
10592 if Is_Class_Wide_Type (Iface) then
10593 Iface := Root_Type (Iface);
10596 Collect_Interfaces (Typ, Ifaces_List);
10598 Elmt := First_Elmt (Ifaces_List);
10599 while Present (Elmt) loop
10600 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
10601 and then Exclude_Parents
10605 elsif Node (Elmt) = Iface then
10613 end Implements_Interface;
10615 ------------------------------------
10616 -- In_Assertion_Expression_Pragma --
10617 ------------------------------------
10619 function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is
10621 Prag : Node_Id := Empty;
10624 -- Climb the parent chain looking for an enclosing pragma
10627 while Present (Par) loop
10628 if Nkind (Par) = N_Pragma then
10632 -- Precondition-like pragmas are expanded into if statements, check
10633 -- the original node instead.
10635 elsif Nkind (Original_Node (Par)) = N_Pragma then
10636 Prag := Original_Node (Par);
10639 -- The expansion of attribute 'Old generates a constant to capture
10640 -- the result of the prefix. If the parent traversal reaches
10641 -- one of these constants, then the node technically came from a
10642 -- postcondition-like pragma. Note that the Ekind is not tested here
10643 -- because N may be the expression of an object declaration which is
10644 -- currently being analyzed. Such objects carry Ekind of E_Void.
10646 elsif Nkind (Par) = N_Object_Declaration
10647 and then Constant_Present (Par)
10648 and then Stores_Attribute_Old_Prefix (Defining_Entity (Par))
10652 -- Prevent the search from going too far
10654 elsif Is_Body_Or_Package_Declaration (Par) then
10658 Par := Parent (Par);
10663 and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag));
10664 end In_Assertion_Expression_Pragma;
10666 ----------------------
10667 -- In_Generic_Scope --
10668 ----------------------
10670 function In_Generic_Scope (E : Entity_Id) return Boolean is
10675 while Present (S) and then S /= Standard_Standard loop
10676 if Is_Generic_Unit (S) then
10684 end In_Generic_Scope;
10690 function In_Instance return Boolean is
10691 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
10695 S := Current_Scope;
10696 while Present (S) and then S /= Standard_Standard loop
10697 if Ekind_In (S, E_Function, E_Package, E_Procedure)
10698 and then Is_Generic_Instance (S)
10700 -- A child instance is always compiled in the context of a parent
10701 -- instance. Nevertheless, the actuals are not analyzed in an
10702 -- instance context. We detect this case by examining the current
10703 -- compilation unit, which must be a child instance, and checking
10704 -- that it is not currently on the scope stack.
10706 if Is_Child_Unit (Curr_Unit)
10707 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
10708 N_Package_Instantiation
10709 and then not In_Open_Scopes (Curr_Unit)
10723 ----------------------
10724 -- In_Instance_Body --
10725 ----------------------
10727 function In_Instance_Body return Boolean is
10731 S := Current_Scope;
10732 while Present (S) and then S /= Standard_Standard loop
10733 if Ekind_In (S, E_Function, E_Procedure)
10734 and then Is_Generic_Instance (S)
10738 elsif Ekind (S) = E_Package
10739 and then In_Package_Body (S)
10740 and then Is_Generic_Instance (S)
10749 end In_Instance_Body;
10751 -----------------------------
10752 -- In_Instance_Not_Visible --
10753 -----------------------------
10755 function In_Instance_Not_Visible return Boolean is
10759 S := Current_Scope;
10760 while Present (S) and then S /= Standard_Standard loop
10761 if Ekind_In (S, E_Function, E_Procedure)
10762 and then Is_Generic_Instance (S)
10766 elsif Ekind (S) = E_Package
10767 and then (In_Package_Body (S) or else In_Private_Part (S))
10768 and then Is_Generic_Instance (S)
10777 end In_Instance_Not_Visible;
10779 ------------------------------
10780 -- In_Instance_Visible_Part --
10781 ------------------------------
10783 function In_Instance_Visible_Part return Boolean is
10787 S := Current_Scope;
10788 while Present (S) and then S /= Standard_Standard loop
10789 if Ekind (S) = E_Package
10790 and then Is_Generic_Instance (S)
10791 and then not In_Package_Body (S)
10792 and then not In_Private_Part (S)
10801 end In_Instance_Visible_Part;
10803 ---------------------
10804 -- In_Package_Body --
10805 ---------------------
10807 function In_Package_Body return Boolean is
10811 S := Current_Scope;
10812 while Present (S) and then S /= Standard_Standard loop
10813 if Ekind (S) = E_Package and then In_Package_Body (S) then
10821 end In_Package_Body;
10823 --------------------------------
10824 -- In_Parameter_Specification --
10825 --------------------------------
10827 function In_Parameter_Specification (N : Node_Id) return Boolean is
10832 while Present (PN) loop
10833 if Nkind (PN) = N_Parameter_Specification then
10841 end In_Parameter_Specification;
10843 --------------------------
10844 -- In_Pragma_Expression --
10845 --------------------------
10847 function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean is
10854 elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
10860 end In_Pragma_Expression;
10862 ---------------------------
10863 -- In_Pre_Post_Condition --
10864 ---------------------------
10866 function In_Pre_Post_Condition (N : Node_Id) return Boolean is
10868 Prag : Node_Id := Empty;
10869 Prag_Id : Pragma_Id;
10872 -- Climb the parent chain looking for an enclosing pragma
10875 while Present (Par) loop
10876 if Nkind (Par) = N_Pragma then
10880 -- Prevent the search from going too far
10882 elsif Is_Body_Or_Package_Declaration (Par) then
10886 Par := Parent (Par);
10889 if Present (Prag) then
10890 Prag_Id := Get_Pragma_Id (Prag);
10893 Prag_Id = Pragma_Post
10894 or else Prag_Id = Pragma_Post_Class
10895 or else Prag_Id = Pragma_Postcondition
10896 or else Prag_Id = Pragma_Pre
10897 or else Prag_Id = Pragma_Pre_Class
10898 or else Prag_Id = Pragma_Precondition;
10900 -- Otherwise the node is not enclosed by a pre/postcondition pragma
10905 end In_Pre_Post_Condition;
10907 -------------------------------------
10908 -- In_Reverse_Storage_Order_Object --
10909 -------------------------------------
10911 function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
10913 Btyp : Entity_Id := Empty;
10916 -- Climb up indexed components
10920 case Nkind (Pref) is
10921 when N_Selected_Component =>
10922 Pref := Prefix (Pref);
10925 when N_Indexed_Component =>
10926 Pref := Prefix (Pref);
10934 if Present (Pref) then
10935 Btyp := Base_Type (Etype (Pref));
10938 return Present (Btyp)
10939 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
10940 and then Reverse_Storage_Order (Btyp);
10941 end In_Reverse_Storage_Order_Object;
10943 --------------------------------------
10944 -- In_Subprogram_Or_Concurrent_Unit --
10945 --------------------------------------
10947 function In_Subprogram_Or_Concurrent_Unit return Boolean is
10952 -- Use scope chain to check successively outer scopes
10954 E := Current_Scope;
10958 if K in Subprogram_Kind
10959 or else K in Concurrent_Kind
10960 or else K in Generic_Subprogram_Kind
10964 elsif E = Standard_Standard then
10970 end In_Subprogram_Or_Concurrent_Unit;
10972 ---------------------
10973 -- In_Visible_Part --
10974 ---------------------
10976 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
10978 return Is_Package_Or_Generic_Package (Scope_Id)
10979 and then In_Open_Scopes (Scope_Id)
10980 and then not In_Package_Body (Scope_Id)
10981 and then not In_Private_Part (Scope_Id);
10982 end In_Visible_Part;
10984 --------------------------------
10985 -- Incomplete_Or_Partial_View --
10986 --------------------------------
10988 function Incomplete_Or_Partial_View (Id : Entity_Id) return Entity_Id is
10989 function Inspect_Decls
10991 Taft : Boolean := False) return Entity_Id;
10992 -- Check whether a declarative region contains the incomplete or partial
10995 -------------------
10996 -- Inspect_Decls --
10997 -------------------
10999 function Inspect_Decls
11001 Taft : Boolean := False) return Entity_Id
11007 Decl := First (Decls);
11008 while Present (Decl) loop
11011 -- The partial view of a Taft-amendment type is an incomplete
11015 if Nkind (Decl) = N_Incomplete_Type_Declaration then
11016 Match := Defining_Identifier (Decl);
11019 -- Otherwise look for a private type whose full view matches the
11020 -- input type. Note that this checks full_type_declaration nodes
11021 -- to account for derivations from a private type where the type
11022 -- declaration hold the partial view and the full view is an
11025 elsif Nkind_In (Decl, N_Full_Type_Declaration,
11026 N_Private_Extension_Declaration,
11027 N_Private_Type_Declaration)
11029 Match := Defining_Identifier (Decl);
11032 -- Guard against unanalyzed entities
11035 and then Is_Type (Match)
11036 and then Present (Full_View (Match))
11037 and then Full_View (Match) = Id
11052 -- Start of processing for Incomplete_Or_Partial_View
11055 -- Deferred constant or incomplete type case
11057 Prev := Current_Entity_In_Scope (Id);
11060 and then (Is_Incomplete_Type (Prev) or else Ekind (Prev) = E_Constant)
11061 and then Present (Full_View (Prev))
11062 and then Full_View (Prev) = Id
11067 -- Private or Taft amendment type case
11070 Pkg : constant Entity_Id := Scope (Id);
11071 Pkg_Decl : Node_Id := Pkg;
11075 and then Ekind_In (Pkg, E_Generic_Package, E_Package)
11077 while Nkind (Pkg_Decl) /= N_Package_Specification loop
11078 Pkg_Decl := Parent (Pkg_Decl);
11081 -- It is knows that Typ has a private view, look for it in the
11082 -- visible declarations of the enclosing scope. A special case
11083 -- of this is when the two views have been exchanged - the full
11084 -- appears earlier than the private.
11086 if Has_Private_Declaration (Id) then
11087 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
11089 -- Exchanged view case, look in the private declarations
11092 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
11097 -- Otherwise if this is the package body, then Typ is a potential
11098 -- Taft amendment type. The incomplete view should be located in
11099 -- the private declarations of the enclosing scope.
11101 elsif In_Package_Body (Pkg) then
11102 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
11107 -- The type has no incomplete or private view
11110 end Incomplete_Or_Partial_View;
11112 ----------------------------------
11113 -- Indexed_Component_Bit_Offset --
11114 ----------------------------------
11116 function Indexed_Component_Bit_Offset (N : Node_Id) return Uint is
11117 Exp : constant Node_Id := First (Expressions (N));
11118 Typ : constant Entity_Id := Etype (Prefix (N));
11119 Off : constant Uint := Component_Size (Typ);
11123 -- Return early if the component size is not known or variable
11125 if Off = No_Uint or else Off < Uint_0 then
11129 -- Deal with the degenerate case of an empty component
11131 if Off = Uint_0 then
11135 -- Check that both the index value and the low bound are known
11137 if not Compile_Time_Known_Value (Exp) then
11141 Ind := First_Index (Typ);
11146 if Nkind (Ind) = N_Subtype_Indication then
11147 Ind := Constraint (Ind);
11149 if Nkind (Ind) = N_Range_Constraint then
11150 Ind := Range_Expression (Ind);
11154 if Nkind (Ind) /= N_Range
11155 or else not Compile_Time_Known_Value (Low_Bound (Ind))
11160 -- Return the scaled offset
11162 return Off * (Expr_Value (Exp) - Expr_Value (Low_Bound ((Ind))));
11163 end Indexed_Component_Bit_Offset;
11165 ----------------------------
11166 -- Inherit_Rep_Item_Chain --
11167 ----------------------------
11169 procedure Inherit_Rep_Item_Chain (Typ : Entity_Id; From_Typ : Entity_Id) is
11171 Next_Item : Node_Id;
11174 -- There are several inheritance scenarios to consider depending on
11175 -- whether both types have rep item chains and whether the destination
11176 -- type already inherits part of the source type's rep item chain.
11178 -- 1) The source type lacks a rep item chain
11179 -- From_Typ ---> Empty
11181 -- Typ --------> Item (or Empty)
11183 -- In this case inheritance cannot take place because there are no items
11186 -- 2) The destination type lacks a rep item chain
11187 -- From_Typ ---> Item ---> ...
11189 -- Typ --------> Empty
11191 -- Inheritance takes place by setting the First_Rep_Item of the
11192 -- destination type to the First_Rep_Item of the source type.
11193 -- From_Typ ---> Item ---> ...
11195 -- Typ -----------+
11197 -- 3.1) Both source and destination types have at least one rep item.
11198 -- The destination type does NOT inherit a rep item from the source
11200 -- From_Typ ---> Item ---> Item
11202 -- Typ --------> Item ---> Item
11204 -- Inheritance takes place by setting the Next_Rep_Item of the last item
11205 -- of the destination type to the First_Rep_Item of the source type.
11206 -- From_Typ -------------------> Item ---> Item
11208 -- Typ --------> Item ---> Item --+
11210 -- 3.2) Both source and destination types have at least one rep item.
11211 -- The destination type DOES inherit part of the rep item chain of the
11213 -- From_Typ ---> Item ---> Item ---> Item
11215 -- Typ --------> Item ------+
11217 -- This rare case arises when the full view of a private extension must
11218 -- inherit the rep item chain from the full view of its parent type and
11219 -- the full view of the parent type contains extra rep items. Currently
11220 -- only invariants may lead to such form of inheritance.
11222 -- type From_Typ is tagged private
11223 -- with Type_Invariant'Class => Item_2;
11225 -- type Typ is new From_Typ with private
11226 -- with Type_Invariant => Item_4;
11228 -- At this point the rep item chains contain the following items
11230 -- From_Typ -----------> Item_2 ---> Item_3
11232 -- Typ --------> Item_4 --+
11234 -- The full views of both types may introduce extra invariants
11236 -- type From_Typ is tagged null record
11237 -- with Type_Invariant => Item_1;
11239 -- type Typ is new From_Typ with null record;
11241 -- The full view of Typ would have to inherit any new rep items added to
11242 -- the full view of From_Typ.
11244 -- From_Typ -----------> Item_1 ---> Item_2 ---> Item_3
11246 -- Typ --------> Item_4 --+
11248 -- To achieve this form of inheritance, the destination type must first
11249 -- sever the link between its own rep chain and that of the source type,
11250 -- then inheritance 3.1 takes place.
11252 -- Case 1: The source type lacks a rep item chain
11254 if No (First_Rep_Item (From_Typ)) then
11257 -- Case 2: The destination type lacks a rep item chain
11259 elsif No (First_Rep_Item (Typ)) then
11260 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
11262 -- Case 3: Both the source and destination types have at least one rep
11263 -- item. Traverse the rep item chain of the destination type to find the
11268 Next_Item := First_Rep_Item (Typ);
11269 while Present (Next_Item) loop
11271 -- Detect a link between the destination type's rep chain and that
11272 -- of the source type. There are two possibilities:
11277 -- From_Typ ---> Item_1 --->
11279 -- Typ -----------+
11286 -- From_Typ ---> Item_1 ---> Item_2 --->
11288 -- Typ --------> Item_3 ------+
11292 if Has_Rep_Item (From_Typ, Next_Item) then
11297 Next_Item := Next_Rep_Item (Next_Item);
11300 -- Inherit the source type's rep item chain
11302 if Present (Item) then
11303 Set_Next_Rep_Item (Item, First_Rep_Item (From_Typ));
11305 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
11308 end Inherit_Rep_Item_Chain;
11310 ---------------------------------
11311 -- Insert_Explicit_Dereference --
11312 ---------------------------------
11314 procedure Insert_Explicit_Dereference (N : Node_Id) is
11315 New_Prefix : constant Node_Id := Relocate_Node (N);
11316 Ent : Entity_Id := Empty;
11323 Save_Interps (N, New_Prefix);
11326 Make_Explicit_Dereference (Sloc (Parent (N)),
11327 Prefix => New_Prefix));
11329 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
11331 if Is_Overloaded (New_Prefix) then
11333 -- The dereference is also overloaded, and its interpretations are
11334 -- the designated types of the interpretations of the original node.
11336 Set_Etype (N, Any_Type);
11338 Get_First_Interp (New_Prefix, I, It);
11339 while Present (It.Nam) loop
11342 if Is_Access_Type (T) then
11343 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
11346 Get_Next_Interp (I, It);
11352 -- Prefix is unambiguous: mark the original prefix (which might
11353 -- Come_From_Source) as a reference, since the new (relocated) one
11354 -- won't be taken into account.
11356 if Is_Entity_Name (New_Prefix) then
11357 Ent := Entity (New_Prefix);
11358 Pref := New_Prefix;
11360 -- For a retrieval of a subcomponent of some composite object,
11361 -- retrieve the ultimate entity if there is one.
11363 elsif Nkind_In (New_Prefix, N_Selected_Component,
11364 N_Indexed_Component)
11366 Pref := Prefix (New_Prefix);
11367 while Present (Pref)
11368 and then Nkind_In (Pref, N_Selected_Component,
11369 N_Indexed_Component)
11371 Pref := Prefix (Pref);
11374 if Present (Pref) and then Is_Entity_Name (Pref) then
11375 Ent := Entity (Pref);
11379 -- Place the reference on the entity node
11381 if Present (Ent) then
11382 Generate_Reference (Ent, Pref);
11385 end Insert_Explicit_Dereference;
11387 ------------------------------------------
11388 -- Inspect_Deferred_Constant_Completion --
11389 ------------------------------------------
11391 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
11395 Decl := First (Decls);
11396 while Present (Decl) loop
11398 -- Deferred constant signature
11400 if Nkind (Decl) = N_Object_Declaration
11401 and then Constant_Present (Decl)
11402 and then No (Expression (Decl))
11404 -- No need to check internally generated constants
11406 and then Comes_From_Source (Decl)
11408 -- The constant is not completed. A full object declaration or a
11409 -- pragma Import complete a deferred constant.
11411 and then not Has_Completion (Defining_Identifier (Decl))
11414 ("constant declaration requires initialization expression",
11415 Defining_Identifier (Decl));
11418 Decl := Next (Decl);
11420 end Inspect_Deferred_Constant_Completion;
11422 -----------------------------
11423 -- Install_Generic_Formals --
11424 -----------------------------
11426 procedure Install_Generic_Formals (Subp_Id : Entity_Id) is
11430 pragma Assert (Is_Generic_Subprogram (Subp_Id));
11432 E := First_Entity (Subp_Id);
11433 while Present (E) loop
11434 Install_Entity (E);
11437 end Install_Generic_Formals;
11439 -----------------------------
11440 -- Is_Actual_Out_Parameter --
11441 -----------------------------
11443 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
11444 Formal : Entity_Id;
11447 Find_Actual (N, Formal, Call);
11448 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
11449 end Is_Actual_Out_Parameter;
11451 -------------------------
11452 -- Is_Actual_Parameter --
11453 -------------------------
11455 function Is_Actual_Parameter (N : Node_Id) return Boolean is
11456 PK : constant Node_Kind := Nkind (Parent (N));
11460 when N_Parameter_Association =>
11461 return N = Explicit_Actual_Parameter (Parent (N));
11463 when N_Subprogram_Call =>
11464 return Is_List_Member (N)
11466 List_Containing (N) = Parameter_Associations (Parent (N));
11471 end Is_Actual_Parameter;
11473 --------------------------------
11474 -- Is_Actual_Tagged_Parameter --
11475 --------------------------------
11477 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
11478 Formal : Entity_Id;
11481 Find_Actual (N, Formal, Call);
11482 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
11483 end Is_Actual_Tagged_Parameter;
11485 ---------------------
11486 -- Is_Aliased_View --
11487 ---------------------
11489 function Is_Aliased_View (Obj : Node_Id) return Boolean is
11493 if Is_Entity_Name (Obj) then
11500 or else (Present (Renamed_Object (E))
11501 and then Is_Aliased_View (Renamed_Object (E)))))
11503 or else ((Is_Formal (E)
11504 or else Ekind_In (E, E_Generic_In_Out_Parameter,
11505 E_Generic_In_Parameter))
11506 and then Is_Tagged_Type (Etype (E)))
11508 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
11510 -- Current instance of type, either directly or as rewritten
11511 -- reference to the current object.
11513 or else (Is_Entity_Name (Original_Node (Obj))
11514 and then Present (Entity (Original_Node (Obj)))
11515 and then Is_Type (Entity (Original_Node (Obj))))
11517 or else (Is_Type (E) and then E = Current_Scope)
11519 or else (Is_Incomplete_Or_Private_Type (E)
11520 and then Full_View (E) = Current_Scope)
11522 -- Ada 2012 AI05-0053: the return object of an extended return
11523 -- statement is aliased if its type is immutably limited.
11525 or else (Is_Return_Object (E)
11526 and then Is_Limited_View (Etype (E)));
11528 elsif Nkind (Obj) = N_Selected_Component then
11529 return Is_Aliased (Entity (Selector_Name (Obj)));
11531 elsif Nkind (Obj) = N_Indexed_Component then
11532 return Has_Aliased_Components (Etype (Prefix (Obj)))
11534 (Is_Access_Type (Etype (Prefix (Obj)))
11535 and then Has_Aliased_Components
11536 (Designated_Type (Etype (Prefix (Obj)))));
11538 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
11539 return Is_Tagged_Type (Etype (Obj))
11540 and then Is_Aliased_View (Expression (Obj));
11542 elsif Nkind (Obj) = N_Explicit_Dereference then
11543 return Nkind (Original_Node (Obj)) /= N_Function_Call;
11548 end Is_Aliased_View;
11550 -------------------------
11551 -- Is_Ancestor_Package --
11552 -------------------------
11554 function Is_Ancestor_Package
11556 E2 : Entity_Id) return Boolean
11562 while Present (Par) and then Par /= Standard_Standard loop
11567 Par := Scope (Par);
11571 end Is_Ancestor_Package;
11573 ----------------------
11574 -- Is_Atomic_Object --
11575 ----------------------
11577 function Is_Atomic_Object (N : Node_Id) return Boolean is
11579 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
11580 -- Determines if given object has atomic components
11582 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
11583 -- If prefix is an implicit dereference, examine designated type
11585 ----------------------
11586 -- Is_Atomic_Prefix --
11587 ----------------------
11589 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
11591 if Is_Access_Type (Etype (N)) then
11593 Has_Atomic_Components (Designated_Type (Etype (N)));
11595 return Object_Has_Atomic_Components (N);
11597 end Is_Atomic_Prefix;
11599 ----------------------------------
11600 -- Object_Has_Atomic_Components --
11601 ----------------------------------
11603 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
11605 if Has_Atomic_Components (Etype (N))
11606 or else Is_Atomic (Etype (N))
11610 elsif Is_Entity_Name (N)
11611 and then (Has_Atomic_Components (Entity (N))
11612 or else Is_Atomic (Entity (N)))
11616 elsif Nkind (N) = N_Selected_Component
11617 and then Is_Atomic (Entity (Selector_Name (N)))
11621 elsif Nkind (N) = N_Indexed_Component
11622 or else Nkind (N) = N_Selected_Component
11624 return Is_Atomic_Prefix (Prefix (N));
11629 end Object_Has_Atomic_Components;
11631 -- Start of processing for Is_Atomic_Object
11634 -- Predicate is not relevant to subprograms
11636 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
11639 elsif Is_Atomic (Etype (N))
11640 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
11644 elsif Nkind (N) = N_Selected_Component
11645 and then Is_Atomic (Entity (Selector_Name (N)))
11649 elsif Nkind (N) = N_Indexed_Component
11650 or else Nkind (N) = N_Selected_Component
11652 return Is_Atomic_Prefix (Prefix (N));
11657 end Is_Atomic_Object;
11659 -----------------------------
11660 -- Is_Atomic_Or_VFA_Object --
11661 -----------------------------
11663 function Is_Atomic_Or_VFA_Object (N : Node_Id) return Boolean is
11665 return Is_Atomic_Object (N)
11666 or else (Is_Object_Reference (N)
11667 and then Is_Entity_Name (N)
11668 and then (Is_Volatile_Full_Access (Entity (N))
11670 Is_Volatile_Full_Access (Etype (Entity (N)))));
11671 end Is_Atomic_Or_VFA_Object;
11673 -------------------------
11674 -- Is_Attribute_Result --
11675 -------------------------
11677 function Is_Attribute_Result (N : Node_Id) return Boolean is
11679 return Nkind (N) = N_Attribute_Reference
11680 and then Attribute_Name (N) = Name_Result;
11681 end Is_Attribute_Result;
11683 -------------------------
11684 -- Is_Attribute_Update --
11685 -------------------------
11687 function Is_Attribute_Update (N : Node_Id) return Boolean is
11689 return Nkind (N) = N_Attribute_Reference
11690 and then Attribute_Name (N) = Name_Update;
11691 end Is_Attribute_Update;
11693 ------------------------------------
11694 -- Is_Body_Or_Package_Declaration --
11695 ------------------------------------
11697 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
11699 return Nkind_In (N, N_Entry_Body,
11701 N_Package_Declaration,
11705 end Is_Body_Or_Package_Declaration;
11707 -----------------------
11708 -- Is_Bounded_String --
11709 -----------------------
11711 function Is_Bounded_String (T : Entity_Id) return Boolean is
11712 Under : constant Entity_Id := Underlying_Type (Root_Type (T));
11715 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
11716 -- Super_String, or one of the [Wide_]Wide_ versions. This will
11717 -- be True for all the Bounded_String types in instances of the
11718 -- Generic_Bounded_Length generics, and for types derived from those.
11720 return Present (Under)
11721 and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
11722 Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
11723 Is_RTE (Root_Type (Under), RO_WW_Super_String));
11724 end Is_Bounded_String;
11726 -------------------------
11727 -- Is_Child_Or_Sibling --
11728 -------------------------
11730 function Is_Child_Or_Sibling
11731 (Pack_1 : Entity_Id;
11732 Pack_2 : Entity_Id) return Boolean
11734 function Distance_From_Standard (Pack : Entity_Id) return Nat;
11735 -- Given an arbitrary package, return the number of "climbs" necessary
11736 -- to reach scope Standard_Standard.
11738 procedure Equalize_Depths
11739 (Pack : in out Entity_Id;
11740 Depth : in out Nat;
11741 Depth_To_Reach : Nat);
11742 -- Given an arbitrary package, its depth and a target depth to reach,
11743 -- climb the scope chain until the said depth is reached. The pointer
11744 -- to the package and its depth a modified during the climb.
11746 ----------------------------
11747 -- Distance_From_Standard --
11748 ----------------------------
11750 function Distance_From_Standard (Pack : Entity_Id) return Nat is
11757 while Present (Scop) and then Scop /= Standard_Standard loop
11759 Scop := Scope (Scop);
11763 end Distance_From_Standard;
11765 ---------------------
11766 -- Equalize_Depths --
11767 ---------------------
11769 procedure Equalize_Depths
11770 (Pack : in out Entity_Id;
11771 Depth : in out Nat;
11772 Depth_To_Reach : Nat)
11775 -- The package must be at a greater or equal depth
11777 if Depth < Depth_To_Reach then
11778 raise Program_Error;
11781 -- Climb the scope chain until the desired depth is reached
11783 while Present (Pack) and then Depth /= Depth_To_Reach loop
11784 Pack := Scope (Pack);
11785 Depth := Depth - 1;
11787 end Equalize_Depths;
11791 P_1 : Entity_Id := Pack_1;
11792 P_1_Child : Boolean := False;
11793 P_1_Depth : Nat := Distance_From_Standard (P_1);
11794 P_2 : Entity_Id := Pack_2;
11795 P_2_Child : Boolean := False;
11796 P_2_Depth : Nat := Distance_From_Standard (P_2);
11798 -- Start of processing for Is_Child_Or_Sibling
11802 (Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
11804 -- Both packages denote the same entity, therefore they cannot be
11805 -- children or siblings.
11810 -- One of the packages is at a deeper level than the other. Note that
11811 -- both may still come from differen hierarchies.
11819 elsif P_1_Depth > P_2_Depth then
11822 Depth => P_1_Depth,
11823 Depth_To_Reach => P_2_Depth);
11832 elsif P_2_Depth > P_1_Depth then
11835 Depth => P_2_Depth,
11836 Depth_To_Reach => P_1_Depth);
11840 -- At this stage the package pointers have been elevated to the same
11841 -- depth. If the related entities are the same, then one package is a
11842 -- potential child of the other:
11846 -- X became P_1 P_2 or vica versa
11852 return Is_Child_Unit (Pack_1);
11854 else pragma Assert (P_2_Child);
11855 return Is_Child_Unit (Pack_2);
11858 -- The packages may come from the same package chain or from entirely
11859 -- different hierarcies. To determine this, climb the scope stack until
11860 -- a common root is found.
11862 -- (root) (root 1) (root 2)
11867 while Present (P_1) and then Present (P_2) loop
11869 -- The two packages may be siblings
11872 return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2);
11875 P_1 := Scope (P_1);
11876 P_2 := Scope (P_2);
11881 end Is_Child_Or_Sibling;
11883 -----------------------------
11884 -- Is_Concurrent_Interface --
11885 -----------------------------
11887 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
11889 return Is_Interface (T)
11891 (Is_Protected_Interface (T)
11892 or else Is_Synchronized_Interface (T)
11893 or else Is_Task_Interface (T));
11894 end Is_Concurrent_Interface;
11896 -----------------------
11897 -- Is_Constant_Bound --
11898 -----------------------
11900 function Is_Constant_Bound (Exp : Node_Id) return Boolean is
11902 if Compile_Time_Known_Value (Exp) then
11905 elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
11906 return Is_Constant_Object (Entity (Exp))
11907 or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
11909 elsif Nkind (Exp) in N_Binary_Op then
11910 return Is_Constant_Bound (Left_Opnd (Exp))
11911 and then Is_Constant_Bound (Right_Opnd (Exp))
11912 and then Scope (Entity (Exp)) = Standard_Standard;
11917 end Is_Constant_Bound;
11919 ---------------------------
11920 -- Is_Container_Element --
11921 ---------------------------
11923 function Is_Container_Element (Exp : Node_Id) return Boolean is
11924 Loc : constant Source_Ptr := Sloc (Exp);
11925 Pref : constant Node_Id := Prefix (Exp);
11928 -- Call to an indexing aspect
11930 Cont_Typ : Entity_Id;
11931 -- The type of the container being accessed
11933 Elem_Typ : Entity_Id;
11934 -- Its element type
11936 Indexing : Entity_Id;
11937 Is_Const : Boolean;
11938 -- Indicates that constant indexing is used, and the element is thus
11941 Ref_Typ : Entity_Id;
11942 -- The reference type returned by the indexing operation
11945 -- If C is a container, in a context that imposes the element type of
11946 -- that container, the indexing notation C (X) is rewritten as:
11948 -- Indexing (C, X).Discr.all
11950 -- where Indexing is one of the indexing aspects of the container.
11951 -- If the context does not require a reference, the construct can be
11956 -- First, verify that the construct has the proper form
11958 if not Expander_Active then
11961 elsif Nkind (Pref) /= N_Selected_Component then
11964 elsif Nkind (Prefix (Pref)) /= N_Function_Call then
11968 Call := Prefix (Pref);
11969 Ref_Typ := Etype (Call);
11972 if not Has_Implicit_Dereference (Ref_Typ)
11973 or else No (First (Parameter_Associations (Call)))
11974 or else not Is_Entity_Name (Name (Call))
11979 -- Retrieve type of container object, and its iterator aspects
11981 Cont_Typ := Etype (First (Parameter_Associations (Call)));
11982 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Constant_Indexing);
11985 if No (Indexing) then
11987 -- Container should have at least one indexing operation
11991 elsif Entity (Name (Call)) /= Entity (Indexing) then
11993 -- This may be a variable indexing operation
11995 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Variable_Indexing);
11998 or else Entity (Name (Call)) /= Entity (Indexing)
12007 Elem_Typ := Find_Value_Of_Aspect (Cont_Typ, Aspect_Iterator_Element);
12009 if No (Elem_Typ) or else Entity (Elem_Typ) /= Etype (Exp) then
12013 -- Check that the expression is not the target of an assignment, in
12014 -- which case the rewriting is not possible.
12016 if not Is_Const then
12022 while Present (Par)
12024 if Nkind (Parent (Par)) = N_Assignment_Statement
12025 and then Par = Name (Parent (Par))
12029 -- A renaming produces a reference, and the transformation
12032 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
12036 (Nkind (Parent (Par)), N_Function_Call,
12037 N_Procedure_Call_Statement,
12038 N_Entry_Call_Statement)
12040 -- Check that the element is not part of an actual for an
12041 -- in-out parameter.
12048 F := First_Formal (Entity (Name (Parent (Par))));
12049 A := First (Parameter_Associations (Parent (Par)));
12050 while Present (F) loop
12051 if A = Par and then Ekind (F) /= E_In_Parameter then
12060 -- E_In_Parameter in a call: element is not modified.
12065 Par := Parent (Par);
12070 -- The expression has the proper form and the context requires the
12071 -- element type. Retrieve the Element function of the container and
12072 -- rewrite the construct as a call to it.
12078 Op := First_Elmt (Primitive_Operations (Cont_Typ));
12079 while Present (Op) loop
12080 exit when Chars (Node (Op)) = Name_Element;
12089 Make_Function_Call (Loc,
12090 Name => New_Occurrence_Of (Node (Op), Loc),
12091 Parameter_Associations => Parameter_Associations (Call)));
12092 Analyze_And_Resolve (Exp, Entity (Elem_Typ));
12096 end Is_Container_Element;
12098 ----------------------------
12099 -- Is_Contract_Annotation --
12100 ----------------------------
12102 function Is_Contract_Annotation (Item : Node_Id) return Boolean is
12104 return Is_Package_Contract_Annotation (Item)
12106 Is_Subprogram_Contract_Annotation (Item);
12107 end Is_Contract_Annotation;
12109 --------------------------------------
12110 -- Is_Controlling_Limited_Procedure --
12111 --------------------------------------
12113 function Is_Controlling_Limited_Procedure
12114 (Proc_Nam : Entity_Id) return Boolean
12116 Param_Typ : Entity_Id := Empty;
12119 if Ekind (Proc_Nam) = E_Procedure
12120 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
12122 Param_Typ := Etype (Parameter_Type (First (
12123 Parameter_Specifications (Parent (Proc_Nam)))));
12125 -- In this case where an Itype was created, the procedure call has been
12128 elsif Present (Associated_Node_For_Itype (Proc_Nam))
12129 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
12131 Present (Parameter_Associations
12132 (Associated_Node_For_Itype (Proc_Nam)))
12135 Etype (First (Parameter_Associations
12136 (Associated_Node_For_Itype (Proc_Nam))));
12139 if Present (Param_Typ) then
12141 Is_Interface (Param_Typ)
12142 and then Is_Limited_Record (Param_Typ);
12146 end Is_Controlling_Limited_Procedure;
12148 -----------------------------
12149 -- Is_CPP_Constructor_Call --
12150 -----------------------------
12152 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
12154 return Nkind (N) = N_Function_Call
12155 and then Is_CPP_Class (Etype (Etype (N)))
12156 and then Is_Constructor (Entity (Name (N)))
12157 and then Is_Imported (Entity (Name (N)));
12158 end Is_CPP_Constructor_Call;
12160 -------------------------
12161 -- Is_Current_Instance --
12162 -------------------------
12164 function Is_Current_Instance (N : Node_Id) return Boolean is
12165 Typ : constant Entity_Id := Entity (N);
12169 -- Simplest case: entity is a concurrent type and we are currently
12170 -- inside the body. This will eventually be expanded into a
12171 -- call to Self (for tasks) or _object (for protected objects).
12173 if Is_Concurrent_Type (Typ) and then In_Open_Scopes (Typ) then
12177 -- Check whether the context is a (sub)type declaration for the
12181 while Present (P) loop
12182 if Nkind_In (P, N_Full_Type_Declaration,
12183 N_Private_Type_Declaration,
12184 N_Subtype_Declaration)
12185 and then Comes_From_Source (P)
12186 and then Defining_Entity (P) = Typ
12190 -- A subtype name may appear in an aspect specification for a
12191 -- Predicate_Failure aspect, for which we do not construct a
12192 -- wrapper procedure. The subtype will be replaced by the
12193 -- expression being tested when the corresponding predicate
12194 -- check is expanded.
12196 elsif Nkind (P) = N_Aspect_Specification
12197 and then Nkind (Parent (P)) = N_Subtype_Declaration
12201 elsif Nkind (P) = N_Pragma
12203 Get_Pragma_Id (P) = Pragma_Predicate_Failure
12212 -- In any other context this is not a current occurrence
12215 end Is_Current_Instance;
12217 --------------------
12218 -- Is_Declaration --
12219 --------------------
12221 function Is_Declaration (N : Node_Id) return Boolean is
12224 Is_Declaration_Other_Than_Renaming (N)
12225 or else Is_Renaming_Declaration (N);
12226 end Is_Declaration;
12228 ----------------------------------------
12229 -- Is_Declaration_Other_Than_Renaming --
12230 ----------------------------------------
12232 function Is_Declaration_Other_Than_Renaming (N : Node_Id) return Boolean is
12235 when N_Abstract_Subprogram_Declaration
12236 | N_Exception_Declaration
12237 | N_Expression_Function
12238 | N_Full_Type_Declaration
12239 | N_Generic_Package_Declaration
12240 | N_Generic_Subprogram_Declaration
12241 | N_Number_Declaration
12242 | N_Object_Declaration
12243 | N_Package_Declaration
12244 | N_Private_Extension_Declaration
12245 | N_Private_Type_Declaration
12246 | N_Subprogram_Declaration
12247 | N_Subtype_Declaration
12254 end Is_Declaration_Other_Than_Renaming;
12256 --------------------------------
12257 -- Is_Declared_Within_Variant --
12258 --------------------------------
12260 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
12261 Comp_Decl : constant Node_Id := Parent (Comp);
12262 Comp_List : constant Node_Id := Parent (Comp_Decl);
12264 return Nkind (Parent (Comp_List)) = N_Variant;
12265 end Is_Declared_Within_Variant;
12267 ----------------------------------------------
12268 -- Is_Dependent_Component_Of_Mutable_Object --
12269 ----------------------------------------------
12271 function Is_Dependent_Component_Of_Mutable_Object
12272 (Object : Node_Id) return Boolean
12275 Prefix_Type : Entity_Id;
12276 P_Aliased : Boolean := False;
12279 Deref : Node_Id := Object;
12280 -- Dereference node, in something like X.all.Y(2)
12282 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
12285 -- Find the dereference node if any
12287 while Nkind_In (Deref, N_Indexed_Component,
12288 N_Selected_Component,
12291 Deref := Prefix (Deref);
12294 -- Ada 2005: If we have a component or slice of a dereference,
12295 -- something like X.all.Y (2), and the type of X is access-to-constant,
12296 -- Is_Variable will return False, because it is indeed a constant
12297 -- view. But it might be a view of a variable object, so we want the
12298 -- following condition to be True in that case.
12300 if Is_Variable (Object)
12301 or else (Ada_Version >= Ada_2005
12302 and then Nkind (Deref) = N_Explicit_Dereference)
12304 if Nkind (Object) = N_Selected_Component then
12305 P := Prefix (Object);
12306 Prefix_Type := Etype (P);
12308 if Is_Entity_Name (P) then
12309 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
12310 Prefix_Type := Base_Type (Prefix_Type);
12313 if Is_Aliased (Entity (P)) then
12317 -- A discriminant check on a selected component may be expanded
12318 -- into a dereference when removing side-effects. Recover the
12319 -- original node and its type, which may be unconstrained.
12321 elsif Nkind (P) = N_Explicit_Dereference
12322 and then not (Comes_From_Source (P))
12324 P := Original_Node (P);
12325 Prefix_Type := Etype (P);
12328 -- Check for prefix being an aliased component???
12334 -- A heap object is constrained by its initial value
12336 -- Ada 2005 (AI-363): Always assume the object could be mutable in
12337 -- the dereferenced case, since the access value might denote an
12338 -- unconstrained aliased object, whereas in Ada 95 the designated
12339 -- object is guaranteed to be constrained. A worst-case assumption
12340 -- has to apply in Ada 2005 because we can't tell at compile
12341 -- time whether the object is "constrained by its initial value"
12342 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
12343 -- rules (these rules are acknowledged to need fixing).
12345 if Ada_Version < Ada_2005 then
12346 if Is_Access_Type (Prefix_Type)
12347 or else Nkind (P) = N_Explicit_Dereference
12352 else pragma Assert (Ada_Version >= Ada_2005);
12353 if Is_Access_Type (Prefix_Type) then
12355 -- If the access type is pool-specific, and there is no
12356 -- constrained partial view of the designated type, then the
12357 -- designated object is known to be constrained.
12359 if Ekind (Prefix_Type) = E_Access_Type
12360 and then not Object_Type_Has_Constrained_Partial_View
12361 (Typ => Designated_Type (Prefix_Type),
12362 Scop => Current_Scope)
12366 -- Otherwise (general access type, or there is a constrained
12367 -- partial view of the designated type), we need to check
12368 -- based on the designated type.
12371 Prefix_Type := Designated_Type (Prefix_Type);
12377 Original_Record_Component (Entity (Selector_Name (Object)));
12379 -- As per AI-0017, the renaming is illegal in a generic body, even
12380 -- if the subtype is indefinite.
12382 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
12384 if not Is_Constrained (Prefix_Type)
12385 and then (Is_Definite_Subtype (Prefix_Type)
12387 (Is_Generic_Type (Prefix_Type)
12388 and then Ekind (Current_Scope) = E_Generic_Package
12389 and then In_Package_Body (Current_Scope)))
12391 and then (Is_Declared_Within_Variant (Comp)
12392 or else Has_Discriminant_Dependent_Constraint (Comp))
12393 and then (not P_Aliased or else Ada_Version >= Ada_2005)
12397 -- If the prefix is of an access type at this point, then we want
12398 -- to return False, rather than calling this function recursively
12399 -- on the access object (which itself might be a discriminant-
12400 -- dependent component of some other object, but that isn't
12401 -- relevant to checking the object passed to us). This avoids
12402 -- issuing wrong errors when compiling with -gnatc, where there
12403 -- can be implicit dereferences that have not been expanded.
12405 elsif Is_Access_Type (Etype (Prefix (Object))) then
12410 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
12413 elsif Nkind (Object) = N_Indexed_Component
12414 or else Nkind (Object) = N_Slice
12416 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
12418 -- A type conversion that Is_Variable is a view conversion:
12419 -- go back to the denoted object.
12421 elsif Nkind (Object) = N_Type_Conversion then
12423 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
12428 end Is_Dependent_Component_Of_Mutable_Object;
12430 ---------------------
12431 -- Is_Dereferenced --
12432 ---------------------
12434 function Is_Dereferenced (N : Node_Id) return Boolean is
12435 P : constant Node_Id := Parent (N);
12437 return Nkind_In (P, N_Selected_Component,
12438 N_Explicit_Dereference,
12439 N_Indexed_Component,
12441 and then Prefix (P) = N;
12442 end Is_Dereferenced;
12444 ----------------------
12445 -- Is_Descendant_Of --
12446 ----------------------
12448 function Is_Descendant_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
12453 pragma Assert (Nkind (T1) in N_Entity);
12454 pragma Assert (Nkind (T2) in N_Entity);
12456 T := Base_Type (T1);
12458 -- Immediate return if the types match
12463 -- Comment needed here ???
12465 elsif Ekind (T) = E_Class_Wide_Type then
12466 return Etype (T) = T2;
12474 -- Done if we found the type we are looking for
12479 -- Done if no more derivations to check
12486 -- Following test catches error cases resulting from prev errors
12488 elsif No (Etyp) then
12491 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
12494 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
12498 T := Base_Type (Etyp);
12501 end Is_Descendant_Of;
12503 ----------------------------------------
12504 -- Is_Descendant_Of_Suspension_Object --
12505 ----------------------------------------
12507 function Is_Descendant_Of_Suspension_Object
12508 (Typ : Entity_Id) return Boolean
12510 Cur_Typ : Entity_Id;
12511 Par_Typ : Entity_Id;
12514 -- Climb the type derivation chain checking each parent type against
12515 -- Suspension_Object.
12517 Cur_Typ := Base_Type (Typ);
12518 while Present (Cur_Typ) loop
12519 Par_Typ := Etype (Cur_Typ);
12521 -- The current type is a match
12523 if Is_Suspension_Object (Cur_Typ) then
12526 -- Stop the traversal once the root of the derivation chain has been
12527 -- reached. In that case the current type is its own base type.
12529 elsif Cur_Typ = Par_Typ then
12533 Cur_Typ := Base_Type (Par_Typ);
12537 end Is_Descendant_Of_Suspension_Object;
12539 ---------------------------------------------
12540 -- Is_Double_Precision_Floating_Point_Type --
12541 ---------------------------------------------
12543 function Is_Double_Precision_Floating_Point_Type
12544 (E : Entity_Id) return Boolean is
12546 return Is_Floating_Point_Type (E)
12547 and then Machine_Radix_Value (E) = Uint_2
12548 and then Machine_Mantissa_Value (E) = UI_From_Int (53)
12549 and then Machine_Emax_Value (E) = Uint_2 ** Uint_10
12550 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_10);
12551 end Is_Double_Precision_Floating_Point_Type;
12553 -----------------------------
12554 -- Is_Effectively_Volatile --
12555 -----------------------------
12557 function Is_Effectively_Volatile (Id : Entity_Id) return Boolean is
12559 if Is_Type (Id) then
12561 -- An arbitrary type is effectively volatile when it is subject to
12562 -- pragma Atomic or Volatile.
12564 if Is_Volatile (Id) then
12567 -- An array type is effectively volatile when it is subject to pragma
12568 -- Atomic_Components or Volatile_Components or its component type is
12569 -- effectively volatile.
12571 elsif Is_Array_Type (Id) then
12573 Has_Volatile_Components (Id)
12575 Is_Effectively_Volatile (Component_Type (Base_Type (Id)));
12577 -- A protected type is always volatile
12579 elsif Is_Protected_Type (Id) then
12582 -- A descendant of Ada.Synchronous_Task_Control.Suspension_Object is
12583 -- automatically volatile.
12585 elsif Is_Descendant_Of_Suspension_Object (Id) then
12588 -- Otherwise the type is not effectively volatile
12594 -- Otherwise Id denotes an object
12599 or else Has_Volatile_Components (Id)
12600 or else Is_Effectively_Volatile (Etype (Id));
12602 end Is_Effectively_Volatile;
12604 ------------------------------------
12605 -- Is_Effectively_Volatile_Object --
12606 ------------------------------------
12608 function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean is
12610 if Is_Entity_Name (N) then
12611 return Is_Effectively_Volatile (Entity (N));
12613 elsif Nkind (N) = N_Indexed_Component then
12614 return Is_Effectively_Volatile_Object (Prefix (N));
12616 elsif Nkind (N) = N_Selected_Component then
12618 Is_Effectively_Volatile_Object (Prefix (N))
12620 Is_Effectively_Volatile_Object (Selector_Name (N));
12625 end Is_Effectively_Volatile_Object;
12627 -------------------
12628 -- Is_Entry_Body --
12629 -------------------
12631 function Is_Entry_Body (Id : Entity_Id) return Boolean is
12634 Ekind_In (Id, E_Entry, E_Entry_Family)
12635 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Body;
12638 --------------------------
12639 -- Is_Entry_Declaration --
12640 --------------------------
12642 function Is_Entry_Declaration (Id : Entity_Id) return Boolean is
12645 Ekind_In (Id, E_Entry, E_Entry_Family)
12646 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Declaration;
12647 end Is_Entry_Declaration;
12649 ------------------------------------
12650 -- Is_Expanded_Priority_Attribute --
12651 ------------------------------------
12653 function Is_Expanded_Priority_Attribute (E : Entity_Id) return Boolean is
12656 Nkind (E) = N_Function_Call
12657 and then not Configurable_Run_Time_Mode
12658 and then (Entity (Name (E)) = RTE (RE_Get_Ceiling)
12659 or else Entity (Name (E)) = RTE (RO_PE_Get_Ceiling));
12660 end Is_Expanded_Priority_Attribute;
12662 ----------------------------
12663 -- Is_Expression_Function --
12664 ----------------------------
12666 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
12668 if Ekind_In (Subp, E_Function, E_Subprogram_Body) then
12670 Nkind (Original_Node (Unit_Declaration_Node (Subp))) =
12671 N_Expression_Function;
12675 end Is_Expression_Function;
12677 ------------------------------------------
12678 -- Is_Expression_Function_Or_Completion --
12679 ------------------------------------------
12681 function Is_Expression_Function_Or_Completion
12682 (Subp : Entity_Id) return Boolean
12684 Subp_Decl : Node_Id;
12687 if Ekind (Subp) = E_Function then
12688 Subp_Decl := Unit_Declaration_Node (Subp);
12690 -- The function declaration is either an expression function or is
12691 -- completed by an expression function body.
12694 Is_Expression_Function (Subp)
12695 or else (Nkind (Subp_Decl) = N_Subprogram_Declaration
12696 and then Present (Corresponding_Body (Subp_Decl))
12697 and then Is_Expression_Function
12698 (Corresponding_Body (Subp_Decl)));
12700 elsif Ekind (Subp) = E_Subprogram_Body then
12701 return Is_Expression_Function (Subp);
12706 end Is_Expression_Function_Or_Completion;
12708 -----------------------
12709 -- Is_EVF_Expression --
12710 -----------------------
12712 function Is_EVF_Expression (N : Node_Id) return Boolean is
12713 Orig_N : constant Node_Id := Original_Node (N);
12719 -- Detect a reference to a formal parameter of a specific tagged type
12720 -- whose related subprogram is subject to pragma Expresions_Visible with
12723 if Is_Entity_Name (N) and then Present (Entity (N)) then
12728 and then Is_Specific_Tagged_Type (Etype (Id))
12729 and then Extensions_Visible_Status (Id) =
12730 Extensions_Visible_False;
12732 -- A case expression is an EVF expression when it contains at least one
12733 -- EVF dependent_expression. Note that a case expression may have been
12734 -- expanded, hence the use of Original_Node.
12736 elsif Nkind (Orig_N) = N_Case_Expression then
12737 Alt := First (Alternatives (Orig_N));
12738 while Present (Alt) loop
12739 if Is_EVF_Expression (Expression (Alt)) then
12746 -- An if expression is an EVF expression when it contains at least one
12747 -- EVF dependent_expression. Note that an if expression may have been
12748 -- expanded, hence the use of Original_Node.
12750 elsif Nkind (Orig_N) = N_If_Expression then
12751 Expr := Next (First (Expressions (Orig_N)));
12752 while Present (Expr) loop
12753 if Is_EVF_Expression (Expr) then
12760 -- A qualified expression or a type conversion is an EVF expression when
12761 -- its operand is an EVF expression.
12763 elsif Nkind_In (N, N_Qualified_Expression,
12764 N_Unchecked_Type_Conversion,
12767 return Is_EVF_Expression (Expression (N));
12769 -- Attributes 'Loop_Entry, 'Old, and 'Update are EVF expressions when
12770 -- their prefix denotes an EVF expression.
12772 elsif Nkind (N) = N_Attribute_Reference
12773 and then Nam_In (Attribute_Name (N), Name_Loop_Entry,
12777 return Is_EVF_Expression (Prefix (N));
12781 end Is_EVF_Expression;
12787 function Is_False (U : Uint) return Boolean is
12792 ---------------------------
12793 -- Is_Fixed_Model_Number --
12794 ---------------------------
12796 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
12797 S : constant Ureal := Small_Value (T);
12798 M : Urealp.Save_Mark;
12802 R := (U = UR_Trunc (U / S) * S);
12803 Urealp.Release (M);
12805 end Is_Fixed_Model_Number;
12807 -------------------------------
12808 -- Is_Fully_Initialized_Type --
12809 -------------------------------
12811 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
12815 if Is_Scalar_Type (Typ) then
12817 -- A scalar type with an aspect Default_Value is fully initialized
12819 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
12820 -- of a scalar type, but we don't take that into account here, since
12821 -- we don't want these to affect warnings.
12823 return Has_Default_Aspect (Typ);
12825 elsif Is_Access_Type (Typ) then
12828 elsif Is_Array_Type (Typ) then
12829 if Is_Fully_Initialized_Type (Component_Type (Typ))
12830 or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
12835 -- An interesting case, if we have a constrained type one of whose
12836 -- bounds is known to be null, then there are no elements to be
12837 -- initialized, so all the elements are initialized.
12839 if Is_Constrained (Typ) then
12842 Indx_Typ : Entity_Id;
12843 Lbd, Hbd : Node_Id;
12846 Indx := First_Index (Typ);
12847 while Present (Indx) loop
12848 if Etype (Indx) = Any_Type then
12851 -- If index is a range, use directly
12853 elsif Nkind (Indx) = N_Range then
12854 Lbd := Low_Bound (Indx);
12855 Hbd := High_Bound (Indx);
12858 Indx_Typ := Etype (Indx);
12860 if Is_Private_Type (Indx_Typ) then
12861 Indx_Typ := Full_View (Indx_Typ);
12864 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
12867 Lbd := Type_Low_Bound (Indx_Typ);
12868 Hbd := Type_High_Bound (Indx_Typ);
12872 if Compile_Time_Known_Value (Lbd)
12874 Compile_Time_Known_Value (Hbd)
12876 if Expr_Value (Hbd) < Expr_Value (Lbd) then
12886 -- If no null indexes, then type is not fully initialized
12892 elsif Is_Record_Type (Typ) then
12893 if Has_Discriminants (Typ)
12895 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
12896 and then Is_Fully_Initialized_Variant (Typ)
12901 -- We consider bounded string types to be fully initialized, because
12902 -- otherwise we get false alarms when the Data component is not
12903 -- default-initialized.
12905 if Is_Bounded_String (Typ) then
12909 -- Controlled records are considered to be fully initialized if
12910 -- there is a user defined Initialize routine. This may not be
12911 -- entirely correct, but as the spec notes, we are guessing here
12912 -- what is best from the point of view of issuing warnings.
12914 if Is_Controlled (Typ) then
12916 Utyp : constant Entity_Id := Underlying_Type (Typ);
12919 if Present (Utyp) then
12921 Init : constant Entity_Id :=
12922 (Find_Optional_Prim_Op
12923 (Underlying_Type (Typ), Name_Initialize));
12927 and then Comes_From_Source (Init)
12929 Is_Predefined_File_Name
12930 (File_Name (Get_Source_File_Index (Sloc (Init))))
12934 elsif Has_Null_Extension (Typ)
12936 Is_Fully_Initialized_Type
12937 (Etype (Base_Type (Typ)))
12946 -- Otherwise see if all record components are initialized
12952 Ent := First_Entity (Typ);
12953 while Present (Ent) loop
12954 if Ekind (Ent) = E_Component
12955 and then (No (Parent (Ent))
12956 or else No (Expression (Parent (Ent))))
12957 and then not Is_Fully_Initialized_Type (Etype (Ent))
12959 -- Special VM case for tag components, which need to be
12960 -- defined in this case, but are never initialized as VMs
12961 -- are using other dispatching mechanisms. Ignore this
12962 -- uninitialized case. Note that this applies both to the
12963 -- uTag entry and the main vtable pointer (CPP_Class case).
12965 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
12974 -- No uninitialized components, so type is fully initialized.
12975 -- Note that this catches the case of no components as well.
12979 elsif Is_Concurrent_Type (Typ) then
12982 elsif Is_Private_Type (Typ) then
12984 U : constant Entity_Id := Underlying_Type (Typ);
12990 return Is_Fully_Initialized_Type (U);
12997 end Is_Fully_Initialized_Type;
12999 ----------------------------------
13000 -- Is_Fully_Initialized_Variant --
13001 ----------------------------------
13003 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
13004 Loc : constant Source_Ptr := Sloc (Typ);
13005 Constraints : constant List_Id := New_List;
13006 Components : constant Elist_Id := New_Elmt_List;
13007 Comp_Elmt : Elmt_Id;
13009 Comp_List : Node_Id;
13011 Discr_Val : Node_Id;
13013 Report_Errors : Boolean;
13014 pragma Warnings (Off, Report_Errors);
13017 if Serious_Errors_Detected > 0 then
13021 if Is_Record_Type (Typ)
13022 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
13023 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
13025 Comp_List := Component_List (Type_Definition (Parent (Typ)));
13027 Discr := First_Discriminant (Typ);
13028 while Present (Discr) loop
13029 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
13030 Discr_Val := Expression (Parent (Discr));
13032 if Present (Discr_Val)
13033 and then Is_OK_Static_Expression (Discr_Val)
13035 Append_To (Constraints,
13036 Make_Component_Association (Loc,
13037 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
13038 Expression => New_Copy (Discr_Val)));
13046 Next_Discriminant (Discr);
13051 Comp_List => Comp_List,
13052 Governed_By => Constraints,
13053 Into => Components,
13054 Report_Errors => Report_Errors);
13056 -- Check that each component present is fully initialized
13058 Comp_Elmt := First_Elmt (Components);
13059 while Present (Comp_Elmt) loop
13060 Comp_Id := Node (Comp_Elmt);
13062 if Ekind (Comp_Id) = E_Component
13063 and then (No (Parent (Comp_Id))
13064 or else No (Expression (Parent (Comp_Id))))
13065 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
13070 Next_Elmt (Comp_Elmt);
13075 elsif Is_Private_Type (Typ) then
13077 U : constant Entity_Id := Underlying_Type (Typ);
13083 return Is_Fully_Initialized_Variant (U);
13090 end Is_Fully_Initialized_Variant;
13092 ------------------------------------
13093 -- Is_Generic_Declaration_Or_Body --
13094 ------------------------------------
13096 function Is_Generic_Declaration_Or_Body (Decl : Node_Id) return Boolean is
13097 Spec_Decl : Node_Id;
13100 -- Package/subprogram body
13102 if Nkind_In (Decl, N_Package_Body, N_Subprogram_Body)
13103 and then Present (Corresponding_Spec (Decl))
13105 Spec_Decl := Unit_Declaration_Node (Corresponding_Spec (Decl));
13107 -- Package/subprogram body stub
13109 elsif Nkind_In (Decl, N_Package_Body_Stub, N_Subprogram_Body_Stub)
13110 and then Present (Corresponding_Spec_Of_Stub (Decl))
13113 Unit_Declaration_Node (Corresponding_Spec_Of_Stub (Decl));
13121 -- Rather than inspecting the defining entity of the spec declaration,
13122 -- look at its Nkind. This takes care of the case where the analysis of
13123 -- a generic body modifies the Ekind of its spec to allow for recursive
13127 Nkind_In (Spec_Decl, N_Generic_Package_Declaration,
13128 N_Generic_Subprogram_Declaration);
13129 end Is_Generic_Declaration_Or_Body;
13131 ----------------------------
13132 -- Is_Inherited_Operation --
13133 ----------------------------
13135 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
13136 pragma Assert (Is_Overloadable (E));
13137 Kind : constant Node_Kind := Nkind (Parent (E));
13139 return Kind = N_Full_Type_Declaration
13140 or else Kind = N_Private_Extension_Declaration
13141 or else Kind = N_Subtype_Declaration
13142 or else (Ekind (E) = E_Enumeration_Literal
13143 and then Is_Derived_Type (Etype (E)));
13144 end Is_Inherited_Operation;
13146 -------------------------------------
13147 -- Is_Inherited_Operation_For_Type --
13148 -------------------------------------
13150 function Is_Inherited_Operation_For_Type
13152 Typ : Entity_Id) return Boolean
13155 -- Check that the operation has been created by the type declaration
13157 return Is_Inherited_Operation (E)
13158 and then Defining_Identifier (Parent (E)) = Typ;
13159 end Is_Inherited_Operation_For_Type;
13161 --------------------------------------
13162 -- Is_Inlinable_Expression_Function --
13163 --------------------------------------
13165 function Is_Inlinable_Expression_Function
13166 (Subp : Entity_Id) return Boolean
13168 Return_Expr : Node_Id;
13171 if Is_Expression_Function_Or_Completion (Subp)
13172 and then Has_Pragma_Inline_Always (Subp)
13173 and then Needs_No_Actuals (Subp)
13174 and then No (Contract (Subp))
13175 and then not Is_Dispatching_Operation (Subp)
13176 and then Needs_Finalization (Etype (Subp))
13177 and then not Is_Class_Wide_Type (Etype (Subp))
13178 and then not (Has_Invariants (Etype (Subp)))
13179 and then Present (Subprogram_Body (Subp))
13180 and then Was_Expression_Function (Subprogram_Body (Subp))
13182 Return_Expr := Expression_Of_Expression_Function (Subp);
13184 -- The returned object must not have a qualified expression and its
13185 -- nominal subtype must be statically compatible with the result
13186 -- subtype of the expression function.
13189 Nkind (Return_Expr) = N_Identifier
13190 and then Etype (Return_Expr) = Etype (Subp);
13194 end Is_Inlinable_Expression_Function;
13200 function Is_Iterator (Typ : Entity_Id) return Boolean is
13201 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean;
13202 -- Determine whether type Iter_Typ is a predefined forward or reversible
13205 ----------------------
13206 -- Denotes_Iterator --
13207 ----------------------
13209 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean is
13211 -- Check that the name matches, and that the ultimate ancestor is in
13212 -- a predefined unit, i.e the one that declares iterator interfaces.
13215 Nam_In (Chars (Iter_Typ), Name_Forward_Iterator,
13216 Name_Reversible_Iterator)
13217 and then Is_Predefined_File_Name
13218 (Unit_File_Name (Get_Source_Unit (Root_Type (Iter_Typ))));
13219 end Denotes_Iterator;
13223 Iface_Elmt : Elmt_Id;
13226 -- Start of processing for Is_Iterator
13229 -- The type may be a subtype of a descendant of the proper instance of
13230 -- the predefined interface type, so we must use the root type of the
13231 -- given type. The same is done for Is_Reversible_Iterator.
13233 if Is_Class_Wide_Type (Typ)
13234 and then Denotes_Iterator (Root_Type (Typ))
13238 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
13241 elsif Present (Find_Value_Of_Aspect (Typ, Aspect_Iterable)) then
13245 Collect_Interfaces (Typ, Ifaces);
13247 Iface_Elmt := First_Elmt (Ifaces);
13248 while Present (Iface_Elmt) loop
13249 if Denotes_Iterator (Node (Iface_Elmt)) then
13253 Next_Elmt (Iface_Elmt);
13260 ----------------------------
13261 -- Is_Iterator_Over_Array --
13262 ----------------------------
13264 function Is_Iterator_Over_Array (N : Node_Id) return Boolean is
13265 Container : constant Node_Id := Name (N);
13266 Container_Typ : constant Entity_Id := Base_Type (Etype (Container));
13268 return Is_Array_Type (Container_Typ);
13269 end Is_Iterator_Over_Array;
13275 -- We seem to have a lot of overlapping functions that do similar things
13276 -- (testing for left hand sides or lvalues???).
13278 function Is_LHS (N : Node_Id) return Is_LHS_Result is
13279 P : constant Node_Id := Parent (N);
13282 -- Return True if we are the left hand side of an assignment statement
13284 if Nkind (P) = N_Assignment_Statement then
13285 if Name (P) = N then
13291 -- Case of prefix of indexed or selected component or slice
13293 elsif Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
13294 and then N = Prefix (P)
13296 -- Here we have the case where the parent P is N.Q or N(Q .. R).
13297 -- If P is an LHS, then N is also effectively an LHS, but there
13298 -- is an important exception. If N is of an access type, then
13299 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
13300 -- case this makes N.all a left hand side but not N itself.
13302 -- If we don't know the type yet, this is the case where we return
13303 -- Unknown, since the answer depends on the type which is unknown.
13305 if No (Etype (N)) then
13308 -- We have an Etype set, so we can check it
13310 elsif Is_Access_Type (Etype (N)) then
13313 -- OK, not access type case, so just test whole expression
13319 -- All other cases are not left hand sides
13326 -----------------------------
13327 -- Is_Library_Level_Entity --
13328 -----------------------------
13330 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
13332 -- The following is a small optimization, and it also properly handles
13333 -- discriminals, which in task bodies might appear in expressions before
13334 -- the corresponding procedure has been created, and which therefore do
13335 -- not have an assigned scope.
13337 if Is_Formal (E) then
13341 -- Normal test is simply that the enclosing dynamic scope is Standard
13343 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
13344 end Is_Library_Level_Entity;
13346 --------------------------------
13347 -- Is_Limited_Class_Wide_Type --
13348 --------------------------------
13350 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
13353 Is_Class_Wide_Type (Typ)
13354 and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
13355 end Is_Limited_Class_Wide_Type;
13357 ---------------------------------
13358 -- Is_Local_Variable_Reference --
13359 ---------------------------------
13361 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
13363 if not Is_Entity_Name (Expr) then
13368 Ent : constant Entity_Id := Entity (Expr);
13369 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
13371 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
13374 return Present (Sub) and then Sub = Current_Subprogram;
13378 end Is_Local_Variable_Reference;
13380 -----------------------
13381 -- Is_Name_Reference --
13382 -----------------------
13384 function Is_Name_Reference (N : Node_Id) return Boolean is
13386 if Is_Entity_Name (N) then
13387 return Present (Entity (N)) and then Is_Object (Entity (N));
13391 when N_Indexed_Component
13395 Is_Name_Reference (Prefix (N))
13396 or else Is_Access_Type (Etype (Prefix (N)));
13398 -- Attributes 'Input, 'Old and 'Result produce objects
13400 when N_Attribute_Reference =>
13402 Nam_In (Attribute_Name (N), Name_Input, Name_Old, Name_Result);
13404 when N_Selected_Component =>
13406 Is_Name_Reference (Selector_Name (N))
13408 (Is_Name_Reference (Prefix (N))
13409 or else Is_Access_Type (Etype (Prefix (N))));
13411 when N_Explicit_Dereference =>
13414 -- A view conversion of a tagged name is a name reference
13416 when N_Type_Conversion =>
13418 Is_Tagged_Type (Etype (Subtype_Mark (N)))
13419 and then Is_Tagged_Type (Etype (Expression (N)))
13420 and then Is_Name_Reference (Expression (N));
13422 -- An unchecked type conversion is considered to be a name if the
13423 -- operand is a name (this construction arises only as a result of
13424 -- expansion activities).
13426 when N_Unchecked_Type_Conversion =>
13427 return Is_Name_Reference (Expression (N));
13432 end Is_Name_Reference;
13434 ---------------------------------
13435 -- Is_Nontrivial_DIC_Procedure --
13436 ---------------------------------
13438 function Is_Nontrivial_DIC_Procedure (Id : Entity_Id) return Boolean is
13439 Body_Decl : Node_Id;
13443 if Ekind (Id) = E_Procedure and then Is_DIC_Procedure (Id) then
13445 Unit_Declaration_Node
13446 (Corresponding_Body (Unit_Declaration_Node (Id)));
13448 -- The body of the Default_Initial_Condition procedure must contain
13449 -- at least one statement, otherwise the generation of the subprogram
13452 pragma Assert (Present (Handled_Statement_Sequence (Body_Decl)));
13454 -- To qualify as nontrivial, the first statement of the procedure
13455 -- must be a check in the form of an if statement. If the original
13456 -- Default_Initial_Condition expression was folded, then the first
13457 -- statement is not a check.
13459 Stmt := First (Statements (Handled_Statement_Sequence (Body_Decl)));
13462 Nkind (Stmt) = N_If_Statement
13463 and then Nkind (Original_Node (Stmt)) = N_Pragma;
13467 end Is_Nontrivial_DIC_Procedure;
13469 -------------------------
13470 -- Is_Null_Record_Type --
13471 -------------------------
13473 function Is_Null_Record_Type (T : Entity_Id) return Boolean is
13474 Decl : constant Node_Id := Parent (T);
13476 return Nkind (Decl) = N_Full_Type_Declaration
13477 and then Nkind (Type_Definition (Decl)) = N_Record_Definition
13479 (No (Component_List (Type_Definition (Decl)))
13480 or else Null_Present (Component_List (Type_Definition (Decl))));
13481 end Is_Null_Record_Type;
13483 -------------------------
13484 -- Is_Object_Reference --
13485 -------------------------
13487 function Is_Object_Reference (N : Node_Id) return Boolean is
13488 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean;
13489 -- Determine whether N is the name of an internally-generated renaming
13491 --------------------------------------
13492 -- Is_Internally_Generated_Renaming --
13493 --------------------------------------
13495 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean is
13500 while Present (P) loop
13501 if Nkind (P) = N_Object_Renaming_Declaration then
13502 return not Comes_From_Source (P);
13503 elsif Is_List_Member (P) then
13511 end Is_Internally_Generated_Renaming;
13513 -- Start of processing for Is_Object_Reference
13516 if Is_Entity_Name (N) then
13517 return Present (Entity (N)) and then Is_Object (Entity (N));
13521 when N_Indexed_Component
13525 Is_Object_Reference (Prefix (N))
13526 or else Is_Access_Type (Etype (Prefix (N)));
13528 -- In Ada 95, a function call is a constant object; a procedure
13531 when N_Function_Call =>
13532 return Etype (N) /= Standard_Void_Type;
13534 -- Attributes 'Input, 'Loop_Entry, 'Old, and 'Result produce
13537 when N_Attribute_Reference =>
13539 Nam_In (Attribute_Name (N), Name_Input,
13544 when N_Selected_Component =>
13546 Is_Object_Reference (Selector_Name (N))
13548 (Is_Object_Reference (Prefix (N))
13549 or else Is_Access_Type (Etype (Prefix (N))));
13551 when N_Explicit_Dereference =>
13554 -- A view conversion of a tagged object is an object reference
13556 when N_Type_Conversion =>
13557 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
13558 and then Is_Tagged_Type (Etype (Expression (N)))
13559 and then Is_Object_Reference (Expression (N));
13561 -- An unchecked type conversion is considered to be an object if
13562 -- the operand is an object (this construction arises only as a
13563 -- result of expansion activities).
13565 when N_Unchecked_Type_Conversion =>
13568 -- Allow string literals to act as objects as long as they appear
13569 -- in internally-generated renamings. The expansion of iterators
13570 -- may generate such renamings when the range involves a string
13573 when N_String_Literal =>
13574 return Is_Internally_Generated_Renaming (Parent (N));
13576 -- AI05-0003: In Ada 2012 a qualified expression is a name.
13577 -- This allows disambiguation of function calls and the use
13578 -- of aggregates in more contexts.
13580 when N_Qualified_Expression =>
13581 if Ada_Version < Ada_2012 then
13584 return Is_Object_Reference (Expression (N))
13585 or else Nkind (Expression (N)) = N_Aggregate;
13592 end Is_Object_Reference;
13594 -----------------------------------
13595 -- Is_OK_Variable_For_Out_Formal --
13596 -----------------------------------
13598 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
13600 Note_Possible_Modification (AV, Sure => True);
13602 -- We must reject parenthesized variable names. Comes_From_Source is
13603 -- checked because there are currently cases where the compiler violates
13604 -- this rule (e.g. passing a task object to its controlled Initialize
13605 -- routine). This should be properly documented in sinfo???
13607 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
13610 -- A variable is always allowed
13612 elsif Is_Variable (AV) then
13615 -- Generalized indexing operations are rewritten as explicit
13616 -- dereferences, and it is only during resolution that we can
13617 -- check whether the context requires an access_to_variable type.
13619 elsif Nkind (AV) = N_Explicit_Dereference
13620 and then Ada_Version >= Ada_2012
13621 and then Nkind (Original_Node (AV)) = N_Indexed_Component
13622 and then Present (Etype (Original_Node (AV)))
13623 and then Has_Implicit_Dereference (Etype (Original_Node (AV)))
13625 return not Is_Access_Constant (Etype (Prefix (AV)));
13627 -- Unchecked conversions are allowed only if they come from the
13628 -- generated code, which sometimes uses unchecked conversions for out
13629 -- parameters in cases where code generation is unaffected. We tell
13630 -- source unchecked conversions by seeing if they are rewrites of
13631 -- an original Unchecked_Conversion function call, or of an explicit
13632 -- conversion of a function call or an aggregate (as may happen in the
13633 -- expansion of a packed array aggregate).
13635 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
13636 if Nkind_In (Original_Node (AV), N_Function_Call, N_Aggregate) then
13639 elsif Comes_From_Source (AV)
13640 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
13644 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
13645 return Is_OK_Variable_For_Out_Formal (Expression (AV));
13651 -- Normal type conversions are allowed if argument is a variable
13653 elsif Nkind (AV) = N_Type_Conversion then
13654 if Is_Variable (Expression (AV))
13655 and then Paren_Count (Expression (AV)) = 0
13657 Note_Possible_Modification (Expression (AV), Sure => True);
13660 -- We also allow a non-parenthesized expression that raises
13661 -- constraint error if it rewrites what used to be a variable
13663 elsif Raises_Constraint_Error (Expression (AV))
13664 and then Paren_Count (Expression (AV)) = 0
13665 and then Is_Variable (Original_Node (Expression (AV)))
13669 -- Type conversion of something other than a variable
13675 -- If this node is rewritten, then test the original form, if that is
13676 -- OK, then we consider the rewritten node OK (for example, if the
13677 -- original node is a conversion, then Is_Variable will not be true
13678 -- but we still want to allow the conversion if it converts a variable).
13680 elsif Original_Node (AV) /= AV then
13682 -- In Ada 2012, the explicit dereference may be a rewritten call to a
13683 -- Reference function.
13685 if Ada_Version >= Ada_2012
13686 and then Nkind (Original_Node (AV)) = N_Function_Call
13688 Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
13691 -- Check that this is not a constant reference.
13693 return not Is_Access_Constant (Etype (Prefix (AV)));
13695 elsif Has_Implicit_Dereference (Etype (Original_Node (AV))) then
13697 not Is_Access_Constant (Etype
13698 (Get_Reference_Discriminant (Etype (Original_Node (AV)))));
13701 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
13704 -- All other non-variables are rejected
13709 end Is_OK_Variable_For_Out_Formal;
13711 ----------------------------
13712 -- Is_OK_Volatile_Context --
13713 ----------------------------
13715 function Is_OK_Volatile_Context
13716 (Context : Node_Id;
13717 Obj_Ref : Node_Id) return Boolean
13719 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean;
13720 -- Determine whether an arbitrary node denotes a call to a protected
13721 -- entry, function, or procedure in prefixed form where the prefix is
13724 function Within_Check (Nod : Node_Id) return Boolean;
13725 -- Determine whether an arbitrary node appears in a check node
13727 function Within_Subprogram_Call (Nod : Node_Id) return Boolean;
13728 -- Determine whether an arbitrary node appears in an entry, function, or
13731 function Within_Volatile_Function (Id : Entity_Id) return Boolean;
13732 -- Determine whether an arbitrary entity appears in a volatile function
13734 ---------------------------------
13735 -- Is_Protected_Operation_Call --
13736 ---------------------------------
13738 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean is
13743 -- A call to a protected operations retains its selected component
13744 -- form as opposed to other prefixed calls that are transformed in
13747 if Nkind (Nod) = N_Selected_Component then
13748 Pref := Prefix (Nod);
13749 Subp := Selector_Name (Nod);
13753 and then Present (Etype (Pref))
13754 and then Is_Protected_Type (Etype (Pref))
13755 and then Is_Entity_Name (Subp)
13756 and then Present (Entity (Subp))
13757 and then Ekind_In (Entity (Subp), E_Entry,
13764 end Is_Protected_Operation_Call;
13770 function Within_Check (Nod : Node_Id) return Boolean is
13774 -- Climb the parent chain looking for a check node
13777 while Present (Par) loop
13778 if Nkind (Par) in N_Raise_xxx_Error then
13781 -- Prevent the search from going too far
13783 elsif Is_Body_Or_Package_Declaration (Par) then
13787 Par := Parent (Par);
13793 ----------------------------
13794 -- Within_Subprogram_Call --
13795 ----------------------------
13797 function Within_Subprogram_Call (Nod : Node_Id) return Boolean is
13801 -- Climb the parent chain looking for a function or procedure call
13804 while Present (Par) loop
13805 if Nkind_In (Par, N_Entry_Call_Statement,
13807 N_Procedure_Call_Statement)
13811 -- Prevent the search from going too far
13813 elsif Is_Body_Or_Package_Declaration (Par) then
13817 Par := Parent (Par);
13821 end Within_Subprogram_Call;
13823 ------------------------------
13824 -- Within_Volatile_Function --
13825 ------------------------------
13827 function Within_Volatile_Function (Id : Entity_Id) return Boolean is
13828 Func_Id : Entity_Id;
13831 -- Traverse the scope stack looking for a [generic] function
13834 while Present (Func_Id) and then Func_Id /= Standard_Standard loop
13835 if Ekind_In (Func_Id, E_Function, E_Generic_Function) then
13836 return Is_Volatile_Function (Func_Id);
13839 Func_Id := Scope (Func_Id);
13843 end Within_Volatile_Function;
13847 Obj_Id : Entity_Id;
13849 -- Start of processing for Is_OK_Volatile_Context
13852 -- The volatile object appears on either side of an assignment
13854 if Nkind (Context) = N_Assignment_Statement then
13857 -- The volatile object is part of the initialization expression of
13860 elsif Nkind (Context) = N_Object_Declaration
13861 and then Present (Expression (Context))
13862 and then Expression (Context) = Obj_Ref
13864 Obj_Id := Defining_Entity (Context);
13866 -- The volatile object acts as the initialization expression of an
13867 -- extended return statement. This is valid context as long as the
13868 -- function is volatile.
13870 if Is_Return_Object (Obj_Id) then
13871 return Within_Volatile_Function (Obj_Id);
13873 -- Otherwise this is a normal object initialization
13879 -- The volatile object acts as the name of a renaming declaration
13881 elsif Nkind (Context) = N_Object_Renaming_Declaration
13882 and then Name (Context) = Obj_Ref
13886 -- The volatile object appears as an actual parameter in a call to an
13887 -- instance of Unchecked_Conversion whose result is renamed.
13889 elsif Nkind (Context) = N_Function_Call
13890 and then Is_Entity_Name (Name (Context))
13891 and then Is_Unchecked_Conversion_Instance (Entity (Name (Context)))
13892 and then Nkind (Parent (Context)) = N_Object_Renaming_Declaration
13896 -- The volatile object is actually the prefix in a protected entry,
13897 -- function, or procedure call.
13899 elsif Is_Protected_Operation_Call (Context) then
13902 -- The volatile object appears as the expression of a simple return
13903 -- statement that applies to a volatile function.
13905 elsif Nkind (Context) = N_Simple_Return_Statement
13906 and then Expression (Context) = Obj_Ref
13909 Within_Volatile_Function (Return_Statement_Entity (Context));
13911 -- The volatile object appears as the prefix of a name occurring in a
13912 -- non-interfering context.
13914 elsif Nkind_In (Context, N_Attribute_Reference,
13915 N_Explicit_Dereference,
13916 N_Indexed_Component,
13917 N_Selected_Component,
13919 and then Prefix (Context) = Obj_Ref
13920 and then Is_OK_Volatile_Context
13921 (Context => Parent (Context),
13922 Obj_Ref => Context)
13926 -- The volatile object appears as the prefix of attributes Address,
13927 -- Alignment, Component_Size, First_Bit, Last_Bit, Position, Size,
13930 elsif Nkind (Context) = N_Attribute_Reference
13931 and then Prefix (Context) = Obj_Ref
13932 and then Nam_In (Attribute_Name (Context), Name_Address,
13934 Name_Component_Size,
13943 -- The volatile object appears as the expression of a type conversion
13944 -- occurring in a non-interfering context.
13946 elsif Nkind_In (Context, N_Type_Conversion,
13947 N_Unchecked_Type_Conversion)
13948 and then Expression (Context) = Obj_Ref
13949 and then Is_OK_Volatile_Context
13950 (Context => Parent (Context),
13951 Obj_Ref => Context)
13955 -- The volatile object appears as the expression in a delay statement
13957 elsif Nkind (Context) in N_Delay_Statement then
13960 -- Allow references to volatile objects in various checks. This is not a
13961 -- direct SPARK 2014 requirement.
13963 elsif Within_Check (Context) then
13966 -- Assume that references to effectively volatile objects that appear
13967 -- as actual parameters in a subprogram call are always legal. A full
13968 -- legality check is done when the actuals are resolved (see routine
13969 -- Resolve_Actuals).
13971 elsif Within_Subprogram_Call (Context) then
13974 -- Otherwise the context is not suitable for an effectively volatile
13980 end Is_OK_Volatile_Context;
13982 ------------------------------------
13983 -- Is_Package_Contract_Annotation --
13984 ------------------------------------
13986 function Is_Package_Contract_Annotation (Item : Node_Id) return Boolean is
13990 if Nkind (Item) = N_Aspect_Specification then
13991 Nam := Chars (Identifier (Item));
13993 else pragma Assert (Nkind (Item) = N_Pragma);
13994 Nam := Pragma_Name (Item);
13997 return Nam = Name_Abstract_State
13998 or else Nam = Name_Initial_Condition
13999 or else Nam = Name_Initializes
14000 or else Nam = Name_Refined_State;
14001 end Is_Package_Contract_Annotation;
14003 -----------------------------------
14004 -- Is_Partially_Initialized_Type --
14005 -----------------------------------
14007 function Is_Partially_Initialized_Type
14009 Include_Implicit : Boolean := True) return Boolean
14012 if Is_Scalar_Type (Typ) then
14015 elsif Is_Access_Type (Typ) then
14016 return Include_Implicit;
14018 elsif Is_Array_Type (Typ) then
14020 -- If component type is partially initialized, so is array type
14022 if Is_Partially_Initialized_Type
14023 (Component_Type (Typ), Include_Implicit)
14027 -- Otherwise we are only partially initialized if we are fully
14028 -- initialized (this is the empty array case, no point in us
14029 -- duplicating that code here).
14032 return Is_Fully_Initialized_Type (Typ);
14035 elsif Is_Record_Type (Typ) then
14037 -- A discriminated type is always partially initialized if in
14040 if Has_Discriminants (Typ) and then Include_Implicit then
14043 -- A tagged type is always partially initialized
14045 elsif Is_Tagged_Type (Typ) then
14048 -- Case of non-discriminated record
14054 Component_Present : Boolean := False;
14055 -- Set True if at least one component is present. If no
14056 -- components are present, then record type is fully
14057 -- initialized (another odd case, like the null array).
14060 -- Loop through components
14062 Ent := First_Entity (Typ);
14063 while Present (Ent) loop
14064 if Ekind (Ent) = E_Component then
14065 Component_Present := True;
14067 -- If a component has an initialization expression then
14068 -- the enclosing record type is partially initialized
14070 if Present (Parent (Ent))
14071 and then Present (Expression (Parent (Ent)))
14075 -- If a component is of a type which is itself partially
14076 -- initialized, then the enclosing record type is also.
14078 elsif Is_Partially_Initialized_Type
14079 (Etype (Ent), Include_Implicit)
14088 -- No initialized components found. If we found any components
14089 -- they were all uninitialized so the result is false.
14091 if Component_Present then
14094 -- But if we found no components, then all the components are
14095 -- initialized so we consider the type to be initialized.
14103 -- Concurrent types are always fully initialized
14105 elsif Is_Concurrent_Type (Typ) then
14108 -- For a private type, go to underlying type. If there is no underlying
14109 -- type then just assume this partially initialized. Not clear if this
14110 -- can happen in a non-error case, but no harm in testing for this.
14112 elsif Is_Private_Type (Typ) then
14114 U : constant Entity_Id := Underlying_Type (Typ);
14119 return Is_Partially_Initialized_Type (U, Include_Implicit);
14123 -- For any other type (are there any?) assume partially initialized
14128 end Is_Partially_Initialized_Type;
14130 ------------------------------------
14131 -- Is_Potentially_Persistent_Type --
14132 ------------------------------------
14134 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
14139 -- For private type, test corresponding full type
14141 if Is_Private_Type (T) then
14142 return Is_Potentially_Persistent_Type (Full_View (T));
14144 -- Scalar types are potentially persistent
14146 elsif Is_Scalar_Type (T) then
14149 -- Record type is potentially persistent if not tagged and the types of
14150 -- all it components are potentially persistent, and no component has
14151 -- an initialization expression.
14153 elsif Is_Record_Type (T)
14154 and then not Is_Tagged_Type (T)
14155 and then not Is_Partially_Initialized_Type (T)
14157 Comp := First_Component (T);
14158 while Present (Comp) loop
14159 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
14162 Next_Entity (Comp);
14168 -- Array type is potentially persistent if its component type is
14169 -- potentially persistent and if all its constraints are static.
14171 elsif Is_Array_Type (T) then
14172 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
14176 Indx := First_Index (T);
14177 while Present (Indx) loop
14178 if not Is_OK_Static_Subtype (Etype (Indx)) then
14187 -- All other types are not potentially persistent
14192 end Is_Potentially_Persistent_Type;
14194 --------------------------------
14195 -- Is_Potentially_Unevaluated --
14196 --------------------------------
14198 function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is
14206 -- A postcondition whose expression is a short-circuit is broken down
14207 -- into individual aspects for better exception reporting. The original
14208 -- short-circuit expression is rewritten as the second operand, and an
14209 -- occurrence of 'Old in that operand is potentially unevaluated.
14210 -- See Sem_ch13.adb for details of this transformation.
14212 if Nkind (Original_Node (Par)) = N_And_Then then
14216 while not Nkind_In (Par, N_If_Expression,
14224 Par := Parent (Par);
14226 -- If the context is not an expression, or if is the result of
14227 -- expansion of an enclosing construct (such as another attribute)
14228 -- the predicate does not apply.
14230 if Nkind (Par) not in N_Subexpr
14231 or else not Comes_From_Source (Par)
14237 if Nkind (Par) = N_If_Expression then
14238 return Is_Elsif (Par) or else Expr /= First (Expressions (Par));
14240 elsif Nkind (Par) = N_Case_Expression then
14241 return Expr /= Expression (Par);
14243 elsif Nkind_In (Par, N_And_Then, N_Or_Else) then
14244 return Expr = Right_Opnd (Par);
14246 elsif Nkind_In (Par, N_In, N_Not_In) then
14247 return Expr /= Left_Opnd (Par);
14252 end Is_Potentially_Unevaluated;
14254 ---------------------------------
14255 -- Is_Protected_Self_Reference --
14256 ---------------------------------
14258 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
14260 function In_Access_Definition (N : Node_Id) return Boolean;
14261 -- Returns true if N belongs to an access definition
14263 --------------------------
14264 -- In_Access_Definition --
14265 --------------------------
14267 function In_Access_Definition (N : Node_Id) return Boolean is
14272 while Present (P) loop
14273 if Nkind (P) = N_Access_Definition then
14281 end In_Access_Definition;
14283 -- Start of processing for Is_Protected_Self_Reference
14286 -- Verify that prefix is analyzed and has the proper form. Note that
14287 -- the attributes Elab_Spec, Elab_Body, and Elab_Subp_Body, which also
14288 -- produce the address of an entity, do not analyze their prefix
14289 -- because they denote entities that are not necessarily visible.
14290 -- Neither of them can apply to a protected type.
14292 return Ada_Version >= Ada_2005
14293 and then Is_Entity_Name (N)
14294 and then Present (Entity (N))
14295 and then Is_Protected_Type (Entity (N))
14296 and then In_Open_Scopes (Entity (N))
14297 and then not In_Access_Definition (N);
14298 end Is_Protected_Self_Reference;
14300 -----------------------------
14301 -- Is_RCI_Pkg_Spec_Or_Body --
14302 -----------------------------
14304 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
14306 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
14307 -- Return True if the unit of Cunit is an RCI package declaration
14309 ---------------------------
14310 -- Is_RCI_Pkg_Decl_Cunit --
14311 ---------------------------
14313 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
14314 The_Unit : constant Node_Id := Unit (Cunit);
14317 if Nkind (The_Unit) /= N_Package_Declaration then
14321 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
14322 end Is_RCI_Pkg_Decl_Cunit;
14324 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
14327 return Is_RCI_Pkg_Decl_Cunit (Cunit)
14329 (Nkind (Unit (Cunit)) = N_Package_Body
14330 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
14331 end Is_RCI_Pkg_Spec_Or_Body;
14333 -----------------------------------------
14334 -- Is_Remote_Access_To_Class_Wide_Type --
14335 -----------------------------------------
14337 function Is_Remote_Access_To_Class_Wide_Type
14338 (E : Entity_Id) return Boolean
14341 -- A remote access to class-wide type is a general access to object type
14342 -- declared in the visible part of a Remote_Types or Remote_Call_
14345 return Ekind (E) = E_General_Access_Type
14346 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
14347 end Is_Remote_Access_To_Class_Wide_Type;
14349 -----------------------------------------
14350 -- Is_Remote_Access_To_Subprogram_Type --
14351 -----------------------------------------
14353 function Is_Remote_Access_To_Subprogram_Type
14354 (E : Entity_Id) return Boolean
14357 return (Ekind (E) = E_Access_Subprogram_Type
14358 or else (Ekind (E) = E_Record_Type
14359 and then Present (Corresponding_Remote_Type (E))))
14360 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
14361 end Is_Remote_Access_To_Subprogram_Type;
14363 --------------------
14364 -- Is_Remote_Call --
14365 --------------------
14367 function Is_Remote_Call (N : Node_Id) return Boolean is
14369 if Nkind (N) not in N_Subprogram_Call then
14371 -- An entry call cannot be remote
14375 elsif Nkind (Name (N)) in N_Has_Entity
14376 and then Is_Remote_Call_Interface (Entity (Name (N)))
14378 -- A subprogram declared in the spec of a RCI package is remote
14382 elsif Nkind (Name (N)) = N_Explicit_Dereference
14383 and then Is_Remote_Access_To_Subprogram_Type
14384 (Etype (Prefix (Name (N))))
14386 -- The dereference of a RAS is a remote call
14390 elsif Present (Controlling_Argument (N))
14391 and then Is_Remote_Access_To_Class_Wide_Type
14392 (Etype (Controlling_Argument (N)))
14394 -- Any primitive operation call with a controlling argument of
14395 -- a RACW type is a remote call.
14400 -- All other calls are local calls
14403 end Is_Remote_Call;
14405 ----------------------
14406 -- Is_Renamed_Entry --
14407 ----------------------
14409 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
14410 Orig_Node : Node_Id := Empty;
14411 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
14413 function Is_Entry (Nam : Node_Id) return Boolean;
14414 -- Determine whether Nam is an entry. Traverse selectors if there are
14415 -- nested selected components.
14421 function Is_Entry (Nam : Node_Id) return Boolean is
14423 if Nkind (Nam) = N_Selected_Component then
14424 return Is_Entry (Selector_Name (Nam));
14427 return Ekind (Entity (Nam)) = E_Entry;
14430 -- Start of processing for Is_Renamed_Entry
14433 if Present (Alias (Proc_Nam)) then
14434 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
14437 -- Look for a rewritten subprogram renaming declaration
14439 if Nkind (Subp_Decl) = N_Subprogram_Declaration
14440 and then Present (Original_Node (Subp_Decl))
14442 Orig_Node := Original_Node (Subp_Decl);
14445 -- The rewritten subprogram is actually an entry
14447 if Present (Orig_Node)
14448 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
14449 and then Is_Entry (Name (Orig_Node))
14455 end Is_Renamed_Entry;
14457 -----------------------------
14458 -- Is_Renaming_Declaration --
14459 -----------------------------
14461 function Is_Renaming_Declaration (N : Node_Id) return Boolean is
14464 when N_Exception_Renaming_Declaration
14465 | N_Generic_Function_Renaming_Declaration
14466 | N_Generic_Package_Renaming_Declaration
14467 | N_Generic_Procedure_Renaming_Declaration
14468 | N_Object_Renaming_Declaration
14469 | N_Package_Renaming_Declaration
14470 | N_Subprogram_Renaming_Declaration
14477 end Is_Renaming_Declaration;
14479 ----------------------------
14480 -- Is_Reversible_Iterator --
14481 ----------------------------
14483 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
14484 Ifaces_List : Elist_Id;
14485 Iface_Elmt : Elmt_Id;
14489 if Is_Class_Wide_Type (Typ)
14490 and then Chars (Root_Type (Typ)) = Name_Reversible_Iterator
14491 and then Is_Predefined_File_Name
14492 (Unit_File_Name (Get_Source_Unit (Root_Type (Typ))))
14496 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
14500 Collect_Interfaces (Typ, Ifaces_List);
14502 Iface_Elmt := First_Elmt (Ifaces_List);
14503 while Present (Iface_Elmt) loop
14504 Iface := Node (Iface_Elmt);
14505 if Chars (Iface) = Name_Reversible_Iterator
14507 Is_Predefined_File_Name
14508 (Unit_File_Name (Get_Source_Unit (Iface)))
14513 Next_Elmt (Iface_Elmt);
14518 end Is_Reversible_Iterator;
14520 ----------------------
14521 -- Is_Selector_Name --
14522 ----------------------
14524 function Is_Selector_Name (N : Node_Id) return Boolean is
14526 if not Is_List_Member (N) then
14528 P : constant Node_Id := Parent (N);
14530 return Nkind_In (P, N_Expanded_Name,
14531 N_Generic_Association,
14532 N_Parameter_Association,
14533 N_Selected_Component)
14534 and then Selector_Name (P) = N;
14539 L : constant List_Id := List_Containing (N);
14540 P : constant Node_Id := Parent (L);
14542 return (Nkind (P) = N_Discriminant_Association
14543 and then Selector_Names (P) = L)
14545 (Nkind (P) = N_Component_Association
14546 and then Choices (P) = L);
14549 end Is_Selector_Name;
14551 ---------------------------------
14552 -- Is_Single_Concurrent_Object --
14553 ---------------------------------
14555 function Is_Single_Concurrent_Object (Id : Entity_Id) return Boolean is
14558 Is_Single_Protected_Object (Id) or else Is_Single_Task_Object (Id);
14559 end Is_Single_Concurrent_Object;
14561 -------------------------------
14562 -- Is_Single_Concurrent_Type --
14563 -------------------------------
14565 function Is_Single_Concurrent_Type (Id : Entity_Id) return Boolean is
14568 Ekind_In (Id, E_Protected_Type, E_Task_Type)
14569 and then Is_Single_Concurrent_Type_Declaration
14570 (Declaration_Node (Id));
14571 end Is_Single_Concurrent_Type;
14573 -------------------------------------------
14574 -- Is_Single_Concurrent_Type_Declaration --
14575 -------------------------------------------
14577 function Is_Single_Concurrent_Type_Declaration
14578 (N : Node_Id) return Boolean
14581 return Nkind_In (Original_Node (N), N_Single_Protected_Declaration,
14582 N_Single_Task_Declaration);
14583 end Is_Single_Concurrent_Type_Declaration;
14585 ---------------------------------------------
14586 -- Is_Single_Precision_Floating_Point_Type --
14587 ---------------------------------------------
14589 function Is_Single_Precision_Floating_Point_Type
14590 (E : Entity_Id) return Boolean is
14592 return Is_Floating_Point_Type (E)
14593 and then Machine_Radix_Value (E) = Uint_2
14594 and then Machine_Mantissa_Value (E) = Uint_24
14595 and then Machine_Emax_Value (E) = Uint_2 ** Uint_7
14596 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_7);
14597 end Is_Single_Precision_Floating_Point_Type;
14599 --------------------------------
14600 -- Is_Single_Protected_Object --
14601 --------------------------------
14603 function Is_Single_Protected_Object (Id : Entity_Id) return Boolean is
14606 Ekind (Id) = E_Variable
14607 and then Ekind (Etype (Id)) = E_Protected_Type
14608 and then Is_Single_Concurrent_Type (Etype (Id));
14609 end Is_Single_Protected_Object;
14611 ---------------------------
14612 -- Is_Single_Task_Object --
14613 ---------------------------
14615 function Is_Single_Task_Object (Id : Entity_Id) return Boolean is
14618 Ekind (Id) = E_Variable
14619 and then Ekind (Etype (Id)) = E_Task_Type
14620 and then Is_Single_Concurrent_Type (Etype (Id));
14621 end Is_Single_Task_Object;
14623 -------------------------------------
14624 -- Is_SPARK_05_Initialization_Expr --
14625 -------------------------------------
14627 function Is_SPARK_05_Initialization_Expr (N : Node_Id) return Boolean is
14630 Comp_Assn : Node_Id;
14631 Orig_N : constant Node_Id := Original_Node (N);
14636 if not Comes_From_Source (Orig_N) then
14640 pragma Assert (Nkind (Orig_N) in N_Subexpr);
14642 case Nkind (Orig_N) is
14643 when N_Character_Literal
14644 | N_Integer_Literal
14650 when N_Expanded_Name
14653 if Is_Entity_Name (Orig_N)
14654 and then Present (Entity (Orig_N)) -- needed in some cases
14656 case Ekind (Entity (Orig_N)) is
14658 | E_Enumeration_Literal
14665 if Is_Type (Entity (Orig_N)) then
14673 when N_Qualified_Expression
14674 | N_Type_Conversion
14676 Is_Ok := Is_SPARK_05_Initialization_Expr (Expression (Orig_N));
14679 Is_Ok := Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
14682 | N_Membership_Test
14685 Is_Ok := Is_SPARK_05_Initialization_Expr (Left_Opnd (Orig_N))
14687 Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
14690 | N_Extension_Aggregate
14692 if Nkind (Orig_N) = N_Extension_Aggregate then
14694 Is_SPARK_05_Initialization_Expr (Ancestor_Part (Orig_N));
14697 Expr := First (Expressions (Orig_N));
14698 while Present (Expr) loop
14699 if not Is_SPARK_05_Initialization_Expr (Expr) then
14707 Comp_Assn := First (Component_Associations (Orig_N));
14708 while Present (Comp_Assn) loop
14709 Expr := Expression (Comp_Assn);
14711 -- Note: test for Present here needed for box assocation
14714 and then not Is_SPARK_05_Initialization_Expr (Expr)
14723 when N_Attribute_Reference =>
14724 if Nkind (Prefix (Orig_N)) in N_Subexpr then
14725 Is_Ok := Is_SPARK_05_Initialization_Expr (Prefix (Orig_N));
14728 Expr := First (Expressions (Orig_N));
14729 while Present (Expr) loop
14730 if not Is_SPARK_05_Initialization_Expr (Expr) then
14738 -- Selected components might be expanded named not yet resolved, so
14739 -- default on the safe side. (Eg on sparklex.ads)
14741 when N_Selected_Component =>
14750 end Is_SPARK_05_Initialization_Expr;
14752 ----------------------------------
14753 -- Is_SPARK_05_Object_Reference --
14754 ----------------------------------
14756 function Is_SPARK_05_Object_Reference (N : Node_Id) return Boolean is
14758 if Is_Entity_Name (N) then
14759 return Present (Entity (N))
14761 (Ekind_In (Entity (N), E_Constant, E_Variable)
14762 or else Ekind (Entity (N)) in Formal_Kind);
14766 when N_Selected_Component =>
14767 return Is_SPARK_05_Object_Reference (Prefix (N));
14773 end Is_SPARK_05_Object_Reference;
14775 -----------------------------
14776 -- Is_Specific_Tagged_Type --
14777 -----------------------------
14779 function Is_Specific_Tagged_Type (Typ : Entity_Id) return Boolean is
14780 Full_Typ : Entity_Id;
14783 -- Handle private types
14785 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
14786 Full_Typ := Full_View (Typ);
14791 -- A specific tagged type is a non-class-wide tagged type
14793 return Is_Tagged_Type (Full_Typ) and not Is_Class_Wide_Type (Full_Typ);
14794 end Is_Specific_Tagged_Type;
14800 function Is_Statement (N : Node_Id) return Boolean is
14803 Nkind (N) in N_Statement_Other_Than_Procedure_Call
14804 or else Nkind (N) = N_Procedure_Call_Statement;
14807 ---------------------------------------
14808 -- Is_Subprogram_Contract_Annotation --
14809 ---------------------------------------
14811 function Is_Subprogram_Contract_Annotation
14812 (Item : Node_Id) return Boolean
14817 if Nkind (Item) = N_Aspect_Specification then
14818 Nam := Chars (Identifier (Item));
14820 else pragma Assert (Nkind (Item) = N_Pragma);
14821 Nam := Pragma_Name (Item);
14824 return Nam = Name_Contract_Cases
14825 or else Nam = Name_Depends
14826 or else Nam = Name_Extensions_Visible
14827 or else Nam = Name_Global
14828 or else Nam = Name_Post
14829 or else Nam = Name_Post_Class
14830 or else Nam = Name_Postcondition
14831 or else Nam = Name_Pre
14832 or else Nam = Name_Pre_Class
14833 or else Nam = Name_Precondition
14834 or else Nam = Name_Refined_Depends
14835 or else Nam = Name_Refined_Global
14836 or else Nam = Name_Refined_Post
14837 or else Nam = Name_Test_Case;
14838 end Is_Subprogram_Contract_Annotation;
14840 --------------------------------------------------
14841 -- Is_Subprogram_Stub_Without_Prior_Declaration --
14842 --------------------------------------------------
14844 function Is_Subprogram_Stub_Without_Prior_Declaration
14845 (N : Node_Id) return Boolean
14848 -- A subprogram stub without prior declaration serves as declaration for
14849 -- the actual subprogram body. As such, it has an attached defining
14850 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
14852 return Nkind (N) = N_Subprogram_Body_Stub
14853 and then Ekind (Defining_Entity (N)) /= E_Subprogram_Body;
14854 end Is_Subprogram_Stub_Without_Prior_Declaration;
14856 --------------------------
14857 -- Is_Suspension_Object --
14858 --------------------------
14860 function Is_Suspension_Object (Id : Entity_Id) return Boolean is
14862 -- This approach does an exact name match rather than to rely on
14863 -- RTSfind. Routine Is_Effectively_Volatile is used by clients of the
14864 -- front end at point where all auxiliary tables are locked and any
14865 -- modifications to them are treated as violations. Do not tamper with
14866 -- the tables, instead examine the Chars fields of all the scopes of Id.
14869 Chars (Id) = Name_Suspension_Object
14870 and then Present (Scope (Id))
14871 and then Chars (Scope (Id)) = Name_Synchronous_Task_Control
14872 and then Present (Scope (Scope (Id)))
14873 and then Chars (Scope (Scope (Id))) = Name_Ada
14874 and then Present (Scope (Scope (Scope (Id))))
14875 and then Scope (Scope (Scope (Id))) = Standard_Standard;
14876 end Is_Suspension_Object;
14878 ----------------------------
14879 -- Is_Synchronized_Object --
14880 ----------------------------
14882 function Is_Synchronized_Object (Id : Entity_Id) return Boolean is
14886 if Is_Object (Id) then
14888 -- The object is synchronized if it is of a type that yields a
14889 -- synchronized object.
14891 if Yields_Synchronized_Object (Etype (Id)) then
14894 -- The object is synchronized if it is atomic and Async_Writers is
14897 elsif Is_Atomic (Id) and then Async_Writers_Enabled (Id) then
14900 -- A constant is a synchronized object by default
14902 elsif Ekind (Id) = E_Constant then
14905 -- A variable is a synchronized object if it is subject to pragma
14906 -- Constant_After_Elaboration.
14908 elsif Ekind (Id) = E_Variable then
14909 Prag := Get_Pragma (Id, Pragma_Constant_After_Elaboration);
14911 return Present (Prag) and then Is_Enabled_Pragma (Prag);
14915 -- Otherwise the input is not an object or it does not qualify as a
14916 -- synchronized object.
14919 end Is_Synchronized_Object;
14921 ---------------------------------
14922 -- Is_Synchronized_Tagged_Type --
14923 ---------------------------------
14925 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
14926 Kind : constant Entity_Kind := Ekind (Base_Type (E));
14929 -- A task or protected type derived from an interface is a tagged type.
14930 -- Such a tagged type is called a synchronized tagged type, as are
14931 -- synchronized interfaces and private extensions whose declaration
14932 -- includes the reserved word synchronized.
14934 return (Is_Tagged_Type (E)
14935 and then (Kind = E_Task_Type
14937 Kind = E_Protected_Type))
14940 and then Is_Synchronized_Interface (E))
14942 (Ekind (E) = E_Record_Type_With_Private
14943 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
14944 and then (Synchronized_Present (Parent (E))
14945 or else Is_Synchronized_Interface (Etype (E))));
14946 end Is_Synchronized_Tagged_Type;
14952 function Is_Transfer (N : Node_Id) return Boolean is
14953 Kind : constant Node_Kind := Nkind (N);
14956 if Kind = N_Simple_Return_Statement
14958 Kind = N_Extended_Return_Statement
14960 Kind = N_Goto_Statement
14962 Kind = N_Raise_Statement
14964 Kind = N_Requeue_Statement
14968 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
14969 and then No (Condition (N))
14973 elsif Kind = N_Procedure_Call_Statement
14974 and then Is_Entity_Name (Name (N))
14975 and then Present (Entity (Name (N)))
14976 and then No_Return (Entity (Name (N)))
14980 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
14992 function Is_True (U : Uint) return Boolean is
14997 --------------------------------------
14998 -- Is_Unchecked_Conversion_Instance --
14999 --------------------------------------
15001 function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is
15005 -- Look for a function whose generic parent is the predefined intrinsic
15006 -- function Unchecked_Conversion, or for one that renames such an
15009 if Ekind (Id) = E_Function then
15010 Par := Parent (Id);
15012 if Nkind (Par) = N_Function_Specification then
15013 Par := Generic_Parent (Par);
15015 if Present (Par) then
15017 Chars (Par) = Name_Unchecked_Conversion
15018 and then Is_Intrinsic_Subprogram (Par)
15019 and then Is_Predefined_File_Name
15020 (Unit_File_Name (Get_Source_Unit (Par)));
15023 Present (Alias (Id))
15024 and then Is_Unchecked_Conversion_Instance (Alias (Id));
15030 end Is_Unchecked_Conversion_Instance;
15032 -------------------------------
15033 -- Is_Universal_Numeric_Type --
15034 -------------------------------
15036 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
15038 return T = Universal_Integer or else T = Universal_Real;
15039 end Is_Universal_Numeric_Type;
15041 ----------------------------
15042 -- Is_Variable_Size_Array --
15043 ----------------------------
15045 function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
15049 pragma Assert (Is_Array_Type (E));
15051 -- Check if some index is initialized with a non-constant value
15053 Idx := First_Index (E);
15054 while Present (Idx) loop
15055 if Nkind (Idx) = N_Range then
15056 if not Is_Constant_Bound (Low_Bound (Idx))
15057 or else not Is_Constant_Bound (High_Bound (Idx))
15063 Idx := Next_Index (Idx);
15067 end Is_Variable_Size_Array;
15069 -----------------------------
15070 -- Is_Variable_Size_Record --
15071 -----------------------------
15073 function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
15075 Comp_Typ : Entity_Id;
15078 pragma Assert (Is_Record_Type (E));
15080 Comp := First_Entity (E);
15081 while Present (Comp) loop
15082 Comp_Typ := Etype (Comp);
15084 -- Recursive call if the record type has discriminants
15086 if Is_Record_Type (Comp_Typ)
15087 and then Has_Discriminants (Comp_Typ)
15088 and then Is_Variable_Size_Record (Comp_Typ)
15092 elsif Is_Array_Type (Comp_Typ)
15093 and then Is_Variable_Size_Array (Comp_Typ)
15098 Next_Entity (Comp);
15102 end Is_Variable_Size_Record;
15108 function Is_Variable
15110 Use_Original_Node : Boolean := True) return Boolean
15112 Orig_Node : Node_Id;
15114 function In_Protected_Function (E : Entity_Id) return Boolean;
15115 -- Within a protected function, the private components of the enclosing
15116 -- protected type are constants. A function nested within a (protected)
15117 -- procedure is not itself protected. Within the body of a protected
15118 -- function the current instance of the protected type is a constant.
15120 function Is_Variable_Prefix (P : Node_Id) return Boolean;
15121 -- Prefixes can involve implicit dereferences, in which case we must
15122 -- test for the case of a reference of a constant access type, which can
15123 -- can never be a variable.
15125 ---------------------------
15126 -- In_Protected_Function --
15127 ---------------------------
15129 function In_Protected_Function (E : Entity_Id) return Boolean is
15134 -- E is the current instance of a type
15136 if Is_Type (E) then
15145 if not Is_Protected_Type (Prot) then
15149 S := Current_Scope;
15150 while Present (S) and then S /= Prot loop
15151 if Ekind (S) = E_Function and then Scope (S) = Prot then
15160 end In_Protected_Function;
15162 ------------------------
15163 -- Is_Variable_Prefix --
15164 ------------------------
15166 function Is_Variable_Prefix (P : Node_Id) return Boolean is
15168 if Is_Access_Type (Etype (P)) then
15169 return not Is_Access_Constant (Root_Type (Etype (P)));
15171 -- For the case of an indexed component whose prefix has a packed
15172 -- array type, the prefix has been rewritten into a type conversion.
15173 -- Determine variable-ness from the converted expression.
15175 elsif Nkind (P) = N_Type_Conversion
15176 and then not Comes_From_Source (P)
15177 and then Is_Array_Type (Etype (P))
15178 and then Is_Packed (Etype (P))
15180 return Is_Variable (Expression (P));
15183 return Is_Variable (P);
15185 end Is_Variable_Prefix;
15187 -- Start of processing for Is_Variable
15190 -- Special check, allow x'Deref(expr) as a variable
15192 if Nkind (N) = N_Attribute_Reference
15193 and then Attribute_Name (N) = Name_Deref
15198 -- Check if we perform the test on the original node since this may be a
15199 -- test of syntactic categories which must not be disturbed by whatever
15200 -- rewriting might have occurred. For example, an aggregate, which is
15201 -- certainly NOT a variable, could be turned into a variable by
15204 if Use_Original_Node then
15205 Orig_Node := Original_Node (N);
15210 -- Definitely OK if Assignment_OK is set. Since this is something that
15211 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
15213 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
15216 -- Normally we go to the original node, but there is one exception where
15217 -- we use the rewritten node, namely when it is an explicit dereference.
15218 -- The generated code may rewrite a prefix which is an access type with
15219 -- an explicit dereference. The dereference is a variable, even though
15220 -- the original node may not be (since it could be a constant of the
15223 -- In Ada 2005 we have a further case to consider: the prefix may be a
15224 -- function call given in prefix notation. The original node appears to
15225 -- be a selected component, but we need to examine the call.
15227 elsif Nkind (N) = N_Explicit_Dereference
15228 and then Nkind (Orig_Node) /= N_Explicit_Dereference
15229 and then Present (Etype (Orig_Node))
15230 and then Is_Access_Type (Etype (Orig_Node))
15232 -- Note that if the prefix is an explicit dereference that does not
15233 -- come from source, we must check for a rewritten function call in
15234 -- prefixed notation before other forms of rewriting, to prevent a
15238 (Nkind (Orig_Node) = N_Function_Call
15239 and then not Is_Access_Constant (Etype (Prefix (N))))
15241 Is_Variable_Prefix (Original_Node (Prefix (N)));
15243 -- in Ada 2012, the dereference may have been added for a type with
15244 -- a declared implicit dereference aspect. Check that it is not an
15245 -- access to constant.
15247 elsif Nkind (N) = N_Explicit_Dereference
15248 and then Present (Etype (Orig_Node))
15249 and then Ada_Version >= Ada_2012
15250 and then Has_Implicit_Dereference (Etype (Orig_Node))
15252 return not Is_Access_Constant (Etype (Prefix (N)));
15254 -- A function call is never a variable
15256 elsif Nkind (N) = N_Function_Call then
15259 -- All remaining checks use the original node
15261 elsif Is_Entity_Name (Orig_Node)
15262 and then Present (Entity (Orig_Node))
15265 E : constant Entity_Id := Entity (Orig_Node);
15266 K : constant Entity_Kind := Ekind (E);
15269 return (K = E_Variable
15270 and then Nkind (Parent (E)) /= N_Exception_Handler)
15271 or else (K = E_Component
15272 and then not In_Protected_Function (E))
15273 or else K = E_Out_Parameter
15274 or else K = E_In_Out_Parameter
15275 or else K = E_Generic_In_Out_Parameter
15277 -- Current instance of type. If this is a protected type, check
15278 -- we are not within the body of one of its protected functions.
15280 or else (Is_Type (E)
15281 and then In_Open_Scopes (E)
15282 and then not In_Protected_Function (E))
15284 or else (Is_Incomplete_Or_Private_Type (E)
15285 and then In_Open_Scopes (Full_View (E)));
15289 case Nkind (Orig_Node) is
15290 when N_Indexed_Component
15293 return Is_Variable_Prefix (Prefix (Orig_Node));
15295 when N_Selected_Component =>
15296 return (Is_Variable (Selector_Name (Orig_Node))
15297 and then Is_Variable_Prefix (Prefix (Orig_Node)))
15299 (Nkind (N) = N_Expanded_Name
15300 and then Scope (Entity (N)) = Entity (Prefix (N)));
15302 -- For an explicit dereference, the type of the prefix cannot
15303 -- be an access to constant or an access to subprogram.
15305 when N_Explicit_Dereference =>
15307 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
15309 return Is_Access_Type (Typ)
15310 and then not Is_Access_Constant (Root_Type (Typ))
15311 and then Ekind (Typ) /= E_Access_Subprogram_Type;
15314 -- The type conversion is the case where we do not deal with the
15315 -- context dependent special case of an actual parameter. Thus
15316 -- the type conversion is only considered a variable for the
15317 -- purposes of this routine if the target type is tagged. However,
15318 -- a type conversion is considered to be a variable if it does not
15319 -- come from source (this deals for example with the conversions
15320 -- of expressions to their actual subtypes).
15322 when N_Type_Conversion =>
15323 return Is_Variable (Expression (Orig_Node))
15325 (not Comes_From_Source (Orig_Node)
15327 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
15329 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
15331 -- GNAT allows an unchecked type conversion as a variable. This
15332 -- only affects the generation of internal expanded code, since
15333 -- calls to instantiations of Unchecked_Conversion are never
15334 -- considered variables (since they are function calls).
15336 when N_Unchecked_Type_Conversion =>
15337 return Is_Variable (Expression (Orig_Node));
15345 ------------------------------
15346 -- Is_Verifiable_DIC_Pragma --
15347 ------------------------------
15349 function Is_Verifiable_DIC_Pragma (Prag : Node_Id) return Boolean is
15350 Args : constant List_Id := Pragma_Argument_Associations (Prag);
15353 -- To qualify as verifiable, a DIC pragma must have a non-null argument
15357 and then Nkind (Get_Pragma_Arg (First (Args))) /= N_Null;
15358 end Is_Verifiable_DIC_Pragma;
15360 ---------------------------
15361 -- Is_Visibly_Controlled --
15362 ---------------------------
15364 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
15365 Root : constant Entity_Id := Root_Type (T);
15367 return Chars (Scope (Root)) = Name_Finalization
15368 and then Chars (Scope (Scope (Root))) = Name_Ada
15369 and then Scope (Scope (Scope (Root))) = Standard_Standard;
15370 end Is_Visibly_Controlled;
15372 --------------------------
15373 -- Is_Volatile_Function --
15374 --------------------------
15376 function Is_Volatile_Function (Func_Id : Entity_Id) return Boolean is
15378 pragma Assert (Ekind_In (Func_Id, E_Function, E_Generic_Function));
15380 -- A function declared within a protected type is volatile
15382 if Is_Protected_Type (Scope (Func_Id)) then
15385 -- An instance of Ada.Unchecked_Conversion is a volatile function if
15386 -- either the source or the target are effectively volatile.
15388 elsif Is_Unchecked_Conversion_Instance (Func_Id)
15389 and then Has_Effectively_Volatile_Profile (Func_Id)
15393 -- Otherwise the function is treated as volatile if it is subject to
15394 -- enabled pragma Volatile_Function.
15398 Is_Enabled_Pragma (Get_Pragma (Func_Id, Pragma_Volatile_Function));
15400 end Is_Volatile_Function;
15402 ------------------------
15403 -- Is_Volatile_Object --
15404 ------------------------
15406 function Is_Volatile_Object (N : Node_Id) return Boolean is
15408 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
15409 -- If prefix is an implicit dereference, examine designated type
15411 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
15412 -- Determines if given object has volatile components
15414 ------------------------
15415 -- Is_Volatile_Prefix --
15416 ------------------------
15418 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
15419 Typ : constant Entity_Id := Etype (N);
15422 if Is_Access_Type (Typ) then
15424 Dtyp : constant Entity_Id := Designated_Type (Typ);
15427 return Is_Volatile (Dtyp)
15428 or else Has_Volatile_Components (Dtyp);
15432 return Object_Has_Volatile_Components (N);
15434 end Is_Volatile_Prefix;
15436 ------------------------------------
15437 -- Object_Has_Volatile_Components --
15438 ------------------------------------
15440 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
15441 Typ : constant Entity_Id := Etype (N);
15444 if Is_Volatile (Typ)
15445 or else Has_Volatile_Components (Typ)
15449 elsif Is_Entity_Name (N)
15450 and then (Has_Volatile_Components (Entity (N))
15451 or else Is_Volatile (Entity (N)))
15455 elsif Nkind (N) = N_Indexed_Component
15456 or else Nkind (N) = N_Selected_Component
15458 return Is_Volatile_Prefix (Prefix (N));
15463 end Object_Has_Volatile_Components;
15465 -- Start of processing for Is_Volatile_Object
15468 if Nkind (N) = N_Defining_Identifier then
15469 return Is_Volatile (N) or else Is_Volatile (Etype (N));
15471 elsif Nkind (N) = N_Expanded_Name then
15472 return Is_Volatile_Object (Entity (N));
15474 elsif Is_Volatile (Etype (N))
15475 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
15479 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component)
15480 and then Is_Volatile_Prefix (Prefix (N))
15484 elsif Nkind (N) = N_Selected_Component
15485 and then Is_Volatile (Entity (Selector_Name (N)))
15492 end Is_Volatile_Object;
15494 ---------------------------
15495 -- Itype_Has_Declaration --
15496 ---------------------------
15498 function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
15500 pragma Assert (Is_Itype (Id));
15501 return Present (Parent (Id))
15502 and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
15503 N_Subtype_Declaration)
15504 and then Defining_Entity (Parent (Id)) = Id;
15505 end Itype_Has_Declaration;
15507 -------------------------
15508 -- Kill_Current_Values --
15509 -------------------------
15511 procedure Kill_Current_Values
15513 Last_Assignment_Only : Boolean := False)
15516 if Is_Assignable (Ent) then
15517 Set_Last_Assignment (Ent, Empty);
15520 if Is_Object (Ent) then
15521 if not Last_Assignment_Only then
15523 Set_Current_Value (Ent, Empty);
15525 -- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
15526 -- for a constant. Once the constant is elaborated, its value is
15527 -- not changed, therefore the associated flags that describe the
15528 -- value should not be modified either.
15530 if Ekind (Ent) = E_Constant then
15533 -- Non-constant entities
15536 if not Can_Never_Be_Null (Ent) then
15537 Set_Is_Known_Non_Null (Ent, False);
15540 Set_Is_Known_Null (Ent, False);
15542 -- Reset the Is_Known_Valid flag unless the type is always
15543 -- valid. This does not apply to a loop parameter because its
15544 -- bounds are defined by the loop header and therefore always
15547 if not Is_Known_Valid (Etype (Ent))
15548 and then Ekind (Ent) /= E_Loop_Parameter
15550 Set_Is_Known_Valid (Ent, False);
15555 end Kill_Current_Values;
15557 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
15560 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
15561 -- Clear current value for entity E and all entities chained to E
15563 ------------------------------------------
15564 -- Kill_Current_Values_For_Entity_Chain --
15565 ------------------------------------------
15567 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
15571 while Present (Ent) loop
15572 Kill_Current_Values (Ent, Last_Assignment_Only);
15575 end Kill_Current_Values_For_Entity_Chain;
15577 -- Start of processing for Kill_Current_Values
15580 -- Kill all saved checks, a special case of killing saved values
15582 if not Last_Assignment_Only then
15586 -- Loop through relevant scopes, which includes the current scope and
15587 -- any parent scopes if the current scope is a block or a package.
15589 S := Current_Scope;
15592 -- Clear current values of all entities in current scope
15594 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
15596 -- If scope is a package, also clear current values of all private
15597 -- entities in the scope.
15599 if Is_Package_Or_Generic_Package (S)
15600 or else Is_Concurrent_Type (S)
15602 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
15605 -- If this is a not a subprogram, deal with parents
15607 if not Is_Subprogram (S) then
15609 exit Scope_Loop when S = Standard_Standard;
15613 end loop Scope_Loop;
15614 end Kill_Current_Values;
15616 --------------------------
15617 -- Kill_Size_Check_Code --
15618 --------------------------
15620 procedure Kill_Size_Check_Code (E : Entity_Id) is
15622 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
15623 and then Present (Size_Check_Code (E))
15625 Remove (Size_Check_Code (E));
15626 Set_Size_Check_Code (E, Empty);
15628 end Kill_Size_Check_Code;
15630 --------------------------
15631 -- Known_To_Be_Assigned --
15632 --------------------------
15634 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
15635 P : constant Node_Id := Parent (N);
15640 -- Test left side of assignment
15642 when N_Assignment_Statement =>
15643 return N = Name (P);
15645 -- Function call arguments are never lvalues
15647 when N_Function_Call =>
15650 -- Positional parameter for procedure or accept call
15652 when N_Accept_Statement
15653 | N_Procedure_Call_Statement
15661 Proc := Get_Subprogram_Entity (P);
15667 -- If we are not a list member, something is strange, so
15668 -- be conservative and return False.
15670 if not Is_List_Member (N) then
15674 -- We are going to find the right formal by stepping forward
15675 -- through the formals, as we step backwards in the actuals.
15677 Form := First_Formal (Proc);
15680 -- If no formal, something is weird, so be conservative
15681 -- and return False.
15688 exit when No (Act);
15689 Next_Formal (Form);
15692 return Ekind (Form) /= E_In_Parameter;
15695 -- Named parameter for procedure or accept call
15697 when N_Parameter_Association =>
15703 Proc := Get_Subprogram_Entity (Parent (P));
15709 -- Loop through formals to find the one that matches
15711 Form := First_Formal (Proc);
15713 -- If no matching formal, that's peculiar, some kind of
15714 -- previous error, so return False to be conservative.
15715 -- Actually this also happens in legal code in the case
15716 -- where P is a parameter association for an Extra_Formal???
15722 -- Else test for match
15724 if Chars (Form) = Chars (Selector_Name (P)) then
15725 return Ekind (Form) /= E_In_Parameter;
15728 Next_Formal (Form);
15732 -- Test for appearing in a conversion that itself appears
15733 -- in an lvalue context, since this should be an lvalue.
15735 when N_Type_Conversion =>
15736 return Known_To_Be_Assigned (P);
15738 -- All other references are definitely not known to be modifications
15743 end Known_To_Be_Assigned;
15745 ---------------------------
15746 -- Last_Source_Statement --
15747 ---------------------------
15749 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
15753 N := Last (Statements (HSS));
15754 while Present (N) loop
15755 exit when Comes_From_Source (N);
15760 end Last_Source_Statement;
15762 ----------------------------------
15763 -- Matching_Static_Array_Bounds --
15764 ----------------------------------
15766 function Matching_Static_Array_Bounds
15768 R_Typ : Node_Id) return Boolean
15770 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
15771 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
15783 if L_Ndims /= R_Ndims then
15787 -- Unconstrained types do not have static bounds
15789 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
15793 -- First treat specially the first dimension, as the lower bound and
15794 -- length of string literals are not stored like those of arrays.
15796 if Ekind (L_Typ) = E_String_Literal_Subtype then
15797 L_Low := String_Literal_Low_Bound (L_Typ);
15798 L_Len := String_Literal_Length (L_Typ);
15800 L_Index := First_Index (L_Typ);
15801 Get_Index_Bounds (L_Index, L_Low, L_High);
15803 if Is_OK_Static_Expression (L_Low)
15805 Is_OK_Static_Expression (L_High)
15807 if Expr_Value (L_High) < Expr_Value (L_Low) then
15810 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
15817 if Ekind (R_Typ) = E_String_Literal_Subtype then
15818 R_Low := String_Literal_Low_Bound (R_Typ);
15819 R_Len := String_Literal_Length (R_Typ);
15821 R_Index := First_Index (R_Typ);
15822 Get_Index_Bounds (R_Index, R_Low, R_High);
15824 if Is_OK_Static_Expression (R_Low)
15826 Is_OK_Static_Expression (R_High)
15828 if Expr_Value (R_High) < Expr_Value (R_Low) then
15831 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
15838 if (Is_OK_Static_Expression (L_Low)
15840 Is_OK_Static_Expression (R_Low))
15841 and then Expr_Value (L_Low) = Expr_Value (R_Low)
15842 and then L_Len = R_Len
15849 -- Then treat all other dimensions
15851 for Indx in 2 .. L_Ndims loop
15855 Get_Index_Bounds (L_Index, L_Low, L_High);
15856 Get_Index_Bounds (R_Index, R_Low, R_High);
15858 if (Is_OK_Static_Expression (L_Low) and then
15859 Is_OK_Static_Expression (L_High) and then
15860 Is_OK_Static_Expression (R_Low) and then
15861 Is_OK_Static_Expression (R_High))
15862 and then (Expr_Value (L_Low) = Expr_Value (R_Low)
15864 Expr_Value (L_High) = Expr_Value (R_High))
15872 -- If we fall through the loop, all indexes matched
15875 end Matching_Static_Array_Bounds;
15877 -------------------
15878 -- May_Be_Lvalue --
15879 -------------------
15881 function May_Be_Lvalue (N : Node_Id) return Boolean is
15882 P : constant Node_Id := Parent (N);
15887 -- Test left side of assignment
15889 when N_Assignment_Statement =>
15890 return N = Name (P);
15892 -- Test prefix of component or attribute. Note that the prefix of an
15893 -- explicit or implicit dereference cannot be an l-value. In the case
15894 -- of a 'Read attribute, the reference can be an actual in the
15895 -- argument list of the attribute.
15897 when N_Attribute_Reference =>
15898 return (N = Prefix (P)
15899 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P)))
15901 Attribute_Name (P) = Name_Read;
15903 -- For an expanded name, the name is an lvalue if the expanded name
15904 -- is an lvalue, but the prefix is never an lvalue, since it is just
15905 -- the scope where the name is found.
15907 when N_Expanded_Name =>
15908 if N = Prefix (P) then
15909 return May_Be_Lvalue (P);
15914 -- For a selected component A.B, A is certainly an lvalue if A.B is.
15915 -- B is a little interesting, if we have A.B := 3, there is some
15916 -- discussion as to whether B is an lvalue or not, we choose to say
15917 -- it is. Note however that A is not an lvalue if it is of an access
15918 -- type since this is an implicit dereference.
15920 when N_Selected_Component =>
15922 and then Present (Etype (N))
15923 and then Is_Access_Type (Etype (N))
15927 return May_Be_Lvalue (P);
15930 -- For an indexed component or slice, the index or slice bounds is
15931 -- never an lvalue. The prefix is an lvalue if the indexed component
15932 -- or slice is an lvalue, except if it is an access type, where we
15933 -- have an implicit dereference.
15935 when N_Indexed_Component
15939 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
15943 return May_Be_Lvalue (P);
15946 -- Prefix of a reference is an lvalue if the reference is an lvalue
15948 when N_Reference =>
15949 return May_Be_Lvalue (P);
15951 -- Prefix of explicit dereference is never an lvalue
15953 when N_Explicit_Dereference =>
15956 -- Positional parameter for subprogram, entry, or accept call.
15957 -- In older versions of Ada function call arguments are never
15958 -- lvalues. In Ada 2012 functions can have in-out parameters.
15960 when N_Accept_Statement
15961 | N_Entry_Call_Statement
15962 | N_Subprogram_Call
15964 if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
15968 -- The following mechanism is clumsy and fragile. A single flag
15969 -- set in Resolve_Actuals would be preferable ???
15977 Proc := Get_Subprogram_Entity (P);
15983 -- If we are not a list member, something is strange, so be
15984 -- conservative and return True.
15986 if not Is_List_Member (N) then
15990 -- We are going to find the right formal by stepping forward
15991 -- through the formals, as we step backwards in the actuals.
15993 Form := First_Formal (Proc);
15996 -- If no formal, something is weird, so be conservative and
16004 exit when No (Act);
16005 Next_Formal (Form);
16008 return Ekind (Form) /= E_In_Parameter;
16011 -- Named parameter for procedure or accept call
16013 when N_Parameter_Association =>
16019 Proc := Get_Subprogram_Entity (Parent (P));
16025 -- Loop through formals to find the one that matches
16027 Form := First_Formal (Proc);
16029 -- If no matching formal, that's peculiar, some kind of
16030 -- previous error, so return True to be conservative.
16031 -- Actually happens with legal code for an unresolved call
16032 -- where we may get the wrong homonym???
16038 -- Else test for match
16040 if Chars (Form) = Chars (Selector_Name (P)) then
16041 return Ekind (Form) /= E_In_Parameter;
16044 Next_Formal (Form);
16048 -- Test for appearing in a conversion that itself appears in an
16049 -- lvalue context, since this should be an lvalue.
16051 when N_Type_Conversion =>
16052 return May_Be_Lvalue (P);
16054 -- Test for appearance in object renaming declaration
16056 when N_Object_Renaming_Declaration =>
16059 -- All other references are definitely not lvalues
16066 -----------------------
16067 -- Mark_Coextensions --
16068 -----------------------
16070 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
16071 Is_Dynamic : Boolean;
16072 -- Indicates whether the context causes nested coextensions to be
16073 -- dynamic or static
16075 function Mark_Allocator (N : Node_Id) return Traverse_Result;
16076 -- Recognize an allocator node and label it as a dynamic coextension
16078 --------------------
16079 -- Mark_Allocator --
16080 --------------------
16082 function Mark_Allocator (N : Node_Id) return Traverse_Result is
16084 if Nkind (N) = N_Allocator then
16086 Set_Is_Dynamic_Coextension (N);
16088 -- If the allocator expression is potentially dynamic, it may
16089 -- be expanded out of order and require dynamic allocation
16090 -- anyway, so we treat the coextension itself as dynamic.
16091 -- Potential optimization ???
16093 elsif Nkind (Expression (N)) = N_Qualified_Expression
16094 and then Nkind (Expression (Expression (N))) = N_Op_Concat
16096 Set_Is_Dynamic_Coextension (N);
16098 Set_Is_Static_Coextension (N);
16103 end Mark_Allocator;
16105 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
16107 -- Start of processing for Mark_Coextensions
16110 -- An allocator that appears on the right-hand side of an assignment is
16111 -- treated as a potentially dynamic coextension when the right-hand side
16112 -- is an allocator or a qualified expression.
16114 -- Obj := new ...'(new Coextension ...);
16116 if Nkind (Context_Nod) = N_Assignment_Statement then
16118 Nkind_In (Expression (Context_Nod), N_Allocator,
16119 N_Qualified_Expression);
16121 -- An allocator that appears within the expression of a simple return
16122 -- statement is treated as a potentially dynamic coextension when the
16123 -- expression is either aggregate, allocator, or qualified expression.
16125 -- return (new Coextension ...);
16126 -- return new ...'(new Coextension ...);
16128 elsif Nkind (Context_Nod) = N_Simple_Return_Statement then
16130 Nkind_In (Expression (Context_Nod), N_Aggregate,
16132 N_Qualified_Expression);
16134 -- An alloctor that appears within the initialization expression of an
16135 -- object declaration is considered a potentially dynamic coextension
16136 -- when the initialization expression is an allocator or a qualified
16139 -- Obj : ... := new ...'(new Coextension ...);
16141 -- A similar case arises when the object declaration is part of an
16142 -- extended return statement.
16144 -- return Obj : ... := new ...'(new Coextension ...);
16145 -- return Obj : ... := (new Coextension ...);
16147 elsif Nkind (Context_Nod) = N_Object_Declaration then
16149 Nkind_In (Root_Nod, N_Allocator, N_Qualified_Expression)
16151 Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
16153 -- This routine should not be called with constructs that cannot contain
16157 raise Program_Error;
16160 Mark_Allocators (Root_Nod);
16161 end Mark_Coextensions;
16163 ----------------------
16164 -- Needs_One_Actual --
16165 ----------------------
16167 function Needs_One_Actual (E : Entity_Id) return Boolean is
16168 Formal : Entity_Id;
16171 -- Ada 2005 or later, and formals present
16173 if Ada_Version >= Ada_2005
16174 and then Present (First_Formal (E))
16175 and then No (Default_Value (First_Formal (E)))
16177 Formal := Next_Formal (First_Formal (E));
16178 while Present (Formal) loop
16179 if No (Default_Value (Formal)) then
16183 Next_Formal (Formal);
16188 -- Ada 83/95 or no formals
16193 end Needs_One_Actual;
16195 ------------------------
16196 -- New_Copy_List_Tree --
16197 ------------------------
16199 function New_Copy_List_Tree (List : List_Id) return List_Id is
16204 if List = No_List then
16211 while Present (E) loop
16212 Append (New_Copy_Tree (E), NL);
16218 end New_Copy_List_Tree;
16220 -------------------
16221 -- New_Copy_Tree --
16222 -------------------
16224 function New_Copy_Tree
16226 Map : Elist_Id := No_Elist;
16227 New_Sloc : Source_Ptr := No_Location;
16228 New_Scope : Entity_Id := Empty) return Node_Id
16230 ------------------------------------
16231 -- Auxiliary Data and Subprograms --
16232 ------------------------------------
16234 use Atree.Unchecked_Access;
16235 use Atree_Private_Part;
16237 -- Our approach here requires a two pass traversal of the tree. The
16238 -- first pass visits all nodes that eventually will be copied looking
16239 -- for defining Itypes. If any defining Itypes are found, then they are
16240 -- copied, and an entry is added to the replacement map. In the second
16241 -- phase, the tree is copied, using the replacement map to replace any
16242 -- Itype references within the copied tree.
16244 -- The following hash tables are used if the Map supplied has more than
16245 -- hash threshold entries to speed up access to the map. If there are
16246 -- fewer entries, then the map is searched sequentially (because setting
16247 -- up a hash table for only a few entries takes more time than it saves.
16249 subtype NCT_Header_Num is Int range 0 .. 511;
16250 -- Defines range of headers in hash tables (512 headers)
16252 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
16253 -- Hash function used for hash operations
16259 -- The hash table NCT_Assoc associates old entities in the table with
16260 -- their corresponding new entities (i.e. the pairs of entries presented
16261 -- in the original Map argument are Key-Element pairs).
16263 package NCT_Assoc is new Simple_HTable (
16264 Header_Num => NCT_Header_Num,
16265 Element => Entity_Id,
16266 No_Element => Empty,
16268 Hash => New_Copy_Hash,
16269 Equal => Types."=");
16271 ---------------------
16272 -- NCT_Itype_Assoc --
16273 ---------------------
16275 -- The hash table NCT_Itype_Assoc contains entries only for those old
16276 -- nodes which have a non-empty Associated_Node_For_Itype set. The key
16277 -- is the associated node, and the element is the new node itself (NOT
16278 -- the associated node for the new node).
16280 package NCT_Itype_Assoc is new Simple_HTable (
16281 Header_Num => NCT_Header_Num,
16282 Element => Entity_Id,
16283 No_Element => Empty,
16285 Hash => New_Copy_Hash,
16286 Equal => Types."=");
16288 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
16289 -- Called during second phase to map entities into their corresponding
16290 -- copies using the hash table. If the argument is not an entity, or is
16291 -- not in the hash table, then it is returned unchanged.
16293 procedure Build_NCT_Hash_Tables;
16294 -- Builds hash tables.
16296 function Copy_Elist_With_Replacement
16297 (Old_Elist : Elist_Id) return Elist_Id;
16298 -- Called during second phase to copy element list doing replacements
16300 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
16301 -- Called during the second phase to process a copied Itype. The actual
16302 -- copy happened during the first phase (so that we could make the entry
16303 -- in the mapping), but we still have to deal with the descendants of
16304 -- the copied Itype and copy them where necessary.
16306 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
16307 -- Called during second phase to copy list doing replacements
16309 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
16310 -- Called during second phase to copy node doing replacements
16312 procedure Visit_Elist (E : Elist_Id);
16313 -- Called during first phase to visit all elements of an Elist
16315 procedure Visit_Field (F : Union_Id; N : Node_Id);
16316 -- Visit a single field, recursing to call Visit_Node or Visit_List if
16317 -- the field is a syntactic descendant of the current node (i.e. its
16318 -- parent is Node N).
16320 procedure Visit_Itype (Old_Itype : Entity_Id);
16321 -- Called during first phase to visit subsidiary fields of a defining
16322 -- Itype, and also create a copy and make an entry in the replacement
16323 -- map for the new copy.
16325 procedure Visit_List (L : List_Id);
16326 -- Called during first phase to visit all elements of a List
16328 procedure Visit_Node (N : Node_Or_Entity_Id);
16329 -- Called during first phase to visit a node and all its subtrees
16335 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
16339 if Nkind (N) not in N_Entity then
16343 Ent := NCT_Assoc.Get (Entity_Id (N));
16345 if Present (Ent) then
16353 ---------------------------
16354 -- Build_NCT_Hash_Tables --
16355 ---------------------------
16357 procedure Build_NCT_Hash_Tables is
16366 Elmt := First_Elmt (Map);
16367 while Present (Elmt) loop
16368 Ent := Node (Elmt);
16370 -- Get new entity, and associate old and new
16373 NCT_Assoc.Set (Ent, Node (Elmt));
16375 if Is_Type (Ent) then
16377 Anode : constant Entity_Id :=
16378 Associated_Node_For_Itype (Ent);
16381 if Present (Anode) then
16383 -- Enter a link between the associated node of the old
16384 -- Itype and the new Itype, for updating later when node
16387 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
16394 end Build_NCT_Hash_Tables;
16396 ---------------------------------
16397 -- Copy_Elist_With_Replacement --
16398 ---------------------------------
16400 function Copy_Elist_With_Replacement
16401 (Old_Elist : Elist_Id) return Elist_Id
16404 New_Elist : Elist_Id;
16407 if No (Old_Elist) then
16411 New_Elist := New_Elmt_List;
16413 M := First_Elmt (Old_Elist);
16414 while Present (M) loop
16415 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
16421 end Copy_Elist_With_Replacement;
16423 ---------------------------------
16424 -- Copy_Itype_With_Replacement --
16425 ---------------------------------
16427 -- This routine exactly parallels its phase one analog Visit_Itype,
16429 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
16431 -- Translate Next_Entity, Scope, and Etype fields, in case they
16432 -- reference entities that have been mapped into copies.
16434 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
16435 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
16437 if Present (New_Scope) then
16438 Set_Scope (New_Itype, New_Scope);
16440 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
16443 -- Copy referenced fields
16445 if Is_Discrete_Type (New_Itype) then
16446 Set_Scalar_Range (New_Itype,
16447 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
16449 elsif Has_Discriminants (Base_Type (New_Itype)) then
16450 Set_Discriminant_Constraint (New_Itype,
16451 Copy_Elist_With_Replacement
16452 (Discriminant_Constraint (New_Itype)));
16454 elsif Is_Array_Type (New_Itype) then
16455 if Present (First_Index (New_Itype)) then
16456 Set_First_Index (New_Itype,
16457 First (Copy_List_With_Replacement
16458 (List_Containing (First_Index (New_Itype)))));
16461 if Is_Packed (New_Itype) then
16462 Set_Packed_Array_Impl_Type (New_Itype,
16463 Copy_Node_With_Replacement
16464 (Packed_Array_Impl_Type (New_Itype)));
16467 end Copy_Itype_With_Replacement;
16469 --------------------------------
16470 -- Copy_List_With_Replacement --
16471 --------------------------------
16473 function Copy_List_With_Replacement
16474 (Old_List : List_Id) return List_Id
16476 New_List : List_Id;
16480 if Old_List = No_List then
16484 New_List := Empty_List;
16486 E := First (Old_List);
16487 while Present (E) loop
16488 Append (Copy_Node_With_Replacement (E), New_List);
16494 end Copy_List_With_Replacement;
16496 --------------------------------
16497 -- Copy_Node_With_Replacement --
16498 --------------------------------
16500 function Copy_Node_With_Replacement
16501 (Old_Node : Node_Id) return Node_Id
16503 New_Node : Node_Id;
16505 procedure Adjust_Named_Associations
16506 (Old_Node : Node_Id;
16507 New_Node : Node_Id);
16508 -- If a call node has named associations, these are chained through
16509 -- the First_Named_Actual, Next_Named_Actual links. These must be
16510 -- propagated separately to the new parameter list, because these
16511 -- are not syntactic fields.
16513 function Copy_Field_With_Replacement
16514 (Field : Union_Id) return Union_Id;
16515 -- Given Field, which is a field of Old_Node, return a copy of it
16516 -- if it is a syntactic field (i.e. its parent is Node), setting
16517 -- the parent of the copy to poit to New_Node. Otherwise returns
16518 -- the field (possibly mapped if it is an entity).
16520 -------------------------------
16521 -- Adjust_Named_Associations --
16522 -------------------------------
16524 procedure Adjust_Named_Associations
16525 (Old_Node : Node_Id;
16526 New_Node : Node_Id)
16531 Old_Next : Node_Id;
16532 New_Next : Node_Id;
16535 Old_E := First (Parameter_Associations (Old_Node));
16536 New_E := First (Parameter_Associations (New_Node));
16537 while Present (Old_E) loop
16538 if Nkind (Old_E) = N_Parameter_Association
16539 and then Present (Next_Named_Actual (Old_E))
16541 if First_Named_Actual (Old_Node) =
16542 Explicit_Actual_Parameter (Old_E)
16544 Set_First_Named_Actual
16545 (New_Node, Explicit_Actual_Parameter (New_E));
16548 -- Now scan parameter list from the beginning, to locate
16549 -- next named actual, which can be out of order.
16551 Old_Next := First (Parameter_Associations (Old_Node));
16552 New_Next := First (Parameter_Associations (New_Node));
16553 while Nkind (Old_Next) /= N_Parameter_Association
16554 or else Explicit_Actual_Parameter (Old_Next) /=
16555 Next_Named_Actual (Old_E)
16561 Set_Next_Named_Actual
16562 (New_E, Explicit_Actual_Parameter (New_Next));
16568 end Adjust_Named_Associations;
16570 ---------------------------------
16571 -- Copy_Field_With_Replacement --
16572 ---------------------------------
16574 function Copy_Field_With_Replacement
16575 (Field : Union_Id) return Union_Id
16578 if Field = Union_Id (Empty) then
16581 elsif Field in Node_Range then
16583 Old_N : constant Node_Id := Node_Id (Field);
16587 -- If syntactic field, as indicated by the parent pointer
16588 -- being set, then copy the referenced node recursively.
16590 if Parent (Old_N) = Old_Node then
16591 New_N := Copy_Node_With_Replacement (Old_N);
16593 if New_N /= Old_N then
16594 Set_Parent (New_N, New_Node);
16597 -- For semantic fields, update possible entity reference
16598 -- from the replacement map.
16601 New_N := Assoc (Old_N);
16604 return Union_Id (New_N);
16607 elsif Field in List_Range then
16609 Old_L : constant List_Id := List_Id (Field);
16613 -- If syntactic field, as indicated by the parent pointer,
16614 -- then recursively copy the entire referenced list.
16616 if Parent (Old_L) = Old_Node then
16617 New_L := Copy_List_With_Replacement (Old_L);
16618 Set_Parent (New_L, New_Node);
16620 -- For semantic list, just returned unchanged
16626 return Union_Id (New_L);
16629 -- Anything other than a list or a node is returned unchanged
16634 end Copy_Field_With_Replacement;
16636 -- Start of processing for Copy_Node_With_Replacement
16639 if Old_Node <= Empty_Or_Error then
16642 elsif Nkind (Old_Node) in N_Entity then
16643 return Assoc (Old_Node);
16646 New_Node := New_Copy (Old_Node);
16648 -- If the node we are copying is the associated node of a
16649 -- previously copied Itype, then adjust the associated node
16650 -- of the copy of that Itype accordingly.
16653 Ent : constant Entity_Id := NCT_Itype_Assoc.Get (Old_Node);
16656 if Present (Ent) then
16657 Set_Associated_Node_For_Itype (Ent, New_Node);
16661 -- Recursively copy descendants
16664 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
16666 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
16668 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
16670 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
16672 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
16674 -- Adjust Sloc of new node if necessary
16676 if New_Sloc /= No_Location then
16677 Set_Sloc (New_Node, New_Sloc);
16679 -- If we adjust the Sloc, then we are essentially making a
16680 -- completely new node, so the Comes_From_Source flag should
16681 -- be reset to the proper default value.
16683 Set_Comes_From_Source
16684 (New_Node, Default_Node.Comes_From_Source);
16687 -- If the node is a call and has named associations, set the
16688 -- corresponding links in the copy.
16690 if Nkind_In (Old_Node, N_Entry_Call_Statement,
16692 N_Procedure_Call_Statement)
16693 and then Present (First_Named_Actual (Old_Node))
16695 Adjust_Named_Associations (Old_Node, New_Node);
16698 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
16699 -- The replacement mechanism applies to entities, and is not used
16700 -- here. Eventually we may need a more general graph-copying
16701 -- routine. For now, do a sequential search to find desired node.
16703 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
16704 and then Present (First_Real_Statement (Old_Node))
16707 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
16711 N1 := First (Statements (Old_Node));
16712 N2 := First (Statements (New_Node));
16714 while N1 /= Old_F loop
16719 Set_First_Real_Statement (New_Node, N2);
16724 -- All done, return copied node
16727 end Copy_Node_With_Replacement;
16729 -------------------
16730 -- New_Copy_Hash --
16731 -------------------
16733 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
16735 return Nat (E) mod (NCT_Header_Num'Last + 1);
16742 procedure Visit_Elist (E : Elist_Id) is
16745 if Present (E) then
16746 Elmt := First_Elmt (E);
16748 while Elmt /= No_Elmt loop
16749 Visit_Node (Node (Elmt));
16759 procedure Visit_Field (F : Union_Id; N : Node_Id) is
16761 if F = Union_Id (Empty) then
16764 elsif F in Node_Range then
16766 -- Copy node if it is syntactic, i.e. its parent pointer is
16767 -- set to point to the field that referenced it (certain
16768 -- Itypes will also meet this criterion, which is fine, since
16769 -- these are clearly Itypes that do need to be copied, since
16770 -- we are copying their parent.)
16772 if Parent (Node_Id (F)) = N then
16773 Visit_Node (Node_Id (F));
16776 -- Another case, if we are pointing to an Itype, then we want
16777 -- to copy it if its associated node is somewhere in the tree
16780 -- Note: the exclusion of self-referential copies is just an
16781 -- optimization, since the search of the already copied list
16782 -- would catch it, but it is a common case (Etype pointing to
16783 -- itself for an Itype that is a base type).
16785 elsif Nkind (Node_Id (F)) in N_Entity
16786 and then Is_Itype (Entity_Id (F))
16787 and then Node_Id (F) /= N
16793 P := Associated_Node_For_Itype (Node_Id (F));
16794 while Present (P) loop
16796 Visit_Node (Node_Id (F));
16803 -- An Itype whose parent is not being copied definitely
16804 -- should NOT be copied, since it does not belong in any
16805 -- sense to the copied subtree.
16811 elsif F in List_Range and then Parent (List_Id (F)) = N then
16812 Visit_List (List_Id (F));
16821 procedure Visit_Itype (Old_Itype : Entity_Id) is
16822 New_Itype : Entity_Id;
16826 -- Itypes that describe the designated type of access to subprograms
16827 -- have the structure of subprogram declarations, with signatures,
16828 -- etc. Either we duplicate the signatures completely, or choose to
16829 -- share such itypes, which is fine because their elaboration will
16830 -- have no side effects.
16832 if Ekind (Old_Itype) = E_Subprogram_Type then
16836 New_Itype := New_Copy (Old_Itype);
16838 -- The new Itype has all the attributes of the old one, and we
16839 -- just copy the contents of the entity. However, the back-end
16840 -- needs different names for debugging purposes, so we create a
16841 -- new internal name for it in all cases.
16843 Set_Chars (New_Itype, New_Internal_Name ('T'));
16845 -- If our associated node is an entity that has already been copied,
16846 -- then set the associated node of the copy to point to the right
16847 -- copy. If we have copied an Itype that is itself the associated
16848 -- node of some previously copied Itype, then we set the right
16849 -- pointer in the other direction.
16851 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
16853 if Present (Ent) then
16854 Set_Associated_Node_For_Itype (New_Itype, Ent);
16857 Ent := NCT_Itype_Assoc.Get (Old_Itype);
16859 if Present (Ent) then
16860 Set_Associated_Node_For_Itype (Ent, New_Itype);
16862 -- If the hash table has no association for this Itype and its
16863 -- associated node, enter one now.
16866 NCT_Itype_Assoc.Set
16867 (Associated_Node_For_Itype (Old_Itype), New_Itype);
16870 if Present (Freeze_Node (New_Itype)) then
16871 Set_Is_Frozen (New_Itype, False);
16872 Set_Freeze_Node (New_Itype, Empty);
16875 -- Add new association to map
16877 NCT_Assoc.Set (Old_Itype, New_Itype);
16879 -- If a record subtype is simply copied, the entity list will be
16880 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
16882 if Ekind_In (Old_Itype, E_Class_Wide_Subtype, E_Record_Subtype) then
16883 Set_Cloned_Subtype (New_Itype, Old_Itype);
16886 -- Visit descendants that eventually get copied
16888 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
16890 if Is_Discrete_Type (Old_Itype) then
16891 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
16893 elsif Has_Discriminants (Base_Type (Old_Itype)) then
16894 -- ??? This should involve call to Visit_Field
16895 Visit_Elist (Discriminant_Constraint (Old_Itype));
16897 elsif Is_Array_Type (Old_Itype) then
16898 if Present (First_Index (Old_Itype)) then
16900 (Union_Id (List_Containing (First_Index (Old_Itype))),
16904 if Is_Packed (Old_Itype) then
16906 (Union_Id (Packed_Array_Impl_Type (Old_Itype)), Old_Itype);
16915 procedure Visit_List (L : List_Id) is
16918 if L /= No_List then
16921 while Present (N) loop
16932 procedure Visit_Node (N : Node_Or_Entity_Id) is
16934 -- Handle case of an Itype, which must be copied
16936 if Nkind (N) in N_Entity and then Is_Itype (N) then
16938 -- Nothing to do if already in the list. This can happen with an
16939 -- Itype entity that appears more than once in the tree. Note that
16940 -- we do not want to visit descendants in this case.
16942 if Present (NCT_Assoc.Get (Entity_Id (N))) then
16949 -- Visit descendants
16951 Visit_Field (Field1 (N), N);
16952 Visit_Field (Field2 (N), N);
16953 Visit_Field (Field3 (N), N);
16954 Visit_Field (Field4 (N), N);
16955 Visit_Field (Field5 (N), N);
16958 -- Start of processing for New_Copy_Tree
16961 Build_NCT_Hash_Tables;
16963 -- Hash table set up if required, now start phase one by visiting top
16964 -- node (we will recursively visit the descendants).
16966 Visit_Node (Source);
16968 -- Now the second phase of the copy can start. First we process all the
16969 -- mapped entities, copying their descendants.
16972 Old_E : Entity_Id := Empty;
16976 NCT_Assoc.Get_First (Old_E, New_E);
16977 while Present (New_E) loop
16978 if Is_Itype (New_E) then
16979 Copy_Itype_With_Replacement (New_E);
16982 NCT_Assoc.Get_Next (Old_E, New_E);
16986 -- Now we can copy the actual tree
16989 Result : constant Node_Id := Copy_Node_With_Replacement (Source);
16993 NCT_Itype_Assoc.Reset;
16999 -------------------------
17000 -- New_External_Entity --
17001 -------------------------
17003 function New_External_Entity
17004 (Kind : Entity_Kind;
17005 Scope_Id : Entity_Id;
17006 Sloc_Value : Source_Ptr;
17007 Related_Id : Entity_Id;
17008 Suffix : Character;
17009 Suffix_Index : Nat := 0;
17010 Prefix : Character := ' ') return Entity_Id
17012 N : constant Entity_Id :=
17013 Make_Defining_Identifier (Sloc_Value,
17015 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
17018 Set_Ekind (N, Kind);
17019 Set_Is_Internal (N, True);
17020 Append_Entity (N, Scope_Id);
17021 Set_Public_Status (N);
17023 if Kind in Type_Kind then
17024 Init_Size_Align (N);
17028 end New_External_Entity;
17030 -------------------------
17031 -- New_Internal_Entity --
17032 -------------------------
17034 function New_Internal_Entity
17035 (Kind : Entity_Kind;
17036 Scope_Id : Entity_Id;
17037 Sloc_Value : Source_Ptr;
17038 Id_Char : Character) return Entity_Id
17040 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
17043 Set_Ekind (N, Kind);
17044 Set_Is_Internal (N, True);
17045 Append_Entity (N, Scope_Id);
17047 if Kind in Type_Kind then
17048 Init_Size_Align (N);
17052 end New_Internal_Entity;
17058 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
17062 -- If we are pointing at a positional parameter, it is a member of a
17063 -- node list (the list of parameters), and the next parameter is the
17064 -- next node on the list, unless we hit a parameter association, then
17065 -- we shift to using the chain whose head is the First_Named_Actual in
17066 -- the parent, and then is threaded using the Next_Named_Actual of the
17067 -- Parameter_Association. All this fiddling is because the original node
17068 -- list is in the textual call order, and what we need is the
17069 -- declaration order.
17071 if Is_List_Member (Actual_Id) then
17072 N := Next (Actual_Id);
17074 if Nkind (N) = N_Parameter_Association then
17075 return First_Named_Actual (Parent (Actual_Id));
17081 return Next_Named_Actual (Parent (Actual_Id));
17085 procedure Next_Actual (Actual_Id : in out Node_Id) is
17087 Actual_Id := Next_Actual (Actual_Id);
17090 ----------------------------------
17091 -- New_Requires_Transient_Scope --
17092 ----------------------------------
17094 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
17095 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean;
17096 -- This is called for untagged records and protected types, with
17097 -- nondefaulted discriminants. Returns True if the size of function
17098 -- results is known at the call site, False otherwise. Returns False
17099 -- if there is a variant part that depends on the discriminants of
17100 -- this type, or if there is an array constrained by the discriminants
17101 -- of this type. ???Currently, this is overly conservative (the array
17102 -- could be nested inside some other record that is constrained by
17103 -- nondiscriminants). That is, the recursive calls are too conservative.
17105 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean;
17106 -- Returns True if Typ is a nonlimited record with defaulted
17107 -- discriminants whose max size makes it unsuitable for allocating on
17108 -- the primary stack.
17110 ------------------------------
17111 -- Caller_Known_Size_Record --
17112 ------------------------------
17114 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean is
17115 pragma Assert (Typ = Underlying_Type (Typ));
17118 if Has_Variant_Part (Typ) and then not Is_Definite_Subtype (Typ) then
17126 Comp := First_Entity (Typ);
17127 while Present (Comp) loop
17129 -- Only look at E_Component entities. No need to look at
17130 -- E_Discriminant entities, and we must ignore internal
17131 -- subtypes generated for constrained components.
17133 if Ekind (Comp) = E_Component then
17135 Comp_Type : constant Entity_Id :=
17136 Underlying_Type (Etype (Comp));
17139 if Is_Record_Type (Comp_Type)
17141 Is_Protected_Type (Comp_Type)
17143 if not Caller_Known_Size_Record (Comp_Type) then
17147 elsif Is_Array_Type (Comp_Type) then
17148 if Size_Depends_On_Discriminant (Comp_Type) then
17155 Next_Entity (Comp);
17160 end Caller_Known_Size_Record;
17162 ------------------------------
17163 -- Large_Max_Size_Mutable --
17164 ------------------------------
17166 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean is
17167 pragma Assert (Typ = Underlying_Type (Typ));
17169 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean;
17170 -- Returns true if the discrete type T has a large range
17172 ----------------------------
17173 -- Is_Large_Discrete_Type --
17174 ----------------------------
17176 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean is
17177 Threshold : constant Int := 16;
17178 -- Arbitrary threshold above which we consider it "large". We want
17179 -- a fairly large threshold, because these large types really
17180 -- shouldn't have default discriminants in the first place, in
17184 return UI_To_Int (RM_Size (T)) > Threshold;
17185 end Is_Large_Discrete_Type;
17187 -- Start of processing for Large_Max_Size_Mutable
17190 if Is_Record_Type (Typ)
17191 and then not Is_Limited_View (Typ)
17192 and then Has_Defaulted_Discriminants (Typ)
17194 -- Loop through the components, looking for an array whose upper
17195 -- bound(s) depends on discriminants, where both the subtype of
17196 -- the discriminant and the index subtype are too large.
17202 Comp := First_Entity (Typ);
17203 while Present (Comp) loop
17204 if Ekind (Comp) = E_Component then
17206 Comp_Type : constant Entity_Id :=
17207 Underlying_Type (Etype (Comp));
17214 if Is_Array_Type (Comp_Type) then
17215 Indx := First_Index (Comp_Type);
17217 while Present (Indx) loop
17218 Ityp := Etype (Indx);
17219 Hi := Type_High_Bound (Ityp);
17221 if Nkind (Hi) = N_Identifier
17222 and then Ekind (Entity (Hi)) = E_Discriminant
17223 and then Is_Large_Discrete_Type (Ityp)
17224 and then Is_Large_Discrete_Type
17225 (Etype (Entity (Hi)))
17236 Next_Entity (Comp);
17242 end Large_Max_Size_Mutable;
17244 -- Local declarations
17246 Typ : constant Entity_Id := Underlying_Type (Id);
17248 -- Start of processing for New_Requires_Transient_Scope
17251 -- This is a private type which is not completed yet. This can only
17252 -- happen in a default expression (of a formal parameter or of a
17253 -- record component). Do not expand transient scope in this case.
17258 -- Do not expand transient scope for non-existent procedure return or
17259 -- string literal types.
17261 elsif Typ = Standard_Void_Type
17262 or else Ekind (Typ) = E_String_Literal_Subtype
17266 -- If Typ is a generic formal incomplete type, then we want to look at
17267 -- the actual type.
17269 elsif Ekind (Typ) = E_Record_Subtype
17270 and then Present (Cloned_Subtype (Typ))
17272 return New_Requires_Transient_Scope (Cloned_Subtype (Typ));
17274 -- Functions returning specific tagged types may dispatch on result, so
17275 -- their returned value is allocated on the secondary stack, even in the
17276 -- definite case. We must treat nondispatching functions the same way,
17277 -- because access-to-function types can point at both, so the calling
17278 -- conventions must be compatible. Is_Tagged_Type includes controlled
17279 -- types and class-wide types. Controlled type temporaries need
17282 -- ???It's not clear why we need to return noncontrolled types with
17283 -- controlled components on the secondary stack.
17285 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
17288 -- Untagged definite subtypes are known size. This includes all
17289 -- elementary [sub]types. Tasks are known size even if they have
17290 -- discriminants. So we return False here, with one exception:
17291 -- For a type like:
17292 -- type T (Last : Natural := 0) is
17293 -- X : String (1 .. Last);
17295 -- we return True. That's because for "P(F(...));", where F returns T,
17296 -- we don't know the size of the result at the call site, so if we
17297 -- allocated it on the primary stack, we would have to allocate the
17298 -- maximum size, which is way too big.
17300 elsif Is_Definite_Subtype (Typ) or else Is_Task_Type (Typ) then
17301 return Large_Max_Size_Mutable (Typ);
17303 -- Indefinite (discriminated) untagged record or protected type
17305 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
17306 return not Caller_Known_Size_Record (Typ);
17308 -- Unconstrained array
17311 pragma Assert (Is_Array_Type (Typ) and not Is_Definite_Subtype (Typ));
17314 end New_Requires_Transient_Scope;
17316 -----------------------
17317 -- Normalize_Actuals --
17318 -----------------------
17320 -- Chain actuals according to formals of subprogram. If there are no named
17321 -- associations, the chain is simply the list of Parameter Associations,
17322 -- since the order is the same as the declaration order. If there are named
17323 -- associations, then the First_Named_Actual field in the N_Function_Call
17324 -- or N_Procedure_Call_Statement node points to the Parameter_Association
17325 -- node for the parameter that comes first in declaration order. The
17326 -- remaining named parameters are then chained in declaration order using
17327 -- Next_Named_Actual.
17329 -- This routine also verifies that the number of actuals is compatible with
17330 -- the number and default values of formals, but performs no type checking
17331 -- (type checking is done by the caller).
17333 -- If the matching succeeds, Success is set to True and the caller proceeds
17334 -- with type-checking. If the match is unsuccessful, then Success is set to
17335 -- False, and the caller attempts a different interpretation, if there is
17338 -- If the flag Report is on, the call is not overloaded, and a failure to
17339 -- match can be reported here, rather than in the caller.
17341 procedure Normalize_Actuals
17345 Success : out Boolean)
17347 Actuals : constant List_Id := Parameter_Associations (N);
17348 Actual : Node_Id := Empty;
17349 Formal : Entity_Id;
17350 Last : Node_Id := Empty;
17351 First_Named : Node_Id := Empty;
17354 Formals_To_Match : Integer := 0;
17355 Actuals_To_Match : Integer := 0;
17357 procedure Chain (A : Node_Id);
17358 -- Add named actual at the proper place in the list, using the
17359 -- Next_Named_Actual link.
17361 function Reporting return Boolean;
17362 -- Determines if an error is to be reported. To report an error, we
17363 -- need Report to be True, and also we do not report errors caused
17364 -- by calls to init procs that occur within other init procs. Such
17365 -- errors must always be cascaded errors, since if all the types are
17366 -- declared correctly, the compiler will certainly build decent calls.
17372 procedure Chain (A : Node_Id) is
17376 -- Call node points to first actual in list
17378 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
17381 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
17385 Set_Next_Named_Actual (Last, Empty);
17392 function Reporting return Boolean is
17397 elsif not Within_Init_Proc then
17400 elsif Is_Init_Proc (Entity (Name (N))) then
17408 -- Start of processing for Normalize_Actuals
17411 if Is_Access_Type (S) then
17413 -- The name in the call is a function call that returns an access
17414 -- to subprogram. The designated type has the list of formals.
17416 Formal := First_Formal (Designated_Type (S));
17418 Formal := First_Formal (S);
17421 while Present (Formal) loop
17422 Formals_To_Match := Formals_To_Match + 1;
17423 Next_Formal (Formal);
17426 -- Find if there is a named association, and verify that no positional
17427 -- associations appear after named ones.
17429 if Present (Actuals) then
17430 Actual := First (Actuals);
17433 while Present (Actual)
17434 and then Nkind (Actual) /= N_Parameter_Association
17436 Actuals_To_Match := Actuals_To_Match + 1;
17440 if No (Actual) and Actuals_To_Match = Formals_To_Match then
17442 -- Most common case: positional notation, no defaults
17447 elsif Actuals_To_Match > Formals_To_Match then
17449 -- Too many actuals: will not work
17452 if Is_Entity_Name (Name (N)) then
17453 Error_Msg_N ("too many arguments in call to&", Name (N));
17455 Error_Msg_N ("too many arguments in call", N);
17463 First_Named := Actual;
17465 while Present (Actual) loop
17466 if Nkind (Actual) /= N_Parameter_Association then
17468 ("positional parameters not allowed after named ones", Actual);
17473 Actuals_To_Match := Actuals_To_Match + 1;
17479 if Present (Actuals) then
17480 Actual := First (Actuals);
17483 Formal := First_Formal (S);
17484 while Present (Formal) loop
17486 -- Match the formals in order. If the corresponding actual is
17487 -- positional, nothing to do. Else scan the list of named actuals
17488 -- to find the one with the right name.
17490 if Present (Actual)
17491 and then Nkind (Actual) /= N_Parameter_Association
17494 Actuals_To_Match := Actuals_To_Match - 1;
17495 Formals_To_Match := Formals_To_Match - 1;
17498 -- For named parameters, search the list of actuals to find
17499 -- one that matches the next formal name.
17501 Actual := First_Named;
17503 while Present (Actual) loop
17504 if Chars (Selector_Name (Actual)) = Chars (Formal) then
17507 Actuals_To_Match := Actuals_To_Match - 1;
17508 Formals_To_Match := Formals_To_Match - 1;
17516 if Ekind (Formal) /= E_In_Parameter
17517 or else No (Default_Value (Formal))
17520 if (Comes_From_Source (S)
17521 or else Sloc (S) = Standard_Location)
17522 and then Is_Overloadable (S)
17526 Nkind_In (Parent (N), N_Procedure_Call_Statement,
17528 N_Parameter_Association)
17529 and then Ekind (S) /= E_Function
17531 Set_Etype (N, Etype (S));
17534 Error_Msg_Name_1 := Chars (S);
17535 Error_Msg_Sloc := Sloc (S);
17537 ("missing argument for parameter & "
17538 & "in call to % declared #", N, Formal);
17541 elsif Is_Overloadable (S) then
17542 Error_Msg_Name_1 := Chars (S);
17544 -- Point to type derivation that generated the
17547 Error_Msg_Sloc := Sloc (Parent (S));
17550 ("missing argument for parameter & "
17551 & "in call to % (inherited) #", N, Formal);
17555 ("missing argument for parameter &", N, Formal);
17563 Formals_To_Match := Formals_To_Match - 1;
17568 Next_Formal (Formal);
17571 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
17578 -- Find some superfluous named actual that did not get
17579 -- attached to the list of associations.
17581 Actual := First (Actuals);
17582 while Present (Actual) loop
17583 if Nkind (Actual) = N_Parameter_Association
17584 and then Actual /= Last
17585 and then No (Next_Named_Actual (Actual))
17587 -- A validity check may introduce a copy of a call that
17588 -- includes an extra actual (for example for an unrelated
17589 -- accessibility check). Check that the extra actual matches
17590 -- some extra formal, which must exist already because
17591 -- subprogram must be frozen at this point.
17593 if Present (Extra_Formals (S))
17594 and then not Comes_From_Source (Actual)
17595 and then Nkind (Actual) = N_Parameter_Association
17596 and then Chars (Extra_Formals (S)) =
17597 Chars (Selector_Name (Actual))
17602 ("unmatched actual & in call", Selector_Name (Actual));
17614 end Normalize_Actuals;
17616 --------------------------------
17617 -- Note_Possible_Modification --
17618 --------------------------------
17620 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
17621 Modification_Comes_From_Source : constant Boolean :=
17622 Comes_From_Source (Parent (N));
17628 -- Loop to find referenced entity, if there is one
17634 if Is_Entity_Name (Exp) then
17635 Ent := Entity (Exp);
17637 -- If the entity is missing, it is an undeclared identifier,
17638 -- and there is nothing to annotate.
17644 elsif Nkind (Exp) = N_Explicit_Dereference then
17646 P : constant Node_Id := Prefix (Exp);
17649 -- In formal verification mode, keep track of all reads and
17650 -- writes through explicit dereferences.
17652 if GNATprove_Mode then
17653 SPARK_Specific.Generate_Dereference (N, 'm');
17656 if Nkind (P) = N_Selected_Component
17657 and then Present (Entry_Formal (Entity (Selector_Name (P))))
17659 -- Case of a reference to an entry formal
17661 Ent := Entry_Formal (Entity (Selector_Name (P)));
17663 elsif Nkind (P) = N_Identifier
17664 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
17665 and then Present (Expression (Parent (Entity (P))))
17666 and then Nkind (Expression (Parent (Entity (P)))) =
17669 -- Case of a reference to a value on which side effects have
17672 Exp := Prefix (Expression (Parent (Entity (P))));
17680 elsif Nkind_In (Exp, N_Type_Conversion,
17681 N_Unchecked_Type_Conversion)
17683 Exp := Expression (Exp);
17686 elsif Nkind_In (Exp, N_Slice,
17687 N_Indexed_Component,
17688 N_Selected_Component)
17690 -- Special check, if the prefix is an access type, then return
17691 -- since we are modifying the thing pointed to, not the prefix.
17692 -- When we are expanding, most usually the prefix is replaced
17693 -- by an explicit dereference, and this test is not needed, but
17694 -- in some cases (notably -gnatc mode and generics) when we do
17695 -- not do full expansion, we need this special test.
17697 if Is_Access_Type (Etype (Prefix (Exp))) then
17700 -- Otherwise go to prefix and keep going
17703 Exp := Prefix (Exp);
17707 -- All other cases, not a modification
17713 -- Now look for entity being referenced
17715 if Present (Ent) then
17716 if Is_Object (Ent) then
17717 if Comes_From_Source (Exp)
17718 or else Modification_Comes_From_Source
17720 -- Give warning if pragma unmodified is given and we are
17721 -- sure this is a modification.
17723 if Has_Pragma_Unmodified (Ent) and then Sure then
17725 -- Note that the entity may be present only as a result
17726 -- of pragma Unused.
17728 if Has_Pragma_Unused (Ent) then
17729 Error_Msg_NE ("??pragma Unused given for &!", N, Ent);
17732 ("??pragma Unmodified given for &!", N, Ent);
17736 Set_Never_Set_In_Source (Ent, False);
17739 Set_Is_True_Constant (Ent, False);
17740 Set_Current_Value (Ent, Empty);
17741 Set_Is_Known_Null (Ent, False);
17743 if not Can_Never_Be_Null (Ent) then
17744 Set_Is_Known_Non_Null (Ent, False);
17747 -- Follow renaming chain
17749 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
17750 and then Present (Renamed_Object (Ent))
17752 Exp := Renamed_Object (Ent);
17754 -- If the entity is the loop variable in an iteration over
17755 -- a container, retrieve container expression to indicate
17756 -- possible modification.
17758 if Present (Related_Expression (Ent))
17759 and then Nkind (Parent (Related_Expression (Ent))) =
17760 N_Iterator_Specification
17762 Exp := Original_Node (Related_Expression (Ent));
17767 -- The expression may be the renaming of a subcomponent of an
17768 -- array or container. The assignment to the subcomponent is
17769 -- a modification of the container.
17771 elsif Comes_From_Source (Original_Node (Exp))
17772 and then Nkind_In (Original_Node (Exp), N_Selected_Component,
17773 N_Indexed_Component)
17775 Exp := Prefix (Original_Node (Exp));
17779 -- Generate a reference only if the assignment comes from
17780 -- source. This excludes, for example, calls to a dispatching
17781 -- assignment operation when the left-hand side is tagged. In
17782 -- GNATprove mode, we need those references also on generated
17783 -- code, as these are used to compute the local effects of
17786 if Modification_Comes_From_Source or GNATprove_Mode then
17787 Generate_Reference (Ent, Exp, 'm');
17789 -- If the target of the assignment is the bound variable
17790 -- in an iterator, indicate that the corresponding array
17791 -- or container is also modified.
17793 if Ada_Version >= Ada_2012
17794 and then Nkind (Parent (Ent)) = N_Iterator_Specification
17797 Domain : constant Node_Id := Name (Parent (Ent));
17800 -- TBD : in the full version of the construct, the
17801 -- domain of iteration can be given by an expression.
17803 if Is_Entity_Name (Domain) then
17804 Generate_Reference (Entity (Domain), Exp, 'm');
17805 Set_Is_True_Constant (Entity (Domain), False);
17806 Set_Never_Set_In_Source (Entity (Domain), False);
17815 -- If we are sure this is a modification from source, and we know
17816 -- this modifies a constant, then give an appropriate warning.
17819 and then Modification_Comes_From_Source
17820 and then Overlays_Constant (Ent)
17821 and then Address_Clause_Overlay_Warnings
17824 Addr : constant Node_Id := Address_Clause (Ent);
17829 Find_Overlaid_Entity (Addr, O_Ent, Off);
17831 Error_Msg_Sloc := Sloc (Addr);
17833 ("??constant& may be modified via address clause#",
17844 end Note_Possible_Modification;
17846 --------------------------------------
17847 -- Null_To_Null_Address_Convert_OK --
17848 --------------------------------------
17850 function Null_To_Null_Address_Convert_OK
17852 Typ : Entity_Id := Empty) return Boolean
17855 if not Relaxed_RM_Semantics then
17859 if Nkind (N) = N_Null then
17860 return Present (Typ) and then Is_Descendant_Of_Address (Typ);
17862 elsif Nkind_In (N, N_Op_Eq, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt, N_Op_Ne)
17865 L : constant Node_Id := Left_Opnd (N);
17866 R : constant Node_Id := Right_Opnd (N);
17869 -- We check the Etype of the complementary operand since the
17870 -- N_Null node is not decorated at this stage.
17873 ((Nkind (L) = N_Null
17874 and then Is_Descendant_Of_Address (Etype (R)))
17876 (Nkind (R) = N_Null
17877 and then Is_Descendant_Of_Address (Etype (L))));
17882 end Null_To_Null_Address_Convert_OK;
17884 -------------------------
17885 -- Object_Access_Level --
17886 -------------------------
17888 -- Returns the static accessibility level of the view denoted by Obj. Note
17889 -- that the value returned is the result of a call to Scope_Depth. Only
17890 -- scope depths associated with dynamic scopes can actually be returned.
17891 -- Since only relative levels matter for accessibility checking, the fact
17892 -- that the distance between successive levels of accessibility is not
17893 -- always one is immaterial (invariant: if level(E2) is deeper than
17894 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
17896 function Object_Access_Level (Obj : Node_Id) return Uint is
17897 function Is_Interface_Conversion (N : Node_Id) return Boolean;
17898 -- Determine whether N is a construct of the form
17899 -- Some_Type (Operand._tag'Address)
17900 -- This construct appears in the context of dispatching calls.
17902 function Reference_To (Obj : Node_Id) return Node_Id;
17903 -- An explicit dereference is created when removing side-effects from
17904 -- expressions for constraint checking purposes. In this case a local
17905 -- access type is created for it. The correct access level is that of
17906 -- the original source node. We detect this case by noting that the
17907 -- prefix of the dereference is created by an object declaration whose
17908 -- initial expression is a reference.
17910 -----------------------------
17911 -- Is_Interface_Conversion --
17912 -----------------------------
17914 function Is_Interface_Conversion (N : Node_Id) return Boolean is
17916 return Nkind (N) = N_Unchecked_Type_Conversion
17917 and then Nkind (Expression (N)) = N_Attribute_Reference
17918 and then Attribute_Name (Expression (N)) = Name_Address;
17919 end Is_Interface_Conversion;
17925 function Reference_To (Obj : Node_Id) return Node_Id is
17926 Pref : constant Node_Id := Prefix (Obj);
17928 if Is_Entity_Name (Pref)
17929 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
17930 and then Present (Expression (Parent (Entity (Pref))))
17931 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
17933 return (Prefix (Expression (Parent (Entity (Pref)))));
17943 -- Start of processing for Object_Access_Level
17946 if Nkind (Obj) = N_Defining_Identifier
17947 or else Is_Entity_Name (Obj)
17949 if Nkind (Obj) = N_Defining_Identifier then
17955 if Is_Prival (E) then
17956 E := Prival_Link (E);
17959 -- If E is a type then it denotes a current instance. For this case
17960 -- we add one to the normal accessibility level of the type to ensure
17961 -- that current instances are treated as always being deeper than
17962 -- than the level of any visible named access type (see 3.10.2(21)).
17964 if Is_Type (E) then
17965 return Type_Access_Level (E) + 1;
17967 elsif Present (Renamed_Object (E)) then
17968 return Object_Access_Level (Renamed_Object (E));
17970 -- Similarly, if E is a component of the current instance of a
17971 -- protected type, any instance of it is assumed to be at a deeper
17972 -- level than the type. For a protected object (whose type is an
17973 -- anonymous protected type) its components are at the same level
17974 -- as the type itself.
17976 elsif not Is_Overloadable (E)
17977 and then Ekind (Scope (E)) = E_Protected_Type
17978 and then Comes_From_Source (Scope (E))
17980 return Type_Access_Level (Scope (E)) + 1;
17983 -- Aliased formals of functions take their access level from the
17984 -- point of call, i.e. require a dynamic check. For static check
17985 -- purposes, this is smaller than the level of the subprogram
17986 -- itself. For procedures the aliased makes no difference.
17989 and then Is_Aliased (E)
17990 and then Ekind (Scope (E)) = E_Function
17992 return Type_Access_Level (Etype (E));
17995 return Scope_Depth (Enclosing_Dynamic_Scope (E));
17999 elsif Nkind (Obj) = N_Selected_Component then
18000 if Is_Access_Type (Etype (Prefix (Obj))) then
18001 return Type_Access_Level (Etype (Prefix (Obj)));
18003 return Object_Access_Level (Prefix (Obj));
18006 elsif Nkind (Obj) = N_Indexed_Component then
18007 if Is_Access_Type (Etype (Prefix (Obj))) then
18008 return Type_Access_Level (Etype (Prefix (Obj)));
18010 return Object_Access_Level (Prefix (Obj));
18013 elsif Nkind (Obj) = N_Explicit_Dereference then
18015 -- If the prefix is a selected access discriminant then we make a
18016 -- recursive call on the prefix, which will in turn check the level
18017 -- of the prefix object of the selected discriminant.
18019 -- In Ada 2012, if the discriminant has implicit dereference and
18020 -- the context is a selected component, treat this as an object of
18021 -- unknown scope (see below). This is necessary in compile-only mode;
18022 -- otherwise expansion will already have transformed the prefix into
18025 if Nkind (Prefix (Obj)) = N_Selected_Component
18026 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
18028 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
18030 (not Has_Implicit_Dereference
18031 (Entity (Selector_Name (Prefix (Obj))))
18032 or else Nkind (Parent (Obj)) /= N_Selected_Component)
18034 return Object_Access_Level (Prefix (Obj));
18036 -- Detect an interface conversion in the context of a dispatching
18037 -- call. Use the original form of the conversion to find the access
18038 -- level of the operand.
18040 elsif Is_Interface (Etype (Obj))
18041 and then Is_Interface_Conversion (Prefix (Obj))
18042 and then Nkind (Original_Node (Obj)) = N_Type_Conversion
18044 return Object_Access_Level (Original_Node (Obj));
18046 elsif not Comes_From_Source (Obj) then
18048 Ref : constant Node_Id := Reference_To (Obj);
18050 if Present (Ref) then
18051 return Object_Access_Level (Ref);
18053 return Type_Access_Level (Etype (Prefix (Obj)));
18058 return Type_Access_Level (Etype (Prefix (Obj)));
18061 elsif Nkind_In (Obj, N_Type_Conversion, N_Unchecked_Type_Conversion) then
18062 return Object_Access_Level (Expression (Obj));
18064 elsif Nkind (Obj) = N_Function_Call then
18066 -- Function results are objects, so we get either the access level of
18067 -- the function or, in the case of an indirect call, the level of the
18068 -- access-to-subprogram type. (This code is used for Ada 95, but it
18069 -- looks wrong, because it seems that we should be checking the level
18070 -- of the call itself, even for Ada 95. However, using the Ada 2005
18071 -- version of the code causes regressions in several tests that are
18072 -- compiled with -gnat95. ???)
18074 if Ada_Version < Ada_2005 then
18075 if Is_Entity_Name (Name (Obj)) then
18076 return Subprogram_Access_Level (Entity (Name (Obj)));
18078 return Type_Access_Level (Etype (Prefix (Name (Obj))));
18081 -- For Ada 2005, the level of the result object of a function call is
18082 -- defined to be the level of the call's innermost enclosing master.
18083 -- We determine that by querying the depth of the innermost enclosing
18087 Return_Master_Scope_Depth_Of_Call : declare
18088 function Innermost_Master_Scope_Depth
18089 (N : Node_Id) return Uint;
18090 -- Returns the scope depth of the given node's innermost
18091 -- enclosing dynamic scope (effectively the accessibility
18092 -- level of the innermost enclosing master).
18094 ----------------------------------
18095 -- Innermost_Master_Scope_Depth --
18096 ----------------------------------
18098 function Innermost_Master_Scope_Depth
18099 (N : Node_Id) return Uint
18101 Node_Par : Node_Id := Parent (N);
18104 -- Locate the nearest enclosing node (by traversing Parents)
18105 -- that Defining_Entity can be applied to, and return the
18106 -- depth of that entity's nearest enclosing dynamic scope.
18108 while Present (Node_Par) loop
18109 case Nkind (Node_Par) is
18110 when N_Abstract_Subprogram_Declaration
18111 | N_Block_Statement
18113 | N_Component_Declaration
18115 | N_Entry_Declaration
18116 | N_Exception_Declaration
18117 | N_Formal_Object_Declaration
18118 | N_Formal_Package_Declaration
18119 | N_Formal_Subprogram_Declaration
18120 | N_Formal_Type_Declaration
18121 | N_Full_Type_Declaration
18122 | N_Function_Specification
18123 | N_Generic_Declaration
18124 | N_Generic_Instantiation
18125 | N_Implicit_Label_Declaration
18126 | N_Incomplete_Type_Declaration
18127 | N_Loop_Parameter_Specification
18128 | N_Number_Declaration
18129 | N_Object_Declaration
18130 | N_Package_Declaration
18131 | N_Package_Specification
18132 | N_Parameter_Specification
18133 | N_Private_Extension_Declaration
18134 | N_Private_Type_Declaration
18135 | N_Procedure_Specification
18137 | N_Protected_Type_Declaration
18138 | N_Renaming_Declaration
18139 | N_Single_Protected_Declaration
18140 | N_Single_Task_Declaration
18141 | N_Subprogram_Declaration
18142 | N_Subtype_Declaration
18144 | N_Task_Type_Declaration
18147 (Nearest_Dynamic_Scope
18148 (Defining_Entity (Node_Par)));
18154 Node_Par := Parent (Node_Par);
18157 pragma Assert (False);
18159 -- Should never reach the following return
18161 return Scope_Depth (Current_Scope) + 1;
18162 end Innermost_Master_Scope_Depth;
18164 -- Start of processing for Return_Master_Scope_Depth_Of_Call
18167 return Innermost_Master_Scope_Depth (Obj);
18168 end Return_Master_Scope_Depth_Of_Call;
18171 -- For convenience we handle qualified expressions, even though they
18172 -- aren't technically object names.
18174 elsif Nkind (Obj) = N_Qualified_Expression then
18175 return Object_Access_Level (Expression (Obj));
18177 -- Ditto for aggregates. They have the level of the temporary that
18178 -- will hold their value.
18180 elsif Nkind (Obj) = N_Aggregate then
18181 return Object_Access_Level (Current_Scope);
18183 -- Otherwise return the scope level of Standard. (If there are cases
18184 -- that fall through to this point they will be treated as having
18185 -- global accessibility for now. ???)
18188 return Scope_Depth (Standard_Standard);
18190 end Object_Access_Level;
18192 ----------------------------------
18193 -- Old_Requires_Transient_Scope --
18194 ----------------------------------
18196 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
18197 Typ : constant Entity_Id := Underlying_Type (Id);
18200 -- This is a private type which is not completed yet. This can only
18201 -- happen in a default expression (of a formal parameter or of a
18202 -- record component). Do not expand transient scope in this case.
18207 -- Do not expand transient scope for non-existent procedure return
18209 elsif Typ = Standard_Void_Type then
18212 -- Elementary types do not require a transient scope
18214 elsif Is_Elementary_Type (Typ) then
18217 -- Generally, indefinite subtypes require a transient scope, since the
18218 -- back end cannot generate temporaries, since this is not a valid type
18219 -- for declaring an object. It might be possible to relax this in the
18220 -- future, e.g. by declaring the maximum possible space for the type.
18222 elsif not Is_Definite_Subtype (Typ) then
18225 -- Functions returning tagged types may dispatch on result so their
18226 -- returned value is allocated on the secondary stack. Controlled
18227 -- type temporaries need finalization.
18229 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
18234 elsif Is_Record_Type (Typ) then
18239 Comp := First_Entity (Typ);
18240 while Present (Comp) loop
18241 if Ekind (Comp) = E_Component then
18243 -- ???It's not clear we need a full recursive call to
18244 -- Old_Requires_Transient_Scope here. Note that the
18245 -- following can't happen.
18247 pragma Assert (Is_Definite_Subtype (Etype (Comp)));
18248 pragma Assert (not Has_Controlled_Component (Etype (Comp)));
18250 if Old_Requires_Transient_Scope (Etype (Comp)) then
18255 Next_Entity (Comp);
18261 -- String literal types never require transient scope
18263 elsif Ekind (Typ) = E_String_Literal_Subtype then
18266 -- Array type. Note that we already know that this is a constrained
18267 -- array, since unconstrained arrays will fail the indefinite test.
18269 elsif Is_Array_Type (Typ) then
18271 -- If component type requires a transient scope, the array does too
18273 if Old_Requires_Transient_Scope (Component_Type (Typ)) then
18276 -- Otherwise, we only need a transient scope if the size depends on
18277 -- the value of one or more discriminants.
18280 return Size_Depends_On_Discriminant (Typ);
18283 -- All other cases do not require a transient scope
18286 pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
18289 end Old_Requires_Transient_Scope;
18291 ---------------------------------
18292 -- Original_Aspect_Pragma_Name --
18293 ---------------------------------
18295 function Original_Aspect_Pragma_Name (N : Node_Id) return Name_Id is
18297 Item_Nam : Name_Id;
18300 pragma Assert (Nkind_In (N, N_Aspect_Specification, N_Pragma));
18304 -- The pragma was generated to emulate an aspect, use the original
18305 -- aspect specification.
18307 if Nkind (Item) = N_Pragma and then From_Aspect_Specification (Item) then
18308 Item := Corresponding_Aspect (Item);
18311 -- Retrieve the name of the aspect/pragma. Note that Pre, Pre_Class,
18312 -- Post and Post_Class rewrite their pragma identifier to preserve the
18314 -- ??? this is kludgey
18316 if Nkind (Item) = N_Pragma then
18317 Item_Nam := Chars (Original_Node (Pragma_Identifier (Item)));
18320 pragma Assert (Nkind (Item) = N_Aspect_Specification);
18321 Item_Nam := Chars (Identifier (Item));
18324 -- Deal with 'Class by converting the name to its _XXX form
18326 if Class_Present (Item) then
18327 if Item_Nam = Name_Invariant then
18328 Item_Nam := Name_uInvariant;
18330 elsif Item_Nam = Name_Post then
18331 Item_Nam := Name_uPost;
18333 elsif Item_Nam = Name_Pre then
18334 Item_Nam := Name_uPre;
18336 elsif Nam_In (Item_Nam, Name_Type_Invariant,
18337 Name_Type_Invariant_Class)
18339 Item_Nam := Name_uType_Invariant;
18341 -- Nothing to do for other cases (e.g. a Check that derived from
18342 -- Pre_Class and has the flag set). Also we do nothing if the name
18343 -- is already in special _xxx form.
18349 end Original_Aspect_Pragma_Name;
18351 --------------------------------------
18352 -- Original_Corresponding_Operation --
18353 --------------------------------------
18355 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
18357 Typ : constant Entity_Id := Find_Dispatching_Type (S);
18360 -- If S is an inherited primitive S2 the original corresponding
18361 -- operation of S is the original corresponding operation of S2
18363 if Present (Alias (S))
18364 and then Find_Dispatching_Type (Alias (S)) /= Typ
18366 return Original_Corresponding_Operation (Alias (S));
18368 -- If S overrides an inherited subprogram S2 the original corresponding
18369 -- operation of S is the original corresponding operation of S2
18371 elsif Present (Overridden_Operation (S)) then
18372 return Original_Corresponding_Operation (Overridden_Operation (S));
18374 -- otherwise it is S itself
18379 end Original_Corresponding_Operation;
18381 -------------------
18382 -- Output_Entity --
18383 -------------------
18385 procedure Output_Entity (Id : Entity_Id) is
18389 Scop := Scope (Id);
18391 -- The entity may lack a scope when it is in the process of being
18392 -- analyzed. Use the current scope as an approximation.
18395 Scop := Current_Scope;
18398 Output_Name (Chars (Id), Scop);
18405 procedure Output_Name (Nam : Name_Id; Scop : Entity_Id := Current_Scope) is
18409 (Get_Qualified_Name
18416 ----------------------
18417 -- Policy_In_Effect --
18418 ----------------------
18420 function Policy_In_Effect (Policy : Name_Id) return Name_Id is
18421 function Policy_In_List (List : Node_Id) return Name_Id;
18422 -- Determine the mode of a policy in a N_Pragma list
18424 --------------------
18425 -- Policy_In_List --
18426 --------------------
18428 function Policy_In_List (List : Node_Id) return Name_Id is
18435 while Present (Prag) loop
18436 Arg1 := First (Pragma_Argument_Associations (Prag));
18437 Arg2 := Next (Arg1);
18439 Arg1 := Get_Pragma_Arg (Arg1);
18440 Arg2 := Get_Pragma_Arg (Arg2);
18442 -- The current Check_Policy pragma matches the requested policy or
18443 -- appears in the single argument form (Assertion, policy_id).
18445 if Nam_In (Chars (Arg1), Name_Assertion, Policy) then
18446 return Chars (Arg2);
18449 Prag := Next_Pragma (Prag);
18453 end Policy_In_List;
18459 -- Start of processing for Policy_In_Effect
18462 if not Is_Valid_Assertion_Kind (Policy) then
18463 raise Program_Error;
18466 -- Inspect all policy pragmas that appear within scopes (if any)
18468 Kind := Policy_In_List (Check_Policy_List);
18470 -- Inspect all configuration policy pragmas (if any)
18472 if Kind = No_Name then
18473 Kind := Policy_In_List (Check_Policy_List_Config);
18476 -- The context lacks policy pragmas, determine the mode based on whether
18477 -- assertions are enabled at the configuration level. This ensures that
18478 -- the policy is preserved when analyzing generics.
18480 if Kind = No_Name then
18481 if Assertions_Enabled_Config then
18482 Kind := Name_Check;
18484 Kind := Name_Ignore;
18489 end Policy_In_Effect;
18491 ----------------------------------
18492 -- Predicate_Tests_On_Arguments --
18493 ----------------------------------
18495 function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean is
18497 -- Always test predicates on indirect call
18499 if Ekind (Subp) = E_Subprogram_Type then
18502 -- Do not test predicates on call to generated default Finalize, since
18503 -- we are not interested in whether something we are finalizing (and
18504 -- typically destroying) satisfies its predicates.
18506 elsif Chars (Subp) = Name_Finalize
18507 and then not Comes_From_Source (Subp)
18511 -- Do not test predicates on any internally generated routines
18513 elsif Is_Internal_Name (Chars (Subp)) then
18516 -- Do not test predicates on call to Init_Proc, since if needed the
18517 -- predicate test will occur at some other point.
18519 elsif Is_Init_Proc (Subp) then
18522 -- Do not test predicates on call to predicate function, since this
18523 -- would cause infinite recursion.
18525 elsif Ekind (Subp) = E_Function
18526 and then (Is_Predicate_Function (Subp)
18528 Is_Predicate_Function_M (Subp))
18532 -- For now, no other exceptions
18537 end Predicate_Tests_On_Arguments;
18539 -----------------------
18540 -- Private_Component --
18541 -----------------------
18543 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
18544 Ancestor : constant Entity_Id := Base_Type (Type_Id);
18546 function Trace_Components
18548 Check : Boolean) return Entity_Id;
18549 -- Recursive function that does the work, and checks against circular
18550 -- definition for each subcomponent type.
18552 ----------------------
18553 -- Trace_Components --
18554 ----------------------
18556 function Trace_Components
18558 Check : Boolean) return Entity_Id
18560 Btype : constant Entity_Id := Base_Type (T);
18561 Component : Entity_Id;
18563 Candidate : Entity_Id := Empty;
18566 if Check and then Btype = Ancestor then
18567 Error_Msg_N ("circular type definition", Type_Id);
18571 if Is_Private_Type (Btype) and then not Is_Generic_Type (Btype) then
18572 if Present (Full_View (Btype))
18573 and then Is_Record_Type (Full_View (Btype))
18574 and then not Is_Frozen (Btype)
18576 -- To indicate that the ancestor depends on a private type, the
18577 -- current Btype is sufficient. However, to check for circular
18578 -- definition we must recurse on the full view.
18580 Candidate := Trace_Components (Full_View (Btype), True);
18582 if Candidate = Any_Type then
18592 elsif Is_Array_Type (Btype) then
18593 return Trace_Components (Component_Type (Btype), True);
18595 elsif Is_Record_Type (Btype) then
18596 Component := First_Entity (Btype);
18597 while Present (Component)
18598 and then Comes_From_Source (Component)
18600 -- Skip anonymous types generated by constrained components
18602 if not Is_Type (Component) then
18603 P := Trace_Components (Etype (Component), True);
18605 if Present (P) then
18606 if P = Any_Type then
18614 Next_Entity (Component);
18622 end Trace_Components;
18624 -- Start of processing for Private_Component
18627 return Trace_Components (Type_Id, False);
18628 end Private_Component;
18630 ---------------------------
18631 -- Primitive_Names_Match --
18632 ---------------------------
18634 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
18635 function Non_Internal_Name (E : Entity_Id) return Name_Id;
18636 -- Given an internal name, returns the corresponding non-internal name
18638 ------------------------
18639 -- Non_Internal_Name --
18640 ------------------------
18642 function Non_Internal_Name (E : Entity_Id) return Name_Id is
18644 Get_Name_String (Chars (E));
18645 Name_Len := Name_Len - 1;
18647 end Non_Internal_Name;
18649 -- Start of processing for Primitive_Names_Match
18652 pragma Assert (Present (E1) and then Present (E2));
18654 return Chars (E1) = Chars (E2)
18656 (not Is_Internal_Name (Chars (E1))
18657 and then Is_Internal_Name (Chars (E2))
18658 and then Non_Internal_Name (E2) = Chars (E1))
18660 (not Is_Internal_Name (Chars (E2))
18661 and then Is_Internal_Name (Chars (E1))
18662 and then Non_Internal_Name (E1) = Chars (E2))
18664 (Is_Predefined_Dispatching_Operation (E1)
18665 and then Is_Predefined_Dispatching_Operation (E2)
18666 and then Same_TSS (E1, E2))
18668 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
18669 end Primitive_Names_Match;
18671 -----------------------
18672 -- Process_End_Label --
18673 -----------------------
18675 procedure Process_End_Label
18684 Label_Ref : Boolean;
18685 -- Set True if reference to end label itself is required
18688 -- Gets set to the operator symbol or identifier that references the
18689 -- entity Ent. For the child unit case, this is the identifier from the
18690 -- designator. For other cases, this is simply Endl.
18692 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
18693 -- N is an identifier node that appears as a parent unit reference in
18694 -- the case where Ent is a child unit. This procedure generates an
18695 -- appropriate cross-reference entry. E is the corresponding entity.
18697 -------------------------
18698 -- Generate_Parent_Ref --
18699 -------------------------
18701 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
18703 -- If names do not match, something weird, skip reference
18705 if Chars (E) = Chars (N) then
18707 -- Generate the reference. We do NOT consider this as a reference
18708 -- for unreferenced symbol purposes.
18710 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
18712 if Style_Check then
18713 Style.Check_Identifier (N, E);
18716 end Generate_Parent_Ref;
18718 -- Start of processing for Process_End_Label
18721 -- If no node, ignore. This happens in some error situations, and
18722 -- also for some internally generated structures where no end label
18723 -- references are required in any case.
18729 -- Nothing to do if no End_Label, happens for internally generated
18730 -- constructs where we don't want an end label reference anyway. Also
18731 -- nothing to do if Endl is a string literal, which means there was
18732 -- some prior error (bad operator symbol)
18734 Endl := End_Label (N);
18736 if No (Endl) or else Nkind (Endl) = N_String_Literal then
18740 -- Reference node is not in extended main source unit
18742 if not In_Extended_Main_Source_Unit (N) then
18744 -- Generally we do not collect references except for the extended
18745 -- main source unit. The one exception is the 'e' entry for a
18746 -- package spec, where it is useful for a client to have the
18747 -- ending information to define scopes.
18753 Label_Ref := False;
18755 -- For this case, we can ignore any parent references, but we
18756 -- need the package name itself for the 'e' entry.
18758 if Nkind (Endl) = N_Designator then
18759 Endl := Identifier (Endl);
18763 -- Reference is in extended main source unit
18768 -- For designator, generate references for the parent entries
18770 if Nkind (Endl) = N_Designator then
18772 -- Generate references for the prefix if the END line comes from
18773 -- source (otherwise we do not need these references) We climb the
18774 -- scope stack to find the expected entities.
18776 if Comes_From_Source (Endl) then
18777 Nam := Name (Endl);
18778 Scop := Current_Scope;
18779 while Nkind (Nam) = N_Selected_Component loop
18780 Scop := Scope (Scop);
18781 exit when No (Scop);
18782 Generate_Parent_Ref (Selector_Name (Nam), Scop);
18783 Nam := Prefix (Nam);
18786 if Present (Scop) then
18787 Generate_Parent_Ref (Nam, Scope (Scop));
18791 Endl := Identifier (Endl);
18795 -- If the end label is not for the given entity, then either we have
18796 -- some previous error, or this is a generic instantiation for which
18797 -- we do not need to make a cross-reference in this case anyway. In
18798 -- either case we simply ignore the call.
18800 if Chars (Ent) /= Chars (Endl) then
18804 -- If label was really there, then generate a normal reference and then
18805 -- adjust the location in the end label to point past the name (which
18806 -- should almost always be the semicolon).
18808 Loc := Sloc (Endl);
18810 if Comes_From_Source (Endl) then
18812 -- If a label reference is required, then do the style check and
18813 -- generate an l-type cross-reference entry for the label
18816 if Style_Check then
18817 Style.Check_Identifier (Endl, Ent);
18820 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
18823 -- Set the location to point past the label (normally this will
18824 -- mean the semicolon immediately following the label). This is
18825 -- done for the sake of the 'e' or 't' entry generated below.
18827 Get_Decoded_Name_String (Chars (Endl));
18828 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
18831 -- In SPARK mode, no missing label is allowed for packages and
18832 -- subprogram bodies. Detect those cases by testing whether
18833 -- Process_End_Label was called for a body (Typ = 't') or a package.
18835 if Restriction_Check_Required (SPARK_05)
18836 and then (Typ = 't' or else Ekind (Ent) = E_Package)
18838 Error_Msg_Node_1 := Endl;
18839 Check_SPARK_05_Restriction
18840 ("`END &` required", Endl, Force => True);
18844 -- Now generate the e/t reference
18846 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
18848 -- Restore Sloc, in case modified above, since we have an identifier
18849 -- and the normal Sloc should be left set in the tree.
18851 Set_Sloc (Endl, Loc);
18852 end Process_End_Label;
18854 --------------------------------
18855 -- Propagate_Concurrent_Flags --
18856 --------------------------------
18858 procedure Propagate_Concurrent_Flags
18860 Comp_Typ : Entity_Id)
18863 if Has_Task (Comp_Typ) then
18864 Set_Has_Task (Typ);
18867 if Has_Protected (Comp_Typ) then
18868 Set_Has_Protected (Typ);
18871 if Has_Timing_Event (Comp_Typ) then
18872 Set_Has_Timing_Event (Typ);
18874 end Propagate_Concurrent_Flags;
18876 ------------------------------
18877 -- Propagate_DIC_Attributes --
18878 ------------------------------
18880 procedure Propagate_DIC_Attributes
18882 From_Typ : Entity_Id)
18884 DIC_Proc : Entity_Id;
18887 if Present (Typ) and then Present (From_Typ) then
18888 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
18890 -- Nothing to do if both the source and the destination denote the
18893 if From_Typ = Typ then
18897 DIC_Proc := DIC_Procedure (From_Typ);
18899 -- The setting of the attributes is intentionally conservative. This
18900 -- prevents accidental clobbering of enabled attributes.
18902 if Has_Inherited_DIC (From_Typ)
18903 and then not Has_Inherited_DIC (Typ)
18905 Set_Has_Inherited_DIC (Typ);
18908 if Has_Own_DIC (From_Typ) and then not Has_Own_DIC (Typ) then
18909 Set_Has_Own_DIC (Typ);
18912 if Present (DIC_Proc) and then No (DIC_Procedure (Typ)) then
18913 Set_DIC_Procedure (Typ, DIC_Proc);
18916 end Propagate_DIC_Attributes;
18918 ------------------------------------
18919 -- Propagate_Invariant_Attributes --
18920 ------------------------------------
18922 procedure Propagate_Invariant_Attributes
18924 From_Typ : Entity_Id)
18926 Full_IP : Entity_Id;
18927 Part_IP : Entity_Id;
18930 if Present (Typ) and then Present (From_Typ) then
18931 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
18933 -- Nothing to do if both the source and the destination denote the
18936 if From_Typ = Typ then
18940 Full_IP := Invariant_Procedure (From_Typ);
18941 Part_IP := Partial_Invariant_Procedure (From_Typ);
18943 -- The setting of the attributes is intentionally conservative. This
18944 -- prevents accidental clobbering of enabled attributes.
18946 if Has_Inheritable_Invariants (From_Typ)
18947 and then not Has_Inheritable_Invariants (Typ)
18949 Set_Has_Inheritable_Invariants (Typ, True);
18952 if Has_Inherited_Invariants (From_Typ)
18953 and then not Has_Inherited_Invariants (Typ)
18955 Set_Has_Inherited_Invariants (Typ, True);
18958 if Has_Own_Invariants (From_Typ)
18959 and then not Has_Own_Invariants (Typ)
18961 Set_Has_Own_Invariants (Typ, True);
18964 if Present (Full_IP) and then No (Invariant_Procedure (Typ)) then
18965 Set_Invariant_Procedure (Typ, Full_IP);
18968 if Present (Part_IP) and then No (Partial_Invariant_Procedure (Typ))
18970 Set_Partial_Invariant_Procedure (Typ, Part_IP);
18973 end Propagate_Invariant_Attributes;
18975 ---------------------------------------
18976 -- Record_Possible_Part_Of_Reference --
18977 ---------------------------------------
18979 procedure Record_Possible_Part_Of_Reference
18980 (Var_Id : Entity_Id;
18983 Encap : constant Entity_Id := Encapsulating_State (Var_Id);
18987 -- The variable is a constituent of a single protected/task type. Such
18988 -- a variable acts as a component of the type and must appear within a
18989 -- specific region (SPARK RM 9.3). Instead of recording the reference,
18990 -- verify its legality now.
18992 if Present (Encap) and then Is_Single_Concurrent_Object (Encap) then
18993 Check_Part_Of_Reference (Var_Id, Ref);
18995 -- The variable is subject to pragma Part_Of and may eventually become a
18996 -- constituent of a single protected/task type. Record the reference to
18997 -- verify its placement when the contract of the variable is analyzed.
18999 elsif Present (Get_Pragma (Var_Id, Pragma_Part_Of)) then
19000 Refs := Part_Of_References (Var_Id);
19003 Refs := New_Elmt_List;
19004 Set_Part_Of_References (Var_Id, Refs);
19007 Append_Elmt (Ref, Refs);
19009 end Record_Possible_Part_Of_Reference;
19015 function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
19016 Seen : Boolean := False;
19018 function Is_Reference (N : Node_Id) return Traverse_Result;
19019 -- Determine whether node N denotes a reference to Id. If this is the
19020 -- case, set global flag Seen to True and stop the traversal.
19026 function Is_Reference (N : Node_Id) return Traverse_Result is
19028 if Is_Entity_Name (N)
19029 and then Present (Entity (N))
19030 and then Entity (N) = Id
19039 procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
19041 -- Start of processing for Referenced
19044 Inspect_Expression (Expr);
19048 ------------------------------------
19049 -- References_Generic_Formal_Type --
19050 ------------------------------------
19052 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
19054 function Process (N : Node_Id) return Traverse_Result;
19055 -- Process one node in search for generic formal type
19061 function Process (N : Node_Id) return Traverse_Result is
19063 if Nkind (N) in N_Has_Entity then
19065 E : constant Entity_Id := Entity (N);
19067 if Present (E) then
19068 if Is_Generic_Type (E) then
19070 elsif Present (Etype (E))
19071 and then Is_Generic_Type (Etype (E))
19082 function Traverse is new Traverse_Func (Process);
19083 -- Traverse tree to look for generic type
19086 if Inside_A_Generic then
19087 return Traverse (N) = Abandon;
19091 end References_Generic_Formal_Type;
19093 --------------------
19094 -- Remove_Homonym --
19095 --------------------
19097 procedure Remove_Homonym (E : Entity_Id) is
19098 Prev : Entity_Id := Empty;
19102 if E = Current_Entity (E) then
19103 if Present (Homonym (E)) then
19104 Set_Current_Entity (Homonym (E));
19106 Set_Name_Entity_Id (Chars (E), Empty);
19110 H := Current_Entity (E);
19111 while Present (H) and then H /= E loop
19116 -- If E is not on the homonym chain, nothing to do
19118 if Present (H) then
19119 Set_Homonym (Prev, Homonym (E));
19122 end Remove_Homonym;
19124 ------------------------------
19125 -- Remove_Overloaded_Entity --
19126 ------------------------------
19128 procedure Remove_Overloaded_Entity (Id : Entity_Id) is
19129 procedure Remove_Primitive_Of (Typ : Entity_Id);
19130 -- Remove primitive subprogram Id from the list of primitives that
19131 -- belong to type Typ.
19133 -------------------------
19134 -- Remove_Primitive_Of --
19135 -------------------------
19137 procedure Remove_Primitive_Of (Typ : Entity_Id) is
19141 if Is_Tagged_Type (Typ) then
19142 Prims := Direct_Primitive_Operations (Typ);
19144 if Present (Prims) then
19145 Remove (Prims, Id);
19148 end Remove_Primitive_Of;
19152 Scop : constant Entity_Id := Scope (Id);
19153 Formal : Entity_Id;
19154 Prev_Id : Entity_Id;
19156 -- Start of processing for Remove_Overloaded_Entity
19159 -- Remove the entity from the homonym chain. When the entity is the
19160 -- head of the chain, associate the entry in the name table with its
19161 -- homonym effectively making it the new head of the chain.
19163 if Current_Entity (Id) = Id then
19164 Set_Name_Entity_Id (Chars (Id), Homonym (Id));
19166 -- Otherwise link the previous and next homonyms
19169 Prev_Id := Current_Entity (Id);
19170 while Present (Prev_Id) and then Homonym (Prev_Id) /= Id loop
19171 Prev_Id := Homonym (Prev_Id);
19174 Set_Homonym (Prev_Id, Homonym (Id));
19177 -- Remove the entity from the scope entity chain. When the entity is
19178 -- the head of the chain, set the next entity as the new head of the
19181 if First_Entity (Scop) = Id then
19183 Set_First_Entity (Scop, Next_Entity (Id));
19185 -- Otherwise the entity is either in the middle of the chain or it acts
19186 -- as its tail. Traverse and link the previous and next entities.
19189 Prev_Id := First_Entity (Scop);
19190 while Present (Prev_Id) and then Next_Entity (Prev_Id) /= Id loop
19191 Next_Entity (Prev_Id);
19194 Set_Next_Entity (Prev_Id, Next_Entity (Id));
19197 -- Handle the case where the entity acts as the tail of the scope entity
19200 if Last_Entity (Scop) = Id then
19201 Set_Last_Entity (Scop, Prev_Id);
19204 -- The entity denotes a primitive subprogram. Remove it from the list of
19205 -- primitives of the associated controlling type.
19207 if Ekind_In (Id, E_Function, E_Procedure) and then Is_Primitive (Id) then
19208 Formal := First_Formal (Id);
19209 while Present (Formal) loop
19210 if Is_Controlling_Formal (Formal) then
19211 Remove_Primitive_Of (Etype (Formal));
19215 Next_Formal (Formal);
19218 if Ekind (Id) = E_Function and then Has_Controlling_Result (Id) then
19219 Remove_Primitive_Of (Etype (Id));
19222 end Remove_Overloaded_Entity;
19224 ---------------------
19225 -- Rep_To_Pos_Flag --
19226 ---------------------
19228 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
19230 return New_Occurrence_Of
19231 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
19232 end Rep_To_Pos_Flag;
19234 --------------------
19235 -- Require_Entity --
19236 --------------------
19238 procedure Require_Entity (N : Node_Id) is
19240 if Is_Entity_Name (N) and then No (Entity (N)) then
19241 if Total_Errors_Detected /= 0 then
19242 Set_Entity (N, Any_Id);
19244 raise Program_Error;
19247 end Require_Entity;
19249 ------------------------------
19250 -- Requires_Transient_Scope --
19251 ------------------------------
19253 -- A transient scope is required when variable-sized temporaries are
19254 -- allocated on the secondary stack, or when finalization actions must be
19255 -- generated before the next instruction.
19257 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
19258 Old_Result : constant Boolean := Old_Requires_Transient_Scope (Id);
19261 if Debug_Flag_QQ then
19266 New_Result : constant Boolean := New_Requires_Transient_Scope (Id);
19269 -- Assert that we're not putting things on the secondary stack if we
19270 -- didn't before; we are trying to AVOID secondary stack when
19273 if not Old_Result then
19274 pragma Assert (not New_Result);
19278 if New_Result /= Old_Result then
19279 Results_Differ (Id, Old_Result, New_Result);
19284 end Requires_Transient_Scope;
19286 --------------------
19287 -- Results_Differ --
19288 --------------------
19290 procedure Results_Differ
19296 if False then -- False to disable; True for debugging
19297 Treepr.Print_Tree_Node (Id);
19299 if Old_Val = New_Val then
19300 raise Program_Error;
19303 end Results_Differ;
19305 --------------------------
19306 -- Reset_Analyzed_Flags --
19307 --------------------------
19309 procedure Reset_Analyzed_Flags (N : Node_Id) is
19310 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
19311 -- Function used to reset Analyzed flags in tree. Note that we do
19312 -- not reset Analyzed flags in entities, since there is no need to
19313 -- reanalyze entities, and indeed, it is wrong to do so, since it
19314 -- can result in generating auxiliary stuff more than once.
19316 --------------------
19317 -- Clear_Analyzed --
19318 --------------------
19320 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
19322 if Nkind (N) not in N_Entity then
19323 Set_Analyzed (N, False);
19327 end Clear_Analyzed;
19329 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
19331 -- Start of processing for Reset_Analyzed_Flags
19334 Reset_Analyzed (N);
19335 end Reset_Analyzed_Flags;
19337 ------------------------
19338 -- Restore_SPARK_Mode --
19339 ------------------------
19341 procedure Restore_SPARK_Mode (Mode : SPARK_Mode_Type) is
19343 SPARK_Mode := Mode;
19344 end Restore_SPARK_Mode;
19346 --------------------------------
19347 -- Returns_Unconstrained_Type --
19348 --------------------------------
19350 function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
19352 return Ekind (Subp) = E_Function
19353 and then not Is_Scalar_Type (Etype (Subp))
19354 and then not Is_Access_Type (Etype (Subp))
19355 and then not Is_Constrained (Etype (Subp));
19356 end Returns_Unconstrained_Type;
19358 ----------------------------
19359 -- Root_Type_Of_Full_View --
19360 ----------------------------
19362 function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id is
19363 Rtyp : constant Entity_Id := Root_Type (T);
19366 -- The root type of the full view may itself be a private type. Keep
19367 -- looking for the ultimate derivation parent.
19369 if Is_Private_Type (Rtyp) and then Present (Full_View (Rtyp)) then
19370 return Root_Type_Of_Full_View (Full_View (Rtyp));
19374 end Root_Type_Of_Full_View;
19376 ---------------------------
19377 -- Safe_To_Capture_Value --
19378 ---------------------------
19380 function Safe_To_Capture_Value
19383 Cond : Boolean := False) return Boolean
19386 -- The only entities for which we track constant values are variables
19387 -- which are not renamings, constants, out parameters, and in out
19388 -- parameters, so check if we have this case.
19390 -- Note: it may seem odd to track constant values for constants, but in
19391 -- fact this routine is used for other purposes than simply capturing
19392 -- the value. In particular, the setting of Known[_Non]_Null.
19394 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
19396 Ekind_In (Ent, E_Constant, E_Out_Parameter, E_In_Out_Parameter)
19400 -- For conditionals, we also allow loop parameters and all formals,
19401 -- including in parameters.
19403 elsif Cond and then Ekind_In (Ent, E_Loop_Parameter, E_In_Parameter) then
19406 -- For all other cases, not just unsafe, but impossible to capture
19407 -- Current_Value, since the above are the only entities which have
19408 -- Current_Value fields.
19414 -- Skip if volatile or aliased, since funny things might be going on in
19415 -- these cases which we cannot necessarily track. Also skip any variable
19416 -- for which an address clause is given, or whose address is taken. Also
19417 -- never capture value of library level variables (an attempt to do so
19418 -- can occur in the case of package elaboration code).
19420 if Treat_As_Volatile (Ent)
19421 or else Is_Aliased (Ent)
19422 or else Present (Address_Clause (Ent))
19423 or else Address_Taken (Ent)
19424 or else (Is_Library_Level_Entity (Ent)
19425 and then Ekind (Ent) = E_Variable)
19430 -- OK, all above conditions are met. We also require that the scope of
19431 -- the reference be the same as the scope of the entity, not counting
19432 -- packages and blocks and loops.
19435 E_Scope : constant Entity_Id := Scope (Ent);
19436 R_Scope : Entity_Id;
19439 R_Scope := Current_Scope;
19440 while R_Scope /= Standard_Standard loop
19441 exit when R_Scope = E_Scope;
19443 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
19446 R_Scope := Scope (R_Scope);
19451 -- We also require that the reference does not appear in a context
19452 -- where it is not sure to be executed (i.e. a conditional context
19453 -- or an exception handler). We skip this if Cond is True, since the
19454 -- capturing of values from conditional tests handles this ok.
19467 -- Seems dubious that case expressions are not handled here ???
19470 while Present (P) loop
19471 if Nkind (P) = N_If_Statement
19472 or else Nkind (P) = N_Case_Statement
19473 or else (Nkind (P) in N_Short_Circuit
19474 and then Desc = Right_Opnd (P))
19475 or else (Nkind (P) = N_If_Expression
19476 and then Desc /= First (Expressions (P)))
19477 or else Nkind (P) = N_Exception_Handler
19478 or else Nkind (P) = N_Selective_Accept
19479 or else Nkind (P) = N_Conditional_Entry_Call
19480 or else Nkind (P) = N_Timed_Entry_Call
19481 or else Nkind (P) = N_Asynchronous_Select
19489 -- A special Ada 2012 case: the original node may be part
19490 -- of the else_actions of a conditional expression, in which
19491 -- case it might not have been expanded yet, and appears in
19492 -- a non-syntactic list of actions. In that case it is clearly
19493 -- not safe to save a value.
19496 and then Is_List_Member (Desc)
19497 and then No (Parent (List_Containing (Desc)))
19505 -- OK, looks safe to set value
19508 end Safe_To_Capture_Value;
19514 function Same_Name (N1, N2 : Node_Id) return Boolean is
19515 K1 : constant Node_Kind := Nkind (N1);
19516 K2 : constant Node_Kind := Nkind (N2);
19519 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
19520 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
19522 return Chars (N1) = Chars (N2);
19524 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
19525 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
19527 return Same_Name (Selector_Name (N1), Selector_Name (N2))
19528 and then Same_Name (Prefix (N1), Prefix (N2));
19539 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
19540 N1 : constant Node_Id := Original_Node (Node1);
19541 N2 : constant Node_Id := Original_Node (Node2);
19542 -- We do the tests on original nodes, since we are most interested
19543 -- in the original source, not any expansion that got in the way.
19545 K1 : constant Node_Kind := Nkind (N1);
19546 K2 : constant Node_Kind := Nkind (N2);
19549 -- First case, both are entities with same entity
19551 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
19553 EN1 : constant Entity_Id := Entity (N1);
19554 EN2 : constant Entity_Id := Entity (N2);
19556 if Present (EN1) and then Present (EN2)
19557 and then (Ekind_In (EN1, E_Variable, E_Constant)
19558 or else Is_Formal (EN1))
19566 -- Second case, selected component with same selector, same record
19568 if K1 = N_Selected_Component
19569 and then K2 = N_Selected_Component
19570 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
19572 return Same_Object (Prefix (N1), Prefix (N2));
19574 -- Third case, indexed component with same subscripts, same array
19576 elsif K1 = N_Indexed_Component
19577 and then K2 = N_Indexed_Component
19578 and then Same_Object (Prefix (N1), Prefix (N2))
19583 E1 := First (Expressions (N1));
19584 E2 := First (Expressions (N2));
19585 while Present (E1) loop
19586 if not Same_Value (E1, E2) then
19597 -- Fourth case, slice of same array with same bounds
19600 and then K2 = N_Slice
19601 and then Nkind (Discrete_Range (N1)) = N_Range
19602 and then Nkind (Discrete_Range (N2)) = N_Range
19603 and then Same_Value (Low_Bound (Discrete_Range (N1)),
19604 Low_Bound (Discrete_Range (N2)))
19605 and then Same_Value (High_Bound (Discrete_Range (N1)),
19606 High_Bound (Discrete_Range (N2)))
19608 return Same_Name (Prefix (N1), Prefix (N2));
19610 -- All other cases, not clearly the same object
19621 function Same_Type (T1, T2 : Entity_Id) return Boolean is
19626 elsif not Is_Constrained (T1)
19627 and then not Is_Constrained (T2)
19628 and then Base_Type (T1) = Base_Type (T2)
19632 -- For now don't bother with case of identical constraints, to be
19633 -- fiddled with later on perhaps (this is only used for optimization
19634 -- purposes, so it is not critical to do a best possible job)
19645 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
19647 if Compile_Time_Known_Value (Node1)
19648 and then Compile_Time_Known_Value (Node2)
19649 and then Expr_Value (Node1) = Expr_Value (Node2)
19652 elsif Same_Object (Node1, Node2) then
19659 -----------------------------
19660 -- Save_SPARK_Mode_And_Set --
19661 -----------------------------
19663 procedure Save_SPARK_Mode_And_Set
19664 (Context : Entity_Id;
19665 Mode : out SPARK_Mode_Type)
19668 -- Save the current mode in effect
19670 Mode := SPARK_Mode;
19672 -- Do not consider illegal or partially decorated constructs
19674 if Ekind (Context) = E_Void or else Error_Posted (Context) then
19677 elsif Present (SPARK_Pragma (Context)) then
19678 SPARK_Mode := Get_SPARK_Mode_From_Annotation (SPARK_Pragma (Context));
19680 end Save_SPARK_Mode_And_Set;
19682 -------------------------
19683 -- Scalar_Part_Present --
19684 -------------------------
19686 function Scalar_Part_Present (T : Entity_Id) return Boolean is
19690 if Is_Scalar_Type (T) then
19693 elsif Is_Array_Type (T) then
19694 return Scalar_Part_Present (Component_Type (T));
19696 elsif Is_Record_Type (T) or else Has_Discriminants (T) then
19697 C := First_Component_Or_Discriminant (T);
19698 while Present (C) loop
19699 if Scalar_Part_Present (Etype (C)) then
19702 Next_Component_Or_Discriminant (C);
19708 end Scalar_Part_Present;
19710 ------------------------
19711 -- Scope_Is_Transient --
19712 ------------------------
19714 function Scope_Is_Transient return Boolean is
19716 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
19717 end Scope_Is_Transient;
19723 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
19728 while Scop /= Standard_Standard loop
19729 Scop := Scope (Scop);
19731 if Scop = Scope2 then
19739 --------------------------
19740 -- Scope_Within_Or_Same --
19741 --------------------------
19743 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
19748 while Scop /= Standard_Standard loop
19749 if Scop = Scope2 then
19752 Scop := Scope (Scop);
19757 end Scope_Within_Or_Same;
19759 --------------------
19760 -- Set_Convention --
19761 --------------------
19763 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
19765 Basic_Set_Convention (E, Val);
19768 and then Is_Access_Subprogram_Type (Base_Type (E))
19769 and then Has_Foreign_Convention (E)
19772 -- A pragma Convention in an instance may apply to the subtype
19773 -- created for a formal, in which case we have already verified
19774 -- that conventions of actual and formal match and there is nothing
19775 -- to flag on the subtype.
19777 if In_Instance then
19780 Set_Can_Use_Internal_Rep (E, False);
19784 -- If E is an object or component, and the type of E is an anonymous
19785 -- access type with no convention set, then also set the convention of
19786 -- the anonymous access type. We do not do this for anonymous protected
19787 -- types, since protected types always have the default convention.
19789 if Present (Etype (E))
19790 and then (Is_Object (E)
19791 or else Ekind (E) = E_Component
19793 -- Allow E_Void (happens for pragma Convention appearing
19794 -- in the middle of a record applying to a component)
19796 or else Ekind (E) = E_Void)
19799 Typ : constant Entity_Id := Etype (E);
19802 if Ekind_In (Typ, E_Anonymous_Access_Type,
19803 E_Anonymous_Access_Subprogram_Type)
19804 and then not Has_Convention_Pragma (Typ)
19806 Basic_Set_Convention (Typ, Val);
19807 Set_Has_Convention_Pragma (Typ);
19809 -- And for the access subprogram type, deal similarly with the
19810 -- designated E_Subprogram_Type if it is also internal (which
19813 if Ekind (Typ) = E_Anonymous_Access_Subprogram_Type then
19815 Dtype : constant Entity_Id := Designated_Type (Typ);
19817 if Ekind (Dtype) = E_Subprogram_Type
19818 and then Is_Itype (Dtype)
19819 and then not Has_Convention_Pragma (Dtype)
19821 Basic_Set_Convention (Dtype, Val);
19822 Set_Has_Convention_Pragma (Dtype);
19829 end Set_Convention;
19831 ------------------------
19832 -- Set_Current_Entity --
19833 ------------------------
19835 -- The given entity is to be set as the currently visible definition of its
19836 -- associated name (i.e. the Node_Id associated with its name). All we have
19837 -- to do is to get the name from the identifier, and then set the
19838 -- associated Node_Id to point to the given entity.
19840 procedure Set_Current_Entity (E : Entity_Id) is
19842 Set_Name_Entity_Id (Chars (E), E);
19843 end Set_Current_Entity;
19845 ---------------------------
19846 -- Set_Debug_Info_Needed --
19847 ---------------------------
19849 procedure Set_Debug_Info_Needed (T : Entity_Id) is
19851 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
19852 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
19853 -- Used to set debug info in a related node if not set already
19855 --------------------------------------
19856 -- Set_Debug_Info_Needed_If_Not_Set --
19857 --------------------------------------
19859 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
19861 if Present (E) and then not Needs_Debug_Info (E) then
19862 Set_Debug_Info_Needed (E);
19864 -- For a private type, indicate that the full view also needs
19865 -- debug information.
19868 and then Is_Private_Type (E)
19869 and then Present (Full_View (E))
19871 Set_Debug_Info_Needed (Full_View (E));
19874 end Set_Debug_Info_Needed_If_Not_Set;
19876 -- Start of processing for Set_Debug_Info_Needed
19879 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
19880 -- indicates that Debug_Info_Needed is never required for the entity.
19881 -- Nothing to do if entity comes from a predefined file. Library files
19882 -- are compiled without debug information, but inlined bodies of these
19883 -- routines may appear in user code, and debug information on them ends
19884 -- up complicating debugging the user code.
19887 or else Debug_Info_Off (T)
19891 elsif In_Inlined_Body
19892 and then Is_Predefined_File_Name
19893 (Unit_File_Name (Get_Source_Unit (Sloc (T))))
19895 Set_Needs_Debug_Info (T, False);
19898 -- Set flag in entity itself. Note that we will go through the following
19899 -- circuitry even if the flag is already set on T. That's intentional,
19900 -- it makes sure that the flag will be set in subsidiary entities.
19902 Set_Needs_Debug_Info (T);
19904 -- Set flag on subsidiary entities if not set already
19906 if Is_Object (T) then
19907 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
19909 elsif Is_Type (T) then
19910 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
19912 if Is_Record_Type (T) then
19914 Ent : Entity_Id := First_Entity (T);
19916 while Present (Ent) loop
19917 Set_Debug_Info_Needed_If_Not_Set (Ent);
19922 -- For a class wide subtype, we also need debug information
19923 -- for the equivalent type.
19925 if Ekind (T) = E_Class_Wide_Subtype then
19926 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
19929 elsif Is_Array_Type (T) then
19930 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
19933 Indx : Node_Id := First_Index (T);
19935 while Present (Indx) loop
19936 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
19937 Indx := Next_Index (Indx);
19941 -- For a packed array type, we also need debug information for
19942 -- the type used to represent the packed array. Conversely, we
19943 -- also need it for the former if we need it for the latter.
19945 if Is_Packed (T) then
19946 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Impl_Type (T));
19949 if Is_Packed_Array_Impl_Type (T) then
19950 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
19953 elsif Is_Access_Type (T) then
19954 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
19956 elsif Is_Private_Type (T) then
19958 FV : constant Entity_Id := Full_View (T);
19961 Set_Debug_Info_Needed_If_Not_Set (FV);
19963 -- If the full view is itself a derived private type, we need
19964 -- debug information on its underlying type.
19967 and then Is_Private_Type (FV)
19968 and then Present (Underlying_Full_View (FV))
19970 Set_Needs_Debug_Info (Underlying_Full_View (FV));
19974 elsif Is_Protected_Type (T) then
19975 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
19977 elsif Is_Scalar_Type (T) then
19979 -- If the subrange bounds are materialized by dedicated constant
19980 -- objects, also include them in the debug info to make sure the
19981 -- debugger can properly use them.
19983 if Present (Scalar_Range (T))
19984 and then Nkind (Scalar_Range (T)) = N_Range
19987 Low_Bnd : constant Node_Id := Type_Low_Bound (T);
19988 High_Bnd : constant Node_Id := Type_High_Bound (T);
19991 if Is_Entity_Name (Low_Bnd) then
19992 Set_Debug_Info_Needed_If_Not_Set (Entity (Low_Bnd));
19995 if Is_Entity_Name (High_Bnd) then
19996 Set_Debug_Info_Needed_If_Not_Set (Entity (High_Bnd));
20002 end Set_Debug_Info_Needed;
20004 ----------------------------
20005 -- Set_Entity_With_Checks --
20006 ----------------------------
20008 procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id) is
20009 Val_Actual : Entity_Id;
20011 Post_Node : Node_Id;
20014 -- Unconditionally set the entity
20016 Set_Entity (N, Val);
20018 -- The node to post on is the selector in the case of an expanded name,
20019 -- and otherwise the node itself.
20021 if Nkind (N) = N_Expanded_Name then
20022 Post_Node := Selector_Name (N);
20027 -- Check for violation of No_Fixed_IO
20029 if Restriction_Check_Required (No_Fixed_IO)
20031 ((RTU_Loaded (Ada_Text_IO)
20032 and then (Is_RTE (Val, RE_Decimal_IO)
20034 Is_RTE (Val, RE_Fixed_IO)))
20037 (RTU_Loaded (Ada_Wide_Text_IO)
20038 and then (Is_RTE (Val, RO_WT_Decimal_IO)
20040 Is_RTE (Val, RO_WT_Fixed_IO)))
20043 (RTU_Loaded (Ada_Wide_Wide_Text_IO)
20044 and then (Is_RTE (Val, RO_WW_Decimal_IO)
20046 Is_RTE (Val, RO_WW_Fixed_IO))))
20048 -- A special extra check, don't complain about a reference from within
20049 -- the Ada.Interrupts package itself!
20051 and then not In_Same_Extended_Unit (N, Val)
20053 Check_Restriction (No_Fixed_IO, Post_Node);
20056 -- Remaining checks are only done on source nodes. Note that we test
20057 -- for violation of No_Fixed_IO even on non-source nodes, because the
20058 -- cases for checking violations of this restriction are instantiations
20059 -- where the reference in the instance has Comes_From_Source False.
20061 if not Comes_From_Source (N) then
20065 -- Check for violation of No_Abort_Statements, which is triggered by
20066 -- call to Ada.Task_Identification.Abort_Task.
20068 if Restriction_Check_Required (No_Abort_Statements)
20069 and then (Is_RTE (Val, RE_Abort_Task))
20071 -- A special extra check, don't complain about a reference from within
20072 -- the Ada.Task_Identification package itself!
20074 and then not In_Same_Extended_Unit (N, Val)
20076 Check_Restriction (No_Abort_Statements, Post_Node);
20079 if Val = Standard_Long_Long_Integer then
20080 Check_Restriction (No_Long_Long_Integers, Post_Node);
20083 -- Check for violation of No_Dynamic_Attachment
20085 if Restriction_Check_Required (No_Dynamic_Attachment)
20086 and then RTU_Loaded (Ada_Interrupts)
20087 and then (Is_RTE (Val, RE_Is_Reserved) or else
20088 Is_RTE (Val, RE_Is_Attached) or else
20089 Is_RTE (Val, RE_Current_Handler) or else
20090 Is_RTE (Val, RE_Attach_Handler) or else
20091 Is_RTE (Val, RE_Exchange_Handler) or else
20092 Is_RTE (Val, RE_Detach_Handler) or else
20093 Is_RTE (Val, RE_Reference))
20095 -- A special extra check, don't complain about a reference from within
20096 -- the Ada.Interrupts package itself!
20098 and then not In_Same_Extended_Unit (N, Val)
20100 Check_Restriction (No_Dynamic_Attachment, Post_Node);
20103 -- Check for No_Implementation_Identifiers
20105 if Restriction_Check_Required (No_Implementation_Identifiers) then
20107 -- We have an implementation defined entity if it is marked as
20108 -- implementation defined, or is defined in a package marked as
20109 -- implementation defined. However, library packages themselves
20110 -- are excluded (we don't want to flag Interfaces itself, just
20111 -- the entities within it).
20113 if (Is_Implementation_Defined (Val)
20115 (Present (Scope (Val))
20116 and then Is_Implementation_Defined (Scope (Val))))
20117 and then not (Ekind_In (Val, E_Package, E_Generic_Package)
20118 and then Is_Library_Level_Entity (Val))
20120 Check_Restriction (No_Implementation_Identifiers, Post_Node);
20124 -- Do the style check
20127 and then not Suppress_Style_Checks (Val)
20128 and then not In_Instance
20130 if Nkind (N) = N_Identifier then
20132 elsif Nkind (N) = N_Expanded_Name then
20133 Nod := Selector_Name (N);
20138 -- A special situation arises for derived operations, where we want
20139 -- to do the check against the parent (since the Sloc of the derived
20140 -- operation points to the derived type declaration itself).
20143 while not Comes_From_Source (Val_Actual)
20144 and then Nkind (Val_Actual) in N_Entity
20145 and then (Ekind (Val_Actual) = E_Enumeration_Literal
20146 or else Is_Subprogram_Or_Generic_Subprogram (Val_Actual))
20147 and then Present (Alias (Val_Actual))
20149 Val_Actual := Alias (Val_Actual);
20152 -- Renaming declarations for generic actuals do not come from source,
20153 -- and have a different name from that of the entity they rename, so
20154 -- there is no style check to perform here.
20156 if Chars (Nod) = Chars (Val_Actual) then
20157 Style.Check_Identifier (Nod, Val_Actual);
20161 Set_Entity (N, Val);
20162 end Set_Entity_With_Checks;
20164 ------------------------
20165 -- Set_Name_Entity_Id --
20166 ------------------------
20168 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
20170 Set_Name_Table_Int (Id, Int (Val));
20171 end Set_Name_Entity_Id;
20173 ---------------------
20174 -- Set_Next_Actual --
20175 ---------------------
20177 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
20179 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
20180 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
20182 end Set_Next_Actual;
20184 ----------------------------------
20185 -- Set_Optimize_Alignment_Flags --
20186 ----------------------------------
20188 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
20190 if Optimize_Alignment = 'S' then
20191 Set_Optimize_Alignment_Space (E);
20192 elsif Optimize_Alignment = 'T' then
20193 Set_Optimize_Alignment_Time (E);
20195 end Set_Optimize_Alignment_Flags;
20197 -----------------------
20198 -- Set_Public_Status --
20199 -----------------------
20201 procedure Set_Public_Status (Id : Entity_Id) is
20202 S : constant Entity_Id := Current_Scope;
20204 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
20205 -- Determines if E is defined within handled statement sequence or
20206 -- an if statement, returns True if so, False otherwise.
20208 ----------------------
20209 -- Within_HSS_Or_If --
20210 ----------------------
20212 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
20215 N := Declaration_Node (E);
20222 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
20228 end Within_HSS_Or_If;
20230 -- Start of processing for Set_Public_Status
20233 -- Everything in the scope of Standard is public
20235 if S = Standard_Standard then
20236 Set_Is_Public (Id);
20238 -- Entity is definitely not public if enclosing scope is not public
20240 elsif not Is_Public (S) then
20243 -- An object or function declaration that occurs in a handled sequence
20244 -- of statements or within an if statement is the declaration for a
20245 -- temporary object or local subprogram generated by the expander. It
20246 -- never needs to be made public and furthermore, making it public can
20247 -- cause back end problems.
20249 elsif Nkind_In (Parent (Id), N_Object_Declaration,
20250 N_Function_Specification)
20251 and then Within_HSS_Or_If (Id)
20255 -- Entities in public packages or records are public
20257 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
20258 Set_Is_Public (Id);
20260 -- The bounds of an entry family declaration can generate object
20261 -- declarations that are visible to the back-end, e.g. in the
20262 -- the declaration of a composite type that contains tasks.
20264 elsif Is_Concurrent_Type (S)
20265 and then not Has_Completion (S)
20266 and then Nkind (Parent (Id)) = N_Object_Declaration
20268 Set_Is_Public (Id);
20270 end Set_Public_Status;
20272 -----------------------------
20273 -- Set_Referenced_Modified --
20274 -----------------------------
20276 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
20280 -- Deal with indexed or selected component where prefix is modified
20282 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
20283 Pref := Prefix (N);
20285 -- If prefix is access type, then it is the designated object that is
20286 -- being modified, which means we have no entity to set the flag on.
20288 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
20291 -- Otherwise chase the prefix
20294 Set_Referenced_Modified (Pref, Out_Param);
20297 -- Otherwise see if we have an entity name (only other case to process)
20299 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
20300 Set_Referenced_As_LHS (Entity (N), not Out_Param);
20301 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
20303 end Set_Referenced_Modified;
20305 ----------------------------
20306 -- Set_Scope_Is_Transient --
20307 ----------------------------
20309 procedure Set_Scope_Is_Transient (V : Boolean := True) is
20311 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
20312 end Set_Scope_Is_Transient;
20314 -------------------
20315 -- Set_Size_Info --
20316 -------------------
20318 procedure Set_Size_Info (T1, T2 : Entity_Id) is
20320 -- We copy Esize, but not RM_Size, since in general RM_Size is
20321 -- subtype specific and does not get inherited by all subtypes.
20323 Set_Esize (T1, Esize (T2));
20324 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
20326 if Is_Discrete_Or_Fixed_Point_Type (T1)
20328 Is_Discrete_Or_Fixed_Point_Type (T2)
20330 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
20333 Set_Alignment (T1, Alignment (T2));
20336 --------------------
20337 -- Static_Boolean --
20338 --------------------
20340 function Static_Boolean (N : Node_Id) return Uint is
20342 Analyze_And_Resolve (N, Standard_Boolean);
20345 or else Error_Posted (N)
20346 or else Etype (N) = Any_Type
20351 if Is_OK_Static_Expression (N) then
20352 if not Raises_Constraint_Error (N) then
20353 return Expr_Value (N);
20358 elsif Etype (N) = Any_Type then
20362 Flag_Non_Static_Expr
20363 ("static boolean expression required here", N);
20366 end Static_Boolean;
20368 --------------------
20369 -- Static_Integer --
20370 --------------------
20372 function Static_Integer (N : Node_Id) return Uint is
20374 Analyze_And_Resolve (N, Any_Integer);
20377 or else Error_Posted (N)
20378 or else Etype (N) = Any_Type
20383 if Is_OK_Static_Expression (N) then
20384 if not Raises_Constraint_Error (N) then
20385 return Expr_Value (N);
20390 elsif Etype (N) = Any_Type then
20394 Flag_Non_Static_Expr
20395 ("static integer expression required here", N);
20398 end Static_Integer;
20400 --------------------------
20401 -- Statically_Different --
20402 --------------------------
20404 function Statically_Different (E1, E2 : Node_Id) return Boolean is
20405 R1 : constant Node_Id := Get_Referenced_Object (E1);
20406 R2 : constant Node_Id := Get_Referenced_Object (E2);
20408 return Is_Entity_Name (R1)
20409 and then Is_Entity_Name (R2)
20410 and then Entity (R1) /= Entity (R2)
20411 and then not Is_Formal (Entity (R1))
20412 and then not Is_Formal (Entity (R2));
20413 end Statically_Different;
20415 --------------------------------------
20416 -- Subject_To_Loop_Entry_Attributes --
20417 --------------------------------------
20419 function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
20425 -- The expansion mechanism transform a loop subject to at least one
20426 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
20427 -- the conditional part.
20429 if Nkind_In (Stmt, N_Block_Statement, N_If_Statement)
20430 and then Nkind (Original_Node (N)) = N_Loop_Statement
20432 Stmt := Original_Node (N);
20436 Nkind (Stmt) = N_Loop_Statement
20437 and then Present (Identifier (Stmt))
20438 and then Present (Entity (Identifier (Stmt)))
20439 and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
20440 end Subject_To_Loop_Entry_Attributes;
20442 -----------------------------
20443 -- Subprogram_Access_Level --
20444 -----------------------------
20446 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
20448 if Present (Alias (Subp)) then
20449 return Subprogram_Access_Level (Alias (Subp));
20451 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
20453 end Subprogram_Access_Level;
20455 -------------------------------
20456 -- Support_Atomic_Primitives --
20457 -------------------------------
20459 function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
20463 -- Verify the alignment of Typ is known
20465 if not Known_Alignment (Typ) then
20469 if Known_Static_Esize (Typ) then
20470 Size := UI_To_Int (Esize (Typ));
20472 -- If the Esize (Object_Size) is unknown at compile time, look at the
20473 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
20475 elsif Known_Static_RM_Size (Typ) then
20476 Size := UI_To_Int (RM_Size (Typ));
20478 -- Otherwise, the size is considered to be unknown.
20484 -- Check that the size of the component is 8, 16, 32, or 64 bits and
20485 -- that Typ is properly aligned.
20488 when 8 | 16 | 32 | 64 =>
20489 return Size = UI_To_Int (Alignment (Typ)) * 8;
20494 end Support_Atomic_Primitives;
20500 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
20502 if Debug_Flag_W then
20503 for J in 0 .. Scope_Stack.Last loop
20508 Write_Name (Chars (E));
20509 Write_Str (" from ");
20510 Write_Location (Sloc (N));
20515 -----------------------
20516 -- Transfer_Entities --
20517 -----------------------
20519 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
20520 procedure Set_Public_Status_Of (Id : Entity_Id);
20521 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
20522 -- Set_Public_Status. If successfull and Id denotes a record type, set
20523 -- the Is_Public attribute of its fields.
20525 --------------------------
20526 -- Set_Public_Status_Of --
20527 --------------------------
20529 procedure Set_Public_Status_Of (Id : Entity_Id) is
20533 if not Is_Public (Id) then
20534 Set_Public_Status (Id);
20536 -- When the input entity is a public record type, ensure that all
20537 -- its internal fields are also exposed to the linker. The fields
20538 -- of a class-wide type are never made public.
20541 and then Is_Record_Type (Id)
20542 and then not Is_Class_Wide_Type (Id)
20544 Field := First_Entity (Id);
20545 while Present (Field) loop
20546 Set_Is_Public (Field);
20547 Next_Entity (Field);
20551 end Set_Public_Status_Of;
20555 Full_Id : Entity_Id;
20558 -- Start of processing for Transfer_Entities
20561 Id := First_Entity (From);
20563 if Present (Id) then
20565 -- Merge the entity chain of the source scope with that of the
20566 -- destination scope.
20568 if Present (Last_Entity (To)) then
20569 Set_Next_Entity (Last_Entity (To), Id);
20571 Set_First_Entity (To, Id);
20574 Set_Last_Entity (To, Last_Entity (From));
20576 -- Inspect the entities of the source scope and update their Scope
20579 while Present (Id) loop
20580 Set_Scope (Id, To);
20581 Set_Public_Status_Of (Id);
20583 -- Handle an internally generated full view for a private type
20585 if Is_Private_Type (Id)
20586 and then Present (Full_View (Id))
20587 and then Is_Itype (Full_View (Id))
20589 Full_Id := Full_View (Id);
20591 Set_Scope (Full_Id, To);
20592 Set_Public_Status_Of (Full_Id);
20598 Set_First_Entity (From, Empty);
20599 Set_Last_Entity (From, Empty);
20601 end Transfer_Entities;
20603 -----------------------
20604 -- Type_Access_Level --
20605 -----------------------
20607 function Type_Access_Level (Typ : Entity_Id) return Uint is
20611 Btyp := Base_Type (Typ);
20613 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
20614 -- simply use the level where the type is declared. This is true for
20615 -- stand-alone object declarations, and for anonymous access types
20616 -- associated with components the level is the same as that of the
20617 -- enclosing composite type. However, special treatment is needed for
20618 -- the cases of access parameters, return objects of an anonymous access
20619 -- type, and, in Ada 95, access discriminants of limited types.
20621 if Is_Access_Type (Btyp) then
20622 if Ekind (Btyp) = E_Anonymous_Access_Type then
20624 -- If the type is a nonlocal anonymous access type (such as for
20625 -- an access parameter) we treat it as being declared at the
20626 -- library level to ensure that names such as X.all'access don't
20627 -- fail static accessibility checks.
20629 if not Is_Local_Anonymous_Access (Typ) then
20630 return Scope_Depth (Standard_Standard);
20632 -- If this is a return object, the accessibility level is that of
20633 -- the result subtype of the enclosing function. The test here is
20634 -- little complicated, because we have to account for extended
20635 -- return statements that have been rewritten as blocks, in which
20636 -- case we have to find and the Is_Return_Object attribute of the
20637 -- itype's associated object. It would be nice to find a way to
20638 -- simplify this test, but it doesn't seem worthwhile to add a new
20639 -- flag just for purposes of this test. ???
20641 elsif Ekind (Scope (Btyp)) = E_Return_Statement
20644 and then Nkind (Associated_Node_For_Itype (Btyp)) =
20645 N_Object_Declaration
20646 and then Is_Return_Object
20647 (Defining_Identifier
20648 (Associated_Node_For_Itype (Btyp))))
20654 Scop := Scope (Scope (Btyp));
20655 while Present (Scop) loop
20656 exit when Ekind (Scop) = E_Function;
20657 Scop := Scope (Scop);
20660 -- Treat the return object's type as having the level of the
20661 -- function's result subtype (as per RM05-6.5(5.3/2)).
20663 return Type_Access_Level (Etype (Scop));
20668 Btyp := Root_Type (Btyp);
20670 -- The accessibility level of anonymous access types associated with
20671 -- discriminants is that of the current instance of the type, and
20672 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
20674 -- AI-402: access discriminants have accessibility based on the
20675 -- object rather than the type in Ada 2005, so the above paragraph
20678 -- ??? Needs completion with rules from AI-416
20680 if Ada_Version <= Ada_95
20681 and then Ekind (Typ) = E_Anonymous_Access_Type
20682 and then Present (Associated_Node_For_Itype (Typ))
20683 and then Nkind (Associated_Node_For_Itype (Typ)) =
20684 N_Discriminant_Specification
20686 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
20690 -- Return library level for a generic formal type. This is done because
20691 -- RM(10.3.2) says that "The statically deeper relationship does not
20692 -- apply to ... a descendant of a generic formal type". Rather than
20693 -- checking at each point where a static accessibility check is
20694 -- performed to see if we are dealing with a formal type, this rule is
20695 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
20696 -- return extreme values for a formal type; Deepest_Type_Access_Level
20697 -- returns Int'Last. By calling the appropriate function from among the
20698 -- two, we ensure that the static accessibility check will pass if we
20699 -- happen to run into a formal type. More specifically, we should call
20700 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
20701 -- call occurs as part of a static accessibility check and the error
20702 -- case is the case where the type's level is too shallow (as opposed
20705 if Is_Generic_Type (Root_Type (Btyp)) then
20706 return Scope_Depth (Standard_Standard);
20709 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
20710 end Type_Access_Level;
20712 ------------------------------------
20713 -- Type_Without_Stream_Operation --
20714 ------------------------------------
20716 function Type_Without_Stream_Operation
20718 Op : TSS_Name_Type := TSS_Null) return Entity_Id
20720 BT : constant Entity_Id := Base_Type (T);
20721 Op_Missing : Boolean;
20724 if not Restriction_Active (No_Default_Stream_Attributes) then
20728 if Is_Elementary_Type (T) then
20729 if Op = TSS_Null then
20731 No (TSS (BT, TSS_Stream_Read))
20732 or else No (TSS (BT, TSS_Stream_Write));
20735 Op_Missing := No (TSS (BT, Op));
20744 elsif Is_Array_Type (T) then
20745 return Type_Without_Stream_Operation (Component_Type (T), Op);
20747 elsif Is_Record_Type (T) then
20753 Comp := First_Component (T);
20754 while Present (Comp) loop
20755 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
20757 if Present (C_Typ) then
20761 Next_Component (Comp);
20767 elsif Is_Private_Type (T) and then Present (Full_View (T)) then
20768 return Type_Without_Stream_Operation (Full_View (T), Op);
20772 end Type_Without_Stream_Operation;
20774 ----------------------------
20775 -- Unique_Defining_Entity --
20776 ----------------------------
20778 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
20780 return Unique_Entity (Defining_Entity (N));
20781 end Unique_Defining_Entity;
20783 -------------------
20784 -- Unique_Entity --
20785 -------------------
20787 function Unique_Entity (E : Entity_Id) return Entity_Id is
20788 U : Entity_Id := E;
20794 if Present (Full_View (E)) then
20795 U := Full_View (E);
20799 if Nkind (Parent (E)) = N_Entry_Body then
20801 Prot_Item : Entity_Id;
20802 Prot_Type : Entity_Id;
20805 if Ekind (E) = E_Entry then
20806 Prot_Type := Scope (E);
20808 -- Bodies of entry families are nested within an extra scope
20809 -- that contains an entry index declaration
20812 Prot_Type := Scope (Scope (E));
20815 pragma Assert (Ekind (Prot_Type) = E_Protected_Type);
20817 -- Traverse the entity list of the protected type and locate
20818 -- an entry declaration which matches the entry body.
20820 Prot_Item := First_Entity (Prot_Type);
20821 while Present (Prot_Item) loop
20822 if Ekind (Prot_Item) in Entry_Kind
20823 and then Corresponding_Body (Parent (Prot_Item)) = E
20829 Next_Entity (Prot_Item);
20834 when Formal_Kind =>
20835 if Present (Spec_Entity (E)) then
20836 U := Spec_Entity (E);
20839 when E_Package_Body =>
20842 if Nkind (P) = N_Defining_Program_Unit_Name then
20846 if Nkind (P) = N_Package_Body
20847 and then Present (Corresponding_Spec (P))
20849 U := Corresponding_Spec (P);
20851 elsif Nkind (P) = N_Package_Body_Stub
20852 and then Present (Corresponding_Spec_Of_Stub (P))
20854 U := Corresponding_Spec_Of_Stub (P);
20857 when E_Protected_Body =>
20860 if Nkind (P) = N_Protected_Body
20861 and then Present (Corresponding_Spec (P))
20863 U := Corresponding_Spec (P);
20865 elsif Nkind (P) = N_Protected_Body_Stub
20866 and then Present (Corresponding_Spec_Of_Stub (P))
20868 U := Corresponding_Spec_Of_Stub (P);
20870 if Is_Single_Protected_Object (U) then
20875 when E_Subprogram_Body =>
20878 if Nkind (P) = N_Defining_Program_Unit_Name then
20884 if Nkind (P) = N_Subprogram_Body
20885 and then Present (Corresponding_Spec (P))
20887 U := Corresponding_Spec (P);
20889 elsif Nkind (P) = N_Subprogram_Body_Stub
20890 and then Present (Corresponding_Spec_Of_Stub (P))
20892 U := Corresponding_Spec_Of_Stub (P);
20894 elsif Nkind (P) = N_Subprogram_Renaming_Declaration then
20895 U := Corresponding_Spec (P);
20898 when E_Task_Body =>
20901 if Nkind (P) = N_Task_Body
20902 and then Present (Corresponding_Spec (P))
20904 U := Corresponding_Spec (P);
20906 elsif Nkind (P) = N_Task_Body_Stub
20907 and then Present (Corresponding_Spec_Of_Stub (P))
20909 U := Corresponding_Spec_Of_Stub (P);
20911 if Is_Single_Task_Object (U) then
20917 if Present (Full_View (E)) then
20918 U := Full_View (E);
20932 function Unique_Name (E : Entity_Id) return String is
20934 -- Names in E_Subprogram_Body or E_Package_Body entities are not
20935 -- reliable, as they may not include the overloading suffix. Instead,
20936 -- when looking for the name of E or one of its enclosing scope, we get
20937 -- the name of the corresponding Unique_Entity.
20939 U : constant Entity_Id := Unique_Entity (E);
20941 function This_Name return String;
20947 function This_Name return String is
20949 return Get_Name_String (Chars (U));
20952 -- Start of processing for Unique_Name
20955 if E = Standard_Standard
20956 or else Has_Fully_Qualified_Name (E)
20960 elsif Ekind (E) = E_Enumeration_Literal then
20961 return Unique_Name (Etype (E)) & "__" & This_Name;
20965 S : constant Entity_Id := Scope (U);
20966 pragma Assert (Present (S));
20969 -- Prefix names of predefined types with standard__, but leave
20970 -- names of user-defined packages and subprograms without prefix
20971 -- (even if technically they are nested in the Standard package).
20973 if S = Standard_Standard then
20974 if Ekind (U) = E_Package or else Is_Subprogram (U) then
20977 return Unique_Name (S) & "__" & This_Name;
20980 -- For intances of generic subprograms use the name of the related
20981 -- instace and skip the scope of its wrapper package.
20983 elsif Is_Wrapper_Package (S) then
20984 pragma Assert (Scope (S) = Scope (Related_Instance (S)));
20985 -- Wrapper package and the instantiation are in the same scope
20988 Enclosing_Name : constant String :=
20989 Unique_Name (Scope (S)) & "__" &
20990 Get_Name_String (Chars (Related_Instance (S)));
20993 if Is_Subprogram (U)
20994 and then not Is_Generic_Actual_Subprogram (U)
20996 return Enclosing_Name;
20998 return Enclosing_Name & "__" & This_Name;
21003 return Unique_Name (S) & "__" & This_Name;
21009 ---------------------
21010 -- Unit_Is_Visible --
21011 ---------------------
21013 function Unit_Is_Visible (U : Entity_Id) return Boolean is
21014 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
21015 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
21017 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
21018 -- For a child unit, check whether unit appears in a with_clause
21021 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
21022 -- Scan the context clause of one compilation unit looking for a
21023 -- with_clause for the unit in question.
21025 ----------------------------
21026 -- Unit_In_Parent_Context --
21027 ----------------------------
21029 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
21031 if Unit_In_Context (Par_Unit) then
21034 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
21035 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
21040 end Unit_In_Parent_Context;
21042 ---------------------
21043 -- Unit_In_Context --
21044 ---------------------
21046 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
21050 Clause := First (Context_Items (Comp_Unit));
21051 while Present (Clause) loop
21052 if Nkind (Clause) = N_With_Clause then
21053 if Library_Unit (Clause) = U then
21056 -- The with_clause may denote a renaming of the unit we are
21057 -- looking for, eg. Text_IO which renames Ada.Text_IO.
21060 Renamed_Entity (Entity (Name (Clause))) =
21061 Defining_Entity (Unit (U))
21071 end Unit_In_Context;
21073 -- Start of processing for Unit_Is_Visible
21076 -- The currrent unit is directly visible
21081 elsif Unit_In_Context (Curr) then
21084 -- If the current unit is a body, check the context of the spec
21086 elsif Nkind (Unit (Curr)) = N_Package_Body
21088 (Nkind (Unit (Curr)) = N_Subprogram_Body
21089 and then not Acts_As_Spec (Unit (Curr)))
21091 if Unit_In_Context (Library_Unit (Curr)) then
21096 -- If the spec is a child unit, examine the parents
21098 if Is_Child_Unit (Curr_Entity) then
21099 if Nkind (Unit (Curr)) in N_Unit_Body then
21101 Unit_In_Parent_Context
21102 (Parent_Spec (Unit (Library_Unit (Curr))));
21104 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
21110 end Unit_Is_Visible;
21112 ------------------------------
21113 -- Universal_Interpretation --
21114 ------------------------------
21116 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
21117 Index : Interp_Index;
21121 -- The argument may be a formal parameter of an operator or subprogram
21122 -- with multiple interpretations, or else an expression for an actual.
21124 if Nkind (Opnd) = N_Defining_Identifier
21125 or else not Is_Overloaded (Opnd)
21127 if Etype (Opnd) = Universal_Integer
21128 or else Etype (Opnd) = Universal_Real
21130 return Etype (Opnd);
21136 Get_First_Interp (Opnd, Index, It);
21137 while Present (It.Typ) loop
21138 if It.Typ = Universal_Integer
21139 or else It.Typ = Universal_Real
21144 Get_Next_Interp (Index, It);
21149 end Universal_Interpretation;
21155 function Unqualify (Expr : Node_Id) return Node_Id is
21157 -- Recurse to handle unlikely case of multiple levels of qualification
21159 if Nkind (Expr) = N_Qualified_Expression then
21160 return Unqualify (Expression (Expr));
21162 -- Normal case, not a qualified expression
21169 -----------------------
21170 -- Visible_Ancestors --
21171 -----------------------
21173 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
21179 pragma Assert (Is_Record_Type (Typ) and then Is_Tagged_Type (Typ));
21181 -- Collect all the parents and progenitors of Typ. If the full-view of
21182 -- private parents and progenitors is available then it is used to
21183 -- generate the list of visible ancestors; otherwise their partial
21184 -- view is added to the resulting list.
21189 Use_Full_View => True);
21193 Ifaces_List => List_2,
21194 Exclude_Parents => True,
21195 Use_Full_View => True);
21197 -- Join the two lists. Avoid duplications because an interface may
21198 -- simultaneously be parent and progenitor of a type.
21200 Elmt := First_Elmt (List_2);
21201 while Present (Elmt) loop
21202 Append_Unique_Elmt (Node (Elmt), List_1);
21207 end Visible_Ancestors;
21209 ----------------------
21210 -- Within_Init_Proc --
21211 ----------------------
21213 function Within_Init_Proc return Boolean is
21217 S := Current_Scope;
21218 while not Is_Overloadable (S) loop
21219 if S = Standard_Standard then
21226 return Is_Init_Proc (S);
21227 end Within_Init_Proc;
21233 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
21235 return Scope_Within_Or_Same (Scope (E), S);
21242 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
21243 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
21244 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
21246 Matching_Field : Entity_Id;
21247 -- Entity to give a more precise suggestion on how to write a one-
21248 -- element positional aggregate.
21250 function Has_One_Matching_Field return Boolean;
21251 -- Determines if Expec_Type is a record type with a single component or
21252 -- discriminant whose type matches the found type or is one dimensional
21253 -- array whose component type matches the found type. In the case of
21254 -- one discriminant, we ignore the variant parts. That's not accurate,
21255 -- but good enough for the warning.
21257 ----------------------------
21258 -- Has_One_Matching_Field --
21259 ----------------------------
21261 function Has_One_Matching_Field return Boolean is
21265 Matching_Field := Empty;
21267 if Is_Array_Type (Expec_Type)
21268 and then Number_Dimensions (Expec_Type) = 1
21269 and then Covers (Etype (Component_Type (Expec_Type)), Found_Type)
21271 -- Use type name if available. This excludes multidimensional
21272 -- arrays and anonymous arrays.
21274 if Comes_From_Source (Expec_Type) then
21275 Matching_Field := Expec_Type;
21277 -- For an assignment, use name of target
21279 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
21280 and then Is_Entity_Name (Name (Parent (Expr)))
21282 Matching_Field := Entity (Name (Parent (Expr)));
21287 elsif not Is_Record_Type (Expec_Type) then
21291 E := First_Entity (Expec_Type);
21296 elsif not Ekind_In (E, E_Discriminant, E_Component)
21297 or else Nam_In (Chars (E), Name_uTag, Name_uParent)
21306 if not Covers (Etype (E), Found_Type) then
21309 elsif Present (Next_Entity (E))
21310 and then (Ekind (E) = E_Component
21311 or else Ekind (Next_Entity (E)) = E_Discriminant)
21316 Matching_Field := E;
21320 end Has_One_Matching_Field;
21322 -- Start of processing for Wrong_Type
21325 -- Don't output message if either type is Any_Type, or if a message
21326 -- has already been posted for this node. We need to do the latter
21327 -- check explicitly (it is ordinarily done in Errout), because we
21328 -- are using ! to force the output of the error messages.
21330 if Expec_Type = Any_Type
21331 or else Found_Type = Any_Type
21332 or else Error_Posted (Expr)
21336 -- If one of the types is a Taft-Amendment type and the other it its
21337 -- completion, it must be an illegal use of a TAT in the spec, for
21338 -- which an error was already emitted. Avoid cascaded errors.
21340 elsif Is_Incomplete_Type (Expec_Type)
21341 and then Has_Completion_In_Body (Expec_Type)
21342 and then Full_View (Expec_Type) = Etype (Expr)
21346 elsif Is_Incomplete_Type (Etype (Expr))
21347 and then Has_Completion_In_Body (Etype (Expr))
21348 and then Full_View (Etype (Expr)) = Expec_Type
21352 -- In an instance, there is an ongoing problem with completion of
21353 -- type derived from private types. Their structure is what Gigi
21354 -- expects, but the Etype is the parent type rather than the
21355 -- derived private type itself. Do not flag error in this case. The
21356 -- private completion is an entity without a parent, like an Itype.
21357 -- Similarly, full and partial views may be incorrect in the instance.
21358 -- There is no simple way to insure that it is consistent ???
21360 -- A similar view discrepancy can happen in an inlined body, for the
21361 -- same reason: inserted body may be outside of the original package
21362 -- and only partial views are visible at the point of insertion.
21364 elsif In_Instance or else In_Inlined_Body then
21365 if Etype (Etype (Expr)) = Etype (Expected_Type)
21367 (Has_Private_Declaration (Expected_Type)
21368 or else Has_Private_Declaration (Etype (Expr)))
21369 and then No (Parent (Expected_Type))
21373 elsif Nkind (Parent (Expr)) = N_Qualified_Expression
21374 and then Entity (Subtype_Mark (Parent (Expr))) = Expected_Type
21378 elsif Is_Private_Type (Expected_Type)
21379 and then Present (Full_View (Expected_Type))
21380 and then Covers (Full_View (Expected_Type), Etype (Expr))
21384 -- Conversely, type of expression may be the private one
21386 elsif Is_Private_Type (Base_Type (Etype (Expr)))
21387 and then Full_View (Base_Type (Etype (Expr))) = Expected_Type
21393 -- An interesting special check. If the expression is parenthesized
21394 -- and its type corresponds to the type of the sole component of the
21395 -- expected record type, or to the component type of the expected one
21396 -- dimensional array type, then assume we have a bad aggregate attempt.
21398 if Nkind (Expr) in N_Subexpr
21399 and then Paren_Count (Expr) /= 0
21400 and then Has_One_Matching_Field
21402 Error_Msg_N ("positional aggregate cannot have one component", Expr);
21404 if Present (Matching_Field) then
21405 if Is_Array_Type (Expec_Type) then
21407 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
21410 ("\write instead `& ='> ...`", Expr, Matching_Field);
21414 -- Another special check, if we are looking for a pool-specific access
21415 -- type and we found an E_Access_Attribute_Type, then we have the case
21416 -- of an Access attribute being used in a context which needs a pool-
21417 -- specific type, which is never allowed. The one extra check we make
21418 -- is that the expected designated type covers the Found_Type.
21420 elsif Is_Access_Type (Expec_Type)
21421 and then Ekind (Found_Type) = E_Access_Attribute_Type
21422 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
21423 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
21425 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
21427 Error_Msg_N -- CODEFIX
21428 ("result must be general access type!", Expr);
21429 Error_Msg_NE -- CODEFIX
21430 ("add ALL to }!", Expr, Expec_Type);
21432 -- Another special check, if the expected type is an integer type,
21433 -- but the expression is of type System.Address, and the parent is
21434 -- an addition or subtraction operation whose left operand is the
21435 -- expression in question and whose right operand is of an integral
21436 -- type, then this is an attempt at address arithmetic, so give
21437 -- appropriate message.
21439 elsif Is_Integer_Type (Expec_Type)
21440 and then Is_RTE (Found_Type, RE_Address)
21441 and then Nkind_In (Parent (Expr), N_Op_Add, N_Op_Subtract)
21442 and then Expr = Left_Opnd (Parent (Expr))
21443 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
21446 ("address arithmetic not predefined in package System",
21449 ("\possible missing with/use of System.Storage_Elements",
21453 -- If the expected type is an anonymous access type, as for access
21454 -- parameters and discriminants, the error is on the designated types.
21456 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
21457 if Comes_From_Source (Expec_Type) then
21458 Error_Msg_NE ("expected}!", Expr, Expec_Type);
21461 ("expected an access type with designated}",
21462 Expr, Designated_Type (Expec_Type));
21465 if Is_Access_Type (Found_Type)
21466 and then not Comes_From_Source (Found_Type)
21469 ("\\found an access type with designated}!",
21470 Expr, Designated_Type (Found_Type));
21472 if From_Limited_With (Found_Type) then
21473 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
21474 Error_Msg_Qual_Level := 99;
21475 Error_Msg_NE -- CODEFIX
21476 ("\\missing `WITH &;", Expr, Scope (Found_Type));
21477 Error_Msg_Qual_Level := 0;
21479 Error_Msg_NE ("found}!", Expr, Found_Type);
21483 -- Normal case of one type found, some other type expected
21486 -- If the names of the two types are the same, see if some number
21487 -- of levels of qualification will help. Don't try more than three
21488 -- levels, and if we get to standard, it's no use (and probably
21489 -- represents an error in the compiler) Also do not bother with
21490 -- internal scope names.
21493 Expec_Scope : Entity_Id;
21494 Found_Scope : Entity_Id;
21497 Expec_Scope := Expec_Type;
21498 Found_Scope := Found_Type;
21500 for Levels in Nat range 0 .. 3 loop
21501 if Chars (Expec_Scope) /= Chars (Found_Scope) then
21502 Error_Msg_Qual_Level := Levels;
21506 Expec_Scope := Scope (Expec_Scope);
21507 Found_Scope := Scope (Found_Scope);
21509 exit when Expec_Scope = Standard_Standard
21510 or else Found_Scope = Standard_Standard
21511 or else not Comes_From_Source (Expec_Scope)
21512 or else not Comes_From_Source (Found_Scope);
21516 if Is_Record_Type (Expec_Type)
21517 and then Present (Corresponding_Remote_Type (Expec_Type))
21519 Error_Msg_NE ("expected}!", Expr,
21520 Corresponding_Remote_Type (Expec_Type));
21522 Error_Msg_NE ("expected}!", Expr, Expec_Type);
21525 if Is_Entity_Name (Expr)
21526 and then Is_Package_Or_Generic_Package (Entity (Expr))
21528 Error_Msg_N ("\\found package name!", Expr);
21530 elsif Is_Entity_Name (Expr)
21531 and then Ekind_In (Entity (Expr), E_Procedure, E_Generic_Procedure)
21533 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
21535 ("found procedure name, possibly missing Access attribute!",
21539 ("\\found procedure name instead of function!", Expr);
21542 elsif Nkind (Expr) = N_Function_Call
21543 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
21544 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
21545 and then No (Parameter_Associations (Expr))
21548 ("found function name, possibly missing Access attribute!",
21551 -- Catch common error: a prefix or infix operator which is not
21552 -- directly visible because the type isn't.
21554 elsif Nkind (Expr) in N_Op
21555 and then Is_Overloaded (Expr)
21556 and then not Is_Immediately_Visible (Expec_Type)
21557 and then not Is_Potentially_Use_Visible (Expec_Type)
21558 and then not In_Use (Expec_Type)
21559 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
21562 ("operator of the type is not directly visible!", Expr);
21564 elsif Ekind (Found_Type) = E_Void
21565 and then Present (Parent (Found_Type))
21566 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
21568 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
21571 Error_Msg_NE ("\\found}!", Expr, Found_Type);
21574 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
21575 -- of the same modular type, and (M1 and M2) = 0 was intended.
21577 if Expec_Type = Standard_Boolean
21578 and then Is_Modular_Integer_Type (Found_Type)
21579 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
21580 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
21583 Op : constant Node_Id := Right_Opnd (Parent (Expr));
21584 L : constant Node_Id := Left_Opnd (Op);
21585 R : constant Node_Id := Right_Opnd (Op);
21588 -- The case for the message is when the left operand of the
21589 -- comparison is the same modular type, or when it is an
21590 -- integer literal (or other universal integer expression),
21591 -- which would have been typed as the modular type if the
21592 -- parens had been there.
21594 if (Etype (L) = Found_Type
21596 Etype (L) = Universal_Integer)
21597 and then Is_Integer_Type (Etype (R))
21600 ("\\possible missing parens for modular operation", Expr);
21605 -- Reset error message qualification indication
21607 Error_Msg_Qual_Level := 0;
21611 --------------------------------
21612 -- Yields_Synchronized_Object --
21613 --------------------------------
21615 function Yields_Synchronized_Object (Typ : Entity_Id) return Boolean is
21616 Has_Sync_Comp : Boolean := False;
21620 -- An array type yields a synchronized object if its component type
21621 -- yields a synchronized object.
21623 if Is_Array_Type (Typ) then
21624 return Yields_Synchronized_Object (Component_Type (Typ));
21626 -- A descendant of type Ada.Synchronous_Task_Control.Suspension_Object
21627 -- yields a synchronized object by default.
21629 elsif Is_Descendant_Of_Suspension_Object (Typ) then
21632 -- A protected type yields a synchronized object by default
21634 elsif Is_Protected_Type (Typ) then
21637 -- A record type or type extension yields a synchronized object when its
21638 -- discriminants (if any) lack default values and all components are of
21639 -- a type that yelds a synchronized object.
21641 elsif Is_Record_Type (Typ) then
21643 -- Inspect all entities defined in the scope of the type, looking for
21644 -- components of a type that does not yeld a synchronized object or
21645 -- for discriminants with default values.
21647 Id := First_Entity (Typ);
21648 while Present (Id) loop
21649 if Comes_From_Source (Id) then
21650 if Ekind (Id) = E_Component then
21651 if Yields_Synchronized_Object (Etype (Id)) then
21652 Has_Sync_Comp := True;
21654 -- The component does not yield a synchronized object
21660 elsif Ekind (Id) = E_Discriminant
21661 and then Present (Expression (Parent (Id)))
21670 -- Ensure that the parent type of a type extension yields a
21671 -- synchronized object.
21673 if Etype (Typ) /= Typ
21674 and then not Yields_Synchronized_Object (Etype (Typ))
21679 -- If we get here, then all discriminants lack default values and all
21680 -- components are of a type that yields a synchronized object.
21682 return Has_Sync_Comp;
21684 -- A synchronized interface type yields a synchronized object by default
21686 elsif Is_Synchronized_Interface (Typ) then
21689 -- A task type yelds a synchronized object by default
21691 elsif Is_Task_Type (Typ) then
21694 -- Otherwise the type does not yield a synchronized object
21699 end Yields_Synchronized_Object;
21701 ---------------------------
21702 -- Yields_Universal_Type --
21703 ---------------------------
21705 function Yields_Universal_Type (N : Node_Id) return Boolean is
21707 -- Integer and real literals are of a universal type
21709 if Nkind_In (N, N_Integer_Literal, N_Real_Literal) then
21712 -- The values of certain attributes are of a universal type
21714 elsif Nkind (N) = N_Attribute_Reference then
21716 Universal_Type_Attribute (Get_Attribute_Id (Attribute_Name (N)));
21718 -- ??? There are possibly other cases to consider
21723 end Yields_Universal_Type;