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 Erroutc; use Erroutc;
36 with Exp_Ch11; use Exp_Ch11;
37 with Exp_Disp; use Exp_Disp;
38 with Exp_Util; use Exp_Util;
39 with Fname; use Fname;
40 with Freeze; use Freeze;
42 with Lib.Xref; use Lib.Xref;
43 with Namet.Sp; use Namet.Sp;
44 with Nlists; use Nlists;
45 with Nmake; use Nmake;
46 with Output; use Output;
47 with Restrict; use Restrict;
48 with Rident; use Rident;
49 with Rtsfind; use Rtsfind;
51 with Sem_Aux; use Sem_Aux;
52 with Sem_Attr; use Sem_Attr;
53 with Sem_Ch6; use Sem_Ch6;
54 with Sem_Ch8; use Sem_Ch8;
55 with Sem_Disp; use Sem_Disp;
56 with Sem_Elab; use Sem_Elab;
57 with Sem_Eval; use Sem_Eval;
58 with Sem_Prag; use Sem_Prag;
59 with Sem_Res; use Sem_Res;
60 with Sem_Warn; use Sem_Warn;
61 with Sem_Type; use Sem_Type;
62 with Sinfo; use Sinfo;
63 with Sinput; use Sinput;
64 with Stand; use Stand;
66 with Stringt; use Stringt;
67 with Targparm; use Targparm;
68 with Tbuild; use Tbuild;
69 with Ttypes; use Ttypes;
70 with Uname; use Uname;
72 with GNAT.HTable; use GNAT.HTable;
74 package body Sem_Util is
76 -----------------------
77 -- Local Subprograms --
78 -----------------------
80 function Build_Component_Subtype
83 T : Entity_Id) return Node_Id;
84 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
85 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
86 -- Loc is the source location, T is the original subtype.
88 function Has_Enabled_Property
90 Property : Name_Id) return Boolean;
91 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
92 -- Determine whether an abstract state or a variable denoted by entity
93 -- Item_Id has enabled property Property.
95 function Has_Null_Extension (T : Entity_Id) return Boolean;
96 -- T is a derived tagged type. Check whether the type extension is null.
97 -- If the parent type is fully initialized, T can be treated as such.
99 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
100 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
101 -- with discriminants whose default values are static, examine only the
102 -- components in the selected variant to determine whether all of them
105 type Null_Status_Kind is
107 -- This value indicates that a subexpression is known to have a null
108 -- value at compile time.
111 -- This value indicates that a subexpression is known to have a non-null
112 -- value at compile time.
115 -- This value indicates that it cannot be determined at compile time
116 -- whether a subexpression yields a null or non-null value.
118 function Null_Status (N : Node_Id) return Null_Status_Kind;
119 -- Determine whether subexpression N of an access type yields a null value,
120 -- a non-null value, or the value cannot be determined at compile time. The
121 -- routine does not take simple flow diagnostics into account, it relies on
122 -- static facts such as the presence of null exclusions.
124 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
125 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
126 -- ???We retain the old and new algorithms for Requires_Transient_Scope for
127 -- the time being. New_Requires_Transient_Scope is used by default; the
128 -- debug switch -gnatdQ can be used to do Old_Requires_Transient_Scope
129 -- instead. The intent is to use this temporarily to measure before/after
130 -- efficiency. Note: when this temporary code is removed, the documentation
131 -- of dQ in debug.adb should be removed.
133 procedure Results_Differ
137 -- ???Debugging code. Called when the Old_Val and New_Val differ. This
138 -- routine will be removed eventially when New_Requires_Transient_Scope
139 -- becomes Requires_Transient_Scope and Old_Requires_Transient_Scope is
142 function Subprogram_Name (N : Node_Id) return String;
143 -- Return the fully qualified name of the enclosing subprogram for the
144 -- given node N, with file:line:col information appended, e.g.
145 -- "subp:file:line:col", corresponding to the source location of the
146 -- body of the subprogram.
148 ------------------------------
149 -- Abstract_Interface_List --
150 ------------------------------
152 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
156 if Is_Concurrent_Type (Typ) then
158 -- If we are dealing with a synchronized subtype, go to the base
159 -- type, whose declaration has the interface list.
161 -- Shouldn't this be Declaration_Node???
163 Nod := Parent (Base_Type (Typ));
165 if Nkind (Nod) = N_Full_Type_Declaration then
169 elsif Ekind (Typ) = E_Record_Type_With_Private then
170 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
171 Nod := Type_Definition (Parent (Typ));
173 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
174 if Present (Full_View (Typ))
176 Nkind (Parent (Full_View (Typ))) = N_Full_Type_Declaration
178 Nod := Type_Definition (Parent (Full_View (Typ)));
180 -- If the full-view is not available we cannot do anything else
181 -- here (the source has errors).
187 -- Support for generic formals with interfaces is still missing ???
189 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
194 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
198 elsif Ekind (Typ) = E_Record_Subtype then
199 Nod := Type_Definition (Parent (Etype (Typ)));
201 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
203 -- Recurse, because parent may still be a private extension. Also
204 -- note that the full view of the subtype or the full view of its
205 -- base type may (both) be unavailable.
207 return Abstract_Interface_List (Etype (Typ));
209 elsif Ekind (Typ) = E_Record_Type then
210 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
211 Nod := Formal_Type_Definition (Parent (Typ));
213 Nod := Type_Definition (Parent (Typ));
216 -- Otherwise the type is of a kind which does not implement interfaces
222 return Interface_List (Nod);
223 end Abstract_Interface_List;
225 --------------------------------
226 -- Add_Access_Type_To_Process --
227 --------------------------------
229 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
233 Ensure_Freeze_Node (E);
234 L := Access_Types_To_Process (Freeze_Node (E));
238 Set_Access_Types_To_Process (Freeze_Node (E), L);
242 end Add_Access_Type_To_Process;
244 --------------------------
245 -- Add_Block_Identifier --
246 --------------------------
248 procedure Add_Block_Identifier (N : Node_Id; Id : out Entity_Id) is
249 Loc : constant Source_Ptr := Sloc (N);
252 pragma Assert (Nkind (N) = N_Block_Statement);
254 -- The block already has a label, return its entity
256 if Present (Identifier (N)) then
257 Id := Entity (Identifier (N));
259 -- Create a new block label and set its attributes
262 Id := New_Internal_Entity (E_Block, Current_Scope, Loc, 'B');
263 Set_Etype (Id, Standard_Void_Type);
266 Set_Identifier (N, New_Occurrence_Of (Id, Loc));
267 Set_Block_Node (Id, Identifier (N));
269 end Add_Block_Identifier;
271 ----------------------------
272 -- Add_Global_Declaration --
273 ----------------------------
275 procedure Add_Global_Declaration (N : Node_Id) is
276 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
279 if No (Declarations (Aux_Node)) then
280 Set_Declarations (Aux_Node, New_List);
283 Append_To (Declarations (Aux_Node), N);
285 end Add_Global_Declaration;
287 --------------------------------
288 -- Address_Integer_Convert_OK --
289 --------------------------------
291 function Address_Integer_Convert_OK (T1, T2 : Entity_Id) return Boolean is
293 if Allow_Integer_Address
294 and then ((Is_Descendant_Of_Address (T1)
295 and then Is_Private_Type (T1)
296 and then Is_Integer_Type (T2))
298 (Is_Descendant_Of_Address (T2)
299 and then Is_Private_Type (T2)
300 and then Is_Integer_Type (T1)))
306 end Address_Integer_Convert_OK;
312 function Address_Value (N : Node_Id) return Node_Id is
317 -- For constant, get constant expression
319 if Is_Entity_Name (Expr)
320 and then Ekind (Entity (Expr)) = E_Constant
322 Expr := Constant_Value (Entity (Expr));
324 -- For unchecked conversion, get result to convert
326 elsif Nkind (Expr) = N_Unchecked_Type_Conversion then
327 Expr := Expression (Expr);
329 -- For (common case) of To_Address call, get argument
331 elsif Nkind (Expr) = N_Function_Call
332 and then Is_Entity_Name (Name (Expr))
333 and then Is_RTE (Entity (Name (Expr)), RE_To_Address)
335 Expr := First (Parameter_Associations (Expr));
337 if Nkind (Expr) = N_Parameter_Association then
338 Expr := Explicit_Actual_Parameter (Expr);
341 -- We finally have the real expression
355 -- For now, just 8/16/32/64
357 function Addressable (V : Uint) return Boolean is
359 return V = Uint_8 or else
365 function Addressable (V : Int) return Boolean is
373 ---------------------------------
374 -- Aggregate_Constraint_Checks --
375 ---------------------------------
377 procedure Aggregate_Constraint_Checks
379 Check_Typ : Entity_Id)
381 Exp_Typ : constant Entity_Id := Etype (Exp);
384 if Raises_Constraint_Error (Exp) then
388 -- Ada 2005 (AI-230): Generate a conversion to an anonymous access
389 -- component's type to force the appropriate accessibility checks.
391 -- Ada 2005 (AI-231): Generate conversion to the null-excluding type to
392 -- force the corresponding run-time check
394 if Is_Access_Type (Check_Typ)
395 and then Is_Local_Anonymous_Access (Check_Typ)
397 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
398 Analyze_And_Resolve (Exp, Check_Typ);
399 Check_Unset_Reference (Exp);
402 -- What follows is really expansion activity, so check that expansion
403 -- is on and is allowed. In GNATprove mode, we also want check flags to
404 -- be added in the tree, so that the formal verification can rely on
405 -- those to be present. In GNATprove mode for formal verification, some
406 -- treatment typically only done during expansion needs to be performed
407 -- on the tree, but it should not be applied inside generics. Otherwise,
408 -- this breaks the name resolution mechanism for generic instances.
410 if not Expander_Active
411 and (Inside_A_Generic or not Full_Analysis or not GNATprove_Mode)
416 if Is_Access_Type (Check_Typ)
417 and then Can_Never_Be_Null (Check_Typ)
418 and then not Can_Never_Be_Null (Exp_Typ)
420 Install_Null_Excluding_Check (Exp);
423 -- First check if we have to insert discriminant checks
425 if Has_Discriminants (Exp_Typ) then
426 Apply_Discriminant_Check (Exp, Check_Typ);
428 -- Next emit length checks for array aggregates
430 elsif Is_Array_Type (Exp_Typ) then
431 Apply_Length_Check (Exp, Check_Typ);
433 -- Finally emit scalar and string checks. If we are dealing with a
434 -- scalar literal we need to check by hand because the Etype of
435 -- literals is not necessarily correct.
437 elsif Is_Scalar_Type (Exp_Typ)
438 and then Compile_Time_Known_Value (Exp)
440 if Is_Out_Of_Range (Exp, Base_Type (Check_Typ)) then
441 Apply_Compile_Time_Constraint_Error
442 (Exp, "value not in range of}??", CE_Range_Check_Failed,
443 Ent => Base_Type (Check_Typ),
444 Typ => Base_Type (Check_Typ));
446 elsif Is_Out_Of_Range (Exp, Check_Typ) then
447 Apply_Compile_Time_Constraint_Error
448 (Exp, "value not in range of}??", CE_Range_Check_Failed,
452 elsif not Range_Checks_Suppressed (Check_Typ) then
453 Apply_Scalar_Range_Check (Exp, Check_Typ);
456 -- Verify that target type is also scalar, to prevent view anomalies
457 -- in instantiations.
459 elsif (Is_Scalar_Type (Exp_Typ)
460 or else Nkind (Exp) = N_String_Literal)
461 and then Is_Scalar_Type (Check_Typ)
462 and then Exp_Typ /= Check_Typ
464 if Is_Entity_Name (Exp)
465 and then Ekind (Entity (Exp)) = E_Constant
467 -- If expression is a constant, it is worthwhile checking whether
468 -- it is a bound of the type.
470 if (Is_Entity_Name (Type_Low_Bound (Check_Typ))
471 and then Entity (Exp) = Entity (Type_Low_Bound (Check_Typ)))
473 (Is_Entity_Name (Type_High_Bound (Check_Typ))
474 and then Entity (Exp) = Entity (Type_High_Bound (Check_Typ)))
479 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
480 Analyze_And_Resolve (Exp, Check_Typ);
481 Check_Unset_Reference (Exp);
484 -- Could use a comment on this case ???
487 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
488 Analyze_And_Resolve (Exp, Check_Typ);
489 Check_Unset_Reference (Exp);
493 end Aggregate_Constraint_Checks;
495 -----------------------
496 -- Alignment_In_Bits --
497 -----------------------
499 function Alignment_In_Bits (E : Entity_Id) return Uint is
501 return Alignment (E) * System_Storage_Unit;
502 end Alignment_In_Bits;
504 --------------------------------------
505 -- All_Composite_Constraints_Static --
506 --------------------------------------
508 function All_Composite_Constraints_Static
509 (Constr : Node_Id) return Boolean
512 if No (Constr) or else Error_Posted (Constr) then
516 case Nkind (Constr) is
518 if Nkind (Constr) in N_Has_Entity
519 and then Present (Entity (Constr))
521 if Is_Type (Entity (Constr)) then
523 not Is_Discrete_Type (Entity (Constr))
524 or else Is_OK_Static_Subtype (Entity (Constr));
527 elsif Nkind (Constr) = N_Range then
529 Is_OK_Static_Expression (Low_Bound (Constr))
531 Is_OK_Static_Expression (High_Bound (Constr));
533 elsif Nkind (Constr) = N_Attribute_Reference
534 and then Attribute_Name (Constr) = Name_Range
537 Is_OK_Static_Expression
538 (Type_Low_Bound (Etype (Prefix (Constr))))
540 Is_OK_Static_Expression
541 (Type_High_Bound (Etype (Prefix (Constr))));
545 not Present (Etype (Constr)) -- previous error
546 or else not Is_Discrete_Type (Etype (Constr))
547 or else Is_OK_Static_Expression (Constr);
549 when N_Discriminant_Association =>
550 return All_Composite_Constraints_Static (Expression (Constr));
552 when N_Range_Constraint =>
554 All_Composite_Constraints_Static (Range_Expression (Constr));
556 when N_Index_Or_Discriminant_Constraint =>
558 One_Cstr : Entity_Id;
560 One_Cstr := First (Constraints (Constr));
561 while Present (One_Cstr) loop
562 if not All_Composite_Constraints_Static (One_Cstr) then
572 when N_Subtype_Indication =>
574 All_Composite_Constraints_Static (Subtype_Mark (Constr))
576 All_Composite_Constraints_Static (Constraint (Constr));
581 end All_Composite_Constraints_Static;
583 ------------------------
584 -- Append_Entity_Name --
585 ------------------------
587 procedure Append_Entity_Name (Buf : in out Bounded_String; E : Entity_Id) is
588 Temp : Bounded_String;
590 procedure Inner (E : Entity_Id);
591 -- Inner recursive routine, keep outer routine nonrecursive to ease
592 -- debugging when we get strange results from this routine.
598 procedure Inner (E : Entity_Id) is
601 -- If entity has an internal name, skip by it, and print its scope.
602 -- Note that we strip a final R from the name before the test; this
603 -- is needed for some cases of instantiations.
606 E_Name : Bounded_String;
609 Append (E_Name, Chars (E));
611 if E_Name.Chars (E_Name.Length) = 'R' then
612 E_Name.Length := E_Name.Length - 1;
615 if Is_Internal_Name (E_Name) then
623 -- Just print entity name if its scope is at the outer level
625 if Scop = Standard_Standard then
628 -- If scope comes from source, write scope and entity
630 elsif Comes_From_Source (Scop) then
631 Append_Entity_Name (Temp, Scop);
634 -- If in wrapper package skip past it
636 elsif Present (Scop) and then Is_Wrapper_Package (Scop) then
637 Append_Entity_Name (Temp, Scope (Scop));
640 -- Otherwise nothing to output (happens in unnamed block statements)
649 E_Name : Bounded_String;
652 Append_Unqualified_Decoded (E_Name, Chars (E));
654 -- Remove trailing upper-case letters from the name (useful for
655 -- dealing with some cases of internal names generated in the case
656 -- of references from within a generic).
658 while E_Name.Length > 1
659 and then E_Name.Chars (E_Name.Length) in 'A' .. 'Z'
661 E_Name.Length := E_Name.Length - 1;
664 -- Adjust casing appropriately (gets name from source if possible)
666 Adjust_Name_Case (E_Name, Sloc (E));
667 Append (Temp, E_Name);
671 -- Start of processing for Append_Entity_Name
676 end Append_Entity_Name;
678 ---------------------------------
679 -- Append_Inherited_Subprogram --
680 ---------------------------------
682 procedure Append_Inherited_Subprogram (S : Entity_Id) is
683 Par : constant Entity_Id := Alias (S);
684 -- The parent subprogram
686 Scop : constant Entity_Id := Scope (Par);
687 -- The scope of definition of the parent subprogram
689 Typ : constant Entity_Id := Defining_Entity (Parent (S));
690 -- The derived type of which S is a primitive operation
696 if Ekind (Current_Scope) = E_Package
697 and then In_Private_Part (Current_Scope)
698 and then Has_Private_Declaration (Typ)
699 and then Is_Tagged_Type (Typ)
700 and then Scop = Current_Scope
702 -- The inherited operation is available at the earliest place after
703 -- the derived type declaration ( RM 7.3.1 (6/1)). This is only
704 -- relevant for type extensions. If the parent operation appears
705 -- after the type extension, the operation is not visible.
708 (Visible_Declarations
709 (Package_Specification (Current_Scope)));
710 while Present (Decl) loop
711 if Nkind (Decl) = N_Private_Extension_Declaration
712 and then Defining_Entity (Decl) = Typ
714 if Sloc (Decl) > Sloc (Par) then
715 Next_E := Next_Entity (Par);
716 Set_Next_Entity (Par, S);
717 Set_Next_Entity (S, Next_E);
729 -- If partial view is not a type extension, or it appears before the
730 -- subprogram declaration, insert normally at end of entity list.
732 Append_Entity (S, Current_Scope);
733 end Append_Inherited_Subprogram;
735 -----------------------------------------
736 -- Apply_Compile_Time_Constraint_Error --
737 -----------------------------------------
739 procedure Apply_Compile_Time_Constraint_Error
742 Reason : RT_Exception_Code;
743 Ent : Entity_Id := Empty;
744 Typ : Entity_Id := Empty;
745 Loc : Source_Ptr := No_Location;
746 Rep : Boolean := True;
747 Warn : Boolean := False)
749 Stat : constant Boolean := Is_Static_Expression (N);
750 R_Stat : constant Node_Id :=
751 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
762 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
764 -- In GNATprove mode, do not replace the node with an exception raised.
765 -- In such a case, either the call to Compile_Time_Constraint_Error
766 -- issues an error which stops analysis, or it issues a warning in
767 -- a few cases where a suitable check flag is set for GNATprove to
768 -- generate a check message.
770 if not Rep or GNATprove_Mode then
774 -- Now we replace the node by an N_Raise_Constraint_Error node
775 -- This does not need reanalyzing, so set it as analyzed now.
778 Set_Analyzed (N, True);
781 Set_Raises_Constraint_Error (N);
783 -- Now deal with possible local raise handling
785 Possible_Local_Raise (N, Standard_Constraint_Error);
787 -- If the original expression was marked as static, the result is
788 -- still marked as static, but the Raises_Constraint_Error flag is
789 -- always set so that further static evaluation is not attempted.
792 Set_Is_Static_Expression (N);
794 end Apply_Compile_Time_Constraint_Error;
796 ---------------------------
797 -- Async_Readers_Enabled --
798 ---------------------------
800 function Async_Readers_Enabled (Id : Entity_Id) return Boolean is
802 return Has_Enabled_Property (Id, Name_Async_Readers);
803 end Async_Readers_Enabled;
805 ---------------------------
806 -- Async_Writers_Enabled --
807 ---------------------------
809 function Async_Writers_Enabled (Id : Entity_Id) return Boolean is
811 return Has_Enabled_Property (Id, Name_Async_Writers);
812 end Async_Writers_Enabled;
814 --------------------------------------
815 -- Available_Full_View_Of_Component --
816 --------------------------------------
818 function Available_Full_View_Of_Component (T : Entity_Id) return Boolean is
819 ST : constant Entity_Id := Scope (T);
820 SCT : constant Entity_Id := Scope (Component_Type (T));
822 return In_Open_Scopes (ST)
823 and then In_Open_Scopes (SCT)
824 and then Scope_Depth (ST) >= Scope_Depth (SCT);
825 end Available_Full_View_Of_Component;
831 procedure Bad_Attribute
834 Warn : Boolean := False)
837 Error_Msg_Warn := Warn;
838 Error_Msg_N ("unrecognized attribute&<<", N);
840 -- Check for possible misspelling
842 Error_Msg_Name_1 := First_Attribute_Name;
843 while Error_Msg_Name_1 <= Last_Attribute_Name loop
844 if Is_Bad_Spelling_Of (Nam, Error_Msg_Name_1) then
845 Error_Msg_N -- CODEFIX
846 ("\possible misspelling of %<<", N);
850 Error_Msg_Name_1 := Error_Msg_Name_1 + 1;
854 --------------------------------
855 -- Bad_Predicated_Subtype_Use --
856 --------------------------------
858 procedure Bad_Predicated_Subtype_Use
862 Suggest_Static : Boolean := False)
867 -- Avoid cascaded errors
869 if Error_Posted (N) then
873 if Inside_A_Generic then
874 Gen := Current_Scope;
875 while Present (Gen) and then Ekind (Gen) /= E_Generic_Package loop
883 if Is_Generic_Formal (Typ) and then Is_Discrete_Type (Typ) then
884 Set_No_Predicate_On_Actual (Typ);
887 elsif Has_Predicates (Typ) then
888 if Is_Generic_Actual_Type (Typ) then
890 -- The restriction on loop parameters is only that the type
891 -- should have no dynamic predicates.
893 if Nkind (Parent (N)) = N_Loop_Parameter_Specification
894 and then not Has_Dynamic_Predicate_Aspect (Typ)
895 and then Is_OK_Static_Subtype (Typ)
900 Gen := Current_Scope;
901 while not Is_Generic_Instance (Gen) loop
905 pragma Assert (Present (Gen));
907 if Ekind (Gen) = E_Package and then In_Package_Body (Gen) then
908 Error_Msg_Warn := SPARK_Mode /= On;
909 Error_Msg_FE (Msg & "<<", N, Typ);
910 Error_Msg_F ("\Program_Error [<<", N);
913 Make_Raise_Program_Error (Sloc (N),
914 Reason => PE_Bad_Predicated_Generic_Type));
917 Error_Msg_FE (Msg & "<<", N, Typ);
921 Error_Msg_FE (Msg, N, Typ);
924 -- Emit an optional suggestion on how to remedy the error if the
925 -- context warrants it.
927 if Suggest_Static and then Has_Static_Predicate (Typ) then
928 Error_Msg_FE ("\predicate of & should be marked static", N, Typ);
931 end Bad_Predicated_Subtype_Use;
933 -----------------------------------------
934 -- Bad_Unordered_Enumeration_Reference --
935 -----------------------------------------
937 function Bad_Unordered_Enumeration_Reference
939 T : Entity_Id) return Boolean
942 return Is_Enumeration_Type (T)
943 and then Warn_On_Unordered_Enumeration_Type
944 and then not Is_Generic_Type (T)
945 and then Comes_From_Source (N)
946 and then not Has_Pragma_Ordered (T)
947 and then not In_Same_Extended_Unit (N, T);
948 end Bad_Unordered_Enumeration_Reference;
950 ----------------------------
951 -- Begin_Keyword_Location --
952 ----------------------------
954 function Begin_Keyword_Location (N : Node_Id) return Source_Ptr is
958 pragma Assert (Nkind_In (N, N_Block_Statement,
964 HSS := Handled_Statement_Sequence (N);
966 -- When the handled sequence of statements comes from source, the
967 -- location of the "begin" keyword is that of the sequence itself.
968 -- Note that an internal construct may inherit a source sequence.
970 if Comes_From_Source (HSS) then
973 -- The parser generates an internal handled sequence of statements to
974 -- capture the location of the "begin" keyword if present in the source.
975 -- Since there are no source statements, the location of the "begin"
976 -- keyword is effectively that of the "end" keyword.
978 elsif Comes_From_Source (N) then
981 -- Otherwise the construct is internal and should carry the location of
982 -- the original construct which prompted its creation.
987 end Begin_Keyword_Location;
989 --------------------------
990 -- Build_Actual_Subtype --
991 --------------------------
993 function Build_Actual_Subtype
995 N : Node_Or_Entity_Id) return Node_Id
998 -- Normally Sloc (N), but may point to corresponding body in some cases
1000 Constraints : List_Id;
1006 Disc_Type : Entity_Id;
1012 if Nkind (N) = N_Defining_Identifier then
1013 Obj := New_Occurrence_Of (N, Loc);
1015 -- If this is a formal parameter of a subprogram declaration, and
1016 -- we are compiling the body, we want the declaration for the
1017 -- actual subtype to carry the source position of the body, to
1018 -- prevent anomalies in gdb when stepping through the code.
1020 if Is_Formal (N) then
1022 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
1024 if Nkind (Decl) = N_Subprogram_Declaration
1025 and then Present (Corresponding_Body (Decl))
1027 Loc := Sloc (Corresponding_Body (Decl));
1036 if Is_Array_Type (T) then
1037 Constraints := New_List;
1038 for J in 1 .. Number_Dimensions (T) loop
1040 -- Build an array subtype declaration with the nominal subtype and
1041 -- the bounds of the actual. Add the declaration in front of the
1042 -- local declarations for the subprogram, for analysis before any
1043 -- reference to the formal in the body.
1046 Make_Attribute_Reference (Loc,
1048 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
1049 Attribute_Name => Name_First,
1050 Expressions => New_List (
1051 Make_Integer_Literal (Loc, J)));
1054 Make_Attribute_Reference (Loc,
1056 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
1057 Attribute_Name => Name_Last,
1058 Expressions => New_List (
1059 Make_Integer_Literal (Loc, J)));
1061 Append (Make_Range (Loc, Lo, Hi), Constraints);
1064 -- If the type has unknown discriminants there is no constrained
1065 -- subtype to build. This is never called for a formal or for a
1066 -- lhs, so returning the type is ok ???
1068 elsif Has_Unknown_Discriminants (T) then
1072 Constraints := New_List;
1074 -- Type T is a generic derived type, inherit the discriminants from
1077 if Is_Private_Type (T)
1078 and then No (Full_View (T))
1080 -- T was flagged as an error if it was declared as a formal
1081 -- derived type with known discriminants. In this case there
1082 -- is no need to look at the parent type since T already carries
1083 -- its own discriminants.
1085 and then not Error_Posted (T)
1087 Disc_Type := Etype (Base_Type (T));
1092 Discr := First_Discriminant (Disc_Type);
1093 while Present (Discr) loop
1094 Append_To (Constraints,
1095 Make_Selected_Component (Loc,
1097 Duplicate_Subexpr_No_Checks (Obj),
1098 Selector_Name => New_Occurrence_Of (Discr, Loc)));
1099 Next_Discriminant (Discr);
1103 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
1104 Set_Is_Internal (Subt);
1107 Make_Subtype_Declaration (Loc,
1108 Defining_Identifier => Subt,
1109 Subtype_Indication =>
1110 Make_Subtype_Indication (Loc,
1111 Subtype_Mark => New_Occurrence_Of (T, Loc),
1113 Make_Index_Or_Discriminant_Constraint (Loc,
1114 Constraints => Constraints)));
1116 Mark_Rewrite_Insertion (Decl);
1118 end Build_Actual_Subtype;
1120 ---------------------------------------
1121 -- Build_Actual_Subtype_Of_Component --
1122 ---------------------------------------
1124 function Build_Actual_Subtype_Of_Component
1126 N : Node_Id) return Node_Id
1128 Loc : constant Source_Ptr := Sloc (N);
1129 P : constant Node_Id := Prefix (N);
1132 Index_Typ : Entity_Id;
1134 Desig_Typ : Entity_Id;
1135 -- This is either a copy of T, or if T is an access type, then it is
1136 -- the directly designated type of this access type.
1138 function Build_Actual_Array_Constraint return List_Id;
1139 -- If one or more of the bounds of the component depends on
1140 -- discriminants, build actual constraint using the discriminants
1143 function Build_Actual_Record_Constraint return List_Id;
1144 -- Similar to previous one, for discriminated components constrained
1145 -- by the discriminant of the enclosing object.
1147 -----------------------------------
1148 -- Build_Actual_Array_Constraint --
1149 -----------------------------------
1151 function Build_Actual_Array_Constraint return List_Id is
1152 Constraints : constant List_Id := New_List;
1160 Indx := First_Index (Desig_Typ);
1161 while Present (Indx) loop
1162 Old_Lo := Type_Low_Bound (Etype (Indx));
1163 Old_Hi := Type_High_Bound (Etype (Indx));
1165 if Denotes_Discriminant (Old_Lo) then
1167 Make_Selected_Component (Loc,
1168 Prefix => New_Copy_Tree (P),
1169 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
1172 Lo := New_Copy_Tree (Old_Lo);
1174 -- The new bound will be reanalyzed in the enclosing
1175 -- declaration. For literal bounds that come from a type
1176 -- declaration, the type of the context must be imposed, so
1177 -- insure that analysis will take place. For non-universal
1178 -- types this is not strictly necessary.
1180 Set_Analyzed (Lo, False);
1183 if Denotes_Discriminant (Old_Hi) then
1185 Make_Selected_Component (Loc,
1186 Prefix => New_Copy_Tree (P),
1187 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
1190 Hi := New_Copy_Tree (Old_Hi);
1191 Set_Analyzed (Hi, False);
1194 Append (Make_Range (Loc, Lo, Hi), Constraints);
1199 end Build_Actual_Array_Constraint;
1201 ------------------------------------
1202 -- Build_Actual_Record_Constraint --
1203 ------------------------------------
1205 function Build_Actual_Record_Constraint return List_Id is
1206 Constraints : constant List_Id := New_List;
1211 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1212 while Present (D) loop
1213 if Denotes_Discriminant (Node (D)) then
1214 D_Val := Make_Selected_Component (Loc,
1215 Prefix => New_Copy_Tree (P),
1216 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
1219 D_Val := New_Copy_Tree (Node (D));
1222 Append (D_Val, Constraints);
1227 end Build_Actual_Record_Constraint;
1229 -- Start of processing for Build_Actual_Subtype_Of_Component
1232 -- Why the test for Spec_Expression mode here???
1234 if In_Spec_Expression then
1237 -- More comments for the rest of this body would be good ???
1239 elsif Nkind (N) = N_Explicit_Dereference then
1240 if Is_Composite_Type (T)
1241 and then not Is_Constrained (T)
1242 and then not (Is_Class_Wide_Type (T)
1243 and then Is_Constrained (Root_Type (T)))
1244 and then not Has_Unknown_Discriminants (T)
1246 -- If the type of the dereference is already constrained, it is an
1249 if Is_Array_Type (Etype (N))
1250 and then Is_Constrained (Etype (N))
1254 Remove_Side_Effects (P);
1255 return Build_Actual_Subtype (T, N);
1262 if Ekind (T) = E_Access_Subtype then
1263 Desig_Typ := Designated_Type (T);
1268 if Ekind (Desig_Typ) = E_Array_Subtype then
1269 Id := First_Index (Desig_Typ);
1270 while Present (Id) loop
1271 Index_Typ := Underlying_Type (Etype (Id));
1273 if Denotes_Discriminant (Type_Low_Bound (Index_Typ))
1275 Denotes_Discriminant (Type_High_Bound (Index_Typ))
1277 Remove_Side_Effects (P);
1279 Build_Component_Subtype
1280 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
1286 elsif Is_Composite_Type (Desig_Typ)
1287 and then Has_Discriminants (Desig_Typ)
1288 and then not Has_Unknown_Discriminants (Desig_Typ)
1290 if Is_Private_Type (Desig_Typ)
1291 and then No (Discriminant_Constraint (Desig_Typ))
1293 Desig_Typ := Full_View (Desig_Typ);
1296 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1297 while Present (D) loop
1298 if Denotes_Discriminant (Node (D)) then
1299 Remove_Side_Effects (P);
1301 Build_Component_Subtype (
1302 Build_Actual_Record_Constraint, Loc, Base_Type (T));
1309 -- If none of the above, the actual and nominal subtypes are the same
1312 end Build_Actual_Subtype_Of_Component;
1314 ---------------------------------
1315 -- Build_Class_Wide_Clone_Body --
1316 ---------------------------------
1318 procedure Build_Class_Wide_Clone_Body
1319 (Spec_Id : Entity_Id;
1322 Loc : constant Source_Ptr := Sloc (Bod);
1323 Clone_Id : constant Entity_Id := Class_Wide_Clone (Spec_Id);
1324 Clone_Body : Node_Id;
1327 -- The declaration of the class-wide clone was created when the
1328 -- corresponding class-wide condition was analyzed.
1331 Make_Subprogram_Body (Loc,
1333 Copy_Subprogram_Spec (Parent (Clone_Id)),
1334 Declarations => Declarations (Bod),
1335 Handled_Statement_Sequence => Handled_Statement_Sequence (Bod));
1337 -- The new operation is internal and overriding indicators do not apply
1338 -- (the original primitive may have carried one).
1340 Set_Must_Override (Specification (Clone_Body), False);
1341 Insert_Before (Bod, Clone_Body);
1342 Analyze (Clone_Body);
1343 end Build_Class_Wide_Clone_Body;
1345 ---------------------------------
1346 -- Build_Class_Wide_Clone_Call --
1347 ---------------------------------
1349 function Build_Class_Wide_Clone_Call
1352 Spec_Id : Entity_Id;
1353 Spec : Node_Id) return Node_Id
1355 Clone_Id : constant Entity_Id := Class_Wide_Clone (Spec_Id);
1356 Par_Type : constant Entity_Id := Find_Dispatching_Type (Spec_Id);
1362 New_F_Spec : Entity_Id;
1363 New_Formal : Entity_Id;
1366 Actuals := Empty_List;
1367 Formal := First_Formal (Spec_Id);
1368 New_F_Spec := First (Parameter_Specifications (Spec));
1370 -- Build parameter association for call to class-wide clone.
1372 while Present (Formal) loop
1373 New_Formal := Defining_Identifier (New_F_Spec);
1375 -- If controlling argument and operation is inherited, add conversion
1376 -- to parent type for the call.
1378 if Etype (Formal) = Par_Type
1379 and then not Is_Empty_List (Decls)
1382 Make_Type_Conversion (Loc,
1383 New_Occurrence_Of (Par_Type, Loc),
1384 New_Occurrence_Of (New_Formal, Loc)));
1387 Append_To (Actuals, New_Occurrence_Of (New_Formal, Loc));
1390 Next_Formal (Formal);
1394 if Ekind (Spec_Id) = E_Procedure then
1396 Make_Procedure_Call_Statement (Loc,
1397 Name => New_Occurrence_Of (Clone_Id, Loc),
1398 Parameter_Associations => Actuals);
1401 Make_Simple_Return_Statement (Loc,
1403 Make_Function_Call (Loc,
1404 Name => New_Occurrence_Of (Clone_Id, Loc),
1405 Parameter_Associations => Actuals));
1409 Make_Subprogram_Body (Loc,
1411 Copy_Subprogram_Spec (Spec),
1412 Declarations => Decls,
1413 Handled_Statement_Sequence =>
1414 Make_Handled_Sequence_Of_Statements (Loc,
1415 Statements => New_List (Call),
1416 End_Label => Make_Identifier (Loc, Chars (Spec_Id))));
1419 end Build_Class_Wide_Clone_Call;
1421 ---------------------------------
1422 -- Build_Class_Wide_Clone_Decl --
1423 ---------------------------------
1425 procedure Build_Class_Wide_Clone_Decl (Spec_Id : Entity_Id) is
1426 Loc : constant Source_Ptr := Sloc (Spec_Id);
1427 Clone_Id : constant Entity_Id :=
1428 Make_Defining_Identifier (Loc,
1429 New_External_Name (Chars (Spec_Id), Suffix => "CL"));
1435 Spec := Copy_Subprogram_Spec (Parent (Spec_Id));
1436 Set_Must_Override (Spec, False);
1437 Set_Must_Not_Override (Spec, False);
1438 Set_Defining_Unit_Name (Spec, Clone_Id);
1440 Decl := Make_Subprogram_Declaration (Loc, Spec);
1441 Append (Decl, List_Containing (Unit_Declaration_Node (Spec_Id)));
1443 -- Link clone to original subprogram, for use when building body and
1444 -- wrapper call to inherited operation.
1446 Set_Class_Wide_Clone (Spec_Id, Clone_Id);
1447 end Build_Class_Wide_Clone_Decl;
1449 -----------------------------
1450 -- Build_Component_Subtype --
1451 -----------------------------
1453 function Build_Component_Subtype
1456 T : Entity_Id) return Node_Id
1462 -- Unchecked_Union components do not require component subtypes
1464 if Is_Unchecked_Union (T) then
1468 Subt := Make_Temporary (Loc, 'S');
1469 Set_Is_Internal (Subt);
1472 Make_Subtype_Declaration (Loc,
1473 Defining_Identifier => Subt,
1474 Subtype_Indication =>
1475 Make_Subtype_Indication (Loc,
1476 Subtype_Mark => New_Occurrence_Of (Base_Type (T), Loc),
1478 Make_Index_Or_Discriminant_Constraint (Loc,
1479 Constraints => C)));
1481 Mark_Rewrite_Insertion (Decl);
1483 end Build_Component_Subtype;
1485 ---------------------------
1486 -- Build_Default_Subtype --
1487 ---------------------------
1489 function Build_Default_Subtype
1491 N : Node_Id) return Entity_Id
1493 Loc : constant Source_Ptr := Sloc (N);
1497 -- The base type that is to be constrained by the defaults
1500 if not Has_Discriminants (T) or else Is_Constrained (T) then
1504 Bas := Base_Type (T);
1506 -- If T is non-private but its base type is private, this is the
1507 -- completion of a subtype declaration whose parent type is private
1508 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1509 -- are to be found in the full view of the base. Check that the private
1510 -- status of T and its base differ.
1512 if Is_Private_Type (Bas)
1513 and then not Is_Private_Type (T)
1514 and then Present (Full_View (Bas))
1516 Bas := Full_View (Bas);
1519 Disc := First_Discriminant (T);
1521 if No (Discriminant_Default_Value (Disc)) then
1526 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
1527 Constraints : constant List_Id := New_List;
1531 while Present (Disc) loop
1532 Append_To (Constraints,
1533 New_Copy_Tree (Discriminant_Default_Value (Disc)));
1534 Next_Discriminant (Disc);
1538 Make_Subtype_Declaration (Loc,
1539 Defining_Identifier => Act,
1540 Subtype_Indication =>
1541 Make_Subtype_Indication (Loc,
1542 Subtype_Mark => New_Occurrence_Of (Bas, Loc),
1544 Make_Index_Or_Discriminant_Constraint (Loc,
1545 Constraints => Constraints)));
1547 Insert_Action (N, Decl);
1549 -- If the context is a component declaration the subtype declaration
1550 -- will be analyzed when the enclosing type is frozen, otherwise do
1553 if Ekind (Current_Scope) /= E_Record_Type then
1559 end Build_Default_Subtype;
1561 --------------------------------------------
1562 -- Build_Discriminal_Subtype_Of_Component --
1563 --------------------------------------------
1565 function Build_Discriminal_Subtype_Of_Component
1566 (T : Entity_Id) return Node_Id
1568 Loc : constant Source_Ptr := Sloc (T);
1572 function Build_Discriminal_Array_Constraint return List_Id;
1573 -- If one or more of the bounds of the component depends on
1574 -- discriminants, build actual constraint using the discriminants
1577 function Build_Discriminal_Record_Constraint return List_Id;
1578 -- Similar to previous one, for discriminated components constrained by
1579 -- the discriminant of the enclosing object.
1581 ----------------------------------------
1582 -- Build_Discriminal_Array_Constraint --
1583 ----------------------------------------
1585 function Build_Discriminal_Array_Constraint return List_Id is
1586 Constraints : constant List_Id := New_List;
1594 Indx := First_Index (T);
1595 while Present (Indx) loop
1596 Old_Lo := Type_Low_Bound (Etype (Indx));
1597 Old_Hi := Type_High_Bound (Etype (Indx));
1599 if Denotes_Discriminant (Old_Lo) then
1600 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
1603 Lo := New_Copy_Tree (Old_Lo);
1606 if Denotes_Discriminant (Old_Hi) then
1607 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
1610 Hi := New_Copy_Tree (Old_Hi);
1613 Append (Make_Range (Loc, Lo, Hi), Constraints);
1618 end Build_Discriminal_Array_Constraint;
1620 -----------------------------------------
1621 -- Build_Discriminal_Record_Constraint --
1622 -----------------------------------------
1624 function Build_Discriminal_Record_Constraint return List_Id is
1625 Constraints : constant List_Id := New_List;
1630 D := First_Elmt (Discriminant_Constraint (T));
1631 while Present (D) loop
1632 if Denotes_Discriminant (Node (D)) then
1634 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
1636 D_Val := New_Copy_Tree (Node (D));
1639 Append (D_Val, Constraints);
1644 end Build_Discriminal_Record_Constraint;
1646 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1649 if Ekind (T) = E_Array_Subtype then
1650 Id := First_Index (T);
1651 while Present (Id) loop
1652 if Denotes_Discriminant (Type_Low_Bound (Etype (Id)))
1654 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
1656 return Build_Component_Subtype
1657 (Build_Discriminal_Array_Constraint, Loc, T);
1663 elsif Ekind (T) = E_Record_Subtype
1664 and then Has_Discriminants (T)
1665 and then not Has_Unknown_Discriminants (T)
1667 D := First_Elmt (Discriminant_Constraint (T));
1668 while Present (D) loop
1669 if Denotes_Discriminant (Node (D)) then
1670 return Build_Component_Subtype
1671 (Build_Discriminal_Record_Constraint, Loc, T);
1678 -- If none of the above, the actual and nominal subtypes are the same
1681 end Build_Discriminal_Subtype_Of_Component;
1683 ------------------------------
1684 -- Build_Elaboration_Entity --
1685 ------------------------------
1687 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
1688 Loc : constant Source_Ptr := Sloc (N);
1690 Elab_Ent : Entity_Id;
1692 procedure Set_Package_Name (Ent : Entity_Id);
1693 -- Given an entity, sets the fully qualified name of the entity in
1694 -- Name_Buffer, with components separated by double underscores. This
1695 -- is a recursive routine that climbs the scope chain to Standard.
1697 ----------------------
1698 -- Set_Package_Name --
1699 ----------------------
1701 procedure Set_Package_Name (Ent : Entity_Id) is
1703 if Scope (Ent) /= Standard_Standard then
1704 Set_Package_Name (Scope (Ent));
1707 Nam : constant String := Get_Name_String (Chars (Ent));
1709 Name_Buffer (Name_Len + 1) := '_';
1710 Name_Buffer (Name_Len + 2) := '_';
1711 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
1712 Name_Len := Name_Len + Nam'Length + 2;
1716 Get_Name_String (Chars (Ent));
1718 end Set_Package_Name;
1720 -- Start of processing for Build_Elaboration_Entity
1723 -- Ignore call if already constructed
1725 if Present (Elaboration_Entity (Spec_Id)) then
1728 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1729 -- no role in analysis.
1731 elsif ASIS_Mode then
1734 -- Do not generate an elaboration entity in GNATprove move because the
1735 -- elaboration counter is a form of expansion.
1737 elsif GNATprove_Mode then
1740 -- See if we need elaboration entity
1742 -- We always need an elaboration entity when preserving control flow, as
1743 -- we want to remain explicit about the unit's elaboration order.
1745 elsif Opt.Suppress_Control_Flow_Optimizations then
1748 -- We always need an elaboration entity for the dynamic elaboration
1749 -- model, since it is needed to properly generate the PE exception for
1750 -- access before elaboration.
1752 elsif Dynamic_Elaboration_Checks then
1755 -- For the static model, we don't need the elaboration counter if this
1756 -- unit is sure to have no elaboration code, since that means there
1757 -- is no elaboration unit to be called. Note that we can't just decide
1758 -- after the fact by looking to see whether there was elaboration code,
1759 -- because that's too late to make this decision.
1761 elsif Restriction_Active (No_Elaboration_Code) then
1764 -- Similarly, for the static model, we can skip the elaboration counter
1765 -- if we have the No_Multiple_Elaboration restriction, since for the
1766 -- static model, that's the only purpose of the counter (to avoid
1767 -- multiple elaboration).
1769 elsif Restriction_Active (No_Multiple_Elaboration) then
1773 -- Here we need the elaboration entity
1775 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1776 -- name with dots replaced by double underscore. We have to manually
1777 -- construct this name, since it will be elaborated in the outer scope,
1778 -- and thus will not have the unit name automatically prepended.
1780 Set_Package_Name (Spec_Id);
1781 Add_Str_To_Name_Buffer ("_E");
1783 -- Create elaboration counter
1785 Elab_Ent := Make_Defining_Identifier (Loc, Chars => Name_Find);
1786 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
1789 Make_Object_Declaration (Loc,
1790 Defining_Identifier => Elab_Ent,
1791 Object_Definition =>
1792 New_Occurrence_Of (Standard_Short_Integer, Loc),
1793 Expression => Make_Integer_Literal (Loc, Uint_0));
1795 Push_Scope (Standard_Standard);
1796 Add_Global_Declaration (Decl);
1799 -- Reset True_Constant indication, since we will indeed assign a value
1800 -- to the variable in the binder main. We also kill the Current_Value
1801 -- and Last_Assignment fields for the same reason.
1803 Set_Is_True_Constant (Elab_Ent, False);
1804 Set_Current_Value (Elab_Ent, Empty);
1805 Set_Last_Assignment (Elab_Ent, Empty);
1807 -- We do not want any further qualification of the name (if we did not
1808 -- do this, we would pick up the name of the generic package in the case
1809 -- of a library level generic instantiation).
1811 Set_Has_Qualified_Name (Elab_Ent);
1812 Set_Has_Fully_Qualified_Name (Elab_Ent);
1813 end Build_Elaboration_Entity;
1815 --------------------------------
1816 -- Build_Explicit_Dereference --
1817 --------------------------------
1819 procedure Build_Explicit_Dereference
1823 Loc : constant Source_Ptr := Sloc (Expr);
1828 -- An entity of a type with a reference aspect is overloaded with
1829 -- both interpretations: with and without the dereference. Now that
1830 -- the dereference is made explicit, set the type of the node properly,
1831 -- to prevent anomalies in the backend. Same if the expression is an
1832 -- overloaded function call whose return type has a reference aspect.
1834 if Is_Entity_Name (Expr) then
1835 Set_Etype (Expr, Etype (Entity (Expr)));
1837 -- The designated entity will not be examined again when resolving
1838 -- the dereference, so generate a reference to it now.
1840 Generate_Reference (Entity (Expr), Expr);
1842 elsif Nkind (Expr) = N_Function_Call then
1844 -- If the name of the indexing function is overloaded, locate the one
1845 -- whose return type has an implicit dereference on the desired
1846 -- discriminant, and set entity and type of function call.
1848 if Is_Overloaded (Name (Expr)) then
1849 Get_First_Interp (Name (Expr), I, It);
1851 while Present (It.Nam) loop
1852 if Ekind ((It.Typ)) = E_Record_Type
1853 and then First_Entity ((It.Typ)) = Disc
1855 Set_Entity (Name (Expr), It.Nam);
1856 Set_Etype (Name (Expr), Etype (It.Nam));
1860 Get_Next_Interp (I, It);
1864 -- Set type of call from resolved function name.
1866 Set_Etype (Expr, Etype (Name (Expr)));
1869 Set_Is_Overloaded (Expr, False);
1871 -- The expression will often be a generalized indexing that yields a
1872 -- container element that is then dereferenced, in which case the
1873 -- generalized indexing call is also non-overloaded.
1875 if Nkind (Expr) = N_Indexed_Component
1876 and then Present (Generalized_Indexing (Expr))
1878 Set_Is_Overloaded (Generalized_Indexing (Expr), False);
1882 Make_Explicit_Dereference (Loc,
1884 Make_Selected_Component (Loc,
1885 Prefix => Relocate_Node (Expr),
1886 Selector_Name => New_Occurrence_Of (Disc, Loc))));
1887 Set_Etype (Prefix (Expr), Etype (Disc));
1888 Set_Etype (Expr, Designated_Type (Etype (Disc)));
1889 end Build_Explicit_Dereference;
1891 ---------------------------
1892 -- Build_Overriding_Spec --
1893 ---------------------------
1895 function Build_Overriding_Spec
1897 Typ : Entity_Id) return Node_Id
1899 Loc : constant Source_Ptr := Sloc (Typ);
1900 Par_Typ : constant Entity_Id := Find_Dispatching_Type (Op);
1901 Spec : constant Node_Id := Specification (Unit_Declaration_Node (Op));
1903 Formal_Spec : Node_Id;
1904 Formal_Type : Node_Id;
1908 New_Spec := Copy_Subprogram_Spec (Spec);
1910 Formal_Spec := First (Parameter_Specifications (New_Spec));
1911 while Present (Formal_Spec) loop
1912 Formal_Type := Parameter_Type (Formal_Spec);
1914 if Is_Entity_Name (Formal_Type)
1915 and then Entity (Formal_Type) = Par_Typ
1917 Rewrite (Formal_Type, New_Occurrence_Of (Typ, Loc));
1920 -- Nothing needs to be done for access parameters
1926 end Build_Overriding_Spec;
1928 -----------------------------------
1929 -- Cannot_Raise_Constraint_Error --
1930 -----------------------------------
1932 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
1934 if Compile_Time_Known_Value (Expr) then
1937 elsif Do_Range_Check (Expr) then
1940 elsif Raises_Constraint_Error (Expr) then
1944 case Nkind (Expr) is
1945 when N_Identifier =>
1948 when N_Expanded_Name =>
1951 when N_Selected_Component =>
1952 return not Do_Discriminant_Check (Expr);
1954 when N_Attribute_Reference =>
1955 if Do_Overflow_Check (Expr) then
1958 elsif No (Expressions (Expr)) then
1966 N := First (Expressions (Expr));
1967 while Present (N) loop
1968 if Cannot_Raise_Constraint_Error (N) then
1979 when N_Type_Conversion =>
1980 if Do_Overflow_Check (Expr)
1981 or else Do_Length_Check (Expr)
1982 or else Do_Tag_Check (Expr)
1986 return Cannot_Raise_Constraint_Error (Expression (Expr));
1989 when N_Unchecked_Type_Conversion =>
1990 return Cannot_Raise_Constraint_Error (Expression (Expr));
1993 if Do_Overflow_Check (Expr) then
1996 return Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
2003 if Do_Division_Check (Expr)
2005 Do_Overflow_Check (Expr)
2010 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
2012 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
2031 | N_Op_Shift_Right_Arithmetic
2035 if Do_Overflow_Check (Expr) then
2039 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
2041 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
2048 end Cannot_Raise_Constraint_Error;
2050 -----------------------------------------
2051 -- Check_Dynamically_Tagged_Expression --
2052 -----------------------------------------
2054 procedure Check_Dynamically_Tagged_Expression
2057 Related_Nod : Node_Id)
2060 pragma Assert (Is_Tagged_Type (Typ));
2062 -- In order to avoid spurious errors when analyzing the expanded code,
2063 -- this check is done only for nodes that come from source and for
2064 -- actuals of generic instantiations.
2066 if (Comes_From_Source (Related_Nod)
2067 or else In_Generic_Actual (Expr))
2068 and then (Is_Class_Wide_Type (Etype (Expr))
2069 or else Is_Dynamically_Tagged (Expr))
2070 and then not Is_Class_Wide_Type (Typ)
2072 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
2074 end Check_Dynamically_Tagged_Expression;
2076 --------------------------
2077 -- Check_Fully_Declared --
2078 --------------------------
2080 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
2082 if Ekind (T) = E_Incomplete_Type then
2084 -- Ada 2005 (AI-50217): If the type is available through a limited
2085 -- with_clause, verify that its full view has been analyzed.
2087 if From_Limited_With (T)
2088 and then Present (Non_Limited_View (T))
2089 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
2091 -- The non-limited view is fully declared
2097 ("premature usage of incomplete}", N, First_Subtype (T));
2100 -- Need comments for these tests ???
2102 elsif Has_Private_Component (T)
2103 and then not Is_Generic_Type (Root_Type (T))
2104 and then not In_Spec_Expression
2106 -- Special case: if T is the anonymous type created for a single
2107 -- task or protected object, use the name of the source object.
2109 if Is_Concurrent_Type (T)
2110 and then not Comes_From_Source (T)
2111 and then Nkind (N) = N_Object_Declaration
2114 ("type of& has incomplete component",
2115 N, Defining_Identifier (N));
2118 ("premature usage of incomplete}",
2119 N, First_Subtype (T));
2122 end Check_Fully_Declared;
2124 -------------------------------------------
2125 -- Check_Function_With_Address_Parameter --
2126 -------------------------------------------
2128 procedure Check_Function_With_Address_Parameter (Subp_Id : Entity_Id) is
2133 F := First_Formal (Subp_Id);
2134 while Present (F) loop
2137 if Is_Private_Type (T) and then Present (Full_View (T)) then
2141 if Is_Descendant_Of_Address (T) or else Is_Limited_Type (T) then
2142 Set_Is_Pure (Subp_Id, False);
2148 end Check_Function_With_Address_Parameter;
2150 -------------------------------------
2151 -- Check_Function_Writable_Actuals --
2152 -------------------------------------
2154 procedure Check_Function_Writable_Actuals (N : Node_Id) is
2155 Writable_Actuals_List : Elist_Id := No_Elist;
2156 Identifiers_List : Elist_Id := No_Elist;
2157 Aggr_Error_Node : Node_Id := Empty;
2158 Error_Node : Node_Id := Empty;
2160 procedure Collect_Identifiers (N : Node_Id);
2161 -- In a single traversal of subtree N collect in Writable_Actuals_List
2162 -- all the actuals of functions with writable actuals, and in the list
2163 -- Identifiers_List collect all the identifiers that are not actuals of
2164 -- functions with writable actuals. If a writable actual is referenced
2165 -- twice as writable actual then Error_Node is set to reference its
2166 -- second occurrence, the error is reported, and the tree traversal
2169 procedure Preanalyze_Without_Errors (N : Node_Id);
2170 -- Preanalyze N without reporting errors. Very dubious, you can't just
2171 -- go analyzing things more than once???
2173 -------------------------
2174 -- Collect_Identifiers --
2175 -------------------------
2177 procedure Collect_Identifiers (N : Node_Id) is
2179 function Check_Node (N : Node_Id) return Traverse_Result;
2180 -- Process a single node during the tree traversal to collect the
2181 -- writable actuals of functions and all the identifiers which are
2182 -- not writable actuals of functions.
2184 function Contains (List : Elist_Id; N : Node_Id) return Boolean;
2185 -- Returns True if List has a node whose Entity is Entity (N)
2191 function Check_Node (N : Node_Id) return Traverse_Result is
2192 Is_Writable_Actual : Boolean := False;
2196 if Nkind (N) = N_Identifier then
2198 -- No analysis possible if the entity is not decorated
2200 if No (Entity (N)) then
2203 -- Don't collect identifiers of packages, called functions, etc
2205 elsif Ekind_In (Entity (N), E_Package,
2212 -- For rewritten nodes, continue the traversal in the original
2213 -- subtree. Needed to handle aggregates in original expressions
2214 -- extracted from the tree by Remove_Side_Effects.
2216 elsif Is_Rewrite_Substitution (N) then
2217 Collect_Identifiers (Original_Node (N));
2220 -- For now we skip aggregate discriminants, since they require
2221 -- performing the analysis in two phases to identify conflicts:
2222 -- first one analyzing discriminants and second one analyzing
2223 -- the rest of components (since at run time, discriminants are
2224 -- evaluated prior to components): too much computation cost
2225 -- to identify a corner case???
2227 elsif Nkind (Parent (N)) = N_Component_Association
2228 and then Nkind_In (Parent (Parent (N)),
2230 N_Extension_Aggregate)
2233 Choice : constant Node_Id := First (Choices (Parent (N)));
2236 if Ekind (Entity (N)) = E_Discriminant then
2239 elsif Expression (Parent (N)) = N
2240 and then Nkind (Choice) = N_Identifier
2241 and then Ekind (Entity (Choice)) = E_Discriminant
2247 -- Analyze if N is a writable actual of a function
2249 elsif Nkind (Parent (N)) = N_Function_Call then
2251 Call : constant Node_Id := Parent (N);
2256 Id := Get_Called_Entity (Call);
2258 -- In case of previous error, no check is possible
2264 if Ekind_In (Id, E_Function, E_Generic_Function)
2265 and then Has_Out_Or_In_Out_Parameter (Id)
2267 Formal := First_Formal (Id);
2268 Actual := First_Actual (Call);
2269 while Present (Actual) and then Present (Formal) loop
2271 if Ekind_In (Formal, E_Out_Parameter,
2274 Is_Writable_Actual := True;
2280 Next_Formal (Formal);
2281 Next_Actual (Actual);
2287 if Is_Writable_Actual then
2289 -- Skip checking the error in non-elementary types since
2290 -- RM 6.4.1(6.15/3) is restricted to elementary types, but
2291 -- store this actual in Writable_Actuals_List since it is
2292 -- needed to perform checks on other constructs that have
2293 -- arbitrary order of evaluation (for example, aggregates).
2295 if not Is_Elementary_Type (Etype (N)) then
2296 if not Contains (Writable_Actuals_List, N) then
2297 Append_New_Elmt (N, To => Writable_Actuals_List);
2300 -- Second occurrence of an elementary type writable actual
2302 elsif Contains (Writable_Actuals_List, N) then
2304 -- Report the error on the second occurrence of the
2305 -- identifier. We cannot assume that N is the second
2306 -- occurrence (according to their location in the
2307 -- sources), since Traverse_Func walks through Field2
2308 -- last (see comment in the body of Traverse_Func).
2314 Elmt := First_Elmt (Writable_Actuals_List);
2315 while Present (Elmt)
2316 and then Entity (Node (Elmt)) /= Entity (N)
2321 if Sloc (N) > Sloc (Node (Elmt)) then
2324 Error_Node := Node (Elmt);
2328 ("value may be affected by call to & "
2329 & "because order of evaluation is arbitrary",
2334 -- First occurrence of a elementary type writable actual
2337 Append_New_Elmt (N, To => Writable_Actuals_List);
2341 if Identifiers_List = No_Elist then
2342 Identifiers_List := New_Elmt_List;
2345 Append_Unique_Elmt (N, Identifiers_List);
2358 N : Node_Id) return Boolean
2360 pragma Assert (Nkind (N) in N_Has_Entity);
2365 if List = No_Elist then
2369 Elmt := First_Elmt (List);
2370 while Present (Elmt) loop
2371 if Entity (Node (Elmt)) = Entity (N) then
2385 procedure Do_Traversal is new Traverse_Proc (Check_Node);
2386 -- The traversal procedure
2388 -- Start of processing for Collect_Identifiers
2391 if Present (Error_Node) then
2395 if Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
2400 end Collect_Identifiers;
2402 -------------------------------
2403 -- Preanalyze_Without_Errors --
2404 -------------------------------
2406 procedure Preanalyze_Without_Errors (N : Node_Id) is
2407 Status : constant Boolean := Get_Ignore_Errors;
2409 Set_Ignore_Errors (True);
2411 Set_Ignore_Errors (Status);
2412 end Preanalyze_Without_Errors;
2414 -- Start of processing for Check_Function_Writable_Actuals
2417 -- The check only applies to Ada 2012 code on which Check_Actuals has
2418 -- been set, and only to constructs that have multiple constituents
2419 -- whose order of evaluation is not specified by the language.
2421 if Ada_Version < Ada_2012
2422 or else not Check_Actuals (N)
2423 or else (not (Nkind (N) in N_Op)
2424 and then not (Nkind (N) in N_Membership_Test)
2425 and then not Nkind_In (N, N_Range,
2427 N_Extension_Aggregate,
2428 N_Full_Type_Declaration,
2430 N_Procedure_Call_Statement,
2431 N_Entry_Call_Statement))
2432 or else (Nkind (N) = N_Full_Type_Declaration
2433 and then not Is_Record_Type (Defining_Identifier (N)))
2435 -- In addition, this check only applies to source code, not to code
2436 -- generated by constraint checks.
2438 or else not Comes_From_Source (N)
2443 -- If a construct C has two or more direct constituents that are names
2444 -- or expressions whose evaluation may occur in an arbitrary order, at
2445 -- least one of which contains a function call with an in out or out
2446 -- parameter, then the construct is legal only if: for each name N that
2447 -- is passed as a parameter of mode in out or out to some inner function
2448 -- call C2 (not including the construct C itself), there is no other
2449 -- name anywhere within a direct constituent of the construct C other
2450 -- than the one containing C2, that is known to refer to the same
2451 -- object (RM 6.4.1(6.17/3)).
2455 Collect_Identifiers (Low_Bound (N));
2456 Collect_Identifiers (High_Bound (N));
2458 when N_Membership_Test
2465 Collect_Identifiers (Left_Opnd (N));
2467 if Present (Right_Opnd (N)) then
2468 Collect_Identifiers (Right_Opnd (N));
2471 if Nkind_In (N, N_In, N_Not_In)
2472 and then Present (Alternatives (N))
2474 Expr := First (Alternatives (N));
2475 while Present (Expr) loop
2476 Collect_Identifiers (Expr);
2483 when N_Full_Type_Declaration =>
2485 function Get_Record_Part (N : Node_Id) return Node_Id;
2486 -- Return the record part of this record type definition
2488 function Get_Record_Part (N : Node_Id) return Node_Id is
2489 Type_Def : constant Node_Id := Type_Definition (N);
2491 if Nkind (Type_Def) = N_Derived_Type_Definition then
2492 return Record_Extension_Part (Type_Def);
2496 end Get_Record_Part;
2499 Def_Id : Entity_Id := Defining_Identifier (N);
2500 Rec : Node_Id := Get_Record_Part (N);
2503 -- No need to perform any analysis if the record has no
2506 if No (Rec) or else No (Component_List (Rec)) then
2510 -- Collect the identifiers starting from the deepest
2511 -- derivation. Done to report the error in the deepest
2515 if Present (Component_List (Rec)) then
2516 Comp := First (Component_Items (Component_List (Rec)));
2517 while Present (Comp) loop
2518 if Nkind (Comp) = N_Component_Declaration
2519 and then Present (Expression (Comp))
2521 Collect_Identifiers (Expression (Comp));
2528 exit when No (Underlying_Type (Etype (Def_Id)))
2529 or else Base_Type (Underlying_Type (Etype (Def_Id)))
2532 Def_Id := Base_Type (Underlying_Type (Etype (Def_Id)));
2533 Rec := Get_Record_Part (Parent (Def_Id));
2537 when N_Entry_Call_Statement
2541 Id : constant Entity_Id := Get_Called_Entity (N);
2546 Formal := First_Formal (Id);
2547 Actual := First_Actual (N);
2548 while Present (Actual) and then Present (Formal) loop
2549 if Ekind_In (Formal, E_Out_Parameter,
2552 Collect_Identifiers (Actual);
2555 Next_Formal (Formal);
2556 Next_Actual (Actual);
2561 | N_Extension_Aggregate
2566 Comp_Expr : Node_Id;
2569 -- Handle the N_Others_Choice of array aggregates with static
2570 -- bounds. There is no need to perform this analysis in
2571 -- aggregates without static bounds since we cannot evaluate
2572 -- if the N_Others_Choice covers several elements. There is
2573 -- no need to handle the N_Others choice of record aggregates
2574 -- since at this stage it has been already expanded by
2575 -- Resolve_Record_Aggregate.
2577 if Is_Array_Type (Etype (N))
2578 and then Nkind (N) = N_Aggregate
2579 and then Present (Aggregate_Bounds (N))
2580 and then Compile_Time_Known_Bounds (Etype (N))
2581 and then Expr_Value (High_Bound (Aggregate_Bounds (N)))
2583 Expr_Value (Low_Bound (Aggregate_Bounds (N)))
2586 Count_Components : Uint := Uint_0;
2587 Num_Components : Uint;
2588 Others_Assoc : Node_Id;
2589 Others_Choice : Node_Id := Empty;
2590 Others_Box_Present : Boolean := False;
2593 -- Count positional associations
2595 if Present (Expressions (N)) then
2596 Comp_Expr := First (Expressions (N));
2597 while Present (Comp_Expr) loop
2598 Count_Components := Count_Components + 1;
2603 -- Count the rest of elements and locate the N_Others
2606 Assoc := First (Component_Associations (N));
2607 while Present (Assoc) loop
2608 Choice := First (Choices (Assoc));
2609 while Present (Choice) loop
2610 if Nkind (Choice) = N_Others_Choice then
2611 Others_Assoc := Assoc;
2612 Others_Choice := Choice;
2613 Others_Box_Present := Box_Present (Assoc);
2615 -- Count several components
2617 elsif Nkind_In (Choice, N_Range,
2618 N_Subtype_Indication)
2619 or else (Is_Entity_Name (Choice)
2620 and then Is_Type (Entity (Choice)))
2625 Get_Index_Bounds (Choice, L, H);
2627 (Compile_Time_Known_Value (L)
2628 and then Compile_Time_Known_Value (H));
2631 + Expr_Value (H) - Expr_Value (L) + 1;
2634 -- Count single component. No other case available
2635 -- since we are handling an aggregate with static
2639 pragma Assert (Is_OK_Static_Expression (Choice)
2640 or else Nkind (Choice) = N_Identifier
2641 or else Nkind (Choice) = N_Integer_Literal);
2643 Count_Components := Count_Components + 1;
2653 Expr_Value (High_Bound (Aggregate_Bounds (N))) -
2654 Expr_Value (Low_Bound (Aggregate_Bounds (N))) + 1;
2656 pragma Assert (Count_Components <= Num_Components);
2658 -- Handle the N_Others choice if it covers several
2661 if Present (Others_Choice)
2662 and then (Num_Components - Count_Components) > 1
2664 if not Others_Box_Present then
2666 -- At this stage, if expansion is active, the
2667 -- expression of the others choice has not been
2668 -- analyzed. Hence we generate a duplicate and
2669 -- we analyze it silently to have available the
2670 -- minimum decoration required to collect the
2673 if not Expander_Active then
2674 Comp_Expr := Expression (Others_Assoc);
2677 New_Copy_Tree (Expression (Others_Assoc));
2678 Preanalyze_Without_Errors (Comp_Expr);
2681 Collect_Identifiers (Comp_Expr);
2683 if Writable_Actuals_List /= No_Elist then
2685 -- As suggested by Robert, at current stage we
2686 -- report occurrences of this case as warnings.
2689 ("writable function parameter may affect "
2690 & "value in other component because order "
2691 & "of evaluation is unspecified??",
2692 Node (First_Elmt (Writable_Actuals_List)));
2698 -- For an array aggregate, a discrete_choice_list that has
2699 -- a nonstatic range is considered as two or more separate
2700 -- occurrences of the expression (RM 6.4.1(20/3)).
2702 elsif Is_Array_Type (Etype (N))
2703 and then Nkind (N) = N_Aggregate
2704 and then Present (Aggregate_Bounds (N))
2705 and then not Compile_Time_Known_Bounds (Etype (N))
2707 -- Collect identifiers found in the dynamic bounds
2710 Count_Components : Natural := 0;
2711 Low, High : Node_Id;
2714 Assoc := First (Component_Associations (N));
2715 while Present (Assoc) loop
2716 Choice := First (Choices (Assoc));
2717 while Present (Choice) loop
2718 if Nkind_In (Choice, N_Range,
2719 N_Subtype_Indication)
2720 or else (Is_Entity_Name (Choice)
2721 and then Is_Type (Entity (Choice)))
2723 Get_Index_Bounds (Choice, Low, High);
2725 if not Compile_Time_Known_Value (Low) then
2726 Collect_Identifiers (Low);
2728 if No (Aggr_Error_Node) then
2729 Aggr_Error_Node := Low;
2733 if not Compile_Time_Known_Value (High) then
2734 Collect_Identifiers (High);
2736 if No (Aggr_Error_Node) then
2737 Aggr_Error_Node := High;
2741 -- The RM rule is violated if there is more than
2742 -- a single choice in a component association.
2745 Count_Components := Count_Components + 1;
2747 if No (Aggr_Error_Node)
2748 and then Count_Components > 1
2750 Aggr_Error_Node := Choice;
2753 if not Compile_Time_Known_Value (Choice) then
2754 Collect_Identifiers (Choice);
2766 -- Handle ancestor part of extension aggregates
2768 if Nkind (N) = N_Extension_Aggregate then
2769 Collect_Identifiers (Ancestor_Part (N));
2772 -- Handle positional associations
2774 if Present (Expressions (N)) then
2775 Comp_Expr := First (Expressions (N));
2776 while Present (Comp_Expr) loop
2777 if not Is_OK_Static_Expression (Comp_Expr) then
2778 Collect_Identifiers (Comp_Expr);
2785 -- Handle discrete associations
2787 if Present (Component_Associations (N)) then
2788 Assoc := First (Component_Associations (N));
2789 while Present (Assoc) loop
2791 if not Box_Present (Assoc) then
2792 Choice := First (Choices (Assoc));
2793 while Present (Choice) loop
2795 -- For now we skip discriminants since it requires
2796 -- performing the analysis in two phases: first one
2797 -- analyzing discriminants and second one analyzing
2798 -- the rest of components since discriminants are
2799 -- evaluated prior to components: too much extra
2800 -- work to detect a corner case???
2802 if Nkind (Choice) in N_Has_Entity
2803 and then Present (Entity (Choice))
2804 and then Ekind (Entity (Choice)) = E_Discriminant
2808 elsif Box_Present (Assoc) then
2812 if not Analyzed (Expression (Assoc)) then
2814 New_Copy_Tree (Expression (Assoc));
2815 Set_Parent (Comp_Expr, Parent (N));
2816 Preanalyze_Without_Errors (Comp_Expr);
2818 Comp_Expr := Expression (Assoc);
2821 Collect_Identifiers (Comp_Expr);
2837 -- No further action needed if we already reported an error
2839 if Present (Error_Node) then
2843 -- Check violation of RM 6.20/3 in aggregates
2845 if Present (Aggr_Error_Node)
2846 and then Writable_Actuals_List /= No_Elist
2849 ("value may be affected by call in other component because they "
2850 & "are evaluated in unspecified order",
2851 Node (First_Elmt (Writable_Actuals_List)));
2855 -- Check if some writable argument of a function is referenced
2857 if Writable_Actuals_List /= No_Elist
2858 and then Identifiers_List /= No_Elist
2865 Elmt_1 := First_Elmt (Writable_Actuals_List);
2866 while Present (Elmt_1) loop
2867 Elmt_2 := First_Elmt (Identifiers_List);
2868 while Present (Elmt_2) loop
2869 if Entity (Node (Elmt_1)) = Entity (Node (Elmt_2)) then
2870 case Nkind (Parent (Node (Elmt_2))) is
2872 | N_Component_Association
2873 | N_Component_Declaration
2876 ("value may be affected by call in other "
2877 & "component because they are evaluated "
2878 & "in unspecified order",
2885 ("value may be affected by call in other "
2886 & "alternative because they are evaluated "
2887 & "in unspecified order",
2892 ("value of actual may be affected by call in "
2893 & "other actual because they are evaluated "
2894 & "in unspecified order",
2906 end Check_Function_Writable_Actuals;
2908 --------------------------------
2909 -- Check_Implicit_Dereference --
2910 --------------------------------
2912 procedure Check_Implicit_Dereference (N : Node_Id; Typ : Entity_Id) is
2918 if Nkind (N) = N_Indexed_Component
2919 and then Present (Generalized_Indexing (N))
2921 Nam := Generalized_Indexing (N);
2926 if Ada_Version < Ada_2012
2927 or else not Has_Implicit_Dereference (Base_Type (Typ))
2931 elsif not Comes_From_Source (N)
2932 and then Nkind (N) /= N_Indexed_Component
2936 elsif Is_Entity_Name (Nam) and then Is_Type (Entity (Nam)) then
2940 Disc := First_Discriminant (Typ);
2941 while Present (Disc) loop
2942 if Has_Implicit_Dereference (Disc) then
2943 Desig := Designated_Type (Etype (Disc));
2944 Add_One_Interp (Nam, Disc, Desig);
2946 -- If the node is a generalized indexing, add interpretation
2947 -- to that node as well, for subsequent resolution.
2949 if Nkind (N) = N_Indexed_Component then
2950 Add_One_Interp (N, Disc, Desig);
2953 -- If the operation comes from a generic unit and the context
2954 -- is a selected component, the selector name may be global
2955 -- and set in the instance already. Remove the entity to
2956 -- force resolution of the selected component, and the
2957 -- generation of an explicit dereference if needed.
2960 and then Nkind (Parent (Nam)) = N_Selected_Component
2962 Set_Entity (Selector_Name (Parent (Nam)), Empty);
2968 Next_Discriminant (Disc);
2971 end Check_Implicit_Dereference;
2973 ----------------------------------
2974 -- Check_Internal_Protected_Use --
2975 ----------------------------------
2977 procedure Check_Internal_Protected_Use (N : Node_Id; Nam : Entity_Id) is
2985 while Present (S) loop
2986 if S = Standard_Standard then
2989 elsif Ekind (S) = E_Function
2990 and then Ekind (Scope (S)) = E_Protected_Type
3000 and then Scope (Nam) = Prot
3001 and then Ekind (Nam) /= E_Function
3003 -- An indirect function call (e.g. a callback within a protected
3004 -- function body) is not statically illegal. If the access type is
3005 -- anonymous and is the type of an access parameter, the scope of Nam
3006 -- will be the protected type, but it is not a protected operation.
3008 if Ekind (Nam) = E_Subprogram_Type
3009 and then Nkind (Associated_Node_For_Itype (Nam)) =
3010 N_Function_Specification
3014 elsif Nkind (N) = N_Subprogram_Renaming_Declaration then
3016 ("within protected function cannot use protected procedure in "
3017 & "renaming or as generic actual", N);
3019 elsif Nkind (N) = N_Attribute_Reference then
3021 ("within protected function cannot take access of protected "
3026 ("within protected function, protected object is constant", N);
3028 ("\cannot call operation that may modify it", N);
3032 -- Verify that an internal call does not appear within a precondition
3033 -- of a protected operation. This implements AI12-0166.
3034 -- The precondition aspect has been rewritten as a pragma Precondition
3035 -- and we check whether the scope of the called subprogram is the same
3036 -- as that of the entity to which the aspect applies.
3038 if Convention (Nam) = Convention_Protected then
3044 while Present (P) loop
3045 if Nkind (P) = N_Pragma
3046 and then Chars (Pragma_Identifier (P)) = Name_Precondition
3047 and then From_Aspect_Specification (P)
3049 Scope (Entity (Corresponding_Aspect (P))) = Scope (Nam)
3052 ("internal call cannot appear in precondition of "
3053 & "protected operation", N);
3056 elsif Nkind (P) = N_Pragma
3057 and then Chars (Pragma_Identifier (P)) = Name_Contract_Cases
3059 -- Check whether call is in a case guard. It is legal in a
3063 while Present (P) loop
3064 if Nkind (Parent (P)) = N_Component_Association
3065 and then P /= Expression (Parent (P))
3068 ("internal call cannot appear in case guard in a "
3069 & "contract case", N);
3077 elsif Nkind (P) = N_Parameter_Specification
3078 and then Scope (Current_Scope) = Scope (Nam)
3079 and then Nkind_In (Parent (P), N_Entry_Declaration,
3080 N_Subprogram_Declaration)
3083 ("internal call cannot appear in default for formal of "
3084 & "protected operation", N);
3092 end Check_Internal_Protected_Use;
3094 ---------------------------------------
3095 -- Check_Later_Vs_Basic_Declarations --
3096 ---------------------------------------
3098 procedure Check_Later_Vs_Basic_Declarations
3100 During_Parsing : Boolean)
3102 Body_Sloc : Source_Ptr;
3105 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
3106 -- Return whether Decl is considered as a declarative item.
3107 -- When During_Parsing is True, the semantics of Ada 83 is followed.
3108 -- When During_Parsing is False, the semantics of SPARK is followed.
3110 -------------------------------
3111 -- Is_Later_Declarative_Item --
3112 -------------------------------
3114 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
3116 if Nkind (Decl) in N_Later_Decl_Item then
3119 elsif Nkind (Decl) = N_Pragma then
3122 elsif During_Parsing then
3125 -- In SPARK, a package declaration is not considered as a later
3126 -- declarative item.
3128 elsif Nkind (Decl) = N_Package_Declaration then
3131 -- In SPARK, a renaming is considered as a later declarative item
3133 elsif Nkind (Decl) in N_Renaming_Declaration then
3139 end Is_Later_Declarative_Item;
3141 -- Start of processing for Check_Later_Vs_Basic_Declarations
3144 Decl := First (Decls);
3146 -- Loop through sequence of basic declarative items
3148 Outer : while Present (Decl) loop
3149 if not Nkind_In (Decl, N_Subprogram_Body, N_Package_Body, N_Task_Body)
3150 and then Nkind (Decl) not in N_Body_Stub
3154 -- Once a body is encountered, we only allow later declarative
3155 -- items. The inner loop checks the rest of the list.
3158 Body_Sloc := Sloc (Decl);
3160 Inner : while Present (Decl) loop
3161 if not Is_Later_Declarative_Item (Decl) then
3162 if During_Parsing then
3163 if Ada_Version = Ada_83 then
3164 Error_Msg_Sloc := Body_Sloc;
3166 ("(Ada 83) decl cannot appear after body#", Decl);
3169 Error_Msg_Sloc := Body_Sloc;
3170 Check_SPARK_05_Restriction
3171 ("decl cannot appear after body#", Decl);
3179 end Check_Later_Vs_Basic_Declarations;
3181 ---------------------------
3182 -- Check_No_Hidden_State --
3183 ---------------------------
3185 procedure Check_No_Hidden_State (Id : Entity_Id) is
3186 Context : Entity_Id := Empty;
3187 Not_Visible : Boolean := False;
3191 pragma Assert (Ekind_In (Id, E_Abstract_State, E_Variable));
3193 -- Find the proper context where the object or state appears
3196 while Present (Scop) loop
3199 -- Keep track of the context's visibility
3201 Not_Visible := Not_Visible or else In_Private_Part (Context);
3203 -- Prevent the search from going too far
3205 if Context = Standard_Standard then
3208 -- Objects and states that appear immediately within a subprogram or
3209 -- inside a construct nested within a subprogram do not introduce a
3210 -- hidden state. They behave as local variable declarations.
3212 elsif Is_Subprogram (Context) then
3215 -- When examining a package body, use the entity of the spec as it
3216 -- carries the abstract state declarations.
3218 elsif Ekind (Context) = E_Package_Body then
3219 Context := Spec_Entity (Context);
3222 -- Stop the traversal when a package subject to a null abstract state
3225 if Ekind_In (Context, E_Generic_Package, E_Package)
3226 and then Has_Null_Abstract_State (Context)
3231 Scop := Scope (Scop);
3234 -- At this point we know that there is at least one package with a null
3235 -- abstract state in visibility. Emit an error message unconditionally
3236 -- if the entity being processed is a state because the placement of the
3237 -- related package is irrelevant. This is not the case for objects as
3238 -- the intermediate context matters.
3240 if Present (Context)
3241 and then (Ekind (Id) = E_Abstract_State or else Not_Visible)
3243 Error_Msg_N ("cannot introduce hidden state &", Id);
3244 Error_Msg_NE ("\package & has null abstract state", Id, Context);
3246 end Check_No_Hidden_State;
3248 ----------------------------------------
3249 -- Check_Nonvolatile_Function_Profile --
3250 ----------------------------------------
3252 procedure Check_Nonvolatile_Function_Profile (Func_Id : Entity_Id) is
3256 -- Inspect all formal parameters
3258 Formal := First_Formal (Func_Id);
3259 while Present (Formal) loop
3260 if Is_Effectively_Volatile (Etype (Formal)) then
3262 ("nonvolatile function & cannot have a volatile parameter",
3266 Next_Formal (Formal);
3269 -- Inspect the return type
3271 if Is_Effectively_Volatile (Etype (Func_Id)) then
3273 ("nonvolatile function & cannot have a volatile return type",
3274 Result_Definition (Parent (Func_Id)), Func_Id);
3276 end Check_Nonvolatile_Function_Profile;
3278 -----------------------------
3279 -- Check_Part_Of_Reference --
3280 -----------------------------
3282 procedure Check_Part_Of_Reference (Var_Id : Entity_Id; Ref : Node_Id) is
3283 Conc_Obj : constant Entity_Id := Encapsulating_State (Var_Id);
3285 OK_Use : Boolean := False;
3288 Spec_Id : Entity_Id;
3291 -- Traverse the parent chain looking for a suitable context for the
3292 -- reference to the concurrent constituent.
3294 Par := Parent (Ref);
3295 while Present (Par) loop
3296 if Nkind (Par) = N_Pragma then
3297 Prag_Nam := Pragma_Name (Par);
3299 -- A concurrent constituent is allowed to appear in pragmas
3300 -- Initial_Condition and Initializes as this is part of the
3301 -- elaboration checks for the constituent (SPARK RM 9.3).
3303 if Nam_In (Prag_Nam, Name_Initial_Condition, Name_Initializes) then
3307 -- When the reference appears within pragma Depends or Global,
3308 -- check whether the pragma applies to a single task type. Note
3309 -- that the pragma is not encapsulated by the type definition,
3310 -- but this is still a valid context.
3312 elsif Nam_In (Prag_Nam, Name_Depends, Name_Global) then
3313 Decl := Find_Related_Declaration_Or_Body (Par);
3315 if Nkind (Decl) = N_Object_Declaration
3316 and then Defining_Entity (Decl) = Conc_Obj
3323 -- The reference appears somewhere in the definition of the single
3324 -- protected/task type (SPARK RM 9.3).
3326 elsif Nkind_In (Par, N_Single_Protected_Declaration,
3327 N_Single_Task_Declaration)
3328 and then Defining_Entity (Par) = Conc_Obj
3333 -- The reference appears within the expanded declaration or the body
3334 -- of the single protected/task type (SPARK RM 9.3).
3336 elsif Nkind_In (Par, N_Protected_Body,
3337 N_Protected_Type_Declaration,
3339 N_Task_Type_Declaration)
3341 Spec_Id := Unique_Defining_Entity (Par);
3343 if Present (Anonymous_Object (Spec_Id))
3344 and then Anonymous_Object (Spec_Id) = Conc_Obj
3350 -- The reference has been relocated within an internally generated
3351 -- package or subprogram. Assume that the reference is legal as the
3352 -- real check was already performed in the original context of the
3355 elsif Nkind_In (Par, N_Package_Body,
3356 N_Package_Declaration,
3358 N_Subprogram_Declaration)
3359 and then not Comes_From_Source (Par)
3361 -- Continue to examine the context if the reference appears in a
3362 -- subprogram body which was previously an expression function,
3363 -- unless this is during preanalysis (when In_Spec_Expression is
3364 -- True), as the body may not yet be inserted in the tree.
3366 if Nkind (Par) = N_Subprogram_Body
3367 and then Was_Expression_Function (Par)
3368 and then not In_Spec_Expression
3372 -- Otherwise the reference is legal
3379 -- The reference has been relocated to an inlined body for GNATprove.
3380 -- Assume that the reference is legal as the real check was already
3381 -- performed in the original context of the reference.
3383 elsif GNATprove_Mode
3384 and then Nkind (Par) = N_Subprogram_Body
3385 and then Chars (Defining_Entity (Par)) = Name_uParent
3391 Par := Parent (Par);
3394 -- The reference is illegal as it appears outside the definition or
3395 -- body of the single protected/task type.
3399 ("reference to variable & cannot appear in this context",
3401 Error_Msg_Name_1 := Chars (Var_Id);
3403 if Is_Single_Protected_Object (Conc_Obj) then
3405 ("\% is constituent of single protected type &", Ref, Conc_Obj);
3409 ("\% is constituent of single task type &", Ref, Conc_Obj);
3412 end Check_Part_Of_Reference;
3414 ------------------------------------------
3415 -- Check_Potentially_Blocking_Operation --
3416 ------------------------------------------
3418 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
3422 -- N is one of the potentially blocking operations listed in 9.5.1(8).
3423 -- When pragma Detect_Blocking is active, the run time will raise
3424 -- Program_Error. Here we only issue a warning, since we generally
3425 -- support the use of potentially blocking operations in the absence
3428 -- Indirect blocking through a subprogram call cannot be diagnosed
3429 -- statically without interprocedural analysis, so we do not attempt
3432 S := Scope (Current_Scope);
3433 while Present (S) and then S /= Standard_Standard loop
3434 if Is_Protected_Type (S) then
3436 ("potentially blocking operation in protected operation??", N);
3442 end Check_Potentially_Blocking_Operation;
3444 ------------------------------------
3445 -- Check_Previous_Null_Procedure --
3446 ------------------------------------
3448 procedure Check_Previous_Null_Procedure
3453 if Ekind (Prev) = E_Procedure
3454 and then Nkind (Parent (Prev)) = N_Procedure_Specification
3455 and then Null_Present (Parent (Prev))
3457 Error_Msg_Sloc := Sloc (Prev);
3459 ("declaration cannot complete previous null procedure#", Decl);
3461 end Check_Previous_Null_Procedure;
3463 ---------------------------------
3464 -- Check_Result_And_Post_State --
3465 ---------------------------------
3467 procedure Check_Result_And_Post_State (Subp_Id : Entity_Id) is
3468 procedure Check_Result_And_Post_State_In_Pragma
3470 Result_Seen : in out Boolean);
3471 -- Determine whether pragma Prag mentions attribute 'Result and whether
3472 -- the pragma contains an expression that evaluates differently in pre-
3473 -- and post-state. Prag is a [refined] postcondition or a contract-cases
3474 -- pragma. Result_Seen is set when the pragma mentions attribute 'Result
3476 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean;
3477 -- Determine whether subprogram Subp_Id contains at least one IN OUT
3478 -- formal parameter.
3480 -------------------------------------------
3481 -- Check_Result_And_Post_State_In_Pragma --
3482 -------------------------------------------
3484 procedure Check_Result_And_Post_State_In_Pragma
3486 Result_Seen : in out Boolean)
3488 procedure Check_Conjunct (Expr : Node_Id);
3489 -- Check an individual conjunct in a conjunction of Boolean
3490 -- expressions, connected by "and" or "and then" operators.
3492 procedure Check_Conjuncts (Expr : Node_Id);
3493 -- Apply the post-state check to every conjunct in an expression, in
3494 -- case this is a conjunction of Boolean expressions. Otherwise apply
3495 -- it to the expression as a whole.
3497 procedure Check_Expression (Expr : Node_Id);
3498 -- Perform the 'Result and post-state checks on a given expression
3500 function Is_Function_Result (N : Node_Id) return Traverse_Result;
3501 -- Attempt to find attribute 'Result in a subtree denoted by N
3503 function Is_Trivial_Boolean (N : Node_Id) return Boolean;
3504 -- Determine whether source node N denotes "True" or "False"
3506 function Mentions_Post_State (N : Node_Id) return Boolean;
3507 -- Determine whether a subtree denoted by N mentions any construct
3508 -- that denotes a post-state.
3510 procedure Check_Function_Result is
3511 new Traverse_Proc (Is_Function_Result);
3513 --------------------
3514 -- Check_Conjunct --
3515 --------------------
3517 procedure Check_Conjunct (Expr : Node_Id) is
3518 function Adjust_Message (Msg : String) return String;
3519 -- Prepend a prefix to the input message Msg denoting that the
3520 -- message applies to a conjunct in the expression, when this
3523 function Applied_On_Conjunct return Boolean;
3524 -- Returns True if the message applies to a conjunct in the
3525 -- expression, instead of the whole expression.
3527 function Has_Global_Output (Subp : Entity_Id) return Boolean;
3528 -- Returns True if Subp has an output in its Global contract
3530 function Has_No_Output (Subp : Entity_Id) return Boolean;
3531 -- Returns True if Subp has no declared output: no function
3532 -- result, no output parameter, and no output in its Global
3535 --------------------
3536 -- Adjust_Message --
3537 --------------------
3539 function Adjust_Message (Msg : String) return String is
3541 if Applied_On_Conjunct then
3542 return "conjunct in " & Msg;
3548 -------------------------
3549 -- Applied_On_Conjunct --
3550 -------------------------
3552 function Applied_On_Conjunct return Boolean is
3554 -- Expr is the conjunct of an enclosing "and" expression
3556 return Nkind (Parent (Expr)) in N_Subexpr
3558 -- or Expr is a conjunct of an enclosing "and then"
3559 -- expression in a postcondition aspect that was split into
3560 -- multiple pragmas. The first conjunct has the "and then"
3561 -- expression as Original_Node, and other conjuncts have
3562 -- Split_PCC set to True.
3564 or else Nkind (Original_Node (Expr)) = N_And_Then
3565 or else Split_PPC (Prag);
3566 end Applied_On_Conjunct;
3568 -----------------------
3569 -- Has_Global_Output --
3570 -----------------------
3572 function Has_Global_Output (Subp : Entity_Id) return Boolean is
3573 Global : constant Node_Id := Get_Pragma (Subp, Pragma_Global);
3582 List := Expression (Get_Argument (Global, Subp));
3584 -- Empty list (no global items) or single global item
3585 -- declaration (only input items).
3587 if Nkind_In (List, N_Null,
3590 N_Selected_Component)
3594 -- Simple global list (only input items) or moded global list
3597 elsif Nkind (List) = N_Aggregate then
3598 if Present (Expressions (List)) then
3602 Assoc := First (Component_Associations (List));
3603 while Present (Assoc) loop
3604 if Chars (First (Choices (Assoc))) /= Name_Input then
3614 -- To accommodate partial decoration of disabled SPARK
3615 -- features, this routine may be called with illegal input.
3616 -- If this is the case, do not raise Program_Error.
3621 end Has_Global_Output;
3627 function Has_No_Output (Subp : Entity_Id) return Boolean is
3631 -- A function has its result as output
3633 if Ekind (Subp) = E_Function then
3637 -- An OUT or IN OUT parameter is an output
3639 Param := First_Formal (Subp);
3640 while Present (Param) loop
3641 if Ekind_In (Param, E_Out_Parameter, E_In_Out_Parameter) then
3645 Next_Formal (Param);
3648 -- An item of mode Output or In_Out in the Global contract is
3651 if Has_Global_Output (Subp) then
3661 -- Error node when reporting a warning on a (refined)
3664 -- Start of processing for Check_Conjunct
3667 if Applied_On_Conjunct then
3673 -- Do not report missing reference to outcome in postcondition if
3674 -- either the postcondition is trivially True or False, or if the
3675 -- subprogram is ghost and has no declared output.
3677 if not Is_Trivial_Boolean (Expr)
3678 and then not Mentions_Post_State (Expr)
3679 and then not (Is_Ghost_Entity (Subp_Id)
3680 and then Has_No_Output (Subp_Id))
3682 if Pragma_Name (Prag) = Name_Contract_Cases then
3683 Error_Msg_NE (Adjust_Message
3684 ("contract case does not check the outcome of calling "
3685 & "&?T?"), Expr, Subp_Id);
3687 elsif Pragma_Name (Prag) = Name_Refined_Post then
3688 Error_Msg_NE (Adjust_Message
3689 ("refined postcondition does not check the outcome of "
3690 & "calling &?T?"), Err_Node, Subp_Id);
3693 Error_Msg_NE (Adjust_Message
3694 ("postcondition does not check the outcome of calling "
3695 & "&?T?"), Err_Node, Subp_Id);
3700 ---------------------
3701 -- Check_Conjuncts --
3702 ---------------------
3704 procedure Check_Conjuncts (Expr : Node_Id) is
3706 if Nkind_In (Expr, N_Op_And, N_And_Then) then
3707 Check_Conjuncts (Left_Opnd (Expr));
3708 Check_Conjuncts (Right_Opnd (Expr));
3710 Check_Conjunct (Expr);
3712 end Check_Conjuncts;
3714 ----------------------
3715 -- Check_Expression --
3716 ----------------------
3718 procedure Check_Expression (Expr : Node_Id) is
3720 if not Is_Trivial_Boolean (Expr) then
3721 Check_Function_Result (Expr);
3722 Check_Conjuncts (Expr);
3724 end Check_Expression;
3726 ------------------------
3727 -- Is_Function_Result --
3728 ------------------------
3730 function Is_Function_Result (N : Node_Id) return Traverse_Result is
3732 if Is_Attribute_Result (N) then
3733 Result_Seen := True;
3736 -- Continue the traversal
3741 end Is_Function_Result;
3743 ------------------------
3744 -- Is_Trivial_Boolean --
3745 ------------------------
3747 function Is_Trivial_Boolean (N : Node_Id) return Boolean is
3750 Comes_From_Source (N)
3751 and then Is_Entity_Name (N)
3752 and then (Entity (N) = Standard_True
3754 Entity (N) = Standard_False);
3755 end Is_Trivial_Boolean;
3757 -------------------------
3758 -- Mentions_Post_State --
3759 -------------------------
3761 function Mentions_Post_State (N : Node_Id) return Boolean is
3762 Post_State_Seen : Boolean := False;
3764 function Is_Post_State (N : Node_Id) return Traverse_Result;
3765 -- Attempt to find a construct that denotes a post-state. If this
3766 -- is the case, set flag Post_State_Seen.
3772 function Is_Post_State (N : Node_Id) return Traverse_Result is
3776 if Nkind_In (N, N_Explicit_Dereference, N_Function_Call) then
3777 Post_State_Seen := True;
3780 elsif Nkind_In (N, N_Expanded_Name, N_Identifier) then
3783 -- Treat an undecorated reference as OK
3787 -- A reference to an assignable entity is considered a
3788 -- change in the post-state of a subprogram.
3790 or else Ekind_In (Ent, E_Generic_In_Out_Parameter,
3795 -- The reference may be modified through a dereference
3797 or else (Is_Access_Type (Etype (Ent))
3798 and then Nkind (Parent (N)) =
3799 N_Selected_Component)
3801 Post_State_Seen := True;
3805 elsif Nkind (N) = N_Attribute_Reference then
3806 if Attribute_Name (N) = Name_Old then
3809 elsif Attribute_Name (N) = Name_Result then
3810 Post_State_Seen := True;
3818 procedure Find_Post_State is new Traverse_Proc (Is_Post_State);
3820 -- Start of processing for Mentions_Post_State
3823 Find_Post_State (N);
3825 return Post_State_Seen;
3826 end Mentions_Post_State;
3830 Expr : constant Node_Id :=
3832 (First (Pragma_Argument_Associations (Prag)));
3833 Nam : constant Name_Id := Pragma_Name (Prag);
3836 -- Start of processing for Check_Result_And_Post_State_In_Pragma
3839 -- Examine all consequences
3841 if Nam = Name_Contract_Cases then
3842 CCase := First (Component_Associations (Expr));
3843 while Present (CCase) loop
3844 Check_Expression (Expression (CCase));
3849 -- Examine the expression of a postcondition
3851 else pragma Assert (Nam_In (Nam, Name_Postcondition,
3852 Name_Refined_Post));
3853 Check_Expression (Expr);
3855 end Check_Result_And_Post_State_In_Pragma;
3857 --------------------------
3858 -- Has_In_Out_Parameter --
3859 --------------------------
3861 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean is
3865 -- Traverse the formals looking for an IN OUT parameter
3867 Formal := First_Formal (Subp_Id);
3868 while Present (Formal) loop
3869 if Ekind (Formal) = E_In_Out_Parameter then
3873 Next_Formal (Formal);
3877 end Has_In_Out_Parameter;
3881 Items : constant Node_Id := Contract (Subp_Id);
3882 Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id);
3883 Case_Prag : Node_Id := Empty;
3884 Post_Prag : Node_Id := Empty;
3886 Seen_In_Case : Boolean := False;
3887 Seen_In_Post : Boolean := False;
3888 Spec_Id : Entity_Id;
3890 -- Start of processing for Check_Result_And_Post_State
3893 -- The lack of attribute 'Result or a post-state is classified as a
3894 -- suspicious contract. Do not perform the check if the corresponding
3895 -- swich is not set.
3897 if not Warn_On_Suspicious_Contract then
3900 -- Nothing to do if there is no contract
3902 elsif No (Items) then
3906 -- Retrieve the entity of the subprogram spec (if any)
3908 if Nkind (Subp_Decl) = N_Subprogram_Body
3909 and then Present (Corresponding_Spec (Subp_Decl))
3911 Spec_Id := Corresponding_Spec (Subp_Decl);
3913 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
3914 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
3916 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
3922 -- Examine all postconditions for attribute 'Result and a post-state
3924 Prag := Pre_Post_Conditions (Items);
3925 while Present (Prag) loop
3926 if Nam_In (Pragma_Name_Unmapped (Prag),
3927 Name_Postcondition, Name_Refined_Post)
3928 and then not Error_Posted (Prag)
3931 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Post);
3934 Prag := Next_Pragma (Prag);
3937 -- Examine the contract cases of the subprogram for attribute 'Result
3938 -- and a post-state.
3940 Prag := Contract_Test_Cases (Items);
3941 while Present (Prag) loop
3942 if Pragma_Name (Prag) = Name_Contract_Cases
3943 and then not Error_Posted (Prag)
3946 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Case);
3949 Prag := Next_Pragma (Prag);
3952 -- Do not emit any errors if the subprogram is not a function
3954 if not Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
3957 -- Regardless of whether the function has postconditions or contract
3958 -- cases, or whether they mention attribute 'Result, an IN OUT formal
3959 -- parameter is always treated as a result.
3961 elsif Has_In_Out_Parameter (Spec_Id) then
3964 -- The function has both a postcondition and contract cases and they do
3965 -- not mention attribute 'Result.
3967 elsif Present (Case_Prag)
3968 and then not Seen_In_Case
3969 and then Present (Post_Prag)
3970 and then not Seen_In_Post
3973 ("neither postcondition nor contract cases mention function "
3974 & "result?T?", Post_Prag);
3976 -- The function has contract cases only and they do not mention
3977 -- attribute 'Result.
3979 elsif Present (Case_Prag) and then not Seen_In_Case then
3980 Error_Msg_N ("contract cases do not mention result?T?", Case_Prag);
3982 -- The function has postconditions only and they do not mention
3983 -- attribute 'Result.
3985 elsif Present (Post_Prag) and then not Seen_In_Post then
3987 ("postcondition does not mention function result?T?", Post_Prag);
3989 end Check_Result_And_Post_State;
3991 -----------------------------
3992 -- Check_State_Refinements --
3993 -----------------------------
3995 procedure Check_State_Refinements
3997 Is_Main_Unit : Boolean := False)
3999 procedure Check_Package (Pack : Node_Id);
4000 -- Verify that all abstract states of a [generic] package denoted by its
4001 -- declarative node Pack have proper refinement. Recursively verify the
4002 -- visible and private declarations of the [generic] package for other
4005 procedure Check_Packages_In (Decls : List_Id);
4006 -- Seek out [generic] package declarations within declarative list Decls
4007 -- and verify the status of their abstract state refinement.
4009 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean;
4010 -- Determine whether construct N is subject to pragma SPARK_Mode Off
4016 procedure Check_Package (Pack : Node_Id) is
4017 Body_Id : constant Entity_Id := Corresponding_Body (Pack);
4018 Spec : constant Node_Id := Specification (Pack);
4019 States : constant Elist_Id :=
4020 Abstract_States (Defining_Entity (Pack));
4022 State_Elmt : Elmt_Id;
4023 State_Id : Entity_Id;
4026 -- Do not verify proper state refinement when the package is subject
4027 -- to pragma SPARK_Mode Off because this disables the requirement for
4028 -- state refinement.
4030 if SPARK_Mode_Is_Off (Pack) then
4033 -- State refinement can only occur in a completing packge body. Do
4034 -- not verify proper state refinement when the body is subject to
4035 -- pragma SPARK_Mode Off because this disables the requirement for
4036 -- state refinement.
4038 elsif Present (Body_Id)
4039 and then SPARK_Mode_Is_Off (Unit_Declaration_Node (Body_Id))
4043 -- Do not verify proper state refinement when the package is an
4044 -- instance as this check was already performed in the generic.
4046 elsif Present (Generic_Parent (Spec)) then
4049 -- Otherwise examine the contents of the package
4052 if Present (States) then
4053 State_Elmt := First_Elmt (States);
4054 while Present (State_Elmt) loop
4055 State_Id := Node (State_Elmt);
4057 -- Emit an error when a non-null state lacks any form of
4060 if not Is_Null_State (State_Id)
4061 and then not Has_Null_Refinement (State_Id)
4062 and then not Has_Non_Null_Refinement (State_Id)
4064 Error_Msg_N ("state & requires refinement", State_Id);
4067 Next_Elmt (State_Elmt);
4071 Check_Packages_In (Visible_Declarations (Spec));
4072 Check_Packages_In (Private_Declarations (Spec));
4076 -----------------------
4077 -- Check_Packages_In --
4078 -----------------------
4080 procedure Check_Packages_In (Decls : List_Id) is
4084 if Present (Decls) then
4085 Decl := First (Decls);
4086 while Present (Decl) loop
4087 if Nkind_In (Decl, N_Generic_Package_Declaration,
4088 N_Package_Declaration)
4090 Check_Package (Decl);
4096 end Check_Packages_In;
4098 -----------------------
4099 -- SPARK_Mode_Is_Off --
4100 -----------------------
4102 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean is
4103 Id : constant Entity_Id := Defining_Entity (N);
4104 Prag : constant Node_Id := SPARK_Pragma (Id);
4107 -- Default the mode to "off" when the context is an instance and all
4108 -- SPARK_Mode pragmas found within are to be ignored.
4110 if Ignore_SPARK_Mode_Pragmas (Id) then
4116 and then Get_SPARK_Mode_From_Annotation (Prag) = Off;
4118 end SPARK_Mode_Is_Off;
4120 -- Start of processing for Check_State_Refinements
4123 -- A block may declare a nested package
4125 if Nkind (Context) = N_Block_Statement then
4126 Check_Packages_In (Declarations (Context));
4128 -- An entry, protected, subprogram, or task body may declare a nested
4131 elsif Nkind_In (Context, N_Entry_Body,
4136 -- Do not verify proper state refinement when the body is subject to
4137 -- pragma SPARK_Mode Off because this disables the requirement for
4138 -- state refinement.
4140 if not SPARK_Mode_Is_Off (Context) then
4141 Check_Packages_In (Declarations (Context));
4144 -- A package body may declare a nested package
4146 elsif Nkind (Context) = N_Package_Body then
4147 Check_Package (Unit_Declaration_Node (Corresponding_Spec (Context)));
4149 -- Do not verify proper state refinement when the body is subject to
4150 -- pragma SPARK_Mode Off because this disables the requirement for
4151 -- state refinement.
4153 if not SPARK_Mode_Is_Off (Context) then
4154 Check_Packages_In (Declarations (Context));
4157 -- A library level [generic] package may declare a nested package
4159 elsif Nkind_In (Context, N_Generic_Package_Declaration,
4160 N_Package_Declaration)
4161 and then Is_Main_Unit
4163 Check_Package (Context);
4165 end Check_State_Refinements;
4167 ------------------------------
4168 -- Check_Unprotected_Access --
4169 ------------------------------
4171 procedure Check_Unprotected_Access
4175 Cont_Encl_Typ : Entity_Id;
4176 Pref_Encl_Typ : Entity_Id;
4178 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
4179 -- Check whether Obj is a private component of a protected object.
4180 -- Return the protected type where the component resides, Empty
4183 function Is_Public_Operation return Boolean;
4184 -- Verify that the enclosing operation is callable from outside the
4185 -- protected object, to minimize false positives.
4187 ------------------------------
4188 -- Enclosing_Protected_Type --
4189 ------------------------------
4191 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
4193 if Is_Entity_Name (Obj) then
4195 Ent : Entity_Id := Entity (Obj);
4198 -- The object can be a renaming of a private component, use
4199 -- the original record component.
4201 if Is_Prival (Ent) then
4202 Ent := Prival_Link (Ent);
4205 if Is_Protected_Type (Scope (Ent)) then
4211 -- For indexed and selected components, recursively check the prefix
4213 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
4214 return Enclosing_Protected_Type (Prefix (Obj));
4216 -- The object does not denote a protected component
4221 end Enclosing_Protected_Type;
4223 -------------------------
4224 -- Is_Public_Operation --
4225 -------------------------
4227 function Is_Public_Operation return Boolean is
4233 while Present (S) and then S /= Pref_Encl_Typ loop
4234 if Scope (S) = Pref_Encl_Typ then
4235 E := First_Entity (Pref_Encl_Typ);
4237 and then E /= First_Private_Entity (Pref_Encl_Typ)
4251 end Is_Public_Operation;
4253 -- Start of processing for Check_Unprotected_Access
4256 if Nkind (Expr) = N_Attribute_Reference
4257 and then Attribute_Name (Expr) = Name_Unchecked_Access
4259 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
4260 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
4262 -- Check whether we are trying to export a protected component to a
4263 -- context with an equal or lower access level.
4265 if Present (Pref_Encl_Typ)
4266 and then No (Cont_Encl_Typ)
4267 and then Is_Public_Operation
4268 and then Scope_Depth (Pref_Encl_Typ) >=
4269 Object_Access_Level (Context)
4272 ("??possible unprotected access to protected data", Expr);
4275 end Check_Unprotected_Access;
4277 ------------------------------
4278 -- Check_Unused_Body_States --
4279 ------------------------------
4281 procedure Check_Unused_Body_States (Body_Id : Entity_Id) is
4282 procedure Process_Refinement_Clause
4285 -- Inspect all constituents of refinement clause Clause and remove any
4286 -- matches from body state list States.
4288 procedure Report_Unused_Body_States (States : Elist_Id);
4289 -- Emit errors for each abstract state or object found in list States
4291 -------------------------------
4292 -- Process_Refinement_Clause --
4293 -------------------------------
4295 procedure Process_Refinement_Clause
4299 procedure Process_Constituent (Constit : Node_Id);
4300 -- Remove constituent Constit from body state list States
4302 -------------------------
4303 -- Process_Constituent --
4304 -------------------------
4306 procedure Process_Constituent (Constit : Node_Id) is
4307 Constit_Id : Entity_Id;
4310 -- Guard against illegal constituents. Only abstract states and
4311 -- objects can appear on the right hand side of a refinement.
4313 if Is_Entity_Name (Constit) then
4314 Constit_Id := Entity_Of (Constit);
4316 if Present (Constit_Id)
4317 and then Ekind_In (Constit_Id, E_Abstract_State,
4321 Remove (States, Constit_Id);
4324 end Process_Constituent;
4330 -- Start of processing for Process_Refinement_Clause
4333 if Nkind (Clause) = N_Component_Association then
4334 Constit := Expression (Clause);
4336 -- Multiple constituents appear as an aggregate
4338 if Nkind (Constit) = N_Aggregate then
4339 Constit := First (Expressions (Constit));
4340 while Present (Constit) loop
4341 Process_Constituent (Constit);
4345 -- Various forms of a single constituent
4348 Process_Constituent (Constit);
4351 end Process_Refinement_Clause;
4353 -------------------------------
4354 -- Report_Unused_Body_States --
4355 -------------------------------
4357 procedure Report_Unused_Body_States (States : Elist_Id) is
4358 Posted : Boolean := False;
4359 State_Elmt : Elmt_Id;
4360 State_Id : Entity_Id;
4363 if Present (States) then
4364 State_Elmt := First_Elmt (States);
4365 while Present (State_Elmt) loop
4366 State_Id := Node (State_Elmt);
4368 -- Constants are part of the hidden state of a package, but the
4369 -- compiler cannot determine whether they have variable input
4370 -- (SPARK RM 7.1.1(2)) and cannot classify them properly as a
4371 -- hidden state. Do not emit an error when a constant does not
4372 -- participate in a state refinement, even though it acts as a
4375 if Ekind (State_Id) = E_Constant then
4378 -- Generate an error message of the form:
4380 -- body of package ... has unused hidden states
4381 -- abstract state ... defined at ...
4382 -- variable ... defined at ...
4388 ("body of package & has unused hidden states", Body_Id);
4391 Error_Msg_Sloc := Sloc (State_Id);
4393 if Ekind (State_Id) = E_Abstract_State then
4395 ("\abstract state & defined #", Body_Id, State_Id);
4398 SPARK_Msg_NE ("\variable & defined #", Body_Id, State_Id);
4402 Next_Elmt (State_Elmt);
4405 end Report_Unused_Body_States;
4409 Prag : constant Node_Id := Get_Pragma (Body_Id, Pragma_Refined_State);
4410 Spec_Id : constant Entity_Id := Spec_Entity (Body_Id);
4414 -- Start of processing for Check_Unused_Body_States
4417 -- Inspect the clauses of pragma Refined_State and determine whether all
4418 -- visible states declared within the package body participate in the
4421 if Present (Prag) then
4422 Clause := Expression (Get_Argument (Prag, Spec_Id));
4423 States := Collect_Body_States (Body_Id);
4425 -- Multiple non-null state refinements appear as an aggregate
4427 if Nkind (Clause) = N_Aggregate then
4428 Clause := First (Component_Associations (Clause));
4429 while Present (Clause) loop
4430 Process_Refinement_Clause (Clause, States);
4434 -- Various forms of a single state refinement
4437 Process_Refinement_Clause (Clause, States);
4440 -- Ensure that all abstract states and objects declared in the
4441 -- package body state space are utilized as constituents.
4443 Report_Unused_Body_States (States);
4445 end Check_Unused_Body_States;
4451 function Choice_List (N : Node_Id) return List_Id is
4453 if Nkind (N) = N_Iterated_Component_Association then
4454 return Discrete_Choices (N);
4460 -------------------------
4461 -- Collect_Body_States --
4462 -------------------------
4464 function Collect_Body_States (Body_Id : Entity_Id) return Elist_Id is
4465 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean;
4466 -- Determine whether object Obj_Id is a suitable visible state of a
4469 procedure Collect_Visible_States
4470 (Pack_Id : Entity_Id;
4471 States : in out Elist_Id);
4472 -- Gather the entities of all abstract states and objects declared in
4473 -- the visible state space of package Pack_Id.
4475 ----------------------------
4476 -- Collect_Visible_States --
4477 ----------------------------
4479 procedure Collect_Visible_States
4480 (Pack_Id : Entity_Id;
4481 States : in out Elist_Id)
4483 Item_Id : Entity_Id;
4486 -- Traverse the entity chain of the package and inspect all visible
4489 Item_Id := First_Entity (Pack_Id);
4490 while Present (Item_Id) and then not In_Private_Part (Item_Id) loop
4492 -- Do not consider internally generated items as those cannot be
4493 -- named and participate in refinement.
4495 if not Comes_From_Source (Item_Id) then
4498 elsif Ekind (Item_Id) = E_Abstract_State then
4499 Append_New_Elmt (Item_Id, States);
4501 elsif Ekind_In (Item_Id, E_Constant, E_Variable)
4502 and then Is_Visible_Object (Item_Id)
4504 Append_New_Elmt (Item_Id, States);
4506 -- Recursively gather the visible states of a nested package
4508 elsif Ekind (Item_Id) = E_Package then
4509 Collect_Visible_States (Item_Id, States);
4512 Next_Entity (Item_Id);
4514 end Collect_Visible_States;
4516 -----------------------
4517 -- Is_Visible_Object --
4518 -----------------------
4520 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean is
4522 -- Objects that map generic formals to their actuals are not visible
4523 -- from outside the generic instantiation.
4525 if Present (Corresponding_Generic_Association
4526 (Declaration_Node (Obj_Id)))
4530 -- Constituents of a single protected/task type act as components of
4531 -- the type and are not visible from outside the type.
4533 elsif Ekind (Obj_Id) = E_Variable
4534 and then Present (Encapsulating_State (Obj_Id))
4535 and then Is_Single_Concurrent_Object (Encapsulating_State (Obj_Id))
4542 end Is_Visible_Object;
4546 Body_Decl : constant Node_Id := Unit_Declaration_Node (Body_Id);
4548 Item_Id : Entity_Id;
4549 States : Elist_Id := No_Elist;
4551 -- Start of processing for Collect_Body_States
4554 -- Inspect the declarations of the body looking for source objects,
4555 -- packages and package instantiations. Note that even though this
4556 -- processing is very similar to Collect_Visible_States, a package
4557 -- body does not have a First/Next_Entity list.
4559 Decl := First (Declarations (Body_Decl));
4560 while Present (Decl) loop
4562 -- Capture source objects as internally generated temporaries cannot
4563 -- be named and participate in refinement.
4565 if Nkind (Decl) = N_Object_Declaration then
4566 Item_Id := Defining_Entity (Decl);
4568 if Comes_From_Source (Item_Id)
4569 and then Is_Visible_Object (Item_Id)
4571 Append_New_Elmt (Item_Id, States);
4574 -- Capture the visible abstract states and objects of a source
4575 -- package [instantiation].
4577 elsif Nkind (Decl) = N_Package_Declaration then
4578 Item_Id := Defining_Entity (Decl);
4580 if Comes_From_Source (Item_Id) then
4581 Collect_Visible_States (Item_Id, States);
4589 end Collect_Body_States;
4591 ------------------------
4592 -- Collect_Interfaces --
4593 ------------------------
4595 procedure Collect_Interfaces
4597 Ifaces_List : out Elist_Id;
4598 Exclude_Parents : Boolean := False;
4599 Use_Full_View : Boolean := True)
4601 procedure Collect (Typ : Entity_Id);
4602 -- Subsidiary subprogram used to traverse the whole list
4603 -- of directly and indirectly implemented interfaces
4609 procedure Collect (Typ : Entity_Id) is
4610 Ancestor : Entity_Id;
4618 -- Handle private types and subtypes
4621 and then Is_Private_Type (Typ)
4622 and then Present (Full_View (Typ))
4624 Full_T := Full_View (Typ);
4626 if Ekind (Full_T) = E_Record_Subtype then
4627 Full_T := Etype (Typ);
4629 if Present (Full_View (Full_T)) then
4630 Full_T := Full_View (Full_T);
4635 -- Include the ancestor if we are generating the whole list of
4636 -- abstract interfaces.
4638 if Etype (Full_T) /= Typ
4640 -- Protect the frontend against wrong sources. For example:
4643 -- type A is tagged null record;
4644 -- type B is new A with private;
4645 -- type C is new A with private;
4647 -- type B is new C with null record;
4648 -- type C is new B with null record;
4651 and then Etype (Full_T) /= T
4653 Ancestor := Etype (Full_T);
4656 if Is_Interface (Ancestor) and then not Exclude_Parents then
4657 Append_Unique_Elmt (Ancestor, Ifaces_List);
4661 -- Traverse the graph of ancestor interfaces
4663 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
4664 Id := First (Abstract_Interface_List (Full_T));
4665 while Present (Id) loop
4666 Iface := Etype (Id);
4668 -- Protect against wrong uses. For example:
4669 -- type I is interface;
4670 -- type O is tagged null record;
4671 -- type Wrong is new I and O with null record; -- ERROR
4673 if Is_Interface (Iface) then
4675 and then Etype (T) /= T
4676 and then Interface_Present_In_Ancestor (Etype (T), Iface)
4681 Append_Unique_Elmt (Iface, Ifaces_List);
4690 -- Start of processing for Collect_Interfaces
4693 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
4694 Ifaces_List := New_Elmt_List;
4696 end Collect_Interfaces;
4698 ----------------------------------
4699 -- Collect_Interface_Components --
4700 ----------------------------------
4702 procedure Collect_Interface_Components
4703 (Tagged_Type : Entity_Id;
4704 Components_List : out Elist_Id)
4706 procedure Collect (Typ : Entity_Id);
4707 -- Subsidiary subprogram used to climb to the parents
4713 procedure Collect (Typ : Entity_Id) is
4714 Tag_Comp : Entity_Id;
4715 Parent_Typ : Entity_Id;
4718 -- Handle private types
4720 if Present (Full_View (Etype (Typ))) then
4721 Parent_Typ := Full_View (Etype (Typ));
4723 Parent_Typ := Etype (Typ);
4726 if Parent_Typ /= Typ
4728 -- Protect the frontend against wrong sources. For example:
4731 -- type A is tagged null record;
4732 -- type B is new A with private;
4733 -- type C is new A with private;
4735 -- type B is new C with null record;
4736 -- type C is new B with null record;
4739 and then Parent_Typ /= Tagged_Type
4741 Collect (Parent_Typ);
4744 -- Collect the components containing tags of secondary dispatch
4747 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
4748 while Present (Tag_Comp) loop
4749 pragma Assert (Present (Related_Type (Tag_Comp)));
4750 Append_Elmt (Tag_Comp, Components_List);
4752 Tag_Comp := Next_Tag_Component (Tag_Comp);
4756 -- Start of processing for Collect_Interface_Components
4759 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
4760 and then Is_Tagged_Type (Tagged_Type));
4762 Components_List := New_Elmt_List;
4763 Collect (Tagged_Type);
4764 end Collect_Interface_Components;
4766 -----------------------------
4767 -- Collect_Interfaces_Info --
4768 -----------------------------
4770 procedure Collect_Interfaces_Info
4772 Ifaces_List : out Elist_Id;
4773 Components_List : out Elist_Id;
4774 Tags_List : out Elist_Id)
4776 Comps_List : Elist_Id;
4777 Comp_Elmt : Elmt_Id;
4778 Comp_Iface : Entity_Id;
4779 Iface_Elmt : Elmt_Id;
4782 function Search_Tag (Iface : Entity_Id) return Entity_Id;
4783 -- Search for the secondary tag associated with the interface type
4784 -- Iface that is implemented by T.
4790 function Search_Tag (Iface : Entity_Id) return Entity_Id is
4793 if not Is_CPP_Class (T) then
4794 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
4796 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
4800 and then Is_Tag (Node (ADT))
4801 and then Related_Type (Node (ADT)) /= Iface
4803 -- Skip secondary dispatch table referencing thunks to user
4804 -- defined primitives covered by this interface.
4806 pragma Assert (Has_Suffix (Node (ADT), 'P'));
4809 -- Skip secondary dispatch tables of Ada types
4811 if not Is_CPP_Class (T) then
4813 -- Skip secondary dispatch table referencing thunks to
4814 -- predefined primitives.
4816 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
4819 -- Skip secondary dispatch table referencing user-defined
4820 -- primitives covered by this interface.
4822 pragma Assert (Has_Suffix (Node (ADT), 'D'));
4825 -- Skip secondary dispatch table referencing predefined
4828 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
4833 pragma Assert (Is_Tag (Node (ADT)));
4837 -- Start of processing for Collect_Interfaces_Info
4840 Collect_Interfaces (T, Ifaces_List);
4841 Collect_Interface_Components (T, Comps_List);
4843 -- Search for the record component and tag associated with each
4844 -- interface type of T.
4846 Components_List := New_Elmt_List;
4847 Tags_List := New_Elmt_List;
4849 Iface_Elmt := First_Elmt (Ifaces_List);
4850 while Present (Iface_Elmt) loop
4851 Iface := Node (Iface_Elmt);
4853 -- Associate the primary tag component and the primary dispatch table
4854 -- with all the interfaces that are parents of T
4856 if Is_Ancestor (Iface, T, Use_Full_View => True) then
4857 Append_Elmt (First_Tag_Component (T), Components_List);
4858 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
4860 -- Otherwise search for the tag component and secondary dispatch
4864 Comp_Elmt := First_Elmt (Comps_List);
4865 while Present (Comp_Elmt) loop
4866 Comp_Iface := Related_Type (Node (Comp_Elmt));
4868 if Comp_Iface = Iface
4869 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
4871 Append_Elmt (Node (Comp_Elmt), Components_List);
4872 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
4876 Next_Elmt (Comp_Elmt);
4878 pragma Assert (Present (Comp_Elmt));
4881 Next_Elmt (Iface_Elmt);
4883 end Collect_Interfaces_Info;
4885 ---------------------
4886 -- Collect_Parents --
4887 ---------------------
4889 procedure Collect_Parents
4891 List : out Elist_Id;
4892 Use_Full_View : Boolean := True)
4894 Current_Typ : Entity_Id := T;
4895 Parent_Typ : Entity_Id;
4898 List := New_Elmt_List;
4900 -- No action if the if the type has no parents
4902 if T = Etype (T) then
4907 Parent_Typ := Etype (Current_Typ);
4909 if Is_Private_Type (Parent_Typ)
4910 and then Present (Full_View (Parent_Typ))
4911 and then Use_Full_View
4913 Parent_Typ := Full_View (Base_Type (Parent_Typ));
4916 Append_Elmt (Parent_Typ, List);
4918 exit when Parent_Typ = Current_Typ;
4919 Current_Typ := Parent_Typ;
4921 end Collect_Parents;
4923 ----------------------------------
4924 -- Collect_Primitive_Operations --
4925 ----------------------------------
4927 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
4928 B_Type : constant Entity_Id := Base_Type (T);
4929 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
4930 B_Scope : Entity_Id := Scope (B_Type);
4934 Is_Type_In_Pkg : Boolean;
4935 Formal_Derived : Boolean := False;
4938 function Match (E : Entity_Id) return Boolean;
4939 -- True if E's base type is B_Type, or E is of an anonymous access type
4940 -- and the base type of its designated type is B_Type.
4946 function Match (E : Entity_Id) return Boolean is
4947 Etyp : Entity_Id := Etype (E);
4950 if Ekind (Etyp) = E_Anonymous_Access_Type then
4951 Etyp := Designated_Type (Etyp);
4954 -- In Ada 2012 a primitive operation may have a formal of an
4955 -- incomplete view of the parent type.
4957 return Base_Type (Etyp) = B_Type
4959 (Ada_Version >= Ada_2012
4960 and then Ekind (Etyp) = E_Incomplete_Type
4961 and then Full_View (Etyp) = B_Type);
4964 -- Start of processing for Collect_Primitive_Operations
4967 -- For tagged types, the primitive operations are collected as they
4968 -- are declared, and held in an explicit list which is simply returned.
4970 if Is_Tagged_Type (B_Type) then
4971 return Primitive_Operations (B_Type);
4973 -- An untagged generic type that is a derived type inherits the
4974 -- primitive operations of its parent type. Other formal types only
4975 -- have predefined operators, which are not explicitly represented.
4977 elsif Is_Generic_Type (B_Type) then
4978 if Nkind (B_Decl) = N_Formal_Type_Declaration
4979 and then Nkind (Formal_Type_Definition (B_Decl)) =
4980 N_Formal_Derived_Type_Definition
4982 Formal_Derived := True;
4984 return New_Elmt_List;
4988 Op_List := New_Elmt_List;
4990 if B_Scope = Standard_Standard then
4991 if B_Type = Standard_String then
4992 Append_Elmt (Standard_Op_Concat, Op_List);
4994 elsif B_Type = Standard_Wide_String then
4995 Append_Elmt (Standard_Op_Concatw, Op_List);
5001 -- Locate the primitive subprograms of the type
5004 -- The primitive operations appear after the base type, except
5005 -- if the derivation happens within the private part of B_Scope
5006 -- and the type is a private type, in which case both the type
5007 -- and some primitive operations may appear before the base
5008 -- type, and the list of candidates starts after the type.
5010 if In_Open_Scopes (B_Scope)
5011 and then Scope (T) = B_Scope
5012 and then In_Private_Part (B_Scope)
5014 Id := Next_Entity (T);
5016 -- In Ada 2012, If the type has an incomplete partial view, there
5017 -- may be primitive operations declared before the full view, so
5018 -- we need to start scanning from the incomplete view, which is
5019 -- earlier on the entity chain.
5021 elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration
5022 and then Present (Incomplete_View (Parent (B_Type)))
5024 Id := Defining_Entity (Incomplete_View (Parent (B_Type)));
5026 -- If T is a derived from a type with an incomplete view declared
5027 -- elsewhere, that incomplete view is irrelevant, we want the
5028 -- operations in the scope of T.
5030 if Scope (Id) /= Scope (B_Type) then
5031 Id := Next_Entity (B_Type);
5035 Id := Next_Entity (B_Type);
5038 -- Set flag if this is a type in a package spec
5041 Is_Package_Or_Generic_Package (B_Scope)
5043 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
5046 while Present (Id) loop
5048 -- Test whether the result type or any of the parameter types of
5049 -- each subprogram following the type match that type when the
5050 -- type is declared in a package spec, is a derived type, or the
5051 -- subprogram is marked as primitive. (The Is_Primitive test is
5052 -- needed to find primitives of nonderived types in declarative
5053 -- parts that happen to override the predefined "=" operator.)
5055 -- Note that generic formal subprograms are not considered to be
5056 -- primitive operations and thus are never inherited.
5058 if Is_Overloadable (Id)
5059 and then (Is_Type_In_Pkg
5060 or else Is_Derived_Type (B_Type)
5061 or else Is_Primitive (Id))
5062 and then Nkind (Parent (Parent (Id)))
5063 not in N_Formal_Subprogram_Declaration
5071 Formal := First_Formal (Id);
5072 while Present (Formal) loop
5073 if Match (Formal) then
5078 Next_Formal (Formal);
5082 -- For a formal derived type, the only primitives are the ones
5083 -- inherited from the parent type. Operations appearing in the
5084 -- package declaration are not primitive for it.
5087 and then (not Formal_Derived or else Present (Alias (Id)))
5089 -- In the special case of an equality operator aliased to
5090 -- an overriding dispatching equality belonging to the same
5091 -- type, we don't include it in the list of primitives.
5092 -- This avoids inheriting multiple equality operators when
5093 -- deriving from untagged private types whose full type is
5094 -- tagged, which can otherwise cause ambiguities. Note that
5095 -- this should only happen for this kind of untagged parent
5096 -- type, since normally dispatching operations are inherited
5097 -- using the type's Primitive_Operations list.
5099 if Chars (Id) = Name_Op_Eq
5100 and then Is_Dispatching_Operation (Id)
5101 and then Present (Alias (Id))
5102 and then Present (Overridden_Operation (Alias (Id)))
5103 and then Base_Type (Etype (First_Entity (Id))) =
5104 Base_Type (Etype (First_Entity (Alias (Id))))
5108 -- Include the subprogram in the list of primitives
5111 Append_Elmt (Id, Op_List);
5118 -- For a type declared in System, some of its operations may
5119 -- appear in the target-specific extension to System.
5122 and then B_Scope = RTU_Entity (System)
5123 and then Present_System_Aux
5125 B_Scope := System_Aux_Id;
5126 Id := First_Entity (System_Aux_Id);
5132 end Collect_Primitive_Operations;
5134 -----------------------------------
5135 -- Compile_Time_Constraint_Error --
5136 -----------------------------------
5138 function Compile_Time_Constraint_Error
5141 Ent : Entity_Id := Empty;
5142 Loc : Source_Ptr := No_Location;
5143 Warn : Boolean := False) return Node_Id
5145 Msgc : String (1 .. Msg'Length + 3);
5146 -- Copy of message, with room for possible ?? or << and ! at end
5152 -- Start of processing for Compile_Time_Constraint_Error
5155 -- If this is a warning, convert it into an error if we are in code
5156 -- subject to SPARK_Mode being set On, unless Warn is True to force a
5157 -- warning. The rationale is that a compile-time constraint error should
5158 -- lead to an error instead of a warning when SPARK_Mode is On, but in
5159 -- a few cases we prefer to issue a warning and generate both a suitable
5160 -- run-time error in GNAT and a suitable check message in GNATprove.
5161 -- Those cases are those that likely correspond to deactivated SPARK
5162 -- code, so that this kind of code can be compiled and analyzed instead
5163 -- of being rejected.
5165 Error_Msg_Warn := Warn or SPARK_Mode /= On;
5167 -- A static constraint error in an instance body is not a fatal error.
5168 -- we choose to inhibit the message altogether, because there is no
5169 -- obvious node (for now) on which to post it. On the other hand the
5170 -- offending node must be replaced with a constraint_error in any case.
5172 -- No messages are generated if we already posted an error on this node
5174 if not Error_Posted (N) then
5175 if Loc /= No_Location then
5181 -- Copy message to Msgc, converting any ? in the message into <
5182 -- instead, so that we have an error in GNATprove mode.
5186 for J in 1 .. Msgl loop
5187 if Msg (J) = '?' and then (J = 1 or else Msg (J - 1) /= ''') then
5190 Msgc (J) := Msg (J);
5194 -- Message is a warning, even in Ada 95 case
5196 if Msg (Msg'Last) = '?' or else Msg (Msg'Last) = '<' then
5199 -- In Ada 83, all messages are warnings. In the private part and the
5200 -- body of an instance, constraint_checks are only warnings. We also
5201 -- make this a warning if the Warn parameter is set.
5204 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
5205 or else In_Instance_Not_Visible
5213 -- Otherwise we have a real error message (Ada 95 static case) and we
5214 -- make this an unconditional message. Note that in the warning case
5215 -- we do not make the message unconditional, it seems reasonable to
5216 -- delete messages like this (about exceptions that will be raised)
5225 -- One more test, skip the warning if the related expression is
5226 -- statically unevaluated, since we don't want to warn about what
5227 -- will happen when something is evaluated if it never will be
5230 if not Is_Statically_Unevaluated (N) then
5231 if Present (Ent) then
5232 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
5234 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
5239 -- Check whether the context is an Init_Proc
5241 if Inside_Init_Proc then
5243 Conc_Typ : constant Entity_Id :=
5244 Corresponding_Concurrent_Type
5245 (Entity (Parameter_Type (First
5246 (Parameter_Specifications
5247 (Parent (Current_Scope))))));
5250 -- Don't complain if the corresponding concurrent type
5251 -- doesn't come from source (i.e. a single task/protected
5254 if Present (Conc_Typ)
5255 and then not Comes_From_Source (Conc_Typ)
5258 ("\& [<<", N, Standard_Constraint_Error, Eloc);
5261 if GNATprove_Mode then
5263 ("\& would have been raised for objects of this "
5264 & "type", N, Standard_Constraint_Error, Eloc);
5267 ("\& will be raised for objects of this type??",
5268 N, Standard_Constraint_Error, Eloc);
5274 Error_Msg_NEL ("\& [<<", N, Standard_Constraint_Error, Eloc);
5278 Error_Msg ("\static expression fails Constraint_Check", Eloc);
5279 Set_Error_Posted (N);
5285 end Compile_Time_Constraint_Error;
5287 -----------------------
5288 -- Conditional_Delay --
5289 -----------------------
5291 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
5293 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
5294 Set_Has_Delayed_Freeze (New_Ent);
5296 end Conditional_Delay;
5298 ----------------------------
5299 -- Contains_Refined_State --
5300 ----------------------------
5302 function Contains_Refined_State (Prag : Node_Id) return Boolean is
5303 function Has_State_In_Dependency (List : Node_Id) return Boolean;
5304 -- Determine whether a dependency list mentions a state with a visible
5307 function Has_State_In_Global (List : Node_Id) return Boolean;
5308 -- Determine whether a global list mentions a state with a visible
5311 function Is_Refined_State (Item : Node_Id) return Boolean;
5312 -- Determine whether Item is a reference to an abstract state with a
5313 -- visible refinement.
5315 -----------------------------
5316 -- Has_State_In_Dependency --
5317 -----------------------------
5319 function Has_State_In_Dependency (List : Node_Id) return Boolean is
5324 -- A null dependency list does not mention any states
5326 if Nkind (List) = N_Null then
5329 -- Dependency clauses appear as component associations of an
5332 elsif Nkind (List) = N_Aggregate
5333 and then Present (Component_Associations (List))
5335 Clause := First (Component_Associations (List));
5336 while Present (Clause) loop
5338 -- Inspect the outputs of a dependency clause
5340 Output := First (Choices (Clause));
5341 while Present (Output) loop
5342 if Is_Refined_State (Output) then
5349 -- Inspect the outputs of a dependency clause
5351 if Is_Refined_State (Expression (Clause)) then
5358 -- If we get here, then none of the dependency clauses mention a
5359 -- state with visible refinement.
5363 -- An illegal pragma managed to sneak in
5366 raise Program_Error;
5368 end Has_State_In_Dependency;
5370 -------------------------
5371 -- Has_State_In_Global --
5372 -------------------------
5374 function Has_State_In_Global (List : Node_Id) return Boolean is
5378 -- A null global list does not mention any states
5380 if Nkind (List) = N_Null then
5383 -- Simple global list or moded global list declaration
5385 elsif Nkind (List) = N_Aggregate then
5387 -- The declaration of a simple global list appear as a collection
5390 if Present (Expressions (List)) then
5391 Item := First (Expressions (List));
5392 while Present (Item) loop
5393 if Is_Refined_State (Item) then
5400 -- The declaration of a moded global list appears as a collection
5401 -- of component associations where individual choices denote
5405 Item := First (Component_Associations (List));
5406 while Present (Item) loop
5407 if Has_State_In_Global (Expression (Item)) then
5415 -- If we get here, then the simple/moded global list did not
5416 -- mention any states with a visible refinement.
5420 -- Single global item declaration
5422 elsif Is_Entity_Name (List) then
5423 return Is_Refined_State (List);
5425 -- An illegal pragma managed to sneak in
5428 raise Program_Error;
5430 end Has_State_In_Global;
5432 ----------------------
5433 -- Is_Refined_State --
5434 ----------------------
5436 function Is_Refined_State (Item : Node_Id) return Boolean is
5438 Item_Id : Entity_Id;
5441 if Nkind (Item) = N_Null then
5444 -- States cannot be subject to attribute 'Result. This case arises
5445 -- in dependency relations.
5447 elsif Nkind (Item) = N_Attribute_Reference
5448 and then Attribute_Name (Item) = Name_Result
5452 -- Multiple items appear as an aggregate. This case arises in
5453 -- dependency relations.
5455 elsif Nkind (Item) = N_Aggregate
5456 and then Present (Expressions (Item))
5458 Elmt := First (Expressions (Item));
5459 while Present (Elmt) loop
5460 if Is_Refined_State (Elmt) then
5467 -- If we get here, then none of the inputs or outputs reference a
5468 -- state with visible refinement.
5475 Item_Id := Entity_Of (Item);
5479 and then Ekind (Item_Id) = E_Abstract_State
5480 and then Has_Visible_Refinement (Item_Id);
5482 end Is_Refined_State;
5486 Arg : constant Node_Id :=
5487 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
5488 Nam : constant Name_Id := Pragma_Name (Prag);
5490 -- Start of processing for Contains_Refined_State
5493 if Nam = Name_Depends then
5494 return Has_State_In_Dependency (Arg);
5496 else pragma Assert (Nam = Name_Global);
5497 return Has_State_In_Global (Arg);
5499 end Contains_Refined_State;
5501 -------------------------
5502 -- Copy_Component_List --
5503 -------------------------
5505 function Copy_Component_List
5507 Loc : Source_Ptr) return List_Id
5510 Comps : constant List_Id := New_List;
5513 Comp := First_Component (Underlying_Type (R_Typ));
5514 while Present (Comp) loop
5515 if Comes_From_Source (Comp) then
5517 Comp_Decl : constant Node_Id := Declaration_Node (Comp);
5520 Make_Component_Declaration (Loc,
5521 Defining_Identifier =>
5522 Make_Defining_Identifier (Loc, Chars (Comp)),
5523 Component_Definition =>
5525 (Component_Definition (Comp_Decl), New_Sloc => Loc)));
5529 Next_Component (Comp);
5533 end Copy_Component_List;
5535 -------------------------
5536 -- Copy_Parameter_List --
5537 -------------------------
5539 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
5540 Loc : constant Source_Ptr := Sloc (Subp_Id);
5545 if No (First_Formal (Subp_Id)) then
5549 Formal := First_Formal (Subp_Id);
5550 while Present (Formal) loop
5552 Make_Parameter_Specification (Loc,
5553 Defining_Identifier =>
5554 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
5555 In_Present => In_Present (Parent (Formal)),
5556 Out_Present => Out_Present (Parent (Formal)),
5558 New_Occurrence_Of (Etype (Formal), Loc),
5560 New_Copy_Tree (Expression (Parent (Formal)))));
5562 Next_Formal (Formal);
5567 end Copy_Parameter_List;
5569 ----------------------------
5570 -- Copy_SPARK_Mode_Aspect --
5571 ----------------------------
5573 procedure Copy_SPARK_Mode_Aspect (From : Node_Id; To : Node_Id) is
5574 pragma Assert (not Has_Aspects (To));
5578 if Has_Aspects (From) then
5579 Asp := Find_Aspect (Defining_Entity (From), Aspect_SPARK_Mode);
5581 if Present (Asp) then
5582 Set_Aspect_Specifications (To, New_List (New_Copy_Tree (Asp)));
5583 Set_Has_Aspects (To, True);
5586 end Copy_SPARK_Mode_Aspect;
5588 --------------------------
5589 -- Copy_Subprogram_Spec --
5590 --------------------------
5592 function Copy_Subprogram_Spec (Spec : Node_Id) return Node_Id is
5594 Formal_Spec : Node_Id;
5598 -- The structure of the original tree must be replicated without any
5599 -- alterations. Use New_Copy_Tree for this purpose.
5601 Result := New_Copy_Tree (Spec);
5603 -- However, the spec of a null procedure carries the corresponding null
5604 -- statement of the body (created by the parser), and this cannot be
5605 -- shared with the new subprogram spec.
5607 if Nkind (Result) = N_Procedure_Specification then
5608 Set_Null_Statement (Result, Empty);
5611 -- Create a new entity for the defining unit name
5613 Def_Id := Defining_Unit_Name (Result);
5614 Set_Defining_Unit_Name (Result,
5615 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
5617 -- Create new entities for the formal parameters
5619 if Present (Parameter_Specifications (Result)) then
5620 Formal_Spec := First (Parameter_Specifications (Result));
5621 while Present (Formal_Spec) loop
5622 Def_Id := Defining_Identifier (Formal_Spec);
5623 Set_Defining_Identifier (Formal_Spec,
5624 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
5631 end Copy_Subprogram_Spec;
5633 --------------------------------
5634 -- Corresponding_Generic_Type --
5635 --------------------------------
5637 function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id is
5643 if not Is_Generic_Actual_Type (T) then
5646 -- If the actual is the actual of an enclosing instance, resolution
5647 -- was correct in the generic.
5649 elsif Nkind (Parent (T)) = N_Subtype_Declaration
5650 and then Is_Entity_Name (Subtype_Indication (Parent (T)))
5652 Is_Generic_Actual_Type (Entity (Subtype_Indication (Parent (T))))
5659 if Is_Wrapper_Package (Inst) then
5660 Inst := Related_Instance (Inst);
5665 (Specification (Unit_Declaration_Node (Inst)));
5667 -- Generic actual has the same name as the corresponding formal
5669 Typ := First_Entity (Gen);
5670 while Present (Typ) loop
5671 if Chars (Typ) = Chars (T) then
5680 end Corresponding_Generic_Type;
5682 --------------------
5683 -- Current_Entity --
5684 --------------------
5686 -- The currently visible definition for a given identifier is the
5687 -- one most chained at the start of the visibility chain, i.e. the
5688 -- one that is referenced by the Node_Id value of the name of the
5689 -- given identifier.
5691 function Current_Entity (N : Node_Id) return Entity_Id is
5693 return Get_Name_Entity_Id (Chars (N));
5696 -----------------------------
5697 -- Current_Entity_In_Scope --
5698 -----------------------------
5700 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
5702 CS : constant Entity_Id := Current_Scope;
5704 Transient_Case : constant Boolean := Scope_Is_Transient;
5707 E := Get_Name_Entity_Id (Chars (N));
5709 and then Scope (E) /= CS
5710 and then (not Transient_Case or else Scope (E) /= Scope (CS))
5716 end Current_Entity_In_Scope;
5722 function Current_Scope return Entity_Id is
5724 if Scope_Stack.Last = -1 then
5725 return Standard_Standard;
5728 C : constant Entity_Id :=
5729 Scope_Stack.Table (Scope_Stack.Last).Entity;
5734 return Standard_Standard;
5740 ----------------------------
5741 -- Current_Scope_No_Loops --
5742 ----------------------------
5744 function Current_Scope_No_Loops return Entity_Id is
5748 -- Examine the scope stack starting from the current scope and skip any
5749 -- internally generated loops.
5752 while Present (S) and then S /= Standard_Standard loop
5753 if Ekind (S) = E_Loop and then not Comes_From_Source (S) then
5761 end Current_Scope_No_Loops;
5763 ------------------------
5764 -- Current_Subprogram --
5765 ------------------------
5767 function Current_Subprogram return Entity_Id is
5768 Scop : constant Entity_Id := Current_Scope;
5770 if Is_Subprogram_Or_Generic_Subprogram (Scop) then
5773 return Enclosing_Subprogram (Scop);
5775 end Current_Subprogram;
5777 ----------------------------------
5778 -- Deepest_Type_Access_Level --
5779 ----------------------------------
5781 function Deepest_Type_Access_Level (Typ : Entity_Id) return Uint is
5783 if Ekind (Typ) = E_Anonymous_Access_Type
5784 and then not Is_Local_Anonymous_Access (Typ)
5785 and then Nkind (Associated_Node_For_Itype (Typ)) = N_Object_Declaration
5787 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
5791 Scope_Depth (Enclosing_Dynamic_Scope
5792 (Defining_Identifier
5793 (Associated_Node_For_Itype (Typ))));
5795 -- For generic formal type, return Int'Last (infinite).
5796 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
5798 elsif Is_Generic_Type (Root_Type (Typ)) then
5799 return UI_From_Int (Int'Last);
5802 return Type_Access_Level (Typ);
5804 end Deepest_Type_Access_Level;
5806 ---------------------
5807 -- Defining_Entity --
5808 ---------------------
5810 function Defining_Entity
5812 Empty_On_Errors : Boolean := False;
5813 Concurrent_Subunit : Boolean := False) return Entity_Id
5817 when N_Abstract_Subprogram_Declaration
5818 | N_Expression_Function
5819 | N_Formal_Subprogram_Declaration
5820 | N_Generic_Package_Declaration
5821 | N_Generic_Subprogram_Declaration
5822 | N_Package_Declaration
5824 | N_Subprogram_Body_Stub
5825 | N_Subprogram_Declaration
5826 | N_Subprogram_Renaming_Declaration
5828 return Defining_Entity (Specification (N));
5830 when N_Component_Declaration
5831 | N_Defining_Program_Unit_Name
5832 | N_Discriminant_Specification
5834 | N_Entry_Declaration
5835 | N_Entry_Index_Specification
5836 | N_Exception_Declaration
5837 | N_Exception_Renaming_Declaration
5838 | N_Formal_Object_Declaration
5839 | N_Formal_Package_Declaration
5840 | N_Formal_Type_Declaration
5841 | N_Full_Type_Declaration
5842 | N_Implicit_Label_Declaration
5843 | N_Incomplete_Type_Declaration
5844 | N_Iterator_Specification
5845 | N_Loop_Parameter_Specification
5846 | N_Number_Declaration
5847 | N_Object_Declaration
5848 | N_Object_Renaming_Declaration
5849 | N_Package_Body_Stub
5850 | N_Parameter_Specification
5851 | N_Private_Extension_Declaration
5852 | N_Private_Type_Declaration
5854 | N_Protected_Body_Stub
5855 | N_Protected_Type_Declaration
5856 | N_Single_Protected_Declaration
5857 | N_Single_Task_Declaration
5858 | N_Subtype_Declaration
5861 | N_Task_Type_Declaration
5863 return Defining_Identifier (N);
5867 Bod : constant Node_Id := Proper_Body (N);
5868 Orig_Bod : constant Node_Id := Original_Node (Bod);
5871 -- Retrieve the entity of the original protected or task body
5872 -- if requested by the caller.
5874 if Concurrent_Subunit
5875 and then Nkind (Bod) = N_Null_Statement
5876 and then Nkind_In (Orig_Bod, N_Protected_Body, N_Task_Body)
5878 return Defining_Entity (Orig_Bod);
5880 return Defining_Entity (Bod);
5884 when N_Function_Instantiation
5885 | N_Function_Specification
5886 | N_Generic_Function_Renaming_Declaration
5887 | N_Generic_Package_Renaming_Declaration
5888 | N_Generic_Procedure_Renaming_Declaration
5890 | N_Package_Instantiation
5891 | N_Package_Renaming_Declaration
5892 | N_Package_Specification
5893 | N_Procedure_Instantiation
5894 | N_Procedure_Specification
5897 Nam : constant Node_Id := Defining_Unit_Name (N);
5898 Err : Entity_Id := Empty;
5901 if Nkind (Nam) in N_Entity then
5904 -- For Error, make up a name and attach to declaration so we
5905 -- can continue semantic analysis.
5907 elsif Nam = Error then
5908 if Empty_On_Errors then
5911 Err := Make_Temporary (Sloc (N), 'T');
5912 Set_Defining_Unit_Name (N, Err);
5917 -- If not an entity, get defining identifier
5920 return Defining_Identifier (Nam);
5924 when N_Block_Statement
5927 return Entity (Identifier (N));
5930 if Empty_On_Errors then
5933 raise Program_Error;
5936 end Defining_Entity;
5938 --------------------------
5939 -- Denotes_Discriminant --
5940 --------------------------
5942 function Denotes_Discriminant
5944 Check_Concurrent : Boolean := False) return Boolean
5949 if not Is_Entity_Name (N) or else No (Entity (N)) then
5955 -- If we are checking for a protected type, the discriminant may have
5956 -- been rewritten as the corresponding discriminal of the original type
5957 -- or of the corresponding concurrent record, depending on whether we
5958 -- are in the spec or body of the protected type.
5960 return Ekind (E) = E_Discriminant
5963 and then Ekind (E) = E_In_Parameter
5964 and then Present (Discriminal_Link (E))
5966 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
5968 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
5969 end Denotes_Discriminant;
5971 -------------------------
5972 -- Denotes_Same_Object --
5973 -------------------------
5975 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
5976 Obj1 : Node_Id := A1;
5977 Obj2 : Node_Id := A2;
5979 function Has_Prefix (N : Node_Id) return Boolean;
5980 -- Return True if N has attribute Prefix
5982 function Is_Renaming (N : Node_Id) return Boolean;
5983 -- Return true if N names a renaming entity
5985 function Is_Valid_Renaming (N : Node_Id) return Boolean;
5986 -- For renamings, return False if the prefix of any dereference within
5987 -- the renamed object_name is a variable, or any expression within the
5988 -- renamed object_name contains references to variables or calls on
5989 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
5995 function Has_Prefix (N : Node_Id) return Boolean is
5999 N_Attribute_Reference,
6001 N_Explicit_Dereference,
6002 N_Indexed_Component,
6004 N_Selected_Component,
6012 function Is_Renaming (N : Node_Id) return Boolean is
6014 return Is_Entity_Name (N)
6015 and then Present (Renamed_Entity (Entity (N)));
6018 -----------------------
6019 -- Is_Valid_Renaming --
6020 -----------------------
6022 function Is_Valid_Renaming (N : Node_Id) return Boolean is
6024 function Check_Renaming (N : Node_Id) return Boolean;
6025 -- Recursive function used to traverse all the prefixes of N
6027 function Check_Renaming (N : Node_Id) return Boolean is
6030 and then not Check_Renaming (Renamed_Entity (Entity (N)))
6035 if Nkind (N) = N_Indexed_Component then
6040 Indx := First (Expressions (N));
6041 while Present (Indx) loop
6042 if not Is_OK_Static_Expression (Indx) then
6051 if Has_Prefix (N) then
6053 P : constant Node_Id := Prefix (N);
6056 if Nkind (N) = N_Explicit_Dereference
6057 and then Is_Variable (P)
6061 elsif Is_Entity_Name (P)
6062 and then Ekind (Entity (P)) = E_Function
6066 elsif Nkind (P) = N_Function_Call then
6070 -- Recursion to continue traversing the prefix of the
6071 -- renaming expression
6073 return Check_Renaming (P);
6080 -- Start of processing for Is_Valid_Renaming
6083 return Check_Renaming (N);
6084 end Is_Valid_Renaming;
6086 -- Start of processing for Denotes_Same_Object
6089 -- Both names statically denote the same stand-alone object or parameter
6090 -- (RM 6.4.1(6.5/3))
6092 if Is_Entity_Name (Obj1)
6093 and then Is_Entity_Name (Obj2)
6094 and then Entity (Obj1) = Entity (Obj2)
6099 -- For renamings, the prefix of any dereference within the renamed
6100 -- object_name is not a variable, and any expression within the
6101 -- renamed object_name contains no references to variables nor
6102 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
6104 if Is_Renaming (Obj1) then
6105 if Is_Valid_Renaming (Obj1) then
6106 Obj1 := Renamed_Entity (Entity (Obj1));
6112 if Is_Renaming (Obj2) then
6113 if Is_Valid_Renaming (Obj2) then
6114 Obj2 := Renamed_Entity (Entity (Obj2));
6120 -- No match if not same node kind (such cases are handled by
6121 -- Denotes_Same_Prefix)
6123 if Nkind (Obj1) /= Nkind (Obj2) then
6126 -- After handling valid renamings, one of the two names statically
6127 -- denoted a renaming declaration whose renamed object_name is known
6128 -- to denote the same object as the other (RM 6.4.1(6.10/3))
6130 elsif Is_Entity_Name (Obj1) then
6131 if Is_Entity_Name (Obj2) then
6132 return Entity (Obj1) = Entity (Obj2);
6137 -- Both names are selected_components, their prefixes are known to
6138 -- denote the same object, and their selector_names denote the same
6139 -- component (RM 6.4.1(6.6/3)).
6141 elsif Nkind (Obj1) = N_Selected_Component then
6142 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
6144 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
6146 -- Both names are dereferences and the dereferenced names are known to
6147 -- denote the same object (RM 6.4.1(6.7/3))
6149 elsif Nkind (Obj1) = N_Explicit_Dereference then
6150 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
6152 -- Both names are indexed_components, their prefixes are known to denote
6153 -- the same object, and each of the pairs of corresponding index values
6154 -- are either both static expressions with the same static value or both
6155 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
6157 elsif Nkind (Obj1) = N_Indexed_Component then
6158 if not Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
6166 Indx1 := First (Expressions (Obj1));
6167 Indx2 := First (Expressions (Obj2));
6168 while Present (Indx1) loop
6170 -- Indexes must denote the same static value or same object
6172 if Is_OK_Static_Expression (Indx1) then
6173 if not Is_OK_Static_Expression (Indx2) then
6176 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
6180 elsif not Denotes_Same_Object (Indx1, Indx2) then
6192 -- Both names are slices, their prefixes are known to denote the same
6193 -- object, and the two slices have statically matching index constraints
6194 -- (RM 6.4.1(6.9/3))
6196 elsif Nkind (Obj1) = N_Slice
6197 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
6200 Lo1, Lo2, Hi1, Hi2 : Node_Id;
6203 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
6204 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
6206 -- Check whether bounds are statically identical. There is no
6207 -- attempt to detect partial overlap of slices.
6209 return Denotes_Same_Object (Lo1, Lo2)
6211 Denotes_Same_Object (Hi1, Hi2);
6214 -- In the recursion, literals appear as indexes
6216 elsif Nkind (Obj1) = N_Integer_Literal
6218 Nkind (Obj2) = N_Integer_Literal
6220 return Intval (Obj1) = Intval (Obj2);
6225 end Denotes_Same_Object;
6227 -------------------------
6228 -- Denotes_Same_Prefix --
6229 -------------------------
6231 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
6233 if Is_Entity_Name (A1) then
6234 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
6235 and then not Is_Access_Type (Etype (A1))
6237 return Denotes_Same_Object (A1, Prefix (A2))
6238 or else Denotes_Same_Prefix (A1, Prefix (A2));
6243 elsif Is_Entity_Name (A2) then
6244 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
6246 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
6248 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
6251 Root1, Root2 : Node_Id;
6252 Depth1, Depth2 : Nat := 0;
6255 Root1 := Prefix (A1);
6256 while not Is_Entity_Name (Root1) loop
6258 (Root1, N_Selected_Component, N_Indexed_Component)
6262 Root1 := Prefix (Root1);
6265 Depth1 := Depth1 + 1;
6268 Root2 := Prefix (A2);
6269 while not Is_Entity_Name (Root2) loop
6270 if not Nkind_In (Root2, N_Selected_Component,
6271 N_Indexed_Component)
6275 Root2 := Prefix (Root2);
6278 Depth2 := Depth2 + 1;
6281 -- If both have the same depth and they do not denote the same
6282 -- object, they are disjoint and no warning is needed.
6284 if Depth1 = Depth2 then
6287 elsif Depth1 > Depth2 then
6288 Root1 := Prefix (A1);
6289 for J in 1 .. Depth1 - Depth2 - 1 loop
6290 Root1 := Prefix (Root1);
6293 return Denotes_Same_Object (Root1, A2);
6296 Root2 := Prefix (A2);
6297 for J in 1 .. Depth2 - Depth1 - 1 loop
6298 Root2 := Prefix (Root2);
6301 return Denotes_Same_Object (A1, Root2);
6308 end Denotes_Same_Prefix;
6310 ----------------------
6311 -- Denotes_Variable --
6312 ----------------------
6314 function Denotes_Variable (N : Node_Id) return Boolean is
6316 return Is_Variable (N) and then Paren_Count (N) = 0;
6317 end Denotes_Variable;
6319 -----------------------------
6320 -- Depends_On_Discriminant --
6321 -----------------------------
6323 function Depends_On_Discriminant (N : Node_Id) return Boolean is
6328 Get_Index_Bounds (N, L, H);
6329 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
6330 end Depends_On_Discriminant;
6332 -------------------------
6333 -- Designate_Same_Unit --
6334 -------------------------
6336 function Designate_Same_Unit
6338 Name2 : Node_Id) return Boolean
6340 K1 : constant Node_Kind := Nkind (Name1);
6341 K2 : constant Node_Kind := Nkind (Name2);
6343 function Prefix_Node (N : Node_Id) return Node_Id;
6344 -- Returns the parent unit name node of a defining program unit name
6345 -- or the prefix if N is a selected component or an expanded name.
6347 function Select_Node (N : Node_Id) return Node_Id;
6348 -- Returns the defining identifier node of a defining program unit
6349 -- name or the selector node if N is a selected component or an
6356 function Prefix_Node (N : Node_Id) return Node_Id is
6358 if Nkind (N) = N_Defining_Program_Unit_Name then
6369 function Select_Node (N : Node_Id) return Node_Id is
6371 if Nkind (N) = N_Defining_Program_Unit_Name then
6372 return Defining_Identifier (N);
6374 return Selector_Name (N);
6378 -- Start of processing for Designate_Same_Unit
6381 if Nkind_In (K1, N_Identifier, N_Defining_Identifier)
6383 Nkind_In (K2, N_Identifier, N_Defining_Identifier)
6385 return Chars (Name1) = Chars (Name2);
6387 elsif Nkind_In (K1, N_Expanded_Name,
6388 N_Selected_Component,
6389 N_Defining_Program_Unit_Name)
6391 Nkind_In (K2, N_Expanded_Name,
6392 N_Selected_Component,
6393 N_Defining_Program_Unit_Name)
6396 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
6398 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
6403 end Designate_Same_Unit;
6405 ---------------------------------------------
6406 -- Diagnose_Iterated_Component_Association --
6407 ---------------------------------------------
6409 procedure Diagnose_Iterated_Component_Association (N : Node_Id) is
6410 Def_Id : constant Entity_Id := Defining_Identifier (N);
6414 -- Determine whether the iterated component association appears within
6415 -- an aggregate. If this is the case, raise Program_Error because the
6416 -- iterated component association cannot be left in the tree as is and
6417 -- must always be processed by the related aggregate.
6420 while Present (Aggr) loop
6421 if Nkind (Aggr) = N_Aggregate then
6422 raise Program_Error;
6424 -- Prevent the search from going too far
6426 elsif Is_Body_Or_Package_Declaration (Aggr) then
6430 Aggr := Parent (Aggr);
6433 -- At this point it is known that the iterated component association is
6434 -- not within an aggregate. This is really a quantified expression with
6435 -- a missing "all" or "some" quantifier.
6437 Error_Msg_N ("missing quantifier", Def_Id);
6439 -- Rewrite the iterated component association as True to prevent any
6442 Rewrite (N, New_Occurrence_Of (Standard_True, Sloc (N)));
6444 end Diagnose_Iterated_Component_Association;
6446 ---------------------------------
6447 -- Dynamic_Accessibility_Level --
6448 ---------------------------------
6450 function Dynamic_Accessibility_Level (Expr : Node_Id) return Node_Id is
6451 Loc : constant Source_Ptr := Sloc (Expr);
6453 function Make_Level_Literal (Level : Uint) return Node_Id;
6454 -- Construct an integer literal representing an accessibility level
6455 -- with its type set to Natural.
6457 ------------------------
6458 -- Make_Level_Literal --
6459 ------------------------
6461 function Make_Level_Literal (Level : Uint) return Node_Id is
6462 Result : constant Node_Id := Make_Integer_Literal (Loc, Level);
6465 Set_Etype (Result, Standard_Natural);
6467 end Make_Level_Literal;
6473 -- Start of processing for Dynamic_Accessibility_Level
6476 if Is_Entity_Name (Expr) then
6479 if Present (Renamed_Object (E)) then
6480 return Dynamic_Accessibility_Level (Renamed_Object (E));
6483 if Is_Formal (E) or else Ekind_In (E, E_Variable, E_Constant) then
6484 if Present (Extra_Accessibility (E)) then
6485 return New_Occurrence_Of (Extra_Accessibility (E), Loc);
6490 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
6492 case Nkind (Expr) is
6494 -- For access discriminant, the level of the enclosing object
6496 when N_Selected_Component =>
6497 if Ekind (Entity (Selector_Name (Expr))) = E_Discriminant
6498 and then Ekind (Etype (Entity (Selector_Name (Expr)))) =
6499 E_Anonymous_Access_Type
6501 return Make_Level_Literal (Object_Access_Level (Expr));
6504 when N_Attribute_Reference =>
6505 case Get_Attribute_Id (Attribute_Name (Expr)) is
6507 -- For X'Access, the level of the prefix X
6509 when Attribute_Access =>
6510 return Make_Level_Literal
6511 (Object_Access_Level (Prefix (Expr)));
6513 -- Treat the unchecked attributes as library-level
6515 when Attribute_Unchecked_Access
6516 | Attribute_Unrestricted_Access
6518 return Make_Level_Literal (Scope_Depth (Standard_Standard));
6520 -- No other access-valued attributes
6523 raise Program_Error;
6528 -- Unimplemented: depends on context. As an actual parameter where
6529 -- formal type is anonymous, use
6530 -- Scope_Depth (Current_Scope) + 1.
6531 -- For other cases, see 3.10.2(14/3) and following. ???
6535 when N_Type_Conversion =>
6536 if not Is_Local_Anonymous_Access (Etype (Expr)) then
6538 -- Handle type conversions introduced for a rename of an
6539 -- Ada 2012 stand-alone object of an anonymous access type.
6541 return Dynamic_Accessibility_Level (Expression (Expr));
6548 return Make_Level_Literal (Type_Access_Level (Etype (Expr)));
6549 end Dynamic_Accessibility_Level;
6551 ------------------------
6552 -- Discriminated_Size --
6553 ------------------------
6555 function Discriminated_Size (Comp : Entity_Id) return Boolean is
6556 function Non_Static_Bound (Bound : Node_Id) return Boolean;
6557 -- Check whether the bound of an index is non-static and does denote
6558 -- a discriminant, in which case any object of the type (protected or
6559 -- otherwise) will have a non-static size.
6561 ----------------------
6562 -- Non_Static_Bound --
6563 ----------------------
6565 function Non_Static_Bound (Bound : Node_Id) return Boolean is
6567 if Is_OK_Static_Expression (Bound) then
6570 -- If the bound is given by a discriminant it is non-static
6571 -- (A static constraint replaces the reference with the value).
6572 -- In an protected object the discriminant has been replaced by
6573 -- the corresponding discriminal within the protected operation.
6575 elsif Is_Entity_Name (Bound)
6577 (Ekind (Entity (Bound)) = E_Discriminant
6578 or else Present (Discriminal_Link (Entity (Bound))))
6585 end Non_Static_Bound;
6589 Typ : constant Entity_Id := Etype (Comp);
6592 -- Start of processing for Discriminated_Size
6595 if not Is_Array_Type (Typ) then
6599 if Ekind (Typ) = E_Array_Subtype then
6600 Index := First_Index (Typ);
6601 while Present (Index) loop
6602 if Non_Static_Bound (Low_Bound (Index))
6603 or else Non_Static_Bound (High_Bound (Index))
6615 end Discriminated_Size;
6617 -----------------------------------
6618 -- Effective_Extra_Accessibility --
6619 -----------------------------------
6621 function Effective_Extra_Accessibility (Id : Entity_Id) return Entity_Id is
6623 if Present (Renamed_Object (Id))
6624 and then Is_Entity_Name (Renamed_Object (Id))
6626 return Effective_Extra_Accessibility (Entity (Renamed_Object (Id)));
6628 return Extra_Accessibility (Id);
6630 end Effective_Extra_Accessibility;
6632 -----------------------------
6633 -- Effective_Reads_Enabled --
6634 -----------------------------
6636 function Effective_Reads_Enabled (Id : Entity_Id) return Boolean is
6638 return Has_Enabled_Property (Id, Name_Effective_Reads);
6639 end Effective_Reads_Enabled;
6641 ------------------------------
6642 -- Effective_Writes_Enabled --
6643 ------------------------------
6645 function Effective_Writes_Enabled (Id : Entity_Id) return Boolean is
6647 return Has_Enabled_Property (Id, Name_Effective_Writes);
6648 end Effective_Writes_Enabled;
6650 ------------------------------
6651 -- Enclosing_Comp_Unit_Node --
6652 ------------------------------
6654 function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id is
6655 Current_Node : Node_Id;
6659 while Present (Current_Node)
6660 and then Nkind (Current_Node) /= N_Compilation_Unit
6662 Current_Node := Parent (Current_Node);
6665 if Nkind (Current_Node) /= N_Compilation_Unit then
6668 return Current_Node;
6670 end Enclosing_Comp_Unit_Node;
6672 --------------------------
6673 -- Enclosing_CPP_Parent --
6674 --------------------------
6676 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
6677 Parent_Typ : Entity_Id := Typ;
6680 while not Is_CPP_Class (Parent_Typ)
6681 and then Etype (Parent_Typ) /= Parent_Typ
6683 Parent_Typ := Etype (Parent_Typ);
6685 if Is_Private_Type (Parent_Typ) then
6686 Parent_Typ := Full_View (Base_Type (Parent_Typ));
6690 pragma Assert (Is_CPP_Class (Parent_Typ));
6692 end Enclosing_CPP_Parent;
6694 ---------------------------
6695 -- Enclosing_Declaration --
6696 ---------------------------
6698 function Enclosing_Declaration (N : Node_Id) return Node_Id is
6699 Decl : Node_Id := N;
6702 while Present (Decl)
6703 and then not (Nkind (Decl) in N_Declaration
6705 Nkind (Decl) in N_Later_Decl_Item)
6707 Decl := Parent (Decl);
6711 end Enclosing_Declaration;
6713 ----------------------------
6714 -- Enclosing_Generic_Body --
6715 ----------------------------
6717 function Enclosing_Generic_Body
6718 (N : Node_Id) return Node_Id
6726 while Present (P) loop
6727 if Nkind (P) = N_Package_Body
6728 or else Nkind (P) = N_Subprogram_Body
6730 Spec := Corresponding_Spec (P);
6732 if Present (Spec) then
6733 Decl := Unit_Declaration_Node (Spec);
6735 if Nkind (Decl) = N_Generic_Package_Declaration
6736 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
6747 end Enclosing_Generic_Body;
6749 ----------------------------
6750 -- Enclosing_Generic_Unit --
6751 ----------------------------
6753 function Enclosing_Generic_Unit
6754 (N : Node_Id) return Node_Id
6762 while Present (P) loop
6763 if Nkind (P) = N_Generic_Package_Declaration
6764 or else Nkind (P) = N_Generic_Subprogram_Declaration
6768 elsif Nkind (P) = N_Package_Body
6769 or else Nkind (P) = N_Subprogram_Body
6771 Spec := Corresponding_Spec (P);
6773 if Present (Spec) then
6774 Decl := Unit_Declaration_Node (Spec);
6776 if Nkind (Decl) = N_Generic_Package_Declaration
6777 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
6788 end Enclosing_Generic_Unit;
6790 -------------------------------
6791 -- Enclosing_Lib_Unit_Entity --
6792 -------------------------------
6794 function Enclosing_Lib_Unit_Entity
6795 (E : Entity_Id := Current_Scope) return Entity_Id
6797 Unit_Entity : Entity_Id;
6800 -- Look for enclosing library unit entity by following scope links.
6801 -- Equivalent to, but faster than indexing through the scope stack.
6804 while (Present (Scope (Unit_Entity))
6805 and then Scope (Unit_Entity) /= Standard_Standard)
6806 and not Is_Child_Unit (Unit_Entity)
6808 Unit_Entity := Scope (Unit_Entity);
6812 end Enclosing_Lib_Unit_Entity;
6814 -----------------------------
6815 -- Enclosing_Lib_Unit_Node --
6816 -----------------------------
6818 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
6819 Encl_Unit : Node_Id;
6822 Encl_Unit := Enclosing_Comp_Unit_Node (N);
6823 while Present (Encl_Unit)
6824 and then Nkind (Unit (Encl_Unit)) = N_Subunit
6826 Encl_Unit := Library_Unit (Encl_Unit);
6829 pragma Assert (Nkind (Encl_Unit) = N_Compilation_Unit);
6831 end Enclosing_Lib_Unit_Node;
6833 -----------------------
6834 -- Enclosing_Package --
6835 -----------------------
6837 function Enclosing_Package (E : Entity_Id) return Entity_Id is
6838 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
6841 if Dynamic_Scope = Standard_Standard then
6842 return Standard_Standard;
6844 elsif Dynamic_Scope = Empty then
6847 elsif Ekind_In (Dynamic_Scope, E_Package, E_Package_Body,
6850 return Dynamic_Scope;
6853 return Enclosing_Package (Dynamic_Scope);
6855 end Enclosing_Package;
6857 -------------------------------------
6858 -- Enclosing_Package_Or_Subprogram --
6859 -------------------------------------
6861 function Enclosing_Package_Or_Subprogram (E : Entity_Id) return Entity_Id is
6866 while Present (S) loop
6867 if Is_Package_Or_Generic_Package (S)
6868 or else Ekind (S) = E_Package_Body
6872 elsif Is_Subprogram_Or_Generic_Subprogram (S)
6873 or else Ekind (S) = E_Subprogram_Body
6883 end Enclosing_Package_Or_Subprogram;
6885 --------------------------
6886 -- Enclosing_Subprogram --
6887 --------------------------
6889 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
6890 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
6893 if Dynamic_Scope = Standard_Standard then
6896 elsif Dynamic_Scope = Empty then
6899 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
6900 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
6902 elsif Ekind (Dynamic_Scope) = E_Block
6903 or else Ekind (Dynamic_Scope) = E_Return_Statement
6905 return Enclosing_Subprogram (Dynamic_Scope);
6907 elsif Ekind (Dynamic_Scope) = E_Task_Type then
6908 return Get_Task_Body_Procedure (Dynamic_Scope);
6910 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
6911 and then Present (Full_View (Dynamic_Scope))
6912 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
6914 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
6916 -- No body is generated if the protected operation is eliminated
6918 elsif Convention (Dynamic_Scope) = Convention_Protected
6919 and then not Is_Eliminated (Dynamic_Scope)
6920 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
6922 return Protected_Body_Subprogram (Dynamic_Scope);
6925 return Dynamic_Scope;
6927 end Enclosing_Subprogram;
6929 --------------------------
6930 -- End_Keyword_Location --
6931 --------------------------
6933 function End_Keyword_Location (N : Node_Id) return Source_Ptr is
6934 function End_Label_Loc (Nod : Node_Id) return Source_Ptr;
6935 -- Return the source location of Nod's end label according to the
6936 -- following precedence rules:
6938 -- 1) If the end label exists, return its location
6939 -- 2) If Nod exists, return its location
6940 -- 3) Return the location of N
6946 function End_Label_Loc (Nod : Node_Id) return Source_Ptr is
6950 if Present (Nod) then
6951 Label := End_Label (Nod);
6953 if Present (Label) then
6954 return Sloc (Label);
6968 -- Start of processing for End_Keyword_Location
6971 if Nkind_In (N, N_Block_Statement,
6977 Owner := Handled_Statement_Sequence (N);
6979 elsif Nkind (N) = N_Package_Declaration then
6980 Owner := Specification (N);
6982 elsif Nkind (N) = N_Protected_Body then
6985 elsif Nkind_In (N, N_Protected_Type_Declaration,
6986 N_Single_Protected_Declaration)
6988 Owner := Protected_Definition (N);
6990 elsif Nkind_In (N, N_Single_Task_Declaration,
6991 N_Task_Type_Declaration)
6993 Owner := Task_Definition (N);
6995 -- This routine should not be called with other contexts
6998 pragma Assert (False);
7002 return End_Label_Loc (Owner);
7003 end End_Keyword_Location;
7005 ------------------------
7006 -- Ensure_Freeze_Node --
7007 ------------------------
7009 procedure Ensure_Freeze_Node (E : Entity_Id) is
7012 if No (Freeze_Node (E)) then
7013 FN := Make_Freeze_Entity (Sloc (E));
7014 Set_Has_Delayed_Freeze (E);
7015 Set_Freeze_Node (E, FN);
7016 Set_Access_Types_To_Process (FN, No_Elist);
7017 Set_TSS_Elist (FN, No_Elist);
7020 end Ensure_Freeze_Node;
7026 procedure Enter_Name (Def_Id : Entity_Id) is
7027 C : constant Entity_Id := Current_Entity (Def_Id);
7028 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
7029 S : constant Entity_Id := Current_Scope;
7032 Generate_Definition (Def_Id);
7034 -- Add new name to current scope declarations. Check for duplicate
7035 -- declaration, which may or may not be a genuine error.
7039 -- Case of previous entity entered because of a missing declaration
7040 -- or else a bad subtype indication. Best is to use the new entity,
7041 -- and make the previous one invisible.
7043 if Etype (E) = Any_Type then
7044 Set_Is_Immediately_Visible (E, False);
7046 -- Case of renaming declaration constructed for package instances.
7047 -- if there is an explicit declaration with the same identifier,
7048 -- the renaming is not immediately visible any longer, but remains
7049 -- visible through selected component notation.
7051 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
7052 and then not Comes_From_Source (E)
7054 Set_Is_Immediately_Visible (E, False);
7056 -- The new entity may be the package renaming, which has the same
7057 -- same name as a generic formal which has been seen already.
7059 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
7060 and then not Comes_From_Source (Def_Id)
7062 Set_Is_Immediately_Visible (E, False);
7064 -- For a fat pointer corresponding to a remote access to subprogram,
7065 -- we use the same identifier as the RAS type, so that the proper
7066 -- name appears in the stub. This type is only retrieved through
7067 -- the RAS type and never by visibility, and is not added to the
7068 -- visibility list (see below).
7070 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
7071 and then Ekind (Def_Id) = E_Record_Type
7072 and then Present (Corresponding_Remote_Type (Def_Id))
7076 -- Case of an implicit operation or derived literal. The new entity
7077 -- hides the implicit one, which is removed from all visibility,
7078 -- i.e. the entity list of its scope, and homonym chain of its name.
7080 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
7081 or else Is_Internal (E)
7084 Decl : constant Node_Id := Parent (E);
7086 Prev_Vis : Entity_Id;
7089 -- If E is an implicit declaration, it cannot be the first
7090 -- entity in the scope.
7092 Prev := First_Entity (Current_Scope);
7093 while Present (Prev) and then Next_Entity (Prev) /= E loop
7099 -- If E is not on the entity chain of the current scope,
7100 -- it is an implicit declaration in the generic formal
7101 -- part of a generic subprogram. When analyzing the body,
7102 -- the generic formals are visible but not on the entity
7103 -- chain of the subprogram. The new entity will become
7104 -- the visible one in the body.
7107 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
7111 Set_Next_Entity (Prev, Next_Entity (E));
7113 if No (Next_Entity (Prev)) then
7114 Set_Last_Entity (Current_Scope, Prev);
7117 if E = Current_Entity (E) then
7121 Prev_Vis := Current_Entity (E);
7122 while Homonym (Prev_Vis) /= E loop
7123 Prev_Vis := Homonym (Prev_Vis);
7127 if Present (Prev_Vis) then
7129 -- Skip E in the visibility chain
7131 Set_Homonym (Prev_Vis, Homonym (E));
7134 Set_Name_Entity_Id (Chars (E), Homonym (E));
7139 -- This section of code could use a comment ???
7141 elsif Present (Etype (E))
7142 and then Is_Concurrent_Type (Etype (E))
7147 -- If the homograph is a protected component renaming, it should not
7148 -- be hiding the current entity. Such renamings are treated as weak
7151 elsif Is_Prival (E) then
7152 Set_Is_Immediately_Visible (E, False);
7154 -- In this case the current entity is a protected component renaming.
7155 -- Perform minimal decoration by setting the scope and return since
7156 -- the prival should not be hiding other visible entities.
7158 elsif Is_Prival (Def_Id) then
7159 Set_Scope (Def_Id, Current_Scope);
7162 -- Analogous to privals, the discriminal generated for an entry index
7163 -- parameter acts as a weak declaration. Perform minimal decoration
7164 -- to avoid bogus errors.
7166 elsif Is_Discriminal (Def_Id)
7167 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
7169 Set_Scope (Def_Id, Current_Scope);
7172 -- In the body or private part of an instance, a type extension may
7173 -- introduce a component with the same name as that of an actual. The
7174 -- legality rule is not enforced, but the semantics of the full type
7175 -- with two components of same name are not clear at this point???
7177 elsif In_Instance_Not_Visible then
7180 -- When compiling a package body, some child units may have become
7181 -- visible. They cannot conflict with local entities that hide them.
7183 elsif Is_Child_Unit (E)
7184 and then In_Open_Scopes (Scope (E))
7185 and then not Is_Immediately_Visible (E)
7189 -- Conversely, with front-end inlining we may compile the parent body
7190 -- first, and a child unit subsequently. The context is now the
7191 -- parent spec, and body entities are not visible.
7193 elsif Is_Child_Unit (Def_Id)
7194 and then Is_Package_Body_Entity (E)
7195 and then not In_Package_Body (Current_Scope)
7199 -- Case of genuine duplicate declaration
7202 Error_Msg_Sloc := Sloc (E);
7204 -- If the previous declaration is an incomplete type declaration
7205 -- this may be an attempt to complete it with a private type. The
7206 -- following avoids confusing cascaded errors.
7208 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
7209 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
7212 ("incomplete type cannot be completed with a private " &
7213 "declaration", Parent (Def_Id));
7214 Set_Is_Immediately_Visible (E, False);
7215 Set_Full_View (E, Def_Id);
7217 -- An inherited component of a record conflicts with a new
7218 -- discriminant. The discriminant is inserted first in the scope,
7219 -- but the error should be posted on it, not on the component.
7221 elsif Ekind (E) = E_Discriminant
7222 and then Present (Scope (Def_Id))
7223 and then Scope (Def_Id) /= Current_Scope
7225 Error_Msg_Sloc := Sloc (Def_Id);
7226 Error_Msg_N ("& conflicts with declaration#", E);
7229 -- If the name of the unit appears in its own context clause, a
7230 -- dummy package with the name has already been created, and the
7231 -- error emitted. Try to continue quietly.
7233 elsif Error_Posted (E)
7234 and then Sloc (E) = No_Location
7235 and then Nkind (Parent (E)) = N_Package_Specification
7236 and then Current_Scope = Standard_Standard
7238 Set_Scope (Def_Id, Current_Scope);
7242 Error_Msg_N ("& conflicts with declaration#", Def_Id);
7244 -- Avoid cascaded messages with duplicate components in
7247 if Ekind_In (E, E_Component, E_Discriminant) then
7252 if Nkind (Parent (Parent (Def_Id))) =
7253 N_Generic_Subprogram_Declaration
7255 Defining_Entity (Specification (Parent (Parent (Def_Id))))
7257 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
7260 -- If entity is in standard, then we are in trouble, because it
7261 -- means that we have a library package with a duplicated name.
7262 -- That's hard to recover from, so abort.
7264 if S = Standard_Standard then
7265 raise Unrecoverable_Error;
7267 -- Otherwise we continue with the declaration. Having two
7268 -- identical declarations should not cause us too much trouble.
7276 -- If we fall through, declaration is OK, at least OK enough to continue
7278 -- If Def_Id is a discriminant or a record component we are in the midst
7279 -- of inheriting components in a derived record definition. Preserve
7280 -- their Ekind and Etype.
7282 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
7285 -- If a type is already set, leave it alone (happens when a type
7286 -- declaration is reanalyzed following a call to the optimizer).
7288 elsif Present (Etype (Def_Id)) then
7291 -- Otherwise, the kind E_Void insures that premature uses of the entity
7292 -- will be detected. Any_Type insures that no cascaded errors will occur
7295 Set_Ekind (Def_Id, E_Void);
7296 Set_Etype (Def_Id, Any_Type);
7299 -- Inherited discriminants and components in derived record types are
7300 -- immediately visible. Itypes are not.
7302 -- Unless the Itype is for a record type with a corresponding remote
7303 -- type (what is that about, it was not commented ???)
7305 if Ekind_In (Def_Id, E_Discriminant, E_Component)
7307 ((not Is_Record_Type (Def_Id)
7308 or else No (Corresponding_Remote_Type (Def_Id)))
7309 and then not Is_Itype (Def_Id))
7311 Set_Is_Immediately_Visible (Def_Id);
7312 Set_Current_Entity (Def_Id);
7315 Set_Homonym (Def_Id, C);
7316 Append_Entity (Def_Id, S);
7317 Set_Public_Status (Def_Id);
7319 -- Declaring a homonym is not allowed in SPARK ...
7321 if Present (C) and then Restriction_Check_Required (SPARK_05) then
7323 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
7324 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
7325 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
7328 -- ... unless the new declaration is in a subprogram, and the
7329 -- visible declaration is a variable declaration or a parameter
7330 -- specification outside that subprogram.
7332 if Present (Enclosing_Subp)
7333 and then Nkind_In (Parent (C), N_Object_Declaration,
7334 N_Parameter_Specification)
7335 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
7339 -- ... or the new declaration is in a package, and the visible
7340 -- declaration occurs outside that package.
7342 elsif Present (Enclosing_Pack)
7343 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
7347 -- ... or the new declaration is a component declaration in a
7348 -- record type definition.
7350 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
7353 -- Don't issue error for non-source entities
7355 elsif Comes_From_Source (Def_Id)
7356 and then Comes_From_Source (C)
7358 Error_Msg_Sloc := Sloc (C);
7359 Check_SPARK_05_Restriction
7360 ("redeclaration of identifier &#", Def_Id);
7365 -- Warn if new entity hides an old one
7367 if Warn_On_Hiding and then Present (C)
7369 -- Don't warn for record components since they always have a well
7370 -- defined scope which does not confuse other uses. Note that in
7371 -- some cases, Ekind has not been set yet.
7373 and then Ekind (C) /= E_Component
7374 and then Ekind (C) /= E_Discriminant
7375 and then Nkind (Parent (C)) /= N_Component_Declaration
7376 and then Ekind (Def_Id) /= E_Component
7377 and then Ekind (Def_Id) /= E_Discriminant
7378 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
7380 -- Don't warn for one character variables. It is too common to use
7381 -- such variables as locals and will just cause too many false hits.
7383 and then Length_Of_Name (Chars (C)) /= 1
7385 -- Don't warn for non-source entities
7387 and then Comes_From_Source (C)
7388 and then Comes_From_Source (Def_Id)
7390 -- Don't warn unless entity in question is in extended main source
7392 and then In_Extended_Main_Source_Unit (Def_Id)
7394 -- Finally, the hidden entity must be either immediately visible or
7395 -- use visible (i.e. from a used package).
7398 (Is_Immediately_Visible (C)
7400 Is_Potentially_Use_Visible (C))
7402 Error_Msg_Sloc := Sloc (C);
7403 Error_Msg_N ("declaration hides &#?h?", Def_Id);
7411 function Entity_Of (N : Node_Id) return Entity_Id is
7416 -- Assume that the arbitrary node does not have an entity
7420 if Is_Entity_Name (N) then
7423 -- Follow a possible chain of renamings to reach the earliest renamed
7427 and then Is_Object (Id)
7428 and then Present (Renamed_Object (Id))
7430 Ren := Renamed_Object (Id);
7432 -- The reference renames an abstract state or a whole object
7435 -- Ren : ... renames Obj;
7437 if Is_Entity_Name (Ren) then
7440 -- The reference renames a function result. Check the original
7441 -- node in case expansion relocates the function call.
7443 -- Ren : ... renames Func_Call;
7445 elsif Nkind (Original_Node (Ren)) = N_Function_Call then
7448 -- Otherwise the reference renames something which does not yield
7449 -- an abstract state or a whole object. Treat the reference as not
7450 -- having a proper entity for SPARK legality purposes.
7462 --------------------------
7463 -- Explain_Limited_Type --
7464 --------------------------
7466 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
7470 -- For array, component type must be limited
7472 if Is_Array_Type (T) then
7473 Error_Msg_Node_2 := T;
7475 ("\component type& of type& is limited", N, Component_Type (T));
7476 Explain_Limited_Type (Component_Type (T), N);
7478 elsif Is_Record_Type (T) then
7480 -- No need for extra messages if explicit limited record
7482 if Is_Limited_Record (Base_Type (T)) then
7486 -- Otherwise find a limited component. Check only components that
7487 -- come from source, or inherited components that appear in the
7488 -- source of the ancestor.
7490 C := First_Component (T);
7491 while Present (C) loop
7492 if Is_Limited_Type (Etype (C))
7494 (Comes_From_Source (C)
7496 (Present (Original_Record_Component (C))
7498 Comes_From_Source (Original_Record_Component (C))))
7500 Error_Msg_Node_2 := T;
7501 Error_Msg_NE ("\component& of type& has limited type", N, C);
7502 Explain_Limited_Type (Etype (C), N);
7509 -- The type may be declared explicitly limited, even if no component
7510 -- of it is limited, in which case we fall out of the loop.
7513 end Explain_Limited_Type;
7515 ---------------------------------------
7516 -- Expression_Of_Expression_Function --
7517 ---------------------------------------
7519 function Expression_Of_Expression_Function
7520 (Subp : Entity_Id) return Node_Id
7522 Expr_Func : Node_Id;
7525 pragma Assert (Is_Expression_Function_Or_Completion (Subp));
7527 if Nkind (Original_Node (Subprogram_Spec (Subp))) =
7528 N_Expression_Function
7530 Expr_Func := Original_Node (Subprogram_Spec (Subp));
7532 elsif Nkind (Original_Node (Subprogram_Body (Subp))) =
7533 N_Expression_Function
7535 Expr_Func := Original_Node (Subprogram_Body (Subp));
7538 pragma Assert (False);
7542 return Original_Node (Expression (Expr_Func));
7543 end Expression_Of_Expression_Function;
7545 -------------------------------
7546 -- Extensions_Visible_Status --
7547 -------------------------------
7549 function Extensions_Visible_Status
7550 (Id : Entity_Id) return Extensions_Visible_Mode
7559 -- When a formal parameter is subject to Extensions_Visible, the pragma
7560 -- is stored in the contract of related subprogram.
7562 if Is_Formal (Id) then
7565 elsif Is_Subprogram_Or_Generic_Subprogram (Id) then
7568 -- No other construct carries this pragma
7571 return Extensions_Visible_None;
7574 Prag := Get_Pragma (Subp, Pragma_Extensions_Visible);
7576 -- In certain cases analysis may request the Extensions_Visible status
7577 -- of an expression function before the pragma has been analyzed yet.
7578 -- Inspect the declarative items after the expression function looking
7579 -- for the pragma (if any).
7581 if No (Prag) and then Is_Expression_Function (Subp) then
7582 Decl := Next (Unit_Declaration_Node (Subp));
7583 while Present (Decl) loop
7584 if Nkind (Decl) = N_Pragma
7585 and then Pragma_Name (Decl) = Name_Extensions_Visible
7590 -- A source construct ends the region where Extensions_Visible may
7591 -- appear, stop the traversal. An expanded expression function is
7592 -- no longer a source construct, but it must still be recognized.
7594 elsif Comes_From_Source (Decl)
7596 (Nkind_In (Decl, N_Subprogram_Body,
7597 N_Subprogram_Declaration)
7598 and then Is_Expression_Function (Defining_Entity (Decl)))
7607 -- Extract the value from the Boolean expression (if any)
7609 if Present (Prag) then
7610 Arg := First (Pragma_Argument_Associations (Prag));
7612 if Present (Arg) then
7613 Expr := Get_Pragma_Arg (Arg);
7615 -- When the associated subprogram is an expression function, the
7616 -- argument of the pragma may not have been analyzed.
7618 if not Analyzed (Expr) then
7619 Preanalyze_And_Resolve (Expr, Standard_Boolean);
7622 -- Guard against cascading errors when the argument of pragma
7623 -- Extensions_Visible is not a valid static Boolean expression.
7625 if Error_Posted (Expr) then
7626 return Extensions_Visible_None;
7628 elsif Is_True (Expr_Value (Expr)) then
7629 return Extensions_Visible_True;
7632 return Extensions_Visible_False;
7635 -- Otherwise the aspect or pragma defaults to True
7638 return Extensions_Visible_True;
7641 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
7642 -- directly specified. In SPARK code, its value defaults to "False".
7644 elsif SPARK_Mode = On then
7645 return Extensions_Visible_False;
7647 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
7651 return Extensions_Visible_True;
7653 end Extensions_Visible_Status;
7659 procedure Find_Actual
7661 Formal : out Entity_Id;
7664 Context : constant Node_Id := Parent (N);
7669 if Nkind_In (Context, N_Indexed_Component, N_Selected_Component)
7670 and then N = Prefix (Context)
7672 Find_Actual (Context, Formal, Call);
7675 elsif Nkind (Context) = N_Parameter_Association
7676 and then N = Explicit_Actual_Parameter (Context)
7678 Call := Parent (Context);
7680 elsif Nkind_In (Context, N_Entry_Call_Statement,
7682 N_Procedure_Call_Statement)
7692 -- If we have a call to a subprogram look for the parameter. Note that
7693 -- we exclude overloaded calls, since we don't know enough to be sure
7694 -- of giving the right answer in this case.
7696 if Nkind_In (Call, N_Entry_Call_Statement,
7698 N_Procedure_Call_Statement)
7700 Call_Nam := Name (Call);
7702 -- A call to a protected or task entry appears as a selected
7703 -- component rather than an expanded name.
7705 if Nkind (Call_Nam) = N_Selected_Component then
7706 Call_Nam := Selector_Name (Call_Nam);
7709 if Is_Entity_Name (Call_Nam)
7710 and then Present (Entity (Call_Nam))
7711 and then Is_Overloadable (Entity (Call_Nam))
7712 and then not Is_Overloaded (Call_Nam)
7714 -- If node is name in call it is not an actual
7716 if N = Call_Nam then
7722 -- Fall here if we are definitely a parameter
7724 Actual := First_Actual (Call);
7725 Formal := First_Formal (Entity (Call_Nam));
7726 while Present (Formal) and then Present (Actual) loop
7730 -- An actual that is the prefix in a prefixed call may have
7731 -- been rewritten in the call, after the deferred reference
7732 -- was collected. Check if sloc and kinds and names match.
7734 elsif Sloc (Actual) = Sloc (N)
7735 and then Nkind (Actual) = N_Identifier
7736 and then Nkind (Actual) = Nkind (N)
7737 and then Chars (Actual) = Chars (N)
7742 Actual := Next_Actual (Actual);
7743 Formal := Next_Formal (Formal);
7749 -- Fall through here if we did not find matching actual
7755 ---------------------------
7756 -- Find_Body_Discriminal --
7757 ---------------------------
7759 function Find_Body_Discriminal
7760 (Spec_Discriminant : Entity_Id) return Entity_Id
7766 -- If expansion is suppressed, then the scope can be the concurrent type
7767 -- itself rather than a corresponding concurrent record type.
7769 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
7770 Tsk := Scope (Spec_Discriminant);
7773 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
7775 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
7778 -- Find discriminant of original concurrent type, and use its current
7779 -- discriminal, which is the renaming within the task/protected body.
7781 Disc := First_Discriminant (Tsk);
7782 while Present (Disc) loop
7783 if Chars (Disc) = Chars (Spec_Discriminant) then
7784 return Discriminal (Disc);
7787 Next_Discriminant (Disc);
7790 -- That loop should always succeed in finding a matching entry and
7791 -- returning. Fatal error if not.
7793 raise Program_Error;
7794 end Find_Body_Discriminal;
7796 -------------------------------------
7797 -- Find_Corresponding_Discriminant --
7798 -------------------------------------
7800 function Find_Corresponding_Discriminant
7802 Typ : Entity_Id) return Entity_Id
7804 Par_Disc : Entity_Id;
7805 Old_Disc : Entity_Id;
7806 New_Disc : Entity_Id;
7809 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
7811 -- The original type may currently be private, and the discriminant
7812 -- only appear on its full view.
7814 if Is_Private_Type (Scope (Par_Disc))
7815 and then not Has_Discriminants (Scope (Par_Disc))
7816 and then Present (Full_View (Scope (Par_Disc)))
7818 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
7820 Old_Disc := First_Discriminant (Scope (Par_Disc));
7823 if Is_Class_Wide_Type (Typ) then
7824 New_Disc := First_Discriminant (Root_Type (Typ));
7826 New_Disc := First_Discriminant (Typ);
7829 while Present (Old_Disc) and then Present (New_Disc) loop
7830 if Old_Disc = Par_Disc then
7834 Next_Discriminant (Old_Disc);
7835 Next_Discriminant (New_Disc);
7838 -- Should always find it
7840 raise Program_Error;
7841 end Find_Corresponding_Discriminant;
7843 ----------------------------------
7844 -- Find_Enclosing_Iterator_Loop --
7845 ----------------------------------
7847 function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id is
7852 -- Traverse the scope chain looking for an iterator loop. Such loops are
7853 -- usually transformed into blocks, hence the use of Original_Node.
7856 while Present (S) and then S /= Standard_Standard loop
7857 if Ekind (S) = E_Loop
7858 and then Nkind (Parent (S)) = N_Implicit_Label_Declaration
7860 Constr := Original_Node (Label_Construct (Parent (S)));
7862 if Nkind (Constr) = N_Loop_Statement
7863 and then Present (Iteration_Scheme (Constr))
7864 and then Nkind (Iterator_Specification
7865 (Iteration_Scheme (Constr))) =
7866 N_Iterator_Specification
7876 end Find_Enclosing_Iterator_Loop;
7878 --------------------------
7879 -- Find_Enclosing_Scope --
7880 --------------------------
7882 function Find_Enclosing_Scope (N : Node_Id) return Entity_Id is
7884 Spec_Id : Entity_Id;
7887 -- Examine the parent chain looking for a construct which defines a
7891 while Present (Par) loop
7894 -- The construct denotes a declaration, the proper scope is its
7897 when N_Entry_Declaration
7898 | N_Expression_Function
7899 | N_Full_Type_Declaration
7900 | N_Generic_Package_Declaration
7901 | N_Generic_Subprogram_Declaration
7902 | N_Package_Declaration
7903 | N_Private_Extension_Declaration
7904 | N_Protected_Type_Declaration
7905 | N_Single_Protected_Declaration
7906 | N_Single_Task_Declaration
7907 | N_Subprogram_Declaration
7908 | N_Task_Type_Declaration
7910 return Defining_Entity (Par);
7912 -- The construct denotes a body, the proper scope is the entity of
7913 -- the corresponding spec.
7921 Spec_Id := Corresponding_Spec (Par);
7923 -- The defining entity of a stand-alone subprogram body defines
7926 if Nkind (Par) = N_Subprogram_Body and then No (Spec_Id) then
7927 return Defining_Entity (Par);
7929 -- Otherwise there should be corresponding spec which defines a
7933 pragma Assert (Present (Spec_Id));
7940 -- Blocks carry either a source or an internally-generated scope,
7941 -- unless the block is a byproduct of exception handling.
7943 when N_Block_Statement =>
7944 if not Exception_Junk (Par) then
7945 return Entity (Identifier (Par));
7948 -- Loops carry an internally-generated scope
7950 when N_Loop_Statement =>
7951 return Entity (Identifier (Par));
7953 -- Extended return statements carry an internally-generated scope
7955 when N_Extended_Return_Statement =>
7956 return Return_Statement_Entity (Par);
7958 -- A traversal from a subunit continues via the corresponding stub
7961 Par := Corresponding_Stub (Par);
7967 Par := Parent (Par);
7970 return Standard_Standard;
7971 end Find_Enclosing_Scope;
7973 ------------------------------------
7974 -- Find_Loop_In_Conditional_Block --
7975 ------------------------------------
7977 function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is
7983 if Nkind (Stmt) = N_If_Statement then
7984 Stmt := First (Then_Statements (Stmt));
7987 pragma Assert (Nkind (Stmt) = N_Block_Statement);
7989 -- Inspect the statements of the conditional block. In general the loop
7990 -- should be the first statement in the statement sequence of the block,
7991 -- but the finalization machinery may have introduced extra object
7994 Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
7995 while Present (Stmt) loop
7996 if Nkind (Stmt) = N_Loop_Statement then
8003 -- The expansion of attribute 'Loop_Entry produced a malformed block
8005 raise Program_Error;
8006 end Find_Loop_In_Conditional_Block;
8008 --------------------------
8009 -- Find_Overlaid_Entity --
8010 --------------------------
8012 procedure Find_Overlaid_Entity
8014 Ent : out Entity_Id;
8020 -- We are looking for one of the two following forms:
8022 -- for X'Address use Y'Address
8026 -- Const : constant Address := expr;
8028 -- for X'Address use Const;
8030 -- In the second case, the expr is either Y'Address, or recursively a
8031 -- constant that eventually references Y'Address.
8036 if Nkind (N) = N_Attribute_Definition_Clause
8037 and then Chars (N) = Name_Address
8039 Expr := Expression (N);
8041 -- This loop checks the form of the expression for Y'Address,
8042 -- using recursion to deal with intermediate constants.
8045 -- Check for Y'Address
8047 if Nkind (Expr) = N_Attribute_Reference
8048 and then Attribute_Name (Expr) = Name_Address
8050 Expr := Prefix (Expr);
8053 -- Check for Const where Const is a constant entity
8055 elsif Is_Entity_Name (Expr)
8056 and then Ekind (Entity (Expr)) = E_Constant
8058 Expr := Constant_Value (Entity (Expr));
8060 -- Anything else does not need checking
8067 -- This loop checks the form of the prefix for an entity, using
8068 -- recursion to deal with intermediate components.
8071 -- Check for Y where Y is an entity
8073 if Is_Entity_Name (Expr) then
8074 Ent := Entity (Expr);
8077 -- Check for components
8080 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component)
8082 Expr := Prefix (Expr);
8085 -- Anything else does not need checking
8092 end Find_Overlaid_Entity;
8094 -------------------------
8095 -- Find_Parameter_Type --
8096 -------------------------
8098 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
8100 if Nkind (Param) /= N_Parameter_Specification then
8103 -- For an access parameter, obtain the type from the formal entity
8104 -- itself, because access to subprogram nodes do not carry a type.
8105 -- Shouldn't we always use the formal entity ???
8107 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
8108 return Etype (Defining_Identifier (Param));
8111 return Etype (Parameter_Type (Param));
8113 end Find_Parameter_Type;
8115 -----------------------------------
8116 -- Find_Placement_In_State_Space --
8117 -----------------------------------
8119 procedure Find_Placement_In_State_Space
8120 (Item_Id : Entity_Id;
8121 Placement : out State_Space_Kind;
8122 Pack_Id : out Entity_Id)
8124 Context : Entity_Id;
8127 -- Assume that the item does not appear in the state space of a package
8129 Placement := Not_In_Package;
8132 -- Climb the scope stack and examine the enclosing context
8134 Context := Scope (Item_Id);
8135 while Present (Context) and then Context /= Standard_Standard loop
8136 if Is_Package_Or_Generic_Package (Context) then
8139 -- A package body is a cut off point for the traversal as the item
8140 -- cannot be visible to the outside from this point on. Note that
8141 -- this test must be done first as a body is also classified as a
8144 if In_Package_Body (Context) then
8145 Placement := Body_State_Space;
8148 -- The private part of a package is a cut off point for the
8149 -- traversal as the item cannot be visible to the outside from
8152 elsif In_Private_Part (Context) then
8153 Placement := Private_State_Space;
8156 -- When the item appears in the visible state space of a package,
8157 -- continue to climb the scope stack as this may not be the final
8161 Placement := Visible_State_Space;
8163 -- The visible state space of a child unit acts as the proper
8164 -- placement of an item.
8166 if Is_Child_Unit (Context) then
8171 -- The item or its enclosing package appear in a construct that has
8175 Placement := Not_In_Package;
8179 Context := Scope (Context);
8181 end Find_Placement_In_State_Space;
8183 ------------------------
8184 -- Find_Specific_Type --
8185 ------------------------
8187 function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
8188 Typ : Entity_Id := Root_Type (CW);
8191 if Ekind (Typ) = E_Incomplete_Type then
8192 if From_Limited_With (Typ) then
8193 Typ := Non_Limited_View (Typ);
8195 Typ := Full_View (Typ);
8199 if Is_Private_Type (Typ)
8200 and then not Is_Tagged_Type (Typ)
8201 and then Present (Full_View (Typ))
8203 return Full_View (Typ);
8207 end Find_Specific_Type;
8209 -----------------------------
8210 -- Find_Static_Alternative --
8211 -----------------------------
8213 function Find_Static_Alternative (N : Node_Id) return Node_Id is
8214 Expr : constant Node_Id := Expression (N);
8215 Val : constant Uint := Expr_Value (Expr);
8220 Alt := First (Alternatives (N));
8223 if Nkind (Alt) /= N_Pragma then
8224 Choice := First (Discrete_Choices (Alt));
8225 while Present (Choice) loop
8227 -- Others choice, always matches
8229 if Nkind (Choice) = N_Others_Choice then
8232 -- Range, check if value is in the range
8234 elsif Nkind (Choice) = N_Range then
8236 Val >= Expr_Value (Low_Bound (Choice))
8238 Val <= Expr_Value (High_Bound (Choice));
8240 -- Choice is a subtype name. Note that we know it must
8241 -- be a static subtype, since otherwise it would have
8242 -- been diagnosed as illegal.
8244 elsif Is_Entity_Name (Choice)
8245 and then Is_Type (Entity (Choice))
8247 exit Search when Is_In_Range (Expr, Etype (Choice),
8248 Assume_Valid => False);
8250 -- Choice is a subtype indication
8252 elsif Nkind (Choice) = N_Subtype_Indication then
8254 C : constant Node_Id := Constraint (Choice);
8255 R : constant Node_Id := Range_Expression (C);
8259 Val >= Expr_Value (Low_Bound (R))
8261 Val <= Expr_Value (High_Bound (R));
8264 -- Choice is a simple expression
8267 exit Search when Val = Expr_Value (Choice);
8275 pragma Assert (Present (Alt));
8278 -- The above loop *must* terminate by finding a match, since we know the
8279 -- case statement is valid, and the value of the expression is known at
8280 -- compile time. When we fall out of the loop, Alt points to the
8281 -- alternative that we know will be selected at run time.
8284 end Find_Static_Alternative;
8290 function First_Actual (Node : Node_Id) return Node_Id is
8294 if No (Parameter_Associations (Node)) then
8298 N := First (Parameter_Associations (Node));
8300 if Nkind (N) = N_Parameter_Association then
8301 return First_Named_Actual (Node);
8311 function First_Global
8313 Global_Mode : Name_Id;
8314 Refined : Boolean := False) return Node_Id
8316 function First_From_Global_List
8318 Global_Mode : Name_Id := Name_Input) return Entity_Id;
8319 -- Get the first item with suitable mode from List
8321 ----------------------------
8322 -- First_From_Global_List --
8323 ----------------------------
8325 function First_From_Global_List
8327 Global_Mode : Name_Id := Name_Input) return Entity_Id
8332 -- Empty list (no global items)
8334 if Nkind (List) = N_Null then
8337 -- Single global item declaration (only input items)
8339 elsif Nkind_In (List, N_Expanded_Name,
8341 N_Selected_Component)
8343 if Global_Mode = Name_Input then
8349 -- Simple global list (only input items) or moded global list
8352 elsif Nkind (List) = N_Aggregate then
8353 if Present (Expressions (List)) then
8354 if Global_Mode = Name_Input then
8355 return First (Expressions (List));
8361 Assoc := First (Component_Associations (List));
8362 while Present (Assoc) loop
8364 -- When we find the desired mode in an association, call
8365 -- recursively First_From_Global_List as if the mode was
8366 -- Name_Input, in order to reuse the existing machinery
8367 -- for the other cases.
8369 if Chars (First (Choices (Assoc))) = Global_Mode then
8370 return First_From_Global_List (Expression (Assoc));
8379 -- To accommodate partial decoration of disabled SPARK features,
8380 -- this routine may be called with illegal input. If this is the
8381 -- case, do not raise Program_Error.
8386 end First_From_Global_List;
8390 Global : Node_Id := Empty;
8391 Body_Id : Entity_Id;
8394 pragma Assert (Global_Mode = Name_Input
8395 or else Global_Mode = Name_Output
8396 or else Global_Mode = Name_In_Out
8397 or else Global_Mode = Name_Proof_In);
8399 -- Retrieve the suitable pragma Global or Refined_Global. In the second
8400 -- case, it can only be located on the body entity.
8403 Body_Id := Subprogram_Body_Entity (Subp);
8404 if Present (Body_Id) then
8405 Global := Get_Pragma (Body_Id, Pragma_Refined_Global);
8408 Global := Get_Pragma (Subp, Pragma_Global);
8411 -- No corresponding global if pragma is not present
8416 -- Otherwise retrieve the corresponding list of items depending on the
8420 return First_From_Global_List
8421 (Expression (Get_Argument (Global, Subp)), Global_Mode);
8429 function Fix_Msg (Id : Entity_Id; Msg : String) return String is
8430 Is_Task : constant Boolean :=
8431 Ekind_In (Id, E_Task_Body, E_Task_Type)
8432 or else Is_Single_Task_Object (Id);
8433 Msg_Last : constant Natural := Msg'Last;
8434 Msg_Index : Natural;
8435 Res : String (Msg'Range) := (others => ' ');
8436 Res_Index : Natural;
8439 -- Copy all characters from the input message Msg to result Res with
8440 -- suitable replacements.
8442 Msg_Index := Msg'First;
8443 Res_Index := Res'First;
8444 while Msg_Index <= Msg_Last loop
8446 -- Replace "subprogram" with a different word
8448 if Msg_Index <= Msg_Last - 10
8449 and then Msg (Msg_Index .. Msg_Index + 9) = "subprogram"
8451 if Ekind_In (Id, E_Entry, E_Entry_Family) then
8452 Res (Res_Index .. Res_Index + 4) := "entry";
8453 Res_Index := Res_Index + 5;
8456 Res (Res_Index .. Res_Index + 8) := "task type";
8457 Res_Index := Res_Index + 9;
8460 Res (Res_Index .. Res_Index + 9) := "subprogram";
8461 Res_Index := Res_Index + 10;
8464 Msg_Index := Msg_Index + 10;
8466 -- Replace "protected" with a different word
8468 elsif Msg_Index <= Msg_Last - 9
8469 and then Msg (Msg_Index .. Msg_Index + 8) = "protected"
8472 Res (Res_Index .. Res_Index + 3) := "task";
8473 Res_Index := Res_Index + 4;
8474 Msg_Index := Msg_Index + 9;
8476 -- Otherwise copy the character
8479 Res (Res_Index) := Msg (Msg_Index);
8480 Msg_Index := Msg_Index + 1;
8481 Res_Index := Res_Index + 1;
8485 return Res (Res'First .. Res_Index - 1);
8488 -------------------------
8489 -- From_Nested_Package --
8490 -------------------------
8492 function From_Nested_Package (T : Entity_Id) return Boolean is
8493 Pack : constant Entity_Id := Scope (T);
8497 Ekind (Pack) = E_Package
8498 and then not Is_Frozen (Pack)
8499 and then not Scope_Within_Or_Same (Current_Scope, Pack)
8500 and then In_Open_Scopes (Scope (Pack));
8501 end From_Nested_Package;
8503 -----------------------
8504 -- Gather_Components --
8505 -----------------------
8507 procedure Gather_Components
8509 Comp_List : Node_Id;
8510 Governed_By : List_Id;
8512 Report_Errors : out Boolean)
8516 Discrete_Choice : Node_Id;
8517 Comp_Item : Node_Id;
8519 Discrim : Entity_Id;
8520 Discrim_Name : Node_Id;
8521 Discrim_Value : Node_Id;
8524 Report_Errors := False;
8526 if No (Comp_List) or else Null_Present (Comp_List) then
8529 elsif Present (Component_Items (Comp_List)) then
8530 Comp_Item := First (Component_Items (Comp_List));
8536 while Present (Comp_Item) loop
8538 -- Skip the tag of a tagged record, the interface tags, as well
8539 -- as all items that are not user components (anonymous types,
8540 -- rep clauses, Parent field, controller field).
8542 if Nkind (Comp_Item) = N_Component_Declaration then
8544 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
8546 if not Is_Tag (Comp) and then Chars (Comp) /= Name_uParent then
8547 Append_Elmt (Comp, Into);
8555 if No (Variant_Part (Comp_List)) then
8558 Discrim_Name := Name (Variant_Part (Comp_List));
8559 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
8562 -- Look for the discriminant that governs this variant part.
8563 -- The discriminant *must* be in the Governed_By List
8565 Assoc := First (Governed_By);
8566 Find_Constraint : loop
8567 Discrim := First (Choices (Assoc));
8568 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
8569 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
8571 Chars (Corresponding_Discriminant (Entity (Discrim))) =
8572 Chars (Discrim_Name))
8573 or else Chars (Original_Record_Component (Entity (Discrim)))
8574 = Chars (Discrim_Name);
8576 if No (Next (Assoc)) then
8577 if not Is_Constrained (Typ)
8578 and then Is_Derived_Type (Typ)
8579 and then Present (Stored_Constraint (Typ))
8581 -- If the type is a tagged type with inherited discriminants,
8582 -- use the stored constraint on the parent in order to find
8583 -- the values of discriminants that are otherwise hidden by an
8584 -- explicit constraint. Renamed discriminants are handled in
8587 -- If several parent discriminants are renamed by a single
8588 -- discriminant of the derived type, the call to obtain the
8589 -- Corresponding_Discriminant field only retrieves the last
8590 -- of them. We recover the constraint on the others from the
8591 -- Stored_Constraint as well.
8598 D := First_Discriminant (Etype (Typ));
8599 C := First_Elmt (Stored_Constraint (Typ));
8600 while Present (D) and then Present (C) loop
8601 if Chars (Discrim_Name) = Chars (D) then
8602 if Is_Entity_Name (Node (C))
8603 and then Entity (Node (C)) = Entity (Discrim)
8605 -- D is renamed by Discrim, whose value is given in
8612 Make_Component_Association (Sloc (Typ),
8614 (New_Occurrence_Of (D, Sloc (Typ))),
8615 Duplicate_Subexpr_No_Checks (Node (C)));
8617 exit Find_Constraint;
8620 Next_Discriminant (D);
8627 if No (Next (Assoc)) then
8628 Error_Msg_NE (" missing value for discriminant&",
8629 First (Governed_By), Discrim_Name);
8630 Report_Errors := True;
8635 end loop Find_Constraint;
8637 Discrim_Value := Expression (Assoc);
8639 if not Is_OK_Static_Expression (Discrim_Value) then
8641 -- If the variant part is governed by a discriminant of the type
8642 -- this is an error. If the variant part and the discriminant are
8643 -- inherited from an ancestor this is legal (AI05-120) unless the
8644 -- components are being gathered for an aggregate, in which case
8645 -- the caller must check Report_Errors.
8647 if Scope (Original_Record_Component
8648 ((Entity (First (Choices (Assoc)))))) = Typ
8651 ("value for discriminant & must be static!",
8652 Discrim_Value, Discrim);
8653 Why_Not_Static (Discrim_Value);
8656 Report_Errors := True;
8660 Search_For_Discriminant_Value : declare
8666 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
8669 Find_Discrete_Value : while Present (Variant) loop
8670 Discrete_Choice := First (Discrete_Choices (Variant));
8671 while Present (Discrete_Choice) loop
8672 exit Find_Discrete_Value when
8673 Nkind (Discrete_Choice) = N_Others_Choice;
8675 Get_Index_Bounds (Discrete_Choice, Low, High);
8677 UI_Low := Expr_Value (Low);
8678 UI_High := Expr_Value (High);
8680 exit Find_Discrete_Value when
8681 UI_Low <= UI_Discrim_Value
8683 UI_High >= UI_Discrim_Value;
8685 Next (Discrete_Choice);
8688 Next_Non_Pragma (Variant);
8689 end loop Find_Discrete_Value;
8690 end Search_For_Discriminant_Value;
8692 -- The case statement must include a variant that corresponds to the
8693 -- value of the discriminant, unless the discriminant type has a
8694 -- static predicate. In that case the absence of an others_choice that
8695 -- would cover this value becomes a run-time error (3.8,1 (21.1/2)).
8698 and then not Has_Static_Predicate (Etype (Discrim_Name))
8701 ("value of discriminant & is out of range", Discrim_Value, Discrim);
8702 Report_Errors := True;
8706 -- If we have found the corresponding choice, recursively add its
8707 -- components to the Into list. The nested components are part of
8708 -- the same record type.
8710 if Present (Variant) then
8712 (Typ, Component_List (Variant), Governed_By, Into, Report_Errors);
8714 end Gather_Components;
8716 ------------------------
8717 -- Get_Actual_Subtype --
8718 ------------------------
8720 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
8721 Typ : constant Entity_Id := Etype (N);
8722 Utyp : Entity_Id := Underlying_Type (Typ);
8731 -- If what we have is an identifier that references a subprogram
8732 -- formal, or a variable or constant object, then we get the actual
8733 -- subtype from the referenced entity if one has been built.
8735 if Nkind (N) = N_Identifier
8737 (Is_Formal (Entity (N))
8738 or else Ekind (Entity (N)) = E_Constant
8739 or else Ekind (Entity (N)) = E_Variable)
8740 and then Present (Actual_Subtype (Entity (N)))
8742 return Actual_Subtype (Entity (N));
8744 -- Actual subtype of unchecked union is always itself. We never need
8745 -- the "real" actual subtype. If we did, we couldn't get it anyway
8746 -- because the discriminant is not available. The restrictions on
8747 -- Unchecked_Union are designed to make sure that this is OK.
8749 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
8752 -- Here for the unconstrained case, we must find actual subtype
8753 -- No actual subtype is available, so we must build it on the fly.
8755 -- Checking the type, not the underlying type, for constrainedness
8756 -- seems to be necessary. Maybe all the tests should be on the type???
8758 elsif (not Is_Constrained (Typ))
8759 and then (Is_Array_Type (Utyp)
8760 or else (Is_Record_Type (Utyp)
8761 and then Has_Discriminants (Utyp)))
8762 and then not Has_Unknown_Discriminants (Utyp)
8763 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
8765 -- Nothing to do if in spec expression (why not???)
8767 if In_Spec_Expression then
8770 elsif Is_Private_Type (Typ) and then not Has_Discriminants (Typ) then
8772 -- If the type has no discriminants, there is no subtype to
8773 -- build, even if the underlying type is discriminated.
8777 -- Else build the actual subtype
8780 Decl := Build_Actual_Subtype (Typ, N);
8781 Atyp := Defining_Identifier (Decl);
8783 -- If Build_Actual_Subtype generated a new declaration then use it
8787 -- The actual subtype is an Itype, so analyze the declaration,
8788 -- but do not attach it to the tree, to get the type defined.
8790 Set_Parent (Decl, N);
8791 Set_Is_Itype (Atyp);
8792 Analyze (Decl, Suppress => All_Checks);
8793 Set_Associated_Node_For_Itype (Atyp, N);
8794 Set_Has_Delayed_Freeze (Atyp, False);
8796 -- We need to freeze the actual subtype immediately. This is
8797 -- needed, because otherwise this Itype will not get frozen
8798 -- at all, and it is always safe to freeze on creation because
8799 -- any associated types must be frozen at this point.
8801 Freeze_Itype (Atyp, N);
8804 -- Otherwise we did not build a declaration, so return original
8811 -- For all remaining cases, the actual subtype is the same as
8812 -- the nominal type.
8817 end Get_Actual_Subtype;
8819 -------------------------------------
8820 -- Get_Actual_Subtype_If_Available --
8821 -------------------------------------
8823 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
8824 Typ : constant Entity_Id := Etype (N);
8827 -- If what we have is an identifier that references a subprogram
8828 -- formal, or a variable or constant object, then we get the actual
8829 -- subtype from the referenced entity if one has been built.
8831 if Nkind (N) = N_Identifier
8833 (Is_Formal (Entity (N))
8834 or else Ekind (Entity (N)) = E_Constant
8835 or else Ekind (Entity (N)) = E_Variable)
8836 and then Present (Actual_Subtype (Entity (N)))
8838 return Actual_Subtype (Entity (N));
8840 -- Otherwise the Etype of N is returned unchanged
8845 end Get_Actual_Subtype_If_Available;
8847 ------------------------
8848 -- Get_Body_From_Stub --
8849 ------------------------
8851 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
8853 return Proper_Body (Unit (Library_Unit (N)));
8854 end Get_Body_From_Stub;
8856 ---------------------
8857 -- Get_Cursor_Type --
8858 ---------------------
8860 function Get_Cursor_Type
8862 Typ : Entity_Id) return Entity_Id
8866 First_Op : Entity_Id;
8870 -- If error already detected, return
8872 if Error_Posted (Aspect) then
8876 -- The cursor type for an Iterable aspect is the return type of a
8877 -- non-overloaded First primitive operation. Locate association for
8880 Assoc := First (Component_Associations (Expression (Aspect)));
8882 while Present (Assoc) loop
8883 if Chars (First (Choices (Assoc))) = Name_First then
8884 First_Op := Expression (Assoc);
8891 if First_Op = Any_Id then
8892 Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
8898 -- Locate function with desired name and profile in scope of type
8899 -- In the rare case where the type is an integer type, a base type
8900 -- is created for it, check that the base type of the first formal
8901 -- of First matches the base type of the domain.
8903 Func := First_Entity (Scope (Typ));
8904 while Present (Func) loop
8905 if Chars (Func) = Chars (First_Op)
8906 and then Ekind (Func) = E_Function
8907 and then Present (First_Formal (Func))
8908 and then Base_Type (Etype (First_Formal (Func))) = Base_Type (Typ)
8909 and then No (Next_Formal (First_Formal (Func)))
8911 if Cursor /= Any_Type then
8913 ("Operation First for iterable type must be unique", Aspect);
8916 Cursor := Etype (Func);
8923 -- If not found, no way to resolve remaining primitives.
8925 if Cursor = Any_Type then
8927 ("No legal primitive operation First for Iterable type", Aspect);
8931 end Get_Cursor_Type;
8933 function Get_Cursor_Type (Typ : Entity_Id) return Entity_Id is
8935 return Etype (Get_Iterable_Type_Primitive (Typ, Name_First));
8936 end Get_Cursor_Type;
8938 -------------------------------
8939 -- Get_Default_External_Name --
8940 -------------------------------
8942 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
8944 Get_Decoded_Name_String (Chars (E));
8946 if Opt.External_Name_Imp_Casing = Uppercase then
8947 Set_Casing (All_Upper_Case);
8949 Set_Casing (All_Lower_Case);
8953 Make_String_Literal (Sloc (E),
8954 Strval => String_From_Name_Buffer);
8955 end Get_Default_External_Name;
8957 --------------------------
8958 -- Get_Enclosing_Object --
8959 --------------------------
8961 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
8963 if Is_Entity_Name (N) then
8967 when N_Indexed_Component
8968 | N_Selected_Component
8971 -- If not generating code, a dereference may be left implicit.
8972 -- In thoses cases, return Empty.
8974 if Is_Access_Type (Etype (Prefix (N))) then
8977 return Get_Enclosing_Object (Prefix (N));
8980 when N_Type_Conversion =>
8981 return Get_Enclosing_Object (Expression (N));
8987 end Get_Enclosing_Object;
8989 ---------------------------
8990 -- Get_Enum_Lit_From_Pos --
8991 ---------------------------
8993 function Get_Enum_Lit_From_Pos
8996 Loc : Source_Ptr) return Node_Id
8998 Btyp : Entity_Id := Base_Type (T);
9003 -- In the case where the literal is of type Character, Wide_Character
9004 -- or Wide_Wide_Character or of a type derived from them, there needs
9005 -- to be some special handling since there is no explicit chain of
9006 -- literals to search. Instead, an N_Character_Literal node is created
9007 -- with the appropriate Char_Code and Chars fields.
9009 if Is_Standard_Character_Type (T) then
9010 Set_Character_Literal_Name (UI_To_CC (Pos));
9013 Make_Character_Literal (Loc,
9015 Char_Literal_Value => Pos);
9017 -- For all other cases, we have a complete table of literals, and
9018 -- we simply iterate through the chain of literal until the one
9019 -- with the desired position value is found.
9022 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
9023 Btyp := Full_View (Btyp);
9026 Lit := First_Literal (Btyp);
9027 for J in 1 .. UI_To_Int (Pos) loop
9030 -- If Lit is Empty, Pos is not in range, so raise Constraint_Error
9031 -- inside the loop to avoid calling Next_Literal on Empty.
9034 raise Constraint_Error;
9038 -- Create a new node from Lit, with source location provided by Loc
9039 -- if not equal to No_Location, or by copying the source location of
9044 if LLoc = No_Location then
9048 return New_Occurrence_Of (Lit, LLoc);
9050 end Get_Enum_Lit_From_Pos;
9052 ------------------------
9053 -- Get_Generic_Entity --
9054 ------------------------
9056 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
9057 Ent : constant Entity_Id := Entity (Name (N));
9059 if Present (Renamed_Object (Ent)) then
9060 return Renamed_Object (Ent);
9064 end Get_Generic_Entity;
9066 -------------------------------------
9067 -- Get_Incomplete_View_Of_Ancestor --
9068 -------------------------------------
9070 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
9071 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
9072 Par_Scope : Entity_Id;
9073 Par_Type : Entity_Id;
9076 -- The incomplete view of an ancestor is only relevant for private
9077 -- derived types in child units.
9079 if not Is_Derived_Type (E)
9080 or else not Is_Child_Unit (Cur_Unit)
9085 Par_Scope := Scope (Cur_Unit);
9086 if No (Par_Scope) then
9090 Par_Type := Etype (Base_Type (E));
9092 -- Traverse list of ancestor types until we find one declared in
9093 -- a parent or grandparent unit (two levels seem sufficient).
9095 while Present (Par_Type) loop
9096 if Scope (Par_Type) = Par_Scope
9097 or else Scope (Par_Type) = Scope (Par_Scope)
9101 elsif not Is_Derived_Type (Par_Type) then
9105 Par_Type := Etype (Base_Type (Par_Type));
9109 -- If none found, there is no relevant ancestor type.
9113 end Get_Incomplete_View_Of_Ancestor;
9115 ----------------------
9116 -- Get_Index_Bounds --
9117 ----------------------
9119 procedure Get_Index_Bounds
9123 Use_Full_View : Boolean := False)
9125 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id;
9126 -- Obtain the scalar range of type Typ. If flag Use_Full_View is set and
9127 -- Typ qualifies, the scalar range is obtained from the full view of the
9130 --------------------------
9131 -- Scalar_Range_Of_Type --
9132 --------------------------
9134 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id is
9135 T : Entity_Id := Typ;
9138 if Use_Full_View and then Present (Full_View (T)) then
9142 return Scalar_Range (T);
9143 end Scalar_Range_Of_Type;
9147 Kind : constant Node_Kind := Nkind (N);
9150 -- Start of processing for Get_Index_Bounds
9153 if Kind = N_Range then
9155 H := High_Bound (N);
9157 elsif Kind = N_Subtype_Indication then
9158 Rng := Range_Expression (Constraint (N));
9166 L := Low_Bound (Range_Expression (Constraint (N)));
9167 H := High_Bound (Range_Expression (Constraint (N)));
9170 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
9171 Rng := Scalar_Range_Of_Type (Entity (N));
9173 if Error_Posted (Rng) then
9177 elsif Nkind (Rng) = N_Subtype_Indication then
9178 Get_Index_Bounds (Rng, L, H);
9181 L := Low_Bound (Rng);
9182 H := High_Bound (Rng);
9186 -- N is an expression, indicating a range with one value
9191 end Get_Index_Bounds;
9193 -----------------------------
9194 -- Get_Interfacing_Aspects --
9195 -----------------------------
9197 procedure Get_Interfacing_Aspects
9198 (Iface_Asp : Node_Id;
9199 Conv_Asp : out Node_Id;
9200 EN_Asp : out Node_Id;
9201 Expo_Asp : out Node_Id;
9202 Imp_Asp : out Node_Id;
9203 LN_Asp : out Node_Id;
9204 Do_Checks : Boolean := False)
9206 procedure Save_Or_Duplication_Error
9208 To : in out Node_Id);
9209 -- Save the value of aspect Asp in node To. If To already has a value,
9210 -- then this is considered a duplicate use of aspect. Emit an error if
9211 -- flag Do_Checks is set.
9213 -------------------------------
9214 -- Save_Or_Duplication_Error --
9215 -------------------------------
9217 procedure Save_Or_Duplication_Error
9219 To : in out Node_Id)
9222 -- Detect an extra aspect and issue an error
9224 if Present (To) then
9226 Error_Msg_Name_1 := Chars (Identifier (Asp));
9227 Error_Msg_Sloc := Sloc (To);
9228 Error_Msg_N ("aspect % previously given #", Asp);
9231 -- Otherwise capture the aspect
9236 end Save_Or_Duplication_Error;
9243 -- The following variables capture each individual aspect
9245 Conv : Node_Id := Empty;
9246 EN : Node_Id := Empty;
9247 Expo : Node_Id := Empty;
9248 Imp : Node_Id := Empty;
9249 LN : Node_Id := Empty;
9251 -- Start of processing for Get_Interfacing_Aspects
9254 -- The input interfacing aspect should reside in an aspect specification
9257 pragma Assert (Is_List_Member (Iface_Asp));
9259 -- Examine the aspect specifications of the related entity. Find and
9260 -- capture all interfacing aspects. Detect duplicates and emit errors
9263 Asp := First (List_Containing (Iface_Asp));
9264 while Present (Asp) loop
9265 Asp_Id := Get_Aspect_Id (Asp);
9267 if Asp_Id = Aspect_Convention then
9268 Save_Or_Duplication_Error (Asp, Conv);
9270 elsif Asp_Id = Aspect_External_Name then
9271 Save_Or_Duplication_Error (Asp, EN);
9273 elsif Asp_Id = Aspect_Export then
9274 Save_Or_Duplication_Error (Asp, Expo);
9276 elsif Asp_Id = Aspect_Import then
9277 Save_Or_Duplication_Error (Asp, Imp);
9279 elsif Asp_Id = Aspect_Link_Name then
9280 Save_Or_Duplication_Error (Asp, LN);
9291 end Get_Interfacing_Aspects;
9293 ---------------------------------
9294 -- Get_Iterable_Type_Primitive --
9295 ---------------------------------
9297 function Get_Iterable_Type_Primitive
9299 Nam : Name_Id) return Entity_Id
9301 Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
9309 Assoc := First (Component_Associations (Funcs));
9310 while Present (Assoc) loop
9311 if Chars (First (Choices (Assoc))) = Nam then
9312 return Entity (Expression (Assoc));
9315 Assoc := Next (Assoc);
9320 end Get_Iterable_Type_Primitive;
9322 ----------------------------------
9323 -- Get_Library_Unit_Name_string --
9324 ----------------------------------
9326 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
9327 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
9330 Get_Unit_Name_String (Unit_Name_Id);
9332 -- Remove seven last character (" (spec)" or " (body)")
9334 Name_Len := Name_Len - 7;
9335 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
9336 end Get_Library_Unit_Name_String;
9338 --------------------------
9339 -- Get_Max_Queue_Length --
9340 --------------------------
9342 function Get_Max_Queue_Length (Id : Entity_Id) return Uint is
9343 pragma Assert (Is_Entry (Id));
9344 Prag : constant Entity_Id := Get_Pragma (Id, Pragma_Max_Queue_Length);
9347 -- A value of 0 represents no maximum specified, and entries and entry
9348 -- families with no Max_Queue_Length aspect or pragma default to it.
9350 if not Present (Prag) then
9354 return Intval (Expression (First (Pragma_Argument_Associations (Prag))));
9355 end Get_Max_Queue_Length;
9357 ------------------------
9358 -- Get_Name_Entity_Id --
9359 ------------------------
9361 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
9363 return Entity_Id (Get_Name_Table_Int (Id));
9364 end Get_Name_Entity_Id;
9366 ------------------------------
9367 -- Get_Name_From_CTC_Pragma --
9368 ------------------------------
9370 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
9371 Arg : constant Node_Id :=
9372 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
9374 return Strval (Expr_Value_S (Arg));
9375 end Get_Name_From_CTC_Pragma;
9377 -----------------------
9378 -- Get_Parent_Entity --
9379 -----------------------
9381 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
9383 if Nkind (Unit) = N_Package_Body
9384 and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
9386 return Defining_Entity
9387 (Specification (Instance_Spec (Original_Node (Unit))));
9388 elsif Nkind (Unit) = N_Package_Instantiation then
9389 return Defining_Entity (Specification (Instance_Spec (Unit)));
9391 return Defining_Entity (Unit);
9393 end Get_Parent_Entity;
9399 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
9401 return Get_Pragma_Id (Pragma_Name_Unmapped (N));
9404 ------------------------
9405 -- Get_Qualified_Name --
9406 ------------------------
9408 function Get_Qualified_Name
9410 Suffix : Entity_Id := Empty) return Name_Id
9412 Suffix_Nam : Name_Id := No_Name;
9415 if Present (Suffix) then
9416 Suffix_Nam := Chars (Suffix);
9419 return Get_Qualified_Name (Chars (Id), Suffix_Nam, Scope (Id));
9420 end Get_Qualified_Name;
9422 function Get_Qualified_Name
9424 Suffix : Name_Id := No_Name;
9425 Scop : Entity_Id := Current_Scope) return Name_Id
9427 procedure Add_Scope (S : Entity_Id);
9428 -- Add the fully qualified form of scope S to the name buffer. The
9436 procedure Add_Scope (S : Entity_Id) is
9441 elsif S = Standard_Standard then
9445 Add_Scope (Scope (S));
9446 Get_Name_String_And_Append (Chars (S));
9447 Add_Str_To_Name_Buffer ("__");
9451 -- Start of processing for Get_Qualified_Name
9457 -- Append the base name after all scopes have been chained
9459 Get_Name_String_And_Append (Nam);
9461 -- Append the suffix (if present)
9463 if Suffix /= No_Name then
9464 Add_Str_To_Name_Buffer ("__");
9465 Get_Name_String_And_Append (Suffix);
9469 end Get_Qualified_Name;
9471 -----------------------
9472 -- Get_Reason_String --
9473 -----------------------
9475 procedure Get_Reason_String (N : Node_Id) is
9477 if Nkind (N) = N_String_Literal then
9478 Store_String_Chars (Strval (N));
9480 elsif Nkind (N) = N_Op_Concat then
9481 Get_Reason_String (Left_Opnd (N));
9482 Get_Reason_String (Right_Opnd (N));
9484 -- If not of required form, error
9488 ("Reason for pragma Warnings has wrong form", N);
9490 ("\must be string literal or concatenation of string literals", N);
9493 end Get_Reason_String;
9495 --------------------------------
9496 -- Get_Reference_Discriminant --
9497 --------------------------------
9499 function Get_Reference_Discriminant (Typ : Entity_Id) return Entity_Id is
9503 D := First_Discriminant (Typ);
9504 while Present (D) loop
9505 if Has_Implicit_Dereference (D) then
9508 Next_Discriminant (D);
9512 end Get_Reference_Discriminant;
9514 ---------------------------
9515 -- Get_Referenced_Object --
9516 ---------------------------
9518 function Get_Referenced_Object (N : Node_Id) return Node_Id is
9523 while Is_Entity_Name (R)
9524 and then Present (Renamed_Object (Entity (R)))
9526 R := Renamed_Object (Entity (R));
9530 end Get_Referenced_Object;
9532 ------------------------
9533 -- Get_Renamed_Entity --
9534 ------------------------
9536 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
9541 while Present (Renamed_Entity (R)) loop
9542 R := Renamed_Entity (R);
9546 end Get_Renamed_Entity;
9548 -----------------------
9549 -- Get_Return_Object --
9550 -----------------------
9552 function Get_Return_Object (N : Node_Id) return Entity_Id is
9556 Decl := First (Return_Object_Declarations (N));
9557 while Present (Decl) loop
9558 exit when Nkind (Decl) = N_Object_Declaration
9559 and then Is_Return_Object (Defining_Identifier (Decl));
9563 pragma Assert (Present (Decl));
9564 return Defining_Identifier (Decl);
9565 end Get_Return_Object;
9567 ---------------------------
9568 -- Get_Subprogram_Entity --
9569 ---------------------------
9571 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
9573 Subp_Id : Entity_Id;
9576 if Nkind (Nod) = N_Accept_Statement then
9577 Subp := Entry_Direct_Name (Nod);
9579 elsif Nkind (Nod) = N_Slice then
9580 Subp := Prefix (Nod);
9586 -- Strip the subprogram call
9589 if Nkind_In (Subp, N_Explicit_Dereference,
9590 N_Indexed_Component,
9591 N_Selected_Component)
9593 Subp := Prefix (Subp);
9595 elsif Nkind_In (Subp, N_Type_Conversion,
9596 N_Unchecked_Type_Conversion)
9598 Subp := Expression (Subp);
9605 -- Extract the entity of the subprogram call
9607 if Is_Entity_Name (Subp) then
9608 Subp_Id := Entity (Subp);
9610 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
9611 Subp_Id := Directly_Designated_Type (Subp_Id);
9614 if Is_Subprogram (Subp_Id) then
9620 -- The search did not find a construct that denotes a subprogram
9625 end Get_Subprogram_Entity;
9627 -----------------------------
9628 -- Get_Task_Body_Procedure --
9629 -----------------------------
9631 function Get_Task_Body_Procedure (E : Entity_Id) return Entity_Id is
9633 -- Note: A task type may be the completion of a private type with
9634 -- discriminants. When performing elaboration checks on a task
9635 -- declaration, the current view of the type may be the private one,
9636 -- and the procedure that holds the body of the task is held in its
9639 -- This is an odd function, why not have Task_Body_Procedure do
9640 -- the following digging???
9642 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
9643 end Get_Task_Body_Procedure;
9645 -------------------------
9646 -- Get_User_Defined_Eq --
9647 -------------------------
9649 function Get_User_Defined_Eq (E : Entity_Id) return Entity_Id is
9654 Prim := First_Elmt (Collect_Primitive_Operations (E));
9655 while Present (Prim) loop
9658 if Chars (Op) = Name_Op_Eq
9659 and then Etype (Op) = Standard_Boolean
9660 and then Etype (First_Formal (Op)) = E
9661 and then Etype (Next_Formal (First_Formal (Op))) = E
9670 end Get_User_Defined_Eq;
9678 Priv_Typ : out Entity_Id;
9679 Full_Typ : out Entity_Id;
9680 Full_Base : out Entity_Id;
9681 CRec_Typ : out Entity_Id)
9683 IP_View : Entity_Id;
9686 -- Assume that none of the views can be recovered
9693 -- The input type is the corresponding record type of a protected or a
9696 if Ekind (Typ) = E_Record_Type
9697 and then Is_Concurrent_Record_Type (Typ)
9700 Full_Typ := Corresponding_Concurrent_Type (CRec_Typ);
9701 Full_Base := Base_Type (Full_Typ);
9702 Priv_Typ := Incomplete_Or_Partial_View (Full_Typ);
9704 -- Otherwise the input type denotes an arbitrary type
9707 IP_View := Incomplete_Or_Partial_View (Typ);
9709 -- The input type denotes the full view of a private type
9711 if Present (IP_View) then
9712 Priv_Typ := IP_View;
9715 -- The input type is a private type
9717 elsif Is_Private_Type (Typ) then
9719 Full_Typ := Full_View (Priv_Typ);
9721 -- Otherwise the input type does not have any views
9727 if Present (Full_Typ) then
9728 Full_Base := Base_Type (Full_Typ);
9730 if Ekind_In (Full_Typ, E_Protected_Type, E_Task_Type) then
9731 CRec_Typ := Corresponding_Record_Type (Full_Typ);
9737 -----------------------
9738 -- Has_Access_Values --
9739 -----------------------
9741 function Has_Access_Values (T : Entity_Id) return Boolean is
9742 Typ : constant Entity_Id := Underlying_Type (T);
9745 -- Case of a private type which is not completed yet. This can only
9746 -- happen in the case of a generic format type appearing directly, or
9747 -- as a component of the type to which this function is being applied
9748 -- at the top level. Return False in this case, since we certainly do
9749 -- not know that the type contains access types.
9754 elsif Is_Access_Type (Typ) then
9757 elsif Is_Array_Type (Typ) then
9758 return Has_Access_Values (Component_Type (Typ));
9760 elsif Is_Record_Type (Typ) then
9765 -- Loop to Check components
9767 Comp := First_Component_Or_Discriminant (Typ);
9768 while Present (Comp) loop
9770 -- Check for access component, tag field does not count, even
9771 -- though it is implemented internally using an access type.
9773 if Has_Access_Values (Etype (Comp))
9774 and then Chars (Comp) /= Name_uTag
9779 Next_Component_Or_Discriminant (Comp);
9788 end Has_Access_Values;
9790 ------------------------------
9791 -- Has_Compatible_Alignment --
9792 ------------------------------
9794 function Has_Compatible_Alignment
9797 Layout_Done : Boolean) return Alignment_Result
9799 function Has_Compatible_Alignment_Internal
9802 Layout_Done : Boolean;
9803 Default : Alignment_Result) return Alignment_Result;
9804 -- This is the internal recursive function that actually does the work.
9805 -- There is one additional parameter, which says what the result should
9806 -- be if no alignment information is found, and there is no definite
9807 -- indication of compatible alignments. At the outer level, this is set
9808 -- to Unknown, but for internal recursive calls in the case where types
9809 -- are known to be correct, it is set to Known_Compatible.
9811 ---------------------------------------
9812 -- Has_Compatible_Alignment_Internal --
9813 ---------------------------------------
9815 function Has_Compatible_Alignment_Internal
9818 Layout_Done : Boolean;
9819 Default : Alignment_Result) return Alignment_Result
9821 Result : Alignment_Result := Known_Compatible;
9822 -- Holds the current status of the result. Note that once a value of
9823 -- Known_Incompatible is set, it is sticky and does not get changed
9824 -- to Unknown (the value in Result only gets worse as we go along,
9827 Offs : Uint := No_Uint;
9828 -- Set to a factor of the offset from the base object when Expr is a
9829 -- selected or indexed component, based on Component_Bit_Offset and
9830 -- Component_Size respectively. A negative value is used to represent
9831 -- a value which is not known at compile time.
9833 procedure Check_Prefix;
9834 -- Checks the prefix recursively in the case where the expression
9835 -- is an indexed or selected component.
9837 procedure Set_Result (R : Alignment_Result);
9838 -- If R represents a worse outcome (unknown instead of known
9839 -- compatible, or known incompatible), then set Result to R.
9845 procedure Check_Prefix is
9847 -- The subtlety here is that in doing a recursive call to check
9848 -- the prefix, we have to decide what to do in the case where we
9849 -- don't find any specific indication of an alignment problem.
9851 -- At the outer level, we normally set Unknown as the result in
9852 -- this case, since we can only set Known_Compatible if we really
9853 -- know that the alignment value is OK, but for the recursive
9854 -- call, in the case where the types match, and we have not
9855 -- specified a peculiar alignment for the object, we are only
9856 -- concerned about suspicious rep clauses, the default case does
9857 -- not affect us, since the compiler will, in the absence of such
9858 -- rep clauses, ensure that the alignment is correct.
9860 if Default = Known_Compatible
9862 (Etype (Obj) = Etype (Expr)
9863 and then (Unknown_Alignment (Obj)
9865 Alignment (Obj) = Alignment (Etype (Obj))))
9868 (Has_Compatible_Alignment_Internal
9869 (Obj, Prefix (Expr), Layout_Done, Known_Compatible));
9871 -- In all other cases, we need a full check on the prefix
9875 (Has_Compatible_Alignment_Internal
9876 (Obj, Prefix (Expr), Layout_Done, Unknown));
9884 procedure Set_Result (R : Alignment_Result) is
9891 -- Start of processing for Has_Compatible_Alignment_Internal
9894 -- If Expr is a selected component, we must make sure there is no
9895 -- potentially troublesome component clause and that the record is
9896 -- not packed if the layout is not done.
9898 if Nkind (Expr) = N_Selected_Component then
9900 -- Packing generates unknown alignment if layout is not done
9902 if Is_Packed (Etype (Prefix (Expr))) and then not Layout_Done then
9903 Set_Result (Unknown);
9906 -- Check prefix and component offset
9909 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
9911 -- If Expr is an indexed component, we must make sure there is no
9912 -- potentially troublesome Component_Size clause and that the array
9913 -- is not bit-packed if the layout is not done.
9915 elsif Nkind (Expr) = N_Indexed_Component then
9917 Typ : constant Entity_Id := Etype (Prefix (Expr));
9920 -- Packing generates unknown alignment if layout is not done
9922 if Is_Bit_Packed_Array (Typ) and then not Layout_Done then
9923 Set_Result (Unknown);
9926 -- Check prefix and component offset (or at least size)
9929 Offs := Indexed_Component_Bit_Offset (Expr);
9930 if Offs = No_Uint then
9931 Offs := Component_Size (Typ);
9936 -- If we have a null offset, the result is entirely determined by
9937 -- the base object and has already been computed recursively.
9939 if Offs = Uint_0 then
9942 -- Case where we know the alignment of the object
9944 elsif Known_Alignment (Obj) then
9946 ObjA : constant Uint := Alignment (Obj);
9947 ExpA : Uint := No_Uint;
9948 SizA : Uint := No_Uint;
9951 -- If alignment of Obj is 1, then we are always OK
9954 Set_Result (Known_Compatible);
9956 -- Alignment of Obj is greater than 1, so we need to check
9959 -- If we have an offset, see if it is compatible
9961 if Offs /= No_Uint and Offs > Uint_0 then
9962 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
9963 Set_Result (Known_Incompatible);
9966 -- See if Expr is an object with known alignment
9968 elsif Is_Entity_Name (Expr)
9969 and then Known_Alignment (Entity (Expr))
9971 ExpA := Alignment (Entity (Expr));
9973 -- Otherwise, we can use the alignment of the type of
9974 -- Expr given that we already checked for
9975 -- discombobulating rep clauses for the cases of indexed
9976 -- and selected components above.
9978 elsif Known_Alignment (Etype (Expr)) then
9979 ExpA := Alignment (Etype (Expr));
9981 -- Otherwise the alignment is unknown
9984 Set_Result (Default);
9987 -- If we got an alignment, see if it is acceptable
9989 if ExpA /= No_Uint and then ExpA < ObjA then
9990 Set_Result (Known_Incompatible);
9993 -- If Expr is not a piece of a larger object, see if size
9994 -- is given. If so, check that it is not too small for the
9995 -- required alignment.
9997 if Offs /= No_Uint then
10000 -- See if Expr is an object with known size
10002 elsif Is_Entity_Name (Expr)
10003 and then Known_Static_Esize (Entity (Expr))
10005 SizA := Esize (Entity (Expr));
10007 -- Otherwise, we check the object size of the Expr type
10009 elsif Known_Static_Esize (Etype (Expr)) then
10010 SizA := Esize (Etype (Expr));
10013 -- If we got a size, see if it is a multiple of the Obj
10014 -- alignment, if not, then the alignment cannot be
10015 -- acceptable, since the size is always a multiple of the
10018 if SizA /= No_Uint then
10019 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
10020 Set_Result (Known_Incompatible);
10026 -- If we do not know required alignment, any non-zero offset is a
10027 -- potential problem (but certainly may be OK, so result is unknown).
10029 elsif Offs /= No_Uint then
10030 Set_Result (Unknown);
10032 -- If we can't find the result by direct comparison of alignment
10033 -- values, then there is still one case that we can determine known
10034 -- result, and that is when we can determine that the types are the
10035 -- same, and no alignments are specified. Then we known that the
10036 -- alignments are compatible, even if we don't know the alignment
10037 -- value in the front end.
10039 elsif Etype (Obj) = Etype (Expr) then
10041 -- Types are the same, but we have to check for possible size
10042 -- and alignments on the Expr object that may make the alignment
10043 -- different, even though the types are the same.
10045 if Is_Entity_Name (Expr) then
10047 -- First check alignment of the Expr object. Any alignment less
10048 -- than Maximum_Alignment is worrisome since this is the case
10049 -- where we do not know the alignment of Obj.
10051 if Known_Alignment (Entity (Expr))
10052 and then UI_To_Int (Alignment (Entity (Expr))) <
10053 Ttypes.Maximum_Alignment
10055 Set_Result (Unknown);
10057 -- Now check size of Expr object. Any size that is not an
10058 -- even multiple of Maximum_Alignment is also worrisome
10059 -- since it may cause the alignment of the object to be less
10060 -- than the alignment of the type.
10062 elsif Known_Static_Esize (Entity (Expr))
10064 (UI_To_Int (Esize (Entity (Expr))) mod
10065 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
10068 Set_Result (Unknown);
10070 -- Otherwise same type is decisive
10073 Set_Result (Known_Compatible);
10077 -- Another case to deal with is when there is an explicit size or
10078 -- alignment clause when the types are not the same. If so, then the
10079 -- result is Unknown. We don't need to do this test if the Default is
10080 -- Unknown, since that result will be set in any case.
10082 elsif Default /= Unknown
10083 and then (Has_Size_Clause (Etype (Expr))
10085 Has_Alignment_Clause (Etype (Expr)))
10087 Set_Result (Unknown);
10089 -- If no indication found, set default
10092 Set_Result (Default);
10095 -- Return worst result found
10098 end Has_Compatible_Alignment_Internal;
10100 -- Start of processing for Has_Compatible_Alignment
10103 -- If Obj has no specified alignment, then set alignment from the type
10104 -- alignment. Perhaps we should always do this, but for sure we should
10105 -- do it when there is an address clause since we can do more if the
10106 -- alignment is known.
10108 if Unknown_Alignment (Obj) then
10109 Set_Alignment (Obj, Alignment (Etype (Obj)));
10112 -- Now do the internal call that does all the work
10115 Has_Compatible_Alignment_Internal (Obj, Expr, Layout_Done, Unknown);
10116 end Has_Compatible_Alignment;
10118 ----------------------
10119 -- Has_Declarations --
10120 ----------------------
10122 function Has_Declarations (N : Node_Id) return Boolean is
10124 return Nkind_In (Nkind (N), N_Accept_Statement,
10126 N_Compilation_Unit_Aux,
10132 N_Package_Specification);
10133 end Has_Declarations;
10135 ---------------------------------
10136 -- Has_Defaulted_Discriminants --
10137 ---------------------------------
10139 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
10141 return Has_Discriminants (Typ)
10142 and then Present (First_Discriminant (Typ))
10143 and then Present (Discriminant_Default_Value
10144 (First_Discriminant (Typ)));
10145 end Has_Defaulted_Discriminants;
10147 -------------------
10148 -- Has_Denormals --
10149 -------------------
10151 function Has_Denormals (E : Entity_Id) return Boolean is
10153 return Is_Floating_Point_Type (E) and then Denorm_On_Target;
10156 -------------------------------------------
10157 -- Has_Discriminant_Dependent_Constraint --
10158 -------------------------------------------
10160 function Has_Discriminant_Dependent_Constraint
10161 (Comp : Entity_Id) return Boolean
10163 Comp_Decl : constant Node_Id := Parent (Comp);
10164 Subt_Indic : Node_Id;
10169 -- Discriminants can't depend on discriminants
10171 if Ekind (Comp) = E_Discriminant then
10175 Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl));
10177 if Nkind (Subt_Indic) = N_Subtype_Indication then
10178 Constr := Constraint (Subt_Indic);
10180 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
10181 Assn := First (Constraints (Constr));
10182 while Present (Assn) loop
10183 case Nkind (Assn) is
10186 | N_Subtype_Indication
10188 if Depends_On_Discriminant (Assn) then
10192 when N_Discriminant_Association =>
10193 if Depends_On_Discriminant (Expression (Assn)) then
10208 end Has_Discriminant_Dependent_Constraint;
10210 --------------------------------------
10211 -- Has_Effectively_Volatile_Profile --
10212 --------------------------------------
10214 function Has_Effectively_Volatile_Profile
10215 (Subp_Id : Entity_Id) return Boolean
10217 Formal : Entity_Id;
10220 -- Inspect the formal parameters looking for an effectively volatile
10223 Formal := First_Formal (Subp_Id);
10224 while Present (Formal) loop
10225 if Is_Effectively_Volatile (Etype (Formal)) then
10229 Next_Formal (Formal);
10232 -- Inspect the return type of functions
10234 if Ekind_In (Subp_Id, E_Function, E_Generic_Function)
10235 and then Is_Effectively_Volatile (Etype (Subp_Id))
10241 end Has_Effectively_Volatile_Profile;
10243 --------------------------
10244 -- Has_Enabled_Property --
10245 --------------------------
10247 function Has_Enabled_Property
10248 (Item_Id : Entity_Id;
10249 Property : Name_Id) return Boolean
10251 function Protected_Object_Has_Enabled_Property return Boolean;
10252 -- Determine whether a protected object denoted by Item_Id has the
10253 -- property enabled.
10255 function State_Has_Enabled_Property return Boolean;
10256 -- Determine whether a state denoted by Item_Id has the property enabled
10258 function Variable_Has_Enabled_Property return Boolean;
10259 -- Determine whether a variable denoted by Item_Id has the property
10262 -------------------------------------------
10263 -- Protected_Object_Has_Enabled_Property --
10264 -------------------------------------------
10266 function Protected_Object_Has_Enabled_Property return Boolean is
10267 Constits : constant Elist_Id := Part_Of_Constituents (Item_Id);
10268 Constit_Elmt : Elmt_Id;
10269 Constit_Id : Entity_Id;
10272 -- Protected objects always have the properties Async_Readers and
10273 -- Async_Writers (SPARK RM 7.1.2(16)).
10275 if Property = Name_Async_Readers
10276 or else Property = Name_Async_Writers
10280 -- Protected objects that have Part_Of components also inherit their
10281 -- properties Effective_Reads and Effective_Writes
10282 -- (SPARK RM 7.1.2(16)).
10284 elsif Present (Constits) then
10285 Constit_Elmt := First_Elmt (Constits);
10286 while Present (Constit_Elmt) loop
10287 Constit_Id := Node (Constit_Elmt);
10289 if Has_Enabled_Property (Constit_Id, Property) then
10293 Next_Elmt (Constit_Elmt);
10298 end Protected_Object_Has_Enabled_Property;
10300 --------------------------------
10301 -- State_Has_Enabled_Property --
10302 --------------------------------
10304 function State_Has_Enabled_Property return Boolean is
10305 Decl : constant Node_Id := Parent (Item_Id);
10309 Prop_Nam : Node_Id;
10313 -- The declaration of an external abstract state appears as an
10314 -- extension aggregate. If this is not the case, properties can never
10317 if Nkind (Decl) /= N_Extension_Aggregate then
10321 -- When External appears as a simple option, it automatically enables
10324 Opt := First (Expressions (Decl));
10325 while Present (Opt) loop
10326 if Nkind (Opt) = N_Identifier
10327 and then Chars (Opt) = Name_External
10335 -- When External specifies particular properties, inspect those and
10336 -- find the desired one (if any).
10338 Opt := First (Component_Associations (Decl));
10339 while Present (Opt) loop
10340 Opt_Nam := First (Choices (Opt));
10342 if Nkind (Opt_Nam) = N_Identifier
10343 and then Chars (Opt_Nam) = Name_External
10345 Props := Expression (Opt);
10347 -- Multiple properties appear as an aggregate
10349 if Nkind (Props) = N_Aggregate then
10351 -- Simple property form
10353 Prop := First (Expressions (Props));
10354 while Present (Prop) loop
10355 if Chars (Prop) = Property then
10362 -- Property with expression form
10364 Prop := First (Component_Associations (Props));
10365 while Present (Prop) loop
10366 Prop_Nam := First (Choices (Prop));
10368 -- The property can be represented in two ways:
10369 -- others => <value>
10370 -- <property> => <value>
10372 if Nkind (Prop_Nam) = N_Others_Choice
10373 or else (Nkind (Prop_Nam) = N_Identifier
10374 and then Chars (Prop_Nam) = Property)
10376 return Is_True (Expr_Value (Expression (Prop)));
10385 return Chars (Props) = Property;
10393 end State_Has_Enabled_Property;
10395 -----------------------------------
10396 -- Variable_Has_Enabled_Property --
10397 -----------------------------------
10399 function Variable_Has_Enabled_Property return Boolean is
10400 function Is_Enabled (Prag : Node_Id) return Boolean;
10401 -- Determine whether property pragma Prag (if present) denotes an
10402 -- enabled property.
10408 function Is_Enabled (Prag : Node_Id) return Boolean is
10412 if Present (Prag) then
10413 Arg1 := First (Pragma_Argument_Associations (Prag));
10415 -- The pragma has an optional Boolean expression, the related
10416 -- property is enabled only when the expression evaluates to
10419 if Present (Arg1) then
10420 return Is_True (Expr_Value (Get_Pragma_Arg (Arg1)));
10422 -- Otherwise the lack of expression enables the property by
10429 -- The property was never set in the first place
10438 AR : constant Node_Id :=
10439 Get_Pragma (Item_Id, Pragma_Async_Readers);
10440 AW : constant Node_Id :=
10441 Get_Pragma (Item_Id, Pragma_Async_Writers);
10442 ER : constant Node_Id :=
10443 Get_Pragma (Item_Id, Pragma_Effective_Reads);
10444 EW : constant Node_Id :=
10445 Get_Pragma (Item_Id, Pragma_Effective_Writes);
10447 -- Start of processing for Variable_Has_Enabled_Property
10450 -- A non-effectively volatile object can never possess external
10453 if not Is_Effectively_Volatile (Item_Id) then
10456 -- External properties related to variables come in two flavors -
10457 -- explicit and implicit. The explicit case is characterized by the
10458 -- presence of a property pragma with an optional Boolean flag. The
10459 -- property is enabled when the flag evaluates to True or the flag is
10460 -- missing altogether.
10462 elsif Property = Name_Async_Readers and then Is_Enabled (AR) then
10465 elsif Property = Name_Async_Writers and then Is_Enabled (AW) then
10468 elsif Property = Name_Effective_Reads and then Is_Enabled (ER) then
10471 elsif Property = Name_Effective_Writes and then Is_Enabled (EW) then
10474 -- The implicit case lacks all property pragmas
10476 elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then
10477 if Is_Protected_Type (Etype (Item_Id)) then
10478 return Protected_Object_Has_Enabled_Property;
10486 end Variable_Has_Enabled_Property;
10488 -- Start of processing for Has_Enabled_Property
10491 -- Abstract states and variables have a flexible scheme of specifying
10492 -- external properties.
10494 if Ekind (Item_Id) = E_Abstract_State then
10495 return State_Has_Enabled_Property;
10497 elsif Ekind (Item_Id) = E_Variable then
10498 return Variable_Has_Enabled_Property;
10500 -- By default, protected objects only have the properties Async_Readers
10501 -- and Async_Writers. If they have Part_Of components, they also inherit
10502 -- their properties Effective_Reads and Effective_Writes
10503 -- (SPARK RM 7.1.2(16)).
10505 elsif Ekind (Item_Id) = E_Protected_Object then
10506 return Protected_Object_Has_Enabled_Property;
10508 -- Otherwise a property is enabled when the related item is effectively
10512 return Is_Effectively_Volatile (Item_Id);
10514 end Has_Enabled_Property;
10516 -------------------------------------
10517 -- Has_Full_Default_Initialization --
10518 -------------------------------------
10520 function Has_Full_Default_Initialization (Typ : Entity_Id) return Boolean is
10525 -- A type subject to pragma Default_Initial_Condition is fully default
10526 -- initialized when the pragma appears with a non-null argument. Since
10527 -- any type may act as the full view of a private type, this check must
10528 -- be performed prior to the specialized tests below.
10530 if Has_DIC (Typ) then
10531 Prag := Get_Pragma (Typ, Pragma_Default_Initial_Condition);
10532 pragma Assert (Present (Prag));
10534 return Is_Verifiable_DIC_Pragma (Prag);
10537 -- A scalar type is fully default initialized if it is subject to aspect
10540 if Is_Scalar_Type (Typ) then
10541 return Has_Default_Aspect (Typ);
10543 -- An array type is fully default initialized if its element type is
10544 -- scalar and the array type carries aspect Default_Component_Value or
10545 -- the element type is fully default initialized.
10547 elsif Is_Array_Type (Typ) then
10549 Has_Default_Aspect (Typ)
10550 or else Has_Full_Default_Initialization (Component_Type (Typ));
10552 -- A protected type, record type, or type extension is fully default
10553 -- initialized if all its components either carry an initialization
10554 -- expression or have a type that is fully default initialized. The
10555 -- parent type of a type extension must be fully default initialized.
10557 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
10559 -- Inspect all entities defined in the scope of the type, looking for
10560 -- uninitialized components.
10562 Comp := First_Entity (Typ);
10563 while Present (Comp) loop
10564 if Ekind (Comp) = E_Component
10565 and then Comes_From_Source (Comp)
10566 and then No (Expression (Parent (Comp)))
10567 and then not Has_Full_Default_Initialization (Etype (Comp))
10572 Next_Entity (Comp);
10575 -- Ensure that the parent type of a type extension is fully default
10578 if Etype (Typ) /= Typ
10579 and then not Has_Full_Default_Initialization (Etype (Typ))
10584 -- If we get here, then all components and parent portion are fully
10585 -- default initialized.
10589 -- A task type is fully default initialized by default
10591 elsif Is_Task_Type (Typ) then
10594 -- Otherwise the type is not fully default initialized
10599 end Has_Full_Default_Initialization;
10601 --------------------
10602 -- Has_Infinities --
10603 --------------------
10605 function Has_Infinities (E : Entity_Id) return Boolean is
10608 Is_Floating_Point_Type (E)
10609 and then Nkind (Scalar_Range (E)) = N_Range
10610 and then Includes_Infinities (Scalar_Range (E));
10611 end Has_Infinities;
10613 --------------------
10614 -- Has_Interfaces --
10615 --------------------
10617 function Has_Interfaces
10619 Use_Full_View : Boolean := True) return Boolean
10621 Typ : Entity_Id := Base_Type (T);
10624 -- Handle concurrent types
10626 if Is_Concurrent_Type (Typ) then
10627 Typ := Corresponding_Record_Type (Typ);
10630 if not Present (Typ)
10631 or else not Is_Record_Type (Typ)
10632 or else not Is_Tagged_Type (Typ)
10637 -- Handle private types
10639 if Use_Full_View and then Present (Full_View (Typ)) then
10640 Typ := Full_View (Typ);
10643 -- Handle concurrent record types
10645 if Is_Concurrent_Record_Type (Typ)
10646 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
10652 if Is_Interface (Typ)
10654 (Is_Record_Type (Typ)
10655 and then Present (Interfaces (Typ))
10656 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
10661 exit when Etype (Typ) = Typ
10663 -- Handle private types
10665 or else (Present (Full_View (Etype (Typ)))
10666 and then Full_View (Etype (Typ)) = Typ)
10668 -- Protect frontend against wrong sources with cyclic derivations
10670 or else Etype (Typ) = T;
10672 -- Climb to the ancestor type handling private types
10674 if Present (Full_View (Etype (Typ))) then
10675 Typ := Full_View (Etype (Typ));
10677 Typ := Etype (Typ);
10682 end Has_Interfaces;
10684 --------------------------
10685 -- Has_Max_Queue_Length --
10686 --------------------------
10688 function Has_Max_Queue_Length (Id : Entity_Id) return Boolean is
10691 Ekind (Id) = E_Entry
10692 and then Present (Get_Pragma (Id, Pragma_Max_Queue_Length));
10693 end Has_Max_Queue_Length;
10695 ---------------------------------
10696 -- Has_No_Obvious_Side_Effects --
10697 ---------------------------------
10699 function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
10701 -- For now handle literals, constants, and non-volatile variables and
10702 -- expressions combining these with operators or short circuit forms.
10704 if Nkind (N) in N_Numeric_Or_String_Literal then
10707 elsif Nkind (N) = N_Character_Literal then
10710 elsif Nkind (N) in N_Unary_Op then
10711 return Has_No_Obvious_Side_Effects (Right_Opnd (N));
10713 elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
10714 return Has_No_Obvious_Side_Effects (Left_Opnd (N))
10716 Has_No_Obvious_Side_Effects (Right_Opnd (N));
10718 elsif Nkind (N) = N_Expression_With_Actions
10719 and then Is_Empty_List (Actions (N))
10721 return Has_No_Obvious_Side_Effects (Expression (N));
10723 elsif Nkind (N) in N_Has_Entity then
10724 return Present (Entity (N))
10725 and then Ekind_In (Entity (N), E_Variable,
10727 E_Enumeration_Literal,
10730 E_In_Out_Parameter)
10731 and then not Is_Volatile (Entity (N));
10736 end Has_No_Obvious_Side_Effects;
10738 -----------------------------
10739 -- Has_Non_Null_Refinement --
10740 -----------------------------
10742 function Has_Non_Null_Refinement (Id : Entity_Id) return Boolean is
10743 Constits : Elist_Id;
10746 pragma Assert (Ekind (Id) = E_Abstract_State);
10747 Constits := Refinement_Constituents (Id);
10749 -- For a refinement to be non-null, the first constituent must be
10750 -- anything other than null.
10754 and then Nkind (Node (First_Elmt (Constits))) /= N_Null;
10755 end Has_Non_Null_Refinement;
10757 ----------------------------------
10758 -- Has_Non_Trivial_Precondition --
10759 ----------------------------------
10761 function Has_Non_Trivial_Precondition (Subp : Entity_Id) return Boolean is
10762 Pre : constant Node_Id := Find_Aspect (Subp, Aspect_Pre);
10767 and then Class_Present (Pre)
10768 and then not Is_Entity_Name (Expression (Pre));
10769 end Has_Non_Trivial_Precondition;
10771 -------------------
10772 -- Has_Null_Body --
10773 -------------------
10775 function Has_Null_Body (Proc_Id : Entity_Id) return Boolean is
10776 Body_Id : Entity_Id;
10783 Spec := Parent (Proc_Id);
10784 Decl := Parent (Spec);
10786 -- Retrieve the entity of the procedure body (e.g. invariant proc).
10788 if Nkind (Spec) = N_Procedure_Specification
10789 and then Nkind (Decl) = N_Subprogram_Declaration
10791 Body_Id := Corresponding_Body (Decl);
10793 -- The body acts as a spec
10796 Body_Id := Proc_Id;
10799 -- The body will be generated later
10801 if No (Body_Id) then
10805 Spec := Parent (Body_Id);
10806 Decl := Parent (Spec);
10809 (Nkind (Spec) = N_Procedure_Specification
10810 and then Nkind (Decl) = N_Subprogram_Body);
10812 Stmt1 := First (Statements (Handled_Statement_Sequence (Decl)));
10814 -- Look for a null statement followed by an optional return
10817 if Nkind (Stmt1) = N_Null_Statement then
10818 Stmt2 := Next (Stmt1);
10820 if Present (Stmt2) then
10821 return Nkind (Stmt2) = N_Simple_Return_Statement;
10830 ------------------------
10831 -- Has_Null_Exclusion --
10832 ------------------------
10834 function Has_Null_Exclusion (N : Node_Id) return Boolean is
10837 when N_Access_Definition
10838 | N_Access_Function_Definition
10839 | N_Access_Procedure_Definition
10840 | N_Access_To_Object_Definition
10842 | N_Derived_Type_Definition
10843 | N_Function_Specification
10844 | N_Subtype_Declaration
10846 return Null_Exclusion_Present (N);
10848 when N_Component_Definition
10849 | N_Formal_Object_Declaration
10850 | N_Object_Renaming_Declaration
10852 if Present (Subtype_Mark (N)) then
10853 return Null_Exclusion_Present (N);
10854 else pragma Assert (Present (Access_Definition (N)));
10855 return Null_Exclusion_Present (Access_Definition (N));
10858 when N_Discriminant_Specification =>
10859 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
10860 return Null_Exclusion_Present (Discriminant_Type (N));
10862 return Null_Exclusion_Present (N);
10865 when N_Object_Declaration =>
10866 if Nkind (Object_Definition (N)) = N_Access_Definition then
10867 return Null_Exclusion_Present (Object_Definition (N));
10869 return Null_Exclusion_Present (N);
10872 when N_Parameter_Specification =>
10873 if Nkind (Parameter_Type (N)) = N_Access_Definition then
10874 return Null_Exclusion_Present (Parameter_Type (N));
10876 return Null_Exclusion_Present (N);
10882 end Has_Null_Exclusion;
10884 ------------------------
10885 -- Has_Null_Extension --
10886 ------------------------
10888 function Has_Null_Extension (T : Entity_Id) return Boolean is
10889 B : constant Entity_Id := Base_Type (T);
10894 if Nkind (Parent (B)) = N_Full_Type_Declaration
10895 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
10897 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
10899 if Present (Ext) then
10900 if Null_Present (Ext) then
10903 Comps := Component_List (Ext);
10905 -- The null component list is rewritten during analysis to
10906 -- include the parent component. Any other component indicates
10907 -- that the extension was not originally null.
10909 return Null_Present (Comps)
10910 or else No (Next (First (Component_Items (Comps))));
10919 end Has_Null_Extension;
10921 -------------------------
10922 -- Has_Null_Refinement --
10923 -------------------------
10925 function Has_Null_Refinement (Id : Entity_Id) return Boolean is
10926 Constits : Elist_Id;
10929 pragma Assert (Ekind (Id) = E_Abstract_State);
10930 Constits := Refinement_Constituents (Id);
10932 -- For a refinement to be null, the state's sole constituent must be a
10937 and then Nkind (Node (First_Elmt (Constits))) = N_Null;
10938 end Has_Null_Refinement;
10940 -------------------------------
10941 -- Has_Overriding_Initialize --
10942 -------------------------------
10944 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
10945 BT : constant Entity_Id := Base_Type (T);
10949 if Is_Controlled (BT) then
10950 if Is_RTU (Scope (BT), Ada_Finalization) then
10953 elsif Present (Primitive_Operations (BT)) then
10954 P := First_Elmt (Primitive_Operations (BT));
10955 while Present (P) loop
10957 Init : constant Entity_Id := Node (P);
10958 Formal : constant Entity_Id := First_Formal (Init);
10960 if Ekind (Init) = E_Procedure
10961 and then Chars (Init) = Name_Initialize
10962 and then Comes_From_Source (Init)
10963 and then Present (Formal)
10964 and then Etype (Formal) = BT
10965 and then No (Next_Formal (Formal))
10966 and then (Ada_Version < Ada_2012
10967 or else not Null_Present (Parent (Init)))
10977 -- Here if type itself does not have a non-null Initialize operation:
10978 -- check immediate ancestor.
10980 if Is_Derived_Type (BT)
10981 and then Has_Overriding_Initialize (Etype (BT))
10988 end Has_Overriding_Initialize;
10990 --------------------------------------
10991 -- Has_Preelaborable_Initialization --
10992 --------------------------------------
10994 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
10997 procedure Check_Components (E : Entity_Id);
10998 -- Check component/discriminant chain, sets Has_PE False if a component
10999 -- or discriminant does not meet the preelaborable initialization rules.
11001 ----------------------
11002 -- Check_Components --
11003 ----------------------
11005 procedure Check_Components (E : Entity_Id) is
11010 -- Loop through entities of record or protected type
11013 while Present (Ent) loop
11015 -- We are interested only in components and discriminants
11019 case Ekind (Ent) is
11020 when E_Component =>
11022 -- Get default expression if any. If there is no declaration
11023 -- node, it means we have an internal entity. The parent and
11024 -- tag fields are examples of such entities. For such cases,
11025 -- we just test the type of the entity.
11027 if Present (Declaration_Node (Ent)) then
11028 Exp := Expression (Declaration_Node (Ent));
11031 when E_Discriminant =>
11033 -- Note: for a renamed discriminant, the Declaration_Node
11034 -- may point to the one from the ancestor, and have a
11035 -- different expression, so use the proper attribute to
11036 -- retrieve the expression from the derived constraint.
11038 Exp := Discriminant_Default_Value (Ent);
11041 goto Check_Next_Entity;
11044 -- A component has PI if it has no default expression and the
11045 -- component type has PI.
11048 if not Has_Preelaborable_Initialization (Etype (Ent)) then
11053 -- Require the default expression to be preelaborable
11055 elsif not Is_Preelaborable_Construct (Exp) then
11060 <<Check_Next_Entity>>
11063 end Check_Components;
11065 -- Start of processing for Has_Preelaborable_Initialization
11068 -- Immediate return if already marked as known preelaborable init. This
11069 -- covers types for which this function has already been called once
11070 -- and returned True (in which case the result is cached), and also
11071 -- types to which a pragma Preelaborable_Initialization applies.
11073 if Known_To_Have_Preelab_Init (E) then
11077 -- If the type is a subtype representing a generic actual type, then
11078 -- test whether its base type has preelaborable initialization since
11079 -- the subtype representing the actual does not inherit this attribute
11080 -- from the actual or formal. (but maybe it should???)
11082 if Is_Generic_Actual_Type (E) then
11083 return Has_Preelaborable_Initialization (Base_Type (E));
11086 -- All elementary types have preelaborable initialization
11088 if Is_Elementary_Type (E) then
11091 -- Array types have PI if the component type has PI
11093 elsif Is_Array_Type (E) then
11094 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
11096 -- A derived type has preelaborable initialization if its parent type
11097 -- has preelaborable initialization and (in the case of a derived record
11098 -- extension) if the non-inherited components all have preelaborable
11099 -- initialization. However, a user-defined controlled type with an
11100 -- overriding Initialize procedure does not have preelaborable
11103 elsif Is_Derived_Type (E) then
11105 -- If the derived type is a private extension then it doesn't have
11106 -- preelaborable initialization.
11108 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
11112 -- First check whether ancestor type has preelaborable initialization
11114 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
11116 -- If OK, check extension components (if any)
11118 if Has_PE and then Is_Record_Type (E) then
11119 Check_Components (First_Entity (E));
11122 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
11123 -- with a user defined Initialize procedure does not have PI. If
11124 -- the type is untagged, the control primitives come from a component
11125 -- that has already been checked.
11128 and then Is_Controlled (E)
11129 and then Is_Tagged_Type (E)
11130 and then Has_Overriding_Initialize (E)
11135 -- Private types not derived from a type having preelaborable init and
11136 -- that are not marked with pragma Preelaborable_Initialization do not
11137 -- have preelaborable initialization.
11139 elsif Is_Private_Type (E) then
11142 -- Record type has PI if it is non private and all components have PI
11144 elsif Is_Record_Type (E) then
11146 Check_Components (First_Entity (E));
11148 -- Protected types must not have entries, and components must meet
11149 -- same set of rules as for record components.
11151 elsif Is_Protected_Type (E) then
11152 if Has_Entries (E) then
11156 Check_Components (First_Entity (E));
11157 Check_Components (First_Private_Entity (E));
11160 -- Type System.Address always has preelaborable initialization
11162 elsif Is_RTE (E, RE_Address) then
11165 -- In all other cases, type does not have preelaborable initialization
11171 -- If type has preelaborable initialization, cache result
11174 Set_Known_To_Have_Preelab_Init (E);
11178 end Has_Preelaborable_Initialization;
11180 ---------------------------
11181 -- Has_Private_Component --
11182 ---------------------------
11184 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
11185 Btype : Entity_Id := Base_Type (Type_Id);
11186 Component : Entity_Id;
11189 if Error_Posted (Type_Id)
11190 or else Error_Posted (Btype)
11195 if Is_Class_Wide_Type (Btype) then
11196 Btype := Root_Type (Btype);
11199 if Is_Private_Type (Btype) then
11201 UT : constant Entity_Id := Underlying_Type (Btype);
11204 if No (Full_View (Btype)) then
11205 return not Is_Generic_Type (Btype)
11207 not Is_Generic_Type (Root_Type (Btype));
11209 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
11212 return not Is_Frozen (UT) and then Has_Private_Component (UT);
11216 elsif Is_Array_Type (Btype) then
11217 return Has_Private_Component (Component_Type (Btype));
11219 elsif Is_Record_Type (Btype) then
11220 Component := First_Component (Btype);
11221 while Present (Component) loop
11222 if Has_Private_Component (Etype (Component)) then
11226 Next_Component (Component);
11231 elsif Is_Protected_Type (Btype)
11232 and then Present (Corresponding_Record_Type (Btype))
11234 return Has_Private_Component (Corresponding_Record_Type (Btype));
11239 end Has_Private_Component;
11241 ----------------------
11242 -- Has_Signed_Zeros --
11243 ----------------------
11245 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
11247 return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target;
11248 end Has_Signed_Zeros;
11250 ------------------------------
11251 -- Has_Significant_Contract --
11252 ------------------------------
11254 function Has_Significant_Contract (Subp_Id : Entity_Id) return Boolean is
11255 Subp_Nam : constant Name_Id := Chars (Subp_Id);
11258 -- _Finalizer procedure
11260 if Subp_Nam = Name_uFinalizer then
11263 -- _Postconditions procedure
11265 elsif Subp_Nam = Name_uPostconditions then
11268 -- Predicate function
11270 elsif Ekind (Subp_Id) = E_Function
11271 and then Is_Predicate_Function (Subp_Id)
11277 elsif Get_TSS_Name (Subp_Id) /= TSS_Null then
11283 end Has_Significant_Contract;
11285 -----------------------------
11286 -- Has_Static_Array_Bounds --
11287 -----------------------------
11289 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
11290 Ndims : constant Nat := Number_Dimensions (Typ);
11297 -- Unconstrained types do not have static bounds
11299 if not Is_Constrained (Typ) then
11303 -- First treat string literals specially, as the lower bound and length
11304 -- of string literals are not stored like those of arrays.
11306 -- A string literal always has static bounds
11308 if Ekind (Typ) = E_String_Literal_Subtype then
11312 -- Treat all dimensions in turn
11314 Index := First_Index (Typ);
11315 for Indx in 1 .. Ndims loop
11317 -- In case of an illegal index which is not a discrete type, return
11318 -- that the type is not static.
11320 if not Is_Discrete_Type (Etype (Index))
11321 or else Etype (Index) = Any_Type
11326 Get_Index_Bounds (Index, Low, High);
11328 if Error_Posted (Low) or else Error_Posted (High) then
11332 if Is_OK_Static_Expression (Low)
11334 Is_OK_Static_Expression (High)
11344 -- If we fall through the loop, all indexes matched
11347 end Has_Static_Array_Bounds;
11353 function Has_Stream (T : Entity_Id) return Boolean is
11360 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
11363 elsif Is_Array_Type (T) then
11364 return Has_Stream (Component_Type (T));
11366 elsif Is_Record_Type (T) then
11367 E := First_Component (T);
11368 while Present (E) loop
11369 if Has_Stream (Etype (E)) then
11372 Next_Component (E);
11378 elsif Is_Private_Type (T) then
11379 return Has_Stream (Underlying_Type (T));
11390 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
11392 Get_Name_String (Chars (E));
11393 return Name_Buffer (Name_Len) = Suffix;
11400 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
11402 Get_Name_String (Chars (E));
11403 Add_Char_To_Name_Buffer (Suffix);
11407 -------------------
11408 -- Remove_Suffix --
11409 -------------------
11411 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
11413 pragma Assert (Has_Suffix (E, Suffix));
11414 Get_Name_String (Chars (E));
11415 Name_Len := Name_Len - 1;
11419 ----------------------------------
11420 -- Replace_Null_By_Null_Address --
11421 ----------------------------------
11423 procedure Replace_Null_By_Null_Address (N : Node_Id) is
11424 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id);
11425 -- Replace operand Op with a reference to Null_Address when the operand
11426 -- denotes a null Address. Other_Op denotes the other operand.
11428 --------------------------
11429 -- Replace_Null_Operand --
11430 --------------------------
11432 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id) is
11434 -- Check the type of the complementary operand since the N_Null node
11435 -- has not been decorated yet.
11437 if Nkind (Op) = N_Null
11438 and then Is_Descendant_Of_Address (Etype (Other_Op))
11440 Rewrite (Op, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (Op)));
11442 end Replace_Null_Operand;
11444 -- Start of processing for Replace_Null_By_Null_Address
11447 pragma Assert (Relaxed_RM_Semantics);
11448 pragma Assert (Nkind_In (N, N_Null,
11456 if Nkind (N) = N_Null then
11457 Rewrite (N, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (N)));
11461 L : constant Node_Id := Left_Opnd (N);
11462 R : constant Node_Id := Right_Opnd (N);
11465 Replace_Null_Operand (L, Other_Op => R);
11466 Replace_Null_Operand (R, Other_Op => L);
11469 end Replace_Null_By_Null_Address;
11471 --------------------------
11472 -- Has_Tagged_Component --
11473 --------------------------
11475 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
11479 if Is_Private_Type (Typ) and then Present (Underlying_Type (Typ)) then
11480 return Has_Tagged_Component (Underlying_Type (Typ));
11482 elsif Is_Array_Type (Typ) then
11483 return Has_Tagged_Component (Component_Type (Typ));
11485 elsif Is_Tagged_Type (Typ) then
11488 elsif Is_Record_Type (Typ) then
11489 Comp := First_Component (Typ);
11490 while Present (Comp) loop
11491 if Has_Tagged_Component (Etype (Comp)) then
11495 Next_Component (Comp);
11503 end Has_Tagged_Component;
11505 -----------------------------
11506 -- Has_Undefined_Reference --
11507 -----------------------------
11509 function Has_Undefined_Reference (Expr : Node_Id) return Boolean is
11510 Has_Undef_Ref : Boolean := False;
11511 -- Flag set when expression Expr contains at least one undefined
11514 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result;
11515 -- Determine whether N denotes a reference and if it does, whether it is
11518 ----------------------------
11519 -- Is_Undefined_Reference --
11520 ----------------------------
11522 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result is
11524 if Is_Entity_Name (N)
11525 and then Present (Entity (N))
11526 and then Entity (N) = Any_Id
11528 Has_Undef_Ref := True;
11533 end Is_Undefined_Reference;
11535 procedure Find_Undefined_References is
11536 new Traverse_Proc (Is_Undefined_Reference);
11538 -- Start of processing for Has_Undefined_Reference
11541 Find_Undefined_References (Expr);
11543 return Has_Undef_Ref;
11544 end Has_Undefined_Reference;
11546 ----------------------------
11547 -- Has_Volatile_Component --
11548 ----------------------------
11550 function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
11554 if Has_Volatile_Components (Typ) then
11557 elsif Is_Array_Type (Typ) then
11558 return Is_Volatile (Component_Type (Typ));
11560 elsif Is_Record_Type (Typ) then
11561 Comp := First_Component (Typ);
11562 while Present (Comp) loop
11563 if Is_Volatile_Object (Comp) then
11567 Comp := Next_Component (Comp);
11572 end Has_Volatile_Component;
11574 -------------------------
11575 -- Implementation_Kind --
11576 -------------------------
11578 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
11579 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
11582 pragma Assert (Present (Impl_Prag));
11583 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
11584 return Chars (Get_Pragma_Arg (Arg));
11585 end Implementation_Kind;
11587 --------------------------
11588 -- Implements_Interface --
11589 --------------------------
11591 function Implements_Interface
11592 (Typ_Ent : Entity_Id;
11593 Iface_Ent : Entity_Id;
11594 Exclude_Parents : Boolean := False) return Boolean
11596 Ifaces_List : Elist_Id;
11598 Iface : Entity_Id := Base_Type (Iface_Ent);
11599 Typ : Entity_Id := Base_Type (Typ_Ent);
11602 if Is_Class_Wide_Type (Typ) then
11603 Typ := Root_Type (Typ);
11606 if not Has_Interfaces (Typ) then
11610 if Is_Class_Wide_Type (Iface) then
11611 Iface := Root_Type (Iface);
11614 Collect_Interfaces (Typ, Ifaces_List);
11616 Elmt := First_Elmt (Ifaces_List);
11617 while Present (Elmt) loop
11618 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
11619 and then Exclude_Parents
11623 elsif Node (Elmt) = Iface then
11631 end Implements_Interface;
11633 ------------------------------------
11634 -- In_Assertion_Expression_Pragma --
11635 ------------------------------------
11637 function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is
11639 Prag : Node_Id := Empty;
11642 -- Climb the parent chain looking for an enclosing pragma
11645 while Present (Par) loop
11646 if Nkind (Par) = N_Pragma then
11650 -- Precondition-like pragmas are expanded into if statements, check
11651 -- the original node instead.
11653 elsif Nkind (Original_Node (Par)) = N_Pragma then
11654 Prag := Original_Node (Par);
11657 -- The expansion of attribute 'Old generates a constant to capture
11658 -- the result of the prefix. If the parent traversal reaches
11659 -- one of these constants, then the node technically came from a
11660 -- postcondition-like pragma. Note that the Ekind is not tested here
11661 -- because N may be the expression of an object declaration which is
11662 -- currently being analyzed. Such objects carry Ekind of E_Void.
11664 elsif Nkind (Par) = N_Object_Declaration
11665 and then Constant_Present (Par)
11666 and then Stores_Attribute_Old_Prefix (Defining_Entity (Par))
11670 -- Prevent the search from going too far
11672 elsif Is_Body_Or_Package_Declaration (Par) then
11676 Par := Parent (Par);
11681 and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag));
11682 end In_Assertion_Expression_Pragma;
11684 ----------------------
11685 -- In_Generic_Scope --
11686 ----------------------
11688 function In_Generic_Scope (E : Entity_Id) return Boolean is
11693 while Present (S) and then S /= Standard_Standard loop
11694 if Is_Generic_Unit (S) then
11702 end In_Generic_Scope;
11708 function In_Instance return Boolean is
11709 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
11713 S := Current_Scope;
11714 while Present (S) and then S /= Standard_Standard loop
11715 if Is_Generic_Instance (S) then
11717 -- A child instance is always compiled in the context of a parent
11718 -- instance. Nevertheless, the actuals are not analyzed in an
11719 -- instance context. We detect this case by examining the current
11720 -- compilation unit, which must be a child instance, and checking
11721 -- that it is not currently on the scope stack.
11723 if Is_Child_Unit (Curr_Unit)
11724 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
11725 N_Package_Instantiation
11726 and then not In_Open_Scopes (Curr_Unit)
11740 ----------------------
11741 -- In_Instance_Body --
11742 ----------------------
11744 function In_Instance_Body return Boolean is
11748 S := Current_Scope;
11749 while Present (S) and then S /= Standard_Standard loop
11750 if Ekind_In (S, E_Function, E_Procedure)
11751 and then Is_Generic_Instance (S)
11755 elsif Ekind (S) = E_Package
11756 and then In_Package_Body (S)
11757 and then Is_Generic_Instance (S)
11766 end In_Instance_Body;
11768 -----------------------------
11769 -- In_Instance_Not_Visible --
11770 -----------------------------
11772 function In_Instance_Not_Visible return Boolean is
11776 S := Current_Scope;
11777 while Present (S) and then S /= Standard_Standard loop
11778 if Ekind_In (S, E_Function, E_Procedure)
11779 and then Is_Generic_Instance (S)
11783 elsif Ekind (S) = E_Package
11784 and then (In_Package_Body (S) or else In_Private_Part (S))
11785 and then Is_Generic_Instance (S)
11794 end In_Instance_Not_Visible;
11796 ------------------------------
11797 -- In_Instance_Visible_Part --
11798 ------------------------------
11800 function In_Instance_Visible_Part
11801 (Id : Entity_Id := Current_Scope) return Boolean
11807 while Present (Inst) and then Inst /= Standard_Standard loop
11808 if Ekind (Inst) = E_Package
11809 and then Is_Generic_Instance (Inst)
11810 and then not In_Package_Body (Inst)
11811 and then not In_Private_Part (Inst)
11816 Inst := Scope (Inst);
11820 end In_Instance_Visible_Part;
11822 ---------------------
11823 -- In_Package_Body --
11824 ---------------------
11826 function In_Package_Body return Boolean is
11830 S := Current_Scope;
11831 while Present (S) and then S /= Standard_Standard loop
11832 if Ekind (S) = E_Package and then In_Package_Body (S) then
11840 end In_Package_Body;
11842 --------------------------
11843 -- In_Pragma_Expression --
11844 --------------------------
11846 function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean is
11853 elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
11859 end In_Pragma_Expression;
11861 ---------------------------
11862 -- In_Pre_Post_Condition --
11863 ---------------------------
11865 function In_Pre_Post_Condition (N : Node_Id) return Boolean is
11867 Prag : Node_Id := Empty;
11868 Prag_Id : Pragma_Id;
11871 -- Climb the parent chain looking for an enclosing pragma
11874 while Present (Par) loop
11875 if Nkind (Par) = N_Pragma then
11879 -- Prevent the search from going too far
11881 elsif Is_Body_Or_Package_Declaration (Par) then
11885 Par := Parent (Par);
11888 if Present (Prag) then
11889 Prag_Id := Get_Pragma_Id (Prag);
11892 Prag_Id = Pragma_Post
11893 or else Prag_Id = Pragma_Post_Class
11894 or else Prag_Id = Pragma_Postcondition
11895 or else Prag_Id = Pragma_Pre
11896 or else Prag_Id = Pragma_Pre_Class
11897 or else Prag_Id = Pragma_Precondition;
11899 -- Otherwise the node is not enclosed by a pre/postcondition pragma
11904 end In_Pre_Post_Condition;
11906 -------------------------------------
11907 -- In_Reverse_Storage_Order_Object --
11908 -------------------------------------
11910 function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
11912 Btyp : Entity_Id := Empty;
11915 -- Climb up indexed components
11919 case Nkind (Pref) is
11920 when N_Selected_Component =>
11921 Pref := Prefix (Pref);
11924 when N_Indexed_Component =>
11925 Pref := Prefix (Pref);
11933 if Present (Pref) then
11934 Btyp := Base_Type (Etype (Pref));
11937 return Present (Btyp)
11938 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
11939 and then Reverse_Storage_Order (Btyp);
11940 end In_Reverse_Storage_Order_Object;
11942 --------------------------------------
11943 -- In_Subprogram_Or_Concurrent_Unit --
11944 --------------------------------------
11946 function In_Subprogram_Or_Concurrent_Unit return Boolean is
11951 -- Use scope chain to check successively outer scopes
11953 E := Current_Scope;
11957 if K in Subprogram_Kind
11958 or else K in Concurrent_Kind
11959 or else K in Generic_Subprogram_Kind
11963 elsif E = Standard_Standard then
11969 end In_Subprogram_Or_Concurrent_Unit;
11975 function In_Subtree (N : Node_Id; Root : Node_Id) return Boolean is
11980 while Present (Curr) loop
11981 if Curr = Root then
11985 Curr := Parent (Curr);
11995 function In_Subtree
11998 Root2 : Node_Id) return Boolean
12004 while Present (Curr) loop
12005 if Curr = Root1 or else Curr = Root2 then
12009 Curr := Parent (Curr);
12015 ---------------------
12016 -- In_Visible_Part --
12017 ---------------------
12019 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
12021 return Is_Package_Or_Generic_Package (Scope_Id)
12022 and then In_Open_Scopes (Scope_Id)
12023 and then not In_Package_Body (Scope_Id)
12024 and then not In_Private_Part (Scope_Id);
12025 end In_Visible_Part;
12027 --------------------------------
12028 -- Incomplete_Or_Partial_View --
12029 --------------------------------
12031 function Incomplete_Or_Partial_View (Id : Entity_Id) return Entity_Id is
12032 function Inspect_Decls
12034 Taft : Boolean := False) return Entity_Id;
12035 -- Check whether a declarative region contains the incomplete or partial
12038 -------------------
12039 -- Inspect_Decls --
12040 -------------------
12042 function Inspect_Decls
12044 Taft : Boolean := False) return Entity_Id
12050 Decl := First (Decls);
12051 while Present (Decl) loop
12054 -- The partial view of a Taft-amendment type is an incomplete
12058 if Nkind (Decl) = N_Incomplete_Type_Declaration then
12059 Match := Defining_Identifier (Decl);
12062 -- Otherwise look for a private type whose full view matches the
12063 -- input type. Note that this checks full_type_declaration nodes
12064 -- to account for derivations from a private type where the type
12065 -- declaration hold the partial view and the full view is an
12068 elsif Nkind_In (Decl, N_Full_Type_Declaration,
12069 N_Private_Extension_Declaration,
12070 N_Private_Type_Declaration)
12072 Match := Defining_Identifier (Decl);
12075 -- Guard against unanalyzed entities
12078 and then Is_Type (Match)
12079 and then Present (Full_View (Match))
12080 and then Full_View (Match) = Id
12095 -- Start of processing for Incomplete_Or_Partial_View
12098 -- Deferred constant or incomplete type case
12100 Prev := Current_Entity_In_Scope (Id);
12103 and then (Is_Incomplete_Type (Prev) or else Ekind (Prev) = E_Constant)
12104 and then Present (Full_View (Prev))
12105 and then Full_View (Prev) = Id
12110 -- Private or Taft amendment type case
12113 Pkg : constant Entity_Id := Scope (Id);
12114 Pkg_Decl : Node_Id := Pkg;
12118 and then Ekind_In (Pkg, E_Generic_Package, E_Package)
12120 while Nkind (Pkg_Decl) /= N_Package_Specification loop
12121 Pkg_Decl := Parent (Pkg_Decl);
12124 -- It is knows that Typ has a private view, look for it in the
12125 -- visible declarations of the enclosing scope. A special case
12126 -- of this is when the two views have been exchanged - the full
12127 -- appears earlier than the private.
12129 if Has_Private_Declaration (Id) then
12130 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
12132 -- Exchanged view case, look in the private declarations
12135 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
12140 -- Otherwise if this is the package body, then Typ is a potential
12141 -- Taft amendment type. The incomplete view should be located in
12142 -- the private declarations of the enclosing scope.
12144 elsif In_Package_Body (Pkg) then
12145 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
12150 -- The type has no incomplete or private view
12153 end Incomplete_Or_Partial_View;
12155 ----------------------------------
12156 -- Indexed_Component_Bit_Offset --
12157 ----------------------------------
12159 function Indexed_Component_Bit_Offset (N : Node_Id) return Uint is
12160 Exp : constant Node_Id := First (Expressions (N));
12161 Typ : constant Entity_Id := Etype (Prefix (N));
12162 Off : constant Uint := Component_Size (Typ);
12166 -- Return early if the component size is not known or variable
12168 if Off = No_Uint or else Off < Uint_0 then
12172 -- Deal with the degenerate case of an empty component
12174 if Off = Uint_0 then
12178 -- Check that both the index value and the low bound are known
12180 if not Compile_Time_Known_Value (Exp) then
12184 Ind := First_Index (Typ);
12189 if Nkind (Ind) = N_Subtype_Indication then
12190 Ind := Constraint (Ind);
12192 if Nkind (Ind) = N_Range_Constraint then
12193 Ind := Range_Expression (Ind);
12197 if Nkind (Ind) /= N_Range
12198 or else not Compile_Time_Known_Value (Low_Bound (Ind))
12203 -- Return the scaled offset
12205 return Off * (Expr_Value (Exp) - Expr_Value (Low_Bound ((Ind))));
12206 end Indexed_Component_Bit_Offset;
12208 ----------------------------
12209 -- Inherit_Rep_Item_Chain --
12210 ----------------------------
12212 procedure Inherit_Rep_Item_Chain (Typ : Entity_Id; From_Typ : Entity_Id) is
12214 Next_Item : Node_Id;
12217 -- There are several inheritance scenarios to consider depending on
12218 -- whether both types have rep item chains and whether the destination
12219 -- type already inherits part of the source type's rep item chain.
12221 -- 1) The source type lacks a rep item chain
12222 -- From_Typ ---> Empty
12224 -- Typ --------> Item (or Empty)
12226 -- In this case inheritance cannot take place because there are no items
12229 -- 2) The destination type lacks a rep item chain
12230 -- From_Typ ---> Item ---> ...
12232 -- Typ --------> Empty
12234 -- Inheritance takes place by setting the First_Rep_Item of the
12235 -- destination type to the First_Rep_Item of the source type.
12236 -- From_Typ ---> Item ---> ...
12238 -- Typ -----------+
12240 -- 3.1) Both source and destination types have at least one rep item.
12241 -- The destination type does NOT inherit a rep item from the source
12243 -- From_Typ ---> Item ---> Item
12245 -- Typ --------> Item ---> Item
12247 -- Inheritance takes place by setting the Next_Rep_Item of the last item
12248 -- of the destination type to the First_Rep_Item of the source type.
12249 -- From_Typ -------------------> Item ---> Item
12251 -- Typ --------> Item ---> Item --+
12253 -- 3.2) Both source and destination types have at least one rep item.
12254 -- The destination type DOES inherit part of the rep item chain of the
12256 -- From_Typ ---> Item ---> Item ---> Item
12258 -- Typ --------> Item ------+
12260 -- This rare case arises when the full view of a private extension must
12261 -- inherit the rep item chain from the full view of its parent type and
12262 -- the full view of the parent type contains extra rep items. Currently
12263 -- only invariants may lead to such form of inheritance.
12265 -- type From_Typ is tagged private
12266 -- with Type_Invariant'Class => Item_2;
12268 -- type Typ is new From_Typ with private
12269 -- with Type_Invariant => Item_4;
12271 -- At this point the rep item chains contain the following items
12273 -- From_Typ -----------> Item_2 ---> Item_3
12275 -- Typ --------> Item_4 --+
12277 -- The full views of both types may introduce extra invariants
12279 -- type From_Typ is tagged null record
12280 -- with Type_Invariant => Item_1;
12282 -- type Typ is new From_Typ with null record;
12284 -- The full view of Typ would have to inherit any new rep items added to
12285 -- the full view of From_Typ.
12287 -- From_Typ -----------> Item_1 ---> Item_2 ---> Item_3
12289 -- Typ --------> Item_4 --+
12291 -- To achieve this form of inheritance, the destination type must first
12292 -- sever the link between its own rep chain and that of the source type,
12293 -- then inheritance 3.1 takes place.
12295 -- Case 1: The source type lacks a rep item chain
12297 if No (First_Rep_Item (From_Typ)) then
12300 -- Case 2: The destination type lacks a rep item chain
12302 elsif No (First_Rep_Item (Typ)) then
12303 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
12305 -- Case 3: Both the source and destination types have at least one rep
12306 -- item. Traverse the rep item chain of the destination type to find the
12311 Next_Item := First_Rep_Item (Typ);
12312 while Present (Next_Item) loop
12314 -- Detect a link between the destination type's rep chain and that
12315 -- of the source type. There are two possibilities:
12320 -- From_Typ ---> Item_1 --->
12322 -- Typ -----------+
12329 -- From_Typ ---> Item_1 ---> Item_2 --->
12331 -- Typ --------> Item_3 ------+
12335 if Has_Rep_Item (From_Typ, Next_Item) then
12340 Next_Item := Next_Rep_Item (Next_Item);
12343 -- Inherit the source type's rep item chain
12345 if Present (Item) then
12346 Set_Next_Rep_Item (Item, First_Rep_Item (From_Typ));
12348 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
12351 end Inherit_Rep_Item_Chain;
12353 ---------------------------------
12354 -- Insert_Explicit_Dereference --
12355 ---------------------------------
12357 procedure Insert_Explicit_Dereference (N : Node_Id) is
12358 New_Prefix : constant Node_Id := Relocate_Node (N);
12359 Ent : Entity_Id := Empty;
12366 Save_Interps (N, New_Prefix);
12369 Make_Explicit_Dereference (Sloc (Parent (N)),
12370 Prefix => New_Prefix));
12372 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
12374 if Is_Overloaded (New_Prefix) then
12376 -- The dereference is also overloaded, and its interpretations are
12377 -- the designated types of the interpretations of the original node.
12379 Set_Etype (N, Any_Type);
12381 Get_First_Interp (New_Prefix, I, It);
12382 while Present (It.Nam) loop
12385 if Is_Access_Type (T) then
12386 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
12389 Get_Next_Interp (I, It);
12395 -- Prefix is unambiguous: mark the original prefix (which might
12396 -- Come_From_Source) as a reference, since the new (relocated) one
12397 -- won't be taken into account.
12399 if Is_Entity_Name (New_Prefix) then
12400 Ent := Entity (New_Prefix);
12401 Pref := New_Prefix;
12403 -- For a retrieval of a subcomponent of some composite object,
12404 -- retrieve the ultimate entity if there is one.
12406 elsif Nkind_In (New_Prefix, N_Selected_Component,
12407 N_Indexed_Component)
12409 Pref := Prefix (New_Prefix);
12410 while Present (Pref)
12411 and then Nkind_In (Pref, N_Selected_Component,
12412 N_Indexed_Component)
12414 Pref := Prefix (Pref);
12417 if Present (Pref) and then Is_Entity_Name (Pref) then
12418 Ent := Entity (Pref);
12422 -- Place the reference on the entity node
12424 if Present (Ent) then
12425 Generate_Reference (Ent, Pref);
12428 end Insert_Explicit_Dereference;
12430 ------------------------------------------
12431 -- Inspect_Deferred_Constant_Completion --
12432 ------------------------------------------
12434 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
12438 Decl := First (Decls);
12439 while Present (Decl) loop
12441 -- Deferred constant signature
12443 if Nkind (Decl) = N_Object_Declaration
12444 and then Constant_Present (Decl)
12445 and then No (Expression (Decl))
12447 -- No need to check internally generated constants
12449 and then Comes_From_Source (Decl)
12451 -- The constant is not completed. A full object declaration or a
12452 -- pragma Import complete a deferred constant.
12454 and then not Has_Completion (Defining_Identifier (Decl))
12457 ("constant declaration requires initialization expression",
12458 Defining_Identifier (Decl));
12461 Decl := Next (Decl);
12463 end Inspect_Deferred_Constant_Completion;
12465 -----------------------------
12466 -- Install_Generic_Formals --
12467 -----------------------------
12469 procedure Install_Generic_Formals (Subp_Id : Entity_Id) is
12473 pragma Assert (Is_Generic_Subprogram (Subp_Id));
12475 E := First_Entity (Subp_Id);
12476 while Present (E) loop
12477 Install_Entity (E);
12480 end Install_Generic_Formals;
12482 ------------------------
12483 -- Install_SPARK_Mode --
12484 ------------------------
12486 procedure Install_SPARK_Mode (Mode : SPARK_Mode_Type; Prag : Node_Id) is
12488 SPARK_Mode := Mode;
12489 SPARK_Mode_Pragma := Prag;
12490 end Install_SPARK_Mode;
12492 -----------------------------
12493 -- Is_Actual_Out_Parameter --
12494 -----------------------------
12496 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
12497 Formal : Entity_Id;
12500 Find_Actual (N, Formal, Call);
12501 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
12502 end Is_Actual_Out_Parameter;
12504 -------------------------
12505 -- Is_Actual_Parameter --
12506 -------------------------
12508 function Is_Actual_Parameter (N : Node_Id) return Boolean is
12509 PK : constant Node_Kind := Nkind (Parent (N));
12513 when N_Parameter_Association =>
12514 return N = Explicit_Actual_Parameter (Parent (N));
12516 when N_Subprogram_Call =>
12517 return Is_List_Member (N)
12519 List_Containing (N) = Parameter_Associations (Parent (N));
12524 end Is_Actual_Parameter;
12526 --------------------------------
12527 -- Is_Actual_Tagged_Parameter --
12528 --------------------------------
12530 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
12531 Formal : Entity_Id;
12534 Find_Actual (N, Formal, Call);
12535 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
12536 end Is_Actual_Tagged_Parameter;
12538 ---------------------
12539 -- Is_Aliased_View --
12540 ---------------------
12542 function Is_Aliased_View (Obj : Node_Id) return Boolean is
12546 if Is_Entity_Name (Obj) then
12553 or else (Present (Renamed_Object (E))
12554 and then Is_Aliased_View (Renamed_Object (E)))))
12556 or else ((Is_Formal (E) or else Is_Formal_Object (E))
12557 and then Is_Tagged_Type (Etype (E)))
12559 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
12561 -- Current instance of type, either directly or as rewritten
12562 -- reference to the current object.
12564 or else (Is_Entity_Name (Original_Node (Obj))
12565 and then Present (Entity (Original_Node (Obj)))
12566 and then Is_Type (Entity (Original_Node (Obj))))
12568 or else (Is_Type (E) and then E = Current_Scope)
12570 or else (Is_Incomplete_Or_Private_Type (E)
12571 and then Full_View (E) = Current_Scope)
12573 -- Ada 2012 AI05-0053: the return object of an extended return
12574 -- statement is aliased if its type is immutably limited.
12576 or else (Is_Return_Object (E)
12577 and then Is_Limited_View (Etype (E)));
12579 elsif Nkind (Obj) = N_Selected_Component then
12580 return Is_Aliased (Entity (Selector_Name (Obj)));
12582 elsif Nkind (Obj) = N_Indexed_Component then
12583 return Has_Aliased_Components (Etype (Prefix (Obj)))
12585 (Is_Access_Type (Etype (Prefix (Obj)))
12586 and then Has_Aliased_Components
12587 (Designated_Type (Etype (Prefix (Obj)))));
12589 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
12590 return Is_Tagged_Type (Etype (Obj))
12591 and then Is_Aliased_View (Expression (Obj));
12593 elsif Nkind (Obj) = N_Explicit_Dereference then
12594 return Nkind (Original_Node (Obj)) /= N_Function_Call;
12599 end Is_Aliased_View;
12601 -------------------------
12602 -- Is_Ancestor_Package --
12603 -------------------------
12605 function Is_Ancestor_Package
12607 E2 : Entity_Id) return Boolean
12613 while Present (Par) and then Par /= Standard_Standard loop
12618 Par := Scope (Par);
12622 end Is_Ancestor_Package;
12624 ----------------------
12625 -- Is_Atomic_Object --
12626 ----------------------
12628 function Is_Atomic_Object (N : Node_Id) return Boolean is
12630 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
12631 -- Determines if given object has atomic components
12633 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
12634 -- If prefix is an implicit dereference, examine designated type
12636 ----------------------
12637 -- Is_Atomic_Prefix --
12638 ----------------------
12640 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
12642 if Is_Access_Type (Etype (N)) then
12644 Has_Atomic_Components (Designated_Type (Etype (N)));
12646 return Object_Has_Atomic_Components (N);
12648 end Is_Atomic_Prefix;
12650 ----------------------------------
12651 -- Object_Has_Atomic_Components --
12652 ----------------------------------
12654 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
12656 if Has_Atomic_Components (Etype (N))
12657 or else Is_Atomic (Etype (N))
12661 elsif Is_Entity_Name (N)
12662 and then (Has_Atomic_Components (Entity (N))
12663 or else Is_Atomic (Entity (N)))
12667 elsif Nkind (N) = N_Selected_Component
12668 and then Is_Atomic (Entity (Selector_Name (N)))
12672 elsif Nkind (N) = N_Indexed_Component
12673 or else Nkind (N) = N_Selected_Component
12675 return Is_Atomic_Prefix (Prefix (N));
12680 end Object_Has_Atomic_Components;
12682 -- Start of processing for Is_Atomic_Object
12685 -- Predicate is not relevant to subprograms
12687 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
12690 elsif Is_Atomic (Etype (N))
12691 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
12695 elsif Nkind (N) = N_Selected_Component
12696 and then Is_Atomic (Entity (Selector_Name (N)))
12700 elsif Nkind (N) = N_Indexed_Component
12701 or else Nkind (N) = N_Selected_Component
12703 return Is_Atomic_Prefix (Prefix (N));
12708 end Is_Atomic_Object;
12710 -----------------------------
12711 -- Is_Atomic_Or_VFA_Object --
12712 -----------------------------
12714 function Is_Atomic_Or_VFA_Object (N : Node_Id) return Boolean is
12716 return Is_Atomic_Object (N)
12717 or else (Is_Object_Reference (N)
12718 and then Is_Entity_Name (N)
12719 and then (Is_Volatile_Full_Access (Entity (N))
12721 Is_Volatile_Full_Access (Etype (Entity (N)))));
12722 end Is_Atomic_Or_VFA_Object;
12724 -------------------------
12725 -- Is_Attribute_Result --
12726 -------------------------
12728 function Is_Attribute_Result (N : Node_Id) return Boolean is
12730 return Nkind (N) = N_Attribute_Reference
12731 and then Attribute_Name (N) = Name_Result;
12732 end Is_Attribute_Result;
12734 -------------------------
12735 -- Is_Attribute_Update --
12736 -------------------------
12738 function Is_Attribute_Update (N : Node_Id) return Boolean is
12740 return Nkind (N) = N_Attribute_Reference
12741 and then Attribute_Name (N) = Name_Update;
12742 end Is_Attribute_Update;
12744 ------------------------------------
12745 -- Is_Body_Or_Package_Declaration --
12746 ------------------------------------
12748 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
12750 return Nkind_In (N, N_Entry_Body,
12752 N_Package_Declaration,
12756 end Is_Body_Or_Package_Declaration;
12758 -----------------------
12759 -- Is_Bounded_String --
12760 -----------------------
12762 function Is_Bounded_String (T : Entity_Id) return Boolean is
12763 Under : constant Entity_Id := Underlying_Type (Root_Type (T));
12766 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
12767 -- Super_String, or one of the [Wide_]Wide_ versions. This will
12768 -- be True for all the Bounded_String types in instances of the
12769 -- Generic_Bounded_Length generics, and for types derived from those.
12771 return Present (Under)
12772 and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
12773 Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
12774 Is_RTE (Root_Type (Under), RO_WW_Super_String));
12775 end Is_Bounded_String;
12777 ---------------------
12778 -- Is_CCT_Instance --
12779 ---------------------
12781 function Is_CCT_Instance
12782 (Ref_Id : Entity_Id;
12783 Context_Id : Entity_Id) return Boolean
12786 pragma Assert (Ekind_In (Ref_Id, E_Protected_Type, E_Task_Type));
12788 if Is_Single_Task_Object (Context_Id) then
12789 return Scope_Within_Or_Same (Etype (Context_Id), Ref_Id);
12792 pragma Assert (Ekind_In (Context_Id, E_Entry,
12800 return Scope_Within_Or_Same (Context_Id, Ref_Id);
12802 end Is_CCT_Instance;
12804 -------------------------
12805 -- Is_Child_Or_Sibling --
12806 -------------------------
12808 function Is_Child_Or_Sibling
12809 (Pack_1 : Entity_Id;
12810 Pack_2 : Entity_Id) return Boolean
12812 function Distance_From_Standard (Pack : Entity_Id) return Nat;
12813 -- Given an arbitrary package, return the number of "climbs" necessary
12814 -- to reach scope Standard_Standard.
12816 procedure Equalize_Depths
12817 (Pack : in out Entity_Id;
12818 Depth : in out Nat;
12819 Depth_To_Reach : Nat);
12820 -- Given an arbitrary package, its depth and a target depth to reach,
12821 -- climb the scope chain until the said depth is reached. The pointer
12822 -- to the package and its depth a modified during the climb.
12824 ----------------------------
12825 -- Distance_From_Standard --
12826 ----------------------------
12828 function Distance_From_Standard (Pack : Entity_Id) return Nat is
12835 while Present (Scop) and then Scop /= Standard_Standard loop
12837 Scop := Scope (Scop);
12841 end Distance_From_Standard;
12843 ---------------------
12844 -- Equalize_Depths --
12845 ---------------------
12847 procedure Equalize_Depths
12848 (Pack : in out Entity_Id;
12849 Depth : in out Nat;
12850 Depth_To_Reach : Nat)
12853 -- The package must be at a greater or equal depth
12855 if Depth < Depth_To_Reach then
12856 raise Program_Error;
12859 -- Climb the scope chain until the desired depth is reached
12861 while Present (Pack) and then Depth /= Depth_To_Reach loop
12862 Pack := Scope (Pack);
12863 Depth := Depth - 1;
12865 end Equalize_Depths;
12869 P_1 : Entity_Id := Pack_1;
12870 P_1_Child : Boolean := False;
12871 P_1_Depth : Nat := Distance_From_Standard (P_1);
12872 P_2 : Entity_Id := Pack_2;
12873 P_2_Child : Boolean := False;
12874 P_2_Depth : Nat := Distance_From_Standard (P_2);
12876 -- Start of processing for Is_Child_Or_Sibling
12880 (Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
12882 -- Both packages denote the same entity, therefore they cannot be
12883 -- children or siblings.
12888 -- One of the packages is at a deeper level than the other. Note that
12889 -- both may still come from different hierarchies.
12897 elsif P_1_Depth > P_2_Depth then
12900 Depth => P_1_Depth,
12901 Depth_To_Reach => P_2_Depth);
12910 elsif P_2_Depth > P_1_Depth then
12913 Depth => P_2_Depth,
12914 Depth_To_Reach => P_1_Depth);
12918 -- At this stage the package pointers have been elevated to the same
12919 -- depth. If the related entities are the same, then one package is a
12920 -- potential child of the other:
12924 -- X became P_1 P_2 or vice versa
12930 return Is_Child_Unit (Pack_1);
12932 else pragma Assert (P_2_Child);
12933 return Is_Child_Unit (Pack_2);
12936 -- The packages may come from the same package chain or from entirely
12937 -- different hierarcies. To determine this, climb the scope stack until
12938 -- a common root is found.
12940 -- (root) (root 1) (root 2)
12945 while Present (P_1) and then Present (P_2) loop
12947 -- The two packages may be siblings
12950 return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2);
12953 P_1 := Scope (P_1);
12954 P_2 := Scope (P_2);
12959 end Is_Child_Or_Sibling;
12961 -----------------------------
12962 -- Is_Concurrent_Interface --
12963 -----------------------------
12965 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
12967 return Is_Interface (T)
12969 (Is_Protected_Interface (T)
12970 or else Is_Synchronized_Interface (T)
12971 or else Is_Task_Interface (T));
12972 end Is_Concurrent_Interface;
12974 -----------------------
12975 -- Is_Constant_Bound --
12976 -----------------------
12978 function Is_Constant_Bound (Exp : Node_Id) return Boolean is
12980 if Compile_Time_Known_Value (Exp) then
12983 elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
12984 return Is_Constant_Object (Entity (Exp))
12985 or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
12987 elsif Nkind (Exp) in N_Binary_Op then
12988 return Is_Constant_Bound (Left_Opnd (Exp))
12989 and then Is_Constant_Bound (Right_Opnd (Exp))
12990 and then Scope (Entity (Exp)) = Standard_Standard;
12995 end Is_Constant_Bound;
12997 ---------------------------
12998 -- Is_Container_Element --
12999 ---------------------------
13001 function Is_Container_Element (Exp : Node_Id) return Boolean is
13002 Loc : constant Source_Ptr := Sloc (Exp);
13003 Pref : constant Node_Id := Prefix (Exp);
13006 -- Call to an indexing aspect
13008 Cont_Typ : Entity_Id;
13009 -- The type of the container being accessed
13011 Elem_Typ : Entity_Id;
13012 -- Its element type
13014 Indexing : Entity_Id;
13015 Is_Const : Boolean;
13016 -- Indicates that constant indexing is used, and the element is thus
13019 Ref_Typ : Entity_Id;
13020 -- The reference type returned by the indexing operation
13023 -- If C is a container, in a context that imposes the element type of
13024 -- that container, the indexing notation C (X) is rewritten as:
13026 -- Indexing (C, X).Discr.all
13028 -- where Indexing is one of the indexing aspects of the container.
13029 -- If the context does not require a reference, the construct can be
13034 -- First, verify that the construct has the proper form
13036 if not Expander_Active then
13039 elsif Nkind (Pref) /= N_Selected_Component then
13042 elsif Nkind (Prefix (Pref)) /= N_Function_Call then
13046 Call := Prefix (Pref);
13047 Ref_Typ := Etype (Call);
13050 if not Has_Implicit_Dereference (Ref_Typ)
13051 or else No (First (Parameter_Associations (Call)))
13052 or else not Is_Entity_Name (Name (Call))
13057 -- Retrieve type of container object, and its iterator aspects
13059 Cont_Typ := Etype (First (Parameter_Associations (Call)));
13060 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Constant_Indexing);
13063 if No (Indexing) then
13065 -- Container should have at least one indexing operation
13069 elsif Entity (Name (Call)) /= Entity (Indexing) then
13071 -- This may be a variable indexing operation
13073 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Variable_Indexing);
13076 or else Entity (Name (Call)) /= Entity (Indexing)
13085 Elem_Typ := Find_Value_Of_Aspect (Cont_Typ, Aspect_Iterator_Element);
13087 if No (Elem_Typ) or else Entity (Elem_Typ) /= Etype (Exp) then
13091 -- Check that the expression is not the target of an assignment, in
13092 -- which case the rewriting is not possible.
13094 if not Is_Const then
13100 while Present (Par)
13102 if Nkind (Parent (Par)) = N_Assignment_Statement
13103 and then Par = Name (Parent (Par))
13107 -- A renaming produces a reference, and the transformation
13110 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
13114 (Nkind (Parent (Par)), N_Function_Call,
13115 N_Procedure_Call_Statement,
13116 N_Entry_Call_Statement)
13118 -- Check that the element is not part of an actual for an
13119 -- in-out parameter.
13126 F := First_Formal (Entity (Name (Parent (Par))));
13127 A := First (Parameter_Associations (Parent (Par)));
13128 while Present (F) loop
13129 if A = Par and then Ekind (F) /= E_In_Parameter then
13138 -- E_In_Parameter in a call: element is not modified.
13143 Par := Parent (Par);
13148 -- The expression has the proper form and the context requires the
13149 -- element type. Retrieve the Element function of the container and
13150 -- rewrite the construct as a call to it.
13156 Op := First_Elmt (Primitive_Operations (Cont_Typ));
13157 while Present (Op) loop
13158 exit when Chars (Node (Op)) = Name_Element;
13167 Make_Function_Call (Loc,
13168 Name => New_Occurrence_Of (Node (Op), Loc),
13169 Parameter_Associations => Parameter_Associations (Call)));
13170 Analyze_And_Resolve (Exp, Entity (Elem_Typ));
13174 end Is_Container_Element;
13176 ----------------------------
13177 -- Is_Contract_Annotation --
13178 ----------------------------
13180 function Is_Contract_Annotation (Item : Node_Id) return Boolean is
13182 return Is_Package_Contract_Annotation (Item)
13184 Is_Subprogram_Contract_Annotation (Item);
13185 end Is_Contract_Annotation;
13187 --------------------------------------
13188 -- Is_Controlling_Limited_Procedure --
13189 --------------------------------------
13191 function Is_Controlling_Limited_Procedure
13192 (Proc_Nam : Entity_Id) return Boolean
13195 Param_Typ : Entity_Id := Empty;
13198 if Ekind (Proc_Nam) = E_Procedure
13199 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
13201 Param := Parameter_Type (First (
13202 Parameter_Specifications (Parent (Proc_Nam))));
13204 -- The formal may be an anonymous access type.
13206 if Nkind (Param) = N_Access_Definition then
13207 Param_Typ := Entity (Subtype_Mark (Param));
13210 Param_Typ := Etype (Param);
13213 -- In the case where an Itype was created for a dispatchin call, the
13214 -- procedure call has been rewritten. The actual may be an access to
13215 -- interface type in which case it is the designated type that is the
13216 -- controlling type.
13218 elsif Present (Associated_Node_For_Itype (Proc_Nam))
13219 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
13221 Present (Parameter_Associations
13222 (Associated_Node_For_Itype (Proc_Nam)))
13225 Etype (First (Parameter_Associations
13226 (Associated_Node_For_Itype (Proc_Nam))));
13228 if Ekind (Param_Typ) = E_Anonymous_Access_Type then
13229 Param_Typ := Directly_Designated_Type (Param_Typ);
13233 if Present (Param_Typ) then
13235 Is_Interface (Param_Typ)
13236 and then Is_Limited_Record (Param_Typ);
13240 end Is_Controlling_Limited_Procedure;
13242 -----------------------------
13243 -- Is_CPP_Constructor_Call --
13244 -----------------------------
13246 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
13248 return Nkind (N) = N_Function_Call
13249 and then Is_CPP_Class (Etype (Etype (N)))
13250 and then Is_Constructor (Entity (Name (N)))
13251 and then Is_Imported (Entity (Name (N)));
13252 end Is_CPP_Constructor_Call;
13254 -------------------------
13255 -- Is_Current_Instance --
13256 -------------------------
13258 function Is_Current_Instance (N : Node_Id) return Boolean is
13259 Typ : constant Entity_Id := Entity (N);
13263 -- Simplest case: entity is a concurrent type and we are currently
13264 -- inside the body. This will eventually be expanded into a
13265 -- call to Self (for tasks) or _object (for protected objects).
13267 if Is_Concurrent_Type (Typ) and then In_Open_Scopes (Typ) then
13271 -- Check whether the context is a (sub)type declaration for the
13275 while Present (P) loop
13276 if Nkind_In (P, N_Full_Type_Declaration,
13277 N_Private_Type_Declaration,
13278 N_Subtype_Declaration)
13279 and then Comes_From_Source (P)
13280 and then Defining_Entity (P) = Typ
13284 -- A subtype name may appear in an aspect specification for a
13285 -- Predicate_Failure aspect, for which we do not construct a
13286 -- wrapper procedure. The subtype will be replaced by the
13287 -- expression being tested when the corresponding predicate
13288 -- check is expanded.
13290 elsif Nkind (P) = N_Aspect_Specification
13291 and then Nkind (Parent (P)) = N_Subtype_Declaration
13295 elsif Nkind (P) = N_Pragma
13297 Get_Pragma_Id (P) = Pragma_Predicate_Failure
13306 -- In any other context this is not a current occurrence
13309 end Is_Current_Instance;
13311 --------------------
13312 -- Is_Declaration --
13313 --------------------
13315 function Is_Declaration (N : Node_Id) return Boolean is
13318 Is_Declaration_Other_Than_Renaming (N)
13319 or else Is_Renaming_Declaration (N);
13320 end Is_Declaration;
13322 ----------------------------------------
13323 -- Is_Declaration_Other_Than_Renaming --
13324 ----------------------------------------
13326 function Is_Declaration_Other_Than_Renaming (N : Node_Id) return Boolean is
13329 when N_Abstract_Subprogram_Declaration
13330 | N_Exception_Declaration
13331 | N_Expression_Function
13332 | N_Full_Type_Declaration
13333 | N_Generic_Package_Declaration
13334 | N_Generic_Subprogram_Declaration
13335 | N_Number_Declaration
13336 | N_Object_Declaration
13337 | N_Package_Declaration
13338 | N_Private_Extension_Declaration
13339 | N_Private_Type_Declaration
13340 | N_Subprogram_Declaration
13341 | N_Subtype_Declaration
13348 end Is_Declaration_Other_Than_Renaming;
13350 --------------------------------
13351 -- Is_Declared_Within_Variant --
13352 --------------------------------
13354 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
13355 Comp_Decl : constant Node_Id := Parent (Comp);
13356 Comp_List : constant Node_Id := Parent (Comp_Decl);
13358 return Nkind (Parent (Comp_List)) = N_Variant;
13359 end Is_Declared_Within_Variant;
13361 ----------------------------------------------
13362 -- Is_Dependent_Component_Of_Mutable_Object --
13363 ----------------------------------------------
13365 function Is_Dependent_Component_Of_Mutable_Object
13366 (Object : Node_Id) return Boolean
13369 Prefix_Type : Entity_Id;
13370 P_Aliased : Boolean := False;
13373 Deref : Node_Id := Object;
13374 -- Dereference node, in something like X.all.Y(2)
13376 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
13379 -- Find the dereference node if any
13381 while Nkind_In (Deref, N_Indexed_Component,
13382 N_Selected_Component,
13385 Deref := Prefix (Deref);
13388 -- Ada 2005: If we have a component or slice of a dereference,
13389 -- something like X.all.Y (2), and the type of X is access-to-constant,
13390 -- Is_Variable will return False, because it is indeed a constant
13391 -- view. But it might be a view of a variable object, so we want the
13392 -- following condition to be True in that case.
13394 if Is_Variable (Object)
13395 or else (Ada_Version >= Ada_2005
13396 and then Nkind (Deref) = N_Explicit_Dereference)
13398 if Nkind (Object) = N_Selected_Component then
13399 P := Prefix (Object);
13400 Prefix_Type := Etype (P);
13402 if Is_Entity_Name (P) then
13403 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
13404 Prefix_Type := Base_Type (Prefix_Type);
13407 if Is_Aliased (Entity (P)) then
13411 -- A discriminant check on a selected component may be expanded
13412 -- into a dereference when removing side effects. Recover the
13413 -- original node and its type, which may be unconstrained.
13415 elsif Nkind (P) = N_Explicit_Dereference
13416 and then not (Comes_From_Source (P))
13418 P := Original_Node (P);
13419 Prefix_Type := Etype (P);
13422 -- Check for prefix being an aliased component???
13428 -- A heap object is constrained by its initial value
13430 -- Ada 2005 (AI-363): Always assume the object could be mutable in
13431 -- the dereferenced case, since the access value might denote an
13432 -- unconstrained aliased object, whereas in Ada 95 the designated
13433 -- object is guaranteed to be constrained. A worst-case assumption
13434 -- has to apply in Ada 2005 because we can't tell at compile
13435 -- time whether the object is "constrained by its initial value",
13436 -- despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
13437 -- rules (these rules are acknowledged to need fixing). We don't
13438 -- impose this more stringent checking for earlier Ada versions or
13439 -- when Relaxed_RM_Semantics applies (the latter for CodePeer's
13440 -- benefit, though it's unclear on why using -gnat95 would not be
13443 if Ada_Version < Ada_2005 or else Relaxed_RM_Semantics then
13444 if Is_Access_Type (Prefix_Type)
13445 or else Nkind (P) = N_Explicit_Dereference
13450 else pragma Assert (Ada_Version >= Ada_2005);
13451 if Is_Access_Type (Prefix_Type) then
13453 -- If the access type is pool-specific, and there is no
13454 -- constrained partial view of the designated type, then the
13455 -- designated object is known to be constrained.
13457 if Ekind (Prefix_Type) = E_Access_Type
13458 and then not Object_Type_Has_Constrained_Partial_View
13459 (Typ => Designated_Type (Prefix_Type),
13460 Scop => Current_Scope)
13464 -- Otherwise (general access type, or there is a constrained
13465 -- partial view of the designated type), we need to check
13466 -- based on the designated type.
13469 Prefix_Type := Designated_Type (Prefix_Type);
13475 Original_Record_Component (Entity (Selector_Name (Object)));
13477 -- As per AI-0017, the renaming is illegal in a generic body, even
13478 -- if the subtype is indefinite.
13480 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
13482 if not Is_Constrained (Prefix_Type)
13483 and then (Is_Definite_Subtype (Prefix_Type)
13485 (Is_Generic_Type (Prefix_Type)
13486 and then Ekind (Current_Scope) = E_Generic_Package
13487 and then In_Package_Body (Current_Scope)))
13489 and then (Is_Declared_Within_Variant (Comp)
13490 or else Has_Discriminant_Dependent_Constraint (Comp))
13491 and then (not P_Aliased or else Ada_Version >= Ada_2005)
13495 -- If the prefix is of an access type at this point, then we want
13496 -- to return False, rather than calling this function recursively
13497 -- on the access object (which itself might be a discriminant-
13498 -- dependent component of some other object, but that isn't
13499 -- relevant to checking the object passed to us). This avoids
13500 -- issuing wrong errors when compiling with -gnatc, where there
13501 -- can be implicit dereferences that have not been expanded.
13503 elsif Is_Access_Type (Etype (Prefix (Object))) then
13508 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
13511 elsif Nkind (Object) = N_Indexed_Component
13512 or else Nkind (Object) = N_Slice
13514 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
13516 -- A type conversion that Is_Variable is a view conversion:
13517 -- go back to the denoted object.
13519 elsif Nkind (Object) = N_Type_Conversion then
13521 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
13526 end Is_Dependent_Component_Of_Mutable_Object;
13528 ---------------------
13529 -- Is_Dereferenced --
13530 ---------------------
13532 function Is_Dereferenced (N : Node_Id) return Boolean is
13533 P : constant Node_Id := Parent (N);
13535 return Nkind_In (P, N_Selected_Component,
13536 N_Explicit_Dereference,
13537 N_Indexed_Component,
13539 and then Prefix (P) = N;
13540 end Is_Dereferenced;
13542 ----------------------
13543 -- Is_Descendant_Of --
13544 ----------------------
13546 function Is_Descendant_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
13551 pragma Assert (Nkind (T1) in N_Entity);
13552 pragma Assert (Nkind (T2) in N_Entity);
13554 T := Base_Type (T1);
13556 -- Immediate return if the types match
13561 -- Comment needed here ???
13563 elsif Ekind (T) = E_Class_Wide_Type then
13564 return Etype (T) = T2;
13572 -- Done if we found the type we are looking for
13577 -- Done if no more derivations to check
13584 -- Following test catches error cases resulting from prev errors
13586 elsif No (Etyp) then
13589 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
13592 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
13596 T := Base_Type (Etyp);
13599 end Is_Descendant_Of;
13601 ----------------------------------------
13602 -- Is_Descendant_Of_Suspension_Object --
13603 ----------------------------------------
13605 function Is_Descendant_Of_Suspension_Object
13606 (Typ : Entity_Id) return Boolean
13608 Cur_Typ : Entity_Id;
13609 Par_Typ : Entity_Id;
13612 -- Climb the type derivation chain checking each parent type against
13613 -- Suspension_Object.
13615 Cur_Typ := Base_Type (Typ);
13616 while Present (Cur_Typ) loop
13617 Par_Typ := Etype (Cur_Typ);
13619 -- The current type is a match
13621 if Is_Suspension_Object (Cur_Typ) then
13624 -- Stop the traversal once the root of the derivation chain has been
13625 -- reached. In that case the current type is its own base type.
13627 elsif Cur_Typ = Par_Typ then
13631 Cur_Typ := Base_Type (Par_Typ);
13635 end Is_Descendant_Of_Suspension_Object;
13637 ---------------------------------------------
13638 -- Is_Double_Precision_Floating_Point_Type --
13639 ---------------------------------------------
13641 function Is_Double_Precision_Floating_Point_Type
13642 (E : Entity_Id) return Boolean is
13644 return Is_Floating_Point_Type (E)
13645 and then Machine_Radix_Value (E) = Uint_2
13646 and then Machine_Mantissa_Value (E) = UI_From_Int (53)
13647 and then Machine_Emax_Value (E) = Uint_2 ** Uint_10
13648 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_10);
13649 end Is_Double_Precision_Floating_Point_Type;
13651 -----------------------------
13652 -- Is_Effectively_Volatile --
13653 -----------------------------
13655 function Is_Effectively_Volatile (Id : Entity_Id) return Boolean is
13657 if Is_Type (Id) then
13659 -- An arbitrary type is effectively volatile when it is subject to
13660 -- pragma Atomic or Volatile.
13662 if Is_Volatile (Id) then
13665 -- An array type is effectively volatile when it is subject to pragma
13666 -- Atomic_Components or Volatile_Components or its component type is
13667 -- effectively volatile.
13669 elsif Is_Array_Type (Id) then
13671 Anc : Entity_Id := Base_Type (Id);
13673 if Is_Private_Type (Anc) then
13674 Anc := Full_View (Anc);
13677 -- Test for presence of ancestor, as the full view of a private
13678 -- type may be missing in case of error.
13681 Has_Volatile_Components (Id)
13684 and then Is_Effectively_Volatile (Component_Type (Anc)));
13687 -- A protected type is always volatile
13689 elsif Is_Protected_Type (Id) then
13692 -- A descendant of Ada.Synchronous_Task_Control.Suspension_Object is
13693 -- automatically volatile.
13695 elsif Is_Descendant_Of_Suspension_Object (Id) then
13698 -- Otherwise the type is not effectively volatile
13704 -- Otherwise Id denotes an object
13709 or else Has_Volatile_Components (Id)
13710 or else Is_Effectively_Volatile (Etype (Id));
13712 end Is_Effectively_Volatile;
13714 ------------------------------------
13715 -- Is_Effectively_Volatile_Object --
13716 ------------------------------------
13718 function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean is
13720 if Is_Entity_Name (N) then
13721 return Is_Effectively_Volatile (Entity (N));
13723 elsif Nkind (N) = N_Indexed_Component then
13724 return Is_Effectively_Volatile_Object (Prefix (N));
13726 elsif Nkind (N) = N_Selected_Component then
13728 Is_Effectively_Volatile_Object (Prefix (N))
13730 Is_Effectively_Volatile_Object (Selector_Name (N));
13735 end Is_Effectively_Volatile_Object;
13737 -------------------
13738 -- Is_Entry_Body --
13739 -------------------
13741 function Is_Entry_Body (Id : Entity_Id) return Boolean is
13744 Ekind_In (Id, E_Entry, E_Entry_Family)
13745 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Body;
13748 --------------------------
13749 -- Is_Entry_Declaration --
13750 --------------------------
13752 function Is_Entry_Declaration (Id : Entity_Id) return Boolean is
13755 Ekind_In (Id, E_Entry, E_Entry_Family)
13756 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Declaration;
13757 end Is_Entry_Declaration;
13759 ------------------------------------
13760 -- Is_Expanded_Priority_Attribute --
13761 ------------------------------------
13763 function Is_Expanded_Priority_Attribute (E : Entity_Id) return Boolean is
13766 Nkind (E) = N_Function_Call
13767 and then not Configurable_Run_Time_Mode
13768 and then (Entity (Name (E)) = RTE (RE_Get_Ceiling)
13769 or else Entity (Name (E)) = RTE (RO_PE_Get_Ceiling));
13770 end Is_Expanded_Priority_Attribute;
13772 ----------------------------
13773 -- Is_Expression_Function --
13774 ----------------------------
13776 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
13778 if Ekind_In (Subp, E_Function, E_Subprogram_Body) then
13780 Nkind (Original_Node (Unit_Declaration_Node (Subp))) =
13781 N_Expression_Function;
13785 end Is_Expression_Function;
13787 ------------------------------------------
13788 -- Is_Expression_Function_Or_Completion --
13789 ------------------------------------------
13791 function Is_Expression_Function_Or_Completion
13792 (Subp : Entity_Id) return Boolean
13794 Subp_Decl : Node_Id;
13797 if Ekind (Subp) = E_Function then
13798 Subp_Decl := Unit_Declaration_Node (Subp);
13800 -- The function declaration is either an expression function or is
13801 -- completed by an expression function body.
13804 Is_Expression_Function (Subp)
13805 or else (Nkind (Subp_Decl) = N_Subprogram_Declaration
13806 and then Present (Corresponding_Body (Subp_Decl))
13807 and then Is_Expression_Function
13808 (Corresponding_Body (Subp_Decl)));
13810 elsif Ekind (Subp) = E_Subprogram_Body then
13811 return Is_Expression_Function (Subp);
13816 end Is_Expression_Function_Or_Completion;
13818 -----------------------
13819 -- Is_EVF_Expression --
13820 -----------------------
13822 function Is_EVF_Expression (N : Node_Id) return Boolean is
13823 Orig_N : constant Node_Id := Original_Node (N);
13829 -- Detect a reference to a formal parameter of a specific tagged type
13830 -- whose related subprogram is subject to pragma Expresions_Visible with
13833 if Is_Entity_Name (N) and then Present (Entity (N)) then
13838 and then Is_Specific_Tagged_Type (Etype (Id))
13839 and then Extensions_Visible_Status (Id) =
13840 Extensions_Visible_False;
13842 -- A case expression is an EVF expression when it contains at least one
13843 -- EVF dependent_expression. Note that a case expression may have been
13844 -- expanded, hence the use of Original_Node.
13846 elsif Nkind (Orig_N) = N_Case_Expression then
13847 Alt := First (Alternatives (Orig_N));
13848 while Present (Alt) loop
13849 if Is_EVF_Expression (Expression (Alt)) then
13856 -- An if expression is an EVF expression when it contains at least one
13857 -- EVF dependent_expression. Note that an if expression may have been
13858 -- expanded, hence the use of Original_Node.
13860 elsif Nkind (Orig_N) = N_If_Expression then
13861 Expr := Next (First (Expressions (Orig_N)));
13862 while Present (Expr) loop
13863 if Is_EVF_Expression (Expr) then
13870 -- A qualified expression or a type conversion is an EVF expression when
13871 -- its operand is an EVF expression.
13873 elsif Nkind_In (N, N_Qualified_Expression,
13874 N_Unchecked_Type_Conversion,
13877 return Is_EVF_Expression (Expression (N));
13879 -- Attributes 'Loop_Entry, 'Old, and 'Update are EVF expressions when
13880 -- their prefix denotes an EVF expression.
13882 elsif Nkind (N) = N_Attribute_Reference
13883 and then Nam_In (Attribute_Name (N), Name_Loop_Entry,
13887 return Is_EVF_Expression (Prefix (N));
13891 end Is_EVF_Expression;
13897 function Is_False (U : Uint) return Boolean is
13902 ---------------------------
13903 -- Is_Fixed_Model_Number --
13904 ---------------------------
13906 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
13907 S : constant Ureal := Small_Value (T);
13908 M : Urealp.Save_Mark;
13913 R := (U = UR_Trunc (U / S) * S);
13914 Urealp.Release (M);
13916 end Is_Fixed_Model_Number;
13918 -------------------------------
13919 -- Is_Fully_Initialized_Type --
13920 -------------------------------
13922 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
13926 if Is_Scalar_Type (Typ) then
13928 -- A scalar type with an aspect Default_Value is fully initialized
13930 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
13931 -- of a scalar type, but we don't take that into account here, since
13932 -- we don't want these to affect warnings.
13934 return Has_Default_Aspect (Typ);
13936 elsif Is_Access_Type (Typ) then
13939 elsif Is_Array_Type (Typ) then
13940 if Is_Fully_Initialized_Type (Component_Type (Typ))
13941 or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
13946 -- An interesting case, if we have a constrained type one of whose
13947 -- bounds is known to be null, then there are no elements to be
13948 -- initialized, so all the elements are initialized.
13950 if Is_Constrained (Typ) then
13953 Indx_Typ : Entity_Id;
13954 Lbd, Hbd : Node_Id;
13957 Indx := First_Index (Typ);
13958 while Present (Indx) loop
13959 if Etype (Indx) = Any_Type then
13962 -- If index is a range, use directly
13964 elsif Nkind (Indx) = N_Range then
13965 Lbd := Low_Bound (Indx);
13966 Hbd := High_Bound (Indx);
13969 Indx_Typ := Etype (Indx);
13971 if Is_Private_Type (Indx_Typ) then
13972 Indx_Typ := Full_View (Indx_Typ);
13975 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
13978 Lbd := Type_Low_Bound (Indx_Typ);
13979 Hbd := Type_High_Bound (Indx_Typ);
13983 if Compile_Time_Known_Value (Lbd)
13985 Compile_Time_Known_Value (Hbd)
13987 if Expr_Value (Hbd) < Expr_Value (Lbd) then
13997 -- If no null indexes, then type is not fully initialized
14003 elsif Is_Record_Type (Typ) then
14004 if Has_Discriminants (Typ)
14006 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
14007 and then Is_Fully_Initialized_Variant (Typ)
14012 -- We consider bounded string types to be fully initialized, because
14013 -- otherwise we get false alarms when the Data component is not
14014 -- default-initialized.
14016 if Is_Bounded_String (Typ) then
14020 -- Controlled records are considered to be fully initialized if
14021 -- there is a user defined Initialize routine. This may not be
14022 -- entirely correct, but as the spec notes, we are guessing here
14023 -- what is best from the point of view of issuing warnings.
14025 if Is_Controlled (Typ) then
14027 Utyp : constant Entity_Id := Underlying_Type (Typ);
14030 if Present (Utyp) then
14032 Init : constant Entity_Id :=
14033 (Find_Optional_Prim_Op
14034 (Underlying_Type (Typ), Name_Initialize));
14038 and then Comes_From_Source (Init)
14039 and then not In_Predefined_Unit (Init)
14043 elsif Has_Null_Extension (Typ)
14045 Is_Fully_Initialized_Type
14046 (Etype (Base_Type (Typ)))
14055 -- Otherwise see if all record components are initialized
14061 Ent := First_Entity (Typ);
14062 while Present (Ent) loop
14063 if Ekind (Ent) = E_Component
14064 and then (No (Parent (Ent))
14065 or else No (Expression (Parent (Ent))))
14066 and then not Is_Fully_Initialized_Type (Etype (Ent))
14068 -- Special VM case for tag components, which need to be
14069 -- defined in this case, but are never initialized as VMs
14070 -- are using other dispatching mechanisms. Ignore this
14071 -- uninitialized case. Note that this applies both to the
14072 -- uTag entry and the main vtable pointer (CPP_Class case).
14074 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
14083 -- No uninitialized components, so type is fully initialized.
14084 -- Note that this catches the case of no components as well.
14088 elsif Is_Concurrent_Type (Typ) then
14091 elsif Is_Private_Type (Typ) then
14093 U : constant Entity_Id := Underlying_Type (Typ);
14099 return Is_Fully_Initialized_Type (U);
14106 end Is_Fully_Initialized_Type;
14108 ----------------------------------
14109 -- Is_Fully_Initialized_Variant --
14110 ----------------------------------
14112 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
14113 Loc : constant Source_Ptr := Sloc (Typ);
14114 Constraints : constant List_Id := New_List;
14115 Components : constant Elist_Id := New_Elmt_List;
14116 Comp_Elmt : Elmt_Id;
14118 Comp_List : Node_Id;
14120 Discr_Val : Node_Id;
14122 Report_Errors : Boolean;
14123 pragma Warnings (Off, Report_Errors);
14126 if Serious_Errors_Detected > 0 then
14130 if Is_Record_Type (Typ)
14131 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
14132 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
14134 Comp_List := Component_List (Type_Definition (Parent (Typ)));
14136 Discr := First_Discriminant (Typ);
14137 while Present (Discr) loop
14138 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
14139 Discr_Val := Expression (Parent (Discr));
14141 if Present (Discr_Val)
14142 and then Is_OK_Static_Expression (Discr_Val)
14144 Append_To (Constraints,
14145 Make_Component_Association (Loc,
14146 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
14147 Expression => New_Copy (Discr_Val)));
14155 Next_Discriminant (Discr);
14160 Comp_List => Comp_List,
14161 Governed_By => Constraints,
14162 Into => Components,
14163 Report_Errors => Report_Errors);
14165 -- Check that each component present is fully initialized
14167 Comp_Elmt := First_Elmt (Components);
14168 while Present (Comp_Elmt) loop
14169 Comp_Id := Node (Comp_Elmt);
14171 if Ekind (Comp_Id) = E_Component
14172 and then (No (Parent (Comp_Id))
14173 or else No (Expression (Parent (Comp_Id))))
14174 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
14179 Next_Elmt (Comp_Elmt);
14184 elsif Is_Private_Type (Typ) then
14186 U : constant Entity_Id := Underlying_Type (Typ);
14192 return Is_Fully_Initialized_Variant (U);
14199 end Is_Fully_Initialized_Variant;
14201 ------------------------------------
14202 -- Is_Generic_Declaration_Or_Body --
14203 ------------------------------------
14205 function Is_Generic_Declaration_Or_Body (Decl : Node_Id) return Boolean is
14206 Spec_Decl : Node_Id;
14209 -- Package/subprogram body
14211 if Nkind_In (Decl, N_Package_Body, N_Subprogram_Body)
14212 and then Present (Corresponding_Spec (Decl))
14214 Spec_Decl := Unit_Declaration_Node (Corresponding_Spec (Decl));
14216 -- Package/subprogram body stub
14218 elsif Nkind_In (Decl, N_Package_Body_Stub, N_Subprogram_Body_Stub)
14219 and then Present (Corresponding_Spec_Of_Stub (Decl))
14222 Unit_Declaration_Node (Corresponding_Spec_Of_Stub (Decl));
14230 -- Rather than inspecting the defining entity of the spec declaration,
14231 -- look at its Nkind. This takes care of the case where the analysis of
14232 -- a generic body modifies the Ekind of its spec to allow for recursive
14236 Nkind_In (Spec_Decl, N_Generic_Package_Declaration,
14237 N_Generic_Subprogram_Declaration);
14238 end Is_Generic_Declaration_Or_Body;
14240 ----------------------------
14241 -- Is_Inherited_Operation --
14242 ----------------------------
14244 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
14245 pragma Assert (Is_Overloadable (E));
14246 Kind : constant Node_Kind := Nkind (Parent (E));
14248 return Kind = N_Full_Type_Declaration
14249 or else Kind = N_Private_Extension_Declaration
14250 or else Kind = N_Subtype_Declaration
14251 or else (Ekind (E) = E_Enumeration_Literal
14252 and then Is_Derived_Type (Etype (E)));
14253 end Is_Inherited_Operation;
14255 -------------------------------------
14256 -- Is_Inherited_Operation_For_Type --
14257 -------------------------------------
14259 function Is_Inherited_Operation_For_Type
14261 Typ : Entity_Id) return Boolean
14264 -- Check that the operation has been created by the type declaration
14266 return Is_Inherited_Operation (E)
14267 and then Defining_Identifier (Parent (E)) = Typ;
14268 end Is_Inherited_Operation_For_Type;
14270 --------------------------------------
14271 -- Is_Inlinable_Expression_Function --
14272 --------------------------------------
14274 function Is_Inlinable_Expression_Function
14275 (Subp : Entity_Id) return Boolean
14277 Return_Expr : Node_Id;
14280 if Is_Expression_Function_Or_Completion (Subp)
14281 and then Has_Pragma_Inline_Always (Subp)
14282 and then Needs_No_Actuals (Subp)
14283 and then No (Contract (Subp))
14284 and then not Is_Dispatching_Operation (Subp)
14285 and then Needs_Finalization (Etype (Subp))
14286 and then not Is_Class_Wide_Type (Etype (Subp))
14287 and then not (Has_Invariants (Etype (Subp)))
14288 and then Present (Subprogram_Body (Subp))
14289 and then Was_Expression_Function (Subprogram_Body (Subp))
14291 Return_Expr := Expression_Of_Expression_Function (Subp);
14293 -- The returned object must not have a qualified expression and its
14294 -- nominal subtype must be statically compatible with the result
14295 -- subtype of the expression function.
14298 Nkind (Return_Expr) = N_Identifier
14299 and then Etype (Return_Expr) = Etype (Subp);
14303 end Is_Inlinable_Expression_Function;
14309 function Is_Iterator (Typ : Entity_Id) return Boolean is
14310 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean;
14311 -- Determine whether type Iter_Typ is a predefined forward or reversible
14314 ----------------------
14315 -- Denotes_Iterator --
14316 ----------------------
14318 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean is
14320 -- Check that the name matches, and that the ultimate ancestor is in
14321 -- a predefined unit, i.e the one that declares iterator interfaces.
14324 Nam_In (Chars (Iter_Typ), Name_Forward_Iterator,
14325 Name_Reversible_Iterator)
14326 and then In_Predefined_Unit (Root_Type (Iter_Typ));
14327 end Denotes_Iterator;
14331 Iface_Elmt : Elmt_Id;
14334 -- Start of processing for Is_Iterator
14337 -- The type may be a subtype of a descendant of the proper instance of
14338 -- the predefined interface type, so we must use the root type of the
14339 -- given type. The same is done for Is_Reversible_Iterator.
14341 if Is_Class_Wide_Type (Typ)
14342 and then Denotes_Iterator (Root_Type (Typ))
14346 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
14349 elsif Present (Find_Value_Of_Aspect (Typ, Aspect_Iterable)) then
14353 Collect_Interfaces (Typ, Ifaces);
14355 Iface_Elmt := First_Elmt (Ifaces);
14356 while Present (Iface_Elmt) loop
14357 if Denotes_Iterator (Node (Iface_Elmt)) then
14361 Next_Elmt (Iface_Elmt);
14368 ----------------------------
14369 -- Is_Iterator_Over_Array --
14370 ----------------------------
14372 function Is_Iterator_Over_Array (N : Node_Id) return Boolean is
14373 Container : constant Node_Id := Name (N);
14374 Container_Typ : constant Entity_Id := Base_Type (Etype (Container));
14376 return Is_Array_Type (Container_Typ);
14377 end Is_Iterator_Over_Array;
14383 -- We seem to have a lot of overlapping functions that do similar things
14384 -- (testing for left hand sides or lvalues???).
14386 function Is_LHS (N : Node_Id) return Is_LHS_Result is
14387 P : constant Node_Id := Parent (N);
14390 -- Return True if we are the left hand side of an assignment statement
14392 if Nkind (P) = N_Assignment_Statement then
14393 if Name (P) = N then
14399 -- Case of prefix of indexed or selected component or slice
14401 elsif Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
14402 and then N = Prefix (P)
14404 -- Here we have the case where the parent P is N.Q or N(Q .. R).
14405 -- If P is an LHS, then N is also effectively an LHS, but there
14406 -- is an important exception. If N is of an access type, then
14407 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
14408 -- case this makes N.all a left hand side but not N itself.
14410 -- If we don't know the type yet, this is the case where we return
14411 -- Unknown, since the answer depends on the type which is unknown.
14413 if No (Etype (N)) then
14416 -- We have an Etype set, so we can check it
14418 elsif Is_Access_Type (Etype (N)) then
14421 -- OK, not access type case, so just test whole expression
14427 -- All other cases are not left hand sides
14434 -----------------------------
14435 -- Is_Library_Level_Entity --
14436 -----------------------------
14438 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
14440 -- The following is a small optimization, and it also properly handles
14441 -- discriminals, which in task bodies might appear in expressions before
14442 -- the corresponding procedure has been created, and which therefore do
14443 -- not have an assigned scope.
14445 if Is_Formal (E) then
14449 -- Normal test is simply that the enclosing dynamic scope is Standard
14451 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
14452 end Is_Library_Level_Entity;
14454 --------------------------------
14455 -- Is_Limited_Class_Wide_Type --
14456 --------------------------------
14458 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
14461 Is_Class_Wide_Type (Typ)
14462 and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
14463 end Is_Limited_Class_Wide_Type;
14465 ---------------------------------
14466 -- Is_Local_Variable_Reference --
14467 ---------------------------------
14469 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
14471 if not Is_Entity_Name (Expr) then
14476 Ent : constant Entity_Id := Entity (Expr);
14477 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
14479 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
14482 return Present (Sub) and then Sub = Current_Subprogram;
14486 end Is_Local_Variable_Reference;
14488 -----------------------
14489 -- Is_Name_Reference --
14490 -----------------------
14492 function Is_Name_Reference (N : Node_Id) return Boolean is
14494 if Is_Entity_Name (N) then
14495 return Present (Entity (N)) and then Is_Object (Entity (N));
14499 when N_Indexed_Component
14503 Is_Name_Reference (Prefix (N))
14504 or else Is_Access_Type (Etype (Prefix (N)));
14506 -- Attributes 'Input, 'Old and 'Result produce objects
14508 when N_Attribute_Reference =>
14510 Nam_In (Attribute_Name (N), Name_Input, Name_Old, Name_Result);
14512 when N_Selected_Component =>
14514 Is_Name_Reference (Selector_Name (N))
14516 (Is_Name_Reference (Prefix (N))
14517 or else Is_Access_Type (Etype (Prefix (N))));
14519 when N_Explicit_Dereference =>
14522 -- A view conversion of a tagged name is a name reference
14524 when N_Type_Conversion =>
14526 Is_Tagged_Type (Etype (Subtype_Mark (N)))
14527 and then Is_Tagged_Type (Etype (Expression (N)))
14528 and then Is_Name_Reference (Expression (N));
14530 -- An unchecked type conversion is considered to be a name if the
14531 -- operand is a name (this construction arises only as a result of
14532 -- expansion activities).
14534 when N_Unchecked_Type_Conversion =>
14535 return Is_Name_Reference (Expression (N));
14540 end Is_Name_Reference;
14542 ---------------------------------
14543 -- Is_Nontrivial_DIC_Procedure --
14544 ---------------------------------
14546 function Is_Nontrivial_DIC_Procedure (Id : Entity_Id) return Boolean is
14547 Body_Decl : Node_Id;
14551 if Ekind (Id) = E_Procedure and then Is_DIC_Procedure (Id) then
14553 Unit_Declaration_Node
14554 (Corresponding_Body (Unit_Declaration_Node (Id)));
14556 -- The body of the Default_Initial_Condition procedure must contain
14557 -- at least one statement, otherwise the generation of the subprogram
14560 pragma Assert (Present (Handled_Statement_Sequence (Body_Decl)));
14562 -- To qualify as nontrivial, the first statement of the procedure
14563 -- must be a check in the form of an if statement. If the original
14564 -- Default_Initial_Condition expression was folded, then the first
14565 -- statement is not a check.
14567 Stmt := First (Statements (Handled_Statement_Sequence (Body_Decl)));
14570 Nkind (Stmt) = N_If_Statement
14571 and then Nkind (Original_Node (Stmt)) = N_Pragma;
14575 end Is_Nontrivial_DIC_Procedure;
14577 -------------------------
14578 -- Is_Null_Record_Type --
14579 -------------------------
14581 function Is_Null_Record_Type (T : Entity_Id) return Boolean is
14582 Decl : constant Node_Id := Parent (T);
14584 return Nkind (Decl) = N_Full_Type_Declaration
14585 and then Nkind (Type_Definition (Decl)) = N_Record_Definition
14587 (No (Component_List (Type_Definition (Decl)))
14588 or else Null_Present (Component_List (Type_Definition (Decl))));
14589 end Is_Null_Record_Type;
14591 ---------------------
14592 -- Is_Object_Image --
14593 ---------------------
14595 function Is_Object_Image (Prefix : Node_Id) return Boolean is
14597 -- When the type of the prefix is not scalar, then the prefix is not
14598 -- valid in any scenario.
14600 if not Is_Scalar_Type (Etype (Prefix)) then
14604 -- Here we test for the case that the prefix is not a type and assume
14605 -- if it is not then it must be a named value or an object reference.
14606 -- This is because the parser always checks that prefixes of attributes
14609 return not (Is_Entity_Name (Prefix) and then Is_Type (Entity (Prefix)));
14610 end Is_Object_Image;
14612 -------------------------
14613 -- Is_Object_Reference --
14614 -------------------------
14616 function Is_Object_Reference (N : Node_Id) return Boolean is
14617 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean;
14618 -- Determine whether N is the name of an internally-generated renaming
14620 --------------------------------------
14621 -- Is_Internally_Generated_Renaming --
14622 --------------------------------------
14624 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean is
14629 while Present (P) loop
14630 if Nkind (P) = N_Object_Renaming_Declaration then
14631 return not Comes_From_Source (P);
14632 elsif Is_List_Member (P) then
14640 end Is_Internally_Generated_Renaming;
14642 -- Start of processing for Is_Object_Reference
14645 if Is_Entity_Name (N) then
14646 return Present (Entity (N)) and then Is_Object (Entity (N));
14650 when N_Indexed_Component
14654 Is_Object_Reference (Prefix (N))
14655 or else Is_Access_Type (Etype (Prefix (N)));
14657 -- In Ada 95, a function call is a constant object; a procedure
14660 -- Note that predefined operators are functions as well, and so
14661 -- are attributes that are (can be renamed as) functions.
14667 return Etype (N) /= Standard_Void_Type;
14669 -- Attributes references 'Loop_Entry, 'Old, and 'Result yield
14670 -- objects, even though they are not functions.
14672 when N_Attribute_Reference =>
14674 Nam_In (Attribute_Name (N), Name_Loop_Entry,
14677 or else Is_Function_Attribute_Name (Attribute_Name (N));
14679 when N_Selected_Component =>
14681 Is_Object_Reference (Selector_Name (N))
14683 (Is_Object_Reference (Prefix (N))
14684 or else Is_Access_Type (Etype (Prefix (N))));
14686 -- An explicit dereference denotes an object, except that a
14687 -- conditional expression gets turned into an explicit dereference
14688 -- in some cases, and conditional expressions are not object
14691 when N_Explicit_Dereference =>
14692 return not Nkind_In (Original_Node (N), N_Case_Expression,
14695 -- A view conversion of a tagged object is an object reference
14697 when N_Type_Conversion =>
14698 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
14699 and then Is_Tagged_Type (Etype (Expression (N)))
14700 and then Is_Object_Reference (Expression (N));
14702 -- An unchecked type conversion is considered to be an object if
14703 -- the operand is an object (this construction arises only as a
14704 -- result of expansion activities).
14706 when N_Unchecked_Type_Conversion =>
14709 -- Allow string literals to act as objects as long as they appear
14710 -- in internally-generated renamings. The expansion of iterators
14711 -- may generate such renamings when the range involves a string
14714 when N_String_Literal =>
14715 return Is_Internally_Generated_Renaming (Parent (N));
14717 -- AI05-0003: In Ada 2012 a qualified expression is a name.
14718 -- This allows disambiguation of function calls and the use
14719 -- of aggregates in more contexts.
14721 when N_Qualified_Expression =>
14722 if Ada_Version < Ada_2012 then
14725 return Is_Object_Reference (Expression (N))
14726 or else Nkind (Expression (N)) = N_Aggregate;
14733 end Is_Object_Reference;
14735 -----------------------------------
14736 -- Is_OK_Variable_For_Out_Formal --
14737 -----------------------------------
14739 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
14741 Note_Possible_Modification (AV, Sure => True);
14743 -- We must reject parenthesized variable names. Comes_From_Source is
14744 -- checked because there are currently cases where the compiler violates
14745 -- this rule (e.g. passing a task object to its controlled Initialize
14746 -- routine). This should be properly documented in sinfo???
14748 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
14751 -- A variable is always allowed
14753 elsif Is_Variable (AV) then
14756 -- Generalized indexing operations are rewritten as explicit
14757 -- dereferences, and it is only during resolution that we can
14758 -- check whether the context requires an access_to_variable type.
14760 elsif Nkind (AV) = N_Explicit_Dereference
14761 and then Ada_Version >= Ada_2012
14762 and then Nkind (Original_Node (AV)) = N_Indexed_Component
14763 and then Present (Etype (Original_Node (AV)))
14764 and then Has_Implicit_Dereference (Etype (Original_Node (AV)))
14766 return not Is_Access_Constant (Etype (Prefix (AV)));
14768 -- Unchecked conversions are allowed only if they come from the
14769 -- generated code, which sometimes uses unchecked conversions for out
14770 -- parameters in cases where code generation is unaffected. We tell
14771 -- source unchecked conversions by seeing if they are rewrites of
14772 -- an original Unchecked_Conversion function call, or of an explicit
14773 -- conversion of a function call or an aggregate (as may happen in the
14774 -- expansion of a packed array aggregate).
14776 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
14777 if Nkind_In (Original_Node (AV), N_Function_Call, N_Aggregate) then
14780 elsif Comes_From_Source (AV)
14781 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
14785 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
14786 return Is_OK_Variable_For_Out_Formal (Expression (AV));
14792 -- Normal type conversions are allowed if argument is a variable
14794 elsif Nkind (AV) = N_Type_Conversion then
14795 if Is_Variable (Expression (AV))
14796 and then Paren_Count (Expression (AV)) = 0
14798 Note_Possible_Modification (Expression (AV), Sure => True);
14801 -- We also allow a non-parenthesized expression that raises
14802 -- constraint error if it rewrites what used to be a variable
14804 elsif Raises_Constraint_Error (Expression (AV))
14805 and then Paren_Count (Expression (AV)) = 0
14806 and then Is_Variable (Original_Node (Expression (AV)))
14810 -- Type conversion of something other than a variable
14816 -- If this node is rewritten, then test the original form, if that is
14817 -- OK, then we consider the rewritten node OK (for example, if the
14818 -- original node is a conversion, then Is_Variable will not be true
14819 -- but we still want to allow the conversion if it converts a variable).
14821 elsif Original_Node (AV) /= AV then
14823 -- In Ada 2012, the explicit dereference may be a rewritten call to a
14824 -- Reference function.
14826 if Ada_Version >= Ada_2012
14827 and then Nkind (Original_Node (AV)) = N_Function_Call
14829 Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
14832 -- Check that this is not a constant reference.
14834 return not Is_Access_Constant (Etype (Prefix (AV)));
14836 elsif Has_Implicit_Dereference (Etype (Original_Node (AV))) then
14838 not Is_Access_Constant (Etype
14839 (Get_Reference_Discriminant (Etype (Original_Node (AV)))));
14842 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
14845 -- All other non-variables are rejected
14850 end Is_OK_Variable_For_Out_Formal;
14852 ----------------------------
14853 -- Is_OK_Volatile_Context --
14854 ----------------------------
14856 function Is_OK_Volatile_Context
14857 (Context : Node_Id;
14858 Obj_Ref : Node_Id) return Boolean
14860 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean;
14861 -- Determine whether an arbitrary node denotes a call to a protected
14862 -- entry, function, or procedure in prefixed form where the prefix is
14865 function Within_Check (Nod : Node_Id) return Boolean;
14866 -- Determine whether an arbitrary node appears in a check node
14868 function Within_Volatile_Function (Id : Entity_Id) return Boolean;
14869 -- Determine whether an arbitrary entity appears in a volatile function
14871 ---------------------------------
14872 -- Is_Protected_Operation_Call --
14873 ---------------------------------
14875 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean is
14880 -- A call to a protected operations retains its selected component
14881 -- form as opposed to other prefixed calls that are transformed in
14884 if Nkind (Nod) = N_Selected_Component then
14885 Pref := Prefix (Nod);
14886 Subp := Selector_Name (Nod);
14890 and then Present (Etype (Pref))
14891 and then Is_Protected_Type (Etype (Pref))
14892 and then Is_Entity_Name (Subp)
14893 and then Present (Entity (Subp))
14894 and then Ekind_In (Entity (Subp), E_Entry,
14901 end Is_Protected_Operation_Call;
14907 function Within_Check (Nod : Node_Id) return Boolean is
14911 -- Climb the parent chain looking for a check node
14914 while Present (Par) loop
14915 if Nkind (Par) in N_Raise_xxx_Error then
14918 -- Prevent the search from going too far
14920 elsif Is_Body_Or_Package_Declaration (Par) then
14924 Par := Parent (Par);
14930 ------------------------------
14931 -- Within_Volatile_Function --
14932 ------------------------------
14934 function Within_Volatile_Function (Id : Entity_Id) return Boolean is
14935 Func_Id : Entity_Id;
14938 -- Traverse the scope stack looking for a [generic] function
14941 while Present (Func_Id) and then Func_Id /= Standard_Standard loop
14942 if Ekind_In (Func_Id, E_Function, E_Generic_Function) then
14943 return Is_Volatile_Function (Func_Id);
14946 Func_Id := Scope (Func_Id);
14950 end Within_Volatile_Function;
14954 Obj_Id : Entity_Id;
14956 -- Start of processing for Is_OK_Volatile_Context
14959 -- The volatile object appears on either side of an assignment
14961 if Nkind (Context) = N_Assignment_Statement then
14964 -- The volatile object is part of the initialization expression of
14967 elsif Nkind (Context) = N_Object_Declaration
14968 and then Present (Expression (Context))
14969 and then Expression (Context) = Obj_Ref
14971 Obj_Id := Defining_Entity (Context);
14973 -- The volatile object acts as the initialization expression of an
14974 -- extended return statement. This is valid context as long as the
14975 -- function is volatile.
14977 if Is_Return_Object (Obj_Id) then
14978 return Within_Volatile_Function (Obj_Id);
14980 -- Otherwise this is a normal object initialization
14986 -- The volatile object acts as the name of a renaming declaration
14988 elsif Nkind (Context) = N_Object_Renaming_Declaration
14989 and then Name (Context) = Obj_Ref
14993 -- The volatile object appears as an actual parameter in a call to an
14994 -- instance of Unchecked_Conversion whose result is renamed.
14996 elsif Nkind (Context) = N_Function_Call
14997 and then Is_Entity_Name (Name (Context))
14998 and then Is_Unchecked_Conversion_Instance (Entity (Name (Context)))
14999 and then Nkind (Parent (Context)) = N_Object_Renaming_Declaration
15003 -- The volatile object is actually the prefix in a protected entry,
15004 -- function, or procedure call.
15006 elsif Is_Protected_Operation_Call (Context) then
15009 -- The volatile object appears as the expression of a simple return
15010 -- statement that applies to a volatile function.
15012 elsif Nkind (Context) = N_Simple_Return_Statement
15013 and then Expression (Context) = Obj_Ref
15016 Within_Volatile_Function (Return_Statement_Entity (Context));
15018 -- The volatile object appears as the prefix of a name occurring in a
15019 -- non-interfering context.
15021 elsif Nkind_In (Context, N_Attribute_Reference,
15022 N_Explicit_Dereference,
15023 N_Indexed_Component,
15024 N_Selected_Component,
15026 and then Prefix (Context) = Obj_Ref
15027 and then Is_OK_Volatile_Context
15028 (Context => Parent (Context),
15029 Obj_Ref => Context)
15033 -- The volatile object appears as the prefix of attributes Address,
15034 -- Alignment, Component_Size, First_Bit, Last_Bit, Position, Size,
15037 elsif Nkind (Context) = N_Attribute_Reference
15038 and then Prefix (Context) = Obj_Ref
15039 and then Nam_In (Attribute_Name (Context), Name_Address,
15041 Name_Component_Size,
15050 -- The volatile object appears as the expression of a type conversion
15051 -- occurring in a non-interfering context.
15053 elsif Nkind_In (Context, N_Type_Conversion,
15054 N_Unchecked_Type_Conversion)
15055 and then Expression (Context) = Obj_Ref
15056 and then Is_OK_Volatile_Context
15057 (Context => Parent (Context),
15058 Obj_Ref => Context)
15062 -- The volatile object appears as the expression in a delay statement
15064 elsif Nkind (Context) in N_Delay_Statement then
15067 -- Allow references to volatile objects in various checks. This is not a
15068 -- direct SPARK 2014 requirement.
15070 elsif Within_Check (Context) then
15073 -- Assume that references to effectively volatile objects that appear
15074 -- as actual parameters in a subprogram call are always legal. A full
15075 -- legality check is done when the actuals are resolved (see routine
15076 -- Resolve_Actuals).
15078 elsif Within_Subprogram_Call (Context) then
15081 -- Otherwise the context is not suitable for an effectively volatile
15087 end Is_OK_Volatile_Context;
15089 ------------------------------------
15090 -- Is_Package_Contract_Annotation --
15091 ------------------------------------
15093 function Is_Package_Contract_Annotation (Item : Node_Id) return Boolean is
15097 if Nkind (Item) = N_Aspect_Specification then
15098 Nam := Chars (Identifier (Item));
15100 else pragma Assert (Nkind (Item) = N_Pragma);
15101 Nam := Pragma_Name (Item);
15104 return Nam = Name_Abstract_State
15105 or else Nam = Name_Initial_Condition
15106 or else Nam = Name_Initializes
15107 or else Nam = Name_Refined_State;
15108 end Is_Package_Contract_Annotation;
15110 -----------------------------------
15111 -- Is_Partially_Initialized_Type --
15112 -----------------------------------
15114 function Is_Partially_Initialized_Type
15116 Include_Implicit : Boolean := True) return Boolean
15119 if Is_Scalar_Type (Typ) then
15122 elsif Is_Access_Type (Typ) then
15123 return Include_Implicit;
15125 elsif Is_Array_Type (Typ) then
15127 -- If component type is partially initialized, so is array type
15129 if Is_Partially_Initialized_Type
15130 (Component_Type (Typ), Include_Implicit)
15134 -- Otherwise we are only partially initialized if we are fully
15135 -- initialized (this is the empty array case, no point in us
15136 -- duplicating that code here).
15139 return Is_Fully_Initialized_Type (Typ);
15142 elsif Is_Record_Type (Typ) then
15144 -- A discriminated type is always partially initialized if in
15147 if Has_Discriminants (Typ) and then Include_Implicit then
15150 -- A tagged type is always partially initialized
15152 elsif Is_Tagged_Type (Typ) then
15155 -- Case of non-discriminated record
15161 Component_Present : Boolean := False;
15162 -- Set True if at least one component is present. If no
15163 -- components are present, then record type is fully
15164 -- initialized (another odd case, like the null array).
15167 -- Loop through components
15169 Ent := First_Entity (Typ);
15170 while Present (Ent) loop
15171 if Ekind (Ent) = E_Component then
15172 Component_Present := True;
15174 -- If a component has an initialization expression then
15175 -- the enclosing record type is partially initialized
15177 if Present (Parent (Ent))
15178 and then Present (Expression (Parent (Ent)))
15182 -- If a component is of a type which is itself partially
15183 -- initialized, then the enclosing record type is also.
15185 elsif Is_Partially_Initialized_Type
15186 (Etype (Ent), Include_Implicit)
15195 -- No initialized components found. If we found any components
15196 -- they were all uninitialized so the result is false.
15198 if Component_Present then
15201 -- But if we found no components, then all the components are
15202 -- initialized so we consider the type to be initialized.
15210 -- Concurrent types are always fully initialized
15212 elsif Is_Concurrent_Type (Typ) then
15215 -- For a private type, go to underlying type. If there is no underlying
15216 -- type then just assume this partially initialized. Not clear if this
15217 -- can happen in a non-error case, but no harm in testing for this.
15219 elsif Is_Private_Type (Typ) then
15221 U : constant Entity_Id := Underlying_Type (Typ);
15226 return Is_Partially_Initialized_Type (U, Include_Implicit);
15230 -- For any other type (are there any?) assume partially initialized
15235 end Is_Partially_Initialized_Type;
15237 ------------------------------------
15238 -- Is_Potentially_Persistent_Type --
15239 ------------------------------------
15241 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
15246 -- For private type, test corresponding full type
15248 if Is_Private_Type (T) then
15249 return Is_Potentially_Persistent_Type (Full_View (T));
15251 -- Scalar types are potentially persistent
15253 elsif Is_Scalar_Type (T) then
15256 -- Record type is potentially persistent if not tagged and the types of
15257 -- all it components are potentially persistent, and no component has
15258 -- an initialization expression.
15260 elsif Is_Record_Type (T)
15261 and then not Is_Tagged_Type (T)
15262 and then not Is_Partially_Initialized_Type (T)
15264 Comp := First_Component (T);
15265 while Present (Comp) loop
15266 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
15269 Next_Entity (Comp);
15275 -- Array type is potentially persistent if its component type is
15276 -- potentially persistent and if all its constraints are static.
15278 elsif Is_Array_Type (T) then
15279 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
15283 Indx := First_Index (T);
15284 while Present (Indx) loop
15285 if not Is_OK_Static_Subtype (Etype (Indx)) then
15294 -- All other types are not potentially persistent
15299 end Is_Potentially_Persistent_Type;
15301 --------------------------------
15302 -- Is_Potentially_Unevaluated --
15303 --------------------------------
15305 function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is
15313 -- A postcondition whose expression is a short-circuit is broken down
15314 -- into individual aspects for better exception reporting. The original
15315 -- short-circuit expression is rewritten as the second operand, and an
15316 -- occurrence of 'Old in that operand is potentially unevaluated.
15317 -- See Sem_ch13.adb for details of this transformation.
15319 if Nkind (Original_Node (Par)) = N_And_Then then
15323 while not Nkind_In (Par, N_If_Expression,
15329 N_Quantified_Expression)
15332 Par := Parent (Par);
15334 -- If the context is not an expression, or if is the result of
15335 -- expansion of an enclosing construct (such as another attribute)
15336 -- the predicate does not apply.
15338 if Nkind (Par) = N_Case_Expression_Alternative then
15341 elsif Nkind (Par) not in N_Subexpr
15342 or else not Comes_From_Source (Par)
15348 if Nkind (Par) = N_If_Expression then
15349 return Is_Elsif (Par) or else Expr /= First (Expressions (Par));
15351 elsif Nkind (Par) = N_Case_Expression then
15352 return Expr /= Expression (Par);
15354 elsif Nkind_In (Par, N_And_Then, N_Or_Else) then
15355 return Expr = Right_Opnd (Par);
15357 elsif Nkind_In (Par, N_In, N_Not_In) then
15359 -- If the membership includes several alternatives, only the first is
15360 -- definitely evaluated.
15362 if Present (Alternatives (Par)) then
15363 return Expr /= First (Alternatives (Par));
15365 -- If this is a range membership both bounds are evaluated
15371 elsif Nkind (Par) = N_Quantified_Expression then
15372 return Expr = Condition (Par);
15377 end Is_Potentially_Unevaluated;
15379 --------------------------------
15380 -- Is_Preelaborable_Aggregate --
15381 --------------------------------
15383 function Is_Preelaborable_Aggregate (Aggr : Node_Id) return Boolean is
15384 Aggr_Typ : constant Entity_Id := Etype (Aggr);
15385 Array_Aggr : constant Boolean := Is_Array_Type (Aggr_Typ);
15387 Anc_Part : Node_Id;
15390 Comp_Typ : Entity_Id;
15395 Comp_Typ := Component_Type (Aggr_Typ);
15398 -- Inspect the ancestor part
15400 if Nkind (Aggr) = N_Extension_Aggregate then
15401 Anc_Part := Ancestor_Part (Aggr);
15403 -- The ancestor denotes a subtype mark
15405 if Is_Entity_Name (Anc_Part)
15406 and then Is_Type (Entity (Anc_Part))
15408 if not Has_Preelaborable_Initialization (Entity (Anc_Part)) then
15412 -- Otherwise the ancestor denotes an expression
15414 elsif not Is_Preelaborable_Construct (Anc_Part) then
15419 -- Inspect the positional associations
15421 Expr := First (Expressions (Aggr));
15422 while Present (Expr) loop
15423 if not Is_Preelaborable_Construct (Expr) then
15430 -- Inspect the named associations
15432 Assoc := First (Component_Associations (Aggr));
15433 while Present (Assoc) loop
15435 -- Inspect the choices of the current named association
15437 Choice := First (Choices (Assoc));
15438 while Present (Choice) loop
15441 -- For a choice to be preelaborable, it must denote either a
15442 -- static range or a static expression.
15444 if Nkind (Choice) = N_Others_Choice then
15447 elsif Nkind (Choice) = N_Range then
15448 if not Is_OK_Static_Range (Choice) then
15452 elsif not Is_OK_Static_Expression (Choice) then
15457 Comp_Typ := Etype (Choice);
15463 -- The type of the choice must have preelaborable initialization if
15464 -- the association carries a <>.
15466 if Box_Present (Assoc) then
15467 if not Has_Preelaborable_Initialization (Comp_Typ) then
15471 -- The type of the expression must have preelaborable initialization
15473 elsif not Is_Preelaborable_Construct (Expression (Assoc)) then
15480 -- At this point the aggregate is preelaborable
15483 end Is_Preelaborable_Aggregate;
15485 --------------------------------
15486 -- Is_Preelaborable_Construct --
15487 --------------------------------
15489 function Is_Preelaborable_Construct (N : Node_Id) return Boolean is
15493 if Nkind_In (N, N_Aggregate, N_Extension_Aggregate) then
15494 return Is_Preelaborable_Aggregate (N);
15496 -- Attributes are allowed in general, even if their prefix is a formal
15497 -- type. It seems that certain attributes known not to be static might
15498 -- not be allowed, but there are no rules to prevent them.
15500 elsif Nkind (N) = N_Attribute_Reference then
15505 elsif Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
15508 elsif Nkind (N) = N_Qualified_Expression then
15509 return Is_Preelaborable_Construct (Expression (N));
15511 -- Names are preelaborable when they denote a discriminant of an
15512 -- enclosing type. Discriminals are also considered for this check.
15514 elsif Is_Entity_Name (N)
15515 and then Present (Entity (N))
15517 (Ekind (Entity (N)) = E_Discriminant
15518 or else (Ekind_In (Entity (N), E_Constant, E_In_Parameter)
15519 and then Present (Discriminal_Link (Entity (N)))))
15525 elsif Nkind (N) = N_Null then
15528 -- Otherwise the construct is not preelaborable
15533 end Is_Preelaborable_Construct;
15535 ---------------------------------
15536 -- Is_Protected_Self_Reference --
15537 ---------------------------------
15539 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
15541 function In_Access_Definition (N : Node_Id) return Boolean;
15542 -- Returns true if N belongs to an access definition
15544 --------------------------
15545 -- In_Access_Definition --
15546 --------------------------
15548 function In_Access_Definition (N : Node_Id) return Boolean is
15553 while Present (P) loop
15554 if Nkind (P) = N_Access_Definition then
15562 end In_Access_Definition;
15564 -- Start of processing for Is_Protected_Self_Reference
15567 -- Verify that prefix is analyzed and has the proper form. Note that
15568 -- the attributes Elab_Spec, Elab_Body, and Elab_Subp_Body, which also
15569 -- produce the address of an entity, do not analyze their prefix
15570 -- because they denote entities that are not necessarily visible.
15571 -- Neither of them can apply to a protected type.
15573 return Ada_Version >= Ada_2005
15574 and then Is_Entity_Name (N)
15575 and then Present (Entity (N))
15576 and then Is_Protected_Type (Entity (N))
15577 and then In_Open_Scopes (Entity (N))
15578 and then not In_Access_Definition (N);
15579 end Is_Protected_Self_Reference;
15581 -----------------------------
15582 -- Is_RCI_Pkg_Spec_Or_Body --
15583 -----------------------------
15585 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
15587 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
15588 -- Return True if the unit of Cunit is an RCI package declaration
15590 ---------------------------
15591 -- Is_RCI_Pkg_Decl_Cunit --
15592 ---------------------------
15594 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
15595 The_Unit : constant Node_Id := Unit (Cunit);
15598 if Nkind (The_Unit) /= N_Package_Declaration then
15602 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
15603 end Is_RCI_Pkg_Decl_Cunit;
15605 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
15608 return Is_RCI_Pkg_Decl_Cunit (Cunit)
15610 (Nkind (Unit (Cunit)) = N_Package_Body
15611 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
15612 end Is_RCI_Pkg_Spec_Or_Body;
15614 -----------------------------------------
15615 -- Is_Remote_Access_To_Class_Wide_Type --
15616 -----------------------------------------
15618 function Is_Remote_Access_To_Class_Wide_Type
15619 (E : Entity_Id) return Boolean
15622 -- A remote access to class-wide type is a general access to object type
15623 -- declared in the visible part of a Remote_Types or Remote_Call_
15626 return Ekind (E) = E_General_Access_Type
15627 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
15628 end Is_Remote_Access_To_Class_Wide_Type;
15630 -----------------------------------------
15631 -- Is_Remote_Access_To_Subprogram_Type --
15632 -----------------------------------------
15634 function Is_Remote_Access_To_Subprogram_Type
15635 (E : Entity_Id) return Boolean
15638 return (Ekind (E) = E_Access_Subprogram_Type
15639 or else (Ekind (E) = E_Record_Type
15640 and then Present (Corresponding_Remote_Type (E))))
15641 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
15642 end Is_Remote_Access_To_Subprogram_Type;
15644 --------------------
15645 -- Is_Remote_Call --
15646 --------------------
15648 function Is_Remote_Call (N : Node_Id) return Boolean is
15650 if Nkind (N) not in N_Subprogram_Call then
15652 -- An entry call cannot be remote
15656 elsif Nkind (Name (N)) in N_Has_Entity
15657 and then Is_Remote_Call_Interface (Entity (Name (N)))
15659 -- A subprogram declared in the spec of a RCI package is remote
15663 elsif Nkind (Name (N)) = N_Explicit_Dereference
15664 and then Is_Remote_Access_To_Subprogram_Type
15665 (Etype (Prefix (Name (N))))
15667 -- The dereference of a RAS is a remote call
15671 elsif Present (Controlling_Argument (N))
15672 and then Is_Remote_Access_To_Class_Wide_Type
15673 (Etype (Controlling_Argument (N)))
15675 -- Any primitive operation call with a controlling argument of
15676 -- a RACW type is a remote call.
15681 -- All other calls are local calls
15684 end Is_Remote_Call;
15686 ----------------------
15687 -- Is_Renamed_Entry --
15688 ----------------------
15690 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
15691 Orig_Node : Node_Id := Empty;
15692 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
15694 function Is_Entry (Nam : Node_Id) return Boolean;
15695 -- Determine whether Nam is an entry. Traverse selectors if there are
15696 -- nested selected components.
15702 function Is_Entry (Nam : Node_Id) return Boolean is
15704 if Nkind (Nam) = N_Selected_Component then
15705 return Is_Entry (Selector_Name (Nam));
15708 return Ekind (Entity (Nam)) = E_Entry;
15711 -- Start of processing for Is_Renamed_Entry
15714 if Present (Alias (Proc_Nam)) then
15715 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
15718 -- Look for a rewritten subprogram renaming declaration
15720 if Nkind (Subp_Decl) = N_Subprogram_Declaration
15721 and then Present (Original_Node (Subp_Decl))
15723 Orig_Node := Original_Node (Subp_Decl);
15726 -- The rewritten subprogram is actually an entry
15728 if Present (Orig_Node)
15729 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
15730 and then Is_Entry (Name (Orig_Node))
15736 end Is_Renamed_Entry;
15738 -----------------------------
15739 -- Is_Renaming_Declaration --
15740 -----------------------------
15742 function Is_Renaming_Declaration (N : Node_Id) return Boolean is
15745 when N_Exception_Renaming_Declaration
15746 | N_Generic_Function_Renaming_Declaration
15747 | N_Generic_Package_Renaming_Declaration
15748 | N_Generic_Procedure_Renaming_Declaration
15749 | N_Object_Renaming_Declaration
15750 | N_Package_Renaming_Declaration
15751 | N_Subprogram_Renaming_Declaration
15758 end Is_Renaming_Declaration;
15760 ----------------------------
15761 -- Is_Reversible_Iterator --
15762 ----------------------------
15764 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
15765 Ifaces_List : Elist_Id;
15766 Iface_Elmt : Elmt_Id;
15770 if Is_Class_Wide_Type (Typ)
15771 and then Chars (Root_Type (Typ)) = Name_Reversible_Iterator
15772 and then In_Predefined_Unit (Root_Type (Typ))
15776 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
15780 Collect_Interfaces (Typ, Ifaces_List);
15782 Iface_Elmt := First_Elmt (Ifaces_List);
15783 while Present (Iface_Elmt) loop
15784 Iface := Node (Iface_Elmt);
15785 if Chars (Iface) = Name_Reversible_Iterator
15786 and then In_Predefined_Unit (Iface)
15791 Next_Elmt (Iface_Elmt);
15796 end Is_Reversible_Iterator;
15798 ----------------------
15799 -- Is_Selector_Name --
15800 ----------------------
15802 function Is_Selector_Name (N : Node_Id) return Boolean is
15804 if not Is_List_Member (N) then
15806 P : constant Node_Id := Parent (N);
15808 return Nkind_In (P, N_Expanded_Name,
15809 N_Generic_Association,
15810 N_Parameter_Association,
15811 N_Selected_Component)
15812 and then Selector_Name (P) = N;
15817 L : constant List_Id := List_Containing (N);
15818 P : constant Node_Id := Parent (L);
15820 return (Nkind (P) = N_Discriminant_Association
15821 and then Selector_Names (P) = L)
15823 (Nkind (P) = N_Component_Association
15824 and then Choices (P) = L);
15827 end Is_Selector_Name;
15829 ---------------------------------
15830 -- Is_Single_Concurrent_Object --
15831 ---------------------------------
15833 function Is_Single_Concurrent_Object (Id : Entity_Id) return Boolean is
15836 Is_Single_Protected_Object (Id) or else Is_Single_Task_Object (Id);
15837 end Is_Single_Concurrent_Object;
15839 -------------------------------
15840 -- Is_Single_Concurrent_Type --
15841 -------------------------------
15843 function Is_Single_Concurrent_Type (Id : Entity_Id) return Boolean is
15846 Ekind_In (Id, E_Protected_Type, E_Task_Type)
15847 and then Is_Single_Concurrent_Type_Declaration
15848 (Declaration_Node (Id));
15849 end Is_Single_Concurrent_Type;
15851 -------------------------------------------
15852 -- Is_Single_Concurrent_Type_Declaration --
15853 -------------------------------------------
15855 function Is_Single_Concurrent_Type_Declaration
15856 (N : Node_Id) return Boolean
15859 return Nkind_In (Original_Node (N), N_Single_Protected_Declaration,
15860 N_Single_Task_Declaration);
15861 end Is_Single_Concurrent_Type_Declaration;
15863 ---------------------------------------------
15864 -- Is_Single_Precision_Floating_Point_Type --
15865 ---------------------------------------------
15867 function Is_Single_Precision_Floating_Point_Type
15868 (E : Entity_Id) return Boolean is
15870 return Is_Floating_Point_Type (E)
15871 and then Machine_Radix_Value (E) = Uint_2
15872 and then Machine_Mantissa_Value (E) = Uint_24
15873 and then Machine_Emax_Value (E) = Uint_2 ** Uint_7
15874 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_7);
15875 end Is_Single_Precision_Floating_Point_Type;
15877 --------------------------------
15878 -- Is_Single_Protected_Object --
15879 --------------------------------
15881 function Is_Single_Protected_Object (Id : Entity_Id) return Boolean is
15884 Ekind (Id) = E_Variable
15885 and then Ekind (Etype (Id)) = E_Protected_Type
15886 and then Is_Single_Concurrent_Type (Etype (Id));
15887 end Is_Single_Protected_Object;
15889 ---------------------------
15890 -- Is_Single_Task_Object --
15891 ---------------------------
15893 function Is_Single_Task_Object (Id : Entity_Id) return Boolean is
15896 Ekind (Id) = E_Variable
15897 and then Ekind (Etype (Id)) = E_Task_Type
15898 and then Is_Single_Concurrent_Type (Etype (Id));
15899 end Is_Single_Task_Object;
15901 -------------------------------------
15902 -- Is_SPARK_05_Initialization_Expr --
15903 -------------------------------------
15905 function Is_SPARK_05_Initialization_Expr (N : Node_Id) return Boolean is
15908 Comp_Assn : Node_Id;
15909 Orig_N : constant Node_Id := Original_Node (N);
15914 if not Comes_From_Source (Orig_N) then
15918 pragma Assert (Nkind (Orig_N) in N_Subexpr);
15920 case Nkind (Orig_N) is
15921 when N_Character_Literal
15922 | N_Integer_Literal
15928 when N_Expanded_Name
15931 if Is_Entity_Name (Orig_N)
15932 and then Present (Entity (Orig_N)) -- needed in some cases
15934 case Ekind (Entity (Orig_N)) is
15936 | E_Enumeration_Literal
15943 if Is_Type (Entity (Orig_N)) then
15951 when N_Qualified_Expression
15952 | N_Type_Conversion
15954 Is_Ok := Is_SPARK_05_Initialization_Expr (Expression (Orig_N));
15957 Is_Ok := Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
15960 | N_Membership_Test
15963 Is_Ok := Is_SPARK_05_Initialization_Expr (Left_Opnd (Orig_N))
15965 Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
15968 | N_Extension_Aggregate
15970 if Nkind (Orig_N) = N_Extension_Aggregate then
15972 Is_SPARK_05_Initialization_Expr (Ancestor_Part (Orig_N));
15975 Expr := First (Expressions (Orig_N));
15976 while Present (Expr) loop
15977 if not Is_SPARK_05_Initialization_Expr (Expr) then
15985 Comp_Assn := First (Component_Associations (Orig_N));
15986 while Present (Comp_Assn) loop
15987 Expr := Expression (Comp_Assn);
15989 -- Note: test for Present here needed for box assocation
15992 and then not Is_SPARK_05_Initialization_Expr (Expr)
16001 when N_Attribute_Reference =>
16002 if Nkind (Prefix (Orig_N)) in N_Subexpr then
16003 Is_Ok := Is_SPARK_05_Initialization_Expr (Prefix (Orig_N));
16006 Expr := First (Expressions (Orig_N));
16007 while Present (Expr) loop
16008 if not Is_SPARK_05_Initialization_Expr (Expr) then
16016 -- Selected components might be expanded named not yet resolved, so
16017 -- default on the safe side. (Eg on sparklex.ads)
16019 when N_Selected_Component =>
16028 end Is_SPARK_05_Initialization_Expr;
16030 ----------------------------------
16031 -- Is_SPARK_05_Object_Reference --
16032 ----------------------------------
16034 function Is_SPARK_05_Object_Reference (N : Node_Id) return Boolean is
16036 if Is_Entity_Name (N) then
16037 return Present (Entity (N))
16039 (Ekind_In (Entity (N), E_Constant, E_Variable)
16040 or else Ekind (Entity (N)) in Formal_Kind);
16044 when N_Selected_Component =>
16045 return Is_SPARK_05_Object_Reference (Prefix (N));
16051 end Is_SPARK_05_Object_Reference;
16053 -----------------------------
16054 -- Is_Specific_Tagged_Type --
16055 -----------------------------
16057 function Is_Specific_Tagged_Type (Typ : Entity_Id) return Boolean is
16058 Full_Typ : Entity_Id;
16061 -- Handle private types
16063 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
16064 Full_Typ := Full_View (Typ);
16069 -- A specific tagged type is a non-class-wide tagged type
16071 return Is_Tagged_Type (Full_Typ) and not Is_Class_Wide_Type (Full_Typ);
16072 end Is_Specific_Tagged_Type;
16078 function Is_Statement (N : Node_Id) return Boolean is
16081 Nkind (N) in N_Statement_Other_Than_Procedure_Call
16082 or else Nkind (N) = N_Procedure_Call_Statement;
16085 ---------------------------------------
16086 -- Is_Subprogram_Contract_Annotation --
16087 ---------------------------------------
16089 function Is_Subprogram_Contract_Annotation
16090 (Item : Node_Id) return Boolean
16095 if Nkind (Item) = N_Aspect_Specification then
16096 Nam := Chars (Identifier (Item));
16098 else pragma Assert (Nkind (Item) = N_Pragma);
16099 Nam := Pragma_Name (Item);
16102 return Nam = Name_Contract_Cases
16103 or else Nam = Name_Depends
16104 or else Nam = Name_Extensions_Visible
16105 or else Nam = Name_Global
16106 or else Nam = Name_Post
16107 or else Nam = Name_Post_Class
16108 or else Nam = Name_Postcondition
16109 or else Nam = Name_Pre
16110 or else Nam = Name_Pre_Class
16111 or else Nam = Name_Precondition
16112 or else Nam = Name_Refined_Depends
16113 or else Nam = Name_Refined_Global
16114 or else Nam = Name_Refined_Post
16115 or else Nam = Name_Test_Case;
16116 end Is_Subprogram_Contract_Annotation;
16118 --------------------------------------------------
16119 -- Is_Subprogram_Stub_Without_Prior_Declaration --
16120 --------------------------------------------------
16122 function Is_Subprogram_Stub_Without_Prior_Declaration
16123 (N : Node_Id) return Boolean
16126 -- A subprogram stub without prior declaration serves as declaration for
16127 -- the actual subprogram body. As such, it has an attached defining
16128 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
16130 return Nkind (N) = N_Subprogram_Body_Stub
16131 and then Ekind (Defining_Entity (N)) /= E_Subprogram_Body;
16132 end Is_Subprogram_Stub_Without_Prior_Declaration;
16134 --------------------------
16135 -- Is_Suspension_Object --
16136 --------------------------
16138 function Is_Suspension_Object (Id : Entity_Id) return Boolean is
16140 -- This approach does an exact name match rather than to rely on
16141 -- RTSfind. Routine Is_Effectively_Volatile is used by clients of the
16142 -- front end at point where all auxiliary tables are locked and any
16143 -- modifications to them are treated as violations. Do not tamper with
16144 -- the tables, instead examine the Chars fields of all the scopes of Id.
16147 Chars (Id) = Name_Suspension_Object
16148 and then Present (Scope (Id))
16149 and then Chars (Scope (Id)) = Name_Synchronous_Task_Control
16150 and then Present (Scope (Scope (Id)))
16151 and then Chars (Scope (Scope (Id))) = Name_Ada
16152 and then Present (Scope (Scope (Scope (Id))))
16153 and then Scope (Scope (Scope (Id))) = Standard_Standard;
16154 end Is_Suspension_Object;
16156 ----------------------------
16157 -- Is_Synchronized_Object --
16158 ----------------------------
16160 function Is_Synchronized_Object (Id : Entity_Id) return Boolean is
16164 if Is_Object (Id) then
16166 -- The object is synchronized if it is of a type that yields a
16167 -- synchronized object.
16169 if Yields_Synchronized_Object (Etype (Id)) then
16172 -- The object is synchronized if it is atomic and Async_Writers is
16175 elsif Is_Atomic (Id) and then Async_Writers_Enabled (Id) then
16178 -- A constant is a synchronized object by default
16180 elsif Ekind (Id) = E_Constant then
16183 -- A variable is a synchronized object if it is subject to pragma
16184 -- Constant_After_Elaboration.
16186 elsif Ekind (Id) = E_Variable then
16187 Prag := Get_Pragma (Id, Pragma_Constant_After_Elaboration);
16189 return Present (Prag) and then Is_Enabled_Pragma (Prag);
16193 -- Otherwise the input is not an object or it does not qualify as a
16194 -- synchronized object.
16197 end Is_Synchronized_Object;
16199 ---------------------------------
16200 -- Is_Synchronized_Tagged_Type --
16201 ---------------------------------
16203 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
16204 Kind : constant Entity_Kind := Ekind (Base_Type (E));
16207 -- A task or protected type derived from an interface is a tagged type.
16208 -- Such a tagged type is called a synchronized tagged type, as are
16209 -- synchronized interfaces and private extensions whose declaration
16210 -- includes the reserved word synchronized.
16212 return (Is_Tagged_Type (E)
16213 and then (Kind = E_Task_Type
16215 Kind = E_Protected_Type))
16218 and then Is_Synchronized_Interface (E))
16220 (Ekind (E) = E_Record_Type_With_Private
16221 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
16222 and then (Synchronized_Present (Parent (E))
16223 or else Is_Synchronized_Interface (Etype (E))));
16224 end Is_Synchronized_Tagged_Type;
16230 function Is_Transfer (N : Node_Id) return Boolean is
16231 Kind : constant Node_Kind := Nkind (N);
16234 if Kind = N_Simple_Return_Statement
16236 Kind = N_Extended_Return_Statement
16238 Kind = N_Goto_Statement
16240 Kind = N_Raise_Statement
16242 Kind = N_Requeue_Statement
16246 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
16247 and then No (Condition (N))
16251 elsif Kind = N_Procedure_Call_Statement
16252 and then Is_Entity_Name (Name (N))
16253 and then Present (Entity (Name (N)))
16254 and then No_Return (Entity (Name (N)))
16258 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
16270 function Is_True (U : Uint) return Boolean is
16275 --------------------------------------
16276 -- Is_Unchecked_Conversion_Instance --
16277 --------------------------------------
16279 function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is
16283 -- Look for a function whose generic parent is the predefined intrinsic
16284 -- function Unchecked_Conversion, or for one that renames such an
16287 if Ekind (Id) = E_Function then
16288 Par := Parent (Id);
16290 if Nkind (Par) = N_Function_Specification then
16291 Par := Generic_Parent (Par);
16293 if Present (Par) then
16295 Chars (Par) = Name_Unchecked_Conversion
16296 and then Is_Intrinsic_Subprogram (Par)
16297 and then In_Predefined_Unit (Par);
16300 Present (Alias (Id))
16301 and then Is_Unchecked_Conversion_Instance (Alias (Id));
16307 end Is_Unchecked_Conversion_Instance;
16309 -------------------------------
16310 -- Is_Universal_Numeric_Type --
16311 -------------------------------
16313 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
16315 return T = Universal_Integer or else T = Universal_Real;
16316 end Is_Universal_Numeric_Type;
16318 ------------------------------
16319 -- Is_User_Defined_Equality --
16320 ------------------------------
16322 function Is_User_Defined_Equality (Id : Entity_Id) return Boolean is
16324 return Ekind (Id) = E_Function
16325 and then Chars (Id) = Name_Op_Eq
16326 and then Comes_From_Source (Id)
16328 -- Internally generated equalities have a full type declaration
16329 -- as their parent.
16331 and then Nkind (Parent (Id)) = N_Function_Specification;
16332 end Is_User_Defined_Equality;
16334 --------------------------------------
16335 -- Is_Validation_Variable_Reference --
16336 --------------------------------------
16338 function Is_Validation_Variable_Reference (N : Node_Id) return Boolean is
16339 Var : constant Node_Id := Unqual_Conv (N);
16340 Var_Id : Entity_Id;
16345 if Is_Entity_Name (Var) then
16346 Var_Id := Entity (Var);
16351 and then Ekind (Var_Id) = E_Variable
16352 and then Present (Validated_Object (Var_Id));
16353 end Is_Validation_Variable_Reference;
16355 ----------------------------
16356 -- Is_Variable_Size_Array --
16357 ----------------------------
16359 function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
16363 pragma Assert (Is_Array_Type (E));
16365 -- Check if some index is initialized with a non-constant value
16367 Idx := First_Index (E);
16368 while Present (Idx) loop
16369 if Nkind (Idx) = N_Range then
16370 if not Is_Constant_Bound (Low_Bound (Idx))
16371 or else not Is_Constant_Bound (High_Bound (Idx))
16377 Idx := Next_Index (Idx);
16381 end Is_Variable_Size_Array;
16383 -----------------------------
16384 -- Is_Variable_Size_Record --
16385 -----------------------------
16387 function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
16389 Comp_Typ : Entity_Id;
16392 pragma Assert (Is_Record_Type (E));
16394 Comp := First_Entity (E);
16395 while Present (Comp) loop
16396 Comp_Typ := Etype (Comp);
16398 -- Recursive call if the record type has discriminants
16400 if Is_Record_Type (Comp_Typ)
16401 and then Has_Discriminants (Comp_Typ)
16402 and then Is_Variable_Size_Record (Comp_Typ)
16406 elsif Is_Array_Type (Comp_Typ)
16407 and then Is_Variable_Size_Array (Comp_Typ)
16412 Next_Entity (Comp);
16416 end Is_Variable_Size_Record;
16422 function Is_Variable
16424 Use_Original_Node : Boolean := True) return Boolean
16426 Orig_Node : Node_Id;
16428 function In_Protected_Function (E : Entity_Id) return Boolean;
16429 -- Within a protected function, the private components of the enclosing
16430 -- protected type are constants. A function nested within a (protected)
16431 -- procedure is not itself protected. Within the body of a protected
16432 -- function the current instance of the protected type is a constant.
16434 function Is_Variable_Prefix (P : Node_Id) return Boolean;
16435 -- Prefixes can involve implicit dereferences, in which case we must
16436 -- test for the case of a reference of a constant access type, which can
16437 -- can never be a variable.
16439 ---------------------------
16440 -- In_Protected_Function --
16441 ---------------------------
16443 function In_Protected_Function (E : Entity_Id) return Boolean is
16448 -- E is the current instance of a type
16450 if Is_Type (E) then
16459 if not Is_Protected_Type (Prot) then
16463 S := Current_Scope;
16464 while Present (S) and then S /= Prot loop
16465 if Ekind (S) = E_Function and then Scope (S) = Prot then
16474 end In_Protected_Function;
16476 ------------------------
16477 -- Is_Variable_Prefix --
16478 ------------------------
16480 function Is_Variable_Prefix (P : Node_Id) return Boolean is
16482 if Is_Access_Type (Etype (P)) then
16483 return not Is_Access_Constant (Root_Type (Etype (P)));
16485 -- For the case of an indexed component whose prefix has a packed
16486 -- array type, the prefix has been rewritten into a type conversion.
16487 -- Determine variable-ness from the converted expression.
16489 elsif Nkind (P) = N_Type_Conversion
16490 and then not Comes_From_Source (P)
16491 and then Is_Array_Type (Etype (P))
16492 and then Is_Packed (Etype (P))
16494 return Is_Variable (Expression (P));
16497 return Is_Variable (P);
16499 end Is_Variable_Prefix;
16501 -- Start of processing for Is_Variable
16504 -- Special check, allow x'Deref(expr) as a variable
16506 if Nkind (N) = N_Attribute_Reference
16507 and then Attribute_Name (N) = Name_Deref
16512 -- Check if we perform the test on the original node since this may be a
16513 -- test of syntactic categories which must not be disturbed by whatever
16514 -- rewriting might have occurred. For example, an aggregate, which is
16515 -- certainly NOT a variable, could be turned into a variable by
16518 if Use_Original_Node then
16519 Orig_Node := Original_Node (N);
16524 -- Definitely OK if Assignment_OK is set. Since this is something that
16525 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
16527 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
16530 -- Normally we go to the original node, but there is one exception where
16531 -- we use the rewritten node, namely when it is an explicit dereference.
16532 -- The generated code may rewrite a prefix which is an access type with
16533 -- an explicit dereference. The dereference is a variable, even though
16534 -- the original node may not be (since it could be a constant of the
16537 -- In Ada 2005 we have a further case to consider: the prefix may be a
16538 -- function call given in prefix notation. The original node appears to
16539 -- be a selected component, but we need to examine the call.
16541 elsif Nkind (N) = N_Explicit_Dereference
16542 and then Nkind (Orig_Node) /= N_Explicit_Dereference
16543 and then Present (Etype (Orig_Node))
16544 and then Is_Access_Type (Etype (Orig_Node))
16546 -- Note that if the prefix is an explicit dereference that does not
16547 -- come from source, we must check for a rewritten function call in
16548 -- prefixed notation before other forms of rewriting, to prevent a
16552 (Nkind (Orig_Node) = N_Function_Call
16553 and then not Is_Access_Constant (Etype (Prefix (N))))
16555 Is_Variable_Prefix (Original_Node (Prefix (N)));
16557 -- in Ada 2012, the dereference may have been added for a type with
16558 -- a declared implicit dereference aspect. Check that it is not an
16559 -- access to constant.
16561 elsif Nkind (N) = N_Explicit_Dereference
16562 and then Present (Etype (Orig_Node))
16563 and then Ada_Version >= Ada_2012
16564 and then Has_Implicit_Dereference (Etype (Orig_Node))
16566 return not Is_Access_Constant (Etype (Prefix (N)));
16568 -- A function call is never a variable
16570 elsif Nkind (N) = N_Function_Call then
16573 -- All remaining checks use the original node
16575 elsif Is_Entity_Name (Orig_Node)
16576 and then Present (Entity (Orig_Node))
16579 E : constant Entity_Id := Entity (Orig_Node);
16580 K : constant Entity_Kind := Ekind (E);
16583 return (K = E_Variable
16584 and then Nkind (Parent (E)) /= N_Exception_Handler)
16585 or else (K = E_Component
16586 and then not In_Protected_Function (E))
16587 or else K = E_Out_Parameter
16588 or else K = E_In_Out_Parameter
16589 or else K = E_Generic_In_Out_Parameter
16591 -- Current instance of type. If this is a protected type, check
16592 -- we are not within the body of one of its protected functions.
16594 or else (Is_Type (E)
16595 and then In_Open_Scopes (E)
16596 and then not In_Protected_Function (E))
16598 or else (Is_Incomplete_Or_Private_Type (E)
16599 and then In_Open_Scopes (Full_View (E)));
16603 case Nkind (Orig_Node) is
16604 when N_Indexed_Component
16607 return Is_Variable_Prefix (Prefix (Orig_Node));
16609 when N_Selected_Component =>
16610 return (Is_Variable (Selector_Name (Orig_Node))
16611 and then Is_Variable_Prefix (Prefix (Orig_Node)))
16613 (Nkind (N) = N_Expanded_Name
16614 and then Scope (Entity (N)) = Entity (Prefix (N)));
16616 -- For an explicit dereference, the type of the prefix cannot
16617 -- be an access to constant or an access to subprogram.
16619 when N_Explicit_Dereference =>
16621 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
16623 return Is_Access_Type (Typ)
16624 and then not Is_Access_Constant (Root_Type (Typ))
16625 and then Ekind (Typ) /= E_Access_Subprogram_Type;
16628 -- The type conversion is the case where we do not deal with the
16629 -- context dependent special case of an actual parameter. Thus
16630 -- the type conversion is only considered a variable for the
16631 -- purposes of this routine if the target type is tagged. However,
16632 -- a type conversion is considered to be a variable if it does not
16633 -- come from source (this deals for example with the conversions
16634 -- of expressions to their actual subtypes).
16636 when N_Type_Conversion =>
16637 return Is_Variable (Expression (Orig_Node))
16639 (not Comes_From_Source (Orig_Node)
16641 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
16643 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
16645 -- GNAT allows an unchecked type conversion as a variable. This
16646 -- only affects the generation of internal expanded code, since
16647 -- calls to instantiations of Unchecked_Conversion are never
16648 -- considered variables (since they are function calls).
16650 when N_Unchecked_Type_Conversion =>
16651 return Is_Variable (Expression (Orig_Node));
16659 ------------------------------
16660 -- Is_Verifiable_DIC_Pragma --
16661 ------------------------------
16663 function Is_Verifiable_DIC_Pragma (Prag : Node_Id) return Boolean is
16664 Args : constant List_Id := Pragma_Argument_Associations (Prag);
16667 -- To qualify as verifiable, a DIC pragma must have a non-null argument
16671 and then Nkind (Get_Pragma_Arg (First (Args))) /= N_Null;
16672 end Is_Verifiable_DIC_Pragma;
16674 ---------------------------
16675 -- Is_Visibly_Controlled --
16676 ---------------------------
16678 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
16679 Root : constant Entity_Id := Root_Type (T);
16681 return Chars (Scope (Root)) = Name_Finalization
16682 and then Chars (Scope (Scope (Root))) = Name_Ada
16683 and then Scope (Scope (Scope (Root))) = Standard_Standard;
16684 end Is_Visibly_Controlled;
16686 --------------------------
16687 -- Is_Volatile_Function --
16688 --------------------------
16690 function Is_Volatile_Function (Func_Id : Entity_Id) return Boolean is
16692 pragma Assert (Ekind_In (Func_Id, E_Function, E_Generic_Function));
16694 -- A function declared within a protected type is volatile
16696 if Is_Protected_Type (Scope (Func_Id)) then
16699 -- An instance of Ada.Unchecked_Conversion is a volatile function if
16700 -- either the source or the target are effectively volatile.
16702 elsif Is_Unchecked_Conversion_Instance (Func_Id)
16703 and then Has_Effectively_Volatile_Profile (Func_Id)
16707 -- Otherwise the function is treated as volatile if it is subject to
16708 -- enabled pragma Volatile_Function.
16712 Is_Enabled_Pragma (Get_Pragma (Func_Id, Pragma_Volatile_Function));
16714 end Is_Volatile_Function;
16716 ------------------------
16717 -- Is_Volatile_Object --
16718 ------------------------
16720 function Is_Volatile_Object (N : Node_Id) return Boolean is
16721 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
16722 -- If prefix is an implicit dereference, examine designated type
16724 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
16725 -- Determines if given object has volatile components
16727 ------------------------
16728 -- Is_Volatile_Prefix --
16729 ------------------------
16731 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
16732 Typ : constant Entity_Id := Etype (N);
16735 if Is_Access_Type (Typ) then
16737 Dtyp : constant Entity_Id := Designated_Type (Typ);
16740 return Is_Volatile (Dtyp)
16741 or else Has_Volatile_Components (Dtyp);
16745 return Object_Has_Volatile_Components (N);
16747 end Is_Volatile_Prefix;
16749 ------------------------------------
16750 -- Object_Has_Volatile_Components --
16751 ------------------------------------
16753 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
16754 Typ : constant Entity_Id := Etype (N);
16757 if Is_Volatile (Typ)
16758 or else Has_Volatile_Components (Typ)
16762 elsif Is_Entity_Name (N)
16763 and then (Has_Volatile_Components (Entity (N))
16764 or else Is_Volatile (Entity (N)))
16768 elsif Nkind (N) = N_Indexed_Component
16769 or else Nkind (N) = N_Selected_Component
16771 return Is_Volatile_Prefix (Prefix (N));
16776 end Object_Has_Volatile_Components;
16778 -- Start of processing for Is_Volatile_Object
16781 if Nkind (N) = N_Defining_Identifier then
16782 return Is_Volatile (N) or else Is_Volatile (Etype (N));
16784 elsif Nkind (N) = N_Expanded_Name then
16785 return Is_Volatile_Object (Entity (N));
16787 elsif Is_Volatile (Etype (N))
16788 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
16792 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component)
16793 and then Is_Volatile_Prefix (Prefix (N))
16797 elsif Nkind (N) = N_Selected_Component
16798 and then Is_Volatile (Entity (Selector_Name (N)))
16805 end Is_Volatile_Object;
16807 -----------------------------
16808 -- Iterate_Call_Parameters --
16809 -----------------------------
16811 procedure Iterate_Call_Parameters (Call : Node_Id) is
16812 Formal : Entity_Id := First_Formal (Get_Called_Entity (Call));
16813 Actual : Node_Id := First_Actual (Call);
16816 while Present (Formal) and then Present (Actual) loop
16817 Handle_Parameter (Formal, Actual);
16818 Formal := Next_Formal (Formal);
16819 Actual := Next_Actual (Actual);
16821 end Iterate_Call_Parameters;
16823 ---------------------------
16824 -- Itype_Has_Declaration --
16825 ---------------------------
16827 function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
16829 pragma Assert (Is_Itype (Id));
16830 return Present (Parent (Id))
16831 and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
16832 N_Subtype_Declaration)
16833 and then Defining_Entity (Parent (Id)) = Id;
16834 end Itype_Has_Declaration;
16836 -------------------------
16837 -- Kill_Current_Values --
16838 -------------------------
16840 procedure Kill_Current_Values
16842 Last_Assignment_Only : Boolean := False)
16845 if Is_Assignable (Ent) then
16846 Set_Last_Assignment (Ent, Empty);
16849 if Is_Object (Ent) then
16850 if not Last_Assignment_Only then
16852 Set_Current_Value (Ent, Empty);
16854 -- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
16855 -- for a constant. Once the constant is elaborated, its value is
16856 -- not changed, therefore the associated flags that describe the
16857 -- value should not be modified either.
16859 if Ekind (Ent) = E_Constant then
16862 -- Non-constant entities
16865 if not Can_Never_Be_Null (Ent) then
16866 Set_Is_Known_Non_Null (Ent, False);
16869 Set_Is_Known_Null (Ent, False);
16871 -- Reset the Is_Known_Valid flag unless the type is always
16872 -- valid. This does not apply to a loop parameter because its
16873 -- bounds are defined by the loop header and therefore always
16876 if not Is_Known_Valid (Etype (Ent))
16877 and then Ekind (Ent) /= E_Loop_Parameter
16879 Set_Is_Known_Valid (Ent, False);
16884 end Kill_Current_Values;
16886 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
16889 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
16890 -- Clear current value for entity E and all entities chained to E
16892 ------------------------------------------
16893 -- Kill_Current_Values_For_Entity_Chain --
16894 ------------------------------------------
16896 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
16900 while Present (Ent) loop
16901 Kill_Current_Values (Ent, Last_Assignment_Only);
16904 end Kill_Current_Values_For_Entity_Chain;
16906 -- Start of processing for Kill_Current_Values
16909 -- Kill all saved checks, a special case of killing saved values
16911 if not Last_Assignment_Only then
16915 -- Loop through relevant scopes, which includes the current scope and
16916 -- any parent scopes if the current scope is a block or a package.
16918 S := Current_Scope;
16921 -- Clear current values of all entities in current scope
16923 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
16925 -- If scope is a package, also clear current values of all private
16926 -- entities in the scope.
16928 if Is_Package_Or_Generic_Package (S)
16929 or else Is_Concurrent_Type (S)
16931 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
16934 -- If this is a not a subprogram, deal with parents
16936 if not Is_Subprogram (S) then
16938 exit Scope_Loop when S = Standard_Standard;
16942 end loop Scope_Loop;
16943 end Kill_Current_Values;
16945 --------------------------
16946 -- Kill_Size_Check_Code --
16947 --------------------------
16949 procedure Kill_Size_Check_Code (E : Entity_Id) is
16951 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
16952 and then Present (Size_Check_Code (E))
16954 Remove (Size_Check_Code (E));
16955 Set_Size_Check_Code (E, Empty);
16957 end Kill_Size_Check_Code;
16959 --------------------
16960 -- Known_Non_Null --
16961 --------------------
16963 function Known_Non_Null (N : Node_Id) return Boolean is
16964 Status : constant Null_Status_Kind := Null_Status (N);
16971 -- The expression yields a non-null value ignoring simple flow analysis
16973 if Status = Is_Non_Null then
16976 -- Otherwise check whether N is a reference to an entity that appears
16977 -- within a conditional construct.
16979 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
16981 -- First check if we are in decisive conditional
16983 Get_Current_Value_Condition (N, Op, Val);
16985 if Known_Null (Val) then
16986 if Op = N_Op_Eq then
16988 elsif Op = N_Op_Ne then
16993 -- If OK to do replacement, test Is_Known_Non_Null flag
16997 if OK_To_Do_Constant_Replacement (Id) then
16998 return Is_Known_Non_Null (Id);
17002 -- Otherwise it is not possible to determine whether N yields a non-null
17006 end Known_Non_Null;
17012 function Known_Null (N : Node_Id) return Boolean is
17013 Status : constant Null_Status_Kind := Null_Status (N);
17020 -- The expression yields a null value ignoring simple flow analysis
17022 if Status = Is_Null then
17025 -- Otherwise check whether N is a reference to an entity that appears
17026 -- within a conditional construct.
17028 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
17030 -- First check if we are in decisive conditional
17032 Get_Current_Value_Condition (N, Op, Val);
17034 if Known_Null (Val) then
17035 if Op = N_Op_Eq then
17037 elsif Op = N_Op_Ne then
17042 -- If OK to do replacement, test Is_Known_Null flag
17046 if OK_To_Do_Constant_Replacement (Id) then
17047 return Is_Known_Null (Id);
17051 -- Otherwise it is not possible to determine whether N yields a null
17057 --------------------------
17058 -- Known_To_Be_Assigned --
17059 --------------------------
17061 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
17062 P : constant Node_Id := Parent (N);
17067 -- Test left side of assignment
17069 when N_Assignment_Statement =>
17070 return N = Name (P);
17072 -- Function call arguments are never lvalues
17074 when N_Function_Call =>
17077 -- Positional parameter for procedure or accept call
17079 when N_Accept_Statement
17080 | N_Procedure_Call_Statement
17088 Proc := Get_Subprogram_Entity (P);
17094 -- If we are not a list member, something is strange, so
17095 -- be conservative and return False.
17097 if not Is_List_Member (N) then
17101 -- We are going to find the right formal by stepping forward
17102 -- through the formals, as we step backwards in the actuals.
17104 Form := First_Formal (Proc);
17107 -- If no formal, something is weird, so be conservative
17108 -- and return False.
17115 exit when No (Act);
17116 Next_Formal (Form);
17119 return Ekind (Form) /= E_In_Parameter;
17122 -- Named parameter for procedure or accept call
17124 when N_Parameter_Association =>
17130 Proc := Get_Subprogram_Entity (Parent (P));
17136 -- Loop through formals to find the one that matches
17138 Form := First_Formal (Proc);
17140 -- If no matching formal, that's peculiar, some kind of
17141 -- previous error, so return False to be conservative.
17142 -- Actually this also happens in legal code in the case
17143 -- where P is a parameter association for an Extra_Formal???
17149 -- Else test for match
17151 if Chars (Form) = Chars (Selector_Name (P)) then
17152 return Ekind (Form) /= E_In_Parameter;
17155 Next_Formal (Form);
17159 -- Test for appearing in a conversion that itself appears
17160 -- in an lvalue context, since this should be an lvalue.
17162 when N_Type_Conversion =>
17163 return Known_To_Be_Assigned (P);
17165 -- All other references are definitely not known to be modifications
17170 end Known_To_Be_Assigned;
17172 ---------------------------
17173 -- Last_Source_Statement --
17174 ---------------------------
17176 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
17180 N := Last (Statements (HSS));
17181 while Present (N) loop
17182 exit when Comes_From_Source (N);
17187 end Last_Source_Statement;
17189 -----------------------
17190 -- Mark_Coextensions --
17191 -----------------------
17193 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
17194 Is_Dynamic : Boolean;
17195 -- Indicates whether the context causes nested coextensions to be
17196 -- dynamic or static
17198 function Mark_Allocator (N : Node_Id) return Traverse_Result;
17199 -- Recognize an allocator node and label it as a dynamic coextension
17201 --------------------
17202 -- Mark_Allocator --
17203 --------------------
17205 function Mark_Allocator (N : Node_Id) return Traverse_Result is
17207 if Nkind (N) = N_Allocator then
17209 Set_Is_Dynamic_Coextension (N);
17211 -- If the allocator expression is potentially dynamic, it may
17212 -- be expanded out of order and require dynamic allocation
17213 -- anyway, so we treat the coextension itself as dynamic.
17214 -- Potential optimization ???
17216 elsif Nkind (Expression (N)) = N_Qualified_Expression
17217 and then Nkind (Expression (Expression (N))) = N_Op_Concat
17219 Set_Is_Dynamic_Coextension (N);
17221 Set_Is_Static_Coextension (N);
17226 end Mark_Allocator;
17228 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
17230 -- Start of processing for Mark_Coextensions
17233 -- An allocator that appears on the right-hand side of an assignment is
17234 -- treated as a potentially dynamic coextension when the right-hand side
17235 -- is an allocator or a qualified expression.
17237 -- Obj := new ...'(new Coextension ...);
17239 if Nkind (Context_Nod) = N_Assignment_Statement then
17241 Nkind_In (Expression (Context_Nod), N_Allocator,
17242 N_Qualified_Expression);
17244 -- An allocator that appears within the expression of a simple return
17245 -- statement is treated as a potentially dynamic coextension when the
17246 -- expression is either aggregate, allocator, or qualified expression.
17248 -- return (new Coextension ...);
17249 -- return new ...'(new Coextension ...);
17251 elsif Nkind (Context_Nod) = N_Simple_Return_Statement then
17253 Nkind_In (Expression (Context_Nod), N_Aggregate,
17255 N_Qualified_Expression);
17257 -- An alloctor that appears within the initialization expression of an
17258 -- object declaration is considered a potentially dynamic coextension
17259 -- when the initialization expression is an allocator or a qualified
17262 -- Obj : ... := new ...'(new Coextension ...);
17264 -- A similar case arises when the object declaration is part of an
17265 -- extended return statement.
17267 -- return Obj : ... := new ...'(new Coextension ...);
17268 -- return Obj : ... := (new Coextension ...);
17270 elsif Nkind (Context_Nod) = N_Object_Declaration then
17272 Nkind_In (Root_Nod, N_Allocator, N_Qualified_Expression)
17274 Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
17276 -- This routine should not be called with constructs that cannot contain
17280 raise Program_Error;
17283 Mark_Allocators (Root_Nod);
17284 end Mark_Coextensions;
17286 ---------------------------------
17287 -- Mark_Elaboration_Attributes --
17288 ---------------------------------
17290 procedure Mark_Elaboration_Attributes
17291 (N_Id : Node_Or_Entity_Id;
17292 Checks : Boolean := False;
17293 Level : Boolean := False;
17294 Modes : Boolean := False)
17296 function Elaboration_Checks_OK
17297 (Target_Id : Entity_Id;
17298 Context_Id : Entity_Id) return Boolean;
17299 -- Determine whether elaboration checks are enabled for target Target_Id
17300 -- which resides within context Context_Id.
17302 procedure Mark_Elaboration_Attributes_Id (Id : Entity_Id);
17303 -- Preserve relevant attributes of the context in arbitrary entity Id
17305 procedure Mark_Elaboration_Attributes_Node (N : Node_Id);
17306 -- Preserve relevant attributes of the context in arbitrary node N
17308 ---------------------------
17309 -- Elaboration_Checks_OK --
17310 ---------------------------
17312 function Elaboration_Checks_OK
17313 (Target_Id : Entity_Id;
17314 Context_Id : Entity_Id) return Boolean
17316 Encl_Scop : Entity_Id;
17319 -- Elaboration checks are suppressed for the target
17321 if Elaboration_Checks_Suppressed (Target_Id) then
17325 -- Otherwise elaboration checks are OK for the target, but may be
17326 -- suppressed for the context where the target is declared.
17328 Encl_Scop := Context_Id;
17329 while Present (Encl_Scop) and then Encl_Scop /= Standard_Standard loop
17330 if Elaboration_Checks_Suppressed (Encl_Scop) then
17334 Encl_Scop := Scope (Encl_Scop);
17337 -- Neither the target nor its declarative context have elaboration
17338 -- checks suppressed.
17341 end Elaboration_Checks_OK;
17343 ------------------------------------
17344 -- Mark_Elaboration_Attributes_Id --
17345 ------------------------------------
17347 procedure Mark_Elaboration_Attributes_Id (Id : Entity_Id) is
17349 -- Mark the status of elaboration checks in effect. Do not reset the
17350 -- status in case the entity is reanalyzed with checks suppressed.
17352 if Checks and then not Is_Elaboration_Checks_OK_Id (Id) then
17353 Set_Is_Elaboration_Checks_OK_Id (Id,
17354 Elaboration_Checks_OK
17356 Context_Id => Scope (Id)));
17358 -- Entities do not need to capture their enclosing level. The Ghost
17359 -- and SPARK modes in effect are already marked during analysis.
17364 end Mark_Elaboration_Attributes_Id;
17366 --------------------------------------
17367 -- Mark_Elaboration_Attributes_Node --
17368 --------------------------------------
17370 procedure Mark_Elaboration_Attributes_Node (N : Node_Id) is
17371 function Extract_Name (N : Node_Id) return Node_Id;
17372 -- Obtain the Name attribute of call or instantiation N
17378 function Extract_Name (N : Node_Id) return Node_Id is
17384 -- A call to an entry family appears in indexed form
17386 if Nkind (Nam) = N_Indexed_Component then
17387 Nam := Prefix (Nam);
17390 -- The name may also appear in qualified form
17392 if Nkind (Nam) = N_Selected_Component then
17393 Nam := Selector_Name (Nam);
17401 Context_Id : Entity_Id;
17404 -- Start of processing for Mark_Elaboration_Attributes_Node
17407 -- Mark the status of elaboration checks in effect. Do not reset the
17408 -- status in case the node is reanalyzed with checks suppressed.
17410 if Checks and then not Is_Elaboration_Checks_OK_Node (N) then
17412 -- Assignments, attribute references, and variable references do
17413 -- not have a "declarative" context.
17415 Context_Id := Empty;
17417 -- The status of elaboration checks for calls and instantiations
17418 -- depends on the most recent pragma Suppress/Unsuppress, as well
17419 -- as the suppression status of the context where the target is
17423 -- function Func ...;
17427 -- procedure Main is
17428 -- pragma Suppress (Elaboration_Checks, Pack);
17429 -- X : ... := Pack.Func;
17432 -- In the example above, the call to Func has elaboration checks
17433 -- enabled because there is no active general purpose suppression
17434 -- pragma, however the elaboration checks of Pack are explicitly
17435 -- suppressed. As a result the elaboration checks of the call must
17436 -- be disabled in order to preserve this dependency.
17438 if Nkind_In (N, N_Entry_Call_Statement,
17440 N_Function_Instantiation,
17441 N_Package_Instantiation,
17442 N_Procedure_Call_Statement,
17443 N_Procedure_Instantiation)
17445 Nam := Extract_Name (N);
17447 if Is_Entity_Name (Nam) and then Present (Entity (Nam)) then
17448 Context_Id := Scope (Entity (Nam));
17452 Set_Is_Elaboration_Checks_OK_Node (N,
17453 Elaboration_Checks_OK
17454 (Target_Id => Empty,
17455 Context_Id => Context_Id));
17458 -- Mark the enclosing level of the node. Do not reset the status in
17459 -- case the node is relocated and reanalyzed.
17461 if Level and then not Is_Declaration_Level_Node (N) then
17462 Set_Is_Declaration_Level_Node (N,
17463 Find_Enclosing_Level (N) = Declaration_Level);
17466 -- Mark the Ghost and SPARK mode in effect
17469 if Ghost_Mode = Ignore then
17470 Set_Is_Ignored_Ghost_Node (N);
17473 if SPARK_Mode = On then
17474 Set_Is_SPARK_Mode_On_Node (N);
17477 end Mark_Elaboration_Attributes_Node;
17479 -- Start of processing for Mark_Elaboration_Attributes
17482 if Nkind (N_Id) in N_Entity then
17483 Mark_Elaboration_Attributes_Id (N_Id);
17485 Mark_Elaboration_Attributes_Node (N_Id);
17487 end Mark_Elaboration_Attributes;
17489 ----------------------------------
17490 -- Matching_Static_Array_Bounds --
17491 ----------------------------------
17493 function Matching_Static_Array_Bounds
17495 R_Typ : Node_Id) return Boolean
17497 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
17498 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
17510 if L_Ndims /= R_Ndims then
17514 -- Unconstrained types do not have static bounds
17516 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
17520 -- First treat specially the first dimension, as the lower bound and
17521 -- length of string literals are not stored like those of arrays.
17523 if Ekind (L_Typ) = E_String_Literal_Subtype then
17524 L_Low := String_Literal_Low_Bound (L_Typ);
17525 L_Len := String_Literal_Length (L_Typ);
17527 L_Index := First_Index (L_Typ);
17528 Get_Index_Bounds (L_Index, L_Low, L_High);
17530 if Is_OK_Static_Expression (L_Low)
17532 Is_OK_Static_Expression (L_High)
17534 if Expr_Value (L_High) < Expr_Value (L_Low) then
17537 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
17544 if Ekind (R_Typ) = E_String_Literal_Subtype then
17545 R_Low := String_Literal_Low_Bound (R_Typ);
17546 R_Len := String_Literal_Length (R_Typ);
17548 R_Index := First_Index (R_Typ);
17549 Get_Index_Bounds (R_Index, R_Low, R_High);
17551 if Is_OK_Static_Expression (R_Low)
17553 Is_OK_Static_Expression (R_High)
17555 if Expr_Value (R_High) < Expr_Value (R_Low) then
17558 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
17565 if (Is_OK_Static_Expression (L_Low)
17567 Is_OK_Static_Expression (R_Low))
17568 and then Expr_Value (L_Low) = Expr_Value (R_Low)
17569 and then L_Len = R_Len
17576 -- Then treat all other dimensions
17578 for Indx in 2 .. L_Ndims loop
17582 Get_Index_Bounds (L_Index, L_Low, L_High);
17583 Get_Index_Bounds (R_Index, R_Low, R_High);
17585 if (Is_OK_Static_Expression (L_Low) and then
17586 Is_OK_Static_Expression (L_High) and then
17587 Is_OK_Static_Expression (R_Low) and then
17588 Is_OK_Static_Expression (R_High))
17589 and then (Expr_Value (L_Low) = Expr_Value (R_Low)
17591 Expr_Value (L_High) = Expr_Value (R_High))
17599 -- If we fall through the loop, all indexes matched
17602 end Matching_Static_Array_Bounds;
17604 -------------------
17605 -- May_Be_Lvalue --
17606 -------------------
17608 function May_Be_Lvalue (N : Node_Id) return Boolean is
17609 P : constant Node_Id := Parent (N);
17614 -- Test left side of assignment
17616 when N_Assignment_Statement =>
17617 return N = Name (P);
17619 -- Test prefix of component or attribute. Note that the prefix of an
17620 -- explicit or implicit dereference cannot be an l-value. In the case
17621 -- of a 'Read attribute, the reference can be an actual in the
17622 -- argument list of the attribute.
17624 when N_Attribute_Reference =>
17625 return (N = Prefix (P)
17626 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P)))
17628 Attribute_Name (P) = Name_Read;
17630 -- For an expanded name, the name is an lvalue if the expanded name
17631 -- is an lvalue, but the prefix is never an lvalue, since it is just
17632 -- the scope where the name is found.
17634 when N_Expanded_Name =>
17635 if N = Prefix (P) then
17636 return May_Be_Lvalue (P);
17641 -- For a selected component A.B, A is certainly an lvalue if A.B is.
17642 -- B is a little interesting, if we have A.B := 3, there is some
17643 -- discussion as to whether B is an lvalue or not, we choose to say
17644 -- it is. Note however that A is not an lvalue if it is of an access
17645 -- type since this is an implicit dereference.
17647 when N_Selected_Component =>
17649 and then Present (Etype (N))
17650 and then Is_Access_Type (Etype (N))
17654 return May_Be_Lvalue (P);
17657 -- For an indexed component or slice, the index or slice bounds is
17658 -- never an lvalue. The prefix is an lvalue if the indexed component
17659 -- or slice is an lvalue, except if it is an access type, where we
17660 -- have an implicit dereference.
17662 when N_Indexed_Component
17666 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
17670 return May_Be_Lvalue (P);
17673 -- Prefix of a reference is an lvalue if the reference is an lvalue
17675 when N_Reference =>
17676 return May_Be_Lvalue (P);
17678 -- Prefix of explicit dereference is never an lvalue
17680 when N_Explicit_Dereference =>
17683 -- Positional parameter for subprogram, entry, or accept call.
17684 -- In older versions of Ada function call arguments are never
17685 -- lvalues. In Ada 2012 functions can have in-out parameters.
17687 when N_Accept_Statement
17688 | N_Entry_Call_Statement
17689 | N_Subprogram_Call
17691 if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
17695 -- The following mechanism is clumsy and fragile. A single flag
17696 -- set in Resolve_Actuals would be preferable ???
17704 Proc := Get_Subprogram_Entity (P);
17710 -- If we are not a list member, something is strange, so be
17711 -- conservative and return True.
17713 if not Is_List_Member (N) then
17717 -- We are going to find the right formal by stepping forward
17718 -- through the formals, as we step backwards in the actuals.
17720 Form := First_Formal (Proc);
17723 -- If no formal, something is weird, so be conservative and
17731 exit when No (Act);
17732 Next_Formal (Form);
17735 return Ekind (Form) /= E_In_Parameter;
17738 -- Named parameter for procedure or accept call
17740 when N_Parameter_Association =>
17746 Proc := Get_Subprogram_Entity (Parent (P));
17752 -- Loop through formals to find the one that matches
17754 Form := First_Formal (Proc);
17756 -- If no matching formal, that's peculiar, some kind of
17757 -- previous error, so return True to be conservative.
17758 -- Actually happens with legal code for an unresolved call
17759 -- where we may get the wrong homonym???
17765 -- Else test for match
17767 if Chars (Form) = Chars (Selector_Name (P)) then
17768 return Ekind (Form) /= E_In_Parameter;
17771 Next_Formal (Form);
17775 -- Test for appearing in a conversion that itself appears in an
17776 -- lvalue context, since this should be an lvalue.
17778 when N_Type_Conversion =>
17779 return May_Be_Lvalue (P);
17781 -- Test for appearance in object renaming declaration
17783 when N_Object_Renaming_Declaration =>
17786 -- All other references are definitely not lvalues
17797 function Might_Raise (N : Node_Id) return Boolean is
17798 Result : Boolean := False;
17800 function Process (N : Node_Id) return Traverse_Result;
17801 -- Set Result to True if we find something that could raise an exception
17807 function Process (N : Node_Id) return Traverse_Result is
17809 if Nkind_In (N, N_Procedure_Call_Statement,
17812 N_Raise_Constraint_Error,
17813 N_Raise_Program_Error,
17814 N_Raise_Storage_Error)
17823 procedure Set_Result is new Traverse_Proc (Process);
17825 -- Start of processing for Might_Raise
17828 -- False if exceptions can't be propagated
17830 if No_Exception_Handlers_Set then
17834 -- If the checks handled by the back end are not disabled, we cannot
17835 -- ensure that no exception will be raised.
17837 if not Access_Checks_Suppressed (Empty)
17838 or else not Discriminant_Checks_Suppressed (Empty)
17839 or else not Range_Checks_Suppressed (Empty)
17840 or else not Index_Checks_Suppressed (Empty)
17841 or else Opt.Stack_Checking_Enabled
17850 --------------------------------
17851 -- Nearest_Enclosing_Instance --
17852 --------------------------------
17854 function Nearest_Enclosing_Instance (E : Entity_Id) return Entity_Id is
17859 while Present (Inst) and then Inst /= Standard_Standard loop
17860 if Is_Generic_Instance (Inst) then
17864 Inst := Scope (Inst);
17868 end Nearest_Enclosing_Instance;
17870 ----------------------
17871 -- Needs_One_Actual --
17872 ----------------------
17874 function Needs_One_Actual (E : Entity_Id) return Boolean is
17875 Formal : Entity_Id;
17878 -- Ada 2005 or later, and formals present. The first formal must be
17879 -- of a type that supports prefix notation: a controlling argument,
17880 -- a class-wide type, or an access to such.
17882 if Ada_Version >= Ada_2005
17883 and then Present (First_Formal (E))
17884 and then No (Default_Value (First_Formal (E)))
17886 (Is_Controlling_Formal (First_Formal (E))
17887 or else Is_Class_Wide_Type (Etype (First_Formal (E)))
17888 or else Is_Anonymous_Access_Type (Etype (First_Formal (E))))
17890 Formal := Next_Formal (First_Formal (E));
17891 while Present (Formal) loop
17892 if No (Default_Value (Formal)) then
17896 Next_Formal (Formal);
17901 -- Ada 83/95 or no formals
17906 end Needs_One_Actual;
17908 ------------------------
17909 -- New_Copy_List_Tree --
17910 ------------------------
17912 function New_Copy_List_Tree (List : List_Id) return List_Id is
17917 if List = No_List then
17924 while Present (E) loop
17925 Append (New_Copy_Tree (E), NL);
17931 end New_Copy_List_Tree;
17933 -------------------
17934 -- New_Copy_Tree --
17935 -------------------
17937 -- The following tables play a key role in replicating entities and Itypes.
17938 -- They are intentionally declared at the library level rather than within
17939 -- New_Copy_Tree to avoid elaborating them on each call. This performance
17940 -- optimization saves up to 2% of the entire compilation time spent in the
17941 -- front end. Care should be taken to reset the tables on each new call to
17944 NCT_Table_Max : constant := 511;
17946 subtype NCT_Table_Index is Nat range 0 .. NCT_Table_Max - 1;
17948 function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index;
17949 -- Obtain the hash value of node or entity Key
17951 --------------------
17952 -- NCT_Table_Hash --
17953 --------------------
17955 function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index is
17957 return NCT_Table_Index (Key mod NCT_Table_Max);
17958 end NCT_Table_Hash;
17960 ----------------------
17961 -- NCT_New_Entities --
17962 ----------------------
17964 -- The following table maps old entities and Itypes to their corresponding
17965 -- new entities and Itypes.
17969 package NCT_New_Entities is new Simple_HTable (
17970 Header_Num => NCT_Table_Index,
17971 Element => Entity_Id,
17972 No_Element => Empty,
17974 Hash => NCT_Table_Hash,
17977 ------------------------
17978 -- NCT_Pending_Itypes --
17979 ------------------------
17981 -- The following table maps old Associated_Node_For_Itype nodes to a set of
17982 -- new itypes. Given a set of old Itypes Aaa, Bbb, and Ccc, where all three
17983 -- have the same Associated_Node_For_Itype Ppp, and their corresponding new
17984 -- Itypes Xxx, Yyy, Zzz, the table contains the following mapping:
17986 -- Ppp -> (Xxx, Yyy, Zzz)
17988 -- The set is expressed as an Elist
17990 package NCT_Pending_Itypes is new Simple_HTable (
17991 Header_Num => NCT_Table_Index,
17992 Element => Elist_Id,
17993 No_Element => No_Elist,
17995 Hash => NCT_Table_Hash,
17998 NCT_Tables_In_Use : Boolean := False;
17999 -- This flag keeps track of whether the two tables NCT_New_Entities and
18000 -- NCT_Pending_Itypes are in use. The flag is part of an optimization
18001 -- where certain operations are not performed if the tables are not in
18002 -- use. This saves up to 8% of the entire compilation time spent in the
18005 -------------------
18006 -- New_Copy_Tree --
18007 -------------------
18009 function New_Copy_Tree
18011 Map : Elist_Id := No_Elist;
18012 New_Sloc : Source_Ptr := No_Location;
18013 New_Scope : Entity_Id := Empty) return Node_Id
18015 -- This routine performs low-level tree manipulations and needs access
18016 -- to the internals of the tree.
18018 use Atree.Unchecked_Access;
18019 use Atree_Private_Part;
18021 EWA_Level : Nat := 0;
18022 -- This counter keeps track of how many N_Expression_With_Actions nodes
18023 -- are encountered during a depth-first traversal of the subtree. These
18024 -- nodes may define new entities in their Actions lists and thus require
18025 -- special processing.
18027 EWA_Inner_Scope_Level : Nat := 0;
18028 -- This counter keeps track of how many scoping constructs appear within
18029 -- an N_Expression_With_Actions node.
18031 procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id);
18032 pragma Inline (Add_New_Entity);
18033 -- Add an entry in the NCT_New_Entities table which maps key Old_Id to
18034 -- value New_Id. Old_Id is an entity which appears within the Actions
18035 -- list of an N_Expression_With_Actions node, or within an entity map.
18036 -- New_Id is the corresponding new entity generated during Phase 1.
18038 procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id);
18039 pragma Inline (Add_New_Entity);
18040 -- Add an entry in the NCT_Pending_Itypes which maps key Assoc_Nod to
18041 -- value Itype. Assoc_Nod is the associated node of an itype. Itype is
18044 procedure Build_NCT_Tables (Entity_Map : Elist_Id);
18045 pragma Inline (Build_NCT_Tables);
18046 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with the
18047 -- information supplied in entity map Entity_Map. The format of the
18048 -- entity map must be as follows:
18050 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
18052 function Copy_Any_Node_With_Replacement
18053 (N : Node_Or_Entity_Id) return Node_Or_Entity_Id;
18054 pragma Inline (Copy_Any_Node_With_Replacement);
18055 -- Replicate entity or node N by invoking one of the following routines:
18057 -- Copy_Node_With_Replacement
18058 -- Corresponding_Entity
18060 function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id;
18061 -- Replicate the elements of entity list List
18063 function Copy_Field_With_Replacement
18065 Old_Par : Node_Id := Empty;
18066 New_Par : Node_Id := Empty;
18067 Semantic : Boolean := False) return Union_Id;
18068 -- Replicate field Field by invoking one of the following routines:
18070 -- Copy_Elist_With_Replacement
18071 -- Copy_List_With_Replacement
18072 -- Copy_Node_With_Replacement
18073 -- Corresponding_Entity
18075 -- If the field is not an entity list, entity, itype, syntactic list,
18076 -- or node, then the field is returned unchanged. The routine always
18077 -- replicates entities, itypes, and valid syntactic fields. Old_Par is
18078 -- the expected parent of a syntactic field. New_Par is the new parent
18079 -- associated with a replicated syntactic field. Flag Semantic should
18080 -- be set when the input is a semantic field.
18082 function Copy_List_With_Replacement (List : List_Id) return List_Id;
18083 -- Replicate the elements of syntactic list List
18085 function Copy_Node_With_Replacement (N : Node_Id) return Node_Id;
18086 -- Replicate node N
18088 function Corresponding_Entity (Id : Entity_Id) return Entity_Id;
18089 pragma Inline (Corresponding_Entity);
18090 -- Return the corresponding new entity of Id generated during Phase 1.
18091 -- If there is no such entity, return Id.
18093 function In_Entity_Map
18095 Entity_Map : Elist_Id) return Boolean;
18096 pragma Inline (In_Entity_Map);
18097 -- Determine whether entity Id is one of the old ids specified in entity
18098 -- map Entity_Map. The format of the entity map must be as follows:
18100 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
18102 procedure Update_CFS_Sloc (N : Node_Or_Entity_Id);
18103 pragma Inline (Update_CFS_Sloc);
18104 -- Update the Comes_From_Source and Sloc attributes of node or entity N
18106 procedure Update_First_Real_Statement
18107 (Old_HSS : Node_Id;
18108 New_HSS : Node_Id);
18109 pragma Inline (Update_First_Real_Statement);
18110 -- Update semantic attribute First_Real_Statement of handled sequence of
18111 -- statements New_HSS based on handled sequence of statements Old_HSS.
18113 procedure Update_Named_Associations
18114 (Old_Call : Node_Id;
18115 New_Call : Node_Id);
18116 pragma Inline (Update_Named_Associations);
18117 -- Update semantic chain First/Next_Named_Association of call New_call
18118 -- based on call Old_Call.
18120 procedure Update_New_Entities (Entity_Map : Elist_Id);
18121 pragma Inline (Update_New_Entities);
18122 -- Update the semantic attributes of all new entities generated during
18123 -- Phase 1 that do not appear in entity map Entity_Map. The format of
18124 -- the entity map must be as follows:
18126 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
18128 procedure Update_Pending_Itypes
18129 (Old_Assoc : Node_Id;
18130 New_Assoc : Node_Id);
18131 pragma Inline (Update_Pending_Itypes);
18132 -- Update semantic attribute Associated_Node_For_Itype to refer to node
18133 -- New_Assoc for all itypes whose associated node is Old_Assoc.
18135 procedure Update_Semantic_Fields (Id : Entity_Id);
18136 pragma Inline (Update_Semantic_Fields);
18137 -- Subsidiary to Update_New_Entities. Update semantic fields of entity
18140 procedure Visit_Any_Node (N : Node_Or_Entity_Id);
18141 pragma Inline (Visit_Any_Node);
18142 -- Visit entity of node N by invoking one of the following routines:
18148 procedure Visit_Elist (List : Elist_Id);
18149 -- Visit the elements of entity list List
18151 procedure Visit_Entity (Id : Entity_Id);
18152 -- Visit entity Id. This action may create a new entity of Id and save
18153 -- it in table NCT_New_Entities.
18155 procedure Visit_Field
18157 Par_Nod : Node_Id := Empty;
18158 Semantic : Boolean := False);
18159 -- Visit field Field by invoking one of the following routines:
18167 -- If the field is not an entity list, entity, itype, syntactic list,
18168 -- or node, then the field is not visited. The routine always visits
18169 -- valid syntactic fields. Par_Nod is the expected parent of the
18170 -- syntactic field. Flag Semantic should be set when the input is a
18173 procedure Visit_Itype (Itype : Entity_Id);
18174 -- Visit itype Itype. This action may create a new entity for Itype and
18175 -- save it in table NCT_New_Entities. In addition, the routine may map
18176 -- the associated node of Itype to the new itype in NCT_Pending_Itypes.
18178 procedure Visit_List (List : List_Id);
18179 -- Visit the elements of syntactic list List
18181 procedure Visit_Node (N : Node_Id);
18184 procedure Visit_Semantic_Fields (Id : Entity_Id);
18185 pragma Inline (Visit_Semantic_Fields);
18186 -- Subsidiary to Visit_Entity and Visit_Itype. Visit common semantic
18187 -- fields of entity or itype Id.
18189 --------------------
18190 -- Add_New_Entity --
18191 --------------------
18193 procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id) is
18195 pragma Assert (Present (Old_Id));
18196 pragma Assert (Present (New_Id));
18197 pragma Assert (Nkind (Old_Id) in N_Entity);
18198 pragma Assert (Nkind (New_Id) in N_Entity);
18200 NCT_Tables_In_Use := True;
18202 -- Sanity check the NCT_New_Entities table. No previous mapping with
18203 -- key Old_Id should exist.
18205 pragma Assert (No (NCT_New_Entities.Get (Old_Id)));
18207 -- Establish the mapping
18209 -- Old_Id -> New_Id
18211 NCT_New_Entities.Set (Old_Id, New_Id);
18212 end Add_New_Entity;
18214 -----------------------
18215 -- Add_Pending_Itype --
18216 -----------------------
18218 procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id) is
18222 pragma Assert (Present (Assoc_Nod));
18223 pragma Assert (Present (Itype));
18224 pragma Assert (Nkind (Itype) in N_Entity);
18225 pragma Assert (Is_Itype (Itype));
18227 NCT_Tables_In_Use := True;
18229 -- It is not possible to sanity check the NCT_Pendint_Itypes table
18230 -- directly because a single node may act as the associated node for
18231 -- multiple itypes.
18233 Itypes := NCT_Pending_Itypes.Get (Assoc_Nod);
18235 if No (Itypes) then
18236 Itypes := New_Elmt_List;
18237 NCT_Pending_Itypes.Set (Assoc_Nod, Itypes);
18240 -- Establish the mapping
18242 -- Assoc_Nod -> (Itype, ...)
18244 -- Avoid inserting the same itype multiple times. This involves a
18245 -- linear search, however the set of itypes with the same associated
18246 -- node is very small.
18248 Append_Unique_Elmt (Itype, Itypes);
18249 end Add_Pending_Itype;
18251 ----------------------
18252 -- Build_NCT_Tables --
18253 ----------------------
18255 procedure Build_NCT_Tables (Entity_Map : Elist_Id) is
18257 Old_Id : Entity_Id;
18258 New_Id : Entity_Id;
18261 -- Nothing to do when there is no entity map
18263 if No (Entity_Map) then
18267 Elmt := First_Elmt (Entity_Map);
18268 while Present (Elmt) loop
18270 -- Extract the (Old_Id, New_Id) pair from the entity map
18272 Old_Id := Node (Elmt);
18275 New_Id := Node (Elmt);
18278 -- Establish the following mapping within table NCT_New_Entities
18280 -- Old_Id -> New_Id
18282 Add_New_Entity (Old_Id, New_Id);
18284 -- Establish the following mapping within table NCT_Pending_Itypes
18285 -- when the new entity is an itype.
18287 -- Assoc_Nod -> (New_Id, ...)
18289 -- IMPORTANT: the associated node is that of the old itype because
18290 -- the node will be replicated in Phase 2.
18292 if Is_Itype (Old_Id) then
18294 (Assoc_Nod => Associated_Node_For_Itype (Old_Id),
18298 end Build_NCT_Tables;
18300 ------------------------------------
18301 -- Copy_Any_Node_With_Replacement --
18302 ------------------------------------
18304 function Copy_Any_Node_With_Replacement
18305 (N : Node_Or_Entity_Id) return Node_Or_Entity_Id
18308 if Nkind (N) in N_Entity then
18309 return Corresponding_Entity (N);
18311 return Copy_Node_With_Replacement (N);
18313 end Copy_Any_Node_With_Replacement;
18315 ---------------------------------
18316 -- Copy_Elist_With_Replacement --
18317 ---------------------------------
18319 function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id is
18324 -- Copy the contents of the old list. Note that the list itself may
18325 -- be empty, in which case the routine returns a new empty list. This
18326 -- avoids sharing lists between subtrees. The element of an entity
18327 -- list could be an entity or a node, hence the invocation of routine
18328 -- Copy_Any_Node_With_Replacement.
18330 if Present (List) then
18331 Result := New_Elmt_List;
18333 Elmt := First_Elmt (List);
18334 while Present (Elmt) loop
18336 (Copy_Any_Node_With_Replacement (Node (Elmt)), Result);
18341 -- Otherwise the list does not exist
18344 Result := No_Elist;
18348 end Copy_Elist_With_Replacement;
18350 ---------------------------------
18351 -- Copy_Field_With_Replacement --
18352 ---------------------------------
18354 function Copy_Field_With_Replacement
18356 Old_Par : Node_Id := Empty;
18357 New_Par : Node_Id := Empty;
18358 Semantic : Boolean := False) return Union_Id
18361 -- The field is empty
18363 if Field = Union_Id (Empty) then
18366 -- The field is an entity/itype/node
18368 elsif Field in Node_Range then
18370 Old_N : constant Node_Id := Node_Id (Field);
18371 Syntactic : constant Boolean := Parent (Old_N) = Old_Par;
18376 -- The field is an entity/itype
18378 if Nkind (Old_N) in N_Entity then
18380 -- An entity/itype is always replicated
18382 New_N := Corresponding_Entity (Old_N);
18384 -- Update the parent pointer when the entity is a syntactic
18385 -- field. Note that itypes do not have parent pointers.
18387 if Syntactic and then New_N /= Old_N then
18388 Set_Parent (New_N, New_Par);
18391 -- The field is a node
18394 -- A node is replicated when it is either a syntactic field
18395 -- or when the caller treats it as a semantic attribute.
18397 if Syntactic or else Semantic then
18398 New_N := Copy_Node_With_Replacement (Old_N);
18400 -- Update the parent pointer when the node is a syntactic
18403 if Syntactic and then New_N /= Old_N then
18404 Set_Parent (New_N, New_Par);
18407 -- Otherwise the node is returned unchanged
18414 return Union_Id (New_N);
18417 -- The field is an entity list
18419 elsif Field in Elist_Range then
18420 return Union_Id (Copy_Elist_With_Replacement (Elist_Id (Field)));
18422 -- The field is a syntactic list
18424 elsif Field in List_Range then
18426 Old_List : constant List_Id := List_Id (Field);
18427 Syntactic : constant Boolean := Parent (Old_List) = Old_Par;
18429 New_List : List_Id;
18432 -- A list is replicated when it is either a syntactic field or
18433 -- when the caller treats it as a semantic attribute.
18435 if Syntactic or else Semantic then
18436 New_List := Copy_List_With_Replacement (Old_List);
18438 -- Update the parent pointer when the list is a syntactic
18441 if Syntactic and then New_List /= Old_List then
18442 Set_Parent (New_List, New_Par);
18445 -- Otherwise the list is returned unchanged
18448 New_List := Old_List;
18451 return Union_Id (New_List);
18454 -- Otherwise the field denotes an attribute that does not need to be
18455 -- replicated (Chars, literals, etc).
18460 end Copy_Field_With_Replacement;
18462 --------------------------------
18463 -- Copy_List_With_Replacement --
18464 --------------------------------
18466 function Copy_List_With_Replacement (List : List_Id) return List_Id is
18471 -- Copy the contents of the old list. Note that the list itself may
18472 -- be empty, in which case the routine returns a new empty list. This
18473 -- avoids sharing lists between subtrees. The element of a syntactic
18474 -- list is always a node, never an entity or itype, hence the call to
18475 -- routine Copy_Node_With_Replacement.
18477 if Present (List) then
18478 Result := New_List;
18480 Elmt := First (List);
18481 while Present (Elmt) loop
18482 Append (Copy_Node_With_Replacement (Elmt), Result);
18487 -- Otherwise the list does not exist
18494 end Copy_List_With_Replacement;
18496 --------------------------------
18497 -- Copy_Node_With_Replacement --
18498 --------------------------------
18500 function Copy_Node_With_Replacement (N : Node_Id) return Node_Id is
18504 -- Assume that the node must be returned unchanged
18508 if N > Empty_Or_Error then
18509 pragma Assert (Nkind (N) not in N_Entity);
18511 Result := New_Copy (N);
18513 Set_Field1 (Result,
18514 Copy_Field_With_Replacement
18515 (Field => Field1 (Result),
18517 New_Par => Result));
18519 Set_Field2 (Result,
18520 Copy_Field_With_Replacement
18521 (Field => Field2 (Result),
18523 New_Par => Result));
18525 Set_Field3 (Result,
18526 Copy_Field_With_Replacement
18527 (Field => Field3 (Result),
18529 New_Par => Result));
18531 Set_Field4 (Result,
18532 Copy_Field_With_Replacement
18533 (Field => Field4 (Result),
18535 New_Par => Result));
18537 Set_Field5 (Result,
18538 Copy_Field_With_Replacement
18539 (Field => Field5 (Result),
18541 New_Par => Result));
18543 -- Update the Comes_From_Source and Sloc attributes of the node
18544 -- in case the caller has supplied new values.
18546 Update_CFS_Sloc (Result);
18548 -- Update the Associated_Node_For_Itype attribute of all itypes
18549 -- created during Phase 1 whose associated node is N. As a result
18550 -- the Associated_Node_For_Itype refers to the replicated node.
18551 -- No action needs to be taken when the Associated_Node_For_Itype
18552 -- refers to an entity because this was already handled during
18553 -- Phase 1, in Visit_Itype.
18555 Update_Pending_Itypes
18557 New_Assoc => Result);
18559 -- Update the First/Next_Named_Association chain for a replicated
18562 if Nkind_In (N, N_Entry_Call_Statement,
18564 N_Procedure_Call_Statement)
18566 Update_Named_Associations
18568 New_Call => Result);
18570 -- Update the Renamed_Object attribute of a replicated object
18573 elsif Nkind (N) = N_Object_Renaming_Declaration then
18574 Set_Renamed_Object (Defining_Entity (Result), Name (Result));
18576 -- Update the First_Real_Statement attribute of a replicated
18577 -- handled sequence of statements.
18579 elsif Nkind (N) = N_Handled_Sequence_Of_Statements then
18580 Update_First_Real_Statement
18582 New_HSS => Result);
18587 end Copy_Node_With_Replacement;
18589 --------------------------
18590 -- Corresponding_Entity --
18591 --------------------------
18593 function Corresponding_Entity (Id : Entity_Id) return Entity_Id is
18594 New_Id : Entity_Id;
18595 Result : Entity_Id;
18598 -- Assume that the entity must be returned unchanged
18602 if Id > Empty_Or_Error then
18603 pragma Assert (Nkind (Id) in N_Entity);
18605 -- Determine whether the entity has a corresponding new entity
18606 -- generated during Phase 1 and if it does, use it.
18608 if NCT_Tables_In_Use then
18609 New_Id := NCT_New_Entities.Get (Id);
18611 if Present (New_Id) then
18618 end Corresponding_Entity;
18620 -------------------
18621 -- In_Entity_Map --
18622 -------------------
18624 function In_Entity_Map
18626 Entity_Map : Elist_Id) return Boolean
18629 Old_Id : Entity_Id;
18632 -- The entity map contains pairs (Old_Id, New_Id). The advancement
18633 -- step always skips the New_Id portion of the pair.
18635 if Present (Entity_Map) then
18636 Elmt := First_Elmt (Entity_Map);
18637 while Present (Elmt) loop
18638 Old_Id := Node (Elmt);
18640 if Old_Id = Id then
18652 ---------------------
18653 -- Update_CFS_Sloc --
18654 ---------------------
18656 procedure Update_CFS_Sloc (N : Node_Or_Entity_Id) is
18658 -- A new source location defaults the Comes_From_Source attribute
18660 if New_Sloc /= No_Location then
18661 Set_Comes_From_Source (N, Default_Node.Comes_From_Source);
18662 Set_Sloc (N, New_Sloc);
18664 end Update_CFS_Sloc;
18666 ---------------------------------
18667 -- Update_First_Real_Statement --
18668 ---------------------------------
18670 procedure Update_First_Real_Statement
18671 (Old_HSS : Node_Id;
18674 Old_First_Stmt : constant Node_Id := First_Real_Statement (Old_HSS);
18676 New_Stmt : Node_Id;
18677 Old_Stmt : Node_Id;
18680 -- Recreate the First_Real_Statement attribute of a handled sequence
18681 -- of statements by traversing the statement lists of both sequences
18684 if Present (Old_First_Stmt) then
18685 New_Stmt := First (Statements (New_HSS));
18686 Old_Stmt := First (Statements (Old_HSS));
18687 while Present (Old_Stmt) and then Old_Stmt /= Old_First_Stmt loop
18692 pragma Assert (Present (New_Stmt));
18693 pragma Assert (Present (Old_Stmt));
18695 Set_First_Real_Statement (New_HSS, New_Stmt);
18697 end Update_First_Real_Statement;
18699 -------------------------------
18700 -- Update_Named_Associations --
18701 -------------------------------
18703 procedure Update_Named_Associations
18704 (Old_Call : Node_Id;
18705 New_Call : Node_Id)
18708 New_Next : Node_Id;
18710 Old_Next : Node_Id;
18713 -- Recreate the First/Next_Named_Actual chain of a call by traversing
18714 -- the chains of both the old and new calls in parallel.
18716 New_Act := First (Parameter_Associations (New_Call));
18717 Old_Act := First (Parameter_Associations (Old_Call));
18718 while Present (Old_Act) loop
18719 if Nkind (Old_Act) = N_Parameter_Association
18720 and then Present (Next_Named_Actual (Old_Act))
18722 if First_Named_Actual (Old_Call) =
18723 Explicit_Actual_Parameter (Old_Act)
18725 Set_First_Named_Actual (New_Call,
18726 Explicit_Actual_Parameter (New_Act));
18729 -- Scan the actual parameter list to find the next suitable
18730 -- named actual. Note that the list may be out of order.
18732 New_Next := First (Parameter_Associations (New_Call));
18733 Old_Next := First (Parameter_Associations (Old_Call));
18734 while Nkind (Old_Next) /= N_Parameter_Association
18735 or else Explicit_Actual_Parameter (Old_Next) /=
18736 Next_Named_Actual (Old_Act)
18742 Set_Next_Named_Actual (New_Act,
18743 Explicit_Actual_Parameter (New_Next));
18749 end Update_Named_Associations;
18751 -------------------------
18752 -- Update_New_Entities --
18753 -------------------------
18755 procedure Update_New_Entities (Entity_Map : Elist_Id) is
18756 New_Id : Entity_Id := Empty;
18757 Old_Id : Entity_Id := Empty;
18760 if NCT_Tables_In_Use then
18761 NCT_New_Entities.Get_First (Old_Id, New_Id);
18763 -- Update the semantic fields of all new entities created during
18764 -- Phase 1 which were not supplied via an entity map.
18765 -- ??? Is there a better way of distinguishing those?
18767 while Present (Old_Id) and then Present (New_Id) loop
18768 if not (Present (Entity_Map)
18769 and then In_Entity_Map (Old_Id, Entity_Map))
18771 Update_Semantic_Fields (New_Id);
18774 NCT_New_Entities.Get_Next (Old_Id, New_Id);
18777 end Update_New_Entities;
18779 ---------------------------
18780 -- Update_Pending_Itypes --
18781 ---------------------------
18783 procedure Update_Pending_Itypes
18784 (Old_Assoc : Node_Id;
18785 New_Assoc : Node_Id)
18791 if NCT_Tables_In_Use then
18792 Itypes := NCT_Pending_Itypes.Get (Old_Assoc);
18794 -- Update the Associated_Node_For_Itype attribute for all itypes
18795 -- which originally refer to Old_Assoc to designate New_Assoc.
18797 if Present (Itypes) then
18798 Item := First_Elmt (Itypes);
18799 while Present (Item) loop
18800 Set_Associated_Node_For_Itype (Node (Item), New_Assoc);
18806 end Update_Pending_Itypes;
18808 ----------------------------
18809 -- Update_Semantic_Fields --
18810 ----------------------------
18812 procedure Update_Semantic_Fields (Id : Entity_Id) is
18814 -- Discriminant_Constraint
18816 if Has_Discriminants (Base_Type (Id)) then
18817 Set_Discriminant_Constraint (Id, Elist_Id (
18818 Copy_Field_With_Replacement
18819 (Field => Union_Id (Discriminant_Constraint (Id)),
18820 Semantic => True)));
18825 Set_Etype (Id, Node_Id (
18826 Copy_Field_With_Replacement
18827 (Field => Union_Id (Etype (Id)),
18828 Semantic => True)));
18831 -- Packed_Array_Impl_Type
18833 if Is_Array_Type (Id) then
18834 if Present (First_Index (Id)) then
18835 Set_First_Index (Id, First (List_Id (
18836 Copy_Field_With_Replacement
18837 (Field => Union_Id (List_Containing (First_Index (Id))),
18838 Semantic => True))));
18841 if Is_Packed (Id) then
18842 Set_Packed_Array_Impl_Type (Id, Node_Id (
18843 Copy_Field_With_Replacement
18844 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
18845 Semantic => True)));
18851 Set_Next_Entity (Id, Node_Id (
18852 Copy_Field_With_Replacement
18853 (Field => Union_Id (Next_Entity (Id)),
18854 Semantic => True)));
18858 if Is_Discrete_Type (Id) then
18859 Set_Scalar_Range (Id, Node_Id (
18860 Copy_Field_With_Replacement
18861 (Field => Union_Id (Scalar_Range (Id)),
18862 Semantic => True)));
18867 -- Update the scope when the caller specified an explicit one
18869 if Present (New_Scope) then
18870 Set_Scope (Id, New_Scope);
18872 Set_Scope (Id, Node_Id (
18873 Copy_Field_With_Replacement
18874 (Field => Union_Id (Scope (Id)),
18875 Semantic => True)));
18877 end Update_Semantic_Fields;
18879 --------------------
18880 -- Visit_Any_Node --
18881 --------------------
18883 procedure Visit_Any_Node (N : Node_Or_Entity_Id) is
18885 if Nkind (N) in N_Entity then
18886 if Is_Itype (N) then
18894 end Visit_Any_Node;
18900 procedure Visit_Elist (List : Elist_Id) is
18904 -- The element of an entity list could be an entity, itype, or a
18905 -- node, hence the call to Visit_Any_Node.
18907 if Present (List) then
18908 Elmt := First_Elmt (List);
18909 while Present (Elmt) loop
18910 Visit_Any_Node (Node (Elmt));
18921 procedure Visit_Entity (Id : Entity_Id) is
18922 New_Id : Entity_Id;
18925 pragma Assert (Nkind (Id) in N_Entity);
18926 pragma Assert (not Is_Itype (Id));
18928 -- Nothing to do if the entity is not defined in the Actions list of
18929 -- an N_Expression_With_Actions node.
18931 if EWA_Level = 0 then
18934 -- Nothing to do if the entity is defined within a scoping construct
18935 -- of an N_Expression_With_Actions node.
18937 elsif EWA_Inner_Scope_Level > 0 then
18940 -- Nothing to do if the entity is not an object or a type. Relaxing
18941 -- this restriction leads to a performance penalty.
18943 elsif not Ekind_In (Id, E_Constant, E_Variable)
18944 and then not Is_Type (Id)
18948 -- Nothing to do if the entity was already visited
18950 elsif NCT_Tables_In_Use
18951 and then Present (NCT_New_Entities.Get (Id))
18955 -- Nothing to do if the declaration node of the entity is not within
18956 -- the subtree being replicated.
18958 elsif not In_Subtree
18959 (N => Declaration_Node (Id),
18965 -- Create a new entity by directly copying the old entity. This
18966 -- action causes all attributes of the old entity to be inherited.
18968 New_Id := New_Copy (Id);
18970 -- Create a new name for the new entity because the back end needs
18971 -- distinct names for debugging purposes.
18973 Set_Chars (New_Id, New_Internal_Name ('T'));
18975 -- Update the Comes_From_Source and Sloc attributes of the entity in
18976 -- case the caller has supplied new values.
18978 Update_CFS_Sloc (New_Id);
18980 -- Establish the following mapping within table NCT_New_Entities:
18984 Add_New_Entity (Id, New_Id);
18986 -- Deal with the semantic fields of entities. The fields are visited
18987 -- because they may mention entities which reside within the subtree
18990 Visit_Semantic_Fields (Id);
18997 procedure Visit_Field
18999 Par_Nod : Node_Id := Empty;
19000 Semantic : Boolean := False)
19003 -- The field is empty
19005 if Field = Union_Id (Empty) then
19008 -- The field is an entity/itype/node
19010 elsif Field in Node_Range then
19012 N : constant Node_Id := Node_Id (Field);
19015 -- The field is an entity/itype
19017 if Nkind (N) in N_Entity then
19019 -- Itypes are always visited
19021 if Is_Itype (N) then
19024 -- An entity is visited when it is either a syntactic field
19025 -- or when the caller treats it as a semantic attribute.
19027 elsif Parent (N) = Par_Nod or else Semantic then
19031 -- The field is a node
19034 -- A node is visited when it is either a syntactic field or
19035 -- when the caller treats it as a semantic attribute.
19037 if Parent (N) = Par_Nod or else Semantic then
19043 -- The field is an entity list
19045 elsif Field in Elist_Range then
19046 Visit_Elist (Elist_Id (Field));
19048 -- The field is a syntax list
19050 elsif Field in List_Range then
19052 List : constant List_Id := List_Id (Field);
19055 -- A syntax list is visited when it is either a syntactic field
19056 -- or when the caller treats it as a semantic attribute.
19058 if Parent (List) = Par_Nod or else Semantic then
19063 -- Otherwise the field denotes information which does not need to be
19064 -- visited (chars, literals, etc.).
19075 procedure Visit_Itype (Itype : Entity_Id) is
19076 New_Assoc : Node_Id;
19077 New_Itype : Entity_Id;
19078 Old_Assoc : Node_Id;
19081 pragma Assert (Nkind (Itype) in N_Entity);
19082 pragma Assert (Is_Itype (Itype));
19084 -- Itypes that describe the designated type of access to subprograms
19085 -- have the structure of subprogram declarations, with signatures,
19086 -- etc. Either we duplicate the signatures completely, or choose to
19087 -- share such itypes, which is fine because their elaboration will
19088 -- have no side effects.
19090 if Ekind (Itype) = E_Subprogram_Type then
19093 -- Nothing to do if the itype was already visited
19095 elsif NCT_Tables_In_Use
19096 and then Present (NCT_New_Entities.Get (Itype))
19100 -- Nothing to do if the associated node of the itype is not within
19101 -- the subtree being replicated.
19103 elsif not In_Subtree
19104 (N => Associated_Node_For_Itype (Itype),
19110 -- Create a new itype by directly copying the old itype. This action
19111 -- causes all attributes of the old itype to be inherited.
19113 New_Itype := New_Copy (Itype);
19115 -- Create a new name for the new itype because the back end requires
19116 -- distinct names for debugging purposes.
19118 Set_Chars (New_Itype, New_Internal_Name ('T'));
19120 -- Update the Comes_From_Source and Sloc attributes of the itype in
19121 -- case the caller has supplied new values.
19123 Update_CFS_Sloc (New_Itype);
19125 -- Establish the following mapping within table NCT_New_Entities:
19127 -- Itype -> New_Itype
19129 Add_New_Entity (Itype, New_Itype);
19131 -- The new itype must be unfrozen because the resulting subtree may
19132 -- be inserted anywhere and cause an earlier or later freezing.
19134 if Present (Freeze_Node (New_Itype)) then
19135 Set_Freeze_Node (New_Itype, Empty);
19136 Set_Is_Frozen (New_Itype, False);
19139 -- If a record subtype is simply copied, the entity list will be
19140 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
19141 -- ??? What does this do?
19143 if Ekind_In (Itype, E_Class_Wide_Subtype, E_Record_Subtype) then
19144 Set_Cloned_Subtype (New_Itype, Itype);
19147 -- The associated node may denote an entity, in which case it may
19148 -- already have a new corresponding entity created during a prior
19149 -- call to Visit_Entity or Visit_Itype for the same subtree.
19152 -- Old_Assoc ---------> New_Assoc
19154 -- Created by Visit_Itype
19155 -- Itype -------------> New_Itype
19156 -- ANFI = Old_Assoc ANFI = Old_Assoc < must be updated
19158 -- In the example above, Old_Assoc is an arbitrary entity that was
19159 -- already visited for the same subtree and has a corresponding new
19160 -- entity New_Assoc. Old_Assoc was inherited by New_Itype by virtue
19161 -- of copying entities, however it must be updated to New_Assoc.
19163 Old_Assoc := Associated_Node_For_Itype (Itype);
19165 if Nkind (Old_Assoc) in N_Entity then
19166 if NCT_Tables_In_Use then
19167 New_Assoc := NCT_New_Entities.Get (Old_Assoc);
19169 if Present (New_Assoc) then
19170 Set_Associated_Node_For_Itype (New_Itype, New_Assoc);
19174 -- Otherwise the associated node denotes a node. Postpone the update
19175 -- until Phase 2 when the node is replicated. Establish the following
19176 -- mapping within table NCT_Pending_Itypes:
19178 -- Old_Assoc -> (New_Type, ...)
19181 Add_Pending_Itype (Old_Assoc, New_Itype);
19184 -- Deal with the semantic fields of itypes. The fields are visited
19185 -- because they may mention entities that reside within the subtree
19188 Visit_Semantic_Fields (Itype);
19195 procedure Visit_List (List : List_Id) is
19199 -- Note that the element of a syntactic list is always a node, never
19200 -- an entity or itype, hence the call to Visit_Node.
19202 if Present (List) then
19203 Elmt := First (List);
19204 while Present (Elmt) loop
19216 procedure Visit_Node (N : Node_Or_Entity_Id) is
19218 pragma Assert (Nkind (N) not in N_Entity);
19220 if Nkind (N) = N_Expression_With_Actions then
19221 EWA_Level := EWA_Level + 1;
19223 elsif EWA_Level > 0
19224 and then Nkind_In (N, N_Block_Statement,
19226 N_Subprogram_Declaration)
19228 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level + 1;
19232 (Field => Field1 (N),
19236 (Field => Field2 (N),
19240 (Field => Field3 (N),
19244 (Field => Field4 (N),
19248 (Field => Field5 (N),
19252 and then Nkind_In (N, N_Block_Statement,
19254 N_Subprogram_Declaration)
19256 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level - 1;
19258 elsif Nkind (N) = N_Expression_With_Actions then
19259 EWA_Level := EWA_Level - 1;
19263 ---------------------------
19264 -- Visit_Semantic_Fields --
19265 ---------------------------
19267 procedure Visit_Semantic_Fields (Id : Entity_Id) is
19269 pragma Assert (Nkind (Id) in N_Entity);
19271 -- Discriminant_Constraint
19273 if Has_Discriminants (Base_Type (Id)) then
19275 (Field => Union_Id (Discriminant_Constraint (Id)),
19282 (Field => Union_Id (Etype (Id)),
19286 -- Packed_Array_Impl_Type
19288 if Is_Array_Type (Id) then
19289 if Present (First_Index (Id)) then
19291 (Field => Union_Id (List_Containing (First_Index (Id))),
19295 if Is_Packed (Id) then
19297 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
19304 if Is_Discrete_Type (Id) then
19306 (Field => Union_Id (Scalar_Range (Id)),
19309 end Visit_Semantic_Fields;
19311 -- Start of processing for New_Copy_Tree
19314 -- Routine New_Copy_Tree performs a deep copy of a subtree by creating
19315 -- shallow copies for each node within, and then updating the child and
19316 -- parent pointers accordingly. This process is straightforward, however
19317 -- the routine must deal with the following complications:
19319 -- * Entities defined within N_Expression_With_Actions nodes must be
19320 -- replicated rather than shared to avoid introducing two identical
19321 -- symbols within the same scope. Note that no other expression can
19322 -- currently define entities.
19325 -- Source_Low : ...;
19326 -- Source_High : ...;
19328 -- <reference to Source_Low>
19329 -- <reference to Source_High>
19332 -- New_Copy_Tree handles this case by first creating new entities
19333 -- and then updating all existing references to point to these new
19340 -- <reference to New_Low>
19341 -- <reference to New_High>
19344 -- * Itypes defined within the subtree must be replicated to avoid any
19345 -- dependencies on invalid or inaccessible data.
19347 -- subtype Source_Itype is ... range Source_Low .. Source_High;
19349 -- New_Copy_Tree handles this case by first creating a new itype in
19350 -- the same fashion as entities, and then updating various relevant
19353 -- subtype New_Itype is ... range New_Low .. New_High;
19355 -- * The Associated_Node_For_Itype field of itypes must be updated to
19356 -- reference the proper replicated entity or node.
19358 -- * Semantic fields of entities such as Etype and Scope must be
19359 -- updated to reference the proper replicated entities.
19361 -- * Semantic fields of nodes such as First_Real_Statement must be
19362 -- updated to reference the proper replicated nodes.
19364 -- To meet all these demands, routine New_Copy_Tree is split into two
19367 -- Phase 1 traverses the tree in order to locate entities and itypes
19368 -- defined within the subtree. New entities are generated and saved in
19369 -- table NCT_New_Entities. The semantic fields of all new entities and
19370 -- itypes are then updated accordingly.
19372 -- Phase 2 traverses the tree in order to replicate each node. Various
19373 -- semantic fields of nodes and entities are updated accordingly.
19375 -- Preparatory phase. Clear the contents of tables NCT_New_Entities and
19376 -- NCT_Pending_Itypes in case a previous call to New_Copy_Tree left some
19379 if NCT_Tables_In_Use then
19380 NCT_Tables_In_Use := False;
19382 NCT_New_Entities.Reset;
19383 NCT_Pending_Itypes.Reset;
19386 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with data
19387 -- supplied by a linear entity map. The tables offer faster access to
19390 Build_NCT_Tables (Map);
19392 -- Execute Phase 1. Traverse the subtree and generate new entities for
19393 -- the following cases:
19395 -- * An entity defined within an N_Expression_With_Actions node
19397 -- * An itype referenced within the subtree where the associated node
19398 -- is also in the subtree.
19400 -- All new entities are accessible via table NCT_New_Entities, which
19401 -- contains mappings of the form:
19403 -- Old_Entity -> New_Entity
19404 -- Old_Itype -> New_Itype
19406 -- In addition, the associated nodes of all new itypes are mapped in
19407 -- table NCT_Pending_Itypes:
19409 -- Assoc_Nod -> (New_Itype1, New_Itype2, .., New_ItypeN)
19411 Visit_Any_Node (Source);
19413 -- Update the semantic attributes of all new entities generated during
19414 -- Phase 1 before starting Phase 2. The updates could be performed in
19415 -- routine Corresponding_Entity, however this may cause the same entity
19416 -- to be updated multiple times, effectively generating useless nodes.
19417 -- Keeping the updates separates from Phase 2 ensures that only one set
19418 -- of attributes is generated for an entity at any one time.
19420 Update_New_Entities (Map);
19422 -- Execute Phase 2. Replicate the source subtree one node at a time.
19423 -- The following transformations take place:
19425 -- * References to entities and itypes are updated to refer to the
19426 -- new entities and itypes generated during Phase 1.
19428 -- * All Associated_Node_For_Itype attributes of itypes are updated
19429 -- to refer to the new replicated Associated_Node_For_Itype.
19431 return Copy_Node_With_Replacement (Source);
19434 -------------------------
19435 -- New_External_Entity --
19436 -------------------------
19438 function New_External_Entity
19439 (Kind : Entity_Kind;
19440 Scope_Id : Entity_Id;
19441 Sloc_Value : Source_Ptr;
19442 Related_Id : Entity_Id;
19443 Suffix : Character;
19444 Suffix_Index : Nat := 0;
19445 Prefix : Character := ' ') return Entity_Id
19447 N : constant Entity_Id :=
19448 Make_Defining_Identifier (Sloc_Value,
19450 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
19453 Set_Ekind (N, Kind);
19454 Set_Is_Internal (N, True);
19455 Append_Entity (N, Scope_Id);
19456 Set_Public_Status (N);
19458 if Kind in Type_Kind then
19459 Init_Size_Align (N);
19463 end New_External_Entity;
19465 -------------------------
19466 -- New_Internal_Entity --
19467 -------------------------
19469 function New_Internal_Entity
19470 (Kind : Entity_Kind;
19471 Scope_Id : Entity_Id;
19472 Sloc_Value : Source_Ptr;
19473 Id_Char : Character) return Entity_Id
19475 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
19478 Set_Ekind (N, Kind);
19479 Set_Is_Internal (N, True);
19480 Append_Entity (N, Scope_Id);
19482 if Kind in Type_Kind then
19483 Init_Size_Align (N);
19487 end New_Internal_Entity;
19493 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
19497 -- If we are pointing at a positional parameter, it is a member of a
19498 -- node list (the list of parameters), and the next parameter is the
19499 -- next node on the list, unless we hit a parameter association, then
19500 -- we shift to using the chain whose head is the First_Named_Actual in
19501 -- the parent, and then is threaded using the Next_Named_Actual of the
19502 -- Parameter_Association. All this fiddling is because the original node
19503 -- list is in the textual call order, and what we need is the
19504 -- declaration order.
19506 if Is_List_Member (Actual_Id) then
19507 N := Next (Actual_Id);
19509 if Nkind (N) = N_Parameter_Association then
19511 -- In case of a build-in-place call, the call will no longer be a
19512 -- call; it will have been rewritten.
19514 if Nkind_In (Parent (Actual_Id), N_Entry_Call_Statement,
19516 N_Procedure_Call_Statement)
19518 return First_Named_Actual (Parent (Actual_Id));
19527 return Next_Named_Actual (Parent (Actual_Id));
19531 procedure Next_Actual (Actual_Id : in out Node_Id) is
19533 Actual_Id := Next_Actual (Actual_Id);
19540 function Next_Global (Node : Node_Id) return Node_Id is
19542 -- The global item may either be in a list, or by itself, in which case
19543 -- there is no next global item with the same mode.
19545 if Is_List_Member (Node) then
19546 return Next (Node);
19552 procedure Next_Global (Node : in out Node_Id) is
19554 Node := Next_Global (Node);
19557 ----------------------------------
19558 -- New_Requires_Transient_Scope --
19559 ----------------------------------
19561 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
19562 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean;
19563 -- This is called for untagged records and protected types, with
19564 -- nondefaulted discriminants. Returns True if the size of function
19565 -- results is known at the call site, False otherwise. Returns False
19566 -- if there is a variant part that depends on the discriminants of
19567 -- this type, or if there is an array constrained by the discriminants
19568 -- of this type. ???Currently, this is overly conservative (the array
19569 -- could be nested inside some other record that is constrained by
19570 -- nondiscriminants). That is, the recursive calls are too conservative.
19572 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean;
19573 -- Returns True if Typ is a nonlimited record with defaulted
19574 -- discriminants whose max size makes it unsuitable for allocating on
19575 -- the primary stack.
19577 ------------------------------
19578 -- Caller_Known_Size_Record --
19579 ------------------------------
19581 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean is
19582 pragma Assert (Typ = Underlying_Type (Typ));
19585 if Has_Variant_Part (Typ) and then not Is_Definite_Subtype (Typ) then
19593 Comp := First_Entity (Typ);
19594 while Present (Comp) loop
19596 -- Only look at E_Component entities. No need to look at
19597 -- E_Discriminant entities, and we must ignore internal
19598 -- subtypes generated for constrained components.
19600 if Ekind (Comp) = E_Component then
19602 Comp_Type : constant Entity_Id :=
19603 Underlying_Type (Etype (Comp));
19606 if Is_Record_Type (Comp_Type)
19608 Is_Protected_Type (Comp_Type)
19610 if not Caller_Known_Size_Record (Comp_Type) then
19614 elsif Is_Array_Type (Comp_Type) then
19615 if Size_Depends_On_Discriminant (Comp_Type) then
19622 Next_Entity (Comp);
19627 end Caller_Known_Size_Record;
19629 ------------------------------
19630 -- Large_Max_Size_Mutable --
19631 ------------------------------
19633 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean is
19634 pragma Assert (Typ = Underlying_Type (Typ));
19636 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean;
19637 -- Returns true if the discrete type T has a large range
19639 ----------------------------
19640 -- Is_Large_Discrete_Type --
19641 ----------------------------
19643 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean is
19644 Threshold : constant Int := 16;
19645 -- Arbitrary threshold above which we consider it "large". We want
19646 -- a fairly large threshold, because these large types really
19647 -- shouldn't have default discriminants in the first place, in
19651 return UI_To_Int (RM_Size (T)) > Threshold;
19652 end Is_Large_Discrete_Type;
19654 -- Start of processing for Large_Max_Size_Mutable
19657 if Is_Record_Type (Typ)
19658 and then not Is_Limited_View (Typ)
19659 and then Has_Defaulted_Discriminants (Typ)
19661 -- Loop through the components, looking for an array whose upper
19662 -- bound(s) depends on discriminants, where both the subtype of
19663 -- the discriminant and the index subtype are too large.
19669 Comp := First_Entity (Typ);
19670 while Present (Comp) loop
19671 if Ekind (Comp) = E_Component then
19673 Comp_Type : constant Entity_Id :=
19674 Underlying_Type (Etype (Comp));
19681 if Is_Array_Type (Comp_Type) then
19682 Indx := First_Index (Comp_Type);
19684 while Present (Indx) loop
19685 Ityp := Etype (Indx);
19686 Hi := Type_High_Bound (Ityp);
19688 if Nkind (Hi) = N_Identifier
19689 and then Ekind (Entity (Hi)) = E_Discriminant
19690 and then Is_Large_Discrete_Type (Ityp)
19691 and then Is_Large_Discrete_Type
19692 (Etype (Entity (Hi)))
19703 Next_Entity (Comp);
19709 end Large_Max_Size_Mutable;
19711 -- Local declarations
19713 Typ : constant Entity_Id := Underlying_Type (Id);
19715 -- Start of processing for New_Requires_Transient_Scope
19718 -- This is a private type which is not completed yet. This can only
19719 -- happen in a default expression (of a formal parameter or of a
19720 -- record component). Do not expand transient scope in this case.
19725 -- Do not expand transient scope for non-existent procedure return or
19726 -- string literal types.
19728 elsif Typ = Standard_Void_Type
19729 or else Ekind (Typ) = E_String_Literal_Subtype
19733 -- If Typ is a generic formal incomplete type, then we want to look at
19734 -- the actual type.
19736 elsif Ekind (Typ) = E_Record_Subtype
19737 and then Present (Cloned_Subtype (Typ))
19739 return New_Requires_Transient_Scope (Cloned_Subtype (Typ));
19741 -- Functions returning specific tagged types may dispatch on result, so
19742 -- their returned value is allocated on the secondary stack, even in the
19743 -- definite case. We must treat nondispatching functions the same way,
19744 -- because access-to-function types can point at both, so the calling
19745 -- conventions must be compatible. Is_Tagged_Type includes controlled
19746 -- types and class-wide types. Controlled type temporaries need
19749 -- ???It's not clear why we need to return noncontrolled types with
19750 -- controlled components on the secondary stack.
19752 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
19755 -- Untagged definite subtypes are known size. This includes all
19756 -- elementary [sub]types. Tasks are known size even if they have
19757 -- discriminants. So we return False here, with one exception:
19758 -- For a type like:
19759 -- type T (Last : Natural := 0) is
19760 -- X : String (1 .. Last);
19762 -- we return True. That's because for "P(F(...));", where F returns T,
19763 -- we don't know the size of the result at the call site, so if we
19764 -- allocated it on the primary stack, we would have to allocate the
19765 -- maximum size, which is way too big.
19767 elsif Is_Definite_Subtype (Typ) or else Is_Task_Type (Typ) then
19768 return Large_Max_Size_Mutable (Typ);
19770 -- Indefinite (discriminated) untagged record or protected type
19772 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
19773 return not Caller_Known_Size_Record (Typ);
19775 -- Unconstrained array
19778 pragma Assert (Is_Array_Type (Typ) and not Is_Definite_Subtype (Typ));
19781 end New_Requires_Transient_Scope;
19783 --------------------------
19784 -- No_Heap_Finalization --
19785 --------------------------
19787 function No_Heap_Finalization (Typ : Entity_Id) return Boolean is
19789 if Ekind_In (Typ, E_Access_Type, E_General_Access_Type)
19790 and then Is_Library_Level_Entity (Typ)
19792 -- A global No_Heap_Finalization pragma applies to all library-level
19793 -- named access-to-object types.
19795 if Present (No_Heap_Finalization_Pragma) then
19798 -- The library-level named access-to-object type itself is subject to
19799 -- pragma No_Heap_Finalization.
19801 elsif Present (Get_Pragma (Typ, Pragma_No_Heap_Finalization)) then
19807 end No_Heap_Finalization;
19809 -----------------------
19810 -- Normalize_Actuals --
19811 -----------------------
19813 -- Chain actuals according to formals of subprogram. If there are no named
19814 -- associations, the chain is simply the list of Parameter Associations,
19815 -- since the order is the same as the declaration order. If there are named
19816 -- associations, then the First_Named_Actual field in the N_Function_Call
19817 -- or N_Procedure_Call_Statement node points to the Parameter_Association
19818 -- node for the parameter that comes first in declaration order. The
19819 -- remaining named parameters are then chained in declaration order using
19820 -- Next_Named_Actual.
19822 -- This routine also verifies that the number of actuals is compatible with
19823 -- the number and default values of formals, but performs no type checking
19824 -- (type checking is done by the caller).
19826 -- If the matching succeeds, Success is set to True and the caller proceeds
19827 -- with type-checking. If the match is unsuccessful, then Success is set to
19828 -- False, and the caller attempts a different interpretation, if there is
19831 -- If the flag Report is on, the call is not overloaded, and a failure to
19832 -- match can be reported here, rather than in the caller.
19834 procedure Normalize_Actuals
19838 Success : out Boolean)
19840 Actuals : constant List_Id := Parameter_Associations (N);
19841 Actual : Node_Id := Empty;
19842 Formal : Entity_Id;
19843 Last : Node_Id := Empty;
19844 First_Named : Node_Id := Empty;
19847 Formals_To_Match : Integer := 0;
19848 Actuals_To_Match : Integer := 0;
19850 procedure Chain (A : Node_Id);
19851 -- Add named actual at the proper place in the list, using the
19852 -- Next_Named_Actual link.
19854 function Reporting return Boolean;
19855 -- Determines if an error is to be reported. To report an error, we
19856 -- need Report to be True, and also we do not report errors caused
19857 -- by calls to init procs that occur within other init procs. Such
19858 -- errors must always be cascaded errors, since if all the types are
19859 -- declared correctly, the compiler will certainly build decent calls.
19865 procedure Chain (A : Node_Id) is
19869 -- Call node points to first actual in list
19871 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
19874 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
19878 Set_Next_Named_Actual (Last, Empty);
19885 function Reporting return Boolean is
19890 elsif not Within_Init_Proc then
19893 elsif Is_Init_Proc (Entity (Name (N))) then
19901 -- Start of processing for Normalize_Actuals
19904 if Is_Access_Type (S) then
19906 -- The name in the call is a function call that returns an access
19907 -- to subprogram. The designated type has the list of formals.
19909 Formal := First_Formal (Designated_Type (S));
19911 Formal := First_Formal (S);
19914 while Present (Formal) loop
19915 Formals_To_Match := Formals_To_Match + 1;
19916 Next_Formal (Formal);
19919 -- Find if there is a named association, and verify that no positional
19920 -- associations appear after named ones.
19922 if Present (Actuals) then
19923 Actual := First (Actuals);
19926 while Present (Actual)
19927 and then Nkind (Actual) /= N_Parameter_Association
19929 Actuals_To_Match := Actuals_To_Match + 1;
19933 if No (Actual) and Actuals_To_Match = Formals_To_Match then
19935 -- Most common case: positional notation, no defaults
19940 elsif Actuals_To_Match > Formals_To_Match then
19942 -- Too many actuals: will not work
19945 if Is_Entity_Name (Name (N)) then
19946 Error_Msg_N ("too many arguments in call to&", Name (N));
19948 Error_Msg_N ("too many arguments in call", N);
19956 First_Named := Actual;
19958 while Present (Actual) loop
19959 if Nkind (Actual) /= N_Parameter_Association then
19961 ("positional parameters not allowed after named ones", Actual);
19966 Actuals_To_Match := Actuals_To_Match + 1;
19972 if Present (Actuals) then
19973 Actual := First (Actuals);
19976 Formal := First_Formal (S);
19977 while Present (Formal) loop
19979 -- Match the formals in order. If the corresponding actual is
19980 -- positional, nothing to do. Else scan the list of named actuals
19981 -- to find the one with the right name.
19983 if Present (Actual)
19984 and then Nkind (Actual) /= N_Parameter_Association
19987 Actuals_To_Match := Actuals_To_Match - 1;
19988 Formals_To_Match := Formals_To_Match - 1;
19991 -- For named parameters, search the list of actuals to find
19992 -- one that matches the next formal name.
19994 Actual := First_Named;
19996 while Present (Actual) loop
19997 if Chars (Selector_Name (Actual)) = Chars (Formal) then
20000 Actuals_To_Match := Actuals_To_Match - 1;
20001 Formals_To_Match := Formals_To_Match - 1;
20009 if Ekind (Formal) /= E_In_Parameter
20010 or else No (Default_Value (Formal))
20013 if (Comes_From_Source (S)
20014 or else Sloc (S) = Standard_Location)
20015 and then Is_Overloadable (S)
20019 Nkind_In (Parent (N), N_Procedure_Call_Statement,
20021 N_Parameter_Association)
20022 and then Ekind (S) /= E_Function
20024 Set_Etype (N, Etype (S));
20027 Error_Msg_Name_1 := Chars (S);
20028 Error_Msg_Sloc := Sloc (S);
20030 ("missing argument for parameter & "
20031 & "in call to % declared #", N, Formal);
20034 elsif Is_Overloadable (S) then
20035 Error_Msg_Name_1 := Chars (S);
20037 -- Point to type derivation that generated the
20040 Error_Msg_Sloc := Sloc (Parent (S));
20043 ("missing argument for parameter & "
20044 & "in call to % (inherited) #", N, Formal);
20048 ("missing argument for parameter &", N, Formal);
20056 Formals_To_Match := Formals_To_Match - 1;
20061 Next_Formal (Formal);
20064 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
20071 -- Find some superfluous named actual that did not get
20072 -- attached to the list of associations.
20074 Actual := First (Actuals);
20075 while Present (Actual) loop
20076 if Nkind (Actual) = N_Parameter_Association
20077 and then Actual /= Last
20078 and then No (Next_Named_Actual (Actual))
20080 -- A validity check may introduce a copy of a call that
20081 -- includes an extra actual (for example for an unrelated
20082 -- accessibility check). Check that the extra actual matches
20083 -- some extra formal, which must exist already because
20084 -- subprogram must be frozen at this point.
20086 if Present (Extra_Formals (S))
20087 and then not Comes_From_Source (Actual)
20088 and then Nkind (Actual) = N_Parameter_Association
20089 and then Chars (Extra_Formals (S)) =
20090 Chars (Selector_Name (Actual))
20095 ("unmatched actual & in call", Selector_Name (Actual));
20107 end Normalize_Actuals;
20109 --------------------------------
20110 -- Note_Possible_Modification --
20111 --------------------------------
20113 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
20114 Modification_Comes_From_Source : constant Boolean :=
20115 Comes_From_Source (Parent (N));
20121 -- Loop to find referenced entity, if there is one
20127 if Is_Entity_Name (Exp) then
20128 Ent := Entity (Exp);
20130 -- If the entity is missing, it is an undeclared identifier,
20131 -- and there is nothing to annotate.
20137 elsif Nkind (Exp) = N_Explicit_Dereference then
20139 P : constant Node_Id := Prefix (Exp);
20142 -- In formal verification mode, keep track of all reads and
20143 -- writes through explicit dereferences.
20145 if GNATprove_Mode then
20146 SPARK_Specific.Generate_Dereference (N, 'm');
20149 if Nkind (P) = N_Selected_Component
20150 and then Present (Entry_Formal (Entity (Selector_Name (P))))
20152 -- Case of a reference to an entry formal
20154 Ent := Entry_Formal (Entity (Selector_Name (P)));
20156 elsif Nkind (P) = N_Identifier
20157 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
20158 and then Present (Expression (Parent (Entity (P))))
20159 and then Nkind (Expression (Parent (Entity (P)))) =
20162 -- Case of a reference to a value on which side effects have
20165 Exp := Prefix (Expression (Parent (Entity (P))));
20173 elsif Nkind_In (Exp, N_Type_Conversion,
20174 N_Unchecked_Type_Conversion)
20176 Exp := Expression (Exp);
20179 elsif Nkind_In (Exp, N_Slice,
20180 N_Indexed_Component,
20181 N_Selected_Component)
20183 -- Special check, if the prefix is an access type, then return
20184 -- since we are modifying the thing pointed to, not the prefix.
20185 -- When we are expanding, most usually the prefix is replaced
20186 -- by an explicit dereference, and this test is not needed, but
20187 -- in some cases (notably -gnatc mode and generics) when we do
20188 -- not do full expansion, we need this special test.
20190 if Is_Access_Type (Etype (Prefix (Exp))) then
20193 -- Otherwise go to prefix and keep going
20196 Exp := Prefix (Exp);
20200 -- All other cases, not a modification
20206 -- Now look for entity being referenced
20208 if Present (Ent) then
20209 if Is_Object (Ent) then
20210 if Comes_From_Source (Exp)
20211 or else Modification_Comes_From_Source
20213 -- Give warning if pragma unmodified is given and we are
20214 -- sure this is a modification.
20216 if Has_Pragma_Unmodified (Ent) and then Sure then
20218 -- Note that the entity may be present only as a result
20219 -- of pragma Unused.
20221 if Has_Pragma_Unused (Ent) then
20222 Error_Msg_NE ("??pragma Unused given for &!", N, Ent);
20225 ("??pragma Unmodified given for &!", N, Ent);
20229 Set_Never_Set_In_Source (Ent, False);
20232 Set_Is_True_Constant (Ent, False);
20233 Set_Current_Value (Ent, Empty);
20234 Set_Is_Known_Null (Ent, False);
20236 if not Can_Never_Be_Null (Ent) then
20237 Set_Is_Known_Non_Null (Ent, False);
20240 -- Follow renaming chain
20242 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
20243 and then Present (Renamed_Object (Ent))
20245 Exp := Renamed_Object (Ent);
20247 -- If the entity is the loop variable in an iteration over
20248 -- a container, retrieve container expression to indicate
20249 -- possible modification.
20251 if Present (Related_Expression (Ent))
20252 and then Nkind (Parent (Related_Expression (Ent))) =
20253 N_Iterator_Specification
20255 Exp := Original_Node (Related_Expression (Ent));
20260 -- The expression may be the renaming of a subcomponent of an
20261 -- array or container. The assignment to the subcomponent is
20262 -- a modification of the container.
20264 elsif Comes_From_Source (Original_Node (Exp))
20265 and then Nkind_In (Original_Node (Exp), N_Selected_Component,
20266 N_Indexed_Component)
20268 Exp := Prefix (Original_Node (Exp));
20272 -- Generate a reference only if the assignment comes from
20273 -- source. This excludes, for example, calls to a dispatching
20274 -- assignment operation when the left-hand side is tagged. In
20275 -- GNATprove mode, we need those references also on generated
20276 -- code, as these are used to compute the local effects of
20279 if Modification_Comes_From_Source or GNATprove_Mode then
20280 Generate_Reference (Ent, Exp, 'm');
20282 -- If the target of the assignment is the bound variable
20283 -- in an iterator, indicate that the corresponding array
20284 -- or container is also modified.
20286 if Ada_Version >= Ada_2012
20287 and then Nkind (Parent (Ent)) = N_Iterator_Specification
20290 Domain : constant Node_Id := Name (Parent (Ent));
20293 -- TBD : in the full version of the construct, the
20294 -- domain of iteration can be given by an expression.
20296 if Is_Entity_Name (Domain) then
20297 Generate_Reference (Entity (Domain), Exp, 'm');
20298 Set_Is_True_Constant (Entity (Domain), False);
20299 Set_Never_Set_In_Source (Entity (Domain), False);
20308 -- If we are sure this is a modification from source, and we know
20309 -- this modifies a constant, then give an appropriate warning.
20312 and then Modification_Comes_From_Source
20313 and then Overlays_Constant (Ent)
20314 and then Address_Clause_Overlay_Warnings
20317 Addr : constant Node_Id := Address_Clause (Ent);
20322 Find_Overlaid_Entity (Addr, O_Ent, Off);
20324 Error_Msg_Sloc := Sloc (Addr);
20326 ("??constant& may be modified via address clause#",
20337 end Note_Possible_Modification;
20343 function Null_Status (N : Node_Id) return Null_Status_Kind is
20344 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean;
20345 -- Determine whether definition Def carries a null exclusion
20347 function Null_Status_Of_Entity (Id : Entity_Id) return Null_Status_Kind;
20348 -- Determine the null status of arbitrary entity Id
20350 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind;
20351 -- Determine the null status of type Typ
20353 ---------------------------
20354 -- Is_Null_Excluding_Def --
20355 ---------------------------
20357 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean is
20360 Nkind_In (Def, N_Access_Definition,
20361 N_Access_Function_Definition,
20362 N_Access_Procedure_Definition,
20363 N_Access_To_Object_Definition,
20364 N_Component_Definition,
20365 N_Derived_Type_Definition)
20366 and then Null_Exclusion_Present (Def);
20367 end Is_Null_Excluding_Def;
20369 ---------------------------
20370 -- Null_Status_Of_Entity --
20371 ---------------------------
20373 function Null_Status_Of_Entity
20374 (Id : Entity_Id) return Null_Status_Kind
20376 Decl : constant Node_Id := Declaration_Node (Id);
20380 -- The value of an imported or exported entity may be set externally
20381 -- regardless of a null exclusion. As a result, the value cannot be
20382 -- determined statically.
20384 if Is_Imported (Id) or else Is_Exported (Id) then
20387 elsif Nkind_In (Decl, N_Component_Declaration,
20388 N_Discriminant_Specification,
20389 N_Formal_Object_Declaration,
20390 N_Object_Declaration,
20391 N_Object_Renaming_Declaration,
20392 N_Parameter_Specification)
20394 -- A component declaration yields a non-null value when either
20395 -- its component definition or access definition carries a null
20398 if Nkind (Decl) = N_Component_Declaration then
20399 Def := Component_Definition (Decl);
20401 if Is_Null_Excluding_Def (Def) then
20402 return Is_Non_Null;
20405 Def := Access_Definition (Def);
20407 if Present (Def) and then Is_Null_Excluding_Def (Def) then
20408 return Is_Non_Null;
20411 -- A formal object declaration yields a non-null value if its
20412 -- access definition carries a null exclusion. If the object is
20413 -- default initialized, then the value depends on the expression.
20415 elsif Nkind (Decl) = N_Formal_Object_Declaration then
20416 Def := Access_Definition (Decl);
20418 if Present (Def) and then Is_Null_Excluding_Def (Def) then
20419 return Is_Non_Null;
20422 -- A constant may yield a null or non-null value depending on its
20423 -- initialization expression.
20425 elsif Ekind (Id) = E_Constant then
20426 return Null_Status (Constant_Value (Id));
20428 -- The construct yields a non-null value when it has a null
20431 elsif Null_Exclusion_Present (Decl) then
20432 return Is_Non_Null;
20434 -- An object renaming declaration yields a non-null value if its
20435 -- access definition carries a null exclusion. Otherwise the value
20436 -- depends on the renamed name.
20438 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
20439 Def := Access_Definition (Decl);
20441 if Present (Def) and then Is_Null_Excluding_Def (Def) then
20442 return Is_Non_Null;
20445 return Null_Status (Name (Decl));
20450 -- At this point the declaration of the entity does not carry a null
20451 -- exclusion and lacks an initialization expression. Check the status
20454 return Null_Status_Of_Type (Etype (Id));
20455 end Null_Status_Of_Entity;
20457 -------------------------
20458 -- Null_Status_Of_Type --
20459 -------------------------
20461 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind is
20466 -- Traverse the type chain looking for types with null exclusion
20469 while Present (Curr) and then Etype (Curr) /= Curr loop
20470 Decl := Parent (Curr);
20472 -- Guard against itypes which do not always have declarations. A
20473 -- type yields a non-null value if it carries a null exclusion.
20475 if Present (Decl) then
20476 if Nkind (Decl) = N_Full_Type_Declaration
20477 and then Is_Null_Excluding_Def (Type_Definition (Decl))
20479 return Is_Non_Null;
20481 elsif Nkind (Decl) = N_Subtype_Declaration
20482 and then Null_Exclusion_Present (Decl)
20484 return Is_Non_Null;
20488 Curr := Etype (Curr);
20491 -- The type chain does not contain any null excluding types
20494 end Null_Status_Of_Type;
20496 -- Start of processing for Null_Status
20499 -- An allocator always creates a non-null value
20501 if Nkind (N) = N_Allocator then
20502 return Is_Non_Null;
20504 -- Taking the 'Access of something yields a non-null value
20506 elsif Nkind (N) = N_Attribute_Reference
20507 and then Nam_In (Attribute_Name (N), Name_Access,
20508 Name_Unchecked_Access,
20509 Name_Unrestricted_Access)
20511 return Is_Non_Null;
20513 -- "null" yields null
20515 elsif Nkind (N) = N_Null then
20518 -- Check the status of the operand of a type conversion
20520 elsif Nkind (N) = N_Type_Conversion then
20521 return Null_Status (Expression (N));
20523 -- The input denotes a reference to an entity. Determine whether the
20524 -- entity or its type yields a null or non-null value.
20526 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
20527 return Null_Status_Of_Entity (Entity (N));
20530 -- Otherwise it is not possible to determine the null status of the
20531 -- subexpression at compile time without resorting to simple flow
20537 --------------------------------------
20538 -- Null_To_Null_Address_Convert_OK --
20539 --------------------------------------
20541 function Null_To_Null_Address_Convert_OK
20543 Typ : Entity_Id := Empty) return Boolean
20546 if not Relaxed_RM_Semantics then
20550 if Nkind (N) = N_Null then
20551 return Present (Typ) and then Is_Descendant_Of_Address (Typ);
20553 elsif Nkind_In (N, N_Op_Eq, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt, N_Op_Ne)
20556 L : constant Node_Id := Left_Opnd (N);
20557 R : constant Node_Id := Right_Opnd (N);
20560 -- We check the Etype of the complementary operand since the
20561 -- N_Null node is not decorated at this stage.
20564 ((Nkind (L) = N_Null
20565 and then Is_Descendant_Of_Address (Etype (R)))
20567 (Nkind (R) = N_Null
20568 and then Is_Descendant_Of_Address (Etype (L))));
20573 end Null_To_Null_Address_Convert_OK;
20575 ---------------------------------
20576 -- Number_Of_Elements_In_Array --
20577 ---------------------------------
20579 function Number_Of_Elements_In_Array (T : Entity_Id) return Int is
20587 pragma Assert (Is_Array_Type (T));
20589 Indx := First_Index (T);
20590 while Present (Indx) loop
20591 Typ := Underlying_Type (Etype (Indx));
20593 -- Never look at junk bounds of a generic type
20595 if Is_Generic_Type (Typ) then
20599 -- Check the array bounds are known at compile time and return zero
20600 -- if they are not.
20602 Low := Type_Low_Bound (Typ);
20603 High := Type_High_Bound (Typ);
20605 if not Compile_Time_Known_Value (Low) then
20607 elsif not Compile_Time_Known_Value (High) then
20611 Num * UI_To_Int ((Expr_Value (High) - Expr_Value (Low) + 1));
20618 end Number_Of_Elements_In_Array;
20620 -------------------------
20621 -- Object_Access_Level --
20622 -------------------------
20624 -- Returns the static accessibility level of the view denoted by Obj. Note
20625 -- that the value returned is the result of a call to Scope_Depth. Only
20626 -- scope depths associated with dynamic scopes can actually be returned.
20627 -- Since only relative levels matter for accessibility checking, the fact
20628 -- that the distance between successive levels of accessibility is not
20629 -- always one is immaterial (invariant: if level(E2) is deeper than
20630 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
20632 function Object_Access_Level (Obj : Node_Id) return Uint is
20633 function Is_Interface_Conversion (N : Node_Id) return Boolean;
20634 -- Determine whether N is a construct of the form
20635 -- Some_Type (Operand._tag'Address)
20636 -- This construct appears in the context of dispatching calls.
20638 function Reference_To (Obj : Node_Id) return Node_Id;
20639 -- An explicit dereference is created when removing side effects from
20640 -- expressions for constraint checking purposes. In this case a local
20641 -- access type is created for it. The correct access level is that of
20642 -- the original source node. We detect this case by noting that the
20643 -- prefix of the dereference is created by an object declaration whose
20644 -- initial expression is a reference.
20646 -----------------------------
20647 -- Is_Interface_Conversion --
20648 -----------------------------
20650 function Is_Interface_Conversion (N : Node_Id) return Boolean is
20652 return Nkind (N) = N_Unchecked_Type_Conversion
20653 and then Nkind (Expression (N)) = N_Attribute_Reference
20654 and then Attribute_Name (Expression (N)) = Name_Address;
20655 end Is_Interface_Conversion;
20661 function Reference_To (Obj : Node_Id) return Node_Id is
20662 Pref : constant Node_Id := Prefix (Obj);
20664 if Is_Entity_Name (Pref)
20665 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
20666 and then Present (Expression (Parent (Entity (Pref))))
20667 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
20669 return (Prefix (Expression (Parent (Entity (Pref)))));
20679 -- Start of processing for Object_Access_Level
20682 if Nkind (Obj) = N_Defining_Identifier
20683 or else Is_Entity_Name (Obj)
20685 if Nkind (Obj) = N_Defining_Identifier then
20691 if Is_Prival (E) then
20692 E := Prival_Link (E);
20695 -- If E is a type then it denotes a current instance. For this case
20696 -- we add one to the normal accessibility level of the type to ensure
20697 -- that current instances are treated as always being deeper than
20698 -- than the level of any visible named access type (see 3.10.2(21)).
20700 if Is_Type (E) then
20701 return Type_Access_Level (E) + 1;
20703 elsif Present (Renamed_Object (E)) then
20704 return Object_Access_Level (Renamed_Object (E));
20706 -- Similarly, if E is a component of the current instance of a
20707 -- protected type, any instance of it is assumed to be at a deeper
20708 -- level than the type. For a protected object (whose type is an
20709 -- anonymous protected type) its components are at the same level
20710 -- as the type itself.
20712 elsif not Is_Overloadable (E)
20713 and then Ekind (Scope (E)) = E_Protected_Type
20714 and then Comes_From_Source (Scope (E))
20716 return Type_Access_Level (Scope (E)) + 1;
20719 -- Aliased formals of functions take their access level from the
20720 -- point of call, i.e. require a dynamic check. For static check
20721 -- purposes, this is smaller than the level of the subprogram
20722 -- itself. For procedures the aliased makes no difference.
20725 and then Is_Aliased (E)
20726 and then Ekind (Scope (E)) = E_Function
20728 return Type_Access_Level (Etype (E));
20731 return Scope_Depth (Enclosing_Dynamic_Scope (E));
20735 elsif Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
20736 if Is_Access_Type (Etype (Prefix (Obj))) then
20737 return Type_Access_Level (Etype (Prefix (Obj)));
20739 return Object_Access_Level (Prefix (Obj));
20742 elsif Nkind (Obj) = N_Explicit_Dereference then
20744 -- If the prefix is a selected access discriminant then we make a
20745 -- recursive call on the prefix, which will in turn check the level
20746 -- of the prefix object of the selected discriminant.
20748 -- In Ada 2012, if the discriminant has implicit dereference and
20749 -- the context is a selected component, treat this as an object of
20750 -- unknown scope (see below). This is necessary in compile-only mode;
20751 -- otherwise expansion will already have transformed the prefix into
20754 if Nkind (Prefix (Obj)) = N_Selected_Component
20755 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
20757 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
20759 (not Has_Implicit_Dereference
20760 (Entity (Selector_Name (Prefix (Obj))))
20761 or else Nkind (Parent (Obj)) /= N_Selected_Component)
20763 return Object_Access_Level (Prefix (Obj));
20765 -- Detect an interface conversion in the context of a dispatching
20766 -- call. Use the original form of the conversion to find the access
20767 -- level of the operand.
20769 elsif Is_Interface (Etype (Obj))
20770 and then Is_Interface_Conversion (Prefix (Obj))
20771 and then Nkind (Original_Node (Obj)) = N_Type_Conversion
20773 return Object_Access_Level (Original_Node (Obj));
20775 elsif not Comes_From_Source (Obj) then
20777 Ref : constant Node_Id := Reference_To (Obj);
20779 if Present (Ref) then
20780 return Object_Access_Level (Ref);
20782 return Type_Access_Level (Etype (Prefix (Obj)));
20787 return Type_Access_Level (Etype (Prefix (Obj)));
20790 elsif Nkind_In (Obj, N_Type_Conversion, N_Unchecked_Type_Conversion) then
20791 return Object_Access_Level (Expression (Obj));
20793 elsif Nkind (Obj) = N_Function_Call then
20795 -- Function results are objects, so we get either the access level of
20796 -- the function or, in the case of an indirect call, the level of the
20797 -- access-to-subprogram type. (This code is used for Ada 95, but it
20798 -- looks wrong, because it seems that we should be checking the level
20799 -- of the call itself, even for Ada 95. However, using the Ada 2005
20800 -- version of the code causes regressions in several tests that are
20801 -- compiled with -gnat95. ???)
20803 if Ada_Version < Ada_2005 then
20804 if Is_Entity_Name (Name (Obj)) then
20805 return Subprogram_Access_Level (Entity (Name (Obj)));
20807 return Type_Access_Level (Etype (Prefix (Name (Obj))));
20810 -- For Ada 2005, the level of the result object of a function call is
20811 -- defined to be the level of the call's innermost enclosing master.
20812 -- We determine that by querying the depth of the innermost enclosing
20816 Return_Master_Scope_Depth_Of_Call : declare
20817 function Innermost_Master_Scope_Depth
20818 (N : Node_Id) return Uint;
20819 -- Returns the scope depth of the given node's innermost
20820 -- enclosing dynamic scope (effectively the accessibility
20821 -- level of the innermost enclosing master).
20823 ----------------------------------
20824 -- Innermost_Master_Scope_Depth --
20825 ----------------------------------
20827 function Innermost_Master_Scope_Depth
20828 (N : Node_Id) return Uint
20830 Node_Par : Node_Id := Parent (N);
20833 -- Locate the nearest enclosing node (by traversing Parents)
20834 -- that Defining_Entity can be applied to, and return the
20835 -- depth of that entity's nearest enclosing dynamic scope.
20837 while Present (Node_Par) loop
20838 case Nkind (Node_Par) is
20839 when N_Abstract_Subprogram_Declaration
20840 | N_Block_Statement
20842 | N_Component_Declaration
20844 | N_Entry_Declaration
20845 | N_Exception_Declaration
20846 | N_Formal_Object_Declaration
20847 | N_Formal_Package_Declaration
20848 | N_Formal_Subprogram_Declaration
20849 | N_Formal_Type_Declaration
20850 | N_Full_Type_Declaration
20851 | N_Function_Specification
20852 | N_Generic_Declaration
20853 | N_Generic_Instantiation
20854 | N_Implicit_Label_Declaration
20855 | N_Incomplete_Type_Declaration
20856 | N_Loop_Parameter_Specification
20857 | N_Number_Declaration
20858 | N_Object_Declaration
20859 | N_Package_Declaration
20860 | N_Package_Specification
20861 | N_Parameter_Specification
20862 | N_Private_Extension_Declaration
20863 | N_Private_Type_Declaration
20864 | N_Procedure_Specification
20866 | N_Protected_Type_Declaration
20867 | N_Renaming_Declaration
20868 | N_Single_Protected_Declaration
20869 | N_Single_Task_Declaration
20870 | N_Subprogram_Declaration
20871 | N_Subtype_Declaration
20873 | N_Task_Type_Declaration
20876 (Nearest_Dynamic_Scope
20877 (Defining_Entity (Node_Par)));
20879 -- For a return statement within a function, return
20880 -- the depth of the function itself. This is not just
20881 -- a small optimization, but matters when analyzing
20882 -- the expression in an expression function before
20883 -- the body is created.
20885 when N_Simple_Return_Statement =>
20886 if Ekind (Current_Scope) = E_Function then
20887 return Scope_Depth (Current_Scope);
20894 Node_Par := Parent (Node_Par);
20897 pragma Assert (False);
20899 -- Should never reach the following return
20901 return Scope_Depth (Current_Scope) + 1;
20902 end Innermost_Master_Scope_Depth;
20904 -- Start of processing for Return_Master_Scope_Depth_Of_Call
20907 return Innermost_Master_Scope_Depth (Obj);
20908 end Return_Master_Scope_Depth_Of_Call;
20911 -- For convenience we handle qualified expressions, even though they
20912 -- aren't technically object names.
20914 elsif Nkind (Obj) = N_Qualified_Expression then
20915 return Object_Access_Level (Expression (Obj));
20917 -- Ditto for aggregates. They have the level of the temporary that
20918 -- will hold their value.
20920 elsif Nkind (Obj) = N_Aggregate then
20921 return Object_Access_Level (Current_Scope);
20923 -- Otherwise return the scope level of Standard. (If there are cases
20924 -- that fall through to this point they will be treated as having
20925 -- global accessibility for now. ???)
20928 return Scope_Depth (Standard_Standard);
20930 end Object_Access_Level;
20932 ----------------------------------
20933 -- Old_Requires_Transient_Scope --
20934 ----------------------------------
20936 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
20937 Typ : constant Entity_Id := Underlying_Type (Id);
20940 -- This is a private type which is not completed yet. This can only
20941 -- happen in a default expression (of a formal parameter or of a
20942 -- record component). Do not expand transient scope in this case.
20947 -- Do not expand transient scope for non-existent procedure return
20949 elsif Typ = Standard_Void_Type then
20952 -- Elementary types do not require a transient scope
20954 elsif Is_Elementary_Type (Typ) then
20957 -- Generally, indefinite subtypes require a transient scope, since the
20958 -- back end cannot generate temporaries, since this is not a valid type
20959 -- for declaring an object. It might be possible to relax this in the
20960 -- future, e.g. by declaring the maximum possible space for the type.
20962 elsif not Is_Definite_Subtype (Typ) then
20965 -- Functions returning tagged types may dispatch on result so their
20966 -- returned value is allocated on the secondary stack. Controlled
20967 -- type temporaries need finalization.
20969 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
20974 elsif Is_Record_Type (Typ) then
20979 Comp := First_Entity (Typ);
20980 while Present (Comp) loop
20981 if Ekind (Comp) = E_Component then
20983 -- ???It's not clear we need a full recursive call to
20984 -- Old_Requires_Transient_Scope here. Note that the
20985 -- following can't happen.
20987 pragma Assert (Is_Definite_Subtype (Etype (Comp)));
20988 pragma Assert (not Has_Controlled_Component (Etype (Comp)));
20990 if Old_Requires_Transient_Scope (Etype (Comp)) then
20995 Next_Entity (Comp);
21001 -- String literal types never require transient scope
21003 elsif Ekind (Typ) = E_String_Literal_Subtype then
21006 -- Array type. Note that we already know that this is a constrained
21007 -- array, since unconstrained arrays will fail the indefinite test.
21009 elsif Is_Array_Type (Typ) then
21011 -- If component type requires a transient scope, the array does too
21013 if Old_Requires_Transient_Scope (Component_Type (Typ)) then
21016 -- Otherwise, we only need a transient scope if the size depends on
21017 -- the value of one or more discriminants.
21020 return Size_Depends_On_Discriminant (Typ);
21023 -- All other cases do not require a transient scope
21026 pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
21029 end Old_Requires_Transient_Scope;
21031 ---------------------------------
21032 -- Original_Aspect_Pragma_Name --
21033 ---------------------------------
21035 function Original_Aspect_Pragma_Name (N : Node_Id) return Name_Id is
21037 Item_Nam : Name_Id;
21040 pragma Assert (Nkind_In (N, N_Aspect_Specification, N_Pragma));
21044 -- The pragma was generated to emulate an aspect, use the original
21045 -- aspect specification.
21047 if Nkind (Item) = N_Pragma and then From_Aspect_Specification (Item) then
21048 Item := Corresponding_Aspect (Item);
21051 -- Retrieve the name of the aspect/pragma. Note that Pre, Pre_Class,
21052 -- Post and Post_Class rewrite their pragma identifier to preserve the
21054 -- ??? this is kludgey
21056 if Nkind (Item) = N_Pragma then
21057 Item_Nam := Chars (Original_Node (Pragma_Identifier (Item)));
21060 pragma Assert (Nkind (Item) = N_Aspect_Specification);
21061 Item_Nam := Chars (Identifier (Item));
21064 -- Deal with 'Class by converting the name to its _XXX form
21066 if Class_Present (Item) then
21067 if Item_Nam = Name_Invariant then
21068 Item_Nam := Name_uInvariant;
21070 elsif Item_Nam = Name_Post then
21071 Item_Nam := Name_uPost;
21073 elsif Item_Nam = Name_Pre then
21074 Item_Nam := Name_uPre;
21076 elsif Nam_In (Item_Nam, Name_Type_Invariant,
21077 Name_Type_Invariant_Class)
21079 Item_Nam := Name_uType_Invariant;
21081 -- Nothing to do for other cases (e.g. a Check that derived from
21082 -- Pre_Class and has the flag set). Also we do nothing if the name
21083 -- is already in special _xxx form.
21089 end Original_Aspect_Pragma_Name;
21091 --------------------------------------
21092 -- Original_Corresponding_Operation --
21093 --------------------------------------
21095 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
21097 Typ : constant Entity_Id := Find_Dispatching_Type (S);
21100 -- If S is an inherited primitive S2 the original corresponding
21101 -- operation of S is the original corresponding operation of S2
21103 if Present (Alias (S))
21104 and then Find_Dispatching_Type (Alias (S)) /= Typ
21106 return Original_Corresponding_Operation (Alias (S));
21108 -- If S overrides an inherited subprogram S2 the original corresponding
21109 -- operation of S is the original corresponding operation of S2
21111 elsif Present (Overridden_Operation (S)) then
21112 return Original_Corresponding_Operation (Overridden_Operation (S));
21114 -- otherwise it is S itself
21119 end Original_Corresponding_Operation;
21121 -------------------
21122 -- Output_Entity --
21123 -------------------
21125 procedure Output_Entity (Id : Entity_Id) is
21129 Scop := Scope (Id);
21131 -- The entity may lack a scope when it is in the process of being
21132 -- analyzed. Use the current scope as an approximation.
21135 Scop := Current_Scope;
21138 Output_Name (Chars (Id), Scop);
21145 procedure Output_Name (Nam : Name_Id; Scop : Entity_Id := Current_Scope) is
21149 (Get_Qualified_Name
21156 ----------------------
21157 -- Policy_In_Effect --
21158 ----------------------
21160 function Policy_In_Effect (Policy : Name_Id) return Name_Id is
21161 function Policy_In_List (List : Node_Id) return Name_Id;
21162 -- Determine the mode of a policy in a N_Pragma list
21164 --------------------
21165 -- Policy_In_List --
21166 --------------------
21168 function Policy_In_List (List : Node_Id) return Name_Id is
21175 while Present (Prag) loop
21176 Arg1 := First (Pragma_Argument_Associations (Prag));
21177 Arg2 := Next (Arg1);
21179 Arg1 := Get_Pragma_Arg (Arg1);
21180 Arg2 := Get_Pragma_Arg (Arg2);
21182 -- The current Check_Policy pragma matches the requested policy or
21183 -- appears in the single argument form (Assertion, policy_id).
21185 if Nam_In (Chars (Arg1), Name_Assertion, Policy) then
21186 return Chars (Arg2);
21189 Prag := Next_Pragma (Prag);
21193 end Policy_In_List;
21199 -- Start of processing for Policy_In_Effect
21202 if not Is_Valid_Assertion_Kind (Policy) then
21203 raise Program_Error;
21206 -- Inspect all policy pragmas that appear within scopes (if any)
21208 Kind := Policy_In_List (Check_Policy_List);
21210 -- Inspect all configuration policy pragmas (if any)
21212 if Kind = No_Name then
21213 Kind := Policy_In_List (Check_Policy_List_Config);
21216 -- The context lacks policy pragmas, determine the mode based on whether
21217 -- assertions are enabled at the configuration level. This ensures that
21218 -- the policy is preserved when analyzing generics.
21220 if Kind = No_Name then
21221 if Assertions_Enabled_Config then
21222 Kind := Name_Check;
21224 Kind := Name_Ignore;
21229 end Policy_In_Effect;
21231 ----------------------------------
21232 -- Predicate_Tests_On_Arguments --
21233 ----------------------------------
21235 function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean is
21237 -- Always test predicates on indirect call
21239 if Ekind (Subp) = E_Subprogram_Type then
21242 -- Do not test predicates on call to generated default Finalize, since
21243 -- we are not interested in whether something we are finalizing (and
21244 -- typically destroying) satisfies its predicates.
21246 elsif Chars (Subp) = Name_Finalize
21247 and then not Comes_From_Source (Subp)
21251 -- Do not test predicates on any internally generated routines
21253 elsif Is_Internal_Name (Chars (Subp)) then
21256 -- Do not test predicates on call to Init_Proc, since if needed the
21257 -- predicate test will occur at some other point.
21259 elsif Is_Init_Proc (Subp) then
21262 -- Do not test predicates on call to predicate function, since this
21263 -- would cause infinite recursion.
21265 elsif Ekind (Subp) = E_Function
21266 and then (Is_Predicate_Function (Subp)
21268 Is_Predicate_Function_M (Subp))
21272 -- For now, no other exceptions
21277 end Predicate_Tests_On_Arguments;
21279 -----------------------
21280 -- Private_Component --
21281 -----------------------
21283 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
21284 Ancestor : constant Entity_Id := Base_Type (Type_Id);
21286 function Trace_Components
21288 Check : Boolean) return Entity_Id;
21289 -- Recursive function that does the work, and checks against circular
21290 -- definition for each subcomponent type.
21292 ----------------------
21293 -- Trace_Components --
21294 ----------------------
21296 function Trace_Components
21298 Check : Boolean) return Entity_Id
21300 Btype : constant Entity_Id := Base_Type (T);
21301 Component : Entity_Id;
21303 Candidate : Entity_Id := Empty;
21306 if Check and then Btype = Ancestor then
21307 Error_Msg_N ("circular type definition", Type_Id);
21311 if Is_Private_Type (Btype) and then not Is_Generic_Type (Btype) then
21312 if Present (Full_View (Btype))
21313 and then Is_Record_Type (Full_View (Btype))
21314 and then not Is_Frozen (Btype)
21316 -- To indicate that the ancestor depends on a private type, the
21317 -- current Btype is sufficient. However, to check for circular
21318 -- definition we must recurse on the full view.
21320 Candidate := Trace_Components (Full_View (Btype), True);
21322 if Candidate = Any_Type then
21332 elsif Is_Array_Type (Btype) then
21333 return Trace_Components (Component_Type (Btype), True);
21335 elsif Is_Record_Type (Btype) then
21336 Component := First_Entity (Btype);
21337 while Present (Component)
21338 and then Comes_From_Source (Component)
21340 -- Skip anonymous types generated by constrained components
21342 if not Is_Type (Component) then
21343 P := Trace_Components (Etype (Component), True);
21345 if Present (P) then
21346 if P = Any_Type then
21354 Next_Entity (Component);
21362 end Trace_Components;
21364 -- Start of processing for Private_Component
21367 return Trace_Components (Type_Id, False);
21368 end Private_Component;
21370 ---------------------------
21371 -- Primitive_Names_Match --
21372 ---------------------------
21374 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
21375 function Non_Internal_Name (E : Entity_Id) return Name_Id;
21376 -- Given an internal name, returns the corresponding non-internal name
21378 ------------------------
21379 -- Non_Internal_Name --
21380 ------------------------
21382 function Non_Internal_Name (E : Entity_Id) return Name_Id is
21384 Get_Name_String (Chars (E));
21385 Name_Len := Name_Len - 1;
21387 end Non_Internal_Name;
21389 -- Start of processing for Primitive_Names_Match
21392 pragma Assert (Present (E1) and then Present (E2));
21394 return Chars (E1) = Chars (E2)
21396 (not Is_Internal_Name (Chars (E1))
21397 and then Is_Internal_Name (Chars (E2))
21398 and then Non_Internal_Name (E2) = Chars (E1))
21400 (not Is_Internal_Name (Chars (E2))
21401 and then Is_Internal_Name (Chars (E1))
21402 and then Non_Internal_Name (E1) = Chars (E2))
21404 (Is_Predefined_Dispatching_Operation (E1)
21405 and then Is_Predefined_Dispatching_Operation (E2)
21406 and then Same_TSS (E1, E2))
21408 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
21409 end Primitive_Names_Match;
21411 -----------------------
21412 -- Process_End_Label --
21413 -----------------------
21415 procedure Process_End_Label
21424 Label_Ref : Boolean;
21425 -- Set True if reference to end label itself is required
21428 -- Gets set to the operator symbol or identifier that references the
21429 -- entity Ent. For the child unit case, this is the identifier from the
21430 -- designator. For other cases, this is simply Endl.
21432 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
21433 -- N is an identifier node that appears as a parent unit reference in
21434 -- the case where Ent is a child unit. This procedure generates an
21435 -- appropriate cross-reference entry. E is the corresponding entity.
21437 -------------------------
21438 -- Generate_Parent_Ref --
21439 -------------------------
21441 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
21443 -- If names do not match, something weird, skip reference
21445 if Chars (E) = Chars (N) then
21447 -- Generate the reference. We do NOT consider this as a reference
21448 -- for unreferenced symbol purposes.
21450 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
21452 if Style_Check then
21453 Style.Check_Identifier (N, E);
21456 end Generate_Parent_Ref;
21458 -- Start of processing for Process_End_Label
21461 -- If no node, ignore. This happens in some error situations, and
21462 -- also for some internally generated structures where no end label
21463 -- references are required in any case.
21469 -- Nothing to do if no End_Label, happens for internally generated
21470 -- constructs where we don't want an end label reference anyway. Also
21471 -- nothing to do if Endl is a string literal, which means there was
21472 -- some prior error (bad operator symbol)
21474 Endl := End_Label (N);
21476 if No (Endl) or else Nkind (Endl) = N_String_Literal then
21480 -- Reference node is not in extended main source unit
21482 if not In_Extended_Main_Source_Unit (N) then
21484 -- Generally we do not collect references except for the extended
21485 -- main source unit. The one exception is the 'e' entry for a
21486 -- package spec, where it is useful for a client to have the
21487 -- ending information to define scopes.
21493 Label_Ref := False;
21495 -- For this case, we can ignore any parent references, but we
21496 -- need the package name itself for the 'e' entry.
21498 if Nkind (Endl) = N_Designator then
21499 Endl := Identifier (Endl);
21503 -- Reference is in extended main source unit
21508 -- For designator, generate references for the parent entries
21510 if Nkind (Endl) = N_Designator then
21512 -- Generate references for the prefix if the END line comes from
21513 -- source (otherwise we do not need these references) We climb the
21514 -- scope stack to find the expected entities.
21516 if Comes_From_Source (Endl) then
21517 Nam := Name (Endl);
21518 Scop := Current_Scope;
21519 while Nkind (Nam) = N_Selected_Component loop
21520 Scop := Scope (Scop);
21521 exit when No (Scop);
21522 Generate_Parent_Ref (Selector_Name (Nam), Scop);
21523 Nam := Prefix (Nam);
21526 if Present (Scop) then
21527 Generate_Parent_Ref (Nam, Scope (Scop));
21531 Endl := Identifier (Endl);
21535 -- If the end label is not for the given entity, then either we have
21536 -- some previous error, or this is a generic instantiation for which
21537 -- we do not need to make a cross-reference in this case anyway. In
21538 -- either case we simply ignore the call.
21540 if Chars (Ent) /= Chars (Endl) then
21544 -- If label was really there, then generate a normal reference and then
21545 -- adjust the location in the end label to point past the name (which
21546 -- should almost always be the semicolon).
21548 Loc := Sloc (Endl);
21550 if Comes_From_Source (Endl) then
21552 -- If a label reference is required, then do the style check and
21553 -- generate an l-type cross-reference entry for the label
21556 if Style_Check then
21557 Style.Check_Identifier (Endl, Ent);
21560 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
21563 -- Set the location to point past the label (normally this will
21564 -- mean the semicolon immediately following the label). This is
21565 -- done for the sake of the 'e' or 't' entry generated below.
21567 Get_Decoded_Name_String (Chars (Endl));
21568 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
21571 -- In SPARK mode, no missing label is allowed for packages and
21572 -- subprogram bodies. Detect those cases by testing whether
21573 -- Process_End_Label was called for a body (Typ = 't') or a package.
21575 if Restriction_Check_Required (SPARK_05)
21576 and then (Typ = 't' or else Ekind (Ent) = E_Package)
21578 Error_Msg_Node_1 := Endl;
21579 Check_SPARK_05_Restriction
21580 ("`END &` required", Endl, Force => True);
21584 -- Now generate the e/t reference
21586 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
21588 -- Restore Sloc, in case modified above, since we have an identifier
21589 -- and the normal Sloc should be left set in the tree.
21591 Set_Sloc (Endl, Loc);
21592 end Process_End_Label;
21594 --------------------------------
21595 -- Propagate_Concurrent_Flags --
21596 --------------------------------
21598 procedure Propagate_Concurrent_Flags
21600 Comp_Typ : Entity_Id)
21603 if Has_Task (Comp_Typ) then
21604 Set_Has_Task (Typ);
21607 if Has_Protected (Comp_Typ) then
21608 Set_Has_Protected (Typ);
21611 if Has_Timing_Event (Comp_Typ) then
21612 Set_Has_Timing_Event (Typ);
21614 end Propagate_Concurrent_Flags;
21616 ------------------------------
21617 -- Propagate_DIC_Attributes --
21618 ------------------------------
21620 procedure Propagate_DIC_Attributes
21622 From_Typ : Entity_Id)
21624 DIC_Proc : Entity_Id;
21627 if Present (Typ) and then Present (From_Typ) then
21628 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
21630 -- Nothing to do if both the source and the destination denote the
21633 if From_Typ = Typ then
21637 DIC_Proc := DIC_Procedure (From_Typ);
21639 -- The setting of the attributes is intentionally conservative. This
21640 -- prevents accidental clobbering of enabled attributes.
21642 if Has_Inherited_DIC (From_Typ)
21643 and then not Has_Inherited_DIC (Typ)
21645 Set_Has_Inherited_DIC (Typ);
21648 if Has_Own_DIC (From_Typ) and then not Has_Own_DIC (Typ) then
21649 Set_Has_Own_DIC (Typ);
21652 if Present (DIC_Proc) and then No (DIC_Procedure (Typ)) then
21653 Set_DIC_Procedure (Typ, DIC_Proc);
21656 end Propagate_DIC_Attributes;
21658 ------------------------------------
21659 -- Propagate_Invariant_Attributes --
21660 ------------------------------------
21662 procedure Propagate_Invariant_Attributes
21664 From_Typ : Entity_Id)
21666 Full_IP : Entity_Id;
21667 Part_IP : Entity_Id;
21670 if Present (Typ) and then Present (From_Typ) then
21671 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
21673 -- Nothing to do if both the source and the destination denote the
21676 if From_Typ = Typ then
21680 Full_IP := Invariant_Procedure (From_Typ);
21681 Part_IP := Partial_Invariant_Procedure (From_Typ);
21683 -- The setting of the attributes is intentionally conservative. This
21684 -- prevents accidental clobbering of enabled attributes.
21686 if Has_Inheritable_Invariants (From_Typ)
21687 and then not Has_Inheritable_Invariants (Typ)
21689 Set_Has_Inheritable_Invariants (Typ, True);
21692 if Has_Inherited_Invariants (From_Typ)
21693 and then not Has_Inherited_Invariants (Typ)
21695 Set_Has_Inherited_Invariants (Typ, True);
21698 if Has_Own_Invariants (From_Typ)
21699 and then not Has_Own_Invariants (Typ)
21701 Set_Has_Own_Invariants (Typ, True);
21704 if Present (Full_IP) and then No (Invariant_Procedure (Typ)) then
21705 Set_Invariant_Procedure (Typ, Full_IP);
21708 if Present (Part_IP) and then No (Partial_Invariant_Procedure (Typ))
21710 Set_Partial_Invariant_Procedure (Typ, Part_IP);
21713 end Propagate_Invariant_Attributes;
21715 ---------------------------------------
21716 -- Record_Possible_Part_Of_Reference --
21717 ---------------------------------------
21719 procedure Record_Possible_Part_Of_Reference
21720 (Var_Id : Entity_Id;
21723 Encap : constant Entity_Id := Encapsulating_State (Var_Id);
21727 -- The variable is a constituent of a single protected/task type. Such
21728 -- a variable acts as a component of the type and must appear within a
21729 -- specific region (SPARK RM 9.3). Instead of recording the reference,
21730 -- verify its legality now.
21732 if Present (Encap) and then Is_Single_Concurrent_Object (Encap) then
21733 Check_Part_Of_Reference (Var_Id, Ref);
21735 -- The variable is subject to pragma Part_Of and may eventually become a
21736 -- constituent of a single protected/task type. Record the reference to
21737 -- verify its placement when the contract of the variable is analyzed.
21739 elsif Present (Get_Pragma (Var_Id, Pragma_Part_Of)) then
21740 Refs := Part_Of_References (Var_Id);
21743 Refs := New_Elmt_List;
21744 Set_Part_Of_References (Var_Id, Refs);
21747 Append_Elmt (Ref, Refs);
21749 end Record_Possible_Part_Of_Reference;
21755 function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
21756 Seen : Boolean := False;
21758 function Is_Reference (N : Node_Id) return Traverse_Result;
21759 -- Determine whether node N denotes a reference to Id. If this is the
21760 -- case, set global flag Seen to True and stop the traversal.
21766 function Is_Reference (N : Node_Id) return Traverse_Result is
21768 if Is_Entity_Name (N)
21769 and then Present (Entity (N))
21770 and then Entity (N) = Id
21779 procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
21781 -- Start of processing for Referenced
21784 Inspect_Expression (Expr);
21788 ------------------------------------
21789 -- References_Generic_Formal_Type --
21790 ------------------------------------
21792 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
21794 function Process (N : Node_Id) return Traverse_Result;
21795 -- Process one node in search for generic formal type
21801 function Process (N : Node_Id) return Traverse_Result is
21803 if Nkind (N) in N_Has_Entity then
21805 E : constant Entity_Id := Entity (N);
21807 if Present (E) then
21808 if Is_Generic_Type (E) then
21810 elsif Present (Etype (E))
21811 and then Is_Generic_Type (Etype (E))
21822 function Traverse is new Traverse_Func (Process);
21823 -- Traverse tree to look for generic type
21826 if Inside_A_Generic then
21827 return Traverse (N) = Abandon;
21831 end References_Generic_Formal_Type;
21833 -------------------
21834 -- Remove_Entity --
21835 -------------------
21837 procedure Remove_Entity (Id : Entity_Id) is
21838 Scop : constant Entity_Id := Scope (Id);
21839 Prev_Id : Entity_Id;
21842 -- Remove the entity from the homonym chain. When the entity is the
21843 -- head of the chain, associate the entry in the name table with its
21844 -- homonym effectively making it the new head of the chain.
21846 if Current_Entity (Id) = Id then
21847 Set_Name_Entity_Id (Chars (Id), Homonym (Id));
21849 -- Otherwise link the previous and next homonyms
21852 Prev_Id := Current_Entity (Id);
21853 while Present (Prev_Id) and then Homonym (Prev_Id) /= Id loop
21854 Prev_Id := Homonym (Prev_Id);
21857 Set_Homonym (Prev_Id, Homonym (Id));
21860 -- Remove the entity from the scope entity chain. When the entity is
21861 -- the head of the chain, set the next entity as the new head of the
21864 if First_Entity (Scop) = Id then
21866 Set_First_Entity (Scop, Next_Entity (Id));
21868 -- Otherwise the entity is either in the middle of the chain or it acts
21869 -- as its tail. Traverse and link the previous and next entities.
21872 Prev_Id := First_Entity (Scop);
21873 while Present (Prev_Id) and then Next_Entity (Prev_Id) /= Id loop
21874 Next_Entity (Prev_Id);
21877 Set_Next_Entity (Prev_Id, Next_Entity (Id));
21880 -- Handle the case where the entity acts as the tail of the scope entity
21883 if Last_Entity (Scop) = Id then
21884 Set_Last_Entity (Scop, Prev_Id);
21888 --------------------
21889 -- Remove_Homonym --
21890 --------------------
21892 procedure Remove_Homonym (E : Entity_Id) is
21893 Prev : Entity_Id := Empty;
21897 if E = Current_Entity (E) then
21898 if Present (Homonym (E)) then
21899 Set_Current_Entity (Homonym (E));
21901 Set_Name_Entity_Id (Chars (E), Empty);
21905 H := Current_Entity (E);
21906 while Present (H) and then H /= E loop
21911 -- If E is not on the homonym chain, nothing to do
21913 if Present (H) then
21914 Set_Homonym (Prev, Homonym (E));
21917 end Remove_Homonym;
21919 ------------------------------
21920 -- Remove_Overloaded_Entity --
21921 ------------------------------
21923 procedure Remove_Overloaded_Entity (Id : Entity_Id) is
21924 procedure Remove_Primitive_Of (Typ : Entity_Id);
21925 -- Remove primitive subprogram Id from the list of primitives that
21926 -- belong to type Typ.
21928 -------------------------
21929 -- Remove_Primitive_Of --
21930 -------------------------
21932 procedure Remove_Primitive_Of (Typ : Entity_Id) is
21936 if Is_Tagged_Type (Typ) then
21937 Prims := Direct_Primitive_Operations (Typ);
21939 if Present (Prims) then
21940 Remove (Prims, Id);
21943 end Remove_Primitive_Of;
21947 Formal : Entity_Id;
21949 -- Start of processing for Remove_Overloaded_Entity
21952 -- Remove the entity from both the homonym and scope chains
21954 Remove_Entity (Id);
21956 -- The entity denotes a primitive subprogram. Remove it from the list of
21957 -- primitives of the associated controlling type.
21959 if Ekind_In (Id, E_Function, E_Procedure) and then Is_Primitive (Id) then
21960 Formal := First_Formal (Id);
21961 while Present (Formal) loop
21962 if Is_Controlling_Formal (Formal) then
21963 Remove_Primitive_Of (Etype (Formal));
21967 Next_Formal (Formal);
21970 if Ekind (Id) = E_Function and then Has_Controlling_Result (Id) then
21971 Remove_Primitive_Of (Etype (Id));
21974 end Remove_Overloaded_Entity;
21976 ---------------------
21977 -- Rep_To_Pos_Flag --
21978 ---------------------
21980 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
21982 return New_Occurrence_Of
21983 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
21984 end Rep_To_Pos_Flag;
21986 --------------------
21987 -- Require_Entity --
21988 --------------------
21990 procedure Require_Entity (N : Node_Id) is
21992 if Is_Entity_Name (N) and then No (Entity (N)) then
21993 if Total_Errors_Detected /= 0 then
21994 Set_Entity (N, Any_Id);
21996 raise Program_Error;
21999 end Require_Entity;
22001 ------------------------------
22002 -- Requires_Transient_Scope --
22003 ------------------------------
22005 -- A transient scope is required when variable-sized temporaries are
22006 -- allocated on the secondary stack, or when finalization actions must be
22007 -- generated before the next instruction.
22009 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
22010 Old_Result : constant Boolean := Old_Requires_Transient_Scope (Id);
22013 if Debug_Flag_QQ then
22018 New_Result : constant Boolean := New_Requires_Transient_Scope (Id);
22021 -- Assert that we're not putting things on the secondary stack if we
22022 -- didn't before; we are trying to AVOID secondary stack when
22025 if not Old_Result then
22026 pragma Assert (not New_Result);
22030 if New_Result /= Old_Result then
22031 Results_Differ (Id, Old_Result, New_Result);
22036 end Requires_Transient_Scope;
22038 --------------------
22039 -- Results_Differ --
22040 --------------------
22042 procedure Results_Differ
22048 if False then -- False to disable; True for debugging
22049 Treepr.Print_Tree_Node (Id);
22051 if Old_Val = New_Val then
22052 raise Program_Error;
22055 end Results_Differ;
22057 --------------------------
22058 -- Reset_Analyzed_Flags --
22059 --------------------------
22061 procedure Reset_Analyzed_Flags (N : Node_Id) is
22062 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
22063 -- Function used to reset Analyzed flags in tree. Note that we do
22064 -- not reset Analyzed flags in entities, since there is no need to
22065 -- reanalyze entities, and indeed, it is wrong to do so, since it
22066 -- can result in generating auxiliary stuff more than once.
22068 --------------------
22069 -- Clear_Analyzed --
22070 --------------------
22072 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
22074 if Nkind (N) not in N_Entity then
22075 Set_Analyzed (N, False);
22079 end Clear_Analyzed;
22081 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
22083 -- Start of processing for Reset_Analyzed_Flags
22086 Reset_Analyzed (N);
22087 end Reset_Analyzed_Flags;
22089 ------------------------
22090 -- Restore_SPARK_Mode --
22091 ------------------------
22093 procedure Restore_SPARK_Mode
22094 (Mode : SPARK_Mode_Type;
22098 SPARK_Mode := Mode;
22099 SPARK_Mode_Pragma := Prag;
22100 end Restore_SPARK_Mode;
22102 --------------------------------
22103 -- Returns_Unconstrained_Type --
22104 --------------------------------
22106 function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
22108 return Ekind (Subp) = E_Function
22109 and then not Is_Scalar_Type (Etype (Subp))
22110 and then not Is_Access_Type (Etype (Subp))
22111 and then not Is_Constrained (Etype (Subp));
22112 end Returns_Unconstrained_Type;
22114 ----------------------------
22115 -- Root_Type_Of_Full_View --
22116 ----------------------------
22118 function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id is
22119 Rtyp : constant Entity_Id := Root_Type (T);
22122 -- The root type of the full view may itself be a private type. Keep
22123 -- looking for the ultimate derivation parent.
22125 if Is_Private_Type (Rtyp) and then Present (Full_View (Rtyp)) then
22126 return Root_Type_Of_Full_View (Full_View (Rtyp));
22130 end Root_Type_Of_Full_View;
22132 ---------------------------
22133 -- Safe_To_Capture_Value --
22134 ---------------------------
22136 function Safe_To_Capture_Value
22139 Cond : Boolean := False) return Boolean
22142 -- The only entities for which we track constant values are variables
22143 -- which are not renamings, constants, out parameters, and in out
22144 -- parameters, so check if we have this case.
22146 -- Note: it may seem odd to track constant values for constants, but in
22147 -- fact this routine is used for other purposes than simply capturing
22148 -- the value. In particular, the setting of Known[_Non]_Null.
22150 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
22152 Ekind_In (Ent, E_Constant, E_Out_Parameter, E_In_Out_Parameter)
22156 -- For conditionals, we also allow loop parameters and all formals,
22157 -- including in parameters.
22159 elsif Cond and then Ekind_In (Ent, E_Loop_Parameter, E_In_Parameter) then
22162 -- For all other cases, not just unsafe, but impossible to capture
22163 -- Current_Value, since the above are the only entities which have
22164 -- Current_Value fields.
22170 -- Skip if volatile or aliased, since funny things might be going on in
22171 -- these cases which we cannot necessarily track. Also skip any variable
22172 -- for which an address clause is given, or whose address is taken. Also
22173 -- never capture value of library level variables (an attempt to do so
22174 -- can occur in the case of package elaboration code).
22176 if Treat_As_Volatile (Ent)
22177 or else Is_Aliased (Ent)
22178 or else Present (Address_Clause (Ent))
22179 or else Address_Taken (Ent)
22180 or else (Is_Library_Level_Entity (Ent)
22181 and then Ekind (Ent) = E_Variable)
22186 -- OK, all above conditions are met. We also require that the scope of
22187 -- the reference be the same as the scope of the entity, not counting
22188 -- packages and blocks and loops.
22191 E_Scope : constant Entity_Id := Scope (Ent);
22192 R_Scope : Entity_Id;
22195 R_Scope := Current_Scope;
22196 while R_Scope /= Standard_Standard loop
22197 exit when R_Scope = E_Scope;
22199 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
22202 R_Scope := Scope (R_Scope);
22207 -- We also require that the reference does not appear in a context
22208 -- where it is not sure to be executed (i.e. a conditional context
22209 -- or an exception handler). We skip this if Cond is True, since the
22210 -- capturing of values from conditional tests handles this ok.
22223 -- Seems dubious that case expressions are not handled here ???
22226 while Present (P) loop
22227 if Nkind (P) = N_If_Statement
22228 or else Nkind (P) = N_Case_Statement
22229 or else (Nkind (P) in N_Short_Circuit
22230 and then Desc = Right_Opnd (P))
22231 or else (Nkind (P) = N_If_Expression
22232 and then Desc /= First (Expressions (P)))
22233 or else Nkind (P) = N_Exception_Handler
22234 or else Nkind (P) = N_Selective_Accept
22235 or else Nkind (P) = N_Conditional_Entry_Call
22236 or else Nkind (P) = N_Timed_Entry_Call
22237 or else Nkind (P) = N_Asynchronous_Select
22245 -- A special Ada 2012 case: the original node may be part
22246 -- of the else_actions of a conditional expression, in which
22247 -- case it might not have been expanded yet, and appears in
22248 -- a non-syntactic list of actions. In that case it is clearly
22249 -- not safe to save a value.
22252 and then Is_List_Member (Desc)
22253 and then No (Parent (List_Containing (Desc)))
22261 -- OK, looks safe to set value
22264 end Safe_To_Capture_Value;
22270 function Same_Name (N1, N2 : Node_Id) return Boolean is
22271 K1 : constant Node_Kind := Nkind (N1);
22272 K2 : constant Node_Kind := Nkind (N2);
22275 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
22276 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
22278 return Chars (N1) = Chars (N2);
22280 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
22281 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
22283 return Same_Name (Selector_Name (N1), Selector_Name (N2))
22284 and then Same_Name (Prefix (N1), Prefix (N2));
22295 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
22296 N1 : constant Node_Id := Original_Node (Node1);
22297 N2 : constant Node_Id := Original_Node (Node2);
22298 -- We do the tests on original nodes, since we are most interested
22299 -- in the original source, not any expansion that got in the way.
22301 K1 : constant Node_Kind := Nkind (N1);
22302 K2 : constant Node_Kind := Nkind (N2);
22305 -- First case, both are entities with same entity
22307 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
22309 EN1 : constant Entity_Id := Entity (N1);
22310 EN2 : constant Entity_Id := Entity (N2);
22312 if Present (EN1) and then Present (EN2)
22313 and then (Ekind_In (EN1, E_Variable, E_Constant)
22314 or else Is_Formal (EN1))
22322 -- Second case, selected component with same selector, same record
22324 if K1 = N_Selected_Component
22325 and then K2 = N_Selected_Component
22326 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
22328 return Same_Object (Prefix (N1), Prefix (N2));
22330 -- Third case, indexed component with same subscripts, same array
22332 elsif K1 = N_Indexed_Component
22333 and then K2 = N_Indexed_Component
22334 and then Same_Object (Prefix (N1), Prefix (N2))
22339 E1 := First (Expressions (N1));
22340 E2 := First (Expressions (N2));
22341 while Present (E1) loop
22342 if not Same_Value (E1, E2) then
22353 -- Fourth case, slice of same array with same bounds
22356 and then K2 = N_Slice
22357 and then Nkind (Discrete_Range (N1)) = N_Range
22358 and then Nkind (Discrete_Range (N2)) = N_Range
22359 and then Same_Value (Low_Bound (Discrete_Range (N1)),
22360 Low_Bound (Discrete_Range (N2)))
22361 and then Same_Value (High_Bound (Discrete_Range (N1)),
22362 High_Bound (Discrete_Range (N2)))
22364 return Same_Name (Prefix (N1), Prefix (N2));
22366 -- All other cases, not clearly the same object
22377 function Same_Type (T1, T2 : Entity_Id) return Boolean is
22382 elsif not Is_Constrained (T1)
22383 and then not Is_Constrained (T2)
22384 and then Base_Type (T1) = Base_Type (T2)
22388 -- For now don't bother with case of identical constraints, to be
22389 -- fiddled with later on perhaps (this is only used for optimization
22390 -- purposes, so it is not critical to do a best possible job)
22401 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
22403 if Compile_Time_Known_Value (Node1)
22404 and then Compile_Time_Known_Value (Node2)
22406 -- Handle properly compile-time expressions that are not
22409 if Is_String_Type (Etype (Node1)) then
22410 return Expr_Value_S (Node1) = Expr_Value_S (Node2);
22413 return Expr_Value (Node1) = Expr_Value (Node2);
22416 elsif Same_Object (Node1, Node2) then
22423 --------------------
22424 -- Set_SPARK_Mode --
22425 --------------------
22427 procedure Set_SPARK_Mode (Context : Entity_Id) is
22429 -- Do not consider illegal or partially decorated constructs
22431 if Ekind (Context) = E_Void or else Error_Posted (Context) then
22434 elsif Present (SPARK_Pragma (Context)) then
22436 (Mode => Get_SPARK_Mode_From_Annotation (SPARK_Pragma (Context)),
22437 Prag => SPARK_Pragma (Context));
22439 end Set_SPARK_Mode;
22441 -------------------------
22442 -- Scalar_Part_Present --
22443 -------------------------
22445 function Scalar_Part_Present (T : Entity_Id) return Boolean is
22449 if Is_Scalar_Type (T) then
22452 elsif Is_Array_Type (T) then
22453 return Scalar_Part_Present (Component_Type (T));
22455 elsif Is_Record_Type (T) or else Has_Discriminants (T) then
22456 C := First_Component_Or_Discriminant (T);
22457 while Present (C) loop
22458 if Scalar_Part_Present (Etype (C)) then
22461 Next_Component_Or_Discriminant (C);
22467 end Scalar_Part_Present;
22469 ------------------------
22470 -- Scope_Is_Transient --
22471 ------------------------
22473 function Scope_Is_Transient return Boolean is
22475 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
22476 end Scope_Is_Transient;
22482 function Scope_Within
22483 (Inner : Entity_Id;
22484 Outer : Entity_Id) return Boolean
22490 while Present (Curr) and then Curr /= Standard_Standard loop
22491 Curr := Scope (Curr);
22493 if Curr = Outer then
22501 --------------------------
22502 -- Scope_Within_Or_Same --
22503 --------------------------
22505 function Scope_Within_Or_Same
22506 (Inner : Entity_Id;
22507 Outer : Entity_Id) return Boolean
22513 while Present (Curr) and then Curr /= Standard_Standard loop
22514 if Curr = Outer then
22518 Curr := Scope (Curr);
22522 end Scope_Within_Or_Same;
22524 --------------------
22525 -- Set_Convention --
22526 --------------------
22528 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
22530 Basic_Set_Convention (E, Val);
22533 and then Is_Access_Subprogram_Type (Base_Type (E))
22534 and then Has_Foreign_Convention (E)
22537 -- A pragma Convention in an instance may apply to the subtype
22538 -- created for a formal, in which case we have already verified
22539 -- that conventions of actual and formal match and there is nothing
22540 -- to flag on the subtype.
22542 if In_Instance then
22545 Set_Can_Use_Internal_Rep (E, False);
22549 -- If E is an object, including a component, and the type of E is an
22550 -- anonymous access type with no convention set, then also set the
22551 -- convention of the anonymous access type. We do not do this for
22552 -- anonymous protected types, since protected types always have the
22553 -- default convention.
22555 if Present (Etype (E))
22556 and then (Is_Object (E)
22558 -- Allow E_Void (happens for pragma Convention appearing
22559 -- in the middle of a record applying to a component)
22561 or else Ekind (E) = E_Void)
22564 Typ : constant Entity_Id := Etype (E);
22567 if Ekind_In (Typ, E_Anonymous_Access_Type,
22568 E_Anonymous_Access_Subprogram_Type)
22569 and then not Has_Convention_Pragma (Typ)
22571 Basic_Set_Convention (Typ, Val);
22572 Set_Has_Convention_Pragma (Typ);
22574 -- And for the access subprogram type, deal similarly with the
22575 -- designated E_Subprogram_Type, which is always internal.
22577 if Ekind (Typ) = E_Anonymous_Access_Subprogram_Type then
22579 Dtype : constant Entity_Id := Designated_Type (Typ);
22581 if Ekind (Dtype) = E_Subprogram_Type
22582 and then not Has_Convention_Pragma (Dtype)
22584 Basic_Set_Convention (Dtype, Val);
22585 Set_Has_Convention_Pragma (Dtype);
22592 end Set_Convention;
22594 ------------------------
22595 -- Set_Current_Entity --
22596 ------------------------
22598 -- The given entity is to be set as the currently visible definition of its
22599 -- associated name (i.e. the Node_Id associated with its name). All we have
22600 -- to do is to get the name from the identifier, and then set the
22601 -- associated Node_Id to point to the given entity.
22603 procedure Set_Current_Entity (E : Entity_Id) is
22605 Set_Name_Entity_Id (Chars (E), E);
22606 end Set_Current_Entity;
22608 ---------------------------
22609 -- Set_Debug_Info_Needed --
22610 ---------------------------
22612 procedure Set_Debug_Info_Needed (T : Entity_Id) is
22614 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
22615 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
22616 -- Used to set debug info in a related node if not set already
22618 --------------------------------------
22619 -- Set_Debug_Info_Needed_If_Not_Set --
22620 --------------------------------------
22622 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
22624 if Present (E) and then not Needs_Debug_Info (E) then
22625 Set_Debug_Info_Needed (E);
22627 -- For a private type, indicate that the full view also needs
22628 -- debug information.
22631 and then Is_Private_Type (E)
22632 and then Present (Full_View (E))
22634 Set_Debug_Info_Needed (Full_View (E));
22637 end Set_Debug_Info_Needed_If_Not_Set;
22639 -- Start of processing for Set_Debug_Info_Needed
22642 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
22643 -- indicates that Debug_Info_Needed is never required for the entity.
22644 -- Nothing to do if entity comes from a predefined file. Library files
22645 -- are compiled without debug information, but inlined bodies of these
22646 -- routines may appear in user code, and debug information on them ends
22647 -- up complicating debugging the user code.
22650 or else Debug_Info_Off (T)
22654 elsif In_Inlined_Body and then In_Predefined_Unit (T) then
22655 Set_Needs_Debug_Info (T, False);
22658 -- Set flag in entity itself. Note that we will go through the following
22659 -- circuitry even if the flag is already set on T. That's intentional,
22660 -- it makes sure that the flag will be set in subsidiary entities.
22662 Set_Needs_Debug_Info (T);
22664 -- Set flag on subsidiary entities if not set already
22666 if Is_Object (T) then
22667 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
22669 elsif Is_Type (T) then
22670 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
22672 if Is_Record_Type (T) then
22674 Ent : Entity_Id := First_Entity (T);
22676 while Present (Ent) loop
22677 Set_Debug_Info_Needed_If_Not_Set (Ent);
22682 -- For a class wide subtype, we also need debug information
22683 -- for the equivalent type.
22685 if Ekind (T) = E_Class_Wide_Subtype then
22686 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
22689 elsif Is_Array_Type (T) then
22690 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
22693 Indx : Node_Id := First_Index (T);
22695 while Present (Indx) loop
22696 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
22697 Indx := Next_Index (Indx);
22701 -- For a packed array type, we also need debug information for
22702 -- the type used to represent the packed array. Conversely, we
22703 -- also need it for the former if we need it for the latter.
22705 if Is_Packed (T) then
22706 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Impl_Type (T));
22709 if Is_Packed_Array_Impl_Type (T) then
22710 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
22713 elsif Is_Access_Type (T) then
22714 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
22716 elsif Is_Private_Type (T) then
22718 FV : constant Entity_Id := Full_View (T);
22721 Set_Debug_Info_Needed_If_Not_Set (FV);
22723 -- If the full view is itself a derived private type, we need
22724 -- debug information on its underlying type.
22727 and then Is_Private_Type (FV)
22728 and then Present (Underlying_Full_View (FV))
22730 Set_Needs_Debug_Info (Underlying_Full_View (FV));
22734 elsif Is_Protected_Type (T) then
22735 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
22737 elsif Is_Scalar_Type (T) then
22739 -- If the subrange bounds are materialized by dedicated constant
22740 -- objects, also include them in the debug info to make sure the
22741 -- debugger can properly use them.
22743 if Present (Scalar_Range (T))
22744 and then Nkind (Scalar_Range (T)) = N_Range
22747 Low_Bnd : constant Node_Id := Type_Low_Bound (T);
22748 High_Bnd : constant Node_Id := Type_High_Bound (T);
22751 if Is_Entity_Name (Low_Bnd) then
22752 Set_Debug_Info_Needed_If_Not_Set (Entity (Low_Bnd));
22755 if Is_Entity_Name (High_Bnd) then
22756 Set_Debug_Info_Needed_If_Not_Set (Entity (High_Bnd));
22762 end Set_Debug_Info_Needed;
22764 ----------------------------
22765 -- Set_Entity_With_Checks --
22766 ----------------------------
22768 procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id) is
22769 Val_Actual : Entity_Id;
22771 Post_Node : Node_Id;
22774 -- Unconditionally set the entity
22776 Set_Entity (N, Val);
22778 -- The node to post on is the selector in the case of an expanded name,
22779 -- and otherwise the node itself.
22781 if Nkind (N) = N_Expanded_Name then
22782 Post_Node := Selector_Name (N);
22787 -- Check for violation of No_Fixed_IO
22789 if Restriction_Check_Required (No_Fixed_IO)
22791 ((RTU_Loaded (Ada_Text_IO)
22792 and then (Is_RTE (Val, RE_Decimal_IO)
22794 Is_RTE (Val, RE_Fixed_IO)))
22797 (RTU_Loaded (Ada_Wide_Text_IO)
22798 and then (Is_RTE (Val, RO_WT_Decimal_IO)
22800 Is_RTE (Val, RO_WT_Fixed_IO)))
22803 (RTU_Loaded (Ada_Wide_Wide_Text_IO)
22804 and then (Is_RTE (Val, RO_WW_Decimal_IO)
22806 Is_RTE (Val, RO_WW_Fixed_IO))))
22808 -- A special extra check, don't complain about a reference from within
22809 -- the Ada.Interrupts package itself!
22811 and then not In_Same_Extended_Unit (N, Val)
22813 Check_Restriction (No_Fixed_IO, Post_Node);
22816 -- Remaining checks are only done on source nodes. Note that we test
22817 -- for violation of No_Fixed_IO even on non-source nodes, because the
22818 -- cases for checking violations of this restriction are instantiations
22819 -- where the reference in the instance has Comes_From_Source False.
22821 if not Comes_From_Source (N) then
22825 -- Check for violation of No_Abort_Statements, which is triggered by
22826 -- call to Ada.Task_Identification.Abort_Task.
22828 if Restriction_Check_Required (No_Abort_Statements)
22829 and then (Is_RTE (Val, RE_Abort_Task))
22831 -- A special extra check, don't complain about a reference from within
22832 -- the Ada.Task_Identification package itself!
22834 and then not In_Same_Extended_Unit (N, Val)
22836 Check_Restriction (No_Abort_Statements, Post_Node);
22839 if Val = Standard_Long_Long_Integer then
22840 Check_Restriction (No_Long_Long_Integers, Post_Node);
22843 -- Check for violation of No_Dynamic_Attachment
22845 if Restriction_Check_Required (No_Dynamic_Attachment)
22846 and then RTU_Loaded (Ada_Interrupts)
22847 and then (Is_RTE (Val, RE_Is_Reserved) or else
22848 Is_RTE (Val, RE_Is_Attached) or else
22849 Is_RTE (Val, RE_Current_Handler) or else
22850 Is_RTE (Val, RE_Attach_Handler) or else
22851 Is_RTE (Val, RE_Exchange_Handler) or else
22852 Is_RTE (Val, RE_Detach_Handler) or else
22853 Is_RTE (Val, RE_Reference))
22855 -- A special extra check, don't complain about a reference from within
22856 -- the Ada.Interrupts package itself!
22858 and then not In_Same_Extended_Unit (N, Val)
22860 Check_Restriction (No_Dynamic_Attachment, Post_Node);
22863 -- Check for No_Implementation_Identifiers
22865 if Restriction_Check_Required (No_Implementation_Identifiers) then
22867 -- We have an implementation defined entity if it is marked as
22868 -- implementation defined, or is defined in a package marked as
22869 -- implementation defined. However, library packages themselves
22870 -- are excluded (we don't want to flag Interfaces itself, just
22871 -- the entities within it).
22873 if (Is_Implementation_Defined (Val)
22875 (Present (Scope (Val))
22876 and then Is_Implementation_Defined (Scope (Val))))
22877 and then not (Ekind_In (Val, E_Package, E_Generic_Package)
22878 and then Is_Library_Level_Entity (Val))
22880 Check_Restriction (No_Implementation_Identifiers, Post_Node);
22884 -- Do the style check
22887 and then not Suppress_Style_Checks (Val)
22888 and then not In_Instance
22890 if Nkind (N) = N_Identifier then
22892 elsif Nkind (N) = N_Expanded_Name then
22893 Nod := Selector_Name (N);
22898 -- A special situation arises for derived operations, where we want
22899 -- to do the check against the parent (since the Sloc of the derived
22900 -- operation points to the derived type declaration itself).
22903 while not Comes_From_Source (Val_Actual)
22904 and then Nkind (Val_Actual) in N_Entity
22905 and then (Ekind (Val_Actual) = E_Enumeration_Literal
22906 or else Is_Subprogram_Or_Generic_Subprogram (Val_Actual))
22907 and then Present (Alias (Val_Actual))
22909 Val_Actual := Alias (Val_Actual);
22912 -- Renaming declarations for generic actuals do not come from source,
22913 -- and have a different name from that of the entity they rename, so
22914 -- there is no style check to perform here.
22916 if Chars (Nod) = Chars (Val_Actual) then
22917 Style.Check_Identifier (Nod, Val_Actual);
22921 Set_Entity (N, Val);
22922 end Set_Entity_With_Checks;
22924 ------------------------
22925 -- Set_Name_Entity_Id --
22926 ------------------------
22928 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
22930 Set_Name_Table_Int (Id, Int (Val));
22931 end Set_Name_Entity_Id;
22933 ---------------------
22934 -- Set_Next_Actual --
22935 ---------------------
22937 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
22939 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
22940 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
22942 end Set_Next_Actual;
22944 ----------------------------------
22945 -- Set_Optimize_Alignment_Flags --
22946 ----------------------------------
22948 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
22950 if Optimize_Alignment = 'S' then
22951 Set_Optimize_Alignment_Space (E);
22952 elsif Optimize_Alignment = 'T' then
22953 Set_Optimize_Alignment_Time (E);
22955 end Set_Optimize_Alignment_Flags;
22957 -----------------------
22958 -- Set_Public_Status --
22959 -----------------------
22961 procedure Set_Public_Status (Id : Entity_Id) is
22962 S : constant Entity_Id := Current_Scope;
22964 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
22965 -- Determines if E is defined within handled statement sequence or
22966 -- an if statement, returns True if so, False otherwise.
22968 ----------------------
22969 -- Within_HSS_Or_If --
22970 ----------------------
22972 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
22975 N := Declaration_Node (E);
22982 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
22988 end Within_HSS_Or_If;
22990 -- Start of processing for Set_Public_Status
22993 -- Everything in the scope of Standard is public
22995 if S = Standard_Standard then
22996 Set_Is_Public (Id);
22998 -- Entity is definitely not public if enclosing scope is not public
23000 elsif not Is_Public (S) then
23003 -- An object or function declaration that occurs in a handled sequence
23004 -- of statements or within an if statement is the declaration for a
23005 -- temporary object or local subprogram generated by the expander. It
23006 -- never needs to be made public and furthermore, making it public can
23007 -- cause back end problems.
23009 elsif Nkind_In (Parent (Id), N_Object_Declaration,
23010 N_Function_Specification)
23011 and then Within_HSS_Or_If (Id)
23015 -- Entities in public packages or records are public
23017 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
23018 Set_Is_Public (Id);
23020 -- The bounds of an entry family declaration can generate object
23021 -- declarations that are visible to the back-end, e.g. in the
23022 -- the declaration of a composite type that contains tasks.
23024 elsif Is_Concurrent_Type (S)
23025 and then not Has_Completion (S)
23026 and then Nkind (Parent (Id)) = N_Object_Declaration
23028 Set_Is_Public (Id);
23030 end Set_Public_Status;
23032 -----------------------------
23033 -- Set_Referenced_Modified --
23034 -----------------------------
23036 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
23040 -- Deal with indexed or selected component where prefix is modified
23042 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
23043 Pref := Prefix (N);
23045 -- If prefix is access type, then it is the designated object that is
23046 -- being modified, which means we have no entity to set the flag on.
23048 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
23051 -- Otherwise chase the prefix
23054 Set_Referenced_Modified (Pref, Out_Param);
23057 -- Otherwise see if we have an entity name (only other case to process)
23059 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
23060 Set_Referenced_As_LHS (Entity (N), not Out_Param);
23061 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
23063 end Set_Referenced_Modified;
23069 procedure Set_Rep_Info (T1 : Entity_Id; T2 : Entity_Id) is
23071 Set_Is_Atomic (T1, Is_Atomic (T2));
23072 Set_Is_Independent (T1, Is_Independent (T2));
23073 Set_Is_Volatile_Full_Access (T1, Is_Volatile_Full_Access (T2));
23075 if Is_Base_Type (T1) then
23076 Set_Is_Volatile (T1, Is_Volatile (T2));
23080 ----------------------------
23081 -- Set_Scope_Is_Transient --
23082 ----------------------------
23084 procedure Set_Scope_Is_Transient (V : Boolean := True) is
23086 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
23087 end Set_Scope_Is_Transient;
23089 -------------------
23090 -- Set_Size_Info --
23091 -------------------
23093 procedure Set_Size_Info (T1, T2 : Entity_Id) is
23095 -- We copy Esize, but not RM_Size, since in general RM_Size is
23096 -- subtype specific and does not get inherited by all subtypes.
23098 Set_Esize (T1, Esize (T2));
23099 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
23101 if Is_Discrete_Or_Fixed_Point_Type (T1)
23103 Is_Discrete_Or_Fixed_Point_Type (T2)
23105 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
23108 Set_Alignment (T1, Alignment (T2));
23111 ------------------------------
23112 -- Should_Ignore_Pragma_Par --
23113 ------------------------------
23115 function Should_Ignore_Pragma_Par (Prag_Name : Name_Id) return Boolean is
23116 pragma Assert (Compiler_State = Parsing);
23117 -- This one can't work during semantic analysis, because we don't have a
23118 -- correct Current_Source_File.
23120 Result : constant Boolean :=
23121 Get_Name_Table_Boolean3 (Prag_Name)
23122 and then not Is_Internal_File_Name
23123 (File_Name (Current_Source_File));
23126 end Should_Ignore_Pragma_Par;
23128 ------------------------------
23129 -- Should_Ignore_Pragma_Sem --
23130 ------------------------------
23132 function Should_Ignore_Pragma_Sem (N : Node_Id) return Boolean is
23133 pragma Assert (Compiler_State = Analyzing);
23134 Prag_Name : constant Name_Id := Pragma_Name (N);
23135 Result : constant Boolean :=
23136 Get_Name_Table_Boolean3 (Prag_Name)
23137 and then not In_Internal_Unit (N);
23141 end Should_Ignore_Pragma_Sem;
23143 --------------------
23144 -- Static_Boolean --
23145 --------------------
23147 function Static_Boolean (N : Node_Id) return Uint is
23149 Analyze_And_Resolve (N, Standard_Boolean);
23152 or else Error_Posted (N)
23153 or else Etype (N) = Any_Type
23158 if Is_OK_Static_Expression (N) then
23159 if not Raises_Constraint_Error (N) then
23160 return Expr_Value (N);
23165 elsif Etype (N) = Any_Type then
23169 Flag_Non_Static_Expr
23170 ("static boolean expression required here", N);
23173 end Static_Boolean;
23175 --------------------
23176 -- Static_Integer --
23177 --------------------
23179 function Static_Integer (N : Node_Id) return Uint is
23181 Analyze_And_Resolve (N, Any_Integer);
23184 or else Error_Posted (N)
23185 or else Etype (N) = Any_Type
23190 if Is_OK_Static_Expression (N) then
23191 if not Raises_Constraint_Error (N) then
23192 return Expr_Value (N);
23197 elsif Etype (N) = Any_Type then
23201 Flag_Non_Static_Expr
23202 ("static integer expression required here", N);
23205 end Static_Integer;
23207 --------------------------
23208 -- Statically_Different --
23209 --------------------------
23211 function Statically_Different (E1, E2 : Node_Id) return Boolean is
23212 R1 : constant Node_Id := Get_Referenced_Object (E1);
23213 R2 : constant Node_Id := Get_Referenced_Object (E2);
23215 return Is_Entity_Name (R1)
23216 and then Is_Entity_Name (R2)
23217 and then Entity (R1) /= Entity (R2)
23218 and then not Is_Formal (Entity (R1))
23219 and then not Is_Formal (Entity (R2));
23220 end Statically_Different;
23222 --------------------------------------
23223 -- Subject_To_Loop_Entry_Attributes --
23224 --------------------------------------
23226 function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
23232 -- The expansion mechanism transform a loop subject to at least one
23233 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
23234 -- the conditional part.
23236 if Nkind_In (Stmt, N_Block_Statement, N_If_Statement)
23237 and then Nkind (Original_Node (N)) = N_Loop_Statement
23239 Stmt := Original_Node (N);
23243 Nkind (Stmt) = N_Loop_Statement
23244 and then Present (Identifier (Stmt))
23245 and then Present (Entity (Identifier (Stmt)))
23246 and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
23247 end Subject_To_Loop_Entry_Attributes;
23249 -----------------------------
23250 -- Subprogram_Access_Level --
23251 -----------------------------
23253 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
23255 if Present (Alias (Subp)) then
23256 return Subprogram_Access_Level (Alias (Subp));
23258 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
23260 end Subprogram_Access_Level;
23262 ---------------------
23263 -- Subprogram_Name --
23264 ---------------------
23266 function Subprogram_Name (N : Node_Id) return String is
23267 Buf : Bounded_String;
23268 Ent : Node_Id := N;
23272 while Present (Ent) loop
23273 case Nkind (Ent) is
23274 when N_Subprogram_Body =>
23275 Ent := Defining_Unit_Name (Specification (Ent));
23278 when N_Subprogram_Declaration =>
23279 Nod := Corresponding_Body (Ent);
23281 if Present (Nod) then
23284 Ent := Defining_Unit_Name (Specification (Ent));
23289 when N_Subprogram_Instantiation
23291 | N_Package_Specification
23293 Ent := Defining_Unit_Name (Ent);
23296 when N_Protected_Type_Declaration =>
23297 Ent := Corresponding_Body (Ent);
23300 when N_Protected_Body
23303 Ent := Defining_Identifier (Ent);
23310 Ent := Parent (Ent);
23314 return "unknown subprogram:unknown file:0:0";
23317 -- If the subprogram is a child unit, use its simple name to start the
23318 -- construction of the fully qualified name.
23320 if Nkind (Ent) = N_Defining_Program_Unit_Name then
23321 Ent := Defining_Identifier (Ent);
23324 Append_Entity_Name (Buf, Ent);
23326 -- Append homonym number if needed
23328 if Nkind (N) in N_Entity and then Has_Homonym (N) then
23330 H : Entity_Id := Homonym (N);
23333 while Present (H) loop
23334 if Scope (H) = Scope (N) then
23348 -- Append source location of Ent to Buf so that the string will
23349 -- look like "subp:file:line:col".
23352 Loc : constant Source_Ptr := Sloc (Ent);
23355 Append (Buf, Reference_Name (Get_Source_File_Index (Loc)));
23357 Append (Buf, Nat (Get_Logical_Line_Number (Loc)));
23359 Append (Buf, Nat (Get_Column_Number (Loc)));
23363 end Subprogram_Name;
23365 -------------------------------
23366 -- Support_Atomic_Primitives --
23367 -------------------------------
23369 function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
23373 -- Verify the alignment of Typ is known
23375 if not Known_Alignment (Typ) then
23379 if Known_Static_Esize (Typ) then
23380 Size := UI_To_Int (Esize (Typ));
23382 -- If the Esize (Object_Size) is unknown at compile time, look at the
23383 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
23385 elsif Known_Static_RM_Size (Typ) then
23386 Size := UI_To_Int (RM_Size (Typ));
23388 -- Otherwise, the size is considered to be unknown.
23394 -- Check that the size of the component is 8, 16, 32, or 64 bits and
23395 -- that Typ is properly aligned.
23398 when 8 | 16 | 32 | 64 =>
23399 return Size = UI_To_Int (Alignment (Typ)) * 8;
23404 end Support_Atomic_Primitives;
23410 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
23412 if Debug_Flag_W then
23413 for J in 0 .. Scope_Stack.Last loop
23418 Write_Name (Chars (E));
23419 Write_Str (" from ");
23420 Write_Location (Sloc (N));
23425 -----------------------
23426 -- Transfer_Entities --
23427 -----------------------
23429 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
23430 procedure Set_Public_Status_Of (Id : Entity_Id);
23431 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
23432 -- Set_Public_Status. If successful and Id denotes a record type, set
23433 -- the Is_Public attribute of its fields.
23435 --------------------------
23436 -- Set_Public_Status_Of --
23437 --------------------------
23439 procedure Set_Public_Status_Of (Id : Entity_Id) is
23443 if not Is_Public (Id) then
23444 Set_Public_Status (Id);
23446 -- When the input entity is a public record type, ensure that all
23447 -- its internal fields are also exposed to the linker. The fields
23448 -- of a class-wide type are never made public.
23451 and then Is_Record_Type (Id)
23452 and then not Is_Class_Wide_Type (Id)
23454 Field := First_Entity (Id);
23455 while Present (Field) loop
23456 Set_Is_Public (Field);
23457 Next_Entity (Field);
23461 end Set_Public_Status_Of;
23465 Full_Id : Entity_Id;
23468 -- Start of processing for Transfer_Entities
23471 Id := First_Entity (From);
23473 if Present (Id) then
23475 -- Merge the entity chain of the source scope with that of the
23476 -- destination scope.
23478 if Present (Last_Entity (To)) then
23479 Set_Next_Entity (Last_Entity (To), Id);
23481 Set_First_Entity (To, Id);
23484 Set_Last_Entity (To, Last_Entity (From));
23486 -- Inspect the entities of the source scope and update their Scope
23489 while Present (Id) loop
23490 Set_Scope (Id, To);
23491 Set_Public_Status_Of (Id);
23493 -- Handle an internally generated full view for a private type
23495 if Is_Private_Type (Id)
23496 and then Present (Full_View (Id))
23497 and then Is_Itype (Full_View (Id))
23499 Full_Id := Full_View (Id);
23501 Set_Scope (Full_Id, To);
23502 Set_Public_Status_Of (Full_Id);
23508 Set_First_Entity (From, Empty);
23509 Set_Last_Entity (From, Empty);
23511 end Transfer_Entities;
23513 -----------------------
23514 -- Type_Access_Level --
23515 -----------------------
23517 function Type_Access_Level (Typ : Entity_Id) return Uint is
23521 Btyp := Base_Type (Typ);
23523 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
23524 -- simply use the level where the type is declared. This is true for
23525 -- stand-alone object declarations, and for anonymous access types
23526 -- associated with components the level is the same as that of the
23527 -- enclosing composite type. However, special treatment is needed for
23528 -- the cases of access parameters, return objects of an anonymous access
23529 -- type, and, in Ada 95, access discriminants of limited types.
23531 if Is_Access_Type (Btyp) then
23532 if Ekind (Btyp) = E_Anonymous_Access_Type then
23534 -- If the type is a nonlocal anonymous access type (such as for
23535 -- an access parameter) we treat it as being declared at the
23536 -- library level to ensure that names such as X.all'access don't
23537 -- fail static accessibility checks.
23539 if not Is_Local_Anonymous_Access (Typ) then
23540 return Scope_Depth (Standard_Standard);
23542 -- If this is a return object, the accessibility level is that of
23543 -- the result subtype of the enclosing function. The test here is
23544 -- little complicated, because we have to account for extended
23545 -- return statements that have been rewritten as blocks, in which
23546 -- case we have to find and the Is_Return_Object attribute of the
23547 -- itype's associated object. It would be nice to find a way to
23548 -- simplify this test, but it doesn't seem worthwhile to add a new
23549 -- flag just for purposes of this test. ???
23551 elsif Ekind (Scope (Btyp)) = E_Return_Statement
23554 and then Nkind (Associated_Node_For_Itype (Btyp)) =
23555 N_Object_Declaration
23556 and then Is_Return_Object
23557 (Defining_Identifier
23558 (Associated_Node_For_Itype (Btyp))))
23564 Scop := Scope (Scope (Btyp));
23565 while Present (Scop) loop
23566 exit when Ekind (Scop) = E_Function;
23567 Scop := Scope (Scop);
23570 -- Treat the return object's type as having the level of the
23571 -- function's result subtype (as per RM05-6.5(5.3/2)).
23573 return Type_Access_Level (Etype (Scop));
23578 Btyp := Root_Type (Btyp);
23580 -- The accessibility level of anonymous access types associated with
23581 -- discriminants is that of the current instance of the type, and
23582 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
23584 -- AI-402: access discriminants have accessibility based on the
23585 -- object rather than the type in Ada 2005, so the above paragraph
23588 -- ??? Needs completion with rules from AI-416
23590 if Ada_Version <= Ada_95
23591 and then Ekind (Typ) = E_Anonymous_Access_Type
23592 and then Present (Associated_Node_For_Itype (Typ))
23593 and then Nkind (Associated_Node_For_Itype (Typ)) =
23594 N_Discriminant_Specification
23596 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
23600 -- Return library level for a generic formal type. This is done because
23601 -- RM(10.3.2) says that "The statically deeper relationship does not
23602 -- apply to ... a descendant of a generic formal type". Rather than
23603 -- checking at each point where a static accessibility check is
23604 -- performed to see if we are dealing with a formal type, this rule is
23605 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
23606 -- return extreme values for a formal type; Deepest_Type_Access_Level
23607 -- returns Int'Last. By calling the appropriate function from among the
23608 -- two, we ensure that the static accessibility check will pass if we
23609 -- happen to run into a formal type. More specifically, we should call
23610 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
23611 -- call occurs as part of a static accessibility check and the error
23612 -- case is the case where the type's level is too shallow (as opposed
23615 if Is_Generic_Type (Root_Type (Btyp)) then
23616 return Scope_Depth (Standard_Standard);
23619 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
23620 end Type_Access_Level;
23622 ------------------------------------
23623 -- Type_Without_Stream_Operation --
23624 ------------------------------------
23626 function Type_Without_Stream_Operation
23628 Op : TSS_Name_Type := TSS_Null) return Entity_Id
23630 BT : constant Entity_Id := Base_Type (T);
23631 Op_Missing : Boolean;
23634 if not Restriction_Active (No_Default_Stream_Attributes) then
23638 if Is_Elementary_Type (T) then
23639 if Op = TSS_Null then
23641 No (TSS (BT, TSS_Stream_Read))
23642 or else No (TSS (BT, TSS_Stream_Write));
23645 Op_Missing := No (TSS (BT, Op));
23654 elsif Is_Array_Type (T) then
23655 return Type_Without_Stream_Operation (Component_Type (T), Op);
23657 elsif Is_Record_Type (T) then
23663 Comp := First_Component (T);
23664 while Present (Comp) loop
23665 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
23667 if Present (C_Typ) then
23671 Next_Component (Comp);
23677 elsif Is_Private_Type (T) and then Present (Full_View (T)) then
23678 return Type_Without_Stream_Operation (Full_View (T), Op);
23682 end Type_Without_Stream_Operation;
23684 ----------------------------
23685 -- Unique_Defining_Entity --
23686 ----------------------------
23688 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
23690 return Unique_Entity (Defining_Entity (N));
23691 end Unique_Defining_Entity;
23693 -------------------
23694 -- Unique_Entity --
23695 -------------------
23697 function Unique_Entity (E : Entity_Id) return Entity_Id is
23698 U : Entity_Id := E;
23704 if Present (Full_View (E)) then
23705 U := Full_View (E);
23709 if Nkind (Parent (E)) = N_Entry_Body then
23711 Prot_Item : Entity_Id;
23712 Prot_Type : Entity_Id;
23715 if Ekind (E) = E_Entry then
23716 Prot_Type := Scope (E);
23718 -- Bodies of entry families are nested within an extra scope
23719 -- that contains an entry index declaration.
23722 Prot_Type := Scope (Scope (E));
23725 -- A protected type may be declared as a private type, in
23726 -- which case we need to get its full view.
23728 if Is_Private_Type (Prot_Type) then
23729 Prot_Type := Full_View (Prot_Type);
23732 -- Full view may not be present on error, in which case
23733 -- return E by default.
23735 if Present (Prot_Type) then
23736 pragma Assert (Ekind (Prot_Type) = E_Protected_Type);
23738 -- Traverse the entity list of the protected type and
23739 -- locate an entry declaration which matches the entry
23742 Prot_Item := First_Entity (Prot_Type);
23743 while Present (Prot_Item) loop
23744 if Ekind (Prot_Item) in Entry_Kind
23745 and then Corresponding_Body (Parent (Prot_Item)) = E
23751 Next_Entity (Prot_Item);
23757 when Formal_Kind =>
23758 if Present (Spec_Entity (E)) then
23759 U := Spec_Entity (E);
23762 when E_Package_Body =>
23765 if Nkind (P) = N_Defining_Program_Unit_Name then
23769 if Nkind (P) = N_Package_Body
23770 and then Present (Corresponding_Spec (P))
23772 U := Corresponding_Spec (P);
23774 elsif Nkind (P) = N_Package_Body_Stub
23775 and then Present (Corresponding_Spec_Of_Stub (P))
23777 U := Corresponding_Spec_Of_Stub (P);
23780 when E_Protected_Body =>
23783 if Nkind (P) = N_Protected_Body
23784 and then Present (Corresponding_Spec (P))
23786 U := Corresponding_Spec (P);
23788 elsif Nkind (P) = N_Protected_Body_Stub
23789 and then Present (Corresponding_Spec_Of_Stub (P))
23791 U := Corresponding_Spec_Of_Stub (P);
23793 if Is_Single_Protected_Object (U) then
23798 if Is_Private_Type (U) then
23799 U := Full_View (U);
23802 when E_Subprogram_Body =>
23805 if Nkind (P) = N_Defining_Program_Unit_Name then
23811 if Nkind (P) = N_Subprogram_Body
23812 and then Present (Corresponding_Spec (P))
23814 U := Corresponding_Spec (P);
23816 elsif Nkind (P) = N_Subprogram_Body_Stub
23817 and then Present (Corresponding_Spec_Of_Stub (P))
23819 U := Corresponding_Spec_Of_Stub (P);
23821 elsif Nkind (P) = N_Subprogram_Renaming_Declaration then
23822 U := Corresponding_Spec (P);
23825 when E_Task_Body =>
23828 if Nkind (P) = N_Task_Body
23829 and then Present (Corresponding_Spec (P))
23831 U := Corresponding_Spec (P);
23833 elsif Nkind (P) = N_Task_Body_Stub
23834 and then Present (Corresponding_Spec_Of_Stub (P))
23836 U := Corresponding_Spec_Of_Stub (P);
23838 if Is_Single_Task_Object (U) then
23843 if Is_Private_Type (U) then
23844 U := Full_View (U);
23848 if Present (Full_View (E)) then
23849 U := Full_View (E);
23863 function Unique_Name (E : Entity_Id) return String is
23865 -- Names in E_Subprogram_Body or E_Package_Body entities are not
23866 -- reliable, as they may not include the overloading suffix. Instead,
23867 -- when looking for the name of E or one of its enclosing scope, we get
23868 -- the name of the corresponding Unique_Entity.
23870 U : constant Entity_Id := Unique_Entity (E);
23872 function This_Name return String;
23878 function This_Name return String is
23880 return Get_Name_String (Chars (U));
23883 -- Start of processing for Unique_Name
23886 if E = Standard_Standard
23887 or else Has_Fully_Qualified_Name (E)
23891 elsif Ekind (E) = E_Enumeration_Literal then
23892 return Unique_Name (Etype (E)) & "__" & This_Name;
23896 S : constant Entity_Id := Scope (U);
23897 pragma Assert (Present (S));
23900 -- Prefix names of predefined types with standard__, but leave
23901 -- names of user-defined packages and subprograms without prefix
23902 -- (even if technically they are nested in the Standard package).
23904 if S = Standard_Standard then
23905 if Ekind (U) = E_Package or else Is_Subprogram (U) then
23908 return Unique_Name (S) & "__" & This_Name;
23911 -- For intances of generic subprograms use the name of the related
23912 -- instace and skip the scope of its wrapper package.
23914 elsif Is_Wrapper_Package (S) then
23915 pragma Assert (Scope (S) = Scope (Related_Instance (S)));
23916 -- Wrapper package and the instantiation are in the same scope
23919 Enclosing_Name : constant String :=
23920 Unique_Name (Scope (S)) & "__" &
23921 Get_Name_String (Chars (Related_Instance (S)));
23924 if Is_Subprogram (U)
23925 and then not Is_Generic_Actual_Subprogram (U)
23927 return Enclosing_Name;
23929 return Enclosing_Name & "__" & This_Name;
23934 return Unique_Name (S) & "__" & This_Name;
23940 ---------------------
23941 -- Unit_Is_Visible --
23942 ---------------------
23944 function Unit_Is_Visible (U : Entity_Id) return Boolean is
23945 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
23946 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
23948 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
23949 -- For a child unit, check whether unit appears in a with_clause
23952 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
23953 -- Scan the context clause of one compilation unit looking for a
23954 -- with_clause for the unit in question.
23956 ----------------------------
23957 -- Unit_In_Parent_Context --
23958 ----------------------------
23960 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
23962 if Unit_In_Context (Par_Unit) then
23965 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
23966 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
23971 end Unit_In_Parent_Context;
23973 ---------------------
23974 -- Unit_In_Context --
23975 ---------------------
23977 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
23981 Clause := First (Context_Items (Comp_Unit));
23982 while Present (Clause) loop
23983 if Nkind (Clause) = N_With_Clause then
23984 if Library_Unit (Clause) = U then
23987 -- The with_clause may denote a renaming of the unit we are
23988 -- looking for, eg. Text_IO which renames Ada.Text_IO.
23991 Renamed_Entity (Entity (Name (Clause))) =
23992 Defining_Entity (Unit (U))
24002 end Unit_In_Context;
24004 -- Start of processing for Unit_Is_Visible
24007 -- The currrent unit is directly visible
24012 elsif Unit_In_Context (Curr) then
24015 -- If the current unit is a body, check the context of the spec
24017 elsif Nkind (Unit (Curr)) = N_Package_Body
24019 (Nkind (Unit (Curr)) = N_Subprogram_Body
24020 and then not Acts_As_Spec (Unit (Curr)))
24022 if Unit_In_Context (Library_Unit (Curr)) then
24027 -- If the spec is a child unit, examine the parents
24029 if Is_Child_Unit (Curr_Entity) then
24030 if Nkind (Unit (Curr)) in N_Unit_Body then
24032 Unit_In_Parent_Context
24033 (Parent_Spec (Unit (Library_Unit (Curr))));
24035 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
24041 end Unit_Is_Visible;
24043 ------------------------------
24044 -- Universal_Interpretation --
24045 ------------------------------
24047 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
24048 Index : Interp_Index;
24052 -- The argument may be a formal parameter of an operator or subprogram
24053 -- with multiple interpretations, or else an expression for an actual.
24055 if Nkind (Opnd) = N_Defining_Identifier
24056 or else not Is_Overloaded (Opnd)
24058 if Etype (Opnd) = Universal_Integer
24059 or else Etype (Opnd) = Universal_Real
24061 return Etype (Opnd);
24067 Get_First_Interp (Opnd, Index, It);
24068 while Present (It.Typ) loop
24069 if It.Typ = Universal_Integer
24070 or else It.Typ = Universal_Real
24075 Get_Next_Interp (Index, It);
24080 end Universal_Interpretation;
24086 function Unqualify (Expr : Node_Id) return Node_Id is
24088 -- Recurse to handle unlikely case of multiple levels of qualification
24090 if Nkind (Expr) = N_Qualified_Expression then
24091 return Unqualify (Expression (Expr));
24093 -- Normal case, not a qualified expression
24104 function Unqual_Conv (Expr : Node_Id) return Node_Id is
24106 -- Recurse to handle unlikely case of multiple levels of qualification
24107 -- and/or conversion.
24109 if Nkind_In (Expr, N_Qualified_Expression,
24111 N_Unchecked_Type_Conversion)
24113 return Unqual_Conv (Expression (Expr));
24115 -- Normal case, not a qualified expression
24122 -----------------------
24123 -- Visible_Ancestors --
24124 -----------------------
24126 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
24132 pragma Assert (Is_Record_Type (Typ) and then Is_Tagged_Type (Typ));
24134 -- Collect all the parents and progenitors of Typ. If the full-view of
24135 -- private parents and progenitors is available then it is used to
24136 -- generate the list of visible ancestors; otherwise their partial
24137 -- view is added to the resulting list.
24142 Use_Full_View => True);
24146 Ifaces_List => List_2,
24147 Exclude_Parents => True,
24148 Use_Full_View => True);
24150 -- Join the two lists. Avoid duplications because an interface may
24151 -- simultaneously be parent and progenitor of a type.
24153 Elmt := First_Elmt (List_2);
24154 while Present (Elmt) loop
24155 Append_Unique_Elmt (Node (Elmt), List_1);
24160 end Visible_Ancestors;
24162 ----------------------
24163 -- Within_Init_Proc --
24164 ----------------------
24166 function Within_Init_Proc return Boolean is
24170 S := Current_Scope;
24171 while not Is_Overloadable (S) loop
24172 if S = Standard_Standard then
24179 return Is_Init_Proc (S);
24180 end Within_Init_Proc;
24182 ---------------------------
24183 -- Within_Protected_Type --
24184 ---------------------------
24186 function Within_Protected_Type (E : Entity_Id) return Boolean is
24187 Scop : Entity_Id := Scope (E);
24190 while Present (Scop) loop
24191 if Ekind (Scop) = E_Protected_Type then
24195 Scop := Scope (Scop);
24199 end Within_Protected_Type;
24205 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
24207 return Scope_Within_Or_Same (Scope (E), S);
24210 ----------------------------
24211 -- Within_Subprogram_Call --
24212 ----------------------------
24214 function Within_Subprogram_Call (N : Node_Id) return Boolean is
24218 -- Climb the parent chain looking for a function or procedure call
24221 while Present (Par) loop
24222 if Nkind_In (Par, N_Entry_Call_Statement,
24224 N_Procedure_Call_Statement)
24228 -- Prevent the search from going too far
24230 elsif Is_Body_Or_Package_Declaration (Par) then
24234 Par := Parent (Par);
24238 end Within_Subprogram_Call;
24244 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
24245 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
24246 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
24248 Matching_Field : Entity_Id;
24249 -- Entity to give a more precise suggestion on how to write a one-
24250 -- element positional aggregate.
24252 function Has_One_Matching_Field return Boolean;
24253 -- Determines if Expec_Type is a record type with a single component or
24254 -- discriminant whose type matches the found type or is one dimensional
24255 -- array whose component type matches the found type. In the case of
24256 -- one discriminant, we ignore the variant parts. That's not accurate,
24257 -- but good enough for the warning.
24259 ----------------------------
24260 -- Has_One_Matching_Field --
24261 ----------------------------
24263 function Has_One_Matching_Field return Boolean is
24267 Matching_Field := Empty;
24269 if Is_Array_Type (Expec_Type)
24270 and then Number_Dimensions (Expec_Type) = 1
24271 and then Covers (Etype (Component_Type (Expec_Type)), Found_Type)
24273 -- Use type name if available. This excludes multidimensional
24274 -- arrays and anonymous arrays.
24276 if Comes_From_Source (Expec_Type) then
24277 Matching_Field := Expec_Type;
24279 -- For an assignment, use name of target
24281 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
24282 and then Is_Entity_Name (Name (Parent (Expr)))
24284 Matching_Field := Entity (Name (Parent (Expr)));
24289 elsif not Is_Record_Type (Expec_Type) then
24293 E := First_Entity (Expec_Type);
24298 elsif not Ekind_In (E, E_Discriminant, E_Component)
24299 or else Nam_In (Chars (E), Name_uTag, Name_uParent)
24308 if not Covers (Etype (E), Found_Type) then
24311 elsif Present (Next_Entity (E))
24312 and then (Ekind (E) = E_Component
24313 or else Ekind (Next_Entity (E)) = E_Discriminant)
24318 Matching_Field := E;
24322 end Has_One_Matching_Field;
24324 -- Start of processing for Wrong_Type
24327 -- Don't output message if either type is Any_Type, or if a message
24328 -- has already been posted for this node. We need to do the latter
24329 -- check explicitly (it is ordinarily done in Errout), because we
24330 -- are using ! to force the output of the error messages.
24332 if Expec_Type = Any_Type
24333 or else Found_Type = Any_Type
24334 or else Error_Posted (Expr)
24338 -- If one of the types is a Taft-Amendment type and the other it its
24339 -- completion, it must be an illegal use of a TAT in the spec, for
24340 -- which an error was already emitted. Avoid cascaded errors.
24342 elsif Is_Incomplete_Type (Expec_Type)
24343 and then Has_Completion_In_Body (Expec_Type)
24344 and then Full_View (Expec_Type) = Etype (Expr)
24348 elsif Is_Incomplete_Type (Etype (Expr))
24349 and then Has_Completion_In_Body (Etype (Expr))
24350 and then Full_View (Etype (Expr)) = Expec_Type
24354 -- In an instance, there is an ongoing problem with completion of
24355 -- type derived from private types. Their structure is what Gigi
24356 -- expects, but the Etype is the parent type rather than the
24357 -- derived private type itself. Do not flag error in this case. The
24358 -- private completion is an entity without a parent, like an Itype.
24359 -- Similarly, full and partial views may be incorrect in the instance.
24360 -- There is no simple way to insure that it is consistent ???
24362 -- A similar view discrepancy can happen in an inlined body, for the
24363 -- same reason: inserted body may be outside of the original package
24364 -- and only partial views are visible at the point of insertion.
24366 elsif In_Instance or else In_Inlined_Body then
24367 if Etype (Etype (Expr)) = Etype (Expected_Type)
24369 (Has_Private_Declaration (Expected_Type)
24370 or else Has_Private_Declaration (Etype (Expr)))
24371 and then No (Parent (Expected_Type))
24375 elsif Nkind (Parent (Expr)) = N_Qualified_Expression
24376 and then Entity (Subtype_Mark (Parent (Expr))) = Expected_Type
24380 elsif Is_Private_Type (Expected_Type)
24381 and then Present (Full_View (Expected_Type))
24382 and then Covers (Full_View (Expected_Type), Etype (Expr))
24386 -- Conversely, type of expression may be the private one
24388 elsif Is_Private_Type (Base_Type (Etype (Expr)))
24389 and then Full_View (Base_Type (Etype (Expr))) = Expected_Type
24395 -- An interesting special check. If the expression is parenthesized
24396 -- and its type corresponds to the type of the sole component of the
24397 -- expected record type, or to the component type of the expected one
24398 -- dimensional array type, then assume we have a bad aggregate attempt.
24400 if Nkind (Expr) in N_Subexpr
24401 and then Paren_Count (Expr) /= 0
24402 and then Has_One_Matching_Field
24404 Error_Msg_N ("positional aggregate cannot have one component", Expr);
24406 if Present (Matching_Field) then
24407 if Is_Array_Type (Expec_Type) then
24409 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
24412 ("\write instead `& ='> ...`", Expr, Matching_Field);
24416 -- Another special check, if we are looking for a pool-specific access
24417 -- type and we found an E_Access_Attribute_Type, then we have the case
24418 -- of an Access attribute being used in a context which needs a pool-
24419 -- specific type, which is never allowed. The one extra check we make
24420 -- is that the expected designated type covers the Found_Type.
24422 elsif Is_Access_Type (Expec_Type)
24423 and then Ekind (Found_Type) = E_Access_Attribute_Type
24424 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
24425 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
24427 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
24429 Error_Msg_N -- CODEFIX
24430 ("result must be general access type!", Expr);
24431 Error_Msg_NE -- CODEFIX
24432 ("add ALL to }!", Expr, Expec_Type);
24434 -- Another special check, if the expected type is an integer type,
24435 -- but the expression is of type System.Address, and the parent is
24436 -- an addition or subtraction operation whose left operand is the
24437 -- expression in question and whose right operand is of an integral
24438 -- type, then this is an attempt at address arithmetic, so give
24439 -- appropriate message.
24441 elsif Is_Integer_Type (Expec_Type)
24442 and then Is_RTE (Found_Type, RE_Address)
24443 and then Nkind_In (Parent (Expr), N_Op_Add, N_Op_Subtract)
24444 and then Expr = Left_Opnd (Parent (Expr))
24445 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
24448 ("address arithmetic not predefined in package System",
24451 ("\possible missing with/use of System.Storage_Elements",
24455 -- If the expected type is an anonymous access type, as for access
24456 -- parameters and discriminants, the error is on the designated types.
24458 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
24459 if Comes_From_Source (Expec_Type) then
24460 Error_Msg_NE ("expected}!", Expr, Expec_Type);
24463 ("expected an access type with designated}",
24464 Expr, Designated_Type (Expec_Type));
24467 if Is_Access_Type (Found_Type)
24468 and then not Comes_From_Source (Found_Type)
24471 ("\\found an access type with designated}!",
24472 Expr, Designated_Type (Found_Type));
24474 if From_Limited_With (Found_Type) then
24475 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
24476 Error_Msg_Qual_Level := 99;
24477 Error_Msg_NE -- CODEFIX
24478 ("\\missing `WITH &;", Expr, Scope (Found_Type));
24479 Error_Msg_Qual_Level := 0;
24481 Error_Msg_NE ("found}!", Expr, Found_Type);
24485 -- Normal case of one type found, some other type expected
24488 -- If the names of the two types are the same, see if some number
24489 -- of levels of qualification will help. Don't try more than three
24490 -- levels, and if we get to standard, it's no use (and probably
24491 -- represents an error in the compiler) Also do not bother with
24492 -- internal scope names.
24495 Expec_Scope : Entity_Id;
24496 Found_Scope : Entity_Id;
24499 Expec_Scope := Expec_Type;
24500 Found_Scope := Found_Type;
24502 for Levels in Nat range 0 .. 3 loop
24503 if Chars (Expec_Scope) /= Chars (Found_Scope) then
24504 Error_Msg_Qual_Level := Levels;
24508 Expec_Scope := Scope (Expec_Scope);
24509 Found_Scope := Scope (Found_Scope);
24511 exit when Expec_Scope = Standard_Standard
24512 or else Found_Scope = Standard_Standard
24513 or else not Comes_From_Source (Expec_Scope)
24514 or else not Comes_From_Source (Found_Scope);
24518 if Is_Record_Type (Expec_Type)
24519 and then Present (Corresponding_Remote_Type (Expec_Type))
24521 Error_Msg_NE ("expected}!", Expr,
24522 Corresponding_Remote_Type (Expec_Type));
24524 Error_Msg_NE ("expected}!", Expr, Expec_Type);
24527 if Is_Entity_Name (Expr)
24528 and then Is_Package_Or_Generic_Package (Entity (Expr))
24530 Error_Msg_N ("\\found package name!", Expr);
24532 elsif Is_Entity_Name (Expr)
24533 and then Ekind_In (Entity (Expr), E_Procedure, E_Generic_Procedure)
24535 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
24537 ("found procedure name, possibly missing Access attribute!",
24541 ("\\found procedure name instead of function!", Expr);
24544 elsif Nkind (Expr) = N_Function_Call
24545 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
24546 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
24547 and then No (Parameter_Associations (Expr))
24550 ("found function name, possibly missing Access attribute!",
24553 -- Catch common error: a prefix or infix operator which is not
24554 -- directly visible because the type isn't.
24556 elsif Nkind (Expr) in N_Op
24557 and then Is_Overloaded (Expr)
24558 and then not Is_Immediately_Visible (Expec_Type)
24559 and then not Is_Potentially_Use_Visible (Expec_Type)
24560 and then not In_Use (Expec_Type)
24561 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
24564 ("operator of the type is not directly visible!", Expr);
24566 elsif Ekind (Found_Type) = E_Void
24567 and then Present (Parent (Found_Type))
24568 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
24570 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
24573 Error_Msg_NE ("\\found}!", Expr, Found_Type);
24576 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
24577 -- of the same modular type, and (M1 and M2) = 0 was intended.
24579 if Expec_Type = Standard_Boolean
24580 and then Is_Modular_Integer_Type (Found_Type)
24581 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
24582 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
24585 Op : constant Node_Id := Right_Opnd (Parent (Expr));
24586 L : constant Node_Id := Left_Opnd (Op);
24587 R : constant Node_Id := Right_Opnd (Op);
24590 -- The case for the message is when the left operand of the
24591 -- comparison is the same modular type, or when it is an
24592 -- integer literal (or other universal integer expression),
24593 -- which would have been typed as the modular type if the
24594 -- parens had been there.
24596 if (Etype (L) = Found_Type
24598 Etype (L) = Universal_Integer)
24599 and then Is_Integer_Type (Etype (R))
24602 ("\\possible missing parens for modular operation", Expr);
24607 -- Reset error message qualification indication
24609 Error_Msg_Qual_Level := 0;
24613 --------------------------------
24614 -- Yields_Synchronized_Object --
24615 --------------------------------
24617 function Yields_Synchronized_Object (Typ : Entity_Id) return Boolean is
24618 Has_Sync_Comp : Boolean := False;
24622 -- An array type yields a synchronized object if its component type
24623 -- yields a synchronized object.
24625 if Is_Array_Type (Typ) then
24626 return Yields_Synchronized_Object (Component_Type (Typ));
24628 -- A descendant of type Ada.Synchronous_Task_Control.Suspension_Object
24629 -- yields a synchronized object by default.
24631 elsif Is_Descendant_Of_Suspension_Object (Typ) then
24634 -- A protected type yields a synchronized object by default
24636 elsif Is_Protected_Type (Typ) then
24639 -- A record type or type extension yields a synchronized object when its
24640 -- discriminants (if any) lack default values and all components are of
24641 -- a type that yelds a synchronized object.
24643 elsif Is_Record_Type (Typ) then
24645 -- Inspect all entities defined in the scope of the type, looking for
24646 -- components of a type that does not yeld a synchronized object or
24647 -- for discriminants with default values.
24649 Id := First_Entity (Typ);
24650 while Present (Id) loop
24651 if Comes_From_Source (Id) then
24652 if Ekind (Id) = E_Component then
24653 if Yields_Synchronized_Object (Etype (Id)) then
24654 Has_Sync_Comp := True;
24656 -- The component does not yield a synchronized object
24662 elsif Ekind (Id) = E_Discriminant
24663 and then Present (Expression (Parent (Id)))
24672 -- Ensure that the parent type of a type extension yields a
24673 -- synchronized object.
24675 if Etype (Typ) /= Typ
24676 and then not Yields_Synchronized_Object (Etype (Typ))
24681 -- If we get here, then all discriminants lack default values and all
24682 -- components are of a type that yields a synchronized object.
24684 return Has_Sync_Comp;
24686 -- A synchronized interface type yields a synchronized object by default
24688 elsif Is_Synchronized_Interface (Typ) then
24691 -- A task type yelds a synchronized object by default
24693 elsif Is_Task_Type (Typ) then
24696 -- Otherwise the type does not yield a synchronized object
24701 end Yields_Synchronized_Object;
24703 ---------------------------
24704 -- Yields_Universal_Type --
24705 ---------------------------
24707 function Yields_Universal_Type (N : Node_Id) return Boolean is
24709 -- Integer and real literals are of a universal type
24711 if Nkind_In (N, N_Integer_Literal, N_Real_Literal) then
24714 -- The values of certain attributes are of a universal type
24716 elsif Nkind (N) = N_Attribute_Reference then
24718 Universal_Type_Attribute (Get_Attribute_Id (Attribute_Name (N)));
24720 -- ??? There are possibly other cases to consider
24725 end Yields_Universal_Type;
24728 Erroutc.Subprogram_Name_Ptr := Subprogram_Name'Access;