1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2017, 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 type Null_Status_Kind is
105 -- This value indicates that a subexpression is known to have a null
106 -- value at compile time.
109 -- This value indicates that a subexpression is known to have a non-null
110 -- value at compile time.
113 -- This value indicates that it cannot be determined at compile time
114 -- whether a subexpression yields a null or non-null value.
116 function Null_Status (N : Node_Id) return Null_Status_Kind;
117 -- Determine whether subexpression N of an access type yields a null value,
118 -- a non-null value, or the value cannot be determined at compile time. The
119 -- routine does not take simple flow diagnostics into account, it relies on
120 -- static facts such as the presence of null exclusions.
122 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
123 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
124 -- ???We retain the old and new algorithms for Requires_Transient_Scope for
125 -- the time being. New_Requires_Transient_Scope is used by default; the
126 -- debug switch -gnatdQ can be used to do Old_Requires_Transient_Scope
127 -- instead. The intent is to use this temporarily to measure before/after
128 -- efficiency. Note: when this temporary code is removed, the documentation
129 -- of dQ in debug.adb should be removed.
131 procedure Results_Differ
135 -- ???Debugging code. Called when the Old_Val and New_Val differ. This
136 -- routine will be removed eventially when New_Requires_Transient_Scope
137 -- becomes Requires_Transient_Scope and Old_Requires_Transient_Scope is
140 ------------------------------
141 -- Abstract_Interface_List --
142 ------------------------------
144 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
148 if Is_Concurrent_Type (Typ) then
150 -- If we are dealing with a synchronized subtype, go to the base
151 -- type, whose declaration has the interface list.
153 -- Shouldn't this be Declaration_Node???
155 Nod := Parent (Base_Type (Typ));
157 if Nkind (Nod) = N_Full_Type_Declaration then
161 elsif Ekind (Typ) = E_Record_Type_With_Private then
162 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
163 Nod := Type_Definition (Parent (Typ));
165 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
166 if Present (Full_View (Typ))
168 Nkind (Parent (Full_View (Typ))) = N_Full_Type_Declaration
170 Nod := Type_Definition (Parent (Full_View (Typ)));
172 -- If the full-view is not available we cannot do anything else
173 -- here (the source has errors).
179 -- Support for generic formals with interfaces is still missing ???
181 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
186 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
190 elsif Ekind (Typ) = E_Record_Subtype then
191 Nod := Type_Definition (Parent (Etype (Typ)));
193 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
195 -- Recurse, because parent may still be a private extension. Also
196 -- note that the full view of the subtype or the full view of its
197 -- base type may (both) be unavailable.
199 return Abstract_Interface_List (Etype (Typ));
201 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
202 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
203 Nod := Formal_Type_Definition (Parent (Typ));
205 Nod := Type_Definition (Parent (Typ));
209 return Interface_List (Nod);
210 end Abstract_Interface_List;
212 --------------------------------
213 -- Add_Access_Type_To_Process --
214 --------------------------------
216 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
220 Ensure_Freeze_Node (E);
221 L := Access_Types_To_Process (Freeze_Node (E));
225 Set_Access_Types_To_Process (Freeze_Node (E), L);
229 end Add_Access_Type_To_Process;
231 --------------------------
232 -- Add_Block_Identifier --
233 --------------------------
235 procedure Add_Block_Identifier (N : Node_Id; Id : out Entity_Id) is
236 Loc : constant Source_Ptr := Sloc (N);
239 pragma Assert (Nkind (N) = N_Block_Statement);
241 -- The block already has a label, return its entity
243 if Present (Identifier (N)) then
244 Id := Entity (Identifier (N));
246 -- Create a new block label and set its attributes
249 Id := New_Internal_Entity (E_Block, Current_Scope, Loc, 'B');
250 Set_Etype (Id, Standard_Void_Type);
253 Set_Identifier (N, New_Occurrence_Of (Id, Loc));
254 Set_Block_Node (Id, Identifier (N));
256 end Add_Block_Identifier;
258 ----------------------------
259 -- Add_Global_Declaration --
260 ----------------------------
262 procedure Add_Global_Declaration (N : Node_Id) is
263 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
266 if No (Declarations (Aux_Node)) then
267 Set_Declarations (Aux_Node, New_List);
270 Append_To (Declarations (Aux_Node), N);
272 end Add_Global_Declaration;
274 --------------------------------
275 -- Address_Integer_Convert_OK --
276 --------------------------------
278 function Address_Integer_Convert_OK (T1, T2 : Entity_Id) return Boolean is
280 if Allow_Integer_Address
281 and then ((Is_Descendant_Of_Address (T1)
282 and then Is_Private_Type (T1)
283 and then Is_Integer_Type (T2))
285 (Is_Descendant_Of_Address (T2)
286 and then Is_Private_Type (T2)
287 and then Is_Integer_Type (T1)))
293 end Address_Integer_Convert_OK;
299 function Address_Value (N : Node_Id) return Node_Id is
304 -- For constant, get constant expression
306 if Is_Entity_Name (Expr)
307 and then Ekind (Entity (Expr)) = E_Constant
309 Expr := Constant_Value (Entity (Expr));
311 -- For unchecked conversion, get result to convert
313 elsif Nkind (Expr) = N_Unchecked_Type_Conversion then
314 Expr := Expression (Expr);
316 -- For (common case) of To_Address call, get argument
318 elsif Nkind (Expr) = N_Function_Call
319 and then Is_Entity_Name (Name (Expr))
320 and then Is_RTE (Entity (Name (Expr)), RE_To_Address)
322 Expr := First (Parameter_Associations (Expr));
324 if Nkind (Expr) = N_Parameter_Association then
325 Expr := Explicit_Actual_Parameter (Expr);
328 -- We finally have the real expression
342 -- For now, just 8/16/32/64
344 function Addressable (V : Uint) return Boolean is
346 return V = Uint_8 or else
352 function Addressable (V : Int) return Boolean is
360 ---------------------------------
361 -- Aggregate_Constraint_Checks --
362 ---------------------------------
364 procedure Aggregate_Constraint_Checks
366 Check_Typ : Entity_Id)
368 Exp_Typ : constant Entity_Id := Etype (Exp);
371 if Raises_Constraint_Error (Exp) then
375 -- Ada 2005 (AI-230): Generate a conversion to an anonymous access
376 -- component's type to force the appropriate accessibility checks.
378 -- Ada 2005 (AI-231): Generate conversion to the null-excluding type to
379 -- force the corresponding run-time check
381 if Is_Access_Type (Check_Typ)
382 and then Is_Local_Anonymous_Access (Check_Typ)
384 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
385 Analyze_And_Resolve (Exp, Check_Typ);
386 Check_Unset_Reference (Exp);
389 -- What follows is really expansion activity, so check that expansion
390 -- is on and is allowed. In GNATprove mode, we also want check flags to
391 -- be added in the tree, so that the formal verification can rely on
392 -- those to be present. In GNATprove mode for formal verification, some
393 -- treatment typically only done during expansion needs to be performed
394 -- on the tree, but it should not be applied inside generics. Otherwise,
395 -- this breaks the name resolution mechanism for generic instances.
397 if not Expander_Active
398 and (Inside_A_Generic or not Full_Analysis or not GNATprove_Mode)
403 if Is_Access_Type (Check_Typ)
404 and then Can_Never_Be_Null (Check_Typ)
405 and then not Can_Never_Be_Null (Exp_Typ)
407 Install_Null_Excluding_Check (Exp);
410 -- First check if we have to insert discriminant checks
412 if Has_Discriminants (Exp_Typ) then
413 Apply_Discriminant_Check (Exp, Check_Typ);
415 -- Next emit length checks for array aggregates
417 elsif Is_Array_Type (Exp_Typ) then
418 Apply_Length_Check (Exp, Check_Typ);
420 -- Finally emit scalar and string checks. If we are dealing with a
421 -- scalar literal we need to check by hand because the Etype of
422 -- literals is not necessarily correct.
424 elsif Is_Scalar_Type (Exp_Typ)
425 and then Compile_Time_Known_Value (Exp)
427 if Is_Out_Of_Range (Exp, Base_Type (Check_Typ)) then
428 Apply_Compile_Time_Constraint_Error
429 (Exp, "value not in range of}??", CE_Range_Check_Failed,
430 Ent => Base_Type (Check_Typ),
431 Typ => Base_Type (Check_Typ));
433 elsif Is_Out_Of_Range (Exp, Check_Typ) then
434 Apply_Compile_Time_Constraint_Error
435 (Exp, "value not in range of}??", CE_Range_Check_Failed,
439 elsif not Range_Checks_Suppressed (Check_Typ) then
440 Apply_Scalar_Range_Check (Exp, Check_Typ);
443 -- Verify that target type is also scalar, to prevent view anomalies
444 -- in instantiations.
446 elsif (Is_Scalar_Type (Exp_Typ)
447 or else Nkind (Exp) = N_String_Literal)
448 and then Is_Scalar_Type (Check_Typ)
449 and then Exp_Typ /= Check_Typ
451 if Is_Entity_Name (Exp)
452 and then Ekind (Entity (Exp)) = E_Constant
454 -- If expression is a constant, it is worthwhile checking whether
455 -- it is a bound of the type.
457 if (Is_Entity_Name (Type_Low_Bound (Check_Typ))
458 and then Entity (Exp) = Entity (Type_Low_Bound (Check_Typ)))
460 (Is_Entity_Name (Type_High_Bound (Check_Typ))
461 and then Entity (Exp) = Entity (Type_High_Bound (Check_Typ)))
466 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
467 Analyze_And_Resolve (Exp, Check_Typ);
468 Check_Unset_Reference (Exp);
471 -- Could use a comment on this case ???
474 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
475 Analyze_And_Resolve (Exp, Check_Typ);
476 Check_Unset_Reference (Exp);
480 end Aggregate_Constraint_Checks;
482 -----------------------
483 -- Alignment_In_Bits --
484 -----------------------
486 function Alignment_In_Bits (E : Entity_Id) return Uint is
488 return Alignment (E) * System_Storage_Unit;
489 end Alignment_In_Bits;
491 --------------------------------------
492 -- All_Composite_Constraints_Static --
493 --------------------------------------
495 function All_Composite_Constraints_Static
496 (Constr : Node_Id) return Boolean
499 if No (Constr) or else Error_Posted (Constr) then
503 case Nkind (Constr) is
505 if Nkind (Constr) in N_Has_Entity
506 and then Present (Entity (Constr))
508 if Is_Type (Entity (Constr)) then
510 not Is_Discrete_Type (Entity (Constr))
511 or else Is_OK_Static_Subtype (Entity (Constr));
514 elsif Nkind (Constr) = N_Range then
516 Is_OK_Static_Expression (Low_Bound (Constr))
518 Is_OK_Static_Expression (High_Bound (Constr));
520 elsif Nkind (Constr) = N_Attribute_Reference
521 and then Attribute_Name (Constr) = Name_Range
524 Is_OK_Static_Expression
525 (Type_Low_Bound (Etype (Prefix (Constr))))
527 Is_OK_Static_Expression
528 (Type_High_Bound (Etype (Prefix (Constr))));
532 not Present (Etype (Constr)) -- previous error
533 or else not Is_Discrete_Type (Etype (Constr))
534 or else Is_OK_Static_Expression (Constr);
536 when N_Discriminant_Association =>
537 return All_Composite_Constraints_Static (Expression (Constr));
539 when N_Range_Constraint =>
541 All_Composite_Constraints_Static (Range_Expression (Constr));
543 when N_Index_Or_Discriminant_Constraint =>
545 One_Cstr : Entity_Id;
547 One_Cstr := First (Constraints (Constr));
548 while Present (One_Cstr) loop
549 if not All_Composite_Constraints_Static (One_Cstr) then
559 when N_Subtype_Indication =>
561 All_Composite_Constraints_Static (Subtype_Mark (Constr))
563 All_Composite_Constraints_Static (Constraint (Constr));
568 end All_Composite_Constraints_Static;
570 ---------------------------------
571 -- Append_Inherited_Subprogram --
572 ---------------------------------
574 procedure Append_Inherited_Subprogram (S : Entity_Id) is
575 Par : constant Entity_Id := Alias (S);
576 -- The parent subprogram
578 Scop : constant Entity_Id := Scope (Par);
579 -- The scope of definition of the parent subprogram
581 Typ : constant Entity_Id := Defining_Entity (Parent (S));
582 -- The derived type of which S is a primitive operation
588 if Ekind (Current_Scope) = E_Package
589 and then In_Private_Part (Current_Scope)
590 and then Has_Private_Declaration (Typ)
591 and then Is_Tagged_Type (Typ)
592 and then Scop = Current_Scope
594 -- The inherited operation is available at the earliest place after
595 -- the derived type declaration ( RM 7.3.1 (6/1)). This is only
596 -- relevant for type extensions. If the parent operation appears
597 -- after the type extension, the operation is not visible.
600 (Visible_Declarations
601 (Package_Specification (Current_Scope)));
602 while Present (Decl) loop
603 if Nkind (Decl) = N_Private_Extension_Declaration
604 and then Defining_Entity (Decl) = Typ
606 if Sloc (Decl) > Sloc (Par) then
607 Next_E := Next_Entity (Par);
608 Set_Next_Entity (Par, S);
609 Set_Next_Entity (S, Next_E);
621 -- If partial view is not a type extension, or it appears before the
622 -- subprogram declaration, insert normally at end of entity list.
624 Append_Entity (S, Current_Scope);
625 end Append_Inherited_Subprogram;
627 -----------------------------------------
628 -- Apply_Compile_Time_Constraint_Error --
629 -----------------------------------------
631 procedure Apply_Compile_Time_Constraint_Error
634 Reason : RT_Exception_Code;
635 Ent : Entity_Id := Empty;
636 Typ : Entity_Id := Empty;
637 Loc : Source_Ptr := No_Location;
638 Rep : Boolean := True;
639 Warn : Boolean := False)
641 Stat : constant Boolean := Is_Static_Expression (N);
642 R_Stat : constant Node_Id :=
643 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
654 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
656 -- In GNATprove mode, do not replace the node with an exception raised.
657 -- In such a case, either the call to Compile_Time_Constraint_Error
658 -- issues an error which stops analysis, or it issues a warning in
659 -- a few cases where a suitable check flag is set for GNATprove to
660 -- generate a check message.
662 if not Rep or GNATprove_Mode then
666 -- Now we replace the node by an N_Raise_Constraint_Error node
667 -- This does not need reanalyzing, so set it as analyzed now.
670 Set_Analyzed (N, True);
673 Set_Raises_Constraint_Error (N);
675 -- Now deal with possible local raise handling
677 Possible_Local_Raise (N, Standard_Constraint_Error);
679 -- If the original expression was marked as static, the result is
680 -- still marked as static, but the Raises_Constraint_Error flag is
681 -- always set so that further static evaluation is not attempted.
684 Set_Is_Static_Expression (N);
686 end Apply_Compile_Time_Constraint_Error;
688 ---------------------------
689 -- Async_Readers_Enabled --
690 ---------------------------
692 function Async_Readers_Enabled (Id : Entity_Id) return Boolean is
694 return Has_Enabled_Property (Id, Name_Async_Readers);
695 end Async_Readers_Enabled;
697 ---------------------------
698 -- Async_Writers_Enabled --
699 ---------------------------
701 function Async_Writers_Enabled (Id : Entity_Id) return Boolean is
703 return Has_Enabled_Property (Id, Name_Async_Writers);
704 end Async_Writers_Enabled;
706 --------------------------------------
707 -- Available_Full_View_Of_Component --
708 --------------------------------------
710 function Available_Full_View_Of_Component (T : Entity_Id) return Boolean is
711 ST : constant Entity_Id := Scope (T);
712 SCT : constant Entity_Id := Scope (Component_Type (T));
714 return In_Open_Scopes (ST)
715 and then In_Open_Scopes (SCT)
716 and then Scope_Depth (ST) >= Scope_Depth (SCT);
717 end Available_Full_View_Of_Component;
723 procedure Bad_Attribute
726 Warn : Boolean := False)
729 Error_Msg_Warn := Warn;
730 Error_Msg_N ("unrecognized attribute&<<", N);
732 -- Check for possible misspelling
734 Error_Msg_Name_1 := First_Attribute_Name;
735 while Error_Msg_Name_1 <= Last_Attribute_Name loop
736 if Is_Bad_Spelling_Of (Nam, Error_Msg_Name_1) then
737 Error_Msg_N -- CODEFIX
738 ("\possible misspelling of %<<", N);
742 Error_Msg_Name_1 := Error_Msg_Name_1 + 1;
746 --------------------------------
747 -- Bad_Predicated_Subtype_Use --
748 --------------------------------
750 procedure Bad_Predicated_Subtype_Use
754 Suggest_Static : Boolean := False)
759 -- Avoid cascaded errors
761 if Error_Posted (N) then
765 if Inside_A_Generic then
766 Gen := Current_Scope;
767 while Present (Gen) and then Ekind (Gen) /= E_Generic_Package loop
775 if Is_Generic_Formal (Typ) and then Is_Discrete_Type (Typ) then
776 Set_No_Predicate_On_Actual (Typ);
779 elsif Has_Predicates (Typ) then
780 if Is_Generic_Actual_Type (Typ) then
782 -- The restriction on loop parameters is only that the type
783 -- should have no dynamic predicates.
785 if Nkind (Parent (N)) = N_Loop_Parameter_Specification
786 and then not Has_Dynamic_Predicate_Aspect (Typ)
787 and then Is_OK_Static_Subtype (Typ)
792 Gen := Current_Scope;
793 while not Is_Generic_Instance (Gen) loop
797 pragma Assert (Present (Gen));
799 if Ekind (Gen) = E_Package and then In_Package_Body (Gen) then
800 Error_Msg_Warn := SPARK_Mode /= On;
801 Error_Msg_FE (Msg & "<<", N, Typ);
802 Error_Msg_F ("\Program_Error [<<", N);
805 Make_Raise_Program_Error (Sloc (N),
806 Reason => PE_Bad_Predicated_Generic_Type));
809 Error_Msg_FE (Msg & "<<", N, Typ);
813 Error_Msg_FE (Msg, N, Typ);
816 -- Emit an optional suggestion on how to remedy the error if the
817 -- context warrants it.
819 if Suggest_Static and then Has_Static_Predicate (Typ) then
820 Error_Msg_FE ("\predicate of & should be marked static", N, Typ);
823 end Bad_Predicated_Subtype_Use;
825 -----------------------------------------
826 -- Bad_Unordered_Enumeration_Reference --
827 -----------------------------------------
829 function Bad_Unordered_Enumeration_Reference
831 T : Entity_Id) return Boolean
834 return Is_Enumeration_Type (T)
835 and then Warn_On_Unordered_Enumeration_Type
836 and then not Is_Generic_Type (T)
837 and then Comes_From_Source (N)
838 and then not Has_Pragma_Ordered (T)
839 and then not In_Same_Extended_Unit (N, T);
840 end Bad_Unordered_Enumeration_Reference;
842 --------------------------
843 -- Build_Actual_Subtype --
844 --------------------------
846 function Build_Actual_Subtype
848 N : Node_Or_Entity_Id) return Node_Id
851 -- Normally Sloc (N), but may point to corresponding body in some cases
853 Constraints : List_Id;
859 Disc_Type : Entity_Id;
865 if Nkind (N) = N_Defining_Identifier then
866 Obj := New_Occurrence_Of (N, Loc);
868 -- If this is a formal parameter of a subprogram declaration, and
869 -- we are compiling the body, we want the declaration for the
870 -- actual subtype to carry the source position of the body, to
871 -- prevent anomalies in gdb when stepping through the code.
873 if Is_Formal (N) then
875 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
877 if Nkind (Decl) = N_Subprogram_Declaration
878 and then Present (Corresponding_Body (Decl))
880 Loc := Sloc (Corresponding_Body (Decl));
889 if Is_Array_Type (T) then
890 Constraints := New_List;
891 for J in 1 .. Number_Dimensions (T) loop
893 -- Build an array subtype declaration with the nominal subtype and
894 -- the bounds of the actual. Add the declaration in front of the
895 -- local declarations for the subprogram, for analysis before any
896 -- reference to the formal in the body.
899 Make_Attribute_Reference (Loc,
901 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
902 Attribute_Name => Name_First,
903 Expressions => New_List (
904 Make_Integer_Literal (Loc, J)));
907 Make_Attribute_Reference (Loc,
909 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
910 Attribute_Name => Name_Last,
911 Expressions => New_List (
912 Make_Integer_Literal (Loc, J)));
914 Append (Make_Range (Loc, Lo, Hi), Constraints);
917 -- If the type has unknown discriminants there is no constrained
918 -- subtype to build. This is never called for a formal or for a
919 -- lhs, so returning the type is ok ???
921 elsif Has_Unknown_Discriminants (T) then
925 Constraints := New_List;
927 -- Type T is a generic derived type, inherit the discriminants from
930 if Is_Private_Type (T)
931 and then No (Full_View (T))
933 -- T was flagged as an error if it was declared as a formal
934 -- derived type with known discriminants. In this case there
935 -- is no need to look at the parent type since T already carries
936 -- its own discriminants.
938 and then not Error_Posted (T)
940 Disc_Type := Etype (Base_Type (T));
945 Discr := First_Discriminant (Disc_Type);
946 while Present (Discr) loop
947 Append_To (Constraints,
948 Make_Selected_Component (Loc,
950 Duplicate_Subexpr_No_Checks (Obj),
951 Selector_Name => New_Occurrence_Of (Discr, Loc)));
952 Next_Discriminant (Discr);
956 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
957 Set_Is_Internal (Subt);
960 Make_Subtype_Declaration (Loc,
961 Defining_Identifier => Subt,
962 Subtype_Indication =>
963 Make_Subtype_Indication (Loc,
964 Subtype_Mark => New_Occurrence_Of (T, Loc),
966 Make_Index_Or_Discriminant_Constraint (Loc,
967 Constraints => Constraints)));
969 Mark_Rewrite_Insertion (Decl);
971 end Build_Actual_Subtype;
973 ---------------------------------------
974 -- Build_Actual_Subtype_Of_Component --
975 ---------------------------------------
977 function Build_Actual_Subtype_Of_Component
979 N : Node_Id) return Node_Id
981 Loc : constant Source_Ptr := Sloc (N);
982 P : constant Node_Id := Prefix (N);
985 Index_Typ : Entity_Id;
987 Desig_Typ : Entity_Id;
988 -- This is either a copy of T, or if T is an access type, then it is
989 -- the directly designated type of this access type.
991 function Build_Actual_Array_Constraint return List_Id;
992 -- If one or more of the bounds of the component depends on
993 -- discriminants, build actual constraint using the discriminants
996 function Build_Actual_Record_Constraint return List_Id;
997 -- Similar to previous one, for discriminated components constrained
998 -- by the discriminant of the enclosing object.
1000 -----------------------------------
1001 -- Build_Actual_Array_Constraint --
1002 -----------------------------------
1004 function Build_Actual_Array_Constraint return List_Id is
1005 Constraints : constant List_Id := New_List;
1013 Indx := First_Index (Desig_Typ);
1014 while Present (Indx) loop
1015 Old_Lo := Type_Low_Bound (Etype (Indx));
1016 Old_Hi := Type_High_Bound (Etype (Indx));
1018 if Denotes_Discriminant (Old_Lo) then
1020 Make_Selected_Component (Loc,
1021 Prefix => New_Copy_Tree (P),
1022 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
1025 Lo := New_Copy_Tree (Old_Lo);
1027 -- The new bound will be reanalyzed in the enclosing
1028 -- declaration. For literal bounds that come from a type
1029 -- declaration, the type of the context must be imposed, so
1030 -- insure that analysis will take place. For non-universal
1031 -- types this is not strictly necessary.
1033 Set_Analyzed (Lo, False);
1036 if Denotes_Discriminant (Old_Hi) then
1038 Make_Selected_Component (Loc,
1039 Prefix => New_Copy_Tree (P),
1040 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
1043 Hi := New_Copy_Tree (Old_Hi);
1044 Set_Analyzed (Hi, False);
1047 Append (Make_Range (Loc, Lo, Hi), Constraints);
1052 end Build_Actual_Array_Constraint;
1054 ------------------------------------
1055 -- Build_Actual_Record_Constraint --
1056 ------------------------------------
1058 function Build_Actual_Record_Constraint return List_Id is
1059 Constraints : constant List_Id := New_List;
1064 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1065 while Present (D) loop
1066 if Denotes_Discriminant (Node (D)) then
1067 D_Val := Make_Selected_Component (Loc,
1068 Prefix => New_Copy_Tree (P),
1069 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
1072 D_Val := New_Copy_Tree (Node (D));
1075 Append (D_Val, Constraints);
1080 end Build_Actual_Record_Constraint;
1082 -- Start of processing for Build_Actual_Subtype_Of_Component
1085 -- Why the test for Spec_Expression mode here???
1087 if In_Spec_Expression then
1090 -- More comments for the rest of this body would be good ???
1092 elsif Nkind (N) = N_Explicit_Dereference then
1093 if Is_Composite_Type (T)
1094 and then not Is_Constrained (T)
1095 and then not (Is_Class_Wide_Type (T)
1096 and then Is_Constrained (Root_Type (T)))
1097 and then not Has_Unknown_Discriminants (T)
1099 -- If the type of the dereference is already constrained, it is an
1102 if Is_Array_Type (Etype (N))
1103 and then Is_Constrained (Etype (N))
1107 Remove_Side_Effects (P);
1108 return Build_Actual_Subtype (T, N);
1115 if Ekind (T) = E_Access_Subtype then
1116 Desig_Typ := Designated_Type (T);
1121 if Ekind (Desig_Typ) = E_Array_Subtype then
1122 Id := First_Index (Desig_Typ);
1123 while Present (Id) loop
1124 Index_Typ := Underlying_Type (Etype (Id));
1126 if Denotes_Discriminant (Type_Low_Bound (Index_Typ))
1128 Denotes_Discriminant (Type_High_Bound (Index_Typ))
1130 Remove_Side_Effects (P);
1132 Build_Component_Subtype
1133 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
1139 elsif Is_Composite_Type (Desig_Typ)
1140 and then Has_Discriminants (Desig_Typ)
1141 and then not Has_Unknown_Discriminants (Desig_Typ)
1143 if Is_Private_Type (Desig_Typ)
1144 and then No (Discriminant_Constraint (Desig_Typ))
1146 Desig_Typ := Full_View (Desig_Typ);
1149 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1150 while Present (D) loop
1151 if Denotes_Discriminant (Node (D)) then
1152 Remove_Side_Effects (P);
1154 Build_Component_Subtype (
1155 Build_Actual_Record_Constraint, Loc, Base_Type (T));
1162 -- If none of the above, the actual and nominal subtypes are the same
1165 end Build_Actual_Subtype_Of_Component;
1167 -----------------------------
1168 -- Build_Component_Subtype --
1169 -----------------------------
1171 function Build_Component_Subtype
1174 T : Entity_Id) return Node_Id
1180 -- Unchecked_Union components do not require component subtypes
1182 if Is_Unchecked_Union (T) then
1186 Subt := Make_Temporary (Loc, 'S');
1187 Set_Is_Internal (Subt);
1190 Make_Subtype_Declaration (Loc,
1191 Defining_Identifier => Subt,
1192 Subtype_Indication =>
1193 Make_Subtype_Indication (Loc,
1194 Subtype_Mark => New_Occurrence_Of (Base_Type (T), Loc),
1196 Make_Index_Or_Discriminant_Constraint (Loc,
1197 Constraints => C)));
1199 Mark_Rewrite_Insertion (Decl);
1201 end Build_Component_Subtype;
1203 ---------------------------
1204 -- Build_Default_Subtype --
1205 ---------------------------
1207 function Build_Default_Subtype
1209 N : Node_Id) return Entity_Id
1211 Loc : constant Source_Ptr := Sloc (N);
1215 -- The base type that is to be constrained by the defaults
1218 if not Has_Discriminants (T) or else Is_Constrained (T) then
1222 Bas := Base_Type (T);
1224 -- If T is non-private but its base type is private, this is the
1225 -- completion of a subtype declaration whose parent type is private
1226 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1227 -- are to be found in the full view of the base. Check that the private
1228 -- status of T and its base differ.
1230 if Is_Private_Type (Bas)
1231 and then not Is_Private_Type (T)
1232 and then Present (Full_View (Bas))
1234 Bas := Full_View (Bas);
1237 Disc := First_Discriminant (T);
1239 if No (Discriminant_Default_Value (Disc)) then
1244 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
1245 Constraints : constant List_Id := New_List;
1249 while Present (Disc) loop
1250 Append_To (Constraints,
1251 New_Copy_Tree (Discriminant_Default_Value (Disc)));
1252 Next_Discriminant (Disc);
1256 Make_Subtype_Declaration (Loc,
1257 Defining_Identifier => Act,
1258 Subtype_Indication =>
1259 Make_Subtype_Indication (Loc,
1260 Subtype_Mark => New_Occurrence_Of (Bas, Loc),
1262 Make_Index_Or_Discriminant_Constraint (Loc,
1263 Constraints => Constraints)));
1265 Insert_Action (N, Decl);
1267 -- If the context is a component declaration the subtype declaration
1268 -- will be analyzed when the enclosing type is frozen, otherwise do
1271 if Ekind (Current_Scope) /= E_Record_Type then
1277 end Build_Default_Subtype;
1279 --------------------------------------------
1280 -- Build_Discriminal_Subtype_Of_Component --
1281 --------------------------------------------
1283 function Build_Discriminal_Subtype_Of_Component
1284 (T : Entity_Id) return Node_Id
1286 Loc : constant Source_Ptr := Sloc (T);
1290 function Build_Discriminal_Array_Constraint return List_Id;
1291 -- If one or more of the bounds of the component depends on
1292 -- discriminants, build actual constraint using the discriminants
1295 function Build_Discriminal_Record_Constraint return List_Id;
1296 -- Similar to previous one, for discriminated components constrained by
1297 -- the discriminant of the enclosing object.
1299 ----------------------------------------
1300 -- Build_Discriminal_Array_Constraint --
1301 ----------------------------------------
1303 function Build_Discriminal_Array_Constraint return List_Id is
1304 Constraints : constant List_Id := New_List;
1312 Indx := First_Index (T);
1313 while Present (Indx) loop
1314 Old_Lo := Type_Low_Bound (Etype (Indx));
1315 Old_Hi := Type_High_Bound (Etype (Indx));
1317 if Denotes_Discriminant (Old_Lo) then
1318 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
1321 Lo := New_Copy_Tree (Old_Lo);
1324 if Denotes_Discriminant (Old_Hi) then
1325 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
1328 Hi := New_Copy_Tree (Old_Hi);
1331 Append (Make_Range (Loc, Lo, Hi), Constraints);
1336 end Build_Discriminal_Array_Constraint;
1338 -----------------------------------------
1339 -- Build_Discriminal_Record_Constraint --
1340 -----------------------------------------
1342 function Build_Discriminal_Record_Constraint return List_Id is
1343 Constraints : constant List_Id := New_List;
1348 D := First_Elmt (Discriminant_Constraint (T));
1349 while Present (D) loop
1350 if Denotes_Discriminant (Node (D)) then
1352 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
1354 D_Val := New_Copy_Tree (Node (D));
1357 Append (D_Val, Constraints);
1362 end Build_Discriminal_Record_Constraint;
1364 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1367 if Ekind (T) = E_Array_Subtype then
1368 Id := First_Index (T);
1369 while Present (Id) loop
1370 if Denotes_Discriminant (Type_Low_Bound (Etype (Id)))
1372 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
1374 return Build_Component_Subtype
1375 (Build_Discriminal_Array_Constraint, Loc, T);
1381 elsif Ekind (T) = E_Record_Subtype
1382 and then Has_Discriminants (T)
1383 and then not Has_Unknown_Discriminants (T)
1385 D := First_Elmt (Discriminant_Constraint (T));
1386 while Present (D) loop
1387 if Denotes_Discriminant (Node (D)) then
1388 return Build_Component_Subtype
1389 (Build_Discriminal_Record_Constraint, Loc, T);
1396 -- If none of the above, the actual and nominal subtypes are the same
1399 end Build_Discriminal_Subtype_Of_Component;
1401 ------------------------------
1402 -- Build_Elaboration_Entity --
1403 ------------------------------
1405 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
1406 Loc : constant Source_Ptr := Sloc (N);
1408 Elab_Ent : Entity_Id;
1410 procedure Set_Package_Name (Ent : Entity_Id);
1411 -- Given an entity, sets the fully qualified name of the entity in
1412 -- Name_Buffer, with components separated by double underscores. This
1413 -- is a recursive routine that climbs the scope chain to Standard.
1415 ----------------------
1416 -- Set_Package_Name --
1417 ----------------------
1419 procedure Set_Package_Name (Ent : Entity_Id) is
1421 if Scope (Ent) /= Standard_Standard then
1422 Set_Package_Name (Scope (Ent));
1425 Nam : constant String := Get_Name_String (Chars (Ent));
1427 Name_Buffer (Name_Len + 1) := '_';
1428 Name_Buffer (Name_Len + 2) := '_';
1429 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
1430 Name_Len := Name_Len + Nam'Length + 2;
1434 Get_Name_String (Chars (Ent));
1436 end Set_Package_Name;
1438 -- Start of processing for Build_Elaboration_Entity
1441 -- Ignore call if already constructed
1443 if Present (Elaboration_Entity (Spec_Id)) then
1446 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1447 -- no role in analysis.
1449 elsif ASIS_Mode then
1452 -- See if we need elaboration entity.
1454 -- We always need an elaboration entity when preserving control flow, as
1455 -- we want to remain explicit about the unit's elaboration order.
1457 elsif Opt.Suppress_Control_Flow_Optimizations then
1460 -- We always need an elaboration entity for the dynamic elaboration
1461 -- model, since it is needed to properly generate the PE exception for
1462 -- access before elaboration.
1464 elsif Dynamic_Elaboration_Checks then
1467 -- For the static model, we don't need the elaboration counter if this
1468 -- unit is sure to have no elaboration code, since that means there
1469 -- is no elaboration unit to be called. Note that we can't just decide
1470 -- after the fact by looking to see whether there was elaboration code,
1471 -- because that's too late to make this decision.
1473 elsif Restriction_Active (No_Elaboration_Code) then
1476 -- Similarly, for the static model, we can skip the elaboration counter
1477 -- if we have the No_Multiple_Elaboration restriction, since for the
1478 -- static model, that's the only purpose of the counter (to avoid
1479 -- multiple elaboration).
1481 elsif Restriction_Active (No_Multiple_Elaboration) then
1485 -- Here we need the elaboration entity
1487 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1488 -- name with dots replaced by double underscore. We have to manually
1489 -- construct this name, since it will be elaborated in the outer scope,
1490 -- and thus will not have the unit name automatically prepended.
1492 Set_Package_Name (Spec_Id);
1493 Add_Str_To_Name_Buffer ("_E");
1495 -- Create elaboration counter
1497 Elab_Ent := Make_Defining_Identifier (Loc, Chars => Name_Find);
1498 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
1501 Make_Object_Declaration (Loc,
1502 Defining_Identifier => Elab_Ent,
1503 Object_Definition =>
1504 New_Occurrence_Of (Standard_Short_Integer, Loc),
1505 Expression => Make_Integer_Literal (Loc, Uint_0));
1507 Push_Scope (Standard_Standard);
1508 Add_Global_Declaration (Decl);
1511 -- Reset True_Constant indication, since we will indeed assign a value
1512 -- to the variable in the binder main. We also kill the Current_Value
1513 -- and Last_Assignment fields for the same reason.
1515 Set_Is_True_Constant (Elab_Ent, False);
1516 Set_Current_Value (Elab_Ent, Empty);
1517 Set_Last_Assignment (Elab_Ent, Empty);
1519 -- We do not want any further qualification of the name (if we did not
1520 -- do this, we would pick up the name of the generic package in the case
1521 -- of a library level generic instantiation).
1523 Set_Has_Qualified_Name (Elab_Ent);
1524 Set_Has_Fully_Qualified_Name (Elab_Ent);
1525 end Build_Elaboration_Entity;
1527 --------------------------------
1528 -- Build_Explicit_Dereference --
1529 --------------------------------
1531 procedure Build_Explicit_Dereference
1535 Loc : constant Source_Ptr := Sloc (Expr);
1540 -- An entity of a type with a reference aspect is overloaded with
1541 -- both interpretations: with and without the dereference. Now that
1542 -- the dereference is made explicit, set the type of the node properly,
1543 -- to prevent anomalies in the backend. Same if the expression is an
1544 -- overloaded function call whose return type has a reference aspect.
1546 if Is_Entity_Name (Expr) then
1547 Set_Etype (Expr, Etype (Entity (Expr)));
1549 -- The designated entity will not be examined again when resolving
1550 -- the dereference, so generate a reference to it now.
1552 Generate_Reference (Entity (Expr), Expr);
1554 elsif Nkind (Expr) = N_Function_Call then
1556 -- If the name of the indexing function is overloaded, locate the one
1557 -- whose return type has an implicit dereference on the desired
1558 -- discriminant, and set entity and type of function call.
1560 if Is_Overloaded (Name (Expr)) then
1561 Get_First_Interp (Name (Expr), I, It);
1563 while Present (It.Nam) loop
1564 if Ekind ((It.Typ)) = E_Record_Type
1565 and then First_Entity ((It.Typ)) = Disc
1567 Set_Entity (Name (Expr), It.Nam);
1568 Set_Etype (Name (Expr), Etype (It.Nam));
1572 Get_Next_Interp (I, It);
1576 -- Set type of call from resolved function name.
1578 Set_Etype (Expr, Etype (Name (Expr)));
1581 Set_Is_Overloaded (Expr, False);
1583 -- The expression will often be a generalized indexing that yields a
1584 -- container element that is then dereferenced, in which case the
1585 -- generalized indexing call is also non-overloaded.
1587 if Nkind (Expr) = N_Indexed_Component
1588 and then Present (Generalized_Indexing (Expr))
1590 Set_Is_Overloaded (Generalized_Indexing (Expr), False);
1594 Make_Explicit_Dereference (Loc,
1596 Make_Selected_Component (Loc,
1597 Prefix => Relocate_Node (Expr),
1598 Selector_Name => New_Occurrence_Of (Disc, Loc))));
1599 Set_Etype (Prefix (Expr), Etype (Disc));
1600 Set_Etype (Expr, Designated_Type (Etype (Disc)));
1601 end Build_Explicit_Dereference;
1603 ---------------------------
1604 -- Build_Overriding_Spec --
1605 ---------------------------
1607 function Build_Overriding_Spec
1609 Typ : Entity_Id) return Node_Id
1611 Loc : constant Source_Ptr := Sloc (Typ);
1612 Par_Typ : constant Entity_Id := Find_Dispatching_Type (Op);
1613 Spec : constant Node_Id := Specification (Unit_Declaration_Node (Op));
1615 Formal_Spec : Node_Id;
1616 Formal_Type : Node_Id;
1620 New_Spec := Copy_Subprogram_Spec (Spec);
1622 Formal_Spec := First (Parameter_Specifications (New_Spec));
1623 while Present (Formal_Spec) loop
1624 Formal_Type := Parameter_Type (Formal_Spec);
1626 if Is_Entity_Name (Formal_Type)
1627 and then Entity (Formal_Type) = Par_Typ
1629 Rewrite (Formal_Type, New_Occurrence_Of (Typ, Loc));
1632 -- Nothing needs to be done for access parameters
1638 end Build_Overriding_Spec;
1640 -----------------------------------
1641 -- Cannot_Raise_Constraint_Error --
1642 -----------------------------------
1644 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
1646 if Compile_Time_Known_Value (Expr) then
1649 elsif Do_Range_Check (Expr) then
1652 elsif Raises_Constraint_Error (Expr) then
1656 case Nkind (Expr) is
1657 when N_Identifier =>
1660 when N_Expanded_Name =>
1663 when N_Selected_Component =>
1664 return not Do_Discriminant_Check (Expr);
1666 when N_Attribute_Reference =>
1667 if Do_Overflow_Check (Expr) then
1670 elsif No (Expressions (Expr)) then
1678 N := First (Expressions (Expr));
1679 while Present (N) loop
1680 if Cannot_Raise_Constraint_Error (N) then
1691 when N_Type_Conversion =>
1692 if Do_Overflow_Check (Expr)
1693 or else Do_Length_Check (Expr)
1694 or else Do_Tag_Check (Expr)
1698 return Cannot_Raise_Constraint_Error (Expression (Expr));
1701 when N_Unchecked_Type_Conversion =>
1702 return Cannot_Raise_Constraint_Error (Expression (Expr));
1705 if Do_Overflow_Check (Expr) then
1708 return Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1715 if Do_Division_Check (Expr)
1717 Do_Overflow_Check (Expr)
1722 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1724 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1743 | N_Op_Shift_Right_Arithmetic
1747 if Do_Overflow_Check (Expr) then
1751 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1753 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1760 end Cannot_Raise_Constraint_Error;
1762 -----------------------------
1763 -- Check_Part_Of_Reference --
1764 -----------------------------
1766 procedure Check_Part_Of_Reference (Var_Id : Entity_Id; Ref : Node_Id) is
1767 Conc_Typ : constant Entity_Id := Encapsulating_State (Var_Id);
1769 OK_Use : Boolean := False;
1772 Spec_Id : Entity_Id;
1775 -- Traverse the parent chain looking for a suitable context for the
1776 -- reference to the concurrent constituent.
1778 Par := Parent (Ref);
1779 while Present (Par) loop
1780 if Nkind (Par) = N_Pragma then
1781 Prag_Nam := Pragma_Name (Par);
1783 -- A concurrent constituent is allowed to appear in pragmas
1784 -- Initial_Condition and Initializes as this is part of the
1785 -- elaboration checks for the constituent (SPARK RM 9.3).
1787 if Nam_In (Prag_Nam, Name_Initial_Condition, Name_Initializes) then
1791 -- When the reference appears within pragma Depends or Global,
1792 -- check whether the pragma applies to a single task type. Note
1793 -- that the pragma is not encapsulated by the type definition,
1794 -- but this is still a valid context.
1796 elsif Nam_In (Prag_Nam, Name_Depends, Name_Global) then
1797 Decl := Find_Related_Declaration_Or_Body (Par);
1799 if Nkind (Decl) = N_Object_Declaration
1800 and then Defining_Entity (Decl) = Conc_Typ
1807 -- The reference appears somewhere in the definition of the single
1808 -- protected/task type (SPARK RM 9.3).
1810 elsif Nkind_In (Par, N_Single_Protected_Declaration,
1811 N_Single_Task_Declaration)
1812 and then Defining_Entity (Par) = Conc_Typ
1817 -- The reference appears within the expanded declaration or the body
1818 -- of the single protected/task type (SPARK RM 9.3).
1820 elsif Nkind_In (Par, N_Protected_Body,
1821 N_Protected_Type_Declaration,
1823 N_Task_Type_Declaration)
1825 Spec_Id := Unique_Defining_Entity (Par);
1827 if Present (Anonymous_Object (Spec_Id))
1828 and then Anonymous_Object (Spec_Id) = Conc_Typ
1834 -- The reference has been relocated within an internally generated
1835 -- package or subprogram. Assume that the reference is legal as the
1836 -- real check was already performed in the original context of the
1839 elsif Nkind_In (Par, N_Package_Body,
1840 N_Package_Declaration,
1842 N_Subprogram_Declaration)
1843 and then not Comes_From_Source (Par)
1845 -- Continue to examine the context if the reference appears in a
1846 -- subprogram body which was previously an expression function.
1848 if Nkind (Par) = N_Subprogram_Body
1849 and then Was_Expression_Function (Par)
1853 -- Otherwise the reference is legal
1860 -- The reference has been relocated to an inlined body for GNATprove.
1861 -- Assume that the reference is legal as the real check was already
1862 -- performed in the original context of the reference.
1864 elsif GNATprove_Mode
1865 and then Nkind (Par) = N_Subprogram_Body
1866 and then Chars (Defining_Entity (Par)) = Name_uParent
1872 Par := Parent (Par);
1875 -- The reference is illegal as it appears outside the definition or
1876 -- body of the single protected/task type.
1880 ("reference to variable & cannot appear in this context",
1882 Error_Msg_Name_1 := Chars (Var_Id);
1884 if Ekind (Conc_Typ) = E_Protected_Type then
1886 ("\% is constituent of single protected type &", Ref, Conc_Typ);
1889 ("\% is constituent of single task type &", Ref, Conc_Typ);
1892 end Check_Part_Of_Reference;
1894 -----------------------------------------
1895 -- Check_Dynamically_Tagged_Expression --
1896 -----------------------------------------
1898 procedure Check_Dynamically_Tagged_Expression
1901 Related_Nod : Node_Id)
1904 pragma Assert (Is_Tagged_Type (Typ));
1906 -- In order to avoid spurious errors when analyzing the expanded code,
1907 -- this check is done only for nodes that come from source and for
1908 -- actuals of generic instantiations.
1910 if (Comes_From_Source (Related_Nod)
1911 or else In_Generic_Actual (Expr))
1912 and then (Is_Class_Wide_Type (Etype (Expr))
1913 or else Is_Dynamically_Tagged (Expr))
1914 and then Is_Tagged_Type (Typ)
1915 and then not Is_Class_Wide_Type (Typ)
1917 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
1919 end Check_Dynamically_Tagged_Expression;
1921 --------------------------
1922 -- Check_Fully_Declared --
1923 --------------------------
1925 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
1927 if Ekind (T) = E_Incomplete_Type then
1929 -- Ada 2005 (AI-50217): If the type is available through a limited
1930 -- with_clause, verify that its full view has been analyzed.
1932 if From_Limited_With (T)
1933 and then Present (Non_Limited_View (T))
1934 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1936 -- The non-limited view is fully declared
1942 ("premature usage of incomplete}", N, First_Subtype (T));
1945 -- Need comments for these tests ???
1947 elsif Has_Private_Component (T)
1948 and then not Is_Generic_Type (Root_Type (T))
1949 and then not In_Spec_Expression
1951 -- Special case: if T is the anonymous type created for a single
1952 -- task or protected object, use the name of the source object.
1954 if Is_Concurrent_Type (T)
1955 and then not Comes_From_Source (T)
1956 and then Nkind (N) = N_Object_Declaration
1959 ("type of& has incomplete component",
1960 N, Defining_Identifier (N));
1963 ("premature usage of incomplete}",
1964 N, First_Subtype (T));
1967 end Check_Fully_Declared;
1969 -------------------------------------------
1970 -- Check_Function_With_Address_Parameter --
1971 -------------------------------------------
1973 procedure Check_Function_With_Address_Parameter (Subp_Id : Entity_Id) is
1978 F := First_Formal (Subp_Id);
1979 while Present (F) loop
1982 if Is_Private_Type (T) and then Present (Full_View (T)) then
1986 if Is_Descendant_Of_Address (T) or else Is_Limited_Type (T) then
1987 Set_Is_Pure (Subp_Id, False);
1993 end Check_Function_With_Address_Parameter;
1995 -------------------------------------
1996 -- Check_Function_Writable_Actuals --
1997 -------------------------------------
1999 procedure Check_Function_Writable_Actuals (N : Node_Id) is
2000 Writable_Actuals_List : Elist_Id := No_Elist;
2001 Identifiers_List : Elist_Id := No_Elist;
2002 Aggr_Error_Node : Node_Id := Empty;
2003 Error_Node : Node_Id := Empty;
2005 procedure Collect_Identifiers (N : Node_Id);
2006 -- In a single traversal of subtree N collect in Writable_Actuals_List
2007 -- all the actuals of functions with writable actuals, and in the list
2008 -- Identifiers_List collect all the identifiers that are not actuals of
2009 -- functions with writable actuals. If a writable actual is referenced
2010 -- twice as writable actual then Error_Node is set to reference its
2011 -- second occurrence, the error is reported, and the tree traversal
2014 function Get_Function_Id (Call : Node_Id) return Entity_Id;
2015 -- Return the entity associated with the function call
2017 procedure Preanalyze_Without_Errors (N : Node_Id);
2018 -- Preanalyze N without reporting errors. Very dubious, you can't just
2019 -- go analyzing things more than once???
2021 -------------------------
2022 -- Collect_Identifiers --
2023 -------------------------
2025 procedure Collect_Identifiers (N : Node_Id) is
2027 function Check_Node (N : Node_Id) return Traverse_Result;
2028 -- Process a single node during the tree traversal to collect the
2029 -- writable actuals of functions and all the identifiers which are
2030 -- not writable actuals of functions.
2032 function Contains (List : Elist_Id; N : Node_Id) return Boolean;
2033 -- Returns True if List has a node whose Entity is Entity (N)
2039 function Check_Node (N : Node_Id) return Traverse_Result is
2040 Is_Writable_Actual : Boolean := False;
2044 if Nkind (N) = N_Identifier then
2046 -- No analysis possible if the entity is not decorated
2048 if No (Entity (N)) then
2051 -- Don't collect identifiers of packages, called functions, etc
2053 elsif Ekind_In (Entity (N), E_Package,
2060 -- For rewritten nodes, continue the traversal in the original
2061 -- subtree. Needed to handle aggregates in original expressions
2062 -- extracted from the tree by Remove_Side_Effects.
2064 elsif Is_Rewrite_Substitution (N) then
2065 Collect_Identifiers (Original_Node (N));
2068 -- For now we skip aggregate discriminants, since they require
2069 -- performing the analysis in two phases to identify conflicts:
2070 -- first one analyzing discriminants and second one analyzing
2071 -- the rest of components (since at run time, discriminants are
2072 -- evaluated prior to components): too much computation cost
2073 -- to identify a corner case???
2075 elsif Nkind (Parent (N)) = N_Component_Association
2076 and then Nkind_In (Parent (Parent (N)),
2078 N_Extension_Aggregate)
2081 Choice : constant Node_Id := First (Choices (Parent (N)));
2084 if Ekind (Entity (N)) = E_Discriminant then
2087 elsif Expression (Parent (N)) = N
2088 and then Nkind (Choice) = N_Identifier
2089 and then Ekind (Entity (Choice)) = E_Discriminant
2095 -- Analyze if N is a writable actual of a function
2097 elsif Nkind (Parent (N)) = N_Function_Call then
2099 Call : constant Node_Id := Parent (N);
2104 Id := Get_Function_Id (Call);
2106 -- In case of previous error, no check is possible
2112 if Ekind_In (Id, E_Function, E_Generic_Function)
2113 and then Has_Out_Or_In_Out_Parameter (Id)
2115 Formal := First_Formal (Id);
2116 Actual := First_Actual (Call);
2117 while Present (Actual) and then Present (Formal) loop
2119 if Ekind_In (Formal, E_Out_Parameter,
2122 Is_Writable_Actual := True;
2128 Next_Formal (Formal);
2129 Next_Actual (Actual);
2135 if Is_Writable_Actual then
2137 -- Skip checking the error in non-elementary types since
2138 -- RM 6.4.1(6.15/3) is restricted to elementary types, but
2139 -- store this actual in Writable_Actuals_List since it is
2140 -- needed to perform checks on other constructs that have
2141 -- arbitrary order of evaluation (for example, aggregates).
2143 if not Is_Elementary_Type (Etype (N)) then
2144 if not Contains (Writable_Actuals_List, N) then
2145 Append_New_Elmt (N, To => Writable_Actuals_List);
2148 -- Second occurrence of an elementary type writable actual
2150 elsif Contains (Writable_Actuals_List, N) then
2152 -- Report the error on the second occurrence of the
2153 -- identifier. We cannot assume that N is the second
2154 -- occurrence (according to their location in the
2155 -- sources), since Traverse_Func walks through Field2
2156 -- last (see comment in the body of Traverse_Func).
2162 Elmt := First_Elmt (Writable_Actuals_List);
2163 while Present (Elmt)
2164 and then Entity (Node (Elmt)) /= Entity (N)
2169 if Sloc (N) > Sloc (Node (Elmt)) then
2172 Error_Node := Node (Elmt);
2176 ("value may be affected by call to & "
2177 & "because order of evaluation is arbitrary",
2182 -- First occurrence of a elementary type writable actual
2185 Append_New_Elmt (N, To => Writable_Actuals_List);
2189 if Identifiers_List = No_Elist then
2190 Identifiers_List := New_Elmt_List;
2193 Append_Unique_Elmt (N, Identifiers_List);
2206 N : Node_Id) return Boolean
2208 pragma Assert (Nkind (N) in N_Has_Entity);
2213 if List = No_Elist then
2217 Elmt := First_Elmt (List);
2218 while Present (Elmt) loop
2219 if Entity (Node (Elmt)) = Entity (N) then
2233 procedure Do_Traversal is new Traverse_Proc (Check_Node);
2234 -- The traversal procedure
2236 -- Start of processing for Collect_Identifiers
2239 if Present (Error_Node) then
2243 if Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
2248 end Collect_Identifiers;
2250 ---------------------
2251 -- Get_Function_Id --
2252 ---------------------
2254 function Get_Function_Id (Call : Node_Id) return Entity_Id is
2255 Nam : constant Node_Id := Name (Call);
2259 if Nkind (Nam) = N_Explicit_Dereference then
2261 pragma Assert (Ekind (Id) = E_Subprogram_Type);
2263 elsif Nkind (Nam) = N_Selected_Component then
2264 Id := Entity (Selector_Name (Nam));
2266 elsif Nkind (Nam) = N_Indexed_Component then
2267 Id := Entity (Selector_Name (Prefix (Nam)));
2274 end Get_Function_Id;
2276 -------------------------------
2277 -- Preanalyze_Without_Errors --
2278 -------------------------------
2280 procedure Preanalyze_Without_Errors (N : Node_Id) is
2281 Status : constant Boolean := Get_Ignore_Errors;
2283 Set_Ignore_Errors (True);
2285 Set_Ignore_Errors (Status);
2286 end Preanalyze_Without_Errors;
2288 -- Start of processing for Check_Function_Writable_Actuals
2291 -- The check only applies to Ada 2012 code on which Check_Actuals has
2292 -- been set, and only to constructs that have multiple constituents
2293 -- whose order of evaluation is not specified by the language.
2295 if Ada_Version < Ada_2012
2296 or else not Check_Actuals (N)
2297 or else (not (Nkind (N) in N_Op)
2298 and then not (Nkind (N) in N_Membership_Test)
2299 and then not Nkind_In (N, N_Range,
2301 N_Extension_Aggregate,
2302 N_Full_Type_Declaration,
2304 N_Procedure_Call_Statement,
2305 N_Entry_Call_Statement))
2306 or else (Nkind (N) = N_Full_Type_Declaration
2307 and then not Is_Record_Type (Defining_Identifier (N)))
2309 -- In addition, this check only applies to source code, not to code
2310 -- generated by constraint checks.
2312 or else not Comes_From_Source (N)
2317 -- If a construct C has two or more direct constituents that are names
2318 -- or expressions whose evaluation may occur in an arbitrary order, at
2319 -- least one of which contains a function call with an in out or out
2320 -- parameter, then the construct is legal only if: for each name N that
2321 -- is passed as a parameter of mode in out or out to some inner function
2322 -- call C2 (not including the construct C itself), there is no other
2323 -- name anywhere within a direct constituent of the construct C other
2324 -- than the one containing C2, that is known to refer to the same
2325 -- object (RM 6.4.1(6.17/3)).
2329 Collect_Identifiers (Low_Bound (N));
2330 Collect_Identifiers (High_Bound (N));
2332 when N_Membership_Test
2339 Collect_Identifiers (Left_Opnd (N));
2341 if Present (Right_Opnd (N)) then
2342 Collect_Identifiers (Right_Opnd (N));
2345 if Nkind_In (N, N_In, N_Not_In)
2346 and then Present (Alternatives (N))
2348 Expr := First (Alternatives (N));
2349 while Present (Expr) loop
2350 Collect_Identifiers (Expr);
2357 when N_Full_Type_Declaration =>
2359 function Get_Record_Part (N : Node_Id) return Node_Id;
2360 -- Return the record part of this record type definition
2362 function Get_Record_Part (N : Node_Id) return Node_Id is
2363 Type_Def : constant Node_Id := Type_Definition (N);
2365 if Nkind (Type_Def) = N_Derived_Type_Definition then
2366 return Record_Extension_Part (Type_Def);
2370 end Get_Record_Part;
2373 Def_Id : Entity_Id := Defining_Identifier (N);
2374 Rec : Node_Id := Get_Record_Part (N);
2377 -- No need to perform any analysis if the record has no
2380 if No (Rec) or else No (Component_List (Rec)) then
2384 -- Collect the identifiers starting from the deepest
2385 -- derivation. Done to report the error in the deepest
2389 if Present (Component_List (Rec)) then
2390 Comp := First (Component_Items (Component_List (Rec)));
2391 while Present (Comp) loop
2392 if Nkind (Comp) = N_Component_Declaration
2393 and then Present (Expression (Comp))
2395 Collect_Identifiers (Expression (Comp));
2402 exit when No (Underlying_Type (Etype (Def_Id)))
2403 or else Base_Type (Underlying_Type (Etype (Def_Id)))
2406 Def_Id := Base_Type (Underlying_Type (Etype (Def_Id)));
2407 Rec := Get_Record_Part (Parent (Def_Id));
2411 when N_Entry_Call_Statement
2415 Id : constant Entity_Id := Get_Function_Id (N);
2420 Formal := First_Formal (Id);
2421 Actual := First_Actual (N);
2422 while Present (Actual) and then Present (Formal) loop
2423 if Ekind_In (Formal, E_Out_Parameter,
2426 Collect_Identifiers (Actual);
2429 Next_Formal (Formal);
2430 Next_Actual (Actual);
2435 | N_Extension_Aggregate
2440 Comp_Expr : Node_Id;
2443 -- Handle the N_Others_Choice of array aggregates with static
2444 -- bounds. There is no need to perform this analysis in
2445 -- aggregates without static bounds since we cannot evaluate
2446 -- if the N_Others_Choice covers several elements. There is
2447 -- no need to handle the N_Others choice of record aggregates
2448 -- since at this stage it has been already expanded by
2449 -- Resolve_Record_Aggregate.
2451 if Is_Array_Type (Etype (N))
2452 and then Nkind (N) = N_Aggregate
2453 and then Present (Aggregate_Bounds (N))
2454 and then Compile_Time_Known_Bounds (Etype (N))
2455 and then Expr_Value (High_Bound (Aggregate_Bounds (N)))
2457 Expr_Value (Low_Bound (Aggregate_Bounds (N)))
2460 Count_Components : Uint := Uint_0;
2461 Num_Components : Uint;
2462 Others_Assoc : Node_Id;
2463 Others_Choice : Node_Id := Empty;
2464 Others_Box_Present : Boolean := False;
2467 -- Count positional associations
2469 if Present (Expressions (N)) then
2470 Comp_Expr := First (Expressions (N));
2471 while Present (Comp_Expr) loop
2472 Count_Components := Count_Components + 1;
2477 -- Count the rest of elements and locate the N_Others
2480 Assoc := First (Component_Associations (N));
2481 while Present (Assoc) loop
2482 Choice := First (Choices (Assoc));
2483 while Present (Choice) loop
2484 if Nkind (Choice) = N_Others_Choice then
2485 Others_Assoc := Assoc;
2486 Others_Choice := Choice;
2487 Others_Box_Present := Box_Present (Assoc);
2489 -- Count several components
2491 elsif Nkind_In (Choice, N_Range,
2492 N_Subtype_Indication)
2493 or else (Is_Entity_Name (Choice)
2494 and then Is_Type (Entity (Choice)))
2499 Get_Index_Bounds (Choice, L, H);
2501 (Compile_Time_Known_Value (L)
2502 and then Compile_Time_Known_Value (H));
2505 + Expr_Value (H) - Expr_Value (L) + 1;
2508 -- Count single component. No other case available
2509 -- since we are handling an aggregate with static
2513 pragma Assert (Is_OK_Static_Expression (Choice)
2514 or else Nkind (Choice) = N_Identifier
2515 or else Nkind (Choice) = N_Integer_Literal);
2517 Count_Components := Count_Components + 1;
2527 Expr_Value (High_Bound (Aggregate_Bounds (N))) -
2528 Expr_Value (Low_Bound (Aggregate_Bounds (N))) + 1;
2530 pragma Assert (Count_Components <= Num_Components);
2532 -- Handle the N_Others choice if it covers several
2535 if Present (Others_Choice)
2536 and then (Num_Components - Count_Components) > 1
2538 if not Others_Box_Present then
2540 -- At this stage, if expansion is active, the
2541 -- expression of the others choice has not been
2542 -- analyzed. Hence we generate a duplicate and
2543 -- we analyze it silently to have available the
2544 -- minimum decoration required to collect the
2547 if not Expander_Active then
2548 Comp_Expr := Expression (Others_Assoc);
2551 New_Copy_Tree (Expression (Others_Assoc));
2552 Preanalyze_Without_Errors (Comp_Expr);
2555 Collect_Identifiers (Comp_Expr);
2557 if Writable_Actuals_List /= No_Elist then
2559 -- As suggested by Robert, at current stage we
2560 -- report occurrences of this case as warnings.
2563 ("writable function parameter may affect "
2564 & "value in other component because order "
2565 & "of evaluation is unspecified??",
2566 Node (First_Elmt (Writable_Actuals_List)));
2572 -- For an array aggregate, a discrete_choice_list that has
2573 -- a nonstatic range is considered as two or more separate
2574 -- occurrences of the expression (RM 6.4.1(20/3)).
2576 elsif Is_Array_Type (Etype (N))
2577 and then Nkind (N) = N_Aggregate
2578 and then Present (Aggregate_Bounds (N))
2579 and then not Compile_Time_Known_Bounds (Etype (N))
2581 -- Collect identifiers found in the dynamic bounds
2584 Count_Components : Natural := 0;
2585 Low, High : Node_Id;
2588 Assoc := First (Component_Associations (N));
2589 while Present (Assoc) loop
2590 Choice := First (Choices (Assoc));
2591 while Present (Choice) loop
2592 if Nkind_In (Choice, N_Range,
2593 N_Subtype_Indication)
2594 or else (Is_Entity_Name (Choice)
2595 and then Is_Type (Entity (Choice)))
2597 Get_Index_Bounds (Choice, Low, High);
2599 if not Compile_Time_Known_Value (Low) then
2600 Collect_Identifiers (Low);
2602 if No (Aggr_Error_Node) then
2603 Aggr_Error_Node := Low;
2607 if not Compile_Time_Known_Value (High) then
2608 Collect_Identifiers (High);
2610 if No (Aggr_Error_Node) then
2611 Aggr_Error_Node := High;
2615 -- The RM rule is violated if there is more than
2616 -- a single choice in a component association.
2619 Count_Components := Count_Components + 1;
2621 if No (Aggr_Error_Node)
2622 and then Count_Components > 1
2624 Aggr_Error_Node := Choice;
2627 if not Compile_Time_Known_Value (Choice) then
2628 Collect_Identifiers (Choice);
2640 -- Handle ancestor part of extension aggregates
2642 if Nkind (N) = N_Extension_Aggregate then
2643 Collect_Identifiers (Ancestor_Part (N));
2646 -- Handle positional associations
2648 if Present (Expressions (N)) then
2649 Comp_Expr := First (Expressions (N));
2650 while Present (Comp_Expr) loop
2651 if not Is_OK_Static_Expression (Comp_Expr) then
2652 Collect_Identifiers (Comp_Expr);
2659 -- Handle discrete associations
2661 if Present (Component_Associations (N)) then
2662 Assoc := First (Component_Associations (N));
2663 while Present (Assoc) loop
2665 if not Box_Present (Assoc) then
2666 Choice := First (Choices (Assoc));
2667 while Present (Choice) loop
2669 -- For now we skip discriminants since it requires
2670 -- performing the analysis in two phases: first one
2671 -- analyzing discriminants and second one analyzing
2672 -- the rest of components since discriminants are
2673 -- evaluated prior to components: too much extra
2674 -- work to detect a corner case???
2676 if Nkind (Choice) in N_Has_Entity
2677 and then Present (Entity (Choice))
2678 and then Ekind (Entity (Choice)) = E_Discriminant
2682 elsif Box_Present (Assoc) then
2686 if not Analyzed (Expression (Assoc)) then
2688 New_Copy_Tree (Expression (Assoc));
2689 Set_Parent (Comp_Expr, Parent (N));
2690 Preanalyze_Without_Errors (Comp_Expr);
2692 Comp_Expr := Expression (Assoc);
2695 Collect_Identifiers (Comp_Expr);
2711 -- No further action needed if we already reported an error
2713 if Present (Error_Node) then
2717 -- Check violation of RM 6.20/3 in aggregates
2719 if Present (Aggr_Error_Node)
2720 and then Writable_Actuals_List /= No_Elist
2723 ("value may be affected by call in other component because they "
2724 & "are evaluated in unspecified order",
2725 Node (First_Elmt (Writable_Actuals_List)));
2729 -- Check if some writable argument of a function is referenced
2731 if Writable_Actuals_List /= No_Elist
2732 and then Identifiers_List /= No_Elist
2739 Elmt_1 := First_Elmt (Writable_Actuals_List);
2740 while Present (Elmt_1) loop
2741 Elmt_2 := First_Elmt (Identifiers_List);
2742 while Present (Elmt_2) loop
2743 if Entity (Node (Elmt_1)) = Entity (Node (Elmt_2)) then
2744 case Nkind (Parent (Node (Elmt_2))) is
2746 | N_Component_Association
2747 | N_Component_Declaration
2750 ("value may be affected by call in other "
2751 & "component because they are evaluated "
2752 & "in unspecified order",
2759 ("value may be affected by call in other "
2760 & "alternative because they are evaluated "
2761 & "in unspecified order",
2766 ("value of actual may be affected by call in "
2767 & "other actual because they are evaluated "
2768 & "in unspecified order",
2780 end Check_Function_Writable_Actuals;
2782 --------------------------------
2783 -- Check_Implicit_Dereference --
2784 --------------------------------
2786 procedure Check_Implicit_Dereference (N : Node_Id; Typ : Entity_Id) is
2792 if Nkind (N) = N_Indexed_Component
2793 and then Present (Generalized_Indexing (N))
2795 Nam := Generalized_Indexing (N);
2800 if Ada_Version < Ada_2012
2801 or else not Has_Implicit_Dereference (Base_Type (Typ))
2805 elsif not Comes_From_Source (N)
2806 and then Nkind (N) /= N_Indexed_Component
2810 elsif Is_Entity_Name (Nam) and then Is_Type (Entity (Nam)) then
2814 Disc := First_Discriminant (Typ);
2815 while Present (Disc) loop
2816 if Has_Implicit_Dereference (Disc) then
2817 Desig := Designated_Type (Etype (Disc));
2818 Add_One_Interp (Nam, Disc, Desig);
2820 -- If the node is a generalized indexing, add interpretation
2821 -- to that node as well, for subsequent resolution.
2823 if Nkind (N) = N_Indexed_Component then
2824 Add_One_Interp (N, Disc, Desig);
2827 -- If the operation comes from a generic unit and the context
2828 -- is a selected component, the selector name may be global
2829 -- and set in the instance already. Remove the entity to
2830 -- force resolution of the selected component, and the
2831 -- generation of an explicit dereference if needed.
2834 and then Nkind (Parent (Nam)) = N_Selected_Component
2836 Set_Entity (Selector_Name (Parent (Nam)), Empty);
2842 Next_Discriminant (Disc);
2845 end Check_Implicit_Dereference;
2847 ----------------------------------
2848 -- Check_Internal_Protected_Use --
2849 ----------------------------------
2851 procedure Check_Internal_Protected_Use (N : Node_Id; Nam : Entity_Id) is
2859 while Present (S) loop
2860 if S = Standard_Standard then
2863 elsif Ekind (S) = E_Function
2864 and then Ekind (Scope (S)) = E_Protected_Type
2874 and then Scope (Nam) = Prot
2875 and then Ekind (Nam) /= E_Function
2877 -- An indirect function call (e.g. a callback within a protected
2878 -- function body) is not statically illegal. If the access type is
2879 -- anonymous and is the type of an access parameter, the scope of Nam
2880 -- will be the protected type, but it is not a protected operation.
2882 if Ekind (Nam) = E_Subprogram_Type
2883 and then Nkind (Associated_Node_For_Itype (Nam)) =
2884 N_Function_Specification
2888 elsif Nkind (N) = N_Subprogram_Renaming_Declaration then
2890 ("within protected function cannot use protected procedure in "
2891 & "renaming or as generic actual", N);
2893 elsif Nkind (N) = N_Attribute_Reference then
2895 ("within protected function cannot take access of protected "
2900 ("within protected function, protected object is constant", N);
2902 ("\cannot call operation that may modify it", N);
2906 -- Verify that an internal call does not appear within a precondition
2907 -- of a protected operation. This implements AI12-0166.
2908 -- The precondition aspect has been rewritten as a pragma Precondition
2909 -- and we check whether the scope of the called subprogram is the same
2910 -- as that of the entity to which the aspect applies.
2912 if Convention (Nam) = Convention_Protected then
2918 while Present (P) loop
2919 if Nkind (P) = N_Pragma
2920 and then Chars (Pragma_Identifier (P)) = Name_Precondition
2921 and then From_Aspect_Specification (P)
2923 Scope (Entity (Corresponding_Aspect (P))) = Scope (Nam)
2926 ("internal call cannot appear in precondition of "
2927 & "protected operation", N);
2930 elsif Nkind (P) = N_Pragma
2931 and then Chars (Pragma_Identifier (P)) = Name_Contract_Cases
2933 -- Check whether call is in a case guard. It is legal in a
2937 while Present (P) loop
2938 if Nkind (Parent (P)) = N_Component_Association
2939 and then P /= Expression (Parent (P))
2942 ("internal call cannot appear in case guard in a "
2943 & "contract case", N);
2951 elsif Nkind (P) = N_Parameter_Specification
2952 and then Scope (Current_Scope) = Scope (Nam)
2953 and then Nkind_In (Parent (P), N_Entry_Declaration,
2954 N_Subprogram_Declaration)
2957 ("internal call cannot appear in default for formal of "
2958 & "protected operation", N);
2966 end Check_Internal_Protected_Use;
2968 ---------------------------------------
2969 -- Check_Later_Vs_Basic_Declarations --
2970 ---------------------------------------
2972 procedure Check_Later_Vs_Basic_Declarations
2974 During_Parsing : Boolean)
2976 Body_Sloc : Source_Ptr;
2979 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
2980 -- Return whether Decl is considered as a declarative item.
2981 -- When During_Parsing is True, the semantics of Ada 83 is followed.
2982 -- When During_Parsing is False, the semantics of SPARK is followed.
2984 -------------------------------
2985 -- Is_Later_Declarative_Item --
2986 -------------------------------
2988 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
2990 if Nkind (Decl) in N_Later_Decl_Item then
2993 elsif Nkind (Decl) = N_Pragma then
2996 elsif During_Parsing then
2999 -- In SPARK, a package declaration is not considered as a later
3000 -- declarative item.
3002 elsif Nkind (Decl) = N_Package_Declaration then
3005 -- In SPARK, a renaming is considered as a later declarative item
3007 elsif Nkind (Decl) in N_Renaming_Declaration then
3013 end Is_Later_Declarative_Item;
3015 -- Start of processing for Check_Later_Vs_Basic_Declarations
3018 Decl := First (Decls);
3020 -- Loop through sequence of basic declarative items
3022 Outer : while Present (Decl) loop
3023 if not Nkind_In (Decl, N_Subprogram_Body, N_Package_Body, N_Task_Body)
3024 and then Nkind (Decl) not in N_Body_Stub
3028 -- Once a body is encountered, we only allow later declarative
3029 -- items. The inner loop checks the rest of the list.
3032 Body_Sloc := Sloc (Decl);
3034 Inner : while Present (Decl) loop
3035 if not Is_Later_Declarative_Item (Decl) then
3036 if During_Parsing then
3037 if Ada_Version = Ada_83 then
3038 Error_Msg_Sloc := Body_Sloc;
3040 ("(Ada 83) decl cannot appear after body#", Decl);
3043 Error_Msg_Sloc := Body_Sloc;
3044 Check_SPARK_05_Restriction
3045 ("decl cannot appear after body#", Decl);
3053 end Check_Later_Vs_Basic_Declarations;
3055 ---------------------------
3056 -- Check_No_Hidden_State --
3057 ---------------------------
3059 procedure Check_No_Hidden_State (Id : Entity_Id) is
3060 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean;
3061 -- Determine whether the entity of a package denoted by Pkg has a null
3064 -----------------------------
3065 -- Has_Null_Abstract_State --
3066 -----------------------------
3068 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean is
3069 States : constant Elist_Id := Abstract_States (Pkg);
3072 -- Check first available state of related package. A null abstract
3073 -- state always appears as the sole element of the state list.
3077 and then Is_Null_State (Node (First_Elmt (States)));
3078 end Has_Null_Abstract_State;
3082 Context : Entity_Id := Empty;
3083 Not_Visible : Boolean := False;
3086 -- Start of processing for Check_No_Hidden_State
3089 pragma Assert (Ekind_In (Id, E_Abstract_State, E_Variable));
3091 -- Find the proper context where the object or state appears
3094 while Present (Scop) loop
3097 -- Keep track of the context's visibility
3099 Not_Visible := Not_Visible or else In_Private_Part (Context);
3101 -- Prevent the search from going too far
3103 if Context = Standard_Standard then
3106 -- Objects and states that appear immediately within a subprogram or
3107 -- inside a construct nested within a subprogram do not introduce a
3108 -- hidden state. They behave as local variable declarations.
3110 elsif Is_Subprogram (Context) then
3113 -- When examining a package body, use the entity of the spec as it
3114 -- carries the abstract state declarations.
3116 elsif Ekind (Context) = E_Package_Body then
3117 Context := Spec_Entity (Context);
3120 -- Stop the traversal when a package subject to a null abstract state
3123 if Ekind_In (Context, E_Generic_Package, E_Package)
3124 and then Has_Null_Abstract_State (Context)
3129 Scop := Scope (Scop);
3132 -- At this point we know that there is at least one package with a null
3133 -- abstract state in visibility. Emit an error message unconditionally
3134 -- if the entity being processed is a state because the placement of the
3135 -- related package is irrelevant. This is not the case for objects as
3136 -- the intermediate context matters.
3138 if Present (Context)
3139 and then (Ekind (Id) = E_Abstract_State or else Not_Visible)
3141 Error_Msg_N ("cannot introduce hidden state &", Id);
3142 Error_Msg_NE ("\package & has null abstract state", Id, Context);
3144 end Check_No_Hidden_State;
3146 ----------------------------------------
3147 -- Check_Nonvolatile_Function_Profile --
3148 ----------------------------------------
3150 procedure Check_Nonvolatile_Function_Profile (Func_Id : Entity_Id) is
3154 -- Inspect all formal parameters
3156 Formal := First_Formal (Func_Id);
3157 while Present (Formal) loop
3158 if Is_Effectively_Volatile (Etype (Formal)) then
3160 ("nonvolatile function & cannot have a volatile parameter",
3164 Next_Formal (Formal);
3167 -- Inspect the return type
3169 if Is_Effectively_Volatile (Etype (Func_Id)) then
3171 ("nonvolatile function & cannot have a volatile return type",
3172 Result_Definition (Parent (Func_Id)), Func_Id);
3174 end Check_Nonvolatile_Function_Profile;
3176 ------------------------------------------
3177 -- Check_Potentially_Blocking_Operation --
3178 ------------------------------------------
3180 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
3184 -- N is one of the potentially blocking operations listed in 9.5.1(8).
3185 -- When pragma Detect_Blocking is active, the run time will raise
3186 -- Program_Error. Here we only issue a warning, since we generally
3187 -- support the use of potentially blocking operations in the absence
3190 -- Indirect blocking through a subprogram call cannot be diagnosed
3191 -- statically without interprocedural analysis, so we do not attempt
3194 S := Scope (Current_Scope);
3195 while Present (S) and then S /= Standard_Standard loop
3196 if Is_Protected_Type (S) then
3198 ("potentially blocking operation in protected operation??", N);
3204 end Check_Potentially_Blocking_Operation;
3206 ---------------------------------
3207 -- Check_Result_And_Post_State --
3208 ---------------------------------
3210 procedure Check_Result_And_Post_State (Subp_Id : Entity_Id) is
3211 procedure Check_Result_And_Post_State_In_Pragma
3213 Result_Seen : in out Boolean);
3214 -- Determine whether pragma Prag mentions attribute 'Result and whether
3215 -- the pragma contains an expression that evaluates differently in pre-
3216 -- and post-state. Prag is a [refined] postcondition or a contract-cases
3217 -- pragma. Result_Seen is set when the pragma mentions attribute 'Result
3219 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean;
3220 -- Determine whether subprogram Subp_Id contains at least one IN OUT
3221 -- formal parameter.
3223 -------------------------------------------
3224 -- Check_Result_And_Post_State_In_Pragma --
3225 -------------------------------------------
3227 procedure Check_Result_And_Post_State_In_Pragma
3229 Result_Seen : in out Boolean)
3231 procedure Check_Conjunct (Expr : Node_Id);
3232 -- Check an individual conjunct in a conjunction of Boolean
3233 -- expressions, connected by "and" or "and then" operators.
3235 procedure Check_Conjuncts (Expr : Node_Id);
3236 -- Apply the post-state check to every conjunct in an expression, in
3237 -- case this is a conjunction of Boolean expressions. Otherwise apply
3238 -- it to the expression as a whole.
3240 procedure Check_Expression (Expr : Node_Id);
3241 -- Perform the 'Result and post-state checks on a given expression
3243 function Is_Function_Result (N : Node_Id) return Traverse_Result;
3244 -- Attempt to find attribute 'Result in a subtree denoted by N
3246 function Is_Trivial_Boolean (N : Node_Id) return Boolean;
3247 -- Determine whether source node N denotes "True" or "False"
3249 function Mentions_Post_State (N : Node_Id) return Boolean;
3250 -- Determine whether a subtree denoted by N mentions any construct
3251 -- that denotes a post-state.
3253 procedure Check_Function_Result is
3254 new Traverse_Proc (Is_Function_Result);
3256 --------------------
3257 -- Check_Conjunct --
3258 --------------------
3260 procedure Check_Conjunct (Expr : Node_Id) is
3261 function Adjust_Message (Msg : String) return String;
3262 -- Prepend a prefix to the input message Msg denoting that the
3263 -- message applies to a conjunct in the expression, when this
3266 function Applied_On_Conjunct return Boolean;
3267 -- Returns True if the message applies to a conjunct in the
3268 -- expression, instead of the whole expression.
3270 --------------------
3271 -- Adjust_Message --
3272 --------------------
3274 function Adjust_Message (Msg : String) return String is
3276 if Applied_On_Conjunct then
3277 return "conjunct in " & Msg;
3283 -------------------------
3284 -- Applied_On_Conjunct --
3285 -------------------------
3287 function Applied_On_Conjunct return Boolean is
3289 -- Expr is the conjunct of an enclosing "and" expression
3291 return Nkind (Parent (Expr)) in N_Subexpr
3293 -- or Expr is a conjunct of an enclosing "and then"
3294 -- expression in a postcondition aspect that was split into
3295 -- multiple pragmas. The first conjunct has the "and then"
3296 -- expression as Original_Node, and other conjuncts have
3297 -- Split_PCC set to True.
3299 or else Nkind (Original_Node (Expr)) = N_And_Then
3300 or else Split_PPC (Prag);
3301 end Applied_On_Conjunct;
3306 -- Error node when reporting a warning on a (refined)
3309 -- Start of processing for Check_Conjunct
3312 if Applied_On_Conjunct then
3318 if not Is_Trivial_Boolean (Expr)
3319 and then not Mentions_Post_State (Expr)
3321 if Pragma_Name (Prag) = Name_Contract_Cases then
3322 Error_Msg_NE (Adjust_Message
3323 ("contract case does not check the outcome of calling "
3324 & "&?T?"), Expr, Subp_Id);
3326 elsif Pragma_Name (Prag) = Name_Refined_Post then
3327 Error_Msg_NE (Adjust_Message
3328 ("refined postcondition does not check the outcome of "
3329 & "calling &?T?"), Err_Node, Subp_Id);
3332 Error_Msg_NE (Adjust_Message
3333 ("postcondition does not check the outcome of calling "
3334 & "&?T?"), Err_Node, Subp_Id);
3339 ---------------------
3340 -- Check_Conjuncts --
3341 ---------------------
3343 procedure Check_Conjuncts (Expr : Node_Id) is
3345 if Nkind_In (Expr, N_Op_And, N_And_Then) then
3346 Check_Conjuncts (Left_Opnd (Expr));
3347 Check_Conjuncts (Right_Opnd (Expr));
3349 Check_Conjunct (Expr);
3351 end Check_Conjuncts;
3353 ----------------------
3354 -- Check_Expression --
3355 ----------------------
3357 procedure Check_Expression (Expr : Node_Id) is
3359 if not Is_Trivial_Boolean (Expr) then
3360 Check_Function_Result (Expr);
3361 Check_Conjuncts (Expr);
3363 end Check_Expression;
3365 ------------------------
3366 -- Is_Function_Result --
3367 ------------------------
3369 function Is_Function_Result (N : Node_Id) return Traverse_Result is
3371 if Is_Attribute_Result (N) then
3372 Result_Seen := True;
3375 -- Continue the traversal
3380 end Is_Function_Result;
3382 ------------------------
3383 -- Is_Trivial_Boolean --
3384 ------------------------
3386 function Is_Trivial_Boolean (N : Node_Id) return Boolean is
3389 Comes_From_Source (N)
3390 and then Is_Entity_Name (N)
3391 and then (Entity (N) = Standard_True
3393 Entity (N) = Standard_False);
3394 end Is_Trivial_Boolean;
3396 -------------------------
3397 -- Mentions_Post_State --
3398 -------------------------
3400 function Mentions_Post_State (N : Node_Id) return Boolean is
3401 Post_State_Seen : Boolean := False;
3403 function Is_Post_State (N : Node_Id) return Traverse_Result;
3404 -- Attempt to find a construct that denotes a post-state. If this
3405 -- is the case, set flag Post_State_Seen.
3411 function Is_Post_State (N : Node_Id) return Traverse_Result is
3415 if Nkind_In (N, N_Explicit_Dereference, N_Function_Call) then
3416 Post_State_Seen := True;
3419 elsif Nkind_In (N, N_Expanded_Name, N_Identifier) then
3422 -- Treat an undecorated reference as OK
3426 -- A reference to an assignable entity is considered a
3427 -- change in the post-state of a subprogram.
3429 or else Ekind_In (Ent, E_Generic_In_Out_Parameter,
3434 -- The reference may be modified through a dereference
3436 or else (Is_Access_Type (Etype (Ent))
3437 and then Nkind (Parent (N)) =
3438 N_Selected_Component)
3440 Post_State_Seen := True;
3444 elsif Nkind (N) = N_Attribute_Reference then
3445 if Attribute_Name (N) = Name_Old then
3448 elsif Attribute_Name (N) = Name_Result then
3449 Post_State_Seen := True;
3457 procedure Find_Post_State is new Traverse_Proc (Is_Post_State);
3459 -- Start of processing for Mentions_Post_State
3462 Find_Post_State (N);
3464 return Post_State_Seen;
3465 end Mentions_Post_State;
3469 Expr : constant Node_Id :=
3471 (First (Pragma_Argument_Associations (Prag)));
3472 Nam : constant Name_Id := Pragma_Name (Prag);
3475 -- Start of processing for Check_Result_And_Post_State_In_Pragma
3478 -- Examine all consequences
3480 if Nam = Name_Contract_Cases then
3481 CCase := First (Component_Associations (Expr));
3482 while Present (CCase) loop
3483 Check_Expression (Expression (CCase));
3488 -- Examine the expression of a postcondition
3490 else pragma Assert (Nam_In (Nam, Name_Postcondition,
3491 Name_Refined_Post));
3492 Check_Expression (Expr);
3494 end Check_Result_And_Post_State_In_Pragma;
3496 --------------------------
3497 -- Has_In_Out_Parameter --
3498 --------------------------
3500 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean is
3504 -- Traverse the formals looking for an IN OUT parameter
3506 Formal := First_Formal (Subp_Id);
3507 while Present (Formal) loop
3508 if Ekind (Formal) = E_In_Out_Parameter then
3512 Next_Formal (Formal);
3516 end Has_In_Out_Parameter;
3520 Items : constant Node_Id := Contract (Subp_Id);
3521 Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id);
3522 Case_Prag : Node_Id := Empty;
3523 Post_Prag : Node_Id := Empty;
3525 Seen_In_Case : Boolean := False;
3526 Seen_In_Post : Boolean := False;
3527 Spec_Id : Entity_Id;
3529 -- Start of processing for Check_Result_And_Post_State
3532 -- The lack of attribute 'Result or a post-state is classified as a
3533 -- suspicious contract. Do not perform the check if the corresponding
3534 -- swich is not set.
3536 if not Warn_On_Suspicious_Contract then
3539 -- Nothing to do if there is no contract
3541 elsif No (Items) then
3545 -- Retrieve the entity of the subprogram spec (if any)
3547 if Nkind (Subp_Decl) = N_Subprogram_Body
3548 and then Present (Corresponding_Spec (Subp_Decl))
3550 Spec_Id := Corresponding_Spec (Subp_Decl);
3552 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
3553 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
3555 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
3561 -- Examine all postconditions for attribute 'Result and a post-state
3563 Prag := Pre_Post_Conditions (Items);
3564 while Present (Prag) loop
3565 if Nam_In (Pragma_Name_Unmapped (Prag),
3566 Name_Postcondition, Name_Refined_Post)
3567 and then not Error_Posted (Prag)
3570 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Post);
3573 Prag := Next_Pragma (Prag);
3576 -- Examine the contract cases of the subprogram for attribute 'Result
3577 -- and a post-state.
3579 Prag := Contract_Test_Cases (Items);
3580 while Present (Prag) loop
3581 if Pragma_Name (Prag) = Name_Contract_Cases
3582 and then not Error_Posted (Prag)
3585 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Case);
3588 Prag := Next_Pragma (Prag);
3591 -- Do not emit any errors if the subprogram is not a function
3593 if not Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
3596 -- Regardless of whether the function has postconditions or contract
3597 -- cases, or whether they mention attribute 'Result, an IN OUT formal
3598 -- parameter is always treated as a result.
3600 elsif Has_In_Out_Parameter (Spec_Id) then
3603 -- The function has both a postcondition and contract cases and they do
3604 -- not mention attribute 'Result.
3606 elsif Present (Case_Prag)
3607 and then not Seen_In_Case
3608 and then Present (Post_Prag)
3609 and then not Seen_In_Post
3612 ("neither postcondition nor contract cases mention function "
3613 & "result?T?", Post_Prag);
3615 -- The function has contract cases only and they do not mention
3616 -- attribute 'Result.
3618 elsif Present (Case_Prag) and then not Seen_In_Case then
3619 Error_Msg_N ("contract cases do not mention result?T?", Case_Prag);
3621 -- The function has postconditions only and they do not mention
3622 -- attribute 'Result.
3624 elsif Present (Post_Prag) and then not Seen_In_Post then
3626 ("postcondition does not mention function result?T?", Post_Prag);
3628 end Check_Result_And_Post_State;
3630 -----------------------------
3631 -- Check_State_Refinements --
3632 -----------------------------
3634 procedure Check_State_Refinements
3636 Is_Main_Unit : Boolean := False)
3638 procedure Check_Package (Pack : Node_Id);
3639 -- Verify that all abstract states of a [generic] package denoted by its
3640 -- declarative node Pack have proper refinement. Recursively verify the
3641 -- visible and private declarations of the [generic] package for other
3644 procedure Check_Packages_In (Decls : List_Id);
3645 -- Seek out [generic] package declarations within declarative list Decls
3646 -- and verify the status of their abstract state refinement.
3648 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean;
3649 -- Determine whether construct N is subject to pragma SPARK_Mode Off
3655 procedure Check_Package (Pack : Node_Id) is
3656 Body_Id : constant Entity_Id := Corresponding_Body (Pack);
3657 Spec : constant Node_Id := Specification (Pack);
3658 States : constant Elist_Id :=
3659 Abstract_States (Defining_Entity (Pack));
3661 State_Elmt : Elmt_Id;
3662 State_Id : Entity_Id;
3665 -- Do not verify proper state refinement when the package is subject
3666 -- to pragma SPARK_Mode Off because this disables the requirement for
3667 -- state refinement.
3669 if SPARK_Mode_Is_Off (Pack) then
3672 -- State refinement can only occur in a completing packge body. Do
3673 -- not verify proper state refinement when the body is subject to
3674 -- pragma SPARK_Mode Off because this disables the requirement for
3675 -- state refinement.
3677 elsif Present (Body_Id)
3678 and then SPARK_Mode_Is_Off (Unit_Declaration_Node (Body_Id))
3682 -- Do not verify proper state refinement when the package is an
3683 -- instance as this check was already performed in the generic.
3685 elsif Present (Generic_Parent (Spec)) then
3688 -- Otherwise examine the contents of the package
3691 if Present (States) then
3692 State_Elmt := First_Elmt (States);
3693 while Present (State_Elmt) loop
3694 State_Id := Node (State_Elmt);
3696 -- Emit an error when a non-null state lacks any form of
3699 if not Is_Null_State (State_Id)
3700 and then not Has_Null_Refinement (State_Id)
3701 and then not Has_Non_Null_Refinement (State_Id)
3703 Error_Msg_N ("state & requires refinement", State_Id);
3706 Next_Elmt (State_Elmt);
3710 Check_Packages_In (Visible_Declarations (Spec));
3711 Check_Packages_In (Private_Declarations (Spec));
3715 -----------------------
3716 -- Check_Packages_In --
3717 -----------------------
3719 procedure Check_Packages_In (Decls : List_Id) is
3723 if Present (Decls) then
3724 Decl := First (Decls);
3725 while Present (Decl) loop
3726 if Nkind_In (Decl, N_Generic_Package_Declaration,
3727 N_Package_Declaration)
3729 Check_Package (Decl);
3735 end Check_Packages_In;
3737 -----------------------
3738 -- SPARK_Mode_Is_Off --
3739 -----------------------
3741 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean is
3742 Id : constant Entity_Id := Defining_Entity (N);
3743 Prag : constant Node_Id := SPARK_Pragma (Id);
3746 -- Default the mode to "off" when the context is an instance and all
3747 -- SPARK_Mode pragmas found within are to be ignored.
3749 if Ignore_SPARK_Mode_Pragmas (Id) then
3755 and then Get_SPARK_Mode_From_Annotation (Prag) = Off;
3757 end SPARK_Mode_Is_Off;
3759 -- Start of processing for Check_State_Refinements
3762 -- A block may declare a nested package
3764 if Nkind (Context) = N_Block_Statement then
3765 Check_Packages_In (Declarations (Context));
3767 -- An entry, protected, subprogram, or task body may declare a nested
3770 elsif Nkind_In (Context, N_Entry_Body,
3775 -- Do not verify proper state refinement when the body is subject to
3776 -- pragma SPARK_Mode Off because this disables the requirement for
3777 -- state refinement.
3779 if not SPARK_Mode_Is_Off (Context) then
3780 Check_Packages_In (Declarations (Context));
3783 -- A package body may declare a nested package
3785 elsif Nkind (Context) = N_Package_Body then
3786 Check_Package (Unit_Declaration_Node (Corresponding_Spec (Context)));
3788 -- Do not verify proper state refinement when the body is subject to
3789 -- pragma SPARK_Mode Off because this disables the requirement for
3790 -- state refinement.
3792 if not SPARK_Mode_Is_Off (Context) then
3793 Check_Packages_In (Declarations (Context));
3796 -- A library level [generic] package may declare a nested package
3798 elsif Nkind_In (Context, N_Generic_Package_Declaration,
3799 N_Package_Declaration)
3800 and then Is_Main_Unit
3802 Check_Package (Context);
3804 end Check_State_Refinements;
3806 ------------------------------
3807 -- Check_Unprotected_Access --
3808 ------------------------------
3810 procedure Check_Unprotected_Access
3814 Cont_Encl_Typ : Entity_Id;
3815 Pref_Encl_Typ : Entity_Id;
3817 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
3818 -- Check whether Obj is a private component of a protected object.
3819 -- Return the protected type where the component resides, Empty
3822 function Is_Public_Operation return Boolean;
3823 -- Verify that the enclosing operation is callable from outside the
3824 -- protected object, to minimize false positives.
3826 ------------------------------
3827 -- Enclosing_Protected_Type --
3828 ------------------------------
3830 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
3832 if Is_Entity_Name (Obj) then
3834 Ent : Entity_Id := Entity (Obj);
3837 -- The object can be a renaming of a private component, use
3838 -- the original record component.
3840 if Is_Prival (Ent) then
3841 Ent := Prival_Link (Ent);
3844 if Is_Protected_Type (Scope (Ent)) then
3850 -- For indexed and selected components, recursively check the prefix
3852 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
3853 return Enclosing_Protected_Type (Prefix (Obj));
3855 -- The object does not denote a protected component
3860 end Enclosing_Protected_Type;
3862 -------------------------
3863 -- Is_Public_Operation --
3864 -------------------------
3866 function Is_Public_Operation return Boolean is
3872 while Present (S) and then S /= Pref_Encl_Typ loop
3873 if Scope (S) = Pref_Encl_Typ then
3874 E := First_Entity (Pref_Encl_Typ);
3876 and then E /= First_Private_Entity (Pref_Encl_Typ)
3890 end Is_Public_Operation;
3892 -- Start of processing for Check_Unprotected_Access
3895 if Nkind (Expr) = N_Attribute_Reference
3896 and then Attribute_Name (Expr) = Name_Unchecked_Access
3898 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
3899 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
3901 -- Check whether we are trying to export a protected component to a
3902 -- context with an equal or lower access level.
3904 if Present (Pref_Encl_Typ)
3905 and then No (Cont_Encl_Typ)
3906 and then Is_Public_Operation
3907 and then Scope_Depth (Pref_Encl_Typ) >=
3908 Object_Access_Level (Context)
3911 ("??possible unprotected access to protected data", Expr);
3914 end Check_Unprotected_Access;
3916 ------------------------------
3917 -- Check_Unused_Body_States --
3918 ------------------------------
3920 procedure Check_Unused_Body_States (Body_Id : Entity_Id) is
3921 procedure Process_Refinement_Clause
3924 -- Inspect all constituents of refinement clause Clause and remove any
3925 -- matches from body state list States.
3927 procedure Report_Unused_Body_States (States : Elist_Id);
3928 -- Emit errors for each abstract state or object found in list States
3930 -------------------------------
3931 -- Process_Refinement_Clause --
3932 -------------------------------
3934 procedure Process_Refinement_Clause
3938 procedure Process_Constituent (Constit : Node_Id);
3939 -- Remove constituent Constit from body state list States
3941 -------------------------
3942 -- Process_Constituent --
3943 -------------------------
3945 procedure Process_Constituent (Constit : Node_Id) is
3946 Constit_Id : Entity_Id;
3949 -- Guard against illegal constituents. Only abstract states and
3950 -- objects can appear on the right hand side of a refinement.
3952 if Is_Entity_Name (Constit) then
3953 Constit_Id := Entity_Of (Constit);
3955 if Present (Constit_Id)
3956 and then Ekind_In (Constit_Id, E_Abstract_State,
3960 Remove (States, Constit_Id);
3963 end Process_Constituent;
3969 -- Start of processing for Process_Refinement_Clause
3972 if Nkind (Clause) = N_Component_Association then
3973 Constit := Expression (Clause);
3975 -- Multiple constituents appear as an aggregate
3977 if Nkind (Constit) = N_Aggregate then
3978 Constit := First (Expressions (Constit));
3979 while Present (Constit) loop
3980 Process_Constituent (Constit);
3984 -- Various forms of a single constituent
3987 Process_Constituent (Constit);
3990 end Process_Refinement_Clause;
3992 -------------------------------
3993 -- Report_Unused_Body_States --
3994 -------------------------------
3996 procedure Report_Unused_Body_States (States : Elist_Id) is
3997 Posted : Boolean := False;
3998 State_Elmt : Elmt_Id;
3999 State_Id : Entity_Id;
4002 if Present (States) then
4003 State_Elmt := First_Elmt (States);
4004 while Present (State_Elmt) loop
4005 State_Id := Node (State_Elmt);
4007 -- Constants are part of the hidden state of a package, but the
4008 -- compiler cannot determine whether they have variable input
4009 -- (SPARK RM 7.1.1(2)) and cannot classify them properly as a
4010 -- hidden state. Do not emit an error when a constant does not
4011 -- participate in a state refinement, even though it acts as a
4014 if Ekind (State_Id) = E_Constant then
4017 -- Generate an error message of the form:
4019 -- body of package ... has unused hidden states
4020 -- abstract state ... defined at ...
4021 -- variable ... defined at ...
4027 ("body of package & has unused hidden states", Body_Id);
4030 Error_Msg_Sloc := Sloc (State_Id);
4032 if Ekind (State_Id) = E_Abstract_State then
4034 ("\abstract state & defined #", Body_Id, State_Id);
4037 SPARK_Msg_NE ("\variable & defined #", Body_Id, State_Id);
4041 Next_Elmt (State_Elmt);
4044 end Report_Unused_Body_States;
4048 Prag : constant Node_Id := Get_Pragma (Body_Id, Pragma_Refined_State);
4049 Spec_Id : constant Entity_Id := Spec_Entity (Body_Id);
4053 -- Start of processing for Check_Unused_Body_States
4056 -- Inspect the clauses of pragma Refined_State and determine whether all
4057 -- visible states declared within the package body participate in the
4060 if Present (Prag) then
4061 Clause := Expression (Get_Argument (Prag, Spec_Id));
4062 States := Collect_Body_States (Body_Id);
4064 -- Multiple non-null state refinements appear as an aggregate
4066 if Nkind (Clause) = N_Aggregate then
4067 Clause := First (Component_Associations (Clause));
4068 while Present (Clause) loop
4069 Process_Refinement_Clause (Clause, States);
4073 -- Various forms of a single state refinement
4076 Process_Refinement_Clause (Clause, States);
4079 -- Ensure that all abstract states and objects declared in the
4080 -- package body state space are utilized as constituents.
4082 Report_Unused_Body_States (States);
4084 end Check_Unused_Body_States;
4090 function Choice_List (N : Node_Id) return List_Id is
4092 if Nkind (N) = N_Iterated_Component_Association then
4093 return Discrete_Choices (N);
4099 -------------------------
4100 -- Collect_Body_States --
4101 -------------------------
4103 function Collect_Body_States (Body_Id : Entity_Id) return Elist_Id is
4104 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean;
4105 -- Determine whether object Obj_Id is a suitable visible state of a
4108 procedure Collect_Visible_States
4109 (Pack_Id : Entity_Id;
4110 States : in out Elist_Id);
4111 -- Gather the entities of all abstract states and objects declared in
4112 -- the visible state space of package Pack_Id.
4114 ----------------------------
4115 -- Collect_Visible_States --
4116 ----------------------------
4118 procedure Collect_Visible_States
4119 (Pack_Id : Entity_Id;
4120 States : in out Elist_Id)
4122 Item_Id : Entity_Id;
4125 -- Traverse the entity chain of the package and inspect all visible
4128 Item_Id := First_Entity (Pack_Id);
4129 while Present (Item_Id) and then not In_Private_Part (Item_Id) loop
4131 -- Do not consider internally generated items as those cannot be
4132 -- named and participate in refinement.
4134 if not Comes_From_Source (Item_Id) then
4137 elsif Ekind (Item_Id) = E_Abstract_State then
4138 Append_New_Elmt (Item_Id, States);
4140 elsif Ekind_In (Item_Id, E_Constant, E_Variable)
4141 and then Is_Visible_Object (Item_Id)
4143 Append_New_Elmt (Item_Id, States);
4145 -- Recursively gather the visible states of a nested package
4147 elsif Ekind (Item_Id) = E_Package then
4148 Collect_Visible_States (Item_Id, States);
4151 Next_Entity (Item_Id);
4153 end Collect_Visible_States;
4155 -----------------------
4156 -- Is_Visible_Object --
4157 -----------------------
4159 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean is
4161 -- Objects that map generic formals to their actuals are not visible
4162 -- from outside the generic instantiation.
4164 if Present (Corresponding_Generic_Association
4165 (Declaration_Node (Obj_Id)))
4169 -- Constituents of a single protected/task type act as components of
4170 -- the type and are not visible from outside the type.
4172 elsif Ekind (Obj_Id) = E_Variable
4173 and then Present (Encapsulating_State (Obj_Id))
4174 and then Is_Single_Concurrent_Object (Encapsulating_State (Obj_Id))
4181 end Is_Visible_Object;
4185 Body_Decl : constant Node_Id := Unit_Declaration_Node (Body_Id);
4187 Item_Id : Entity_Id;
4188 States : Elist_Id := No_Elist;
4190 -- Start of processing for Collect_Body_States
4193 -- Inspect the declarations of the body looking for source objects,
4194 -- packages and package instantiations. Note that even though this
4195 -- processing is very similar to Collect_Visible_States, a package
4196 -- body does not have a First/Next_Entity list.
4198 Decl := First (Declarations (Body_Decl));
4199 while Present (Decl) loop
4201 -- Capture source objects as internally generated temporaries cannot
4202 -- be named and participate in refinement.
4204 if Nkind (Decl) = N_Object_Declaration then
4205 Item_Id := Defining_Entity (Decl);
4207 if Comes_From_Source (Item_Id)
4208 and then Is_Visible_Object (Item_Id)
4210 Append_New_Elmt (Item_Id, States);
4213 -- Capture the visible abstract states and objects of a source
4214 -- package [instantiation].
4216 elsif Nkind (Decl) = N_Package_Declaration then
4217 Item_Id := Defining_Entity (Decl);
4219 if Comes_From_Source (Item_Id) then
4220 Collect_Visible_States (Item_Id, States);
4228 end Collect_Body_States;
4230 ------------------------
4231 -- Collect_Interfaces --
4232 ------------------------
4234 procedure Collect_Interfaces
4236 Ifaces_List : out Elist_Id;
4237 Exclude_Parents : Boolean := False;
4238 Use_Full_View : Boolean := True)
4240 procedure Collect (Typ : Entity_Id);
4241 -- Subsidiary subprogram used to traverse the whole list
4242 -- of directly and indirectly implemented interfaces
4248 procedure Collect (Typ : Entity_Id) is
4249 Ancestor : Entity_Id;
4257 -- Handle private types and subtypes
4260 and then Is_Private_Type (Typ)
4261 and then Present (Full_View (Typ))
4263 Full_T := Full_View (Typ);
4265 if Ekind (Full_T) = E_Record_Subtype then
4266 Full_T := Etype (Typ);
4268 if Present (Full_View (Full_T)) then
4269 Full_T := Full_View (Full_T);
4274 -- Include the ancestor if we are generating the whole list of
4275 -- abstract interfaces.
4277 if Etype (Full_T) /= Typ
4279 -- Protect the frontend against wrong sources. For example:
4282 -- type A is tagged null record;
4283 -- type B is new A with private;
4284 -- type C is new A with private;
4286 -- type B is new C with null record;
4287 -- type C is new B with null record;
4290 and then Etype (Full_T) /= T
4292 Ancestor := Etype (Full_T);
4295 if Is_Interface (Ancestor) and then not Exclude_Parents then
4296 Append_Unique_Elmt (Ancestor, Ifaces_List);
4300 -- Traverse the graph of ancestor interfaces
4302 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
4303 Id := First (Abstract_Interface_List (Full_T));
4304 while Present (Id) loop
4305 Iface := Etype (Id);
4307 -- Protect against wrong uses. For example:
4308 -- type I is interface;
4309 -- type O is tagged null record;
4310 -- type Wrong is new I and O with null record; -- ERROR
4312 if Is_Interface (Iface) then
4314 and then Etype (T) /= T
4315 and then Interface_Present_In_Ancestor (Etype (T), Iface)
4320 Append_Unique_Elmt (Iface, Ifaces_List);
4329 -- Start of processing for Collect_Interfaces
4332 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
4333 Ifaces_List := New_Elmt_List;
4335 end Collect_Interfaces;
4337 ----------------------------------
4338 -- Collect_Interface_Components --
4339 ----------------------------------
4341 procedure Collect_Interface_Components
4342 (Tagged_Type : Entity_Id;
4343 Components_List : out Elist_Id)
4345 procedure Collect (Typ : Entity_Id);
4346 -- Subsidiary subprogram used to climb to the parents
4352 procedure Collect (Typ : Entity_Id) is
4353 Tag_Comp : Entity_Id;
4354 Parent_Typ : Entity_Id;
4357 -- Handle private types
4359 if Present (Full_View (Etype (Typ))) then
4360 Parent_Typ := Full_View (Etype (Typ));
4362 Parent_Typ := Etype (Typ);
4365 if Parent_Typ /= Typ
4367 -- Protect the frontend against wrong sources. For example:
4370 -- type A is tagged null record;
4371 -- type B is new A with private;
4372 -- type C is new A with private;
4374 -- type B is new C with null record;
4375 -- type C is new B with null record;
4378 and then Parent_Typ /= Tagged_Type
4380 Collect (Parent_Typ);
4383 -- Collect the components containing tags of secondary dispatch
4386 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
4387 while Present (Tag_Comp) loop
4388 pragma Assert (Present (Related_Type (Tag_Comp)));
4389 Append_Elmt (Tag_Comp, Components_List);
4391 Tag_Comp := Next_Tag_Component (Tag_Comp);
4395 -- Start of processing for Collect_Interface_Components
4398 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
4399 and then Is_Tagged_Type (Tagged_Type));
4401 Components_List := New_Elmt_List;
4402 Collect (Tagged_Type);
4403 end Collect_Interface_Components;
4405 -----------------------------
4406 -- Collect_Interfaces_Info --
4407 -----------------------------
4409 procedure Collect_Interfaces_Info
4411 Ifaces_List : out Elist_Id;
4412 Components_List : out Elist_Id;
4413 Tags_List : out Elist_Id)
4415 Comps_List : Elist_Id;
4416 Comp_Elmt : Elmt_Id;
4417 Comp_Iface : Entity_Id;
4418 Iface_Elmt : Elmt_Id;
4421 function Search_Tag (Iface : Entity_Id) return Entity_Id;
4422 -- Search for the secondary tag associated with the interface type
4423 -- Iface that is implemented by T.
4429 function Search_Tag (Iface : Entity_Id) return Entity_Id is
4432 if not Is_CPP_Class (T) then
4433 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
4435 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
4439 and then Is_Tag (Node (ADT))
4440 and then Related_Type (Node (ADT)) /= Iface
4442 -- Skip secondary dispatch table referencing thunks to user
4443 -- defined primitives covered by this interface.
4445 pragma Assert (Has_Suffix (Node (ADT), 'P'));
4448 -- Skip secondary dispatch tables of Ada types
4450 if not Is_CPP_Class (T) then
4452 -- Skip secondary dispatch table referencing thunks to
4453 -- predefined primitives.
4455 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
4458 -- Skip secondary dispatch table referencing user-defined
4459 -- primitives covered by this interface.
4461 pragma Assert (Has_Suffix (Node (ADT), 'D'));
4464 -- Skip secondary dispatch table referencing predefined
4467 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
4472 pragma Assert (Is_Tag (Node (ADT)));
4476 -- Start of processing for Collect_Interfaces_Info
4479 Collect_Interfaces (T, Ifaces_List);
4480 Collect_Interface_Components (T, Comps_List);
4482 -- Search for the record component and tag associated with each
4483 -- interface type of T.
4485 Components_List := New_Elmt_List;
4486 Tags_List := New_Elmt_List;
4488 Iface_Elmt := First_Elmt (Ifaces_List);
4489 while Present (Iface_Elmt) loop
4490 Iface := Node (Iface_Elmt);
4492 -- Associate the primary tag component and the primary dispatch table
4493 -- with all the interfaces that are parents of T
4495 if Is_Ancestor (Iface, T, Use_Full_View => True) then
4496 Append_Elmt (First_Tag_Component (T), Components_List);
4497 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
4499 -- Otherwise search for the tag component and secondary dispatch
4503 Comp_Elmt := First_Elmt (Comps_List);
4504 while Present (Comp_Elmt) loop
4505 Comp_Iface := Related_Type (Node (Comp_Elmt));
4507 if Comp_Iface = Iface
4508 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
4510 Append_Elmt (Node (Comp_Elmt), Components_List);
4511 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
4515 Next_Elmt (Comp_Elmt);
4517 pragma Assert (Present (Comp_Elmt));
4520 Next_Elmt (Iface_Elmt);
4522 end Collect_Interfaces_Info;
4524 ---------------------
4525 -- Collect_Parents --
4526 ---------------------
4528 procedure Collect_Parents
4530 List : out Elist_Id;
4531 Use_Full_View : Boolean := True)
4533 Current_Typ : Entity_Id := T;
4534 Parent_Typ : Entity_Id;
4537 List := New_Elmt_List;
4539 -- No action if the if the type has no parents
4541 if T = Etype (T) then
4546 Parent_Typ := Etype (Current_Typ);
4548 if Is_Private_Type (Parent_Typ)
4549 and then Present (Full_View (Parent_Typ))
4550 and then Use_Full_View
4552 Parent_Typ := Full_View (Base_Type (Parent_Typ));
4555 Append_Elmt (Parent_Typ, List);
4557 exit when Parent_Typ = Current_Typ;
4558 Current_Typ := Parent_Typ;
4560 end Collect_Parents;
4562 ----------------------------------
4563 -- Collect_Primitive_Operations --
4564 ----------------------------------
4566 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
4567 B_Type : constant Entity_Id := Base_Type (T);
4568 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
4569 B_Scope : Entity_Id := Scope (B_Type);
4573 Is_Type_In_Pkg : Boolean;
4574 Formal_Derived : Boolean := False;
4577 function Match (E : Entity_Id) return Boolean;
4578 -- True if E's base type is B_Type, or E is of an anonymous access type
4579 -- and the base type of its designated type is B_Type.
4585 function Match (E : Entity_Id) return Boolean is
4586 Etyp : Entity_Id := Etype (E);
4589 if Ekind (Etyp) = E_Anonymous_Access_Type then
4590 Etyp := Designated_Type (Etyp);
4593 -- In Ada 2012 a primitive operation may have a formal of an
4594 -- incomplete view of the parent type.
4596 return Base_Type (Etyp) = B_Type
4598 (Ada_Version >= Ada_2012
4599 and then Ekind (Etyp) = E_Incomplete_Type
4600 and then Full_View (Etyp) = B_Type);
4603 -- Start of processing for Collect_Primitive_Operations
4606 -- For tagged types, the primitive operations are collected as they
4607 -- are declared, and held in an explicit list which is simply returned.
4609 if Is_Tagged_Type (B_Type) then
4610 return Primitive_Operations (B_Type);
4612 -- An untagged generic type that is a derived type inherits the
4613 -- primitive operations of its parent type. Other formal types only
4614 -- have predefined operators, which are not explicitly represented.
4616 elsif Is_Generic_Type (B_Type) then
4617 if Nkind (B_Decl) = N_Formal_Type_Declaration
4618 and then Nkind (Formal_Type_Definition (B_Decl)) =
4619 N_Formal_Derived_Type_Definition
4621 Formal_Derived := True;
4623 return New_Elmt_List;
4627 Op_List := New_Elmt_List;
4629 if B_Scope = Standard_Standard then
4630 if B_Type = Standard_String then
4631 Append_Elmt (Standard_Op_Concat, Op_List);
4633 elsif B_Type = Standard_Wide_String then
4634 Append_Elmt (Standard_Op_Concatw, Op_List);
4640 -- Locate the primitive subprograms of the type
4643 -- The primitive operations appear after the base type, except
4644 -- if the derivation happens within the private part of B_Scope
4645 -- and the type is a private type, in which case both the type
4646 -- and some primitive operations may appear before the base
4647 -- type, and the list of candidates starts after the type.
4649 if In_Open_Scopes (B_Scope)
4650 and then Scope (T) = B_Scope
4651 and then In_Private_Part (B_Scope)
4653 Id := Next_Entity (T);
4655 -- In Ada 2012, If the type has an incomplete partial view, there
4656 -- may be primitive operations declared before the full view, so
4657 -- we need to start scanning from the incomplete view, which is
4658 -- earlier on the entity chain.
4660 elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration
4661 and then Present (Incomplete_View (Parent (B_Type)))
4663 Id := Defining_Entity (Incomplete_View (Parent (B_Type)));
4665 -- If T is a derived from a type with an incomplete view declared
4666 -- elsewhere, that incomplete view is irrelevant, we want the
4667 -- operations in the scope of T.
4669 if Scope (Id) /= Scope (B_Type) then
4670 Id := Next_Entity (B_Type);
4674 Id := Next_Entity (B_Type);
4677 -- Set flag if this is a type in a package spec
4680 Is_Package_Or_Generic_Package (B_Scope)
4682 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
4685 while Present (Id) loop
4687 -- Test whether the result type or any of the parameter types of
4688 -- each subprogram following the type match that type when the
4689 -- type is declared in a package spec, is a derived type, or the
4690 -- subprogram is marked as primitive. (The Is_Primitive test is
4691 -- needed to find primitives of nonderived types in declarative
4692 -- parts that happen to override the predefined "=" operator.)
4694 -- Note that generic formal subprograms are not considered to be
4695 -- primitive operations and thus are never inherited.
4697 if Is_Overloadable (Id)
4698 and then (Is_Type_In_Pkg
4699 or else Is_Derived_Type (B_Type)
4700 or else Is_Primitive (Id))
4701 and then Nkind (Parent (Parent (Id)))
4702 not in N_Formal_Subprogram_Declaration
4710 Formal := First_Formal (Id);
4711 while Present (Formal) loop
4712 if Match (Formal) then
4717 Next_Formal (Formal);
4721 -- For a formal derived type, the only primitives are the ones
4722 -- inherited from the parent type. Operations appearing in the
4723 -- package declaration are not primitive for it.
4726 and then (not Formal_Derived or else Present (Alias (Id)))
4728 -- In the special case of an equality operator aliased to
4729 -- an overriding dispatching equality belonging to the same
4730 -- type, we don't include it in the list of primitives.
4731 -- This avoids inheriting multiple equality operators when
4732 -- deriving from untagged private types whose full type is
4733 -- tagged, which can otherwise cause ambiguities. Note that
4734 -- this should only happen for this kind of untagged parent
4735 -- type, since normally dispatching operations are inherited
4736 -- using the type's Primitive_Operations list.
4738 if Chars (Id) = Name_Op_Eq
4739 and then Is_Dispatching_Operation (Id)
4740 and then Present (Alias (Id))
4741 and then Present (Overridden_Operation (Alias (Id)))
4742 and then Base_Type (Etype (First_Entity (Id))) =
4743 Base_Type (Etype (First_Entity (Alias (Id))))
4747 -- Include the subprogram in the list of primitives
4750 Append_Elmt (Id, Op_List);
4757 -- For a type declared in System, some of its operations may
4758 -- appear in the target-specific extension to System.
4761 and then B_Scope = RTU_Entity (System)
4762 and then Present_System_Aux
4764 B_Scope := System_Aux_Id;
4765 Id := First_Entity (System_Aux_Id);
4771 end Collect_Primitive_Operations;
4773 -----------------------------------
4774 -- Compile_Time_Constraint_Error --
4775 -----------------------------------
4777 function Compile_Time_Constraint_Error
4780 Ent : Entity_Id := Empty;
4781 Loc : Source_Ptr := No_Location;
4782 Warn : Boolean := False) return Node_Id
4784 Msgc : String (1 .. Msg'Length + 3);
4785 -- Copy of message, with room for possible ?? or << and ! at end
4791 -- Start of processing for Compile_Time_Constraint_Error
4794 -- If this is a warning, convert it into an error if we are in code
4795 -- subject to SPARK_Mode being set On, unless Warn is True to force a
4796 -- warning. The rationale is that a compile-time constraint error should
4797 -- lead to an error instead of a warning when SPARK_Mode is On, but in
4798 -- a few cases we prefer to issue a warning and generate both a suitable
4799 -- run-time error in GNAT and a suitable check message in GNATprove.
4800 -- Those cases are those that likely correspond to deactivated SPARK
4801 -- code, so that this kind of code can be compiled and analyzed instead
4802 -- of being rejected.
4804 Error_Msg_Warn := Warn or SPARK_Mode /= On;
4806 -- A static constraint error in an instance body is not a fatal error.
4807 -- we choose to inhibit the message altogether, because there is no
4808 -- obvious node (for now) on which to post it. On the other hand the
4809 -- offending node must be replaced with a constraint_error in any case.
4811 -- No messages are generated if we already posted an error on this node
4813 if not Error_Posted (N) then
4814 if Loc /= No_Location then
4820 -- Copy message to Msgc, converting any ? in the message into
4821 -- < instead, so that we have an error in GNATprove mode.
4825 for J in 1 .. Msgl loop
4826 if Msg (J) = '?' and then (J = 1 or else Msg (J - 1) /= ''') then
4829 Msgc (J) := Msg (J);
4833 -- Message is a warning, even in Ada 95 case
4835 if Msg (Msg'Last) = '?' or else Msg (Msg'Last) = '<' then
4838 -- In Ada 83, all messages are warnings. In the private part and
4839 -- the body of an instance, constraint_checks are only warnings.
4840 -- We also make this a warning if the Warn parameter is set.
4843 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
4851 elsif In_Instance_Not_Visible then
4858 -- Otherwise we have a real error message (Ada 95 static case)
4859 -- and we make this an unconditional message. Note that in the
4860 -- warning case we do not make the message unconditional, it seems
4861 -- quite reasonable to delete messages like this (about exceptions
4862 -- that will be raised) in dead code.
4870 -- One more test, skip the warning if the related expression is
4871 -- statically unevaluated, since we don't want to warn about what
4872 -- will happen when something is evaluated if it never will be
4875 if not Is_Statically_Unevaluated (N) then
4876 if Present (Ent) then
4877 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
4879 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
4884 -- Check whether the context is an Init_Proc
4886 if Inside_Init_Proc then
4888 Conc_Typ : constant Entity_Id :=
4889 Corresponding_Concurrent_Type
4890 (Entity (Parameter_Type (First
4891 (Parameter_Specifications
4892 (Parent (Current_Scope))))));
4895 -- Don't complain if the corresponding concurrent type
4896 -- doesn't come from source (i.e. a single task/protected
4899 if Present (Conc_Typ)
4900 and then not Comes_From_Source (Conc_Typ)
4903 ("\& [<<", N, Standard_Constraint_Error, Eloc);
4906 if GNATprove_Mode then
4908 ("\& would have been raised for objects of this "
4909 & "type", N, Standard_Constraint_Error, Eloc);
4912 ("\& will be raised for objects of this type??",
4913 N, Standard_Constraint_Error, Eloc);
4919 Error_Msg_NEL ("\& [<<", N, Standard_Constraint_Error, Eloc);
4923 Error_Msg ("\static expression fails Constraint_Check", Eloc);
4924 Set_Error_Posted (N);
4930 end Compile_Time_Constraint_Error;
4932 -----------------------
4933 -- Conditional_Delay --
4934 -----------------------
4936 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
4938 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
4939 Set_Has_Delayed_Freeze (New_Ent);
4941 end Conditional_Delay;
4943 ----------------------------
4944 -- Contains_Refined_State --
4945 ----------------------------
4947 function Contains_Refined_State (Prag : Node_Id) return Boolean is
4948 function Has_State_In_Dependency (List : Node_Id) return Boolean;
4949 -- Determine whether a dependency list mentions a state with a visible
4952 function Has_State_In_Global (List : Node_Id) return Boolean;
4953 -- Determine whether a global list mentions a state with a visible
4956 function Is_Refined_State (Item : Node_Id) return Boolean;
4957 -- Determine whether Item is a reference to an abstract state with a
4958 -- visible refinement.
4960 -----------------------------
4961 -- Has_State_In_Dependency --
4962 -----------------------------
4964 function Has_State_In_Dependency (List : Node_Id) return Boolean is
4969 -- A null dependency list does not mention any states
4971 if Nkind (List) = N_Null then
4974 -- Dependency clauses appear as component associations of an
4977 elsif Nkind (List) = N_Aggregate
4978 and then Present (Component_Associations (List))
4980 Clause := First (Component_Associations (List));
4981 while Present (Clause) loop
4983 -- Inspect the outputs of a dependency clause
4985 Output := First (Choices (Clause));
4986 while Present (Output) loop
4987 if Is_Refined_State (Output) then
4994 -- Inspect the outputs of a dependency clause
4996 if Is_Refined_State (Expression (Clause)) then
5003 -- If we get here, then none of the dependency clauses mention a
5004 -- state with visible refinement.
5008 -- An illegal pragma managed to sneak in
5011 raise Program_Error;
5013 end Has_State_In_Dependency;
5015 -------------------------
5016 -- Has_State_In_Global --
5017 -------------------------
5019 function Has_State_In_Global (List : Node_Id) return Boolean is
5023 -- A null global list does not mention any states
5025 if Nkind (List) = N_Null then
5028 -- Simple global list or moded global list declaration
5030 elsif Nkind (List) = N_Aggregate then
5032 -- The declaration of a simple global list appear as a collection
5035 if Present (Expressions (List)) then
5036 Item := First (Expressions (List));
5037 while Present (Item) loop
5038 if Is_Refined_State (Item) then
5045 -- The declaration of a moded global list appears as a collection
5046 -- of component associations where individual choices denote
5050 Item := First (Component_Associations (List));
5051 while Present (Item) loop
5052 if Has_State_In_Global (Expression (Item)) then
5060 -- If we get here, then the simple/moded global list did not
5061 -- mention any states with a visible refinement.
5065 -- Single global item declaration
5067 elsif Is_Entity_Name (List) then
5068 return Is_Refined_State (List);
5070 -- An illegal pragma managed to sneak in
5073 raise Program_Error;
5075 end Has_State_In_Global;
5077 ----------------------
5078 -- Is_Refined_State --
5079 ----------------------
5081 function Is_Refined_State (Item : Node_Id) return Boolean is
5083 Item_Id : Entity_Id;
5086 if Nkind (Item) = N_Null then
5089 -- States cannot be subject to attribute 'Result. This case arises
5090 -- in dependency relations.
5092 elsif Nkind (Item) = N_Attribute_Reference
5093 and then Attribute_Name (Item) = Name_Result
5097 -- Multiple items appear as an aggregate. This case arises in
5098 -- dependency relations.
5100 elsif Nkind (Item) = N_Aggregate
5101 and then Present (Expressions (Item))
5103 Elmt := First (Expressions (Item));
5104 while Present (Elmt) loop
5105 if Is_Refined_State (Elmt) then
5112 -- If we get here, then none of the inputs or outputs reference a
5113 -- state with visible refinement.
5120 Item_Id := Entity_Of (Item);
5124 and then Ekind (Item_Id) = E_Abstract_State
5125 and then Has_Visible_Refinement (Item_Id);
5127 end Is_Refined_State;
5131 Arg : constant Node_Id :=
5132 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
5133 Nam : constant Name_Id := Pragma_Name (Prag);
5135 -- Start of processing for Contains_Refined_State
5138 if Nam = Name_Depends then
5139 return Has_State_In_Dependency (Arg);
5141 else pragma Assert (Nam = Name_Global);
5142 return Has_State_In_Global (Arg);
5144 end Contains_Refined_State;
5146 -------------------------
5147 -- Copy_Component_List --
5148 -------------------------
5150 function Copy_Component_List
5152 Loc : Source_Ptr) return List_Id
5155 Comps : constant List_Id := New_List;
5158 Comp := First_Component (Underlying_Type (R_Typ));
5159 while Present (Comp) loop
5160 if Comes_From_Source (Comp) then
5162 Comp_Decl : constant Node_Id := Declaration_Node (Comp);
5165 Make_Component_Declaration (Loc,
5166 Defining_Identifier =>
5167 Make_Defining_Identifier (Loc, Chars (Comp)),
5168 Component_Definition =>
5170 (Component_Definition (Comp_Decl), New_Sloc => Loc)));
5174 Next_Component (Comp);
5178 end Copy_Component_List;
5180 -------------------------
5181 -- Copy_Parameter_List --
5182 -------------------------
5184 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
5185 Loc : constant Source_Ptr := Sloc (Subp_Id);
5190 if No (First_Formal (Subp_Id)) then
5194 Formal := First_Formal (Subp_Id);
5195 while Present (Formal) loop
5197 Make_Parameter_Specification (Loc,
5198 Defining_Identifier =>
5199 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
5200 In_Present => In_Present (Parent (Formal)),
5201 Out_Present => Out_Present (Parent (Formal)),
5203 New_Occurrence_Of (Etype (Formal), Loc),
5205 New_Copy_Tree (Expression (Parent (Formal)))));
5207 Next_Formal (Formal);
5212 end Copy_Parameter_List;
5214 ----------------------------
5215 -- Copy_SPARK_Mode_Aspect --
5216 ----------------------------
5218 procedure Copy_SPARK_Mode_Aspect (From : Node_Id; To : Node_Id) is
5219 pragma Assert (not Has_Aspects (To));
5223 if Has_Aspects (From) then
5224 Asp := Find_Aspect (Defining_Entity (From), Aspect_SPARK_Mode);
5226 if Present (Asp) then
5227 Set_Aspect_Specifications (To, New_List (New_Copy_Tree (Asp)));
5228 Set_Has_Aspects (To, True);
5231 end Copy_SPARK_Mode_Aspect;
5233 --------------------------
5234 -- Copy_Subprogram_Spec --
5235 --------------------------
5237 function Copy_Subprogram_Spec (Spec : Node_Id) return Node_Id is
5239 Formal_Spec : Node_Id;
5243 -- The structure of the original tree must be replicated without any
5244 -- alterations. Use New_Copy_Tree for this purpose.
5246 Result := New_Copy_Tree (Spec);
5248 -- Create a new entity for the defining unit name
5250 Def_Id := Defining_Unit_Name (Result);
5251 Set_Defining_Unit_Name (Result,
5252 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
5254 -- Create new entities for the formal parameters
5256 if Present (Parameter_Specifications (Result)) then
5257 Formal_Spec := First (Parameter_Specifications (Result));
5258 while Present (Formal_Spec) loop
5259 Def_Id := Defining_Identifier (Formal_Spec);
5260 Set_Defining_Identifier (Formal_Spec,
5261 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
5268 end Copy_Subprogram_Spec;
5270 --------------------------------
5271 -- Corresponding_Generic_Type --
5272 --------------------------------
5274 function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id is
5280 if not Is_Generic_Actual_Type (T) then
5283 -- If the actual is the actual of an enclosing instance, resolution
5284 -- was correct in the generic.
5286 elsif Nkind (Parent (T)) = N_Subtype_Declaration
5287 and then Is_Entity_Name (Subtype_Indication (Parent (T)))
5289 Is_Generic_Actual_Type (Entity (Subtype_Indication (Parent (T))))
5296 if Is_Wrapper_Package (Inst) then
5297 Inst := Related_Instance (Inst);
5302 (Specification (Unit_Declaration_Node (Inst)));
5304 -- Generic actual has the same name as the corresponding formal
5306 Typ := First_Entity (Gen);
5307 while Present (Typ) loop
5308 if Chars (Typ) = Chars (T) then
5317 end Corresponding_Generic_Type;
5319 --------------------
5320 -- Current_Entity --
5321 --------------------
5323 -- The currently visible definition for a given identifier is the
5324 -- one most chained at the start of the visibility chain, i.e. the
5325 -- one that is referenced by the Node_Id value of the name of the
5326 -- given identifier.
5328 function Current_Entity (N : Node_Id) return Entity_Id is
5330 return Get_Name_Entity_Id (Chars (N));
5333 -----------------------------
5334 -- Current_Entity_In_Scope --
5335 -----------------------------
5337 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
5339 CS : constant Entity_Id := Current_Scope;
5341 Transient_Case : constant Boolean := Scope_Is_Transient;
5344 E := Get_Name_Entity_Id (Chars (N));
5346 and then Scope (E) /= CS
5347 and then (not Transient_Case or else Scope (E) /= Scope (CS))
5353 end Current_Entity_In_Scope;
5359 function Current_Scope return Entity_Id is
5361 if Scope_Stack.Last = -1 then
5362 return Standard_Standard;
5365 C : constant Entity_Id :=
5366 Scope_Stack.Table (Scope_Stack.Last).Entity;
5371 return Standard_Standard;
5377 ----------------------------
5378 -- Current_Scope_No_Loops --
5379 ----------------------------
5381 function Current_Scope_No_Loops return Entity_Id is
5385 -- Examine the scope stack starting from the current scope and skip any
5386 -- internally generated loops.
5389 while Present (S) and then S /= Standard_Standard loop
5390 if Ekind (S) = E_Loop and then not Comes_From_Source (S) then
5398 end Current_Scope_No_Loops;
5400 ------------------------
5401 -- Current_Subprogram --
5402 ------------------------
5404 function Current_Subprogram return Entity_Id is
5405 Scop : constant Entity_Id := Current_Scope;
5407 if Is_Subprogram_Or_Generic_Subprogram (Scop) then
5410 return Enclosing_Subprogram (Scop);
5412 end Current_Subprogram;
5414 ----------------------------------
5415 -- Deepest_Type_Access_Level --
5416 ----------------------------------
5418 function Deepest_Type_Access_Level (Typ : Entity_Id) return Uint is
5420 if Ekind (Typ) = E_Anonymous_Access_Type
5421 and then not Is_Local_Anonymous_Access (Typ)
5422 and then Nkind (Associated_Node_For_Itype (Typ)) = N_Object_Declaration
5424 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
5428 Scope_Depth (Enclosing_Dynamic_Scope
5429 (Defining_Identifier
5430 (Associated_Node_For_Itype (Typ))));
5432 -- For generic formal type, return Int'Last (infinite).
5433 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
5435 elsif Is_Generic_Type (Root_Type (Typ)) then
5436 return UI_From_Int (Int'Last);
5439 return Type_Access_Level (Typ);
5441 end Deepest_Type_Access_Level;
5443 ---------------------
5444 -- Defining_Entity --
5445 ---------------------
5447 function Defining_Entity
5449 Empty_On_Errors : Boolean := False) return Entity_Id
5451 Err : Entity_Id := Empty;
5455 when N_Abstract_Subprogram_Declaration
5456 | N_Expression_Function
5457 | N_Formal_Subprogram_Declaration
5458 | N_Generic_Package_Declaration
5459 | N_Generic_Subprogram_Declaration
5460 | N_Package_Declaration
5462 | N_Subprogram_Body_Stub
5463 | N_Subprogram_Declaration
5464 | N_Subprogram_Renaming_Declaration
5466 return Defining_Entity (Specification (N));
5468 when N_Component_Declaration
5469 | N_Defining_Program_Unit_Name
5470 | N_Discriminant_Specification
5472 | N_Entry_Declaration
5473 | N_Entry_Index_Specification
5474 | N_Exception_Declaration
5475 | N_Exception_Renaming_Declaration
5476 | N_Formal_Object_Declaration
5477 | N_Formal_Package_Declaration
5478 | N_Formal_Type_Declaration
5479 | N_Full_Type_Declaration
5480 | N_Implicit_Label_Declaration
5481 | N_Incomplete_Type_Declaration
5482 | N_Iterator_Specification
5483 | N_Loop_Parameter_Specification
5484 | N_Number_Declaration
5485 | N_Object_Declaration
5486 | N_Object_Renaming_Declaration
5487 | N_Package_Body_Stub
5488 | N_Parameter_Specification
5489 | N_Private_Extension_Declaration
5490 | N_Private_Type_Declaration
5492 | N_Protected_Body_Stub
5493 | N_Protected_Type_Declaration
5494 | N_Single_Protected_Declaration
5495 | N_Single_Task_Declaration
5496 | N_Subtype_Declaration
5499 | N_Task_Type_Declaration
5501 return Defining_Identifier (N);
5504 return Defining_Entity (Proper_Body (N));
5506 when N_Function_Instantiation
5507 | N_Function_Specification
5508 | N_Generic_Function_Renaming_Declaration
5509 | N_Generic_Package_Renaming_Declaration
5510 | N_Generic_Procedure_Renaming_Declaration
5512 | N_Package_Instantiation
5513 | N_Package_Renaming_Declaration
5514 | N_Package_Specification
5515 | N_Procedure_Instantiation
5516 | N_Procedure_Specification
5519 Nam : constant Node_Id := Defining_Unit_Name (N);
5522 if Nkind (Nam) in N_Entity then
5525 -- For Error, make up a name and attach to declaration so we
5526 -- can continue semantic analysis.
5528 elsif Nam = Error then
5529 if Empty_On_Errors then
5532 Err := Make_Temporary (Sloc (N), 'T');
5533 Set_Defining_Unit_Name (N, Err);
5538 -- If not an entity, get defining identifier
5541 return Defining_Identifier (Nam);
5545 when N_Block_Statement
5548 return Entity (Identifier (N));
5551 if Empty_On_Errors then
5554 raise Program_Error;
5557 end Defining_Entity;
5559 --------------------------
5560 -- Denotes_Discriminant --
5561 --------------------------
5563 function Denotes_Discriminant
5565 Check_Concurrent : Boolean := False) return Boolean
5570 if not Is_Entity_Name (N) or else No (Entity (N)) then
5576 -- If we are checking for a protected type, the discriminant may have
5577 -- been rewritten as the corresponding discriminal of the original type
5578 -- or of the corresponding concurrent record, depending on whether we
5579 -- are in the spec or body of the protected type.
5581 return Ekind (E) = E_Discriminant
5584 and then Ekind (E) = E_In_Parameter
5585 and then Present (Discriminal_Link (E))
5587 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
5589 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
5590 end Denotes_Discriminant;
5592 -------------------------
5593 -- Denotes_Same_Object --
5594 -------------------------
5596 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
5597 Obj1 : Node_Id := A1;
5598 Obj2 : Node_Id := A2;
5600 function Has_Prefix (N : Node_Id) return Boolean;
5601 -- Return True if N has attribute Prefix
5603 function Is_Renaming (N : Node_Id) return Boolean;
5604 -- Return true if N names a renaming entity
5606 function Is_Valid_Renaming (N : Node_Id) return Boolean;
5607 -- For renamings, return False if the prefix of any dereference within
5608 -- the renamed object_name is a variable, or any expression within the
5609 -- renamed object_name contains references to variables or calls on
5610 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
5616 function Has_Prefix (N : Node_Id) return Boolean is
5620 N_Attribute_Reference,
5622 N_Explicit_Dereference,
5623 N_Indexed_Component,
5625 N_Selected_Component,
5633 function Is_Renaming (N : Node_Id) return Boolean is
5635 return Is_Entity_Name (N)
5636 and then Present (Renamed_Entity (Entity (N)));
5639 -----------------------
5640 -- Is_Valid_Renaming --
5641 -----------------------
5643 function Is_Valid_Renaming (N : Node_Id) return Boolean is
5645 function Check_Renaming (N : Node_Id) return Boolean;
5646 -- Recursive function used to traverse all the prefixes of N
5648 function Check_Renaming (N : Node_Id) return Boolean is
5651 and then not Check_Renaming (Renamed_Entity (Entity (N)))
5656 if Nkind (N) = N_Indexed_Component then
5661 Indx := First (Expressions (N));
5662 while Present (Indx) loop
5663 if not Is_OK_Static_Expression (Indx) then
5672 if Has_Prefix (N) then
5674 P : constant Node_Id := Prefix (N);
5677 if Nkind (N) = N_Explicit_Dereference
5678 and then Is_Variable (P)
5682 elsif Is_Entity_Name (P)
5683 and then Ekind (Entity (P)) = E_Function
5687 elsif Nkind (P) = N_Function_Call then
5691 -- Recursion to continue traversing the prefix of the
5692 -- renaming expression
5694 return Check_Renaming (P);
5701 -- Start of processing for Is_Valid_Renaming
5704 return Check_Renaming (N);
5705 end Is_Valid_Renaming;
5707 -- Start of processing for Denotes_Same_Object
5710 -- Both names statically denote the same stand-alone object or parameter
5711 -- (RM 6.4.1(6.5/3))
5713 if Is_Entity_Name (Obj1)
5714 and then Is_Entity_Name (Obj2)
5715 and then Entity (Obj1) = Entity (Obj2)
5720 -- For renamings, the prefix of any dereference within the renamed
5721 -- object_name is not a variable, and any expression within the
5722 -- renamed object_name contains no references to variables nor
5723 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
5725 if Is_Renaming (Obj1) then
5726 if Is_Valid_Renaming (Obj1) then
5727 Obj1 := Renamed_Entity (Entity (Obj1));
5733 if Is_Renaming (Obj2) then
5734 if Is_Valid_Renaming (Obj2) then
5735 Obj2 := Renamed_Entity (Entity (Obj2));
5741 -- No match if not same node kind (such cases are handled by
5742 -- Denotes_Same_Prefix)
5744 if Nkind (Obj1) /= Nkind (Obj2) then
5747 -- After handling valid renamings, one of the two names statically
5748 -- denoted a renaming declaration whose renamed object_name is known
5749 -- to denote the same object as the other (RM 6.4.1(6.10/3))
5751 elsif Is_Entity_Name (Obj1) then
5752 if Is_Entity_Name (Obj2) then
5753 return Entity (Obj1) = Entity (Obj2);
5758 -- Both names are selected_components, their prefixes are known to
5759 -- denote the same object, and their selector_names denote the same
5760 -- component (RM 6.4.1(6.6/3)).
5762 elsif Nkind (Obj1) = N_Selected_Component then
5763 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
5765 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
5767 -- Both names are dereferences and the dereferenced names are known to
5768 -- denote the same object (RM 6.4.1(6.7/3))
5770 elsif Nkind (Obj1) = N_Explicit_Dereference then
5771 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
5773 -- Both names are indexed_components, their prefixes are known to denote
5774 -- the same object, and each of the pairs of corresponding index values
5775 -- are either both static expressions with the same static value or both
5776 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
5778 elsif Nkind (Obj1) = N_Indexed_Component then
5779 if not Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
5787 Indx1 := First (Expressions (Obj1));
5788 Indx2 := First (Expressions (Obj2));
5789 while Present (Indx1) loop
5791 -- Indexes must denote the same static value or same object
5793 if Is_OK_Static_Expression (Indx1) then
5794 if not Is_OK_Static_Expression (Indx2) then
5797 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
5801 elsif not Denotes_Same_Object (Indx1, Indx2) then
5813 -- Both names are slices, their prefixes are known to denote the same
5814 -- object, and the two slices have statically matching index constraints
5815 -- (RM 6.4.1(6.9/3))
5817 elsif Nkind (Obj1) = N_Slice
5818 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
5821 Lo1, Lo2, Hi1, Hi2 : Node_Id;
5824 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
5825 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
5827 -- Check whether bounds are statically identical. There is no
5828 -- attempt to detect partial overlap of slices.
5830 return Denotes_Same_Object (Lo1, Lo2)
5832 Denotes_Same_Object (Hi1, Hi2);
5835 -- In the recursion, literals appear as indexes
5837 elsif Nkind (Obj1) = N_Integer_Literal
5839 Nkind (Obj2) = N_Integer_Literal
5841 return Intval (Obj1) = Intval (Obj2);
5846 end Denotes_Same_Object;
5848 -------------------------
5849 -- Denotes_Same_Prefix --
5850 -------------------------
5852 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
5854 if Is_Entity_Name (A1) then
5855 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
5856 and then not Is_Access_Type (Etype (A1))
5858 return Denotes_Same_Object (A1, Prefix (A2))
5859 or else Denotes_Same_Prefix (A1, Prefix (A2));
5864 elsif Is_Entity_Name (A2) then
5865 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
5867 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
5869 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
5872 Root1, Root2 : Node_Id;
5873 Depth1, Depth2 : Nat := 0;
5876 Root1 := Prefix (A1);
5877 while not Is_Entity_Name (Root1) loop
5879 (Root1, N_Selected_Component, N_Indexed_Component)
5883 Root1 := Prefix (Root1);
5886 Depth1 := Depth1 + 1;
5889 Root2 := Prefix (A2);
5890 while not Is_Entity_Name (Root2) loop
5891 if not Nkind_In (Root2, N_Selected_Component,
5892 N_Indexed_Component)
5896 Root2 := Prefix (Root2);
5899 Depth2 := Depth2 + 1;
5902 -- If both have the same depth and they do not denote the same
5903 -- object, they are disjoint and no warning is needed.
5905 if Depth1 = Depth2 then
5908 elsif Depth1 > Depth2 then
5909 Root1 := Prefix (A1);
5910 for J in 1 .. Depth1 - Depth2 - 1 loop
5911 Root1 := Prefix (Root1);
5914 return Denotes_Same_Object (Root1, A2);
5917 Root2 := Prefix (A2);
5918 for J in 1 .. Depth2 - Depth1 - 1 loop
5919 Root2 := Prefix (Root2);
5922 return Denotes_Same_Object (A1, Root2);
5929 end Denotes_Same_Prefix;
5931 ----------------------
5932 -- Denotes_Variable --
5933 ----------------------
5935 function Denotes_Variable (N : Node_Id) return Boolean is
5937 return Is_Variable (N) and then Paren_Count (N) = 0;
5938 end Denotes_Variable;
5940 -----------------------------
5941 -- Depends_On_Discriminant --
5942 -----------------------------
5944 function Depends_On_Discriminant (N : Node_Id) return Boolean is
5949 Get_Index_Bounds (N, L, H);
5950 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
5951 end Depends_On_Discriminant;
5953 -------------------------
5954 -- Designate_Same_Unit --
5955 -------------------------
5957 function Designate_Same_Unit
5959 Name2 : Node_Id) return Boolean
5961 K1 : constant Node_Kind := Nkind (Name1);
5962 K2 : constant Node_Kind := Nkind (Name2);
5964 function Prefix_Node (N : Node_Id) return Node_Id;
5965 -- Returns the parent unit name node of a defining program unit name
5966 -- or the prefix if N is a selected component or an expanded name.
5968 function Select_Node (N : Node_Id) return Node_Id;
5969 -- Returns the defining identifier node of a defining program unit
5970 -- name or the selector node if N is a selected component or an
5977 function Prefix_Node (N : Node_Id) return Node_Id is
5979 if Nkind (N) = N_Defining_Program_Unit_Name then
5990 function Select_Node (N : Node_Id) return Node_Id is
5992 if Nkind (N) = N_Defining_Program_Unit_Name then
5993 return Defining_Identifier (N);
5995 return Selector_Name (N);
5999 -- Start of processing for Designate_Same_Unit
6002 if Nkind_In (K1, N_Identifier, N_Defining_Identifier)
6004 Nkind_In (K2, N_Identifier, N_Defining_Identifier)
6006 return Chars (Name1) = Chars (Name2);
6008 elsif Nkind_In (K1, N_Expanded_Name,
6009 N_Selected_Component,
6010 N_Defining_Program_Unit_Name)
6012 Nkind_In (K2, N_Expanded_Name,
6013 N_Selected_Component,
6014 N_Defining_Program_Unit_Name)
6017 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
6019 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
6024 end Designate_Same_Unit;
6026 ---------------------------------------------
6027 -- Diagnose_Iterated_Component_Association --
6028 ---------------------------------------------
6030 procedure Diagnose_Iterated_Component_Association (N : Node_Id) is
6031 Def_Id : constant Entity_Id := Defining_Identifier (N);
6035 -- Determine whether the iterated component association appears within
6036 -- an aggregate. If this is the case, raise Program_Error because the
6037 -- iterated component association cannot be left in the tree as is and
6038 -- must always be processed by the related aggregate.
6041 while Present (Aggr) loop
6042 if Nkind (Aggr) = N_Aggregate then
6043 raise Program_Error;
6045 -- Prevent the search from going too far
6047 elsif Is_Body_Or_Package_Declaration (Aggr) then
6051 Aggr := Parent (Aggr);
6054 -- At this point it is known that the iterated component association is
6055 -- not within an aggregate. This is really a quantified expression with
6056 -- a missing "all" or "some" quantifier.
6058 Error_Msg_N ("missing quantifier", Def_Id);
6060 -- Rewrite the iterated component association as True to prevent any
6063 Rewrite (N, New_Occurrence_Of (Standard_True, Sloc (N)));
6065 end Diagnose_Iterated_Component_Association;
6067 ---------------------------------
6068 -- Dynamic_Accessibility_Level --
6069 ---------------------------------
6071 function Dynamic_Accessibility_Level (Expr : Node_Id) return Node_Id is
6072 Loc : constant Source_Ptr := Sloc (Expr);
6074 function Make_Level_Literal (Level : Uint) return Node_Id;
6075 -- Construct an integer literal representing an accessibility level
6076 -- with its type set to Natural.
6078 ------------------------
6079 -- Make_Level_Literal --
6080 ------------------------
6082 function Make_Level_Literal (Level : Uint) return Node_Id is
6083 Result : constant Node_Id := Make_Integer_Literal (Loc, Level);
6086 Set_Etype (Result, Standard_Natural);
6088 end Make_Level_Literal;
6094 -- Start of processing for Dynamic_Accessibility_Level
6097 if Is_Entity_Name (Expr) then
6100 if Present (Renamed_Object (E)) then
6101 return Dynamic_Accessibility_Level (Renamed_Object (E));
6104 if Is_Formal (E) or else Ekind_In (E, E_Variable, E_Constant) then
6105 if Present (Extra_Accessibility (E)) then
6106 return New_Occurrence_Of (Extra_Accessibility (E), Loc);
6111 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
6113 case Nkind (Expr) is
6115 -- For access discriminant, the level of the enclosing object
6117 when N_Selected_Component =>
6118 if Ekind (Entity (Selector_Name (Expr))) = E_Discriminant
6119 and then Ekind (Etype (Entity (Selector_Name (Expr)))) =
6120 E_Anonymous_Access_Type
6122 return Make_Level_Literal (Object_Access_Level (Expr));
6125 when N_Attribute_Reference =>
6126 case Get_Attribute_Id (Attribute_Name (Expr)) is
6128 -- For X'Access, the level of the prefix X
6130 when Attribute_Access =>
6131 return Make_Level_Literal
6132 (Object_Access_Level (Prefix (Expr)));
6134 -- Treat the unchecked attributes as library-level
6136 when Attribute_Unchecked_Access
6137 | Attribute_Unrestricted_Access
6139 return Make_Level_Literal (Scope_Depth (Standard_Standard));
6141 -- No other access-valued attributes
6144 raise Program_Error;
6149 -- Unimplemented: depends on context. As an actual parameter where
6150 -- formal type is anonymous, use
6151 -- Scope_Depth (Current_Scope) + 1.
6152 -- For other cases, see 3.10.2(14/3) and following. ???
6156 when N_Type_Conversion =>
6157 if not Is_Local_Anonymous_Access (Etype (Expr)) then
6159 -- Handle type conversions introduced for a rename of an
6160 -- Ada 2012 stand-alone object of an anonymous access type.
6162 return Dynamic_Accessibility_Level (Expression (Expr));
6169 return Make_Level_Literal (Type_Access_Level (Etype (Expr)));
6170 end Dynamic_Accessibility_Level;
6172 -----------------------------------
6173 -- Effective_Extra_Accessibility --
6174 -----------------------------------
6176 function Effective_Extra_Accessibility (Id : Entity_Id) return Entity_Id is
6178 if Present (Renamed_Object (Id))
6179 and then Is_Entity_Name (Renamed_Object (Id))
6181 return Effective_Extra_Accessibility (Entity (Renamed_Object (Id)));
6183 return Extra_Accessibility (Id);
6185 end Effective_Extra_Accessibility;
6187 -----------------------------
6188 -- Effective_Reads_Enabled --
6189 -----------------------------
6191 function Effective_Reads_Enabled (Id : Entity_Id) return Boolean is
6193 return Has_Enabled_Property (Id, Name_Effective_Reads);
6194 end Effective_Reads_Enabled;
6196 ------------------------------
6197 -- Effective_Writes_Enabled --
6198 ------------------------------
6200 function Effective_Writes_Enabled (Id : Entity_Id) return Boolean is
6202 return Has_Enabled_Property (Id, Name_Effective_Writes);
6203 end Effective_Writes_Enabled;
6205 ------------------------------
6206 -- Enclosing_Comp_Unit_Node --
6207 ------------------------------
6209 function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id is
6210 Current_Node : Node_Id;
6214 while Present (Current_Node)
6215 and then Nkind (Current_Node) /= N_Compilation_Unit
6217 Current_Node := Parent (Current_Node);
6220 if Nkind (Current_Node) /= N_Compilation_Unit then
6223 return Current_Node;
6225 end Enclosing_Comp_Unit_Node;
6227 --------------------------
6228 -- Enclosing_CPP_Parent --
6229 --------------------------
6231 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
6232 Parent_Typ : Entity_Id := Typ;
6235 while not Is_CPP_Class (Parent_Typ)
6236 and then Etype (Parent_Typ) /= Parent_Typ
6238 Parent_Typ := Etype (Parent_Typ);
6240 if Is_Private_Type (Parent_Typ) then
6241 Parent_Typ := Full_View (Base_Type (Parent_Typ));
6245 pragma Assert (Is_CPP_Class (Parent_Typ));
6247 end Enclosing_CPP_Parent;
6249 ---------------------------
6250 -- Enclosing_Declaration --
6251 ---------------------------
6253 function Enclosing_Declaration (N : Node_Id) return Node_Id is
6254 Decl : Node_Id := N;
6257 while Present (Decl)
6258 and then not (Nkind (Decl) in N_Declaration
6260 Nkind (Decl) in N_Later_Decl_Item)
6262 Decl := Parent (Decl);
6266 end Enclosing_Declaration;
6268 ----------------------------
6269 -- Enclosing_Generic_Body --
6270 ----------------------------
6272 function Enclosing_Generic_Body
6273 (N : Node_Id) return Node_Id
6281 while Present (P) loop
6282 if Nkind (P) = N_Package_Body
6283 or else Nkind (P) = N_Subprogram_Body
6285 Spec := Corresponding_Spec (P);
6287 if Present (Spec) then
6288 Decl := Unit_Declaration_Node (Spec);
6290 if Nkind (Decl) = N_Generic_Package_Declaration
6291 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
6302 end Enclosing_Generic_Body;
6304 ----------------------------
6305 -- Enclosing_Generic_Unit --
6306 ----------------------------
6308 function Enclosing_Generic_Unit
6309 (N : Node_Id) return Node_Id
6317 while Present (P) loop
6318 if Nkind (P) = N_Generic_Package_Declaration
6319 or else Nkind (P) = N_Generic_Subprogram_Declaration
6323 elsif Nkind (P) = N_Package_Body
6324 or else Nkind (P) = N_Subprogram_Body
6326 Spec := Corresponding_Spec (P);
6328 if Present (Spec) then
6329 Decl := Unit_Declaration_Node (Spec);
6331 if Nkind (Decl) = N_Generic_Package_Declaration
6332 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
6343 end Enclosing_Generic_Unit;
6345 -------------------------------
6346 -- Enclosing_Lib_Unit_Entity --
6347 -------------------------------
6349 function Enclosing_Lib_Unit_Entity
6350 (E : Entity_Id := Current_Scope) return Entity_Id
6352 Unit_Entity : Entity_Id;
6355 -- Look for enclosing library unit entity by following scope links.
6356 -- Equivalent to, but faster than indexing through the scope stack.
6359 while (Present (Scope (Unit_Entity))
6360 and then Scope (Unit_Entity) /= Standard_Standard)
6361 and not Is_Child_Unit (Unit_Entity)
6363 Unit_Entity := Scope (Unit_Entity);
6367 end Enclosing_Lib_Unit_Entity;
6369 -----------------------------
6370 -- Enclosing_Lib_Unit_Node --
6371 -----------------------------
6373 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
6374 Encl_Unit : Node_Id;
6377 Encl_Unit := Enclosing_Comp_Unit_Node (N);
6378 while Present (Encl_Unit)
6379 and then Nkind (Unit (Encl_Unit)) = N_Subunit
6381 Encl_Unit := Library_Unit (Encl_Unit);
6384 pragma Assert (Nkind (Encl_Unit) = N_Compilation_Unit);
6386 end Enclosing_Lib_Unit_Node;
6388 -----------------------
6389 -- Enclosing_Package --
6390 -----------------------
6392 function Enclosing_Package (E : Entity_Id) return Entity_Id is
6393 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
6396 if Dynamic_Scope = Standard_Standard then
6397 return Standard_Standard;
6399 elsif Dynamic_Scope = Empty then
6402 elsif Ekind_In (Dynamic_Scope, E_Package, E_Package_Body,
6405 return Dynamic_Scope;
6408 return Enclosing_Package (Dynamic_Scope);
6410 end Enclosing_Package;
6412 -------------------------------------
6413 -- Enclosing_Package_Or_Subprogram --
6414 -------------------------------------
6416 function Enclosing_Package_Or_Subprogram (E : Entity_Id) return Entity_Id is
6421 while Present (S) loop
6422 if Is_Package_Or_Generic_Package (S)
6423 or else Ekind (S) = E_Package_Body
6427 elsif Is_Subprogram_Or_Generic_Subprogram (S)
6428 or else Ekind (S) = E_Subprogram_Body
6438 end Enclosing_Package_Or_Subprogram;
6440 --------------------------
6441 -- Enclosing_Subprogram --
6442 --------------------------
6444 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
6445 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
6448 if Dynamic_Scope = Standard_Standard then
6451 elsif Dynamic_Scope = Empty then
6454 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
6455 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
6457 elsif Ekind (Dynamic_Scope) = E_Block
6458 or else Ekind (Dynamic_Scope) = E_Return_Statement
6460 return Enclosing_Subprogram (Dynamic_Scope);
6462 elsif Ekind (Dynamic_Scope) = E_Task_Type then
6463 return Get_Task_Body_Procedure (Dynamic_Scope);
6465 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
6466 and then Present (Full_View (Dynamic_Scope))
6467 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
6469 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
6471 -- No body is generated if the protected operation is eliminated
6473 elsif Convention (Dynamic_Scope) = Convention_Protected
6474 and then not Is_Eliminated (Dynamic_Scope)
6475 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
6477 return Protected_Body_Subprogram (Dynamic_Scope);
6480 return Dynamic_Scope;
6482 end Enclosing_Subprogram;
6484 ------------------------
6485 -- Ensure_Freeze_Node --
6486 ------------------------
6488 procedure Ensure_Freeze_Node (E : Entity_Id) is
6491 if No (Freeze_Node (E)) then
6492 FN := Make_Freeze_Entity (Sloc (E));
6493 Set_Has_Delayed_Freeze (E);
6494 Set_Freeze_Node (E, FN);
6495 Set_Access_Types_To_Process (FN, No_Elist);
6496 Set_TSS_Elist (FN, No_Elist);
6499 end Ensure_Freeze_Node;
6505 procedure Enter_Name (Def_Id : Entity_Id) is
6506 C : constant Entity_Id := Current_Entity (Def_Id);
6507 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
6508 S : constant Entity_Id := Current_Scope;
6511 Generate_Definition (Def_Id);
6513 -- Add new name to current scope declarations. Check for duplicate
6514 -- declaration, which may or may not be a genuine error.
6518 -- Case of previous entity entered because of a missing declaration
6519 -- or else a bad subtype indication. Best is to use the new entity,
6520 -- and make the previous one invisible.
6522 if Etype (E) = Any_Type then
6523 Set_Is_Immediately_Visible (E, False);
6525 -- Case of renaming declaration constructed for package instances.
6526 -- if there is an explicit declaration with the same identifier,
6527 -- the renaming is not immediately visible any longer, but remains
6528 -- visible through selected component notation.
6530 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
6531 and then not Comes_From_Source (E)
6533 Set_Is_Immediately_Visible (E, False);
6535 -- The new entity may be the package renaming, which has the same
6536 -- same name as a generic formal which has been seen already.
6538 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
6539 and then not Comes_From_Source (Def_Id)
6541 Set_Is_Immediately_Visible (E, False);
6543 -- For a fat pointer corresponding to a remote access to subprogram,
6544 -- we use the same identifier as the RAS type, so that the proper
6545 -- name appears in the stub. This type is only retrieved through
6546 -- the RAS type and never by visibility, and is not added to the
6547 -- visibility list (see below).
6549 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
6550 and then Ekind (Def_Id) = E_Record_Type
6551 and then Present (Corresponding_Remote_Type (Def_Id))
6555 -- Case of an implicit operation or derived literal. The new entity
6556 -- hides the implicit one, which is removed from all visibility,
6557 -- i.e. the entity list of its scope, and homonym chain of its name.
6559 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
6560 or else Is_Internal (E)
6563 Decl : constant Node_Id := Parent (E);
6565 Prev_Vis : Entity_Id;
6568 -- If E is an implicit declaration, it cannot be the first
6569 -- entity in the scope.
6571 Prev := First_Entity (Current_Scope);
6572 while Present (Prev) and then Next_Entity (Prev) /= E loop
6578 -- If E is not on the entity chain of the current scope,
6579 -- it is an implicit declaration in the generic formal
6580 -- part of a generic subprogram. When analyzing the body,
6581 -- the generic formals are visible but not on the entity
6582 -- chain of the subprogram. The new entity will become
6583 -- the visible one in the body.
6586 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
6590 Set_Next_Entity (Prev, Next_Entity (E));
6592 if No (Next_Entity (Prev)) then
6593 Set_Last_Entity (Current_Scope, Prev);
6596 if E = Current_Entity (E) then
6600 Prev_Vis := Current_Entity (E);
6601 while Homonym (Prev_Vis) /= E loop
6602 Prev_Vis := Homonym (Prev_Vis);
6606 if Present (Prev_Vis) then
6608 -- Skip E in the visibility chain
6610 Set_Homonym (Prev_Vis, Homonym (E));
6613 Set_Name_Entity_Id (Chars (E), Homonym (E));
6618 -- This section of code could use a comment ???
6620 elsif Present (Etype (E))
6621 and then Is_Concurrent_Type (Etype (E))
6626 -- If the homograph is a protected component renaming, it should not
6627 -- be hiding the current entity. Such renamings are treated as weak
6630 elsif Is_Prival (E) then
6631 Set_Is_Immediately_Visible (E, False);
6633 -- In this case the current entity is a protected component renaming.
6634 -- Perform minimal decoration by setting the scope and return since
6635 -- the prival should not be hiding other visible entities.
6637 elsif Is_Prival (Def_Id) then
6638 Set_Scope (Def_Id, Current_Scope);
6641 -- Analogous to privals, the discriminal generated for an entry index
6642 -- parameter acts as a weak declaration. Perform minimal decoration
6643 -- to avoid bogus errors.
6645 elsif Is_Discriminal (Def_Id)
6646 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
6648 Set_Scope (Def_Id, Current_Scope);
6651 -- In the body or private part of an instance, a type extension may
6652 -- introduce a component with the same name as that of an actual. The
6653 -- legality rule is not enforced, but the semantics of the full type
6654 -- with two components of same name are not clear at this point???
6656 elsif In_Instance_Not_Visible then
6659 -- When compiling a package body, some child units may have become
6660 -- visible. They cannot conflict with local entities that hide them.
6662 elsif Is_Child_Unit (E)
6663 and then In_Open_Scopes (Scope (E))
6664 and then not Is_Immediately_Visible (E)
6668 -- Conversely, with front-end inlining we may compile the parent body
6669 -- first, and a child unit subsequently. The context is now the
6670 -- parent spec, and body entities are not visible.
6672 elsif Is_Child_Unit (Def_Id)
6673 and then Is_Package_Body_Entity (E)
6674 and then not In_Package_Body (Current_Scope)
6678 -- Case of genuine duplicate declaration
6681 Error_Msg_Sloc := Sloc (E);
6683 -- If the previous declaration is an incomplete type declaration
6684 -- this may be an attempt to complete it with a private type. The
6685 -- following avoids confusing cascaded errors.
6687 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
6688 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
6691 ("incomplete type cannot be completed with a private " &
6692 "declaration", Parent (Def_Id));
6693 Set_Is_Immediately_Visible (E, False);
6694 Set_Full_View (E, Def_Id);
6696 -- An inherited component of a record conflicts with a new
6697 -- discriminant. The discriminant is inserted first in the scope,
6698 -- but the error should be posted on it, not on the component.
6700 elsif Ekind (E) = E_Discriminant
6701 and then Present (Scope (Def_Id))
6702 and then Scope (Def_Id) /= Current_Scope
6704 Error_Msg_Sloc := Sloc (Def_Id);
6705 Error_Msg_N ("& conflicts with declaration#", E);
6708 -- If the name of the unit appears in its own context clause, a
6709 -- dummy package with the name has already been created, and the
6710 -- error emitted. Try to continue quietly.
6712 elsif Error_Posted (E)
6713 and then Sloc (E) = No_Location
6714 and then Nkind (Parent (E)) = N_Package_Specification
6715 and then Current_Scope = Standard_Standard
6717 Set_Scope (Def_Id, Current_Scope);
6721 Error_Msg_N ("& conflicts with declaration#", Def_Id);
6723 -- Avoid cascaded messages with duplicate components in
6726 if Ekind_In (E, E_Component, E_Discriminant) then
6731 if Nkind (Parent (Parent (Def_Id))) =
6732 N_Generic_Subprogram_Declaration
6734 Defining_Entity (Specification (Parent (Parent (Def_Id))))
6736 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
6739 -- If entity is in standard, then we are in trouble, because it
6740 -- means that we have a library package with a duplicated name.
6741 -- That's hard to recover from, so abort.
6743 if S = Standard_Standard then
6744 raise Unrecoverable_Error;
6746 -- Otherwise we continue with the declaration. Having two
6747 -- identical declarations should not cause us too much trouble.
6755 -- If we fall through, declaration is OK, at least OK enough to continue
6757 -- If Def_Id is a discriminant or a record component we are in the midst
6758 -- of inheriting components in a derived record definition. Preserve
6759 -- their Ekind and Etype.
6761 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
6764 -- If a type is already set, leave it alone (happens when a type
6765 -- declaration is reanalyzed following a call to the optimizer).
6767 elsif Present (Etype (Def_Id)) then
6770 -- Otherwise, the kind E_Void insures that premature uses of the entity
6771 -- will be detected. Any_Type insures that no cascaded errors will occur
6774 Set_Ekind (Def_Id, E_Void);
6775 Set_Etype (Def_Id, Any_Type);
6778 -- Inherited discriminants and components in derived record types are
6779 -- immediately visible. Itypes are not.
6781 -- Unless the Itype is for a record type with a corresponding remote
6782 -- type (what is that about, it was not commented ???)
6784 if Ekind_In (Def_Id, E_Discriminant, E_Component)
6786 ((not Is_Record_Type (Def_Id)
6787 or else No (Corresponding_Remote_Type (Def_Id)))
6788 and then not Is_Itype (Def_Id))
6790 Set_Is_Immediately_Visible (Def_Id);
6791 Set_Current_Entity (Def_Id);
6794 Set_Homonym (Def_Id, C);
6795 Append_Entity (Def_Id, S);
6796 Set_Public_Status (Def_Id);
6798 -- Declaring a homonym is not allowed in SPARK ...
6800 if Present (C) and then Restriction_Check_Required (SPARK_05) then
6802 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
6803 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
6804 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
6807 -- ... unless the new declaration is in a subprogram, and the
6808 -- visible declaration is a variable declaration or a parameter
6809 -- specification outside that subprogram.
6811 if Present (Enclosing_Subp)
6812 and then Nkind_In (Parent (C), N_Object_Declaration,
6813 N_Parameter_Specification)
6814 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
6818 -- ... or the new declaration is in a package, and the visible
6819 -- declaration occurs outside that package.
6821 elsif Present (Enclosing_Pack)
6822 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
6826 -- ... or the new declaration is a component declaration in a
6827 -- record type definition.
6829 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
6832 -- Don't issue error for non-source entities
6834 elsif Comes_From_Source (Def_Id)
6835 and then Comes_From_Source (C)
6837 Error_Msg_Sloc := Sloc (C);
6838 Check_SPARK_05_Restriction
6839 ("redeclaration of identifier &#", Def_Id);
6844 -- Warn if new entity hides an old one
6846 if Warn_On_Hiding and then Present (C)
6848 -- Don't warn for record components since they always have a well
6849 -- defined scope which does not confuse other uses. Note that in
6850 -- some cases, Ekind has not been set yet.
6852 and then Ekind (C) /= E_Component
6853 and then Ekind (C) /= E_Discriminant
6854 and then Nkind (Parent (C)) /= N_Component_Declaration
6855 and then Ekind (Def_Id) /= E_Component
6856 and then Ekind (Def_Id) /= E_Discriminant
6857 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
6859 -- Don't warn for one character variables. It is too common to use
6860 -- such variables as locals and will just cause too many false hits.
6862 and then Length_Of_Name (Chars (C)) /= 1
6864 -- Don't warn for non-source entities
6866 and then Comes_From_Source (C)
6867 and then Comes_From_Source (Def_Id)
6869 -- Don't warn unless entity in question is in extended main source
6871 and then In_Extended_Main_Source_Unit (Def_Id)
6873 -- Finally, the hidden entity must be either immediately visible or
6874 -- use visible (i.e. from a used package).
6877 (Is_Immediately_Visible (C)
6879 Is_Potentially_Use_Visible (C))
6881 Error_Msg_Sloc := Sloc (C);
6882 Error_Msg_N ("declaration hides &#?h?", Def_Id);
6890 function Entity_Of (N : Node_Id) return Entity_Id is
6896 if Is_Entity_Name (N) then
6899 -- Follow a possible chain of renamings to reach the root renamed
6903 and then Is_Object (Id)
6904 and then Present (Renamed_Object (Id))
6906 if Is_Entity_Name (Renamed_Object (Id)) then
6907 Id := Entity (Renamed_Object (Id));
6918 --------------------------
6919 -- Explain_Limited_Type --
6920 --------------------------
6922 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
6926 -- For array, component type must be limited
6928 if Is_Array_Type (T) then
6929 Error_Msg_Node_2 := T;
6931 ("\component type& of type& is limited", N, Component_Type (T));
6932 Explain_Limited_Type (Component_Type (T), N);
6934 elsif Is_Record_Type (T) then
6936 -- No need for extra messages if explicit limited record
6938 if Is_Limited_Record (Base_Type (T)) then
6942 -- Otherwise find a limited component. Check only components that
6943 -- come from source, or inherited components that appear in the
6944 -- source of the ancestor.
6946 C := First_Component (T);
6947 while Present (C) loop
6948 if Is_Limited_Type (Etype (C))
6950 (Comes_From_Source (C)
6952 (Present (Original_Record_Component (C))
6954 Comes_From_Source (Original_Record_Component (C))))
6956 Error_Msg_Node_2 := T;
6957 Error_Msg_NE ("\component& of type& has limited type", N, C);
6958 Explain_Limited_Type (Etype (C), N);
6965 -- The type may be declared explicitly limited, even if no component
6966 -- of it is limited, in which case we fall out of the loop.
6969 end Explain_Limited_Type;
6971 ---------------------------------------
6972 -- Expression_Of_Expression_Function --
6973 ---------------------------------------
6975 function Expression_Of_Expression_Function
6976 (Subp : Entity_Id) return Node_Id
6978 Expr_Func : Node_Id;
6981 pragma Assert (Is_Expression_Function_Or_Completion (Subp));
6983 if Nkind (Original_Node (Subprogram_Spec (Subp))) =
6984 N_Expression_Function
6986 Expr_Func := Original_Node (Subprogram_Spec (Subp));
6988 elsif Nkind (Original_Node (Subprogram_Body (Subp))) =
6989 N_Expression_Function
6991 Expr_Func := Original_Node (Subprogram_Body (Subp));
6994 pragma Assert (False);
6998 return Original_Node (Expression (Expr_Func));
6999 end Expression_Of_Expression_Function;
7001 -------------------------------
7002 -- Extensions_Visible_Status --
7003 -------------------------------
7005 function Extensions_Visible_Status
7006 (Id : Entity_Id) return Extensions_Visible_Mode
7015 -- When a formal parameter is subject to Extensions_Visible, the pragma
7016 -- is stored in the contract of related subprogram.
7018 if Is_Formal (Id) then
7021 elsif Is_Subprogram_Or_Generic_Subprogram (Id) then
7024 -- No other construct carries this pragma
7027 return Extensions_Visible_None;
7030 Prag := Get_Pragma (Subp, Pragma_Extensions_Visible);
7032 -- In certain cases analysis may request the Extensions_Visible status
7033 -- of an expression function before the pragma has been analyzed yet.
7034 -- Inspect the declarative items after the expression function looking
7035 -- for the pragma (if any).
7037 if No (Prag) and then Is_Expression_Function (Subp) then
7038 Decl := Next (Unit_Declaration_Node (Subp));
7039 while Present (Decl) loop
7040 if Nkind (Decl) = N_Pragma
7041 and then Pragma_Name (Decl) = Name_Extensions_Visible
7046 -- A source construct ends the region where Extensions_Visible may
7047 -- appear, stop the traversal. An expanded expression function is
7048 -- no longer a source construct, but it must still be recognized.
7050 elsif Comes_From_Source (Decl)
7052 (Nkind_In (Decl, N_Subprogram_Body,
7053 N_Subprogram_Declaration)
7054 and then Is_Expression_Function (Defining_Entity (Decl)))
7063 -- Extract the value from the Boolean expression (if any)
7065 if Present (Prag) then
7066 Arg := First (Pragma_Argument_Associations (Prag));
7068 if Present (Arg) then
7069 Expr := Get_Pragma_Arg (Arg);
7071 -- When the associated subprogram is an expression function, the
7072 -- argument of the pragma may not have been analyzed.
7074 if not Analyzed (Expr) then
7075 Preanalyze_And_Resolve (Expr, Standard_Boolean);
7078 -- Guard against cascading errors when the argument of pragma
7079 -- Extensions_Visible is not a valid static Boolean expression.
7081 if Error_Posted (Expr) then
7082 return Extensions_Visible_None;
7084 elsif Is_True (Expr_Value (Expr)) then
7085 return Extensions_Visible_True;
7088 return Extensions_Visible_False;
7091 -- Otherwise the aspect or pragma defaults to True
7094 return Extensions_Visible_True;
7097 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
7098 -- directly specified. In SPARK code, its value defaults to "False".
7100 elsif SPARK_Mode = On then
7101 return Extensions_Visible_False;
7103 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
7107 return Extensions_Visible_True;
7109 end Extensions_Visible_Status;
7115 procedure Find_Actual
7117 Formal : out Entity_Id;
7120 Context : constant Node_Id := Parent (N);
7125 if Nkind_In (Context, N_Indexed_Component, N_Selected_Component)
7126 and then N = Prefix (Context)
7128 Find_Actual (Context, Formal, Call);
7131 elsif Nkind (Context) = N_Parameter_Association
7132 and then N = Explicit_Actual_Parameter (Context)
7134 Call := Parent (Context);
7136 elsif Nkind_In (Context, N_Entry_Call_Statement,
7138 N_Procedure_Call_Statement)
7148 -- If we have a call to a subprogram look for the parameter. Note that
7149 -- we exclude overloaded calls, since we don't know enough to be sure
7150 -- of giving the right answer in this case.
7152 if Nkind_In (Call, N_Entry_Call_Statement,
7154 N_Procedure_Call_Statement)
7156 Call_Nam := Name (Call);
7158 -- A call to a protected or task entry appears as a selected
7159 -- component rather than an expanded name.
7161 if Nkind (Call_Nam) = N_Selected_Component then
7162 Call_Nam := Selector_Name (Call_Nam);
7165 if Is_Entity_Name (Call_Nam)
7166 and then Present (Entity (Call_Nam))
7167 and then Is_Overloadable (Entity (Call_Nam))
7168 and then not Is_Overloaded (Call_Nam)
7170 -- If node is name in call it is not an actual
7172 if N = Call_Nam then
7178 -- Fall here if we are definitely a parameter
7180 Actual := First_Actual (Call);
7181 Formal := First_Formal (Entity (Call_Nam));
7182 while Present (Formal) and then Present (Actual) loop
7186 -- An actual that is the prefix in a prefixed call may have
7187 -- been rewritten in the call, after the deferred reference
7188 -- was collected. Check if sloc and kinds and names match.
7190 elsif Sloc (Actual) = Sloc (N)
7191 and then Nkind (Actual) = N_Identifier
7192 and then Nkind (Actual) = Nkind (N)
7193 and then Chars (Actual) = Chars (N)
7198 Actual := Next_Actual (Actual);
7199 Formal := Next_Formal (Formal);
7205 -- Fall through here if we did not find matching actual
7211 ---------------------------
7212 -- Find_Body_Discriminal --
7213 ---------------------------
7215 function Find_Body_Discriminal
7216 (Spec_Discriminant : Entity_Id) return Entity_Id
7222 -- If expansion is suppressed, then the scope can be the concurrent type
7223 -- itself rather than a corresponding concurrent record type.
7225 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
7226 Tsk := Scope (Spec_Discriminant);
7229 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
7231 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
7234 -- Find discriminant of original concurrent type, and use its current
7235 -- discriminal, which is the renaming within the task/protected body.
7237 Disc := First_Discriminant (Tsk);
7238 while Present (Disc) loop
7239 if Chars (Disc) = Chars (Spec_Discriminant) then
7240 return Discriminal (Disc);
7243 Next_Discriminant (Disc);
7246 -- That loop should always succeed in finding a matching entry and
7247 -- returning. Fatal error if not.
7249 raise Program_Error;
7250 end Find_Body_Discriminal;
7252 -------------------------------------
7253 -- Find_Corresponding_Discriminant --
7254 -------------------------------------
7256 function Find_Corresponding_Discriminant
7258 Typ : Entity_Id) return Entity_Id
7260 Par_Disc : Entity_Id;
7261 Old_Disc : Entity_Id;
7262 New_Disc : Entity_Id;
7265 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
7267 -- The original type may currently be private, and the discriminant
7268 -- only appear on its full view.
7270 if Is_Private_Type (Scope (Par_Disc))
7271 and then not Has_Discriminants (Scope (Par_Disc))
7272 and then Present (Full_View (Scope (Par_Disc)))
7274 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
7276 Old_Disc := First_Discriminant (Scope (Par_Disc));
7279 if Is_Class_Wide_Type (Typ) then
7280 New_Disc := First_Discriminant (Root_Type (Typ));
7282 New_Disc := First_Discriminant (Typ);
7285 while Present (Old_Disc) and then Present (New_Disc) loop
7286 if Old_Disc = Par_Disc then
7290 Next_Discriminant (Old_Disc);
7291 Next_Discriminant (New_Disc);
7294 -- Should always find it
7296 raise Program_Error;
7297 end Find_Corresponding_Discriminant;
7299 ----------------------------------
7300 -- Find_Enclosing_Iterator_Loop --
7301 ----------------------------------
7303 function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id is
7308 -- Traverse the scope chain looking for an iterator loop. Such loops are
7309 -- usually transformed into blocks, hence the use of Original_Node.
7312 while Present (S) and then S /= Standard_Standard loop
7313 if Ekind (S) = E_Loop
7314 and then Nkind (Parent (S)) = N_Implicit_Label_Declaration
7316 Constr := Original_Node (Label_Construct (Parent (S)));
7318 if Nkind (Constr) = N_Loop_Statement
7319 and then Present (Iteration_Scheme (Constr))
7320 and then Nkind (Iterator_Specification
7321 (Iteration_Scheme (Constr))) =
7322 N_Iterator_Specification
7332 end Find_Enclosing_Iterator_Loop;
7334 ------------------------------------
7335 -- Find_Loop_In_Conditional_Block --
7336 ------------------------------------
7338 function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is
7344 if Nkind (Stmt) = N_If_Statement then
7345 Stmt := First (Then_Statements (Stmt));
7348 pragma Assert (Nkind (Stmt) = N_Block_Statement);
7350 -- Inspect the statements of the conditional block. In general the loop
7351 -- should be the first statement in the statement sequence of the block,
7352 -- but the finalization machinery may have introduced extra object
7355 Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
7356 while Present (Stmt) loop
7357 if Nkind (Stmt) = N_Loop_Statement then
7364 -- The expansion of attribute 'Loop_Entry produced a malformed block
7366 raise Program_Error;
7367 end Find_Loop_In_Conditional_Block;
7369 --------------------------
7370 -- Find_Overlaid_Entity --
7371 --------------------------
7373 procedure Find_Overlaid_Entity
7375 Ent : out Entity_Id;
7381 -- We are looking for one of the two following forms:
7383 -- for X'Address use Y'Address
7387 -- Const : constant Address := expr;
7389 -- for X'Address use Const;
7391 -- In the second case, the expr is either Y'Address, or recursively a
7392 -- constant that eventually references Y'Address.
7397 if Nkind (N) = N_Attribute_Definition_Clause
7398 and then Chars (N) = Name_Address
7400 Expr := Expression (N);
7402 -- This loop checks the form of the expression for Y'Address,
7403 -- using recursion to deal with intermediate constants.
7406 -- Check for Y'Address
7408 if Nkind (Expr) = N_Attribute_Reference
7409 and then Attribute_Name (Expr) = Name_Address
7411 Expr := Prefix (Expr);
7414 -- Check for Const where Const is a constant entity
7416 elsif Is_Entity_Name (Expr)
7417 and then Ekind (Entity (Expr)) = E_Constant
7419 Expr := Constant_Value (Entity (Expr));
7421 -- Anything else does not need checking
7428 -- This loop checks the form of the prefix for an entity, using
7429 -- recursion to deal with intermediate components.
7432 -- Check for Y where Y is an entity
7434 if Is_Entity_Name (Expr) then
7435 Ent := Entity (Expr);
7438 -- Check for components
7441 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component)
7443 Expr := Prefix (Expr);
7446 -- Anything else does not need checking
7453 end Find_Overlaid_Entity;
7455 -------------------------
7456 -- Find_Parameter_Type --
7457 -------------------------
7459 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
7461 if Nkind (Param) /= N_Parameter_Specification then
7464 -- For an access parameter, obtain the type from the formal entity
7465 -- itself, because access to subprogram nodes do not carry a type.
7466 -- Shouldn't we always use the formal entity ???
7468 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
7469 return Etype (Defining_Identifier (Param));
7472 return Etype (Parameter_Type (Param));
7474 end Find_Parameter_Type;
7476 -----------------------------------
7477 -- Find_Placement_In_State_Space --
7478 -----------------------------------
7480 procedure Find_Placement_In_State_Space
7481 (Item_Id : Entity_Id;
7482 Placement : out State_Space_Kind;
7483 Pack_Id : out Entity_Id)
7485 Context : Entity_Id;
7488 -- Assume that the item does not appear in the state space of a package
7490 Placement := Not_In_Package;
7493 -- Climb the scope stack and examine the enclosing context
7495 Context := Scope (Item_Id);
7496 while Present (Context) and then Context /= Standard_Standard loop
7497 if Ekind (Context) = E_Package then
7500 -- A package body is a cut off point for the traversal as the item
7501 -- cannot be visible to the outside from this point on. Note that
7502 -- this test must be done first as a body is also classified as a
7505 if In_Package_Body (Context) then
7506 Placement := Body_State_Space;
7509 -- The private part of a package is a cut off point for the
7510 -- traversal as the item cannot be visible to the outside from
7513 elsif In_Private_Part (Context) then
7514 Placement := Private_State_Space;
7517 -- When the item appears in the visible state space of a package,
7518 -- continue to climb the scope stack as this may not be the final
7522 Placement := Visible_State_Space;
7524 -- The visible state space of a child unit acts as the proper
7525 -- placement of an item.
7527 if Is_Child_Unit (Context) then
7532 -- The item or its enclosing package appear in a construct that has
7536 Placement := Not_In_Package;
7540 Context := Scope (Context);
7542 end Find_Placement_In_State_Space;
7544 ------------------------
7545 -- Find_Specific_Type --
7546 ------------------------
7548 function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
7549 Typ : Entity_Id := Root_Type (CW);
7552 if Ekind (Typ) = E_Incomplete_Type then
7553 if From_Limited_With (Typ) then
7554 Typ := Non_Limited_View (Typ);
7556 Typ := Full_View (Typ);
7560 if Is_Private_Type (Typ)
7561 and then not Is_Tagged_Type (Typ)
7562 and then Present (Full_View (Typ))
7564 return Full_View (Typ);
7568 end Find_Specific_Type;
7570 -----------------------------
7571 -- Find_Static_Alternative --
7572 -----------------------------
7574 function Find_Static_Alternative (N : Node_Id) return Node_Id is
7575 Expr : constant Node_Id := Expression (N);
7576 Val : constant Uint := Expr_Value (Expr);
7581 Alt := First (Alternatives (N));
7584 if Nkind (Alt) /= N_Pragma then
7585 Choice := First (Discrete_Choices (Alt));
7586 while Present (Choice) loop
7588 -- Others choice, always matches
7590 if Nkind (Choice) = N_Others_Choice then
7593 -- Range, check if value is in the range
7595 elsif Nkind (Choice) = N_Range then
7597 Val >= Expr_Value (Low_Bound (Choice))
7599 Val <= Expr_Value (High_Bound (Choice));
7601 -- Choice is a subtype name. Note that we know it must
7602 -- be a static subtype, since otherwise it would have
7603 -- been diagnosed as illegal.
7605 elsif Is_Entity_Name (Choice)
7606 and then Is_Type (Entity (Choice))
7608 exit Search when Is_In_Range (Expr, Etype (Choice),
7609 Assume_Valid => False);
7611 -- Choice is a subtype indication
7613 elsif Nkind (Choice) = N_Subtype_Indication then
7615 C : constant Node_Id := Constraint (Choice);
7616 R : constant Node_Id := Range_Expression (C);
7620 Val >= Expr_Value (Low_Bound (R))
7622 Val <= Expr_Value (High_Bound (R));
7625 -- Choice is a simple expression
7628 exit Search when Val = Expr_Value (Choice);
7636 pragma Assert (Present (Alt));
7639 -- The above loop *must* terminate by finding a match, since we know the
7640 -- case statement is valid, and the value of the expression is known at
7641 -- compile time. When we fall out of the loop, Alt points to the
7642 -- alternative that we know will be selected at run time.
7645 end Find_Static_Alternative;
7651 function First_Actual (Node : Node_Id) return Node_Id is
7655 if No (Parameter_Associations (Node)) then
7659 N := First (Parameter_Associations (Node));
7661 if Nkind (N) = N_Parameter_Association then
7662 return First_Named_Actual (Node);
7672 function Fix_Msg (Id : Entity_Id; Msg : String) return String is
7673 Is_Task : constant Boolean :=
7674 Ekind_In (Id, E_Task_Body, E_Task_Type)
7675 or else Is_Single_Task_Object (Id);
7676 Msg_Last : constant Natural := Msg'Last;
7677 Msg_Index : Natural;
7678 Res : String (Msg'Range) := (others => ' ');
7679 Res_Index : Natural;
7682 -- Copy all characters from the input message Msg to result Res with
7683 -- suitable replacements.
7685 Msg_Index := Msg'First;
7686 Res_Index := Res'First;
7687 while Msg_Index <= Msg_Last loop
7689 -- Replace "subprogram" with a different word
7691 if Msg_Index <= Msg_Last - 10
7692 and then Msg (Msg_Index .. Msg_Index + 9) = "subprogram"
7694 if Ekind_In (Id, E_Entry, E_Entry_Family) then
7695 Res (Res_Index .. Res_Index + 4) := "entry";
7696 Res_Index := Res_Index + 5;
7699 Res (Res_Index .. Res_Index + 8) := "task type";
7700 Res_Index := Res_Index + 9;
7703 Res (Res_Index .. Res_Index + 9) := "subprogram";
7704 Res_Index := Res_Index + 10;
7707 Msg_Index := Msg_Index + 10;
7709 -- Replace "protected" with a different word
7711 elsif Msg_Index <= Msg_Last - 9
7712 and then Msg (Msg_Index .. Msg_Index + 8) = "protected"
7715 Res (Res_Index .. Res_Index + 3) := "task";
7716 Res_Index := Res_Index + 4;
7717 Msg_Index := Msg_Index + 9;
7719 -- Otherwise copy the character
7722 Res (Res_Index) := Msg (Msg_Index);
7723 Msg_Index := Msg_Index + 1;
7724 Res_Index := Res_Index + 1;
7728 return Res (Res'First .. Res_Index - 1);
7731 -------------------------
7732 -- From_Nested_Package --
7733 -------------------------
7735 function From_Nested_Package (T : Entity_Id) return Boolean is
7736 Pack : constant Entity_Id := Scope (T);
7740 Ekind (Pack) = E_Package
7741 and then not Is_Frozen (Pack)
7742 and then not Scope_Within_Or_Same (Current_Scope, Pack)
7743 and then In_Open_Scopes (Scope (Pack));
7744 end From_Nested_Package;
7746 -----------------------
7747 -- Gather_Components --
7748 -----------------------
7750 procedure Gather_Components
7752 Comp_List : Node_Id;
7753 Governed_By : List_Id;
7755 Report_Errors : out Boolean)
7759 Discrete_Choice : Node_Id;
7760 Comp_Item : Node_Id;
7762 Discrim : Entity_Id;
7763 Discrim_Name : Node_Id;
7764 Discrim_Value : Node_Id;
7767 Report_Errors := False;
7769 if No (Comp_List) or else Null_Present (Comp_List) then
7772 elsif Present (Component_Items (Comp_List)) then
7773 Comp_Item := First (Component_Items (Comp_List));
7779 while Present (Comp_Item) loop
7781 -- Skip the tag of a tagged record, the interface tags, as well
7782 -- as all items that are not user components (anonymous types,
7783 -- rep clauses, Parent field, controller field).
7785 if Nkind (Comp_Item) = N_Component_Declaration then
7787 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
7789 if not Is_Tag (Comp) and then Chars (Comp) /= Name_uParent then
7790 Append_Elmt (Comp, Into);
7798 if No (Variant_Part (Comp_List)) then
7801 Discrim_Name := Name (Variant_Part (Comp_List));
7802 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
7805 -- Look for the discriminant that governs this variant part.
7806 -- The discriminant *must* be in the Governed_By List
7808 Assoc := First (Governed_By);
7809 Find_Constraint : loop
7810 Discrim := First (Choices (Assoc));
7811 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
7812 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
7814 Chars (Corresponding_Discriminant (Entity (Discrim))) =
7815 Chars (Discrim_Name))
7816 or else Chars (Original_Record_Component (Entity (Discrim)))
7817 = Chars (Discrim_Name);
7819 if No (Next (Assoc)) then
7820 if not Is_Constrained (Typ)
7821 and then Is_Derived_Type (Typ)
7822 and then Present (Stored_Constraint (Typ))
7824 -- If the type is a tagged type with inherited discriminants,
7825 -- use the stored constraint on the parent in order to find
7826 -- the values of discriminants that are otherwise hidden by an
7827 -- explicit constraint. Renamed discriminants are handled in
7830 -- If several parent discriminants are renamed by a single
7831 -- discriminant of the derived type, the call to obtain the
7832 -- Corresponding_Discriminant field only retrieves the last
7833 -- of them. We recover the constraint on the others from the
7834 -- Stored_Constraint as well.
7841 D := First_Discriminant (Etype (Typ));
7842 C := First_Elmt (Stored_Constraint (Typ));
7843 while Present (D) and then Present (C) loop
7844 if Chars (Discrim_Name) = Chars (D) then
7845 if Is_Entity_Name (Node (C))
7846 and then Entity (Node (C)) = Entity (Discrim)
7848 -- D is renamed by Discrim, whose value is given in
7855 Make_Component_Association (Sloc (Typ),
7857 (New_Occurrence_Of (D, Sloc (Typ))),
7858 Duplicate_Subexpr_No_Checks (Node (C)));
7860 exit Find_Constraint;
7863 Next_Discriminant (D);
7870 if No (Next (Assoc)) then
7871 Error_Msg_NE (" missing value for discriminant&",
7872 First (Governed_By), Discrim_Name);
7873 Report_Errors := True;
7878 end loop Find_Constraint;
7880 Discrim_Value := Expression (Assoc);
7882 if not Is_OK_Static_Expression (Discrim_Value) then
7884 -- If the variant part is governed by a discriminant of the type
7885 -- this is an error. If the variant part and the discriminant are
7886 -- inherited from an ancestor this is legal (AI05-120) unless the
7887 -- components are being gathered for an aggregate, in which case
7888 -- the caller must check Report_Errors.
7890 if Scope (Original_Record_Component
7891 ((Entity (First (Choices (Assoc)))))) = Typ
7894 ("value for discriminant & must be static!",
7895 Discrim_Value, Discrim);
7896 Why_Not_Static (Discrim_Value);
7899 Report_Errors := True;
7903 Search_For_Discriminant_Value : declare
7909 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
7912 Find_Discrete_Value : while Present (Variant) loop
7913 Discrete_Choice := First (Discrete_Choices (Variant));
7914 while Present (Discrete_Choice) loop
7915 exit Find_Discrete_Value when
7916 Nkind (Discrete_Choice) = N_Others_Choice;
7918 Get_Index_Bounds (Discrete_Choice, Low, High);
7920 UI_Low := Expr_Value (Low);
7921 UI_High := Expr_Value (High);
7923 exit Find_Discrete_Value when
7924 UI_Low <= UI_Discrim_Value
7926 UI_High >= UI_Discrim_Value;
7928 Next (Discrete_Choice);
7931 Next_Non_Pragma (Variant);
7932 end loop Find_Discrete_Value;
7933 end Search_For_Discriminant_Value;
7935 -- The case statement must include a variant that corresponds to the
7936 -- value of the discriminant, unless the discriminant type has a
7937 -- static predicate. In that case the absence of an others_choice that
7938 -- would cover this value becomes a run-time error (3.8,1 (21.1/2)).
7941 and then not Has_Static_Predicate (Etype (Discrim_Name))
7944 ("value of discriminant & is out of range", Discrim_Value, Discrim);
7945 Report_Errors := True;
7949 -- If we have found the corresponding choice, recursively add its
7950 -- components to the Into list. The nested components are part of
7951 -- the same record type.
7953 if Present (Variant) then
7955 (Typ, Component_List (Variant), Governed_By, Into, Report_Errors);
7957 end Gather_Components;
7959 ------------------------
7960 -- Get_Actual_Subtype --
7961 ------------------------
7963 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
7964 Typ : constant Entity_Id := Etype (N);
7965 Utyp : Entity_Id := Underlying_Type (Typ);
7974 -- If what we have is an identifier that references a subprogram
7975 -- formal, or a variable or constant object, then we get the actual
7976 -- subtype from the referenced entity if one has been built.
7978 if Nkind (N) = N_Identifier
7980 (Is_Formal (Entity (N))
7981 or else Ekind (Entity (N)) = E_Constant
7982 or else Ekind (Entity (N)) = E_Variable)
7983 and then Present (Actual_Subtype (Entity (N)))
7985 return Actual_Subtype (Entity (N));
7987 -- Actual subtype of unchecked union is always itself. We never need
7988 -- the "real" actual subtype. If we did, we couldn't get it anyway
7989 -- because the discriminant is not available. The restrictions on
7990 -- Unchecked_Union are designed to make sure that this is OK.
7992 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
7995 -- Here for the unconstrained case, we must find actual subtype
7996 -- No actual subtype is available, so we must build it on the fly.
7998 -- Checking the type, not the underlying type, for constrainedness
7999 -- seems to be necessary. Maybe all the tests should be on the type???
8001 elsif (not Is_Constrained (Typ))
8002 and then (Is_Array_Type (Utyp)
8003 or else (Is_Record_Type (Utyp)
8004 and then Has_Discriminants (Utyp)))
8005 and then not Has_Unknown_Discriminants (Utyp)
8006 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
8008 -- Nothing to do if in spec expression (why not???)
8010 if In_Spec_Expression then
8013 elsif Is_Private_Type (Typ) and then not Has_Discriminants (Typ) then
8015 -- If the type has no discriminants, there is no subtype to
8016 -- build, even if the underlying type is discriminated.
8020 -- Else build the actual subtype
8023 Decl := Build_Actual_Subtype (Typ, N);
8024 Atyp := Defining_Identifier (Decl);
8026 -- If Build_Actual_Subtype generated a new declaration then use it
8030 -- The actual subtype is an Itype, so analyze the declaration,
8031 -- but do not attach it to the tree, to get the type defined.
8033 Set_Parent (Decl, N);
8034 Set_Is_Itype (Atyp);
8035 Analyze (Decl, Suppress => All_Checks);
8036 Set_Associated_Node_For_Itype (Atyp, N);
8037 Set_Has_Delayed_Freeze (Atyp, False);
8039 -- We need to freeze the actual subtype immediately. This is
8040 -- needed, because otherwise this Itype will not get frozen
8041 -- at all, and it is always safe to freeze on creation because
8042 -- any associated types must be frozen at this point.
8044 Freeze_Itype (Atyp, N);
8047 -- Otherwise we did not build a declaration, so return original
8054 -- For all remaining cases, the actual subtype is the same as
8055 -- the nominal type.
8060 end Get_Actual_Subtype;
8062 -------------------------------------
8063 -- Get_Actual_Subtype_If_Available --
8064 -------------------------------------
8066 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
8067 Typ : constant Entity_Id := Etype (N);
8070 -- If what we have is an identifier that references a subprogram
8071 -- formal, or a variable or constant object, then we get the actual
8072 -- subtype from the referenced entity if one has been built.
8074 if Nkind (N) = N_Identifier
8076 (Is_Formal (Entity (N))
8077 or else Ekind (Entity (N)) = E_Constant
8078 or else Ekind (Entity (N)) = E_Variable)
8079 and then Present (Actual_Subtype (Entity (N)))
8081 return Actual_Subtype (Entity (N));
8083 -- Otherwise the Etype of N is returned unchanged
8088 end Get_Actual_Subtype_If_Available;
8090 ------------------------
8091 -- Get_Body_From_Stub --
8092 ------------------------
8094 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
8096 return Proper_Body (Unit (Library_Unit (N)));
8097 end Get_Body_From_Stub;
8099 ---------------------
8100 -- Get_Cursor_Type --
8101 ---------------------
8103 function Get_Cursor_Type
8105 Typ : Entity_Id) return Entity_Id
8109 First_Op : Entity_Id;
8113 -- If error already detected, return
8115 if Error_Posted (Aspect) then
8119 -- The cursor type for an Iterable aspect is the return type of a
8120 -- non-overloaded First primitive operation. Locate association for
8123 Assoc := First (Component_Associations (Expression (Aspect)));
8125 while Present (Assoc) loop
8126 if Chars (First (Choices (Assoc))) = Name_First then
8127 First_Op := Expression (Assoc);
8134 if First_Op = Any_Id then
8135 Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
8141 -- Locate function with desired name and profile in scope of type
8142 -- In the rare case where the type is an integer type, a base type
8143 -- is created for it, check that the base type of the first formal
8144 -- of First matches the base type of the domain.
8146 Func := First_Entity (Scope (Typ));
8147 while Present (Func) loop
8148 if Chars (Func) = Chars (First_Op)
8149 and then Ekind (Func) = E_Function
8150 and then Present (First_Formal (Func))
8151 and then Base_Type (Etype (First_Formal (Func))) = Base_Type (Typ)
8152 and then No (Next_Formal (First_Formal (Func)))
8154 if Cursor /= Any_Type then
8156 ("Operation First for iterable type must be unique", Aspect);
8159 Cursor := Etype (Func);
8166 -- If not found, no way to resolve remaining primitives.
8168 if Cursor = Any_Type then
8170 ("No legal primitive operation First for Iterable type", Aspect);
8174 end Get_Cursor_Type;
8176 function Get_Cursor_Type (Typ : Entity_Id) return Entity_Id is
8178 return Etype (Get_Iterable_Type_Primitive (Typ, Name_First));
8179 end Get_Cursor_Type;
8181 -------------------------------
8182 -- Get_Default_External_Name --
8183 -------------------------------
8185 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
8187 Get_Decoded_Name_String (Chars (E));
8189 if Opt.External_Name_Imp_Casing = Uppercase then
8190 Set_Casing (All_Upper_Case);
8192 Set_Casing (All_Lower_Case);
8196 Make_String_Literal (Sloc (E),
8197 Strval => String_From_Name_Buffer);
8198 end Get_Default_External_Name;
8200 --------------------------
8201 -- Get_Enclosing_Object --
8202 --------------------------
8204 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
8206 if Is_Entity_Name (N) then
8210 when N_Indexed_Component
8211 | N_Selected_Component
8214 -- If not generating code, a dereference may be left implicit.
8215 -- In thoses cases, return Empty.
8217 if Is_Access_Type (Etype (Prefix (N))) then
8220 return Get_Enclosing_Object (Prefix (N));
8223 when N_Type_Conversion =>
8224 return Get_Enclosing_Object (Expression (N));
8230 end Get_Enclosing_Object;
8232 ---------------------------
8233 -- Get_Enum_Lit_From_Pos --
8234 ---------------------------
8236 function Get_Enum_Lit_From_Pos
8239 Loc : Source_Ptr) return Node_Id
8241 Btyp : Entity_Id := Base_Type (T);
8246 -- In the case where the literal is of type Character, Wide_Character
8247 -- or Wide_Wide_Character or of a type derived from them, there needs
8248 -- to be some special handling since there is no explicit chain of
8249 -- literals to search. Instead, an N_Character_Literal node is created
8250 -- with the appropriate Char_Code and Chars fields.
8252 if Is_Standard_Character_Type (T) then
8253 Set_Character_Literal_Name (UI_To_CC (Pos));
8256 Make_Character_Literal (Loc,
8258 Char_Literal_Value => Pos);
8260 -- For all other cases, we have a complete table of literals, and
8261 -- we simply iterate through the chain of literal until the one
8262 -- with the desired position value is found.
8265 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
8266 Btyp := Full_View (Btyp);
8269 Lit := First_Literal (Btyp);
8270 for J in 1 .. UI_To_Int (Pos) loop
8273 -- If Lit is Empty, Pos is not in range, so raise Constraint_Error
8274 -- inside the loop to avoid calling Next_Literal on Empty.
8277 raise Constraint_Error;
8281 -- Create a new node from Lit, with source location provided by Loc
8282 -- if not equal to No_Location, or by copying the source location of
8287 if LLoc = No_Location then
8291 return New_Occurrence_Of (Lit, LLoc);
8293 end Get_Enum_Lit_From_Pos;
8295 ------------------------
8296 -- Get_Generic_Entity --
8297 ------------------------
8299 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
8300 Ent : constant Entity_Id := Entity (Name (N));
8302 if Present (Renamed_Object (Ent)) then
8303 return Renamed_Object (Ent);
8307 end Get_Generic_Entity;
8309 -------------------------------------
8310 -- Get_Incomplete_View_Of_Ancestor --
8311 -------------------------------------
8313 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
8314 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
8315 Par_Scope : Entity_Id;
8316 Par_Type : Entity_Id;
8319 -- The incomplete view of an ancestor is only relevant for private
8320 -- derived types in child units.
8322 if not Is_Derived_Type (E)
8323 or else not Is_Child_Unit (Cur_Unit)
8328 Par_Scope := Scope (Cur_Unit);
8329 if No (Par_Scope) then
8333 Par_Type := Etype (Base_Type (E));
8335 -- Traverse list of ancestor types until we find one declared in
8336 -- a parent or grandparent unit (two levels seem sufficient).
8338 while Present (Par_Type) loop
8339 if Scope (Par_Type) = Par_Scope
8340 or else Scope (Par_Type) = Scope (Par_Scope)
8344 elsif not Is_Derived_Type (Par_Type) then
8348 Par_Type := Etype (Base_Type (Par_Type));
8352 -- If none found, there is no relevant ancestor type.
8356 end Get_Incomplete_View_Of_Ancestor;
8358 ----------------------
8359 -- Get_Index_Bounds --
8360 ----------------------
8362 procedure Get_Index_Bounds
8366 Use_Full_View : Boolean := False)
8368 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id;
8369 -- Obtain the scalar range of type Typ. If flag Use_Full_View is set and
8370 -- Typ qualifies, the scalar range is obtained from the full view of the
8373 --------------------------
8374 -- Scalar_Range_Of_Type --
8375 --------------------------
8377 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id is
8378 T : Entity_Id := Typ;
8381 if Use_Full_View and then Present (Full_View (T)) then
8385 return Scalar_Range (T);
8386 end Scalar_Range_Of_Type;
8390 Kind : constant Node_Kind := Nkind (N);
8393 -- Start of processing for Get_Index_Bounds
8396 if Kind = N_Range then
8398 H := High_Bound (N);
8400 elsif Kind = N_Subtype_Indication then
8401 Rng := Range_Expression (Constraint (N));
8409 L := Low_Bound (Range_Expression (Constraint (N)));
8410 H := High_Bound (Range_Expression (Constraint (N)));
8413 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
8414 Rng := Scalar_Range_Of_Type (Entity (N));
8416 if Error_Posted (Rng) then
8420 elsif Nkind (Rng) = N_Subtype_Indication then
8421 Get_Index_Bounds (Rng, L, H);
8424 L := Low_Bound (Rng);
8425 H := High_Bound (Rng);
8429 -- N is an expression, indicating a range with one value
8434 end Get_Index_Bounds;
8436 -----------------------------
8437 -- Get_Interfacing_Aspects --
8438 -----------------------------
8440 procedure Get_Interfacing_Aspects
8441 (Iface_Asp : Node_Id;
8442 Conv_Asp : out Node_Id;
8443 EN_Asp : out Node_Id;
8444 Expo_Asp : out Node_Id;
8445 Imp_Asp : out Node_Id;
8446 LN_Asp : out Node_Id;
8447 Do_Checks : Boolean := False)
8449 procedure Save_Or_Duplication_Error
8451 To : in out Node_Id);
8452 -- Save the value of aspect Asp in node To. If To already has a value,
8453 -- then this is considered a duplicate use of aspect. Emit an error if
8454 -- flag Do_Checks is set.
8456 -------------------------------
8457 -- Save_Or_Duplication_Error --
8458 -------------------------------
8460 procedure Save_Or_Duplication_Error
8462 To : in out Node_Id)
8465 -- Detect an extra aspect and issue an error
8467 if Present (To) then
8469 Error_Msg_Name_1 := Chars (Identifier (Asp));
8470 Error_Msg_Sloc := Sloc (To);
8471 Error_Msg_N ("aspect % previously given #", Asp);
8474 -- Otherwise capture the aspect
8479 end Save_Or_Duplication_Error;
8486 -- The following variables capture each individual aspect
8488 Conv : Node_Id := Empty;
8489 EN : Node_Id := Empty;
8490 Expo : Node_Id := Empty;
8491 Imp : Node_Id := Empty;
8492 LN : Node_Id := Empty;
8494 -- Start of processing for Get_Interfacing_Aspects
8497 -- The input interfacing aspect should reside in an aspect specification
8500 pragma Assert (Is_List_Member (Iface_Asp));
8502 -- Examine the aspect specifications of the related entity. Find and
8503 -- capture all interfacing aspects. Detect duplicates and emit errors
8506 Asp := First (List_Containing (Iface_Asp));
8507 while Present (Asp) loop
8508 Asp_Id := Get_Aspect_Id (Asp);
8510 if Asp_Id = Aspect_Convention then
8511 Save_Or_Duplication_Error (Asp, Conv);
8513 elsif Asp_Id = Aspect_External_Name then
8514 Save_Or_Duplication_Error (Asp, EN);
8516 elsif Asp_Id = Aspect_Export then
8517 Save_Or_Duplication_Error (Asp, Expo);
8519 elsif Asp_Id = Aspect_Import then
8520 Save_Or_Duplication_Error (Asp, Imp);
8522 elsif Asp_Id = Aspect_Link_Name then
8523 Save_Or_Duplication_Error (Asp, LN);
8534 end Get_Interfacing_Aspects;
8536 ---------------------------------
8537 -- Get_Iterable_Type_Primitive --
8538 ---------------------------------
8540 function Get_Iterable_Type_Primitive
8542 Nam : Name_Id) return Entity_Id
8544 Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
8552 Assoc := First (Component_Associations (Funcs));
8553 while Present (Assoc) loop
8554 if Chars (First (Choices (Assoc))) = Nam then
8555 return Entity (Expression (Assoc));
8558 Assoc := Next (Assoc);
8563 end Get_Iterable_Type_Primitive;
8565 ----------------------------------
8566 -- Get_Library_Unit_Name_string --
8567 ----------------------------------
8569 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
8570 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
8573 Get_Unit_Name_String (Unit_Name_Id);
8575 -- Remove seven last character (" (spec)" or " (body)")
8577 Name_Len := Name_Len - 7;
8578 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
8579 end Get_Library_Unit_Name_String;
8581 --------------------------
8582 -- Get_Max_Queue_Length --
8583 --------------------------
8585 function Get_Max_Queue_Length (Id : Entity_Id) return Uint is
8586 pragma Assert (Is_Entry (Id));
8587 Prag : constant Entity_Id := Get_Pragma (Id, Pragma_Max_Queue_Length);
8590 -- A value of 0 represents no maximum specified, and entries and entry
8591 -- families with no Max_Queue_Length aspect or pragma default to it.
8593 if not Present (Prag) then
8597 return Intval (Expression (First (Pragma_Argument_Associations (Prag))));
8598 end Get_Max_Queue_Length;
8600 ------------------------
8601 -- Get_Name_Entity_Id --
8602 ------------------------
8604 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
8606 return Entity_Id (Get_Name_Table_Int (Id));
8607 end Get_Name_Entity_Id;
8609 ------------------------------
8610 -- Get_Name_From_CTC_Pragma --
8611 ------------------------------
8613 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
8614 Arg : constant Node_Id :=
8615 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
8617 return Strval (Expr_Value_S (Arg));
8618 end Get_Name_From_CTC_Pragma;
8620 -----------------------
8621 -- Get_Parent_Entity --
8622 -----------------------
8624 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
8626 if Nkind (Unit) = N_Package_Body
8627 and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
8629 return Defining_Entity
8630 (Specification (Instance_Spec (Original_Node (Unit))));
8631 elsif Nkind (Unit) = N_Package_Instantiation then
8632 return Defining_Entity (Specification (Instance_Spec (Unit)));
8634 return Defining_Entity (Unit);
8636 end Get_Parent_Entity;
8642 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
8644 return Get_Pragma_Id (Pragma_Name_Unmapped (N));
8647 ------------------------
8648 -- Get_Qualified_Name --
8649 ------------------------
8651 function Get_Qualified_Name
8653 Suffix : Entity_Id := Empty) return Name_Id
8655 Suffix_Nam : Name_Id := No_Name;
8658 if Present (Suffix) then
8659 Suffix_Nam := Chars (Suffix);
8662 return Get_Qualified_Name (Chars (Id), Suffix_Nam, Scope (Id));
8663 end Get_Qualified_Name;
8665 function Get_Qualified_Name
8667 Suffix : Name_Id := No_Name;
8668 Scop : Entity_Id := Current_Scope) return Name_Id
8670 procedure Add_Scope (S : Entity_Id);
8671 -- Add the fully qualified form of scope S to the name buffer. The
8679 procedure Add_Scope (S : Entity_Id) is
8684 elsif S = Standard_Standard then
8688 Add_Scope (Scope (S));
8689 Get_Name_String_And_Append (Chars (S));
8690 Add_Str_To_Name_Buffer ("__");
8694 -- Start of processing for Get_Qualified_Name
8700 -- Append the base name after all scopes have been chained
8702 Get_Name_String_And_Append (Nam);
8704 -- Append the suffix (if present)
8706 if Suffix /= No_Name then
8707 Add_Str_To_Name_Buffer ("__");
8708 Get_Name_String_And_Append (Suffix);
8712 end Get_Qualified_Name;
8714 -----------------------
8715 -- Get_Reason_String --
8716 -----------------------
8718 procedure Get_Reason_String (N : Node_Id) is
8720 if Nkind (N) = N_String_Literal then
8721 Store_String_Chars (Strval (N));
8723 elsif Nkind (N) = N_Op_Concat then
8724 Get_Reason_String (Left_Opnd (N));
8725 Get_Reason_String (Right_Opnd (N));
8727 -- If not of required form, error
8731 ("Reason for pragma Warnings has wrong form", N);
8733 ("\must be string literal or concatenation of string literals", N);
8736 end Get_Reason_String;
8738 --------------------------------
8739 -- Get_Reference_Discriminant --
8740 --------------------------------
8742 function Get_Reference_Discriminant (Typ : Entity_Id) return Entity_Id is
8746 D := First_Discriminant (Typ);
8747 while Present (D) loop
8748 if Has_Implicit_Dereference (D) then
8751 Next_Discriminant (D);
8755 end Get_Reference_Discriminant;
8757 ---------------------------
8758 -- Get_Referenced_Object --
8759 ---------------------------
8761 function Get_Referenced_Object (N : Node_Id) return Node_Id is
8766 while Is_Entity_Name (R)
8767 and then Present (Renamed_Object (Entity (R)))
8769 R := Renamed_Object (Entity (R));
8773 end Get_Referenced_Object;
8775 ------------------------
8776 -- Get_Renamed_Entity --
8777 ------------------------
8779 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
8784 while Present (Renamed_Entity (R)) loop
8785 R := Renamed_Entity (R);
8789 end Get_Renamed_Entity;
8791 -----------------------
8792 -- Get_Return_Object --
8793 -----------------------
8795 function Get_Return_Object (N : Node_Id) return Entity_Id is
8799 Decl := First (Return_Object_Declarations (N));
8800 while Present (Decl) loop
8801 exit when Nkind (Decl) = N_Object_Declaration
8802 and then Is_Return_Object (Defining_Identifier (Decl));
8806 pragma Assert (Present (Decl));
8807 return Defining_Identifier (Decl);
8808 end Get_Return_Object;
8810 ---------------------------
8811 -- Get_Subprogram_Entity --
8812 ---------------------------
8814 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
8816 Subp_Id : Entity_Id;
8819 if Nkind (Nod) = N_Accept_Statement then
8820 Subp := Entry_Direct_Name (Nod);
8822 elsif Nkind (Nod) = N_Slice then
8823 Subp := Prefix (Nod);
8829 -- Strip the subprogram call
8832 if Nkind_In (Subp, N_Explicit_Dereference,
8833 N_Indexed_Component,
8834 N_Selected_Component)
8836 Subp := Prefix (Subp);
8838 elsif Nkind_In (Subp, N_Type_Conversion,
8839 N_Unchecked_Type_Conversion)
8841 Subp := Expression (Subp);
8848 -- Extract the entity of the subprogram call
8850 if Is_Entity_Name (Subp) then
8851 Subp_Id := Entity (Subp);
8853 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
8854 Subp_Id := Directly_Designated_Type (Subp_Id);
8857 if Is_Subprogram (Subp_Id) then
8863 -- The search did not find a construct that denotes a subprogram
8868 end Get_Subprogram_Entity;
8870 -----------------------------
8871 -- Get_Task_Body_Procedure --
8872 -----------------------------
8874 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
8876 -- Note: A task type may be the completion of a private type with
8877 -- discriminants. When performing elaboration checks on a task
8878 -- declaration, the current view of the type may be the private one,
8879 -- and the procedure that holds the body of the task is held in its
8882 -- This is an odd function, why not have Task_Body_Procedure do
8883 -- the following digging???
8885 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
8886 end Get_Task_Body_Procedure;
8888 -------------------------
8889 -- Get_User_Defined_Eq --
8890 -------------------------
8892 function Get_User_Defined_Eq (E : Entity_Id) return Entity_Id is
8897 Prim := First_Elmt (Collect_Primitive_Operations (E));
8898 while Present (Prim) loop
8901 if Chars (Op) = Name_Op_Eq
8902 and then Etype (Op) = Standard_Boolean
8903 and then Etype (First_Formal (Op)) = E
8904 and then Etype (Next_Formal (First_Formal (Op))) = E
8913 end Get_User_Defined_Eq;
8921 Priv_Typ : out Entity_Id;
8922 Full_Typ : out Entity_Id;
8923 Full_Base : out Entity_Id;
8924 CRec_Typ : out Entity_Id)
8926 IP_View : Entity_Id;
8929 -- Assume that none of the views can be recovered
8936 -- The input type is the corresponding record type of a protected or a
8939 if Ekind (Typ) = E_Record_Type
8940 and then Is_Concurrent_Record_Type (Typ)
8943 Full_Typ := Corresponding_Concurrent_Type (CRec_Typ);
8944 Full_Base := Base_Type (Full_Typ);
8945 Priv_Typ := Incomplete_Or_Partial_View (Full_Typ);
8947 -- Otherwise the input type denotes an arbitrary type
8950 IP_View := Incomplete_Or_Partial_View (Typ);
8952 -- The input type denotes the full view of a private type
8954 if Present (IP_View) then
8955 Priv_Typ := IP_View;
8958 -- The input type is a private type
8960 elsif Is_Private_Type (Typ) then
8962 Full_Typ := Full_View (Priv_Typ);
8964 -- Otherwise the input type does not have any views
8970 if Present (Full_Typ) then
8971 Full_Base := Base_Type (Full_Typ);
8973 if Ekind_In (Full_Typ, E_Protected_Type, E_Task_Type) then
8974 CRec_Typ := Corresponding_Record_Type (Full_Typ);
8980 -----------------------
8981 -- Has_Access_Values --
8982 -----------------------
8984 function Has_Access_Values (T : Entity_Id) return Boolean is
8985 Typ : constant Entity_Id := Underlying_Type (T);
8988 -- Case of a private type which is not completed yet. This can only
8989 -- happen in the case of a generic format type appearing directly, or
8990 -- as a component of the type to which this function is being applied
8991 -- at the top level. Return False in this case, since we certainly do
8992 -- not know that the type contains access types.
8997 elsif Is_Access_Type (Typ) then
9000 elsif Is_Array_Type (Typ) then
9001 return Has_Access_Values (Component_Type (Typ));
9003 elsif Is_Record_Type (Typ) then
9008 -- Loop to Check components
9010 Comp := First_Component_Or_Discriminant (Typ);
9011 while Present (Comp) loop
9013 -- Check for access component, tag field does not count, even
9014 -- though it is implemented internally using an access type.
9016 if Has_Access_Values (Etype (Comp))
9017 and then Chars (Comp) /= Name_uTag
9022 Next_Component_Or_Discriminant (Comp);
9031 end Has_Access_Values;
9033 ------------------------------
9034 -- Has_Compatible_Alignment --
9035 ------------------------------
9037 function Has_Compatible_Alignment
9040 Layout_Done : Boolean) return Alignment_Result
9042 function Has_Compatible_Alignment_Internal
9045 Layout_Done : Boolean;
9046 Default : Alignment_Result) return Alignment_Result;
9047 -- This is the internal recursive function that actually does the work.
9048 -- There is one additional parameter, which says what the result should
9049 -- be if no alignment information is found, and there is no definite
9050 -- indication of compatible alignments. At the outer level, this is set
9051 -- to Unknown, but for internal recursive calls in the case where types
9052 -- are known to be correct, it is set to Known_Compatible.
9054 ---------------------------------------
9055 -- Has_Compatible_Alignment_Internal --
9056 ---------------------------------------
9058 function Has_Compatible_Alignment_Internal
9061 Layout_Done : Boolean;
9062 Default : Alignment_Result) return Alignment_Result
9064 Result : Alignment_Result := Known_Compatible;
9065 -- Holds the current status of the result. Note that once a value of
9066 -- Known_Incompatible is set, it is sticky and does not get changed
9067 -- to Unknown (the value in Result only gets worse as we go along,
9070 Offs : Uint := No_Uint;
9071 -- Set to a factor of the offset from the base object when Expr is a
9072 -- selected or indexed component, based on Component_Bit_Offset and
9073 -- Component_Size respectively. A negative value is used to represent
9074 -- a value which is not known at compile time.
9076 procedure Check_Prefix;
9077 -- Checks the prefix recursively in the case where the expression
9078 -- is an indexed or selected component.
9080 procedure Set_Result (R : Alignment_Result);
9081 -- If R represents a worse outcome (unknown instead of known
9082 -- compatible, or known incompatible), then set Result to R.
9088 procedure Check_Prefix is
9090 -- The subtlety here is that in doing a recursive call to check
9091 -- the prefix, we have to decide what to do in the case where we
9092 -- don't find any specific indication of an alignment problem.
9094 -- At the outer level, we normally set Unknown as the result in
9095 -- this case, since we can only set Known_Compatible if we really
9096 -- know that the alignment value is OK, but for the recursive
9097 -- call, in the case where the types match, and we have not
9098 -- specified a peculiar alignment for the object, we are only
9099 -- concerned about suspicious rep clauses, the default case does
9100 -- not affect us, since the compiler will, in the absence of such
9101 -- rep clauses, ensure that the alignment is correct.
9103 if Default = Known_Compatible
9105 (Etype (Obj) = Etype (Expr)
9106 and then (Unknown_Alignment (Obj)
9108 Alignment (Obj) = Alignment (Etype (Obj))))
9111 (Has_Compatible_Alignment_Internal
9112 (Obj, Prefix (Expr), Layout_Done, Known_Compatible));
9114 -- In all other cases, we need a full check on the prefix
9118 (Has_Compatible_Alignment_Internal
9119 (Obj, Prefix (Expr), Layout_Done, Unknown));
9127 procedure Set_Result (R : Alignment_Result) is
9134 -- Start of processing for Has_Compatible_Alignment_Internal
9137 -- If Expr is a selected component, we must make sure there is no
9138 -- potentially troublesome component clause and that the record is
9139 -- not packed if the layout is not done.
9141 if Nkind (Expr) = N_Selected_Component then
9143 -- Packing generates unknown alignment if layout is not done
9145 if Is_Packed (Etype (Prefix (Expr))) and then not Layout_Done then
9146 Set_Result (Unknown);
9149 -- Check prefix and component offset
9152 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
9154 -- If Expr is an indexed component, we must make sure there is no
9155 -- potentially troublesome Component_Size clause and that the array
9156 -- is not bit-packed if the layout is not done.
9158 elsif Nkind (Expr) = N_Indexed_Component then
9160 Typ : constant Entity_Id := Etype (Prefix (Expr));
9163 -- Packing generates unknown alignment if layout is not done
9165 if Is_Bit_Packed_Array (Typ) and then not Layout_Done then
9166 Set_Result (Unknown);
9169 -- Check prefix and component offset (or at least size)
9172 Offs := Indexed_Component_Bit_Offset (Expr);
9173 if Offs = No_Uint then
9174 Offs := Component_Size (Typ);
9179 -- If we have a null offset, the result is entirely determined by
9180 -- the base object and has already been computed recursively.
9182 if Offs = Uint_0 then
9185 -- Case where we know the alignment of the object
9187 elsif Known_Alignment (Obj) then
9189 ObjA : constant Uint := Alignment (Obj);
9190 ExpA : Uint := No_Uint;
9191 SizA : Uint := No_Uint;
9194 -- If alignment of Obj is 1, then we are always OK
9197 Set_Result (Known_Compatible);
9199 -- Alignment of Obj is greater than 1, so we need to check
9202 -- If we have an offset, see if it is compatible
9204 if Offs /= No_Uint and Offs > Uint_0 then
9205 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
9206 Set_Result (Known_Incompatible);
9209 -- See if Expr is an object with known alignment
9211 elsif Is_Entity_Name (Expr)
9212 and then Known_Alignment (Entity (Expr))
9214 ExpA := Alignment (Entity (Expr));
9216 -- Otherwise, we can use the alignment of the type of
9217 -- Expr given that we already checked for
9218 -- discombobulating rep clauses for the cases of indexed
9219 -- and selected components above.
9221 elsif Known_Alignment (Etype (Expr)) then
9222 ExpA := Alignment (Etype (Expr));
9224 -- Otherwise the alignment is unknown
9227 Set_Result (Default);
9230 -- If we got an alignment, see if it is acceptable
9232 if ExpA /= No_Uint and then ExpA < ObjA then
9233 Set_Result (Known_Incompatible);
9236 -- If Expr is not a piece of a larger object, see if size
9237 -- is given. If so, check that it is not too small for the
9238 -- required alignment.
9240 if Offs /= No_Uint then
9243 -- See if Expr is an object with known size
9245 elsif Is_Entity_Name (Expr)
9246 and then Known_Static_Esize (Entity (Expr))
9248 SizA := Esize (Entity (Expr));
9250 -- Otherwise, we check the object size of the Expr type
9252 elsif Known_Static_Esize (Etype (Expr)) then
9253 SizA := Esize (Etype (Expr));
9256 -- If we got a size, see if it is a multiple of the Obj
9257 -- alignment, if not, then the alignment cannot be
9258 -- acceptable, since the size is always a multiple of the
9261 if SizA /= No_Uint then
9262 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
9263 Set_Result (Known_Incompatible);
9269 -- If we do not know required alignment, any non-zero offset is a
9270 -- potential problem (but certainly may be OK, so result is unknown).
9272 elsif Offs /= No_Uint then
9273 Set_Result (Unknown);
9275 -- If we can't find the result by direct comparison of alignment
9276 -- values, then there is still one case that we can determine known
9277 -- result, and that is when we can determine that the types are the
9278 -- same, and no alignments are specified. Then we known that the
9279 -- alignments are compatible, even if we don't know the alignment
9280 -- value in the front end.
9282 elsif Etype (Obj) = Etype (Expr) then
9284 -- Types are the same, but we have to check for possible size
9285 -- and alignments on the Expr object that may make the alignment
9286 -- different, even though the types are the same.
9288 if Is_Entity_Name (Expr) then
9290 -- First check alignment of the Expr object. Any alignment less
9291 -- than Maximum_Alignment is worrisome since this is the case
9292 -- where we do not know the alignment of Obj.
9294 if Known_Alignment (Entity (Expr))
9295 and then UI_To_Int (Alignment (Entity (Expr))) <
9296 Ttypes.Maximum_Alignment
9298 Set_Result (Unknown);
9300 -- Now check size of Expr object. Any size that is not an
9301 -- even multiple of Maximum_Alignment is also worrisome
9302 -- since it may cause the alignment of the object to be less
9303 -- than the alignment of the type.
9305 elsif Known_Static_Esize (Entity (Expr))
9307 (UI_To_Int (Esize (Entity (Expr))) mod
9308 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
9311 Set_Result (Unknown);
9313 -- Otherwise same type is decisive
9316 Set_Result (Known_Compatible);
9320 -- Another case to deal with is when there is an explicit size or
9321 -- alignment clause when the types are not the same. If so, then the
9322 -- result is Unknown. We don't need to do this test if the Default is
9323 -- Unknown, since that result will be set in any case.
9325 elsif Default /= Unknown
9326 and then (Has_Size_Clause (Etype (Expr))
9328 Has_Alignment_Clause (Etype (Expr)))
9330 Set_Result (Unknown);
9332 -- If no indication found, set default
9335 Set_Result (Default);
9338 -- Return worst result found
9341 end Has_Compatible_Alignment_Internal;
9343 -- Start of processing for Has_Compatible_Alignment
9346 -- If Obj has no specified alignment, then set alignment from the type
9347 -- alignment. Perhaps we should always do this, but for sure we should
9348 -- do it when there is an address clause since we can do more if the
9349 -- alignment is known.
9351 if Unknown_Alignment (Obj) then
9352 Set_Alignment (Obj, Alignment (Etype (Obj)));
9355 -- Now do the internal call that does all the work
9358 Has_Compatible_Alignment_Internal (Obj, Expr, Layout_Done, Unknown);
9359 end Has_Compatible_Alignment;
9361 ----------------------
9362 -- Has_Declarations --
9363 ----------------------
9365 function Has_Declarations (N : Node_Id) return Boolean is
9367 return Nkind_In (Nkind (N), N_Accept_Statement,
9369 N_Compilation_Unit_Aux,
9375 N_Package_Specification);
9376 end Has_Declarations;
9378 ---------------------------------
9379 -- Has_Defaulted_Discriminants --
9380 ---------------------------------
9382 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
9384 return Has_Discriminants (Typ)
9385 and then Present (First_Discriminant (Typ))
9386 and then Present (Discriminant_Default_Value
9387 (First_Discriminant (Typ)));
9388 end Has_Defaulted_Discriminants;
9394 function Has_Denormals (E : Entity_Id) return Boolean is
9396 return Is_Floating_Point_Type (E) and then Denorm_On_Target;
9399 -------------------------------------------
9400 -- Has_Discriminant_Dependent_Constraint --
9401 -------------------------------------------
9403 function Has_Discriminant_Dependent_Constraint
9404 (Comp : Entity_Id) return Boolean
9406 Comp_Decl : constant Node_Id := Parent (Comp);
9407 Subt_Indic : Node_Id;
9412 -- Discriminants can't depend on discriminants
9414 if Ekind (Comp) = E_Discriminant then
9418 Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl));
9420 if Nkind (Subt_Indic) = N_Subtype_Indication then
9421 Constr := Constraint (Subt_Indic);
9423 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
9424 Assn := First (Constraints (Constr));
9425 while Present (Assn) loop
9426 case Nkind (Assn) is
9429 | N_Subtype_Indication
9431 if Depends_On_Discriminant (Assn) then
9435 when N_Discriminant_Association =>
9436 if Depends_On_Discriminant (Expression (Assn)) then
9451 end Has_Discriminant_Dependent_Constraint;
9453 --------------------------------------
9454 -- Has_Effectively_Volatile_Profile --
9455 --------------------------------------
9457 function Has_Effectively_Volatile_Profile
9458 (Subp_Id : Entity_Id) return Boolean
9463 -- Inspect the formal parameters looking for an effectively volatile
9466 Formal := First_Formal (Subp_Id);
9467 while Present (Formal) loop
9468 if Is_Effectively_Volatile (Etype (Formal)) then
9472 Next_Formal (Formal);
9475 -- Inspect the return type of functions
9477 if Ekind_In (Subp_Id, E_Function, E_Generic_Function)
9478 and then Is_Effectively_Volatile (Etype (Subp_Id))
9484 end Has_Effectively_Volatile_Profile;
9486 --------------------------
9487 -- Has_Enabled_Property --
9488 --------------------------
9490 function Has_Enabled_Property
9491 (Item_Id : Entity_Id;
9492 Property : Name_Id) return Boolean
9494 function Protected_Object_Has_Enabled_Property return Boolean;
9495 -- Determine whether a protected object denoted by Item_Id has the
9496 -- property enabled.
9498 function State_Has_Enabled_Property return Boolean;
9499 -- Determine whether a state denoted by Item_Id has the property enabled
9501 function Variable_Has_Enabled_Property return Boolean;
9502 -- Determine whether a variable denoted by Item_Id has the property
9505 -------------------------------------------
9506 -- Protected_Object_Has_Enabled_Property --
9507 -------------------------------------------
9509 function Protected_Object_Has_Enabled_Property return Boolean is
9510 Constits : constant Elist_Id := Part_Of_Constituents (Item_Id);
9511 Constit_Elmt : Elmt_Id;
9512 Constit_Id : Entity_Id;
9515 -- Protected objects always have the properties Async_Readers and
9516 -- Async_Writers (SPARK RM 7.1.2(16)).
9518 if Property = Name_Async_Readers
9519 or else Property = Name_Async_Writers
9523 -- Protected objects that have Part_Of components also inherit their
9524 -- properties Effective_Reads and Effective_Writes
9525 -- (SPARK RM 7.1.2(16)).
9527 elsif Present (Constits) then
9528 Constit_Elmt := First_Elmt (Constits);
9529 while Present (Constit_Elmt) loop
9530 Constit_Id := Node (Constit_Elmt);
9532 if Has_Enabled_Property (Constit_Id, Property) then
9536 Next_Elmt (Constit_Elmt);
9541 end Protected_Object_Has_Enabled_Property;
9543 --------------------------------
9544 -- State_Has_Enabled_Property --
9545 --------------------------------
9547 function State_Has_Enabled_Property return Boolean is
9548 Decl : constant Node_Id := Parent (Item_Id);
9556 -- The declaration of an external abstract state appears as an
9557 -- extension aggregate. If this is not the case, properties can never
9560 if Nkind (Decl) /= N_Extension_Aggregate then
9564 -- When External appears as a simple option, it automatically enables
9567 Opt := First (Expressions (Decl));
9568 while Present (Opt) loop
9569 if Nkind (Opt) = N_Identifier
9570 and then Chars (Opt) = Name_External
9578 -- When External specifies particular properties, inspect those and
9579 -- find the desired one (if any).
9581 Opt := First (Component_Associations (Decl));
9582 while Present (Opt) loop
9583 Opt_Nam := First (Choices (Opt));
9585 if Nkind (Opt_Nam) = N_Identifier
9586 and then Chars (Opt_Nam) = Name_External
9588 Props := Expression (Opt);
9590 -- Multiple properties appear as an aggregate
9592 if Nkind (Props) = N_Aggregate then
9594 -- Simple property form
9596 Prop := First (Expressions (Props));
9597 while Present (Prop) loop
9598 if Chars (Prop) = Property then
9605 -- Property with expression form
9607 Prop := First (Component_Associations (Props));
9608 while Present (Prop) loop
9609 Prop_Nam := First (Choices (Prop));
9611 -- The property can be represented in two ways:
9612 -- others => <value>
9613 -- <property> => <value>
9615 if Nkind (Prop_Nam) = N_Others_Choice
9616 or else (Nkind (Prop_Nam) = N_Identifier
9617 and then Chars (Prop_Nam) = Property)
9619 return Is_True (Expr_Value (Expression (Prop)));
9628 return Chars (Props) = Property;
9636 end State_Has_Enabled_Property;
9638 -----------------------------------
9639 -- Variable_Has_Enabled_Property --
9640 -----------------------------------
9642 function Variable_Has_Enabled_Property return Boolean is
9643 function Is_Enabled (Prag : Node_Id) return Boolean;
9644 -- Determine whether property pragma Prag (if present) denotes an
9645 -- enabled property.
9651 function Is_Enabled (Prag : Node_Id) return Boolean is
9655 if Present (Prag) then
9656 Arg1 := First (Pragma_Argument_Associations (Prag));
9658 -- The pragma has an optional Boolean expression, the related
9659 -- property is enabled only when the expression evaluates to
9662 if Present (Arg1) then
9663 return Is_True (Expr_Value (Get_Pragma_Arg (Arg1)));
9665 -- Otherwise the lack of expression enables the property by
9672 -- The property was never set in the first place
9681 AR : constant Node_Id :=
9682 Get_Pragma (Item_Id, Pragma_Async_Readers);
9683 AW : constant Node_Id :=
9684 Get_Pragma (Item_Id, Pragma_Async_Writers);
9685 ER : constant Node_Id :=
9686 Get_Pragma (Item_Id, Pragma_Effective_Reads);
9687 EW : constant Node_Id :=
9688 Get_Pragma (Item_Id, Pragma_Effective_Writes);
9690 -- Start of processing for Variable_Has_Enabled_Property
9693 -- A non-effectively volatile object can never possess external
9696 if not Is_Effectively_Volatile (Item_Id) then
9699 -- External properties related to variables come in two flavors -
9700 -- explicit and implicit. The explicit case is characterized by the
9701 -- presence of a property pragma with an optional Boolean flag. The
9702 -- property is enabled when the flag evaluates to True or the flag is
9703 -- missing altogether.
9705 elsif Property = Name_Async_Readers and then Is_Enabled (AR) then
9708 elsif Property = Name_Async_Writers and then Is_Enabled (AW) then
9711 elsif Property = Name_Effective_Reads and then Is_Enabled (ER) then
9714 elsif Property = Name_Effective_Writes and then Is_Enabled (EW) then
9717 -- The implicit case lacks all property pragmas
9719 elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then
9720 if Is_Protected_Type (Etype (Item_Id)) then
9721 return Protected_Object_Has_Enabled_Property;
9729 end Variable_Has_Enabled_Property;
9731 -- Start of processing for Has_Enabled_Property
9734 -- Abstract states and variables have a flexible scheme of specifying
9735 -- external properties.
9737 if Ekind (Item_Id) = E_Abstract_State then
9738 return State_Has_Enabled_Property;
9740 elsif Ekind (Item_Id) = E_Variable then
9741 return Variable_Has_Enabled_Property;
9743 -- By default, protected objects only have the properties Async_Readers
9744 -- and Async_Writers. If they have Part_Of components, they also inherit
9745 -- their properties Effective_Reads and Effective_Writes
9746 -- (SPARK RM 7.1.2(16)).
9748 elsif Ekind (Item_Id) = E_Protected_Object then
9749 return Protected_Object_Has_Enabled_Property;
9751 -- Otherwise a property is enabled when the related item is effectively
9755 return Is_Effectively_Volatile (Item_Id);
9757 end Has_Enabled_Property;
9759 -------------------------------------
9760 -- Has_Full_Default_Initialization --
9761 -------------------------------------
9763 function Has_Full_Default_Initialization (Typ : Entity_Id) return Boolean is
9768 -- A type subject to pragma Default_Initial_Condition is fully default
9769 -- initialized when the pragma appears with a non-null argument. Since
9770 -- any type may act as the full view of a private type, this check must
9771 -- be performed prior to the specialized tests below.
9773 if Has_DIC (Typ) then
9774 Prag := Get_Pragma (Typ, Pragma_Default_Initial_Condition);
9775 pragma Assert (Present (Prag));
9777 return Is_Verifiable_DIC_Pragma (Prag);
9780 -- A scalar type is fully default initialized if it is subject to aspect
9783 if Is_Scalar_Type (Typ) then
9784 return Has_Default_Aspect (Typ);
9786 -- An array type is fully default initialized if its element type is
9787 -- scalar and the array type carries aspect Default_Component_Value or
9788 -- the element type is fully default initialized.
9790 elsif Is_Array_Type (Typ) then
9792 Has_Default_Aspect (Typ)
9793 or else Has_Full_Default_Initialization (Component_Type (Typ));
9795 -- A protected type, record type, or type extension is fully default
9796 -- initialized if all its components either carry an initialization
9797 -- expression or have a type that is fully default initialized. The
9798 -- parent type of a type extension must be fully default initialized.
9800 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
9802 -- Inspect all entities defined in the scope of the type, looking for
9803 -- uninitialized components.
9805 Comp := First_Entity (Typ);
9806 while Present (Comp) loop
9807 if Ekind (Comp) = E_Component
9808 and then Comes_From_Source (Comp)
9809 and then No (Expression (Parent (Comp)))
9810 and then not Has_Full_Default_Initialization (Etype (Comp))
9818 -- Ensure that the parent type of a type extension is fully default
9821 if Etype (Typ) /= Typ
9822 and then not Has_Full_Default_Initialization (Etype (Typ))
9827 -- If we get here, then all components and parent portion are fully
9828 -- default initialized.
9832 -- A task type is fully default initialized by default
9834 elsif Is_Task_Type (Typ) then
9837 -- Otherwise the type is not fully default initialized
9842 end Has_Full_Default_Initialization;
9844 --------------------
9845 -- Has_Infinities --
9846 --------------------
9848 function Has_Infinities (E : Entity_Id) return Boolean is
9851 Is_Floating_Point_Type (E)
9852 and then Nkind (Scalar_Range (E)) = N_Range
9853 and then Includes_Infinities (Scalar_Range (E));
9856 --------------------
9857 -- Has_Interfaces --
9858 --------------------
9860 function Has_Interfaces
9862 Use_Full_View : Boolean := True) return Boolean
9864 Typ : Entity_Id := Base_Type (T);
9867 -- Handle concurrent types
9869 if Is_Concurrent_Type (Typ) then
9870 Typ := Corresponding_Record_Type (Typ);
9873 if not Present (Typ)
9874 or else not Is_Record_Type (Typ)
9875 or else not Is_Tagged_Type (Typ)
9880 -- Handle private types
9882 if Use_Full_View and then Present (Full_View (Typ)) then
9883 Typ := Full_View (Typ);
9886 -- Handle concurrent record types
9888 if Is_Concurrent_Record_Type (Typ)
9889 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
9895 if Is_Interface (Typ)
9897 (Is_Record_Type (Typ)
9898 and then Present (Interfaces (Typ))
9899 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
9904 exit when Etype (Typ) = Typ
9906 -- Handle private types
9908 or else (Present (Full_View (Etype (Typ)))
9909 and then Full_View (Etype (Typ)) = Typ)
9911 -- Protect frontend against wrong sources with cyclic derivations
9913 or else Etype (Typ) = T;
9915 -- Climb to the ancestor type handling private types
9917 if Present (Full_View (Etype (Typ))) then
9918 Typ := Full_View (Etype (Typ));
9927 --------------------------
9928 -- Has_Max_Queue_Length --
9929 --------------------------
9931 function Has_Max_Queue_Length (Id : Entity_Id) return Boolean is
9934 Ekind (Id) = E_Entry
9935 and then Present (Get_Pragma (Id, Pragma_Max_Queue_Length));
9936 end Has_Max_Queue_Length;
9938 ---------------------------------
9939 -- Has_No_Obvious_Side_Effects --
9940 ---------------------------------
9942 function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
9944 -- For now handle literals, constants, and non-volatile variables and
9945 -- expressions combining these with operators or short circuit forms.
9947 if Nkind (N) in N_Numeric_Or_String_Literal then
9950 elsif Nkind (N) = N_Character_Literal then
9953 elsif Nkind (N) in N_Unary_Op then
9954 return Has_No_Obvious_Side_Effects (Right_Opnd (N));
9956 elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
9957 return Has_No_Obvious_Side_Effects (Left_Opnd (N))
9959 Has_No_Obvious_Side_Effects (Right_Opnd (N));
9961 elsif Nkind (N) = N_Expression_With_Actions
9962 and then Is_Empty_List (Actions (N))
9964 return Has_No_Obvious_Side_Effects (Expression (N));
9966 elsif Nkind (N) in N_Has_Entity then
9967 return Present (Entity (N))
9968 and then Ekind_In (Entity (N), E_Variable,
9970 E_Enumeration_Literal,
9974 and then not Is_Volatile (Entity (N));
9979 end Has_No_Obvious_Side_Effects;
9981 -----------------------------
9982 -- Has_Non_Null_Refinement --
9983 -----------------------------
9985 function Has_Non_Null_Refinement (Id : Entity_Id) return Boolean is
9986 Constits : Elist_Id;
9989 pragma Assert (Ekind (Id) = E_Abstract_State);
9990 Constits := Refinement_Constituents (Id);
9992 -- For a refinement to be non-null, the first constituent must be
9993 -- anything other than null.
9997 and then Nkind (Node (First_Elmt (Constits))) /= N_Null;
9998 end Has_Non_Null_Refinement;
10000 ----------------------------------
10001 -- Has_Non_Trivial_Precondition --
10002 ----------------------------------
10004 function Has_Non_Trivial_Precondition (P : Entity_Id) return Boolean is
10005 Cont : constant Node_Id := Find_Aspect (P, Aspect_Pre);
10007 return Present (Cont)
10008 and then Class_Present (Cont)
10009 and then not Is_Entity_Name (Expression (Cont));
10010 end Has_Non_Trivial_Precondition;
10012 -------------------
10013 -- Has_Null_Body --
10014 -------------------
10016 function Has_Null_Body (Proc_Id : Entity_Id) return Boolean is
10017 Body_Id : Entity_Id;
10024 Spec := Parent (Proc_Id);
10025 Decl := Parent (Spec);
10027 -- Retrieve the entity of the procedure body (e.g. invariant proc).
10029 if Nkind (Spec) = N_Procedure_Specification
10030 and then Nkind (Decl) = N_Subprogram_Declaration
10032 Body_Id := Corresponding_Body (Decl);
10034 -- The body acts as a spec
10037 Body_Id := Proc_Id;
10040 -- The body will be generated later
10042 if No (Body_Id) then
10046 Spec := Parent (Body_Id);
10047 Decl := Parent (Spec);
10050 (Nkind (Spec) = N_Procedure_Specification
10051 and then Nkind (Decl) = N_Subprogram_Body);
10053 Stmt1 := First (Statements (Handled_Statement_Sequence (Decl)));
10055 -- Look for a null statement followed by an optional return
10058 if Nkind (Stmt1) = N_Null_Statement then
10059 Stmt2 := Next (Stmt1);
10061 if Present (Stmt2) then
10062 return Nkind (Stmt2) = N_Simple_Return_Statement;
10071 ------------------------
10072 -- Has_Null_Exclusion --
10073 ------------------------
10075 function Has_Null_Exclusion (N : Node_Id) return Boolean is
10078 when N_Access_Definition
10079 | N_Access_Function_Definition
10080 | N_Access_Procedure_Definition
10081 | N_Access_To_Object_Definition
10083 | N_Derived_Type_Definition
10084 | N_Function_Specification
10085 | N_Subtype_Declaration
10087 return Null_Exclusion_Present (N);
10089 when N_Component_Definition
10090 | N_Formal_Object_Declaration
10091 | N_Object_Renaming_Declaration
10093 if Present (Subtype_Mark (N)) then
10094 return Null_Exclusion_Present (N);
10095 else pragma Assert (Present (Access_Definition (N)));
10096 return Null_Exclusion_Present (Access_Definition (N));
10099 when N_Discriminant_Specification =>
10100 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
10101 return Null_Exclusion_Present (Discriminant_Type (N));
10103 return Null_Exclusion_Present (N);
10106 when N_Object_Declaration =>
10107 if Nkind (Object_Definition (N)) = N_Access_Definition then
10108 return Null_Exclusion_Present (Object_Definition (N));
10110 return Null_Exclusion_Present (N);
10113 when N_Parameter_Specification =>
10114 if Nkind (Parameter_Type (N)) = N_Access_Definition then
10115 return Null_Exclusion_Present (Parameter_Type (N));
10117 return Null_Exclusion_Present (N);
10123 end Has_Null_Exclusion;
10125 ------------------------
10126 -- Has_Null_Extension --
10127 ------------------------
10129 function Has_Null_Extension (T : Entity_Id) return Boolean is
10130 B : constant Entity_Id := Base_Type (T);
10135 if Nkind (Parent (B)) = N_Full_Type_Declaration
10136 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
10138 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
10140 if Present (Ext) then
10141 if Null_Present (Ext) then
10144 Comps := Component_List (Ext);
10146 -- The null component list is rewritten during analysis to
10147 -- include the parent component. Any other component indicates
10148 -- that the extension was not originally null.
10150 return Null_Present (Comps)
10151 or else No (Next (First (Component_Items (Comps))));
10160 end Has_Null_Extension;
10162 -------------------------
10163 -- Has_Null_Refinement --
10164 -------------------------
10166 function Has_Null_Refinement (Id : Entity_Id) return Boolean is
10167 Constits : Elist_Id;
10170 pragma Assert (Ekind (Id) = E_Abstract_State);
10171 Constits := Refinement_Constituents (Id);
10173 -- For a refinement to be null, the state's sole constituent must be a
10178 and then Nkind (Node (First_Elmt (Constits))) = N_Null;
10179 end Has_Null_Refinement;
10181 -------------------------------
10182 -- Has_Overriding_Initialize --
10183 -------------------------------
10185 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
10186 BT : constant Entity_Id := Base_Type (T);
10190 if Is_Controlled (BT) then
10191 if Is_RTU (Scope (BT), Ada_Finalization) then
10194 elsif Present (Primitive_Operations (BT)) then
10195 P := First_Elmt (Primitive_Operations (BT));
10196 while Present (P) loop
10198 Init : constant Entity_Id := Node (P);
10199 Formal : constant Entity_Id := First_Formal (Init);
10201 if Ekind (Init) = E_Procedure
10202 and then Chars (Init) = Name_Initialize
10203 and then Comes_From_Source (Init)
10204 and then Present (Formal)
10205 and then Etype (Formal) = BT
10206 and then No (Next_Formal (Formal))
10207 and then (Ada_Version < Ada_2012
10208 or else not Null_Present (Parent (Init)))
10218 -- Here if type itself does not have a non-null Initialize operation:
10219 -- check immediate ancestor.
10221 if Is_Derived_Type (BT)
10222 and then Has_Overriding_Initialize (Etype (BT))
10229 end Has_Overriding_Initialize;
10231 --------------------------------------
10232 -- Has_Preelaborable_Initialization --
10233 --------------------------------------
10235 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
10238 procedure Check_Components (E : Entity_Id);
10239 -- Check component/discriminant chain, sets Has_PE False if a component
10240 -- or discriminant does not meet the preelaborable initialization rules.
10242 ----------------------
10243 -- Check_Components --
10244 ----------------------
10246 procedure Check_Components (E : Entity_Id) is
10250 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
10251 -- Returns True if and only if the expression denoted by N does not
10252 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
10254 ---------------------------------
10255 -- Is_Preelaborable_Expression --
10256 ---------------------------------
10258 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
10262 Comp_Type : Entity_Id;
10263 Is_Array_Aggr : Boolean;
10266 if Is_OK_Static_Expression (N) then
10269 elsif Nkind (N) = N_Null then
10272 -- Attributes are allowed in general, even if their prefix is a
10273 -- formal type. (It seems that certain attributes known not to be
10274 -- static might not be allowed, but there are no rules to prevent
10277 elsif Nkind (N) = N_Attribute_Reference then
10280 -- The name of a discriminant evaluated within its parent type is
10281 -- defined to be preelaborable (10.2.1(8)). Note that we test for
10282 -- names that denote discriminals as well as discriminants to
10283 -- catch references occurring within init procs.
10285 elsif Is_Entity_Name (N)
10287 (Ekind (Entity (N)) = E_Discriminant
10288 or else (Ekind_In (Entity (N), E_Constant, E_In_Parameter)
10289 and then Present (Discriminal_Link (Entity (N)))))
10293 elsif Nkind (N) = N_Qualified_Expression then
10294 return Is_Preelaborable_Expression (Expression (N));
10296 -- For aggregates we have to check that each of the associations
10297 -- is preelaborable.
10299 elsif Nkind_In (N, N_Aggregate, N_Extension_Aggregate) then
10300 Is_Array_Aggr := Is_Array_Type (Etype (N));
10302 if Is_Array_Aggr then
10303 Comp_Type := Component_Type (Etype (N));
10306 -- Check the ancestor part of extension aggregates, which must
10307 -- be either the name of a type that has preelaborable init or
10308 -- an expression that is preelaborable.
10310 if Nkind (N) = N_Extension_Aggregate then
10312 Anc_Part : constant Node_Id := Ancestor_Part (N);
10315 if Is_Entity_Name (Anc_Part)
10316 and then Is_Type (Entity (Anc_Part))
10318 if not Has_Preelaborable_Initialization
10319 (Entity (Anc_Part))
10324 elsif not Is_Preelaborable_Expression (Anc_Part) then
10330 -- Check positional associations
10332 Exp := First (Expressions (N));
10333 while Present (Exp) loop
10334 if not Is_Preelaborable_Expression (Exp) then
10341 -- Check named associations
10343 Assn := First (Component_Associations (N));
10344 while Present (Assn) loop
10345 Choice := First (Choices (Assn));
10346 while Present (Choice) loop
10347 if Is_Array_Aggr then
10348 if Nkind (Choice) = N_Others_Choice then
10351 elsif Nkind (Choice) = N_Range then
10352 if not Is_OK_Static_Range (Choice) then
10356 elsif not Is_OK_Static_Expression (Choice) then
10361 Comp_Type := Etype (Choice);
10367 -- If the association has a <> at this point, then we have
10368 -- to check whether the component's type has preelaborable
10369 -- initialization. Note that this only occurs when the
10370 -- association's corresponding component does not have a
10371 -- default expression, the latter case having already been
10372 -- expanded as an expression for the association.
10374 if Box_Present (Assn) then
10375 if not Has_Preelaborable_Initialization (Comp_Type) then
10379 -- In the expression case we check whether the expression
10380 -- is preelaborable.
10383 not Is_Preelaborable_Expression (Expression (Assn))
10391 -- If we get here then aggregate as a whole is preelaborable
10395 -- All other cases are not preelaborable
10400 end Is_Preelaborable_Expression;
10402 -- Start of processing for Check_Components
10405 -- Loop through entities of record or protected type
10408 while Present (Ent) loop
10410 -- We are interested only in components and discriminants
10414 case Ekind (Ent) is
10415 when E_Component =>
10417 -- Get default expression if any. If there is no declaration
10418 -- node, it means we have an internal entity. The parent and
10419 -- tag fields are examples of such entities. For such cases,
10420 -- we just test the type of the entity.
10422 if Present (Declaration_Node (Ent)) then
10423 Exp := Expression (Declaration_Node (Ent));
10426 when E_Discriminant =>
10428 -- Note: for a renamed discriminant, the Declaration_Node
10429 -- may point to the one from the ancestor, and have a
10430 -- different expression, so use the proper attribute to
10431 -- retrieve the expression from the derived constraint.
10433 Exp := Discriminant_Default_Value (Ent);
10436 goto Check_Next_Entity;
10439 -- A component has PI if it has no default expression and the
10440 -- component type has PI.
10443 if not Has_Preelaborable_Initialization (Etype (Ent)) then
10448 -- Require the default expression to be preelaborable
10450 elsif not Is_Preelaborable_Expression (Exp) then
10455 <<Check_Next_Entity>>
10458 end Check_Components;
10460 -- Start of processing for Has_Preelaborable_Initialization
10463 -- Immediate return if already marked as known preelaborable init. This
10464 -- covers types for which this function has already been called once
10465 -- and returned True (in which case the result is cached), and also
10466 -- types to which a pragma Preelaborable_Initialization applies.
10468 if Known_To_Have_Preelab_Init (E) then
10472 -- If the type is a subtype representing a generic actual type, then
10473 -- test whether its base type has preelaborable initialization since
10474 -- the subtype representing the actual does not inherit this attribute
10475 -- from the actual or formal. (but maybe it should???)
10477 if Is_Generic_Actual_Type (E) then
10478 return Has_Preelaborable_Initialization (Base_Type (E));
10481 -- All elementary types have preelaborable initialization
10483 if Is_Elementary_Type (E) then
10486 -- Array types have PI if the component type has PI
10488 elsif Is_Array_Type (E) then
10489 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
10491 -- A derived type has preelaborable initialization if its parent type
10492 -- has preelaborable initialization and (in the case of a derived record
10493 -- extension) if the non-inherited components all have preelaborable
10494 -- initialization. However, a user-defined controlled type with an
10495 -- overriding Initialize procedure does not have preelaborable
10498 elsif Is_Derived_Type (E) then
10500 -- If the derived type is a private extension then it doesn't have
10501 -- preelaborable initialization.
10503 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
10507 -- First check whether ancestor type has preelaborable initialization
10509 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
10511 -- If OK, check extension components (if any)
10513 if Has_PE and then Is_Record_Type (E) then
10514 Check_Components (First_Entity (E));
10517 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
10518 -- with a user defined Initialize procedure does not have PI. If
10519 -- the type is untagged, the control primitives come from a component
10520 -- that has already been checked.
10523 and then Is_Controlled (E)
10524 and then Is_Tagged_Type (E)
10525 and then Has_Overriding_Initialize (E)
10530 -- Private types not derived from a type having preelaborable init and
10531 -- that are not marked with pragma Preelaborable_Initialization do not
10532 -- have preelaborable initialization.
10534 elsif Is_Private_Type (E) then
10537 -- Record type has PI if it is non private and all components have PI
10539 elsif Is_Record_Type (E) then
10541 Check_Components (First_Entity (E));
10543 -- Protected types must not have entries, and components must meet
10544 -- same set of rules as for record components.
10546 elsif Is_Protected_Type (E) then
10547 if Has_Entries (E) then
10551 Check_Components (First_Entity (E));
10552 Check_Components (First_Private_Entity (E));
10555 -- Type System.Address always has preelaborable initialization
10557 elsif Is_RTE (E, RE_Address) then
10560 -- In all other cases, type does not have preelaborable initialization
10566 -- If type has preelaborable initialization, cache result
10569 Set_Known_To_Have_Preelab_Init (E);
10573 end Has_Preelaborable_Initialization;
10575 ---------------------------
10576 -- Has_Private_Component --
10577 ---------------------------
10579 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
10580 Btype : Entity_Id := Base_Type (Type_Id);
10581 Component : Entity_Id;
10584 if Error_Posted (Type_Id)
10585 or else Error_Posted (Btype)
10590 if Is_Class_Wide_Type (Btype) then
10591 Btype := Root_Type (Btype);
10594 if Is_Private_Type (Btype) then
10596 UT : constant Entity_Id := Underlying_Type (Btype);
10599 if No (Full_View (Btype)) then
10600 return not Is_Generic_Type (Btype)
10602 not Is_Generic_Type (Root_Type (Btype));
10604 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
10607 return not Is_Frozen (UT) and then Has_Private_Component (UT);
10611 elsif Is_Array_Type (Btype) then
10612 return Has_Private_Component (Component_Type (Btype));
10614 elsif Is_Record_Type (Btype) then
10615 Component := First_Component (Btype);
10616 while Present (Component) loop
10617 if Has_Private_Component (Etype (Component)) then
10621 Next_Component (Component);
10626 elsif Is_Protected_Type (Btype)
10627 and then Present (Corresponding_Record_Type (Btype))
10629 return Has_Private_Component (Corresponding_Record_Type (Btype));
10634 end Has_Private_Component;
10636 ----------------------
10637 -- Has_Signed_Zeros --
10638 ----------------------
10640 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
10642 return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target;
10643 end Has_Signed_Zeros;
10645 ------------------------------
10646 -- Has_Significant_Contract --
10647 ------------------------------
10649 function Has_Significant_Contract (Subp_Id : Entity_Id) return Boolean is
10650 Subp_Nam : constant Name_Id := Chars (Subp_Id);
10653 -- _Finalizer procedure
10655 if Subp_Nam = Name_uFinalizer then
10658 -- _Postconditions procedure
10660 elsif Subp_Nam = Name_uPostconditions then
10663 -- Predicate function
10665 elsif Ekind (Subp_Id) = E_Function
10666 and then Is_Predicate_Function (Subp_Id)
10672 elsif Get_TSS_Name (Subp_Id) /= TSS_Null then
10678 end Has_Significant_Contract;
10680 -----------------------------
10681 -- Has_Static_Array_Bounds --
10682 -----------------------------
10684 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
10685 Ndims : constant Nat := Number_Dimensions (Typ);
10692 -- Unconstrained types do not have static bounds
10694 if not Is_Constrained (Typ) then
10698 -- First treat string literals specially, as the lower bound and length
10699 -- of string literals are not stored like those of arrays.
10701 -- A string literal always has static bounds
10703 if Ekind (Typ) = E_String_Literal_Subtype then
10707 -- Treat all dimensions in turn
10709 Index := First_Index (Typ);
10710 for Indx in 1 .. Ndims loop
10712 -- In case of an illegal index which is not a discrete type, return
10713 -- that the type is not static.
10715 if not Is_Discrete_Type (Etype (Index))
10716 or else Etype (Index) = Any_Type
10721 Get_Index_Bounds (Index, Low, High);
10723 if Error_Posted (Low) or else Error_Posted (High) then
10727 if Is_OK_Static_Expression (Low)
10729 Is_OK_Static_Expression (High)
10739 -- If we fall through the loop, all indexes matched
10742 end Has_Static_Array_Bounds;
10748 function Has_Stream (T : Entity_Id) return Boolean is
10755 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
10758 elsif Is_Array_Type (T) then
10759 return Has_Stream (Component_Type (T));
10761 elsif Is_Record_Type (T) then
10762 E := First_Component (T);
10763 while Present (E) loop
10764 if Has_Stream (Etype (E)) then
10767 Next_Component (E);
10773 elsif Is_Private_Type (T) then
10774 return Has_Stream (Underlying_Type (T));
10785 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
10787 Get_Name_String (Chars (E));
10788 return Name_Buffer (Name_Len) = Suffix;
10795 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
10797 Get_Name_String (Chars (E));
10798 Add_Char_To_Name_Buffer (Suffix);
10802 -------------------
10803 -- Remove_Suffix --
10804 -------------------
10806 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
10808 pragma Assert (Has_Suffix (E, Suffix));
10809 Get_Name_String (Chars (E));
10810 Name_Len := Name_Len - 1;
10814 ----------------------------------
10815 -- Replace_Null_By_Null_Address --
10816 ----------------------------------
10818 procedure Replace_Null_By_Null_Address (N : Node_Id) is
10819 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id);
10820 -- Replace operand Op with a reference to Null_Address when the operand
10821 -- denotes a null Address. Other_Op denotes the other operand.
10823 --------------------------
10824 -- Replace_Null_Operand --
10825 --------------------------
10827 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id) is
10829 -- Check the type of the complementary operand since the N_Null node
10830 -- has not been decorated yet.
10832 if Nkind (Op) = N_Null
10833 and then Is_Descendant_Of_Address (Etype (Other_Op))
10835 Rewrite (Op, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (Op)));
10837 end Replace_Null_Operand;
10839 -- Start of processing for Replace_Null_By_Null_Address
10842 pragma Assert (Relaxed_RM_Semantics);
10843 pragma Assert (Nkind_In (N, N_Null,
10851 if Nkind (N) = N_Null then
10852 Rewrite (N, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (N)));
10856 L : constant Node_Id := Left_Opnd (N);
10857 R : constant Node_Id := Right_Opnd (N);
10860 Replace_Null_Operand (L, Other_Op => R);
10861 Replace_Null_Operand (R, Other_Op => L);
10864 end Replace_Null_By_Null_Address;
10866 --------------------------
10867 -- Has_Tagged_Component --
10868 --------------------------
10870 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
10874 if Is_Private_Type (Typ) and then Present (Underlying_Type (Typ)) then
10875 return Has_Tagged_Component (Underlying_Type (Typ));
10877 elsif Is_Array_Type (Typ) then
10878 return Has_Tagged_Component (Component_Type (Typ));
10880 elsif Is_Tagged_Type (Typ) then
10883 elsif Is_Record_Type (Typ) then
10884 Comp := First_Component (Typ);
10885 while Present (Comp) loop
10886 if Has_Tagged_Component (Etype (Comp)) then
10890 Next_Component (Comp);
10898 end Has_Tagged_Component;
10900 -----------------------------
10901 -- Has_Undefined_Reference --
10902 -----------------------------
10904 function Has_Undefined_Reference (Expr : Node_Id) return Boolean is
10905 Has_Undef_Ref : Boolean := False;
10906 -- Flag set when expression Expr contains at least one undefined
10909 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result;
10910 -- Determine whether N denotes a reference and if it does, whether it is
10913 ----------------------------
10914 -- Is_Undefined_Reference --
10915 ----------------------------
10917 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result is
10919 if Is_Entity_Name (N)
10920 and then Present (Entity (N))
10921 and then Entity (N) = Any_Id
10923 Has_Undef_Ref := True;
10928 end Is_Undefined_Reference;
10930 procedure Find_Undefined_References is
10931 new Traverse_Proc (Is_Undefined_Reference);
10933 -- Start of processing for Has_Undefined_Reference
10936 Find_Undefined_References (Expr);
10938 return Has_Undef_Ref;
10939 end Has_Undefined_Reference;
10941 ----------------------------
10942 -- Has_Volatile_Component --
10943 ----------------------------
10945 function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
10949 if Has_Volatile_Components (Typ) then
10952 elsif Is_Array_Type (Typ) then
10953 return Is_Volatile (Component_Type (Typ));
10955 elsif Is_Record_Type (Typ) then
10956 Comp := First_Component (Typ);
10957 while Present (Comp) loop
10958 if Is_Volatile_Object (Comp) then
10962 Comp := Next_Component (Comp);
10967 end Has_Volatile_Component;
10969 -------------------------
10970 -- Implementation_Kind --
10971 -------------------------
10973 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
10974 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
10977 pragma Assert (Present (Impl_Prag));
10978 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
10979 return Chars (Get_Pragma_Arg (Arg));
10980 end Implementation_Kind;
10982 --------------------------
10983 -- Implements_Interface --
10984 --------------------------
10986 function Implements_Interface
10987 (Typ_Ent : Entity_Id;
10988 Iface_Ent : Entity_Id;
10989 Exclude_Parents : Boolean := False) return Boolean
10991 Ifaces_List : Elist_Id;
10993 Iface : Entity_Id := Base_Type (Iface_Ent);
10994 Typ : Entity_Id := Base_Type (Typ_Ent);
10997 if Is_Class_Wide_Type (Typ) then
10998 Typ := Root_Type (Typ);
11001 if not Has_Interfaces (Typ) then
11005 if Is_Class_Wide_Type (Iface) then
11006 Iface := Root_Type (Iface);
11009 Collect_Interfaces (Typ, Ifaces_List);
11011 Elmt := First_Elmt (Ifaces_List);
11012 while Present (Elmt) loop
11013 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
11014 and then Exclude_Parents
11018 elsif Node (Elmt) = Iface then
11026 end Implements_Interface;
11028 ------------------------------------
11029 -- In_Assertion_Expression_Pragma --
11030 ------------------------------------
11032 function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is
11034 Prag : Node_Id := Empty;
11037 -- Climb the parent chain looking for an enclosing pragma
11040 while Present (Par) loop
11041 if Nkind (Par) = N_Pragma then
11045 -- Precondition-like pragmas are expanded into if statements, check
11046 -- the original node instead.
11048 elsif Nkind (Original_Node (Par)) = N_Pragma then
11049 Prag := Original_Node (Par);
11052 -- The expansion of attribute 'Old generates a constant to capture
11053 -- the result of the prefix. If the parent traversal reaches
11054 -- one of these constants, then the node technically came from a
11055 -- postcondition-like pragma. Note that the Ekind is not tested here
11056 -- because N may be the expression of an object declaration which is
11057 -- currently being analyzed. Such objects carry Ekind of E_Void.
11059 elsif Nkind (Par) = N_Object_Declaration
11060 and then Constant_Present (Par)
11061 and then Stores_Attribute_Old_Prefix (Defining_Entity (Par))
11065 -- Prevent the search from going too far
11067 elsif Is_Body_Or_Package_Declaration (Par) then
11071 Par := Parent (Par);
11076 and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag));
11077 end In_Assertion_Expression_Pragma;
11079 ----------------------
11080 -- In_Generic_Scope --
11081 ----------------------
11083 function In_Generic_Scope (E : Entity_Id) return Boolean is
11088 while Present (S) and then S /= Standard_Standard loop
11089 if Is_Generic_Unit (S) then
11097 end In_Generic_Scope;
11103 function In_Instance return Boolean is
11104 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
11108 S := Current_Scope;
11109 while Present (S) and then S /= Standard_Standard loop
11110 if Ekind_In (S, E_Function, E_Package, E_Procedure)
11111 and then Is_Generic_Instance (S)
11113 -- A child instance is always compiled in the context of a parent
11114 -- instance. Nevertheless, the actuals are not analyzed in an
11115 -- instance context. We detect this case by examining the current
11116 -- compilation unit, which must be a child instance, and checking
11117 -- that it is not currently on the scope stack.
11119 if Is_Child_Unit (Curr_Unit)
11120 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
11121 N_Package_Instantiation
11122 and then not In_Open_Scopes (Curr_Unit)
11136 ----------------------
11137 -- In_Instance_Body --
11138 ----------------------
11140 function In_Instance_Body return Boolean is
11144 S := Current_Scope;
11145 while Present (S) and then S /= Standard_Standard loop
11146 if Ekind_In (S, E_Function, E_Procedure)
11147 and then Is_Generic_Instance (S)
11151 elsif Ekind (S) = E_Package
11152 and then In_Package_Body (S)
11153 and then Is_Generic_Instance (S)
11162 end In_Instance_Body;
11164 -----------------------------
11165 -- In_Instance_Not_Visible --
11166 -----------------------------
11168 function In_Instance_Not_Visible return Boolean is
11172 S := Current_Scope;
11173 while Present (S) and then S /= Standard_Standard loop
11174 if Ekind_In (S, E_Function, E_Procedure)
11175 and then Is_Generic_Instance (S)
11179 elsif Ekind (S) = E_Package
11180 and then (In_Package_Body (S) or else In_Private_Part (S))
11181 and then Is_Generic_Instance (S)
11190 end In_Instance_Not_Visible;
11192 ------------------------------
11193 -- In_Instance_Visible_Part --
11194 ------------------------------
11196 function In_Instance_Visible_Part return Boolean is
11200 S := Current_Scope;
11201 while Present (S) and then S /= Standard_Standard loop
11202 if Ekind (S) = E_Package
11203 and then Is_Generic_Instance (S)
11204 and then not In_Package_Body (S)
11205 and then not In_Private_Part (S)
11214 end In_Instance_Visible_Part;
11216 ---------------------
11217 -- In_Package_Body --
11218 ---------------------
11220 function In_Package_Body return Boolean is
11224 S := Current_Scope;
11225 while Present (S) and then S /= Standard_Standard loop
11226 if Ekind (S) = E_Package and then In_Package_Body (S) then
11234 end In_Package_Body;
11236 --------------------------------
11237 -- In_Parameter_Specification --
11238 --------------------------------
11240 function In_Parameter_Specification (N : Node_Id) return Boolean is
11245 while Present (PN) loop
11246 if Nkind (PN) = N_Parameter_Specification then
11254 end In_Parameter_Specification;
11256 --------------------------
11257 -- In_Pragma_Expression --
11258 --------------------------
11260 function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean is
11267 elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
11273 end In_Pragma_Expression;
11275 ---------------------------
11276 -- In_Pre_Post_Condition --
11277 ---------------------------
11279 function In_Pre_Post_Condition (N : Node_Id) return Boolean is
11281 Prag : Node_Id := Empty;
11282 Prag_Id : Pragma_Id;
11285 -- Climb the parent chain looking for an enclosing pragma
11288 while Present (Par) loop
11289 if Nkind (Par) = N_Pragma then
11293 -- Prevent the search from going too far
11295 elsif Is_Body_Or_Package_Declaration (Par) then
11299 Par := Parent (Par);
11302 if Present (Prag) then
11303 Prag_Id := Get_Pragma_Id (Prag);
11306 Prag_Id = Pragma_Post
11307 or else Prag_Id = Pragma_Post_Class
11308 or else Prag_Id = Pragma_Postcondition
11309 or else Prag_Id = Pragma_Pre
11310 or else Prag_Id = Pragma_Pre_Class
11311 or else Prag_Id = Pragma_Precondition;
11313 -- Otherwise the node is not enclosed by a pre/postcondition pragma
11318 end In_Pre_Post_Condition;
11320 -------------------------------------
11321 -- In_Reverse_Storage_Order_Object --
11322 -------------------------------------
11324 function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
11326 Btyp : Entity_Id := Empty;
11329 -- Climb up indexed components
11333 case Nkind (Pref) is
11334 when N_Selected_Component =>
11335 Pref := Prefix (Pref);
11338 when N_Indexed_Component =>
11339 Pref := Prefix (Pref);
11347 if Present (Pref) then
11348 Btyp := Base_Type (Etype (Pref));
11351 return Present (Btyp)
11352 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
11353 and then Reverse_Storage_Order (Btyp);
11354 end In_Reverse_Storage_Order_Object;
11356 --------------------------------------
11357 -- In_Subprogram_Or_Concurrent_Unit --
11358 --------------------------------------
11360 function In_Subprogram_Or_Concurrent_Unit return Boolean is
11365 -- Use scope chain to check successively outer scopes
11367 E := Current_Scope;
11371 if K in Subprogram_Kind
11372 or else K in Concurrent_Kind
11373 or else K in Generic_Subprogram_Kind
11377 elsif E = Standard_Standard then
11383 end In_Subprogram_Or_Concurrent_Unit;
11385 ---------------------
11386 -- In_Visible_Part --
11387 ---------------------
11389 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
11391 return Is_Package_Or_Generic_Package (Scope_Id)
11392 and then In_Open_Scopes (Scope_Id)
11393 and then not In_Package_Body (Scope_Id)
11394 and then not In_Private_Part (Scope_Id);
11395 end In_Visible_Part;
11397 --------------------------------
11398 -- Incomplete_Or_Partial_View --
11399 --------------------------------
11401 function Incomplete_Or_Partial_View (Id : Entity_Id) return Entity_Id is
11402 function Inspect_Decls
11404 Taft : Boolean := False) return Entity_Id;
11405 -- Check whether a declarative region contains the incomplete or partial
11408 -------------------
11409 -- Inspect_Decls --
11410 -------------------
11412 function Inspect_Decls
11414 Taft : Boolean := False) return Entity_Id
11420 Decl := First (Decls);
11421 while Present (Decl) loop
11424 -- The partial view of a Taft-amendment type is an incomplete
11428 if Nkind (Decl) = N_Incomplete_Type_Declaration then
11429 Match := Defining_Identifier (Decl);
11432 -- Otherwise look for a private type whose full view matches the
11433 -- input type. Note that this checks full_type_declaration nodes
11434 -- to account for derivations from a private type where the type
11435 -- declaration hold the partial view and the full view is an
11438 elsif Nkind_In (Decl, N_Full_Type_Declaration,
11439 N_Private_Extension_Declaration,
11440 N_Private_Type_Declaration)
11442 Match := Defining_Identifier (Decl);
11445 -- Guard against unanalyzed entities
11448 and then Is_Type (Match)
11449 and then Present (Full_View (Match))
11450 and then Full_View (Match) = Id
11465 -- Start of processing for Incomplete_Or_Partial_View
11468 -- Deferred constant or incomplete type case
11470 Prev := Current_Entity_In_Scope (Id);
11473 and then (Is_Incomplete_Type (Prev) or else Ekind (Prev) = E_Constant)
11474 and then Present (Full_View (Prev))
11475 and then Full_View (Prev) = Id
11480 -- Private or Taft amendment type case
11483 Pkg : constant Entity_Id := Scope (Id);
11484 Pkg_Decl : Node_Id := Pkg;
11488 and then Ekind_In (Pkg, E_Generic_Package, E_Package)
11490 while Nkind (Pkg_Decl) /= N_Package_Specification loop
11491 Pkg_Decl := Parent (Pkg_Decl);
11494 -- It is knows that Typ has a private view, look for it in the
11495 -- visible declarations of the enclosing scope. A special case
11496 -- of this is when the two views have been exchanged - the full
11497 -- appears earlier than the private.
11499 if Has_Private_Declaration (Id) then
11500 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
11502 -- Exchanged view case, look in the private declarations
11505 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
11510 -- Otherwise if this is the package body, then Typ is a potential
11511 -- Taft amendment type. The incomplete view should be located in
11512 -- the private declarations of the enclosing scope.
11514 elsif In_Package_Body (Pkg) then
11515 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
11520 -- The type has no incomplete or private view
11523 end Incomplete_Or_Partial_View;
11525 ----------------------------------
11526 -- Indexed_Component_Bit_Offset --
11527 ----------------------------------
11529 function Indexed_Component_Bit_Offset (N : Node_Id) return Uint is
11530 Exp : constant Node_Id := First (Expressions (N));
11531 Typ : constant Entity_Id := Etype (Prefix (N));
11532 Off : constant Uint := Component_Size (Typ);
11536 -- Return early if the component size is not known or variable
11538 if Off = No_Uint or else Off < Uint_0 then
11542 -- Deal with the degenerate case of an empty component
11544 if Off = Uint_0 then
11548 -- Check that both the index value and the low bound are known
11550 if not Compile_Time_Known_Value (Exp) then
11554 Ind := First_Index (Typ);
11559 if Nkind (Ind) = N_Subtype_Indication then
11560 Ind := Constraint (Ind);
11562 if Nkind (Ind) = N_Range_Constraint then
11563 Ind := Range_Expression (Ind);
11567 if Nkind (Ind) /= N_Range
11568 or else not Compile_Time_Known_Value (Low_Bound (Ind))
11573 -- Return the scaled offset
11575 return Off * (Expr_Value (Exp) - Expr_Value (Low_Bound ((Ind))));
11576 end Indexed_Component_Bit_Offset;
11578 ----------------------------
11579 -- Inherit_Rep_Item_Chain --
11580 ----------------------------
11582 procedure Inherit_Rep_Item_Chain (Typ : Entity_Id; From_Typ : Entity_Id) is
11584 Next_Item : Node_Id;
11587 -- There are several inheritance scenarios to consider depending on
11588 -- whether both types have rep item chains and whether the destination
11589 -- type already inherits part of the source type's rep item chain.
11591 -- 1) The source type lacks a rep item chain
11592 -- From_Typ ---> Empty
11594 -- Typ --------> Item (or Empty)
11596 -- In this case inheritance cannot take place because there are no items
11599 -- 2) The destination type lacks a rep item chain
11600 -- From_Typ ---> Item ---> ...
11602 -- Typ --------> Empty
11604 -- Inheritance takes place by setting the First_Rep_Item of the
11605 -- destination type to the First_Rep_Item of the source type.
11606 -- From_Typ ---> Item ---> ...
11608 -- Typ -----------+
11610 -- 3.1) Both source and destination types have at least one rep item.
11611 -- The destination type does NOT inherit a rep item from the source
11613 -- From_Typ ---> Item ---> Item
11615 -- Typ --------> Item ---> Item
11617 -- Inheritance takes place by setting the Next_Rep_Item of the last item
11618 -- of the destination type to the First_Rep_Item of the source type.
11619 -- From_Typ -------------------> Item ---> Item
11621 -- Typ --------> Item ---> Item --+
11623 -- 3.2) Both source and destination types have at least one rep item.
11624 -- The destination type DOES inherit part of the rep item chain of the
11626 -- From_Typ ---> Item ---> Item ---> Item
11628 -- Typ --------> Item ------+
11630 -- This rare case arises when the full view of a private extension must
11631 -- inherit the rep item chain from the full view of its parent type and
11632 -- the full view of the parent type contains extra rep items. Currently
11633 -- only invariants may lead to such form of inheritance.
11635 -- type From_Typ is tagged private
11636 -- with Type_Invariant'Class => Item_2;
11638 -- type Typ is new From_Typ with private
11639 -- with Type_Invariant => Item_4;
11641 -- At this point the rep item chains contain the following items
11643 -- From_Typ -----------> Item_2 ---> Item_3
11645 -- Typ --------> Item_4 --+
11647 -- The full views of both types may introduce extra invariants
11649 -- type From_Typ is tagged null record
11650 -- with Type_Invariant => Item_1;
11652 -- type Typ is new From_Typ with null record;
11654 -- The full view of Typ would have to inherit any new rep items added to
11655 -- the full view of From_Typ.
11657 -- From_Typ -----------> Item_1 ---> Item_2 ---> Item_3
11659 -- Typ --------> Item_4 --+
11661 -- To achieve this form of inheritance, the destination type must first
11662 -- sever the link between its own rep chain and that of the source type,
11663 -- then inheritance 3.1 takes place.
11665 -- Case 1: The source type lacks a rep item chain
11667 if No (First_Rep_Item (From_Typ)) then
11670 -- Case 2: The destination type lacks a rep item chain
11672 elsif No (First_Rep_Item (Typ)) then
11673 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
11675 -- Case 3: Both the source and destination types have at least one rep
11676 -- item. Traverse the rep item chain of the destination type to find the
11681 Next_Item := First_Rep_Item (Typ);
11682 while Present (Next_Item) loop
11684 -- Detect a link between the destination type's rep chain and that
11685 -- of the source type. There are two possibilities:
11690 -- From_Typ ---> Item_1 --->
11692 -- Typ -----------+
11699 -- From_Typ ---> Item_1 ---> Item_2 --->
11701 -- Typ --------> Item_3 ------+
11705 if Has_Rep_Item (From_Typ, Next_Item) then
11710 Next_Item := Next_Rep_Item (Next_Item);
11713 -- Inherit the source type's rep item chain
11715 if Present (Item) then
11716 Set_Next_Rep_Item (Item, First_Rep_Item (From_Typ));
11718 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
11721 end Inherit_Rep_Item_Chain;
11723 ---------------------------------
11724 -- Insert_Explicit_Dereference --
11725 ---------------------------------
11727 procedure Insert_Explicit_Dereference (N : Node_Id) is
11728 New_Prefix : constant Node_Id := Relocate_Node (N);
11729 Ent : Entity_Id := Empty;
11736 Save_Interps (N, New_Prefix);
11739 Make_Explicit_Dereference (Sloc (Parent (N)),
11740 Prefix => New_Prefix));
11742 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
11744 if Is_Overloaded (New_Prefix) then
11746 -- The dereference is also overloaded, and its interpretations are
11747 -- the designated types of the interpretations of the original node.
11749 Set_Etype (N, Any_Type);
11751 Get_First_Interp (New_Prefix, I, It);
11752 while Present (It.Nam) loop
11755 if Is_Access_Type (T) then
11756 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
11759 Get_Next_Interp (I, It);
11765 -- Prefix is unambiguous: mark the original prefix (which might
11766 -- Come_From_Source) as a reference, since the new (relocated) one
11767 -- won't be taken into account.
11769 if Is_Entity_Name (New_Prefix) then
11770 Ent := Entity (New_Prefix);
11771 Pref := New_Prefix;
11773 -- For a retrieval of a subcomponent of some composite object,
11774 -- retrieve the ultimate entity if there is one.
11776 elsif Nkind_In (New_Prefix, N_Selected_Component,
11777 N_Indexed_Component)
11779 Pref := Prefix (New_Prefix);
11780 while Present (Pref)
11781 and then Nkind_In (Pref, N_Selected_Component,
11782 N_Indexed_Component)
11784 Pref := Prefix (Pref);
11787 if Present (Pref) and then Is_Entity_Name (Pref) then
11788 Ent := Entity (Pref);
11792 -- Place the reference on the entity node
11794 if Present (Ent) then
11795 Generate_Reference (Ent, Pref);
11798 end Insert_Explicit_Dereference;
11800 ------------------------------------------
11801 -- Inspect_Deferred_Constant_Completion --
11802 ------------------------------------------
11804 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
11808 Decl := First (Decls);
11809 while Present (Decl) loop
11811 -- Deferred constant signature
11813 if Nkind (Decl) = N_Object_Declaration
11814 and then Constant_Present (Decl)
11815 and then No (Expression (Decl))
11817 -- No need to check internally generated constants
11819 and then Comes_From_Source (Decl)
11821 -- The constant is not completed. A full object declaration or a
11822 -- pragma Import complete a deferred constant.
11824 and then not Has_Completion (Defining_Identifier (Decl))
11827 ("constant declaration requires initialization expression",
11828 Defining_Identifier (Decl));
11831 Decl := Next (Decl);
11833 end Inspect_Deferred_Constant_Completion;
11835 -----------------------------
11836 -- Install_Generic_Formals --
11837 -----------------------------
11839 procedure Install_Generic_Formals (Subp_Id : Entity_Id) is
11843 pragma Assert (Is_Generic_Subprogram (Subp_Id));
11845 E := First_Entity (Subp_Id);
11846 while Present (E) loop
11847 Install_Entity (E);
11850 end Install_Generic_Formals;
11852 ------------------------
11853 -- Install_SPARK_Mode --
11854 ------------------------
11856 procedure Install_SPARK_Mode (Mode : SPARK_Mode_Type; Prag : Node_Id) is
11858 SPARK_Mode := Mode;
11859 SPARK_Mode_Pragma := Prag;
11860 end Install_SPARK_Mode;
11862 -----------------------------
11863 -- Is_Actual_Out_Parameter --
11864 -----------------------------
11866 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
11867 Formal : Entity_Id;
11870 Find_Actual (N, Formal, Call);
11871 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
11872 end Is_Actual_Out_Parameter;
11874 -------------------------
11875 -- Is_Actual_Parameter --
11876 -------------------------
11878 function Is_Actual_Parameter (N : Node_Id) return Boolean is
11879 PK : constant Node_Kind := Nkind (Parent (N));
11883 when N_Parameter_Association =>
11884 return N = Explicit_Actual_Parameter (Parent (N));
11886 when N_Subprogram_Call =>
11887 return Is_List_Member (N)
11889 List_Containing (N) = Parameter_Associations (Parent (N));
11894 end Is_Actual_Parameter;
11896 --------------------------------
11897 -- Is_Actual_Tagged_Parameter --
11898 --------------------------------
11900 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
11901 Formal : Entity_Id;
11904 Find_Actual (N, Formal, Call);
11905 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
11906 end Is_Actual_Tagged_Parameter;
11908 ---------------------
11909 -- Is_Aliased_View --
11910 ---------------------
11912 function Is_Aliased_View (Obj : Node_Id) return Boolean is
11916 if Is_Entity_Name (Obj) then
11923 or else (Present (Renamed_Object (E))
11924 and then Is_Aliased_View (Renamed_Object (E)))))
11926 or else ((Is_Formal (E)
11927 or else Ekind_In (E, E_Generic_In_Out_Parameter,
11928 E_Generic_In_Parameter))
11929 and then Is_Tagged_Type (Etype (E)))
11931 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
11933 -- Current instance of type, either directly or as rewritten
11934 -- reference to the current object.
11936 or else (Is_Entity_Name (Original_Node (Obj))
11937 and then Present (Entity (Original_Node (Obj)))
11938 and then Is_Type (Entity (Original_Node (Obj))))
11940 or else (Is_Type (E) and then E = Current_Scope)
11942 or else (Is_Incomplete_Or_Private_Type (E)
11943 and then Full_View (E) = Current_Scope)
11945 -- Ada 2012 AI05-0053: the return object of an extended return
11946 -- statement is aliased if its type is immutably limited.
11948 or else (Is_Return_Object (E)
11949 and then Is_Limited_View (Etype (E)));
11951 elsif Nkind (Obj) = N_Selected_Component then
11952 return Is_Aliased (Entity (Selector_Name (Obj)));
11954 elsif Nkind (Obj) = N_Indexed_Component then
11955 return Has_Aliased_Components (Etype (Prefix (Obj)))
11957 (Is_Access_Type (Etype (Prefix (Obj)))
11958 and then Has_Aliased_Components
11959 (Designated_Type (Etype (Prefix (Obj)))));
11961 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
11962 return Is_Tagged_Type (Etype (Obj))
11963 and then Is_Aliased_View (Expression (Obj));
11965 elsif Nkind (Obj) = N_Explicit_Dereference then
11966 return Nkind (Original_Node (Obj)) /= N_Function_Call;
11971 end Is_Aliased_View;
11973 -------------------------
11974 -- Is_Ancestor_Package --
11975 -------------------------
11977 function Is_Ancestor_Package
11979 E2 : Entity_Id) return Boolean
11985 while Present (Par) and then Par /= Standard_Standard loop
11990 Par := Scope (Par);
11994 end Is_Ancestor_Package;
11996 ----------------------
11997 -- Is_Atomic_Object --
11998 ----------------------
12000 function Is_Atomic_Object (N : Node_Id) return Boolean is
12002 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
12003 -- Determines if given object has atomic components
12005 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
12006 -- If prefix is an implicit dereference, examine designated type
12008 ----------------------
12009 -- Is_Atomic_Prefix --
12010 ----------------------
12012 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
12014 if Is_Access_Type (Etype (N)) then
12016 Has_Atomic_Components (Designated_Type (Etype (N)));
12018 return Object_Has_Atomic_Components (N);
12020 end Is_Atomic_Prefix;
12022 ----------------------------------
12023 -- Object_Has_Atomic_Components --
12024 ----------------------------------
12026 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
12028 if Has_Atomic_Components (Etype (N))
12029 or else Is_Atomic (Etype (N))
12033 elsif Is_Entity_Name (N)
12034 and then (Has_Atomic_Components (Entity (N))
12035 or else Is_Atomic (Entity (N)))
12039 elsif Nkind (N) = N_Selected_Component
12040 and then Is_Atomic (Entity (Selector_Name (N)))
12044 elsif Nkind (N) = N_Indexed_Component
12045 or else Nkind (N) = N_Selected_Component
12047 return Is_Atomic_Prefix (Prefix (N));
12052 end Object_Has_Atomic_Components;
12054 -- Start of processing for Is_Atomic_Object
12057 -- Predicate is not relevant to subprograms
12059 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
12062 elsif Is_Atomic (Etype (N))
12063 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
12067 elsif Nkind (N) = N_Selected_Component
12068 and then Is_Atomic (Entity (Selector_Name (N)))
12072 elsif Nkind (N) = N_Indexed_Component
12073 or else Nkind (N) = N_Selected_Component
12075 return Is_Atomic_Prefix (Prefix (N));
12080 end Is_Atomic_Object;
12082 -----------------------------
12083 -- Is_Atomic_Or_VFA_Object --
12084 -----------------------------
12086 function Is_Atomic_Or_VFA_Object (N : Node_Id) return Boolean is
12088 return Is_Atomic_Object (N)
12089 or else (Is_Object_Reference (N)
12090 and then Is_Entity_Name (N)
12091 and then (Is_Volatile_Full_Access (Entity (N))
12093 Is_Volatile_Full_Access (Etype (Entity (N)))));
12094 end Is_Atomic_Or_VFA_Object;
12096 -------------------------
12097 -- Is_Attribute_Result --
12098 -------------------------
12100 function Is_Attribute_Result (N : Node_Id) return Boolean is
12102 return Nkind (N) = N_Attribute_Reference
12103 and then Attribute_Name (N) = Name_Result;
12104 end Is_Attribute_Result;
12106 -------------------------
12107 -- Is_Attribute_Update --
12108 -------------------------
12110 function Is_Attribute_Update (N : Node_Id) return Boolean is
12112 return Nkind (N) = N_Attribute_Reference
12113 and then Attribute_Name (N) = Name_Update;
12114 end Is_Attribute_Update;
12116 ------------------------------------
12117 -- Is_Body_Or_Package_Declaration --
12118 ------------------------------------
12120 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
12122 return Nkind_In (N, N_Entry_Body,
12124 N_Package_Declaration,
12128 end Is_Body_Or_Package_Declaration;
12130 -----------------------
12131 -- Is_Bounded_String --
12132 -----------------------
12134 function Is_Bounded_String (T : Entity_Id) return Boolean is
12135 Under : constant Entity_Id := Underlying_Type (Root_Type (T));
12138 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
12139 -- Super_String, or one of the [Wide_]Wide_ versions. This will
12140 -- be True for all the Bounded_String types in instances of the
12141 -- Generic_Bounded_Length generics, and for types derived from those.
12143 return Present (Under)
12144 and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
12145 Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
12146 Is_RTE (Root_Type (Under), RO_WW_Super_String));
12147 end Is_Bounded_String;
12149 -------------------------
12150 -- Is_Child_Or_Sibling --
12151 -------------------------
12153 function Is_Child_Or_Sibling
12154 (Pack_1 : Entity_Id;
12155 Pack_2 : Entity_Id) return Boolean
12157 function Distance_From_Standard (Pack : Entity_Id) return Nat;
12158 -- Given an arbitrary package, return the number of "climbs" necessary
12159 -- to reach scope Standard_Standard.
12161 procedure Equalize_Depths
12162 (Pack : in out Entity_Id;
12163 Depth : in out Nat;
12164 Depth_To_Reach : Nat);
12165 -- Given an arbitrary package, its depth and a target depth to reach,
12166 -- climb the scope chain until the said depth is reached. The pointer
12167 -- to the package and its depth a modified during the climb.
12169 ----------------------------
12170 -- Distance_From_Standard --
12171 ----------------------------
12173 function Distance_From_Standard (Pack : Entity_Id) return Nat is
12180 while Present (Scop) and then Scop /= Standard_Standard loop
12182 Scop := Scope (Scop);
12186 end Distance_From_Standard;
12188 ---------------------
12189 -- Equalize_Depths --
12190 ---------------------
12192 procedure Equalize_Depths
12193 (Pack : in out Entity_Id;
12194 Depth : in out Nat;
12195 Depth_To_Reach : Nat)
12198 -- The package must be at a greater or equal depth
12200 if Depth < Depth_To_Reach then
12201 raise Program_Error;
12204 -- Climb the scope chain until the desired depth is reached
12206 while Present (Pack) and then Depth /= Depth_To_Reach loop
12207 Pack := Scope (Pack);
12208 Depth := Depth - 1;
12210 end Equalize_Depths;
12214 P_1 : Entity_Id := Pack_1;
12215 P_1_Child : Boolean := False;
12216 P_1_Depth : Nat := Distance_From_Standard (P_1);
12217 P_2 : Entity_Id := Pack_2;
12218 P_2_Child : Boolean := False;
12219 P_2_Depth : Nat := Distance_From_Standard (P_2);
12221 -- Start of processing for Is_Child_Or_Sibling
12225 (Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
12227 -- Both packages denote the same entity, therefore they cannot be
12228 -- children or siblings.
12233 -- One of the packages is at a deeper level than the other. Note that
12234 -- both may still come from differen hierarchies.
12242 elsif P_1_Depth > P_2_Depth then
12245 Depth => P_1_Depth,
12246 Depth_To_Reach => P_2_Depth);
12255 elsif P_2_Depth > P_1_Depth then
12258 Depth => P_2_Depth,
12259 Depth_To_Reach => P_1_Depth);
12263 -- At this stage the package pointers have been elevated to the same
12264 -- depth. If the related entities are the same, then one package is a
12265 -- potential child of the other:
12269 -- X became P_1 P_2 or vica versa
12275 return Is_Child_Unit (Pack_1);
12277 else pragma Assert (P_2_Child);
12278 return Is_Child_Unit (Pack_2);
12281 -- The packages may come from the same package chain or from entirely
12282 -- different hierarcies. To determine this, climb the scope stack until
12283 -- a common root is found.
12285 -- (root) (root 1) (root 2)
12290 while Present (P_1) and then Present (P_2) loop
12292 -- The two packages may be siblings
12295 return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2);
12298 P_1 := Scope (P_1);
12299 P_2 := Scope (P_2);
12304 end Is_Child_Or_Sibling;
12306 -----------------------------
12307 -- Is_Concurrent_Interface --
12308 -----------------------------
12310 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
12312 return Is_Interface (T)
12314 (Is_Protected_Interface (T)
12315 or else Is_Synchronized_Interface (T)
12316 or else Is_Task_Interface (T));
12317 end Is_Concurrent_Interface;
12319 -----------------------
12320 -- Is_Constant_Bound --
12321 -----------------------
12323 function Is_Constant_Bound (Exp : Node_Id) return Boolean is
12325 if Compile_Time_Known_Value (Exp) then
12328 elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
12329 return Is_Constant_Object (Entity (Exp))
12330 or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
12332 elsif Nkind (Exp) in N_Binary_Op then
12333 return Is_Constant_Bound (Left_Opnd (Exp))
12334 and then Is_Constant_Bound (Right_Opnd (Exp))
12335 and then Scope (Entity (Exp)) = Standard_Standard;
12340 end Is_Constant_Bound;
12342 ---------------------------
12343 -- Is_Container_Element --
12344 ---------------------------
12346 function Is_Container_Element (Exp : Node_Id) return Boolean is
12347 Loc : constant Source_Ptr := Sloc (Exp);
12348 Pref : constant Node_Id := Prefix (Exp);
12351 -- Call to an indexing aspect
12353 Cont_Typ : Entity_Id;
12354 -- The type of the container being accessed
12356 Elem_Typ : Entity_Id;
12357 -- Its element type
12359 Indexing : Entity_Id;
12360 Is_Const : Boolean;
12361 -- Indicates that constant indexing is used, and the element is thus
12364 Ref_Typ : Entity_Id;
12365 -- The reference type returned by the indexing operation
12368 -- If C is a container, in a context that imposes the element type of
12369 -- that container, the indexing notation C (X) is rewritten as:
12371 -- Indexing (C, X).Discr.all
12373 -- where Indexing is one of the indexing aspects of the container.
12374 -- If the context does not require a reference, the construct can be
12379 -- First, verify that the construct has the proper form
12381 if not Expander_Active then
12384 elsif Nkind (Pref) /= N_Selected_Component then
12387 elsif Nkind (Prefix (Pref)) /= N_Function_Call then
12391 Call := Prefix (Pref);
12392 Ref_Typ := Etype (Call);
12395 if not Has_Implicit_Dereference (Ref_Typ)
12396 or else No (First (Parameter_Associations (Call)))
12397 or else not Is_Entity_Name (Name (Call))
12402 -- Retrieve type of container object, and its iterator aspects
12404 Cont_Typ := Etype (First (Parameter_Associations (Call)));
12405 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Constant_Indexing);
12408 if No (Indexing) then
12410 -- Container should have at least one indexing operation
12414 elsif Entity (Name (Call)) /= Entity (Indexing) then
12416 -- This may be a variable indexing operation
12418 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Variable_Indexing);
12421 or else Entity (Name (Call)) /= Entity (Indexing)
12430 Elem_Typ := Find_Value_Of_Aspect (Cont_Typ, Aspect_Iterator_Element);
12432 if No (Elem_Typ) or else Entity (Elem_Typ) /= Etype (Exp) then
12436 -- Check that the expression is not the target of an assignment, in
12437 -- which case the rewriting is not possible.
12439 if not Is_Const then
12445 while Present (Par)
12447 if Nkind (Parent (Par)) = N_Assignment_Statement
12448 and then Par = Name (Parent (Par))
12452 -- A renaming produces a reference, and the transformation
12455 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
12459 (Nkind (Parent (Par)), N_Function_Call,
12460 N_Procedure_Call_Statement,
12461 N_Entry_Call_Statement)
12463 -- Check that the element is not part of an actual for an
12464 -- in-out parameter.
12471 F := First_Formal (Entity (Name (Parent (Par))));
12472 A := First (Parameter_Associations (Parent (Par)));
12473 while Present (F) loop
12474 if A = Par and then Ekind (F) /= E_In_Parameter then
12483 -- E_In_Parameter in a call: element is not modified.
12488 Par := Parent (Par);
12493 -- The expression has the proper form and the context requires the
12494 -- element type. Retrieve the Element function of the container and
12495 -- rewrite the construct as a call to it.
12501 Op := First_Elmt (Primitive_Operations (Cont_Typ));
12502 while Present (Op) loop
12503 exit when Chars (Node (Op)) = Name_Element;
12512 Make_Function_Call (Loc,
12513 Name => New_Occurrence_Of (Node (Op), Loc),
12514 Parameter_Associations => Parameter_Associations (Call)));
12515 Analyze_And_Resolve (Exp, Entity (Elem_Typ));
12519 end Is_Container_Element;
12521 ----------------------------
12522 -- Is_Contract_Annotation --
12523 ----------------------------
12525 function Is_Contract_Annotation (Item : Node_Id) return Boolean is
12527 return Is_Package_Contract_Annotation (Item)
12529 Is_Subprogram_Contract_Annotation (Item);
12530 end Is_Contract_Annotation;
12532 --------------------------------------
12533 -- Is_Controlling_Limited_Procedure --
12534 --------------------------------------
12536 function Is_Controlling_Limited_Procedure
12537 (Proc_Nam : Entity_Id) return Boolean
12539 Param_Typ : Entity_Id := Empty;
12542 if Ekind (Proc_Nam) = E_Procedure
12543 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
12545 Param_Typ := Etype (Parameter_Type (First (
12546 Parameter_Specifications (Parent (Proc_Nam)))));
12548 -- In this case where an Itype was created, the procedure call has been
12551 elsif Present (Associated_Node_For_Itype (Proc_Nam))
12552 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
12554 Present (Parameter_Associations
12555 (Associated_Node_For_Itype (Proc_Nam)))
12558 Etype (First (Parameter_Associations
12559 (Associated_Node_For_Itype (Proc_Nam))));
12562 if Present (Param_Typ) then
12564 Is_Interface (Param_Typ)
12565 and then Is_Limited_Record (Param_Typ);
12569 end Is_Controlling_Limited_Procedure;
12571 -----------------------------
12572 -- Is_CPP_Constructor_Call --
12573 -----------------------------
12575 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
12577 return Nkind (N) = N_Function_Call
12578 and then Is_CPP_Class (Etype (Etype (N)))
12579 and then Is_Constructor (Entity (Name (N)))
12580 and then Is_Imported (Entity (Name (N)));
12581 end Is_CPP_Constructor_Call;
12583 -------------------------
12584 -- Is_Current_Instance --
12585 -------------------------
12587 function Is_Current_Instance (N : Node_Id) return Boolean is
12588 Typ : constant Entity_Id := Entity (N);
12592 -- Simplest case: entity is a concurrent type and we are currently
12593 -- inside the body. This will eventually be expanded into a
12594 -- call to Self (for tasks) or _object (for protected objects).
12596 if Is_Concurrent_Type (Typ) and then In_Open_Scopes (Typ) then
12600 -- Check whether the context is a (sub)type declaration for the
12604 while Present (P) loop
12605 if Nkind_In (P, N_Full_Type_Declaration,
12606 N_Private_Type_Declaration,
12607 N_Subtype_Declaration)
12608 and then Comes_From_Source (P)
12609 and then Defining_Entity (P) = Typ
12613 -- A subtype name may appear in an aspect specification for a
12614 -- Predicate_Failure aspect, for which we do not construct a
12615 -- wrapper procedure. The subtype will be replaced by the
12616 -- expression being tested when the corresponding predicate
12617 -- check is expanded.
12619 elsif Nkind (P) = N_Aspect_Specification
12620 and then Nkind (Parent (P)) = N_Subtype_Declaration
12624 elsif Nkind (P) = N_Pragma
12626 Get_Pragma_Id (P) = Pragma_Predicate_Failure
12635 -- In any other context this is not a current occurrence
12638 end Is_Current_Instance;
12640 --------------------
12641 -- Is_Declaration --
12642 --------------------
12644 function Is_Declaration (N : Node_Id) return Boolean is
12647 Is_Declaration_Other_Than_Renaming (N)
12648 or else Is_Renaming_Declaration (N);
12649 end Is_Declaration;
12651 ----------------------------------------
12652 -- Is_Declaration_Other_Than_Renaming --
12653 ----------------------------------------
12655 function Is_Declaration_Other_Than_Renaming (N : Node_Id) return Boolean is
12658 when N_Abstract_Subprogram_Declaration
12659 | N_Exception_Declaration
12660 | N_Expression_Function
12661 | N_Full_Type_Declaration
12662 | N_Generic_Package_Declaration
12663 | N_Generic_Subprogram_Declaration
12664 | N_Number_Declaration
12665 | N_Object_Declaration
12666 | N_Package_Declaration
12667 | N_Private_Extension_Declaration
12668 | N_Private_Type_Declaration
12669 | N_Subprogram_Declaration
12670 | N_Subtype_Declaration
12677 end Is_Declaration_Other_Than_Renaming;
12679 --------------------------------
12680 -- Is_Declared_Within_Variant --
12681 --------------------------------
12683 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
12684 Comp_Decl : constant Node_Id := Parent (Comp);
12685 Comp_List : constant Node_Id := Parent (Comp_Decl);
12687 return Nkind (Parent (Comp_List)) = N_Variant;
12688 end Is_Declared_Within_Variant;
12690 ----------------------------------------------
12691 -- Is_Dependent_Component_Of_Mutable_Object --
12692 ----------------------------------------------
12694 function Is_Dependent_Component_Of_Mutable_Object
12695 (Object : Node_Id) return Boolean
12698 Prefix_Type : Entity_Id;
12699 P_Aliased : Boolean := False;
12702 Deref : Node_Id := Object;
12703 -- Dereference node, in something like X.all.Y(2)
12705 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
12708 -- Find the dereference node if any
12710 while Nkind_In (Deref, N_Indexed_Component,
12711 N_Selected_Component,
12714 Deref := Prefix (Deref);
12717 -- Ada 2005: If we have a component or slice of a dereference,
12718 -- something like X.all.Y (2), and the type of X is access-to-constant,
12719 -- Is_Variable will return False, because it is indeed a constant
12720 -- view. But it might be a view of a variable object, so we want the
12721 -- following condition to be True in that case.
12723 if Is_Variable (Object)
12724 or else (Ada_Version >= Ada_2005
12725 and then Nkind (Deref) = N_Explicit_Dereference)
12727 if Nkind (Object) = N_Selected_Component then
12728 P := Prefix (Object);
12729 Prefix_Type := Etype (P);
12731 if Is_Entity_Name (P) then
12732 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
12733 Prefix_Type := Base_Type (Prefix_Type);
12736 if Is_Aliased (Entity (P)) then
12740 -- A discriminant check on a selected component may be expanded
12741 -- into a dereference when removing side-effects. Recover the
12742 -- original node and its type, which may be unconstrained.
12744 elsif Nkind (P) = N_Explicit_Dereference
12745 and then not (Comes_From_Source (P))
12747 P := Original_Node (P);
12748 Prefix_Type := Etype (P);
12751 -- Check for prefix being an aliased component???
12757 -- A heap object is constrained by its initial value
12759 -- Ada 2005 (AI-363): Always assume the object could be mutable in
12760 -- the dereferenced case, since the access value might denote an
12761 -- unconstrained aliased object, whereas in Ada 95 the designated
12762 -- object is guaranteed to be constrained. A worst-case assumption
12763 -- has to apply in Ada 2005 because we can't tell at compile
12764 -- time whether the object is "constrained by its initial value"
12765 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
12766 -- rules (these rules are acknowledged to need fixing).
12768 if Ada_Version < Ada_2005 then
12769 if Is_Access_Type (Prefix_Type)
12770 or else Nkind (P) = N_Explicit_Dereference
12775 else pragma Assert (Ada_Version >= Ada_2005);
12776 if Is_Access_Type (Prefix_Type) then
12778 -- If the access type is pool-specific, and there is no
12779 -- constrained partial view of the designated type, then the
12780 -- designated object is known to be constrained.
12782 if Ekind (Prefix_Type) = E_Access_Type
12783 and then not Object_Type_Has_Constrained_Partial_View
12784 (Typ => Designated_Type (Prefix_Type),
12785 Scop => Current_Scope)
12789 -- Otherwise (general access type, or there is a constrained
12790 -- partial view of the designated type), we need to check
12791 -- based on the designated type.
12794 Prefix_Type := Designated_Type (Prefix_Type);
12800 Original_Record_Component (Entity (Selector_Name (Object)));
12802 -- As per AI-0017, the renaming is illegal in a generic body, even
12803 -- if the subtype is indefinite.
12805 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
12807 if not Is_Constrained (Prefix_Type)
12808 and then (Is_Definite_Subtype (Prefix_Type)
12810 (Is_Generic_Type (Prefix_Type)
12811 and then Ekind (Current_Scope) = E_Generic_Package
12812 and then In_Package_Body (Current_Scope)))
12814 and then (Is_Declared_Within_Variant (Comp)
12815 or else Has_Discriminant_Dependent_Constraint (Comp))
12816 and then (not P_Aliased or else Ada_Version >= Ada_2005)
12820 -- If the prefix is of an access type at this point, then we want
12821 -- to return False, rather than calling this function recursively
12822 -- on the access object (which itself might be a discriminant-
12823 -- dependent component of some other object, but that isn't
12824 -- relevant to checking the object passed to us). This avoids
12825 -- issuing wrong errors when compiling with -gnatc, where there
12826 -- can be implicit dereferences that have not been expanded.
12828 elsif Is_Access_Type (Etype (Prefix (Object))) then
12833 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
12836 elsif Nkind (Object) = N_Indexed_Component
12837 or else Nkind (Object) = N_Slice
12839 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
12841 -- A type conversion that Is_Variable is a view conversion:
12842 -- go back to the denoted object.
12844 elsif Nkind (Object) = N_Type_Conversion then
12846 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
12851 end Is_Dependent_Component_Of_Mutable_Object;
12853 ---------------------
12854 -- Is_Dereferenced --
12855 ---------------------
12857 function Is_Dereferenced (N : Node_Id) return Boolean is
12858 P : constant Node_Id := Parent (N);
12860 return Nkind_In (P, N_Selected_Component,
12861 N_Explicit_Dereference,
12862 N_Indexed_Component,
12864 and then Prefix (P) = N;
12865 end Is_Dereferenced;
12867 ----------------------
12868 -- Is_Descendant_Of --
12869 ----------------------
12871 function Is_Descendant_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
12876 pragma Assert (Nkind (T1) in N_Entity);
12877 pragma Assert (Nkind (T2) in N_Entity);
12879 T := Base_Type (T1);
12881 -- Immediate return if the types match
12886 -- Comment needed here ???
12888 elsif Ekind (T) = E_Class_Wide_Type then
12889 return Etype (T) = T2;
12897 -- Done if we found the type we are looking for
12902 -- Done if no more derivations to check
12909 -- Following test catches error cases resulting from prev errors
12911 elsif No (Etyp) then
12914 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
12917 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
12921 T := Base_Type (Etyp);
12924 end Is_Descendant_Of;
12926 ----------------------------------------
12927 -- Is_Descendant_Of_Suspension_Object --
12928 ----------------------------------------
12930 function Is_Descendant_Of_Suspension_Object
12931 (Typ : Entity_Id) return Boolean
12933 Cur_Typ : Entity_Id;
12934 Par_Typ : Entity_Id;
12937 -- Climb the type derivation chain checking each parent type against
12938 -- Suspension_Object.
12940 Cur_Typ := Base_Type (Typ);
12941 while Present (Cur_Typ) loop
12942 Par_Typ := Etype (Cur_Typ);
12944 -- The current type is a match
12946 if Is_Suspension_Object (Cur_Typ) then
12949 -- Stop the traversal once the root of the derivation chain has been
12950 -- reached. In that case the current type is its own base type.
12952 elsif Cur_Typ = Par_Typ then
12956 Cur_Typ := Base_Type (Par_Typ);
12960 end Is_Descendant_Of_Suspension_Object;
12962 ---------------------------------------------
12963 -- Is_Double_Precision_Floating_Point_Type --
12964 ---------------------------------------------
12966 function Is_Double_Precision_Floating_Point_Type
12967 (E : Entity_Id) return Boolean is
12969 return Is_Floating_Point_Type (E)
12970 and then Machine_Radix_Value (E) = Uint_2
12971 and then Machine_Mantissa_Value (E) = UI_From_Int (53)
12972 and then Machine_Emax_Value (E) = Uint_2 ** Uint_10
12973 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_10);
12974 end Is_Double_Precision_Floating_Point_Type;
12976 -----------------------------
12977 -- Is_Effectively_Volatile --
12978 -----------------------------
12980 function Is_Effectively_Volatile (Id : Entity_Id) return Boolean is
12982 if Is_Type (Id) then
12984 -- An arbitrary type is effectively volatile when it is subject to
12985 -- pragma Atomic or Volatile.
12987 if Is_Volatile (Id) then
12990 -- An array type is effectively volatile when it is subject to pragma
12991 -- Atomic_Components or Volatile_Components or its component type is
12992 -- effectively volatile.
12994 elsif Is_Array_Type (Id) then
12996 Anc : Entity_Id := Base_Type (Id);
12998 if Is_Private_Type (Anc) then
12999 Anc := Full_View (Anc);
13002 -- Test for presence of ancestor, as the full view of a private
13003 -- type may be missing in case of error.
13006 Has_Volatile_Components (Id)
13009 and then Is_Effectively_Volatile (Component_Type (Anc)));
13012 -- A protected type is always volatile
13014 elsif Is_Protected_Type (Id) then
13017 -- A descendant of Ada.Synchronous_Task_Control.Suspension_Object is
13018 -- automatically volatile.
13020 elsif Is_Descendant_Of_Suspension_Object (Id) then
13023 -- Otherwise the type is not effectively volatile
13029 -- Otherwise Id denotes an object
13034 or else Has_Volatile_Components (Id)
13035 or else Is_Effectively_Volatile (Etype (Id));
13037 end Is_Effectively_Volatile;
13039 ------------------------------------
13040 -- Is_Effectively_Volatile_Object --
13041 ------------------------------------
13043 function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean is
13045 if Is_Entity_Name (N) then
13046 return Is_Effectively_Volatile (Entity (N));
13048 elsif Nkind (N) = N_Indexed_Component then
13049 return Is_Effectively_Volatile_Object (Prefix (N));
13051 elsif Nkind (N) = N_Selected_Component then
13053 Is_Effectively_Volatile_Object (Prefix (N))
13055 Is_Effectively_Volatile_Object (Selector_Name (N));
13060 end Is_Effectively_Volatile_Object;
13062 -------------------
13063 -- Is_Entry_Body --
13064 -------------------
13066 function Is_Entry_Body (Id : Entity_Id) return Boolean is
13069 Ekind_In (Id, E_Entry, E_Entry_Family)
13070 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Body;
13073 --------------------------
13074 -- Is_Entry_Declaration --
13075 --------------------------
13077 function Is_Entry_Declaration (Id : Entity_Id) return Boolean is
13080 Ekind_In (Id, E_Entry, E_Entry_Family)
13081 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Declaration;
13082 end Is_Entry_Declaration;
13084 ------------------------------------
13085 -- Is_Expanded_Priority_Attribute --
13086 ------------------------------------
13088 function Is_Expanded_Priority_Attribute (E : Entity_Id) return Boolean is
13091 Nkind (E) = N_Function_Call
13092 and then not Configurable_Run_Time_Mode
13093 and then (Entity (Name (E)) = RTE (RE_Get_Ceiling)
13094 or else Entity (Name (E)) = RTE (RO_PE_Get_Ceiling));
13095 end Is_Expanded_Priority_Attribute;
13097 ----------------------------
13098 -- Is_Expression_Function --
13099 ----------------------------
13101 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
13103 if Ekind_In (Subp, E_Function, E_Subprogram_Body) then
13105 Nkind (Original_Node (Unit_Declaration_Node (Subp))) =
13106 N_Expression_Function;
13110 end Is_Expression_Function;
13112 ------------------------------------------
13113 -- Is_Expression_Function_Or_Completion --
13114 ------------------------------------------
13116 function Is_Expression_Function_Or_Completion
13117 (Subp : Entity_Id) return Boolean
13119 Subp_Decl : Node_Id;
13122 if Ekind (Subp) = E_Function then
13123 Subp_Decl := Unit_Declaration_Node (Subp);
13125 -- The function declaration is either an expression function or is
13126 -- completed by an expression function body.
13129 Is_Expression_Function (Subp)
13130 or else (Nkind (Subp_Decl) = N_Subprogram_Declaration
13131 and then Present (Corresponding_Body (Subp_Decl))
13132 and then Is_Expression_Function
13133 (Corresponding_Body (Subp_Decl)));
13135 elsif Ekind (Subp) = E_Subprogram_Body then
13136 return Is_Expression_Function (Subp);
13141 end Is_Expression_Function_Or_Completion;
13143 -----------------------
13144 -- Is_EVF_Expression --
13145 -----------------------
13147 function Is_EVF_Expression (N : Node_Id) return Boolean is
13148 Orig_N : constant Node_Id := Original_Node (N);
13154 -- Detect a reference to a formal parameter of a specific tagged type
13155 -- whose related subprogram is subject to pragma Expresions_Visible with
13158 if Is_Entity_Name (N) and then Present (Entity (N)) then
13163 and then Is_Specific_Tagged_Type (Etype (Id))
13164 and then Extensions_Visible_Status (Id) =
13165 Extensions_Visible_False;
13167 -- A case expression is an EVF expression when it contains at least one
13168 -- EVF dependent_expression. Note that a case expression may have been
13169 -- expanded, hence the use of Original_Node.
13171 elsif Nkind (Orig_N) = N_Case_Expression then
13172 Alt := First (Alternatives (Orig_N));
13173 while Present (Alt) loop
13174 if Is_EVF_Expression (Expression (Alt)) then
13181 -- An if expression is an EVF expression when it contains at least one
13182 -- EVF dependent_expression. Note that an if expression may have been
13183 -- expanded, hence the use of Original_Node.
13185 elsif Nkind (Orig_N) = N_If_Expression then
13186 Expr := Next (First (Expressions (Orig_N)));
13187 while Present (Expr) loop
13188 if Is_EVF_Expression (Expr) then
13195 -- A qualified expression or a type conversion is an EVF expression when
13196 -- its operand is an EVF expression.
13198 elsif Nkind_In (N, N_Qualified_Expression,
13199 N_Unchecked_Type_Conversion,
13202 return Is_EVF_Expression (Expression (N));
13204 -- Attributes 'Loop_Entry, 'Old, and 'Update are EVF expressions when
13205 -- their prefix denotes an EVF expression.
13207 elsif Nkind (N) = N_Attribute_Reference
13208 and then Nam_In (Attribute_Name (N), Name_Loop_Entry,
13212 return Is_EVF_Expression (Prefix (N));
13216 end Is_EVF_Expression;
13222 function Is_False (U : Uint) return Boolean is
13227 ---------------------------
13228 -- Is_Fixed_Model_Number --
13229 ---------------------------
13231 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
13232 S : constant Ureal := Small_Value (T);
13233 M : Urealp.Save_Mark;
13238 R := (U = UR_Trunc (U / S) * S);
13239 Urealp.Release (M);
13241 end Is_Fixed_Model_Number;
13243 -------------------------------
13244 -- Is_Fully_Initialized_Type --
13245 -------------------------------
13247 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
13251 if Is_Scalar_Type (Typ) then
13253 -- A scalar type with an aspect Default_Value is fully initialized
13255 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
13256 -- of a scalar type, but we don't take that into account here, since
13257 -- we don't want these to affect warnings.
13259 return Has_Default_Aspect (Typ);
13261 elsif Is_Access_Type (Typ) then
13264 elsif Is_Array_Type (Typ) then
13265 if Is_Fully_Initialized_Type (Component_Type (Typ))
13266 or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
13271 -- An interesting case, if we have a constrained type one of whose
13272 -- bounds is known to be null, then there are no elements to be
13273 -- initialized, so all the elements are initialized.
13275 if Is_Constrained (Typ) then
13278 Indx_Typ : Entity_Id;
13279 Lbd, Hbd : Node_Id;
13282 Indx := First_Index (Typ);
13283 while Present (Indx) loop
13284 if Etype (Indx) = Any_Type then
13287 -- If index is a range, use directly
13289 elsif Nkind (Indx) = N_Range then
13290 Lbd := Low_Bound (Indx);
13291 Hbd := High_Bound (Indx);
13294 Indx_Typ := Etype (Indx);
13296 if Is_Private_Type (Indx_Typ) then
13297 Indx_Typ := Full_View (Indx_Typ);
13300 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
13303 Lbd := Type_Low_Bound (Indx_Typ);
13304 Hbd := Type_High_Bound (Indx_Typ);
13308 if Compile_Time_Known_Value (Lbd)
13310 Compile_Time_Known_Value (Hbd)
13312 if Expr_Value (Hbd) < Expr_Value (Lbd) then
13322 -- If no null indexes, then type is not fully initialized
13328 elsif Is_Record_Type (Typ) then
13329 if Has_Discriminants (Typ)
13331 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
13332 and then Is_Fully_Initialized_Variant (Typ)
13337 -- We consider bounded string types to be fully initialized, because
13338 -- otherwise we get false alarms when the Data component is not
13339 -- default-initialized.
13341 if Is_Bounded_String (Typ) then
13345 -- Controlled records are considered to be fully initialized if
13346 -- there is a user defined Initialize routine. This may not be
13347 -- entirely correct, but as the spec notes, we are guessing here
13348 -- what is best from the point of view of issuing warnings.
13350 if Is_Controlled (Typ) then
13352 Utyp : constant Entity_Id := Underlying_Type (Typ);
13355 if Present (Utyp) then
13357 Init : constant Entity_Id :=
13358 (Find_Optional_Prim_Op
13359 (Underlying_Type (Typ), Name_Initialize));
13363 and then Comes_From_Source (Init)
13365 Is_Predefined_File_Name
13366 (File_Name (Get_Source_File_Index (Sloc (Init))))
13370 elsif Has_Null_Extension (Typ)
13372 Is_Fully_Initialized_Type
13373 (Etype (Base_Type (Typ)))
13382 -- Otherwise see if all record components are initialized
13388 Ent := First_Entity (Typ);
13389 while Present (Ent) loop
13390 if Ekind (Ent) = E_Component
13391 and then (No (Parent (Ent))
13392 or else No (Expression (Parent (Ent))))
13393 and then not Is_Fully_Initialized_Type (Etype (Ent))
13395 -- Special VM case for tag components, which need to be
13396 -- defined in this case, but are never initialized as VMs
13397 -- are using other dispatching mechanisms. Ignore this
13398 -- uninitialized case. Note that this applies both to the
13399 -- uTag entry and the main vtable pointer (CPP_Class case).
13401 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
13410 -- No uninitialized components, so type is fully initialized.
13411 -- Note that this catches the case of no components as well.
13415 elsif Is_Concurrent_Type (Typ) then
13418 elsif Is_Private_Type (Typ) then
13420 U : constant Entity_Id := Underlying_Type (Typ);
13426 return Is_Fully_Initialized_Type (U);
13433 end Is_Fully_Initialized_Type;
13435 ----------------------------------
13436 -- Is_Fully_Initialized_Variant --
13437 ----------------------------------
13439 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
13440 Loc : constant Source_Ptr := Sloc (Typ);
13441 Constraints : constant List_Id := New_List;
13442 Components : constant Elist_Id := New_Elmt_List;
13443 Comp_Elmt : Elmt_Id;
13445 Comp_List : Node_Id;
13447 Discr_Val : Node_Id;
13449 Report_Errors : Boolean;
13450 pragma Warnings (Off, Report_Errors);
13453 if Serious_Errors_Detected > 0 then
13457 if Is_Record_Type (Typ)
13458 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
13459 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
13461 Comp_List := Component_List (Type_Definition (Parent (Typ)));
13463 Discr := First_Discriminant (Typ);
13464 while Present (Discr) loop
13465 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
13466 Discr_Val := Expression (Parent (Discr));
13468 if Present (Discr_Val)
13469 and then Is_OK_Static_Expression (Discr_Val)
13471 Append_To (Constraints,
13472 Make_Component_Association (Loc,
13473 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
13474 Expression => New_Copy (Discr_Val)));
13482 Next_Discriminant (Discr);
13487 Comp_List => Comp_List,
13488 Governed_By => Constraints,
13489 Into => Components,
13490 Report_Errors => Report_Errors);
13492 -- Check that each component present is fully initialized
13494 Comp_Elmt := First_Elmt (Components);
13495 while Present (Comp_Elmt) loop
13496 Comp_Id := Node (Comp_Elmt);
13498 if Ekind (Comp_Id) = E_Component
13499 and then (No (Parent (Comp_Id))
13500 or else No (Expression (Parent (Comp_Id))))
13501 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
13506 Next_Elmt (Comp_Elmt);
13511 elsif Is_Private_Type (Typ) then
13513 U : constant Entity_Id := Underlying_Type (Typ);
13519 return Is_Fully_Initialized_Variant (U);
13526 end Is_Fully_Initialized_Variant;
13528 ------------------------------------
13529 -- Is_Generic_Declaration_Or_Body --
13530 ------------------------------------
13532 function Is_Generic_Declaration_Or_Body (Decl : Node_Id) return Boolean is
13533 Spec_Decl : Node_Id;
13536 -- Package/subprogram body
13538 if Nkind_In (Decl, N_Package_Body, N_Subprogram_Body)
13539 and then Present (Corresponding_Spec (Decl))
13541 Spec_Decl := Unit_Declaration_Node (Corresponding_Spec (Decl));
13543 -- Package/subprogram body stub
13545 elsif Nkind_In (Decl, N_Package_Body_Stub, N_Subprogram_Body_Stub)
13546 and then Present (Corresponding_Spec_Of_Stub (Decl))
13549 Unit_Declaration_Node (Corresponding_Spec_Of_Stub (Decl));
13557 -- Rather than inspecting the defining entity of the spec declaration,
13558 -- look at its Nkind. This takes care of the case where the analysis of
13559 -- a generic body modifies the Ekind of its spec to allow for recursive
13563 Nkind_In (Spec_Decl, N_Generic_Package_Declaration,
13564 N_Generic_Subprogram_Declaration);
13565 end Is_Generic_Declaration_Or_Body;
13567 ----------------------------
13568 -- Is_Inherited_Operation --
13569 ----------------------------
13571 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
13572 pragma Assert (Is_Overloadable (E));
13573 Kind : constant Node_Kind := Nkind (Parent (E));
13575 return Kind = N_Full_Type_Declaration
13576 or else Kind = N_Private_Extension_Declaration
13577 or else Kind = N_Subtype_Declaration
13578 or else (Ekind (E) = E_Enumeration_Literal
13579 and then Is_Derived_Type (Etype (E)));
13580 end Is_Inherited_Operation;
13582 -------------------------------------
13583 -- Is_Inherited_Operation_For_Type --
13584 -------------------------------------
13586 function Is_Inherited_Operation_For_Type
13588 Typ : Entity_Id) return Boolean
13591 -- Check that the operation has been created by the type declaration
13593 return Is_Inherited_Operation (E)
13594 and then Defining_Identifier (Parent (E)) = Typ;
13595 end Is_Inherited_Operation_For_Type;
13597 --------------------------------------
13598 -- Is_Inlinable_Expression_Function --
13599 --------------------------------------
13601 function Is_Inlinable_Expression_Function
13602 (Subp : Entity_Id) return Boolean
13604 Return_Expr : Node_Id;
13607 if Is_Expression_Function_Or_Completion (Subp)
13608 and then Has_Pragma_Inline_Always (Subp)
13609 and then Needs_No_Actuals (Subp)
13610 and then No (Contract (Subp))
13611 and then not Is_Dispatching_Operation (Subp)
13612 and then Needs_Finalization (Etype (Subp))
13613 and then not Is_Class_Wide_Type (Etype (Subp))
13614 and then not (Has_Invariants (Etype (Subp)))
13615 and then Present (Subprogram_Body (Subp))
13616 and then Was_Expression_Function (Subprogram_Body (Subp))
13618 Return_Expr := Expression_Of_Expression_Function (Subp);
13620 -- The returned object must not have a qualified expression and its
13621 -- nominal subtype must be statically compatible with the result
13622 -- subtype of the expression function.
13625 Nkind (Return_Expr) = N_Identifier
13626 and then Etype (Return_Expr) = Etype (Subp);
13630 end Is_Inlinable_Expression_Function;
13636 function Is_Iterator (Typ : Entity_Id) return Boolean is
13637 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean;
13638 -- Determine whether type Iter_Typ is a predefined forward or reversible
13641 ----------------------
13642 -- Denotes_Iterator --
13643 ----------------------
13645 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean is
13647 -- Check that the name matches, and that the ultimate ancestor is in
13648 -- a predefined unit, i.e the one that declares iterator interfaces.
13651 Nam_In (Chars (Iter_Typ), Name_Forward_Iterator,
13652 Name_Reversible_Iterator)
13653 and then Is_Predefined_File_Name
13654 (Unit_File_Name (Get_Source_Unit (Root_Type (Iter_Typ))));
13655 end Denotes_Iterator;
13659 Iface_Elmt : Elmt_Id;
13662 -- Start of processing for Is_Iterator
13665 -- The type may be a subtype of a descendant of the proper instance of
13666 -- the predefined interface type, so we must use the root type of the
13667 -- given type. The same is done for Is_Reversible_Iterator.
13669 if Is_Class_Wide_Type (Typ)
13670 and then Denotes_Iterator (Root_Type (Typ))
13674 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
13677 elsif Present (Find_Value_Of_Aspect (Typ, Aspect_Iterable)) then
13681 Collect_Interfaces (Typ, Ifaces);
13683 Iface_Elmt := First_Elmt (Ifaces);
13684 while Present (Iface_Elmt) loop
13685 if Denotes_Iterator (Node (Iface_Elmt)) then
13689 Next_Elmt (Iface_Elmt);
13696 ----------------------------
13697 -- Is_Iterator_Over_Array --
13698 ----------------------------
13700 function Is_Iterator_Over_Array (N : Node_Id) return Boolean is
13701 Container : constant Node_Id := Name (N);
13702 Container_Typ : constant Entity_Id := Base_Type (Etype (Container));
13704 return Is_Array_Type (Container_Typ);
13705 end Is_Iterator_Over_Array;
13711 -- We seem to have a lot of overlapping functions that do similar things
13712 -- (testing for left hand sides or lvalues???).
13714 function Is_LHS (N : Node_Id) return Is_LHS_Result is
13715 P : constant Node_Id := Parent (N);
13718 -- Return True if we are the left hand side of an assignment statement
13720 if Nkind (P) = N_Assignment_Statement then
13721 if Name (P) = N then
13727 -- Case of prefix of indexed or selected component or slice
13729 elsif Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
13730 and then N = Prefix (P)
13732 -- Here we have the case where the parent P is N.Q or N(Q .. R).
13733 -- If P is an LHS, then N is also effectively an LHS, but there
13734 -- is an important exception. If N is of an access type, then
13735 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
13736 -- case this makes N.all a left hand side but not N itself.
13738 -- If we don't know the type yet, this is the case where we return
13739 -- Unknown, since the answer depends on the type which is unknown.
13741 if No (Etype (N)) then
13744 -- We have an Etype set, so we can check it
13746 elsif Is_Access_Type (Etype (N)) then
13749 -- OK, not access type case, so just test whole expression
13755 -- All other cases are not left hand sides
13762 -----------------------------
13763 -- Is_Library_Level_Entity --
13764 -----------------------------
13766 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
13768 -- The following is a small optimization, and it also properly handles
13769 -- discriminals, which in task bodies might appear in expressions before
13770 -- the corresponding procedure has been created, and which therefore do
13771 -- not have an assigned scope.
13773 if Is_Formal (E) then
13777 -- Normal test is simply that the enclosing dynamic scope is Standard
13779 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
13780 end Is_Library_Level_Entity;
13782 --------------------------------
13783 -- Is_Limited_Class_Wide_Type --
13784 --------------------------------
13786 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
13789 Is_Class_Wide_Type (Typ)
13790 and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
13791 end Is_Limited_Class_Wide_Type;
13793 ---------------------------------
13794 -- Is_Local_Variable_Reference --
13795 ---------------------------------
13797 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
13799 if not Is_Entity_Name (Expr) then
13804 Ent : constant Entity_Id := Entity (Expr);
13805 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
13807 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
13810 return Present (Sub) and then Sub = Current_Subprogram;
13814 end Is_Local_Variable_Reference;
13816 -----------------------
13817 -- Is_Name_Reference --
13818 -----------------------
13820 function Is_Name_Reference (N : Node_Id) return Boolean is
13822 if Is_Entity_Name (N) then
13823 return Present (Entity (N)) and then Is_Object (Entity (N));
13827 when N_Indexed_Component
13831 Is_Name_Reference (Prefix (N))
13832 or else Is_Access_Type (Etype (Prefix (N)));
13834 -- Attributes 'Input, 'Old and 'Result produce objects
13836 when N_Attribute_Reference =>
13838 Nam_In (Attribute_Name (N), Name_Input, Name_Old, Name_Result);
13840 when N_Selected_Component =>
13842 Is_Name_Reference (Selector_Name (N))
13844 (Is_Name_Reference (Prefix (N))
13845 or else Is_Access_Type (Etype (Prefix (N))));
13847 when N_Explicit_Dereference =>
13850 -- A view conversion of a tagged name is a name reference
13852 when N_Type_Conversion =>
13854 Is_Tagged_Type (Etype (Subtype_Mark (N)))
13855 and then Is_Tagged_Type (Etype (Expression (N)))
13856 and then Is_Name_Reference (Expression (N));
13858 -- An unchecked type conversion is considered to be a name if the
13859 -- operand is a name (this construction arises only as a result of
13860 -- expansion activities).
13862 when N_Unchecked_Type_Conversion =>
13863 return Is_Name_Reference (Expression (N));
13868 end Is_Name_Reference;
13870 ---------------------------------
13871 -- Is_Nontrivial_DIC_Procedure --
13872 ---------------------------------
13874 function Is_Nontrivial_DIC_Procedure (Id : Entity_Id) return Boolean is
13875 Body_Decl : Node_Id;
13879 if Ekind (Id) = E_Procedure and then Is_DIC_Procedure (Id) then
13881 Unit_Declaration_Node
13882 (Corresponding_Body (Unit_Declaration_Node (Id)));
13884 -- The body of the Default_Initial_Condition procedure must contain
13885 -- at least one statement, otherwise the generation of the subprogram
13888 pragma Assert (Present (Handled_Statement_Sequence (Body_Decl)));
13890 -- To qualify as nontrivial, the first statement of the procedure
13891 -- must be a check in the form of an if statement. If the original
13892 -- Default_Initial_Condition expression was folded, then the first
13893 -- statement is not a check.
13895 Stmt := First (Statements (Handled_Statement_Sequence (Body_Decl)));
13898 Nkind (Stmt) = N_If_Statement
13899 and then Nkind (Original_Node (Stmt)) = N_Pragma;
13903 end Is_Nontrivial_DIC_Procedure;
13905 -------------------------
13906 -- Is_Null_Record_Type --
13907 -------------------------
13909 function Is_Null_Record_Type (T : Entity_Id) return Boolean is
13910 Decl : constant Node_Id := Parent (T);
13912 return Nkind (Decl) = N_Full_Type_Declaration
13913 and then Nkind (Type_Definition (Decl)) = N_Record_Definition
13915 (No (Component_List (Type_Definition (Decl)))
13916 or else Null_Present (Component_List (Type_Definition (Decl))));
13917 end Is_Null_Record_Type;
13919 -------------------------
13920 -- Is_Object_Reference --
13921 -------------------------
13923 function Is_Object_Reference (N : Node_Id) return Boolean is
13924 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean;
13925 -- Determine whether N is the name of an internally-generated renaming
13927 --------------------------------------
13928 -- Is_Internally_Generated_Renaming --
13929 --------------------------------------
13931 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean is
13936 while Present (P) loop
13937 if Nkind (P) = N_Object_Renaming_Declaration then
13938 return not Comes_From_Source (P);
13939 elsif Is_List_Member (P) then
13947 end Is_Internally_Generated_Renaming;
13949 -- Start of processing for Is_Object_Reference
13952 if Is_Entity_Name (N) then
13953 return Present (Entity (N)) and then Is_Object (Entity (N));
13957 when N_Indexed_Component
13961 Is_Object_Reference (Prefix (N))
13962 or else Is_Access_Type (Etype (Prefix (N)));
13964 -- In Ada 95, a function call is a constant object; a procedure
13967 when N_Function_Call =>
13968 return Etype (N) /= Standard_Void_Type;
13970 -- Attributes 'Input, 'Loop_Entry, 'Old, and 'Result produce
13973 when N_Attribute_Reference =>
13975 Nam_In (Attribute_Name (N), Name_Input,
13980 when N_Selected_Component =>
13982 Is_Object_Reference (Selector_Name (N))
13984 (Is_Object_Reference (Prefix (N))
13985 or else Is_Access_Type (Etype (Prefix (N))));
13987 -- An explicit dereference denotes an object, except that a
13988 -- conditional expression gets turned into an explicit dereference
13989 -- in some cases, and conditional expressions are not object
13992 when N_Explicit_Dereference =>
13993 return not Nkind_In (Original_Node (N), N_Case_Expression,
13996 -- A view conversion of a tagged object is an object reference
13998 when N_Type_Conversion =>
13999 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
14000 and then Is_Tagged_Type (Etype (Expression (N)))
14001 and then Is_Object_Reference (Expression (N));
14003 -- An unchecked type conversion is considered to be an object if
14004 -- the operand is an object (this construction arises only as a
14005 -- result of expansion activities).
14007 when N_Unchecked_Type_Conversion =>
14010 -- Allow string literals to act as objects as long as they appear
14011 -- in internally-generated renamings. The expansion of iterators
14012 -- may generate such renamings when the range involves a string
14015 when N_String_Literal =>
14016 return Is_Internally_Generated_Renaming (Parent (N));
14018 -- AI05-0003: In Ada 2012 a qualified expression is a name.
14019 -- This allows disambiguation of function calls and the use
14020 -- of aggregates in more contexts.
14022 when N_Qualified_Expression =>
14023 if Ada_Version < Ada_2012 then
14026 return Is_Object_Reference (Expression (N))
14027 or else Nkind (Expression (N)) = N_Aggregate;
14034 end Is_Object_Reference;
14036 -----------------------------------
14037 -- Is_OK_Variable_For_Out_Formal --
14038 -----------------------------------
14040 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
14042 Note_Possible_Modification (AV, Sure => True);
14044 -- We must reject parenthesized variable names. Comes_From_Source is
14045 -- checked because there are currently cases where the compiler violates
14046 -- this rule (e.g. passing a task object to its controlled Initialize
14047 -- routine). This should be properly documented in sinfo???
14049 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
14052 -- A variable is always allowed
14054 elsif Is_Variable (AV) then
14057 -- Generalized indexing operations are rewritten as explicit
14058 -- dereferences, and it is only during resolution that we can
14059 -- check whether the context requires an access_to_variable type.
14061 elsif Nkind (AV) = N_Explicit_Dereference
14062 and then Ada_Version >= Ada_2012
14063 and then Nkind (Original_Node (AV)) = N_Indexed_Component
14064 and then Present (Etype (Original_Node (AV)))
14065 and then Has_Implicit_Dereference (Etype (Original_Node (AV)))
14067 return not Is_Access_Constant (Etype (Prefix (AV)));
14069 -- Unchecked conversions are allowed only if they come from the
14070 -- generated code, which sometimes uses unchecked conversions for out
14071 -- parameters in cases where code generation is unaffected. We tell
14072 -- source unchecked conversions by seeing if they are rewrites of
14073 -- an original Unchecked_Conversion function call, or of an explicit
14074 -- conversion of a function call or an aggregate (as may happen in the
14075 -- expansion of a packed array aggregate).
14077 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
14078 if Nkind_In (Original_Node (AV), N_Function_Call, N_Aggregate) then
14081 elsif Comes_From_Source (AV)
14082 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
14086 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
14087 return Is_OK_Variable_For_Out_Formal (Expression (AV));
14093 -- Normal type conversions are allowed if argument is a variable
14095 elsif Nkind (AV) = N_Type_Conversion then
14096 if Is_Variable (Expression (AV))
14097 and then Paren_Count (Expression (AV)) = 0
14099 Note_Possible_Modification (Expression (AV), Sure => True);
14102 -- We also allow a non-parenthesized expression that raises
14103 -- constraint error if it rewrites what used to be a variable
14105 elsif Raises_Constraint_Error (Expression (AV))
14106 and then Paren_Count (Expression (AV)) = 0
14107 and then Is_Variable (Original_Node (Expression (AV)))
14111 -- Type conversion of something other than a variable
14117 -- If this node is rewritten, then test the original form, if that is
14118 -- OK, then we consider the rewritten node OK (for example, if the
14119 -- original node is a conversion, then Is_Variable will not be true
14120 -- but we still want to allow the conversion if it converts a variable).
14122 elsif Original_Node (AV) /= AV then
14124 -- In Ada 2012, the explicit dereference may be a rewritten call to a
14125 -- Reference function.
14127 if Ada_Version >= Ada_2012
14128 and then Nkind (Original_Node (AV)) = N_Function_Call
14130 Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
14133 -- Check that this is not a constant reference.
14135 return not Is_Access_Constant (Etype (Prefix (AV)));
14137 elsif Has_Implicit_Dereference (Etype (Original_Node (AV))) then
14139 not Is_Access_Constant (Etype
14140 (Get_Reference_Discriminant (Etype (Original_Node (AV)))));
14143 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
14146 -- All other non-variables are rejected
14151 end Is_OK_Variable_For_Out_Formal;
14153 ----------------------------
14154 -- Is_OK_Volatile_Context --
14155 ----------------------------
14157 function Is_OK_Volatile_Context
14158 (Context : Node_Id;
14159 Obj_Ref : Node_Id) return Boolean
14161 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean;
14162 -- Determine whether an arbitrary node denotes a call to a protected
14163 -- entry, function, or procedure in prefixed form where the prefix is
14166 function Within_Check (Nod : Node_Id) return Boolean;
14167 -- Determine whether an arbitrary node appears in a check node
14169 function Within_Subprogram_Call (Nod : Node_Id) return Boolean;
14170 -- Determine whether an arbitrary node appears in an entry, function, or
14173 function Within_Volatile_Function (Id : Entity_Id) return Boolean;
14174 -- Determine whether an arbitrary entity appears in a volatile function
14176 ---------------------------------
14177 -- Is_Protected_Operation_Call --
14178 ---------------------------------
14180 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean is
14185 -- A call to a protected operations retains its selected component
14186 -- form as opposed to other prefixed calls that are transformed in
14189 if Nkind (Nod) = N_Selected_Component then
14190 Pref := Prefix (Nod);
14191 Subp := Selector_Name (Nod);
14195 and then Present (Etype (Pref))
14196 and then Is_Protected_Type (Etype (Pref))
14197 and then Is_Entity_Name (Subp)
14198 and then Present (Entity (Subp))
14199 and then Ekind_In (Entity (Subp), E_Entry,
14206 end Is_Protected_Operation_Call;
14212 function Within_Check (Nod : Node_Id) return Boolean is
14216 -- Climb the parent chain looking for a check node
14219 while Present (Par) loop
14220 if Nkind (Par) in N_Raise_xxx_Error then
14223 -- Prevent the search from going too far
14225 elsif Is_Body_Or_Package_Declaration (Par) then
14229 Par := Parent (Par);
14235 ----------------------------
14236 -- Within_Subprogram_Call --
14237 ----------------------------
14239 function Within_Subprogram_Call (Nod : Node_Id) return Boolean is
14243 -- Climb the parent chain looking for a function or procedure call
14246 while Present (Par) loop
14247 if Nkind_In (Par, N_Entry_Call_Statement,
14249 N_Procedure_Call_Statement)
14253 -- Prevent the search from going too far
14255 elsif Is_Body_Or_Package_Declaration (Par) then
14259 Par := Parent (Par);
14263 end Within_Subprogram_Call;
14265 ------------------------------
14266 -- Within_Volatile_Function --
14267 ------------------------------
14269 function Within_Volatile_Function (Id : Entity_Id) return Boolean is
14270 Func_Id : Entity_Id;
14273 -- Traverse the scope stack looking for a [generic] function
14276 while Present (Func_Id) and then Func_Id /= Standard_Standard loop
14277 if Ekind_In (Func_Id, E_Function, E_Generic_Function) then
14278 return Is_Volatile_Function (Func_Id);
14281 Func_Id := Scope (Func_Id);
14285 end Within_Volatile_Function;
14289 Obj_Id : Entity_Id;
14291 -- Start of processing for Is_OK_Volatile_Context
14294 -- The volatile object appears on either side of an assignment
14296 if Nkind (Context) = N_Assignment_Statement then
14299 -- The volatile object is part of the initialization expression of
14302 elsif Nkind (Context) = N_Object_Declaration
14303 and then Present (Expression (Context))
14304 and then Expression (Context) = Obj_Ref
14306 Obj_Id := Defining_Entity (Context);
14308 -- The volatile object acts as the initialization expression of an
14309 -- extended return statement. This is valid context as long as the
14310 -- function is volatile.
14312 if Is_Return_Object (Obj_Id) then
14313 return Within_Volatile_Function (Obj_Id);
14315 -- Otherwise this is a normal object initialization
14321 -- The volatile object acts as the name of a renaming declaration
14323 elsif Nkind (Context) = N_Object_Renaming_Declaration
14324 and then Name (Context) = Obj_Ref
14328 -- The volatile object appears as an actual parameter in a call to an
14329 -- instance of Unchecked_Conversion whose result is renamed.
14331 elsif Nkind (Context) = N_Function_Call
14332 and then Is_Entity_Name (Name (Context))
14333 and then Is_Unchecked_Conversion_Instance (Entity (Name (Context)))
14334 and then Nkind (Parent (Context)) = N_Object_Renaming_Declaration
14338 -- The volatile object is actually the prefix in a protected entry,
14339 -- function, or procedure call.
14341 elsif Is_Protected_Operation_Call (Context) then
14344 -- The volatile object appears as the expression of a simple return
14345 -- statement that applies to a volatile function.
14347 elsif Nkind (Context) = N_Simple_Return_Statement
14348 and then Expression (Context) = Obj_Ref
14351 Within_Volatile_Function (Return_Statement_Entity (Context));
14353 -- The volatile object appears as the prefix of a name occurring in a
14354 -- non-interfering context.
14356 elsif Nkind_In (Context, N_Attribute_Reference,
14357 N_Explicit_Dereference,
14358 N_Indexed_Component,
14359 N_Selected_Component,
14361 and then Prefix (Context) = Obj_Ref
14362 and then Is_OK_Volatile_Context
14363 (Context => Parent (Context),
14364 Obj_Ref => Context)
14368 -- The volatile object appears as the prefix of attributes Address,
14369 -- Alignment, Component_Size, First_Bit, Last_Bit, Position, Size,
14372 elsif Nkind (Context) = N_Attribute_Reference
14373 and then Prefix (Context) = Obj_Ref
14374 and then Nam_In (Attribute_Name (Context), Name_Address,
14376 Name_Component_Size,
14385 -- The volatile object appears as the expression of a type conversion
14386 -- occurring in a non-interfering context.
14388 elsif Nkind_In (Context, N_Type_Conversion,
14389 N_Unchecked_Type_Conversion)
14390 and then Expression (Context) = Obj_Ref
14391 and then Is_OK_Volatile_Context
14392 (Context => Parent (Context),
14393 Obj_Ref => Context)
14397 -- The volatile object appears as the expression in a delay statement
14399 elsif Nkind (Context) in N_Delay_Statement then
14402 -- Allow references to volatile objects in various checks. This is not a
14403 -- direct SPARK 2014 requirement.
14405 elsif Within_Check (Context) then
14408 -- Assume that references to effectively volatile objects that appear
14409 -- as actual parameters in a subprogram call are always legal. A full
14410 -- legality check is done when the actuals are resolved (see routine
14411 -- Resolve_Actuals).
14413 elsif Within_Subprogram_Call (Context) then
14416 -- Otherwise the context is not suitable for an effectively volatile
14422 end Is_OK_Volatile_Context;
14424 ------------------------------------
14425 -- Is_Package_Contract_Annotation --
14426 ------------------------------------
14428 function Is_Package_Contract_Annotation (Item : Node_Id) return Boolean is
14432 if Nkind (Item) = N_Aspect_Specification then
14433 Nam := Chars (Identifier (Item));
14435 else pragma Assert (Nkind (Item) = N_Pragma);
14436 Nam := Pragma_Name (Item);
14439 return Nam = Name_Abstract_State
14440 or else Nam = Name_Initial_Condition
14441 or else Nam = Name_Initializes
14442 or else Nam = Name_Refined_State;
14443 end Is_Package_Contract_Annotation;
14445 -----------------------------------
14446 -- Is_Partially_Initialized_Type --
14447 -----------------------------------
14449 function Is_Partially_Initialized_Type
14451 Include_Implicit : Boolean := True) return Boolean
14454 if Is_Scalar_Type (Typ) then
14457 elsif Is_Access_Type (Typ) then
14458 return Include_Implicit;
14460 elsif Is_Array_Type (Typ) then
14462 -- If component type is partially initialized, so is array type
14464 if Is_Partially_Initialized_Type
14465 (Component_Type (Typ), Include_Implicit)
14469 -- Otherwise we are only partially initialized if we are fully
14470 -- initialized (this is the empty array case, no point in us
14471 -- duplicating that code here).
14474 return Is_Fully_Initialized_Type (Typ);
14477 elsif Is_Record_Type (Typ) then
14479 -- A discriminated type is always partially initialized if in
14482 if Has_Discriminants (Typ) and then Include_Implicit then
14485 -- A tagged type is always partially initialized
14487 elsif Is_Tagged_Type (Typ) then
14490 -- Case of non-discriminated record
14496 Component_Present : Boolean := False;
14497 -- Set True if at least one component is present. If no
14498 -- components are present, then record type is fully
14499 -- initialized (another odd case, like the null array).
14502 -- Loop through components
14504 Ent := First_Entity (Typ);
14505 while Present (Ent) loop
14506 if Ekind (Ent) = E_Component then
14507 Component_Present := True;
14509 -- If a component has an initialization expression then
14510 -- the enclosing record type is partially initialized
14512 if Present (Parent (Ent))
14513 and then Present (Expression (Parent (Ent)))
14517 -- If a component is of a type which is itself partially
14518 -- initialized, then the enclosing record type is also.
14520 elsif Is_Partially_Initialized_Type
14521 (Etype (Ent), Include_Implicit)
14530 -- No initialized components found. If we found any components
14531 -- they were all uninitialized so the result is false.
14533 if Component_Present then
14536 -- But if we found no components, then all the components are
14537 -- initialized so we consider the type to be initialized.
14545 -- Concurrent types are always fully initialized
14547 elsif Is_Concurrent_Type (Typ) then
14550 -- For a private type, go to underlying type. If there is no underlying
14551 -- type then just assume this partially initialized. Not clear if this
14552 -- can happen in a non-error case, but no harm in testing for this.
14554 elsif Is_Private_Type (Typ) then
14556 U : constant Entity_Id := Underlying_Type (Typ);
14561 return Is_Partially_Initialized_Type (U, Include_Implicit);
14565 -- For any other type (are there any?) assume partially initialized
14570 end Is_Partially_Initialized_Type;
14572 ------------------------------------
14573 -- Is_Potentially_Persistent_Type --
14574 ------------------------------------
14576 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
14581 -- For private type, test corresponding full type
14583 if Is_Private_Type (T) then
14584 return Is_Potentially_Persistent_Type (Full_View (T));
14586 -- Scalar types are potentially persistent
14588 elsif Is_Scalar_Type (T) then
14591 -- Record type is potentially persistent if not tagged and the types of
14592 -- all it components are potentially persistent, and no component has
14593 -- an initialization expression.
14595 elsif Is_Record_Type (T)
14596 and then not Is_Tagged_Type (T)
14597 and then not Is_Partially_Initialized_Type (T)
14599 Comp := First_Component (T);
14600 while Present (Comp) loop
14601 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
14604 Next_Entity (Comp);
14610 -- Array type is potentially persistent if its component type is
14611 -- potentially persistent and if all its constraints are static.
14613 elsif Is_Array_Type (T) then
14614 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
14618 Indx := First_Index (T);
14619 while Present (Indx) loop
14620 if not Is_OK_Static_Subtype (Etype (Indx)) then
14629 -- All other types are not potentially persistent
14634 end Is_Potentially_Persistent_Type;
14636 --------------------------------
14637 -- Is_Potentially_Unevaluated --
14638 --------------------------------
14640 function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is
14648 -- A postcondition whose expression is a short-circuit is broken down
14649 -- into individual aspects for better exception reporting. The original
14650 -- short-circuit expression is rewritten as the second operand, and an
14651 -- occurrence of 'Old in that operand is potentially unevaluated.
14652 -- See Sem_ch13.adb for details of this transformation.
14654 if Nkind (Original_Node (Par)) = N_And_Then then
14658 while not Nkind_In (Par, N_If_Expression,
14664 N_Quantified_Expression)
14667 Par := Parent (Par);
14669 -- If the context is not an expression, or if is the result of
14670 -- expansion of an enclosing construct (such as another attribute)
14671 -- the predicate does not apply.
14673 if Nkind (Par) = N_Case_Expression_Alternative then
14676 elsif Nkind (Par) not in N_Subexpr
14677 or else not Comes_From_Source (Par)
14683 if Nkind (Par) = N_If_Expression then
14684 return Is_Elsif (Par) or else Expr /= First (Expressions (Par));
14686 elsif Nkind (Par) = N_Case_Expression then
14687 return Expr /= Expression (Par);
14689 elsif Nkind_In (Par, N_And_Then, N_Or_Else) then
14690 return Expr = Right_Opnd (Par);
14692 elsif Nkind_In (Par, N_In, N_Not_In) then
14694 -- If the membership includes several alternatives, only the first is
14695 -- definitely evaluated.
14697 if Present (Alternatives (Par)) then
14698 return Expr /= First (Alternatives (Par));
14700 -- If this is a range membership both bounds are evaluated
14706 elsif Nkind (Par) = N_Quantified_Expression then
14707 return Expr = Condition (Par);
14712 end Is_Potentially_Unevaluated;
14714 ---------------------------------
14715 -- Is_Protected_Self_Reference --
14716 ---------------------------------
14718 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
14720 function In_Access_Definition (N : Node_Id) return Boolean;
14721 -- Returns true if N belongs to an access definition
14723 --------------------------
14724 -- In_Access_Definition --
14725 --------------------------
14727 function In_Access_Definition (N : Node_Id) return Boolean is
14732 while Present (P) loop
14733 if Nkind (P) = N_Access_Definition then
14741 end In_Access_Definition;
14743 -- Start of processing for Is_Protected_Self_Reference
14746 -- Verify that prefix is analyzed and has the proper form. Note that
14747 -- the attributes Elab_Spec, Elab_Body, and Elab_Subp_Body, which also
14748 -- produce the address of an entity, do not analyze their prefix
14749 -- because they denote entities that are not necessarily visible.
14750 -- Neither of them can apply to a protected type.
14752 return Ada_Version >= Ada_2005
14753 and then Is_Entity_Name (N)
14754 and then Present (Entity (N))
14755 and then Is_Protected_Type (Entity (N))
14756 and then In_Open_Scopes (Entity (N))
14757 and then not In_Access_Definition (N);
14758 end Is_Protected_Self_Reference;
14760 -----------------------------
14761 -- Is_RCI_Pkg_Spec_Or_Body --
14762 -----------------------------
14764 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
14766 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
14767 -- Return True if the unit of Cunit is an RCI package declaration
14769 ---------------------------
14770 -- Is_RCI_Pkg_Decl_Cunit --
14771 ---------------------------
14773 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
14774 The_Unit : constant Node_Id := Unit (Cunit);
14777 if Nkind (The_Unit) /= N_Package_Declaration then
14781 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
14782 end Is_RCI_Pkg_Decl_Cunit;
14784 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
14787 return Is_RCI_Pkg_Decl_Cunit (Cunit)
14789 (Nkind (Unit (Cunit)) = N_Package_Body
14790 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
14791 end Is_RCI_Pkg_Spec_Or_Body;
14793 -----------------------------------------
14794 -- Is_Remote_Access_To_Class_Wide_Type --
14795 -----------------------------------------
14797 function Is_Remote_Access_To_Class_Wide_Type
14798 (E : Entity_Id) return Boolean
14801 -- A remote access to class-wide type is a general access to object type
14802 -- declared in the visible part of a Remote_Types or Remote_Call_
14805 return Ekind (E) = E_General_Access_Type
14806 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
14807 end Is_Remote_Access_To_Class_Wide_Type;
14809 -----------------------------------------
14810 -- Is_Remote_Access_To_Subprogram_Type --
14811 -----------------------------------------
14813 function Is_Remote_Access_To_Subprogram_Type
14814 (E : Entity_Id) return Boolean
14817 return (Ekind (E) = E_Access_Subprogram_Type
14818 or else (Ekind (E) = E_Record_Type
14819 and then Present (Corresponding_Remote_Type (E))))
14820 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
14821 end Is_Remote_Access_To_Subprogram_Type;
14823 --------------------
14824 -- Is_Remote_Call --
14825 --------------------
14827 function Is_Remote_Call (N : Node_Id) return Boolean is
14829 if Nkind (N) not in N_Subprogram_Call then
14831 -- An entry call cannot be remote
14835 elsif Nkind (Name (N)) in N_Has_Entity
14836 and then Is_Remote_Call_Interface (Entity (Name (N)))
14838 -- A subprogram declared in the spec of a RCI package is remote
14842 elsif Nkind (Name (N)) = N_Explicit_Dereference
14843 and then Is_Remote_Access_To_Subprogram_Type
14844 (Etype (Prefix (Name (N))))
14846 -- The dereference of a RAS is a remote call
14850 elsif Present (Controlling_Argument (N))
14851 and then Is_Remote_Access_To_Class_Wide_Type
14852 (Etype (Controlling_Argument (N)))
14854 -- Any primitive operation call with a controlling argument of
14855 -- a RACW type is a remote call.
14860 -- All other calls are local calls
14863 end Is_Remote_Call;
14865 ----------------------
14866 -- Is_Renamed_Entry --
14867 ----------------------
14869 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
14870 Orig_Node : Node_Id := Empty;
14871 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
14873 function Is_Entry (Nam : Node_Id) return Boolean;
14874 -- Determine whether Nam is an entry. Traverse selectors if there are
14875 -- nested selected components.
14881 function Is_Entry (Nam : Node_Id) return Boolean is
14883 if Nkind (Nam) = N_Selected_Component then
14884 return Is_Entry (Selector_Name (Nam));
14887 return Ekind (Entity (Nam)) = E_Entry;
14890 -- Start of processing for Is_Renamed_Entry
14893 if Present (Alias (Proc_Nam)) then
14894 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
14897 -- Look for a rewritten subprogram renaming declaration
14899 if Nkind (Subp_Decl) = N_Subprogram_Declaration
14900 and then Present (Original_Node (Subp_Decl))
14902 Orig_Node := Original_Node (Subp_Decl);
14905 -- The rewritten subprogram is actually an entry
14907 if Present (Orig_Node)
14908 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
14909 and then Is_Entry (Name (Orig_Node))
14915 end Is_Renamed_Entry;
14917 -----------------------------
14918 -- Is_Renaming_Declaration --
14919 -----------------------------
14921 function Is_Renaming_Declaration (N : Node_Id) return Boolean is
14924 when N_Exception_Renaming_Declaration
14925 | N_Generic_Function_Renaming_Declaration
14926 | N_Generic_Package_Renaming_Declaration
14927 | N_Generic_Procedure_Renaming_Declaration
14928 | N_Object_Renaming_Declaration
14929 | N_Package_Renaming_Declaration
14930 | N_Subprogram_Renaming_Declaration
14937 end Is_Renaming_Declaration;
14939 ----------------------------
14940 -- Is_Reversible_Iterator --
14941 ----------------------------
14943 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
14944 Ifaces_List : Elist_Id;
14945 Iface_Elmt : Elmt_Id;
14949 if Is_Class_Wide_Type (Typ)
14950 and then Chars (Root_Type (Typ)) = Name_Reversible_Iterator
14951 and then Is_Predefined_File_Name
14952 (Unit_File_Name (Get_Source_Unit (Root_Type (Typ))))
14956 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
14960 Collect_Interfaces (Typ, Ifaces_List);
14962 Iface_Elmt := First_Elmt (Ifaces_List);
14963 while Present (Iface_Elmt) loop
14964 Iface := Node (Iface_Elmt);
14965 if Chars (Iface) = Name_Reversible_Iterator
14967 Is_Predefined_File_Name
14968 (Unit_File_Name (Get_Source_Unit (Iface)))
14973 Next_Elmt (Iface_Elmt);
14978 end Is_Reversible_Iterator;
14980 ----------------------
14981 -- Is_Selector_Name --
14982 ----------------------
14984 function Is_Selector_Name (N : Node_Id) return Boolean is
14986 if not Is_List_Member (N) then
14988 P : constant Node_Id := Parent (N);
14990 return Nkind_In (P, N_Expanded_Name,
14991 N_Generic_Association,
14992 N_Parameter_Association,
14993 N_Selected_Component)
14994 and then Selector_Name (P) = N;
14999 L : constant List_Id := List_Containing (N);
15000 P : constant Node_Id := Parent (L);
15002 return (Nkind (P) = N_Discriminant_Association
15003 and then Selector_Names (P) = L)
15005 (Nkind (P) = N_Component_Association
15006 and then Choices (P) = L);
15009 end Is_Selector_Name;
15011 ---------------------------------
15012 -- Is_Single_Concurrent_Object --
15013 ---------------------------------
15015 function Is_Single_Concurrent_Object (Id : Entity_Id) return Boolean is
15018 Is_Single_Protected_Object (Id) or else Is_Single_Task_Object (Id);
15019 end Is_Single_Concurrent_Object;
15021 -------------------------------
15022 -- Is_Single_Concurrent_Type --
15023 -------------------------------
15025 function Is_Single_Concurrent_Type (Id : Entity_Id) return Boolean is
15028 Ekind_In (Id, E_Protected_Type, E_Task_Type)
15029 and then Is_Single_Concurrent_Type_Declaration
15030 (Declaration_Node (Id));
15031 end Is_Single_Concurrent_Type;
15033 -------------------------------------------
15034 -- Is_Single_Concurrent_Type_Declaration --
15035 -------------------------------------------
15037 function Is_Single_Concurrent_Type_Declaration
15038 (N : Node_Id) return Boolean
15041 return Nkind_In (Original_Node (N), N_Single_Protected_Declaration,
15042 N_Single_Task_Declaration);
15043 end Is_Single_Concurrent_Type_Declaration;
15045 ---------------------------------------------
15046 -- Is_Single_Precision_Floating_Point_Type --
15047 ---------------------------------------------
15049 function Is_Single_Precision_Floating_Point_Type
15050 (E : Entity_Id) return Boolean is
15052 return Is_Floating_Point_Type (E)
15053 and then Machine_Radix_Value (E) = Uint_2
15054 and then Machine_Mantissa_Value (E) = Uint_24
15055 and then Machine_Emax_Value (E) = Uint_2 ** Uint_7
15056 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_7);
15057 end Is_Single_Precision_Floating_Point_Type;
15059 --------------------------------
15060 -- Is_Single_Protected_Object --
15061 --------------------------------
15063 function Is_Single_Protected_Object (Id : Entity_Id) return Boolean is
15066 Ekind (Id) = E_Variable
15067 and then Ekind (Etype (Id)) = E_Protected_Type
15068 and then Is_Single_Concurrent_Type (Etype (Id));
15069 end Is_Single_Protected_Object;
15071 ---------------------------
15072 -- Is_Single_Task_Object --
15073 ---------------------------
15075 function Is_Single_Task_Object (Id : Entity_Id) return Boolean is
15078 Ekind (Id) = E_Variable
15079 and then Ekind (Etype (Id)) = E_Task_Type
15080 and then Is_Single_Concurrent_Type (Etype (Id));
15081 end Is_Single_Task_Object;
15083 -------------------------------------
15084 -- Is_SPARK_05_Initialization_Expr --
15085 -------------------------------------
15087 function Is_SPARK_05_Initialization_Expr (N : Node_Id) return Boolean is
15090 Comp_Assn : Node_Id;
15091 Orig_N : constant Node_Id := Original_Node (N);
15096 if not Comes_From_Source (Orig_N) then
15100 pragma Assert (Nkind (Orig_N) in N_Subexpr);
15102 case Nkind (Orig_N) is
15103 when N_Character_Literal
15104 | N_Integer_Literal
15110 when N_Expanded_Name
15113 if Is_Entity_Name (Orig_N)
15114 and then Present (Entity (Orig_N)) -- needed in some cases
15116 case Ekind (Entity (Orig_N)) is
15118 | E_Enumeration_Literal
15125 if Is_Type (Entity (Orig_N)) then
15133 when N_Qualified_Expression
15134 | N_Type_Conversion
15136 Is_Ok := Is_SPARK_05_Initialization_Expr (Expression (Orig_N));
15139 Is_Ok := Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
15142 | N_Membership_Test
15145 Is_Ok := Is_SPARK_05_Initialization_Expr (Left_Opnd (Orig_N))
15147 Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
15150 | N_Extension_Aggregate
15152 if Nkind (Orig_N) = N_Extension_Aggregate then
15154 Is_SPARK_05_Initialization_Expr (Ancestor_Part (Orig_N));
15157 Expr := First (Expressions (Orig_N));
15158 while Present (Expr) loop
15159 if not Is_SPARK_05_Initialization_Expr (Expr) then
15167 Comp_Assn := First (Component_Associations (Orig_N));
15168 while Present (Comp_Assn) loop
15169 Expr := Expression (Comp_Assn);
15171 -- Note: test for Present here needed for box assocation
15174 and then not Is_SPARK_05_Initialization_Expr (Expr)
15183 when N_Attribute_Reference =>
15184 if Nkind (Prefix (Orig_N)) in N_Subexpr then
15185 Is_Ok := Is_SPARK_05_Initialization_Expr (Prefix (Orig_N));
15188 Expr := First (Expressions (Orig_N));
15189 while Present (Expr) loop
15190 if not Is_SPARK_05_Initialization_Expr (Expr) then
15198 -- Selected components might be expanded named not yet resolved, so
15199 -- default on the safe side. (Eg on sparklex.ads)
15201 when N_Selected_Component =>
15210 end Is_SPARK_05_Initialization_Expr;
15212 ----------------------------------
15213 -- Is_SPARK_05_Object_Reference --
15214 ----------------------------------
15216 function Is_SPARK_05_Object_Reference (N : Node_Id) return Boolean is
15218 if Is_Entity_Name (N) then
15219 return Present (Entity (N))
15221 (Ekind_In (Entity (N), E_Constant, E_Variable)
15222 or else Ekind (Entity (N)) in Formal_Kind);
15226 when N_Selected_Component =>
15227 return Is_SPARK_05_Object_Reference (Prefix (N));
15233 end Is_SPARK_05_Object_Reference;
15235 -----------------------------
15236 -- Is_Specific_Tagged_Type --
15237 -----------------------------
15239 function Is_Specific_Tagged_Type (Typ : Entity_Id) return Boolean is
15240 Full_Typ : Entity_Id;
15243 -- Handle private types
15245 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
15246 Full_Typ := Full_View (Typ);
15251 -- A specific tagged type is a non-class-wide tagged type
15253 return Is_Tagged_Type (Full_Typ) and not Is_Class_Wide_Type (Full_Typ);
15254 end Is_Specific_Tagged_Type;
15260 function Is_Statement (N : Node_Id) return Boolean is
15263 Nkind (N) in N_Statement_Other_Than_Procedure_Call
15264 or else Nkind (N) = N_Procedure_Call_Statement;
15267 ---------------------------------------
15268 -- Is_Subprogram_Contract_Annotation --
15269 ---------------------------------------
15271 function Is_Subprogram_Contract_Annotation
15272 (Item : Node_Id) return Boolean
15277 if Nkind (Item) = N_Aspect_Specification then
15278 Nam := Chars (Identifier (Item));
15280 else pragma Assert (Nkind (Item) = N_Pragma);
15281 Nam := Pragma_Name (Item);
15284 return Nam = Name_Contract_Cases
15285 or else Nam = Name_Depends
15286 or else Nam = Name_Extensions_Visible
15287 or else Nam = Name_Global
15288 or else Nam = Name_Post
15289 or else Nam = Name_Post_Class
15290 or else Nam = Name_Postcondition
15291 or else Nam = Name_Pre
15292 or else Nam = Name_Pre_Class
15293 or else Nam = Name_Precondition
15294 or else Nam = Name_Refined_Depends
15295 or else Nam = Name_Refined_Global
15296 or else Nam = Name_Refined_Post
15297 or else Nam = Name_Test_Case;
15298 end Is_Subprogram_Contract_Annotation;
15300 --------------------------------------------------
15301 -- Is_Subprogram_Stub_Without_Prior_Declaration --
15302 --------------------------------------------------
15304 function Is_Subprogram_Stub_Without_Prior_Declaration
15305 (N : Node_Id) return Boolean
15308 -- A subprogram stub without prior declaration serves as declaration for
15309 -- the actual subprogram body. As such, it has an attached defining
15310 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
15312 return Nkind (N) = N_Subprogram_Body_Stub
15313 and then Ekind (Defining_Entity (N)) /= E_Subprogram_Body;
15314 end Is_Subprogram_Stub_Without_Prior_Declaration;
15316 --------------------------
15317 -- Is_Suspension_Object --
15318 --------------------------
15320 function Is_Suspension_Object (Id : Entity_Id) return Boolean is
15322 -- This approach does an exact name match rather than to rely on
15323 -- RTSfind. Routine Is_Effectively_Volatile is used by clients of the
15324 -- front end at point where all auxiliary tables are locked and any
15325 -- modifications to them are treated as violations. Do not tamper with
15326 -- the tables, instead examine the Chars fields of all the scopes of Id.
15329 Chars (Id) = Name_Suspension_Object
15330 and then Present (Scope (Id))
15331 and then Chars (Scope (Id)) = Name_Synchronous_Task_Control
15332 and then Present (Scope (Scope (Id)))
15333 and then Chars (Scope (Scope (Id))) = Name_Ada
15334 and then Present (Scope (Scope (Scope (Id))))
15335 and then Scope (Scope (Scope (Id))) = Standard_Standard;
15336 end Is_Suspension_Object;
15338 ----------------------------
15339 -- Is_Synchronized_Object --
15340 ----------------------------
15342 function Is_Synchronized_Object (Id : Entity_Id) return Boolean is
15346 if Is_Object (Id) then
15348 -- The object is synchronized if it is of a type that yields a
15349 -- synchronized object.
15351 if Yields_Synchronized_Object (Etype (Id)) then
15354 -- The object is synchronized if it is atomic and Async_Writers is
15357 elsif Is_Atomic (Id) and then Async_Writers_Enabled (Id) then
15360 -- A constant is a synchronized object by default
15362 elsif Ekind (Id) = E_Constant then
15365 -- A variable is a synchronized object if it is subject to pragma
15366 -- Constant_After_Elaboration.
15368 elsif Ekind (Id) = E_Variable then
15369 Prag := Get_Pragma (Id, Pragma_Constant_After_Elaboration);
15371 return Present (Prag) and then Is_Enabled_Pragma (Prag);
15375 -- Otherwise the input is not an object or it does not qualify as a
15376 -- synchronized object.
15379 end Is_Synchronized_Object;
15381 ---------------------------------
15382 -- Is_Synchronized_Tagged_Type --
15383 ---------------------------------
15385 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
15386 Kind : constant Entity_Kind := Ekind (Base_Type (E));
15389 -- A task or protected type derived from an interface is a tagged type.
15390 -- Such a tagged type is called a synchronized tagged type, as are
15391 -- synchronized interfaces and private extensions whose declaration
15392 -- includes the reserved word synchronized.
15394 return (Is_Tagged_Type (E)
15395 and then (Kind = E_Task_Type
15397 Kind = E_Protected_Type))
15400 and then Is_Synchronized_Interface (E))
15402 (Ekind (E) = E_Record_Type_With_Private
15403 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
15404 and then (Synchronized_Present (Parent (E))
15405 or else Is_Synchronized_Interface (Etype (E))));
15406 end Is_Synchronized_Tagged_Type;
15412 function Is_Transfer (N : Node_Id) return Boolean is
15413 Kind : constant Node_Kind := Nkind (N);
15416 if Kind = N_Simple_Return_Statement
15418 Kind = N_Extended_Return_Statement
15420 Kind = N_Goto_Statement
15422 Kind = N_Raise_Statement
15424 Kind = N_Requeue_Statement
15428 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
15429 and then No (Condition (N))
15433 elsif Kind = N_Procedure_Call_Statement
15434 and then Is_Entity_Name (Name (N))
15435 and then Present (Entity (Name (N)))
15436 and then No_Return (Entity (Name (N)))
15440 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
15452 function Is_True (U : Uint) return Boolean is
15457 --------------------------------------
15458 -- Is_Unchecked_Conversion_Instance --
15459 --------------------------------------
15461 function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is
15465 -- Look for a function whose generic parent is the predefined intrinsic
15466 -- function Unchecked_Conversion, or for one that renames such an
15469 if Ekind (Id) = E_Function then
15470 Par := Parent (Id);
15472 if Nkind (Par) = N_Function_Specification then
15473 Par := Generic_Parent (Par);
15475 if Present (Par) then
15477 Chars (Par) = Name_Unchecked_Conversion
15478 and then Is_Intrinsic_Subprogram (Par)
15479 and then Is_Predefined_File_Name
15480 (Unit_File_Name (Get_Source_Unit (Par)));
15483 Present (Alias (Id))
15484 and then Is_Unchecked_Conversion_Instance (Alias (Id));
15490 end Is_Unchecked_Conversion_Instance;
15492 -------------------------------
15493 -- Is_Universal_Numeric_Type --
15494 -------------------------------
15496 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
15498 return T = Universal_Integer or else T = Universal_Real;
15499 end Is_Universal_Numeric_Type;
15501 --------------------------------------
15502 -- Is_Validation_Variable_Reference --
15503 --------------------------------------
15505 function Is_Validation_Variable_Reference (N : Node_Id) return Boolean is
15507 Var_Id : Entity_Id;
15512 -- Use the expression when the context qualifies a reference in some
15515 while Nkind_In (Var, N_Qualified_Expression,
15517 N_Unchecked_Type_Conversion)
15519 Var := Expression (Var);
15524 if Is_Entity_Name (Var) then
15525 Var_Id := Entity (Var);
15530 and then Ekind (Var_Id) = E_Variable
15531 and then Present (Validated_Object (Var_Id));
15532 end Is_Validation_Variable_Reference;
15534 ----------------------------
15535 -- Is_Variable_Size_Array --
15536 ----------------------------
15538 function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
15542 pragma Assert (Is_Array_Type (E));
15544 -- Check if some index is initialized with a non-constant value
15546 Idx := First_Index (E);
15547 while Present (Idx) loop
15548 if Nkind (Idx) = N_Range then
15549 if not Is_Constant_Bound (Low_Bound (Idx))
15550 or else not Is_Constant_Bound (High_Bound (Idx))
15556 Idx := Next_Index (Idx);
15560 end Is_Variable_Size_Array;
15562 -----------------------------
15563 -- Is_Variable_Size_Record --
15564 -----------------------------
15566 function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
15568 Comp_Typ : Entity_Id;
15571 pragma Assert (Is_Record_Type (E));
15573 Comp := First_Entity (E);
15574 while Present (Comp) loop
15575 Comp_Typ := Etype (Comp);
15577 -- Recursive call if the record type has discriminants
15579 if Is_Record_Type (Comp_Typ)
15580 and then Has_Discriminants (Comp_Typ)
15581 and then Is_Variable_Size_Record (Comp_Typ)
15585 elsif Is_Array_Type (Comp_Typ)
15586 and then Is_Variable_Size_Array (Comp_Typ)
15591 Next_Entity (Comp);
15595 end Is_Variable_Size_Record;
15601 function Is_Variable
15603 Use_Original_Node : Boolean := True) return Boolean
15605 Orig_Node : Node_Id;
15607 function In_Protected_Function (E : Entity_Id) return Boolean;
15608 -- Within a protected function, the private components of the enclosing
15609 -- protected type are constants. A function nested within a (protected)
15610 -- procedure is not itself protected. Within the body of a protected
15611 -- function the current instance of the protected type is a constant.
15613 function Is_Variable_Prefix (P : Node_Id) return Boolean;
15614 -- Prefixes can involve implicit dereferences, in which case we must
15615 -- test for the case of a reference of a constant access type, which can
15616 -- can never be a variable.
15618 ---------------------------
15619 -- In_Protected_Function --
15620 ---------------------------
15622 function In_Protected_Function (E : Entity_Id) return Boolean is
15627 -- E is the current instance of a type
15629 if Is_Type (E) then
15638 if not Is_Protected_Type (Prot) then
15642 S := Current_Scope;
15643 while Present (S) and then S /= Prot loop
15644 if Ekind (S) = E_Function and then Scope (S) = Prot then
15653 end In_Protected_Function;
15655 ------------------------
15656 -- Is_Variable_Prefix --
15657 ------------------------
15659 function Is_Variable_Prefix (P : Node_Id) return Boolean is
15661 if Is_Access_Type (Etype (P)) then
15662 return not Is_Access_Constant (Root_Type (Etype (P)));
15664 -- For the case of an indexed component whose prefix has a packed
15665 -- array type, the prefix has been rewritten into a type conversion.
15666 -- Determine variable-ness from the converted expression.
15668 elsif Nkind (P) = N_Type_Conversion
15669 and then not Comes_From_Source (P)
15670 and then Is_Array_Type (Etype (P))
15671 and then Is_Packed (Etype (P))
15673 return Is_Variable (Expression (P));
15676 return Is_Variable (P);
15678 end Is_Variable_Prefix;
15680 -- Start of processing for Is_Variable
15683 -- Special check, allow x'Deref(expr) as a variable
15685 if Nkind (N) = N_Attribute_Reference
15686 and then Attribute_Name (N) = Name_Deref
15691 -- Check if we perform the test on the original node since this may be a
15692 -- test of syntactic categories which must not be disturbed by whatever
15693 -- rewriting might have occurred. For example, an aggregate, which is
15694 -- certainly NOT a variable, could be turned into a variable by
15697 if Use_Original_Node then
15698 Orig_Node := Original_Node (N);
15703 -- Definitely OK if Assignment_OK is set. Since this is something that
15704 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
15706 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
15709 -- Normally we go to the original node, but there is one exception where
15710 -- we use the rewritten node, namely when it is an explicit dereference.
15711 -- The generated code may rewrite a prefix which is an access type with
15712 -- an explicit dereference. The dereference is a variable, even though
15713 -- the original node may not be (since it could be a constant of the
15716 -- In Ada 2005 we have a further case to consider: the prefix may be a
15717 -- function call given in prefix notation. The original node appears to
15718 -- be a selected component, but we need to examine the call.
15720 elsif Nkind (N) = N_Explicit_Dereference
15721 and then Nkind (Orig_Node) /= N_Explicit_Dereference
15722 and then Present (Etype (Orig_Node))
15723 and then Is_Access_Type (Etype (Orig_Node))
15725 -- Note that if the prefix is an explicit dereference that does not
15726 -- come from source, we must check for a rewritten function call in
15727 -- prefixed notation before other forms of rewriting, to prevent a
15731 (Nkind (Orig_Node) = N_Function_Call
15732 and then not Is_Access_Constant (Etype (Prefix (N))))
15734 Is_Variable_Prefix (Original_Node (Prefix (N)));
15736 -- in Ada 2012, the dereference may have been added for a type with
15737 -- a declared implicit dereference aspect. Check that it is not an
15738 -- access to constant.
15740 elsif Nkind (N) = N_Explicit_Dereference
15741 and then Present (Etype (Orig_Node))
15742 and then Ada_Version >= Ada_2012
15743 and then Has_Implicit_Dereference (Etype (Orig_Node))
15745 return not Is_Access_Constant (Etype (Prefix (N)));
15747 -- A function call is never a variable
15749 elsif Nkind (N) = N_Function_Call then
15752 -- All remaining checks use the original node
15754 elsif Is_Entity_Name (Orig_Node)
15755 and then Present (Entity (Orig_Node))
15758 E : constant Entity_Id := Entity (Orig_Node);
15759 K : constant Entity_Kind := Ekind (E);
15762 return (K = E_Variable
15763 and then Nkind (Parent (E)) /= N_Exception_Handler)
15764 or else (K = E_Component
15765 and then not In_Protected_Function (E))
15766 or else K = E_Out_Parameter
15767 or else K = E_In_Out_Parameter
15768 or else K = E_Generic_In_Out_Parameter
15770 -- Current instance of type. If this is a protected type, check
15771 -- we are not within the body of one of its protected functions.
15773 or else (Is_Type (E)
15774 and then In_Open_Scopes (E)
15775 and then not In_Protected_Function (E))
15777 or else (Is_Incomplete_Or_Private_Type (E)
15778 and then In_Open_Scopes (Full_View (E)));
15782 case Nkind (Orig_Node) is
15783 when N_Indexed_Component
15786 return Is_Variable_Prefix (Prefix (Orig_Node));
15788 when N_Selected_Component =>
15789 return (Is_Variable (Selector_Name (Orig_Node))
15790 and then Is_Variable_Prefix (Prefix (Orig_Node)))
15792 (Nkind (N) = N_Expanded_Name
15793 and then Scope (Entity (N)) = Entity (Prefix (N)));
15795 -- For an explicit dereference, the type of the prefix cannot
15796 -- be an access to constant or an access to subprogram.
15798 when N_Explicit_Dereference =>
15800 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
15802 return Is_Access_Type (Typ)
15803 and then not Is_Access_Constant (Root_Type (Typ))
15804 and then Ekind (Typ) /= E_Access_Subprogram_Type;
15807 -- The type conversion is the case where we do not deal with the
15808 -- context dependent special case of an actual parameter. Thus
15809 -- the type conversion is only considered a variable for the
15810 -- purposes of this routine if the target type is tagged. However,
15811 -- a type conversion is considered to be a variable if it does not
15812 -- come from source (this deals for example with the conversions
15813 -- of expressions to their actual subtypes).
15815 when N_Type_Conversion =>
15816 return Is_Variable (Expression (Orig_Node))
15818 (not Comes_From_Source (Orig_Node)
15820 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
15822 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
15824 -- GNAT allows an unchecked type conversion as a variable. This
15825 -- only affects the generation of internal expanded code, since
15826 -- calls to instantiations of Unchecked_Conversion are never
15827 -- considered variables (since they are function calls).
15829 when N_Unchecked_Type_Conversion =>
15830 return Is_Variable (Expression (Orig_Node));
15838 ------------------------------
15839 -- Is_Verifiable_DIC_Pragma --
15840 ------------------------------
15842 function Is_Verifiable_DIC_Pragma (Prag : Node_Id) return Boolean is
15843 Args : constant List_Id := Pragma_Argument_Associations (Prag);
15846 -- To qualify as verifiable, a DIC pragma must have a non-null argument
15850 and then Nkind (Get_Pragma_Arg (First (Args))) /= N_Null;
15851 end Is_Verifiable_DIC_Pragma;
15853 ---------------------------
15854 -- Is_Visibly_Controlled --
15855 ---------------------------
15857 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
15858 Root : constant Entity_Id := Root_Type (T);
15860 return Chars (Scope (Root)) = Name_Finalization
15861 and then Chars (Scope (Scope (Root))) = Name_Ada
15862 and then Scope (Scope (Scope (Root))) = Standard_Standard;
15863 end Is_Visibly_Controlled;
15865 --------------------------
15866 -- Is_Volatile_Function --
15867 --------------------------
15869 function Is_Volatile_Function (Func_Id : Entity_Id) return Boolean is
15871 pragma Assert (Ekind_In (Func_Id, E_Function, E_Generic_Function));
15873 -- A function declared within a protected type is volatile
15875 if Is_Protected_Type (Scope (Func_Id)) then
15878 -- An instance of Ada.Unchecked_Conversion is a volatile function if
15879 -- either the source or the target are effectively volatile.
15881 elsif Is_Unchecked_Conversion_Instance (Func_Id)
15882 and then Has_Effectively_Volatile_Profile (Func_Id)
15886 -- Otherwise the function is treated as volatile if it is subject to
15887 -- enabled pragma Volatile_Function.
15891 Is_Enabled_Pragma (Get_Pragma (Func_Id, Pragma_Volatile_Function));
15893 end Is_Volatile_Function;
15895 ------------------------
15896 -- Is_Volatile_Object --
15897 ------------------------
15899 function Is_Volatile_Object (N : Node_Id) return Boolean is
15900 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
15901 -- If prefix is an implicit dereference, examine designated type
15903 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
15904 -- Determines if given object has volatile components
15906 ------------------------
15907 -- Is_Volatile_Prefix --
15908 ------------------------
15910 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
15911 Typ : constant Entity_Id := Etype (N);
15914 if Is_Access_Type (Typ) then
15916 Dtyp : constant Entity_Id := Designated_Type (Typ);
15919 return Is_Volatile (Dtyp)
15920 or else Has_Volatile_Components (Dtyp);
15924 return Object_Has_Volatile_Components (N);
15926 end Is_Volatile_Prefix;
15928 ------------------------------------
15929 -- Object_Has_Volatile_Components --
15930 ------------------------------------
15932 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
15933 Typ : constant Entity_Id := Etype (N);
15936 if Is_Volatile (Typ)
15937 or else Has_Volatile_Components (Typ)
15941 elsif Is_Entity_Name (N)
15942 and then (Has_Volatile_Components (Entity (N))
15943 or else Is_Volatile (Entity (N)))
15947 elsif Nkind (N) = N_Indexed_Component
15948 or else Nkind (N) = N_Selected_Component
15950 return Is_Volatile_Prefix (Prefix (N));
15955 end Object_Has_Volatile_Components;
15957 -- Start of processing for Is_Volatile_Object
15960 if Nkind (N) = N_Defining_Identifier then
15961 return Is_Volatile (N) or else Is_Volatile (Etype (N));
15963 elsif Nkind (N) = N_Expanded_Name then
15964 return Is_Volatile_Object (Entity (N));
15966 elsif Is_Volatile (Etype (N))
15967 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
15971 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component)
15972 and then Is_Volatile_Prefix (Prefix (N))
15976 elsif Nkind (N) = N_Selected_Component
15977 and then Is_Volatile (Entity (Selector_Name (N)))
15984 end Is_Volatile_Object;
15986 ---------------------------
15987 -- Itype_Has_Declaration --
15988 ---------------------------
15990 function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
15992 pragma Assert (Is_Itype (Id));
15993 return Present (Parent (Id))
15994 and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
15995 N_Subtype_Declaration)
15996 and then Defining_Entity (Parent (Id)) = Id;
15997 end Itype_Has_Declaration;
15999 -------------------------
16000 -- Kill_Current_Values --
16001 -------------------------
16003 procedure Kill_Current_Values
16005 Last_Assignment_Only : Boolean := False)
16008 if Is_Assignable (Ent) then
16009 Set_Last_Assignment (Ent, Empty);
16012 if Is_Object (Ent) then
16013 if not Last_Assignment_Only then
16015 Set_Current_Value (Ent, Empty);
16017 -- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
16018 -- for a constant. Once the constant is elaborated, its value is
16019 -- not changed, therefore the associated flags that describe the
16020 -- value should not be modified either.
16022 if Ekind (Ent) = E_Constant then
16025 -- Non-constant entities
16028 if not Can_Never_Be_Null (Ent) then
16029 Set_Is_Known_Non_Null (Ent, False);
16032 Set_Is_Known_Null (Ent, False);
16034 -- Reset the Is_Known_Valid flag unless the type is always
16035 -- valid. This does not apply to a loop parameter because its
16036 -- bounds are defined by the loop header and therefore always
16039 if not Is_Known_Valid (Etype (Ent))
16040 and then Ekind (Ent) /= E_Loop_Parameter
16042 Set_Is_Known_Valid (Ent, False);
16047 end Kill_Current_Values;
16049 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
16052 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
16053 -- Clear current value for entity E and all entities chained to E
16055 ------------------------------------------
16056 -- Kill_Current_Values_For_Entity_Chain --
16057 ------------------------------------------
16059 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
16063 while Present (Ent) loop
16064 Kill_Current_Values (Ent, Last_Assignment_Only);
16067 end Kill_Current_Values_For_Entity_Chain;
16069 -- Start of processing for Kill_Current_Values
16072 -- Kill all saved checks, a special case of killing saved values
16074 if not Last_Assignment_Only then
16078 -- Loop through relevant scopes, which includes the current scope and
16079 -- any parent scopes if the current scope is a block or a package.
16081 S := Current_Scope;
16084 -- Clear current values of all entities in current scope
16086 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
16088 -- If scope is a package, also clear current values of all private
16089 -- entities in the scope.
16091 if Is_Package_Or_Generic_Package (S)
16092 or else Is_Concurrent_Type (S)
16094 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
16097 -- If this is a not a subprogram, deal with parents
16099 if not Is_Subprogram (S) then
16101 exit Scope_Loop when S = Standard_Standard;
16105 end loop Scope_Loop;
16106 end Kill_Current_Values;
16108 --------------------------
16109 -- Kill_Size_Check_Code --
16110 --------------------------
16112 procedure Kill_Size_Check_Code (E : Entity_Id) is
16114 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
16115 and then Present (Size_Check_Code (E))
16117 Remove (Size_Check_Code (E));
16118 Set_Size_Check_Code (E, Empty);
16120 end Kill_Size_Check_Code;
16122 --------------------
16123 -- Known_Non_Null --
16124 --------------------
16126 function Known_Non_Null (N : Node_Id) return Boolean is
16127 Status : constant Null_Status_Kind := Null_Status (N);
16134 -- The expression yields a non-null value ignoring simple flow analysis
16136 if Status = Is_Non_Null then
16139 -- Otherwise check whether N is a reference to an entity that appears
16140 -- within a conditional construct.
16142 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
16144 -- First check if we are in decisive conditional
16146 Get_Current_Value_Condition (N, Op, Val);
16148 if Known_Null (Val) then
16149 if Op = N_Op_Eq then
16151 elsif Op = N_Op_Ne then
16156 -- If OK to do replacement, test Is_Known_Non_Null flag
16160 if OK_To_Do_Constant_Replacement (Id) then
16161 return Is_Known_Non_Null (Id);
16165 -- Otherwise it is not possible to determine whether N yields a non-null
16169 end Known_Non_Null;
16175 function Known_Null (N : Node_Id) return Boolean is
16176 Status : constant Null_Status_Kind := Null_Status (N);
16183 -- The expression yields a null value ignoring simple flow analysis
16185 if Status = Is_Null then
16188 -- Otherwise check whether N is a reference to an entity that appears
16189 -- within a conditional construct.
16191 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
16193 -- First check if we are in decisive conditional
16195 Get_Current_Value_Condition (N, Op, Val);
16197 if Known_Null (Val) then
16198 if Op = N_Op_Eq then
16200 elsif Op = N_Op_Ne then
16205 -- If OK to do replacement, test Is_Known_Null flag
16209 if OK_To_Do_Constant_Replacement (Id) then
16210 return Is_Known_Null (Id);
16214 -- Otherwise it is not possible to determine whether N yields a null
16220 --------------------------
16221 -- Known_To_Be_Assigned --
16222 --------------------------
16224 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
16225 P : constant Node_Id := Parent (N);
16230 -- Test left side of assignment
16232 when N_Assignment_Statement =>
16233 return N = Name (P);
16235 -- Function call arguments are never lvalues
16237 when N_Function_Call =>
16240 -- Positional parameter for procedure or accept call
16242 when N_Accept_Statement
16243 | N_Procedure_Call_Statement
16251 Proc := Get_Subprogram_Entity (P);
16257 -- If we are not a list member, something is strange, so
16258 -- be conservative and return False.
16260 if not Is_List_Member (N) then
16264 -- We are going to find the right formal by stepping forward
16265 -- through the formals, as we step backwards in the actuals.
16267 Form := First_Formal (Proc);
16270 -- If no formal, something is weird, so be conservative
16271 -- and return False.
16278 exit when No (Act);
16279 Next_Formal (Form);
16282 return Ekind (Form) /= E_In_Parameter;
16285 -- Named parameter for procedure or accept call
16287 when N_Parameter_Association =>
16293 Proc := Get_Subprogram_Entity (Parent (P));
16299 -- Loop through formals to find the one that matches
16301 Form := First_Formal (Proc);
16303 -- If no matching formal, that's peculiar, some kind of
16304 -- previous error, so return False to be conservative.
16305 -- Actually this also happens in legal code in the case
16306 -- where P is a parameter association for an Extra_Formal???
16312 -- Else test for match
16314 if Chars (Form) = Chars (Selector_Name (P)) then
16315 return Ekind (Form) /= E_In_Parameter;
16318 Next_Formal (Form);
16322 -- Test for appearing in a conversion that itself appears
16323 -- in an lvalue context, since this should be an lvalue.
16325 when N_Type_Conversion =>
16326 return Known_To_Be_Assigned (P);
16328 -- All other references are definitely not known to be modifications
16333 end Known_To_Be_Assigned;
16335 ---------------------------
16336 -- Last_Source_Statement --
16337 ---------------------------
16339 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
16343 N := Last (Statements (HSS));
16344 while Present (N) loop
16345 exit when Comes_From_Source (N);
16350 end Last_Source_Statement;
16352 ----------------------------------
16353 -- Matching_Static_Array_Bounds --
16354 ----------------------------------
16356 function Matching_Static_Array_Bounds
16358 R_Typ : Node_Id) return Boolean
16360 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
16361 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
16373 if L_Ndims /= R_Ndims then
16377 -- Unconstrained types do not have static bounds
16379 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
16383 -- First treat specially the first dimension, as the lower bound and
16384 -- length of string literals are not stored like those of arrays.
16386 if Ekind (L_Typ) = E_String_Literal_Subtype then
16387 L_Low := String_Literal_Low_Bound (L_Typ);
16388 L_Len := String_Literal_Length (L_Typ);
16390 L_Index := First_Index (L_Typ);
16391 Get_Index_Bounds (L_Index, L_Low, L_High);
16393 if Is_OK_Static_Expression (L_Low)
16395 Is_OK_Static_Expression (L_High)
16397 if Expr_Value (L_High) < Expr_Value (L_Low) then
16400 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
16407 if Ekind (R_Typ) = E_String_Literal_Subtype then
16408 R_Low := String_Literal_Low_Bound (R_Typ);
16409 R_Len := String_Literal_Length (R_Typ);
16411 R_Index := First_Index (R_Typ);
16412 Get_Index_Bounds (R_Index, R_Low, R_High);
16414 if Is_OK_Static_Expression (R_Low)
16416 Is_OK_Static_Expression (R_High)
16418 if Expr_Value (R_High) < Expr_Value (R_Low) then
16421 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
16428 if (Is_OK_Static_Expression (L_Low)
16430 Is_OK_Static_Expression (R_Low))
16431 and then Expr_Value (L_Low) = Expr_Value (R_Low)
16432 and then L_Len = R_Len
16439 -- Then treat all other dimensions
16441 for Indx in 2 .. L_Ndims loop
16445 Get_Index_Bounds (L_Index, L_Low, L_High);
16446 Get_Index_Bounds (R_Index, R_Low, R_High);
16448 if (Is_OK_Static_Expression (L_Low) and then
16449 Is_OK_Static_Expression (L_High) and then
16450 Is_OK_Static_Expression (R_Low) and then
16451 Is_OK_Static_Expression (R_High))
16452 and then (Expr_Value (L_Low) = Expr_Value (R_Low)
16454 Expr_Value (L_High) = Expr_Value (R_High))
16462 -- If we fall through the loop, all indexes matched
16465 end Matching_Static_Array_Bounds;
16467 -------------------
16468 -- May_Be_Lvalue --
16469 -------------------
16471 function May_Be_Lvalue (N : Node_Id) return Boolean is
16472 P : constant Node_Id := Parent (N);
16477 -- Test left side of assignment
16479 when N_Assignment_Statement =>
16480 return N = Name (P);
16482 -- Test prefix of component or attribute. Note that the prefix of an
16483 -- explicit or implicit dereference cannot be an l-value. In the case
16484 -- of a 'Read attribute, the reference can be an actual in the
16485 -- argument list of the attribute.
16487 when N_Attribute_Reference =>
16488 return (N = Prefix (P)
16489 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P)))
16491 Attribute_Name (P) = Name_Read;
16493 -- For an expanded name, the name is an lvalue if the expanded name
16494 -- is an lvalue, but the prefix is never an lvalue, since it is just
16495 -- the scope where the name is found.
16497 when N_Expanded_Name =>
16498 if N = Prefix (P) then
16499 return May_Be_Lvalue (P);
16504 -- For a selected component A.B, A is certainly an lvalue if A.B is.
16505 -- B is a little interesting, if we have A.B := 3, there is some
16506 -- discussion as to whether B is an lvalue or not, we choose to say
16507 -- it is. Note however that A is not an lvalue if it is of an access
16508 -- type since this is an implicit dereference.
16510 when N_Selected_Component =>
16512 and then Present (Etype (N))
16513 and then Is_Access_Type (Etype (N))
16517 return May_Be_Lvalue (P);
16520 -- For an indexed component or slice, the index or slice bounds is
16521 -- never an lvalue. The prefix is an lvalue if the indexed component
16522 -- or slice is an lvalue, except if it is an access type, where we
16523 -- have an implicit dereference.
16525 when N_Indexed_Component
16529 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
16533 return May_Be_Lvalue (P);
16536 -- Prefix of a reference is an lvalue if the reference is an lvalue
16538 when N_Reference =>
16539 return May_Be_Lvalue (P);
16541 -- Prefix of explicit dereference is never an lvalue
16543 when N_Explicit_Dereference =>
16546 -- Positional parameter for subprogram, entry, or accept call.
16547 -- In older versions of Ada function call arguments are never
16548 -- lvalues. In Ada 2012 functions can have in-out parameters.
16550 when N_Accept_Statement
16551 | N_Entry_Call_Statement
16552 | N_Subprogram_Call
16554 if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
16558 -- The following mechanism is clumsy and fragile. A single flag
16559 -- set in Resolve_Actuals would be preferable ???
16567 Proc := Get_Subprogram_Entity (P);
16573 -- If we are not a list member, something is strange, so be
16574 -- conservative and return True.
16576 if not Is_List_Member (N) then
16580 -- We are going to find the right formal by stepping forward
16581 -- through the formals, as we step backwards in the actuals.
16583 Form := First_Formal (Proc);
16586 -- If no formal, something is weird, so be conservative and
16594 exit when No (Act);
16595 Next_Formal (Form);
16598 return Ekind (Form) /= E_In_Parameter;
16601 -- Named parameter for procedure or accept call
16603 when N_Parameter_Association =>
16609 Proc := Get_Subprogram_Entity (Parent (P));
16615 -- Loop through formals to find the one that matches
16617 Form := First_Formal (Proc);
16619 -- If no matching formal, that's peculiar, some kind of
16620 -- previous error, so return True to be conservative.
16621 -- Actually happens with legal code for an unresolved call
16622 -- where we may get the wrong homonym???
16628 -- Else test for match
16630 if Chars (Form) = Chars (Selector_Name (P)) then
16631 return Ekind (Form) /= E_In_Parameter;
16634 Next_Formal (Form);
16638 -- Test for appearing in a conversion that itself appears in an
16639 -- lvalue context, since this should be an lvalue.
16641 when N_Type_Conversion =>
16642 return May_Be_Lvalue (P);
16644 -- Test for appearance in object renaming declaration
16646 when N_Object_Renaming_Declaration =>
16649 -- All other references are definitely not lvalues
16656 -----------------------
16657 -- Mark_Coextensions --
16658 -----------------------
16660 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
16661 Is_Dynamic : Boolean;
16662 -- Indicates whether the context causes nested coextensions to be
16663 -- dynamic or static
16665 function Mark_Allocator (N : Node_Id) return Traverse_Result;
16666 -- Recognize an allocator node and label it as a dynamic coextension
16668 --------------------
16669 -- Mark_Allocator --
16670 --------------------
16672 function Mark_Allocator (N : Node_Id) return Traverse_Result is
16674 if Nkind (N) = N_Allocator then
16676 Set_Is_Dynamic_Coextension (N);
16678 -- If the allocator expression is potentially dynamic, it may
16679 -- be expanded out of order and require dynamic allocation
16680 -- anyway, so we treat the coextension itself as dynamic.
16681 -- Potential optimization ???
16683 elsif Nkind (Expression (N)) = N_Qualified_Expression
16684 and then Nkind (Expression (Expression (N))) = N_Op_Concat
16686 Set_Is_Dynamic_Coextension (N);
16688 Set_Is_Static_Coextension (N);
16693 end Mark_Allocator;
16695 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
16697 -- Start of processing for Mark_Coextensions
16700 -- An allocator that appears on the right-hand side of an assignment is
16701 -- treated as a potentially dynamic coextension when the right-hand side
16702 -- is an allocator or a qualified expression.
16704 -- Obj := new ...'(new Coextension ...);
16706 if Nkind (Context_Nod) = N_Assignment_Statement then
16708 Nkind_In (Expression (Context_Nod), N_Allocator,
16709 N_Qualified_Expression);
16711 -- An allocator that appears within the expression of a simple return
16712 -- statement is treated as a potentially dynamic coextension when the
16713 -- expression is either aggregate, allocator, or qualified expression.
16715 -- return (new Coextension ...);
16716 -- return new ...'(new Coextension ...);
16718 elsif Nkind (Context_Nod) = N_Simple_Return_Statement then
16720 Nkind_In (Expression (Context_Nod), N_Aggregate,
16722 N_Qualified_Expression);
16724 -- An allocator that appears within the initialization expression of an
16725 -- object declaration is considered a potentially dynamic coextension
16726 -- when the initialization expression is an allocator or a qualified
16729 -- Obj : ... := new ...'(new Coextension ...);
16731 -- A similar case arises when the object declaration is part of an
16732 -- extended return statement.
16734 -- return Obj : ... := new ...'(new Coextension ...);
16735 -- return Obj : ... := (new Coextension ...);
16737 elsif Nkind (Context_Nod) = N_Object_Declaration then
16739 Nkind_In (Root_Nod, N_Allocator, N_Qualified_Expression)
16741 Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
16743 -- This routine should not be called with constructs that cannot contain
16747 raise Program_Error;
16750 Mark_Allocators (Root_Nod);
16751 end Mark_Coextensions;
16753 ----------------------
16754 -- Needs_One_Actual --
16755 ----------------------
16757 function Needs_One_Actual (E : Entity_Id) return Boolean is
16758 Formal : Entity_Id;
16761 -- Ada 2005 or later, and formals present
16763 if Ada_Version >= Ada_2005
16764 and then Present (First_Formal (E))
16765 and then No (Default_Value (First_Formal (E)))
16767 Formal := Next_Formal (First_Formal (E));
16768 while Present (Formal) loop
16769 if No (Default_Value (Formal)) then
16773 Next_Formal (Formal);
16778 -- Ada 83/95 or no formals
16783 end Needs_One_Actual;
16785 ------------------------
16786 -- New_Copy_List_Tree --
16787 ------------------------
16789 function New_Copy_List_Tree (List : List_Id) return List_Id is
16794 if List = No_List then
16801 while Present (E) loop
16802 Append (New_Copy_Tree (E), NL);
16808 end New_Copy_List_Tree;
16810 --------------------------------------------------
16811 -- New_Copy_Tree Auxiliary Data and Subprograms --
16812 --------------------------------------------------
16814 use Atree.Unchecked_Access;
16815 use Atree_Private_Part;
16817 -- Our approach here requires a two pass traversal of the tree. The
16818 -- first pass visits all nodes that eventually will be copied looking
16819 -- for defining Itypes. If any defining Itypes are found, then they are
16820 -- copied, and an entry is added to the replacement map. In the second
16821 -- phase, the tree is copied, using the replacement map to replace any
16822 -- Itype references within the copied tree.
16824 -- The following hash tables are used to speed up access to the map. They
16825 -- are declared at library level to avoid elaborating them for every call
16826 -- to New_Copy_Tree. This can save up to 2% of the entire compilation time
16827 -- spent in the front end.
16829 subtype NCT_Header_Num is Int range 0 .. 511;
16830 -- Defines range of headers in hash tables (512 headers)
16832 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
16833 -- Hash function used for hash operations
16835 -------------------
16836 -- New_Copy_Hash --
16837 -------------------
16839 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
16841 return Nat (E) mod (NCT_Header_Num'Last + 1);
16848 -- The hash table NCT_Assoc associates old entities in the table with their
16849 -- corresponding new entities (i.e. the pairs of entries presented in the
16850 -- original Map argument are Key-Element pairs).
16852 package NCT_Assoc is new Simple_HTable (
16853 Header_Num => NCT_Header_Num,
16854 Element => Entity_Id,
16855 No_Element => Empty,
16857 Hash => New_Copy_Hash,
16858 Equal => Types."=");
16860 ---------------------
16861 -- NCT_Itype_Assoc --
16862 ---------------------
16864 -- The hash table NCT_Itype_Assoc contains entries only for those old
16865 -- nodes which have a non-empty Associated_Node_For_Itype set. The key
16866 -- is the associated node, and the element is the new node itself (NOT
16867 -- the associated node for the new node).
16869 package NCT_Itype_Assoc is new Simple_HTable (
16870 Header_Num => NCT_Header_Num,
16871 Element => Entity_Id,
16872 No_Element => Empty,
16874 Hash => New_Copy_Hash,
16875 Equal => Types."=");
16877 -------------------
16878 -- New_Copy_Tree --
16879 -------------------
16881 function New_Copy_Tree
16883 Map : Elist_Id := No_Elist;
16884 New_Sloc : Source_Ptr := No_Location;
16885 New_Scope : Entity_Id := Empty) return Node_Id
16887 EWA_Level : Nat := 0;
16888 -- By default, copying of defining identifiers is prohibited because
16889 -- this would introduce an entirely new entity into the tree. The
16890 -- exception to this general rule is declaration of constants and
16891 -- variables located in Expression_With_Action nodes.
16893 EWA_Inner_Scope_Level : Nat := 0;
16894 -- Level of internal scope of defined in EWAs. Used to avoid creating
16895 -- variables for declarations located in blocks or subprograms defined
16896 -- in Expression_With_Action nodes.
16898 NCT_Hash_Tables_Used : Boolean := False;
16899 -- Set to True if hash tables are in use. It is intended to speed up the
16900 -- common case, which is no hash tables in use. This can save up to 8%
16901 -- of the entire compilation time spent in the front end.
16903 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
16904 -- Called during second phase to map entities into their corresponding
16905 -- copies using the hash table. If the argument is not an entity, or is
16906 -- not in the hash table, then it is returned unchanged.
16908 procedure Build_NCT_Hash_Tables;
16909 -- Builds hash tables
16911 function Copy_Elist_With_Replacement
16912 (Old_Elist : Elist_Id) return Elist_Id;
16913 -- Called during second phase to copy element list doing replacements
16915 procedure Copy_Entity_With_Replacement (New_Entity : Entity_Id);
16916 -- Called during the second phase to process a copied Entity. The actual
16917 -- copy happened during the first phase (so that we could make the entry
16918 -- in the mapping), but we still have to deal with the descendants of
16919 -- the copied Entity and copy them where necessary.
16921 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
16922 -- Called during second phase to copy list doing replacements
16924 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
16925 -- Called during second phase to copy node doing replacements
16927 function In_Map (E : Entity_Id) return Boolean;
16928 -- Return True if E is one of the old entities specified in the set of
16929 -- mappings to be applied to entities in the tree (i.e. Map).
16931 procedure Visit_Elist (E : Elist_Id);
16932 -- Called during first phase to visit all elements of an Elist
16934 procedure Visit_Entity (Old_Entity : Entity_Id);
16935 -- Called during first phase to visit subsidiary fields of a defining
16936 -- entity which is not an itype, and also create a copy and make an
16937 -- entry in the replacement map for the new copy.
16939 procedure Visit_Field (F : Union_Id; N : Node_Id);
16940 -- Visit a single field, recursing to call Visit_Node or Visit_List if
16941 -- the field is a syntactic descendant of the current node (i.e. its
16942 -- parent is Node N).
16944 procedure Visit_Itype (Old_Itype : Entity_Id);
16945 -- Called during first phase to visit subsidiary fields of a defining
16946 -- Itype, and also create a copy and make an entry in the replacement
16947 -- map for the new copy.
16949 procedure Visit_List (L : List_Id);
16950 -- Called during first phase to visit all elements of a List
16952 procedure Visit_Node (N : Node_Or_Entity_Id);
16953 -- Called during first phase to visit a node and all its subtrees
16959 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
16963 if Nkind (N) not in N_Entity or else not NCT_Hash_Tables_Used then
16967 Ent := NCT_Assoc.Get (Entity_Id (N));
16969 if Present (Ent) then
16977 ---------------------------
16978 -- Build_NCT_Hash_Tables --
16979 ---------------------------
16981 procedure Build_NCT_Hash_Tables is
16990 Elmt := First_Elmt (Map);
16991 while Present (Elmt) loop
16992 Ent := Node (Elmt);
16994 -- Get new entity, and associate old and new
16997 NCT_Assoc.Set (Ent, Node (Elmt));
16999 if Is_Type (Ent) then
17001 Anode : constant Entity_Id :=
17002 Associated_Node_For_Itype (Ent);
17005 -- Enter the link between the associated node of the old
17006 -- Itype and the new Itype, for updating later when node
17009 if Present (Anode) then
17010 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
17018 NCT_Hash_Tables_Used := True;
17019 end Build_NCT_Hash_Tables;
17021 ---------------------------------
17022 -- Copy_Elist_With_Replacement --
17023 ---------------------------------
17025 function Copy_Elist_With_Replacement
17026 (Old_Elist : Elist_Id) return Elist_Id
17029 New_Elist : Elist_Id;
17032 if No (Old_Elist) then
17036 New_Elist := New_Elmt_List;
17038 M := First_Elmt (Old_Elist);
17039 while Present (M) loop
17040 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
17046 end Copy_Elist_With_Replacement;
17048 ----------------------------------
17049 -- Copy_Entity_With_Replacement --
17050 ----------------------------------
17052 -- This routine exactly parallels its phase one analog Visit_Itype
17054 procedure Copy_Entity_With_Replacement (New_Entity : Entity_Id) is
17056 -- Translate Next_Entity, Scope, and Etype fields, in case they
17057 -- reference entities that have been mapped into copies.
17059 Set_Next_Entity (New_Entity, Assoc (Next_Entity (New_Entity)));
17060 Set_Etype (New_Entity, Assoc (Etype (New_Entity)));
17062 if Present (New_Scope) then
17063 Set_Scope (New_Entity, New_Scope);
17065 Set_Scope (New_Entity, Assoc (Scope (New_Entity)));
17068 -- Copy referenced fields
17070 if Is_Discrete_Type (New_Entity) then
17071 Set_Scalar_Range (New_Entity,
17072 Copy_Node_With_Replacement (Scalar_Range (New_Entity)));
17074 elsif Has_Discriminants (Base_Type (New_Entity)) then
17075 Set_Discriminant_Constraint (New_Entity,
17076 Copy_Elist_With_Replacement
17077 (Discriminant_Constraint (New_Entity)));
17079 elsif Is_Array_Type (New_Entity) then
17080 if Present (First_Index (New_Entity)) then
17081 Set_First_Index (New_Entity,
17082 First (Copy_List_With_Replacement
17083 (List_Containing (First_Index (New_Entity)))));
17086 if Is_Packed (New_Entity) then
17087 Set_Packed_Array_Impl_Type (New_Entity,
17088 Copy_Node_With_Replacement
17089 (Packed_Array_Impl_Type (New_Entity)));
17092 end Copy_Entity_With_Replacement;
17094 --------------------------------
17095 -- Copy_List_With_Replacement --
17096 --------------------------------
17098 function Copy_List_With_Replacement
17099 (Old_List : List_Id) return List_Id
17101 New_List : List_Id;
17105 if Old_List = No_List then
17109 New_List := Empty_List;
17111 E := First (Old_List);
17112 while Present (E) loop
17113 Append (Copy_Node_With_Replacement (E), New_List);
17119 end Copy_List_With_Replacement;
17121 --------------------------------
17122 -- Copy_Node_With_Replacement --
17123 --------------------------------
17125 function Copy_Node_With_Replacement
17126 (Old_Node : Node_Id) return Node_Id
17128 New_Node : Node_Id;
17130 procedure Adjust_Named_Associations
17131 (Old_Node : Node_Id;
17132 New_Node : Node_Id);
17133 -- If a call node has named associations, these are chained through
17134 -- the First_Named_Actual, Next_Named_Actual links. These must be
17135 -- propagated separately to the new parameter list, because these
17136 -- are not syntactic fields.
17138 function Copy_Field_With_Replacement
17139 (Field : Union_Id) return Union_Id;
17140 -- Given Field, which is a field of Old_Node, return a copy of it
17141 -- if it is a syntactic field (i.e. its parent is Node), setting
17142 -- the parent of the copy to poit to New_Node. Otherwise returns
17143 -- the field (possibly mapped if it is an entity).
17145 -------------------------------
17146 -- Adjust_Named_Associations --
17147 -------------------------------
17149 procedure Adjust_Named_Associations
17150 (Old_Node : Node_Id;
17151 New_Node : Node_Id)
17156 Old_Next : Node_Id;
17157 New_Next : Node_Id;
17160 Old_E := First (Parameter_Associations (Old_Node));
17161 New_E := First (Parameter_Associations (New_Node));
17162 while Present (Old_E) loop
17163 if Nkind (Old_E) = N_Parameter_Association
17164 and then Present (Next_Named_Actual (Old_E))
17166 if First_Named_Actual (Old_Node) =
17167 Explicit_Actual_Parameter (Old_E)
17169 Set_First_Named_Actual
17170 (New_Node, Explicit_Actual_Parameter (New_E));
17173 -- Now scan parameter list from the beginning, to locate
17174 -- next named actual, which can be out of order.
17176 Old_Next := First (Parameter_Associations (Old_Node));
17177 New_Next := First (Parameter_Associations (New_Node));
17178 while Nkind (Old_Next) /= N_Parameter_Association
17179 or else Explicit_Actual_Parameter (Old_Next) /=
17180 Next_Named_Actual (Old_E)
17186 Set_Next_Named_Actual
17187 (New_E, Explicit_Actual_Parameter (New_Next));
17193 end Adjust_Named_Associations;
17195 ---------------------------------
17196 -- Copy_Field_With_Replacement --
17197 ---------------------------------
17199 function Copy_Field_With_Replacement
17200 (Field : Union_Id) return Union_Id
17203 if Field = Union_Id (Empty) then
17206 elsif Field in Node_Range then
17208 Old_N : constant Node_Id := Node_Id (Field);
17212 -- If syntactic field, as indicated by the parent pointer
17213 -- being set, then copy the referenced node recursively.
17215 if Parent (Old_N) = Old_Node then
17216 New_N := Copy_Node_With_Replacement (Old_N);
17218 if New_N /= Old_N then
17219 Set_Parent (New_N, New_Node);
17222 -- For semantic fields, update possible entity reference
17223 -- from the replacement map.
17226 New_N := Assoc (Old_N);
17229 return Union_Id (New_N);
17232 elsif Field in List_Range then
17234 Old_L : constant List_Id := List_Id (Field);
17238 -- If syntactic field, as indicated by the parent pointer,
17239 -- then recursively copy the entire referenced list.
17241 if Parent (Old_L) = Old_Node then
17242 New_L := Copy_List_With_Replacement (Old_L);
17243 Set_Parent (New_L, New_Node);
17245 -- For semantic list, just returned unchanged
17251 return Union_Id (New_L);
17254 -- Anything other than a list or a node is returned unchanged
17259 end Copy_Field_With_Replacement;
17261 -- Start of processing for Copy_Node_With_Replacement
17264 if Old_Node <= Empty_Or_Error then
17267 elsif Nkind (Old_Node) in N_Entity then
17268 return Assoc (Old_Node);
17271 New_Node := New_Copy (Old_Node);
17273 -- If the node we are copying is the associated node of a
17274 -- previously copied Itype, then adjust the associated node
17275 -- of the copy of that Itype accordingly.
17278 Ent : constant Entity_Id := NCT_Itype_Assoc.Get (Old_Node);
17281 if Present (Ent) then
17282 Set_Associated_Node_For_Itype (Ent, New_Node);
17286 -- Recursively copy descendants
17289 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
17291 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
17293 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
17295 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
17297 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
17299 -- Adjust Sloc of new node if necessary
17301 if New_Sloc /= No_Location then
17302 Set_Sloc (New_Node, New_Sloc);
17304 -- If we adjust the Sloc, then we are essentially making a
17305 -- completely new node, so the Comes_From_Source flag should
17306 -- be reset to the proper default value.
17308 Set_Comes_From_Source
17309 (New_Node, Default_Node.Comes_From_Source);
17312 -- If the node is a call and has named associations, set the
17313 -- corresponding links in the copy.
17315 if Nkind_In (Old_Node, N_Entry_Call_Statement,
17317 N_Procedure_Call_Statement)
17318 and then Present (First_Named_Actual (Old_Node))
17320 Adjust_Named_Associations (Old_Node, New_Node);
17323 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
17324 -- The replacement mechanism applies to entities, and is not used
17325 -- here. Eventually we may need a more general graph-copying
17326 -- routine. For now, do a sequential search to find desired node.
17328 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
17329 and then Present (First_Real_Statement (Old_Node))
17332 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
17336 N1 := First (Statements (Old_Node));
17337 N2 := First (Statements (New_Node));
17339 while N1 /= Old_F loop
17344 Set_First_Real_Statement (New_Node, N2);
17349 -- All done, return copied node
17352 end Copy_Node_With_Replacement;
17358 function In_Map (E : Entity_Id) return Boolean is
17363 if Present (Map) then
17364 Elmt := First_Elmt (Map);
17365 while Present (Elmt) loop
17366 Ent := Node (Elmt);
17384 procedure Visit_Elist (E : Elist_Id) is
17387 if Present (E) then
17388 Elmt := First_Elmt (E);
17390 while Elmt /= No_Elmt loop
17391 Visit_Node (Node (Elmt));
17401 procedure Visit_Entity (Old_Entity : Entity_Id) is
17405 pragma Assert (not Is_Itype (Old_Entity));
17406 pragma Assert (Nkind (Old_Entity) in N_Entity);
17408 -- Restrict entity creation to declarations of constants, variables
17409 -- and subtypes. There is no need to duplicate entities declared in
17412 if (not Ekind_In (Old_Entity, E_Constant, E_Variable)
17413 and then Nkind (Parent (Old_Entity)) /= N_Subtype_Declaration)
17414 or else EWA_Inner_Scope_Level > 0
17419 New_E := New_Copy (Old_Entity);
17421 -- The new entity has all the attributes of the old one, and we
17422 -- just copy the contents of the entity. However, the back-end
17423 -- needs different names for debugging purposes, so we create a
17424 -- new internal name for it in all cases.
17426 Set_Chars (New_E, New_Internal_Name ('T'));
17428 -- Add new association to map
17430 NCT_Assoc.Set (Old_Entity, New_E);
17431 NCT_Hash_Tables_Used := True;
17433 -- Visit descendants that eventually get copied
17435 Visit_Field (Union_Id (Etype (Old_Entity)), Old_Entity);
17442 procedure Visit_Field (F : Union_Id; N : Node_Id) is
17444 if F = Union_Id (Empty) then
17447 elsif F in Node_Range then
17449 -- Copy node if it is syntactic, i.e. its parent pointer is
17450 -- set to point to the field that referenced it (certain
17451 -- Itypes will also meet this criterion, which is fine, since
17452 -- these are clearly Itypes that do need to be copied, since
17453 -- we are copying their parent.)
17455 if Parent (Node_Id (F)) = N then
17456 Visit_Node (Node_Id (F));
17459 -- Another case, if we are pointing to an Itype, then we want
17460 -- to copy it if its associated node is somewhere in the tree
17463 -- Note: the exclusion of self-referential copies is just an
17464 -- optimization, since the search of the already copied list
17465 -- would catch it, but it is a common case (Etype pointing to
17466 -- itself for an Itype that is a base type).
17468 elsif Nkind (Node_Id (F)) in N_Entity
17469 and then Is_Itype (Entity_Id (F))
17470 and then Node_Id (F) /= N
17476 P := Associated_Node_For_Itype (Node_Id (F));
17477 while Present (P) loop
17479 Visit_Node (Node_Id (F));
17486 -- An Itype whose parent is not being copied definitely
17487 -- should NOT be copied, since it does not belong in any
17488 -- sense to the copied subtree.
17494 elsif F in List_Range and then Parent (List_Id (F)) = N then
17495 Visit_List (List_Id (F));
17504 procedure Visit_Itype (Old_Itype : Entity_Id) is
17505 New_Itype : Entity_Id;
17509 -- Itypes that describe the designated type of access to subprograms
17510 -- have the structure of subprogram declarations, with signatures,
17511 -- etc. Either we duplicate the signatures completely, or choose to
17512 -- share such itypes, which is fine because their elaboration will
17513 -- have no side effects.
17515 if Ekind (Old_Itype) = E_Subprogram_Type then
17519 New_Itype := New_Copy (Old_Itype);
17521 -- The new Itype has all the attributes of the old one, and we
17522 -- just copy the contents of the entity. However, the back-end
17523 -- needs different names for debugging purposes, so we create a
17524 -- new internal name for it in all cases.
17526 Set_Chars (New_Itype, New_Internal_Name ('T'));
17528 -- If our associated node is an entity that has already been copied,
17529 -- then set the associated node of the copy to point to the right
17530 -- copy. If we have copied an Itype that is itself the associated
17531 -- node of some previously copied Itype, then we set the right
17532 -- pointer in the other direction.
17534 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
17536 if Present (Ent) then
17537 Set_Associated_Node_For_Itype (New_Itype, Ent);
17540 Ent := NCT_Itype_Assoc.Get (Old_Itype);
17542 if Present (Ent) then
17543 Set_Associated_Node_For_Itype (Ent, New_Itype);
17545 -- If the hash table has no association for this Itype and its
17546 -- associated node, enter one now.
17549 NCT_Itype_Assoc.Set
17550 (Associated_Node_For_Itype (Old_Itype), New_Itype);
17553 if Present (Freeze_Node (New_Itype)) then
17554 Set_Is_Frozen (New_Itype, False);
17555 Set_Freeze_Node (New_Itype, Empty);
17558 -- Add new association to map
17560 NCT_Assoc.Set (Old_Itype, New_Itype);
17561 NCT_Hash_Tables_Used := True;
17563 -- If a record subtype is simply copied, the entity list will be
17564 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
17566 if Ekind_In (Old_Itype, E_Class_Wide_Subtype, E_Record_Subtype) then
17567 Set_Cloned_Subtype (New_Itype, Old_Itype);
17570 -- Visit descendants that eventually get copied
17572 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
17574 if Is_Discrete_Type (Old_Itype) then
17575 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
17577 elsif Has_Discriminants (Base_Type (Old_Itype)) then
17578 -- ??? This should involve call to Visit_Field
17579 Visit_Elist (Discriminant_Constraint (Old_Itype));
17581 elsif Is_Array_Type (Old_Itype) then
17582 if Present (First_Index (Old_Itype)) then
17584 (Union_Id (List_Containing (First_Index (Old_Itype))),
17588 if Is_Packed (Old_Itype) then
17590 (Union_Id (Packed_Array_Impl_Type (Old_Itype)), Old_Itype);
17599 procedure Visit_List (L : List_Id) is
17602 if L /= No_List then
17605 while Present (N) loop
17616 procedure Visit_Node (N : Node_Or_Entity_Id) is
17618 if Nkind (N) = N_Expression_With_Actions then
17619 EWA_Level := EWA_Level + 1;
17621 elsif EWA_Level > 0
17622 and then Nkind_In (N, N_Block_Statement,
17624 N_Subprogram_Declaration)
17626 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level + 1;
17628 -- Handle case of an Itype, which must be copied
17630 elsif Nkind (N) in N_Entity and then Is_Itype (N) then
17632 -- Nothing to do if already in the list. This can happen with an
17633 -- Itype entity that appears more than once in the tree. Note that
17634 -- we do not want to visit descendants in this case.
17636 if Present (NCT_Assoc.Get (Entity_Id (N))) then
17642 -- Handle defining entities in Expression_With_Action nodes
17644 elsif Nkind (N) in N_Entity and then EWA_Level > 0 then
17646 -- Nothing to do if already in the hash table
17648 if Present (NCT_Assoc.Get (Entity_Id (N))) then
17655 -- Visit descendants
17657 Visit_Field (Field1 (N), N);
17658 Visit_Field (Field2 (N), N);
17659 Visit_Field (Field3 (N), N);
17660 Visit_Field (Field4 (N), N);
17661 Visit_Field (Field5 (N), N);
17664 and then Nkind_In (N, N_Block_Statement,
17666 N_Subprogram_Declaration)
17668 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level - 1;
17670 elsif Nkind (N) = N_Expression_With_Actions then
17671 EWA_Level := EWA_Level - 1;
17675 -- Start of processing for New_Copy_Tree
17678 Build_NCT_Hash_Tables;
17680 -- Hash table set up if required, now start phase one by visiting top
17681 -- node (we will recursively visit the descendants).
17683 Visit_Node (Source);
17685 -- Now the second phase of the copy can start. First we process all the
17686 -- mapped entities, copying their descendants.
17688 if NCT_Hash_Tables_Used then
17690 Old_E : Entity_Id := Empty;
17694 NCT_Assoc.Get_First (Old_E, New_E);
17695 while Present (New_E) loop
17697 -- Skip entities that were not created in the first phase
17698 -- (that is, old entities specified by the caller in the
17699 -- set of mappings to be applied to the tree).
17701 if Is_Itype (New_E)
17703 or else not In_Map (Old_E)
17705 Copy_Entity_With_Replacement (New_E);
17708 NCT_Assoc.Get_Next (Old_E, New_E);
17713 -- Now we can copy the actual tree
17716 Result : constant Node_Id := Copy_Node_With_Replacement (Source);
17719 if NCT_Hash_Tables_Used then
17721 NCT_Itype_Assoc.Reset;
17728 -------------------------
17729 -- New_External_Entity --
17730 -------------------------
17732 function New_External_Entity
17733 (Kind : Entity_Kind;
17734 Scope_Id : Entity_Id;
17735 Sloc_Value : Source_Ptr;
17736 Related_Id : Entity_Id;
17737 Suffix : Character;
17738 Suffix_Index : Nat := 0;
17739 Prefix : Character := ' ') return Entity_Id
17741 N : constant Entity_Id :=
17742 Make_Defining_Identifier (Sloc_Value,
17744 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
17747 Set_Ekind (N, Kind);
17748 Set_Is_Internal (N, True);
17749 Append_Entity (N, Scope_Id);
17750 Set_Public_Status (N);
17752 if Kind in Type_Kind then
17753 Init_Size_Align (N);
17757 end New_External_Entity;
17759 -------------------------
17760 -- New_Internal_Entity --
17761 -------------------------
17763 function New_Internal_Entity
17764 (Kind : Entity_Kind;
17765 Scope_Id : Entity_Id;
17766 Sloc_Value : Source_Ptr;
17767 Id_Char : Character) return Entity_Id
17769 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
17772 Set_Ekind (N, Kind);
17773 Set_Is_Internal (N, True);
17774 Append_Entity (N, Scope_Id);
17776 if Kind in Type_Kind then
17777 Init_Size_Align (N);
17781 end New_Internal_Entity;
17787 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
17791 -- If we are pointing at a positional parameter, it is a member of a
17792 -- node list (the list of parameters), and the next parameter is the
17793 -- next node on the list, unless we hit a parameter association, then
17794 -- we shift to using the chain whose head is the First_Named_Actual in
17795 -- the parent, and then is threaded using the Next_Named_Actual of the
17796 -- Parameter_Association. All this fiddling is because the original node
17797 -- list is in the textual call order, and what we need is the
17798 -- declaration order.
17800 if Is_List_Member (Actual_Id) then
17801 N := Next (Actual_Id);
17803 if Nkind (N) = N_Parameter_Association then
17804 return First_Named_Actual (Parent (Actual_Id));
17810 return Next_Named_Actual (Parent (Actual_Id));
17814 procedure Next_Actual (Actual_Id : in out Node_Id) is
17816 Actual_Id := Next_Actual (Actual_Id);
17819 ----------------------------------
17820 -- New_Requires_Transient_Scope --
17821 ----------------------------------
17823 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
17824 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean;
17825 -- This is called for untagged records and protected types, with
17826 -- nondefaulted discriminants. Returns True if the size of function
17827 -- results is known at the call site, False otherwise. Returns False
17828 -- if there is a variant part that depends on the discriminants of
17829 -- this type, or if there is an array constrained by the discriminants
17830 -- of this type. ???Currently, this is overly conservative (the array
17831 -- could be nested inside some other record that is constrained by
17832 -- nondiscriminants). That is, the recursive calls are too conservative.
17834 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean;
17835 -- Returns True if Typ is a nonlimited record with defaulted
17836 -- discriminants whose max size makes it unsuitable for allocating on
17837 -- the primary stack.
17839 ------------------------------
17840 -- Caller_Known_Size_Record --
17841 ------------------------------
17843 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean is
17844 pragma Assert (Typ = Underlying_Type (Typ));
17847 if Has_Variant_Part (Typ) and then not Is_Definite_Subtype (Typ) then
17855 Comp := First_Entity (Typ);
17856 while Present (Comp) loop
17858 -- Only look at E_Component entities. No need to look at
17859 -- E_Discriminant entities, and we must ignore internal
17860 -- subtypes generated for constrained components.
17862 if Ekind (Comp) = E_Component then
17864 Comp_Type : constant Entity_Id :=
17865 Underlying_Type (Etype (Comp));
17868 if Is_Record_Type (Comp_Type)
17870 Is_Protected_Type (Comp_Type)
17872 if not Caller_Known_Size_Record (Comp_Type) then
17876 elsif Is_Array_Type (Comp_Type) then
17877 if Size_Depends_On_Discriminant (Comp_Type) then
17884 Next_Entity (Comp);
17889 end Caller_Known_Size_Record;
17891 ------------------------------
17892 -- Large_Max_Size_Mutable --
17893 ------------------------------
17895 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean is
17896 pragma Assert (Typ = Underlying_Type (Typ));
17898 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean;
17899 -- Returns true if the discrete type T has a large range
17901 ----------------------------
17902 -- Is_Large_Discrete_Type --
17903 ----------------------------
17905 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean is
17906 Threshold : constant Int := 16;
17907 -- Arbitrary threshold above which we consider it "large". We want
17908 -- a fairly large threshold, because these large types really
17909 -- shouldn't have default discriminants in the first place, in
17913 return UI_To_Int (RM_Size (T)) > Threshold;
17914 end Is_Large_Discrete_Type;
17916 -- Start of processing for Large_Max_Size_Mutable
17919 if Is_Record_Type (Typ)
17920 and then not Is_Limited_View (Typ)
17921 and then Has_Defaulted_Discriminants (Typ)
17923 -- Loop through the components, looking for an array whose upper
17924 -- bound(s) depends on discriminants, where both the subtype of
17925 -- the discriminant and the index subtype are too large.
17931 Comp := First_Entity (Typ);
17932 while Present (Comp) loop
17933 if Ekind (Comp) = E_Component then
17935 Comp_Type : constant Entity_Id :=
17936 Underlying_Type (Etype (Comp));
17943 if Is_Array_Type (Comp_Type) then
17944 Indx := First_Index (Comp_Type);
17946 while Present (Indx) loop
17947 Ityp := Etype (Indx);
17948 Hi := Type_High_Bound (Ityp);
17950 if Nkind (Hi) = N_Identifier
17951 and then Ekind (Entity (Hi)) = E_Discriminant
17952 and then Is_Large_Discrete_Type (Ityp)
17953 and then Is_Large_Discrete_Type
17954 (Etype (Entity (Hi)))
17965 Next_Entity (Comp);
17971 end Large_Max_Size_Mutable;
17973 -- Local declarations
17975 Typ : constant Entity_Id := Underlying_Type (Id);
17977 -- Start of processing for New_Requires_Transient_Scope
17980 -- This is a private type which is not completed yet. This can only
17981 -- happen in a default expression (of a formal parameter or of a
17982 -- record component). Do not expand transient scope in this case.
17987 -- Do not expand transient scope for non-existent procedure return or
17988 -- string literal types.
17990 elsif Typ = Standard_Void_Type
17991 or else Ekind (Typ) = E_String_Literal_Subtype
17995 -- If Typ is a generic formal incomplete type, then we want to look at
17996 -- the actual type.
17998 elsif Ekind (Typ) = E_Record_Subtype
17999 and then Present (Cloned_Subtype (Typ))
18001 return New_Requires_Transient_Scope (Cloned_Subtype (Typ));
18003 -- Functions returning specific tagged types may dispatch on result, so
18004 -- their returned value is allocated on the secondary stack, even in the
18005 -- definite case. We must treat nondispatching functions the same way,
18006 -- because access-to-function types can point at both, so the calling
18007 -- conventions must be compatible. Is_Tagged_Type includes controlled
18008 -- types and class-wide types. Controlled type temporaries need
18011 -- ???It's not clear why we need to return noncontrolled types with
18012 -- controlled components on the secondary stack.
18014 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
18017 -- Untagged definite subtypes are known size. This includes all
18018 -- elementary [sub]types. Tasks are known size even if they have
18019 -- discriminants. So we return False here, with one exception:
18020 -- For a type like:
18021 -- type T (Last : Natural := 0) is
18022 -- X : String (1 .. Last);
18024 -- we return True. That's because for "P(F(...));", where F returns T,
18025 -- we don't know the size of the result at the call site, so if we
18026 -- allocated it on the primary stack, we would have to allocate the
18027 -- maximum size, which is way too big.
18029 elsif Is_Definite_Subtype (Typ) or else Is_Task_Type (Typ) then
18030 return Large_Max_Size_Mutable (Typ);
18032 -- Indefinite (discriminated) untagged record or protected type
18034 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
18035 return not Caller_Known_Size_Record (Typ);
18037 -- Unconstrained array
18040 pragma Assert (Is_Array_Type (Typ) and not Is_Definite_Subtype (Typ));
18043 end New_Requires_Transient_Scope;
18045 --------------------------
18046 -- No_Heap_Finalization --
18047 --------------------------
18049 function No_Heap_Finalization (Typ : Entity_Id) return Boolean is
18051 if Ekind_In (Typ, E_Access_Type, E_General_Access_Type)
18052 and then Is_Library_Level_Entity (Typ)
18054 -- A global No_Heap_Finalization pragma applies to all library-level
18055 -- named access-to-object types.
18057 if Present (No_Heap_Finalization_Pragma) then
18060 -- The library-level named access-to-object type itself is subject to
18061 -- pragma No_Heap_Finalization.
18063 elsif Present (Get_Pragma (Typ, Pragma_No_Heap_Finalization)) then
18069 end No_Heap_Finalization;
18071 -----------------------
18072 -- Normalize_Actuals --
18073 -----------------------
18075 -- Chain actuals according to formals of subprogram. If there are no named
18076 -- associations, the chain is simply the list of Parameter Associations,
18077 -- since the order is the same as the declaration order. If there are named
18078 -- associations, then the First_Named_Actual field in the N_Function_Call
18079 -- or N_Procedure_Call_Statement node points to the Parameter_Association
18080 -- node for the parameter that comes first in declaration order. The
18081 -- remaining named parameters are then chained in declaration order using
18082 -- Next_Named_Actual.
18084 -- This routine also verifies that the number of actuals is compatible with
18085 -- the number and default values of formals, but performs no type checking
18086 -- (type checking is done by the caller).
18088 -- If the matching succeeds, Success is set to True and the caller proceeds
18089 -- with type-checking. If the match is unsuccessful, then Success is set to
18090 -- False, and the caller attempts a different interpretation, if there is
18093 -- If the flag Report is on, the call is not overloaded, and a failure to
18094 -- match can be reported here, rather than in the caller.
18096 procedure Normalize_Actuals
18100 Success : out Boolean)
18102 Actuals : constant List_Id := Parameter_Associations (N);
18103 Actual : Node_Id := Empty;
18104 Formal : Entity_Id;
18105 Last : Node_Id := Empty;
18106 First_Named : Node_Id := Empty;
18109 Formals_To_Match : Integer := 0;
18110 Actuals_To_Match : Integer := 0;
18112 procedure Chain (A : Node_Id);
18113 -- Add named actual at the proper place in the list, using the
18114 -- Next_Named_Actual link.
18116 function Reporting return Boolean;
18117 -- Determines if an error is to be reported. To report an error, we
18118 -- need Report to be True, and also we do not report errors caused
18119 -- by calls to init procs that occur within other init procs. Such
18120 -- errors must always be cascaded errors, since if all the types are
18121 -- declared correctly, the compiler will certainly build decent calls.
18127 procedure Chain (A : Node_Id) is
18131 -- Call node points to first actual in list
18133 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
18136 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
18140 Set_Next_Named_Actual (Last, Empty);
18147 function Reporting return Boolean is
18152 elsif not Within_Init_Proc then
18155 elsif Is_Init_Proc (Entity (Name (N))) then
18163 -- Start of processing for Normalize_Actuals
18166 if Is_Access_Type (S) then
18168 -- The name in the call is a function call that returns an access
18169 -- to subprogram. The designated type has the list of formals.
18171 Formal := First_Formal (Designated_Type (S));
18173 Formal := First_Formal (S);
18176 while Present (Formal) loop
18177 Formals_To_Match := Formals_To_Match + 1;
18178 Next_Formal (Formal);
18181 -- Find if there is a named association, and verify that no positional
18182 -- associations appear after named ones.
18184 if Present (Actuals) then
18185 Actual := First (Actuals);
18188 while Present (Actual)
18189 and then Nkind (Actual) /= N_Parameter_Association
18191 Actuals_To_Match := Actuals_To_Match + 1;
18195 if No (Actual) and Actuals_To_Match = Formals_To_Match then
18197 -- Most common case: positional notation, no defaults
18202 elsif Actuals_To_Match > Formals_To_Match then
18204 -- Too many actuals: will not work
18207 if Is_Entity_Name (Name (N)) then
18208 Error_Msg_N ("too many arguments in call to&", Name (N));
18210 Error_Msg_N ("too many arguments in call", N);
18218 First_Named := Actual;
18220 while Present (Actual) loop
18221 if Nkind (Actual) /= N_Parameter_Association then
18223 ("positional parameters not allowed after named ones", Actual);
18228 Actuals_To_Match := Actuals_To_Match + 1;
18234 if Present (Actuals) then
18235 Actual := First (Actuals);
18238 Formal := First_Formal (S);
18239 while Present (Formal) loop
18241 -- Match the formals in order. If the corresponding actual is
18242 -- positional, nothing to do. Else scan the list of named actuals
18243 -- to find the one with the right name.
18245 if Present (Actual)
18246 and then Nkind (Actual) /= N_Parameter_Association
18249 Actuals_To_Match := Actuals_To_Match - 1;
18250 Formals_To_Match := Formals_To_Match - 1;
18253 -- For named parameters, search the list of actuals to find
18254 -- one that matches the next formal name.
18256 Actual := First_Named;
18258 while Present (Actual) loop
18259 if Chars (Selector_Name (Actual)) = Chars (Formal) then
18262 Actuals_To_Match := Actuals_To_Match - 1;
18263 Formals_To_Match := Formals_To_Match - 1;
18271 if Ekind (Formal) /= E_In_Parameter
18272 or else No (Default_Value (Formal))
18275 if (Comes_From_Source (S)
18276 or else Sloc (S) = Standard_Location)
18277 and then Is_Overloadable (S)
18281 Nkind_In (Parent (N), N_Procedure_Call_Statement,
18283 N_Parameter_Association)
18284 and then Ekind (S) /= E_Function
18286 Set_Etype (N, Etype (S));
18289 Error_Msg_Name_1 := Chars (S);
18290 Error_Msg_Sloc := Sloc (S);
18292 ("missing argument for parameter & "
18293 & "in call to % declared #", N, Formal);
18296 elsif Is_Overloadable (S) then
18297 Error_Msg_Name_1 := Chars (S);
18299 -- Point to type derivation that generated the
18302 Error_Msg_Sloc := Sloc (Parent (S));
18305 ("missing argument for parameter & "
18306 & "in call to % (inherited) #", N, Formal);
18310 ("missing argument for parameter &", N, Formal);
18318 Formals_To_Match := Formals_To_Match - 1;
18323 Next_Formal (Formal);
18326 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
18333 -- Find some superfluous named actual that did not get
18334 -- attached to the list of associations.
18336 Actual := First (Actuals);
18337 while Present (Actual) loop
18338 if Nkind (Actual) = N_Parameter_Association
18339 and then Actual /= Last
18340 and then No (Next_Named_Actual (Actual))
18342 -- A validity check may introduce a copy of a call that
18343 -- includes an extra actual (for example for an unrelated
18344 -- accessibility check). Check that the extra actual matches
18345 -- some extra formal, which must exist already because
18346 -- subprogram must be frozen at this point.
18348 if Present (Extra_Formals (S))
18349 and then not Comes_From_Source (Actual)
18350 and then Nkind (Actual) = N_Parameter_Association
18351 and then Chars (Extra_Formals (S)) =
18352 Chars (Selector_Name (Actual))
18357 ("unmatched actual & in call", Selector_Name (Actual));
18369 end Normalize_Actuals;
18371 --------------------------------
18372 -- Note_Possible_Modification --
18373 --------------------------------
18375 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
18376 Modification_Comes_From_Source : constant Boolean :=
18377 Comes_From_Source (Parent (N));
18383 -- Loop to find referenced entity, if there is one
18389 if Is_Entity_Name (Exp) then
18390 Ent := Entity (Exp);
18392 -- If the entity is missing, it is an undeclared identifier,
18393 -- and there is nothing to annotate.
18399 elsif Nkind (Exp) = N_Explicit_Dereference then
18401 P : constant Node_Id := Prefix (Exp);
18404 -- In formal verification mode, keep track of all reads and
18405 -- writes through explicit dereferences.
18407 if GNATprove_Mode then
18408 SPARK_Specific.Generate_Dereference (N, 'm');
18411 if Nkind (P) = N_Selected_Component
18412 and then Present (Entry_Formal (Entity (Selector_Name (P))))
18414 -- Case of a reference to an entry formal
18416 Ent := Entry_Formal (Entity (Selector_Name (P)));
18418 elsif Nkind (P) = N_Identifier
18419 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
18420 and then Present (Expression (Parent (Entity (P))))
18421 and then Nkind (Expression (Parent (Entity (P)))) =
18424 -- Case of a reference to a value on which side effects have
18427 Exp := Prefix (Expression (Parent (Entity (P))));
18435 elsif Nkind_In (Exp, N_Type_Conversion,
18436 N_Unchecked_Type_Conversion)
18438 Exp := Expression (Exp);
18441 elsif Nkind_In (Exp, N_Slice,
18442 N_Indexed_Component,
18443 N_Selected_Component)
18445 -- Special check, if the prefix is an access type, then return
18446 -- since we are modifying the thing pointed to, not the prefix.
18447 -- When we are expanding, most usually the prefix is replaced
18448 -- by an explicit dereference, and this test is not needed, but
18449 -- in some cases (notably -gnatc mode and generics) when we do
18450 -- not do full expansion, we need this special test.
18452 if Is_Access_Type (Etype (Prefix (Exp))) then
18455 -- Otherwise go to prefix and keep going
18458 Exp := Prefix (Exp);
18462 -- All other cases, not a modification
18468 -- Now look for entity being referenced
18470 if Present (Ent) then
18471 if Is_Object (Ent) then
18472 if Comes_From_Source (Exp)
18473 or else Modification_Comes_From_Source
18475 -- Give warning if pragma unmodified is given and we are
18476 -- sure this is a modification.
18478 if Has_Pragma_Unmodified (Ent) and then Sure then
18480 -- Note that the entity may be present only as a result
18481 -- of pragma Unused.
18483 if Has_Pragma_Unused (Ent) then
18484 Error_Msg_NE ("??pragma Unused given for &!", N, Ent);
18487 ("??pragma Unmodified given for &!", N, Ent);
18491 Set_Never_Set_In_Source (Ent, False);
18494 Set_Is_True_Constant (Ent, False);
18495 Set_Current_Value (Ent, Empty);
18496 Set_Is_Known_Null (Ent, False);
18498 if not Can_Never_Be_Null (Ent) then
18499 Set_Is_Known_Non_Null (Ent, False);
18502 -- Follow renaming chain
18504 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
18505 and then Present (Renamed_Object (Ent))
18507 Exp := Renamed_Object (Ent);
18509 -- If the entity is the loop variable in an iteration over
18510 -- a container, retrieve container expression to indicate
18511 -- possible modification.
18513 if Present (Related_Expression (Ent))
18514 and then Nkind (Parent (Related_Expression (Ent))) =
18515 N_Iterator_Specification
18517 Exp := Original_Node (Related_Expression (Ent));
18522 -- The expression may be the renaming of a subcomponent of an
18523 -- array or container. The assignment to the subcomponent is
18524 -- a modification of the container.
18526 elsif Comes_From_Source (Original_Node (Exp))
18527 and then Nkind_In (Original_Node (Exp), N_Selected_Component,
18528 N_Indexed_Component)
18530 Exp := Prefix (Original_Node (Exp));
18534 -- Generate a reference only if the assignment comes from
18535 -- source. This excludes, for example, calls to a dispatching
18536 -- assignment operation when the left-hand side is tagged. In
18537 -- GNATprove mode, we need those references also on generated
18538 -- code, as these are used to compute the local effects of
18541 if Modification_Comes_From_Source or GNATprove_Mode then
18542 Generate_Reference (Ent, Exp, 'm');
18544 -- If the target of the assignment is the bound variable
18545 -- in an iterator, indicate that the corresponding array
18546 -- or container is also modified.
18548 if Ada_Version >= Ada_2012
18549 and then Nkind (Parent (Ent)) = N_Iterator_Specification
18552 Domain : constant Node_Id := Name (Parent (Ent));
18555 -- TBD : in the full version of the construct, the
18556 -- domain of iteration can be given by an expression.
18558 if Is_Entity_Name (Domain) then
18559 Generate_Reference (Entity (Domain), Exp, 'm');
18560 Set_Is_True_Constant (Entity (Domain), False);
18561 Set_Never_Set_In_Source (Entity (Domain), False);
18570 -- If we are sure this is a modification from source, and we know
18571 -- this modifies a constant, then give an appropriate warning.
18574 and then Modification_Comes_From_Source
18575 and then Overlays_Constant (Ent)
18576 and then Address_Clause_Overlay_Warnings
18579 Addr : constant Node_Id := Address_Clause (Ent);
18584 Find_Overlaid_Entity (Addr, O_Ent, Off);
18586 Error_Msg_Sloc := Sloc (Addr);
18588 ("??constant& may be modified via address clause#",
18599 end Note_Possible_Modification;
18605 function Null_Status (N : Node_Id) return Null_Status_Kind is
18606 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean;
18607 -- Determine whether definition Def carries a null exclusion
18609 function Null_Status_Of_Entity (Id : Entity_Id) return Null_Status_Kind;
18610 -- Determine the null status of arbitrary entity Id
18612 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind;
18613 -- Determine the null status of type Typ
18615 ---------------------------
18616 -- Is_Null_Excluding_Def --
18617 ---------------------------
18619 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean is
18622 Nkind_In (Def, N_Access_Definition,
18623 N_Access_Function_Definition,
18624 N_Access_Procedure_Definition,
18625 N_Access_To_Object_Definition,
18626 N_Component_Definition,
18627 N_Derived_Type_Definition)
18628 and then Null_Exclusion_Present (Def);
18629 end Is_Null_Excluding_Def;
18631 ---------------------------
18632 -- Null_Status_Of_Entity --
18633 ---------------------------
18635 function Null_Status_Of_Entity
18636 (Id : Entity_Id) return Null_Status_Kind
18638 Decl : constant Node_Id := Declaration_Node (Id);
18642 -- The value of an imported or exported entity may be set externally
18643 -- regardless of a null exclusion. As a result, the value cannot be
18644 -- determined statically.
18646 if Is_Imported (Id) or else Is_Exported (Id) then
18649 elsif Nkind_In (Decl, N_Component_Declaration,
18650 N_Discriminant_Specification,
18651 N_Formal_Object_Declaration,
18652 N_Object_Declaration,
18653 N_Object_Renaming_Declaration,
18654 N_Parameter_Specification)
18656 -- A component declaration yields a non-null value when either
18657 -- its component definition or access definition carries a null
18660 if Nkind (Decl) = N_Component_Declaration then
18661 Def := Component_Definition (Decl);
18663 if Is_Null_Excluding_Def (Def) then
18664 return Is_Non_Null;
18667 Def := Access_Definition (Def);
18669 if Present (Def) and then Is_Null_Excluding_Def (Def) then
18670 return Is_Non_Null;
18673 -- A formal object declaration yields a non-null value if its
18674 -- access definition carries a null exclusion. If the object is
18675 -- default initialized, then the value depends on the expression.
18677 elsif Nkind (Decl) = N_Formal_Object_Declaration then
18678 Def := Access_Definition (Decl);
18680 if Present (Def) and then Is_Null_Excluding_Def (Def) then
18681 return Is_Non_Null;
18684 -- A constant may yield a null or non-null value depending on its
18685 -- initialization expression.
18687 elsif Ekind (Id) = E_Constant then
18688 return Null_Status (Constant_Value (Id));
18690 -- The construct yields a non-null value when it has a null
18693 elsif Null_Exclusion_Present (Decl) then
18694 return Is_Non_Null;
18696 -- An object renaming declaration yields a non-null value if its
18697 -- access definition carries a null exclusion. Otherwise the value
18698 -- depends on the renamed name.
18700 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
18701 Def := Access_Definition (Decl);
18703 if Present (Def) and then Is_Null_Excluding_Def (Def) then
18704 return Is_Non_Null;
18707 return Null_Status (Name (Decl));
18712 -- At this point the declaration of the entity does not carry a null
18713 -- exclusion and lacks an initialization expression. Check the status
18716 return Null_Status_Of_Type (Etype (Id));
18717 end Null_Status_Of_Entity;
18719 -------------------------
18720 -- Null_Status_Of_Type --
18721 -------------------------
18723 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind is
18728 -- Traverse the type chain looking for types with null exclusion
18731 while Present (Curr) and then Etype (Curr) /= Curr loop
18732 Decl := Parent (Curr);
18734 -- Guard against itypes which do not always have declarations. A
18735 -- type yields a non-null value if it carries a null exclusion.
18737 if Present (Decl) then
18738 if Nkind (Decl) = N_Full_Type_Declaration
18739 and then Is_Null_Excluding_Def (Type_Definition (Decl))
18741 return Is_Non_Null;
18743 elsif Nkind (Decl) = N_Subtype_Declaration
18744 and then Null_Exclusion_Present (Decl)
18746 return Is_Non_Null;
18750 Curr := Etype (Curr);
18753 -- The type chain does not contain any null excluding types
18756 end Null_Status_Of_Type;
18758 -- Start of processing for Null_Status
18761 -- An allocator always creates a non-null value
18763 if Nkind (N) = N_Allocator then
18764 return Is_Non_Null;
18766 -- Taking the 'Access of something yields a non-null value
18768 elsif Nkind (N) = N_Attribute_Reference
18769 and then Nam_In (Attribute_Name (N), Name_Access,
18770 Name_Unchecked_Access,
18771 Name_Unrestricted_Access)
18773 return Is_Non_Null;
18775 -- "null" yields null
18777 elsif Nkind (N) = N_Null then
18780 -- Check the status of the operand of a type conversion
18782 elsif Nkind (N) = N_Type_Conversion then
18783 return Null_Status (Expression (N));
18785 -- The input denotes a reference to an entity. Determine whether the
18786 -- entity or its type yields a null or non-null value.
18788 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
18789 return Null_Status_Of_Entity (Entity (N));
18792 -- Otherwise it is not possible to determine the null status of the
18793 -- subexpression at compile time without resorting to simple flow
18799 --------------------------------------
18800 -- Null_To_Null_Address_Convert_OK --
18801 --------------------------------------
18803 function Null_To_Null_Address_Convert_OK
18805 Typ : Entity_Id := Empty) return Boolean
18808 if not Relaxed_RM_Semantics then
18812 if Nkind (N) = N_Null then
18813 return Present (Typ) and then Is_Descendant_Of_Address (Typ);
18815 elsif Nkind_In (N, N_Op_Eq, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt, N_Op_Ne)
18818 L : constant Node_Id := Left_Opnd (N);
18819 R : constant Node_Id := Right_Opnd (N);
18822 -- We check the Etype of the complementary operand since the
18823 -- N_Null node is not decorated at this stage.
18826 ((Nkind (L) = N_Null
18827 and then Is_Descendant_Of_Address (Etype (R)))
18829 (Nkind (R) = N_Null
18830 and then Is_Descendant_Of_Address (Etype (L))));
18835 end Null_To_Null_Address_Convert_OK;
18837 -------------------------
18838 -- Object_Access_Level --
18839 -------------------------
18841 -- Returns the static accessibility level of the view denoted by Obj. Note
18842 -- that the value returned is the result of a call to Scope_Depth. Only
18843 -- scope depths associated with dynamic scopes can actually be returned.
18844 -- Since only relative levels matter for accessibility checking, the fact
18845 -- that the distance between successive levels of accessibility is not
18846 -- always one is immaterial (invariant: if level(E2) is deeper than
18847 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
18849 function Object_Access_Level (Obj : Node_Id) return Uint is
18850 function Is_Interface_Conversion (N : Node_Id) return Boolean;
18851 -- Determine whether N is a construct of the form
18852 -- Some_Type (Operand._tag'Address)
18853 -- This construct appears in the context of dispatching calls.
18855 function Reference_To (Obj : Node_Id) return Node_Id;
18856 -- An explicit dereference is created when removing side-effects from
18857 -- expressions for constraint checking purposes. In this case a local
18858 -- access type is created for it. The correct access level is that of
18859 -- the original source node. We detect this case by noting that the
18860 -- prefix of the dereference is created by an object declaration whose
18861 -- initial expression is a reference.
18863 -----------------------------
18864 -- Is_Interface_Conversion --
18865 -----------------------------
18867 function Is_Interface_Conversion (N : Node_Id) return Boolean is
18869 return Nkind (N) = N_Unchecked_Type_Conversion
18870 and then Nkind (Expression (N)) = N_Attribute_Reference
18871 and then Attribute_Name (Expression (N)) = Name_Address;
18872 end Is_Interface_Conversion;
18878 function Reference_To (Obj : Node_Id) return Node_Id is
18879 Pref : constant Node_Id := Prefix (Obj);
18881 if Is_Entity_Name (Pref)
18882 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
18883 and then Present (Expression (Parent (Entity (Pref))))
18884 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
18886 return (Prefix (Expression (Parent (Entity (Pref)))));
18896 -- Start of processing for Object_Access_Level
18899 if Nkind (Obj) = N_Defining_Identifier
18900 or else Is_Entity_Name (Obj)
18902 if Nkind (Obj) = N_Defining_Identifier then
18908 if Is_Prival (E) then
18909 E := Prival_Link (E);
18912 -- If E is a type then it denotes a current instance. For this case
18913 -- we add one to the normal accessibility level of the type to ensure
18914 -- that current instances are treated as always being deeper than
18915 -- than the level of any visible named access type (see 3.10.2(21)).
18917 if Is_Type (E) then
18918 return Type_Access_Level (E) + 1;
18920 elsif Present (Renamed_Object (E)) then
18921 return Object_Access_Level (Renamed_Object (E));
18923 -- Similarly, if E is a component of the current instance of a
18924 -- protected type, any instance of it is assumed to be at a deeper
18925 -- level than the type. For a protected object (whose type is an
18926 -- anonymous protected type) its components are at the same level
18927 -- as the type itself.
18929 elsif not Is_Overloadable (E)
18930 and then Ekind (Scope (E)) = E_Protected_Type
18931 and then Comes_From_Source (Scope (E))
18933 return Type_Access_Level (Scope (E)) + 1;
18936 -- Aliased formals of functions take their access level from the
18937 -- point of call, i.e. require a dynamic check. For static check
18938 -- purposes, this is smaller than the level of the subprogram
18939 -- itself. For procedures the aliased makes no difference.
18942 and then Is_Aliased (E)
18943 and then Ekind (Scope (E)) = E_Function
18945 return Type_Access_Level (Etype (E));
18948 return Scope_Depth (Enclosing_Dynamic_Scope (E));
18952 elsif Nkind (Obj) = N_Selected_Component then
18953 if Is_Access_Type (Etype (Prefix (Obj))) then
18954 return Type_Access_Level (Etype (Prefix (Obj)));
18956 return Object_Access_Level (Prefix (Obj));
18959 elsif Nkind (Obj) = N_Indexed_Component then
18960 if Is_Access_Type (Etype (Prefix (Obj))) then
18961 return Type_Access_Level (Etype (Prefix (Obj)));
18963 return Object_Access_Level (Prefix (Obj));
18966 elsif Nkind (Obj) = N_Explicit_Dereference then
18968 -- If the prefix is a selected access discriminant then we make a
18969 -- recursive call on the prefix, which will in turn check the level
18970 -- of the prefix object of the selected discriminant.
18972 -- In Ada 2012, if the discriminant has implicit dereference and
18973 -- the context is a selected component, treat this as an object of
18974 -- unknown scope (see below). This is necessary in compile-only mode;
18975 -- otherwise expansion will already have transformed the prefix into
18978 if Nkind (Prefix (Obj)) = N_Selected_Component
18979 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
18981 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
18983 (not Has_Implicit_Dereference
18984 (Entity (Selector_Name (Prefix (Obj))))
18985 or else Nkind (Parent (Obj)) /= N_Selected_Component)
18987 return Object_Access_Level (Prefix (Obj));
18989 -- Detect an interface conversion in the context of a dispatching
18990 -- call. Use the original form of the conversion to find the access
18991 -- level of the operand.
18993 elsif Is_Interface (Etype (Obj))
18994 and then Is_Interface_Conversion (Prefix (Obj))
18995 and then Nkind (Original_Node (Obj)) = N_Type_Conversion
18997 return Object_Access_Level (Original_Node (Obj));
18999 elsif not Comes_From_Source (Obj) then
19001 Ref : constant Node_Id := Reference_To (Obj);
19003 if Present (Ref) then
19004 return Object_Access_Level (Ref);
19006 return Type_Access_Level (Etype (Prefix (Obj)));
19011 return Type_Access_Level (Etype (Prefix (Obj)));
19014 elsif Nkind_In (Obj, N_Type_Conversion, N_Unchecked_Type_Conversion) then
19015 return Object_Access_Level (Expression (Obj));
19017 elsif Nkind (Obj) = N_Function_Call then
19019 -- Function results are objects, so we get either the access level of
19020 -- the function or, in the case of an indirect call, the level of the
19021 -- access-to-subprogram type. (This code is used for Ada 95, but it
19022 -- looks wrong, because it seems that we should be checking the level
19023 -- of the call itself, even for Ada 95. However, using the Ada 2005
19024 -- version of the code causes regressions in several tests that are
19025 -- compiled with -gnat95. ???)
19027 if Ada_Version < Ada_2005 then
19028 if Is_Entity_Name (Name (Obj)) then
19029 return Subprogram_Access_Level (Entity (Name (Obj)));
19031 return Type_Access_Level (Etype (Prefix (Name (Obj))));
19034 -- For Ada 2005, the level of the result object of a function call is
19035 -- defined to be the level of the call's innermost enclosing master.
19036 -- We determine that by querying the depth of the innermost enclosing
19040 Return_Master_Scope_Depth_Of_Call : declare
19041 function Innermost_Master_Scope_Depth
19042 (N : Node_Id) return Uint;
19043 -- Returns the scope depth of the given node's innermost
19044 -- enclosing dynamic scope (effectively the accessibility
19045 -- level of the innermost enclosing master).
19047 ----------------------------------
19048 -- Innermost_Master_Scope_Depth --
19049 ----------------------------------
19051 function Innermost_Master_Scope_Depth
19052 (N : Node_Id) return Uint
19054 Node_Par : Node_Id := Parent (N);
19057 -- Locate the nearest enclosing node (by traversing Parents)
19058 -- that Defining_Entity can be applied to, and return the
19059 -- depth of that entity's nearest enclosing dynamic scope.
19061 while Present (Node_Par) loop
19062 case Nkind (Node_Par) is
19063 when N_Abstract_Subprogram_Declaration
19064 | N_Block_Statement
19066 | N_Component_Declaration
19068 | N_Entry_Declaration
19069 | N_Exception_Declaration
19070 | N_Formal_Object_Declaration
19071 | N_Formal_Package_Declaration
19072 | N_Formal_Subprogram_Declaration
19073 | N_Formal_Type_Declaration
19074 | N_Full_Type_Declaration
19075 | N_Function_Specification
19076 | N_Generic_Declaration
19077 | N_Generic_Instantiation
19078 | N_Implicit_Label_Declaration
19079 | N_Incomplete_Type_Declaration
19080 | N_Loop_Parameter_Specification
19081 | N_Number_Declaration
19082 | N_Object_Declaration
19083 | N_Package_Declaration
19084 | N_Package_Specification
19085 | N_Parameter_Specification
19086 | N_Private_Extension_Declaration
19087 | N_Private_Type_Declaration
19088 | N_Procedure_Specification
19090 | N_Protected_Type_Declaration
19091 | N_Renaming_Declaration
19092 | N_Single_Protected_Declaration
19093 | N_Single_Task_Declaration
19094 | N_Subprogram_Declaration
19095 | N_Subtype_Declaration
19097 | N_Task_Type_Declaration
19100 (Nearest_Dynamic_Scope
19101 (Defining_Entity (Node_Par)));
19107 Node_Par := Parent (Node_Par);
19110 pragma Assert (False);
19112 -- Should never reach the following return
19114 return Scope_Depth (Current_Scope) + 1;
19115 end Innermost_Master_Scope_Depth;
19117 -- Start of processing for Return_Master_Scope_Depth_Of_Call
19120 return Innermost_Master_Scope_Depth (Obj);
19121 end Return_Master_Scope_Depth_Of_Call;
19124 -- For convenience we handle qualified expressions, even though they
19125 -- aren't technically object names.
19127 elsif Nkind (Obj) = N_Qualified_Expression then
19128 return Object_Access_Level (Expression (Obj));
19130 -- Ditto for aggregates. They have the level of the temporary that
19131 -- will hold their value.
19133 elsif Nkind (Obj) = N_Aggregate then
19134 return Object_Access_Level (Current_Scope);
19136 -- Otherwise return the scope level of Standard. (If there are cases
19137 -- that fall through to this point they will be treated as having
19138 -- global accessibility for now. ???)
19141 return Scope_Depth (Standard_Standard);
19143 end Object_Access_Level;
19145 ----------------------------------
19146 -- Old_Requires_Transient_Scope --
19147 ----------------------------------
19149 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
19150 Typ : constant Entity_Id := Underlying_Type (Id);
19153 -- This is a private type which is not completed yet. This can only
19154 -- happen in a default expression (of a formal parameter or of a
19155 -- record component). Do not expand transient scope in this case.
19160 -- Do not expand transient scope for non-existent procedure return
19162 elsif Typ = Standard_Void_Type then
19165 -- Elementary types do not require a transient scope
19167 elsif Is_Elementary_Type (Typ) then
19170 -- Generally, indefinite subtypes require a transient scope, since the
19171 -- back end cannot generate temporaries, since this is not a valid type
19172 -- for declaring an object. It might be possible to relax this in the
19173 -- future, e.g. by declaring the maximum possible space for the type.
19175 elsif not Is_Definite_Subtype (Typ) then
19178 -- Functions returning tagged types may dispatch on result so their
19179 -- returned value is allocated on the secondary stack. Controlled
19180 -- type temporaries need finalization.
19182 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
19187 elsif Is_Record_Type (Typ) then
19192 Comp := First_Entity (Typ);
19193 while Present (Comp) loop
19194 if Ekind (Comp) = E_Component then
19196 -- ???It's not clear we need a full recursive call to
19197 -- Old_Requires_Transient_Scope here. Note that the
19198 -- following can't happen.
19200 pragma Assert (Is_Definite_Subtype (Etype (Comp)));
19201 pragma Assert (not Has_Controlled_Component (Etype (Comp)));
19203 if Old_Requires_Transient_Scope (Etype (Comp)) then
19208 Next_Entity (Comp);
19214 -- String literal types never require transient scope
19216 elsif Ekind (Typ) = E_String_Literal_Subtype then
19219 -- Array type. Note that we already know that this is a constrained
19220 -- array, since unconstrained arrays will fail the indefinite test.
19222 elsif Is_Array_Type (Typ) then
19224 -- If component type requires a transient scope, the array does too
19226 if Old_Requires_Transient_Scope (Component_Type (Typ)) then
19229 -- Otherwise, we only need a transient scope if the size depends on
19230 -- the value of one or more discriminants.
19233 return Size_Depends_On_Discriminant (Typ);
19236 -- All other cases do not require a transient scope
19239 pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
19242 end Old_Requires_Transient_Scope;
19244 ---------------------------------
19245 -- Original_Aspect_Pragma_Name --
19246 ---------------------------------
19248 function Original_Aspect_Pragma_Name (N : Node_Id) return Name_Id is
19250 Item_Nam : Name_Id;
19253 pragma Assert (Nkind_In (N, N_Aspect_Specification, N_Pragma));
19257 -- The pragma was generated to emulate an aspect, use the original
19258 -- aspect specification.
19260 if Nkind (Item) = N_Pragma and then From_Aspect_Specification (Item) then
19261 Item := Corresponding_Aspect (Item);
19264 -- Retrieve the name of the aspect/pragma. Note that Pre, Pre_Class,
19265 -- Post and Post_Class rewrite their pragma identifier to preserve the
19267 -- ??? this is kludgey
19269 if Nkind (Item) = N_Pragma then
19270 Item_Nam := Chars (Original_Node (Pragma_Identifier (Item)));
19273 pragma Assert (Nkind (Item) = N_Aspect_Specification);
19274 Item_Nam := Chars (Identifier (Item));
19277 -- Deal with 'Class by converting the name to its _XXX form
19279 if Class_Present (Item) then
19280 if Item_Nam = Name_Invariant then
19281 Item_Nam := Name_uInvariant;
19283 elsif Item_Nam = Name_Post then
19284 Item_Nam := Name_uPost;
19286 elsif Item_Nam = Name_Pre then
19287 Item_Nam := Name_uPre;
19289 elsif Nam_In (Item_Nam, Name_Type_Invariant,
19290 Name_Type_Invariant_Class)
19292 Item_Nam := Name_uType_Invariant;
19294 -- Nothing to do for other cases (e.g. a Check that derived from
19295 -- Pre_Class and has the flag set). Also we do nothing if the name
19296 -- is already in special _xxx form.
19302 end Original_Aspect_Pragma_Name;
19304 --------------------------------------
19305 -- Original_Corresponding_Operation --
19306 --------------------------------------
19308 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
19310 Typ : constant Entity_Id := Find_Dispatching_Type (S);
19313 -- If S is an inherited primitive S2 the original corresponding
19314 -- operation of S is the original corresponding operation of S2
19316 if Present (Alias (S))
19317 and then Find_Dispatching_Type (Alias (S)) /= Typ
19319 return Original_Corresponding_Operation (Alias (S));
19321 -- If S overrides an inherited subprogram S2 the original corresponding
19322 -- operation of S is the original corresponding operation of S2
19324 elsif Present (Overridden_Operation (S)) then
19325 return Original_Corresponding_Operation (Overridden_Operation (S));
19327 -- otherwise it is S itself
19332 end Original_Corresponding_Operation;
19334 -------------------
19335 -- Output_Entity --
19336 -------------------
19338 procedure Output_Entity (Id : Entity_Id) is
19342 Scop := Scope (Id);
19344 -- The entity may lack a scope when it is in the process of being
19345 -- analyzed. Use the current scope as an approximation.
19348 Scop := Current_Scope;
19351 Output_Name (Chars (Id), Scop);
19358 procedure Output_Name (Nam : Name_Id; Scop : Entity_Id := Current_Scope) is
19362 (Get_Qualified_Name
19369 ----------------------
19370 -- Policy_In_Effect --
19371 ----------------------
19373 function Policy_In_Effect (Policy : Name_Id) return Name_Id is
19374 function Policy_In_List (List : Node_Id) return Name_Id;
19375 -- Determine the mode of a policy in a N_Pragma list
19377 --------------------
19378 -- Policy_In_List --
19379 --------------------
19381 function Policy_In_List (List : Node_Id) return Name_Id is
19388 while Present (Prag) loop
19389 Arg1 := First (Pragma_Argument_Associations (Prag));
19390 Arg2 := Next (Arg1);
19392 Arg1 := Get_Pragma_Arg (Arg1);
19393 Arg2 := Get_Pragma_Arg (Arg2);
19395 -- The current Check_Policy pragma matches the requested policy or
19396 -- appears in the single argument form (Assertion, policy_id).
19398 if Nam_In (Chars (Arg1), Name_Assertion, Policy) then
19399 return Chars (Arg2);
19402 Prag := Next_Pragma (Prag);
19406 end Policy_In_List;
19412 -- Start of processing for Policy_In_Effect
19415 if not Is_Valid_Assertion_Kind (Policy) then
19416 raise Program_Error;
19419 -- Inspect all policy pragmas that appear within scopes (if any)
19421 Kind := Policy_In_List (Check_Policy_List);
19423 -- Inspect all configuration policy pragmas (if any)
19425 if Kind = No_Name then
19426 Kind := Policy_In_List (Check_Policy_List_Config);
19429 -- The context lacks policy pragmas, determine the mode based on whether
19430 -- assertions are enabled at the configuration level. This ensures that
19431 -- the policy is preserved when analyzing generics.
19433 if Kind = No_Name then
19434 if Assertions_Enabled_Config then
19435 Kind := Name_Check;
19437 Kind := Name_Ignore;
19442 end Policy_In_Effect;
19444 ----------------------------------
19445 -- Predicate_Tests_On_Arguments --
19446 ----------------------------------
19448 function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean is
19450 -- Always test predicates on indirect call
19452 if Ekind (Subp) = E_Subprogram_Type then
19455 -- Do not test predicates on call to generated default Finalize, since
19456 -- we are not interested in whether something we are finalizing (and
19457 -- typically destroying) satisfies its predicates.
19459 elsif Chars (Subp) = Name_Finalize
19460 and then not Comes_From_Source (Subp)
19464 -- Do not test predicates on any internally generated routines
19466 elsif Is_Internal_Name (Chars (Subp)) then
19469 -- Do not test predicates on call to Init_Proc, since if needed the
19470 -- predicate test will occur at some other point.
19472 elsif Is_Init_Proc (Subp) then
19475 -- Do not test predicates on call to predicate function, since this
19476 -- would cause infinite recursion.
19478 elsif Ekind (Subp) = E_Function
19479 and then (Is_Predicate_Function (Subp)
19481 Is_Predicate_Function_M (Subp))
19485 -- For now, no other exceptions
19490 end Predicate_Tests_On_Arguments;
19492 -----------------------
19493 -- Private_Component --
19494 -----------------------
19496 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
19497 Ancestor : constant Entity_Id := Base_Type (Type_Id);
19499 function Trace_Components
19501 Check : Boolean) return Entity_Id;
19502 -- Recursive function that does the work, and checks against circular
19503 -- definition for each subcomponent type.
19505 ----------------------
19506 -- Trace_Components --
19507 ----------------------
19509 function Trace_Components
19511 Check : Boolean) return Entity_Id
19513 Btype : constant Entity_Id := Base_Type (T);
19514 Component : Entity_Id;
19516 Candidate : Entity_Id := Empty;
19519 if Check and then Btype = Ancestor then
19520 Error_Msg_N ("circular type definition", Type_Id);
19524 if Is_Private_Type (Btype) and then not Is_Generic_Type (Btype) then
19525 if Present (Full_View (Btype))
19526 and then Is_Record_Type (Full_View (Btype))
19527 and then not Is_Frozen (Btype)
19529 -- To indicate that the ancestor depends on a private type, the
19530 -- current Btype is sufficient. However, to check for circular
19531 -- definition we must recurse on the full view.
19533 Candidate := Trace_Components (Full_View (Btype), True);
19535 if Candidate = Any_Type then
19545 elsif Is_Array_Type (Btype) then
19546 return Trace_Components (Component_Type (Btype), True);
19548 elsif Is_Record_Type (Btype) then
19549 Component := First_Entity (Btype);
19550 while Present (Component)
19551 and then Comes_From_Source (Component)
19553 -- Skip anonymous types generated by constrained components
19555 if not Is_Type (Component) then
19556 P := Trace_Components (Etype (Component), True);
19558 if Present (P) then
19559 if P = Any_Type then
19567 Next_Entity (Component);
19575 end Trace_Components;
19577 -- Start of processing for Private_Component
19580 return Trace_Components (Type_Id, False);
19581 end Private_Component;
19583 ---------------------------
19584 -- Primitive_Names_Match --
19585 ---------------------------
19587 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
19588 function Non_Internal_Name (E : Entity_Id) return Name_Id;
19589 -- Given an internal name, returns the corresponding non-internal name
19591 ------------------------
19592 -- Non_Internal_Name --
19593 ------------------------
19595 function Non_Internal_Name (E : Entity_Id) return Name_Id is
19597 Get_Name_String (Chars (E));
19598 Name_Len := Name_Len - 1;
19600 end Non_Internal_Name;
19602 -- Start of processing for Primitive_Names_Match
19605 pragma Assert (Present (E1) and then Present (E2));
19607 return Chars (E1) = Chars (E2)
19609 (not Is_Internal_Name (Chars (E1))
19610 and then Is_Internal_Name (Chars (E2))
19611 and then Non_Internal_Name (E2) = Chars (E1))
19613 (not Is_Internal_Name (Chars (E2))
19614 and then Is_Internal_Name (Chars (E1))
19615 and then Non_Internal_Name (E1) = Chars (E2))
19617 (Is_Predefined_Dispatching_Operation (E1)
19618 and then Is_Predefined_Dispatching_Operation (E2)
19619 and then Same_TSS (E1, E2))
19621 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
19622 end Primitive_Names_Match;
19624 -----------------------
19625 -- Process_End_Label --
19626 -----------------------
19628 procedure Process_End_Label
19637 Label_Ref : Boolean;
19638 -- Set True if reference to end label itself is required
19641 -- Gets set to the operator symbol or identifier that references the
19642 -- entity Ent. For the child unit case, this is the identifier from the
19643 -- designator. For other cases, this is simply Endl.
19645 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
19646 -- N is an identifier node that appears as a parent unit reference in
19647 -- the case where Ent is a child unit. This procedure generates an
19648 -- appropriate cross-reference entry. E is the corresponding entity.
19650 -------------------------
19651 -- Generate_Parent_Ref --
19652 -------------------------
19654 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
19656 -- If names do not match, something weird, skip reference
19658 if Chars (E) = Chars (N) then
19660 -- Generate the reference. We do NOT consider this as a reference
19661 -- for unreferenced symbol purposes.
19663 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
19665 if Style_Check then
19666 Style.Check_Identifier (N, E);
19669 end Generate_Parent_Ref;
19671 -- Start of processing for Process_End_Label
19674 -- If no node, ignore. This happens in some error situations, and
19675 -- also for some internally generated structures where no end label
19676 -- references are required in any case.
19682 -- Nothing to do if no End_Label, happens for internally generated
19683 -- constructs where we don't want an end label reference anyway. Also
19684 -- nothing to do if Endl is a string literal, which means there was
19685 -- some prior error (bad operator symbol)
19687 Endl := End_Label (N);
19689 if No (Endl) or else Nkind (Endl) = N_String_Literal then
19693 -- Reference node is not in extended main source unit
19695 if not In_Extended_Main_Source_Unit (N) then
19697 -- Generally we do not collect references except for the extended
19698 -- main source unit. The one exception is the 'e' entry for a
19699 -- package spec, where it is useful for a client to have the
19700 -- ending information to define scopes.
19706 Label_Ref := False;
19708 -- For this case, we can ignore any parent references, but we
19709 -- need the package name itself for the 'e' entry.
19711 if Nkind (Endl) = N_Designator then
19712 Endl := Identifier (Endl);
19716 -- Reference is in extended main source unit
19721 -- For designator, generate references for the parent entries
19723 if Nkind (Endl) = N_Designator then
19725 -- Generate references for the prefix if the END line comes from
19726 -- source (otherwise we do not need these references) We climb the
19727 -- scope stack to find the expected entities.
19729 if Comes_From_Source (Endl) then
19730 Nam := Name (Endl);
19731 Scop := Current_Scope;
19732 while Nkind (Nam) = N_Selected_Component loop
19733 Scop := Scope (Scop);
19734 exit when No (Scop);
19735 Generate_Parent_Ref (Selector_Name (Nam), Scop);
19736 Nam := Prefix (Nam);
19739 if Present (Scop) then
19740 Generate_Parent_Ref (Nam, Scope (Scop));
19744 Endl := Identifier (Endl);
19748 -- If the end label is not for the given entity, then either we have
19749 -- some previous error, or this is a generic instantiation for which
19750 -- we do not need to make a cross-reference in this case anyway. In
19751 -- either case we simply ignore the call.
19753 if Chars (Ent) /= Chars (Endl) then
19757 -- If label was really there, then generate a normal reference and then
19758 -- adjust the location in the end label to point past the name (which
19759 -- should almost always be the semicolon).
19761 Loc := Sloc (Endl);
19763 if Comes_From_Source (Endl) then
19765 -- If a label reference is required, then do the style check and
19766 -- generate an l-type cross-reference entry for the label
19769 if Style_Check then
19770 Style.Check_Identifier (Endl, Ent);
19773 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
19776 -- Set the location to point past the label (normally this will
19777 -- mean the semicolon immediately following the label). This is
19778 -- done for the sake of the 'e' or 't' entry generated below.
19780 Get_Decoded_Name_String (Chars (Endl));
19781 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
19784 -- In SPARK mode, no missing label is allowed for packages and
19785 -- subprogram bodies. Detect those cases by testing whether
19786 -- Process_End_Label was called for a body (Typ = 't') or a package.
19788 if Restriction_Check_Required (SPARK_05)
19789 and then (Typ = 't' or else Ekind (Ent) = E_Package)
19791 Error_Msg_Node_1 := Endl;
19792 Check_SPARK_05_Restriction
19793 ("`END &` required", Endl, Force => True);
19797 -- Now generate the e/t reference
19799 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
19801 -- Restore Sloc, in case modified above, since we have an identifier
19802 -- and the normal Sloc should be left set in the tree.
19804 Set_Sloc (Endl, Loc);
19805 end Process_End_Label;
19807 --------------------------------
19808 -- Propagate_Concurrent_Flags --
19809 --------------------------------
19811 procedure Propagate_Concurrent_Flags
19813 Comp_Typ : Entity_Id)
19816 if Has_Task (Comp_Typ) then
19817 Set_Has_Task (Typ);
19820 if Has_Protected (Comp_Typ) then
19821 Set_Has_Protected (Typ);
19824 if Has_Timing_Event (Comp_Typ) then
19825 Set_Has_Timing_Event (Typ);
19827 end Propagate_Concurrent_Flags;
19829 ------------------------------
19830 -- Propagate_DIC_Attributes --
19831 ------------------------------
19833 procedure Propagate_DIC_Attributes
19835 From_Typ : Entity_Id)
19837 DIC_Proc : Entity_Id;
19840 if Present (Typ) and then Present (From_Typ) then
19841 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
19843 -- Nothing to do if both the source and the destination denote the
19846 if From_Typ = Typ then
19850 DIC_Proc := DIC_Procedure (From_Typ);
19852 -- The setting of the attributes is intentionally conservative. This
19853 -- prevents accidental clobbering of enabled attributes.
19855 if Has_Inherited_DIC (From_Typ)
19856 and then not Has_Inherited_DIC (Typ)
19858 Set_Has_Inherited_DIC (Typ);
19861 if Has_Own_DIC (From_Typ) and then not Has_Own_DIC (Typ) then
19862 Set_Has_Own_DIC (Typ);
19865 if Present (DIC_Proc) and then No (DIC_Procedure (Typ)) then
19866 Set_DIC_Procedure (Typ, DIC_Proc);
19869 end Propagate_DIC_Attributes;
19871 ------------------------------------
19872 -- Propagate_Invariant_Attributes --
19873 ------------------------------------
19875 procedure Propagate_Invariant_Attributes
19877 From_Typ : Entity_Id)
19879 Full_IP : Entity_Id;
19880 Part_IP : Entity_Id;
19883 if Present (Typ) and then Present (From_Typ) then
19884 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
19886 -- Nothing to do if both the source and the destination denote the
19889 if From_Typ = Typ then
19893 Full_IP := Invariant_Procedure (From_Typ);
19894 Part_IP := Partial_Invariant_Procedure (From_Typ);
19896 -- The setting of the attributes is intentionally conservative. This
19897 -- prevents accidental clobbering of enabled attributes.
19899 if Has_Inheritable_Invariants (From_Typ)
19900 and then not Has_Inheritable_Invariants (Typ)
19902 Set_Has_Inheritable_Invariants (Typ, True);
19905 if Has_Inherited_Invariants (From_Typ)
19906 and then not Has_Inherited_Invariants (Typ)
19908 Set_Has_Inherited_Invariants (Typ, True);
19911 if Has_Own_Invariants (From_Typ)
19912 and then not Has_Own_Invariants (Typ)
19914 Set_Has_Own_Invariants (Typ, True);
19917 if Present (Full_IP) and then No (Invariant_Procedure (Typ)) then
19918 Set_Invariant_Procedure (Typ, Full_IP);
19921 if Present (Part_IP) and then No (Partial_Invariant_Procedure (Typ))
19923 Set_Partial_Invariant_Procedure (Typ, Part_IP);
19926 end Propagate_Invariant_Attributes;
19928 ---------------------------------------
19929 -- Record_Possible_Part_Of_Reference --
19930 ---------------------------------------
19932 procedure Record_Possible_Part_Of_Reference
19933 (Var_Id : Entity_Id;
19936 Encap : constant Entity_Id := Encapsulating_State (Var_Id);
19940 -- The variable is a constituent of a single protected/task type. Such
19941 -- a variable acts as a component of the type and must appear within a
19942 -- specific region (SPARK RM 9.3). Instead of recording the reference,
19943 -- verify its legality now.
19945 if Present (Encap) and then Is_Single_Concurrent_Object (Encap) then
19946 Check_Part_Of_Reference (Var_Id, Ref);
19948 -- The variable is subject to pragma Part_Of and may eventually become a
19949 -- constituent of a single protected/task type. Record the reference to
19950 -- verify its placement when the contract of the variable is analyzed.
19952 elsif Present (Get_Pragma (Var_Id, Pragma_Part_Of)) then
19953 Refs := Part_Of_References (Var_Id);
19956 Refs := New_Elmt_List;
19957 Set_Part_Of_References (Var_Id, Refs);
19960 Append_Elmt (Ref, Refs);
19962 end Record_Possible_Part_Of_Reference;
19968 function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
19969 Seen : Boolean := False;
19971 function Is_Reference (N : Node_Id) return Traverse_Result;
19972 -- Determine whether node N denotes a reference to Id. If this is the
19973 -- case, set global flag Seen to True and stop the traversal.
19979 function Is_Reference (N : Node_Id) return Traverse_Result is
19981 if Is_Entity_Name (N)
19982 and then Present (Entity (N))
19983 and then Entity (N) = Id
19992 procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
19994 -- Start of processing for Referenced
19997 Inspect_Expression (Expr);
20001 ------------------------------------
20002 -- References_Generic_Formal_Type --
20003 ------------------------------------
20005 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
20007 function Process (N : Node_Id) return Traverse_Result;
20008 -- Process one node in search for generic formal type
20014 function Process (N : Node_Id) return Traverse_Result is
20016 if Nkind (N) in N_Has_Entity then
20018 E : constant Entity_Id := Entity (N);
20020 if Present (E) then
20021 if Is_Generic_Type (E) then
20023 elsif Present (Etype (E))
20024 and then Is_Generic_Type (Etype (E))
20035 function Traverse is new Traverse_Func (Process);
20036 -- Traverse tree to look for generic type
20039 if Inside_A_Generic then
20040 return Traverse (N) = Abandon;
20044 end References_Generic_Formal_Type;
20046 --------------------
20047 -- Remove_Homonym --
20048 --------------------
20050 procedure Remove_Homonym (E : Entity_Id) is
20051 Prev : Entity_Id := Empty;
20055 if E = Current_Entity (E) then
20056 if Present (Homonym (E)) then
20057 Set_Current_Entity (Homonym (E));
20059 Set_Name_Entity_Id (Chars (E), Empty);
20063 H := Current_Entity (E);
20064 while Present (H) and then H /= E loop
20069 -- If E is not on the homonym chain, nothing to do
20071 if Present (H) then
20072 Set_Homonym (Prev, Homonym (E));
20075 end Remove_Homonym;
20077 ------------------------------
20078 -- Remove_Overloaded_Entity --
20079 ------------------------------
20081 procedure Remove_Overloaded_Entity (Id : Entity_Id) is
20082 procedure Remove_Primitive_Of (Typ : Entity_Id);
20083 -- Remove primitive subprogram Id from the list of primitives that
20084 -- belong to type Typ.
20086 -------------------------
20087 -- Remove_Primitive_Of --
20088 -------------------------
20090 procedure Remove_Primitive_Of (Typ : Entity_Id) is
20094 if Is_Tagged_Type (Typ) then
20095 Prims := Direct_Primitive_Operations (Typ);
20097 if Present (Prims) then
20098 Remove (Prims, Id);
20101 end Remove_Primitive_Of;
20105 Scop : constant Entity_Id := Scope (Id);
20106 Formal : Entity_Id;
20107 Prev_Id : Entity_Id;
20109 -- Start of processing for Remove_Overloaded_Entity
20112 -- Remove the entity from the homonym chain. When the entity is the
20113 -- head of the chain, associate the entry in the name table with its
20114 -- homonym effectively making it the new head of the chain.
20116 if Current_Entity (Id) = Id then
20117 Set_Name_Entity_Id (Chars (Id), Homonym (Id));
20119 -- Otherwise link the previous and next homonyms
20122 Prev_Id := Current_Entity (Id);
20123 while Present (Prev_Id) and then Homonym (Prev_Id) /= Id loop
20124 Prev_Id := Homonym (Prev_Id);
20127 Set_Homonym (Prev_Id, Homonym (Id));
20130 -- Remove the entity from the scope entity chain. When the entity is
20131 -- the head of the chain, set the next entity as the new head of the
20134 if First_Entity (Scop) = Id then
20136 Set_First_Entity (Scop, Next_Entity (Id));
20138 -- Otherwise the entity is either in the middle of the chain or it acts
20139 -- as its tail. Traverse and link the previous and next entities.
20142 Prev_Id := First_Entity (Scop);
20143 while Present (Prev_Id) and then Next_Entity (Prev_Id) /= Id loop
20144 Next_Entity (Prev_Id);
20147 Set_Next_Entity (Prev_Id, Next_Entity (Id));
20150 -- Handle the case where the entity acts as the tail of the scope entity
20153 if Last_Entity (Scop) = Id then
20154 Set_Last_Entity (Scop, Prev_Id);
20157 -- The entity denotes a primitive subprogram. Remove it from the list of
20158 -- primitives of the associated controlling type.
20160 if Ekind_In (Id, E_Function, E_Procedure) and then Is_Primitive (Id) then
20161 Formal := First_Formal (Id);
20162 while Present (Formal) loop
20163 if Is_Controlling_Formal (Formal) then
20164 Remove_Primitive_Of (Etype (Formal));
20168 Next_Formal (Formal);
20171 if Ekind (Id) = E_Function and then Has_Controlling_Result (Id) then
20172 Remove_Primitive_Of (Etype (Id));
20175 end Remove_Overloaded_Entity;
20177 ---------------------
20178 -- Rep_To_Pos_Flag --
20179 ---------------------
20181 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
20183 return New_Occurrence_Of
20184 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
20185 end Rep_To_Pos_Flag;
20187 --------------------
20188 -- Require_Entity --
20189 --------------------
20191 procedure Require_Entity (N : Node_Id) is
20193 if Is_Entity_Name (N) and then No (Entity (N)) then
20194 if Total_Errors_Detected /= 0 then
20195 Set_Entity (N, Any_Id);
20197 raise Program_Error;
20200 end Require_Entity;
20202 ------------------------------
20203 -- Requires_Transient_Scope --
20204 ------------------------------
20206 -- A transient scope is required when variable-sized temporaries are
20207 -- allocated on the secondary stack, or when finalization actions must be
20208 -- generated before the next instruction.
20210 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
20211 Old_Result : constant Boolean := Old_Requires_Transient_Scope (Id);
20214 if Debug_Flag_QQ then
20219 New_Result : constant Boolean := New_Requires_Transient_Scope (Id);
20222 -- Assert that we're not putting things on the secondary stack if we
20223 -- didn't before; we are trying to AVOID secondary stack when
20226 if not Old_Result then
20227 pragma Assert (not New_Result);
20231 if New_Result /= Old_Result then
20232 Results_Differ (Id, Old_Result, New_Result);
20237 end Requires_Transient_Scope;
20239 --------------------
20240 -- Results_Differ --
20241 --------------------
20243 procedure Results_Differ
20249 if False then -- False to disable; True for debugging
20250 Treepr.Print_Tree_Node (Id);
20252 if Old_Val = New_Val then
20253 raise Program_Error;
20256 end Results_Differ;
20258 --------------------------
20259 -- Reset_Analyzed_Flags --
20260 --------------------------
20262 procedure Reset_Analyzed_Flags (N : Node_Id) is
20263 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
20264 -- Function used to reset Analyzed flags in tree. Note that we do
20265 -- not reset Analyzed flags in entities, since there is no need to
20266 -- reanalyze entities, and indeed, it is wrong to do so, since it
20267 -- can result in generating auxiliary stuff more than once.
20269 --------------------
20270 -- Clear_Analyzed --
20271 --------------------
20273 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
20275 if Nkind (N) not in N_Entity then
20276 Set_Analyzed (N, False);
20280 end Clear_Analyzed;
20282 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
20284 -- Start of processing for Reset_Analyzed_Flags
20287 Reset_Analyzed (N);
20288 end Reset_Analyzed_Flags;
20290 ------------------------
20291 -- Restore_SPARK_Mode --
20292 ------------------------
20294 procedure Restore_SPARK_Mode
20295 (Mode : SPARK_Mode_Type;
20299 SPARK_Mode := Mode;
20300 SPARK_Mode_Pragma := Prag;
20301 end Restore_SPARK_Mode;
20303 --------------------------------
20304 -- Returns_Unconstrained_Type --
20305 --------------------------------
20307 function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
20309 return Ekind (Subp) = E_Function
20310 and then not Is_Scalar_Type (Etype (Subp))
20311 and then not Is_Access_Type (Etype (Subp))
20312 and then not Is_Constrained (Etype (Subp));
20313 end Returns_Unconstrained_Type;
20315 ----------------------------
20316 -- Root_Type_Of_Full_View --
20317 ----------------------------
20319 function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id is
20320 Rtyp : constant Entity_Id := Root_Type (T);
20323 -- The root type of the full view may itself be a private type. Keep
20324 -- looking for the ultimate derivation parent.
20326 if Is_Private_Type (Rtyp) and then Present (Full_View (Rtyp)) then
20327 return Root_Type_Of_Full_View (Full_View (Rtyp));
20331 end Root_Type_Of_Full_View;
20333 ---------------------------
20334 -- Safe_To_Capture_Value --
20335 ---------------------------
20337 function Safe_To_Capture_Value
20340 Cond : Boolean := False) return Boolean
20343 -- The only entities for which we track constant values are variables
20344 -- which are not renamings, constants, out parameters, and in out
20345 -- parameters, so check if we have this case.
20347 -- Note: it may seem odd to track constant values for constants, but in
20348 -- fact this routine is used for other purposes than simply capturing
20349 -- the value. In particular, the setting of Known[_Non]_Null.
20351 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
20353 Ekind_In (Ent, E_Constant, E_Out_Parameter, E_In_Out_Parameter)
20357 -- For conditionals, we also allow loop parameters and all formals,
20358 -- including in parameters.
20360 elsif Cond and then Ekind_In (Ent, E_Loop_Parameter, E_In_Parameter) then
20363 -- For all other cases, not just unsafe, but impossible to capture
20364 -- Current_Value, since the above are the only entities which have
20365 -- Current_Value fields.
20371 -- Skip if volatile or aliased, since funny things might be going on in
20372 -- these cases which we cannot necessarily track. Also skip any variable
20373 -- for which an address clause is given, or whose address is taken. Also
20374 -- never capture value of library level variables (an attempt to do so
20375 -- can occur in the case of package elaboration code).
20377 if Treat_As_Volatile (Ent)
20378 or else Is_Aliased (Ent)
20379 or else Present (Address_Clause (Ent))
20380 or else Address_Taken (Ent)
20381 or else (Is_Library_Level_Entity (Ent)
20382 and then Ekind (Ent) = E_Variable)
20387 -- OK, all above conditions are met. We also require that the scope of
20388 -- the reference be the same as the scope of the entity, not counting
20389 -- packages and blocks and loops.
20392 E_Scope : constant Entity_Id := Scope (Ent);
20393 R_Scope : Entity_Id;
20396 R_Scope := Current_Scope;
20397 while R_Scope /= Standard_Standard loop
20398 exit when R_Scope = E_Scope;
20400 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
20403 R_Scope := Scope (R_Scope);
20408 -- We also require that the reference does not appear in a context
20409 -- where it is not sure to be executed (i.e. a conditional context
20410 -- or an exception handler). We skip this if Cond is True, since the
20411 -- capturing of values from conditional tests handles this ok.
20424 -- Seems dubious that case expressions are not handled here ???
20427 while Present (P) loop
20428 if Nkind (P) = N_If_Statement
20429 or else Nkind (P) = N_Case_Statement
20430 or else (Nkind (P) in N_Short_Circuit
20431 and then Desc = Right_Opnd (P))
20432 or else (Nkind (P) = N_If_Expression
20433 and then Desc /= First (Expressions (P)))
20434 or else Nkind (P) = N_Exception_Handler
20435 or else Nkind (P) = N_Selective_Accept
20436 or else Nkind (P) = N_Conditional_Entry_Call
20437 or else Nkind (P) = N_Timed_Entry_Call
20438 or else Nkind (P) = N_Asynchronous_Select
20446 -- A special Ada 2012 case: the original node may be part
20447 -- of the else_actions of a conditional expression, in which
20448 -- case it might not have been expanded yet, and appears in
20449 -- a non-syntactic list of actions. In that case it is clearly
20450 -- not safe to save a value.
20453 and then Is_List_Member (Desc)
20454 and then No (Parent (List_Containing (Desc)))
20462 -- OK, looks safe to set value
20465 end Safe_To_Capture_Value;
20471 function Same_Name (N1, N2 : Node_Id) return Boolean is
20472 K1 : constant Node_Kind := Nkind (N1);
20473 K2 : constant Node_Kind := Nkind (N2);
20476 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
20477 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
20479 return Chars (N1) = Chars (N2);
20481 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
20482 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
20484 return Same_Name (Selector_Name (N1), Selector_Name (N2))
20485 and then Same_Name (Prefix (N1), Prefix (N2));
20496 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
20497 N1 : constant Node_Id := Original_Node (Node1);
20498 N2 : constant Node_Id := Original_Node (Node2);
20499 -- We do the tests on original nodes, since we are most interested
20500 -- in the original source, not any expansion that got in the way.
20502 K1 : constant Node_Kind := Nkind (N1);
20503 K2 : constant Node_Kind := Nkind (N2);
20506 -- First case, both are entities with same entity
20508 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
20510 EN1 : constant Entity_Id := Entity (N1);
20511 EN2 : constant Entity_Id := Entity (N2);
20513 if Present (EN1) and then Present (EN2)
20514 and then (Ekind_In (EN1, E_Variable, E_Constant)
20515 or else Is_Formal (EN1))
20523 -- Second case, selected component with same selector, same record
20525 if K1 = N_Selected_Component
20526 and then K2 = N_Selected_Component
20527 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
20529 return Same_Object (Prefix (N1), Prefix (N2));
20531 -- Third case, indexed component with same subscripts, same array
20533 elsif K1 = N_Indexed_Component
20534 and then K2 = N_Indexed_Component
20535 and then Same_Object (Prefix (N1), Prefix (N2))
20540 E1 := First (Expressions (N1));
20541 E2 := First (Expressions (N2));
20542 while Present (E1) loop
20543 if not Same_Value (E1, E2) then
20554 -- Fourth case, slice of same array with same bounds
20557 and then K2 = N_Slice
20558 and then Nkind (Discrete_Range (N1)) = N_Range
20559 and then Nkind (Discrete_Range (N2)) = N_Range
20560 and then Same_Value (Low_Bound (Discrete_Range (N1)),
20561 Low_Bound (Discrete_Range (N2)))
20562 and then Same_Value (High_Bound (Discrete_Range (N1)),
20563 High_Bound (Discrete_Range (N2)))
20565 return Same_Name (Prefix (N1), Prefix (N2));
20567 -- All other cases, not clearly the same object
20578 function Same_Type (T1, T2 : Entity_Id) return Boolean is
20583 elsif not Is_Constrained (T1)
20584 and then not Is_Constrained (T2)
20585 and then Base_Type (T1) = Base_Type (T2)
20589 -- For now don't bother with case of identical constraints, to be
20590 -- fiddled with later on perhaps (this is only used for optimization
20591 -- purposes, so it is not critical to do a best possible job)
20602 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
20604 if Compile_Time_Known_Value (Node1)
20605 and then Compile_Time_Known_Value (Node2)
20607 -- Handle properly compile-time expressions that are not
20610 if Is_String_Type (Etype (Node1)) then
20611 return Expr_Value_S (Node1) = Expr_Value_S (Node2);
20614 return Expr_Value (Node1) = Expr_Value (Node2);
20617 elsif Same_Object (Node1, Node2) then
20624 --------------------
20625 -- Set_SPARK_Mode --
20626 --------------------
20628 procedure Set_SPARK_Mode (Context : Entity_Id) is
20630 -- Do not consider illegal or partially decorated constructs
20632 if Ekind (Context) = E_Void or else Error_Posted (Context) then
20635 elsif Present (SPARK_Pragma (Context)) then
20637 (Mode => Get_SPARK_Mode_From_Annotation (SPARK_Pragma (Context)),
20638 Prag => SPARK_Pragma (Context));
20640 end Set_SPARK_Mode;
20642 -------------------------
20643 -- Scalar_Part_Present --
20644 -------------------------
20646 function Scalar_Part_Present (T : Entity_Id) return Boolean is
20650 if Is_Scalar_Type (T) then
20653 elsif Is_Array_Type (T) then
20654 return Scalar_Part_Present (Component_Type (T));
20656 elsif Is_Record_Type (T) or else Has_Discriminants (T) then
20657 C := First_Component_Or_Discriminant (T);
20658 while Present (C) loop
20659 if Scalar_Part_Present (Etype (C)) then
20662 Next_Component_Or_Discriminant (C);
20668 end Scalar_Part_Present;
20670 ------------------------
20671 -- Scope_Is_Transient --
20672 ------------------------
20674 function Scope_Is_Transient return Boolean is
20676 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
20677 end Scope_Is_Transient;
20683 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
20688 while Scop /= Standard_Standard loop
20689 Scop := Scope (Scop);
20691 if Scop = Scope2 then
20699 --------------------------
20700 -- Scope_Within_Or_Same --
20701 --------------------------
20703 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
20708 while Scop /= Standard_Standard loop
20709 if Scop = Scope2 then
20712 Scop := Scope (Scop);
20717 end Scope_Within_Or_Same;
20719 --------------------
20720 -- Set_Convention --
20721 --------------------
20723 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
20725 Basic_Set_Convention (E, Val);
20728 and then Is_Access_Subprogram_Type (Base_Type (E))
20729 and then Has_Foreign_Convention (E)
20732 -- A pragma Convention in an instance may apply to the subtype
20733 -- created for a formal, in which case we have already verified
20734 -- that conventions of actual and formal match and there is nothing
20735 -- to flag on the subtype.
20737 if In_Instance then
20740 Set_Can_Use_Internal_Rep (E, False);
20744 -- If E is an object or component, and the type of E is an anonymous
20745 -- access type with no convention set, then also set the convention of
20746 -- the anonymous access type. We do not do this for anonymous protected
20747 -- types, since protected types always have the default convention.
20749 if Present (Etype (E))
20750 and then (Is_Object (E)
20751 or else Ekind (E) = E_Component
20753 -- Allow E_Void (happens for pragma Convention appearing
20754 -- in the middle of a record applying to a component)
20756 or else Ekind (E) = E_Void)
20759 Typ : constant Entity_Id := Etype (E);
20762 if Ekind_In (Typ, E_Anonymous_Access_Type,
20763 E_Anonymous_Access_Subprogram_Type)
20764 and then not Has_Convention_Pragma (Typ)
20766 Basic_Set_Convention (Typ, Val);
20767 Set_Has_Convention_Pragma (Typ);
20769 -- And for the access subprogram type, deal similarly with the
20770 -- designated E_Subprogram_Type if it is also internal (which
20773 if Ekind (Typ) = E_Anonymous_Access_Subprogram_Type then
20775 Dtype : constant Entity_Id := Designated_Type (Typ);
20777 if Ekind (Dtype) = E_Subprogram_Type
20778 and then Is_Itype (Dtype)
20779 and then not Has_Convention_Pragma (Dtype)
20781 Basic_Set_Convention (Dtype, Val);
20782 Set_Has_Convention_Pragma (Dtype);
20789 end Set_Convention;
20791 ------------------------
20792 -- Set_Current_Entity --
20793 ------------------------
20795 -- The given entity is to be set as the currently visible definition of its
20796 -- associated name (i.e. the Node_Id associated with its name). All we have
20797 -- to do is to get the name from the identifier, and then set the
20798 -- associated Node_Id to point to the given entity.
20800 procedure Set_Current_Entity (E : Entity_Id) is
20802 Set_Name_Entity_Id (Chars (E), E);
20803 end Set_Current_Entity;
20805 ---------------------------
20806 -- Set_Debug_Info_Needed --
20807 ---------------------------
20809 procedure Set_Debug_Info_Needed (T : Entity_Id) is
20811 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
20812 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
20813 -- Used to set debug info in a related node if not set already
20815 --------------------------------------
20816 -- Set_Debug_Info_Needed_If_Not_Set --
20817 --------------------------------------
20819 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
20821 if Present (E) and then not Needs_Debug_Info (E) then
20822 Set_Debug_Info_Needed (E);
20824 -- For a private type, indicate that the full view also needs
20825 -- debug information.
20828 and then Is_Private_Type (E)
20829 and then Present (Full_View (E))
20831 Set_Debug_Info_Needed (Full_View (E));
20834 end Set_Debug_Info_Needed_If_Not_Set;
20836 -- Start of processing for Set_Debug_Info_Needed
20839 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
20840 -- indicates that Debug_Info_Needed is never required for the entity.
20841 -- Nothing to do if entity comes from a predefined file. Library files
20842 -- are compiled without debug information, but inlined bodies of these
20843 -- routines may appear in user code, and debug information on them ends
20844 -- up complicating debugging the user code.
20847 or else Debug_Info_Off (T)
20851 elsif In_Inlined_Body
20852 and then Is_Predefined_File_Name
20853 (Unit_File_Name (Get_Source_Unit (Sloc (T))))
20855 Set_Needs_Debug_Info (T, False);
20858 -- Set flag in entity itself. Note that we will go through the following
20859 -- circuitry even if the flag is already set on T. That's intentional,
20860 -- it makes sure that the flag will be set in subsidiary entities.
20862 Set_Needs_Debug_Info (T);
20864 -- Set flag on subsidiary entities if not set already
20866 if Is_Object (T) then
20867 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
20869 elsif Is_Type (T) then
20870 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
20872 if Is_Record_Type (T) then
20874 Ent : Entity_Id := First_Entity (T);
20876 while Present (Ent) loop
20877 Set_Debug_Info_Needed_If_Not_Set (Ent);
20882 -- For a class wide subtype, we also need debug information
20883 -- for the equivalent type.
20885 if Ekind (T) = E_Class_Wide_Subtype then
20886 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
20889 elsif Is_Array_Type (T) then
20890 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
20893 Indx : Node_Id := First_Index (T);
20895 while Present (Indx) loop
20896 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
20897 Indx := Next_Index (Indx);
20901 -- For a packed array type, we also need debug information for
20902 -- the type used to represent the packed array. Conversely, we
20903 -- also need it for the former if we need it for the latter.
20905 if Is_Packed (T) then
20906 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Impl_Type (T));
20909 if Is_Packed_Array_Impl_Type (T) then
20910 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
20913 elsif Is_Access_Type (T) then
20914 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
20916 elsif Is_Private_Type (T) then
20918 FV : constant Entity_Id := Full_View (T);
20921 Set_Debug_Info_Needed_If_Not_Set (FV);
20923 -- If the full view is itself a derived private type, we need
20924 -- debug information on its underlying type.
20927 and then Is_Private_Type (FV)
20928 and then Present (Underlying_Full_View (FV))
20930 Set_Needs_Debug_Info (Underlying_Full_View (FV));
20934 elsif Is_Protected_Type (T) then
20935 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
20937 elsif Is_Scalar_Type (T) then
20939 -- If the subrange bounds are materialized by dedicated constant
20940 -- objects, also include them in the debug info to make sure the
20941 -- debugger can properly use them.
20943 if Present (Scalar_Range (T))
20944 and then Nkind (Scalar_Range (T)) = N_Range
20947 Low_Bnd : constant Node_Id := Type_Low_Bound (T);
20948 High_Bnd : constant Node_Id := Type_High_Bound (T);
20951 if Is_Entity_Name (Low_Bnd) then
20952 Set_Debug_Info_Needed_If_Not_Set (Entity (Low_Bnd));
20955 if Is_Entity_Name (High_Bnd) then
20956 Set_Debug_Info_Needed_If_Not_Set (Entity (High_Bnd));
20962 end Set_Debug_Info_Needed;
20964 ----------------------------
20965 -- Set_Entity_With_Checks --
20966 ----------------------------
20968 procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id) is
20969 Val_Actual : Entity_Id;
20971 Post_Node : Node_Id;
20974 -- Unconditionally set the entity
20976 Set_Entity (N, Val);
20978 -- The node to post on is the selector in the case of an expanded name,
20979 -- and otherwise the node itself.
20981 if Nkind (N) = N_Expanded_Name then
20982 Post_Node := Selector_Name (N);
20987 -- Check for violation of No_Fixed_IO
20989 if Restriction_Check_Required (No_Fixed_IO)
20991 ((RTU_Loaded (Ada_Text_IO)
20992 and then (Is_RTE (Val, RE_Decimal_IO)
20994 Is_RTE (Val, RE_Fixed_IO)))
20997 (RTU_Loaded (Ada_Wide_Text_IO)
20998 and then (Is_RTE (Val, RO_WT_Decimal_IO)
21000 Is_RTE (Val, RO_WT_Fixed_IO)))
21003 (RTU_Loaded (Ada_Wide_Wide_Text_IO)
21004 and then (Is_RTE (Val, RO_WW_Decimal_IO)
21006 Is_RTE (Val, RO_WW_Fixed_IO))))
21008 -- A special extra check, don't complain about a reference from within
21009 -- the Ada.Interrupts package itself!
21011 and then not In_Same_Extended_Unit (N, Val)
21013 Check_Restriction (No_Fixed_IO, Post_Node);
21016 -- Remaining checks are only done on source nodes. Note that we test
21017 -- for violation of No_Fixed_IO even on non-source nodes, because the
21018 -- cases for checking violations of this restriction are instantiations
21019 -- where the reference in the instance has Comes_From_Source False.
21021 if not Comes_From_Source (N) then
21025 -- Check for violation of No_Abort_Statements, which is triggered by
21026 -- call to Ada.Task_Identification.Abort_Task.
21028 if Restriction_Check_Required (No_Abort_Statements)
21029 and then (Is_RTE (Val, RE_Abort_Task))
21031 -- A special extra check, don't complain about a reference from within
21032 -- the Ada.Task_Identification package itself!
21034 and then not In_Same_Extended_Unit (N, Val)
21036 Check_Restriction (No_Abort_Statements, Post_Node);
21039 if Val = Standard_Long_Long_Integer then
21040 Check_Restriction (No_Long_Long_Integers, Post_Node);
21043 -- Check for violation of No_Dynamic_Attachment
21045 if Restriction_Check_Required (No_Dynamic_Attachment)
21046 and then RTU_Loaded (Ada_Interrupts)
21047 and then (Is_RTE (Val, RE_Is_Reserved) or else
21048 Is_RTE (Val, RE_Is_Attached) or else
21049 Is_RTE (Val, RE_Current_Handler) or else
21050 Is_RTE (Val, RE_Attach_Handler) or else
21051 Is_RTE (Val, RE_Exchange_Handler) or else
21052 Is_RTE (Val, RE_Detach_Handler) or else
21053 Is_RTE (Val, RE_Reference))
21055 -- A special extra check, don't complain about a reference from within
21056 -- the Ada.Interrupts package itself!
21058 and then not In_Same_Extended_Unit (N, Val)
21060 Check_Restriction (No_Dynamic_Attachment, Post_Node);
21063 -- Check for No_Implementation_Identifiers
21065 if Restriction_Check_Required (No_Implementation_Identifiers) then
21067 -- We have an implementation defined entity if it is marked as
21068 -- implementation defined, or is defined in a package marked as
21069 -- implementation defined. However, library packages themselves
21070 -- are excluded (we don't want to flag Interfaces itself, just
21071 -- the entities within it).
21073 if (Is_Implementation_Defined (Val)
21075 (Present (Scope (Val))
21076 and then Is_Implementation_Defined (Scope (Val))))
21077 and then not (Ekind_In (Val, E_Package, E_Generic_Package)
21078 and then Is_Library_Level_Entity (Val))
21080 Check_Restriction (No_Implementation_Identifiers, Post_Node);
21084 -- Do the style check
21087 and then not Suppress_Style_Checks (Val)
21088 and then not In_Instance
21090 if Nkind (N) = N_Identifier then
21092 elsif Nkind (N) = N_Expanded_Name then
21093 Nod := Selector_Name (N);
21098 -- A special situation arises for derived operations, where we want
21099 -- to do the check against the parent (since the Sloc of the derived
21100 -- operation points to the derived type declaration itself).
21103 while not Comes_From_Source (Val_Actual)
21104 and then Nkind (Val_Actual) in N_Entity
21105 and then (Ekind (Val_Actual) = E_Enumeration_Literal
21106 or else Is_Subprogram_Or_Generic_Subprogram (Val_Actual))
21107 and then Present (Alias (Val_Actual))
21109 Val_Actual := Alias (Val_Actual);
21112 -- Renaming declarations for generic actuals do not come from source,
21113 -- and have a different name from that of the entity they rename, so
21114 -- there is no style check to perform here.
21116 if Chars (Nod) = Chars (Val_Actual) then
21117 Style.Check_Identifier (Nod, Val_Actual);
21121 Set_Entity (N, Val);
21122 end Set_Entity_With_Checks;
21124 ------------------------
21125 -- Set_Name_Entity_Id --
21126 ------------------------
21128 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
21130 Set_Name_Table_Int (Id, Int (Val));
21131 end Set_Name_Entity_Id;
21133 ---------------------
21134 -- Set_Next_Actual --
21135 ---------------------
21137 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
21139 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
21140 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
21142 end Set_Next_Actual;
21144 ----------------------------------
21145 -- Set_Optimize_Alignment_Flags --
21146 ----------------------------------
21148 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
21150 if Optimize_Alignment = 'S' then
21151 Set_Optimize_Alignment_Space (E);
21152 elsif Optimize_Alignment = 'T' then
21153 Set_Optimize_Alignment_Time (E);
21155 end Set_Optimize_Alignment_Flags;
21157 -----------------------
21158 -- Set_Public_Status --
21159 -----------------------
21161 procedure Set_Public_Status (Id : Entity_Id) is
21162 S : constant Entity_Id := Current_Scope;
21164 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
21165 -- Determines if E is defined within handled statement sequence or
21166 -- an if statement, returns True if so, False otherwise.
21168 ----------------------
21169 -- Within_HSS_Or_If --
21170 ----------------------
21172 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
21175 N := Declaration_Node (E);
21182 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
21188 end Within_HSS_Or_If;
21190 -- Start of processing for Set_Public_Status
21193 -- Everything in the scope of Standard is public
21195 if S = Standard_Standard then
21196 Set_Is_Public (Id);
21198 -- Entity is definitely not public if enclosing scope is not public
21200 elsif not Is_Public (S) then
21203 -- An object or function declaration that occurs in a handled sequence
21204 -- of statements or within an if statement is the declaration for a
21205 -- temporary object or local subprogram generated by the expander. It
21206 -- never needs to be made public and furthermore, making it public can
21207 -- cause back end problems.
21209 elsif Nkind_In (Parent (Id), N_Object_Declaration,
21210 N_Function_Specification)
21211 and then Within_HSS_Or_If (Id)
21215 -- Entities in public packages or records are public
21217 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
21218 Set_Is_Public (Id);
21220 -- The bounds of an entry family declaration can generate object
21221 -- declarations that are visible to the back-end, e.g. in the
21222 -- the declaration of a composite type that contains tasks.
21224 elsif Is_Concurrent_Type (S)
21225 and then not Has_Completion (S)
21226 and then Nkind (Parent (Id)) = N_Object_Declaration
21228 Set_Is_Public (Id);
21230 end Set_Public_Status;
21232 -----------------------------
21233 -- Set_Referenced_Modified --
21234 -----------------------------
21236 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
21240 -- Deal with indexed or selected component where prefix is modified
21242 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
21243 Pref := Prefix (N);
21245 -- If prefix is access type, then it is the designated object that is
21246 -- being modified, which means we have no entity to set the flag on.
21248 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
21251 -- Otherwise chase the prefix
21254 Set_Referenced_Modified (Pref, Out_Param);
21257 -- Otherwise see if we have an entity name (only other case to process)
21259 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
21260 Set_Referenced_As_LHS (Entity (N), not Out_Param);
21261 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
21263 end Set_Referenced_Modified;
21265 ----------------------------
21266 -- Set_Scope_Is_Transient --
21267 ----------------------------
21269 procedure Set_Scope_Is_Transient (V : Boolean := True) is
21271 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
21272 end Set_Scope_Is_Transient;
21274 -------------------
21275 -- Set_Size_Info --
21276 -------------------
21278 procedure Set_Size_Info (T1, T2 : Entity_Id) is
21280 -- We copy Esize, but not RM_Size, since in general RM_Size is
21281 -- subtype specific and does not get inherited by all subtypes.
21283 Set_Esize (T1, Esize (T2));
21284 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
21286 if Is_Discrete_Or_Fixed_Point_Type (T1)
21288 Is_Discrete_Or_Fixed_Point_Type (T2)
21290 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
21293 Set_Alignment (T1, Alignment (T2));
21296 ------------------------------
21297 -- Should_Ignore_Pragma_Par --
21298 ------------------------------
21300 function Should_Ignore_Pragma_Par (Prag_Name : Name_Id) return Boolean is
21301 pragma Assert (Compiler_State = Parsing);
21302 -- This one can't work during semantic analysis, because we don't have a
21303 -- correct Current_Source_File.
21305 Result : constant Boolean :=
21306 Get_Name_Table_Boolean3 (Prag_Name)
21307 and then not Is_Internal_File_Name
21308 (File_Name (Current_Source_File));
21311 end Should_Ignore_Pragma_Par;
21313 ------------------------------
21314 -- Should_Ignore_Pragma_Sem --
21315 ------------------------------
21317 function Should_Ignore_Pragma_Sem (N : Node_Id) return Boolean is
21318 pragma Assert (Compiler_State = Analyzing);
21319 Prag_Name : constant Name_Id := Pragma_Name (N);
21320 Result : constant Boolean :=
21321 Get_Name_Table_Boolean3 (Prag_Name)
21322 and then not In_Internal_Unit (N);
21326 end Should_Ignore_Pragma_Sem;
21328 --------------------
21329 -- Static_Boolean --
21330 --------------------
21332 function Static_Boolean (N : Node_Id) return Uint is
21334 Analyze_And_Resolve (N, Standard_Boolean);
21337 or else Error_Posted (N)
21338 or else Etype (N) = Any_Type
21343 if Is_OK_Static_Expression (N) then
21344 if not Raises_Constraint_Error (N) then
21345 return Expr_Value (N);
21350 elsif Etype (N) = Any_Type then
21354 Flag_Non_Static_Expr
21355 ("static boolean expression required here", N);
21358 end Static_Boolean;
21360 --------------------
21361 -- Static_Integer --
21362 --------------------
21364 function Static_Integer (N : Node_Id) return Uint is
21366 Analyze_And_Resolve (N, Any_Integer);
21369 or else Error_Posted (N)
21370 or else Etype (N) = Any_Type
21375 if Is_OK_Static_Expression (N) then
21376 if not Raises_Constraint_Error (N) then
21377 return Expr_Value (N);
21382 elsif Etype (N) = Any_Type then
21386 Flag_Non_Static_Expr
21387 ("static integer expression required here", N);
21390 end Static_Integer;
21392 --------------------------
21393 -- Statically_Different --
21394 --------------------------
21396 function Statically_Different (E1, E2 : Node_Id) return Boolean is
21397 R1 : constant Node_Id := Get_Referenced_Object (E1);
21398 R2 : constant Node_Id := Get_Referenced_Object (E2);
21400 return Is_Entity_Name (R1)
21401 and then Is_Entity_Name (R2)
21402 and then Entity (R1) /= Entity (R2)
21403 and then not Is_Formal (Entity (R1))
21404 and then not Is_Formal (Entity (R2));
21405 end Statically_Different;
21407 --------------------------------------
21408 -- Subject_To_Loop_Entry_Attributes --
21409 --------------------------------------
21411 function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
21417 -- The expansion mechanism transform a loop subject to at least one
21418 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
21419 -- the conditional part.
21421 if Nkind_In (Stmt, N_Block_Statement, N_If_Statement)
21422 and then Nkind (Original_Node (N)) = N_Loop_Statement
21424 Stmt := Original_Node (N);
21428 Nkind (Stmt) = N_Loop_Statement
21429 and then Present (Identifier (Stmt))
21430 and then Present (Entity (Identifier (Stmt)))
21431 and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
21432 end Subject_To_Loop_Entry_Attributes;
21434 -----------------------------
21435 -- Subprogram_Access_Level --
21436 -----------------------------
21438 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
21440 if Present (Alias (Subp)) then
21441 return Subprogram_Access_Level (Alias (Subp));
21443 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
21445 end Subprogram_Access_Level;
21447 -------------------------------
21448 -- Support_Atomic_Primitives --
21449 -------------------------------
21451 function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
21455 -- Verify the alignment of Typ is known
21457 if not Known_Alignment (Typ) then
21461 if Known_Static_Esize (Typ) then
21462 Size := UI_To_Int (Esize (Typ));
21464 -- If the Esize (Object_Size) is unknown at compile time, look at the
21465 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
21467 elsif Known_Static_RM_Size (Typ) then
21468 Size := UI_To_Int (RM_Size (Typ));
21470 -- Otherwise, the size is considered to be unknown.
21476 -- Check that the size of the component is 8, 16, 32, or 64 bits and
21477 -- that Typ is properly aligned.
21480 when 8 | 16 | 32 | 64 =>
21481 return Size = UI_To_Int (Alignment (Typ)) * 8;
21486 end Support_Atomic_Primitives;
21492 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
21494 if Debug_Flag_W then
21495 for J in 0 .. Scope_Stack.Last loop
21500 Write_Name (Chars (E));
21501 Write_Str (" from ");
21502 Write_Location (Sloc (N));
21507 -----------------------
21508 -- Transfer_Entities --
21509 -----------------------
21511 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
21512 procedure Set_Public_Status_Of (Id : Entity_Id);
21513 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
21514 -- Set_Public_Status. If successful and Id denotes a record type, set
21515 -- the Is_Public attribute of its fields.
21517 --------------------------
21518 -- Set_Public_Status_Of --
21519 --------------------------
21521 procedure Set_Public_Status_Of (Id : Entity_Id) is
21525 if not Is_Public (Id) then
21526 Set_Public_Status (Id);
21528 -- When the input entity is a public record type, ensure that all
21529 -- its internal fields are also exposed to the linker. The fields
21530 -- of a class-wide type are never made public.
21533 and then Is_Record_Type (Id)
21534 and then not Is_Class_Wide_Type (Id)
21536 Field := First_Entity (Id);
21537 while Present (Field) loop
21538 Set_Is_Public (Field);
21539 Next_Entity (Field);
21543 end Set_Public_Status_Of;
21547 Full_Id : Entity_Id;
21550 -- Start of processing for Transfer_Entities
21553 Id := First_Entity (From);
21555 if Present (Id) then
21557 -- Merge the entity chain of the source scope with that of the
21558 -- destination scope.
21560 if Present (Last_Entity (To)) then
21561 Set_Next_Entity (Last_Entity (To), Id);
21563 Set_First_Entity (To, Id);
21566 Set_Last_Entity (To, Last_Entity (From));
21568 -- Inspect the entities of the source scope and update their Scope
21571 while Present (Id) loop
21572 Set_Scope (Id, To);
21573 Set_Public_Status_Of (Id);
21575 -- Handle an internally generated full view for a private type
21577 if Is_Private_Type (Id)
21578 and then Present (Full_View (Id))
21579 and then Is_Itype (Full_View (Id))
21581 Full_Id := Full_View (Id);
21583 Set_Scope (Full_Id, To);
21584 Set_Public_Status_Of (Full_Id);
21590 Set_First_Entity (From, Empty);
21591 Set_Last_Entity (From, Empty);
21593 end Transfer_Entities;
21595 -----------------------
21596 -- Type_Access_Level --
21597 -----------------------
21599 function Type_Access_Level (Typ : Entity_Id) return Uint is
21603 Btyp := Base_Type (Typ);
21605 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
21606 -- simply use the level where the type is declared. This is true for
21607 -- stand-alone object declarations, and for anonymous access types
21608 -- associated with components the level is the same as that of the
21609 -- enclosing composite type. However, special treatment is needed for
21610 -- the cases of access parameters, return objects of an anonymous access
21611 -- type, and, in Ada 95, access discriminants of limited types.
21613 if Is_Access_Type (Btyp) then
21614 if Ekind (Btyp) = E_Anonymous_Access_Type then
21616 -- If the type is a nonlocal anonymous access type (such as for
21617 -- an access parameter) we treat it as being declared at the
21618 -- library level to ensure that names such as X.all'access don't
21619 -- fail static accessibility checks.
21621 if not Is_Local_Anonymous_Access (Typ) then
21622 return Scope_Depth (Standard_Standard);
21624 -- If this is a return object, the accessibility level is that of
21625 -- the result subtype of the enclosing function. The test here is
21626 -- little complicated, because we have to account for extended
21627 -- return statements that have been rewritten as blocks, in which
21628 -- case we have to find and the Is_Return_Object attribute of the
21629 -- itype's associated object. It would be nice to find a way to
21630 -- simplify this test, but it doesn't seem worthwhile to add a new
21631 -- flag just for purposes of this test. ???
21633 elsif Ekind (Scope (Btyp)) = E_Return_Statement
21636 and then Nkind (Associated_Node_For_Itype (Btyp)) =
21637 N_Object_Declaration
21638 and then Is_Return_Object
21639 (Defining_Identifier
21640 (Associated_Node_For_Itype (Btyp))))
21646 Scop := Scope (Scope (Btyp));
21647 while Present (Scop) loop
21648 exit when Ekind (Scop) = E_Function;
21649 Scop := Scope (Scop);
21652 -- Treat the return object's type as having the level of the
21653 -- function's result subtype (as per RM05-6.5(5.3/2)).
21655 return Type_Access_Level (Etype (Scop));
21660 Btyp := Root_Type (Btyp);
21662 -- The accessibility level of anonymous access types associated with
21663 -- discriminants is that of the current instance of the type, and
21664 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
21666 -- AI-402: access discriminants have accessibility based on the
21667 -- object rather than the type in Ada 2005, so the above paragraph
21670 -- ??? Needs completion with rules from AI-416
21672 if Ada_Version <= Ada_95
21673 and then Ekind (Typ) = E_Anonymous_Access_Type
21674 and then Present (Associated_Node_For_Itype (Typ))
21675 and then Nkind (Associated_Node_For_Itype (Typ)) =
21676 N_Discriminant_Specification
21678 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
21682 -- Return library level for a generic formal type. This is done because
21683 -- RM(10.3.2) says that "The statically deeper relationship does not
21684 -- apply to ... a descendant of a generic formal type". Rather than
21685 -- checking at each point where a static accessibility check is
21686 -- performed to see if we are dealing with a formal type, this rule is
21687 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
21688 -- return extreme values for a formal type; Deepest_Type_Access_Level
21689 -- returns Int'Last. By calling the appropriate function from among the
21690 -- two, we ensure that the static accessibility check will pass if we
21691 -- happen to run into a formal type. More specifically, we should call
21692 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
21693 -- call occurs as part of a static accessibility check and the error
21694 -- case is the case where the type's level is too shallow (as opposed
21697 if Is_Generic_Type (Root_Type (Btyp)) then
21698 return Scope_Depth (Standard_Standard);
21701 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
21702 end Type_Access_Level;
21704 ------------------------------------
21705 -- Type_Without_Stream_Operation --
21706 ------------------------------------
21708 function Type_Without_Stream_Operation
21710 Op : TSS_Name_Type := TSS_Null) return Entity_Id
21712 BT : constant Entity_Id := Base_Type (T);
21713 Op_Missing : Boolean;
21716 if not Restriction_Active (No_Default_Stream_Attributes) then
21720 if Is_Elementary_Type (T) then
21721 if Op = TSS_Null then
21723 No (TSS (BT, TSS_Stream_Read))
21724 or else No (TSS (BT, TSS_Stream_Write));
21727 Op_Missing := No (TSS (BT, Op));
21736 elsif Is_Array_Type (T) then
21737 return Type_Without_Stream_Operation (Component_Type (T), Op);
21739 elsif Is_Record_Type (T) then
21745 Comp := First_Component (T);
21746 while Present (Comp) loop
21747 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
21749 if Present (C_Typ) then
21753 Next_Component (Comp);
21759 elsif Is_Private_Type (T) and then Present (Full_View (T)) then
21760 return Type_Without_Stream_Operation (Full_View (T), Op);
21764 end Type_Without_Stream_Operation;
21766 ----------------------------
21767 -- Unique_Defining_Entity --
21768 ----------------------------
21770 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
21772 return Unique_Entity (Defining_Entity (N));
21773 end Unique_Defining_Entity;
21775 -------------------
21776 -- Unique_Entity --
21777 -------------------
21779 function Unique_Entity (E : Entity_Id) return Entity_Id is
21780 U : Entity_Id := E;
21786 if Present (Full_View (E)) then
21787 U := Full_View (E);
21791 if Nkind (Parent (E)) = N_Entry_Body then
21793 Prot_Item : Entity_Id;
21794 Prot_Type : Entity_Id;
21797 if Ekind (E) = E_Entry then
21798 Prot_Type := Scope (E);
21800 -- Bodies of entry families are nested within an extra scope
21801 -- that contains an entry index declaration
21804 Prot_Type := Scope (Scope (E));
21807 -- A protected type may be declared as a private type, in
21808 -- which case we need to get its full view.
21810 if Is_Private_Type (Prot_Type) then
21811 Prot_Type := Full_View (Prot_Type);
21814 -- Full view may not be present on error, in which case
21815 -- return E by default.
21817 if Present (Prot_Type) then
21818 pragma Assert (Ekind (Prot_Type) = E_Protected_Type);
21820 -- Traverse the entity list of the protected type and
21821 -- locate an entry declaration which matches the entry
21824 Prot_Item := First_Entity (Prot_Type);
21825 while Present (Prot_Item) loop
21826 if Ekind (Prot_Item) in Entry_Kind
21827 and then Corresponding_Body (Parent (Prot_Item)) = E
21833 Next_Entity (Prot_Item);
21839 when Formal_Kind =>
21840 if Present (Spec_Entity (E)) then
21841 U := Spec_Entity (E);
21844 when E_Package_Body =>
21847 if Nkind (P) = N_Defining_Program_Unit_Name then
21851 if Nkind (P) = N_Package_Body
21852 and then Present (Corresponding_Spec (P))
21854 U := Corresponding_Spec (P);
21856 elsif Nkind (P) = N_Package_Body_Stub
21857 and then Present (Corresponding_Spec_Of_Stub (P))
21859 U := Corresponding_Spec_Of_Stub (P);
21862 when E_Protected_Body =>
21865 if Nkind (P) = N_Protected_Body
21866 and then Present (Corresponding_Spec (P))
21868 U := Corresponding_Spec (P);
21870 elsif Nkind (P) = N_Protected_Body_Stub
21871 and then Present (Corresponding_Spec_Of_Stub (P))
21873 U := Corresponding_Spec_Of_Stub (P);
21875 if Is_Single_Protected_Object (U) then
21880 if Is_Private_Type (U) then
21881 U := Full_View (U);
21884 when E_Subprogram_Body =>
21887 if Nkind (P) = N_Defining_Program_Unit_Name then
21893 if Nkind (P) = N_Subprogram_Body
21894 and then Present (Corresponding_Spec (P))
21896 U := Corresponding_Spec (P);
21898 elsif Nkind (P) = N_Subprogram_Body_Stub
21899 and then Present (Corresponding_Spec_Of_Stub (P))
21901 U := Corresponding_Spec_Of_Stub (P);
21903 elsif Nkind (P) = N_Subprogram_Renaming_Declaration then
21904 U := Corresponding_Spec (P);
21907 when E_Task_Body =>
21910 if Nkind (P) = N_Task_Body
21911 and then Present (Corresponding_Spec (P))
21913 U := Corresponding_Spec (P);
21915 elsif Nkind (P) = N_Task_Body_Stub
21916 and then Present (Corresponding_Spec_Of_Stub (P))
21918 U := Corresponding_Spec_Of_Stub (P);
21920 if Is_Single_Task_Object (U) then
21925 if Is_Private_Type (U) then
21926 U := Full_View (U);
21930 if Present (Full_View (E)) then
21931 U := Full_View (E);
21945 function Unique_Name (E : Entity_Id) return String is
21947 -- Names in E_Subprogram_Body or E_Package_Body entities are not
21948 -- reliable, as they may not include the overloading suffix. Instead,
21949 -- when looking for the name of E or one of its enclosing scope, we get
21950 -- the name of the corresponding Unique_Entity.
21952 U : constant Entity_Id := Unique_Entity (E);
21954 function This_Name return String;
21960 function This_Name return String is
21962 return Get_Name_String (Chars (U));
21965 -- Start of processing for Unique_Name
21968 if E = Standard_Standard
21969 or else Has_Fully_Qualified_Name (E)
21973 elsif Ekind (E) = E_Enumeration_Literal then
21974 return Unique_Name (Etype (E)) & "__" & This_Name;
21978 S : constant Entity_Id := Scope (U);
21979 pragma Assert (Present (S));
21982 -- Prefix names of predefined types with standard__, but leave
21983 -- names of user-defined packages and subprograms without prefix
21984 -- (even if technically they are nested in the Standard package).
21986 if S = Standard_Standard then
21987 if Ekind (U) = E_Package or else Is_Subprogram (U) then
21990 return Unique_Name (S) & "__" & This_Name;
21993 -- For intances of generic subprograms use the name of the related
21994 -- instace and skip the scope of its wrapper package.
21996 elsif Is_Wrapper_Package (S) then
21997 pragma Assert (Scope (S) = Scope (Related_Instance (S)));
21998 -- Wrapper package and the instantiation are in the same scope
22001 Enclosing_Name : constant String :=
22002 Unique_Name (Scope (S)) & "__" &
22003 Get_Name_String (Chars (Related_Instance (S)));
22006 if Is_Subprogram (U)
22007 and then not Is_Generic_Actual_Subprogram (U)
22009 return Enclosing_Name;
22011 return Enclosing_Name & "__" & This_Name;
22016 return Unique_Name (S) & "__" & This_Name;
22022 ---------------------
22023 -- Unit_Is_Visible --
22024 ---------------------
22026 function Unit_Is_Visible (U : Entity_Id) return Boolean is
22027 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
22028 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
22030 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
22031 -- For a child unit, check whether unit appears in a with_clause
22034 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
22035 -- Scan the context clause of one compilation unit looking for a
22036 -- with_clause for the unit in question.
22038 ----------------------------
22039 -- Unit_In_Parent_Context --
22040 ----------------------------
22042 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
22044 if Unit_In_Context (Par_Unit) then
22047 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
22048 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
22053 end Unit_In_Parent_Context;
22055 ---------------------
22056 -- Unit_In_Context --
22057 ---------------------
22059 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
22063 Clause := First (Context_Items (Comp_Unit));
22064 while Present (Clause) loop
22065 if Nkind (Clause) = N_With_Clause then
22066 if Library_Unit (Clause) = U then
22069 -- The with_clause may denote a renaming of the unit we are
22070 -- looking for, eg. Text_IO which renames Ada.Text_IO.
22073 Renamed_Entity (Entity (Name (Clause))) =
22074 Defining_Entity (Unit (U))
22084 end Unit_In_Context;
22086 -- Start of processing for Unit_Is_Visible
22089 -- The currrent unit is directly visible
22094 elsif Unit_In_Context (Curr) then
22097 -- If the current unit is a body, check the context of the spec
22099 elsif Nkind (Unit (Curr)) = N_Package_Body
22101 (Nkind (Unit (Curr)) = N_Subprogram_Body
22102 and then not Acts_As_Spec (Unit (Curr)))
22104 if Unit_In_Context (Library_Unit (Curr)) then
22109 -- If the spec is a child unit, examine the parents
22111 if Is_Child_Unit (Curr_Entity) then
22112 if Nkind (Unit (Curr)) in N_Unit_Body then
22114 Unit_In_Parent_Context
22115 (Parent_Spec (Unit (Library_Unit (Curr))));
22117 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
22123 end Unit_Is_Visible;
22125 ------------------------------
22126 -- Universal_Interpretation --
22127 ------------------------------
22129 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
22130 Index : Interp_Index;
22134 -- The argument may be a formal parameter of an operator or subprogram
22135 -- with multiple interpretations, or else an expression for an actual.
22137 if Nkind (Opnd) = N_Defining_Identifier
22138 or else not Is_Overloaded (Opnd)
22140 if Etype (Opnd) = Universal_Integer
22141 or else Etype (Opnd) = Universal_Real
22143 return Etype (Opnd);
22149 Get_First_Interp (Opnd, Index, It);
22150 while Present (It.Typ) loop
22151 if It.Typ = Universal_Integer
22152 or else It.Typ = Universal_Real
22157 Get_Next_Interp (Index, It);
22162 end Universal_Interpretation;
22168 function Unqualify (Expr : Node_Id) return Node_Id is
22170 -- Recurse to handle unlikely case of multiple levels of qualification
22172 if Nkind (Expr) = N_Qualified_Expression then
22173 return Unqualify (Expression (Expr));
22175 -- Normal case, not a qualified expression
22182 -----------------------
22183 -- Visible_Ancestors --
22184 -----------------------
22186 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
22192 pragma Assert (Is_Record_Type (Typ) and then Is_Tagged_Type (Typ));
22194 -- Collect all the parents and progenitors of Typ. If the full-view of
22195 -- private parents and progenitors is available then it is used to
22196 -- generate the list of visible ancestors; otherwise their partial
22197 -- view is added to the resulting list.
22202 Use_Full_View => True);
22206 Ifaces_List => List_2,
22207 Exclude_Parents => True,
22208 Use_Full_View => True);
22210 -- Join the two lists. Avoid duplications because an interface may
22211 -- simultaneously be parent and progenitor of a type.
22213 Elmt := First_Elmt (List_2);
22214 while Present (Elmt) loop
22215 Append_Unique_Elmt (Node (Elmt), List_1);
22220 end Visible_Ancestors;
22222 ----------------------
22223 -- Within_Init_Proc --
22224 ----------------------
22226 function Within_Init_Proc return Boolean is
22230 S := Current_Scope;
22231 while not Is_Overloadable (S) loop
22232 if S = Standard_Standard then
22239 return Is_Init_Proc (S);
22240 end Within_Init_Proc;
22246 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
22248 return Scope_Within_Or_Same (Scope (E), S);
22255 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
22256 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
22257 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
22259 Matching_Field : Entity_Id;
22260 -- Entity to give a more precise suggestion on how to write a one-
22261 -- element positional aggregate.
22263 function Has_One_Matching_Field return Boolean;
22264 -- Determines if Expec_Type is a record type with a single component or
22265 -- discriminant whose type matches the found type or is one dimensional
22266 -- array whose component type matches the found type. In the case of
22267 -- one discriminant, we ignore the variant parts. That's not accurate,
22268 -- but good enough for the warning.
22270 ----------------------------
22271 -- Has_One_Matching_Field --
22272 ----------------------------
22274 function Has_One_Matching_Field return Boolean is
22278 Matching_Field := Empty;
22280 if Is_Array_Type (Expec_Type)
22281 and then Number_Dimensions (Expec_Type) = 1
22282 and then Covers (Etype (Component_Type (Expec_Type)), Found_Type)
22284 -- Use type name if available. This excludes multidimensional
22285 -- arrays and anonymous arrays.
22287 if Comes_From_Source (Expec_Type) then
22288 Matching_Field := Expec_Type;
22290 -- For an assignment, use name of target
22292 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
22293 and then Is_Entity_Name (Name (Parent (Expr)))
22295 Matching_Field := Entity (Name (Parent (Expr)));
22300 elsif not Is_Record_Type (Expec_Type) then
22304 E := First_Entity (Expec_Type);
22309 elsif not Ekind_In (E, E_Discriminant, E_Component)
22310 or else Nam_In (Chars (E), Name_uTag, Name_uParent)
22319 if not Covers (Etype (E), Found_Type) then
22322 elsif Present (Next_Entity (E))
22323 and then (Ekind (E) = E_Component
22324 or else Ekind (Next_Entity (E)) = E_Discriminant)
22329 Matching_Field := E;
22333 end Has_One_Matching_Field;
22335 -- Start of processing for Wrong_Type
22338 -- Don't output message if either type is Any_Type, or if a message
22339 -- has already been posted for this node. We need to do the latter
22340 -- check explicitly (it is ordinarily done in Errout), because we
22341 -- are using ! to force the output of the error messages.
22343 if Expec_Type = Any_Type
22344 or else Found_Type = Any_Type
22345 or else Error_Posted (Expr)
22349 -- If one of the types is a Taft-Amendment type and the other it its
22350 -- completion, it must be an illegal use of a TAT in the spec, for
22351 -- which an error was already emitted. Avoid cascaded errors.
22353 elsif Is_Incomplete_Type (Expec_Type)
22354 and then Has_Completion_In_Body (Expec_Type)
22355 and then Full_View (Expec_Type) = Etype (Expr)
22359 elsif Is_Incomplete_Type (Etype (Expr))
22360 and then Has_Completion_In_Body (Etype (Expr))
22361 and then Full_View (Etype (Expr)) = Expec_Type
22365 -- In an instance, there is an ongoing problem with completion of
22366 -- type derived from private types. Their structure is what Gigi
22367 -- expects, but the Etype is the parent type rather than the
22368 -- derived private type itself. Do not flag error in this case. The
22369 -- private completion is an entity without a parent, like an Itype.
22370 -- Similarly, full and partial views may be incorrect in the instance.
22371 -- There is no simple way to insure that it is consistent ???
22373 -- A similar view discrepancy can happen in an inlined body, for the
22374 -- same reason: inserted body may be outside of the original package
22375 -- and only partial views are visible at the point of insertion.
22377 elsif In_Instance or else In_Inlined_Body then
22378 if Etype (Etype (Expr)) = Etype (Expected_Type)
22380 (Has_Private_Declaration (Expected_Type)
22381 or else Has_Private_Declaration (Etype (Expr)))
22382 and then No (Parent (Expected_Type))
22386 elsif Nkind (Parent (Expr)) = N_Qualified_Expression
22387 and then Entity (Subtype_Mark (Parent (Expr))) = Expected_Type
22391 elsif Is_Private_Type (Expected_Type)
22392 and then Present (Full_View (Expected_Type))
22393 and then Covers (Full_View (Expected_Type), Etype (Expr))
22397 -- Conversely, type of expression may be the private one
22399 elsif Is_Private_Type (Base_Type (Etype (Expr)))
22400 and then Full_View (Base_Type (Etype (Expr))) = Expected_Type
22406 -- An interesting special check. If the expression is parenthesized
22407 -- and its type corresponds to the type of the sole component of the
22408 -- expected record type, or to the component type of the expected one
22409 -- dimensional array type, then assume we have a bad aggregate attempt.
22411 if Nkind (Expr) in N_Subexpr
22412 and then Paren_Count (Expr) /= 0
22413 and then Has_One_Matching_Field
22415 Error_Msg_N ("positional aggregate cannot have one component", Expr);
22417 if Present (Matching_Field) then
22418 if Is_Array_Type (Expec_Type) then
22420 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
22423 ("\write instead `& ='> ...`", Expr, Matching_Field);
22427 -- Another special check, if we are looking for a pool-specific access
22428 -- type and we found an E_Access_Attribute_Type, then we have the case
22429 -- of an Access attribute being used in a context which needs a pool-
22430 -- specific type, which is never allowed. The one extra check we make
22431 -- is that the expected designated type covers the Found_Type.
22433 elsif Is_Access_Type (Expec_Type)
22434 and then Ekind (Found_Type) = E_Access_Attribute_Type
22435 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
22436 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
22438 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
22440 Error_Msg_N -- CODEFIX
22441 ("result must be general access type!", Expr);
22442 Error_Msg_NE -- CODEFIX
22443 ("add ALL to }!", Expr, Expec_Type);
22445 -- Another special check, if the expected type is an integer type,
22446 -- but the expression is of type System.Address, and the parent is
22447 -- an addition or subtraction operation whose left operand is the
22448 -- expression in question and whose right operand is of an integral
22449 -- type, then this is an attempt at address arithmetic, so give
22450 -- appropriate message.
22452 elsif Is_Integer_Type (Expec_Type)
22453 and then Is_RTE (Found_Type, RE_Address)
22454 and then Nkind_In (Parent (Expr), N_Op_Add, N_Op_Subtract)
22455 and then Expr = Left_Opnd (Parent (Expr))
22456 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
22459 ("address arithmetic not predefined in package System",
22462 ("\possible missing with/use of System.Storage_Elements",
22466 -- If the expected type is an anonymous access type, as for access
22467 -- parameters and discriminants, the error is on the designated types.
22469 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
22470 if Comes_From_Source (Expec_Type) then
22471 Error_Msg_NE ("expected}!", Expr, Expec_Type);
22474 ("expected an access type with designated}",
22475 Expr, Designated_Type (Expec_Type));
22478 if Is_Access_Type (Found_Type)
22479 and then not Comes_From_Source (Found_Type)
22482 ("\\found an access type with designated}!",
22483 Expr, Designated_Type (Found_Type));
22485 if From_Limited_With (Found_Type) then
22486 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
22487 Error_Msg_Qual_Level := 99;
22488 Error_Msg_NE -- CODEFIX
22489 ("\\missing `WITH &;", Expr, Scope (Found_Type));
22490 Error_Msg_Qual_Level := 0;
22492 Error_Msg_NE ("found}!", Expr, Found_Type);
22496 -- Normal case of one type found, some other type expected
22499 -- If the names of the two types are the same, see if some number
22500 -- of levels of qualification will help. Don't try more than three
22501 -- levels, and if we get to standard, it's no use (and probably
22502 -- represents an error in the compiler) Also do not bother with
22503 -- internal scope names.
22506 Expec_Scope : Entity_Id;
22507 Found_Scope : Entity_Id;
22510 Expec_Scope := Expec_Type;
22511 Found_Scope := Found_Type;
22513 for Levels in Nat range 0 .. 3 loop
22514 if Chars (Expec_Scope) /= Chars (Found_Scope) then
22515 Error_Msg_Qual_Level := Levels;
22519 Expec_Scope := Scope (Expec_Scope);
22520 Found_Scope := Scope (Found_Scope);
22522 exit when Expec_Scope = Standard_Standard
22523 or else Found_Scope = Standard_Standard
22524 or else not Comes_From_Source (Expec_Scope)
22525 or else not Comes_From_Source (Found_Scope);
22529 if Is_Record_Type (Expec_Type)
22530 and then Present (Corresponding_Remote_Type (Expec_Type))
22532 Error_Msg_NE ("expected}!", Expr,
22533 Corresponding_Remote_Type (Expec_Type));
22535 Error_Msg_NE ("expected}!", Expr, Expec_Type);
22538 if Is_Entity_Name (Expr)
22539 and then Is_Package_Or_Generic_Package (Entity (Expr))
22541 Error_Msg_N ("\\found package name!", Expr);
22543 elsif Is_Entity_Name (Expr)
22544 and then Ekind_In (Entity (Expr), E_Procedure, E_Generic_Procedure)
22546 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
22548 ("found procedure name, possibly missing Access attribute!",
22552 ("\\found procedure name instead of function!", Expr);
22555 elsif Nkind (Expr) = N_Function_Call
22556 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
22557 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
22558 and then No (Parameter_Associations (Expr))
22561 ("found function name, possibly missing Access attribute!",
22564 -- Catch common error: a prefix or infix operator which is not
22565 -- directly visible because the type isn't.
22567 elsif Nkind (Expr) in N_Op
22568 and then Is_Overloaded (Expr)
22569 and then not Is_Immediately_Visible (Expec_Type)
22570 and then not Is_Potentially_Use_Visible (Expec_Type)
22571 and then not In_Use (Expec_Type)
22572 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
22575 ("operator of the type is not directly visible!", Expr);
22577 elsif Ekind (Found_Type) = E_Void
22578 and then Present (Parent (Found_Type))
22579 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
22581 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
22584 Error_Msg_NE ("\\found}!", Expr, Found_Type);
22587 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
22588 -- of the same modular type, and (M1 and M2) = 0 was intended.
22590 if Expec_Type = Standard_Boolean
22591 and then Is_Modular_Integer_Type (Found_Type)
22592 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
22593 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
22596 Op : constant Node_Id := Right_Opnd (Parent (Expr));
22597 L : constant Node_Id := Left_Opnd (Op);
22598 R : constant Node_Id := Right_Opnd (Op);
22601 -- The case for the message is when the left operand of the
22602 -- comparison is the same modular type, or when it is an
22603 -- integer literal (or other universal integer expression),
22604 -- which would have been typed as the modular type if the
22605 -- parens had been there.
22607 if (Etype (L) = Found_Type
22609 Etype (L) = Universal_Integer)
22610 and then Is_Integer_Type (Etype (R))
22613 ("\\possible missing parens for modular operation", Expr);
22618 -- Reset error message qualification indication
22620 Error_Msg_Qual_Level := 0;
22624 --------------------------------
22625 -- Yields_Synchronized_Object --
22626 --------------------------------
22628 function Yields_Synchronized_Object (Typ : Entity_Id) return Boolean is
22629 Has_Sync_Comp : Boolean := False;
22633 -- An array type yields a synchronized object if its component type
22634 -- yields a synchronized object.
22636 if Is_Array_Type (Typ) then
22637 return Yields_Synchronized_Object (Component_Type (Typ));
22639 -- A descendant of type Ada.Synchronous_Task_Control.Suspension_Object
22640 -- yields a synchronized object by default.
22642 elsif Is_Descendant_Of_Suspension_Object (Typ) then
22645 -- A protected type yields a synchronized object by default
22647 elsif Is_Protected_Type (Typ) then
22650 -- A record type or type extension yields a synchronized object when its
22651 -- discriminants (if any) lack default values and all components are of
22652 -- a type that yelds a synchronized object.
22654 elsif Is_Record_Type (Typ) then
22656 -- Inspect all entities defined in the scope of the type, looking for
22657 -- components of a type that does not yeld a synchronized object or
22658 -- for discriminants with default values.
22660 Id := First_Entity (Typ);
22661 while Present (Id) loop
22662 if Comes_From_Source (Id) then
22663 if Ekind (Id) = E_Component then
22664 if Yields_Synchronized_Object (Etype (Id)) then
22665 Has_Sync_Comp := True;
22667 -- The component does not yield a synchronized object
22673 elsif Ekind (Id) = E_Discriminant
22674 and then Present (Expression (Parent (Id)))
22683 -- Ensure that the parent type of a type extension yields a
22684 -- synchronized object.
22686 if Etype (Typ) /= Typ
22687 and then not Yields_Synchronized_Object (Etype (Typ))
22692 -- If we get here, then all discriminants lack default values and all
22693 -- components are of a type that yields a synchronized object.
22695 return Has_Sync_Comp;
22697 -- A synchronized interface type yields a synchronized object by default
22699 elsif Is_Synchronized_Interface (Typ) then
22702 -- A task type yelds a synchronized object by default
22704 elsif Is_Task_Type (Typ) then
22707 -- Otherwise the type does not yield a synchronized object
22712 end Yields_Synchronized_Object;
22714 ---------------------------
22715 -- Yields_Universal_Type --
22716 ---------------------------
22718 function Yields_Universal_Type (N : Node_Id) return Boolean is
22720 -- Integer and real literals are of a universal type
22722 if Nkind_In (N, N_Integer_Literal, N_Real_Literal) then
22725 -- The values of certain attributes are of a universal type
22727 elsif Nkind (N) = N_Attribute_Reference then
22729 Universal_Type_Attribute (Get_Attribute_Id (Attribute_Name (N)));
22731 -- ??? There are possibly other cases to consider
22736 end Yields_Universal_Type;