1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2019, 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);
1621 end Build_Class_Wide_Clone_Decl;
1623 -----------------------------
1624 -- Build_Component_Subtype --
1625 -----------------------------
1627 function Build_Component_Subtype
1630 T : Entity_Id) return Node_Id
1636 -- Unchecked_Union components do not require component subtypes
1638 if Is_Unchecked_Union (T) then
1642 Subt := Make_Temporary (Loc, 'S');
1643 Set_Is_Internal (Subt);
1646 Make_Subtype_Declaration (Loc,
1647 Defining_Identifier => Subt,
1648 Subtype_Indication =>
1649 Make_Subtype_Indication (Loc,
1650 Subtype_Mark => New_Occurrence_Of (Base_Type (T), Loc),
1652 Make_Index_Or_Discriminant_Constraint (Loc,
1653 Constraints => C)));
1655 Mark_Rewrite_Insertion (Decl);
1657 end Build_Component_Subtype;
1659 ---------------------------
1660 -- Build_Default_Subtype --
1661 ---------------------------
1663 function Build_Default_Subtype
1665 N : Node_Id) return Entity_Id
1667 Loc : constant Source_Ptr := Sloc (N);
1671 -- The base type that is to be constrained by the defaults
1674 if not Has_Discriminants (T) or else Is_Constrained (T) then
1678 Bas := Base_Type (T);
1680 -- If T is non-private but its base type is private, this is the
1681 -- completion of a subtype declaration whose parent type is private
1682 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1683 -- are to be found in the full view of the base. Check that the private
1684 -- status of T and its base differ.
1686 if Is_Private_Type (Bas)
1687 and then not Is_Private_Type (T)
1688 and then Present (Full_View (Bas))
1690 Bas := Full_View (Bas);
1693 Disc := First_Discriminant (T);
1695 if No (Discriminant_Default_Value (Disc)) then
1700 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
1701 Constraints : constant List_Id := New_List;
1705 while Present (Disc) loop
1706 Append_To (Constraints,
1707 New_Copy_Tree (Discriminant_Default_Value (Disc)));
1708 Next_Discriminant (Disc);
1712 Make_Subtype_Declaration (Loc,
1713 Defining_Identifier => Act,
1714 Subtype_Indication =>
1715 Make_Subtype_Indication (Loc,
1716 Subtype_Mark => New_Occurrence_Of (Bas, Loc),
1718 Make_Index_Or_Discriminant_Constraint (Loc,
1719 Constraints => Constraints)));
1721 Insert_Action (N, Decl);
1723 -- If the context is a component declaration the subtype declaration
1724 -- will be analyzed when the enclosing type is frozen, otherwise do
1727 if Ekind (Current_Scope) /= E_Record_Type then
1733 end Build_Default_Subtype;
1735 --------------------------------------------
1736 -- Build_Discriminal_Subtype_Of_Component --
1737 --------------------------------------------
1739 function Build_Discriminal_Subtype_Of_Component
1740 (T : Entity_Id) return Node_Id
1742 Loc : constant Source_Ptr := Sloc (T);
1746 function Build_Discriminal_Array_Constraint return List_Id;
1747 -- If one or more of the bounds of the component depends on
1748 -- discriminants, build actual constraint using the discriminants
1751 function Build_Discriminal_Record_Constraint return List_Id;
1752 -- Similar to previous one, for discriminated components constrained by
1753 -- the discriminant of the enclosing object.
1755 ----------------------------------------
1756 -- Build_Discriminal_Array_Constraint --
1757 ----------------------------------------
1759 function Build_Discriminal_Array_Constraint return List_Id is
1760 Constraints : constant List_Id := New_List;
1768 Indx := First_Index (T);
1769 while Present (Indx) loop
1770 Old_Lo := Type_Low_Bound (Etype (Indx));
1771 Old_Hi := Type_High_Bound (Etype (Indx));
1773 if Denotes_Discriminant (Old_Lo) then
1774 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
1777 Lo := New_Copy_Tree (Old_Lo);
1780 if Denotes_Discriminant (Old_Hi) then
1781 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
1784 Hi := New_Copy_Tree (Old_Hi);
1787 Append (Make_Range (Loc, Lo, Hi), Constraints);
1792 end Build_Discriminal_Array_Constraint;
1794 -----------------------------------------
1795 -- Build_Discriminal_Record_Constraint --
1796 -----------------------------------------
1798 function Build_Discriminal_Record_Constraint return List_Id is
1799 Constraints : constant List_Id := New_List;
1804 D := First_Elmt (Discriminant_Constraint (T));
1805 while Present (D) loop
1806 if Denotes_Discriminant (Node (D)) then
1808 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
1810 D_Val := New_Copy_Tree (Node (D));
1813 Append (D_Val, Constraints);
1818 end Build_Discriminal_Record_Constraint;
1820 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1823 if Ekind (T) = E_Array_Subtype then
1824 Id := First_Index (T);
1825 while Present (Id) loop
1826 if Denotes_Discriminant (Type_Low_Bound (Etype (Id)))
1828 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
1830 return Build_Component_Subtype
1831 (Build_Discriminal_Array_Constraint, Loc, T);
1837 elsif Ekind (T) = E_Record_Subtype
1838 and then Has_Discriminants (T)
1839 and then not Has_Unknown_Discriminants (T)
1841 D := First_Elmt (Discriminant_Constraint (T));
1842 while Present (D) loop
1843 if Denotes_Discriminant (Node (D)) then
1844 return Build_Component_Subtype
1845 (Build_Discriminal_Record_Constraint, Loc, T);
1852 -- If none of the above, the actual and nominal subtypes are the same
1855 end Build_Discriminal_Subtype_Of_Component;
1857 ------------------------------
1858 -- Build_Elaboration_Entity --
1859 ------------------------------
1861 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
1862 Loc : constant Source_Ptr := Sloc (N);
1864 Elab_Ent : Entity_Id;
1866 procedure Set_Package_Name (Ent : Entity_Id);
1867 -- Given an entity, sets the fully qualified name of the entity in
1868 -- Name_Buffer, with components separated by double underscores. This
1869 -- is a recursive routine that climbs the scope chain to Standard.
1871 ----------------------
1872 -- Set_Package_Name --
1873 ----------------------
1875 procedure Set_Package_Name (Ent : Entity_Id) is
1877 if Scope (Ent) /= Standard_Standard then
1878 Set_Package_Name (Scope (Ent));
1881 Nam : constant String := Get_Name_String (Chars (Ent));
1883 Name_Buffer (Name_Len + 1) := '_';
1884 Name_Buffer (Name_Len + 2) := '_';
1885 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
1886 Name_Len := Name_Len + Nam'Length + 2;
1890 Get_Name_String (Chars (Ent));
1892 end Set_Package_Name;
1894 -- Start of processing for Build_Elaboration_Entity
1897 -- Ignore call if already constructed
1899 if Present (Elaboration_Entity (Spec_Id)) then
1902 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1903 -- no role in analysis.
1905 elsif ASIS_Mode then
1908 -- Do not generate an elaboration entity in GNATprove move because the
1909 -- elaboration counter is a form of expansion.
1911 elsif GNATprove_Mode then
1914 -- See if we need elaboration entity
1916 -- We always need an elaboration entity when preserving control flow, as
1917 -- we want to remain explicit about the unit's elaboration order.
1919 elsif Opt.Suppress_Control_Flow_Optimizations then
1922 -- We always need an elaboration entity for the dynamic elaboration
1923 -- model, since it is needed to properly generate the PE exception for
1924 -- access before elaboration.
1926 elsif Dynamic_Elaboration_Checks then
1929 -- For the static model, we don't need the elaboration counter if this
1930 -- unit is sure to have no elaboration code, since that means there
1931 -- is no elaboration unit to be called. Note that we can't just decide
1932 -- after the fact by looking to see whether there was elaboration code,
1933 -- because that's too late to make this decision.
1935 elsif Restriction_Active (No_Elaboration_Code) then
1938 -- Similarly, for the static model, we can skip the elaboration counter
1939 -- if we have the No_Multiple_Elaboration restriction, since for the
1940 -- static model, that's the only purpose of the counter (to avoid
1941 -- multiple elaboration).
1943 elsif Restriction_Active (No_Multiple_Elaboration) then
1947 -- Here we need the elaboration entity
1949 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1950 -- name with dots replaced by double underscore. We have to manually
1951 -- construct this name, since it will be elaborated in the outer scope,
1952 -- and thus will not have the unit name automatically prepended.
1954 Set_Package_Name (Spec_Id);
1955 Add_Str_To_Name_Buffer ("_E");
1957 -- Create elaboration counter
1959 Elab_Ent := Make_Defining_Identifier (Loc, Chars => Name_Find);
1960 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
1963 Make_Object_Declaration (Loc,
1964 Defining_Identifier => Elab_Ent,
1965 Object_Definition =>
1966 New_Occurrence_Of (Standard_Short_Integer, Loc),
1967 Expression => Make_Integer_Literal (Loc, Uint_0));
1969 Push_Scope (Standard_Standard);
1970 Add_Global_Declaration (Decl);
1973 -- Reset True_Constant indication, since we will indeed assign a value
1974 -- to the variable in the binder main. We also kill the Current_Value
1975 -- and Last_Assignment fields for the same reason.
1977 Set_Is_True_Constant (Elab_Ent, False);
1978 Set_Current_Value (Elab_Ent, Empty);
1979 Set_Last_Assignment (Elab_Ent, Empty);
1981 -- We do not want any further qualification of the name (if we did not
1982 -- do this, we would pick up the name of the generic package in the case
1983 -- of a library level generic instantiation).
1985 Set_Has_Qualified_Name (Elab_Ent);
1986 Set_Has_Fully_Qualified_Name (Elab_Ent);
1987 end Build_Elaboration_Entity;
1989 --------------------------------
1990 -- Build_Explicit_Dereference --
1991 --------------------------------
1993 procedure Build_Explicit_Dereference
1997 Loc : constant Source_Ptr := Sloc (Expr);
2002 -- An entity of a type with a reference aspect is overloaded with
2003 -- both interpretations: with and without the dereference. Now that
2004 -- the dereference is made explicit, set the type of the node properly,
2005 -- to prevent anomalies in the backend. Same if the expression is an
2006 -- overloaded function call whose return type has a reference aspect.
2008 if Is_Entity_Name (Expr) then
2009 Set_Etype (Expr, Etype (Entity (Expr)));
2011 -- The designated entity will not be examined again when resolving
2012 -- the dereference, so generate a reference to it now.
2014 Generate_Reference (Entity (Expr), Expr);
2016 elsif Nkind (Expr) = N_Function_Call then
2018 -- If the name of the indexing function is overloaded, locate the one
2019 -- whose return type has an implicit dereference on the desired
2020 -- discriminant, and set entity and type of function call.
2022 if Is_Overloaded (Name (Expr)) then
2023 Get_First_Interp (Name (Expr), I, It);
2025 while Present (It.Nam) loop
2026 if Ekind ((It.Typ)) = E_Record_Type
2027 and then First_Entity ((It.Typ)) = Disc
2029 Set_Entity (Name (Expr), It.Nam);
2030 Set_Etype (Name (Expr), Etype (It.Nam));
2034 Get_Next_Interp (I, It);
2038 -- Set type of call from resolved function name.
2040 Set_Etype (Expr, Etype (Name (Expr)));
2043 Set_Is_Overloaded (Expr, False);
2045 -- The expression will often be a generalized indexing that yields a
2046 -- container element that is then dereferenced, in which case the
2047 -- generalized indexing call is also non-overloaded.
2049 if Nkind (Expr) = N_Indexed_Component
2050 and then Present (Generalized_Indexing (Expr))
2052 Set_Is_Overloaded (Generalized_Indexing (Expr), False);
2056 Make_Explicit_Dereference (Loc,
2058 Make_Selected_Component (Loc,
2059 Prefix => Relocate_Node (Expr),
2060 Selector_Name => New_Occurrence_Of (Disc, Loc))));
2061 Set_Etype (Prefix (Expr), Etype (Disc));
2062 Set_Etype (Expr, Designated_Type (Etype (Disc)));
2063 end Build_Explicit_Dereference;
2065 ---------------------------
2066 -- Build_Overriding_Spec --
2067 ---------------------------
2069 function Build_Overriding_Spec
2071 Typ : Entity_Id) return Node_Id
2073 Loc : constant Source_Ptr := Sloc (Typ);
2074 Par_Typ : constant Entity_Id := Find_Dispatching_Type (Op);
2075 Spec : constant Node_Id := Specification (Unit_Declaration_Node (Op));
2077 Formal_Spec : Node_Id;
2078 Formal_Type : Node_Id;
2082 New_Spec := Copy_Subprogram_Spec (Spec);
2084 Formal_Spec := First (Parameter_Specifications (New_Spec));
2085 while Present (Formal_Spec) loop
2086 Formal_Type := Parameter_Type (Formal_Spec);
2088 if Is_Entity_Name (Formal_Type)
2089 and then Entity (Formal_Type) = Par_Typ
2091 Rewrite (Formal_Type, New_Occurrence_Of (Typ, Loc));
2094 -- Nothing needs to be done for access parameters
2100 end Build_Overriding_Spec;
2102 -----------------------------------
2103 -- Cannot_Raise_Constraint_Error --
2104 -----------------------------------
2106 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
2108 if Compile_Time_Known_Value (Expr) then
2111 elsif Do_Range_Check (Expr) then
2114 elsif Raises_Constraint_Error (Expr) then
2118 case Nkind (Expr) is
2119 when N_Identifier =>
2122 when N_Expanded_Name =>
2125 when N_Selected_Component =>
2126 return not Do_Discriminant_Check (Expr);
2128 when N_Attribute_Reference =>
2129 if Do_Overflow_Check (Expr) then
2132 elsif No (Expressions (Expr)) then
2140 N := First (Expressions (Expr));
2141 while Present (N) loop
2142 if Cannot_Raise_Constraint_Error (N) then
2153 when N_Type_Conversion =>
2154 if Do_Overflow_Check (Expr)
2155 or else Do_Length_Check (Expr)
2156 or else Do_Tag_Check (Expr)
2160 return Cannot_Raise_Constraint_Error (Expression (Expr));
2163 when N_Unchecked_Type_Conversion =>
2164 return Cannot_Raise_Constraint_Error (Expression (Expr));
2167 if Do_Overflow_Check (Expr) then
2170 return Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
2177 if Do_Division_Check (Expr)
2179 Do_Overflow_Check (Expr)
2184 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
2186 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
2205 | N_Op_Shift_Right_Arithmetic
2209 if Do_Overflow_Check (Expr) then
2213 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
2215 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
2222 end Cannot_Raise_Constraint_Error;
2224 -----------------------------------------
2225 -- Check_Dynamically_Tagged_Expression --
2226 -----------------------------------------
2228 procedure Check_Dynamically_Tagged_Expression
2231 Related_Nod : Node_Id)
2234 pragma Assert (Is_Tagged_Type (Typ));
2236 -- In order to avoid spurious errors when analyzing the expanded code,
2237 -- this check is done only for nodes that come from source and for
2238 -- actuals of generic instantiations.
2240 if (Comes_From_Source (Related_Nod)
2241 or else In_Generic_Actual (Expr))
2242 and then (Is_Class_Wide_Type (Etype (Expr))
2243 or else Is_Dynamically_Tagged (Expr))
2244 and then not Is_Class_Wide_Type (Typ)
2246 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
2248 end Check_Dynamically_Tagged_Expression;
2250 --------------------------
2251 -- Check_Fully_Declared --
2252 --------------------------
2254 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
2256 if Ekind (T) = E_Incomplete_Type then
2258 -- Ada 2005 (AI-50217): If the type is available through a limited
2259 -- with_clause, verify that its full view has been analyzed.
2261 if From_Limited_With (T)
2262 and then Present (Non_Limited_View (T))
2263 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
2265 -- The non-limited view is fully declared
2271 ("premature usage of incomplete}", N, First_Subtype (T));
2274 -- Need comments for these tests ???
2276 elsif Has_Private_Component (T)
2277 and then not Is_Generic_Type (Root_Type (T))
2278 and then not In_Spec_Expression
2280 -- Special case: if T is the anonymous type created for a single
2281 -- task or protected object, use the name of the source object.
2283 if Is_Concurrent_Type (T)
2284 and then not Comes_From_Source (T)
2285 and then Nkind (N) = N_Object_Declaration
2288 ("type of& has incomplete component",
2289 N, Defining_Identifier (N));
2292 ("premature usage of incomplete}",
2293 N, First_Subtype (T));
2296 end Check_Fully_Declared;
2298 -------------------------------------------
2299 -- Check_Function_With_Address_Parameter --
2300 -------------------------------------------
2302 procedure Check_Function_With_Address_Parameter (Subp_Id : Entity_Id) is
2307 F := First_Formal (Subp_Id);
2308 while Present (F) loop
2311 if Is_Private_Type (T) and then Present (Full_View (T)) then
2315 if Is_Descendant_Of_Address (T) or else Is_Limited_Type (T) then
2316 Set_Is_Pure (Subp_Id, False);
2322 end Check_Function_With_Address_Parameter;
2324 -------------------------------------
2325 -- Check_Function_Writable_Actuals --
2326 -------------------------------------
2328 procedure Check_Function_Writable_Actuals (N : Node_Id) is
2329 Writable_Actuals_List : Elist_Id := No_Elist;
2330 Identifiers_List : Elist_Id := No_Elist;
2331 Aggr_Error_Node : Node_Id := Empty;
2332 Error_Node : Node_Id := Empty;
2334 procedure Collect_Identifiers (N : Node_Id);
2335 -- In a single traversal of subtree N collect in Writable_Actuals_List
2336 -- all the actuals of functions with writable actuals, and in the list
2337 -- Identifiers_List collect all the identifiers that are not actuals of
2338 -- functions with writable actuals. If a writable actual is referenced
2339 -- twice as writable actual then Error_Node is set to reference its
2340 -- second occurrence, the error is reported, and the tree traversal
2343 procedure Preanalyze_Without_Errors (N : Node_Id);
2344 -- Preanalyze N without reporting errors. Very dubious, you can't just
2345 -- go analyzing things more than once???
2347 -------------------------
2348 -- Collect_Identifiers --
2349 -------------------------
2351 procedure Collect_Identifiers (N : Node_Id) is
2353 function Check_Node (N : Node_Id) return Traverse_Result;
2354 -- Process a single node during the tree traversal to collect the
2355 -- writable actuals of functions and all the identifiers which are
2356 -- not writable actuals of functions.
2358 function Contains (List : Elist_Id; N : Node_Id) return Boolean;
2359 -- Returns True if List has a node whose Entity is Entity (N)
2365 function Check_Node (N : Node_Id) return Traverse_Result is
2366 Is_Writable_Actual : Boolean := False;
2370 if Nkind (N) = N_Identifier then
2372 -- No analysis possible if the entity is not decorated
2374 if No (Entity (N)) then
2377 -- Don't collect identifiers of packages, called functions, etc
2379 elsif Ekind_In (Entity (N), E_Package,
2386 -- For rewritten nodes, continue the traversal in the original
2387 -- subtree. Needed to handle aggregates in original expressions
2388 -- extracted from the tree by Remove_Side_Effects.
2390 elsif Is_Rewrite_Substitution (N) then
2391 Collect_Identifiers (Original_Node (N));
2394 -- For now we skip aggregate discriminants, since they require
2395 -- performing the analysis in two phases to identify conflicts:
2396 -- first one analyzing discriminants and second one analyzing
2397 -- the rest of components (since at run time, discriminants are
2398 -- evaluated prior to components): too much computation cost
2399 -- to identify a corner case???
2401 elsif Nkind (Parent (N)) = N_Component_Association
2402 and then Nkind_In (Parent (Parent (N)),
2404 N_Extension_Aggregate)
2407 Choice : constant Node_Id := First (Choices (Parent (N)));
2410 if Ekind (Entity (N)) = E_Discriminant then
2413 elsif Expression (Parent (N)) = N
2414 and then Nkind (Choice) = N_Identifier
2415 and then Ekind (Entity (Choice)) = E_Discriminant
2421 -- Analyze if N is a writable actual of a function
2423 elsif Nkind (Parent (N)) = N_Function_Call then
2425 Call : constant Node_Id := Parent (N);
2430 Id := Get_Called_Entity (Call);
2432 -- In case of previous error, no check is possible
2438 if Ekind_In (Id, E_Function, E_Generic_Function)
2439 and then Has_Out_Or_In_Out_Parameter (Id)
2441 Formal := First_Formal (Id);
2442 Actual := First_Actual (Call);
2443 while Present (Actual) and then Present (Formal) loop
2445 if Ekind_In (Formal, E_Out_Parameter,
2448 Is_Writable_Actual := True;
2454 Next_Formal (Formal);
2455 Next_Actual (Actual);
2461 if Is_Writable_Actual then
2463 -- Skip checking the error in non-elementary types since
2464 -- RM 6.4.1(6.15/3) is restricted to elementary types, but
2465 -- store this actual in Writable_Actuals_List since it is
2466 -- needed to perform checks on other constructs that have
2467 -- arbitrary order of evaluation (for example, aggregates).
2469 if not Is_Elementary_Type (Etype (N)) then
2470 if not Contains (Writable_Actuals_List, N) then
2471 Append_New_Elmt (N, To => Writable_Actuals_List);
2474 -- Second occurrence of an elementary type writable actual
2476 elsif Contains (Writable_Actuals_List, N) then
2478 -- Report the error on the second occurrence of the
2479 -- identifier. We cannot assume that N is the second
2480 -- occurrence (according to their location in the
2481 -- sources), since Traverse_Func walks through Field2
2482 -- last (see comment in the body of Traverse_Func).
2488 Elmt := First_Elmt (Writable_Actuals_List);
2489 while Present (Elmt)
2490 and then Entity (Node (Elmt)) /= Entity (N)
2495 if Sloc (N) > Sloc (Node (Elmt)) then
2498 Error_Node := Node (Elmt);
2502 ("value may be affected by call to & "
2503 & "because order of evaluation is arbitrary",
2508 -- First occurrence of a elementary type writable actual
2511 Append_New_Elmt (N, To => Writable_Actuals_List);
2515 if Identifiers_List = No_Elist then
2516 Identifiers_List := New_Elmt_List;
2519 Append_Unique_Elmt (N, Identifiers_List);
2532 N : Node_Id) return Boolean
2534 pragma Assert (Nkind (N) in N_Has_Entity);
2539 if List = No_Elist then
2543 Elmt := First_Elmt (List);
2544 while Present (Elmt) loop
2545 if Entity (Node (Elmt)) = Entity (N) then
2559 procedure Do_Traversal is new Traverse_Proc (Check_Node);
2560 -- The traversal procedure
2562 -- Start of processing for Collect_Identifiers
2565 if Present (Error_Node) then
2569 if Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
2574 end Collect_Identifiers;
2576 -------------------------------
2577 -- Preanalyze_Without_Errors --
2578 -------------------------------
2580 procedure Preanalyze_Without_Errors (N : Node_Id) is
2581 Status : constant Boolean := Get_Ignore_Errors;
2583 Set_Ignore_Errors (True);
2585 Set_Ignore_Errors (Status);
2586 end Preanalyze_Without_Errors;
2588 -- Start of processing for Check_Function_Writable_Actuals
2591 -- The check only applies to Ada 2012 code on which Check_Actuals has
2592 -- been set, and only to constructs that have multiple constituents
2593 -- whose order of evaluation is not specified by the language.
2595 if Ada_Version < Ada_2012
2596 or else not Check_Actuals (N)
2597 or else (not (Nkind (N) in N_Op)
2598 and then not (Nkind (N) in N_Membership_Test)
2599 and then not Nkind_In (N, N_Range,
2601 N_Extension_Aggregate,
2602 N_Full_Type_Declaration,
2604 N_Procedure_Call_Statement,
2605 N_Entry_Call_Statement))
2606 or else (Nkind (N) = N_Full_Type_Declaration
2607 and then not Is_Record_Type (Defining_Identifier (N)))
2609 -- In addition, this check only applies to source code, not to code
2610 -- generated by constraint checks.
2612 or else not Comes_From_Source (N)
2617 -- If a construct C has two or more direct constituents that are names
2618 -- or expressions whose evaluation may occur in an arbitrary order, at
2619 -- least one of which contains a function call with an in out or out
2620 -- parameter, then the construct is legal only if: for each name N that
2621 -- is passed as a parameter of mode in out or out to some inner function
2622 -- call C2 (not including the construct C itself), there is no other
2623 -- name anywhere within a direct constituent of the construct C other
2624 -- than the one containing C2, that is known to refer to the same
2625 -- object (RM 6.4.1(6.17/3)).
2629 Collect_Identifiers (Low_Bound (N));
2630 Collect_Identifiers (High_Bound (N));
2632 when N_Membership_Test
2639 Collect_Identifiers (Left_Opnd (N));
2641 if Present (Right_Opnd (N)) then
2642 Collect_Identifiers (Right_Opnd (N));
2645 if Nkind_In (N, N_In, N_Not_In)
2646 and then Present (Alternatives (N))
2648 Expr := First (Alternatives (N));
2649 while Present (Expr) loop
2650 Collect_Identifiers (Expr);
2657 when N_Full_Type_Declaration =>
2659 function Get_Record_Part (N : Node_Id) return Node_Id;
2660 -- Return the record part of this record type definition
2662 function Get_Record_Part (N : Node_Id) return Node_Id is
2663 Type_Def : constant Node_Id := Type_Definition (N);
2665 if Nkind (Type_Def) = N_Derived_Type_Definition then
2666 return Record_Extension_Part (Type_Def);
2670 end Get_Record_Part;
2673 Def_Id : Entity_Id := Defining_Identifier (N);
2674 Rec : Node_Id := Get_Record_Part (N);
2677 -- No need to perform any analysis if the record has no
2680 if No (Rec) or else No (Component_List (Rec)) then
2684 -- Collect the identifiers starting from the deepest
2685 -- derivation. Done to report the error in the deepest
2689 if Present (Component_List (Rec)) then
2690 Comp := First (Component_Items (Component_List (Rec)));
2691 while Present (Comp) loop
2692 if Nkind (Comp) = N_Component_Declaration
2693 and then Present (Expression (Comp))
2695 Collect_Identifiers (Expression (Comp));
2702 exit when No (Underlying_Type (Etype (Def_Id)))
2703 or else Base_Type (Underlying_Type (Etype (Def_Id)))
2706 Def_Id := Base_Type (Underlying_Type (Etype (Def_Id)));
2707 Rec := Get_Record_Part (Parent (Def_Id));
2711 when N_Entry_Call_Statement
2715 Id : constant Entity_Id := Get_Called_Entity (N);
2720 Formal := First_Formal (Id);
2721 Actual := First_Actual (N);
2722 while Present (Actual) and then Present (Formal) loop
2723 if Ekind_In (Formal, E_Out_Parameter,
2726 Collect_Identifiers (Actual);
2729 Next_Formal (Formal);
2730 Next_Actual (Actual);
2735 | N_Extension_Aggregate
2740 Comp_Expr : Node_Id;
2743 -- Handle the N_Others_Choice of array aggregates with static
2744 -- bounds. There is no need to perform this analysis in
2745 -- aggregates without static bounds since we cannot evaluate
2746 -- if the N_Others_Choice covers several elements. There is
2747 -- no need to handle the N_Others choice of record aggregates
2748 -- since at this stage it has been already expanded by
2749 -- Resolve_Record_Aggregate.
2751 if Is_Array_Type (Etype (N))
2752 and then Nkind (N) = N_Aggregate
2753 and then Present (Aggregate_Bounds (N))
2754 and then Compile_Time_Known_Bounds (Etype (N))
2755 and then Expr_Value (High_Bound (Aggregate_Bounds (N)))
2757 Expr_Value (Low_Bound (Aggregate_Bounds (N)))
2760 Count_Components : Uint := Uint_0;
2761 Num_Components : Uint;
2762 Others_Assoc : Node_Id;
2763 Others_Choice : Node_Id := Empty;
2764 Others_Box_Present : Boolean := False;
2767 -- Count positional associations
2769 if Present (Expressions (N)) then
2770 Comp_Expr := First (Expressions (N));
2771 while Present (Comp_Expr) loop
2772 Count_Components := Count_Components + 1;
2777 -- Count the rest of elements and locate the N_Others
2780 Assoc := First (Component_Associations (N));
2781 while Present (Assoc) loop
2782 Choice := First (Choices (Assoc));
2783 while Present (Choice) loop
2784 if Nkind (Choice) = N_Others_Choice then
2785 Others_Assoc := Assoc;
2786 Others_Choice := Choice;
2787 Others_Box_Present := Box_Present (Assoc);
2789 -- Count several components
2791 elsif Nkind_In (Choice, N_Range,
2792 N_Subtype_Indication)
2793 or else (Is_Entity_Name (Choice)
2794 and then Is_Type (Entity (Choice)))
2799 Get_Index_Bounds (Choice, L, H);
2801 (Compile_Time_Known_Value (L)
2802 and then Compile_Time_Known_Value (H));
2805 + Expr_Value (H) - Expr_Value (L) + 1;
2808 -- Count single component. No other case available
2809 -- since we are handling an aggregate with static
2813 pragma Assert (Is_OK_Static_Expression (Choice)
2814 or else Nkind (Choice) = N_Identifier
2815 or else Nkind (Choice) = N_Integer_Literal);
2817 Count_Components := Count_Components + 1;
2827 Expr_Value (High_Bound (Aggregate_Bounds (N))) -
2828 Expr_Value (Low_Bound (Aggregate_Bounds (N))) + 1;
2830 pragma Assert (Count_Components <= Num_Components);
2832 -- Handle the N_Others choice if it covers several
2835 if Present (Others_Choice)
2836 and then (Num_Components - Count_Components) > 1
2838 if not Others_Box_Present then
2840 -- At this stage, if expansion is active, the
2841 -- expression of the others choice has not been
2842 -- analyzed. Hence we generate a duplicate and
2843 -- we analyze it silently to have available the
2844 -- minimum decoration required to collect the
2847 if not Expander_Active then
2848 Comp_Expr := Expression (Others_Assoc);
2851 New_Copy_Tree (Expression (Others_Assoc));
2852 Preanalyze_Without_Errors (Comp_Expr);
2855 Collect_Identifiers (Comp_Expr);
2857 if Writable_Actuals_List /= No_Elist then
2859 -- As suggested by Robert, at current stage we
2860 -- report occurrences of this case as warnings.
2863 ("writable function parameter may affect "
2864 & "value in other component because order "
2865 & "of evaluation is unspecified??",
2866 Node (First_Elmt (Writable_Actuals_List)));
2872 -- For an array aggregate, a discrete_choice_list that has
2873 -- a nonstatic range is considered as two or more separate
2874 -- occurrences of the expression (RM 6.4.1(20/3)).
2876 elsif Is_Array_Type (Etype (N))
2877 and then Nkind (N) = N_Aggregate
2878 and then Present (Aggregate_Bounds (N))
2879 and then not Compile_Time_Known_Bounds (Etype (N))
2881 -- Collect identifiers found in the dynamic bounds
2884 Count_Components : Natural := 0;
2885 Low, High : Node_Id;
2888 Assoc := First (Component_Associations (N));
2889 while Present (Assoc) loop
2890 Choice := First (Choices (Assoc));
2891 while Present (Choice) loop
2892 if Nkind_In (Choice, N_Range,
2893 N_Subtype_Indication)
2894 or else (Is_Entity_Name (Choice)
2895 and then Is_Type (Entity (Choice)))
2897 Get_Index_Bounds (Choice, Low, High);
2899 if not Compile_Time_Known_Value (Low) then
2900 Collect_Identifiers (Low);
2902 if No (Aggr_Error_Node) then
2903 Aggr_Error_Node := Low;
2907 if not Compile_Time_Known_Value (High) then
2908 Collect_Identifiers (High);
2910 if No (Aggr_Error_Node) then
2911 Aggr_Error_Node := High;
2915 -- The RM rule is violated if there is more than
2916 -- a single choice in a component association.
2919 Count_Components := Count_Components + 1;
2921 if No (Aggr_Error_Node)
2922 and then Count_Components > 1
2924 Aggr_Error_Node := Choice;
2927 if not Compile_Time_Known_Value (Choice) then
2928 Collect_Identifiers (Choice);
2940 -- Handle ancestor part of extension aggregates
2942 if Nkind (N) = N_Extension_Aggregate then
2943 Collect_Identifiers (Ancestor_Part (N));
2946 -- Handle positional associations
2948 if Present (Expressions (N)) then
2949 Comp_Expr := First (Expressions (N));
2950 while Present (Comp_Expr) loop
2951 if not Is_OK_Static_Expression (Comp_Expr) then
2952 Collect_Identifiers (Comp_Expr);
2959 -- Handle discrete associations
2961 if Present (Component_Associations (N)) then
2962 Assoc := First (Component_Associations (N));
2963 while Present (Assoc) loop
2965 if not Box_Present (Assoc) then
2966 Choice := First (Choices (Assoc));
2967 while Present (Choice) loop
2969 -- For now we skip discriminants since it requires
2970 -- performing the analysis in two phases: first one
2971 -- analyzing discriminants and second one analyzing
2972 -- the rest of components since discriminants are
2973 -- evaluated prior to components: too much extra
2974 -- work to detect a corner case???
2976 if Nkind (Choice) in N_Has_Entity
2977 and then Present (Entity (Choice))
2978 and then Ekind (Entity (Choice)) = E_Discriminant
2982 elsif Box_Present (Assoc) then
2986 if not Analyzed (Expression (Assoc)) then
2988 New_Copy_Tree (Expression (Assoc));
2989 Set_Parent (Comp_Expr, Parent (N));
2990 Preanalyze_Without_Errors (Comp_Expr);
2992 Comp_Expr := Expression (Assoc);
2995 Collect_Identifiers (Comp_Expr);
3011 -- No further action needed if we already reported an error
3013 if Present (Error_Node) then
3017 -- Check violation of RM 6.20/3 in aggregates
3019 if Present (Aggr_Error_Node)
3020 and then Writable_Actuals_List /= No_Elist
3023 ("value may be affected by call in other component because they "
3024 & "are evaluated in unspecified order",
3025 Node (First_Elmt (Writable_Actuals_List)));
3029 -- Check if some writable argument of a function is referenced
3031 if Writable_Actuals_List /= No_Elist
3032 and then Identifiers_List /= No_Elist
3039 Elmt_1 := First_Elmt (Writable_Actuals_List);
3040 while Present (Elmt_1) loop
3041 Elmt_2 := First_Elmt (Identifiers_List);
3042 while Present (Elmt_2) loop
3043 if Entity (Node (Elmt_1)) = Entity (Node (Elmt_2)) then
3044 case Nkind (Parent (Node (Elmt_2))) is
3046 | N_Component_Association
3047 | N_Component_Declaration
3050 ("value may be affected by call in other "
3051 & "component because they are evaluated "
3052 & "in unspecified order",
3059 ("value may be affected by call in other "
3060 & "alternative because they are evaluated "
3061 & "in unspecified order",
3066 ("value of actual may be affected by call in "
3067 & "other actual because they are evaluated "
3068 & "in unspecified order",
3080 end Check_Function_Writable_Actuals;
3082 --------------------------------
3083 -- Check_Implicit_Dereference --
3084 --------------------------------
3086 procedure Check_Implicit_Dereference (N : Node_Id; Typ : Entity_Id) is
3092 if Nkind (N) = N_Indexed_Component
3093 and then Present (Generalized_Indexing (N))
3095 Nam := Generalized_Indexing (N);
3100 if Ada_Version < Ada_2012
3101 or else not Has_Implicit_Dereference (Base_Type (Typ))
3105 elsif not Comes_From_Source (N)
3106 and then Nkind (N) /= N_Indexed_Component
3110 elsif Is_Entity_Name (Nam) and then Is_Type (Entity (Nam)) then
3114 Disc := First_Discriminant (Typ);
3115 while Present (Disc) loop
3116 if Has_Implicit_Dereference (Disc) then
3117 Desig := Designated_Type (Etype (Disc));
3118 Add_One_Interp (Nam, Disc, Desig);
3120 -- If the node is a generalized indexing, add interpretation
3121 -- to that node as well, for subsequent resolution.
3123 if Nkind (N) = N_Indexed_Component then
3124 Add_One_Interp (N, Disc, Desig);
3127 -- If the operation comes from a generic unit and the context
3128 -- is a selected component, the selector name may be global
3129 -- and set in the instance already. Remove the entity to
3130 -- force resolution of the selected component, and the
3131 -- generation of an explicit dereference if needed.
3134 and then Nkind (Parent (Nam)) = N_Selected_Component
3136 Set_Entity (Selector_Name (Parent (Nam)), Empty);
3142 Next_Discriminant (Disc);
3145 end Check_Implicit_Dereference;
3147 ----------------------------------
3148 -- Check_Internal_Protected_Use --
3149 ----------------------------------
3151 procedure Check_Internal_Protected_Use (N : Node_Id; Nam : Entity_Id) is
3159 while Present (S) loop
3160 if S = Standard_Standard then
3163 elsif Ekind (S) = E_Function
3164 and then Ekind (Scope (S)) = E_Protected_Type
3174 and then Scope (Nam) = Prot
3175 and then Ekind (Nam) /= E_Function
3177 -- An indirect function call (e.g. a callback within a protected
3178 -- function body) is not statically illegal. If the access type is
3179 -- anonymous and is the type of an access parameter, the scope of Nam
3180 -- will be the protected type, but it is not a protected operation.
3182 if Ekind (Nam) = E_Subprogram_Type
3183 and then Nkind (Associated_Node_For_Itype (Nam)) =
3184 N_Function_Specification
3188 elsif Nkind (N) = N_Subprogram_Renaming_Declaration then
3190 ("within protected function cannot use protected procedure in "
3191 & "renaming or as generic actual", N);
3193 elsif Nkind (N) = N_Attribute_Reference then
3195 ("within protected function cannot take access of protected "
3200 ("within protected function, protected object is constant", N);
3202 ("\cannot call operation that may modify it", N);
3206 -- Verify that an internal call does not appear within a precondition
3207 -- of a protected operation. This implements AI12-0166.
3208 -- The precondition aspect has been rewritten as a pragma Precondition
3209 -- and we check whether the scope of the called subprogram is the same
3210 -- as that of the entity to which the aspect applies.
3212 if Convention (Nam) = Convention_Protected then
3218 while Present (P) loop
3219 if Nkind (P) = N_Pragma
3220 and then Chars (Pragma_Identifier (P)) = Name_Precondition
3221 and then From_Aspect_Specification (P)
3223 Scope (Entity (Corresponding_Aspect (P))) = Scope (Nam)
3226 ("internal call cannot appear in precondition of "
3227 & "protected operation", N);
3230 elsif Nkind (P) = N_Pragma
3231 and then Chars (Pragma_Identifier (P)) = Name_Contract_Cases
3233 -- Check whether call is in a case guard. It is legal in a
3237 while Present (P) loop
3238 if Nkind (Parent (P)) = N_Component_Association
3239 and then P /= Expression (Parent (P))
3242 ("internal call cannot appear in case guard in a "
3243 & "contract case", N);
3251 elsif Nkind (P) = N_Parameter_Specification
3252 and then Scope (Current_Scope) = Scope (Nam)
3253 and then Nkind_In (Parent (P), N_Entry_Declaration,
3254 N_Subprogram_Declaration)
3257 ("internal call cannot appear in default for formal of "
3258 & "protected operation", N);
3266 end Check_Internal_Protected_Use;
3268 ---------------------------------------
3269 -- Check_Later_Vs_Basic_Declarations --
3270 ---------------------------------------
3272 procedure Check_Later_Vs_Basic_Declarations
3274 During_Parsing : Boolean)
3276 Body_Sloc : Source_Ptr;
3279 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
3280 -- Return whether Decl is considered as a declarative item.
3281 -- When During_Parsing is True, the semantics of Ada 83 is followed.
3282 -- When During_Parsing is False, the semantics of SPARK is followed.
3284 -------------------------------
3285 -- Is_Later_Declarative_Item --
3286 -------------------------------
3288 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
3290 if Nkind (Decl) in N_Later_Decl_Item then
3293 elsif Nkind (Decl) = N_Pragma then
3296 elsif During_Parsing then
3299 -- In SPARK, a package declaration is not considered as a later
3300 -- declarative item.
3302 elsif Nkind (Decl) = N_Package_Declaration then
3305 -- In SPARK, a renaming is considered as a later declarative item
3307 elsif Nkind (Decl) in N_Renaming_Declaration then
3313 end Is_Later_Declarative_Item;
3315 -- Start of processing for Check_Later_Vs_Basic_Declarations
3318 Decl := First (Decls);
3320 -- Loop through sequence of basic declarative items
3322 Outer : while Present (Decl) loop
3323 if not Nkind_In (Decl, N_Subprogram_Body, N_Package_Body, N_Task_Body)
3324 and then Nkind (Decl) not in N_Body_Stub
3328 -- Once a body is encountered, we only allow later declarative
3329 -- items. The inner loop checks the rest of the list.
3332 Body_Sloc := Sloc (Decl);
3334 Inner : while Present (Decl) loop
3335 if not Is_Later_Declarative_Item (Decl) then
3336 if During_Parsing then
3337 if Ada_Version = Ada_83 then
3338 Error_Msg_Sloc := Body_Sloc;
3340 ("(Ada 83) decl cannot appear after body#", Decl);
3343 Error_Msg_Sloc := Body_Sloc;
3344 Check_SPARK_05_Restriction
3345 ("decl cannot appear after body#", Decl);
3353 end Check_Later_Vs_Basic_Declarations;
3355 ---------------------------
3356 -- Check_No_Hidden_State --
3357 ---------------------------
3359 procedure Check_No_Hidden_State (Id : Entity_Id) is
3360 Context : Entity_Id := Empty;
3361 Not_Visible : Boolean := False;
3365 pragma Assert (Ekind_In (Id, E_Abstract_State, E_Variable));
3367 -- Nothing to do for internally-generated abstract states and variables
3368 -- because they do not represent the hidden state of the source unit.
3370 if not Comes_From_Source (Id) then
3374 -- Find the proper context where the object or state appears
3377 while Present (Scop) loop
3380 -- Keep track of the context's visibility
3382 Not_Visible := Not_Visible or else In_Private_Part (Context);
3384 -- Prevent the search from going too far
3386 if Context = Standard_Standard then
3389 -- Objects and states that appear immediately within a subprogram or
3390 -- entry inside a construct nested within a subprogram do not
3391 -- introduce a hidden state. They behave as local variable
3392 -- declarations. The same is true for elaboration code inside a block
3395 elsif Is_Subprogram_Or_Entry (Context)
3396 or else Ekind_In (Context, E_Block, E_Task_Type)
3400 -- When examining a package body, use the entity of the spec as it
3401 -- carries the abstract state declarations.
3403 elsif Ekind (Context) = E_Package_Body then
3404 Context := Spec_Entity (Context);
3407 -- Stop the traversal when a package subject to a null abstract state
3410 if Ekind_In (Context, E_Generic_Package, E_Package)
3411 and then Has_Null_Abstract_State (Context)
3416 Scop := Scope (Scop);
3419 -- At this point we know that there is at least one package with a null
3420 -- abstract state in visibility. Emit an error message unconditionally
3421 -- if the entity being processed is a state because the placement of the
3422 -- related package is irrelevant. This is not the case for objects as
3423 -- the intermediate context matters.
3425 if Present (Context)
3426 and then (Ekind (Id) = E_Abstract_State or else Not_Visible)
3428 Error_Msg_N ("cannot introduce hidden state &", Id);
3429 Error_Msg_NE ("\package & has null abstract state", Id, Context);
3431 end Check_No_Hidden_State;
3433 ----------------------------------------
3434 -- Check_Nonvolatile_Function_Profile --
3435 ----------------------------------------
3437 procedure Check_Nonvolatile_Function_Profile (Func_Id : Entity_Id) is
3441 -- Inspect all formal parameters
3443 Formal := First_Formal (Func_Id);
3444 while Present (Formal) loop
3445 if Is_Effectively_Volatile (Etype (Formal)) then
3447 ("nonvolatile function & cannot have a volatile parameter",
3451 Next_Formal (Formal);
3454 -- Inspect the return type
3456 if Is_Effectively_Volatile (Etype (Func_Id)) then
3458 ("nonvolatile function & cannot have a volatile return type",
3459 Result_Definition (Parent (Func_Id)), Func_Id);
3461 end Check_Nonvolatile_Function_Profile;
3463 -----------------------------
3464 -- Check_Part_Of_Reference --
3465 -----------------------------
3467 procedure Check_Part_Of_Reference (Var_Id : Entity_Id; Ref : Node_Id) is
3468 function Is_Enclosing_Package_Body
3469 (Body_Decl : Node_Id;
3470 Obj_Id : Entity_Id) return Boolean;
3471 pragma Inline (Is_Enclosing_Package_Body);
3472 -- Determine whether package body Body_Decl or its corresponding spec
3473 -- immediately encloses the declaration of object Obj_Id.
3475 function Is_Internal_Declaration_Or_Body
3476 (Decl : Node_Id) return Boolean;
3477 pragma Inline (Is_Internal_Declaration_Or_Body);
3478 -- Determine whether declaration or body denoted by Decl is internal
3480 function Is_Single_Declaration_Or_Body
3482 Conc_Typ : Entity_Id) return Boolean;
3483 pragma Inline (Is_Single_Declaration_Or_Body);
3484 -- Determine whether protected/task declaration or body denoted by Decl
3485 -- belongs to single concurrent type Conc_Typ.
3487 function Is_Single_Task_Pragma
3489 Task_Typ : Entity_Id) return Boolean;
3490 pragma Inline (Is_Single_Task_Pragma);
3491 -- Determine whether pragma Prag belongs to single task type Task_Typ
3493 -------------------------------
3494 -- Is_Enclosing_Package_Body --
3495 -------------------------------
3497 function Is_Enclosing_Package_Body
3498 (Body_Decl : Node_Id;
3499 Obj_Id : Entity_Id) return Boolean
3501 Obj_Context : Node_Id;
3504 -- Find the context of the object declaration
3506 Obj_Context := Parent (Declaration_Node (Obj_Id));
3508 if Nkind (Obj_Context) = N_Package_Specification then
3509 Obj_Context := Parent (Obj_Context);
3512 -- The object appears immediately within the package body
3514 if Obj_Context = Body_Decl then
3517 -- The object appears immediately within the corresponding spec
3519 elsif Nkind (Obj_Context) = N_Package_Declaration
3520 and then Unit_Declaration_Node (Corresponding_Spec (Body_Decl)) =
3527 end Is_Enclosing_Package_Body;
3529 -------------------------------------
3530 -- Is_Internal_Declaration_Or_Body --
3531 -------------------------------------
3533 function Is_Internal_Declaration_Or_Body
3534 (Decl : Node_Id) return Boolean
3537 if Comes_From_Source (Decl) then
3540 -- A body generated for an expression function which has not been
3541 -- inserted into the tree yet (In_Spec_Expression is True) is not
3542 -- considered internal.
3544 elsif Nkind (Decl) = N_Subprogram_Body
3545 and then Was_Expression_Function (Decl)
3546 and then not In_Spec_Expression
3552 end Is_Internal_Declaration_Or_Body;
3554 -----------------------------------
3555 -- Is_Single_Declaration_Or_Body --
3556 -----------------------------------
3558 function Is_Single_Declaration_Or_Body
3560 Conc_Typ : Entity_Id) return Boolean
3562 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Decl);
3566 Present (Anonymous_Object (Spec_Id))
3567 and then Anonymous_Object (Spec_Id) = Conc_Typ;
3568 end Is_Single_Declaration_Or_Body;
3570 ---------------------------
3571 -- Is_Single_Task_Pragma --
3572 ---------------------------
3574 function Is_Single_Task_Pragma
3576 Task_Typ : Entity_Id) return Boolean
3578 Decl : constant Node_Id := Find_Related_Declaration_Or_Body (Prag);
3581 -- To qualify, the pragma must be associated with single task type
3585 Is_Single_Task_Object (Task_Typ)
3586 and then Nkind (Decl) = N_Object_Declaration
3587 and then Defining_Entity (Decl) = Task_Typ;
3588 end Is_Single_Task_Pragma;
3592 Conc_Obj : constant Entity_Id := Encapsulating_State (Var_Id);
3597 -- Start of processing for Check_Part_Of_Reference
3600 -- Nothing to do when the variable was recorded, but did not become a
3601 -- constituent of a single concurrent type.
3603 if No (Conc_Obj) then
3607 -- Traverse the parent chain looking for a suitable context for the
3608 -- reference to the concurrent constituent.
3611 Par := Parent (Prev);
3612 while Present (Par) loop
3613 if Nkind (Par) = N_Pragma then
3614 Prag_Nam := Pragma_Name (Par);
3616 -- A concurrent constituent is allowed to appear in pragmas
3617 -- Initial_Condition and Initializes as this is part of the
3618 -- elaboration checks for the constituent (SPARK RM 9(3)).
3620 if Nam_In (Prag_Nam, Name_Initial_Condition, Name_Initializes) then
3623 -- When the reference appears within pragma Depends or Global,
3624 -- check whether the pragma applies to a single task type. Note
3625 -- that the pragma may not encapsulated by the type definition,
3626 -- but this is still a valid context.
3628 elsif Nam_In (Prag_Nam, Name_Depends, Name_Global)
3629 and then Is_Single_Task_Pragma (Par, Conc_Obj)
3634 -- The reference appears somewhere in the definition of a single
3635 -- concurrent type (SPARK RM 9(3)).
3637 elsif Nkind_In (Par, N_Single_Protected_Declaration,
3638 N_Single_Task_Declaration)
3639 and then Defining_Entity (Par) = Conc_Obj
3643 -- The reference appears within the declaration or body of a single
3644 -- concurrent type (SPARK RM 9(3)).
3646 elsif Nkind_In (Par, N_Protected_Body,
3647 N_Protected_Type_Declaration,
3649 N_Task_Type_Declaration)
3650 and then Is_Single_Declaration_Or_Body (Par, Conc_Obj)
3654 -- The reference appears within the statement list of the object's
3655 -- immediately enclosing package (SPARK RM 9(3)).
3657 elsif Nkind (Par) = N_Package_Body
3658 and then Nkind (Prev) = N_Handled_Sequence_Of_Statements
3659 and then Is_Enclosing_Package_Body (Par, Var_Id)
3663 -- The reference has been relocated within an internally generated
3664 -- package or subprogram. Assume that the reference is legal as the
3665 -- real check was already performed in the original context of the
3668 elsif Nkind_In (Par, N_Package_Body,
3669 N_Package_Declaration,
3671 N_Subprogram_Declaration)
3672 and then Is_Internal_Declaration_Or_Body (Par)
3676 -- The reference has been relocated to an inlined body for GNATprove.
3677 -- Assume that the reference is legal as the real check was already
3678 -- performed in the original context of the reference.
3680 elsif GNATprove_Mode
3681 and then Nkind (Par) = N_Subprogram_Body
3682 and then Chars (Defining_Entity (Par)) = Name_uParent
3688 Par := Parent (Prev);
3691 -- At this point it is known that the reference does not appear within a
3695 ("reference to variable & cannot appear in this context", Ref, Var_Id);
3696 Error_Msg_Name_1 := Chars (Var_Id);
3698 if Is_Single_Protected_Object (Conc_Obj) then
3700 ("\% is constituent of single protected type &", Ref, Conc_Obj);
3704 ("\% is constituent of single task type &", Ref, Conc_Obj);
3706 end Check_Part_Of_Reference;
3708 ------------------------------------------
3709 -- Check_Potentially_Blocking_Operation --
3710 ------------------------------------------
3712 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
3716 -- N is one of the potentially blocking operations listed in 9.5.1(8).
3717 -- When pragma Detect_Blocking is active, the run time will raise
3718 -- Program_Error. Here we only issue a warning, since we generally
3719 -- support the use of potentially blocking operations in the absence
3722 -- Indirect blocking through a subprogram call cannot be diagnosed
3723 -- statically without interprocedural analysis, so we do not attempt
3726 S := Scope (Current_Scope);
3727 while Present (S) and then S /= Standard_Standard loop
3728 if Is_Protected_Type (S) then
3730 ("potentially blocking operation in protected operation??", N);
3736 end Check_Potentially_Blocking_Operation;
3738 ------------------------------------
3739 -- Check_Previous_Null_Procedure --
3740 ------------------------------------
3742 procedure Check_Previous_Null_Procedure
3747 if Ekind (Prev) = E_Procedure
3748 and then Nkind (Parent (Prev)) = N_Procedure_Specification
3749 and then Null_Present (Parent (Prev))
3751 Error_Msg_Sloc := Sloc (Prev);
3753 ("declaration cannot complete previous null procedure#", Decl);
3755 end Check_Previous_Null_Procedure;
3757 ---------------------------------
3758 -- Check_Result_And_Post_State --
3759 ---------------------------------
3761 procedure Check_Result_And_Post_State (Subp_Id : Entity_Id) is
3762 procedure Check_Result_And_Post_State_In_Pragma
3764 Result_Seen : in out Boolean);
3765 -- Determine whether pragma Prag mentions attribute 'Result and whether
3766 -- the pragma contains an expression that evaluates differently in pre-
3767 -- and post-state. Prag is a [refined] postcondition or a contract-cases
3768 -- pragma. Result_Seen is set when the pragma mentions attribute 'Result
3770 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean;
3771 -- Determine whether subprogram Subp_Id contains at least one IN OUT
3772 -- formal parameter.
3774 -------------------------------------------
3775 -- Check_Result_And_Post_State_In_Pragma --
3776 -------------------------------------------
3778 procedure Check_Result_And_Post_State_In_Pragma
3780 Result_Seen : in out Boolean)
3782 procedure Check_Conjunct (Expr : Node_Id);
3783 -- Check an individual conjunct in a conjunction of Boolean
3784 -- expressions, connected by "and" or "and then" operators.
3786 procedure Check_Conjuncts (Expr : Node_Id);
3787 -- Apply the post-state check to every conjunct in an expression, in
3788 -- case this is a conjunction of Boolean expressions. Otherwise apply
3789 -- it to the expression as a whole.
3791 procedure Check_Expression (Expr : Node_Id);
3792 -- Perform the 'Result and post-state checks on a given expression
3794 function Is_Function_Result (N : Node_Id) return Traverse_Result;
3795 -- Attempt to find attribute 'Result in a subtree denoted by N
3797 function Is_Trivial_Boolean (N : Node_Id) return Boolean;
3798 -- Determine whether source node N denotes "True" or "False"
3800 function Mentions_Post_State (N : Node_Id) return Boolean;
3801 -- Determine whether a subtree denoted by N mentions any construct
3802 -- that denotes a post-state.
3804 procedure Check_Function_Result is
3805 new Traverse_Proc (Is_Function_Result);
3807 --------------------
3808 -- Check_Conjunct --
3809 --------------------
3811 procedure Check_Conjunct (Expr : Node_Id) is
3812 function Adjust_Message (Msg : String) return String;
3813 -- Prepend a prefix to the input message Msg denoting that the
3814 -- message applies to a conjunct in the expression, when this
3817 function Applied_On_Conjunct return Boolean;
3818 -- Returns True if the message applies to a conjunct in the
3819 -- expression, instead of the whole expression.
3821 function Has_Global_Output (Subp : Entity_Id) return Boolean;
3822 -- Returns True if Subp has an output in its Global contract
3824 function Has_No_Output (Subp : Entity_Id) return Boolean;
3825 -- Returns True if Subp has no declared output: no function
3826 -- result, no output parameter, and no output in its Global
3829 --------------------
3830 -- Adjust_Message --
3831 --------------------
3833 function Adjust_Message (Msg : String) return String is
3835 if Applied_On_Conjunct then
3836 return "conjunct in " & Msg;
3842 -------------------------
3843 -- Applied_On_Conjunct --
3844 -------------------------
3846 function Applied_On_Conjunct return Boolean is
3848 -- Expr is the conjunct of an enclosing "and" expression
3850 return Nkind (Parent (Expr)) in N_Subexpr
3852 -- or Expr is a conjunct of an enclosing "and then"
3853 -- expression in a postcondition aspect that was split into
3854 -- multiple pragmas. The first conjunct has the "and then"
3855 -- expression as Original_Node, and other conjuncts have
3856 -- Split_PCC set to True.
3858 or else Nkind (Original_Node (Expr)) = N_And_Then
3859 or else Split_PPC (Prag);
3860 end Applied_On_Conjunct;
3862 -----------------------
3863 -- Has_Global_Output --
3864 -----------------------
3866 function Has_Global_Output (Subp : Entity_Id) return Boolean is
3867 Global : constant Node_Id := Get_Pragma (Subp, Pragma_Global);
3876 List := Expression (Get_Argument (Global, Subp));
3878 -- Empty list (no global items) or single global item
3879 -- declaration (only input items).
3881 if Nkind_In (List, N_Null,
3884 N_Selected_Component)
3888 -- Simple global list (only input items) or moded global list
3891 elsif Nkind (List) = N_Aggregate then
3892 if Present (Expressions (List)) then
3896 Assoc := First (Component_Associations (List));
3897 while Present (Assoc) loop
3898 if Chars (First (Choices (Assoc))) /= Name_Input then
3908 -- To accommodate partial decoration of disabled SPARK
3909 -- features, this routine may be called with illegal input.
3910 -- If this is the case, do not raise Program_Error.
3915 end Has_Global_Output;
3921 function Has_No_Output (Subp : Entity_Id) return Boolean is
3925 -- A function has its result as output
3927 if Ekind (Subp) = E_Function then
3931 -- An OUT or IN OUT parameter is an output
3933 Param := First_Formal (Subp);
3934 while Present (Param) loop
3935 if Ekind_In (Param, E_Out_Parameter, E_In_Out_Parameter) then
3939 Next_Formal (Param);
3942 -- An item of mode Output or In_Out in the Global contract is
3945 if Has_Global_Output (Subp) then
3955 -- Error node when reporting a warning on a (refined)
3958 -- Start of processing for Check_Conjunct
3961 if Applied_On_Conjunct then
3967 -- Do not report missing reference to outcome in postcondition if
3968 -- either the postcondition is trivially True or False, or if the
3969 -- subprogram is ghost and has no declared output.
3971 if not Is_Trivial_Boolean (Expr)
3972 and then not Mentions_Post_State (Expr)
3973 and then not (Is_Ghost_Entity (Subp_Id)
3974 and then Has_No_Output (Subp_Id))
3976 if Pragma_Name (Prag) = Name_Contract_Cases then
3977 Error_Msg_NE (Adjust_Message
3978 ("contract case does not check the outcome of calling "
3979 & "&?T?"), Expr, Subp_Id);
3981 elsif Pragma_Name (Prag) = Name_Refined_Post then
3982 Error_Msg_NE (Adjust_Message
3983 ("refined postcondition does not check the outcome of "
3984 & "calling &?T?"), Err_Node, Subp_Id);
3987 Error_Msg_NE (Adjust_Message
3988 ("postcondition does not check the outcome of calling "
3989 & "&?T?"), Err_Node, Subp_Id);
3994 ---------------------
3995 -- Check_Conjuncts --
3996 ---------------------
3998 procedure Check_Conjuncts (Expr : Node_Id) is
4000 if Nkind_In (Expr, N_Op_And, N_And_Then) then
4001 Check_Conjuncts (Left_Opnd (Expr));
4002 Check_Conjuncts (Right_Opnd (Expr));
4004 Check_Conjunct (Expr);
4006 end Check_Conjuncts;
4008 ----------------------
4009 -- Check_Expression --
4010 ----------------------
4012 procedure Check_Expression (Expr : Node_Id) is
4014 if not Is_Trivial_Boolean (Expr) then
4015 Check_Function_Result (Expr);
4016 Check_Conjuncts (Expr);
4018 end Check_Expression;
4020 ------------------------
4021 -- Is_Function_Result --
4022 ------------------------
4024 function Is_Function_Result (N : Node_Id) return Traverse_Result is
4026 if Is_Attribute_Result (N) then
4027 Result_Seen := True;
4030 -- Warn on infinite recursion if call is to current function
4032 elsif Nkind (N) = N_Function_Call
4033 and then Is_Entity_Name (Name (N))
4034 and then Entity (Name (N)) = Subp_Id
4035 and then not Is_Potentially_Unevaluated (N)
4038 ("call to & within its postcondition will lead to infinite "
4039 & "recursion?", N, Subp_Id);
4042 -- Continue the traversal
4047 end Is_Function_Result;
4049 ------------------------
4050 -- Is_Trivial_Boolean --
4051 ------------------------
4053 function Is_Trivial_Boolean (N : Node_Id) return Boolean is
4056 Comes_From_Source (N)
4057 and then Is_Entity_Name (N)
4058 and then (Entity (N) = Standard_True
4060 Entity (N) = Standard_False);
4061 end Is_Trivial_Boolean;
4063 -------------------------
4064 -- Mentions_Post_State --
4065 -------------------------
4067 function Mentions_Post_State (N : Node_Id) return Boolean is
4068 Post_State_Seen : Boolean := False;
4070 function Is_Post_State (N : Node_Id) return Traverse_Result;
4071 -- Attempt to find a construct that denotes a post-state. If this
4072 -- is the case, set flag Post_State_Seen.
4078 function Is_Post_State (N : Node_Id) return Traverse_Result is
4082 if Nkind_In (N, N_Explicit_Dereference, N_Function_Call) then
4083 Post_State_Seen := True;
4086 elsif Nkind_In (N, N_Expanded_Name, N_Identifier) then
4089 -- Treat an undecorated reference as OK
4093 -- A reference to an assignable entity is considered a
4094 -- change in the post-state of a subprogram.
4096 or else Ekind_In (Ent, E_Generic_In_Out_Parameter,
4101 -- The reference may be modified through a dereference
4103 or else (Is_Access_Type (Etype (Ent))
4104 and then Nkind (Parent (N)) =
4105 N_Selected_Component)
4107 Post_State_Seen := True;
4111 elsif Nkind (N) = N_Attribute_Reference then
4112 if Attribute_Name (N) = Name_Old then
4115 elsif Attribute_Name (N) = Name_Result then
4116 Post_State_Seen := True;
4124 procedure Find_Post_State is new Traverse_Proc (Is_Post_State);
4126 -- Start of processing for Mentions_Post_State
4129 Find_Post_State (N);
4131 return Post_State_Seen;
4132 end Mentions_Post_State;
4136 Expr : constant Node_Id :=
4138 (First (Pragma_Argument_Associations (Prag)));
4139 Nam : constant Name_Id := Pragma_Name (Prag);
4142 -- Start of processing for Check_Result_And_Post_State_In_Pragma
4145 -- Examine all consequences
4147 if Nam = Name_Contract_Cases then
4148 CCase := First (Component_Associations (Expr));
4149 while Present (CCase) loop
4150 Check_Expression (Expression (CCase));
4155 -- Examine the expression of a postcondition
4157 else pragma Assert (Nam_In (Nam, Name_Postcondition,
4158 Name_Refined_Post));
4159 Check_Expression (Expr);
4161 end Check_Result_And_Post_State_In_Pragma;
4163 --------------------------
4164 -- Has_In_Out_Parameter --
4165 --------------------------
4167 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean is
4171 -- Traverse the formals looking for an IN OUT parameter
4173 Formal := First_Formal (Subp_Id);
4174 while Present (Formal) loop
4175 if Ekind (Formal) = E_In_Out_Parameter then
4179 Next_Formal (Formal);
4183 end Has_In_Out_Parameter;
4187 Items : constant Node_Id := Contract (Subp_Id);
4188 Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id);
4189 Case_Prag : Node_Id := Empty;
4190 Post_Prag : Node_Id := Empty;
4192 Seen_In_Case : Boolean := False;
4193 Seen_In_Post : Boolean := False;
4194 Spec_Id : Entity_Id;
4196 -- Start of processing for Check_Result_And_Post_State
4199 -- The lack of attribute 'Result or a post-state is classified as a
4200 -- suspicious contract. Do not perform the check if the corresponding
4201 -- swich is not set.
4203 if not Warn_On_Suspicious_Contract then
4206 -- Nothing to do if there is no contract
4208 elsif No (Items) then
4212 -- Retrieve the entity of the subprogram spec (if any)
4214 if Nkind (Subp_Decl) = N_Subprogram_Body
4215 and then Present (Corresponding_Spec (Subp_Decl))
4217 Spec_Id := Corresponding_Spec (Subp_Decl);
4219 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4220 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
4222 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
4228 -- Examine all postconditions for attribute 'Result and a post-state
4230 Prag := Pre_Post_Conditions (Items);
4231 while Present (Prag) loop
4232 if Nam_In (Pragma_Name_Unmapped (Prag),
4233 Name_Postcondition, Name_Refined_Post)
4234 and then not Error_Posted (Prag)
4237 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Post);
4240 Prag := Next_Pragma (Prag);
4243 -- Examine the contract cases of the subprogram for attribute 'Result
4244 -- and a post-state.
4246 Prag := Contract_Test_Cases (Items);
4247 while Present (Prag) loop
4248 if Pragma_Name (Prag) = Name_Contract_Cases
4249 and then not Error_Posted (Prag)
4252 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Case);
4255 Prag := Next_Pragma (Prag);
4258 -- Do not emit any errors if the subprogram is not a function
4260 if not Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
4263 -- Regardless of whether the function has postconditions or contract
4264 -- cases, or whether they mention attribute 'Result, an IN OUT formal
4265 -- parameter is always treated as a result.
4267 elsif Has_In_Out_Parameter (Spec_Id) then
4270 -- The function has both a postcondition and contract cases and they do
4271 -- not mention attribute 'Result.
4273 elsif Present (Case_Prag)
4274 and then not Seen_In_Case
4275 and then Present (Post_Prag)
4276 and then not Seen_In_Post
4279 ("neither postcondition nor contract cases mention function "
4280 & "result?T?", Post_Prag);
4282 -- The function has contract cases only and they do not mention
4283 -- attribute 'Result.
4285 elsif Present (Case_Prag) and then not Seen_In_Case then
4286 Error_Msg_N ("contract cases do not mention result?T?", Case_Prag);
4288 -- The function has postconditions only and they do not mention
4289 -- attribute 'Result.
4291 elsif Present (Post_Prag) and then not Seen_In_Post then
4293 ("postcondition does not mention function result?T?", Post_Prag);
4295 end Check_Result_And_Post_State;
4297 -----------------------------
4298 -- Check_State_Refinements --
4299 -----------------------------
4301 procedure Check_State_Refinements
4303 Is_Main_Unit : Boolean := False)
4305 procedure Check_Package (Pack : Node_Id);
4306 -- Verify that all abstract states of a [generic] package denoted by its
4307 -- declarative node Pack have proper refinement. Recursively verify the
4308 -- visible and private declarations of the [generic] package for other
4311 procedure Check_Packages_In (Decls : List_Id);
4312 -- Seek out [generic] package declarations within declarative list Decls
4313 -- and verify the status of their abstract state refinement.
4315 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean;
4316 -- Determine whether construct N is subject to pragma SPARK_Mode Off
4322 procedure Check_Package (Pack : Node_Id) is
4323 Body_Id : constant Entity_Id := Corresponding_Body (Pack);
4324 Spec : constant Node_Id := Specification (Pack);
4325 States : constant Elist_Id :=
4326 Abstract_States (Defining_Entity (Pack));
4328 State_Elmt : Elmt_Id;
4329 State_Id : Entity_Id;
4332 -- Do not verify proper state refinement when the package is subject
4333 -- to pragma SPARK_Mode Off because this disables the requirement for
4334 -- state refinement.
4336 if SPARK_Mode_Is_Off (Pack) then
4339 -- State refinement can only occur in a completing package body. Do
4340 -- not verify proper state refinement when the body is subject to
4341 -- pragma SPARK_Mode Off because this disables the requirement for
4342 -- state refinement.
4344 elsif Present (Body_Id)
4345 and then SPARK_Mode_Is_Off (Unit_Declaration_Node (Body_Id))
4349 -- Do not verify proper state refinement when the package is an
4350 -- instance as this check was already performed in the generic.
4352 elsif Present (Generic_Parent (Spec)) then
4355 -- Otherwise examine the contents of the package
4358 if Present (States) then
4359 State_Elmt := First_Elmt (States);
4360 while Present (State_Elmt) loop
4361 State_Id := Node (State_Elmt);
4363 -- Emit an error when a non-null state lacks any form of
4366 if not Is_Null_State (State_Id)
4367 and then not Has_Null_Refinement (State_Id)
4368 and then not Has_Non_Null_Refinement (State_Id)
4370 Error_Msg_N ("state & requires refinement", State_Id);
4373 Next_Elmt (State_Elmt);
4377 Check_Packages_In (Visible_Declarations (Spec));
4378 Check_Packages_In (Private_Declarations (Spec));
4382 -----------------------
4383 -- Check_Packages_In --
4384 -----------------------
4386 procedure Check_Packages_In (Decls : List_Id) is
4390 if Present (Decls) then
4391 Decl := First (Decls);
4392 while Present (Decl) loop
4393 if Nkind_In (Decl, N_Generic_Package_Declaration,
4394 N_Package_Declaration)
4396 Check_Package (Decl);
4402 end Check_Packages_In;
4404 -----------------------
4405 -- SPARK_Mode_Is_Off --
4406 -----------------------
4408 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean is
4409 Id : constant Entity_Id := Defining_Entity (N);
4410 Prag : constant Node_Id := SPARK_Pragma (Id);
4413 -- Default the mode to "off" when the context is an instance and all
4414 -- SPARK_Mode pragmas found within are to be ignored.
4416 if Ignore_SPARK_Mode_Pragmas (Id) then
4422 and then Get_SPARK_Mode_From_Annotation (Prag) = Off;
4424 end SPARK_Mode_Is_Off;
4426 -- Start of processing for Check_State_Refinements
4429 -- A block may declare a nested package
4431 if Nkind (Context) = N_Block_Statement then
4432 Check_Packages_In (Declarations (Context));
4434 -- An entry, protected, subprogram, or task body may declare a nested
4437 elsif Nkind_In (Context, N_Entry_Body,
4442 -- Do not verify proper state refinement when the body is subject to
4443 -- pragma SPARK_Mode Off because this disables the requirement for
4444 -- state refinement.
4446 if not SPARK_Mode_Is_Off (Context) then
4447 Check_Packages_In (Declarations (Context));
4450 -- A package body may declare a nested package
4452 elsif Nkind (Context) = N_Package_Body then
4453 Check_Package (Unit_Declaration_Node (Corresponding_Spec (Context)));
4455 -- Do not verify proper state refinement when the body is subject to
4456 -- pragma SPARK_Mode Off because this disables the requirement for
4457 -- state refinement.
4459 if not SPARK_Mode_Is_Off (Context) then
4460 Check_Packages_In (Declarations (Context));
4463 -- A library level [generic] package may declare a nested package
4465 elsif Nkind_In (Context, N_Generic_Package_Declaration,
4466 N_Package_Declaration)
4467 and then Is_Main_Unit
4469 Check_Package (Context);
4471 end Check_State_Refinements;
4473 ------------------------------
4474 -- Check_Unprotected_Access --
4475 ------------------------------
4477 procedure Check_Unprotected_Access
4481 Cont_Encl_Typ : Entity_Id;
4482 Pref_Encl_Typ : Entity_Id;
4484 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
4485 -- Check whether Obj is a private component of a protected object.
4486 -- Return the protected type where the component resides, Empty
4489 function Is_Public_Operation return Boolean;
4490 -- Verify that the enclosing operation is callable from outside the
4491 -- protected object, to minimize false positives.
4493 ------------------------------
4494 -- Enclosing_Protected_Type --
4495 ------------------------------
4497 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
4499 if Is_Entity_Name (Obj) then
4501 Ent : Entity_Id := Entity (Obj);
4504 -- The object can be a renaming of a private component, use
4505 -- the original record component.
4507 if Is_Prival (Ent) then
4508 Ent := Prival_Link (Ent);
4511 if Is_Protected_Type (Scope (Ent)) then
4517 -- For indexed and selected components, recursively check the prefix
4519 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
4520 return Enclosing_Protected_Type (Prefix (Obj));
4522 -- The object does not denote a protected component
4527 end Enclosing_Protected_Type;
4529 -------------------------
4530 -- Is_Public_Operation --
4531 -------------------------
4533 function Is_Public_Operation return Boolean is
4539 while Present (S) and then S /= Pref_Encl_Typ loop
4540 if Scope (S) = Pref_Encl_Typ then
4541 E := First_Entity (Pref_Encl_Typ);
4543 and then E /= First_Private_Entity (Pref_Encl_Typ)
4557 end Is_Public_Operation;
4559 -- Start of processing for Check_Unprotected_Access
4562 if Nkind (Expr) = N_Attribute_Reference
4563 and then Attribute_Name (Expr) = Name_Unchecked_Access
4565 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
4566 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
4568 -- Check whether we are trying to export a protected component to a
4569 -- context with an equal or lower access level.
4571 if Present (Pref_Encl_Typ)
4572 and then No (Cont_Encl_Typ)
4573 and then Is_Public_Operation
4574 and then Scope_Depth (Pref_Encl_Typ) >=
4575 Object_Access_Level (Context)
4578 ("??possible unprotected access to protected data", Expr);
4581 end Check_Unprotected_Access;
4583 ------------------------------
4584 -- Check_Unused_Body_States --
4585 ------------------------------
4587 procedure Check_Unused_Body_States (Body_Id : Entity_Id) is
4588 procedure Process_Refinement_Clause
4591 -- Inspect all constituents of refinement clause Clause and remove any
4592 -- matches from body state list States.
4594 procedure Report_Unused_Body_States (States : Elist_Id);
4595 -- Emit errors for each abstract state or object found in list States
4597 -------------------------------
4598 -- Process_Refinement_Clause --
4599 -------------------------------
4601 procedure Process_Refinement_Clause
4605 procedure Process_Constituent (Constit : Node_Id);
4606 -- Remove constituent Constit from body state list States
4608 -------------------------
4609 -- Process_Constituent --
4610 -------------------------
4612 procedure Process_Constituent (Constit : Node_Id) is
4613 Constit_Id : Entity_Id;
4616 -- Guard against illegal constituents. Only abstract states and
4617 -- objects can appear on the right hand side of a refinement.
4619 if Is_Entity_Name (Constit) then
4620 Constit_Id := Entity_Of (Constit);
4622 if Present (Constit_Id)
4623 and then Ekind_In (Constit_Id, E_Abstract_State,
4627 Remove (States, Constit_Id);
4630 end Process_Constituent;
4636 -- Start of processing for Process_Refinement_Clause
4639 if Nkind (Clause) = N_Component_Association then
4640 Constit := Expression (Clause);
4642 -- Multiple constituents appear as an aggregate
4644 if Nkind (Constit) = N_Aggregate then
4645 Constit := First (Expressions (Constit));
4646 while Present (Constit) loop
4647 Process_Constituent (Constit);
4651 -- Various forms of a single constituent
4654 Process_Constituent (Constit);
4657 end Process_Refinement_Clause;
4659 -------------------------------
4660 -- Report_Unused_Body_States --
4661 -------------------------------
4663 procedure Report_Unused_Body_States (States : Elist_Id) is
4664 Posted : Boolean := False;
4665 State_Elmt : Elmt_Id;
4666 State_Id : Entity_Id;
4669 if Present (States) then
4670 State_Elmt := First_Elmt (States);
4671 while Present (State_Elmt) loop
4672 State_Id := Node (State_Elmt);
4674 -- Constants are part of the hidden state of a package, but the
4675 -- compiler cannot determine whether they have variable input
4676 -- (SPARK RM 7.1.1(2)) and cannot classify them properly as a
4677 -- hidden state. Do not emit an error when a constant does not
4678 -- participate in a state refinement, even though it acts as a
4681 if Ekind (State_Id) = E_Constant then
4684 -- Generate an error message of the form:
4686 -- body of package ... has unused hidden states
4687 -- abstract state ... defined at ...
4688 -- variable ... defined at ...
4694 ("body of package & has unused hidden states", Body_Id);
4697 Error_Msg_Sloc := Sloc (State_Id);
4699 if Ekind (State_Id) = E_Abstract_State then
4701 ("\abstract state & defined #", Body_Id, State_Id);
4704 SPARK_Msg_NE ("\variable & defined #", Body_Id, State_Id);
4708 Next_Elmt (State_Elmt);
4711 end Report_Unused_Body_States;
4715 Prag : constant Node_Id := Get_Pragma (Body_Id, Pragma_Refined_State);
4716 Spec_Id : constant Entity_Id := Spec_Entity (Body_Id);
4720 -- Start of processing for Check_Unused_Body_States
4723 -- Inspect the clauses of pragma Refined_State and determine whether all
4724 -- visible states declared within the package body participate in the
4727 if Present (Prag) then
4728 Clause := Expression (Get_Argument (Prag, Spec_Id));
4729 States := Collect_Body_States (Body_Id);
4731 -- Multiple non-null state refinements appear as an aggregate
4733 if Nkind (Clause) = N_Aggregate then
4734 Clause := First (Component_Associations (Clause));
4735 while Present (Clause) loop
4736 Process_Refinement_Clause (Clause, States);
4740 -- Various forms of a single state refinement
4743 Process_Refinement_Clause (Clause, States);
4746 -- Ensure that all abstract states and objects declared in the
4747 -- package body state space are utilized as constituents.
4749 Report_Unused_Body_States (States);
4751 end Check_Unused_Body_States;
4757 function Choice_List (N : Node_Id) return List_Id is
4759 if Nkind (N) = N_Iterated_Component_Association then
4760 return Discrete_Choices (N);
4766 -------------------------
4767 -- Collect_Body_States --
4768 -------------------------
4770 function Collect_Body_States (Body_Id : Entity_Id) return Elist_Id is
4771 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean;
4772 -- Determine whether object Obj_Id is a suitable visible state of a
4775 procedure Collect_Visible_States
4776 (Pack_Id : Entity_Id;
4777 States : in out Elist_Id);
4778 -- Gather the entities of all abstract states and objects declared in
4779 -- the visible state space of package Pack_Id.
4781 ----------------------------
4782 -- Collect_Visible_States --
4783 ----------------------------
4785 procedure Collect_Visible_States
4786 (Pack_Id : Entity_Id;
4787 States : in out Elist_Id)
4789 Item_Id : Entity_Id;
4792 -- Traverse the entity chain of the package and inspect all visible
4795 Item_Id := First_Entity (Pack_Id);
4796 while Present (Item_Id) and then not In_Private_Part (Item_Id) loop
4798 -- Do not consider internally generated items as those cannot be
4799 -- named and participate in refinement.
4801 if not Comes_From_Source (Item_Id) then
4804 elsif Ekind (Item_Id) = E_Abstract_State then
4805 Append_New_Elmt (Item_Id, States);
4807 elsif Ekind_In (Item_Id, E_Constant, E_Variable)
4808 and then Is_Visible_Object (Item_Id)
4810 Append_New_Elmt (Item_Id, States);
4812 -- Recursively gather the visible states of a nested package
4814 elsif Ekind (Item_Id) = E_Package then
4815 Collect_Visible_States (Item_Id, States);
4818 Next_Entity (Item_Id);
4820 end Collect_Visible_States;
4822 -----------------------
4823 -- Is_Visible_Object --
4824 -----------------------
4826 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean is
4828 -- Objects that map generic formals to their actuals are not visible
4829 -- from outside the generic instantiation.
4831 if Present (Corresponding_Generic_Association
4832 (Declaration_Node (Obj_Id)))
4836 -- Constituents of a single protected/task type act as components of
4837 -- the type and are not visible from outside the type.
4839 elsif Ekind (Obj_Id) = E_Variable
4840 and then Present (Encapsulating_State (Obj_Id))
4841 and then Is_Single_Concurrent_Object (Encapsulating_State (Obj_Id))
4848 end Is_Visible_Object;
4852 Body_Decl : constant Node_Id := Unit_Declaration_Node (Body_Id);
4854 Item_Id : Entity_Id;
4855 States : Elist_Id := No_Elist;
4857 -- Start of processing for Collect_Body_States
4860 -- Inspect the declarations of the body looking for source objects,
4861 -- packages and package instantiations. Note that even though this
4862 -- processing is very similar to Collect_Visible_States, a package
4863 -- body does not have a First/Next_Entity list.
4865 Decl := First (Declarations (Body_Decl));
4866 while Present (Decl) loop
4868 -- Capture source objects as internally generated temporaries cannot
4869 -- be named and participate in refinement.
4871 if Nkind (Decl) = N_Object_Declaration then
4872 Item_Id := Defining_Entity (Decl);
4874 if Comes_From_Source (Item_Id)
4875 and then Is_Visible_Object (Item_Id)
4877 Append_New_Elmt (Item_Id, States);
4880 -- Capture the visible abstract states and objects of a source
4881 -- package [instantiation].
4883 elsif Nkind (Decl) = N_Package_Declaration then
4884 Item_Id := Defining_Entity (Decl);
4886 if Comes_From_Source (Item_Id) then
4887 Collect_Visible_States (Item_Id, States);
4895 end Collect_Body_States;
4897 ------------------------
4898 -- Collect_Interfaces --
4899 ------------------------
4901 procedure Collect_Interfaces
4903 Ifaces_List : out Elist_Id;
4904 Exclude_Parents : Boolean := False;
4905 Use_Full_View : Boolean := True)
4907 procedure Collect (Typ : Entity_Id);
4908 -- Subsidiary subprogram used to traverse the whole list
4909 -- of directly and indirectly implemented interfaces
4915 procedure Collect (Typ : Entity_Id) is
4916 Ancestor : Entity_Id;
4924 -- Handle private types and subtypes
4927 and then Is_Private_Type (Typ)
4928 and then Present (Full_View (Typ))
4930 Full_T := Full_View (Typ);
4932 if Ekind (Full_T) = E_Record_Subtype then
4933 Full_T := Etype (Typ);
4935 if Present (Full_View (Full_T)) then
4936 Full_T := Full_View (Full_T);
4941 -- Include the ancestor if we are generating the whole list of
4942 -- abstract interfaces.
4944 if Etype (Full_T) /= Typ
4946 -- Protect the frontend against wrong sources. For example:
4949 -- type A is tagged null record;
4950 -- type B is new A with private;
4951 -- type C is new A with private;
4953 -- type B is new C with null record;
4954 -- type C is new B with null record;
4957 and then Etype (Full_T) /= T
4959 Ancestor := Etype (Full_T);
4962 if Is_Interface (Ancestor) and then not Exclude_Parents then
4963 Append_Unique_Elmt (Ancestor, Ifaces_List);
4967 -- Traverse the graph of ancestor interfaces
4969 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
4970 Id := First (Abstract_Interface_List (Full_T));
4971 while Present (Id) loop
4972 Iface := Etype (Id);
4974 -- Protect against wrong uses. For example:
4975 -- type I is interface;
4976 -- type O is tagged null record;
4977 -- type Wrong is new I and O with null record; -- ERROR
4979 if Is_Interface (Iface) then
4981 and then Etype (T) /= T
4982 and then Interface_Present_In_Ancestor (Etype (T), Iface)
4987 Append_Unique_Elmt (Iface, Ifaces_List);
4996 -- Start of processing for Collect_Interfaces
4999 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
5000 Ifaces_List := New_Elmt_List;
5002 end Collect_Interfaces;
5004 ----------------------------------
5005 -- Collect_Interface_Components --
5006 ----------------------------------
5008 procedure Collect_Interface_Components
5009 (Tagged_Type : Entity_Id;
5010 Components_List : out Elist_Id)
5012 procedure Collect (Typ : Entity_Id);
5013 -- Subsidiary subprogram used to climb to the parents
5019 procedure Collect (Typ : Entity_Id) is
5020 Tag_Comp : Entity_Id;
5021 Parent_Typ : Entity_Id;
5024 -- Handle private types
5026 if Present (Full_View (Etype (Typ))) then
5027 Parent_Typ := Full_View (Etype (Typ));
5029 Parent_Typ := Etype (Typ);
5032 if Parent_Typ /= Typ
5034 -- Protect the frontend against wrong sources. For example:
5037 -- type A is tagged null record;
5038 -- type B is new A with private;
5039 -- type C is new A with private;
5041 -- type B is new C with null record;
5042 -- type C is new B with null record;
5045 and then Parent_Typ /= Tagged_Type
5047 Collect (Parent_Typ);
5050 -- Collect the components containing tags of secondary dispatch
5053 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
5054 while Present (Tag_Comp) loop
5055 pragma Assert (Present (Related_Type (Tag_Comp)));
5056 Append_Elmt (Tag_Comp, Components_List);
5058 Tag_Comp := Next_Tag_Component (Tag_Comp);
5062 -- Start of processing for Collect_Interface_Components
5065 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
5066 and then Is_Tagged_Type (Tagged_Type));
5068 Components_List := New_Elmt_List;
5069 Collect (Tagged_Type);
5070 end Collect_Interface_Components;
5072 -----------------------------
5073 -- Collect_Interfaces_Info --
5074 -----------------------------
5076 procedure Collect_Interfaces_Info
5078 Ifaces_List : out Elist_Id;
5079 Components_List : out Elist_Id;
5080 Tags_List : out Elist_Id)
5082 Comps_List : Elist_Id;
5083 Comp_Elmt : Elmt_Id;
5084 Comp_Iface : Entity_Id;
5085 Iface_Elmt : Elmt_Id;
5088 function Search_Tag (Iface : Entity_Id) return Entity_Id;
5089 -- Search for the secondary tag associated with the interface type
5090 -- Iface that is implemented by T.
5096 function Search_Tag (Iface : Entity_Id) return Entity_Id is
5099 if not Is_CPP_Class (T) then
5100 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
5102 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
5106 and then Is_Tag (Node (ADT))
5107 and then Related_Type (Node (ADT)) /= Iface
5109 -- Skip secondary dispatch table referencing thunks to user
5110 -- defined primitives covered by this interface.
5112 pragma Assert (Has_Suffix (Node (ADT), 'P'));
5115 -- Skip secondary dispatch tables of Ada types
5117 if not Is_CPP_Class (T) then
5119 -- Skip secondary dispatch table referencing thunks to
5120 -- predefined primitives.
5122 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
5125 -- Skip secondary dispatch table referencing user-defined
5126 -- primitives covered by this interface.
5128 pragma Assert (Has_Suffix (Node (ADT), 'D'));
5131 -- Skip secondary dispatch table referencing predefined
5134 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
5139 pragma Assert (Is_Tag (Node (ADT)));
5143 -- Start of processing for Collect_Interfaces_Info
5146 Collect_Interfaces (T, Ifaces_List);
5147 Collect_Interface_Components (T, Comps_List);
5149 -- Search for the record component and tag associated with each
5150 -- interface type of T.
5152 Components_List := New_Elmt_List;
5153 Tags_List := New_Elmt_List;
5155 Iface_Elmt := First_Elmt (Ifaces_List);
5156 while Present (Iface_Elmt) loop
5157 Iface := Node (Iface_Elmt);
5159 -- Associate the primary tag component and the primary dispatch table
5160 -- with all the interfaces that are parents of T
5162 if Is_Ancestor (Iface, T, Use_Full_View => True) then
5163 Append_Elmt (First_Tag_Component (T), Components_List);
5164 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
5166 -- Otherwise search for the tag component and secondary dispatch
5170 Comp_Elmt := First_Elmt (Comps_List);
5171 while Present (Comp_Elmt) loop
5172 Comp_Iface := Related_Type (Node (Comp_Elmt));
5174 if Comp_Iface = Iface
5175 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
5177 Append_Elmt (Node (Comp_Elmt), Components_List);
5178 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
5182 Next_Elmt (Comp_Elmt);
5184 pragma Assert (Present (Comp_Elmt));
5187 Next_Elmt (Iface_Elmt);
5189 end Collect_Interfaces_Info;
5191 ---------------------
5192 -- Collect_Parents --
5193 ---------------------
5195 procedure Collect_Parents
5197 List : out Elist_Id;
5198 Use_Full_View : Boolean := True)
5200 Current_Typ : Entity_Id := T;
5201 Parent_Typ : Entity_Id;
5204 List := New_Elmt_List;
5206 -- No action if the if the type has no parents
5208 if T = Etype (T) then
5213 Parent_Typ := Etype (Current_Typ);
5215 if Is_Private_Type (Parent_Typ)
5216 and then Present (Full_View (Parent_Typ))
5217 and then Use_Full_View
5219 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5222 Append_Elmt (Parent_Typ, List);
5224 exit when Parent_Typ = Current_Typ;
5225 Current_Typ := Parent_Typ;
5227 end Collect_Parents;
5229 ----------------------------------
5230 -- Collect_Primitive_Operations --
5231 ----------------------------------
5233 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
5234 B_Type : constant Entity_Id := Base_Type (T);
5236 function Match (E : Entity_Id) return Boolean;
5237 -- True if E's base type is B_Type, or E is of an anonymous access type
5238 -- and the base type of its designated type is B_Type.
5244 function Match (E : Entity_Id) return Boolean is
5245 Etyp : Entity_Id := Etype (E);
5248 if Ekind (Etyp) = E_Anonymous_Access_Type then
5249 Etyp := Designated_Type (Etyp);
5252 -- In Ada 2012 a primitive operation may have a formal of an
5253 -- incomplete view of the parent type.
5255 return Base_Type (Etyp) = B_Type
5257 (Ada_Version >= Ada_2012
5258 and then Ekind (Etyp) = E_Incomplete_Type
5259 and then Full_View (Etyp) = B_Type);
5264 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
5265 B_Scope : Entity_Id := Scope (B_Type);
5267 Eq_Prims_List : Elist_Id := No_Elist;
5270 Is_Type_In_Pkg : Boolean;
5271 Formal_Derived : Boolean := False;
5274 -- Start of processing for Collect_Primitive_Operations
5277 -- For tagged types, the primitive operations are collected as they
5278 -- are declared, and held in an explicit list which is simply returned.
5280 if Is_Tagged_Type (B_Type) then
5281 return Primitive_Operations (B_Type);
5283 -- An untagged generic type that is a derived type inherits the
5284 -- primitive operations of its parent type. Other formal types only
5285 -- have predefined operators, which are not explicitly represented.
5287 elsif Is_Generic_Type (B_Type) then
5288 if Nkind (B_Decl) = N_Formal_Type_Declaration
5289 and then Nkind (Formal_Type_Definition (B_Decl)) =
5290 N_Formal_Derived_Type_Definition
5292 Formal_Derived := True;
5294 return New_Elmt_List;
5298 Op_List := New_Elmt_List;
5300 if B_Scope = Standard_Standard then
5301 if B_Type = Standard_String then
5302 Append_Elmt (Standard_Op_Concat, Op_List);
5304 elsif B_Type = Standard_Wide_String then
5305 Append_Elmt (Standard_Op_Concatw, Op_List);
5311 -- Locate the primitive subprograms of the type
5314 -- The primitive operations appear after the base type, except if the
5315 -- derivation happens within the private part of B_Scope and the type
5316 -- is a private type, in which case both the type and some primitive
5317 -- operations may appear before the base type, and the list of
5318 -- candidates starts after the type.
5320 if In_Open_Scopes (B_Scope)
5321 and then Scope (T) = B_Scope
5322 and then In_Private_Part (B_Scope)
5324 Id := Next_Entity (T);
5326 -- In Ada 2012, If the type has an incomplete partial view, there may
5327 -- be primitive operations declared before the full view, so we need
5328 -- to start scanning from the incomplete view, which is earlier on
5329 -- the entity chain.
5331 elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration
5332 and then Present (Incomplete_View (Parent (B_Type)))
5334 Id := Defining_Entity (Incomplete_View (Parent (B_Type)));
5336 -- If T is a derived from a type with an incomplete view declared
5337 -- elsewhere, that incomplete view is irrelevant, we want the
5338 -- operations in the scope of T.
5340 if Scope (Id) /= Scope (B_Type) then
5341 Id := Next_Entity (B_Type);
5345 Id := Next_Entity (B_Type);
5348 -- Set flag if this is a type in a package spec
5351 Is_Package_Or_Generic_Package (B_Scope)
5353 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
5356 while Present (Id) loop
5358 -- Test whether the result type or any of the parameter types of
5359 -- each subprogram following the type match that type when the
5360 -- type is declared in a package spec, is a derived type, or the
5361 -- subprogram is marked as primitive. (The Is_Primitive test is
5362 -- needed to find primitives of nonderived types in declarative
5363 -- parts that happen to override the predefined "=" operator.)
5365 -- Note that generic formal subprograms are not considered to be
5366 -- primitive operations and thus are never inherited.
5368 if Is_Overloadable (Id)
5369 and then (Is_Type_In_Pkg
5370 or else Is_Derived_Type (B_Type)
5371 or else Is_Primitive (Id))
5372 and then Nkind (Parent (Parent (Id)))
5373 not in N_Formal_Subprogram_Declaration
5381 Formal := First_Formal (Id);
5382 while Present (Formal) loop
5383 if Match (Formal) then
5388 Next_Formal (Formal);
5392 -- For a formal derived type, the only primitives are the ones
5393 -- inherited from the parent type. Operations appearing in the
5394 -- package declaration are not primitive for it.
5397 and then (not Formal_Derived or else Present (Alias (Id)))
5399 -- In the special case of an equality operator aliased to
5400 -- an overriding dispatching equality belonging to the same
5401 -- type, we don't include it in the list of primitives.
5402 -- This avoids inheriting multiple equality operators when
5403 -- deriving from untagged private types whose full type is
5404 -- tagged, which can otherwise cause ambiguities. Note that
5405 -- this should only happen for this kind of untagged parent
5406 -- type, since normally dispatching operations are inherited
5407 -- using the type's Primitive_Operations list.
5409 if Chars (Id) = Name_Op_Eq
5410 and then Is_Dispatching_Operation (Id)
5411 and then Present (Alias (Id))
5412 and then Present (Overridden_Operation (Alias (Id)))
5413 and then Base_Type (Etype (First_Entity (Id))) =
5414 Base_Type (Etype (First_Entity (Alias (Id))))
5418 -- Include the subprogram in the list of primitives
5421 Append_Elmt (Id, Op_List);
5423 -- Save collected equality primitives for later filtering
5424 -- (if we are processing a private type for which we can
5425 -- collect several candidates).
5427 if Inherits_From_Tagged_Full_View (T)
5428 and then Chars (Id) = Name_Op_Eq
5429 and then Etype (First_Formal (Id)) =
5430 Etype (Next_Formal (First_Formal (Id)))
5432 if No (Eq_Prims_List) then
5433 Eq_Prims_List := New_Elmt_List;
5436 Append_Elmt (Id, Eq_Prims_List);
5444 -- For a type declared in System, some of its operations may
5445 -- appear in the target-specific extension to System.
5448 and then B_Scope = RTU_Entity (System)
5449 and then Present_System_Aux
5451 B_Scope := System_Aux_Id;
5452 Id := First_Entity (System_Aux_Id);
5456 -- Filter collected equality primitives
5458 if Inherits_From_Tagged_Full_View (T)
5459 and then Present (Eq_Prims_List)
5462 First : constant Elmt_Id := First_Elmt (Eq_Prims_List);
5466 pragma Assert (No (Next_Elmt (First))
5467 or else No (Next_Elmt (Next_Elmt (First))));
5469 -- No action needed if we have collected a single equality
5472 if Present (Next_Elmt (First)) then
5473 Second := Next_Elmt (First);
5475 if Is_Dispatching_Operation
5476 (Ultimate_Alias (Node (First)))
5478 Remove (Op_List, Node (First));
5480 elsif Is_Dispatching_Operation
5481 (Ultimate_Alias (Node (Second)))
5483 Remove (Op_List, Node (Second));
5486 pragma Assert (False);
5487 raise Program_Error;
5495 end Collect_Primitive_Operations;
5497 -----------------------------------
5498 -- Compile_Time_Constraint_Error --
5499 -----------------------------------
5501 function Compile_Time_Constraint_Error
5504 Ent : Entity_Id := Empty;
5505 Loc : Source_Ptr := No_Location;
5506 Warn : Boolean := False;
5507 Extra_Msg : String := "") return Node_Id
5509 Msgc : String (1 .. Msg'Length + 3);
5510 -- Copy of message, with room for possible ?? or << and ! at end
5516 -- Start of processing for Compile_Time_Constraint_Error
5519 -- If this is a warning, convert it into an error if we are in code
5520 -- subject to SPARK_Mode being set On, unless Warn is True to force a
5521 -- warning. The rationale is that a compile-time constraint error should
5522 -- lead to an error instead of a warning when SPARK_Mode is On, but in
5523 -- a few cases we prefer to issue a warning and generate both a suitable
5524 -- run-time error in GNAT and a suitable check message in GNATprove.
5525 -- Those cases are those that likely correspond to deactivated SPARK
5526 -- code, so that this kind of code can be compiled and analyzed instead
5527 -- of being rejected.
5529 Error_Msg_Warn := Warn or SPARK_Mode /= On;
5531 -- A static constraint error in an instance body is not a fatal error.
5532 -- we choose to inhibit the message altogether, because there is no
5533 -- obvious node (for now) on which to post it. On the other hand the
5534 -- offending node must be replaced with a constraint_error in any case.
5536 -- No messages are generated if we already posted an error on this node
5538 if not Error_Posted (N) then
5539 if Loc /= No_Location then
5545 -- Copy message to Msgc, converting any ? in the message into <
5546 -- instead, so that we have an error in GNATprove mode.
5550 for J in 1 .. Msgl loop
5551 if Msg (J) = '?' and then (J = 1 or else Msg (J - 1) /= ''') then
5554 Msgc (J) := Msg (J);
5558 -- Message is a warning, even in Ada 95 case
5560 if Msg (Msg'Last) = '?' or else Msg (Msg'Last) = '<' then
5563 -- In Ada 83, all messages are warnings. In the private part and the
5564 -- body of an instance, constraint_checks are only warnings. We also
5565 -- make this a warning if the Warn parameter is set.
5568 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
5569 or else In_Instance_Not_Visible
5577 -- Otherwise we have a real error message (Ada 95 static case) and we
5578 -- make this an unconditional message. Note that in the warning case
5579 -- we do not make the message unconditional, it seems reasonable to
5580 -- delete messages like this (about exceptions that will be raised)
5589 -- One more test, skip the warning if the related expression is
5590 -- statically unevaluated, since we don't want to warn about what
5591 -- will happen when something is evaluated if it never will be
5594 if not Is_Statically_Unevaluated (N) then
5595 if Present (Ent) then
5596 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
5598 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
5601 -- Emit any extra message as a continuation
5603 if Extra_Msg /= "" then
5604 Error_Msg_N ('\' & Extra_Msg, N);
5609 -- Check whether the context is an Init_Proc
5611 if Inside_Init_Proc then
5613 Conc_Typ : constant Entity_Id :=
5614 Corresponding_Concurrent_Type
5615 (Entity (Parameter_Type (First
5616 (Parameter_Specifications
5617 (Parent (Current_Scope))))));
5620 -- Don't complain if the corresponding concurrent type
5621 -- doesn't come from source (i.e. a single task/protected
5624 if Present (Conc_Typ)
5625 and then not Comes_From_Source (Conc_Typ)
5628 ("\& [<<", N, Standard_Constraint_Error, Eloc);
5631 if GNATprove_Mode then
5633 ("\& would have been raised for objects of this "
5634 & "type", N, Standard_Constraint_Error, Eloc);
5637 ("\& will be raised for objects of this type??",
5638 N, Standard_Constraint_Error, Eloc);
5644 Error_Msg_NEL ("\& [<<", N, Standard_Constraint_Error, Eloc);
5648 Error_Msg ("\static expression fails Constraint_Check", Eloc);
5649 Set_Error_Posted (N);
5655 end Compile_Time_Constraint_Error;
5657 -----------------------
5658 -- Conditional_Delay --
5659 -----------------------
5661 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
5663 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
5664 Set_Has_Delayed_Freeze (New_Ent);
5666 end Conditional_Delay;
5668 -------------------------
5669 -- Copy_Component_List --
5670 -------------------------
5672 function Copy_Component_List
5674 Loc : Source_Ptr) return List_Id
5677 Comps : constant List_Id := New_List;
5680 Comp := First_Component (Underlying_Type (R_Typ));
5681 while Present (Comp) loop
5682 if Comes_From_Source (Comp) then
5684 Comp_Decl : constant Node_Id := Declaration_Node (Comp);
5687 Make_Component_Declaration (Loc,
5688 Defining_Identifier =>
5689 Make_Defining_Identifier (Loc, Chars (Comp)),
5690 Component_Definition =>
5692 (Component_Definition (Comp_Decl), New_Sloc => Loc)));
5696 Next_Component (Comp);
5700 end Copy_Component_List;
5702 -------------------------
5703 -- Copy_Parameter_List --
5704 -------------------------
5706 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
5707 Loc : constant Source_Ptr := Sloc (Subp_Id);
5712 if No (First_Formal (Subp_Id)) then
5716 Formal := First_Formal (Subp_Id);
5717 while Present (Formal) loop
5719 Make_Parameter_Specification (Loc,
5720 Defining_Identifier =>
5721 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
5722 In_Present => In_Present (Parent (Formal)),
5723 Out_Present => Out_Present (Parent (Formal)),
5725 New_Occurrence_Of (Etype (Formal), Loc),
5727 New_Copy_Tree (Expression (Parent (Formal)))));
5729 Next_Formal (Formal);
5734 end Copy_Parameter_List;
5736 ----------------------------
5737 -- Copy_SPARK_Mode_Aspect --
5738 ----------------------------
5740 procedure Copy_SPARK_Mode_Aspect (From : Node_Id; To : Node_Id) is
5741 pragma Assert (not Has_Aspects (To));
5745 if Has_Aspects (From) then
5746 Asp := Find_Aspect (Defining_Entity (From), Aspect_SPARK_Mode);
5748 if Present (Asp) then
5749 Set_Aspect_Specifications (To, New_List (New_Copy_Tree (Asp)));
5750 Set_Has_Aspects (To, True);
5753 end Copy_SPARK_Mode_Aspect;
5755 --------------------------
5756 -- Copy_Subprogram_Spec --
5757 --------------------------
5759 function Copy_Subprogram_Spec (Spec : Node_Id) return Node_Id is
5761 Formal_Spec : Node_Id;
5765 -- The structure of the original tree must be replicated without any
5766 -- alterations. Use New_Copy_Tree for this purpose.
5768 Result := New_Copy_Tree (Spec);
5770 -- However, the spec of a null procedure carries the corresponding null
5771 -- statement of the body (created by the parser), and this cannot be
5772 -- shared with the new subprogram spec.
5774 if Nkind (Result) = N_Procedure_Specification then
5775 Set_Null_Statement (Result, Empty);
5778 -- Create a new entity for the defining unit name
5780 Def_Id := Defining_Unit_Name (Result);
5781 Set_Defining_Unit_Name (Result,
5782 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
5784 -- Create new entities for the formal parameters
5786 if Present (Parameter_Specifications (Result)) then
5787 Formal_Spec := First (Parameter_Specifications (Result));
5788 while Present (Formal_Spec) loop
5789 Def_Id := Defining_Identifier (Formal_Spec);
5790 Set_Defining_Identifier (Formal_Spec,
5791 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
5798 end Copy_Subprogram_Spec;
5800 --------------------------------
5801 -- Corresponding_Generic_Type --
5802 --------------------------------
5804 function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id is
5810 if not Is_Generic_Actual_Type (T) then
5813 -- If the actual is the actual of an enclosing instance, resolution
5814 -- was correct in the generic.
5816 elsif Nkind (Parent (T)) = N_Subtype_Declaration
5817 and then Is_Entity_Name (Subtype_Indication (Parent (T)))
5819 Is_Generic_Actual_Type (Entity (Subtype_Indication (Parent (T))))
5826 if Is_Wrapper_Package (Inst) then
5827 Inst := Related_Instance (Inst);
5832 (Specification (Unit_Declaration_Node (Inst)));
5834 -- Generic actual has the same name as the corresponding formal
5836 Typ := First_Entity (Gen);
5837 while Present (Typ) loop
5838 if Chars (Typ) = Chars (T) then
5847 end Corresponding_Generic_Type;
5849 --------------------
5850 -- Current_Entity --
5851 --------------------
5853 -- The currently visible definition for a given identifier is the
5854 -- one most chained at the start of the visibility chain, i.e. the
5855 -- one that is referenced by the Node_Id value of the name of the
5856 -- given identifier.
5858 function Current_Entity (N : Node_Id) return Entity_Id is
5860 return Get_Name_Entity_Id (Chars (N));
5863 -----------------------------
5864 -- Current_Entity_In_Scope --
5865 -----------------------------
5867 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
5869 CS : constant Entity_Id := Current_Scope;
5871 Transient_Case : constant Boolean := Scope_Is_Transient;
5874 E := Get_Name_Entity_Id (Chars (N));
5876 and then Scope (E) /= CS
5877 and then (not Transient_Case or else Scope (E) /= Scope (CS))
5883 end Current_Entity_In_Scope;
5889 function Current_Scope return Entity_Id is
5891 if Scope_Stack.Last = -1 then
5892 return Standard_Standard;
5895 C : constant Entity_Id :=
5896 Scope_Stack.Table (Scope_Stack.Last).Entity;
5901 return Standard_Standard;
5907 ----------------------------
5908 -- Current_Scope_No_Loops --
5909 ----------------------------
5911 function Current_Scope_No_Loops return Entity_Id is
5915 -- Examine the scope stack starting from the current scope and skip any
5916 -- internally generated loops.
5919 while Present (S) and then S /= Standard_Standard loop
5920 if Ekind (S) = E_Loop and then not Comes_From_Source (S) then
5928 end Current_Scope_No_Loops;
5930 ------------------------
5931 -- Current_Subprogram --
5932 ------------------------
5934 function Current_Subprogram return Entity_Id is
5935 Scop : constant Entity_Id := Current_Scope;
5937 if Is_Subprogram_Or_Generic_Subprogram (Scop) then
5940 return Enclosing_Subprogram (Scop);
5942 end Current_Subprogram;
5944 ----------------------------------
5945 -- Deepest_Type_Access_Level --
5946 ----------------------------------
5948 function Deepest_Type_Access_Level (Typ : Entity_Id) return Uint is
5950 if Ekind (Typ) = E_Anonymous_Access_Type
5951 and then not Is_Local_Anonymous_Access (Typ)
5952 and then Nkind (Associated_Node_For_Itype (Typ)) = N_Object_Declaration
5954 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
5958 Scope_Depth (Enclosing_Dynamic_Scope
5959 (Defining_Identifier
5960 (Associated_Node_For_Itype (Typ))));
5962 -- For generic formal type, return Int'Last (infinite).
5963 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
5965 elsif Is_Generic_Type (Root_Type (Typ)) then
5966 return UI_From_Int (Int'Last);
5969 return Type_Access_Level (Typ);
5971 end Deepest_Type_Access_Level;
5973 ---------------------
5974 -- Defining_Entity --
5975 ---------------------
5977 function Defining_Entity (N : Node_Id) return Entity_Id is
5980 when N_Abstract_Subprogram_Declaration
5981 | N_Expression_Function
5982 | N_Formal_Subprogram_Declaration
5983 | N_Generic_Package_Declaration
5984 | N_Generic_Subprogram_Declaration
5985 | N_Package_Declaration
5987 | N_Subprogram_Body_Stub
5988 | N_Subprogram_Declaration
5989 | N_Subprogram_Renaming_Declaration
5991 return Defining_Entity (Specification (N));
5993 when N_Component_Declaration
5994 | N_Defining_Program_Unit_Name
5995 | N_Discriminant_Specification
5997 | N_Entry_Declaration
5998 | N_Entry_Index_Specification
5999 | N_Exception_Declaration
6000 | N_Exception_Renaming_Declaration
6001 | N_Formal_Object_Declaration
6002 | N_Formal_Package_Declaration
6003 | N_Formal_Type_Declaration
6004 | N_Full_Type_Declaration
6005 | N_Implicit_Label_Declaration
6006 | N_Incomplete_Type_Declaration
6007 | N_Iterator_Specification
6008 | N_Loop_Parameter_Specification
6009 | N_Number_Declaration
6010 | N_Object_Declaration
6011 | N_Object_Renaming_Declaration
6012 | N_Package_Body_Stub
6013 | N_Parameter_Specification
6014 | N_Private_Extension_Declaration
6015 | N_Private_Type_Declaration
6017 | N_Protected_Body_Stub
6018 | N_Protected_Type_Declaration
6019 | N_Single_Protected_Declaration
6020 | N_Single_Task_Declaration
6021 | N_Subtype_Declaration
6024 | N_Task_Type_Declaration
6026 return Defining_Identifier (N);
6028 when N_Compilation_Unit =>
6029 return Defining_Entity (Unit (N));
6032 return Defining_Entity (Proper_Body (N));
6034 when N_Function_Instantiation
6035 | N_Function_Specification
6036 | N_Generic_Function_Renaming_Declaration
6037 | N_Generic_Package_Renaming_Declaration
6038 | N_Generic_Procedure_Renaming_Declaration
6040 | N_Package_Instantiation
6041 | N_Package_Renaming_Declaration
6042 | N_Package_Specification
6043 | N_Procedure_Instantiation
6044 | N_Procedure_Specification
6047 Nam : constant Node_Id := Defining_Unit_Name (N);
6048 Err : Entity_Id := Empty;
6051 if Nkind (Nam) in N_Entity then
6054 -- For Error, make up a name and attach to declaration so we
6055 -- can continue semantic analysis.
6057 elsif Nam = Error then
6058 Err := Make_Temporary (Sloc (N), 'T');
6059 Set_Defining_Unit_Name (N, Err);
6063 -- If not an entity, get defining identifier
6066 return Defining_Identifier (Nam);
6070 when N_Block_Statement
6073 return Entity (Identifier (N));
6076 raise Program_Error;
6078 end Defining_Entity;
6080 --------------------------
6081 -- Denotes_Discriminant --
6082 --------------------------
6084 function Denotes_Discriminant
6086 Check_Concurrent : Boolean := False) return Boolean
6091 if not Is_Entity_Name (N) or else No (Entity (N)) then
6097 -- If we are checking for a protected type, the discriminant may have
6098 -- been rewritten as the corresponding discriminal of the original type
6099 -- or of the corresponding concurrent record, depending on whether we
6100 -- are in the spec or body of the protected type.
6102 return Ekind (E) = E_Discriminant
6105 and then Ekind (E) = E_In_Parameter
6106 and then Present (Discriminal_Link (E))
6108 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
6110 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
6111 end Denotes_Discriminant;
6113 -------------------------
6114 -- Denotes_Same_Object --
6115 -------------------------
6117 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
6118 function Is_Renaming (N : Node_Id) return Boolean;
6119 -- Return true if N names a renaming entity
6121 function Is_Valid_Renaming (N : Node_Id) return Boolean;
6122 -- For renamings, return False if the prefix of any dereference within
6123 -- the renamed object_name is a variable, or any expression within the
6124 -- renamed object_name contains references to variables or calls on
6125 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
6131 function Is_Renaming (N : Node_Id) return Boolean is
6134 Is_Entity_Name (N) and then Present (Renamed_Entity (Entity (N)));
6137 -----------------------
6138 -- Is_Valid_Renaming --
6139 -----------------------
6141 function Is_Valid_Renaming (N : Node_Id) return Boolean is
6142 function Check_Renaming (N : Node_Id) return Boolean;
6143 -- Recursive function used to traverse all the prefixes of N
6145 --------------------
6146 -- Check_Renaming --
6147 --------------------
6149 function Check_Renaming (N : Node_Id) return Boolean is
6152 and then not Check_Renaming (Renamed_Entity (Entity (N)))
6157 if Nkind (N) = N_Indexed_Component then
6162 Indx := First (Expressions (N));
6163 while Present (Indx) loop
6164 if not Is_OK_Static_Expression (Indx) then
6173 if Has_Prefix (N) then
6175 P : constant Node_Id := Prefix (N);
6178 if Nkind (N) = N_Explicit_Dereference
6179 and then Is_Variable (P)
6183 elsif Is_Entity_Name (P)
6184 and then Ekind (Entity (P)) = E_Function
6188 elsif Nkind (P) = N_Function_Call then
6192 -- Recursion to continue traversing the prefix of the
6193 -- renaming expression
6195 return Check_Renaming (P);
6202 -- Start of processing for Is_Valid_Renaming
6205 return Check_Renaming (N);
6206 end Is_Valid_Renaming;
6210 Obj1 : Node_Id := A1;
6211 Obj2 : Node_Id := A2;
6213 -- Start of processing for Denotes_Same_Object
6216 -- Both names statically denote the same stand-alone object or parameter
6217 -- (RM 6.4.1(6.5/3))
6219 if Is_Entity_Name (Obj1)
6220 and then Is_Entity_Name (Obj2)
6221 and then Entity (Obj1) = Entity (Obj2)
6226 -- For renamings, the prefix of any dereference within the renamed
6227 -- object_name is not a variable, and any expression within the
6228 -- renamed object_name contains no references to variables nor
6229 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
6231 if Is_Renaming (Obj1) then
6232 if Is_Valid_Renaming (Obj1) then
6233 Obj1 := Renamed_Entity (Entity (Obj1));
6239 if Is_Renaming (Obj2) then
6240 if Is_Valid_Renaming (Obj2) then
6241 Obj2 := Renamed_Entity (Entity (Obj2));
6247 -- No match if not same node kind (such cases are handled by
6248 -- Denotes_Same_Prefix)
6250 if Nkind (Obj1) /= Nkind (Obj2) then
6253 -- After handling valid renamings, one of the two names statically
6254 -- denoted a renaming declaration whose renamed object_name is known
6255 -- to denote the same object as the other (RM 6.4.1(6.10/3))
6257 elsif Is_Entity_Name (Obj1) then
6258 if Is_Entity_Name (Obj2) then
6259 return Entity (Obj1) = Entity (Obj2);
6264 -- Both names are selected_components, their prefixes are known to
6265 -- denote the same object, and their selector_names denote the same
6266 -- component (RM 6.4.1(6.6/3)).
6268 elsif Nkind (Obj1) = N_Selected_Component then
6269 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
6271 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
6273 -- Both names are dereferences and the dereferenced names are known to
6274 -- denote the same object (RM 6.4.1(6.7/3))
6276 elsif Nkind (Obj1) = N_Explicit_Dereference then
6277 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
6279 -- Both names are indexed_components, their prefixes are known to denote
6280 -- the same object, and each of the pairs of corresponding index values
6281 -- are either both static expressions with the same static value or both
6282 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
6284 elsif Nkind (Obj1) = N_Indexed_Component then
6285 if not Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
6293 Indx1 := First (Expressions (Obj1));
6294 Indx2 := First (Expressions (Obj2));
6295 while Present (Indx1) loop
6297 -- Indexes must denote the same static value or same object
6299 if Is_OK_Static_Expression (Indx1) then
6300 if not Is_OK_Static_Expression (Indx2) then
6303 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
6307 elsif not Denotes_Same_Object (Indx1, Indx2) then
6319 -- Both names are slices, their prefixes are known to denote the same
6320 -- object, and the two slices have statically matching index constraints
6321 -- (RM 6.4.1(6.9/3))
6323 elsif Nkind (Obj1) = N_Slice
6324 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
6327 Lo1, Lo2, Hi1, Hi2 : Node_Id;
6330 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
6331 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
6333 -- Check whether bounds are statically identical. There is no
6334 -- attempt to detect partial overlap of slices.
6336 return Denotes_Same_Object (Lo1, Lo2)
6338 Denotes_Same_Object (Hi1, Hi2);
6341 -- In the recursion, literals appear as indexes
6343 elsif Nkind (Obj1) = N_Integer_Literal
6345 Nkind (Obj2) = N_Integer_Literal
6347 return Intval (Obj1) = Intval (Obj2);
6352 end Denotes_Same_Object;
6354 -------------------------
6355 -- Denotes_Same_Prefix --
6356 -------------------------
6358 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
6360 if Is_Entity_Name (A1) then
6361 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
6362 and then not Is_Access_Type (Etype (A1))
6364 return Denotes_Same_Object (A1, Prefix (A2))
6365 or else Denotes_Same_Prefix (A1, Prefix (A2));
6370 elsif Is_Entity_Name (A2) then
6371 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
6373 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
6375 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
6378 Root1, Root2 : Node_Id;
6379 Depth1, Depth2 : Nat := 0;
6382 Root1 := Prefix (A1);
6383 while not Is_Entity_Name (Root1) loop
6385 (Root1, N_Selected_Component, N_Indexed_Component)
6389 Root1 := Prefix (Root1);
6392 Depth1 := Depth1 + 1;
6395 Root2 := Prefix (A2);
6396 while not Is_Entity_Name (Root2) loop
6397 if not Nkind_In (Root2, N_Selected_Component,
6398 N_Indexed_Component)
6402 Root2 := Prefix (Root2);
6405 Depth2 := Depth2 + 1;
6408 -- If both have the same depth and they do not denote the same
6409 -- object, they are disjoint and no warning is needed.
6411 if Depth1 = Depth2 then
6414 elsif Depth1 > Depth2 then
6415 Root1 := Prefix (A1);
6416 for J in 1 .. Depth1 - Depth2 - 1 loop
6417 Root1 := Prefix (Root1);
6420 return Denotes_Same_Object (Root1, A2);
6423 Root2 := Prefix (A2);
6424 for J in 1 .. Depth2 - Depth1 - 1 loop
6425 Root2 := Prefix (Root2);
6428 return Denotes_Same_Object (A1, Root2);
6435 end Denotes_Same_Prefix;
6437 ----------------------
6438 -- Denotes_Variable --
6439 ----------------------
6441 function Denotes_Variable (N : Node_Id) return Boolean is
6443 return Is_Variable (N) and then Paren_Count (N) = 0;
6444 end Denotes_Variable;
6446 -----------------------------
6447 -- Depends_On_Discriminant --
6448 -----------------------------
6450 function Depends_On_Discriminant (N : Node_Id) return Boolean is
6455 Get_Index_Bounds (N, L, H);
6456 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
6457 end Depends_On_Discriminant;
6459 -------------------------
6460 -- Designate_Same_Unit --
6461 -------------------------
6463 function Designate_Same_Unit
6465 Name2 : Node_Id) return Boolean
6467 K1 : constant Node_Kind := Nkind (Name1);
6468 K2 : constant Node_Kind := Nkind (Name2);
6470 function Prefix_Node (N : Node_Id) return Node_Id;
6471 -- Returns the parent unit name node of a defining program unit name
6472 -- or the prefix if N is a selected component or an expanded name.
6474 function Select_Node (N : Node_Id) return Node_Id;
6475 -- Returns the defining identifier node of a defining program unit
6476 -- name or the selector node if N is a selected component or an
6483 function Prefix_Node (N : Node_Id) return Node_Id is
6485 if Nkind (N) = N_Defining_Program_Unit_Name then
6496 function Select_Node (N : Node_Id) return Node_Id is
6498 if Nkind (N) = N_Defining_Program_Unit_Name then
6499 return Defining_Identifier (N);
6501 return Selector_Name (N);
6505 -- Start of processing for Designate_Same_Unit
6508 if Nkind_In (K1, N_Identifier, N_Defining_Identifier)
6510 Nkind_In (K2, N_Identifier, N_Defining_Identifier)
6512 return Chars (Name1) = Chars (Name2);
6514 elsif Nkind_In (K1, N_Expanded_Name,
6515 N_Selected_Component,
6516 N_Defining_Program_Unit_Name)
6518 Nkind_In (K2, N_Expanded_Name,
6519 N_Selected_Component,
6520 N_Defining_Program_Unit_Name)
6523 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
6525 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
6530 end Designate_Same_Unit;
6532 ---------------------------------------------
6533 -- Diagnose_Iterated_Component_Association --
6534 ---------------------------------------------
6536 procedure Diagnose_Iterated_Component_Association (N : Node_Id) is
6537 Def_Id : constant Entity_Id := Defining_Identifier (N);
6541 -- Determine whether the iterated component association appears within
6542 -- an aggregate. If this is the case, raise Program_Error because the
6543 -- iterated component association cannot be left in the tree as is and
6544 -- must always be processed by the related aggregate.
6547 while Present (Aggr) loop
6548 if Nkind (Aggr) = N_Aggregate then
6549 raise Program_Error;
6551 -- Prevent the search from going too far
6553 elsif Is_Body_Or_Package_Declaration (Aggr) then
6557 Aggr := Parent (Aggr);
6560 -- At this point it is known that the iterated component association is
6561 -- not within an aggregate. This is really a quantified expression with
6562 -- a missing "all" or "some" quantifier.
6564 Error_Msg_N ("missing quantifier", Def_Id);
6566 -- Rewrite the iterated component association as True to prevent any
6569 Rewrite (N, New_Occurrence_Of (Standard_True, Sloc (N)));
6571 end Diagnose_Iterated_Component_Association;
6573 ---------------------------------
6574 -- Dynamic_Accessibility_Level --
6575 ---------------------------------
6577 function Dynamic_Accessibility_Level (N : Node_Id) return Node_Id is
6578 Loc : constant Source_Ptr := Sloc (N);
6580 function Make_Level_Literal (Level : Uint) return Node_Id;
6581 -- Construct an integer literal representing an accessibility level
6582 -- with its type set to Natural.
6584 ------------------------
6585 -- Make_Level_Literal --
6586 ------------------------
6588 function Make_Level_Literal (Level : Uint) return Node_Id is
6589 Result : constant Node_Id := Make_Integer_Literal (Loc, Level);
6592 Set_Etype (Result, Standard_Natural);
6594 end Make_Level_Literal;
6598 Expr : Node_Id := Original_Node (N);
6599 -- Expr references the original node because at this stage N may be the
6600 -- reference to a variable internally created by the frontend to remove
6601 -- side effects of an expression.
6605 -- Start of processing for Dynamic_Accessibility_Level
6608 if Is_Entity_Name (Expr) then
6611 if Present (Renamed_Object (E)) then
6612 return Dynamic_Accessibility_Level (Renamed_Object (E));
6616 or else Ekind_In (E, E_Variable, E_Constant))
6617 and then Present (Get_Accessibility (E))
6619 return New_Occurrence_Of (Get_Accessibility (E), Loc);
6623 -- Handle a constant-folded conditional expression by avoiding use of
6624 -- the original node.
6626 if Nkind_In (Expr, N_Case_Expression, N_If_Expression) then
6630 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
6632 case Nkind (Expr) is
6633 -- It may be possible that we have an access object denoted by an
6634 -- attribute reference for 'Loop_Entry which may, in turn, have an
6635 -- indexed component representing a loop identifier.
6637 -- In this case we must climb up the indexed component and set expr
6638 -- to the attribute reference so the rest of the machinery can
6639 -- operate as expected.
6641 when N_Indexed_Component =>
6642 if Nkind (Prefix (Expr)) = N_Attribute_Reference
6643 and then Get_Attribute_Id (Attribute_Name (Prefix (Expr)))
6644 = Attribute_Loop_Entry
6646 Expr := Prefix (Expr);
6649 -- For access discriminant, the level of the enclosing object
6651 when N_Selected_Component =>
6652 if Ekind (Entity (Selector_Name (Expr))) = E_Discriminant
6653 and then Ekind (Etype (Entity (Selector_Name (Expr)))) =
6654 E_Anonymous_Access_Type
6656 return Make_Level_Literal (Object_Access_Level (Expr));
6659 when N_Attribute_Reference =>
6660 case Get_Attribute_Id (Attribute_Name (Expr)) is
6662 -- Ignore 'Loop_Entry, 'Result, and 'Old as they can be used to
6663 -- identify access objects and do not have an effect on
6664 -- accessibility level.
6666 when Attribute_Loop_Entry | Attribute_Old | Attribute_Result =>
6669 -- For X'Access, the level of the prefix X
6671 when Attribute_Access =>
6672 return Make_Level_Literal
6673 (Object_Access_Level (Prefix (Expr)));
6675 -- Treat the unchecked attributes as library-level
6677 when Attribute_Unchecked_Access
6678 | Attribute_Unrestricted_Access
6680 return Make_Level_Literal (Scope_Depth (Standard_Standard));
6682 -- No other access-valued attributes
6685 raise Program_Error;
6690 -- This is not fully implemented since it depends on context (see
6691 -- 3.10.2(14/3-14.2/3). More work is needed in the following cases
6693 -- 1) For an anonymous allocator defining the value of an access
6694 -- parameter, the accessibility level is that of the innermost
6695 -- master of the call; however currently we pass the level of
6696 -- execution of the called subprogram, which is one greater
6697 -- than the current scope level (see Expand_Call_Helper).
6699 -- For example, a statement is a master and a declaration is
6700 -- not a master; so we should not pass in the same level for
6701 -- the following cases:
6703 -- function F (X : access Integer) return T is ... ;
6704 -- Decl : T := F (new Integer); -- level is off by one
6706 -- Decl := F (new Integer); -- we get this case right
6708 -- 2) For an anonymous allocator that defines the result of a
6709 -- function with an access result, the accessibility level is
6710 -- determined as though the allocator were in place of the call
6711 -- of the function. In the special case of a call that is the
6712 -- operand of a type conversion the level is that of the target
6713 -- access type of the conversion.
6715 -- 3) For an anonymous allocator defining an access discriminant
6716 -- the accessibility level is determined as follows:
6717 -- * for an allocator used to define the discriminant of an
6718 -- object, the level of the object
6719 -- * for an allocator used to define the constraint in a
6720 -- subtype_indication in any other context, the level of
6721 -- the master that elaborates the subtype_indication.
6723 case Nkind (Parent (N)) is
6724 when N_Object_Declaration =>
6726 -- For an anonymous allocator whose type is that of a
6727 -- stand-alone object of an anonymous access-to-object type,
6728 -- the accessibility level is that of the declaration of the
6729 -- stand-alone object.
6733 (Object_Access_Level
6734 (Defining_Identifier (Parent (N))));
6736 when N_Assignment_Statement =>
6739 (Object_Access_Level (Name (Parent (N))));
6743 S : constant String :=
6744 Node_Kind'Image (Nkind (Parent (N)));
6746 Error_Msg_Strlen := S'Length;
6747 Error_Msg_String (1 .. Error_Msg_Strlen) := S;
6749 ("unsupported context for anonymous allocator (~)",
6754 when N_Type_Conversion =>
6755 if not Is_Local_Anonymous_Access (Etype (Expr)) then
6757 -- Handle type conversions introduced for a rename of an
6758 -- Ada 2012 stand-alone object of an anonymous access type.
6760 return Dynamic_Accessibility_Level (Expression (Expr));
6767 return Make_Level_Literal (Type_Access_Level (Etype (Expr)));
6768 end Dynamic_Accessibility_Level;
6770 ------------------------
6771 -- Discriminated_Size --
6772 ------------------------
6774 function Discriminated_Size (Comp : Entity_Id) return Boolean is
6775 function Non_Static_Bound (Bound : Node_Id) return Boolean;
6776 -- Check whether the bound of an index is non-static and does denote
6777 -- a discriminant, in which case any object of the type (protected or
6778 -- otherwise) will have a non-static size.
6780 ----------------------
6781 -- Non_Static_Bound --
6782 ----------------------
6784 function Non_Static_Bound (Bound : Node_Id) return Boolean is
6786 if Is_OK_Static_Expression (Bound) then
6789 -- If the bound is given by a discriminant it is non-static
6790 -- (A static constraint replaces the reference with the value).
6791 -- In an protected object the discriminant has been replaced by
6792 -- the corresponding discriminal within the protected operation.
6794 elsif Is_Entity_Name (Bound)
6796 (Ekind (Entity (Bound)) = E_Discriminant
6797 or else Present (Discriminal_Link (Entity (Bound))))
6804 end Non_Static_Bound;
6808 Typ : constant Entity_Id := Etype (Comp);
6811 -- Start of processing for Discriminated_Size
6814 if not Is_Array_Type (Typ) then
6818 if Ekind (Typ) = E_Array_Subtype then
6819 Index := First_Index (Typ);
6820 while Present (Index) loop
6821 if Non_Static_Bound (Low_Bound (Index))
6822 or else Non_Static_Bound (High_Bound (Index))
6834 end Discriminated_Size;
6836 -----------------------------------
6837 -- Effective_Extra_Accessibility --
6838 -----------------------------------
6840 function Effective_Extra_Accessibility (Id : Entity_Id) return Entity_Id is
6842 if Present (Renamed_Object (Id))
6843 and then Is_Entity_Name (Renamed_Object (Id))
6845 return Effective_Extra_Accessibility (Entity (Renamed_Object (Id)));
6847 return Extra_Accessibility (Id);
6849 end Effective_Extra_Accessibility;
6851 -----------------------------
6852 -- Effective_Reads_Enabled --
6853 -----------------------------
6855 function Effective_Reads_Enabled (Id : Entity_Id) return Boolean is
6857 return Has_Enabled_Property (Id, Name_Effective_Reads);
6858 end Effective_Reads_Enabled;
6860 ------------------------------
6861 -- Effective_Writes_Enabled --
6862 ------------------------------
6864 function Effective_Writes_Enabled (Id : Entity_Id) return Boolean is
6866 return Has_Enabled_Property (Id, Name_Effective_Writes);
6867 end Effective_Writes_Enabled;
6869 ------------------------------
6870 -- Enclosing_Comp_Unit_Node --
6871 ------------------------------
6873 function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id is
6874 Current_Node : Node_Id;
6878 while Present (Current_Node)
6879 and then Nkind (Current_Node) /= N_Compilation_Unit
6881 Current_Node := Parent (Current_Node);
6884 if Nkind (Current_Node) /= N_Compilation_Unit then
6887 return Current_Node;
6889 end Enclosing_Comp_Unit_Node;
6891 --------------------------
6892 -- Enclosing_CPP_Parent --
6893 --------------------------
6895 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
6896 Parent_Typ : Entity_Id := Typ;
6899 while not Is_CPP_Class (Parent_Typ)
6900 and then Etype (Parent_Typ) /= Parent_Typ
6902 Parent_Typ := Etype (Parent_Typ);
6904 if Is_Private_Type (Parent_Typ) then
6905 Parent_Typ := Full_View (Base_Type (Parent_Typ));
6909 pragma Assert (Is_CPP_Class (Parent_Typ));
6911 end Enclosing_CPP_Parent;
6913 ---------------------------
6914 -- Enclosing_Declaration --
6915 ---------------------------
6917 function Enclosing_Declaration (N : Node_Id) return Node_Id is
6918 Decl : Node_Id := N;
6921 while Present (Decl)
6922 and then not (Nkind (Decl) in N_Declaration
6924 Nkind (Decl) in N_Later_Decl_Item
6926 Nkind (Decl) = N_Number_Declaration)
6928 Decl := Parent (Decl);
6932 end Enclosing_Declaration;
6934 ----------------------------
6935 -- Enclosing_Generic_Body --
6936 ----------------------------
6938 function Enclosing_Generic_Body (N : Node_Id) return Node_Id is
6940 Spec_Id : Entity_Id;
6944 while Present (Par) loop
6945 if Nkind_In (Par, N_Package_Body, N_Subprogram_Body) then
6946 Spec_Id := Corresponding_Spec (Par);
6948 if Present (Spec_Id)
6949 and then Nkind_In (Unit_Declaration_Node (Spec_Id),
6950 N_Generic_Package_Declaration,
6951 N_Generic_Subprogram_Declaration)
6957 Par := Parent (Par);
6961 end Enclosing_Generic_Body;
6963 ----------------------------
6964 -- Enclosing_Generic_Unit --
6965 ----------------------------
6967 function Enclosing_Generic_Unit (N : Node_Id) return Node_Id is
6969 Spec_Decl : Node_Id;
6970 Spec_Id : Entity_Id;
6974 while Present (Par) loop
6975 if Nkind_In (Par, N_Generic_Package_Declaration,
6976 N_Generic_Subprogram_Declaration)
6980 elsif Nkind_In (Par, N_Package_Body, N_Subprogram_Body) then
6981 Spec_Id := Corresponding_Spec (Par);
6983 if Present (Spec_Id) then
6984 Spec_Decl := Unit_Declaration_Node (Spec_Id);
6986 if Nkind_In (Spec_Decl, N_Generic_Package_Declaration,
6987 N_Generic_Subprogram_Declaration)
6994 Par := Parent (Par);
6998 end Enclosing_Generic_Unit;
7000 -------------------------------
7001 -- Enclosing_Lib_Unit_Entity --
7002 -------------------------------
7004 function Enclosing_Lib_Unit_Entity
7005 (E : Entity_Id := Current_Scope) return Entity_Id
7007 Unit_Entity : Entity_Id;
7010 -- Look for enclosing library unit entity by following scope links.
7011 -- Equivalent to, but faster than indexing through the scope stack.
7014 while (Present (Scope (Unit_Entity))
7015 and then Scope (Unit_Entity) /= Standard_Standard)
7016 and not Is_Child_Unit (Unit_Entity)
7018 Unit_Entity := Scope (Unit_Entity);
7022 end Enclosing_Lib_Unit_Entity;
7024 -----------------------------
7025 -- Enclosing_Lib_Unit_Node --
7026 -----------------------------
7028 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
7029 Encl_Unit : Node_Id;
7032 Encl_Unit := Enclosing_Comp_Unit_Node (N);
7033 while Present (Encl_Unit)
7034 and then Nkind (Unit (Encl_Unit)) = N_Subunit
7036 Encl_Unit := Library_Unit (Encl_Unit);
7039 pragma Assert (Nkind (Encl_Unit) = N_Compilation_Unit);
7041 end Enclosing_Lib_Unit_Node;
7043 -----------------------
7044 -- Enclosing_Package --
7045 -----------------------
7047 function Enclosing_Package (E : Entity_Id) return Entity_Id is
7048 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
7051 if Dynamic_Scope = Standard_Standard then
7052 return Standard_Standard;
7054 elsif Dynamic_Scope = Empty then
7057 elsif Ekind_In (Dynamic_Scope, E_Generic_Package,
7061 return Dynamic_Scope;
7064 return Enclosing_Package (Dynamic_Scope);
7066 end Enclosing_Package;
7068 -------------------------------------
7069 -- Enclosing_Package_Or_Subprogram --
7070 -------------------------------------
7072 function Enclosing_Package_Or_Subprogram (E : Entity_Id) return Entity_Id is
7077 while Present (S) loop
7078 if Is_Package_Or_Generic_Package (S)
7079 or else Is_Subprogram_Or_Generic_Subprogram (S)
7089 end Enclosing_Package_Or_Subprogram;
7091 --------------------------
7092 -- Enclosing_Subprogram --
7093 --------------------------
7095 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
7096 Dyn_Scop : constant Entity_Id := Enclosing_Dynamic_Scope (E);
7099 if Dyn_Scop = Standard_Standard then
7102 elsif Dyn_Scop = Empty then
7105 elsif Ekind (Dyn_Scop) = E_Subprogram_Body then
7106 return Corresponding_Spec (Parent (Parent (Dyn_Scop)));
7108 elsif Ekind_In (Dyn_Scop, E_Block, E_Loop, E_Return_Statement) then
7109 return Enclosing_Subprogram (Dyn_Scop);
7111 elsif Ekind_In (Dyn_Scop, E_Entry, E_Entry_Family) then
7113 -- For a task entry or entry family, return the enclosing subprogram
7114 -- of the task itself.
7116 if Ekind (Scope (Dyn_Scop)) = E_Task_Type then
7117 return Enclosing_Subprogram (Dyn_Scop);
7119 -- A protected entry or entry family is rewritten as a protected
7120 -- procedure which is the desired enclosing subprogram. This is
7121 -- relevant when unnesting a procedure local to an entry body.
7124 return Protected_Body_Subprogram (Dyn_Scop);
7127 elsif Ekind (Dyn_Scop) = E_Task_Type then
7128 return Get_Task_Body_Procedure (Dyn_Scop);
7130 -- The scope may appear as a private type or as a private extension
7131 -- whose completion is a task or protected type.
7133 elsif Ekind_In (Dyn_Scop, E_Limited_Private_Type,
7134 E_Record_Type_With_Private)
7135 and then Present (Full_View (Dyn_Scop))
7136 and then Ekind_In (Full_View (Dyn_Scop), E_Task_Type, E_Protected_Type)
7138 return Get_Task_Body_Procedure (Full_View (Dyn_Scop));
7140 -- No body is generated if the protected operation is eliminated
7142 elsif Convention (Dyn_Scop) = Convention_Protected
7143 and then not Is_Eliminated (Dyn_Scop)
7144 and then Present (Protected_Body_Subprogram (Dyn_Scop))
7146 return Protected_Body_Subprogram (Dyn_Scop);
7151 end Enclosing_Subprogram;
7153 --------------------------
7154 -- End_Keyword_Location --
7155 --------------------------
7157 function End_Keyword_Location (N : Node_Id) return Source_Ptr is
7158 function End_Label_Loc (Nod : Node_Id) return Source_Ptr;
7159 -- Return the source location of Nod's end label according to the
7160 -- following precedence rules:
7162 -- 1) If the end label exists, return its location
7163 -- 2) If Nod exists, return its location
7164 -- 3) Return the location of N
7170 function End_Label_Loc (Nod : Node_Id) return Source_Ptr is
7174 if Present (Nod) then
7175 Label := End_Label (Nod);
7177 if Present (Label) then
7178 return Sloc (Label);
7192 -- Start of processing for End_Keyword_Location
7195 if Nkind_In (N, N_Block_Statement,
7201 Owner := Handled_Statement_Sequence (N);
7203 elsif Nkind (N) = N_Package_Declaration then
7204 Owner := Specification (N);
7206 elsif Nkind (N) = N_Protected_Body then
7209 elsif Nkind_In (N, N_Protected_Type_Declaration,
7210 N_Single_Protected_Declaration)
7212 Owner := Protected_Definition (N);
7214 elsif Nkind_In (N, N_Single_Task_Declaration,
7215 N_Task_Type_Declaration)
7217 Owner := Task_Definition (N);
7219 -- This routine should not be called with other contexts
7222 pragma Assert (False);
7226 return End_Label_Loc (Owner);
7227 end End_Keyword_Location;
7229 ------------------------
7230 -- Ensure_Freeze_Node --
7231 ------------------------
7233 procedure Ensure_Freeze_Node (E : Entity_Id) is
7236 if No (Freeze_Node (E)) then
7237 FN := Make_Freeze_Entity (Sloc (E));
7238 Set_Has_Delayed_Freeze (E);
7239 Set_Freeze_Node (E, FN);
7240 Set_Access_Types_To_Process (FN, No_Elist);
7241 Set_TSS_Elist (FN, No_Elist);
7244 end Ensure_Freeze_Node;
7250 procedure Enter_Name (Def_Id : Entity_Id) is
7251 C : constant Entity_Id := Current_Entity (Def_Id);
7252 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
7253 S : constant Entity_Id := Current_Scope;
7256 Generate_Definition (Def_Id);
7258 -- Add new name to current scope declarations. Check for duplicate
7259 -- declaration, which may or may not be a genuine error.
7263 -- Case of previous entity entered because of a missing declaration
7264 -- or else a bad subtype indication. Best is to use the new entity,
7265 -- and make the previous one invisible.
7267 if Etype (E) = Any_Type then
7268 Set_Is_Immediately_Visible (E, False);
7270 -- Case of renaming declaration constructed for package instances.
7271 -- if there is an explicit declaration with the same identifier,
7272 -- the renaming is not immediately visible any longer, but remains
7273 -- visible through selected component notation.
7275 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
7276 and then not Comes_From_Source (E)
7278 Set_Is_Immediately_Visible (E, False);
7280 -- The new entity may be the package renaming, which has the same
7281 -- same name as a generic formal which has been seen already.
7283 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
7284 and then not Comes_From_Source (Def_Id)
7286 Set_Is_Immediately_Visible (E, False);
7288 -- For a fat pointer corresponding to a remote access to subprogram,
7289 -- we use the same identifier as the RAS type, so that the proper
7290 -- name appears in the stub. This type is only retrieved through
7291 -- the RAS type and never by visibility, and is not added to the
7292 -- visibility list (see below).
7294 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
7295 and then Ekind (Def_Id) = E_Record_Type
7296 and then Present (Corresponding_Remote_Type (Def_Id))
7300 -- Case of an implicit operation or derived literal. The new entity
7301 -- hides the implicit one, which is removed from all visibility,
7302 -- i.e. the entity list of its scope, and homonym chain of its name.
7304 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
7305 or else Is_Internal (E)
7308 Decl : constant Node_Id := Parent (E);
7310 Prev_Vis : Entity_Id;
7313 -- If E is an implicit declaration, it cannot be the first
7314 -- entity in the scope.
7316 Prev := First_Entity (Current_Scope);
7317 while Present (Prev) and then Next_Entity (Prev) /= E loop
7323 -- If E is not on the entity chain of the current scope,
7324 -- it is an implicit declaration in the generic formal
7325 -- part of a generic subprogram. When analyzing the body,
7326 -- the generic formals are visible but not on the entity
7327 -- chain of the subprogram. The new entity will become
7328 -- the visible one in the body.
7331 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
7335 Link_Entities (Prev, Next_Entity (E));
7337 if No (Next_Entity (Prev)) then
7338 Set_Last_Entity (Current_Scope, Prev);
7341 if E = Current_Entity (E) then
7345 Prev_Vis := Current_Entity (E);
7346 while Homonym (Prev_Vis) /= E loop
7347 Prev_Vis := Homonym (Prev_Vis);
7351 if Present (Prev_Vis) then
7353 -- Skip E in the visibility chain
7355 Set_Homonym (Prev_Vis, Homonym (E));
7358 Set_Name_Entity_Id (Chars (E), Homonym (E));
7363 -- This section of code could use a comment ???
7365 elsif Present (Etype (E))
7366 and then Is_Concurrent_Type (Etype (E))
7371 -- If the homograph is a protected component renaming, it should not
7372 -- be hiding the current entity. Such renamings are treated as weak
7375 elsif Is_Prival (E) then
7376 Set_Is_Immediately_Visible (E, False);
7378 -- In this case the current entity is a protected component renaming.
7379 -- Perform minimal decoration by setting the scope and return since
7380 -- the prival should not be hiding other visible entities.
7382 elsif Is_Prival (Def_Id) then
7383 Set_Scope (Def_Id, Current_Scope);
7386 -- Analogous to privals, the discriminal generated for an entry index
7387 -- parameter acts as a weak declaration. Perform minimal decoration
7388 -- to avoid bogus errors.
7390 elsif Is_Discriminal (Def_Id)
7391 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
7393 Set_Scope (Def_Id, Current_Scope);
7396 -- In the body or private part of an instance, a type extension may
7397 -- introduce a component with the same name as that of an actual. The
7398 -- legality rule is not enforced, but the semantics of the full type
7399 -- with two components of same name are not clear at this point???
7401 elsif In_Instance_Not_Visible then
7404 -- When compiling a package body, some child units may have become
7405 -- visible. They cannot conflict with local entities that hide them.
7407 elsif Is_Child_Unit (E)
7408 and then In_Open_Scopes (Scope (E))
7409 and then not Is_Immediately_Visible (E)
7413 -- Conversely, with front-end inlining we may compile the parent body
7414 -- first, and a child unit subsequently. The context is now the
7415 -- parent spec, and body entities are not visible.
7417 elsif Is_Child_Unit (Def_Id)
7418 and then Is_Package_Body_Entity (E)
7419 and then not In_Package_Body (Current_Scope)
7423 -- Case of genuine duplicate declaration
7426 Error_Msg_Sloc := Sloc (E);
7428 -- If the previous declaration is an incomplete type declaration
7429 -- this may be an attempt to complete it with a private type. The
7430 -- following avoids confusing cascaded errors.
7432 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
7433 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
7436 ("incomplete type cannot be completed with a private " &
7437 "declaration", Parent (Def_Id));
7438 Set_Is_Immediately_Visible (E, False);
7439 Set_Full_View (E, Def_Id);
7441 -- An inherited component of a record conflicts with a new
7442 -- discriminant. The discriminant is inserted first in the scope,
7443 -- but the error should be posted on it, not on the component.
7445 elsif Ekind (E) = E_Discriminant
7446 and then Present (Scope (Def_Id))
7447 and then Scope (Def_Id) /= Current_Scope
7449 Error_Msg_Sloc := Sloc (Def_Id);
7450 Error_Msg_N ("& conflicts with declaration#", E);
7453 -- If the name of the unit appears in its own context clause, a
7454 -- dummy package with the name has already been created, and the
7455 -- error emitted. Try to continue quietly.
7457 elsif Error_Posted (E)
7458 and then Sloc (E) = No_Location
7459 and then Nkind (Parent (E)) = N_Package_Specification
7460 and then Current_Scope = Standard_Standard
7462 Set_Scope (Def_Id, Current_Scope);
7466 Error_Msg_N ("& conflicts with declaration#", Def_Id);
7468 -- Avoid cascaded messages with duplicate components in
7471 if Ekind_In (E, E_Component, E_Discriminant) then
7476 if Nkind (Parent (Parent (Def_Id))) =
7477 N_Generic_Subprogram_Declaration
7479 Defining_Entity (Specification (Parent (Parent (Def_Id))))
7481 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
7484 -- If entity is in standard, then we are in trouble, because it
7485 -- means that we have a library package with a duplicated name.
7486 -- That's hard to recover from, so abort.
7488 if S = Standard_Standard then
7489 raise Unrecoverable_Error;
7491 -- Otherwise we continue with the declaration. Having two
7492 -- identical declarations should not cause us too much trouble.
7500 -- If we fall through, declaration is OK, at least OK enough to continue
7502 -- If Def_Id is a discriminant or a record component we are in the midst
7503 -- of inheriting components in a derived record definition. Preserve
7504 -- their Ekind and Etype.
7506 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
7509 -- If a type is already set, leave it alone (happens when a type
7510 -- declaration is reanalyzed following a call to the optimizer).
7512 elsif Present (Etype (Def_Id)) then
7515 -- Otherwise, the kind E_Void insures that premature uses of the entity
7516 -- will be detected. Any_Type insures that no cascaded errors will occur
7519 Set_Ekind (Def_Id, E_Void);
7520 Set_Etype (Def_Id, Any_Type);
7523 -- Inherited discriminants and components in derived record types are
7524 -- immediately visible. Itypes are not.
7526 -- Unless the Itype is for a record type with a corresponding remote
7527 -- type (what is that about, it was not commented ???)
7529 if Ekind_In (Def_Id, E_Discriminant, E_Component)
7531 ((not Is_Record_Type (Def_Id)
7532 or else No (Corresponding_Remote_Type (Def_Id)))
7533 and then not Is_Itype (Def_Id))
7535 Set_Is_Immediately_Visible (Def_Id);
7536 Set_Current_Entity (Def_Id);
7539 Set_Homonym (Def_Id, C);
7540 Append_Entity (Def_Id, S);
7541 Set_Public_Status (Def_Id);
7543 -- Declaring a homonym is not allowed in SPARK ...
7545 if Present (C) and then Restriction_Check_Required (SPARK_05) then
7547 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
7548 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
7549 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
7552 -- ... unless the new declaration is in a subprogram, and the
7553 -- visible declaration is a variable declaration or a parameter
7554 -- specification outside that subprogram.
7556 if Present (Enclosing_Subp)
7557 and then Nkind_In (Parent (C), N_Object_Declaration,
7558 N_Parameter_Specification)
7559 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
7563 -- ... or the new declaration is in a package, and the visible
7564 -- declaration occurs outside that package.
7566 elsif Present (Enclosing_Pack)
7567 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
7571 -- ... or the new declaration is a component declaration in a
7572 -- record type definition.
7574 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
7577 -- Don't issue error for non-source entities
7579 elsif Comes_From_Source (Def_Id)
7580 and then Comes_From_Source (C)
7582 Error_Msg_Sloc := Sloc (C);
7583 Check_SPARK_05_Restriction
7584 ("redeclaration of identifier &#", Def_Id);
7589 -- Warn if new entity hides an old one
7591 if Warn_On_Hiding and then Present (C)
7593 -- Don't warn for record components since they always have a well
7594 -- defined scope which does not confuse other uses. Note that in
7595 -- some cases, Ekind has not been set yet.
7597 and then Ekind (C) /= E_Component
7598 and then Ekind (C) /= E_Discriminant
7599 and then Nkind (Parent (C)) /= N_Component_Declaration
7600 and then Ekind (Def_Id) /= E_Component
7601 and then Ekind (Def_Id) /= E_Discriminant
7602 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
7604 -- Don't warn for one character variables. It is too common to use
7605 -- such variables as locals and will just cause too many false hits.
7607 and then Length_Of_Name (Chars (C)) /= 1
7609 -- Don't warn for non-source entities
7611 and then Comes_From_Source (C)
7612 and then Comes_From_Source (Def_Id)
7614 -- Don't warn unless entity in question is in extended main source
7616 and then In_Extended_Main_Source_Unit (Def_Id)
7618 -- Finally, the hidden entity must be either immediately visible or
7619 -- use visible (i.e. from a used package).
7622 (Is_Immediately_Visible (C)
7624 Is_Potentially_Use_Visible (C))
7626 Error_Msg_Sloc := Sloc (C);
7627 Error_Msg_N ("declaration hides &#?h?", Def_Id);
7635 function Entity_Of (N : Node_Id) return Entity_Id is
7640 -- Assume that the arbitrary node does not have an entity
7644 if Is_Entity_Name (N) then
7647 -- Follow a possible chain of renamings to reach the earliest renamed
7651 and then Is_Object (Id)
7652 and then Present (Renamed_Object (Id))
7654 Ren := Renamed_Object (Id);
7656 -- The reference renames an abstract state or a whole object
7659 -- Ren : ... renames Obj;
7661 if Is_Entity_Name (Ren) then
7663 -- Do not follow a renaming that goes through a generic formal,
7664 -- because these entities are hidden and must not be referenced
7665 -- from outside the generic.
7667 if Is_Hidden (Entity (Ren)) then
7674 -- The reference renames a function result. Check the original
7675 -- node in case expansion relocates the function call.
7677 -- Ren : ... renames Func_Call;
7679 elsif Nkind (Original_Node (Ren)) = N_Function_Call then
7682 -- Otherwise the reference renames something which does not yield
7683 -- an abstract state or a whole object. Treat the reference as not
7684 -- having a proper entity for SPARK legality purposes.
7696 --------------------------
7697 -- Examine_Array_Bounds --
7698 --------------------------
7700 procedure Examine_Array_Bounds
7702 All_Static : out Boolean;
7703 Has_Empty : out Boolean)
7705 function Is_OK_Static_Bound (Bound : Node_Id) return Boolean;
7706 -- Determine whether bound Bound is a suitable static bound
7708 ------------------------
7709 -- Is_OK_Static_Bound --
7710 ------------------------
7712 function Is_OK_Static_Bound (Bound : Node_Id) return Boolean is
7715 not Error_Posted (Bound)
7716 and then Is_OK_Static_Expression (Bound);
7717 end Is_OK_Static_Bound;
7725 -- Start of processing for Examine_Array_Bounds
7728 -- An unconstrained array type does not have static bounds, and it is
7729 -- not known whether they are empty or not.
7731 if not Is_Constrained (Typ) then
7732 All_Static := False;
7735 -- A string literal has static bounds, and is not empty as long as it
7736 -- contains at least one character.
7738 elsif Ekind (Typ) = E_String_Literal_Subtype then
7740 Has_Empty := String_Literal_Length (Typ) > 0;
7743 -- Assume that all bounds are static and not empty
7748 -- Examine each index
7750 Index := First_Index (Typ);
7751 while Present (Index) loop
7752 if Is_Discrete_Type (Etype (Index)) then
7753 Get_Index_Bounds (Index, Lo_Bound, Hi_Bound);
7755 if Is_OK_Static_Bound (Lo_Bound)
7757 Is_OK_Static_Bound (Hi_Bound)
7759 -- The static bounds produce an empty range
7761 if Is_Null_Range (Lo_Bound, Hi_Bound) then
7765 -- Otherwise at least one of the bounds is not static
7768 All_Static := False;
7771 -- Otherwise the index is non-discrete, therefore not static
7774 All_Static := False;
7779 end Examine_Array_Bounds;
7785 function Exceptions_OK return Boolean is
7788 not (Restriction_Active (No_Exception_Handlers) or else
7789 Restriction_Active (No_Exception_Propagation) or else
7790 Restriction_Active (No_Exceptions));
7793 --------------------------
7794 -- Explain_Limited_Type --
7795 --------------------------
7797 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
7801 -- For array, component type must be limited
7803 if Is_Array_Type (T) then
7804 Error_Msg_Node_2 := T;
7806 ("\component type& of type& is limited", N, Component_Type (T));
7807 Explain_Limited_Type (Component_Type (T), N);
7809 elsif Is_Record_Type (T) then
7811 -- No need for extra messages if explicit limited record
7813 if Is_Limited_Record (Base_Type (T)) then
7817 -- Otherwise find a limited component. Check only components that
7818 -- come from source, or inherited components that appear in the
7819 -- source of the ancestor.
7821 C := First_Component (T);
7822 while Present (C) loop
7823 if Is_Limited_Type (Etype (C))
7825 (Comes_From_Source (C)
7827 (Present (Original_Record_Component (C))
7829 Comes_From_Source (Original_Record_Component (C))))
7831 Error_Msg_Node_2 := T;
7832 Error_Msg_NE ("\component& of type& has limited type", N, C);
7833 Explain_Limited_Type (Etype (C), N);
7840 -- The type may be declared explicitly limited, even if no component
7841 -- of it is limited, in which case we fall out of the loop.
7844 end Explain_Limited_Type;
7846 ---------------------------------------
7847 -- Expression_Of_Expression_Function --
7848 ---------------------------------------
7850 function Expression_Of_Expression_Function
7851 (Subp : Entity_Id) return Node_Id
7853 Expr_Func : Node_Id;
7856 pragma Assert (Is_Expression_Function_Or_Completion (Subp));
7858 if Nkind (Original_Node (Subprogram_Spec (Subp))) =
7859 N_Expression_Function
7861 Expr_Func := Original_Node (Subprogram_Spec (Subp));
7863 elsif Nkind (Original_Node (Subprogram_Body (Subp))) =
7864 N_Expression_Function
7866 Expr_Func := Original_Node (Subprogram_Body (Subp));
7869 pragma Assert (False);
7873 return Original_Node (Expression (Expr_Func));
7874 end Expression_Of_Expression_Function;
7876 -------------------------------
7877 -- Extensions_Visible_Status --
7878 -------------------------------
7880 function Extensions_Visible_Status
7881 (Id : Entity_Id) return Extensions_Visible_Mode
7890 -- When a formal parameter is subject to Extensions_Visible, the pragma
7891 -- is stored in the contract of related subprogram.
7893 if Is_Formal (Id) then
7896 elsif Is_Subprogram_Or_Generic_Subprogram (Id) then
7899 -- No other construct carries this pragma
7902 return Extensions_Visible_None;
7905 Prag := Get_Pragma (Subp, Pragma_Extensions_Visible);
7907 -- In certain cases analysis may request the Extensions_Visible status
7908 -- of an expression function before the pragma has been analyzed yet.
7909 -- Inspect the declarative items after the expression function looking
7910 -- for the pragma (if any).
7912 if No (Prag) and then Is_Expression_Function (Subp) then
7913 Decl := Next (Unit_Declaration_Node (Subp));
7914 while Present (Decl) loop
7915 if Nkind (Decl) = N_Pragma
7916 and then Pragma_Name (Decl) = Name_Extensions_Visible
7921 -- A source construct ends the region where Extensions_Visible may
7922 -- appear, stop the traversal. An expanded expression function is
7923 -- no longer a source construct, but it must still be recognized.
7925 elsif Comes_From_Source (Decl)
7927 (Nkind_In (Decl, N_Subprogram_Body,
7928 N_Subprogram_Declaration)
7929 and then Is_Expression_Function (Defining_Entity (Decl)))
7938 -- Extract the value from the Boolean expression (if any)
7940 if Present (Prag) then
7941 Arg := First (Pragma_Argument_Associations (Prag));
7943 if Present (Arg) then
7944 Expr := Get_Pragma_Arg (Arg);
7946 -- When the associated subprogram is an expression function, the
7947 -- argument of the pragma may not have been analyzed.
7949 if not Analyzed (Expr) then
7950 Preanalyze_And_Resolve (Expr, Standard_Boolean);
7953 -- Guard against cascading errors when the argument of pragma
7954 -- Extensions_Visible is not a valid static Boolean expression.
7956 if Error_Posted (Expr) then
7957 return Extensions_Visible_None;
7959 elsif Is_True (Expr_Value (Expr)) then
7960 return Extensions_Visible_True;
7963 return Extensions_Visible_False;
7966 -- Otherwise the aspect or pragma defaults to True
7969 return Extensions_Visible_True;
7972 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
7973 -- directly specified. In SPARK code, its value defaults to "False".
7975 elsif SPARK_Mode = On then
7976 return Extensions_Visible_False;
7978 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
7982 return Extensions_Visible_True;
7984 end Extensions_Visible_Status;
7990 procedure Find_Actual
7992 Formal : out Entity_Id;
7995 Context : constant Node_Id := Parent (N);
8000 if Nkind_In (Context, N_Indexed_Component, N_Selected_Component)
8001 and then N = Prefix (Context)
8003 Find_Actual (Context, Formal, Call);
8006 elsif Nkind (Context) = N_Parameter_Association
8007 and then N = Explicit_Actual_Parameter (Context)
8009 Call := Parent (Context);
8011 elsif Nkind_In (Context, N_Entry_Call_Statement,
8013 N_Procedure_Call_Statement)
8023 -- If we have a call to a subprogram look for the parameter. Note that
8024 -- we exclude overloaded calls, since we don't know enough to be sure
8025 -- of giving the right answer in this case.
8027 if Nkind_In (Call, N_Entry_Call_Statement,
8029 N_Procedure_Call_Statement)
8031 Call_Nam := Name (Call);
8033 -- A call to a protected or task entry appears as a selected
8034 -- component rather than an expanded name.
8036 if Nkind (Call_Nam) = N_Selected_Component then
8037 Call_Nam := Selector_Name (Call_Nam);
8040 if Is_Entity_Name (Call_Nam)
8041 and then Present (Entity (Call_Nam))
8042 and then Is_Overloadable (Entity (Call_Nam))
8043 and then not Is_Overloaded (Call_Nam)
8045 -- If node is name in call it is not an actual
8047 if N = Call_Nam then
8053 -- Fall here if we are definitely a parameter
8055 Actual := First_Actual (Call);
8056 Formal := First_Formal (Entity (Call_Nam));
8057 while Present (Formal) and then Present (Actual) loop
8061 -- An actual that is the prefix in a prefixed call may have
8062 -- been rewritten in the call, after the deferred reference
8063 -- was collected. Check if sloc and kinds and names match.
8065 elsif Sloc (Actual) = Sloc (N)
8066 and then Nkind (Actual) = N_Identifier
8067 and then Nkind (Actual) = Nkind (N)
8068 and then Chars (Actual) = Chars (N)
8073 Actual := Next_Actual (Actual);
8074 Formal := Next_Formal (Formal);
8080 -- Fall through here if we did not find matching actual
8086 ---------------------------
8087 -- Find_Body_Discriminal --
8088 ---------------------------
8090 function Find_Body_Discriminal
8091 (Spec_Discriminant : Entity_Id) return Entity_Id
8097 -- If expansion is suppressed, then the scope can be the concurrent type
8098 -- itself rather than a corresponding concurrent record type.
8100 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
8101 Tsk := Scope (Spec_Discriminant);
8104 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
8106 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
8109 -- Find discriminant of original concurrent type, and use its current
8110 -- discriminal, which is the renaming within the task/protected body.
8112 Disc := First_Discriminant (Tsk);
8113 while Present (Disc) loop
8114 if Chars (Disc) = Chars (Spec_Discriminant) then
8115 return Discriminal (Disc);
8118 Next_Discriminant (Disc);
8121 -- That loop should always succeed in finding a matching entry and
8122 -- returning. Fatal error if not.
8124 raise Program_Error;
8125 end Find_Body_Discriminal;
8127 -------------------------------------
8128 -- Find_Corresponding_Discriminant --
8129 -------------------------------------
8131 function Find_Corresponding_Discriminant
8133 Typ : Entity_Id) return Entity_Id
8135 Par_Disc : Entity_Id;
8136 Old_Disc : Entity_Id;
8137 New_Disc : Entity_Id;
8140 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
8142 -- The original type may currently be private, and the discriminant
8143 -- only appear on its full view.
8145 if Is_Private_Type (Scope (Par_Disc))
8146 and then not Has_Discriminants (Scope (Par_Disc))
8147 and then Present (Full_View (Scope (Par_Disc)))
8149 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
8151 Old_Disc := First_Discriminant (Scope (Par_Disc));
8154 if Is_Class_Wide_Type (Typ) then
8155 New_Disc := First_Discriminant (Root_Type (Typ));
8157 New_Disc := First_Discriminant (Typ);
8160 while Present (Old_Disc) and then Present (New_Disc) loop
8161 if Old_Disc = Par_Disc then
8165 Next_Discriminant (Old_Disc);
8166 Next_Discriminant (New_Disc);
8169 -- Should always find it
8171 raise Program_Error;
8172 end Find_Corresponding_Discriminant;
8178 function Find_DIC_Type (Typ : Entity_Id) return Entity_Id is
8179 Curr_Typ : Entity_Id;
8180 -- The current type being examined in the parent hierarchy traversal
8182 DIC_Typ : Entity_Id;
8183 -- The type which carries the DIC pragma. This variable denotes the
8184 -- partial view when private types are involved.
8186 Par_Typ : Entity_Id;
8187 -- The parent type of the current type. This variable denotes the full
8188 -- view when private types are involved.
8191 -- The input type defines its own DIC pragma, therefore it is the owner
8193 if Has_Own_DIC (Typ) then
8196 -- Otherwise the DIC pragma is inherited from a parent type
8199 pragma Assert (Has_Inherited_DIC (Typ));
8201 -- Climb the parent chain
8205 -- Inspect the parent type. Do not consider subtypes as they
8206 -- inherit the DIC attributes from their base types.
8208 DIC_Typ := Base_Type (Etype (Curr_Typ));
8210 -- Look at the full view of a private type because the type may
8211 -- have a hidden parent introduced in the full view.
8215 if Is_Private_Type (Par_Typ)
8216 and then Present (Full_View (Par_Typ))
8218 Par_Typ := Full_View (Par_Typ);
8221 -- Stop the climb once the nearest parent type which defines a DIC
8222 -- pragma of its own is encountered or when the root of the parent
8223 -- chain is reached.
8225 exit when Has_Own_DIC (DIC_Typ) or else Curr_Typ = Par_Typ;
8227 Curr_Typ := Par_Typ;
8234 ----------------------------------
8235 -- Find_Enclosing_Iterator_Loop --
8236 ----------------------------------
8238 function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id is
8243 -- Traverse the scope chain looking for an iterator loop. Such loops are
8244 -- usually transformed into blocks, hence the use of Original_Node.
8247 while Present (S) and then S /= Standard_Standard loop
8248 if Ekind (S) = E_Loop
8249 and then Nkind (Parent (S)) = N_Implicit_Label_Declaration
8251 Constr := Original_Node (Label_Construct (Parent (S)));
8253 if Nkind (Constr) = N_Loop_Statement
8254 and then Present (Iteration_Scheme (Constr))
8255 and then Nkind (Iterator_Specification
8256 (Iteration_Scheme (Constr))) =
8257 N_Iterator_Specification
8267 end Find_Enclosing_Iterator_Loop;
8269 --------------------------
8270 -- Find_Enclosing_Scope --
8271 --------------------------
8273 function Find_Enclosing_Scope (N : Node_Id) return Entity_Id is
8277 -- Examine the parent chain looking for a construct which defines a
8281 while Present (Par) loop
8284 -- The construct denotes a declaration, the proper scope is its
8287 when N_Entry_Declaration
8288 | N_Expression_Function
8289 | N_Full_Type_Declaration
8290 | N_Generic_Package_Declaration
8291 | N_Generic_Subprogram_Declaration
8292 | N_Package_Declaration
8293 | N_Private_Extension_Declaration
8294 | N_Protected_Type_Declaration
8295 | N_Single_Protected_Declaration
8296 | N_Single_Task_Declaration
8297 | N_Subprogram_Declaration
8298 | N_Task_Type_Declaration
8300 return Defining_Entity (Par);
8302 -- The construct denotes a body, the proper scope is the entity of
8303 -- the corresponding spec or that of the body if the body does not
8304 -- complete a previous declaration.
8312 return Unique_Defining_Entity (Par);
8316 -- Blocks carry either a source or an internally-generated scope,
8317 -- unless the block is a byproduct of exception handling.
8319 when N_Block_Statement =>
8320 if not Exception_Junk (Par) then
8321 return Entity (Identifier (Par));
8324 -- Loops carry an internally-generated scope
8326 when N_Loop_Statement =>
8327 return Entity (Identifier (Par));
8329 -- Extended return statements carry an internally-generated scope
8331 when N_Extended_Return_Statement =>
8332 return Return_Statement_Entity (Par);
8334 -- A traversal from a subunit continues via the corresponding stub
8337 Par := Corresponding_Stub (Par);
8343 Par := Parent (Par);
8346 return Standard_Standard;
8347 end Find_Enclosing_Scope;
8349 ------------------------------------
8350 -- Find_Loop_In_Conditional_Block --
8351 ------------------------------------
8353 function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is
8359 if Nkind (Stmt) = N_If_Statement then
8360 Stmt := First (Then_Statements (Stmt));
8363 pragma Assert (Nkind (Stmt) = N_Block_Statement);
8365 -- Inspect the statements of the conditional block. In general the loop
8366 -- should be the first statement in the statement sequence of the block,
8367 -- but the finalization machinery may have introduced extra object
8370 Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
8371 while Present (Stmt) loop
8372 if Nkind (Stmt) = N_Loop_Statement then
8379 -- The expansion of attribute 'Loop_Entry produced a malformed block
8381 raise Program_Error;
8382 end Find_Loop_In_Conditional_Block;
8384 --------------------------
8385 -- Find_Overlaid_Entity --
8386 --------------------------
8388 procedure Find_Overlaid_Entity
8390 Ent : out Entity_Id;
8396 -- We are looking for one of the two following forms:
8398 -- for X'Address use Y'Address
8402 -- Const : constant Address := expr;
8404 -- for X'Address use Const;
8406 -- In the second case, the expr is either Y'Address, or recursively a
8407 -- constant that eventually references Y'Address.
8412 if Nkind (N) = N_Attribute_Definition_Clause
8413 and then Chars (N) = Name_Address
8415 Expr := Expression (N);
8417 -- This loop checks the form of the expression for Y'Address,
8418 -- using recursion to deal with intermediate constants.
8421 -- Check for Y'Address
8423 if Nkind (Expr) = N_Attribute_Reference
8424 and then Attribute_Name (Expr) = Name_Address
8426 Expr := Prefix (Expr);
8429 -- Check for Const where Const is a constant entity
8431 elsif Is_Entity_Name (Expr)
8432 and then Ekind (Entity (Expr)) = E_Constant
8434 Expr := Constant_Value (Entity (Expr));
8436 -- Anything else does not need checking
8443 -- This loop checks the form of the prefix for an entity, using
8444 -- recursion to deal with intermediate components.
8447 -- Check for Y where Y is an entity
8449 if Is_Entity_Name (Expr) then
8450 Ent := Entity (Expr);
8453 -- Check for components
8456 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component)
8458 Expr := Prefix (Expr);
8461 -- Anything else does not need checking
8468 end Find_Overlaid_Entity;
8470 -------------------------
8471 -- Find_Parameter_Type --
8472 -------------------------
8474 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
8476 if Nkind (Param) /= N_Parameter_Specification then
8479 -- For an access parameter, obtain the type from the formal entity
8480 -- itself, because access to subprogram nodes do not carry a type.
8481 -- Shouldn't we always use the formal entity ???
8483 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
8484 return Etype (Defining_Identifier (Param));
8487 return Etype (Parameter_Type (Param));
8489 end Find_Parameter_Type;
8491 -----------------------------------
8492 -- Find_Placement_In_State_Space --
8493 -----------------------------------
8495 procedure Find_Placement_In_State_Space
8496 (Item_Id : Entity_Id;
8497 Placement : out State_Space_Kind;
8498 Pack_Id : out Entity_Id)
8500 Context : Entity_Id;
8503 -- Assume that the item does not appear in the state space of a package
8505 Placement := Not_In_Package;
8508 -- Climb the scope stack and examine the enclosing context
8510 Context := Scope (Item_Id);
8511 while Present (Context) and then Context /= Standard_Standard loop
8512 if Is_Package_Or_Generic_Package (Context) then
8515 -- A package body is a cut off point for the traversal as the item
8516 -- cannot be visible to the outside from this point on. Note that
8517 -- this test must be done first as a body is also classified as a
8520 if In_Package_Body (Context) then
8521 Placement := Body_State_Space;
8524 -- The private part of a package is a cut off point for the
8525 -- traversal as the item cannot be visible to the outside from
8528 elsif In_Private_Part (Context) then
8529 Placement := Private_State_Space;
8532 -- When the item appears in the visible state space of a package,
8533 -- continue to climb the scope stack as this may not be the final
8537 Placement := Visible_State_Space;
8539 -- The visible state space of a child unit acts as the proper
8540 -- placement of an item.
8542 if Is_Child_Unit (Context) then
8547 -- The item or its enclosing package appear in a construct that has
8551 Placement := Not_In_Package;
8555 Context := Scope (Context);
8557 end Find_Placement_In_State_Space;
8559 -----------------------
8560 -- Find_Primitive_Eq --
8561 -----------------------
8563 function Find_Primitive_Eq (Typ : Entity_Id) return Entity_Id is
8564 function Find_Eq_Prim (Prims_List : Elist_Id) return Entity_Id;
8565 -- Search for the equality primitive; return Empty if the primitive is
8572 function Find_Eq_Prim (Prims_List : Elist_Id) return Entity_Id is
8574 Prim_Elmt : Elmt_Id;
8577 Prim_Elmt := First_Elmt (Prims_List);
8578 while Present (Prim_Elmt) loop
8579 Prim := Node (Prim_Elmt);
8581 -- Locate primitive equality with the right signature
8583 if Chars (Prim) = Name_Op_Eq
8584 and then Etype (First_Formal (Prim)) =
8585 Etype (Next_Formal (First_Formal (Prim)))
8586 and then Base_Type (Etype (Prim)) = Standard_Boolean
8591 Next_Elmt (Prim_Elmt);
8599 Eq_Prim : Entity_Id;
8600 Full_Type : Entity_Id;
8602 -- Start of processing for Find_Primitive_Eq
8605 if Is_Private_Type (Typ) then
8606 Full_Type := Underlying_Type (Typ);
8611 if No (Full_Type) then
8615 Full_Type := Base_Type (Full_Type);
8617 -- When the base type itself is private, use the full view
8619 if Is_Private_Type (Full_Type) then
8620 Full_Type := Underlying_Type (Full_Type);
8623 if Is_Class_Wide_Type (Full_Type) then
8624 Full_Type := Root_Type (Full_Type);
8627 if not Is_Tagged_Type (Full_Type) then
8628 Eq_Prim := Find_Eq_Prim (Collect_Primitive_Operations (Typ));
8630 -- If this is an untagged private type completed with a derivation of
8631 -- an untagged private type whose full view is a tagged type, we use
8632 -- the primitive operations of the private parent type (since it does
8633 -- not have a full view, and also because its equality primitive may
8634 -- have been overridden in its untagged full view). If no equality was
8635 -- defined for it then take its dispatching equality primitive.
8637 elsif Inherits_From_Tagged_Full_View (Typ) then
8638 Eq_Prim := Find_Eq_Prim (Collect_Primitive_Operations (Typ));
8640 if No (Eq_Prim) then
8641 Eq_Prim := Find_Eq_Prim (Primitive_Operations (Full_Type));
8645 Eq_Prim := Find_Eq_Prim (Primitive_Operations (Full_Type));
8649 end Find_Primitive_Eq;
8651 ------------------------
8652 -- Find_Specific_Type --
8653 ------------------------
8655 function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
8656 Typ : Entity_Id := Root_Type (CW);
8659 if Ekind (Typ) = E_Incomplete_Type then
8660 if From_Limited_With (Typ) then
8661 Typ := Non_Limited_View (Typ);
8663 Typ := Full_View (Typ);
8667 if Is_Private_Type (Typ)
8668 and then not Is_Tagged_Type (Typ)
8669 and then Present (Full_View (Typ))
8671 return Full_View (Typ);
8675 end Find_Specific_Type;
8677 -----------------------------
8678 -- Find_Static_Alternative --
8679 -----------------------------
8681 function Find_Static_Alternative (N : Node_Id) return Node_Id is
8682 Expr : constant Node_Id := Expression (N);
8683 Val : constant Uint := Expr_Value (Expr);
8688 Alt := First (Alternatives (N));
8691 if Nkind (Alt) /= N_Pragma then
8692 Choice := First (Discrete_Choices (Alt));
8693 while Present (Choice) loop
8695 -- Others choice, always matches
8697 if Nkind (Choice) = N_Others_Choice then
8700 -- Range, check if value is in the range
8702 elsif Nkind (Choice) = N_Range then
8704 Val >= Expr_Value (Low_Bound (Choice))
8706 Val <= Expr_Value (High_Bound (Choice));
8708 -- Choice is a subtype name. Note that we know it must
8709 -- be a static subtype, since otherwise it would have
8710 -- been diagnosed as illegal.
8712 elsif Is_Entity_Name (Choice)
8713 and then Is_Type (Entity (Choice))
8715 exit Search when Is_In_Range (Expr, Etype (Choice),
8716 Assume_Valid => False);
8718 -- Choice is a subtype indication
8720 elsif Nkind (Choice) = N_Subtype_Indication then
8722 C : constant Node_Id := Constraint (Choice);
8723 R : constant Node_Id := Range_Expression (C);
8727 Val >= Expr_Value (Low_Bound (R))
8729 Val <= Expr_Value (High_Bound (R));
8732 -- Choice is a simple expression
8735 exit Search when Val = Expr_Value (Choice);
8743 pragma Assert (Present (Alt));
8746 -- The above loop *must* terminate by finding a match, since we know the
8747 -- case statement is valid, and the value of the expression is known at
8748 -- compile time. When we fall out of the loop, Alt points to the
8749 -- alternative that we know will be selected at run time.
8752 end Find_Static_Alternative;
8758 function First_Actual (Node : Node_Id) return Node_Id is
8762 if No (Parameter_Associations (Node)) then
8766 N := First (Parameter_Associations (Node));
8768 if Nkind (N) = N_Parameter_Association then
8769 return First_Named_Actual (Node);
8779 function First_Global
8781 Global_Mode : Name_Id;
8782 Refined : Boolean := False) return Node_Id
8784 function First_From_Global_List
8786 Global_Mode : Name_Id := Name_Input) return Entity_Id;
8787 -- Get the first item with suitable mode from List
8789 ----------------------------
8790 -- First_From_Global_List --
8791 ----------------------------
8793 function First_From_Global_List
8795 Global_Mode : Name_Id := Name_Input) return Entity_Id
8800 -- Empty list (no global items)
8802 if Nkind (List) = N_Null then
8805 -- Single global item declaration (only input items)
8807 elsif Nkind_In (List, N_Expanded_Name, N_Identifier) then
8808 if Global_Mode = Name_Input then
8814 -- Simple global list (only input items) or moded global list
8817 elsif Nkind (List) = N_Aggregate then
8818 if Present (Expressions (List)) then
8819 if Global_Mode = Name_Input then
8820 return First (Expressions (List));
8826 Assoc := First (Component_Associations (List));
8827 while Present (Assoc) loop
8829 -- When we find the desired mode in an association, call
8830 -- recursively First_From_Global_List as if the mode was
8831 -- Name_Input, in order to reuse the existing machinery
8832 -- for the other cases.
8834 if Chars (First (Choices (Assoc))) = Global_Mode then
8835 return First_From_Global_List (Expression (Assoc));
8844 -- To accommodate partial decoration of disabled SPARK features,
8845 -- this routine may be called with illegal input. If this is the
8846 -- case, do not raise Program_Error.
8851 end First_From_Global_List;
8855 Global : Node_Id := Empty;
8856 Body_Id : Entity_Id;
8858 -- Start of processing for First_Global
8861 pragma Assert (Nam_In (Global_Mode, Name_In_Out,
8866 -- Retrieve the suitable pragma Global or Refined_Global. In the second
8867 -- case, it can only be located on the body entity.
8870 if Is_Subprogram_Or_Generic_Subprogram (Subp) then
8871 Body_Id := Subprogram_Body_Entity (Subp);
8873 elsif Is_Entry (Subp) or else Is_Task_Type (Subp) then
8874 Body_Id := Corresponding_Body (Parent (Subp));
8876 -- ??? It should be possible to retrieve the Refined_Global on the
8877 -- task body associated to the task object. This is not yet possible.
8879 elsif Is_Single_Task_Object (Subp) then
8886 if Present (Body_Id) then
8887 Global := Get_Pragma (Body_Id, Pragma_Refined_Global);
8890 Global := Get_Pragma (Subp, Pragma_Global);
8893 -- No corresponding global if pragma is not present
8898 -- Otherwise retrieve the corresponding list of items depending on the
8902 return First_From_Global_List
8903 (Expression (Get_Argument (Global, Subp)), Global_Mode);
8911 function Fix_Msg (Id : Entity_Id; Msg : String) return String is
8912 Is_Task : constant Boolean :=
8913 Ekind_In (Id, E_Task_Body, E_Task_Type)
8914 or else Is_Single_Task_Object (Id);
8915 Msg_Last : constant Natural := Msg'Last;
8916 Msg_Index : Natural;
8917 Res : String (Msg'Range) := (others => ' ');
8918 Res_Index : Natural;
8921 -- Copy all characters from the input message Msg to result Res with
8922 -- suitable replacements.
8924 Msg_Index := Msg'First;
8925 Res_Index := Res'First;
8926 while Msg_Index <= Msg_Last loop
8928 -- Replace "subprogram" with a different word
8930 if Msg_Index <= Msg_Last - 10
8931 and then Msg (Msg_Index .. Msg_Index + 9) = "subprogram"
8933 if Ekind_In (Id, E_Entry, E_Entry_Family) then
8934 Res (Res_Index .. Res_Index + 4) := "entry";
8935 Res_Index := Res_Index + 5;
8938 Res (Res_Index .. Res_Index + 8) := "task type";
8939 Res_Index := Res_Index + 9;
8942 Res (Res_Index .. Res_Index + 9) := "subprogram";
8943 Res_Index := Res_Index + 10;
8946 Msg_Index := Msg_Index + 10;
8948 -- Replace "protected" with a different word
8950 elsif Msg_Index <= Msg_Last - 9
8951 and then Msg (Msg_Index .. Msg_Index + 8) = "protected"
8954 Res (Res_Index .. Res_Index + 3) := "task";
8955 Res_Index := Res_Index + 4;
8956 Msg_Index := Msg_Index + 9;
8958 -- Otherwise copy the character
8961 Res (Res_Index) := Msg (Msg_Index);
8962 Msg_Index := Msg_Index + 1;
8963 Res_Index := Res_Index + 1;
8967 return Res (Res'First .. Res_Index - 1);
8970 -------------------------
8971 -- From_Nested_Package --
8972 -------------------------
8974 function From_Nested_Package (T : Entity_Id) return Boolean is
8975 Pack : constant Entity_Id := Scope (T);
8979 Ekind (Pack) = E_Package
8980 and then not Is_Frozen (Pack)
8981 and then not Scope_Within_Or_Same (Current_Scope, Pack)
8982 and then In_Open_Scopes (Scope (Pack));
8983 end From_Nested_Package;
8985 -----------------------
8986 -- Gather_Components --
8987 -----------------------
8989 procedure Gather_Components
8991 Comp_List : Node_Id;
8992 Governed_By : List_Id;
8994 Report_Errors : out Boolean)
8998 Discrete_Choice : Node_Id;
8999 Comp_Item : Node_Id;
9000 Discrim : Entity_Id;
9001 Discrim_Name : Node_Id;
9003 type Discriminant_Value_Status is
9004 (Static_Expr, Static_Subtype, Bad);
9005 subtype Good_Discrim_Value_Status is Discriminant_Value_Status
9006 range Static_Expr .. Static_Subtype; -- range excludes Bad
9008 Discrim_Value : Node_Id;
9009 Discrim_Value_Subtype : Node_Id;
9010 Discrim_Value_Status : Discriminant_Value_Status := Bad;
9012 Report_Errors := False;
9014 if No (Comp_List) or else Null_Present (Comp_List) then
9017 elsif Present (Component_Items (Comp_List)) then
9018 Comp_Item := First (Component_Items (Comp_List));
9024 while Present (Comp_Item) loop
9026 -- Skip the tag of a tagged record, the interface tags, as well
9027 -- as all items that are not user components (anonymous types,
9028 -- rep clauses, Parent field, controller field).
9030 if Nkind (Comp_Item) = N_Component_Declaration then
9032 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
9034 if not Is_Tag (Comp) and then Chars (Comp) /= Name_uParent then
9035 Append_Elmt (Comp, Into);
9043 if No (Variant_Part (Comp_List)) then
9046 Discrim_Name := Name (Variant_Part (Comp_List));
9047 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
9050 -- Look for the discriminant that governs this variant part.
9051 -- The discriminant *must* be in the Governed_By List
9053 Assoc := First (Governed_By);
9054 Find_Constraint : loop
9055 Discrim := First (Choices (Assoc));
9056 exit Find_Constraint when
9057 Chars (Discrim_Name) = Chars (Discrim)
9059 (Present (Corresponding_Discriminant (Entity (Discrim)))
9060 and then Chars (Corresponding_Discriminant
9061 (Entity (Discrim))) = Chars (Discrim_Name))
9063 Chars (Original_Record_Component (Entity (Discrim))) =
9064 Chars (Discrim_Name);
9066 if No (Next (Assoc)) then
9067 if not Is_Constrained (Typ) and then Is_Derived_Type (Typ) then
9069 -- If the type is a tagged type with inherited discriminants,
9070 -- use the stored constraint on the parent in order to find
9071 -- the values of discriminants that are otherwise hidden by an
9072 -- explicit constraint. Renamed discriminants are handled in
9075 -- If several parent discriminants are renamed by a single
9076 -- discriminant of the derived type, the call to obtain the
9077 -- Corresponding_Discriminant field only retrieves the last
9078 -- of them. We recover the constraint on the others from the
9079 -- Stored_Constraint as well.
9081 -- An inherited discriminant may have been constrained in a
9082 -- later ancestor (not the immediate parent) so we must examine
9083 -- the stored constraint of all of them to locate the inherited
9089 T : Entity_Id := Typ;
9092 while Is_Derived_Type (T) loop
9093 if Present (Stored_Constraint (T)) then
9094 D := First_Discriminant (Etype (T));
9095 C := First_Elmt (Stored_Constraint (T));
9096 while Present (D) and then Present (C) loop
9097 if Chars (Discrim_Name) = Chars (D) then
9098 if Is_Entity_Name (Node (C))
9099 and then Entity (Node (C)) = Entity (Discrim)
9101 -- D is renamed by Discrim, whose value is
9108 Make_Component_Association (Sloc (Typ),
9110 (New_Occurrence_Of (D, Sloc (Typ))),
9111 Duplicate_Subexpr_No_Checks (Node (C)));
9114 exit Find_Constraint;
9117 Next_Discriminant (D);
9122 -- Discriminant may be inherited from ancestor
9130 if No (Next (Assoc)) then
9132 (" missing value for discriminant&",
9133 First (Governed_By), Discrim_Name);
9135 Report_Errors := True;
9140 end loop Find_Constraint;
9142 Discrim_Value := Expression (Assoc);
9143 if Is_OK_Static_Expression (Discrim_Value) then
9144 Discrim_Value_Status := Static_Expr;
9146 if Ada_Version >= Ada_2020 then
9147 if Original_Node (Discrim_Value) /= Discrim_Value
9148 and then Nkind (Discrim_Value) = N_Type_Conversion
9149 and then Etype (Original_Node (Discrim_Value))
9150 = Etype (Expression (Discrim_Value))
9152 Discrim_Value_Subtype := Etype (Original_Node (Discrim_Value));
9153 -- An unhelpful (for this code) type conversion may be
9154 -- introduced in some cases; deal with it.
9156 Discrim_Value_Subtype := Etype (Discrim_Value);
9159 if Is_OK_Static_Subtype (Discrim_Value_Subtype) and then
9160 not Is_Null_Range (Type_Low_Bound (Discrim_Value_Subtype),
9161 Type_High_Bound (Discrim_Value_Subtype))
9163 -- Is_Null_Range test doesn't account for predicates, as in
9164 -- subtype Null_By_Predicate is Natural
9165 -- with Static_Predicate => Null_By_Predicate < 0;
9166 -- so test for that null case separately.
9168 if (not Has_Static_Predicate (Discrim_Value_Subtype))
9169 or else Present (First (Static_Discrete_Predicate
9170 (Discrim_Value_Subtype)))
9172 Discrim_Value_Status := Static_Subtype;
9177 if Discrim_Value_Status = Bad then
9179 -- If the variant part is governed by a discriminant of the type
9180 -- this is an error. If the variant part and the discriminant are
9181 -- inherited from an ancestor this is legal (AI05-220) unless the
9182 -- components are being gathered for an aggregate, in which case
9183 -- the caller must check Report_Errors.
9185 -- In Ada 2020 the above rules are relaxed. A nonstatic governing
9186 -- discriminant is OK as long as it has a static subtype and
9187 -- every value of that subtype (and there must be at least one)
9188 -- selects the same variant.
9190 if Scope (Original_Record_Component
9191 ((Entity (First (Choices (Assoc)))))) = Typ
9193 if Ada_Version >= Ada_2020 then
9195 ("value for discriminant & must be static or " &
9196 "discriminant's nominal subtype must be static " &
9198 Discrim_Value, Discrim);
9201 ("value for discriminant & must be static!",
9202 Discrim_Value, Discrim);
9204 Why_Not_Static (Discrim_Value);
9207 Report_Errors := True;
9212 Search_For_Discriminant_Value : declare
9218 UI_Discrim_Value : Uint;
9221 case Good_Discrim_Value_Status'(Discrim_Value_Status) is
9223 UI_Discrim_Value := Expr_Value (Discrim_Value);
9224 when Static_Subtype =>
9225 -- Arbitrarily pick one value of the subtype and look
9226 -- for the variant associated with that value; we will
9227 -- check later that the same variant is associated with
9228 -- all of the other values of the subtype.
9229 if Has_Static_Predicate (Discrim_Value_Subtype) then
9231 Range_Or_Expr : constant Node_Id :=
9232 First (Static_Discrete_Predicate
9233 (Discrim_Value_Subtype));
9235 if Nkind (Range_Or_Expr) = N_Range then
9237 Expr_Value (Low_Bound (Range_Or_Expr));
9239 UI_Discrim_Value := Expr_Value (Range_Or_Expr);
9244 := Expr_Value (Type_Low_Bound (Discrim_Value_Subtype));
9248 Find_Discrete_Value : while Present (Variant) loop
9250 -- If a choice is a subtype with a static predicate, it must
9251 -- be rewritten as an explicit list of non-predicated choices.
9253 Expand_Static_Predicates_In_Choices (Variant);
9255 Discrete_Choice := First (Discrete_Choices (Variant));
9256 while Present (Discrete_Choice) loop
9257 exit Find_Discrete_Value when
9258 Nkind (Discrete_Choice) = N_Others_Choice;
9260 Get_Index_Bounds (Discrete_Choice, Low, High);
9262 UI_Low := Expr_Value (Low);
9263 UI_High := Expr_Value (High);
9265 exit Find_Discrete_Value when
9266 UI_Low <= UI_Discrim_Value
9268 UI_High >= UI_Discrim_Value;
9270 Next (Discrete_Choice);
9273 Next_Non_Pragma (Variant);
9274 end loop Find_Discrete_Value;
9275 end Search_For_Discriminant_Value;
9277 -- The case statement must include a variant that corresponds to the
9278 -- value of the discriminant, unless the discriminant type has a
9279 -- static predicate. In that case the absence of an others_choice that
9280 -- would cover this value becomes a run-time error (3.8.1 (21.1/2)).
9283 and then not Has_Static_Predicate (Etype (Discrim_Name))
9286 ("value of discriminant & is out of range", Discrim_Value, Discrim);
9287 Report_Errors := True;
9291 -- If we have found the corresponding choice, recursively add its
9292 -- components to the Into list. The nested components are part of
9293 -- the same record type.
9295 if Present (Variant) then
9296 if Discrim_Value_Status = Static_Subtype then
9298 Discrim_Value_Subtype_Intervals
9299 : constant Interval_Lists.Discrete_Interval_List
9300 := Interval_Lists.Type_Intervals (Discrim_Value_Subtype);
9303 : constant Interval_Lists.Discrete_Interval_List
9304 := Interval_Lists.Choice_List_Intervals
9305 (Discrete_Choices => Discrete_Choices (Variant));
9307 if not Interval_Lists.Is_Subset
9308 (Subset => Discrim_Value_Subtype_Intervals,
9309 Of_Set => Variant_Intervals)
9312 ("no single variant is associated with all values of " &
9313 "the subtype of discriminant value &",
9314 Discrim_Value, Discrim);
9315 Report_Errors := True;
9322 (Typ, Component_List (Variant), Governed_By, Into, Report_Errors);
9324 end Gather_Components;
9326 -----------------------
9327 -- Get_Accessibility --
9328 -----------------------
9330 function Get_Accessibility (E : Entity_Id) return Node_Id is
9332 -- When minimum accessibility is set for E then we utilize it - except
9333 -- in a few edge cases like the expansion of select statements where
9334 -- generated subprogram may attempt to unnecessarily use a minimum
9335 -- accessibility object declared outside of scope.
9337 -- To avoid these situations where expansion may get complex we verify
9338 -- that the minimum accessibility object is within scope.
9340 if Ekind (E) in Formal_Kind
9341 and then Present (Minimum_Accessibility (E))
9342 and then In_Open_Scopes (Scope (Minimum_Accessibility (E)))
9344 return Minimum_Accessibility (E);
9347 return Extra_Accessibility (E);
9348 end Get_Accessibility;
9350 ------------------------
9351 -- Get_Actual_Subtype --
9352 ------------------------
9354 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
9355 Typ : constant Entity_Id := Etype (N);
9356 Utyp : Entity_Id := Underlying_Type (Typ);
9365 -- If what we have is an identifier that references a subprogram
9366 -- formal, or a variable or constant object, then we get the actual
9367 -- subtype from the referenced entity if one has been built.
9369 if Nkind (N) = N_Identifier
9371 (Is_Formal (Entity (N))
9372 or else Ekind (Entity (N)) = E_Constant
9373 or else Ekind (Entity (N)) = E_Variable)
9374 and then Present (Actual_Subtype (Entity (N)))
9376 return Actual_Subtype (Entity (N));
9378 -- Actual subtype of unchecked union is always itself. We never need
9379 -- the "real" actual subtype. If we did, we couldn't get it anyway
9380 -- because the discriminant is not available. The restrictions on
9381 -- Unchecked_Union are designed to make sure that this is OK.
9383 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
9386 -- Here for the unconstrained case, we must find actual subtype
9387 -- No actual subtype is available, so we must build it on the fly.
9389 -- Checking the type, not the underlying type, for constrainedness
9390 -- seems to be necessary. Maybe all the tests should be on the type???
9392 elsif (not Is_Constrained (Typ))
9393 and then (Is_Array_Type (Utyp)
9394 or else (Is_Record_Type (Utyp)
9395 and then Has_Discriminants (Utyp)))
9396 and then not Has_Unknown_Discriminants (Utyp)
9397 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
9399 -- Nothing to do if in spec expression (why not???)
9401 if In_Spec_Expression then
9404 elsif Is_Private_Type (Typ) and then not Has_Discriminants (Typ) then
9406 -- If the type has no discriminants, there is no subtype to
9407 -- build, even if the underlying type is discriminated.
9411 -- Else build the actual subtype
9414 Decl := Build_Actual_Subtype (Typ, N);
9416 -- The call may yield a declaration, or just return the entity
9422 Atyp := Defining_Identifier (Decl);
9424 -- If Build_Actual_Subtype generated a new declaration then use it
9428 -- The actual subtype is an Itype, so analyze the declaration,
9429 -- but do not attach it to the tree, to get the type defined.
9431 Set_Parent (Decl, N);
9432 Set_Is_Itype (Atyp);
9433 Analyze (Decl, Suppress => All_Checks);
9434 Set_Associated_Node_For_Itype (Atyp, N);
9435 Set_Has_Delayed_Freeze (Atyp, False);
9437 -- We need to freeze the actual subtype immediately. This is
9438 -- needed, because otherwise this Itype will not get frozen
9439 -- at all, and it is always safe to freeze on creation because
9440 -- any associated types must be frozen at this point.
9442 Freeze_Itype (Atyp, N);
9445 -- Otherwise we did not build a declaration, so return original
9452 -- For all remaining cases, the actual subtype is the same as
9453 -- the nominal type.
9458 end Get_Actual_Subtype;
9460 -------------------------------------
9461 -- Get_Actual_Subtype_If_Available --
9462 -------------------------------------
9464 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
9465 Typ : constant Entity_Id := Etype (N);
9468 -- If what we have is an identifier that references a subprogram
9469 -- formal, or a variable or constant object, then we get the actual
9470 -- subtype from the referenced entity if one has been built.
9472 if Nkind (N) = N_Identifier
9474 (Is_Formal (Entity (N))
9475 or else Ekind (Entity (N)) = E_Constant
9476 or else Ekind (Entity (N)) = E_Variable)
9477 and then Present (Actual_Subtype (Entity (N)))
9479 return Actual_Subtype (Entity (N));
9481 -- Otherwise the Etype of N is returned unchanged
9486 end Get_Actual_Subtype_If_Available;
9488 ------------------------
9489 -- Get_Body_From_Stub --
9490 ------------------------
9492 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
9494 return Proper_Body (Unit (Library_Unit (N)));
9495 end Get_Body_From_Stub;
9497 ---------------------
9498 -- Get_Cursor_Type --
9499 ---------------------
9501 function Get_Cursor_Type
9503 Typ : Entity_Id) return Entity_Id
9507 First_Op : Entity_Id;
9511 -- If error already detected, return
9513 if Error_Posted (Aspect) then
9517 -- The cursor type for an Iterable aspect is the return type of a
9518 -- non-overloaded First primitive operation. Locate association for
9521 Assoc := First (Component_Associations (Expression (Aspect)));
9523 while Present (Assoc) loop
9524 if Chars (First (Choices (Assoc))) = Name_First then
9525 First_Op := Expression (Assoc);
9532 if First_Op = Any_Id then
9533 Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
9536 elsif not Analyzed (First_Op) then
9542 -- Locate function with desired name and profile in scope of type
9543 -- In the rare case where the type is an integer type, a base type
9544 -- is created for it, check that the base type of the first formal
9545 -- of First matches the base type of the domain.
9547 Func := First_Entity (Scope (Typ));
9548 while Present (Func) loop
9549 if Chars (Func) = Chars (First_Op)
9550 and then Ekind (Func) = E_Function
9551 and then Present (First_Formal (Func))
9552 and then Base_Type (Etype (First_Formal (Func))) = Base_Type (Typ)
9553 and then No (Next_Formal (First_Formal (Func)))
9555 if Cursor /= Any_Type then
9557 ("Operation First for iterable type must be unique", Aspect);
9560 Cursor := Etype (Func);
9567 -- If not found, no way to resolve remaining primitives
9569 if Cursor = Any_Type then
9571 ("primitive operation for Iterable type must appear in the same "
9572 & "list of declarations as the type", Aspect);
9576 end Get_Cursor_Type;
9578 function Get_Cursor_Type (Typ : Entity_Id) return Entity_Id is
9580 return Etype (Get_Iterable_Type_Primitive (Typ, Name_First));
9581 end Get_Cursor_Type;
9583 -------------------------------
9584 -- Get_Default_External_Name --
9585 -------------------------------
9587 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
9589 Get_Decoded_Name_String (Chars (E));
9591 if Opt.External_Name_Imp_Casing = Uppercase then
9592 Set_Casing (All_Upper_Case);
9594 Set_Casing (All_Lower_Case);
9598 Make_String_Literal (Sloc (E),
9599 Strval => String_From_Name_Buffer);
9600 end Get_Default_External_Name;
9602 --------------------------
9603 -- Get_Enclosing_Object --
9604 --------------------------
9606 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
9608 if Is_Entity_Name (N) then
9612 when N_Indexed_Component
9613 | N_Selected_Component
9616 -- If not generating code, a dereference may be left implicit.
9617 -- In thoses cases, return Empty.
9619 if Is_Access_Type (Etype (Prefix (N))) then
9622 return Get_Enclosing_Object (Prefix (N));
9625 when N_Type_Conversion =>
9626 return Get_Enclosing_Object (Expression (N));
9632 end Get_Enclosing_Object;
9634 ---------------------------
9635 -- Get_Enum_Lit_From_Pos --
9636 ---------------------------
9638 function Get_Enum_Lit_From_Pos
9641 Loc : Source_Ptr) return Node_Id
9643 Btyp : Entity_Id := Base_Type (T);
9648 -- In the case where the literal is of type Character, Wide_Character
9649 -- or Wide_Wide_Character or of a type derived from them, there needs
9650 -- to be some special handling since there is no explicit chain of
9651 -- literals to search. Instead, an N_Character_Literal node is created
9652 -- with the appropriate Char_Code and Chars fields.
9654 if Is_Standard_Character_Type (T) then
9655 Set_Character_Literal_Name (UI_To_CC (Pos));
9658 Make_Character_Literal (Loc,
9660 Char_Literal_Value => Pos);
9662 -- For all other cases, we have a complete table of literals, and
9663 -- we simply iterate through the chain of literal until the one
9664 -- with the desired position value is found.
9667 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
9668 Btyp := Full_View (Btyp);
9671 Lit := First_Literal (Btyp);
9673 -- Position in the enumeration type starts at 0
9675 if UI_To_Int (Pos) < 0 then
9676 raise Constraint_Error;
9679 for J in 1 .. UI_To_Int (Pos) loop
9682 -- If Lit is Empty, Pos is not in range, so raise Constraint_Error
9683 -- inside the loop to avoid calling Next_Literal on Empty.
9686 raise Constraint_Error;
9690 -- Create a new node from Lit, with source location provided by Loc
9691 -- if not equal to No_Location, or by copying the source location of
9696 if LLoc = No_Location then
9700 return New_Occurrence_Of (Lit, LLoc);
9702 end Get_Enum_Lit_From_Pos;
9704 ------------------------
9705 -- Get_Generic_Entity --
9706 ------------------------
9708 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
9709 Ent : constant Entity_Id := Entity (Name (N));
9711 if Present (Renamed_Object (Ent)) then
9712 return Renamed_Object (Ent);
9716 end Get_Generic_Entity;
9718 -------------------------------------
9719 -- Get_Incomplete_View_Of_Ancestor --
9720 -------------------------------------
9722 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
9723 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
9724 Par_Scope : Entity_Id;
9725 Par_Type : Entity_Id;
9728 -- The incomplete view of an ancestor is only relevant for private
9729 -- derived types in child units.
9731 if not Is_Derived_Type (E)
9732 or else not Is_Child_Unit (Cur_Unit)
9737 Par_Scope := Scope (Cur_Unit);
9738 if No (Par_Scope) then
9742 Par_Type := Etype (Base_Type (E));
9744 -- Traverse list of ancestor types until we find one declared in
9745 -- a parent or grandparent unit (two levels seem sufficient).
9747 while Present (Par_Type) loop
9748 if Scope (Par_Type) = Par_Scope
9749 or else Scope (Par_Type) = Scope (Par_Scope)
9753 elsif not Is_Derived_Type (Par_Type) then
9757 Par_Type := Etype (Base_Type (Par_Type));
9761 -- If none found, there is no relevant ancestor type.
9765 end Get_Incomplete_View_Of_Ancestor;
9767 ----------------------
9768 -- Get_Index_Bounds --
9769 ----------------------
9771 procedure Get_Index_Bounds
9775 Use_Full_View : Boolean := False)
9777 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id;
9778 -- Obtain the scalar range of type Typ. If flag Use_Full_View is set and
9779 -- Typ qualifies, the scalar range is obtained from the full view of the
9782 --------------------------
9783 -- Scalar_Range_Of_Type --
9784 --------------------------
9786 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id is
9787 T : Entity_Id := Typ;
9790 if Use_Full_View and then Present (Full_View (T)) then
9794 return Scalar_Range (T);
9795 end Scalar_Range_Of_Type;
9799 Kind : constant Node_Kind := Nkind (N);
9802 -- Start of processing for Get_Index_Bounds
9805 if Kind = N_Range then
9807 H := High_Bound (N);
9809 elsif Kind = N_Subtype_Indication then
9810 Rng := Range_Expression (Constraint (N));
9818 L := Low_Bound (Range_Expression (Constraint (N)));
9819 H := High_Bound (Range_Expression (Constraint (N)));
9822 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
9823 Rng := Scalar_Range_Of_Type (Entity (N));
9825 if Error_Posted (Rng) then
9829 elsif Nkind (Rng) = N_Subtype_Indication then
9830 Get_Index_Bounds (Rng, L, H);
9833 L := Low_Bound (Rng);
9834 H := High_Bound (Rng);
9838 -- N is an expression, indicating a range with one value
9843 end Get_Index_Bounds;
9845 -----------------------------
9846 -- Get_Interfacing_Aspects --
9847 -----------------------------
9849 procedure Get_Interfacing_Aspects
9850 (Iface_Asp : Node_Id;
9851 Conv_Asp : out Node_Id;
9852 EN_Asp : out Node_Id;
9853 Expo_Asp : out Node_Id;
9854 Imp_Asp : out Node_Id;
9855 LN_Asp : out Node_Id;
9856 Do_Checks : Boolean := False)
9858 procedure Save_Or_Duplication_Error
9860 To : in out Node_Id);
9861 -- Save the value of aspect Asp in node To. If To already has a value,
9862 -- then this is considered a duplicate use of aspect. Emit an error if
9863 -- flag Do_Checks is set.
9865 -------------------------------
9866 -- Save_Or_Duplication_Error --
9867 -------------------------------
9869 procedure Save_Or_Duplication_Error
9871 To : in out Node_Id)
9874 -- Detect an extra aspect and issue an error
9876 if Present (To) then
9878 Error_Msg_Name_1 := Chars (Identifier (Asp));
9879 Error_Msg_Sloc := Sloc (To);
9880 Error_Msg_N ("aspect % previously given #", Asp);
9883 -- Otherwise capture the aspect
9888 end Save_Or_Duplication_Error;
9895 -- The following variables capture each individual aspect
9897 Conv : Node_Id := Empty;
9898 EN : Node_Id := Empty;
9899 Expo : Node_Id := Empty;
9900 Imp : Node_Id := Empty;
9901 LN : Node_Id := Empty;
9903 -- Start of processing for Get_Interfacing_Aspects
9906 -- The input interfacing aspect should reside in an aspect specification
9909 pragma Assert (Is_List_Member (Iface_Asp));
9911 -- Examine the aspect specifications of the related entity. Find and
9912 -- capture all interfacing aspects. Detect duplicates and emit errors
9915 Asp := First (List_Containing (Iface_Asp));
9916 while Present (Asp) loop
9917 Asp_Id := Get_Aspect_Id (Asp);
9919 if Asp_Id = Aspect_Convention then
9920 Save_Or_Duplication_Error (Asp, Conv);
9922 elsif Asp_Id = Aspect_External_Name then
9923 Save_Or_Duplication_Error (Asp, EN);
9925 elsif Asp_Id = Aspect_Export then
9926 Save_Or_Duplication_Error (Asp, Expo);
9928 elsif Asp_Id = Aspect_Import then
9929 Save_Or_Duplication_Error (Asp, Imp);
9931 elsif Asp_Id = Aspect_Link_Name then
9932 Save_Or_Duplication_Error (Asp, LN);
9943 end Get_Interfacing_Aspects;
9945 ---------------------------------
9946 -- Get_Iterable_Type_Primitive --
9947 ---------------------------------
9949 function Get_Iterable_Type_Primitive
9951 Nam : Name_Id) return Entity_Id
9953 Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
9961 Assoc := First (Component_Associations (Funcs));
9962 while Present (Assoc) loop
9963 if Chars (First (Choices (Assoc))) = Nam then
9964 return Entity (Expression (Assoc));
9967 Assoc := Next (Assoc);
9972 end Get_Iterable_Type_Primitive;
9974 ----------------------------------
9975 -- Get_Library_Unit_Name_String --
9976 ----------------------------------
9978 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
9979 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
9982 Get_Unit_Name_String (Unit_Name_Id);
9984 -- Remove seven last character (" (spec)" or " (body)")
9986 Name_Len := Name_Len - 7;
9987 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
9988 end Get_Library_Unit_Name_String;
9990 --------------------------
9991 -- Get_Max_Queue_Length --
9992 --------------------------
9994 function Get_Max_Queue_Length (Id : Entity_Id) return Uint is
9995 pragma Assert (Is_Entry (Id));
9996 Prag : constant Entity_Id := Get_Pragma (Id, Pragma_Max_Queue_Length);
10000 -- A value of 0 or -1 represents no maximum specified, and entries and
10001 -- entry families with no Max_Queue_Length aspect or pragma default to
10004 if not Present (Prag) then
10009 (Expression (First (Pragma_Argument_Associations (Prag))));
10011 -- Since -1 and 0 are equivalent, return 0 for instances of -1 for
10019 end Get_Max_Queue_Length;
10021 ------------------------
10022 -- Get_Name_Entity_Id --
10023 ------------------------
10025 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
10027 return Entity_Id (Get_Name_Table_Int (Id));
10028 end Get_Name_Entity_Id;
10030 ------------------------------
10031 -- Get_Name_From_CTC_Pragma --
10032 ------------------------------
10034 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
10035 Arg : constant Node_Id :=
10036 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
10038 return Strval (Expr_Value_S (Arg));
10039 end Get_Name_From_CTC_Pragma;
10041 -----------------------
10042 -- Get_Parent_Entity --
10043 -----------------------
10045 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
10047 if Nkind (Unit) = N_Package_Body
10048 and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
10050 return Defining_Entity
10051 (Specification (Instance_Spec (Original_Node (Unit))));
10052 elsif Nkind (Unit) = N_Package_Instantiation then
10053 return Defining_Entity (Specification (Instance_Spec (Unit)));
10055 return Defining_Entity (Unit);
10057 end Get_Parent_Entity;
10059 -------------------
10060 -- Get_Pragma_Id --
10061 -------------------
10063 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
10065 return Get_Pragma_Id (Pragma_Name_Unmapped (N));
10068 ------------------------
10069 -- Get_Qualified_Name --
10070 ------------------------
10072 function Get_Qualified_Name
10074 Suffix : Entity_Id := Empty) return Name_Id
10076 Suffix_Nam : Name_Id := No_Name;
10079 if Present (Suffix) then
10080 Suffix_Nam := Chars (Suffix);
10083 return Get_Qualified_Name (Chars (Id), Suffix_Nam, Scope (Id));
10084 end Get_Qualified_Name;
10086 function Get_Qualified_Name
10088 Suffix : Name_Id := No_Name;
10089 Scop : Entity_Id := Current_Scope) return Name_Id
10091 procedure Add_Scope (S : Entity_Id);
10092 -- Add the fully qualified form of scope S to the name buffer. The
10100 procedure Add_Scope (S : Entity_Id) is
10105 elsif S = Standard_Standard then
10109 Add_Scope (Scope (S));
10110 Get_Name_String_And_Append (Chars (S));
10111 Add_Str_To_Name_Buffer ("__");
10115 -- Start of processing for Get_Qualified_Name
10121 -- Append the base name after all scopes have been chained
10123 Get_Name_String_And_Append (Nam);
10125 -- Append the suffix (if present)
10127 if Suffix /= No_Name then
10128 Add_Str_To_Name_Buffer ("__");
10129 Get_Name_String_And_Append (Suffix);
10133 end Get_Qualified_Name;
10135 -----------------------
10136 -- Get_Reason_String --
10137 -----------------------
10139 procedure Get_Reason_String (N : Node_Id) is
10141 if Nkind (N) = N_String_Literal then
10142 Store_String_Chars (Strval (N));
10144 elsif Nkind (N) = N_Op_Concat then
10145 Get_Reason_String (Left_Opnd (N));
10146 Get_Reason_String (Right_Opnd (N));
10148 -- If not of required form, error
10152 ("Reason for pragma Warnings has wrong form", N);
10154 ("\must be string literal or concatenation of string literals", N);
10157 end Get_Reason_String;
10159 --------------------------------
10160 -- Get_Reference_Discriminant --
10161 --------------------------------
10163 function Get_Reference_Discriminant (Typ : Entity_Id) return Entity_Id is
10167 D := First_Discriminant (Typ);
10168 while Present (D) loop
10169 if Has_Implicit_Dereference (D) then
10172 Next_Discriminant (D);
10176 end Get_Reference_Discriminant;
10178 ---------------------------
10179 -- Get_Referenced_Object --
10180 ---------------------------
10182 function Get_Referenced_Object (N : Node_Id) return Node_Id is
10187 while Is_Entity_Name (R)
10188 and then Present (Renamed_Object (Entity (R)))
10190 R := Renamed_Object (Entity (R));
10194 end Get_Referenced_Object;
10196 ------------------------
10197 -- Get_Renamed_Entity --
10198 ------------------------
10200 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
10205 while Present (Renamed_Entity (R)) loop
10206 R := Renamed_Entity (R);
10210 end Get_Renamed_Entity;
10212 -----------------------
10213 -- Get_Return_Object --
10214 -----------------------
10216 function Get_Return_Object (N : Node_Id) return Entity_Id is
10220 Decl := First (Return_Object_Declarations (N));
10221 while Present (Decl) loop
10222 exit when Nkind (Decl) = N_Object_Declaration
10223 and then Is_Return_Object (Defining_Identifier (Decl));
10227 pragma Assert (Present (Decl));
10228 return Defining_Identifier (Decl);
10229 end Get_Return_Object;
10231 ---------------------------
10232 -- Get_Subprogram_Entity --
10233 ---------------------------
10235 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
10237 Subp_Id : Entity_Id;
10240 if Nkind (Nod) = N_Accept_Statement then
10241 Subp := Entry_Direct_Name (Nod);
10243 elsif Nkind (Nod) = N_Slice then
10244 Subp := Prefix (Nod);
10247 Subp := Name (Nod);
10250 -- Strip the subprogram call
10253 if Nkind_In (Subp, N_Explicit_Dereference,
10254 N_Indexed_Component,
10255 N_Selected_Component)
10257 Subp := Prefix (Subp);
10259 elsif Nkind_In (Subp, N_Type_Conversion,
10260 N_Unchecked_Type_Conversion)
10262 Subp := Expression (Subp);
10269 -- Extract the entity of the subprogram call
10271 if Is_Entity_Name (Subp) then
10272 Subp_Id := Entity (Subp);
10274 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
10275 Subp_Id := Directly_Designated_Type (Subp_Id);
10278 if Is_Subprogram (Subp_Id) then
10284 -- The search did not find a construct that denotes a subprogram
10289 end Get_Subprogram_Entity;
10291 -----------------------------
10292 -- Get_Task_Body_Procedure --
10293 -----------------------------
10295 function Get_Task_Body_Procedure (E : Entity_Id) return Entity_Id is
10297 -- Note: A task type may be the completion of a private type with
10298 -- discriminants. When performing elaboration checks on a task
10299 -- declaration, the current view of the type may be the private one,
10300 -- and the procedure that holds the body of the task is held in its
10301 -- underlying type.
10303 -- This is an odd function, why not have Task_Body_Procedure do
10304 -- the following digging???
10306 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
10307 end Get_Task_Body_Procedure;
10309 -------------------------
10310 -- Get_User_Defined_Eq --
10311 -------------------------
10313 function Get_User_Defined_Eq (E : Entity_Id) return Entity_Id is
10318 Prim := First_Elmt (Collect_Primitive_Operations (E));
10319 while Present (Prim) loop
10322 if Chars (Op) = Name_Op_Eq
10323 and then Etype (Op) = Standard_Boolean
10324 and then Etype (First_Formal (Op)) = E
10325 and then Etype (Next_Formal (First_Formal (Op))) = E
10334 end Get_User_Defined_Eq;
10340 procedure Get_Views
10342 Priv_Typ : out Entity_Id;
10343 Full_Typ : out Entity_Id;
10344 Full_Base : out Entity_Id;
10345 CRec_Typ : out Entity_Id)
10347 IP_View : Entity_Id;
10350 -- Assume that none of the views can be recovered
10354 Full_Base := Empty;
10357 -- The input type is the corresponding record type of a protected or a
10360 if Ekind (Typ) = E_Record_Type
10361 and then Is_Concurrent_Record_Type (Typ)
10364 Full_Typ := Corresponding_Concurrent_Type (CRec_Typ);
10365 Full_Base := Base_Type (Full_Typ);
10366 Priv_Typ := Incomplete_Or_Partial_View (Full_Typ);
10368 -- Otherwise the input type denotes an arbitrary type
10371 IP_View := Incomplete_Or_Partial_View (Typ);
10373 -- The input type denotes the full view of a private type
10375 if Present (IP_View) then
10376 Priv_Typ := IP_View;
10379 -- The input type is a private type
10381 elsif Is_Private_Type (Typ) then
10383 Full_Typ := Full_View (Priv_Typ);
10385 -- Otherwise the input type does not have any views
10391 if Present (Full_Typ) then
10392 Full_Base := Base_Type (Full_Typ);
10394 if Ekind_In (Full_Typ, E_Protected_Type, E_Task_Type) then
10395 CRec_Typ := Corresponding_Record_Type (Full_Typ);
10401 -----------------------
10402 -- Has_Access_Values --
10403 -----------------------
10405 function Has_Access_Values (T : Entity_Id) return Boolean is
10406 Typ : constant Entity_Id := Underlying_Type (T);
10409 -- Case of a private type which is not completed yet. This can only
10410 -- happen in the case of a generic format type appearing directly, or
10411 -- as a component of the type to which this function is being applied
10412 -- at the top level. Return False in this case, since we certainly do
10413 -- not know that the type contains access types.
10418 elsif Is_Access_Type (Typ) then
10421 elsif Is_Array_Type (Typ) then
10422 return Has_Access_Values (Component_Type (Typ));
10424 elsif Is_Record_Type (Typ) then
10429 -- Loop to Check components
10431 Comp := First_Component_Or_Discriminant (Typ);
10432 while Present (Comp) loop
10434 -- Check for access component, tag field does not count, even
10435 -- though it is implemented internally using an access type.
10437 if Has_Access_Values (Etype (Comp))
10438 and then Chars (Comp) /= Name_uTag
10443 Next_Component_Or_Discriminant (Comp);
10452 end Has_Access_Values;
10454 ------------------------------
10455 -- Has_Compatible_Alignment --
10456 ------------------------------
10458 function Has_Compatible_Alignment
10461 Layout_Done : Boolean) return Alignment_Result
10463 function Has_Compatible_Alignment_Internal
10466 Layout_Done : Boolean;
10467 Default : Alignment_Result) return Alignment_Result;
10468 -- This is the internal recursive function that actually does the work.
10469 -- There is one additional parameter, which says what the result should
10470 -- be if no alignment information is found, and there is no definite
10471 -- indication of compatible alignments. At the outer level, this is set
10472 -- to Unknown, but for internal recursive calls in the case where types
10473 -- are known to be correct, it is set to Known_Compatible.
10475 ---------------------------------------
10476 -- Has_Compatible_Alignment_Internal --
10477 ---------------------------------------
10479 function Has_Compatible_Alignment_Internal
10482 Layout_Done : Boolean;
10483 Default : Alignment_Result) return Alignment_Result
10485 Result : Alignment_Result := Known_Compatible;
10486 -- Holds the current status of the result. Note that once a value of
10487 -- Known_Incompatible is set, it is sticky and does not get changed
10488 -- to Unknown (the value in Result only gets worse as we go along,
10491 Offs : Uint := No_Uint;
10492 -- Set to a factor of the offset from the base object when Expr is a
10493 -- selected or indexed component, based on Component_Bit_Offset and
10494 -- Component_Size respectively. A negative value is used to represent
10495 -- a value which is not known at compile time.
10497 procedure Check_Prefix;
10498 -- Checks the prefix recursively in the case where the expression
10499 -- is an indexed or selected component.
10501 procedure Set_Result (R : Alignment_Result);
10502 -- If R represents a worse outcome (unknown instead of known
10503 -- compatible, or known incompatible), then set Result to R.
10509 procedure Check_Prefix is
10511 -- The subtlety here is that in doing a recursive call to check
10512 -- the prefix, we have to decide what to do in the case where we
10513 -- don't find any specific indication of an alignment problem.
10515 -- At the outer level, we normally set Unknown as the result in
10516 -- this case, since we can only set Known_Compatible if we really
10517 -- know that the alignment value is OK, but for the recursive
10518 -- call, in the case where the types match, and we have not
10519 -- specified a peculiar alignment for the object, we are only
10520 -- concerned about suspicious rep clauses, the default case does
10521 -- not affect us, since the compiler will, in the absence of such
10522 -- rep clauses, ensure that the alignment is correct.
10524 if Default = Known_Compatible
10526 (Etype (Obj) = Etype (Expr)
10527 and then (Unknown_Alignment (Obj)
10529 Alignment (Obj) = Alignment (Etype (Obj))))
10532 (Has_Compatible_Alignment_Internal
10533 (Obj, Prefix (Expr), Layout_Done, Known_Compatible));
10535 -- In all other cases, we need a full check on the prefix
10539 (Has_Compatible_Alignment_Internal
10540 (Obj, Prefix (Expr), Layout_Done, Unknown));
10548 procedure Set_Result (R : Alignment_Result) is
10555 -- Start of processing for Has_Compatible_Alignment_Internal
10558 -- If Expr is a selected component, we must make sure there is no
10559 -- potentially troublesome component clause and that the record is
10560 -- not packed if the layout is not done.
10562 if Nkind (Expr) = N_Selected_Component then
10564 -- Packing generates unknown alignment if layout is not done
10566 if Is_Packed (Etype (Prefix (Expr))) and then not Layout_Done then
10567 Set_Result (Unknown);
10570 -- Check prefix and component offset
10573 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
10575 -- If Expr is an indexed component, we must make sure there is no
10576 -- potentially troublesome Component_Size clause and that the array
10577 -- is not bit-packed if the layout is not done.
10579 elsif Nkind (Expr) = N_Indexed_Component then
10581 Typ : constant Entity_Id := Etype (Prefix (Expr));
10584 -- Packing generates unknown alignment if layout is not done
10586 if Is_Bit_Packed_Array (Typ) and then not Layout_Done then
10587 Set_Result (Unknown);
10590 -- Check prefix and component offset (or at least size)
10593 Offs := Indexed_Component_Bit_Offset (Expr);
10594 if Offs = No_Uint then
10595 Offs := Component_Size (Typ);
10600 -- If we have a null offset, the result is entirely determined by
10601 -- the base object and has already been computed recursively.
10603 if Offs = Uint_0 then
10606 -- Case where we know the alignment of the object
10608 elsif Known_Alignment (Obj) then
10610 ObjA : constant Uint := Alignment (Obj);
10611 ExpA : Uint := No_Uint;
10612 SizA : Uint := No_Uint;
10615 -- If alignment of Obj is 1, then we are always OK
10618 Set_Result (Known_Compatible);
10620 -- Alignment of Obj is greater than 1, so we need to check
10623 -- If we have an offset, see if it is compatible
10625 if Offs /= No_Uint and Offs > Uint_0 then
10626 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
10627 Set_Result (Known_Incompatible);
10630 -- See if Expr is an object with known alignment
10632 elsif Is_Entity_Name (Expr)
10633 and then Known_Alignment (Entity (Expr))
10635 ExpA := Alignment (Entity (Expr));
10637 -- Otherwise, we can use the alignment of the type of
10638 -- Expr given that we already checked for
10639 -- discombobulating rep clauses for the cases of indexed
10640 -- and selected components above.
10642 elsif Known_Alignment (Etype (Expr)) then
10643 ExpA := Alignment (Etype (Expr));
10645 -- Otherwise the alignment is unknown
10648 Set_Result (Default);
10651 -- If we got an alignment, see if it is acceptable
10653 if ExpA /= No_Uint and then ExpA < ObjA then
10654 Set_Result (Known_Incompatible);
10657 -- If Expr is not a piece of a larger object, see if size
10658 -- is given. If so, check that it is not too small for the
10659 -- required alignment.
10661 if Offs /= No_Uint then
10664 -- See if Expr is an object with known size
10666 elsif Is_Entity_Name (Expr)
10667 and then Known_Static_Esize (Entity (Expr))
10669 SizA := Esize (Entity (Expr));
10671 -- Otherwise, we check the object size of the Expr type
10673 elsif Known_Static_Esize (Etype (Expr)) then
10674 SizA := Esize (Etype (Expr));
10677 -- If we got a size, see if it is a multiple of the Obj
10678 -- alignment, if not, then the alignment cannot be
10679 -- acceptable, since the size is always a multiple of the
10682 if SizA /= No_Uint then
10683 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
10684 Set_Result (Known_Incompatible);
10690 -- If we do not know required alignment, any non-zero offset is a
10691 -- potential problem (but certainly may be OK, so result is unknown).
10693 elsif Offs /= No_Uint then
10694 Set_Result (Unknown);
10696 -- If we can't find the result by direct comparison of alignment
10697 -- values, then there is still one case that we can determine known
10698 -- result, and that is when we can determine that the types are the
10699 -- same, and no alignments are specified. Then we known that the
10700 -- alignments are compatible, even if we don't know the alignment
10701 -- value in the front end.
10703 elsif Etype (Obj) = Etype (Expr) then
10705 -- Types are the same, but we have to check for possible size
10706 -- and alignments on the Expr object that may make the alignment
10707 -- different, even though the types are the same.
10709 if Is_Entity_Name (Expr) then
10711 -- First check alignment of the Expr object. Any alignment less
10712 -- than Maximum_Alignment is worrisome since this is the case
10713 -- where we do not know the alignment of Obj.
10715 if Known_Alignment (Entity (Expr))
10716 and then UI_To_Int (Alignment (Entity (Expr))) <
10717 Ttypes.Maximum_Alignment
10719 Set_Result (Unknown);
10721 -- Now check size of Expr object. Any size that is not an
10722 -- even multiple of Maximum_Alignment is also worrisome
10723 -- since it may cause the alignment of the object to be less
10724 -- than the alignment of the type.
10726 elsif Known_Static_Esize (Entity (Expr))
10728 (UI_To_Int (Esize (Entity (Expr))) mod
10729 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
10732 Set_Result (Unknown);
10734 -- Otherwise same type is decisive
10737 Set_Result (Known_Compatible);
10741 -- Another case to deal with is when there is an explicit size or
10742 -- alignment clause when the types are not the same. If so, then the
10743 -- result is Unknown. We don't need to do this test if the Default is
10744 -- Unknown, since that result will be set in any case.
10746 elsif Default /= Unknown
10747 and then (Has_Size_Clause (Etype (Expr))
10749 Has_Alignment_Clause (Etype (Expr)))
10751 Set_Result (Unknown);
10753 -- If no indication found, set default
10756 Set_Result (Default);
10759 -- Return worst result found
10762 end Has_Compatible_Alignment_Internal;
10764 -- Start of processing for Has_Compatible_Alignment
10767 -- If Obj has no specified alignment, then set alignment from the type
10768 -- alignment. Perhaps we should always do this, but for sure we should
10769 -- do it when there is an address clause since we can do more if the
10770 -- alignment is known.
10772 if Unknown_Alignment (Obj) then
10773 Set_Alignment (Obj, Alignment (Etype (Obj)));
10776 -- Now do the internal call that does all the work
10779 Has_Compatible_Alignment_Internal (Obj, Expr, Layout_Done, Unknown);
10780 end Has_Compatible_Alignment;
10782 ----------------------
10783 -- Has_Declarations --
10784 ----------------------
10786 function Has_Declarations (N : Node_Id) return Boolean is
10788 return Nkind_In (Nkind (N), N_Accept_Statement,
10790 N_Compilation_Unit_Aux,
10796 N_Package_Specification);
10797 end Has_Declarations;
10799 ---------------------------------
10800 -- Has_Defaulted_Discriminants --
10801 ---------------------------------
10803 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
10805 return Has_Discriminants (Typ)
10806 and then Present (First_Discriminant (Typ))
10807 and then Present (Discriminant_Default_Value
10808 (First_Discriminant (Typ)));
10809 end Has_Defaulted_Discriminants;
10811 -------------------
10812 -- Has_Denormals --
10813 -------------------
10815 function Has_Denormals (E : Entity_Id) return Boolean is
10817 return Is_Floating_Point_Type (E) and then Denorm_On_Target;
10820 -------------------------------------------
10821 -- Has_Discriminant_Dependent_Constraint --
10822 -------------------------------------------
10824 function Has_Discriminant_Dependent_Constraint
10825 (Comp : Entity_Id) return Boolean
10827 Comp_Decl : constant Node_Id := Parent (Comp);
10828 Subt_Indic : Node_Id;
10833 -- Discriminants can't depend on discriminants
10835 if Ekind (Comp) = E_Discriminant then
10839 Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl));
10841 if Nkind (Subt_Indic) = N_Subtype_Indication then
10842 Constr := Constraint (Subt_Indic);
10844 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
10845 Assn := First (Constraints (Constr));
10846 while Present (Assn) loop
10847 case Nkind (Assn) is
10850 | N_Subtype_Indication
10852 if Depends_On_Discriminant (Assn) then
10856 when N_Discriminant_Association =>
10857 if Depends_On_Discriminant (Expression (Assn)) then
10872 end Has_Discriminant_Dependent_Constraint;
10874 --------------------------------------
10875 -- Has_Effectively_Volatile_Profile --
10876 --------------------------------------
10878 function Has_Effectively_Volatile_Profile
10879 (Subp_Id : Entity_Id) return Boolean
10881 Formal : Entity_Id;
10884 -- Inspect the formal parameters looking for an effectively volatile
10887 Formal := First_Formal (Subp_Id);
10888 while Present (Formal) loop
10889 if Is_Effectively_Volatile (Etype (Formal)) then
10893 Next_Formal (Formal);
10896 -- Inspect the return type of functions
10898 if Ekind_In (Subp_Id, E_Function, E_Generic_Function)
10899 and then Is_Effectively_Volatile (Etype (Subp_Id))
10905 end Has_Effectively_Volatile_Profile;
10907 --------------------------
10908 -- Has_Enabled_Property --
10909 --------------------------
10911 function Has_Enabled_Property
10912 (Item_Id : Entity_Id;
10913 Property : Name_Id) return Boolean
10915 function Protected_Object_Has_Enabled_Property return Boolean;
10916 -- Determine whether a protected object denoted by Item_Id has the
10917 -- property enabled.
10919 function State_Has_Enabled_Property return Boolean;
10920 -- Determine whether a state denoted by Item_Id has the property enabled
10922 function Variable_Has_Enabled_Property return Boolean;
10923 -- Determine whether a variable denoted by Item_Id has the property
10926 -------------------------------------------
10927 -- Protected_Object_Has_Enabled_Property --
10928 -------------------------------------------
10930 function Protected_Object_Has_Enabled_Property return Boolean is
10931 Constits : constant Elist_Id := Part_Of_Constituents (Item_Id);
10932 Constit_Elmt : Elmt_Id;
10933 Constit_Id : Entity_Id;
10936 -- Protected objects always have the properties Async_Readers and
10937 -- Async_Writers (SPARK RM 7.1.2(16)).
10939 if Property = Name_Async_Readers
10940 or else Property = Name_Async_Writers
10944 -- Protected objects that have Part_Of components also inherit their
10945 -- properties Effective_Reads and Effective_Writes
10946 -- (SPARK RM 7.1.2(16)).
10948 elsif Present (Constits) then
10949 Constit_Elmt := First_Elmt (Constits);
10950 while Present (Constit_Elmt) loop
10951 Constit_Id := Node (Constit_Elmt);
10953 if Has_Enabled_Property (Constit_Id, Property) then
10957 Next_Elmt (Constit_Elmt);
10962 end Protected_Object_Has_Enabled_Property;
10964 --------------------------------
10965 -- State_Has_Enabled_Property --
10966 --------------------------------
10968 function State_Has_Enabled_Property return Boolean is
10969 Decl : constant Node_Id := Parent (Item_Id);
10971 procedure Find_Simple_Properties
10972 (Has_External : out Boolean;
10973 Has_Synchronous : out Boolean);
10974 -- Extract the simple properties associated with declaration Decl
10976 function Is_Enabled_External_Property return Boolean;
10977 -- Determine whether property Property appears within the external
10978 -- property list of declaration Decl, and return its status.
10980 ----------------------------
10981 -- Find_Simple_Properties --
10982 ----------------------------
10984 procedure Find_Simple_Properties
10985 (Has_External : out Boolean;
10986 Has_Synchronous : out Boolean)
10991 -- Assume that none of the properties are available
10993 Has_External := False;
10994 Has_Synchronous := False;
10996 Opt := First (Expressions (Decl));
10997 while Present (Opt) loop
10998 if Nkind (Opt) = N_Identifier then
10999 if Chars (Opt) = Name_External then
11000 Has_External := True;
11002 elsif Chars (Opt) = Name_Synchronous then
11003 Has_Synchronous := True;
11009 end Find_Simple_Properties;
11011 ----------------------------------
11012 -- Is_Enabled_External_Property --
11013 ----------------------------------
11015 function Is_Enabled_External_Property return Boolean is
11019 Prop_Nam : Node_Id;
11023 Opt := First (Component_Associations (Decl));
11024 while Present (Opt) loop
11025 Opt_Nam := First (Choices (Opt));
11027 if Nkind (Opt_Nam) = N_Identifier
11028 and then Chars (Opt_Nam) = Name_External
11030 Props := Expression (Opt);
11032 -- Multiple properties appear as an aggregate
11034 if Nkind (Props) = N_Aggregate then
11036 -- Simple property form
11038 Prop := First (Expressions (Props));
11039 while Present (Prop) loop
11040 if Chars (Prop) = Property then
11047 -- Property with expression form
11049 Prop := First (Component_Associations (Props));
11050 while Present (Prop) loop
11051 Prop_Nam := First (Choices (Prop));
11053 -- The property can be represented in two ways:
11054 -- others => <value>
11055 -- <property> => <value>
11057 if Nkind (Prop_Nam) = N_Others_Choice
11058 or else (Nkind (Prop_Nam) = N_Identifier
11059 and then Chars (Prop_Nam) = Property)
11061 return Is_True (Expr_Value (Expression (Prop)));
11070 return Chars (Props) = Property;
11078 end Is_Enabled_External_Property;
11082 Has_External : Boolean;
11083 Has_Synchronous : Boolean;
11085 -- Start of processing for State_Has_Enabled_Property
11088 -- The declaration of an external abstract state appears as an
11089 -- extension aggregate. If this is not the case, properties can
11092 if Nkind (Decl) /= N_Extension_Aggregate then
11096 Find_Simple_Properties (Has_External, Has_Synchronous);
11098 -- Simple option External enables all properties (SPARK RM 7.1.2(2))
11100 if Has_External then
11103 -- Option External may enable or disable specific properties
11105 elsif Is_Enabled_External_Property then
11108 -- Simple option Synchronous
11110 -- enables disables
11111 -- Async_Readers Effective_Reads
11112 -- Async_Writers Effective_Writes
11114 -- Note that both forms of External have higher precedence than
11115 -- Synchronous (SPARK RM 7.1.4(9)).
11117 elsif Has_Synchronous then
11118 return Nam_In (Property, Name_Async_Readers, Name_Async_Writers);
11122 end State_Has_Enabled_Property;
11124 -----------------------------------
11125 -- Variable_Has_Enabled_Property --
11126 -----------------------------------
11128 function Variable_Has_Enabled_Property return Boolean is
11129 function Is_Enabled (Prag : Node_Id) return Boolean;
11130 -- Determine whether property pragma Prag (if present) denotes an
11131 -- enabled property.
11137 function Is_Enabled (Prag : Node_Id) return Boolean is
11141 if Present (Prag) then
11142 Arg1 := First (Pragma_Argument_Associations (Prag));
11144 -- The pragma has an optional Boolean expression, the related
11145 -- property is enabled only when the expression evaluates to
11148 if Present (Arg1) then
11149 return Is_True (Expr_Value (Get_Pragma_Arg (Arg1)));
11151 -- Otherwise the lack of expression enables the property by
11158 -- The property was never set in the first place
11167 AR : constant Node_Id :=
11168 Get_Pragma (Item_Id, Pragma_Async_Readers);
11169 AW : constant Node_Id :=
11170 Get_Pragma (Item_Id, Pragma_Async_Writers);
11171 ER : constant Node_Id :=
11172 Get_Pragma (Item_Id, Pragma_Effective_Reads);
11173 EW : constant Node_Id :=
11174 Get_Pragma (Item_Id, Pragma_Effective_Writes);
11176 -- Start of processing for Variable_Has_Enabled_Property
11179 -- A non-effectively volatile object can never possess external
11182 if not Is_Effectively_Volatile (Item_Id) then
11185 -- External properties related to variables come in two flavors -
11186 -- explicit and implicit. The explicit case is characterized by the
11187 -- presence of a property pragma with an optional Boolean flag. The
11188 -- property is enabled when the flag evaluates to True or the flag is
11189 -- missing altogether.
11191 elsif Property = Name_Async_Readers and then Is_Enabled (AR) then
11194 elsif Property = Name_Async_Writers and then Is_Enabled (AW) then
11197 elsif Property = Name_Effective_Reads and then Is_Enabled (ER) then
11200 elsif Property = Name_Effective_Writes and then Is_Enabled (EW) then
11203 -- The implicit case lacks all property pragmas
11205 elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then
11206 if Is_Protected_Type (Etype (Item_Id)) then
11207 return Protected_Object_Has_Enabled_Property;
11215 end Variable_Has_Enabled_Property;
11217 -- Start of processing for Has_Enabled_Property
11220 -- Abstract states and variables have a flexible scheme of specifying
11221 -- external properties.
11223 if Ekind (Item_Id) = E_Abstract_State then
11224 return State_Has_Enabled_Property;
11226 elsif Ekind (Item_Id) = E_Variable then
11227 return Variable_Has_Enabled_Property;
11229 -- By default, protected objects only have the properties Async_Readers
11230 -- and Async_Writers. If they have Part_Of components, they also inherit
11231 -- their properties Effective_Reads and Effective_Writes
11232 -- (SPARK RM 7.1.2(16)).
11234 elsif Ekind (Item_Id) = E_Protected_Object then
11235 return Protected_Object_Has_Enabled_Property;
11237 -- Otherwise a property is enabled when the related item is effectively
11241 return Is_Effectively_Volatile (Item_Id);
11243 end Has_Enabled_Property;
11245 -------------------------------------
11246 -- Has_Full_Default_Initialization --
11247 -------------------------------------
11249 function Has_Full_Default_Initialization (Typ : Entity_Id) return Boolean is
11253 -- A type subject to pragma Default_Initial_Condition may be fully
11254 -- default initialized depending on inheritance and the argument of
11255 -- the pragma. Since any type may act as the full view of a private
11256 -- type, this check must be performed prior to the specialized tests
11259 if Has_Fully_Default_Initializing_DIC_Pragma (Typ) then
11263 -- A scalar type is fully default initialized if it is subject to aspect
11266 if Is_Scalar_Type (Typ) then
11267 return Has_Default_Aspect (Typ);
11269 -- An access type is fully default initialized by default
11271 elsif Is_Access_Type (Typ) then
11274 -- An array type is fully default initialized if its element type is
11275 -- scalar and the array type carries aspect Default_Component_Value or
11276 -- the element type is fully default initialized.
11278 elsif Is_Array_Type (Typ) then
11280 Has_Default_Aspect (Typ)
11281 or else Has_Full_Default_Initialization (Component_Type (Typ));
11283 -- A protected type, record type, or type extension is fully default
11284 -- initialized if all its components either carry an initialization
11285 -- expression or have a type that is fully default initialized. The
11286 -- parent type of a type extension must be fully default initialized.
11288 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
11290 -- Inspect all entities defined in the scope of the type, looking for
11291 -- uninitialized components.
11293 Comp := First_Entity (Typ);
11294 while Present (Comp) loop
11295 if Ekind (Comp) = E_Component
11296 and then Comes_From_Source (Comp)
11297 and then No (Expression (Parent (Comp)))
11298 and then not Has_Full_Default_Initialization (Etype (Comp))
11303 Next_Entity (Comp);
11306 -- Ensure that the parent type of a type extension is fully default
11309 if Etype (Typ) /= Typ
11310 and then not Has_Full_Default_Initialization (Etype (Typ))
11315 -- If we get here, then all components and parent portion are fully
11316 -- default initialized.
11320 -- A task type is fully default initialized by default
11322 elsif Is_Task_Type (Typ) then
11325 -- Otherwise the type is not fully default initialized
11330 end Has_Full_Default_Initialization;
11332 -----------------------------------------------
11333 -- Has_Fully_Default_Initializing_DIC_Pragma --
11334 -----------------------------------------------
11336 function Has_Fully_Default_Initializing_DIC_Pragma
11337 (Typ : Entity_Id) return Boolean
11343 -- A type that inherits pragma Default_Initial_Condition from a parent
11344 -- type is automatically fully default initialized.
11346 if Has_Inherited_DIC (Typ) then
11349 -- Otherwise the type is fully default initialized only when the pragma
11350 -- appears without an argument, or the argument is non-null.
11352 elsif Has_Own_DIC (Typ) then
11353 Prag := Get_Pragma (Typ, Pragma_Default_Initial_Condition);
11354 pragma Assert (Present (Prag));
11355 Args := Pragma_Argument_Associations (Prag);
11357 -- The pragma appears without an argument in which case it defaults
11363 -- The pragma appears with a non-null expression
11365 elsif Nkind (Get_Pragma_Arg (First (Args))) /= N_Null then
11371 end Has_Fully_Default_Initializing_DIC_Pragma;
11373 --------------------
11374 -- Has_Infinities --
11375 --------------------
11377 function Has_Infinities (E : Entity_Id) return Boolean is
11380 Is_Floating_Point_Type (E)
11381 and then Nkind (Scalar_Range (E)) = N_Range
11382 and then Includes_Infinities (Scalar_Range (E));
11383 end Has_Infinities;
11385 --------------------
11386 -- Has_Interfaces --
11387 --------------------
11389 function Has_Interfaces
11391 Use_Full_View : Boolean := True) return Boolean
11393 Typ : Entity_Id := Base_Type (T);
11396 -- Handle concurrent types
11398 if Is_Concurrent_Type (Typ) then
11399 Typ := Corresponding_Record_Type (Typ);
11402 if not Present (Typ)
11403 or else not Is_Record_Type (Typ)
11404 or else not Is_Tagged_Type (Typ)
11409 -- Handle private types
11411 if Use_Full_View and then Present (Full_View (Typ)) then
11412 Typ := Full_View (Typ);
11415 -- Handle concurrent record types
11417 if Is_Concurrent_Record_Type (Typ)
11418 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
11424 if Is_Interface (Typ)
11426 (Is_Record_Type (Typ)
11427 and then Present (Interfaces (Typ))
11428 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
11433 exit when Etype (Typ) = Typ
11435 -- Handle private types
11437 or else (Present (Full_View (Etype (Typ)))
11438 and then Full_View (Etype (Typ)) = Typ)
11440 -- Protect frontend against wrong sources with cyclic derivations
11442 or else Etype (Typ) = T;
11444 -- Climb to the ancestor type handling private types
11446 if Present (Full_View (Etype (Typ))) then
11447 Typ := Full_View (Etype (Typ));
11449 Typ := Etype (Typ);
11454 end Has_Interfaces;
11456 --------------------------
11457 -- Has_Max_Queue_Length --
11458 --------------------------
11460 function Has_Max_Queue_Length (Id : Entity_Id) return Boolean is
11463 Ekind (Id) = E_Entry
11464 and then Present (Get_Pragma (Id, Pragma_Max_Queue_Length));
11465 end Has_Max_Queue_Length;
11467 ---------------------------------
11468 -- Has_No_Obvious_Side_Effects --
11469 ---------------------------------
11471 function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
11473 -- For now handle literals, constants, and non-volatile variables and
11474 -- expressions combining these with operators or short circuit forms.
11476 if Nkind (N) in N_Numeric_Or_String_Literal then
11479 elsif Nkind (N) = N_Character_Literal then
11482 elsif Nkind (N) in N_Unary_Op then
11483 return Has_No_Obvious_Side_Effects (Right_Opnd (N));
11485 elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
11486 return Has_No_Obvious_Side_Effects (Left_Opnd (N))
11488 Has_No_Obvious_Side_Effects (Right_Opnd (N));
11490 elsif Nkind (N) = N_Expression_With_Actions
11491 and then Is_Empty_List (Actions (N))
11493 return Has_No_Obvious_Side_Effects (Expression (N));
11495 elsif Nkind (N) in N_Has_Entity then
11496 return Present (Entity (N))
11497 and then Ekind_In (Entity (N), E_Variable,
11499 E_Enumeration_Literal,
11502 E_In_Out_Parameter)
11503 and then not Is_Volatile (Entity (N));
11508 end Has_No_Obvious_Side_Effects;
11510 -----------------------------
11511 -- Has_Non_Null_Refinement --
11512 -----------------------------
11514 function Has_Non_Null_Refinement (Id : Entity_Id) return Boolean is
11515 Constits : Elist_Id;
11518 pragma Assert (Ekind (Id) = E_Abstract_State);
11519 Constits := Refinement_Constituents (Id);
11521 -- For a refinement to be non-null, the first constituent must be
11522 -- anything other than null.
11526 and then Nkind (Node (First_Elmt (Constits))) /= N_Null;
11527 end Has_Non_Null_Refinement;
11529 -----------------------------
11530 -- Has_Non_Null_Statements --
11531 -----------------------------
11533 function Has_Non_Null_Statements (L : List_Id) return Boolean is
11537 if Is_Non_Empty_List (L) then
11541 if Nkind (Node) /= N_Null_Statement then
11546 exit when Node = Empty;
11551 end Has_Non_Null_Statements;
11553 ----------------------------------
11554 -- Has_Non_Trivial_Precondition --
11555 ----------------------------------
11557 function Has_Non_Trivial_Precondition (Subp : Entity_Id) return Boolean is
11558 Pre : constant Node_Id := Find_Aspect (Subp, Aspect_Pre);
11563 and then Class_Present (Pre)
11564 and then not Is_Entity_Name (Expression (Pre));
11565 end Has_Non_Trivial_Precondition;
11567 -------------------
11568 -- Has_Null_Body --
11569 -------------------
11571 function Has_Null_Body (Proc_Id : Entity_Id) return Boolean is
11572 Body_Id : Entity_Id;
11579 Spec := Parent (Proc_Id);
11580 Decl := Parent (Spec);
11582 -- Retrieve the entity of the procedure body (e.g. invariant proc).
11584 if Nkind (Spec) = N_Procedure_Specification
11585 and then Nkind (Decl) = N_Subprogram_Declaration
11587 Body_Id := Corresponding_Body (Decl);
11589 -- The body acts as a spec
11592 Body_Id := Proc_Id;
11595 -- The body will be generated later
11597 if No (Body_Id) then
11601 Spec := Parent (Body_Id);
11602 Decl := Parent (Spec);
11605 (Nkind (Spec) = N_Procedure_Specification
11606 and then Nkind (Decl) = N_Subprogram_Body);
11608 Stmt1 := First (Statements (Handled_Statement_Sequence (Decl)));
11610 -- Look for a null statement followed by an optional return
11613 if Nkind (Stmt1) = N_Null_Statement then
11614 Stmt2 := Next (Stmt1);
11616 if Present (Stmt2) then
11617 return Nkind (Stmt2) = N_Simple_Return_Statement;
11626 ------------------------
11627 -- Has_Null_Exclusion --
11628 ------------------------
11630 function Has_Null_Exclusion (N : Node_Id) return Boolean is
11633 when N_Access_Definition
11634 | N_Access_Function_Definition
11635 | N_Access_Procedure_Definition
11636 | N_Access_To_Object_Definition
11638 | N_Derived_Type_Definition
11639 | N_Function_Specification
11640 | N_Subtype_Declaration
11642 return Null_Exclusion_Present (N);
11644 when N_Component_Definition
11645 | N_Formal_Object_Declaration
11646 | N_Object_Renaming_Declaration
11648 if Present (Subtype_Mark (N)) then
11649 return Null_Exclusion_Present (N);
11650 else pragma Assert (Present (Access_Definition (N)));
11651 return Null_Exclusion_Present (Access_Definition (N));
11654 when N_Discriminant_Specification =>
11655 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
11656 return Null_Exclusion_Present (Discriminant_Type (N));
11658 return Null_Exclusion_Present (N);
11661 when N_Object_Declaration =>
11662 if Nkind (Object_Definition (N)) = N_Access_Definition then
11663 return Null_Exclusion_Present (Object_Definition (N));
11665 return Null_Exclusion_Present (N);
11668 when N_Parameter_Specification =>
11669 if Nkind (Parameter_Type (N)) = N_Access_Definition then
11670 return Null_Exclusion_Present (Parameter_Type (N));
11672 return Null_Exclusion_Present (N);
11678 end Has_Null_Exclusion;
11680 ------------------------
11681 -- Has_Null_Extension --
11682 ------------------------
11684 function Has_Null_Extension (T : Entity_Id) return Boolean is
11685 B : constant Entity_Id := Base_Type (T);
11690 if Nkind (Parent (B)) = N_Full_Type_Declaration
11691 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
11693 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
11695 if Present (Ext) then
11696 if Null_Present (Ext) then
11699 Comps := Component_List (Ext);
11701 -- The null component list is rewritten during analysis to
11702 -- include the parent component. Any other component indicates
11703 -- that the extension was not originally null.
11705 return Null_Present (Comps)
11706 or else No (Next (First (Component_Items (Comps))));
11715 end Has_Null_Extension;
11717 -------------------------
11718 -- Has_Null_Refinement --
11719 -------------------------
11721 function Has_Null_Refinement (Id : Entity_Id) return Boolean is
11722 Constits : Elist_Id;
11725 pragma Assert (Ekind (Id) = E_Abstract_State);
11726 Constits := Refinement_Constituents (Id);
11728 -- For a refinement to be null, the state's sole constituent must be a
11733 and then Nkind (Node (First_Elmt (Constits))) = N_Null;
11734 end Has_Null_Refinement;
11736 -------------------------------
11737 -- Has_Overriding_Initialize --
11738 -------------------------------
11740 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
11741 BT : constant Entity_Id := Base_Type (T);
11745 if Is_Controlled (BT) then
11746 if Is_RTU (Scope (BT), Ada_Finalization) then
11749 elsif Present (Primitive_Operations (BT)) then
11750 P := First_Elmt (Primitive_Operations (BT));
11751 while Present (P) loop
11753 Init : constant Entity_Id := Node (P);
11754 Formal : constant Entity_Id := First_Formal (Init);
11756 if Ekind (Init) = E_Procedure
11757 and then Chars (Init) = Name_Initialize
11758 and then Comes_From_Source (Init)
11759 and then Present (Formal)
11760 and then Etype (Formal) = BT
11761 and then No (Next_Formal (Formal))
11762 and then (Ada_Version < Ada_2012
11763 or else not Null_Present (Parent (Init)))
11773 -- Here if type itself does not have a non-null Initialize operation:
11774 -- check immediate ancestor.
11776 if Is_Derived_Type (BT)
11777 and then Has_Overriding_Initialize (Etype (BT))
11784 end Has_Overriding_Initialize;
11786 --------------------------------------
11787 -- Has_Preelaborable_Initialization --
11788 --------------------------------------
11790 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
11793 procedure Check_Components (E : Entity_Id);
11794 -- Check component/discriminant chain, sets Has_PE False if a component
11795 -- or discriminant does not meet the preelaborable initialization rules.
11797 ----------------------
11798 -- Check_Components --
11799 ----------------------
11801 procedure Check_Components (E : Entity_Id) is
11806 -- Loop through entities of record or protected type
11809 while Present (Ent) loop
11811 -- We are interested only in components and discriminants
11815 case Ekind (Ent) is
11816 when E_Component =>
11818 -- Get default expression if any. If there is no declaration
11819 -- node, it means we have an internal entity. The parent and
11820 -- tag fields are examples of such entities. For such cases,
11821 -- we just test the type of the entity.
11823 if Present (Declaration_Node (Ent)) then
11824 Exp := Expression (Declaration_Node (Ent));
11827 when E_Discriminant =>
11829 -- Note: for a renamed discriminant, the Declaration_Node
11830 -- may point to the one from the ancestor, and have a
11831 -- different expression, so use the proper attribute to
11832 -- retrieve the expression from the derived constraint.
11834 Exp := Discriminant_Default_Value (Ent);
11837 goto Check_Next_Entity;
11840 -- A component has PI if it has no default expression and the
11841 -- component type has PI.
11844 if not Has_Preelaborable_Initialization (Etype (Ent)) then
11849 -- Require the default expression to be preelaborable
11851 elsif not Is_Preelaborable_Construct (Exp) then
11856 <<Check_Next_Entity>>
11859 end Check_Components;
11861 -- Start of processing for Has_Preelaborable_Initialization
11864 -- Immediate return if already marked as known preelaborable init. This
11865 -- covers types for which this function has already been called once
11866 -- and returned True (in which case the result is cached), and also
11867 -- types to which a pragma Preelaborable_Initialization applies.
11869 if Known_To_Have_Preelab_Init (E) then
11873 -- If the type is a subtype representing a generic actual type, then
11874 -- test whether its base type has preelaborable initialization since
11875 -- the subtype representing the actual does not inherit this attribute
11876 -- from the actual or formal. (but maybe it should???)
11878 if Is_Generic_Actual_Type (E) then
11879 return Has_Preelaborable_Initialization (Base_Type (E));
11882 -- All elementary types have preelaborable initialization
11884 if Is_Elementary_Type (E) then
11887 -- Array types have PI if the component type has PI
11889 elsif Is_Array_Type (E) then
11890 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
11892 -- A derived type has preelaborable initialization if its parent type
11893 -- has preelaborable initialization and (in the case of a derived record
11894 -- extension) if the non-inherited components all have preelaborable
11895 -- initialization. However, a user-defined controlled type with an
11896 -- overriding Initialize procedure does not have preelaborable
11899 elsif Is_Derived_Type (E) then
11901 -- If the derived type is a private extension then it doesn't have
11902 -- preelaborable initialization.
11904 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
11908 -- First check whether ancestor type has preelaborable initialization
11910 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
11912 -- If OK, check extension components (if any)
11914 if Has_PE and then Is_Record_Type (E) then
11915 Check_Components (First_Entity (E));
11918 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
11919 -- with a user defined Initialize procedure does not have PI. If
11920 -- the type is untagged, the control primitives come from a component
11921 -- that has already been checked.
11924 and then Is_Controlled (E)
11925 and then Is_Tagged_Type (E)
11926 and then Has_Overriding_Initialize (E)
11931 -- Private types not derived from a type having preelaborable init and
11932 -- that are not marked with pragma Preelaborable_Initialization do not
11933 -- have preelaborable initialization.
11935 elsif Is_Private_Type (E) then
11938 -- Record type has PI if it is non private and all components have PI
11940 elsif Is_Record_Type (E) then
11942 Check_Components (First_Entity (E));
11944 -- Protected types must not have entries, and components must meet
11945 -- same set of rules as for record components.
11947 elsif Is_Protected_Type (E) then
11948 if Has_Entries (E) then
11952 Check_Components (First_Entity (E));
11953 Check_Components (First_Private_Entity (E));
11956 -- Type System.Address always has preelaborable initialization
11958 elsif Is_RTE (E, RE_Address) then
11961 -- In all other cases, type does not have preelaborable initialization
11967 -- If type has preelaborable initialization, cache result
11970 Set_Known_To_Have_Preelab_Init (E);
11974 end Has_Preelaborable_Initialization;
11980 function Has_Prefix (N : Node_Id) return Boolean is
11983 Nkind_In (N, N_Attribute_Reference,
11985 N_Explicit_Dereference,
11986 N_Indexed_Component,
11988 N_Selected_Component,
11992 ---------------------------
11993 -- Has_Private_Component --
11994 ---------------------------
11996 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
11997 Btype : Entity_Id := Base_Type (Type_Id);
11998 Component : Entity_Id;
12001 if Error_Posted (Type_Id)
12002 or else Error_Posted (Btype)
12007 if Is_Class_Wide_Type (Btype) then
12008 Btype := Root_Type (Btype);
12011 if Is_Private_Type (Btype) then
12013 UT : constant Entity_Id := Underlying_Type (Btype);
12016 if No (Full_View (Btype)) then
12017 return not Is_Generic_Type (Btype)
12019 not Is_Generic_Type (Root_Type (Btype));
12021 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
12024 return not Is_Frozen (UT) and then Has_Private_Component (UT);
12028 elsif Is_Array_Type (Btype) then
12029 return Has_Private_Component (Component_Type (Btype));
12031 elsif Is_Record_Type (Btype) then
12032 Component := First_Component (Btype);
12033 while Present (Component) loop
12034 if Has_Private_Component (Etype (Component)) then
12038 Next_Component (Component);
12043 elsif Is_Protected_Type (Btype)
12044 and then Present (Corresponding_Record_Type (Btype))
12046 return Has_Private_Component (Corresponding_Record_Type (Btype));
12051 end Has_Private_Component;
12053 ----------------------
12054 -- Has_Signed_Zeros --
12055 ----------------------
12057 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
12059 return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target;
12060 end Has_Signed_Zeros;
12062 ------------------------------
12063 -- Has_Significant_Contract --
12064 ------------------------------
12066 function Has_Significant_Contract (Subp_Id : Entity_Id) return Boolean is
12067 Subp_Nam : constant Name_Id := Chars (Subp_Id);
12070 -- _Finalizer procedure
12072 if Subp_Nam = Name_uFinalizer then
12075 -- _Postconditions procedure
12077 elsif Subp_Nam = Name_uPostconditions then
12080 -- Predicate function
12082 elsif Ekind (Subp_Id) = E_Function
12083 and then Is_Predicate_Function (Subp_Id)
12089 elsif Get_TSS_Name (Subp_Id) /= TSS_Null then
12095 end Has_Significant_Contract;
12097 -----------------------------
12098 -- Has_Static_Array_Bounds --
12099 -----------------------------
12101 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
12102 All_Static : Boolean;
12106 Examine_Array_Bounds (Typ, All_Static, Dummy);
12109 end Has_Static_Array_Bounds;
12111 ---------------------------------------
12112 -- Has_Static_Non_Empty_Array_Bounds --
12113 ---------------------------------------
12115 function Has_Static_Non_Empty_Array_Bounds (Typ : Node_Id) return Boolean is
12116 All_Static : Boolean;
12117 Has_Empty : Boolean;
12120 Examine_Array_Bounds (Typ, All_Static, Has_Empty);
12122 return All_Static and not Has_Empty;
12123 end Has_Static_Non_Empty_Array_Bounds;
12129 function Has_Stream (T : Entity_Id) return Boolean is
12136 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
12139 elsif Is_Array_Type (T) then
12140 return Has_Stream (Component_Type (T));
12142 elsif Is_Record_Type (T) then
12143 E := First_Component (T);
12144 while Present (E) loop
12145 if Has_Stream (Etype (E)) then
12148 Next_Component (E);
12154 elsif Is_Private_Type (T) then
12155 return Has_Stream (Underlying_Type (T));
12166 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
12168 Get_Name_String (Chars (E));
12169 return Name_Buffer (Name_Len) = Suffix;
12176 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
12178 Get_Name_String (Chars (E));
12179 Add_Char_To_Name_Buffer (Suffix);
12183 -------------------
12184 -- Remove_Suffix --
12185 -------------------
12187 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
12189 pragma Assert (Has_Suffix (E, Suffix));
12190 Get_Name_String (Chars (E));
12191 Name_Len := Name_Len - 1;
12195 ----------------------------------
12196 -- Replace_Null_By_Null_Address --
12197 ----------------------------------
12199 procedure Replace_Null_By_Null_Address (N : Node_Id) is
12200 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id);
12201 -- Replace operand Op with a reference to Null_Address when the operand
12202 -- denotes a null Address. Other_Op denotes the other operand.
12204 --------------------------
12205 -- Replace_Null_Operand --
12206 --------------------------
12208 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id) is
12210 -- Check the type of the complementary operand since the N_Null node
12211 -- has not been decorated yet.
12213 if Nkind (Op) = N_Null
12214 and then Is_Descendant_Of_Address (Etype (Other_Op))
12216 Rewrite (Op, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (Op)));
12218 end Replace_Null_Operand;
12220 -- Start of processing for Replace_Null_By_Null_Address
12223 pragma Assert (Relaxed_RM_Semantics);
12224 pragma Assert (Nkind_In (N, N_Null,
12232 if Nkind (N) = N_Null then
12233 Rewrite (N, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (N)));
12237 L : constant Node_Id := Left_Opnd (N);
12238 R : constant Node_Id := Right_Opnd (N);
12241 Replace_Null_Operand (L, Other_Op => R);
12242 Replace_Null_Operand (R, Other_Op => L);
12245 end Replace_Null_By_Null_Address;
12247 --------------------------
12248 -- Has_Tagged_Component --
12249 --------------------------
12251 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
12255 if Is_Private_Type (Typ) and then Present (Underlying_Type (Typ)) then
12256 return Has_Tagged_Component (Underlying_Type (Typ));
12258 elsif Is_Array_Type (Typ) then
12259 return Has_Tagged_Component (Component_Type (Typ));
12261 elsif Is_Tagged_Type (Typ) then
12264 elsif Is_Record_Type (Typ) then
12265 Comp := First_Component (Typ);
12266 while Present (Comp) loop
12267 if Has_Tagged_Component (Etype (Comp)) then
12271 Next_Component (Comp);
12279 end Has_Tagged_Component;
12281 -----------------------------
12282 -- Has_Undefined_Reference --
12283 -----------------------------
12285 function Has_Undefined_Reference (Expr : Node_Id) return Boolean is
12286 Has_Undef_Ref : Boolean := False;
12287 -- Flag set when expression Expr contains at least one undefined
12290 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result;
12291 -- Determine whether N denotes a reference and if it does, whether it is
12294 ----------------------------
12295 -- Is_Undefined_Reference --
12296 ----------------------------
12298 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result is
12300 if Is_Entity_Name (N)
12301 and then Present (Entity (N))
12302 and then Entity (N) = Any_Id
12304 Has_Undef_Ref := True;
12309 end Is_Undefined_Reference;
12311 procedure Find_Undefined_References is
12312 new Traverse_Proc (Is_Undefined_Reference);
12314 -- Start of processing for Has_Undefined_Reference
12317 Find_Undefined_References (Expr);
12319 return Has_Undef_Ref;
12320 end Has_Undefined_Reference;
12322 ----------------------------
12323 -- Has_Volatile_Component --
12324 ----------------------------
12326 function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
12330 if Has_Volatile_Components (Typ) then
12333 elsif Is_Array_Type (Typ) then
12334 return Is_Volatile (Component_Type (Typ));
12336 elsif Is_Record_Type (Typ) then
12337 Comp := First_Component (Typ);
12338 while Present (Comp) loop
12339 if Is_Volatile_Object (Comp) then
12343 Comp := Next_Component (Comp);
12348 end Has_Volatile_Component;
12350 -------------------------
12351 -- Implementation_Kind --
12352 -------------------------
12354 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
12355 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
12358 pragma Assert (Present (Impl_Prag));
12359 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
12360 return Chars (Get_Pragma_Arg (Arg));
12361 end Implementation_Kind;
12363 --------------------------
12364 -- Implements_Interface --
12365 --------------------------
12367 function Implements_Interface
12368 (Typ_Ent : Entity_Id;
12369 Iface_Ent : Entity_Id;
12370 Exclude_Parents : Boolean := False) return Boolean
12372 Ifaces_List : Elist_Id;
12374 Iface : Entity_Id := Base_Type (Iface_Ent);
12375 Typ : Entity_Id := Base_Type (Typ_Ent);
12378 if Is_Class_Wide_Type (Typ) then
12379 Typ := Root_Type (Typ);
12382 if not Has_Interfaces (Typ) then
12386 if Is_Class_Wide_Type (Iface) then
12387 Iface := Root_Type (Iface);
12390 Collect_Interfaces (Typ, Ifaces_List);
12392 Elmt := First_Elmt (Ifaces_List);
12393 while Present (Elmt) loop
12394 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
12395 and then Exclude_Parents
12399 elsif Node (Elmt) = Iface then
12407 end Implements_Interface;
12409 ------------------------------------
12410 -- In_Assertion_Expression_Pragma --
12411 ------------------------------------
12413 function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is
12415 Prag : Node_Id := Empty;
12418 -- Climb the parent chain looking for an enclosing pragma
12421 while Present (Par) loop
12422 if Nkind (Par) = N_Pragma then
12426 -- Precondition-like pragmas are expanded into if statements, check
12427 -- the original node instead.
12429 elsif Nkind (Original_Node (Par)) = N_Pragma then
12430 Prag := Original_Node (Par);
12433 -- The expansion of attribute 'Old generates a constant to capture
12434 -- the result of the prefix. If the parent traversal reaches
12435 -- one of these constants, then the node technically came from a
12436 -- postcondition-like pragma. Note that the Ekind is not tested here
12437 -- because N may be the expression of an object declaration which is
12438 -- currently being analyzed. Such objects carry Ekind of E_Void.
12440 elsif Nkind (Par) = N_Object_Declaration
12441 and then Constant_Present (Par)
12442 and then Stores_Attribute_Old_Prefix (Defining_Entity (Par))
12446 -- Prevent the search from going too far
12448 elsif Is_Body_Or_Package_Declaration (Par) then
12452 Par := Parent (Par);
12457 and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag));
12458 end In_Assertion_Expression_Pragma;
12460 ----------------------
12461 -- In_Generic_Scope --
12462 ----------------------
12464 function In_Generic_Scope (E : Entity_Id) return Boolean is
12469 while Present (S) and then S /= Standard_Standard loop
12470 if Is_Generic_Unit (S) then
12478 end In_Generic_Scope;
12484 function In_Instance return Boolean is
12485 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
12489 S := Current_Scope;
12490 while Present (S) and then S /= Standard_Standard loop
12491 if Is_Generic_Instance (S) then
12493 -- A child instance is always compiled in the context of a parent
12494 -- instance. Nevertheless, its actuals must not be analyzed in an
12495 -- instance context. We detect this case by examining the current
12496 -- compilation unit, which must be a child instance, and checking
12497 -- that it has not been analyzed yet.
12499 if Is_Child_Unit (Curr_Unit)
12500 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
12501 N_Package_Instantiation
12502 and then Ekind (Curr_Unit) = E_Void
12516 ----------------------
12517 -- In_Instance_Body --
12518 ----------------------
12520 function In_Instance_Body return Boolean is
12524 S := Current_Scope;
12525 while Present (S) and then S /= Standard_Standard loop
12526 if Ekind_In (S, E_Function, E_Procedure)
12527 and then Is_Generic_Instance (S)
12531 elsif Ekind (S) = E_Package
12532 and then In_Package_Body (S)
12533 and then Is_Generic_Instance (S)
12542 end In_Instance_Body;
12544 -----------------------------
12545 -- In_Instance_Not_Visible --
12546 -----------------------------
12548 function In_Instance_Not_Visible return Boolean is
12552 S := Current_Scope;
12553 while Present (S) and then S /= Standard_Standard loop
12554 if Ekind_In (S, E_Function, E_Procedure)
12555 and then Is_Generic_Instance (S)
12559 elsif Ekind (S) = E_Package
12560 and then (In_Package_Body (S) or else In_Private_Part (S))
12561 and then Is_Generic_Instance (S)
12570 end In_Instance_Not_Visible;
12572 ------------------------------
12573 -- In_Instance_Visible_Part --
12574 ------------------------------
12576 function In_Instance_Visible_Part
12577 (Id : Entity_Id := Current_Scope) return Boolean
12583 while Present (Inst) and then Inst /= Standard_Standard loop
12584 if Ekind (Inst) = E_Package
12585 and then Is_Generic_Instance (Inst)
12586 and then not In_Package_Body (Inst)
12587 and then not In_Private_Part (Inst)
12592 Inst := Scope (Inst);
12596 end In_Instance_Visible_Part;
12598 ---------------------
12599 -- In_Package_Body --
12600 ---------------------
12602 function In_Package_Body return Boolean is
12606 S := Current_Scope;
12607 while Present (S) and then S /= Standard_Standard loop
12608 if Ekind (S) = E_Package and then In_Package_Body (S) then
12616 end In_Package_Body;
12618 --------------------------
12619 -- In_Pragma_Expression --
12620 --------------------------
12622 function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean is
12629 elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
12635 end In_Pragma_Expression;
12637 ---------------------------
12638 -- In_Pre_Post_Condition --
12639 ---------------------------
12641 function In_Pre_Post_Condition (N : Node_Id) return Boolean is
12643 Prag : Node_Id := Empty;
12644 Prag_Id : Pragma_Id;
12647 -- Climb the parent chain looking for an enclosing pragma
12650 while Present (Par) loop
12651 if Nkind (Par) = N_Pragma then
12655 -- Prevent the search from going too far
12657 elsif Is_Body_Or_Package_Declaration (Par) then
12661 Par := Parent (Par);
12664 if Present (Prag) then
12665 Prag_Id := Get_Pragma_Id (Prag);
12668 Prag_Id = Pragma_Post
12669 or else Prag_Id = Pragma_Post_Class
12670 or else Prag_Id = Pragma_Postcondition
12671 or else Prag_Id = Pragma_Pre
12672 or else Prag_Id = Pragma_Pre_Class
12673 or else Prag_Id = Pragma_Precondition;
12675 -- Otherwise the node is not enclosed by a pre/postcondition pragma
12680 end In_Pre_Post_Condition;
12682 ------------------------------
12683 -- In_Quantified_Expression --
12684 ------------------------------
12686 function In_Quantified_Expression (N : Node_Id) return Boolean is
12693 elsif Nkind (P) = N_Quantified_Expression then
12699 end In_Quantified_Expression;
12701 -------------------------------------
12702 -- In_Reverse_Storage_Order_Object --
12703 -------------------------------------
12705 function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
12707 Btyp : Entity_Id := Empty;
12710 -- Climb up indexed components
12714 case Nkind (Pref) is
12715 when N_Selected_Component =>
12716 Pref := Prefix (Pref);
12719 when N_Indexed_Component =>
12720 Pref := Prefix (Pref);
12728 if Present (Pref) then
12729 Btyp := Base_Type (Etype (Pref));
12732 return Present (Btyp)
12733 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
12734 and then Reverse_Storage_Order (Btyp);
12735 end In_Reverse_Storage_Order_Object;
12737 ------------------------------
12738 -- In_Same_Declarative_Part --
12739 ------------------------------
12741 function In_Same_Declarative_Part
12742 (Context : Node_Id;
12743 N : Node_Id) return Boolean
12745 Cont : Node_Id := Context;
12749 if Nkind (Cont) = N_Compilation_Unit_Aux then
12750 Cont := Parent (Cont);
12754 while Present (Nod) loop
12758 elsif Nkind_In (Nod, N_Accept_Statement,
12760 N_Compilation_Unit,
12763 N_Package_Declaration,
12770 elsif Nkind (Nod) = N_Subunit then
12771 Nod := Corresponding_Stub (Nod);
12774 Nod := Parent (Nod);
12779 end In_Same_Declarative_Part;
12781 --------------------------------------
12782 -- In_Subprogram_Or_Concurrent_Unit --
12783 --------------------------------------
12785 function In_Subprogram_Or_Concurrent_Unit return Boolean is
12790 -- Use scope chain to check successively outer scopes
12792 E := Current_Scope;
12796 if K in Subprogram_Kind
12797 or else K in Concurrent_Kind
12798 or else K in Generic_Subprogram_Kind
12802 elsif E = Standard_Standard then
12808 end In_Subprogram_Or_Concurrent_Unit;
12814 function In_Subtree (N : Node_Id; Root : Node_Id) return Boolean is
12819 while Present (Curr) loop
12820 if Curr = Root then
12824 Curr := Parent (Curr);
12834 function In_Subtree
12837 Root2 : Node_Id) return Boolean
12843 while Present (Curr) loop
12844 if Curr = Root1 or else Curr = Root2 then
12848 Curr := Parent (Curr);
12854 ---------------------
12855 -- In_Visible_Part --
12856 ---------------------
12858 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
12860 return Is_Package_Or_Generic_Package (Scope_Id)
12861 and then In_Open_Scopes (Scope_Id)
12862 and then not In_Package_Body (Scope_Id)
12863 and then not In_Private_Part (Scope_Id);
12864 end In_Visible_Part;
12866 -----------------------------
12867 -- In_While_Loop_Condition --
12868 -----------------------------
12870 function In_While_Loop_Condition (N : Node_Id) return Boolean is
12871 Prev : Node_Id := N;
12872 P : Node_Id := Parent (N);
12873 -- P and Prev will be used for traversing the AST, while maintaining an
12874 -- invariant that P = Parent (Prev).
12879 elsif Nkind (P) = N_Iteration_Scheme
12880 and then Prev = Condition (P)
12888 end In_While_Loop_Condition;
12890 --------------------------------
12891 -- Incomplete_Or_Partial_View --
12892 --------------------------------
12894 function Incomplete_Or_Partial_View (Id : Entity_Id) return Entity_Id is
12895 function Inspect_Decls
12897 Taft : Boolean := False) return Entity_Id;
12898 -- Check whether a declarative region contains the incomplete or partial
12901 -------------------
12902 -- Inspect_Decls --
12903 -------------------
12905 function Inspect_Decls
12907 Taft : Boolean := False) return Entity_Id
12913 Decl := First (Decls);
12914 while Present (Decl) loop
12917 -- The partial view of a Taft-amendment type is an incomplete
12921 if Nkind (Decl) = N_Incomplete_Type_Declaration then
12922 Match := Defining_Identifier (Decl);
12925 -- Otherwise look for a private type whose full view matches the
12926 -- input type. Note that this checks full_type_declaration nodes
12927 -- to account for derivations from a private type where the type
12928 -- declaration hold the partial view and the full view is an
12931 elsif Nkind_In (Decl, N_Full_Type_Declaration,
12932 N_Private_Extension_Declaration,
12933 N_Private_Type_Declaration)
12935 Match := Defining_Identifier (Decl);
12938 -- Guard against unanalyzed entities
12941 and then Is_Type (Match)
12942 and then Present (Full_View (Match))
12943 and then Full_View (Match) = Id
12958 -- Start of processing for Incomplete_Or_Partial_View
12961 -- Deferred constant or incomplete type case
12963 Prev := Current_Entity_In_Scope (Id);
12966 and then (Is_Incomplete_Type (Prev) or else Ekind (Prev) = E_Constant)
12967 and then Present (Full_View (Prev))
12968 and then Full_View (Prev) = Id
12973 -- Private or Taft amendment type case
12976 Pkg : constant Entity_Id := Scope (Id);
12977 Pkg_Decl : Node_Id := Pkg;
12981 and then Ekind_In (Pkg, E_Generic_Package, E_Package)
12983 while Nkind (Pkg_Decl) /= N_Package_Specification loop
12984 Pkg_Decl := Parent (Pkg_Decl);
12987 -- It is knows that Typ has a private view, look for it in the
12988 -- visible declarations of the enclosing scope. A special case
12989 -- of this is when the two views have been exchanged - the full
12990 -- appears earlier than the private.
12992 if Has_Private_Declaration (Id) then
12993 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
12995 -- Exchanged view case, look in the private declarations
12998 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
13003 -- Otherwise if this is the package body, then Typ is a potential
13004 -- Taft amendment type. The incomplete view should be located in
13005 -- the private declarations of the enclosing scope.
13007 elsif In_Package_Body (Pkg) then
13008 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
13013 -- The type has no incomplete or private view
13016 end Incomplete_Or_Partial_View;
13018 ---------------------------------------
13019 -- Incomplete_View_From_Limited_With --
13020 ---------------------------------------
13022 function Incomplete_View_From_Limited_With
13023 (Typ : Entity_Id) return Entity_Id
13026 -- It might make sense to make this an attribute in Einfo, and set it
13027 -- in Sem_Ch10 in Build_Shadow_Entity. However, we're running short on
13028 -- slots for new attributes, and it seems a bit simpler to just search
13029 -- the Limited_View (if it exists) for an incomplete type whose
13030 -- Non_Limited_View is Typ.
13032 if Ekind (Scope (Typ)) = E_Package
13033 and then Present (Limited_View (Scope (Typ)))
13036 Ent : Entity_Id := First_Entity (Limited_View (Scope (Typ)));
13038 while Present (Ent) loop
13039 if Ekind (Ent) in Incomplete_Kind
13040 and then Non_Limited_View (Ent) = Typ
13045 Ent := Next_Entity (Ent);
13051 end Incomplete_View_From_Limited_With;
13053 ----------------------------------
13054 -- Indexed_Component_Bit_Offset --
13055 ----------------------------------
13057 function Indexed_Component_Bit_Offset (N : Node_Id) return Uint is
13058 Exp : constant Node_Id := First (Expressions (N));
13059 Typ : constant Entity_Id := Etype (Prefix (N));
13060 Off : constant Uint := Component_Size (Typ);
13064 -- Return early if the component size is not known or variable
13066 if Off = No_Uint or else Off < Uint_0 then
13070 -- Deal with the degenerate case of an empty component
13072 if Off = Uint_0 then
13076 -- Check that both the index value and the low bound are known
13078 if not Compile_Time_Known_Value (Exp) then
13082 Ind := First_Index (Typ);
13087 if Nkind (Ind) = N_Subtype_Indication then
13088 Ind := Constraint (Ind);
13090 if Nkind (Ind) = N_Range_Constraint then
13091 Ind := Range_Expression (Ind);
13095 if Nkind (Ind) /= N_Range
13096 or else not Compile_Time_Known_Value (Low_Bound (Ind))
13101 -- Return the scaled offset
13103 return Off * (Expr_Value (Exp) - Expr_Value (Low_Bound ((Ind))));
13104 end Indexed_Component_Bit_Offset;
13106 ----------------------------
13107 -- Inherit_Rep_Item_Chain --
13108 ----------------------------
13110 procedure Inherit_Rep_Item_Chain (Typ : Entity_Id; From_Typ : Entity_Id) is
13112 Next_Item : Node_Id;
13115 -- There are several inheritance scenarios to consider depending on
13116 -- whether both types have rep item chains and whether the destination
13117 -- type already inherits part of the source type's rep item chain.
13119 -- 1) The source type lacks a rep item chain
13120 -- From_Typ ---> Empty
13122 -- Typ --------> Item (or Empty)
13124 -- In this case inheritance cannot take place because there are no items
13127 -- 2) The destination type lacks a rep item chain
13128 -- From_Typ ---> Item ---> ...
13130 -- Typ --------> Empty
13132 -- Inheritance takes place by setting the First_Rep_Item of the
13133 -- destination type to the First_Rep_Item of the source type.
13134 -- From_Typ ---> Item ---> ...
13136 -- Typ -----------+
13138 -- 3.1) Both source and destination types have at least one rep item.
13139 -- The destination type does NOT inherit a rep item from the source
13141 -- From_Typ ---> Item ---> Item
13143 -- Typ --------> Item ---> Item
13145 -- Inheritance takes place by setting the Next_Rep_Item of the last item
13146 -- of the destination type to the First_Rep_Item of the source type.
13147 -- From_Typ -------------------> Item ---> Item
13149 -- Typ --------> Item ---> Item --+
13151 -- 3.2) Both source and destination types have at least one rep item.
13152 -- The destination type DOES inherit part of the rep item chain of the
13154 -- From_Typ ---> Item ---> Item ---> Item
13156 -- Typ --------> Item ------+
13158 -- This rare case arises when the full view of a private extension must
13159 -- inherit the rep item chain from the full view of its parent type and
13160 -- the full view of the parent type contains extra rep items. Currently
13161 -- only invariants may lead to such form of inheritance.
13163 -- type From_Typ is tagged private
13164 -- with Type_Invariant'Class => Item_2;
13166 -- type Typ is new From_Typ with private
13167 -- with Type_Invariant => Item_4;
13169 -- At this point the rep item chains contain the following items
13171 -- From_Typ -----------> Item_2 ---> Item_3
13173 -- Typ --------> Item_4 --+
13175 -- The full views of both types may introduce extra invariants
13177 -- type From_Typ is tagged null record
13178 -- with Type_Invariant => Item_1;
13180 -- type Typ is new From_Typ with null record;
13182 -- The full view of Typ would have to inherit any new rep items added to
13183 -- the full view of From_Typ.
13185 -- From_Typ -----------> Item_1 ---> Item_2 ---> Item_3
13187 -- Typ --------> Item_4 --+
13189 -- To achieve this form of inheritance, the destination type must first
13190 -- sever the link between its own rep chain and that of the source type,
13191 -- then inheritance 3.1 takes place.
13193 -- Case 1: The source type lacks a rep item chain
13195 if No (First_Rep_Item (From_Typ)) then
13198 -- Case 2: The destination type lacks a rep item chain
13200 elsif No (First_Rep_Item (Typ)) then
13201 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
13203 -- Case 3: Both the source and destination types have at least one rep
13204 -- item. Traverse the rep item chain of the destination type to find the
13209 Next_Item := First_Rep_Item (Typ);
13210 while Present (Next_Item) loop
13212 -- Detect a link between the destination type's rep chain and that
13213 -- of the source type. There are two possibilities:
13218 -- From_Typ ---> Item_1 --->
13220 -- Typ -----------+
13227 -- From_Typ ---> Item_1 ---> Item_2 --->
13229 -- Typ --------> Item_3 ------+
13233 if Has_Rep_Item (From_Typ, Next_Item) then
13238 Next_Item := Next_Rep_Item (Next_Item);
13241 -- Inherit the source type's rep item chain
13243 if Present (Item) then
13244 Set_Next_Rep_Item (Item, First_Rep_Item (From_Typ));
13246 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
13249 end Inherit_Rep_Item_Chain;
13251 ------------------------------------
13252 -- Inherits_From_Tagged_Full_View --
13253 ------------------------------------
13255 function Inherits_From_Tagged_Full_View (Typ : Entity_Id) return Boolean is
13257 return Is_Private_Type (Typ)
13258 and then Present (Full_View (Typ))
13259 and then Is_Private_Type (Full_View (Typ))
13260 and then not Is_Tagged_Type (Full_View (Typ))
13261 and then Present (Underlying_Type (Full_View (Typ)))
13262 and then Is_Tagged_Type (Underlying_Type (Full_View (Typ)));
13263 end Inherits_From_Tagged_Full_View;
13265 ---------------------------------
13266 -- Insert_Explicit_Dereference --
13267 ---------------------------------
13269 procedure Insert_Explicit_Dereference (N : Node_Id) is
13270 New_Prefix : constant Node_Id := Relocate_Node (N);
13271 Ent : Entity_Id := Empty;
13278 Save_Interps (N, New_Prefix);
13281 Make_Explicit_Dereference (Sloc (Parent (N)),
13282 Prefix => New_Prefix));
13284 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
13286 if Is_Overloaded (New_Prefix) then
13288 -- The dereference is also overloaded, and its interpretations are
13289 -- the designated types of the interpretations of the original node.
13291 Set_Etype (N, Any_Type);
13293 Get_First_Interp (New_Prefix, I, It);
13294 while Present (It.Nam) loop
13297 if Is_Access_Type (T) then
13298 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
13301 Get_Next_Interp (I, It);
13307 -- Prefix is unambiguous: mark the original prefix (which might
13308 -- Come_From_Source) as a reference, since the new (relocated) one
13309 -- won't be taken into account.
13311 if Is_Entity_Name (New_Prefix) then
13312 Ent := Entity (New_Prefix);
13313 Pref := New_Prefix;
13315 -- For a retrieval of a subcomponent of some composite object,
13316 -- retrieve the ultimate entity if there is one.
13318 elsif Nkind_In (New_Prefix, N_Selected_Component,
13319 N_Indexed_Component)
13321 Pref := Prefix (New_Prefix);
13322 while Present (Pref)
13323 and then Nkind_In (Pref, N_Selected_Component,
13324 N_Indexed_Component)
13326 Pref := Prefix (Pref);
13329 if Present (Pref) and then Is_Entity_Name (Pref) then
13330 Ent := Entity (Pref);
13334 -- Place the reference on the entity node
13336 if Present (Ent) then
13337 Generate_Reference (Ent, Pref);
13340 end Insert_Explicit_Dereference;
13342 ------------------------------------------
13343 -- Inspect_Deferred_Constant_Completion --
13344 ------------------------------------------
13346 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
13350 Decl := First (Decls);
13351 while Present (Decl) loop
13353 -- Deferred constant signature
13355 if Nkind (Decl) = N_Object_Declaration
13356 and then Constant_Present (Decl)
13357 and then No (Expression (Decl))
13359 -- No need to check internally generated constants
13361 and then Comes_From_Source (Decl)
13363 -- The constant is not completed. A full object declaration or a
13364 -- pragma Import complete a deferred constant.
13366 and then not Has_Completion (Defining_Identifier (Decl))
13369 ("constant declaration requires initialization expression",
13370 Defining_Identifier (Decl));
13373 Decl := Next (Decl);
13375 end Inspect_Deferred_Constant_Completion;
13377 -------------------------------
13378 -- Install_Elaboration_Model --
13379 -------------------------------
13381 procedure Install_Elaboration_Model (Unit_Id : Entity_Id) is
13382 function Find_Elaboration_Checks_Pragma (L : List_Id) return Node_Id;
13383 -- Try to find pragma Elaboration_Checks in arbitrary list L. Return
13384 -- Empty if there is no such pragma.
13386 ------------------------------------
13387 -- Find_Elaboration_Checks_Pragma --
13388 ------------------------------------
13390 function Find_Elaboration_Checks_Pragma (L : List_Id) return Node_Id is
13395 while Present (Item) loop
13396 if Nkind (Item) = N_Pragma
13397 and then Pragma_Name (Item) = Name_Elaboration_Checks
13406 end Find_Elaboration_Checks_Pragma;
13415 -- Start of processing for Install_Elaboration_Model
13418 -- Nothing to do when the unit does not exist
13420 if No (Unit_Id) then
13424 Unit := Parent (Unit_Declaration_Node (Unit_Id));
13426 -- Nothing to do when the unit is not a library unit
13428 if Nkind (Unit) /= N_Compilation_Unit then
13432 Prag := Find_Elaboration_Checks_Pragma (Context_Items (Unit));
13434 -- The compilation unit is subject to pragma Elaboration_Checks. Set the
13435 -- elaboration model as specified by the pragma.
13437 if Present (Prag) then
13438 Args := Pragma_Argument_Associations (Prag);
13440 -- Guard against an illegal pragma. The sole argument must be an
13441 -- identifier which specifies either Dynamic or Static model.
13443 if Present (Args) then
13444 Model := Get_Pragma_Arg (First (Args));
13446 if Nkind (Model) = N_Identifier then
13447 Dynamic_Elaboration_Checks := Chars (Model) = Name_Dynamic;
13451 end Install_Elaboration_Model;
13453 -----------------------------
13454 -- Install_Generic_Formals --
13455 -----------------------------
13457 procedure Install_Generic_Formals (Subp_Id : Entity_Id) is
13461 pragma Assert (Is_Generic_Subprogram (Subp_Id));
13463 E := First_Entity (Subp_Id);
13464 while Present (E) loop
13465 Install_Entity (E);
13468 end Install_Generic_Formals;
13470 ------------------------
13471 -- Install_SPARK_Mode --
13472 ------------------------
13474 procedure Install_SPARK_Mode (Mode : SPARK_Mode_Type; Prag : Node_Id) is
13476 SPARK_Mode := Mode;
13477 SPARK_Mode_Pragma := Prag;
13478 end Install_SPARK_Mode;
13480 --------------------------
13481 -- Invalid_Scalar_Value --
13482 --------------------------
13484 function Invalid_Scalar_Value
13486 Scal_Typ : Scalar_Id) return Node_Id
13488 function Invalid_Binder_Value return Node_Id;
13489 -- Return a reference to the corresponding invalid value for type
13490 -- Scal_Typ as defined in unit System.Scalar_Values.
13492 function Invalid_Float_Value return Node_Id;
13493 -- Return the invalid value of float type Scal_Typ
13495 function Invalid_Integer_Value return Node_Id;
13496 -- Return the invalid value of integer type Scal_Typ
13498 procedure Set_Invalid_Binder_Values;
13499 -- Set the contents of collection Invalid_Binder_Values
13501 --------------------------
13502 -- Invalid_Binder_Value --
13503 --------------------------
13505 function Invalid_Binder_Value return Node_Id is
13506 Val_Id : Entity_Id;
13509 -- Initialize the collection of invalid binder values the first time
13512 Set_Invalid_Binder_Values;
13514 -- Obtain the corresponding variable from System.Scalar_Values which
13515 -- holds the invalid value for this type.
13517 Val_Id := Invalid_Binder_Values (Scal_Typ);
13518 pragma Assert (Present (Val_Id));
13520 return New_Occurrence_Of (Val_Id, Loc);
13521 end Invalid_Binder_Value;
13523 -------------------------
13524 -- Invalid_Float_Value --
13525 -------------------------
13527 function Invalid_Float_Value return Node_Id is
13528 Value : constant Ureal := Invalid_Floats (Scal_Typ);
13531 -- Pragma Invalid_Scalars did not specify an invalid value for this
13532 -- type. Fall back to the value provided by the binder.
13534 if Value = No_Ureal then
13535 return Invalid_Binder_Value;
13537 return Make_Real_Literal (Loc, Realval => Value);
13539 end Invalid_Float_Value;
13541 ---------------------------
13542 -- Invalid_Integer_Value --
13543 ---------------------------
13545 function Invalid_Integer_Value return Node_Id is
13546 Value : constant Uint := Invalid_Integers (Scal_Typ);
13549 -- Pragma Invalid_Scalars did not specify an invalid value for this
13550 -- type. Fall back to the value provided by the binder.
13552 if Value = No_Uint then
13553 return Invalid_Binder_Value;
13555 return Make_Integer_Literal (Loc, Intval => Value);
13557 end Invalid_Integer_Value;
13559 -------------------------------
13560 -- Set_Invalid_Binder_Values --
13561 -------------------------------
13563 procedure Set_Invalid_Binder_Values is
13565 if not Invalid_Binder_Values_Set then
13566 Invalid_Binder_Values_Set := True;
13568 -- Initialize the contents of the collection once since RTE calls
13571 Invalid_Binder_Values :=
13572 (Name_Short_Float => RTE (RE_IS_Isf),
13573 Name_Float => RTE (RE_IS_Ifl),
13574 Name_Long_Float => RTE (RE_IS_Ilf),
13575 Name_Long_Long_Float => RTE (RE_IS_Ill),
13576 Name_Signed_8 => RTE (RE_IS_Is1),
13577 Name_Signed_16 => RTE (RE_IS_Is2),
13578 Name_Signed_32 => RTE (RE_IS_Is4),
13579 Name_Signed_64 => RTE (RE_IS_Is8),
13580 Name_Unsigned_8 => RTE (RE_IS_Iu1),
13581 Name_Unsigned_16 => RTE (RE_IS_Iu2),
13582 Name_Unsigned_32 => RTE (RE_IS_Iu4),
13583 Name_Unsigned_64 => RTE (RE_IS_Iu8));
13585 end Set_Invalid_Binder_Values;
13587 -- Start of processing for Invalid_Scalar_Value
13590 if Scal_Typ in Float_Scalar_Id then
13591 return Invalid_Float_Value;
13593 else pragma Assert (Scal_Typ in Integer_Scalar_Id);
13594 return Invalid_Integer_Value;
13596 end Invalid_Scalar_Value;
13598 -----------------------------
13599 -- Is_Actual_Out_Parameter --
13600 -----------------------------
13602 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
13603 Formal : Entity_Id;
13606 Find_Actual (N, Formal, Call);
13607 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
13608 end Is_Actual_Out_Parameter;
13610 -------------------------
13611 -- Is_Actual_Parameter --
13612 -------------------------
13614 function Is_Actual_Parameter (N : Node_Id) return Boolean is
13615 PK : constant Node_Kind := Nkind (Parent (N));
13619 when N_Parameter_Association =>
13620 return N = Explicit_Actual_Parameter (Parent (N));
13622 when N_Subprogram_Call =>
13623 return Is_List_Member (N)
13625 List_Containing (N) = Parameter_Associations (Parent (N));
13630 end Is_Actual_Parameter;
13632 --------------------------------
13633 -- Is_Actual_Tagged_Parameter --
13634 --------------------------------
13636 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
13637 Formal : Entity_Id;
13640 Find_Actual (N, Formal, Call);
13641 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
13642 end Is_Actual_Tagged_Parameter;
13644 ---------------------
13645 -- Is_Aliased_View --
13646 ---------------------
13648 function Is_Aliased_View (Obj : Node_Id) return Boolean is
13652 if Is_Entity_Name (Obj) then
13659 or else (Present (Renamed_Object (E))
13660 and then Is_Aliased_View (Renamed_Object (E)))))
13662 or else ((Is_Formal (E) or else Is_Formal_Object (E))
13663 and then Is_Tagged_Type (Etype (E)))
13665 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
13667 -- Current instance of type, either directly or as rewritten
13668 -- reference to the current object.
13670 or else (Is_Entity_Name (Original_Node (Obj))
13671 and then Present (Entity (Original_Node (Obj)))
13672 and then Is_Type (Entity (Original_Node (Obj))))
13674 or else (Is_Type (E) and then E = Current_Scope)
13676 or else (Is_Incomplete_Or_Private_Type (E)
13677 and then Full_View (E) = Current_Scope)
13679 -- Ada 2012 AI05-0053: the return object of an extended return
13680 -- statement is aliased if its type is immutably limited.
13682 or else (Is_Return_Object (E)
13683 and then Is_Limited_View (Etype (E)));
13685 elsif Nkind (Obj) = N_Selected_Component then
13686 return Is_Aliased (Entity (Selector_Name (Obj)));
13688 elsif Nkind (Obj) = N_Indexed_Component then
13689 return Has_Aliased_Components (Etype (Prefix (Obj)))
13691 (Is_Access_Type (Etype (Prefix (Obj)))
13692 and then Has_Aliased_Components
13693 (Designated_Type (Etype (Prefix (Obj)))));
13695 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
13696 return Is_Tagged_Type (Etype (Obj))
13697 and then Is_Aliased_View (Expression (Obj));
13699 elsif Nkind (Obj) = N_Explicit_Dereference then
13700 return Nkind (Original_Node (Obj)) /= N_Function_Call;
13705 end Is_Aliased_View;
13707 -------------------------
13708 -- Is_Ancestor_Package --
13709 -------------------------
13711 function Is_Ancestor_Package
13713 E2 : Entity_Id) return Boolean
13719 while Present (Par) and then Par /= Standard_Standard loop
13724 Par := Scope (Par);
13728 end Is_Ancestor_Package;
13730 ----------------------
13731 -- Is_Atomic_Object --
13732 ----------------------
13734 function Is_Atomic_Object (N : Node_Id) return Boolean is
13735 function Prefix_Has_Atomic_Components (P : Node_Id) return Boolean;
13736 -- Determine whether prefix P has atomic components. This requires the
13737 -- presence of an Atomic_Components aspect/pragma.
13739 ---------------------------------
13740 -- Prefix_Has_Atomic_Components --
13741 ---------------------------------
13743 function Prefix_Has_Atomic_Components (P : Node_Id) return Boolean is
13744 Typ : constant Entity_Id := Etype (P);
13747 if Is_Access_Type (Typ) then
13748 return Has_Atomic_Components (Designated_Type (Typ));
13750 elsif Has_Atomic_Components (Typ) then
13753 elsif Is_Entity_Name (P)
13754 and then Has_Atomic_Components (Entity (P))
13761 end Prefix_Has_Atomic_Components;
13763 -- Start of processing for Is_Atomic_Object
13766 if Is_Entity_Name (N) then
13767 return Is_Atomic_Object_Entity (Entity (N));
13769 elsif Is_Atomic (Etype (N)) then
13772 elsif Nkind (N) = N_Indexed_Component then
13773 return Prefix_Has_Atomic_Components (Prefix (N));
13775 elsif Nkind (N) = N_Selected_Component then
13776 return Is_Atomic (Entity (Selector_Name (N)));
13781 end Is_Atomic_Object;
13783 -----------------------------
13784 -- Is_Atomic_Object_Entity --
13785 -----------------------------
13787 function Is_Atomic_Object_Entity (Id : Entity_Id) return Boolean is
13791 and then (Is_Atomic (Id) or else Is_Atomic (Etype (Id)));
13792 end Is_Atomic_Object_Entity;
13794 -----------------------------
13795 -- Is_Atomic_Or_VFA_Object --
13796 -----------------------------
13798 function Is_Atomic_Or_VFA_Object (N : Node_Id) return Boolean is
13800 return Is_Atomic_Object (N) or else Is_Volatile_Full_Access_Object (N);
13801 end Is_Atomic_Or_VFA_Object;
13803 ----------------------
13804 -- Is_Attribute_Old --
13805 ----------------------
13807 function Is_Attribute_Old (N : Node_Id) return Boolean is
13809 return Nkind (N) = N_Attribute_Reference
13810 and then Attribute_Name (N) = Name_Old;
13811 end Is_Attribute_Old;
13813 -------------------------
13814 -- Is_Attribute_Result --
13815 -------------------------
13817 function Is_Attribute_Result (N : Node_Id) return Boolean is
13819 return Nkind (N) = N_Attribute_Reference
13820 and then Attribute_Name (N) = Name_Result;
13821 end Is_Attribute_Result;
13823 -------------------------
13824 -- Is_Attribute_Update --
13825 -------------------------
13827 function Is_Attribute_Update (N : Node_Id) return Boolean is
13829 return Nkind (N) = N_Attribute_Reference
13830 and then Attribute_Name (N) = Name_Update;
13831 end Is_Attribute_Update;
13833 ------------------------------------
13834 -- Is_Body_Or_Package_Declaration --
13835 ------------------------------------
13837 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
13839 return Is_Body (N) or else Nkind (N) = N_Package_Declaration;
13840 end Is_Body_Or_Package_Declaration;
13842 -----------------------
13843 -- Is_Bounded_String --
13844 -----------------------
13846 function Is_Bounded_String (T : Entity_Id) return Boolean is
13847 Under : constant Entity_Id := Underlying_Type (Root_Type (T));
13850 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
13851 -- Super_String, or one of the [Wide_]Wide_ versions. This will
13852 -- be True for all the Bounded_String types in instances of the
13853 -- Generic_Bounded_Length generics, and for types derived from those.
13855 return Present (Under)
13856 and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
13857 Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
13858 Is_RTE (Root_Type (Under), RO_WW_Super_String));
13859 end Is_Bounded_String;
13861 ---------------------
13862 -- Is_CCT_Instance --
13863 ---------------------
13865 function Is_CCT_Instance
13866 (Ref_Id : Entity_Id;
13867 Context_Id : Entity_Id) return Boolean
13870 pragma Assert (Ekind_In (Ref_Id, E_Protected_Type, E_Task_Type));
13872 if Is_Single_Task_Object (Context_Id) then
13873 return Scope_Within_Or_Same (Etype (Context_Id), Ref_Id);
13876 pragma Assert (Ekind_In (Context_Id, E_Entry,
13884 Is_Record_Type (Context_Id));
13885 return Scope_Within_Or_Same (Context_Id, Ref_Id);
13887 end Is_CCT_Instance;
13889 -------------------------
13890 -- Is_Child_Or_Sibling --
13891 -------------------------
13893 function Is_Child_Or_Sibling
13894 (Pack_1 : Entity_Id;
13895 Pack_2 : Entity_Id) return Boolean
13897 function Distance_From_Standard (Pack : Entity_Id) return Nat;
13898 -- Given an arbitrary package, return the number of "climbs" necessary
13899 -- to reach scope Standard_Standard.
13901 procedure Equalize_Depths
13902 (Pack : in out Entity_Id;
13903 Depth : in out Nat;
13904 Depth_To_Reach : Nat);
13905 -- Given an arbitrary package, its depth and a target depth to reach,
13906 -- climb the scope chain until the said depth is reached. The pointer
13907 -- to the package and its depth a modified during the climb.
13909 ----------------------------
13910 -- Distance_From_Standard --
13911 ----------------------------
13913 function Distance_From_Standard (Pack : Entity_Id) return Nat is
13920 while Present (Scop) and then Scop /= Standard_Standard loop
13922 Scop := Scope (Scop);
13926 end Distance_From_Standard;
13928 ---------------------
13929 -- Equalize_Depths --
13930 ---------------------
13932 procedure Equalize_Depths
13933 (Pack : in out Entity_Id;
13934 Depth : in out Nat;
13935 Depth_To_Reach : Nat)
13938 -- The package must be at a greater or equal depth
13940 if Depth < Depth_To_Reach then
13941 raise Program_Error;
13944 -- Climb the scope chain until the desired depth is reached
13946 while Present (Pack) and then Depth /= Depth_To_Reach loop
13947 Pack := Scope (Pack);
13948 Depth := Depth - 1;
13950 end Equalize_Depths;
13954 P_1 : Entity_Id := Pack_1;
13955 P_1_Child : Boolean := False;
13956 P_1_Depth : Nat := Distance_From_Standard (P_1);
13957 P_2 : Entity_Id := Pack_2;
13958 P_2_Child : Boolean := False;
13959 P_2_Depth : Nat := Distance_From_Standard (P_2);
13961 -- Start of processing for Is_Child_Or_Sibling
13965 (Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
13967 -- Both packages denote the same entity, therefore they cannot be
13968 -- children or siblings.
13973 -- One of the packages is at a deeper level than the other. Note that
13974 -- both may still come from different hierarchies.
13982 elsif P_1_Depth > P_2_Depth then
13985 Depth => P_1_Depth,
13986 Depth_To_Reach => P_2_Depth);
13995 elsif P_2_Depth > P_1_Depth then
13998 Depth => P_2_Depth,
13999 Depth_To_Reach => P_1_Depth);
14003 -- At this stage the package pointers have been elevated to the same
14004 -- depth. If the related entities are the same, then one package is a
14005 -- potential child of the other:
14009 -- X became P_1 P_2 or vice versa
14015 return Is_Child_Unit (Pack_1);
14017 else pragma Assert (P_2_Child);
14018 return Is_Child_Unit (Pack_2);
14021 -- The packages may come from the same package chain or from entirely
14022 -- different hierarcies. To determine this, climb the scope stack until
14023 -- a common root is found.
14025 -- (root) (root 1) (root 2)
14030 while Present (P_1) and then Present (P_2) loop
14032 -- The two packages may be siblings
14035 return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2);
14038 P_1 := Scope (P_1);
14039 P_2 := Scope (P_2);
14044 end Is_Child_Or_Sibling;
14046 -----------------------------
14047 -- Is_Concurrent_Interface --
14048 -----------------------------
14050 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
14052 return Is_Interface (T)
14054 (Is_Protected_Interface (T)
14055 or else Is_Synchronized_Interface (T)
14056 or else Is_Task_Interface (T));
14057 end Is_Concurrent_Interface;
14059 -----------------------
14060 -- Is_Constant_Bound --
14061 -----------------------
14063 function Is_Constant_Bound (Exp : Node_Id) return Boolean is
14065 if Compile_Time_Known_Value (Exp) then
14068 elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
14069 return Is_Constant_Object (Entity (Exp))
14070 or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
14072 elsif Nkind (Exp) in N_Binary_Op then
14073 return Is_Constant_Bound (Left_Opnd (Exp))
14074 and then Is_Constant_Bound (Right_Opnd (Exp))
14075 and then Scope (Entity (Exp)) = Standard_Standard;
14080 end Is_Constant_Bound;
14082 ---------------------------
14083 -- Is_Container_Element --
14084 ---------------------------
14086 function Is_Container_Element (Exp : Node_Id) return Boolean is
14087 Loc : constant Source_Ptr := Sloc (Exp);
14088 Pref : constant Node_Id := Prefix (Exp);
14091 -- Call to an indexing aspect
14093 Cont_Typ : Entity_Id;
14094 -- The type of the container being accessed
14096 Elem_Typ : Entity_Id;
14097 -- Its element type
14099 Indexing : Entity_Id;
14100 Is_Const : Boolean;
14101 -- Indicates that constant indexing is used, and the element is thus
14104 Ref_Typ : Entity_Id;
14105 -- The reference type returned by the indexing operation
14108 -- If C is a container, in a context that imposes the element type of
14109 -- that container, the indexing notation C (X) is rewritten as:
14111 -- Indexing (C, X).Discr.all
14113 -- where Indexing is one of the indexing aspects of the container.
14114 -- If the context does not require a reference, the construct can be
14119 -- First, verify that the construct has the proper form
14121 if not Expander_Active then
14124 elsif Nkind (Pref) /= N_Selected_Component then
14127 elsif Nkind (Prefix (Pref)) /= N_Function_Call then
14131 Call := Prefix (Pref);
14132 Ref_Typ := Etype (Call);
14135 if not Has_Implicit_Dereference (Ref_Typ)
14136 or else No (First (Parameter_Associations (Call)))
14137 or else not Is_Entity_Name (Name (Call))
14142 -- Retrieve type of container object, and its iterator aspects
14144 Cont_Typ := Etype (First (Parameter_Associations (Call)));
14145 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Constant_Indexing);
14148 if No (Indexing) then
14150 -- Container should have at least one indexing operation
14154 elsif Entity (Name (Call)) /= Entity (Indexing) then
14156 -- This may be a variable indexing operation
14158 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Variable_Indexing);
14161 or else Entity (Name (Call)) /= Entity (Indexing)
14170 Elem_Typ := Find_Value_Of_Aspect (Cont_Typ, Aspect_Iterator_Element);
14172 if No (Elem_Typ) or else Entity (Elem_Typ) /= Etype (Exp) then
14176 -- Check that the expression is not the target of an assignment, in
14177 -- which case the rewriting is not possible.
14179 if not Is_Const then
14185 while Present (Par)
14187 if Nkind (Parent (Par)) = N_Assignment_Statement
14188 and then Par = Name (Parent (Par))
14192 -- A renaming produces a reference, and the transformation
14195 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
14199 (Nkind (Parent (Par)), N_Function_Call,
14200 N_Procedure_Call_Statement,
14201 N_Entry_Call_Statement)
14203 -- Check that the element is not part of an actual for an
14204 -- in-out parameter.
14211 F := First_Formal (Entity (Name (Parent (Par))));
14212 A := First (Parameter_Associations (Parent (Par)));
14213 while Present (F) loop
14214 if A = Par and then Ekind (F) /= E_In_Parameter then
14223 -- E_In_Parameter in a call: element is not modified.
14228 Par := Parent (Par);
14233 -- The expression has the proper form and the context requires the
14234 -- element type. Retrieve the Element function of the container and
14235 -- rewrite the construct as a call to it.
14241 Op := First_Elmt (Primitive_Operations (Cont_Typ));
14242 while Present (Op) loop
14243 exit when Chars (Node (Op)) = Name_Element;
14252 Make_Function_Call (Loc,
14253 Name => New_Occurrence_Of (Node (Op), Loc),
14254 Parameter_Associations => Parameter_Associations (Call)));
14255 Analyze_And_Resolve (Exp, Entity (Elem_Typ));
14259 end Is_Container_Element;
14261 ----------------------------
14262 -- Is_Contract_Annotation --
14263 ----------------------------
14265 function Is_Contract_Annotation (Item : Node_Id) return Boolean is
14267 return Is_Package_Contract_Annotation (Item)
14269 Is_Subprogram_Contract_Annotation (Item);
14270 end Is_Contract_Annotation;
14272 --------------------------------------
14273 -- Is_Controlling_Limited_Procedure --
14274 --------------------------------------
14276 function Is_Controlling_Limited_Procedure
14277 (Proc_Nam : Entity_Id) return Boolean
14280 Param_Typ : Entity_Id := Empty;
14283 if Ekind (Proc_Nam) = E_Procedure
14284 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
14288 (First (Parameter_Specifications (Parent (Proc_Nam))));
14290 -- The formal may be an anonymous access type
14292 if Nkind (Param) = N_Access_Definition then
14293 Param_Typ := Entity (Subtype_Mark (Param));
14295 Param_Typ := Etype (Param);
14298 -- In the case where an Itype was created for a dispatchin call, the
14299 -- procedure call has been rewritten. The actual may be an access to
14300 -- interface type in which case it is the designated type that is the
14301 -- controlling type.
14303 elsif Present (Associated_Node_For_Itype (Proc_Nam))
14304 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
14306 Present (Parameter_Associations
14307 (Associated_Node_For_Itype (Proc_Nam)))
14310 Etype (First (Parameter_Associations
14311 (Associated_Node_For_Itype (Proc_Nam))));
14313 if Ekind (Param_Typ) = E_Anonymous_Access_Type then
14314 Param_Typ := Directly_Designated_Type (Param_Typ);
14318 if Present (Param_Typ) then
14320 Is_Interface (Param_Typ)
14321 and then Is_Limited_Record (Param_Typ);
14325 end Is_Controlling_Limited_Procedure;
14327 -----------------------------
14328 -- Is_CPP_Constructor_Call --
14329 -----------------------------
14331 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
14333 return Nkind (N) = N_Function_Call
14334 and then Is_CPP_Class (Etype (Etype (N)))
14335 and then Is_Constructor (Entity (Name (N)))
14336 and then Is_Imported (Entity (Name (N)));
14337 end Is_CPP_Constructor_Call;
14339 -------------------------
14340 -- Is_Current_Instance --
14341 -------------------------
14343 function Is_Current_Instance (N : Node_Id) return Boolean is
14344 Typ : constant Entity_Id := Entity (N);
14348 -- Simplest case: entity is a concurrent type and we are currently
14349 -- inside the body. This will eventually be expanded into a call to
14350 -- Self (for tasks) or _object (for protected objects).
14352 if Is_Concurrent_Type (Typ) and then In_Open_Scopes (Typ) then
14356 -- Check whether the context is a (sub)type declaration for the
14360 while Present (P) loop
14361 if Nkind_In (P, N_Full_Type_Declaration,
14362 N_Private_Type_Declaration,
14363 N_Subtype_Declaration)
14364 and then Comes_From_Source (P)
14365 and then Defining_Entity (P) = Typ
14369 -- A subtype name may appear in an aspect specification for a
14370 -- Predicate_Failure aspect, for which we do not construct a
14371 -- wrapper procedure. The subtype will be replaced by the
14372 -- expression being tested when the corresponding predicate
14373 -- check is expanded.
14375 elsif Nkind (P) = N_Aspect_Specification
14376 and then Nkind (Parent (P)) = N_Subtype_Declaration
14380 elsif Nkind (P) = N_Pragma
14381 and then Get_Pragma_Id (P) = Pragma_Predicate_Failure
14390 -- In any other context this is not a current occurrence
14393 end Is_Current_Instance;
14395 --------------------
14396 -- Is_Declaration --
14397 --------------------
14399 function Is_Declaration
14401 Body_OK : Boolean := True;
14402 Concurrent_OK : Boolean := True;
14403 Formal_OK : Boolean := True;
14404 Generic_OK : Boolean := True;
14405 Instantiation_OK : Boolean := True;
14406 Renaming_OK : Boolean := True;
14407 Stub_OK : Boolean := True;
14408 Subprogram_OK : Boolean := True;
14409 Type_OK : Boolean := True) return Boolean
14414 -- Body declarations
14416 when N_Proper_Body =>
14419 -- Concurrent type declarations
14421 when N_Protected_Type_Declaration
14422 | N_Single_Protected_Declaration
14423 | N_Single_Task_Declaration
14424 | N_Task_Type_Declaration
14426 return Concurrent_OK or Type_OK;
14428 -- Formal declarations
14430 when N_Formal_Abstract_Subprogram_Declaration
14431 | N_Formal_Concrete_Subprogram_Declaration
14432 | N_Formal_Object_Declaration
14433 | N_Formal_Package_Declaration
14434 | N_Formal_Type_Declaration
14438 -- Generic declarations
14440 when N_Generic_Package_Declaration
14441 | N_Generic_Subprogram_Declaration
14445 -- Generic instantiations
14447 when N_Function_Instantiation
14448 | N_Package_Instantiation
14449 | N_Procedure_Instantiation
14451 return Instantiation_OK;
14453 -- Generic renaming declarations
14455 when N_Generic_Renaming_Declaration =>
14456 return Generic_OK or Renaming_OK;
14458 -- Renaming declarations
14460 when N_Exception_Renaming_Declaration
14461 | N_Object_Renaming_Declaration
14462 | N_Package_Renaming_Declaration
14463 | N_Subprogram_Renaming_Declaration
14465 return Renaming_OK;
14467 -- Stub declarations
14469 when N_Body_Stub =>
14472 -- Subprogram declarations
14474 when N_Abstract_Subprogram_Declaration
14475 | N_Entry_Declaration
14476 | N_Expression_Function
14477 | N_Subprogram_Declaration
14479 return Subprogram_OK;
14481 -- Type declarations
14483 when N_Full_Type_Declaration
14484 | N_Incomplete_Type_Declaration
14485 | N_Private_Extension_Declaration
14486 | N_Private_Type_Declaration
14487 | N_Subtype_Declaration
14493 when N_Component_Declaration
14494 | N_Exception_Declaration
14495 | N_Implicit_Label_Declaration
14496 | N_Number_Declaration
14497 | N_Object_Declaration
14498 | N_Package_Declaration
14505 end Is_Declaration;
14507 --------------------------------
14508 -- Is_Declared_Within_Variant --
14509 --------------------------------
14511 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
14512 Comp_Decl : constant Node_Id := Parent (Comp);
14513 Comp_List : constant Node_Id := Parent (Comp_Decl);
14515 return Nkind (Parent (Comp_List)) = N_Variant;
14516 end Is_Declared_Within_Variant;
14518 ----------------------------------------------
14519 -- Is_Dependent_Component_Of_Mutable_Object --
14520 ----------------------------------------------
14522 function Is_Dependent_Component_Of_Mutable_Object
14523 (Object : Node_Id) return Boolean
14526 Prefix_Type : Entity_Id;
14527 P_Aliased : Boolean := False;
14530 Deref : Node_Id := Object;
14531 -- Dereference node, in something like X.all.Y(2)
14533 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
14536 -- Find the dereference node if any
14538 while Nkind_In (Deref, N_Indexed_Component,
14539 N_Selected_Component,
14542 Deref := Prefix (Deref);
14545 -- If the prefix is a qualified expression of a variable, then function
14546 -- Is_Variable will return False for that because a qualified expression
14547 -- denotes a constant view, so we need to get the name being qualified
14548 -- so we can test below whether that's a variable (or a dereference).
14550 if Nkind (Deref) = N_Qualified_Expression then
14551 Deref := Expression (Deref);
14554 -- Ada 2005: If we have a component or slice of a dereference, something
14555 -- like X.all.Y (2) and the type of X is access-to-constant, Is_Variable
14556 -- will return False, because it is indeed a constant view. But it might
14557 -- be a view of a variable object, so we want the following condition to
14558 -- be True in that case.
14560 if Is_Variable (Object)
14561 or else Is_Variable (Deref)
14562 or else (Ada_Version >= Ada_2005
14563 and then (Nkind (Deref) = N_Explicit_Dereference
14564 or else Is_Access_Type (Etype (Deref))))
14566 if Nkind (Object) = N_Selected_Component then
14568 -- If the selector is not a component, then we definitely return
14569 -- False (it could be a function selector in a prefix form call
14570 -- occurring in an iterator specification).
14572 if not Ekind_In (Entity (Selector_Name (Object)), E_Component,
14578 -- Get the original node of the prefix in case it has been
14579 -- rewritten, which can occur, for example, in qualified
14580 -- expression cases. Also, a discriminant check on a selected
14581 -- component may be expanded into a dereference when removing
14582 -- side effects, and the subtype of the original node may be
14585 P := Original_Node (Prefix (Object));
14586 Prefix_Type := Etype (P);
14588 -- If the prefix is a qualified expression, we want to look at its
14591 if Nkind (P) = N_Qualified_Expression then
14592 P := Expression (P);
14593 Prefix_Type := Etype (P);
14596 if Is_Entity_Name (P) then
14597 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
14598 Prefix_Type := Base_Type (Prefix_Type);
14601 if Is_Aliased (Entity (P)) then
14605 -- For explicit dereferences we get the access prefix so we can
14606 -- treat this similarly to implicit dereferences and examine the
14607 -- kind of the access type and its designated subtype further
14610 elsif Nkind (P) = N_Explicit_Dereference then
14612 Prefix_Type := Etype (P);
14615 -- Check for prefix being an aliased component???
14620 -- A heap object is constrained by its initial value
14622 -- Ada 2005 (AI-363): Always assume the object could be mutable in
14623 -- the dereferenced case, since the access value might denote an
14624 -- unconstrained aliased object, whereas in Ada 95 the designated
14625 -- object is guaranteed to be constrained. A worst-case assumption
14626 -- has to apply in Ada 2005 because we can't tell at compile
14627 -- time whether the object is "constrained by its initial value",
14628 -- despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
14629 -- rules (these rules are acknowledged to need fixing). We don't
14630 -- impose this more stringent checking for earlier Ada versions or
14631 -- when Relaxed_RM_Semantics applies (the latter for CodePeer's
14632 -- benefit, though it's unclear on why using -gnat95 would not be
14635 if Ada_Version < Ada_2005 or else Relaxed_RM_Semantics then
14636 if Is_Access_Type (Prefix_Type)
14637 or else Nkind (P) = N_Explicit_Dereference
14642 else pragma Assert (Ada_Version >= Ada_2005);
14643 if Is_Access_Type (Prefix_Type) then
14644 -- We need to make sure we have the base subtype, in case
14645 -- this is actually an access subtype (whose Ekind will be
14646 -- E_Access_Subtype).
14648 Prefix_Type := Etype (Prefix_Type);
14650 -- If the access type is pool-specific, and there is no
14651 -- constrained partial view of the designated type, then the
14652 -- designated object is known to be constrained. If it's a
14653 -- formal access type and the renaming is in the generic
14654 -- spec, we also treat it as pool-specific (known to be
14655 -- constrained), but assume the worst if in the generic body
14656 -- (see RM 3.3(23.3/3)).
14658 if Ekind (Prefix_Type) = E_Access_Type
14659 and then (not Is_Generic_Type (Prefix_Type)
14660 or else not In_Generic_Body (Current_Scope))
14661 and then not Object_Type_Has_Constrained_Partial_View
14662 (Typ => Designated_Type (Prefix_Type),
14663 Scop => Current_Scope)
14667 -- Otherwise (general access type, or there is a constrained
14668 -- partial view of the designated type), we need to check
14669 -- based on the designated type.
14672 Prefix_Type := Designated_Type (Prefix_Type);
14678 Original_Record_Component (Entity (Selector_Name (Object)));
14680 -- As per AI-0017, the renaming is illegal in a generic body, even
14681 -- if the subtype is indefinite (only applies to prefixes of an
14682 -- untagged formal type, see RM 3.3 (23.11/3)).
14684 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
14686 if not Is_Constrained (Prefix_Type)
14687 and then (Is_Definite_Subtype (Prefix_Type)
14689 (not Is_Tagged_Type (Prefix_Type)
14690 and then Is_Generic_Type (Prefix_Type)
14691 and then In_Generic_Body (Current_Scope)))
14693 and then (Is_Declared_Within_Variant (Comp)
14694 or else Has_Discriminant_Dependent_Constraint (Comp))
14695 and then (not P_Aliased or else Ada_Version >= Ada_2005)
14699 -- If the prefix is of an access type at this point, then we want
14700 -- to return False, rather than calling this function recursively
14701 -- on the access object (which itself might be a discriminant-
14702 -- dependent component of some other object, but that isn't
14703 -- relevant to checking the object passed to us). This avoids
14704 -- issuing wrong errors when compiling with -gnatc, where there
14705 -- can be implicit dereferences that have not been expanded.
14707 elsif Is_Access_Type (Etype (Prefix (Object))) then
14712 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
14715 elsif Nkind (Object) = N_Indexed_Component
14716 or else Nkind (Object) = N_Slice
14718 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
14720 -- A type conversion that Is_Variable is a view conversion:
14721 -- go back to the denoted object.
14723 elsif Nkind (Object) = N_Type_Conversion then
14725 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
14730 end Is_Dependent_Component_Of_Mutable_Object;
14732 ---------------------
14733 -- Is_Dereferenced --
14734 ---------------------
14736 function Is_Dereferenced (N : Node_Id) return Boolean is
14737 P : constant Node_Id := Parent (N);
14739 return Nkind_In (P, N_Selected_Component,
14740 N_Explicit_Dereference,
14741 N_Indexed_Component,
14743 and then Prefix (P) = N;
14744 end Is_Dereferenced;
14746 ----------------------
14747 -- Is_Descendant_Of --
14748 ----------------------
14750 function Is_Descendant_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
14755 pragma Assert (Nkind (T1) in N_Entity);
14756 pragma Assert (Nkind (T2) in N_Entity);
14758 T := Base_Type (T1);
14760 -- Immediate return if the types match
14765 -- Comment needed here ???
14767 elsif Ekind (T) = E_Class_Wide_Type then
14768 return Etype (T) = T2;
14776 -- Done if we found the type we are looking for
14781 -- Done if no more derivations to check
14788 -- Following test catches error cases resulting from prev errors
14790 elsif No (Etyp) then
14793 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
14796 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
14800 T := Base_Type (Etyp);
14803 end Is_Descendant_Of;
14805 ----------------------------------------
14806 -- Is_Descendant_Of_Suspension_Object --
14807 ----------------------------------------
14809 function Is_Descendant_Of_Suspension_Object
14810 (Typ : Entity_Id) return Boolean
14812 Cur_Typ : Entity_Id;
14813 Par_Typ : Entity_Id;
14816 -- Climb the type derivation chain checking each parent type against
14817 -- Suspension_Object.
14819 Cur_Typ := Base_Type (Typ);
14820 while Present (Cur_Typ) loop
14821 Par_Typ := Etype (Cur_Typ);
14823 -- The current type is a match
14825 if Is_Suspension_Object (Cur_Typ) then
14828 -- Stop the traversal once the root of the derivation chain has been
14829 -- reached. In that case the current type is its own base type.
14831 elsif Cur_Typ = Par_Typ then
14835 Cur_Typ := Base_Type (Par_Typ);
14839 end Is_Descendant_Of_Suspension_Object;
14841 ---------------------------------------------
14842 -- Is_Double_Precision_Floating_Point_Type --
14843 ---------------------------------------------
14845 function Is_Double_Precision_Floating_Point_Type
14846 (E : Entity_Id) return Boolean is
14848 return Is_Floating_Point_Type (E)
14849 and then Machine_Radix_Value (E) = Uint_2
14850 and then Machine_Mantissa_Value (E) = UI_From_Int (53)
14851 and then Machine_Emax_Value (E) = Uint_2 ** Uint_10
14852 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_10);
14853 end Is_Double_Precision_Floating_Point_Type;
14855 -----------------------------
14856 -- Is_Effectively_Volatile --
14857 -----------------------------
14859 function Is_Effectively_Volatile (Id : Entity_Id) return Boolean is
14861 if Is_Type (Id) then
14863 -- An arbitrary type is effectively volatile when it is subject to
14864 -- pragma Atomic or Volatile.
14866 if Is_Volatile (Id) then
14869 -- An array type is effectively volatile when it is subject to pragma
14870 -- Atomic_Components or Volatile_Components or its component type is
14871 -- effectively volatile.
14873 elsif Is_Array_Type (Id) then
14875 Anc : Entity_Id := Base_Type (Id);
14877 if Is_Private_Type (Anc) then
14878 Anc := Full_View (Anc);
14881 -- Test for presence of ancestor, as the full view of a private
14882 -- type may be missing in case of error.
14885 Has_Volatile_Components (Id)
14888 and then Is_Effectively_Volatile (Component_Type (Anc)));
14891 -- A protected type is always volatile
14893 elsif Is_Protected_Type (Id) then
14896 -- A descendant of Ada.Synchronous_Task_Control.Suspension_Object is
14897 -- automatically volatile.
14899 elsif Is_Descendant_Of_Suspension_Object (Id) then
14902 -- Otherwise the type is not effectively volatile
14908 -- Otherwise Id denotes an object
14911 -- A volatile object for which No_Caching is enabled is not
14912 -- effectively volatile.
14915 (Is_Volatile (Id) and then not No_Caching_Enabled (Id))
14916 or else Has_Volatile_Components (Id)
14917 or else Is_Effectively_Volatile (Etype (Id));
14919 end Is_Effectively_Volatile;
14921 ------------------------------------
14922 -- Is_Effectively_Volatile_Object --
14923 ------------------------------------
14925 function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean is
14927 if Is_Entity_Name (N) then
14928 return Is_Effectively_Volatile (Entity (N));
14930 elsif Nkind (N) = N_Indexed_Component then
14931 return Is_Effectively_Volatile_Object (Prefix (N));
14933 elsif Nkind (N) = N_Selected_Component then
14935 Is_Effectively_Volatile_Object (Prefix (N))
14937 Is_Effectively_Volatile_Object (Selector_Name (N));
14942 end Is_Effectively_Volatile_Object;
14944 -------------------
14945 -- Is_Entry_Body --
14946 -------------------
14948 function Is_Entry_Body (Id : Entity_Id) return Boolean is
14951 Ekind_In (Id, E_Entry, E_Entry_Family)
14952 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Body;
14955 --------------------------
14956 -- Is_Entry_Declaration --
14957 --------------------------
14959 function Is_Entry_Declaration (Id : Entity_Id) return Boolean is
14962 Ekind_In (Id, E_Entry, E_Entry_Family)
14963 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Declaration;
14964 end Is_Entry_Declaration;
14966 ------------------------------------
14967 -- Is_Expanded_Priority_Attribute --
14968 ------------------------------------
14970 function Is_Expanded_Priority_Attribute (E : Entity_Id) return Boolean is
14973 Nkind (E) = N_Function_Call
14974 and then not Configurable_Run_Time_Mode
14975 and then Nkind (Original_Node (E)) = N_Attribute_Reference
14976 and then (Entity (Name (E)) = RTE (RE_Get_Ceiling)
14977 or else Entity (Name (E)) = RTE (RO_PE_Get_Ceiling));
14978 end Is_Expanded_Priority_Attribute;
14980 ----------------------------
14981 -- Is_Expression_Function --
14982 ----------------------------
14984 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
14986 if Ekind_In (Subp, E_Function, E_Subprogram_Body) then
14988 Nkind (Original_Node (Unit_Declaration_Node (Subp))) =
14989 N_Expression_Function;
14993 end Is_Expression_Function;
14995 ------------------------------------------
14996 -- Is_Expression_Function_Or_Completion --
14997 ------------------------------------------
14999 function Is_Expression_Function_Or_Completion
15000 (Subp : Entity_Id) return Boolean
15002 Subp_Decl : Node_Id;
15005 if Ekind (Subp) = E_Function then
15006 Subp_Decl := Unit_Declaration_Node (Subp);
15008 -- The function declaration is either an expression function or is
15009 -- completed by an expression function body.
15012 Is_Expression_Function (Subp)
15013 or else (Nkind (Subp_Decl) = N_Subprogram_Declaration
15014 and then Present (Corresponding_Body (Subp_Decl))
15015 and then Is_Expression_Function
15016 (Corresponding_Body (Subp_Decl)));
15018 elsif Ekind (Subp) = E_Subprogram_Body then
15019 return Is_Expression_Function (Subp);
15024 end Is_Expression_Function_Or_Completion;
15026 -----------------------
15027 -- Is_EVF_Expression --
15028 -----------------------
15030 function Is_EVF_Expression (N : Node_Id) return Boolean is
15031 Orig_N : constant Node_Id := Original_Node (N);
15037 -- Detect a reference to a formal parameter of a specific tagged type
15038 -- whose related subprogram is subject to pragma Expresions_Visible with
15041 if Is_Entity_Name (N) and then Present (Entity (N)) then
15046 and then Is_Specific_Tagged_Type (Etype (Id))
15047 and then Extensions_Visible_Status (Id) =
15048 Extensions_Visible_False;
15050 -- A case expression is an EVF expression when it contains at least one
15051 -- EVF dependent_expression. Note that a case expression may have been
15052 -- expanded, hence the use of Original_Node.
15054 elsif Nkind (Orig_N) = N_Case_Expression then
15055 Alt := First (Alternatives (Orig_N));
15056 while Present (Alt) loop
15057 if Is_EVF_Expression (Expression (Alt)) then
15064 -- An if expression is an EVF expression when it contains at least one
15065 -- EVF dependent_expression. Note that an if expression may have been
15066 -- expanded, hence the use of Original_Node.
15068 elsif Nkind (Orig_N) = N_If_Expression then
15069 Expr := Next (First (Expressions (Orig_N)));
15070 while Present (Expr) loop
15071 if Is_EVF_Expression (Expr) then
15078 -- A qualified expression or a type conversion is an EVF expression when
15079 -- its operand is an EVF expression.
15081 elsif Nkind_In (N, N_Qualified_Expression,
15082 N_Unchecked_Type_Conversion,
15085 return Is_EVF_Expression (Expression (N));
15087 -- Attributes 'Loop_Entry, 'Old, and 'Update are EVF expressions when
15088 -- their prefix denotes an EVF expression.
15090 elsif Nkind (N) = N_Attribute_Reference
15091 and then Nam_In (Attribute_Name (N), Name_Loop_Entry,
15095 return Is_EVF_Expression (Prefix (N));
15099 end Is_EVF_Expression;
15105 function Is_False (U : Uint) return Boolean is
15110 ---------------------------
15111 -- Is_Fixed_Model_Number --
15112 ---------------------------
15114 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
15115 S : constant Ureal := Small_Value (T);
15116 M : Urealp.Save_Mark;
15121 R := (U = UR_Trunc (U / S) * S);
15122 Urealp.Release (M);
15124 end Is_Fixed_Model_Number;
15126 -------------------------------
15127 -- Is_Fully_Initialized_Type --
15128 -------------------------------
15130 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
15134 if Is_Scalar_Type (Typ) then
15136 -- A scalar type with an aspect Default_Value is fully initialized
15138 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
15139 -- of a scalar type, but we don't take that into account here, since
15140 -- we don't want these to affect warnings.
15142 return Has_Default_Aspect (Typ);
15144 elsif Is_Access_Type (Typ) then
15147 elsif Is_Array_Type (Typ) then
15148 if Is_Fully_Initialized_Type (Component_Type (Typ))
15149 or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
15154 -- An interesting case, if we have a constrained type one of whose
15155 -- bounds is known to be null, then there are no elements to be
15156 -- initialized, so all the elements are initialized.
15158 if Is_Constrained (Typ) then
15161 Indx_Typ : Entity_Id;
15162 Lbd, Hbd : Node_Id;
15165 Indx := First_Index (Typ);
15166 while Present (Indx) loop
15167 if Etype (Indx) = Any_Type then
15170 -- If index is a range, use directly
15172 elsif Nkind (Indx) = N_Range then
15173 Lbd := Low_Bound (Indx);
15174 Hbd := High_Bound (Indx);
15177 Indx_Typ := Etype (Indx);
15179 if Is_Private_Type (Indx_Typ) then
15180 Indx_Typ := Full_View (Indx_Typ);
15183 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
15186 Lbd := Type_Low_Bound (Indx_Typ);
15187 Hbd := Type_High_Bound (Indx_Typ);
15191 if Compile_Time_Known_Value (Lbd)
15193 Compile_Time_Known_Value (Hbd)
15195 if Expr_Value (Hbd) < Expr_Value (Lbd) then
15205 -- If no null indexes, then type is not fully initialized
15211 elsif Is_Record_Type (Typ) then
15212 if Has_Discriminants (Typ)
15214 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
15215 and then Is_Fully_Initialized_Variant (Typ)
15220 -- We consider bounded string types to be fully initialized, because
15221 -- otherwise we get false alarms when the Data component is not
15222 -- default-initialized.
15224 if Is_Bounded_String (Typ) then
15228 -- Controlled records are considered to be fully initialized if
15229 -- there is a user defined Initialize routine. This may not be
15230 -- entirely correct, but as the spec notes, we are guessing here
15231 -- what is best from the point of view of issuing warnings.
15233 if Is_Controlled (Typ) then
15235 Utyp : constant Entity_Id := Underlying_Type (Typ);
15238 if Present (Utyp) then
15240 Init : constant Entity_Id :=
15241 (Find_Optional_Prim_Op
15242 (Underlying_Type (Typ), Name_Initialize));
15246 and then Comes_From_Source (Init)
15247 and then not In_Predefined_Unit (Init)
15251 elsif Has_Null_Extension (Typ)
15253 Is_Fully_Initialized_Type
15254 (Etype (Base_Type (Typ)))
15263 -- Otherwise see if all record components are initialized
15269 Ent := First_Entity (Typ);
15270 while Present (Ent) loop
15271 if Ekind (Ent) = E_Component
15272 and then (No (Parent (Ent))
15273 or else No (Expression (Parent (Ent))))
15274 and then not Is_Fully_Initialized_Type (Etype (Ent))
15276 -- Special VM case for tag components, which need to be
15277 -- defined in this case, but are never initialized as VMs
15278 -- are using other dispatching mechanisms. Ignore this
15279 -- uninitialized case. Note that this applies both to the
15280 -- uTag entry and the main vtable pointer (CPP_Class case).
15282 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
15291 -- No uninitialized components, so type is fully initialized.
15292 -- Note that this catches the case of no components as well.
15296 elsif Is_Concurrent_Type (Typ) then
15299 elsif Is_Private_Type (Typ) then
15301 U : constant Entity_Id := Underlying_Type (Typ);
15307 return Is_Fully_Initialized_Type (U);
15314 end Is_Fully_Initialized_Type;
15316 ----------------------------------
15317 -- Is_Fully_Initialized_Variant --
15318 ----------------------------------
15320 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
15321 Loc : constant Source_Ptr := Sloc (Typ);
15322 Constraints : constant List_Id := New_List;
15323 Components : constant Elist_Id := New_Elmt_List;
15324 Comp_Elmt : Elmt_Id;
15326 Comp_List : Node_Id;
15328 Discr_Val : Node_Id;
15330 Report_Errors : Boolean;
15331 pragma Warnings (Off, Report_Errors);
15334 if Serious_Errors_Detected > 0 then
15338 if Is_Record_Type (Typ)
15339 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
15340 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
15342 Comp_List := Component_List (Type_Definition (Parent (Typ)));
15344 Discr := First_Discriminant (Typ);
15345 while Present (Discr) loop
15346 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
15347 Discr_Val := Expression (Parent (Discr));
15349 if Present (Discr_Val)
15350 and then Is_OK_Static_Expression (Discr_Val)
15352 Append_To (Constraints,
15353 Make_Component_Association (Loc,
15354 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
15355 Expression => New_Copy (Discr_Val)));
15363 Next_Discriminant (Discr);
15368 Comp_List => Comp_List,
15369 Governed_By => Constraints,
15370 Into => Components,
15371 Report_Errors => Report_Errors);
15373 -- Check that each component present is fully initialized
15375 Comp_Elmt := First_Elmt (Components);
15376 while Present (Comp_Elmt) loop
15377 Comp_Id := Node (Comp_Elmt);
15379 if Ekind (Comp_Id) = E_Component
15380 and then (No (Parent (Comp_Id))
15381 or else No (Expression (Parent (Comp_Id))))
15382 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
15387 Next_Elmt (Comp_Elmt);
15392 elsif Is_Private_Type (Typ) then
15394 U : constant Entity_Id := Underlying_Type (Typ);
15400 return Is_Fully_Initialized_Variant (U);
15407 end Is_Fully_Initialized_Variant;
15409 ------------------------------------
15410 -- Is_Generic_Declaration_Or_Body --
15411 ------------------------------------
15413 function Is_Generic_Declaration_Or_Body (Decl : Node_Id) return Boolean is
15414 Spec_Decl : Node_Id;
15417 -- Package/subprogram body
15419 if Nkind_In (Decl, N_Package_Body, N_Subprogram_Body)
15420 and then Present (Corresponding_Spec (Decl))
15422 Spec_Decl := Unit_Declaration_Node (Corresponding_Spec (Decl));
15424 -- Package/subprogram body stub
15426 elsif Nkind_In (Decl, N_Package_Body_Stub, N_Subprogram_Body_Stub)
15427 and then Present (Corresponding_Spec_Of_Stub (Decl))
15430 Unit_Declaration_Node (Corresponding_Spec_Of_Stub (Decl));
15438 -- Rather than inspecting the defining entity of the spec declaration,
15439 -- look at its Nkind. This takes care of the case where the analysis of
15440 -- a generic body modifies the Ekind of its spec to allow for recursive
15444 Nkind_In (Spec_Decl, N_Generic_Package_Declaration,
15445 N_Generic_Subprogram_Declaration);
15446 end Is_Generic_Declaration_Or_Body;
15448 ---------------------------
15449 -- Is_Independent_Object --
15450 ---------------------------
15452 function Is_Independent_Object (N : Node_Id) return Boolean is
15453 function Is_Independent_Object_Entity (Id : Entity_Id) return Boolean;
15454 -- Determine whether arbitrary entity Id denotes an object that is
15457 function Prefix_Has_Independent_Components (P : Node_Id) return Boolean;
15458 -- Determine whether prefix P has independent components. This requires
15459 -- the presence of an Independent_Components aspect/pragma.
15461 ------------------------------------
15462 -- Is_Independent_Object_Entity --
15463 ------------------------------------
15465 function Is_Independent_Object_Entity (Id : Entity_Id) return Boolean is
15469 and then (Is_Independent (Id)
15471 Is_Independent (Etype (Id)));
15472 end Is_Independent_Object_Entity;
15474 -------------------------------------
15475 -- Prefix_Has_Independent_Components --
15476 -------------------------------------
15478 function Prefix_Has_Independent_Components (P : Node_Id) return Boolean
15480 Typ : constant Entity_Id := Etype (P);
15483 if Is_Access_Type (Typ) then
15484 return Has_Independent_Components (Designated_Type (Typ));
15486 elsif Has_Independent_Components (Typ) then
15489 elsif Is_Entity_Name (P)
15490 and then Has_Independent_Components (Entity (P))
15497 end Prefix_Has_Independent_Components;
15499 -- Start of processing for Is_Independent_Object
15502 if Is_Entity_Name (N) then
15503 return Is_Independent_Object_Entity (Entity (N));
15505 elsif Is_Independent (Etype (N)) then
15508 elsif Nkind (N) = N_Indexed_Component then
15509 return Prefix_Has_Independent_Components (Prefix (N));
15511 elsif Nkind (N) = N_Selected_Component then
15512 return Prefix_Has_Independent_Components (Prefix (N))
15513 or else Is_Independent (Entity (Selector_Name (N)));
15518 end Is_Independent_Object;
15520 ----------------------------
15521 -- Is_Inherited_Operation --
15522 ----------------------------
15524 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
15525 pragma Assert (Is_Overloadable (E));
15526 Kind : constant Node_Kind := Nkind (Parent (E));
15528 return Kind = N_Full_Type_Declaration
15529 or else Kind = N_Private_Extension_Declaration
15530 or else Kind = N_Subtype_Declaration
15531 or else (Ekind (E) = E_Enumeration_Literal
15532 and then Is_Derived_Type (Etype (E)));
15533 end Is_Inherited_Operation;
15535 -------------------------------------
15536 -- Is_Inherited_Operation_For_Type --
15537 -------------------------------------
15539 function Is_Inherited_Operation_For_Type
15541 Typ : Entity_Id) return Boolean
15544 -- Check that the operation has been created by the type declaration
15546 return Is_Inherited_Operation (E)
15547 and then Defining_Identifier (Parent (E)) = Typ;
15548 end Is_Inherited_Operation_For_Type;
15550 --------------------------------------
15551 -- Is_Inlinable_Expression_Function --
15552 --------------------------------------
15554 function Is_Inlinable_Expression_Function
15555 (Subp : Entity_Id) return Boolean
15557 Return_Expr : Node_Id;
15560 if Is_Expression_Function_Or_Completion (Subp)
15561 and then Has_Pragma_Inline_Always (Subp)
15562 and then Needs_No_Actuals (Subp)
15563 and then No (Contract (Subp))
15564 and then not Is_Dispatching_Operation (Subp)
15565 and then Needs_Finalization (Etype (Subp))
15566 and then not Is_Class_Wide_Type (Etype (Subp))
15567 and then not (Has_Invariants (Etype (Subp)))
15568 and then Present (Subprogram_Body (Subp))
15569 and then Was_Expression_Function (Subprogram_Body (Subp))
15571 Return_Expr := Expression_Of_Expression_Function (Subp);
15573 -- The returned object must not have a qualified expression and its
15574 -- nominal subtype must be statically compatible with the result
15575 -- subtype of the expression function.
15578 Nkind (Return_Expr) = N_Identifier
15579 and then Etype (Return_Expr) = Etype (Subp);
15583 end Is_Inlinable_Expression_Function;
15589 function Is_Iterator (Typ : Entity_Id) return Boolean is
15590 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean;
15591 -- Determine whether type Iter_Typ is a predefined forward or reversible
15594 ----------------------
15595 -- Denotes_Iterator --
15596 ----------------------
15598 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean is
15600 -- Check that the name matches, and that the ultimate ancestor is in
15601 -- a predefined unit, i.e the one that declares iterator interfaces.
15604 Nam_In (Chars (Iter_Typ), Name_Forward_Iterator,
15605 Name_Reversible_Iterator)
15606 and then In_Predefined_Unit (Root_Type (Iter_Typ));
15607 end Denotes_Iterator;
15611 Iface_Elmt : Elmt_Id;
15614 -- Start of processing for Is_Iterator
15617 -- The type may be a subtype of a descendant of the proper instance of
15618 -- the predefined interface type, so we must use the root type of the
15619 -- given type. The same is done for Is_Reversible_Iterator.
15621 if Is_Class_Wide_Type (Typ)
15622 and then Denotes_Iterator (Root_Type (Typ))
15626 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
15629 elsif Present (Find_Value_Of_Aspect (Typ, Aspect_Iterable)) then
15633 Collect_Interfaces (Typ, Ifaces);
15635 Iface_Elmt := First_Elmt (Ifaces);
15636 while Present (Iface_Elmt) loop
15637 if Denotes_Iterator (Node (Iface_Elmt)) then
15641 Next_Elmt (Iface_Elmt);
15648 ----------------------------
15649 -- Is_Iterator_Over_Array --
15650 ----------------------------
15652 function Is_Iterator_Over_Array (N : Node_Id) return Boolean is
15653 Container : constant Node_Id := Name (N);
15654 Container_Typ : constant Entity_Id := Base_Type (Etype (Container));
15656 return Is_Array_Type (Container_Typ);
15657 end Is_Iterator_Over_Array;
15663 -- We seem to have a lot of overlapping functions that do similar things
15664 -- (testing for left hand sides or lvalues???).
15666 function Is_LHS (N : Node_Id) return Is_LHS_Result is
15667 P : constant Node_Id := Parent (N);
15670 -- Return True if we are the left hand side of an assignment statement
15672 if Nkind (P) = N_Assignment_Statement then
15673 if Name (P) = N then
15679 -- Case of prefix of indexed or selected component or slice
15681 elsif Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
15682 and then N = Prefix (P)
15684 -- Here we have the case where the parent P is N.Q or N(Q .. R).
15685 -- If P is an LHS, then N is also effectively an LHS, but there
15686 -- is an important exception. If N is of an access type, then
15687 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
15688 -- case this makes N.all a left hand side but not N itself.
15690 -- If we don't know the type yet, this is the case where we return
15691 -- Unknown, since the answer depends on the type which is unknown.
15693 if No (Etype (N)) then
15696 -- We have an Etype set, so we can check it
15698 elsif Is_Access_Type (Etype (N)) then
15701 -- OK, not access type case, so just test whole expression
15707 -- All other cases are not left hand sides
15714 -----------------------------
15715 -- Is_Library_Level_Entity --
15716 -----------------------------
15718 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
15720 -- The following is a small optimization, and it also properly handles
15721 -- discriminals, which in task bodies might appear in expressions before
15722 -- the corresponding procedure has been created, and which therefore do
15723 -- not have an assigned scope.
15725 if Is_Formal (E) then
15729 -- Normal test is simply that the enclosing dynamic scope is Standard
15731 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
15732 end Is_Library_Level_Entity;
15734 --------------------------------
15735 -- Is_Limited_Class_Wide_Type --
15736 --------------------------------
15738 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
15741 Is_Class_Wide_Type (Typ)
15742 and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
15743 end Is_Limited_Class_Wide_Type;
15745 ---------------------------------
15746 -- Is_Local_Variable_Reference --
15747 ---------------------------------
15749 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
15751 if not Is_Entity_Name (Expr) then
15756 Ent : constant Entity_Id := Entity (Expr);
15757 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
15759 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
15762 return Present (Sub) and then Sub = Current_Subprogram;
15766 end Is_Local_Variable_Reference;
15768 -----------------------
15769 -- Is_Name_Reference --
15770 -----------------------
15772 function Is_Name_Reference (N : Node_Id) return Boolean is
15774 if Is_Entity_Name (N) then
15775 return Present (Entity (N)) and then Is_Object (Entity (N));
15779 when N_Indexed_Component
15783 Is_Name_Reference (Prefix (N))
15784 or else Is_Access_Type (Etype (Prefix (N)));
15786 -- Attributes 'Input, 'Old and 'Result produce objects
15788 when N_Attribute_Reference =>
15790 Nam_In (Attribute_Name (N), Name_Input, Name_Old, Name_Result);
15792 when N_Selected_Component =>
15794 Is_Name_Reference (Selector_Name (N))
15796 (Is_Name_Reference (Prefix (N))
15797 or else Is_Access_Type (Etype (Prefix (N))));
15799 when N_Explicit_Dereference =>
15802 -- A view conversion of a tagged name is a name reference
15804 when N_Type_Conversion =>
15806 Is_Tagged_Type (Etype (Subtype_Mark (N)))
15807 and then Is_Tagged_Type (Etype (Expression (N)))
15808 and then Is_Name_Reference (Expression (N));
15810 -- An unchecked type conversion is considered to be a name if the
15811 -- operand is a name (this construction arises only as a result of
15812 -- expansion activities).
15814 when N_Unchecked_Type_Conversion =>
15815 return Is_Name_Reference (Expression (N));
15820 end Is_Name_Reference;
15822 ------------------------------------
15823 -- Is_Non_Preelaborable_Construct --
15824 ------------------------------------
15826 function Is_Non_Preelaborable_Construct (N : Node_Id) return Boolean is
15828 -- NOTE: the routines within Is_Non_Preelaborable_Construct are
15829 -- intentionally unnested to avoid deep indentation of code.
15831 Non_Preelaborable : exception;
15832 -- This exception is raised when the construct violates preelaborability
15833 -- to terminate the recursion.
15835 procedure Visit (Nod : Node_Id);
15836 -- Semantically inspect construct Nod to determine whether it violates
15837 -- preelaborability. This routine raises Non_Preelaborable.
15839 procedure Visit_List (List : List_Id);
15840 pragma Inline (Visit_List);
15841 -- Invoke Visit on each element of list List. This routine raises
15842 -- Non_Preelaborable.
15844 procedure Visit_Pragma (Prag : Node_Id);
15845 pragma Inline (Visit_Pragma);
15846 -- Semantically inspect pragma Prag to determine whether it violates
15847 -- preelaborability. This routine raises Non_Preelaborable.
15849 procedure Visit_Subexpression (Expr : Node_Id);
15850 pragma Inline (Visit_Subexpression);
15851 -- Semantically inspect expression Expr to determine whether it violates
15852 -- preelaborability. This routine raises Non_Preelaborable.
15858 procedure Visit (Nod : Node_Id) is
15860 case Nkind (Nod) is
15864 when N_Component_Declaration =>
15866 -- Defining_Identifier is left out because it is not relevant
15867 -- for preelaborability.
15869 Visit (Component_Definition (Nod));
15870 Visit (Expression (Nod));
15872 when N_Derived_Type_Definition =>
15874 -- Interface_List is left out because it is not relevant for
15875 -- preelaborability.
15877 Visit (Record_Extension_Part (Nod));
15878 Visit (Subtype_Indication (Nod));
15880 when N_Entry_Declaration =>
15882 -- A protected type with at leat one entry is not preelaborable
15883 -- while task types are never preelaborable. This renders entry
15884 -- declarations non-preelaborable.
15886 raise Non_Preelaborable;
15888 when N_Full_Type_Declaration =>
15890 -- Defining_Identifier and Discriminant_Specifications are left
15891 -- out because they are not relevant for preelaborability.
15893 Visit (Type_Definition (Nod));
15895 when N_Function_Instantiation
15896 | N_Package_Instantiation
15897 | N_Procedure_Instantiation
15899 -- Defining_Unit_Name and Name are left out because they are
15900 -- not relevant for preelaborability.
15902 Visit_List (Generic_Associations (Nod));
15904 when N_Object_Declaration =>
15906 -- Defining_Identifier is left out because it is not relevant
15907 -- for preelaborability.
15909 Visit (Object_Definition (Nod));
15911 if Has_Init_Expression (Nod) then
15912 Visit (Expression (Nod));
15914 elsif not Has_Preelaborable_Initialization
15915 (Etype (Defining_Entity (Nod)))
15917 raise Non_Preelaborable;
15920 when N_Private_Extension_Declaration
15921 | N_Subtype_Declaration
15923 -- Defining_Identifier, Discriminant_Specifications, and
15924 -- Interface_List are left out because they are not relevant
15925 -- for preelaborability.
15927 Visit (Subtype_Indication (Nod));
15929 when N_Protected_Type_Declaration
15930 | N_Single_Protected_Declaration
15932 -- Defining_Identifier, Discriminant_Specifications, and
15933 -- Interface_List are left out because they are not relevant
15934 -- for preelaborability.
15936 Visit (Protected_Definition (Nod));
15938 -- A [single] task type is never preelaborable
15940 when N_Single_Task_Declaration
15941 | N_Task_Type_Declaration
15943 raise Non_Preelaborable;
15948 Visit_Pragma (Nod);
15952 when N_Statement_Other_Than_Procedure_Call =>
15953 if Nkind (Nod) /= N_Null_Statement then
15954 raise Non_Preelaborable;
15960 Visit_Subexpression (Nod);
15964 when N_Access_To_Object_Definition =>
15965 Visit (Subtype_Indication (Nod));
15967 when N_Case_Expression_Alternative =>
15968 Visit (Expression (Nod));
15969 Visit_List (Discrete_Choices (Nod));
15971 when N_Component_Definition =>
15972 Visit (Access_Definition (Nod));
15973 Visit (Subtype_Indication (Nod));
15975 when N_Component_List =>
15976 Visit_List (Component_Items (Nod));
15977 Visit (Variant_Part (Nod));
15979 when N_Constrained_Array_Definition =>
15980 Visit_List (Discrete_Subtype_Definitions (Nod));
15981 Visit (Component_Definition (Nod));
15983 when N_Delta_Constraint
15984 | N_Digits_Constraint
15986 -- Delta_Expression and Digits_Expression are left out because
15987 -- they are not relevant for preelaborability.
15989 Visit (Range_Constraint (Nod));
15991 when N_Discriminant_Specification =>
15993 -- Defining_Identifier and Expression are left out because they
15994 -- are not relevant for preelaborability.
15996 Visit (Discriminant_Type (Nod));
15998 when N_Generic_Association =>
16000 -- Selector_Name is left out because it is not relevant for
16001 -- preelaborability.
16003 Visit (Explicit_Generic_Actual_Parameter (Nod));
16005 when N_Index_Or_Discriminant_Constraint =>
16006 Visit_List (Constraints (Nod));
16008 when N_Iterator_Specification =>
16010 -- Defining_Identifier is left out because it is not relevant
16011 -- for preelaborability.
16013 Visit (Name (Nod));
16014 Visit (Subtype_Indication (Nod));
16016 when N_Loop_Parameter_Specification =>
16018 -- Defining_Identifier is left out because it is not relevant
16019 -- for preelaborability.
16021 Visit (Discrete_Subtype_Definition (Nod));
16023 when N_Protected_Definition =>
16025 -- End_Label is left out because it is not relevant for
16026 -- preelaborability.
16028 Visit_List (Private_Declarations (Nod));
16029 Visit_List (Visible_Declarations (Nod));
16031 when N_Range_Constraint =>
16032 Visit (Range_Expression (Nod));
16034 when N_Record_Definition
16037 -- End_Label, Discrete_Choices, and Interface_List are left out
16038 -- because they are not relevant for preelaborability.
16040 Visit (Component_List (Nod));
16042 when N_Subtype_Indication =>
16044 -- Subtype_Mark is left out because it is not relevant for
16045 -- preelaborability.
16047 Visit (Constraint (Nod));
16049 when N_Unconstrained_Array_Definition =>
16051 -- Subtype_Marks is left out because it is not relevant for
16052 -- preelaborability.
16054 Visit (Component_Definition (Nod));
16056 when N_Variant_Part =>
16058 -- Name is left out because it is not relevant for
16059 -- preelaborability.
16061 Visit_List (Variants (Nod));
16074 procedure Visit_List (List : List_Id) is
16078 if Present (List) then
16079 Nod := First (List);
16080 while Present (Nod) loop
16091 procedure Visit_Pragma (Prag : Node_Id) is
16093 case Get_Pragma_Id (Prag) is
16095 | Pragma_Assert_And_Cut
16097 | Pragma_Async_Readers
16098 | Pragma_Async_Writers
16099 | Pragma_Attribute_Definition
16101 | Pragma_Constant_After_Elaboration
16103 | Pragma_Deadline_Floor
16104 | Pragma_Dispatching_Domain
16105 | Pragma_Effective_Reads
16106 | Pragma_Effective_Writes
16107 | Pragma_Extensions_Visible
16109 | Pragma_Secondary_Stack_Size
16111 | Pragma_Volatile_Function
16113 Visit_List (Pragma_Argument_Associations (Prag));
16122 -------------------------
16123 -- Visit_Subexpression --
16124 -------------------------
16126 procedure Visit_Subexpression (Expr : Node_Id) is
16127 procedure Visit_Aggregate (Aggr : Node_Id);
16128 pragma Inline (Visit_Aggregate);
16129 -- Semantically inspect aggregate Aggr to determine whether it
16130 -- violates preelaborability.
16132 ---------------------
16133 -- Visit_Aggregate --
16134 ---------------------
16136 procedure Visit_Aggregate (Aggr : Node_Id) is
16138 if not Is_Preelaborable_Aggregate (Aggr) then
16139 raise Non_Preelaborable;
16141 end Visit_Aggregate;
16143 -- Start of processing for Visit_Subexpression
16146 case Nkind (Expr) is
16148 | N_Qualified_Expression
16149 | N_Type_Conversion
16150 | N_Unchecked_Expression
16151 | N_Unchecked_Type_Conversion
16153 -- Subpool_Handle_Name and Subtype_Mark are left out because
16154 -- they are not relevant for preelaborability.
16156 Visit (Expression (Expr));
16159 | N_Extension_Aggregate
16161 Visit_Aggregate (Expr);
16163 when N_Attribute_Reference
16164 | N_Explicit_Dereference
16167 -- Attribute_Name and Expressions are left out because they are
16168 -- not relevant for preelaborability.
16170 Visit (Prefix (Expr));
16172 when N_Case_Expression =>
16174 -- End_Span is left out because it is not relevant for
16175 -- preelaborability.
16177 Visit_List (Alternatives (Expr));
16178 Visit (Expression (Expr));
16180 when N_Delta_Aggregate =>
16181 Visit_Aggregate (Expr);
16182 Visit (Expression (Expr));
16184 when N_Expression_With_Actions =>
16185 Visit_List (Actions (Expr));
16186 Visit (Expression (Expr));
16188 when N_If_Expression =>
16189 Visit_List (Expressions (Expr));
16191 when N_Quantified_Expression =>
16192 Visit (Condition (Expr));
16193 Visit (Iterator_Specification (Expr));
16194 Visit (Loop_Parameter_Specification (Expr));
16197 Visit (High_Bound (Expr));
16198 Visit (Low_Bound (Expr));
16201 Visit (Discrete_Range (Expr));
16202 Visit (Prefix (Expr));
16208 -- The evaluation of an object name is not preelaborable,
16209 -- unless the name is a static expression (checked further
16210 -- below), or statically denotes a discriminant.
16212 if Is_Entity_Name (Expr) then
16213 Object_Name : declare
16214 Id : constant Entity_Id := Entity (Expr);
16217 if Is_Object (Id) then
16218 if Ekind (Id) = E_Discriminant then
16221 elsif Ekind_In (Id, E_Constant, E_In_Parameter)
16222 and then Present (Discriminal_Link (Id))
16227 raise Non_Preelaborable;
16232 -- A non-static expression is not preelaborable
16234 elsif not Is_OK_Static_Expression (Expr) then
16235 raise Non_Preelaborable;
16238 end Visit_Subexpression;
16240 -- Start of processing for Is_Non_Preelaborable_Construct
16245 -- At this point it is known that the construct is preelaborable
16251 -- The elaboration of the construct performs an action which violates
16252 -- preelaborability.
16254 when Non_Preelaborable =>
16256 end Is_Non_Preelaborable_Construct;
16258 ---------------------------------
16259 -- Is_Nontrivial_DIC_Procedure --
16260 ---------------------------------
16262 function Is_Nontrivial_DIC_Procedure (Id : Entity_Id) return Boolean is
16263 Body_Decl : Node_Id;
16267 if Ekind (Id) = E_Procedure and then Is_DIC_Procedure (Id) then
16269 Unit_Declaration_Node
16270 (Corresponding_Body (Unit_Declaration_Node (Id)));
16272 -- The body of the Default_Initial_Condition procedure must contain
16273 -- at least one statement, otherwise the generation of the subprogram
16276 pragma Assert (Present (Handled_Statement_Sequence (Body_Decl)));
16278 -- To qualify as nontrivial, the first statement of the procedure
16279 -- must be a check in the form of an if statement. If the original
16280 -- Default_Initial_Condition expression was folded, then the first
16281 -- statement is not a check.
16283 Stmt := First (Statements (Handled_Statement_Sequence (Body_Decl)));
16286 Nkind (Stmt) = N_If_Statement
16287 and then Nkind (Original_Node (Stmt)) = N_Pragma;
16291 end Is_Nontrivial_DIC_Procedure;
16293 -------------------------
16294 -- Is_Null_Record_Type --
16295 -------------------------
16297 function Is_Null_Record_Type (T : Entity_Id) return Boolean is
16298 Decl : constant Node_Id := Parent (T);
16300 return Nkind (Decl) = N_Full_Type_Declaration
16301 and then Nkind (Type_Definition (Decl)) = N_Record_Definition
16303 (No (Component_List (Type_Definition (Decl)))
16304 or else Null_Present (Component_List (Type_Definition (Decl))));
16305 end Is_Null_Record_Type;
16307 ---------------------
16308 -- Is_Object_Image --
16309 ---------------------
16311 function Is_Object_Image (Prefix : Node_Id) return Boolean is
16313 -- When the type of the prefix is not scalar, then the prefix is not
16314 -- valid in any scenario.
16316 if not Is_Scalar_Type (Etype (Prefix)) then
16320 -- Here we test for the case that the prefix is not a type and assume
16321 -- if it is not then it must be a named value or an object reference.
16322 -- This is because the parser always checks that prefixes of attributes
16325 return not (Is_Entity_Name (Prefix) and then Is_Type (Entity (Prefix)));
16326 end Is_Object_Image;
16328 -------------------------
16329 -- Is_Object_Reference --
16330 -------------------------
16332 function Is_Object_Reference (N : Node_Id) return Boolean is
16333 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean;
16334 -- Determine whether N is the name of an internally-generated renaming
16336 --------------------------------------
16337 -- Is_Internally_Generated_Renaming --
16338 --------------------------------------
16340 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean is
16345 while Present (P) loop
16346 if Nkind (P) = N_Object_Renaming_Declaration then
16347 return not Comes_From_Source (P);
16348 elsif Is_List_Member (P) then
16356 end Is_Internally_Generated_Renaming;
16358 -- Start of processing for Is_Object_Reference
16361 if Is_Entity_Name (N) then
16362 return Present (Entity (N)) and then Is_Object (Entity (N));
16366 when N_Indexed_Component
16370 Is_Object_Reference (Prefix (N))
16371 or else Is_Access_Type (Etype (Prefix (N)));
16373 -- In Ada 95, a function call is a constant object; a procedure
16376 -- Note that predefined operators are functions as well, and so
16377 -- are attributes that are (can be renamed as) functions.
16383 return Etype (N) /= Standard_Void_Type;
16385 -- Attributes references 'Loop_Entry, 'Old, and 'Result yield
16386 -- objects, even though they are not functions.
16388 when N_Attribute_Reference =>
16390 Nam_In (Attribute_Name (N), Name_Loop_Entry,
16393 or else Is_Function_Attribute_Name (Attribute_Name (N));
16395 when N_Selected_Component =>
16397 Is_Object_Reference (Selector_Name (N))
16399 (Is_Object_Reference (Prefix (N))
16400 or else Is_Access_Type (Etype (Prefix (N))));
16402 -- An explicit dereference denotes an object, except that a
16403 -- conditional expression gets turned into an explicit dereference
16404 -- in some cases, and conditional expressions are not object
16407 when N_Explicit_Dereference =>
16408 return not Nkind_In (Original_Node (N), N_Case_Expression,
16411 -- A view conversion of a tagged object is an object reference
16413 when N_Type_Conversion =>
16414 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
16415 and then Is_Tagged_Type (Etype (Expression (N)))
16416 and then Is_Object_Reference (Expression (N));
16418 -- An unchecked type conversion is considered to be an object if
16419 -- the operand is an object (this construction arises only as a
16420 -- result of expansion activities).
16422 when N_Unchecked_Type_Conversion =>
16425 -- Allow string literals to act as objects as long as they appear
16426 -- in internally-generated renamings. The expansion of iterators
16427 -- may generate such renamings when the range involves a string
16430 when N_String_Literal =>
16431 return Is_Internally_Generated_Renaming (Parent (N));
16433 -- AI05-0003: In Ada 2012 a qualified expression is a name.
16434 -- This allows disambiguation of function calls and the use
16435 -- of aggregates in more contexts.
16437 when N_Qualified_Expression =>
16438 if Ada_Version < Ada_2012 then
16441 return Is_Object_Reference (Expression (N))
16442 or else Nkind (Expression (N)) = N_Aggregate;
16449 end Is_Object_Reference;
16451 -----------------------------------
16452 -- Is_OK_Variable_For_Out_Formal --
16453 -----------------------------------
16455 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
16457 Note_Possible_Modification (AV, Sure => True);
16459 -- We must reject parenthesized variable names. Comes_From_Source is
16460 -- checked because there are currently cases where the compiler violates
16461 -- this rule (e.g. passing a task object to its controlled Initialize
16462 -- routine). This should be properly documented in sinfo???
16464 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
16467 -- A variable is always allowed
16469 elsif Is_Variable (AV) then
16472 -- Generalized indexing operations are rewritten as explicit
16473 -- dereferences, and it is only during resolution that we can
16474 -- check whether the context requires an access_to_variable type.
16476 elsif Nkind (AV) = N_Explicit_Dereference
16477 and then Ada_Version >= Ada_2012
16478 and then Nkind (Original_Node (AV)) = N_Indexed_Component
16479 and then Present (Etype (Original_Node (AV)))
16480 and then Has_Implicit_Dereference (Etype (Original_Node (AV)))
16482 return not Is_Access_Constant (Etype (Prefix (AV)));
16484 -- Unchecked conversions are allowed only if they come from the
16485 -- generated code, which sometimes uses unchecked conversions for out
16486 -- parameters in cases where code generation is unaffected. We tell
16487 -- source unchecked conversions by seeing if they are rewrites of
16488 -- an original Unchecked_Conversion function call, or of an explicit
16489 -- conversion of a function call or an aggregate (as may happen in the
16490 -- expansion of a packed array aggregate).
16492 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
16493 if Nkind_In (Original_Node (AV), N_Function_Call, N_Aggregate) then
16496 elsif Comes_From_Source (AV)
16497 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
16501 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
16502 return Is_OK_Variable_For_Out_Formal (Expression (AV));
16508 -- Normal type conversions are allowed if argument is a variable
16510 elsif Nkind (AV) = N_Type_Conversion then
16511 if Is_Variable (Expression (AV))
16512 and then Paren_Count (Expression (AV)) = 0
16514 Note_Possible_Modification (Expression (AV), Sure => True);
16517 -- We also allow a non-parenthesized expression that raises
16518 -- constraint error if it rewrites what used to be a variable
16520 elsif Raises_Constraint_Error (Expression (AV))
16521 and then Paren_Count (Expression (AV)) = 0
16522 and then Is_Variable (Original_Node (Expression (AV)))
16526 -- Type conversion of something other than a variable
16532 -- If this node is rewritten, then test the original form, if that is
16533 -- OK, then we consider the rewritten node OK (for example, if the
16534 -- original node is a conversion, then Is_Variable will not be true
16535 -- but we still want to allow the conversion if it converts a variable).
16537 elsif Is_Rewrite_Substitution (AV) then
16539 -- In Ada 2012, the explicit dereference may be a rewritten call to a
16540 -- Reference function.
16542 if Ada_Version >= Ada_2012
16543 and then Nkind (Original_Node (AV)) = N_Function_Call
16545 Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
16548 -- Check that this is not a constant reference.
16550 return not Is_Access_Constant (Etype (Prefix (AV)));
16552 elsif Has_Implicit_Dereference (Etype (Original_Node (AV))) then
16554 not Is_Access_Constant (Etype
16555 (Get_Reference_Discriminant (Etype (Original_Node (AV)))));
16558 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
16561 -- All other non-variables are rejected
16566 end Is_OK_Variable_For_Out_Formal;
16568 ----------------------------
16569 -- Is_OK_Volatile_Context --
16570 ----------------------------
16572 function Is_OK_Volatile_Context
16573 (Context : Node_Id;
16574 Obj_Ref : Node_Id) return Boolean
16576 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean;
16577 -- Determine whether an arbitrary node denotes a call to a protected
16578 -- entry, function, or procedure in prefixed form where the prefix is
16581 function Within_Check (Nod : Node_Id) return Boolean;
16582 -- Determine whether an arbitrary node appears in a check node
16584 function Within_Volatile_Function (Id : Entity_Id) return Boolean;
16585 -- Determine whether an arbitrary entity appears in a volatile function
16587 ---------------------------------
16588 -- Is_Protected_Operation_Call --
16589 ---------------------------------
16591 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean is
16596 -- A call to a protected operations retains its selected component
16597 -- form as opposed to other prefixed calls that are transformed in
16600 if Nkind (Nod) = N_Selected_Component then
16601 Pref := Prefix (Nod);
16602 Subp := Selector_Name (Nod);
16606 and then Present (Etype (Pref))
16607 and then Is_Protected_Type (Etype (Pref))
16608 and then Is_Entity_Name (Subp)
16609 and then Present (Entity (Subp))
16610 and then Ekind_In (Entity (Subp), E_Entry,
16617 end Is_Protected_Operation_Call;
16623 function Within_Check (Nod : Node_Id) return Boolean is
16627 -- Climb the parent chain looking for a check node
16630 while Present (Par) loop
16631 if Nkind (Par) in N_Raise_xxx_Error then
16634 -- Prevent the search from going too far
16636 elsif Is_Body_Or_Package_Declaration (Par) then
16640 Par := Parent (Par);
16646 ------------------------------
16647 -- Within_Volatile_Function --
16648 ------------------------------
16650 function Within_Volatile_Function (Id : Entity_Id) return Boolean is
16651 Func_Id : Entity_Id;
16654 -- Traverse the scope stack looking for a [generic] function
16657 while Present (Func_Id) and then Func_Id /= Standard_Standard loop
16658 if Ekind_In (Func_Id, E_Function, E_Generic_Function) then
16659 return Is_Volatile_Function (Func_Id);
16662 Func_Id := Scope (Func_Id);
16666 end Within_Volatile_Function;
16670 Obj_Id : Entity_Id;
16672 -- Start of processing for Is_OK_Volatile_Context
16675 -- The volatile object appears on either side of an assignment
16677 if Nkind (Context) = N_Assignment_Statement then
16680 -- The volatile object is part of the initialization expression of
16683 elsif Nkind (Context) = N_Object_Declaration
16684 and then Present (Expression (Context))
16685 and then Expression (Context) = Obj_Ref
16687 Obj_Id := Defining_Entity (Context);
16689 -- The volatile object acts as the initialization expression of an
16690 -- extended return statement. This is valid context as long as the
16691 -- function is volatile.
16693 if Is_Return_Object (Obj_Id) then
16694 return Within_Volatile_Function (Obj_Id);
16696 -- Otherwise this is a normal object initialization
16702 -- The volatile object acts as the name of a renaming declaration
16704 elsif Nkind (Context) = N_Object_Renaming_Declaration
16705 and then Name (Context) = Obj_Ref
16709 -- The volatile object appears as an actual parameter in a call to an
16710 -- instance of Unchecked_Conversion whose result is renamed.
16712 elsif Nkind (Context) = N_Function_Call
16713 and then Is_Entity_Name (Name (Context))
16714 and then Is_Unchecked_Conversion_Instance (Entity (Name (Context)))
16715 and then Nkind (Parent (Context)) = N_Object_Renaming_Declaration
16719 -- The volatile object is actually the prefix in a protected entry,
16720 -- function, or procedure call.
16722 elsif Is_Protected_Operation_Call (Context) then
16725 -- The volatile object appears as the expression of a simple return
16726 -- statement that applies to a volatile function.
16728 elsif Nkind (Context) = N_Simple_Return_Statement
16729 and then Expression (Context) = Obj_Ref
16732 Within_Volatile_Function (Return_Statement_Entity (Context));
16734 -- The volatile object appears as the prefix of a name occurring in a
16735 -- non-interfering context.
16737 elsif Nkind_In (Context, N_Attribute_Reference,
16738 N_Explicit_Dereference,
16739 N_Indexed_Component,
16740 N_Selected_Component,
16742 and then Prefix (Context) = Obj_Ref
16743 and then Is_OK_Volatile_Context
16744 (Context => Parent (Context),
16745 Obj_Ref => Context)
16749 -- The volatile object appears as the prefix of attributes Address,
16750 -- Alignment, Component_Size, First, First_Bit, Last, Last_Bit, Length,
16751 -- Position, Size, Storage_Size.
16753 elsif Nkind (Context) = N_Attribute_Reference
16754 and then Prefix (Context) = Obj_Ref
16755 and then Nam_In (Attribute_Name (Context), Name_Address,
16757 Name_Component_Size,
16769 -- The volatile object appears as the expression of a type conversion
16770 -- occurring in a non-interfering context.
16772 elsif Nkind_In (Context, N_Type_Conversion,
16773 N_Unchecked_Type_Conversion)
16774 and then Expression (Context) = Obj_Ref
16775 and then Is_OK_Volatile_Context
16776 (Context => Parent (Context),
16777 Obj_Ref => Context)
16781 -- The volatile object appears as the expression in a delay statement
16783 elsif Nkind (Context) in N_Delay_Statement then
16786 -- Allow references to volatile objects in various checks. This is not a
16787 -- direct SPARK 2014 requirement.
16789 elsif Within_Check (Context) then
16792 -- Assume that references to effectively volatile objects that appear
16793 -- as actual parameters in a subprogram call are always legal. A full
16794 -- legality check is done when the actuals are resolved (see routine
16795 -- Resolve_Actuals).
16797 elsif Within_Subprogram_Call (Context) then
16800 -- Otherwise the context is not suitable for an effectively volatile
16806 end Is_OK_Volatile_Context;
16808 ------------------------------------
16809 -- Is_Package_Contract_Annotation --
16810 ------------------------------------
16812 function Is_Package_Contract_Annotation (Item : Node_Id) return Boolean is
16816 if Nkind (Item) = N_Aspect_Specification then
16817 Nam := Chars (Identifier (Item));
16819 else pragma Assert (Nkind (Item) = N_Pragma);
16820 Nam := Pragma_Name (Item);
16823 return Nam = Name_Abstract_State
16824 or else Nam = Name_Initial_Condition
16825 or else Nam = Name_Initializes
16826 or else Nam = Name_Refined_State;
16827 end Is_Package_Contract_Annotation;
16829 -----------------------------------
16830 -- Is_Partially_Initialized_Type --
16831 -----------------------------------
16833 function Is_Partially_Initialized_Type
16835 Include_Implicit : Boolean := True) return Boolean
16838 if Is_Scalar_Type (Typ) then
16841 elsif Is_Access_Type (Typ) then
16842 return Include_Implicit;
16844 elsif Is_Array_Type (Typ) then
16846 -- If component type is partially initialized, so is array type
16848 if Is_Partially_Initialized_Type
16849 (Component_Type (Typ), Include_Implicit)
16853 -- Otherwise we are only partially initialized if we are fully
16854 -- initialized (this is the empty array case, no point in us
16855 -- duplicating that code here).
16858 return Is_Fully_Initialized_Type (Typ);
16861 elsif Is_Record_Type (Typ) then
16863 -- A discriminated type is always partially initialized if in
16866 if Has_Discriminants (Typ) and then Include_Implicit then
16869 -- A tagged type is always partially initialized
16871 elsif Is_Tagged_Type (Typ) then
16874 -- Case of non-discriminated record
16880 Component_Present : Boolean := False;
16881 -- Set True if at least one component is present. If no
16882 -- components are present, then record type is fully
16883 -- initialized (another odd case, like the null array).
16886 -- Loop through components
16888 Ent := First_Entity (Typ);
16889 while Present (Ent) loop
16890 if Ekind (Ent) = E_Component then
16891 Component_Present := True;
16893 -- If a component has an initialization expression then
16894 -- the enclosing record type is partially initialized
16896 if Present (Parent (Ent))
16897 and then Present (Expression (Parent (Ent)))
16901 -- If a component is of a type which is itself partially
16902 -- initialized, then the enclosing record type is also.
16904 elsif Is_Partially_Initialized_Type
16905 (Etype (Ent), Include_Implicit)
16914 -- No initialized components found. If we found any components
16915 -- they were all uninitialized so the result is false.
16917 if Component_Present then
16920 -- But if we found no components, then all the components are
16921 -- initialized so we consider the type to be initialized.
16929 -- Concurrent types are always fully initialized
16931 elsif Is_Concurrent_Type (Typ) then
16934 -- For a private type, go to underlying type. If there is no underlying
16935 -- type then just assume this partially initialized. Not clear if this
16936 -- can happen in a non-error case, but no harm in testing for this.
16938 elsif Is_Private_Type (Typ) then
16940 U : constant Entity_Id := Underlying_Type (Typ);
16945 return Is_Partially_Initialized_Type (U, Include_Implicit);
16949 -- For any other type (are there any?) assume partially initialized
16954 end Is_Partially_Initialized_Type;
16956 ------------------------------------
16957 -- Is_Potentially_Persistent_Type --
16958 ------------------------------------
16960 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
16965 -- For private type, test corresponding full type
16967 if Is_Private_Type (T) then
16968 return Is_Potentially_Persistent_Type (Full_View (T));
16970 -- Scalar types are potentially persistent
16972 elsif Is_Scalar_Type (T) then
16975 -- Record type is potentially persistent if not tagged and the types of
16976 -- all it components are potentially persistent, and no component has
16977 -- an initialization expression.
16979 elsif Is_Record_Type (T)
16980 and then not Is_Tagged_Type (T)
16981 and then not Is_Partially_Initialized_Type (T)
16983 Comp := First_Component (T);
16984 while Present (Comp) loop
16985 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
16988 Next_Entity (Comp);
16994 -- Array type is potentially persistent if its component type is
16995 -- potentially persistent and if all its constraints are static.
16997 elsif Is_Array_Type (T) then
16998 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
17002 Indx := First_Index (T);
17003 while Present (Indx) loop
17004 if not Is_OK_Static_Subtype (Etype (Indx)) then
17013 -- All other types are not potentially persistent
17018 end Is_Potentially_Persistent_Type;
17020 --------------------------------
17021 -- Is_Potentially_Unevaluated --
17022 --------------------------------
17024 function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is
17032 -- A postcondition whose expression is a short-circuit is broken down
17033 -- into individual aspects for better exception reporting. The original
17034 -- short-circuit expression is rewritten as the second operand, and an
17035 -- occurrence of 'Old in that operand is potentially unevaluated.
17036 -- See sem_ch13.adb for details of this transformation. The reference
17037 -- to 'Old may appear within an expression, so we must look for the
17038 -- enclosing pragma argument in the tree that contains the reference.
17040 while Present (Par)
17041 and then Nkind (Par) /= N_Pragma_Argument_Association
17043 if Is_Rewrite_Substitution (Par)
17044 and then Nkind (Original_Node (Par)) = N_And_Then
17049 Par := Parent (Par);
17052 -- Other cases; 'Old appears within other expression (not the top-level
17053 -- conjunct in a postcondition) with a potentially unevaluated operand.
17055 Par := Parent (Expr);
17056 while not Nkind_In (Par, N_And_Then,
17062 N_Quantified_Expression)
17065 Par := Parent (Par);
17067 -- If the context is not an expression, or if is the result of
17068 -- expansion of an enclosing construct (such as another attribute)
17069 -- the predicate does not apply.
17071 if Nkind (Par) = N_Case_Expression_Alternative then
17074 elsif Nkind (Par) not in N_Subexpr
17075 or else not Comes_From_Source (Par)
17081 if Nkind (Par) = N_If_Expression then
17082 return Is_Elsif (Par) or else Expr /= First (Expressions (Par));
17084 elsif Nkind (Par) = N_Case_Expression then
17085 return Expr /= Expression (Par);
17087 elsif Nkind_In (Par, N_And_Then, N_Or_Else) then
17088 return Expr = Right_Opnd (Par);
17090 elsif Nkind_In (Par, N_In, N_Not_In) then
17092 -- If the membership includes several alternatives, only the first is
17093 -- definitely evaluated.
17095 if Present (Alternatives (Par)) then
17096 return Expr /= First (Alternatives (Par));
17098 -- If this is a range membership both bounds are evaluated
17104 elsif Nkind (Par) = N_Quantified_Expression then
17105 return Expr = Condition (Par);
17110 end Is_Potentially_Unevaluated;
17112 -----------------------------------------
17113 -- Is_Predefined_Dispatching_Operation --
17114 -----------------------------------------
17116 function Is_Predefined_Dispatching_Operation
17117 (E : Entity_Id) return Boolean
17119 TSS_Name : TSS_Name_Type;
17122 if not Is_Dispatching_Operation (E) then
17126 Get_Name_String (Chars (E));
17128 -- Most predefined primitives have internally generated names. Equality
17129 -- must be treated differently; the predefined operation is recognized
17130 -- as a homogeneous binary operator that returns Boolean.
17132 if Name_Len > TSS_Name_Type'Last then
17135 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
17137 if Nam_In (Chars (E), Name_uAssign, Name_uSize)
17139 (Chars (E) = Name_Op_Eq
17140 and then Etype (First_Formal (E)) = Etype (Last_Formal (E)))
17141 or else TSS_Name = TSS_Deep_Adjust
17142 or else TSS_Name = TSS_Deep_Finalize
17143 or else TSS_Name = TSS_Stream_Input
17144 or else TSS_Name = TSS_Stream_Output
17145 or else TSS_Name = TSS_Stream_Read
17146 or else TSS_Name = TSS_Stream_Write
17147 or else Is_Predefined_Interface_Primitive (E)
17154 end Is_Predefined_Dispatching_Operation;
17156 ---------------------------------------
17157 -- Is_Predefined_Interface_Primitive --
17158 ---------------------------------------
17160 function Is_Predefined_Interface_Primitive (E : Entity_Id) return Boolean is
17162 -- In VM targets we don't restrict the functionality of this test to
17163 -- compiling in Ada 2005 mode since in VM targets any tagged type has
17164 -- these primitives.
17166 return (Ada_Version >= Ada_2005 or else not Tagged_Type_Expansion)
17167 and then Nam_In (Chars (E), Name_uDisp_Asynchronous_Select,
17168 Name_uDisp_Conditional_Select,
17169 Name_uDisp_Get_Prim_Op_Kind,
17170 Name_uDisp_Get_Task_Id,
17171 Name_uDisp_Requeue,
17172 Name_uDisp_Timed_Select);
17173 end Is_Predefined_Interface_Primitive;
17175 ---------------------------------------
17176 -- Is_Predefined_Internal_Operation --
17177 ---------------------------------------
17179 function Is_Predefined_Internal_Operation
17180 (E : Entity_Id) return Boolean
17182 TSS_Name : TSS_Name_Type;
17185 if not Is_Dispatching_Operation (E) then
17189 Get_Name_String (Chars (E));
17191 -- Most predefined primitives have internally generated names. Equality
17192 -- must be treated differently; the predefined operation is recognized
17193 -- as a homogeneous binary operator that returns Boolean.
17195 if Name_Len > TSS_Name_Type'Last then
17198 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
17200 if Nam_In (Chars (E), Name_uSize, Name_uAssign)
17202 (Chars (E) = Name_Op_Eq
17203 and then Etype (First_Formal (E)) = Etype (Last_Formal (E)))
17204 or else TSS_Name = TSS_Deep_Adjust
17205 or else TSS_Name = TSS_Deep_Finalize
17206 or else Is_Predefined_Interface_Primitive (E)
17213 end Is_Predefined_Internal_Operation;
17215 --------------------------------
17216 -- Is_Preelaborable_Aggregate --
17217 --------------------------------
17219 function Is_Preelaborable_Aggregate (Aggr : Node_Id) return Boolean is
17220 Aggr_Typ : constant Entity_Id := Etype (Aggr);
17221 Array_Aggr : constant Boolean := Is_Array_Type (Aggr_Typ);
17223 Anc_Part : Node_Id;
17226 Comp_Typ : Entity_Id := Empty; -- init to avoid warning
17231 Comp_Typ := Component_Type (Aggr_Typ);
17234 -- Inspect the ancestor part
17236 if Nkind (Aggr) = N_Extension_Aggregate then
17237 Anc_Part := Ancestor_Part (Aggr);
17239 -- The ancestor denotes a subtype mark
17241 if Is_Entity_Name (Anc_Part)
17242 and then Is_Type (Entity (Anc_Part))
17244 if not Has_Preelaborable_Initialization (Entity (Anc_Part)) then
17248 -- Otherwise the ancestor denotes an expression
17250 elsif not Is_Preelaborable_Construct (Anc_Part) then
17255 -- Inspect the positional associations
17257 Expr := First (Expressions (Aggr));
17258 while Present (Expr) loop
17259 if not Is_Preelaborable_Construct (Expr) then
17266 -- Inspect the named associations
17268 Assoc := First (Component_Associations (Aggr));
17269 while Present (Assoc) loop
17271 -- Inspect the choices of the current named association
17273 Choice := First (Choices (Assoc));
17274 while Present (Choice) loop
17277 -- For a choice to be preelaborable, it must denote either a
17278 -- static range or a static expression.
17280 if Nkind (Choice) = N_Others_Choice then
17283 elsif Nkind (Choice) = N_Range then
17284 if not Is_OK_Static_Range (Choice) then
17288 elsif not Is_OK_Static_Expression (Choice) then
17293 Comp_Typ := Etype (Choice);
17299 -- The type of the choice must have preelaborable initialization if
17300 -- the association carries a <>.
17302 pragma Assert (Present (Comp_Typ));
17303 if Box_Present (Assoc) then
17304 if not Has_Preelaborable_Initialization (Comp_Typ) then
17308 -- The type of the expression must have preelaborable initialization
17310 elsif not Is_Preelaborable_Construct (Expression (Assoc)) then
17317 -- At this point the aggregate is preelaborable
17320 end Is_Preelaborable_Aggregate;
17322 --------------------------------
17323 -- Is_Preelaborable_Construct --
17324 --------------------------------
17326 function Is_Preelaborable_Construct (N : Node_Id) return Boolean is
17330 if Nkind_In (N, N_Aggregate, N_Extension_Aggregate) then
17331 return Is_Preelaborable_Aggregate (N);
17333 -- Attributes are allowed in general, even if their prefix is a formal
17334 -- type. It seems that certain attributes known not to be static might
17335 -- not be allowed, but there are no rules to prevent them.
17337 elsif Nkind (N) = N_Attribute_Reference then
17342 elsif Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
17345 elsif Nkind (N) = N_Qualified_Expression then
17346 return Is_Preelaborable_Construct (Expression (N));
17348 -- Names are preelaborable when they denote a discriminant of an
17349 -- enclosing type. Discriminals are also considered for this check.
17351 elsif Is_Entity_Name (N)
17352 and then Present (Entity (N))
17354 (Ekind (Entity (N)) = E_Discriminant
17355 or else (Ekind_In (Entity (N), E_Constant, E_In_Parameter)
17356 and then Present (Discriminal_Link (Entity (N)))))
17362 elsif Nkind (N) = N_Null then
17365 -- Otherwise the construct is not preelaborable
17370 end Is_Preelaborable_Construct;
17372 ---------------------------------
17373 -- Is_Protected_Self_Reference --
17374 ---------------------------------
17376 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
17378 function In_Access_Definition (N : Node_Id) return Boolean;
17379 -- Returns true if N belongs to an access definition
17381 --------------------------
17382 -- In_Access_Definition --
17383 --------------------------
17385 function In_Access_Definition (N : Node_Id) return Boolean is
17390 while Present (P) loop
17391 if Nkind (P) = N_Access_Definition then
17399 end In_Access_Definition;
17401 -- Start of processing for Is_Protected_Self_Reference
17404 -- Verify that prefix is analyzed and has the proper form. Note that
17405 -- the attributes Elab_Spec, Elab_Body, and Elab_Subp_Body, which also
17406 -- produce the address of an entity, do not analyze their prefix
17407 -- because they denote entities that are not necessarily visible.
17408 -- Neither of them can apply to a protected type.
17410 return Ada_Version >= Ada_2005
17411 and then Is_Entity_Name (N)
17412 and then Present (Entity (N))
17413 and then Is_Protected_Type (Entity (N))
17414 and then In_Open_Scopes (Entity (N))
17415 and then not In_Access_Definition (N);
17416 end Is_Protected_Self_Reference;
17418 -----------------------------
17419 -- Is_RCI_Pkg_Spec_Or_Body --
17420 -----------------------------
17422 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
17424 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
17425 -- Return True if the unit of Cunit is an RCI package declaration
17427 ---------------------------
17428 -- Is_RCI_Pkg_Decl_Cunit --
17429 ---------------------------
17431 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
17432 The_Unit : constant Node_Id := Unit (Cunit);
17435 if Nkind (The_Unit) /= N_Package_Declaration then
17439 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
17440 end Is_RCI_Pkg_Decl_Cunit;
17442 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
17445 return Is_RCI_Pkg_Decl_Cunit (Cunit)
17447 (Nkind (Unit (Cunit)) = N_Package_Body
17448 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
17449 end Is_RCI_Pkg_Spec_Or_Body;
17451 -----------------------------------------
17452 -- Is_Remote_Access_To_Class_Wide_Type --
17453 -----------------------------------------
17455 function Is_Remote_Access_To_Class_Wide_Type
17456 (E : Entity_Id) return Boolean
17459 -- A remote access to class-wide type is a general access to object type
17460 -- declared in the visible part of a Remote_Types or Remote_Call_
17463 return Ekind (E) = E_General_Access_Type
17464 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
17465 end Is_Remote_Access_To_Class_Wide_Type;
17467 -----------------------------------------
17468 -- Is_Remote_Access_To_Subprogram_Type --
17469 -----------------------------------------
17471 function Is_Remote_Access_To_Subprogram_Type
17472 (E : Entity_Id) return Boolean
17475 return (Ekind (E) = E_Access_Subprogram_Type
17476 or else (Ekind (E) = E_Record_Type
17477 and then Present (Corresponding_Remote_Type (E))))
17478 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
17479 end Is_Remote_Access_To_Subprogram_Type;
17481 --------------------
17482 -- Is_Remote_Call --
17483 --------------------
17485 function Is_Remote_Call (N : Node_Id) return Boolean is
17487 if Nkind (N) not in N_Subprogram_Call then
17489 -- An entry call cannot be remote
17493 elsif Nkind (Name (N)) in N_Has_Entity
17494 and then Is_Remote_Call_Interface (Entity (Name (N)))
17496 -- A subprogram declared in the spec of a RCI package is remote
17500 elsif Nkind (Name (N)) = N_Explicit_Dereference
17501 and then Is_Remote_Access_To_Subprogram_Type
17502 (Etype (Prefix (Name (N))))
17504 -- The dereference of a RAS is a remote call
17508 elsif Present (Controlling_Argument (N))
17509 and then Is_Remote_Access_To_Class_Wide_Type
17510 (Etype (Controlling_Argument (N)))
17512 -- Any primitive operation call with a controlling argument of
17513 -- a RACW type is a remote call.
17518 -- All other calls are local calls
17521 end Is_Remote_Call;
17523 ----------------------
17524 -- Is_Renamed_Entry --
17525 ----------------------
17527 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
17528 Orig_Node : Node_Id := Empty;
17529 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
17531 function Is_Entry (Nam : Node_Id) return Boolean;
17532 -- Determine whether Nam is an entry. Traverse selectors if there are
17533 -- nested selected components.
17539 function Is_Entry (Nam : Node_Id) return Boolean is
17541 if Nkind (Nam) = N_Selected_Component then
17542 return Is_Entry (Selector_Name (Nam));
17545 return Ekind (Entity (Nam)) = E_Entry;
17548 -- Start of processing for Is_Renamed_Entry
17551 if Present (Alias (Proc_Nam)) then
17552 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
17555 -- Look for a rewritten subprogram renaming declaration
17557 if Nkind (Subp_Decl) = N_Subprogram_Declaration
17558 and then Present (Original_Node (Subp_Decl))
17560 Orig_Node := Original_Node (Subp_Decl);
17563 -- The rewritten subprogram is actually an entry
17565 if Present (Orig_Node)
17566 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
17567 and then Is_Entry (Name (Orig_Node))
17573 end Is_Renamed_Entry;
17575 -----------------------------
17576 -- Is_Renaming_Declaration --
17577 -----------------------------
17579 function Is_Renaming_Declaration (N : Node_Id) return Boolean is
17582 when N_Exception_Renaming_Declaration
17583 | N_Generic_Function_Renaming_Declaration
17584 | N_Generic_Package_Renaming_Declaration
17585 | N_Generic_Procedure_Renaming_Declaration
17586 | N_Object_Renaming_Declaration
17587 | N_Package_Renaming_Declaration
17588 | N_Subprogram_Renaming_Declaration
17595 end Is_Renaming_Declaration;
17597 ----------------------------
17598 -- Is_Reversible_Iterator --
17599 ----------------------------
17601 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
17602 Ifaces_List : Elist_Id;
17603 Iface_Elmt : Elmt_Id;
17607 if Is_Class_Wide_Type (Typ)
17608 and then Chars (Root_Type (Typ)) = Name_Reversible_Iterator
17609 and then In_Predefined_Unit (Root_Type (Typ))
17613 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
17617 Collect_Interfaces (Typ, Ifaces_List);
17619 Iface_Elmt := First_Elmt (Ifaces_List);
17620 while Present (Iface_Elmt) loop
17621 Iface := Node (Iface_Elmt);
17622 if Chars (Iface) = Name_Reversible_Iterator
17623 and then In_Predefined_Unit (Iface)
17628 Next_Elmt (Iface_Elmt);
17633 end Is_Reversible_Iterator;
17635 ----------------------
17636 -- Is_Selector_Name --
17637 ----------------------
17639 function Is_Selector_Name (N : Node_Id) return Boolean is
17641 if not Is_List_Member (N) then
17643 P : constant Node_Id := Parent (N);
17645 return Nkind_In (P, N_Expanded_Name,
17646 N_Generic_Association,
17647 N_Parameter_Association,
17648 N_Selected_Component)
17649 and then Selector_Name (P) = N;
17654 L : constant List_Id := List_Containing (N);
17655 P : constant Node_Id := Parent (L);
17657 return (Nkind (P) = N_Discriminant_Association
17658 and then Selector_Names (P) = L)
17660 (Nkind (P) = N_Component_Association
17661 and then Choices (P) = L);
17664 end Is_Selector_Name;
17666 ---------------------------------
17667 -- Is_Single_Concurrent_Object --
17668 ---------------------------------
17670 function Is_Single_Concurrent_Object (Id : Entity_Id) return Boolean is
17673 Is_Single_Protected_Object (Id) or else Is_Single_Task_Object (Id);
17674 end Is_Single_Concurrent_Object;
17676 -------------------------------
17677 -- Is_Single_Concurrent_Type --
17678 -------------------------------
17680 function Is_Single_Concurrent_Type (Id : Entity_Id) return Boolean is
17683 Ekind_In (Id, E_Protected_Type, E_Task_Type)
17684 and then Is_Single_Concurrent_Type_Declaration
17685 (Declaration_Node (Id));
17686 end Is_Single_Concurrent_Type;
17688 -------------------------------------------
17689 -- Is_Single_Concurrent_Type_Declaration --
17690 -------------------------------------------
17692 function Is_Single_Concurrent_Type_Declaration
17693 (N : Node_Id) return Boolean
17696 return Nkind_In (Original_Node (N), N_Single_Protected_Declaration,
17697 N_Single_Task_Declaration);
17698 end Is_Single_Concurrent_Type_Declaration;
17700 ---------------------------------------------
17701 -- Is_Single_Precision_Floating_Point_Type --
17702 ---------------------------------------------
17704 function Is_Single_Precision_Floating_Point_Type
17705 (E : Entity_Id) return Boolean is
17707 return Is_Floating_Point_Type (E)
17708 and then Machine_Radix_Value (E) = Uint_2
17709 and then Machine_Mantissa_Value (E) = Uint_24
17710 and then Machine_Emax_Value (E) = Uint_2 ** Uint_7
17711 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_7);
17712 end Is_Single_Precision_Floating_Point_Type;
17714 --------------------------------
17715 -- Is_Single_Protected_Object --
17716 --------------------------------
17718 function Is_Single_Protected_Object (Id : Entity_Id) return Boolean is
17721 Ekind (Id) = E_Variable
17722 and then Ekind (Etype (Id)) = E_Protected_Type
17723 and then Is_Single_Concurrent_Type (Etype (Id));
17724 end Is_Single_Protected_Object;
17726 ---------------------------
17727 -- Is_Single_Task_Object --
17728 ---------------------------
17730 function Is_Single_Task_Object (Id : Entity_Id) return Boolean is
17733 Ekind (Id) = E_Variable
17734 and then Ekind (Etype (Id)) = E_Task_Type
17735 and then Is_Single_Concurrent_Type (Etype (Id));
17736 end Is_Single_Task_Object;
17738 -------------------------------------
17739 -- Is_SPARK_05_Initialization_Expr --
17740 -------------------------------------
17742 function Is_SPARK_05_Initialization_Expr (N : Node_Id) return Boolean is
17745 Comp_Assn : Node_Id;
17746 Orig_N : constant Node_Id := Original_Node (N);
17751 if not Comes_From_Source (Orig_N) then
17755 pragma Assert (Nkind (Orig_N) in N_Subexpr);
17757 case Nkind (Orig_N) is
17758 when N_Character_Literal
17759 | N_Integer_Literal
17765 when N_Expanded_Name
17768 if Is_Entity_Name (Orig_N)
17769 and then Present (Entity (Orig_N)) -- needed in some cases
17771 case Ekind (Entity (Orig_N)) is
17773 | E_Enumeration_Literal
17780 if Is_Type (Entity (Orig_N)) then
17788 when N_Qualified_Expression
17789 | N_Type_Conversion
17791 Is_Ok := Is_SPARK_05_Initialization_Expr (Expression (Orig_N));
17794 Is_Ok := Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
17797 | N_Membership_Test
17800 Is_Ok := Is_SPARK_05_Initialization_Expr (Left_Opnd (Orig_N))
17802 Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
17805 | N_Extension_Aggregate
17807 if Nkind (Orig_N) = N_Extension_Aggregate then
17809 Is_SPARK_05_Initialization_Expr (Ancestor_Part (Orig_N));
17812 Expr := First (Expressions (Orig_N));
17813 while Present (Expr) loop
17814 if not Is_SPARK_05_Initialization_Expr (Expr) then
17822 Comp_Assn := First (Component_Associations (Orig_N));
17823 while Present (Comp_Assn) loop
17824 Expr := Expression (Comp_Assn);
17826 -- Note: test for Present here needed for box assocation
17829 and then not Is_SPARK_05_Initialization_Expr (Expr)
17838 when N_Attribute_Reference =>
17839 if Nkind (Prefix (Orig_N)) in N_Subexpr then
17840 Is_Ok := Is_SPARK_05_Initialization_Expr (Prefix (Orig_N));
17843 Expr := First (Expressions (Orig_N));
17844 while Present (Expr) loop
17845 if not Is_SPARK_05_Initialization_Expr (Expr) then
17853 -- Selected components might be expanded named not yet resolved, so
17854 -- default on the safe side. (Eg on sparklex.ads)
17856 when N_Selected_Component =>
17865 end Is_SPARK_05_Initialization_Expr;
17867 ----------------------------------
17868 -- Is_SPARK_05_Object_Reference --
17869 ----------------------------------
17871 function Is_SPARK_05_Object_Reference (N : Node_Id) return Boolean is
17873 if Is_Entity_Name (N) then
17874 return Present (Entity (N))
17876 (Ekind_In (Entity (N), E_Constant, E_Variable)
17877 or else Ekind (Entity (N)) in Formal_Kind);
17881 when N_Selected_Component =>
17882 return Is_SPARK_05_Object_Reference (Prefix (N));
17888 end Is_SPARK_05_Object_Reference;
17890 -----------------------------
17891 -- Is_Specific_Tagged_Type --
17892 -----------------------------
17894 function Is_Specific_Tagged_Type (Typ : Entity_Id) return Boolean is
17895 Full_Typ : Entity_Id;
17898 -- Handle private types
17900 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
17901 Full_Typ := Full_View (Typ);
17906 -- A specific tagged type is a non-class-wide tagged type
17908 return Is_Tagged_Type (Full_Typ) and not Is_Class_Wide_Type (Full_Typ);
17909 end Is_Specific_Tagged_Type;
17915 function Is_Statement (N : Node_Id) return Boolean is
17918 Nkind (N) in N_Statement_Other_Than_Procedure_Call
17919 or else Nkind (N) = N_Procedure_Call_Statement;
17922 ----------------------------------------
17923 -- Is_Subcomponent_Of_Atomic_Object --
17924 ----------------------------------------
17926 function Is_Subcomponent_Of_Atomic_Object (N : Node_Id) return Boolean is
17930 R := Get_Referenced_Object (N);
17932 while Nkind_In (R, N_Indexed_Component, N_Selected_Component, N_Slice)
17934 R := Get_Referenced_Object (Prefix (R));
17936 -- If the prefix is an access value, only the designated type matters
17938 if Is_Access_Type (Etype (R)) then
17939 if Is_Atomic (Designated_Type (Etype (R))) then
17944 if Is_Atomic_Object (R) then
17951 end Is_Subcomponent_Of_Atomic_Object;
17953 ---------------------------------------
17954 -- Is_Subprogram_Contract_Annotation --
17955 ---------------------------------------
17957 function Is_Subprogram_Contract_Annotation
17958 (Item : Node_Id) return Boolean
17963 if Nkind (Item) = N_Aspect_Specification then
17964 Nam := Chars (Identifier (Item));
17966 else pragma Assert (Nkind (Item) = N_Pragma);
17967 Nam := Pragma_Name (Item);
17970 return Nam = Name_Contract_Cases
17971 or else Nam = Name_Depends
17972 or else Nam = Name_Extensions_Visible
17973 or else Nam = Name_Global
17974 or else Nam = Name_Post
17975 or else Nam = Name_Post_Class
17976 or else Nam = Name_Postcondition
17977 or else Nam = Name_Pre
17978 or else Nam = Name_Pre_Class
17979 or else Nam = Name_Precondition
17980 or else Nam = Name_Refined_Depends
17981 or else Nam = Name_Refined_Global
17982 or else Nam = Name_Refined_Post
17983 or else Nam = Name_Test_Case;
17984 end Is_Subprogram_Contract_Annotation;
17986 --------------------------------------------------
17987 -- Is_Subprogram_Stub_Without_Prior_Declaration --
17988 --------------------------------------------------
17990 function Is_Subprogram_Stub_Without_Prior_Declaration
17991 (N : Node_Id) return Boolean
17994 pragma Assert (Nkind (N) = N_Subprogram_Body_Stub);
17996 case Ekind (Defining_Entity (N)) is
17998 -- A subprogram stub without prior declaration serves as declaration
17999 -- for the actual subprogram body. As such, it has an attached
18000 -- defining entity of E_Function or E_Procedure.
18007 -- Otherwise, it is completes a [generic] subprogram declaration
18009 when E_Generic_Function
18010 | E_Generic_Procedure
18011 | E_Subprogram_Body
18016 raise Program_Error;
18018 end Is_Subprogram_Stub_Without_Prior_Declaration;
18020 ---------------------------
18021 -- Is_Suitable_Primitive --
18022 ---------------------------
18024 function Is_Suitable_Primitive (Subp_Id : Entity_Id) return Boolean is
18026 -- The Default_Initial_Condition and invariant procedures must not be
18027 -- treated as primitive operations even when they apply to a tagged
18028 -- type. These routines must not act as targets of dispatching calls
18029 -- because they already utilize class-wide-precondition semantics to
18030 -- handle inheritance and overriding.
18032 if Ekind (Subp_Id) = E_Procedure
18033 and then (Is_DIC_Procedure (Subp_Id)
18035 Is_Invariant_Procedure (Subp_Id))
18041 end Is_Suitable_Primitive;
18043 --------------------------
18044 -- Is_Suspension_Object --
18045 --------------------------
18047 function Is_Suspension_Object (Id : Entity_Id) return Boolean is
18049 -- This approach does an exact name match rather than to rely on
18050 -- RTSfind. Routine Is_Effectively_Volatile is used by clients of the
18051 -- front end at point where all auxiliary tables are locked and any
18052 -- modifications to them are treated as violations. Do not tamper with
18053 -- the tables, instead examine the Chars fields of all the scopes of Id.
18056 Chars (Id) = Name_Suspension_Object
18057 and then Present (Scope (Id))
18058 and then Chars (Scope (Id)) = Name_Synchronous_Task_Control
18059 and then Present (Scope (Scope (Id)))
18060 and then Chars (Scope (Scope (Id))) = Name_Ada
18061 and then Present (Scope (Scope (Scope (Id))))
18062 and then Scope (Scope (Scope (Id))) = Standard_Standard;
18063 end Is_Suspension_Object;
18065 ----------------------------
18066 -- Is_Synchronized_Object --
18067 ----------------------------
18069 function Is_Synchronized_Object (Id : Entity_Id) return Boolean is
18073 if Is_Object (Id) then
18075 -- The object is synchronized if it is of a type that yields a
18076 -- synchronized object.
18078 if Yields_Synchronized_Object (Etype (Id)) then
18081 -- The object is synchronized if it is atomic and Async_Writers is
18084 elsif Is_Atomic_Object_Entity (Id)
18085 and then Async_Writers_Enabled (Id)
18089 -- A constant is a synchronized object by default
18091 elsif Ekind (Id) = E_Constant then
18094 -- A variable is a synchronized object if it is subject to pragma
18095 -- Constant_After_Elaboration.
18097 elsif Ekind (Id) = E_Variable then
18098 Prag := Get_Pragma (Id, Pragma_Constant_After_Elaboration);
18100 return Present (Prag) and then Is_Enabled_Pragma (Prag);
18104 -- Otherwise the input is not an object or it does not qualify as a
18105 -- synchronized object.
18108 end Is_Synchronized_Object;
18110 ---------------------------------
18111 -- Is_Synchronized_Tagged_Type --
18112 ---------------------------------
18114 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
18115 Kind : constant Entity_Kind := Ekind (Base_Type (E));
18118 -- A task or protected type derived from an interface is a tagged type.
18119 -- Such a tagged type is called a synchronized tagged type, as are
18120 -- synchronized interfaces and private extensions whose declaration
18121 -- includes the reserved word synchronized.
18123 return (Is_Tagged_Type (E)
18124 and then (Kind = E_Task_Type
18126 Kind = E_Protected_Type))
18129 and then Is_Synchronized_Interface (E))
18131 (Ekind (E) = E_Record_Type_With_Private
18132 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
18133 and then (Synchronized_Present (Parent (E))
18134 or else Is_Synchronized_Interface (Etype (E))));
18135 end Is_Synchronized_Tagged_Type;
18141 function Is_Transfer (N : Node_Id) return Boolean is
18142 Kind : constant Node_Kind := Nkind (N);
18145 if Kind = N_Simple_Return_Statement
18147 Kind = N_Extended_Return_Statement
18149 Kind = N_Goto_Statement
18151 Kind = N_Raise_Statement
18153 Kind = N_Requeue_Statement
18157 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
18158 and then No (Condition (N))
18162 elsif Kind = N_Procedure_Call_Statement
18163 and then Is_Entity_Name (Name (N))
18164 and then Present (Entity (Name (N)))
18165 and then No_Return (Entity (Name (N)))
18169 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
18181 function Is_True (U : Uint) return Boolean is
18186 --------------------------------------
18187 -- Is_Unchecked_Conversion_Instance --
18188 --------------------------------------
18190 function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is
18194 -- Look for a function whose generic parent is the predefined intrinsic
18195 -- function Unchecked_Conversion, or for one that renames such an
18198 if Ekind (Id) = E_Function then
18199 Par := Parent (Id);
18201 if Nkind (Par) = N_Function_Specification then
18202 Par := Generic_Parent (Par);
18204 if Present (Par) then
18206 Chars (Par) = Name_Unchecked_Conversion
18207 and then Is_Intrinsic_Subprogram (Par)
18208 and then In_Predefined_Unit (Par);
18211 Present (Alias (Id))
18212 and then Is_Unchecked_Conversion_Instance (Alias (Id));
18218 end Is_Unchecked_Conversion_Instance;
18220 -------------------------------
18221 -- Is_Universal_Numeric_Type --
18222 -------------------------------
18224 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
18226 return T = Universal_Integer or else T = Universal_Real;
18227 end Is_Universal_Numeric_Type;
18229 ------------------------------
18230 -- Is_User_Defined_Equality --
18231 ------------------------------
18233 function Is_User_Defined_Equality (Id : Entity_Id) return Boolean is
18235 return Ekind (Id) = E_Function
18236 and then Chars (Id) = Name_Op_Eq
18237 and then Comes_From_Source (Id)
18239 -- Internally generated equalities have a full type declaration
18240 -- as their parent.
18242 and then Nkind (Parent (Id)) = N_Function_Specification;
18243 end Is_User_Defined_Equality;
18245 --------------------------------------
18246 -- Is_Validation_Variable_Reference --
18247 --------------------------------------
18249 function Is_Validation_Variable_Reference (N : Node_Id) return Boolean is
18250 Var : constant Node_Id := Unqual_Conv (N);
18251 Var_Id : Entity_Id;
18256 if Is_Entity_Name (Var) then
18257 Var_Id := Entity (Var);
18262 and then Ekind (Var_Id) = E_Variable
18263 and then Present (Validated_Object (Var_Id));
18264 end Is_Validation_Variable_Reference;
18266 ----------------------------
18267 -- Is_Variable_Size_Array --
18268 ----------------------------
18270 function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
18274 pragma Assert (Is_Array_Type (E));
18276 -- Check if some index is initialized with a non-constant value
18278 Idx := First_Index (E);
18279 while Present (Idx) loop
18280 if Nkind (Idx) = N_Range then
18281 if not Is_Constant_Bound (Low_Bound (Idx))
18282 or else not Is_Constant_Bound (High_Bound (Idx))
18288 Idx := Next_Index (Idx);
18292 end Is_Variable_Size_Array;
18294 -----------------------------
18295 -- Is_Variable_Size_Record --
18296 -----------------------------
18298 function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
18300 Comp_Typ : Entity_Id;
18303 pragma Assert (Is_Record_Type (E));
18305 Comp := First_Component (E);
18306 while Present (Comp) loop
18307 Comp_Typ := Underlying_Type (Etype (Comp));
18309 -- Recursive call if the record type has discriminants
18311 if Is_Record_Type (Comp_Typ)
18312 and then Has_Discriminants (Comp_Typ)
18313 and then Is_Variable_Size_Record (Comp_Typ)
18317 elsif Is_Array_Type (Comp_Typ)
18318 and then Is_Variable_Size_Array (Comp_Typ)
18323 Next_Component (Comp);
18327 end Is_Variable_Size_Record;
18333 function Is_Variable
18335 Use_Original_Node : Boolean := True) return Boolean
18337 Orig_Node : Node_Id;
18339 function In_Protected_Function (E : Entity_Id) return Boolean;
18340 -- Within a protected function, the private components of the enclosing
18341 -- protected type are constants. A function nested within a (protected)
18342 -- procedure is not itself protected. Within the body of a protected
18343 -- function the current instance of the protected type is a constant.
18345 function Is_Variable_Prefix (P : Node_Id) return Boolean;
18346 -- Prefixes can involve implicit dereferences, in which case we must
18347 -- test for the case of a reference of a constant access type, which can
18348 -- can never be a variable.
18350 ---------------------------
18351 -- In_Protected_Function --
18352 ---------------------------
18354 function In_Protected_Function (E : Entity_Id) return Boolean is
18359 -- E is the current instance of a type
18361 if Is_Type (E) then
18370 if not Is_Protected_Type (Prot) then
18374 S := Current_Scope;
18375 while Present (S) and then S /= Prot loop
18376 if Ekind (S) = E_Function and then Scope (S) = Prot then
18385 end In_Protected_Function;
18387 ------------------------
18388 -- Is_Variable_Prefix --
18389 ------------------------
18391 function Is_Variable_Prefix (P : Node_Id) return Boolean is
18393 if Is_Access_Type (Etype (P)) then
18394 return not Is_Access_Constant (Root_Type (Etype (P)));
18396 -- For the case of an indexed component whose prefix has a packed
18397 -- array type, the prefix has been rewritten into a type conversion.
18398 -- Determine variable-ness from the converted expression.
18400 elsif Nkind (P) = N_Type_Conversion
18401 and then not Comes_From_Source (P)
18402 and then Is_Array_Type (Etype (P))
18403 and then Is_Packed (Etype (P))
18405 return Is_Variable (Expression (P));
18408 return Is_Variable (P);
18410 end Is_Variable_Prefix;
18412 -- Start of processing for Is_Variable
18415 -- Special check, allow x'Deref(expr) as a variable
18417 if Nkind (N) = N_Attribute_Reference
18418 and then Attribute_Name (N) = Name_Deref
18423 -- Check if we perform the test on the original node since this may be a
18424 -- test of syntactic categories which must not be disturbed by whatever
18425 -- rewriting might have occurred. For example, an aggregate, which is
18426 -- certainly NOT a variable, could be turned into a variable by
18429 if Use_Original_Node then
18430 Orig_Node := Original_Node (N);
18435 -- Definitely OK if Assignment_OK is set. Since this is something that
18436 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
18438 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
18441 -- Normally we go to the original node, but there is one exception where
18442 -- we use the rewritten node, namely when it is an explicit dereference.
18443 -- The generated code may rewrite a prefix which is an access type with
18444 -- an explicit dereference. The dereference is a variable, even though
18445 -- the original node may not be (since it could be a constant of the
18448 -- In Ada 2005 we have a further case to consider: the prefix may be a
18449 -- function call given in prefix notation. The original node appears to
18450 -- be a selected component, but we need to examine the call.
18452 elsif Nkind (N) = N_Explicit_Dereference
18453 and then Nkind (Orig_Node) /= N_Explicit_Dereference
18454 and then Present (Etype (Orig_Node))
18455 and then Is_Access_Type (Etype (Orig_Node))
18457 -- Note that if the prefix is an explicit dereference that does not
18458 -- come from source, we must check for a rewritten function call in
18459 -- prefixed notation before other forms of rewriting, to prevent a
18463 (Nkind (Orig_Node) = N_Function_Call
18464 and then not Is_Access_Constant (Etype (Prefix (N))))
18466 Is_Variable_Prefix (Original_Node (Prefix (N)));
18468 -- in Ada 2012, the dereference may have been added for a type with
18469 -- a declared implicit dereference aspect. Check that it is not an
18470 -- access to constant.
18472 elsif Nkind (N) = N_Explicit_Dereference
18473 and then Present (Etype (Orig_Node))
18474 and then Ada_Version >= Ada_2012
18475 and then Has_Implicit_Dereference (Etype (Orig_Node))
18477 return not Is_Access_Constant (Etype (Prefix (N)));
18479 -- A function call is never a variable
18481 elsif Nkind (N) = N_Function_Call then
18484 -- All remaining checks use the original node
18486 elsif Is_Entity_Name (Orig_Node)
18487 and then Present (Entity (Orig_Node))
18490 E : constant Entity_Id := Entity (Orig_Node);
18491 K : constant Entity_Kind := Ekind (E);
18494 if Is_Loop_Parameter (E) then
18498 return (K = E_Variable
18499 and then Nkind (Parent (E)) /= N_Exception_Handler)
18500 or else (K = E_Component
18501 and then not In_Protected_Function (E))
18502 or else K = E_Out_Parameter
18503 or else K = E_In_Out_Parameter
18504 or else K = E_Generic_In_Out_Parameter
18506 -- Current instance of type. If this is a protected type, check
18507 -- we are not within the body of one of its protected functions.
18509 or else (Is_Type (E)
18510 and then In_Open_Scopes (E)
18511 and then not In_Protected_Function (E))
18513 or else (Is_Incomplete_Or_Private_Type (E)
18514 and then In_Open_Scopes (Full_View (E)));
18518 case Nkind (Orig_Node) is
18519 when N_Indexed_Component
18522 return Is_Variable_Prefix (Prefix (Orig_Node));
18524 when N_Selected_Component =>
18525 return (Is_Variable (Selector_Name (Orig_Node))
18526 and then Is_Variable_Prefix (Prefix (Orig_Node)))
18528 (Nkind (N) = N_Expanded_Name
18529 and then Scope (Entity (N)) = Entity (Prefix (N)));
18531 -- For an explicit dereference, the type of the prefix cannot
18532 -- be an access to constant or an access to subprogram.
18534 when N_Explicit_Dereference =>
18536 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
18538 return Is_Access_Type (Typ)
18539 and then not Is_Access_Constant (Root_Type (Typ))
18540 and then Ekind (Typ) /= E_Access_Subprogram_Type;
18543 -- The type conversion is the case where we do not deal with the
18544 -- context dependent special case of an actual parameter. Thus
18545 -- the type conversion is only considered a variable for the
18546 -- purposes of this routine if the target type is tagged. However,
18547 -- a type conversion is considered to be a variable if it does not
18548 -- come from source (this deals for example with the conversions
18549 -- of expressions to their actual subtypes).
18551 when N_Type_Conversion =>
18552 return Is_Variable (Expression (Orig_Node))
18554 (not Comes_From_Source (Orig_Node)
18556 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
18558 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
18560 -- GNAT allows an unchecked type conversion as a variable. This
18561 -- only affects the generation of internal expanded code, since
18562 -- calls to instantiations of Unchecked_Conversion are never
18563 -- considered variables (since they are function calls).
18565 when N_Unchecked_Type_Conversion =>
18566 return Is_Variable (Expression (Orig_Node));
18574 ---------------------------
18575 -- Is_Visibly_Controlled --
18576 ---------------------------
18578 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
18579 Root : constant Entity_Id := Root_Type (T);
18581 return Chars (Scope (Root)) = Name_Finalization
18582 and then Chars (Scope (Scope (Root))) = Name_Ada
18583 and then Scope (Scope (Scope (Root))) = Standard_Standard;
18584 end Is_Visibly_Controlled;
18586 --------------------------------------
18587 -- Is_Volatile_Full_Access_Object --
18588 --------------------------------------
18590 function Is_Volatile_Full_Access_Object (N : Node_Id) return Boolean is
18591 function Is_VFA_Object_Entity (Id : Entity_Id) return Boolean;
18592 -- Determine whether arbitrary entity Id denotes an object that is
18593 -- Volatile_Full_Access.
18595 ----------------------------
18596 -- Is_VFA_Object_Entity --
18597 ----------------------------
18599 function Is_VFA_Object_Entity (Id : Entity_Id) return Boolean is
18603 and then (Is_Volatile_Full_Access (Id)
18605 Is_Volatile_Full_Access (Etype (Id)));
18606 end Is_VFA_Object_Entity;
18608 -- Start of processing for Is_Volatile_Full_Access_Object
18611 if Is_Entity_Name (N) then
18612 return Is_VFA_Object_Entity (Entity (N));
18614 elsif Is_Volatile_Full_Access (Etype (N)) then
18617 elsif Nkind (N) = N_Selected_Component then
18618 return Is_Volatile_Full_Access (Entity (Selector_Name (N)));
18623 end Is_Volatile_Full_Access_Object;
18625 --------------------------
18626 -- Is_Volatile_Function --
18627 --------------------------
18629 function Is_Volatile_Function (Func_Id : Entity_Id) return Boolean is
18631 pragma Assert (Ekind_In (Func_Id, E_Function, E_Generic_Function));
18633 -- A function declared within a protected type is volatile
18635 if Is_Protected_Type (Scope (Func_Id)) then
18638 -- An instance of Ada.Unchecked_Conversion is a volatile function if
18639 -- either the source or the target are effectively volatile.
18641 elsif Is_Unchecked_Conversion_Instance (Func_Id)
18642 and then Has_Effectively_Volatile_Profile (Func_Id)
18646 -- Otherwise the function is treated as volatile if it is subject to
18647 -- enabled pragma Volatile_Function.
18651 Is_Enabled_Pragma (Get_Pragma (Func_Id, Pragma_Volatile_Function));
18653 end Is_Volatile_Function;
18655 ------------------------
18656 -- Is_Volatile_Object --
18657 ------------------------
18659 function Is_Volatile_Object (N : Node_Id) return Boolean is
18660 function Is_Volatile_Object_Entity (Id : Entity_Id) return Boolean;
18661 -- Determine whether arbitrary entity Id denotes an object that is
18664 function Prefix_Has_Volatile_Components (P : Node_Id) return Boolean;
18665 -- Determine whether prefix P has volatile components. This requires
18666 -- the presence of a Volatile_Components aspect/pragma or that P be
18667 -- itself a volatile object as per RM C.6(8).
18669 ---------------------------------
18670 -- Is_Volatile_Object_Entity --
18671 ---------------------------------
18673 function Is_Volatile_Object_Entity (Id : Entity_Id) return Boolean is
18677 and then (Is_Volatile (Id) or else Is_Volatile (Etype (Id)));
18678 end Is_Volatile_Object_Entity;
18680 ------------------------------------
18681 -- Prefix_Has_Volatile_Components --
18682 ------------------------------------
18684 function Prefix_Has_Volatile_Components (P : Node_Id) return Boolean is
18685 Typ : constant Entity_Id := Etype (P);
18688 if Is_Access_Type (Typ) then
18690 Dtyp : constant Entity_Id := Designated_Type (Typ);
18693 return Has_Volatile_Components (Dtyp)
18694 or else Is_Volatile (Dtyp);
18697 elsif Has_Volatile_Components (Typ) then
18700 elsif Is_Entity_Name (P)
18701 and then Has_Volatile_Component (Entity (P))
18705 elsif Is_Volatile_Object (P) then
18711 end Prefix_Has_Volatile_Components;
18713 -- Start of processing for Is_Volatile_Object
18716 if Is_Entity_Name (N) then
18717 return Is_Volatile_Object_Entity (Entity (N));
18719 elsif Is_Volatile (Etype (N)) then
18722 elsif Nkind (N) = N_Indexed_Component then
18723 return Prefix_Has_Volatile_Components (Prefix (N));
18725 elsif Nkind (N) = N_Selected_Component then
18726 return Prefix_Has_Volatile_Components (Prefix (N))
18727 or else Is_Volatile (Entity (Selector_Name (N)));
18732 end Is_Volatile_Object;
18734 -----------------------------
18735 -- Iterate_Call_Parameters --
18736 -----------------------------
18738 procedure Iterate_Call_Parameters (Call : Node_Id) is
18739 Actual : Node_Id := First_Actual (Call);
18740 Formal : Entity_Id := First_Formal (Get_Called_Entity (Call));
18743 while Present (Formal) and then Present (Actual) loop
18744 Handle_Parameter (Formal, Actual);
18746 Next_Formal (Formal);
18747 Next_Actual (Actual);
18750 pragma Assert (No (Formal));
18751 pragma Assert (No (Actual));
18752 end Iterate_Call_Parameters;
18754 ---------------------------
18755 -- Itype_Has_Declaration --
18756 ---------------------------
18758 function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
18760 pragma Assert (Is_Itype (Id));
18761 return Present (Parent (Id))
18762 and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
18763 N_Subtype_Declaration)
18764 and then Defining_Entity (Parent (Id)) = Id;
18765 end Itype_Has_Declaration;
18767 -------------------------
18768 -- Kill_Current_Values --
18769 -------------------------
18771 procedure Kill_Current_Values
18773 Last_Assignment_Only : Boolean := False)
18776 if Is_Assignable (Ent) then
18777 Set_Last_Assignment (Ent, Empty);
18780 if Is_Object (Ent) then
18781 if not Last_Assignment_Only then
18783 Set_Current_Value (Ent, Empty);
18785 -- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
18786 -- for a constant. Once the constant is elaborated, its value is
18787 -- not changed, therefore the associated flags that describe the
18788 -- value should not be modified either.
18790 if Ekind (Ent) = E_Constant then
18793 -- Non-constant entities
18796 if not Can_Never_Be_Null (Ent) then
18797 Set_Is_Known_Non_Null (Ent, False);
18800 Set_Is_Known_Null (Ent, False);
18802 -- Reset the Is_Known_Valid flag unless the type is always
18803 -- valid. This does not apply to a loop parameter because its
18804 -- bounds are defined by the loop header and therefore always
18807 if not Is_Known_Valid (Etype (Ent))
18808 and then Ekind (Ent) /= E_Loop_Parameter
18810 Set_Is_Known_Valid (Ent, False);
18815 end Kill_Current_Values;
18817 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
18820 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
18821 -- Clear current value for entity E and all entities chained to E
18823 ------------------------------------------
18824 -- Kill_Current_Values_For_Entity_Chain --
18825 ------------------------------------------
18827 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
18831 while Present (Ent) loop
18832 Kill_Current_Values (Ent, Last_Assignment_Only);
18835 end Kill_Current_Values_For_Entity_Chain;
18837 -- Start of processing for Kill_Current_Values
18840 -- Kill all saved checks, a special case of killing saved values
18842 if not Last_Assignment_Only then
18846 -- Loop through relevant scopes, which includes the current scope and
18847 -- any parent scopes if the current scope is a block or a package.
18849 S := Current_Scope;
18852 -- Clear current values of all entities in current scope
18854 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
18856 -- If scope is a package, also clear current values of all private
18857 -- entities in the scope.
18859 if Is_Package_Or_Generic_Package (S)
18860 or else Is_Concurrent_Type (S)
18862 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
18865 -- If this is a not a subprogram, deal with parents
18867 if not Is_Subprogram (S) then
18869 exit Scope_Loop when S = Standard_Standard;
18873 end loop Scope_Loop;
18874 end Kill_Current_Values;
18876 --------------------------
18877 -- Kill_Size_Check_Code --
18878 --------------------------
18880 procedure Kill_Size_Check_Code (E : Entity_Id) is
18882 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
18883 and then Present (Size_Check_Code (E))
18885 Remove (Size_Check_Code (E));
18886 Set_Size_Check_Code (E, Empty);
18888 end Kill_Size_Check_Code;
18890 --------------------
18891 -- Known_Non_Null --
18892 --------------------
18894 function Known_Non_Null (N : Node_Id) return Boolean is
18895 Status : constant Null_Status_Kind := Null_Status (N);
18902 -- The expression yields a non-null value ignoring simple flow analysis
18904 if Status = Is_Non_Null then
18907 -- Otherwise check whether N is a reference to an entity that appears
18908 -- within a conditional construct.
18910 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
18912 -- First check if we are in decisive conditional
18914 Get_Current_Value_Condition (N, Op, Val);
18916 if Known_Null (Val) then
18917 if Op = N_Op_Eq then
18919 elsif Op = N_Op_Ne then
18924 -- If OK to do replacement, test Is_Known_Non_Null flag
18928 if OK_To_Do_Constant_Replacement (Id) then
18929 return Is_Known_Non_Null (Id);
18933 -- Otherwise it is not possible to determine whether N yields a non-null
18937 end Known_Non_Null;
18943 function Known_Null (N : Node_Id) return Boolean is
18944 Status : constant Null_Status_Kind := Null_Status (N);
18951 -- The expression yields a null value ignoring simple flow analysis
18953 if Status = Is_Null then
18956 -- Otherwise check whether N is a reference to an entity that appears
18957 -- within a conditional construct.
18959 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
18961 -- First check if we are in decisive conditional
18963 Get_Current_Value_Condition (N, Op, Val);
18965 if Known_Null (Val) then
18966 if Op = N_Op_Eq then
18968 elsif Op = N_Op_Ne then
18973 -- If OK to do replacement, test Is_Known_Null flag
18977 if OK_To_Do_Constant_Replacement (Id) then
18978 return Is_Known_Null (Id);
18982 -- Otherwise it is not possible to determine whether N yields a null
18988 --------------------------
18989 -- Known_To_Be_Assigned --
18990 --------------------------
18992 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
18993 P : constant Node_Id := Parent (N);
18998 -- Test left side of assignment
19000 when N_Assignment_Statement =>
19001 return N = Name (P);
19003 -- Function call arguments are never lvalues
19005 when N_Function_Call =>
19008 -- Positional parameter for procedure or accept call
19010 when N_Accept_Statement
19011 | N_Procedure_Call_Statement
19019 Proc := Get_Subprogram_Entity (P);
19025 -- If we are not a list member, something is strange, so
19026 -- be conservative and return False.
19028 if not Is_List_Member (N) then
19032 -- We are going to find the right formal by stepping forward
19033 -- through the formals, as we step backwards in the actuals.
19035 Form := First_Formal (Proc);
19038 -- If no formal, something is weird, so be conservative
19039 -- and return False.
19046 exit when No (Act);
19047 Next_Formal (Form);
19050 return Ekind (Form) /= E_In_Parameter;
19053 -- Named parameter for procedure or accept call
19055 when N_Parameter_Association =>
19061 Proc := Get_Subprogram_Entity (Parent (P));
19067 -- Loop through formals to find the one that matches
19069 Form := First_Formal (Proc);
19071 -- If no matching formal, that's peculiar, some kind of
19072 -- previous error, so return False to be conservative.
19073 -- Actually this also happens in legal code in the case
19074 -- where P is a parameter association for an Extra_Formal???
19080 -- Else test for match
19082 if Chars (Form) = Chars (Selector_Name (P)) then
19083 return Ekind (Form) /= E_In_Parameter;
19086 Next_Formal (Form);
19090 -- Test for appearing in a conversion that itself appears
19091 -- in an lvalue context, since this should be an lvalue.
19093 when N_Type_Conversion =>
19094 return Known_To_Be_Assigned (P);
19096 -- All other references are definitely not known to be modifications
19101 end Known_To_Be_Assigned;
19103 ---------------------------
19104 -- Last_Source_Statement --
19105 ---------------------------
19107 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
19111 N := Last (Statements (HSS));
19112 while Present (N) loop
19113 exit when Comes_From_Source (N);
19118 end Last_Source_Statement;
19120 -----------------------
19121 -- Mark_Coextensions --
19122 -----------------------
19124 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
19125 Is_Dynamic : Boolean;
19126 -- Indicates whether the context causes nested coextensions to be
19127 -- dynamic or static
19129 function Mark_Allocator (N : Node_Id) return Traverse_Result;
19130 -- Recognize an allocator node and label it as a dynamic coextension
19132 --------------------
19133 -- Mark_Allocator --
19134 --------------------
19136 function Mark_Allocator (N : Node_Id) return Traverse_Result is
19138 if Nkind (N) = N_Allocator then
19140 Set_Is_Static_Coextension (N, False);
19141 Set_Is_Dynamic_Coextension (N);
19143 -- If the allocator expression is potentially dynamic, it may
19144 -- be expanded out of order and require dynamic allocation
19145 -- anyway, so we treat the coextension itself as dynamic.
19146 -- Potential optimization ???
19148 elsif Nkind (Expression (N)) = N_Qualified_Expression
19149 and then Nkind (Expression (Expression (N))) = N_Op_Concat
19151 Set_Is_Static_Coextension (N, False);
19152 Set_Is_Dynamic_Coextension (N);
19154 Set_Is_Dynamic_Coextension (N, False);
19155 Set_Is_Static_Coextension (N);
19160 end Mark_Allocator;
19162 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
19164 -- Start of processing for Mark_Coextensions
19167 -- An allocator that appears on the right-hand side of an assignment is
19168 -- treated as a potentially dynamic coextension when the right-hand side
19169 -- is an allocator or a qualified expression.
19171 -- Obj := new ...'(new Coextension ...);
19173 if Nkind (Context_Nod) = N_Assignment_Statement then
19175 Nkind_In (Expression (Context_Nod), N_Allocator,
19176 N_Qualified_Expression);
19178 -- An allocator that appears within the expression of a simple return
19179 -- statement is treated as a potentially dynamic coextension when the
19180 -- expression is either aggregate, allocator, or qualified expression.
19182 -- return (new Coextension ...);
19183 -- return new ...'(new Coextension ...);
19185 elsif Nkind (Context_Nod) = N_Simple_Return_Statement then
19187 Nkind_In (Expression (Context_Nod), N_Aggregate,
19189 N_Qualified_Expression);
19191 -- An alloctor that appears within the initialization expression of an
19192 -- object declaration is considered a potentially dynamic coextension
19193 -- when the initialization expression is an allocator or a qualified
19196 -- Obj : ... := new ...'(new Coextension ...);
19198 -- A similar case arises when the object declaration is part of an
19199 -- extended return statement.
19201 -- return Obj : ... := new ...'(new Coextension ...);
19202 -- return Obj : ... := (new Coextension ...);
19204 elsif Nkind (Context_Nod) = N_Object_Declaration then
19206 Nkind_In (Root_Nod, N_Allocator, N_Qualified_Expression)
19208 Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
19210 -- This routine should not be called with constructs that cannot contain
19214 raise Program_Error;
19217 Mark_Allocators (Root_Nod);
19218 end Mark_Coextensions;
19220 ---------------------------------
19221 -- Mark_Elaboration_Attributes --
19222 ---------------------------------
19224 procedure Mark_Elaboration_Attributes
19225 (N_Id : Node_Or_Entity_Id;
19226 Checks : Boolean := False;
19227 Level : Boolean := False;
19228 Modes : Boolean := False;
19229 Warnings : Boolean := False)
19231 function Elaboration_Checks_OK
19232 (Target_Id : Entity_Id;
19233 Context_Id : Entity_Id) return Boolean;
19234 -- Determine whether elaboration checks are enabled for target Target_Id
19235 -- which resides within context Context_Id.
19237 procedure Mark_Elaboration_Attributes_Id (Id : Entity_Id);
19238 -- Preserve relevant attributes of the context in arbitrary entity Id
19240 procedure Mark_Elaboration_Attributes_Node (N : Node_Id);
19241 -- Preserve relevant attributes of the context in arbitrary node N
19243 ---------------------------
19244 -- Elaboration_Checks_OK --
19245 ---------------------------
19247 function Elaboration_Checks_OK
19248 (Target_Id : Entity_Id;
19249 Context_Id : Entity_Id) return Boolean
19251 Encl_Scop : Entity_Id;
19254 -- Elaboration checks are suppressed for the target
19256 if Elaboration_Checks_Suppressed (Target_Id) then
19260 -- Otherwise elaboration checks are OK for the target, but may be
19261 -- suppressed for the context where the target is declared.
19263 Encl_Scop := Context_Id;
19264 while Present (Encl_Scop) and then Encl_Scop /= Standard_Standard loop
19265 if Elaboration_Checks_Suppressed (Encl_Scop) then
19269 Encl_Scop := Scope (Encl_Scop);
19272 -- Neither the target nor its declarative context have elaboration
19273 -- checks suppressed.
19276 end Elaboration_Checks_OK;
19278 ------------------------------------
19279 -- Mark_Elaboration_Attributes_Id --
19280 ------------------------------------
19282 procedure Mark_Elaboration_Attributes_Id (Id : Entity_Id) is
19284 -- Mark the status of elaboration checks in effect. Do not reset the
19285 -- status in case the entity is reanalyzed with checks suppressed.
19287 if Checks and then not Is_Elaboration_Checks_OK_Id (Id) then
19288 Set_Is_Elaboration_Checks_OK_Id (Id,
19289 Elaboration_Checks_OK
19291 Context_Id => Scope (Id)));
19294 -- Mark the status of elaboration warnings in effect. Do not reset
19295 -- the status in case the entity is reanalyzed with warnings off.
19297 if Warnings and then not Is_Elaboration_Warnings_OK_Id (Id) then
19298 Set_Is_Elaboration_Warnings_OK_Id (Id, Elab_Warnings);
19300 end Mark_Elaboration_Attributes_Id;
19302 --------------------------------------
19303 -- Mark_Elaboration_Attributes_Node --
19304 --------------------------------------
19306 procedure Mark_Elaboration_Attributes_Node (N : Node_Id) is
19307 function Extract_Name (N : Node_Id) return Node_Id;
19308 -- Obtain the Name attribute of call or instantiation N
19314 function Extract_Name (N : Node_Id) return Node_Id is
19320 -- A call to an entry family appears in indexed form
19322 if Nkind (Nam) = N_Indexed_Component then
19323 Nam := Prefix (Nam);
19326 -- The name may also appear in qualified form
19328 if Nkind (Nam) = N_Selected_Component then
19329 Nam := Selector_Name (Nam);
19337 Context_Id : Entity_Id;
19340 -- Start of processing for Mark_Elaboration_Attributes_Node
19343 -- Mark the status of elaboration checks in effect. Do not reset the
19344 -- status in case the node is reanalyzed with checks suppressed.
19346 if Checks and then not Is_Elaboration_Checks_OK_Node (N) then
19348 -- Assignments, attribute references, and variable references do
19349 -- not have a "declarative" context.
19351 Context_Id := Empty;
19353 -- The status of elaboration checks for calls and instantiations
19354 -- depends on the most recent pragma Suppress/Unsuppress, as well
19355 -- as the suppression status of the context where the target is
19359 -- function Func ...;
19363 -- procedure Main is
19364 -- pragma Suppress (Elaboration_Checks, Pack);
19365 -- X : ... := Pack.Func;
19368 -- In the example above, the call to Func has elaboration checks
19369 -- enabled because there is no active general purpose suppression
19370 -- pragma, however the elaboration checks of Pack are explicitly
19371 -- suppressed. As a result the elaboration checks of the call must
19372 -- be disabled in order to preserve this dependency.
19374 if Nkind_In (N, N_Entry_Call_Statement,
19376 N_Function_Instantiation,
19377 N_Package_Instantiation,
19378 N_Procedure_Call_Statement,
19379 N_Procedure_Instantiation)
19381 Nam := Extract_Name (N);
19383 if Is_Entity_Name (Nam) and then Present (Entity (Nam)) then
19384 Context_Id := Scope (Entity (Nam));
19388 Set_Is_Elaboration_Checks_OK_Node (N,
19389 Elaboration_Checks_OK
19390 (Target_Id => Empty,
19391 Context_Id => Context_Id));
19394 -- Mark the enclosing level of the node. Do not reset the status in
19395 -- case the node is relocated and reanalyzed.
19397 if Level and then not Is_Declaration_Level_Node (N) then
19398 Set_Is_Declaration_Level_Node (N,
19399 Find_Enclosing_Level (N) = Declaration_Level);
19402 -- Mark the Ghost and SPARK mode in effect
19405 if Ghost_Mode = Ignore then
19406 Set_Is_Ignored_Ghost_Node (N);
19409 if SPARK_Mode = On then
19410 Set_Is_SPARK_Mode_On_Node (N);
19414 -- Mark the status of elaboration warnings in effect. Do not reset
19415 -- the status in case the node is reanalyzed with warnings off.
19417 if Warnings and then not Is_Elaboration_Warnings_OK_Node (N) then
19418 Set_Is_Elaboration_Warnings_OK_Node (N, Elab_Warnings);
19420 end Mark_Elaboration_Attributes_Node;
19422 -- Start of processing for Mark_Elaboration_Attributes
19425 -- Do not capture any elaboration-related attributes when switch -gnatH
19426 -- (legacy elaboration checking mode enabled) is in effect because the
19427 -- attributes are useless to the legacy model.
19429 if Legacy_Elaboration_Checks then
19433 if Nkind (N_Id) in N_Entity then
19434 Mark_Elaboration_Attributes_Id (N_Id);
19436 Mark_Elaboration_Attributes_Node (N_Id);
19438 end Mark_Elaboration_Attributes;
19440 ----------------------------------------
19441 -- Mark_Save_Invocation_Graph_Of_Body --
19442 ----------------------------------------
19444 procedure Mark_Save_Invocation_Graph_Of_Body is
19445 Main : constant Node_Id := Cunit (Main_Unit);
19446 Main_Unit : constant Node_Id := Unit (Main);
19447 Aux_Id : Entity_Id;
19450 Set_Save_Invocation_Graph_Of_Body (Main);
19452 -- Assume that the main unit does not have a complimentary unit
19456 -- Obtain the complimentary unit of the main unit
19458 if Nkind_In (Main_Unit, N_Generic_Package_Declaration,
19459 N_Generic_Subprogram_Declaration,
19460 N_Package_Declaration,
19461 N_Subprogram_Declaration)
19463 Aux_Id := Corresponding_Body (Main_Unit);
19465 elsif Nkind_In (Main_Unit, N_Package_Body,
19467 N_Subprogram_Renaming_Declaration)
19469 Aux_Id := Corresponding_Spec (Main_Unit);
19472 if Present (Aux_Id) then
19473 Set_Save_Invocation_Graph_Of_Body
19474 (Parent (Unit_Declaration_Node (Aux_Id)));
19476 end Mark_Save_Invocation_Graph_Of_Body;
19478 ----------------------------------
19479 -- Matching_Static_Array_Bounds --
19480 ----------------------------------
19482 function Matching_Static_Array_Bounds
19484 R_Typ : Node_Id) return Boolean
19486 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
19487 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
19489 L_Index : Node_Id := Empty; -- init to ...
19490 R_Index : Node_Id := Empty; -- ...avoid warnings
19499 if L_Ndims /= R_Ndims then
19503 -- Unconstrained types do not have static bounds
19505 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
19509 -- First treat specially the first dimension, as the lower bound and
19510 -- length of string literals are not stored like those of arrays.
19512 if Ekind (L_Typ) = E_String_Literal_Subtype then
19513 L_Low := String_Literal_Low_Bound (L_Typ);
19514 L_Len := String_Literal_Length (L_Typ);
19516 L_Index := First_Index (L_Typ);
19517 Get_Index_Bounds (L_Index, L_Low, L_High);
19519 if Is_OK_Static_Expression (L_Low)
19521 Is_OK_Static_Expression (L_High)
19523 if Expr_Value (L_High) < Expr_Value (L_Low) then
19526 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
19533 if Ekind (R_Typ) = E_String_Literal_Subtype then
19534 R_Low := String_Literal_Low_Bound (R_Typ);
19535 R_Len := String_Literal_Length (R_Typ);
19537 R_Index := First_Index (R_Typ);
19538 Get_Index_Bounds (R_Index, R_Low, R_High);
19540 if Is_OK_Static_Expression (R_Low)
19542 Is_OK_Static_Expression (R_High)
19544 if Expr_Value (R_High) < Expr_Value (R_Low) then
19547 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
19554 if (Is_OK_Static_Expression (L_Low)
19556 Is_OK_Static_Expression (R_Low))
19557 and then Expr_Value (L_Low) = Expr_Value (R_Low)
19558 and then L_Len = R_Len
19565 -- Then treat all other dimensions
19567 for Indx in 2 .. L_Ndims loop
19571 Get_Index_Bounds (L_Index, L_Low, L_High);
19572 Get_Index_Bounds (R_Index, R_Low, R_High);
19574 if (Is_OK_Static_Expression (L_Low) and then
19575 Is_OK_Static_Expression (L_High) and then
19576 Is_OK_Static_Expression (R_Low) and then
19577 Is_OK_Static_Expression (R_High))
19578 and then (Expr_Value (L_Low) = Expr_Value (R_Low)
19580 Expr_Value (L_High) = Expr_Value (R_High))
19588 -- If we fall through the loop, all indexes matched
19591 end Matching_Static_Array_Bounds;
19593 -------------------
19594 -- May_Be_Lvalue --
19595 -------------------
19597 function May_Be_Lvalue (N : Node_Id) return Boolean is
19598 P : constant Node_Id := Parent (N);
19603 -- Test left side of assignment
19605 when N_Assignment_Statement =>
19606 return N = Name (P);
19608 -- Test prefix of component or attribute. Note that the prefix of an
19609 -- explicit or implicit dereference cannot be an l-value. In the case
19610 -- of a 'Read attribute, the reference can be an actual in the
19611 -- argument list of the attribute.
19613 when N_Attribute_Reference =>
19614 return (N = Prefix (P)
19615 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P)))
19617 Attribute_Name (P) = Name_Read;
19619 -- For an expanded name, the name is an lvalue if the expanded name
19620 -- is an lvalue, but the prefix is never an lvalue, since it is just
19621 -- the scope where the name is found.
19623 when N_Expanded_Name =>
19624 if N = Prefix (P) then
19625 return May_Be_Lvalue (P);
19630 -- For a selected component A.B, A is certainly an lvalue if A.B is.
19631 -- B is a little interesting, if we have A.B := 3, there is some
19632 -- discussion as to whether B is an lvalue or not, we choose to say
19633 -- it is. Note however that A is not an lvalue if it is of an access
19634 -- type since this is an implicit dereference.
19636 when N_Selected_Component =>
19638 and then Present (Etype (N))
19639 and then Is_Access_Type (Etype (N))
19643 return May_Be_Lvalue (P);
19646 -- For an indexed component or slice, the index or slice bounds is
19647 -- never an lvalue. The prefix is an lvalue if the indexed component
19648 -- or slice is an lvalue, except if it is an access type, where we
19649 -- have an implicit dereference.
19651 when N_Indexed_Component
19655 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
19659 return May_Be_Lvalue (P);
19662 -- Prefix of a reference is an lvalue if the reference is an lvalue
19664 when N_Reference =>
19665 return May_Be_Lvalue (P);
19667 -- Prefix of explicit dereference is never an lvalue
19669 when N_Explicit_Dereference =>
19672 -- Positional parameter for subprogram, entry, or accept call.
19673 -- In older versions of Ada function call arguments are never
19674 -- lvalues. In Ada 2012 functions can have in-out parameters.
19676 when N_Accept_Statement
19677 | N_Entry_Call_Statement
19678 | N_Subprogram_Call
19680 if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
19684 -- The following mechanism is clumsy and fragile. A single flag
19685 -- set in Resolve_Actuals would be preferable ???
19693 Proc := Get_Subprogram_Entity (P);
19699 -- If we are not a list member, something is strange, so be
19700 -- conservative and return True.
19702 if not Is_List_Member (N) then
19706 -- We are going to find the right formal by stepping forward
19707 -- through the formals, as we step backwards in the actuals.
19709 Form := First_Formal (Proc);
19712 -- If no formal, something is weird, so be conservative and
19720 exit when No (Act);
19721 Next_Formal (Form);
19724 return Ekind (Form) /= E_In_Parameter;
19727 -- Named parameter for procedure or accept call
19729 when N_Parameter_Association =>
19735 Proc := Get_Subprogram_Entity (Parent (P));
19741 -- Loop through formals to find the one that matches
19743 Form := First_Formal (Proc);
19745 -- If no matching formal, that's peculiar, some kind of
19746 -- previous error, so return True to be conservative.
19747 -- Actually happens with legal code for an unresolved call
19748 -- where we may get the wrong homonym???
19754 -- Else test for match
19756 if Chars (Form) = Chars (Selector_Name (P)) then
19757 return Ekind (Form) /= E_In_Parameter;
19760 Next_Formal (Form);
19764 -- Test for appearing in a conversion that itself appears in an
19765 -- lvalue context, since this should be an lvalue.
19767 when N_Type_Conversion =>
19768 return May_Be_Lvalue (P);
19770 -- Test for appearance in object renaming declaration
19772 when N_Object_Renaming_Declaration =>
19775 -- All other references are definitely not lvalues
19786 function Might_Raise (N : Node_Id) return Boolean is
19787 Result : Boolean := False;
19789 function Process (N : Node_Id) return Traverse_Result;
19790 -- Set Result to True if we find something that could raise an exception
19796 function Process (N : Node_Id) return Traverse_Result is
19798 if Nkind_In (N, N_Procedure_Call_Statement,
19801 N_Raise_Constraint_Error,
19802 N_Raise_Program_Error,
19803 N_Raise_Storage_Error)
19812 procedure Set_Result is new Traverse_Proc (Process);
19814 -- Start of processing for Might_Raise
19817 -- False if exceptions can't be propagated
19819 if No_Exception_Handlers_Set then
19823 -- If the checks handled by the back end are not disabled, we cannot
19824 -- ensure that no exception will be raised.
19826 if not Access_Checks_Suppressed (Empty)
19827 or else not Discriminant_Checks_Suppressed (Empty)
19828 or else not Range_Checks_Suppressed (Empty)
19829 or else not Index_Checks_Suppressed (Empty)
19830 or else Opt.Stack_Checking_Enabled
19839 --------------------------------
19840 -- Nearest_Enclosing_Instance --
19841 --------------------------------
19843 function Nearest_Enclosing_Instance (E : Entity_Id) return Entity_Id is
19848 while Present (Inst) and then Inst /= Standard_Standard loop
19849 if Is_Generic_Instance (Inst) then
19853 Inst := Scope (Inst);
19857 end Nearest_Enclosing_Instance;
19859 ------------------------
19860 -- Needs_Finalization --
19861 ------------------------
19863 function Needs_Finalization (Typ : Entity_Id) return Boolean is
19864 function Has_Some_Controlled_Component
19865 (Input_Typ : Entity_Id) return Boolean;
19866 -- Determine whether type Input_Typ has at least one controlled
19869 -----------------------------------
19870 -- Has_Some_Controlled_Component --
19871 -----------------------------------
19873 function Has_Some_Controlled_Component
19874 (Input_Typ : Entity_Id) return Boolean
19879 -- When a type is already frozen and has at least one controlled
19880 -- component, or is manually decorated, it is sufficient to inspect
19881 -- flag Has_Controlled_Component.
19883 if Has_Controlled_Component (Input_Typ) then
19886 -- Otherwise inspect the internals of the type
19888 elsif not Is_Frozen (Input_Typ) then
19889 if Is_Array_Type (Input_Typ) then
19890 return Needs_Finalization (Component_Type (Input_Typ));
19892 elsif Is_Record_Type (Input_Typ) then
19893 Comp := First_Component (Input_Typ);
19894 while Present (Comp) loop
19895 if Needs_Finalization (Etype (Comp)) then
19899 Next_Component (Comp);
19905 end Has_Some_Controlled_Component;
19907 -- Start of processing for Needs_Finalization
19910 -- Certain run-time configurations and targets do not provide support
19911 -- for controlled types.
19913 if Restriction_Active (No_Finalization) then
19916 -- C++ types are not considered controlled. It is assumed that the non-
19917 -- Ada side will handle their clean up.
19919 elsif Convention (Typ) = Convention_CPP then
19922 -- Class-wide types are treated as controlled because derivations from
19923 -- the root type may introduce controlled components.
19925 elsif Is_Class_Wide_Type (Typ) then
19928 -- Concurrent types are controlled as long as their corresponding record
19931 elsif Is_Concurrent_Type (Typ)
19932 and then Present (Corresponding_Record_Type (Typ))
19933 and then Needs_Finalization (Corresponding_Record_Type (Typ))
19937 -- Otherwise the type is controlled when it is either derived from type
19938 -- [Limited_]Controlled and not subject to aspect Disable_Controlled, or
19939 -- contains at least one controlled component.
19943 Is_Controlled (Typ) or else Has_Some_Controlled_Component (Typ);
19945 end Needs_Finalization;
19947 ----------------------
19948 -- Needs_One_Actual --
19949 ----------------------
19951 function Needs_One_Actual (E : Entity_Id) return Boolean is
19952 Formal : Entity_Id;
19955 -- Ada 2005 or later, and formals present. The first formal must be
19956 -- of a type that supports prefix notation: a controlling argument,
19957 -- a class-wide type, or an access to such.
19959 if Ada_Version >= Ada_2005
19960 and then Present (First_Formal (E))
19961 and then No (Default_Value (First_Formal (E)))
19963 (Is_Controlling_Formal (First_Formal (E))
19964 or else Is_Class_Wide_Type (Etype (First_Formal (E)))
19965 or else Is_Anonymous_Access_Type (Etype (First_Formal (E))))
19967 Formal := Next_Formal (First_Formal (E));
19968 while Present (Formal) loop
19969 if No (Default_Value (Formal)) then
19973 Next_Formal (Formal);
19978 -- Ada 83/95 or no formals
19983 end Needs_One_Actual;
19985 ---------------------------------
19986 -- Needs_Simple_Initialization --
19987 ---------------------------------
19989 function Needs_Simple_Initialization
19991 Consider_IS : Boolean := True) return Boolean
19993 Consider_IS_NS : constant Boolean :=
19994 Normalize_Scalars or (Initialize_Scalars and Consider_IS);
19997 -- Never need initialization if it is suppressed
19999 if Initialization_Suppressed (Typ) then
20003 -- Check for private type, in which case test applies to the underlying
20004 -- type of the private type.
20006 if Is_Private_Type (Typ) then
20008 RT : constant Entity_Id := Underlying_Type (Typ);
20010 if Present (RT) then
20011 return Needs_Simple_Initialization (RT);
20017 -- Scalar type with Default_Value aspect requires initialization
20019 elsif Is_Scalar_Type (Typ) and then Has_Default_Aspect (Typ) then
20022 -- Cases needing simple initialization are access types, and, if pragma
20023 -- Normalize_Scalars or Initialize_Scalars is in effect, then all scalar
20026 elsif Is_Access_Type (Typ)
20027 or else (Consider_IS_NS and then (Is_Scalar_Type (Typ)))
20031 -- If Initialize/Normalize_Scalars is in effect, string objects also
20032 -- need initialization, unless they are created in the course of
20033 -- expanding an aggregate (since in the latter case they will be
20034 -- filled with appropriate initializing values before they are used).
20036 elsif Consider_IS_NS
20037 and then Is_Standard_String_Type (Typ)
20039 (not Is_Itype (Typ)
20040 or else Nkind (Associated_Node_For_Itype (Typ)) /= N_Aggregate)
20047 end Needs_Simple_Initialization;
20049 -------------------------------------
20050 -- Needs_Variable_Reference_Marker --
20051 -------------------------------------
20053 function Needs_Variable_Reference_Marker
20055 Calls_OK : Boolean) return Boolean
20057 function Within_Suitable_Context (Ref : Node_Id) return Boolean;
20058 -- Deteremine whether variable reference Ref appears within a suitable
20059 -- context that allows the creation of a marker.
20061 -----------------------------
20062 -- Within_Suitable_Context --
20063 -----------------------------
20065 function Within_Suitable_Context (Ref : Node_Id) return Boolean is
20070 while Present (Par) loop
20072 -- The context is not suitable when the reference appears within
20073 -- the formal part of an instantiation which acts as compilation
20074 -- unit because there is no proper list for the insertion of the
20077 if Nkind (Par) = N_Generic_Association
20078 and then Nkind (Parent (Par)) in N_Generic_Instantiation
20079 and then Nkind (Parent (Parent (Par))) = N_Compilation_Unit
20083 -- The context is not suitable when the reference appears within
20084 -- a pragma. If the pragma has run-time semantics, the reference
20085 -- will be reconsidered once the pragma is expanded.
20087 elsif Nkind (Par) = N_Pragma then
20090 -- The context is not suitable when the reference appears within a
20091 -- subprogram call, and the caller requests this behavior.
20094 and then Nkind_In (Par, N_Entry_Call_Statement,
20096 N_Procedure_Call_Statement)
20100 -- Prevent the search from going too far
20102 elsif Is_Body_Or_Package_Declaration (Par) then
20106 Par := Parent (Par);
20110 end Within_Suitable_Context;
20115 Var_Id : Entity_Id;
20117 -- Start of processing for Needs_Variable_Reference_Marker
20120 -- No marker needs to be created when switch -gnatH (legacy elaboration
20121 -- checking mode enabled) is in effect because the legacy ABE mechanism
20122 -- does not use markers.
20124 if Legacy_Elaboration_Checks then
20127 -- No marker needs to be created for ASIS because ABE diagnostics and
20128 -- checks are not performed in this mode.
20130 elsif ASIS_Mode then
20133 -- No marker needs to be created when the reference is preanalyzed
20134 -- because the marker will be inserted in the wrong place.
20136 elsif Preanalysis_Active then
20139 -- Only references warrant a marker
20141 elsif not Nkind_In (N, N_Expanded_Name, N_Identifier) then
20144 -- Only source references warrant a marker
20146 elsif not Comes_From_Source (N) then
20149 -- No marker needs to be created when the reference is erroneous, left
20150 -- in a bad state, or does not denote a variable.
20152 elsif not (Present (Entity (N))
20153 and then Ekind (Entity (N)) = E_Variable
20154 and then Entity (N) /= Any_Id)
20159 Var_Id := Entity (N);
20160 Prag := SPARK_Pragma (Var_Id);
20162 -- Both the variable and reference must appear in SPARK_Mode On regions
20163 -- because this elaboration scenario falls under the SPARK rules.
20165 if not (Comes_From_Source (Var_Id)
20166 and then Present (Prag)
20167 and then Get_SPARK_Mode_From_Annotation (Prag) = On
20168 and then Is_SPARK_Mode_On_Node (N))
20172 -- No marker needs to be created when the reference does not appear
20173 -- within a suitable context (see body for details).
20175 -- Performance note: parent traversal
20177 elsif not Within_Suitable_Context (N) then
20181 -- At this point it is known that the variable reference will play a
20182 -- role in ABE diagnostics and requires a marker.
20185 end Needs_Variable_Reference_Marker;
20187 ------------------------
20188 -- New_Copy_List_Tree --
20189 ------------------------
20191 function New_Copy_List_Tree (List : List_Id) return List_Id is
20196 if List = No_List then
20203 while Present (E) loop
20204 Append (New_Copy_Tree (E), NL);
20210 end New_Copy_List_Tree;
20212 -------------------
20213 -- New_Copy_Tree --
20214 -------------------
20216 -- The following tables play a key role in replicating entities and Itypes.
20217 -- They are intentionally declared at the library level rather than within
20218 -- New_Copy_Tree to avoid elaborating them on each call. This performance
20219 -- optimization saves up to 2% of the entire compilation time spent in the
20220 -- front end. Care should be taken to reset the tables on each new call to
20223 NCT_Table_Max : constant := 511;
20225 subtype NCT_Table_Index is Nat range 0 .. NCT_Table_Max - 1;
20227 function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index;
20228 -- Obtain the hash value of node or entity Key
20230 --------------------
20231 -- NCT_Table_Hash --
20232 --------------------
20234 function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index is
20236 return NCT_Table_Index (Key mod NCT_Table_Max);
20237 end NCT_Table_Hash;
20239 ----------------------
20240 -- NCT_New_Entities --
20241 ----------------------
20243 -- The following table maps old entities and Itypes to their corresponding
20244 -- new entities and Itypes.
20248 package NCT_New_Entities is new Simple_HTable (
20249 Header_Num => NCT_Table_Index,
20250 Element => Entity_Id,
20251 No_Element => Empty,
20253 Hash => NCT_Table_Hash,
20256 ------------------------
20257 -- NCT_Pending_Itypes --
20258 ------------------------
20260 -- The following table maps old Associated_Node_For_Itype nodes to a set of
20261 -- new itypes. Given a set of old Itypes Aaa, Bbb, and Ccc, where all three
20262 -- have the same Associated_Node_For_Itype Ppp, and their corresponding new
20263 -- Itypes Xxx, Yyy, Zzz, the table contains the following mapping:
20265 -- Ppp -> (Xxx, Yyy, Zzz)
20267 -- The set is expressed as an Elist
20269 package NCT_Pending_Itypes is new Simple_HTable (
20270 Header_Num => NCT_Table_Index,
20271 Element => Elist_Id,
20272 No_Element => No_Elist,
20274 Hash => NCT_Table_Hash,
20277 NCT_Tables_In_Use : Boolean := False;
20278 -- This flag keeps track of whether the two tables NCT_New_Entities and
20279 -- NCT_Pending_Itypes are in use. The flag is part of an optimization
20280 -- where certain operations are not performed if the tables are not in
20281 -- use. This saves up to 8% of the entire compilation time spent in the
20284 -------------------
20285 -- New_Copy_Tree --
20286 -------------------
20288 function New_Copy_Tree
20290 Map : Elist_Id := No_Elist;
20291 New_Sloc : Source_Ptr := No_Location;
20292 New_Scope : Entity_Id := Empty;
20293 Scopes_In_EWA_OK : Boolean := False) return Node_Id
20295 -- This routine performs low-level tree manipulations and needs access
20296 -- to the internals of the tree.
20298 use Atree.Unchecked_Access;
20299 use Atree_Private_Part;
20301 EWA_Level : Nat := 0;
20302 -- This counter keeps track of how many N_Expression_With_Actions nodes
20303 -- are encountered during a depth-first traversal of the subtree. These
20304 -- nodes may define new entities in their Actions lists and thus require
20305 -- special processing.
20307 EWA_Inner_Scope_Level : Nat := 0;
20308 -- This counter keeps track of how many scoping constructs appear within
20309 -- an N_Expression_With_Actions node.
20311 procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id);
20312 pragma Inline (Add_New_Entity);
20313 -- Add an entry in the NCT_New_Entities table which maps key Old_Id to
20314 -- value New_Id. Old_Id is an entity which appears within the Actions
20315 -- list of an N_Expression_With_Actions node, or within an entity map.
20316 -- New_Id is the corresponding new entity generated during Phase 1.
20318 procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id);
20319 pragma Inline (Add_New_Entity);
20320 -- Add an entry in the NCT_Pending_Itypes which maps key Assoc_Nod to
20321 -- value Itype. Assoc_Nod is the associated node of an itype. Itype is
20324 procedure Build_NCT_Tables (Entity_Map : Elist_Id);
20325 pragma Inline (Build_NCT_Tables);
20326 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with the
20327 -- information supplied in entity map Entity_Map. The format of the
20328 -- entity map must be as follows:
20330 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
20332 function Copy_Any_Node_With_Replacement
20333 (N : Node_Or_Entity_Id) return Node_Or_Entity_Id;
20334 pragma Inline (Copy_Any_Node_With_Replacement);
20335 -- Replicate entity or node N by invoking one of the following routines:
20337 -- Copy_Node_With_Replacement
20338 -- Corresponding_Entity
20340 function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id;
20341 -- Replicate the elements of entity list List
20343 function Copy_Field_With_Replacement
20345 Old_Par : Node_Id := Empty;
20346 New_Par : Node_Id := Empty;
20347 Semantic : Boolean := False) return Union_Id;
20348 -- Replicate field Field by invoking one of the following routines:
20350 -- Copy_Elist_With_Replacement
20351 -- Copy_List_With_Replacement
20352 -- Copy_Node_With_Replacement
20353 -- Corresponding_Entity
20355 -- If the field is not an entity list, entity, itype, syntactic list,
20356 -- or node, then the field is returned unchanged. The routine always
20357 -- replicates entities, itypes, and valid syntactic fields. Old_Par is
20358 -- the expected parent of a syntactic field. New_Par is the new parent
20359 -- associated with a replicated syntactic field. Flag Semantic should
20360 -- be set when the input is a semantic field.
20362 function Copy_List_With_Replacement (List : List_Id) return List_Id;
20363 -- Replicate the elements of syntactic list List
20365 function Copy_Node_With_Replacement (N : Node_Id) return Node_Id;
20366 -- Replicate node N
20368 function Corresponding_Entity (Id : Entity_Id) return Entity_Id;
20369 pragma Inline (Corresponding_Entity);
20370 -- Return the corresponding new entity of Id generated during Phase 1.
20371 -- If there is no such entity, return Id.
20373 function In_Entity_Map
20375 Entity_Map : Elist_Id) return Boolean;
20376 pragma Inline (In_Entity_Map);
20377 -- Determine whether entity Id is one of the old ids specified in entity
20378 -- map Entity_Map. The format of the entity map must be as follows:
20380 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
20382 procedure Update_CFS_Sloc (N : Node_Or_Entity_Id);
20383 pragma Inline (Update_CFS_Sloc);
20384 -- Update the Comes_From_Source and Sloc attributes of node or entity N
20386 procedure Update_First_Real_Statement
20387 (Old_HSS : Node_Id;
20388 New_HSS : Node_Id);
20389 pragma Inline (Update_First_Real_Statement);
20390 -- Update semantic attribute First_Real_Statement of handled sequence of
20391 -- statements New_HSS based on handled sequence of statements Old_HSS.
20393 procedure Update_Named_Associations
20394 (Old_Call : Node_Id;
20395 New_Call : Node_Id);
20396 pragma Inline (Update_Named_Associations);
20397 -- Update semantic chain First/Next_Named_Association of call New_call
20398 -- based on call Old_Call.
20400 procedure Update_New_Entities (Entity_Map : Elist_Id);
20401 pragma Inline (Update_New_Entities);
20402 -- Update the semantic attributes of all new entities generated during
20403 -- Phase 1 that do not appear in entity map Entity_Map. The format of
20404 -- the entity map must be as follows:
20406 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
20408 procedure Update_Pending_Itypes
20409 (Old_Assoc : Node_Id;
20410 New_Assoc : Node_Id);
20411 pragma Inline (Update_Pending_Itypes);
20412 -- Update semantic attribute Associated_Node_For_Itype to refer to node
20413 -- New_Assoc for all itypes whose associated node is Old_Assoc.
20415 procedure Update_Semantic_Fields (Id : Entity_Id);
20416 pragma Inline (Update_Semantic_Fields);
20417 -- Subsidiary to Update_New_Entities. Update semantic fields of entity
20420 procedure Visit_Any_Node (N : Node_Or_Entity_Id);
20421 pragma Inline (Visit_Any_Node);
20422 -- Visit entity of node N by invoking one of the following routines:
20428 procedure Visit_Elist (List : Elist_Id);
20429 -- Visit the elements of entity list List
20431 procedure Visit_Entity (Id : Entity_Id);
20432 -- Visit entity Id. This action may create a new entity of Id and save
20433 -- it in table NCT_New_Entities.
20435 procedure Visit_Field
20437 Par_Nod : Node_Id := Empty;
20438 Semantic : Boolean := False);
20439 -- Visit field Field by invoking one of the following routines:
20447 -- If the field is not an entity list, entity, itype, syntactic list,
20448 -- or node, then the field is not visited. The routine always visits
20449 -- valid syntactic fields. Par_Nod is the expected parent of the
20450 -- syntactic field. Flag Semantic should be set when the input is a
20453 procedure Visit_Itype (Itype : Entity_Id);
20454 -- Visit itype Itype. This action may create a new entity for Itype and
20455 -- save it in table NCT_New_Entities. In addition, the routine may map
20456 -- the associated node of Itype to the new itype in NCT_Pending_Itypes.
20458 procedure Visit_List (List : List_Id);
20459 -- Visit the elements of syntactic list List
20461 procedure Visit_Node (N : Node_Id);
20464 procedure Visit_Semantic_Fields (Id : Entity_Id);
20465 pragma Inline (Visit_Semantic_Fields);
20466 -- Subsidiary to Visit_Entity and Visit_Itype. Visit common semantic
20467 -- fields of entity or itype Id.
20469 --------------------
20470 -- Add_New_Entity --
20471 --------------------
20473 procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id) is
20475 pragma Assert (Present (Old_Id));
20476 pragma Assert (Present (New_Id));
20477 pragma Assert (Nkind (Old_Id) in N_Entity);
20478 pragma Assert (Nkind (New_Id) in N_Entity);
20480 NCT_Tables_In_Use := True;
20482 -- Sanity check the NCT_New_Entities table. No previous mapping with
20483 -- key Old_Id should exist.
20485 pragma Assert (No (NCT_New_Entities.Get (Old_Id)));
20487 -- Establish the mapping
20489 -- Old_Id -> New_Id
20491 NCT_New_Entities.Set (Old_Id, New_Id);
20492 end Add_New_Entity;
20494 -----------------------
20495 -- Add_Pending_Itype --
20496 -----------------------
20498 procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id) is
20502 pragma Assert (Present (Assoc_Nod));
20503 pragma Assert (Present (Itype));
20504 pragma Assert (Nkind (Itype) in N_Entity);
20505 pragma Assert (Is_Itype (Itype));
20507 NCT_Tables_In_Use := True;
20509 -- It is not possible to sanity check the NCT_Pendint_Itypes table
20510 -- directly because a single node may act as the associated node for
20511 -- multiple itypes.
20513 Itypes := NCT_Pending_Itypes.Get (Assoc_Nod);
20515 if No (Itypes) then
20516 Itypes := New_Elmt_List;
20517 NCT_Pending_Itypes.Set (Assoc_Nod, Itypes);
20520 -- Establish the mapping
20522 -- Assoc_Nod -> (Itype, ...)
20524 -- Avoid inserting the same itype multiple times. This involves a
20525 -- linear search, however the set of itypes with the same associated
20526 -- node is very small.
20528 Append_Unique_Elmt (Itype, Itypes);
20529 end Add_Pending_Itype;
20531 ----------------------
20532 -- Build_NCT_Tables --
20533 ----------------------
20535 procedure Build_NCT_Tables (Entity_Map : Elist_Id) is
20537 Old_Id : Entity_Id;
20538 New_Id : Entity_Id;
20541 -- Nothing to do when there is no entity map
20543 if No (Entity_Map) then
20547 Elmt := First_Elmt (Entity_Map);
20548 while Present (Elmt) loop
20550 -- Extract the (Old_Id, New_Id) pair from the entity map
20552 Old_Id := Node (Elmt);
20555 New_Id := Node (Elmt);
20558 -- Establish the following mapping within table NCT_New_Entities
20560 -- Old_Id -> New_Id
20562 Add_New_Entity (Old_Id, New_Id);
20564 -- Establish the following mapping within table NCT_Pending_Itypes
20565 -- when the new entity is an itype.
20567 -- Assoc_Nod -> (New_Id, ...)
20569 -- IMPORTANT: the associated node is that of the old itype because
20570 -- the node will be replicated in Phase 2.
20572 if Is_Itype (Old_Id) then
20574 (Assoc_Nod => Associated_Node_For_Itype (Old_Id),
20578 end Build_NCT_Tables;
20580 ------------------------------------
20581 -- Copy_Any_Node_With_Replacement --
20582 ------------------------------------
20584 function Copy_Any_Node_With_Replacement
20585 (N : Node_Or_Entity_Id) return Node_Or_Entity_Id
20588 if Nkind (N) in N_Entity then
20589 return Corresponding_Entity (N);
20591 return Copy_Node_With_Replacement (N);
20593 end Copy_Any_Node_With_Replacement;
20595 ---------------------------------
20596 -- Copy_Elist_With_Replacement --
20597 ---------------------------------
20599 function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id is
20604 -- Copy the contents of the old list. Note that the list itself may
20605 -- be empty, in which case the routine returns a new empty list. This
20606 -- avoids sharing lists between subtrees. The element of an entity
20607 -- list could be an entity or a node, hence the invocation of routine
20608 -- Copy_Any_Node_With_Replacement.
20610 if Present (List) then
20611 Result := New_Elmt_List;
20613 Elmt := First_Elmt (List);
20614 while Present (Elmt) loop
20616 (Copy_Any_Node_With_Replacement (Node (Elmt)), Result);
20621 -- Otherwise the list does not exist
20624 Result := No_Elist;
20628 end Copy_Elist_With_Replacement;
20630 ---------------------------------
20631 -- Copy_Field_With_Replacement --
20632 ---------------------------------
20634 function Copy_Field_With_Replacement
20636 Old_Par : Node_Id := Empty;
20637 New_Par : Node_Id := Empty;
20638 Semantic : Boolean := False) return Union_Id
20641 -- The field is empty
20643 if Field = Union_Id (Empty) then
20646 -- The field is an entity/itype/node
20648 elsif Field in Node_Range then
20650 Old_N : constant Node_Id := Node_Id (Field);
20651 Syntactic : constant Boolean := Parent (Old_N) = Old_Par;
20656 -- The field is an entity/itype
20658 if Nkind (Old_N) in N_Entity then
20660 -- An entity/itype is always replicated
20662 New_N := Corresponding_Entity (Old_N);
20664 -- Update the parent pointer when the entity is a syntactic
20665 -- field. Note that itypes do not have parent pointers.
20667 if Syntactic and then New_N /= Old_N then
20668 Set_Parent (New_N, New_Par);
20671 -- The field is a node
20674 -- A node is replicated when it is either a syntactic field
20675 -- or when the caller treats it as a semantic attribute.
20677 if Syntactic or else Semantic then
20678 New_N := Copy_Node_With_Replacement (Old_N);
20680 -- Update the parent pointer when the node is a syntactic
20683 if Syntactic and then New_N /= Old_N then
20684 Set_Parent (New_N, New_Par);
20687 -- Otherwise the node is returned unchanged
20694 return Union_Id (New_N);
20697 -- The field is an entity list
20699 elsif Field in Elist_Range then
20700 return Union_Id (Copy_Elist_With_Replacement (Elist_Id (Field)));
20702 -- The field is a syntactic list
20704 elsif Field in List_Range then
20706 Old_List : constant List_Id := List_Id (Field);
20707 Syntactic : constant Boolean := Parent (Old_List) = Old_Par;
20709 New_List : List_Id;
20712 -- A list is replicated when it is either a syntactic field or
20713 -- when the caller treats it as a semantic attribute.
20715 if Syntactic or else Semantic then
20716 New_List := Copy_List_With_Replacement (Old_List);
20718 -- Update the parent pointer when the list is a syntactic
20721 if Syntactic and then New_List /= Old_List then
20722 Set_Parent (New_List, New_Par);
20725 -- Otherwise the list is returned unchanged
20728 New_List := Old_List;
20731 return Union_Id (New_List);
20734 -- Otherwise the field denotes an attribute that does not need to be
20735 -- replicated (Chars, literals, etc).
20740 end Copy_Field_With_Replacement;
20742 --------------------------------
20743 -- Copy_List_With_Replacement --
20744 --------------------------------
20746 function Copy_List_With_Replacement (List : List_Id) return List_Id is
20751 -- Copy the contents of the old list. Note that the list itself may
20752 -- be empty, in which case the routine returns a new empty list. This
20753 -- avoids sharing lists between subtrees. The element of a syntactic
20754 -- list is always a node, never an entity or itype, hence the call to
20755 -- routine Copy_Node_With_Replacement.
20757 if Present (List) then
20758 Result := New_List;
20760 Elmt := First (List);
20761 while Present (Elmt) loop
20762 Append (Copy_Node_With_Replacement (Elmt), Result);
20767 -- Otherwise the list does not exist
20774 end Copy_List_With_Replacement;
20776 --------------------------------
20777 -- Copy_Node_With_Replacement --
20778 --------------------------------
20780 function Copy_Node_With_Replacement (N : Node_Id) return Node_Id is
20784 -- Assume that the node must be returned unchanged
20788 if N > Empty_Or_Error then
20789 pragma Assert (Nkind (N) not in N_Entity);
20791 Result := New_Copy (N);
20793 Set_Field1 (Result,
20794 Copy_Field_With_Replacement
20795 (Field => Field1 (Result),
20797 New_Par => Result));
20799 Set_Field2 (Result,
20800 Copy_Field_With_Replacement
20801 (Field => Field2 (Result),
20803 New_Par => Result));
20805 Set_Field3 (Result,
20806 Copy_Field_With_Replacement
20807 (Field => Field3 (Result),
20809 New_Par => Result));
20811 Set_Field4 (Result,
20812 Copy_Field_With_Replacement
20813 (Field => Field4 (Result),
20815 New_Par => Result));
20817 Set_Field5 (Result,
20818 Copy_Field_With_Replacement
20819 (Field => Field5 (Result),
20821 New_Par => Result));
20823 -- Update the Comes_From_Source and Sloc attributes of the node
20824 -- in case the caller has supplied new values.
20826 Update_CFS_Sloc (Result);
20828 -- Update the Associated_Node_For_Itype attribute of all itypes
20829 -- created during Phase 1 whose associated node is N. As a result
20830 -- the Associated_Node_For_Itype refers to the replicated node.
20831 -- No action needs to be taken when the Associated_Node_For_Itype
20832 -- refers to an entity because this was already handled during
20833 -- Phase 1, in Visit_Itype.
20835 Update_Pending_Itypes
20837 New_Assoc => Result);
20839 -- Update the First/Next_Named_Association chain for a replicated
20842 if Nkind_In (N, N_Entry_Call_Statement,
20844 N_Procedure_Call_Statement)
20846 Update_Named_Associations
20848 New_Call => Result);
20850 -- Update the Renamed_Object attribute of a replicated object
20853 elsif Nkind (N) = N_Object_Renaming_Declaration then
20854 Set_Renamed_Object (Defining_Entity (Result), Name (Result));
20856 -- Update the First_Real_Statement attribute of a replicated
20857 -- handled sequence of statements.
20859 elsif Nkind (N) = N_Handled_Sequence_Of_Statements then
20860 Update_First_Real_Statement
20862 New_HSS => Result);
20864 -- Update the Chars attribute of identifiers
20866 elsif Nkind (N) = N_Identifier then
20868 -- The Entity field of identifiers that denote aspects is used
20869 -- to store arbitrary expressions (and hence we must check that
20870 -- they reference an actual entity before copying their Chars
20873 if Present (Entity (Result))
20874 and then Nkind (Entity (Result)) in N_Entity
20876 Set_Chars (Result, Chars (Entity (Result)));
20882 end Copy_Node_With_Replacement;
20884 --------------------------
20885 -- Corresponding_Entity --
20886 --------------------------
20888 function Corresponding_Entity (Id : Entity_Id) return Entity_Id is
20889 New_Id : Entity_Id;
20890 Result : Entity_Id;
20893 -- Assume that the entity must be returned unchanged
20897 if Id > Empty_Or_Error then
20898 pragma Assert (Nkind (Id) in N_Entity);
20900 -- Determine whether the entity has a corresponding new entity
20901 -- generated during Phase 1 and if it does, use it.
20903 if NCT_Tables_In_Use then
20904 New_Id := NCT_New_Entities.Get (Id);
20906 if Present (New_Id) then
20913 end Corresponding_Entity;
20915 -------------------
20916 -- In_Entity_Map --
20917 -------------------
20919 function In_Entity_Map
20921 Entity_Map : Elist_Id) return Boolean
20924 Old_Id : Entity_Id;
20927 -- The entity map contains pairs (Old_Id, New_Id). The advancement
20928 -- step always skips the New_Id portion of the pair.
20930 if Present (Entity_Map) then
20931 Elmt := First_Elmt (Entity_Map);
20932 while Present (Elmt) loop
20933 Old_Id := Node (Elmt);
20935 if Old_Id = Id then
20947 ---------------------
20948 -- Update_CFS_Sloc --
20949 ---------------------
20951 procedure Update_CFS_Sloc (N : Node_Or_Entity_Id) is
20953 -- A new source location defaults the Comes_From_Source attribute
20955 if New_Sloc /= No_Location then
20956 Set_Comes_From_Source (N, Default_Node.Comes_From_Source);
20957 Set_Sloc (N, New_Sloc);
20959 end Update_CFS_Sloc;
20961 ---------------------------------
20962 -- Update_First_Real_Statement --
20963 ---------------------------------
20965 procedure Update_First_Real_Statement
20966 (Old_HSS : Node_Id;
20969 Old_First_Stmt : constant Node_Id := First_Real_Statement (Old_HSS);
20971 New_Stmt : Node_Id;
20972 Old_Stmt : Node_Id;
20975 -- Recreate the First_Real_Statement attribute of a handled sequence
20976 -- of statements by traversing the statement lists of both sequences
20979 if Present (Old_First_Stmt) then
20980 New_Stmt := First (Statements (New_HSS));
20981 Old_Stmt := First (Statements (Old_HSS));
20982 while Present (Old_Stmt) and then Old_Stmt /= Old_First_Stmt loop
20987 pragma Assert (Present (New_Stmt));
20988 pragma Assert (Present (Old_Stmt));
20990 Set_First_Real_Statement (New_HSS, New_Stmt);
20992 end Update_First_Real_Statement;
20994 -------------------------------
20995 -- Update_Named_Associations --
20996 -------------------------------
20998 procedure Update_Named_Associations
20999 (Old_Call : Node_Id;
21000 New_Call : Node_Id)
21003 New_Next : Node_Id;
21005 Old_Next : Node_Id;
21008 if No (First_Named_Actual (Old_Call)) then
21012 -- Recreate the First/Next_Named_Actual chain of a call by traversing
21013 -- the chains of both the old and new calls in parallel.
21015 New_Act := First (Parameter_Associations (New_Call));
21016 Old_Act := First (Parameter_Associations (Old_Call));
21017 while Present (Old_Act) loop
21018 if Nkind (Old_Act) = N_Parameter_Association
21019 and then Explicit_Actual_Parameter (Old_Act)
21020 = First_Named_Actual (Old_Call)
21022 Set_First_Named_Actual (New_Call,
21023 Explicit_Actual_Parameter (New_Act));
21026 if Nkind (Old_Act) = N_Parameter_Association
21027 and then Present (Next_Named_Actual (Old_Act))
21029 -- Scan the actual parameter list to find the next suitable
21030 -- named actual. Note that the list may be out of order.
21032 New_Next := First (Parameter_Associations (New_Call));
21033 Old_Next := First (Parameter_Associations (Old_Call));
21034 while Nkind (Old_Next) /= N_Parameter_Association
21035 or else Explicit_Actual_Parameter (Old_Next) /=
21036 Next_Named_Actual (Old_Act)
21042 Set_Next_Named_Actual (New_Act,
21043 Explicit_Actual_Parameter (New_Next));
21049 end Update_Named_Associations;
21051 -------------------------
21052 -- Update_New_Entities --
21053 -------------------------
21055 procedure Update_New_Entities (Entity_Map : Elist_Id) is
21056 New_Id : Entity_Id := Empty;
21057 Old_Id : Entity_Id := Empty;
21060 if NCT_Tables_In_Use then
21061 NCT_New_Entities.Get_First (Old_Id, New_Id);
21063 -- Update the semantic fields of all new entities created during
21064 -- Phase 1 which were not supplied via an entity map.
21065 -- ??? Is there a better way of distinguishing those?
21067 while Present (Old_Id) and then Present (New_Id) loop
21068 if not (Present (Entity_Map)
21069 and then In_Entity_Map (Old_Id, Entity_Map))
21071 Update_Semantic_Fields (New_Id);
21074 NCT_New_Entities.Get_Next (Old_Id, New_Id);
21077 end Update_New_Entities;
21079 ---------------------------
21080 -- Update_Pending_Itypes --
21081 ---------------------------
21083 procedure Update_Pending_Itypes
21084 (Old_Assoc : Node_Id;
21085 New_Assoc : Node_Id)
21091 if NCT_Tables_In_Use then
21092 Itypes := NCT_Pending_Itypes.Get (Old_Assoc);
21094 -- Update the Associated_Node_For_Itype attribute for all itypes
21095 -- which originally refer to Old_Assoc to designate New_Assoc.
21097 if Present (Itypes) then
21098 Item := First_Elmt (Itypes);
21099 while Present (Item) loop
21100 Set_Associated_Node_For_Itype (Node (Item), New_Assoc);
21106 end Update_Pending_Itypes;
21108 ----------------------------
21109 -- Update_Semantic_Fields --
21110 ----------------------------
21112 procedure Update_Semantic_Fields (Id : Entity_Id) is
21114 -- Discriminant_Constraint
21116 if Is_Type (Id) and then Has_Discriminants (Base_Type (Id)) then
21117 Set_Discriminant_Constraint (Id, Elist_Id (
21118 Copy_Field_With_Replacement
21119 (Field => Union_Id (Discriminant_Constraint (Id)),
21120 Semantic => True)));
21125 Set_Etype (Id, Node_Id (
21126 Copy_Field_With_Replacement
21127 (Field => Union_Id (Etype (Id)),
21128 Semantic => True)));
21131 -- Packed_Array_Impl_Type
21133 if Is_Array_Type (Id) then
21134 if Present (First_Index (Id)) then
21135 Set_First_Index (Id, First (List_Id (
21136 Copy_Field_With_Replacement
21137 (Field => Union_Id (List_Containing (First_Index (Id))),
21138 Semantic => True))));
21141 if Is_Packed (Id) then
21142 Set_Packed_Array_Impl_Type (Id, Node_Id (
21143 Copy_Field_With_Replacement
21144 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
21145 Semantic => True)));
21151 Set_Prev_Entity (Id, Node_Id (
21152 Copy_Field_With_Replacement
21153 (Field => Union_Id (Prev_Entity (Id)),
21154 Semantic => True)));
21158 Set_Next_Entity (Id, Node_Id (
21159 Copy_Field_With_Replacement
21160 (Field => Union_Id (Next_Entity (Id)),
21161 Semantic => True)));
21165 if Is_Discrete_Type (Id) then
21166 Set_Scalar_Range (Id, Node_Id (
21167 Copy_Field_With_Replacement
21168 (Field => Union_Id (Scalar_Range (Id)),
21169 Semantic => True)));
21174 -- Update the scope when the caller specified an explicit one
21176 if Present (New_Scope) then
21177 Set_Scope (Id, New_Scope);
21179 Set_Scope (Id, Node_Id (
21180 Copy_Field_With_Replacement
21181 (Field => Union_Id (Scope (Id)),
21182 Semantic => True)));
21184 end Update_Semantic_Fields;
21186 --------------------
21187 -- Visit_Any_Node --
21188 --------------------
21190 procedure Visit_Any_Node (N : Node_Or_Entity_Id) is
21192 if Nkind (N) in N_Entity then
21193 if Is_Itype (N) then
21201 end Visit_Any_Node;
21207 procedure Visit_Elist (List : Elist_Id) is
21211 -- The element of an entity list could be an entity, itype, or a
21212 -- node, hence the call to Visit_Any_Node.
21214 if Present (List) then
21215 Elmt := First_Elmt (List);
21216 while Present (Elmt) loop
21217 Visit_Any_Node (Node (Elmt));
21228 procedure Visit_Entity (Id : Entity_Id) is
21229 New_Id : Entity_Id;
21232 pragma Assert (Nkind (Id) in N_Entity);
21233 pragma Assert (not Is_Itype (Id));
21235 -- Nothing to do when the entity is not defined in the Actions list
21236 -- of an N_Expression_With_Actions node.
21238 if EWA_Level = 0 then
21241 -- Nothing to do when the entity is defined in a scoping construct
21242 -- within an N_Expression_With_Actions node, unless the caller has
21243 -- requested their replication.
21245 -- ??? should this restriction be eliminated?
21247 elsif EWA_Inner_Scope_Level > 0 and then not Scopes_In_EWA_OK then
21250 -- Nothing to do when the entity does not denote a construct that
21251 -- may appear within an N_Expression_With_Actions node. Relaxing
21252 -- this restriction leads to a performance penalty.
21254 -- ??? this list is flaky, and may hide dormant bugs
21255 -- Should functions be included???
21257 -- Loop parameters appear within quantified expressions and contain
21258 -- an entity declaration that must be replaced when the expander is
21259 -- active if the expression has been preanalyzed or analyzed.
21261 elsif not Ekind_In (Id, E_Block,
21267 and then not Is_Type (Id)
21271 elsif Ekind (Id) = E_Loop_Parameter
21272 and then No (Etype (Condition (Parent (Parent (Id)))))
21276 -- Nothing to do when the entity was already visited
21278 elsif NCT_Tables_In_Use
21279 and then Present (NCT_New_Entities.Get (Id))
21283 -- Nothing to do when the declaration node of the entity is not in
21284 -- the subtree being replicated.
21286 elsif not In_Subtree
21287 (N => Declaration_Node (Id),
21293 -- Create a new entity by directly copying the old entity. This
21294 -- action causes all attributes of the old entity to be inherited.
21296 New_Id := New_Copy (Id);
21298 -- Create a new name for the new entity because the back end needs
21299 -- distinct names for debugging purposes.
21301 Set_Chars (New_Id, New_Internal_Name ('T'));
21303 -- Update the Comes_From_Source and Sloc attributes of the entity in
21304 -- case the caller has supplied new values.
21306 Update_CFS_Sloc (New_Id);
21308 -- Establish the following mapping within table NCT_New_Entities:
21312 Add_New_Entity (Id, New_Id);
21314 -- Deal with the semantic fields of entities. The fields are visited
21315 -- because they may mention entities which reside within the subtree
21318 Visit_Semantic_Fields (Id);
21325 procedure Visit_Field
21327 Par_Nod : Node_Id := Empty;
21328 Semantic : Boolean := False)
21331 -- The field is empty
21333 if Field = Union_Id (Empty) then
21336 -- The field is an entity/itype/node
21338 elsif Field in Node_Range then
21340 N : constant Node_Id := Node_Id (Field);
21343 -- The field is an entity/itype
21345 if Nkind (N) in N_Entity then
21347 -- Itypes are always visited
21349 if Is_Itype (N) then
21352 -- An entity is visited when it is either a syntactic field
21353 -- or when the caller treats it as a semantic attribute.
21355 elsif Parent (N) = Par_Nod or else Semantic then
21359 -- The field is a node
21362 -- A node is visited when it is either a syntactic field or
21363 -- when the caller treats it as a semantic attribute.
21365 if Parent (N) = Par_Nod or else Semantic then
21371 -- The field is an entity list
21373 elsif Field in Elist_Range then
21374 Visit_Elist (Elist_Id (Field));
21376 -- The field is a syntax list
21378 elsif Field in List_Range then
21380 List : constant List_Id := List_Id (Field);
21383 -- A syntax list is visited when it is either a syntactic field
21384 -- or when the caller treats it as a semantic attribute.
21386 if Parent (List) = Par_Nod or else Semantic then
21391 -- Otherwise the field denotes information which does not need to be
21392 -- visited (chars, literals, etc.).
21403 procedure Visit_Itype (Itype : Entity_Id) is
21404 New_Assoc : Node_Id;
21405 New_Itype : Entity_Id;
21406 Old_Assoc : Node_Id;
21409 pragma Assert (Nkind (Itype) in N_Entity);
21410 pragma Assert (Is_Itype (Itype));
21412 -- Itypes that describe the designated type of access to subprograms
21413 -- have the structure of subprogram declarations, with signatures,
21414 -- etc. Either we duplicate the signatures completely, or choose to
21415 -- share such itypes, which is fine because their elaboration will
21416 -- have no side effects.
21418 if Ekind (Itype) = E_Subprogram_Type then
21421 -- Nothing to do if the itype was already visited
21423 elsif NCT_Tables_In_Use
21424 and then Present (NCT_New_Entities.Get (Itype))
21428 -- Nothing to do if the associated node of the itype is not within
21429 -- the subtree being replicated.
21431 elsif not In_Subtree
21432 (N => Associated_Node_For_Itype (Itype),
21438 -- Create a new itype by directly copying the old itype. This action
21439 -- causes all attributes of the old itype to be inherited.
21441 New_Itype := New_Copy (Itype);
21443 -- Create a new name for the new itype because the back end requires
21444 -- distinct names for debugging purposes.
21446 Set_Chars (New_Itype, New_Internal_Name ('T'));
21448 -- Update the Comes_From_Source and Sloc attributes of the itype in
21449 -- case the caller has supplied new values.
21451 Update_CFS_Sloc (New_Itype);
21453 -- Establish the following mapping within table NCT_New_Entities:
21455 -- Itype -> New_Itype
21457 Add_New_Entity (Itype, New_Itype);
21459 -- The new itype must be unfrozen because the resulting subtree may
21460 -- be inserted anywhere and cause an earlier or later freezing.
21462 if Present (Freeze_Node (New_Itype)) then
21463 Set_Freeze_Node (New_Itype, Empty);
21464 Set_Is_Frozen (New_Itype, False);
21467 -- If a record subtype is simply copied, the entity list will be
21468 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
21469 -- ??? What does this do?
21471 if Ekind_In (Itype, E_Class_Wide_Subtype, E_Record_Subtype) then
21472 Set_Cloned_Subtype (New_Itype, Itype);
21475 -- The associated node may denote an entity, in which case it may
21476 -- already have a new corresponding entity created during a prior
21477 -- call to Visit_Entity or Visit_Itype for the same subtree.
21480 -- Old_Assoc ---------> New_Assoc
21482 -- Created by Visit_Itype
21483 -- Itype -------------> New_Itype
21484 -- ANFI = Old_Assoc ANFI = Old_Assoc < must be updated
21486 -- In the example above, Old_Assoc is an arbitrary entity that was
21487 -- already visited for the same subtree and has a corresponding new
21488 -- entity New_Assoc. Old_Assoc was inherited by New_Itype by virtue
21489 -- of copying entities, however it must be updated to New_Assoc.
21491 Old_Assoc := Associated_Node_For_Itype (Itype);
21493 if Nkind (Old_Assoc) in N_Entity then
21494 if NCT_Tables_In_Use then
21495 New_Assoc := NCT_New_Entities.Get (Old_Assoc);
21497 if Present (New_Assoc) then
21498 Set_Associated_Node_For_Itype (New_Itype, New_Assoc);
21502 -- Otherwise the associated node denotes a node. Postpone the update
21503 -- until Phase 2 when the node is replicated. Establish the following
21504 -- mapping within table NCT_Pending_Itypes:
21506 -- Old_Assoc -> (New_Type, ...)
21509 Add_Pending_Itype (Old_Assoc, New_Itype);
21512 -- Deal with the semantic fields of itypes. The fields are visited
21513 -- because they may mention entities that reside within the subtree
21516 Visit_Semantic_Fields (Itype);
21523 procedure Visit_List (List : List_Id) is
21527 -- Note that the element of a syntactic list is always a node, never
21528 -- an entity or itype, hence the call to Visit_Node.
21530 if Present (List) then
21531 Elmt := First (List);
21532 while Present (Elmt) loop
21544 procedure Visit_Node (N : Node_Or_Entity_Id) is
21546 pragma Assert (Nkind (N) not in N_Entity);
21548 -- If the node is a quantified expression and expander is active,
21549 -- it contains an implicit declaration that may require a new entity
21550 -- when the condition has already been (pre)analyzed.
21552 if Nkind (N) = N_Expression_With_Actions
21554 (Nkind (N) = N_Quantified_Expression and then Expander_Active)
21556 EWA_Level := EWA_Level + 1;
21558 elsif EWA_Level > 0
21559 and then Nkind_In (N, N_Block_Statement,
21561 N_Subprogram_Declaration)
21563 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level + 1;
21567 (Field => Field1 (N),
21571 (Field => Field2 (N),
21575 (Field => Field3 (N),
21579 (Field => Field4 (N),
21583 (Field => Field5 (N),
21587 and then Nkind_In (N, N_Block_Statement,
21589 N_Subprogram_Declaration)
21591 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level - 1;
21593 elsif Nkind (N) = N_Expression_With_Actions then
21594 EWA_Level := EWA_Level - 1;
21598 ---------------------------
21599 -- Visit_Semantic_Fields --
21600 ---------------------------
21602 procedure Visit_Semantic_Fields (Id : Entity_Id) is
21604 pragma Assert (Nkind (Id) in N_Entity);
21606 -- Discriminant_Constraint
21608 if Is_Type (Id) and then Has_Discriminants (Base_Type (Id)) then
21610 (Field => Union_Id (Discriminant_Constraint (Id)),
21617 (Field => Union_Id (Etype (Id)),
21621 -- Packed_Array_Impl_Type
21623 if Is_Array_Type (Id) then
21624 if Present (First_Index (Id)) then
21626 (Field => Union_Id (List_Containing (First_Index (Id))),
21630 if Is_Packed (Id) then
21632 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
21639 if Is_Discrete_Type (Id) then
21641 (Field => Union_Id (Scalar_Range (Id)),
21644 end Visit_Semantic_Fields;
21646 -- Start of processing for New_Copy_Tree
21649 -- Routine New_Copy_Tree performs a deep copy of a subtree by creating
21650 -- shallow copies for each node within, and then updating the child and
21651 -- parent pointers accordingly. This process is straightforward, however
21652 -- the routine must deal with the following complications:
21654 -- * Entities defined within N_Expression_With_Actions nodes must be
21655 -- replicated rather than shared to avoid introducing two identical
21656 -- symbols within the same scope. Note that no other expression can
21657 -- currently define entities.
21660 -- Source_Low : ...;
21661 -- Source_High : ...;
21663 -- <reference to Source_Low>
21664 -- <reference to Source_High>
21667 -- New_Copy_Tree handles this case by first creating new entities
21668 -- and then updating all existing references to point to these new
21675 -- <reference to New_Low>
21676 -- <reference to New_High>
21679 -- * Itypes defined within the subtree must be replicated to avoid any
21680 -- dependencies on invalid or inaccessible data.
21682 -- subtype Source_Itype is ... range Source_Low .. Source_High;
21684 -- New_Copy_Tree handles this case by first creating a new itype in
21685 -- the same fashion as entities, and then updating various relevant
21688 -- subtype New_Itype is ... range New_Low .. New_High;
21690 -- * The Associated_Node_For_Itype field of itypes must be updated to
21691 -- reference the proper replicated entity or node.
21693 -- * Semantic fields of entities such as Etype and Scope must be
21694 -- updated to reference the proper replicated entities.
21696 -- * Semantic fields of nodes such as First_Real_Statement must be
21697 -- updated to reference the proper replicated nodes.
21699 -- Finally, quantified expressions contain an implicit delaration for
21700 -- the bound variable. Given that quantified expressions appearing
21701 -- in contracts are copied to create pragmas and eventually checking
21702 -- procedures, a new bound variable must be created for each copy, to
21703 -- prevent multiple declarations of the same symbol.
21705 -- To meet all these demands, routine New_Copy_Tree is split into two
21708 -- Phase 1 traverses the tree in order to locate entities and itypes
21709 -- defined within the subtree. New entities are generated and saved in
21710 -- table NCT_New_Entities. The semantic fields of all new entities and
21711 -- itypes are then updated accordingly.
21713 -- Phase 2 traverses the tree in order to replicate each node. Various
21714 -- semantic fields of nodes and entities are updated accordingly.
21716 -- Preparatory phase. Clear the contents of tables NCT_New_Entities and
21717 -- NCT_Pending_Itypes in case a previous call to New_Copy_Tree left some
21720 if NCT_Tables_In_Use then
21721 NCT_Tables_In_Use := False;
21723 NCT_New_Entities.Reset;
21724 NCT_Pending_Itypes.Reset;
21727 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with data
21728 -- supplied by a linear entity map. The tables offer faster access to
21731 Build_NCT_Tables (Map);
21733 -- Execute Phase 1. Traverse the subtree and generate new entities for
21734 -- the following cases:
21736 -- * An entity defined within an N_Expression_With_Actions node
21738 -- * An itype referenced within the subtree where the associated node
21739 -- is also in the subtree.
21741 -- All new entities are accessible via table NCT_New_Entities, which
21742 -- contains mappings of the form:
21744 -- Old_Entity -> New_Entity
21745 -- Old_Itype -> New_Itype
21747 -- In addition, the associated nodes of all new itypes are mapped in
21748 -- table NCT_Pending_Itypes:
21750 -- Assoc_Nod -> (New_Itype1, New_Itype2, .., New_ItypeN)
21752 Visit_Any_Node (Source);
21754 -- Update the semantic attributes of all new entities generated during
21755 -- Phase 1 before starting Phase 2. The updates could be performed in
21756 -- routine Corresponding_Entity, however this may cause the same entity
21757 -- to be updated multiple times, effectively generating useless nodes.
21758 -- Keeping the updates separates from Phase 2 ensures that only one set
21759 -- of attributes is generated for an entity at any one time.
21761 Update_New_Entities (Map);
21763 -- Execute Phase 2. Replicate the source subtree one node at a time.
21764 -- The following transformations take place:
21766 -- * References to entities and itypes are updated to refer to the
21767 -- new entities and itypes generated during Phase 1.
21769 -- * All Associated_Node_For_Itype attributes of itypes are updated
21770 -- to refer to the new replicated Associated_Node_For_Itype.
21772 return Copy_Node_With_Replacement (Source);
21775 -------------------------
21776 -- New_External_Entity --
21777 -------------------------
21779 function New_External_Entity
21780 (Kind : Entity_Kind;
21781 Scope_Id : Entity_Id;
21782 Sloc_Value : Source_Ptr;
21783 Related_Id : Entity_Id;
21784 Suffix : Character;
21785 Suffix_Index : Int := 0;
21786 Prefix : Character := ' ') return Entity_Id
21788 N : constant Entity_Id :=
21789 Make_Defining_Identifier (Sloc_Value,
21791 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
21794 Set_Ekind (N, Kind);
21795 Set_Is_Internal (N, True);
21796 Append_Entity (N, Scope_Id);
21797 Set_Public_Status (N);
21799 if Kind in Type_Kind then
21800 Init_Size_Align (N);
21804 end New_External_Entity;
21806 -------------------------
21807 -- New_Internal_Entity --
21808 -------------------------
21810 function New_Internal_Entity
21811 (Kind : Entity_Kind;
21812 Scope_Id : Entity_Id;
21813 Sloc_Value : Source_Ptr;
21814 Id_Char : Character) return Entity_Id
21816 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
21819 Set_Ekind (N, Kind);
21820 Set_Is_Internal (N, True);
21821 Append_Entity (N, Scope_Id);
21823 if Kind in Type_Kind then
21824 Init_Size_Align (N);
21828 end New_Internal_Entity;
21834 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
21835 Par : constant Node_Id := Parent (Actual_Id);
21839 -- If we are pointing at a positional parameter, it is a member of a
21840 -- node list (the list of parameters), and the next parameter is the
21841 -- next node on the list, unless we hit a parameter association, then
21842 -- we shift to using the chain whose head is the First_Named_Actual in
21843 -- the parent, and then is threaded using the Next_Named_Actual of the
21844 -- Parameter_Association. All this fiddling is because the original node
21845 -- list is in the textual call order, and what we need is the
21846 -- declaration order.
21848 if Is_List_Member (Actual_Id) then
21849 N := Next (Actual_Id);
21851 if Nkind (N) = N_Parameter_Association then
21853 -- In case of a build-in-place call, the call will no longer be a
21854 -- call; it will have been rewritten.
21856 if Nkind_In (Par, N_Entry_Call_Statement,
21858 N_Procedure_Call_Statement)
21860 return First_Named_Actual (Par);
21862 -- In case of a call rewritten in GNATprove mode while "inlining
21863 -- for proof" go to the original call.
21865 elsif Nkind (Par) = N_Null_Statement then
21869 Nkind (Original_Node (Par)) in N_Subprogram_Call);
21871 return First_Named_Actual (Original_Node (Par));
21880 return Next_Named_Actual (Parent (Actual_Id));
21884 procedure Next_Actual (Actual_Id : in out Node_Id) is
21886 Actual_Id := Next_Actual (Actual_Id);
21893 function Next_Global (Node : Node_Id) return Node_Id is
21895 -- The global item may either be in a list, or by itself, in which case
21896 -- there is no next global item with the same mode.
21898 if Is_List_Member (Node) then
21899 return Next (Node);
21905 procedure Next_Global (Node : in out Node_Id) is
21907 Node := Next_Global (Node);
21910 ----------------------------------
21911 -- New_Requires_Transient_Scope --
21912 ----------------------------------
21914 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
21915 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean;
21916 -- This is called for untagged records and protected types, with
21917 -- nondefaulted discriminants. Returns True if the size of function
21918 -- results is known at the call site, False otherwise. Returns False
21919 -- if there is a variant part that depends on the discriminants of
21920 -- this type, or if there is an array constrained by the discriminants
21921 -- of this type. ???Currently, this is overly conservative (the array
21922 -- could be nested inside some other record that is constrained by
21923 -- nondiscriminants). That is, the recursive calls are too conservative.
21925 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean;
21926 -- Returns True if Typ is a nonlimited record with defaulted
21927 -- discriminants whose max size makes it unsuitable for allocating on
21928 -- the primary stack.
21930 ------------------------------
21931 -- Caller_Known_Size_Record --
21932 ------------------------------
21934 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean is
21935 pragma Assert (Typ = Underlying_Type (Typ));
21938 if Has_Variant_Part (Typ) and then not Is_Definite_Subtype (Typ) then
21946 Comp := First_Entity (Typ);
21947 while Present (Comp) loop
21949 -- Only look at E_Component entities. No need to look at
21950 -- E_Discriminant entities, and we must ignore internal
21951 -- subtypes generated for constrained components.
21953 if Ekind (Comp) = E_Component then
21955 Comp_Type : constant Entity_Id :=
21956 Underlying_Type (Etype (Comp));
21959 if Is_Record_Type (Comp_Type)
21961 Is_Protected_Type (Comp_Type)
21963 if not Caller_Known_Size_Record (Comp_Type) then
21967 elsif Is_Array_Type (Comp_Type) then
21968 if Size_Depends_On_Discriminant (Comp_Type) then
21975 Next_Entity (Comp);
21980 end Caller_Known_Size_Record;
21982 ------------------------------
21983 -- Large_Max_Size_Mutable --
21984 ------------------------------
21986 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean is
21987 pragma Assert (Typ = Underlying_Type (Typ));
21989 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean;
21990 -- Returns true if the discrete type T has a large range
21992 ----------------------------
21993 -- Is_Large_Discrete_Type --
21994 ----------------------------
21996 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean is
21997 Threshold : constant Int := 16;
21998 -- Arbitrary threshold above which we consider it "large". We want
21999 -- a fairly large threshold, because these large types really
22000 -- shouldn't have default discriminants in the first place, in
22004 return UI_To_Int (RM_Size (T)) > Threshold;
22005 end Is_Large_Discrete_Type;
22007 -- Start of processing for Large_Max_Size_Mutable
22010 if Is_Record_Type (Typ)
22011 and then not Is_Limited_View (Typ)
22012 and then Has_Defaulted_Discriminants (Typ)
22014 -- Loop through the components, looking for an array whose upper
22015 -- bound(s) depends on discriminants, where both the subtype of
22016 -- the discriminant and the index subtype are too large.
22022 Comp := First_Entity (Typ);
22023 while Present (Comp) loop
22024 if Ekind (Comp) = E_Component then
22026 Comp_Type : constant Entity_Id :=
22027 Underlying_Type (Etype (Comp));
22034 if Is_Array_Type (Comp_Type) then
22035 Indx := First_Index (Comp_Type);
22037 while Present (Indx) loop
22038 Ityp := Etype (Indx);
22039 Hi := Type_High_Bound (Ityp);
22041 if Nkind (Hi) = N_Identifier
22042 and then Ekind (Entity (Hi)) = E_Discriminant
22043 and then Is_Large_Discrete_Type (Ityp)
22044 and then Is_Large_Discrete_Type
22045 (Etype (Entity (Hi)))
22056 Next_Entity (Comp);
22062 end Large_Max_Size_Mutable;
22064 -- Local declarations
22066 Typ : constant Entity_Id := Underlying_Type (Id);
22068 -- Start of processing for New_Requires_Transient_Scope
22071 -- This is a private type which is not completed yet. This can only
22072 -- happen in a default expression (of a formal parameter or of a
22073 -- record component). Do not expand transient scope in this case.
22078 -- Do not expand transient scope for non-existent procedure return or
22079 -- string literal types.
22081 elsif Typ = Standard_Void_Type
22082 or else Ekind (Typ) = E_String_Literal_Subtype
22086 -- If Typ is a generic formal incomplete type, then we want to look at
22087 -- the actual type.
22089 elsif Ekind (Typ) = E_Record_Subtype
22090 and then Present (Cloned_Subtype (Typ))
22092 return New_Requires_Transient_Scope (Cloned_Subtype (Typ));
22094 -- Functions returning specific tagged types may dispatch on result, so
22095 -- their returned value is allocated on the secondary stack, even in the
22096 -- definite case. We must treat nondispatching functions the same way,
22097 -- because access-to-function types can point at both, so the calling
22098 -- conventions must be compatible. Is_Tagged_Type includes controlled
22099 -- types and class-wide types. Controlled type temporaries need
22102 -- ???It's not clear why we need to return noncontrolled types with
22103 -- controlled components on the secondary stack.
22105 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
22108 -- Untagged definite subtypes are known size. This includes all
22109 -- elementary [sub]types. Tasks are known size even if they have
22110 -- discriminants. So we return False here, with one exception:
22111 -- For a type like:
22112 -- type T (Last : Natural := 0) is
22113 -- X : String (1 .. Last);
22115 -- we return True. That's because for "P(F(...));", where F returns T,
22116 -- we don't know the size of the result at the call site, so if we
22117 -- allocated it on the primary stack, we would have to allocate the
22118 -- maximum size, which is way too big.
22120 elsif Is_Definite_Subtype (Typ) or else Is_Task_Type (Typ) then
22121 return Large_Max_Size_Mutable (Typ);
22123 -- Indefinite (discriminated) untagged record or protected type
22125 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
22126 return not Caller_Known_Size_Record (Typ);
22128 -- Unconstrained array
22131 pragma Assert (Is_Array_Type (Typ) and not Is_Definite_Subtype (Typ));
22134 end New_Requires_Transient_Scope;
22136 ------------------------
22137 -- No_Caching_Enabled --
22138 ------------------------
22140 function No_Caching_Enabled (Id : Entity_Id) return Boolean is
22141 Prag : constant Node_Id := Get_Pragma (Id, Pragma_No_Caching);
22145 if Present (Prag) then
22146 Arg1 := First (Pragma_Argument_Associations (Prag));
22148 -- The pragma has an optional Boolean expression, the related
22149 -- property is enabled only when the expression evaluates to True.
22151 if Present (Arg1) then
22152 return Is_True (Expr_Value (Get_Pragma_Arg (Arg1)));
22154 -- Otherwise the lack of expression enables the property by
22161 -- The property was never set in the first place
22166 end No_Caching_Enabled;
22168 --------------------------
22169 -- No_Heap_Finalization --
22170 --------------------------
22172 function No_Heap_Finalization (Typ : Entity_Id) return Boolean is
22174 if Ekind_In (Typ, E_Access_Type, E_General_Access_Type)
22175 and then Is_Library_Level_Entity (Typ)
22177 -- A global No_Heap_Finalization pragma applies to all library-level
22178 -- named access-to-object types.
22180 if Present (No_Heap_Finalization_Pragma) then
22183 -- The library-level named access-to-object type itself is subject to
22184 -- pragma No_Heap_Finalization.
22186 elsif Present (Get_Pragma (Typ, Pragma_No_Heap_Finalization)) then
22192 end No_Heap_Finalization;
22194 -----------------------
22195 -- Normalize_Actuals --
22196 -----------------------
22198 -- Chain actuals according to formals of subprogram. If there are no named
22199 -- associations, the chain is simply the list of Parameter Associations,
22200 -- since the order is the same as the declaration order. If there are named
22201 -- associations, then the First_Named_Actual field in the N_Function_Call
22202 -- or N_Procedure_Call_Statement node points to the Parameter_Association
22203 -- node for the parameter that comes first in declaration order. The
22204 -- remaining named parameters are then chained in declaration order using
22205 -- Next_Named_Actual.
22207 -- This routine also verifies that the number of actuals is compatible with
22208 -- the number and default values of formals, but performs no type checking
22209 -- (type checking is done by the caller).
22211 -- If the matching succeeds, Success is set to True and the caller proceeds
22212 -- with type-checking. If the match is unsuccessful, then Success is set to
22213 -- False, and the caller attempts a different interpretation, if there is
22216 -- If the flag Report is on, the call is not overloaded, and a failure to
22217 -- match can be reported here, rather than in the caller.
22219 procedure Normalize_Actuals
22223 Success : out Boolean)
22225 Actuals : constant List_Id := Parameter_Associations (N);
22226 Actual : Node_Id := Empty;
22227 Formal : Entity_Id;
22228 Last : Node_Id := Empty;
22229 First_Named : Node_Id := Empty;
22232 Formals_To_Match : Integer := 0;
22233 Actuals_To_Match : Integer := 0;
22235 procedure Chain (A : Node_Id);
22236 -- Add named actual at the proper place in the list, using the
22237 -- Next_Named_Actual link.
22239 function Reporting return Boolean;
22240 -- Determines if an error is to be reported. To report an error, we
22241 -- need Report to be True, and also we do not report errors caused
22242 -- by calls to init procs that occur within other init procs. Such
22243 -- errors must always be cascaded errors, since if all the types are
22244 -- declared correctly, the compiler will certainly build decent calls.
22250 procedure Chain (A : Node_Id) is
22254 -- Call node points to first actual in list
22256 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
22259 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
22263 Set_Next_Named_Actual (Last, Empty);
22270 function Reporting return Boolean is
22275 elsif not Within_Init_Proc then
22278 elsif Is_Init_Proc (Entity (Name (N))) then
22286 -- Start of processing for Normalize_Actuals
22289 if Is_Access_Type (S) then
22291 -- The name in the call is a function call that returns an access
22292 -- to subprogram. The designated type has the list of formals.
22294 Formal := First_Formal (Designated_Type (S));
22296 Formal := First_Formal (S);
22299 while Present (Formal) loop
22300 Formals_To_Match := Formals_To_Match + 1;
22301 Next_Formal (Formal);
22304 -- Find if there is a named association, and verify that no positional
22305 -- associations appear after named ones.
22307 if Present (Actuals) then
22308 Actual := First (Actuals);
22311 while Present (Actual)
22312 and then Nkind (Actual) /= N_Parameter_Association
22314 Actuals_To_Match := Actuals_To_Match + 1;
22318 if No (Actual) and Actuals_To_Match = Formals_To_Match then
22320 -- Most common case: positional notation, no defaults
22325 elsif Actuals_To_Match > Formals_To_Match then
22327 -- Too many actuals: will not work
22330 if Is_Entity_Name (Name (N)) then
22331 Error_Msg_N ("too many arguments in call to&", Name (N));
22333 Error_Msg_N ("too many arguments in call", N);
22341 First_Named := Actual;
22343 while Present (Actual) loop
22344 if Nkind (Actual) /= N_Parameter_Association then
22346 ("positional parameters not allowed after named ones", Actual);
22351 Actuals_To_Match := Actuals_To_Match + 1;
22357 if Present (Actuals) then
22358 Actual := First (Actuals);
22361 Formal := First_Formal (S);
22362 while Present (Formal) loop
22364 -- Match the formals in order. If the corresponding actual is
22365 -- positional, nothing to do. Else scan the list of named actuals
22366 -- to find the one with the right name.
22368 if Present (Actual)
22369 and then Nkind (Actual) /= N_Parameter_Association
22372 Actuals_To_Match := Actuals_To_Match - 1;
22373 Formals_To_Match := Formals_To_Match - 1;
22376 -- For named parameters, search the list of actuals to find
22377 -- one that matches the next formal name.
22379 Actual := First_Named;
22381 while Present (Actual) loop
22382 if Chars (Selector_Name (Actual)) = Chars (Formal) then
22385 Actuals_To_Match := Actuals_To_Match - 1;
22386 Formals_To_Match := Formals_To_Match - 1;
22394 if Ekind (Formal) /= E_In_Parameter
22395 or else No (Default_Value (Formal))
22398 if (Comes_From_Source (S)
22399 or else Sloc (S) = Standard_Location)
22400 and then Is_Overloadable (S)
22404 Nkind_In (Parent (N), N_Procedure_Call_Statement,
22406 N_Parameter_Association)
22407 and then Ekind (S) /= E_Function
22409 Set_Etype (N, Etype (S));
22412 Error_Msg_Name_1 := Chars (S);
22413 Error_Msg_Sloc := Sloc (S);
22415 ("missing argument for parameter & "
22416 & "in call to % declared #", N, Formal);
22419 elsif Is_Overloadable (S) then
22420 Error_Msg_Name_1 := Chars (S);
22422 -- Point to type derivation that generated the
22425 Error_Msg_Sloc := Sloc (Parent (S));
22428 ("missing argument for parameter & "
22429 & "in call to % (inherited) #", N, Formal);
22433 ("missing argument for parameter &", N, Formal);
22441 Formals_To_Match := Formals_To_Match - 1;
22446 Next_Formal (Formal);
22449 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
22456 -- Find some superfluous named actual that did not get
22457 -- attached to the list of associations.
22459 Actual := First (Actuals);
22460 while Present (Actual) loop
22461 if Nkind (Actual) = N_Parameter_Association
22462 and then Actual /= Last
22463 and then No (Next_Named_Actual (Actual))
22465 -- A validity check may introduce a copy of a call that
22466 -- includes an extra actual (for example for an unrelated
22467 -- accessibility check). Check that the extra actual matches
22468 -- some extra formal, which must exist already because
22469 -- subprogram must be frozen at this point.
22471 if Present (Extra_Formals (S))
22472 and then not Comes_From_Source (Actual)
22473 and then Nkind (Actual) = N_Parameter_Association
22474 and then Chars (Extra_Formals (S)) =
22475 Chars (Selector_Name (Actual))
22480 ("unmatched actual & in call", Selector_Name (Actual));
22492 end Normalize_Actuals;
22494 --------------------------------
22495 -- Note_Possible_Modification --
22496 --------------------------------
22498 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
22499 Modification_Comes_From_Source : constant Boolean :=
22500 Comes_From_Source (Parent (N));
22506 -- Loop to find referenced entity, if there is one
22512 if Is_Entity_Name (Exp) then
22513 Ent := Entity (Exp);
22515 -- If the entity is missing, it is an undeclared identifier,
22516 -- and there is nothing to annotate.
22522 elsif Nkind (Exp) = N_Explicit_Dereference then
22524 P : constant Node_Id := Prefix (Exp);
22527 -- In formal verification mode, keep track of all reads and
22528 -- writes through explicit dereferences.
22530 if GNATprove_Mode then
22531 SPARK_Specific.Generate_Dereference (N, 'm');
22534 if Nkind (P) = N_Selected_Component
22535 and then Present (Entry_Formal (Entity (Selector_Name (P))))
22537 -- Case of a reference to an entry formal
22539 Ent := Entry_Formal (Entity (Selector_Name (P)));
22541 elsif Nkind (P) = N_Identifier
22542 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
22543 and then Present (Expression (Parent (Entity (P))))
22544 and then Nkind (Expression (Parent (Entity (P)))) =
22547 -- Case of a reference to a value on which side effects have
22550 Exp := Prefix (Expression (Parent (Entity (P))));
22558 elsif Nkind_In (Exp, N_Type_Conversion,
22559 N_Unchecked_Type_Conversion)
22561 Exp := Expression (Exp);
22564 elsif Nkind_In (Exp, N_Slice,
22565 N_Indexed_Component,
22566 N_Selected_Component)
22568 -- Special check, if the prefix is an access type, then return
22569 -- since we are modifying the thing pointed to, not the prefix.
22570 -- When we are expanding, most usually the prefix is replaced
22571 -- by an explicit dereference, and this test is not needed, but
22572 -- in some cases (notably -gnatc mode and generics) when we do
22573 -- not do full expansion, we need this special test.
22575 if Is_Access_Type (Etype (Prefix (Exp))) then
22578 -- Otherwise go to prefix and keep going
22581 Exp := Prefix (Exp);
22585 -- All other cases, not a modification
22591 -- Now look for entity being referenced
22593 if Present (Ent) then
22594 if Is_Object (Ent) then
22595 if Comes_From_Source (Exp)
22596 or else Modification_Comes_From_Source
22598 -- Give warning if pragma unmodified is given and we are
22599 -- sure this is a modification.
22601 if Has_Pragma_Unmodified (Ent) and then Sure then
22603 -- Note that the entity may be present only as a result
22604 -- of pragma Unused.
22606 if Has_Pragma_Unused (Ent) then
22607 Error_Msg_NE ("??pragma Unused given for &!", N, Ent);
22610 ("??pragma Unmodified given for &!", N, Ent);
22614 Set_Never_Set_In_Source (Ent, False);
22617 Set_Is_True_Constant (Ent, False);
22618 Set_Current_Value (Ent, Empty);
22619 Set_Is_Known_Null (Ent, False);
22621 if not Can_Never_Be_Null (Ent) then
22622 Set_Is_Known_Non_Null (Ent, False);
22625 -- Follow renaming chain
22627 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
22628 and then Present (Renamed_Object (Ent))
22630 Exp := Renamed_Object (Ent);
22632 -- If the entity is the loop variable in an iteration over
22633 -- a container, retrieve container expression to indicate
22634 -- possible modification.
22636 if Present (Related_Expression (Ent))
22637 and then Nkind (Parent (Related_Expression (Ent))) =
22638 N_Iterator_Specification
22640 Exp := Original_Node (Related_Expression (Ent));
22645 -- The expression may be the renaming of a subcomponent of an
22646 -- array or container. The assignment to the subcomponent is
22647 -- a modification of the container.
22649 elsif Comes_From_Source (Original_Node (Exp))
22650 and then Nkind_In (Original_Node (Exp), N_Selected_Component,
22651 N_Indexed_Component)
22653 Exp := Prefix (Original_Node (Exp));
22657 -- Generate a reference only if the assignment comes from
22658 -- source. This excludes, for example, calls to a dispatching
22659 -- assignment operation when the left-hand side is tagged. In
22660 -- GNATprove mode, we need those references also on generated
22661 -- code, as these are used to compute the local effects of
22664 if Modification_Comes_From_Source or GNATprove_Mode then
22665 Generate_Reference (Ent, Exp, 'm');
22667 -- If the target of the assignment is the bound variable
22668 -- in an iterator, indicate that the corresponding array
22669 -- or container is also modified.
22671 if Ada_Version >= Ada_2012
22672 and then Nkind (Parent (Ent)) = N_Iterator_Specification
22675 Domain : constant Node_Id := Name (Parent (Ent));
22678 -- TBD : in the full version of the construct, the
22679 -- domain of iteration can be given by an expression.
22681 if Is_Entity_Name (Domain) then
22682 Generate_Reference (Entity (Domain), Exp, 'm');
22683 Set_Is_True_Constant (Entity (Domain), False);
22684 Set_Never_Set_In_Source (Entity (Domain), False);
22693 -- If we are sure this is a modification from source, and we know
22694 -- this modifies a constant, then give an appropriate warning.
22697 and then Modification_Comes_From_Source
22698 and then Overlays_Constant (Ent)
22699 and then Address_Clause_Overlay_Warnings
22702 Addr : constant Node_Id := Address_Clause (Ent);
22707 Find_Overlaid_Entity (Addr, O_Ent, Off);
22709 Error_Msg_Sloc := Sloc (Addr);
22711 ("??constant& may be modified via address clause#",
22722 end Note_Possible_Modification;
22728 function Null_Status (N : Node_Id) return Null_Status_Kind is
22729 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean;
22730 -- Determine whether definition Def carries a null exclusion
22732 function Null_Status_Of_Entity (Id : Entity_Id) return Null_Status_Kind;
22733 -- Determine the null status of arbitrary entity Id
22735 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind;
22736 -- Determine the null status of type Typ
22738 ---------------------------
22739 -- Is_Null_Excluding_Def --
22740 ---------------------------
22742 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean is
22745 Nkind_In (Def, N_Access_Definition,
22746 N_Access_Function_Definition,
22747 N_Access_Procedure_Definition,
22748 N_Access_To_Object_Definition,
22749 N_Component_Definition,
22750 N_Derived_Type_Definition)
22751 and then Null_Exclusion_Present (Def);
22752 end Is_Null_Excluding_Def;
22754 ---------------------------
22755 -- Null_Status_Of_Entity --
22756 ---------------------------
22758 function Null_Status_Of_Entity
22759 (Id : Entity_Id) return Null_Status_Kind
22761 Decl : constant Node_Id := Declaration_Node (Id);
22765 -- The value of an imported or exported entity may be set externally
22766 -- regardless of a null exclusion. As a result, the value cannot be
22767 -- determined statically.
22769 if Is_Imported (Id) or else Is_Exported (Id) then
22772 elsif Nkind_In (Decl, N_Component_Declaration,
22773 N_Discriminant_Specification,
22774 N_Formal_Object_Declaration,
22775 N_Object_Declaration,
22776 N_Object_Renaming_Declaration,
22777 N_Parameter_Specification)
22779 -- A component declaration yields a non-null value when either
22780 -- its component definition or access definition carries a null
22783 if Nkind (Decl) = N_Component_Declaration then
22784 Def := Component_Definition (Decl);
22786 if Is_Null_Excluding_Def (Def) then
22787 return Is_Non_Null;
22790 Def := Access_Definition (Def);
22792 if Present (Def) and then Is_Null_Excluding_Def (Def) then
22793 return Is_Non_Null;
22796 -- A formal object declaration yields a non-null value if its
22797 -- access definition carries a null exclusion. If the object is
22798 -- default initialized, then the value depends on the expression.
22800 elsif Nkind (Decl) = N_Formal_Object_Declaration then
22801 Def := Access_Definition (Decl);
22803 if Present (Def) and then Is_Null_Excluding_Def (Def) then
22804 return Is_Non_Null;
22807 -- A constant may yield a null or non-null value depending on its
22808 -- initialization expression.
22810 elsif Ekind (Id) = E_Constant then
22811 return Null_Status (Constant_Value (Id));
22813 -- The construct yields a non-null value when it has a null
22816 elsif Null_Exclusion_Present (Decl) then
22817 return Is_Non_Null;
22819 -- An object renaming declaration yields a non-null value if its
22820 -- access definition carries a null exclusion. Otherwise the value
22821 -- depends on the renamed name.
22823 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
22824 Def := Access_Definition (Decl);
22826 if Present (Def) and then Is_Null_Excluding_Def (Def) then
22827 return Is_Non_Null;
22830 return Null_Status (Name (Decl));
22835 -- At this point the declaration of the entity does not carry a null
22836 -- exclusion and lacks an initialization expression. Check the status
22839 return Null_Status_Of_Type (Etype (Id));
22840 end Null_Status_Of_Entity;
22842 -------------------------
22843 -- Null_Status_Of_Type --
22844 -------------------------
22846 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind is
22851 -- Traverse the type chain looking for types with null exclusion
22854 while Present (Curr) and then Etype (Curr) /= Curr loop
22855 Decl := Parent (Curr);
22857 -- Guard against itypes which do not always have declarations. A
22858 -- type yields a non-null value if it carries a null exclusion.
22860 if Present (Decl) then
22861 if Nkind (Decl) = N_Full_Type_Declaration
22862 and then Is_Null_Excluding_Def (Type_Definition (Decl))
22864 return Is_Non_Null;
22866 elsif Nkind (Decl) = N_Subtype_Declaration
22867 and then Null_Exclusion_Present (Decl)
22869 return Is_Non_Null;
22873 Curr := Etype (Curr);
22876 -- The type chain does not contain any null excluding types
22879 end Null_Status_Of_Type;
22881 -- Start of processing for Null_Status
22884 -- Prevent cascaded errors or infinite loops when trying to determine
22885 -- the null status of an erroneous construct.
22887 if Error_Posted (N) then
22890 -- An allocator always creates a non-null value
22892 elsif Nkind (N) = N_Allocator then
22893 return Is_Non_Null;
22895 -- Taking the 'Access of something yields a non-null value
22897 elsif Nkind (N) = N_Attribute_Reference
22898 and then Nam_In (Attribute_Name (N), Name_Access,
22899 Name_Unchecked_Access,
22900 Name_Unrestricted_Access)
22902 return Is_Non_Null;
22904 -- "null" yields null
22906 elsif Nkind (N) = N_Null then
22909 -- Check the status of the operand of a type conversion
22911 elsif Nkind (N) = N_Type_Conversion then
22912 return Null_Status (Expression (N));
22914 -- The input denotes a reference to an entity. Determine whether the
22915 -- entity or its type yields a null or non-null value.
22917 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
22918 return Null_Status_Of_Entity (Entity (N));
22921 -- Otherwise it is not possible to determine the null status of the
22922 -- subexpression at compile time without resorting to simple flow
22928 --------------------------------------
22929 -- Null_To_Null_Address_Convert_OK --
22930 --------------------------------------
22932 function Null_To_Null_Address_Convert_OK
22934 Typ : Entity_Id := Empty) return Boolean
22937 if not Relaxed_RM_Semantics then
22941 if Nkind (N) = N_Null then
22942 return Present (Typ) and then Is_Descendant_Of_Address (Typ);
22944 elsif Nkind_In (N, N_Op_Eq, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt, N_Op_Ne)
22947 L : constant Node_Id := Left_Opnd (N);
22948 R : constant Node_Id := Right_Opnd (N);
22951 -- We check the Etype of the complementary operand since the
22952 -- N_Null node is not decorated at this stage.
22955 ((Nkind (L) = N_Null
22956 and then Is_Descendant_Of_Address (Etype (R)))
22958 (Nkind (R) = N_Null
22959 and then Is_Descendant_Of_Address (Etype (L))));
22964 end Null_To_Null_Address_Convert_OK;
22966 ---------------------------------
22967 -- Number_Of_Elements_In_Array --
22968 ---------------------------------
22970 function Number_Of_Elements_In_Array (T : Entity_Id) return Int is
22978 pragma Assert (Is_Array_Type (T));
22980 Indx := First_Index (T);
22981 while Present (Indx) loop
22982 Typ := Underlying_Type (Etype (Indx));
22984 -- Never look at junk bounds of a generic type
22986 if Is_Generic_Type (Typ) then
22990 -- Check the array bounds are known at compile time and return zero
22991 -- if they are not.
22993 Low := Type_Low_Bound (Typ);
22994 High := Type_High_Bound (Typ);
22996 if not Compile_Time_Known_Value (Low) then
22998 elsif not Compile_Time_Known_Value (High) then
23002 Num * UI_To_Int ((Expr_Value (High) - Expr_Value (Low) + 1));
23009 end Number_Of_Elements_In_Array;
23011 -------------------------
23012 -- Object_Access_Level --
23013 -------------------------
23015 -- Returns the static accessibility level of the view denoted by Obj. Note
23016 -- that the value returned is the result of a call to Scope_Depth. Only
23017 -- scope depths associated with dynamic scopes can actually be returned.
23018 -- Since only relative levels matter for accessibility checking, the fact
23019 -- that the distance between successive levels of accessibility is not
23020 -- always one is immaterial (invariant: if level(E2) is deeper than
23021 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
23023 function Object_Access_Level (Obj : Node_Id) return Uint is
23024 function Is_Interface_Conversion (N : Node_Id) return Boolean;
23025 -- Determine whether N is a construct of the form
23026 -- Some_Type (Operand._tag'Address)
23027 -- This construct appears in the context of dispatching calls.
23029 function Reference_To (Obj : Node_Id) return Node_Id;
23030 -- An explicit dereference is created when removing side effects from
23031 -- expressions for constraint checking purposes. In this case a local
23032 -- access type is created for it. The correct access level is that of
23033 -- the original source node. We detect this case by noting that the
23034 -- prefix of the dereference is created by an object declaration whose
23035 -- initial expression is a reference.
23037 -----------------------------
23038 -- Is_Interface_Conversion --
23039 -----------------------------
23041 function Is_Interface_Conversion (N : Node_Id) return Boolean is
23043 return Nkind (N) = N_Unchecked_Type_Conversion
23044 and then Nkind (Expression (N)) = N_Attribute_Reference
23045 and then Attribute_Name (Expression (N)) = Name_Address;
23046 end Is_Interface_Conversion;
23052 function Reference_To (Obj : Node_Id) return Node_Id is
23053 Pref : constant Node_Id := Prefix (Obj);
23055 if Is_Entity_Name (Pref)
23056 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
23057 and then Present (Expression (Parent (Entity (Pref))))
23058 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
23060 return (Prefix (Expression (Parent (Entity (Pref)))));
23070 -- Start of processing for Object_Access_Level
23073 if Nkind (Obj) = N_Defining_Identifier
23074 or else Is_Entity_Name (Obj)
23076 if Nkind (Obj) = N_Defining_Identifier then
23082 if Is_Prival (E) then
23083 E := Prival_Link (E);
23086 -- If E is a type then it denotes a current instance. For this case
23087 -- we add one to the normal accessibility level of the type to ensure
23088 -- that current instances are treated as always being deeper than
23089 -- than the level of any visible named access type (see 3.10.2(21)).
23091 if Is_Type (E) then
23092 return Type_Access_Level (E) + 1;
23094 elsif Present (Renamed_Object (E)) then
23095 return Object_Access_Level (Renamed_Object (E));
23097 -- Similarly, if E is a component of the current instance of a
23098 -- protected type, any instance of it is assumed to be at a deeper
23099 -- level than the type. For a protected object (whose type is an
23100 -- anonymous protected type) its components are at the same level
23101 -- as the type itself.
23103 elsif not Is_Overloadable (E)
23104 and then Ekind (Scope (E)) = E_Protected_Type
23105 and then Comes_From_Source (Scope (E))
23107 return Type_Access_Level (Scope (E)) + 1;
23110 -- Aliased formals of functions take their access level from the
23111 -- point of call, i.e. require a dynamic check. For static check
23112 -- purposes, this is smaller than the level of the subprogram
23113 -- itself. For procedures the aliased makes no difference.
23116 and then Is_Aliased (E)
23117 and then Ekind (Scope (E)) = E_Function
23119 return Type_Access_Level (Etype (E));
23122 return Scope_Depth (Enclosing_Dynamic_Scope (E));
23126 elsif Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
23127 if Is_Access_Type (Etype (Prefix (Obj))) then
23128 return Type_Access_Level (Etype (Prefix (Obj)));
23130 return Object_Access_Level (Prefix (Obj));
23133 elsif Nkind (Obj) = N_Explicit_Dereference then
23135 -- If the prefix is a selected access discriminant then we make a
23136 -- recursive call on the prefix, which will in turn check the level
23137 -- of the prefix object of the selected discriminant.
23139 -- In Ada 2012, if the discriminant has implicit dereference and
23140 -- the context is a selected component, treat this as an object of
23141 -- unknown scope (see below). This is necessary in compile-only mode;
23142 -- otherwise expansion will already have transformed the prefix into
23145 if Nkind (Prefix (Obj)) = N_Selected_Component
23146 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
23148 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
23150 (not Has_Implicit_Dereference
23151 (Entity (Selector_Name (Prefix (Obj))))
23152 or else Nkind (Parent (Obj)) /= N_Selected_Component)
23154 return Object_Access_Level (Prefix (Obj));
23156 -- Detect an interface conversion in the context of a dispatching
23157 -- call. Use the original form of the conversion to find the access
23158 -- level of the operand.
23160 elsif Is_Interface (Etype (Obj))
23161 and then Is_Interface_Conversion (Prefix (Obj))
23162 and then Nkind (Original_Node (Obj)) = N_Type_Conversion
23164 return Object_Access_Level (Original_Node (Obj));
23166 elsif not Comes_From_Source (Obj) then
23168 Ref : constant Node_Id := Reference_To (Obj);
23170 if Present (Ref) then
23171 return Object_Access_Level (Ref);
23173 return Type_Access_Level (Etype (Prefix (Obj)));
23178 return Type_Access_Level (Etype (Prefix (Obj)));
23181 elsif Nkind_In (Obj, N_Type_Conversion, N_Unchecked_Type_Conversion) then
23182 return Object_Access_Level (Expression (Obj));
23184 elsif Nkind (Obj) = N_Function_Call then
23186 -- Function results are objects, so we get either the access level of
23187 -- the function or, in the case of an indirect call, the level of the
23188 -- access-to-subprogram type. (This code is used for Ada 95, but it
23189 -- looks wrong, because it seems that we should be checking the level
23190 -- of the call itself, even for Ada 95. However, using the Ada 2005
23191 -- version of the code causes regressions in several tests that are
23192 -- compiled with -gnat95. ???)
23194 if Ada_Version < Ada_2005 then
23195 if Is_Entity_Name (Name (Obj)) then
23196 return Subprogram_Access_Level (Entity (Name (Obj)));
23198 return Type_Access_Level (Etype (Prefix (Name (Obj))));
23201 -- For Ada 2005, the level of the result object of a function call is
23202 -- defined to be the level of the call's innermost enclosing master.
23203 -- We determine that by querying the depth of the innermost enclosing
23207 Return_Master_Scope_Depth_Of_Call : declare
23208 function Innermost_Master_Scope_Depth
23209 (N : Node_Id) return Uint;
23210 -- Returns the scope depth of the given node's innermost
23211 -- enclosing dynamic scope (effectively the accessibility
23212 -- level of the innermost enclosing master).
23214 ----------------------------------
23215 -- Innermost_Master_Scope_Depth --
23216 ----------------------------------
23218 function Innermost_Master_Scope_Depth
23219 (N : Node_Id) return Uint
23221 Node_Par : Node_Id := Parent (N);
23224 -- Locate the nearest enclosing node (by traversing Parents)
23225 -- that Defining_Entity can be applied to, and return the
23226 -- depth of that entity's nearest enclosing dynamic scope.
23228 while Present (Node_Par) loop
23229 case Nkind (Node_Par) is
23230 when N_Abstract_Subprogram_Declaration
23231 | N_Block_Statement
23233 | N_Component_Declaration
23235 | N_Entry_Declaration
23236 | N_Exception_Declaration
23237 | N_Formal_Object_Declaration
23238 | N_Formal_Package_Declaration
23239 | N_Formal_Subprogram_Declaration
23240 | N_Formal_Type_Declaration
23241 | N_Full_Type_Declaration
23242 | N_Function_Specification
23243 | N_Generic_Declaration
23244 | N_Generic_Instantiation
23245 | N_Implicit_Label_Declaration
23246 | N_Incomplete_Type_Declaration
23247 | N_Loop_Parameter_Specification
23248 | N_Number_Declaration
23249 | N_Object_Declaration
23250 | N_Package_Declaration
23251 | N_Package_Specification
23252 | N_Parameter_Specification
23253 | N_Private_Extension_Declaration
23254 | N_Private_Type_Declaration
23255 | N_Procedure_Specification
23257 | N_Protected_Type_Declaration
23258 | N_Renaming_Declaration
23259 | N_Single_Protected_Declaration
23260 | N_Single_Task_Declaration
23261 | N_Subprogram_Declaration
23262 | N_Subtype_Declaration
23264 | N_Task_Type_Declaration
23267 (Nearest_Dynamic_Scope
23268 (Defining_Entity (Node_Par)));
23270 -- For a return statement within a function, return
23271 -- the depth of the function itself. This is not just
23272 -- a small optimization, but matters when analyzing
23273 -- the expression in an expression function before
23274 -- the body is created.
23276 when N_Simple_Return_Statement =>
23277 if Ekind (Current_Scope) = E_Function then
23278 return Scope_Depth (Current_Scope);
23285 Node_Par := Parent (Node_Par);
23288 pragma Assert (False);
23290 -- Should never reach the following return
23292 return Scope_Depth (Current_Scope) + 1;
23293 end Innermost_Master_Scope_Depth;
23295 -- Start of processing for Return_Master_Scope_Depth_Of_Call
23298 return Innermost_Master_Scope_Depth (Obj);
23299 end Return_Master_Scope_Depth_Of_Call;
23302 -- For convenience we handle qualified expressions, even though they
23303 -- aren't technically object names.
23305 elsif Nkind (Obj) = N_Qualified_Expression then
23306 return Object_Access_Level (Expression (Obj));
23308 -- Ditto for aggregates. They have the level of the temporary that
23309 -- will hold their value.
23311 elsif Nkind (Obj) = N_Aggregate then
23312 return Object_Access_Level (Current_Scope);
23314 -- Otherwise return the scope level of Standard. (If there are cases
23315 -- that fall through to this point they will be treated as having
23316 -- global accessibility for now. ???)
23319 return Scope_Depth (Standard_Standard);
23321 end Object_Access_Level;
23323 ----------------------------------
23324 -- Old_Requires_Transient_Scope --
23325 ----------------------------------
23327 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
23328 Typ : constant Entity_Id := Underlying_Type (Id);
23331 -- This is a private type which is not completed yet. This can only
23332 -- happen in a default expression (of a formal parameter or of a
23333 -- record component). Do not expand transient scope in this case.
23338 -- Do not expand transient scope for non-existent procedure return
23340 elsif Typ = Standard_Void_Type then
23343 -- Elementary types do not require a transient scope
23345 elsif Is_Elementary_Type (Typ) then
23348 -- Generally, indefinite subtypes require a transient scope, since the
23349 -- back end cannot generate temporaries, since this is not a valid type
23350 -- for declaring an object. It might be possible to relax this in the
23351 -- future, e.g. by declaring the maximum possible space for the type.
23353 elsif not Is_Definite_Subtype (Typ) then
23356 -- Functions returning tagged types may dispatch on result so their
23357 -- returned value is allocated on the secondary stack. Controlled
23358 -- type temporaries need finalization.
23360 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
23365 elsif Is_Record_Type (Typ) then
23370 Comp := First_Entity (Typ);
23371 while Present (Comp) loop
23372 if Ekind (Comp) = E_Component then
23374 -- ???It's not clear we need a full recursive call to
23375 -- Old_Requires_Transient_Scope here. Note that the
23376 -- following can't happen.
23378 pragma Assert (Is_Definite_Subtype (Etype (Comp)));
23379 pragma Assert (not Has_Controlled_Component (Etype (Comp)));
23381 if Old_Requires_Transient_Scope (Etype (Comp)) then
23386 Next_Entity (Comp);
23392 -- String literal types never require transient scope
23394 elsif Ekind (Typ) = E_String_Literal_Subtype then
23397 -- Array type. Note that we already know that this is a constrained
23398 -- array, since unconstrained arrays will fail the indefinite test.
23400 elsif Is_Array_Type (Typ) then
23402 -- If component type requires a transient scope, the array does too
23404 if Old_Requires_Transient_Scope (Component_Type (Typ)) then
23407 -- Otherwise, we only need a transient scope if the size depends on
23408 -- the value of one or more discriminants.
23411 return Size_Depends_On_Discriminant (Typ);
23414 -- All other cases do not require a transient scope
23417 pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
23420 end Old_Requires_Transient_Scope;
23422 ---------------------------------
23423 -- Original_Aspect_Pragma_Name --
23424 ---------------------------------
23426 function Original_Aspect_Pragma_Name (N : Node_Id) return Name_Id is
23428 Item_Nam : Name_Id;
23431 pragma Assert (Nkind_In (N, N_Aspect_Specification, N_Pragma));
23435 -- The pragma was generated to emulate an aspect, use the original
23436 -- aspect specification.
23438 if Nkind (Item) = N_Pragma and then From_Aspect_Specification (Item) then
23439 Item := Corresponding_Aspect (Item);
23442 -- Retrieve the name of the aspect/pragma. As assertion pragmas from
23443 -- a generic instantiation might have been rewritten into pragma Check,
23444 -- we look at the original node for Item. Note also that Pre, Pre_Class,
23445 -- Post and Post_Class rewrite their pragma identifier to preserve the
23446 -- original name, so we look at the original node for the identifier.
23447 -- ??? this is kludgey
23449 if Nkind (Item) = N_Pragma then
23451 Chars (Original_Node (Pragma_Identifier (Original_Node (Item))));
23454 pragma Assert (Nkind (Item) = N_Aspect_Specification);
23455 Item_Nam := Chars (Identifier (Item));
23458 -- Deal with 'Class by converting the name to its _XXX form
23460 if Class_Present (Item) then
23461 if Item_Nam = Name_Invariant then
23462 Item_Nam := Name_uInvariant;
23464 elsif Item_Nam = Name_Post then
23465 Item_Nam := Name_uPost;
23467 elsif Item_Nam = Name_Pre then
23468 Item_Nam := Name_uPre;
23470 elsif Nam_In (Item_Nam, Name_Type_Invariant,
23471 Name_Type_Invariant_Class)
23473 Item_Nam := Name_uType_Invariant;
23475 -- Nothing to do for other cases (e.g. a Check that derived from
23476 -- Pre_Class and has the flag set). Also we do nothing if the name
23477 -- is already in special _xxx form.
23483 end Original_Aspect_Pragma_Name;
23485 --------------------------------------
23486 -- Original_Corresponding_Operation --
23487 --------------------------------------
23489 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
23491 Typ : constant Entity_Id := Find_Dispatching_Type (S);
23494 -- If S is an inherited primitive S2 the original corresponding
23495 -- operation of S is the original corresponding operation of S2
23497 if Present (Alias (S))
23498 and then Find_Dispatching_Type (Alias (S)) /= Typ
23500 return Original_Corresponding_Operation (Alias (S));
23502 -- If S overrides an inherited subprogram S2 the original corresponding
23503 -- operation of S is the original corresponding operation of S2
23505 elsif Present (Overridden_Operation (S)) then
23506 return Original_Corresponding_Operation (Overridden_Operation (S));
23508 -- otherwise it is S itself
23513 end Original_Corresponding_Operation;
23515 -------------------
23516 -- Output_Entity --
23517 -------------------
23519 procedure Output_Entity (Id : Entity_Id) is
23523 Scop := Scope (Id);
23525 -- The entity may lack a scope when it is in the process of being
23526 -- analyzed. Use the current scope as an approximation.
23529 Scop := Current_Scope;
23532 Output_Name (Chars (Id), Scop);
23539 procedure Output_Name (Nam : Name_Id; Scop : Entity_Id := Current_Scope) is
23543 (Get_Qualified_Name
23550 ----------------------
23551 -- Policy_In_Effect --
23552 ----------------------
23554 function Policy_In_Effect (Policy : Name_Id) return Name_Id is
23555 function Policy_In_List (List : Node_Id) return Name_Id;
23556 -- Determine the mode of a policy in a N_Pragma list
23558 --------------------
23559 -- Policy_In_List --
23560 --------------------
23562 function Policy_In_List (List : Node_Id) return Name_Id is
23569 while Present (Prag) loop
23570 Arg1 := First (Pragma_Argument_Associations (Prag));
23571 Arg2 := Next (Arg1);
23573 Arg1 := Get_Pragma_Arg (Arg1);
23574 Arg2 := Get_Pragma_Arg (Arg2);
23576 -- The current Check_Policy pragma matches the requested policy or
23577 -- appears in the single argument form (Assertion, policy_id).
23579 if Nam_In (Chars (Arg1), Name_Assertion, Policy) then
23580 return Chars (Arg2);
23583 Prag := Next_Pragma (Prag);
23587 end Policy_In_List;
23593 -- Start of processing for Policy_In_Effect
23596 if not Is_Valid_Assertion_Kind (Policy) then
23597 raise Program_Error;
23600 -- Inspect all policy pragmas that appear within scopes (if any)
23602 Kind := Policy_In_List (Check_Policy_List);
23604 -- Inspect all configuration policy pragmas (if any)
23606 if Kind = No_Name then
23607 Kind := Policy_In_List (Check_Policy_List_Config);
23610 -- The context lacks policy pragmas, determine the mode based on whether
23611 -- assertions are enabled at the configuration level. This ensures that
23612 -- the policy is preserved when analyzing generics.
23614 if Kind = No_Name then
23615 if Assertions_Enabled_Config then
23616 Kind := Name_Check;
23618 Kind := Name_Ignore;
23622 -- In CodePeer mode and GNATprove mode, we need to consider all
23623 -- assertions, unless they are disabled. Force Name_Check on
23624 -- ignored assertions.
23626 if Nam_In (Kind, Name_Ignore, Name_Off)
23627 and then (CodePeer_Mode or GNATprove_Mode)
23629 Kind := Name_Check;
23633 end Policy_In_Effect;
23635 ----------------------------------
23636 -- Predicate_Tests_On_Arguments --
23637 ----------------------------------
23639 function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean is
23641 -- Always test predicates on indirect call
23643 if Ekind (Subp) = E_Subprogram_Type then
23646 -- Do not test predicates on call to generated default Finalize, since
23647 -- we are not interested in whether something we are finalizing (and
23648 -- typically destroying) satisfies its predicates.
23650 elsif Chars (Subp) = Name_Finalize
23651 and then not Comes_From_Source (Subp)
23655 -- Do not test predicates on any internally generated routines
23657 elsif Is_Internal_Name (Chars (Subp)) then
23660 -- Do not test predicates on call to Init_Proc, since if needed the
23661 -- predicate test will occur at some other point.
23663 elsif Is_Init_Proc (Subp) then
23666 -- Do not test predicates on call to predicate function, since this
23667 -- would cause infinite recursion.
23669 elsif Ekind (Subp) = E_Function
23670 and then (Is_Predicate_Function (Subp)
23672 Is_Predicate_Function_M (Subp))
23676 -- For now, no other exceptions
23681 end Predicate_Tests_On_Arguments;
23683 -----------------------
23684 -- Private_Component --
23685 -----------------------
23687 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
23688 Ancestor : constant Entity_Id := Base_Type (Type_Id);
23690 function Trace_Components
23692 Check : Boolean) return Entity_Id;
23693 -- Recursive function that does the work, and checks against circular
23694 -- definition for each subcomponent type.
23696 ----------------------
23697 -- Trace_Components --
23698 ----------------------
23700 function Trace_Components
23702 Check : Boolean) return Entity_Id
23704 Btype : constant Entity_Id := Base_Type (T);
23705 Component : Entity_Id;
23707 Candidate : Entity_Id := Empty;
23710 if Check and then Btype = Ancestor then
23711 Error_Msg_N ("circular type definition", Type_Id);
23715 if Is_Private_Type (Btype) and then not Is_Generic_Type (Btype) then
23716 if Present (Full_View (Btype))
23717 and then Is_Record_Type (Full_View (Btype))
23718 and then not Is_Frozen (Btype)
23720 -- To indicate that the ancestor depends on a private type, the
23721 -- current Btype is sufficient. However, to check for circular
23722 -- definition we must recurse on the full view.
23724 Candidate := Trace_Components (Full_View (Btype), True);
23726 if Candidate = Any_Type then
23736 elsif Is_Array_Type (Btype) then
23737 return Trace_Components (Component_Type (Btype), True);
23739 elsif Is_Record_Type (Btype) then
23740 Component := First_Entity (Btype);
23741 while Present (Component)
23742 and then Comes_From_Source (Component)
23744 -- Skip anonymous types generated by constrained components
23746 if not Is_Type (Component) then
23747 P := Trace_Components (Etype (Component), True);
23749 if Present (P) then
23750 if P = Any_Type then
23758 Next_Entity (Component);
23766 end Trace_Components;
23768 -- Start of processing for Private_Component
23771 return Trace_Components (Type_Id, False);
23772 end Private_Component;
23774 ---------------------------
23775 -- Primitive_Names_Match --
23776 ---------------------------
23778 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
23779 function Non_Internal_Name (E : Entity_Id) return Name_Id;
23780 -- Given an internal name, returns the corresponding non-internal name
23782 ------------------------
23783 -- Non_Internal_Name --
23784 ------------------------
23786 function Non_Internal_Name (E : Entity_Id) return Name_Id is
23788 Get_Name_String (Chars (E));
23789 Name_Len := Name_Len - 1;
23791 end Non_Internal_Name;
23793 -- Start of processing for Primitive_Names_Match
23796 pragma Assert (Present (E1) and then Present (E2));
23798 return Chars (E1) = Chars (E2)
23800 (not Is_Internal_Name (Chars (E1))
23801 and then Is_Internal_Name (Chars (E2))
23802 and then Non_Internal_Name (E2) = Chars (E1))
23804 (not Is_Internal_Name (Chars (E2))
23805 and then Is_Internal_Name (Chars (E1))
23806 and then Non_Internal_Name (E1) = Chars (E2))
23808 (Is_Predefined_Dispatching_Operation (E1)
23809 and then Is_Predefined_Dispatching_Operation (E2)
23810 and then Same_TSS (E1, E2))
23812 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
23813 end Primitive_Names_Match;
23815 -----------------------
23816 -- Process_End_Label --
23817 -----------------------
23819 procedure Process_End_Label
23828 Label_Ref : Boolean;
23829 -- Set True if reference to end label itself is required
23832 -- Gets set to the operator symbol or identifier that references the
23833 -- entity Ent. For the child unit case, this is the identifier from the
23834 -- designator. For other cases, this is simply Endl.
23836 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
23837 -- N is an identifier node that appears as a parent unit reference in
23838 -- the case where Ent is a child unit. This procedure generates an
23839 -- appropriate cross-reference entry. E is the corresponding entity.
23841 -------------------------
23842 -- Generate_Parent_Ref --
23843 -------------------------
23845 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
23847 -- If names do not match, something weird, skip reference
23849 if Chars (E) = Chars (N) then
23851 -- Generate the reference. We do NOT consider this as a reference
23852 -- for unreferenced symbol purposes.
23854 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
23856 if Style_Check then
23857 Style.Check_Identifier (N, E);
23860 end Generate_Parent_Ref;
23862 -- Start of processing for Process_End_Label
23865 -- If no node, ignore. This happens in some error situations, and
23866 -- also for some internally generated structures where no end label
23867 -- references are required in any case.
23873 -- Nothing to do if no End_Label, happens for internally generated
23874 -- constructs where we don't want an end label reference anyway. Also
23875 -- nothing to do if Endl is a string literal, which means there was
23876 -- some prior error (bad operator symbol)
23878 Endl := End_Label (N);
23880 if No (Endl) or else Nkind (Endl) = N_String_Literal then
23884 -- Reference node is not in extended main source unit
23886 if not In_Extended_Main_Source_Unit (N) then
23888 -- Generally we do not collect references except for the extended
23889 -- main source unit. The one exception is the 'e' entry for a
23890 -- package spec, where it is useful for a client to have the
23891 -- ending information to define scopes.
23897 Label_Ref := False;
23899 -- For this case, we can ignore any parent references, but we
23900 -- need the package name itself for the 'e' entry.
23902 if Nkind (Endl) = N_Designator then
23903 Endl := Identifier (Endl);
23907 -- Reference is in extended main source unit
23912 -- For designator, generate references for the parent entries
23914 if Nkind (Endl) = N_Designator then
23916 -- Generate references for the prefix if the END line comes from
23917 -- source (otherwise we do not need these references) We climb the
23918 -- scope stack to find the expected entities.
23920 if Comes_From_Source (Endl) then
23921 Nam := Name (Endl);
23922 Scop := Current_Scope;
23923 while Nkind (Nam) = N_Selected_Component loop
23924 Scop := Scope (Scop);
23925 exit when No (Scop);
23926 Generate_Parent_Ref (Selector_Name (Nam), Scop);
23927 Nam := Prefix (Nam);
23930 if Present (Scop) then
23931 Generate_Parent_Ref (Nam, Scope (Scop));
23935 Endl := Identifier (Endl);
23939 -- If the end label is not for the given entity, then either we have
23940 -- some previous error, or this is a generic instantiation for which
23941 -- we do not need to make a cross-reference in this case anyway. In
23942 -- either case we simply ignore the call.
23944 if Chars (Ent) /= Chars (Endl) then
23948 -- If label was really there, then generate a normal reference and then
23949 -- adjust the location in the end label to point past the name (which
23950 -- should almost always be the semicolon).
23952 Loc := Sloc (Endl);
23954 if Comes_From_Source (Endl) then
23956 -- If a label reference is required, then do the style check and
23957 -- generate an l-type cross-reference entry for the label
23960 if Style_Check then
23961 Style.Check_Identifier (Endl, Ent);
23964 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
23967 -- Set the location to point past the label (normally this will
23968 -- mean the semicolon immediately following the label). This is
23969 -- done for the sake of the 'e' or 't' entry generated below.
23971 Get_Decoded_Name_String (Chars (Endl));
23972 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
23975 -- In SPARK mode, no missing label is allowed for packages and
23976 -- subprogram bodies. Detect those cases by testing whether
23977 -- Process_End_Label was called for a body (Typ = 't') or a package.
23979 if Restriction_Check_Required (SPARK_05)
23980 and then (Typ = 't' or else Ekind (Ent) = E_Package)
23982 Error_Msg_Node_1 := Endl;
23983 Check_SPARK_05_Restriction
23984 ("`END &` required", Endl, Force => True);
23988 -- Now generate the e/t reference
23990 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
23992 -- Restore Sloc, in case modified above, since we have an identifier
23993 -- and the normal Sloc should be left set in the tree.
23995 Set_Sloc (Endl, Loc);
23996 end Process_End_Label;
23998 --------------------------------
23999 -- Propagate_Concurrent_Flags --
24000 --------------------------------
24002 procedure Propagate_Concurrent_Flags
24004 Comp_Typ : Entity_Id)
24007 if Has_Task (Comp_Typ) then
24008 Set_Has_Task (Typ);
24011 if Has_Protected (Comp_Typ) then
24012 Set_Has_Protected (Typ);
24015 if Has_Timing_Event (Comp_Typ) then
24016 Set_Has_Timing_Event (Typ);
24018 end Propagate_Concurrent_Flags;
24020 ------------------------------
24021 -- Propagate_DIC_Attributes --
24022 ------------------------------
24024 procedure Propagate_DIC_Attributes
24026 From_Typ : Entity_Id)
24028 DIC_Proc : Entity_Id;
24031 if Present (Typ) and then Present (From_Typ) then
24032 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
24034 -- Nothing to do if both the source and the destination denote the
24037 if From_Typ = Typ then
24040 -- Nothing to do when the destination denotes an incomplete type
24041 -- because the DIC is associated with the current instance of a
24042 -- private type, thus it can never apply to an incomplete type.
24044 elsif Is_Incomplete_Type (Typ) then
24048 DIC_Proc := DIC_Procedure (From_Typ);
24050 -- The setting of the attributes is intentionally conservative. This
24051 -- prevents accidental clobbering of enabled attributes.
24053 if Has_Inherited_DIC (From_Typ)
24054 and then not Has_Inherited_DIC (Typ)
24056 Set_Has_Inherited_DIC (Typ);
24059 if Has_Own_DIC (From_Typ) and then not Has_Own_DIC (Typ) then
24060 Set_Has_Own_DIC (Typ);
24063 if Present (DIC_Proc) and then No (DIC_Procedure (Typ)) then
24064 Set_DIC_Procedure (Typ, DIC_Proc);
24067 end Propagate_DIC_Attributes;
24069 ------------------------------------
24070 -- Propagate_Invariant_Attributes --
24071 ------------------------------------
24073 procedure Propagate_Invariant_Attributes
24075 From_Typ : Entity_Id)
24077 Full_IP : Entity_Id;
24078 Part_IP : Entity_Id;
24081 if Present (Typ) and then Present (From_Typ) then
24082 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
24084 -- Nothing to do if both the source and the destination denote the
24087 if From_Typ = Typ then
24091 Full_IP := Invariant_Procedure (From_Typ);
24092 Part_IP := Partial_Invariant_Procedure (From_Typ);
24094 -- The setting of the attributes is intentionally conservative. This
24095 -- prevents accidental clobbering of enabled attributes.
24097 if Has_Inheritable_Invariants (From_Typ)
24098 and then not Has_Inheritable_Invariants (Typ)
24100 Set_Has_Inheritable_Invariants (Typ);
24103 if Has_Inherited_Invariants (From_Typ)
24104 and then not Has_Inherited_Invariants (Typ)
24106 Set_Has_Inherited_Invariants (Typ);
24109 if Has_Own_Invariants (From_Typ)
24110 and then not Has_Own_Invariants (Typ)
24112 Set_Has_Own_Invariants (Typ);
24115 if Present (Full_IP) and then No (Invariant_Procedure (Typ)) then
24116 Set_Invariant_Procedure (Typ, Full_IP);
24119 if Present (Part_IP) and then No (Partial_Invariant_Procedure (Typ))
24121 Set_Partial_Invariant_Procedure (Typ, Part_IP);
24124 end Propagate_Invariant_Attributes;
24126 ---------------------------------------
24127 -- Record_Possible_Part_Of_Reference --
24128 ---------------------------------------
24130 procedure Record_Possible_Part_Of_Reference
24131 (Var_Id : Entity_Id;
24134 Encap : constant Entity_Id := Encapsulating_State (Var_Id);
24138 -- The variable is a constituent of a single protected/task type. Such
24139 -- a variable acts as a component of the type and must appear within a
24140 -- specific region (SPARK RM 9(3)). Instead of recording the reference,
24141 -- verify its legality now.
24143 if Present (Encap) and then Is_Single_Concurrent_Object (Encap) then
24144 Check_Part_Of_Reference (Var_Id, Ref);
24146 -- The variable is subject to pragma Part_Of and may eventually become a
24147 -- constituent of a single protected/task type. Record the reference to
24148 -- verify its placement when the contract of the variable is analyzed.
24150 elsif Present (Get_Pragma (Var_Id, Pragma_Part_Of)) then
24151 Refs := Part_Of_References (Var_Id);
24154 Refs := New_Elmt_List;
24155 Set_Part_Of_References (Var_Id, Refs);
24158 Append_Elmt (Ref, Refs);
24160 end Record_Possible_Part_Of_Reference;
24166 function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
24167 Seen : Boolean := False;
24169 function Is_Reference (N : Node_Id) return Traverse_Result;
24170 -- Determine whether node N denotes a reference to Id. If this is the
24171 -- case, set global flag Seen to True and stop the traversal.
24177 function Is_Reference (N : Node_Id) return Traverse_Result is
24179 if Is_Entity_Name (N)
24180 and then Present (Entity (N))
24181 and then Entity (N) = Id
24190 procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
24192 -- Start of processing for Referenced
24195 Inspect_Expression (Expr);
24199 ------------------------------------
24200 -- References_Generic_Formal_Type --
24201 ------------------------------------
24203 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
24205 function Process (N : Node_Id) return Traverse_Result;
24206 -- Process one node in search for generic formal type
24212 function Process (N : Node_Id) return Traverse_Result is
24214 if Nkind (N) in N_Has_Entity then
24216 E : constant Entity_Id := Entity (N);
24218 if Present (E) then
24219 if Is_Generic_Type (E) then
24221 elsif Present (Etype (E))
24222 and then Is_Generic_Type (Etype (E))
24233 function Traverse is new Traverse_Func (Process);
24234 -- Traverse tree to look for generic type
24237 if Inside_A_Generic then
24238 return Traverse (N) = Abandon;
24242 end References_Generic_Formal_Type;
24244 -------------------------------
24245 -- Remove_Entity_And_Homonym --
24246 -------------------------------
24248 procedure Remove_Entity_And_Homonym (Id : Entity_Id) is
24250 Remove_Entity (Id);
24251 Remove_Homonym (Id);
24252 end Remove_Entity_And_Homonym;
24254 --------------------
24255 -- Remove_Homonym --
24256 --------------------
24258 procedure Remove_Homonym (Id : Entity_Id) is
24260 Prev : Entity_Id := Empty;
24263 if Id = Current_Entity (Id) then
24264 if Present (Homonym (Id)) then
24265 Set_Current_Entity (Homonym (Id));
24267 Set_Name_Entity_Id (Chars (Id), Empty);
24271 Hom := Current_Entity (Id);
24272 while Present (Hom) and then Hom /= Id loop
24274 Hom := Homonym (Hom);
24277 -- If Id is not on the homonym chain, nothing to do
24279 if Present (Hom) then
24280 Set_Homonym (Prev, Homonym (Id));
24283 end Remove_Homonym;
24285 ------------------------------
24286 -- Remove_Overloaded_Entity --
24287 ------------------------------
24289 procedure Remove_Overloaded_Entity (Id : Entity_Id) is
24290 procedure Remove_Primitive_Of (Typ : Entity_Id);
24291 -- Remove primitive subprogram Id from the list of primitives that
24292 -- belong to type Typ.
24294 -------------------------
24295 -- Remove_Primitive_Of --
24296 -------------------------
24298 procedure Remove_Primitive_Of (Typ : Entity_Id) is
24302 if Is_Tagged_Type (Typ) then
24303 Prims := Direct_Primitive_Operations (Typ);
24305 if Present (Prims) then
24306 Remove (Prims, Id);
24309 end Remove_Primitive_Of;
24313 Formal : Entity_Id;
24315 -- Start of processing for Remove_Overloaded_Entity
24318 Remove_Entity_And_Homonym (Id);
24320 -- The entity denotes a primitive subprogram. Remove it from the list of
24321 -- primitives of the associated controlling type.
24323 if Ekind_In (Id, E_Function, E_Procedure) and then Is_Primitive (Id) then
24324 Formal := First_Formal (Id);
24325 while Present (Formal) loop
24326 if Is_Controlling_Formal (Formal) then
24327 Remove_Primitive_Of (Etype (Formal));
24331 Next_Formal (Formal);
24334 if Ekind (Id) = E_Function and then Has_Controlling_Result (Id) then
24335 Remove_Primitive_Of (Etype (Id));
24338 end Remove_Overloaded_Entity;
24340 ---------------------
24341 -- Rep_To_Pos_Flag --
24342 ---------------------
24344 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
24346 return New_Occurrence_Of
24347 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
24348 end Rep_To_Pos_Flag;
24350 --------------------
24351 -- Require_Entity --
24352 --------------------
24354 procedure Require_Entity (N : Node_Id) is
24356 if Is_Entity_Name (N) and then No (Entity (N)) then
24357 if Total_Errors_Detected /= 0 then
24358 Set_Entity (N, Any_Id);
24360 raise Program_Error;
24363 end Require_Entity;
24365 ------------------------------
24366 -- Requires_Transient_Scope --
24367 ------------------------------
24369 -- A transient scope is required when variable-sized temporaries are
24370 -- allocated on the secondary stack, or when finalization actions must be
24371 -- generated before the next instruction.
24373 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
24374 Old_Result : constant Boolean := Old_Requires_Transient_Scope (Id);
24377 if Debug_Flag_QQ then
24382 New_Result : constant Boolean := New_Requires_Transient_Scope (Id);
24385 -- Assert that we're not putting things on the secondary stack if we
24386 -- didn't before; we are trying to AVOID secondary stack when
24389 if not Old_Result then
24390 pragma Assert (not New_Result);
24394 if New_Result /= Old_Result then
24395 Results_Differ (Id, Old_Result, New_Result);
24400 end Requires_Transient_Scope;
24402 --------------------
24403 -- Results_Differ --
24404 --------------------
24406 procedure Results_Differ
24412 if False then -- False to disable; True for debugging
24413 Treepr.Print_Tree_Node (Id);
24415 if Old_Val = New_Val then
24416 raise Program_Error;
24419 end Results_Differ;
24421 --------------------------
24422 -- Reset_Analyzed_Flags --
24423 --------------------------
24425 procedure Reset_Analyzed_Flags (N : Node_Id) is
24426 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
24427 -- Function used to reset Analyzed flags in tree. Note that we do
24428 -- not reset Analyzed flags in entities, since there is no need to
24429 -- reanalyze entities, and indeed, it is wrong to do so, since it
24430 -- can result in generating auxiliary stuff more than once.
24432 --------------------
24433 -- Clear_Analyzed --
24434 --------------------
24436 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
24438 if Nkind (N) not in N_Entity then
24439 Set_Analyzed (N, False);
24443 end Clear_Analyzed;
24445 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
24447 -- Start of processing for Reset_Analyzed_Flags
24450 Reset_Analyzed (N);
24451 end Reset_Analyzed_Flags;
24453 ------------------------
24454 -- Restore_SPARK_Mode --
24455 ------------------------
24457 procedure Restore_SPARK_Mode
24458 (Mode : SPARK_Mode_Type;
24462 SPARK_Mode := Mode;
24463 SPARK_Mode_Pragma := Prag;
24464 end Restore_SPARK_Mode;
24466 --------------------------------
24467 -- Returns_Unconstrained_Type --
24468 --------------------------------
24470 function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
24472 return Ekind (Subp) = E_Function
24473 and then not Is_Scalar_Type (Etype (Subp))
24474 and then not Is_Access_Type (Etype (Subp))
24475 and then not Is_Constrained (Etype (Subp));
24476 end Returns_Unconstrained_Type;
24478 ----------------------------
24479 -- Root_Type_Of_Full_View --
24480 ----------------------------
24482 function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id is
24483 Rtyp : constant Entity_Id := Root_Type (T);
24486 -- The root type of the full view may itself be a private type. Keep
24487 -- looking for the ultimate derivation parent.
24489 if Is_Private_Type (Rtyp) and then Present (Full_View (Rtyp)) then
24490 return Root_Type_Of_Full_View (Full_View (Rtyp));
24494 end Root_Type_Of_Full_View;
24496 ---------------------------
24497 -- Safe_To_Capture_Value --
24498 ---------------------------
24500 function Safe_To_Capture_Value
24503 Cond : Boolean := False) return Boolean
24506 -- The only entities for which we track constant values are variables
24507 -- which are not renamings, constants, out parameters, and in out
24508 -- parameters, so check if we have this case.
24510 -- Note: it may seem odd to track constant values for constants, but in
24511 -- fact this routine is used for other purposes than simply capturing
24512 -- the value. In particular, the setting of Known[_Non]_Null.
24514 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
24516 Ekind_In (Ent, E_Constant, E_Out_Parameter, E_In_Out_Parameter)
24520 -- For conditionals, we also allow loop parameters and all formals,
24521 -- including in parameters.
24523 elsif Cond and then Ekind_In (Ent, E_Loop_Parameter, E_In_Parameter) then
24526 -- For all other cases, not just unsafe, but impossible to capture
24527 -- Current_Value, since the above are the only entities which have
24528 -- Current_Value fields.
24534 -- Skip if volatile or aliased, since funny things might be going on in
24535 -- these cases which we cannot necessarily track. Also skip any variable
24536 -- for which an address clause is given, or whose address is taken. Also
24537 -- never capture value of library level variables (an attempt to do so
24538 -- can occur in the case of package elaboration code).
24540 if Treat_As_Volatile (Ent)
24541 or else Is_Aliased (Ent)
24542 or else Present (Address_Clause (Ent))
24543 or else Address_Taken (Ent)
24544 or else (Is_Library_Level_Entity (Ent)
24545 and then Ekind (Ent) = E_Variable)
24550 -- OK, all above conditions are met. We also require that the scope of
24551 -- the reference be the same as the scope of the entity, not counting
24552 -- packages and blocks and loops.
24555 E_Scope : constant Entity_Id := Scope (Ent);
24556 R_Scope : Entity_Id;
24559 R_Scope := Current_Scope;
24560 while R_Scope /= Standard_Standard loop
24561 exit when R_Scope = E_Scope;
24563 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
24566 R_Scope := Scope (R_Scope);
24571 -- We also require that the reference does not appear in a context
24572 -- where it is not sure to be executed (i.e. a conditional context
24573 -- or an exception handler). We skip this if Cond is True, since the
24574 -- capturing of values from conditional tests handles this ok.
24587 -- Seems dubious that case expressions are not handled here ???
24590 while Present (P) loop
24591 if Nkind (P) = N_If_Statement
24592 or else Nkind (P) = N_Case_Statement
24593 or else (Nkind (P) in N_Short_Circuit
24594 and then Desc = Right_Opnd (P))
24595 or else (Nkind (P) = N_If_Expression
24596 and then Desc /= First (Expressions (P)))
24597 or else Nkind (P) = N_Exception_Handler
24598 or else Nkind (P) = N_Selective_Accept
24599 or else Nkind (P) = N_Conditional_Entry_Call
24600 or else Nkind (P) = N_Timed_Entry_Call
24601 or else Nkind (P) = N_Asynchronous_Select
24609 -- A special Ada 2012 case: the original node may be part
24610 -- of the else_actions of a conditional expression, in which
24611 -- case it might not have been expanded yet, and appears in
24612 -- a non-syntactic list of actions. In that case it is clearly
24613 -- not safe to save a value.
24616 and then Is_List_Member (Desc)
24617 and then No (Parent (List_Containing (Desc)))
24625 -- OK, looks safe to set value
24628 end Safe_To_Capture_Value;
24634 function Same_Name (N1, N2 : Node_Id) return Boolean is
24635 K1 : constant Node_Kind := Nkind (N1);
24636 K2 : constant Node_Kind := Nkind (N2);
24639 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
24640 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
24642 return Chars (N1) = Chars (N2);
24644 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
24645 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
24647 return Same_Name (Selector_Name (N1), Selector_Name (N2))
24648 and then Same_Name (Prefix (N1), Prefix (N2));
24659 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
24660 N1 : constant Node_Id := Original_Node (Node1);
24661 N2 : constant Node_Id := Original_Node (Node2);
24662 -- We do the tests on original nodes, since we are most interested
24663 -- in the original source, not any expansion that got in the way.
24665 K1 : constant Node_Kind := Nkind (N1);
24666 K2 : constant Node_Kind := Nkind (N2);
24669 -- First case, both are entities with same entity
24671 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
24673 EN1 : constant Entity_Id := Entity (N1);
24674 EN2 : constant Entity_Id := Entity (N2);
24676 if Present (EN1) and then Present (EN2)
24677 and then (Ekind_In (EN1, E_Variable, E_Constant)
24678 or else Is_Formal (EN1))
24686 -- Second case, selected component with same selector, same record
24688 if K1 = N_Selected_Component
24689 and then K2 = N_Selected_Component
24690 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
24692 return Same_Object (Prefix (N1), Prefix (N2));
24694 -- Third case, indexed component with same subscripts, same array
24696 elsif K1 = N_Indexed_Component
24697 and then K2 = N_Indexed_Component
24698 and then Same_Object (Prefix (N1), Prefix (N2))
24703 E1 := First (Expressions (N1));
24704 E2 := First (Expressions (N2));
24705 while Present (E1) loop
24706 if not Same_Value (E1, E2) then
24717 -- Fourth case, slice of same array with same bounds
24720 and then K2 = N_Slice
24721 and then Nkind (Discrete_Range (N1)) = N_Range
24722 and then Nkind (Discrete_Range (N2)) = N_Range
24723 and then Same_Value (Low_Bound (Discrete_Range (N1)),
24724 Low_Bound (Discrete_Range (N2)))
24725 and then Same_Value (High_Bound (Discrete_Range (N1)),
24726 High_Bound (Discrete_Range (N2)))
24728 return Same_Name (Prefix (N1), Prefix (N2));
24730 -- All other cases, not clearly the same object
24741 function Same_Type (T1, T2 : Entity_Id) return Boolean is
24746 elsif not Is_Constrained (T1)
24747 and then not Is_Constrained (T2)
24748 and then Base_Type (T1) = Base_Type (T2)
24752 -- For now don't bother with case of identical constraints, to be
24753 -- fiddled with later on perhaps (this is only used for optimization
24754 -- purposes, so it is not critical to do a best possible job)
24765 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
24767 if Compile_Time_Known_Value (Node1)
24768 and then Compile_Time_Known_Value (Node2)
24770 -- Handle properly compile-time expressions that are not
24773 if Is_String_Type (Etype (Node1)) then
24774 return Expr_Value_S (Node1) = Expr_Value_S (Node2);
24777 return Expr_Value (Node1) = Expr_Value (Node2);
24780 elsif Same_Object (Node1, Node2) then
24787 --------------------
24788 -- Set_SPARK_Mode --
24789 --------------------
24791 procedure Set_SPARK_Mode (Context : Entity_Id) is
24793 -- Do not consider illegal or partially decorated constructs
24795 if Ekind (Context) = E_Void or else Error_Posted (Context) then
24798 elsif Present (SPARK_Pragma (Context)) then
24800 (Mode => Get_SPARK_Mode_From_Annotation (SPARK_Pragma (Context)),
24801 Prag => SPARK_Pragma (Context));
24803 end Set_SPARK_Mode;
24805 -------------------------
24806 -- Scalar_Part_Present --
24807 -------------------------
24809 function Scalar_Part_Present (Typ : Entity_Id) return Boolean is
24810 Val_Typ : constant Entity_Id := Validated_View (Typ);
24814 if Is_Scalar_Type (Val_Typ) then
24817 elsif Is_Array_Type (Val_Typ) then
24818 return Scalar_Part_Present (Component_Type (Val_Typ));
24820 elsif Is_Record_Type (Val_Typ) then
24821 Field := First_Component_Or_Discriminant (Val_Typ);
24822 while Present (Field) loop
24823 if Scalar_Part_Present (Etype (Field)) then
24827 Next_Component_Or_Discriminant (Field);
24832 end Scalar_Part_Present;
24834 ------------------------
24835 -- Scope_Is_Transient --
24836 ------------------------
24838 function Scope_Is_Transient return Boolean is
24840 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
24841 end Scope_Is_Transient;
24847 function Scope_Within
24848 (Inner : Entity_Id;
24849 Outer : Entity_Id) return Boolean
24855 while Present (Curr) and then Curr /= Standard_Standard loop
24856 Curr := Scope (Curr);
24858 if Curr = Outer then
24861 -- A selective accept body appears within a task type, but the
24862 -- enclosing subprogram is the procedure of the task body.
24864 elsif Ekind (Implementation_Base_Type (Curr)) = E_Task_Type
24866 Outer = Task_Body_Procedure (Implementation_Base_Type (Curr))
24870 -- Ditto for the body of a protected operation
24872 elsif Is_Subprogram (Curr)
24873 and then Outer = Protected_Body_Subprogram (Curr)
24877 -- Outside of its scope, a synchronized type may just be private
24879 elsif Is_Private_Type (Curr)
24880 and then Present (Full_View (Curr))
24881 and then Is_Concurrent_Type (Full_View (Curr))
24883 return Scope_Within (Full_View (Curr), Outer);
24890 --------------------------
24891 -- Scope_Within_Or_Same --
24892 --------------------------
24894 function Scope_Within_Or_Same
24895 (Inner : Entity_Id;
24896 Outer : Entity_Id) return Boolean
24898 Curr : Entity_Id := Inner;
24901 -- Similar to the above, but check for scope identity first
24903 while Present (Curr) and then Curr /= Standard_Standard loop
24904 if Curr = Outer then
24907 elsif Ekind (Implementation_Base_Type (Curr)) = E_Task_Type
24909 Outer = Task_Body_Procedure (Implementation_Base_Type (Curr))
24913 elsif Is_Subprogram (Curr)
24914 and then Outer = Protected_Body_Subprogram (Curr)
24918 elsif Is_Private_Type (Curr)
24919 and then Present (Full_View (Curr))
24921 if Full_View (Curr) = Outer then
24924 return Scope_Within (Full_View (Curr), Outer);
24928 Curr := Scope (Curr);
24932 end Scope_Within_Or_Same;
24934 --------------------
24935 -- Set_Convention --
24936 --------------------
24938 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
24940 Basic_Set_Convention (E, Val);
24943 and then Is_Access_Subprogram_Type (Base_Type (E))
24944 and then Has_Foreign_Convention (E)
24946 Set_Can_Use_Internal_Rep (E, False);
24949 -- If E is an object, including a component, and the type of E is an
24950 -- anonymous access type with no convention set, then also set the
24951 -- convention of the anonymous access type. We do not do this for
24952 -- anonymous protected types, since protected types always have the
24953 -- default convention.
24955 if Present (Etype (E))
24956 and then (Is_Object (E)
24958 -- Allow E_Void (happens for pragma Convention appearing
24959 -- in the middle of a record applying to a component)
24961 or else Ekind (E) = E_Void)
24964 Typ : constant Entity_Id := Etype (E);
24967 if Ekind_In (Typ, E_Anonymous_Access_Type,
24968 E_Anonymous_Access_Subprogram_Type)
24969 and then not Has_Convention_Pragma (Typ)
24971 Basic_Set_Convention (Typ, Val);
24972 Set_Has_Convention_Pragma (Typ);
24974 -- And for the access subprogram type, deal similarly with the
24975 -- designated E_Subprogram_Type, which is always internal.
24977 if Ekind (Typ) = E_Anonymous_Access_Subprogram_Type then
24979 Dtype : constant Entity_Id := Designated_Type (Typ);
24981 if Ekind (Dtype) = E_Subprogram_Type
24982 and then not Has_Convention_Pragma (Dtype)
24984 Basic_Set_Convention (Dtype, Val);
24985 Set_Has_Convention_Pragma (Dtype);
24992 end Set_Convention;
24994 ------------------------
24995 -- Set_Current_Entity --
24996 ------------------------
24998 -- The given entity is to be set as the currently visible definition of its
24999 -- associated name (i.e. the Node_Id associated with its name). All we have
25000 -- to do is to get the name from the identifier, and then set the
25001 -- associated Node_Id to point to the given entity.
25003 procedure Set_Current_Entity (E : Entity_Id) is
25005 Set_Name_Entity_Id (Chars (E), E);
25006 end Set_Current_Entity;
25008 ---------------------------
25009 -- Set_Debug_Info_Needed --
25010 ---------------------------
25012 procedure Set_Debug_Info_Needed (T : Entity_Id) is
25014 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
25015 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
25016 -- Used to set debug info in a related node if not set already
25018 --------------------------------------
25019 -- Set_Debug_Info_Needed_If_Not_Set --
25020 --------------------------------------
25022 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
25024 if Present (E) and then not Needs_Debug_Info (E) then
25025 Set_Debug_Info_Needed (E);
25027 -- For a private type, indicate that the full view also needs
25028 -- debug information.
25031 and then Is_Private_Type (E)
25032 and then Present (Full_View (E))
25034 Set_Debug_Info_Needed (Full_View (E));
25037 end Set_Debug_Info_Needed_If_Not_Set;
25039 -- Start of processing for Set_Debug_Info_Needed
25042 -- Nothing to do if there is no available entity
25047 -- Nothing to do for an entity with suppressed debug information
25049 elsif Debug_Info_Off (T) then
25052 -- Nothing to do for an ignored Ghost entity because the entity will be
25053 -- eliminated from the tree.
25055 elsif Is_Ignored_Ghost_Entity (T) then
25058 -- Nothing to do if entity comes from a predefined file. Library files
25059 -- are compiled without debug information, but inlined bodies of these
25060 -- routines may appear in user code, and debug information on them ends
25061 -- up complicating debugging the user code.
25063 elsif In_Inlined_Body and then In_Predefined_Unit (T) then
25064 Set_Needs_Debug_Info (T, False);
25067 -- Set flag in entity itself. Note that we will go through the following
25068 -- circuitry even if the flag is already set on T. That's intentional,
25069 -- it makes sure that the flag will be set in subsidiary entities.
25071 Set_Needs_Debug_Info (T);
25073 -- Set flag on subsidiary entities if not set already
25075 if Is_Object (T) then
25076 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
25078 elsif Is_Type (T) then
25079 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
25081 if Is_Record_Type (T) then
25083 Ent : Entity_Id := First_Entity (T);
25085 while Present (Ent) loop
25086 Set_Debug_Info_Needed_If_Not_Set (Ent);
25091 -- For a class wide subtype, we also need debug information
25092 -- for the equivalent type.
25094 if Ekind (T) = E_Class_Wide_Subtype then
25095 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
25098 elsif Is_Array_Type (T) then
25099 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
25102 Indx : Node_Id := First_Index (T);
25104 while Present (Indx) loop
25105 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
25106 Indx := Next_Index (Indx);
25110 -- For a packed array type, we also need debug information for
25111 -- the type used to represent the packed array. Conversely, we
25112 -- also need it for the former if we need it for the latter.
25114 if Is_Packed (T) then
25115 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Impl_Type (T));
25118 if Is_Packed_Array_Impl_Type (T) then
25119 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
25122 elsif Is_Access_Type (T) then
25123 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
25125 elsif Is_Private_Type (T) then
25127 FV : constant Entity_Id := Full_View (T);
25130 Set_Debug_Info_Needed_If_Not_Set (FV);
25132 -- If the full view is itself a derived private type, we need
25133 -- debug information on its underlying type.
25136 and then Is_Private_Type (FV)
25137 and then Present (Underlying_Full_View (FV))
25139 Set_Needs_Debug_Info (Underlying_Full_View (FV));
25143 elsif Is_Protected_Type (T) then
25144 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
25146 elsif Is_Scalar_Type (T) then
25148 -- If the subrange bounds are materialized by dedicated constant
25149 -- objects, also include them in the debug info to make sure the
25150 -- debugger can properly use them.
25152 if Present (Scalar_Range (T))
25153 and then Nkind (Scalar_Range (T)) = N_Range
25156 Low_Bnd : constant Node_Id := Type_Low_Bound (T);
25157 High_Bnd : constant Node_Id := Type_High_Bound (T);
25160 if Is_Entity_Name (Low_Bnd) then
25161 Set_Debug_Info_Needed_If_Not_Set (Entity (Low_Bnd));
25164 if Is_Entity_Name (High_Bnd) then
25165 Set_Debug_Info_Needed_If_Not_Set (Entity (High_Bnd));
25171 end Set_Debug_Info_Needed;
25173 ----------------------------
25174 -- Set_Entity_With_Checks --
25175 ----------------------------
25177 procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id) is
25178 Val_Actual : Entity_Id;
25180 Post_Node : Node_Id;
25183 -- Unconditionally set the entity
25185 Set_Entity (N, Val);
25187 -- The node to post on is the selector in the case of an expanded name,
25188 -- and otherwise the node itself.
25190 if Nkind (N) = N_Expanded_Name then
25191 Post_Node := Selector_Name (N);
25196 -- Check for violation of No_Fixed_IO
25198 if Restriction_Check_Required (No_Fixed_IO)
25200 ((RTU_Loaded (Ada_Text_IO)
25201 and then (Is_RTE (Val, RE_Decimal_IO)
25203 Is_RTE (Val, RE_Fixed_IO)))
25206 (RTU_Loaded (Ada_Wide_Text_IO)
25207 and then (Is_RTE (Val, RO_WT_Decimal_IO)
25209 Is_RTE (Val, RO_WT_Fixed_IO)))
25212 (RTU_Loaded (Ada_Wide_Wide_Text_IO)
25213 and then (Is_RTE (Val, RO_WW_Decimal_IO)
25215 Is_RTE (Val, RO_WW_Fixed_IO))))
25217 -- A special extra check, don't complain about a reference from within
25218 -- the Ada.Interrupts package itself!
25220 and then not In_Same_Extended_Unit (N, Val)
25222 Check_Restriction (No_Fixed_IO, Post_Node);
25225 -- Remaining checks are only done on source nodes. Note that we test
25226 -- for violation of No_Fixed_IO even on non-source nodes, because the
25227 -- cases for checking violations of this restriction are instantiations
25228 -- where the reference in the instance has Comes_From_Source False.
25230 if not Comes_From_Source (N) then
25234 -- Check for violation of No_Abort_Statements, which is triggered by
25235 -- call to Ada.Task_Identification.Abort_Task.
25237 if Restriction_Check_Required (No_Abort_Statements)
25238 and then (Is_RTE (Val, RE_Abort_Task))
25240 -- A special extra check, don't complain about a reference from within
25241 -- the Ada.Task_Identification package itself!
25243 and then not In_Same_Extended_Unit (N, Val)
25245 Check_Restriction (No_Abort_Statements, Post_Node);
25248 if Val = Standard_Long_Long_Integer then
25249 Check_Restriction (No_Long_Long_Integers, Post_Node);
25252 -- Check for violation of No_Dynamic_Attachment
25254 if Restriction_Check_Required (No_Dynamic_Attachment)
25255 and then RTU_Loaded (Ada_Interrupts)
25256 and then (Is_RTE (Val, RE_Is_Reserved) or else
25257 Is_RTE (Val, RE_Is_Attached) or else
25258 Is_RTE (Val, RE_Current_Handler) or else
25259 Is_RTE (Val, RE_Attach_Handler) or else
25260 Is_RTE (Val, RE_Exchange_Handler) or else
25261 Is_RTE (Val, RE_Detach_Handler) or else
25262 Is_RTE (Val, RE_Reference))
25264 -- A special extra check, don't complain about a reference from within
25265 -- the Ada.Interrupts package itself!
25267 and then not In_Same_Extended_Unit (N, Val)
25269 Check_Restriction (No_Dynamic_Attachment, Post_Node);
25272 -- Check for No_Implementation_Identifiers
25274 if Restriction_Check_Required (No_Implementation_Identifiers) then
25276 -- We have an implementation defined entity if it is marked as
25277 -- implementation defined, or is defined in a package marked as
25278 -- implementation defined. However, library packages themselves
25279 -- are excluded (we don't want to flag Interfaces itself, just
25280 -- the entities within it).
25282 if (Is_Implementation_Defined (Val)
25284 (Present (Scope (Val))
25285 and then Is_Implementation_Defined (Scope (Val))))
25286 and then not (Ekind_In (Val, E_Package, E_Generic_Package)
25287 and then Is_Library_Level_Entity (Val))
25289 Check_Restriction (No_Implementation_Identifiers, Post_Node);
25293 -- Do the style check
25296 and then not Suppress_Style_Checks (Val)
25297 and then not In_Instance
25299 if Nkind (N) = N_Identifier then
25301 elsif Nkind (N) = N_Expanded_Name then
25302 Nod := Selector_Name (N);
25307 -- A special situation arises for derived operations, where we want
25308 -- to do the check against the parent (since the Sloc of the derived
25309 -- operation points to the derived type declaration itself).
25312 while not Comes_From_Source (Val_Actual)
25313 and then Nkind (Val_Actual) in N_Entity
25314 and then (Ekind (Val_Actual) = E_Enumeration_Literal
25315 or else Is_Subprogram_Or_Generic_Subprogram (Val_Actual))
25316 and then Present (Alias (Val_Actual))
25318 Val_Actual := Alias (Val_Actual);
25321 -- Renaming declarations for generic actuals do not come from source,
25322 -- and have a different name from that of the entity they rename, so
25323 -- there is no style check to perform here.
25325 if Chars (Nod) = Chars (Val_Actual) then
25326 Style.Check_Identifier (Nod, Val_Actual);
25330 Set_Entity (N, Val);
25331 end Set_Entity_With_Checks;
25333 ------------------------------
25334 -- Set_Invalid_Scalar_Value --
25335 ------------------------------
25337 procedure Set_Invalid_Scalar_Value
25338 (Scal_Typ : Float_Scalar_Id;
25341 Slot : Ureal renames Invalid_Floats (Scal_Typ);
25344 -- Detect an attempt to set a different value for the same scalar type
25346 pragma Assert (Slot = No_Ureal);
25348 end Set_Invalid_Scalar_Value;
25350 ------------------------------
25351 -- Set_Invalid_Scalar_Value --
25352 ------------------------------
25354 procedure Set_Invalid_Scalar_Value
25355 (Scal_Typ : Integer_Scalar_Id;
25358 Slot : Uint renames Invalid_Integers (Scal_Typ);
25361 -- Detect an attempt to set a different value for the same scalar type
25363 pragma Assert (Slot = No_Uint);
25365 end Set_Invalid_Scalar_Value;
25367 ------------------------
25368 -- Set_Name_Entity_Id --
25369 ------------------------
25371 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
25373 Set_Name_Table_Int (Id, Int (Val));
25374 end Set_Name_Entity_Id;
25376 ---------------------
25377 -- Set_Next_Actual --
25378 ---------------------
25380 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
25382 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
25383 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
25385 end Set_Next_Actual;
25387 ----------------------------------
25388 -- Set_Optimize_Alignment_Flags --
25389 ----------------------------------
25391 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
25393 if Optimize_Alignment = 'S' then
25394 Set_Optimize_Alignment_Space (E);
25395 elsif Optimize_Alignment = 'T' then
25396 Set_Optimize_Alignment_Time (E);
25398 end Set_Optimize_Alignment_Flags;
25400 -----------------------
25401 -- Set_Public_Status --
25402 -----------------------
25404 procedure Set_Public_Status (Id : Entity_Id) is
25405 S : constant Entity_Id := Current_Scope;
25407 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
25408 -- Determines if E is defined within handled statement sequence or
25409 -- an if statement, returns True if so, False otherwise.
25411 ----------------------
25412 -- Within_HSS_Or_If --
25413 ----------------------
25415 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
25418 N := Declaration_Node (E);
25425 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
25431 end Within_HSS_Or_If;
25433 -- Start of processing for Set_Public_Status
25436 -- Everything in the scope of Standard is public
25438 if S = Standard_Standard then
25439 Set_Is_Public (Id);
25441 -- Entity is definitely not public if enclosing scope is not public
25443 elsif not Is_Public (S) then
25446 -- An object or function declaration that occurs in a handled sequence
25447 -- of statements or within an if statement is the declaration for a
25448 -- temporary object or local subprogram generated by the expander. It
25449 -- never needs to be made public and furthermore, making it public can
25450 -- cause back end problems.
25452 elsif Nkind_In (Parent (Id), N_Object_Declaration,
25453 N_Function_Specification)
25454 and then Within_HSS_Or_If (Id)
25458 -- Entities in public packages or records are public
25460 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
25461 Set_Is_Public (Id);
25463 -- The bounds of an entry family declaration can generate object
25464 -- declarations that are visible to the back-end, e.g. in the
25465 -- the declaration of a composite type that contains tasks.
25467 elsif Is_Concurrent_Type (S)
25468 and then not Has_Completion (S)
25469 and then Nkind (Parent (Id)) = N_Object_Declaration
25471 Set_Is_Public (Id);
25473 end Set_Public_Status;
25475 -----------------------------
25476 -- Set_Referenced_Modified --
25477 -----------------------------
25479 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
25483 -- Deal with indexed or selected component where prefix is modified
25485 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
25486 Pref := Prefix (N);
25488 -- If prefix is access type, then it is the designated object that is
25489 -- being modified, which means we have no entity to set the flag on.
25491 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
25494 -- Otherwise chase the prefix
25497 Set_Referenced_Modified (Pref, Out_Param);
25500 -- Otherwise see if we have an entity name (only other case to process)
25502 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
25503 Set_Referenced_As_LHS (Entity (N), not Out_Param);
25504 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
25506 end Set_Referenced_Modified;
25512 procedure Set_Rep_Info (T1 : Entity_Id; T2 : Entity_Id) is
25514 Set_Is_Atomic (T1, Is_Atomic (T2));
25515 Set_Is_Independent (T1, Is_Independent (T2));
25516 Set_Is_Volatile_Full_Access (T1, Is_Volatile_Full_Access (T2));
25518 if Is_Base_Type (T1) then
25519 Set_Is_Volatile (T1, Is_Volatile (T2));
25523 ----------------------------
25524 -- Set_Scope_Is_Transient --
25525 ----------------------------
25527 procedure Set_Scope_Is_Transient (V : Boolean := True) is
25529 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
25530 end Set_Scope_Is_Transient;
25532 -------------------
25533 -- Set_Size_Info --
25534 -------------------
25536 procedure Set_Size_Info (T1, T2 : Entity_Id) is
25538 -- We copy Esize, but not RM_Size, since in general RM_Size is
25539 -- subtype specific and does not get inherited by all subtypes.
25541 Set_Esize (T1, Esize (T2));
25542 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
25544 if Is_Discrete_Or_Fixed_Point_Type (T1)
25546 Is_Discrete_Or_Fixed_Point_Type (T2)
25548 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
25551 Set_Alignment (T1, Alignment (T2));
25554 ------------------------------
25555 -- Should_Ignore_Pragma_Par --
25556 ------------------------------
25558 function Should_Ignore_Pragma_Par (Prag_Name : Name_Id) return Boolean is
25559 pragma Assert (Compiler_State = Parsing);
25560 -- This one can't work during semantic analysis, because we don't have a
25561 -- correct Current_Source_File.
25563 Result : constant Boolean :=
25564 Get_Name_Table_Boolean3 (Prag_Name)
25565 and then not Is_Internal_File_Name
25566 (File_Name (Current_Source_File));
25569 end Should_Ignore_Pragma_Par;
25571 ------------------------------
25572 -- Should_Ignore_Pragma_Sem --
25573 ------------------------------
25575 function Should_Ignore_Pragma_Sem (N : Node_Id) return Boolean is
25576 pragma Assert (Compiler_State = Analyzing);
25577 Prag_Name : constant Name_Id := Pragma_Name (N);
25578 Result : constant Boolean :=
25579 Get_Name_Table_Boolean3 (Prag_Name)
25580 and then not In_Internal_Unit (N);
25584 end Should_Ignore_Pragma_Sem;
25586 --------------------
25587 -- Static_Boolean --
25588 --------------------
25590 function Static_Boolean (N : Node_Id) return Uint is
25592 Analyze_And_Resolve (N, Standard_Boolean);
25595 or else Error_Posted (N)
25596 or else Etype (N) = Any_Type
25601 if Is_OK_Static_Expression (N) then
25602 if not Raises_Constraint_Error (N) then
25603 return Expr_Value (N);
25608 elsif Etype (N) = Any_Type then
25612 Flag_Non_Static_Expr
25613 ("static boolean expression required here", N);
25616 end Static_Boolean;
25618 --------------------
25619 -- Static_Integer --
25620 --------------------
25622 function Static_Integer (N : Node_Id) return Uint is
25624 Analyze_And_Resolve (N, Any_Integer);
25627 or else Error_Posted (N)
25628 or else Etype (N) = Any_Type
25633 if Is_OK_Static_Expression (N) then
25634 if not Raises_Constraint_Error (N) then
25635 return Expr_Value (N);
25640 elsif Etype (N) = Any_Type then
25644 Flag_Non_Static_Expr
25645 ("static integer expression required here", N);
25648 end Static_Integer;
25650 --------------------------
25651 -- Statically_Different --
25652 --------------------------
25654 function Statically_Different (E1, E2 : Node_Id) return Boolean is
25655 R1 : constant Node_Id := Get_Referenced_Object (E1);
25656 R2 : constant Node_Id := Get_Referenced_Object (E2);
25658 return Is_Entity_Name (R1)
25659 and then Is_Entity_Name (R2)
25660 and then Entity (R1) /= Entity (R2)
25661 and then not Is_Formal (Entity (R1))
25662 and then not Is_Formal (Entity (R2));
25663 end Statically_Different;
25665 --------------------------------------
25666 -- Subject_To_Loop_Entry_Attributes --
25667 --------------------------------------
25669 function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
25675 -- The expansion mechanism transform a loop subject to at least one
25676 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
25677 -- the conditional part.
25679 if Nkind_In (Stmt, N_Block_Statement, N_If_Statement)
25680 and then Nkind (Original_Node (N)) = N_Loop_Statement
25682 Stmt := Original_Node (N);
25686 Nkind (Stmt) = N_Loop_Statement
25687 and then Present (Identifier (Stmt))
25688 and then Present (Entity (Identifier (Stmt)))
25689 and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
25690 end Subject_To_Loop_Entry_Attributes;
25692 -----------------------------
25693 -- Subprogram_Access_Level --
25694 -----------------------------
25696 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
25698 if Present (Alias (Subp)) then
25699 return Subprogram_Access_Level (Alias (Subp));
25701 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
25703 end Subprogram_Access_Level;
25705 ---------------------
25706 -- Subprogram_Name --
25707 ---------------------
25709 function Subprogram_Name (N : Node_Id) return String is
25710 Buf : Bounded_String;
25711 Ent : Node_Id := N;
25715 while Present (Ent) loop
25716 case Nkind (Ent) is
25717 when N_Subprogram_Body =>
25718 Ent := Defining_Unit_Name (Specification (Ent));
25721 when N_Subprogram_Declaration =>
25722 Nod := Corresponding_Body (Ent);
25724 if Present (Nod) then
25727 Ent := Defining_Unit_Name (Specification (Ent));
25732 when N_Subprogram_Instantiation
25734 | N_Package_Specification
25736 Ent := Defining_Unit_Name (Ent);
25739 when N_Protected_Type_Declaration =>
25740 Ent := Corresponding_Body (Ent);
25743 when N_Protected_Body
25746 Ent := Defining_Identifier (Ent);
25753 Ent := Parent (Ent);
25757 return "unknown subprogram:unknown file:0:0";
25760 -- If the subprogram is a child unit, use its simple name to start the
25761 -- construction of the fully qualified name.
25763 if Nkind (Ent) = N_Defining_Program_Unit_Name then
25764 Ent := Defining_Identifier (Ent);
25767 Append_Entity_Name (Buf, Ent);
25769 -- Append homonym number if needed
25771 if Nkind (N) in N_Entity and then Has_Homonym (N) then
25773 H : Entity_Id := Homonym (N);
25777 while Present (H) loop
25778 if Scope (H) = Scope (N) then
25792 -- Append source location of Ent to Buf so that the string will
25793 -- look like "subp:file:line:col".
25796 Loc : constant Source_Ptr := Sloc (Ent);
25799 Append (Buf, Reference_Name (Get_Source_File_Index (Loc)));
25801 Append (Buf, Nat (Get_Logical_Line_Number (Loc)));
25803 Append (Buf, Nat (Get_Column_Number (Loc)));
25807 end Subprogram_Name;
25809 -------------------------------
25810 -- Support_Atomic_Primitives --
25811 -------------------------------
25813 function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
25817 -- Verify the alignment of Typ is known
25819 if not Known_Alignment (Typ) then
25823 if Known_Static_Esize (Typ) then
25824 Size := UI_To_Int (Esize (Typ));
25826 -- If the Esize (Object_Size) is unknown at compile time, look at the
25827 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
25829 elsif Known_Static_RM_Size (Typ) then
25830 Size := UI_To_Int (RM_Size (Typ));
25832 -- Otherwise, the size is considered to be unknown.
25838 -- Check that the size of the component is 8, 16, 32, or 64 bits and
25839 -- that Typ is properly aligned.
25842 when 8 | 16 | 32 | 64 =>
25843 return Size = UI_To_Int (Alignment (Typ)) * 8;
25848 end Support_Atomic_Primitives;
25854 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
25856 if Debug_Flag_W then
25857 for J in 0 .. Scope_Stack.Last loop
25862 Write_Name (Chars (E));
25863 Write_Str (" from ");
25864 Write_Location (Sloc (N));
25869 -----------------------
25870 -- Transfer_Entities --
25871 -----------------------
25873 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
25874 procedure Set_Public_Status_Of (Id : Entity_Id);
25875 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
25876 -- Set_Public_Status. If successful and Id denotes a record type, set
25877 -- the Is_Public attribute of its fields.
25879 --------------------------
25880 -- Set_Public_Status_Of --
25881 --------------------------
25883 procedure Set_Public_Status_Of (Id : Entity_Id) is
25887 if not Is_Public (Id) then
25888 Set_Public_Status (Id);
25890 -- When the input entity is a public record type, ensure that all
25891 -- its internal fields are also exposed to the linker. The fields
25892 -- of a class-wide type are never made public.
25895 and then Is_Record_Type (Id)
25896 and then not Is_Class_Wide_Type (Id)
25898 Field := First_Entity (Id);
25899 while Present (Field) loop
25900 Set_Is_Public (Field);
25901 Next_Entity (Field);
25905 end Set_Public_Status_Of;
25909 Full_Id : Entity_Id;
25912 -- Start of processing for Transfer_Entities
25915 Id := First_Entity (From);
25917 if Present (Id) then
25919 -- Merge the entity chain of the source scope with that of the
25920 -- destination scope.
25922 if Present (Last_Entity (To)) then
25923 Link_Entities (Last_Entity (To), Id);
25925 Set_First_Entity (To, Id);
25928 Set_Last_Entity (To, Last_Entity (From));
25930 -- Inspect the entities of the source scope and update their Scope
25933 while Present (Id) loop
25934 Set_Scope (Id, To);
25935 Set_Public_Status_Of (Id);
25937 -- Handle an internally generated full view for a private type
25939 if Is_Private_Type (Id)
25940 and then Present (Full_View (Id))
25941 and then Is_Itype (Full_View (Id))
25943 Full_Id := Full_View (Id);
25945 Set_Scope (Full_Id, To);
25946 Set_Public_Status_Of (Full_Id);
25952 Set_First_Entity (From, Empty);
25953 Set_Last_Entity (From, Empty);
25955 end Transfer_Entities;
25957 ------------------------
25958 -- Traverse_More_Func --
25959 ------------------------
25961 function Traverse_More_Func (Node : Node_Id) return Traverse_Final_Result is
25963 Processing_Itype : Boolean := False;
25964 -- Set to True while traversing the nodes under an Itype, to prevent
25965 -- looping on Itype handling during that traversal.
25967 function Process_More (N : Node_Id) return Traverse_Result;
25968 -- Wrapper over the Process callback to handle parts of the AST that
25969 -- are not normally traversed as syntactic children.
25971 function Traverse_Rec (N : Node_Id) return Traverse_Final_Result;
25972 -- Main recursive traversal implemented as an instantiation of
25973 -- Traverse_Func over a modified Process callback.
25979 function Process_More (N : Node_Id) return Traverse_Result is
25981 procedure Traverse_More (N : Node_Id;
25982 Res : in out Traverse_Result);
25983 procedure Traverse_More (L : List_Id;
25984 Res : in out Traverse_Result);
25985 -- Traverse a node or list and update the traversal result to value
25986 -- Abandon when needed.
25988 -------------------
25989 -- Traverse_More --
25990 -------------------
25992 procedure Traverse_More (N : Node_Id;
25993 Res : in out Traverse_Result)
25996 -- Do not process any more nodes if Abandon was reached
25998 if Res = Abandon then
26002 if Traverse_Rec (N) = Abandon then
26007 procedure Traverse_More (L : List_Id;
26008 Res : in out Traverse_Result)
26010 N : Node_Id := First (L);
26013 -- Do not process any more nodes if Abandon was reached
26015 if Res = Abandon then
26019 while Present (N) loop
26020 Traverse_More (N, Res);
26028 Result : Traverse_Result;
26030 -- Start of processing for Process_More
26033 -- Initial callback to Process. Return immediately on Skip/Abandon.
26034 -- Otherwise update the value of Node for further processing of
26035 -- non-syntactic children.
26037 Result := Process (N);
26040 when OK => Node := N;
26041 when OK_Orig => Node := Original_Node (N);
26042 when Skip => return Skip;
26043 when Abandon => return Abandon;
26046 -- Process the relevant semantic children which are a logical part of
26047 -- the AST under this node before returning for the processing of
26048 -- syntactic children.
26050 -- Start with all non-syntactic lists of action nodes
26052 case Nkind (Node) is
26053 when N_Component_Association =>
26054 Traverse_More (Loop_Actions (Node), Result);
26056 when N_Elsif_Part =>
26057 Traverse_More (Condition_Actions (Node), Result);
26059 when N_Short_Circuit =>
26060 Traverse_More (Actions (Node), Result);
26062 when N_Case_Expression_Alternative =>
26063 Traverse_More (Actions (Node), Result);
26065 when N_Iterated_Component_Association =>
26066 Traverse_More (Loop_Actions (Node), Result);
26068 when N_Iteration_Scheme =>
26069 Traverse_More (Condition_Actions (Node), Result);
26071 when N_If_Expression =>
26072 Traverse_More (Then_Actions (Node), Result);
26073 Traverse_More (Else_Actions (Node), Result);
26075 -- Various nodes have a field Actions as a syntactic node,
26076 -- so it will be traversed in the regular syntactic traversal.
26078 when N_Compilation_Unit_Aux
26079 | N_Compound_Statement
26080 | N_Expression_With_Actions
26089 -- If Process_Itypes is True, process unattached nodes which come
26090 -- from Itypes. This only concerns currently ranges of scalar
26091 -- (possibly as index) types. This traversal is protected against
26092 -- looping with Processing_Itype.
26095 and then not Processing_Itype
26096 and then Nkind (Node) in N_Has_Etype
26097 and then Present (Etype (Node))
26098 and then Is_Itype (Etype (Node))
26101 Typ : constant Entity_Id := Etype (Node);
26103 Processing_Itype := True;
26105 case Ekind (Typ) is
26106 when Scalar_Kind =>
26107 Traverse_More (Scalar_Range (Typ), Result);
26111 Index : Node_Id := First_Index (Typ);
26114 while Present (Index) loop
26115 if Nkind (Index) in N_Has_Entity then
26116 Rng := Scalar_Range (Entity (Index));
26121 Traverse_More (Rng, Result);
26122 Next_Index (Index);
26129 Processing_Itype := False;
26136 -- Define Traverse_Rec as a renaming of the instantiation, as an
26137 -- instantiation cannot complete a previous spec.
26139 function Traverse_Recursive is new Traverse_Func (Process_More);
26140 function Traverse_Rec (N : Node_Id) return Traverse_Final_Result
26141 renames Traverse_Recursive;
26143 -- Start of processing for Traverse_More_Func
26146 return Traverse_Rec (Node);
26147 end Traverse_More_Func;
26149 ------------------------
26150 -- Traverse_More_Proc --
26151 ------------------------
26153 procedure Traverse_More_Proc (Node : Node_Id) is
26154 function Traverse is new Traverse_More_Func (Process, Process_Itypes);
26155 Discard : Traverse_Final_Result;
26156 pragma Warnings (Off, Discard);
26158 Discard := Traverse (Node);
26159 end Traverse_More_Proc;
26161 -----------------------
26162 -- Type_Access_Level --
26163 -----------------------
26165 function Type_Access_Level (Typ : Entity_Id) return Uint is
26169 Btyp := Base_Type (Typ);
26171 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
26172 -- simply use the level where the type is declared. This is true for
26173 -- stand-alone object declarations, and for anonymous access types
26174 -- associated with components the level is the same as that of the
26175 -- enclosing composite type. However, special treatment is needed for
26176 -- the cases of access parameters, return objects of an anonymous access
26177 -- type, and, in Ada 95, access discriminants of limited types.
26179 if Is_Access_Type (Btyp) then
26180 if Ekind (Btyp) = E_Anonymous_Access_Type then
26182 -- If the type is a nonlocal anonymous access type (such as for
26183 -- an access parameter) we treat it as being declared at the
26184 -- library level to ensure that names such as X.all'access don't
26185 -- fail static accessibility checks.
26187 if not Is_Local_Anonymous_Access (Typ) then
26188 return Scope_Depth (Standard_Standard);
26190 -- If this is a return object, the accessibility level is that of
26191 -- the result subtype of the enclosing function. The test here is
26192 -- little complicated, because we have to account for extended
26193 -- return statements that have been rewritten as blocks, in which
26194 -- case we have to find and the Is_Return_Object attribute of the
26195 -- itype's associated object. It would be nice to find a way to
26196 -- simplify this test, but it doesn't seem worthwhile to add a new
26197 -- flag just for purposes of this test. ???
26199 elsif Ekind (Scope (Btyp)) = E_Return_Statement
26202 and then Nkind (Associated_Node_For_Itype (Btyp)) =
26203 N_Object_Declaration
26204 and then Is_Return_Object
26205 (Defining_Identifier
26206 (Associated_Node_For_Itype (Btyp))))
26212 Scop := Scope (Scope (Btyp));
26213 while Present (Scop) loop
26214 exit when Ekind (Scop) = E_Function;
26215 Scop := Scope (Scop);
26218 -- Treat the return object's type as having the level of the
26219 -- function's result subtype (as per RM05-6.5(5.3/2)).
26221 return Type_Access_Level (Etype (Scop));
26226 Btyp := Root_Type (Btyp);
26228 -- The accessibility level of anonymous access types associated with
26229 -- discriminants is that of the current instance of the type, and
26230 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
26232 -- AI-402: access discriminants have accessibility based on the
26233 -- object rather than the type in Ada 2005, so the above paragraph
26236 -- ??? Needs completion with rules from AI-416
26238 if Ada_Version <= Ada_95
26239 and then Ekind (Typ) = E_Anonymous_Access_Type
26240 and then Present (Associated_Node_For_Itype (Typ))
26241 and then Nkind (Associated_Node_For_Itype (Typ)) =
26242 N_Discriminant_Specification
26244 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
26248 -- Return library level for a generic formal type. This is done because
26249 -- RM(10.3.2) says that "The statically deeper relationship does not
26250 -- apply to ... a descendant of a generic formal type". Rather than
26251 -- checking at each point where a static accessibility check is
26252 -- performed to see if we are dealing with a formal type, this rule is
26253 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
26254 -- return extreme values for a formal type; Deepest_Type_Access_Level
26255 -- returns Int'Last. By calling the appropriate function from among the
26256 -- two, we ensure that the static accessibility check will pass if we
26257 -- happen to run into a formal type. More specifically, we should call
26258 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
26259 -- call occurs as part of a static accessibility check and the error
26260 -- case is the case where the type's level is too shallow (as opposed
26263 if Is_Generic_Type (Root_Type (Btyp)) then
26264 return Scope_Depth (Standard_Standard);
26267 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
26268 end Type_Access_Level;
26270 ------------------------------------
26271 -- Type_Without_Stream_Operation --
26272 ------------------------------------
26274 function Type_Without_Stream_Operation
26276 Op : TSS_Name_Type := TSS_Null) return Entity_Id
26278 BT : constant Entity_Id := Base_Type (T);
26279 Op_Missing : Boolean;
26282 if not Restriction_Active (No_Default_Stream_Attributes) then
26286 if Is_Elementary_Type (T) then
26287 if Op = TSS_Null then
26289 No (TSS (BT, TSS_Stream_Read))
26290 or else No (TSS (BT, TSS_Stream_Write));
26293 Op_Missing := No (TSS (BT, Op));
26302 elsif Is_Array_Type (T) then
26303 return Type_Without_Stream_Operation (Component_Type (T), Op);
26305 elsif Is_Record_Type (T) then
26311 Comp := First_Component (T);
26312 while Present (Comp) loop
26313 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
26315 if Present (C_Typ) then
26319 Next_Component (Comp);
26325 elsif Is_Private_Type (T) and then Present (Full_View (T)) then
26326 return Type_Without_Stream_Operation (Full_View (T), Op);
26330 end Type_Without_Stream_Operation;
26332 ---------------------
26333 -- Ultimate_Prefix --
26334 ---------------------
26336 function Ultimate_Prefix (N : Node_Id) return Node_Id is
26341 while Nkind_In (Pref, N_Explicit_Dereference,
26342 N_Indexed_Component,
26343 N_Selected_Component,
26346 Pref := Prefix (Pref);
26350 end Ultimate_Prefix;
26352 ----------------------------
26353 -- Unique_Defining_Entity --
26354 ----------------------------
26356 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
26358 return Unique_Entity (Defining_Entity (N));
26359 end Unique_Defining_Entity;
26361 -------------------
26362 -- Unique_Entity --
26363 -------------------
26365 function Unique_Entity (E : Entity_Id) return Entity_Id is
26366 U : Entity_Id := E;
26372 if Present (Full_View (E)) then
26373 U := Full_View (E);
26377 if Nkind (Parent (E)) = N_Entry_Body then
26379 Prot_Item : Entity_Id;
26380 Prot_Type : Entity_Id;
26383 if Ekind (E) = E_Entry then
26384 Prot_Type := Scope (E);
26386 -- Bodies of entry families are nested within an extra scope
26387 -- that contains an entry index declaration.
26390 Prot_Type := Scope (Scope (E));
26393 -- A protected type may be declared as a private type, in
26394 -- which case we need to get its full view.
26396 if Is_Private_Type (Prot_Type) then
26397 Prot_Type := Full_View (Prot_Type);
26400 -- Full view may not be present on error, in which case
26401 -- return E by default.
26403 if Present (Prot_Type) then
26404 pragma Assert (Ekind (Prot_Type) = E_Protected_Type);
26406 -- Traverse the entity list of the protected type and
26407 -- locate an entry declaration which matches the entry
26410 Prot_Item := First_Entity (Prot_Type);
26411 while Present (Prot_Item) loop
26412 if Ekind (Prot_Item) in Entry_Kind
26413 and then Corresponding_Body (Parent (Prot_Item)) = E
26419 Next_Entity (Prot_Item);
26425 when Formal_Kind =>
26426 if Present (Spec_Entity (E)) then
26427 U := Spec_Entity (E);
26430 when E_Package_Body =>
26433 if Nkind (P) = N_Defining_Program_Unit_Name then
26437 if Nkind (P) = N_Package_Body
26438 and then Present (Corresponding_Spec (P))
26440 U := Corresponding_Spec (P);
26442 elsif Nkind (P) = N_Package_Body_Stub
26443 and then Present (Corresponding_Spec_Of_Stub (P))
26445 U := Corresponding_Spec_Of_Stub (P);
26448 when E_Protected_Body =>
26451 if Nkind (P) = N_Protected_Body
26452 and then Present (Corresponding_Spec (P))
26454 U := Corresponding_Spec (P);
26456 elsif Nkind (P) = N_Protected_Body_Stub
26457 and then Present (Corresponding_Spec_Of_Stub (P))
26459 U := Corresponding_Spec_Of_Stub (P);
26461 if Is_Single_Protected_Object (U) then
26466 if Is_Private_Type (U) then
26467 U := Full_View (U);
26470 when E_Subprogram_Body =>
26473 if Nkind (P) = N_Defining_Program_Unit_Name then
26479 if Nkind (P) = N_Subprogram_Body
26480 and then Present (Corresponding_Spec (P))
26482 U := Corresponding_Spec (P);
26484 elsif Nkind (P) = N_Subprogram_Body_Stub
26485 and then Present (Corresponding_Spec_Of_Stub (P))
26487 U := Corresponding_Spec_Of_Stub (P);
26489 elsif Nkind (P) = N_Subprogram_Renaming_Declaration then
26490 U := Corresponding_Spec (P);
26493 when E_Task_Body =>
26496 if Nkind (P) = N_Task_Body
26497 and then Present (Corresponding_Spec (P))
26499 U := Corresponding_Spec (P);
26501 elsif Nkind (P) = N_Task_Body_Stub
26502 and then Present (Corresponding_Spec_Of_Stub (P))
26504 U := Corresponding_Spec_Of_Stub (P);
26506 if Is_Single_Task_Object (U) then
26511 if Is_Private_Type (U) then
26512 U := Full_View (U);
26516 if Present (Full_View (E)) then
26517 U := Full_View (E);
26531 function Unique_Name (E : Entity_Id) return String is
26533 -- Local subprograms
26535 function Add_Homonym_Suffix (E : Entity_Id) return String;
26537 function This_Name return String;
26539 ------------------------
26540 -- Add_Homonym_Suffix --
26541 ------------------------
26543 function Add_Homonym_Suffix (E : Entity_Id) return String is
26545 -- Names in E_Subprogram_Body or E_Package_Body entities are not
26546 -- reliable, as they may not include the overloading suffix.
26547 -- Instead, when looking for the name of E or one of its enclosing
26548 -- scope, we get the name of the corresponding Unique_Entity.
26550 U : constant Entity_Id := Unique_Entity (E);
26551 Nam : constant String := Get_Name_String (Chars (U));
26554 -- If E has homonyms but is not fully qualified, as done in
26555 -- GNATprove mode, append the homonym number on the fly. Strip the
26556 -- leading space character in the image of natural numbers. Also do
26557 -- not print the homonym value of 1.
26559 if Has_Homonym (U) then
26561 N : constant Pos := Homonym_Number (U);
26562 S : constant String := N'Img;
26565 return Nam & "__" & S (2 .. S'Last);
26571 end Add_Homonym_Suffix;
26577 function This_Name return String is
26579 return Add_Homonym_Suffix (E);
26584 U : constant Entity_Id := Unique_Entity (E);
26586 -- Start of processing for Unique_Name
26589 if E = Standard_Standard
26590 or else Has_Fully_Qualified_Name (E)
26594 elsif Ekind (E) = E_Enumeration_Literal then
26595 return Unique_Name (Etype (E)) & "__" & This_Name;
26599 S : constant Entity_Id := Scope (U);
26600 pragma Assert (Present (S));
26603 -- Prefix names of predefined types with standard__, but leave
26604 -- names of user-defined packages and subprograms without prefix
26605 -- (even if technically they are nested in the Standard package).
26607 if S = Standard_Standard then
26608 if Ekind (U) = E_Package or else Is_Subprogram (U) then
26611 return Unique_Name (S) & "__" & This_Name;
26614 -- For intances of generic subprograms use the name of the related
26615 -- instance and skip the scope of its wrapper package.
26617 elsif Is_Wrapper_Package (S) then
26618 pragma Assert (Scope (S) = Scope (Related_Instance (S)));
26619 -- Wrapper package and the instantiation are in the same scope
26622 Related_Name : constant String :=
26623 Add_Homonym_Suffix (Related_Instance (S));
26624 Enclosing_Name : constant String :=
26625 Unique_Name (Scope (S)) & "__" & Related_Name;
26628 if Is_Subprogram (U)
26629 and then not Is_Generic_Actual_Subprogram (U)
26631 return Enclosing_Name;
26633 return Enclosing_Name & "__" & This_Name;
26637 elsif Is_Child_Unit (U) then
26638 return Child_Prefix & Unique_Name (S) & "__" & This_Name;
26640 return Unique_Name (S) & "__" & This_Name;
26646 ---------------------
26647 -- Unit_Is_Visible --
26648 ---------------------
26650 function Unit_Is_Visible (U : Entity_Id) return Boolean is
26651 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
26652 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
26654 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
26655 -- For a child unit, check whether unit appears in a with_clause
26658 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
26659 -- Scan the context clause of one compilation unit looking for a
26660 -- with_clause for the unit in question.
26662 ----------------------------
26663 -- Unit_In_Parent_Context --
26664 ----------------------------
26666 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
26668 if Unit_In_Context (Par_Unit) then
26671 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
26672 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
26677 end Unit_In_Parent_Context;
26679 ---------------------
26680 -- Unit_In_Context --
26681 ---------------------
26683 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
26687 Clause := First (Context_Items (Comp_Unit));
26688 while Present (Clause) loop
26689 if Nkind (Clause) = N_With_Clause then
26690 if Library_Unit (Clause) = U then
26693 -- The with_clause may denote a renaming of the unit we are
26694 -- looking for, eg. Text_IO which renames Ada.Text_IO.
26697 Renamed_Entity (Entity (Name (Clause))) =
26698 Defining_Entity (Unit (U))
26708 end Unit_In_Context;
26710 -- Start of processing for Unit_Is_Visible
26713 -- The currrent unit is directly visible
26718 elsif Unit_In_Context (Curr) then
26721 -- If the current unit is a body, check the context of the spec
26723 elsif Nkind (Unit (Curr)) = N_Package_Body
26725 (Nkind (Unit (Curr)) = N_Subprogram_Body
26726 and then not Acts_As_Spec (Unit (Curr)))
26728 if Unit_In_Context (Library_Unit (Curr)) then
26733 -- If the spec is a child unit, examine the parents
26735 if Is_Child_Unit (Curr_Entity) then
26736 if Nkind (Unit (Curr)) in N_Unit_Body then
26738 Unit_In_Parent_Context
26739 (Parent_Spec (Unit (Library_Unit (Curr))));
26741 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
26747 end Unit_Is_Visible;
26749 ------------------------------
26750 -- Universal_Interpretation --
26751 ------------------------------
26753 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
26754 Index : Interp_Index;
26758 -- The argument may be a formal parameter of an operator or subprogram
26759 -- with multiple interpretations, or else an expression for an actual.
26761 if Nkind (Opnd) = N_Defining_Identifier
26762 or else not Is_Overloaded (Opnd)
26764 if Etype (Opnd) = Universal_Integer
26765 or else Etype (Opnd) = Universal_Real
26767 return Etype (Opnd);
26773 Get_First_Interp (Opnd, Index, It);
26774 while Present (It.Typ) loop
26775 if It.Typ = Universal_Integer
26776 or else It.Typ = Universal_Real
26781 Get_Next_Interp (Index, It);
26786 end Universal_Interpretation;
26792 function Unqualify (Expr : Node_Id) return Node_Id is
26794 -- Recurse to handle unlikely case of multiple levels of qualification
26796 if Nkind (Expr) = N_Qualified_Expression then
26797 return Unqualify (Expression (Expr));
26799 -- Normal case, not a qualified expression
26810 function Unqual_Conv (Expr : Node_Id) return Node_Id is
26812 -- Recurse to handle unlikely case of multiple levels of qualification
26813 -- and/or conversion.
26815 if Nkind_In (Expr, N_Qualified_Expression,
26817 N_Unchecked_Type_Conversion)
26819 return Unqual_Conv (Expression (Expr));
26821 -- Normal case, not a qualified expression
26828 --------------------
26829 -- Validated_View --
26830 --------------------
26832 function Validated_View (Typ : Entity_Id) return Entity_Id is
26833 Continue : Boolean;
26834 Val_Typ : Entity_Id;
26838 Val_Typ := Base_Type (Typ);
26840 -- Obtain the full view of the input type by stripping away concurrency,
26841 -- derivations, and privacy.
26843 while Continue loop
26846 if Is_Concurrent_Type (Val_Typ) then
26847 if Present (Corresponding_Record_Type (Val_Typ)) then
26849 Val_Typ := Corresponding_Record_Type (Val_Typ);
26852 elsif Is_Derived_Type (Val_Typ) then
26854 Val_Typ := Etype (Val_Typ);
26856 elsif Is_Private_Type (Val_Typ) then
26857 if Present (Underlying_Full_View (Val_Typ)) then
26859 Val_Typ := Underlying_Full_View (Val_Typ);
26861 elsif Present (Full_View (Val_Typ)) then
26863 Val_Typ := Full_View (Val_Typ);
26869 end Validated_View;
26871 -----------------------
26872 -- Visible_Ancestors --
26873 -----------------------
26875 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
26881 pragma Assert (Is_Record_Type (Typ) and then Is_Tagged_Type (Typ));
26883 -- Collect all the parents and progenitors of Typ. If the full-view of
26884 -- private parents and progenitors is available then it is used to
26885 -- generate the list of visible ancestors; otherwise their partial
26886 -- view is added to the resulting list.
26891 Use_Full_View => True);
26895 Ifaces_List => List_2,
26896 Exclude_Parents => True,
26897 Use_Full_View => True);
26899 -- Join the two lists. Avoid duplications because an interface may
26900 -- simultaneously be parent and progenitor of a type.
26902 Elmt := First_Elmt (List_2);
26903 while Present (Elmt) loop
26904 Append_Unique_Elmt (Node (Elmt), List_1);
26909 end Visible_Ancestors;
26911 ----------------------
26912 -- Within_Init_Proc --
26913 ----------------------
26915 function Within_Init_Proc return Boolean is
26919 S := Current_Scope;
26920 while not Is_Overloadable (S) loop
26921 if S = Standard_Standard then
26928 return Is_Init_Proc (S);
26929 end Within_Init_Proc;
26931 ---------------------------
26932 -- Within_Protected_Type --
26933 ---------------------------
26935 function Within_Protected_Type (E : Entity_Id) return Boolean is
26936 Scop : Entity_Id := Scope (E);
26939 while Present (Scop) loop
26940 if Ekind (Scop) = E_Protected_Type then
26944 Scop := Scope (Scop);
26948 end Within_Protected_Type;
26954 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
26956 return Scope_Within_Or_Same (Scope (E), S);
26959 ----------------------------
26960 -- Within_Subprogram_Call --
26961 ----------------------------
26963 function Within_Subprogram_Call (N : Node_Id) return Boolean is
26967 -- Climb the parent chain looking for a function or procedure call
26970 while Present (Par) loop
26971 if Nkind_In (Par, N_Entry_Call_Statement,
26973 N_Procedure_Call_Statement)
26977 -- Prevent the search from going too far
26979 elsif Is_Body_Or_Package_Declaration (Par) then
26983 Par := Parent (Par);
26987 end Within_Subprogram_Call;
26993 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
26994 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
26995 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
26997 Matching_Field : Entity_Id;
26998 -- Entity to give a more precise suggestion on how to write a one-
26999 -- element positional aggregate.
27001 function Has_One_Matching_Field return Boolean;
27002 -- Determines if Expec_Type is a record type with a single component or
27003 -- discriminant whose type matches the found type or is one dimensional
27004 -- array whose component type matches the found type. In the case of
27005 -- one discriminant, we ignore the variant parts. That's not accurate,
27006 -- but good enough for the warning.
27008 ----------------------------
27009 -- Has_One_Matching_Field --
27010 ----------------------------
27012 function Has_One_Matching_Field return Boolean is
27016 Matching_Field := Empty;
27018 if Is_Array_Type (Expec_Type)
27019 and then Number_Dimensions (Expec_Type) = 1
27020 and then Covers (Etype (Component_Type (Expec_Type)), Found_Type)
27022 -- Use type name if available. This excludes multidimensional
27023 -- arrays and anonymous arrays.
27025 if Comes_From_Source (Expec_Type) then
27026 Matching_Field := Expec_Type;
27028 -- For an assignment, use name of target
27030 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
27031 and then Is_Entity_Name (Name (Parent (Expr)))
27033 Matching_Field := Entity (Name (Parent (Expr)));
27038 elsif not Is_Record_Type (Expec_Type) then
27042 E := First_Entity (Expec_Type);
27047 elsif not Ekind_In (E, E_Discriminant, E_Component)
27048 or else Nam_In (Chars (E), Name_uTag, Name_uParent)
27057 if not Covers (Etype (E), Found_Type) then
27060 elsif Present (Next_Entity (E))
27061 and then (Ekind (E) = E_Component
27062 or else Ekind (Next_Entity (E)) = E_Discriminant)
27067 Matching_Field := E;
27071 end Has_One_Matching_Field;
27073 -- Start of processing for Wrong_Type
27076 -- Don't output message if either type is Any_Type, or if a message
27077 -- has already been posted for this node. We need to do the latter
27078 -- check explicitly (it is ordinarily done in Errout), because we
27079 -- are using ! to force the output of the error messages.
27081 if Expec_Type = Any_Type
27082 or else Found_Type = Any_Type
27083 or else Error_Posted (Expr)
27087 -- If one of the types is a Taft-Amendment type and the other it its
27088 -- completion, it must be an illegal use of a TAT in the spec, for
27089 -- which an error was already emitted. Avoid cascaded errors.
27091 elsif Is_Incomplete_Type (Expec_Type)
27092 and then Has_Completion_In_Body (Expec_Type)
27093 and then Full_View (Expec_Type) = Etype (Expr)
27097 elsif Is_Incomplete_Type (Etype (Expr))
27098 and then Has_Completion_In_Body (Etype (Expr))
27099 and then Full_View (Etype (Expr)) = Expec_Type
27103 -- In an instance, there is an ongoing problem with completion of
27104 -- types derived from private types. Their structure is what Gigi
27105 -- expects, but the Etype is the parent type rather than the
27106 -- derived private type itself. Do not flag error in this case. The
27107 -- private completion is an entity without a parent, like an Itype.
27108 -- Similarly, full and partial views may be incorrect in the instance.
27109 -- There is no simple way to insure that it is consistent ???
27111 -- A similar view discrepancy can happen in an inlined body, for the
27112 -- same reason: inserted body may be outside of the original package
27113 -- and only partial views are visible at the point of insertion.
27115 -- If In_Generic_Actual (Expr) is True then we cannot assume that
27116 -- the successful semantic analysis of the generic guarantees anything
27117 -- useful about type checking of this instance, so we ignore
27118 -- In_Instance in that case. There may be cases where this is not
27119 -- right (the symptom would probably be rejecting something
27120 -- that ought to be accepted) but we don't currently have any
27121 -- concrete examples of this.
27123 elsif (In_Instance and then not In_Generic_Actual (Expr))
27124 or else In_Inlined_Body
27126 if Etype (Etype (Expr)) = Etype (Expected_Type)
27128 (Has_Private_Declaration (Expected_Type)
27129 or else Has_Private_Declaration (Etype (Expr)))
27130 and then No (Parent (Expected_Type))
27134 elsif Nkind (Parent (Expr)) = N_Qualified_Expression
27135 and then Entity (Subtype_Mark (Parent (Expr))) = Expected_Type
27139 elsif Is_Private_Type (Expected_Type)
27140 and then Present (Full_View (Expected_Type))
27141 and then Covers (Full_View (Expected_Type), Etype (Expr))
27145 -- Conversely, type of expression may be the private one
27147 elsif Is_Private_Type (Base_Type (Etype (Expr)))
27148 and then Full_View (Base_Type (Etype (Expr))) = Expected_Type
27154 -- An interesting special check. If the expression is parenthesized
27155 -- and its type corresponds to the type of the sole component of the
27156 -- expected record type, or to the component type of the expected one
27157 -- dimensional array type, then assume we have a bad aggregate attempt.
27159 if Nkind (Expr) in N_Subexpr
27160 and then Paren_Count (Expr) /= 0
27161 and then Has_One_Matching_Field
27163 Error_Msg_N ("positional aggregate cannot have one component", Expr);
27165 if Present (Matching_Field) then
27166 if Is_Array_Type (Expec_Type) then
27168 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
27171 ("\write instead `& ='> ...`", Expr, Matching_Field);
27175 -- Another special check, if we are looking for a pool-specific access
27176 -- type and we found an E_Access_Attribute_Type, then we have the case
27177 -- of an Access attribute being used in a context which needs a pool-
27178 -- specific type, which is never allowed. The one extra check we make
27179 -- is that the expected designated type covers the Found_Type.
27181 elsif Is_Access_Type (Expec_Type)
27182 and then Ekind (Found_Type) = E_Access_Attribute_Type
27183 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
27184 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
27186 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
27188 Error_Msg_N -- CODEFIX
27189 ("result must be general access type!", Expr);
27190 Error_Msg_NE -- CODEFIX
27191 ("add ALL to }!", Expr, Expec_Type);
27193 -- Another special check, if the expected type is an integer type,
27194 -- but the expression is of type System.Address, and the parent is
27195 -- an addition or subtraction operation whose left operand is the
27196 -- expression in question and whose right operand is of an integral
27197 -- type, then this is an attempt at address arithmetic, so give
27198 -- appropriate message.
27200 elsif Is_Integer_Type (Expec_Type)
27201 and then Is_RTE (Found_Type, RE_Address)
27202 and then Nkind_In (Parent (Expr), N_Op_Add, N_Op_Subtract)
27203 and then Expr = Left_Opnd (Parent (Expr))
27204 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
27207 ("address arithmetic not predefined in package System",
27210 ("\possible missing with/use of System.Storage_Elements",
27214 -- If the expected type is an anonymous access type, as for access
27215 -- parameters and discriminants, the error is on the designated types.
27217 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
27218 if Comes_From_Source (Expec_Type) then
27219 Error_Msg_NE ("expected}!", Expr, Expec_Type);
27222 ("expected an access type with designated}",
27223 Expr, Designated_Type (Expec_Type));
27226 if Is_Access_Type (Found_Type)
27227 and then not Comes_From_Source (Found_Type)
27230 ("\\found an access type with designated}!",
27231 Expr, Designated_Type (Found_Type));
27233 if From_Limited_With (Found_Type) then
27234 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
27235 Error_Msg_Qual_Level := 99;
27236 Error_Msg_NE -- CODEFIX
27237 ("\\missing `WITH &;", Expr, Scope (Found_Type));
27238 Error_Msg_Qual_Level := 0;
27240 Error_Msg_NE ("found}!", Expr, Found_Type);
27244 -- Normal case of one type found, some other type expected
27247 -- If the names of the two types are the same, see if some number
27248 -- of levels of qualification will help. Don't try more than three
27249 -- levels, and if we get to standard, it's no use (and probably
27250 -- represents an error in the compiler) Also do not bother with
27251 -- internal scope names.
27254 Expec_Scope : Entity_Id;
27255 Found_Scope : Entity_Id;
27258 Expec_Scope := Expec_Type;
27259 Found_Scope := Found_Type;
27261 for Levels in Nat range 0 .. 3 loop
27262 if Chars (Expec_Scope) /= Chars (Found_Scope) then
27263 Error_Msg_Qual_Level := Levels;
27267 Expec_Scope := Scope (Expec_Scope);
27268 Found_Scope := Scope (Found_Scope);
27270 exit when Expec_Scope = Standard_Standard
27271 or else Found_Scope = Standard_Standard
27272 or else not Comes_From_Source (Expec_Scope)
27273 or else not Comes_From_Source (Found_Scope);
27277 if Is_Record_Type (Expec_Type)
27278 and then Present (Corresponding_Remote_Type (Expec_Type))
27280 Error_Msg_NE ("expected}!", Expr,
27281 Corresponding_Remote_Type (Expec_Type));
27283 Error_Msg_NE ("expected}!", Expr, Expec_Type);
27286 if Is_Entity_Name (Expr)
27287 and then Is_Package_Or_Generic_Package (Entity (Expr))
27289 Error_Msg_N ("\\found package name!", Expr);
27291 elsif Is_Entity_Name (Expr)
27292 and then Ekind_In (Entity (Expr), E_Procedure, E_Generic_Procedure)
27294 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
27296 ("found procedure name, possibly missing Access attribute!",
27300 ("\\found procedure name instead of function!", Expr);
27303 elsif Nkind (Expr) = N_Function_Call
27304 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
27305 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
27306 and then No (Parameter_Associations (Expr))
27309 ("found function name, possibly missing Access attribute!",
27312 -- Catch common error: a prefix or infix operator which is not
27313 -- directly visible because the type isn't.
27315 elsif Nkind (Expr) in N_Op
27316 and then Is_Overloaded (Expr)
27317 and then not Is_Immediately_Visible (Expec_Type)
27318 and then not Is_Potentially_Use_Visible (Expec_Type)
27319 and then not In_Use (Expec_Type)
27320 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
27323 ("operator of the type is not directly visible!", Expr);
27325 elsif Ekind (Found_Type) = E_Void
27326 and then Present (Parent (Found_Type))
27327 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
27329 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
27332 Error_Msg_NE ("\\found}!", Expr, Found_Type);
27335 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
27336 -- of the same modular type, and (M1 and M2) = 0 was intended.
27338 if Expec_Type = Standard_Boolean
27339 and then Is_Modular_Integer_Type (Found_Type)
27340 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
27341 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
27344 Op : constant Node_Id := Right_Opnd (Parent (Expr));
27345 L : constant Node_Id := Left_Opnd (Op);
27346 R : constant Node_Id := Right_Opnd (Op);
27349 -- The case for the message is when the left operand of the
27350 -- comparison is the same modular type, or when it is an
27351 -- integer literal (or other universal integer expression),
27352 -- which would have been typed as the modular type if the
27353 -- parens had been there.
27355 if (Etype (L) = Found_Type
27357 Etype (L) = Universal_Integer)
27358 and then Is_Integer_Type (Etype (R))
27361 ("\\possible missing parens for modular operation", Expr);
27366 -- Reset error message qualification indication
27368 Error_Msg_Qual_Level := 0;
27372 --------------------------------
27373 -- Yields_Synchronized_Object --
27374 --------------------------------
27376 function Yields_Synchronized_Object (Typ : Entity_Id) return Boolean is
27377 Has_Sync_Comp : Boolean := False;
27381 -- An array type yields a synchronized object if its component type
27382 -- yields a synchronized object.
27384 if Is_Array_Type (Typ) then
27385 return Yields_Synchronized_Object (Component_Type (Typ));
27387 -- A descendant of type Ada.Synchronous_Task_Control.Suspension_Object
27388 -- yields a synchronized object by default.
27390 elsif Is_Descendant_Of_Suspension_Object (Typ) then
27393 -- A protected type yields a synchronized object by default
27395 elsif Is_Protected_Type (Typ) then
27398 -- A record type or type extension yields a synchronized object when its
27399 -- discriminants (if any) lack default values and all components are of
27400 -- a type that yields a synchronized object.
27402 elsif Is_Record_Type (Typ) then
27404 -- Inspect all entities defined in the scope of the type, looking for
27405 -- components of a type that does not yield a synchronized object or
27406 -- for discriminants with default values.
27408 Id := First_Entity (Typ);
27409 while Present (Id) loop
27410 if Comes_From_Source (Id) then
27411 if Ekind (Id) = E_Component then
27412 if Yields_Synchronized_Object (Etype (Id)) then
27413 Has_Sync_Comp := True;
27415 -- The component does not yield a synchronized object
27421 elsif Ekind (Id) = E_Discriminant
27422 and then Present (Expression (Parent (Id)))
27431 -- Ensure that the parent type of a type extension yields a
27432 -- synchronized object.
27434 if Etype (Typ) /= Typ
27435 and then not Is_Private_Type (Etype (Typ))
27436 and then not Yields_Synchronized_Object (Etype (Typ))
27441 -- If we get here, then all discriminants lack default values and all
27442 -- components are of a type that yields a synchronized object.
27444 return Has_Sync_Comp;
27446 -- A synchronized interface type yields a synchronized object by default
27448 elsif Is_Synchronized_Interface (Typ) then
27451 -- A task type yields a synchronized object by default
27453 elsif Is_Task_Type (Typ) then
27456 -- A private type yields a synchronized object if its underlying type
27459 elsif Is_Private_Type (Typ)
27460 and then Present (Underlying_Type (Typ))
27462 return Yields_Synchronized_Object (Underlying_Type (Typ));
27464 -- Otherwise the type does not yield a synchronized object
27469 end Yields_Synchronized_Object;
27471 ---------------------------
27472 -- Yields_Universal_Type --
27473 ---------------------------
27475 function Yields_Universal_Type (N : Node_Id) return Boolean is
27477 -- Integer and real literals are of a universal type
27479 if Nkind_In (N, N_Integer_Literal, N_Real_Literal) then
27482 -- The values of certain attributes are of a universal type
27484 elsif Nkind (N) = N_Attribute_Reference then
27486 Universal_Type_Attribute (Get_Attribute_Id (Attribute_Name (N)));
27488 -- ??? There are possibly other cases to consider
27493 end Yields_Universal_Type;
27495 package body Interval_Lists is
27497 function In_Interval
27498 (Value : Uint; Interval : Discrete_Interval) return Boolean;
27499 -- Does the given value lie within the given interval?
27504 function In_Interval
27505 (Value : Uint; Interval : Discrete_Interval) return Boolean is
27507 return Value >= Interval.Low and then Value <= Interval.High;
27510 procedure Check_Consistency (Intervals : Discrete_Interval_List);
27511 -- Check that list is sorted, lacks null intervals, and has gaps
27512 -- between intervals.
27514 ------------------------
27515 -- Check_Consistency --
27516 ------------------------
27517 procedure Check_Consistency (Intervals : Discrete_Interval_List) is
27519 if Serious_Errors_Detected > 0 then
27523 -- low bound is 1 and high bound equals length
27524 pragma Assert (Intervals'First = 1 and Intervals'Last >= 0);
27525 for Idx in Intervals'Range loop
27526 -- each interval is non-null
27527 pragma Assert (Intervals (Idx).Low <= Intervals (Idx).High);
27528 if Idx /= Intervals'First then
27529 -- intervals are sorted with non-empty gaps between them
27531 (Intervals (Idx - 1).High < (Intervals (Idx).Low - 1));
27535 end Check_Consistency;
27537 function Chosen_Interval (Choice : Node_Id) return Discrete_Interval;
27538 -- Given an element of a Discrete_Choices list, a
27539 -- Static_Discrete_Predicate list, or an Others_Discrete_Choices
27540 -- list (but not an N_Others_Choice node) return the corresponding
27541 -- interval. If an element that does not represent a single
27542 -- contiguous interval due to a static predicate (or which
27543 -- represents a single contiguous interval whose bounds depend on
27544 -- a static predicate) is encountered, then that is an error on the
27545 -- part of whoever built the list in question.
27547 ---------------------
27548 -- Chosen_Interval --
27549 ---------------------
27550 function Chosen_Interval (Choice : Node_Id) return Discrete_Interval is
27552 case Nkind (Choice) is
27554 return (Low => Expr_Value (Low_Bound (Choice)),
27555 High => Expr_Value (High_Bound (Choice)));
27557 when N_Subtype_Indication =>
27559 Range_Exp : constant Node_Id
27560 := Range_Expression (Constraint (Choice));
27562 return (Low => Expr_Value (Low_Bound (Range_Exp)),
27563 High => Expr_Value (High_Bound (Range_Exp)));
27566 when N_Others_Choice =>
27567 raise Program_Error;
27570 if Is_Entity_Name (Choice) and then Is_Type (Entity (Choice))
27573 (Low => Expr_Value (Type_Low_Bound (Entity (Choice))),
27574 High => Expr_Value (Type_High_Bound (Entity (Choice))));
27577 return (Low | High => Expr_Value (Choice));
27580 end Chosen_Interval;
27582 --------------------
27583 -- Type_Intervals --
27584 --------------------
27585 function Type_Intervals
27586 (Typ : Entity_Id) return Discrete_Interval_List
27589 if Has_Static_Predicate (Typ) then
27591 -- No sorting or merging needed
27592 SDP_List : constant List_Id := Static_Discrete_Predicate (Typ);
27593 Range_Or_Expr : Node_Id := First (SDP_List);
27595 Discrete_Interval_List (1 .. List_Length (SDP_List));
27597 for Idx in Result'Range loop
27598 Result (Idx) := Chosen_Interval (Range_Or_Expr);
27599 Range_Or_Expr := Next (Range_Or_Expr);
27601 pragma Assert (not Present (Range_Or_Expr));
27602 Check_Consistency (Result);
27607 Low : constant Uint := Expr_Value (Type_Low_Bound (Typ));
27608 High : constant Uint := Expr_Value (Type_High_Bound (Typ));
27612 Null_Array : Discrete_Interval_List (1 .. 0);
27617 return (1 => (Low => Low, High => High));
27621 end Type_Intervals;
27623 procedure Normalize_Interval_List
27624 (List : in out Discrete_Interval_List; Last : out Nat);
27625 -- Perform sorting and merging as required by Check_Consistency.
27627 -----------------------------
27628 -- Normalize_Interval_List --
27629 -----------------------------
27630 procedure Normalize_Interval_List
27631 (List : in out Discrete_Interval_List; Last : out Nat) is
27633 procedure Move_Interval (From, To : Natural);
27634 -- Copy interval from one location to another
27636 function Lt_Interval (Idx1, Idx2 : Natural) return Boolean;
27637 -- Compare two list elements
27639 Temp_0 : Discrete_Interval := (others => Uint_0);
27640 -- cope with Heap_Sort_G idiosyncrasies.
27642 function Read_Interval (From : Natural) return Discrete_Interval;
27643 -- Normal array indexing unless From = 0
27645 -------------------
27646 -- Read_Interval --
27647 -------------------
27648 function Read_Interval (From : Natural) return Discrete_Interval is
27653 return List (Pos (From));
27657 -------------------
27658 -- Move_Interval --
27659 -------------------
27660 procedure Move_Interval (From, To : Natural) is
27661 Rhs : constant Discrete_Interval := Read_Interval (From);
27666 List (Pos (To)) := Rhs;
27673 function Lt_Interval (Idx1, Idx2 : Natural) return Boolean is
27674 Elem1 : constant Discrete_Interval := Read_Interval (Idx1);
27675 Elem2 : constant Discrete_Interval := Read_Interval (Idx2);
27676 Null_1 : constant Boolean := Elem1.Low > Elem1.High;
27677 Null_2 : constant Boolean := Elem2.Low > Elem2.High;
27679 if Null_1 /= Null_2 then
27680 -- So that sorting moves null intervals to high end
27682 elsif Elem1.Low /= Elem2.Low then
27683 return Elem1.Low < Elem2.Low;
27685 return Elem1.High < Elem2.High;
27689 package Interval_Sorting is
27690 new Gnat.Heap_Sort_G (Move_Interval, Lt_Interval);
27692 function Is_Null (Idx : Pos) return Boolean;
27693 -- True iff List (Idx) defines a null range
27695 function Is_Null (Idx : Pos) return Boolean is
27697 return List (Idx).Low > List (Idx).High;
27700 procedure Merge_Intervals (Null_Interval_Count : out Nat);
27701 -- Merge contiguous ranges by replacing one with merged range
27702 -- and the other with a null value. Return a count of the
27703 -- null intervals, both preexisting and those introduced by
27706 ---------------------
27707 -- Merge_Intervals --
27708 ---------------------
27709 procedure Merge_Intervals (Null_Interval_Count : out Nat) is
27710 Not_Null : Pos range List'Range;
27711 -- Index of the most recently examined non-null interval
27713 Null_Interval : constant Discrete_Interval
27714 := (Low => Uint_1, High => Uint_0); -- any null range ok here
27716 if List'Length = 0 or else Is_Null (List'First) then
27717 Null_Interval_Count := List'Length;
27718 -- no non-null elements, so no merge candidates
27722 Null_Interval_Count := 0;
27723 Not_Null := List'First;
27724 for Idx in List'First + 1 .. List'Last loop
27725 if Is_Null (Idx) then
27726 -- all remaining elements are null
27727 Null_Interval_Count :=
27728 Null_Interval_Count + List (Idx .. List'Last)'Length;
27730 elsif List (Idx).Low = List (Not_Null).High + 1 then
27731 -- Merge the two intervals into one; discard the other
27732 List (Not_Null).High := List (Idx).High;
27733 List (Idx) := Null_Interval;
27734 Null_Interval_Count := Null_Interval_Count + 1;
27736 pragma Assert (List (Idx).Low > List (Not_Null).High);
27740 end Merge_Intervals;
27742 Interval_Sorting.Sort (Natural (List'Last));
27744 Null_Interval_Count : Nat;
27746 Merge_Intervals (Null_Interval_Count);
27747 Last := List'Last - Null_Interval_Count;
27748 if Null_Interval_Count /= 0 then
27749 -- Move null intervals introduced during merging to high end
27750 Interval_Sorting.Sort (Natural (List'Last));
27753 end Normalize_Interval_List;
27755 ---------------------------
27756 -- Choice_List_Intervals --
27757 ---------------------------
27758 function Choice_List_Intervals
27759 (Discrete_Choices : List_Id) return Discrete_Interval_List
27761 function Unmerged_Choice_Count return Nat;
27762 -- The number of intervals before adjacent intervals are merged.
27764 ---------------------------
27765 -- Unmerged_Choice_Count --
27766 ---------------------------
27767 function Unmerged_Choice_Count return Nat is
27768 Choice : Node_Id := First (Discrete_Choices);
27771 while Present (Choice) loop
27772 -- Non-contiguous choices involving static predicates
27773 -- have already been normalized away.
27775 if Nkind (Choice) = N_Others_Choice then
27777 Count + List_Length (Others_Discrete_Choices (Choice));
27779 Count := Count + 1; -- an ordinary expression or range
27782 Choice := Next (Choice);
27785 end Unmerged_Choice_Count;
27787 Choice : Node_Id := First (Discrete_Choices);
27788 Result : Discrete_Interval_List (1 .. Unmerged_Choice_Count);
27791 while Present (Choice) loop
27792 if Nkind (Choice) = N_Others_Choice then
27794 Others_Choice : Node_Id
27795 := First (Others_Discrete_Choices (Choice));
27797 while Present (Others_Choice) loop
27798 Count := Count + 1;
27799 Result (Count) := Chosen_Interval (Others_Choice);
27800 Others_Choice := Next (Others_Choice);
27804 Count := Count + 1;
27805 Result (Count) := Chosen_Interval (Choice);
27807 Choice := Next (Choice);
27809 pragma Assert (Count = Result'Last);
27810 Normalize_Interval_List (Result, Count);
27811 Check_Consistency (Result (1 .. Count));
27812 return Result (1 .. Count);
27813 end Choice_List_Intervals;
27819 (Subset, Of_Set : Discrete_Interval_List) return Boolean
27821 -- Returns True iff for each interval of Subset we can find
27822 -- a single interval of Of_Set which contains the Subset interval.
27824 if Of_Set'Length = 0 then
27825 return Subset'Length = 0;
27829 Set_Index : Pos range Of_Set'Range := Of_Set'First;
27831 for Ss_Idx in Subset'Range loop
27832 while not In_Interval
27833 (Value => Subset (Ss_Idx).Low,
27834 Interval => Of_Set (Set_Index))
27836 if Set_Index = Of_Set'Last then
27839 Set_Index := Set_Index + 1;
27843 (Value => Subset (Ss_Idx).High,
27844 Interval => Of_Set (Set_Index))
27854 end Interval_Lists;
27857 Erroutc.Subprogram_Name_Ptr := Subprogram_Name'Access;