1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2020, 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 Casing; use Casing;
30 with Checks; use Checks;
31 with Debug; use Debug;
32 with Elists; use Elists;
33 with Errout; use Errout;
34 with Erroutc; use Erroutc;
35 with Exp_Ch11; use Exp_Ch11;
36 with Exp_Util; use Exp_Util;
37 with Fname; use Fname;
38 with Freeze; use Freeze;
40 with Lib.Xref; use Lib.Xref;
41 with Namet.Sp; use Namet.Sp;
42 with Nlists; use Nlists;
43 with Nmake; use Nmake;
44 with Output; use Output;
45 with Restrict; use Restrict;
46 with Rident; use Rident;
47 with Rtsfind; use Rtsfind;
49 with Sem_Aux; use Sem_Aux;
50 with Sem_Attr; use Sem_Attr;
51 with Sem_Ch6; use Sem_Ch6;
52 with Sem_Ch8; use Sem_Ch8;
53 with Sem_Disp; use Sem_Disp;
54 with Sem_Elab; use Sem_Elab;
55 with Sem_Eval; use Sem_Eval;
56 with Sem_Prag; use Sem_Prag;
57 with Sem_Res; use Sem_Res;
58 with Sem_Warn; use Sem_Warn;
59 with Sem_Type; use Sem_Type;
60 with Sinfo; use Sinfo;
61 with Sinput; use Sinput;
62 with Stand; use Stand;
64 with Stringt; use Stringt;
65 with Targparm; use Targparm;
66 with Tbuild; use Tbuild;
67 with Ttypes; use Ttypes;
68 with Uname; use Uname;
70 with GNAT.Heap_Sort_G;
71 with GNAT.HTable; use GNAT.HTable;
73 package body Sem_Util is
75 ---------------------------
76 -- Local Data Structures --
77 ---------------------------
79 Invalid_Binder_Values : array (Scalar_Id) of Entity_Id := (others => Empty);
80 -- A collection to hold the entities of the variables declared in package
81 -- System.Scalar_Values which describe the invalid values of scalar types.
83 Invalid_Binder_Values_Set : Boolean := False;
84 -- This flag prevents multiple attempts to initialize Invalid_Binder_Values
86 Invalid_Floats : array (Float_Scalar_Id) of Ureal := (others => No_Ureal);
87 -- A collection to hold the invalid values of float types as specified by
88 -- pragma Initialize_Scalars.
90 Invalid_Integers : array (Integer_Scalar_Id) of Uint := (others => No_Uint);
91 -- A collection to hold the invalid values of integer types as specified
92 -- by pragma Initialize_Scalars.
94 -----------------------
95 -- Local Subprograms --
96 -----------------------
98 function Build_Component_Subtype
101 T : Entity_Id) return Node_Id;
102 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
103 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
104 -- Loc is the source location, T is the original subtype.
106 procedure Examine_Array_Bounds
108 All_Static : out Boolean;
109 Has_Empty : out Boolean);
110 -- Inspect the index constraints of array type Typ. Flag All_Static is set
111 -- when all ranges are static. Flag Has_Empty is set only when All_Static
112 -- is set and indicates that at least one range is empty.
114 function Has_Enabled_Property
115 (Item_Id : Entity_Id;
116 Property : Name_Id) return Boolean;
117 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
118 -- Determine whether an abstract state or a variable denoted by entity
119 -- Item_Id has enabled property Property.
121 function Has_Null_Extension (T : Entity_Id) return Boolean;
122 -- T is a derived tagged type. Check whether the type extension is null.
123 -- If the parent type is fully initialized, T can be treated as such.
125 function Is_Atomic_Object_Entity (Id : Entity_Id) return Boolean;
126 -- Determine whether arbitrary entity Id denotes an atomic object as per
129 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
130 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
131 -- with discriminants whose default values are static, examine only the
132 -- components in the selected variant to determine whether all of them
135 type Null_Status_Kind is
137 -- This value indicates that a subexpression is known to have a null
138 -- value at compile time.
141 -- This value indicates that a subexpression is known to have a non-null
142 -- value at compile time.
145 -- This value indicates that it cannot be determined at compile time
146 -- whether a subexpression yields a null or non-null value.
148 function Null_Status (N : Node_Id) return Null_Status_Kind;
149 -- Determine whether subexpression N of an access type yields a null value,
150 -- a non-null value, or the value cannot be determined at compile time. The
151 -- routine does not take simple flow diagnostics into account, it relies on
152 -- static facts such as the presence of null exclusions.
154 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
155 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
156 -- ???We retain the old and new algorithms for Requires_Transient_Scope for
157 -- the time being. New_Requires_Transient_Scope is used by default; the
158 -- debug switch -gnatdQ can be used to do Old_Requires_Transient_Scope
159 -- instead. The intent is to use this temporarily to measure before/after
160 -- efficiency. Note: when this temporary code is removed, the documentation
161 -- of dQ in debug.adb should be removed.
163 procedure Results_Differ
167 -- ???Debugging code. Called when the Old_Val and New_Val differ. This
168 -- routine will be removed eventially when New_Requires_Transient_Scope
169 -- becomes Requires_Transient_Scope and Old_Requires_Transient_Scope is
172 function Subprogram_Name (N : Node_Id) return String;
173 -- Return the fully qualified name of the enclosing subprogram for the
174 -- given node N, with file:line:col information appended, e.g.
175 -- "subp:file:line:col", corresponding to the source location of the
176 -- body of the subprogram.
178 ------------------------------
179 -- Abstract_Interface_List --
180 ------------------------------
182 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
186 if Is_Concurrent_Type (Typ) then
188 -- If we are dealing with a synchronized subtype, go to the base
189 -- type, whose declaration has the interface list.
191 Nod := Declaration_Node (Base_Type (Typ));
193 if Nkind_In (Nod, N_Full_Type_Declaration,
194 N_Private_Type_Declaration)
199 elsif Ekind (Typ) = E_Record_Type_With_Private then
200 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
201 Nod := Type_Definition (Parent (Typ));
203 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
204 if Present (Full_View (Typ))
206 Nkind (Parent (Full_View (Typ))) = N_Full_Type_Declaration
208 Nod := Type_Definition (Parent (Full_View (Typ)));
210 -- If the full-view is not available we cannot do anything else
211 -- here (the source has errors).
217 -- Support for generic formals with interfaces is still missing ???
219 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
224 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
228 elsif Ekind (Typ) = E_Record_Subtype then
229 Nod := Type_Definition (Parent (Etype (Typ)));
231 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
233 -- Recurse, because parent may still be a private extension. Also
234 -- note that the full view of the subtype or the full view of its
235 -- base type may (both) be unavailable.
237 return Abstract_Interface_List (Etype (Typ));
239 elsif Ekind (Typ) = E_Record_Type then
240 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
241 Nod := Formal_Type_Definition (Parent (Typ));
243 Nod := Type_Definition (Parent (Typ));
246 -- Otherwise the type is of a kind which does not implement interfaces
252 return Interface_List (Nod);
253 end Abstract_Interface_List;
255 ----------------------------------
256 -- Acquire_Warning_Match_String --
257 ----------------------------------
259 function Acquire_Warning_Match_String (Str_Lit : Node_Id) return String is
260 S : constant String := To_String (Strval (Str_Lit));
265 -- Put "*" before or after or both, if it's not already there
268 F : constant Boolean := S (S'First) = '*';
269 L : constant Boolean := S (S'Last) = '*';
281 return "*" & S & "*";
286 end Acquire_Warning_Match_String;
288 --------------------------------
289 -- Add_Access_Type_To_Process --
290 --------------------------------
292 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
296 Ensure_Freeze_Node (E);
297 L := Access_Types_To_Process (Freeze_Node (E));
301 Set_Access_Types_To_Process (Freeze_Node (E), L);
305 end Add_Access_Type_To_Process;
307 --------------------------
308 -- Add_Block_Identifier --
309 --------------------------
311 procedure Add_Block_Identifier (N : Node_Id; Id : out Entity_Id) is
312 Loc : constant Source_Ptr := Sloc (N);
315 pragma Assert (Nkind (N) = N_Block_Statement);
317 -- The block already has a label, return its entity
319 if Present (Identifier (N)) then
320 Id := Entity (Identifier (N));
322 -- Create a new block label and set its attributes
325 Id := New_Internal_Entity (E_Block, Current_Scope, Loc, 'B');
326 Set_Etype (Id, Standard_Void_Type);
329 Set_Identifier (N, New_Occurrence_Of (Id, Loc));
330 Set_Block_Node (Id, Identifier (N));
332 end Add_Block_Identifier;
334 ----------------------------
335 -- Add_Global_Declaration --
336 ----------------------------
338 procedure Add_Global_Declaration (N : Node_Id) is
339 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
342 if No (Declarations (Aux_Node)) then
343 Set_Declarations (Aux_Node, New_List);
346 Append_To (Declarations (Aux_Node), N);
348 end Add_Global_Declaration;
350 --------------------------------
351 -- Address_Integer_Convert_OK --
352 --------------------------------
354 function Address_Integer_Convert_OK (T1, T2 : Entity_Id) return Boolean is
356 if Allow_Integer_Address
357 and then ((Is_Descendant_Of_Address (T1)
358 and then Is_Private_Type (T1)
359 and then Is_Integer_Type (T2))
361 (Is_Descendant_Of_Address (T2)
362 and then Is_Private_Type (T2)
363 and then Is_Integer_Type (T1)))
369 end Address_Integer_Convert_OK;
375 function Address_Value (N : Node_Id) return Node_Id is
380 -- For constant, get constant expression
382 if Is_Entity_Name (Expr)
383 and then Ekind (Entity (Expr)) = E_Constant
385 Expr := Constant_Value (Entity (Expr));
387 -- For unchecked conversion, get result to convert
389 elsif Nkind (Expr) = N_Unchecked_Type_Conversion then
390 Expr := Expression (Expr);
392 -- For (common case) of To_Address call, get argument
394 elsif Nkind (Expr) = N_Function_Call
395 and then Is_Entity_Name (Name (Expr))
396 and then Is_RTE (Entity (Name (Expr)), RE_To_Address)
398 Expr := First (Parameter_Associations (Expr));
400 if Nkind (Expr) = N_Parameter_Association then
401 Expr := Explicit_Actual_Parameter (Expr);
404 -- We finally have the real expression
418 -- For now, just 8/16/32/64
420 function Addressable (V : Uint) return Boolean is
422 return V = Uint_8 or else
428 function Addressable (V : Int) return Boolean is
436 ---------------------------------
437 -- Aggregate_Constraint_Checks --
438 ---------------------------------
440 procedure Aggregate_Constraint_Checks
442 Check_Typ : Entity_Id)
444 Exp_Typ : constant Entity_Id := Etype (Exp);
447 if Raises_Constraint_Error (Exp) then
451 -- Ada 2005 (AI-230): Generate a conversion to an anonymous access
452 -- component's type to force the appropriate accessibility checks.
454 -- Ada 2005 (AI-231): Generate conversion to the null-excluding type to
455 -- force the corresponding run-time check
457 if Is_Access_Type (Check_Typ)
458 and then Is_Local_Anonymous_Access (Check_Typ)
460 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
461 Analyze_And_Resolve (Exp, Check_Typ);
462 Check_Unset_Reference (Exp);
465 -- What follows is really expansion activity, so check that expansion
466 -- is on and is allowed. In GNATprove mode, we also want check flags to
467 -- be added in the tree, so that the formal verification can rely on
468 -- those to be present. In GNATprove mode for formal verification, some
469 -- treatment typically only done during expansion needs to be performed
470 -- on the tree, but it should not be applied inside generics. Otherwise,
471 -- this breaks the name resolution mechanism for generic instances.
473 if not Expander_Active
474 and (Inside_A_Generic or not Full_Analysis or not GNATprove_Mode)
479 if Is_Access_Type (Check_Typ)
480 and then Can_Never_Be_Null (Check_Typ)
481 and then not Can_Never_Be_Null (Exp_Typ)
483 Install_Null_Excluding_Check (Exp);
486 -- First check if we have to insert discriminant checks
488 if Has_Discriminants (Exp_Typ) then
489 Apply_Discriminant_Check (Exp, Check_Typ);
491 -- Next emit length checks for array aggregates
493 elsif Is_Array_Type (Exp_Typ) then
494 Apply_Length_Check (Exp, Check_Typ);
496 -- Finally emit scalar and string checks. If we are dealing with a
497 -- scalar literal we need to check by hand because the Etype of
498 -- literals is not necessarily correct.
500 elsif Is_Scalar_Type (Exp_Typ)
501 and then Compile_Time_Known_Value (Exp)
503 if Is_Out_Of_Range (Exp, Base_Type (Check_Typ)) then
504 Apply_Compile_Time_Constraint_Error
505 (Exp, "value not in range of}??", CE_Range_Check_Failed,
506 Ent => Base_Type (Check_Typ),
507 Typ => Base_Type (Check_Typ));
509 elsif Is_Out_Of_Range (Exp, Check_Typ) then
510 Apply_Compile_Time_Constraint_Error
511 (Exp, "value not in range of}??", CE_Range_Check_Failed,
515 elsif not Range_Checks_Suppressed (Check_Typ) then
516 Apply_Scalar_Range_Check (Exp, Check_Typ);
519 -- Verify that target type is also scalar, to prevent view anomalies
520 -- in instantiations.
522 elsif (Is_Scalar_Type (Exp_Typ)
523 or else Nkind (Exp) = N_String_Literal)
524 and then Is_Scalar_Type (Check_Typ)
525 and then Exp_Typ /= Check_Typ
527 if Is_Entity_Name (Exp)
528 and then Ekind (Entity (Exp)) = E_Constant
530 -- If expression is a constant, it is worthwhile checking whether
531 -- it is a bound of the type.
533 if (Is_Entity_Name (Type_Low_Bound (Check_Typ))
534 and then Entity (Exp) = Entity (Type_Low_Bound (Check_Typ)))
536 (Is_Entity_Name (Type_High_Bound (Check_Typ))
537 and then Entity (Exp) = Entity (Type_High_Bound (Check_Typ)))
542 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
543 Analyze_And_Resolve (Exp, Check_Typ);
544 Check_Unset_Reference (Exp);
547 -- Could use a comment on this case ???
550 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
551 Analyze_And_Resolve (Exp, Check_Typ);
552 Check_Unset_Reference (Exp);
556 end Aggregate_Constraint_Checks;
558 -----------------------
559 -- Alignment_In_Bits --
560 -----------------------
562 function Alignment_In_Bits (E : Entity_Id) return Uint is
564 return Alignment (E) * System_Storage_Unit;
565 end Alignment_In_Bits;
567 --------------------------------------
568 -- All_Composite_Constraints_Static --
569 --------------------------------------
571 function All_Composite_Constraints_Static
572 (Constr : Node_Id) return Boolean
575 if No (Constr) or else Error_Posted (Constr) then
579 case Nkind (Constr) is
581 if Nkind (Constr) in N_Has_Entity
582 and then Present (Entity (Constr))
584 if Is_Type (Entity (Constr)) then
586 not Is_Discrete_Type (Entity (Constr))
587 or else Is_OK_Static_Subtype (Entity (Constr));
590 elsif Nkind (Constr) = N_Range then
592 Is_OK_Static_Expression (Low_Bound (Constr))
594 Is_OK_Static_Expression (High_Bound (Constr));
596 elsif Nkind (Constr) = N_Attribute_Reference
597 and then Attribute_Name (Constr) = Name_Range
600 Is_OK_Static_Expression
601 (Type_Low_Bound (Etype (Prefix (Constr))))
603 Is_OK_Static_Expression
604 (Type_High_Bound (Etype (Prefix (Constr))));
608 not Present (Etype (Constr)) -- previous error
609 or else not Is_Discrete_Type (Etype (Constr))
610 or else Is_OK_Static_Expression (Constr);
612 when N_Discriminant_Association =>
613 return All_Composite_Constraints_Static (Expression (Constr));
615 when N_Range_Constraint =>
617 All_Composite_Constraints_Static (Range_Expression (Constr));
619 when N_Index_Or_Discriminant_Constraint =>
621 One_Cstr : Entity_Id;
623 One_Cstr := First (Constraints (Constr));
624 while Present (One_Cstr) loop
625 if not All_Composite_Constraints_Static (One_Cstr) then
635 when N_Subtype_Indication =>
637 All_Composite_Constraints_Static (Subtype_Mark (Constr))
639 All_Composite_Constraints_Static (Constraint (Constr));
644 end All_Composite_Constraints_Static;
646 ------------------------
647 -- Append_Entity_Name --
648 ------------------------
650 procedure Append_Entity_Name (Buf : in out Bounded_String; E : Entity_Id) is
651 Temp : Bounded_String;
653 procedure Inner (E : Entity_Id);
654 -- Inner recursive routine, keep outer routine nonrecursive to ease
655 -- debugging when we get strange results from this routine.
661 procedure Inner (E : Entity_Id) is
665 -- If entity has an internal name, skip by it, and print its scope.
666 -- Note that we strip a final R from the name before the test; this
667 -- is needed for some cases of instantiations.
670 E_Name : Bounded_String;
673 Append (E_Name, Chars (E));
675 if E_Name.Chars (E_Name.Length) = 'R' then
676 E_Name.Length := E_Name.Length - 1;
679 if Is_Internal_Name (E_Name) then
687 -- Just print entity name if its scope is at the outer level
689 if Scop = Standard_Standard then
692 -- If scope comes from source, write scope and entity
694 elsif Comes_From_Source (Scop) then
695 Append_Entity_Name (Temp, Scop);
698 -- If in wrapper package skip past it
700 elsif Present (Scop) and then Is_Wrapper_Package (Scop) then
701 Append_Entity_Name (Temp, Scope (Scop));
704 -- Otherwise nothing to output (happens in unnamed block statements)
713 E_Name : Bounded_String;
716 Append_Unqualified_Decoded (E_Name, Chars (E));
718 -- Remove trailing upper-case letters from the name (useful for
719 -- dealing with some cases of internal names generated in the case
720 -- of references from within a generic).
722 while E_Name.Length > 1
723 and then E_Name.Chars (E_Name.Length) in 'A' .. 'Z'
725 E_Name.Length := E_Name.Length - 1;
728 -- Adjust casing appropriately (gets name from source if possible)
730 Adjust_Name_Case (E_Name, Sloc (E));
731 Append (Temp, E_Name);
735 -- Start of processing for Append_Entity_Name
740 end Append_Entity_Name;
742 ---------------------------------
743 -- Append_Inherited_Subprogram --
744 ---------------------------------
746 procedure Append_Inherited_Subprogram (S : Entity_Id) is
747 Par : constant Entity_Id := Alias (S);
748 -- The parent subprogram
750 Scop : constant Entity_Id := Scope (Par);
751 -- The scope of definition of the parent subprogram
753 Typ : constant Entity_Id := Defining_Entity (Parent (S));
754 -- The derived type of which S is a primitive operation
760 if Ekind (Current_Scope) = E_Package
761 and then In_Private_Part (Current_Scope)
762 and then Has_Private_Declaration (Typ)
763 and then Is_Tagged_Type (Typ)
764 and then Scop = Current_Scope
766 -- The inherited operation is available at the earliest place after
767 -- the derived type declaration (RM 7.3.1 (6/1)). This is only
768 -- relevant for type extensions. If the parent operation appears
769 -- after the type extension, the operation is not visible.
772 (Visible_Declarations
773 (Package_Specification (Current_Scope)));
774 while Present (Decl) loop
775 if Nkind (Decl) = N_Private_Extension_Declaration
776 and then Defining_Entity (Decl) = Typ
778 if Sloc (Decl) > Sloc (Par) then
779 Next_E := Next_Entity (Par);
780 Link_Entities (Par, S);
781 Link_Entities (S, Next_E);
793 -- If partial view is not a type extension, or it appears before the
794 -- subprogram declaration, insert normally at end of entity list.
796 Append_Entity (S, Current_Scope);
797 end Append_Inherited_Subprogram;
799 -----------------------------------------
800 -- Apply_Compile_Time_Constraint_Error --
801 -----------------------------------------
803 procedure Apply_Compile_Time_Constraint_Error
806 Reason : RT_Exception_Code;
807 Ent : Entity_Id := Empty;
808 Typ : Entity_Id := Empty;
809 Loc : Source_Ptr := No_Location;
810 Rep : Boolean := True;
811 Warn : Boolean := False)
813 Stat : constant Boolean := Is_Static_Expression (N);
814 R_Stat : constant Node_Id :=
815 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
826 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
828 -- In GNATprove mode, do not replace the node with an exception raised.
829 -- In such a case, either the call to Compile_Time_Constraint_Error
830 -- issues an error which stops analysis, or it issues a warning in
831 -- a few cases where a suitable check flag is set for GNATprove to
832 -- generate a check message.
834 if not Rep or GNATprove_Mode then
838 -- Now we replace the node by an N_Raise_Constraint_Error node
839 -- This does not need reanalyzing, so set it as analyzed now.
842 Set_Analyzed (N, True);
845 Set_Raises_Constraint_Error (N);
847 -- Now deal with possible local raise handling
849 Possible_Local_Raise (N, Standard_Constraint_Error);
851 -- If the original expression was marked as static, the result is
852 -- still marked as static, but the Raises_Constraint_Error flag is
853 -- always set so that further static evaluation is not attempted.
856 Set_Is_Static_Expression (N);
858 end Apply_Compile_Time_Constraint_Error;
860 ---------------------------
861 -- Async_Readers_Enabled --
862 ---------------------------
864 function Async_Readers_Enabled (Id : Entity_Id) return Boolean is
866 return Has_Enabled_Property (Id, Name_Async_Readers);
867 end Async_Readers_Enabled;
869 ---------------------------
870 -- Async_Writers_Enabled --
871 ---------------------------
873 function Async_Writers_Enabled (Id : Entity_Id) return Boolean is
875 return Has_Enabled_Property (Id, Name_Async_Writers);
876 end Async_Writers_Enabled;
878 --------------------------------------
879 -- Available_Full_View_Of_Component --
880 --------------------------------------
882 function Available_Full_View_Of_Component (T : Entity_Id) return Boolean is
883 ST : constant Entity_Id := Scope (T);
884 SCT : constant Entity_Id := Scope (Component_Type (T));
886 return In_Open_Scopes (ST)
887 and then In_Open_Scopes (SCT)
888 and then Scope_Depth (ST) >= Scope_Depth (SCT);
889 end Available_Full_View_Of_Component;
895 procedure Bad_Attribute
898 Warn : Boolean := False)
901 Error_Msg_Warn := Warn;
902 Error_Msg_N ("unrecognized attribute&<<", N);
904 -- Check for possible misspelling
906 Error_Msg_Name_1 := First_Attribute_Name;
907 while Error_Msg_Name_1 <= Last_Attribute_Name loop
908 if Is_Bad_Spelling_Of (Nam, Error_Msg_Name_1) then
909 Error_Msg_N -- CODEFIX
910 ("\possible misspelling of %<<", N);
914 Error_Msg_Name_1 := Error_Msg_Name_1 + 1;
918 --------------------------------
919 -- Bad_Predicated_Subtype_Use --
920 --------------------------------
922 procedure Bad_Predicated_Subtype_Use
926 Suggest_Static : Boolean := False)
931 -- Avoid cascaded errors
933 if Error_Posted (N) then
937 if Inside_A_Generic then
938 Gen := Current_Scope;
939 while Present (Gen) and then Ekind (Gen) /= E_Generic_Package loop
947 if Is_Generic_Formal (Typ) and then Is_Discrete_Type (Typ) then
948 Set_No_Predicate_On_Actual (Typ);
951 elsif Has_Predicates (Typ) then
952 if Is_Generic_Actual_Type (Typ) then
954 -- The restriction on loop parameters is only that the type
955 -- should have no dynamic predicates.
957 if Nkind (Parent (N)) = N_Loop_Parameter_Specification
958 and then not Has_Dynamic_Predicate_Aspect (Typ)
959 and then Is_OK_Static_Subtype (Typ)
964 Gen := Current_Scope;
965 while not Is_Generic_Instance (Gen) loop
969 pragma Assert (Present (Gen));
971 if Ekind (Gen) = E_Package and then In_Package_Body (Gen) then
972 Error_Msg_Warn := SPARK_Mode /= On;
973 Error_Msg_FE (Msg & "<<", N, Typ);
974 Error_Msg_F ("\Program_Error [<<", N);
977 Make_Raise_Program_Error (Sloc (N),
978 Reason => PE_Bad_Predicated_Generic_Type));
981 Error_Msg_FE (Msg & "<<", N, Typ);
985 Error_Msg_FE (Msg, N, Typ);
988 -- Emit an optional suggestion on how to remedy the error if the
989 -- context warrants it.
991 if Suggest_Static and then Has_Static_Predicate (Typ) then
992 Error_Msg_FE ("\predicate of & should be marked static", N, Typ);
995 end Bad_Predicated_Subtype_Use;
997 -----------------------------------------
998 -- Bad_Unordered_Enumeration_Reference --
999 -----------------------------------------
1001 function Bad_Unordered_Enumeration_Reference
1003 T : Entity_Id) return Boolean
1006 return Is_Enumeration_Type (T)
1007 and then Warn_On_Unordered_Enumeration_Type
1008 and then not Is_Generic_Type (T)
1009 and then Comes_From_Source (N)
1010 and then not Has_Pragma_Ordered (T)
1011 and then not In_Same_Extended_Unit (N, T);
1012 end Bad_Unordered_Enumeration_Reference;
1014 ----------------------------
1015 -- Begin_Keyword_Location --
1016 ----------------------------
1018 function Begin_Keyword_Location (N : Node_Id) return Source_Ptr is
1022 pragma Assert (Nkind_In (N, N_Block_Statement,
1028 HSS := Handled_Statement_Sequence (N);
1030 -- When the handled sequence of statements comes from source, the
1031 -- location of the "begin" keyword is that of the sequence itself.
1032 -- Note that an internal construct may inherit a source sequence.
1034 if Comes_From_Source (HSS) then
1037 -- The parser generates an internal handled sequence of statements to
1038 -- capture the location of the "begin" keyword if present in the source.
1039 -- Since there are no source statements, the location of the "begin"
1040 -- keyword is effectively that of the "end" keyword.
1042 elsif Comes_From_Source (N) then
1045 -- Otherwise the construct is internal and should carry the location of
1046 -- the original construct which prompted its creation.
1051 end Begin_Keyword_Location;
1053 --------------------------
1054 -- Build_Actual_Subtype --
1055 --------------------------
1057 function Build_Actual_Subtype
1059 N : Node_Or_Entity_Id) return Node_Id
1062 -- Normally Sloc (N), but may point to corresponding body in some cases
1064 Constraints : List_Id;
1070 Disc_Type : Entity_Id;
1076 if Nkind (N) = N_Defining_Identifier then
1077 Obj := New_Occurrence_Of (N, Loc);
1079 -- If this is a formal parameter of a subprogram declaration, and
1080 -- we are compiling the body, we want the declaration for the
1081 -- actual subtype to carry the source position of the body, to
1082 -- prevent anomalies in gdb when stepping through the code.
1084 if Is_Formal (N) then
1086 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
1088 if Nkind (Decl) = N_Subprogram_Declaration
1089 and then Present (Corresponding_Body (Decl))
1091 Loc := Sloc (Corresponding_Body (Decl));
1100 if Is_Array_Type (T) then
1101 Constraints := New_List;
1102 for J in 1 .. Number_Dimensions (T) loop
1104 -- Build an array subtype declaration with the nominal subtype and
1105 -- the bounds of the actual. Add the declaration in front of the
1106 -- local declarations for the subprogram, for analysis before any
1107 -- reference to the formal in the body.
1110 Make_Attribute_Reference (Loc,
1112 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
1113 Attribute_Name => Name_First,
1114 Expressions => New_List (
1115 Make_Integer_Literal (Loc, J)));
1118 Make_Attribute_Reference (Loc,
1120 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
1121 Attribute_Name => Name_Last,
1122 Expressions => New_List (
1123 Make_Integer_Literal (Loc, J)));
1125 Append (Make_Range (Loc, Lo, Hi), Constraints);
1128 -- If the type has unknown discriminants there is no constrained
1129 -- subtype to build. This is never called for a formal or for a
1130 -- lhs, so returning the type is ok ???
1132 elsif Has_Unknown_Discriminants (T) then
1136 Constraints := New_List;
1138 -- Type T is a generic derived type, inherit the discriminants from
1141 if Is_Private_Type (T)
1142 and then No (Full_View (T))
1144 -- T was flagged as an error if it was declared as a formal
1145 -- derived type with known discriminants. In this case there
1146 -- is no need to look at the parent type since T already carries
1147 -- its own discriminants.
1149 and then not Error_Posted (T)
1151 Disc_Type := Etype (Base_Type (T));
1156 Discr := First_Discriminant (Disc_Type);
1157 while Present (Discr) loop
1158 Append_To (Constraints,
1159 Make_Selected_Component (Loc,
1161 Duplicate_Subexpr_No_Checks (Obj),
1162 Selector_Name => New_Occurrence_Of (Discr, Loc)));
1163 Next_Discriminant (Discr);
1167 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
1168 Set_Is_Internal (Subt);
1171 Make_Subtype_Declaration (Loc,
1172 Defining_Identifier => Subt,
1173 Subtype_Indication =>
1174 Make_Subtype_Indication (Loc,
1175 Subtype_Mark => New_Occurrence_Of (T, Loc),
1177 Make_Index_Or_Discriminant_Constraint (Loc,
1178 Constraints => Constraints)));
1180 Mark_Rewrite_Insertion (Decl);
1182 end Build_Actual_Subtype;
1184 ---------------------------------------
1185 -- Build_Actual_Subtype_Of_Component --
1186 ---------------------------------------
1188 function Build_Actual_Subtype_Of_Component
1190 N : Node_Id) return Node_Id
1192 Loc : constant Source_Ptr := Sloc (N);
1193 P : constant Node_Id := Prefix (N);
1197 Index_Typ : Entity_Id;
1198 Sel : Entity_Id := Empty;
1200 Desig_Typ : Entity_Id;
1201 -- This is either a copy of T, or if T is an access type, then it is
1202 -- the directly designated type of this access type.
1204 function Build_Access_Record_Constraint (C : List_Id) return List_Id;
1205 -- If the record component is a constrained access to the current
1206 -- record, the subtype has not been constructed during analysis of
1207 -- the enclosing record type (see Analyze_Access). In that case, build
1208 -- a constrained access subtype after replacing references to the
1209 -- enclosing discriminants with the corresponding discriminant values
1212 function Build_Actual_Array_Constraint return List_Id;
1213 -- If one or more of the bounds of the component depends on
1214 -- discriminants, build actual constraint using the discriminants
1215 -- of the prefix, as above.
1217 function Build_Actual_Record_Constraint return List_Id;
1218 -- Similar to previous one, for discriminated components constrained
1219 -- by the discriminant of the enclosing object.
1221 -----------------------------------
1222 -- Build_Actual_Array_Constraint --
1223 -----------------------------------
1225 function Build_Actual_Array_Constraint return List_Id is
1226 Constraints : constant List_Id := New_List;
1234 Indx := First_Index (Desig_Typ);
1235 while Present (Indx) loop
1236 Old_Lo := Type_Low_Bound (Etype (Indx));
1237 Old_Hi := Type_High_Bound (Etype (Indx));
1239 if Denotes_Discriminant (Old_Lo) then
1241 Make_Selected_Component (Loc,
1242 Prefix => New_Copy_Tree (P),
1243 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
1246 Lo := New_Copy_Tree (Old_Lo);
1248 -- The new bound will be reanalyzed in the enclosing
1249 -- declaration. For literal bounds that come from a type
1250 -- declaration, the type of the context must be imposed, so
1251 -- insure that analysis will take place. For non-universal
1252 -- types this is not strictly necessary.
1254 Set_Analyzed (Lo, False);
1257 if Denotes_Discriminant (Old_Hi) then
1259 Make_Selected_Component (Loc,
1260 Prefix => New_Copy_Tree (P),
1261 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
1264 Hi := New_Copy_Tree (Old_Hi);
1265 Set_Analyzed (Hi, False);
1268 Append (Make_Range (Loc, Lo, Hi), Constraints);
1273 end Build_Actual_Array_Constraint;
1275 ------------------------------------
1276 -- Build_Actual_Record_Constraint --
1277 ------------------------------------
1279 function Build_Actual_Record_Constraint return List_Id is
1280 Constraints : constant List_Id := New_List;
1285 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1286 while Present (D) loop
1287 if Denotes_Discriminant (Node (D)) then
1288 D_Val := Make_Selected_Component (Loc,
1289 Prefix => New_Copy_Tree (P),
1290 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
1293 D_Val := New_Copy_Tree (Node (D));
1296 Append (D_Val, Constraints);
1301 end Build_Actual_Record_Constraint;
1303 ------------------------------------
1304 -- Build_Access_Record_Constraint --
1305 ------------------------------------
1307 function Build_Access_Record_Constraint (C : List_Id) return List_Id is
1308 Constraints : constant List_Id := New_List;
1313 -- Retrieve the constraint from the component declaration, because
1314 -- the component subtype has not been constructed and the component
1315 -- type is an unconstrained access.
1318 while Present (D) loop
1319 if Nkind (D) = N_Discriminant_Association
1320 and then Denotes_Discriminant (Expression (D))
1322 D_Val := New_Copy_Tree (D);
1323 Set_Expression (D_Val,
1324 Make_Selected_Component (Loc,
1325 Prefix => New_Copy_Tree (P),
1327 New_Occurrence_Of (Entity (Expression (D)), Loc)));
1329 elsif Denotes_Discriminant (D) then
1330 D_Val := Make_Selected_Component (Loc,
1331 Prefix => New_Copy_Tree (P),
1332 Selector_Name => New_Occurrence_Of (Entity (D), Loc));
1335 D_Val := New_Copy_Tree (D);
1338 Append (D_Val, Constraints);
1343 end Build_Access_Record_Constraint;
1345 -- Start of processing for Build_Actual_Subtype_Of_Component
1348 -- The subtype does not need to be created for a selected component
1349 -- in a Spec_Expression.
1351 if In_Spec_Expression then
1354 -- More comments for the rest of this body would be good ???
1356 elsif Nkind (N) = N_Explicit_Dereference then
1357 if Is_Composite_Type (T)
1358 and then not Is_Constrained (T)
1359 and then not (Is_Class_Wide_Type (T)
1360 and then Is_Constrained (Root_Type (T)))
1361 and then not Has_Unknown_Discriminants (T)
1363 -- If the type of the dereference is already constrained, it is an
1366 if Is_Array_Type (Etype (N))
1367 and then Is_Constrained (Etype (N))
1371 Remove_Side_Effects (P);
1372 return Build_Actual_Subtype (T, N);
1379 elsif Nkind (N) = N_Selected_Component then
1380 -- The entity of the selected component allows us to retrieve
1381 -- the original constraint from its component declaration.
1383 Sel := Entity (Selector_Name (N));
1384 if Nkind (Parent (Sel)) /= N_Component_Declaration then
1389 if Is_Access_Type (T) then
1390 Desig_Typ := Designated_Type (T);
1396 if Ekind (Desig_Typ) = E_Array_Subtype then
1397 Id := First_Index (Desig_Typ);
1399 -- Check whether an index bound is constrained by a discriminant.
1401 while Present (Id) loop
1402 Index_Typ := Underlying_Type (Etype (Id));
1404 if Denotes_Discriminant (Type_Low_Bound (Index_Typ))
1406 Denotes_Discriminant (Type_High_Bound (Index_Typ))
1408 Remove_Side_Effects (P);
1410 Build_Component_Subtype
1411 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
1417 elsif Is_Composite_Type (Desig_Typ)
1418 and then Has_Discriminants (Desig_Typ)
1419 and then not Is_Empty_Elmt_List (Discriminant_Constraint (Desig_Typ))
1420 and then not Has_Unknown_Discriminants (Desig_Typ)
1422 if Is_Private_Type (Desig_Typ)
1423 and then No (Discriminant_Constraint (Desig_Typ))
1425 Desig_Typ := Full_View (Desig_Typ);
1428 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1429 while Present (D) loop
1430 if Denotes_Discriminant (Node (D)) then
1431 Remove_Side_Effects (P);
1433 Build_Component_Subtype (
1434 Build_Actual_Record_Constraint, Loc, Base_Type (T));
1440 -- Special processing for an access record component that is
1441 -- the target of an assignment. If the designated type is an
1442 -- unconstrained discriminated record we create its actual
1445 elsif Ekind (T) = E_Access_Type
1446 and then Present (Sel)
1447 and then Has_Per_Object_Constraint (Sel)
1448 and then Nkind (Parent (N)) = N_Assignment_Statement
1449 and then N = Name (Parent (N))
1450 -- and then not Inside_Init_Proc
1451 -- and then Has_Discriminants (Desig_Typ)
1452 -- and then not Is_Constrained (Desig_Typ)
1455 S_Indic : constant Node_Id :=
1457 (Component_Definition (Parent (Sel))));
1460 if Nkind (S_Indic) = N_Subtype_Indication then
1461 Discs := Constraints (Constraint (S_Indic));
1463 Remove_Side_Effects (P);
1464 return Build_Component_Subtype
1465 (Build_Access_Record_Constraint (Discs), Loc, T);
1472 -- If none of the above, the actual and nominal subtypes are the same
1475 end Build_Actual_Subtype_Of_Component;
1477 ---------------------------------
1478 -- Build_Class_Wide_Clone_Body --
1479 ---------------------------------
1481 procedure Build_Class_Wide_Clone_Body
1482 (Spec_Id : Entity_Id;
1485 Loc : constant Source_Ptr := Sloc (Bod);
1486 Clone_Id : constant Entity_Id := Class_Wide_Clone (Spec_Id);
1487 Clone_Body : Node_Id;
1490 -- The declaration of the class-wide clone was created when the
1491 -- corresponding class-wide condition was analyzed.
1494 Make_Subprogram_Body (Loc,
1496 Copy_Subprogram_Spec (Parent (Clone_Id)),
1497 Declarations => Declarations (Bod),
1498 Handled_Statement_Sequence => Handled_Statement_Sequence (Bod));
1500 -- The new operation is internal and overriding indicators do not apply
1501 -- (the original primitive may have carried one).
1503 Set_Must_Override (Specification (Clone_Body), False);
1505 -- If the subprogram body is the proper body of a stub, insert the
1506 -- subprogram after the stub, i.e. the same declarative region as
1507 -- the original sugprogram.
1509 if Nkind (Parent (Bod)) = N_Subunit then
1510 Insert_After (Corresponding_Stub (Parent (Bod)), Clone_Body);
1513 Insert_Before (Bod, Clone_Body);
1516 Analyze (Clone_Body);
1517 end Build_Class_Wide_Clone_Body;
1519 ---------------------------------
1520 -- Build_Class_Wide_Clone_Call --
1521 ---------------------------------
1523 function Build_Class_Wide_Clone_Call
1526 Spec_Id : Entity_Id;
1527 Spec : Node_Id) return Node_Id
1529 Clone_Id : constant Entity_Id := Class_Wide_Clone (Spec_Id);
1530 Par_Type : constant Entity_Id := Find_Dispatching_Type (Spec_Id);
1536 New_F_Spec : Entity_Id;
1537 New_Formal : Entity_Id;
1540 Actuals := Empty_List;
1541 Formal := First_Formal (Spec_Id);
1542 New_F_Spec := First (Parameter_Specifications (Spec));
1544 -- Build parameter association for call to class-wide clone.
1546 while Present (Formal) loop
1547 New_Formal := Defining_Identifier (New_F_Spec);
1549 -- If controlling argument and operation is inherited, add conversion
1550 -- to parent type for the call.
1552 if Etype (Formal) = Par_Type
1553 and then not Is_Empty_List (Decls)
1556 Make_Type_Conversion (Loc,
1557 New_Occurrence_Of (Par_Type, Loc),
1558 New_Occurrence_Of (New_Formal, Loc)));
1561 Append_To (Actuals, New_Occurrence_Of (New_Formal, Loc));
1564 Next_Formal (Formal);
1568 if Ekind (Spec_Id) = E_Procedure then
1570 Make_Procedure_Call_Statement (Loc,
1571 Name => New_Occurrence_Of (Clone_Id, Loc),
1572 Parameter_Associations => Actuals);
1575 Make_Simple_Return_Statement (Loc,
1577 Make_Function_Call (Loc,
1578 Name => New_Occurrence_Of (Clone_Id, Loc),
1579 Parameter_Associations => Actuals));
1583 Make_Subprogram_Body (Loc,
1585 Copy_Subprogram_Spec (Spec),
1586 Declarations => Decls,
1587 Handled_Statement_Sequence =>
1588 Make_Handled_Sequence_Of_Statements (Loc,
1589 Statements => New_List (Call),
1590 End_Label => Make_Identifier (Loc, Chars (Spec_Id))));
1593 end Build_Class_Wide_Clone_Call;
1595 ---------------------------------
1596 -- Build_Class_Wide_Clone_Decl --
1597 ---------------------------------
1599 procedure Build_Class_Wide_Clone_Decl (Spec_Id : Entity_Id) is
1600 Loc : constant Source_Ptr := Sloc (Spec_Id);
1601 Clone_Id : constant Entity_Id :=
1602 Make_Defining_Identifier (Loc,
1603 New_External_Name (Chars (Spec_Id), Suffix => "CL"));
1609 Spec := Copy_Subprogram_Spec (Parent (Spec_Id));
1610 Set_Must_Override (Spec, False);
1611 Set_Must_Not_Override (Spec, False);
1612 Set_Defining_Unit_Name (Spec, Clone_Id);
1614 Decl := Make_Subprogram_Declaration (Loc, Spec);
1615 Append (Decl, List_Containing (Unit_Declaration_Node (Spec_Id)));
1617 -- Link clone to original subprogram, for use when building body and
1618 -- wrapper call to inherited operation.
1620 Set_Class_Wide_Clone (Spec_Id, Clone_Id);
1622 -- Inherit debug info flag from Spec_Id to Clone_Id to allow debugging
1623 -- of the class-wide clone subprogram.
1625 if Needs_Debug_Info (Spec_Id) then
1626 Set_Debug_Info_Needed (Clone_Id);
1628 end Build_Class_Wide_Clone_Decl;
1630 -----------------------------
1631 -- Build_Component_Subtype --
1632 -----------------------------
1634 function Build_Component_Subtype
1637 T : Entity_Id) return Node_Id
1643 -- Unchecked_Union components do not require component subtypes
1645 if Is_Unchecked_Union (T) then
1649 Subt := Make_Temporary (Loc, 'S');
1650 Set_Is_Internal (Subt);
1653 Make_Subtype_Declaration (Loc,
1654 Defining_Identifier => Subt,
1655 Subtype_Indication =>
1656 Make_Subtype_Indication (Loc,
1657 Subtype_Mark => New_Occurrence_Of (Base_Type (T), Loc),
1659 Make_Index_Or_Discriminant_Constraint (Loc,
1660 Constraints => C)));
1662 Mark_Rewrite_Insertion (Decl);
1664 end Build_Component_Subtype;
1666 ---------------------------
1667 -- Build_Default_Subtype --
1668 ---------------------------
1670 function Build_Default_Subtype
1672 N : Node_Id) return Entity_Id
1674 Loc : constant Source_Ptr := Sloc (N);
1678 -- The base type that is to be constrained by the defaults
1681 if not Has_Discriminants (T) or else Is_Constrained (T) then
1685 Bas := Base_Type (T);
1687 -- If T is non-private but its base type is private, this is the
1688 -- completion of a subtype declaration whose parent type is private
1689 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1690 -- are to be found in the full view of the base. Check that the private
1691 -- status of T and its base differ.
1693 if Is_Private_Type (Bas)
1694 and then not Is_Private_Type (T)
1695 and then Present (Full_View (Bas))
1697 Bas := Full_View (Bas);
1700 Disc := First_Discriminant (T);
1702 if No (Discriminant_Default_Value (Disc)) then
1707 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
1708 Constraints : constant List_Id := New_List;
1712 while Present (Disc) loop
1713 Append_To (Constraints,
1714 New_Copy_Tree (Discriminant_Default_Value (Disc)));
1715 Next_Discriminant (Disc);
1719 Make_Subtype_Declaration (Loc,
1720 Defining_Identifier => Act,
1721 Subtype_Indication =>
1722 Make_Subtype_Indication (Loc,
1723 Subtype_Mark => New_Occurrence_Of (Bas, Loc),
1725 Make_Index_Or_Discriminant_Constraint (Loc,
1726 Constraints => Constraints)));
1728 Insert_Action (N, Decl);
1730 -- If the context is a component declaration the subtype declaration
1731 -- will be analyzed when the enclosing type is frozen, otherwise do
1734 if Ekind (Current_Scope) /= E_Record_Type then
1740 end Build_Default_Subtype;
1742 --------------------------------------------
1743 -- Build_Discriminal_Subtype_Of_Component --
1744 --------------------------------------------
1746 function Build_Discriminal_Subtype_Of_Component
1747 (T : Entity_Id) return Node_Id
1749 Loc : constant Source_Ptr := Sloc (T);
1753 function Build_Discriminal_Array_Constraint return List_Id;
1754 -- If one or more of the bounds of the component depends on
1755 -- discriminants, build actual constraint using the discriminants
1758 function Build_Discriminal_Record_Constraint return List_Id;
1759 -- Similar to previous one, for discriminated components constrained by
1760 -- the discriminant of the enclosing object.
1762 ----------------------------------------
1763 -- Build_Discriminal_Array_Constraint --
1764 ----------------------------------------
1766 function Build_Discriminal_Array_Constraint return List_Id is
1767 Constraints : constant List_Id := New_List;
1775 Indx := First_Index (T);
1776 while Present (Indx) loop
1777 Old_Lo := Type_Low_Bound (Etype (Indx));
1778 Old_Hi := Type_High_Bound (Etype (Indx));
1780 if Denotes_Discriminant (Old_Lo) then
1781 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
1784 Lo := New_Copy_Tree (Old_Lo);
1787 if Denotes_Discriminant (Old_Hi) then
1788 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
1791 Hi := New_Copy_Tree (Old_Hi);
1794 Append (Make_Range (Loc, Lo, Hi), Constraints);
1799 end Build_Discriminal_Array_Constraint;
1801 -----------------------------------------
1802 -- Build_Discriminal_Record_Constraint --
1803 -----------------------------------------
1805 function Build_Discriminal_Record_Constraint return List_Id is
1806 Constraints : constant List_Id := New_List;
1811 D := First_Elmt (Discriminant_Constraint (T));
1812 while Present (D) loop
1813 if Denotes_Discriminant (Node (D)) then
1815 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
1817 D_Val := New_Copy_Tree (Node (D));
1820 Append (D_Val, Constraints);
1825 end Build_Discriminal_Record_Constraint;
1827 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1830 if Ekind (T) = E_Array_Subtype then
1831 Id := First_Index (T);
1832 while Present (Id) loop
1833 if Denotes_Discriminant (Type_Low_Bound (Etype (Id)))
1835 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
1837 return Build_Component_Subtype
1838 (Build_Discriminal_Array_Constraint, Loc, T);
1844 elsif Ekind (T) = E_Record_Subtype
1845 and then Has_Discriminants (T)
1846 and then not Has_Unknown_Discriminants (T)
1848 D := First_Elmt (Discriminant_Constraint (T));
1849 while Present (D) loop
1850 if Denotes_Discriminant (Node (D)) then
1851 return Build_Component_Subtype
1852 (Build_Discriminal_Record_Constraint, Loc, T);
1859 -- If none of the above, the actual and nominal subtypes are the same
1862 end Build_Discriminal_Subtype_Of_Component;
1864 ------------------------------
1865 -- Build_Elaboration_Entity --
1866 ------------------------------
1868 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
1869 Loc : constant Source_Ptr := Sloc (N);
1871 Elab_Ent : Entity_Id;
1873 procedure Set_Package_Name (Ent : Entity_Id);
1874 -- Given an entity, sets the fully qualified name of the entity in
1875 -- Name_Buffer, with components separated by double underscores. This
1876 -- is a recursive routine that climbs the scope chain to Standard.
1878 ----------------------
1879 -- Set_Package_Name --
1880 ----------------------
1882 procedure Set_Package_Name (Ent : Entity_Id) is
1884 if Scope (Ent) /= Standard_Standard then
1885 Set_Package_Name (Scope (Ent));
1888 Nam : constant String := Get_Name_String (Chars (Ent));
1890 Name_Buffer (Name_Len + 1) := '_';
1891 Name_Buffer (Name_Len + 2) := '_';
1892 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
1893 Name_Len := Name_Len + Nam'Length + 2;
1897 Get_Name_String (Chars (Ent));
1899 end Set_Package_Name;
1901 -- Start of processing for Build_Elaboration_Entity
1904 -- Ignore call if already constructed
1906 if Present (Elaboration_Entity (Spec_Id)) then
1909 -- Do not generate an elaboration entity in GNATprove move because the
1910 -- elaboration counter is a form of expansion.
1912 elsif GNATprove_Mode then
1915 -- See if we need elaboration entity
1917 -- We always need an elaboration entity when preserving control flow, as
1918 -- we want to remain explicit about the unit's elaboration order.
1920 elsif Opt.Suppress_Control_Flow_Optimizations then
1923 -- We always need an elaboration entity for the dynamic elaboration
1924 -- model, since it is needed to properly generate the PE exception for
1925 -- access before elaboration.
1927 elsif Dynamic_Elaboration_Checks then
1930 -- For the static model, we don't need the elaboration counter if this
1931 -- unit is sure to have no elaboration code, since that means there
1932 -- is no elaboration unit to be called. Note that we can't just decide
1933 -- after the fact by looking to see whether there was elaboration code,
1934 -- because that's too late to make this decision.
1936 elsif Restriction_Active (No_Elaboration_Code) then
1939 -- Similarly, for the static model, we can skip the elaboration counter
1940 -- if we have the No_Multiple_Elaboration restriction, since for the
1941 -- static model, that's the only purpose of the counter (to avoid
1942 -- multiple elaboration).
1944 elsif Restriction_Active (No_Multiple_Elaboration) then
1948 -- Here we need the elaboration entity
1950 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1951 -- name with dots replaced by double underscore. We have to manually
1952 -- construct this name, since it will be elaborated in the outer scope,
1953 -- and thus will not have the unit name automatically prepended.
1955 Set_Package_Name (Spec_Id);
1956 Add_Str_To_Name_Buffer ("_E");
1958 -- Create elaboration counter
1960 Elab_Ent := Make_Defining_Identifier (Loc, Chars => Name_Find);
1961 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
1964 Make_Object_Declaration (Loc,
1965 Defining_Identifier => Elab_Ent,
1966 Object_Definition =>
1967 New_Occurrence_Of (Standard_Short_Integer, Loc),
1968 Expression => Make_Integer_Literal (Loc, Uint_0));
1970 Push_Scope (Standard_Standard);
1971 Add_Global_Declaration (Decl);
1974 -- Reset True_Constant indication, since we will indeed assign a value
1975 -- to the variable in the binder main. We also kill the Current_Value
1976 -- and Last_Assignment fields for the same reason.
1978 Set_Is_True_Constant (Elab_Ent, False);
1979 Set_Current_Value (Elab_Ent, Empty);
1980 Set_Last_Assignment (Elab_Ent, Empty);
1982 -- We do not want any further qualification of the name (if we did not
1983 -- do this, we would pick up the name of the generic package in the case
1984 -- of a library level generic instantiation).
1986 Set_Has_Qualified_Name (Elab_Ent);
1987 Set_Has_Fully_Qualified_Name (Elab_Ent);
1988 end Build_Elaboration_Entity;
1990 --------------------------------
1991 -- Build_Explicit_Dereference --
1992 --------------------------------
1994 procedure Build_Explicit_Dereference
1998 Loc : constant Source_Ptr := Sloc (Expr);
2003 -- An entity of a type with a reference aspect is overloaded with
2004 -- both interpretations: with and without the dereference. Now that
2005 -- the dereference is made explicit, set the type of the node properly,
2006 -- to prevent anomalies in the backend. Same if the expression is an
2007 -- overloaded function call whose return type has a reference aspect.
2009 if Is_Entity_Name (Expr) then
2010 Set_Etype (Expr, Etype (Entity (Expr)));
2012 -- The designated entity will not be examined again when resolving
2013 -- the dereference, so generate a reference to it now.
2015 Generate_Reference (Entity (Expr), Expr);
2017 elsif Nkind (Expr) = N_Function_Call then
2019 -- If the name of the indexing function is overloaded, locate the one
2020 -- whose return type has an implicit dereference on the desired
2021 -- discriminant, and set entity and type of function call.
2023 if Is_Overloaded (Name (Expr)) then
2024 Get_First_Interp (Name (Expr), I, It);
2026 while Present (It.Nam) loop
2027 if Ekind ((It.Typ)) = E_Record_Type
2028 and then First_Entity ((It.Typ)) = Disc
2030 Set_Entity (Name (Expr), It.Nam);
2031 Set_Etype (Name (Expr), Etype (It.Nam));
2035 Get_Next_Interp (I, It);
2039 -- Set type of call from resolved function name.
2041 Set_Etype (Expr, Etype (Name (Expr)));
2044 Set_Is_Overloaded (Expr, False);
2046 -- The expression will often be a generalized indexing that yields a
2047 -- container element that is then dereferenced, in which case the
2048 -- generalized indexing call is also non-overloaded.
2050 if Nkind (Expr) = N_Indexed_Component
2051 and then Present (Generalized_Indexing (Expr))
2053 Set_Is_Overloaded (Generalized_Indexing (Expr), False);
2057 Make_Explicit_Dereference (Loc,
2059 Make_Selected_Component (Loc,
2060 Prefix => Relocate_Node (Expr),
2061 Selector_Name => New_Occurrence_Of (Disc, Loc))));
2062 Set_Etype (Prefix (Expr), Etype (Disc));
2063 Set_Etype (Expr, Designated_Type (Etype (Disc)));
2064 end Build_Explicit_Dereference;
2066 ---------------------------
2067 -- Build_Overriding_Spec --
2068 ---------------------------
2070 function Build_Overriding_Spec
2072 Typ : Entity_Id) return Node_Id
2074 Loc : constant Source_Ptr := Sloc (Typ);
2075 Par_Typ : constant Entity_Id := Find_Dispatching_Type (Op);
2076 Spec : constant Node_Id := Specification (Unit_Declaration_Node (Op));
2078 Formal_Spec : Node_Id;
2079 Formal_Type : Node_Id;
2083 New_Spec := Copy_Subprogram_Spec (Spec);
2085 Formal_Spec := First (Parameter_Specifications (New_Spec));
2086 while Present (Formal_Spec) loop
2087 Formal_Type := Parameter_Type (Formal_Spec);
2089 if Is_Entity_Name (Formal_Type)
2090 and then Entity (Formal_Type) = Par_Typ
2092 Rewrite (Formal_Type, New_Occurrence_Of (Typ, Loc));
2095 -- Nothing needs to be done for access parameters
2101 end Build_Overriding_Spec;
2103 -----------------------------------
2104 -- Cannot_Raise_Constraint_Error --
2105 -----------------------------------
2107 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
2109 if Compile_Time_Known_Value (Expr) then
2112 elsif Do_Range_Check (Expr) then
2115 elsif Raises_Constraint_Error (Expr) then
2119 case Nkind (Expr) is
2120 when N_Identifier =>
2123 when N_Expanded_Name =>
2126 when N_Selected_Component =>
2127 return not Do_Discriminant_Check (Expr);
2129 when N_Attribute_Reference =>
2130 if Do_Overflow_Check (Expr) then
2133 elsif No (Expressions (Expr)) then
2141 N := First (Expressions (Expr));
2142 while Present (N) loop
2143 if Cannot_Raise_Constraint_Error (N) then
2154 when N_Type_Conversion =>
2155 if Do_Overflow_Check (Expr)
2156 or else Do_Length_Check (Expr)
2157 or else Do_Tag_Check (Expr)
2161 return Cannot_Raise_Constraint_Error (Expression (Expr));
2164 when N_Unchecked_Type_Conversion =>
2165 return Cannot_Raise_Constraint_Error (Expression (Expr));
2168 if Do_Overflow_Check (Expr) then
2171 return Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
2178 if Do_Division_Check (Expr)
2180 Do_Overflow_Check (Expr)
2185 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
2187 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
2206 | N_Op_Shift_Right_Arithmetic
2210 if Do_Overflow_Check (Expr) then
2214 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
2216 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
2223 end Cannot_Raise_Constraint_Error;
2225 -----------------------------------------
2226 -- Check_Dynamically_Tagged_Expression --
2227 -----------------------------------------
2229 procedure Check_Dynamically_Tagged_Expression
2232 Related_Nod : Node_Id)
2235 pragma Assert (Is_Tagged_Type (Typ));
2237 -- In order to avoid spurious errors when analyzing the expanded code,
2238 -- this check is done only for nodes that come from source and for
2239 -- actuals of generic instantiations.
2241 if (Comes_From_Source (Related_Nod)
2242 or else In_Generic_Actual (Expr))
2243 and then (Is_Class_Wide_Type (Etype (Expr))
2244 or else Is_Dynamically_Tagged (Expr))
2245 and then not Is_Class_Wide_Type (Typ)
2247 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
2249 end Check_Dynamically_Tagged_Expression;
2251 --------------------------
2252 -- Check_Fully_Declared --
2253 --------------------------
2255 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
2257 if Ekind (T) = E_Incomplete_Type then
2259 -- Ada 2005 (AI-50217): If the type is available through a limited
2260 -- with_clause, verify that its full view has been analyzed.
2262 if From_Limited_With (T)
2263 and then Present (Non_Limited_View (T))
2264 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
2266 -- The non-limited view is fully declared
2272 ("premature usage of incomplete}", N, First_Subtype (T));
2275 -- Need comments for these tests ???
2277 elsif Has_Private_Component (T)
2278 and then not Is_Generic_Type (Root_Type (T))
2279 and then not In_Spec_Expression
2281 -- Special case: if T is the anonymous type created for a single
2282 -- task or protected object, use the name of the source object.
2284 if Is_Concurrent_Type (T)
2285 and then not Comes_From_Source (T)
2286 and then Nkind (N) = N_Object_Declaration
2289 ("type of& has incomplete component",
2290 N, Defining_Identifier (N));
2293 ("premature usage of incomplete}",
2294 N, First_Subtype (T));
2297 end Check_Fully_Declared;
2299 -------------------------------------------
2300 -- Check_Function_With_Address_Parameter --
2301 -------------------------------------------
2303 procedure Check_Function_With_Address_Parameter (Subp_Id : Entity_Id) is
2308 F := First_Formal (Subp_Id);
2309 while Present (F) loop
2312 if Is_Private_Type (T) and then Present (Full_View (T)) then
2316 if Is_Descendant_Of_Address (T) or else Is_Limited_Type (T) then
2317 Set_Is_Pure (Subp_Id, False);
2323 end Check_Function_With_Address_Parameter;
2325 -------------------------------------
2326 -- Check_Function_Writable_Actuals --
2327 -------------------------------------
2329 procedure Check_Function_Writable_Actuals (N : Node_Id) is
2330 Writable_Actuals_List : Elist_Id := No_Elist;
2331 Identifiers_List : Elist_Id := No_Elist;
2332 Aggr_Error_Node : Node_Id := Empty;
2333 Error_Node : Node_Id := Empty;
2335 procedure Collect_Identifiers (N : Node_Id);
2336 -- In a single traversal of subtree N collect in Writable_Actuals_List
2337 -- all the actuals of functions with writable actuals, and in the list
2338 -- Identifiers_List collect all the identifiers that are not actuals of
2339 -- functions with writable actuals. If a writable actual is referenced
2340 -- twice as writable actual then Error_Node is set to reference its
2341 -- second occurrence, the error is reported, and the tree traversal
2344 procedure Preanalyze_Without_Errors (N : Node_Id);
2345 -- Preanalyze N without reporting errors. Very dubious, you can't just
2346 -- go analyzing things more than once???
2348 -------------------------
2349 -- Collect_Identifiers --
2350 -------------------------
2352 procedure Collect_Identifiers (N : Node_Id) is
2354 function Check_Node (N : Node_Id) return Traverse_Result;
2355 -- Process a single node during the tree traversal to collect the
2356 -- writable actuals of functions and all the identifiers which are
2357 -- not writable actuals of functions.
2359 function Contains (List : Elist_Id; N : Node_Id) return Boolean;
2360 -- Returns True if List has a node whose Entity is Entity (N)
2366 function Check_Node (N : Node_Id) return Traverse_Result is
2367 Is_Writable_Actual : Boolean := False;
2371 if Nkind (N) = N_Identifier then
2373 -- No analysis possible if the entity is not decorated
2375 if No (Entity (N)) then
2378 -- Don't collect identifiers of packages, called functions, etc
2380 elsif Ekind_In (Entity (N), E_Package,
2387 -- For rewritten nodes, continue the traversal in the original
2388 -- subtree. Needed to handle aggregates in original expressions
2389 -- extracted from the tree by Remove_Side_Effects.
2391 elsif Is_Rewrite_Substitution (N) then
2392 Collect_Identifiers (Original_Node (N));
2395 -- For now we skip aggregate discriminants, since they require
2396 -- performing the analysis in two phases to identify conflicts:
2397 -- first one analyzing discriminants and second one analyzing
2398 -- the rest of components (since at run time, discriminants are
2399 -- evaluated prior to components): too much computation cost
2400 -- to identify a corner case???
2402 elsif Nkind (Parent (N)) = N_Component_Association
2403 and then Nkind_In (Parent (Parent (N)),
2405 N_Extension_Aggregate)
2408 Choice : constant Node_Id := First (Choices (Parent (N)));
2411 if Ekind (Entity (N)) = E_Discriminant then
2414 elsif Expression (Parent (N)) = N
2415 and then Nkind (Choice) = N_Identifier
2416 and then Ekind (Entity (Choice)) = E_Discriminant
2422 -- Analyze if N is a writable actual of a function
2424 elsif Nkind (Parent (N)) = N_Function_Call then
2426 Call : constant Node_Id := Parent (N);
2431 Id := Get_Called_Entity (Call);
2433 -- In case of previous error, no check is possible
2439 if Ekind_In (Id, E_Function, E_Generic_Function)
2440 and then Has_Out_Or_In_Out_Parameter (Id)
2442 Formal := First_Formal (Id);
2443 Actual := First_Actual (Call);
2444 while Present (Actual) and then Present (Formal) loop
2446 if Ekind_In (Formal, E_Out_Parameter,
2449 Is_Writable_Actual := True;
2455 Next_Formal (Formal);
2456 Next_Actual (Actual);
2462 if Is_Writable_Actual then
2464 -- Skip checking the error in non-elementary types since
2465 -- RM 6.4.1(6.15/3) is restricted to elementary types, but
2466 -- store this actual in Writable_Actuals_List since it is
2467 -- needed to perform checks on other constructs that have
2468 -- arbitrary order of evaluation (for example, aggregates).
2470 if not Is_Elementary_Type (Etype (N)) then
2471 if not Contains (Writable_Actuals_List, N) then
2472 Append_New_Elmt (N, To => Writable_Actuals_List);
2475 -- Second occurrence of an elementary type writable actual
2477 elsif Contains (Writable_Actuals_List, N) then
2479 -- Report the error on the second occurrence of the
2480 -- identifier. We cannot assume that N is the second
2481 -- occurrence (according to their location in the
2482 -- sources), since Traverse_Func walks through Field2
2483 -- last (see comment in the body of Traverse_Func).
2489 Elmt := First_Elmt (Writable_Actuals_List);
2490 while Present (Elmt)
2491 and then Entity (Node (Elmt)) /= Entity (N)
2496 if Sloc (N) > Sloc (Node (Elmt)) then
2499 Error_Node := Node (Elmt);
2503 ("value may be affected by call to & "
2504 & "because order of evaluation is arbitrary",
2509 -- First occurrence of a elementary type writable actual
2512 Append_New_Elmt (N, To => Writable_Actuals_List);
2516 if Identifiers_List = No_Elist then
2517 Identifiers_List := New_Elmt_List;
2520 Append_Unique_Elmt (N, Identifiers_List);
2533 N : Node_Id) return Boolean
2535 pragma Assert (Nkind (N) in N_Has_Entity);
2540 if List = No_Elist then
2544 Elmt := First_Elmt (List);
2545 while Present (Elmt) loop
2546 if Entity (Node (Elmt)) = Entity (N) then
2560 procedure Do_Traversal is new Traverse_Proc (Check_Node);
2561 -- The traversal procedure
2563 -- Start of processing for Collect_Identifiers
2566 if Present (Error_Node) then
2570 if Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
2575 end Collect_Identifiers;
2577 -------------------------------
2578 -- Preanalyze_Without_Errors --
2579 -------------------------------
2581 procedure Preanalyze_Without_Errors (N : Node_Id) is
2582 Status : constant Boolean := Get_Ignore_Errors;
2584 Set_Ignore_Errors (True);
2586 Set_Ignore_Errors (Status);
2587 end Preanalyze_Without_Errors;
2589 -- Start of processing for Check_Function_Writable_Actuals
2592 -- The check only applies to Ada 2012 code on which Check_Actuals has
2593 -- been set, and only to constructs that have multiple constituents
2594 -- whose order of evaluation is not specified by the language.
2596 if Ada_Version < Ada_2012
2597 or else not Check_Actuals (N)
2598 or else (not (Nkind (N) in N_Op)
2599 and then not (Nkind (N) in N_Membership_Test)
2600 and then not Nkind_In (N, N_Range,
2602 N_Extension_Aggregate,
2603 N_Full_Type_Declaration,
2605 N_Procedure_Call_Statement,
2606 N_Entry_Call_Statement))
2607 or else (Nkind (N) = N_Full_Type_Declaration
2608 and then not Is_Record_Type (Defining_Identifier (N)))
2610 -- In addition, this check only applies to source code, not to code
2611 -- generated by constraint checks.
2613 or else not Comes_From_Source (N)
2618 -- If a construct C has two or more direct constituents that are names
2619 -- or expressions whose evaluation may occur in an arbitrary order, at
2620 -- least one of which contains a function call with an in out or out
2621 -- parameter, then the construct is legal only if: for each name N that
2622 -- is passed as a parameter of mode in out or out to some inner function
2623 -- call C2 (not including the construct C itself), there is no other
2624 -- name anywhere within a direct constituent of the construct C other
2625 -- than the one containing C2, that is known to refer to the same
2626 -- object (RM 6.4.1(6.17/3)).
2630 Collect_Identifiers (Low_Bound (N));
2631 Collect_Identifiers (High_Bound (N));
2633 when N_Membership_Test
2640 Collect_Identifiers (Left_Opnd (N));
2642 if Present (Right_Opnd (N)) then
2643 Collect_Identifiers (Right_Opnd (N));
2646 if Nkind_In (N, N_In, N_Not_In)
2647 and then Present (Alternatives (N))
2649 Expr := First (Alternatives (N));
2650 while Present (Expr) loop
2651 Collect_Identifiers (Expr);
2658 when N_Full_Type_Declaration =>
2660 function Get_Record_Part (N : Node_Id) return Node_Id;
2661 -- Return the record part of this record type definition
2663 function Get_Record_Part (N : Node_Id) return Node_Id is
2664 Type_Def : constant Node_Id := Type_Definition (N);
2666 if Nkind (Type_Def) = N_Derived_Type_Definition then
2667 return Record_Extension_Part (Type_Def);
2671 end Get_Record_Part;
2674 Def_Id : Entity_Id := Defining_Identifier (N);
2675 Rec : Node_Id := Get_Record_Part (N);
2678 -- No need to perform any analysis if the record has no
2681 if No (Rec) or else No (Component_List (Rec)) then
2685 -- Collect the identifiers starting from the deepest
2686 -- derivation. Done to report the error in the deepest
2690 if Present (Component_List (Rec)) then
2691 Comp := First (Component_Items (Component_List (Rec)));
2692 while Present (Comp) loop
2693 if Nkind (Comp) = N_Component_Declaration
2694 and then Present (Expression (Comp))
2696 Collect_Identifiers (Expression (Comp));
2703 exit when No (Underlying_Type (Etype (Def_Id)))
2704 or else Base_Type (Underlying_Type (Etype (Def_Id)))
2707 Def_Id := Base_Type (Underlying_Type (Etype (Def_Id)));
2708 Rec := Get_Record_Part (Parent (Def_Id));
2712 when N_Entry_Call_Statement
2716 Id : constant Entity_Id := Get_Called_Entity (N);
2721 Formal := First_Formal (Id);
2722 Actual := First_Actual (N);
2723 while Present (Actual) and then Present (Formal) loop
2724 if Ekind_In (Formal, E_Out_Parameter,
2727 Collect_Identifiers (Actual);
2730 Next_Formal (Formal);
2731 Next_Actual (Actual);
2736 | N_Extension_Aggregate
2741 Comp_Expr : Node_Id;
2744 -- Handle the N_Others_Choice of array aggregates with static
2745 -- bounds. There is no need to perform this analysis in
2746 -- aggregates without static bounds since we cannot evaluate
2747 -- if the N_Others_Choice covers several elements. There is
2748 -- no need to handle the N_Others choice of record aggregates
2749 -- since at this stage it has been already expanded by
2750 -- Resolve_Record_Aggregate.
2752 if Is_Array_Type (Etype (N))
2753 and then Nkind (N) = N_Aggregate
2754 and then Present (Aggregate_Bounds (N))
2755 and then Compile_Time_Known_Bounds (Etype (N))
2756 and then Expr_Value (High_Bound (Aggregate_Bounds (N)))
2758 Expr_Value (Low_Bound (Aggregate_Bounds (N)))
2761 Count_Components : Uint := Uint_0;
2762 Num_Components : Uint;
2763 Others_Assoc : Node_Id := Empty;
2764 Others_Choice : Node_Id := Empty;
2765 Others_Box_Present : Boolean := False;
2768 -- Count positional associations
2770 if Present (Expressions (N)) then
2771 Comp_Expr := First (Expressions (N));
2772 while Present (Comp_Expr) loop
2773 Count_Components := Count_Components + 1;
2778 -- Count the rest of elements and locate the N_Others
2781 Assoc := First (Component_Associations (N));
2782 while Present (Assoc) loop
2783 Choice := First (Choices (Assoc));
2784 while Present (Choice) loop
2785 if Nkind (Choice) = N_Others_Choice then
2786 Others_Assoc := Assoc;
2787 Others_Choice := Choice;
2788 Others_Box_Present := Box_Present (Assoc);
2790 -- Count several components
2792 elsif Nkind_In (Choice, N_Range,
2793 N_Subtype_Indication)
2794 or else (Is_Entity_Name (Choice)
2795 and then Is_Type (Entity (Choice)))
2800 Get_Index_Bounds (Choice, L, H);
2802 (Compile_Time_Known_Value (L)
2803 and then Compile_Time_Known_Value (H));
2806 + Expr_Value (H) - Expr_Value (L) + 1;
2809 -- Count single component. No other case available
2810 -- since we are handling an aggregate with static
2814 pragma Assert (Is_OK_Static_Expression (Choice)
2815 or else Nkind (Choice) = N_Identifier
2816 or else Nkind (Choice) = N_Integer_Literal);
2818 Count_Components := Count_Components + 1;
2828 Expr_Value (High_Bound (Aggregate_Bounds (N))) -
2829 Expr_Value (Low_Bound (Aggregate_Bounds (N))) + 1;
2831 pragma Assert (Count_Components <= Num_Components);
2833 -- Handle the N_Others choice if it covers several
2836 if Present (Others_Choice)
2837 and then (Num_Components - Count_Components) > 1
2839 if not Others_Box_Present then
2841 -- At this stage, if expansion is active, the
2842 -- expression of the others choice has not been
2843 -- analyzed. Hence we generate a duplicate and
2844 -- we analyze it silently to have available the
2845 -- minimum decoration required to collect the
2848 pragma Assert (Present (Others_Assoc));
2850 if not Expander_Active then
2851 Comp_Expr := Expression (Others_Assoc);
2854 New_Copy_Tree (Expression (Others_Assoc));
2855 Preanalyze_Without_Errors (Comp_Expr);
2858 Collect_Identifiers (Comp_Expr);
2860 if Writable_Actuals_List /= No_Elist then
2862 -- As suggested by Robert, at current stage we
2863 -- report occurrences of this case as warnings.
2866 ("writable function parameter may affect "
2867 & "value in other component because order "
2868 & "of evaluation is unspecified??",
2869 Node (First_Elmt (Writable_Actuals_List)));
2875 -- For an array aggregate, a discrete_choice_list that has
2876 -- a nonstatic range is considered as two or more separate
2877 -- occurrences of the expression (RM 6.4.1(20/3)).
2879 elsif Is_Array_Type (Etype (N))
2880 and then Nkind (N) = N_Aggregate
2881 and then Present (Aggregate_Bounds (N))
2882 and then not Compile_Time_Known_Bounds (Etype (N))
2884 -- Collect identifiers found in the dynamic bounds
2887 Count_Components : Natural := 0;
2888 Low, High : Node_Id;
2891 Assoc := First (Component_Associations (N));
2892 while Present (Assoc) loop
2893 Choice := First (Choices (Assoc));
2894 while Present (Choice) loop
2895 if Nkind_In (Choice, N_Range,
2896 N_Subtype_Indication)
2897 or else (Is_Entity_Name (Choice)
2898 and then Is_Type (Entity (Choice)))
2900 Get_Index_Bounds (Choice, Low, High);
2902 if not Compile_Time_Known_Value (Low) then
2903 Collect_Identifiers (Low);
2905 if No (Aggr_Error_Node) then
2906 Aggr_Error_Node := Low;
2910 if not Compile_Time_Known_Value (High) then
2911 Collect_Identifiers (High);
2913 if No (Aggr_Error_Node) then
2914 Aggr_Error_Node := High;
2918 -- The RM rule is violated if there is more than
2919 -- a single choice in a component association.
2922 Count_Components := Count_Components + 1;
2924 if No (Aggr_Error_Node)
2925 and then Count_Components > 1
2927 Aggr_Error_Node := Choice;
2930 if not Compile_Time_Known_Value (Choice) then
2931 Collect_Identifiers (Choice);
2943 -- Handle ancestor part of extension aggregates
2945 if Nkind (N) = N_Extension_Aggregate then
2946 Collect_Identifiers (Ancestor_Part (N));
2949 -- Handle positional associations
2951 if Present (Expressions (N)) then
2952 Comp_Expr := First (Expressions (N));
2953 while Present (Comp_Expr) loop
2954 if not Is_OK_Static_Expression (Comp_Expr) then
2955 Collect_Identifiers (Comp_Expr);
2962 -- Handle discrete associations
2964 if Present (Component_Associations (N)) then
2965 Assoc := First (Component_Associations (N));
2966 while Present (Assoc) loop
2968 if not Box_Present (Assoc) then
2969 Choice := First (Choices (Assoc));
2970 while Present (Choice) loop
2972 -- For now we skip discriminants since it requires
2973 -- performing the analysis in two phases: first one
2974 -- analyzing discriminants and second one analyzing
2975 -- the rest of components since discriminants are
2976 -- evaluated prior to components: too much extra
2977 -- work to detect a corner case???
2979 if Nkind (Choice) in N_Has_Entity
2980 and then Present (Entity (Choice))
2981 and then Ekind (Entity (Choice)) = E_Discriminant
2985 elsif Box_Present (Assoc) then
2989 if not Analyzed (Expression (Assoc)) then
2991 New_Copy_Tree (Expression (Assoc));
2992 Set_Parent (Comp_Expr, Parent (N));
2993 Preanalyze_Without_Errors (Comp_Expr);
2995 Comp_Expr := Expression (Assoc);
2998 Collect_Identifiers (Comp_Expr);
3014 -- No further action needed if we already reported an error
3016 if Present (Error_Node) then
3020 -- Check violation of RM 6.20/3 in aggregates
3022 if Present (Aggr_Error_Node)
3023 and then Writable_Actuals_List /= No_Elist
3026 ("value may be affected by call in other component because they "
3027 & "are evaluated in unspecified order",
3028 Node (First_Elmt (Writable_Actuals_List)));
3032 -- Check if some writable argument of a function is referenced
3034 if Writable_Actuals_List /= No_Elist
3035 and then Identifiers_List /= No_Elist
3042 Elmt_1 := First_Elmt (Writable_Actuals_List);
3043 while Present (Elmt_1) loop
3044 Elmt_2 := First_Elmt (Identifiers_List);
3045 while Present (Elmt_2) loop
3046 if Entity (Node (Elmt_1)) = Entity (Node (Elmt_2)) then
3047 case Nkind (Parent (Node (Elmt_2))) is
3049 | N_Component_Association
3050 | N_Component_Declaration
3053 ("value may be affected by call in other "
3054 & "component because they are evaluated "
3055 & "in unspecified order",
3062 ("value may be affected by call in other "
3063 & "alternative because they are evaluated "
3064 & "in unspecified order",
3069 ("value of actual may be affected by call in "
3070 & "other actual because they are evaluated "
3071 & "in unspecified order",
3083 end Check_Function_Writable_Actuals;
3085 --------------------------------
3086 -- Check_Implicit_Dereference --
3087 --------------------------------
3089 procedure Check_Implicit_Dereference (N : Node_Id; Typ : Entity_Id) is
3095 if Nkind (N) = N_Indexed_Component
3096 and then Present (Generalized_Indexing (N))
3098 Nam := Generalized_Indexing (N);
3103 if Ada_Version < Ada_2012
3104 or else not Has_Implicit_Dereference (Base_Type (Typ))
3108 elsif not Comes_From_Source (N)
3109 and then Nkind (N) /= N_Indexed_Component
3113 elsif Is_Entity_Name (Nam) and then Is_Type (Entity (Nam)) then
3117 Disc := First_Discriminant (Typ);
3118 while Present (Disc) loop
3119 if Has_Implicit_Dereference (Disc) then
3120 Desig := Designated_Type (Etype (Disc));
3121 Add_One_Interp (Nam, Disc, Desig);
3123 -- If the node is a generalized indexing, add interpretation
3124 -- to that node as well, for subsequent resolution.
3126 if Nkind (N) = N_Indexed_Component then
3127 Add_One_Interp (N, Disc, Desig);
3130 -- If the operation comes from a generic unit and the context
3131 -- is a selected component, the selector name may be global
3132 -- and set in the instance already. Remove the entity to
3133 -- force resolution of the selected component, and the
3134 -- generation of an explicit dereference if needed.
3137 and then Nkind (Parent (Nam)) = N_Selected_Component
3139 Set_Entity (Selector_Name (Parent (Nam)), Empty);
3145 Next_Discriminant (Disc);
3148 end Check_Implicit_Dereference;
3150 ----------------------------------
3151 -- Check_Internal_Protected_Use --
3152 ----------------------------------
3154 procedure Check_Internal_Protected_Use (N : Node_Id; Nam : Entity_Id) is
3162 while Present (S) loop
3163 if S = Standard_Standard then
3166 elsif Ekind (S) = E_Function
3167 and then Ekind (Scope (S)) = E_Protected_Type
3177 and then Scope (Nam) = Prot
3178 and then Ekind (Nam) /= E_Function
3180 -- An indirect function call (e.g. a callback within a protected
3181 -- function body) is not statically illegal. If the access type is
3182 -- anonymous and is the type of an access parameter, the scope of Nam
3183 -- will be the protected type, but it is not a protected operation.
3185 if Ekind (Nam) = E_Subprogram_Type
3186 and then Nkind (Associated_Node_For_Itype (Nam)) =
3187 N_Function_Specification
3191 elsif Nkind (N) = N_Subprogram_Renaming_Declaration then
3193 ("within protected function cannot use protected procedure in "
3194 & "renaming or as generic actual", N);
3196 elsif Nkind (N) = N_Attribute_Reference then
3198 ("within protected function cannot take access of protected "
3203 ("within protected function, protected object is constant", N);
3205 ("\cannot call operation that may modify it", N);
3209 -- Verify that an internal call does not appear within a precondition
3210 -- of a protected operation. This implements AI12-0166.
3211 -- The precondition aspect has been rewritten as a pragma Precondition
3212 -- and we check whether the scope of the called subprogram is the same
3213 -- as that of the entity to which the aspect applies.
3215 if Convention (Nam) = Convention_Protected then
3221 while Present (P) loop
3222 if Nkind (P) = N_Pragma
3223 and then Chars (Pragma_Identifier (P)) = Name_Precondition
3224 and then From_Aspect_Specification (P)
3226 Scope (Entity (Corresponding_Aspect (P))) = Scope (Nam)
3229 ("internal call cannot appear in precondition of "
3230 & "protected operation", N);
3233 elsif Nkind (P) = N_Pragma
3234 and then Chars (Pragma_Identifier (P)) = Name_Contract_Cases
3236 -- Check whether call is in a case guard. It is legal in a
3240 while Present (P) loop
3241 if Nkind (Parent (P)) = N_Component_Association
3242 and then P /= Expression (Parent (P))
3245 ("internal call cannot appear in case guard in a "
3246 & "contract case", N);
3254 elsif Nkind (P) = N_Parameter_Specification
3255 and then Scope (Current_Scope) = Scope (Nam)
3256 and then Nkind_In (Parent (P), N_Entry_Declaration,
3257 N_Subprogram_Declaration)
3260 ("internal call cannot appear in default for formal of "
3261 & "protected operation", N);
3269 end Check_Internal_Protected_Use;
3271 ---------------------------------------
3272 -- Check_Later_Vs_Basic_Declarations --
3273 ---------------------------------------
3275 procedure Check_Later_Vs_Basic_Declarations
3277 During_Parsing : Boolean)
3279 Body_Sloc : Source_Ptr;
3282 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
3283 -- Return whether Decl is considered as a declarative item.
3284 -- When During_Parsing is True, the semantics of Ada 83 is followed.
3285 -- When During_Parsing is False, the semantics of SPARK is followed.
3287 -------------------------------
3288 -- Is_Later_Declarative_Item --
3289 -------------------------------
3291 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
3293 if Nkind (Decl) in N_Later_Decl_Item then
3296 elsif Nkind (Decl) = N_Pragma then
3299 elsif During_Parsing then
3302 -- In SPARK, a package declaration is not considered as a later
3303 -- declarative item.
3305 elsif Nkind (Decl) = N_Package_Declaration then
3308 -- In SPARK, a renaming is considered as a later declarative item
3310 elsif Nkind (Decl) in N_Renaming_Declaration then
3316 end Is_Later_Declarative_Item;
3318 -- Start of processing for Check_Later_Vs_Basic_Declarations
3321 Decl := First (Decls);
3323 -- Loop through sequence of basic declarative items
3325 Outer : while Present (Decl) loop
3326 if not Nkind_In (Decl, N_Subprogram_Body, N_Package_Body, N_Task_Body)
3327 and then Nkind (Decl) not in N_Body_Stub
3331 -- Once a body is encountered, we only allow later declarative
3332 -- items. The inner loop checks the rest of the list.
3335 Body_Sloc := Sloc (Decl);
3337 Inner : while Present (Decl) loop
3338 if not Is_Later_Declarative_Item (Decl) then
3339 if During_Parsing then
3340 if Ada_Version = Ada_83 then
3341 Error_Msg_Sloc := Body_Sloc;
3343 ("(Ada 83) decl cannot appear after body#", Decl);
3346 Error_Msg_Sloc := Body_Sloc;
3347 Check_SPARK_05_Restriction
3348 ("decl cannot appear after body#", Decl);
3356 end Check_Later_Vs_Basic_Declarations;
3358 ---------------------------
3359 -- Check_No_Hidden_State --
3360 ---------------------------
3362 procedure Check_No_Hidden_State (Id : Entity_Id) is
3363 Context : Entity_Id := Empty;
3364 Not_Visible : Boolean := False;
3368 pragma Assert (Ekind_In (Id, E_Abstract_State, E_Variable));
3370 -- Nothing to do for internally-generated abstract states and variables
3371 -- because they do not represent the hidden state of the source unit.
3373 if not Comes_From_Source (Id) then
3377 -- Find the proper context where the object or state appears
3380 while Present (Scop) loop
3383 -- Keep track of the context's visibility
3385 Not_Visible := Not_Visible or else In_Private_Part (Context);
3387 -- Prevent the search from going too far
3389 if Context = Standard_Standard then
3392 -- Objects and states that appear immediately within a subprogram or
3393 -- entry inside a construct nested within a subprogram do not
3394 -- introduce a hidden state. They behave as local variable
3395 -- declarations. The same is true for elaboration code inside a block
3398 elsif Is_Subprogram_Or_Entry (Context)
3399 or else Ekind_In (Context, E_Block, E_Task_Type)
3404 -- Stop the traversal when a package subject to a null abstract state
3407 if Is_Package_Or_Generic_Package (Context)
3408 and then Has_Null_Abstract_State (Context)
3413 Scop := Scope (Scop);
3416 -- At this point we know that there is at least one package with a null
3417 -- abstract state in visibility. Emit an error message unconditionally
3418 -- if the entity being processed is a state because the placement of the
3419 -- related package is irrelevant. This is not the case for objects as
3420 -- the intermediate context matters.
3422 if Present (Context)
3423 and then (Ekind (Id) = E_Abstract_State or else Not_Visible)
3425 Error_Msg_N ("cannot introduce hidden state &", Id);
3426 Error_Msg_NE ("\package & has null abstract state", Id, Context);
3428 end Check_No_Hidden_State;
3430 ----------------------------------------
3431 -- Check_Nonvolatile_Function_Profile --
3432 ----------------------------------------
3434 procedure Check_Nonvolatile_Function_Profile (Func_Id : Entity_Id) is
3438 -- Inspect all formal parameters
3440 Formal := First_Formal (Func_Id);
3441 while Present (Formal) loop
3442 if Is_Effectively_Volatile (Etype (Formal)) then
3444 ("nonvolatile function & cannot have a volatile parameter",
3448 Next_Formal (Formal);
3451 -- Inspect the return type
3453 if Is_Effectively_Volatile (Etype (Func_Id)) then
3455 ("nonvolatile function & cannot have a volatile return type",
3456 Result_Definition (Parent (Func_Id)), Func_Id);
3458 end Check_Nonvolatile_Function_Profile;
3460 -----------------------------
3461 -- Check_Part_Of_Reference --
3462 -----------------------------
3464 procedure Check_Part_Of_Reference (Var_Id : Entity_Id; Ref : Node_Id) is
3465 function Is_Enclosing_Package_Body
3466 (Body_Decl : Node_Id;
3467 Obj_Id : Entity_Id) return Boolean;
3468 pragma Inline (Is_Enclosing_Package_Body);
3469 -- Determine whether package body Body_Decl or its corresponding spec
3470 -- immediately encloses the declaration of object Obj_Id.
3472 function Is_Internal_Declaration_Or_Body
3473 (Decl : Node_Id) return Boolean;
3474 pragma Inline (Is_Internal_Declaration_Or_Body);
3475 -- Determine whether declaration or body denoted by Decl is internal
3477 function Is_Single_Declaration_Or_Body
3479 Conc_Typ : Entity_Id) return Boolean;
3480 pragma Inline (Is_Single_Declaration_Or_Body);
3481 -- Determine whether protected/task declaration or body denoted by Decl
3482 -- belongs to single concurrent type Conc_Typ.
3484 function Is_Single_Task_Pragma
3486 Task_Typ : Entity_Id) return Boolean;
3487 pragma Inline (Is_Single_Task_Pragma);
3488 -- Determine whether pragma Prag belongs to single task type Task_Typ
3490 -------------------------------
3491 -- Is_Enclosing_Package_Body --
3492 -------------------------------
3494 function Is_Enclosing_Package_Body
3495 (Body_Decl : Node_Id;
3496 Obj_Id : Entity_Id) return Boolean
3498 Obj_Context : Node_Id;
3501 -- Find the context of the object declaration
3503 Obj_Context := Parent (Declaration_Node (Obj_Id));
3505 if Nkind (Obj_Context) = N_Package_Specification then
3506 Obj_Context := Parent (Obj_Context);
3509 -- The object appears immediately within the package body
3511 if Obj_Context = Body_Decl then
3514 -- The object appears immediately within the corresponding spec
3516 elsif Nkind (Obj_Context) = N_Package_Declaration
3517 and then Unit_Declaration_Node (Corresponding_Spec (Body_Decl)) =
3524 end Is_Enclosing_Package_Body;
3526 -------------------------------------
3527 -- Is_Internal_Declaration_Or_Body --
3528 -------------------------------------
3530 function Is_Internal_Declaration_Or_Body
3531 (Decl : Node_Id) return Boolean
3534 if Comes_From_Source (Decl) then
3537 -- A body generated for an expression function which has not been
3538 -- inserted into the tree yet (In_Spec_Expression is True) is not
3539 -- considered internal.
3541 elsif Nkind (Decl) = N_Subprogram_Body
3542 and then Was_Expression_Function (Decl)
3543 and then not In_Spec_Expression
3549 end Is_Internal_Declaration_Or_Body;
3551 -----------------------------------
3552 -- Is_Single_Declaration_Or_Body --
3553 -----------------------------------
3555 function Is_Single_Declaration_Or_Body
3557 Conc_Typ : Entity_Id) return Boolean
3559 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Decl);
3563 Present (Anonymous_Object (Spec_Id))
3564 and then Anonymous_Object (Spec_Id) = Conc_Typ;
3565 end Is_Single_Declaration_Or_Body;
3567 ---------------------------
3568 -- Is_Single_Task_Pragma --
3569 ---------------------------
3571 function Is_Single_Task_Pragma
3573 Task_Typ : Entity_Id) return Boolean
3575 Decl : constant Node_Id := Find_Related_Declaration_Or_Body (Prag);
3578 -- To qualify, the pragma must be associated with single task type
3582 Is_Single_Task_Object (Task_Typ)
3583 and then Nkind (Decl) = N_Object_Declaration
3584 and then Defining_Entity (Decl) = Task_Typ;
3585 end Is_Single_Task_Pragma;
3589 Conc_Obj : constant Entity_Id := Encapsulating_State (Var_Id);
3594 -- Start of processing for Check_Part_Of_Reference
3597 -- Nothing to do when the variable was recorded, but did not become a
3598 -- constituent of a single concurrent type.
3600 if No (Conc_Obj) then
3604 -- Traverse the parent chain looking for a suitable context for the
3605 -- reference to the concurrent constituent.
3608 Par := Parent (Prev);
3609 while Present (Par) loop
3610 if Nkind (Par) = N_Pragma then
3611 Prag_Nam := Pragma_Name (Par);
3613 -- A concurrent constituent is allowed to appear in pragmas
3614 -- Initial_Condition and Initializes as this is part of the
3615 -- elaboration checks for the constituent (SPARK RM 9(3)).
3617 if Nam_In (Prag_Nam, Name_Initial_Condition, Name_Initializes) then
3620 -- When the reference appears within pragma Depends or Global,
3621 -- check whether the pragma applies to a single task type. Note
3622 -- that the pragma may not encapsulated by the type definition,
3623 -- but this is still a valid context.
3625 elsif Nam_In (Prag_Nam, Name_Depends, Name_Global)
3626 and then Is_Single_Task_Pragma (Par, Conc_Obj)
3631 -- The reference appears somewhere in the definition of a single
3632 -- concurrent type (SPARK RM 9(3)).
3634 elsif Nkind_In (Par, N_Single_Protected_Declaration,
3635 N_Single_Task_Declaration)
3636 and then Defining_Entity (Par) = Conc_Obj
3640 -- The reference appears within the declaration or body of a single
3641 -- concurrent type (SPARK RM 9(3)).
3643 elsif Nkind_In (Par, N_Protected_Body,
3644 N_Protected_Type_Declaration,
3646 N_Task_Type_Declaration)
3647 and then Is_Single_Declaration_Or_Body (Par, Conc_Obj)
3651 -- The reference appears within the statement list of the object's
3652 -- immediately enclosing package (SPARK RM 9(3)).
3654 elsif Nkind (Par) = N_Package_Body
3655 and then Nkind (Prev) = N_Handled_Sequence_Of_Statements
3656 and then Is_Enclosing_Package_Body (Par, Var_Id)
3660 -- The reference has been relocated within an internally generated
3661 -- package or subprogram. Assume that the reference is legal as the
3662 -- real check was already performed in the original context of the
3665 elsif Nkind_In (Par, N_Package_Body,
3666 N_Package_Declaration,
3668 N_Subprogram_Declaration)
3669 and then Is_Internal_Declaration_Or_Body (Par)
3673 -- The reference has been relocated to an inlined body for GNATprove.
3674 -- Assume that the reference is legal as the real check was already
3675 -- performed in the original context of the reference.
3677 elsif GNATprove_Mode
3678 and then Nkind (Par) = N_Subprogram_Body
3679 and then Chars (Defining_Entity (Par)) = Name_uParent
3685 Par := Parent (Prev);
3688 -- At this point it is known that the reference does not appear within a
3692 ("reference to variable & cannot appear in this context", Ref, Var_Id);
3693 Error_Msg_Name_1 := Chars (Var_Id);
3695 if Is_Single_Protected_Object (Conc_Obj) then
3697 ("\% is constituent of single protected type &", Ref, Conc_Obj);
3701 ("\% is constituent of single task type &", Ref, Conc_Obj);
3703 end Check_Part_Of_Reference;
3705 ------------------------------------------
3706 -- Check_Potentially_Blocking_Operation --
3707 ------------------------------------------
3709 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
3713 -- N is one of the potentially blocking operations listed in 9.5.1(8).
3714 -- When pragma Detect_Blocking is active, the run time will raise
3715 -- Program_Error. Here we only issue a warning, since we generally
3716 -- support the use of potentially blocking operations in the absence
3719 -- Indirect blocking through a subprogram call cannot be diagnosed
3720 -- statically without interprocedural analysis, so we do not attempt
3723 S := Scope (Current_Scope);
3724 while Present (S) and then S /= Standard_Standard loop
3725 if Is_Protected_Type (S) then
3727 ("potentially blocking operation in protected operation??", N);
3733 end Check_Potentially_Blocking_Operation;
3735 ------------------------------------
3736 -- Check_Previous_Null_Procedure --
3737 ------------------------------------
3739 procedure Check_Previous_Null_Procedure
3744 if Ekind (Prev) = E_Procedure
3745 and then Nkind (Parent (Prev)) = N_Procedure_Specification
3746 and then Null_Present (Parent (Prev))
3748 Error_Msg_Sloc := Sloc (Prev);
3750 ("declaration cannot complete previous null procedure#", Decl);
3752 end Check_Previous_Null_Procedure;
3754 ---------------------------------
3755 -- Check_Result_And_Post_State --
3756 ---------------------------------
3758 procedure Check_Result_And_Post_State (Subp_Id : Entity_Id) is
3759 procedure Check_Result_And_Post_State_In_Pragma
3761 Result_Seen : in out Boolean);
3762 -- Determine whether pragma Prag mentions attribute 'Result and whether
3763 -- the pragma contains an expression that evaluates differently in pre-
3764 -- and post-state. Prag is a [refined] postcondition or a contract-cases
3765 -- pragma. Result_Seen is set when the pragma mentions attribute 'Result
3767 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean;
3768 -- Determine whether subprogram Subp_Id contains at least one IN OUT
3769 -- formal parameter.
3771 -------------------------------------------
3772 -- Check_Result_And_Post_State_In_Pragma --
3773 -------------------------------------------
3775 procedure Check_Result_And_Post_State_In_Pragma
3777 Result_Seen : in out Boolean)
3779 procedure Check_Conjunct (Expr : Node_Id);
3780 -- Check an individual conjunct in a conjunction of Boolean
3781 -- expressions, connected by "and" or "and then" operators.
3783 procedure Check_Conjuncts (Expr : Node_Id);
3784 -- Apply the post-state check to every conjunct in an expression, in
3785 -- case this is a conjunction of Boolean expressions. Otherwise apply
3786 -- it to the expression as a whole.
3788 procedure Check_Expression (Expr : Node_Id);
3789 -- Perform the 'Result and post-state checks on a given expression
3791 function Is_Function_Result (N : Node_Id) return Traverse_Result;
3792 -- Attempt to find attribute 'Result in a subtree denoted by N
3794 function Is_Trivial_Boolean (N : Node_Id) return Boolean;
3795 -- Determine whether source node N denotes "True" or "False"
3797 function Mentions_Post_State (N : Node_Id) return Boolean;
3798 -- Determine whether a subtree denoted by N mentions any construct
3799 -- that denotes a post-state.
3801 procedure Check_Function_Result is
3802 new Traverse_Proc (Is_Function_Result);
3804 --------------------
3805 -- Check_Conjunct --
3806 --------------------
3808 procedure Check_Conjunct (Expr : Node_Id) is
3809 function Adjust_Message (Msg : String) return String;
3810 -- Prepend a prefix to the input message Msg denoting that the
3811 -- message applies to a conjunct in the expression, when this
3814 function Applied_On_Conjunct return Boolean;
3815 -- Returns True if the message applies to a conjunct in the
3816 -- expression, instead of the whole expression.
3818 function Has_Global_Output (Subp : Entity_Id) return Boolean;
3819 -- Returns True if Subp has an output in its Global contract
3821 function Has_No_Output (Subp : Entity_Id) return Boolean;
3822 -- Returns True if Subp has no declared output: no function
3823 -- result, no output parameter, and no output in its Global
3826 --------------------
3827 -- Adjust_Message --
3828 --------------------
3830 function Adjust_Message (Msg : String) return String is
3832 if Applied_On_Conjunct then
3833 return "conjunct in " & Msg;
3839 -------------------------
3840 -- Applied_On_Conjunct --
3841 -------------------------
3843 function Applied_On_Conjunct return Boolean is
3845 -- Expr is the conjunct of an enclosing "and" expression
3847 return Nkind (Parent (Expr)) in N_Subexpr
3849 -- or Expr is a conjunct of an enclosing "and then"
3850 -- expression in a postcondition aspect that was split into
3851 -- multiple pragmas. The first conjunct has the "and then"
3852 -- expression as Original_Node, and other conjuncts have
3853 -- Split_PCC set to True.
3855 or else Nkind (Original_Node (Expr)) = N_And_Then
3856 or else Split_PPC (Prag);
3857 end Applied_On_Conjunct;
3859 -----------------------
3860 -- Has_Global_Output --
3861 -----------------------
3863 function Has_Global_Output (Subp : Entity_Id) return Boolean is
3864 Global : constant Node_Id := Get_Pragma (Subp, Pragma_Global);
3873 List := Expression (Get_Argument (Global, Subp));
3875 -- Empty list (no global items) or single global item
3876 -- declaration (only input items).
3878 if Nkind_In (List, N_Null,
3881 N_Selected_Component)
3885 -- Simple global list (only input items) or moded global list
3888 elsif Nkind (List) = N_Aggregate then
3889 if Present (Expressions (List)) then
3893 Assoc := First (Component_Associations (List));
3894 while Present (Assoc) loop
3895 if Chars (First (Choices (Assoc))) /= Name_Input then
3905 -- To accommodate partial decoration of disabled SPARK
3906 -- features, this routine may be called with illegal input.
3907 -- If this is the case, do not raise Program_Error.
3912 end Has_Global_Output;
3918 function Has_No_Output (Subp : Entity_Id) return Boolean is
3922 -- A function has its result as output
3924 if Ekind (Subp) = E_Function then
3928 -- An OUT or IN OUT parameter is an output
3930 Param := First_Formal (Subp);
3931 while Present (Param) loop
3932 if Ekind_In (Param, E_Out_Parameter, E_In_Out_Parameter) then
3936 Next_Formal (Param);
3939 -- An item of mode Output or In_Out in the Global contract is
3942 if Has_Global_Output (Subp) then
3952 -- Error node when reporting a warning on a (refined)
3955 -- Start of processing for Check_Conjunct
3958 if Applied_On_Conjunct then
3964 -- Do not report missing reference to outcome in postcondition if
3965 -- either the postcondition is trivially True or False, or if the
3966 -- subprogram is ghost and has no declared output.
3968 if not Is_Trivial_Boolean (Expr)
3969 and then not Mentions_Post_State (Expr)
3970 and then not (Is_Ghost_Entity (Subp_Id)
3971 and then Has_No_Output (Subp_Id))
3973 if Pragma_Name (Prag) = Name_Contract_Cases then
3974 Error_Msg_NE (Adjust_Message
3975 ("contract case does not check the outcome of calling "
3976 & "&?T?"), Expr, Subp_Id);
3978 elsif Pragma_Name (Prag) = Name_Refined_Post then
3979 Error_Msg_NE (Adjust_Message
3980 ("refined postcondition does not check the outcome of "
3981 & "calling &?T?"), Err_Node, Subp_Id);
3984 Error_Msg_NE (Adjust_Message
3985 ("postcondition does not check the outcome of calling "
3986 & "&?T?"), Err_Node, Subp_Id);
3991 ---------------------
3992 -- Check_Conjuncts --
3993 ---------------------
3995 procedure Check_Conjuncts (Expr : Node_Id) is
3997 if Nkind_In (Expr, N_Op_And, N_And_Then) then
3998 Check_Conjuncts (Left_Opnd (Expr));
3999 Check_Conjuncts (Right_Opnd (Expr));
4001 Check_Conjunct (Expr);
4003 end Check_Conjuncts;
4005 ----------------------
4006 -- Check_Expression --
4007 ----------------------
4009 procedure Check_Expression (Expr : Node_Id) is
4011 if not Is_Trivial_Boolean (Expr) then
4012 Check_Function_Result (Expr);
4013 Check_Conjuncts (Expr);
4015 end Check_Expression;
4017 ------------------------
4018 -- Is_Function_Result --
4019 ------------------------
4021 function Is_Function_Result (N : Node_Id) return Traverse_Result is
4023 if Is_Attribute_Result (N) then
4024 Result_Seen := True;
4027 -- Warn on infinite recursion if call is to current function
4029 elsif Nkind (N) = N_Function_Call
4030 and then Is_Entity_Name (Name (N))
4031 and then Entity (Name (N)) = Subp_Id
4032 and then not Is_Potentially_Unevaluated (N)
4035 ("call to & within its postcondition will lead to infinite "
4036 & "recursion?", N, Subp_Id);
4039 -- Continue the traversal
4044 end Is_Function_Result;
4046 ------------------------
4047 -- Is_Trivial_Boolean --
4048 ------------------------
4050 function Is_Trivial_Boolean (N : Node_Id) return Boolean is
4053 Comes_From_Source (N)
4054 and then Is_Entity_Name (N)
4055 and then (Entity (N) = Standard_True
4057 Entity (N) = Standard_False);
4058 end Is_Trivial_Boolean;
4060 -------------------------
4061 -- Mentions_Post_State --
4062 -------------------------
4064 function Mentions_Post_State (N : Node_Id) return Boolean is
4065 Post_State_Seen : Boolean := False;
4067 function Is_Post_State (N : Node_Id) return Traverse_Result;
4068 -- Attempt to find a construct that denotes a post-state. If this
4069 -- is the case, set flag Post_State_Seen.
4075 function Is_Post_State (N : Node_Id) return Traverse_Result is
4079 if Nkind_In (N, N_Explicit_Dereference, N_Function_Call) then
4080 Post_State_Seen := True;
4083 elsif Nkind_In (N, N_Expanded_Name, N_Identifier) then
4086 -- Treat an undecorated reference as OK
4090 -- A reference to an assignable entity is considered a
4091 -- change in the post-state of a subprogram.
4093 or else Ekind_In (Ent, E_Generic_In_Out_Parameter,
4098 -- The reference may be modified through a dereference
4100 or else (Is_Access_Type (Etype (Ent))
4101 and then Nkind (Parent (N)) =
4102 N_Selected_Component)
4104 Post_State_Seen := True;
4108 elsif Nkind (N) = N_Attribute_Reference then
4109 if Attribute_Name (N) = Name_Old then
4112 elsif Attribute_Name (N) = Name_Result then
4113 Post_State_Seen := True;
4121 procedure Find_Post_State is new Traverse_Proc (Is_Post_State);
4123 -- Start of processing for Mentions_Post_State
4126 Find_Post_State (N);
4128 return Post_State_Seen;
4129 end Mentions_Post_State;
4133 Expr : constant Node_Id :=
4135 (First (Pragma_Argument_Associations (Prag)));
4136 Nam : constant Name_Id := Pragma_Name (Prag);
4139 -- Start of processing for Check_Result_And_Post_State_In_Pragma
4142 -- Examine all consequences
4144 if Nam = Name_Contract_Cases then
4145 CCase := First (Component_Associations (Expr));
4146 while Present (CCase) loop
4147 Check_Expression (Expression (CCase));
4152 -- Examine the expression of a postcondition
4154 else pragma Assert (Nam_In (Nam, Name_Postcondition,
4155 Name_Refined_Post));
4156 Check_Expression (Expr);
4158 end Check_Result_And_Post_State_In_Pragma;
4160 --------------------------
4161 -- Has_In_Out_Parameter --
4162 --------------------------
4164 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean is
4168 -- Traverse the formals looking for an IN OUT parameter
4170 Formal := First_Formal (Subp_Id);
4171 while Present (Formal) loop
4172 if Ekind (Formal) = E_In_Out_Parameter then
4176 Next_Formal (Formal);
4180 end Has_In_Out_Parameter;
4184 Items : constant Node_Id := Contract (Subp_Id);
4185 Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id);
4186 Case_Prag : Node_Id := Empty;
4187 Post_Prag : Node_Id := Empty;
4189 Seen_In_Case : Boolean := False;
4190 Seen_In_Post : Boolean := False;
4191 Spec_Id : Entity_Id;
4193 -- Start of processing for Check_Result_And_Post_State
4196 -- The lack of attribute 'Result or a post-state is classified as a
4197 -- suspicious contract. Do not perform the check if the corresponding
4198 -- swich is not set.
4200 if not Warn_On_Suspicious_Contract then
4203 -- Nothing to do if there is no contract
4205 elsif No (Items) then
4209 -- Retrieve the entity of the subprogram spec (if any)
4211 if Nkind (Subp_Decl) = N_Subprogram_Body
4212 and then Present (Corresponding_Spec (Subp_Decl))
4214 Spec_Id := Corresponding_Spec (Subp_Decl);
4216 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4217 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
4219 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
4225 -- Examine all postconditions for attribute 'Result and a post-state
4227 Prag := Pre_Post_Conditions (Items);
4228 while Present (Prag) loop
4229 if Nam_In (Pragma_Name_Unmapped (Prag),
4230 Name_Postcondition, Name_Refined_Post)
4231 and then not Error_Posted (Prag)
4234 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Post);
4237 Prag := Next_Pragma (Prag);
4240 -- Examine the contract cases of the subprogram for attribute 'Result
4241 -- and a post-state.
4243 Prag := Contract_Test_Cases (Items);
4244 while Present (Prag) loop
4245 if Pragma_Name (Prag) = Name_Contract_Cases
4246 and then not Error_Posted (Prag)
4249 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Case);
4252 Prag := Next_Pragma (Prag);
4255 -- Do not emit any errors if the subprogram is not a function
4257 if not Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
4260 -- Regardless of whether the function has postconditions or contract
4261 -- cases, or whether they mention attribute 'Result, an IN OUT formal
4262 -- parameter is always treated as a result.
4264 elsif Has_In_Out_Parameter (Spec_Id) then
4267 -- The function has both a postcondition and contract cases and they do
4268 -- not mention attribute 'Result.
4270 elsif Present (Case_Prag)
4271 and then not Seen_In_Case
4272 and then Present (Post_Prag)
4273 and then not Seen_In_Post
4276 ("neither postcondition nor contract cases mention function "
4277 & "result?T?", Post_Prag);
4279 -- The function has contract cases only and they do not mention
4280 -- attribute 'Result.
4282 elsif Present (Case_Prag) and then not Seen_In_Case then
4283 Error_Msg_N ("contract cases do not mention result?T?", Case_Prag);
4285 -- The function has postconditions only and they do not mention
4286 -- attribute 'Result.
4288 elsif Present (Post_Prag) and then not Seen_In_Post then
4290 ("postcondition does not mention function result?T?", Post_Prag);
4292 end Check_Result_And_Post_State;
4294 -----------------------------
4295 -- Check_State_Refinements --
4296 -----------------------------
4298 procedure Check_State_Refinements
4300 Is_Main_Unit : Boolean := False)
4302 procedure Check_Package (Pack : Node_Id);
4303 -- Verify that all abstract states of a [generic] package denoted by its
4304 -- declarative node Pack have proper refinement. Recursively verify the
4305 -- visible and private declarations of the [generic] package for other
4308 procedure Check_Packages_In (Decls : List_Id);
4309 -- Seek out [generic] package declarations within declarative list Decls
4310 -- and verify the status of their abstract state refinement.
4312 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean;
4313 -- Determine whether construct N is subject to pragma SPARK_Mode Off
4319 procedure Check_Package (Pack : Node_Id) is
4320 Body_Id : constant Entity_Id := Corresponding_Body (Pack);
4321 Spec : constant Node_Id := Specification (Pack);
4322 States : constant Elist_Id :=
4323 Abstract_States (Defining_Entity (Pack));
4325 State_Elmt : Elmt_Id;
4326 State_Id : Entity_Id;
4329 -- Do not verify proper state refinement when the package is subject
4330 -- to pragma SPARK_Mode Off because this disables the requirement for
4331 -- state refinement.
4333 if SPARK_Mode_Is_Off (Pack) then
4336 -- State refinement can only occur in a completing package body. Do
4337 -- not verify proper state refinement when the body is subject to
4338 -- pragma SPARK_Mode Off because this disables the requirement for
4339 -- state refinement.
4341 elsif Present (Body_Id)
4342 and then SPARK_Mode_Is_Off (Unit_Declaration_Node (Body_Id))
4346 -- Do not verify proper state refinement when the package is an
4347 -- instance as this check was already performed in the generic.
4349 elsif Present (Generic_Parent (Spec)) then
4352 -- Otherwise examine the contents of the package
4355 if Present (States) then
4356 State_Elmt := First_Elmt (States);
4357 while Present (State_Elmt) loop
4358 State_Id := Node (State_Elmt);
4360 -- Emit an error when a non-null state lacks any form of
4363 if not Is_Null_State (State_Id)
4364 and then not Has_Null_Refinement (State_Id)
4365 and then not Has_Non_Null_Refinement (State_Id)
4367 Error_Msg_N ("state & requires refinement", State_Id);
4370 Next_Elmt (State_Elmt);
4374 Check_Packages_In (Visible_Declarations (Spec));
4375 Check_Packages_In (Private_Declarations (Spec));
4379 -----------------------
4380 -- Check_Packages_In --
4381 -----------------------
4383 procedure Check_Packages_In (Decls : List_Id) is
4387 if Present (Decls) then
4388 Decl := First (Decls);
4389 while Present (Decl) loop
4390 if Nkind_In (Decl, N_Generic_Package_Declaration,
4391 N_Package_Declaration)
4393 Check_Package (Decl);
4399 end Check_Packages_In;
4401 -----------------------
4402 -- SPARK_Mode_Is_Off --
4403 -----------------------
4405 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean is
4406 Id : constant Entity_Id := Defining_Entity (N);
4407 Prag : constant Node_Id := SPARK_Pragma (Id);
4410 -- Default the mode to "off" when the context is an instance and all
4411 -- SPARK_Mode pragmas found within are to be ignored.
4413 if Ignore_SPARK_Mode_Pragmas (Id) then
4419 and then Get_SPARK_Mode_From_Annotation (Prag) = Off;
4421 end SPARK_Mode_Is_Off;
4423 -- Start of processing for Check_State_Refinements
4426 -- A block may declare a nested package
4428 if Nkind (Context) = N_Block_Statement then
4429 Check_Packages_In (Declarations (Context));
4431 -- An entry, protected, subprogram, or task body may declare a nested
4434 elsif Nkind_In (Context, N_Entry_Body,
4439 -- Do not verify proper state refinement when the body is subject to
4440 -- pragma SPARK_Mode Off because this disables the requirement for
4441 -- state refinement.
4443 if not SPARK_Mode_Is_Off (Context) then
4444 Check_Packages_In (Declarations (Context));
4447 -- A package body may declare a nested package
4449 elsif Nkind (Context) = N_Package_Body then
4450 Check_Package (Unit_Declaration_Node (Corresponding_Spec (Context)));
4452 -- Do not verify proper state refinement when the body is subject to
4453 -- pragma SPARK_Mode Off because this disables the requirement for
4454 -- state refinement.
4456 if not SPARK_Mode_Is_Off (Context) then
4457 Check_Packages_In (Declarations (Context));
4460 -- A library level [generic] package may declare a nested package
4462 elsif Nkind_In (Context, N_Generic_Package_Declaration,
4463 N_Package_Declaration)
4464 and then Is_Main_Unit
4466 Check_Package (Context);
4468 end Check_State_Refinements;
4470 ------------------------------
4471 -- Check_Unprotected_Access --
4472 ------------------------------
4474 procedure Check_Unprotected_Access
4478 Cont_Encl_Typ : Entity_Id;
4479 Pref_Encl_Typ : Entity_Id;
4481 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
4482 -- Check whether Obj is a private component of a protected object.
4483 -- Return the protected type where the component resides, Empty
4486 function Is_Public_Operation return Boolean;
4487 -- Verify that the enclosing operation is callable from outside the
4488 -- protected object, to minimize false positives.
4490 ------------------------------
4491 -- Enclosing_Protected_Type --
4492 ------------------------------
4494 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
4496 if Is_Entity_Name (Obj) then
4498 Ent : Entity_Id := Entity (Obj);
4501 -- The object can be a renaming of a private component, use
4502 -- the original record component.
4504 if Is_Prival (Ent) then
4505 Ent := Prival_Link (Ent);
4508 if Is_Protected_Type (Scope (Ent)) then
4514 -- For indexed and selected components, recursively check the prefix
4516 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
4517 return Enclosing_Protected_Type (Prefix (Obj));
4519 -- The object does not denote a protected component
4524 end Enclosing_Protected_Type;
4526 -------------------------
4527 -- Is_Public_Operation --
4528 -------------------------
4530 function Is_Public_Operation return Boolean is
4536 while Present (S) and then S /= Pref_Encl_Typ loop
4537 if Scope (S) = Pref_Encl_Typ then
4538 E := First_Entity (Pref_Encl_Typ);
4540 and then E /= First_Private_Entity (Pref_Encl_Typ)
4554 end Is_Public_Operation;
4556 -- Start of processing for Check_Unprotected_Access
4559 if Nkind (Expr) = N_Attribute_Reference
4560 and then Attribute_Name (Expr) = Name_Unchecked_Access
4562 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
4563 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
4565 -- Check whether we are trying to export a protected component to a
4566 -- context with an equal or lower access level.
4568 if Present (Pref_Encl_Typ)
4569 and then No (Cont_Encl_Typ)
4570 and then Is_Public_Operation
4571 and then Scope_Depth (Pref_Encl_Typ) >=
4572 Object_Access_Level (Context)
4575 ("??possible unprotected access to protected data", Expr);
4578 end Check_Unprotected_Access;
4580 ------------------------------
4581 -- Check_Unused_Body_States --
4582 ------------------------------
4584 procedure Check_Unused_Body_States (Body_Id : Entity_Id) is
4585 procedure Process_Refinement_Clause
4588 -- Inspect all constituents of refinement clause Clause and remove any
4589 -- matches from body state list States.
4591 procedure Report_Unused_Body_States (States : Elist_Id);
4592 -- Emit errors for each abstract state or object found in list States
4594 -------------------------------
4595 -- Process_Refinement_Clause --
4596 -------------------------------
4598 procedure Process_Refinement_Clause
4602 procedure Process_Constituent (Constit : Node_Id);
4603 -- Remove constituent Constit from body state list States
4605 -------------------------
4606 -- Process_Constituent --
4607 -------------------------
4609 procedure Process_Constituent (Constit : Node_Id) is
4610 Constit_Id : Entity_Id;
4613 -- Guard against illegal constituents. Only abstract states and
4614 -- objects can appear on the right hand side of a refinement.
4616 if Is_Entity_Name (Constit) then
4617 Constit_Id := Entity_Of (Constit);
4619 if Present (Constit_Id)
4620 and then Ekind_In (Constit_Id, E_Abstract_State,
4624 Remove (States, Constit_Id);
4627 end Process_Constituent;
4633 -- Start of processing for Process_Refinement_Clause
4636 if Nkind (Clause) = N_Component_Association then
4637 Constit := Expression (Clause);
4639 -- Multiple constituents appear as an aggregate
4641 if Nkind (Constit) = N_Aggregate then
4642 Constit := First (Expressions (Constit));
4643 while Present (Constit) loop
4644 Process_Constituent (Constit);
4648 -- Various forms of a single constituent
4651 Process_Constituent (Constit);
4654 end Process_Refinement_Clause;
4656 -------------------------------
4657 -- Report_Unused_Body_States --
4658 -------------------------------
4660 procedure Report_Unused_Body_States (States : Elist_Id) is
4661 Posted : Boolean := False;
4662 State_Elmt : Elmt_Id;
4663 State_Id : Entity_Id;
4666 if Present (States) then
4667 State_Elmt := First_Elmt (States);
4668 while Present (State_Elmt) loop
4669 State_Id := Node (State_Elmt);
4671 -- Constants are part of the hidden state of a package, but the
4672 -- compiler cannot determine whether they have variable input
4673 -- (SPARK RM 7.1.1(2)) and cannot classify them properly as a
4674 -- hidden state. Do not emit an error when a constant does not
4675 -- participate in a state refinement, even though it acts as a
4678 if Ekind (State_Id) = E_Constant then
4681 -- Generate an error message of the form:
4683 -- body of package ... has unused hidden states
4684 -- abstract state ... defined at ...
4685 -- variable ... defined at ...
4691 ("body of package & has unused hidden states", Body_Id);
4694 Error_Msg_Sloc := Sloc (State_Id);
4696 if Ekind (State_Id) = E_Abstract_State then
4698 ("\abstract state & defined #", Body_Id, State_Id);
4701 SPARK_Msg_NE ("\variable & defined #", Body_Id, State_Id);
4705 Next_Elmt (State_Elmt);
4708 end Report_Unused_Body_States;
4712 Prag : constant Node_Id := Get_Pragma (Body_Id, Pragma_Refined_State);
4713 Spec_Id : constant Entity_Id := Spec_Entity (Body_Id);
4717 -- Start of processing for Check_Unused_Body_States
4720 -- Inspect the clauses of pragma Refined_State and determine whether all
4721 -- visible states declared within the package body participate in the
4724 if Present (Prag) then
4725 Clause := Expression (Get_Argument (Prag, Spec_Id));
4726 States := Collect_Body_States (Body_Id);
4728 -- Multiple non-null state refinements appear as an aggregate
4730 if Nkind (Clause) = N_Aggregate then
4731 Clause := First (Component_Associations (Clause));
4732 while Present (Clause) loop
4733 Process_Refinement_Clause (Clause, States);
4737 -- Various forms of a single state refinement
4740 Process_Refinement_Clause (Clause, States);
4743 -- Ensure that all abstract states and objects declared in the
4744 -- package body state space are utilized as constituents.
4746 Report_Unused_Body_States (States);
4748 end Check_Unused_Body_States;
4754 function Choice_List (N : Node_Id) return List_Id is
4756 if Nkind (N) = N_Iterated_Component_Association then
4757 return Discrete_Choices (N);
4763 -------------------------
4764 -- Collect_Body_States --
4765 -------------------------
4767 function Collect_Body_States (Body_Id : Entity_Id) return Elist_Id is
4768 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean;
4769 -- Determine whether object Obj_Id is a suitable visible state of a
4772 procedure Collect_Visible_States
4773 (Pack_Id : Entity_Id;
4774 States : in out Elist_Id);
4775 -- Gather the entities of all abstract states and objects declared in
4776 -- the visible state space of package Pack_Id.
4778 ----------------------------
4779 -- Collect_Visible_States --
4780 ----------------------------
4782 procedure Collect_Visible_States
4783 (Pack_Id : Entity_Id;
4784 States : in out Elist_Id)
4786 Item_Id : Entity_Id;
4789 -- Traverse the entity chain of the package and inspect all visible
4792 Item_Id := First_Entity (Pack_Id);
4793 while Present (Item_Id) and then not In_Private_Part (Item_Id) loop
4795 -- Do not consider internally generated items as those cannot be
4796 -- named and participate in refinement.
4798 if not Comes_From_Source (Item_Id) then
4801 elsif Ekind (Item_Id) = E_Abstract_State then
4802 Append_New_Elmt (Item_Id, States);
4804 elsif Ekind_In (Item_Id, E_Constant, E_Variable)
4805 and then Is_Visible_Object (Item_Id)
4807 Append_New_Elmt (Item_Id, States);
4809 -- Recursively gather the visible states of a nested package
4811 elsif Ekind (Item_Id) = E_Package then
4812 Collect_Visible_States (Item_Id, States);
4815 Next_Entity (Item_Id);
4817 end Collect_Visible_States;
4819 -----------------------
4820 -- Is_Visible_Object --
4821 -----------------------
4823 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean is
4825 -- Objects that map generic formals to their actuals are not visible
4826 -- from outside the generic instantiation.
4828 if Present (Corresponding_Generic_Association
4829 (Declaration_Node (Obj_Id)))
4833 -- Constituents of a single protected/task type act as components of
4834 -- the type and are not visible from outside the type.
4836 elsif Ekind (Obj_Id) = E_Variable
4837 and then Present (Encapsulating_State (Obj_Id))
4838 and then Is_Single_Concurrent_Object (Encapsulating_State (Obj_Id))
4845 end Is_Visible_Object;
4849 Body_Decl : constant Node_Id := Unit_Declaration_Node (Body_Id);
4851 Item_Id : Entity_Id;
4852 States : Elist_Id := No_Elist;
4854 -- Start of processing for Collect_Body_States
4857 -- Inspect the declarations of the body looking for source objects,
4858 -- packages and package instantiations. Note that even though this
4859 -- processing is very similar to Collect_Visible_States, a package
4860 -- body does not have a First/Next_Entity list.
4862 Decl := First (Declarations (Body_Decl));
4863 while Present (Decl) loop
4865 -- Capture source objects as internally generated temporaries cannot
4866 -- be named and participate in refinement.
4868 if Nkind (Decl) = N_Object_Declaration then
4869 Item_Id := Defining_Entity (Decl);
4871 if Comes_From_Source (Item_Id)
4872 and then Is_Visible_Object (Item_Id)
4874 Append_New_Elmt (Item_Id, States);
4877 -- Capture the visible abstract states and objects of a source
4878 -- package [instantiation].
4880 elsif Nkind (Decl) = N_Package_Declaration then
4881 Item_Id := Defining_Entity (Decl);
4883 if Comes_From_Source (Item_Id) then
4884 Collect_Visible_States (Item_Id, States);
4892 end Collect_Body_States;
4894 ------------------------
4895 -- Collect_Interfaces --
4896 ------------------------
4898 procedure Collect_Interfaces
4900 Ifaces_List : out Elist_Id;
4901 Exclude_Parents : Boolean := False;
4902 Use_Full_View : Boolean := True)
4904 procedure Collect (Typ : Entity_Id);
4905 -- Subsidiary subprogram used to traverse the whole list
4906 -- of directly and indirectly implemented interfaces
4912 procedure Collect (Typ : Entity_Id) is
4913 Ancestor : Entity_Id;
4921 -- Handle private types and subtypes
4924 and then Is_Private_Type (Typ)
4925 and then Present (Full_View (Typ))
4927 Full_T := Full_View (Typ);
4929 if Ekind (Full_T) = E_Record_Subtype then
4930 Full_T := Etype (Typ);
4932 if Present (Full_View (Full_T)) then
4933 Full_T := Full_View (Full_T);
4938 -- Include the ancestor if we are generating the whole list of
4939 -- abstract interfaces.
4941 if Etype (Full_T) /= Typ
4943 -- Protect the frontend against wrong sources. For example:
4946 -- type A is tagged null record;
4947 -- type B is new A with private;
4948 -- type C is new A with private;
4950 -- type B is new C with null record;
4951 -- type C is new B with null record;
4954 and then Etype (Full_T) /= T
4956 Ancestor := Etype (Full_T);
4959 if Is_Interface (Ancestor) and then not Exclude_Parents then
4960 Append_Unique_Elmt (Ancestor, Ifaces_List);
4964 -- Traverse the graph of ancestor interfaces
4966 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
4967 Id := First (Abstract_Interface_List (Full_T));
4968 while Present (Id) loop
4969 Iface := Etype (Id);
4971 -- Protect against wrong uses. For example:
4972 -- type I is interface;
4973 -- type O is tagged null record;
4974 -- type Wrong is new I and O with null record; -- ERROR
4976 if Is_Interface (Iface) then
4978 and then Etype (T) /= T
4979 and then Interface_Present_In_Ancestor (Etype (T), Iface)
4984 Append_Unique_Elmt (Iface, Ifaces_List);
4993 -- Start of processing for Collect_Interfaces
4996 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
4997 Ifaces_List := New_Elmt_List;
4999 end Collect_Interfaces;
5001 ----------------------------------
5002 -- Collect_Interface_Components --
5003 ----------------------------------
5005 procedure Collect_Interface_Components
5006 (Tagged_Type : Entity_Id;
5007 Components_List : out Elist_Id)
5009 procedure Collect (Typ : Entity_Id);
5010 -- Subsidiary subprogram used to climb to the parents
5016 procedure Collect (Typ : Entity_Id) is
5017 Tag_Comp : Entity_Id;
5018 Parent_Typ : Entity_Id;
5021 -- Handle private types
5023 if Present (Full_View (Etype (Typ))) then
5024 Parent_Typ := Full_View (Etype (Typ));
5026 Parent_Typ := Etype (Typ);
5029 if Parent_Typ /= Typ
5031 -- Protect the frontend against wrong sources. For example:
5034 -- type A is tagged null record;
5035 -- type B is new A with private;
5036 -- type C is new A with private;
5038 -- type B is new C with null record;
5039 -- type C is new B with null record;
5042 and then Parent_Typ /= Tagged_Type
5044 Collect (Parent_Typ);
5047 -- Collect the components containing tags of secondary dispatch
5050 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
5051 while Present (Tag_Comp) loop
5052 pragma Assert (Present (Related_Type (Tag_Comp)));
5053 Append_Elmt (Tag_Comp, Components_List);
5055 Tag_Comp := Next_Tag_Component (Tag_Comp);
5059 -- Start of processing for Collect_Interface_Components
5062 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
5063 and then Is_Tagged_Type (Tagged_Type));
5065 Components_List := New_Elmt_List;
5066 Collect (Tagged_Type);
5067 end Collect_Interface_Components;
5069 -----------------------------
5070 -- Collect_Interfaces_Info --
5071 -----------------------------
5073 procedure Collect_Interfaces_Info
5075 Ifaces_List : out Elist_Id;
5076 Components_List : out Elist_Id;
5077 Tags_List : out Elist_Id)
5079 Comps_List : Elist_Id;
5080 Comp_Elmt : Elmt_Id;
5081 Comp_Iface : Entity_Id;
5082 Iface_Elmt : Elmt_Id;
5085 function Search_Tag (Iface : Entity_Id) return Entity_Id;
5086 -- Search for the secondary tag associated with the interface type
5087 -- Iface that is implemented by T.
5093 function Search_Tag (Iface : Entity_Id) return Entity_Id is
5096 if not Is_CPP_Class (T) then
5097 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
5099 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
5103 and then Is_Tag (Node (ADT))
5104 and then Related_Type (Node (ADT)) /= Iface
5106 -- Skip secondary dispatch table referencing thunks to user
5107 -- defined primitives covered by this interface.
5109 pragma Assert (Has_Suffix (Node (ADT), 'P'));
5112 -- Skip secondary dispatch tables of Ada types
5114 if not Is_CPP_Class (T) then
5116 -- Skip secondary dispatch table referencing thunks to
5117 -- predefined primitives.
5119 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
5122 -- Skip secondary dispatch table referencing user-defined
5123 -- primitives covered by this interface.
5125 pragma Assert (Has_Suffix (Node (ADT), 'D'));
5128 -- Skip secondary dispatch table referencing predefined
5131 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
5136 pragma Assert (Is_Tag (Node (ADT)));
5140 -- Start of processing for Collect_Interfaces_Info
5143 Collect_Interfaces (T, Ifaces_List);
5144 Collect_Interface_Components (T, Comps_List);
5146 -- Search for the record component and tag associated with each
5147 -- interface type of T.
5149 Components_List := New_Elmt_List;
5150 Tags_List := New_Elmt_List;
5152 Iface_Elmt := First_Elmt (Ifaces_List);
5153 while Present (Iface_Elmt) loop
5154 Iface := Node (Iface_Elmt);
5156 -- Associate the primary tag component and the primary dispatch table
5157 -- with all the interfaces that are parents of T
5159 if Is_Ancestor (Iface, T, Use_Full_View => True) then
5160 Append_Elmt (First_Tag_Component (T), Components_List);
5161 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
5163 -- Otherwise search for the tag component and secondary dispatch
5167 Comp_Elmt := First_Elmt (Comps_List);
5168 while Present (Comp_Elmt) loop
5169 Comp_Iface := Related_Type (Node (Comp_Elmt));
5171 if Comp_Iface = Iface
5172 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
5174 Append_Elmt (Node (Comp_Elmt), Components_List);
5175 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
5179 Next_Elmt (Comp_Elmt);
5181 pragma Assert (Present (Comp_Elmt));
5184 Next_Elmt (Iface_Elmt);
5186 end Collect_Interfaces_Info;
5188 ---------------------
5189 -- Collect_Parents --
5190 ---------------------
5192 procedure Collect_Parents
5194 List : out Elist_Id;
5195 Use_Full_View : Boolean := True)
5197 Current_Typ : Entity_Id := T;
5198 Parent_Typ : Entity_Id;
5201 List := New_Elmt_List;
5203 -- No action if the if the type has no parents
5205 if T = Etype (T) then
5210 Parent_Typ := Etype (Current_Typ);
5212 if Is_Private_Type (Parent_Typ)
5213 and then Present (Full_View (Parent_Typ))
5214 and then Use_Full_View
5216 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5219 Append_Elmt (Parent_Typ, List);
5221 exit when Parent_Typ = Current_Typ;
5222 Current_Typ := Parent_Typ;
5224 end Collect_Parents;
5226 ----------------------------------
5227 -- Collect_Primitive_Operations --
5228 ----------------------------------
5230 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
5231 B_Type : constant Entity_Id := Base_Type (T);
5233 function Match (E : Entity_Id) return Boolean;
5234 -- True if E's base type is B_Type, or E is of an anonymous access type
5235 -- and the base type of its designated type is B_Type.
5241 function Match (E : Entity_Id) return Boolean is
5242 Etyp : Entity_Id := Etype (E);
5245 if Ekind (Etyp) = E_Anonymous_Access_Type then
5246 Etyp := Designated_Type (Etyp);
5249 -- In Ada 2012 a primitive operation may have a formal of an
5250 -- incomplete view of the parent type.
5252 return Base_Type (Etyp) = B_Type
5254 (Ada_Version >= Ada_2012
5255 and then Ekind (Etyp) = E_Incomplete_Type
5256 and then Full_View (Etyp) = B_Type);
5261 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
5262 B_Scope : Entity_Id := Scope (B_Type);
5264 Eq_Prims_List : Elist_Id := No_Elist;
5267 Is_Type_In_Pkg : Boolean;
5268 Formal_Derived : Boolean := False;
5271 -- Start of processing for Collect_Primitive_Operations
5274 -- For tagged types, the primitive operations are collected as they
5275 -- are declared, and held in an explicit list which is simply returned.
5277 if Is_Tagged_Type (B_Type) then
5278 return Primitive_Operations (B_Type);
5280 -- An untagged generic type that is a derived type inherits the
5281 -- primitive operations of its parent type. Other formal types only
5282 -- have predefined operators, which are not explicitly represented.
5284 elsif Is_Generic_Type (B_Type) then
5285 if Nkind (B_Decl) = N_Formal_Type_Declaration
5286 and then Nkind (Formal_Type_Definition (B_Decl)) =
5287 N_Formal_Derived_Type_Definition
5289 Formal_Derived := True;
5291 return New_Elmt_List;
5295 Op_List := New_Elmt_List;
5297 if B_Scope = Standard_Standard then
5298 if B_Type = Standard_String then
5299 Append_Elmt (Standard_Op_Concat, Op_List);
5301 elsif B_Type = Standard_Wide_String then
5302 Append_Elmt (Standard_Op_Concatw, Op_List);
5308 -- Locate the primitive subprograms of the type
5311 -- The primitive operations appear after the base type, except if the
5312 -- derivation happens within the private part of B_Scope and the type
5313 -- is a private type, in which case both the type and some primitive
5314 -- operations may appear before the base type, and the list of
5315 -- candidates starts after the type.
5317 if In_Open_Scopes (B_Scope)
5318 and then Scope (T) = B_Scope
5319 and then In_Private_Part (B_Scope)
5321 Id := Next_Entity (T);
5323 -- In Ada 2012, If the type has an incomplete partial view, there may
5324 -- be primitive operations declared before the full view, so we need
5325 -- to start scanning from the incomplete view, which is earlier on
5326 -- the entity chain.
5328 elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration
5329 and then Present (Incomplete_View (Parent (B_Type)))
5331 Id := Defining_Entity (Incomplete_View (Parent (B_Type)));
5333 -- If T is a derived from a type with an incomplete view declared
5334 -- elsewhere, that incomplete view is irrelevant, we want the
5335 -- operations in the scope of T.
5337 if Scope (Id) /= Scope (B_Type) then
5338 Id := Next_Entity (B_Type);
5342 Id := Next_Entity (B_Type);
5345 -- Set flag if this is a type in a package spec
5348 Is_Package_Or_Generic_Package (B_Scope)
5350 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
5353 while Present (Id) loop
5355 -- Test whether the result type or any of the parameter types of
5356 -- each subprogram following the type match that type when the
5357 -- type is declared in a package spec, is a derived type, or the
5358 -- subprogram is marked as primitive. (The Is_Primitive test is
5359 -- needed to find primitives of nonderived types in declarative
5360 -- parts that happen to override the predefined "=" operator.)
5362 -- Note that generic formal subprograms are not considered to be
5363 -- primitive operations and thus are never inherited.
5365 if Is_Overloadable (Id)
5366 and then (Is_Type_In_Pkg
5367 or else Is_Derived_Type (B_Type)
5368 or else Is_Primitive (Id))
5369 and then Nkind (Parent (Parent (Id)))
5370 not in N_Formal_Subprogram_Declaration
5378 Formal := First_Formal (Id);
5379 while Present (Formal) loop
5380 if Match (Formal) then
5385 Next_Formal (Formal);
5389 -- For a formal derived type, the only primitives are the ones
5390 -- inherited from the parent type. Operations appearing in the
5391 -- package declaration are not primitive for it.
5394 and then (not Formal_Derived or else Present (Alias (Id)))
5396 -- In the special case of an equality operator aliased to
5397 -- an overriding dispatching equality belonging to the same
5398 -- type, we don't include it in the list of primitives.
5399 -- This avoids inheriting multiple equality operators when
5400 -- deriving from untagged private types whose full type is
5401 -- tagged, which can otherwise cause ambiguities. Note that
5402 -- this should only happen for this kind of untagged parent
5403 -- type, since normally dispatching operations are inherited
5404 -- using the type's Primitive_Operations list.
5406 if Chars (Id) = Name_Op_Eq
5407 and then Is_Dispatching_Operation (Id)
5408 and then Present (Alias (Id))
5409 and then Present (Overridden_Operation (Alias (Id)))
5410 and then Base_Type (Etype (First_Entity (Id))) =
5411 Base_Type (Etype (First_Entity (Alias (Id))))
5415 -- Include the subprogram in the list of primitives
5418 Append_Elmt (Id, Op_List);
5420 -- Save collected equality primitives for later filtering
5421 -- (if we are processing a private type for which we can
5422 -- collect several candidates).
5424 if Inherits_From_Tagged_Full_View (T)
5425 and then Chars (Id) = Name_Op_Eq
5426 and then Etype (First_Formal (Id)) =
5427 Etype (Next_Formal (First_Formal (Id)))
5429 if No (Eq_Prims_List) then
5430 Eq_Prims_List := New_Elmt_List;
5433 Append_Elmt (Id, Eq_Prims_List);
5441 -- For a type declared in System, some of its operations may
5442 -- appear in the target-specific extension to System.
5445 and then B_Scope = RTU_Entity (System)
5446 and then Present_System_Aux
5448 B_Scope := System_Aux_Id;
5449 Id := First_Entity (System_Aux_Id);
5453 -- Filter collected equality primitives
5455 if Inherits_From_Tagged_Full_View (T)
5456 and then Present (Eq_Prims_List)
5459 First : constant Elmt_Id := First_Elmt (Eq_Prims_List);
5463 pragma Assert (No (Next_Elmt (First))
5464 or else No (Next_Elmt (Next_Elmt (First))));
5466 -- No action needed if we have collected a single equality
5469 if Present (Next_Elmt (First)) then
5470 Second := Next_Elmt (First);
5472 if Is_Dispatching_Operation
5473 (Ultimate_Alias (Node (First)))
5475 Remove (Op_List, Node (First));
5477 elsif Is_Dispatching_Operation
5478 (Ultimate_Alias (Node (Second)))
5480 Remove (Op_List, Node (Second));
5483 pragma Assert (False);
5484 raise Program_Error;
5492 end Collect_Primitive_Operations;
5494 -----------------------------------
5495 -- Compile_Time_Constraint_Error --
5496 -----------------------------------
5498 function Compile_Time_Constraint_Error
5501 Ent : Entity_Id := Empty;
5502 Loc : Source_Ptr := No_Location;
5503 Warn : Boolean := False;
5504 Extra_Msg : String := "") return Node_Id
5506 Msgc : String (1 .. Msg'Length + 3);
5507 -- Copy of message, with room for possible ?? or << and ! at end
5513 -- Start of processing for Compile_Time_Constraint_Error
5516 -- If this is a warning, convert it into an error if we are in code
5517 -- subject to SPARK_Mode being set On, unless Warn is True to force a
5518 -- warning. The rationale is that a compile-time constraint error should
5519 -- lead to an error instead of a warning when SPARK_Mode is On, but in
5520 -- a few cases we prefer to issue a warning and generate both a suitable
5521 -- run-time error in GNAT and a suitable check message in GNATprove.
5522 -- Those cases are those that likely correspond to deactivated SPARK
5523 -- code, so that this kind of code can be compiled and analyzed instead
5524 -- of being rejected.
5526 Error_Msg_Warn := Warn or SPARK_Mode /= On;
5528 -- A static constraint error in an instance body is not a fatal error.
5529 -- we choose to inhibit the message altogether, because there is no
5530 -- obvious node (for now) on which to post it. On the other hand the
5531 -- offending node must be replaced with a constraint_error in any case.
5533 -- No messages are generated if we already posted an error on this node
5535 if not Error_Posted (N) then
5536 if Loc /= No_Location then
5542 -- Copy message to Msgc, converting any ? in the message into <
5543 -- instead, so that we have an error in GNATprove mode.
5547 for J in 1 .. Msgl loop
5548 if Msg (J) = '?' and then (J = 1 or else Msg (J - 1) /= ''') then
5551 Msgc (J) := Msg (J);
5555 -- Message is a warning, even in Ada 95 case
5557 if Msg (Msg'Last) = '?' or else Msg (Msg'Last) = '<' then
5560 -- In Ada 83, all messages are warnings. In the private part and the
5561 -- body of an instance, constraint_checks are only warnings. We also
5562 -- make this a warning if the Warn parameter is set.
5565 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
5566 or else In_Instance_Not_Visible
5574 -- Otherwise we have a real error message (Ada 95 static case) and we
5575 -- make this an unconditional message. Note that in the warning case
5576 -- we do not make the message unconditional, it seems reasonable to
5577 -- delete messages like this (about exceptions that will be raised)
5586 -- One more test, skip the warning if the related expression is
5587 -- statically unevaluated, since we don't want to warn about what
5588 -- will happen when something is evaluated if it never will be
5591 if not Is_Statically_Unevaluated (N) then
5592 if Present (Ent) then
5593 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
5595 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
5598 -- Emit any extra message as a continuation
5600 if Extra_Msg /= "" then
5601 Error_Msg_N ('\' & Extra_Msg, N);
5606 -- Check whether the context is an Init_Proc
5608 if Inside_Init_Proc then
5610 Conc_Typ : constant Entity_Id :=
5611 Corresponding_Concurrent_Type
5612 (Entity (Parameter_Type (First
5613 (Parameter_Specifications
5614 (Parent (Current_Scope))))));
5617 -- Don't complain if the corresponding concurrent type
5618 -- doesn't come from source (i.e. a single task/protected
5621 if Present (Conc_Typ)
5622 and then not Comes_From_Source (Conc_Typ)
5625 ("\& [<<", N, Standard_Constraint_Error, Eloc);
5628 if GNATprove_Mode then
5630 ("\& would have been raised for objects of this "
5631 & "type", N, Standard_Constraint_Error, Eloc);
5634 ("\& will be raised for objects of this type??",
5635 N, Standard_Constraint_Error, Eloc);
5641 Error_Msg_NEL ("\& [<<", N, Standard_Constraint_Error, Eloc);
5645 Error_Msg ("\static expression fails Constraint_Check", Eloc);
5646 Set_Error_Posted (N);
5652 end Compile_Time_Constraint_Error;
5654 -----------------------
5655 -- Conditional_Delay --
5656 -----------------------
5658 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
5660 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
5661 Set_Has_Delayed_Freeze (New_Ent);
5663 end Conditional_Delay;
5665 -------------------------
5666 -- Copy_Component_List --
5667 -------------------------
5669 function Copy_Component_List
5671 Loc : Source_Ptr) return List_Id
5674 Comps : constant List_Id := New_List;
5677 Comp := First_Component (Underlying_Type (R_Typ));
5678 while Present (Comp) loop
5679 if Comes_From_Source (Comp) then
5681 Comp_Decl : constant Node_Id := Declaration_Node (Comp);
5684 Make_Component_Declaration (Loc,
5685 Defining_Identifier =>
5686 Make_Defining_Identifier (Loc, Chars (Comp)),
5687 Component_Definition =>
5689 (Component_Definition (Comp_Decl), New_Sloc => Loc)));
5693 Next_Component (Comp);
5697 end Copy_Component_List;
5699 -------------------------
5700 -- Copy_Parameter_List --
5701 -------------------------
5703 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
5704 Loc : constant Source_Ptr := Sloc (Subp_Id);
5709 if No (First_Formal (Subp_Id)) then
5713 Formal := First_Formal (Subp_Id);
5714 while Present (Formal) loop
5716 Make_Parameter_Specification (Loc,
5717 Defining_Identifier =>
5718 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
5719 In_Present => In_Present (Parent (Formal)),
5720 Out_Present => Out_Present (Parent (Formal)),
5722 New_Occurrence_Of (Etype (Formal), Loc),
5724 New_Copy_Tree (Expression (Parent (Formal)))));
5726 Next_Formal (Formal);
5731 end Copy_Parameter_List;
5733 ----------------------------
5734 -- Copy_SPARK_Mode_Aspect --
5735 ----------------------------
5737 procedure Copy_SPARK_Mode_Aspect (From : Node_Id; To : Node_Id) is
5738 pragma Assert (not Has_Aspects (To));
5742 if Has_Aspects (From) then
5743 Asp := Find_Aspect (Defining_Entity (From), Aspect_SPARK_Mode);
5745 if Present (Asp) then
5746 Set_Aspect_Specifications (To, New_List (New_Copy_Tree (Asp)));
5747 Set_Has_Aspects (To, True);
5750 end Copy_SPARK_Mode_Aspect;
5752 --------------------------
5753 -- Copy_Subprogram_Spec --
5754 --------------------------
5756 function Copy_Subprogram_Spec (Spec : Node_Id) return Node_Id is
5758 Formal_Spec : Node_Id;
5762 -- The structure of the original tree must be replicated without any
5763 -- alterations. Use New_Copy_Tree for this purpose.
5765 Result := New_Copy_Tree (Spec);
5767 -- However, the spec of a null procedure carries the corresponding null
5768 -- statement of the body (created by the parser), and this cannot be
5769 -- shared with the new subprogram spec.
5771 if Nkind (Result) = N_Procedure_Specification then
5772 Set_Null_Statement (Result, Empty);
5775 -- Create a new entity for the defining unit name
5777 Def_Id := Defining_Unit_Name (Result);
5778 Set_Defining_Unit_Name (Result,
5779 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
5781 -- Create new entities for the formal parameters
5783 if Present (Parameter_Specifications (Result)) then
5784 Formal_Spec := First (Parameter_Specifications (Result));
5785 while Present (Formal_Spec) loop
5786 Def_Id := Defining_Identifier (Formal_Spec);
5787 Set_Defining_Identifier (Formal_Spec,
5788 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
5795 end Copy_Subprogram_Spec;
5797 --------------------------------
5798 -- Corresponding_Generic_Type --
5799 --------------------------------
5801 function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id is
5807 if not Is_Generic_Actual_Type (T) then
5810 -- If the actual is the actual of an enclosing instance, resolution
5811 -- was correct in the generic.
5813 elsif Nkind (Parent (T)) = N_Subtype_Declaration
5814 and then Is_Entity_Name (Subtype_Indication (Parent (T)))
5816 Is_Generic_Actual_Type (Entity (Subtype_Indication (Parent (T))))
5823 if Is_Wrapper_Package (Inst) then
5824 Inst := Related_Instance (Inst);
5829 (Specification (Unit_Declaration_Node (Inst)));
5831 -- Generic actual has the same name as the corresponding formal
5833 Typ := First_Entity (Gen);
5834 while Present (Typ) loop
5835 if Chars (Typ) = Chars (T) then
5844 end Corresponding_Generic_Type;
5846 --------------------
5847 -- Current_Entity --
5848 --------------------
5850 -- The currently visible definition for a given identifier is the
5851 -- one most chained at the start of the visibility chain, i.e. the
5852 -- one that is referenced by the Node_Id value of the name of the
5853 -- given identifier.
5855 function Current_Entity (N : Node_Id) return Entity_Id is
5857 return Get_Name_Entity_Id (Chars (N));
5860 -----------------------------
5861 -- Current_Entity_In_Scope --
5862 -----------------------------
5864 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
5866 CS : constant Entity_Id := Current_Scope;
5868 Transient_Case : constant Boolean := Scope_Is_Transient;
5871 E := Get_Name_Entity_Id (Chars (N));
5873 and then Scope (E) /= CS
5874 and then (not Transient_Case or else Scope (E) /= Scope (CS))
5880 end Current_Entity_In_Scope;
5886 function Current_Scope return Entity_Id is
5888 if Scope_Stack.Last = -1 then
5889 return Standard_Standard;
5892 C : constant Entity_Id :=
5893 Scope_Stack.Table (Scope_Stack.Last).Entity;
5898 return Standard_Standard;
5904 ----------------------------
5905 -- Current_Scope_No_Loops --
5906 ----------------------------
5908 function Current_Scope_No_Loops return Entity_Id is
5912 -- Examine the scope stack starting from the current scope and skip any
5913 -- internally generated loops.
5916 while Present (S) and then S /= Standard_Standard loop
5917 if Ekind (S) = E_Loop and then not Comes_From_Source (S) then
5925 end Current_Scope_No_Loops;
5927 ------------------------
5928 -- Current_Subprogram --
5929 ------------------------
5931 function Current_Subprogram return Entity_Id is
5932 Scop : constant Entity_Id := Current_Scope;
5934 if Is_Subprogram_Or_Generic_Subprogram (Scop) then
5937 return Enclosing_Subprogram (Scop);
5939 end Current_Subprogram;
5941 ----------------------------------
5942 -- Deepest_Type_Access_Level --
5943 ----------------------------------
5945 function Deepest_Type_Access_Level (Typ : Entity_Id) return Uint is
5947 if Ekind (Typ) = E_Anonymous_Access_Type
5948 and then not Is_Local_Anonymous_Access (Typ)
5949 and then Nkind (Associated_Node_For_Itype (Typ)) = N_Object_Declaration
5951 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
5955 Scope_Depth (Enclosing_Dynamic_Scope
5956 (Defining_Identifier
5957 (Associated_Node_For_Itype (Typ))));
5959 -- For generic formal type, return Int'Last (infinite).
5960 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
5962 elsif Is_Generic_Type (Root_Type (Typ)) then
5963 return UI_From_Int (Int'Last);
5966 return Type_Access_Level (Typ);
5968 end Deepest_Type_Access_Level;
5970 ---------------------
5971 -- Defining_Entity --
5972 ---------------------
5974 function Defining_Entity (N : Node_Id) return Entity_Id is
5977 when N_Abstract_Subprogram_Declaration
5978 | N_Expression_Function
5979 | N_Formal_Subprogram_Declaration
5980 | N_Generic_Package_Declaration
5981 | N_Generic_Subprogram_Declaration
5982 | N_Package_Declaration
5984 | N_Subprogram_Body_Stub
5985 | N_Subprogram_Declaration
5986 | N_Subprogram_Renaming_Declaration
5988 return Defining_Entity (Specification (N));
5990 when N_Component_Declaration
5991 | N_Defining_Program_Unit_Name
5992 | N_Discriminant_Specification
5994 | N_Entry_Declaration
5995 | N_Entry_Index_Specification
5996 | N_Exception_Declaration
5997 | N_Exception_Renaming_Declaration
5998 | N_Formal_Object_Declaration
5999 | N_Formal_Package_Declaration
6000 | N_Formal_Type_Declaration
6001 | N_Full_Type_Declaration
6002 | N_Implicit_Label_Declaration
6003 | N_Incomplete_Type_Declaration
6004 | N_Iterator_Specification
6005 | N_Loop_Parameter_Specification
6006 | N_Number_Declaration
6007 | N_Object_Declaration
6008 | N_Object_Renaming_Declaration
6009 | N_Package_Body_Stub
6010 | N_Parameter_Specification
6011 | N_Private_Extension_Declaration
6012 | N_Private_Type_Declaration
6014 | N_Protected_Body_Stub
6015 | N_Protected_Type_Declaration
6016 | N_Single_Protected_Declaration
6017 | N_Single_Task_Declaration
6018 | N_Subtype_Declaration
6021 | N_Task_Type_Declaration
6023 return Defining_Identifier (N);
6025 when N_Compilation_Unit =>
6026 return Defining_Entity (Unit (N));
6029 return Defining_Entity (Proper_Body (N));
6031 when N_Function_Instantiation
6032 | N_Function_Specification
6033 | N_Generic_Function_Renaming_Declaration
6034 | N_Generic_Package_Renaming_Declaration
6035 | N_Generic_Procedure_Renaming_Declaration
6037 | N_Package_Instantiation
6038 | N_Package_Renaming_Declaration
6039 | N_Package_Specification
6040 | N_Procedure_Instantiation
6041 | N_Procedure_Specification
6044 Nam : constant Node_Id := Defining_Unit_Name (N);
6045 Err : Entity_Id := Empty;
6048 if Nkind (Nam) in N_Entity then
6051 -- For Error, make up a name and attach to declaration so we
6052 -- can continue semantic analysis.
6054 elsif Nam = Error then
6055 Err := Make_Temporary (Sloc (N), 'T');
6056 Set_Defining_Unit_Name (N, Err);
6060 -- If not an entity, get defining identifier
6063 return Defining_Identifier (Nam);
6067 when N_Block_Statement
6070 return Entity (Identifier (N));
6073 raise Program_Error;
6075 end Defining_Entity;
6077 --------------------------
6078 -- Denotes_Discriminant --
6079 --------------------------
6081 function Denotes_Discriminant
6083 Check_Concurrent : Boolean := False) return Boolean
6088 if not Is_Entity_Name (N) or else No (Entity (N)) then
6094 -- If we are checking for a protected type, the discriminant may have
6095 -- been rewritten as the corresponding discriminal of the original type
6096 -- or of the corresponding concurrent record, depending on whether we
6097 -- are in the spec or body of the protected type.
6099 return Ekind (E) = E_Discriminant
6102 and then Ekind (E) = E_In_Parameter
6103 and then Present (Discriminal_Link (E))
6105 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
6107 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
6108 end Denotes_Discriminant;
6110 -------------------------
6111 -- Denotes_Same_Object --
6112 -------------------------
6114 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
6115 function Is_Renaming (N : Node_Id) return Boolean;
6116 -- Return true if N names a renaming entity
6118 function Is_Valid_Renaming (N : Node_Id) return Boolean;
6119 -- For renamings, return False if the prefix of any dereference within
6120 -- the renamed object_name is a variable, or any expression within the
6121 -- renamed object_name contains references to variables or calls on
6122 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
6128 function Is_Renaming (N : Node_Id) return Boolean is
6131 Is_Entity_Name (N) and then Present (Renamed_Entity (Entity (N)));
6134 -----------------------
6135 -- Is_Valid_Renaming --
6136 -----------------------
6138 function Is_Valid_Renaming (N : Node_Id) return Boolean is
6139 function Check_Renaming (N : Node_Id) return Boolean;
6140 -- Recursive function used to traverse all the prefixes of N
6142 --------------------
6143 -- Check_Renaming --
6144 --------------------
6146 function Check_Renaming (N : Node_Id) return Boolean is
6149 and then not Check_Renaming (Renamed_Entity (Entity (N)))
6154 if Nkind (N) = N_Indexed_Component then
6159 Indx := First (Expressions (N));
6160 while Present (Indx) loop
6161 if not Is_OK_Static_Expression (Indx) then
6170 if Has_Prefix (N) then
6172 P : constant Node_Id := Prefix (N);
6175 if Nkind (N) = N_Explicit_Dereference
6176 and then Is_Variable (P)
6180 elsif Is_Entity_Name (P)
6181 and then Ekind (Entity (P)) = E_Function
6185 elsif Nkind (P) = N_Function_Call then
6189 -- Recursion to continue traversing the prefix of the
6190 -- renaming expression
6192 return Check_Renaming (P);
6199 -- Start of processing for Is_Valid_Renaming
6202 return Check_Renaming (N);
6203 end Is_Valid_Renaming;
6207 Obj1 : Node_Id := A1;
6208 Obj2 : Node_Id := A2;
6210 -- Start of processing for Denotes_Same_Object
6213 -- Both names statically denote the same stand-alone object or parameter
6214 -- (RM 6.4.1(6.5/3))
6216 if Is_Entity_Name (Obj1)
6217 and then Is_Entity_Name (Obj2)
6218 and then Entity (Obj1) = Entity (Obj2)
6223 -- For renamings, the prefix of any dereference within the renamed
6224 -- object_name is not a variable, and any expression within the
6225 -- renamed object_name contains no references to variables nor
6226 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
6228 if Is_Renaming (Obj1) then
6229 if Is_Valid_Renaming (Obj1) then
6230 Obj1 := Renamed_Entity (Entity (Obj1));
6236 if Is_Renaming (Obj2) then
6237 if Is_Valid_Renaming (Obj2) then
6238 Obj2 := Renamed_Entity (Entity (Obj2));
6244 -- No match if not same node kind (such cases are handled by
6245 -- Denotes_Same_Prefix)
6247 if Nkind (Obj1) /= Nkind (Obj2) then
6250 -- After handling valid renamings, one of the two names statically
6251 -- denoted a renaming declaration whose renamed object_name is known
6252 -- to denote the same object as the other (RM 6.4.1(6.10/3))
6254 elsif Is_Entity_Name (Obj1) then
6255 if Is_Entity_Name (Obj2) then
6256 return Entity (Obj1) = Entity (Obj2);
6261 -- Both names are selected_components, their prefixes are known to
6262 -- denote the same object, and their selector_names denote the same
6263 -- component (RM 6.4.1(6.6/3)).
6265 elsif Nkind (Obj1) = N_Selected_Component then
6266 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
6268 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
6270 -- Both names are dereferences and the dereferenced names are known to
6271 -- denote the same object (RM 6.4.1(6.7/3))
6273 elsif Nkind (Obj1) = N_Explicit_Dereference then
6274 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
6276 -- Both names are indexed_components, their prefixes are known to denote
6277 -- the same object, and each of the pairs of corresponding index values
6278 -- are either both static expressions with the same static value or both
6279 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
6281 elsif Nkind (Obj1) = N_Indexed_Component then
6282 if not Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
6290 Indx1 := First (Expressions (Obj1));
6291 Indx2 := First (Expressions (Obj2));
6292 while Present (Indx1) loop
6294 -- Indexes must denote the same static value or same object
6296 if Is_OK_Static_Expression (Indx1) then
6297 if not Is_OK_Static_Expression (Indx2) then
6300 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
6304 elsif not Denotes_Same_Object (Indx1, Indx2) then
6316 -- Both names are slices, their prefixes are known to denote the same
6317 -- object, and the two slices have statically matching index constraints
6318 -- (RM 6.4.1(6.9/3))
6320 elsif Nkind (Obj1) = N_Slice
6321 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
6324 Lo1, Lo2, Hi1, Hi2 : Node_Id;
6327 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
6328 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
6330 -- Check whether bounds are statically identical. There is no
6331 -- attempt to detect partial overlap of slices.
6333 return Denotes_Same_Object (Lo1, Lo2)
6335 Denotes_Same_Object (Hi1, Hi2);
6338 -- In the recursion, literals appear as indexes
6340 elsif Nkind (Obj1) = N_Integer_Literal
6342 Nkind (Obj2) = N_Integer_Literal
6344 return Intval (Obj1) = Intval (Obj2);
6349 end Denotes_Same_Object;
6351 -------------------------
6352 -- Denotes_Same_Prefix --
6353 -------------------------
6355 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
6357 if Is_Entity_Name (A1) then
6358 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
6359 and then not Is_Access_Type (Etype (A1))
6361 return Denotes_Same_Object (A1, Prefix (A2))
6362 or else Denotes_Same_Prefix (A1, Prefix (A2));
6367 elsif Is_Entity_Name (A2) then
6368 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
6370 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
6372 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
6375 Root1, Root2 : Node_Id;
6376 Depth1, Depth2 : Nat := 0;
6379 Root1 := Prefix (A1);
6380 while not Is_Entity_Name (Root1) loop
6382 (Root1, N_Selected_Component, N_Indexed_Component)
6386 Root1 := Prefix (Root1);
6389 Depth1 := Depth1 + 1;
6392 Root2 := Prefix (A2);
6393 while not Is_Entity_Name (Root2) loop
6394 if not Nkind_In (Root2, N_Selected_Component,
6395 N_Indexed_Component)
6399 Root2 := Prefix (Root2);
6402 Depth2 := Depth2 + 1;
6405 -- If both have the same depth and they do not denote the same
6406 -- object, they are disjoint and no warning is needed.
6408 if Depth1 = Depth2 then
6411 elsif Depth1 > Depth2 then
6412 Root1 := Prefix (A1);
6413 for J in 1 .. Depth1 - Depth2 - 1 loop
6414 Root1 := Prefix (Root1);
6417 return Denotes_Same_Object (Root1, A2);
6420 Root2 := Prefix (A2);
6421 for J in 1 .. Depth2 - Depth1 - 1 loop
6422 Root2 := Prefix (Root2);
6425 return Denotes_Same_Object (A1, Root2);
6432 end Denotes_Same_Prefix;
6434 ----------------------
6435 -- Denotes_Variable --
6436 ----------------------
6438 function Denotes_Variable (N : Node_Id) return Boolean is
6440 return Is_Variable (N) and then Paren_Count (N) = 0;
6441 end Denotes_Variable;
6443 -----------------------------
6444 -- Depends_On_Discriminant --
6445 -----------------------------
6447 function Depends_On_Discriminant (N : Node_Id) return Boolean is
6452 Get_Index_Bounds (N, L, H);
6453 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
6454 end Depends_On_Discriminant;
6456 -------------------------
6457 -- Designate_Same_Unit --
6458 -------------------------
6460 function Designate_Same_Unit
6462 Name2 : Node_Id) return Boolean
6464 K1 : constant Node_Kind := Nkind (Name1);
6465 K2 : constant Node_Kind := Nkind (Name2);
6467 function Prefix_Node (N : Node_Id) return Node_Id;
6468 -- Returns the parent unit name node of a defining program unit name
6469 -- or the prefix if N is a selected component or an expanded name.
6471 function Select_Node (N : Node_Id) return Node_Id;
6472 -- Returns the defining identifier node of a defining program unit
6473 -- name or the selector node if N is a selected component or an
6480 function Prefix_Node (N : Node_Id) return Node_Id is
6482 if Nkind (N) = N_Defining_Program_Unit_Name then
6493 function Select_Node (N : Node_Id) return Node_Id is
6495 if Nkind (N) = N_Defining_Program_Unit_Name then
6496 return Defining_Identifier (N);
6498 return Selector_Name (N);
6502 -- Start of processing for Designate_Same_Unit
6505 if Nkind_In (K1, N_Identifier, N_Defining_Identifier)
6507 Nkind_In (K2, N_Identifier, N_Defining_Identifier)
6509 return Chars (Name1) = Chars (Name2);
6511 elsif Nkind_In (K1, N_Expanded_Name,
6512 N_Selected_Component,
6513 N_Defining_Program_Unit_Name)
6515 Nkind_In (K2, N_Expanded_Name,
6516 N_Selected_Component,
6517 N_Defining_Program_Unit_Name)
6520 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
6522 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
6527 end Designate_Same_Unit;
6529 ---------------------------------------------
6530 -- Diagnose_Iterated_Component_Association --
6531 ---------------------------------------------
6533 procedure Diagnose_Iterated_Component_Association (N : Node_Id) is
6534 Def_Id : constant Entity_Id := Defining_Identifier (N);
6538 -- Determine whether the iterated component association appears within
6539 -- an aggregate. If this is the case, raise Program_Error because the
6540 -- iterated component association cannot be left in the tree as is and
6541 -- must always be processed by the related aggregate.
6544 while Present (Aggr) loop
6545 if Nkind (Aggr) = N_Aggregate then
6546 raise Program_Error;
6548 -- Prevent the search from going too far
6550 elsif Is_Body_Or_Package_Declaration (Aggr) then
6554 Aggr := Parent (Aggr);
6557 -- At this point it is known that the iterated component association is
6558 -- not within an aggregate. This is really a quantified expression with
6559 -- a missing "all" or "some" quantifier.
6561 Error_Msg_N ("missing quantifier", Def_Id);
6563 -- Rewrite the iterated component association as True to prevent any
6566 Rewrite (N, New_Occurrence_Of (Standard_True, Sloc (N)));
6568 end Diagnose_Iterated_Component_Association;
6570 ---------------------------------
6571 -- Dynamic_Accessibility_Level --
6572 ---------------------------------
6574 function Dynamic_Accessibility_Level (N : Node_Id) return Node_Id is
6575 Loc : constant Source_Ptr := Sloc (N);
6577 function Make_Level_Literal (Level : Uint) return Node_Id;
6578 -- Construct an integer literal representing an accessibility level
6579 -- with its type set to Natural.
6581 ------------------------
6582 -- Make_Level_Literal --
6583 ------------------------
6585 function Make_Level_Literal (Level : Uint) return Node_Id is
6586 Result : constant Node_Id := Make_Integer_Literal (Loc, Level);
6589 Set_Etype (Result, Standard_Natural);
6591 end Make_Level_Literal;
6595 Expr : Node_Id := Original_Node (N);
6596 -- Expr references the original node because at this stage N may be the
6597 -- reference to a variable internally created by the frontend to remove
6598 -- side effects of an expression.
6602 -- Start of processing for Dynamic_Accessibility_Level
6605 if Is_Entity_Name (Expr) then
6608 if Present (Renamed_Object (E)) then
6609 return Dynamic_Accessibility_Level (Renamed_Object (E));
6613 or else Ekind_In (E, E_Variable, E_Constant))
6614 and then Present (Get_Accessibility (E))
6616 return New_Occurrence_Of (Get_Accessibility (E), Loc);
6620 -- Handle a constant-folded conditional expression by avoiding use of
6621 -- the original node.
6623 if Nkind_In (Expr, N_Case_Expression, N_If_Expression) then
6627 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
6629 case Nkind (Expr) is
6630 -- It may be possible that we have an access object denoted by an
6631 -- attribute reference for 'Loop_Entry which may, in turn, have an
6632 -- indexed component representing a loop identifier.
6634 -- In this case we must climb up the indexed component and set expr
6635 -- to the attribute reference so the rest of the machinery can
6636 -- operate as expected.
6638 when N_Indexed_Component =>
6639 if Nkind (Prefix (Expr)) = N_Attribute_Reference
6640 and then Get_Attribute_Id (Attribute_Name (Prefix (Expr)))
6641 = Attribute_Loop_Entry
6643 Expr := Prefix (Expr);
6646 -- For access discriminant, the level of the enclosing object
6648 when N_Selected_Component =>
6649 if Ekind (Entity (Selector_Name (Expr))) = E_Discriminant
6650 and then Ekind (Etype (Entity (Selector_Name (Expr)))) =
6651 E_Anonymous_Access_Type
6653 return Make_Level_Literal (Object_Access_Level (Expr));
6656 when N_Attribute_Reference =>
6657 case Get_Attribute_Id (Attribute_Name (Expr)) is
6659 -- Ignore 'Loop_Entry, 'Result, and 'Old as they can be used to
6660 -- identify access objects and do not have an effect on
6661 -- accessibility level.
6663 when Attribute_Loop_Entry | Attribute_Old | Attribute_Result =>
6666 -- For X'Access, the level of the prefix X
6668 when Attribute_Access =>
6669 return Make_Level_Literal
6670 (Object_Access_Level (Prefix (Expr)));
6672 -- Treat the unchecked attributes as library-level
6674 when Attribute_Unchecked_Access
6675 | Attribute_Unrestricted_Access
6677 return Make_Level_Literal (Scope_Depth (Standard_Standard));
6679 -- No other access-valued attributes
6682 raise Program_Error;
6687 -- This is not fully implemented since it depends on context (see
6688 -- 3.10.2(14/3-14.2/3). More work is needed in the following cases
6690 -- 1) For an anonymous allocator defining the value of an access
6691 -- parameter, the accessibility level is that of the innermost
6692 -- master of the call; however currently we pass the level of
6693 -- execution of the called subprogram, which is one greater
6694 -- than the current scope level (see Expand_Call_Helper).
6696 -- For example, a statement is a master and a declaration is
6697 -- not a master; so we should not pass in the same level for
6698 -- the following cases:
6700 -- function F (X : access Integer) return T is ... ;
6701 -- Decl : T := F (new Integer); -- level is off by one
6703 -- Decl := F (new Integer); -- we get this case right
6705 -- 2) For an anonymous allocator that defines the result of a
6706 -- function with an access result, the accessibility level is
6707 -- determined as though the allocator were in place of the call
6708 -- of the function. In the special case of a call that is the
6709 -- operand of a type conversion the level is that of the target
6710 -- access type of the conversion.
6712 -- 3) For an anonymous allocator defining an access discriminant
6713 -- the accessibility level is determined as follows:
6714 -- * for an allocator used to define the discriminant of an
6715 -- object, the level of the object
6716 -- * for an allocator used to define the constraint in a
6717 -- subtype_indication in any other context, the level of
6718 -- the master that elaborates the subtype_indication.
6720 case Nkind (Parent (N)) is
6721 when N_Object_Declaration =>
6723 -- For an anonymous allocator whose type is that of a
6724 -- stand-alone object of an anonymous access-to-object type,
6725 -- the accessibility level is that of the declaration of the
6726 -- stand-alone object.
6730 (Object_Access_Level
6731 (Defining_Identifier (Parent (N))));
6733 when N_Assignment_Statement =>
6736 (Object_Access_Level (Name (Parent (N))));
6740 S : constant String :=
6741 Node_Kind'Image (Nkind (Parent (N)));
6743 Error_Msg_Strlen := S'Length;
6744 Error_Msg_String (1 .. Error_Msg_Strlen) := S;
6746 ("unsupported context for anonymous allocator (~)",
6751 when N_Type_Conversion =>
6752 if not Is_Local_Anonymous_Access (Etype (Expr)) then
6754 -- Handle type conversions introduced for a rename of an
6755 -- Ada 2012 stand-alone object of an anonymous access type.
6757 return Dynamic_Accessibility_Level (Expression (Expr));
6764 return Make_Level_Literal (Type_Access_Level (Etype (Expr)));
6765 end Dynamic_Accessibility_Level;
6767 ------------------------
6768 -- Discriminated_Size --
6769 ------------------------
6771 function Discriminated_Size (Comp : Entity_Id) return Boolean is
6772 function Non_Static_Bound (Bound : Node_Id) return Boolean;
6773 -- Check whether the bound of an index is non-static and does denote
6774 -- a discriminant, in which case any object of the type (protected or
6775 -- otherwise) will have a non-static size.
6777 ----------------------
6778 -- Non_Static_Bound --
6779 ----------------------
6781 function Non_Static_Bound (Bound : Node_Id) return Boolean is
6783 if Is_OK_Static_Expression (Bound) then
6786 -- If the bound is given by a discriminant it is non-static
6787 -- (A static constraint replaces the reference with the value).
6788 -- In an protected object the discriminant has been replaced by
6789 -- the corresponding discriminal within the protected operation.
6791 elsif Is_Entity_Name (Bound)
6793 (Ekind (Entity (Bound)) = E_Discriminant
6794 or else Present (Discriminal_Link (Entity (Bound))))
6801 end Non_Static_Bound;
6805 Typ : constant Entity_Id := Etype (Comp);
6808 -- Start of processing for Discriminated_Size
6811 if not Is_Array_Type (Typ) then
6815 if Ekind (Typ) = E_Array_Subtype then
6816 Index := First_Index (Typ);
6817 while Present (Index) loop
6818 if Non_Static_Bound (Low_Bound (Index))
6819 or else Non_Static_Bound (High_Bound (Index))
6831 end Discriminated_Size;
6833 -----------------------------------
6834 -- Effective_Extra_Accessibility --
6835 -----------------------------------
6837 function Effective_Extra_Accessibility (Id : Entity_Id) return Entity_Id is
6839 if Present (Renamed_Object (Id))
6840 and then Is_Entity_Name (Renamed_Object (Id))
6842 return Effective_Extra_Accessibility (Entity (Renamed_Object (Id)));
6844 return Extra_Accessibility (Id);
6846 end Effective_Extra_Accessibility;
6848 -----------------------------
6849 -- Effective_Reads_Enabled --
6850 -----------------------------
6852 function Effective_Reads_Enabled (Id : Entity_Id) return Boolean is
6854 return Has_Enabled_Property (Id, Name_Effective_Reads);
6855 end Effective_Reads_Enabled;
6857 ------------------------------
6858 -- Effective_Writes_Enabled --
6859 ------------------------------
6861 function Effective_Writes_Enabled (Id : Entity_Id) return Boolean is
6863 return Has_Enabled_Property (Id, Name_Effective_Writes);
6864 end Effective_Writes_Enabled;
6866 ------------------------------
6867 -- Enclosing_Comp_Unit_Node --
6868 ------------------------------
6870 function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id is
6871 Current_Node : Node_Id;
6875 while Present (Current_Node)
6876 and then Nkind (Current_Node) /= N_Compilation_Unit
6878 Current_Node := Parent (Current_Node);
6881 if Nkind (Current_Node) /= N_Compilation_Unit then
6884 return Current_Node;
6886 end Enclosing_Comp_Unit_Node;
6888 --------------------------
6889 -- Enclosing_CPP_Parent --
6890 --------------------------
6892 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
6893 Parent_Typ : Entity_Id := Typ;
6896 while not Is_CPP_Class (Parent_Typ)
6897 and then Etype (Parent_Typ) /= Parent_Typ
6899 Parent_Typ := Etype (Parent_Typ);
6901 if Is_Private_Type (Parent_Typ) then
6902 Parent_Typ := Full_View (Base_Type (Parent_Typ));
6906 pragma Assert (Is_CPP_Class (Parent_Typ));
6908 end Enclosing_CPP_Parent;
6910 ---------------------------
6911 -- Enclosing_Declaration --
6912 ---------------------------
6914 function Enclosing_Declaration (N : Node_Id) return Node_Id is
6915 Decl : Node_Id := N;
6918 while Present (Decl)
6919 and then not (Nkind (Decl) in N_Declaration
6921 Nkind (Decl) in N_Later_Decl_Item
6923 Nkind (Decl) = N_Number_Declaration)
6925 Decl := Parent (Decl);
6929 end Enclosing_Declaration;
6931 ----------------------------
6932 -- Enclosing_Generic_Body --
6933 ----------------------------
6935 function Enclosing_Generic_Body (N : Node_Id) return Node_Id is
6937 Spec_Id : Entity_Id;
6941 while Present (Par) loop
6942 if Nkind_In (Par, N_Package_Body, N_Subprogram_Body) then
6943 Spec_Id := Corresponding_Spec (Par);
6945 if Present (Spec_Id)
6946 and then Nkind_In (Unit_Declaration_Node (Spec_Id),
6947 N_Generic_Package_Declaration,
6948 N_Generic_Subprogram_Declaration)
6954 Par := Parent (Par);
6958 end Enclosing_Generic_Body;
6960 ----------------------------
6961 -- Enclosing_Generic_Unit --
6962 ----------------------------
6964 function Enclosing_Generic_Unit (N : Node_Id) return Node_Id is
6966 Spec_Decl : Node_Id;
6967 Spec_Id : Entity_Id;
6971 while Present (Par) loop
6972 if Nkind_In (Par, N_Generic_Package_Declaration,
6973 N_Generic_Subprogram_Declaration)
6977 elsif Nkind_In (Par, N_Package_Body, N_Subprogram_Body) then
6978 Spec_Id := Corresponding_Spec (Par);
6980 if Present (Spec_Id) then
6981 Spec_Decl := Unit_Declaration_Node (Spec_Id);
6983 if Nkind_In (Spec_Decl, N_Generic_Package_Declaration,
6984 N_Generic_Subprogram_Declaration)
6991 Par := Parent (Par);
6995 end Enclosing_Generic_Unit;
6997 -------------------------------
6998 -- Enclosing_Lib_Unit_Entity --
6999 -------------------------------
7001 function Enclosing_Lib_Unit_Entity
7002 (E : Entity_Id := Current_Scope) return Entity_Id
7004 Unit_Entity : Entity_Id;
7007 -- Look for enclosing library unit entity by following scope links.
7008 -- Equivalent to, but faster than indexing through the scope stack.
7011 while (Present (Scope (Unit_Entity))
7012 and then Scope (Unit_Entity) /= Standard_Standard)
7013 and not Is_Child_Unit (Unit_Entity)
7015 Unit_Entity := Scope (Unit_Entity);
7019 end Enclosing_Lib_Unit_Entity;
7021 -----------------------------
7022 -- Enclosing_Lib_Unit_Node --
7023 -----------------------------
7025 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
7026 Encl_Unit : Node_Id;
7029 Encl_Unit := Enclosing_Comp_Unit_Node (N);
7030 while Present (Encl_Unit)
7031 and then Nkind (Unit (Encl_Unit)) = N_Subunit
7033 Encl_Unit := Library_Unit (Encl_Unit);
7036 pragma Assert (Nkind (Encl_Unit) = N_Compilation_Unit);
7038 end Enclosing_Lib_Unit_Node;
7040 -----------------------
7041 -- Enclosing_Package --
7042 -----------------------
7044 function Enclosing_Package (E : Entity_Id) return Entity_Id is
7045 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
7048 if Dynamic_Scope = Standard_Standard then
7049 return Standard_Standard;
7051 elsif Dynamic_Scope = Empty then
7054 elsif Ekind_In (Dynamic_Scope, E_Generic_Package,
7058 return Dynamic_Scope;
7061 return Enclosing_Package (Dynamic_Scope);
7063 end Enclosing_Package;
7065 -------------------------------------
7066 -- Enclosing_Package_Or_Subprogram --
7067 -------------------------------------
7069 function Enclosing_Package_Or_Subprogram (E : Entity_Id) return Entity_Id is
7074 while Present (S) loop
7075 if Is_Package_Or_Generic_Package (S)
7076 or else Is_Subprogram_Or_Generic_Subprogram (S)
7086 end Enclosing_Package_Or_Subprogram;
7088 --------------------------
7089 -- Enclosing_Subprogram --
7090 --------------------------
7092 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
7093 Dyn_Scop : constant Entity_Id := Enclosing_Dynamic_Scope (E);
7096 if Dyn_Scop = Standard_Standard then
7099 elsif Dyn_Scop = Empty then
7102 elsif Ekind (Dyn_Scop) = E_Subprogram_Body then
7103 return Corresponding_Spec (Parent (Parent (Dyn_Scop)));
7105 elsif Ekind_In (Dyn_Scop, E_Block, E_Loop, E_Return_Statement) then
7106 return Enclosing_Subprogram (Dyn_Scop);
7108 elsif Ekind_In (Dyn_Scop, E_Entry, E_Entry_Family) then
7110 -- For a task entry or entry family, return the enclosing subprogram
7111 -- of the task itself.
7113 if Ekind (Scope (Dyn_Scop)) = E_Task_Type then
7114 return Enclosing_Subprogram (Dyn_Scop);
7116 -- A protected entry or entry family is rewritten as a protected
7117 -- procedure which is the desired enclosing subprogram. This is
7118 -- relevant when unnesting a procedure local to an entry body.
7121 return Protected_Body_Subprogram (Dyn_Scop);
7124 elsif Ekind (Dyn_Scop) = E_Task_Type then
7125 return Get_Task_Body_Procedure (Dyn_Scop);
7127 -- The scope may appear as a private type or as a private extension
7128 -- whose completion is a task or protected type.
7130 elsif Ekind_In (Dyn_Scop, E_Limited_Private_Type,
7131 E_Record_Type_With_Private)
7132 and then Present (Full_View (Dyn_Scop))
7133 and then Ekind_In (Full_View (Dyn_Scop), E_Task_Type, E_Protected_Type)
7135 return Get_Task_Body_Procedure (Full_View (Dyn_Scop));
7137 -- No body is generated if the protected operation is eliminated
7139 elsif Convention (Dyn_Scop) = Convention_Protected
7140 and then not Is_Eliminated (Dyn_Scop)
7141 and then Present (Protected_Body_Subprogram (Dyn_Scop))
7143 return Protected_Body_Subprogram (Dyn_Scop);
7148 end Enclosing_Subprogram;
7150 --------------------------
7151 -- End_Keyword_Location --
7152 --------------------------
7154 function End_Keyword_Location (N : Node_Id) return Source_Ptr is
7155 function End_Label_Loc (Nod : Node_Id) return Source_Ptr;
7156 -- Return the source location of Nod's end label according to the
7157 -- following precedence rules:
7159 -- 1) If the end label exists, return its location
7160 -- 2) If Nod exists, return its location
7161 -- 3) Return the location of N
7167 function End_Label_Loc (Nod : Node_Id) return Source_Ptr is
7171 if Present (Nod) then
7172 Label := End_Label (Nod);
7174 if Present (Label) then
7175 return Sloc (Label);
7189 -- Start of processing for End_Keyword_Location
7192 if Nkind_In (N, N_Block_Statement,
7198 Owner := Handled_Statement_Sequence (N);
7200 elsif Nkind (N) = N_Package_Declaration then
7201 Owner := Specification (N);
7203 elsif Nkind (N) = N_Protected_Body then
7206 elsif Nkind_In (N, N_Protected_Type_Declaration,
7207 N_Single_Protected_Declaration)
7209 Owner := Protected_Definition (N);
7211 elsif Nkind_In (N, N_Single_Task_Declaration,
7212 N_Task_Type_Declaration)
7214 Owner := Task_Definition (N);
7216 -- This routine should not be called with other contexts
7219 pragma Assert (False);
7223 return End_Label_Loc (Owner);
7224 end End_Keyword_Location;
7226 ------------------------
7227 -- Ensure_Freeze_Node --
7228 ------------------------
7230 procedure Ensure_Freeze_Node (E : Entity_Id) is
7233 if No (Freeze_Node (E)) then
7234 FN := Make_Freeze_Entity (Sloc (E));
7235 Set_Has_Delayed_Freeze (E);
7236 Set_Freeze_Node (E, FN);
7237 Set_Access_Types_To_Process (FN, No_Elist);
7238 Set_TSS_Elist (FN, No_Elist);
7241 end Ensure_Freeze_Node;
7247 procedure Enter_Name (Def_Id : Entity_Id) is
7248 C : constant Entity_Id := Current_Entity (Def_Id);
7249 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
7250 S : constant Entity_Id := Current_Scope;
7253 Generate_Definition (Def_Id);
7255 -- Add new name to current scope declarations. Check for duplicate
7256 -- declaration, which may or may not be a genuine error.
7260 -- Case of previous entity entered because of a missing declaration
7261 -- or else a bad subtype indication. Best is to use the new entity,
7262 -- and make the previous one invisible.
7264 if Etype (E) = Any_Type then
7265 Set_Is_Immediately_Visible (E, False);
7267 -- Case of renaming declaration constructed for package instances.
7268 -- if there is an explicit declaration with the same identifier,
7269 -- the renaming is not immediately visible any longer, but remains
7270 -- visible through selected component notation.
7272 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
7273 and then not Comes_From_Source (E)
7275 Set_Is_Immediately_Visible (E, False);
7277 -- The new entity may be the package renaming, which has the same
7278 -- same name as a generic formal which has been seen already.
7280 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
7281 and then not Comes_From_Source (Def_Id)
7283 Set_Is_Immediately_Visible (E, False);
7285 -- For a fat pointer corresponding to a remote access to subprogram,
7286 -- we use the same identifier as the RAS type, so that the proper
7287 -- name appears in the stub. This type is only retrieved through
7288 -- the RAS type and never by visibility, and is not added to the
7289 -- visibility list (see below).
7291 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
7292 and then Ekind (Def_Id) = E_Record_Type
7293 and then Present (Corresponding_Remote_Type (Def_Id))
7297 -- Case of an implicit operation or derived literal. The new entity
7298 -- hides the implicit one, which is removed from all visibility,
7299 -- i.e. the entity list of its scope, and homonym chain of its name.
7301 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
7302 or else Is_Internal (E)
7305 Decl : constant Node_Id := Parent (E);
7307 Prev_Vis : Entity_Id;
7310 -- If E is an implicit declaration, it cannot be the first
7311 -- entity in the scope.
7313 Prev := First_Entity (Current_Scope);
7314 while Present (Prev) and then Next_Entity (Prev) /= E loop
7320 -- If E is not on the entity chain of the current scope,
7321 -- it is an implicit declaration in the generic formal
7322 -- part of a generic subprogram. When analyzing the body,
7323 -- the generic formals are visible but not on the entity
7324 -- chain of the subprogram. The new entity will become
7325 -- the visible one in the body.
7328 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
7332 Link_Entities (Prev, Next_Entity (E));
7334 if No (Next_Entity (Prev)) then
7335 Set_Last_Entity (Current_Scope, Prev);
7338 if E = Current_Entity (E) then
7342 Prev_Vis := Current_Entity (E);
7343 while Homonym (Prev_Vis) /= E loop
7344 Prev_Vis := Homonym (Prev_Vis);
7348 if Present (Prev_Vis) then
7350 -- Skip E in the visibility chain
7352 Set_Homonym (Prev_Vis, Homonym (E));
7355 Set_Name_Entity_Id (Chars (E), Homonym (E));
7360 -- This section of code could use a comment ???
7362 elsif Present (Etype (E))
7363 and then Is_Concurrent_Type (Etype (E))
7368 -- If the homograph is a protected component renaming, it should not
7369 -- be hiding the current entity. Such renamings are treated as weak
7372 elsif Is_Prival (E) then
7373 Set_Is_Immediately_Visible (E, False);
7375 -- In this case the current entity is a protected component renaming.
7376 -- Perform minimal decoration by setting the scope and return since
7377 -- the prival should not be hiding other visible entities.
7379 elsif Is_Prival (Def_Id) then
7380 Set_Scope (Def_Id, Current_Scope);
7383 -- Analogous to privals, the discriminal generated for an entry index
7384 -- parameter acts as a weak declaration. Perform minimal decoration
7385 -- to avoid bogus errors.
7387 elsif Is_Discriminal (Def_Id)
7388 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
7390 Set_Scope (Def_Id, Current_Scope);
7393 -- In the body or private part of an instance, a type extension may
7394 -- introduce a component with the same name as that of an actual. The
7395 -- legality rule is not enforced, but the semantics of the full type
7396 -- with two components of same name are not clear at this point???
7398 elsif In_Instance_Not_Visible then
7401 -- When compiling a package body, some child units may have become
7402 -- visible. They cannot conflict with local entities that hide them.
7404 elsif Is_Child_Unit (E)
7405 and then In_Open_Scopes (Scope (E))
7406 and then not Is_Immediately_Visible (E)
7410 -- Conversely, with front-end inlining we may compile the parent body
7411 -- first, and a child unit subsequently. The context is now the
7412 -- parent spec, and body entities are not visible.
7414 elsif Is_Child_Unit (Def_Id)
7415 and then Is_Package_Body_Entity (E)
7416 and then not In_Package_Body (Current_Scope)
7420 -- Case of genuine duplicate declaration
7423 Error_Msg_Sloc := Sloc (E);
7425 -- If the previous declaration is an incomplete type declaration
7426 -- this may be an attempt to complete it with a private type. The
7427 -- following avoids confusing cascaded errors.
7429 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
7430 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
7433 ("incomplete type cannot be completed with a private " &
7434 "declaration", Parent (Def_Id));
7435 Set_Is_Immediately_Visible (E, False);
7436 Set_Full_View (E, Def_Id);
7438 -- An inherited component of a record conflicts with a new
7439 -- discriminant. The discriminant is inserted first in the scope,
7440 -- but the error should be posted on it, not on the component.
7442 elsif Ekind (E) = E_Discriminant
7443 and then Present (Scope (Def_Id))
7444 and then Scope (Def_Id) /= Current_Scope
7446 Error_Msg_Sloc := Sloc (Def_Id);
7447 Error_Msg_N ("& conflicts with declaration#", E);
7450 -- If the name of the unit appears in its own context clause, a
7451 -- dummy package with the name has already been created, and the
7452 -- error emitted. Try to continue quietly.
7454 elsif Error_Posted (E)
7455 and then Sloc (E) = No_Location
7456 and then Nkind (Parent (E)) = N_Package_Specification
7457 and then Current_Scope = Standard_Standard
7459 Set_Scope (Def_Id, Current_Scope);
7463 Error_Msg_N ("& conflicts with declaration#", Def_Id);
7465 -- Avoid cascaded messages with duplicate components in
7468 if Ekind_In (E, E_Component, E_Discriminant) then
7473 if Nkind (Parent (Parent (Def_Id))) =
7474 N_Generic_Subprogram_Declaration
7476 Defining_Entity (Specification (Parent (Parent (Def_Id))))
7478 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
7481 -- If entity is in standard, then we are in trouble, because it
7482 -- means that we have a library package with a duplicated name.
7483 -- That's hard to recover from, so abort.
7485 if S = Standard_Standard then
7486 raise Unrecoverable_Error;
7488 -- Otherwise we continue with the declaration. Having two
7489 -- identical declarations should not cause us too much trouble.
7497 -- If we fall through, declaration is OK, at least OK enough to continue
7499 -- If Def_Id is a discriminant or a record component we are in the midst
7500 -- of inheriting components in a derived record definition. Preserve
7501 -- their Ekind and Etype.
7503 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
7506 -- If a type is already set, leave it alone (happens when a type
7507 -- declaration is reanalyzed following a call to the optimizer).
7509 elsif Present (Etype (Def_Id)) then
7512 -- Otherwise, the kind E_Void insures that premature uses of the entity
7513 -- will be detected. Any_Type insures that no cascaded errors will occur
7516 Set_Ekind (Def_Id, E_Void);
7517 Set_Etype (Def_Id, Any_Type);
7520 -- Inherited discriminants and components in derived record types are
7521 -- immediately visible. Itypes are not.
7523 -- Unless the Itype is for a record type with a corresponding remote
7524 -- type (what is that about, it was not commented ???)
7526 if Ekind_In (Def_Id, E_Discriminant, E_Component)
7528 ((not Is_Record_Type (Def_Id)
7529 or else No (Corresponding_Remote_Type (Def_Id)))
7530 and then not Is_Itype (Def_Id))
7532 Set_Is_Immediately_Visible (Def_Id);
7533 Set_Current_Entity (Def_Id);
7536 Set_Homonym (Def_Id, C);
7537 Append_Entity (Def_Id, S);
7538 Set_Public_Status (Def_Id);
7540 -- Declaring a homonym is not allowed in SPARK ...
7542 if Present (C) and then Restriction_Check_Required (SPARK_05) then
7544 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
7545 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
7546 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
7549 -- ... unless the new declaration is in a subprogram, and the
7550 -- visible declaration is a variable declaration or a parameter
7551 -- specification outside that subprogram.
7553 if Present (Enclosing_Subp)
7554 and then Nkind_In (Parent (C), N_Object_Declaration,
7555 N_Parameter_Specification)
7556 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
7560 -- ... or the new declaration is in a package, and the visible
7561 -- declaration occurs outside that package.
7563 elsif Present (Enclosing_Pack)
7564 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
7568 -- ... or the new declaration is a component declaration in a
7569 -- record type definition.
7571 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
7574 -- Don't issue error for non-source entities
7576 elsif Comes_From_Source (Def_Id)
7577 and then Comes_From_Source (C)
7579 Error_Msg_Sloc := Sloc (C);
7580 Check_SPARK_05_Restriction
7581 ("redeclaration of identifier &#", Def_Id);
7586 -- Warn if new entity hides an old one
7588 if Warn_On_Hiding and then Present (C)
7590 -- Don't warn for record components since they always have a well
7591 -- defined scope which does not confuse other uses. Note that in
7592 -- some cases, Ekind has not been set yet.
7594 and then Ekind (C) /= E_Component
7595 and then Ekind (C) /= E_Discriminant
7596 and then Nkind (Parent (C)) /= N_Component_Declaration
7597 and then Ekind (Def_Id) /= E_Component
7598 and then Ekind (Def_Id) /= E_Discriminant
7599 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
7601 -- Don't warn for one character variables. It is too common to use
7602 -- such variables as locals and will just cause too many false hits.
7604 and then Length_Of_Name (Chars (C)) /= 1
7606 -- Don't warn for non-source entities
7608 and then Comes_From_Source (C)
7609 and then Comes_From_Source (Def_Id)
7611 -- Don't warn unless entity in question is in extended main source
7613 and then In_Extended_Main_Source_Unit (Def_Id)
7615 -- Finally, the hidden entity must be either immediately visible or
7616 -- use visible (i.e. from a used package).
7619 (Is_Immediately_Visible (C)
7621 Is_Potentially_Use_Visible (C))
7623 Error_Msg_Sloc := Sloc (C);
7624 Error_Msg_N ("declaration hides &#?h?", Def_Id);
7632 function Entity_Of (N : Node_Id) return Entity_Id is
7637 -- Assume that the arbitrary node does not have an entity
7641 if Is_Entity_Name (N) then
7644 -- Follow a possible chain of renamings to reach the earliest renamed
7648 and then Is_Object (Id)
7649 and then Present (Renamed_Object (Id))
7651 Ren := Renamed_Object (Id);
7653 -- The reference renames an abstract state or a whole object
7656 -- Ren : ... renames Obj;
7658 if Is_Entity_Name (Ren) then
7660 -- Do not follow a renaming that goes through a generic formal,
7661 -- because these entities are hidden and must not be referenced
7662 -- from outside the generic.
7664 if Is_Hidden (Entity (Ren)) then
7671 -- The reference renames a function result. Check the original
7672 -- node in case expansion relocates the function call.
7674 -- Ren : ... renames Func_Call;
7676 elsif Nkind (Original_Node (Ren)) = N_Function_Call then
7679 -- Otherwise the reference renames something which does not yield
7680 -- an abstract state or a whole object. Treat the reference as not
7681 -- having a proper entity for SPARK legality purposes.
7693 --------------------------
7694 -- Examine_Array_Bounds --
7695 --------------------------
7697 procedure Examine_Array_Bounds
7699 All_Static : out Boolean;
7700 Has_Empty : out Boolean)
7702 function Is_OK_Static_Bound (Bound : Node_Id) return Boolean;
7703 -- Determine whether bound Bound is a suitable static bound
7705 ------------------------
7706 -- Is_OK_Static_Bound --
7707 ------------------------
7709 function Is_OK_Static_Bound (Bound : Node_Id) return Boolean is
7712 not Error_Posted (Bound)
7713 and then Is_OK_Static_Expression (Bound);
7714 end Is_OK_Static_Bound;
7722 -- Start of processing for Examine_Array_Bounds
7725 -- An unconstrained array type does not have static bounds, and it is
7726 -- not known whether they are empty or not.
7728 if not Is_Constrained (Typ) then
7729 All_Static := False;
7732 -- A string literal has static bounds, and is not empty as long as it
7733 -- contains at least one character.
7735 elsif Ekind (Typ) = E_String_Literal_Subtype then
7737 Has_Empty := String_Literal_Length (Typ) > 0;
7740 -- Assume that all bounds are static and not empty
7745 -- Examine each index
7747 Index := First_Index (Typ);
7748 while Present (Index) loop
7749 if Is_Discrete_Type (Etype (Index)) then
7750 Get_Index_Bounds (Index, Lo_Bound, Hi_Bound);
7752 if Is_OK_Static_Bound (Lo_Bound)
7754 Is_OK_Static_Bound (Hi_Bound)
7756 -- The static bounds produce an empty range
7758 if Is_Null_Range (Lo_Bound, Hi_Bound) then
7762 -- Otherwise at least one of the bounds is not static
7765 All_Static := False;
7768 -- Otherwise the index is non-discrete, therefore not static
7771 All_Static := False;
7776 end Examine_Array_Bounds;
7782 function Exceptions_OK return Boolean is
7785 not (Restriction_Active (No_Exception_Handlers) or else
7786 Restriction_Active (No_Exception_Propagation) or else
7787 Restriction_Active (No_Exceptions));
7790 --------------------------
7791 -- Explain_Limited_Type --
7792 --------------------------
7794 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
7798 -- For array, component type must be limited
7800 if Is_Array_Type (T) then
7801 Error_Msg_Node_2 := T;
7803 ("\component type& of type& is limited", N, Component_Type (T));
7804 Explain_Limited_Type (Component_Type (T), N);
7806 elsif Is_Record_Type (T) then
7808 -- No need for extra messages if explicit limited record
7810 if Is_Limited_Record (Base_Type (T)) then
7814 -- Otherwise find a limited component. Check only components that
7815 -- come from source, or inherited components that appear in the
7816 -- source of the ancestor.
7818 C := First_Component (T);
7819 while Present (C) loop
7820 if Is_Limited_Type (Etype (C))
7822 (Comes_From_Source (C)
7824 (Present (Original_Record_Component (C))
7826 Comes_From_Source (Original_Record_Component (C))))
7828 Error_Msg_Node_2 := T;
7829 Error_Msg_NE ("\component& of type& has limited type", N, C);
7830 Explain_Limited_Type (Etype (C), N);
7837 -- The type may be declared explicitly limited, even if no component
7838 -- of it is limited, in which case we fall out of the loop.
7841 end Explain_Limited_Type;
7843 ---------------------------------------
7844 -- Expression_Of_Expression_Function --
7845 ---------------------------------------
7847 function Expression_Of_Expression_Function
7848 (Subp : Entity_Id) return Node_Id
7850 Expr_Func : Node_Id;
7853 pragma Assert (Is_Expression_Function_Or_Completion (Subp));
7855 if Nkind (Original_Node (Subprogram_Spec (Subp))) =
7856 N_Expression_Function
7858 Expr_Func := Original_Node (Subprogram_Spec (Subp));
7860 elsif Nkind (Original_Node (Subprogram_Body (Subp))) =
7861 N_Expression_Function
7863 Expr_Func := Original_Node (Subprogram_Body (Subp));
7866 pragma Assert (False);
7870 return Original_Node (Expression (Expr_Func));
7871 end Expression_Of_Expression_Function;
7873 -------------------------------
7874 -- Extensions_Visible_Status --
7875 -------------------------------
7877 function Extensions_Visible_Status
7878 (Id : Entity_Id) return Extensions_Visible_Mode
7887 -- When a formal parameter is subject to Extensions_Visible, the pragma
7888 -- is stored in the contract of related subprogram.
7890 if Is_Formal (Id) then
7893 elsif Is_Subprogram_Or_Generic_Subprogram (Id) then
7896 -- No other construct carries this pragma
7899 return Extensions_Visible_None;
7902 Prag := Get_Pragma (Subp, Pragma_Extensions_Visible);
7904 -- In certain cases analysis may request the Extensions_Visible status
7905 -- of an expression function before the pragma has been analyzed yet.
7906 -- Inspect the declarative items after the expression function looking
7907 -- for the pragma (if any).
7909 if No (Prag) and then Is_Expression_Function (Subp) then
7910 Decl := Next (Unit_Declaration_Node (Subp));
7911 while Present (Decl) loop
7912 if Nkind (Decl) = N_Pragma
7913 and then Pragma_Name (Decl) = Name_Extensions_Visible
7918 -- A source construct ends the region where Extensions_Visible may
7919 -- appear, stop the traversal. An expanded expression function is
7920 -- no longer a source construct, but it must still be recognized.
7922 elsif Comes_From_Source (Decl)
7924 (Nkind_In (Decl, N_Subprogram_Body,
7925 N_Subprogram_Declaration)
7926 and then Is_Expression_Function (Defining_Entity (Decl)))
7935 -- Extract the value from the Boolean expression (if any)
7937 if Present (Prag) then
7938 Arg := First (Pragma_Argument_Associations (Prag));
7940 if Present (Arg) then
7941 Expr := Get_Pragma_Arg (Arg);
7943 -- When the associated subprogram is an expression function, the
7944 -- argument of the pragma may not have been analyzed.
7946 if not Analyzed (Expr) then
7947 Preanalyze_And_Resolve (Expr, Standard_Boolean);
7950 -- Guard against cascading errors when the argument of pragma
7951 -- Extensions_Visible is not a valid static Boolean expression.
7953 if Error_Posted (Expr) then
7954 return Extensions_Visible_None;
7956 elsif Is_True (Expr_Value (Expr)) then
7957 return Extensions_Visible_True;
7960 return Extensions_Visible_False;
7963 -- Otherwise the aspect or pragma defaults to True
7966 return Extensions_Visible_True;
7969 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
7970 -- directly specified. In SPARK code, its value defaults to "False".
7972 elsif SPARK_Mode = On then
7973 return Extensions_Visible_False;
7975 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
7979 return Extensions_Visible_True;
7981 end Extensions_Visible_Status;
7987 procedure Find_Actual
7989 Formal : out Entity_Id;
7992 Context : constant Node_Id := Parent (N);
7997 if Nkind_In (Context, N_Indexed_Component, N_Selected_Component)
7998 and then N = Prefix (Context)
8000 Find_Actual (Context, Formal, Call);
8003 elsif Nkind (Context) = N_Parameter_Association
8004 and then N = Explicit_Actual_Parameter (Context)
8006 Call := Parent (Context);
8008 elsif Nkind_In (Context, N_Entry_Call_Statement,
8010 N_Procedure_Call_Statement)
8020 -- If we have a call to a subprogram look for the parameter. Note that
8021 -- we exclude overloaded calls, since we don't know enough to be sure
8022 -- of giving the right answer in this case.
8024 if Nkind_In (Call, N_Entry_Call_Statement,
8026 N_Procedure_Call_Statement)
8028 Call_Nam := Name (Call);
8030 -- A call to a protected or task entry appears as a selected
8031 -- component rather than an expanded name.
8033 if Nkind (Call_Nam) = N_Selected_Component then
8034 Call_Nam := Selector_Name (Call_Nam);
8037 if Is_Entity_Name (Call_Nam)
8038 and then Present (Entity (Call_Nam))
8039 and then Is_Overloadable (Entity (Call_Nam))
8040 and then not Is_Overloaded (Call_Nam)
8042 -- If node is name in call it is not an actual
8044 if N = Call_Nam then
8050 -- Fall here if we are definitely a parameter
8052 Actual := First_Actual (Call);
8053 Formal := First_Formal (Entity (Call_Nam));
8054 while Present (Formal) and then Present (Actual) loop
8058 -- An actual that is the prefix in a prefixed call may have
8059 -- been rewritten in the call, after the deferred reference
8060 -- was collected. Check if sloc and kinds and names match.
8062 elsif Sloc (Actual) = Sloc (N)
8063 and then Nkind (Actual) = N_Identifier
8064 and then Nkind (Actual) = Nkind (N)
8065 and then Chars (Actual) = Chars (N)
8070 Next_Actual (Actual);
8071 Next_Formal (Formal);
8077 -- Fall through here if we did not find matching actual
8083 ---------------------------
8084 -- Find_Body_Discriminal --
8085 ---------------------------
8087 function Find_Body_Discriminal
8088 (Spec_Discriminant : Entity_Id) return Entity_Id
8094 -- If expansion is suppressed, then the scope can be the concurrent type
8095 -- itself rather than a corresponding concurrent record type.
8097 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
8098 Tsk := Scope (Spec_Discriminant);
8101 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
8103 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
8106 -- Find discriminant of original concurrent type, and use its current
8107 -- discriminal, which is the renaming within the task/protected body.
8109 Disc := First_Discriminant (Tsk);
8110 while Present (Disc) loop
8111 if Chars (Disc) = Chars (Spec_Discriminant) then
8112 return Discriminal (Disc);
8115 Next_Discriminant (Disc);
8118 -- That loop should always succeed in finding a matching entry and
8119 -- returning. Fatal error if not.
8121 raise Program_Error;
8122 end Find_Body_Discriminal;
8124 -------------------------------------
8125 -- Find_Corresponding_Discriminant --
8126 -------------------------------------
8128 function Find_Corresponding_Discriminant
8130 Typ : Entity_Id) return Entity_Id
8132 Par_Disc : Entity_Id;
8133 Old_Disc : Entity_Id;
8134 New_Disc : Entity_Id;
8137 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
8139 -- The original type may currently be private, and the discriminant
8140 -- only appear on its full view.
8142 if Is_Private_Type (Scope (Par_Disc))
8143 and then not Has_Discriminants (Scope (Par_Disc))
8144 and then Present (Full_View (Scope (Par_Disc)))
8146 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
8148 Old_Disc := First_Discriminant (Scope (Par_Disc));
8151 if Is_Class_Wide_Type (Typ) then
8152 New_Disc := First_Discriminant (Root_Type (Typ));
8154 New_Disc := First_Discriminant (Typ);
8157 while Present (Old_Disc) and then Present (New_Disc) loop
8158 if Old_Disc = Par_Disc then
8162 Next_Discriminant (Old_Disc);
8163 Next_Discriminant (New_Disc);
8166 -- Should always find it
8168 raise Program_Error;
8169 end Find_Corresponding_Discriminant;
8175 function Find_DIC_Type (Typ : Entity_Id) return Entity_Id is
8176 Curr_Typ : Entity_Id;
8177 -- The current type being examined in the parent hierarchy traversal
8179 DIC_Typ : Entity_Id;
8180 -- The type which carries the DIC pragma. This variable denotes the
8181 -- partial view when private types are involved.
8183 Par_Typ : Entity_Id;
8184 -- The parent type of the current type. This variable denotes the full
8185 -- view when private types are involved.
8188 -- The input type defines its own DIC pragma, therefore it is the owner
8190 if Has_Own_DIC (Typ) then
8193 -- Otherwise the DIC pragma is inherited from a parent type
8196 pragma Assert (Has_Inherited_DIC (Typ));
8198 -- Climb the parent chain
8202 -- Inspect the parent type. Do not consider subtypes as they
8203 -- inherit the DIC attributes from their base types.
8205 DIC_Typ := Base_Type (Etype (Curr_Typ));
8207 -- Look at the full view of a private type because the type may
8208 -- have a hidden parent introduced in the full view.
8212 if Is_Private_Type (Par_Typ)
8213 and then Present (Full_View (Par_Typ))
8215 Par_Typ := Full_View (Par_Typ);
8218 -- Stop the climb once the nearest parent type which defines a DIC
8219 -- pragma of its own is encountered or when the root of the parent
8220 -- chain is reached.
8222 exit when Has_Own_DIC (DIC_Typ) or else Curr_Typ = Par_Typ;
8224 Curr_Typ := Par_Typ;
8231 ----------------------------------
8232 -- Find_Enclosing_Iterator_Loop --
8233 ----------------------------------
8235 function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id is
8240 -- Traverse the scope chain looking for an iterator loop. Such loops are
8241 -- usually transformed into blocks, hence the use of Original_Node.
8244 while Present (S) and then S /= Standard_Standard loop
8245 if Ekind (S) = E_Loop
8246 and then Nkind (Parent (S)) = N_Implicit_Label_Declaration
8248 Constr := Original_Node (Label_Construct (Parent (S)));
8250 if Nkind (Constr) = N_Loop_Statement
8251 and then Present (Iteration_Scheme (Constr))
8252 and then Nkind (Iterator_Specification
8253 (Iteration_Scheme (Constr))) =
8254 N_Iterator_Specification
8264 end Find_Enclosing_Iterator_Loop;
8266 --------------------------
8267 -- Find_Enclosing_Scope --
8268 --------------------------
8270 function Find_Enclosing_Scope (N : Node_Id) return Entity_Id is
8274 -- Examine the parent chain looking for a construct which defines a
8278 while Present (Par) loop
8281 -- The construct denotes a declaration, the proper scope is its
8284 when N_Entry_Declaration
8285 | N_Expression_Function
8286 | N_Full_Type_Declaration
8287 | N_Generic_Package_Declaration
8288 | N_Generic_Subprogram_Declaration
8289 | N_Package_Declaration
8290 | N_Private_Extension_Declaration
8291 | N_Protected_Type_Declaration
8292 | N_Single_Protected_Declaration
8293 | N_Single_Task_Declaration
8294 | N_Subprogram_Declaration
8295 | N_Task_Type_Declaration
8297 return Defining_Entity (Par);
8299 -- The construct denotes a body, the proper scope is the entity of
8300 -- the corresponding spec or that of the body if the body does not
8301 -- complete a previous declaration.
8309 return Unique_Defining_Entity (Par);
8313 -- Blocks carry either a source or an internally-generated scope,
8314 -- unless the block is a byproduct of exception handling.
8316 when N_Block_Statement =>
8317 if not Exception_Junk (Par) then
8318 return Entity (Identifier (Par));
8321 -- Loops carry an internally-generated scope
8323 when N_Loop_Statement =>
8324 return Entity (Identifier (Par));
8326 -- Extended return statements carry an internally-generated scope
8328 when N_Extended_Return_Statement =>
8329 return Return_Statement_Entity (Par);
8331 -- A traversal from a subunit continues via the corresponding stub
8334 Par := Corresponding_Stub (Par);
8340 Par := Parent (Par);
8343 return Standard_Standard;
8344 end Find_Enclosing_Scope;
8346 ------------------------------------
8347 -- Find_Loop_In_Conditional_Block --
8348 ------------------------------------
8350 function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is
8356 if Nkind (Stmt) = N_If_Statement then
8357 Stmt := First (Then_Statements (Stmt));
8360 pragma Assert (Nkind (Stmt) = N_Block_Statement);
8362 -- Inspect the statements of the conditional block. In general the loop
8363 -- should be the first statement in the statement sequence of the block,
8364 -- but the finalization machinery may have introduced extra object
8367 Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
8368 while Present (Stmt) loop
8369 if Nkind (Stmt) = N_Loop_Statement then
8376 -- The expansion of attribute 'Loop_Entry produced a malformed block
8378 raise Program_Error;
8379 end Find_Loop_In_Conditional_Block;
8381 --------------------------
8382 -- Find_Overlaid_Entity --
8383 --------------------------
8385 procedure Find_Overlaid_Entity
8387 Ent : out Entity_Id;
8393 -- We are looking for one of the two following forms:
8395 -- for X'Address use Y'Address
8399 -- Const : constant Address := expr;
8401 -- for X'Address use Const;
8403 -- In the second case, the expr is either Y'Address, or recursively a
8404 -- constant that eventually references Y'Address.
8409 if Nkind (N) = N_Attribute_Definition_Clause
8410 and then Chars (N) = Name_Address
8412 Expr := Expression (N);
8414 -- This loop checks the form of the expression for Y'Address,
8415 -- using recursion to deal with intermediate constants.
8418 -- Check for Y'Address
8420 if Nkind (Expr) = N_Attribute_Reference
8421 and then Attribute_Name (Expr) = Name_Address
8423 Expr := Prefix (Expr);
8426 -- Check for Const where Const is a constant entity
8428 elsif Is_Entity_Name (Expr)
8429 and then Ekind (Entity (Expr)) = E_Constant
8431 Expr := Constant_Value (Entity (Expr));
8433 -- Anything else does not need checking
8440 -- This loop checks the form of the prefix for an entity, using
8441 -- recursion to deal with intermediate components.
8444 -- Check for Y where Y is an entity
8446 if Is_Entity_Name (Expr) then
8447 Ent := Entity (Expr);
8450 -- Check for components
8453 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component)
8455 Expr := Prefix (Expr);
8458 -- Anything else does not need checking
8465 end Find_Overlaid_Entity;
8467 -------------------------
8468 -- Find_Parameter_Type --
8469 -------------------------
8471 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
8473 if Nkind (Param) /= N_Parameter_Specification then
8476 -- For an access parameter, obtain the type from the formal entity
8477 -- itself, because access to subprogram nodes do not carry a type.
8478 -- Shouldn't we always use the formal entity ???
8480 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
8481 return Etype (Defining_Identifier (Param));
8484 return Etype (Parameter_Type (Param));
8486 end Find_Parameter_Type;
8488 -----------------------------------
8489 -- Find_Placement_In_State_Space --
8490 -----------------------------------
8492 procedure Find_Placement_In_State_Space
8493 (Item_Id : Entity_Id;
8494 Placement : out State_Space_Kind;
8495 Pack_Id : out Entity_Id)
8497 Context : Entity_Id;
8500 -- Assume that the item does not appear in the state space of a package
8502 Placement := Not_In_Package;
8505 -- Climb the scope stack and examine the enclosing context
8507 Context := Scope (Item_Id);
8508 while Present (Context) and then Context /= Standard_Standard loop
8509 if Is_Package_Or_Generic_Package (Context) then
8512 -- A package body is a cut off point for the traversal as the item
8513 -- cannot be visible to the outside from this point on. Note that
8514 -- this test must be done first as a body is also classified as a
8517 if In_Package_Body (Context) then
8518 Placement := Body_State_Space;
8521 -- The private part of a package is a cut off point for the
8522 -- traversal as the item cannot be visible to the outside from
8525 elsif In_Private_Part (Context) then
8526 Placement := Private_State_Space;
8529 -- When the item appears in the visible state space of a package,
8530 -- continue to climb the scope stack as this may not be the final
8534 Placement := Visible_State_Space;
8536 -- The visible state space of a child unit acts as the proper
8537 -- placement of an item.
8539 if Is_Child_Unit (Context) then
8544 -- The item or its enclosing package appear in a construct that has
8548 Placement := Not_In_Package;
8552 Context := Scope (Context);
8554 end Find_Placement_In_State_Space;
8556 -----------------------
8557 -- Find_Primitive_Eq --
8558 -----------------------
8560 function Find_Primitive_Eq (Typ : Entity_Id) return Entity_Id is
8561 function Find_Eq_Prim (Prims_List : Elist_Id) return Entity_Id;
8562 -- Search for the equality primitive; return Empty if the primitive is
8569 function Find_Eq_Prim (Prims_List : Elist_Id) return Entity_Id is
8571 Prim_Elmt : Elmt_Id;
8574 Prim_Elmt := First_Elmt (Prims_List);
8575 while Present (Prim_Elmt) loop
8576 Prim := Node (Prim_Elmt);
8578 -- Locate primitive equality with the right signature
8580 if Chars (Prim) = Name_Op_Eq
8581 and then Etype (First_Formal (Prim)) =
8582 Etype (Next_Formal (First_Formal (Prim)))
8583 and then Base_Type (Etype (Prim)) = Standard_Boolean
8588 Next_Elmt (Prim_Elmt);
8596 Eq_Prim : Entity_Id;
8597 Full_Type : Entity_Id;
8599 -- Start of processing for Find_Primitive_Eq
8602 if Is_Private_Type (Typ) then
8603 Full_Type := Underlying_Type (Typ);
8608 if No (Full_Type) then
8612 Full_Type := Base_Type (Full_Type);
8614 -- When the base type itself is private, use the full view
8616 if Is_Private_Type (Full_Type) then
8617 Full_Type := Underlying_Type (Full_Type);
8620 if Is_Class_Wide_Type (Full_Type) then
8621 Full_Type := Root_Type (Full_Type);
8624 if not Is_Tagged_Type (Full_Type) then
8625 Eq_Prim := Find_Eq_Prim (Collect_Primitive_Operations (Typ));
8627 -- If this is an untagged private type completed with a derivation of
8628 -- an untagged private type whose full view is a tagged type, we use
8629 -- the primitive operations of the private parent type (since it does
8630 -- not have a full view, and also because its equality primitive may
8631 -- have been overridden in its untagged full view). If no equality was
8632 -- defined for it then take its dispatching equality primitive.
8634 elsif Inherits_From_Tagged_Full_View (Typ) then
8635 Eq_Prim := Find_Eq_Prim (Collect_Primitive_Operations (Typ));
8637 if No (Eq_Prim) then
8638 Eq_Prim := Find_Eq_Prim (Primitive_Operations (Full_Type));
8642 Eq_Prim := Find_Eq_Prim (Primitive_Operations (Full_Type));
8646 end Find_Primitive_Eq;
8648 ------------------------
8649 -- Find_Specific_Type --
8650 ------------------------
8652 function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
8653 Typ : Entity_Id := Root_Type (CW);
8656 if Ekind (Typ) = E_Incomplete_Type then
8657 if From_Limited_With (Typ) then
8658 Typ := Non_Limited_View (Typ);
8660 Typ := Full_View (Typ);
8664 if Is_Private_Type (Typ)
8665 and then not Is_Tagged_Type (Typ)
8666 and then Present (Full_View (Typ))
8668 return Full_View (Typ);
8672 end Find_Specific_Type;
8674 -----------------------------
8675 -- Find_Static_Alternative --
8676 -----------------------------
8678 function Find_Static_Alternative (N : Node_Id) return Node_Id is
8679 Expr : constant Node_Id := Expression (N);
8680 Val : constant Uint := Expr_Value (Expr);
8685 Alt := First (Alternatives (N));
8688 if Nkind (Alt) /= N_Pragma then
8689 Choice := First (Discrete_Choices (Alt));
8690 while Present (Choice) loop
8692 -- Others choice, always matches
8694 if Nkind (Choice) = N_Others_Choice then
8697 -- Range, check if value is in the range
8699 elsif Nkind (Choice) = N_Range then
8701 Val >= Expr_Value (Low_Bound (Choice))
8703 Val <= Expr_Value (High_Bound (Choice));
8705 -- Choice is a subtype name. Note that we know it must
8706 -- be a static subtype, since otherwise it would have
8707 -- been diagnosed as illegal.
8709 elsif Is_Entity_Name (Choice)
8710 and then Is_Type (Entity (Choice))
8712 exit Search when Is_In_Range (Expr, Etype (Choice),
8713 Assume_Valid => False);
8715 -- Choice is a subtype indication
8717 elsif Nkind (Choice) = N_Subtype_Indication then
8719 C : constant Node_Id := Constraint (Choice);
8720 R : constant Node_Id := Range_Expression (C);
8724 Val >= Expr_Value (Low_Bound (R))
8726 Val <= Expr_Value (High_Bound (R));
8729 -- Choice is a simple expression
8732 exit Search when Val = Expr_Value (Choice);
8740 pragma Assert (Present (Alt));
8743 -- The above loop *must* terminate by finding a match, since we know the
8744 -- case statement is valid, and the value of the expression is known at
8745 -- compile time. When we fall out of the loop, Alt points to the
8746 -- alternative that we know will be selected at run time.
8749 end Find_Static_Alternative;
8755 function First_Actual (Node : Node_Id) return Node_Id is
8759 if No (Parameter_Associations (Node)) then
8763 N := First (Parameter_Associations (Node));
8765 if Nkind (N) = N_Parameter_Association then
8766 return First_Named_Actual (Node);
8776 function First_Global
8778 Global_Mode : Name_Id;
8779 Refined : Boolean := False) return Node_Id
8781 function First_From_Global_List
8783 Global_Mode : Name_Id := Name_Input) return Entity_Id;
8784 -- Get the first item with suitable mode from List
8786 ----------------------------
8787 -- First_From_Global_List --
8788 ----------------------------
8790 function First_From_Global_List
8792 Global_Mode : Name_Id := Name_Input) return Entity_Id
8797 -- Empty list (no global items)
8799 if Nkind (List) = N_Null then
8802 -- Single global item declaration (only input items)
8804 elsif Nkind_In (List, N_Expanded_Name, N_Identifier) then
8805 if Global_Mode = Name_Input then
8811 -- Simple global list (only input items) or moded global list
8814 elsif Nkind (List) = N_Aggregate then
8815 if Present (Expressions (List)) then
8816 if Global_Mode = Name_Input then
8817 return First (Expressions (List));
8823 Assoc := First (Component_Associations (List));
8824 while Present (Assoc) loop
8826 -- When we find the desired mode in an association, call
8827 -- recursively First_From_Global_List as if the mode was
8828 -- Name_Input, in order to reuse the existing machinery
8829 -- for the other cases.
8831 if Chars (First (Choices (Assoc))) = Global_Mode then
8832 return First_From_Global_List (Expression (Assoc));
8841 -- To accommodate partial decoration of disabled SPARK features,
8842 -- this routine may be called with illegal input. If this is the
8843 -- case, do not raise Program_Error.
8848 end First_From_Global_List;
8852 Global : Node_Id := Empty;
8853 Body_Id : Entity_Id;
8855 -- Start of processing for First_Global
8858 pragma Assert (Nam_In (Global_Mode, Name_In_Out,
8863 -- Retrieve the suitable pragma Global or Refined_Global. In the second
8864 -- case, it can only be located on the body entity.
8867 if Is_Subprogram_Or_Generic_Subprogram (Subp) then
8868 Body_Id := Subprogram_Body_Entity (Subp);
8870 elsif Is_Entry (Subp) or else Is_Task_Type (Subp) then
8871 Body_Id := Corresponding_Body (Parent (Subp));
8873 -- ??? It should be possible to retrieve the Refined_Global on the
8874 -- task body associated to the task object. This is not yet possible.
8876 elsif Is_Single_Task_Object (Subp) then
8883 if Present (Body_Id) then
8884 Global := Get_Pragma (Body_Id, Pragma_Refined_Global);
8887 Global := Get_Pragma (Subp, Pragma_Global);
8890 -- No corresponding global if pragma is not present
8895 -- Otherwise retrieve the corresponding list of items depending on the
8899 return First_From_Global_List
8900 (Expression (Get_Argument (Global, Subp)), Global_Mode);
8908 function Fix_Msg (Id : Entity_Id; Msg : String) return String is
8909 Is_Task : constant Boolean :=
8910 Ekind_In (Id, E_Task_Body, E_Task_Type)
8911 or else Is_Single_Task_Object (Id);
8912 Msg_Last : constant Natural := Msg'Last;
8913 Msg_Index : Natural;
8914 Res : String (Msg'Range) := (others => ' ');
8915 Res_Index : Natural;
8918 -- Copy all characters from the input message Msg to result Res with
8919 -- suitable replacements.
8921 Msg_Index := Msg'First;
8922 Res_Index := Res'First;
8923 while Msg_Index <= Msg_Last loop
8925 -- Replace "subprogram" with a different word
8927 if Msg_Index <= Msg_Last - 10
8928 and then Msg (Msg_Index .. Msg_Index + 9) = "subprogram"
8930 if Ekind_In (Id, E_Entry, E_Entry_Family) then
8931 Res (Res_Index .. Res_Index + 4) := "entry";
8932 Res_Index := Res_Index + 5;
8935 Res (Res_Index .. Res_Index + 8) := "task type";
8936 Res_Index := Res_Index + 9;
8939 Res (Res_Index .. Res_Index + 9) := "subprogram";
8940 Res_Index := Res_Index + 10;
8943 Msg_Index := Msg_Index + 10;
8945 -- Replace "protected" with a different word
8947 elsif Msg_Index <= Msg_Last - 9
8948 and then Msg (Msg_Index .. Msg_Index + 8) = "protected"
8951 Res (Res_Index .. Res_Index + 3) := "task";
8952 Res_Index := Res_Index + 4;
8953 Msg_Index := Msg_Index + 9;
8955 -- Otherwise copy the character
8958 Res (Res_Index) := Msg (Msg_Index);
8959 Msg_Index := Msg_Index + 1;
8960 Res_Index := Res_Index + 1;
8964 return Res (Res'First .. Res_Index - 1);
8967 -------------------------
8968 -- From_Nested_Package --
8969 -------------------------
8971 function From_Nested_Package (T : Entity_Id) return Boolean is
8972 Pack : constant Entity_Id := Scope (T);
8976 Ekind (Pack) = E_Package
8977 and then not Is_Frozen (Pack)
8978 and then not Scope_Within_Or_Same (Current_Scope, Pack)
8979 and then In_Open_Scopes (Scope (Pack));
8980 end From_Nested_Package;
8982 -----------------------
8983 -- Gather_Components --
8984 -----------------------
8986 procedure Gather_Components
8988 Comp_List : Node_Id;
8989 Governed_By : List_Id;
8991 Report_Errors : out Boolean)
8995 Discrete_Choice : Node_Id;
8996 Comp_Item : Node_Id;
8997 Discrim : Entity_Id;
8998 Discrim_Name : Node_Id;
9000 type Discriminant_Value_Status is
9001 (Static_Expr, Static_Subtype, Bad);
9002 subtype Good_Discrim_Value_Status is Discriminant_Value_Status
9003 range Static_Expr .. Static_Subtype; -- range excludes Bad
9005 Discrim_Value : Node_Id;
9006 Discrim_Value_Subtype : Node_Id;
9007 Discrim_Value_Status : Discriminant_Value_Status := Bad;
9009 Report_Errors := False;
9011 if No (Comp_List) or else Null_Present (Comp_List) then
9014 elsif Present (Component_Items (Comp_List)) then
9015 Comp_Item := First (Component_Items (Comp_List));
9021 while Present (Comp_Item) loop
9023 -- Skip the tag of a tagged record, the interface tags, as well
9024 -- as all items that are not user components (anonymous types,
9025 -- rep clauses, Parent field, controller field).
9027 if Nkind (Comp_Item) = N_Component_Declaration then
9029 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
9031 if not Is_Tag (Comp) and then Chars (Comp) /= Name_uParent then
9032 Append_Elmt (Comp, Into);
9040 if No (Variant_Part (Comp_List)) then
9043 Discrim_Name := Name (Variant_Part (Comp_List));
9044 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
9047 -- Look for the discriminant that governs this variant part.
9048 -- The discriminant *must* be in the Governed_By List
9050 Assoc := First (Governed_By);
9051 Find_Constraint : loop
9052 Discrim := First (Choices (Assoc));
9053 exit Find_Constraint when
9054 Chars (Discrim_Name) = Chars (Discrim)
9056 (Present (Corresponding_Discriminant (Entity (Discrim)))
9057 and then Chars (Corresponding_Discriminant
9058 (Entity (Discrim))) = Chars (Discrim_Name))
9060 Chars (Original_Record_Component (Entity (Discrim))) =
9061 Chars (Discrim_Name);
9063 if No (Next (Assoc)) then
9064 if not Is_Constrained (Typ) and then Is_Derived_Type (Typ) then
9066 -- If the type is a tagged type with inherited discriminants,
9067 -- use the stored constraint on the parent in order to find
9068 -- the values of discriminants that are otherwise hidden by an
9069 -- explicit constraint. Renamed discriminants are handled in
9072 -- If several parent discriminants are renamed by a single
9073 -- discriminant of the derived type, the call to obtain the
9074 -- Corresponding_Discriminant field only retrieves the last
9075 -- of them. We recover the constraint on the others from the
9076 -- Stored_Constraint as well.
9078 -- An inherited discriminant may have been constrained in a
9079 -- later ancestor (not the immediate parent) so we must examine
9080 -- the stored constraint of all of them to locate the inherited
9086 T : Entity_Id := Typ;
9089 while Is_Derived_Type (T) loop
9090 if Present (Stored_Constraint (T)) then
9091 D := First_Discriminant (Etype (T));
9092 C := First_Elmt (Stored_Constraint (T));
9093 while Present (D) and then Present (C) loop
9094 if Chars (Discrim_Name) = Chars (D) then
9095 if Is_Entity_Name (Node (C))
9096 and then Entity (Node (C)) = Entity (Discrim)
9098 -- D is renamed by Discrim, whose value is
9105 Make_Component_Association (Sloc (Typ),
9107 (New_Occurrence_Of (D, Sloc (Typ))),
9108 Duplicate_Subexpr_No_Checks (Node (C)));
9111 exit Find_Constraint;
9114 Next_Discriminant (D);
9119 -- Discriminant may be inherited from ancestor
9127 if No (Next (Assoc)) then
9129 (" missing value for discriminant&",
9130 First (Governed_By), Discrim_Name);
9132 Report_Errors := True;
9137 end loop Find_Constraint;
9139 Discrim_Value := Expression (Assoc);
9140 if Is_OK_Static_Expression (Discrim_Value) then
9141 Discrim_Value_Status := Static_Expr;
9143 if Ada_Version >= Ada_2020 then
9144 if Original_Node (Discrim_Value) /= Discrim_Value
9145 and then Nkind (Discrim_Value) = N_Type_Conversion
9146 and then Etype (Original_Node (Discrim_Value))
9147 = Etype (Expression (Discrim_Value))
9149 Discrim_Value_Subtype := Etype (Original_Node (Discrim_Value));
9150 -- An unhelpful (for this code) type conversion may be
9151 -- introduced in some cases; deal with it.
9153 Discrim_Value_Subtype := Etype (Discrim_Value);
9156 if Is_OK_Static_Subtype (Discrim_Value_Subtype) and then
9157 not Is_Null_Range (Type_Low_Bound (Discrim_Value_Subtype),
9158 Type_High_Bound (Discrim_Value_Subtype))
9160 -- Is_Null_Range test doesn't account for predicates, as in
9161 -- subtype Null_By_Predicate is Natural
9162 -- with Static_Predicate => Null_By_Predicate < 0;
9163 -- so test for that null case separately.
9165 if (not Has_Static_Predicate (Discrim_Value_Subtype))
9166 or else Present (First (Static_Discrete_Predicate
9167 (Discrim_Value_Subtype)))
9169 Discrim_Value_Status := Static_Subtype;
9174 if Discrim_Value_Status = Bad then
9176 -- If the variant part is governed by a discriminant of the type
9177 -- this is an error. If the variant part and the discriminant are
9178 -- inherited from an ancestor this is legal (AI05-220) unless the
9179 -- components are being gathered for an aggregate, in which case
9180 -- the caller must check Report_Errors.
9182 -- In Ada 2020 the above rules are relaxed. A nonstatic governing
9183 -- discriminant is OK as long as it has a static subtype and
9184 -- every value of that subtype (and there must be at least one)
9185 -- selects the same variant.
9187 if Scope (Original_Record_Component
9188 ((Entity (First (Choices (Assoc)))))) = Typ
9190 if Ada_Version >= Ada_2020 then
9192 ("value for discriminant & must be static or " &
9193 "discriminant's nominal subtype must be static " &
9195 Discrim_Value, Discrim);
9198 ("value for discriminant & must be static!",
9199 Discrim_Value, Discrim);
9201 Why_Not_Static (Discrim_Value);
9204 Report_Errors := True;
9209 Search_For_Discriminant_Value : declare
9215 UI_Discrim_Value : Uint;
9218 case Good_Discrim_Value_Status'(Discrim_Value_Status) is
9220 UI_Discrim_Value := Expr_Value (Discrim_Value);
9221 when Static_Subtype =>
9222 -- Arbitrarily pick one value of the subtype and look
9223 -- for the variant associated with that value; we will
9224 -- check later that the same variant is associated with
9225 -- all of the other values of the subtype.
9226 if Has_Static_Predicate (Discrim_Value_Subtype) then
9228 Range_Or_Expr : constant Node_Id :=
9229 First (Static_Discrete_Predicate
9230 (Discrim_Value_Subtype));
9232 if Nkind (Range_Or_Expr) = N_Range then
9234 Expr_Value (Low_Bound (Range_Or_Expr));
9236 UI_Discrim_Value := Expr_Value (Range_Or_Expr);
9241 := Expr_Value (Type_Low_Bound (Discrim_Value_Subtype));
9245 Find_Discrete_Value : while Present (Variant) loop
9247 -- If a choice is a subtype with a static predicate, it must
9248 -- be rewritten as an explicit list of non-predicated choices.
9250 Expand_Static_Predicates_In_Choices (Variant);
9252 Discrete_Choice := First (Discrete_Choices (Variant));
9253 while Present (Discrete_Choice) loop
9254 exit Find_Discrete_Value when
9255 Nkind (Discrete_Choice) = N_Others_Choice;
9257 Get_Index_Bounds (Discrete_Choice, Low, High);
9259 UI_Low := Expr_Value (Low);
9260 UI_High := Expr_Value (High);
9262 exit Find_Discrete_Value when
9263 UI_Low <= UI_Discrim_Value
9265 UI_High >= UI_Discrim_Value;
9267 Next (Discrete_Choice);
9270 Next_Non_Pragma (Variant);
9271 end loop Find_Discrete_Value;
9272 end Search_For_Discriminant_Value;
9274 -- The case statement must include a variant that corresponds to the
9275 -- value of the discriminant, unless the discriminant type has a
9276 -- static predicate. In that case the absence of an others_choice that
9277 -- would cover this value becomes a run-time error (3.8.1 (21.1/2)).
9280 and then not Has_Static_Predicate (Etype (Discrim_Name))
9283 ("value of discriminant & is out of range", Discrim_Value, Discrim);
9284 Report_Errors := True;
9288 -- If we have found the corresponding choice, recursively add its
9289 -- components to the Into list. The nested components are part of
9290 -- the same record type.
9292 if Present (Variant) then
9293 if Discrim_Value_Status = Static_Subtype then
9295 Discrim_Value_Subtype_Intervals
9296 : constant Interval_Lists.Discrete_Interval_List
9297 := Interval_Lists.Type_Intervals (Discrim_Value_Subtype);
9300 : constant Interval_Lists.Discrete_Interval_List
9301 := Interval_Lists.Choice_List_Intervals
9302 (Discrete_Choices => Discrete_Choices (Variant));
9304 if not Interval_Lists.Is_Subset
9305 (Subset => Discrim_Value_Subtype_Intervals,
9306 Of_Set => Variant_Intervals)
9309 ("no single variant is associated with all values of " &
9310 "the subtype of discriminant value &",
9311 Discrim_Value, Discrim);
9312 Report_Errors := True;
9319 (Typ, Component_List (Variant), Governed_By, Into, Report_Errors);
9321 end Gather_Components;
9323 -----------------------
9324 -- Get_Accessibility --
9325 -----------------------
9327 function Get_Accessibility (E : Entity_Id) return Node_Id is
9329 -- When minimum accessibility is set for E then we utilize it - except
9330 -- in a few edge cases like the expansion of select statements where
9331 -- generated subprogram may attempt to unnecessarily use a minimum
9332 -- accessibility object declared outside of scope.
9334 -- To avoid these situations where expansion may get complex we verify
9335 -- that the minimum accessibility object is within scope.
9337 if Ekind (E) in Formal_Kind
9338 and then Present (Minimum_Accessibility (E))
9339 and then In_Open_Scopes (Scope (Minimum_Accessibility (E)))
9341 return Minimum_Accessibility (E);
9344 return Extra_Accessibility (E);
9345 end Get_Accessibility;
9347 ------------------------
9348 -- Get_Actual_Subtype --
9349 ------------------------
9351 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
9352 Typ : constant Entity_Id := Etype (N);
9353 Utyp : Entity_Id := Underlying_Type (Typ);
9362 -- If what we have is an identifier that references a subprogram
9363 -- formal, or a variable or constant object, then we get the actual
9364 -- subtype from the referenced entity if one has been built.
9366 if Nkind (N) = N_Identifier
9368 (Is_Formal (Entity (N))
9369 or else Ekind (Entity (N)) = E_Constant
9370 or else Ekind (Entity (N)) = E_Variable)
9371 and then Present (Actual_Subtype (Entity (N)))
9373 return Actual_Subtype (Entity (N));
9375 -- Actual subtype of unchecked union is always itself. We never need
9376 -- the "real" actual subtype. If we did, we couldn't get it anyway
9377 -- because the discriminant is not available. The restrictions on
9378 -- Unchecked_Union are designed to make sure that this is OK.
9380 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
9383 -- Here for the unconstrained case, we must find actual subtype
9384 -- No actual subtype is available, so we must build it on the fly.
9386 -- Checking the type, not the underlying type, for constrainedness
9387 -- seems to be necessary. Maybe all the tests should be on the type???
9389 elsif (not Is_Constrained (Typ))
9390 and then (Is_Array_Type (Utyp)
9391 or else (Is_Record_Type (Utyp)
9392 and then Has_Discriminants (Utyp)))
9393 and then not Has_Unknown_Discriminants (Utyp)
9394 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
9396 -- Nothing to do if in spec expression (why not???)
9398 if In_Spec_Expression then
9401 elsif Is_Private_Type (Typ) and then not Has_Discriminants (Typ) then
9403 -- If the type has no discriminants, there is no subtype to
9404 -- build, even if the underlying type is discriminated.
9408 -- Else build the actual subtype
9411 Decl := Build_Actual_Subtype (Typ, N);
9413 -- The call may yield a declaration, or just return the entity
9419 Atyp := Defining_Identifier (Decl);
9421 -- If Build_Actual_Subtype generated a new declaration then use it
9425 -- The actual subtype is an Itype, so analyze the declaration,
9426 -- but do not attach it to the tree, to get the type defined.
9428 Set_Parent (Decl, N);
9429 Set_Is_Itype (Atyp);
9430 Analyze (Decl, Suppress => All_Checks);
9431 Set_Associated_Node_For_Itype (Atyp, N);
9432 Set_Has_Delayed_Freeze (Atyp, False);
9434 -- We need to freeze the actual subtype immediately. This is
9435 -- needed, because otherwise this Itype will not get frozen
9436 -- at all, and it is always safe to freeze on creation because
9437 -- any associated types must be frozen at this point.
9439 Freeze_Itype (Atyp, N);
9442 -- Otherwise we did not build a declaration, so return original
9449 -- For all remaining cases, the actual subtype is the same as
9450 -- the nominal type.
9455 end Get_Actual_Subtype;
9457 -------------------------------------
9458 -- Get_Actual_Subtype_If_Available --
9459 -------------------------------------
9461 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
9462 Typ : constant Entity_Id := Etype (N);
9465 -- If what we have is an identifier that references a subprogram
9466 -- formal, or a variable or constant object, then we get the actual
9467 -- subtype from the referenced entity if one has been built.
9469 if Nkind (N) = N_Identifier
9471 (Is_Formal (Entity (N))
9472 or else Ekind (Entity (N)) = E_Constant
9473 or else Ekind (Entity (N)) = E_Variable)
9474 and then Present (Actual_Subtype (Entity (N)))
9476 return Actual_Subtype (Entity (N));
9478 -- Otherwise the Etype of N is returned unchanged
9483 end Get_Actual_Subtype_If_Available;
9485 ------------------------
9486 -- Get_Body_From_Stub --
9487 ------------------------
9489 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
9491 return Proper_Body (Unit (Library_Unit (N)));
9492 end Get_Body_From_Stub;
9494 ---------------------
9495 -- Get_Cursor_Type --
9496 ---------------------
9498 function Get_Cursor_Type
9500 Typ : Entity_Id) return Entity_Id
9504 First_Op : Entity_Id;
9508 -- If error already detected, return
9510 if Error_Posted (Aspect) then
9514 -- The cursor type for an Iterable aspect is the return type of a
9515 -- non-overloaded First primitive operation. Locate association for
9518 Assoc := First (Component_Associations (Expression (Aspect)));
9520 while Present (Assoc) loop
9521 if Chars (First (Choices (Assoc))) = Name_First then
9522 First_Op := Expression (Assoc);
9529 if First_Op = Any_Id then
9530 Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
9533 elsif not Analyzed (First_Op) then
9539 -- Locate function with desired name and profile in scope of type
9540 -- In the rare case where the type is an integer type, a base type
9541 -- is created for it, check that the base type of the first formal
9542 -- of First matches the base type of the domain.
9544 Func := First_Entity (Scope (Typ));
9545 while Present (Func) loop
9546 if Chars (Func) = Chars (First_Op)
9547 and then Ekind (Func) = E_Function
9548 and then Present (First_Formal (Func))
9549 and then Base_Type (Etype (First_Formal (Func))) = Base_Type (Typ)
9550 and then No (Next_Formal (First_Formal (Func)))
9552 if Cursor /= Any_Type then
9554 ("Operation First for iterable type must be unique", Aspect);
9557 Cursor := Etype (Func);
9564 -- If not found, no way to resolve remaining primitives
9566 if Cursor = Any_Type then
9568 ("primitive operation for Iterable type must appear in the same "
9569 & "list of declarations as the type", Aspect);
9573 end Get_Cursor_Type;
9575 function Get_Cursor_Type (Typ : Entity_Id) return Entity_Id is
9577 return Etype (Get_Iterable_Type_Primitive (Typ, Name_First));
9578 end Get_Cursor_Type;
9580 -------------------------------
9581 -- Get_Default_External_Name --
9582 -------------------------------
9584 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
9586 Get_Decoded_Name_String (Chars (E));
9588 if Opt.External_Name_Imp_Casing = Uppercase then
9589 Set_Casing (All_Upper_Case);
9591 Set_Casing (All_Lower_Case);
9595 Make_String_Literal (Sloc (E),
9596 Strval => String_From_Name_Buffer);
9597 end Get_Default_External_Name;
9599 --------------------------
9600 -- Get_Enclosing_Object --
9601 --------------------------
9603 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
9605 if Is_Entity_Name (N) then
9609 when N_Indexed_Component
9610 | N_Selected_Component
9613 -- If not generating code, a dereference may be left implicit.
9614 -- In thoses cases, return Empty.
9616 if Is_Access_Type (Etype (Prefix (N))) then
9619 return Get_Enclosing_Object (Prefix (N));
9622 when N_Type_Conversion =>
9623 return Get_Enclosing_Object (Expression (N));
9629 end Get_Enclosing_Object;
9631 ---------------------------
9632 -- Get_Enum_Lit_From_Pos --
9633 ---------------------------
9635 function Get_Enum_Lit_From_Pos
9638 Loc : Source_Ptr) return Node_Id
9640 Btyp : Entity_Id := Base_Type (T);
9645 -- In the case where the literal is of type Character, Wide_Character
9646 -- or Wide_Wide_Character or of a type derived from them, there needs
9647 -- to be some special handling since there is no explicit chain of
9648 -- literals to search. Instead, an N_Character_Literal node is created
9649 -- with the appropriate Char_Code and Chars fields.
9651 if Is_Standard_Character_Type (T) then
9652 Set_Character_Literal_Name (UI_To_CC (Pos));
9655 Make_Character_Literal (Loc,
9657 Char_Literal_Value => Pos);
9659 -- For all other cases, we have a complete table of literals, and
9660 -- we simply iterate through the chain of literal until the one
9661 -- with the desired position value is found.
9664 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
9665 Btyp := Full_View (Btyp);
9668 Lit := First_Literal (Btyp);
9670 -- Position in the enumeration type starts at 0
9672 if UI_To_Int (Pos) < 0 then
9673 raise Constraint_Error;
9676 for J in 1 .. UI_To_Int (Pos) loop
9679 -- If Lit is Empty, Pos is not in range, so raise Constraint_Error
9680 -- inside the loop to avoid calling Next_Literal on Empty.
9683 raise Constraint_Error;
9687 -- Create a new node from Lit, with source location provided by Loc
9688 -- if not equal to No_Location, or by copying the source location of
9693 if LLoc = No_Location then
9697 return New_Occurrence_Of (Lit, LLoc);
9699 end Get_Enum_Lit_From_Pos;
9701 ------------------------
9702 -- Get_Generic_Entity --
9703 ------------------------
9705 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
9706 Ent : constant Entity_Id := Entity (Name (N));
9708 if Present (Renamed_Object (Ent)) then
9709 return Renamed_Object (Ent);
9713 end Get_Generic_Entity;
9715 -------------------------------------
9716 -- Get_Incomplete_View_Of_Ancestor --
9717 -------------------------------------
9719 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
9720 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
9721 Par_Scope : Entity_Id;
9722 Par_Type : Entity_Id;
9725 -- The incomplete view of an ancestor is only relevant for private
9726 -- derived types in child units.
9728 if not Is_Derived_Type (E)
9729 or else not Is_Child_Unit (Cur_Unit)
9734 Par_Scope := Scope (Cur_Unit);
9735 if No (Par_Scope) then
9739 Par_Type := Etype (Base_Type (E));
9741 -- Traverse list of ancestor types until we find one declared in
9742 -- a parent or grandparent unit (two levels seem sufficient).
9744 while Present (Par_Type) loop
9745 if Scope (Par_Type) = Par_Scope
9746 or else Scope (Par_Type) = Scope (Par_Scope)
9750 elsif not Is_Derived_Type (Par_Type) then
9754 Par_Type := Etype (Base_Type (Par_Type));
9758 -- If none found, there is no relevant ancestor type.
9762 end Get_Incomplete_View_Of_Ancestor;
9764 ----------------------
9765 -- Get_Index_Bounds --
9766 ----------------------
9768 procedure Get_Index_Bounds
9772 Use_Full_View : Boolean := False)
9774 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id;
9775 -- Obtain the scalar range of type Typ. If flag Use_Full_View is set and
9776 -- Typ qualifies, the scalar range is obtained from the full view of the
9779 --------------------------
9780 -- Scalar_Range_Of_Type --
9781 --------------------------
9783 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id is
9784 T : Entity_Id := Typ;
9787 if Use_Full_View and then Present (Full_View (T)) then
9791 return Scalar_Range (T);
9792 end Scalar_Range_Of_Type;
9796 Kind : constant Node_Kind := Nkind (N);
9799 -- Start of processing for Get_Index_Bounds
9802 if Kind = N_Range then
9804 H := High_Bound (N);
9806 elsif Kind = N_Subtype_Indication then
9807 Rng := Range_Expression (Constraint (N));
9815 L := Low_Bound (Range_Expression (Constraint (N)));
9816 H := High_Bound (Range_Expression (Constraint (N)));
9819 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
9820 Rng := Scalar_Range_Of_Type (Entity (N));
9822 if Error_Posted (Rng) then
9826 elsif Nkind (Rng) = N_Subtype_Indication then
9827 Get_Index_Bounds (Rng, L, H);
9830 L := Low_Bound (Rng);
9831 H := High_Bound (Rng);
9835 -- N is an expression, indicating a range with one value
9840 end Get_Index_Bounds;
9842 -----------------------------
9843 -- Get_Interfacing_Aspects --
9844 -----------------------------
9846 procedure Get_Interfacing_Aspects
9847 (Iface_Asp : Node_Id;
9848 Conv_Asp : out Node_Id;
9849 EN_Asp : out Node_Id;
9850 Expo_Asp : out Node_Id;
9851 Imp_Asp : out Node_Id;
9852 LN_Asp : out Node_Id;
9853 Do_Checks : Boolean := False)
9855 procedure Save_Or_Duplication_Error
9857 To : in out Node_Id);
9858 -- Save the value of aspect Asp in node To. If To already has a value,
9859 -- then this is considered a duplicate use of aspect. Emit an error if
9860 -- flag Do_Checks is set.
9862 -------------------------------
9863 -- Save_Or_Duplication_Error --
9864 -------------------------------
9866 procedure Save_Or_Duplication_Error
9868 To : in out Node_Id)
9871 -- Detect an extra aspect and issue an error
9873 if Present (To) then
9875 Error_Msg_Name_1 := Chars (Identifier (Asp));
9876 Error_Msg_Sloc := Sloc (To);
9877 Error_Msg_N ("aspect % previously given #", Asp);
9880 -- Otherwise capture the aspect
9885 end Save_Or_Duplication_Error;
9892 -- The following variables capture each individual aspect
9894 Conv : Node_Id := Empty;
9895 EN : Node_Id := Empty;
9896 Expo : Node_Id := Empty;
9897 Imp : Node_Id := Empty;
9898 LN : Node_Id := Empty;
9900 -- Start of processing for Get_Interfacing_Aspects
9903 -- The input interfacing aspect should reside in an aspect specification
9906 pragma Assert (Is_List_Member (Iface_Asp));
9908 -- Examine the aspect specifications of the related entity. Find and
9909 -- capture all interfacing aspects. Detect duplicates and emit errors
9912 Asp := First (List_Containing (Iface_Asp));
9913 while Present (Asp) loop
9914 Asp_Id := Get_Aspect_Id (Asp);
9916 if Asp_Id = Aspect_Convention then
9917 Save_Or_Duplication_Error (Asp, Conv);
9919 elsif Asp_Id = Aspect_External_Name then
9920 Save_Or_Duplication_Error (Asp, EN);
9922 elsif Asp_Id = Aspect_Export then
9923 Save_Or_Duplication_Error (Asp, Expo);
9925 elsif Asp_Id = Aspect_Import then
9926 Save_Or_Duplication_Error (Asp, Imp);
9928 elsif Asp_Id = Aspect_Link_Name then
9929 Save_Or_Duplication_Error (Asp, LN);
9940 end Get_Interfacing_Aspects;
9942 ---------------------------------
9943 -- Get_Iterable_Type_Primitive --
9944 ---------------------------------
9946 function Get_Iterable_Type_Primitive
9948 Nam : Name_Id) return Entity_Id
9950 Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
9958 Assoc := First (Component_Associations (Funcs));
9959 while Present (Assoc) loop
9960 if Chars (First (Choices (Assoc))) = Nam then
9961 return Entity (Expression (Assoc));
9964 Assoc := Next (Assoc);
9969 end Get_Iterable_Type_Primitive;
9971 ----------------------------------
9972 -- Get_Library_Unit_Name_String --
9973 ----------------------------------
9975 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
9976 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
9979 Get_Unit_Name_String (Unit_Name_Id);
9981 -- Remove seven last character (" (spec)" or " (body)")
9983 Name_Len := Name_Len - 7;
9984 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
9985 end Get_Library_Unit_Name_String;
9987 --------------------------
9988 -- Get_Max_Queue_Length --
9989 --------------------------
9991 function Get_Max_Queue_Length (Id : Entity_Id) return Uint is
9992 pragma Assert (Is_Entry (Id));
9993 Prag : constant Entity_Id := Get_Pragma (Id, Pragma_Max_Queue_Length);
9997 -- A value of 0 or -1 represents no maximum specified, and entries and
9998 -- entry families with no Max_Queue_Length aspect or pragma default to
10001 if not Present (Prag) then
10006 (Expression (First (Pragma_Argument_Associations (Prag))));
10008 -- Since -1 and 0 are equivalent, return 0 for instances of -1 for
10016 end Get_Max_Queue_Length;
10018 ------------------------
10019 -- Get_Name_Entity_Id --
10020 ------------------------
10022 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
10024 return Entity_Id (Get_Name_Table_Int (Id));
10025 end Get_Name_Entity_Id;
10027 ------------------------------
10028 -- Get_Name_From_CTC_Pragma --
10029 ------------------------------
10031 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
10032 Arg : constant Node_Id :=
10033 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
10035 return Strval (Expr_Value_S (Arg));
10036 end Get_Name_From_CTC_Pragma;
10038 -----------------------
10039 -- Get_Parent_Entity --
10040 -----------------------
10042 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
10044 if Nkind (Unit) = N_Package_Body
10045 and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
10047 return Defining_Entity
10048 (Specification (Instance_Spec (Original_Node (Unit))));
10049 elsif Nkind (Unit) = N_Package_Instantiation then
10050 return Defining_Entity (Specification (Instance_Spec (Unit)));
10052 return Defining_Entity (Unit);
10054 end Get_Parent_Entity;
10056 -------------------
10057 -- Get_Pragma_Id --
10058 -------------------
10060 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
10062 return Get_Pragma_Id (Pragma_Name_Unmapped (N));
10065 ------------------------
10066 -- Get_Qualified_Name --
10067 ------------------------
10069 function Get_Qualified_Name
10071 Suffix : Entity_Id := Empty) return Name_Id
10073 Suffix_Nam : Name_Id := No_Name;
10076 if Present (Suffix) then
10077 Suffix_Nam := Chars (Suffix);
10080 return Get_Qualified_Name (Chars (Id), Suffix_Nam, Scope (Id));
10081 end Get_Qualified_Name;
10083 function Get_Qualified_Name
10085 Suffix : Name_Id := No_Name;
10086 Scop : Entity_Id := Current_Scope) return Name_Id
10088 procedure Add_Scope (S : Entity_Id);
10089 -- Add the fully qualified form of scope S to the name buffer. The
10097 procedure Add_Scope (S : Entity_Id) is
10102 elsif S = Standard_Standard then
10106 Add_Scope (Scope (S));
10107 Get_Name_String_And_Append (Chars (S));
10108 Add_Str_To_Name_Buffer ("__");
10112 -- Start of processing for Get_Qualified_Name
10118 -- Append the base name after all scopes have been chained
10120 Get_Name_String_And_Append (Nam);
10122 -- Append the suffix (if present)
10124 if Suffix /= No_Name then
10125 Add_Str_To_Name_Buffer ("__");
10126 Get_Name_String_And_Append (Suffix);
10130 end Get_Qualified_Name;
10132 -----------------------
10133 -- Get_Reason_String --
10134 -----------------------
10136 procedure Get_Reason_String (N : Node_Id) is
10138 if Nkind (N) = N_String_Literal then
10139 Store_String_Chars (Strval (N));
10141 elsif Nkind (N) = N_Op_Concat then
10142 Get_Reason_String (Left_Opnd (N));
10143 Get_Reason_String (Right_Opnd (N));
10145 -- If not of required form, error
10149 ("Reason for pragma Warnings has wrong form", N);
10151 ("\must be string literal or concatenation of string literals", N);
10154 end Get_Reason_String;
10156 --------------------------------
10157 -- Get_Reference_Discriminant --
10158 --------------------------------
10160 function Get_Reference_Discriminant (Typ : Entity_Id) return Entity_Id is
10164 D := First_Discriminant (Typ);
10165 while Present (D) loop
10166 if Has_Implicit_Dereference (D) then
10169 Next_Discriminant (D);
10173 end Get_Reference_Discriminant;
10175 ---------------------------
10176 -- Get_Referenced_Object --
10177 ---------------------------
10179 function Get_Referenced_Object (N : Node_Id) return Node_Id is
10184 while Is_Entity_Name (R)
10185 and then Is_Object (Entity (R))
10186 and then Present (Renamed_Object (Entity (R)))
10188 R := Renamed_Object (Entity (R));
10192 end Get_Referenced_Object;
10194 ------------------------
10195 -- Get_Renamed_Entity --
10196 ------------------------
10198 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
10203 while Present (Renamed_Entity (R)) loop
10204 R := Renamed_Entity (R);
10208 end Get_Renamed_Entity;
10210 -----------------------
10211 -- Get_Return_Object --
10212 -----------------------
10214 function Get_Return_Object (N : Node_Id) return Entity_Id is
10218 Decl := First (Return_Object_Declarations (N));
10219 while Present (Decl) loop
10220 exit when Nkind (Decl) = N_Object_Declaration
10221 and then Is_Return_Object (Defining_Identifier (Decl));
10225 pragma Assert (Present (Decl));
10226 return Defining_Identifier (Decl);
10227 end Get_Return_Object;
10229 ---------------------------
10230 -- Get_Subprogram_Entity --
10231 ---------------------------
10233 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
10235 Subp_Id : Entity_Id;
10238 if Nkind (Nod) = N_Accept_Statement then
10239 Subp := Entry_Direct_Name (Nod);
10241 elsif Nkind (Nod) = N_Slice then
10242 Subp := Prefix (Nod);
10245 Subp := Name (Nod);
10248 -- Strip the subprogram call
10251 if Nkind_In (Subp, N_Explicit_Dereference,
10252 N_Indexed_Component,
10253 N_Selected_Component)
10255 Subp := Prefix (Subp);
10257 elsif Nkind_In (Subp, N_Type_Conversion,
10258 N_Unchecked_Type_Conversion)
10260 Subp := Expression (Subp);
10267 -- Extract the entity of the subprogram call
10269 if Is_Entity_Name (Subp) then
10270 Subp_Id := Entity (Subp);
10272 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
10273 Subp_Id := Directly_Designated_Type (Subp_Id);
10276 if Is_Subprogram (Subp_Id) then
10282 -- The search did not find a construct that denotes a subprogram
10287 end Get_Subprogram_Entity;
10289 -----------------------------
10290 -- Get_Task_Body_Procedure --
10291 -----------------------------
10293 function Get_Task_Body_Procedure (E : Entity_Id) return Entity_Id is
10295 -- Note: A task type may be the completion of a private type with
10296 -- discriminants. When performing elaboration checks on a task
10297 -- declaration, the current view of the type may be the private one,
10298 -- and the procedure that holds the body of the task is held in its
10299 -- underlying type.
10301 -- This is an odd function, why not have Task_Body_Procedure do
10302 -- the following digging???
10304 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
10305 end Get_Task_Body_Procedure;
10307 -------------------------
10308 -- Get_User_Defined_Eq --
10309 -------------------------
10311 function Get_User_Defined_Eq (E : Entity_Id) return Entity_Id is
10316 Prim := First_Elmt (Collect_Primitive_Operations (E));
10317 while Present (Prim) loop
10320 if Chars (Op) = Name_Op_Eq
10321 and then Etype (Op) = Standard_Boolean
10322 and then Etype (First_Formal (Op)) = E
10323 and then Etype (Next_Formal (First_Formal (Op))) = E
10332 end Get_User_Defined_Eq;
10338 procedure Get_Views
10340 Priv_Typ : out Entity_Id;
10341 Full_Typ : out Entity_Id;
10342 Full_Base : out Entity_Id;
10343 CRec_Typ : out Entity_Id)
10345 IP_View : Entity_Id;
10348 -- Assume that none of the views can be recovered
10352 Full_Base := Empty;
10355 -- The input type is the corresponding record type of a protected or a
10358 if Ekind (Typ) = E_Record_Type
10359 and then Is_Concurrent_Record_Type (Typ)
10362 Full_Typ := Corresponding_Concurrent_Type (CRec_Typ);
10363 Full_Base := Base_Type (Full_Typ);
10364 Priv_Typ := Incomplete_Or_Partial_View (Full_Typ);
10366 -- Otherwise the input type denotes an arbitrary type
10369 IP_View := Incomplete_Or_Partial_View (Typ);
10371 -- The input type denotes the full view of a private type
10373 if Present (IP_View) then
10374 Priv_Typ := IP_View;
10377 -- The input type is a private type
10379 elsif Is_Private_Type (Typ) then
10381 Full_Typ := Full_View (Priv_Typ);
10383 -- Otherwise the input type does not have any views
10389 if Present (Full_Typ) then
10390 Full_Base := Base_Type (Full_Typ);
10392 if Ekind_In (Full_Typ, E_Protected_Type, E_Task_Type) then
10393 CRec_Typ := Corresponding_Record_Type (Full_Typ);
10399 -----------------------
10400 -- Has_Access_Values --
10401 -----------------------
10403 function Has_Access_Values (T : Entity_Id) return Boolean is
10404 Typ : constant Entity_Id := Underlying_Type (T);
10407 -- Case of a private type which is not completed yet. This can only
10408 -- happen in the case of a generic format type appearing directly, or
10409 -- as a component of the type to which this function is being applied
10410 -- at the top level. Return False in this case, since we certainly do
10411 -- not know that the type contains access types.
10416 elsif Is_Access_Type (Typ) then
10419 elsif Is_Array_Type (Typ) then
10420 return Has_Access_Values (Component_Type (Typ));
10422 elsif Is_Record_Type (Typ) then
10427 -- Loop to Check components
10429 Comp := First_Component_Or_Discriminant (Typ);
10430 while Present (Comp) loop
10432 -- Check for access component, tag field does not count, even
10433 -- though it is implemented internally using an access type.
10435 if Has_Access_Values (Etype (Comp))
10436 and then Chars (Comp) /= Name_uTag
10441 Next_Component_Or_Discriminant (Comp);
10450 end Has_Access_Values;
10452 ------------------------------
10453 -- Has_Compatible_Alignment --
10454 ------------------------------
10456 function Has_Compatible_Alignment
10459 Layout_Done : Boolean) return Alignment_Result
10461 function Has_Compatible_Alignment_Internal
10464 Layout_Done : Boolean;
10465 Default : Alignment_Result) return Alignment_Result;
10466 -- This is the internal recursive function that actually does the work.
10467 -- There is one additional parameter, which says what the result should
10468 -- be if no alignment information is found, and there is no definite
10469 -- indication of compatible alignments. At the outer level, this is set
10470 -- to Unknown, but for internal recursive calls in the case where types
10471 -- are known to be correct, it is set to Known_Compatible.
10473 ---------------------------------------
10474 -- Has_Compatible_Alignment_Internal --
10475 ---------------------------------------
10477 function Has_Compatible_Alignment_Internal
10480 Layout_Done : Boolean;
10481 Default : Alignment_Result) return Alignment_Result
10483 Result : Alignment_Result := Known_Compatible;
10484 -- Holds the current status of the result. Note that once a value of
10485 -- Known_Incompatible is set, it is sticky and does not get changed
10486 -- to Unknown (the value in Result only gets worse as we go along,
10489 Offs : Uint := No_Uint;
10490 -- Set to a factor of the offset from the base object when Expr is a
10491 -- selected or indexed component, based on Component_Bit_Offset and
10492 -- Component_Size respectively. A negative value is used to represent
10493 -- a value which is not known at compile time.
10495 procedure Check_Prefix;
10496 -- Checks the prefix recursively in the case where the expression
10497 -- is an indexed or selected component.
10499 procedure Set_Result (R : Alignment_Result);
10500 -- If R represents a worse outcome (unknown instead of known
10501 -- compatible, or known incompatible), then set Result to R.
10507 procedure Check_Prefix is
10509 -- The subtlety here is that in doing a recursive call to check
10510 -- the prefix, we have to decide what to do in the case where we
10511 -- don't find any specific indication of an alignment problem.
10513 -- At the outer level, we normally set Unknown as the result in
10514 -- this case, since we can only set Known_Compatible if we really
10515 -- know that the alignment value is OK, but for the recursive
10516 -- call, in the case where the types match, and we have not
10517 -- specified a peculiar alignment for the object, we are only
10518 -- concerned about suspicious rep clauses, the default case does
10519 -- not affect us, since the compiler will, in the absence of such
10520 -- rep clauses, ensure that the alignment is correct.
10522 if Default = Known_Compatible
10524 (Etype (Obj) = Etype (Expr)
10525 and then (Unknown_Alignment (Obj)
10527 Alignment (Obj) = Alignment (Etype (Obj))))
10530 (Has_Compatible_Alignment_Internal
10531 (Obj, Prefix (Expr), Layout_Done, Known_Compatible));
10533 -- In all other cases, we need a full check on the prefix
10537 (Has_Compatible_Alignment_Internal
10538 (Obj, Prefix (Expr), Layout_Done, Unknown));
10546 procedure Set_Result (R : Alignment_Result) is
10553 -- Start of processing for Has_Compatible_Alignment_Internal
10556 -- If Expr is a selected component, we must make sure there is no
10557 -- potentially troublesome component clause and that the record is
10558 -- not packed if the layout is not done.
10560 if Nkind (Expr) = N_Selected_Component then
10562 -- Packing generates unknown alignment if layout is not done
10564 if Is_Packed (Etype (Prefix (Expr))) and then not Layout_Done then
10565 Set_Result (Unknown);
10568 -- Check prefix and component offset
10571 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
10573 -- If Expr is an indexed component, we must make sure there is no
10574 -- potentially troublesome Component_Size clause and that the array
10575 -- is not bit-packed if the layout is not done.
10577 elsif Nkind (Expr) = N_Indexed_Component then
10579 Typ : constant Entity_Id := Etype (Prefix (Expr));
10582 -- Packing generates unknown alignment if layout is not done
10584 if Is_Bit_Packed_Array (Typ) and then not Layout_Done then
10585 Set_Result (Unknown);
10588 -- Check prefix and component offset (or at least size)
10591 Offs := Indexed_Component_Bit_Offset (Expr);
10592 if Offs = No_Uint then
10593 Offs := Component_Size (Typ);
10598 -- If we have a null offset, the result is entirely determined by
10599 -- the base object and has already been computed recursively.
10601 if Offs = Uint_0 then
10604 -- Case where we know the alignment of the object
10606 elsif Known_Alignment (Obj) then
10608 ObjA : constant Uint := Alignment (Obj);
10609 ExpA : Uint := No_Uint;
10610 SizA : Uint := No_Uint;
10613 -- If alignment of Obj is 1, then we are always OK
10616 Set_Result (Known_Compatible);
10618 -- Alignment of Obj is greater than 1, so we need to check
10621 -- If we have an offset, see if it is compatible
10623 if Offs /= No_Uint and Offs > Uint_0 then
10624 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
10625 Set_Result (Known_Incompatible);
10628 -- See if Expr is an object with known alignment
10630 elsif Is_Entity_Name (Expr)
10631 and then Known_Alignment (Entity (Expr))
10633 ExpA := Alignment (Entity (Expr));
10635 -- Otherwise, we can use the alignment of the type of
10636 -- Expr given that we already checked for
10637 -- discombobulating rep clauses for the cases of indexed
10638 -- and selected components above.
10640 elsif Known_Alignment (Etype (Expr)) then
10641 ExpA := Alignment (Etype (Expr));
10643 -- Otherwise the alignment is unknown
10646 Set_Result (Default);
10649 -- If we got an alignment, see if it is acceptable
10651 if ExpA /= No_Uint and then ExpA < ObjA then
10652 Set_Result (Known_Incompatible);
10655 -- If Expr is not a piece of a larger object, see if size
10656 -- is given. If so, check that it is not too small for the
10657 -- required alignment.
10659 if Offs /= No_Uint then
10662 -- See if Expr is an object with known size
10664 elsif Is_Entity_Name (Expr)
10665 and then Known_Static_Esize (Entity (Expr))
10667 SizA := Esize (Entity (Expr));
10669 -- Otherwise, we check the object size of the Expr type
10671 elsif Known_Static_Esize (Etype (Expr)) then
10672 SizA := Esize (Etype (Expr));
10675 -- If we got a size, see if it is a multiple of the Obj
10676 -- alignment, if not, then the alignment cannot be
10677 -- acceptable, since the size is always a multiple of the
10680 if SizA /= No_Uint then
10681 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
10682 Set_Result (Known_Incompatible);
10688 -- If we do not know required alignment, any non-zero offset is a
10689 -- potential problem (but certainly may be OK, so result is unknown).
10691 elsif Offs /= No_Uint then
10692 Set_Result (Unknown);
10694 -- If we can't find the result by direct comparison of alignment
10695 -- values, then there is still one case that we can determine known
10696 -- result, and that is when we can determine that the types are the
10697 -- same, and no alignments are specified. Then we known that the
10698 -- alignments are compatible, even if we don't know the alignment
10699 -- value in the front end.
10701 elsif Etype (Obj) = Etype (Expr) then
10703 -- Types are the same, but we have to check for possible size
10704 -- and alignments on the Expr object that may make the alignment
10705 -- different, even though the types are the same.
10707 if Is_Entity_Name (Expr) then
10709 -- First check alignment of the Expr object. Any alignment less
10710 -- than Maximum_Alignment is worrisome since this is the case
10711 -- where we do not know the alignment of Obj.
10713 if Known_Alignment (Entity (Expr))
10714 and then UI_To_Int (Alignment (Entity (Expr))) <
10715 Ttypes.Maximum_Alignment
10717 Set_Result (Unknown);
10719 -- Now check size of Expr object. Any size that is not an
10720 -- even multiple of Maximum_Alignment is also worrisome
10721 -- since it may cause the alignment of the object to be less
10722 -- than the alignment of the type.
10724 elsif Known_Static_Esize (Entity (Expr))
10726 (UI_To_Int (Esize (Entity (Expr))) mod
10727 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
10730 Set_Result (Unknown);
10732 -- Otherwise same type is decisive
10735 Set_Result (Known_Compatible);
10739 -- Another case to deal with is when there is an explicit size or
10740 -- alignment clause when the types are not the same. If so, then the
10741 -- result is Unknown. We don't need to do this test if the Default is
10742 -- Unknown, since that result will be set in any case.
10744 elsif Default /= Unknown
10745 and then (Has_Size_Clause (Etype (Expr))
10747 Has_Alignment_Clause (Etype (Expr)))
10749 Set_Result (Unknown);
10751 -- If no indication found, set default
10754 Set_Result (Default);
10757 -- Return worst result found
10760 end Has_Compatible_Alignment_Internal;
10762 -- Start of processing for Has_Compatible_Alignment
10765 -- If Obj has no specified alignment, then set alignment from the type
10766 -- alignment. Perhaps we should always do this, but for sure we should
10767 -- do it when there is an address clause since we can do more if the
10768 -- alignment is known.
10770 if Unknown_Alignment (Obj) then
10771 Set_Alignment (Obj, Alignment (Etype (Obj)));
10774 -- Now do the internal call that does all the work
10777 Has_Compatible_Alignment_Internal (Obj, Expr, Layout_Done, Unknown);
10778 end Has_Compatible_Alignment;
10780 ----------------------
10781 -- Has_Declarations --
10782 ----------------------
10784 function Has_Declarations (N : Node_Id) return Boolean is
10786 return Nkind_In (Nkind (N), N_Accept_Statement,
10788 N_Compilation_Unit_Aux,
10794 N_Package_Specification);
10795 end Has_Declarations;
10797 ---------------------------------
10798 -- Has_Defaulted_Discriminants --
10799 ---------------------------------
10801 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
10803 return Has_Discriminants (Typ)
10804 and then Present (First_Discriminant (Typ))
10805 and then Present (Discriminant_Default_Value
10806 (First_Discriminant (Typ)));
10807 end Has_Defaulted_Discriminants;
10809 -------------------
10810 -- Has_Denormals --
10811 -------------------
10813 function Has_Denormals (E : Entity_Id) return Boolean is
10815 return Is_Floating_Point_Type (E) and then Denorm_On_Target;
10818 -------------------------------------------
10819 -- Has_Discriminant_Dependent_Constraint --
10820 -------------------------------------------
10822 function Has_Discriminant_Dependent_Constraint
10823 (Comp : Entity_Id) return Boolean
10825 Comp_Decl : constant Node_Id := Parent (Comp);
10826 Subt_Indic : Node_Id;
10831 -- Discriminants can't depend on discriminants
10833 if Ekind (Comp) = E_Discriminant then
10837 Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl));
10839 if Nkind (Subt_Indic) = N_Subtype_Indication then
10840 Constr := Constraint (Subt_Indic);
10842 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
10843 Assn := First (Constraints (Constr));
10844 while Present (Assn) loop
10845 case Nkind (Assn) is
10848 | N_Subtype_Indication
10850 if Depends_On_Discriminant (Assn) then
10854 when N_Discriminant_Association =>
10855 if Depends_On_Discriminant (Expression (Assn)) then
10870 end Has_Discriminant_Dependent_Constraint;
10872 --------------------------------------
10873 -- Has_Effectively_Volatile_Profile --
10874 --------------------------------------
10876 function Has_Effectively_Volatile_Profile
10877 (Subp_Id : Entity_Id) return Boolean
10879 Formal : Entity_Id;
10882 -- Inspect the formal parameters looking for an effectively volatile
10885 Formal := First_Formal (Subp_Id);
10886 while Present (Formal) loop
10887 if Is_Effectively_Volatile (Etype (Formal)) then
10891 Next_Formal (Formal);
10894 -- Inspect the return type of functions
10896 if Ekind_In (Subp_Id, E_Function, E_Generic_Function)
10897 and then Is_Effectively_Volatile (Etype (Subp_Id))
10903 end Has_Effectively_Volatile_Profile;
10905 --------------------------
10906 -- Has_Enabled_Property --
10907 --------------------------
10909 function Has_Enabled_Property
10910 (Item_Id : Entity_Id;
10911 Property : Name_Id) return Boolean
10913 function Protected_Object_Has_Enabled_Property return Boolean;
10914 -- Determine whether a protected object denoted by Item_Id has the
10915 -- property enabled.
10917 function State_Has_Enabled_Property return Boolean;
10918 -- Determine whether a state denoted by Item_Id has the property enabled
10920 function Variable_Has_Enabled_Property return Boolean;
10921 -- Determine whether a variable denoted by Item_Id has the property
10924 -------------------------------------------
10925 -- Protected_Object_Has_Enabled_Property --
10926 -------------------------------------------
10928 function Protected_Object_Has_Enabled_Property return Boolean is
10929 Constits : constant Elist_Id := Part_Of_Constituents (Item_Id);
10930 Constit_Elmt : Elmt_Id;
10931 Constit_Id : Entity_Id;
10934 -- Protected objects always have the properties Async_Readers and
10935 -- Async_Writers (SPARK RM 7.1.2(16)).
10937 if Property = Name_Async_Readers
10938 or else Property = Name_Async_Writers
10942 -- Protected objects that have Part_Of components also inherit their
10943 -- properties Effective_Reads and Effective_Writes
10944 -- (SPARK RM 7.1.2(16)).
10946 elsif Present (Constits) then
10947 Constit_Elmt := First_Elmt (Constits);
10948 while Present (Constit_Elmt) loop
10949 Constit_Id := Node (Constit_Elmt);
10951 if Has_Enabled_Property (Constit_Id, Property) then
10955 Next_Elmt (Constit_Elmt);
10960 end Protected_Object_Has_Enabled_Property;
10962 --------------------------------
10963 -- State_Has_Enabled_Property --
10964 --------------------------------
10966 function State_Has_Enabled_Property return Boolean is
10967 Decl : constant Node_Id := Parent (Item_Id);
10969 procedure Find_Simple_Properties
10970 (Has_External : out Boolean;
10971 Has_Synchronous : out Boolean);
10972 -- Extract the simple properties associated with declaration Decl
10974 function Is_Enabled_External_Property return Boolean;
10975 -- Determine whether property Property appears within the external
10976 -- property list of declaration Decl, and return its status.
10978 ----------------------------
10979 -- Find_Simple_Properties --
10980 ----------------------------
10982 procedure Find_Simple_Properties
10983 (Has_External : out Boolean;
10984 Has_Synchronous : out Boolean)
10989 -- Assume that none of the properties are available
10991 Has_External := False;
10992 Has_Synchronous := False;
10994 Opt := First (Expressions (Decl));
10995 while Present (Opt) loop
10996 if Nkind (Opt) = N_Identifier then
10997 if Chars (Opt) = Name_External then
10998 Has_External := True;
11000 elsif Chars (Opt) = Name_Synchronous then
11001 Has_Synchronous := True;
11007 end Find_Simple_Properties;
11009 ----------------------------------
11010 -- Is_Enabled_External_Property --
11011 ----------------------------------
11013 function Is_Enabled_External_Property return Boolean is
11017 Prop_Nam : Node_Id;
11021 Opt := First (Component_Associations (Decl));
11022 while Present (Opt) loop
11023 Opt_Nam := First (Choices (Opt));
11025 if Nkind (Opt_Nam) = N_Identifier
11026 and then Chars (Opt_Nam) = Name_External
11028 Props := Expression (Opt);
11030 -- Multiple properties appear as an aggregate
11032 if Nkind (Props) = N_Aggregate then
11034 -- Simple property form
11036 Prop := First (Expressions (Props));
11037 while Present (Prop) loop
11038 if Chars (Prop) = Property then
11045 -- Property with expression form
11047 Prop := First (Component_Associations (Props));
11048 while Present (Prop) loop
11049 Prop_Nam := First (Choices (Prop));
11051 -- The property can be represented in two ways:
11052 -- others => <value>
11053 -- <property> => <value>
11055 if Nkind (Prop_Nam) = N_Others_Choice
11056 or else (Nkind (Prop_Nam) = N_Identifier
11057 and then Chars (Prop_Nam) = Property)
11059 return Is_True (Expr_Value (Expression (Prop)));
11068 return Chars (Props) = Property;
11076 end Is_Enabled_External_Property;
11080 Has_External : Boolean;
11081 Has_Synchronous : Boolean;
11083 -- Start of processing for State_Has_Enabled_Property
11086 -- The declaration of an external abstract state appears as an
11087 -- extension aggregate. If this is not the case, properties can
11090 if Nkind (Decl) /= N_Extension_Aggregate then
11094 Find_Simple_Properties (Has_External, Has_Synchronous);
11096 -- Simple option External enables all properties (SPARK RM 7.1.2(2))
11098 if Has_External then
11101 -- Option External may enable or disable specific properties
11103 elsif Is_Enabled_External_Property then
11106 -- Simple option Synchronous
11108 -- enables disables
11109 -- Async_Readers Effective_Reads
11110 -- Async_Writers Effective_Writes
11112 -- Note that both forms of External have higher precedence than
11113 -- Synchronous (SPARK RM 7.1.4(9)).
11115 elsif Has_Synchronous then
11116 return Nam_In (Property, Name_Async_Readers, Name_Async_Writers);
11120 end State_Has_Enabled_Property;
11122 -----------------------------------
11123 -- Variable_Has_Enabled_Property --
11124 -----------------------------------
11126 function Variable_Has_Enabled_Property return Boolean is
11127 function Is_Enabled (Prag : Node_Id) return Boolean;
11128 -- Determine whether property pragma Prag (if present) denotes an
11129 -- enabled property.
11135 function Is_Enabled (Prag : Node_Id) return Boolean is
11139 if Present (Prag) then
11140 Arg1 := First (Pragma_Argument_Associations (Prag));
11142 -- The pragma has an optional Boolean expression, the related
11143 -- property is enabled only when the expression evaluates to
11146 if Present (Arg1) then
11147 return Is_True (Expr_Value (Get_Pragma_Arg (Arg1)));
11149 -- Otherwise the lack of expression enables the property by
11156 -- The property was never set in the first place
11165 AR : constant Node_Id :=
11166 Get_Pragma (Item_Id, Pragma_Async_Readers);
11167 AW : constant Node_Id :=
11168 Get_Pragma (Item_Id, Pragma_Async_Writers);
11169 ER : constant Node_Id :=
11170 Get_Pragma (Item_Id, Pragma_Effective_Reads);
11171 EW : constant Node_Id :=
11172 Get_Pragma (Item_Id, Pragma_Effective_Writes);
11174 -- Start of processing for Variable_Has_Enabled_Property
11177 -- A non-effectively volatile object can never possess external
11180 if not Is_Effectively_Volatile (Item_Id) then
11183 -- External properties related to variables come in two flavors -
11184 -- explicit and implicit. The explicit case is characterized by the
11185 -- presence of a property pragma with an optional Boolean flag. The
11186 -- property is enabled when the flag evaluates to True or the flag is
11187 -- missing altogether.
11189 elsif Property = Name_Async_Readers and then Is_Enabled (AR) then
11192 elsif Property = Name_Async_Writers and then Is_Enabled (AW) then
11195 elsif Property = Name_Effective_Reads and then Is_Enabled (ER) then
11198 elsif Property = Name_Effective_Writes and then Is_Enabled (EW) then
11201 -- The implicit case lacks all property pragmas
11203 elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then
11204 if Is_Protected_Type (Etype (Item_Id)) then
11205 return Protected_Object_Has_Enabled_Property;
11213 end Variable_Has_Enabled_Property;
11215 -- Start of processing for Has_Enabled_Property
11218 -- Abstract states and variables have a flexible scheme of specifying
11219 -- external properties.
11221 if Ekind (Item_Id) = E_Abstract_State then
11222 return State_Has_Enabled_Property;
11224 elsif Ekind (Item_Id) = E_Variable then
11225 return Variable_Has_Enabled_Property;
11227 -- By default, protected objects only have the properties Async_Readers
11228 -- and Async_Writers. If they have Part_Of components, they also inherit
11229 -- their properties Effective_Reads and Effective_Writes
11230 -- (SPARK RM 7.1.2(16)).
11232 elsif Ekind (Item_Id) = E_Protected_Object then
11233 return Protected_Object_Has_Enabled_Property;
11235 -- Otherwise a property is enabled when the related item is effectively
11239 return Is_Effectively_Volatile (Item_Id);
11241 end Has_Enabled_Property;
11243 -------------------------------------
11244 -- Has_Full_Default_Initialization --
11245 -------------------------------------
11247 function Has_Full_Default_Initialization (Typ : Entity_Id) return Boolean is
11251 -- A type subject to pragma Default_Initial_Condition may be fully
11252 -- default initialized depending on inheritance and the argument of
11253 -- the pragma. Since any type may act as the full view of a private
11254 -- type, this check must be performed prior to the specialized tests
11257 if Has_Fully_Default_Initializing_DIC_Pragma (Typ) then
11261 -- A scalar type is fully default initialized if it is subject to aspect
11264 if Is_Scalar_Type (Typ) then
11265 return Has_Default_Aspect (Typ);
11267 -- An access type is fully default initialized by default
11269 elsif Is_Access_Type (Typ) then
11272 -- An array type is fully default initialized if its element type is
11273 -- scalar and the array type carries aspect Default_Component_Value or
11274 -- the element type is fully default initialized.
11276 elsif Is_Array_Type (Typ) then
11278 Has_Default_Aspect (Typ)
11279 or else Has_Full_Default_Initialization (Component_Type (Typ));
11281 -- A protected type, record type, or type extension is fully default
11282 -- initialized if all its components either carry an initialization
11283 -- expression or have a type that is fully default initialized. The
11284 -- parent type of a type extension must be fully default initialized.
11286 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
11288 -- Inspect all entities defined in the scope of the type, looking for
11289 -- uninitialized components.
11291 Comp := First_Entity (Typ);
11292 while Present (Comp) loop
11293 if Ekind (Comp) = E_Component
11294 and then Comes_From_Source (Comp)
11295 and then No (Expression (Parent (Comp)))
11296 and then not Has_Full_Default_Initialization (Etype (Comp))
11301 Next_Entity (Comp);
11304 -- Ensure that the parent type of a type extension is fully default
11307 if Etype (Typ) /= Typ
11308 and then not Has_Full_Default_Initialization (Etype (Typ))
11313 -- If we get here, then all components and parent portion are fully
11314 -- default initialized.
11318 -- A task type is fully default initialized by default
11320 elsif Is_Task_Type (Typ) then
11323 -- Otherwise the type is not fully default initialized
11328 end Has_Full_Default_Initialization;
11330 -----------------------------------------------
11331 -- Has_Fully_Default_Initializing_DIC_Pragma --
11332 -----------------------------------------------
11334 function Has_Fully_Default_Initializing_DIC_Pragma
11335 (Typ : Entity_Id) return Boolean
11341 -- A type that inherits pragma Default_Initial_Condition from a parent
11342 -- type is automatically fully default initialized.
11344 if Has_Inherited_DIC (Typ) then
11347 -- Otherwise the type is fully default initialized only when the pragma
11348 -- appears without an argument, or the argument is non-null.
11350 elsif Has_Own_DIC (Typ) then
11351 Prag := Get_Pragma (Typ, Pragma_Default_Initial_Condition);
11352 pragma Assert (Present (Prag));
11353 Args := Pragma_Argument_Associations (Prag);
11355 -- The pragma appears without an argument in which case it defaults
11361 -- The pragma appears with a non-null expression
11363 elsif Nkind (Get_Pragma_Arg (First (Args))) /= N_Null then
11369 end Has_Fully_Default_Initializing_DIC_Pragma;
11371 --------------------
11372 -- Has_Infinities --
11373 --------------------
11375 function Has_Infinities (E : Entity_Id) return Boolean is
11378 Is_Floating_Point_Type (E)
11379 and then Nkind (Scalar_Range (E)) = N_Range
11380 and then Includes_Infinities (Scalar_Range (E));
11381 end Has_Infinities;
11383 --------------------
11384 -- Has_Interfaces --
11385 --------------------
11387 function Has_Interfaces
11389 Use_Full_View : Boolean := True) return Boolean
11391 Typ : Entity_Id := Base_Type (T);
11394 -- Handle concurrent types
11396 if Is_Concurrent_Type (Typ) then
11397 Typ := Corresponding_Record_Type (Typ);
11400 if not Present (Typ)
11401 or else not Is_Record_Type (Typ)
11402 or else not Is_Tagged_Type (Typ)
11407 -- Handle private types
11409 if Use_Full_View and then Present (Full_View (Typ)) then
11410 Typ := Full_View (Typ);
11413 -- Handle concurrent record types
11415 if Is_Concurrent_Record_Type (Typ)
11416 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
11422 if Is_Interface (Typ)
11424 (Is_Record_Type (Typ)
11425 and then Present (Interfaces (Typ))
11426 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
11431 exit when Etype (Typ) = Typ
11433 -- Handle private types
11435 or else (Present (Full_View (Etype (Typ)))
11436 and then Full_View (Etype (Typ)) = Typ)
11438 -- Protect frontend against wrong sources with cyclic derivations
11440 or else Etype (Typ) = T;
11442 -- Climb to the ancestor type handling private types
11444 if Present (Full_View (Etype (Typ))) then
11445 Typ := Full_View (Etype (Typ));
11447 Typ := Etype (Typ);
11452 end Has_Interfaces;
11454 --------------------------
11455 -- Has_Max_Queue_Length --
11456 --------------------------
11458 function Has_Max_Queue_Length (Id : Entity_Id) return Boolean is
11461 Ekind (Id) = E_Entry
11462 and then Present (Get_Pragma (Id, Pragma_Max_Queue_Length));
11463 end Has_Max_Queue_Length;
11465 ---------------------------------
11466 -- Has_No_Obvious_Side_Effects --
11467 ---------------------------------
11469 function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
11471 -- For now handle literals, constants, and non-volatile variables and
11472 -- expressions combining these with operators or short circuit forms.
11474 if Nkind (N) in N_Numeric_Or_String_Literal then
11477 elsif Nkind (N) = N_Character_Literal then
11480 elsif Nkind (N) in N_Unary_Op then
11481 return Has_No_Obvious_Side_Effects (Right_Opnd (N));
11483 elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
11484 return Has_No_Obvious_Side_Effects (Left_Opnd (N))
11486 Has_No_Obvious_Side_Effects (Right_Opnd (N));
11488 elsif Nkind (N) = N_Expression_With_Actions
11489 and then Is_Empty_List (Actions (N))
11491 return Has_No_Obvious_Side_Effects (Expression (N));
11493 elsif Nkind (N) in N_Has_Entity then
11494 return Present (Entity (N))
11495 and then Ekind_In (Entity (N), E_Variable,
11497 E_Enumeration_Literal,
11500 E_In_Out_Parameter)
11501 and then not Is_Volatile (Entity (N));
11506 end Has_No_Obvious_Side_Effects;
11508 -----------------------------
11509 -- Has_Non_Null_Refinement --
11510 -----------------------------
11512 function Has_Non_Null_Refinement (Id : Entity_Id) return Boolean is
11513 Constits : Elist_Id;
11516 pragma Assert (Ekind (Id) = E_Abstract_State);
11517 Constits := Refinement_Constituents (Id);
11519 -- For a refinement to be non-null, the first constituent must be
11520 -- anything other than null.
11524 and then Nkind (Node (First_Elmt (Constits))) /= N_Null;
11525 end Has_Non_Null_Refinement;
11527 -----------------------------
11528 -- Has_Non_Null_Statements --
11529 -----------------------------
11531 function Has_Non_Null_Statements (L : List_Id) return Boolean is
11535 if Is_Non_Empty_List (L) then
11539 if Nkind (Node) /= N_Null_Statement then
11544 exit when Node = Empty;
11549 end Has_Non_Null_Statements;
11551 ----------------------------------
11552 -- Has_Non_Trivial_Precondition --
11553 ----------------------------------
11555 function Has_Non_Trivial_Precondition (Subp : Entity_Id) return Boolean is
11556 Pre : constant Node_Id := Find_Aspect (Subp, Aspect_Pre);
11561 and then Class_Present (Pre)
11562 and then not Is_Entity_Name (Expression (Pre));
11563 end Has_Non_Trivial_Precondition;
11565 -------------------
11566 -- Has_Null_Body --
11567 -------------------
11569 function Has_Null_Body (Proc_Id : Entity_Id) return Boolean is
11570 Body_Id : Entity_Id;
11577 Spec := Parent (Proc_Id);
11578 Decl := Parent (Spec);
11580 -- Retrieve the entity of the procedure body (e.g. invariant proc).
11582 if Nkind (Spec) = N_Procedure_Specification
11583 and then Nkind (Decl) = N_Subprogram_Declaration
11585 Body_Id := Corresponding_Body (Decl);
11587 -- The body acts as a spec
11590 Body_Id := Proc_Id;
11593 -- The body will be generated later
11595 if No (Body_Id) then
11599 Spec := Parent (Body_Id);
11600 Decl := Parent (Spec);
11603 (Nkind (Spec) = N_Procedure_Specification
11604 and then Nkind (Decl) = N_Subprogram_Body);
11606 Stmt1 := First (Statements (Handled_Statement_Sequence (Decl)));
11608 -- Look for a null statement followed by an optional return
11611 if Nkind (Stmt1) = N_Null_Statement then
11612 Stmt2 := Next (Stmt1);
11614 if Present (Stmt2) then
11615 return Nkind (Stmt2) = N_Simple_Return_Statement;
11624 ------------------------
11625 -- Has_Null_Exclusion --
11626 ------------------------
11628 function Has_Null_Exclusion (N : Node_Id) return Boolean is
11631 when N_Access_Definition
11632 | N_Access_Function_Definition
11633 | N_Access_Procedure_Definition
11634 | N_Access_To_Object_Definition
11636 | N_Derived_Type_Definition
11637 | N_Function_Specification
11638 | N_Subtype_Declaration
11640 return Null_Exclusion_Present (N);
11642 when N_Component_Definition
11643 | N_Formal_Object_Declaration
11644 | N_Object_Renaming_Declaration
11646 if Present (Subtype_Mark (N)) then
11647 return Null_Exclusion_Present (N);
11648 else pragma Assert (Present (Access_Definition (N)));
11649 return Null_Exclusion_Present (Access_Definition (N));
11652 when N_Discriminant_Specification =>
11653 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
11654 return Null_Exclusion_Present (Discriminant_Type (N));
11656 return Null_Exclusion_Present (N);
11659 when N_Object_Declaration =>
11660 if Nkind (Object_Definition (N)) = N_Access_Definition then
11661 return Null_Exclusion_Present (Object_Definition (N));
11663 return Null_Exclusion_Present (N);
11666 when N_Parameter_Specification =>
11667 if Nkind (Parameter_Type (N)) = N_Access_Definition then
11668 return Null_Exclusion_Present (Parameter_Type (N));
11670 return Null_Exclusion_Present (N);
11676 end Has_Null_Exclusion;
11678 ------------------------
11679 -- Has_Null_Extension --
11680 ------------------------
11682 function Has_Null_Extension (T : Entity_Id) return Boolean is
11683 B : constant Entity_Id := Base_Type (T);
11688 if Nkind (Parent (B)) = N_Full_Type_Declaration
11689 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
11691 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
11693 if Present (Ext) then
11694 if Null_Present (Ext) then
11697 Comps := Component_List (Ext);
11699 -- The null component list is rewritten during analysis to
11700 -- include the parent component. Any other component indicates
11701 -- that the extension was not originally null.
11703 return Null_Present (Comps)
11704 or else No (Next (First (Component_Items (Comps))));
11713 end Has_Null_Extension;
11715 -------------------------
11716 -- Has_Null_Refinement --
11717 -------------------------
11719 function Has_Null_Refinement (Id : Entity_Id) return Boolean is
11720 Constits : Elist_Id;
11723 pragma Assert (Ekind (Id) = E_Abstract_State);
11724 Constits := Refinement_Constituents (Id);
11726 -- For a refinement to be null, the state's sole constituent must be a
11731 and then Nkind (Node (First_Elmt (Constits))) = N_Null;
11732 end Has_Null_Refinement;
11734 -------------------------------
11735 -- Has_Overriding_Initialize --
11736 -------------------------------
11738 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
11739 BT : constant Entity_Id := Base_Type (T);
11743 if Is_Controlled (BT) then
11744 if Is_RTU (Scope (BT), Ada_Finalization) then
11747 elsif Present (Primitive_Operations (BT)) then
11748 P := First_Elmt (Primitive_Operations (BT));
11749 while Present (P) loop
11751 Init : constant Entity_Id := Node (P);
11752 Formal : constant Entity_Id := First_Formal (Init);
11754 if Ekind (Init) = E_Procedure
11755 and then Chars (Init) = Name_Initialize
11756 and then Comes_From_Source (Init)
11757 and then Present (Formal)
11758 and then Etype (Formal) = BT
11759 and then No (Next_Formal (Formal))
11760 and then (Ada_Version < Ada_2012
11761 or else not Null_Present (Parent (Init)))
11771 -- Here if type itself does not have a non-null Initialize operation:
11772 -- check immediate ancestor.
11774 if Is_Derived_Type (BT)
11775 and then Has_Overriding_Initialize (Etype (BT))
11782 end Has_Overriding_Initialize;
11784 --------------------------------------
11785 -- Has_Preelaborable_Initialization --
11786 --------------------------------------
11788 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
11791 procedure Check_Components (E : Entity_Id);
11792 -- Check component/discriminant chain, sets Has_PE False if a component
11793 -- or discriminant does not meet the preelaborable initialization rules.
11795 ----------------------
11796 -- Check_Components --
11797 ----------------------
11799 procedure Check_Components (E : Entity_Id) is
11804 -- Loop through entities of record or protected type
11807 while Present (Ent) loop
11809 -- We are interested only in components and discriminants
11813 case Ekind (Ent) is
11814 when E_Component =>
11816 -- Get default expression if any. If there is no declaration
11817 -- node, it means we have an internal entity. The parent and
11818 -- tag fields are examples of such entities. For such cases,
11819 -- we just test the type of the entity.
11821 if Present (Declaration_Node (Ent)) then
11822 Exp := Expression (Declaration_Node (Ent));
11825 when E_Discriminant =>
11827 -- Note: for a renamed discriminant, the Declaration_Node
11828 -- may point to the one from the ancestor, and have a
11829 -- different expression, so use the proper attribute to
11830 -- retrieve the expression from the derived constraint.
11832 Exp := Discriminant_Default_Value (Ent);
11835 goto Check_Next_Entity;
11838 -- A component has PI if it has no default expression and the
11839 -- component type has PI.
11842 if not Has_Preelaborable_Initialization (Etype (Ent)) then
11847 -- Require the default expression to be preelaborable
11849 elsif not Is_Preelaborable_Construct (Exp) then
11854 <<Check_Next_Entity>>
11857 end Check_Components;
11859 -- Start of processing for Has_Preelaborable_Initialization
11862 -- Immediate return if already marked as known preelaborable init. This
11863 -- covers types for which this function has already been called once
11864 -- and returned True (in which case the result is cached), and also
11865 -- types to which a pragma Preelaborable_Initialization applies.
11867 if Known_To_Have_Preelab_Init (E) then
11871 -- If the type is a subtype representing a generic actual type, then
11872 -- test whether its base type has preelaborable initialization since
11873 -- the subtype representing the actual does not inherit this attribute
11874 -- from the actual or formal. (but maybe it should???)
11876 if Is_Generic_Actual_Type (E) then
11877 return Has_Preelaborable_Initialization (Base_Type (E));
11880 -- All elementary types have preelaborable initialization
11882 if Is_Elementary_Type (E) then
11885 -- Array types have PI if the component type has PI
11887 elsif Is_Array_Type (E) then
11888 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
11890 -- A derived type has preelaborable initialization if its parent type
11891 -- has preelaborable initialization and (in the case of a derived record
11892 -- extension) if the non-inherited components all have preelaborable
11893 -- initialization. However, a user-defined controlled type with an
11894 -- overriding Initialize procedure does not have preelaborable
11897 elsif Is_Derived_Type (E) then
11899 -- If the derived type is a private extension then it doesn't have
11900 -- preelaborable initialization.
11902 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
11906 -- First check whether ancestor type has preelaborable initialization
11908 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
11910 -- If OK, check extension components (if any)
11912 if Has_PE and then Is_Record_Type (E) then
11913 Check_Components (First_Entity (E));
11916 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
11917 -- with a user defined Initialize procedure does not have PI. If
11918 -- the type is untagged, the control primitives come from a component
11919 -- that has already been checked.
11922 and then Is_Controlled (E)
11923 and then Is_Tagged_Type (E)
11924 and then Has_Overriding_Initialize (E)
11929 -- Private types not derived from a type having preelaborable init and
11930 -- that are not marked with pragma Preelaborable_Initialization do not
11931 -- have preelaborable initialization.
11933 elsif Is_Private_Type (E) then
11936 -- Record type has PI if it is non private and all components have PI
11938 elsif Is_Record_Type (E) then
11940 Check_Components (First_Entity (E));
11942 -- Protected types must not have entries, and components must meet
11943 -- same set of rules as for record components.
11945 elsif Is_Protected_Type (E) then
11946 if Has_Entries (E) then
11950 Check_Components (First_Entity (E));
11951 Check_Components (First_Private_Entity (E));
11954 -- Type System.Address always has preelaborable initialization
11956 elsif Is_RTE (E, RE_Address) then
11959 -- In all other cases, type does not have preelaborable initialization
11965 -- If type has preelaborable initialization, cache result
11968 Set_Known_To_Have_Preelab_Init (E);
11972 end Has_Preelaborable_Initialization;
11978 function Has_Prefix (N : Node_Id) return Boolean is
11981 Nkind_In (N, N_Attribute_Reference,
11983 N_Explicit_Dereference,
11984 N_Indexed_Component,
11986 N_Selected_Component,
11990 ---------------------------
11991 -- Has_Private_Component --
11992 ---------------------------
11994 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
11995 Btype : Entity_Id := Base_Type (Type_Id);
11996 Component : Entity_Id;
11999 if Error_Posted (Type_Id)
12000 or else Error_Posted (Btype)
12005 if Is_Class_Wide_Type (Btype) then
12006 Btype := Root_Type (Btype);
12009 if Is_Private_Type (Btype) then
12011 UT : constant Entity_Id := Underlying_Type (Btype);
12014 if No (Full_View (Btype)) then
12015 return not Is_Generic_Type (Btype)
12017 not Is_Generic_Type (Root_Type (Btype));
12019 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
12022 return not Is_Frozen (UT) and then Has_Private_Component (UT);
12026 elsif Is_Array_Type (Btype) then
12027 return Has_Private_Component (Component_Type (Btype));
12029 elsif Is_Record_Type (Btype) then
12030 Component := First_Component (Btype);
12031 while Present (Component) loop
12032 if Has_Private_Component (Etype (Component)) then
12036 Next_Component (Component);
12041 elsif Is_Protected_Type (Btype)
12042 and then Present (Corresponding_Record_Type (Btype))
12044 return Has_Private_Component (Corresponding_Record_Type (Btype));
12049 end Has_Private_Component;
12051 ----------------------
12052 -- Has_Signed_Zeros --
12053 ----------------------
12055 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
12057 return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target;
12058 end Has_Signed_Zeros;
12060 ------------------------------
12061 -- Has_Significant_Contract --
12062 ------------------------------
12064 function Has_Significant_Contract (Subp_Id : Entity_Id) return Boolean is
12065 Subp_Nam : constant Name_Id := Chars (Subp_Id);
12068 -- _Finalizer procedure
12070 if Subp_Nam = Name_uFinalizer then
12073 -- _Postconditions procedure
12075 elsif Subp_Nam = Name_uPostconditions then
12078 -- Predicate function
12080 elsif Ekind (Subp_Id) = E_Function
12081 and then Is_Predicate_Function (Subp_Id)
12087 elsif Get_TSS_Name (Subp_Id) /= TSS_Null then
12093 end Has_Significant_Contract;
12095 -----------------------------
12096 -- Has_Static_Array_Bounds --
12097 -----------------------------
12099 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
12100 All_Static : Boolean;
12104 Examine_Array_Bounds (Typ, All_Static, Dummy);
12107 end Has_Static_Array_Bounds;
12109 ---------------------------------------
12110 -- Has_Static_Non_Empty_Array_Bounds --
12111 ---------------------------------------
12113 function Has_Static_Non_Empty_Array_Bounds (Typ : Node_Id) return Boolean is
12114 All_Static : Boolean;
12115 Has_Empty : Boolean;
12118 Examine_Array_Bounds (Typ, All_Static, Has_Empty);
12120 return All_Static and not Has_Empty;
12121 end Has_Static_Non_Empty_Array_Bounds;
12127 function Has_Stream (T : Entity_Id) return Boolean is
12134 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
12137 elsif Is_Array_Type (T) then
12138 return Has_Stream (Component_Type (T));
12140 elsif Is_Record_Type (T) then
12141 E := First_Component (T);
12142 while Present (E) loop
12143 if Has_Stream (Etype (E)) then
12146 Next_Component (E);
12152 elsif Is_Private_Type (T) then
12153 return Has_Stream (Underlying_Type (T));
12164 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
12166 Get_Name_String (Chars (E));
12167 return Name_Buffer (Name_Len) = Suffix;
12174 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
12176 Get_Name_String (Chars (E));
12177 Add_Char_To_Name_Buffer (Suffix);
12181 -------------------
12182 -- Remove_Suffix --
12183 -------------------
12185 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
12187 pragma Assert (Has_Suffix (E, Suffix));
12188 Get_Name_String (Chars (E));
12189 Name_Len := Name_Len - 1;
12193 ----------------------------------
12194 -- Replace_Null_By_Null_Address --
12195 ----------------------------------
12197 procedure Replace_Null_By_Null_Address (N : Node_Id) is
12198 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id);
12199 -- Replace operand Op with a reference to Null_Address when the operand
12200 -- denotes a null Address. Other_Op denotes the other operand.
12202 --------------------------
12203 -- Replace_Null_Operand --
12204 --------------------------
12206 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id) is
12208 -- Check the type of the complementary operand since the N_Null node
12209 -- has not been decorated yet.
12211 if Nkind (Op) = N_Null
12212 and then Is_Descendant_Of_Address (Etype (Other_Op))
12214 Rewrite (Op, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (Op)));
12216 end Replace_Null_Operand;
12218 -- Start of processing for Replace_Null_By_Null_Address
12221 pragma Assert (Relaxed_RM_Semantics);
12222 pragma Assert (Nkind_In (N, N_Null,
12230 if Nkind (N) = N_Null then
12231 Rewrite (N, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (N)));
12235 L : constant Node_Id := Left_Opnd (N);
12236 R : constant Node_Id := Right_Opnd (N);
12239 Replace_Null_Operand (L, Other_Op => R);
12240 Replace_Null_Operand (R, Other_Op => L);
12243 end Replace_Null_By_Null_Address;
12245 --------------------------
12246 -- Has_Tagged_Component --
12247 --------------------------
12249 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
12253 if Is_Private_Type (Typ) and then Present (Underlying_Type (Typ)) then
12254 return Has_Tagged_Component (Underlying_Type (Typ));
12256 elsif Is_Array_Type (Typ) then
12257 return Has_Tagged_Component (Component_Type (Typ));
12259 elsif Is_Tagged_Type (Typ) then
12262 elsif Is_Record_Type (Typ) then
12263 Comp := First_Component (Typ);
12264 while Present (Comp) loop
12265 if Has_Tagged_Component (Etype (Comp)) then
12269 Next_Component (Comp);
12277 end Has_Tagged_Component;
12279 -----------------------------
12280 -- Has_Undefined_Reference --
12281 -----------------------------
12283 function Has_Undefined_Reference (Expr : Node_Id) return Boolean is
12284 Has_Undef_Ref : Boolean := False;
12285 -- Flag set when expression Expr contains at least one undefined
12288 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result;
12289 -- Determine whether N denotes a reference and if it does, whether it is
12292 ----------------------------
12293 -- Is_Undefined_Reference --
12294 ----------------------------
12296 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result is
12298 if Is_Entity_Name (N)
12299 and then Present (Entity (N))
12300 and then Entity (N) = Any_Id
12302 Has_Undef_Ref := True;
12307 end Is_Undefined_Reference;
12309 procedure Find_Undefined_References is
12310 new Traverse_Proc (Is_Undefined_Reference);
12312 -- Start of processing for Has_Undefined_Reference
12315 Find_Undefined_References (Expr);
12317 return Has_Undef_Ref;
12318 end Has_Undefined_Reference;
12320 ----------------------------
12321 -- Has_Volatile_Component --
12322 ----------------------------
12324 function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
12328 if Has_Volatile_Components (Typ) then
12331 elsif Is_Array_Type (Typ) then
12332 return Is_Volatile (Component_Type (Typ));
12334 elsif Is_Record_Type (Typ) then
12335 Comp := First_Component (Typ);
12336 while Present (Comp) loop
12337 if Is_Volatile_Object (Comp) then
12341 Next_Component (Comp);
12346 end Has_Volatile_Component;
12348 -------------------------
12349 -- Implementation_Kind --
12350 -------------------------
12352 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
12353 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
12356 pragma Assert (Present (Impl_Prag));
12357 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
12358 return Chars (Get_Pragma_Arg (Arg));
12359 end Implementation_Kind;
12361 --------------------------
12362 -- Implements_Interface --
12363 --------------------------
12365 function Implements_Interface
12366 (Typ_Ent : Entity_Id;
12367 Iface_Ent : Entity_Id;
12368 Exclude_Parents : Boolean := False) return Boolean
12370 Ifaces_List : Elist_Id;
12372 Iface : Entity_Id := Base_Type (Iface_Ent);
12373 Typ : Entity_Id := Base_Type (Typ_Ent);
12376 if Is_Class_Wide_Type (Typ) then
12377 Typ := Root_Type (Typ);
12380 if not Has_Interfaces (Typ) then
12384 if Is_Class_Wide_Type (Iface) then
12385 Iface := Root_Type (Iface);
12388 Collect_Interfaces (Typ, Ifaces_List);
12390 Elmt := First_Elmt (Ifaces_List);
12391 while Present (Elmt) loop
12392 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
12393 and then Exclude_Parents
12397 elsif Node (Elmt) = Iface then
12405 end Implements_Interface;
12407 ------------------------------------
12408 -- In_Assertion_Expression_Pragma --
12409 ------------------------------------
12411 function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is
12413 Prag : Node_Id := Empty;
12416 -- Climb the parent chain looking for an enclosing pragma
12419 while Present (Par) loop
12420 if Nkind (Par) = N_Pragma then
12424 -- Precondition-like pragmas are expanded into if statements, check
12425 -- the original node instead.
12427 elsif Nkind (Original_Node (Par)) = N_Pragma then
12428 Prag := Original_Node (Par);
12431 -- The expansion of attribute 'Old generates a constant to capture
12432 -- the result of the prefix. If the parent traversal reaches
12433 -- one of these constants, then the node technically came from a
12434 -- postcondition-like pragma. Note that the Ekind is not tested here
12435 -- because N may be the expression of an object declaration which is
12436 -- currently being analyzed. Such objects carry Ekind of E_Void.
12438 elsif Nkind (Par) = N_Object_Declaration
12439 and then Constant_Present (Par)
12440 and then Stores_Attribute_Old_Prefix (Defining_Entity (Par))
12444 -- Prevent the search from going too far
12446 elsif Is_Body_Or_Package_Declaration (Par) then
12450 Par := Parent (Par);
12455 and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag));
12456 end In_Assertion_Expression_Pragma;
12458 ----------------------
12459 -- In_Generic_Scope --
12460 ----------------------
12462 function In_Generic_Scope (E : Entity_Id) return Boolean is
12467 while Present (S) and then S /= Standard_Standard loop
12468 if Is_Generic_Unit (S) then
12476 end In_Generic_Scope;
12482 function In_Instance return Boolean is
12483 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
12487 S := Current_Scope;
12488 while Present (S) and then S /= Standard_Standard loop
12489 if Is_Generic_Instance (S) then
12491 -- A child instance is always compiled in the context of a parent
12492 -- instance. Nevertheless, its actuals must not be analyzed in an
12493 -- instance context. We detect this case by examining the current
12494 -- compilation unit, which must be a child instance, and checking
12495 -- that it has not been analyzed yet.
12497 if Is_Child_Unit (Curr_Unit)
12498 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
12499 N_Package_Instantiation
12500 and then Ekind (Curr_Unit) = E_Void
12514 ----------------------
12515 -- In_Instance_Body --
12516 ----------------------
12518 function In_Instance_Body return Boolean is
12522 S := Current_Scope;
12523 while Present (S) and then S /= Standard_Standard loop
12524 if Ekind_In (S, E_Function, E_Procedure)
12525 and then Is_Generic_Instance (S)
12529 elsif Ekind (S) = E_Package
12530 and then In_Package_Body (S)
12531 and then Is_Generic_Instance (S)
12540 end In_Instance_Body;
12542 -----------------------------
12543 -- In_Instance_Not_Visible --
12544 -----------------------------
12546 function In_Instance_Not_Visible return Boolean is
12550 S := Current_Scope;
12551 while Present (S) and then S /= Standard_Standard loop
12552 if Ekind_In (S, E_Function, E_Procedure)
12553 and then Is_Generic_Instance (S)
12557 elsif Ekind (S) = E_Package
12558 and then (In_Package_Body (S) or else In_Private_Part (S))
12559 and then Is_Generic_Instance (S)
12568 end In_Instance_Not_Visible;
12570 ------------------------------
12571 -- In_Instance_Visible_Part --
12572 ------------------------------
12574 function In_Instance_Visible_Part
12575 (Id : Entity_Id := Current_Scope) return Boolean
12581 while Present (Inst) and then Inst /= Standard_Standard loop
12582 if Ekind (Inst) = E_Package
12583 and then Is_Generic_Instance (Inst)
12584 and then not In_Package_Body (Inst)
12585 and then not In_Private_Part (Inst)
12590 Inst := Scope (Inst);
12594 end In_Instance_Visible_Part;
12596 ---------------------
12597 -- In_Package_Body --
12598 ---------------------
12600 function In_Package_Body return Boolean is
12604 S := Current_Scope;
12605 while Present (S) and then S /= Standard_Standard loop
12606 if Ekind (S) = E_Package and then In_Package_Body (S) then
12614 end In_Package_Body;
12616 --------------------------
12617 -- In_Pragma_Expression --
12618 --------------------------
12620 function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean is
12627 elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
12633 end In_Pragma_Expression;
12635 ---------------------------
12636 -- In_Pre_Post_Condition --
12637 ---------------------------
12639 function In_Pre_Post_Condition (N : Node_Id) return Boolean is
12641 Prag : Node_Id := Empty;
12642 Prag_Id : Pragma_Id;
12645 -- Climb the parent chain looking for an enclosing pragma
12648 while Present (Par) loop
12649 if Nkind (Par) = N_Pragma then
12653 -- Prevent the search from going too far
12655 elsif Is_Body_Or_Package_Declaration (Par) then
12659 Par := Parent (Par);
12662 if Present (Prag) then
12663 Prag_Id := Get_Pragma_Id (Prag);
12666 Prag_Id = Pragma_Post
12667 or else Prag_Id = Pragma_Post_Class
12668 or else Prag_Id = Pragma_Postcondition
12669 or else Prag_Id = Pragma_Pre
12670 or else Prag_Id = Pragma_Pre_Class
12671 or else Prag_Id = Pragma_Precondition;
12673 -- Otherwise the node is not enclosed by a pre/postcondition pragma
12678 end In_Pre_Post_Condition;
12680 ------------------------------
12681 -- In_Quantified_Expression --
12682 ------------------------------
12684 function In_Quantified_Expression (N : Node_Id) return Boolean is
12691 elsif Nkind (P) = N_Quantified_Expression then
12697 end In_Quantified_Expression;
12699 -------------------------------------
12700 -- In_Reverse_Storage_Order_Object --
12701 -------------------------------------
12703 function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
12705 Btyp : Entity_Id := Empty;
12708 -- Climb up indexed components
12712 case Nkind (Pref) is
12713 when N_Selected_Component =>
12714 Pref := Prefix (Pref);
12717 when N_Indexed_Component =>
12718 Pref := Prefix (Pref);
12726 if Present (Pref) then
12727 Btyp := Base_Type (Etype (Pref));
12730 return Present (Btyp)
12731 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
12732 and then Reverse_Storage_Order (Btyp);
12733 end In_Reverse_Storage_Order_Object;
12735 ------------------------------
12736 -- In_Same_Declarative_Part --
12737 ------------------------------
12739 function In_Same_Declarative_Part
12740 (Context : Node_Id;
12741 N : Node_Id) return Boolean
12743 Cont : Node_Id := Context;
12747 if Nkind (Cont) = N_Compilation_Unit_Aux then
12748 Cont := Parent (Cont);
12752 while Present (Nod) loop
12756 elsif Nkind_In (Nod, N_Accept_Statement,
12758 N_Compilation_Unit,
12761 N_Package_Declaration,
12768 elsif Nkind (Nod) = N_Subunit then
12769 Nod := Corresponding_Stub (Nod);
12772 Nod := Parent (Nod);
12777 end In_Same_Declarative_Part;
12779 --------------------------------------
12780 -- In_Subprogram_Or_Concurrent_Unit --
12781 --------------------------------------
12783 function In_Subprogram_Or_Concurrent_Unit return Boolean is
12788 -- Use scope chain to check successively outer scopes
12790 E := Current_Scope;
12794 if K in Subprogram_Kind
12795 or else K in Concurrent_Kind
12796 or else K in Generic_Subprogram_Kind
12800 elsif E = Standard_Standard then
12806 end In_Subprogram_Or_Concurrent_Unit;
12812 function In_Subtree (N : Node_Id; Root : Node_Id) return Boolean is
12817 while Present (Curr) loop
12818 if Curr = Root then
12822 Curr := Parent (Curr);
12832 function In_Subtree
12835 Root2 : Node_Id) return Boolean
12841 while Present (Curr) loop
12842 if Curr = Root1 or else Curr = Root2 then
12846 Curr := Parent (Curr);
12852 ---------------------
12853 -- In_Visible_Part --
12854 ---------------------
12856 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
12858 return Is_Package_Or_Generic_Package (Scope_Id)
12859 and then In_Open_Scopes (Scope_Id)
12860 and then not In_Package_Body (Scope_Id)
12861 and then not In_Private_Part (Scope_Id);
12862 end In_Visible_Part;
12864 -----------------------------
12865 -- In_While_Loop_Condition --
12866 -----------------------------
12868 function In_While_Loop_Condition (N : Node_Id) return Boolean is
12869 Prev : Node_Id := N;
12870 P : Node_Id := Parent (N);
12871 -- P and Prev will be used for traversing the AST, while maintaining an
12872 -- invariant that P = Parent (Prev).
12877 elsif Nkind (P) = N_Iteration_Scheme
12878 and then Prev = Condition (P)
12886 end In_While_Loop_Condition;
12888 --------------------------------
12889 -- Incomplete_Or_Partial_View --
12890 --------------------------------
12892 function Incomplete_Or_Partial_View (Id : Entity_Id) return Entity_Id is
12893 function Inspect_Decls
12895 Taft : Boolean := False) return Entity_Id;
12896 -- Check whether a declarative region contains the incomplete or partial
12899 -------------------
12900 -- Inspect_Decls --
12901 -------------------
12903 function Inspect_Decls
12905 Taft : Boolean := False) return Entity_Id
12911 Decl := First (Decls);
12912 while Present (Decl) loop
12915 -- The partial view of a Taft-amendment type is an incomplete
12919 if Nkind (Decl) = N_Incomplete_Type_Declaration then
12920 Match := Defining_Identifier (Decl);
12923 -- Otherwise look for a private type whose full view matches the
12924 -- input type. Note that this checks full_type_declaration nodes
12925 -- to account for derivations from a private type where the type
12926 -- declaration hold the partial view and the full view is an
12929 elsif Nkind_In (Decl, N_Full_Type_Declaration,
12930 N_Private_Extension_Declaration,
12931 N_Private_Type_Declaration)
12933 Match := Defining_Identifier (Decl);
12936 -- Guard against unanalyzed entities
12939 and then Is_Type (Match)
12940 and then Present (Full_View (Match))
12941 and then Full_View (Match) = Id
12956 -- Start of processing for Incomplete_Or_Partial_View
12959 -- Deferred constant or incomplete type case
12961 Prev := Current_Entity_In_Scope (Id);
12964 and then (Is_Incomplete_Type (Prev) or else Ekind (Prev) = E_Constant)
12965 and then Present (Full_View (Prev))
12966 and then Full_View (Prev) = Id
12971 -- Private or Taft amendment type case
12974 Pkg : constant Entity_Id := Scope (Id);
12975 Pkg_Decl : Node_Id := Pkg;
12979 and then Is_Package_Or_Generic_Package (Pkg)
12981 while Nkind (Pkg_Decl) /= N_Package_Specification loop
12982 Pkg_Decl := Parent (Pkg_Decl);
12985 -- It is knows that Typ has a private view, look for it in the
12986 -- visible declarations of the enclosing scope. A special case
12987 -- of this is when the two views have been exchanged - the full
12988 -- appears earlier than the private.
12990 if Has_Private_Declaration (Id) then
12991 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
12993 -- Exchanged view case, look in the private declarations
12996 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
13001 -- Otherwise if this is the package body, then Typ is a potential
13002 -- Taft amendment type. The incomplete view should be located in
13003 -- the private declarations of the enclosing scope.
13005 elsif In_Package_Body (Pkg) then
13006 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
13011 -- The type has no incomplete or private view
13014 end Incomplete_Or_Partial_View;
13016 ---------------------------------------
13017 -- Incomplete_View_From_Limited_With --
13018 ---------------------------------------
13020 function Incomplete_View_From_Limited_With
13021 (Typ : Entity_Id) return Entity_Id
13024 -- It might make sense to make this an attribute in Einfo, and set it
13025 -- in Sem_Ch10 in Build_Shadow_Entity. However, we're running short on
13026 -- slots for new attributes, and it seems a bit simpler to just search
13027 -- the Limited_View (if it exists) for an incomplete type whose
13028 -- Non_Limited_View is Typ.
13030 if Ekind (Scope (Typ)) = E_Package
13031 and then Present (Limited_View (Scope (Typ)))
13034 Ent : Entity_Id := First_Entity (Limited_View (Scope (Typ)));
13036 while Present (Ent) loop
13037 if Ekind (Ent) in Incomplete_Kind
13038 and then Non_Limited_View (Ent) = Typ
13049 end Incomplete_View_From_Limited_With;
13051 ----------------------------------
13052 -- Indexed_Component_Bit_Offset --
13053 ----------------------------------
13055 function Indexed_Component_Bit_Offset (N : Node_Id) return Uint is
13056 Exp : constant Node_Id := First (Expressions (N));
13057 Typ : constant Entity_Id := Etype (Prefix (N));
13058 Off : constant Uint := Component_Size (Typ);
13062 -- Return early if the component size is not known or variable
13064 if Off = No_Uint or else Off < Uint_0 then
13068 -- Deal with the degenerate case of an empty component
13070 if Off = Uint_0 then
13074 -- Check that both the index value and the low bound are known
13076 if not Compile_Time_Known_Value (Exp) then
13080 Ind := First_Index (Typ);
13085 if Nkind (Ind) = N_Subtype_Indication then
13086 Ind := Constraint (Ind);
13088 if Nkind (Ind) = N_Range_Constraint then
13089 Ind := Range_Expression (Ind);
13093 if Nkind (Ind) /= N_Range
13094 or else not Compile_Time_Known_Value (Low_Bound (Ind))
13099 -- Return the scaled offset
13101 return Off * (Expr_Value (Exp) - Expr_Value (Low_Bound ((Ind))));
13102 end Indexed_Component_Bit_Offset;
13104 ----------------------------
13105 -- Inherit_Rep_Item_Chain --
13106 ----------------------------
13108 procedure Inherit_Rep_Item_Chain (Typ : Entity_Id; From_Typ : Entity_Id) is
13110 Next_Item : Node_Id;
13113 -- There are several inheritance scenarios to consider depending on
13114 -- whether both types have rep item chains and whether the destination
13115 -- type already inherits part of the source type's rep item chain.
13117 -- 1) The source type lacks a rep item chain
13118 -- From_Typ ---> Empty
13120 -- Typ --------> Item (or Empty)
13122 -- In this case inheritance cannot take place because there are no items
13125 -- 2) The destination type lacks a rep item chain
13126 -- From_Typ ---> Item ---> ...
13128 -- Typ --------> Empty
13130 -- Inheritance takes place by setting the First_Rep_Item of the
13131 -- destination type to the First_Rep_Item of the source type.
13132 -- From_Typ ---> Item ---> ...
13134 -- Typ -----------+
13136 -- 3.1) Both source and destination types have at least one rep item.
13137 -- The destination type does NOT inherit a rep item from the source
13139 -- From_Typ ---> Item ---> Item
13141 -- Typ --------> Item ---> Item
13143 -- Inheritance takes place by setting the Next_Rep_Item of the last item
13144 -- of the destination type to the First_Rep_Item of the source type.
13145 -- From_Typ -------------------> Item ---> Item
13147 -- Typ --------> Item ---> Item --+
13149 -- 3.2) Both source and destination types have at least one rep item.
13150 -- The destination type DOES inherit part of the rep item chain of the
13152 -- From_Typ ---> Item ---> Item ---> Item
13154 -- Typ --------> Item ------+
13156 -- This rare case arises when the full view of a private extension must
13157 -- inherit the rep item chain from the full view of its parent type and
13158 -- the full view of the parent type contains extra rep items. Currently
13159 -- only invariants may lead to such form of inheritance.
13161 -- type From_Typ is tagged private
13162 -- with Type_Invariant'Class => Item_2;
13164 -- type Typ is new From_Typ with private
13165 -- with Type_Invariant => Item_4;
13167 -- At this point the rep item chains contain the following items
13169 -- From_Typ -----------> Item_2 ---> Item_3
13171 -- Typ --------> Item_4 --+
13173 -- The full views of both types may introduce extra invariants
13175 -- type From_Typ is tagged null record
13176 -- with Type_Invariant => Item_1;
13178 -- type Typ is new From_Typ with null record;
13180 -- The full view of Typ would have to inherit any new rep items added to
13181 -- the full view of From_Typ.
13183 -- From_Typ -----------> Item_1 ---> Item_2 ---> Item_3
13185 -- Typ --------> Item_4 --+
13187 -- To achieve this form of inheritance, the destination type must first
13188 -- sever the link between its own rep chain and that of the source type,
13189 -- then inheritance 3.1 takes place.
13191 -- Case 1: The source type lacks a rep item chain
13193 if No (First_Rep_Item (From_Typ)) then
13196 -- Case 2: The destination type lacks a rep item chain
13198 elsif No (First_Rep_Item (Typ)) then
13199 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
13201 -- Case 3: Both the source and destination types have at least one rep
13202 -- item. Traverse the rep item chain of the destination type to find the
13207 Next_Item := First_Rep_Item (Typ);
13208 while Present (Next_Item) loop
13210 -- Detect a link between the destination type's rep chain and that
13211 -- of the source type. There are two possibilities:
13216 -- From_Typ ---> Item_1 --->
13218 -- Typ -----------+
13225 -- From_Typ ---> Item_1 ---> Item_2 --->
13227 -- Typ --------> Item_3 ------+
13231 if Has_Rep_Item (From_Typ, Next_Item) then
13236 Next_Item := Next_Rep_Item (Next_Item);
13239 -- Inherit the source type's rep item chain
13241 if Present (Item) then
13242 Set_Next_Rep_Item (Item, First_Rep_Item (From_Typ));
13244 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
13247 end Inherit_Rep_Item_Chain;
13249 ------------------------------------
13250 -- Inherits_From_Tagged_Full_View --
13251 ------------------------------------
13253 function Inherits_From_Tagged_Full_View (Typ : Entity_Id) return Boolean is
13255 return Is_Private_Type (Typ)
13256 and then Present (Full_View (Typ))
13257 and then Is_Private_Type (Full_View (Typ))
13258 and then not Is_Tagged_Type (Full_View (Typ))
13259 and then Present (Underlying_Type (Full_View (Typ)))
13260 and then Is_Tagged_Type (Underlying_Type (Full_View (Typ)));
13261 end Inherits_From_Tagged_Full_View;
13263 ---------------------------------
13264 -- Insert_Explicit_Dereference --
13265 ---------------------------------
13267 procedure Insert_Explicit_Dereference (N : Node_Id) is
13268 New_Prefix : constant Node_Id := Relocate_Node (N);
13269 Ent : Entity_Id := Empty;
13270 Pref : Node_Id := Empty;
13276 Save_Interps (N, New_Prefix);
13279 Make_Explicit_Dereference (Sloc (Parent (N)),
13280 Prefix => New_Prefix));
13282 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
13284 if Is_Overloaded (New_Prefix) then
13286 -- The dereference is also overloaded, and its interpretations are
13287 -- the designated types of the interpretations of the original node.
13289 Set_Etype (N, Any_Type);
13291 Get_First_Interp (New_Prefix, I, It);
13292 while Present (It.Nam) loop
13295 if Is_Access_Type (T) then
13296 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
13299 Get_Next_Interp (I, It);
13305 -- Prefix is unambiguous: mark the original prefix (which might
13306 -- Come_From_Source) as a reference, since the new (relocated) one
13307 -- won't be taken into account.
13309 if Is_Entity_Name (New_Prefix) then
13310 Ent := Entity (New_Prefix);
13311 Pref := New_Prefix;
13313 -- For a retrieval of a subcomponent of some composite object,
13314 -- retrieve the ultimate entity if there is one.
13316 elsif Nkind_In (New_Prefix, N_Selected_Component,
13317 N_Indexed_Component)
13319 Pref := Prefix (New_Prefix);
13320 while Present (Pref)
13321 and then Nkind_In (Pref, N_Selected_Component,
13322 N_Indexed_Component)
13324 Pref := Prefix (Pref);
13327 if Present (Pref) and then Is_Entity_Name (Pref) then
13328 Ent := Entity (Pref);
13332 -- Place the reference on the entity node
13334 if Present (Ent) then
13335 Generate_Reference (Ent, Pref);
13338 end Insert_Explicit_Dereference;
13340 ------------------------------------------
13341 -- Inspect_Deferred_Constant_Completion --
13342 ------------------------------------------
13344 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
13348 Decl := First (Decls);
13349 while Present (Decl) loop
13351 -- Deferred constant signature
13353 if Nkind (Decl) = N_Object_Declaration
13354 and then Constant_Present (Decl)
13355 and then No (Expression (Decl))
13357 -- No need to check internally generated constants
13359 and then Comes_From_Source (Decl)
13361 -- The constant is not completed. A full object declaration or a
13362 -- pragma Import complete a deferred constant.
13364 and then not Has_Completion (Defining_Identifier (Decl))
13367 ("constant declaration requires initialization expression",
13368 Defining_Identifier (Decl));
13371 Decl := Next (Decl);
13373 end Inspect_Deferred_Constant_Completion;
13375 -------------------------------
13376 -- Install_Elaboration_Model --
13377 -------------------------------
13379 procedure Install_Elaboration_Model (Unit_Id : Entity_Id) is
13380 function Find_Elaboration_Checks_Pragma (L : List_Id) return Node_Id;
13381 -- Try to find pragma Elaboration_Checks in arbitrary list L. Return
13382 -- Empty if there is no such pragma.
13384 ------------------------------------
13385 -- Find_Elaboration_Checks_Pragma --
13386 ------------------------------------
13388 function Find_Elaboration_Checks_Pragma (L : List_Id) return Node_Id is
13393 while Present (Item) loop
13394 if Nkind (Item) = N_Pragma
13395 and then Pragma_Name (Item) = Name_Elaboration_Checks
13404 end Find_Elaboration_Checks_Pragma;
13413 -- Start of processing for Install_Elaboration_Model
13416 -- Nothing to do when the unit does not exist
13418 if No (Unit_Id) then
13422 Unit := Parent (Unit_Declaration_Node (Unit_Id));
13424 -- Nothing to do when the unit is not a library unit
13426 if Nkind (Unit) /= N_Compilation_Unit then
13430 Prag := Find_Elaboration_Checks_Pragma (Context_Items (Unit));
13432 -- The compilation unit is subject to pragma Elaboration_Checks. Set the
13433 -- elaboration model as specified by the pragma.
13435 if Present (Prag) then
13436 Args := Pragma_Argument_Associations (Prag);
13438 -- Guard against an illegal pragma. The sole argument must be an
13439 -- identifier which specifies either Dynamic or Static model.
13441 if Present (Args) then
13442 Model := Get_Pragma_Arg (First (Args));
13444 if Nkind (Model) = N_Identifier then
13445 Dynamic_Elaboration_Checks := Chars (Model) = Name_Dynamic;
13449 end Install_Elaboration_Model;
13451 -----------------------------
13452 -- Install_Generic_Formals --
13453 -----------------------------
13455 procedure Install_Generic_Formals (Subp_Id : Entity_Id) is
13459 pragma Assert (Is_Generic_Subprogram (Subp_Id));
13461 E := First_Entity (Subp_Id);
13462 while Present (E) loop
13463 Install_Entity (E);
13466 end Install_Generic_Formals;
13468 ------------------------
13469 -- Install_SPARK_Mode --
13470 ------------------------
13472 procedure Install_SPARK_Mode (Mode : SPARK_Mode_Type; Prag : Node_Id) is
13474 SPARK_Mode := Mode;
13475 SPARK_Mode_Pragma := Prag;
13476 end Install_SPARK_Mode;
13478 --------------------------
13479 -- Invalid_Scalar_Value --
13480 --------------------------
13482 function Invalid_Scalar_Value
13484 Scal_Typ : Scalar_Id) return Node_Id
13486 function Invalid_Binder_Value return Node_Id;
13487 -- Return a reference to the corresponding invalid value for type
13488 -- Scal_Typ as defined in unit System.Scalar_Values.
13490 function Invalid_Float_Value return Node_Id;
13491 -- Return the invalid value of float type Scal_Typ
13493 function Invalid_Integer_Value return Node_Id;
13494 -- Return the invalid value of integer type Scal_Typ
13496 procedure Set_Invalid_Binder_Values;
13497 -- Set the contents of collection Invalid_Binder_Values
13499 --------------------------
13500 -- Invalid_Binder_Value --
13501 --------------------------
13503 function Invalid_Binder_Value return Node_Id is
13504 Val_Id : Entity_Id;
13507 -- Initialize the collection of invalid binder values the first time
13510 Set_Invalid_Binder_Values;
13512 -- Obtain the corresponding variable from System.Scalar_Values which
13513 -- holds the invalid value for this type.
13515 Val_Id := Invalid_Binder_Values (Scal_Typ);
13516 pragma Assert (Present (Val_Id));
13518 return New_Occurrence_Of (Val_Id, Loc);
13519 end Invalid_Binder_Value;
13521 -------------------------
13522 -- Invalid_Float_Value --
13523 -------------------------
13525 function Invalid_Float_Value return Node_Id is
13526 Value : constant Ureal := Invalid_Floats (Scal_Typ);
13529 -- Pragma Invalid_Scalars did not specify an invalid value for this
13530 -- type. Fall back to the value provided by the binder.
13532 if Value = No_Ureal then
13533 return Invalid_Binder_Value;
13535 return Make_Real_Literal (Loc, Realval => Value);
13537 end Invalid_Float_Value;
13539 ---------------------------
13540 -- Invalid_Integer_Value --
13541 ---------------------------
13543 function Invalid_Integer_Value return Node_Id is
13544 Value : constant Uint := Invalid_Integers (Scal_Typ);
13547 -- Pragma Invalid_Scalars did not specify an invalid value for this
13548 -- type. Fall back to the value provided by the binder.
13550 if Value = No_Uint then
13551 return Invalid_Binder_Value;
13553 return Make_Integer_Literal (Loc, Intval => Value);
13555 end Invalid_Integer_Value;
13557 -------------------------------
13558 -- Set_Invalid_Binder_Values --
13559 -------------------------------
13561 procedure Set_Invalid_Binder_Values is
13563 if not Invalid_Binder_Values_Set then
13564 Invalid_Binder_Values_Set := True;
13566 -- Initialize the contents of the collection once since RTE calls
13569 Invalid_Binder_Values :=
13570 (Name_Short_Float => RTE (RE_IS_Isf),
13571 Name_Float => RTE (RE_IS_Ifl),
13572 Name_Long_Float => RTE (RE_IS_Ilf),
13573 Name_Long_Long_Float => RTE (RE_IS_Ill),
13574 Name_Signed_8 => RTE (RE_IS_Is1),
13575 Name_Signed_16 => RTE (RE_IS_Is2),
13576 Name_Signed_32 => RTE (RE_IS_Is4),
13577 Name_Signed_64 => RTE (RE_IS_Is8),
13578 Name_Unsigned_8 => RTE (RE_IS_Iu1),
13579 Name_Unsigned_16 => RTE (RE_IS_Iu2),
13580 Name_Unsigned_32 => RTE (RE_IS_Iu4),
13581 Name_Unsigned_64 => RTE (RE_IS_Iu8));
13583 end Set_Invalid_Binder_Values;
13585 -- Start of processing for Invalid_Scalar_Value
13588 if Scal_Typ in Float_Scalar_Id then
13589 return Invalid_Float_Value;
13591 else pragma Assert (Scal_Typ in Integer_Scalar_Id);
13592 return Invalid_Integer_Value;
13594 end Invalid_Scalar_Value;
13596 -----------------------------
13597 -- Is_Actual_Out_Parameter --
13598 -----------------------------
13600 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
13601 Formal : Entity_Id;
13604 Find_Actual (N, Formal, Call);
13605 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
13606 end Is_Actual_Out_Parameter;
13608 -------------------------
13609 -- Is_Actual_Parameter --
13610 -------------------------
13612 function Is_Actual_Parameter (N : Node_Id) return Boolean is
13613 PK : constant Node_Kind := Nkind (Parent (N));
13617 when N_Parameter_Association =>
13618 return N = Explicit_Actual_Parameter (Parent (N));
13620 when N_Subprogram_Call =>
13621 return Is_List_Member (N)
13623 List_Containing (N) = Parameter_Associations (Parent (N));
13628 end Is_Actual_Parameter;
13630 --------------------------------
13631 -- Is_Actual_Tagged_Parameter --
13632 --------------------------------
13634 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
13635 Formal : Entity_Id;
13638 Find_Actual (N, Formal, Call);
13639 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
13640 end Is_Actual_Tagged_Parameter;
13642 ---------------------
13643 -- Is_Aliased_View --
13644 ---------------------
13646 function Is_Aliased_View (Obj : Node_Id) return Boolean is
13650 if Is_Entity_Name (Obj) then
13657 or else (Present (Renamed_Object (E))
13658 and then Is_Aliased_View (Renamed_Object (E)))))
13660 or else ((Is_Formal (E) or else Is_Formal_Object (E))
13661 and then Is_Tagged_Type (Etype (E)))
13663 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
13665 -- Current instance of type, either directly or as rewritten
13666 -- reference to the current object.
13668 or else (Is_Entity_Name (Original_Node (Obj))
13669 and then Present (Entity (Original_Node (Obj)))
13670 and then Is_Type (Entity (Original_Node (Obj))))
13672 or else (Is_Type (E) and then E = Current_Scope)
13674 or else (Is_Incomplete_Or_Private_Type (E)
13675 and then Full_View (E) = Current_Scope)
13677 -- Ada 2012 AI05-0053: the return object of an extended return
13678 -- statement is aliased if its type is immutably limited.
13680 or else (Is_Return_Object (E)
13681 and then Is_Limited_View (Etype (E)));
13683 elsif Nkind (Obj) = N_Selected_Component then
13684 return Is_Aliased (Entity (Selector_Name (Obj)));
13686 elsif Nkind (Obj) = N_Indexed_Component then
13687 return Has_Aliased_Components (Etype (Prefix (Obj)))
13689 (Is_Access_Type (Etype (Prefix (Obj)))
13690 and then Has_Aliased_Components
13691 (Designated_Type (Etype (Prefix (Obj)))));
13693 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
13694 return Is_Tagged_Type (Etype (Obj))
13695 and then Is_Aliased_View (Expression (Obj));
13697 elsif Nkind (Obj) = N_Explicit_Dereference then
13698 return Nkind (Original_Node (Obj)) /= N_Function_Call;
13703 end Is_Aliased_View;
13705 -------------------------
13706 -- Is_Ancestor_Package --
13707 -------------------------
13709 function Is_Ancestor_Package
13711 E2 : Entity_Id) return Boolean
13717 while Present (Par) and then Par /= Standard_Standard loop
13722 Par := Scope (Par);
13726 end Is_Ancestor_Package;
13728 ----------------------
13729 -- Is_Atomic_Object --
13730 ----------------------
13732 function Is_Atomic_Object (N : Node_Id) return Boolean is
13733 function Prefix_Has_Atomic_Components (P : Node_Id) return Boolean;
13734 -- Determine whether prefix P has atomic components. This requires the
13735 -- presence of an Atomic_Components aspect/pragma.
13737 ---------------------------------
13738 -- Prefix_Has_Atomic_Components --
13739 ---------------------------------
13741 function Prefix_Has_Atomic_Components (P : Node_Id) return Boolean is
13742 Typ : constant Entity_Id := Etype (P);
13745 if Is_Access_Type (Typ) then
13746 return Has_Atomic_Components (Designated_Type (Typ));
13748 elsif Has_Atomic_Components (Typ) then
13751 elsif Is_Entity_Name (P)
13752 and then Has_Atomic_Components (Entity (P))
13759 end Prefix_Has_Atomic_Components;
13761 -- Start of processing for Is_Atomic_Object
13764 if Is_Entity_Name (N) then
13765 return Is_Atomic_Object_Entity (Entity (N));
13767 elsif Is_Atomic (Etype (N)) then
13770 elsif Nkind (N) = N_Indexed_Component then
13771 return Prefix_Has_Atomic_Components (Prefix (N));
13773 elsif Nkind (N) = N_Selected_Component then
13774 return Is_Atomic (Entity (Selector_Name (N)));
13779 end Is_Atomic_Object;
13781 -----------------------------
13782 -- Is_Atomic_Object_Entity --
13783 -----------------------------
13785 function Is_Atomic_Object_Entity (Id : Entity_Id) return Boolean is
13789 and then (Is_Atomic (Id) or else Is_Atomic (Etype (Id)));
13790 end Is_Atomic_Object_Entity;
13792 -----------------------------
13793 -- Is_Atomic_Or_VFA_Object --
13794 -----------------------------
13796 function Is_Atomic_Or_VFA_Object (N : Node_Id) return Boolean is
13798 return Is_Atomic_Object (N) or else Is_Volatile_Full_Access_Object (N);
13799 end Is_Atomic_Or_VFA_Object;
13801 ----------------------
13802 -- Is_Attribute_Old --
13803 ----------------------
13805 function Is_Attribute_Old (N : Node_Id) return Boolean is
13807 return Nkind (N) = N_Attribute_Reference
13808 and then Attribute_Name (N) = Name_Old;
13809 end Is_Attribute_Old;
13811 -------------------------
13812 -- Is_Attribute_Result --
13813 -------------------------
13815 function Is_Attribute_Result (N : Node_Id) return Boolean is
13817 return Nkind (N) = N_Attribute_Reference
13818 and then Attribute_Name (N) = Name_Result;
13819 end Is_Attribute_Result;
13821 -------------------------
13822 -- Is_Attribute_Update --
13823 -------------------------
13825 function Is_Attribute_Update (N : Node_Id) return Boolean is
13827 return Nkind (N) = N_Attribute_Reference
13828 and then Attribute_Name (N) = Name_Update;
13829 end Is_Attribute_Update;
13831 ------------------------------------
13832 -- Is_Body_Or_Package_Declaration --
13833 ------------------------------------
13835 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
13837 return Is_Body (N) or else Nkind (N) = N_Package_Declaration;
13838 end Is_Body_Or_Package_Declaration;
13840 -----------------------
13841 -- Is_Bounded_String --
13842 -----------------------
13844 function Is_Bounded_String (T : Entity_Id) return Boolean is
13845 Under : constant Entity_Id := Underlying_Type (Root_Type (T));
13848 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
13849 -- Super_String, or one of the [Wide_]Wide_ versions. This will
13850 -- be True for all the Bounded_String types in instances of the
13851 -- Generic_Bounded_Length generics, and for types derived from those.
13853 return Present (Under)
13854 and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
13855 Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
13856 Is_RTE (Root_Type (Under), RO_WW_Super_String));
13857 end Is_Bounded_String;
13859 ---------------------
13860 -- Is_CCT_Instance --
13861 ---------------------
13863 function Is_CCT_Instance
13864 (Ref_Id : Entity_Id;
13865 Context_Id : Entity_Id) return Boolean
13868 pragma Assert (Ekind_In (Ref_Id, E_Protected_Type, E_Task_Type));
13870 if Is_Single_Task_Object (Context_Id) then
13871 return Scope_Within_Or_Same (Etype (Context_Id), Ref_Id);
13874 pragma Assert (Ekind_In (Context_Id, E_Entry,
13882 Is_Record_Type (Context_Id));
13883 return Scope_Within_Or_Same (Context_Id, Ref_Id);
13885 end Is_CCT_Instance;
13887 -------------------------
13888 -- Is_Child_Or_Sibling --
13889 -------------------------
13891 function Is_Child_Or_Sibling
13892 (Pack_1 : Entity_Id;
13893 Pack_2 : Entity_Id) return Boolean
13895 function Distance_From_Standard (Pack : Entity_Id) return Nat;
13896 -- Given an arbitrary package, return the number of "climbs" necessary
13897 -- to reach scope Standard_Standard.
13899 procedure Equalize_Depths
13900 (Pack : in out Entity_Id;
13901 Depth : in out Nat;
13902 Depth_To_Reach : Nat);
13903 -- Given an arbitrary package, its depth and a target depth to reach,
13904 -- climb the scope chain until the said depth is reached. The pointer
13905 -- to the package and its depth a modified during the climb.
13907 ----------------------------
13908 -- Distance_From_Standard --
13909 ----------------------------
13911 function Distance_From_Standard (Pack : Entity_Id) return Nat is
13918 while Present (Scop) and then Scop /= Standard_Standard loop
13920 Scop := Scope (Scop);
13924 end Distance_From_Standard;
13926 ---------------------
13927 -- Equalize_Depths --
13928 ---------------------
13930 procedure Equalize_Depths
13931 (Pack : in out Entity_Id;
13932 Depth : in out Nat;
13933 Depth_To_Reach : Nat)
13936 -- The package must be at a greater or equal depth
13938 if Depth < Depth_To_Reach then
13939 raise Program_Error;
13942 -- Climb the scope chain until the desired depth is reached
13944 while Present (Pack) and then Depth /= Depth_To_Reach loop
13945 Pack := Scope (Pack);
13946 Depth := Depth - 1;
13948 end Equalize_Depths;
13952 P_1 : Entity_Id := Pack_1;
13953 P_1_Child : Boolean := False;
13954 P_1_Depth : Nat := Distance_From_Standard (P_1);
13955 P_2 : Entity_Id := Pack_2;
13956 P_2_Child : Boolean := False;
13957 P_2_Depth : Nat := Distance_From_Standard (P_2);
13959 -- Start of processing for Is_Child_Or_Sibling
13963 (Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
13965 -- Both packages denote the same entity, therefore they cannot be
13966 -- children or siblings.
13971 -- One of the packages is at a deeper level than the other. Note that
13972 -- both may still come from different hierarchies.
13980 elsif P_1_Depth > P_2_Depth then
13983 Depth => P_1_Depth,
13984 Depth_To_Reach => P_2_Depth);
13993 elsif P_2_Depth > P_1_Depth then
13996 Depth => P_2_Depth,
13997 Depth_To_Reach => P_1_Depth);
14001 -- At this stage the package pointers have been elevated to the same
14002 -- depth. If the related entities are the same, then one package is a
14003 -- potential child of the other:
14007 -- X became P_1 P_2 or vice versa
14013 return Is_Child_Unit (Pack_1);
14015 else pragma Assert (P_2_Child);
14016 return Is_Child_Unit (Pack_2);
14019 -- The packages may come from the same package chain or from entirely
14020 -- different hierarcies. To determine this, climb the scope stack until
14021 -- a common root is found.
14023 -- (root) (root 1) (root 2)
14028 while Present (P_1) and then Present (P_2) loop
14030 -- The two packages may be siblings
14033 return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2);
14036 P_1 := Scope (P_1);
14037 P_2 := Scope (P_2);
14042 end Is_Child_Or_Sibling;
14044 -----------------------------
14045 -- Is_Concurrent_Interface --
14046 -----------------------------
14048 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
14050 return Is_Interface (T)
14052 (Is_Protected_Interface (T)
14053 or else Is_Synchronized_Interface (T)
14054 or else Is_Task_Interface (T));
14055 end Is_Concurrent_Interface;
14057 -----------------------
14058 -- Is_Constant_Bound --
14059 -----------------------
14061 function Is_Constant_Bound (Exp : Node_Id) return Boolean is
14063 if Compile_Time_Known_Value (Exp) then
14066 elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
14067 return Is_Constant_Object (Entity (Exp))
14068 or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
14070 elsif Nkind (Exp) in N_Binary_Op then
14071 return Is_Constant_Bound (Left_Opnd (Exp))
14072 and then Is_Constant_Bound (Right_Opnd (Exp))
14073 and then Scope (Entity (Exp)) = Standard_Standard;
14078 end Is_Constant_Bound;
14080 ---------------------------
14081 -- Is_Container_Element --
14082 ---------------------------
14084 function Is_Container_Element (Exp : Node_Id) return Boolean is
14085 Loc : constant Source_Ptr := Sloc (Exp);
14086 Pref : constant Node_Id := Prefix (Exp);
14089 -- Call to an indexing aspect
14091 Cont_Typ : Entity_Id;
14092 -- The type of the container being accessed
14094 Elem_Typ : Entity_Id;
14095 -- Its element type
14097 Indexing : Entity_Id;
14098 Is_Const : Boolean;
14099 -- Indicates that constant indexing is used, and the element is thus
14102 Ref_Typ : Entity_Id;
14103 -- The reference type returned by the indexing operation
14106 -- If C is a container, in a context that imposes the element type of
14107 -- that container, the indexing notation C (X) is rewritten as:
14109 -- Indexing (C, X).Discr.all
14111 -- where Indexing is one of the indexing aspects of the container.
14112 -- If the context does not require a reference, the construct can be
14117 -- First, verify that the construct has the proper form
14119 if not Expander_Active then
14122 elsif Nkind (Pref) /= N_Selected_Component then
14125 elsif Nkind (Prefix (Pref)) /= N_Function_Call then
14129 Call := Prefix (Pref);
14130 Ref_Typ := Etype (Call);
14133 if not Has_Implicit_Dereference (Ref_Typ)
14134 or else No (First (Parameter_Associations (Call)))
14135 or else not Is_Entity_Name (Name (Call))
14140 -- Retrieve type of container object, and its iterator aspects
14142 Cont_Typ := Etype (First (Parameter_Associations (Call)));
14143 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Constant_Indexing);
14146 if No (Indexing) then
14148 -- Container should have at least one indexing operation
14152 elsif Entity (Name (Call)) /= Entity (Indexing) then
14154 -- This may be a variable indexing operation
14156 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Variable_Indexing);
14159 or else Entity (Name (Call)) /= Entity (Indexing)
14168 Elem_Typ := Find_Value_Of_Aspect (Cont_Typ, Aspect_Iterator_Element);
14170 if No (Elem_Typ) or else Entity (Elem_Typ) /= Etype (Exp) then
14174 -- Check that the expression is not the target of an assignment, in
14175 -- which case the rewriting is not possible.
14177 if not Is_Const then
14183 while Present (Par)
14185 if Nkind (Parent (Par)) = N_Assignment_Statement
14186 and then Par = Name (Parent (Par))
14190 -- A renaming produces a reference, and the transformation
14193 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
14197 (Nkind (Parent (Par)), N_Function_Call,
14198 N_Procedure_Call_Statement,
14199 N_Entry_Call_Statement)
14201 -- Check that the element is not part of an actual for an
14202 -- in-out parameter.
14209 F := First_Formal (Entity (Name (Parent (Par))));
14210 A := First (Parameter_Associations (Parent (Par)));
14211 while Present (F) loop
14212 if A = Par and then Ekind (F) /= E_In_Parameter then
14221 -- E_In_Parameter in a call: element is not modified.
14226 Par := Parent (Par);
14231 -- The expression has the proper form and the context requires the
14232 -- element type. Retrieve the Element function of the container and
14233 -- rewrite the construct as a call to it.
14239 Op := First_Elmt (Primitive_Operations (Cont_Typ));
14240 while Present (Op) loop
14241 exit when Chars (Node (Op)) = Name_Element;
14250 Make_Function_Call (Loc,
14251 Name => New_Occurrence_Of (Node (Op), Loc),
14252 Parameter_Associations => Parameter_Associations (Call)));
14253 Analyze_And_Resolve (Exp, Entity (Elem_Typ));
14257 end Is_Container_Element;
14259 ----------------------------
14260 -- Is_Contract_Annotation --
14261 ----------------------------
14263 function Is_Contract_Annotation (Item : Node_Id) return Boolean is
14265 return Is_Package_Contract_Annotation (Item)
14267 Is_Subprogram_Contract_Annotation (Item);
14268 end Is_Contract_Annotation;
14270 --------------------------------------
14271 -- Is_Controlling_Limited_Procedure --
14272 --------------------------------------
14274 function Is_Controlling_Limited_Procedure
14275 (Proc_Nam : Entity_Id) return Boolean
14278 Param_Typ : Entity_Id := Empty;
14281 if Ekind (Proc_Nam) = E_Procedure
14282 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
14286 (First (Parameter_Specifications (Parent (Proc_Nam))));
14288 -- The formal may be an anonymous access type
14290 if Nkind (Param) = N_Access_Definition then
14291 Param_Typ := Entity (Subtype_Mark (Param));
14293 Param_Typ := Etype (Param);
14296 -- In the case where an Itype was created for a dispatchin call, the
14297 -- procedure call has been rewritten. The actual may be an access to
14298 -- interface type in which case it is the designated type that is the
14299 -- controlling type.
14301 elsif Present (Associated_Node_For_Itype (Proc_Nam))
14302 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
14304 Present (Parameter_Associations
14305 (Associated_Node_For_Itype (Proc_Nam)))
14308 Etype (First (Parameter_Associations
14309 (Associated_Node_For_Itype (Proc_Nam))));
14311 if Ekind (Param_Typ) = E_Anonymous_Access_Type then
14312 Param_Typ := Directly_Designated_Type (Param_Typ);
14316 if Present (Param_Typ) then
14318 Is_Interface (Param_Typ)
14319 and then Is_Limited_Record (Param_Typ);
14323 end Is_Controlling_Limited_Procedure;
14325 -----------------------------
14326 -- Is_CPP_Constructor_Call --
14327 -----------------------------
14329 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
14331 return Nkind (N) = N_Function_Call
14332 and then Is_CPP_Class (Etype (Etype (N)))
14333 and then Is_Constructor (Entity (Name (N)))
14334 and then Is_Imported (Entity (Name (N)));
14335 end Is_CPP_Constructor_Call;
14337 -------------------------
14338 -- Is_Current_Instance --
14339 -------------------------
14341 function Is_Current_Instance (N : Node_Id) return Boolean is
14342 Typ : constant Entity_Id := Entity (N);
14346 -- Simplest case: entity is a concurrent type and we are currently
14347 -- inside the body. This will eventually be expanded into a call to
14348 -- Self (for tasks) or _object (for protected objects).
14350 if Is_Concurrent_Type (Typ) and then In_Open_Scopes (Typ) then
14354 -- Check whether the context is a (sub)type declaration for the
14358 while Present (P) loop
14359 if Nkind_In (P, N_Full_Type_Declaration,
14360 N_Private_Type_Declaration,
14361 N_Subtype_Declaration)
14362 and then Comes_From_Source (P)
14363 and then Defining_Entity (P) = Typ
14367 -- A subtype name may appear in an aspect specification for a
14368 -- Predicate_Failure aspect, for which we do not construct a
14369 -- wrapper procedure. The subtype will be replaced by the
14370 -- expression being tested when the corresponding predicate
14371 -- check is expanded.
14373 elsif Nkind (P) = N_Aspect_Specification
14374 and then Nkind (Parent (P)) = N_Subtype_Declaration
14378 elsif Nkind (P) = N_Pragma
14379 and then Get_Pragma_Id (P) = Pragma_Predicate_Failure
14388 -- In any other context this is not a current occurrence
14391 end Is_Current_Instance;
14393 --------------------
14394 -- Is_Declaration --
14395 --------------------
14397 function Is_Declaration
14399 Body_OK : Boolean := True;
14400 Concurrent_OK : Boolean := True;
14401 Formal_OK : Boolean := True;
14402 Generic_OK : Boolean := True;
14403 Instantiation_OK : Boolean := True;
14404 Renaming_OK : Boolean := True;
14405 Stub_OK : Boolean := True;
14406 Subprogram_OK : Boolean := True;
14407 Type_OK : Boolean := True) return Boolean
14412 -- Body declarations
14414 when N_Proper_Body =>
14417 -- Concurrent type declarations
14419 when N_Protected_Type_Declaration
14420 | N_Single_Protected_Declaration
14421 | N_Single_Task_Declaration
14422 | N_Task_Type_Declaration
14424 return Concurrent_OK or Type_OK;
14426 -- Formal declarations
14428 when N_Formal_Abstract_Subprogram_Declaration
14429 | N_Formal_Concrete_Subprogram_Declaration
14430 | N_Formal_Object_Declaration
14431 | N_Formal_Package_Declaration
14432 | N_Formal_Type_Declaration
14436 -- Generic declarations
14438 when N_Generic_Package_Declaration
14439 | N_Generic_Subprogram_Declaration
14443 -- Generic instantiations
14445 when N_Function_Instantiation
14446 | N_Package_Instantiation
14447 | N_Procedure_Instantiation
14449 return Instantiation_OK;
14451 -- Generic renaming declarations
14453 when N_Generic_Renaming_Declaration =>
14454 return Generic_OK or Renaming_OK;
14456 -- Renaming declarations
14458 when N_Exception_Renaming_Declaration
14459 | N_Object_Renaming_Declaration
14460 | N_Package_Renaming_Declaration
14461 | N_Subprogram_Renaming_Declaration
14463 return Renaming_OK;
14465 -- Stub declarations
14467 when N_Body_Stub =>
14470 -- Subprogram declarations
14472 when N_Abstract_Subprogram_Declaration
14473 | N_Entry_Declaration
14474 | N_Expression_Function
14475 | N_Subprogram_Declaration
14477 return Subprogram_OK;
14479 -- Type declarations
14481 when N_Full_Type_Declaration
14482 | N_Incomplete_Type_Declaration
14483 | N_Private_Extension_Declaration
14484 | N_Private_Type_Declaration
14485 | N_Subtype_Declaration
14491 when N_Component_Declaration
14492 | N_Exception_Declaration
14493 | N_Implicit_Label_Declaration
14494 | N_Number_Declaration
14495 | N_Object_Declaration
14496 | N_Package_Declaration
14503 end Is_Declaration;
14505 --------------------------------
14506 -- Is_Declared_Within_Variant --
14507 --------------------------------
14509 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
14510 Comp_Decl : constant Node_Id := Parent (Comp);
14511 Comp_List : constant Node_Id := Parent (Comp_Decl);
14513 return Nkind (Parent (Comp_List)) = N_Variant;
14514 end Is_Declared_Within_Variant;
14516 ----------------------------------------------
14517 -- Is_Dependent_Component_Of_Mutable_Object --
14518 ----------------------------------------------
14520 function Is_Dependent_Component_Of_Mutable_Object
14521 (Object : Node_Id) return Boolean
14524 Prefix_Type : Entity_Id;
14525 P_Aliased : Boolean := False;
14528 Deref : Node_Id := Object;
14529 -- Dereference node, in something like X.all.Y(2)
14531 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
14534 -- Find the dereference node if any
14536 while Nkind_In (Deref, N_Indexed_Component,
14537 N_Selected_Component,
14540 Deref := Prefix (Deref);
14543 -- If the prefix is a qualified expression of a variable, then function
14544 -- Is_Variable will return False for that because a qualified expression
14545 -- denotes a constant view, so we need to get the name being qualified
14546 -- so we can test below whether that's a variable (or a dereference).
14548 if Nkind (Deref) = N_Qualified_Expression then
14549 Deref := Expression (Deref);
14552 -- Ada 2005: If we have a component or slice of a dereference, something
14553 -- like X.all.Y (2) and the type of X is access-to-constant, Is_Variable
14554 -- will return False, because it is indeed a constant view. But it might
14555 -- be a view of a variable object, so we want the following condition to
14556 -- be True in that case.
14558 if Is_Variable (Object)
14559 or else Is_Variable (Deref)
14560 or else (Ada_Version >= Ada_2005
14561 and then (Nkind (Deref) = N_Explicit_Dereference
14562 or else Is_Access_Type (Etype (Deref))))
14564 if Nkind (Object) = N_Selected_Component then
14566 -- If the selector is not a component, then we definitely return
14567 -- False (it could be a function selector in a prefix form call
14568 -- occurring in an iterator specification).
14570 if not Ekind_In (Entity (Selector_Name (Object)), E_Component,
14576 -- Get the original node of the prefix in case it has been
14577 -- rewritten, which can occur, for example, in qualified
14578 -- expression cases. Also, a discriminant check on a selected
14579 -- component may be expanded into a dereference when removing
14580 -- side effects, and the subtype of the original node may be
14583 P := Original_Node (Prefix (Object));
14584 Prefix_Type := Etype (P);
14586 -- If the prefix is a qualified expression, we want to look at its
14589 if Nkind (P) = N_Qualified_Expression then
14590 P := Expression (P);
14591 Prefix_Type := Etype (P);
14594 if Is_Entity_Name (P) then
14595 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
14596 Prefix_Type := Base_Type (Prefix_Type);
14599 if Is_Aliased (Entity (P)) then
14603 -- For explicit dereferences we get the access prefix so we can
14604 -- treat this similarly to implicit dereferences and examine the
14605 -- kind of the access type and its designated subtype further
14608 elsif Nkind (P) = N_Explicit_Dereference then
14610 Prefix_Type := Etype (P);
14613 -- Check for prefix being an aliased component???
14618 -- A heap object is constrained by its initial value
14620 -- Ada 2005 (AI-363): Always assume the object could be mutable in
14621 -- the dereferenced case, since the access value might denote an
14622 -- unconstrained aliased object, whereas in Ada 95 the designated
14623 -- object is guaranteed to be constrained. A worst-case assumption
14624 -- has to apply in Ada 2005 because we can't tell at compile
14625 -- time whether the object is "constrained by its initial value",
14626 -- despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
14627 -- rules (these rules are acknowledged to need fixing). We don't
14628 -- impose this more stringent checking for earlier Ada versions or
14629 -- when Relaxed_RM_Semantics applies (the latter for CodePeer's
14630 -- benefit, though it's unclear on why using -gnat95 would not be
14633 if Ada_Version < Ada_2005 or else Relaxed_RM_Semantics then
14634 if Is_Access_Type (Prefix_Type)
14635 or else Nkind (P) = N_Explicit_Dereference
14640 else pragma Assert (Ada_Version >= Ada_2005);
14641 if Is_Access_Type (Prefix_Type) then
14642 -- We need to make sure we have the base subtype, in case
14643 -- this is actually an access subtype (whose Ekind will be
14644 -- E_Access_Subtype).
14646 Prefix_Type := Etype (Prefix_Type);
14648 -- If the access type is pool-specific, and there is no
14649 -- constrained partial view of the designated type, then the
14650 -- designated object is known to be constrained. If it's a
14651 -- formal access type and the renaming is in the generic
14652 -- spec, we also treat it as pool-specific (known to be
14653 -- constrained), but assume the worst if in the generic body
14654 -- (see RM 3.3(23.3/3)).
14656 if Ekind (Prefix_Type) = E_Access_Type
14657 and then (not Is_Generic_Type (Prefix_Type)
14658 or else not In_Generic_Body (Current_Scope))
14659 and then not Object_Type_Has_Constrained_Partial_View
14660 (Typ => Designated_Type (Prefix_Type),
14661 Scop => Current_Scope)
14665 -- Otherwise (general access type, or there is a constrained
14666 -- partial view of the designated type), we need to check
14667 -- based on the designated type.
14670 Prefix_Type := Designated_Type (Prefix_Type);
14676 Original_Record_Component (Entity (Selector_Name (Object)));
14678 -- As per AI-0017, the renaming is illegal in a generic body, even
14679 -- if the subtype is indefinite (only applies to prefixes of an
14680 -- untagged formal type, see RM 3.3 (23.11/3)).
14682 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
14684 if not Is_Constrained (Prefix_Type)
14685 and then (Is_Definite_Subtype (Prefix_Type)
14687 (not Is_Tagged_Type (Prefix_Type)
14688 and then Is_Generic_Type (Prefix_Type)
14689 and then In_Generic_Body (Current_Scope)))
14691 and then (Is_Declared_Within_Variant (Comp)
14692 or else Has_Discriminant_Dependent_Constraint (Comp))
14693 and then (not P_Aliased or else Ada_Version >= Ada_2005)
14697 -- If the prefix is of an access type at this point, then we want
14698 -- to return False, rather than calling this function recursively
14699 -- on the access object (which itself might be a discriminant-
14700 -- dependent component of some other object, but that isn't
14701 -- relevant to checking the object passed to us). This avoids
14702 -- issuing wrong errors when compiling with -gnatc, where there
14703 -- can be implicit dereferences that have not been expanded.
14705 elsif Is_Access_Type (Etype (Prefix (Object))) then
14710 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
14713 elsif Nkind (Object) = N_Indexed_Component
14714 or else Nkind (Object) = N_Slice
14716 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
14718 -- A type conversion that Is_Variable is a view conversion:
14719 -- go back to the denoted object.
14721 elsif Nkind (Object) = N_Type_Conversion then
14723 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
14728 end Is_Dependent_Component_Of_Mutable_Object;
14730 ---------------------
14731 -- Is_Dereferenced --
14732 ---------------------
14734 function Is_Dereferenced (N : Node_Id) return Boolean is
14735 P : constant Node_Id := Parent (N);
14737 return Nkind_In (P, N_Selected_Component,
14738 N_Explicit_Dereference,
14739 N_Indexed_Component,
14741 and then Prefix (P) = N;
14742 end Is_Dereferenced;
14744 ----------------------
14745 -- Is_Descendant_Of --
14746 ----------------------
14748 function Is_Descendant_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
14753 pragma Assert (Nkind (T1) in N_Entity);
14754 pragma Assert (Nkind (T2) in N_Entity);
14756 T := Base_Type (T1);
14758 -- Immediate return if the types match
14763 -- Comment needed here ???
14765 elsif Ekind (T) = E_Class_Wide_Type then
14766 return Etype (T) = T2;
14774 -- Done if we found the type we are looking for
14779 -- Done if no more derivations to check
14786 -- Following test catches error cases resulting from prev errors
14788 elsif No (Etyp) then
14791 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
14794 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
14798 T := Base_Type (Etyp);
14801 end Is_Descendant_Of;
14803 ----------------------------------------
14804 -- Is_Descendant_Of_Suspension_Object --
14805 ----------------------------------------
14807 function Is_Descendant_Of_Suspension_Object
14808 (Typ : Entity_Id) return Boolean
14810 Cur_Typ : Entity_Id;
14811 Par_Typ : Entity_Id;
14814 -- Climb the type derivation chain checking each parent type against
14815 -- Suspension_Object.
14817 Cur_Typ := Base_Type (Typ);
14818 while Present (Cur_Typ) loop
14819 Par_Typ := Etype (Cur_Typ);
14821 -- The current type is a match
14823 if Is_Suspension_Object (Cur_Typ) then
14826 -- Stop the traversal once the root of the derivation chain has been
14827 -- reached. In that case the current type is its own base type.
14829 elsif Cur_Typ = Par_Typ then
14833 Cur_Typ := Base_Type (Par_Typ);
14837 end Is_Descendant_Of_Suspension_Object;
14839 ---------------------------------------------
14840 -- Is_Double_Precision_Floating_Point_Type --
14841 ---------------------------------------------
14843 function Is_Double_Precision_Floating_Point_Type
14844 (E : Entity_Id) return Boolean is
14846 return Is_Floating_Point_Type (E)
14847 and then Machine_Radix_Value (E) = Uint_2
14848 and then Machine_Mantissa_Value (E) = UI_From_Int (53)
14849 and then Machine_Emax_Value (E) = Uint_2 ** Uint_10
14850 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_10);
14851 end Is_Double_Precision_Floating_Point_Type;
14853 -----------------------------
14854 -- Is_Effectively_Volatile --
14855 -----------------------------
14857 function Is_Effectively_Volatile (Id : Entity_Id) return Boolean is
14859 if Is_Type (Id) then
14861 -- An arbitrary type is effectively volatile when it is subject to
14862 -- pragma Atomic or Volatile.
14864 if Is_Volatile (Id) then
14867 -- An array type is effectively volatile when it is subject to pragma
14868 -- Atomic_Components or Volatile_Components or its component type is
14869 -- effectively volatile.
14871 elsif Is_Array_Type (Id) then
14873 Anc : Entity_Id := Base_Type (Id);
14875 if Is_Private_Type (Anc) then
14876 Anc := Full_View (Anc);
14879 -- Test for presence of ancestor, as the full view of a private
14880 -- type may be missing in case of error.
14883 Has_Volatile_Components (Id)
14886 and then Is_Effectively_Volatile (Component_Type (Anc)));
14889 -- A protected type is always volatile
14891 elsif Is_Protected_Type (Id) then
14894 -- A descendant of Ada.Synchronous_Task_Control.Suspension_Object is
14895 -- automatically volatile.
14897 elsif Is_Descendant_Of_Suspension_Object (Id) then
14900 -- Otherwise the type is not effectively volatile
14906 -- Otherwise Id denotes an object
14909 -- A volatile object for which No_Caching is enabled is not
14910 -- effectively volatile.
14913 (Is_Volatile (Id) and then not No_Caching_Enabled (Id))
14914 or else Has_Volatile_Components (Id)
14915 or else Is_Effectively_Volatile (Etype (Id));
14917 end Is_Effectively_Volatile;
14919 ------------------------------------
14920 -- Is_Effectively_Volatile_Object --
14921 ------------------------------------
14923 function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean is
14925 if Is_Entity_Name (N) then
14926 return Is_Effectively_Volatile (Entity (N));
14928 elsif Nkind (N) = N_Indexed_Component then
14929 return Is_Effectively_Volatile_Object (Prefix (N));
14931 elsif Nkind (N) = N_Selected_Component then
14933 Is_Effectively_Volatile_Object (Prefix (N))
14935 Is_Effectively_Volatile_Object (Selector_Name (N));
14940 end Is_Effectively_Volatile_Object;
14942 -------------------
14943 -- Is_Entry_Body --
14944 -------------------
14946 function Is_Entry_Body (Id : Entity_Id) return Boolean is
14949 Ekind_In (Id, E_Entry, E_Entry_Family)
14950 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Body;
14953 --------------------------
14954 -- Is_Entry_Declaration --
14955 --------------------------
14957 function Is_Entry_Declaration (Id : Entity_Id) return Boolean is
14960 Ekind_In (Id, E_Entry, E_Entry_Family)
14961 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Declaration;
14962 end Is_Entry_Declaration;
14964 ------------------------------------
14965 -- Is_Expanded_Priority_Attribute --
14966 ------------------------------------
14968 function Is_Expanded_Priority_Attribute (E : Entity_Id) return Boolean is
14971 Nkind (E) = N_Function_Call
14972 and then not Configurable_Run_Time_Mode
14973 and then Nkind (Original_Node (E)) = N_Attribute_Reference
14974 and then (Entity (Name (E)) = RTE (RE_Get_Ceiling)
14975 or else Entity (Name (E)) = RTE (RO_PE_Get_Ceiling));
14976 end Is_Expanded_Priority_Attribute;
14978 ----------------------------
14979 -- Is_Expression_Function --
14980 ----------------------------
14982 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
14984 if Ekind_In (Subp, E_Function, E_Subprogram_Body) then
14986 Nkind (Original_Node (Unit_Declaration_Node (Subp))) =
14987 N_Expression_Function;
14991 end Is_Expression_Function;
14993 ------------------------------------------
14994 -- Is_Expression_Function_Or_Completion --
14995 ------------------------------------------
14997 function Is_Expression_Function_Or_Completion
14998 (Subp : Entity_Id) return Boolean
15000 Subp_Decl : Node_Id;
15003 if Ekind (Subp) = E_Function then
15004 Subp_Decl := Unit_Declaration_Node (Subp);
15006 -- The function declaration is either an expression function or is
15007 -- completed by an expression function body.
15010 Is_Expression_Function (Subp)
15011 or else (Nkind (Subp_Decl) = N_Subprogram_Declaration
15012 and then Present (Corresponding_Body (Subp_Decl))
15013 and then Is_Expression_Function
15014 (Corresponding_Body (Subp_Decl)));
15016 elsif Ekind (Subp) = E_Subprogram_Body then
15017 return Is_Expression_Function (Subp);
15022 end Is_Expression_Function_Or_Completion;
15024 -----------------------
15025 -- Is_EVF_Expression --
15026 -----------------------
15028 function Is_EVF_Expression (N : Node_Id) return Boolean is
15029 Orig_N : constant Node_Id := Original_Node (N);
15035 -- Detect a reference to a formal parameter of a specific tagged type
15036 -- whose related subprogram is subject to pragma Expresions_Visible with
15039 if Is_Entity_Name (N) and then Present (Entity (N)) then
15044 and then Is_Specific_Tagged_Type (Etype (Id))
15045 and then Extensions_Visible_Status (Id) =
15046 Extensions_Visible_False;
15048 -- A case expression is an EVF expression when it contains at least one
15049 -- EVF dependent_expression. Note that a case expression may have been
15050 -- expanded, hence the use of Original_Node.
15052 elsif Nkind (Orig_N) = N_Case_Expression then
15053 Alt := First (Alternatives (Orig_N));
15054 while Present (Alt) loop
15055 if Is_EVF_Expression (Expression (Alt)) then
15062 -- An if expression is an EVF expression when it contains at least one
15063 -- EVF dependent_expression. Note that an if expression may have been
15064 -- expanded, hence the use of Original_Node.
15066 elsif Nkind (Orig_N) = N_If_Expression then
15067 Expr := Next (First (Expressions (Orig_N)));
15068 while Present (Expr) loop
15069 if Is_EVF_Expression (Expr) then
15076 -- A qualified expression or a type conversion is an EVF expression when
15077 -- its operand is an EVF expression.
15079 elsif Nkind_In (N, N_Qualified_Expression,
15080 N_Unchecked_Type_Conversion,
15083 return Is_EVF_Expression (Expression (N));
15085 -- Attributes 'Loop_Entry, 'Old, and 'Update are EVF expressions when
15086 -- their prefix denotes an EVF expression.
15088 elsif Nkind (N) = N_Attribute_Reference
15089 and then Nam_In (Attribute_Name (N), Name_Loop_Entry,
15093 return Is_EVF_Expression (Prefix (N));
15097 end Is_EVF_Expression;
15103 function Is_False (U : Uint) return Boolean is
15108 ---------------------------
15109 -- Is_Fixed_Model_Number --
15110 ---------------------------
15112 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
15113 S : constant Ureal := Small_Value (T);
15114 M : Urealp.Save_Mark;
15119 R := (U = UR_Trunc (U / S) * S);
15120 Urealp.Release (M);
15122 end Is_Fixed_Model_Number;
15124 -------------------------------
15125 -- Is_Fully_Initialized_Type --
15126 -------------------------------
15128 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
15132 if Is_Scalar_Type (Typ) then
15134 -- A scalar type with an aspect Default_Value is fully initialized
15136 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
15137 -- of a scalar type, but we don't take that into account here, since
15138 -- we don't want these to affect warnings.
15140 return Has_Default_Aspect (Typ);
15142 elsif Is_Access_Type (Typ) then
15145 elsif Is_Array_Type (Typ) then
15146 if Is_Fully_Initialized_Type (Component_Type (Typ))
15147 or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
15152 -- An interesting case, if we have a constrained type one of whose
15153 -- bounds is known to be null, then there are no elements to be
15154 -- initialized, so all the elements are initialized.
15156 if Is_Constrained (Typ) then
15159 Indx_Typ : Entity_Id;
15160 Lbd, Hbd : Node_Id;
15163 Indx := First_Index (Typ);
15164 while Present (Indx) loop
15165 if Etype (Indx) = Any_Type then
15168 -- If index is a range, use directly
15170 elsif Nkind (Indx) = N_Range then
15171 Lbd := Low_Bound (Indx);
15172 Hbd := High_Bound (Indx);
15175 Indx_Typ := Etype (Indx);
15177 if Is_Private_Type (Indx_Typ) then
15178 Indx_Typ := Full_View (Indx_Typ);
15181 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
15184 Lbd := Type_Low_Bound (Indx_Typ);
15185 Hbd := Type_High_Bound (Indx_Typ);
15189 if Compile_Time_Known_Value (Lbd)
15191 Compile_Time_Known_Value (Hbd)
15193 if Expr_Value (Hbd) < Expr_Value (Lbd) then
15203 -- If no null indexes, then type is not fully initialized
15209 elsif Is_Record_Type (Typ) then
15210 if Has_Discriminants (Typ)
15212 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
15213 and then Is_Fully_Initialized_Variant (Typ)
15218 -- We consider bounded string types to be fully initialized, because
15219 -- otherwise we get false alarms when the Data component is not
15220 -- default-initialized.
15222 if Is_Bounded_String (Typ) then
15226 -- Controlled records are considered to be fully initialized if
15227 -- there is a user defined Initialize routine. This may not be
15228 -- entirely correct, but as the spec notes, we are guessing here
15229 -- what is best from the point of view of issuing warnings.
15231 if Is_Controlled (Typ) then
15233 Utyp : constant Entity_Id := Underlying_Type (Typ);
15236 if Present (Utyp) then
15238 Init : constant Entity_Id :=
15239 (Find_Optional_Prim_Op
15240 (Underlying_Type (Typ), Name_Initialize));
15244 and then Comes_From_Source (Init)
15245 and then not In_Predefined_Unit (Init)
15249 elsif Has_Null_Extension (Typ)
15251 Is_Fully_Initialized_Type
15252 (Etype (Base_Type (Typ)))
15261 -- Otherwise see if all record components are initialized
15267 Ent := First_Entity (Typ);
15268 while Present (Ent) loop
15269 if Ekind (Ent) = E_Component
15270 and then (No (Parent (Ent))
15271 or else No (Expression (Parent (Ent))))
15272 and then not Is_Fully_Initialized_Type (Etype (Ent))
15274 -- Special VM case for tag components, which need to be
15275 -- defined in this case, but are never initialized as VMs
15276 -- are using other dispatching mechanisms. Ignore this
15277 -- uninitialized case. Note that this applies both to the
15278 -- uTag entry and the main vtable pointer (CPP_Class case).
15280 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
15289 -- No uninitialized components, so type is fully initialized.
15290 -- Note that this catches the case of no components as well.
15294 elsif Is_Concurrent_Type (Typ) then
15297 elsif Is_Private_Type (Typ) then
15299 U : constant Entity_Id := Underlying_Type (Typ);
15305 return Is_Fully_Initialized_Type (U);
15312 end Is_Fully_Initialized_Type;
15314 ----------------------------------
15315 -- Is_Fully_Initialized_Variant --
15316 ----------------------------------
15318 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
15319 Loc : constant Source_Ptr := Sloc (Typ);
15320 Constraints : constant List_Id := New_List;
15321 Components : constant Elist_Id := New_Elmt_List;
15322 Comp_Elmt : Elmt_Id;
15324 Comp_List : Node_Id;
15326 Discr_Val : Node_Id;
15328 Report_Errors : Boolean;
15329 pragma Warnings (Off, Report_Errors);
15332 if Serious_Errors_Detected > 0 then
15336 if Is_Record_Type (Typ)
15337 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
15338 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
15340 Comp_List := Component_List (Type_Definition (Parent (Typ)));
15342 Discr := First_Discriminant (Typ);
15343 while Present (Discr) loop
15344 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
15345 Discr_Val := Expression (Parent (Discr));
15347 if Present (Discr_Val)
15348 and then Is_OK_Static_Expression (Discr_Val)
15350 Append_To (Constraints,
15351 Make_Component_Association (Loc,
15352 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
15353 Expression => New_Copy (Discr_Val)));
15361 Next_Discriminant (Discr);
15366 Comp_List => Comp_List,
15367 Governed_By => Constraints,
15368 Into => Components,
15369 Report_Errors => Report_Errors);
15371 -- Check that each component present is fully initialized
15373 Comp_Elmt := First_Elmt (Components);
15374 while Present (Comp_Elmt) loop
15375 Comp_Id := Node (Comp_Elmt);
15377 if Ekind (Comp_Id) = E_Component
15378 and then (No (Parent (Comp_Id))
15379 or else No (Expression (Parent (Comp_Id))))
15380 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
15385 Next_Elmt (Comp_Elmt);
15390 elsif Is_Private_Type (Typ) then
15392 U : constant Entity_Id := Underlying_Type (Typ);
15398 return Is_Fully_Initialized_Variant (U);
15405 end Is_Fully_Initialized_Variant;
15407 ------------------------------------
15408 -- Is_Generic_Declaration_Or_Body --
15409 ------------------------------------
15411 function Is_Generic_Declaration_Or_Body (Decl : Node_Id) return Boolean is
15412 Spec_Decl : Node_Id;
15415 -- Package/subprogram body
15417 if Nkind_In (Decl, N_Package_Body, N_Subprogram_Body)
15418 and then Present (Corresponding_Spec (Decl))
15420 Spec_Decl := Unit_Declaration_Node (Corresponding_Spec (Decl));
15422 -- Package/subprogram body stub
15424 elsif Nkind_In (Decl, N_Package_Body_Stub, N_Subprogram_Body_Stub)
15425 and then Present (Corresponding_Spec_Of_Stub (Decl))
15428 Unit_Declaration_Node (Corresponding_Spec_Of_Stub (Decl));
15436 -- Rather than inspecting the defining entity of the spec declaration,
15437 -- look at its Nkind. This takes care of the case where the analysis of
15438 -- a generic body modifies the Ekind of its spec to allow for recursive
15442 Nkind_In (Spec_Decl, N_Generic_Package_Declaration,
15443 N_Generic_Subprogram_Declaration);
15444 end Is_Generic_Declaration_Or_Body;
15446 ---------------------------
15447 -- Is_Independent_Object --
15448 ---------------------------
15450 function Is_Independent_Object (N : Node_Id) return Boolean is
15451 function Is_Independent_Object_Entity (Id : Entity_Id) return Boolean;
15452 -- Determine whether arbitrary entity Id denotes an object that is
15455 function Prefix_Has_Independent_Components (P : Node_Id) return Boolean;
15456 -- Determine whether prefix P has independent components. This requires
15457 -- the presence of an Independent_Components aspect/pragma.
15459 ------------------------------------
15460 -- Is_Independent_Object_Entity --
15461 ------------------------------------
15463 function Is_Independent_Object_Entity (Id : Entity_Id) return Boolean is
15467 and then (Is_Independent (Id)
15469 Is_Independent (Etype (Id)));
15470 end Is_Independent_Object_Entity;
15472 -------------------------------------
15473 -- Prefix_Has_Independent_Components --
15474 -------------------------------------
15476 function Prefix_Has_Independent_Components (P : Node_Id) return Boolean
15478 Typ : constant Entity_Id := Etype (P);
15481 if Is_Access_Type (Typ) then
15482 return Has_Independent_Components (Designated_Type (Typ));
15484 elsif Has_Independent_Components (Typ) then
15487 elsif Is_Entity_Name (P)
15488 and then Has_Independent_Components (Entity (P))
15495 end Prefix_Has_Independent_Components;
15497 -- Start of processing for Is_Independent_Object
15500 if Is_Entity_Name (N) then
15501 return Is_Independent_Object_Entity (Entity (N));
15503 elsif Is_Independent (Etype (N)) then
15506 elsif Nkind (N) = N_Indexed_Component then
15507 return Prefix_Has_Independent_Components (Prefix (N));
15509 elsif Nkind (N) = N_Selected_Component then
15510 return Prefix_Has_Independent_Components (Prefix (N))
15511 or else Is_Independent (Entity (Selector_Name (N)));
15516 end Is_Independent_Object;
15518 ----------------------------
15519 -- Is_Inherited_Operation --
15520 ----------------------------
15522 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
15523 pragma Assert (Is_Overloadable (E));
15524 Kind : constant Node_Kind := Nkind (Parent (E));
15526 return Kind = N_Full_Type_Declaration
15527 or else Kind = N_Private_Extension_Declaration
15528 or else Kind = N_Subtype_Declaration
15529 or else (Ekind (E) = E_Enumeration_Literal
15530 and then Is_Derived_Type (Etype (E)));
15531 end Is_Inherited_Operation;
15533 -------------------------------------
15534 -- Is_Inherited_Operation_For_Type --
15535 -------------------------------------
15537 function Is_Inherited_Operation_For_Type
15539 Typ : Entity_Id) return Boolean
15542 -- Check that the operation has been created by the type declaration
15544 return Is_Inherited_Operation (E)
15545 and then Defining_Identifier (Parent (E)) = Typ;
15546 end Is_Inherited_Operation_For_Type;
15548 --------------------------------------
15549 -- Is_Inlinable_Expression_Function --
15550 --------------------------------------
15552 function Is_Inlinable_Expression_Function
15553 (Subp : Entity_Id) return Boolean
15555 Return_Expr : Node_Id;
15558 if Is_Expression_Function_Or_Completion (Subp)
15559 and then Has_Pragma_Inline_Always (Subp)
15560 and then Needs_No_Actuals (Subp)
15561 and then No (Contract (Subp))
15562 and then not Is_Dispatching_Operation (Subp)
15563 and then Needs_Finalization (Etype (Subp))
15564 and then not Is_Class_Wide_Type (Etype (Subp))
15565 and then not (Has_Invariants (Etype (Subp)))
15566 and then Present (Subprogram_Body (Subp))
15567 and then Was_Expression_Function (Subprogram_Body (Subp))
15569 Return_Expr := Expression_Of_Expression_Function (Subp);
15571 -- The returned object must not have a qualified expression and its
15572 -- nominal subtype must be statically compatible with the result
15573 -- subtype of the expression function.
15576 Nkind (Return_Expr) = N_Identifier
15577 and then Etype (Return_Expr) = Etype (Subp);
15581 end Is_Inlinable_Expression_Function;
15587 function Is_Iterator (Typ : Entity_Id) return Boolean is
15588 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean;
15589 -- Determine whether type Iter_Typ is a predefined forward or reversible
15592 ----------------------
15593 -- Denotes_Iterator --
15594 ----------------------
15596 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean is
15598 -- Check that the name matches, and that the ultimate ancestor is in
15599 -- a predefined unit, i.e the one that declares iterator interfaces.
15602 Nam_In (Chars (Iter_Typ), Name_Forward_Iterator,
15603 Name_Reversible_Iterator)
15604 and then In_Predefined_Unit (Root_Type (Iter_Typ));
15605 end Denotes_Iterator;
15609 Iface_Elmt : Elmt_Id;
15612 -- Start of processing for Is_Iterator
15615 -- The type may be a subtype of a descendant of the proper instance of
15616 -- the predefined interface type, so we must use the root type of the
15617 -- given type. The same is done for Is_Reversible_Iterator.
15619 if Is_Class_Wide_Type (Typ)
15620 and then Denotes_Iterator (Root_Type (Typ))
15624 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
15627 elsif Present (Find_Value_Of_Aspect (Typ, Aspect_Iterable)) then
15631 Collect_Interfaces (Typ, Ifaces);
15633 Iface_Elmt := First_Elmt (Ifaces);
15634 while Present (Iface_Elmt) loop
15635 if Denotes_Iterator (Node (Iface_Elmt)) then
15639 Next_Elmt (Iface_Elmt);
15646 ----------------------------
15647 -- Is_Iterator_Over_Array --
15648 ----------------------------
15650 function Is_Iterator_Over_Array (N : Node_Id) return Boolean is
15651 Container : constant Node_Id := Name (N);
15652 Container_Typ : constant Entity_Id := Base_Type (Etype (Container));
15654 return Is_Array_Type (Container_Typ);
15655 end Is_Iterator_Over_Array;
15661 -- We seem to have a lot of overlapping functions that do similar things
15662 -- (testing for left hand sides or lvalues???).
15664 function Is_LHS (N : Node_Id) return Is_LHS_Result is
15665 P : constant Node_Id := Parent (N);
15668 -- Return True if we are the left hand side of an assignment statement
15670 if Nkind (P) = N_Assignment_Statement then
15671 if Name (P) = N then
15677 -- Case of prefix of indexed or selected component or slice
15679 elsif Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
15680 and then N = Prefix (P)
15682 -- Here we have the case where the parent P is N.Q or N(Q .. R).
15683 -- If P is an LHS, then N is also effectively an LHS, but there
15684 -- is an important exception. If N is of an access type, then
15685 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
15686 -- case this makes N.all a left hand side but not N itself.
15688 -- If we don't know the type yet, this is the case where we return
15689 -- Unknown, since the answer depends on the type which is unknown.
15691 if No (Etype (N)) then
15694 -- We have an Etype set, so we can check it
15696 elsif Is_Access_Type (Etype (N)) then
15699 -- OK, not access type case, so just test whole expression
15705 -- All other cases are not left hand sides
15712 -----------------------------
15713 -- Is_Library_Level_Entity --
15714 -----------------------------
15716 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
15718 -- The following is a small optimization, and it also properly handles
15719 -- discriminals, which in task bodies might appear in expressions before
15720 -- the corresponding procedure has been created, and which therefore do
15721 -- not have an assigned scope.
15723 if Is_Formal (E) then
15727 -- Normal test is simply that the enclosing dynamic scope is Standard
15729 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
15730 end Is_Library_Level_Entity;
15732 --------------------------------
15733 -- Is_Limited_Class_Wide_Type --
15734 --------------------------------
15736 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
15739 Is_Class_Wide_Type (Typ)
15740 and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
15741 end Is_Limited_Class_Wide_Type;
15743 ---------------------------------
15744 -- Is_Local_Variable_Reference --
15745 ---------------------------------
15747 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
15749 if not Is_Entity_Name (Expr) then
15754 Ent : constant Entity_Id := Entity (Expr);
15755 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
15757 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
15760 return Present (Sub) and then Sub = Current_Subprogram;
15764 end Is_Local_Variable_Reference;
15766 -----------------------
15767 -- Is_Name_Reference --
15768 -----------------------
15770 function Is_Name_Reference (N : Node_Id) return Boolean is
15772 if Is_Entity_Name (N) then
15773 return Present (Entity (N)) and then Is_Object (Entity (N));
15777 when N_Indexed_Component
15781 Is_Name_Reference (Prefix (N))
15782 or else Is_Access_Type (Etype (Prefix (N)));
15784 -- Attributes 'Input, 'Old and 'Result produce objects
15786 when N_Attribute_Reference =>
15788 Nam_In (Attribute_Name (N), Name_Input, Name_Old, Name_Result);
15790 when N_Selected_Component =>
15792 Is_Name_Reference (Selector_Name (N))
15794 (Is_Name_Reference (Prefix (N))
15795 or else Is_Access_Type (Etype (Prefix (N))));
15797 when N_Explicit_Dereference =>
15800 -- A view conversion of a tagged name is a name reference
15802 when N_Type_Conversion =>
15804 Is_Tagged_Type (Etype (Subtype_Mark (N)))
15805 and then Is_Tagged_Type (Etype (Expression (N)))
15806 and then Is_Name_Reference (Expression (N));
15808 -- An unchecked type conversion is considered to be a name if the
15809 -- operand is a name (this construction arises only as a result of
15810 -- expansion activities).
15812 when N_Unchecked_Type_Conversion =>
15813 return Is_Name_Reference (Expression (N));
15818 end Is_Name_Reference;
15820 ------------------------------------
15821 -- Is_Non_Preelaborable_Construct --
15822 ------------------------------------
15824 function Is_Non_Preelaborable_Construct (N : Node_Id) return Boolean is
15826 -- NOTE: the routines within Is_Non_Preelaborable_Construct are
15827 -- intentionally unnested to avoid deep indentation of code.
15829 Non_Preelaborable : exception;
15830 -- This exception is raised when the construct violates preelaborability
15831 -- to terminate the recursion.
15833 procedure Visit (Nod : Node_Id);
15834 -- Semantically inspect construct Nod to determine whether it violates
15835 -- preelaborability. This routine raises Non_Preelaborable.
15837 procedure Visit_List (List : List_Id);
15838 pragma Inline (Visit_List);
15839 -- Invoke Visit on each element of list List. This routine raises
15840 -- Non_Preelaborable.
15842 procedure Visit_Pragma (Prag : Node_Id);
15843 pragma Inline (Visit_Pragma);
15844 -- Semantically inspect pragma Prag to determine whether it violates
15845 -- preelaborability. This routine raises Non_Preelaborable.
15847 procedure Visit_Subexpression (Expr : Node_Id);
15848 pragma Inline (Visit_Subexpression);
15849 -- Semantically inspect expression Expr to determine whether it violates
15850 -- preelaborability. This routine raises Non_Preelaborable.
15856 procedure Visit (Nod : Node_Id) is
15858 case Nkind (Nod) is
15862 when N_Component_Declaration =>
15864 -- Defining_Identifier is left out because it is not relevant
15865 -- for preelaborability.
15867 Visit (Component_Definition (Nod));
15868 Visit (Expression (Nod));
15870 when N_Derived_Type_Definition =>
15872 -- Interface_List is left out because it is not relevant for
15873 -- preelaborability.
15875 Visit (Record_Extension_Part (Nod));
15876 Visit (Subtype_Indication (Nod));
15878 when N_Entry_Declaration =>
15880 -- A protected type with at leat one entry is not preelaborable
15881 -- while task types are never preelaborable. This renders entry
15882 -- declarations non-preelaborable.
15884 raise Non_Preelaborable;
15886 when N_Full_Type_Declaration =>
15888 -- Defining_Identifier and Discriminant_Specifications are left
15889 -- out because they are not relevant for preelaborability.
15891 Visit (Type_Definition (Nod));
15893 when N_Function_Instantiation
15894 | N_Package_Instantiation
15895 | N_Procedure_Instantiation
15897 -- Defining_Unit_Name and Name are left out because they are
15898 -- not relevant for preelaborability.
15900 Visit_List (Generic_Associations (Nod));
15902 when N_Object_Declaration =>
15904 -- Defining_Identifier is left out because it is not relevant
15905 -- for preelaborability.
15907 Visit (Object_Definition (Nod));
15909 if Has_Init_Expression (Nod) then
15910 Visit (Expression (Nod));
15912 elsif not Has_Preelaborable_Initialization
15913 (Etype (Defining_Entity (Nod)))
15915 raise Non_Preelaborable;
15918 when N_Private_Extension_Declaration
15919 | N_Subtype_Declaration
15921 -- Defining_Identifier, Discriminant_Specifications, and
15922 -- Interface_List are left out because they are not relevant
15923 -- for preelaborability.
15925 Visit (Subtype_Indication (Nod));
15927 when N_Protected_Type_Declaration
15928 | N_Single_Protected_Declaration
15930 -- Defining_Identifier, Discriminant_Specifications, and
15931 -- Interface_List are left out because they are not relevant
15932 -- for preelaborability.
15934 Visit (Protected_Definition (Nod));
15936 -- A [single] task type is never preelaborable
15938 when N_Single_Task_Declaration
15939 | N_Task_Type_Declaration
15941 raise Non_Preelaborable;
15946 Visit_Pragma (Nod);
15950 when N_Statement_Other_Than_Procedure_Call =>
15951 if Nkind (Nod) /= N_Null_Statement then
15952 raise Non_Preelaborable;
15958 Visit_Subexpression (Nod);
15962 when N_Access_To_Object_Definition =>
15963 Visit (Subtype_Indication (Nod));
15965 when N_Case_Expression_Alternative =>
15966 Visit (Expression (Nod));
15967 Visit_List (Discrete_Choices (Nod));
15969 when N_Component_Definition =>
15970 Visit (Access_Definition (Nod));
15971 Visit (Subtype_Indication (Nod));
15973 when N_Component_List =>
15974 Visit_List (Component_Items (Nod));
15975 Visit (Variant_Part (Nod));
15977 when N_Constrained_Array_Definition =>
15978 Visit_List (Discrete_Subtype_Definitions (Nod));
15979 Visit (Component_Definition (Nod));
15981 when N_Delta_Constraint
15982 | N_Digits_Constraint
15984 -- Delta_Expression and Digits_Expression are left out because
15985 -- they are not relevant for preelaborability.
15987 Visit (Range_Constraint (Nod));
15989 when N_Discriminant_Specification =>
15991 -- Defining_Identifier and Expression are left out because they
15992 -- are not relevant for preelaborability.
15994 Visit (Discriminant_Type (Nod));
15996 when N_Generic_Association =>
15998 -- Selector_Name is left out because it is not relevant for
15999 -- preelaborability.
16001 Visit (Explicit_Generic_Actual_Parameter (Nod));
16003 when N_Index_Or_Discriminant_Constraint =>
16004 Visit_List (Constraints (Nod));
16006 when N_Iterator_Specification =>
16008 -- Defining_Identifier is left out because it is not relevant
16009 -- for preelaborability.
16011 Visit (Name (Nod));
16012 Visit (Subtype_Indication (Nod));
16014 when N_Loop_Parameter_Specification =>
16016 -- Defining_Identifier is left out because it is not relevant
16017 -- for preelaborability.
16019 Visit (Discrete_Subtype_Definition (Nod));
16021 when N_Protected_Definition =>
16023 -- End_Label is left out because it is not relevant for
16024 -- preelaborability.
16026 Visit_List (Private_Declarations (Nod));
16027 Visit_List (Visible_Declarations (Nod));
16029 when N_Range_Constraint =>
16030 Visit (Range_Expression (Nod));
16032 when N_Record_Definition
16035 -- End_Label, Discrete_Choices, and Interface_List are left out
16036 -- because they are not relevant for preelaborability.
16038 Visit (Component_List (Nod));
16040 when N_Subtype_Indication =>
16042 -- Subtype_Mark is left out because it is not relevant for
16043 -- preelaborability.
16045 Visit (Constraint (Nod));
16047 when N_Unconstrained_Array_Definition =>
16049 -- Subtype_Marks is left out because it is not relevant for
16050 -- preelaborability.
16052 Visit (Component_Definition (Nod));
16054 when N_Variant_Part =>
16056 -- Name is left out because it is not relevant for
16057 -- preelaborability.
16059 Visit_List (Variants (Nod));
16072 procedure Visit_List (List : List_Id) is
16076 if Present (List) then
16077 Nod := First (List);
16078 while Present (Nod) loop
16089 procedure Visit_Pragma (Prag : Node_Id) is
16091 case Get_Pragma_Id (Prag) is
16093 | Pragma_Assert_And_Cut
16095 | Pragma_Async_Readers
16096 | Pragma_Async_Writers
16097 | Pragma_Attribute_Definition
16099 | Pragma_Constant_After_Elaboration
16101 | Pragma_Deadline_Floor
16102 | Pragma_Dispatching_Domain
16103 | Pragma_Effective_Reads
16104 | Pragma_Effective_Writes
16105 | Pragma_Extensions_Visible
16107 | Pragma_Secondary_Stack_Size
16109 | Pragma_Volatile_Function
16111 Visit_List (Pragma_Argument_Associations (Prag));
16120 -------------------------
16121 -- Visit_Subexpression --
16122 -------------------------
16124 procedure Visit_Subexpression (Expr : Node_Id) is
16125 procedure Visit_Aggregate (Aggr : Node_Id);
16126 pragma Inline (Visit_Aggregate);
16127 -- Semantically inspect aggregate Aggr to determine whether it
16128 -- violates preelaborability.
16130 ---------------------
16131 -- Visit_Aggregate --
16132 ---------------------
16134 procedure Visit_Aggregate (Aggr : Node_Id) is
16136 if not Is_Preelaborable_Aggregate (Aggr) then
16137 raise Non_Preelaborable;
16139 end Visit_Aggregate;
16141 -- Start of processing for Visit_Subexpression
16144 case Nkind (Expr) is
16146 | N_Qualified_Expression
16147 | N_Type_Conversion
16148 | N_Unchecked_Expression
16149 | N_Unchecked_Type_Conversion
16151 -- Subpool_Handle_Name and Subtype_Mark are left out because
16152 -- they are not relevant for preelaborability.
16154 Visit (Expression (Expr));
16157 | N_Extension_Aggregate
16159 Visit_Aggregate (Expr);
16161 when N_Attribute_Reference
16162 | N_Explicit_Dereference
16165 -- Attribute_Name and Expressions are left out because they are
16166 -- not relevant for preelaborability.
16168 Visit (Prefix (Expr));
16170 when N_Case_Expression =>
16172 -- End_Span is left out because it is not relevant for
16173 -- preelaborability.
16175 Visit_List (Alternatives (Expr));
16176 Visit (Expression (Expr));
16178 when N_Delta_Aggregate =>
16179 Visit_Aggregate (Expr);
16180 Visit (Expression (Expr));
16182 when N_Expression_With_Actions =>
16183 Visit_List (Actions (Expr));
16184 Visit (Expression (Expr));
16186 when N_If_Expression =>
16187 Visit_List (Expressions (Expr));
16189 when N_Quantified_Expression =>
16190 Visit (Condition (Expr));
16191 Visit (Iterator_Specification (Expr));
16192 Visit (Loop_Parameter_Specification (Expr));
16195 Visit (High_Bound (Expr));
16196 Visit (Low_Bound (Expr));
16199 Visit (Discrete_Range (Expr));
16200 Visit (Prefix (Expr));
16206 -- The evaluation of an object name is not preelaborable,
16207 -- unless the name is a static expression (checked further
16208 -- below), or statically denotes a discriminant.
16210 if Is_Entity_Name (Expr) then
16211 Object_Name : declare
16212 Id : constant Entity_Id := Entity (Expr);
16215 if Is_Object (Id) then
16216 if Ekind (Id) = E_Discriminant then
16219 elsif Ekind_In (Id, E_Constant, E_In_Parameter)
16220 and then Present (Discriminal_Link (Id))
16225 raise Non_Preelaborable;
16230 -- A non-static expression is not preelaborable
16232 elsif not Is_OK_Static_Expression (Expr) then
16233 raise Non_Preelaborable;
16236 end Visit_Subexpression;
16238 -- Start of processing for Is_Non_Preelaborable_Construct
16243 -- At this point it is known that the construct is preelaborable
16249 -- The elaboration of the construct performs an action which violates
16250 -- preelaborability.
16252 when Non_Preelaborable =>
16254 end Is_Non_Preelaborable_Construct;
16256 ---------------------------------
16257 -- Is_Nontrivial_DIC_Procedure --
16258 ---------------------------------
16260 function Is_Nontrivial_DIC_Procedure (Id : Entity_Id) return Boolean is
16261 Body_Decl : Node_Id;
16265 if Ekind (Id) = E_Procedure and then Is_DIC_Procedure (Id) then
16267 Unit_Declaration_Node
16268 (Corresponding_Body (Unit_Declaration_Node (Id)));
16270 -- The body of the Default_Initial_Condition procedure must contain
16271 -- at least one statement, otherwise the generation of the subprogram
16274 pragma Assert (Present (Handled_Statement_Sequence (Body_Decl)));
16276 -- To qualify as nontrivial, the first statement of the procedure
16277 -- must be a check in the form of an if statement. If the original
16278 -- Default_Initial_Condition expression was folded, then the first
16279 -- statement is not a check.
16281 Stmt := First (Statements (Handled_Statement_Sequence (Body_Decl)));
16284 Nkind (Stmt) = N_If_Statement
16285 and then Nkind (Original_Node (Stmt)) = N_Pragma;
16289 end Is_Nontrivial_DIC_Procedure;
16291 -------------------------
16292 -- Is_Null_Record_Type --
16293 -------------------------
16295 function Is_Null_Record_Type (T : Entity_Id) return Boolean is
16296 Decl : constant Node_Id := Parent (T);
16298 return Nkind (Decl) = N_Full_Type_Declaration
16299 and then Nkind (Type_Definition (Decl)) = N_Record_Definition
16301 (No (Component_List (Type_Definition (Decl)))
16302 or else Null_Present (Component_List (Type_Definition (Decl))));
16303 end Is_Null_Record_Type;
16305 ---------------------
16306 -- Is_Object_Image --
16307 ---------------------
16309 function Is_Object_Image (Prefix : Node_Id) return Boolean is
16311 -- When the type of the prefix is not scalar, then the prefix is not
16312 -- valid in any scenario.
16314 if not Is_Scalar_Type (Etype (Prefix)) then
16318 -- Here we test for the case that the prefix is not a type and assume
16319 -- if it is not then it must be a named value or an object reference.
16320 -- This is because the parser always checks that prefixes of attributes
16323 return not (Is_Entity_Name (Prefix) and then Is_Type (Entity (Prefix)));
16324 end Is_Object_Image;
16326 -------------------------
16327 -- Is_Object_Reference --
16328 -------------------------
16330 function Is_Object_Reference (N : Node_Id) return Boolean is
16331 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean;
16332 -- Determine whether N is the name of an internally-generated renaming
16334 --------------------------------------
16335 -- Is_Internally_Generated_Renaming --
16336 --------------------------------------
16338 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean is
16343 while Present (P) loop
16344 if Nkind (P) = N_Object_Renaming_Declaration then
16345 return not Comes_From_Source (P);
16346 elsif Is_List_Member (P) then
16354 end Is_Internally_Generated_Renaming;
16356 -- Start of processing for Is_Object_Reference
16359 if Is_Entity_Name (N) then
16360 return Present (Entity (N)) and then Is_Object (Entity (N));
16364 when N_Indexed_Component
16368 Is_Object_Reference (Prefix (N))
16369 or else Is_Access_Type (Etype (Prefix (N)));
16371 -- In Ada 95, a function call is a constant object; a procedure
16374 -- Note that predefined operators are functions as well, and so
16375 -- are attributes that are (can be renamed as) functions.
16381 return Etype (N) /= Standard_Void_Type;
16383 -- Attributes references 'Loop_Entry, 'Old, and 'Result yield
16384 -- objects, even though they are not functions.
16386 when N_Attribute_Reference =>
16388 Nam_In (Attribute_Name (N), Name_Loop_Entry,
16391 or else Is_Function_Attribute_Name (Attribute_Name (N));
16393 when N_Selected_Component =>
16395 Is_Object_Reference (Selector_Name (N))
16397 (Is_Object_Reference (Prefix (N))
16398 or else Is_Access_Type (Etype (Prefix (N))));
16400 -- An explicit dereference denotes an object, except that a
16401 -- conditional expression gets turned into an explicit dereference
16402 -- in some cases, and conditional expressions are not object
16405 when N_Explicit_Dereference =>
16406 return not Nkind_In (Original_Node (N), N_Case_Expression,
16409 -- A view conversion of a tagged object is an object reference
16411 when N_Type_Conversion =>
16412 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
16413 and then Is_Tagged_Type (Etype (Expression (N)))
16414 and then Is_Object_Reference (Expression (N));
16416 -- An unchecked type conversion is considered to be an object if
16417 -- the operand is an object (this construction arises only as a
16418 -- result of expansion activities).
16420 when N_Unchecked_Type_Conversion =>
16423 -- Allow string literals to act as objects as long as they appear
16424 -- in internally-generated renamings. The expansion of iterators
16425 -- may generate such renamings when the range involves a string
16428 when N_String_Literal =>
16429 return Is_Internally_Generated_Renaming (Parent (N));
16431 -- AI05-0003: In Ada 2012 a qualified expression is a name.
16432 -- This allows disambiguation of function calls and the use
16433 -- of aggregates in more contexts.
16435 when N_Qualified_Expression =>
16436 if Ada_Version < Ada_2012 then
16439 return Is_Object_Reference (Expression (N))
16440 or else Nkind (Expression (N)) = N_Aggregate;
16447 end Is_Object_Reference;
16449 -----------------------------------
16450 -- Is_OK_Variable_For_Out_Formal --
16451 -----------------------------------
16453 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
16455 Note_Possible_Modification (AV, Sure => True);
16457 -- We must reject parenthesized variable names. Comes_From_Source is
16458 -- checked because there are currently cases where the compiler violates
16459 -- this rule (e.g. passing a task object to its controlled Initialize
16460 -- routine). This should be properly documented in sinfo???
16462 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
16465 -- A variable is always allowed
16467 elsif Is_Variable (AV) then
16470 -- Generalized indexing operations are rewritten as explicit
16471 -- dereferences, and it is only during resolution that we can
16472 -- check whether the context requires an access_to_variable type.
16474 elsif Nkind (AV) = N_Explicit_Dereference
16475 and then Ada_Version >= Ada_2012
16476 and then Nkind (Original_Node (AV)) = N_Indexed_Component
16477 and then Present (Etype (Original_Node (AV)))
16478 and then Has_Implicit_Dereference (Etype (Original_Node (AV)))
16480 return not Is_Access_Constant (Etype (Prefix (AV)));
16482 -- Unchecked conversions are allowed only if they come from the
16483 -- generated code, which sometimes uses unchecked conversions for out
16484 -- parameters in cases where code generation is unaffected. We tell
16485 -- source unchecked conversions by seeing if they are rewrites of
16486 -- an original Unchecked_Conversion function call, or of an explicit
16487 -- conversion of a function call or an aggregate (as may happen in the
16488 -- expansion of a packed array aggregate).
16490 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
16491 if Nkind_In (Original_Node (AV), N_Function_Call, N_Aggregate) then
16494 elsif Comes_From_Source (AV)
16495 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
16499 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
16500 return Is_OK_Variable_For_Out_Formal (Expression (AV));
16506 -- Normal type conversions are allowed if argument is a variable
16508 elsif Nkind (AV) = N_Type_Conversion then
16509 if Is_Variable (Expression (AV))
16510 and then Paren_Count (Expression (AV)) = 0
16512 Note_Possible_Modification (Expression (AV), Sure => True);
16515 -- We also allow a non-parenthesized expression that raises
16516 -- constraint error if it rewrites what used to be a variable
16518 elsif Raises_Constraint_Error (Expression (AV))
16519 and then Paren_Count (Expression (AV)) = 0
16520 and then Is_Variable (Original_Node (Expression (AV)))
16524 -- Type conversion of something other than a variable
16530 -- If this node is rewritten, then test the original form, if that is
16531 -- OK, then we consider the rewritten node OK (for example, if the
16532 -- original node is a conversion, then Is_Variable will not be true
16533 -- but we still want to allow the conversion if it converts a variable).
16535 elsif Is_Rewrite_Substitution (AV) then
16537 -- In Ada 2012, the explicit dereference may be a rewritten call to a
16538 -- Reference function.
16540 if Ada_Version >= Ada_2012
16541 and then Nkind (Original_Node (AV)) = N_Function_Call
16543 Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
16546 -- Check that this is not a constant reference.
16548 return not Is_Access_Constant (Etype (Prefix (AV)));
16550 elsif Has_Implicit_Dereference (Etype (Original_Node (AV))) then
16552 not Is_Access_Constant (Etype
16553 (Get_Reference_Discriminant (Etype (Original_Node (AV)))));
16556 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
16559 -- All other non-variables are rejected
16564 end Is_OK_Variable_For_Out_Formal;
16566 ----------------------------
16567 -- Is_OK_Volatile_Context --
16568 ----------------------------
16570 function Is_OK_Volatile_Context
16571 (Context : Node_Id;
16572 Obj_Ref : Node_Id) return Boolean
16574 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean;
16575 -- Determine whether an arbitrary node denotes a call to a protected
16576 -- entry, function, or procedure in prefixed form where the prefix is
16579 function Within_Check (Nod : Node_Id) return Boolean;
16580 -- Determine whether an arbitrary node appears in a check node
16582 function Within_Volatile_Function (Id : Entity_Id) return Boolean;
16583 -- Determine whether an arbitrary entity appears in a volatile function
16585 ---------------------------------
16586 -- Is_Protected_Operation_Call --
16587 ---------------------------------
16589 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean is
16594 -- A call to a protected operations retains its selected component
16595 -- form as opposed to other prefixed calls that are transformed in
16598 if Nkind (Nod) = N_Selected_Component then
16599 Pref := Prefix (Nod);
16600 Subp := Selector_Name (Nod);
16604 and then Present (Etype (Pref))
16605 and then Is_Protected_Type (Etype (Pref))
16606 and then Is_Entity_Name (Subp)
16607 and then Present (Entity (Subp))
16608 and then Ekind_In (Entity (Subp), E_Entry,
16615 end Is_Protected_Operation_Call;
16621 function Within_Check (Nod : Node_Id) return Boolean is
16625 -- Climb the parent chain looking for a check node
16628 while Present (Par) loop
16629 if Nkind (Par) in N_Raise_xxx_Error then
16632 -- Prevent the search from going too far
16634 elsif Is_Body_Or_Package_Declaration (Par) then
16638 Par := Parent (Par);
16644 ------------------------------
16645 -- Within_Volatile_Function --
16646 ------------------------------
16648 function Within_Volatile_Function (Id : Entity_Id) return Boolean is
16649 Func_Id : Entity_Id;
16652 -- Traverse the scope stack looking for a [generic] function
16655 while Present (Func_Id) and then Func_Id /= Standard_Standard loop
16656 if Ekind_In (Func_Id, E_Function, E_Generic_Function) then
16657 return Is_Volatile_Function (Func_Id);
16660 Func_Id := Scope (Func_Id);
16664 end Within_Volatile_Function;
16668 Obj_Id : Entity_Id;
16670 -- Start of processing for Is_OK_Volatile_Context
16673 -- The volatile object appears on either side of an assignment
16675 if Nkind (Context) = N_Assignment_Statement then
16678 -- The volatile object is part of the initialization expression of
16681 elsif Nkind (Context) = N_Object_Declaration
16682 and then Present (Expression (Context))
16683 and then Expression (Context) = Obj_Ref
16685 Obj_Id := Defining_Entity (Context);
16687 -- The volatile object acts as the initialization expression of an
16688 -- extended return statement. This is valid context as long as the
16689 -- function is volatile.
16691 if Is_Return_Object (Obj_Id) then
16692 return Within_Volatile_Function (Obj_Id);
16694 -- Otherwise this is a normal object initialization
16700 -- The volatile object acts as the name of a renaming declaration
16702 elsif Nkind (Context) = N_Object_Renaming_Declaration
16703 and then Name (Context) = Obj_Ref
16707 -- The volatile object appears as an actual parameter in a call to an
16708 -- instance of Unchecked_Conversion whose result is renamed.
16710 elsif Nkind (Context) = N_Function_Call
16711 and then Is_Entity_Name (Name (Context))
16712 and then Is_Unchecked_Conversion_Instance (Entity (Name (Context)))
16713 and then Nkind (Parent (Context)) = N_Object_Renaming_Declaration
16717 -- The volatile object is actually the prefix in a protected entry,
16718 -- function, or procedure call.
16720 elsif Is_Protected_Operation_Call (Context) then
16723 -- The volatile object appears as the expression of a simple return
16724 -- statement that applies to a volatile function.
16726 elsif Nkind (Context) = N_Simple_Return_Statement
16727 and then Expression (Context) = Obj_Ref
16730 Within_Volatile_Function (Return_Statement_Entity (Context));
16732 -- The volatile object appears as the prefix of a name occurring in a
16733 -- non-interfering context.
16735 elsif Nkind_In (Context, N_Attribute_Reference,
16736 N_Explicit_Dereference,
16737 N_Indexed_Component,
16738 N_Selected_Component,
16740 and then Prefix (Context) = Obj_Ref
16741 and then Is_OK_Volatile_Context
16742 (Context => Parent (Context),
16743 Obj_Ref => Context)
16747 -- The volatile object appears as the prefix of attributes Address,
16748 -- Alignment, Component_Size, First, First_Bit, Last, Last_Bit, Length,
16749 -- Position, Size, Storage_Size.
16751 elsif Nkind (Context) = N_Attribute_Reference
16752 and then Prefix (Context) = Obj_Ref
16753 and then Nam_In (Attribute_Name (Context), Name_Address,
16755 Name_Component_Size,
16767 -- The volatile object appears as the expression of a type conversion
16768 -- occurring in a non-interfering context.
16770 elsif Nkind_In (Context, N_Type_Conversion,
16771 N_Unchecked_Type_Conversion)
16772 and then Expression (Context) = Obj_Ref
16773 and then Is_OK_Volatile_Context
16774 (Context => Parent (Context),
16775 Obj_Ref => Context)
16779 -- The volatile object appears as the expression in a delay statement
16781 elsif Nkind (Context) in N_Delay_Statement then
16784 -- Allow references to volatile objects in various checks. This is not a
16785 -- direct SPARK 2014 requirement.
16787 elsif Within_Check (Context) then
16790 -- Assume that references to effectively volatile objects that appear
16791 -- as actual parameters in a subprogram call are always legal. A full
16792 -- legality check is done when the actuals are resolved (see routine
16793 -- Resolve_Actuals).
16795 elsif Within_Subprogram_Call (Context) then
16798 -- Otherwise the context is not suitable for an effectively volatile
16804 end Is_OK_Volatile_Context;
16806 ------------------------------------
16807 -- Is_Package_Contract_Annotation --
16808 ------------------------------------
16810 function Is_Package_Contract_Annotation (Item : Node_Id) return Boolean is
16814 if Nkind (Item) = N_Aspect_Specification then
16815 Nam := Chars (Identifier (Item));
16817 else pragma Assert (Nkind (Item) = N_Pragma);
16818 Nam := Pragma_Name (Item);
16821 return Nam = Name_Abstract_State
16822 or else Nam = Name_Initial_Condition
16823 or else Nam = Name_Initializes
16824 or else Nam = Name_Refined_State;
16825 end Is_Package_Contract_Annotation;
16827 -----------------------------------
16828 -- Is_Partially_Initialized_Type --
16829 -----------------------------------
16831 function Is_Partially_Initialized_Type
16833 Include_Implicit : Boolean := True) return Boolean
16836 if Is_Scalar_Type (Typ) then
16839 elsif Is_Access_Type (Typ) then
16840 return Include_Implicit;
16842 elsif Is_Array_Type (Typ) then
16844 -- If component type is partially initialized, so is array type
16846 if Is_Partially_Initialized_Type
16847 (Component_Type (Typ), Include_Implicit)
16851 -- Otherwise we are only partially initialized if we are fully
16852 -- initialized (this is the empty array case, no point in us
16853 -- duplicating that code here).
16856 return Is_Fully_Initialized_Type (Typ);
16859 elsif Is_Record_Type (Typ) then
16861 -- A discriminated type is always partially initialized if in
16864 if Has_Discriminants (Typ) and then Include_Implicit then
16867 -- A tagged type is always partially initialized
16869 elsif Is_Tagged_Type (Typ) then
16872 -- Case of non-discriminated record
16878 Component_Present : Boolean := False;
16879 -- Set True if at least one component is present. If no
16880 -- components are present, then record type is fully
16881 -- initialized (another odd case, like the null array).
16884 -- Loop through components
16886 Ent := First_Entity (Typ);
16887 while Present (Ent) loop
16888 if Ekind (Ent) = E_Component then
16889 Component_Present := True;
16891 -- If a component has an initialization expression then
16892 -- the enclosing record type is partially initialized
16894 if Present (Parent (Ent))
16895 and then Present (Expression (Parent (Ent)))
16899 -- If a component is of a type which is itself partially
16900 -- initialized, then the enclosing record type is also.
16902 elsif Is_Partially_Initialized_Type
16903 (Etype (Ent), Include_Implicit)
16912 -- No initialized components found. If we found any components
16913 -- they were all uninitialized so the result is false.
16915 if Component_Present then
16918 -- But if we found no components, then all the components are
16919 -- initialized so we consider the type to be initialized.
16927 -- Concurrent types are always fully initialized
16929 elsif Is_Concurrent_Type (Typ) then
16932 -- For a private type, go to underlying type. If there is no underlying
16933 -- type then just assume this partially initialized. Not clear if this
16934 -- can happen in a non-error case, but no harm in testing for this.
16936 elsif Is_Private_Type (Typ) then
16938 U : constant Entity_Id := Underlying_Type (Typ);
16943 return Is_Partially_Initialized_Type (U, Include_Implicit);
16947 -- For any other type (are there any?) assume partially initialized
16952 end Is_Partially_Initialized_Type;
16954 ------------------------------------
16955 -- Is_Potentially_Persistent_Type --
16956 ------------------------------------
16958 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
16963 -- For private type, test corresponding full type
16965 if Is_Private_Type (T) then
16966 return Is_Potentially_Persistent_Type (Full_View (T));
16968 -- Scalar types are potentially persistent
16970 elsif Is_Scalar_Type (T) then
16973 -- Record type is potentially persistent if not tagged and the types of
16974 -- all it components are potentially persistent, and no component has
16975 -- an initialization expression.
16977 elsif Is_Record_Type (T)
16978 and then not Is_Tagged_Type (T)
16979 and then not Is_Partially_Initialized_Type (T)
16981 Comp := First_Component (T);
16982 while Present (Comp) loop
16983 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
16986 Next_Entity (Comp);
16992 -- Array type is potentially persistent if its component type is
16993 -- potentially persistent and if all its constraints are static.
16995 elsif Is_Array_Type (T) then
16996 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
17000 Indx := First_Index (T);
17001 while Present (Indx) loop
17002 if not Is_OK_Static_Subtype (Etype (Indx)) then
17011 -- All other types are not potentially persistent
17016 end Is_Potentially_Persistent_Type;
17018 --------------------------------
17019 -- Is_Potentially_Unevaluated --
17020 --------------------------------
17022 function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is
17030 -- A postcondition whose expression is a short-circuit is broken down
17031 -- into individual aspects for better exception reporting. The original
17032 -- short-circuit expression is rewritten as the second operand, and an
17033 -- occurrence of 'Old in that operand is potentially unevaluated.
17034 -- See sem_ch13.adb for details of this transformation. The reference
17035 -- to 'Old may appear within an expression, so we must look for the
17036 -- enclosing pragma argument in the tree that contains the reference.
17038 while Present (Par)
17039 and then Nkind (Par) /= N_Pragma_Argument_Association
17041 if Is_Rewrite_Substitution (Par)
17042 and then Nkind (Original_Node (Par)) = N_And_Then
17047 Par := Parent (Par);
17050 -- Other cases; 'Old appears within other expression (not the top-level
17051 -- conjunct in a postcondition) with a potentially unevaluated operand.
17053 Par := Parent (Expr);
17054 while not Nkind_In (Par, N_And_Then,
17060 N_Quantified_Expression)
17063 Par := Parent (Par);
17065 -- If the context is not an expression, or if is the result of
17066 -- expansion of an enclosing construct (such as another attribute)
17067 -- the predicate does not apply.
17069 if Nkind (Par) = N_Case_Expression_Alternative then
17072 elsif Nkind (Par) not in N_Subexpr
17073 or else not Comes_From_Source (Par)
17079 if Nkind (Par) = N_If_Expression then
17080 return Is_Elsif (Par) or else Expr /= First (Expressions (Par));
17082 elsif Nkind (Par) = N_Case_Expression then
17083 return Expr /= Expression (Par);
17085 elsif Nkind_In (Par, N_And_Then, N_Or_Else) then
17086 return Expr = Right_Opnd (Par);
17088 elsif Nkind_In (Par, N_In, N_Not_In) then
17090 -- If the membership includes several alternatives, only the first is
17091 -- definitely evaluated.
17093 if Present (Alternatives (Par)) then
17094 return Expr /= First (Alternatives (Par));
17096 -- If this is a range membership both bounds are evaluated
17102 elsif Nkind (Par) = N_Quantified_Expression then
17103 return Expr = Condition (Par);
17108 end Is_Potentially_Unevaluated;
17110 -----------------------------------------
17111 -- Is_Predefined_Dispatching_Operation --
17112 -----------------------------------------
17114 function Is_Predefined_Dispatching_Operation
17115 (E : Entity_Id) return Boolean
17117 TSS_Name : TSS_Name_Type;
17120 if not Is_Dispatching_Operation (E) then
17124 Get_Name_String (Chars (E));
17126 -- Most predefined primitives have internally generated names. Equality
17127 -- must be treated differently; the predefined operation is recognized
17128 -- as a homogeneous binary operator that returns Boolean.
17130 if Name_Len > TSS_Name_Type'Last then
17133 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
17135 if Nam_In (Chars (E), Name_uAssign, Name_uSize)
17137 (Chars (E) = Name_Op_Eq
17138 and then Etype (First_Formal (E)) = Etype (Last_Formal (E)))
17139 or else TSS_Name = TSS_Deep_Adjust
17140 or else TSS_Name = TSS_Deep_Finalize
17141 or else TSS_Name = TSS_Stream_Input
17142 or else TSS_Name = TSS_Stream_Output
17143 or else TSS_Name = TSS_Stream_Read
17144 or else TSS_Name = TSS_Stream_Write
17145 or else Is_Predefined_Interface_Primitive (E)
17152 end Is_Predefined_Dispatching_Operation;
17154 ---------------------------------------
17155 -- Is_Predefined_Interface_Primitive --
17156 ---------------------------------------
17158 function Is_Predefined_Interface_Primitive (E : Entity_Id) return Boolean is
17160 -- In VM targets we don't restrict the functionality of this test to
17161 -- compiling in Ada 2005 mode since in VM targets any tagged type has
17162 -- these primitives.
17164 return (Ada_Version >= Ada_2005 or else not Tagged_Type_Expansion)
17165 and then Nam_In (Chars (E), Name_uDisp_Asynchronous_Select,
17166 Name_uDisp_Conditional_Select,
17167 Name_uDisp_Get_Prim_Op_Kind,
17168 Name_uDisp_Get_Task_Id,
17169 Name_uDisp_Requeue,
17170 Name_uDisp_Timed_Select);
17171 end Is_Predefined_Interface_Primitive;
17173 ---------------------------------------
17174 -- Is_Predefined_Internal_Operation --
17175 ---------------------------------------
17177 function Is_Predefined_Internal_Operation
17178 (E : Entity_Id) return Boolean
17180 TSS_Name : TSS_Name_Type;
17183 if not Is_Dispatching_Operation (E) then
17187 Get_Name_String (Chars (E));
17189 -- Most predefined primitives have internally generated names. Equality
17190 -- must be treated differently; the predefined operation is recognized
17191 -- as a homogeneous binary operator that returns Boolean.
17193 if Name_Len > TSS_Name_Type'Last then
17196 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
17198 if Nam_In (Chars (E), Name_uSize, Name_uAssign)
17200 (Chars (E) = Name_Op_Eq
17201 and then Etype (First_Formal (E)) = Etype (Last_Formal (E)))
17202 or else TSS_Name = TSS_Deep_Adjust
17203 or else TSS_Name = TSS_Deep_Finalize
17204 or else Is_Predefined_Interface_Primitive (E)
17211 end Is_Predefined_Internal_Operation;
17213 --------------------------------
17214 -- Is_Preelaborable_Aggregate --
17215 --------------------------------
17217 function Is_Preelaborable_Aggregate (Aggr : Node_Id) return Boolean is
17218 Aggr_Typ : constant Entity_Id := Etype (Aggr);
17219 Array_Aggr : constant Boolean := Is_Array_Type (Aggr_Typ);
17221 Anc_Part : Node_Id;
17224 Comp_Typ : Entity_Id := Empty; -- init to avoid warning
17229 Comp_Typ := Component_Type (Aggr_Typ);
17232 -- Inspect the ancestor part
17234 if Nkind (Aggr) = N_Extension_Aggregate then
17235 Anc_Part := Ancestor_Part (Aggr);
17237 -- The ancestor denotes a subtype mark
17239 if Is_Entity_Name (Anc_Part)
17240 and then Is_Type (Entity (Anc_Part))
17242 if not Has_Preelaborable_Initialization (Entity (Anc_Part)) then
17246 -- Otherwise the ancestor denotes an expression
17248 elsif not Is_Preelaborable_Construct (Anc_Part) then
17253 -- Inspect the positional associations
17255 Expr := First (Expressions (Aggr));
17256 while Present (Expr) loop
17257 if not Is_Preelaborable_Construct (Expr) then
17264 -- Inspect the named associations
17266 Assoc := First (Component_Associations (Aggr));
17267 while Present (Assoc) loop
17269 -- Inspect the choices of the current named association
17271 Choice := First (Choices (Assoc));
17272 while Present (Choice) loop
17275 -- For a choice to be preelaborable, it must denote either a
17276 -- static range or a static expression.
17278 if Nkind (Choice) = N_Others_Choice then
17281 elsif Nkind (Choice) = N_Range then
17282 if not Is_OK_Static_Range (Choice) then
17286 elsif not Is_OK_Static_Expression (Choice) then
17291 Comp_Typ := Etype (Choice);
17297 -- The type of the choice must have preelaborable initialization if
17298 -- the association carries a <>.
17300 pragma Assert (Present (Comp_Typ));
17301 if Box_Present (Assoc) then
17302 if not Has_Preelaborable_Initialization (Comp_Typ) then
17306 -- The type of the expression must have preelaborable initialization
17308 elsif not Is_Preelaborable_Construct (Expression (Assoc)) then
17315 -- At this point the aggregate is preelaborable
17318 end Is_Preelaborable_Aggregate;
17320 --------------------------------
17321 -- Is_Preelaborable_Construct --
17322 --------------------------------
17324 function Is_Preelaborable_Construct (N : Node_Id) return Boolean is
17328 if Nkind_In (N, N_Aggregate, N_Extension_Aggregate) then
17329 return Is_Preelaborable_Aggregate (N);
17331 -- Attributes are allowed in general, even if their prefix is a formal
17332 -- type. It seems that certain attributes known not to be static might
17333 -- not be allowed, but there are no rules to prevent them.
17335 elsif Nkind (N) = N_Attribute_Reference then
17340 elsif Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
17343 elsif Nkind (N) = N_Qualified_Expression then
17344 return Is_Preelaborable_Construct (Expression (N));
17346 -- Names are preelaborable when they denote a discriminant of an
17347 -- enclosing type. Discriminals are also considered for this check.
17349 elsif Is_Entity_Name (N)
17350 and then Present (Entity (N))
17352 (Ekind (Entity (N)) = E_Discriminant
17353 or else (Ekind_In (Entity (N), E_Constant, E_In_Parameter)
17354 and then Present (Discriminal_Link (Entity (N)))))
17360 elsif Nkind (N) = N_Null then
17363 -- Otherwise the construct is not preelaborable
17368 end Is_Preelaborable_Construct;
17370 ---------------------------------
17371 -- Is_Protected_Self_Reference --
17372 ---------------------------------
17374 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
17376 function In_Access_Definition (N : Node_Id) return Boolean;
17377 -- Returns true if N belongs to an access definition
17379 --------------------------
17380 -- In_Access_Definition --
17381 --------------------------
17383 function In_Access_Definition (N : Node_Id) return Boolean is
17388 while Present (P) loop
17389 if Nkind (P) = N_Access_Definition then
17397 end In_Access_Definition;
17399 -- Start of processing for Is_Protected_Self_Reference
17402 -- Verify that prefix is analyzed and has the proper form. Note that
17403 -- the attributes Elab_Spec, Elab_Body, and Elab_Subp_Body, which also
17404 -- produce the address of an entity, do not analyze their prefix
17405 -- because they denote entities that are not necessarily visible.
17406 -- Neither of them can apply to a protected type.
17408 return Ada_Version >= Ada_2005
17409 and then Is_Entity_Name (N)
17410 and then Present (Entity (N))
17411 and then Is_Protected_Type (Entity (N))
17412 and then In_Open_Scopes (Entity (N))
17413 and then not In_Access_Definition (N);
17414 end Is_Protected_Self_Reference;
17416 -----------------------------
17417 -- Is_RCI_Pkg_Spec_Or_Body --
17418 -----------------------------
17420 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
17422 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
17423 -- Return True if the unit of Cunit is an RCI package declaration
17425 ---------------------------
17426 -- Is_RCI_Pkg_Decl_Cunit --
17427 ---------------------------
17429 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
17430 The_Unit : constant Node_Id := Unit (Cunit);
17433 if Nkind (The_Unit) /= N_Package_Declaration then
17437 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
17438 end Is_RCI_Pkg_Decl_Cunit;
17440 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
17443 return Is_RCI_Pkg_Decl_Cunit (Cunit)
17445 (Nkind (Unit (Cunit)) = N_Package_Body
17446 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
17447 end Is_RCI_Pkg_Spec_Or_Body;
17449 -----------------------------------------
17450 -- Is_Remote_Access_To_Class_Wide_Type --
17451 -----------------------------------------
17453 function Is_Remote_Access_To_Class_Wide_Type
17454 (E : Entity_Id) return Boolean
17457 -- A remote access to class-wide type is a general access to object type
17458 -- declared in the visible part of a Remote_Types or Remote_Call_
17461 return Ekind (E) = E_General_Access_Type
17462 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
17463 end Is_Remote_Access_To_Class_Wide_Type;
17465 -----------------------------------------
17466 -- Is_Remote_Access_To_Subprogram_Type --
17467 -----------------------------------------
17469 function Is_Remote_Access_To_Subprogram_Type
17470 (E : Entity_Id) return Boolean
17473 return (Ekind (E) = E_Access_Subprogram_Type
17474 or else (Ekind (E) = E_Record_Type
17475 and then Present (Corresponding_Remote_Type (E))))
17476 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
17477 end Is_Remote_Access_To_Subprogram_Type;
17479 --------------------
17480 -- Is_Remote_Call --
17481 --------------------
17483 function Is_Remote_Call (N : Node_Id) return Boolean is
17485 if Nkind (N) not in N_Subprogram_Call then
17487 -- An entry call cannot be remote
17491 elsif Nkind (Name (N)) in N_Has_Entity
17492 and then Is_Remote_Call_Interface (Entity (Name (N)))
17494 -- A subprogram declared in the spec of a RCI package is remote
17498 elsif Nkind (Name (N)) = N_Explicit_Dereference
17499 and then Is_Remote_Access_To_Subprogram_Type
17500 (Etype (Prefix (Name (N))))
17502 -- The dereference of a RAS is a remote call
17506 elsif Present (Controlling_Argument (N))
17507 and then Is_Remote_Access_To_Class_Wide_Type
17508 (Etype (Controlling_Argument (N)))
17510 -- Any primitive operation call with a controlling argument of
17511 -- a RACW type is a remote call.
17516 -- All other calls are local calls
17519 end Is_Remote_Call;
17521 ----------------------
17522 -- Is_Renamed_Entry --
17523 ----------------------
17525 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
17526 Orig_Node : Node_Id := Empty;
17527 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
17529 function Is_Entry (Nam : Node_Id) return Boolean;
17530 -- Determine whether Nam is an entry. Traverse selectors if there are
17531 -- nested selected components.
17537 function Is_Entry (Nam : Node_Id) return Boolean is
17539 if Nkind (Nam) = N_Selected_Component then
17540 return Is_Entry (Selector_Name (Nam));
17543 return Ekind (Entity (Nam)) = E_Entry;
17546 -- Start of processing for Is_Renamed_Entry
17549 if Present (Alias (Proc_Nam)) then
17550 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
17553 -- Look for a rewritten subprogram renaming declaration
17555 if Nkind (Subp_Decl) = N_Subprogram_Declaration
17556 and then Present (Original_Node (Subp_Decl))
17558 Orig_Node := Original_Node (Subp_Decl);
17561 -- The rewritten subprogram is actually an entry
17563 if Present (Orig_Node)
17564 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
17565 and then Is_Entry (Name (Orig_Node))
17571 end Is_Renamed_Entry;
17573 -----------------------------
17574 -- Is_Renaming_Declaration --
17575 -----------------------------
17577 function Is_Renaming_Declaration (N : Node_Id) return Boolean is
17580 when N_Exception_Renaming_Declaration
17581 | N_Generic_Function_Renaming_Declaration
17582 | N_Generic_Package_Renaming_Declaration
17583 | N_Generic_Procedure_Renaming_Declaration
17584 | N_Object_Renaming_Declaration
17585 | N_Package_Renaming_Declaration
17586 | N_Subprogram_Renaming_Declaration
17593 end Is_Renaming_Declaration;
17595 ----------------------------
17596 -- Is_Reversible_Iterator --
17597 ----------------------------
17599 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
17600 Ifaces_List : Elist_Id;
17601 Iface_Elmt : Elmt_Id;
17605 if Is_Class_Wide_Type (Typ)
17606 and then Chars (Root_Type (Typ)) = Name_Reversible_Iterator
17607 and then In_Predefined_Unit (Root_Type (Typ))
17611 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
17615 Collect_Interfaces (Typ, Ifaces_List);
17617 Iface_Elmt := First_Elmt (Ifaces_List);
17618 while Present (Iface_Elmt) loop
17619 Iface := Node (Iface_Elmt);
17620 if Chars (Iface) = Name_Reversible_Iterator
17621 and then In_Predefined_Unit (Iface)
17626 Next_Elmt (Iface_Elmt);
17631 end Is_Reversible_Iterator;
17633 ----------------------
17634 -- Is_Selector_Name --
17635 ----------------------
17637 function Is_Selector_Name (N : Node_Id) return Boolean is
17639 if not Is_List_Member (N) then
17641 P : constant Node_Id := Parent (N);
17643 return Nkind_In (P, N_Expanded_Name,
17644 N_Generic_Association,
17645 N_Parameter_Association,
17646 N_Selected_Component)
17647 and then Selector_Name (P) = N;
17652 L : constant List_Id := List_Containing (N);
17653 P : constant Node_Id := Parent (L);
17655 return (Nkind (P) = N_Discriminant_Association
17656 and then Selector_Names (P) = L)
17658 (Nkind (P) = N_Component_Association
17659 and then Choices (P) = L);
17662 end Is_Selector_Name;
17664 ---------------------------------
17665 -- Is_Single_Concurrent_Object --
17666 ---------------------------------
17668 function Is_Single_Concurrent_Object (Id : Entity_Id) return Boolean is
17671 Is_Single_Protected_Object (Id) or else Is_Single_Task_Object (Id);
17672 end Is_Single_Concurrent_Object;
17674 -------------------------------
17675 -- Is_Single_Concurrent_Type --
17676 -------------------------------
17678 function Is_Single_Concurrent_Type (Id : Entity_Id) return Boolean is
17681 Ekind_In (Id, E_Protected_Type, E_Task_Type)
17682 and then Is_Single_Concurrent_Type_Declaration
17683 (Declaration_Node (Id));
17684 end Is_Single_Concurrent_Type;
17686 -------------------------------------------
17687 -- Is_Single_Concurrent_Type_Declaration --
17688 -------------------------------------------
17690 function Is_Single_Concurrent_Type_Declaration
17691 (N : Node_Id) return Boolean
17694 return Nkind_In (Original_Node (N), N_Single_Protected_Declaration,
17695 N_Single_Task_Declaration);
17696 end Is_Single_Concurrent_Type_Declaration;
17698 ---------------------------------------------
17699 -- Is_Single_Precision_Floating_Point_Type --
17700 ---------------------------------------------
17702 function Is_Single_Precision_Floating_Point_Type
17703 (E : Entity_Id) return Boolean is
17705 return Is_Floating_Point_Type (E)
17706 and then Machine_Radix_Value (E) = Uint_2
17707 and then Machine_Mantissa_Value (E) = Uint_24
17708 and then Machine_Emax_Value (E) = Uint_2 ** Uint_7
17709 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_7);
17710 end Is_Single_Precision_Floating_Point_Type;
17712 --------------------------------
17713 -- Is_Single_Protected_Object --
17714 --------------------------------
17716 function Is_Single_Protected_Object (Id : Entity_Id) return Boolean is
17719 Ekind (Id) = E_Variable
17720 and then Ekind (Etype (Id)) = E_Protected_Type
17721 and then Is_Single_Concurrent_Type (Etype (Id));
17722 end Is_Single_Protected_Object;
17724 ---------------------------
17725 -- Is_Single_Task_Object --
17726 ---------------------------
17728 function Is_Single_Task_Object (Id : Entity_Id) return Boolean is
17731 Ekind (Id) = E_Variable
17732 and then Ekind (Etype (Id)) = E_Task_Type
17733 and then Is_Single_Concurrent_Type (Etype (Id));
17734 end Is_Single_Task_Object;
17736 -------------------------------------
17737 -- Is_SPARK_05_Initialization_Expr --
17738 -------------------------------------
17740 function Is_SPARK_05_Initialization_Expr (N : Node_Id) return Boolean is
17743 Comp_Assn : Node_Id;
17744 Orig_N : constant Node_Id := Original_Node (N);
17749 if not Comes_From_Source (Orig_N) then
17753 pragma Assert (Nkind (Orig_N) in N_Subexpr);
17755 case Nkind (Orig_N) is
17756 when N_Character_Literal
17757 | N_Integer_Literal
17763 when N_Expanded_Name
17766 if Is_Entity_Name (Orig_N)
17767 and then Present (Entity (Orig_N)) -- needed in some cases
17769 case Ekind (Entity (Orig_N)) is
17771 | E_Enumeration_Literal
17778 if Is_Type (Entity (Orig_N)) then
17786 when N_Qualified_Expression
17787 | N_Type_Conversion
17789 Is_Ok := Is_SPARK_05_Initialization_Expr (Expression (Orig_N));
17792 Is_Ok := Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
17795 | N_Membership_Test
17798 Is_Ok := Is_SPARK_05_Initialization_Expr (Left_Opnd (Orig_N))
17800 Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
17803 | N_Extension_Aggregate
17805 if Nkind (Orig_N) = N_Extension_Aggregate then
17807 Is_SPARK_05_Initialization_Expr (Ancestor_Part (Orig_N));
17810 Expr := First (Expressions (Orig_N));
17811 while Present (Expr) loop
17812 if not Is_SPARK_05_Initialization_Expr (Expr) then
17820 Comp_Assn := First (Component_Associations (Orig_N));
17821 while Present (Comp_Assn) loop
17822 Expr := Expression (Comp_Assn);
17824 -- Note: test for Present here needed for box assocation
17827 and then not Is_SPARK_05_Initialization_Expr (Expr)
17836 when N_Attribute_Reference =>
17837 if Nkind (Prefix (Orig_N)) in N_Subexpr then
17838 Is_Ok := Is_SPARK_05_Initialization_Expr (Prefix (Orig_N));
17841 Expr := First (Expressions (Orig_N));
17842 while Present (Expr) loop
17843 if not Is_SPARK_05_Initialization_Expr (Expr) then
17851 -- Selected components might be expanded named not yet resolved, so
17852 -- default on the safe side. (Eg on sparklex.ads)
17854 when N_Selected_Component =>
17863 end Is_SPARK_05_Initialization_Expr;
17865 ----------------------------------
17866 -- Is_SPARK_05_Object_Reference --
17867 ----------------------------------
17869 function Is_SPARK_05_Object_Reference (N : Node_Id) return Boolean is
17871 if Is_Entity_Name (N) then
17872 return Present (Entity (N))
17874 (Ekind_In (Entity (N), E_Constant, E_Variable)
17875 or else Ekind (Entity (N)) in Formal_Kind);
17879 when N_Selected_Component =>
17880 return Is_SPARK_05_Object_Reference (Prefix (N));
17886 end Is_SPARK_05_Object_Reference;
17888 -----------------------------
17889 -- Is_Specific_Tagged_Type --
17890 -----------------------------
17892 function Is_Specific_Tagged_Type (Typ : Entity_Id) return Boolean is
17893 Full_Typ : Entity_Id;
17896 -- Handle private types
17898 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
17899 Full_Typ := Full_View (Typ);
17904 -- A specific tagged type is a non-class-wide tagged type
17906 return Is_Tagged_Type (Full_Typ) and not Is_Class_Wide_Type (Full_Typ);
17907 end Is_Specific_Tagged_Type;
17913 function Is_Statement (N : Node_Id) return Boolean is
17916 Nkind (N) in N_Statement_Other_Than_Procedure_Call
17917 or else Nkind (N) = N_Procedure_Call_Statement;
17920 ----------------------------------------
17921 -- Is_Subcomponent_Of_Atomic_Object --
17922 ----------------------------------------
17924 function Is_Subcomponent_Of_Atomic_Object (N : Node_Id) return Boolean is
17928 R := Get_Referenced_Object (N);
17930 while Nkind_In (R, N_Indexed_Component, N_Selected_Component, N_Slice)
17932 R := Get_Referenced_Object (Prefix (R));
17934 -- If the prefix is an access value, only the designated type matters
17936 if Is_Access_Type (Etype (R)) then
17937 if Is_Atomic (Designated_Type (Etype (R))) then
17942 if Is_Atomic_Object (R) then
17949 end Is_Subcomponent_Of_Atomic_Object;
17951 ---------------------------------------
17952 -- Is_Subprogram_Contract_Annotation --
17953 ---------------------------------------
17955 function Is_Subprogram_Contract_Annotation
17956 (Item : Node_Id) return Boolean
17961 if Nkind (Item) = N_Aspect_Specification then
17962 Nam := Chars (Identifier (Item));
17964 else pragma Assert (Nkind (Item) = N_Pragma);
17965 Nam := Pragma_Name (Item);
17968 return Nam = Name_Contract_Cases
17969 or else Nam = Name_Depends
17970 or else Nam = Name_Extensions_Visible
17971 or else Nam = Name_Global
17972 or else Nam = Name_Post
17973 or else Nam = Name_Post_Class
17974 or else Nam = Name_Postcondition
17975 or else Nam = Name_Pre
17976 or else Nam = Name_Pre_Class
17977 or else Nam = Name_Precondition
17978 or else Nam = Name_Refined_Depends
17979 or else Nam = Name_Refined_Global
17980 or else Nam = Name_Refined_Post
17981 or else Nam = Name_Test_Case;
17982 end Is_Subprogram_Contract_Annotation;
17984 --------------------------------------------------
17985 -- Is_Subprogram_Stub_Without_Prior_Declaration --
17986 --------------------------------------------------
17988 function Is_Subprogram_Stub_Without_Prior_Declaration
17989 (N : Node_Id) return Boolean
17992 pragma Assert (Nkind (N) = N_Subprogram_Body_Stub);
17994 case Ekind (Defining_Entity (N)) is
17996 -- A subprogram stub without prior declaration serves as declaration
17997 -- for the actual subprogram body. As such, it has an attached
17998 -- defining entity of E_Function or E_Procedure.
18005 -- Otherwise, it is completes a [generic] subprogram declaration
18007 when E_Generic_Function
18008 | E_Generic_Procedure
18009 | E_Subprogram_Body
18014 raise Program_Error;
18016 end Is_Subprogram_Stub_Without_Prior_Declaration;
18018 ---------------------------
18019 -- Is_Suitable_Primitive --
18020 ---------------------------
18022 function Is_Suitable_Primitive (Subp_Id : Entity_Id) return Boolean is
18024 -- The Default_Initial_Condition and invariant procedures must not be
18025 -- treated as primitive operations even when they apply to a tagged
18026 -- type. These routines must not act as targets of dispatching calls
18027 -- because they already utilize class-wide-precondition semantics to
18028 -- handle inheritance and overriding.
18030 if Ekind (Subp_Id) = E_Procedure
18031 and then (Is_DIC_Procedure (Subp_Id)
18033 Is_Invariant_Procedure (Subp_Id))
18039 end Is_Suitable_Primitive;
18041 --------------------------
18042 -- Is_Suspension_Object --
18043 --------------------------
18045 function Is_Suspension_Object (Id : Entity_Id) return Boolean is
18047 -- This approach does an exact name match rather than to rely on
18048 -- RTSfind. Routine Is_Effectively_Volatile is used by clients of the
18049 -- front end at point where all auxiliary tables are locked and any
18050 -- modifications to them are treated as violations. Do not tamper with
18051 -- the tables, instead examine the Chars fields of all the scopes of Id.
18054 Chars (Id) = Name_Suspension_Object
18055 and then Present (Scope (Id))
18056 and then Chars (Scope (Id)) = Name_Synchronous_Task_Control
18057 and then Present (Scope (Scope (Id)))
18058 and then Chars (Scope (Scope (Id))) = Name_Ada
18059 and then Present (Scope (Scope (Scope (Id))))
18060 and then Scope (Scope (Scope (Id))) = Standard_Standard;
18061 end Is_Suspension_Object;
18063 ----------------------------
18064 -- Is_Synchronized_Object --
18065 ----------------------------
18067 function Is_Synchronized_Object (Id : Entity_Id) return Boolean is
18071 if Is_Object (Id) then
18073 -- The object is synchronized if it is of a type that yields a
18074 -- synchronized object.
18076 if Yields_Synchronized_Object (Etype (Id)) then
18079 -- The object is synchronized if it is atomic and Async_Writers is
18082 elsif Is_Atomic_Object_Entity (Id)
18083 and then Async_Writers_Enabled (Id)
18087 -- A constant is a synchronized object by default
18089 elsif Ekind (Id) = E_Constant then
18092 -- A variable is a synchronized object if it is subject to pragma
18093 -- Constant_After_Elaboration.
18095 elsif Ekind (Id) = E_Variable then
18096 Prag := Get_Pragma (Id, Pragma_Constant_After_Elaboration);
18098 return Present (Prag) and then Is_Enabled_Pragma (Prag);
18102 -- Otherwise the input is not an object or it does not qualify as a
18103 -- synchronized object.
18106 end Is_Synchronized_Object;
18108 ---------------------------------
18109 -- Is_Synchronized_Tagged_Type --
18110 ---------------------------------
18112 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
18113 Kind : constant Entity_Kind := Ekind (Base_Type (E));
18116 -- A task or protected type derived from an interface is a tagged type.
18117 -- Such a tagged type is called a synchronized tagged type, as are
18118 -- synchronized interfaces and private extensions whose declaration
18119 -- includes the reserved word synchronized.
18121 return (Is_Tagged_Type (E)
18122 and then (Kind = E_Task_Type
18124 Kind = E_Protected_Type))
18127 and then Is_Synchronized_Interface (E))
18129 (Ekind (E) = E_Record_Type_With_Private
18130 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
18131 and then (Synchronized_Present (Parent (E))
18132 or else Is_Synchronized_Interface (Etype (E))));
18133 end Is_Synchronized_Tagged_Type;
18139 function Is_Transfer (N : Node_Id) return Boolean is
18140 Kind : constant Node_Kind := Nkind (N);
18143 if Kind = N_Simple_Return_Statement
18145 Kind = N_Extended_Return_Statement
18147 Kind = N_Goto_Statement
18149 Kind = N_Raise_Statement
18151 Kind = N_Requeue_Statement
18155 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
18156 and then No (Condition (N))
18160 elsif Kind = N_Procedure_Call_Statement
18161 and then Is_Entity_Name (Name (N))
18162 and then Present (Entity (Name (N)))
18163 and then No_Return (Entity (Name (N)))
18167 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
18179 function Is_True (U : Uint) return Boolean is
18184 --------------------------------------
18185 -- Is_Unchecked_Conversion_Instance --
18186 --------------------------------------
18188 function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is
18192 -- Look for a function whose generic parent is the predefined intrinsic
18193 -- function Unchecked_Conversion, or for one that renames such an
18196 if Ekind (Id) = E_Function then
18197 Par := Parent (Id);
18199 if Nkind (Par) = N_Function_Specification then
18200 Par := Generic_Parent (Par);
18202 if Present (Par) then
18204 Chars (Par) = Name_Unchecked_Conversion
18205 and then Is_Intrinsic_Subprogram (Par)
18206 and then In_Predefined_Unit (Par);
18209 Present (Alias (Id))
18210 and then Is_Unchecked_Conversion_Instance (Alias (Id));
18216 end Is_Unchecked_Conversion_Instance;
18218 -------------------------------
18219 -- Is_Universal_Numeric_Type --
18220 -------------------------------
18222 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
18224 return T = Universal_Integer or else T = Universal_Real;
18225 end Is_Universal_Numeric_Type;
18227 ------------------------------
18228 -- Is_User_Defined_Equality --
18229 ------------------------------
18231 function Is_User_Defined_Equality (Id : Entity_Id) return Boolean is
18233 return Ekind (Id) = E_Function
18234 and then Chars (Id) = Name_Op_Eq
18235 and then Comes_From_Source (Id)
18237 -- Internally generated equalities have a full type declaration
18238 -- as their parent.
18240 and then Nkind (Parent (Id)) = N_Function_Specification;
18241 end Is_User_Defined_Equality;
18243 --------------------------------------
18244 -- Is_Validation_Variable_Reference --
18245 --------------------------------------
18247 function Is_Validation_Variable_Reference (N : Node_Id) return Boolean is
18248 Var : constant Node_Id := Unqual_Conv (N);
18249 Var_Id : Entity_Id;
18254 if Is_Entity_Name (Var) then
18255 Var_Id := Entity (Var);
18260 and then Ekind (Var_Id) = E_Variable
18261 and then Present (Validated_Object (Var_Id));
18262 end Is_Validation_Variable_Reference;
18264 ----------------------------
18265 -- Is_Variable_Size_Array --
18266 ----------------------------
18268 function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
18272 pragma Assert (Is_Array_Type (E));
18274 -- Check if some index is initialized with a non-constant value
18276 Idx := First_Index (E);
18277 while Present (Idx) loop
18278 if Nkind (Idx) = N_Range then
18279 if not Is_Constant_Bound (Low_Bound (Idx))
18280 or else not Is_Constant_Bound (High_Bound (Idx))
18290 end Is_Variable_Size_Array;
18292 -----------------------------
18293 -- Is_Variable_Size_Record --
18294 -----------------------------
18296 function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
18298 Comp_Typ : Entity_Id;
18301 pragma Assert (Is_Record_Type (E));
18303 Comp := First_Component (E);
18304 while Present (Comp) loop
18305 Comp_Typ := Underlying_Type (Etype (Comp));
18307 -- Recursive call if the record type has discriminants
18309 if Is_Record_Type (Comp_Typ)
18310 and then Has_Discriminants (Comp_Typ)
18311 and then Is_Variable_Size_Record (Comp_Typ)
18315 elsif Is_Array_Type (Comp_Typ)
18316 and then Is_Variable_Size_Array (Comp_Typ)
18321 Next_Component (Comp);
18325 end Is_Variable_Size_Record;
18331 function Is_Variable
18333 Use_Original_Node : Boolean := True) return Boolean
18335 Orig_Node : Node_Id;
18337 function In_Protected_Function (E : Entity_Id) return Boolean;
18338 -- Within a protected function, the private components of the enclosing
18339 -- protected type are constants. A function nested within a (protected)
18340 -- procedure is not itself protected. Within the body of a protected
18341 -- function the current instance of the protected type is a constant.
18343 function Is_Variable_Prefix (P : Node_Id) return Boolean;
18344 -- Prefixes can involve implicit dereferences, in which case we must
18345 -- test for the case of a reference of a constant access type, which can
18346 -- can never be a variable.
18348 ---------------------------
18349 -- In_Protected_Function --
18350 ---------------------------
18352 function In_Protected_Function (E : Entity_Id) return Boolean is
18357 -- E is the current instance of a type
18359 if Is_Type (E) then
18368 if not Is_Protected_Type (Prot) then
18372 S := Current_Scope;
18373 while Present (S) and then S /= Prot loop
18374 if Ekind (S) = E_Function and then Scope (S) = Prot then
18383 end In_Protected_Function;
18385 ------------------------
18386 -- Is_Variable_Prefix --
18387 ------------------------
18389 function Is_Variable_Prefix (P : Node_Id) return Boolean is
18391 if Is_Access_Type (Etype (P)) then
18392 return not Is_Access_Constant (Root_Type (Etype (P)));
18394 -- For the case of an indexed component whose prefix has a packed
18395 -- array type, the prefix has been rewritten into a type conversion.
18396 -- Determine variable-ness from the converted expression.
18398 elsif Nkind (P) = N_Type_Conversion
18399 and then not Comes_From_Source (P)
18400 and then Is_Array_Type (Etype (P))
18401 and then Is_Packed (Etype (P))
18403 return Is_Variable (Expression (P));
18406 return Is_Variable (P);
18408 end Is_Variable_Prefix;
18410 -- Start of processing for Is_Variable
18413 -- Special check, allow x'Deref(expr) as a variable
18415 if Nkind (N) = N_Attribute_Reference
18416 and then Attribute_Name (N) = Name_Deref
18421 -- Check if we perform the test on the original node since this may be a
18422 -- test of syntactic categories which must not be disturbed by whatever
18423 -- rewriting might have occurred. For example, an aggregate, which is
18424 -- certainly NOT a variable, could be turned into a variable by
18427 if Use_Original_Node then
18428 Orig_Node := Original_Node (N);
18433 -- Definitely OK if Assignment_OK is set. Since this is something that
18434 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
18436 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
18439 -- Normally we go to the original node, but there is one exception where
18440 -- we use the rewritten node, namely when it is an explicit dereference.
18441 -- The generated code may rewrite a prefix which is an access type with
18442 -- an explicit dereference. The dereference is a variable, even though
18443 -- the original node may not be (since it could be a constant of the
18446 -- In Ada 2005 we have a further case to consider: the prefix may be a
18447 -- function call given in prefix notation. The original node appears to
18448 -- be a selected component, but we need to examine the call.
18450 elsif Nkind (N) = N_Explicit_Dereference
18451 and then Nkind (Orig_Node) /= N_Explicit_Dereference
18452 and then Present (Etype (Orig_Node))
18453 and then Is_Access_Type (Etype (Orig_Node))
18455 -- Note that if the prefix is an explicit dereference that does not
18456 -- come from source, we must check for a rewritten function call in
18457 -- prefixed notation before other forms of rewriting, to prevent a
18461 (Nkind (Orig_Node) = N_Function_Call
18462 and then not Is_Access_Constant (Etype (Prefix (N))))
18464 Is_Variable_Prefix (Original_Node (Prefix (N)));
18466 -- in Ada 2012, the dereference may have been added for a type with
18467 -- a declared implicit dereference aspect. Check that it is not an
18468 -- access to constant.
18470 elsif Nkind (N) = N_Explicit_Dereference
18471 and then Present (Etype (Orig_Node))
18472 and then Ada_Version >= Ada_2012
18473 and then Has_Implicit_Dereference (Etype (Orig_Node))
18475 return not Is_Access_Constant (Etype (Prefix (N)));
18477 -- A function call is never a variable
18479 elsif Nkind (N) = N_Function_Call then
18482 -- All remaining checks use the original node
18484 elsif Is_Entity_Name (Orig_Node)
18485 and then Present (Entity (Orig_Node))
18488 E : constant Entity_Id := Entity (Orig_Node);
18489 K : constant Entity_Kind := Ekind (E);
18492 if Is_Loop_Parameter (E) then
18496 return (K = E_Variable
18497 and then Nkind (Parent (E)) /= N_Exception_Handler)
18498 or else (K = E_Component
18499 and then not In_Protected_Function (E))
18500 or else K = E_Out_Parameter
18501 or else K = E_In_Out_Parameter
18502 or else K = E_Generic_In_Out_Parameter
18504 -- Current instance of type. If this is a protected type, check
18505 -- we are not within the body of one of its protected functions.
18507 or else (Is_Type (E)
18508 and then In_Open_Scopes (E)
18509 and then not In_Protected_Function (E))
18511 or else (Is_Incomplete_Or_Private_Type (E)
18512 and then In_Open_Scopes (Full_View (E)));
18516 case Nkind (Orig_Node) is
18517 when N_Indexed_Component
18520 return Is_Variable_Prefix (Prefix (Orig_Node));
18522 when N_Selected_Component =>
18523 return (Is_Variable (Selector_Name (Orig_Node))
18524 and then Is_Variable_Prefix (Prefix (Orig_Node)))
18526 (Nkind (N) = N_Expanded_Name
18527 and then Scope (Entity (N)) = Entity (Prefix (N)));
18529 -- For an explicit dereference, the type of the prefix cannot
18530 -- be an access to constant or an access to subprogram.
18532 when N_Explicit_Dereference =>
18534 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
18536 return Is_Access_Type (Typ)
18537 and then not Is_Access_Constant (Root_Type (Typ))
18538 and then Ekind (Typ) /= E_Access_Subprogram_Type;
18541 -- The type conversion is the case where we do not deal with the
18542 -- context dependent special case of an actual parameter. Thus
18543 -- the type conversion is only considered a variable for the
18544 -- purposes of this routine if the target type is tagged. However,
18545 -- a type conversion is considered to be a variable if it does not
18546 -- come from source (this deals for example with the conversions
18547 -- of expressions to their actual subtypes).
18549 when N_Type_Conversion =>
18550 return Is_Variable (Expression (Orig_Node))
18552 (not Comes_From_Source (Orig_Node)
18554 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
18556 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
18558 -- GNAT allows an unchecked type conversion as a variable. This
18559 -- only affects the generation of internal expanded code, since
18560 -- calls to instantiations of Unchecked_Conversion are never
18561 -- considered variables (since they are function calls).
18563 when N_Unchecked_Type_Conversion =>
18564 return Is_Variable (Expression (Orig_Node));
18572 ---------------------------
18573 -- Is_Visibly_Controlled --
18574 ---------------------------
18576 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
18577 Root : constant Entity_Id := Root_Type (T);
18579 return Chars (Scope (Root)) = Name_Finalization
18580 and then Chars (Scope (Scope (Root))) = Name_Ada
18581 and then Scope (Scope (Scope (Root))) = Standard_Standard;
18582 end Is_Visibly_Controlled;
18584 --------------------------------------
18585 -- Is_Volatile_Full_Access_Object --
18586 --------------------------------------
18588 function Is_Volatile_Full_Access_Object (N : Node_Id) return Boolean is
18589 function Is_VFA_Object_Entity (Id : Entity_Id) return Boolean;
18590 -- Determine whether arbitrary entity Id denotes an object that is
18591 -- Volatile_Full_Access.
18593 ----------------------------
18594 -- Is_VFA_Object_Entity --
18595 ----------------------------
18597 function Is_VFA_Object_Entity (Id : Entity_Id) return Boolean is
18601 and then (Is_Volatile_Full_Access (Id)
18603 Is_Volatile_Full_Access (Etype (Id)));
18604 end Is_VFA_Object_Entity;
18606 -- Start of processing for Is_Volatile_Full_Access_Object
18609 if Is_Entity_Name (N) then
18610 return Is_VFA_Object_Entity (Entity (N));
18612 elsif Is_Volatile_Full_Access (Etype (N)) then
18615 elsif Nkind (N) = N_Selected_Component then
18616 return Is_Volatile_Full_Access (Entity (Selector_Name (N)));
18621 end Is_Volatile_Full_Access_Object;
18623 --------------------------
18624 -- Is_Volatile_Function --
18625 --------------------------
18627 function Is_Volatile_Function (Func_Id : Entity_Id) return Boolean is
18629 pragma Assert (Ekind_In (Func_Id, E_Function, E_Generic_Function));
18631 -- A function declared within a protected type is volatile
18633 if Is_Protected_Type (Scope (Func_Id)) then
18636 -- An instance of Ada.Unchecked_Conversion is a volatile function if
18637 -- either the source or the target are effectively volatile.
18639 elsif Is_Unchecked_Conversion_Instance (Func_Id)
18640 and then Has_Effectively_Volatile_Profile (Func_Id)
18644 -- Otherwise the function is treated as volatile if it is subject to
18645 -- enabled pragma Volatile_Function.
18649 Is_Enabled_Pragma (Get_Pragma (Func_Id, Pragma_Volatile_Function));
18651 end Is_Volatile_Function;
18653 ------------------------
18654 -- Is_Volatile_Object --
18655 ------------------------
18657 function Is_Volatile_Object (N : Node_Id) return Boolean is
18658 function Is_Volatile_Object_Entity (Id : Entity_Id) return Boolean;
18659 -- Determine whether arbitrary entity Id denotes an object that is
18662 function Prefix_Has_Volatile_Components (P : Node_Id) return Boolean;
18663 -- Determine whether prefix P has volatile components. This requires
18664 -- the presence of a Volatile_Components aspect/pragma or that P be
18665 -- itself a volatile object as per RM C.6(8).
18667 ---------------------------------
18668 -- Is_Volatile_Object_Entity --
18669 ---------------------------------
18671 function Is_Volatile_Object_Entity (Id : Entity_Id) return Boolean is
18675 and then (Is_Volatile (Id) or else Is_Volatile (Etype (Id)));
18676 end Is_Volatile_Object_Entity;
18678 ------------------------------------
18679 -- Prefix_Has_Volatile_Components --
18680 ------------------------------------
18682 function Prefix_Has_Volatile_Components (P : Node_Id) return Boolean is
18683 Typ : constant Entity_Id := Etype (P);
18686 if Is_Access_Type (Typ) then
18688 Dtyp : constant Entity_Id := Designated_Type (Typ);
18691 return Has_Volatile_Components (Dtyp)
18692 or else Is_Volatile (Dtyp);
18695 elsif Has_Volatile_Components (Typ) then
18698 elsif Is_Entity_Name (P)
18699 and then Has_Volatile_Component (Entity (P))
18703 elsif Is_Volatile_Object (P) then
18709 end Prefix_Has_Volatile_Components;
18711 -- Start of processing for Is_Volatile_Object
18714 if Is_Entity_Name (N) then
18715 return Is_Volatile_Object_Entity (Entity (N));
18717 elsif Is_Volatile (Etype (N)) then
18720 elsif Nkind (N) = N_Indexed_Component then
18721 return Prefix_Has_Volatile_Components (Prefix (N));
18723 elsif Nkind (N) = N_Selected_Component then
18724 return Prefix_Has_Volatile_Components (Prefix (N))
18725 or else Is_Volatile (Entity (Selector_Name (N)));
18730 end Is_Volatile_Object;
18732 -----------------------------
18733 -- Iterate_Call_Parameters --
18734 -----------------------------
18736 procedure Iterate_Call_Parameters (Call : Node_Id) is
18737 Actual : Node_Id := First_Actual (Call);
18738 Formal : Entity_Id := First_Formal (Get_Called_Entity (Call));
18741 while Present (Formal) and then Present (Actual) loop
18742 Handle_Parameter (Formal, Actual);
18744 Next_Formal (Formal);
18745 Next_Actual (Actual);
18748 pragma Assert (No (Formal));
18749 pragma Assert (No (Actual));
18750 end Iterate_Call_Parameters;
18752 ---------------------------
18753 -- Itype_Has_Declaration --
18754 ---------------------------
18756 function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
18758 pragma Assert (Is_Itype (Id));
18759 return Present (Parent (Id))
18760 and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
18761 N_Subtype_Declaration)
18762 and then Defining_Entity (Parent (Id)) = Id;
18763 end Itype_Has_Declaration;
18765 -------------------------
18766 -- Kill_Current_Values --
18767 -------------------------
18769 procedure Kill_Current_Values
18771 Last_Assignment_Only : Boolean := False)
18774 if Is_Assignable (Ent) then
18775 Set_Last_Assignment (Ent, Empty);
18778 if Is_Object (Ent) then
18779 if not Last_Assignment_Only then
18781 Set_Current_Value (Ent, Empty);
18783 -- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
18784 -- for a constant. Once the constant is elaborated, its value is
18785 -- not changed, therefore the associated flags that describe the
18786 -- value should not be modified either.
18788 if Ekind (Ent) = E_Constant then
18791 -- Non-constant entities
18794 if not Can_Never_Be_Null (Ent) then
18795 Set_Is_Known_Non_Null (Ent, False);
18798 Set_Is_Known_Null (Ent, False);
18800 -- Reset the Is_Known_Valid flag unless the type is always
18801 -- valid. This does not apply to a loop parameter because its
18802 -- bounds are defined by the loop header and therefore always
18805 if not Is_Known_Valid (Etype (Ent))
18806 and then Ekind (Ent) /= E_Loop_Parameter
18808 Set_Is_Known_Valid (Ent, False);
18813 end Kill_Current_Values;
18815 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
18818 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
18819 -- Clear current value for entity E and all entities chained to E
18821 ------------------------------------------
18822 -- Kill_Current_Values_For_Entity_Chain --
18823 ------------------------------------------
18825 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
18829 while Present (Ent) loop
18830 Kill_Current_Values (Ent, Last_Assignment_Only);
18833 end Kill_Current_Values_For_Entity_Chain;
18835 -- Start of processing for Kill_Current_Values
18838 -- Kill all saved checks, a special case of killing saved values
18840 if not Last_Assignment_Only then
18844 -- Loop through relevant scopes, which includes the current scope and
18845 -- any parent scopes if the current scope is a block or a package.
18847 S := Current_Scope;
18850 -- Clear current values of all entities in current scope
18852 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
18854 -- If scope is a package, also clear current values of all private
18855 -- entities in the scope.
18857 if Is_Package_Or_Generic_Package (S)
18858 or else Is_Concurrent_Type (S)
18860 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
18863 -- If this is a not a subprogram, deal with parents
18865 if not Is_Subprogram (S) then
18867 exit Scope_Loop when S = Standard_Standard;
18871 end loop Scope_Loop;
18872 end Kill_Current_Values;
18874 --------------------------
18875 -- Kill_Size_Check_Code --
18876 --------------------------
18878 procedure Kill_Size_Check_Code (E : Entity_Id) is
18880 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
18881 and then Present (Size_Check_Code (E))
18883 Remove (Size_Check_Code (E));
18884 Set_Size_Check_Code (E, Empty);
18886 end Kill_Size_Check_Code;
18888 --------------------
18889 -- Known_Non_Null --
18890 --------------------
18892 function Known_Non_Null (N : Node_Id) return Boolean is
18893 Status : constant Null_Status_Kind := Null_Status (N);
18900 -- The expression yields a non-null value ignoring simple flow analysis
18902 if Status = Is_Non_Null then
18905 -- Otherwise check whether N is a reference to an entity that appears
18906 -- within a conditional construct.
18908 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
18910 -- First check if we are in decisive conditional
18912 Get_Current_Value_Condition (N, Op, Val);
18914 if Known_Null (Val) then
18915 if Op = N_Op_Eq then
18917 elsif Op = N_Op_Ne then
18922 -- If OK to do replacement, test Is_Known_Non_Null flag
18926 if OK_To_Do_Constant_Replacement (Id) then
18927 return Is_Known_Non_Null (Id);
18931 -- Otherwise it is not possible to determine whether N yields a non-null
18935 end Known_Non_Null;
18941 function Known_Null (N : Node_Id) return Boolean is
18942 Status : constant Null_Status_Kind := Null_Status (N);
18949 -- The expression yields a null value ignoring simple flow analysis
18951 if Status = Is_Null then
18954 -- Otherwise check whether N is a reference to an entity that appears
18955 -- within a conditional construct.
18957 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
18959 -- First check if we are in decisive conditional
18961 Get_Current_Value_Condition (N, Op, Val);
18963 if Known_Null (Val) then
18964 if Op = N_Op_Eq then
18966 elsif Op = N_Op_Ne then
18971 -- If OK to do replacement, test Is_Known_Null flag
18975 if OK_To_Do_Constant_Replacement (Id) then
18976 return Is_Known_Null (Id);
18980 -- Otherwise it is not possible to determine whether N yields a null
18986 --------------------------
18987 -- Known_To_Be_Assigned --
18988 --------------------------
18990 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
18991 P : constant Node_Id := Parent (N);
18996 -- Test left side of assignment
18998 when N_Assignment_Statement =>
18999 return N = Name (P);
19001 -- Function call arguments are never lvalues
19003 when N_Function_Call =>
19006 -- Positional parameter for procedure or accept call
19008 when N_Accept_Statement
19009 | N_Procedure_Call_Statement
19017 Proc := Get_Subprogram_Entity (P);
19023 -- If we are not a list member, something is strange, so
19024 -- be conservative and return False.
19026 if not Is_List_Member (N) then
19030 -- We are going to find the right formal by stepping forward
19031 -- through the formals, as we step backwards in the actuals.
19033 Form := First_Formal (Proc);
19036 -- If no formal, something is weird, so be conservative
19037 -- and return False.
19044 exit when No (Act);
19045 Next_Formal (Form);
19048 return Ekind (Form) /= E_In_Parameter;
19051 -- Named parameter for procedure or accept call
19053 when N_Parameter_Association =>
19059 Proc := Get_Subprogram_Entity (Parent (P));
19065 -- Loop through formals to find the one that matches
19067 Form := First_Formal (Proc);
19069 -- If no matching formal, that's peculiar, some kind of
19070 -- previous error, so return False to be conservative.
19071 -- Actually this also happens in legal code in the case
19072 -- where P is a parameter association for an Extra_Formal???
19078 -- Else test for match
19080 if Chars (Form) = Chars (Selector_Name (P)) then
19081 return Ekind (Form) /= E_In_Parameter;
19084 Next_Formal (Form);
19088 -- Test for appearing in a conversion that itself appears
19089 -- in an lvalue context, since this should be an lvalue.
19091 when N_Type_Conversion =>
19092 return Known_To_Be_Assigned (P);
19094 -- All other references are definitely not known to be modifications
19099 end Known_To_Be_Assigned;
19101 ---------------------------
19102 -- Last_Source_Statement --
19103 ---------------------------
19105 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
19109 N := Last (Statements (HSS));
19110 while Present (N) loop
19111 exit when Comes_From_Source (N);
19116 end Last_Source_Statement;
19118 -----------------------
19119 -- Mark_Coextensions --
19120 -----------------------
19122 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
19123 Is_Dynamic : Boolean;
19124 -- Indicates whether the context causes nested coextensions to be
19125 -- dynamic or static
19127 function Mark_Allocator (N : Node_Id) return Traverse_Result;
19128 -- Recognize an allocator node and label it as a dynamic coextension
19130 --------------------
19131 -- Mark_Allocator --
19132 --------------------
19134 function Mark_Allocator (N : Node_Id) return Traverse_Result is
19136 if Nkind (N) = N_Allocator then
19138 Set_Is_Static_Coextension (N, False);
19139 Set_Is_Dynamic_Coextension (N);
19141 -- If the allocator expression is potentially dynamic, it may
19142 -- be expanded out of order and require dynamic allocation
19143 -- anyway, so we treat the coextension itself as dynamic.
19144 -- Potential optimization ???
19146 elsif Nkind (Expression (N)) = N_Qualified_Expression
19147 and then Nkind (Expression (Expression (N))) = N_Op_Concat
19149 Set_Is_Static_Coextension (N, False);
19150 Set_Is_Dynamic_Coextension (N);
19152 Set_Is_Dynamic_Coextension (N, False);
19153 Set_Is_Static_Coextension (N);
19158 end Mark_Allocator;
19160 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
19162 -- Start of processing for Mark_Coextensions
19165 -- An allocator that appears on the right-hand side of an assignment is
19166 -- treated as a potentially dynamic coextension when the right-hand side
19167 -- is an allocator or a qualified expression.
19169 -- Obj := new ...'(new Coextension ...);
19171 if Nkind (Context_Nod) = N_Assignment_Statement then
19173 Nkind_In (Expression (Context_Nod), N_Allocator,
19174 N_Qualified_Expression);
19176 -- An allocator that appears within the expression of a simple return
19177 -- statement is treated as a potentially dynamic coextension when the
19178 -- expression is either aggregate, allocator, or qualified expression.
19180 -- return (new Coextension ...);
19181 -- return new ...'(new Coextension ...);
19183 elsif Nkind (Context_Nod) = N_Simple_Return_Statement then
19185 Nkind_In (Expression (Context_Nod), N_Aggregate,
19187 N_Qualified_Expression);
19189 -- An alloctor that appears within the initialization expression of an
19190 -- object declaration is considered a potentially dynamic coextension
19191 -- when the initialization expression is an allocator or a qualified
19194 -- Obj : ... := new ...'(new Coextension ...);
19196 -- A similar case arises when the object declaration is part of an
19197 -- extended return statement.
19199 -- return Obj : ... := new ...'(new Coextension ...);
19200 -- return Obj : ... := (new Coextension ...);
19202 elsif Nkind (Context_Nod) = N_Object_Declaration then
19204 Nkind_In (Root_Nod, N_Allocator, N_Qualified_Expression)
19206 Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
19208 -- This routine should not be called with constructs that cannot contain
19212 raise Program_Error;
19215 Mark_Allocators (Root_Nod);
19216 end Mark_Coextensions;
19218 ---------------------------------
19219 -- Mark_Elaboration_Attributes --
19220 ---------------------------------
19222 procedure Mark_Elaboration_Attributes
19223 (N_Id : Node_Or_Entity_Id;
19224 Checks : Boolean := False;
19225 Level : Boolean := False;
19226 Modes : Boolean := False;
19227 Warnings : Boolean := False)
19229 function Elaboration_Checks_OK
19230 (Target_Id : Entity_Id;
19231 Context_Id : Entity_Id) return Boolean;
19232 -- Determine whether elaboration checks are enabled for target Target_Id
19233 -- which resides within context Context_Id.
19235 procedure Mark_Elaboration_Attributes_Id (Id : Entity_Id);
19236 -- Preserve relevant attributes of the context in arbitrary entity Id
19238 procedure Mark_Elaboration_Attributes_Node (N : Node_Id);
19239 -- Preserve relevant attributes of the context in arbitrary node N
19241 ---------------------------
19242 -- Elaboration_Checks_OK --
19243 ---------------------------
19245 function Elaboration_Checks_OK
19246 (Target_Id : Entity_Id;
19247 Context_Id : Entity_Id) return Boolean
19249 Encl_Scop : Entity_Id;
19252 -- Elaboration checks are suppressed for the target
19254 if Elaboration_Checks_Suppressed (Target_Id) then
19258 -- Otherwise elaboration checks are OK for the target, but may be
19259 -- suppressed for the context where the target is declared.
19261 Encl_Scop := Context_Id;
19262 while Present (Encl_Scop) and then Encl_Scop /= Standard_Standard loop
19263 if Elaboration_Checks_Suppressed (Encl_Scop) then
19267 Encl_Scop := Scope (Encl_Scop);
19270 -- Neither the target nor its declarative context have elaboration
19271 -- checks suppressed.
19274 end Elaboration_Checks_OK;
19276 ------------------------------------
19277 -- Mark_Elaboration_Attributes_Id --
19278 ------------------------------------
19280 procedure Mark_Elaboration_Attributes_Id (Id : Entity_Id) is
19282 -- Mark the status of elaboration checks in effect. Do not reset the
19283 -- status in case the entity is reanalyzed with checks suppressed.
19285 if Checks and then not Is_Elaboration_Checks_OK_Id (Id) then
19286 Set_Is_Elaboration_Checks_OK_Id (Id,
19287 Elaboration_Checks_OK
19289 Context_Id => Scope (Id)));
19292 -- Mark the status of elaboration warnings in effect. Do not reset
19293 -- the status in case the entity is reanalyzed with warnings off.
19295 if Warnings and then not Is_Elaboration_Warnings_OK_Id (Id) then
19296 Set_Is_Elaboration_Warnings_OK_Id (Id, Elab_Warnings);
19298 end Mark_Elaboration_Attributes_Id;
19300 --------------------------------------
19301 -- Mark_Elaboration_Attributes_Node --
19302 --------------------------------------
19304 procedure Mark_Elaboration_Attributes_Node (N : Node_Id) is
19305 function Extract_Name (N : Node_Id) return Node_Id;
19306 -- Obtain the Name attribute of call or instantiation N
19312 function Extract_Name (N : Node_Id) return Node_Id is
19318 -- A call to an entry family appears in indexed form
19320 if Nkind (Nam) = N_Indexed_Component then
19321 Nam := Prefix (Nam);
19324 -- The name may also appear in qualified form
19326 if Nkind (Nam) = N_Selected_Component then
19327 Nam := Selector_Name (Nam);
19335 Context_Id : Entity_Id;
19338 -- Start of processing for Mark_Elaboration_Attributes_Node
19341 -- Mark the status of elaboration checks in effect. Do not reset the
19342 -- status in case the node is reanalyzed with checks suppressed.
19344 if Checks and then not Is_Elaboration_Checks_OK_Node (N) then
19346 -- Assignments, attribute references, and variable references do
19347 -- not have a "declarative" context.
19349 Context_Id := Empty;
19351 -- The status of elaboration checks for calls and instantiations
19352 -- depends on the most recent pragma Suppress/Unsuppress, as well
19353 -- as the suppression status of the context where the target is
19357 -- function Func ...;
19361 -- procedure Main is
19362 -- pragma Suppress (Elaboration_Checks, Pack);
19363 -- X : ... := Pack.Func;
19366 -- In the example above, the call to Func has elaboration checks
19367 -- enabled because there is no active general purpose suppression
19368 -- pragma, however the elaboration checks of Pack are explicitly
19369 -- suppressed. As a result the elaboration checks of the call must
19370 -- be disabled in order to preserve this dependency.
19372 if Nkind_In (N, N_Entry_Call_Statement,
19374 N_Function_Instantiation,
19375 N_Package_Instantiation,
19376 N_Procedure_Call_Statement,
19377 N_Procedure_Instantiation)
19379 Nam := Extract_Name (N);
19381 if Is_Entity_Name (Nam) and then Present (Entity (Nam)) then
19382 Context_Id := Scope (Entity (Nam));
19386 Set_Is_Elaboration_Checks_OK_Node (N,
19387 Elaboration_Checks_OK
19388 (Target_Id => Empty,
19389 Context_Id => Context_Id));
19392 -- Mark the enclosing level of the node. Do not reset the status in
19393 -- case the node is relocated and reanalyzed.
19395 if Level and then not Is_Declaration_Level_Node (N) then
19396 Set_Is_Declaration_Level_Node (N,
19397 Find_Enclosing_Level (N) = Declaration_Level);
19400 -- Mark the Ghost and SPARK mode in effect
19403 if Ghost_Mode = Ignore then
19404 Set_Is_Ignored_Ghost_Node (N);
19407 if SPARK_Mode = On then
19408 Set_Is_SPARK_Mode_On_Node (N);
19412 -- Mark the status of elaboration warnings in effect. Do not reset
19413 -- the status in case the node is reanalyzed with warnings off.
19415 if Warnings and then not Is_Elaboration_Warnings_OK_Node (N) then
19416 Set_Is_Elaboration_Warnings_OK_Node (N, Elab_Warnings);
19418 end Mark_Elaboration_Attributes_Node;
19420 -- Start of processing for Mark_Elaboration_Attributes
19423 -- Do not capture any elaboration-related attributes when switch -gnatH
19424 -- (legacy elaboration checking mode enabled) is in effect because the
19425 -- attributes are useless to the legacy model.
19427 if Legacy_Elaboration_Checks then
19431 if Nkind (N_Id) in N_Entity then
19432 Mark_Elaboration_Attributes_Id (N_Id);
19434 Mark_Elaboration_Attributes_Node (N_Id);
19436 end Mark_Elaboration_Attributes;
19438 ----------------------------------------
19439 -- Mark_Save_Invocation_Graph_Of_Body --
19440 ----------------------------------------
19442 procedure Mark_Save_Invocation_Graph_Of_Body is
19443 Main : constant Node_Id := Cunit (Main_Unit);
19444 Main_Unit : constant Node_Id := Unit (Main);
19445 Aux_Id : Entity_Id;
19448 Set_Save_Invocation_Graph_Of_Body (Main);
19450 -- Assume that the main unit does not have a complimentary unit
19454 -- Obtain the complimentary unit of the main unit
19456 if Nkind_In (Main_Unit, N_Generic_Package_Declaration,
19457 N_Generic_Subprogram_Declaration,
19458 N_Package_Declaration,
19459 N_Subprogram_Declaration)
19461 Aux_Id := Corresponding_Body (Main_Unit);
19463 elsif Nkind_In (Main_Unit, N_Package_Body,
19465 N_Subprogram_Renaming_Declaration)
19467 Aux_Id := Corresponding_Spec (Main_Unit);
19470 if Present (Aux_Id) then
19471 Set_Save_Invocation_Graph_Of_Body
19472 (Parent (Unit_Declaration_Node (Aux_Id)));
19474 end Mark_Save_Invocation_Graph_Of_Body;
19476 ----------------------------------
19477 -- Matching_Static_Array_Bounds --
19478 ----------------------------------
19480 function Matching_Static_Array_Bounds
19482 R_Typ : Node_Id) return Boolean
19484 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
19485 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
19487 L_Index : Node_Id := Empty; -- init to ...
19488 R_Index : Node_Id := Empty; -- ...avoid warnings
19497 if L_Ndims /= R_Ndims then
19501 -- Unconstrained types do not have static bounds
19503 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
19507 -- First treat specially the first dimension, as the lower bound and
19508 -- length of string literals are not stored like those of arrays.
19510 if Ekind (L_Typ) = E_String_Literal_Subtype then
19511 L_Low := String_Literal_Low_Bound (L_Typ);
19512 L_Len := String_Literal_Length (L_Typ);
19514 L_Index := First_Index (L_Typ);
19515 Get_Index_Bounds (L_Index, L_Low, L_High);
19517 if Is_OK_Static_Expression (L_Low)
19519 Is_OK_Static_Expression (L_High)
19521 if Expr_Value (L_High) < Expr_Value (L_Low) then
19524 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
19531 if Ekind (R_Typ) = E_String_Literal_Subtype then
19532 R_Low := String_Literal_Low_Bound (R_Typ);
19533 R_Len := String_Literal_Length (R_Typ);
19535 R_Index := First_Index (R_Typ);
19536 Get_Index_Bounds (R_Index, R_Low, R_High);
19538 if Is_OK_Static_Expression (R_Low)
19540 Is_OK_Static_Expression (R_High)
19542 if Expr_Value (R_High) < Expr_Value (R_Low) then
19545 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
19552 if (Is_OK_Static_Expression (L_Low)
19554 Is_OK_Static_Expression (R_Low))
19555 and then Expr_Value (L_Low) = Expr_Value (R_Low)
19556 and then L_Len = R_Len
19563 -- Then treat all other dimensions
19565 for Indx in 2 .. L_Ndims loop
19569 Get_Index_Bounds (L_Index, L_Low, L_High);
19570 Get_Index_Bounds (R_Index, R_Low, R_High);
19572 if (Is_OK_Static_Expression (L_Low) and then
19573 Is_OK_Static_Expression (L_High) and then
19574 Is_OK_Static_Expression (R_Low) and then
19575 Is_OK_Static_Expression (R_High))
19576 and then (Expr_Value (L_Low) = Expr_Value (R_Low)
19578 Expr_Value (L_High) = Expr_Value (R_High))
19586 -- If we fall through the loop, all indexes matched
19589 end Matching_Static_Array_Bounds;
19591 -------------------
19592 -- May_Be_Lvalue --
19593 -------------------
19595 function May_Be_Lvalue (N : Node_Id) return Boolean is
19596 P : constant Node_Id := Parent (N);
19601 -- Test left side of assignment
19603 when N_Assignment_Statement =>
19604 return N = Name (P);
19606 -- Test prefix of component or attribute. Note that the prefix of an
19607 -- explicit or implicit dereference cannot be an l-value. In the case
19608 -- of a 'Read attribute, the reference can be an actual in the
19609 -- argument list of the attribute.
19611 when N_Attribute_Reference =>
19612 return (N = Prefix (P)
19613 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P)))
19615 Attribute_Name (P) = Name_Read;
19617 -- For an expanded name, the name is an lvalue if the expanded name
19618 -- is an lvalue, but the prefix is never an lvalue, since it is just
19619 -- the scope where the name is found.
19621 when N_Expanded_Name =>
19622 if N = Prefix (P) then
19623 return May_Be_Lvalue (P);
19628 -- For a selected component A.B, A is certainly an lvalue if A.B is.
19629 -- B is a little interesting, if we have A.B := 3, there is some
19630 -- discussion as to whether B is an lvalue or not, we choose to say
19631 -- it is. Note however that A is not an lvalue if it is of an access
19632 -- type since this is an implicit dereference.
19634 when N_Selected_Component =>
19636 and then Present (Etype (N))
19637 and then Is_Access_Type (Etype (N))
19641 return May_Be_Lvalue (P);
19644 -- For an indexed component or slice, the index or slice bounds is
19645 -- never an lvalue. The prefix is an lvalue if the indexed component
19646 -- or slice is an lvalue, except if it is an access type, where we
19647 -- have an implicit dereference.
19649 when N_Indexed_Component
19653 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
19657 return May_Be_Lvalue (P);
19660 -- Prefix of a reference is an lvalue if the reference is an lvalue
19662 when N_Reference =>
19663 return May_Be_Lvalue (P);
19665 -- Prefix of explicit dereference is never an lvalue
19667 when N_Explicit_Dereference =>
19670 -- Positional parameter for subprogram, entry, or accept call.
19671 -- In older versions of Ada function call arguments are never
19672 -- lvalues. In Ada 2012 functions can have in-out parameters.
19674 when N_Accept_Statement
19675 | N_Entry_Call_Statement
19676 | N_Subprogram_Call
19678 if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
19682 -- The following mechanism is clumsy and fragile. A single flag
19683 -- set in Resolve_Actuals would be preferable ???
19691 Proc := Get_Subprogram_Entity (P);
19697 -- If we are not a list member, something is strange, so be
19698 -- conservative and return True.
19700 if not Is_List_Member (N) then
19704 -- We are going to find the right formal by stepping forward
19705 -- through the formals, as we step backwards in the actuals.
19707 Form := First_Formal (Proc);
19710 -- If no formal, something is weird, so be conservative and
19718 exit when No (Act);
19719 Next_Formal (Form);
19722 return Ekind (Form) /= E_In_Parameter;
19725 -- Named parameter for procedure or accept call
19727 when N_Parameter_Association =>
19733 Proc := Get_Subprogram_Entity (Parent (P));
19739 -- Loop through formals to find the one that matches
19741 Form := First_Formal (Proc);
19743 -- If no matching formal, that's peculiar, some kind of
19744 -- previous error, so return True to be conservative.
19745 -- Actually happens with legal code for an unresolved call
19746 -- where we may get the wrong homonym???
19752 -- Else test for match
19754 if Chars (Form) = Chars (Selector_Name (P)) then
19755 return Ekind (Form) /= E_In_Parameter;
19758 Next_Formal (Form);
19762 -- Test for appearing in a conversion that itself appears in an
19763 -- lvalue context, since this should be an lvalue.
19765 when N_Type_Conversion =>
19766 return May_Be_Lvalue (P);
19768 -- Test for appearance in object renaming declaration
19770 when N_Object_Renaming_Declaration =>
19773 -- All other references are definitely not lvalues
19784 function Might_Raise (N : Node_Id) return Boolean is
19785 Result : Boolean := False;
19787 function Process (N : Node_Id) return Traverse_Result;
19788 -- Set Result to True if we find something that could raise an exception
19794 function Process (N : Node_Id) return Traverse_Result is
19796 if Nkind_In (N, N_Procedure_Call_Statement,
19799 N_Raise_Constraint_Error,
19800 N_Raise_Program_Error,
19801 N_Raise_Storage_Error)
19810 procedure Set_Result is new Traverse_Proc (Process);
19812 -- Start of processing for Might_Raise
19815 -- False if exceptions can't be propagated
19817 if No_Exception_Handlers_Set then
19821 -- If the checks handled by the back end are not disabled, we cannot
19822 -- ensure that no exception will be raised.
19824 if not Access_Checks_Suppressed (Empty)
19825 or else not Discriminant_Checks_Suppressed (Empty)
19826 or else not Range_Checks_Suppressed (Empty)
19827 or else not Index_Checks_Suppressed (Empty)
19828 or else Opt.Stack_Checking_Enabled
19837 --------------------------------
19838 -- Nearest_Enclosing_Instance --
19839 --------------------------------
19841 function Nearest_Enclosing_Instance (E : Entity_Id) return Entity_Id is
19846 while Present (Inst) and then Inst /= Standard_Standard loop
19847 if Is_Generic_Instance (Inst) then
19851 Inst := Scope (Inst);
19855 end Nearest_Enclosing_Instance;
19857 ------------------------
19858 -- Needs_Finalization --
19859 ------------------------
19861 function Needs_Finalization (Typ : Entity_Id) return Boolean is
19862 function Has_Some_Controlled_Component
19863 (Input_Typ : Entity_Id) return Boolean;
19864 -- Determine whether type Input_Typ has at least one controlled
19867 -----------------------------------
19868 -- Has_Some_Controlled_Component --
19869 -----------------------------------
19871 function Has_Some_Controlled_Component
19872 (Input_Typ : Entity_Id) return Boolean
19877 -- When a type is already frozen and has at least one controlled
19878 -- component, or is manually decorated, it is sufficient to inspect
19879 -- flag Has_Controlled_Component.
19881 if Has_Controlled_Component (Input_Typ) then
19884 -- Otherwise inspect the internals of the type
19886 elsif not Is_Frozen (Input_Typ) then
19887 if Is_Array_Type (Input_Typ) then
19888 return Needs_Finalization (Component_Type (Input_Typ));
19890 elsif Is_Record_Type (Input_Typ) then
19891 Comp := First_Component (Input_Typ);
19892 while Present (Comp) loop
19893 if Needs_Finalization (Etype (Comp)) then
19897 Next_Component (Comp);
19903 end Has_Some_Controlled_Component;
19905 -- Start of processing for Needs_Finalization
19908 -- Certain run-time configurations and targets do not provide support
19909 -- for controlled types.
19911 if Restriction_Active (No_Finalization) then
19914 -- C++ types are not considered controlled. It is assumed that the non-
19915 -- Ada side will handle their clean up.
19917 elsif Convention (Typ) = Convention_CPP then
19920 -- Class-wide types are treated as controlled because derivations from
19921 -- the root type may introduce controlled components.
19923 elsif Is_Class_Wide_Type (Typ) then
19926 -- Concurrent types are controlled as long as their corresponding record
19929 elsif Is_Concurrent_Type (Typ)
19930 and then Present (Corresponding_Record_Type (Typ))
19931 and then Needs_Finalization (Corresponding_Record_Type (Typ))
19935 -- Otherwise the type is controlled when it is either derived from type
19936 -- [Limited_]Controlled and not subject to aspect Disable_Controlled, or
19937 -- contains at least one controlled component.
19941 Is_Controlled (Typ) or else Has_Some_Controlled_Component (Typ);
19943 end Needs_Finalization;
19945 ----------------------
19946 -- Needs_One_Actual --
19947 ----------------------
19949 function Needs_One_Actual (E : Entity_Id) return Boolean is
19950 Formal : Entity_Id;
19953 -- Ada 2005 or later, and formals present. The first formal must be
19954 -- of a type that supports prefix notation: a controlling argument,
19955 -- a class-wide type, or an access to such.
19957 if Ada_Version >= Ada_2005
19958 and then Present (First_Formal (E))
19959 and then No (Default_Value (First_Formal (E)))
19961 (Is_Controlling_Formal (First_Formal (E))
19962 or else Is_Class_Wide_Type (Etype (First_Formal (E)))
19963 or else Is_Anonymous_Access_Type (Etype (First_Formal (E))))
19965 Formal := Next_Formal (First_Formal (E));
19966 while Present (Formal) loop
19967 if No (Default_Value (Formal)) then
19971 Next_Formal (Formal);
19976 -- Ada 83/95 or no formals
19981 end Needs_One_Actual;
19983 ---------------------------------
19984 -- Needs_Simple_Initialization --
19985 ---------------------------------
19987 function Needs_Simple_Initialization
19989 Consider_IS : Boolean := True) return Boolean
19991 Consider_IS_NS : constant Boolean :=
19992 Normalize_Scalars or (Initialize_Scalars and Consider_IS);
19995 -- Never need initialization if it is suppressed
19997 if Initialization_Suppressed (Typ) then
20001 -- Check for private type, in which case test applies to the underlying
20002 -- type of the private type.
20004 if Is_Private_Type (Typ) then
20006 RT : constant Entity_Id := Underlying_Type (Typ);
20008 if Present (RT) then
20009 return Needs_Simple_Initialization (RT);
20015 -- Scalar type with Default_Value aspect requires initialization
20017 elsif Is_Scalar_Type (Typ) and then Has_Default_Aspect (Typ) then
20020 -- Cases needing simple initialization are access types, and, if pragma
20021 -- Normalize_Scalars or Initialize_Scalars is in effect, then all scalar
20024 elsif Is_Access_Type (Typ)
20025 or else (Consider_IS_NS and then (Is_Scalar_Type (Typ)))
20029 -- If Initialize/Normalize_Scalars is in effect, string objects also
20030 -- need initialization, unless they are created in the course of
20031 -- expanding an aggregate (since in the latter case they will be
20032 -- filled with appropriate initializing values before they are used).
20034 elsif Consider_IS_NS
20035 and then Is_Standard_String_Type (Typ)
20037 (not Is_Itype (Typ)
20038 or else Nkind (Associated_Node_For_Itype (Typ)) /= N_Aggregate)
20045 end Needs_Simple_Initialization;
20047 -------------------------------------
20048 -- Needs_Variable_Reference_Marker --
20049 -------------------------------------
20051 function Needs_Variable_Reference_Marker
20053 Calls_OK : Boolean) return Boolean
20055 function Within_Suitable_Context (Ref : Node_Id) return Boolean;
20056 -- Deteremine whether variable reference Ref appears within a suitable
20057 -- context that allows the creation of a marker.
20059 -----------------------------
20060 -- Within_Suitable_Context --
20061 -----------------------------
20063 function Within_Suitable_Context (Ref : Node_Id) return Boolean is
20068 while Present (Par) loop
20070 -- The context is not suitable when the reference appears within
20071 -- the formal part of an instantiation which acts as compilation
20072 -- unit because there is no proper list for the insertion of the
20075 if Nkind (Par) = N_Generic_Association
20076 and then Nkind (Parent (Par)) in N_Generic_Instantiation
20077 and then Nkind (Parent (Parent (Par))) = N_Compilation_Unit
20081 -- The context is not suitable when the reference appears within
20082 -- a pragma. If the pragma has run-time semantics, the reference
20083 -- will be reconsidered once the pragma is expanded.
20085 elsif Nkind (Par) = N_Pragma then
20088 -- The context is not suitable when the reference appears within a
20089 -- subprogram call, and the caller requests this behavior.
20092 and then Nkind_In (Par, N_Entry_Call_Statement,
20094 N_Procedure_Call_Statement)
20098 -- Prevent the search from going too far
20100 elsif Is_Body_Or_Package_Declaration (Par) then
20104 Par := Parent (Par);
20108 end Within_Suitable_Context;
20113 Var_Id : Entity_Id;
20115 -- Start of processing for Needs_Variable_Reference_Marker
20118 -- No marker needs to be created when switch -gnatH (legacy elaboration
20119 -- checking mode enabled) is in effect because the legacy ABE mechanism
20120 -- does not use markers.
20122 if Legacy_Elaboration_Checks then
20125 -- No marker needs to be created when the reference is preanalyzed
20126 -- because the marker will be inserted in the wrong place.
20128 elsif Preanalysis_Active then
20131 -- Only references warrant a marker
20133 elsif not Nkind_In (N, N_Expanded_Name, N_Identifier) then
20136 -- Only source references warrant a marker
20138 elsif not Comes_From_Source (N) then
20141 -- No marker needs to be created when the reference is erroneous, left
20142 -- in a bad state, or does not denote a variable.
20144 elsif not (Present (Entity (N))
20145 and then Ekind (Entity (N)) = E_Variable
20146 and then Entity (N) /= Any_Id)
20151 Var_Id := Entity (N);
20152 Prag := SPARK_Pragma (Var_Id);
20154 -- Both the variable and reference must appear in SPARK_Mode On regions
20155 -- because this elaboration scenario falls under the SPARK rules.
20157 if not (Comes_From_Source (Var_Id)
20158 and then Present (Prag)
20159 and then Get_SPARK_Mode_From_Annotation (Prag) = On
20160 and then Is_SPARK_Mode_On_Node (N))
20164 -- No marker needs to be created when the reference does not appear
20165 -- within a suitable context (see body for details).
20167 -- Performance note: parent traversal
20169 elsif not Within_Suitable_Context (N) then
20173 -- At this point it is known that the variable reference will play a
20174 -- role in ABE diagnostics and requires a marker.
20177 end Needs_Variable_Reference_Marker;
20179 ------------------------
20180 -- New_Copy_List_Tree --
20181 ------------------------
20183 function New_Copy_List_Tree (List : List_Id) return List_Id is
20188 if List = No_List then
20195 while Present (E) loop
20196 Append (New_Copy_Tree (E), NL);
20202 end New_Copy_List_Tree;
20204 -------------------
20205 -- New_Copy_Tree --
20206 -------------------
20208 -- The following tables play a key role in replicating entities and Itypes.
20209 -- They are intentionally declared at the library level rather than within
20210 -- New_Copy_Tree to avoid elaborating them on each call. This performance
20211 -- optimization saves up to 2% of the entire compilation time spent in the
20212 -- front end. Care should be taken to reset the tables on each new call to
20215 NCT_Table_Max : constant := 511;
20217 subtype NCT_Table_Index is Nat range 0 .. NCT_Table_Max - 1;
20219 function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index;
20220 -- Obtain the hash value of node or entity Key
20222 --------------------
20223 -- NCT_Table_Hash --
20224 --------------------
20226 function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index is
20228 return NCT_Table_Index (Key mod NCT_Table_Max);
20229 end NCT_Table_Hash;
20231 ----------------------
20232 -- NCT_New_Entities --
20233 ----------------------
20235 -- The following table maps old entities and Itypes to their corresponding
20236 -- new entities and Itypes.
20240 package NCT_New_Entities is new Simple_HTable (
20241 Header_Num => NCT_Table_Index,
20242 Element => Entity_Id,
20243 No_Element => Empty,
20245 Hash => NCT_Table_Hash,
20248 ------------------------
20249 -- NCT_Pending_Itypes --
20250 ------------------------
20252 -- The following table maps old Associated_Node_For_Itype nodes to a set of
20253 -- new itypes. Given a set of old Itypes Aaa, Bbb, and Ccc, where all three
20254 -- have the same Associated_Node_For_Itype Ppp, and their corresponding new
20255 -- Itypes Xxx, Yyy, Zzz, the table contains the following mapping:
20257 -- Ppp -> (Xxx, Yyy, Zzz)
20259 -- The set is expressed as an Elist
20261 package NCT_Pending_Itypes is new Simple_HTable (
20262 Header_Num => NCT_Table_Index,
20263 Element => Elist_Id,
20264 No_Element => No_Elist,
20266 Hash => NCT_Table_Hash,
20269 NCT_Tables_In_Use : Boolean := False;
20270 -- This flag keeps track of whether the two tables NCT_New_Entities and
20271 -- NCT_Pending_Itypes are in use. The flag is part of an optimization
20272 -- where certain operations are not performed if the tables are not in
20273 -- use. This saves up to 8% of the entire compilation time spent in the
20276 -------------------
20277 -- New_Copy_Tree --
20278 -------------------
20280 function New_Copy_Tree
20282 Map : Elist_Id := No_Elist;
20283 New_Sloc : Source_Ptr := No_Location;
20284 New_Scope : Entity_Id := Empty;
20285 Scopes_In_EWA_OK : Boolean := False) return Node_Id
20287 -- This routine performs low-level tree manipulations and needs access
20288 -- to the internals of the tree.
20290 use Atree.Unchecked_Access;
20291 use Atree_Private_Part;
20293 EWA_Level : Nat := 0;
20294 -- This counter keeps track of how many N_Expression_With_Actions nodes
20295 -- are encountered during a depth-first traversal of the subtree. These
20296 -- nodes may define new entities in their Actions lists and thus require
20297 -- special processing.
20299 EWA_Inner_Scope_Level : Nat := 0;
20300 -- This counter keeps track of how many scoping constructs appear within
20301 -- an N_Expression_With_Actions node.
20303 procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id);
20304 pragma Inline (Add_New_Entity);
20305 -- Add an entry in the NCT_New_Entities table which maps key Old_Id to
20306 -- value New_Id. Old_Id is an entity which appears within the Actions
20307 -- list of an N_Expression_With_Actions node, or within an entity map.
20308 -- New_Id is the corresponding new entity generated during Phase 1.
20310 procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id);
20311 pragma Inline (Add_New_Entity);
20312 -- Add an entry in the NCT_Pending_Itypes which maps key Assoc_Nod to
20313 -- value Itype. Assoc_Nod is the associated node of an itype. Itype is
20316 procedure Build_NCT_Tables (Entity_Map : Elist_Id);
20317 pragma Inline (Build_NCT_Tables);
20318 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with the
20319 -- information supplied in entity map Entity_Map. The format of the
20320 -- entity map must be as follows:
20322 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
20324 function Copy_Any_Node_With_Replacement
20325 (N : Node_Or_Entity_Id) return Node_Or_Entity_Id;
20326 pragma Inline (Copy_Any_Node_With_Replacement);
20327 -- Replicate entity or node N by invoking one of the following routines:
20329 -- Copy_Node_With_Replacement
20330 -- Corresponding_Entity
20332 function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id;
20333 -- Replicate the elements of entity list List
20335 function Copy_Field_With_Replacement
20337 Old_Par : Node_Id := Empty;
20338 New_Par : Node_Id := Empty;
20339 Semantic : Boolean := False) return Union_Id;
20340 -- Replicate field Field by invoking one of the following routines:
20342 -- Copy_Elist_With_Replacement
20343 -- Copy_List_With_Replacement
20344 -- Copy_Node_With_Replacement
20345 -- Corresponding_Entity
20347 -- If the field is not an entity list, entity, itype, syntactic list,
20348 -- or node, then the field is returned unchanged. The routine always
20349 -- replicates entities, itypes, and valid syntactic fields. Old_Par is
20350 -- the expected parent of a syntactic field. New_Par is the new parent
20351 -- associated with a replicated syntactic field. Flag Semantic should
20352 -- be set when the input is a semantic field.
20354 function Copy_List_With_Replacement (List : List_Id) return List_Id;
20355 -- Replicate the elements of syntactic list List
20357 function Copy_Node_With_Replacement (N : Node_Id) return Node_Id;
20358 -- Replicate node N
20360 function Corresponding_Entity (Id : Entity_Id) return Entity_Id;
20361 pragma Inline (Corresponding_Entity);
20362 -- Return the corresponding new entity of Id generated during Phase 1.
20363 -- If there is no such entity, return Id.
20365 function In_Entity_Map
20367 Entity_Map : Elist_Id) return Boolean;
20368 pragma Inline (In_Entity_Map);
20369 -- Determine whether entity Id is one of the old ids specified in entity
20370 -- map Entity_Map. The format of the entity map must be as follows:
20372 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
20374 procedure Update_CFS_Sloc (N : Node_Or_Entity_Id);
20375 pragma Inline (Update_CFS_Sloc);
20376 -- Update the Comes_From_Source and Sloc attributes of node or entity N
20378 procedure Update_First_Real_Statement
20379 (Old_HSS : Node_Id;
20380 New_HSS : Node_Id);
20381 pragma Inline (Update_First_Real_Statement);
20382 -- Update semantic attribute First_Real_Statement of handled sequence of
20383 -- statements New_HSS based on handled sequence of statements Old_HSS.
20385 procedure Update_Named_Associations
20386 (Old_Call : Node_Id;
20387 New_Call : Node_Id);
20388 pragma Inline (Update_Named_Associations);
20389 -- Update semantic chain First/Next_Named_Association of call New_call
20390 -- based on call Old_Call.
20392 procedure Update_New_Entities (Entity_Map : Elist_Id);
20393 pragma Inline (Update_New_Entities);
20394 -- Update the semantic attributes of all new entities generated during
20395 -- Phase 1 that do not appear in entity map Entity_Map. The format of
20396 -- the entity map must be as follows:
20398 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
20400 procedure Update_Pending_Itypes
20401 (Old_Assoc : Node_Id;
20402 New_Assoc : Node_Id);
20403 pragma Inline (Update_Pending_Itypes);
20404 -- Update semantic attribute Associated_Node_For_Itype to refer to node
20405 -- New_Assoc for all itypes whose associated node is Old_Assoc.
20407 procedure Update_Semantic_Fields (Id : Entity_Id);
20408 pragma Inline (Update_Semantic_Fields);
20409 -- Subsidiary to Update_New_Entities. Update semantic fields of entity
20412 procedure Visit_Any_Node (N : Node_Or_Entity_Id);
20413 pragma Inline (Visit_Any_Node);
20414 -- Visit entity of node N by invoking one of the following routines:
20420 procedure Visit_Elist (List : Elist_Id);
20421 -- Visit the elements of entity list List
20423 procedure Visit_Entity (Id : Entity_Id);
20424 -- Visit entity Id. This action may create a new entity of Id and save
20425 -- it in table NCT_New_Entities.
20427 procedure Visit_Field
20429 Par_Nod : Node_Id := Empty;
20430 Semantic : Boolean := False);
20431 -- Visit field Field by invoking one of the following routines:
20439 -- If the field is not an entity list, entity, itype, syntactic list,
20440 -- or node, then the field is not visited. The routine always visits
20441 -- valid syntactic fields. Par_Nod is the expected parent of the
20442 -- syntactic field. Flag Semantic should be set when the input is a
20445 procedure Visit_Itype (Itype : Entity_Id);
20446 -- Visit itype Itype. This action may create a new entity for Itype and
20447 -- save it in table NCT_New_Entities. In addition, the routine may map
20448 -- the associated node of Itype to the new itype in NCT_Pending_Itypes.
20450 procedure Visit_List (List : List_Id);
20451 -- Visit the elements of syntactic list List
20453 procedure Visit_Node (N : Node_Id);
20456 procedure Visit_Semantic_Fields (Id : Entity_Id);
20457 pragma Inline (Visit_Semantic_Fields);
20458 -- Subsidiary to Visit_Entity and Visit_Itype. Visit common semantic
20459 -- fields of entity or itype Id.
20461 --------------------
20462 -- Add_New_Entity --
20463 --------------------
20465 procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id) is
20467 pragma Assert (Present (Old_Id));
20468 pragma Assert (Present (New_Id));
20469 pragma Assert (Nkind (Old_Id) in N_Entity);
20470 pragma Assert (Nkind (New_Id) in N_Entity);
20472 NCT_Tables_In_Use := True;
20474 -- Sanity check the NCT_New_Entities table. No previous mapping with
20475 -- key Old_Id should exist.
20477 pragma Assert (No (NCT_New_Entities.Get (Old_Id)));
20479 -- Establish the mapping
20481 -- Old_Id -> New_Id
20483 NCT_New_Entities.Set (Old_Id, New_Id);
20484 end Add_New_Entity;
20486 -----------------------
20487 -- Add_Pending_Itype --
20488 -----------------------
20490 procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id) is
20494 pragma Assert (Present (Assoc_Nod));
20495 pragma Assert (Present (Itype));
20496 pragma Assert (Nkind (Itype) in N_Entity);
20497 pragma Assert (Is_Itype (Itype));
20499 NCT_Tables_In_Use := True;
20501 -- It is not possible to sanity check the NCT_Pendint_Itypes table
20502 -- directly because a single node may act as the associated node for
20503 -- multiple itypes.
20505 Itypes := NCT_Pending_Itypes.Get (Assoc_Nod);
20507 if No (Itypes) then
20508 Itypes := New_Elmt_List;
20509 NCT_Pending_Itypes.Set (Assoc_Nod, Itypes);
20512 -- Establish the mapping
20514 -- Assoc_Nod -> (Itype, ...)
20516 -- Avoid inserting the same itype multiple times. This involves a
20517 -- linear search, however the set of itypes with the same associated
20518 -- node is very small.
20520 Append_Unique_Elmt (Itype, Itypes);
20521 end Add_Pending_Itype;
20523 ----------------------
20524 -- Build_NCT_Tables --
20525 ----------------------
20527 procedure Build_NCT_Tables (Entity_Map : Elist_Id) is
20529 Old_Id : Entity_Id;
20530 New_Id : Entity_Id;
20533 -- Nothing to do when there is no entity map
20535 if No (Entity_Map) then
20539 Elmt := First_Elmt (Entity_Map);
20540 while Present (Elmt) loop
20542 -- Extract the (Old_Id, New_Id) pair from the entity map
20544 Old_Id := Node (Elmt);
20547 New_Id := Node (Elmt);
20550 -- Establish the following mapping within table NCT_New_Entities
20552 -- Old_Id -> New_Id
20554 Add_New_Entity (Old_Id, New_Id);
20556 -- Establish the following mapping within table NCT_Pending_Itypes
20557 -- when the new entity is an itype.
20559 -- Assoc_Nod -> (New_Id, ...)
20561 -- IMPORTANT: the associated node is that of the old itype because
20562 -- the node will be replicated in Phase 2.
20564 if Is_Itype (Old_Id) then
20566 (Assoc_Nod => Associated_Node_For_Itype (Old_Id),
20570 end Build_NCT_Tables;
20572 ------------------------------------
20573 -- Copy_Any_Node_With_Replacement --
20574 ------------------------------------
20576 function Copy_Any_Node_With_Replacement
20577 (N : Node_Or_Entity_Id) return Node_Or_Entity_Id
20580 if Nkind (N) in N_Entity then
20581 return Corresponding_Entity (N);
20583 return Copy_Node_With_Replacement (N);
20585 end Copy_Any_Node_With_Replacement;
20587 ---------------------------------
20588 -- Copy_Elist_With_Replacement --
20589 ---------------------------------
20591 function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id is
20596 -- Copy the contents of the old list. Note that the list itself may
20597 -- be empty, in which case the routine returns a new empty list. This
20598 -- avoids sharing lists between subtrees. The element of an entity
20599 -- list could be an entity or a node, hence the invocation of routine
20600 -- Copy_Any_Node_With_Replacement.
20602 if Present (List) then
20603 Result := New_Elmt_List;
20605 Elmt := First_Elmt (List);
20606 while Present (Elmt) loop
20608 (Copy_Any_Node_With_Replacement (Node (Elmt)), Result);
20613 -- Otherwise the list does not exist
20616 Result := No_Elist;
20620 end Copy_Elist_With_Replacement;
20622 ---------------------------------
20623 -- Copy_Field_With_Replacement --
20624 ---------------------------------
20626 function Copy_Field_With_Replacement
20628 Old_Par : Node_Id := Empty;
20629 New_Par : Node_Id := Empty;
20630 Semantic : Boolean := False) return Union_Id
20633 -- The field is empty
20635 if Field = Union_Id (Empty) then
20638 -- The field is an entity/itype/node
20640 elsif Field in Node_Range then
20642 Old_N : constant Node_Id := Node_Id (Field);
20643 Syntactic : constant Boolean := Parent (Old_N) = Old_Par;
20648 -- The field is an entity/itype
20650 if Nkind (Old_N) in N_Entity then
20652 -- An entity/itype is always replicated
20654 New_N := Corresponding_Entity (Old_N);
20656 -- Update the parent pointer when the entity is a syntactic
20657 -- field. Note that itypes do not have parent pointers.
20659 if Syntactic and then New_N /= Old_N then
20660 Set_Parent (New_N, New_Par);
20663 -- The field is a node
20666 -- A node is replicated when it is either a syntactic field
20667 -- or when the caller treats it as a semantic attribute.
20669 if Syntactic or else Semantic then
20670 New_N := Copy_Node_With_Replacement (Old_N);
20672 -- Update the parent pointer when the node is a syntactic
20675 if Syntactic and then New_N /= Old_N then
20676 Set_Parent (New_N, New_Par);
20679 -- Otherwise the node is returned unchanged
20686 return Union_Id (New_N);
20689 -- The field is an entity list
20691 elsif Field in Elist_Range then
20692 return Union_Id (Copy_Elist_With_Replacement (Elist_Id (Field)));
20694 -- The field is a syntactic list
20696 elsif Field in List_Range then
20698 Old_List : constant List_Id := List_Id (Field);
20699 Syntactic : constant Boolean := Parent (Old_List) = Old_Par;
20701 New_List : List_Id;
20704 -- A list is replicated when it is either a syntactic field or
20705 -- when the caller treats it as a semantic attribute.
20707 if Syntactic or else Semantic then
20708 New_List := Copy_List_With_Replacement (Old_List);
20710 -- Update the parent pointer when the list is a syntactic
20713 if Syntactic and then New_List /= Old_List then
20714 Set_Parent (New_List, New_Par);
20717 -- Otherwise the list is returned unchanged
20720 New_List := Old_List;
20723 return Union_Id (New_List);
20726 -- Otherwise the field denotes an attribute that does not need to be
20727 -- replicated (Chars, literals, etc).
20732 end Copy_Field_With_Replacement;
20734 --------------------------------
20735 -- Copy_List_With_Replacement --
20736 --------------------------------
20738 function Copy_List_With_Replacement (List : List_Id) return List_Id is
20743 -- Copy the contents of the old list. Note that the list itself may
20744 -- be empty, in which case the routine returns a new empty list. This
20745 -- avoids sharing lists between subtrees. The element of a syntactic
20746 -- list is always a node, never an entity or itype, hence the call to
20747 -- routine Copy_Node_With_Replacement.
20749 if Present (List) then
20750 Result := New_List;
20752 Elmt := First (List);
20753 while Present (Elmt) loop
20754 Append (Copy_Node_With_Replacement (Elmt), Result);
20759 -- Otherwise the list does not exist
20766 end Copy_List_With_Replacement;
20768 --------------------------------
20769 -- Copy_Node_With_Replacement --
20770 --------------------------------
20772 function Copy_Node_With_Replacement (N : Node_Id) return Node_Id is
20776 -- Assume that the node must be returned unchanged
20780 if N > Empty_Or_Error then
20781 pragma Assert (Nkind (N) not in N_Entity);
20783 Result := New_Copy (N);
20785 Set_Field1 (Result,
20786 Copy_Field_With_Replacement
20787 (Field => Field1 (Result),
20789 New_Par => Result));
20791 Set_Field2 (Result,
20792 Copy_Field_With_Replacement
20793 (Field => Field2 (Result),
20795 New_Par => Result));
20797 Set_Field3 (Result,
20798 Copy_Field_With_Replacement
20799 (Field => Field3 (Result),
20801 New_Par => Result));
20803 Set_Field4 (Result,
20804 Copy_Field_With_Replacement
20805 (Field => Field4 (Result),
20807 New_Par => Result));
20809 Set_Field5 (Result,
20810 Copy_Field_With_Replacement
20811 (Field => Field5 (Result),
20813 New_Par => Result));
20815 -- Update the Comes_From_Source and Sloc attributes of the node
20816 -- in case the caller has supplied new values.
20818 Update_CFS_Sloc (Result);
20820 -- Update the Associated_Node_For_Itype attribute of all itypes
20821 -- created during Phase 1 whose associated node is N. As a result
20822 -- the Associated_Node_For_Itype refers to the replicated node.
20823 -- No action needs to be taken when the Associated_Node_For_Itype
20824 -- refers to an entity because this was already handled during
20825 -- Phase 1, in Visit_Itype.
20827 Update_Pending_Itypes
20829 New_Assoc => Result);
20831 -- Update the First/Next_Named_Association chain for a replicated
20834 if Nkind_In (N, N_Entry_Call_Statement,
20836 N_Procedure_Call_Statement)
20838 Update_Named_Associations
20840 New_Call => Result);
20842 -- Update the Renamed_Object attribute of a replicated object
20845 elsif Nkind (N) = N_Object_Renaming_Declaration then
20846 Set_Renamed_Object (Defining_Entity (Result), Name (Result));
20848 -- Update the First_Real_Statement attribute of a replicated
20849 -- handled sequence of statements.
20851 elsif Nkind (N) = N_Handled_Sequence_Of_Statements then
20852 Update_First_Real_Statement
20854 New_HSS => Result);
20856 -- Update the Chars attribute of identifiers
20858 elsif Nkind (N) = N_Identifier then
20860 -- The Entity field of identifiers that denote aspects is used
20861 -- to store arbitrary expressions (and hence we must check that
20862 -- they reference an actual entity before copying their Chars
20865 if Present (Entity (Result))
20866 and then Nkind (Entity (Result)) in N_Entity
20868 Set_Chars (Result, Chars (Entity (Result)));
20874 end Copy_Node_With_Replacement;
20876 --------------------------
20877 -- Corresponding_Entity --
20878 --------------------------
20880 function Corresponding_Entity (Id : Entity_Id) return Entity_Id is
20881 New_Id : Entity_Id;
20882 Result : Entity_Id;
20885 -- Assume that the entity must be returned unchanged
20889 if Id > Empty_Or_Error then
20890 pragma Assert (Nkind (Id) in N_Entity);
20892 -- Determine whether the entity has a corresponding new entity
20893 -- generated during Phase 1 and if it does, use it.
20895 if NCT_Tables_In_Use then
20896 New_Id := NCT_New_Entities.Get (Id);
20898 if Present (New_Id) then
20905 end Corresponding_Entity;
20907 -------------------
20908 -- In_Entity_Map --
20909 -------------------
20911 function In_Entity_Map
20913 Entity_Map : Elist_Id) return Boolean
20916 Old_Id : Entity_Id;
20919 -- The entity map contains pairs (Old_Id, New_Id). The advancement
20920 -- step always skips the New_Id portion of the pair.
20922 if Present (Entity_Map) then
20923 Elmt := First_Elmt (Entity_Map);
20924 while Present (Elmt) loop
20925 Old_Id := Node (Elmt);
20927 if Old_Id = Id then
20939 ---------------------
20940 -- Update_CFS_Sloc --
20941 ---------------------
20943 procedure Update_CFS_Sloc (N : Node_Or_Entity_Id) is
20945 -- A new source location defaults the Comes_From_Source attribute
20947 if New_Sloc /= No_Location then
20948 Set_Comes_From_Source (N, Default_Node.Comes_From_Source);
20949 Set_Sloc (N, New_Sloc);
20951 end Update_CFS_Sloc;
20953 ---------------------------------
20954 -- Update_First_Real_Statement --
20955 ---------------------------------
20957 procedure Update_First_Real_Statement
20958 (Old_HSS : Node_Id;
20961 Old_First_Stmt : constant Node_Id := First_Real_Statement (Old_HSS);
20963 New_Stmt : Node_Id;
20964 Old_Stmt : Node_Id;
20967 -- Recreate the First_Real_Statement attribute of a handled sequence
20968 -- of statements by traversing the statement lists of both sequences
20971 if Present (Old_First_Stmt) then
20972 New_Stmt := First (Statements (New_HSS));
20973 Old_Stmt := First (Statements (Old_HSS));
20974 while Present (Old_Stmt) and then Old_Stmt /= Old_First_Stmt loop
20979 pragma Assert (Present (New_Stmt));
20980 pragma Assert (Present (Old_Stmt));
20982 Set_First_Real_Statement (New_HSS, New_Stmt);
20984 end Update_First_Real_Statement;
20986 -------------------------------
20987 -- Update_Named_Associations --
20988 -------------------------------
20990 procedure Update_Named_Associations
20991 (Old_Call : Node_Id;
20992 New_Call : Node_Id)
20995 New_Next : Node_Id;
20997 Old_Next : Node_Id;
21000 if No (First_Named_Actual (Old_Call)) then
21004 -- Recreate the First/Next_Named_Actual chain of a call by traversing
21005 -- the chains of both the old and new calls in parallel.
21007 New_Act := First (Parameter_Associations (New_Call));
21008 Old_Act := First (Parameter_Associations (Old_Call));
21009 while Present (Old_Act) loop
21010 if Nkind (Old_Act) = N_Parameter_Association
21011 and then Explicit_Actual_Parameter (Old_Act)
21012 = First_Named_Actual (Old_Call)
21014 Set_First_Named_Actual (New_Call,
21015 Explicit_Actual_Parameter (New_Act));
21018 if Nkind (Old_Act) = N_Parameter_Association
21019 and then Present (Next_Named_Actual (Old_Act))
21021 -- Scan the actual parameter list to find the next suitable
21022 -- named actual. Note that the list may be out of order.
21024 New_Next := First (Parameter_Associations (New_Call));
21025 Old_Next := First (Parameter_Associations (Old_Call));
21026 while Nkind (Old_Next) /= N_Parameter_Association
21027 or else Explicit_Actual_Parameter (Old_Next) /=
21028 Next_Named_Actual (Old_Act)
21034 Set_Next_Named_Actual (New_Act,
21035 Explicit_Actual_Parameter (New_Next));
21041 end Update_Named_Associations;
21043 -------------------------
21044 -- Update_New_Entities --
21045 -------------------------
21047 procedure Update_New_Entities (Entity_Map : Elist_Id) is
21048 New_Id : Entity_Id := Empty;
21049 Old_Id : Entity_Id := Empty;
21052 if NCT_Tables_In_Use then
21053 NCT_New_Entities.Get_First (Old_Id, New_Id);
21055 -- Update the semantic fields of all new entities created during
21056 -- Phase 1 which were not supplied via an entity map.
21057 -- ??? Is there a better way of distinguishing those?
21059 while Present (Old_Id) and then Present (New_Id) loop
21060 if not (Present (Entity_Map)
21061 and then In_Entity_Map (Old_Id, Entity_Map))
21063 Update_Semantic_Fields (New_Id);
21066 NCT_New_Entities.Get_Next (Old_Id, New_Id);
21069 end Update_New_Entities;
21071 ---------------------------
21072 -- Update_Pending_Itypes --
21073 ---------------------------
21075 procedure Update_Pending_Itypes
21076 (Old_Assoc : Node_Id;
21077 New_Assoc : Node_Id)
21083 if NCT_Tables_In_Use then
21084 Itypes := NCT_Pending_Itypes.Get (Old_Assoc);
21086 -- Update the Associated_Node_For_Itype attribute for all itypes
21087 -- which originally refer to Old_Assoc to designate New_Assoc.
21089 if Present (Itypes) then
21090 Item := First_Elmt (Itypes);
21091 while Present (Item) loop
21092 Set_Associated_Node_For_Itype (Node (Item), New_Assoc);
21098 end Update_Pending_Itypes;
21100 ----------------------------
21101 -- Update_Semantic_Fields --
21102 ----------------------------
21104 procedure Update_Semantic_Fields (Id : Entity_Id) is
21106 -- Discriminant_Constraint
21108 if Is_Type (Id) and then Has_Discriminants (Base_Type (Id)) then
21109 Set_Discriminant_Constraint (Id, Elist_Id (
21110 Copy_Field_With_Replacement
21111 (Field => Union_Id (Discriminant_Constraint (Id)),
21112 Semantic => True)));
21117 Set_Etype (Id, Node_Id (
21118 Copy_Field_With_Replacement
21119 (Field => Union_Id (Etype (Id)),
21120 Semantic => True)));
21123 -- Packed_Array_Impl_Type
21125 if Is_Array_Type (Id) then
21126 if Present (First_Index (Id)) then
21127 Set_First_Index (Id, First (List_Id (
21128 Copy_Field_With_Replacement
21129 (Field => Union_Id (List_Containing (First_Index (Id))),
21130 Semantic => True))));
21133 if Is_Packed (Id) then
21134 Set_Packed_Array_Impl_Type (Id, Node_Id (
21135 Copy_Field_With_Replacement
21136 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
21137 Semantic => True)));
21143 Set_Prev_Entity (Id, Node_Id (
21144 Copy_Field_With_Replacement
21145 (Field => Union_Id (Prev_Entity (Id)),
21146 Semantic => True)));
21150 Set_Next_Entity (Id, Node_Id (
21151 Copy_Field_With_Replacement
21152 (Field => Union_Id (Next_Entity (Id)),
21153 Semantic => True)));
21157 if Is_Discrete_Type (Id) then
21158 Set_Scalar_Range (Id, Node_Id (
21159 Copy_Field_With_Replacement
21160 (Field => Union_Id (Scalar_Range (Id)),
21161 Semantic => True)));
21166 -- Update the scope when the caller specified an explicit one
21168 if Present (New_Scope) then
21169 Set_Scope (Id, New_Scope);
21171 Set_Scope (Id, Node_Id (
21172 Copy_Field_With_Replacement
21173 (Field => Union_Id (Scope (Id)),
21174 Semantic => True)));
21176 end Update_Semantic_Fields;
21178 --------------------
21179 -- Visit_Any_Node --
21180 --------------------
21182 procedure Visit_Any_Node (N : Node_Or_Entity_Id) is
21184 if Nkind (N) in N_Entity then
21185 if Is_Itype (N) then
21193 end Visit_Any_Node;
21199 procedure Visit_Elist (List : Elist_Id) is
21203 -- The element of an entity list could be an entity, itype, or a
21204 -- node, hence the call to Visit_Any_Node.
21206 if Present (List) then
21207 Elmt := First_Elmt (List);
21208 while Present (Elmt) loop
21209 Visit_Any_Node (Node (Elmt));
21220 procedure Visit_Entity (Id : Entity_Id) is
21221 New_Id : Entity_Id;
21224 pragma Assert (Nkind (Id) in N_Entity);
21225 pragma Assert (not Is_Itype (Id));
21227 -- Nothing to do when the entity is not defined in the Actions list
21228 -- of an N_Expression_With_Actions node.
21230 if EWA_Level = 0 then
21233 -- Nothing to do when the entity is defined in a scoping construct
21234 -- within an N_Expression_With_Actions node, unless the caller has
21235 -- requested their replication.
21237 -- ??? should this restriction be eliminated?
21239 elsif EWA_Inner_Scope_Level > 0 and then not Scopes_In_EWA_OK then
21242 -- Nothing to do when the entity does not denote a construct that
21243 -- may appear within an N_Expression_With_Actions node. Relaxing
21244 -- this restriction leads to a performance penalty.
21246 -- ??? this list is flaky, and may hide dormant bugs
21247 -- Should functions be included???
21249 -- Loop parameters appear within quantified expressions and contain
21250 -- an entity declaration that must be replaced when the expander is
21251 -- active if the expression has been preanalyzed or analyzed.
21253 elsif not Ekind_In (Id, E_Block,
21259 and then not Is_Type (Id)
21263 elsif Ekind (Id) = E_Loop_Parameter
21264 and then No (Etype (Condition (Parent (Parent (Id)))))
21268 -- Nothing to do when the entity was already visited
21270 elsif NCT_Tables_In_Use
21271 and then Present (NCT_New_Entities.Get (Id))
21275 -- Nothing to do when the declaration node of the entity is not in
21276 -- the subtree being replicated.
21278 elsif not In_Subtree
21279 (N => Declaration_Node (Id),
21285 -- Create a new entity by directly copying the old entity. This
21286 -- action causes all attributes of the old entity to be inherited.
21288 New_Id := New_Copy (Id);
21290 -- Create a new name for the new entity because the back end needs
21291 -- distinct names for debugging purposes.
21293 Set_Chars (New_Id, New_Internal_Name ('T'));
21295 -- Update the Comes_From_Source and Sloc attributes of the entity in
21296 -- case the caller has supplied new values.
21298 Update_CFS_Sloc (New_Id);
21300 -- Establish the following mapping within table NCT_New_Entities:
21304 Add_New_Entity (Id, New_Id);
21306 -- Deal with the semantic fields of entities. The fields are visited
21307 -- because they may mention entities which reside within the subtree
21310 Visit_Semantic_Fields (Id);
21317 procedure Visit_Field
21319 Par_Nod : Node_Id := Empty;
21320 Semantic : Boolean := False)
21323 -- The field is empty
21325 if Field = Union_Id (Empty) then
21328 -- The field is an entity/itype/node
21330 elsif Field in Node_Range then
21332 N : constant Node_Id := Node_Id (Field);
21335 -- The field is an entity/itype
21337 if Nkind (N) in N_Entity then
21339 -- Itypes are always visited
21341 if Is_Itype (N) then
21344 -- An entity is visited when it is either a syntactic field
21345 -- or when the caller treats it as a semantic attribute.
21347 elsif Parent (N) = Par_Nod or else Semantic then
21351 -- The field is a node
21354 -- A node is visited when it is either a syntactic field or
21355 -- when the caller treats it as a semantic attribute.
21357 if Parent (N) = Par_Nod or else Semantic then
21363 -- The field is an entity list
21365 elsif Field in Elist_Range then
21366 Visit_Elist (Elist_Id (Field));
21368 -- The field is a syntax list
21370 elsif Field in List_Range then
21372 List : constant List_Id := List_Id (Field);
21375 -- A syntax list is visited when it is either a syntactic field
21376 -- or when the caller treats it as a semantic attribute.
21378 if Parent (List) = Par_Nod or else Semantic then
21383 -- Otherwise the field denotes information which does not need to be
21384 -- visited (chars, literals, etc.).
21395 procedure Visit_Itype (Itype : Entity_Id) is
21396 New_Assoc : Node_Id;
21397 New_Itype : Entity_Id;
21398 Old_Assoc : Node_Id;
21401 pragma Assert (Nkind (Itype) in N_Entity);
21402 pragma Assert (Is_Itype (Itype));
21404 -- Itypes that describe the designated type of access to subprograms
21405 -- have the structure of subprogram declarations, with signatures,
21406 -- etc. Either we duplicate the signatures completely, or choose to
21407 -- share such itypes, which is fine because their elaboration will
21408 -- have no side effects.
21410 if Ekind (Itype) = E_Subprogram_Type then
21413 -- Nothing to do if the itype was already visited
21415 elsif NCT_Tables_In_Use
21416 and then Present (NCT_New_Entities.Get (Itype))
21420 -- Nothing to do if the associated node of the itype is not within
21421 -- the subtree being replicated.
21423 elsif not In_Subtree
21424 (N => Associated_Node_For_Itype (Itype),
21430 -- Create a new itype by directly copying the old itype. This action
21431 -- causes all attributes of the old itype to be inherited.
21433 New_Itype := New_Copy (Itype);
21435 -- Create a new name for the new itype because the back end requires
21436 -- distinct names for debugging purposes.
21438 Set_Chars (New_Itype, New_Internal_Name ('T'));
21440 -- Update the Comes_From_Source and Sloc attributes of the itype in
21441 -- case the caller has supplied new values.
21443 Update_CFS_Sloc (New_Itype);
21445 -- Establish the following mapping within table NCT_New_Entities:
21447 -- Itype -> New_Itype
21449 Add_New_Entity (Itype, New_Itype);
21451 -- The new itype must be unfrozen because the resulting subtree may
21452 -- be inserted anywhere and cause an earlier or later freezing.
21454 if Present (Freeze_Node (New_Itype)) then
21455 Set_Freeze_Node (New_Itype, Empty);
21456 Set_Is_Frozen (New_Itype, False);
21459 -- If a record subtype is simply copied, the entity list will be
21460 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
21461 -- ??? What does this do?
21463 if Ekind_In (Itype, E_Class_Wide_Subtype, E_Record_Subtype) then
21464 Set_Cloned_Subtype (New_Itype, Itype);
21467 -- The associated node may denote an entity, in which case it may
21468 -- already have a new corresponding entity created during a prior
21469 -- call to Visit_Entity or Visit_Itype for the same subtree.
21472 -- Old_Assoc ---------> New_Assoc
21474 -- Created by Visit_Itype
21475 -- Itype -------------> New_Itype
21476 -- ANFI = Old_Assoc ANFI = Old_Assoc < must be updated
21478 -- In the example above, Old_Assoc is an arbitrary entity that was
21479 -- already visited for the same subtree and has a corresponding new
21480 -- entity New_Assoc. Old_Assoc was inherited by New_Itype by virtue
21481 -- of copying entities, however it must be updated to New_Assoc.
21483 Old_Assoc := Associated_Node_For_Itype (Itype);
21485 if Nkind (Old_Assoc) in N_Entity then
21486 if NCT_Tables_In_Use then
21487 New_Assoc := NCT_New_Entities.Get (Old_Assoc);
21489 if Present (New_Assoc) then
21490 Set_Associated_Node_For_Itype (New_Itype, New_Assoc);
21494 -- Otherwise the associated node denotes a node. Postpone the update
21495 -- until Phase 2 when the node is replicated. Establish the following
21496 -- mapping within table NCT_Pending_Itypes:
21498 -- Old_Assoc -> (New_Type, ...)
21501 Add_Pending_Itype (Old_Assoc, New_Itype);
21504 -- Deal with the semantic fields of itypes. The fields are visited
21505 -- because they may mention entities that reside within the subtree
21508 Visit_Semantic_Fields (Itype);
21515 procedure Visit_List (List : List_Id) is
21519 -- Note that the element of a syntactic list is always a node, never
21520 -- an entity or itype, hence the call to Visit_Node.
21522 if Present (List) then
21523 Elmt := First (List);
21524 while Present (Elmt) loop
21536 procedure Visit_Node (N : Node_Or_Entity_Id) is
21538 pragma Assert (Nkind (N) not in N_Entity);
21540 -- If the node is a quantified expression and expander is active,
21541 -- it contains an implicit declaration that may require a new entity
21542 -- when the condition has already been (pre)analyzed.
21544 if Nkind (N) = N_Expression_With_Actions
21546 (Nkind (N) = N_Quantified_Expression and then Expander_Active)
21548 EWA_Level := EWA_Level + 1;
21550 elsif EWA_Level > 0
21551 and then Nkind_In (N, N_Block_Statement,
21553 N_Subprogram_Declaration)
21555 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level + 1;
21559 (Field => Field1 (N),
21563 (Field => Field2 (N),
21567 (Field => Field3 (N),
21571 (Field => Field4 (N),
21575 (Field => Field5 (N),
21579 and then Nkind_In (N, N_Block_Statement,
21581 N_Subprogram_Declaration)
21583 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level - 1;
21585 elsif Nkind (N) = N_Expression_With_Actions then
21586 EWA_Level := EWA_Level - 1;
21590 ---------------------------
21591 -- Visit_Semantic_Fields --
21592 ---------------------------
21594 procedure Visit_Semantic_Fields (Id : Entity_Id) is
21596 pragma Assert (Nkind (Id) in N_Entity);
21598 -- Discriminant_Constraint
21600 if Is_Type (Id) and then Has_Discriminants (Base_Type (Id)) then
21602 (Field => Union_Id (Discriminant_Constraint (Id)),
21609 (Field => Union_Id (Etype (Id)),
21613 -- Packed_Array_Impl_Type
21615 if Is_Array_Type (Id) then
21616 if Present (First_Index (Id)) then
21618 (Field => Union_Id (List_Containing (First_Index (Id))),
21622 if Is_Packed (Id) then
21624 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
21631 if Is_Discrete_Type (Id) then
21633 (Field => Union_Id (Scalar_Range (Id)),
21636 end Visit_Semantic_Fields;
21638 -- Start of processing for New_Copy_Tree
21641 -- Routine New_Copy_Tree performs a deep copy of a subtree by creating
21642 -- shallow copies for each node within, and then updating the child and
21643 -- parent pointers accordingly. This process is straightforward, however
21644 -- the routine must deal with the following complications:
21646 -- * Entities defined within N_Expression_With_Actions nodes must be
21647 -- replicated rather than shared to avoid introducing two identical
21648 -- symbols within the same scope. Note that no other expression can
21649 -- currently define entities.
21652 -- Source_Low : ...;
21653 -- Source_High : ...;
21655 -- <reference to Source_Low>
21656 -- <reference to Source_High>
21659 -- New_Copy_Tree handles this case by first creating new entities
21660 -- and then updating all existing references to point to these new
21667 -- <reference to New_Low>
21668 -- <reference to New_High>
21671 -- * Itypes defined within the subtree must be replicated to avoid any
21672 -- dependencies on invalid or inaccessible data.
21674 -- subtype Source_Itype is ... range Source_Low .. Source_High;
21676 -- New_Copy_Tree handles this case by first creating a new itype in
21677 -- the same fashion as entities, and then updating various relevant
21680 -- subtype New_Itype is ... range New_Low .. New_High;
21682 -- * The Associated_Node_For_Itype field of itypes must be updated to
21683 -- reference the proper replicated entity or node.
21685 -- * Semantic fields of entities such as Etype and Scope must be
21686 -- updated to reference the proper replicated entities.
21688 -- * Semantic fields of nodes such as First_Real_Statement must be
21689 -- updated to reference the proper replicated nodes.
21691 -- Finally, quantified expressions contain an implicit delaration for
21692 -- the bound variable. Given that quantified expressions appearing
21693 -- in contracts are copied to create pragmas and eventually checking
21694 -- procedures, a new bound variable must be created for each copy, to
21695 -- prevent multiple declarations of the same symbol.
21697 -- To meet all these demands, routine New_Copy_Tree is split into two
21700 -- Phase 1 traverses the tree in order to locate entities and itypes
21701 -- defined within the subtree. New entities are generated and saved in
21702 -- table NCT_New_Entities. The semantic fields of all new entities and
21703 -- itypes are then updated accordingly.
21705 -- Phase 2 traverses the tree in order to replicate each node. Various
21706 -- semantic fields of nodes and entities are updated accordingly.
21708 -- Preparatory phase. Clear the contents of tables NCT_New_Entities and
21709 -- NCT_Pending_Itypes in case a previous call to New_Copy_Tree left some
21712 if NCT_Tables_In_Use then
21713 NCT_Tables_In_Use := False;
21715 NCT_New_Entities.Reset;
21716 NCT_Pending_Itypes.Reset;
21719 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with data
21720 -- supplied by a linear entity map. The tables offer faster access to
21723 Build_NCT_Tables (Map);
21725 -- Execute Phase 1. Traverse the subtree and generate new entities for
21726 -- the following cases:
21728 -- * An entity defined within an N_Expression_With_Actions node
21730 -- * An itype referenced within the subtree where the associated node
21731 -- is also in the subtree.
21733 -- All new entities are accessible via table NCT_New_Entities, which
21734 -- contains mappings of the form:
21736 -- Old_Entity -> New_Entity
21737 -- Old_Itype -> New_Itype
21739 -- In addition, the associated nodes of all new itypes are mapped in
21740 -- table NCT_Pending_Itypes:
21742 -- Assoc_Nod -> (New_Itype1, New_Itype2, .., New_ItypeN)
21744 Visit_Any_Node (Source);
21746 -- Update the semantic attributes of all new entities generated during
21747 -- Phase 1 before starting Phase 2. The updates could be performed in
21748 -- routine Corresponding_Entity, however this may cause the same entity
21749 -- to be updated multiple times, effectively generating useless nodes.
21750 -- Keeping the updates separates from Phase 2 ensures that only one set
21751 -- of attributes is generated for an entity at any one time.
21753 Update_New_Entities (Map);
21755 -- Execute Phase 2. Replicate the source subtree one node at a time.
21756 -- The following transformations take place:
21758 -- * References to entities and itypes are updated to refer to the
21759 -- new entities and itypes generated during Phase 1.
21761 -- * All Associated_Node_For_Itype attributes of itypes are updated
21762 -- to refer to the new replicated Associated_Node_For_Itype.
21764 return Copy_Node_With_Replacement (Source);
21767 -------------------------
21768 -- New_External_Entity --
21769 -------------------------
21771 function New_External_Entity
21772 (Kind : Entity_Kind;
21773 Scope_Id : Entity_Id;
21774 Sloc_Value : Source_Ptr;
21775 Related_Id : Entity_Id;
21776 Suffix : Character;
21777 Suffix_Index : Int := 0;
21778 Prefix : Character := ' ') return Entity_Id
21780 N : constant Entity_Id :=
21781 Make_Defining_Identifier (Sloc_Value,
21783 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
21786 Set_Ekind (N, Kind);
21787 Set_Is_Internal (N, True);
21788 Append_Entity (N, Scope_Id);
21789 Set_Public_Status (N);
21791 if Kind in Type_Kind then
21792 Init_Size_Align (N);
21796 end New_External_Entity;
21798 -------------------------
21799 -- New_Internal_Entity --
21800 -------------------------
21802 function New_Internal_Entity
21803 (Kind : Entity_Kind;
21804 Scope_Id : Entity_Id;
21805 Sloc_Value : Source_Ptr;
21806 Id_Char : Character) return Entity_Id
21808 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
21811 Set_Ekind (N, Kind);
21812 Set_Is_Internal (N, True);
21813 Append_Entity (N, Scope_Id);
21815 if Kind in Type_Kind then
21816 Init_Size_Align (N);
21820 end New_Internal_Entity;
21826 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
21827 Par : constant Node_Id := Parent (Actual_Id);
21831 -- If we are pointing at a positional parameter, it is a member of a
21832 -- node list (the list of parameters), and the next parameter is the
21833 -- next node on the list, unless we hit a parameter association, then
21834 -- we shift to using the chain whose head is the First_Named_Actual in
21835 -- the parent, and then is threaded using the Next_Named_Actual of the
21836 -- Parameter_Association. All this fiddling is because the original node
21837 -- list is in the textual call order, and what we need is the
21838 -- declaration order.
21840 if Is_List_Member (Actual_Id) then
21841 N := Next (Actual_Id);
21843 if Nkind (N) = N_Parameter_Association then
21845 -- In case of a build-in-place call, the call will no longer be a
21846 -- call; it will have been rewritten.
21848 if Nkind_In (Par, N_Entry_Call_Statement,
21850 N_Procedure_Call_Statement)
21852 return First_Named_Actual (Par);
21854 -- In case of a call rewritten in GNATprove mode while "inlining
21855 -- for proof" go to the original call.
21857 elsif Nkind (Par) = N_Null_Statement then
21861 Nkind (Original_Node (Par)) in N_Subprogram_Call);
21863 return First_Named_Actual (Original_Node (Par));
21872 return Next_Named_Actual (Parent (Actual_Id));
21876 procedure Next_Actual (Actual_Id : in out Node_Id) is
21878 Actual_Id := Next_Actual (Actual_Id);
21885 function Next_Global (Node : Node_Id) return Node_Id is
21887 -- The global item may either be in a list, or by itself, in which case
21888 -- there is no next global item with the same mode.
21890 if Is_List_Member (Node) then
21891 return Next (Node);
21897 procedure Next_Global (Node : in out Node_Id) is
21899 Node := Next_Global (Node);
21902 ----------------------------------
21903 -- New_Requires_Transient_Scope --
21904 ----------------------------------
21906 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
21907 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean;
21908 -- This is called for untagged records and protected types, with
21909 -- nondefaulted discriminants. Returns True if the size of function
21910 -- results is known at the call site, False otherwise. Returns False
21911 -- if there is a variant part that depends on the discriminants of
21912 -- this type, or if there is an array constrained by the discriminants
21913 -- of this type. ???Currently, this is overly conservative (the array
21914 -- could be nested inside some other record that is constrained by
21915 -- nondiscriminants). That is, the recursive calls are too conservative.
21917 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean;
21918 -- Returns True if Typ is a nonlimited record with defaulted
21919 -- discriminants whose max size makes it unsuitable for allocating on
21920 -- the primary stack.
21922 ------------------------------
21923 -- Caller_Known_Size_Record --
21924 ------------------------------
21926 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean is
21927 pragma Assert (Typ = Underlying_Type (Typ));
21930 if Has_Variant_Part (Typ) and then not Is_Definite_Subtype (Typ) then
21938 Comp := First_Entity (Typ);
21939 while Present (Comp) loop
21941 -- Only look at E_Component entities. No need to look at
21942 -- E_Discriminant entities, and we must ignore internal
21943 -- subtypes generated for constrained components.
21945 if Ekind (Comp) = E_Component then
21947 Comp_Type : constant Entity_Id :=
21948 Underlying_Type (Etype (Comp));
21951 if Is_Record_Type (Comp_Type)
21953 Is_Protected_Type (Comp_Type)
21955 if not Caller_Known_Size_Record (Comp_Type) then
21959 elsif Is_Array_Type (Comp_Type) then
21960 if Size_Depends_On_Discriminant (Comp_Type) then
21967 Next_Entity (Comp);
21972 end Caller_Known_Size_Record;
21974 ------------------------------
21975 -- Large_Max_Size_Mutable --
21976 ------------------------------
21978 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean is
21979 pragma Assert (Typ = Underlying_Type (Typ));
21981 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean;
21982 -- Returns true if the discrete type T has a large range
21984 ----------------------------
21985 -- Is_Large_Discrete_Type --
21986 ----------------------------
21988 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean is
21989 Threshold : constant Int := 16;
21990 -- Arbitrary threshold above which we consider it "large". We want
21991 -- a fairly large threshold, because these large types really
21992 -- shouldn't have default discriminants in the first place, in
21996 return UI_To_Int (RM_Size (T)) > Threshold;
21997 end Is_Large_Discrete_Type;
21999 -- Start of processing for Large_Max_Size_Mutable
22002 if Is_Record_Type (Typ)
22003 and then not Is_Limited_View (Typ)
22004 and then Has_Defaulted_Discriminants (Typ)
22006 -- Loop through the components, looking for an array whose upper
22007 -- bound(s) depends on discriminants, where both the subtype of
22008 -- the discriminant and the index subtype are too large.
22014 Comp := First_Entity (Typ);
22015 while Present (Comp) loop
22016 if Ekind (Comp) = E_Component then
22018 Comp_Type : constant Entity_Id :=
22019 Underlying_Type (Etype (Comp));
22026 if Is_Array_Type (Comp_Type) then
22027 Indx := First_Index (Comp_Type);
22029 while Present (Indx) loop
22030 Ityp := Etype (Indx);
22031 Hi := Type_High_Bound (Ityp);
22033 if Nkind (Hi) = N_Identifier
22034 and then Ekind (Entity (Hi)) = E_Discriminant
22035 and then Is_Large_Discrete_Type (Ityp)
22036 and then Is_Large_Discrete_Type
22037 (Etype (Entity (Hi)))
22048 Next_Entity (Comp);
22054 end Large_Max_Size_Mutable;
22056 -- Local declarations
22058 Typ : constant Entity_Id := Underlying_Type (Id);
22060 -- Start of processing for New_Requires_Transient_Scope
22063 -- This is a private type which is not completed yet. This can only
22064 -- happen in a default expression (of a formal parameter or of a
22065 -- record component). Do not expand transient scope in this case.
22070 -- Do not expand transient scope for non-existent procedure return or
22071 -- string literal types.
22073 elsif Typ = Standard_Void_Type
22074 or else Ekind (Typ) = E_String_Literal_Subtype
22078 -- If Typ is a generic formal incomplete type, then we want to look at
22079 -- the actual type.
22081 elsif Ekind (Typ) = E_Record_Subtype
22082 and then Present (Cloned_Subtype (Typ))
22084 return New_Requires_Transient_Scope (Cloned_Subtype (Typ));
22086 -- Functions returning specific tagged types may dispatch on result, so
22087 -- their returned value is allocated on the secondary stack, even in the
22088 -- definite case. We must treat nondispatching functions the same way,
22089 -- because access-to-function types can point at both, so the calling
22090 -- conventions must be compatible. Is_Tagged_Type includes controlled
22091 -- types and class-wide types. Controlled type temporaries need
22094 -- ???It's not clear why we need to return noncontrolled types with
22095 -- controlled components on the secondary stack.
22097 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
22100 -- Untagged definite subtypes are known size. This includes all
22101 -- elementary [sub]types. Tasks are known size even if they have
22102 -- discriminants. So we return False here, with one exception:
22103 -- For a type like:
22104 -- type T (Last : Natural := 0) is
22105 -- X : String (1 .. Last);
22107 -- we return True. That's because for "P(F(...));", where F returns T,
22108 -- we don't know the size of the result at the call site, so if we
22109 -- allocated it on the primary stack, we would have to allocate the
22110 -- maximum size, which is way too big.
22112 elsif Is_Definite_Subtype (Typ) or else Is_Task_Type (Typ) then
22113 return Large_Max_Size_Mutable (Typ);
22115 -- Indefinite (discriminated) untagged record or protected type
22117 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
22118 return not Caller_Known_Size_Record (Typ);
22120 -- Unconstrained array
22123 pragma Assert (Is_Array_Type (Typ) and not Is_Definite_Subtype (Typ));
22126 end New_Requires_Transient_Scope;
22128 ------------------------
22129 -- No_Caching_Enabled --
22130 ------------------------
22132 function No_Caching_Enabled (Id : Entity_Id) return Boolean is
22133 Prag : constant Node_Id := Get_Pragma (Id, Pragma_No_Caching);
22137 if Present (Prag) then
22138 Arg1 := First (Pragma_Argument_Associations (Prag));
22140 -- The pragma has an optional Boolean expression, the related
22141 -- property is enabled only when the expression evaluates to True.
22143 if Present (Arg1) then
22144 return Is_True (Expr_Value (Get_Pragma_Arg (Arg1)));
22146 -- Otherwise the lack of expression enables the property by
22153 -- The property was never set in the first place
22158 end No_Caching_Enabled;
22160 --------------------------
22161 -- No_Heap_Finalization --
22162 --------------------------
22164 function No_Heap_Finalization (Typ : Entity_Id) return Boolean is
22166 if Ekind_In (Typ, E_Access_Type, E_General_Access_Type)
22167 and then Is_Library_Level_Entity (Typ)
22169 -- A global No_Heap_Finalization pragma applies to all library-level
22170 -- named access-to-object types.
22172 if Present (No_Heap_Finalization_Pragma) then
22175 -- The library-level named access-to-object type itself is subject to
22176 -- pragma No_Heap_Finalization.
22178 elsif Present (Get_Pragma (Typ, Pragma_No_Heap_Finalization)) then
22184 end No_Heap_Finalization;
22186 -----------------------
22187 -- Normalize_Actuals --
22188 -----------------------
22190 -- Chain actuals according to formals of subprogram. If there are no named
22191 -- associations, the chain is simply the list of Parameter Associations,
22192 -- since the order is the same as the declaration order. If there are named
22193 -- associations, then the First_Named_Actual field in the N_Function_Call
22194 -- or N_Procedure_Call_Statement node points to the Parameter_Association
22195 -- node for the parameter that comes first in declaration order. The
22196 -- remaining named parameters are then chained in declaration order using
22197 -- Next_Named_Actual.
22199 -- This routine also verifies that the number of actuals is compatible with
22200 -- the number and default values of formals, but performs no type checking
22201 -- (type checking is done by the caller).
22203 -- If the matching succeeds, Success is set to True and the caller proceeds
22204 -- with type-checking. If the match is unsuccessful, then Success is set to
22205 -- False, and the caller attempts a different interpretation, if there is
22208 -- If the flag Report is on, the call is not overloaded, and a failure to
22209 -- match can be reported here, rather than in the caller.
22211 procedure Normalize_Actuals
22215 Success : out Boolean)
22217 Actuals : constant List_Id := Parameter_Associations (N);
22218 Actual : Node_Id := Empty;
22219 Formal : Entity_Id;
22220 Last : Node_Id := Empty;
22221 First_Named : Node_Id := Empty;
22224 Formals_To_Match : Integer := 0;
22225 Actuals_To_Match : Integer := 0;
22227 procedure Chain (A : Node_Id);
22228 -- Add named actual at the proper place in the list, using the
22229 -- Next_Named_Actual link.
22231 function Reporting return Boolean;
22232 -- Determines if an error is to be reported. To report an error, we
22233 -- need Report to be True, and also we do not report errors caused
22234 -- by calls to init procs that occur within other init procs. Such
22235 -- errors must always be cascaded errors, since if all the types are
22236 -- declared correctly, the compiler will certainly build decent calls.
22242 procedure Chain (A : Node_Id) is
22246 -- Call node points to first actual in list
22248 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
22251 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
22255 Set_Next_Named_Actual (Last, Empty);
22262 function Reporting return Boolean is
22267 elsif not Within_Init_Proc then
22270 elsif Is_Init_Proc (Entity (Name (N))) then
22278 -- Start of processing for Normalize_Actuals
22281 if Is_Access_Type (S) then
22283 -- The name in the call is a function call that returns an access
22284 -- to subprogram. The designated type has the list of formals.
22286 Formal := First_Formal (Designated_Type (S));
22288 Formal := First_Formal (S);
22291 while Present (Formal) loop
22292 Formals_To_Match := Formals_To_Match + 1;
22293 Next_Formal (Formal);
22296 -- Find if there is a named association, and verify that no positional
22297 -- associations appear after named ones.
22299 if Present (Actuals) then
22300 Actual := First (Actuals);
22303 while Present (Actual)
22304 and then Nkind (Actual) /= N_Parameter_Association
22306 Actuals_To_Match := Actuals_To_Match + 1;
22310 if No (Actual) and Actuals_To_Match = Formals_To_Match then
22312 -- Most common case: positional notation, no defaults
22317 elsif Actuals_To_Match > Formals_To_Match then
22319 -- Too many actuals: will not work
22322 if Is_Entity_Name (Name (N)) then
22323 Error_Msg_N ("too many arguments in call to&", Name (N));
22325 Error_Msg_N ("too many arguments in call", N);
22333 First_Named := Actual;
22335 while Present (Actual) loop
22336 if Nkind (Actual) /= N_Parameter_Association then
22338 ("positional parameters not allowed after named ones", Actual);
22343 Actuals_To_Match := Actuals_To_Match + 1;
22349 if Present (Actuals) then
22350 Actual := First (Actuals);
22353 Formal := First_Formal (S);
22354 while Present (Formal) loop
22356 -- Match the formals in order. If the corresponding actual is
22357 -- positional, nothing to do. Else scan the list of named actuals
22358 -- to find the one with the right name.
22360 if Present (Actual)
22361 and then Nkind (Actual) /= N_Parameter_Association
22364 Actuals_To_Match := Actuals_To_Match - 1;
22365 Formals_To_Match := Formals_To_Match - 1;
22368 -- For named parameters, search the list of actuals to find
22369 -- one that matches the next formal name.
22371 Actual := First_Named;
22373 while Present (Actual) loop
22374 if Chars (Selector_Name (Actual)) = Chars (Formal) then
22377 Actuals_To_Match := Actuals_To_Match - 1;
22378 Formals_To_Match := Formals_To_Match - 1;
22386 if Ekind (Formal) /= E_In_Parameter
22387 or else No (Default_Value (Formal))
22390 if (Comes_From_Source (S)
22391 or else Sloc (S) = Standard_Location)
22392 and then Is_Overloadable (S)
22396 Nkind_In (Parent (N), N_Procedure_Call_Statement,
22398 N_Parameter_Association)
22399 and then Ekind (S) /= E_Function
22401 Set_Etype (N, Etype (S));
22404 Error_Msg_Name_1 := Chars (S);
22405 Error_Msg_Sloc := Sloc (S);
22407 ("missing argument for parameter & "
22408 & "in call to % declared #", N, Formal);
22411 elsif Is_Overloadable (S) then
22412 Error_Msg_Name_1 := Chars (S);
22414 -- Point to type derivation that generated the
22417 Error_Msg_Sloc := Sloc (Parent (S));
22420 ("missing argument for parameter & "
22421 & "in call to % (inherited) #", N, Formal);
22425 ("missing argument for parameter &", N, Formal);
22433 Formals_To_Match := Formals_To_Match - 1;
22438 Next_Formal (Formal);
22441 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
22448 -- Find some superfluous named actual that did not get
22449 -- attached to the list of associations.
22451 Actual := First (Actuals);
22452 while Present (Actual) loop
22453 if Nkind (Actual) = N_Parameter_Association
22454 and then Actual /= Last
22455 and then No (Next_Named_Actual (Actual))
22457 -- A validity check may introduce a copy of a call that
22458 -- includes an extra actual (for example for an unrelated
22459 -- accessibility check). Check that the extra actual matches
22460 -- some extra formal, which must exist already because
22461 -- subprogram must be frozen at this point.
22463 if Present (Extra_Formals (S))
22464 and then not Comes_From_Source (Actual)
22465 and then Nkind (Actual) = N_Parameter_Association
22466 and then Chars (Extra_Formals (S)) =
22467 Chars (Selector_Name (Actual))
22472 ("unmatched actual & in call", Selector_Name (Actual));
22484 end Normalize_Actuals;
22486 --------------------------------
22487 -- Note_Possible_Modification --
22488 --------------------------------
22490 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
22491 Modification_Comes_From_Source : constant Boolean :=
22492 Comes_From_Source (Parent (N));
22498 -- Loop to find referenced entity, if there is one
22504 if Is_Entity_Name (Exp) then
22505 Ent := Entity (Exp);
22507 -- If the entity is missing, it is an undeclared identifier,
22508 -- and there is nothing to annotate.
22514 elsif Nkind (Exp) = N_Explicit_Dereference then
22516 P : constant Node_Id := Prefix (Exp);
22519 -- In formal verification mode, keep track of all reads and
22520 -- writes through explicit dereferences.
22522 if GNATprove_Mode then
22523 SPARK_Specific.Generate_Dereference (N, 'm');
22526 if Nkind (P) = N_Selected_Component
22527 and then Present (Entry_Formal (Entity (Selector_Name (P))))
22529 -- Case of a reference to an entry formal
22531 Ent := Entry_Formal (Entity (Selector_Name (P)));
22533 elsif Nkind (P) = N_Identifier
22534 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
22535 and then Present (Expression (Parent (Entity (P))))
22536 and then Nkind (Expression (Parent (Entity (P)))) =
22539 -- Case of a reference to a value on which side effects have
22542 Exp := Prefix (Expression (Parent (Entity (P))));
22550 elsif Nkind_In (Exp, N_Type_Conversion,
22551 N_Unchecked_Type_Conversion)
22553 Exp := Expression (Exp);
22556 elsif Nkind_In (Exp, N_Slice,
22557 N_Indexed_Component,
22558 N_Selected_Component)
22560 -- Special check, if the prefix is an access type, then return
22561 -- since we are modifying the thing pointed to, not the prefix.
22562 -- When we are expanding, most usually the prefix is replaced
22563 -- by an explicit dereference, and this test is not needed, but
22564 -- in some cases (notably -gnatc mode and generics) when we do
22565 -- not do full expansion, we need this special test.
22567 if Is_Access_Type (Etype (Prefix (Exp))) then
22570 -- Otherwise go to prefix and keep going
22573 Exp := Prefix (Exp);
22577 -- All other cases, not a modification
22583 -- Now look for entity being referenced
22585 if Present (Ent) then
22586 if Is_Object (Ent) then
22587 if Comes_From_Source (Exp)
22588 or else Modification_Comes_From_Source
22590 -- Give warning if pragma unmodified is given and we are
22591 -- sure this is a modification.
22593 if Has_Pragma_Unmodified (Ent) and then Sure then
22595 -- Note that the entity may be present only as a result
22596 -- of pragma Unused.
22598 if Has_Pragma_Unused (Ent) then
22599 Error_Msg_NE ("??pragma Unused given for &!", N, Ent);
22602 ("??pragma Unmodified given for &!", N, Ent);
22606 Set_Never_Set_In_Source (Ent, False);
22609 Set_Is_True_Constant (Ent, False);
22610 Set_Current_Value (Ent, Empty);
22611 Set_Is_Known_Null (Ent, False);
22613 if not Can_Never_Be_Null (Ent) then
22614 Set_Is_Known_Non_Null (Ent, False);
22617 -- Follow renaming chain
22619 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
22620 and then Present (Renamed_Object (Ent))
22622 Exp := Renamed_Object (Ent);
22624 -- If the entity is the loop variable in an iteration over
22625 -- a container, retrieve container expression to indicate
22626 -- possible modification.
22628 if Present (Related_Expression (Ent))
22629 and then Nkind (Parent (Related_Expression (Ent))) =
22630 N_Iterator_Specification
22632 Exp := Original_Node (Related_Expression (Ent));
22637 -- The expression may be the renaming of a subcomponent of an
22638 -- array or container. The assignment to the subcomponent is
22639 -- a modification of the container.
22641 elsif Comes_From_Source (Original_Node (Exp))
22642 and then Nkind_In (Original_Node (Exp), N_Selected_Component,
22643 N_Indexed_Component)
22645 Exp := Prefix (Original_Node (Exp));
22649 -- Generate a reference only if the assignment comes from
22650 -- source. This excludes, for example, calls to a dispatching
22651 -- assignment operation when the left-hand side is tagged. In
22652 -- GNATprove mode, we need those references also on generated
22653 -- code, as these are used to compute the local effects of
22656 if Modification_Comes_From_Source or GNATprove_Mode then
22657 Generate_Reference (Ent, Exp, 'm');
22659 -- If the target of the assignment is the bound variable
22660 -- in an iterator, indicate that the corresponding array
22661 -- or container is also modified.
22663 if Ada_Version >= Ada_2012
22664 and then Nkind (Parent (Ent)) = N_Iterator_Specification
22667 Domain : constant Node_Id := Name (Parent (Ent));
22670 -- TBD : in the full version of the construct, the
22671 -- domain of iteration can be given by an expression.
22673 if Is_Entity_Name (Domain) then
22674 Generate_Reference (Entity (Domain), Exp, 'm');
22675 Set_Is_True_Constant (Entity (Domain), False);
22676 Set_Never_Set_In_Source (Entity (Domain), False);
22685 -- If we are sure this is a modification from source, and we know
22686 -- this modifies a constant, then give an appropriate warning.
22689 and then Modification_Comes_From_Source
22690 and then Overlays_Constant (Ent)
22691 and then Address_Clause_Overlay_Warnings
22694 Addr : constant Node_Id := Address_Clause (Ent);
22699 Find_Overlaid_Entity (Addr, O_Ent, Off);
22701 Error_Msg_Sloc := Sloc (Addr);
22703 ("??constant& may be modified via address clause#",
22714 end Note_Possible_Modification;
22720 function Null_Status (N : Node_Id) return Null_Status_Kind is
22721 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean;
22722 -- Determine whether definition Def carries a null exclusion
22724 function Null_Status_Of_Entity (Id : Entity_Id) return Null_Status_Kind;
22725 -- Determine the null status of arbitrary entity Id
22727 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind;
22728 -- Determine the null status of type Typ
22730 ---------------------------
22731 -- Is_Null_Excluding_Def --
22732 ---------------------------
22734 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean is
22737 Nkind_In (Def, N_Access_Definition,
22738 N_Access_Function_Definition,
22739 N_Access_Procedure_Definition,
22740 N_Access_To_Object_Definition,
22741 N_Component_Definition,
22742 N_Derived_Type_Definition)
22743 and then Null_Exclusion_Present (Def);
22744 end Is_Null_Excluding_Def;
22746 ---------------------------
22747 -- Null_Status_Of_Entity --
22748 ---------------------------
22750 function Null_Status_Of_Entity
22751 (Id : Entity_Id) return Null_Status_Kind
22753 Decl : constant Node_Id := Declaration_Node (Id);
22757 -- The value of an imported or exported entity may be set externally
22758 -- regardless of a null exclusion. As a result, the value cannot be
22759 -- determined statically.
22761 if Is_Imported (Id) or else Is_Exported (Id) then
22764 elsif Nkind_In (Decl, N_Component_Declaration,
22765 N_Discriminant_Specification,
22766 N_Formal_Object_Declaration,
22767 N_Object_Declaration,
22768 N_Object_Renaming_Declaration,
22769 N_Parameter_Specification)
22771 -- A component declaration yields a non-null value when either
22772 -- its component definition or access definition carries a null
22775 if Nkind (Decl) = N_Component_Declaration then
22776 Def := Component_Definition (Decl);
22778 if Is_Null_Excluding_Def (Def) then
22779 return Is_Non_Null;
22782 Def := Access_Definition (Def);
22784 if Present (Def) and then Is_Null_Excluding_Def (Def) then
22785 return Is_Non_Null;
22788 -- A formal object declaration yields a non-null value if its
22789 -- access definition carries a null exclusion. If the object is
22790 -- default initialized, then the value depends on the expression.
22792 elsif Nkind (Decl) = N_Formal_Object_Declaration then
22793 Def := Access_Definition (Decl);
22795 if Present (Def) and then Is_Null_Excluding_Def (Def) then
22796 return Is_Non_Null;
22799 -- A constant may yield a null or non-null value depending on its
22800 -- initialization expression.
22802 elsif Ekind (Id) = E_Constant then
22803 return Null_Status (Constant_Value (Id));
22805 -- The construct yields a non-null value when it has a null
22808 elsif Null_Exclusion_Present (Decl) then
22809 return Is_Non_Null;
22811 -- An object renaming declaration yields a non-null value if its
22812 -- access definition carries a null exclusion. Otherwise the value
22813 -- depends on the renamed name.
22815 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
22816 Def := Access_Definition (Decl);
22818 if Present (Def) and then Is_Null_Excluding_Def (Def) then
22819 return Is_Non_Null;
22822 return Null_Status (Name (Decl));
22827 -- At this point the declaration of the entity does not carry a null
22828 -- exclusion and lacks an initialization expression. Check the status
22831 return Null_Status_Of_Type (Etype (Id));
22832 end Null_Status_Of_Entity;
22834 -------------------------
22835 -- Null_Status_Of_Type --
22836 -------------------------
22838 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind is
22843 -- Traverse the type chain looking for types with null exclusion
22846 while Present (Curr) and then Etype (Curr) /= Curr loop
22847 Decl := Parent (Curr);
22849 -- Guard against itypes which do not always have declarations. A
22850 -- type yields a non-null value if it carries a null exclusion.
22852 if Present (Decl) then
22853 if Nkind (Decl) = N_Full_Type_Declaration
22854 and then Is_Null_Excluding_Def (Type_Definition (Decl))
22856 return Is_Non_Null;
22858 elsif Nkind (Decl) = N_Subtype_Declaration
22859 and then Null_Exclusion_Present (Decl)
22861 return Is_Non_Null;
22865 Curr := Etype (Curr);
22868 -- The type chain does not contain any null excluding types
22871 end Null_Status_Of_Type;
22873 -- Start of processing for Null_Status
22876 -- Prevent cascaded errors or infinite loops when trying to determine
22877 -- the null status of an erroneous construct.
22879 if Error_Posted (N) then
22882 -- An allocator always creates a non-null value
22884 elsif Nkind (N) = N_Allocator then
22885 return Is_Non_Null;
22887 -- Taking the 'Access of something yields a non-null value
22889 elsif Nkind (N) = N_Attribute_Reference
22890 and then Nam_In (Attribute_Name (N), Name_Access,
22891 Name_Unchecked_Access,
22892 Name_Unrestricted_Access)
22894 return Is_Non_Null;
22896 -- "null" yields null
22898 elsif Nkind (N) = N_Null then
22901 -- Check the status of the operand of a type conversion
22903 elsif Nkind (N) = N_Type_Conversion then
22904 return Null_Status (Expression (N));
22906 -- The input denotes a reference to an entity. Determine whether the
22907 -- entity or its type yields a null or non-null value.
22909 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
22910 return Null_Status_Of_Entity (Entity (N));
22913 -- Otherwise it is not possible to determine the null status of the
22914 -- subexpression at compile time without resorting to simple flow
22920 --------------------------------------
22921 -- Null_To_Null_Address_Convert_OK --
22922 --------------------------------------
22924 function Null_To_Null_Address_Convert_OK
22926 Typ : Entity_Id := Empty) return Boolean
22929 if not Relaxed_RM_Semantics then
22933 if Nkind (N) = N_Null then
22934 return Present (Typ) and then Is_Descendant_Of_Address (Typ);
22936 elsif Nkind_In (N, N_Op_Eq, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt, N_Op_Ne)
22939 L : constant Node_Id := Left_Opnd (N);
22940 R : constant Node_Id := Right_Opnd (N);
22943 -- We check the Etype of the complementary operand since the
22944 -- N_Null node is not decorated at this stage.
22947 ((Nkind (L) = N_Null
22948 and then Is_Descendant_Of_Address (Etype (R)))
22950 (Nkind (R) = N_Null
22951 and then Is_Descendant_Of_Address (Etype (L))));
22956 end Null_To_Null_Address_Convert_OK;
22958 ---------------------------------
22959 -- Number_Of_Elements_In_Array --
22960 ---------------------------------
22962 function Number_Of_Elements_In_Array (T : Entity_Id) return Int is
22970 pragma Assert (Is_Array_Type (T));
22972 Indx := First_Index (T);
22973 while Present (Indx) loop
22974 Typ := Underlying_Type (Etype (Indx));
22976 -- Never look at junk bounds of a generic type
22978 if Is_Generic_Type (Typ) then
22982 -- Check the array bounds are known at compile time and return zero
22983 -- if they are not.
22985 Low := Type_Low_Bound (Typ);
22986 High := Type_High_Bound (Typ);
22988 if not Compile_Time_Known_Value (Low) then
22990 elsif not Compile_Time_Known_Value (High) then
22994 Num * UI_To_Int ((Expr_Value (High) - Expr_Value (Low) + 1));
23001 end Number_Of_Elements_In_Array;
23003 -------------------------
23004 -- Object_Access_Level --
23005 -------------------------
23007 -- Returns the static accessibility level of the view denoted by Obj. Note
23008 -- that the value returned is the result of a call to Scope_Depth. Only
23009 -- scope depths associated with dynamic scopes can actually be returned.
23010 -- Since only relative levels matter for accessibility checking, the fact
23011 -- that the distance between successive levels of accessibility is not
23012 -- always one is immaterial (invariant: if level(E2) is deeper than
23013 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
23015 function Object_Access_Level (Obj : Node_Id) return Uint is
23016 function Is_Interface_Conversion (N : Node_Id) return Boolean;
23017 -- Determine whether N is a construct of the form
23018 -- Some_Type (Operand._tag'Address)
23019 -- This construct appears in the context of dispatching calls.
23021 function Reference_To (Obj : Node_Id) return Node_Id;
23022 -- An explicit dereference is created when removing side effects from
23023 -- expressions for constraint checking purposes. In this case a local
23024 -- access type is created for it. The correct access level is that of
23025 -- the original source node. We detect this case by noting that the
23026 -- prefix of the dereference is created by an object declaration whose
23027 -- initial expression is a reference.
23029 -----------------------------
23030 -- Is_Interface_Conversion --
23031 -----------------------------
23033 function Is_Interface_Conversion (N : Node_Id) return Boolean is
23035 return Nkind (N) = N_Unchecked_Type_Conversion
23036 and then Nkind (Expression (N)) = N_Attribute_Reference
23037 and then Attribute_Name (Expression (N)) = Name_Address;
23038 end Is_Interface_Conversion;
23044 function Reference_To (Obj : Node_Id) return Node_Id is
23045 Pref : constant Node_Id := Prefix (Obj);
23047 if Is_Entity_Name (Pref)
23048 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
23049 and then Present (Expression (Parent (Entity (Pref))))
23050 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
23052 return (Prefix (Expression (Parent (Entity (Pref)))));
23062 -- Start of processing for Object_Access_Level
23065 if Nkind (Obj) = N_Defining_Identifier
23066 or else Is_Entity_Name (Obj)
23068 if Nkind (Obj) = N_Defining_Identifier then
23074 if Is_Prival (E) then
23075 E := Prival_Link (E);
23078 -- If E is a type then it denotes a current instance. For this case
23079 -- we add one to the normal accessibility level of the type to ensure
23080 -- that current instances are treated as always being deeper than
23081 -- than the level of any visible named access type (see 3.10.2(21)).
23083 if Is_Type (E) then
23084 return Type_Access_Level (E) + 1;
23086 elsif Present (Renamed_Object (E)) then
23087 return Object_Access_Level (Renamed_Object (E));
23089 -- Similarly, if E is a component of the current instance of a
23090 -- protected type, any instance of it is assumed to be at a deeper
23091 -- level than the type. For a protected object (whose type is an
23092 -- anonymous protected type) its components are at the same level
23093 -- as the type itself.
23095 elsif not Is_Overloadable (E)
23096 and then Ekind (Scope (E)) = E_Protected_Type
23097 and then Comes_From_Source (Scope (E))
23099 return Type_Access_Level (Scope (E)) + 1;
23102 -- Aliased formals of functions take their access level from the
23103 -- point of call, i.e. require a dynamic check. For static check
23104 -- purposes, this is smaller than the level of the subprogram
23105 -- itself. For procedures the aliased makes no difference.
23108 and then Is_Aliased (E)
23109 and then Ekind (Scope (E)) = E_Function
23111 return Type_Access_Level (Etype (E));
23114 return Scope_Depth (Enclosing_Dynamic_Scope (E));
23118 elsif Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
23119 if Is_Access_Type (Etype (Prefix (Obj))) then
23120 return Type_Access_Level (Etype (Prefix (Obj)));
23122 return Object_Access_Level (Prefix (Obj));
23125 elsif Nkind (Obj) = N_Explicit_Dereference then
23127 -- If the prefix is a selected access discriminant then we make a
23128 -- recursive call on the prefix, which will in turn check the level
23129 -- of the prefix object of the selected discriminant.
23131 -- In Ada 2012, if the discriminant has implicit dereference and
23132 -- the context is a selected component, treat this as an object of
23133 -- unknown scope (see below). This is necessary in compile-only mode;
23134 -- otherwise expansion will already have transformed the prefix into
23137 if Nkind (Prefix (Obj)) = N_Selected_Component
23138 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
23140 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
23142 (not Has_Implicit_Dereference
23143 (Entity (Selector_Name (Prefix (Obj))))
23144 or else Nkind (Parent (Obj)) /= N_Selected_Component)
23146 return Object_Access_Level (Prefix (Obj));
23148 -- Detect an interface conversion in the context of a dispatching
23149 -- call. Use the original form of the conversion to find the access
23150 -- level of the operand.
23152 elsif Is_Interface (Etype (Obj))
23153 and then Is_Interface_Conversion (Prefix (Obj))
23154 and then Nkind (Original_Node (Obj)) = N_Type_Conversion
23156 return Object_Access_Level (Original_Node (Obj));
23158 elsif not Comes_From_Source (Obj) then
23160 Ref : constant Node_Id := Reference_To (Obj);
23162 if Present (Ref) then
23163 return Object_Access_Level (Ref);
23165 return Type_Access_Level (Etype (Prefix (Obj)));
23170 return Type_Access_Level (Etype (Prefix (Obj)));
23173 elsif Nkind_In (Obj, N_Type_Conversion, N_Unchecked_Type_Conversion) then
23174 return Object_Access_Level (Expression (Obj));
23176 elsif Nkind (Obj) = N_Function_Call then
23178 -- Function results are objects, so we get either the access level of
23179 -- the function or, in the case of an indirect call, the level of the
23180 -- access-to-subprogram type. (This code is used for Ada 95, but it
23181 -- looks wrong, because it seems that we should be checking the level
23182 -- of the call itself, even for Ada 95. However, using the Ada 2005
23183 -- version of the code causes regressions in several tests that are
23184 -- compiled with -gnat95. ???)
23186 if Ada_Version < Ada_2005 then
23187 if Is_Entity_Name (Name (Obj)) then
23188 return Subprogram_Access_Level (Entity (Name (Obj)));
23190 return Type_Access_Level (Etype (Prefix (Name (Obj))));
23193 -- For Ada 2005, the level of the result object of a function call is
23194 -- defined to be the level of the call's innermost enclosing master.
23195 -- We determine that by querying the depth of the innermost enclosing
23199 Return_Master_Scope_Depth_Of_Call : declare
23200 function Innermost_Master_Scope_Depth
23201 (N : Node_Id) return Uint;
23202 -- Returns the scope depth of the given node's innermost
23203 -- enclosing dynamic scope (effectively the accessibility
23204 -- level of the innermost enclosing master).
23206 ----------------------------------
23207 -- Innermost_Master_Scope_Depth --
23208 ----------------------------------
23210 function Innermost_Master_Scope_Depth
23211 (N : Node_Id) return Uint
23213 Node_Par : Node_Id := Parent (N);
23216 -- Locate the nearest enclosing node (by traversing Parents)
23217 -- that Defining_Entity can be applied to, and return the
23218 -- depth of that entity's nearest enclosing dynamic scope.
23220 while Present (Node_Par) loop
23221 case Nkind (Node_Par) is
23222 when N_Abstract_Subprogram_Declaration
23223 | N_Block_Statement
23225 | N_Component_Declaration
23227 | N_Entry_Declaration
23228 | N_Exception_Declaration
23229 | N_Formal_Object_Declaration
23230 | N_Formal_Package_Declaration
23231 | N_Formal_Subprogram_Declaration
23232 | N_Formal_Type_Declaration
23233 | N_Full_Type_Declaration
23234 | N_Function_Specification
23235 | N_Generic_Declaration
23236 | N_Generic_Instantiation
23237 | N_Implicit_Label_Declaration
23238 | N_Incomplete_Type_Declaration
23239 | N_Loop_Parameter_Specification
23240 | N_Number_Declaration
23241 | N_Object_Declaration
23242 | N_Package_Declaration
23243 | N_Package_Specification
23244 | N_Parameter_Specification
23245 | N_Private_Extension_Declaration
23246 | N_Private_Type_Declaration
23247 | N_Procedure_Specification
23249 | N_Protected_Type_Declaration
23250 | N_Renaming_Declaration
23251 | N_Single_Protected_Declaration
23252 | N_Single_Task_Declaration
23253 | N_Subprogram_Declaration
23254 | N_Subtype_Declaration
23256 | N_Task_Type_Declaration
23259 (Nearest_Dynamic_Scope
23260 (Defining_Entity (Node_Par)));
23262 -- For a return statement within a function, return
23263 -- the depth of the function itself. This is not just
23264 -- a small optimization, but matters when analyzing
23265 -- the expression in an expression function before
23266 -- the body is created.
23268 when N_Simple_Return_Statement =>
23269 if Ekind (Current_Scope) = E_Function then
23270 return Scope_Depth (Current_Scope);
23277 Node_Par := Parent (Node_Par);
23280 pragma Assert (False);
23282 -- Should never reach the following return
23284 return Scope_Depth (Current_Scope) + 1;
23285 end Innermost_Master_Scope_Depth;
23287 -- Start of processing for Return_Master_Scope_Depth_Of_Call
23290 return Innermost_Master_Scope_Depth (Obj);
23291 end Return_Master_Scope_Depth_Of_Call;
23294 -- For convenience we handle qualified expressions, even though they
23295 -- aren't technically object names.
23297 elsif Nkind (Obj) = N_Qualified_Expression then
23298 return Object_Access_Level (Expression (Obj));
23300 -- Ditto for aggregates. They have the level of the temporary that
23301 -- will hold their value.
23303 elsif Nkind (Obj) = N_Aggregate then
23304 return Object_Access_Level (Current_Scope);
23306 -- Otherwise return the scope level of Standard. (If there are cases
23307 -- that fall through to this point they will be treated as having
23308 -- global accessibility for now. ???)
23311 return Scope_Depth (Standard_Standard);
23313 end Object_Access_Level;
23315 ----------------------------------
23316 -- Old_Requires_Transient_Scope --
23317 ----------------------------------
23319 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
23320 Typ : constant Entity_Id := Underlying_Type (Id);
23323 -- This is a private type which is not completed yet. This can only
23324 -- happen in a default expression (of a formal parameter or of a
23325 -- record component). Do not expand transient scope in this case.
23330 -- Do not expand transient scope for non-existent procedure return
23332 elsif Typ = Standard_Void_Type then
23335 -- Elementary types do not require a transient scope
23337 elsif Is_Elementary_Type (Typ) then
23340 -- Generally, indefinite subtypes require a transient scope, since the
23341 -- back end cannot generate temporaries, since this is not a valid type
23342 -- for declaring an object. It might be possible to relax this in the
23343 -- future, e.g. by declaring the maximum possible space for the type.
23345 elsif not Is_Definite_Subtype (Typ) then
23348 -- Functions returning tagged types may dispatch on result so their
23349 -- returned value is allocated on the secondary stack. Controlled
23350 -- type temporaries need finalization.
23352 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
23357 elsif Is_Record_Type (Typ) then
23362 Comp := First_Entity (Typ);
23363 while Present (Comp) loop
23364 if Ekind (Comp) = E_Component then
23366 -- ???It's not clear we need a full recursive call to
23367 -- Old_Requires_Transient_Scope here. Note that the
23368 -- following can't happen.
23370 pragma Assert (Is_Definite_Subtype (Etype (Comp)));
23371 pragma Assert (not Has_Controlled_Component (Etype (Comp)));
23373 if Old_Requires_Transient_Scope (Etype (Comp)) then
23378 Next_Entity (Comp);
23384 -- String literal types never require transient scope
23386 elsif Ekind (Typ) = E_String_Literal_Subtype then
23389 -- Array type. Note that we already know that this is a constrained
23390 -- array, since unconstrained arrays will fail the indefinite test.
23392 elsif Is_Array_Type (Typ) then
23394 -- If component type requires a transient scope, the array does too
23396 if Old_Requires_Transient_Scope (Component_Type (Typ)) then
23399 -- Otherwise, we only need a transient scope if the size depends on
23400 -- the value of one or more discriminants.
23403 return Size_Depends_On_Discriminant (Typ);
23406 -- All other cases do not require a transient scope
23409 pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
23412 end Old_Requires_Transient_Scope;
23414 ---------------------------------
23415 -- Original_Aspect_Pragma_Name --
23416 ---------------------------------
23418 function Original_Aspect_Pragma_Name (N : Node_Id) return Name_Id is
23420 Item_Nam : Name_Id;
23423 pragma Assert (Nkind_In (N, N_Aspect_Specification, N_Pragma));
23427 -- The pragma was generated to emulate an aspect, use the original
23428 -- aspect specification.
23430 if Nkind (Item) = N_Pragma and then From_Aspect_Specification (Item) then
23431 Item := Corresponding_Aspect (Item);
23434 -- Retrieve the name of the aspect/pragma. As assertion pragmas from
23435 -- a generic instantiation might have been rewritten into pragma Check,
23436 -- we look at the original node for Item. Note also that Pre, Pre_Class,
23437 -- Post and Post_Class rewrite their pragma identifier to preserve the
23438 -- original name, so we look at the original node for the identifier.
23439 -- ??? this is kludgey
23441 if Nkind (Item) = N_Pragma then
23443 Chars (Original_Node (Pragma_Identifier (Original_Node (Item))));
23446 pragma Assert (Nkind (Item) = N_Aspect_Specification);
23447 Item_Nam := Chars (Identifier (Item));
23450 -- Deal with 'Class by converting the name to its _XXX form
23452 if Class_Present (Item) then
23453 if Item_Nam = Name_Invariant then
23454 Item_Nam := Name_uInvariant;
23456 elsif Item_Nam = Name_Post then
23457 Item_Nam := Name_uPost;
23459 elsif Item_Nam = Name_Pre then
23460 Item_Nam := Name_uPre;
23462 elsif Nam_In (Item_Nam, Name_Type_Invariant,
23463 Name_Type_Invariant_Class)
23465 Item_Nam := Name_uType_Invariant;
23467 -- Nothing to do for other cases (e.g. a Check that derived from
23468 -- Pre_Class and has the flag set). Also we do nothing if the name
23469 -- is already in special _xxx form.
23475 end Original_Aspect_Pragma_Name;
23477 --------------------------------------
23478 -- Original_Corresponding_Operation --
23479 --------------------------------------
23481 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
23483 Typ : constant Entity_Id := Find_Dispatching_Type (S);
23486 -- If S is an inherited primitive S2 the original corresponding
23487 -- operation of S is the original corresponding operation of S2
23489 if Present (Alias (S))
23490 and then Find_Dispatching_Type (Alias (S)) /= Typ
23492 return Original_Corresponding_Operation (Alias (S));
23494 -- If S overrides an inherited subprogram S2 the original corresponding
23495 -- operation of S is the original corresponding operation of S2
23497 elsif Present (Overridden_Operation (S)) then
23498 return Original_Corresponding_Operation (Overridden_Operation (S));
23500 -- otherwise it is S itself
23505 end Original_Corresponding_Operation;
23507 -------------------
23508 -- Output_Entity --
23509 -------------------
23511 procedure Output_Entity (Id : Entity_Id) is
23515 Scop := Scope (Id);
23517 -- The entity may lack a scope when it is in the process of being
23518 -- analyzed. Use the current scope as an approximation.
23521 Scop := Current_Scope;
23524 Output_Name (Chars (Id), Scop);
23531 procedure Output_Name (Nam : Name_Id; Scop : Entity_Id := Current_Scope) is
23535 (Get_Qualified_Name
23542 ----------------------
23543 -- Policy_In_Effect --
23544 ----------------------
23546 function Policy_In_Effect (Policy : Name_Id) return Name_Id is
23547 function Policy_In_List (List : Node_Id) return Name_Id;
23548 -- Determine the mode of a policy in a N_Pragma list
23550 --------------------
23551 -- Policy_In_List --
23552 --------------------
23554 function Policy_In_List (List : Node_Id) return Name_Id is
23561 while Present (Prag) loop
23562 Arg1 := First (Pragma_Argument_Associations (Prag));
23563 Arg2 := Next (Arg1);
23565 Arg1 := Get_Pragma_Arg (Arg1);
23566 Arg2 := Get_Pragma_Arg (Arg2);
23568 -- The current Check_Policy pragma matches the requested policy or
23569 -- appears in the single argument form (Assertion, policy_id).
23571 if Nam_In (Chars (Arg1), Name_Assertion, Policy) then
23572 return Chars (Arg2);
23575 Prag := Next_Pragma (Prag);
23579 end Policy_In_List;
23585 -- Start of processing for Policy_In_Effect
23588 if not Is_Valid_Assertion_Kind (Policy) then
23589 raise Program_Error;
23592 -- Inspect all policy pragmas that appear within scopes (if any)
23594 Kind := Policy_In_List (Check_Policy_List);
23596 -- Inspect all configuration policy pragmas (if any)
23598 if Kind = No_Name then
23599 Kind := Policy_In_List (Check_Policy_List_Config);
23602 -- The context lacks policy pragmas, determine the mode based on whether
23603 -- assertions are enabled at the configuration level. This ensures that
23604 -- the policy is preserved when analyzing generics.
23606 if Kind = No_Name then
23607 if Assertions_Enabled_Config then
23608 Kind := Name_Check;
23610 Kind := Name_Ignore;
23614 -- In CodePeer mode and GNATprove mode, we need to consider all
23615 -- assertions, unless they are disabled. Force Name_Check on
23616 -- ignored assertions.
23618 if Nam_In (Kind, Name_Ignore, Name_Off)
23619 and then (CodePeer_Mode or GNATprove_Mode)
23621 Kind := Name_Check;
23625 end Policy_In_Effect;
23627 ----------------------------------
23628 -- Predicate_Tests_On_Arguments --
23629 ----------------------------------
23631 function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean is
23633 -- Always test predicates on indirect call
23635 if Ekind (Subp) = E_Subprogram_Type then
23638 -- Do not test predicates on call to generated default Finalize, since
23639 -- we are not interested in whether something we are finalizing (and
23640 -- typically destroying) satisfies its predicates.
23642 elsif Chars (Subp) = Name_Finalize
23643 and then not Comes_From_Source (Subp)
23647 -- Do not test predicates on any internally generated routines
23649 elsif Is_Internal_Name (Chars (Subp)) then
23652 -- Do not test predicates on call to Init_Proc, since if needed the
23653 -- predicate test will occur at some other point.
23655 elsif Is_Init_Proc (Subp) then
23658 -- Do not test predicates on call to predicate function, since this
23659 -- would cause infinite recursion.
23661 elsif Ekind (Subp) = E_Function
23662 and then (Is_Predicate_Function (Subp)
23664 Is_Predicate_Function_M (Subp))
23668 -- For now, no other exceptions
23673 end Predicate_Tests_On_Arguments;
23675 -----------------------
23676 -- Private_Component --
23677 -----------------------
23679 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
23680 Ancestor : constant Entity_Id := Base_Type (Type_Id);
23682 function Trace_Components
23684 Check : Boolean) return Entity_Id;
23685 -- Recursive function that does the work, and checks against circular
23686 -- definition for each subcomponent type.
23688 ----------------------
23689 -- Trace_Components --
23690 ----------------------
23692 function Trace_Components
23694 Check : Boolean) return Entity_Id
23696 Btype : constant Entity_Id := Base_Type (T);
23697 Component : Entity_Id;
23699 Candidate : Entity_Id := Empty;
23702 if Check and then Btype = Ancestor then
23703 Error_Msg_N ("circular type definition", Type_Id);
23707 if Is_Private_Type (Btype) and then not Is_Generic_Type (Btype) then
23708 if Present (Full_View (Btype))
23709 and then Is_Record_Type (Full_View (Btype))
23710 and then not Is_Frozen (Btype)
23712 -- To indicate that the ancestor depends on a private type, the
23713 -- current Btype is sufficient. However, to check for circular
23714 -- definition we must recurse on the full view.
23716 Candidate := Trace_Components (Full_View (Btype), True);
23718 if Candidate = Any_Type then
23728 elsif Is_Array_Type (Btype) then
23729 return Trace_Components (Component_Type (Btype), True);
23731 elsif Is_Record_Type (Btype) then
23732 Component := First_Entity (Btype);
23733 while Present (Component)
23734 and then Comes_From_Source (Component)
23736 -- Skip anonymous types generated by constrained components
23738 if not Is_Type (Component) then
23739 P := Trace_Components (Etype (Component), True);
23741 if Present (P) then
23742 if P = Any_Type then
23750 Next_Entity (Component);
23758 end Trace_Components;
23760 -- Start of processing for Private_Component
23763 return Trace_Components (Type_Id, False);
23764 end Private_Component;
23766 ---------------------------
23767 -- Primitive_Names_Match --
23768 ---------------------------
23770 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
23771 function Non_Internal_Name (E : Entity_Id) return Name_Id;
23772 -- Given an internal name, returns the corresponding non-internal name
23774 ------------------------
23775 -- Non_Internal_Name --
23776 ------------------------
23778 function Non_Internal_Name (E : Entity_Id) return Name_Id is
23780 Get_Name_String (Chars (E));
23781 Name_Len := Name_Len - 1;
23783 end Non_Internal_Name;
23785 -- Start of processing for Primitive_Names_Match
23788 pragma Assert (Present (E1) and then Present (E2));
23790 return Chars (E1) = Chars (E2)
23792 (not Is_Internal_Name (Chars (E1))
23793 and then Is_Internal_Name (Chars (E2))
23794 and then Non_Internal_Name (E2) = Chars (E1))
23796 (not Is_Internal_Name (Chars (E2))
23797 and then Is_Internal_Name (Chars (E1))
23798 and then Non_Internal_Name (E1) = Chars (E2))
23800 (Is_Predefined_Dispatching_Operation (E1)
23801 and then Is_Predefined_Dispatching_Operation (E2)
23802 and then Same_TSS (E1, E2))
23804 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
23805 end Primitive_Names_Match;
23807 -----------------------
23808 -- Process_End_Label --
23809 -----------------------
23811 procedure Process_End_Label
23820 Label_Ref : Boolean;
23821 -- Set True if reference to end label itself is required
23824 -- Gets set to the operator symbol or identifier that references the
23825 -- entity Ent. For the child unit case, this is the identifier from the
23826 -- designator. For other cases, this is simply Endl.
23828 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
23829 -- N is an identifier node that appears as a parent unit reference in
23830 -- the case where Ent is a child unit. This procedure generates an
23831 -- appropriate cross-reference entry. E is the corresponding entity.
23833 -------------------------
23834 -- Generate_Parent_Ref --
23835 -------------------------
23837 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
23839 -- If names do not match, something weird, skip reference
23841 if Chars (E) = Chars (N) then
23843 -- Generate the reference. We do NOT consider this as a reference
23844 -- for unreferenced symbol purposes.
23846 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
23848 if Style_Check then
23849 Style.Check_Identifier (N, E);
23852 end Generate_Parent_Ref;
23854 -- Start of processing for Process_End_Label
23857 -- If no node, ignore. This happens in some error situations, and
23858 -- also for some internally generated structures where no end label
23859 -- references are required in any case.
23865 -- Nothing to do if no End_Label, happens for internally generated
23866 -- constructs where we don't want an end label reference anyway. Also
23867 -- nothing to do if Endl is a string literal, which means there was
23868 -- some prior error (bad operator symbol)
23870 Endl := End_Label (N);
23872 if No (Endl) or else Nkind (Endl) = N_String_Literal then
23876 -- Reference node is not in extended main source unit
23878 if not In_Extended_Main_Source_Unit (N) then
23880 -- Generally we do not collect references except for the extended
23881 -- main source unit. The one exception is the 'e' entry for a
23882 -- package spec, where it is useful for a client to have the
23883 -- ending information to define scopes.
23889 Label_Ref := False;
23891 -- For this case, we can ignore any parent references, but we
23892 -- need the package name itself for the 'e' entry.
23894 if Nkind (Endl) = N_Designator then
23895 Endl := Identifier (Endl);
23899 -- Reference is in extended main source unit
23904 -- For designator, generate references for the parent entries
23906 if Nkind (Endl) = N_Designator then
23908 -- Generate references for the prefix if the END line comes from
23909 -- source (otherwise we do not need these references) We climb the
23910 -- scope stack to find the expected entities.
23912 if Comes_From_Source (Endl) then
23913 Nam := Name (Endl);
23914 Scop := Current_Scope;
23915 while Nkind (Nam) = N_Selected_Component loop
23916 Scop := Scope (Scop);
23917 exit when No (Scop);
23918 Generate_Parent_Ref (Selector_Name (Nam), Scop);
23919 Nam := Prefix (Nam);
23922 if Present (Scop) then
23923 Generate_Parent_Ref (Nam, Scope (Scop));
23927 Endl := Identifier (Endl);
23931 -- If the end label is not for the given entity, then either we have
23932 -- some previous error, or this is a generic instantiation for which
23933 -- we do not need to make a cross-reference in this case anyway. In
23934 -- either case we simply ignore the call.
23936 if Chars (Ent) /= Chars (Endl) then
23940 -- If label was really there, then generate a normal reference and then
23941 -- adjust the location in the end label to point past the name (which
23942 -- should almost always be the semicolon).
23944 Loc := Sloc (Endl);
23946 if Comes_From_Source (Endl) then
23948 -- If a label reference is required, then do the style check and
23949 -- generate an l-type cross-reference entry for the label
23952 if Style_Check then
23953 Style.Check_Identifier (Endl, Ent);
23956 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
23959 -- Set the location to point past the label (normally this will
23960 -- mean the semicolon immediately following the label). This is
23961 -- done for the sake of the 'e' or 't' entry generated below.
23963 Get_Decoded_Name_String (Chars (Endl));
23964 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
23967 -- In SPARK mode, no missing label is allowed for packages and
23968 -- subprogram bodies. Detect those cases by testing whether
23969 -- Process_End_Label was called for a body (Typ = 't') or a package.
23971 if Restriction_Check_Required (SPARK_05)
23972 and then (Typ = 't' or else Ekind (Ent) = E_Package)
23974 Error_Msg_Node_1 := Endl;
23975 Check_SPARK_05_Restriction
23976 ("`END &` required", Endl, Force => True);
23980 -- Now generate the e/t reference
23982 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
23984 -- Restore Sloc, in case modified above, since we have an identifier
23985 -- and the normal Sloc should be left set in the tree.
23987 Set_Sloc (Endl, Loc);
23988 end Process_End_Label;
23990 --------------------------------
23991 -- Propagate_Concurrent_Flags --
23992 --------------------------------
23994 procedure Propagate_Concurrent_Flags
23996 Comp_Typ : Entity_Id)
23999 if Has_Task (Comp_Typ) then
24000 Set_Has_Task (Typ);
24003 if Has_Protected (Comp_Typ) then
24004 Set_Has_Protected (Typ);
24007 if Has_Timing_Event (Comp_Typ) then
24008 Set_Has_Timing_Event (Typ);
24010 end Propagate_Concurrent_Flags;
24012 ------------------------------
24013 -- Propagate_DIC_Attributes --
24014 ------------------------------
24016 procedure Propagate_DIC_Attributes
24018 From_Typ : Entity_Id)
24020 DIC_Proc : Entity_Id;
24023 if Present (Typ) and then Present (From_Typ) then
24024 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
24026 -- Nothing to do if both the source and the destination denote the
24029 if From_Typ = Typ then
24032 -- Nothing to do when the destination denotes an incomplete type
24033 -- because the DIC is associated with the current instance of a
24034 -- private type, thus it can never apply to an incomplete type.
24036 elsif Is_Incomplete_Type (Typ) then
24040 DIC_Proc := DIC_Procedure (From_Typ);
24042 -- The setting of the attributes is intentionally conservative. This
24043 -- prevents accidental clobbering of enabled attributes.
24045 if Has_Inherited_DIC (From_Typ)
24046 and then not Has_Inherited_DIC (Typ)
24048 Set_Has_Inherited_DIC (Typ);
24051 if Has_Own_DIC (From_Typ) and then not Has_Own_DIC (Typ) then
24052 Set_Has_Own_DIC (Typ);
24055 if Present (DIC_Proc) and then No (DIC_Procedure (Typ)) then
24056 Set_DIC_Procedure (Typ, DIC_Proc);
24059 end Propagate_DIC_Attributes;
24061 ------------------------------------
24062 -- Propagate_Invariant_Attributes --
24063 ------------------------------------
24065 procedure Propagate_Invariant_Attributes
24067 From_Typ : Entity_Id)
24069 Full_IP : Entity_Id;
24070 Part_IP : Entity_Id;
24073 if Present (Typ) and then Present (From_Typ) then
24074 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
24076 -- Nothing to do if both the source and the destination denote the
24079 if From_Typ = Typ then
24083 Full_IP := Invariant_Procedure (From_Typ);
24084 Part_IP := Partial_Invariant_Procedure (From_Typ);
24086 -- The setting of the attributes is intentionally conservative. This
24087 -- prevents accidental clobbering of enabled attributes.
24089 if Has_Inheritable_Invariants (From_Typ)
24090 and then not Has_Inheritable_Invariants (Typ)
24092 Set_Has_Inheritable_Invariants (Typ);
24095 if Has_Inherited_Invariants (From_Typ)
24096 and then not Has_Inherited_Invariants (Typ)
24098 Set_Has_Inherited_Invariants (Typ);
24101 if Has_Own_Invariants (From_Typ)
24102 and then not Has_Own_Invariants (Typ)
24104 Set_Has_Own_Invariants (Typ);
24107 if Present (Full_IP) and then No (Invariant_Procedure (Typ)) then
24108 Set_Invariant_Procedure (Typ, Full_IP);
24111 if Present (Part_IP) and then No (Partial_Invariant_Procedure (Typ))
24113 Set_Partial_Invariant_Procedure (Typ, Part_IP);
24116 end Propagate_Invariant_Attributes;
24118 ---------------------------------------
24119 -- Record_Possible_Part_Of_Reference --
24120 ---------------------------------------
24122 procedure Record_Possible_Part_Of_Reference
24123 (Var_Id : Entity_Id;
24126 Encap : constant Entity_Id := Encapsulating_State (Var_Id);
24130 -- The variable is a constituent of a single protected/task type. Such
24131 -- a variable acts as a component of the type and must appear within a
24132 -- specific region (SPARK RM 9(3)). Instead of recording the reference,
24133 -- verify its legality now.
24135 if Present (Encap) and then Is_Single_Concurrent_Object (Encap) then
24136 Check_Part_Of_Reference (Var_Id, Ref);
24138 -- The variable is subject to pragma Part_Of and may eventually become a
24139 -- constituent of a single protected/task type. Record the reference to
24140 -- verify its placement when the contract of the variable is analyzed.
24142 elsif Present (Get_Pragma (Var_Id, Pragma_Part_Of)) then
24143 Refs := Part_Of_References (Var_Id);
24146 Refs := New_Elmt_List;
24147 Set_Part_Of_References (Var_Id, Refs);
24150 Append_Elmt (Ref, Refs);
24152 end Record_Possible_Part_Of_Reference;
24158 function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
24159 Seen : Boolean := False;
24161 function Is_Reference (N : Node_Id) return Traverse_Result;
24162 -- Determine whether node N denotes a reference to Id. If this is the
24163 -- case, set global flag Seen to True and stop the traversal.
24169 function Is_Reference (N : Node_Id) return Traverse_Result is
24171 if Is_Entity_Name (N)
24172 and then Present (Entity (N))
24173 and then Entity (N) = Id
24182 procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
24184 -- Start of processing for Referenced
24187 Inspect_Expression (Expr);
24191 ------------------------------------
24192 -- References_Generic_Formal_Type --
24193 ------------------------------------
24195 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
24197 function Process (N : Node_Id) return Traverse_Result;
24198 -- Process one node in search for generic formal type
24204 function Process (N : Node_Id) return Traverse_Result is
24206 if Nkind (N) in N_Has_Entity then
24208 E : constant Entity_Id := Entity (N);
24210 if Present (E) then
24211 if Is_Generic_Type (E) then
24213 elsif Present (Etype (E))
24214 and then Is_Generic_Type (Etype (E))
24225 function Traverse is new Traverse_Func (Process);
24226 -- Traverse tree to look for generic type
24229 if Inside_A_Generic then
24230 return Traverse (N) = Abandon;
24234 end References_Generic_Formal_Type;
24236 -------------------------------
24237 -- Remove_Entity_And_Homonym --
24238 -------------------------------
24240 procedure Remove_Entity_And_Homonym (Id : Entity_Id) is
24242 Remove_Entity (Id);
24243 Remove_Homonym (Id);
24244 end Remove_Entity_And_Homonym;
24246 --------------------
24247 -- Remove_Homonym --
24248 --------------------
24250 procedure Remove_Homonym (Id : Entity_Id) is
24252 Prev : Entity_Id := Empty;
24255 if Id = Current_Entity (Id) then
24256 if Present (Homonym (Id)) then
24257 Set_Current_Entity (Homonym (Id));
24259 Set_Name_Entity_Id (Chars (Id), Empty);
24263 Hom := Current_Entity (Id);
24264 while Present (Hom) and then Hom /= Id loop
24266 Hom := Homonym (Hom);
24269 -- If Id is not on the homonym chain, nothing to do
24271 if Present (Hom) then
24272 Set_Homonym (Prev, Homonym (Id));
24275 end Remove_Homonym;
24277 ------------------------------
24278 -- Remove_Overloaded_Entity --
24279 ------------------------------
24281 procedure Remove_Overloaded_Entity (Id : Entity_Id) is
24282 procedure Remove_Primitive_Of (Typ : Entity_Id);
24283 -- Remove primitive subprogram Id from the list of primitives that
24284 -- belong to type Typ.
24286 -------------------------
24287 -- Remove_Primitive_Of --
24288 -------------------------
24290 procedure Remove_Primitive_Of (Typ : Entity_Id) is
24294 if Is_Tagged_Type (Typ) then
24295 Prims := Direct_Primitive_Operations (Typ);
24297 if Present (Prims) then
24298 Remove (Prims, Id);
24301 end Remove_Primitive_Of;
24305 Formal : Entity_Id;
24307 -- Start of processing for Remove_Overloaded_Entity
24310 Remove_Entity_And_Homonym (Id);
24312 -- The entity denotes a primitive subprogram. Remove it from the list of
24313 -- primitives of the associated controlling type.
24315 if Ekind_In (Id, E_Function, E_Procedure) and then Is_Primitive (Id) then
24316 Formal := First_Formal (Id);
24317 while Present (Formal) loop
24318 if Is_Controlling_Formal (Formal) then
24319 Remove_Primitive_Of (Etype (Formal));
24323 Next_Formal (Formal);
24326 if Ekind (Id) = E_Function and then Has_Controlling_Result (Id) then
24327 Remove_Primitive_Of (Etype (Id));
24330 end Remove_Overloaded_Entity;
24332 ---------------------
24333 -- Rep_To_Pos_Flag --
24334 ---------------------
24336 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
24338 return New_Occurrence_Of
24339 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
24340 end Rep_To_Pos_Flag;
24342 --------------------
24343 -- Require_Entity --
24344 --------------------
24346 procedure Require_Entity (N : Node_Id) is
24348 if Is_Entity_Name (N) and then No (Entity (N)) then
24349 if Total_Errors_Detected /= 0 then
24350 Set_Entity (N, Any_Id);
24352 raise Program_Error;
24355 end Require_Entity;
24357 ------------------------------
24358 -- Requires_Transient_Scope --
24359 ------------------------------
24361 -- A transient scope is required when variable-sized temporaries are
24362 -- allocated on the secondary stack, or when finalization actions must be
24363 -- generated before the next instruction.
24365 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
24366 Old_Result : constant Boolean := Old_Requires_Transient_Scope (Id);
24368 procedure Ensure_Minimum_Decoration (Typ : Entity_Id);
24369 -- If Typ is not frozen then add to Typ the minimum decoration required
24370 -- by Requires_Transient_Scope to reliably provide its functionality;
24371 -- otherwise no action is performed.
24373 -------------------------------
24374 -- Ensure_Minimum_Decoration --
24375 -------------------------------
24377 procedure Ensure_Minimum_Decoration (Typ : Entity_Id) is
24379 -- Do not set Has_Controlled_Component on a class-wide equivalent
24380 -- type. See Make_CW_Equivalent_Type.
24383 and then not Is_Frozen (Typ)
24384 and then (Is_Record_Type (Typ)
24385 or else Is_Concurrent_Type (Typ)
24386 or else Is_Incomplete_Or_Private_Type (Typ))
24387 and then not Is_Class_Wide_Equivalent_Type (Typ)
24393 Comp := First_Component (Typ);
24394 while Present (Comp) loop
24395 if Has_Controlled_Component (Etype (Comp))
24397 (Chars (Comp) /= Name_uParent
24398 and then Is_Controlled (Etype (Comp)))
24400 (Is_Protected_Type (Etype (Comp))
24402 Present (Corresponding_Record_Type (Etype (Comp)))
24404 Has_Controlled_Component
24405 (Corresponding_Record_Type (Etype (Comp))))
24407 Set_Has_Controlled_Component (Typ);
24411 Next_Component (Comp);
24415 end Ensure_Minimum_Decoration;
24417 -- Start of processing for Requires_Transient_Scope
24420 if Debug_Flag_QQ then
24424 Ensure_Minimum_Decoration (Id);
24427 New_Result : constant Boolean := New_Requires_Transient_Scope (Id);
24430 -- Assert that we're not putting things on the secondary stack if we
24431 -- didn't before; we are trying to AVOID secondary stack when
24434 if not Old_Result then
24435 pragma Assert (not New_Result);
24439 if New_Result /= Old_Result then
24440 Results_Differ (Id, Old_Result, New_Result);
24445 end Requires_Transient_Scope;
24447 --------------------
24448 -- Results_Differ --
24449 --------------------
24451 procedure Results_Differ
24457 if False then -- False to disable; True for debugging
24458 Treepr.Print_Tree_Node (Id);
24460 if Old_Val = New_Val then
24461 raise Program_Error;
24464 end Results_Differ;
24466 --------------------------
24467 -- Reset_Analyzed_Flags --
24468 --------------------------
24470 procedure Reset_Analyzed_Flags (N : Node_Id) is
24471 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
24472 -- Function used to reset Analyzed flags in tree. Note that we do
24473 -- not reset Analyzed flags in entities, since there is no need to
24474 -- reanalyze entities, and indeed, it is wrong to do so, since it
24475 -- can result in generating auxiliary stuff more than once.
24477 --------------------
24478 -- Clear_Analyzed --
24479 --------------------
24481 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
24483 if Nkind (N) not in N_Entity then
24484 Set_Analyzed (N, False);
24488 end Clear_Analyzed;
24490 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
24492 -- Start of processing for Reset_Analyzed_Flags
24495 Reset_Analyzed (N);
24496 end Reset_Analyzed_Flags;
24498 ------------------------
24499 -- Restore_SPARK_Mode --
24500 ------------------------
24502 procedure Restore_SPARK_Mode
24503 (Mode : SPARK_Mode_Type;
24507 SPARK_Mode := Mode;
24508 SPARK_Mode_Pragma := Prag;
24509 end Restore_SPARK_Mode;
24511 --------------------------------
24512 -- Returns_Unconstrained_Type --
24513 --------------------------------
24515 function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
24517 return Ekind (Subp) = E_Function
24518 and then not Is_Scalar_Type (Etype (Subp))
24519 and then not Is_Access_Type (Etype (Subp))
24520 and then not Is_Constrained (Etype (Subp));
24521 end Returns_Unconstrained_Type;
24523 ----------------------------
24524 -- Root_Type_Of_Full_View --
24525 ----------------------------
24527 function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id is
24528 Rtyp : constant Entity_Id := Root_Type (T);
24531 -- The root type of the full view may itself be a private type. Keep
24532 -- looking for the ultimate derivation parent.
24534 if Is_Private_Type (Rtyp) and then Present (Full_View (Rtyp)) then
24535 return Root_Type_Of_Full_View (Full_View (Rtyp));
24539 end Root_Type_Of_Full_View;
24541 ---------------------------
24542 -- Safe_To_Capture_Value --
24543 ---------------------------
24545 function Safe_To_Capture_Value
24548 Cond : Boolean := False) return Boolean
24551 -- The only entities for which we track constant values are variables
24552 -- which are not renamings, constants, out parameters, and in out
24553 -- parameters, so check if we have this case.
24555 -- Note: it may seem odd to track constant values for constants, but in
24556 -- fact this routine is used for other purposes than simply capturing
24557 -- the value. In particular, the setting of Known[_Non]_Null.
24559 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
24561 Ekind_In (Ent, E_Constant, E_Out_Parameter, E_In_Out_Parameter)
24565 -- For conditionals, we also allow loop parameters and all formals,
24566 -- including in parameters.
24568 elsif Cond and then Ekind_In (Ent, E_Loop_Parameter, E_In_Parameter) then
24571 -- For all other cases, not just unsafe, but impossible to capture
24572 -- Current_Value, since the above are the only entities which have
24573 -- Current_Value fields.
24579 -- Skip if volatile or aliased, since funny things might be going on in
24580 -- these cases which we cannot necessarily track. Also skip any variable
24581 -- for which an address clause is given, or whose address is taken. Also
24582 -- never capture value of library level variables (an attempt to do so
24583 -- can occur in the case of package elaboration code).
24585 if Treat_As_Volatile (Ent)
24586 or else Is_Aliased (Ent)
24587 or else Present (Address_Clause (Ent))
24588 or else Address_Taken (Ent)
24589 or else (Is_Library_Level_Entity (Ent)
24590 and then Ekind (Ent) = E_Variable)
24595 -- OK, all above conditions are met. We also require that the scope of
24596 -- the reference be the same as the scope of the entity, not counting
24597 -- packages and blocks and loops.
24600 E_Scope : constant Entity_Id := Scope (Ent);
24601 R_Scope : Entity_Id;
24604 R_Scope := Current_Scope;
24605 while R_Scope /= Standard_Standard loop
24606 exit when R_Scope = E_Scope;
24608 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
24611 R_Scope := Scope (R_Scope);
24616 -- We also require that the reference does not appear in a context
24617 -- where it is not sure to be executed (i.e. a conditional context
24618 -- or an exception handler). We skip this if Cond is True, since the
24619 -- capturing of values from conditional tests handles this ok.
24632 -- Seems dubious that case expressions are not handled here ???
24635 while Present (P) loop
24636 if Nkind (P) = N_If_Statement
24637 or else Nkind (P) = N_Case_Statement
24638 or else (Nkind (P) in N_Short_Circuit
24639 and then Desc = Right_Opnd (P))
24640 or else (Nkind (P) = N_If_Expression
24641 and then Desc /= First (Expressions (P)))
24642 or else Nkind (P) = N_Exception_Handler
24643 or else Nkind (P) = N_Selective_Accept
24644 or else Nkind (P) = N_Conditional_Entry_Call
24645 or else Nkind (P) = N_Timed_Entry_Call
24646 or else Nkind (P) = N_Asynchronous_Select
24654 -- A special Ada 2012 case: the original node may be part
24655 -- of the else_actions of a conditional expression, in which
24656 -- case it might not have been expanded yet, and appears in
24657 -- a non-syntactic list of actions. In that case it is clearly
24658 -- not safe to save a value.
24661 and then Is_List_Member (Desc)
24662 and then No (Parent (List_Containing (Desc)))
24670 -- OK, looks safe to set value
24673 end Safe_To_Capture_Value;
24679 function Same_Name (N1, N2 : Node_Id) return Boolean is
24680 K1 : constant Node_Kind := Nkind (N1);
24681 K2 : constant Node_Kind := Nkind (N2);
24684 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
24685 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
24687 return Chars (N1) = Chars (N2);
24689 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
24690 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
24692 return Same_Name (Selector_Name (N1), Selector_Name (N2))
24693 and then Same_Name (Prefix (N1), Prefix (N2));
24704 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
24705 N1 : constant Node_Id := Original_Node (Node1);
24706 N2 : constant Node_Id := Original_Node (Node2);
24707 -- We do the tests on original nodes, since we are most interested
24708 -- in the original source, not any expansion that got in the way.
24710 K1 : constant Node_Kind := Nkind (N1);
24711 K2 : constant Node_Kind := Nkind (N2);
24714 -- First case, both are entities with same entity
24716 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
24718 EN1 : constant Entity_Id := Entity (N1);
24719 EN2 : constant Entity_Id := Entity (N2);
24721 if Present (EN1) and then Present (EN2)
24722 and then (Ekind_In (EN1, E_Variable, E_Constant)
24723 or else Is_Formal (EN1))
24731 -- Second case, selected component with same selector, same record
24733 if K1 = N_Selected_Component
24734 and then K2 = N_Selected_Component
24735 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
24737 return Same_Object (Prefix (N1), Prefix (N2));
24739 -- Third case, indexed component with same subscripts, same array
24741 elsif K1 = N_Indexed_Component
24742 and then K2 = N_Indexed_Component
24743 and then Same_Object (Prefix (N1), Prefix (N2))
24748 E1 := First (Expressions (N1));
24749 E2 := First (Expressions (N2));
24750 while Present (E1) loop
24751 if not Same_Value (E1, E2) then
24762 -- Fourth case, slice of same array with same bounds
24765 and then K2 = N_Slice
24766 and then Nkind (Discrete_Range (N1)) = N_Range
24767 and then Nkind (Discrete_Range (N2)) = N_Range
24768 and then Same_Value (Low_Bound (Discrete_Range (N1)),
24769 Low_Bound (Discrete_Range (N2)))
24770 and then Same_Value (High_Bound (Discrete_Range (N1)),
24771 High_Bound (Discrete_Range (N2)))
24773 return Same_Name (Prefix (N1), Prefix (N2));
24775 -- All other cases, not clearly the same object
24786 function Same_Type (T1, T2 : Entity_Id) return Boolean is
24791 elsif not Is_Constrained (T1)
24792 and then not Is_Constrained (T2)
24793 and then Base_Type (T1) = Base_Type (T2)
24797 -- For now don't bother with case of identical constraints, to be
24798 -- fiddled with later on perhaps (this is only used for optimization
24799 -- purposes, so it is not critical to do a best possible job)
24810 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
24812 if Compile_Time_Known_Value (Node1)
24813 and then Compile_Time_Known_Value (Node2)
24815 -- Handle properly compile-time expressions that are not
24818 if Is_String_Type (Etype (Node1)) then
24819 return Expr_Value_S (Node1) = Expr_Value_S (Node2);
24822 return Expr_Value (Node1) = Expr_Value (Node2);
24825 elsif Same_Object (Node1, Node2) then
24832 --------------------
24833 -- Set_SPARK_Mode --
24834 --------------------
24836 procedure Set_SPARK_Mode (Context : Entity_Id) is
24838 -- Do not consider illegal or partially decorated constructs
24840 if Ekind (Context) = E_Void or else Error_Posted (Context) then
24843 elsif Present (SPARK_Pragma (Context)) then
24845 (Mode => Get_SPARK_Mode_From_Annotation (SPARK_Pragma (Context)),
24846 Prag => SPARK_Pragma (Context));
24848 end Set_SPARK_Mode;
24850 -------------------------
24851 -- Scalar_Part_Present --
24852 -------------------------
24854 function Scalar_Part_Present (Typ : Entity_Id) return Boolean is
24855 Val_Typ : constant Entity_Id := Validated_View (Typ);
24859 if Is_Scalar_Type (Val_Typ) then
24862 elsif Is_Array_Type (Val_Typ) then
24863 return Scalar_Part_Present (Component_Type (Val_Typ));
24865 elsif Is_Record_Type (Val_Typ) then
24866 Field := First_Component_Or_Discriminant (Val_Typ);
24867 while Present (Field) loop
24868 if Scalar_Part_Present (Etype (Field)) then
24872 Next_Component_Or_Discriminant (Field);
24877 end Scalar_Part_Present;
24879 ------------------------
24880 -- Scope_Is_Transient --
24881 ------------------------
24883 function Scope_Is_Transient return Boolean is
24885 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
24886 end Scope_Is_Transient;
24892 function Scope_Within
24893 (Inner : Entity_Id;
24894 Outer : Entity_Id) return Boolean
24900 while Present (Curr) and then Curr /= Standard_Standard loop
24901 Curr := Scope (Curr);
24903 if Curr = Outer then
24906 -- A selective accept body appears within a task type, but the
24907 -- enclosing subprogram is the procedure of the task body.
24909 elsif Ekind (Implementation_Base_Type (Curr)) = E_Task_Type
24911 Outer = Task_Body_Procedure (Implementation_Base_Type (Curr))
24915 -- Ditto for the body of a protected operation
24917 elsif Is_Subprogram (Curr)
24918 and then Outer = Protected_Body_Subprogram (Curr)
24922 -- Outside of its scope, a synchronized type may just be private
24924 elsif Is_Private_Type (Curr)
24925 and then Present (Full_View (Curr))
24926 and then Is_Concurrent_Type (Full_View (Curr))
24928 return Scope_Within (Full_View (Curr), Outer);
24935 --------------------------
24936 -- Scope_Within_Or_Same --
24937 --------------------------
24939 function Scope_Within_Or_Same
24940 (Inner : Entity_Id;
24941 Outer : Entity_Id) return Boolean
24943 Curr : Entity_Id := Inner;
24946 -- Similar to the above, but check for scope identity first
24948 while Present (Curr) and then Curr /= Standard_Standard loop
24949 if Curr = Outer then
24952 elsif Ekind (Implementation_Base_Type (Curr)) = E_Task_Type
24954 Outer = Task_Body_Procedure (Implementation_Base_Type (Curr))
24958 elsif Is_Subprogram (Curr)
24959 and then Outer = Protected_Body_Subprogram (Curr)
24963 elsif Is_Private_Type (Curr)
24964 and then Present (Full_View (Curr))
24966 if Full_View (Curr) = Outer then
24969 return Scope_Within (Full_View (Curr), Outer);
24973 Curr := Scope (Curr);
24977 end Scope_Within_Or_Same;
24979 --------------------
24980 -- Set_Convention --
24981 --------------------
24983 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
24985 Basic_Set_Convention (E, Val);
24988 and then Is_Access_Subprogram_Type (Base_Type (E))
24989 and then Has_Foreign_Convention (E)
24991 Set_Can_Use_Internal_Rep (E, False);
24994 -- If E is an object, including a component, and the type of E is an
24995 -- anonymous access type with no convention set, then also set the
24996 -- convention of the anonymous access type. We do not do this for
24997 -- anonymous protected types, since protected types always have the
24998 -- default convention.
25000 if Present (Etype (E))
25001 and then (Is_Object (E)
25003 -- Allow E_Void (happens for pragma Convention appearing
25004 -- in the middle of a record applying to a component)
25006 or else Ekind (E) = E_Void)
25009 Typ : constant Entity_Id := Etype (E);
25012 if Ekind_In (Typ, E_Anonymous_Access_Type,
25013 E_Anonymous_Access_Subprogram_Type)
25014 and then not Has_Convention_Pragma (Typ)
25016 Basic_Set_Convention (Typ, Val);
25017 Set_Has_Convention_Pragma (Typ);
25019 -- And for the access subprogram type, deal similarly with the
25020 -- designated E_Subprogram_Type, which is always internal.
25022 if Ekind (Typ) = E_Anonymous_Access_Subprogram_Type then
25024 Dtype : constant Entity_Id := Designated_Type (Typ);
25026 if Ekind (Dtype) = E_Subprogram_Type
25027 and then not Has_Convention_Pragma (Dtype)
25029 Basic_Set_Convention (Dtype, Val);
25030 Set_Has_Convention_Pragma (Dtype);
25037 end Set_Convention;
25039 ------------------------
25040 -- Set_Current_Entity --
25041 ------------------------
25043 -- The given entity is to be set as the currently visible definition of its
25044 -- associated name (i.e. the Node_Id associated with its name). All we have
25045 -- to do is to get the name from the identifier, and then set the
25046 -- associated Node_Id to point to the given entity.
25048 procedure Set_Current_Entity (E : Entity_Id) is
25050 Set_Name_Entity_Id (Chars (E), E);
25051 end Set_Current_Entity;
25053 ---------------------------
25054 -- Set_Debug_Info_Needed --
25055 ---------------------------
25057 procedure Set_Debug_Info_Needed (T : Entity_Id) is
25059 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
25060 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
25061 -- Used to set debug info in a related node if not set already
25063 --------------------------------------
25064 -- Set_Debug_Info_Needed_If_Not_Set --
25065 --------------------------------------
25067 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
25069 if Present (E) and then not Needs_Debug_Info (E) then
25070 Set_Debug_Info_Needed (E);
25072 -- For a private type, indicate that the full view also needs
25073 -- debug information.
25076 and then Is_Private_Type (E)
25077 and then Present (Full_View (E))
25079 Set_Debug_Info_Needed (Full_View (E));
25082 end Set_Debug_Info_Needed_If_Not_Set;
25084 -- Start of processing for Set_Debug_Info_Needed
25087 -- Nothing to do if there is no available entity
25092 -- Nothing to do for an entity with suppressed debug information
25094 elsif Debug_Info_Off (T) then
25097 -- Nothing to do for an ignored Ghost entity because the entity will be
25098 -- eliminated from the tree.
25100 elsif Is_Ignored_Ghost_Entity (T) then
25103 -- Nothing to do if entity comes from a predefined file. Library files
25104 -- are compiled without debug information, but inlined bodies of these
25105 -- routines may appear in user code, and debug information on them ends
25106 -- up complicating debugging the user code.
25108 elsif In_Inlined_Body and then In_Predefined_Unit (T) then
25109 Set_Needs_Debug_Info (T, False);
25112 -- Set flag in entity itself. Note that we will go through the following
25113 -- circuitry even if the flag is already set on T. That's intentional,
25114 -- it makes sure that the flag will be set in subsidiary entities.
25116 Set_Needs_Debug_Info (T);
25118 -- Set flag on subsidiary entities if not set already
25120 if Is_Object (T) then
25121 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
25123 elsif Is_Type (T) then
25124 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
25126 if Is_Record_Type (T) then
25128 Ent : Entity_Id := First_Entity (T);
25130 while Present (Ent) loop
25131 Set_Debug_Info_Needed_If_Not_Set (Ent);
25136 -- For a class wide subtype, we also need debug information
25137 -- for the equivalent type.
25139 if Ekind (T) = E_Class_Wide_Subtype then
25140 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
25143 elsif Is_Array_Type (T) then
25144 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
25147 Indx : Node_Id := First_Index (T);
25149 while Present (Indx) loop
25150 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
25155 -- For a packed array type, we also need debug information for
25156 -- the type used to represent the packed array. Conversely, we
25157 -- also need it for the former if we need it for the latter.
25159 if Is_Packed (T) then
25160 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Impl_Type (T));
25163 if Is_Packed_Array_Impl_Type (T) then
25164 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
25167 elsif Is_Access_Type (T) then
25168 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
25170 elsif Is_Private_Type (T) then
25172 FV : constant Entity_Id := Full_View (T);
25175 Set_Debug_Info_Needed_If_Not_Set (FV);
25177 -- If the full view is itself a derived private type, we need
25178 -- debug information on its underlying type.
25181 and then Is_Private_Type (FV)
25182 and then Present (Underlying_Full_View (FV))
25184 Set_Needs_Debug_Info (Underlying_Full_View (FV));
25188 elsif Is_Protected_Type (T) then
25189 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
25191 elsif Is_Scalar_Type (T) then
25193 -- If the subrange bounds are materialized by dedicated constant
25194 -- objects, also include them in the debug info to make sure the
25195 -- debugger can properly use them.
25197 if Present (Scalar_Range (T))
25198 and then Nkind (Scalar_Range (T)) = N_Range
25201 Low_Bnd : constant Node_Id := Type_Low_Bound (T);
25202 High_Bnd : constant Node_Id := Type_High_Bound (T);
25205 if Is_Entity_Name (Low_Bnd) then
25206 Set_Debug_Info_Needed_If_Not_Set (Entity (Low_Bnd));
25209 if Is_Entity_Name (High_Bnd) then
25210 Set_Debug_Info_Needed_If_Not_Set (Entity (High_Bnd));
25216 end Set_Debug_Info_Needed;
25218 ----------------------------
25219 -- Set_Entity_With_Checks --
25220 ----------------------------
25222 procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id) is
25223 Val_Actual : Entity_Id;
25225 Post_Node : Node_Id;
25228 -- Unconditionally set the entity
25230 Set_Entity (N, Val);
25232 -- The node to post on is the selector in the case of an expanded name,
25233 -- and otherwise the node itself.
25235 if Nkind (N) = N_Expanded_Name then
25236 Post_Node := Selector_Name (N);
25241 -- Check for violation of No_Fixed_IO
25243 if Restriction_Check_Required (No_Fixed_IO)
25245 ((RTU_Loaded (Ada_Text_IO)
25246 and then (Is_RTE (Val, RE_Decimal_IO)
25248 Is_RTE (Val, RE_Fixed_IO)))
25251 (RTU_Loaded (Ada_Wide_Text_IO)
25252 and then (Is_RTE (Val, RO_WT_Decimal_IO)
25254 Is_RTE (Val, RO_WT_Fixed_IO)))
25257 (RTU_Loaded (Ada_Wide_Wide_Text_IO)
25258 and then (Is_RTE (Val, RO_WW_Decimal_IO)
25260 Is_RTE (Val, RO_WW_Fixed_IO))))
25262 -- A special extra check, don't complain about a reference from within
25263 -- the Ada.Interrupts package itself!
25265 and then not In_Same_Extended_Unit (N, Val)
25267 Check_Restriction (No_Fixed_IO, Post_Node);
25270 -- Remaining checks are only done on source nodes. Note that we test
25271 -- for violation of No_Fixed_IO even on non-source nodes, because the
25272 -- cases for checking violations of this restriction are instantiations
25273 -- where the reference in the instance has Comes_From_Source False.
25275 if not Comes_From_Source (N) then
25279 -- Check for violation of No_Abort_Statements, which is triggered by
25280 -- call to Ada.Task_Identification.Abort_Task.
25282 if Restriction_Check_Required (No_Abort_Statements)
25283 and then (Is_RTE (Val, RE_Abort_Task))
25285 -- A special extra check, don't complain about a reference from within
25286 -- the Ada.Task_Identification package itself!
25288 and then not In_Same_Extended_Unit (N, Val)
25290 Check_Restriction (No_Abort_Statements, Post_Node);
25293 if Val = Standard_Long_Long_Integer then
25294 Check_Restriction (No_Long_Long_Integers, Post_Node);
25297 -- Check for violation of No_Dynamic_Attachment
25299 if Restriction_Check_Required (No_Dynamic_Attachment)
25300 and then RTU_Loaded (Ada_Interrupts)
25301 and then (Is_RTE (Val, RE_Is_Reserved) or else
25302 Is_RTE (Val, RE_Is_Attached) or else
25303 Is_RTE (Val, RE_Current_Handler) or else
25304 Is_RTE (Val, RE_Attach_Handler) or else
25305 Is_RTE (Val, RE_Exchange_Handler) or else
25306 Is_RTE (Val, RE_Detach_Handler) or else
25307 Is_RTE (Val, RE_Reference))
25309 -- A special extra check, don't complain about a reference from within
25310 -- the Ada.Interrupts package itself!
25312 and then not In_Same_Extended_Unit (N, Val)
25314 Check_Restriction (No_Dynamic_Attachment, Post_Node);
25317 -- Check for No_Implementation_Identifiers
25319 if Restriction_Check_Required (No_Implementation_Identifiers) then
25321 -- We have an implementation defined entity if it is marked as
25322 -- implementation defined, or is defined in a package marked as
25323 -- implementation defined. However, library packages themselves
25324 -- are excluded (we don't want to flag Interfaces itself, just
25325 -- the entities within it).
25327 if (Is_Implementation_Defined (Val)
25329 (Present (Scope (Val))
25330 and then Is_Implementation_Defined (Scope (Val))))
25331 and then not (Is_Package_Or_Generic_Package (Val)
25332 and then Is_Library_Level_Entity (Val))
25334 Check_Restriction (No_Implementation_Identifiers, Post_Node);
25338 -- Do the style check
25341 and then not Suppress_Style_Checks (Val)
25342 and then not In_Instance
25344 if Nkind (N) = N_Identifier then
25346 elsif Nkind (N) = N_Expanded_Name then
25347 Nod := Selector_Name (N);
25352 -- A special situation arises for derived operations, where we want
25353 -- to do the check against the parent (since the Sloc of the derived
25354 -- operation points to the derived type declaration itself).
25357 while not Comes_From_Source (Val_Actual)
25358 and then Nkind (Val_Actual) in N_Entity
25359 and then (Ekind (Val_Actual) = E_Enumeration_Literal
25360 or else Is_Subprogram_Or_Generic_Subprogram (Val_Actual))
25361 and then Present (Alias (Val_Actual))
25363 Val_Actual := Alias (Val_Actual);
25366 -- Renaming declarations for generic actuals do not come from source,
25367 -- and have a different name from that of the entity they rename, so
25368 -- there is no style check to perform here.
25370 if Chars (Nod) = Chars (Val_Actual) then
25371 Style.Check_Identifier (Nod, Val_Actual);
25375 Set_Entity (N, Val);
25376 end Set_Entity_With_Checks;
25378 ------------------------------
25379 -- Set_Invalid_Scalar_Value --
25380 ------------------------------
25382 procedure Set_Invalid_Scalar_Value
25383 (Scal_Typ : Float_Scalar_Id;
25386 Slot : Ureal renames Invalid_Floats (Scal_Typ);
25389 -- Detect an attempt to set a different value for the same scalar type
25391 pragma Assert (Slot = No_Ureal);
25393 end Set_Invalid_Scalar_Value;
25395 ------------------------------
25396 -- Set_Invalid_Scalar_Value --
25397 ------------------------------
25399 procedure Set_Invalid_Scalar_Value
25400 (Scal_Typ : Integer_Scalar_Id;
25403 Slot : Uint renames Invalid_Integers (Scal_Typ);
25406 -- Detect an attempt to set a different value for the same scalar type
25408 pragma Assert (Slot = No_Uint);
25410 end Set_Invalid_Scalar_Value;
25412 ------------------------
25413 -- Set_Name_Entity_Id --
25414 ------------------------
25416 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
25418 Set_Name_Table_Int (Id, Int (Val));
25419 end Set_Name_Entity_Id;
25421 ---------------------
25422 -- Set_Next_Actual --
25423 ---------------------
25425 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
25427 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
25428 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
25430 end Set_Next_Actual;
25432 ----------------------------------
25433 -- Set_Optimize_Alignment_Flags --
25434 ----------------------------------
25436 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
25438 if Optimize_Alignment = 'S' then
25439 Set_Optimize_Alignment_Space (E);
25440 elsif Optimize_Alignment = 'T' then
25441 Set_Optimize_Alignment_Time (E);
25443 end Set_Optimize_Alignment_Flags;
25445 -----------------------
25446 -- Set_Public_Status --
25447 -----------------------
25449 procedure Set_Public_Status (Id : Entity_Id) is
25450 S : constant Entity_Id := Current_Scope;
25452 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
25453 -- Determines if E is defined within handled statement sequence or
25454 -- an if statement, returns True if so, False otherwise.
25456 ----------------------
25457 -- Within_HSS_Or_If --
25458 ----------------------
25460 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
25463 N := Declaration_Node (E);
25470 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
25476 end Within_HSS_Or_If;
25478 -- Start of processing for Set_Public_Status
25481 -- Everything in the scope of Standard is public
25483 if S = Standard_Standard then
25484 Set_Is_Public (Id);
25486 -- Entity is definitely not public if enclosing scope is not public
25488 elsif not Is_Public (S) then
25491 -- An object or function declaration that occurs in a handled sequence
25492 -- of statements or within an if statement is the declaration for a
25493 -- temporary object or local subprogram generated by the expander. It
25494 -- never needs to be made public and furthermore, making it public can
25495 -- cause back end problems.
25497 elsif Nkind_In (Parent (Id), N_Object_Declaration,
25498 N_Function_Specification)
25499 and then Within_HSS_Or_If (Id)
25503 -- Entities in public packages or records are public
25505 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
25506 Set_Is_Public (Id);
25508 -- The bounds of an entry family declaration can generate object
25509 -- declarations that are visible to the back-end, e.g. in the
25510 -- the declaration of a composite type that contains tasks.
25512 elsif Is_Concurrent_Type (S)
25513 and then not Has_Completion (S)
25514 and then Nkind (Parent (Id)) = N_Object_Declaration
25516 Set_Is_Public (Id);
25518 end Set_Public_Status;
25520 -----------------------------
25521 -- Set_Referenced_Modified --
25522 -----------------------------
25524 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
25528 -- Deal with indexed or selected component where prefix is modified
25530 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
25531 Pref := Prefix (N);
25533 -- If prefix is access type, then it is the designated object that is
25534 -- being modified, which means we have no entity to set the flag on.
25536 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
25539 -- Otherwise chase the prefix
25542 Set_Referenced_Modified (Pref, Out_Param);
25545 -- Otherwise see if we have an entity name (only other case to process)
25547 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
25548 Set_Referenced_As_LHS (Entity (N), not Out_Param);
25549 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
25551 end Set_Referenced_Modified;
25557 procedure Set_Rep_Info (T1 : Entity_Id; T2 : Entity_Id) is
25559 Set_Is_Atomic (T1, Is_Atomic (T2));
25560 Set_Is_Independent (T1, Is_Independent (T2));
25561 Set_Is_Volatile_Full_Access (T1, Is_Volatile_Full_Access (T2));
25563 if Is_Base_Type (T1) then
25564 Set_Is_Volatile (T1, Is_Volatile (T2));
25568 ----------------------------
25569 -- Set_Scope_Is_Transient --
25570 ----------------------------
25572 procedure Set_Scope_Is_Transient (V : Boolean := True) is
25574 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
25575 end Set_Scope_Is_Transient;
25577 -------------------
25578 -- Set_Size_Info --
25579 -------------------
25581 procedure Set_Size_Info (T1, T2 : Entity_Id) is
25583 -- We copy Esize, but not RM_Size, since in general RM_Size is
25584 -- subtype specific and does not get inherited by all subtypes.
25586 Set_Esize (T1, Esize (T2));
25587 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
25589 if Is_Discrete_Or_Fixed_Point_Type (T1)
25591 Is_Discrete_Or_Fixed_Point_Type (T2)
25593 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
25596 Set_Alignment (T1, Alignment (T2));
25599 ------------------------------
25600 -- Should_Ignore_Pragma_Par --
25601 ------------------------------
25603 function Should_Ignore_Pragma_Par (Prag_Name : Name_Id) return Boolean is
25604 pragma Assert (Compiler_State = Parsing);
25605 -- This one can't work during semantic analysis, because we don't have a
25606 -- correct Current_Source_File.
25608 Result : constant Boolean :=
25609 Get_Name_Table_Boolean3 (Prag_Name)
25610 and then not Is_Internal_File_Name
25611 (File_Name (Current_Source_File));
25614 end Should_Ignore_Pragma_Par;
25616 ------------------------------
25617 -- Should_Ignore_Pragma_Sem --
25618 ------------------------------
25620 function Should_Ignore_Pragma_Sem (N : Node_Id) return Boolean is
25621 pragma Assert (Compiler_State = Analyzing);
25622 Prag_Name : constant Name_Id := Pragma_Name (N);
25623 Result : constant Boolean :=
25624 Get_Name_Table_Boolean3 (Prag_Name)
25625 and then not In_Internal_Unit (N);
25629 end Should_Ignore_Pragma_Sem;
25631 --------------------
25632 -- Static_Boolean --
25633 --------------------
25635 function Static_Boolean (N : Node_Id) return Uint is
25637 Analyze_And_Resolve (N, Standard_Boolean);
25640 or else Error_Posted (N)
25641 or else Etype (N) = Any_Type
25646 if Is_OK_Static_Expression (N) then
25647 if not Raises_Constraint_Error (N) then
25648 return Expr_Value (N);
25653 elsif Etype (N) = Any_Type then
25657 Flag_Non_Static_Expr
25658 ("static boolean expression required here", N);
25661 end Static_Boolean;
25663 --------------------
25664 -- Static_Integer --
25665 --------------------
25667 function Static_Integer (N : Node_Id) return Uint is
25669 Analyze_And_Resolve (N, Any_Integer);
25672 or else Error_Posted (N)
25673 or else Etype (N) = Any_Type
25678 if Is_OK_Static_Expression (N) then
25679 if not Raises_Constraint_Error (N) then
25680 return Expr_Value (N);
25685 elsif Etype (N) = Any_Type then
25689 Flag_Non_Static_Expr
25690 ("static integer expression required here", N);
25693 end Static_Integer;
25695 --------------------------
25696 -- Statically_Different --
25697 --------------------------
25699 function Statically_Different (E1, E2 : Node_Id) return Boolean is
25700 R1 : constant Node_Id := Get_Referenced_Object (E1);
25701 R2 : constant Node_Id := Get_Referenced_Object (E2);
25703 return Is_Entity_Name (R1)
25704 and then Is_Entity_Name (R2)
25705 and then Entity (R1) /= Entity (R2)
25706 and then not Is_Formal (Entity (R1))
25707 and then not Is_Formal (Entity (R2));
25708 end Statically_Different;
25710 --------------------------------------
25711 -- Subject_To_Loop_Entry_Attributes --
25712 --------------------------------------
25714 function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
25720 -- The expansion mechanism transform a loop subject to at least one
25721 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
25722 -- the conditional part.
25724 if Nkind_In (Stmt, N_Block_Statement, N_If_Statement)
25725 and then Nkind (Original_Node (N)) = N_Loop_Statement
25727 Stmt := Original_Node (N);
25731 Nkind (Stmt) = N_Loop_Statement
25732 and then Present (Identifier (Stmt))
25733 and then Present (Entity (Identifier (Stmt)))
25734 and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
25735 end Subject_To_Loop_Entry_Attributes;
25737 -----------------------------
25738 -- Subprogram_Access_Level --
25739 -----------------------------
25741 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
25743 if Present (Alias (Subp)) then
25744 return Subprogram_Access_Level (Alias (Subp));
25746 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
25748 end Subprogram_Access_Level;
25750 ---------------------
25751 -- Subprogram_Name --
25752 ---------------------
25754 function Subprogram_Name (N : Node_Id) return String is
25755 Buf : Bounded_String;
25756 Ent : Node_Id := N;
25760 while Present (Ent) loop
25761 case Nkind (Ent) is
25762 when N_Subprogram_Body =>
25763 Ent := Defining_Unit_Name (Specification (Ent));
25766 when N_Subprogram_Declaration =>
25767 Nod := Corresponding_Body (Ent);
25769 if Present (Nod) then
25772 Ent := Defining_Unit_Name (Specification (Ent));
25777 when N_Subprogram_Instantiation
25779 | N_Package_Specification
25781 Ent := Defining_Unit_Name (Ent);
25784 when N_Protected_Type_Declaration =>
25785 Ent := Corresponding_Body (Ent);
25788 when N_Protected_Body
25791 Ent := Defining_Identifier (Ent);
25798 Ent := Parent (Ent);
25802 return "unknown subprogram:unknown file:0:0";
25805 -- If the subprogram is a child unit, use its simple name to start the
25806 -- construction of the fully qualified name.
25808 if Nkind (Ent) = N_Defining_Program_Unit_Name then
25809 Ent := Defining_Identifier (Ent);
25812 Append_Entity_Name (Buf, Ent);
25814 -- Append homonym number if needed
25816 if Nkind (N) in N_Entity and then Has_Homonym (N) then
25818 H : Entity_Id := Homonym (N);
25822 while Present (H) loop
25823 if Scope (H) = Scope (N) then
25837 -- Append source location of Ent to Buf so that the string will
25838 -- look like "subp:file:line:col".
25841 Loc : constant Source_Ptr := Sloc (Ent);
25844 Append (Buf, Reference_Name (Get_Source_File_Index (Loc)));
25846 Append (Buf, Nat (Get_Logical_Line_Number (Loc)));
25848 Append (Buf, Nat (Get_Column_Number (Loc)));
25852 end Subprogram_Name;
25854 -------------------------------
25855 -- Support_Atomic_Primitives --
25856 -------------------------------
25858 function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
25862 -- Verify the alignment of Typ is known
25864 if not Known_Alignment (Typ) then
25868 if Known_Static_Esize (Typ) then
25869 Size := UI_To_Int (Esize (Typ));
25871 -- If the Esize (Object_Size) is unknown at compile time, look at the
25872 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
25874 elsif Known_Static_RM_Size (Typ) then
25875 Size := UI_To_Int (RM_Size (Typ));
25877 -- Otherwise, the size is considered to be unknown.
25883 -- Check that the size of the component is 8, 16, 32, or 64 bits and
25884 -- that Typ is properly aligned.
25887 when 8 | 16 | 32 | 64 =>
25888 return Size = UI_To_Int (Alignment (Typ)) * 8;
25893 end Support_Atomic_Primitives;
25899 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
25901 if Debug_Flag_W then
25902 for J in 0 .. Scope_Stack.Last loop
25907 Write_Name (Chars (E));
25908 Write_Str (" from ");
25909 Write_Location (Sloc (N));
25914 -----------------------
25915 -- Transfer_Entities --
25916 -----------------------
25918 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
25919 procedure Set_Public_Status_Of (Id : Entity_Id);
25920 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
25921 -- Set_Public_Status. If successful and Id denotes a record type, set
25922 -- the Is_Public attribute of its fields.
25924 --------------------------
25925 -- Set_Public_Status_Of --
25926 --------------------------
25928 procedure Set_Public_Status_Of (Id : Entity_Id) is
25932 if not Is_Public (Id) then
25933 Set_Public_Status (Id);
25935 -- When the input entity is a public record type, ensure that all
25936 -- its internal fields are also exposed to the linker. The fields
25937 -- of a class-wide type are never made public.
25940 and then Is_Record_Type (Id)
25941 and then not Is_Class_Wide_Type (Id)
25943 Field := First_Entity (Id);
25944 while Present (Field) loop
25945 Set_Is_Public (Field);
25946 Next_Entity (Field);
25950 end Set_Public_Status_Of;
25954 Full_Id : Entity_Id;
25957 -- Start of processing for Transfer_Entities
25960 Id := First_Entity (From);
25962 if Present (Id) then
25964 -- Merge the entity chain of the source scope with that of the
25965 -- destination scope.
25967 if Present (Last_Entity (To)) then
25968 Link_Entities (Last_Entity (To), Id);
25970 Set_First_Entity (To, Id);
25973 Set_Last_Entity (To, Last_Entity (From));
25975 -- Inspect the entities of the source scope and update their Scope
25978 while Present (Id) loop
25979 Set_Scope (Id, To);
25980 Set_Public_Status_Of (Id);
25982 -- Handle an internally generated full view for a private type
25984 if Is_Private_Type (Id)
25985 and then Present (Full_View (Id))
25986 and then Is_Itype (Full_View (Id))
25988 Full_Id := Full_View (Id);
25990 Set_Scope (Full_Id, To);
25991 Set_Public_Status_Of (Full_Id);
25997 Set_First_Entity (From, Empty);
25998 Set_Last_Entity (From, Empty);
26000 end Transfer_Entities;
26002 ------------------------
26003 -- Traverse_More_Func --
26004 ------------------------
26006 function Traverse_More_Func (Node : Node_Id) return Traverse_Final_Result is
26008 Processing_Itype : Boolean := False;
26009 -- Set to True while traversing the nodes under an Itype, to prevent
26010 -- looping on Itype handling during that traversal.
26012 function Process_More (N : Node_Id) return Traverse_Result;
26013 -- Wrapper over the Process callback to handle parts of the AST that
26014 -- are not normally traversed as syntactic children.
26016 function Traverse_Rec (N : Node_Id) return Traverse_Final_Result;
26017 -- Main recursive traversal implemented as an instantiation of
26018 -- Traverse_Func over a modified Process callback.
26024 function Process_More (N : Node_Id) return Traverse_Result is
26026 procedure Traverse_More (N : Node_Id;
26027 Res : in out Traverse_Result);
26028 procedure Traverse_More (L : List_Id;
26029 Res : in out Traverse_Result);
26030 -- Traverse a node or list and update the traversal result to value
26031 -- Abandon when needed.
26033 -------------------
26034 -- Traverse_More --
26035 -------------------
26037 procedure Traverse_More (N : Node_Id;
26038 Res : in out Traverse_Result)
26041 -- Do not process any more nodes if Abandon was reached
26043 if Res = Abandon then
26047 if Traverse_Rec (N) = Abandon then
26052 procedure Traverse_More (L : List_Id;
26053 Res : in out Traverse_Result)
26055 N : Node_Id := First (L);
26058 -- Do not process any more nodes if Abandon was reached
26060 if Res = Abandon then
26064 while Present (N) loop
26065 Traverse_More (N, Res);
26073 Result : Traverse_Result;
26075 -- Start of processing for Process_More
26078 -- Initial callback to Process. Return immediately on Skip/Abandon.
26079 -- Otherwise update the value of Node for further processing of
26080 -- non-syntactic children.
26082 Result := Process (N);
26085 when OK => Node := N;
26086 when OK_Orig => Node := Original_Node (N);
26087 when Skip => return Skip;
26088 when Abandon => return Abandon;
26091 -- Process the relevant semantic children which are a logical part of
26092 -- the AST under this node before returning for the processing of
26093 -- syntactic children.
26095 -- Start with all non-syntactic lists of action nodes
26097 case Nkind (Node) is
26098 when N_Component_Association =>
26099 Traverse_More (Loop_Actions (Node), Result);
26101 when N_Elsif_Part =>
26102 Traverse_More (Condition_Actions (Node), Result);
26104 when N_Short_Circuit =>
26105 Traverse_More (Actions (Node), Result);
26107 when N_Case_Expression_Alternative =>
26108 Traverse_More (Actions (Node), Result);
26110 when N_Iterated_Component_Association =>
26111 Traverse_More (Loop_Actions (Node), Result);
26113 when N_Iteration_Scheme =>
26114 Traverse_More (Condition_Actions (Node), Result);
26116 when N_If_Expression =>
26117 Traverse_More (Then_Actions (Node), Result);
26118 Traverse_More (Else_Actions (Node), Result);
26120 -- Various nodes have a field Actions as a syntactic node,
26121 -- so it will be traversed in the regular syntactic traversal.
26123 when N_Compilation_Unit_Aux
26124 | N_Compound_Statement
26125 | N_Expression_With_Actions
26134 -- If Process_Itypes is True, process unattached nodes which come
26135 -- from Itypes. This only concerns currently ranges of scalar
26136 -- (possibly as index) types. This traversal is protected against
26137 -- looping with Processing_Itype.
26140 and then not Processing_Itype
26141 and then Nkind (Node) in N_Has_Etype
26142 and then Present (Etype (Node))
26143 and then Is_Itype (Etype (Node))
26146 Typ : constant Entity_Id := Etype (Node);
26148 Processing_Itype := True;
26150 case Ekind (Typ) is
26151 when Scalar_Kind =>
26152 Traverse_More (Scalar_Range (Typ), Result);
26156 Index : Node_Id := First_Index (Typ);
26159 while Present (Index) loop
26160 if Nkind (Index) in N_Has_Entity then
26161 Rng := Scalar_Range (Entity (Index));
26166 Traverse_More (Rng, Result);
26167 Next_Index (Index);
26174 Processing_Itype := False;
26181 -- Define Traverse_Rec as a renaming of the instantiation, as an
26182 -- instantiation cannot complete a previous spec.
26184 function Traverse_Recursive is new Traverse_Func (Process_More);
26185 function Traverse_Rec (N : Node_Id) return Traverse_Final_Result
26186 renames Traverse_Recursive;
26188 -- Start of processing for Traverse_More_Func
26191 return Traverse_Rec (Node);
26192 end Traverse_More_Func;
26194 ------------------------
26195 -- Traverse_More_Proc --
26196 ------------------------
26198 procedure Traverse_More_Proc (Node : Node_Id) is
26199 function Traverse is new Traverse_More_Func (Process, Process_Itypes);
26200 Discard : Traverse_Final_Result;
26201 pragma Warnings (Off, Discard);
26203 Discard := Traverse (Node);
26204 end Traverse_More_Proc;
26206 -----------------------
26207 -- Type_Access_Level --
26208 -----------------------
26210 function Type_Access_Level (Typ : Entity_Id) return Uint is
26214 Btyp := Base_Type (Typ);
26216 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
26217 -- simply use the level where the type is declared. This is true for
26218 -- stand-alone object declarations, and for anonymous access types
26219 -- associated with components the level is the same as that of the
26220 -- enclosing composite type. However, special treatment is needed for
26221 -- the cases of access parameters, return objects of an anonymous access
26222 -- type, and, in Ada 95, access discriminants of limited types.
26224 if Is_Access_Type (Btyp) then
26225 if Ekind (Btyp) = E_Anonymous_Access_Type then
26227 -- If the type is a nonlocal anonymous access type (such as for
26228 -- an access parameter) we treat it as being declared at the
26229 -- library level to ensure that names such as X.all'access don't
26230 -- fail static accessibility checks.
26232 if not Is_Local_Anonymous_Access (Typ) then
26233 return Scope_Depth (Standard_Standard);
26235 -- If this is a return object, the accessibility level is that of
26236 -- the result subtype of the enclosing function. The test here is
26237 -- little complicated, because we have to account for extended
26238 -- return statements that have been rewritten as blocks, in which
26239 -- case we have to find and the Is_Return_Object attribute of the
26240 -- itype's associated object. It would be nice to find a way to
26241 -- simplify this test, but it doesn't seem worthwhile to add a new
26242 -- flag just for purposes of this test. ???
26244 elsif Ekind (Scope (Btyp)) = E_Return_Statement
26247 and then Nkind (Associated_Node_For_Itype (Btyp)) =
26248 N_Object_Declaration
26249 and then Is_Return_Object
26250 (Defining_Identifier
26251 (Associated_Node_For_Itype (Btyp))))
26257 Scop := Scope (Scope (Btyp));
26258 while Present (Scop) loop
26259 exit when Ekind (Scop) = E_Function;
26260 Scop := Scope (Scop);
26263 -- Treat the return object's type as having the level of the
26264 -- function's result subtype (as per RM05-6.5(5.3/2)).
26266 return Type_Access_Level (Etype (Scop));
26271 Btyp := Root_Type (Btyp);
26273 -- The accessibility level of anonymous access types associated with
26274 -- discriminants is that of the current instance of the type, and
26275 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
26277 -- AI-402: access discriminants have accessibility based on the
26278 -- object rather than the type in Ada 2005, so the above paragraph
26281 -- ??? Needs completion with rules from AI-416
26283 if Ada_Version <= Ada_95
26284 and then Ekind (Typ) = E_Anonymous_Access_Type
26285 and then Present (Associated_Node_For_Itype (Typ))
26286 and then Nkind (Associated_Node_For_Itype (Typ)) =
26287 N_Discriminant_Specification
26289 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
26293 -- Return library level for a generic formal type. This is done because
26294 -- RM(10.3.2) says that "The statically deeper relationship does not
26295 -- apply to ... a descendant of a generic formal type". Rather than
26296 -- checking at each point where a static accessibility check is
26297 -- performed to see if we are dealing with a formal type, this rule is
26298 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
26299 -- return extreme values for a formal type; Deepest_Type_Access_Level
26300 -- returns Int'Last. By calling the appropriate function from among the
26301 -- two, we ensure that the static accessibility check will pass if we
26302 -- happen to run into a formal type. More specifically, we should call
26303 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
26304 -- call occurs as part of a static accessibility check and the error
26305 -- case is the case where the type's level is too shallow (as opposed
26308 if Is_Generic_Type (Root_Type (Btyp)) then
26309 return Scope_Depth (Standard_Standard);
26312 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
26313 end Type_Access_Level;
26315 ------------------------------------
26316 -- Type_Without_Stream_Operation --
26317 ------------------------------------
26319 function Type_Without_Stream_Operation
26321 Op : TSS_Name_Type := TSS_Null) return Entity_Id
26323 BT : constant Entity_Id := Base_Type (T);
26324 Op_Missing : Boolean;
26327 if not Restriction_Active (No_Default_Stream_Attributes) then
26331 if Is_Elementary_Type (T) then
26332 if Op = TSS_Null then
26334 No (TSS (BT, TSS_Stream_Read))
26335 or else No (TSS (BT, TSS_Stream_Write));
26338 Op_Missing := No (TSS (BT, Op));
26347 elsif Is_Array_Type (T) then
26348 return Type_Without_Stream_Operation (Component_Type (T), Op);
26350 elsif Is_Record_Type (T) then
26356 Comp := First_Component (T);
26357 while Present (Comp) loop
26358 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
26360 if Present (C_Typ) then
26364 Next_Component (Comp);
26370 elsif Is_Private_Type (T) and then Present (Full_View (T)) then
26371 return Type_Without_Stream_Operation (Full_View (T), Op);
26375 end Type_Without_Stream_Operation;
26377 ---------------------
26378 -- Ultimate_Prefix --
26379 ---------------------
26381 function Ultimate_Prefix (N : Node_Id) return Node_Id is
26386 while Nkind_In (Pref, N_Explicit_Dereference,
26387 N_Indexed_Component,
26388 N_Selected_Component,
26391 Pref := Prefix (Pref);
26395 end Ultimate_Prefix;
26397 ----------------------------
26398 -- Unique_Defining_Entity --
26399 ----------------------------
26401 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
26403 return Unique_Entity (Defining_Entity (N));
26404 end Unique_Defining_Entity;
26406 -------------------
26407 -- Unique_Entity --
26408 -------------------
26410 function Unique_Entity (E : Entity_Id) return Entity_Id is
26411 U : Entity_Id := E;
26417 if Present (Full_View (E)) then
26418 U := Full_View (E);
26422 if Nkind (Parent (E)) = N_Entry_Body then
26424 Prot_Item : Entity_Id;
26425 Prot_Type : Entity_Id;
26428 if Ekind (E) = E_Entry then
26429 Prot_Type := Scope (E);
26431 -- Bodies of entry families are nested within an extra scope
26432 -- that contains an entry index declaration.
26435 Prot_Type := Scope (Scope (E));
26438 -- A protected type may be declared as a private type, in
26439 -- which case we need to get its full view.
26441 if Is_Private_Type (Prot_Type) then
26442 Prot_Type := Full_View (Prot_Type);
26445 -- Full view may not be present on error, in which case
26446 -- return E by default.
26448 if Present (Prot_Type) then
26449 pragma Assert (Ekind (Prot_Type) = E_Protected_Type);
26451 -- Traverse the entity list of the protected type and
26452 -- locate an entry declaration which matches the entry
26455 Prot_Item := First_Entity (Prot_Type);
26456 while Present (Prot_Item) loop
26457 if Ekind (Prot_Item) in Entry_Kind
26458 and then Corresponding_Body (Parent (Prot_Item)) = E
26464 Next_Entity (Prot_Item);
26470 when Formal_Kind =>
26471 if Present (Spec_Entity (E)) then
26472 U := Spec_Entity (E);
26475 when E_Package_Body =>
26478 if Nkind (P) = N_Defining_Program_Unit_Name then
26482 if Nkind (P) = N_Package_Body
26483 and then Present (Corresponding_Spec (P))
26485 U := Corresponding_Spec (P);
26487 elsif Nkind (P) = N_Package_Body_Stub
26488 and then Present (Corresponding_Spec_Of_Stub (P))
26490 U := Corresponding_Spec_Of_Stub (P);
26493 when E_Protected_Body =>
26496 if Nkind (P) = N_Protected_Body
26497 and then Present (Corresponding_Spec (P))
26499 U := Corresponding_Spec (P);
26501 elsif Nkind (P) = N_Protected_Body_Stub
26502 and then Present (Corresponding_Spec_Of_Stub (P))
26504 U := Corresponding_Spec_Of_Stub (P);
26506 if Is_Single_Protected_Object (U) then
26511 if Is_Private_Type (U) then
26512 U := Full_View (U);
26515 when E_Subprogram_Body =>
26518 if Nkind (P) = N_Defining_Program_Unit_Name then
26524 if Nkind (P) = N_Subprogram_Body
26525 and then Present (Corresponding_Spec (P))
26527 U := Corresponding_Spec (P);
26529 elsif Nkind (P) = N_Subprogram_Body_Stub
26530 and then Present (Corresponding_Spec_Of_Stub (P))
26532 U := Corresponding_Spec_Of_Stub (P);
26534 elsif Nkind (P) = N_Subprogram_Renaming_Declaration then
26535 U := Corresponding_Spec (P);
26538 when E_Task_Body =>
26541 if Nkind (P) = N_Task_Body
26542 and then Present (Corresponding_Spec (P))
26544 U := Corresponding_Spec (P);
26546 elsif Nkind (P) = N_Task_Body_Stub
26547 and then Present (Corresponding_Spec_Of_Stub (P))
26549 U := Corresponding_Spec_Of_Stub (P);
26551 if Is_Single_Task_Object (U) then
26556 if Is_Private_Type (U) then
26557 U := Full_View (U);
26561 if Present (Full_View (E)) then
26562 U := Full_View (E);
26576 function Unique_Name (E : Entity_Id) return String is
26578 -- Local subprograms
26580 function Add_Homonym_Suffix (E : Entity_Id) return String;
26582 function This_Name return String;
26584 ------------------------
26585 -- Add_Homonym_Suffix --
26586 ------------------------
26588 function Add_Homonym_Suffix (E : Entity_Id) return String is
26590 -- Names in E_Subprogram_Body or E_Package_Body entities are not
26591 -- reliable, as they may not include the overloading suffix.
26592 -- Instead, when looking for the name of E or one of its enclosing
26593 -- scope, we get the name of the corresponding Unique_Entity.
26595 U : constant Entity_Id := Unique_Entity (E);
26596 Nam : constant String := Get_Name_String (Chars (U));
26599 -- If E has homonyms but is not fully qualified, as done in
26600 -- GNATprove mode, append the homonym number on the fly. Strip the
26601 -- leading space character in the image of natural numbers. Also do
26602 -- not print the homonym value of 1.
26604 if Has_Homonym (U) then
26606 N : constant Pos := Homonym_Number (U);
26607 S : constant String := N'Img;
26610 return Nam & "__" & S (2 .. S'Last);
26616 end Add_Homonym_Suffix;
26622 function This_Name return String is
26624 return Add_Homonym_Suffix (E);
26629 U : constant Entity_Id := Unique_Entity (E);
26631 -- Start of processing for Unique_Name
26634 if E = Standard_Standard
26635 or else Has_Fully_Qualified_Name (E)
26639 elsif Ekind (E) = E_Enumeration_Literal then
26640 return Unique_Name (Etype (E)) & "__" & This_Name;
26644 S : constant Entity_Id := Scope (U);
26645 pragma Assert (Present (S));
26648 -- Prefix names of predefined types with standard__, but leave
26649 -- names of user-defined packages and subprograms without prefix
26650 -- (even if technically they are nested in the Standard package).
26652 if S = Standard_Standard then
26653 if Ekind (U) = E_Package or else Is_Subprogram (U) then
26656 return Unique_Name (S) & "__" & This_Name;
26659 -- For intances of generic subprograms use the name of the related
26660 -- instance and skip the scope of its wrapper package.
26662 elsif Is_Wrapper_Package (S) then
26663 pragma Assert (Scope (S) = Scope (Related_Instance (S)));
26664 -- Wrapper package and the instantiation are in the same scope
26667 Related_Name : constant String :=
26668 Add_Homonym_Suffix (Related_Instance (S));
26669 Enclosing_Name : constant String :=
26670 Unique_Name (Scope (S)) & "__" & Related_Name;
26673 if Is_Subprogram (U)
26674 and then not Is_Generic_Actual_Subprogram (U)
26676 return Enclosing_Name;
26678 return Enclosing_Name & "__" & This_Name;
26682 elsif Is_Child_Unit (U) then
26683 return Child_Prefix & Unique_Name (S) & "__" & This_Name;
26685 return Unique_Name (S) & "__" & This_Name;
26691 ---------------------
26692 -- Unit_Is_Visible --
26693 ---------------------
26695 function Unit_Is_Visible (U : Entity_Id) return Boolean is
26696 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
26697 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
26699 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
26700 -- For a child unit, check whether unit appears in a with_clause
26703 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
26704 -- Scan the context clause of one compilation unit looking for a
26705 -- with_clause for the unit in question.
26707 ----------------------------
26708 -- Unit_In_Parent_Context --
26709 ----------------------------
26711 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
26713 if Unit_In_Context (Par_Unit) then
26716 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
26717 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
26722 end Unit_In_Parent_Context;
26724 ---------------------
26725 -- Unit_In_Context --
26726 ---------------------
26728 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
26732 Clause := First (Context_Items (Comp_Unit));
26733 while Present (Clause) loop
26734 if Nkind (Clause) = N_With_Clause then
26735 if Library_Unit (Clause) = U then
26738 -- The with_clause may denote a renaming of the unit we are
26739 -- looking for, eg. Text_IO which renames Ada.Text_IO.
26742 Renamed_Entity (Entity (Name (Clause))) =
26743 Defining_Entity (Unit (U))
26753 end Unit_In_Context;
26755 -- Start of processing for Unit_Is_Visible
26758 -- The currrent unit is directly visible
26763 elsif Unit_In_Context (Curr) then
26766 -- If the current unit is a body, check the context of the spec
26768 elsif Nkind (Unit (Curr)) = N_Package_Body
26770 (Nkind (Unit (Curr)) = N_Subprogram_Body
26771 and then not Acts_As_Spec (Unit (Curr)))
26773 if Unit_In_Context (Library_Unit (Curr)) then
26778 -- If the spec is a child unit, examine the parents
26780 if Is_Child_Unit (Curr_Entity) then
26781 if Nkind (Unit (Curr)) in N_Unit_Body then
26783 Unit_In_Parent_Context
26784 (Parent_Spec (Unit (Library_Unit (Curr))));
26786 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
26792 end Unit_Is_Visible;
26794 ------------------------------
26795 -- Universal_Interpretation --
26796 ------------------------------
26798 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
26799 Index : Interp_Index;
26803 -- The argument may be a formal parameter of an operator or subprogram
26804 -- with multiple interpretations, or else an expression for an actual.
26806 if Nkind (Opnd) = N_Defining_Identifier
26807 or else not Is_Overloaded (Opnd)
26809 if Etype (Opnd) = Universal_Integer
26810 or else Etype (Opnd) = Universal_Real
26812 return Etype (Opnd);
26818 Get_First_Interp (Opnd, Index, It);
26819 while Present (It.Typ) loop
26820 if It.Typ = Universal_Integer
26821 or else It.Typ = Universal_Real
26826 Get_Next_Interp (Index, It);
26831 end Universal_Interpretation;
26837 function Unqualify (Expr : Node_Id) return Node_Id is
26839 -- Recurse to handle unlikely case of multiple levels of qualification
26841 if Nkind (Expr) = N_Qualified_Expression then
26842 return Unqualify (Expression (Expr));
26844 -- Normal case, not a qualified expression
26855 function Unqual_Conv (Expr : Node_Id) return Node_Id is
26857 -- Recurse to handle unlikely case of multiple levels of qualification
26858 -- and/or conversion.
26860 if Nkind_In (Expr, N_Qualified_Expression,
26862 N_Unchecked_Type_Conversion)
26864 return Unqual_Conv (Expression (Expr));
26866 -- Normal case, not a qualified expression
26873 --------------------
26874 -- Validated_View --
26875 --------------------
26877 function Validated_View (Typ : Entity_Id) return Entity_Id is
26878 Continue : Boolean;
26879 Val_Typ : Entity_Id;
26883 Val_Typ := Base_Type (Typ);
26885 -- Obtain the full view of the input type by stripping away concurrency,
26886 -- derivations, and privacy.
26888 while Continue loop
26891 if Is_Concurrent_Type (Val_Typ) then
26892 if Present (Corresponding_Record_Type (Val_Typ)) then
26894 Val_Typ := Corresponding_Record_Type (Val_Typ);
26897 elsif Is_Derived_Type (Val_Typ) then
26899 Val_Typ := Etype (Val_Typ);
26901 elsif Is_Private_Type (Val_Typ) then
26902 if Present (Underlying_Full_View (Val_Typ)) then
26904 Val_Typ := Underlying_Full_View (Val_Typ);
26906 elsif Present (Full_View (Val_Typ)) then
26908 Val_Typ := Full_View (Val_Typ);
26914 end Validated_View;
26916 -----------------------
26917 -- Visible_Ancestors --
26918 -----------------------
26920 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
26926 pragma Assert (Is_Record_Type (Typ) and then Is_Tagged_Type (Typ));
26928 -- Collect all the parents and progenitors of Typ. If the full-view of
26929 -- private parents and progenitors is available then it is used to
26930 -- generate the list of visible ancestors; otherwise their partial
26931 -- view is added to the resulting list.
26936 Use_Full_View => True);
26940 Ifaces_List => List_2,
26941 Exclude_Parents => True,
26942 Use_Full_View => True);
26944 -- Join the two lists. Avoid duplications because an interface may
26945 -- simultaneously be parent and progenitor of a type.
26947 Elmt := First_Elmt (List_2);
26948 while Present (Elmt) loop
26949 Append_Unique_Elmt (Node (Elmt), List_1);
26954 end Visible_Ancestors;
26956 ----------------------
26957 -- Within_Init_Proc --
26958 ----------------------
26960 function Within_Init_Proc return Boolean is
26964 S := Current_Scope;
26965 while not Is_Overloadable (S) loop
26966 if S = Standard_Standard then
26973 return Is_Init_Proc (S);
26974 end Within_Init_Proc;
26976 ---------------------------
26977 -- Within_Protected_Type --
26978 ---------------------------
26980 function Within_Protected_Type (E : Entity_Id) return Boolean is
26981 Scop : Entity_Id := Scope (E);
26984 while Present (Scop) loop
26985 if Ekind (Scop) = E_Protected_Type then
26989 Scop := Scope (Scop);
26993 end Within_Protected_Type;
26999 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
27001 return Scope_Within_Or_Same (Scope (E), S);
27004 ----------------------------
27005 -- Within_Subprogram_Call --
27006 ----------------------------
27008 function Within_Subprogram_Call (N : Node_Id) return Boolean is
27012 -- Climb the parent chain looking for a function or procedure call
27015 while Present (Par) loop
27016 if Nkind_In (Par, N_Entry_Call_Statement,
27018 N_Procedure_Call_Statement)
27022 -- Prevent the search from going too far
27024 elsif Is_Body_Or_Package_Declaration (Par) then
27028 Par := Parent (Par);
27032 end Within_Subprogram_Call;
27038 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
27039 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
27040 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
27042 Matching_Field : Entity_Id;
27043 -- Entity to give a more precise suggestion on how to write a one-
27044 -- element positional aggregate.
27046 function Has_One_Matching_Field return Boolean;
27047 -- Determines if Expec_Type is a record type with a single component or
27048 -- discriminant whose type matches the found type or is one dimensional
27049 -- array whose component type matches the found type. In the case of
27050 -- one discriminant, we ignore the variant parts. That's not accurate,
27051 -- but good enough for the warning.
27053 ----------------------------
27054 -- Has_One_Matching_Field --
27055 ----------------------------
27057 function Has_One_Matching_Field return Boolean is
27061 Matching_Field := Empty;
27063 if Is_Array_Type (Expec_Type)
27064 and then Number_Dimensions (Expec_Type) = 1
27065 and then Covers (Etype (Component_Type (Expec_Type)), Found_Type)
27067 -- Use type name if available. This excludes multidimensional
27068 -- arrays and anonymous arrays.
27070 if Comes_From_Source (Expec_Type) then
27071 Matching_Field := Expec_Type;
27073 -- For an assignment, use name of target
27075 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
27076 and then Is_Entity_Name (Name (Parent (Expr)))
27078 Matching_Field := Entity (Name (Parent (Expr)));
27083 elsif not Is_Record_Type (Expec_Type) then
27087 E := First_Entity (Expec_Type);
27092 elsif not Ekind_In (E, E_Discriminant, E_Component)
27093 or else Nam_In (Chars (E), Name_uTag, Name_uParent)
27102 if not Covers (Etype (E), Found_Type) then
27105 elsif Present (Next_Entity (E))
27106 and then (Ekind (E) = E_Component
27107 or else Ekind (Next_Entity (E)) = E_Discriminant)
27112 Matching_Field := E;
27116 end Has_One_Matching_Field;
27118 -- Start of processing for Wrong_Type
27121 -- Don't output message if either type is Any_Type, or if a message
27122 -- has already been posted for this node. We need to do the latter
27123 -- check explicitly (it is ordinarily done in Errout), because we
27124 -- are using ! to force the output of the error messages.
27126 if Expec_Type = Any_Type
27127 or else Found_Type = Any_Type
27128 or else Error_Posted (Expr)
27132 -- If one of the types is a Taft-Amendment type and the other it its
27133 -- completion, it must be an illegal use of a TAT in the spec, for
27134 -- which an error was already emitted. Avoid cascaded errors.
27136 elsif Is_Incomplete_Type (Expec_Type)
27137 and then Has_Completion_In_Body (Expec_Type)
27138 and then Full_View (Expec_Type) = Etype (Expr)
27142 elsif Is_Incomplete_Type (Etype (Expr))
27143 and then Has_Completion_In_Body (Etype (Expr))
27144 and then Full_View (Etype (Expr)) = Expec_Type
27148 -- In an instance, there is an ongoing problem with completion of
27149 -- types derived from private types. Their structure is what Gigi
27150 -- expects, but the Etype is the parent type rather than the
27151 -- derived private type itself. Do not flag error in this case. The
27152 -- private completion is an entity without a parent, like an Itype.
27153 -- Similarly, full and partial views may be incorrect in the instance.
27154 -- There is no simple way to insure that it is consistent ???
27156 -- A similar view discrepancy can happen in an inlined body, for the
27157 -- same reason: inserted body may be outside of the original package
27158 -- and only partial views are visible at the point of insertion.
27160 -- If In_Generic_Actual (Expr) is True then we cannot assume that
27161 -- the successful semantic analysis of the generic guarantees anything
27162 -- useful about type checking of this instance, so we ignore
27163 -- In_Instance in that case. There may be cases where this is not
27164 -- right (the symptom would probably be rejecting something
27165 -- that ought to be accepted) but we don't currently have any
27166 -- concrete examples of this.
27168 elsif (In_Instance and then not In_Generic_Actual (Expr))
27169 or else In_Inlined_Body
27171 if Etype (Etype (Expr)) = Etype (Expected_Type)
27173 (Has_Private_Declaration (Expected_Type)
27174 or else Has_Private_Declaration (Etype (Expr)))
27175 and then No (Parent (Expected_Type))
27179 elsif Nkind (Parent (Expr)) = N_Qualified_Expression
27180 and then Entity (Subtype_Mark (Parent (Expr))) = Expected_Type
27184 elsif Is_Private_Type (Expected_Type)
27185 and then Present (Full_View (Expected_Type))
27186 and then Covers (Full_View (Expected_Type), Etype (Expr))
27190 -- Conversely, type of expression may be the private one
27192 elsif Is_Private_Type (Base_Type (Etype (Expr)))
27193 and then Full_View (Base_Type (Etype (Expr))) = Expected_Type
27199 -- An interesting special check. If the expression is parenthesized
27200 -- and its type corresponds to the type of the sole component of the
27201 -- expected record type, or to the component type of the expected one
27202 -- dimensional array type, then assume we have a bad aggregate attempt.
27204 if Nkind (Expr) in N_Subexpr
27205 and then Paren_Count (Expr) /= 0
27206 and then Has_One_Matching_Field
27208 Error_Msg_N ("positional aggregate cannot have one component", Expr);
27210 if Present (Matching_Field) then
27211 if Is_Array_Type (Expec_Type) then
27213 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
27216 ("\write instead `& ='> ...`", Expr, Matching_Field);
27220 -- Another special check, if we are looking for a pool-specific access
27221 -- type and we found an E_Access_Attribute_Type, then we have the case
27222 -- of an Access attribute being used in a context which needs a pool-
27223 -- specific type, which is never allowed. The one extra check we make
27224 -- is that the expected designated type covers the Found_Type.
27226 elsif Is_Access_Type (Expec_Type)
27227 and then Ekind (Found_Type) = E_Access_Attribute_Type
27228 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
27229 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
27231 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
27233 Error_Msg_N -- CODEFIX
27234 ("result must be general access type!", Expr);
27235 Error_Msg_NE -- CODEFIX
27236 ("add ALL to }!", Expr, Expec_Type);
27238 -- Another special check, if the expected type is an integer type,
27239 -- but the expression is of type System.Address, and the parent is
27240 -- an addition or subtraction operation whose left operand is the
27241 -- expression in question and whose right operand is of an integral
27242 -- type, then this is an attempt at address arithmetic, so give
27243 -- appropriate message.
27245 elsif Is_Integer_Type (Expec_Type)
27246 and then Is_RTE (Found_Type, RE_Address)
27247 and then Nkind_In (Parent (Expr), N_Op_Add, N_Op_Subtract)
27248 and then Expr = Left_Opnd (Parent (Expr))
27249 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
27252 ("address arithmetic not predefined in package System",
27255 ("\possible missing with/use of System.Storage_Elements",
27259 -- If the expected type is an anonymous access type, as for access
27260 -- parameters and discriminants, the error is on the designated types.
27262 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
27263 if Comes_From_Source (Expec_Type) then
27264 Error_Msg_NE ("expected}!", Expr, Expec_Type);
27267 ("expected an access type with designated}",
27268 Expr, Designated_Type (Expec_Type));
27271 if Is_Access_Type (Found_Type)
27272 and then not Comes_From_Source (Found_Type)
27275 ("\\found an access type with designated}!",
27276 Expr, Designated_Type (Found_Type));
27278 if From_Limited_With (Found_Type) then
27279 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
27280 Error_Msg_Qual_Level := 99;
27281 Error_Msg_NE -- CODEFIX
27282 ("\\missing `WITH &;", Expr, Scope (Found_Type));
27283 Error_Msg_Qual_Level := 0;
27285 Error_Msg_NE ("found}!", Expr, Found_Type);
27289 -- Normal case of one type found, some other type expected
27292 -- If the names of the two types are the same, see if some number
27293 -- of levels of qualification will help. Don't try more than three
27294 -- levels, and if we get to standard, it's no use (and probably
27295 -- represents an error in the compiler) Also do not bother with
27296 -- internal scope names.
27299 Expec_Scope : Entity_Id;
27300 Found_Scope : Entity_Id;
27303 Expec_Scope := Expec_Type;
27304 Found_Scope := Found_Type;
27306 for Levels in Nat range 0 .. 3 loop
27307 if Chars (Expec_Scope) /= Chars (Found_Scope) then
27308 Error_Msg_Qual_Level := Levels;
27312 Expec_Scope := Scope (Expec_Scope);
27313 Found_Scope := Scope (Found_Scope);
27315 exit when Expec_Scope = Standard_Standard
27316 or else Found_Scope = Standard_Standard
27317 or else not Comes_From_Source (Expec_Scope)
27318 or else not Comes_From_Source (Found_Scope);
27322 if Is_Record_Type (Expec_Type)
27323 and then Present (Corresponding_Remote_Type (Expec_Type))
27325 Error_Msg_NE ("expected}!", Expr,
27326 Corresponding_Remote_Type (Expec_Type));
27328 Error_Msg_NE ("expected}!", Expr, Expec_Type);
27331 if Is_Entity_Name (Expr)
27332 and then Is_Package_Or_Generic_Package (Entity (Expr))
27334 Error_Msg_N ("\\found package name!", Expr);
27336 elsif Is_Entity_Name (Expr)
27337 and then Ekind_In (Entity (Expr), E_Procedure, E_Generic_Procedure)
27339 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
27341 ("found procedure name, possibly missing Access attribute!",
27345 ("\\found procedure name instead of function!", Expr);
27348 elsif Nkind (Expr) = N_Function_Call
27349 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
27350 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
27351 and then No (Parameter_Associations (Expr))
27354 ("found function name, possibly missing Access attribute!",
27357 -- Catch common error: a prefix or infix operator which is not
27358 -- directly visible because the type isn't.
27360 elsif Nkind (Expr) in N_Op
27361 and then Is_Overloaded (Expr)
27362 and then not Is_Immediately_Visible (Expec_Type)
27363 and then not Is_Potentially_Use_Visible (Expec_Type)
27364 and then not In_Use (Expec_Type)
27365 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
27368 ("operator of the type is not directly visible!", Expr);
27370 elsif Ekind (Found_Type) = E_Void
27371 and then Present (Parent (Found_Type))
27372 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
27374 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
27377 Error_Msg_NE ("\\found}!", Expr, Found_Type);
27380 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
27381 -- of the same modular type, and (M1 and M2) = 0 was intended.
27383 if Expec_Type = Standard_Boolean
27384 and then Is_Modular_Integer_Type (Found_Type)
27385 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
27386 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
27389 Op : constant Node_Id := Right_Opnd (Parent (Expr));
27390 L : constant Node_Id := Left_Opnd (Op);
27391 R : constant Node_Id := Right_Opnd (Op);
27394 -- The case for the message is when the left operand of the
27395 -- comparison is the same modular type, or when it is an
27396 -- integer literal (or other universal integer expression),
27397 -- which would have been typed as the modular type if the
27398 -- parens had been there.
27400 if (Etype (L) = Found_Type
27402 Etype (L) = Universal_Integer)
27403 and then Is_Integer_Type (Etype (R))
27406 ("\\possible missing parens for modular operation", Expr);
27411 -- Reset error message qualification indication
27413 Error_Msg_Qual_Level := 0;
27417 --------------------------------
27418 -- Yields_Synchronized_Object --
27419 --------------------------------
27421 function Yields_Synchronized_Object (Typ : Entity_Id) return Boolean is
27422 Has_Sync_Comp : Boolean := False;
27426 -- An array type yields a synchronized object if its component type
27427 -- yields a synchronized object.
27429 if Is_Array_Type (Typ) then
27430 return Yields_Synchronized_Object (Component_Type (Typ));
27432 -- A descendant of type Ada.Synchronous_Task_Control.Suspension_Object
27433 -- yields a synchronized object by default.
27435 elsif Is_Descendant_Of_Suspension_Object (Typ) then
27438 -- A protected type yields a synchronized object by default
27440 elsif Is_Protected_Type (Typ) then
27443 -- A record type or type extension yields a synchronized object when its
27444 -- discriminants (if any) lack default values and all components are of
27445 -- a type that yields a synchronized object.
27447 elsif Is_Record_Type (Typ) then
27449 -- Inspect all entities defined in the scope of the type, looking for
27450 -- components of a type that does not yield a synchronized object or
27451 -- for discriminants with default values.
27453 Id := First_Entity (Typ);
27454 while Present (Id) loop
27455 if Comes_From_Source (Id) then
27456 if Ekind (Id) = E_Component then
27457 if Yields_Synchronized_Object (Etype (Id)) then
27458 Has_Sync_Comp := True;
27460 -- The component does not yield a synchronized object
27466 elsif Ekind (Id) = E_Discriminant
27467 and then Present (Expression (Parent (Id)))
27476 -- Ensure that the parent type of a type extension yields a
27477 -- synchronized object.
27479 if Etype (Typ) /= Typ
27480 and then not Is_Private_Type (Etype (Typ))
27481 and then not Yields_Synchronized_Object (Etype (Typ))
27486 -- If we get here, then all discriminants lack default values and all
27487 -- components are of a type that yields a synchronized object.
27489 return Has_Sync_Comp;
27491 -- A synchronized interface type yields a synchronized object by default
27493 elsif Is_Synchronized_Interface (Typ) then
27496 -- A task type yields a synchronized object by default
27498 elsif Is_Task_Type (Typ) then
27501 -- A private type yields a synchronized object if its underlying type
27504 elsif Is_Private_Type (Typ)
27505 and then Present (Underlying_Type (Typ))
27507 return Yields_Synchronized_Object (Underlying_Type (Typ));
27509 -- Otherwise the type does not yield a synchronized object
27514 end Yields_Synchronized_Object;
27516 ---------------------------
27517 -- Yields_Universal_Type --
27518 ---------------------------
27520 function Yields_Universal_Type (N : Node_Id) return Boolean is
27522 -- Integer and real literals are of a universal type
27524 if Nkind_In (N, N_Integer_Literal, N_Real_Literal) then
27527 -- The values of certain attributes are of a universal type
27529 elsif Nkind (N) = N_Attribute_Reference then
27531 Universal_Type_Attribute (Get_Attribute_Id (Attribute_Name (N)));
27533 -- ??? There are possibly other cases to consider
27538 end Yields_Universal_Type;
27540 package body Interval_Lists is
27542 function In_Interval
27543 (Value : Uint; Interval : Discrete_Interval) return Boolean;
27544 -- Does the given value lie within the given interval?
27549 function In_Interval
27550 (Value : Uint; Interval : Discrete_Interval) return Boolean is
27552 return Value >= Interval.Low and then Value <= Interval.High;
27555 procedure Check_Consistency (Intervals : Discrete_Interval_List);
27556 -- Check that list is sorted, lacks null intervals, and has gaps
27557 -- between intervals.
27559 ------------------------
27560 -- Check_Consistency --
27561 ------------------------
27562 procedure Check_Consistency (Intervals : Discrete_Interval_List) is
27564 if Serious_Errors_Detected > 0 then
27568 -- low bound is 1 and high bound equals length
27569 pragma Assert (Intervals'First = 1 and Intervals'Last >= 0);
27570 for Idx in Intervals'Range loop
27571 -- each interval is non-null
27572 pragma Assert (Intervals (Idx).Low <= Intervals (Idx).High);
27573 if Idx /= Intervals'First then
27574 -- intervals are sorted with non-empty gaps between them
27576 (Intervals (Idx - 1).High < (Intervals (Idx).Low - 1));
27580 end Check_Consistency;
27582 function Chosen_Interval (Choice : Node_Id) return Discrete_Interval;
27583 -- Given an element of a Discrete_Choices list, a
27584 -- Static_Discrete_Predicate list, or an Others_Discrete_Choices
27585 -- list (but not an N_Others_Choice node) return the corresponding
27586 -- interval. If an element that does not represent a single
27587 -- contiguous interval due to a static predicate (or which
27588 -- represents a single contiguous interval whose bounds depend on
27589 -- a static predicate) is encountered, then that is an error on the
27590 -- part of whoever built the list in question.
27592 ---------------------
27593 -- Chosen_Interval --
27594 ---------------------
27595 function Chosen_Interval (Choice : Node_Id) return Discrete_Interval is
27597 case Nkind (Choice) is
27599 return (Low => Expr_Value (Low_Bound (Choice)),
27600 High => Expr_Value (High_Bound (Choice)));
27602 when N_Subtype_Indication =>
27604 Range_Exp : constant Node_Id
27605 := Range_Expression (Constraint (Choice));
27607 return (Low => Expr_Value (Low_Bound (Range_Exp)),
27608 High => Expr_Value (High_Bound (Range_Exp)));
27611 when N_Others_Choice =>
27612 raise Program_Error;
27615 if Is_Entity_Name (Choice) and then Is_Type (Entity (Choice))
27618 (Low => Expr_Value (Type_Low_Bound (Entity (Choice))),
27619 High => Expr_Value (Type_High_Bound (Entity (Choice))));
27622 return (Low | High => Expr_Value (Choice));
27625 end Chosen_Interval;
27627 --------------------
27628 -- Type_Intervals --
27629 --------------------
27630 function Type_Intervals
27631 (Typ : Entity_Id) return Discrete_Interval_List
27634 if Has_Static_Predicate (Typ) then
27636 -- No sorting or merging needed
27637 SDP_List : constant List_Id := Static_Discrete_Predicate (Typ);
27638 Range_Or_Expr : Node_Id := First (SDP_List);
27640 Discrete_Interval_List (1 .. List_Length (SDP_List));
27642 for Idx in Result'Range loop
27643 Result (Idx) := Chosen_Interval (Range_Or_Expr);
27644 Range_Or_Expr := Next (Range_Or_Expr);
27646 pragma Assert (not Present (Range_Or_Expr));
27647 Check_Consistency (Result);
27652 Low : constant Uint := Expr_Value (Type_Low_Bound (Typ));
27653 High : constant Uint := Expr_Value (Type_High_Bound (Typ));
27657 Null_Array : Discrete_Interval_List (1 .. 0);
27662 return (1 => (Low => Low, High => High));
27666 end Type_Intervals;
27668 procedure Normalize_Interval_List
27669 (List : in out Discrete_Interval_List; Last : out Nat);
27670 -- Perform sorting and merging as required by Check_Consistency.
27672 -----------------------------
27673 -- Normalize_Interval_List --
27674 -----------------------------
27675 procedure Normalize_Interval_List
27676 (List : in out Discrete_Interval_List; Last : out Nat) is
27678 procedure Move_Interval (From, To : Natural);
27679 -- Copy interval from one location to another
27681 function Lt_Interval (Idx1, Idx2 : Natural) return Boolean;
27682 -- Compare two list elements
27684 Temp_0 : Discrete_Interval := (others => Uint_0);
27685 -- cope with Heap_Sort_G idiosyncrasies.
27687 function Read_Interval (From : Natural) return Discrete_Interval;
27688 -- Normal array indexing unless From = 0
27690 -------------------
27691 -- Read_Interval --
27692 -------------------
27693 function Read_Interval (From : Natural) return Discrete_Interval is
27698 return List (Pos (From));
27702 -------------------
27703 -- Move_Interval --
27704 -------------------
27705 procedure Move_Interval (From, To : Natural) is
27706 Rhs : constant Discrete_Interval := Read_Interval (From);
27711 List (Pos (To)) := Rhs;
27718 function Lt_Interval (Idx1, Idx2 : Natural) return Boolean is
27719 Elem1 : constant Discrete_Interval := Read_Interval (Idx1);
27720 Elem2 : constant Discrete_Interval := Read_Interval (Idx2);
27721 Null_1 : constant Boolean := Elem1.Low > Elem1.High;
27722 Null_2 : constant Boolean := Elem2.Low > Elem2.High;
27724 if Null_1 /= Null_2 then
27725 -- So that sorting moves null intervals to high end
27727 elsif Elem1.Low /= Elem2.Low then
27728 return Elem1.Low < Elem2.Low;
27730 return Elem1.High < Elem2.High;
27734 package Interval_Sorting is
27735 new Gnat.Heap_Sort_G (Move_Interval, Lt_Interval);
27737 function Is_Null (Idx : Pos) return Boolean;
27738 -- True iff List (Idx) defines a null range
27740 function Is_Null (Idx : Pos) return Boolean is
27742 return List (Idx).Low > List (Idx).High;
27745 procedure Merge_Intervals (Null_Interval_Count : out Nat);
27746 -- Merge contiguous ranges by replacing one with merged range
27747 -- and the other with a null value. Return a count of the
27748 -- null intervals, both preexisting and those introduced by
27751 ---------------------
27752 -- Merge_Intervals --
27753 ---------------------
27754 procedure Merge_Intervals (Null_Interval_Count : out Nat) is
27755 Not_Null : Pos range List'Range;
27756 -- Index of the most recently examined non-null interval
27758 Null_Interval : constant Discrete_Interval
27759 := (Low => Uint_1, High => Uint_0); -- any null range ok here
27761 if List'Length = 0 or else Is_Null (List'First) then
27762 Null_Interval_Count := List'Length;
27763 -- no non-null elements, so no merge candidates
27767 Null_Interval_Count := 0;
27768 Not_Null := List'First;
27769 for Idx in List'First + 1 .. List'Last loop
27770 if Is_Null (Idx) then
27771 -- all remaining elements are null
27772 Null_Interval_Count :=
27773 Null_Interval_Count + List (Idx .. List'Last)'Length;
27775 elsif List (Idx).Low = List (Not_Null).High + 1 then
27776 -- Merge the two intervals into one; discard the other
27777 List (Not_Null).High := List (Idx).High;
27778 List (Idx) := Null_Interval;
27779 Null_Interval_Count := Null_Interval_Count + 1;
27781 pragma Assert (List (Idx).Low > List (Not_Null).High);
27785 end Merge_Intervals;
27787 Interval_Sorting.Sort (Natural (List'Last));
27789 Null_Interval_Count : Nat;
27791 Merge_Intervals (Null_Interval_Count);
27792 Last := List'Last - Null_Interval_Count;
27793 if Null_Interval_Count /= 0 then
27794 -- Move null intervals introduced during merging to high end
27795 Interval_Sorting.Sort (Natural (List'Last));
27798 end Normalize_Interval_List;
27800 ---------------------------
27801 -- Choice_List_Intervals --
27802 ---------------------------
27803 function Choice_List_Intervals
27804 (Discrete_Choices : List_Id) return Discrete_Interval_List
27806 function Unmerged_Choice_Count return Nat;
27807 -- The number of intervals before adjacent intervals are merged.
27809 ---------------------------
27810 -- Unmerged_Choice_Count --
27811 ---------------------------
27812 function Unmerged_Choice_Count return Nat is
27813 Choice : Node_Id := First (Discrete_Choices);
27816 while Present (Choice) loop
27817 -- Non-contiguous choices involving static predicates
27818 -- have already been normalized away.
27820 if Nkind (Choice) = N_Others_Choice then
27822 Count + List_Length (Others_Discrete_Choices (Choice));
27824 Count := Count + 1; -- an ordinary expression or range
27827 Choice := Next (Choice);
27830 end Unmerged_Choice_Count;
27832 Choice : Node_Id := First (Discrete_Choices);
27833 Result : Discrete_Interval_List (1 .. Unmerged_Choice_Count);
27836 while Present (Choice) loop
27837 if Nkind (Choice) = N_Others_Choice then
27839 Others_Choice : Node_Id
27840 := First (Others_Discrete_Choices (Choice));
27842 while Present (Others_Choice) loop
27843 Count := Count + 1;
27844 Result (Count) := Chosen_Interval (Others_Choice);
27845 Others_Choice := Next (Others_Choice);
27849 Count := Count + 1;
27850 Result (Count) := Chosen_Interval (Choice);
27852 Choice := Next (Choice);
27854 pragma Assert (Count = Result'Last);
27855 Normalize_Interval_List (Result, Count);
27856 Check_Consistency (Result (1 .. Count));
27857 return Result (1 .. Count);
27858 end Choice_List_Intervals;
27864 (Subset, Of_Set : Discrete_Interval_List) return Boolean
27866 -- Returns True iff for each interval of Subset we can find
27867 -- a single interval of Of_Set which contains the Subset interval.
27869 if Of_Set'Length = 0 then
27870 return Subset'Length = 0;
27874 Set_Index : Pos range Of_Set'Range := Of_Set'First;
27876 for Ss_Idx in Subset'Range loop
27877 while not In_Interval
27878 (Value => Subset (Ss_Idx).Low,
27879 Interval => Of_Set (Set_Index))
27881 if Set_Index = Of_Set'Last then
27884 Set_Index := Set_Index + 1;
27888 (Value => Subset (Ss_Idx).High,
27889 Interval => Of_Set (Set_Index))
27899 end Interval_Lists;
27902 Erroutc.Subprogram_Name_Ptr := Subprogram_Name'Access;