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.HTable; use GNAT.HTable;
72 package body Sem_Util is
74 ---------------------------
75 -- Local Data Structures --
76 ---------------------------
78 Invalid_Binder_Values : array (Scalar_Id) of Entity_Id := (others => Empty);
79 -- A collection to hold the entities of the variables declared in package
80 -- System.Scalar_Values which describe the invalid values of scalar types.
82 Invalid_Binder_Values_Set : Boolean := False;
83 -- This flag prevents multiple attempts to initialize Invalid_Binder_Values
85 Invalid_Floats : array (Float_Scalar_Id) of Ureal := (others => No_Ureal);
86 -- A collection to hold the invalid values of float types as specified by
87 -- pragma Initialize_Scalars.
89 Invalid_Integers : array (Integer_Scalar_Id) of Uint := (others => No_Uint);
90 -- A collection to hold the invalid values of integer types as specified
91 -- by pragma Initialize_Scalars.
93 -----------------------
94 -- Local Subprograms --
95 -----------------------
97 function Build_Component_Subtype
100 T : Entity_Id) return Node_Id;
101 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
102 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
103 -- Loc is the source location, T is the original subtype.
105 procedure Examine_Array_Bounds
107 All_Static : out Boolean;
108 Has_Empty : out Boolean);
109 -- Inspect the index constraints of array type Typ. Flag All_Static is set
110 -- when all ranges are static. Flag Has_Empty is set only when All_Static
111 -- is set and indicates that at least one range is empty.
113 function Has_Enabled_Property
114 (Item_Id : Entity_Id;
115 Property : Name_Id) return Boolean;
116 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
117 -- Determine whether an abstract state or a variable denoted by entity
118 -- Item_Id has enabled property Property.
120 function Has_Null_Extension (T : Entity_Id) return Boolean;
121 -- T is a derived tagged type. Check whether the type extension is null.
122 -- If the parent type is fully initialized, T can be treated as such.
124 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
125 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
126 -- with discriminants whose default values are static, examine only the
127 -- components in the selected variant to determine whether all of them
130 type Null_Status_Kind is
132 -- This value indicates that a subexpression is known to have a null
133 -- value at compile time.
136 -- This value indicates that a subexpression is known to have a non-null
137 -- value at compile time.
140 -- This value indicates that it cannot be determined at compile time
141 -- whether a subexpression yields a null or non-null value.
143 function Null_Status (N : Node_Id) return Null_Status_Kind;
144 -- Determine whether subexpression N of an access type yields a null value,
145 -- a non-null value, or the value cannot be determined at compile time. The
146 -- routine does not take simple flow diagnostics into account, it relies on
147 -- static facts such as the presence of null exclusions.
149 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
150 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
151 -- ???We retain the old and new algorithms for Requires_Transient_Scope for
152 -- the time being. New_Requires_Transient_Scope is used by default; the
153 -- debug switch -gnatdQ can be used to do Old_Requires_Transient_Scope
154 -- instead. The intent is to use this temporarily to measure before/after
155 -- efficiency. Note: when this temporary code is removed, the documentation
156 -- of dQ in debug.adb should be removed.
158 procedure Results_Differ
162 -- ???Debugging code. Called when the Old_Val and New_Val differ. This
163 -- routine will be removed eventially when New_Requires_Transient_Scope
164 -- becomes Requires_Transient_Scope and Old_Requires_Transient_Scope is
167 function Subprogram_Name (N : Node_Id) return String;
168 -- Return the fully qualified name of the enclosing subprogram for the
169 -- given node N, with file:line:col information appended, e.g.
170 -- "subp:file:line:col", corresponding to the source location of the
171 -- body of the subprogram.
173 ------------------------------
174 -- Abstract_Interface_List --
175 ------------------------------
177 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
181 if Is_Concurrent_Type (Typ) then
183 -- If we are dealing with a synchronized subtype, go to the base
184 -- type, whose declaration has the interface list.
186 Nod := Declaration_Node (Base_Type (Typ));
188 if Nkind_In (Nod, N_Full_Type_Declaration,
189 N_Private_Type_Declaration)
194 elsif Ekind (Typ) = E_Record_Type_With_Private then
195 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
196 Nod := Type_Definition (Parent (Typ));
198 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
199 if Present (Full_View (Typ))
201 Nkind (Parent (Full_View (Typ))) = N_Full_Type_Declaration
203 Nod := Type_Definition (Parent (Full_View (Typ)));
205 -- If the full-view is not available we cannot do anything else
206 -- here (the source has errors).
212 -- Support for generic formals with interfaces is still missing ???
214 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
219 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
223 elsif Ekind (Typ) = E_Record_Subtype then
224 Nod := Type_Definition (Parent (Etype (Typ)));
226 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
228 -- Recurse, because parent may still be a private extension. Also
229 -- note that the full view of the subtype or the full view of its
230 -- base type may (both) be unavailable.
232 return Abstract_Interface_List (Etype (Typ));
234 elsif Ekind (Typ) = E_Record_Type then
235 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
236 Nod := Formal_Type_Definition (Parent (Typ));
238 Nod := Type_Definition (Parent (Typ));
241 -- Otherwise the type is of a kind which does not implement interfaces
247 return Interface_List (Nod);
248 end Abstract_Interface_List;
250 ----------------------------------
251 -- Acquire_Warning_Match_String --
252 ----------------------------------
254 function Acquire_Warning_Match_String (Str_Lit : Node_Id) return String is
255 S : constant String := To_String (Strval (Str_Lit));
260 -- Put "*" before or after or both, if it's not already there
263 F : constant Boolean := S (S'First) = '*';
264 L : constant Boolean := S (S'Last) = '*';
276 return "*" & S & "*";
281 end Acquire_Warning_Match_String;
283 --------------------------------
284 -- Add_Access_Type_To_Process --
285 --------------------------------
287 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
291 Ensure_Freeze_Node (E);
292 L := Access_Types_To_Process (Freeze_Node (E));
296 Set_Access_Types_To_Process (Freeze_Node (E), L);
300 end Add_Access_Type_To_Process;
302 --------------------------
303 -- Add_Block_Identifier --
304 --------------------------
306 procedure Add_Block_Identifier (N : Node_Id; Id : out Entity_Id) is
307 Loc : constant Source_Ptr := Sloc (N);
310 pragma Assert (Nkind (N) = N_Block_Statement);
312 -- The block already has a label, return its entity
314 if Present (Identifier (N)) then
315 Id := Entity (Identifier (N));
317 -- Create a new block label and set its attributes
320 Id := New_Internal_Entity (E_Block, Current_Scope, Loc, 'B');
321 Set_Etype (Id, Standard_Void_Type);
324 Set_Identifier (N, New_Occurrence_Of (Id, Loc));
325 Set_Block_Node (Id, Identifier (N));
327 end Add_Block_Identifier;
329 ----------------------------
330 -- Add_Global_Declaration --
331 ----------------------------
333 procedure Add_Global_Declaration (N : Node_Id) is
334 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
337 if No (Declarations (Aux_Node)) then
338 Set_Declarations (Aux_Node, New_List);
341 Append_To (Declarations (Aux_Node), N);
343 end Add_Global_Declaration;
345 --------------------------------
346 -- Address_Integer_Convert_OK --
347 --------------------------------
349 function Address_Integer_Convert_OK (T1, T2 : Entity_Id) return Boolean is
351 if Allow_Integer_Address
352 and then ((Is_Descendant_Of_Address (T1)
353 and then Is_Private_Type (T1)
354 and then Is_Integer_Type (T2))
356 (Is_Descendant_Of_Address (T2)
357 and then Is_Private_Type (T2)
358 and then Is_Integer_Type (T1)))
364 end Address_Integer_Convert_OK;
370 function Address_Value (N : Node_Id) return Node_Id is
375 -- For constant, get constant expression
377 if Is_Entity_Name (Expr)
378 and then Ekind (Entity (Expr)) = E_Constant
380 Expr := Constant_Value (Entity (Expr));
382 -- For unchecked conversion, get result to convert
384 elsif Nkind (Expr) = N_Unchecked_Type_Conversion then
385 Expr := Expression (Expr);
387 -- For (common case) of To_Address call, get argument
389 elsif Nkind (Expr) = N_Function_Call
390 and then Is_Entity_Name (Name (Expr))
391 and then Is_RTE (Entity (Name (Expr)), RE_To_Address)
393 Expr := First (Parameter_Associations (Expr));
395 if Nkind (Expr) = N_Parameter_Association then
396 Expr := Explicit_Actual_Parameter (Expr);
399 -- We finally have the real expression
413 -- For now, just 8/16/32/64
415 function Addressable (V : Uint) return Boolean is
417 return V = Uint_8 or else
423 function Addressable (V : Int) return Boolean is
431 ---------------------------------
432 -- Aggregate_Constraint_Checks --
433 ---------------------------------
435 procedure Aggregate_Constraint_Checks
437 Check_Typ : Entity_Id)
439 Exp_Typ : constant Entity_Id := Etype (Exp);
442 if Raises_Constraint_Error (Exp) then
446 -- Ada 2005 (AI-230): Generate a conversion to an anonymous access
447 -- component's type to force the appropriate accessibility checks.
449 -- Ada 2005 (AI-231): Generate conversion to the null-excluding type to
450 -- force the corresponding run-time check
452 if Is_Access_Type (Check_Typ)
453 and then Is_Local_Anonymous_Access (Check_Typ)
455 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
456 Analyze_And_Resolve (Exp, Check_Typ);
457 Check_Unset_Reference (Exp);
460 -- What follows is really expansion activity, so check that expansion
461 -- is on and is allowed. In GNATprove mode, we also want check flags to
462 -- be added in the tree, so that the formal verification can rely on
463 -- those to be present. In GNATprove mode for formal verification, some
464 -- treatment typically only done during expansion needs to be performed
465 -- on the tree, but it should not be applied inside generics. Otherwise,
466 -- this breaks the name resolution mechanism for generic instances.
468 if not Expander_Active
469 and (Inside_A_Generic or not Full_Analysis or not GNATprove_Mode)
474 if Is_Access_Type (Check_Typ)
475 and then Can_Never_Be_Null (Check_Typ)
476 and then not Can_Never_Be_Null (Exp_Typ)
478 Install_Null_Excluding_Check (Exp);
481 -- First check if we have to insert discriminant checks
483 if Has_Discriminants (Exp_Typ) then
484 Apply_Discriminant_Check (Exp, Check_Typ);
486 -- Next emit length checks for array aggregates
488 elsif Is_Array_Type (Exp_Typ) then
489 Apply_Length_Check (Exp, Check_Typ);
491 -- Finally emit scalar and string checks. If we are dealing with a
492 -- scalar literal we need to check by hand because the Etype of
493 -- literals is not necessarily correct.
495 elsif Is_Scalar_Type (Exp_Typ)
496 and then Compile_Time_Known_Value (Exp)
498 if Is_Out_Of_Range (Exp, Base_Type (Check_Typ)) then
499 Apply_Compile_Time_Constraint_Error
500 (Exp, "value not in range of}??", CE_Range_Check_Failed,
501 Ent => Base_Type (Check_Typ),
502 Typ => Base_Type (Check_Typ));
504 elsif Is_Out_Of_Range (Exp, Check_Typ) then
505 Apply_Compile_Time_Constraint_Error
506 (Exp, "value not in range of}??", CE_Range_Check_Failed,
510 elsif not Range_Checks_Suppressed (Check_Typ) then
511 Apply_Scalar_Range_Check (Exp, Check_Typ);
514 -- Verify that target type is also scalar, to prevent view anomalies
515 -- in instantiations.
517 elsif (Is_Scalar_Type (Exp_Typ)
518 or else Nkind (Exp) = N_String_Literal)
519 and then Is_Scalar_Type (Check_Typ)
520 and then Exp_Typ /= Check_Typ
522 if Is_Entity_Name (Exp)
523 and then Ekind (Entity (Exp)) = E_Constant
525 -- If expression is a constant, it is worthwhile checking whether
526 -- it is a bound of the type.
528 if (Is_Entity_Name (Type_Low_Bound (Check_Typ))
529 and then Entity (Exp) = Entity (Type_Low_Bound (Check_Typ)))
531 (Is_Entity_Name (Type_High_Bound (Check_Typ))
532 and then Entity (Exp) = Entity (Type_High_Bound (Check_Typ)))
537 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
538 Analyze_And_Resolve (Exp, Check_Typ);
539 Check_Unset_Reference (Exp);
542 -- Could use a comment on this case ???
545 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
546 Analyze_And_Resolve (Exp, Check_Typ);
547 Check_Unset_Reference (Exp);
551 end Aggregate_Constraint_Checks;
553 -----------------------
554 -- Alignment_In_Bits --
555 -----------------------
557 function Alignment_In_Bits (E : Entity_Id) return Uint is
559 return Alignment (E) * System_Storage_Unit;
560 end Alignment_In_Bits;
562 --------------------------------------
563 -- All_Composite_Constraints_Static --
564 --------------------------------------
566 function All_Composite_Constraints_Static
567 (Constr : Node_Id) return Boolean
570 if No (Constr) or else Error_Posted (Constr) then
574 case Nkind (Constr) is
576 if Nkind (Constr) in N_Has_Entity
577 and then Present (Entity (Constr))
579 if Is_Type (Entity (Constr)) then
581 not Is_Discrete_Type (Entity (Constr))
582 or else Is_OK_Static_Subtype (Entity (Constr));
585 elsif Nkind (Constr) = N_Range then
587 Is_OK_Static_Expression (Low_Bound (Constr))
589 Is_OK_Static_Expression (High_Bound (Constr));
591 elsif Nkind (Constr) = N_Attribute_Reference
592 and then Attribute_Name (Constr) = Name_Range
595 Is_OK_Static_Expression
596 (Type_Low_Bound (Etype (Prefix (Constr))))
598 Is_OK_Static_Expression
599 (Type_High_Bound (Etype (Prefix (Constr))));
603 not Present (Etype (Constr)) -- previous error
604 or else not Is_Discrete_Type (Etype (Constr))
605 or else Is_OK_Static_Expression (Constr);
607 when N_Discriminant_Association =>
608 return All_Composite_Constraints_Static (Expression (Constr));
610 when N_Range_Constraint =>
612 All_Composite_Constraints_Static (Range_Expression (Constr));
614 when N_Index_Or_Discriminant_Constraint =>
616 One_Cstr : Entity_Id;
618 One_Cstr := First (Constraints (Constr));
619 while Present (One_Cstr) loop
620 if not All_Composite_Constraints_Static (One_Cstr) then
630 when N_Subtype_Indication =>
632 All_Composite_Constraints_Static (Subtype_Mark (Constr))
634 All_Composite_Constraints_Static (Constraint (Constr));
639 end All_Composite_Constraints_Static;
641 ------------------------
642 -- Append_Entity_Name --
643 ------------------------
645 procedure Append_Entity_Name (Buf : in out Bounded_String; E : Entity_Id) is
646 Temp : Bounded_String;
648 procedure Inner (E : Entity_Id);
649 -- Inner recursive routine, keep outer routine nonrecursive to ease
650 -- debugging when we get strange results from this routine.
656 procedure Inner (E : Entity_Id) is
660 -- If entity has an internal name, skip by it, and print its scope.
661 -- Note that we strip a final R from the name before the test; this
662 -- is needed for some cases of instantiations.
665 E_Name : Bounded_String;
668 Append (E_Name, Chars (E));
670 if E_Name.Chars (E_Name.Length) = 'R' then
671 E_Name.Length := E_Name.Length - 1;
674 if Is_Internal_Name (E_Name) then
682 -- Just print entity name if its scope is at the outer level
684 if Scop = Standard_Standard then
687 -- If scope comes from source, write scope and entity
689 elsif Comes_From_Source (Scop) then
690 Append_Entity_Name (Temp, Scop);
693 -- If in wrapper package skip past it
695 elsif Present (Scop) and then Is_Wrapper_Package (Scop) then
696 Append_Entity_Name (Temp, Scope (Scop));
699 -- Otherwise nothing to output (happens in unnamed block statements)
708 E_Name : Bounded_String;
711 Append_Unqualified_Decoded (E_Name, Chars (E));
713 -- Remove trailing upper-case letters from the name (useful for
714 -- dealing with some cases of internal names generated in the case
715 -- of references from within a generic).
717 while E_Name.Length > 1
718 and then E_Name.Chars (E_Name.Length) in 'A' .. 'Z'
720 E_Name.Length := E_Name.Length - 1;
723 -- Adjust casing appropriately (gets name from source if possible)
725 Adjust_Name_Case (E_Name, Sloc (E));
726 Append (Temp, E_Name);
730 -- Start of processing for Append_Entity_Name
735 end Append_Entity_Name;
737 ---------------------------------
738 -- Append_Inherited_Subprogram --
739 ---------------------------------
741 procedure Append_Inherited_Subprogram (S : Entity_Id) is
742 Par : constant Entity_Id := Alias (S);
743 -- The parent subprogram
745 Scop : constant Entity_Id := Scope (Par);
746 -- The scope of definition of the parent subprogram
748 Typ : constant Entity_Id := Defining_Entity (Parent (S));
749 -- The derived type of which S is a primitive operation
755 if Ekind (Current_Scope) = E_Package
756 and then In_Private_Part (Current_Scope)
757 and then Has_Private_Declaration (Typ)
758 and then Is_Tagged_Type (Typ)
759 and then Scop = Current_Scope
761 -- The inherited operation is available at the earliest place after
762 -- the derived type declaration (RM 7.3.1 (6/1)). This is only
763 -- relevant for type extensions. If the parent operation appears
764 -- after the type extension, the operation is not visible.
767 (Visible_Declarations
768 (Package_Specification (Current_Scope)));
769 while Present (Decl) loop
770 if Nkind (Decl) = N_Private_Extension_Declaration
771 and then Defining_Entity (Decl) = Typ
773 if Sloc (Decl) > Sloc (Par) then
774 Next_E := Next_Entity (Par);
775 Link_Entities (Par, S);
776 Link_Entities (S, Next_E);
788 -- If partial view is not a type extension, or it appears before the
789 -- subprogram declaration, insert normally at end of entity list.
791 Append_Entity (S, Current_Scope);
792 end Append_Inherited_Subprogram;
794 -----------------------------------------
795 -- Apply_Compile_Time_Constraint_Error --
796 -----------------------------------------
798 procedure Apply_Compile_Time_Constraint_Error
801 Reason : RT_Exception_Code;
802 Ent : Entity_Id := Empty;
803 Typ : Entity_Id := Empty;
804 Loc : Source_Ptr := No_Location;
805 Rep : Boolean := True;
806 Warn : Boolean := False)
808 Stat : constant Boolean := Is_Static_Expression (N);
809 R_Stat : constant Node_Id :=
810 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
821 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
823 -- In GNATprove mode, do not replace the node with an exception raised.
824 -- In such a case, either the call to Compile_Time_Constraint_Error
825 -- issues an error which stops analysis, or it issues a warning in
826 -- a few cases where a suitable check flag is set for GNATprove to
827 -- generate a check message.
829 if not Rep or GNATprove_Mode then
833 -- Now we replace the node by an N_Raise_Constraint_Error node
834 -- This does not need reanalyzing, so set it as analyzed now.
837 Set_Analyzed (N, True);
840 Set_Raises_Constraint_Error (N);
842 -- Now deal with possible local raise handling
844 Possible_Local_Raise (N, Standard_Constraint_Error);
846 -- If the original expression was marked as static, the result is
847 -- still marked as static, but the Raises_Constraint_Error flag is
848 -- always set so that further static evaluation is not attempted.
851 Set_Is_Static_Expression (N);
853 end Apply_Compile_Time_Constraint_Error;
855 ---------------------------
856 -- Async_Readers_Enabled --
857 ---------------------------
859 function Async_Readers_Enabled (Id : Entity_Id) return Boolean is
861 return Has_Enabled_Property (Id, Name_Async_Readers);
862 end Async_Readers_Enabled;
864 ---------------------------
865 -- Async_Writers_Enabled --
866 ---------------------------
868 function Async_Writers_Enabled (Id : Entity_Id) return Boolean is
870 return Has_Enabled_Property (Id, Name_Async_Writers);
871 end Async_Writers_Enabled;
873 --------------------------------------
874 -- Available_Full_View_Of_Component --
875 --------------------------------------
877 function Available_Full_View_Of_Component (T : Entity_Id) return Boolean is
878 ST : constant Entity_Id := Scope (T);
879 SCT : constant Entity_Id := Scope (Component_Type (T));
881 return In_Open_Scopes (ST)
882 and then In_Open_Scopes (SCT)
883 and then Scope_Depth (ST) >= Scope_Depth (SCT);
884 end Available_Full_View_Of_Component;
890 procedure Bad_Attribute
893 Warn : Boolean := False)
896 Error_Msg_Warn := Warn;
897 Error_Msg_N ("unrecognized attribute&<<", N);
899 -- Check for possible misspelling
901 Error_Msg_Name_1 := First_Attribute_Name;
902 while Error_Msg_Name_1 <= Last_Attribute_Name loop
903 if Is_Bad_Spelling_Of (Nam, Error_Msg_Name_1) then
904 Error_Msg_N -- CODEFIX
905 ("\possible misspelling of %<<", N);
909 Error_Msg_Name_1 := Error_Msg_Name_1 + 1;
913 --------------------------------
914 -- Bad_Predicated_Subtype_Use --
915 --------------------------------
917 procedure Bad_Predicated_Subtype_Use
921 Suggest_Static : Boolean := False)
926 -- Avoid cascaded errors
928 if Error_Posted (N) then
932 if Inside_A_Generic then
933 Gen := Current_Scope;
934 while Present (Gen) and then Ekind (Gen) /= E_Generic_Package loop
942 if Is_Generic_Formal (Typ) and then Is_Discrete_Type (Typ) then
943 Set_No_Predicate_On_Actual (Typ);
946 elsif Has_Predicates (Typ) then
947 if Is_Generic_Actual_Type (Typ) then
949 -- The restriction on loop parameters is only that the type
950 -- should have no dynamic predicates.
952 if Nkind (Parent (N)) = N_Loop_Parameter_Specification
953 and then not Has_Dynamic_Predicate_Aspect (Typ)
954 and then Is_OK_Static_Subtype (Typ)
959 Gen := Current_Scope;
960 while not Is_Generic_Instance (Gen) loop
964 pragma Assert (Present (Gen));
966 if Ekind (Gen) = E_Package and then In_Package_Body (Gen) then
967 Error_Msg_Warn := SPARK_Mode /= On;
968 Error_Msg_FE (Msg & "<<", N, Typ);
969 Error_Msg_F ("\Program_Error [<<", N);
972 Make_Raise_Program_Error (Sloc (N),
973 Reason => PE_Bad_Predicated_Generic_Type));
976 Error_Msg_FE (Msg & "<<", N, Typ);
980 Error_Msg_FE (Msg, N, Typ);
983 -- Emit an optional suggestion on how to remedy the error if the
984 -- context warrants it.
986 if Suggest_Static and then Has_Static_Predicate (Typ) then
987 Error_Msg_FE ("\predicate of & should be marked static", N, Typ);
990 end Bad_Predicated_Subtype_Use;
992 -----------------------------------------
993 -- Bad_Unordered_Enumeration_Reference --
994 -----------------------------------------
996 function Bad_Unordered_Enumeration_Reference
998 T : Entity_Id) return Boolean
1001 return Is_Enumeration_Type (T)
1002 and then Warn_On_Unordered_Enumeration_Type
1003 and then not Is_Generic_Type (T)
1004 and then Comes_From_Source (N)
1005 and then not Has_Pragma_Ordered (T)
1006 and then not In_Same_Extended_Unit (N, T);
1007 end Bad_Unordered_Enumeration_Reference;
1009 ----------------------------
1010 -- Begin_Keyword_Location --
1011 ----------------------------
1013 function Begin_Keyword_Location (N : Node_Id) return Source_Ptr is
1017 pragma Assert (Nkind_In (N, N_Block_Statement,
1023 HSS := Handled_Statement_Sequence (N);
1025 -- When the handled sequence of statements comes from source, the
1026 -- location of the "begin" keyword is that of the sequence itself.
1027 -- Note that an internal construct may inherit a source sequence.
1029 if Comes_From_Source (HSS) then
1032 -- The parser generates an internal handled sequence of statements to
1033 -- capture the location of the "begin" keyword if present in the source.
1034 -- Since there are no source statements, the location of the "begin"
1035 -- keyword is effectively that of the "end" keyword.
1037 elsif Comes_From_Source (N) then
1040 -- Otherwise the construct is internal and should carry the location of
1041 -- the original construct which prompted its creation.
1046 end Begin_Keyword_Location;
1048 --------------------------
1049 -- Build_Actual_Subtype --
1050 --------------------------
1052 function Build_Actual_Subtype
1054 N : Node_Or_Entity_Id) return Node_Id
1057 -- Normally Sloc (N), but may point to corresponding body in some cases
1059 Constraints : List_Id;
1065 Disc_Type : Entity_Id;
1071 if Nkind (N) = N_Defining_Identifier then
1072 Obj := New_Occurrence_Of (N, Loc);
1074 -- If this is a formal parameter of a subprogram declaration, and
1075 -- we are compiling the body, we want the declaration for the
1076 -- actual subtype to carry the source position of the body, to
1077 -- prevent anomalies in gdb when stepping through the code.
1079 if Is_Formal (N) then
1081 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
1083 if Nkind (Decl) = N_Subprogram_Declaration
1084 and then Present (Corresponding_Body (Decl))
1086 Loc := Sloc (Corresponding_Body (Decl));
1095 if Is_Array_Type (T) then
1096 Constraints := New_List;
1097 for J in 1 .. Number_Dimensions (T) loop
1099 -- Build an array subtype declaration with the nominal subtype and
1100 -- the bounds of the actual. Add the declaration in front of the
1101 -- local declarations for the subprogram, for analysis before any
1102 -- reference to the formal in the body.
1105 Make_Attribute_Reference (Loc,
1107 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
1108 Attribute_Name => Name_First,
1109 Expressions => New_List (
1110 Make_Integer_Literal (Loc, J)));
1113 Make_Attribute_Reference (Loc,
1115 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
1116 Attribute_Name => Name_Last,
1117 Expressions => New_List (
1118 Make_Integer_Literal (Loc, J)));
1120 Append (Make_Range (Loc, Lo, Hi), Constraints);
1123 -- If the type has unknown discriminants there is no constrained
1124 -- subtype to build. This is never called for a formal or for a
1125 -- lhs, so returning the type is ok ???
1127 elsif Has_Unknown_Discriminants (T) then
1131 Constraints := New_List;
1133 -- Type T is a generic derived type, inherit the discriminants from
1136 if Is_Private_Type (T)
1137 and then No (Full_View (T))
1139 -- T was flagged as an error if it was declared as a formal
1140 -- derived type with known discriminants. In this case there
1141 -- is no need to look at the parent type since T already carries
1142 -- its own discriminants.
1144 and then not Error_Posted (T)
1146 Disc_Type := Etype (Base_Type (T));
1151 Discr := First_Discriminant (Disc_Type);
1152 while Present (Discr) loop
1153 Append_To (Constraints,
1154 Make_Selected_Component (Loc,
1156 Duplicate_Subexpr_No_Checks (Obj),
1157 Selector_Name => New_Occurrence_Of (Discr, Loc)));
1158 Next_Discriminant (Discr);
1162 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
1163 Set_Is_Internal (Subt);
1166 Make_Subtype_Declaration (Loc,
1167 Defining_Identifier => Subt,
1168 Subtype_Indication =>
1169 Make_Subtype_Indication (Loc,
1170 Subtype_Mark => New_Occurrence_Of (T, Loc),
1172 Make_Index_Or_Discriminant_Constraint (Loc,
1173 Constraints => Constraints)));
1175 Mark_Rewrite_Insertion (Decl);
1177 end Build_Actual_Subtype;
1179 ---------------------------------------
1180 -- Build_Actual_Subtype_Of_Component --
1181 ---------------------------------------
1183 function Build_Actual_Subtype_Of_Component
1185 N : Node_Id) return Node_Id
1187 Loc : constant Source_Ptr := Sloc (N);
1188 P : constant Node_Id := Prefix (N);
1191 Index_Typ : Entity_Id;
1193 Desig_Typ : Entity_Id;
1194 -- This is either a copy of T, or if T is an access type, then it is
1195 -- the directly designated type of this access type.
1197 function Build_Actual_Array_Constraint return List_Id;
1198 -- If one or more of the bounds of the component depends on
1199 -- discriminants, build actual constraint using the discriminants
1202 function Build_Actual_Record_Constraint return List_Id;
1203 -- Similar to previous one, for discriminated components constrained
1204 -- by the discriminant of the enclosing object.
1206 -----------------------------------
1207 -- Build_Actual_Array_Constraint --
1208 -----------------------------------
1210 function Build_Actual_Array_Constraint return List_Id is
1211 Constraints : constant List_Id := New_List;
1219 Indx := First_Index (Desig_Typ);
1220 while Present (Indx) loop
1221 Old_Lo := Type_Low_Bound (Etype (Indx));
1222 Old_Hi := Type_High_Bound (Etype (Indx));
1224 if Denotes_Discriminant (Old_Lo) then
1226 Make_Selected_Component (Loc,
1227 Prefix => New_Copy_Tree (P),
1228 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
1231 Lo := New_Copy_Tree (Old_Lo);
1233 -- The new bound will be reanalyzed in the enclosing
1234 -- declaration. For literal bounds that come from a type
1235 -- declaration, the type of the context must be imposed, so
1236 -- insure that analysis will take place. For non-universal
1237 -- types this is not strictly necessary.
1239 Set_Analyzed (Lo, False);
1242 if Denotes_Discriminant (Old_Hi) then
1244 Make_Selected_Component (Loc,
1245 Prefix => New_Copy_Tree (P),
1246 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
1249 Hi := New_Copy_Tree (Old_Hi);
1250 Set_Analyzed (Hi, False);
1253 Append (Make_Range (Loc, Lo, Hi), Constraints);
1258 end Build_Actual_Array_Constraint;
1260 ------------------------------------
1261 -- Build_Actual_Record_Constraint --
1262 ------------------------------------
1264 function Build_Actual_Record_Constraint return List_Id is
1265 Constraints : constant List_Id := New_List;
1270 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1271 while Present (D) loop
1272 if Denotes_Discriminant (Node (D)) then
1273 D_Val := Make_Selected_Component (Loc,
1274 Prefix => New_Copy_Tree (P),
1275 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
1278 D_Val := New_Copy_Tree (Node (D));
1281 Append (D_Val, Constraints);
1286 end Build_Actual_Record_Constraint;
1288 -- Start of processing for Build_Actual_Subtype_Of_Component
1291 -- Why the test for Spec_Expression mode here???
1293 if In_Spec_Expression then
1296 -- More comments for the rest of this body would be good ???
1298 elsif Nkind (N) = N_Explicit_Dereference then
1299 if Is_Composite_Type (T)
1300 and then not Is_Constrained (T)
1301 and then not (Is_Class_Wide_Type (T)
1302 and then Is_Constrained (Root_Type (T)))
1303 and then not Has_Unknown_Discriminants (T)
1305 -- If the type of the dereference is already constrained, it is an
1308 if Is_Array_Type (Etype (N))
1309 and then Is_Constrained (Etype (N))
1313 Remove_Side_Effects (P);
1314 return Build_Actual_Subtype (T, N);
1321 if Ekind (T) = E_Access_Subtype then
1322 Desig_Typ := Designated_Type (T);
1327 if Ekind (Desig_Typ) = E_Array_Subtype then
1328 Id := First_Index (Desig_Typ);
1329 while Present (Id) loop
1330 Index_Typ := Underlying_Type (Etype (Id));
1332 if Denotes_Discriminant (Type_Low_Bound (Index_Typ))
1334 Denotes_Discriminant (Type_High_Bound (Index_Typ))
1336 Remove_Side_Effects (P);
1338 Build_Component_Subtype
1339 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
1345 elsif Is_Composite_Type (Desig_Typ)
1346 and then Has_Discriminants (Desig_Typ)
1347 and then not Has_Unknown_Discriminants (Desig_Typ)
1349 if Is_Private_Type (Desig_Typ)
1350 and then No (Discriminant_Constraint (Desig_Typ))
1352 Desig_Typ := Full_View (Desig_Typ);
1355 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1356 while Present (D) loop
1357 if Denotes_Discriminant (Node (D)) then
1358 Remove_Side_Effects (P);
1360 Build_Component_Subtype (
1361 Build_Actual_Record_Constraint, Loc, Base_Type (T));
1368 -- If none of the above, the actual and nominal subtypes are the same
1371 end Build_Actual_Subtype_Of_Component;
1373 ---------------------------------
1374 -- Build_Class_Wide_Clone_Body --
1375 ---------------------------------
1377 procedure Build_Class_Wide_Clone_Body
1378 (Spec_Id : Entity_Id;
1381 Loc : constant Source_Ptr := Sloc (Bod);
1382 Clone_Id : constant Entity_Id := Class_Wide_Clone (Spec_Id);
1383 Clone_Body : Node_Id;
1386 -- The declaration of the class-wide clone was created when the
1387 -- corresponding class-wide condition was analyzed.
1390 Make_Subprogram_Body (Loc,
1392 Copy_Subprogram_Spec (Parent (Clone_Id)),
1393 Declarations => Declarations (Bod),
1394 Handled_Statement_Sequence => Handled_Statement_Sequence (Bod));
1396 -- The new operation is internal and overriding indicators do not apply
1397 -- (the original primitive may have carried one).
1399 Set_Must_Override (Specification (Clone_Body), False);
1401 -- If the subprogram body is the proper body of a stub, insert the
1402 -- subprogram after the stub, i.e. the same declarative region as
1403 -- the original sugprogram.
1405 if Nkind (Parent (Bod)) = N_Subunit then
1406 Insert_After (Corresponding_Stub (Parent (Bod)), Clone_Body);
1409 Insert_Before (Bod, Clone_Body);
1412 Analyze (Clone_Body);
1413 end Build_Class_Wide_Clone_Body;
1415 ---------------------------------
1416 -- Build_Class_Wide_Clone_Call --
1417 ---------------------------------
1419 function Build_Class_Wide_Clone_Call
1422 Spec_Id : Entity_Id;
1423 Spec : Node_Id) return Node_Id
1425 Clone_Id : constant Entity_Id := Class_Wide_Clone (Spec_Id);
1426 Par_Type : constant Entity_Id := Find_Dispatching_Type (Spec_Id);
1432 New_F_Spec : Entity_Id;
1433 New_Formal : Entity_Id;
1436 Actuals := Empty_List;
1437 Formal := First_Formal (Spec_Id);
1438 New_F_Spec := First (Parameter_Specifications (Spec));
1440 -- Build parameter association for call to class-wide clone.
1442 while Present (Formal) loop
1443 New_Formal := Defining_Identifier (New_F_Spec);
1445 -- If controlling argument and operation is inherited, add conversion
1446 -- to parent type for the call.
1448 if Etype (Formal) = Par_Type
1449 and then not Is_Empty_List (Decls)
1452 Make_Type_Conversion (Loc,
1453 New_Occurrence_Of (Par_Type, Loc),
1454 New_Occurrence_Of (New_Formal, Loc)));
1457 Append_To (Actuals, New_Occurrence_Of (New_Formal, Loc));
1460 Next_Formal (Formal);
1464 if Ekind (Spec_Id) = E_Procedure then
1466 Make_Procedure_Call_Statement (Loc,
1467 Name => New_Occurrence_Of (Clone_Id, Loc),
1468 Parameter_Associations => Actuals);
1471 Make_Simple_Return_Statement (Loc,
1473 Make_Function_Call (Loc,
1474 Name => New_Occurrence_Of (Clone_Id, Loc),
1475 Parameter_Associations => Actuals));
1479 Make_Subprogram_Body (Loc,
1481 Copy_Subprogram_Spec (Spec),
1482 Declarations => Decls,
1483 Handled_Statement_Sequence =>
1484 Make_Handled_Sequence_Of_Statements (Loc,
1485 Statements => New_List (Call),
1486 End_Label => Make_Identifier (Loc, Chars (Spec_Id))));
1489 end Build_Class_Wide_Clone_Call;
1491 ---------------------------------
1492 -- Build_Class_Wide_Clone_Decl --
1493 ---------------------------------
1495 procedure Build_Class_Wide_Clone_Decl (Spec_Id : Entity_Id) is
1496 Loc : constant Source_Ptr := Sloc (Spec_Id);
1497 Clone_Id : constant Entity_Id :=
1498 Make_Defining_Identifier (Loc,
1499 New_External_Name (Chars (Spec_Id), Suffix => "CL"));
1505 Spec := Copy_Subprogram_Spec (Parent (Spec_Id));
1506 Set_Must_Override (Spec, False);
1507 Set_Must_Not_Override (Spec, False);
1508 Set_Defining_Unit_Name (Spec, Clone_Id);
1510 Decl := Make_Subprogram_Declaration (Loc, Spec);
1511 Append (Decl, List_Containing (Unit_Declaration_Node (Spec_Id)));
1513 -- Link clone to original subprogram, for use when building body and
1514 -- wrapper call to inherited operation.
1516 Set_Class_Wide_Clone (Spec_Id, Clone_Id);
1517 end Build_Class_Wide_Clone_Decl;
1519 -----------------------------
1520 -- Build_Component_Subtype --
1521 -----------------------------
1523 function Build_Component_Subtype
1526 T : Entity_Id) return Node_Id
1532 -- Unchecked_Union components do not require component subtypes
1534 if Is_Unchecked_Union (T) then
1538 Subt := Make_Temporary (Loc, 'S');
1539 Set_Is_Internal (Subt);
1542 Make_Subtype_Declaration (Loc,
1543 Defining_Identifier => Subt,
1544 Subtype_Indication =>
1545 Make_Subtype_Indication (Loc,
1546 Subtype_Mark => New_Occurrence_Of (Base_Type (T), Loc),
1548 Make_Index_Or_Discriminant_Constraint (Loc,
1549 Constraints => C)));
1551 Mark_Rewrite_Insertion (Decl);
1553 end Build_Component_Subtype;
1555 ---------------------------
1556 -- Build_Default_Subtype --
1557 ---------------------------
1559 function Build_Default_Subtype
1561 N : Node_Id) return Entity_Id
1563 Loc : constant Source_Ptr := Sloc (N);
1567 -- The base type that is to be constrained by the defaults
1570 if not Has_Discriminants (T) or else Is_Constrained (T) then
1574 Bas := Base_Type (T);
1576 -- If T is non-private but its base type is private, this is the
1577 -- completion of a subtype declaration whose parent type is private
1578 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1579 -- are to be found in the full view of the base. Check that the private
1580 -- status of T and its base differ.
1582 if Is_Private_Type (Bas)
1583 and then not Is_Private_Type (T)
1584 and then Present (Full_View (Bas))
1586 Bas := Full_View (Bas);
1589 Disc := First_Discriminant (T);
1591 if No (Discriminant_Default_Value (Disc)) then
1596 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
1597 Constraints : constant List_Id := New_List;
1601 while Present (Disc) loop
1602 Append_To (Constraints,
1603 New_Copy_Tree (Discriminant_Default_Value (Disc)));
1604 Next_Discriminant (Disc);
1608 Make_Subtype_Declaration (Loc,
1609 Defining_Identifier => Act,
1610 Subtype_Indication =>
1611 Make_Subtype_Indication (Loc,
1612 Subtype_Mark => New_Occurrence_Of (Bas, Loc),
1614 Make_Index_Or_Discriminant_Constraint (Loc,
1615 Constraints => Constraints)));
1617 Insert_Action (N, Decl);
1619 -- If the context is a component declaration the subtype declaration
1620 -- will be analyzed when the enclosing type is frozen, otherwise do
1623 if Ekind (Current_Scope) /= E_Record_Type then
1629 end Build_Default_Subtype;
1631 --------------------------------------------
1632 -- Build_Discriminal_Subtype_Of_Component --
1633 --------------------------------------------
1635 function Build_Discriminal_Subtype_Of_Component
1636 (T : Entity_Id) return Node_Id
1638 Loc : constant Source_Ptr := Sloc (T);
1642 function Build_Discriminal_Array_Constraint return List_Id;
1643 -- If one or more of the bounds of the component depends on
1644 -- discriminants, build actual constraint using the discriminants
1647 function Build_Discriminal_Record_Constraint return List_Id;
1648 -- Similar to previous one, for discriminated components constrained by
1649 -- the discriminant of the enclosing object.
1651 ----------------------------------------
1652 -- Build_Discriminal_Array_Constraint --
1653 ----------------------------------------
1655 function Build_Discriminal_Array_Constraint return List_Id is
1656 Constraints : constant List_Id := New_List;
1664 Indx := First_Index (T);
1665 while Present (Indx) loop
1666 Old_Lo := Type_Low_Bound (Etype (Indx));
1667 Old_Hi := Type_High_Bound (Etype (Indx));
1669 if Denotes_Discriminant (Old_Lo) then
1670 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
1673 Lo := New_Copy_Tree (Old_Lo);
1676 if Denotes_Discriminant (Old_Hi) then
1677 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
1680 Hi := New_Copy_Tree (Old_Hi);
1683 Append (Make_Range (Loc, Lo, Hi), Constraints);
1688 end Build_Discriminal_Array_Constraint;
1690 -----------------------------------------
1691 -- Build_Discriminal_Record_Constraint --
1692 -----------------------------------------
1694 function Build_Discriminal_Record_Constraint return List_Id is
1695 Constraints : constant List_Id := New_List;
1700 D := First_Elmt (Discriminant_Constraint (T));
1701 while Present (D) loop
1702 if Denotes_Discriminant (Node (D)) then
1704 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
1706 D_Val := New_Copy_Tree (Node (D));
1709 Append (D_Val, Constraints);
1714 end Build_Discriminal_Record_Constraint;
1716 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1719 if Ekind (T) = E_Array_Subtype then
1720 Id := First_Index (T);
1721 while Present (Id) loop
1722 if Denotes_Discriminant (Type_Low_Bound (Etype (Id)))
1724 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
1726 return Build_Component_Subtype
1727 (Build_Discriminal_Array_Constraint, Loc, T);
1733 elsif Ekind (T) = E_Record_Subtype
1734 and then Has_Discriminants (T)
1735 and then not Has_Unknown_Discriminants (T)
1737 D := First_Elmt (Discriminant_Constraint (T));
1738 while Present (D) loop
1739 if Denotes_Discriminant (Node (D)) then
1740 return Build_Component_Subtype
1741 (Build_Discriminal_Record_Constraint, Loc, T);
1748 -- If none of the above, the actual and nominal subtypes are the same
1751 end Build_Discriminal_Subtype_Of_Component;
1753 ------------------------------
1754 -- Build_Elaboration_Entity --
1755 ------------------------------
1757 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
1758 Loc : constant Source_Ptr := Sloc (N);
1760 Elab_Ent : Entity_Id;
1762 procedure Set_Package_Name (Ent : Entity_Id);
1763 -- Given an entity, sets the fully qualified name of the entity in
1764 -- Name_Buffer, with components separated by double underscores. This
1765 -- is a recursive routine that climbs the scope chain to Standard.
1767 ----------------------
1768 -- Set_Package_Name --
1769 ----------------------
1771 procedure Set_Package_Name (Ent : Entity_Id) is
1773 if Scope (Ent) /= Standard_Standard then
1774 Set_Package_Name (Scope (Ent));
1777 Nam : constant String := Get_Name_String (Chars (Ent));
1779 Name_Buffer (Name_Len + 1) := '_';
1780 Name_Buffer (Name_Len + 2) := '_';
1781 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
1782 Name_Len := Name_Len + Nam'Length + 2;
1786 Get_Name_String (Chars (Ent));
1788 end Set_Package_Name;
1790 -- Start of processing for Build_Elaboration_Entity
1793 -- Ignore call if already constructed
1795 if Present (Elaboration_Entity (Spec_Id)) then
1798 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1799 -- no role in analysis.
1801 elsif ASIS_Mode then
1804 -- Do not generate an elaboration entity in GNATprove move because the
1805 -- elaboration counter is a form of expansion.
1807 elsif GNATprove_Mode then
1810 -- See if we need elaboration entity
1812 -- We always need an elaboration entity when preserving control flow, as
1813 -- we want to remain explicit about the unit's elaboration order.
1815 elsif Opt.Suppress_Control_Flow_Optimizations then
1818 -- We always need an elaboration entity for the dynamic elaboration
1819 -- model, since it is needed to properly generate the PE exception for
1820 -- access before elaboration.
1822 elsif Dynamic_Elaboration_Checks then
1825 -- For the static model, we don't need the elaboration counter if this
1826 -- unit is sure to have no elaboration code, since that means there
1827 -- is no elaboration unit to be called. Note that we can't just decide
1828 -- after the fact by looking to see whether there was elaboration code,
1829 -- because that's too late to make this decision.
1831 elsif Restriction_Active (No_Elaboration_Code) then
1834 -- Similarly, for the static model, we can skip the elaboration counter
1835 -- if we have the No_Multiple_Elaboration restriction, since for the
1836 -- static model, that's the only purpose of the counter (to avoid
1837 -- multiple elaboration).
1839 elsif Restriction_Active (No_Multiple_Elaboration) then
1843 -- Here we need the elaboration entity
1845 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1846 -- name with dots replaced by double underscore. We have to manually
1847 -- construct this name, since it will be elaborated in the outer scope,
1848 -- and thus will not have the unit name automatically prepended.
1850 Set_Package_Name (Spec_Id);
1851 Add_Str_To_Name_Buffer ("_E");
1853 -- Create elaboration counter
1855 Elab_Ent := Make_Defining_Identifier (Loc, Chars => Name_Find);
1856 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
1859 Make_Object_Declaration (Loc,
1860 Defining_Identifier => Elab_Ent,
1861 Object_Definition =>
1862 New_Occurrence_Of (Standard_Short_Integer, Loc),
1863 Expression => Make_Integer_Literal (Loc, Uint_0));
1865 Push_Scope (Standard_Standard);
1866 Add_Global_Declaration (Decl);
1869 -- Reset True_Constant indication, since we will indeed assign a value
1870 -- to the variable in the binder main. We also kill the Current_Value
1871 -- and Last_Assignment fields for the same reason.
1873 Set_Is_True_Constant (Elab_Ent, False);
1874 Set_Current_Value (Elab_Ent, Empty);
1875 Set_Last_Assignment (Elab_Ent, Empty);
1877 -- We do not want any further qualification of the name (if we did not
1878 -- do this, we would pick up the name of the generic package in the case
1879 -- of a library level generic instantiation).
1881 Set_Has_Qualified_Name (Elab_Ent);
1882 Set_Has_Fully_Qualified_Name (Elab_Ent);
1883 end Build_Elaboration_Entity;
1885 --------------------------------
1886 -- Build_Explicit_Dereference --
1887 --------------------------------
1889 procedure Build_Explicit_Dereference
1893 Loc : constant Source_Ptr := Sloc (Expr);
1898 -- An entity of a type with a reference aspect is overloaded with
1899 -- both interpretations: with and without the dereference. Now that
1900 -- the dereference is made explicit, set the type of the node properly,
1901 -- to prevent anomalies in the backend. Same if the expression is an
1902 -- overloaded function call whose return type has a reference aspect.
1904 if Is_Entity_Name (Expr) then
1905 Set_Etype (Expr, Etype (Entity (Expr)));
1907 -- The designated entity will not be examined again when resolving
1908 -- the dereference, so generate a reference to it now.
1910 Generate_Reference (Entity (Expr), Expr);
1912 elsif Nkind (Expr) = N_Function_Call then
1914 -- If the name of the indexing function is overloaded, locate the one
1915 -- whose return type has an implicit dereference on the desired
1916 -- discriminant, and set entity and type of function call.
1918 if Is_Overloaded (Name (Expr)) then
1919 Get_First_Interp (Name (Expr), I, It);
1921 while Present (It.Nam) loop
1922 if Ekind ((It.Typ)) = E_Record_Type
1923 and then First_Entity ((It.Typ)) = Disc
1925 Set_Entity (Name (Expr), It.Nam);
1926 Set_Etype (Name (Expr), Etype (It.Nam));
1930 Get_Next_Interp (I, It);
1934 -- Set type of call from resolved function name.
1936 Set_Etype (Expr, Etype (Name (Expr)));
1939 Set_Is_Overloaded (Expr, False);
1941 -- The expression will often be a generalized indexing that yields a
1942 -- container element that is then dereferenced, in which case the
1943 -- generalized indexing call is also non-overloaded.
1945 if Nkind (Expr) = N_Indexed_Component
1946 and then Present (Generalized_Indexing (Expr))
1948 Set_Is_Overloaded (Generalized_Indexing (Expr), False);
1952 Make_Explicit_Dereference (Loc,
1954 Make_Selected_Component (Loc,
1955 Prefix => Relocate_Node (Expr),
1956 Selector_Name => New_Occurrence_Of (Disc, Loc))));
1957 Set_Etype (Prefix (Expr), Etype (Disc));
1958 Set_Etype (Expr, Designated_Type (Etype (Disc)));
1959 end Build_Explicit_Dereference;
1961 ---------------------------
1962 -- Build_Overriding_Spec --
1963 ---------------------------
1965 function Build_Overriding_Spec
1967 Typ : Entity_Id) return Node_Id
1969 Loc : constant Source_Ptr := Sloc (Typ);
1970 Par_Typ : constant Entity_Id := Find_Dispatching_Type (Op);
1971 Spec : constant Node_Id := Specification (Unit_Declaration_Node (Op));
1973 Formal_Spec : Node_Id;
1974 Formal_Type : Node_Id;
1978 New_Spec := Copy_Subprogram_Spec (Spec);
1980 Formal_Spec := First (Parameter_Specifications (New_Spec));
1981 while Present (Formal_Spec) loop
1982 Formal_Type := Parameter_Type (Formal_Spec);
1984 if Is_Entity_Name (Formal_Type)
1985 and then Entity (Formal_Type) = Par_Typ
1987 Rewrite (Formal_Type, New_Occurrence_Of (Typ, Loc));
1990 -- Nothing needs to be done for access parameters
1996 end Build_Overriding_Spec;
1998 -----------------------------------
1999 -- Cannot_Raise_Constraint_Error --
2000 -----------------------------------
2002 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
2004 if Compile_Time_Known_Value (Expr) then
2007 elsif Do_Range_Check (Expr) then
2010 elsif Raises_Constraint_Error (Expr) then
2014 case Nkind (Expr) is
2015 when N_Identifier =>
2018 when N_Expanded_Name =>
2021 when N_Selected_Component =>
2022 return not Do_Discriminant_Check (Expr);
2024 when N_Attribute_Reference =>
2025 if Do_Overflow_Check (Expr) then
2028 elsif No (Expressions (Expr)) then
2036 N := First (Expressions (Expr));
2037 while Present (N) loop
2038 if Cannot_Raise_Constraint_Error (N) then
2049 when N_Type_Conversion =>
2050 if Do_Overflow_Check (Expr)
2051 or else Do_Length_Check (Expr)
2052 or else Do_Tag_Check (Expr)
2056 return Cannot_Raise_Constraint_Error (Expression (Expr));
2059 when N_Unchecked_Type_Conversion =>
2060 return Cannot_Raise_Constraint_Error (Expression (Expr));
2063 if Do_Overflow_Check (Expr) then
2066 return Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
2073 if Do_Division_Check (Expr)
2075 Do_Overflow_Check (Expr)
2080 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
2082 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
2101 | N_Op_Shift_Right_Arithmetic
2105 if Do_Overflow_Check (Expr) then
2109 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
2111 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
2118 end Cannot_Raise_Constraint_Error;
2120 -----------------------------------------
2121 -- Check_Dynamically_Tagged_Expression --
2122 -----------------------------------------
2124 procedure Check_Dynamically_Tagged_Expression
2127 Related_Nod : Node_Id)
2130 pragma Assert (Is_Tagged_Type (Typ));
2132 -- In order to avoid spurious errors when analyzing the expanded code,
2133 -- this check is done only for nodes that come from source and for
2134 -- actuals of generic instantiations.
2136 if (Comes_From_Source (Related_Nod)
2137 or else In_Generic_Actual (Expr))
2138 and then (Is_Class_Wide_Type (Etype (Expr))
2139 or else Is_Dynamically_Tagged (Expr))
2140 and then not Is_Class_Wide_Type (Typ)
2142 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
2144 end Check_Dynamically_Tagged_Expression;
2146 --------------------------
2147 -- Check_Fully_Declared --
2148 --------------------------
2150 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
2152 if Ekind (T) = E_Incomplete_Type then
2154 -- Ada 2005 (AI-50217): If the type is available through a limited
2155 -- with_clause, verify that its full view has been analyzed.
2157 if From_Limited_With (T)
2158 and then Present (Non_Limited_View (T))
2159 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
2161 -- The non-limited view is fully declared
2167 ("premature usage of incomplete}", N, First_Subtype (T));
2170 -- Need comments for these tests ???
2172 elsif Has_Private_Component (T)
2173 and then not Is_Generic_Type (Root_Type (T))
2174 and then not In_Spec_Expression
2176 -- Special case: if T is the anonymous type created for a single
2177 -- task or protected object, use the name of the source object.
2179 if Is_Concurrent_Type (T)
2180 and then not Comes_From_Source (T)
2181 and then Nkind (N) = N_Object_Declaration
2184 ("type of& has incomplete component",
2185 N, Defining_Identifier (N));
2188 ("premature usage of incomplete}",
2189 N, First_Subtype (T));
2192 end Check_Fully_Declared;
2194 -------------------------------------------
2195 -- Check_Function_With_Address_Parameter --
2196 -------------------------------------------
2198 procedure Check_Function_With_Address_Parameter (Subp_Id : Entity_Id) is
2203 F := First_Formal (Subp_Id);
2204 while Present (F) loop
2207 if Is_Private_Type (T) and then Present (Full_View (T)) then
2211 if Is_Descendant_Of_Address (T) or else Is_Limited_Type (T) then
2212 Set_Is_Pure (Subp_Id, False);
2218 end Check_Function_With_Address_Parameter;
2220 -------------------------------------
2221 -- Check_Function_Writable_Actuals --
2222 -------------------------------------
2224 procedure Check_Function_Writable_Actuals (N : Node_Id) is
2225 Writable_Actuals_List : Elist_Id := No_Elist;
2226 Identifiers_List : Elist_Id := No_Elist;
2227 Aggr_Error_Node : Node_Id := Empty;
2228 Error_Node : Node_Id := Empty;
2230 procedure Collect_Identifiers (N : Node_Id);
2231 -- In a single traversal of subtree N collect in Writable_Actuals_List
2232 -- all the actuals of functions with writable actuals, and in the list
2233 -- Identifiers_List collect all the identifiers that are not actuals of
2234 -- functions with writable actuals. If a writable actual is referenced
2235 -- twice as writable actual then Error_Node is set to reference its
2236 -- second occurrence, the error is reported, and the tree traversal
2239 procedure Preanalyze_Without_Errors (N : Node_Id);
2240 -- Preanalyze N without reporting errors. Very dubious, you can't just
2241 -- go analyzing things more than once???
2243 -------------------------
2244 -- Collect_Identifiers --
2245 -------------------------
2247 procedure Collect_Identifiers (N : Node_Id) is
2249 function Check_Node (N : Node_Id) return Traverse_Result;
2250 -- Process a single node during the tree traversal to collect the
2251 -- writable actuals of functions and all the identifiers which are
2252 -- not writable actuals of functions.
2254 function Contains (List : Elist_Id; N : Node_Id) return Boolean;
2255 -- Returns True if List has a node whose Entity is Entity (N)
2261 function Check_Node (N : Node_Id) return Traverse_Result is
2262 Is_Writable_Actual : Boolean := False;
2266 if Nkind (N) = N_Identifier then
2268 -- No analysis possible if the entity is not decorated
2270 if No (Entity (N)) then
2273 -- Don't collect identifiers of packages, called functions, etc
2275 elsif Ekind_In (Entity (N), E_Package,
2282 -- For rewritten nodes, continue the traversal in the original
2283 -- subtree. Needed to handle aggregates in original expressions
2284 -- extracted from the tree by Remove_Side_Effects.
2286 elsif Is_Rewrite_Substitution (N) then
2287 Collect_Identifiers (Original_Node (N));
2290 -- For now we skip aggregate discriminants, since they require
2291 -- performing the analysis in two phases to identify conflicts:
2292 -- first one analyzing discriminants and second one analyzing
2293 -- the rest of components (since at run time, discriminants are
2294 -- evaluated prior to components): too much computation cost
2295 -- to identify a corner case???
2297 elsif Nkind (Parent (N)) = N_Component_Association
2298 and then Nkind_In (Parent (Parent (N)),
2300 N_Extension_Aggregate)
2303 Choice : constant Node_Id := First (Choices (Parent (N)));
2306 if Ekind (Entity (N)) = E_Discriminant then
2309 elsif Expression (Parent (N)) = N
2310 and then Nkind (Choice) = N_Identifier
2311 and then Ekind (Entity (Choice)) = E_Discriminant
2317 -- Analyze if N is a writable actual of a function
2319 elsif Nkind (Parent (N)) = N_Function_Call then
2321 Call : constant Node_Id := Parent (N);
2326 Id := Get_Called_Entity (Call);
2328 -- In case of previous error, no check is possible
2334 if Ekind_In (Id, E_Function, E_Generic_Function)
2335 and then Has_Out_Or_In_Out_Parameter (Id)
2337 Formal := First_Formal (Id);
2338 Actual := First_Actual (Call);
2339 while Present (Actual) and then Present (Formal) loop
2341 if Ekind_In (Formal, E_Out_Parameter,
2344 Is_Writable_Actual := True;
2350 Next_Formal (Formal);
2351 Next_Actual (Actual);
2357 if Is_Writable_Actual then
2359 -- Skip checking the error in non-elementary types since
2360 -- RM 6.4.1(6.15/3) is restricted to elementary types, but
2361 -- store this actual in Writable_Actuals_List since it is
2362 -- needed to perform checks on other constructs that have
2363 -- arbitrary order of evaluation (for example, aggregates).
2365 if not Is_Elementary_Type (Etype (N)) then
2366 if not Contains (Writable_Actuals_List, N) then
2367 Append_New_Elmt (N, To => Writable_Actuals_List);
2370 -- Second occurrence of an elementary type writable actual
2372 elsif Contains (Writable_Actuals_List, N) then
2374 -- Report the error on the second occurrence of the
2375 -- identifier. We cannot assume that N is the second
2376 -- occurrence (according to their location in the
2377 -- sources), since Traverse_Func walks through Field2
2378 -- last (see comment in the body of Traverse_Func).
2384 Elmt := First_Elmt (Writable_Actuals_List);
2385 while Present (Elmt)
2386 and then Entity (Node (Elmt)) /= Entity (N)
2391 if Sloc (N) > Sloc (Node (Elmt)) then
2394 Error_Node := Node (Elmt);
2398 ("value may be affected by call to & "
2399 & "because order of evaluation is arbitrary",
2404 -- First occurrence of a elementary type writable actual
2407 Append_New_Elmt (N, To => Writable_Actuals_List);
2411 if Identifiers_List = No_Elist then
2412 Identifiers_List := New_Elmt_List;
2415 Append_Unique_Elmt (N, Identifiers_List);
2428 N : Node_Id) return Boolean
2430 pragma Assert (Nkind (N) in N_Has_Entity);
2435 if List = No_Elist then
2439 Elmt := First_Elmt (List);
2440 while Present (Elmt) loop
2441 if Entity (Node (Elmt)) = Entity (N) then
2455 procedure Do_Traversal is new Traverse_Proc (Check_Node);
2456 -- The traversal procedure
2458 -- Start of processing for Collect_Identifiers
2461 if Present (Error_Node) then
2465 if Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
2470 end Collect_Identifiers;
2472 -------------------------------
2473 -- Preanalyze_Without_Errors --
2474 -------------------------------
2476 procedure Preanalyze_Without_Errors (N : Node_Id) is
2477 Status : constant Boolean := Get_Ignore_Errors;
2479 Set_Ignore_Errors (True);
2481 Set_Ignore_Errors (Status);
2482 end Preanalyze_Without_Errors;
2484 -- Start of processing for Check_Function_Writable_Actuals
2487 -- The check only applies to Ada 2012 code on which Check_Actuals has
2488 -- been set, and only to constructs that have multiple constituents
2489 -- whose order of evaluation is not specified by the language.
2491 if Ada_Version < Ada_2012
2492 or else not Check_Actuals (N)
2493 or else (not (Nkind (N) in N_Op)
2494 and then not (Nkind (N) in N_Membership_Test)
2495 and then not Nkind_In (N, N_Range,
2497 N_Extension_Aggregate,
2498 N_Full_Type_Declaration,
2500 N_Procedure_Call_Statement,
2501 N_Entry_Call_Statement))
2502 or else (Nkind (N) = N_Full_Type_Declaration
2503 and then not Is_Record_Type (Defining_Identifier (N)))
2505 -- In addition, this check only applies to source code, not to code
2506 -- generated by constraint checks.
2508 or else not Comes_From_Source (N)
2513 -- If a construct C has two or more direct constituents that are names
2514 -- or expressions whose evaluation may occur in an arbitrary order, at
2515 -- least one of which contains a function call with an in out or out
2516 -- parameter, then the construct is legal only if: for each name N that
2517 -- is passed as a parameter of mode in out or out to some inner function
2518 -- call C2 (not including the construct C itself), there is no other
2519 -- name anywhere within a direct constituent of the construct C other
2520 -- than the one containing C2, that is known to refer to the same
2521 -- object (RM 6.4.1(6.17/3)).
2525 Collect_Identifiers (Low_Bound (N));
2526 Collect_Identifiers (High_Bound (N));
2528 when N_Membership_Test
2535 Collect_Identifiers (Left_Opnd (N));
2537 if Present (Right_Opnd (N)) then
2538 Collect_Identifiers (Right_Opnd (N));
2541 if Nkind_In (N, N_In, N_Not_In)
2542 and then Present (Alternatives (N))
2544 Expr := First (Alternatives (N));
2545 while Present (Expr) loop
2546 Collect_Identifiers (Expr);
2553 when N_Full_Type_Declaration =>
2555 function Get_Record_Part (N : Node_Id) return Node_Id;
2556 -- Return the record part of this record type definition
2558 function Get_Record_Part (N : Node_Id) return Node_Id is
2559 Type_Def : constant Node_Id := Type_Definition (N);
2561 if Nkind (Type_Def) = N_Derived_Type_Definition then
2562 return Record_Extension_Part (Type_Def);
2566 end Get_Record_Part;
2569 Def_Id : Entity_Id := Defining_Identifier (N);
2570 Rec : Node_Id := Get_Record_Part (N);
2573 -- No need to perform any analysis if the record has no
2576 if No (Rec) or else No (Component_List (Rec)) then
2580 -- Collect the identifiers starting from the deepest
2581 -- derivation. Done to report the error in the deepest
2585 if Present (Component_List (Rec)) then
2586 Comp := First (Component_Items (Component_List (Rec)));
2587 while Present (Comp) loop
2588 if Nkind (Comp) = N_Component_Declaration
2589 and then Present (Expression (Comp))
2591 Collect_Identifiers (Expression (Comp));
2598 exit when No (Underlying_Type (Etype (Def_Id)))
2599 or else Base_Type (Underlying_Type (Etype (Def_Id)))
2602 Def_Id := Base_Type (Underlying_Type (Etype (Def_Id)));
2603 Rec := Get_Record_Part (Parent (Def_Id));
2607 when N_Entry_Call_Statement
2611 Id : constant Entity_Id := Get_Called_Entity (N);
2616 Formal := First_Formal (Id);
2617 Actual := First_Actual (N);
2618 while Present (Actual) and then Present (Formal) loop
2619 if Ekind_In (Formal, E_Out_Parameter,
2622 Collect_Identifiers (Actual);
2625 Next_Formal (Formal);
2626 Next_Actual (Actual);
2631 | N_Extension_Aggregate
2636 Comp_Expr : Node_Id;
2639 -- Handle the N_Others_Choice of array aggregates with static
2640 -- bounds. There is no need to perform this analysis in
2641 -- aggregates without static bounds since we cannot evaluate
2642 -- if the N_Others_Choice covers several elements. There is
2643 -- no need to handle the N_Others choice of record aggregates
2644 -- since at this stage it has been already expanded by
2645 -- Resolve_Record_Aggregate.
2647 if Is_Array_Type (Etype (N))
2648 and then Nkind (N) = N_Aggregate
2649 and then Present (Aggregate_Bounds (N))
2650 and then Compile_Time_Known_Bounds (Etype (N))
2651 and then Expr_Value (High_Bound (Aggregate_Bounds (N)))
2653 Expr_Value (Low_Bound (Aggregate_Bounds (N)))
2656 Count_Components : Uint := Uint_0;
2657 Num_Components : Uint;
2658 Others_Assoc : Node_Id;
2659 Others_Choice : Node_Id := Empty;
2660 Others_Box_Present : Boolean := False;
2663 -- Count positional associations
2665 if Present (Expressions (N)) then
2666 Comp_Expr := First (Expressions (N));
2667 while Present (Comp_Expr) loop
2668 Count_Components := Count_Components + 1;
2673 -- Count the rest of elements and locate the N_Others
2676 Assoc := First (Component_Associations (N));
2677 while Present (Assoc) loop
2678 Choice := First (Choices (Assoc));
2679 while Present (Choice) loop
2680 if Nkind (Choice) = N_Others_Choice then
2681 Others_Assoc := Assoc;
2682 Others_Choice := Choice;
2683 Others_Box_Present := Box_Present (Assoc);
2685 -- Count several components
2687 elsif Nkind_In (Choice, N_Range,
2688 N_Subtype_Indication)
2689 or else (Is_Entity_Name (Choice)
2690 and then Is_Type (Entity (Choice)))
2695 Get_Index_Bounds (Choice, L, H);
2697 (Compile_Time_Known_Value (L)
2698 and then Compile_Time_Known_Value (H));
2701 + Expr_Value (H) - Expr_Value (L) + 1;
2704 -- Count single component. No other case available
2705 -- since we are handling an aggregate with static
2709 pragma Assert (Is_OK_Static_Expression (Choice)
2710 or else Nkind (Choice) = N_Identifier
2711 or else Nkind (Choice) = N_Integer_Literal);
2713 Count_Components := Count_Components + 1;
2723 Expr_Value (High_Bound (Aggregate_Bounds (N))) -
2724 Expr_Value (Low_Bound (Aggregate_Bounds (N))) + 1;
2726 pragma Assert (Count_Components <= Num_Components);
2728 -- Handle the N_Others choice if it covers several
2731 if Present (Others_Choice)
2732 and then (Num_Components - Count_Components) > 1
2734 if not Others_Box_Present then
2736 -- At this stage, if expansion is active, the
2737 -- expression of the others choice has not been
2738 -- analyzed. Hence we generate a duplicate and
2739 -- we analyze it silently to have available the
2740 -- minimum decoration required to collect the
2743 if not Expander_Active then
2744 Comp_Expr := Expression (Others_Assoc);
2747 New_Copy_Tree (Expression (Others_Assoc));
2748 Preanalyze_Without_Errors (Comp_Expr);
2751 Collect_Identifiers (Comp_Expr);
2753 if Writable_Actuals_List /= No_Elist then
2755 -- As suggested by Robert, at current stage we
2756 -- report occurrences of this case as warnings.
2759 ("writable function parameter may affect "
2760 & "value in other component because order "
2761 & "of evaluation is unspecified??",
2762 Node (First_Elmt (Writable_Actuals_List)));
2768 -- For an array aggregate, a discrete_choice_list that has
2769 -- a nonstatic range is considered as two or more separate
2770 -- occurrences of the expression (RM 6.4.1(20/3)).
2772 elsif Is_Array_Type (Etype (N))
2773 and then Nkind (N) = N_Aggregate
2774 and then Present (Aggregate_Bounds (N))
2775 and then not Compile_Time_Known_Bounds (Etype (N))
2777 -- Collect identifiers found in the dynamic bounds
2780 Count_Components : Natural := 0;
2781 Low, High : Node_Id;
2784 Assoc := First (Component_Associations (N));
2785 while Present (Assoc) loop
2786 Choice := First (Choices (Assoc));
2787 while Present (Choice) loop
2788 if Nkind_In (Choice, N_Range,
2789 N_Subtype_Indication)
2790 or else (Is_Entity_Name (Choice)
2791 and then Is_Type (Entity (Choice)))
2793 Get_Index_Bounds (Choice, Low, High);
2795 if not Compile_Time_Known_Value (Low) then
2796 Collect_Identifiers (Low);
2798 if No (Aggr_Error_Node) then
2799 Aggr_Error_Node := Low;
2803 if not Compile_Time_Known_Value (High) then
2804 Collect_Identifiers (High);
2806 if No (Aggr_Error_Node) then
2807 Aggr_Error_Node := High;
2811 -- The RM rule is violated if there is more than
2812 -- a single choice in a component association.
2815 Count_Components := Count_Components + 1;
2817 if No (Aggr_Error_Node)
2818 and then Count_Components > 1
2820 Aggr_Error_Node := Choice;
2823 if not Compile_Time_Known_Value (Choice) then
2824 Collect_Identifiers (Choice);
2836 -- Handle ancestor part of extension aggregates
2838 if Nkind (N) = N_Extension_Aggregate then
2839 Collect_Identifiers (Ancestor_Part (N));
2842 -- Handle positional associations
2844 if Present (Expressions (N)) then
2845 Comp_Expr := First (Expressions (N));
2846 while Present (Comp_Expr) loop
2847 if not Is_OK_Static_Expression (Comp_Expr) then
2848 Collect_Identifiers (Comp_Expr);
2855 -- Handle discrete associations
2857 if Present (Component_Associations (N)) then
2858 Assoc := First (Component_Associations (N));
2859 while Present (Assoc) loop
2861 if not Box_Present (Assoc) then
2862 Choice := First (Choices (Assoc));
2863 while Present (Choice) loop
2865 -- For now we skip discriminants since it requires
2866 -- performing the analysis in two phases: first one
2867 -- analyzing discriminants and second one analyzing
2868 -- the rest of components since discriminants are
2869 -- evaluated prior to components: too much extra
2870 -- work to detect a corner case???
2872 if Nkind (Choice) in N_Has_Entity
2873 and then Present (Entity (Choice))
2874 and then Ekind (Entity (Choice)) = E_Discriminant
2878 elsif Box_Present (Assoc) then
2882 if not Analyzed (Expression (Assoc)) then
2884 New_Copy_Tree (Expression (Assoc));
2885 Set_Parent (Comp_Expr, Parent (N));
2886 Preanalyze_Without_Errors (Comp_Expr);
2888 Comp_Expr := Expression (Assoc);
2891 Collect_Identifiers (Comp_Expr);
2907 -- No further action needed if we already reported an error
2909 if Present (Error_Node) then
2913 -- Check violation of RM 6.20/3 in aggregates
2915 if Present (Aggr_Error_Node)
2916 and then Writable_Actuals_List /= No_Elist
2919 ("value may be affected by call in other component because they "
2920 & "are evaluated in unspecified order",
2921 Node (First_Elmt (Writable_Actuals_List)));
2925 -- Check if some writable argument of a function is referenced
2927 if Writable_Actuals_List /= No_Elist
2928 and then Identifiers_List /= No_Elist
2935 Elmt_1 := First_Elmt (Writable_Actuals_List);
2936 while Present (Elmt_1) loop
2937 Elmt_2 := First_Elmt (Identifiers_List);
2938 while Present (Elmt_2) loop
2939 if Entity (Node (Elmt_1)) = Entity (Node (Elmt_2)) then
2940 case Nkind (Parent (Node (Elmt_2))) is
2942 | N_Component_Association
2943 | N_Component_Declaration
2946 ("value may be affected by call in other "
2947 & "component because they are evaluated "
2948 & "in unspecified order",
2955 ("value may be affected by call in other "
2956 & "alternative because they are evaluated "
2957 & "in unspecified order",
2962 ("value of actual may be affected by call in "
2963 & "other actual because they are evaluated "
2964 & "in unspecified order",
2976 end Check_Function_Writable_Actuals;
2978 --------------------------------
2979 -- Check_Implicit_Dereference --
2980 --------------------------------
2982 procedure Check_Implicit_Dereference (N : Node_Id; Typ : Entity_Id) is
2988 if Nkind (N) = N_Indexed_Component
2989 and then Present (Generalized_Indexing (N))
2991 Nam := Generalized_Indexing (N);
2996 if Ada_Version < Ada_2012
2997 or else not Has_Implicit_Dereference (Base_Type (Typ))
3001 elsif not Comes_From_Source (N)
3002 and then Nkind (N) /= N_Indexed_Component
3006 elsif Is_Entity_Name (Nam) and then Is_Type (Entity (Nam)) then
3010 Disc := First_Discriminant (Typ);
3011 while Present (Disc) loop
3012 if Has_Implicit_Dereference (Disc) then
3013 Desig := Designated_Type (Etype (Disc));
3014 Add_One_Interp (Nam, Disc, Desig);
3016 -- If the node is a generalized indexing, add interpretation
3017 -- to that node as well, for subsequent resolution.
3019 if Nkind (N) = N_Indexed_Component then
3020 Add_One_Interp (N, Disc, Desig);
3023 -- If the operation comes from a generic unit and the context
3024 -- is a selected component, the selector name may be global
3025 -- and set in the instance already. Remove the entity to
3026 -- force resolution of the selected component, and the
3027 -- generation of an explicit dereference if needed.
3030 and then Nkind (Parent (Nam)) = N_Selected_Component
3032 Set_Entity (Selector_Name (Parent (Nam)), Empty);
3038 Next_Discriminant (Disc);
3041 end Check_Implicit_Dereference;
3043 ----------------------------------
3044 -- Check_Internal_Protected_Use --
3045 ----------------------------------
3047 procedure Check_Internal_Protected_Use (N : Node_Id; Nam : Entity_Id) is
3055 while Present (S) loop
3056 if S = Standard_Standard then
3059 elsif Ekind (S) = E_Function
3060 and then Ekind (Scope (S)) = E_Protected_Type
3070 and then Scope (Nam) = Prot
3071 and then Ekind (Nam) /= E_Function
3073 -- An indirect function call (e.g. a callback within a protected
3074 -- function body) is not statically illegal. If the access type is
3075 -- anonymous and is the type of an access parameter, the scope of Nam
3076 -- will be the protected type, but it is not a protected operation.
3078 if Ekind (Nam) = E_Subprogram_Type
3079 and then Nkind (Associated_Node_For_Itype (Nam)) =
3080 N_Function_Specification
3084 elsif Nkind (N) = N_Subprogram_Renaming_Declaration then
3086 ("within protected function cannot use protected procedure in "
3087 & "renaming or as generic actual", N);
3089 elsif Nkind (N) = N_Attribute_Reference then
3091 ("within protected function cannot take access of protected "
3096 ("within protected function, protected object is constant", N);
3098 ("\cannot call operation that may modify it", N);
3102 -- Verify that an internal call does not appear within a precondition
3103 -- of a protected operation. This implements AI12-0166.
3104 -- The precondition aspect has been rewritten as a pragma Precondition
3105 -- and we check whether the scope of the called subprogram is the same
3106 -- as that of the entity to which the aspect applies.
3108 if Convention (Nam) = Convention_Protected then
3114 while Present (P) loop
3115 if Nkind (P) = N_Pragma
3116 and then Chars (Pragma_Identifier (P)) = Name_Precondition
3117 and then From_Aspect_Specification (P)
3119 Scope (Entity (Corresponding_Aspect (P))) = Scope (Nam)
3122 ("internal call cannot appear in precondition of "
3123 & "protected operation", N);
3126 elsif Nkind (P) = N_Pragma
3127 and then Chars (Pragma_Identifier (P)) = Name_Contract_Cases
3129 -- Check whether call is in a case guard. It is legal in a
3133 while Present (P) loop
3134 if Nkind (Parent (P)) = N_Component_Association
3135 and then P /= Expression (Parent (P))
3138 ("internal call cannot appear in case guard in a "
3139 & "contract case", N);
3147 elsif Nkind (P) = N_Parameter_Specification
3148 and then Scope (Current_Scope) = Scope (Nam)
3149 and then Nkind_In (Parent (P), N_Entry_Declaration,
3150 N_Subprogram_Declaration)
3153 ("internal call cannot appear in default for formal of "
3154 & "protected operation", N);
3162 end Check_Internal_Protected_Use;
3164 ---------------------------------------
3165 -- Check_Later_Vs_Basic_Declarations --
3166 ---------------------------------------
3168 procedure Check_Later_Vs_Basic_Declarations
3170 During_Parsing : Boolean)
3172 Body_Sloc : Source_Ptr;
3175 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
3176 -- Return whether Decl is considered as a declarative item.
3177 -- When During_Parsing is True, the semantics of Ada 83 is followed.
3178 -- When During_Parsing is False, the semantics of SPARK is followed.
3180 -------------------------------
3181 -- Is_Later_Declarative_Item --
3182 -------------------------------
3184 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
3186 if Nkind (Decl) in N_Later_Decl_Item then
3189 elsif Nkind (Decl) = N_Pragma then
3192 elsif During_Parsing then
3195 -- In SPARK, a package declaration is not considered as a later
3196 -- declarative item.
3198 elsif Nkind (Decl) = N_Package_Declaration then
3201 -- In SPARK, a renaming is considered as a later declarative item
3203 elsif Nkind (Decl) in N_Renaming_Declaration then
3209 end Is_Later_Declarative_Item;
3211 -- Start of processing for Check_Later_Vs_Basic_Declarations
3214 Decl := First (Decls);
3216 -- Loop through sequence of basic declarative items
3218 Outer : while Present (Decl) loop
3219 if not Nkind_In (Decl, N_Subprogram_Body, N_Package_Body, N_Task_Body)
3220 and then Nkind (Decl) not in N_Body_Stub
3224 -- Once a body is encountered, we only allow later declarative
3225 -- items. The inner loop checks the rest of the list.
3228 Body_Sloc := Sloc (Decl);
3230 Inner : while Present (Decl) loop
3231 if not Is_Later_Declarative_Item (Decl) then
3232 if During_Parsing then
3233 if Ada_Version = Ada_83 then
3234 Error_Msg_Sloc := Body_Sloc;
3236 ("(Ada 83) decl cannot appear after body#", Decl);
3239 Error_Msg_Sloc := Body_Sloc;
3240 Check_SPARK_05_Restriction
3241 ("decl cannot appear after body#", Decl);
3249 end Check_Later_Vs_Basic_Declarations;
3251 ---------------------------
3252 -- Check_No_Hidden_State --
3253 ---------------------------
3255 procedure Check_No_Hidden_State (Id : Entity_Id) is
3256 Context : Entity_Id := Empty;
3257 Not_Visible : Boolean := False;
3261 pragma Assert (Ekind_In (Id, E_Abstract_State, E_Variable));
3263 -- Nothing to do for internally-generated abstract states and variables
3264 -- because they do not represent the hidden state of the source unit.
3266 if not Comes_From_Source (Id) then
3270 -- Find the proper context where the object or state appears
3273 while Present (Scop) loop
3276 -- Keep track of the context's visibility
3278 Not_Visible := Not_Visible or else In_Private_Part (Context);
3280 -- Prevent the search from going too far
3282 if Context = Standard_Standard then
3285 -- Objects and states that appear immediately within a subprogram or
3286 -- inside a construct nested within a subprogram do not introduce a
3287 -- hidden state. They behave as local variable declarations.
3289 elsif Is_Subprogram (Context) then
3292 -- When examining a package body, use the entity of the spec as it
3293 -- carries the abstract state declarations.
3295 elsif Ekind (Context) = E_Package_Body then
3296 Context := Spec_Entity (Context);
3299 -- Stop the traversal when a package subject to a null abstract state
3302 if Ekind_In (Context, E_Generic_Package, E_Package)
3303 and then Has_Null_Abstract_State (Context)
3308 Scop := Scope (Scop);
3311 -- At this point we know that there is at least one package with a null
3312 -- abstract state in visibility. Emit an error message unconditionally
3313 -- if the entity being processed is a state because the placement of the
3314 -- related package is irrelevant. This is not the case for objects as
3315 -- the intermediate context matters.
3317 if Present (Context)
3318 and then (Ekind (Id) = E_Abstract_State or else Not_Visible)
3320 Error_Msg_N ("cannot introduce hidden state &", Id);
3321 Error_Msg_NE ("\package & has null abstract state", Id, Context);
3323 end Check_No_Hidden_State;
3325 ----------------------------------------
3326 -- Check_Nonvolatile_Function_Profile --
3327 ----------------------------------------
3329 procedure Check_Nonvolatile_Function_Profile (Func_Id : Entity_Id) is
3333 -- Inspect all formal parameters
3335 Formal := First_Formal (Func_Id);
3336 while Present (Formal) loop
3337 if Is_Effectively_Volatile (Etype (Formal)) then
3339 ("nonvolatile function & cannot have a volatile parameter",
3343 Next_Formal (Formal);
3346 -- Inspect the return type
3348 if Is_Effectively_Volatile (Etype (Func_Id)) then
3350 ("nonvolatile function & cannot have a volatile return type",
3351 Result_Definition (Parent (Func_Id)), Func_Id);
3353 end Check_Nonvolatile_Function_Profile;
3355 -----------------------------
3356 -- Check_Part_Of_Reference --
3357 -----------------------------
3359 procedure Check_Part_Of_Reference (Var_Id : Entity_Id; Ref : Node_Id) is
3360 function Is_Enclosing_Package_Body
3361 (Body_Decl : Node_Id;
3362 Obj_Id : Entity_Id) return Boolean;
3363 pragma Inline (Is_Enclosing_Package_Body);
3364 -- Determine whether package body Body_Decl or its corresponding spec
3365 -- immediately encloses the declaration of object Obj_Id.
3367 function Is_Internal_Declaration_Or_Body
3368 (Decl : Node_Id) return Boolean;
3369 pragma Inline (Is_Internal_Declaration_Or_Body);
3370 -- Determine whether declaration or body denoted by Decl is internal
3372 function Is_Single_Declaration_Or_Body
3374 Conc_Typ : Entity_Id) return Boolean;
3375 pragma Inline (Is_Single_Declaration_Or_Body);
3376 -- Determine whether protected/task declaration or body denoted by Decl
3377 -- belongs to single concurrent type Conc_Typ.
3379 function Is_Single_Task_Pragma
3381 Task_Typ : Entity_Id) return Boolean;
3382 pragma Inline (Is_Single_Task_Pragma);
3383 -- Determine whether pragma Prag belongs to single task type Task_Typ
3385 -------------------------------
3386 -- Is_Enclosing_Package_Body --
3387 -------------------------------
3389 function Is_Enclosing_Package_Body
3390 (Body_Decl : Node_Id;
3391 Obj_Id : Entity_Id) return Boolean
3393 Obj_Context : Node_Id;
3396 -- Find the context of the object declaration
3398 Obj_Context := Parent (Declaration_Node (Obj_Id));
3400 if Nkind (Obj_Context) = N_Package_Specification then
3401 Obj_Context := Parent (Obj_Context);
3404 -- The object appears immediately within the package body
3406 if Obj_Context = Body_Decl then
3409 -- The object appears immediately within the corresponding spec
3411 elsif Nkind (Obj_Context) = N_Package_Declaration
3412 and then Unit_Declaration_Node (Corresponding_Spec (Body_Decl)) =
3419 end Is_Enclosing_Package_Body;
3421 -------------------------------------
3422 -- Is_Internal_Declaration_Or_Body --
3423 -------------------------------------
3425 function Is_Internal_Declaration_Or_Body
3426 (Decl : Node_Id) return Boolean
3429 if Comes_From_Source (Decl) then
3432 -- A body generated for an expression function which has not been
3433 -- inserted into the tree yet (In_Spec_Expression is True) is not
3434 -- considered internal.
3436 elsif Nkind (Decl) = N_Subprogram_Body
3437 and then Was_Expression_Function (Decl)
3438 and then not In_Spec_Expression
3444 end Is_Internal_Declaration_Or_Body;
3446 -----------------------------------
3447 -- Is_Single_Declaration_Or_Body --
3448 -----------------------------------
3450 function Is_Single_Declaration_Or_Body
3452 Conc_Typ : Entity_Id) return Boolean
3454 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Decl);
3458 Present (Anonymous_Object (Spec_Id))
3459 and then Anonymous_Object (Spec_Id) = Conc_Typ;
3460 end Is_Single_Declaration_Or_Body;
3462 ---------------------------
3463 -- Is_Single_Task_Pragma --
3464 ---------------------------
3466 function Is_Single_Task_Pragma
3468 Task_Typ : Entity_Id) return Boolean
3470 Decl : constant Node_Id := Find_Related_Declaration_Or_Body (Prag);
3473 -- To qualify, the pragma must be associated with single task type
3477 Is_Single_Task_Object (Task_Typ)
3478 and then Nkind (Decl) = N_Object_Declaration
3479 and then Defining_Entity (Decl) = Task_Typ;
3480 end Is_Single_Task_Pragma;
3484 Conc_Obj : constant Entity_Id := Encapsulating_State (Var_Id);
3489 -- Start of processing for Check_Part_Of_Reference
3492 -- Nothing to do when the variable was recorded, but did not become a
3493 -- constituent of a single concurrent type.
3495 if No (Conc_Obj) then
3499 -- Traverse the parent chain looking for a suitable context for the
3500 -- reference to the concurrent constituent.
3503 Par := Parent (Prev);
3504 while Present (Par) loop
3505 if Nkind (Par) = N_Pragma then
3506 Prag_Nam := Pragma_Name (Par);
3508 -- A concurrent constituent is allowed to appear in pragmas
3509 -- Initial_Condition and Initializes as this is part of the
3510 -- elaboration checks for the constituent (SPARK RM 9(3)).
3512 if Nam_In (Prag_Nam, Name_Initial_Condition, Name_Initializes) then
3515 -- When the reference appears within pragma Depends or Global,
3516 -- check whether the pragma applies to a single task type. Note
3517 -- that the pragma may not encapsulated by the type definition,
3518 -- but this is still a valid context.
3520 elsif Nam_In (Prag_Nam, Name_Depends, Name_Global)
3521 and then Is_Single_Task_Pragma (Par, Conc_Obj)
3526 -- The reference appears somewhere in the definition of a single
3527 -- concurrent type (SPARK RM 9(3)).
3529 elsif Nkind_In (Par, N_Single_Protected_Declaration,
3530 N_Single_Task_Declaration)
3531 and then Defining_Entity (Par) = Conc_Obj
3535 -- The reference appears within the declaration or body of a single
3536 -- concurrent type (SPARK RM 9(3)).
3538 elsif Nkind_In (Par, N_Protected_Body,
3539 N_Protected_Type_Declaration,
3541 N_Task_Type_Declaration)
3542 and then Is_Single_Declaration_Or_Body (Par, Conc_Obj)
3546 -- The reference appears within the statement list of the object's
3547 -- immediately enclosing package (SPARK RM 9(3)).
3549 elsif Nkind (Par) = N_Package_Body
3550 and then Nkind (Prev) = N_Handled_Sequence_Of_Statements
3551 and then Is_Enclosing_Package_Body (Par, Var_Id)
3555 -- The reference has been relocated within an internally generated
3556 -- package or subprogram. Assume that the reference is legal as the
3557 -- real check was already performed in the original context of the
3560 elsif Nkind_In (Par, N_Package_Body,
3561 N_Package_Declaration,
3563 N_Subprogram_Declaration)
3564 and then Is_Internal_Declaration_Or_Body (Par)
3568 -- The reference has been relocated to an inlined body for GNATprove.
3569 -- Assume that the reference is legal as the real check was already
3570 -- performed in the original context of the reference.
3572 elsif GNATprove_Mode
3573 and then Nkind (Par) = N_Subprogram_Body
3574 and then Chars (Defining_Entity (Par)) = Name_uParent
3580 Par := Parent (Prev);
3583 -- At this point it is known that the reference does not appear within a
3587 ("reference to variable & cannot appear in this context", Ref, Var_Id);
3588 Error_Msg_Name_1 := Chars (Var_Id);
3590 if Is_Single_Protected_Object (Conc_Obj) then
3592 ("\% is constituent of single protected type &", Ref, Conc_Obj);
3596 ("\% is constituent of single task type &", Ref, Conc_Obj);
3598 end Check_Part_Of_Reference;
3600 ------------------------------------------
3601 -- Check_Potentially_Blocking_Operation --
3602 ------------------------------------------
3604 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
3608 -- N is one of the potentially blocking operations listed in 9.5.1(8).
3609 -- When pragma Detect_Blocking is active, the run time will raise
3610 -- Program_Error. Here we only issue a warning, since we generally
3611 -- support the use of potentially blocking operations in the absence
3614 -- Indirect blocking through a subprogram call cannot be diagnosed
3615 -- statically without interprocedural analysis, so we do not attempt
3618 S := Scope (Current_Scope);
3619 while Present (S) and then S /= Standard_Standard loop
3620 if Is_Protected_Type (S) then
3622 ("potentially blocking operation in protected operation??", N);
3628 end Check_Potentially_Blocking_Operation;
3630 ------------------------------------
3631 -- Check_Previous_Null_Procedure --
3632 ------------------------------------
3634 procedure Check_Previous_Null_Procedure
3639 if Ekind (Prev) = E_Procedure
3640 and then Nkind (Parent (Prev)) = N_Procedure_Specification
3641 and then Null_Present (Parent (Prev))
3643 Error_Msg_Sloc := Sloc (Prev);
3645 ("declaration cannot complete previous null procedure#", Decl);
3647 end Check_Previous_Null_Procedure;
3649 ---------------------------------
3650 -- Check_Result_And_Post_State --
3651 ---------------------------------
3653 procedure Check_Result_And_Post_State (Subp_Id : Entity_Id) is
3654 procedure Check_Result_And_Post_State_In_Pragma
3656 Result_Seen : in out Boolean);
3657 -- Determine whether pragma Prag mentions attribute 'Result and whether
3658 -- the pragma contains an expression that evaluates differently in pre-
3659 -- and post-state. Prag is a [refined] postcondition or a contract-cases
3660 -- pragma. Result_Seen is set when the pragma mentions attribute 'Result
3662 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean;
3663 -- Determine whether subprogram Subp_Id contains at least one IN OUT
3664 -- formal parameter.
3666 -------------------------------------------
3667 -- Check_Result_And_Post_State_In_Pragma --
3668 -------------------------------------------
3670 procedure Check_Result_And_Post_State_In_Pragma
3672 Result_Seen : in out Boolean)
3674 procedure Check_Conjunct (Expr : Node_Id);
3675 -- Check an individual conjunct in a conjunction of Boolean
3676 -- expressions, connected by "and" or "and then" operators.
3678 procedure Check_Conjuncts (Expr : Node_Id);
3679 -- Apply the post-state check to every conjunct in an expression, in
3680 -- case this is a conjunction of Boolean expressions. Otherwise apply
3681 -- it to the expression as a whole.
3683 procedure Check_Expression (Expr : Node_Id);
3684 -- Perform the 'Result and post-state checks on a given expression
3686 function Is_Function_Result (N : Node_Id) return Traverse_Result;
3687 -- Attempt to find attribute 'Result in a subtree denoted by N
3689 function Is_Trivial_Boolean (N : Node_Id) return Boolean;
3690 -- Determine whether source node N denotes "True" or "False"
3692 function Mentions_Post_State (N : Node_Id) return Boolean;
3693 -- Determine whether a subtree denoted by N mentions any construct
3694 -- that denotes a post-state.
3696 procedure Check_Function_Result is
3697 new Traverse_Proc (Is_Function_Result);
3699 --------------------
3700 -- Check_Conjunct --
3701 --------------------
3703 procedure Check_Conjunct (Expr : Node_Id) is
3704 function Adjust_Message (Msg : String) return String;
3705 -- Prepend a prefix to the input message Msg denoting that the
3706 -- message applies to a conjunct in the expression, when this
3709 function Applied_On_Conjunct return Boolean;
3710 -- Returns True if the message applies to a conjunct in the
3711 -- expression, instead of the whole expression.
3713 function Has_Global_Output (Subp : Entity_Id) return Boolean;
3714 -- Returns True if Subp has an output in its Global contract
3716 function Has_No_Output (Subp : Entity_Id) return Boolean;
3717 -- Returns True if Subp has no declared output: no function
3718 -- result, no output parameter, and no output in its Global
3721 --------------------
3722 -- Adjust_Message --
3723 --------------------
3725 function Adjust_Message (Msg : String) return String is
3727 if Applied_On_Conjunct then
3728 return "conjunct in " & Msg;
3734 -------------------------
3735 -- Applied_On_Conjunct --
3736 -------------------------
3738 function Applied_On_Conjunct return Boolean is
3740 -- Expr is the conjunct of an enclosing "and" expression
3742 return Nkind (Parent (Expr)) in N_Subexpr
3744 -- or Expr is a conjunct of an enclosing "and then"
3745 -- expression in a postcondition aspect that was split into
3746 -- multiple pragmas. The first conjunct has the "and then"
3747 -- expression as Original_Node, and other conjuncts have
3748 -- Split_PCC set to True.
3750 or else Nkind (Original_Node (Expr)) = N_And_Then
3751 or else Split_PPC (Prag);
3752 end Applied_On_Conjunct;
3754 -----------------------
3755 -- Has_Global_Output --
3756 -----------------------
3758 function Has_Global_Output (Subp : Entity_Id) return Boolean is
3759 Global : constant Node_Id := Get_Pragma (Subp, Pragma_Global);
3768 List := Expression (Get_Argument (Global, Subp));
3770 -- Empty list (no global items) or single global item
3771 -- declaration (only input items).
3773 if Nkind_In (List, N_Null,
3776 N_Selected_Component)
3780 -- Simple global list (only input items) or moded global list
3783 elsif Nkind (List) = N_Aggregate then
3784 if Present (Expressions (List)) then
3788 Assoc := First (Component_Associations (List));
3789 while Present (Assoc) loop
3790 if Chars (First (Choices (Assoc))) /= Name_Input then
3800 -- To accommodate partial decoration of disabled SPARK
3801 -- features, this routine may be called with illegal input.
3802 -- If this is the case, do not raise Program_Error.
3807 end Has_Global_Output;
3813 function Has_No_Output (Subp : Entity_Id) return Boolean is
3817 -- A function has its result as output
3819 if Ekind (Subp) = E_Function then
3823 -- An OUT or IN OUT parameter is an output
3825 Param := First_Formal (Subp);
3826 while Present (Param) loop
3827 if Ekind_In (Param, E_Out_Parameter, E_In_Out_Parameter) then
3831 Next_Formal (Param);
3834 -- An item of mode Output or In_Out in the Global contract is
3837 if Has_Global_Output (Subp) then
3847 -- Error node when reporting a warning on a (refined)
3850 -- Start of processing for Check_Conjunct
3853 if Applied_On_Conjunct then
3859 -- Do not report missing reference to outcome in postcondition if
3860 -- either the postcondition is trivially True or False, or if the
3861 -- subprogram is ghost and has no declared output.
3863 if not Is_Trivial_Boolean (Expr)
3864 and then not Mentions_Post_State (Expr)
3865 and then not (Is_Ghost_Entity (Subp_Id)
3866 and then Has_No_Output (Subp_Id))
3868 if Pragma_Name (Prag) = Name_Contract_Cases then
3869 Error_Msg_NE (Adjust_Message
3870 ("contract case does not check the outcome of calling "
3871 & "&?T?"), Expr, Subp_Id);
3873 elsif Pragma_Name (Prag) = Name_Refined_Post then
3874 Error_Msg_NE (Adjust_Message
3875 ("refined postcondition does not check the outcome of "
3876 & "calling &?T?"), Err_Node, Subp_Id);
3879 Error_Msg_NE (Adjust_Message
3880 ("postcondition does not check the outcome of calling "
3881 & "&?T?"), Err_Node, Subp_Id);
3886 ---------------------
3887 -- Check_Conjuncts --
3888 ---------------------
3890 procedure Check_Conjuncts (Expr : Node_Id) is
3892 if Nkind_In (Expr, N_Op_And, N_And_Then) then
3893 Check_Conjuncts (Left_Opnd (Expr));
3894 Check_Conjuncts (Right_Opnd (Expr));
3896 Check_Conjunct (Expr);
3898 end Check_Conjuncts;
3900 ----------------------
3901 -- Check_Expression --
3902 ----------------------
3904 procedure Check_Expression (Expr : Node_Id) is
3906 if not Is_Trivial_Boolean (Expr) then
3907 Check_Function_Result (Expr);
3908 Check_Conjuncts (Expr);
3910 end Check_Expression;
3912 ------------------------
3913 -- Is_Function_Result --
3914 ------------------------
3916 function Is_Function_Result (N : Node_Id) return Traverse_Result is
3918 if Is_Attribute_Result (N) then
3919 Result_Seen := True;
3922 -- Warn on infinite recursion if call is to current function
3924 elsif Nkind (N) = N_Function_Call
3925 and then Is_Entity_Name (Name (N))
3926 and then Entity (Name (N)) = Subp_Id
3927 and then not Is_Potentially_Unevaluated (N)
3930 ("call to & within its postcondition will lead to infinite "
3931 & "recursion?", N, Subp_Id);
3934 -- Continue the traversal
3939 end Is_Function_Result;
3941 ------------------------
3942 -- Is_Trivial_Boolean --
3943 ------------------------
3945 function Is_Trivial_Boolean (N : Node_Id) return Boolean is
3948 Comes_From_Source (N)
3949 and then Is_Entity_Name (N)
3950 and then (Entity (N) = Standard_True
3952 Entity (N) = Standard_False);
3953 end Is_Trivial_Boolean;
3955 -------------------------
3956 -- Mentions_Post_State --
3957 -------------------------
3959 function Mentions_Post_State (N : Node_Id) return Boolean is
3960 Post_State_Seen : Boolean := False;
3962 function Is_Post_State (N : Node_Id) return Traverse_Result;
3963 -- Attempt to find a construct that denotes a post-state. If this
3964 -- is the case, set flag Post_State_Seen.
3970 function Is_Post_State (N : Node_Id) return Traverse_Result is
3974 if Nkind_In (N, N_Explicit_Dereference, N_Function_Call) then
3975 Post_State_Seen := True;
3978 elsif Nkind_In (N, N_Expanded_Name, N_Identifier) then
3981 -- Treat an undecorated reference as OK
3985 -- A reference to an assignable entity is considered a
3986 -- change in the post-state of a subprogram.
3988 or else Ekind_In (Ent, E_Generic_In_Out_Parameter,
3993 -- The reference may be modified through a dereference
3995 or else (Is_Access_Type (Etype (Ent))
3996 and then Nkind (Parent (N)) =
3997 N_Selected_Component)
3999 Post_State_Seen := True;
4003 elsif Nkind (N) = N_Attribute_Reference then
4004 if Attribute_Name (N) = Name_Old then
4007 elsif Attribute_Name (N) = Name_Result then
4008 Post_State_Seen := True;
4016 procedure Find_Post_State is new Traverse_Proc (Is_Post_State);
4018 -- Start of processing for Mentions_Post_State
4021 Find_Post_State (N);
4023 return Post_State_Seen;
4024 end Mentions_Post_State;
4028 Expr : constant Node_Id :=
4030 (First (Pragma_Argument_Associations (Prag)));
4031 Nam : constant Name_Id := Pragma_Name (Prag);
4034 -- Start of processing for Check_Result_And_Post_State_In_Pragma
4037 -- Examine all consequences
4039 if Nam = Name_Contract_Cases then
4040 CCase := First (Component_Associations (Expr));
4041 while Present (CCase) loop
4042 Check_Expression (Expression (CCase));
4047 -- Examine the expression of a postcondition
4049 else pragma Assert (Nam_In (Nam, Name_Postcondition,
4050 Name_Refined_Post));
4051 Check_Expression (Expr);
4053 end Check_Result_And_Post_State_In_Pragma;
4055 --------------------------
4056 -- Has_In_Out_Parameter --
4057 --------------------------
4059 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean is
4063 -- Traverse the formals looking for an IN OUT parameter
4065 Formal := First_Formal (Subp_Id);
4066 while Present (Formal) loop
4067 if Ekind (Formal) = E_In_Out_Parameter then
4071 Next_Formal (Formal);
4075 end Has_In_Out_Parameter;
4079 Items : constant Node_Id := Contract (Subp_Id);
4080 Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id);
4081 Case_Prag : Node_Id := Empty;
4082 Post_Prag : Node_Id := Empty;
4084 Seen_In_Case : Boolean := False;
4085 Seen_In_Post : Boolean := False;
4086 Spec_Id : Entity_Id;
4088 -- Start of processing for Check_Result_And_Post_State
4091 -- The lack of attribute 'Result or a post-state is classified as a
4092 -- suspicious contract. Do not perform the check if the corresponding
4093 -- swich is not set.
4095 if not Warn_On_Suspicious_Contract then
4098 -- Nothing to do if there is no contract
4100 elsif No (Items) then
4104 -- Retrieve the entity of the subprogram spec (if any)
4106 if Nkind (Subp_Decl) = N_Subprogram_Body
4107 and then Present (Corresponding_Spec (Subp_Decl))
4109 Spec_Id := Corresponding_Spec (Subp_Decl);
4111 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4112 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
4114 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
4120 -- Examine all postconditions for attribute 'Result and a post-state
4122 Prag := Pre_Post_Conditions (Items);
4123 while Present (Prag) loop
4124 if Nam_In (Pragma_Name_Unmapped (Prag),
4125 Name_Postcondition, Name_Refined_Post)
4126 and then not Error_Posted (Prag)
4129 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Post);
4132 Prag := Next_Pragma (Prag);
4135 -- Examine the contract cases of the subprogram for attribute 'Result
4136 -- and a post-state.
4138 Prag := Contract_Test_Cases (Items);
4139 while Present (Prag) loop
4140 if Pragma_Name (Prag) = Name_Contract_Cases
4141 and then not Error_Posted (Prag)
4144 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Case);
4147 Prag := Next_Pragma (Prag);
4150 -- Do not emit any errors if the subprogram is not a function
4152 if not Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
4155 -- Regardless of whether the function has postconditions or contract
4156 -- cases, or whether they mention attribute 'Result, an IN OUT formal
4157 -- parameter is always treated as a result.
4159 elsif Has_In_Out_Parameter (Spec_Id) then
4162 -- The function has both a postcondition and contract cases and they do
4163 -- not mention attribute 'Result.
4165 elsif Present (Case_Prag)
4166 and then not Seen_In_Case
4167 and then Present (Post_Prag)
4168 and then not Seen_In_Post
4171 ("neither postcondition nor contract cases mention function "
4172 & "result?T?", Post_Prag);
4174 -- The function has contract cases only and they do not mention
4175 -- attribute 'Result.
4177 elsif Present (Case_Prag) and then not Seen_In_Case then
4178 Error_Msg_N ("contract cases do not mention result?T?", Case_Prag);
4180 -- The function has postconditions only and they do not mention
4181 -- attribute 'Result.
4183 elsif Present (Post_Prag) and then not Seen_In_Post then
4185 ("postcondition does not mention function result?T?", Post_Prag);
4187 end Check_Result_And_Post_State;
4189 -----------------------------
4190 -- Check_State_Refinements --
4191 -----------------------------
4193 procedure Check_State_Refinements
4195 Is_Main_Unit : Boolean := False)
4197 procedure Check_Package (Pack : Node_Id);
4198 -- Verify that all abstract states of a [generic] package denoted by its
4199 -- declarative node Pack have proper refinement. Recursively verify the
4200 -- visible and private declarations of the [generic] package for other
4203 procedure Check_Packages_In (Decls : List_Id);
4204 -- Seek out [generic] package declarations within declarative list Decls
4205 -- and verify the status of their abstract state refinement.
4207 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean;
4208 -- Determine whether construct N is subject to pragma SPARK_Mode Off
4214 procedure Check_Package (Pack : Node_Id) is
4215 Body_Id : constant Entity_Id := Corresponding_Body (Pack);
4216 Spec : constant Node_Id := Specification (Pack);
4217 States : constant Elist_Id :=
4218 Abstract_States (Defining_Entity (Pack));
4220 State_Elmt : Elmt_Id;
4221 State_Id : Entity_Id;
4224 -- Do not verify proper state refinement when the package is subject
4225 -- to pragma SPARK_Mode Off because this disables the requirement for
4226 -- state refinement.
4228 if SPARK_Mode_Is_Off (Pack) then
4231 -- State refinement can only occur in a completing package body. Do
4232 -- not verify proper state refinement when the body is subject to
4233 -- pragma SPARK_Mode Off because this disables the requirement for
4234 -- state refinement.
4236 elsif Present (Body_Id)
4237 and then SPARK_Mode_Is_Off (Unit_Declaration_Node (Body_Id))
4241 -- Do not verify proper state refinement when the package is an
4242 -- instance as this check was already performed in the generic.
4244 elsif Present (Generic_Parent (Spec)) then
4247 -- Otherwise examine the contents of the package
4250 if Present (States) then
4251 State_Elmt := First_Elmt (States);
4252 while Present (State_Elmt) loop
4253 State_Id := Node (State_Elmt);
4255 -- Emit an error when a non-null state lacks any form of
4258 if not Is_Null_State (State_Id)
4259 and then not Has_Null_Refinement (State_Id)
4260 and then not Has_Non_Null_Refinement (State_Id)
4262 Error_Msg_N ("state & requires refinement", State_Id);
4265 Next_Elmt (State_Elmt);
4269 Check_Packages_In (Visible_Declarations (Spec));
4270 Check_Packages_In (Private_Declarations (Spec));
4274 -----------------------
4275 -- Check_Packages_In --
4276 -----------------------
4278 procedure Check_Packages_In (Decls : List_Id) is
4282 if Present (Decls) then
4283 Decl := First (Decls);
4284 while Present (Decl) loop
4285 if Nkind_In (Decl, N_Generic_Package_Declaration,
4286 N_Package_Declaration)
4288 Check_Package (Decl);
4294 end Check_Packages_In;
4296 -----------------------
4297 -- SPARK_Mode_Is_Off --
4298 -----------------------
4300 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean is
4301 Id : constant Entity_Id := Defining_Entity (N);
4302 Prag : constant Node_Id := SPARK_Pragma (Id);
4305 -- Default the mode to "off" when the context is an instance and all
4306 -- SPARK_Mode pragmas found within are to be ignored.
4308 if Ignore_SPARK_Mode_Pragmas (Id) then
4314 and then Get_SPARK_Mode_From_Annotation (Prag) = Off;
4316 end SPARK_Mode_Is_Off;
4318 -- Start of processing for Check_State_Refinements
4321 -- A block may declare a nested package
4323 if Nkind (Context) = N_Block_Statement then
4324 Check_Packages_In (Declarations (Context));
4326 -- An entry, protected, subprogram, or task body may declare a nested
4329 elsif Nkind_In (Context, N_Entry_Body,
4334 -- Do not verify proper state refinement when the body is subject to
4335 -- pragma SPARK_Mode Off because this disables the requirement for
4336 -- state refinement.
4338 if not SPARK_Mode_Is_Off (Context) then
4339 Check_Packages_In (Declarations (Context));
4342 -- A package body may declare a nested package
4344 elsif Nkind (Context) = N_Package_Body then
4345 Check_Package (Unit_Declaration_Node (Corresponding_Spec (Context)));
4347 -- Do not verify proper state refinement when the body is subject to
4348 -- pragma SPARK_Mode Off because this disables the requirement for
4349 -- state refinement.
4351 if not SPARK_Mode_Is_Off (Context) then
4352 Check_Packages_In (Declarations (Context));
4355 -- A library level [generic] package may declare a nested package
4357 elsif Nkind_In (Context, N_Generic_Package_Declaration,
4358 N_Package_Declaration)
4359 and then Is_Main_Unit
4361 Check_Package (Context);
4363 end Check_State_Refinements;
4365 ------------------------------
4366 -- Check_Unprotected_Access --
4367 ------------------------------
4369 procedure Check_Unprotected_Access
4373 Cont_Encl_Typ : Entity_Id;
4374 Pref_Encl_Typ : Entity_Id;
4376 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
4377 -- Check whether Obj is a private component of a protected object.
4378 -- Return the protected type where the component resides, Empty
4381 function Is_Public_Operation return Boolean;
4382 -- Verify that the enclosing operation is callable from outside the
4383 -- protected object, to minimize false positives.
4385 ------------------------------
4386 -- Enclosing_Protected_Type --
4387 ------------------------------
4389 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
4391 if Is_Entity_Name (Obj) then
4393 Ent : Entity_Id := Entity (Obj);
4396 -- The object can be a renaming of a private component, use
4397 -- the original record component.
4399 if Is_Prival (Ent) then
4400 Ent := Prival_Link (Ent);
4403 if Is_Protected_Type (Scope (Ent)) then
4409 -- For indexed and selected components, recursively check the prefix
4411 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
4412 return Enclosing_Protected_Type (Prefix (Obj));
4414 -- The object does not denote a protected component
4419 end Enclosing_Protected_Type;
4421 -------------------------
4422 -- Is_Public_Operation --
4423 -------------------------
4425 function Is_Public_Operation return Boolean is
4431 while Present (S) and then S /= Pref_Encl_Typ loop
4432 if Scope (S) = Pref_Encl_Typ then
4433 E := First_Entity (Pref_Encl_Typ);
4435 and then E /= First_Private_Entity (Pref_Encl_Typ)
4449 end Is_Public_Operation;
4451 -- Start of processing for Check_Unprotected_Access
4454 if Nkind (Expr) = N_Attribute_Reference
4455 and then Attribute_Name (Expr) = Name_Unchecked_Access
4457 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
4458 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
4460 -- Check whether we are trying to export a protected component to a
4461 -- context with an equal or lower access level.
4463 if Present (Pref_Encl_Typ)
4464 and then No (Cont_Encl_Typ)
4465 and then Is_Public_Operation
4466 and then Scope_Depth (Pref_Encl_Typ) >=
4467 Object_Access_Level (Context)
4470 ("??possible unprotected access to protected data", Expr);
4473 end Check_Unprotected_Access;
4475 ------------------------------
4476 -- Check_Unused_Body_States --
4477 ------------------------------
4479 procedure Check_Unused_Body_States (Body_Id : Entity_Id) is
4480 procedure Process_Refinement_Clause
4483 -- Inspect all constituents of refinement clause Clause and remove any
4484 -- matches from body state list States.
4486 procedure Report_Unused_Body_States (States : Elist_Id);
4487 -- Emit errors for each abstract state or object found in list States
4489 -------------------------------
4490 -- Process_Refinement_Clause --
4491 -------------------------------
4493 procedure Process_Refinement_Clause
4497 procedure Process_Constituent (Constit : Node_Id);
4498 -- Remove constituent Constit from body state list States
4500 -------------------------
4501 -- Process_Constituent --
4502 -------------------------
4504 procedure Process_Constituent (Constit : Node_Id) is
4505 Constit_Id : Entity_Id;
4508 -- Guard against illegal constituents. Only abstract states and
4509 -- objects can appear on the right hand side of a refinement.
4511 if Is_Entity_Name (Constit) then
4512 Constit_Id := Entity_Of (Constit);
4514 if Present (Constit_Id)
4515 and then Ekind_In (Constit_Id, E_Abstract_State,
4519 Remove (States, Constit_Id);
4522 end Process_Constituent;
4528 -- Start of processing for Process_Refinement_Clause
4531 if Nkind (Clause) = N_Component_Association then
4532 Constit := Expression (Clause);
4534 -- Multiple constituents appear as an aggregate
4536 if Nkind (Constit) = N_Aggregate then
4537 Constit := First (Expressions (Constit));
4538 while Present (Constit) loop
4539 Process_Constituent (Constit);
4543 -- Various forms of a single constituent
4546 Process_Constituent (Constit);
4549 end Process_Refinement_Clause;
4551 -------------------------------
4552 -- Report_Unused_Body_States --
4553 -------------------------------
4555 procedure Report_Unused_Body_States (States : Elist_Id) is
4556 Posted : Boolean := False;
4557 State_Elmt : Elmt_Id;
4558 State_Id : Entity_Id;
4561 if Present (States) then
4562 State_Elmt := First_Elmt (States);
4563 while Present (State_Elmt) loop
4564 State_Id := Node (State_Elmt);
4566 -- Constants are part of the hidden state of a package, but the
4567 -- compiler cannot determine whether they have variable input
4568 -- (SPARK RM 7.1.1(2)) and cannot classify them properly as a
4569 -- hidden state. Do not emit an error when a constant does not
4570 -- participate in a state refinement, even though it acts as a
4573 if Ekind (State_Id) = E_Constant then
4576 -- Generate an error message of the form:
4578 -- body of package ... has unused hidden states
4579 -- abstract state ... defined at ...
4580 -- variable ... defined at ...
4586 ("body of package & has unused hidden states", Body_Id);
4589 Error_Msg_Sloc := Sloc (State_Id);
4591 if Ekind (State_Id) = E_Abstract_State then
4593 ("\abstract state & defined #", Body_Id, State_Id);
4596 SPARK_Msg_NE ("\variable & defined #", Body_Id, State_Id);
4600 Next_Elmt (State_Elmt);
4603 end Report_Unused_Body_States;
4607 Prag : constant Node_Id := Get_Pragma (Body_Id, Pragma_Refined_State);
4608 Spec_Id : constant Entity_Id := Spec_Entity (Body_Id);
4612 -- Start of processing for Check_Unused_Body_States
4615 -- Inspect the clauses of pragma Refined_State and determine whether all
4616 -- visible states declared within the package body participate in the
4619 if Present (Prag) then
4620 Clause := Expression (Get_Argument (Prag, Spec_Id));
4621 States := Collect_Body_States (Body_Id);
4623 -- Multiple non-null state refinements appear as an aggregate
4625 if Nkind (Clause) = N_Aggregate then
4626 Clause := First (Component_Associations (Clause));
4627 while Present (Clause) loop
4628 Process_Refinement_Clause (Clause, States);
4632 -- Various forms of a single state refinement
4635 Process_Refinement_Clause (Clause, States);
4638 -- Ensure that all abstract states and objects declared in the
4639 -- package body state space are utilized as constituents.
4641 Report_Unused_Body_States (States);
4643 end Check_Unused_Body_States;
4649 function Choice_List (N : Node_Id) return List_Id is
4651 if Nkind (N) = N_Iterated_Component_Association then
4652 return Discrete_Choices (N);
4658 -------------------------
4659 -- Collect_Body_States --
4660 -------------------------
4662 function Collect_Body_States (Body_Id : Entity_Id) return Elist_Id is
4663 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean;
4664 -- Determine whether object Obj_Id is a suitable visible state of a
4667 procedure Collect_Visible_States
4668 (Pack_Id : Entity_Id;
4669 States : in out Elist_Id);
4670 -- Gather the entities of all abstract states and objects declared in
4671 -- the visible state space of package Pack_Id.
4673 ----------------------------
4674 -- Collect_Visible_States --
4675 ----------------------------
4677 procedure Collect_Visible_States
4678 (Pack_Id : Entity_Id;
4679 States : in out Elist_Id)
4681 Item_Id : Entity_Id;
4684 -- Traverse the entity chain of the package and inspect all visible
4687 Item_Id := First_Entity (Pack_Id);
4688 while Present (Item_Id) and then not In_Private_Part (Item_Id) loop
4690 -- Do not consider internally generated items as those cannot be
4691 -- named and participate in refinement.
4693 if not Comes_From_Source (Item_Id) then
4696 elsif Ekind (Item_Id) = E_Abstract_State then
4697 Append_New_Elmt (Item_Id, States);
4699 elsif Ekind_In (Item_Id, E_Constant, E_Variable)
4700 and then Is_Visible_Object (Item_Id)
4702 Append_New_Elmt (Item_Id, States);
4704 -- Recursively gather the visible states of a nested package
4706 elsif Ekind (Item_Id) = E_Package then
4707 Collect_Visible_States (Item_Id, States);
4710 Next_Entity (Item_Id);
4712 end Collect_Visible_States;
4714 -----------------------
4715 -- Is_Visible_Object --
4716 -----------------------
4718 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean is
4720 -- Objects that map generic formals to their actuals are not visible
4721 -- from outside the generic instantiation.
4723 if Present (Corresponding_Generic_Association
4724 (Declaration_Node (Obj_Id)))
4728 -- Constituents of a single protected/task type act as components of
4729 -- the type and are not visible from outside the type.
4731 elsif Ekind (Obj_Id) = E_Variable
4732 and then Present (Encapsulating_State (Obj_Id))
4733 and then Is_Single_Concurrent_Object (Encapsulating_State (Obj_Id))
4740 end Is_Visible_Object;
4744 Body_Decl : constant Node_Id := Unit_Declaration_Node (Body_Id);
4746 Item_Id : Entity_Id;
4747 States : Elist_Id := No_Elist;
4749 -- Start of processing for Collect_Body_States
4752 -- Inspect the declarations of the body looking for source objects,
4753 -- packages and package instantiations. Note that even though this
4754 -- processing is very similar to Collect_Visible_States, a package
4755 -- body does not have a First/Next_Entity list.
4757 Decl := First (Declarations (Body_Decl));
4758 while Present (Decl) loop
4760 -- Capture source objects as internally generated temporaries cannot
4761 -- be named and participate in refinement.
4763 if Nkind (Decl) = N_Object_Declaration then
4764 Item_Id := Defining_Entity (Decl);
4766 if Comes_From_Source (Item_Id)
4767 and then Is_Visible_Object (Item_Id)
4769 Append_New_Elmt (Item_Id, States);
4772 -- Capture the visible abstract states and objects of a source
4773 -- package [instantiation].
4775 elsif Nkind (Decl) = N_Package_Declaration then
4776 Item_Id := Defining_Entity (Decl);
4778 if Comes_From_Source (Item_Id) then
4779 Collect_Visible_States (Item_Id, States);
4787 end Collect_Body_States;
4789 ------------------------
4790 -- Collect_Interfaces --
4791 ------------------------
4793 procedure Collect_Interfaces
4795 Ifaces_List : out Elist_Id;
4796 Exclude_Parents : Boolean := False;
4797 Use_Full_View : Boolean := True)
4799 procedure Collect (Typ : Entity_Id);
4800 -- Subsidiary subprogram used to traverse the whole list
4801 -- of directly and indirectly implemented interfaces
4807 procedure Collect (Typ : Entity_Id) is
4808 Ancestor : Entity_Id;
4816 -- Handle private types and subtypes
4819 and then Is_Private_Type (Typ)
4820 and then Present (Full_View (Typ))
4822 Full_T := Full_View (Typ);
4824 if Ekind (Full_T) = E_Record_Subtype then
4825 Full_T := Etype (Typ);
4827 if Present (Full_View (Full_T)) then
4828 Full_T := Full_View (Full_T);
4833 -- Include the ancestor if we are generating the whole list of
4834 -- abstract interfaces.
4836 if Etype (Full_T) /= Typ
4838 -- Protect the frontend against wrong sources. For example:
4841 -- type A is tagged null record;
4842 -- type B is new A with private;
4843 -- type C is new A with private;
4845 -- type B is new C with null record;
4846 -- type C is new B with null record;
4849 and then Etype (Full_T) /= T
4851 Ancestor := Etype (Full_T);
4854 if Is_Interface (Ancestor) and then not Exclude_Parents then
4855 Append_Unique_Elmt (Ancestor, Ifaces_List);
4859 -- Traverse the graph of ancestor interfaces
4861 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
4862 Id := First (Abstract_Interface_List (Full_T));
4863 while Present (Id) loop
4864 Iface := Etype (Id);
4866 -- Protect against wrong uses. For example:
4867 -- type I is interface;
4868 -- type O is tagged null record;
4869 -- type Wrong is new I and O with null record; -- ERROR
4871 if Is_Interface (Iface) then
4873 and then Etype (T) /= T
4874 and then Interface_Present_In_Ancestor (Etype (T), Iface)
4879 Append_Unique_Elmt (Iface, Ifaces_List);
4888 -- Start of processing for Collect_Interfaces
4891 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
4892 Ifaces_List := New_Elmt_List;
4894 end Collect_Interfaces;
4896 ----------------------------------
4897 -- Collect_Interface_Components --
4898 ----------------------------------
4900 procedure Collect_Interface_Components
4901 (Tagged_Type : Entity_Id;
4902 Components_List : out Elist_Id)
4904 procedure Collect (Typ : Entity_Id);
4905 -- Subsidiary subprogram used to climb to the parents
4911 procedure Collect (Typ : Entity_Id) is
4912 Tag_Comp : Entity_Id;
4913 Parent_Typ : Entity_Id;
4916 -- Handle private types
4918 if Present (Full_View (Etype (Typ))) then
4919 Parent_Typ := Full_View (Etype (Typ));
4921 Parent_Typ := Etype (Typ);
4924 if Parent_Typ /= Typ
4926 -- Protect the frontend against wrong sources. For example:
4929 -- type A is tagged null record;
4930 -- type B is new A with private;
4931 -- type C is new A with private;
4933 -- type B is new C with null record;
4934 -- type C is new B with null record;
4937 and then Parent_Typ /= Tagged_Type
4939 Collect (Parent_Typ);
4942 -- Collect the components containing tags of secondary dispatch
4945 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
4946 while Present (Tag_Comp) loop
4947 pragma Assert (Present (Related_Type (Tag_Comp)));
4948 Append_Elmt (Tag_Comp, Components_List);
4950 Tag_Comp := Next_Tag_Component (Tag_Comp);
4954 -- Start of processing for Collect_Interface_Components
4957 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
4958 and then Is_Tagged_Type (Tagged_Type));
4960 Components_List := New_Elmt_List;
4961 Collect (Tagged_Type);
4962 end Collect_Interface_Components;
4964 -----------------------------
4965 -- Collect_Interfaces_Info --
4966 -----------------------------
4968 procedure Collect_Interfaces_Info
4970 Ifaces_List : out Elist_Id;
4971 Components_List : out Elist_Id;
4972 Tags_List : out Elist_Id)
4974 Comps_List : Elist_Id;
4975 Comp_Elmt : Elmt_Id;
4976 Comp_Iface : Entity_Id;
4977 Iface_Elmt : Elmt_Id;
4980 function Search_Tag (Iface : Entity_Id) return Entity_Id;
4981 -- Search for the secondary tag associated with the interface type
4982 -- Iface that is implemented by T.
4988 function Search_Tag (Iface : Entity_Id) return Entity_Id is
4991 if not Is_CPP_Class (T) then
4992 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
4994 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
4998 and then Is_Tag (Node (ADT))
4999 and then Related_Type (Node (ADT)) /= Iface
5001 -- Skip secondary dispatch table referencing thunks to user
5002 -- defined primitives covered by this interface.
5004 pragma Assert (Has_Suffix (Node (ADT), 'P'));
5007 -- Skip secondary dispatch tables of Ada types
5009 if not Is_CPP_Class (T) then
5011 -- Skip secondary dispatch table referencing thunks to
5012 -- predefined primitives.
5014 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
5017 -- Skip secondary dispatch table referencing user-defined
5018 -- primitives covered by this interface.
5020 pragma Assert (Has_Suffix (Node (ADT), 'D'));
5023 -- Skip secondary dispatch table referencing predefined
5026 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
5031 pragma Assert (Is_Tag (Node (ADT)));
5035 -- Start of processing for Collect_Interfaces_Info
5038 Collect_Interfaces (T, Ifaces_List);
5039 Collect_Interface_Components (T, Comps_List);
5041 -- Search for the record component and tag associated with each
5042 -- interface type of T.
5044 Components_List := New_Elmt_List;
5045 Tags_List := New_Elmt_List;
5047 Iface_Elmt := First_Elmt (Ifaces_List);
5048 while Present (Iface_Elmt) loop
5049 Iface := Node (Iface_Elmt);
5051 -- Associate the primary tag component and the primary dispatch table
5052 -- with all the interfaces that are parents of T
5054 if Is_Ancestor (Iface, T, Use_Full_View => True) then
5055 Append_Elmt (First_Tag_Component (T), Components_List);
5056 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
5058 -- Otherwise search for the tag component and secondary dispatch
5062 Comp_Elmt := First_Elmt (Comps_List);
5063 while Present (Comp_Elmt) loop
5064 Comp_Iface := Related_Type (Node (Comp_Elmt));
5066 if Comp_Iface = Iface
5067 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
5069 Append_Elmt (Node (Comp_Elmt), Components_List);
5070 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
5074 Next_Elmt (Comp_Elmt);
5076 pragma Assert (Present (Comp_Elmt));
5079 Next_Elmt (Iface_Elmt);
5081 end Collect_Interfaces_Info;
5083 ---------------------
5084 -- Collect_Parents --
5085 ---------------------
5087 procedure Collect_Parents
5089 List : out Elist_Id;
5090 Use_Full_View : Boolean := True)
5092 Current_Typ : Entity_Id := T;
5093 Parent_Typ : Entity_Id;
5096 List := New_Elmt_List;
5098 -- No action if the if the type has no parents
5100 if T = Etype (T) then
5105 Parent_Typ := Etype (Current_Typ);
5107 if Is_Private_Type (Parent_Typ)
5108 and then Present (Full_View (Parent_Typ))
5109 and then Use_Full_View
5111 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5114 Append_Elmt (Parent_Typ, List);
5116 exit when Parent_Typ = Current_Typ;
5117 Current_Typ := Parent_Typ;
5119 end Collect_Parents;
5121 ----------------------------------
5122 -- Collect_Primitive_Operations --
5123 ----------------------------------
5125 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
5126 B_Type : constant Entity_Id := Base_Type (T);
5128 function Match (E : Entity_Id) return Boolean;
5129 -- True if E's base type is B_Type, or E is of an anonymous access type
5130 -- and the base type of its designated type is B_Type.
5136 function Match (E : Entity_Id) return Boolean is
5137 Etyp : Entity_Id := Etype (E);
5140 if Ekind (Etyp) = E_Anonymous_Access_Type then
5141 Etyp := Designated_Type (Etyp);
5144 -- In Ada 2012 a primitive operation may have a formal of an
5145 -- incomplete view of the parent type.
5147 return Base_Type (Etyp) = B_Type
5149 (Ada_Version >= Ada_2012
5150 and then Ekind (Etyp) = E_Incomplete_Type
5151 and then Full_View (Etyp) = B_Type);
5156 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
5157 B_Scope : Entity_Id := Scope (B_Type);
5159 Eq_Prims_List : Elist_Id := No_Elist;
5162 Is_Type_In_Pkg : Boolean;
5163 Formal_Derived : Boolean := False;
5166 -- Start of processing for Collect_Primitive_Operations
5169 -- For tagged types, the primitive operations are collected as they
5170 -- are declared, and held in an explicit list which is simply returned.
5172 if Is_Tagged_Type (B_Type) then
5173 return Primitive_Operations (B_Type);
5175 -- An untagged generic type that is a derived type inherits the
5176 -- primitive operations of its parent type. Other formal types only
5177 -- have predefined operators, which are not explicitly represented.
5179 elsif Is_Generic_Type (B_Type) then
5180 if Nkind (B_Decl) = N_Formal_Type_Declaration
5181 and then Nkind (Formal_Type_Definition (B_Decl)) =
5182 N_Formal_Derived_Type_Definition
5184 Formal_Derived := True;
5186 return New_Elmt_List;
5190 Op_List := New_Elmt_List;
5192 if B_Scope = Standard_Standard then
5193 if B_Type = Standard_String then
5194 Append_Elmt (Standard_Op_Concat, Op_List);
5196 elsif B_Type = Standard_Wide_String then
5197 Append_Elmt (Standard_Op_Concatw, Op_List);
5203 -- Locate the primitive subprograms of the type
5206 -- The primitive operations appear after the base type, except if the
5207 -- derivation happens within the private part of B_Scope and the type
5208 -- is a private type, in which case both the type and some primitive
5209 -- operations may appear before the base type, and the list of
5210 -- candidates starts after the type.
5212 if In_Open_Scopes (B_Scope)
5213 and then Scope (T) = B_Scope
5214 and then In_Private_Part (B_Scope)
5216 Id := Next_Entity (T);
5218 -- In Ada 2012, If the type has an incomplete partial view, there may
5219 -- be primitive operations declared before the full view, so we need
5220 -- to start scanning from the incomplete view, which is earlier on
5221 -- the entity chain.
5223 elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration
5224 and then Present (Incomplete_View (Parent (B_Type)))
5226 Id := Defining_Entity (Incomplete_View (Parent (B_Type)));
5228 -- If T is a derived from a type with an incomplete view declared
5229 -- elsewhere, that incomplete view is irrelevant, we want the
5230 -- operations in the scope of T.
5232 if Scope (Id) /= Scope (B_Type) then
5233 Id := Next_Entity (B_Type);
5237 Id := Next_Entity (B_Type);
5240 -- Set flag if this is a type in a package spec
5243 Is_Package_Or_Generic_Package (B_Scope)
5245 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
5248 while Present (Id) loop
5250 -- Test whether the result type or any of the parameter types of
5251 -- each subprogram following the type match that type when the
5252 -- type is declared in a package spec, is a derived type, or the
5253 -- subprogram is marked as primitive. (The Is_Primitive test is
5254 -- needed to find primitives of nonderived types in declarative
5255 -- parts that happen to override the predefined "=" operator.)
5257 -- Note that generic formal subprograms are not considered to be
5258 -- primitive operations and thus are never inherited.
5260 if Is_Overloadable (Id)
5261 and then (Is_Type_In_Pkg
5262 or else Is_Derived_Type (B_Type)
5263 or else Is_Primitive (Id))
5264 and then Nkind (Parent (Parent (Id)))
5265 not in N_Formal_Subprogram_Declaration
5273 Formal := First_Formal (Id);
5274 while Present (Formal) loop
5275 if Match (Formal) then
5280 Next_Formal (Formal);
5284 -- For a formal derived type, the only primitives are the ones
5285 -- inherited from the parent type. Operations appearing in the
5286 -- package declaration are not primitive for it.
5289 and then (not Formal_Derived or else Present (Alias (Id)))
5291 -- In the special case of an equality operator aliased to
5292 -- an overriding dispatching equality belonging to the same
5293 -- type, we don't include it in the list of primitives.
5294 -- This avoids inheriting multiple equality operators when
5295 -- deriving from untagged private types whose full type is
5296 -- tagged, which can otherwise cause ambiguities. Note that
5297 -- this should only happen for this kind of untagged parent
5298 -- type, since normally dispatching operations are inherited
5299 -- using the type's Primitive_Operations list.
5301 if Chars (Id) = Name_Op_Eq
5302 and then Is_Dispatching_Operation (Id)
5303 and then Present (Alias (Id))
5304 and then Present (Overridden_Operation (Alias (Id)))
5305 and then Base_Type (Etype (First_Entity (Id))) =
5306 Base_Type (Etype (First_Entity (Alias (Id))))
5310 -- Include the subprogram in the list of primitives
5313 Append_Elmt (Id, Op_List);
5315 -- Save collected equality primitives for later filtering
5316 -- (if we are processing a private type for which we can
5317 -- collect several candidates).
5319 if Inherits_From_Tagged_Full_View (T)
5320 and then Chars (Id) = Name_Op_Eq
5321 and then Etype (First_Formal (Id)) =
5322 Etype (Next_Formal (First_Formal (Id)))
5324 if No (Eq_Prims_List) then
5325 Eq_Prims_List := New_Elmt_List;
5328 Append_Elmt (Id, Eq_Prims_List);
5336 -- For a type declared in System, some of its operations may
5337 -- appear in the target-specific extension to System.
5340 and then B_Scope = RTU_Entity (System)
5341 and then Present_System_Aux
5343 B_Scope := System_Aux_Id;
5344 Id := First_Entity (System_Aux_Id);
5348 -- Filter collected equality primitives
5350 if Inherits_From_Tagged_Full_View (T)
5351 and then Present (Eq_Prims_List)
5354 First : constant Elmt_Id := First_Elmt (Eq_Prims_List);
5358 pragma Assert (No (Next_Elmt (First))
5359 or else No (Next_Elmt (Next_Elmt (First))));
5361 -- No action needed if we have collected a single equality
5364 if Present (Next_Elmt (First)) then
5365 Second := Next_Elmt (First);
5367 if Is_Dispatching_Operation
5368 (Ultimate_Alias (Node (First)))
5370 Remove (Op_List, Node (First));
5372 elsif Is_Dispatching_Operation
5373 (Ultimate_Alias (Node (Second)))
5375 Remove (Op_List, Node (Second));
5378 pragma Assert (False);
5379 raise Program_Error;
5387 end Collect_Primitive_Operations;
5389 -----------------------------------
5390 -- Compile_Time_Constraint_Error --
5391 -----------------------------------
5393 function Compile_Time_Constraint_Error
5396 Ent : Entity_Id := Empty;
5397 Loc : Source_Ptr := No_Location;
5398 Warn : Boolean := False;
5399 Extra_Msg : String := "") return Node_Id
5401 Msgc : String (1 .. Msg'Length + 3);
5402 -- Copy of message, with room for possible ?? or << and ! at end
5408 -- Start of processing for Compile_Time_Constraint_Error
5411 -- If this is a warning, convert it into an error if we are in code
5412 -- subject to SPARK_Mode being set On, unless Warn is True to force a
5413 -- warning. The rationale is that a compile-time constraint error should
5414 -- lead to an error instead of a warning when SPARK_Mode is On, but in
5415 -- a few cases we prefer to issue a warning and generate both a suitable
5416 -- run-time error in GNAT and a suitable check message in GNATprove.
5417 -- Those cases are those that likely correspond to deactivated SPARK
5418 -- code, so that this kind of code can be compiled and analyzed instead
5419 -- of being rejected.
5421 Error_Msg_Warn := Warn or SPARK_Mode /= On;
5423 -- A static constraint error in an instance body is not a fatal error.
5424 -- we choose to inhibit the message altogether, because there is no
5425 -- obvious node (for now) on which to post it. On the other hand the
5426 -- offending node must be replaced with a constraint_error in any case.
5428 -- No messages are generated if we already posted an error on this node
5430 if not Error_Posted (N) then
5431 if Loc /= No_Location then
5437 -- Copy message to Msgc, converting any ? in the message into <
5438 -- instead, so that we have an error in GNATprove mode.
5442 for J in 1 .. Msgl loop
5443 if Msg (J) = '?' and then (J = 1 or else Msg (J - 1) /= ''') then
5446 Msgc (J) := Msg (J);
5450 -- Message is a warning, even in Ada 95 case
5452 if Msg (Msg'Last) = '?' or else Msg (Msg'Last) = '<' then
5455 -- In Ada 83, all messages are warnings. In the private part and the
5456 -- body of an instance, constraint_checks are only warnings. We also
5457 -- make this a warning if the Warn parameter is set.
5460 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
5461 or else In_Instance_Not_Visible
5469 -- Otherwise we have a real error message (Ada 95 static case) and we
5470 -- make this an unconditional message. Note that in the warning case
5471 -- we do not make the message unconditional, it seems reasonable to
5472 -- delete messages like this (about exceptions that will be raised)
5481 -- One more test, skip the warning if the related expression is
5482 -- statically unevaluated, since we don't want to warn about what
5483 -- will happen when something is evaluated if it never will be
5486 if not Is_Statically_Unevaluated (N) then
5487 if Present (Ent) then
5488 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
5490 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
5493 -- Emit any extra message as a continuation
5495 if Extra_Msg /= "" then
5496 Error_Msg_N ('\' & Extra_Msg, N);
5501 -- Check whether the context is an Init_Proc
5503 if Inside_Init_Proc then
5505 Conc_Typ : constant Entity_Id :=
5506 Corresponding_Concurrent_Type
5507 (Entity (Parameter_Type (First
5508 (Parameter_Specifications
5509 (Parent (Current_Scope))))));
5512 -- Don't complain if the corresponding concurrent type
5513 -- doesn't come from source (i.e. a single task/protected
5516 if Present (Conc_Typ)
5517 and then not Comes_From_Source (Conc_Typ)
5520 ("\& [<<", N, Standard_Constraint_Error, Eloc);
5523 if GNATprove_Mode then
5525 ("\& would have been raised for objects of this "
5526 & "type", N, Standard_Constraint_Error, Eloc);
5529 ("\& will be raised for objects of this type??",
5530 N, Standard_Constraint_Error, Eloc);
5536 Error_Msg_NEL ("\& [<<", N, Standard_Constraint_Error, Eloc);
5540 Error_Msg ("\static expression fails Constraint_Check", Eloc);
5541 Set_Error_Posted (N);
5547 end Compile_Time_Constraint_Error;
5549 -----------------------
5550 -- Conditional_Delay --
5551 -----------------------
5553 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
5555 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
5556 Set_Has_Delayed_Freeze (New_Ent);
5558 end Conditional_Delay;
5560 -------------------------
5561 -- Copy_Component_List --
5562 -------------------------
5564 function Copy_Component_List
5566 Loc : Source_Ptr) return List_Id
5569 Comps : constant List_Id := New_List;
5572 Comp := First_Component (Underlying_Type (R_Typ));
5573 while Present (Comp) loop
5574 if Comes_From_Source (Comp) then
5576 Comp_Decl : constant Node_Id := Declaration_Node (Comp);
5579 Make_Component_Declaration (Loc,
5580 Defining_Identifier =>
5581 Make_Defining_Identifier (Loc, Chars (Comp)),
5582 Component_Definition =>
5584 (Component_Definition (Comp_Decl), New_Sloc => Loc)));
5588 Next_Component (Comp);
5592 end Copy_Component_List;
5594 -------------------------
5595 -- Copy_Parameter_List --
5596 -------------------------
5598 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
5599 Loc : constant Source_Ptr := Sloc (Subp_Id);
5604 if No (First_Formal (Subp_Id)) then
5608 Formal := First_Formal (Subp_Id);
5609 while Present (Formal) loop
5611 Make_Parameter_Specification (Loc,
5612 Defining_Identifier =>
5613 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
5614 In_Present => In_Present (Parent (Formal)),
5615 Out_Present => Out_Present (Parent (Formal)),
5617 New_Occurrence_Of (Etype (Formal), Loc),
5619 New_Copy_Tree (Expression (Parent (Formal)))));
5621 Next_Formal (Formal);
5626 end Copy_Parameter_List;
5628 ----------------------------
5629 -- Copy_SPARK_Mode_Aspect --
5630 ----------------------------
5632 procedure Copy_SPARK_Mode_Aspect (From : Node_Id; To : Node_Id) is
5633 pragma Assert (not Has_Aspects (To));
5637 if Has_Aspects (From) then
5638 Asp := Find_Aspect (Defining_Entity (From), Aspect_SPARK_Mode);
5640 if Present (Asp) then
5641 Set_Aspect_Specifications (To, New_List (New_Copy_Tree (Asp)));
5642 Set_Has_Aspects (To, True);
5645 end Copy_SPARK_Mode_Aspect;
5647 --------------------------
5648 -- Copy_Subprogram_Spec --
5649 --------------------------
5651 function Copy_Subprogram_Spec (Spec : Node_Id) return Node_Id is
5653 Formal_Spec : Node_Id;
5657 -- The structure of the original tree must be replicated without any
5658 -- alterations. Use New_Copy_Tree for this purpose.
5660 Result := New_Copy_Tree (Spec);
5662 -- However, the spec of a null procedure carries the corresponding null
5663 -- statement of the body (created by the parser), and this cannot be
5664 -- shared with the new subprogram spec.
5666 if Nkind (Result) = N_Procedure_Specification then
5667 Set_Null_Statement (Result, Empty);
5670 -- Create a new entity for the defining unit name
5672 Def_Id := Defining_Unit_Name (Result);
5673 Set_Defining_Unit_Name (Result,
5674 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
5676 -- Create new entities for the formal parameters
5678 if Present (Parameter_Specifications (Result)) then
5679 Formal_Spec := First (Parameter_Specifications (Result));
5680 while Present (Formal_Spec) loop
5681 Def_Id := Defining_Identifier (Formal_Spec);
5682 Set_Defining_Identifier (Formal_Spec,
5683 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
5690 end Copy_Subprogram_Spec;
5692 --------------------------------
5693 -- Corresponding_Generic_Type --
5694 --------------------------------
5696 function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id is
5702 if not Is_Generic_Actual_Type (T) then
5705 -- If the actual is the actual of an enclosing instance, resolution
5706 -- was correct in the generic.
5708 elsif Nkind (Parent (T)) = N_Subtype_Declaration
5709 and then Is_Entity_Name (Subtype_Indication (Parent (T)))
5711 Is_Generic_Actual_Type (Entity (Subtype_Indication (Parent (T))))
5718 if Is_Wrapper_Package (Inst) then
5719 Inst := Related_Instance (Inst);
5724 (Specification (Unit_Declaration_Node (Inst)));
5726 -- Generic actual has the same name as the corresponding formal
5728 Typ := First_Entity (Gen);
5729 while Present (Typ) loop
5730 if Chars (Typ) = Chars (T) then
5739 end Corresponding_Generic_Type;
5741 --------------------
5742 -- Current_Entity --
5743 --------------------
5745 -- The currently visible definition for a given identifier is the
5746 -- one most chained at the start of the visibility chain, i.e. the
5747 -- one that is referenced by the Node_Id value of the name of the
5748 -- given identifier.
5750 function Current_Entity (N : Node_Id) return Entity_Id is
5752 return Get_Name_Entity_Id (Chars (N));
5755 -----------------------------
5756 -- Current_Entity_In_Scope --
5757 -----------------------------
5759 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
5761 CS : constant Entity_Id := Current_Scope;
5763 Transient_Case : constant Boolean := Scope_Is_Transient;
5766 E := Get_Name_Entity_Id (Chars (N));
5768 and then Scope (E) /= CS
5769 and then (not Transient_Case or else Scope (E) /= Scope (CS))
5775 end Current_Entity_In_Scope;
5781 function Current_Scope return Entity_Id is
5783 if Scope_Stack.Last = -1 then
5784 return Standard_Standard;
5787 C : constant Entity_Id :=
5788 Scope_Stack.Table (Scope_Stack.Last).Entity;
5793 return Standard_Standard;
5799 ----------------------------
5800 -- Current_Scope_No_Loops --
5801 ----------------------------
5803 function Current_Scope_No_Loops return Entity_Id is
5807 -- Examine the scope stack starting from the current scope and skip any
5808 -- internally generated loops.
5811 while Present (S) and then S /= Standard_Standard loop
5812 if Ekind (S) = E_Loop and then not Comes_From_Source (S) then
5820 end Current_Scope_No_Loops;
5822 ------------------------
5823 -- Current_Subprogram --
5824 ------------------------
5826 function Current_Subprogram return Entity_Id is
5827 Scop : constant Entity_Id := Current_Scope;
5829 if Is_Subprogram_Or_Generic_Subprogram (Scop) then
5832 return Enclosing_Subprogram (Scop);
5834 end Current_Subprogram;
5836 ----------------------------------
5837 -- Deepest_Type_Access_Level --
5838 ----------------------------------
5840 function Deepest_Type_Access_Level (Typ : Entity_Id) return Uint is
5842 if Ekind (Typ) = E_Anonymous_Access_Type
5843 and then not Is_Local_Anonymous_Access (Typ)
5844 and then Nkind (Associated_Node_For_Itype (Typ)) = N_Object_Declaration
5846 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
5850 Scope_Depth (Enclosing_Dynamic_Scope
5851 (Defining_Identifier
5852 (Associated_Node_For_Itype (Typ))));
5854 -- For generic formal type, return Int'Last (infinite).
5855 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
5857 elsif Is_Generic_Type (Root_Type (Typ)) then
5858 return UI_From_Int (Int'Last);
5861 return Type_Access_Level (Typ);
5863 end Deepest_Type_Access_Level;
5865 ---------------------
5866 -- Defining_Entity --
5867 ---------------------
5869 function Defining_Entity
5871 Empty_On_Errors : Boolean := False;
5872 Concurrent_Subunit : Boolean := False) return Entity_Id
5876 when N_Abstract_Subprogram_Declaration
5877 | N_Expression_Function
5878 | N_Formal_Subprogram_Declaration
5879 | N_Generic_Package_Declaration
5880 | N_Generic_Subprogram_Declaration
5881 | N_Package_Declaration
5883 | N_Subprogram_Body_Stub
5884 | N_Subprogram_Declaration
5885 | N_Subprogram_Renaming_Declaration
5887 return Defining_Entity (Specification (N));
5889 when N_Component_Declaration
5890 | N_Defining_Program_Unit_Name
5891 | N_Discriminant_Specification
5893 | N_Entry_Declaration
5894 | N_Entry_Index_Specification
5895 | N_Exception_Declaration
5896 | N_Exception_Renaming_Declaration
5897 | N_Formal_Object_Declaration
5898 | N_Formal_Package_Declaration
5899 | N_Formal_Type_Declaration
5900 | N_Full_Type_Declaration
5901 | N_Implicit_Label_Declaration
5902 | N_Incomplete_Type_Declaration
5903 | N_Iterator_Specification
5904 | N_Loop_Parameter_Specification
5905 | N_Number_Declaration
5906 | N_Object_Declaration
5907 | N_Object_Renaming_Declaration
5908 | N_Package_Body_Stub
5909 | N_Parameter_Specification
5910 | N_Private_Extension_Declaration
5911 | N_Private_Type_Declaration
5913 | N_Protected_Body_Stub
5914 | N_Protected_Type_Declaration
5915 | N_Single_Protected_Declaration
5916 | N_Single_Task_Declaration
5917 | N_Subtype_Declaration
5920 | N_Task_Type_Declaration
5922 return Defining_Identifier (N);
5926 Bod : constant Node_Id := Proper_Body (N);
5927 Orig_Bod : constant Node_Id := Original_Node (Bod);
5930 -- Retrieve the entity of the original protected or task body
5931 -- if requested by the caller.
5933 if Concurrent_Subunit
5934 and then Nkind (Bod) = N_Null_Statement
5935 and then Nkind_In (Orig_Bod, N_Protected_Body, N_Task_Body)
5937 return Defining_Entity (Orig_Bod);
5939 return Defining_Entity (Bod);
5943 when N_Function_Instantiation
5944 | N_Function_Specification
5945 | N_Generic_Function_Renaming_Declaration
5946 | N_Generic_Package_Renaming_Declaration
5947 | N_Generic_Procedure_Renaming_Declaration
5949 | N_Package_Instantiation
5950 | N_Package_Renaming_Declaration
5951 | N_Package_Specification
5952 | N_Procedure_Instantiation
5953 | N_Procedure_Specification
5956 Nam : constant Node_Id := Defining_Unit_Name (N);
5957 Err : Entity_Id := Empty;
5960 if Nkind (Nam) in N_Entity then
5963 -- For Error, make up a name and attach to declaration so we
5964 -- can continue semantic analysis.
5966 elsif Nam = Error then
5967 if Empty_On_Errors then
5970 Err := Make_Temporary (Sloc (N), 'T');
5971 Set_Defining_Unit_Name (N, Err);
5976 -- If not an entity, get defining identifier
5979 return Defining_Identifier (Nam);
5983 when N_Block_Statement
5986 return Entity (Identifier (N));
5989 if Empty_On_Errors then
5992 raise Program_Error;
5995 end Defining_Entity;
5997 --------------------------
5998 -- Denotes_Discriminant --
5999 --------------------------
6001 function Denotes_Discriminant
6003 Check_Concurrent : Boolean := False) return Boolean
6008 if not Is_Entity_Name (N) or else No (Entity (N)) then
6014 -- If we are checking for a protected type, the discriminant may have
6015 -- been rewritten as the corresponding discriminal of the original type
6016 -- or of the corresponding concurrent record, depending on whether we
6017 -- are in the spec or body of the protected type.
6019 return Ekind (E) = E_Discriminant
6022 and then Ekind (E) = E_In_Parameter
6023 and then Present (Discriminal_Link (E))
6025 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
6027 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
6028 end Denotes_Discriminant;
6030 -------------------------
6031 -- Denotes_Same_Object --
6032 -------------------------
6034 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
6035 function Is_Renaming (N : Node_Id) return Boolean;
6036 -- Return true if N names a renaming entity
6038 function Is_Valid_Renaming (N : Node_Id) return Boolean;
6039 -- For renamings, return False if the prefix of any dereference within
6040 -- the renamed object_name is a variable, or any expression within the
6041 -- renamed object_name contains references to variables or calls on
6042 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
6048 function Is_Renaming (N : Node_Id) return Boolean is
6051 Is_Entity_Name (N) and then Present (Renamed_Entity (Entity (N)));
6054 -----------------------
6055 -- Is_Valid_Renaming --
6056 -----------------------
6058 function Is_Valid_Renaming (N : Node_Id) return Boolean is
6059 function Check_Renaming (N : Node_Id) return Boolean;
6060 -- Recursive function used to traverse all the prefixes of N
6062 --------------------
6063 -- Check_Renaming --
6064 --------------------
6066 function Check_Renaming (N : Node_Id) return Boolean is
6069 and then not Check_Renaming (Renamed_Entity (Entity (N)))
6074 if Nkind (N) = N_Indexed_Component then
6079 Indx := First (Expressions (N));
6080 while Present (Indx) loop
6081 if not Is_OK_Static_Expression (Indx) then
6090 if Has_Prefix (N) then
6092 P : constant Node_Id := Prefix (N);
6095 if Nkind (N) = N_Explicit_Dereference
6096 and then Is_Variable (P)
6100 elsif Is_Entity_Name (P)
6101 and then Ekind (Entity (P)) = E_Function
6105 elsif Nkind (P) = N_Function_Call then
6109 -- Recursion to continue traversing the prefix of the
6110 -- renaming expression
6112 return Check_Renaming (P);
6119 -- Start of processing for Is_Valid_Renaming
6122 return Check_Renaming (N);
6123 end Is_Valid_Renaming;
6127 Obj1 : Node_Id := A1;
6128 Obj2 : Node_Id := A2;
6130 -- Start of processing for Denotes_Same_Object
6133 -- Both names statically denote the same stand-alone object or parameter
6134 -- (RM 6.4.1(6.5/3))
6136 if Is_Entity_Name (Obj1)
6137 and then Is_Entity_Name (Obj2)
6138 and then Entity (Obj1) = Entity (Obj2)
6143 -- For renamings, the prefix of any dereference within the renamed
6144 -- object_name is not a variable, and any expression within the
6145 -- renamed object_name contains no references to variables nor
6146 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
6148 if Is_Renaming (Obj1) then
6149 if Is_Valid_Renaming (Obj1) then
6150 Obj1 := Renamed_Entity (Entity (Obj1));
6156 if Is_Renaming (Obj2) then
6157 if Is_Valid_Renaming (Obj2) then
6158 Obj2 := Renamed_Entity (Entity (Obj2));
6164 -- No match if not same node kind (such cases are handled by
6165 -- Denotes_Same_Prefix)
6167 if Nkind (Obj1) /= Nkind (Obj2) then
6170 -- After handling valid renamings, one of the two names statically
6171 -- denoted a renaming declaration whose renamed object_name is known
6172 -- to denote the same object as the other (RM 6.4.1(6.10/3))
6174 elsif Is_Entity_Name (Obj1) then
6175 if Is_Entity_Name (Obj2) then
6176 return Entity (Obj1) = Entity (Obj2);
6181 -- Both names are selected_components, their prefixes are known to
6182 -- denote the same object, and their selector_names denote the same
6183 -- component (RM 6.4.1(6.6/3)).
6185 elsif Nkind (Obj1) = N_Selected_Component then
6186 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
6188 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
6190 -- Both names are dereferences and the dereferenced names are known to
6191 -- denote the same object (RM 6.4.1(6.7/3))
6193 elsif Nkind (Obj1) = N_Explicit_Dereference then
6194 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
6196 -- Both names are indexed_components, their prefixes are known to denote
6197 -- the same object, and each of the pairs of corresponding index values
6198 -- are either both static expressions with the same static value or both
6199 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
6201 elsif Nkind (Obj1) = N_Indexed_Component then
6202 if not Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
6210 Indx1 := First (Expressions (Obj1));
6211 Indx2 := First (Expressions (Obj2));
6212 while Present (Indx1) loop
6214 -- Indexes must denote the same static value or same object
6216 if Is_OK_Static_Expression (Indx1) then
6217 if not Is_OK_Static_Expression (Indx2) then
6220 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
6224 elsif not Denotes_Same_Object (Indx1, Indx2) then
6236 -- Both names are slices, their prefixes are known to denote the same
6237 -- object, and the two slices have statically matching index constraints
6238 -- (RM 6.4.1(6.9/3))
6240 elsif Nkind (Obj1) = N_Slice
6241 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
6244 Lo1, Lo2, Hi1, Hi2 : Node_Id;
6247 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
6248 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
6250 -- Check whether bounds are statically identical. There is no
6251 -- attempt to detect partial overlap of slices.
6253 return Denotes_Same_Object (Lo1, Lo2)
6255 Denotes_Same_Object (Hi1, Hi2);
6258 -- In the recursion, literals appear as indexes
6260 elsif Nkind (Obj1) = N_Integer_Literal
6262 Nkind (Obj2) = N_Integer_Literal
6264 return Intval (Obj1) = Intval (Obj2);
6269 end Denotes_Same_Object;
6271 -------------------------
6272 -- Denotes_Same_Prefix --
6273 -------------------------
6275 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
6277 if Is_Entity_Name (A1) then
6278 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
6279 and then not Is_Access_Type (Etype (A1))
6281 return Denotes_Same_Object (A1, Prefix (A2))
6282 or else Denotes_Same_Prefix (A1, Prefix (A2));
6287 elsif Is_Entity_Name (A2) then
6288 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
6290 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
6292 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
6295 Root1, Root2 : Node_Id;
6296 Depth1, Depth2 : Nat := 0;
6299 Root1 := Prefix (A1);
6300 while not Is_Entity_Name (Root1) loop
6302 (Root1, N_Selected_Component, N_Indexed_Component)
6306 Root1 := Prefix (Root1);
6309 Depth1 := Depth1 + 1;
6312 Root2 := Prefix (A2);
6313 while not Is_Entity_Name (Root2) loop
6314 if not Nkind_In (Root2, N_Selected_Component,
6315 N_Indexed_Component)
6319 Root2 := Prefix (Root2);
6322 Depth2 := Depth2 + 1;
6325 -- If both have the same depth and they do not denote the same
6326 -- object, they are disjoint and no warning is needed.
6328 if Depth1 = Depth2 then
6331 elsif Depth1 > Depth2 then
6332 Root1 := Prefix (A1);
6333 for J in 1 .. Depth1 - Depth2 - 1 loop
6334 Root1 := Prefix (Root1);
6337 return Denotes_Same_Object (Root1, A2);
6340 Root2 := Prefix (A2);
6341 for J in 1 .. Depth2 - Depth1 - 1 loop
6342 Root2 := Prefix (Root2);
6345 return Denotes_Same_Object (A1, Root2);
6352 end Denotes_Same_Prefix;
6354 ----------------------
6355 -- Denotes_Variable --
6356 ----------------------
6358 function Denotes_Variable (N : Node_Id) return Boolean is
6360 return Is_Variable (N) and then Paren_Count (N) = 0;
6361 end Denotes_Variable;
6363 -----------------------------
6364 -- Depends_On_Discriminant --
6365 -----------------------------
6367 function Depends_On_Discriminant (N : Node_Id) return Boolean is
6372 Get_Index_Bounds (N, L, H);
6373 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
6374 end Depends_On_Discriminant;
6376 -------------------------
6377 -- Designate_Same_Unit --
6378 -------------------------
6380 function Designate_Same_Unit
6382 Name2 : Node_Id) return Boolean
6384 K1 : constant Node_Kind := Nkind (Name1);
6385 K2 : constant Node_Kind := Nkind (Name2);
6387 function Prefix_Node (N : Node_Id) return Node_Id;
6388 -- Returns the parent unit name node of a defining program unit name
6389 -- or the prefix if N is a selected component or an expanded name.
6391 function Select_Node (N : Node_Id) return Node_Id;
6392 -- Returns the defining identifier node of a defining program unit
6393 -- name or the selector node if N is a selected component or an
6400 function Prefix_Node (N : Node_Id) return Node_Id is
6402 if Nkind (N) = N_Defining_Program_Unit_Name then
6413 function Select_Node (N : Node_Id) return Node_Id is
6415 if Nkind (N) = N_Defining_Program_Unit_Name then
6416 return Defining_Identifier (N);
6418 return Selector_Name (N);
6422 -- Start of processing for Designate_Same_Unit
6425 if Nkind_In (K1, N_Identifier, N_Defining_Identifier)
6427 Nkind_In (K2, N_Identifier, N_Defining_Identifier)
6429 return Chars (Name1) = Chars (Name2);
6431 elsif Nkind_In (K1, N_Expanded_Name,
6432 N_Selected_Component,
6433 N_Defining_Program_Unit_Name)
6435 Nkind_In (K2, N_Expanded_Name,
6436 N_Selected_Component,
6437 N_Defining_Program_Unit_Name)
6440 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
6442 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
6447 end Designate_Same_Unit;
6449 ---------------------------------------------
6450 -- Diagnose_Iterated_Component_Association --
6451 ---------------------------------------------
6453 procedure Diagnose_Iterated_Component_Association (N : Node_Id) is
6454 Def_Id : constant Entity_Id := Defining_Identifier (N);
6458 -- Determine whether the iterated component association appears within
6459 -- an aggregate. If this is the case, raise Program_Error because the
6460 -- iterated component association cannot be left in the tree as is and
6461 -- must always be processed by the related aggregate.
6464 while Present (Aggr) loop
6465 if Nkind (Aggr) = N_Aggregate then
6466 raise Program_Error;
6468 -- Prevent the search from going too far
6470 elsif Is_Body_Or_Package_Declaration (Aggr) then
6474 Aggr := Parent (Aggr);
6477 -- At this point it is known that the iterated component association is
6478 -- not within an aggregate. This is really a quantified expression with
6479 -- a missing "all" or "some" quantifier.
6481 Error_Msg_N ("missing quantifier", Def_Id);
6483 -- Rewrite the iterated component association as True to prevent any
6486 Rewrite (N, New_Occurrence_Of (Standard_True, Sloc (N)));
6488 end Diagnose_Iterated_Component_Association;
6490 ---------------------------------
6491 -- Dynamic_Accessibility_Level --
6492 ---------------------------------
6494 function Dynamic_Accessibility_Level (N : Node_Id) return Node_Id is
6495 Loc : constant Source_Ptr := Sloc (N);
6497 function Make_Level_Literal (Level : Uint) return Node_Id;
6498 -- Construct an integer literal representing an accessibility level
6499 -- with its type set to Natural.
6501 ------------------------
6502 -- Make_Level_Literal --
6503 ------------------------
6505 function Make_Level_Literal (Level : Uint) return Node_Id is
6506 Result : constant Node_Id := Make_Integer_Literal (Loc, Level);
6509 Set_Etype (Result, Standard_Natural);
6511 end Make_Level_Literal;
6515 Expr : constant Node_Id := Original_Node (N);
6516 -- Expr references the original node because at this stage N may be the
6517 -- reference to a variable internally created by the frontend to remove
6518 -- side effects of an expression.
6522 -- Start of processing for Dynamic_Accessibility_Level
6525 if Is_Entity_Name (Expr) then
6528 if Present (Renamed_Object (E)) then
6529 return Dynamic_Accessibility_Level (Renamed_Object (E));
6532 if Is_Formal (E) or else Ekind_In (E, E_Variable, E_Constant) then
6533 if Present (Extra_Accessibility (E)) then
6534 return New_Occurrence_Of (Extra_Accessibility (E), Loc);
6539 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
6541 case Nkind (Expr) is
6543 -- For access discriminant, the level of the enclosing object
6545 when N_Selected_Component =>
6546 if Ekind (Entity (Selector_Name (Expr))) = E_Discriminant
6547 and then Ekind (Etype (Entity (Selector_Name (Expr)))) =
6548 E_Anonymous_Access_Type
6550 return Make_Level_Literal (Object_Access_Level (Expr));
6553 when N_Attribute_Reference =>
6554 case Get_Attribute_Id (Attribute_Name (Expr)) is
6556 -- For X'Access, the level of the prefix X
6558 when Attribute_Access =>
6559 return Make_Level_Literal
6560 (Object_Access_Level (Prefix (Expr)));
6562 -- Treat the unchecked attributes as library-level
6564 when Attribute_Unchecked_Access
6565 | Attribute_Unrestricted_Access
6567 return Make_Level_Literal (Scope_Depth (Standard_Standard));
6569 -- No other access-valued attributes
6572 raise Program_Error;
6577 -- This is not fully implemented since it depends on context (see
6578 -- 3.10.2(14/3-14.2/3). More work is needed in the following cases
6580 -- 1) For an anonymous allocator defining the value of an access
6581 -- parameter, the accessibility level is that of the innermost
6582 -- master of the call; however currently we pass the level of
6583 -- execution of the called subprogram, which is one greater
6584 -- than the current scope level (see Expand_Call_Helper).
6586 -- For example, a statement is a master and a declaration is
6587 -- not a master; so we should not pass in the same level for
6588 -- the following cases:
6590 -- function F (X : access Integer) return T is ... ;
6591 -- Decl : T := F (new Integer); -- level is off by one
6593 -- Decl := F (new Integer); -- we get this case right
6595 -- 2) For an anonymous allocator that defines the result of a
6596 -- function with an access result, the accessibility level is
6597 -- determined as though the allocator were in place of the call
6598 -- of the function. In the special case of a call that is the
6599 -- operand of a type conversion the level is that of the target
6600 -- access type of the conversion.
6602 -- 3) For an anonymous allocator defining an access discriminant
6603 -- the accessibility level is determined as follows:
6604 -- * for an allocator used to define the discriminant of an
6605 -- object, the level of the object
6606 -- * for an allocator used to define the constraint in a
6607 -- subtype_indication in any other context, the level of
6608 -- the master that elaborates the subtype_indication.
6610 case Nkind (Parent (N)) is
6611 when N_Object_Declaration =>
6613 -- For an anonymous allocator whose type is that of a
6614 -- stand-alone object of an anonymous access-to-object type,
6615 -- the accessibility level is that of the declaration of the
6616 -- stand-alone object.
6620 (Object_Access_Level
6621 (Defining_Identifier (Parent (N))));
6623 when N_Assignment_Statement =>
6626 (Object_Access_Level (Name (Parent (N))));
6630 S : constant String :=
6631 Node_Kind'Image (Nkind (Parent (N)));
6633 Error_Msg_Strlen := S'Length;
6634 Error_Msg_String (1 .. Error_Msg_Strlen) := S;
6636 ("unsupported context for anonymous allocator (~)",
6641 when N_Type_Conversion =>
6642 if not Is_Local_Anonymous_Access (Etype (Expr)) then
6644 -- Handle type conversions introduced for a rename of an
6645 -- Ada 2012 stand-alone object of an anonymous access type.
6647 return Dynamic_Accessibility_Level (Expression (Expr));
6654 return Make_Level_Literal (Type_Access_Level (Etype (Expr)));
6655 end Dynamic_Accessibility_Level;
6657 ------------------------
6658 -- Discriminated_Size --
6659 ------------------------
6661 function Discriminated_Size (Comp : Entity_Id) return Boolean is
6662 function Non_Static_Bound (Bound : Node_Id) return Boolean;
6663 -- Check whether the bound of an index is non-static and does denote
6664 -- a discriminant, in which case any object of the type (protected or
6665 -- otherwise) will have a non-static size.
6667 ----------------------
6668 -- Non_Static_Bound --
6669 ----------------------
6671 function Non_Static_Bound (Bound : Node_Id) return Boolean is
6673 if Is_OK_Static_Expression (Bound) then
6676 -- If the bound is given by a discriminant it is non-static
6677 -- (A static constraint replaces the reference with the value).
6678 -- In an protected object the discriminant has been replaced by
6679 -- the corresponding discriminal within the protected operation.
6681 elsif Is_Entity_Name (Bound)
6683 (Ekind (Entity (Bound)) = E_Discriminant
6684 or else Present (Discriminal_Link (Entity (Bound))))
6691 end Non_Static_Bound;
6695 Typ : constant Entity_Id := Etype (Comp);
6698 -- Start of processing for Discriminated_Size
6701 if not Is_Array_Type (Typ) then
6705 if Ekind (Typ) = E_Array_Subtype then
6706 Index := First_Index (Typ);
6707 while Present (Index) loop
6708 if Non_Static_Bound (Low_Bound (Index))
6709 or else Non_Static_Bound (High_Bound (Index))
6721 end Discriminated_Size;
6723 -----------------------------------
6724 -- Effective_Extra_Accessibility --
6725 -----------------------------------
6727 function Effective_Extra_Accessibility (Id : Entity_Id) return Entity_Id is
6729 if Present (Renamed_Object (Id))
6730 and then Is_Entity_Name (Renamed_Object (Id))
6732 return Effective_Extra_Accessibility (Entity (Renamed_Object (Id)));
6734 return Extra_Accessibility (Id);
6736 end Effective_Extra_Accessibility;
6738 -----------------------------
6739 -- Effective_Reads_Enabled --
6740 -----------------------------
6742 function Effective_Reads_Enabled (Id : Entity_Id) return Boolean is
6744 return Has_Enabled_Property (Id, Name_Effective_Reads);
6745 end Effective_Reads_Enabled;
6747 ------------------------------
6748 -- Effective_Writes_Enabled --
6749 ------------------------------
6751 function Effective_Writes_Enabled (Id : Entity_Id) return Boolean is
6753 return Has_Enabled_Property (Id, Name_Effective_Writes);
6754 end Effective_Writes_Enabled;
6756 ------------------------------
6757 -- Enclosing_Comp_Unit_Node --
6758 ------------------------------
6760 function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id is
6761 Current_Node : Node_Id;
6765 while Present (Current_Node)
6766 and then Nkind (Current_Node) /= N_Compilation_Unit
6768 Current_Node := Parent (Current_Node);
6771 if Nkind (Current_Node) /= N_Compilation_Unit then
6774 return Current_Node;
6776 end Enclosing_Comp_Unit_Node;
6778 --------------------------
6779 -- Enclosing_CPP_Parent --
6780 --------------------------
6782 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
6783 Parent_Typ : Entity_Id := Typ;
6786 while not Is_CPP_Class (Parent_Typ)
6787 and then Etype (Parent_Typ) /= Parent_Typ
6789 Parent_Typ := Etype (Parent_Typ);
6791 if Is_Private_Type (Parent_Typ) then
6792 Parent_Typ := Full_View (Base_Type (Parent_Typ));
6796 pragma Assert (Is_CPP_Class (Parent_Typ));
6798 end Enclosing_CPP_Parent;
6800 ---------------------------
6801 -- Enclosing_Declaration --
6802 ---------------------------
6804 function Enclosing_Declaration (N : Node_Id) return Node_Id is
6805 Decl : Node_Id := N;
6808 while Present (Decl)
6809 and then not (Nkind (Decl) in N_Declaration
6811 Nkind (Decl) in N_Later_Decl_Item
6813 Nkind (Decl) = N_Number_Declaration)
6815 Decl := Parent (Decl);
6819 end Enclosing_Declaration;
6821 ----------------------------
6822 -- Enclosing_Generic_Body --
6823 ----------------------------
6825 function Enclosing_Generic_Body (N : Node_Id) return Node_Id is
6827 Spec_Id : Entity_Id;
6831 while Present (Par) loop
6832 if Nkind_In (Par, N_Package_Body, N_Subprogram_Body) then
6833 Spec_Id := Corresponding_Spec (Par);
6835 if Present (Spec_Id)
6836 and then Nkind_In (Unit_Declaration_Node (Spec_Id),
6837 N_Generic_Package_Declaration,
6838 N_Generic_Subprogram_Declaration)
6844 Par := Parent (Par);
6848 end Enclosing_Generic_Body;
6850 ----------------------------
6851 -- Enclosing_Generic_Unit --
6852 ----------------------------
6854 function Enclosing_Generic_Unit (N : Node_Id) return Node_Id is
6856 Spec_Decl : Node_Id;
6857 Spec_Id : Entity_Id;
6861 while Present (Par) loop
6862 if Nkind_In (Par, N_Generic_Package_Declaration,
6863 N_Generic_Subprogram_Declaration)
6867 elsif Nkind_In (Par, N_Package_Body, N_Subprogram_Body) then
6868 Spec_Id := Corresponding_Spec (Par);
6870 if Present (Spec_Id) then
6871 Spec_Decl := Unit_Declaration_Node (Spec_Id);
6873 if Nkind_In (Spec_Decl, N_Generic_Package_Declaration,
6874 N_Generic_Subprogram_Declaration)
6881 Par := Parent (Par);
6885 end Enclosing_Generic_Unit;
6887 -------------------------------
6888 -- Enclosing_Lib_Unit_Entity --
6889 -------------------------------
6891 function Enclosing_Lib_Unit_Entity
6892 (E : Entity_Id := Current_Scope) return Entity_Id
6894 Unit_Entity : Entity_Id;
6897 -- Look for enclosing library unit entity by following scope links.
6898 -- Equivalent to, but faster than indexing through the scope stack.
6901 while (Present (Scope (Unit_Entity))
6902 and then Scope (Unit_Entity) /= Standard_Standard)
6903 and not Is_Child_Unit (Unit_Entity)
6905 Unit_Entity := Scope (Unit_Entity);
6909 end Enclosing_Lib_Unit_Entity;
6911 -----------------------------
6912 -- Enclosing_Lib_Unit_Node --
6913 -----------------------------
6915 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
6916 Encl_Unit : Node_Id;
6919 Encl_Unit := Enclosing_Comp_Unit_Node (N);
6920 while Present (Encl_Unit)
6921 and then Nkind (Unit (Encl_Unit)) = N_Subunit
6923 Encl_Unit := Library_Unit (Encl_Unit);
6926 pragma Assert (Nkind (Encl_Unit) = N_Compilation_Unit);
6928 end Enclosing_Lib_Unit_Node;
6930 -----------------------
6931 -- Enclosing_Package --
6932 -----------------------
6934 function Enclosing_Package (E : Entity_Id) return Entity_Id is
6935 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
6938 if Dynamic_Scope = Standard_Standard then
6939 return Standard_Standard;
6941 elsif Dynamic_Scope = Empty then
6944 elsif Ekind_In (Dynamic_Scope, E_Generic_Package,
6948 return Dynamic_Scope;
6951 return Enclosing_Package (Dynamic_Scope);
6953 end Enclosing_Package;
6955 -------------------------------------
6956 -- Enclosing_Package_Or_Subprogram --
6957 -------------------------------------
6959 function Enclosing_Package_Or_Subprogram (E : Entity_Id) return Entity_Id is
6964 while Present (S) loop
6965 if Is_Package_Or_Generic_Package (S)
6966 or else Is_Subprogram_Or_Generic_Subprogram (S)
6976 end Enclosing_Package_Or_Subprogram;
6978 --------------------------
6979 -- Enclosing_Subprogram --
6980 --------------------------
6982 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
6983 Dyn_Scop : constant Entity_Id := Enclosing_Dynamic_Scope (E);
6986 if Dyn_Scop = Standard_Standard then
6989 elsif Dyn_Scop = Empty then
6992 elsif Ekind (Dyn_Scop) = E_Subprogram_Body then
6993 return Corresponding_Spec (Parent (Parent (Dyn_Scop)));
6995 elsif Ekind_In (Dyn_Scop, E_Block, E_Loop, E_Return_Statement) then
6996 return Enclosing_Subprogram (Dyn_Scop);
6998 elsif Ekind (Dyn_Scop) = E_Entry then
7000 -- For a task entry, return the enclosing subprogram of the
7003 if Ekind (Scope (Dyn_Scop)) = E_Task_Type then
7004 return Enclosing_Subprogram (Dyn_Scop);
7006 -- A protected entry is rewritten as a protected procedure which is
7007 -- the desired enclosing subprogram. This is relevant when unnesting
7008 -- a procedure local to an entry body.
7011 return Protected_Body_Subprogram (Dyn_Scop);
7014 elsif Ekind (Dyn_Scop) = E_Task_Type then
7015 return Get_Task_Body_Procedure (Dyn_Scop);
7017 -- The scope may appear as a private type or as a private extension
7018 -- whose completion is a task or protected type.
7020 elsif Ekind_In (Dyn_Scop, E_Limited_Private_Type,
7021 E_Record_Type_With_Private)
7022 and then Present (Full_View (Dyn_Scop))
7023 and then Ekind_In (Full_View (Dyn_Scop), E_Task_Type, E_Protected_Type)
7025 return Get_Task_Body_Procedure (Full_View (Dyn_Scop));
7027 -- No body is generated if the protected operation is eliminated
7029 elsif Convention (Dyn_Scop) = Convention_Protected
7030 and then not Is_Eliminated (Dyn_Scop)
7031 and then Present (Protected_Body_Subprogram (Dyn_Scop))
7033 return Protected_Body_Subprogram (Dyn_Scop);
7038 end Enclosing_Subprogram;
7040 --------------------------
7041 -- End_Keyword_Location --
7042 --------------------------
7044 function End_Keyword_Location (N : Node_Id) return Source_Ptr is
7045 function End_Label_Loc (Nod : Node_Id) return Source_Ptr;
7046 -- Return the source location of Nod's end label according to the
7047 -- following precedence rules:
7049 -- 1) If the end label exists, return its location
7050 -- 2) If Nod exists, return its location
7051 -- 3) Return the location of N
7057 function End_Label_Loc (Nod : Node_Id) return Source_Ptr is
7061 if Present (Nod) then
7062 Label := End_Label (Nod);
7064 if Present (Label) then
7065 return Sloc (Label);
7079 -- Start of processing for End_Keyword_Location
7082 if Nkind_In (N, N_Block_Statement,
7088 Owner := Handled_Statement_Sequence (N);
7090 elsif Nkind (N) = N_Package_Declaration then
7091 Owner := Specification (N);
7093 elsif Nkind (N) = N_Protected_Body then
7096 elsif Nkind_In (N, N_Protected_Type_Declaration,
7097 N_Single_Protected_Declaration)
7099 Owner := Protected_Definition (N);
7101 elsif Nkind_In (N, N_Single_Task_Declaration,
7102 N_Task_Type_Declaration)
7104 Owner := Task_Definition (N);
7106 -- This routine should not be called with other contexts
7109 pragma Assert (False);
7113 return End_Label_Loc (Owner);
7114 end End_Keyword_Location;
7116 ------------------------
7117 -- Ensure_Freeze_Node --
7118 ------------------------
7120 procedure Ensure_Freeze_Node (E : Entity_Id) is
7123 if No (Freeze_Node (E)) then
7124 FN := Make_Freeze_Entity (Sloc (E));
7125 Set_Has_Delayed_Freeze (E);
7126 Set_Freeze_Node (E, FN);
7127 Set_Access_Types_To_Process (FN, No_Elist);
7128 Set_TSS_Elist (FN, No_Elist);
7131 end Ensure_Freeze_Node;
7137 procedure Enter_Name (Def_Id : Entity_Id) is
7138 C : constant Entity_Id := Current_Entity (Def_Id);
7139 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
7140 S : constant Entity_Id := Current_Scope;
7143 Generate_Definition (Def_Id);
7145 -- Add new name to current scope declarations. Check for duplicate
7146 -- declaration, which may or may not be a genuine error.
7150 -- Case of previous entity entered because of a missing declaration
7151 -- or else a bad subtype indication. Best is to use the new entity,
7152 -- and make the previous one invisible.
7154 if Etype (E) = Any_Type then
7155 Set_Is_Immediately_Visible (E, False);
7157 -- Case of renaming declaration constructed for package instances.
7158 -- if there is an explicit declaration with the same identifier,
7159 -- the renaming is not immediately visible any longer, but remains
7160 -- visible through selected component notation.
7162 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
7163 and then not Comes_From_Source (E)
7165 Set_Is_Immediately_Visible (E, False);
7167 -- The new entity may be the package renaming, which has the same
7168 -- same name as a generic formal which has been seen already.
7170 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
7171 and then not Comes_From_Source (Def_Id)
7173 Set_Is_Immediately_Visible (E, False);
7175 -- For a fat pointer corresponding to a remote access to subprogram,
7176 -- we use the same identifier as the RAS type, so that the proper
7177 -- name appears in the stub. This type is only retrieved through
7178 -- the RAS type and never by visibility, and is not added to the
7179 -- visibility list (see below).
7181 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
7182 and then Ekind (Def_Id) = E_Record_Type
7183 and then Present (Corresponding_Remote_Type (Def_Id))
7187 -- Case of an implicit operation or derived literal. The new entity
7188 -- hides the implicit one, which is removed from all visibility,
7189 -- i.e. the entity list of its scope, and homonym chain of its name.
7191 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
7192 or else Is_Internal (E)
7195 Decl : constant Node_Id := Parent (E);
7197 Prev_Vis : Entity_Id;
7200 -- If E is an implicit declaration, it cannot be the first
7201 -- entity in the scope.
7203 Prev := First_Entity (Current_Scope);
7204 while Present (Prev) and then Next_Entity (Prev) /= E loop
7210 -- If E is not on the entity chain of the current scope,
7211 -- it is an implicit declaration in the generic formal
7212 -- part of a generic subprogram. When analyzing the body,
7213 -- the generic formals are visible but not on the entity
7214 -- chain of the subprogram. The new entity will become
7215 -- the visible one in the body.
7218 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
7222 Link_Entities (Prev, Next_Entity (E));
7224 if No (Next_Entity (Prev)) then
7225 Set_Last_Entity (Current_Scope, Prev);
7228 if E = Current_Entity (E) then
7232 Prev_Vis := Current_Entity (E);
7233 while Homonym (Prev_Vis) /= E loop
7234 Prev_Vis := Homonym (Prev_Vis);
7238 if Present (Prev_Vis) then
7240 -- Skip E in the visibility chain
7242 Set_Homonym (Prev_Vis, Homonym (E));
7245 Set_Name_Entity_Id (Chars (E), Homonym (E));
7250 -- This section of code could use a comment ???
7252 elsif Present (Etype (E))
7253 and then Is_Concurrent_Type (Etype (E))
7258 -- If the homograph is a protected component renaming, it should not
7259 -- be hiding the current entity. Such renamings are treated as weak
7262 elsif Is_Prival (E) then
7263 Set_Is_Immediately_Visible (E, False);
7265 -- In this case the current entity is a protected component renaming.
7266 -- Perform minimal decoration by setting the scope and return since
7267 -- the prival should not be hiding other visible entities.
7269 elsif Is_Prival (Def_Id) then
7270 Set_Scope (Def_Id, Current_Scope);
7273 -- Analogous to privals, the discriminal generated for an entry index
7274 -- parameter acts as a weak declaration. Perform minimal decoration
7275 -- to avoid bogus errors.
7277 elsif Is_Discriminal (Def_Id)
7278 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
7280 Set_Scope (Def_Id, Current_Scope);
7283 -- In the body or private part of an instance, a type extension may
7284 -- introduce a component with the same name as that of an actual. The
7285 -- legality rule is not enforced, but the semantics of the full type
7286 -- with two components of same name are not clear at this point???
7288 elsif In_Instance_Not_Visible then
7291 -- When compiling a package body, some child units may have become
7292 -- visible. They cannot conflict with local entities that hide them.
7294 elsif Is_Child_Unit (E)
7295 and then In_Open_Scopes (Scope (E))
7296 and then not Is_Immediately_Visible (E)
7300 -- Conversely, with front-end inlining we may compile the parent body
7301 -- first, and a child unit subsequently. The context is now the
7302 -- parent spec, and body entities are not visible.
7304 elsif Is_Child_Unit (Def_Id)
7305 and then Is_Package_Body_Entity (E)
7306 and then not In_Package_Body (Current_Scope)
7310 -- Case of genuine duplicate declaration
7313 Error_Msg_Sloc := Sloc (E);
7315 -- If the previous declaration is an incomplete type declaration
7316 -- this may be an attempt to complete it with a private type. The
7317 -- following avoids confusing cascaded errors.
7319 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
7320 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
7323 ("incomplete type cannot be completed with a private " &
7324 "declaration", Parent (Def_Id));
7325 Set_Is_Immediately_Visible (E, False);
7326 Set_Full_View (E, Def_Id);
7328 -- An inherited component of a record conflicts with a new
7329 -- discriminant. The discriminant is inserted first in the scope,
7330 -- but the error should be posted on it, not on the component.
7332 elsif Ekind (E) = E_Discriminant
7333 and then Present (Scope (Def_Id))
7334 and then Scope (Def_Id) /= Current_Scope
7336 Error_Msg_Sloc := Sloc (Def_Id);
7337 Error_Msg_N ("& conflicts with declaration#", E);
7340 -- If the name of the unit appears in its own context clause, a
7341 -- dummy package with the name has already been created, and the
7342 -- error emitted. Try to continue quietly.
7344 elsif Error_Posted (E)
7345 and then Sloc (E) = No_Location
7346 and then Nkind (Parent (E)) = N_Package_Specification
7347 and then Current_Scope = Standard_Standard
7349 Set_Scope (Def_Id, Current_Scope);
7353 Error_Msg_N ("& conflicts with declaration#", Def_Id);
7355 -- Avoid cascaded messages with duplicate components in
7358 if Ekind_In (E, E_Component, E_Discriminant) then
7363 if Nkind (Parent (Parent (Def_Id))) =
7364 N_Generic_Subprogram_Declaration
7366 Defining_Entity (Specification (Parent (Parent (Def_Id))))
7368 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
7371 -- If entity is in standard, then we are in trouble, because it
7372 -- means that we have a library package with a duplicated name.
7373 -- That's hard to recover from, so abort.
7375 if S = Standard_Standard then
7376 raise Unrecoverable_Error;
7378 -- Otherwise we continue with the declaration. Having two
7379 -- identical declarations should not cause us too much trouble.
7387 -- If we fall through, declaration is OK, at least OK enough to continue
7389 -- If Def_Id is a discriminant or a record component we are in the midst
7390 -- of inheriting components in a derived record definition. Preserve
7391 -- their Ekind and Etype.
7393 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
7396 -- If a type is already set, leave it alone (happens when a type
7397 -- declaration is reanalyzed following a call to the optimizer).
7399 elsif Present (Etype (Def_Id)) then
7402 -- Otherwise, the kind E_Void insures that premature uses of the entity
7403 -- will be detected. Any_Type insures that no cascaded errors will occur
7406 Set_Ekind (Def_Id, E_Void);
7407 Set_Etype (Def_Id, Any_Type);
7410 -- Inherited discriminants and components in derived record types are
7411 -- immediately visible. Itypes are not.
7413 -- Unless the Itype is for a record type with a corresponding remote
7414 -- type (what is that about, it was not commented ???)
7416 if Ekind_In (Def_Id, E_Discriminant, E_Component)
7418 ((not Is_Record_Type (Def_Id)
7419 or else No (Corresponding_Remote_Type (Def_Id)))
7420 and then not Is_Itype (Def_Id))
7422 Set_Is_Immediately_Visible (Def_Id);
7423 Set_Current_Entity (Def_Id);
7426 Set_Homonym (Def_Id, C);
7427 Append_Entity (Def_Id, S);
7428 Set_Public_Status (Def_Id);
7430 -- Declaring a homonym is not allowed in SPARK ...
7432 if Present (C) and then Restriction_Check_Required (SPARK_05) then
7434 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
7435 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
7436 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
7439 -- ... unless the new declaration is in a subprogram, and the
7440 -- visible declaration is a variable declaration or a parameter
7441 -- specification outside that subprogram.
7443 if Present (Enclosing_Subp)
7444 and then Nkind_In (Parent (C), N_Object_Declaration,
7445 N_Parameter_Specification)
7446 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
7450 -- ... or the new declaration is in a package, and the visible
7451 -- declaration occurs outside that package.
7453 elsif Present (Enclosing_Pack)
7454 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
7458 -- ... or the new declaration is a component declaration in a
7459 -- record type definition.
7461 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
7464 -- Don't issue error for non-source entities
7466 elsif Comes_From_Source (Def_Id)
7467 and then Comes_From_Source (C)
7469 Error_Msg_Sloc := Sloc (C);
7470 Check_SPARK_05_Restriction
7471 ("redeclaration of identifier &#", Def_Id);
7476 -- Warn if new entity hides an old one
7478 if Warn_On_Hiding and then Present (C)
7480 -- Don't warn for record components since they always have a well
7481 -- defined scope which does not confuse other uses. Note that in
7482 -- some cases, Ekind has not been set yet.
7484 and then Ekind (C) /= E_Component
7485 and then Ekind (C) /= E_Discriminant
7486 and then Nkind (Parent (C)) /= N_Component_Declaration
7487 and then Ekind (Def_Id) /= E_Component
7488 and then Ekind (Def_Id) /= E_Discriminant
7489 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
7491 -- Don't warn for one character variables. It is too common to use
7492 -- such variables as locals and will just cause too many false hits.
7494 and then Length_Of_Name (Chars (C)) /= 1
7496 -- Don't warn for non-source entities
7498 and then Comes_From_Source (C)
7499 and then Comes_From_Source (Def_Id)
7501 -- Don't warn unless entity in question is in extended main source
7503 and then In_Extended_Main_Source_Unit (Def_Id)
7505 -- Finally, the hidden entity must be either immediately visible or
7506 -- use visible (i.e. from a used package).
7509 (Is_Immediately_Visible (C)
7511 Is_Potentially_Use_Visible (C))
7513 Error_Msg_Sloc := Sloc (C);
7514 Error_Msg_N ("declaration hides &#?h?", Def_Id);
7522 function Entity_Of (N : Node_Id) return Entity_Id is
7527 -- Assume that the arbitrary node does not have an entity
7531 if Is_Entity_Name (N) then
7534 -- Follow a possible chain of renamings to reach the earliest renamed
7538 and then Is_Object (Id)
7539 and then Present (Renamed_Object (Id))
7541 Ren := Renamed_Object (Id);
7543 -- The reference renames an abstract state or a whole object
7546 -- Ren : ... renames Obj;
7548 if Is_Entity_Name (Ren) then
7550 -- Do not follow a renaming that goes through a generic formal,
7551 -- because these entities are hidden and must not be referenced
7552 -- from outside the generic.
7554 if Is_Hidden (Entity (Ren)) then
7561 -- The reference renames a function result. Check the original
7562 -- node in case expansion relocates the function call.
7564 -- Ren : ... renames Func_Call;
7566 elsif Nkind (Original_Node (Ren)) = N_Function_Call then
7569 -- Otherwise the reference renames something which does not yield
7570 -- an abstract state or a whole object. Treat the reference as not
7571 -- having a proper entity for SPARK legality purposes.
7583 --------------------------
7584 -- Examine_Array_Bounds --
7585 --------------------------
7587 procedure Examine_Array_Bounds
7589 All_Static : out Boolean;
7590 Has_Empty : out Boolean)
7592 function Is_OK_Static_Bound (Bound : Node_Id) return Boolean;
7593 -- Determine whether bound Bound is a suitable static bound
7595 ------------------------
7596 -- Is_OK_Static_Bound --
7597 ------------------------
7599 function Is_OK_Static_Bound (Bound : Node_Id) return Boolean is
7602 not Error_Posted (Bound)
7603 and then Is_OK_Static_Expression (Bound);
7604 end Is_OK_Static_Bound;
7612 -- Start of processing for Examine_Array_Bounds
7615 -- An unconstrained array type does not have static bounds, and it is
7616 -- not known whether they are empty or not.
7618 if not Is_Constrained (Typ) then
7619 All_Static := False;
7622 -- A string literal has static bounds, and is not empty as long as it
7623 -- contains at least one character.
7625 elsif Ekind (Typ) = E_String_Literal_Subtype then
7627 Has_Empty := String_Literal_Length (Typ) > 0;
7630 -- Assume that all bounds are static and not empty
7635 -- Examine each index
7637 Index := First_Index (Typ);
7638 while Present (Index) loop
7639 if Is_Discrete_Type (Etype (Index)) then
7640 Get_Index_Bounds (Index, Lo_Bound, Hi_Bound);
7642 if Is_OK_Static_Bound (Lo_Bound)
7644 Is_OK_Static_Bound (Hi_Bound)
7646 -- The static bounds produce an empty range
7648 if Is_Null_Range (Lo_Bound, Hi_Bound) then
7652 -- Otherwise at least one of the bounds is not static
7655 All_Static := False;
7658 -- Otherwise the index is non-discrete, therefore not static
7661 All_Static := False;
7666 end Examine_Array_Bounds;
7672 function Exceptions_OK return Boolean is
7675 not (Restriction_Active (No_Exception_Handlers) or else
7676 Restriction_Active (No_Exception_Propagation) or else
7677 Restriction_Active (No_Exceptions));
7680 --------------------------
7681 -- Explain_Limited_Type --
7682 --------------------------
7684 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
7688 -- For array, component type must be limited
7690 if Is_Array_Type (T) then
7691 Error_Msg_Node_2 := T;
7693 ("\component type& of type& is limited", N, Component_Type (T));
7694 Explain_Limited_Type (Component_Type (T), N);
7696 elsif Is_Record_Type (T) then
7698 -- No need for extra messages if explicit limited record
7700 if Is_Limited_Record (Base_Type (T)) then
7704 -- Otherwise find a limited component. Check only components that
7705 -- come from source, or inherited components that appear in the
7706 -- source of the ancestor.
7708 C := First_Component (T);
7709 while Present (C) loop
7710 if Is_Limited_Type (Etype (C))
7712 (Comes_From_Source (C)
7714 (Present (Original_Record_Component (C))
7716 Comes_From_Source (Original_Record_Component (C))))
7718 Error_Msg_Node_2 := T;
7719 Error_Msg_NE ("\component& of type& has limited type", N, C);
7720 Explain_Limited_Type (Etype (C), N);
7727 -- The type may be declared explicitly limited, even if no component
7728 -- of it is limited, in which case we fall out of the loop.
7731 end Explain_Limited_Type;
7733 ---------------------------------------
7734 -- Expression_Of_Expression_Function --
7735 ---------------------------------------
7737 function Expression_Of_Expression_Function
7738 (Subp : Entity_Id) return Node_Id
7740 Expr_Func : Node_Id;
7743 pragma Assert (Is_Expression_Function_Or_Completion (Subp));
7745 if Nkind (Original_Node (Subprogram_Spec (Subp))) =
7746 N_Expression_Function
7748 Expr_Func := Original_Node (Subprogram_Spec (Subp));
7750 elsif Nkind (Original_Node (Subprogram_Body (Subp))) =
7751 N_Expression_Function
7753 Expr_Func := Original_Node (Subprogram_Body (Subp));
7756 pragma Assert (False);
7760 return Original_Node (Expression (Expr_Func));
7761 end Expression_Of_Expression_Function;
7763 -------------------------------
7764 -- Extensions_Visible_Status --
7765 -------------------------------
7767 function Extensions_Visible_Status
7768 (Id : Entity_Id) return Extensions_Visible_Mode
7777 -- When a formal parameter is subject to Extensions_Visible, the pragma
7778 -- is stored in the contract of related subprogram.
7780 if Is_Formal (Id) then
7783 elsif Is_Subprogram_Or_Generic_Subprogram (Id) then
7786 -- No other construct carries this pragma
7789 return Extensions_Visible_None;
7792 Prag := Get_Pragma (Subp, Pragma_Extensions_Visible);
7794 -- In certain cases analysis may request the Extensions_Visible status
7795 -- of an expression function before the pragma has been analyzed yet.
7796 -- Inspect the declarative items after the expression function looking
7797 -- for the pragma (if any).
7799 if No (Prag) and then Is_Expression_Function (Subp) then
7800 Decl := Next (Unit_Declaration_Node (Subp));
7801 while Present (Decl) loop
7802 if Nkind (Decl) = N_Pragma
7803 and then Pragma_Name (Decl) = Name_Extensions_Visible
7808 -- A source construct ends the region where Extensions_Visible may
7809 -- appear, stop the traversal. An expanded expression function is
7810 -- no longer a source construct, but it must still be recognized.
7812 elsif Comes_From_Source (Decl)
7814 (Nkind_In (Decl, N_Subprogram_Body,
7815 N_Subprogram_Declaration)
7816 and then Is_Expression_Function (Defining_Entity (Decl)))
7825 -- Extract the value from the Boolean expression (if any)
7827 if Present (Prag) then
7828 Arg := First (Pragma_Argument_Associations (Prag));
7830 if Present (Arg) then
7831 Expr := Get_Pragma_Arg (Arg);
7833 -- When the associated subprogram is an expression function, the
7834 -- argument of the pragma may not have been analyzed.
7836 if not Analyzed (Expr) then
7837 Preanalyze_And_Resolve (Expr, Standard_Boolean);
7840 -- Guard against cascading errors when the argument of pragma
7841 -- Extensions_Visible is not a valid static Boolean expression.
7843 if Error_Posted (Expr) then
7844 return Extensions_Visible_None;
7846 elsif Is_True (Expr_Value (Expr)) then
7847 return Extensions_Visible_True;
7850 return Extensions_Visible_False;
7853 -- Otherwise the aspect or pragma defaults to True
7856 return Extensions_Visible_True;
7859 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
7860 -- directly specified. In SPARK code, its value defaults to "False".
7862 elsif SPARK_Mode = On then
7863 return Extensions_Visible_False;
7865 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
7869 return Extensions_Visible_True;
7871 end Extensions_Visible_Status;
7877 procedure Find_Actual
7879 Formal : out Entity_Id;
7882 Context : constant Node_Id := Parent (N);
7887 if Nkind_In (Context, N_Indexed_Component, N_Selected_Component)
7888 and then N = Prefix (Context)
7890 Find_Actual (Context, Formal, Call);
7893 elsif Nkind (Context) = N_Parameter_Association
7894 and then N = Explicit_Actual_Parameter (Context)
7896 Call := Parent (Context);
7898 elsif Nkind_In (Context, N_Entry_Call_Statement,
7900 N_Procedure_Call_Statement)
7910 -- If we have a call to a subprogram look for the parameter. Note that
7911 -- we exclude overloaded calls, since we don't know enough to be sure
7912 -- of giving the right answer in this case.
7914 if Nkind_In (Call, N_Entry_Call_Statement,
7916 N_Procedure_Call_Statement)
7918 Call_Nam := Name (Call);
7920 -- A call to a protected or task entry appears as a selected
7921 -- component rather than an expanded name.
7923 if Nkind (Call_Nam) = N_Selected_Component then
7924 Call_Nam := Selector_Name (Call_Nam);
7927 if Is_Entity_Name (Call_Nam)
7928 and then Present (Entity (Call_Nam))
7929 and then Is_Overloadable (Entity (Call_Nam))
7930 and then not Is_Overloaded (Call_Nam)
7932 -- If node is name in call it is not an actual
7934 if N = Call_Nam then
7940 -- Fall here if we are definitely a parameter
7942 Actual := First_Actual (Call);
7943 Formal := First_Formal (Entity (Call_Nam));
7944 while Present (Formal) and then Present (Actual) loop
7948 -- An actual that is the prefix in a prefixed call may have
7949 -- been rewritten in the call, after the deferred reference
7950 -- was collected. Check if sloc and kinds and names match.
7952 elsif Sloc (Actual) = Sloc (N)
7953 and then Nkind (Actual) = N_Identifier
7954 and then Nkind (Actual) = Nkind (N)
7955 and then Chars (Actual) = Chars (N)
7960 Actual := Next_Actual (Actual);
7961 Formal := Next_Formal (Formal);
7967 -- Fall through here if we did not find matching actual
7973 ---------------------------
7974 -- Find_Body_Discriminal --
7975 ---------------------------
7977 function Find_Body_Discriminal
7978 (Spec_Discriminant : Entity_Id) return Entity_Id
7984 -- If expansion is suppressed, then the scope can be the concurrent type
7985 -- itself rather than a corresponding concurrent record type.
7987 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
7988 Tsk := Scope (Spec_Discriminant);
7991 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
7993 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
7996 -- Find discriminant of original concurrent type, and use its current
7997 -- discriminal, which is the renaming within the task/protected body.
7999 Disc := First_Discriminant (Tsk);
8000 while Present (Disc) loop
8001 if Chars (Disc) = Chars (Spec_Discriminant) then
8002 return Discriminal (Disc);
8005 Next_Discriminant (Disc);
8008 -- That loop should always succeed in finding a matching entry and
8009 -- returning. Fatal error if not.
8011 raise Program_Error;
8012 end Find_Body_Discriminal;
8014 -------------------------------------
8015 -- Find_Corresponding_Discriminant --
8016 -------------------------------------
8018 function Find_Corresponding_Discriminant
8020 Typ : Entity_Id) return Entity_Id
8022 Par_Disc : Entity_Id;
8023 Old_Disc : Entity_Id;
8024 New_Disc : Entity_Id;
8027 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
8029 -- The original type may currently be private, and the discriminant
8030 -- only appear on its full view.
8032 if Is_Private_Type (Scope (Par_Disc))
8033 and then not Has_Discriminants (Scope (Par_Disc))
8034 and then Present (Full_View (Scope (Par_Disc)))
8036 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
8038 Old_Disc := First_Discriminant (Scope (Par_Disc));
8041 if Is_Class_Wide_Type (Typ) then
8042 New_Disc := First_Discriminant (Root_Type (Typ));
8044 New_Disc := First_Discriminant (Typ);
8047 while Present (Old_Disc) and then Present (New_Disc) loop
8048 if Old_Disc = Par_Disc then
8052 Next_Discriminant (Old_Disc);
8053 Next_Discriminant (New_Disc);
8056 -- Should always find it
8058 raise Program_Error;
8059 end Find_Corresponding_Discriminant;
8065 function Find_DIC_Type (Typ : Entity_Id) return Entity_Id is
8066 Curr_Typ : Entity_Id;
8067 -- The current type being examined in the parent hierarchy traversal
8069 DIC_Typ : Entity_Id;
8070 -- The type which carries the DIC pragma. This variable denotes the
8071 -- partial view when private types are involved.
8073 Par_Typ : Entity_Id;
8074 -- The parent type of the current type. This variable denotes the full
8075 -- view when private types are involved.
8078 -- The input type defines its own DIC pragma, therefore it is the owner
8080 if Has_Own_DIC (Typ) then
8083 -- Otherwise the DIC pragma is inherited from a parent type
8086 pragma Assert (Has_Inherited_DIC (Typ));
8088 -- Climb the parent chain
8092 -- Inspect the parent type. Do not consider subtypes as they
8093 -- inherit the DIC attributes from their base types.
8095 DIC_Typ := Base_Type (Etype (Curr_Typ));
8097 -- Look at the full view of a private type because the type may
8098 -- have a hidden parent introduced in the full view.
8102 if Is_Private_Type (Par_Typ)
8103 and then Present (Full_View (Par_Typ))
8105 Par_Typ := Full_View (Par_Typ);
8108 -- Stop the climb once the nearest parent type which defines a DIC
8109 -- pragma of its own is encountered or when the root of the parent
8110 -- chain is reached.
8112 exit when Has_Own_DIC (DIC_Typ) or else Curr_Typ = Par_Typ;
8114 Curr_Typ := Par_Typ;
8121 ----------------------------------
8122 -- Find_Enclosing_Iterator_Loop --
8123 ----------------------------------
8125 function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id is
8130 -- Traverse the scope chain looking for an iterator loop. Such loops are
8131 -- usually transformed into blocks, hence the use of Original_Node.
8134 while Present (S) and then S /= Standard_Standard loop
8135 if Ekind (S) = E_Loop
8136 and then Nkind (Parent (S)) = N_Implicit_Label_Declaration
8138 Constr := Original_Node (Label_Construct (Parent (S)));
8140 if Nkind (Constr) = N_Loop_Statement
8141 and then Present (Iteration_Scheme (Constr))
8142 and then Nkind (Iterator_Specification
8143 (Iteration_Scheme (Constr))) =
8144 N_Iterator_Specification
8154 end Find_Enclosing_Iterator_Loop;
8156 --------------------------
8157 -- Find_Enclosing_Scope --
8158 --------------------------
8160 function Find_Enclosing_Scope (N : Node_Id) return Entity_Id is
8164 -- Examine the parent chain looking for a construct which defines a
8168 while Present (Par) loop
8171 -- The construct denotes a declaration, the proper scope is its
8174 when N_Entry_Declaration
8175 | N_Expression_Function
8176 | N_Full_Type_Declaration
8177 | N_Generic_Package_Declaration
8178 | N_Generic_Subprogram_Declaration
8179 | N_Package_Declaration
8180 | N_Private_Extension_Declaration
8181 | N_Protected_Type_Declaration
8182 | N_Single_Protected_Declaration
8183 | N_Single_Task_Declaration
8184 | N_Subprogram_Declaration
8185 | N_Task_Type_Declaration
8187 return Defining_Entity (Par);
8189 -- The construct denotes a body, the proper scope is the entity of
8190 -- the corresponding spec or that of the body if the body does not
8191 -- complete a previous declaration.
8199 return Unique_Defining_Entity (Par);
8203 -- Blocks carry either a source or an internally-generated scope,
8204 -- unless the block is a byproduct of exception handling.
8206 when N_Block_Statement =>
8207 if not Exception_Junk (Par) then
8208 return Entity (Identifier (Par));
8211 -- Loops carry an internally-generated scope
8213 when N_Loop_Statement =>
8214 return Entity (Identifier (Par));
8216 -- Extended return statements carry an internally-generated scope
8218 when N_Extended_Return_Statement =>
8219 return Return_Statement_Entity (Par);
8221 -- A traversal from a subunit continues via the corresponding stub
8224 Par := Corresponding_Stub (Par);
8230 Par := Parent (Par);
8233 return Standard_Standard;
8234 end Find_Enclosing_Scope;
8236 ------------------------------------
8237 -- Find_Loop_In_Conditional_Block --
8238 ------------------------------------
8240 function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is
8246 if Nkind (Stmt) = N_If_Statement then
8247 Stmt := First (Then_Statements (Stmt));
8250 pragma Assert (Nkind (Stmt) = N_Block_Statement);
8252 -- Inspect the statements of the conditional block. In general the loop
8253 -- should be the first statement in the statement sequence of the block,
8254 -- but the finalization machinery may have introduced extra object
8257 Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
8258 while Present (Stmt) loop
8259 if Nkind (Stmt) = N_Loop_Statement then
8266 -- The expansion of attribute 'Loop_Entry produced a malformed block
8268 raise Program_Error;
8269 end Find_Loop_In_Conditional_Block;
8271 --------------------------
8272 -- Find_Overlaid_Entity --
8273 --------------------------
8275 procedure Find_Overlaid_Entity
8277 Ent : out Entity_Id;
8283 -- We are looking for one of the two following forms:
8285 -- for X'Address use Y'Address
8289 -- Const : constant Address := expr;
8291 -- for X'Address use Const;
8293 -- In the second case, the expr is either Y'Address, or recursively a
8294 -- constant that eventually references Y'Address.
8299 if Nkind (N) = N_Attribute_Definition_Clause
8300 and then Chars (N) = Name_Address
8302 Expr := Expression (N);
8304 -- This loop checks the form of the expression for Y'Address,
8305 -- using recursion to deal with intermediate constants.
8308 -- Check for Y'Address
8310 if Nkind (Expr) = N_Attribute_Reference
8311 and then Attribute_Name (Expr) = Name_Address
8313 Expr := Prefix (Expr);
8316 -- Check for Const where Const is a constant entity
8318 elsif Is_Entity_Name (Expr)
8319 and then Ekind (Entity (Expr)) = E_Constant
8321 Expr := Constant_Value (Entity (Expr));
8323 -- Anything else does not need checking
8330 -- This loop checks the form of the prefix for an entity, using
8331 -- recursion to deal with intermediate components.
8334 -- Check for Y where Y is an entity
8336 if Is_Entity_Name (Expr) then
8337 Ent := Entity (Expr);
8340 -- Check for components
8343 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component)
8345 Expr := Prefix (Expr);
8348 -- Anything else does not need checking
8355 end Find_Overlaid_Entity;
8357 -------------------------
8358 -- Find_Parameter_Type --
8359 -------------------------
8361 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
8363 if Nkind (Param) /= N_Parameter_Specification then
8366 -- For an access parameter, obtain the type from the formal entity
8367 -- itself, because access to subprogram nodes do not carry a type.
8368 -- Shouldn't we always use the formal entity ???
8370 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
8371 return Etype (Defining_Identifier (Param));
8374 return Etype (Parameter_Type (Param));
8376 end Find_Parameter_Type;
8378 -----------------------------------
8379 -- Find_Placement_In_State_Space --
8380 -----------------------------------
8382 procedure Find_Placement_In_State_Space
8383 (Item_Id : Entity_Id;
8384 Placement : out State_Space_Kind;
8385 Pack_Id : out Entity_Id)
8387 Context : Entity_Id;
8390 -- Assume that the item does not appear in the state space of a package
8392 Placement := Not_In_Package;
8395 -- Climb the scope stack and examine the enclosing context
8397 Context := Scope (Item_Id);
8398 while Present (Context) and then Context /= Standard_Standard loop
8399 if Is_Package_Or_Generic_Package (Context) then
8402 -- A package body is a cut off point for the traversal as the item
8403 -- cannot be visible to the outside from this point on. Note that
8404 -- this test must be done first as a body is also classified as a
8407 if In_Package_Body (Context) then
8408 Placement := Body_State_Space;
8411 -- The private part of a package is a cut off point for the
8412 -- traversal as the item cannot be visible to the outside from
8415 elsif In_Private_Part (Context) then
8416 Placement := Private_State_Space;
8419 -- When the item appears in the visible state space of a package,
8420 -- continue to climb the scope stack as this may not be the final
8424 Placement := Visible_State_Space;
8426 -- The visible state space of a child unit acts as the proper
8427 -- placement of an item.
8429 if Is_Child_Unit (Context) then
8434 -- The item or its enclosing package appear in a construct that has
8438 Placement := Not_In_Package;
8442 Context := Scope (Context);
8444 end Find_Placement_In_State_Space;
8446 -----------------------
8447 -- Find_Primitive_Eq --
8448 -----------------------
8450 function Find_Primitive_Eq (Typ : Entity_Id) return Entity_Id is
8451 function Find_Eq_Prim (Prims_List : Elist_Id) return Entity_Id;
8452 -- Search for the equality primitive; return Empty if the primitive is
8459 function Find_Eq_Prim (Prims_List : Elist_Id) return Entity_Id is
8461 Prim_Elmt : Elmt_Id;
8464 Prim_Elmt := First_Elmt (Prims_List);
8465 while Present (Prim_Elmt) loop
8466 Prim := Node (Prim_Elmt);
8468 -- Locate primitive equality with the right signature
8470 if Chars (Prim) = Name_Op_Eq
8471 and then Etype (First_Formal (Prim)) =
8472 Etype (Next_Formal (First_Formal (Prim)))
8473 and then Base_Type (Etype (Prim)) = Standard_Boolean
8478 Next_Elmt (Prim_Elmt);
8486 Eq_Prim : Entity_Id;
8487 Full_Type : Entity_Id;
8489 -- Start of processing for Find_Primitive_Eq
8492 if Is_Private_Type (Typ) then
8493 Full_Type := Underlying_Type (Typ);
8498 if No (Full_Type) then
8502 Full_Type := Base_Type (Full_Type);
8504 -- When the base type itself is private, use the full view
8506 if Is_Private_Type (Full_Type) then
8507 Full_Type := Underlying_Type (Full_Type);
8510 if Is_Class_Wide_Type (Full_Type) then
8511 Full_Type := Root_Type (Full_Type);
8514 if not Is_Tagged_Type (Full_Type) then
8515 Eq_Prim := Find_Eq_Prim (Collect_Primitive_Operations (Typ));
8517 -- If this is an untagged private type completed with a derivation of
8518 -- an untagged private type whose full view is a tagged type, we use
8519 -- the primitive operations of the private parent type (since it does
8520 -- not have a full view, and also because its equality primitive may
8521 -- have been overridden in its untagged full view). If no equality was
8522 -- defined for it then take its dispatching equality primitive.
8524 elsif Inherits_From_Tagged_Full_View (Typ) then
8525 Eq_Prim := Find_Eq_Prim (Collect_Primitive_Operations (Typ));
8527 if No (Eq_Prim) then
8528 Eq_Prim := Find_Eq_Prim (Primitive_Operations (Full_Type));
8532 Eq_Prim := Find_Eq_Prim (Primitive_Operations (Full_Type));
8536 end Find_Primitive_Eq;
8538 ------------------------
8539 -- Find_Specific_Type --
8540 ------------------------
8542 function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
8543 Typ : Entity_Id := Root_Type (CW);
8546 if Ekind (Typ) = E_Incomplete_Type then
8547 if From_Limited_With (Typ) then
8548 Typ := Non_Limited_View (Typ);
8550 Typ := Full_View (Typ);
8554 if Is_Private_Type (Typ)
8555 and then not Is_Tagged_Type (Typ)
8556 and then Present (Full_View (Typ))
8558 return Full_View (Typ);
8562 end Find_Specific_Type;
8564 -----------------------------
8565 -- Find_Static_Alternative --
8566 -----------------------------
8568 function Find_Static_Alternative (N : Node_Id) return Node_Id is
8569 Expr : constant Node_Id := Expression (N);
8570 Val : constant Uint := Expr_Value (Expr);
8575 Alt := First (Alternatives (N));
8578 if Nkind (Alt) /= N_Pragma then
8579 Choice := First (Discrete_Choices (Alt));
8580 while Present (Choice) loop
8582 -- Others choice, always matches
8584 if Nkind (Choice) = N_Others_Choice then
8587 -- Range, check if value is in the range
8589 elsif Nkind (Choice) = N_Range then
8591 Val >= Expr_Value (Low_Bound (Choice))
8593 Val <= Expr_Value (High_Bound (Choice));
8595 -- Choice is a subtype name. Note that we know it must
8596 -- be a static subtype, since otherwise it would have
8597 -- been diagnosed as illegal.
8599 elsif Is_Entity_Name (Choice)
8600 and then Is_Type (Entity (Choice))
8602 exit Search when Is_In_Range (Expr, Etype (Choice),
8603 Assume_Valid => False);
8605 -- Choice is a subtype indication
8607 elsif Nkind (Choice) = N_Subtype_Indication then
8609 C : constant Node_Id := Constraint (Choice);
8610 R : constant Node_Id := Range_Expression (C);
8614 Val >= Expr_Value (Low_Bound (R))
8616 Val <= Expr_Value (High_Bound (R));
8619 -- Choice is a simple expression
8622 exit Search when Val = Expr_Value (Choice);
8630 pragma Assert (Present (Alt));
8633 -- The above loop *must* terminate by finding a match, since we know the
8634 -- case statement is valid, and the value of the expression is known at
8635 -- compile time. When we fall out of the loop, Alt points to the
8636 -- alternative that we know will be selected at run time.
8639 end Find_Static_Alternative;
8645 function First_Actual (Node : Node_Id) return Node_Id is
8649 if No (Parameter_Associations (Node)) then
8653 N := First (Parameter_Associations (Node));
8655 if Nkind (N) = N_Parameter_Association then
8656 return First_Named_Actual (Node);
8666 function First_Global
8668 Global_Mode : Name_Id;
8669 Refined : Boolean := False) return Node_Id
8671 function First_From_Global_List
8673 Global_Mode : Name_Id := Name_Input) return Entity_Id;
8674 -- Get the first item with suitable mode from List
8676 ----------------------------
8677 -- First_From_Global_List --
8678 ----------------------------
8680 function First_From_Global_List
8682 Global_Mode : Name_Id := Name_Input) return Entity_Id
8687 -- Empty list (no global items)
8689 if Nkind (List) = N_Null then
8692 -- Single global item declaration (only input items)
8694 elsif Nkind_In (List, N_Expanded_Name, N_Identifier) then
8695 if Global_Mode = Name_Input then
8701 -- Simple global list (only input items) or moded global list
8704 elsif Nkind (List) = N_Aggregate then
8705 if Present (Expressions (List)) then
8706 if Global_Mode = Name_Input then
8707 return First (Expressions (List));
8713 Assoc := First (Component_Associations (List));
8714 while Present (Assoc) loop
8716 -- When we find the desired mode in an association, call
8717 -- recursively First_From_Global_List as if the mode was
8718 -- Name_Input, in order to reuse the existing machinery
8719 -- for the other cases.
8721 if Chars (First (Choices (Assoc))) = Global_Mode then
8722 return First_From_Global_List (Expression (Assoc));
8731 -- To accommodate partial decoration of disabled SPARK features,
8732 -- this routine may be called with illegal input. If this is the
8733 -- case, do not raise Program_Error.
8738 end First_From_Global_List;
8742 Global : Node_Id := Empty;
8743 Body_Id : Entity_Id;
8745 -- Start of processing for First_Global
8748 pragma Assert (Nam_In (Global_Mode, Name_In_Out,
8753 -- Retrieve the suitable pragma Global or Refined_Global. In the second
8754 -- case, it can only be located on the body entity.
8757 if Is_Subprogram_Or_Generic_Subprogram (Subp) then
8758 Body_Id := Subprogram_Body_Entity (Subp);
8760 elsif Is_Entry (Subp) or else Is_Task_Type (Subp) then
8761 Body_Id := Corresponding_Body (Parent (Subp));
8763 -- ??? It should be possible to retrieve the Refined_Global on the
8764 -- task body associated to the task object. This is not yet possible.
8766 elsif Is_Single_Task_Object (Subp) then
8773 if Present (Body_Id) then
8774 Global := Get_Pragma (Body_Id, Pragma_Refined_Global);
8777 Global := Get_Pragma (Subp, Pragma_Global);
8780 -- No corresponding global if pragma is not present
8785 -- Otherwise retrieve the corresponding list of items depending on the
8789 return First_From_Global_List
8790 (Expression (Get_Argument (Global, Subp)), Global_Mode);
8798 function Fix_Msg (Id : Entity_Id; Msg : String) return String is
8799 Is_Task : constant Boolean :=
8800 Ekind_In (Id, E_Task_Body, E_Task_Type)
8801 or else Is_Single_Task_Object (Id);
8802 Msg_Last : constant Natural := Msg'Last;
8803 Msg_Index : Natural;
8804 Res : String (Msg'Range) := (others => ' ');
8805 Res_Index : Natural;
8808 -- Copy all characters from the input message Msg to result Res with
8809 -- suitable replacements.
8811 Msg_Index := Msg'First;
8812 Res_Index := Res'First;
8813 while Msg_Index <= Msg_Last loop
8815 -- Replace "subprogram" with a different word
8817 if Msg_Index <= Msg_Last - 10
8818 and then Msg (Msg_Index .. Msg_Index + 9) = "subprogram"
8820 if Ekind_In (Id, E_Entry, E_Entry_Family) then
8821 Res (Res_Index .. Res_Index + 4) := "entry";
8822 Res_Index := Res_Index + 5;
8825 Res (Res_Index .. Res_Index + 8) := "task type";
8826 Res_Index := Res_Index + 9;
8829 Res (Res_Index .. Res_Index + 9) := "subprogram";
8830 Res_Index := Res_Index + 10;
8833 Msg_Index := Msg_Index + 10;
8835 -- Replace "protected" with a different word
8837 elsif Msg_Index <= Msg_Last - 9
8838 and then Msg (Msg_Index .. Msg_Index + 8) = "protected"
8841 Res (Res_Index .. Res_Index + 3) := "task";
8842 Res_Index := Res_Index + 4;
8843 Msg_Index := Msg_Index + 9;
8845 -- Otherwise copy the character
8848 Res (Res_Index) := Msg (Msg_Index);
8849 Msg_Index := Msg_Index + 1;
8850 Res_Index := Res_Index + 1;
8854 return Res (Res'First .. Res_Index - 1);
8857 -------------------------
8858 -- From_Nested_Package --
8859 -------------------------
8861 function From_Nested_Package (T : Entity_Id) return Boolean is
8862 Pack : constant Entity_Id := Scope (T);
8866 Ekind (Pack) = E_Package
8867 and then not Is_Frozen (Pack)
8868 and then not Scope_Within_Or_Same (Current_Scope, Pack)
8869 and then In_Open_Scopes (Scope (Pack));
8870 end From_Nested_Package;
8872 -----------------------
8873 -- Gather_Components --
8874 -----------------------
8876 procedure Gather_Components
8878 Comp_List : Node_Id;
8879 Governed_By : List_Id;
8881 Report_Errors : out Boolean)
8885 Discrete_Choice : Node_Id;
8886 Comp_Item : Node_Id;
8888 Discrim : Entity_Id;
8889 Discrim_Name : Node_Id;
8890 Discrim_Value : Node_Id;
8893 Report_Errors := False;
8895 if No (Comp_List) or else Null_Present (Comp_List) then
8898 elsif Present (Component_Items (Comp_List)) then
8899 Comp_Item := First (Component_Items (Comp_List));
8905 while Present (Comp_Item) loop
8907 -- Skip the tag of a tagged record, the interface tags, as well
8908 -- as all items that are not user components (anonymous types,
8909 -- rep clauses, Parent field, controller field).
8911 if Nkind (Comp_Item) = N_Component_Declaration then
8913 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
8915 if not Is_Tag (Comp) and then Chars (Comp) /= Name_uParent then
8916 Append_Elmt (Comp, Into);
8924 if No (Variant_Part (Comp_List)) then
8927 Discrim_Name := Name (Variant_Part (Comp_List));
8928 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
8931 -- Look for the discriminant that governs this variant part.
8932 -- The discriminant *must* be in the Governed_By List
8934 Assoc := First (Governed_By);
8935 Find_Constraint : loop
8936 Discrim := First (Choices (Assoc));
8937 exit Find_Constraint when
8938 Chars (Discrim_Name) = Chars (Discrim)
8940 (Present (Corresponding_Discriminant (Entity (Discrim)))
8941 and then Chars (Corresponding_Discriminant
8942 (Entity (Discrim))) = Chars (Discrim_Name))
8944 Chars (Original_Record_Component (Entity (Discrim))) =
8945 Chars (Discrim_Name);
8947 if No (Next (Assoc)) then
8948 if not Is_Constrained (Typ) and then Is_Derived_Type (Typ) then
8950 -- If the type is a tagged type with inherited discriminants,
8951 -- use the stored constraint on the parent in order to find
8952 -- the values of discriminants that are otherwise hidden by an
8953 -- explicit constraint. Renamed discriminants are handled in
8956 -- If several parent discriminants are renamed by a single
8957 -- discriminant of the derived type, the call to obtain the
8958 -- Corresponding_Discriminant field only retrieves the last
8959 -- of them. We recover the constraint on the others from the
8960 -- Stored_Constraint as well.
8962 -- An inherited discriminant may have been constrained in a
8963 -- later ancestor (not the immediate parent) so we must examine
8964 -- the stored constraint of all of them to locate the inherited
8970 T : Entity_Id := Typ;
8973 while Is_Derived_Type (T) loop
8974 if Present (Stored_Constraint (T)) then
8975 D := First_Discriminant (Etype (T));
8976 C := First_Elmt (Stored_Constraint (T));
8977 while Present (D) and then Present (C) loop
8978 if Chars (Discrim_Name) = Chars (D) then
8979 if Is_Entity_Name (Node (C))
8980 and then Entity (Node (C)) = Entity (Discrim)
8982 -- D is renamed by Discrim, whose value is
8989 Make_Component_Association (Sloc (Typ),
8991 (New_Occurrence_Of (D, Sloc (Typ))),
8992 Duplicate_Subexpr_No_Checks (Node (C)));
8995 exit Find_Constraint;
8998 Next_Discriminant (D);
9003 -- Discriminant may be inherited from ancestor
9011 if No (Next (Assoc)) then
9013 (" missing value for discriminant&",
9014 First (Governed_By), Discrim_Name);
9016 Report_Errors := True;
9021 end loop Find_Constraint;
9023 Discrim_Value := Expression (Assoc);
9025 if not Is_OK_Static_Expression (Discrim_Value) then
9027 -- If the variant part is governed by a discriminant of the type
9028 -- this is an error. If the variant part and the discriminant are
9029 -- inherited from an ancestor this is legal (AI05-120) unless the
9030 -- components are being gathered for an aggregate, in which case
9031 -- the caller must check Report_Errors.
9033 if Scope (Original_Record_Component
9034 ((Entity (First (Choices (Assoc)))))) = Typ
9037 ("value for discriminant & must be static!",
9038 Discrim_Value, Discrim);
9039 Why_Not_Static (Discrim_Value);
9042 Report_Errors := True;
9046 Search_For_Discriminant_Value : declare
9052 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
9055 Find_Discrete_Value : while Present (Variant) loop
9057 -- If a choice is a subtype with a static predicate, it must
9058 -- be rewritten as an explicit list of non-predicated choices.
9060 Expand_Static_Predicates_In_Choices (Variant);
9062 Discrete_Choice := First (Discrete_Choices (Variant));
9063 while Present (Discrete_Choice) loop
9064 exit Find_Discrete_Value when
9065 Nkind (Discrete_Choice) = N_Others_Choice;
9067 Get_Index_Bounds (Discrete_Choice, Low, High);
9069 UI_Low := Expr_Value (Low);
9070 UI_High := Expr_Value (High);
9072 exit Find_Discrete_Value when
9073 UI_Low <= UI_Discrim_Value
9075 UI_High >= UI_Discrim_Value;
9077 Next (Discrete_Choice);
9080 Next_Non_Pragma (Variant);
9081 end loop Find_Discrete_Value;
9082 end Search_For_Discriminant_Value;
9084 -- The case statement must include a variant that corresponds to the
9085 -- value of the discriminant, unless the discriminant type has a
9086 -- static predicate. In that case the absence of an others_choice that
9087 -- would cover this value becomes a run-time error (3.8,1 (21.1/2)).
9090 and then not Has_Static_Predicate (Etype (Discrim_Name))
9093 ("value of discriminant & is out of range", Discrim_Value, Discrim);
9094 Report_Errors := True;
9098 -- If we have found the corresponding choice, recursively add its
9099 -- components to the Into list. The nested components are part of
9100 -- the same record type.
9102 if Present (Variant) then
9104 (Typ, Component_List (Variant), Governed_By, Into, Report_Errors);
9106 end Gather_Components;
9108 ------------------------
9109 -- Get_Actual_Subtype --
9110 ------------------------
9112 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
9113 Typ : constant Entity_Id := Etype (N);
9114 Utyp : Entity_Id := Underlying_Type (Typ);
9123 -- If what we have is an identifier that references a subprogram
9124 -- formal, or a variable or constant object, then we get the actual
9125 -- subtype from the referenced entity if one has been built.
9127 if Nkind (N) = N_Identifier
9129 (Is_Formal (Entity (N))
9130 or else Ekind (Entity (N)) = E_Constant
9131 or else Ekind (Entity (N)) = E_Variable)
9132 and then Present (Actual_Subtype (Entity (N)))
9134 return Actual_Subtype (Entity (N));
9136 -- Actual subtype of unchecked union is always itself. We never need
9137 -- the "real" actual subtype. If we did, we couldn't get it anyway
9138 -- because the discriminant is not available. The restrictions on
9139 -- Unchecked_Union are designed to make sure that this is OK.
9141 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
9144 -- Here for the unconstrained case, we must find actual subtype
9145 -- No actual subtype is available, so we must build it on the fly.
9147 -- Checking the type, not the underlying type, for constrainedness
9148 -- seems to be necessary. Maybe all the tests should be on the type???
9150 elsif (not Is_Constrained (Typ))
9151 and then (Is_Array_Type (Utyp)
9152 or else (Is_Record_Type (Utyp)
9153 and then Has_Discriminants (Utyp)))
9154 and then not Has_Unknown_Discriminants (Utyp)
9155 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
9157 -- Nothing to do if in spec expression (why not???)
9159 if In_Spec_Expression then
9162 elsif Is_Private_Type (Typ) and then not Has_Discriminants (Typ) then
9164 -- If the type has no discriminants, there is no subtype to
9165 -- build, even if the underlying type is discriminated.
9169 -- Else build the actual subtype
9172 Decl := Build_Actual_Subtype (Typ, N);
9174 -- The call may yield a declaration, or just return the entity
9180 Atyp := Defining_Identifier (Decl);
9182 -- If Build_Actual_Subtype generated a new declaration then use it
9186 -- The actual subtype is an Itype, so analyze the declaration,
9187 -- but do not attach it to the tree, to get the type defined.
9189 Set_Parent (Decl, N);
9190 Set_Is_Itype (Atyp);
9191 Analyze (Decl, Suppress => All_Checks);
9192 Set_Associated_Node_For_Itype (Atyp, N);
9193 Set_Has_Delayed_Freeze (Atyp, False);
9195 -- We need to freeze the actual subtype immediately. This is
9196 -- needed, because otherwise this Itype will not get frozen
9197 -- at all, and it is always safe to freeze on creation because
9198 -- any associated types must be frozen at this point.
9200 Freeze_Itype (Atyp, N);
9203 -- Otherwise we did not build a declaration, so return original
9210 -- For all remaining cases, the actual subtype is the same as
9211 -- the nominal type.
9216 end Get_Actual_Subtype;
9218 -------------------------------------
9219 -- Get_Actual_Subtype_If_Available --
9220 -------------------------------------
9222 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
9223 Typ : constant Entity_Id := Etype (N);
9226 -- If what we have is an identifier that references a subprogram
9227 -- formal, or a variable or constant object, then we get the actual
9228 -- subtype from the referenced entity if one has been built.
9230 if Nkind (N) = N_Identifier
9232 (Is_Formal (Entity (N))
9233 or else Ekind (Entity (N)) = E_Constant
9234 or else Ekind (Entity (N)) = E_Variable)
9235 and then Present (Actual_Subtype (Entity (N)))
9237 return Actual_Subtype (Entity (N));
9239 -- Otherwise the Etype of N is returned unchanged
9244 end Get_Actual_Subtype_If_Available;
9246 ------------------------
9247 -- Get_Body_From_Stub --
9248 ------------------------
9250 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
9252 return Proper_Body (Unit (Library_Unit (N)));
9253 end Get_Body_From_Stub;
9255 ---------------------
9256 -- Get_Cursor_Type --
9257 ---------------------
9259 function Get_Cursor_Type
9261 Typ : Entity_Id) return Entity_Id
9265 First_Op : Entity_Id;
9269 -- If error already detected, return
9271 if Error_Posted (Aspect) then
9275 -- The cursor type for an Iterable aspect is the return type of a
9276 -- non-overloaded First primitive operation. Locate association for
9279 Assoc := First (Component_Associations (Expression (Aspect)));
9281 while Present (Assoc) loop
9282 if Chars (First (Choices (Assoc))) = Name_First then
9283 First_Op := Expression (Assoc);
9290 if First_Op = Any_Id then
9291 Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
9294 elsif not Analyzed (First_Op) then
9300 -- Locate function with desired name and profile in scope of type
9301 -- In the rare case where the type is an integer type, a base type
9302 -- is created for it, check that the base type of the first formal
9303 -- of First matches the base type of the domain.
9305 Func := First_Entity (Scope (Typ));
9306 while Present (Func) loop
9307 if Chars (Func) = Chars (First_Op)
9308 and then Ekind (Func) = E_Function
9309 and then Present (First_Formal (Func))
9310 and then Base_Type (Etype (First_Formal (Func))) = Base_Type (Typ)
9311 and then No (Next_Formal (First_Formal (Func)))
9313 if Cursor /= Any_Type then
9315 ("Operation First for iterable type must be unique", Aspect);
9318 Cursor := Etype (Func);
9325 -- If not found, no way to resolve remaining primitives
9327 if Cursor = Any_Type then
9329 ("primitive operation for Iterable type must appear in the same "
9330 & "list of declarations as the type", Aspect);
9334 end Get_Cursor_Type;
9336 function Get_Cursor_Type (Typ : Entity_Id) return Entity_Id is
9338 return Etype (Get_Iterable_Type_Primitive (Typ, Name_First));
9339 end Get_Cursor_Type;
9341 -------------------------------
9342 -- Get_Default_External_Name --
9343 -------------------------------
9345 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
9347 Get_Decoded_Name_String (Chars (E));
9349 if Opt.External_Name_Imp_Casing = Uppercase then
9350 Set_Casing (All_Upper_Case);
9352 Set_Casing (All_Lower_Case);
9356 Make_String_Literal (Sloc (E),
9357 Strval => String_From_Name_Buffer);
9358 end Get_Default_External_Name;
9360 --------------------------
9361 -- Get_Enclosing_Object --
9362 --------------------------
9364 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
9366 if Is_Entity_Name (N) then
9370 when N_Indexed_Component
9371 | N_Selected_Component
9374 -- If not generating code, a dereference may be left implicit.
9375 -- In thoses cases, return Empty.
9377 if Is_Access_Type (Etype (Prefix (N))) then
9380 return Get_Enclosing_Object (Prefix (N));
9383 when N_Type_Conversion =>
9384 return Get_Enclosing_Object (Expression (N));
9390 end Get_Enclosing_Object;
9392 ---------------------------
9393 -- Get_Enum_Lit_From_Pos --
9394 ---------------------------
9396 function Get_Enum_Lit_From_Pos
9399 Loc : Source_Ptr) return Node_Id
9401 Btyp : Entity_Id := Base_Type (T);
9406 -- In the case where the literal is of type Character, Wide_Character
9407 -- or Wide_Wide_Character or of a type derived from them, there needs
9408 -- to be some special handling since there is no explicit chain of
9409 -- literals to search. Instead, an N_Character_Literal node is created
9410 -- with the appropriate Char_Code and Chars fields.
9412 if Is_Standard_Character_Type (T) then
9413 Set_Character_Literal_Name (UI_To_CC (Pos));
9416 Make_Character_Literal (Loc,
9418 Char_Literal_Value => Pos);
9420 -- For all other cases, we have a complete table of literals, and
9421 -- we simply iterate through the chain of literal until the one
9422 -- with the desired position value is found.
9425 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
9426 Btyp := Full_View (Btyp);
9429 Lit := First_Literal (Btyp);
9431 -- Position in the enumeration type starts at 0
9433 if UI_To_Int (Pos) < 0 then
9434 raise Constraint_Error;
9437 for J in 1 .. UI_To_Int (Pos) loop
9440 -- If Lit is Empty, Pos is not in range, so raise Constraint_Error
9441 -- inside the loop to avoid calling Next_Literal on Empty.
9444 raise Constraint_Error;
9448 -- Create a new node from Lit, with source location provided by Loc
9449 -- if not equal to No_Location, or by copying the source location of
9454 if LLoc = No_Location then
9458 return New_Occurrence_Of (Lit, LLoc);
9460 end Get_Enum_Lit_From_Pos;
9462 ------------------------
9463 -- Get_Generic_Entity --
9464 ------------------------
9466 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
9467 Ent : constant Entity_Id := Entity (Name (N));
9469 if Present (Renamed_Object (Ent)) then
9470 return Renamed_Object (Ent);
9474 end Get_Generic_Entity;
9476 -------------------------------------
9477 -- Get_Incomplete_View_Of_Ancestor --
9478 -------------------------------------
9480 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
9481 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
9482 Par_Scope : Entity_Id;
9483 Par_Type : Entity_Id;
9486 -- The incomplete view of an ancestor is only relevant for private
9487 -- derived types in child units.
9489 if not Is_Derived_Type (E)
9490 or else not Is_Child_Unit (Cur_Unit)
9495 Par_Scope := Scope (Cur_Unit);
9496 if No (Par_Scope) then
9500 Par_Type := Etype (Base_Type (E));
9502 -- Traverse list of ancestor types until we find one declared in
9503 -- a parent or grandparent unit (two levels seem sufficient).
9505 while Present (Par_Type) loop
9506 if Scope (Par_Type) = Par_Scope
9507 or else Scope (Par_Type) = Scope (Par_Scope)
9511 elsif not Is_Derived_Type (Par_Type) then
9515 Par_Type := Etype (Base_Type (Par_Type));
9519 -- If none found, there is no relevant ancestor type.
9523 end Get_Incomplete_View_Of_Ancestor;
9525 ----------------------
9526 -- Get_Index_Bounds --
9527 ----------------------
9529 procedure Get_Index_Bounds
9533 Use_Full_View : Boolean := False)
9535 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id;
9536 -- Obtain the scalar range of type Typ. If flag Use_Full_View is set and
9537 -- Typ qualifies, the scalar range is obtained from the full view of the
9540 --------------------------
9541 -- Scalar_Range_Of_Type --
9542 --------------------------
9544 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id is
9545 T : Entity_Id := Typ;
9548 if Use_Full_View and then Present (Full_View (T)) then
9552 return Scalar_Range (T);
9553 end Scalar_Range_Of_Type;
9557 Kind : constant Node_Kind := Nkind (N);
9560 -- Start of processing for Get_Index_Bounds
9563 if Kind = N_Range then
9565 H := High_Bound (N);
9567 elsif Kind = N_Subtype_Indication then
9568 Rng := Range_Expression (Constraint (N));
9576 L := Low_Bound (Range_Expression (Constraint (N)));
9577 H := High_Bound (Range_Expression (Constraint (N)));
9580 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
9581 Rng := Scalar_Range_Of_Type (Entity (N));
9583 if Error_Posted (Rng) then
9587 elsif Nkind (Rng) = N_Subtype_Indication then
9588 Get_Index_Bounds (Rng, L, H);
9591 L := Low_Bound (Rng);
9592 H := High_Bound (Rng);
9596 -- N is an expression, indicating a range with one value
9601 end Get_Index_Bounds;
9603 -----------------------------
9604 -- Get_Interfacing_Aspects --
9605 -----------------------------
9607 procedure Get_Interfacing_Aspects
9608 (Iface_Asp : Node_Id;
9609 Conv_Asp : out Node_Id;
9610 EN_Asp : out Node_Id;
9611 Expo_Asp : out Node_Id;
9612 Imp_Asp : out Node_Id;
9613 LN_Asp : out Node_Id;
9614 Do_Checks : Boolean := False)
9616 procedure Save_Or_Duplication_Error
9618 To : in out Node_Id);
9619 -- Save the value of aspect Asp in node To. If To already has a value,
9620 -- then this is considered a duplicate use of aspect. Emit an error if
9621 -- flag Do_Checks is set.
9623 -------------------------------
9624 -- Save_Or_Duplication_Error --
9625 -------------------------------
9627 procedure Save_Or_Duplication_Error
9629 To : in out Node_Id)
9632 -- Detect an extra aspect and issue an error
9634 if Present (To) then
9636 Error_Msg_Name_1 := Chars (Identifier (Asp));
9637 Error_Msg_Sloc := Sloc (To);
9638 Error_Msg_N ("aspect % previously given #", Asp);
9641 -- Otherwise capture the aspect
9646 end Save_Or_Duplication_Error;
9653 -- The following variables capture each individual aspect
9655 Conv : Node_Id := Empty;
9656 EN : Node_Id := Empty;
9657 Expo : Node_Id := Empty;
9658 Imp : Node_Id := Empty;
9659 LN : Node_Id := Empty;
9661 -- Start of processing for Get_Interfacing_Aspects
9664 -- The input interfacing aspect should reside in an aspect specification
9667 pragma Assert (Is_List_Member (Iface_Asp));
9669 -- Examine the aspect specifications of the related entity. Find and
9670 -- capture all interfacing aspects. Detect duplicates and emit errors
9673 Asp := First (List_Containing (Iface_Asp));
9674 while Present (Asp) loop
9675 Asp_Id := Get_Aspect_Id (Asp);
9677 if Asp_Id = Aspect_Convention then
9678 Save_Or_Duplication_Error (Asp, Conv);
9680 elsif Asp_Id = Aspect_External_Name then
9681 Save_Or_Duplication_Error (Asp, EN);
9683 elsif Asp_Id = Aspect_Export then
9684 Save_Or_Duplication_Error (Asp, Expo);
9686 elsif Asp_Id = Aspect_Import then
9687 Save_Or_Duplication_Error (Asp, Imp);
9689 elsif Asp_Id = Aspect_Link_Name then
9690 Save_Or_Duplication_Error (Asp, LN);
9701 end Get_Interfacing_Aspects;
9703 ---------------------------------
9704 -- Get_Iterable_Type_Primitive --
9705 ---------------------------------
9707 function Get_Iterable_Type_Primitive
9709 Nam : Name_Id) return Entity_Id
9711 Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
9719 Assoc := First (Component_Associations (Funcs));
9720 while Present (Assoc) loop
9721 if Chars (First (Choices (Assoc))) = Nam then
9722 return Entity (Expression (Assoc));
9725 Assoc := Next (Assoc);
9730 end Get_Iterable_Type_Primitive;
9732 ----------------------------------
9733 -- Get_Library_Unit_Name_String --
9734 ----------------------------------
9736 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
9737 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
9740 Get_Unit_Name_String (Unit_Name_Id);
9742 -- Remove seven last character (" (spec)" or " (body)")
9744 Name_Len := Name_Len - 7;
9745 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
9746 end Get_Library_Unit_Name_String;
9748 --------------------------
9749 -- Get_Max_Queue_Length --
9750 --------------------------
9752 function Get_Max_Queue_Length (Id : Entity_Id) return Uint is
9753 pragma Assert (Is_Entry (Id));
9754 Prag : constant Entity_Id := Get_Pragma (Id, Pragma_Max_Queue_Length);
9758 -- A value of 0 or -1 represents no maximum specified, and entries and
9759 -- entry families with no Max_Queue_Length aspect or pragma default to
9762 if not Present (Prag) then
9767 (Expression (First (Pragma_Argument_Associations (Prag))));
9769 -- Since -1 and 0 are equivalent, return 0 for instances of -1 for
9777 end Get_Max_Queue_Length;
9779 ------------------------
9780 -- Get_Name_Entity_Id --
9781 ------------------------
9783 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
9785 return Entity_Id (Get_Name_Table_Int (Id));
9786 end Get_Name_Entity_Id;
9788 ------------------------------
9789 -- Get_Name_From_CTC_Pragma --
9790 ------------------------------
9792 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
9793 Arg : constant Node_Id :=
9794 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
9796 return Strval (Expr_Value_S (Arg));
9797 end Get_Name_From_CTC_Pragma;
9799 -----------------------
9800 -- Get_Parent_Entity --
9801 -----------------------
9803 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
9805 if Nkind (Unit) = N_Package_Body
9806 and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
9808 return Defining_Entity
9809 (Specification (Instance_Spec (Original_Node (Unit))));
9810 elsif Nkind (Unit) = N_Package_Instantiation then
9811 return Defining_Entity (Specification (Instance_Spec (Unit)));
9813 return Defining_Entity (Unit);
9815 end Get_Parent_Entity;
9821 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
9823 return Get_Pragma_Id (Pragma_Name_Unmapped (N));
9826 ------------------------
9827 -- Get_Qualified_Name --
9828 ------------------------
9830 function Get_Qualified_Name
9832 Suffix : Entity_Id := Empty) return Name_Id
9834 Suffix_Nam : Name_Id := No_Name;
9837 if Present (Suffix) then
9838 Suffix_Nam := Chars (Suffix);
9841 return Get_Qualified_Name (Chars (Id), Suffix_Nam, Scope (Id));
9842 end Get_Qualified_Name;
9844 function Get_Qualified_Name
9846 Suffix : Name_Id := No_Name;
9847 Scop : Entity_Id := Current_Scope) return Name_Id
9849 procedure Add_Scope (S : Entity_Id);
9850 -- Add the fully qualified form of scope S to the name buffer. The
9858 procedure Add_Scope (S : Entity_Id) is
9863 elsif S = Standard_Standard then
9867 Add_Scope (Scope (S));
9868 Get_Name_String_And_Append (Chars (S));
9869 Add_Str_To_Name_Buffer ("__");
9873 -- Start of processing for Get_Qualified_Name
9879 -- Append the base name after all scopes have been chained
9881 Get_Name_String_And_Append (Nam);
9883 -- Append the suffix (if present)
9885 if Suffix /= No_Name then
9886 Add_Str_To_Name_Buffer ("__");
9887 Get_Name_String_And_Append (Suffix);
9891 end Get_Qualified_Name;
9893 -----------------------
9894 -- Get_Reason_String --
9895 -----------------------
9897 procedure Get_Reason_String (N : Node_Id) is
9899 if Nkind (N) = N_String_Literal then
9900 Store_String_Chars (Strval (N));
9902 elsif Nkind (N) = N_Op_Concat then
9903 Get_Reason_String (Left_Opnd (N));
9904 Get_Reason_String (Right_Opnd (N));
9906 -- If not of required form, error
9910 ("Reason for pragma Warnings has wrong form", N);
9912 ("\must be string literal or concatenation of string literals", N);
9915 end Get_Reason_String;
9917 --------------------------------
9918 -- Get_Reference_Discriminant --
9919 --------------------------------
9921 function Get_Reference_Discriminant (Typ : Entity_Id) return Entity_Id is
9925 D := First_Discriminant (Typ);
9926 while Present (D) loop
9927 if Has_Implicit_Dereference (D) then
9930 Next_Discriminant (D);
9934 end Get_Reference_Discriminant;
9936 ---------------------------
9937 -- Get_Referenced_Object --
9938 ---------------------------
9940 function Get_Referenced_Object (N : Node_Id) return Node_Id is
9945 while Is_Entity_Name (R)
9946 and then Present (Renamed_Object (Entity (R)))
9948 R := Renamed_Object (Entity (R));
9952 end Get_Referenced_Object;
9954 ------------------------
9955 -- Get_Renamed_Entity --
9956 ------------------------
9958 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
9963 while Present (Renamed_Entity (R)) loop
9964 R := Renamed_Entity (R);
9968 end Get_Renamed_Entity;
9970 -----------------------
9971 -- Get_Return_Object --
9972 -----------------------
9974 function Get_Return_Object (N : Node_Id) return Entity_Id is
9978 Decl := First (Return_Object_Declarations (N));
9979 while Present (Decl) loop
9980 exit when Nkind (Decl) = N_Object_Declaration
9981 and then Is_Return_Object (Defining_Identifier (Decl));
9985 pragma Assert (Present (Decl));
9986 return Defining_Identifier (Decl);
9987 end Get_Return_Object;
9989 ---------------------------
9990 -- Get_Subprogram_Entity --
9991 ---------------------------
9993 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
9995 Subp_Id : Entity_Id;
9998 if Nkind (Nod) = N_Accept_Statement then
9999 Subp := Entry_Direct_Name (Nod);
10001 elsif Nkind (Nod) = N_Slice then
10002 Subp := Prefix (Nod);
10005 Subp := Name (Nod);
10008 -- Strip the subprogram call
10011 if Nkind_In (Subp, N_Explicit_Dereference,
10012 N_Indexed_Component,
10013 N_Selected_Component)
10015 Subp := Prefix (Subp);
10017 elsif Nkind_In (Subp, N_Type_Conversion,
10018 N_Unchecked_Type_Conversion)
10020 Subp := Expression (Subp);
10027 -- Extract the entity of the subprogram call
10029 if Is_Entity_Name (Subp) then
10030 Subp_Id := Entity (Subp);
10032 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
10033 Subp_Id := Directly_Designated_Type (Subp_Id);
10036 if Is_Subprogram (Subp_Id) then
10042 -- The search did not find a construct that denotes a subprogram
10047 end Get_Subprogram_Entity;
10049 -----------------------------
10050 -- Get_Task_Body_Procedure --
10051 -----------------------------
10053 function Get_Task_Body_Procedure (E : Entity_Id) return Entity_Id is
10055 -- Note: A task type may be the completion of a private type with
10056 -- discriminants. When performing elaboration checks on a task
10057 -- declaration, the current view of the type may be the private one,
10058 -- and the procedure that holds the body of the task is held in its
10059 -- underlying type.
10061 -- This is an odd function, why not have Task_Body_Procedure do
10062 -- the following digging???
10064 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
10065 end Get_Task_Body_Procedure;
10067 -------------------------
10068 -- Get_User_Defined_Eq --
10069 -------------------------
10071 function Get_User_Defined_Eq (E : Entity_Id) return Entity_Id is
10076 Prim := First_Elmt (Collect_Primitive_Operations (E));
10077 while Present (Prim) loop
10080 if Chars (Op) = Name_Op_Eq
10081 and then Etype (Op) = Standard_Boolean
10082 and then Etype (First_Formal (Op)) = E
10083 and then Etype (Next_Formal (First_Formal (Op))) = E
10092 end Get_User_Defined_Eq;
10098 procedure Get_Views
10100 Priv_Typ : out Entity_Id;
10101 Full_Typ : out Entity_Id;
10102 Full_Base : out Entity_Id;
10103 CRec_Typ : out Entity_Id)
10105 IP_View : Entity_Id;
10108 -- Assume that none of the views can be recovered
10112 Full_Base := Empty;
10115 -- The input type is the corresponding record type of a protected or a
10118 if Ekind (Typ) = E_Record_Type
10119 and then Is_Concurrent_Record_Type (Typ)
10122 Full_Typ := Corresponding_Concurrent_Type (CRec_Typ);
10123 Full_Base := Base_Type (Full_Typ);
10124 Priv_Typ := Incomplete_Or_Partial_View (Full_Typ);
10126 -- Otherwise the input type denotes an arbitrary type
10129 IP_View := Incomplete_Or_Partial_View (Typ);
10131 -- The input type denotes the full view of a private type
10133 if Present (IP_View) then
10134 Priv_Typ := IP_View;
10137 -- The input type is a private type
10139 elsif Is_Private_Type (Typ) then
10141 Full_Typ := Full_View (Priv_Typ);
10143 -- Otherwise the input type does not have any views
10149 if Present (Full_Typ) then
10150 Full_Base := Base_Type (Full_Typ);
10152 if Ekind_In (Full_Typ, E_Protected_Type, E_Task_Type) then
10153 CRec_Typ := Corresponding_Record_Type (Full_Typ);
10159 -----------------------
10160 -- Has_Access_Values --
10161 -----------------------
10163 function Has_Access_Values (T : Entity_Id) return Boolean is
10164 Typ : constant Entity_Id := Underlying_Type (T);
10167 -- Case of a private type which is not completed yet. This can only
10168 -- happen in the case of a generic format type appearing directly, or
10169 -- as a component of the type to which this function is being applied
10170 -- at the top level. Return False in this case, since we certainly do
10171 -- not know that the type contains access types.
10176 elsif Is_Access_Type (Typ) then
10179 elsif Is_Array_Type (Typ) then
10180 return Has_Access_Values (Component_Type (Typ));
10182 elsif Is_Record_Type (Typ) then
10187 -- Loop to Check components
10189 Comp := First_Component_Or_Discriminant (Typ);
10190 while Present (Comp) loop
10192 -- Check for access component, tag field does not count, even
10193 -- though it is implemented internally using an access type.
10195 if Has_Access_Values (Etype (Comp))
10196 and then Chars (Comp) /= Name_uTag
10201 Next_Component_Or_Discriminant (Comp);
10210 end Has_Access_Values;
10212 ------------------------------
10213 -- Has_Compatible_Alignment --
10214 ------------------------------
10216 function Has_Compatible_Alignment
10219 Layout_Done : Boolean) return Alignment_Result
10221 function Has_Compatible_Alignment_Internal
10224 Layout_Done : Boolean;
10225 Default : Alignment_Result) return Alignment_Result;
10226 -- This is the internal recursive function that actually does the work.
10227 -- There is one additional parameter, which says what the result should
10228 -- be if no alignment information is found, and there is no definite
10229 -- indication of compatible alignments. At the outer level, this is set
10230 -- to Unknown, but for internal recursive calls in the case where types
10231 -- are known to be correct, it is set to Known_Compatible.
10233 ---------------------------------------
10234 -- Has_Compatible_Alignment_Internal --
10235 ---------------------------------------
10237 function Has_Compatible_Alignment_Internal
10240 Layout_Done : Boolean;
10241 Default : Alignment_Result) return Alignment_Result
10243 Result : Alignment_Result := Known_Compatible;
10244 -- Holds the current status of the result. Note that once a value of
10245 -- Known_Incompatible is set, it is sticky and does not get changed
10246 -- to Unknown (the value in Result only gets worse as we go along,
10249 Offs : Uint := No_Uint;
10250 -- Set to a factor of the offset from the base object when Expr is a
10251 -- selected or indexed component, based on Component_Bit_Offset and
10252 -- Component_Size respectively. A negative value is used to represent
10253 -- a value which is not known at compile time.
10255 procedure Check_Prefix;
10256 -- Checks the prefix recursively in the case where the expression
10257 -- is an indexed or selected component.
10259 procedure Set_Result (R : Alignment_Result);
10260 -- If R represents a worse outcome (unknown instead of known
10261 -- compatible, or known incompatible), then set Result to R.
10267 procedure Check_Prefix is
10269 -- The subtlety here is that in doing a recursive call to check
10270 -- the prefix, we have to decide what to do in the case where we
10271 -- don't find any specific indication of an alignment problem.
10273 -- At the outer level, we normally set Unknown as the result in
10274 -- this case, since we can only set Known_Compatible if we really
10275 -- know that the alignment value is OK, but for the recursive
10276 -- call, in the case where the types match, and we have not
10277 -- specified a peculiar alignment for the object, we are only
10278 -- concerned about suspicious rep clauses, the default case does
10279 -- not affect us, since the compiler will, in the absence of such
10280 -- rep clauses, ensure that the alignment is correct.
10282 if Default = Known_Compatible
10284 (Etype (Obj) = Etype (Expr)
10285 and then (Unknown_Alignment (Obj)
10287 Alignment (Obj) = Alignment (Etype (Obj))))
10290 (Has_Compatible_Alignment_Internal
10291 (Obj, Prefix (Expr), Layout_Done, Known_Compatible));
10293 -- In all other cases, we need a full check on the prefix
10297 (Has_Compatible_Alignment_Internal
10298 (Obj, Prefix (Expr), Layout_Done, Unknown));
10306 procedure Set_Result (R : Alignment_Result) is
10313 -- Start of processing for Has_Compatible_Alignment_Internal
10316 -- If Expr is a selected component, we must make sure there is no
10317 -- potentially troublesome component clause and that the record is
10318 -- not packed if the layout is not done.
10320 if Nkind (Expr) = N_Selected_Component then
10322 -- Packing generates unknown alignment if layout is not done
10324 if Is_Packed (Etype (Prefix (Expr))) and then not Layout_Done then
10325 Set_Result (Unknown);
10328 -- Check prefix and component offset
10331 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
10333 -- If Expr is an indexed component, we must make sure there is no
10334 -- potentially troublesome Component_Size clause and that the array
10335 -- is not bit-packed if the layout is not done.
10337 elsif Nkind (Expr) = N_Indexed_Component then
10339 Typ : constant Entity_Id := Etype (Prefix (Expr));
10342 -- Packing generates unknown alignment if layout is not done
10344 if Is_Bit_Packed_Array (Typ) and then not Layout_Done then
10345 Set_Result (Unknown);
10348 -- Check prefix and component offset (or at least size)
10351 Offs := Indexed_Component_Bit_Offset (Expr);
10352 if Offs = No_Uint then
10353 Offs := Component_Size (Typ);
10358 -- If we have a null offset, the result is entirely determined by
10359 -- the base object and has already been computed recursively.
10361 if Offs = Uint_0 then
10364 -- Case where we know the alignment of the object
10366 elsif Known_Alignment (Obj) then
10368 ObjA : constant Uint := Alignment (Obj);
10369 ExpA : Uint := No_Uint;
10370 SizA : Uint := No_Uint;
10373 -- If alignment of Obj is 1, then we are always OK
10376 Set_Result (Known_Compatible);
10378 -- Alignment of Obj is greater than 1, so we need to check
10381 -- If we have an offset, see if it is compatible
10383 if Offs /= No_Uint and Offs > Uint_0 then
10384 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
10385 Set_Result (Known_Incompatible);
10388 -- See if Expr is an object with known alignment
10390 elsif Is_Entity_Name (Expr)
10391 and then Known_Alignment (Entity (Expr))
10393 ExpA := Alignment (Entity (Expr));
10395 -- Otherwise, we can use the alignment of the type of
10396 -- Expr given that we already checked for
10397 -- discombobulating rep clauses for the cases of indexed
10398 -- and selected components above.
10400 elsif Known_Alignment (Etype (Expr)) then
10401 ExpA := Alignment (Etype (Expr));
10403 -- Otherwise the alignment is unknown
10406 Set_Result (Default);
10409 -- If we got an alignment, see if it is acceptable
10411 if ExpA /= No_Uint and then ExpA < ObjA then
10412 Set_Result (Known_Incompatible);
10415 -- If Expr is not a piece of a larger object, see if size
10416 -- is given. If so, check that it is not too small for the
10417 -- required alignment.
10419 if Offs /= No_Uint then
10422 -- See if Expr is an object with known size
10424 elsif Is_Entity_Name (Expr)
10425 and then Known_Static_Esize (Entity (Expr))
10427 SizA := Esize (Entity (Expr));
10429 -- Otherwise, we check the object size of the Expr type
10431 elsif Known_Static_Esize (Etype (Expr)) then
10432 SizA := Esize (Etype (Expr));
10435 -- If we got a size, see if it is a multiple of the Obj
10436 -- alignment, if not, then the alignment cannot be
10437 -- acceptable, since the size is always a multiple of the
10440 if SizA /= No_Uint then
10441 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
10442 Set_Result (Known_Incompatible);
10448 -- If we do not know required alignment, any non-zero offset is a
10449 -- potential problem (but certainly may be OK, so result is unknown).
10451 elsif Offs /= No_Uint then
10452 Set_Result (Unknown);
10454 -- If we can't find the result by direct comparison of alignment
10455 -- values, then there is still one case that we can determine known
10456 -- result, and that is when we can determine that the types are the
10457 -- same, and no alignments are specified. Then we known that the
10458 -- alignments are compatible, even if we don't know the alignment
10459 -- value in the front end.
10461 elsif Etype (Obj) = Etype (Expr) then
10463 -- Types are the same, but we have to check for possible size
10464 -- and alignments on the Expr object that may make the alignment
10465 -- different, even though the types are the same.
10467 if Is_Entity_Name (Expr) then
10469 -- First check alignment of the Expr object. Any alignment less
10470 -- than Maximum_Alignment is worrisome since this is the case
10471 -- where we do not know the alignment of Obj.
10473 if Known_Alignment (Entity (Expr))
10474 and then UI_To_Int (Alignment (Entity (Expr))) <
10475 Ttypes.Maximum_Alignment
10477 Set_Result (Unknown);
10479 -- Now check size of Expr object. Any size that is not an
10480 -- even multiple of Maximum_Alignment is also worrisome
10481 -- since it may cause the alignment of the object to be less
10482 -- than the alignment of the type.
10484 elsif Known_Static_Esize (Entity (Expr))
10486 (UI_To_Int (Esize (Entity (Expr))) mod
10487 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
10490 Set_Result (Unknown);
10492 -- Otherwise same type is decisive
10495 Set_Result (Known_Compatible);
10499 -- Another case to deal with is when there is an explicit size or
10500 -- alignment clause when the types are not the same. If so, then the
10501 -- result is Unknown. We don't need to do this test if the Default is
10502 -- Unknown, since that result will be set in any case.
10504 elsif Default /= Unknown
10505 and then (Has_Size_Clause (Etype (Expr))
10507 Has_Alignment_Clause (Etype (Expr)))
10509 Set_Result (Unknown);
10511 -- If no indication found, set default
10514 Set_Result (Default);
10517 -- Return worst result found
10520 end Has_Compatible_Alignment_Internal;
10522 -- Start of processing for Has_Compatible_Alignment
10525 -- If Obj has no specified alignment, then set alignment from the type
10526 -- alignment. Perhaps we should always do this, but for sure we should
10527 -- do it when there is an address clause since we can do more if the
10528 -- alignment is known.
10530 if Unknown_Alignment (Obj) then
10531 Set_Alignment (Obj, Alignment (Etype (Obj)));
10534 -- Now do the internal call that does all the work
10537 Has_Compatible_Alignment_Internal (Obj, Expr, Layout_Done, Unknown);
10538 end Has_Compatible_Alignment;
10540 ----------------------
10541 -- Has_Declarations --
10542 ----------------------
10544 function Has_Declarations (N : Node_Id) return Boolean is
10546 return Nkind_In (Nkind (N), N_Accept_Statement,
10548 N_Compilation_Unit_Aux,
10554 N_Package_Specification);
10555 end Has_Declarations;
10557 ---------------------------------
10558 -- Has_Defaulted_Discriminants --
10559 ---------------------------------
10561 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
10563 return Has_Discriminants (Typ)
10564 and then Present (First_Discriminant (Typ))
10565 and then Present (Discriminant_Default_Value
10566 (First_Discriminant (Typ)));
10567 end Has_Defaulted_Discriminants;
10569 -------------------
10570 -- Has_Denormals --
10571 -------------------
10573 function Has_Denormals (E : Entity_Id) return Boolean is
10575 return Is_Floating_Point_Type (E) and then Denorm_On_Target;
10578 -------------------------------------------
10579 -- Has_Discriminant_Dependent_Constraint --
10580 -------------------------------------------
10582 function Has_Discriminant_Dependent_Constraint
10583 (Comp : Entity_Id) return Boolean
10585 Comp_Decl : constant Node_Id := Parent (Comp);
10586 Subt_Indic : Node_Id;
10591 -- Discriminants can't depend on discriminants
10593 if Ekind (Comp) = E_Discriminant then
10597 Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl));
10599 if Nkind (Subt_Indic) = N_Subtype_Indication then
10600 Constr := Constraint (Subt_Indic);
10602 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
10603 Assn := First (Constraints (Constr));
10604 while Present (Assn) loop
10605 case Nkind (Assn) is
10608 | N_Subtype_Indication
10610 if Depends_On_Discriminant (Assn) then
10614 when N_Discriminant_Association =>
10615 if Depends_On_Discriminant (Expression (Assn)) then
10630 end Has_Discriminant_Dependent_Constraint;
10632 --------------------------------------
10633 -- Has_Effectively_Volatile_Profile --
10634 --------------------------------------
10636 function Has_Effectively_Volatile_Profile
10637 (Subp_Id : Entity_Id) return Boolean
10639 Formal : Entity_Id;
10642 -- Inspect the formal parameters looking for an effectively volatile
10645 Formal := First_Formal (Subp_Id);
10646 while Present (Formal) loop
10647 if Is_Effectively_Volatile (Etype (Formal)) then
10651 Next_Formal (Formal);
10654 -- Inspect the return type of functions
10656 if Ekind_In (Subp_Id, E_Function, E_Generic_Function)
10657 and then Is_Effectively_Volatile (Etype (Subp_Id))
10663 end Has_Effectively_Volatile_Profile;
10665 --------------------------
10666 -- Has_Enabled_Property --
10667 --------------------------
10669 function Has_Enabled_Property
10670 (Item_Id : Entity_Id;
10671 Property : Name_Id) return Boolean
10673 function Protected_Object_Has_Enabled_Property return Boolean;
10674 -- Determine whether a protected object denoted by Item_Id has the
10675 -- property enabled.
10677 function State_Has_Enabled_Property return Boolean;
10678 -- Determine whether a state denoted by Item_Id has the property enabled
10680 function Variable_Has_Enabled_Property return Boolean;
10681 -- Determine whether a variable denoted by Item_Id has the property
10684 -------------------------------------------
10685 -- Protected_Object_Has_Enabled_Property --
10686 -------------------------------------------
10688 function Protected_Object_Has_Enabled_Property return Boolean is
10689 Constits : constant Elist_Id := Part_Of_Constituents (Item_Id);
10690 Constit_Elmt : Elmt_Id;
10691 Constit_Id : Entity_Id;
10694 -- Protected objects always have the properties Async_Readers and
10695 -- Async_Writers (SPARK RM 7.1.2(16)).
10697 if Property = Name_Async_Readers
10698 or else Property = Name_Async_Writers
10702 -- Protected objects that have Part_Of components also inherit their
10703 -- properties Effective_Reads and Effective_Writes
10704 -- (SPARK RM 7.1.2(16)).
10706 elsif Present (Constits) then
10707 Constit_Elmt := First_Elmt (Constits);
10708 while Present (Constit_Elmt) loop
10709 Constit_Id := Node (Constit_Elmt);
10711 if Has_Enabled_Property (Constit_Id, Property) then
10715 Next_Elmt (Constit_Elmt);
10720 end Protected_Object_Has_Enabled_Property;
10722 --------------------------------
10723 -- State_Has_Enabled_Property --
10724 --------------------------------
10726 function State_Has_Enabled_Property return Boolean is
10727 Decl : constant Node_Id := Parent (Item_Id);
10729 procedure Find_Simple_Properties
10730 (Has_External : out Boolean;
10731 Has_Synchronous : out Boolean);
10732 -- Extract the simple properties associated with declaration Decl
10734 function Is_Enabled_External_Property return Boolean;
10735 -- Determine whether property Property appears within the external
10736 -- property list of declaration Decl, and return its status.
10738 ----------------------------
10739 -- Find_Simple_Properties --
10740 ----------------------------
10742 procedure Find_Simple_Properties
10743 (Has_External : out Boolean;
10744 Has_Synchronous : out Boolean)
10749 -- Assume that none of the properties are available
10751 Has_External := False;
10752 Has_Synchronous := False;
10754 Opt := First (Expressions (Decl));
10755 while Present (Opt) loop
10756 if Nkind (Opt) = N_Identifier then
10757 if Chars (Opt) = Name_External then
10758 Has_External := True;
10760 elsif Chars (Opt) = Name_Synchronous then
10761 Has_Synchronous := True;
10767 end Find_Simple_Properties;
10769 ----------------------------------
10770 -- Is_Enabled_External_Property --
10771 ----------------------------------
10773 function Is_Enabled_External_Property return Boolean is
10777 Prop_Nam : Node_Id;
10781 Opt := First (Component_Associations (Decl));
10782 while Present (Opt) loop
10783 Opt_Nam := First (Choices (Opt));
10785 if Nkind (Opt_Nam) = N_Identifier
10786 and then Chars (Opt_Nam) = Name_External
10788 Props := Expression (Opt);
10790 -- Multiple properties appear as an aggregate
10792 if Nkind (Props) = N_Aggregate then
10794 -- Simple property form
10796 Prop := First (Expressions (Props));
10797 while Present (Prop) loop
10798 if Chars (Prop) = Property then
10805 -- Property with expression form
10807 Prop := First (Component_Associations (Props));
10808 while Present (Prop) loop
10809 Prop_Nam := First (Choices (Prop));
10811 -- The property can be represented in two ways:
10812 -- others => <value>
10813 -- <property> => <value>
10815 if Nkind (Prop_Nam) = N_Others_Choice
10816 or else (Nkind (Prop_Nam) = N_Identifier
10817 and then Chars (Prop_Nam) = Property)
10819 return Is_True (Expr_Value (Expression (Prop)));
10828 return Chars (Props) = Property;
10836 end Is_Enabled_External_Property;
10840 Has_External : Boolean;
10841 Has_Synchronous : Boolean;
10843 -- Start of processing for State_Has_Enabled_Property
10846 -- The declaration of an external abstract state appears as an
10847 -- extension aggregate. If this is not the case, properties can
10850 if Nkind (Decl) /= N_Extension_Aggregate then
10854 Find_Simple_Properties (Has_External, Has_Synchronous);
10856 -- Simple option External enables all properties (SPARK RM 7.1.2(2))
10858 if Has_External then
10861 -- Option External may enable or disable specific properties
10863 elsif Is_Enabled_External_Property then
10866 -- Simple option Synchronous
10868 -- enables disables
10869 -- Async_Readers Effective_Reads
10870 -- Async_Writers Effective_Writes
10872 -- Note that both forms of External have higher precedence than
10873 -- Synchronous (SPARK RM 7.1.4(9)).
10875 elsif Has_Synchronous then
10876 return Nam_In (Property, Name_Async_Readers, Name_Async_Writers);
10880 end State_Has_Enabled_Property;
10882 -----------------------------------
10883 -- Variable_Has_Enabled_Property --
10884 -----------------------------------
10886 function Variable_Has_Enabled_Property return Boolean is
10887 function Is_Enabled (Prag : Node_Id) return Boolean;
10888 -- Determine whether property pragma Prag (if present) denotes an
10889 -- enabled property.
10895 function Is_Enabled (Prag : Node_Id) return Boolean is
10899 if Present (Prag) then
10900 Arg1 := First (Pragma_Argument_Associations (Prag));
10902 -- The pragma has an optional Boolean expression, the related
10903 -- property is enabled only when the expression evaluates to
10906 if Present (Arg1) then
10907 return Is_True (Expr_Value (Get_Pragma_Arg (Arg1)));
10909 -- Otherwise the lack of expression enables the property by
10916 -- The property was never set in the first place
10925 AR : constant Node_Id :=
10926 Get_Pragma (Item_Id, Pragma_Async_Readers);
10927 AW : constant Node_Id :=
10928 Get_Pragma (Item_Id, Pragma_Async_Writers);
10929 ER : constant Node_Id :=
10930 Get_Pragma (Item_Id, Pragma_Effective_Reads);
10931 EW : constant Node_Id :=
10932 Get_Pragma (Item_Id, Pragma_Effective_Writes);
10934 -- Start of processing for Variable_Has_Enabled_Property
10937 -- A non-effectively volatile object can never possess external
10940 if not Is_Effectively_Volatile (Item_Id) then
10943 -- External properties related to variables come in two flavors -
10944 -- explicit and implicit. The explicit case is characterized by the
10945 -- presence of a property pragma with an optional Boolean flag. The
10946 -- property is enabled when the flag evaluates to True or the flag is
10947 -- missing altogether.
10949 elsif Property = Name_Async_Readers and then Is_Enabled (AR) then
10952 elsif Property = Name_Async_Writers and then Is_Enabled (AW) then
10955 elsif Property = Name_Effective_Reads and then Is_Enabled (ER) then
10958 elsif Property = Name_Effective_Writes and then Is_Enabled (EW) then
10961 -- The implicit case lacks all property pragmas
10963 elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then
10964 if Is_Protected_Type (Etype (Item_Id)) then
10965 return Protected_Object_Has_Enabled_Property;
10973 end Variable_Has_Enabled_Property;
10975 -- Start of processing for Has_Enabled_Property
10978 -- Abstract states and variables have a flexible scheme of specifying
10979 -- external properties.
10981 if Ekind (Item_Id) = E_Abstract_State then
10982 return State_Has_Enabled_Property;
10984 elsif Ekind (Item_Id) = E_Variable then
10985 return Variable_Has_Enabled_Property;
10987 -- By default, protected objects only have the properties Async_Readers
10988 -- and Async_Writers. If they have Part_Of components, they also inherit
10989 -- their properties Effective_Reads and Effective_Writes
10990 -- (SPARK RM 7.1.2(16)).
10992 elsif Ekind (Item_Id) = E_Protected_Object then
10993 return Protected_Object_Has_Enabled_Property;
10995 -- Otherwise a property is enabled when the related item is effectively
10999 return Is_Effectively_Volatile (Item_Id);
11001 end Has_Enabled_Property;
11003 -------------------------------------
11004 -- Has_Full_Default_Initialization --
11005 -------------------------------------
11007 function Has_Full_Default_Initialization (Typ : Entity_Id) return Boolean is
11011 -- A type subject to pragma Default_Initial_Condition may be fully
11012 -- default initialized depending on inheritance and the argument of
11013 -- the pragma. Since any type may act as the full view of a private
11014 -- type, this check must be performed prior to the specialized tests
11017 if Has_Fully_Default_Initializing_DIC_Pragma (Typ) then
11021 -- A scalar type is fully default initialized if it is subject to aspect
11024 if Is_Scalar_Type (Typ) then
11025 return Has_Default_Aspect (Typ);
11027 -- An access type is fully default initialized by default
11029 elsif Is_Access_Type (Typ) then
11032 -- An array type is fully default initialized if its element type is
11033 -- scalar and the array type carries aspect Default_Component_Value or
11034 -- the element type is fully default initialized.
11036 elsif Is_Array_Type (Typ) then
11038 Has_Default_Aspect (Typ)
11039 or else Has_Full_Default_Initialization (Component_Type (Typ));
11041 -- A protected type, record type, or type extension is fully default
11042 -- initialized if all its components either carry an initialization
11043 -- expression or have a type that is fully default initialized. The
11044 -- parent type of a type extension must be fully default initialized.
11046 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
11048 -- Inspect all entities defined in the scope of the type, looking for
11049 -- uninitialized components.
11051 Comp := First_Entity (Typ);
11052 while Present (Comp) loop
11053 if Ekind (Comp) = E_Component
11054 and then Comes_From_Source (Comp)
11055 and then No (Expression (Parent (Comp)))
11056 and then not Has_Full_Default_Initialization (Etype (Comp))
11061 Next_Entity (Comp);
11064 -- Ensure that the parent type of a type extension is fully default
11067 if Etype (Typ) /= Typ
11068 and then not Has_Full_Default_Initialization (Etype (Typ))
11073 -- If we get here, then all components and parent portion are fully
11074 -- default initialized.
11078 -- A task type is fully default initialized by default
11080 elsif Is_Task_Type (Typ) then
11083 -- Otherwise the type is not fully default initialized
11088 end Has_Full_Default_Initialization;
11090 -----------------------------------------------
11091 -- Has_Fully_Default_Initializing_DIC_Pragma --
11092 -----------------------------------------------
11094 function Has_Fully_Default_Initializing_DIC_Pragma
11095 (Typ : Entity_Id) return Boolean
11101 -- A type that inherits pragma Default_Initial_Condition from a parent
11102 -- type is automatically fully default initialized.
11104 if Has_Inherited_DIC (Typ) then
11107 -- Otherwise the type is fully default initialized only when the pragma
11108 -- appears without an argument, or the argument is non-null.
11110 elsif Has_Own_DIC (Typ) then
11111 Prag := Get_Pragma (Typ, Pragma_Default_Initial_Condition);
11112 pragma Assert (Present (Prag));
11113 Args := Pragma_Argument_Associations (Prag);
11115 -- The pragma appears without an argument in which case it defaults
11121 -- The pragma appears with a non-null expression
11123 elsif Nkind (Get_Pragma_Arg (First (Args))) /= N_Null then
11129 end Has_Fully_Default_Initializing_DIC_Pragma;
11131 --------------------
11132 -- Has_Infinities --
11133 --------------------
11135 function Has_Infinities (E : Entity_Id) return Boolean is
11138 Is_Floating_Point_Type (E)
11139 and then Nkind (Scalar_Range (E)) = N_Range
11140 and then Includes_Infinities (Scalar_Range (E));
11141 end Has_Infinities;
11143 --------------------
11144 -- Has_Interfaces --
11145 --------------------
11147 function Has_Interfaces
11149 Use_Full_View : Boolean := True) return Boolean
11151 Typ : Entity_Id := Base_Type (T);
11154 -- Handle concurrent types
11156 if Is_Concurrent_Type (Typ) then
11157 Typ := Corresponding_Record_Type (Typ);
11160 if not Present (Typ)
11161 or else not Is_Record_Type (Typ)
11162 or else not Is_Tagged_Type (Typ)
11167 -- Handle private types
11169 if Use_Full_View and then Present (Full_View (Typ)) then
11170 Typ := Full_View (Typ);
11173 -- Handle concurrent record types
11175 if Is_Concurrent_Record_Type (Typ)
11176 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
11182 if Is_Interface (Typ)
11184 (Is_Record_Type (Typ)
11185 and then Present (Interfaces (Typ))
11186 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
11191 exit when Etype (Typ) = Typ
11193 -- Handle private types
11195 or else (Present (Full_View (Etype (Typ)))
11196 and then Full_View (Etype (Typ)) = Typ)
11198 -- Protect frontend against wrong sources with cyclic derivations
11200 or else Etype (Typ) = T;
11202 -- Climb to the ancestor type handling private types
11204 if Present (Full_View (Etype (Typ))) then
11205 Typ := Full_View (Etype (Typ));
11207 Typ := Etype (Typ);
11212 end Has_Interfaces;
11214 --------------------------
11215 -- Has_Max_Queue_Length --
11216 --------------------------
11218 function Has_Max_Queue_Length (Id : Entity_Id) return Boolean is
11221 Ekind (Id) = E_Entry
11222 and then Present (Get_Pragma (Id, Pragma_Max_Queue_Length));
11223 end Has_Max_Queue_Length;
11225 ---------------------------------
11226 -- Has_No_Obvious_Side_Effects --
11227 ---------------------------------
11229 function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
11231 -- For now handle literals, constants, and non-volatile variables and
11232 -- expressions combining these with operators or short circuit forms.
11234 if Nkind (N) in N_Numeric_Or_String_Literal then
11237 elsif Nkind (N) = N_Character_Literal then
11240 elsif Nkind (N) in N_Unary_Op then
11241 return Has_No_Obvious_Side_Effects (Right_Opnd (N));
11243 elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
11244 return Has_No_Obvious_Side_Effects (Left_Opnd (N))
11246 Has_No_Obvious_Side_Effects (Right_Opnd (N));
11248 elsif Nkind (N) = N_Expression_With_Actions
11249 and then Is_Empty_List (Actions (N))
11251 return Has_No_Obvious_Side_Effects (Expression (N));
11253 elsif Nkind (N) in N_Has_Entity then
11254 return Present (Entity (N))
11255 and then Ekind_In (Entity (N), E_Variable,
11257 E_Enumeration_Literal,
11260 E_In_Out_Parameter)
11261 and then not Is_Volatile (Entity (N));
11266 end Has_No_Obvious_Side_Effects;
11268 -----------------------------
11269 -- Has_Non_Null_Refinement --
11270 -----------------------------
11272 function Has_Non_Null_Refinement (Id : Entity_Id) return Boolean is
11273 Constits : Elist_Id;
11276 pragma Assert (Ekind (Id) = E_Abstract_State);
11277 Constits := Refinement_Constituents (Id);
11279 -- For a refinement to be non-null, the first constituent must be
11280 -- anything other than null.
11284 and then Nkind (Node (First_Elmt (Constits))) /= N_Null;
11285 end Has_Non_Null_Refinement;
11287 -----------------------------
11288 -- Has_Non_Null_Statements --
11289 -----------------------------
11291 function Has_Non_Null_Statements (L : List_Id) return Boolean is
11295 if Is_Non_Empty_List (L) then
11299 if Nkind (Node) /= N_Null_Statement then
11304 exit when Node = Empty;
11309 end Has_Non_Null_Statements;
11311 ----------------------------------
11312 -- Has_Non_Trivial_Precondition --
11313 ----------------------------------
11315 function Has_Non_Trivial_Precondition (Subp : Entity_Id) return Boolean is
11316 Pre : constant Node_Id := Find_Aspect (Subp, Aspect_Pre);
11321 and then Class_Present (Pre)
11322 and then not Is_Entity_Name (Expression (Pre));
11323 end Has_Non_Trivial_Precondition;
11325 -------------------
11326 -- Has_Null_Body --
11327 -------------------
11329 function Has_Null_Body (Proc_Id : Entity_Id) return Boolean is
11330 Body_Id : Entity_Id;
11337 Spec := Parent (Proc_Id);
11338 Decl := Parent (Spec);
11340 -- Retrieve the entity of the procedure body (e.g. invariant proc).
11342 if Nkind (Spec) = N_Procedure_Specification
11343 and then Nkind (Decl) = N_Subprogram_Declaration
11345 Body_Id := Corresponding_Body (Decl);
11347 -- The body acts as a spec
11350 Body_Id := Proc_Id;
11353 -- The body will be generated later
11355 if No (Body_Id) then
11359 Spec := Parent (Body_Id);
11360 Decl := Parent (Spec);
11363 (Nkind (Spec) = N_Procedure_Specification
11364 and then Nkind (Decl) = N_Subprogram_Body);
11366 Stmt1 := First (Statements (Handled_Statement_Sequence (Decl)));
11368 -- Look for a null statement followed by an optional return
11371 if Nkind (Stmt1) = N_Null_Statement then
11372 Stmt2 := Next (Stmt1);
11374 if Present (Stmt2) then
11375 return Nkind (Stmt2) = N_Simple_Return_Statement;
11384 ------------------------
11385 -- Has_Null_Exclusion --
11386 ------------------------
11388 function Has_Null_Exclusion (N : Node_Id) return Boolean is
11391 when N_Access_Definition
11392 | N_Access_Function_Definition
11393 | N_Access_Procedure_Definition
11394 | N_Access_To_Object_Definition
11396 | N_Derived_Type_Definition
11397 | N_Function_Specification
11398 | N_Subtype_Declaration
11400 return Null_Exclusion_Present (N);
11402 when N_Component_Definition
11403 | N_Formal_Object_Declaration
11404 | N_Object_Renaming_Declaration
11406 if Present (Subtype_Mark (N)) then
11407 return Null_Exclusion_Present (N);
11408 else pragma Assert (Present (Access_Definition (N)));
11409 return Null_Exclusion_Present (Access_Definition (N));
11412 when N_Discriminant_Specification =>
11413 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
11414 return Null_Exclusion_Present (Discriminant_Type (N));
11416 return Null_Exclusion_Present (N);
11419 when N_Object_Declaration =>
11420 if Nkind (Object_Definition (N)) = N_Access_Definition then
11421 return Null_Exclusion_Present (Object_Definition (N));
11423 return Null_Exclusion_Present (N);
11426 when N_Parameter_Specification =>
11427 if Nkind (Parameter_Type (N)) = N_Access_Definition then
11428 return Null_Exclusion_Present (Parameter_Type (N));
11430 return Null_Exclusion_Present (N);
11436 end Has_Null_Exclusion;
11438 ------------------------
11439 -- Has_Null_Extension --
11440 ------------------------
11442 function Has_Null_Extension (T : Entity_Id) return Boolean is
11443 B : constant Entity_Id := Base_Type (T);
11448 if Nkind (Parent (B)) = N_Full_Type_Declaration
11449 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
11451 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
11453 if Present (Ext) then
11454 if Null_Present (Ext) then
11457 Comps := Component_List (Ext);
11459 -- The null component list is rewritten during analysis to
11460 -- include the parent component. Any other component indicates
11461 -- that the extension was not originally null.
11463 return Null_Present (Comps)
11464 or else No (Next (First (Component_Items (Comps))));
11473 end Has_Null_Extension;
11475 -------------------------
11476 -- Has_Null_Refinement --
11477 -------------------------
11479 function Has_Null_Refinement (Id : Entity_Id) return Boolean is
11480 Constits : Elist_Id;
11483 pragma Assert (Ekind (Id) = E_Abstract_State);
11484 Constits := Refinement_Constituents (Id);
11486 -- For a refinement to be null, the state's sole constituent must be a
11491 and then Nkind (Node (First_Elmt (Constits))) = N_Null;
11492 end Has_Null_Refinement;
11494 -------------------------------
11495 -- Has_Overriding_Initialize --
11496 -------------------------------
11498 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
11499 BT : constant Entity_Id := Base_Type (T);
11503 if Is_Controlled (BT) then
11504 if Is_RTU (Scope (BT), Ada_Finalization) then
11507 elsif Present (Primitive_Operations (BT)) then
11508 P := First_Elmt (Primitive_Operations (BT));
11509 while Present (P) loop
11511 Init : constant Entity_Id := Node (P);
11512 Formal : constant Entity_Id := First_Formal (Init);
11514 if Ekind (Init) = E_Procedure
11515 and then Chars (Init) = Name_Initialize
11516 and then Comes_From_Source (Init)
11517 and then Present (Formal)
11518 and then Etype (Formal) = BT
11519 and then No (Next_Formal (Formal))
11520 and then (Ada_Version < Ada_2012
11521 or else not Null_Present (Parent (Init)))
11531 -- Here if type itself does not have a non-null Initialize operation:
11532 -- check immediate ancestor.
11534 if Is_Derived_Type (BT)
11535 and then Has_Overriding_Initialize (Etype (BT))
11542 end Has_Overriding_Initialize;
11544 --------------------------------------
11545 -- Has_Preelaborable_Initialization --
11546 --------------------------------------
11548 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
11551 procedure Check_Components (E : Entity_Id);
11552 -- Check component/discriminant chain, sets Has_PE False if a component
11553 -- or discriminant does not meet the preelaborable initialization rules.
11555 ----------------------
11556 -- Check_Components --
11557 ----------------------
11559 procedure Check_Components (E : Entity_Id) is
11564 -- Loop through entities of record or protected type
11567 while Present (Ent) loop
11569 -- We are interested only in components and discriminants
11573 case Ekind (Ent) is
11574 when E_Component =>
11576 -- Get default expression if any. If there is no declaration
11577 -- node, it means we have an internal entity. The parent and
11578 -- tag fields are examples of such entities. For such cases,
11579 -- we just test the type of the entity.
11581 if Present (Declaration_Node (Ent)) then
11582 Exp := Expression (Declaration_Node (Ent));
11585 when E_Discriminant =>
11587 -- Note: for a renamed discriminant, the Declaration_Node
11588 -- may point to the one from the ancestor, and have a
11589 -- different expression, so use the proper attribute to
11590 -- retrieve the expression from the derived constraint.
11592 Exp := Discriminant_Default_Value (Ent);
11595 goto Check_Next_Entity;
11598 -- A component has PI if it has no default expression and the
11599 -- component type has PI.
11602 if not Has_Preelaborable_Initialization (Etype (Ent)) then
11607 -- Require the default expression to be preelaborable
11609 elsif not Is_Preelaborable_Construct (Exp) then
11614 <<Check_Next_Entity>>
11617 end Check_Components;
11619 -- Start of processing for Has_Preelaborable_Initialization
11622 -- Immediate return if already marked as known preelaborable init. This
11623 -- covers types for which this function has already been called once
11624 -- and returned True (in which case the result is cached), and also
11625 -- types to which a pragma Preelaborable_Initialization applies.
11627 if Known_To_Have_Preelab_Init (E) then
11631 -- If the type is a subtype representing a generic actual type, then
11632 -- test whether its base type has preelaborable initialization since
11633 -- the subtype representing the actual does not inherit this attribute
11634 -- from the actual or formal. (but maybe it should???)
11636 if Is_Generic_Actual_Type (E) then
11637 return Has_Preelaborable_Initialization (Base_Type (E));
11640 -- All elementary types have preelaborable initialization
11642 if Is_Elementary_Type (E) then
11645 -- Array types have PI if the component type has PI
11647 elsif Is_Array_Type (E) then
11648 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
11650 -- A derived type has preelaborable initialization if its parent type
11651 -- has preelaborable initialization and (in the case of a derived record
11652 -- extension) if the non-inherited components all have preelaborable
11653 -- initialization. However, a user-defined controlled type with an
11654 -- overriding Initialize procedure does not have preelaborable
11657 elsif Is_Derived_Type (E) then
11659 -- If the derived type is a private extension then it doesn't have
11660 -- preelaborable initialization.
11662 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
11666 -- First check whether ancestor type has preelaborable initialization
11668 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
11670 -- If OK, check extension components (if any)
11672 if Has_PE and then Is_Record_Type (E) then
11673 Check_Components (First_Entity (E));
11676 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
11677 -- with a user defined Initialize procedure does not have PI. If
11678 -- the type is untagged, the control primitives come from a component
11679 -- that has already been checked.
11682 and then Is_Controlled (E)
11683 and then Is_Tagged_Type (E)
11684 and then Has_Overriding_Initialize (E)
11689 -- Private types not derived from a type having preelaborable init and
11690 -- that are not marked with pragma Preelaborable_Initialization do not
11691 -- have preelaborable initialization.
11693 elsif Is_Private_Type (E) then
11696 -- Record type has PI if it is non private and all components have PI
11698 elsif Is_Record_Type (E) then
11700 Check_Components (First_Entity (E));
11702 -- Protected types must not have entries, and components must meet
11703 -- same set of rules as for record components.
11705 elsif Is_Protected_Type (E) then
11706 if Has_Entries (E) then
11710 Check_Components (First_Entity (E));
11711 Check_Components (First_Private_Entity (E));
11714 -- Type System.Address always has preelaborable initialization
11716 elsif Is_RTE (E, RE_Address) then
11719 -- In all other cases, type does not have preelaborable initialization
11725 -- If type has preelaborable initialization, cache result
11728 Set_Known_To_Have_Preelab_Init (E);
11732 end Has_Preelaborable_Initialization;
11738 function Has_Prefix (N : Node_Id) return Boolean is
11741 Nkind_In (N, N_Attribute_Reference,
11743 N_Explicit_Dereference,
11744 N_Indexed_Component,
11746 N_Selected_Component,
11750 ---------------------------
11751 -- Has_Private_Component --
11752 ---------------------------
11754 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
11755 Btype : Entity_Id := Base_Type (Type_Id);
11756 Component : Entity_Id;
11759 if Error_Posted (Type_Id)
11760 or else Error_Posted (Btype)
11765 if Is_Class_Wide_Type (Btype) then
11766 Btype := Root_Type (Btype);
11769 if Is_Private_Type (Btype) then
11771 UT : constant Entity_Id := Underlying_Type (Btype);
11774 if No (Full_View (Btype)) then
11775 return not Is_Generic_Type (Btype)
11777 not Is_Generic_Type (Root_Type (Btype));
11779 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
11782 return not Is_Frozen (UT) and then Has_Private_Component (UT);
11786 elsif Is_Array_Type (Btype) then
11787 return Has_Private_Component (Component_Type (Btype));
11789 elsif Is_Record_Type (Btype) then
11790 Component := First_Component (Btype);
11791 while Present (Component) loop
11792 if Has_Private_Component (Etype (Component)) then
11796 Next_Component (Component);
11801 elsif Is_Protected_Type (Btype)
11802 and then Present (Corresponding_Record_Type (Btype))
11804 return Has_Private_Component (Corresponding_Record_Type (Btype));
11809 end Has_Private_Component;
11811 ----------------------
11812 -- Has_Signed_Zeros --
11813 ----------------------
11815 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
11817 return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target;
11818 end Has_Signed_Zeros;
11820 ------------------------------
11821 -- Has_Significant_Contract --
11822 ------------------------------
11824 function Has_Significant_Contract (Subp_Id : Entity_Id) return Boolean is
11825 Subp_Nam : constant Name_Id := Chars (Subp_Id);
11828 -- _Finalizer procedure
11830 if Subp_Nam = Name_uFinalizer then
11833 -- _Postconditions procedure
11835 elsif Subp_Nam = Name_uPostconditions then
11838 -- Predicate function
11840 elsif Ekind (Subp_Id) = E_Function
11841 and then Is_Predicate_Function (Subp_Id)
11847 elsif Get_TSS_Name (Subp_Id) /= TSS_Null then
11853 end Has_Significant_Contract;
11855 -----------------------------
11856 -- Has_Static_Array_Bounds --
11857 -----------------------------
11859 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
11860 All_Static : Boolean;
11864 Examine_Array_Bounds (Typ, All_Static, Dummy);
11867 end Has_Static_Array_Bounds;
11869 ---------------------------------------
11870 -- Has_Static_Non_Empty_Array_Bounds --
11871 ---------------------------------------
11873 function Has_Static_Non_Empty_Array_Bounds (Typ : Node_Id) return Boolean is
11874 All_Static : Boolean;
11875 Has_Empty : Boolean;
11878 Examine_Array_Bounds (Typ, All_Static, Has_Empty);
11880 return All_Static and not Has_Empty;
11881 end Has_Static_Non_Empty_Array_Bounds;
11887 function Has_Stream (T : Entity_Id) return Boolean is
11894 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
11897 elsif Is_Array_Type (T) then
11898 return Has_Stream (Component_Type (T));
11900 elsif Is_Record_Type (T) then
11901 E := First_Component (T);
11902 while Present (E) loop
11903 if Has_Stream (Etype (E)) then
11906 Next_Component (E);
11912 elsif Is_Private_Type (T) then
11913 return Has_Stream (Underlying_Type (T));
11924 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
11926 Get_Name_String (Chars (E));
11927 return Name_Buffer (Name_Len) = Suffix;
11934 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
11936 Get_Name_String (Chars (E));
11937 Add_Char_To_Name_Buffer (Suffix);
11941 -------------------
11942 -- Remove_Suffix --
11943 -------------------
11945 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
11947 pragma Assert (Has_Suffix (E, Suffix));
11948 Get_Name_String (Chars (E));
11949 Name_Len := Name_Len - 1;
11953 ----------------------------------
11954 -- Replace_Null_By_Null_Address --
11955 ----------------------------------
11957 procedure Replace_Null_By_Null_Address (N : Node_Id) is
11958 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id);
11959 -- Replace operand Op with a reference to Null_Address when the operand
11960 -- denotes a null Address. Other_Op denotes the other operand.
11962 --------------------------
11963 -- Replace_Null_Operand --
11964 --------------------------
11966 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id) is
11968 -- Check the type of the complementary operand since the N_Null node
11969 -- has not been decorated yet.
11971 if Nkind (Op) = N_Null
11972 and then Is_Descendant_Of_Address (Etype (Other_Op))
11974 Rewrite (Op, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (Op)));
11976 end Replace_Null_Operand;
11978 -- Start of processing for Replace_Null_By_Null_Address
11981 pragma Assert (Relaxed_RM_Semantics);
11982 pragma Assert (Nkind_In (N, N_Null,
11990 if Nkind (N) = N_Null then
11991 Rewrite (N, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (N)));
11995 L : constant Node_Id := Left_Opnd (N);
11996 R : constant Node_Id := Right_Opnd (N);
11999 Replace_Null_Operand (L, Other_Op => R);
12000 Replace_Null_Operand (R, Other_Op => L);
12003 end Replace_Null_By_Null_Address;
12005 --------------------------
12006 -- Has_Tagged_Component --
12007 --------------------------
12009 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
12013 if Is_Private_Type (Typ) and then Present (Underlying_Type (Typ)) then
12014 return Has_Tagged_Component (Underlying_Type (Typ));
12016 elsif Is_Array_Type (Typ) then
12017 return Has_Tagged_Component (Component_Type (Typ));
12019 elsif Is_Tagged_Type (Typ) then
12022 elsif Is_Record_Type (Typ) then
12023 Comp := First_Component (Typ);
12024 while Present (Comp) loop
12025 if Has_Tagged_Component (Etype (Comp)) then
12029 Next_Component (Comp);
12037 end Has_Tagged_Component;
12039 -----------------------------
12040 -- Has_Undefined_Reference --
12041 -----------------------------
12043 function Has_Undefined_Reference (Expr : Node_Id) return Boolean is
12044 Has_Undef_Ref : Boolean := False;
12045 -- Flag set when expression Expr contains at least one undefined
12048 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result;
12049 -- Determine whether N denotes a reference and if it does, whether it is
12052 ----------------------------
12053 -- Is_Undefined_Reference --
12054 ----------------------------
12056 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result is
12058 if Is_Entity_Name (N)
12059 and then Present (Entity (N))
12060 and then Entity (N) = Any_Id
12062 Has_Undef_Ref := True;
12067 end Is_Undefined_Reference;
12069 procedure Find_Undefined_References is
12070 new Traverse_Proc (Is_Undefined_Reference);
12072 -- Start of processing for Has_Undefined_Reference
12075 Find_Undefined_References (Expr);
12077 return Has_Undef_Ref;
12078 end Has_Undefined_Reference;
12080 ----------------------------
12081 -- Has_Volatile_Component --
12082 ----------------------------
12084 function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
12088 if Has_Volatile_Components (Typ) then
12091 elsif Is_Array_Type (Typ) then
12092 return Is_Volatile (Component_Type (Typ));
12094 elsif Is_Record_Type (Typ) then
12095 Comp := First_Component (Typ);
12096 while Present (Comp) loop
12097 if Is_Volatile_Object (Comp) then
12101 Comp := Next_Component (Comp);
12106 end Has_Volatile_Component;
12108 -------------------------
12109 -- Implementation_Kind --
12110 -------------------------
12112 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
12113 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
12116 pragma Assert (Present (Impl_Prag));
12117 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
12118 return Chars (Get_Pragma_Arg (Arg));
12119 end Implementation_Kind;
12121 --------------------------
12122 -- Implements_Interface --
12123 --------------------------
12125 function Implements_Interface
12126 (Typ_Ent : Entity_Id;
12127 Iface_Ent : Entity_Id;
12128 Exclude_Parents : Boolean := False) return Boolean
12130 Ifaces_List : Elist_Id;
12132 Iface : Entity_Id := Base_Type (Iface_Ent);
12133 Typ : Entity_Id := Base_Type (Typ_Ent);
12136 if Is_Class_Wide_Type (Typ) then
12137 Typ := Root_Type (Typ);
12140 if not Has_Interfaces (Typ) then
12144 if Is_Class_Wide_Type (Iface) then
12145 Iface := Root_Type (Iface);
12148 Collect_Interfaces (Typ, Ifaces_List);
12150 Elmt := First_Elmt (Ifaces_List);
12151 while Present (Elmt) loop
12152 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
12153 and then Exclude_Parents
12157 elsif Node (Elmt) = Iface then
12165 end Implements_Interface;
12167 ------------------------------------
12168 -- In_Assertion_Expression_Pragma --
12169 ------------------------------------
12171 function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is
12173 Prag : Node_Id := Empty;
12176 -- Climb the parent chain looking for an enclosing pragma
12179 while Present (Par) loop
12180 if Nkind (Par) = N_Pragma then
12184 -- Precondition-like pragmas are expanded into if statements, check
12185 -- the original node instead.
12187 elsif Nkind (Original_Node (Par)) = N_Pragma then
12188 Prag := Original_Node (Par);
12191 -- The expansion of attribute 'Old generates a constant to capture
12192 -- the result of the prefix. If the parent traversal reaches
12193 -- one of these constants, then the node technically came from a
12194 -- postcondition-like pragma. Note that the Ekind is not tested here
12195 -- because N may be the expression of an object declaration which is
12196 -- currently being analyzed. Such objects carry Ekind of E_Void.
12198 elsif Nkind (Par) = N_Object_Declaration
12199 and then Constant_Present (Par)
12200 and then Stores_Attribute_Old_Prefix (Defining_Entity (Par))
12204 -- Prevent the search from going too far
12206 elsif Is_Body_Or_Package_Declaration (Par) then
12210 Par := Parent (Par);
12215 and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag));
12216 end In_Assertion_Expression_Pragma;
12218 ----------------------
12219 -- In_Generic_Scope --
12220 ----------------------
12222 function In_Generic_Scope (E : Entity_Id) return Boolean is
12227 while Present (S) and then S /= Standard_Standard loop
12228 if Is_Generic_Unit (S) then
12236 end In_Generic_Scope;
12242 function In_Instance return Boolean is
12243 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
12247 S := Current_Scope;
12248 while Present (S) and then S /= Standard_Standard loop
12249 if Is_Generic_Instance (S) then
12251 -- A child instance is always compiled in the context of a parent
12252 -- instance. Nevertheless, the actuals are not analyzed in an
12253 -- instance context. We detect this case by examining the current
12254 -- compilation unit, which must be a child instance, and checking
12255 -- that it is not currently on the scope stack.
12257 if Is_Child_Unit (Curr_Unit)
12258 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
12259 N_Package_Instantiation
12260 and then not In_Open_Scopes (Curr_Unit)
12274 ----------------------
12275 -- In_Instance_Body --
12276 ----------------------
12278 function In_Instance_Body return Boolean is
12282 S := Current_Scope;
12283 while Present (S) and then S /= Standard_Standard loop
12284 if Ekind_In (S, E_Function, E_Procedure)
12285 and then Is_Generic_Instance (S)
12289 elsif Ekind (S) = E_Package
12290 and then In_Package_Body (S)
12291 and then Is_Generic_Instance (S)
12300 end In_Instance_Body;
12302 -----------------------------
12303 -- In_Instance_Not_Visible --
12304 -----------------------------
12306 function In_Instance_Not_Visible return Boolean is
12310 S := Current_Scope;
12311 while Present (S) and then S /= Standard_Standard loop
12312 if Ekind_In (S, E_Function, E_Procedure)
12313 and then Is_Generic_Instance (S)
12317 elsif Ekind (S) = E_Package
12318 and then (In_Package_Body (S) or else In_Private_Part (S))
12319 and then Is_Generic_Instance (S)
12328 end In_Instance_Not_Visible;
12330 ------------------------------
12331 -- In_Instance_Visible_Part --
12332 ------------------------------
12334 function In_Instance_Visible_Part
12335 (Id : Entity_Id := Current_Scope) return Boolean
12341 while Present (Inst) and then Inst /= Standard_Standard loop
12342 if Ekind (Inst) = E_Package
12343 and then Is_Generic_Instance (Inst)
12344 and then not In_Package_Body (Inst)
12345 and then not In_Private_Part (Inst)
12350 Inst := Scope (Inst);
12354 end In_Instance_Visible_Part;
12356 ---------------------
12357 -- In_Package_Body --
12358 ---------------------
12360 function In_Package_Body return Boolean is
12364 S := Current_Scope;
12365 while Present (S) and then S /= Standard_Standard loop
12366 if Ekind (S) = E_Package and then In_Package_Body (S) then
12374 end In_Package_Body;
12376 --------------------------
12377 -- In_Pragma_Expression --
12378 --------------------------
12380 function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean is
12387 elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
12393 end In_Pragma_Expression;
12395 ---------------------------
12396 -- In_Pre_Post_Condition --
12397 ---------------------------
12399 function In_Pre_Post_Condition (N : Node_Id) return Boolean is
12401 Prag : Node_Id := Empty;
12402 Prag_Id : Pragma_Id;
12405 -- Climb the parent chain looking for an enclosing pragma
12408 while Present (Par) loop
12409 if Nkind (Par) = N_Pragma then
12413 -- Prevent the search from going too far
12415 elsif Is_Body_Or_Package_Declaration (Par) then
12419 Par := Parent (Par);
12422 if Present (Prag) then
12423 Prag_Id := Get_Pragma_Id (Prag);
12426 Prag_Id = Pragma_Post
12427 or else Prag_Id = Pragma_Post_Class
12428 or else Prag_Id = Pragma_Postcondition
12429 or else Prag_Id = Pragma_Pre
12430 or else Prag_Id = Pragma_Pre_Class
12431 or else Prag_Id = Pragma_Precondition;
12433 -- Otherwise the node is not enclosed by a pre/postcondition pragma
12438 end In_Pre_Post_Condition;
12440 ------------------------------
12441 -- In_Quantified_Expression --
12442 ------------------------------
12444 function In_Quantified_Expression (N : Node_Id) return Boolean is
12451 elsif Nkind (P) = N_Quantified_Expression then
12457 end In_Quantified_Expression;
12459 -------------------------------------
12460 -- In_Reverse_Storage_Order_Object --
12461 -------------------------------------
12463 function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
12465 Btyp : Entity_Id := Empty;
12468 -- Climb up indexed components
12472 case Nkind (Pref) is
12473 when N_Selected_Component =>
12474 Pref := Prefix (Pref);
12477 when N_Indexed_Component =>
12478 Pref := Prefix (Pref);
12486 if Present (Pref) then
12487 Btyp := Base_Type (Etype (Pref));
12490 return Present (Btyp)
12491 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
12492 and then Reverse_Storage_Order (Btyp);
12493 end In_Reverse_Storage_Order_Object;
12495 ------------------------------
12496 -- In_Same_Declarative_Part --
12497 ------------------------------
12499 function In_Same_Declarative_Part
12500 (Context : Node_Id;
12501 N : Node_Id) return Boolean
12503 Cont : Node_Id := Context;
12507 if Nkind (Cont) = N_Compilation_Unit_Aux then
12508 Cont := Parent (Cont);
12512 while Present (Nod) loop
12516 elsif Nkind_In (Nod, N_Accept_Statement,
12518 N_Compilation_Unit,
12521 N_Package_Declaration,
12528 elsif Nkind (Nod) = N_Subunit then
12529 Nod := Corresponding_Stub (Nod);
12532 Nod := Parent (Nod);
12537 end In_Same_Declarative_Part;
12539 --------------------------------------
12540 -- In_Subprogram_Or_Concurrent_Unit --
12541 --------------------------------------
12543 function In_Subprogram_Or_Concurrent_Unit return Boolean is
12548 -- Use scope chain to check successively outer scopes
12550 E := Current_Scope;
12554 if K in Subprogram_Kind
12555 or else K in Concurrent_Kind
12556 or else K in Generic_Subprogram_Kind
12560 elsif E = Standard_Standard then
12566 end In_Subprogram_Or_Concurrent_Unit;
12572 function In_Subtree (N : Node_Id; Root : Node_Id) return Boolean is
12577 while Present (Curr) loop
12578 if Curr = Root then
12582 Curr := Parent (Curr);
12592 function In_Subtree
12595 Root2 : Node_Id) return Boolean
12601 while Present (Curr) loop
12602 if Curr = Root1 or else Curr = Root2 then
12606 Curr := Parent (Curr);
12612 ---------------------
12613 -- In_Visible_Part --
12614 ---------------------
12616 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
12618 return Is_Package_Or_Generic_Package (Scope_Id)
12619 and then In_Open_Scopes (Scope_Id)
12620 and then not In_Package_Body (Scope_Id)
12621 and then not In_Private_Part (Scope_Id);
12622 end In_Visible_Part;
12624 --------------------------------
12625 -- Incomplete_Or_Partial_View --
12626 --------------------------------
12628 function Incomplete_Or_Partial_View (Id : Entity_Id) return Entity_Id is
12629 function Inspect_Decls
12631 Taft : Boolean := False) return Entity_Id;
12632 -- Check whether a declarative region contains the incomplete or partial
12635 -------------------
12636 -- Inspect_Decls --
12637 -------------------
12639 function Inspect_Decls
12641 Taft : Boolean := False) return Entity_Id
12647 Decl := First (Decls);
12648 while Present (Decl) loop
12651 -- The partial view of a Taft-amendment type is an incomplete
12655 if Nkind (Decl) = N_Incomplete_Type_Declaration then
12656 Match := Defining_Identifier (Decl);
12659 -- Otherwise look for a private type whose full view matches the
12660 -- input type. Note that this checks full_type_declaration nodes
12661 -- to account for derivations from a private type where the type
12662 -- declaration hold the partial view and the full view is an
12665 elsif Nkind_In (Decl, N_Full_Type_Declaration,
12666 N_Private_Extension_Declaration,
12667 N_Private_Type_Declaration)
12669 Match := Defining_Identifier (Decl);
12672 -- Guard against unanalyzed entities
12675 and then Is_Type (Match)
12676 and then Present (Full_View (Match))
12677 and then Full_View (Match) = Id
12692 -- Start of processing for Incomplete_Or_Partial_View
12695 -- Deferred constant or incomplete type case
12697 Prev := Current_Entity_In_Scope (Id);
12700 and then (Is_Incomplete_Type (Prev) or else Ekind (Prev) = E_Constant)
12701 and then Present (Full_View (Prev))
12702 and then Full_View (Prev) = Id
12707 -- Private or Taft amendment type case
12710 Pkg : constant Entity_Id := Scope (Id);
12711 Pkg_Decl : Node_Id := Pkg;
12715 and then Ekind_In (Pkg, E_Generic_Package, E_Package)
12717 while Nkind (Pkg_Decl) /= N_Package_Specification loop
12718 Pkg_Decl := Parent (Pkg_Decl);
12721 -- It is knows that Typ has a private view, look for it in the
12722 -- visible declarations of the enclosing scope. A special case
12723 -- of this is when the two views have been exchanged - the full
12724 -- appears earlier than the private.
12726 if Has_Private_Declaration (Id) then
12727 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
12729 -- Exchanged view case, look in the private declarations
12732 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
12737 -- Otherwise if this is the package body, then Typ is a potential
12738 -- Taft amendment type. The incomplete view should be located in
12739 -- the private declarations of the enclosing scope.
12741 elsif In_Package_Body (Pkg) then
12742 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
12747 -- The type has no incomplete or private view
12750 end Incomplete_Or_Partial_View;
12752 ---------------------------------------
12753 -- Incomplete_View_From_Limited_With --
12754 ---------------------------------------
12756 function Incomplete_View_From_Limited_With
12757 (Typ : Entity_Id) return Entity_Id
12760 -- It might make sense to make this an attribute in Einfo, and set it
12761 -- in Sem_Ch10 in Build_Shadow_Entity. However, we're running short on
12762 -- slots for new attributes, and it seems a bit simpler to just search
12763 -- the Limited_View (if it exists) for an incomplete type whose
12764 -- Non_Limited_View is Typ.
12766 if Ekind (Scope (Typ)) = E_Package
12767 and then Present (Limited_View (Scope (Typ)))
12770 Ent : Entity_Id := First_Entity (Limited_View (Scope (Typ)));
12772 while Present (Ent) loop
12773 if Ekind (Ent) in Incomplete_Kind
12774 and then Non_Limited_View (Ent) = Typ
12779 Ent := Next_Entity (Ent);
12785 end Incomplete_View_From_Limited_With;
12787 ----------------------------------
12788 -- Indexed_Component_Bit_Offset --
12789 ----------------------------------
12791 function Indexed_Component_Bit_Offset (N : Node_Id) return Uint is
12792 Exp : constant Node_Id := First (Expressions (N));
12793 Typ : constant Entity_Id := Etype (Prefix (N));
12794 Off : constant Uint := Component_Size (Typ);
12798 -- Return early if the component size is not known or variable
12800 if Off = No_Uint or else Off < Uint_0 then
12804 -- Deal with the degenerate case of an empty component
12806 if Off = Uint_0 then
12810 -- Check that both the index value and the low bound are known
12812 if not Compile_Time_Known_Value (Exp) then
12816 Ind := First_Index (Typ);
12821 if Nkind (Ind) = N_Subtype_Indication then
12822 Ind := Constraint (Ind);
12824 if Nkind (Ind) = N_Range_Constraint then
12825 Ind := Range_Expression (Ind);
12829 if Nkind (Ind) /= N_Range
12830 or else not Compile_Time_Known_Value (Low_Bound (Ind))
12835 -- Return the scaled offset
12837 return Off * (Expr_Value (Exp) - Expr_Value (Low_Bound ((Ind))));
12838 end Indexed_Component_Bit_Offset;
12840 ----------------------------
12841 -- Inherit_Rep_Item_Chain --
12842 ----------------------------
12844 procedure Inherit_Rep_Item_Chain (Typ : Entity_Id; From_Typ : Entity_Id) is
12846 Next_Item : Node_Id;
12849 -- There are several inheritance scenarios to consider depending on
12850 -- whether both types have rep item chains and whether the destination
12851 -- type already inherits part of the source type's rep item chain.
12853 -- 1) The source type lacks a rep item chain
12854 -- From_Typ ---> Empty
12856 -- Typ --------> Item (or Empty)
12858 -- In this case inheritance cannot take place because there are no items
12861 -- 2) The destination type lacks a rep item chain
12862 -- From_Typ ---> Item ---> ...
12864 -- Typ --------> Empty
12866 -- Inheritance takes place by setting the First_Rep_Item of the
12867 -- destination type to the First_Rep_Item of the source type.
12868 -- From_Typ ---> Item ---> ...
12870 -- Typ -----------+
12872 -- 3.1) Both source and destination types have at least one rep item.
12873 -- The destination type does NOT inherit a rep item from the source
12875 -- From_Typ ---> Item ---> Item
12877 -- Typ --------> Item ---> Item
12879 -- Inheritance takes place by setting the Next_Rep_Item of the last item
12880 -- of the destination type to the First_Rep_Item of the source type.
12881 -- From_Typ -------------------> Item ---> Item
12883 -- Typ --------> Item ---> Item --+
12885 -- 3.2) Both source and destination types have at least one rep item.
12886 -- The destination type DOES inherit part of the rep item chain of the
12888 -- From_Typ ---> Item ---> Item ---> Item
12890 -- Typ --------> Item ------+
12892 -- This rare case arises when the full view of a private extension must
12893 -- inherit the rep item chain from the full view of its parent type and
12894 -- the full view of the parent type contains extra rep items. Currently
12895 -- only invariants may lead to such form of inheritance.
12897 -- type From_Typ is tagged private
12898 -- with Type_Invariant'Class => Item_2;
12900 -- type Typ is new From_Typ with private
12901 -- with Type_Invariant => Item_4;
12903 -- At this point the rep item chains contain the following items
12905 -- From_Typ -----------> Item_2 ---> Item_3
12907 -- Typ --------> Item_4 --+
12909 -- The full views of both types may introduce extra invariants
12911 -- type From_Typ is tagged null record
12912 -- with Type_Invariant => Item_1;
12914 -- type Typ is new From_Typ with null record;
12916 -- The full view of Typ would have to inherit any new rep items added to
12917 -- the full view of From_Typ.
12919 -- From_Typ -----------> Item_1 ---> Item_2 ---> Item_3
12921 -- Typ --------> Item_4 --+
12923 -- To achieve this form of inheritance, the destination type must first
12924 -- sever the link between its own rep chain and that of the source type,
12925 -- then inheritance 3.1 takes place.
12927 -- Case 1: The source type lacks a rep item chain
12929 if No (First_Rep_Item (From_Typ)) then
12932 -- Case 2: The destination type lacks a rep item chain
12934 elsif No (First_Rep_Item (Typ)) then
12935 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
12937 -- Case 3: Both the source and destination types have at least one rep
12938 -- item. Traverse the rep item chain of the destination type to find the
12943 Next_Item := First_Rep_Item (Typ);
12944 while Present (Next_Item) loop
12946 -- Detect a link between the destination type's rep chain and that
12947 -- of the source type. There are two possibilities:
12952 -- From_Typ ---> Item_1 --->
12954 -- Typ -----------+
12961 -- From_Typ ---> Item_1 ---> Item_2 --->
12963 -- Typ --------> Item_3 ------+
12967 if Has_Rep_Item (From_Typ, Next_Item) then
12972 Next_Item := Next_Rep_Item (Next_Item);
12975 -- Inherit the source type's rep item chain
12977 if Present (Item) then
12978 Set_Next_Rep_Item (Item, First_Rep_Item (From_Typ));
12980 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
12983 end Inherit_Rep_Item_Chain;
12985 ------------------------------------
12986 -- Inherits_From_Tagged_Full_View --
12987 ------------------------------------
12989 function Inherits_From_Tagged_Full_View (Typ : Entity_Id) return Boolean is
12991 return Is_Private_Type (Typ)
12992 and then Present (Full_View (Typ))
12993 and then Is_Private_Type (Full_View (Typ))
12994 and then not Is_Tagged_Type (Full_View (Typ))
12995 and then Present (Underlying_Type (Full_View (Typ)))
12996 and then Is_Tagged_Type (Underlying_Type (Full_View (Typ)));
12997 end Inherits_From_Tagged_Full_View;
12999 ---------------------------------
13000 -- Insert_Explicit_Dereference --
13001 ---------------------------------
13003 procedure Insert_Explicit_Dereference (N : Node_Id) is
13004 New_Prefix : constant Node_Id := Relocate_Node (N);
13005 Ent : Entity_Id := Empty;
13012 Save_Interps (N, New_Prefix);
13015 Make_Explicit_Dereference (Sloc (Parent (N)),
13016 Prefix => New_Prefix));
13018 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
13020 if Is_Overloaded (New_Prefix) then
13022 -- The dereference is also overloaded, and its interpretations are
13023 -- the designated types of the interpretations of the original node.
13025 Set_Etype (N, Any_Type);
13027 Get_First_Interp (New_Prefix, I, It);
13028 while Present (It.Nam) loop
13031 if Is_Access_Type (T) then
13032 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
13035 Get_Next_Interp (I, It);
13041 -- Prefix is unambiguous: mark the original prefix (which might
13042 -- Come_From_Source) as a reference, since the new (relocated) one
13043 -- won't be taken into account.
13045 if Is_Entity_Name (New_Prefix) then
13046 Ent := Entity (New_Prefix);
13047 Pref := New_Prefix;
13049 -- For a retrieval of a subcomponent of some composite object,
13050 -- retrieve the ultimate entity if there is one.
13052 elsif Nkind_In (New_Prefix, N_Selected_Component,
13053 N_Indexed_Component)
13055 Pref := Prefix (New_Prefix);
13056 while Present (Pref)
13057 and then Nkind_In (Pref, N_Selected_Component,
13058 N_Indexed_Component)
13060 Pref := Prefix (Pref);
13063 if Present (Pref) and then Is_Entity_Name (Pref) then
13064 Ent := Entity (Pref);
13068 -- Place the reference on the entity node
13070 if Present (Ent) then
13071 Generate_Reference (Ent, Pref);
13074 end Insert_Explicit_Dereference;
13076 ------------------------------------------
13077 -- Inspect_Deferred_Constant_Completion --
13078 ------------------------------------------
13080 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
13084 Decl := First (Decls);
13085 while Present (Decl) loop
13087 -- Deferred constant signature
13089 if Nkind (Decl) = N_Object_Declaration
13090 and then Constant_Present (Decl)
13091 and then No (Expression (Decl))
13093 -- No need to check internally generated constants
13095 and then Comes_From_Source (Decl)
13097 -- The constant is not completed. A full object declaration or a
13098 -- pragma Import complete a deferred constant.
13100 and then not Has_Completion (Defining_Identifier (Decl))
13103 ("constant declaration requires initialization expression",
13104 Defining_Identifier (Decl));
13107 Decl := Next (Decl);
13109 end Inspect_Deferred_Constant_Completion;
13111 -------------------------------
13112 -- Install_Elaboration_Model --
13113 -------------------------------
13115 procedure Install_Elaboration_Model (Unit_Id : Entity_Id) is
13116 function Find_Elaboration_Checks_Pragma (L : List_Id) return Node_Id;
13117 -- Try to find pragma Elaboration_Checks in arbitrary list L. Return
13118 -- Empty if there is no such pragma.
13120 ------------------------------------
13121 -- Find_Elaboration_Checks_Pragma --
13122 ------------------------------------
13124 function Find_Elaboration_Checks_Pragma (L : List_Id) return Node_Id is
13129 while Present (Item) loop
13130 if Nkind (Item) = N_Pragma
13131 and then Pragma_Name (Item) = Name_Elaboration_Checks
13140 end Find_Elaboration_Checks_Pragma;
13149 -- Start of processing for Install_Elaboration_Model
13152 -- Nothing to do when the unit does not exist
13154 if No (Unit_Id) then
13158 Unit := Parent (Unit_Declaration_Node (Unit_Id));
13160 -- Nothing to do when the unit is not a library unit
13162 if Nkind (Unit) /= N_Compilation_Unit then
13166 Prag := Find_Elaboration_Checks_Pragma (Context_Items (Unit));
13168 -- The compilation unit is subject to pragma Elaboration_Checks. Set the
13169 -- elaboration model as specified by the pragma.
13171 if Present (Prag) then
13172 Args := Pragma_Argument_Associations (Prag);
13174 -- Guard against an illegal pragma. The sole argument must be an
13175 -- identifier which specifies either Dynamic or Static model.
13177 if Present (Args) then
13178 Model := Get_Pragma_Arg (First (Args));
13180 if Nkind (Model) = N_Identifier then
13181 Dynamic_Elaboration_Checks := Chars (Model) = Name_Dynamic;
13185 end Install_Elaboration_Model;
13187 -----------------------------
13188 -- Install_Generic_Formals --
13189 -----------------------------
13191 procedure Install_Generic_Formals (Subp_Id : Entity_Id) is
13195 pragma Assert (Is_Generic_Subprogram (Subp_Id));
13197 E := First_Entity (Subp_Id);
13198 while Present (E) loop
13199 Install_Entity (E);
13202 end Install_Generic_Formals;
13204 ------------------------
13205 -- Install_SPARK_Mode --
13206 ------------------------
13208 procedure Install_SPARK_Mode (Mode : SPARK_Mode_Type; Prag : Node_Id) is
13210 SPARK_Mode := Mode;
13211 SPARK_Mode_Pragma := Prag;
13212 end Install_SPARK_Mode;
13214 --------------------------
13215 -- Invalid_Scalar_Value --
13216 --------------------------
13218 function Invalid_Scalar_Value
13220 Scal_Typ : Scalar_Id) return Node_Id
13222 function Invalid_Binder_Value return Node_Id;
13223 -- Return a reference to the corresponding invalid value for type
13224 -- Scal_Typ as defined in unit System.Scalar_Values.
13226 function Invalid_Float_Value return Node_Id;
13227 -- Return the invalid value of float type Scal_Typ
13229 function Invalid_Integer_Value return Node_Id;
13230 -- Return the invalid value of integer type Scal_Typ
13232 procedure Set_Invalid_Binder_Values;
13233 -- Set the contents of collection Invalid_Binder_Values
13235 --------------------------
13236 -- Invalid_Binder_Value --
13237 --------------------------
13239 function Invalid_Binder_Value return Node_Id is
13240 Val_Id : Entity_Id;
13243 -- Initialize the collection of invalid binder values the first time
13246 Set_Invalid_Binder_Values;
13248 -- Obtain the corresponding variable from System.Scalar_Values which
13249 -- holds the invalid value for this type.
13251 Val_Id := Invalid_Binder_Values (Scal_Typ);
13252 pragma Assert (Present (Val_Id));
13254 return New_Occurrence_Of (Val_Id, Loc);
13255 end Invalid_Binder_Value;
13257 -------------------------
13258 -- Invalid_Float_Value --
13259 -------------------------
13261 function Invalid_Float_Value return Node_Id is
13262 Value : constant Ureal := Invalid_Floats (Scal_Typ);
13265 -- Pragma Invalid_Scalars did not specify an invalid value for this
13266 -- type. Fall back to the value provided by the binder.
13268 if Value = No_Ureal then
13269 return Invalid_Binder_Value;
13271 return Make_Real_Literal (Loc, Realval => Value);
13273 end Invalid_Float_Value;
13275 ---------------------------
13276 -- Invalid_Integer_Value --
13277 ---------------------------
13279 function Invalid_Integer_Value return Node_Id is
13280 Value : constant Uint := Invalid_Integers (Scal_Typ);
13283 -- Pragma Invalid_Scalars did not specify an invalid value for this
13284 -- type. Fall back to the value provided by the binder.
13286 if Value = No_Uint then
13287 return Invalid_Binder_Value;
13289 return Make_Integer_Literal (Loc, Intval => Value);
13291 end Invalid_Integer_Value;
13293 -------------------------------
13294 -- Set_Invalid_Binder_Values --
13295 -------------------------------
13297 procedure Set_Invalid_Binder_Values is
13299 if not Invalid_Binder_Values_Set then
13300 Invalid_Binder_Values_Set := True;
13302 -- Initialize the contents of the collection once since RTE calls
13305 Invalid_Binder_Values :=
13306 (Name_Short_Float => RTE (RE_IS_Isf),
13307 Name_Float => RTE (RE_IS_Ifl),
13308 Name_Long_Float => RTE (RE_IS_Ilf),
13309 Name_Long_Long_Float => RTE (RE_IS_Ill),
13310 Name_Signed_8 => RTE (RE_IS_Is1),
13311 Name_Signed_16 => RTE (RE_IS_Is2),
13312 Name_Signed_32 => RTE (RE_IS_Is4),
13313 Name_Signed_64 => RTE (RE_IS_Is8),
13314 Name_Unsigned_8 => RTE (RE_IS_Iu1),
13315 Name_Unsigned_16 => RTE (RE_IS_Iu2),
13316 Name_Unsigned_32 => RTE (RE_IS_Iu4),
13317 Name_Unsigned_64 => RTE (RE_IS_Iu8));
13319 end Set_Invalid_Binder_Values;
13321 -- Start of processing for Invalid_Scalar_Value
13324 if Scal_Typ in Float_Scalar_Id then
13325 return Invalid_Float_Value;
13327 else pragma Assert (Scal_Typ in Integer_Scalar_Id);
13328 return Invalid_Integer_Value;
13330 end Invalid_Scalar_Value;
13332 -----------------------------
13333 -- Is_Actual_Out_Parameter --
13334 -----------------------------
13336 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
13337 Formal : Entity_Id;
13340 Find_Actual (N, Formal, Call);
13341 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
13342 end Is_Actual_Out_Parameter;
13344 -------------------------
13345 -- Is_Actual_Parameter --
13346 -------------------------
13348 function Is_Actual_Parameter (N : Node_Id) return Boolean is
13349 PK : constant Node_Kind := Nkind (Parent (N));
13353 when N_Parameter_Association =>
13354 return N = Explicit_Actual_Parameter (Parent (N));
13356 when N_Subprogram_Call =>
13357 return Is_List_Member (N)
13359 List_Containing (N) = Parameter_Associations (Parent (N));
13364 end Is_Actual_Parameter;
13366 --------------------------------
13367 -- Is_Actual_Tagged_Parameter --
13368 --------------------------------
13370 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
13371 Formal : Entity_Id;
13374 Find_Actual (N, Formal, Call);
13375 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
13376 end Is_Actual_Tagged_Parameter;
13378 ---------------------
13379 -- Is_Aliased_View --
13380 ---------------------
13382 function Is_Aliased_View (Obj : Node_Id) return Boolean is
13386 if Is_Entity_Name (Obj) then
13393 or else (Present (Renamed_Object (E))
13394 and then Is_Aliased_View (Renamed_Object (E)))))
13396 or else ((Is_Formal (E) or else Is_Formal_Object (E))
13397 and then Is_Tagged_Type (Etype (E)))
13399 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
13401 -- Current instance of type, either directly or as rewritten
13402 -- reference to the current object.
13404 or else (Is_Entity_Name (Original_Node (Obj))
13405 and then Present (Entity (Original_Node (Obj)))
13406 and then Is_Type (Entity (Original_Node (Obj))))
13408 or else (Is_Type (E) and then E = Current_Scope)
13410 or else (Is_Incomplete_Or_Private_Type (E)
13411 and then Full_View (E) = Current_Scope)
13413 -- Ada 2012 AI05-0053: the return object of an extended return
13414 -- statement is aliased if its type is immutably limited.
13416 or else (Is_Return_Object (E)
13417 and then Is_Limited_View (Etype (E)));
13419 elsif Nkind (Obj) = N_Selected_Component then
13420 return Is_Aliased (Entity (Selector_Name (Obj)));
13422 elsif Nkind (Obj) = N_Indexed_Component then
13423 return Has_Aliased_Components (Etype (Prefix (Obj)))
13425 (Is_Access_Type (Etype (Prefix (Obj)))
13426 and then Has_Aliased_Components
13427 (Designated_Type (Etype (Prefix (Obj)))));
13429 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
13430 return Is_Tagged_Type (Etype (Obj))
13431 and then Is_Aliased_View (Expression (Obj));
13433 elsif Nkind (Obj) = N_Explicit_Dereference then
13434 return Nkind (Original_Node (Obj)) /= N_Function_Call;
13439 end Is_Aliased_View;
13441 -------------------------
13442 -- Is_Ancestor_Package --
13443 -------------------------
13445 function Is_Ancestor_Package
13447 E2 : Entity_Id) return Boolean
13453 while Present (Par) and then Par /= Standard_Standard loop
13458 Par := Scope (Par);
13462 end Is_Ancestor_Package;
13464 ----------------------
13465 -- Is_Atomic_Object --
13466 ----------------------
13468 function Is_Atomic_Object (N : Node_Id) return Boolean is
13469 function Is_Atomic_Entity (Id : Entity_Id) return Boolean;
13470 pragma Inline (Is_Atomic_Entity);
13471 -- Determine whether arbitrary entity Id is either atomic or has atomic
13474 function Is_Atomic_Prefix (Pref : Node_Id) return Boolean;
13475 -- Determine whether prefix Pref of an indexed or selected component is
13476 -- an atomic object.
13478 ----------------------
13479 -- Is_Atomic_Entity --
13480 ----------------------
13482 function Is_Atomic_Entity (Id : Entity_Id) return Boolean is
13484 return Is_Atomic (Id) or else Has_Atomic_Components (Id);
13485 end Is_Atomic_Entity;
13487 ----------------------
13488 -- Is_Atomic_Prefix --
13489 ----------------------
13491 function Is_Atomic_Prefix (Pref : Node_Id) return Boolean is
13492 Typ : constant Entity_Id := Etype (Pref);
13495 if Is_Access_Type (Typ) then
13496 return Has_Atomic_Components (Designated_Type (Typ));
13498 elsif Is_Atomic_Entity (Typ) then
13501 elsif Is_Entity_Name (Pref)
13502 and then Is_Atomic_Entity (Entity (Pref))
13506 elsif Nkind (Pref) = N_Indexed_Component then
13507 return Is_Atomic_Prefix (Prefix (Pref));
13509 elsif Nkind (Pref) = N_Selected_Component then
13511 Is_Atomic_Prefix (Prefix (Pref))
13512 or else Is_Atomic (Entity (Selector_Name (Pref)));
13516 end Is_Atomic_Prefix;
13518 -- Start of processing for Is_Atomic_Object
13521 if Is_Entity_Name (N) then
13522 return Is_Atomic_Object_Entity (Entity (N));
13524 elsif Nkind (N) = N_Indexed_Component then
13525 return Is_Atomic (Etype (N)) or else Is_Atomic_Prefix (Prefix (N));
13527 elsif Nkind (N) = N_Selected_Component then
13529 Is_Atomic (Etype (N))
13530 or else Is_Atomic_Prefix (Prefix (N))
13531 or else Is_Atomic (Entity (Selector_Name (N)));
13535 end Is_Atomic_Object;
13537 -----------------------------
13538 -- Is_Atomic_Object_Entity --
13539 -----------------------------
13541 function Is_Atomic_Object_Entity (Id : Entity_Id) return Boolean is
13545 and then (Is_Atomic (Id) or else Is_Atomic (Etype (Id)));
13546 end Is_Atomic_Object_Entity;
13548 -----------------------------
13549 -- Is_Atomic_Or_VFA_Object --
13550 -----------------------------
13552 function Is_Atomic_Or_VFA_Object (N : Node_Id) return Boolean is
13554 return Is_Atomic_Object (N)
13555 or else (Is_Object_Reference (N)
13556 and then Is_Entity_Name (N)
13557 and then (Is_Volatile_Full_Access (Entity (N))
13559 Is_Volatile_Full_Access (Etype (Entity (N)))));
13560 end Is_Atomic_Or_VFA_Object;
13562 -------------------------
13563 -- Is_Attribute_Result --
13564 -------------------------
13566 function Is_Attribute_Result (N : Node_Id) return Boolean is
13568 return Nkind (N) = N_Attribute_Reference
13569 and then Attribute_Name (N) = Name_Result;
13570 end Is_Attribute_Result;
13572 -------------------------
13573 -- Is_Attribute_Update --
13574 -------------------------
13576 function Is_Attribute_Update (N : Node_Id) return Boolean is
13578 return Nkind (N) = N_Attribute_Reference
13579 and then Attribute_Name (N) = Name_Update;
13580 end Is_Attribute_Update;
13582 ------------------------------------
13583 -- Is_Body_Or_Package_Declaration --
13584 ------------------------------------
13586 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
13588 return Is_Body (N) or else Nkind (N) = N_Package_Declaration;
13589 end Is_Body_Or_Package_Declaration;
13591 -----------------------
13592 -- Is_Bounded_String --
13593 -----------------------
13595 function Is_Bounded_String (T : Entity_Id) return Boolean is
13596 Under : constant Entity_Id := Underlying_Type (Root_Type (T));
13599 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
13600 -- Super_String, or one of the [Wide_]Wide_ versions. This will
13601 -- be True for all the Bounded_String types in instances of the
13602 -- Generic_Bounded_Length generics, and for types derived from those.
13604 return Present (Under)
13605 and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
13606 Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
13607 Is_RTE (Root_Type (Under), RO_WW_Super_String));
13608 end Is_Bounded_String;
13610 ---------------------
13611 -- Is_CCT_Instance --
13612 ---------------------
13614 function Is_CCT_Instance
13615 (Ref_Id : Entity_Id;
13616 Context_Id : Entity_Id) return Boolean
13619 pragma Assert (Ekind_In (Ref_Id, E_Protected_Type, E_Task_Type));
13621 if Is_Single_Task_Object (Context_Id) then
13622 return Scope_Within_Or_Same (Etype (Context_Id), Ref_Id);
13625 pragma Assert (Ekind_In (Context_Id, E_Entry,
13633 Is_Record_Type (Context_Id));
13634 return Scope_Within_Or_Same (Context_Id, Ref_Id);
13636 end Is_CCT_Instance;
13638 -------------------------
13639 -- Is_Child_Or_Sibling --
13640 -------------------------
13642 function Is_Child_Or_Sibling
13643 (Pack_1 : Entity_Id;
13644 Pack_2 : Entity_Id) return Boolean
13646 function Distance_From_Standard (Pack : Entity_Id) return Nat;
13647 -- Given an arbitrary package, return the number of "climbs" necessary
13648 -- to reach scope Standard_Standard.
13650 procedure Equalize_Depths
13651 (Pack : in out Entity_Id;
13652 Depth : in out Nat;
13653 Depth_To_Reach : Nat);
13654 -- Given an arbitrary package, its depth and a target depth to reach,
13655 -- climb the scope chain until the said depth is reached. The pointer
13656 -- to the package and its depth a modified during the climb.
13658 ----------------------------
13659 -- Distance_From_Standard --
13660 ----------------------------
13662 function Distance_From_Standard (Pack : Entity_Id) return Nat is
13669 while Present (Scop) and then Scop /= Standard_Standard loop
13671 Scop := Scope (Scop);
13675 end Distance_From_Standard;
13677 ---------------------
13678 -- Equalize_Depths --
13679 ---------------------
13681 procedure Equalize_Depths
13682 (Pack : in out Entity_Id;
13683 Depth : in out Nat;
13684 Depth_To_Reach : Nat)
13687 -- The package must be at a greater or equal depth
13689 if Depth < Depth_To_Reach then
13690 raise Program_Error;
13693 -- Climb the scope chain until the desired depth is reached
13695 while Present (Pack) and then Depth /= Depth_To_Reach loop
13696 Pack := Scope (Pack);
13697 Depth := Depth - 1;
13699 end Equalize_Depths;
13703 P_1 : Entity_Id := Pack_1;
13704 P_1_Child : Boolean := False;
13705 P_1_Depth : Nat := Distance_From_Standard (P_1);
13706 P_2 : Entity_Id := Pack_2;
13707 P_2_Child : Boolean := False;
13708 P_2_Depth : Nat := Distance_From_Standard (P_2);
13710 -- Start of processing for Is_Child_Or_Sibling
13714 (Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
13716 -- Both packages denote the same entity, therefore they cannot be
13717 -- children or siblings.
13722 -- One of the packages is at a deeper level than the other. Note that
13723 -- both may still come from different hierarchies.
13731 elsif P_1_Depth > P_2_Depth then
13734 Depth => P_1_Depth,
13735 Depth_To_Reach => P_2_Depth);
13744 elsif P_2_Depth > P_1_Depth then
13747 Depth => P_2_Depth,
13748 Depth_To_Reach => P_1_Depth);
13752 -- At this stage the package pointers have been elevated to the same
13753 -- depth. If the related entities are the same, then one package is a
13754 -- potential child of the other:
13758 -- X became P_1 P_2 or vice versa
13764 return Is_Child_Unit (Pack_1);
13766 else pragma Assert (P_2_Child);
13767 return Is_Child_Unit (Pack_2);
13770 -- The packages may come from the same package chain or from entirely
13771 -- different hierarcies. To determine this, climb the scope stack until
13772 -- a common root is found.
13774 -- (root) (root 1) (root 2)
13779 while Present (P_1) and then Present (P_2) loop
13781 -- The two packages may be siblings
13784 return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2);
13787 P_1 := Scope (P_1);
13788 P_2 := Scope (P_2);
13793 end Is_Child_Or_Sibling;
13795 -----------------------------
13796 -- Is_Concurrent_Interface --
13797 -----------------------------
13799 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
13801 return Is_Interface (T)
13803 (Is_Protected_Interface (T)
13804 or else Is_Synchronized_Interface (T)
13805 or else Is_Task_Interface (T));
13806 end Is_Concurrent_Interface;
13808 -----------------------
13809 -- Is_Constant_Bound --
13810 -----------------------
13812 function Is_Constant_Bound (Exp : Node_Id) return Boolean is
13814 if Compile_Time_Known_Value (Exp) then
13817 elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
13818 return Is_Constant_Object (Entity (Exp))
13819 or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
13821 elsif Nkind (Exp) in N_Binary_Op then
13822 return Is_Constant_Bound (Left_Opnd (Exp))
13823 and then Is_Constant_Bound (Right_Opnd (Exp))
13824 and then Scope (Entity (Exp)) = Standard_Standard;
13829 end Is_Constant_Bound;
13831 ---------------------------
13832 -- Is_Container_Element --
13833 ---------------------------
13835 function Is_Container_Element (Exp : Node_Id) return Boolean is
13836 Loc : constant Source_Ptr := Sloc (Exp);
13837 Pref : constant Node_Id := Prefix (Exp);
13840 -- Call to an indexing aspect
13842 Cont_Typ : Entity_Id;
13843 -- The type of the container being accessed
13845 Elem_Typ : Entity_Id;
13846 -- Its element type
13848 Indexing : Entity_Id;
13849 Is_Const : Boolean;
13850 -- Indicates that constant indexing is used, and the element is thus
13853 Ref_Typ : Entity_Id;
13854 -- The reference type returned by the indexing operation
13857 -- If C is a container, in a context that imposes the element type of
13858 -- that container, the indexing notation C (X) is rewritten as:
13860 -- Indexing (C, X).Discr.all
13862 -- where Indexing is one of the indexing aspects of the container.
13863 -- If the context does not require a reference, the construct can be
13868 -- First, verify that the construct has the proper form
13870 if not Expander_Active then
13873 elsif Nkind (Pref) /= N_Selected_Component then
13876 elsif Nkind (Prefix (Pref)) /= N_Function_Call then
13880 Call := Prefix (Pref);
13881 Ref_Typ := Etype (Call);
13884 if not Has_Implicit_Dereference (Ref_Typ)
13885 or else No (First (Parameter_Associations (Call)))
13886 or else not Is_Entity_Name (Name (Call))
13891 -- Retrieve type of container object, and its iterator aspects
13893 Cont_Typ := Etype (First (Parameter_Associations (Call)));
13894 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Constant_Indexing);
13897 if No (Indexing) then
13899 -- Container should have at least one indexing operation
13903 elsif Entity (Name (Call)) /= Entity (Indexing) then
13905 -- This may be a variable indexing operation
13907 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Variable_Indexing);
13910 or else Entity (Name (Call)) /= Entity (Indexing)
13919 Elem_Typ := Find_Value_Of_Aspect (Cont_Typ, Aspect_Iterator_Element);
13921 if No (Elem_Typ) or else Entity (Elem_Typ) /= Etype (Exp) then
13925 -- Check that the expression is not the target of an assignment, in
13926 -- which case the rewriting is not possible.
13928 if not Is_Const then
13934 while Present (Par)
13936 if Nkind (Parent (Par)) = N_Assignment_Statement
13937 and then Par = Name (Parent (Par))
13941 -- A renaming produces a reference, and the transformation
13944 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
13948 (Nkind (Parent (Par)), N_Function_Call,
13949 N_Procedure_Call_Statement,
13950 N_Entry_Call_Statement)
13952 -- Check that the element is not part of an actual for an
13953 -- in-out parameter.
13960 F := First_Formal (Entity (Name (Parent (Par))));
13961 A := First (Parameter_Associations (Parent (Par)));
13962 while Present (F) loop
13963 if A = Par and then Ekind (F) /= E_In_Parameter then
13972 -- E_In_Parameter in a call: element is not modified.
13977 Par := Parent (Par);
13982 -- The expression has the proper form and the context requires the
13983 -- element type. Retrieve the Element function of the container and
13984 -- rewrite the construct as a call to it.
13990 Op := First_Elmt (Primitive_Operations (Cont_Typ));
13991 while Present (Op) loop
13992 exit when Chars (Node (Op)) = Name_Element;
14001 Make_Function_Call (Loc,
14002 Name => New_Occurrence_Of (Node (Op), Loc),
14003 Parameter_Associations => Parameter_Associations (Call)));
14004 Analyze_And_Resolve (Exp, Entity (Elem_Typ));
14008 end Is_Container_Element;
14010 ----------------------------
14011 -- Is_Contract_Annotation --
14012 ----------------------------
14014 function Is_Contract_Annotation (Item : Node_Id) return Boolean is
14016 return Is_Package_Contract_Annotation (Item)
14018 Is_Subprogram_Contract_Annotation (Item);
14019 end Is_Contract_Annotation;
14021 --------------------------------------
14022 -- Is_Controlling_Limited_Procedure --
14023 --------------------------------------
14025 function Is_Controlling_Limited_Procedure
14026 (Proc_Nam : Entity_Id) return Boolean
14029 Param_Typ : Entity_Id := Empty;
14032 if Ekind (Proc_Nam) = E_Procedure
14033 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
14037 (First (Parameter_Specifications (Parent (Proc_Nam))));
14039 -- The formal may be an anonymous access type
14041 if Nkind (Param) = N_Access_Definition then
14042 Param_Typ := Entity (Subtype_Mark (Param));
14044 Param_Typ := Etype (Param);
14047 -- In the case where an Itype was created for a dispatchin call, the
14048 -- procedure call has been rewritten. The actual may be an access to
14049 -- interface type in which case it is the designated type that is the
14050 -- controlling type.
14052 elsif Present (Associated_Node_For_Itype (Proc_Nam))
14053 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
14055 Present (Parameter_Associations
14056 (Associated_Node_For_Itype (Proc_Nam)))
14059 Etype (First (Parameter_Associations
14060 (Associated_Node_For_Itype (Proc_Nam))));
14062 if Ekind (Param_Typ) = E_Anonymous_Access_Type then
14063 Param_Typ := Directly_Designated_Type (Param_Typ);
14067 if Present (Param_Typ) then
14069 Is_Interface (Param_Typ)
14070 and then Is_Limited_Record (Param_Typ);
14074 end Is_Controlling_Limited_Procedure;
14076 -----------------------------
14077 -- Is_CPP_Constructor_Call --
14078 -----------------------------
14080 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
14082 return Nkind (N) = N_Function_Call
14083 and then Is_CPP_Class (Etype (Etype (N)))
14084 and then Is_Constructor (Entity (Name (N)))
14085 and then Is_Imported (Entity (Name (N)));
14086 end Is_CPP_Constructor_Call;
14088 -------------------------
14089 -- Is_Current_Instance --
14090 -------------------------
14092 function Is_Current_Instance (N : Node_Id) return Boolean is
14093 Typ : constant Entity_Id := Entity (N);
14097 -- Simplest case: entity is a concurrent type and we are currently
14098 -- inside the body. This will eventually be expanded into a call to
14099 -- Self (for tasks) or _object (for protected objects).
14101 if Is_Concurrent_Type (Typ) and then In_Open_Scopes (Typ) then
14105 -- Check whether the context is a (sub)type declaration for the
14109 while Present (P) loop
14110 if Nkind_In (P, N_Full_Type_Declaration,
14111 N_Private_Type_Declaration,
14112 N_Subtype_Declaration)
14113 and then Comes_From_Source (P)
14114 and then Defining_Entity (P) = Typ
14118 -- A subtype name may appear in an aspect specification for a
14119 -- Predicate_Failure aspect, for which we do not construct a
14120 -- wrapper procedure. The subtype will be replaced by the
14121 -- expression being tested when the corresponding predicate
14122 -- check is expanded.
14124 elsif Nkind (P) = N_Aspect_Specification
14125 and then Nkind (Parent (P)) = N_Subtype_Declaration
14129 elsif Nkind (P) = N_Pragma
14130 and then Get_Pragma_Id (P) = Pragma_Predicate_Failure
14139 -- In any other context this is not a current occurrence
14142 end Is_Current_Instance;
14144 --------------------
14145 -- Is_Declaration --
14146 --------------------
14148 function Is_Declaration
14150 Body_OK : Boolean := True;
14151 Concurrent_OK : Boolean := True;
14152 Formal_OK : Boolean := True;
14153 Generic_OK : Boolean := True;
14154 Instantiation_OK : Boolean := True;
14155 Renaming_OK : Boolean := True;
14156 Stub_OK : Boolean := True;
14157 Subprogram_OK : Boolean := True;
14158 Type_OK : Boolean := True) return Boolean
14163 -- Body declarations
14165 when N_Proper_Body =>
14168 -- Concurrent type declarations
14170 when N_Protected_Type_Declaration
14171 | N_Single_Protected_Declaration
14172 | N_Single_Task_Declaration
14173 | N_Task_Type_Declaration
14175 return Concurrent_OK or Type_OK;
14177 -- Formal declarations
14179 when N_Formal_Abstract_Subprogram_Declaration
14180 | N_Formal_Concrete_Subprogram_Declaration
14181 | N_Formal_Object_Declaration
14182 | N_Formal_Package_Declaration
14183 | N_Formal_Type_Declaration
14187 -- Generic declarations
14189 when N_Generic_Package_Declaration
14190 | N_Generic_Subprogram_Declaration
14194 -- Generic instantiations
14196 when N_Function_Instantiation
14197 | N_Package_Instantiation
14198 | N_Procedure_Instantiation
14200 return Instantiation_OK;
14202 -- Generic renaming declarations
14204 when N_Generic_Renaming_Declaration =>
14205 return Generic_OK or Renaming_OK;
14207 -- Renaming declarations
14209 when N_Exception_Renaming_Declaration
14210 | N_Object_Renaming_Declaration
14211 | N_Package_Renaming_Declaration
14212 | N_Subprogram_Renaming_Declaration
14214 return Renaming_OK;
14216 -- Stub declarations
14218 when N_Body_Stub =>
14221 -- Subprogram declarations
14223 when N_Abstract_Subprogram_Declaration
14224 | N_Entry_Declaration
14225 | N_Expression_Function
14226 | N_Subprogram_Declaration
14228 return Subprogram_OK;
14230 -- Type declarations
14232 when N_Full_Type_Declaration
14233 | N_Incomplete_Type_Declaration
14234 | N_Private_Extension_Declaration
14235 | N_Private_Type_Declaration
14236 | N_Subtype_Declaration
14242 when N_Component_Declaration
14243 | N_Exception_Declaration
14244 | N_Implicit_Label_Declaration
14245 | N_Number_Declaration
14246 | N_Object_Declaration
14247 | N_Package_Declaration
14254 end Is_Declaration;
14256 --------------------------------
14257 -- Is_Declared_Within_Variant --
14258 --------------------------------
14260 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
14261 Comp_Decl : constant Node_Id := Parent (Comp);
14262 Comp_List : constant Node_Id := Parent (Comp_Decl);
14264 return Nkind (Parent (Comp_List)) = N_Variant;
14265 end Is_Declared_Within_Variant;
14267 ----------------------------------------------
14268 -- Is_Dependent_Component_Of_Mutable_Object --
14269 ----------------------------------------------
14271 function Is_Dependent_Component_Of_Mutable_Object
14272 (Object : Node_Id) return Boolean
14275 Prefix_Type : Entity_Id;
14276 P_Aliased : Boolean := False;
14279 Deref : Node_Id := Object;
14280 -- Dereference node, in something like X.all.Y(2)
14282 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
14285 -- Find the dereference node if any
14287 while Nkind_In (Deref, N_Indexed_Component,
14288 N_Selected_Component,
14291 Deref := Prefix (Deref);
14294 -- If the prefix is a qualified expression of a variable, then function
14295 -- Is_Variable will return False for that because a qualified expression
14296 -- denotes a constant view, so we need to get the name being qualified
14297 -- so we can test below whether that's a variable (or a dereference).
14299 if Nkind (Deref) = N_Qualified_Expression then
14300 Deref := Expression (Deref);
14303 -- Ada 2005: If we have a component or slice of a dereference, something
14304 -- like X.all.Y (2) and the type of X is access-to-constant, Is_Variable
14305 -- will return False, because it is indeed a constant view. But it might
14306 -- be a view of a variable object, so we want the following condition to
14307 -- be True in that case.
14309 if Is_Variable (Object)
14310 or else Is_Variable (Deref)
14311 or else (Ada_Version >= Ada_2005
14312 and then (Nkind (Deref) = N_Explicit_Dereference
14313 or else Is_Access_Type (Etype (Deref))))
14315 if Nkind (Object) = N_Selected_Component then
14317 -- If the selector is not a component, then we definitely return
14318 -- False (it could be a function selector in a prefix form call
14319 -- occurring in an iterator specification).
14321 if not Ekind_In (Entity (Selector_Name (Object)), E_Component,
14327 -- Get the original node of the prefix in case it has been
14328 -- rewritten, which can occur, for example, in qualified
14329 -- expression cases. Also, a discriminant check on a selected
14330 -- component may be expanded into a dereference when removing
14331 -- side effects, and the subtype of the original node may be
14334 P := Original_Node (Prefix (Object));
14335 Prefix_Type := Etype (P);
14337 -- If the prefix is a qualified expression, we want to look at its
14340 if Nkind (P) = N_Qualified_Expression then
14341 P := Expression (P);
14342 Prefix_Type := Etype (P);
14345 if Is_Entity_Name (P) then
14346 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
14347 Prefix_Type := Base_Type (Prefix_Type);
14350 if Is_Aliased (Entity (P)) then
14354 -- For explicit dereferences we get the access prefix so we can
14355 -- treat this similarly to implicit dereferences and examine the
14356 -- kind of the access type and its designated subtype further
14359 elsif Nkind (P) = N_Explicit_Dereference then
14361 Prefix_Type := Etype (P);
14364 -- Check for prefix being an aliased component???
14369 -- A heap object is constrained by its initial value
14371 -- Ada 2005 (AI-363): Always assume the object could be mutable in
14372 -- the dereferenced case, since the access value might denote an
14373 -- unconstrained aliased object, whereas in Ada 95 the designated
14374 -- object is guaranteed to be constrained. A worst-case assumption
14375 -- has to apply in Ada 2005 because we can't tell at compile
14376 -- time whether the object is "constrained by its initial value",
14377 -- despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
14378 -- rules (these rules are acknowledged to need fixing). We don't
14379 -- impose this more stringent checking for earlier Ada versions or
14380 -- when Relaxed_RM_Semantics applies (the latter for CodePeer's
14381 -- benefit, though it's unclear on why using -gnat95 would not be
14384 if Ada_Version < Ada_2005 or else Relaxed_RM_Semantics then
14385 if Is_Access_Type (Prefix_Type)
14386 or else Nkind (P) = N_Explicit_Dereference
14391 else pragma Assert (Ada_Version >= Ada_2005);
14392 if Is_Access_Type (Prefix_Type) then
14393 -- We need to make sure we have the base subtype, in case
14394 -- this is actually an access subtype (whose Ekind will be
14395 -- E_Access_Subtype).
14397 Prefix_Type := Etype (Prefix_Type);
14399 -- If the access type is pool-specific, and there is no
14400 -- constrained partial view of the designated type, then the
14401 -- designated object is known to be constrained. If it's a
14402 -- formal access type and the renaming is in the generic
14403 -- spec, we also treat it as pool-specific (known to be
14404 -- constrained), but assume the worst if in the generic body
14405 -- (see RM 3.3(23.3/3)).
14407 if Ekind (Prefix_Type) = E_Access_Type
14408 and then (not Is_Generic_Type (Prefix_Type)
14409 or else not In_Generic_Body (Current_Scope))
14410 and then not Object_Type_Has_Constrained_Partial_View
14411 (Typ => Designated_Type (Prefix_Type),
14412 Scop => Current_Scope)
14416 -- Otherwise (general access type, or there is a constrained
14417 -- partial view of the designated type), we need to check
14418 -- based on the designated type.
14421 Prefix_Type := Designated_Type (Prefix_Type);
14427 Original_Record_Component (Entity (Selector_Name (Object)));
14429 -- As per AI-0017, the renaming is illegal in a generic body, even
14430 -- if the subtype is indefinite (only applies to prefixes of an
14431 -- untagged formal type, see RM 3.3 (23.11/3)).
14433 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
14435 if not Is_Constrained (Prefix_Type)
14436 and then (Is_Definite_Subtype (Prefix_Type)
14438 (not Is_Tagged_Type (Prefix_Type)
14439 and then Is_Generic_Type (Prefix_Type)
14440 and then In_Generic_Body (Current_Scope)))
14442 and then (Is_Declared_Within_Variant (Comp)
14443 or else Has_Discriminant_Dependent_Constraint (Comp))
14444 and then (not P_Aliased or else Ada_Version >= Ada_2005)
14448 -- If the prefix is of an access type at this point, then we want
14449 -- to return False, rather than calling this function recursively
14450 -- on the access object (which itself might be a discriminant-
14451 -- dependent component of some other object, but that isn't
14452 -- relevant to checking the object passed to us). This avoids
14453 -- issuing wrong errors when compiling with -gnatc, where there
14454 -- can be implicit dereferences that have not been expanded.
14456 elsif Is_Access_Type (Etype (Prefix (Object))) then
14461 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
14464 elsif Nkind (Object) = N_Indexed_Component
14465 or else Nkind (Object) = N_Slice
14467 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
14469 -- A type conversion that Is_Variable is a view conversion:
14470 -- go back to the denoted object.
14472 elsif Nkind (Object) = N_Type_Conversion then
14474 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
14479 end Is_Dependent_Component_Of_Mutable_Object;
14481 ---------------------
14482 -- Is_Dereferenced --
14483 ---------------------
14485 function Is_Dereferenced (N : Node_Id) return Boolean is
14486 P : constant Node_Id := Parent (N);
14488 return Nkind_In (P, N_Selected_Component,
14489 N_Explicit_Dereference,
14490 N_Indexed_Component,
14492 and then Prefix (P) = N;
14493 end Is_Dereferenced;
14495 ----------------------
14496 -- Is_Descendant_Of --
14497 ----------------------
14499 function Is_Descendant_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
14504 pragma Assert (Nkind (T1) in N_Entity);
14505 pragma Assert (Nkind (T2) in N_Entity);
14507 T := Base_Type (T1);
14509 -- Immediate return if the types match
14514 -- Comment needed here ???
14516 elsif Ekind (T) = E_Class_Wide_Type then
14517 return Etype (T) = T2;
14525 -- Done if we found the type we are looking for
14530 -- Done if no more derivations to check
14537 -- Following test catches error cases resulting from prev errors
14539 elsif No (Etyp) then
14542 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
14545 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
14549 T := Base_Type (Etyp);
14552 end Is_Descendant_Of;
14554 ----------------------------------------
14555 -- Is_Descendant_Of_Suspension_Object --
14556 ----------------------------------------
14558 function Is_Descendant_Of_Suspension_Object
14559 (Typ : Entity_Id) return Boolean
14561 Cur_Typ : Entity_Id;
14562 Par_Typ : Entity_Id;
14565 -- Climb the type derivation chain checking each parent type against
14566 -- Suspension_Object.
14568 Cur_Typ := Base_Type (Typ);
14569 while Present (Cur_Typ) loop
14570 Par_Typ := Etype (Cur_Typ);
14572 -- The current type is a match
14574 if Is_Suspension_Object (Cur_Typ) then
14577 -- Stop the traversal once the root of the derivation chain has been
14578 -- reached. In that case the current type is its own base type.
14580 elsif Cur_Typ = Par_Typ then
14584 Cur_Typ := Base_Type (Par_Typ);
14588 end Is_Descendant_Of_Suspension_Object;
14590 ---------------------------------------------
14591 -- Is_Double_Precision_Floating_Point_Type --
14592 ---------------------------------------------
14594 function Is_Double_Precision_Floating_Point_Type
14595 (E : Entity_Id) return Boolean is
14597 return Is_Floating_Point_Type (E)
14598 and then Machine_Radix_Value (E) = Uint_2
14599 and then Machine_Mantissa_Value (E) = UI_From_Int (53)
14600 and then Machine_Emax_Value (E) = Uint_2 ** Uint_10
14601 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_10);
14602 end Is_Double_Precision_Floating_Point_Type;
14604 -----------------------------
14605 -- Is_Effectively_Volatile --
14606 -----------------------------
14608 function Is_Effectively_Volatile (Id : Entity_Id) return Boolean is
14610 if Is_Type (Id) then
14612 -- An arbitrary type is effectively volatile when it is subject to
14613 -- pragma Atomic or Volatile.
14615 if Is_Volatile (Id) then
14618 -- An array type is effectively volatile when it is subject to pragma
14619 -- Atomic_Components or Volatile_Components or its component type is
14620 -- effectively volatile.
14622 elsif Is_Array_Type (Id) then
14624 Anc : Entity_Id := Base_Type (Id);
14626 if Is_Private_Type (Anc) then
14627 Anc := Full_View (Anc);
14630 -- Test for presence of ancestor, as the full view of a private
14631 -- type may be missing in case of error.
14634 Has_Volatile_Components (Id)
14637 and then Is_Effectively_Volatile (Component_Type (Anc)));
14640 -- A protected type is always volatile
14642 elsif Is_Protected_Type (Id) then
14645 -- A descendant of Ada.Synchronous_Task_Control.Suspension_Object is
14646 -- automatically volatile.
14648 elsif Is_Descendant_Of_Suspension_Object (Id) then
14651 -- Otherwise the type is not effectively volatile
14657 -- Otherwise Id denotes an object
14660 -- A volatile object for which No_Caching is enabled is not
14661 -- effectively volatile.
14664 (Is_Volatile (Id) and then not No_Caching_Enabled (Id))
14665 or else Has_Volatile_Components (Id)
14666 or else Is_Effectively_Volatile (Etype (Id));
14668 end Is_Effectively_Volatile;
14670 ------------------------------------
14671 -- Is_Effectively_Volatile_Object --
14672 ------------------------------------
14674 function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean is
14676 if Is_Entity_Name (N) then
14677 return Is_Effectively_Volatile (Entity (N));
14679 elsif Nkind (N) = N_Indexed_Component then
14680 return Is_Effectively_Volatile_Object (Prefix (N));
14682 elsif Nkind (N) = N_Selected_Component then
14684 Is_Effectively_Volatile_Object (Prefix (N))
14686 Is_Effectively_Volatile_Object (Selector_Name (N));
14691 end Is_Effectively_Volatile_Object;
14693 -------------------
14694 -- Is_Entry_Body --
14695 -------------------
14697 function Is_Entry_Body (Id : Entity_Id) return Boolean is
14700 Ekind_In (Id, E_Entry, E_Entry_Family)
14701 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Body;
14704 --------------------------
14705 -- Is_Entry_Declaration --
14706 --------------------------
14708 function Is_Entry_Declaration (Id : Entity_Id) return Boolean is
14711 Ekind_In (Id, E_Entry, E_Entry_Family)
14712 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Declaration;
14713 end Is_Entry_Declaration;
14715 ------------------------------------
14716 -- Is_Expanded_Priority_Attribute --
14717 ------------------------------------
14719 function Is_Expanded_Priority_Attribute (E : Entity_Id) return Boolean is
14722 Nkind (E) = N_Function_Call
14723 and then not Configurable_Run_Time_Mode
14724 and then Nkind (Original_Node (E)) = N_Attribute_Reference
14725 and then (Entity (Name (E)) = RTE (RE_Get_Ceiling)
14726 or else Entity (Name (E)) = RTE (RO_PE_Get_Ceiling));
14727 end Is_Expanded_Priority_Attribute;
14729 ----------------------------
14730 -- Is_Expression_Function --
14731 ----------------------------
14733 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
14735 if Ekind_In (Subp, E_Function, E_Subprogram_Body) then
14737 Nkind (Original_Node (Unit_Declaration_Node (Subp))) =
14738 N_Expression_Function;
14742 end Is_Expression_Function;
14744 ------------------------------------------
14745 -- Is_Expression_Function_Or_Completion --
14746 ------------------------------------------
14748 function Is_Expression_Function_Or_Completion
14749 (Subp : Entity_Id) return Boolean
14751 Subp_Decl : Node_Id;
14754 if Ekind (Subp) = E_Function then
14755 Subp_Decl := Unit_Declaration_Node (Subp);
14757 -- The function declaration is either an expression function or is
14758 -- completed by an expression function body.
14761 Is_Expression_Function (Subp)
14762 or else (Nkind (Subp_Decl) = N_Subprogram_Declaration
14763 and then Present (Corresponding_Body (Subp_Decl))
14764 and then Is_Expression_Function
14765 (Corresponding_Body (Subp_Decl)));
14767 elsif Ekind (Subp) = E_Subprogram_Body then
14768 return Is_Expression_Function (Subp);
14773 end Is_Expression_Function_Or_Completion;
14775 -----------------------
14776 -- Is_EVF_Expression --
14777 -----------------------
14779 function Is_EVF_Expression (N : Node_Id) return Boolean is
14780 Orig_N : constant Node_Id := Original_Node (N);
14786 -- Detect a reference to a formal parameter of a specific tagged type
14787 -- whose related subprogram is subject to pragma Expresions_Visible with
14790 if Is_Entity_Name (N) and then Present (Entity (N)) then
14795 and then Is_Specific_Tagged_Type (Etype (Id))
14796 and then Extensions_Visible_Status (Id) =
14797 Extensions_Visible_False;
14799 -- A case expression is an EVF expression when it contains at least one
14800 -- EVF dependent_expression. Note that a case expression may have been
14801 -- expanded, hence the use of Original_Node.
14803 elsif Nkind (Orig_N) = N_Case_Expression then
14804 Alt := First (Alternatives (Orig_N));
14805 while Present (Alt) loop
14806 if Is_EVF_Expression (Expression (Alt)) then
14813 -- An if expression is an EVF expression when it contains at least one
14814 -- EVF dependent_expression. Note that an if expression may have been
14815 -- expanded, hence the use of Original_Node.
14817 elsif Nkind (Orig_N) = N_If_Expression then
14818 Expr := Next (First (Expressions (Orig_N)));
14819 while Present (Expr) loop
14820 if Is_EVF_Expression (Expr) then
14827 -- A qualified expression or a type conversion is an EVF expression when
14828 -- its operand is an EVF expression.
14830 elsif Nkind_In (N, N_Qualified_Expression,
14831 N_Unchecked_Type_Conversion,
14834 return Is_EVF_Expression (Expression (N));
14836 -- Attributes 'Loop_Entry, 'Old, and 'Update are EVF expressions when
14837 -- their prefix denotes an EVF expression.
14839 elsif Nkind (N) = N_Attribute_Reference
14840 and then Nam_In (Attribute_Name (N), Name_Loop_Entry,
14844 return Is_EVF_Expression (Prefix (N));
14848 end Is_EVF_Expression;
14854 function Is_False (U : Uint) return Boolean is
14859 ---------------------------
14860 -- Is_Fixed_Model_Number --
14861 ---------------------------
14863 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
14864 S : constant Ureal := Small_Value (T);
14865 M : Urealp.Save_Mark;
14870 R := (U = UR_Trunc (U / S) * S);
14871 Urealp.Release (M);
14873 end Is_Fixed_Model_Number;
14875 -------------------------------
14876 -- Is_Fully_Initialized_Type --
14877 -------------------------------
14879 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
14883 if Is_Scalar_Type (Typ) then
14885 -- A scalar type with an aspect Default_Value is fully initialized
14887 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
14888 -- of a scalar type, but we don't take that into account here, since
14889 -- we don't want these to affect warnings.
14891 return Has_Default_Aspect (Typ);
14893 elsif Is_Access_Type (Typ) then
14896 elsif Is_Array_Type (Typ) then
14897 if Is_Fully_Initialized_Type (Component_Type (Typ))
14898 or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
14903 -- An interesting case, if we have a constrained type one of whose
14904 -- bounds is known to be null, then there are no elements to be
14905 -- initialized, so all the elements are initialized.
14907 if Is_Constrained (Typ) then
14910 Indx_Typ : Entity_Id;
14911 Lbd, Hbd : Node_Id;
14914 Indx := First_Index (Typ);
14915 while Present (Indx) loop
14916 if Etype (Indx) = Any_Type then
14919 -- If index is a range, use directly
14921 elsif Nkind (Indx) = N_Range then
14922 Lbd := Low_Bound (Indx);
14923 Hbd := High_Bound (Indx);
14926 Indx_Typ := Etype (Indx);
14928 if Is_Private_Type (Indx_Typ) then
14929 Indx_Typ := Full_View (Indx_Typ);
14932 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
14935 Lbd := Type_Low_Bound (Indx_Typ);
14936 Hbd := Type_High_Bound (Indx_Typ);
14940 if Compile_Time_Known_Value (Lbd)
14942 Compile_Time_Known_Value (Hbd)
14944 if Expr_Value (Hbd) < Expr_Value (Lbd) then
14954 -- If no null indexes, then type is not fully initialized
14960 elsif Is_Record_Type (Typ) then
14961 if Has_Discriminants (Typ)
14963 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
14964 and then Is_Fully_Initialized_Variant (Typ)
14969 -- We consider bounded string types to be fully initialized, because
14970 -- otherwise we get false alarms when the Data component is not
14971 -- default-initialized.
14973 if Is_Bounded_String (Typ) then
14977 -- Controlled records are considered to be fully initialized if
14978 -- there is a user defined Initialize routine. This may not be
14979 -- entirely correct, but as the spec notes, we are guessing here
14980 -- what is best from the point of view of issuing warnings.
14982 if Is_Controlled (Typ) then
14984 Utyp : constant Entity_Id := Underlying_Type (Typ);
14987 if Present (Utyp) then
14989 Init : constant Entity_Id :=
14990 (Find_Optional_Prim_Op
14991 (Underlying_Type (Typ), Name_Initialize));
14995 and then Comes_From_Source (Init)
14996 and then not In_Predefined_Unit (Init)
15000 elsif Has_Null_Extension (Typ)
15002 Is_Fully_Initialized_Type
15003 (Etype (Base_Type (Typ)))
15012 -- Otherwise see if all record components are initialized
15018 Ent := First_Entity (Typ);
15019 while Present (Ent) loop
15020 if Ekind (Ent) = E_Component
15021 and then (No (Parent (Ent))
15022 or else No (Expression (Parent (Ent))))
15023 and then not Is_Fully_Initialized_Type (Etype (Ent))
15025 -- Special VM case for tag components, which need to be
15026 -- defined in this case, but are never initialized as VMs
15027 -- are using other dispatching mechanisms. Ignore this
15028 -- uninitialized case. Note that this applies both to the
15029 -- uTag entry and the main vtable pointer (CPP_Class case).
15031 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
15040 -- No uninitialized components, so type is fully initialized.
15041 -- Note that this catches the case of no components as well.
15045 elsif Is_Concurrent_Type (Typ) then
15048 elsif Is_Private_Type (Typ) then
15050 U : constant Entity_Id := Underlying_Type (Typ);
15056 return Is_Fully_Initialized_Type (U);
15063 end Is_Fully_Initialized_Type;
15065 ----------------------------------
15066 -- Is_Fully_Initialized_Variant --
15067 ----------------------------------
15069 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
15070 Loc : constant Source_Ptr := Sloc (Typ);
15071 Constraints : constant List_Id := New_List;
15072 Components : constant Elist_Id := New_Elmt_List;
15073 Comp_Elmt : Elmt_Id;
15075 Comp_List : Node_Id;
15077 Discr_Val : Node_Id;
15079 Report_Errors : Boolean;
15080 pragma Warnings (Off, Report_Errors);
15083 if Serious_Errors_Detected > 0 then
15087 if Is_Record_Type (Typ)
15088 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
15089 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
15091 Comp_List := Component_List (Type_Definition (Parent (Typ)));
15093 Discr := First_Discriminant (Typ);
15094 while Present (Discr) loop
15095 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
15096 Discr_Val := Expression (Parent (Discr));
15098 if Present (Discr_Val)
15099 and then Is_OK_Static_Expression (Discr_Val)
15101 Append_To (Constraints,
15102 Make_Component_Association (Loc,
15103 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
15104 Expression => New_Copy (Discr_Val)));
15112 Next_Discriminant (Discr);
15117 Comp_List => Comp_List,
15118 Governed_By => Constraints,
15119 Into => Components,
15120 Report_Errors => Report_Errors);
15122 -- Check that each component present is fully initialized
15124 Comp_Elmt := First_Elmt (Components);
15125 while Present (Comp_Elmt) loop
15126 Comp_Id := Node (Comp_Elmt);
15128 if Ekind (Comp_Id) = E_Component
15129 and then (No (Parent (Comp_Id))
15130 or else No (Expression (Parent (Comp_Id))))
15131 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
15136 Next_Elmt (Comp_Elmt);
15141 elsif Is_Private_Type (Typ) then
15143 U : constant Entity_Id := Underlying_Type (Typ);
15149 return Is_Fully_Initialized_Variant (U);
15156 end Is_Fully_Initialized_Variant;
15158 ------------------------------------
15159 -- Is_Generic_Declaration_Or_Body --
15160 ------------------------------------
15162 function Is_Generic_Declaration_Or_Body (Decl : Node_Id) return Boolean is
15163 Spec_Decl : Node_Id;
15166 -- Package/subprogram body
15168 if Nkind_In (Decl, N_Package_Body, N_Subprogram_Body)
15169 and then Present (Corresponding_Spec (Decl))
15171 Spec_Decl := Unit_Declaration_Node (Corresponding_Spec (Decl));
15173 -- Package/subprogram body stub
15175 elsif Nkind_In (Decl, N_Package_Body_Stub, N_Subprogram_Body_Stub)
15176 and then Present (Corresponding_Spec_Of_Stub (Decl))
15179 Unit_Declaration_Node (Corresponding_Spec_Of_Stub (Decl));
15187 -- Rather than inspecting the defining entity of the spec declaration,
15188 -- look at its Nkind. This takes care of the case where the analysis of
15189 -- a generic body modifies the Ekind of its spec to allow for recursive
15193 Nkind_In (Spec_Decl, N_Generic_Package_Declaration,
15194 N_Generic_Subprogram_Declaration);
15195 end Is_Generic_Declaration_Or_Body;
15197 ----------------------------
15198 -- Is_Inherited_Operation --
15199 ----------------------------
15201 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
15202 pragma Assert (Is_Overloadable (E));
15203 Kind : constant Node_Kind := Nkind (Parent (E));
15205 return Kind = N_Full_Type_Declaration
15206 or else Kind = N_Private_Extension_Declaration
15207 or else Kind = N_Subtype_Declaration
15208 or else (Ekind (E) = E_Enumeration_Literal
15209 and then Is_Derived_Type (Etype (E)));
15210 end Is_Inherited_Operation;
15212 -------------------------------------
15213 -- Is_Inherited_Operation_For_Type --
15214 -------------------------------------
15216 function Is_Inherited_Operation_For_Type
15218 Typ : Entity_Id) return Boolean
15221 -- Check that the operation has been created by the type declaration
15223 return Is_Inherited_Operation (E)
15224 and then Defining_Identifier (Parent (E)) = Typ;
15225 end Is_Inherited_Operation_For_Type;
15227 --------------------------------------
15228 -- Is_Inlinable_Expression_Function --
15229 --------------------------------------
15231 function Is_Inlinable_Expression_Function
15232 (Subp : Entity_Id) return Boolean
15234 Return_Expr : Node_Id;
15237 if Is_Expression_Function_Or_Completion (Subp)
15238 and then Has_Pragma_Inline_Always (Subp)
15239 and then Needs_No_Actuals (Subp)
15240 and then No (Contract (Subp))
15241 and then not Is_Dispatching_Operation (Subp)
15242 and then Needs_Finalization (Etype (Subp))
15243 and then not Is_Class_Wide_Type (Etype (Subp))
15244 and then not (Has_Invariants (Etype (Subp)))
15245 and then Present (Subprogram_Body (Subp))
15246 and then Was_Expression_Function (Subprogram_Body (Subp))
15248 Return_Expr := Expression_Of_Expression_Function (Subp);
15250 -- The returned object must not have a qualified expression and its
15251 -- nominal subtype must be statically compatible with the result
15252 -- subtype of the expression function.
15255 Nkind (Return_Expr) = N_Identifier
15256 and then Etype (Return_Expr) = Etype (Subp);
15260 end Is_Inlinable_Expression_Function;
15266 function Is_Iterator (Typ : Entity_Id) return Boolean is
15267 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean;
15268 -- Determine whether type Iter_Typ is a predefined forward or reversible
15271 ----------------------
15272 -- Denotes_Iterator --
15273 ----------------------
15275 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean is
15277 -- Check that the name matches, and that the ultimate ancestor is in
15278 -- a predefined unit, i.e the one that declares iterator interfaces.
15281 Nam_In (Chars (Iter_Typ), Name_Forward_Iterator,
15282 Name_Reversible_Iterator)
15283 and then In_Predefined_Unit (Root_Type (Iter_Typ));
15284 end Denotes_Iterator;
15288 Iface_Elmt : Elmt_Id;
15291 -- Start of processing for Is_Iterator
15294 -- The type may be a subtype of a descendant of the proper instance of
15295 -- the predefined interface type, so we must use the root type of the
15296 -- given type. The same is done for Is_Reversible_Iterator.
15298 if Is_Class_Wide_Type (Typ)
15299 and then Denotes_Iterator (Root_Type (Typ))
15303 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
15306 elsif Present (Find_Value_Of_Aspect (Typ, Aspect_Iterable)) then
15310 Collect_Interfaces (Typ, Ifaces);
15312 Iface_Elmt := First_Elmt (Ifaces);
15313 while Present (Iface_Elmt) loop
15314 if Denotes_Iterator (Node (Iface_Elmt)) then
15318 Next_Elmt (Iface_Elmt);
15325 ----------------------------
15326 -- Is_Iterator_Over_Array --
15327 ----------------------------
15329 function Is_Iterator_Over_Array (N : Node_Id) return Boolean is
15330 Container : constant Node_Id := Name (N);
15331 Container_Typ : constant Entity_Id := Base_Type (Etype (Container));
15333 return Is_Array_Type (Container_Typ);
15334 end Is_Iterator_Over_Array;
15340 -- We seem to have a lot of overlapping functions that do similar things
15341 -- (testing for left hand sides or lvalues???).
15343 function Is_LHS (N : Node_Id) return Is_LHS_Result is
15344 P : constant Node_Id := Parent (N);
15347 -- Return True if we are the left hand side of an assignment statement
15349 if Nkind (P) = N_Assignment_Statement then
15350 if Name (P) = N then
15356 -- Case of prefix of indexed or selected component or slice
15358 elsif Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
15359 and then N = Prefix (P)
15361 -- Here we have the case where the parent P is N.Q or N(Q .. R).
15362 -- If P is an LHS, then N is also effectively an LHS, but there
15363 -- is an important exception. If N is of an access type, then
15364 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
15365 -- case this makes N.all a left hand side but not N itself.
15367 -- If we don't know the type yet, this is the case where we return
15368 -- Unknown, since the answer depends on the type which is unknown.
15370 if No (Etype (N)) then
15373 -- We have an Etype set, so we can check it
15375 elsif Is_Access_Type (Etype (N)) then
15378 -- OK, not access type case, so just test whole expression
15384 -- All other cases are not left hand sides
15391 -----------------------------
15392 -- Is_Library_Level_Entity --
15393 -----------------------------
15395 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
15397 -- The following is a small optimization, and it also properly handles
15398 -- discriminals, which in task bodies might appear in expressions before
15399 -- the corresponding procedure has been created, and which therefore do
15400 -- not have an assigned scope.
15402 if Is_Formal (E) then
15406 -- Normal test is simply that the enclosing dynamic scope is Standard
15408 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
15409 end Is_Library_Level_Entity;
15411 --------------------------------
15412 -- Is_Limited_Class_Wide_Type --
15413 --------------------------------
15415 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
15418 Is_Class_Wide_Type (Typ)
15419 and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
15420 end Is_Limited_Class_Wide_Type;
15422 ---------------------------------
15423 -- Is_Local_Variable_Reference --
15424 ---------------------------------
15426 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
15428 if not Is_Entity_Name (Expr) then
15433 Ent : constant Entity_Id := Entity (Expr);
15434 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
15436 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
15439 return Present (Sub) and then Sub = Current_Subprogram;
15443 end Is_Local_Variable_Reference;
15445 -----------------------
15446 -- Is_Name_Reference --
15447 -----------------------
15449 function Is_Name_Reference (N : Node_Id) return Boolean is
15451 if Is_Entity_Name (N) then
15452 return Present (Entity (N)) and then Is_Object (Entity (N));
15456 when N_Indexed_Component
15460 Is_Name_Reference (Prefix (N))
15461 or else Is_Access_Type (Etype (Prefix (N)));
15463 -- Attributes 'Input, 'Old and 'Result produce objects
15465 when N_Attribute_Reference =>
15467 Nam_In (Attribute_Name (N), Name_Input, Name_Old, Name_Result);
15469 when N_Selected_Component =>
15471 Is_Name_Reference (Selector_Name (N))
15473 (Is_Name_Reference (Prefix (N))
15474 or else Is_Access_Type (Etype (Prefix (N))));
15476 when N_Explicit_Dereference =>
15479 -- A view conversion of a tagged name is a name reference
15481 when N_Type_Conversion =>
15483 Is_Tagged_Type (Etype (Subtype_Mark (N)))
15484 and then Is_Tagged_Type (Etype (Expression (N)))
15485 and then Is_Name_Reference (Expression (N));
15487 -- An unchecked type conversion is considered to be a name if the
15488 -- operand is a name (this construction arises only as a result of
15489 -- expansion activities).
15491 when N_Unchecked_Type_Conversion =>
15492 return Is_Name_Reference (Expression (N));
15497 end Is_Name_Reference;
15499 ------------------------------------
15500 -- Is_Non_Preelaborable_Construct --
15501 ------------------------------------
15503 function Is_Non_Preelaborable_Construct (N : Node_Id) return Boolean is
15505 -- NOTE: the routines within Is_Non_Preelaborable_Construct are
15506 -- intentionally unnested to avoid deep indentation of code.
15508 Non_Preelaborable : exception;
15509 -- This exception is raised when the construct violates preelaborability
15510 -- to terminate the recursion.
15512 procedure Visit (Nod : Node_Id);
15513 -- Semantically inspect construct Nod to determine whether it violates
15514 -- preelaborability. This routine raises Non_Preelaborable.
15516 procedure Visit_List (List : List_Id);
15517 pragma Inline (Visit_List);
15518 -- Invoke Visit on each element of list List. This routine raises
15519 -- Non_Preelaborable.
15521 procedure Visit_Pragma (Prag : Node_Id);
15522 pragma Inline (Visit_Pragma);
15523 -- Semantically inspect pragma Prag to determine whether it violates
15524 -- preelaborability. This routine raises Non_Preelaborable.
15526 procedure Visit_Subexpression (Expr : Node_Id);
15527 pragma Inline (Visit_Subexpression);
15528 -- Semantically inspect expression Expr to determine whether it violates
15529 -- preelaborability. This routine raises Non_Preelaborable.
15535 procedure Visit (Nod : Node_Id) is
15537 case Nkind (Nod) is
15541 when N_Component_Declaration =>
15543 -- Defining_Identifier is left out because it is not relevant
15544 -- for preelaborability.
15546 Visit (Component_Definition (Nod));
15547 Visit (Expression (Nod));
15549 when N_Derived_Type_Definition =>
15551 -- Interface_List is left out because it is not relevant for
15552 -- preelaborability.
15554 Visit (Record_Extension_Part (Nod));
15555 Visit (Subtype_Indication (Nod));
15557 when N_Entry_Declaration =>
15559 -- A protected type with at leat one entry is not preelaborable
15560 -- while task types are never preelaborable. This renders entry
15561 -- declarations non-preelaborable.
15563 raise Non_Preelaborable;
15565 when N_Full_Type_Declaration =>
15567 -- Defining_Identifier and Discriminant_Specifications are left
15568 -- out because they are not relevant for preelaborability.
15570 Visit (Type_Definition (Nod));
15572 when N_Function_Instantiation
15573 | N_Package_Instantiation
15574 | N_Procedure_Instantiation
15576 -- Defining_Unit_Name and Name are left out because they are
15577 -- not relevant for preelaborability.
15579 Visit_List (Generic_Associations (Nod));
15581 when N_Object_Declaration =>
15583 -- Defining_Identifier is left out because it is not relevant
15584 -- for preelaborability.
15586 Visit (Object_Definition (Nod));
15588 if Has_Init_Expression (Nod) then
15589 Visit (Expression (Nod));
15591 elsif not Has_Preelaborable_Initialization
15592 (Etype (Defining_Entity (Nod)))
15594 raise Non_Preelaborable;
15597 when N_Private_Extension_Declaration
15598 | N_Subtype_Declaration
15600 -- Defining_Identifier, Discriminant_Specifications, and
15601 -- Interface_List are left out because they are not relevant
15602 -- for preelaborability.
15604 Visit (Subtype_Indication (Nod));
15606 when N_Protected_Type_Declaration
15607 | N_Single_Protected_Declaration
15609 -- Defining_Identifier, Discriminant_Specifications, and
15610 -- Interface_List are left out because they are not relevant
15611 -- for preelaborability.
15613 Visit (Protected_Definition (Nod));
15615 -- A [single] task type is never preelaborable
15617 when N_Single_Task_Declaration
15618 | N_Task_Type_Declaration
15620 raise Non_Preelaborable;
15625 Visit_Pragma (Nod);
15629 when N_Statement_Other_Than_Procedure_Call =>
15630 if Nkind (Nod) /= N_Null_Statement then
15631 raise Non_Preelaborable;
15637 Visit_Subexpression (Nod);
15641 when N_Access_To_Object_Definition =>
15642 Visit (Subtype_Indication (Nod));
15644 when N_Case_Expression_Alternative =>
15645 Visit (Expression (Nod));
15646 Visit_List (Discrete_Choices (Nod));
15648 when N_Component_Definition =>
15649 Visit (Access_Definition (Nod));
15650 Visit (Subtype_Indication (Nod));
15652 when N_Component_List =>
15653 Visit_List (Component_Items (Nod));
15654 Visit (Variant_Part (Nod));
15656 when N_Constrained_Array_Definition =>
15657 Visit_List (Discrete_Subtype_Definitions (Nod));
15658 Visit (Component_Definition (Nod));
15660 when N_Delta_Constraint
15661 | N_Digits_Constraint
15663 -- Delta_Expression and Digits_Expression are left out because
15664 -- they are not relevant for preelaborability.
15666 Visit (Range_Constraint (Nod));
15668 when N_Discriminant_Specification =>
15670 -- Defining_Identifier and Expression are left out because they
15671 -- are not relevant for preelaborability.
15673 Visit (Discriminant_Type (Nod));
15675 when N_Generic_Association =>
15677 -- Selector_Name is left out because it is not relevant for
15678 -- preelaborability.
15680 Visit (Explicit_Generic_Actual_Parameter (Nod));
15682 when N_Index_Or_Discriminant_Constraint =>
15683 Visit_List (Constraints (Nod));
15685 when N_Iterator_Specification =>
15687 -- Defining_Identifier is left out because it is not relevant
15688 -- for preelaborability.
15690 Visit (Name (Nod));
15691 Visit (Subtype_Indication (Nod));
15693 when N_Loop_Parameter_Specification =>
15695 -- Defining_Identifier is left out because it is not relevant
15696 -- for preelaborability.
15698 Visit (Discrete_Subtype_Definition (Nod));
15700 when N_Protected_Definition =>
15702 -- End_Label is left out because it is not relevant for
15703 -- preelaborability.
15705 Visit_List (Private_Declarations (Nod));
15706 Visit_List (Visible_Declarations (Nod));
15708 when N_Range_Constraint =>
15709 Visit (Range_Expression (Nod));
15711 when N_Record_Definition
15714 -- End_Label, Discrete_Choices, and Interface_List are left out
15715 -- because they are not relevant for preelaborability.
15717 Visit (Component_List (Nod));
15719 when N_Subtype_Indication =>
15721 -- Subtype_Mark is left out because it is not relevant for
15722 -- preelaborability.
15724 Visit (Constraint (Nod));
15726 when N_Unconstrained_Array_Definition =>
15728 -- Subtype_Marks is left out because it is not relevant for
15729 -- preelaborability.
15731 Visit (Component_Definition (Nod));
15733 when N_Variant_Part =>
15735 -- Name is left out because it is not relevant for
15736 -- preelaborability.
15738 Visit_List (Variants (Nod));
15751 procedure Visit_List (List : List_Id) is
15755 if Present (List) then
15756 Nod := First (List);
15757 while Present (Nod) loop
15768 procedure Visit_Pragma (Prag : Node_Id) is
15770 case Get_Pragma_Id (Prag) is
15772 | Pragma_Assert_And_Cut
15774 | Pragma_Async_Readers
15775 | Pragma_Async_Writers
15776 | Pragma_Attribute_Definition
15778 | Pragma_Constant_After_Elaboration
15780 | Pragma_Deadline_Floor
15781 | Pragma_Dispatching_Domain
15782 | Pragma_Effective_Reads
15783 | Pragma_Effective_Writes
15784 | Pragma_Extensions_Visible
15786 | Pragma_Secondary_Stack_Size
15788 | Pragma_Volatile_Function
15790 Visit_List (Pragma_Argument_Associations (Prag));
15799 -------------------------
15800 -- Visit_Subexpression --
15801 -------------------------
15803 procedure Visit_Subexpression (Expr : Node_Id) is
15804 procedure Visit_Aggregate (Aggr : Node_Id);
15805 pragma Inline (Visit_Aggregate);
15806 -- Semantically inspect aggregate Aggr to determine whether it
15807 -- violates preelaborability.
15809 ---------------------
15810 -- Visit_Aggregate --
15811 ---------------------
15813 procedure Visit_Aggregate (Aggr : Node_Id) is
15815 if not Is_Preelaborable_Aggregate (Aggr) then
15816 raise Non_Preelaborable;
15818 end Visit_Aggregate;
15820 -- Start of processing for Visit_Subexpression
15823 case Nkind (Expr) is
15825 | N_Qualified_Expression
15826 | N_Type_Conversion
15827 | N_Unchecked_Expression
15828 | N_Unchecked_Type_Conversion
15830 -- Subpool_Handle_Name and Subtype_Mark are left out because
15831 -- they are not relevant for preelaborability.
15833 Visit (Expression (Expr));
15836 | N_Extension_Aggregate
15838 Visit_Aggregate (Expr);
15840 when N_Attribute_Reference
15841 | N_Explicit_Dereference
15844 -- Attribute_Name and Expressions are left out because they are
15845 -- not relevant for preelaborability.
15847 Visit (Prefix (Expr));
15849 when N_Case_Expression =>
15851 -- End_Span is left out because it is not relevant for
15852 -- preelaborability.
15854 Visit_List (Alternatives (Expr));
15855 Visit (Expression (Expr));
15857 when N_Delta_Aggregate =>
15858 Visit_Aggregate (Expr);
15859 Visit (Expression (Expr));
15861 when N_Expression_With_Actions =>
15862 Visit_List (Actions (Expr));
15863 Visit (Expression (Expr));
15865 when N_If_Expression =>
15866 Visit_List (Expressions (Expr));
15868 when N_Quantified_Expression =>
15869 Visit (Condition (Expr));
15870 Visit (Iterator_Specification (Expr));
15871 Visit (Loop_Parameter_Specification (Expr));
15874 Visit (High_Bound (Expr));
15875 Visit (Low_Bound (Expr));
15878 Visit (Discrete_Range (Expr));
15879 Visit (Prefix (Expr));
15885 -- The evaluation of an object name is not preelaborable,
15886 -- unless the name is a static expression (checked further
15887 -- below), or statically denotes a discriminant.
15889 if Is_Entity_Name (Expr) then
15890 Object_Name : declare
15891 Id : constant Entity_Id := Entity (Expr);
15894 if Is_Object (Id) then
15895 if Ekind (Id) = E_Discriminant then
15898 elsif Ekind_In (Id, E_Constant, E_In_Parameter)
15899 and then Present (Discriminal_Link (Id))
15904 raise Non_Preelaborable;
15909 -- A non-static expression is not preelaborable
15911 elsif not Is_OK_Static_Expression (Expr) then
15912 raise Non_Preelaborable;
15915 end Visit_Subexpression;
15917 -- Start of processing for Is_Non_Preelaborable_Construct
15922 -- At this point it is known that the construct is preelaborable
15928 -- The elaboration of the construct performs an action which violates
15929 -- preelaborability.
15931 when Non_Preelaborable =>
15933 end Is_Non_Preelaborable_Construct;
15935 ---------------------------------
15936 -- Is_Nontrivial_DIC_Procedure --
15937 ---------------------------------
15939 function Is_Nontrivial_DIC_Procedure (Id : Entity_Id) return Boolean is
15940 Body_Decl : Node_Id;
15944 if Ekind (Id) = E_Procedure and then Is_DIC_Procedure (Id) then
15946 Unit_Declaration_Node
15947 (Corresponding_Body (Unit_Declaration_Node (Id)));
15949 -- The body of the Default_Initial_Condition procedure must contain
15950 -- at least one statement, otherwise the generation of the subprogram
15953 pragma Assert (Present (Handled_Statement_Sequence (Body_Decl)));
15955 -- To qualify as nontrivial, the first statement of the procedure
15956 -- must be a check in the form of an if statement. If the original
15957 -- Default_Initial_Condition expression was folded, then the first
15958 -- statement is not a check.
15960 Stmt := First (Statements (Handled_Statement_Sequence (Body_Decl)));
15963 Nkind (Stmt) = N_If_Statement
15964 and then Nkind (Original_Node (Stmt)) = N_Pragma;
15968 end Is_Nontrivial_DIC_Procedure;
15970 -------------------------
15971 -- Is_Null_Record_Type --
15972 -------------------------
15974 function Is_Null_Record_Type (T : Entity_Id) return Boolean is
15975 Decl : constant Node_Id := Parent (T);
15977 return Nkind (Decl) = N_Full_Type_Declaration
15978 and then Nkind (Type_Definition (Decl)) = N_Record_Definition
15980 (No (Component_List (Type_Definition (Decl)))
15981 or else Null_Present (Component_List (Type_Definition (Decl))));
15982 end Is_Null_Record_Type;
15984 ---------------------
15985 -- Is_Object_Image --
15986 ---------------------
15988 function Is_Object_Image (Prefix : Node_Id) return Boolean is
15990 -- When the type of the prefix is not scalar, then the prefix is not
15991 -- valid in any scenario.
15993 if not Is_Scalar_Type (Etype (Prefix)) then
15997 -- Here we test for the case that the prefix is not a type and assume
15998 -- if it is not then it must be a named value or an object reference.
15999 -- This is because the parser always checks that prefixes of attributes
16002 return not (Is_Entity_Name (Prefix) and then Is_Type (Entity (Prefix)));
16003 end Is_Object_Image;
16005 -------------------------
16006 -- Is_Object_Reference --
16007 -------------------------
16009 function Is_Object_Reference (N : Node_Id) return Boolean is
16010 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean;
16011 -- Determine whether N is the name of an internally-generated renaming
16013 --------------------------------------
16014 -- Is_Internally_Generated_Renaming --
16015 --------------------------------------
16017 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean is
16022 while Present (P) loop
16023 if Nkind (P) = N_Object_Renaming_Declaration then
16024 return not Comes_From_Source (P);
16025 elsif Is_List_Member (P) then
16033 end Is_Internally_Generated_Renaming;
16035 -- Start of processing for Is_Object_Reference
16038 if Is_Entity_Name (N) then
16039 return Present (Entity (N)) and then Is_Object (Entity (N));
16043 when N_Indexed_Component
16047 Is_Object_Reference (Prefix (N))
16048 or else Is_Access_Type (Etype (Prefix (N)));
16050 -- In Ada 95, a function call is a constant object; a procedure
16053 -- Note that predefined operators are functions as well, and so
16054 -- are attributes that are (can be renamed as) functions.
16060 return Etype (N) /= Standard_Void_Type;
16062 -- Attributes references 'Loop_Entry, 'Old, and 'Result yield
16063 -- objects, even though they are not functions.
16065 when N_Attribute_Reference =>
16067 Nam_In (Attribute_Name (N), Name_Loop_Entry,
16070 or else Is_Function_Attribute_Name (Attribute_Name (N));
16072 when N_Selected_Component =>
16074 Is_Object_Reference (Selector_Name (N))
16076 (Is_Object_Reference (Prefix (N))
16077 or else Is_Access_Type (Etype (Prefix (N))));
16079 -- An explicit dereference denotes an object, except that a
16080 -- conditional expression gets turned into an explicit dereference
16081 -- in some cases, and conditional expressions are not object
16084 when N_Explicit_Dereference =>
16085 return not Nkind_In (Original_Node (N), N_Case_Expression,
16088 -- A view conversion of a tagged object is an object reference
16090 when N_Type_Conversion =>
16091 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
16092 and then Is_Tagged_Type (Etype (Expression (N)))
16093 and then Is_Object_Reference (Expression (N));
16095 -- An unchecked type conversion is considered to be an object if
16096 -- the operand is an object (this construction arises only as a
16097 -- result of expansion activities).
16099 when N_Unchecked_Type_Conversion =>
16102 -- Allow string literals to act as objects as long as they appear
16103 -- in internally-generated renamings. The expansion of iterators
16104 -- may generate such renamings when the range involves a string
16107 when N_String_Literal =>
16108 return Is_Internally_Generated_Renaming (Parent (N));
16110 -- AI05-0003: In Ada 2012 a qualified expression is a name.
16111 -- This allows disambiguation of function calls and the use
16112 -- of aggregates in more contexts.
16114 when N_Qualified_Expression =>
16115 if Ada_Version < Ada_2012 then
16118 return Is_Object_Reference (Expression (N))
16119 or else Nkind (Expression (N)) = N_Aggregate;
16126 end Is_Object_Reference;
16128 -----------------------------------
16129 -- Is_OK_Variable_For_Out_Formal --
16130 -----------------------------------
16132 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
16134 Note_Possible_Modification (AV, Sure => True);
16136 -- We must reject parenthesized variable names. Comes_From_Source is
16137 -- checked because there are currently cases where the compiler violates
16138 -- this rule (e.g. passing a task object to its controlled Initialize
16139 -- routine). This should be properly documented in sinfo???
16141 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
16144 -- A variable is always allowed
16146 elsif Is_Variable (AV) then
16149 -- Generalized indexing operations are rewritten as explicit
16150 -- dereferences, and it is only during resolution that we can
16151 -- check whether the context requires an access_to_variable type.
16153 elsif Nkind (AV) = N_Explicit_Dereference
16154 and then Ada_Version >= Ada_2012
16155 and then Nkind (Original_Node (AV)) = N_Indexed_Component
16156 and then Present (Etype (Original_Node (AV)))
16157 and then Has_Implicit_Dereference (Etype (Original_Node (AV)))
16159 return not Is_Access_Constant (Etype (Prefix (AV)));
16161 -- Unchecked conversions are allowed only if they come from the
16162 -- generated code, which sometimes uses unchecked conversions for out
16163 -- parameters in cases where code generation is unaffected. We tell
16164 -- source unchecked conversions by seeing if they are rewrites of
16165 -- an original Unchecked_Conversion function call, or of an explicit
16166 -- conversion of a function call or an aggregate (as may happen in the
16167 -- expansion of a packed array aggregate).
16169 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
16170 if Nkind_In (Original_Node (AV), N_Function_Call, N_Aggregate) then
16173 elsif Comes_From_Source (AV)
16174 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
16178 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
16179 return Is_OK_Variable_For_Out_Formal (Expression (AV));
16185 -- Normal type conversions are allowed if argument is a variable
16187 elsif Nkind (AV) = N_Type_Conversion then
16188 if Is_Variable (Expression (AV))
16189 and then Paren_Count (Expression (AV)) = 0
16191 Note_Possible_Modification (Expression (AV), Sure => True);
16194 -- We also allow a non-parenthesized expression that raises
16195 -- constraint error if it rewrites what used to be a variable
16197 elsif Raises_Constraint_Error (Expression (AV))
16198 and then Paren_Count (Expression (AV)) = 0
16199 and then Is_Variable (Original_Node (Expression (AV)))
16203 -- Type conversion of something other than a variable
16209 -- If this node is rewritten, then test the original form, if that is
16210 -- OK, then we consider the rewritten node OK (for example, if the
16211 -- original node is a conversion, then Is_Variable will not be true
16212 -- but we still want to allow the conversion if it converts a variable).
16214 elsif Is_Rewrite_Substitution (AV) then
16216 -- In Ada 2012, the explicit dereference may be a rewritten call to a
16217 -- Reference function.
16219 if Ada_Version >= Ada_2012
16220 and then Nkind (Original_Node (AV)) = N_Function_Call
16222 Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
16225 -- Check that this is not a constant reference.
16227 return not Is_Access_Constant (Etype (Prefix (AV)));
16229 elsif Has_Implicit_Dereference (Etype (Original_Node (AV))) then
16231 not Is_Access_Constant (Etype
16232 (Get_Reference_Discriminant (Etype (Original_Node (AV)))));
16235 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
16238 -- All other non-variables are rejected
16243 end Is_OK_Variable_For_Out_Formal;
16245 ----------------------------
16246 -- Is_OK_Volatile_Context --
16247 ----------------------------
16249 function Is_OK_Volatile_Context
16250 (Context : Node_Id;
16251 Obj_Ref : Node_Id) return Boolean
16253 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean;
16254 -- Determine whether an arbitrary node denotes a call to a protected
16255 -- entry, function, or procedure in prefixed form where the prefix is
16258 function Within_Check (Nod : Node_Id) return Boolean;
16259 -- Determine whether an arbitrary node appears in a check node
16261 function Within_Volatile_Function (Id : Entity_Id) return Boolean;
16262 -- Determine whether an arbitrary entity appears in a volatile function
16264 ---------------------------------
16265 -- Is_Protected_Operation_Call --
16266 ---------------------------------
16268 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean is
16273 -- A call to a protected operations retains its selected component
16274 -- form as opposed to other prefixed calls that are transformed in
16277 if Nkind (Nod) = N_Selected_Component then
16278 Pref := Prefix (Nod);
16279 Subp := Selector_Name (Nod);
16283 and then Present (Etype (Pref))
16284 and then Is_Protected_Type (Etype (Pref))
16285 and then Is_Entity_Name (Subp)
16286 and then Present (Entity (Subp))
16287 and then Ekind_In (Entity (Subp), E_Entry,
16294 end Is_Protected_Operation_Call;
16300 function Within_Check (Nod : Node_Id) return Boolean is
16304 -- Climb the parent chain looking for a check node
16307 while Present (Par) loop
16308 if Nkind (Par) in N_Raise_xxx_Error then
16311 -- Prevent the search from going too far
16313 elsif Is_Body_Or_Package_Declaration (Par) then
16317 Par := Parent (Par);
16323 ------------------------------
16324 -- Within_Volatile_Function --
16325 ------------------------------
16327 function Within_Volatile_Function (Id : Entity_Id) return Boolean is
16328 Func_Id : Entity_Id;
16331 -- Traverse the scope stack looking for a [generic] function
16334 while Present (Func_Id) and then Func_Id /= Standard_Standard loop
16335 if Ekind_In (Func_Id, E_Function, E_Generic_Function) then
16336 return Is_Volatile_Function (Func_Id);
16339 Func_Id := Scope (Func_Id);
16343 end Within_Volatile_Function;
16347 Obj_Id : Entity_Id;
16349 -- Start of processing for Is_OK_Volatile_Context
16352 -- The volatile object appears on either side of an assignment
16354 if Nkind (Context) = N_Assignment_Statement then
16357 -- The volatile object is part of the initialization expression of
16360 elsif Nkind (Context) = N_Object_Declaration
16361 and then Present (Expression (Context))
16362 and then Expression (Context) = Obj_Ref
16364 Obj_Id := Defining_Entity (Context);
16366 -- The volatile object acts as the initialization expression of an
16367 -- extended return statement. This is valid context as long as the
16368 -- function is volatile.
16370 if Is_Return_Object (Obj_Id) then
16371 return Within_Volatile_Function (Obj_Id);
16373 -- Otherwise this is a normal object initialization
16379 -- The volatile object acts as the name of a renaming declaration
16381 elsif Nkind (Context) = N_Object_Renaming_Declaration
16382 and then Name (Context) = Obj_Ref
16386 -- The volatile object appears as an actual parameter in a call to an
16387 -- instance of Unchecked_Conversion whose result is renamed.
16389 elsif Nkind (Context) = N_Function_Call
16390 and then Is_Entity_Name (Name (Context))
16391 and then Is_Unchecked_Conversion_Instance (Entity (Name (Context)))
16392 and then Nkind (Parent (Context)) = N_Object_Renaming_Declaration
16396 -- The volatile object is actually the prefix in a protected entry,
16397 -- function, or procedure call.
16399 elsif Is_Protected_Operation_Call (Context) then
16402 -- The volatile object appears as the expression of a simple return
16403 -- statement that applies to a volatile function.
16405 elsif Nkind (Context) = N_Simple_Return_Statement
16406 and then Expression (Context) = Obj_Ref
16409 Within_Volatile_Function (Return_Statement_Entity (Context));
16411 -- The volatile object appears as the prefix of a name occurring in a
16412 -- non-interfering context.
16414 elsif Nkind_In (Context, N_Attribute_Reference,
16415 N_Explicit_Dereference,
16416 N_Indexed_Component,
16417 N_Selected_Component,
16419 and then Prefix (Context) = Obj_Ref
16420 and then Is_OK_Volatile_Context
16421 (Context => Parent (Context),
16422 Obj_Ref => Context)
16426 -- The volatile object appears as the prefix of attributes Address,
16427 -- Alignment, Component_Size, First, First_Bit, Last, Last_Bit, Length,
16428 -- Position, Size, Storage_Size.
16430 elsif Nkind (Context) = N_Attribute_Reference
16431 and then Prefix (Context) = Obj_Ref
16432 and then Nam_In (Attribute_Name (Context), Name_Address,
16434 Name_Component_Size,
16446 -- The volatile object appears as the expression of a type conversion
16447 -- occurring in a non-interfering context.
16449 elsif Nkind_In (Context, N_Type_Conversion,
16450 N_Unchecked_Type_Conversion)
16451 and then Expression (Context) = Obj_Ref
16452 and then Is_OK_Volatile_Context
16453 (Context => Parent (Context),
16454 Obj_Ref => Context)
16458 -- The volatile object appears as the expression in a delay statement
16460 elsif Nkind (Context) in N_Delay_Statement then
16463 -- Allow references to volatile objects in various checks. This is not a
16464 -- direct SPARK 2014 requirement.
16466 elsif Within_Check (Context) then
16469 -- Assume that references to effectively volatile objects that appear
16470 -- as actual parameters in a subprogram call are always legal. A full
16471 -- legality check is done when the actuals are resolved (see routine
16472 -- Resolve_Actuals).
16474 elsif Within_Subprogram_Call (Context) then
16477 -- Otherwise the context is not suitable for an effectively volatile
16483 end Is_OK_Volatile_Context;
16485 ------------------------------------
16486 -- Is_Package_Contract_Annotation --
16487 ------------------------------------
16489 function Is_Package_Contract_Annotation (Item : Node_Id) return Boolean is
16493 if Nkind (Item) = N_Aspect_Specification then
16494 Nam := Chars (Identifier (Item));
16496 else pragma Assert (Nkind (Item) = N_Pragma);
16497 Nam := Pragma_Name (Item);
16500 return Nam = Name_Abstract_State
16501 or else Nam = Name_Initial_Condition
16502 or else Nam = Name_Initializes
16503 or else Nam = Name_Refined_State;
16504 end Is_Package_Contract_Annotation;
16506 -----------------------------------
16507 -- Is_Partially_Initialized_Type --
16508 -----------------------------------
16510 function Is_Partially_Initialized_Type
16512 Include_Implicit : Boolean := True) return Boolean
16515 if Is_Scalar_Type (Typ) then
16518 elsif Is_Access_Type (Typ) then
16519 return Include_Implicit;
16521 elsif Is_Array_Type (Typ) then
16523 -- If component type is partially initialized, so is array type
16525 if Is_Partially_Initialized_Type
16526 (Component_Type (Typ), Include_Implicit)
16530 -- Otherwise we are only partially initialized if we are fully
16531 -- initialized (this is the empty array case, no point in us
16532 -- duplicating that code here).
16535 return Is_Fully_Initialized_Type (Typ);
16538 elsif Is_Record_Type (Typ) then
16540 -- A discriminated type is always partially initialized if in
16543 if Has_Discriminants (Typ) and then Include_Implicit then
16546 -- A tagged type is always partially initialized
16548 elsif Is_Tagged_Type (Typ) then
16551 -- Case of non-discriminated record
16557 Component_Present : Boolean := False;
16558 -- Set True if at least one component is present. If no
16559 -- components are present, then record type is fully
16560 -- initialized (another odd case, like the null array).
16563 -- Loop through components
16565 Ent := First_Entity (Typ);
16566 while Present (Ent) loop
16567 if Ekind (Ent) = E_Component then
16568 Component_Present := True;
16570 -- If a component has an initialization expression then
16571 -- the enclosing record type is partially initialized
16573 if Present (Parent (Ent))
16574 and then Present (Expression (Parent (Ent)))
16578 -- If a component is of a type which is itself partially
16579 -- initialized, then the enclosing record type is also.
16581 elsif Is_Partially_Initialized_Type
16582 (Etype (Ent), Include_Implicit)
16591 -- No initialized components found. If we found any components
16592 -- they were all uninitialized so the result is false.
16594 if Component_Present then
16597 -- But if we found no components, then all the components are
16598 -- initialized so we consider the type to be initialized.
16606 -- Concurrent types are always fully initialized
16608 elsif Is_Concurrent_Type (Typ) then
16611 -- For a private type, go to underlying type. If there is no underlying
16612 -- type then just assume this partially initialized. Not clear if this
16613 -- can happen in a non-error case, but no harm in testing for this.
16615 elsif Is_Private_Type (Typ) then
16617 U : constant Entity_Id := Underlying_Type (Typ);
16622 return Is_Partially_Initialized_Type (U, Include_Implicit);
16626 -- For any other type (are there any?) assume partially initialized
16631 end Is_Partially_Initialized_Type;
16633 ------------------------------------
16634 -- Is_Potentially_Persistent_Type --
16635 ------------------------------------
16637 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
16642 -- For private type, test corresponding full type
16644 if Is_Private_Type (T) then
16645 return Is_Potentially_Persistent_Type (Full_View (T));
16647 -- Scalar types are potentially persistent
16649 elsif Is_Scalar_Type (T) then
16652 -- Record type is potentially persistent if not tagged and the types of
16653 -- all it components are potentially persistent, and no component has
16654 -- an initialization expression.
16656 elsif Is_Record_Type (T)
16657 and then not Is_Tagged_Type (T)
16658 and then not Is_Partially_Initialized_Type (T)
16660 Comp := First_Component (T);
16661 while Present (Comp) loop
16662 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
16665 Next_Entity (Comp);
16671 -- Array type is potentially persistent if its component type is
16672 -- potentially persistent and if all its constraints are static.
16674 elsif Is_Array_Type (T) then
16675 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
16679 Indx := First_Index (T);
16680 while Present (Indx) loop
16681 if not Is_OK_Static_Subtype (Etype (Indx)) then
16690 -- All other types are not potentially persistent
16695 end Is_Potentially_Persistent_Type;
16697 --------------------------------
16698 -- Is_Potentially_Unevaluated --
16699 --------------------------------
16701 function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is
16709 -- A postcondition whose expression is a short-circuit is broken down
16710 -- into individual aspects for better exception reporting. The original
16711 -- short-circuit expression is rewritten as the second operand, and an
16712 -- occurrence of 'Old in that operand is potentially unevaluated.
16713 -- See sem_ch13.adb for details of this transformation. The reference
16714 -- to 'Old may appear within an expression, so we must look for the
16715 -- enclosing pragma argument in the tree that contains the reference.
16717 while Present (Par)
16718 and then Nkind (Par) /= N_Pragma_Argument_Association
16720 if Is_Rewrite_Substitution (Par)
16721 and then Nkind (Original_Node (Par)) = N_And_Then
16726 Par := Parent (Par);
16729 -- Other cases; 'Old appears within other expression (not the top-level
16730 -- conjunct in a postcondition) with a potentially unevaluated operand.
16732 Par := Parent (Expr);
16733 while not Nkind_In (Par, N_And_Then,
16739 N_Quantified_Expression)
16742 Par := Parent (Par);
16744 -- If the context is not an expression, or if is the result of
16745 -- expansion of an enclosing construct (such as another attribute)
16746 -- the predicate does not apply.
16748 if Nkind (Par) = N_Case_Expression_Alternative then
16751 elsif Nkind (Par) not in N_Subexpr
16752 or else not Comes_From_Source (Par)
16758 if Nkind (Par) = N_If_Expression then
16759 return Is_Elsif (Par) or else Expr /= First (Expressions (Par));
16761 elsif Nkind (Par) = N_Case_Expression then
16762 return Expr /= Expression (Par);
16764 elsif Nkind_In (Par, N_And_Then, N_Or_Else) then
16765 return Expr = Right_Opnd (Par);
16767 elsif Nkind_In (Par, N_In, N_Not_In) then
16769 -- If the membership includes several alternatives, only the first is
16770 -- definitely evaluated.
16772 if Present (Alternatives (Par)) then
16773 return Expr /= First (Alternatives (Par));
16775 -- If this is a range membership both bounds are evaluated
16781 elsif Nkind (Par) = N_Quantified_Expression then
16782 return Expr = Condition (Par);
16787 end Is_Potentially_Unevaluated;
16789 -----------------------------------------
16790 -- Is_Predefined_Dispatching_Operation --
16791 -----------------------------------------
16793 function Is_Predefined_Dispatching_Operation
16794 (E : Entity_Id) return Boolean
16796 TSS_Name : TSS_Name_Type;
16799 if not Is_Dispatching_Operation (E) then
16803 Get_Name_String (Chars (E));
16805 -- Most predefined primitives have internally generated names. Equality
16806 -- must be treated differently; the predefined operation is recognized
16807 -- as a homogeneous binary operator that returns Boolean.
16809 if Name_Len > TSS_Name_Type'Last then
16812 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
16814 if Nam_In (Chars (E), Name_uAssign, Name_uSize)
16816 (Chars (E) = Name_Op_Eq
16817 and then Etype (First_Formal (E)) = Etype (Last_Formal (E)))
16818 or else TSS_Name = TSS_Deep_Adjust
16819 or else TSS_Name = TSS_Deep_Finalize
16820 or else TSS_Name = TSS_Stream_Input
16821 or else TSS_Name = TSS_Stream_Output
16822 or else TSS_Name = TSS_Stream_Read
16823 or else TSS_Name = TSS_Stream_Write
16824 or else Is_Predefined_Interface_Primitive (E)
16831 end Is_Predefined_Dispatching_Operation;
16833 ---------------------------------------
16834 -- Is_Predefined_Interface_Primitive --
16835 ---------------------------------------
16837 function Is_Predefined_Interface_Primitive (E : Entity_Id) return Boolean is
16839 -- In VM targets we don't restrict the functionality of this test to
16840 -- compiling in Ada 2005 mode since in VM targets any tagged type has
16841 -- these primitives.
16843 return (Ada_Version >= Ada_2005 or else not Tagged_Type_Expansion)
16844 and then Nam_In (Chars (E), Name_uDisp_Asynchronous_Select,
16845 Name_uDisp_Conditional_Select,
16846 Name_uDisp_Get_Prim_Op_Kind,
16847 Name_uDisp_Get_Task_Id,
16848 Name_uDisp_Requeue,
16849 Name_uDisp_Timed_Select);
16850 end Is_Predefined_Interface_Primitive;
16852 ---------------------------------------
16853 -- Is_Predefined_Internal_Operation --
16854 ---------------------------------------
16856 function Is_Predefined_Internal_Operation
16857 (E : Entity_Id) return Boolean
16859 TSS_Name : TSS_Name_Type;
16862 if not Is_Dispatching_Operation (E) then
16866 Get_Name_String (Chars (E));
16868 -- Most predefined primitives have internally generated names. Equality
16869 -- must be treated differently; the predefined operation is recognized
16870 -- as a homogeneous binary operator that returns Boolean.
16872 if Name_Len > TSS_Name_Type'Last then
16875 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
16877 if Nam_In (Chars (E), Name_uSize, Name_uAssign)
16879 (Chars (E) = Name_Op_Eq
16880 and then Etype (First_Formal (E)) = Etype (Last_Formal (E)))
16881 or else TSS_Name = TSS_Deep_Adjust
16882 or else TSS_Name = TSS_Deep_Finalize
16883 or else Is_Predefined_Interface_Primitive (E)
16890 end Is_Predefined_Internal_Operation;
16892 --------------------------------
16893 -- Is_Preelaborable_Aggregate --
16894 --------------------------------
16896 function Is_Preelaborable_Aggregate (Aggr : Node_Id) return Boolean is
16897 Aggr_Typ : constant Entity_Id := Etype (Aggr);
16898 Array_Aggr : constant Boolean := Is_Array_Type (Aggr_Typ);
16900 Anc_Part : Node_Id;
16903 Comp_Typ : Entity_Id := Empty; -- init to avoid warning
16908 Comp_Typ := Component_Type (Aggr_Typ);
16911 -- Inspect the ancestor part
16913 if Nkind (Aggr) = N_Extension_Aggregate then
16914 Anc_Part := Ancestor_Part (Aggr);
16916 -- The ancestor denotes a subtype mark
16918 if Is_Entity_Name (Anc_Part)
16919 and then Is_Type (Entity (Anc_Part))
16921 if not Has_Preelaborable_Initialization (Entity (Anc_Part)) then
16925 -- Otherwise the ancestor denotes an expression
16927 elsif not Is_Preelaborable_Construct (Anc_Part) then
16932 -- Inspect the positional associations
16934 Expr := First (Expressions (Aggr));
16935 while Present (Expr) loop
16936 if not Is_Preelaborable_Construct (Expr) then
16943 -- Inspect the named associations
16945 Assoc := First (Component_Associations (Aggr));
16946 while Present (Assoc) loop
16948 -- Inspect the choices of the current named association
16950 Choice := First (Choices (Assoc));
16951 while Present (Choice) loop
16954 -- For a choice to be preelaborable, it must denote either a
16955 -- static range or a static expression.
16957 if Nkind (Choice) = N_Others_Choice then
16960 elsif Nkind (Choice) = N_Range then
16961 if not Is_OK_Static_Range (Choice) then
16965 elsif not Is_OK_Static_Expression (Choice) then
16970 Comp_Typ := Etype (Choice);
16976 -- The type of the choice must have preelaborable initialization if
16977 -- the association carries a <>.
16979 pragma Assert (Present (Comp_Typ));
16980 if Box_Present (Assoc) then
16981 if not Has_Preelaborable_Initialization (Comp_Typ) then
16985 -- The type of the expression must have preelaborable initialization
16987 elsif not Is_Preelaborable_Construct (Expression (Assoc)) then
16994 -- At this point the aggregate is preelaborable
16997 end Is_Preelaborable_Aggregate;
16999 --------------------------------
17000 -- Is_Preelaborable_Construct --
17001 --------------------------------
17003 function Is_Preelaborable_Construct (N : Node_Id) return Boolean is
17007 if Nkind_In (N, N_Aggregate, N_Extension_Aggregate) then
17008 return Is_Preelaborable_Aggregate (N);
17010 -- Attributes are allowed in general, even if their prefix is a formal
17011 -- type. It seems that certain attributes known not to be static might
17012 -- not be allowed, but there are no rules to prevent them.
17014 elsif Nkind (N) = N_Attribute_Reference then
17019 elsif Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
17022 elsif Nkind (N) = N_Qualified_Expression then
17023 return Is_Preelaborable_Construct (Expression (N));
17025 -- Names are preelaborable when they denote a discriminant of an
17026 -- enclosing type. Discriminals are also considered for this check.
17028 elsif Is_Entity_Name (N)
17029 and then Present (Entity (N))
17031 (Ekind (Entity (N)) = E_Discriminant
17032 or else (Ekind_In (Entity (N), E_Constant, E_In_Parameter)
17033 and then Present (Discriminal_Link (Entity (N)))))
17039 elsif Nkind (N) = N_Null then
17042 -- Otherwise the construct is not preelaborable
17047 end Is_Preelaborable_Construct;
17049 ---------------------------------
17050 -- Is_Protected_Self_Reference --
17051 ---------------------------------
17053 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
17055 function In_Access_Definition (N : Node_Id) return Boolean;
17056 -- Returns true if N belongs to an access definition
17058 --------------------------
17059 -- In_Access_Definition --
17060 --------------------------
17062 function In_Access_Definition (N : Node_Id) return Boolean is
17067 while Present (P) loop
17068 if Nkind (P) = N_Access_Definition then
17076 end In_Access_Definition;
17078 -- Start of processing for Is_Protected_Self_Reference
17081 -- Verify that prefix is analyzed and has the proper form. Note that
17082 -- the attributes Elab_Spec, Elab_Body, and Elab_Subp_Body, which also
17083 -- produce the address of an entity, do not analyze their prefix
17084 -- because they denote entities that are not necessarily visible.
17085 -- Neither of them can apply to a protected type.
17087 return Ada_Version >= Ada_2005
17088 and then Is_Entity_Name (N)
17089 and then Present (Entity (N))
17090 and then Is_Protected_Type (Entity (N))
17091 and then In_Open_Scopes (Entity (N))
17092 and then not In_Access_Definition (N);
17093 end Is_Protected_Self_Reference;
17095 -----------------------------
17096 -- Is_RCI_Pkg_Spec_Or_Body --
17097 -----------------------------
17099 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
17101 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
17102 -- Return True if the unit of Cunit is an RCI package declaration
17104 ---------------------------
17105 -- Is_RCI_Pkg_Decl_Cunit --
17106 ---------------------------
17108 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
17109 The_Unit : constant Node_Id := Unit (Cunit);
17112 if Nkind (The_Unit) /= N_Package_Declaration then
17116 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
17117 end Is_RCI_Pkg_Decl_Cunit;
17119 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
17122 return Is_RCI_Pkg_Decl_Cunit (Cunit)
17124 (Nkind (Unit (Cunit)) = N_Package_Body
17125 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
17126 end Is_RCI_Pkg_Spec_Or_Body;
17128 -----------------------------------------
17129 -- Is_Remote_Access_To_Class_Wide_Type --
17130 -----------------------------------------
17132 function Is_Remote_Access_To_Class_Wide_Type
17133 (E : Entity_Id) return Boolean
17136 -- A remote access to class-wide type is a general access to object type
17137 -- declared in the visible part of a Remote_Types or Remote_Call_
17140 return Ekind (E) = E_General_Access_Type
17141 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
17142 end Is_Remote_Access_To_Class_Wide_Type;
17144 -----------------------------------------
17145 -- Is_Remote_Access_To_Subprogram_Type --
17146 -----------------------------------------
17148 function Is_Remote_Access_To_Subprogram_Type
17149 (E : Entity_Id) return Boolean
17152 return (Ekind (E) = E_Access_Subprogram_Type
17153 or else (Ekind (E) = E_Record_Type
17154 and then Present (Corresponding_Remote_Type (E))))
17155 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
17156 end Is_Remote_Access_To_Subprogram_Type;
17158 --------------------
17159 -- Is_Remote_Call --
17160 --------------------
17162 function Is_Remote_Call (N : Node_Id) return Boolean is
17164 if Nkind (N) not in N_Subprogram_Call then
17166 -- An entry call cannot be remote
17170 elsif Nkind (Name (N)) in N_Has_Entity
17171 and then Is_Remote_Call_Interface (Entity (Name (N)))
17173 -- A subprogram declared in the spec of a RCI package is remote
17177 elsif Nkind (Name (N)) = N_Explicit_Dereference
17178 and then Is_Remote_Access_To_Subprogram_Type
17179 (Etype (Prefix (Name (N))))
17181 -- The dereference of a RAS is a remote call
17185 elsif Present (Controlling_Argument (N))
17186 and then Is_Remote_Access_To_Class_Wide_Type
17187 (Etype (Controlling_Argument (N)))
17189 -- Any primitive operation call with a controlling argument of
17190 -- a RACW type is a remote call.
17195 -- All other calls are local calls
17198 end Is_Remote_Call;
17200 ----------------------
17201 -- Is_Renamed_Entry --
17202 ----------------------
17204 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
17205 Orig_Node : Node_Id := Empty;
17206 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
17208 function Is_Entry (Nam : Node_Id) return Boolean;
17209 -- Determine whether Nam is an entry. Traverse selectors if there are
17210 -- nested selected components.
17216 function Is_Entry (Nam : Node_Id) return Boolean is
17218 if Nkind (Nam) = N_Selected_Component then
17219 return Is_Entry (Selector_Name (Nam));
17222 return Ekind (Entity (Nam)) = E_Entry;
17225 -- Start of processing for Is_Renamed_Entry
17228 if Present (Alias (Proc_Nam)) then
17229 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
17232 -- Look for a rewritten subprogram renaming declaration
17234 if Nkind (Subp_Decl) = N_Subprogram_Declaration
17235 and then Present (Original_Node (Subp_Decl))
17237 Orig_Node := Original_Node (Subp_Decl);
17240 -- The rewritten subprogram is actually an entry
17242 if Present (Orig_Node)
17243 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
17244 and then Is_Entry (Name (Orig_Node))
17250 end Is_Renamed_Entry;
17252 -----------------------------
17253 -- Is_Renaming_Declaration --
17254 -----------------------------
17256 function Is_Renaming_Declaration (N : Node_Id) return Boolean is
17259 when N_Exception_Renaming_Declaration
17260 | N_Generic_Function_Renaming_Declaration
17261 | N_Generic_Package_Renaming_Declaration
17262 | N_Generic_Procedure_Renaming_Declaration
17263 | N_Object_Renaming_Declaration
17264 | N_Package_Renaming_Declaration
17265 | N_Subprogram_Renaming_Declaration
17272 end Is_Renaming_Declaration;
17274 ----------------------------
17275 -- Is_Reversible_Iterator --
17276 ----------------------------
17278 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
17279 Ifaces_List : Elist_Id;
17280 Iface_Elmt : Elmt_Id;
17284 if Is_Class_Wide_Type (Typ)
17285 and then Chars (Root_Type (Typ)) = Name_Reversible_Iterator
17286 and then In_Predefined_Unit (Root_Type (Typ))
17290 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
17294 Collect_Interfaces (Typ, Ifaces_List);
17296 Iface_Elmt := First_Elmt (Ifaces_List);
17297 while Present (Iface_Elmt) loop
17298 Iface := Node (Iface_Elmt);
17299 if Chars (Iface) = Name_Reversible_Iterator
17300 and then In_Predefined_Unit (Iface)
17305 Next_Elmt (Iface_Elmt);
17310 end Is_Reversible_Iterator;
17312 ----------------------
17313 -- Is_Selector_Name --
17314 ----------------------
17316 function Is_Selector_Name (N : Node_Id) return Boolean is
17318 if not Is_List_Member (N) then
17320 P : constant Node_Id := Parent (N);
17322 return Nkind_In (P, N_Expanded_Name,
17323 N_Generic_Association,
17324 N_Parameter_Association,
17325 N_Selected_Component)
17326 and then Selector_Name (P) = N;
17331 L : constant List_Id := List_Containing (N);
17332 P : constant Node_Id := Parent (L);
17334 return (Nkind (P) = N_Discriminant_Association
17335 and then Selector_Names (P) = L)
17337 (Nkind (P) = N_Component_Association
17338 and then Choices (P) = L);
17341 end Is_Selector_Name;
17343 ---------------------------------
17344 -- Is_Single_Concurrent_Object --
17345 ---------------------------------
17347 function Is_Single_Concurrent_Object (Id : Entity_Id) return Boolean is
17350 Is_Single_Protected_Object (Id) or else Is_Single_Task_Object (Id);
17351 end Is_Single_Concurrent_Object;
17353 -------------------------------
17354 -- Is_Single_Concurrent_Type --
17355 -------------------------------
17357 function Is_Single_Concurrent_Type (Id : Entity_Id) return Boolean is
17360 Ekind_In (Id, E_Protected_Type, E_Task_Type)
17361 and then Is_Single_Concurrent_Type_Declaration
17362 (Declaration_Node (Id));
17363 end Is_Single_Concurrent_Type;
17365 -------------------------------------------
17366 -- Is_Single_Concurrent_Type_Declaration --
17367 -------------------------------------------
17369 function Is_Single_Concurrent_Type_Declaration
17370 (N : Node_Id) return Boolean
17373 return Nkind_In (Original_Node (N), N_Single_Protected_Declaration,
17374 N_Single_Task_Declaration);
17375 end Is_Single_Concurrent_Type_Declaration;
17377 ---------------------------------------------
17378 -- Is_Single_Precision_Floating_Point_Type --
17379 ---------------------------------------------
17381 function Is_Single_Precision_Floating_Point_Type
17382 (E : Entity_Id) return Boolean is
17384 return Is_Floating_Point_Type (E)
17385 and then Machine_Radix_Value (E) = Uint_2
17386 and then Machine_Mantissa_Value (E) = Uint_24
17387 and then Machine_Emax_Value (E) = Uint_2 ** Uint_7
17388 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_7);
17389 end Is_Single_Precision_Floating_Point_Type;
17391 --------------------------------
17392 -- Is_Single_Protected_Object --
17393 --------------------------------
17395 function Is_Single_Protected_Object (Id : Entity_Id) return Boolean is
17398 Ekind (Id) = E_Variable
17399 and then Ekind (Etype (Id)) = E_Protected_Type
17400 and then Is_Single_Concurrent_Type (Etype (Id));
17401 end Is_Single_Protected_Object;
17403 ---------------------------
17404 -- Is_Single_Task_Object --
17405 ---------------------------
17407 function Is_Single_Task_Object (Id : Entity_Id) return Boolean is
17410 Ekind (Id) = E_Variable
17411 and then Ekind (Etype (Id)) = E_Task_Type
17412 and then Is_Single_Concurrent_Type (Etype (Id));
17413 end Is_Single_Task_Object;
17415 -------------------------------------
17416 -- Is_SPARK_05_Initialization_Expr --
17417 -------------------------------------
17419 function Is_SPARK_05_Initialization_Expr (N : Node_Id) return Boolean is
17422 Comp_Assn : Node_Id;
17423 Orig_N : constant Node_Id := Original_Node (N);
17428 if not Comes_From_Source (Orig_N) then
17432 pragma Assert (Nkind (Orig_N) in N_Subexpr);
17434 case Nkind (Orig_N) is
17435 when N_Character_Literal
17436 | N_Integer_Literal
17442 when N_Expanded_Name
17445 if Is_Entity_Name (Orig_N)
17446 and then Present (Entity (Orig_N)) -- needed in some cases
17448 case Ekind (Entity (Orig_N)) is
17450 | E_Enumeration_Literal
17457 if Is_Type (Entity (Orig_N)) then
17465 when N_Qualified_Expression
17466 | N_Type_Conversion
17468 Is_Ok := Is_SPARK_05_Initialization_Expr (Expression (Orig_N));
17471 Is_Ok := Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
17474 | N_Membership_Test
17477 Is_Ok := Is_SPARK_05_Initialization_Expr (Left_Opnd (Orig_N))
17479 Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
17482 | N_Extension_Aggregate
17484 if Nkind (Orig_N) = N_Extension_Aggregate then
17486 Is_SPARK_05_Initialization_Expr (Ancestor_Part (Orig_N));
17489 Expr := First (Expressions (Orig_N));
17490 while Present (Expr) loop
17491 if not Is_SPARK_05_Initialization_Expr (Expr) then
17499 Comp_Assn := First (Component_Associations (Orig_N));
17500 while Present (Comp_Assn) loop
17501 Expr := Expression (Comp_Assn);
17503 -- Note: test for Present here needed for box assocation
17506 and then not Is_SPARK_05_Initialization_Expr (Expr)
17515 when N_Attribute_Reference =>
17516 if Nkind (Prefix (Orig_N)) in N_Subexpr then
17517 Is_Ok := Is_SPARK_05_Initialization_Expr (Prefix (Orig_N));
17520 Expr := First (Expressions (Orig_N));
17521 while Present (Expr) loop
17522 if not Is_SPARK_05_Initialization_Expr (Expr) then
17530 -- Selected components might be expanded named not yet resolved, so
17531 -- default on the safe side. (Eg on sparklex.ads)
17533 when N_Selected_Component =>
17542 end Is_SPARK_05_Initialization_Expr;
17544 ----------------------------------
17545 -- Is_SPARK_05_Object_Reference --
17546 ----------------------------------
17548 function Is_SPARK_05_Object_Reference (N : Node_Id) return Boolean is
17550 if Is_Entity_Name (N) then
17551 return Present (Entity (N))
17553 (Ekind_In (Entity (N), E_Constant, E_Variable)
17554 or else Ekind (Entity (N)) in Formal_Kind);
17558 when N_Selected_Component =>
17559 return Is_SPARK_05_Object_Reference (Prefix (N));
17565 end Is_SPARK_05_Object_Reference;
17567 -----------------------------
17568 -- Is_Specific_Tagged_Type --
17569 -----------------------------
17571 function Is_Specific_Tagged_Type (Typ : Entity_Id) return Boolean is
17572 Full_Typ : Entity_Id;
17575 -- Handle private types
17577 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
17578 Full_Typ := Full_View (Typ);
17583 -- A specific tagged type is a non-class-wide tagged type
17585 return Is_Tagged_Type (Full_Typ) and not Is_Class_Wide_Type (Full_Typ);
17586 end Is_Specific_Tagged_Type;
17592 function Is_Statement (N : Node_Id) return Boolean is
17595 Nkind (N) in N_Statement_Other_Than_Procedure_Call
17596 or else Nkind (N) = N_Procedure_Call_Statement;
17599 ---------------------------------------
17600 -- Is_Subprogram_Contract_Annotation --
17601 ---------------------------------------
17603 function Is_Subprogram_Contract_Annotation
17604 (Item : Node_Id) return Boolean
17609 if Nkind (Item) = N_Aspect_Specification then
17610 Nam := Chars (Identifier (Item));
17612 else pragma Assert (Nkind (Item) = N_Pragma);
17613 Nam := Pragma_Name (Item);
17616 return Nam = Name_Contract_Cases
17617 or else Nam = Name_Depends
17618 or else Nam = Name_Extensions_Visible
17619 or else Nam = Name_Global
17620 or else Nam = Name_Post
17621 or else Nam = Name_Post_Class
17622 or else Nam = Name_Postcondition
17623 or else Nam = Name_Pre
17624 or else Nam = Name_Pre_Class
17625 or else Nam = Name_Precondition
17626 or else Nam = Name_Refined_Depends
17627 or else Nam = Name_Refined_Global
17628 or else Nam = Name_Refined_Post
17629 or else Nam = Name_Test_Case;
17630 end Is_Subprogram_Contract_Annotation;
17632 --------------------------------------------------
17633 -- Is_Subprogram_Stub_Without_Prior_Declaration --
17634 --------------------------------------------------
17636 function Is_Subprogram_Stub_Without_Prior_Declaration
17637 (N : Node_Id) return Boolean
17640 pragma Assert (Nkind (N) = N_Subprogram_Body_Stub);
17642 case Ekind (Defining_Entity (N)) is
17644 -- A subprogram stub without prior declaration serves as declaration
17645 -- for the actual subprogram body. As such, it has an attached
17646 -- defining entity of E_Function or E_Procedure.
17653 -- Otherwise, it is completes a [generic] subprogram declaration
17655 when E_Generic_Function
17656 | E_Generic_Procedure
17657 | E_Subprogram_Body
17662 raise Program_Error;
17664 end Is_Subprogram_Stub_Without_Prior_Declaration;
17666 ---------------------------
17667 -- Is_Suitable_Primitive --
17668 ---------------------------
17670 function Is_Suitable_Primitive (Subp_Id : Entity_Id) return Boolean is
17672 -- The Default_Initial_Condition and invariant procedures must not be
17673 -- treated as primitive operations even when they apply to a tagged
17674 -- type. These routines must not act as targets of dispatching calls
17675 -- because they already utilize class-wide-precondition semantics to
17676 -- handle inheritance and overriding.
17678 if Ekind (Subp_Id) = E_Procedure
17679 and then (Is_DIC_Procedure (Subp_Id)
17681 Is_Invariant_Procedure (Subp_Id))
17687 end Is_Suitable_Primitive;
17689 --------------------------
17690 -- Is_Suspension_Object --
17691 --------------------------
17693 function Is_Suspension_Object (Id : Entity_Id) return Boolean is
17695 -- This approach does an exact name match rather than to rely on
17696 -- RTSfind. Routine Is_Effectively_Volatile is used by clients of the
17697 -- front end at point where all auxiliary tables are locked and any
17698 -- modifications to them are treated as violations. Do not tamper with
17699 -- the tables, instead examine the Chars fields of all the scopes of Id.
17702 Chars (Id) = Name_Suspension_Object
17703 and then Present (Scope (Id))
17704 and then Chars (Scope (Id)) = Name_Synchronous_Task_Control
17705 and then Present (Scope (Scope (Id)))
17706 and then Chars (Scope (Scope (Id))) = Name_Ada
17707 and then Present (Scope (Scope (Scope (Id))))
17708 and then Scope (Scope (Scope (Id))) = Standard_Standard;
17709 end Is_Suspension_Object;
17711 ----------------------------
17712 -- Is_Synchronized_Object --
17713 ----------------------------
17715 function Is_Synchronized_Object (Id : Entity_Id) return Boolean is
17719 if Is_Object (Id) then
17721 -- The object is synchronized if it is of a type that yields a
17722 -- synchronized object.
17724 if Yields_Synchronized_Object (Etype (Id)) then
17727 -- The object is synchronized if it is atomic and Async_Writers is
17730 elsif Is_Atomic_Object_Entity (Id)
17731 and then Async_Writers_Enabled (Id)
17735 -- A constant is a synchronized object by default
17737 elsif Ekind (Id) = E_Constant then
17740 -- A variable is a synchronized object if it is subject to pragma
17741 -- Constant_After_Elaboration.
17743 elsif Ekind (Id) = E_Variable then
17744 Prag := Get_Pragma (Id, Pragma_Constant_After_Elaboration);
17746 return Present (Prag) and then Is_Enabled_Pragma (Prag);
17750 -- Otherwise the input is not an object or it does not qualify as a
17751 -- synchronized object.
17754 end Is_Synchronized_Object;
17756 ---------------------------------
17757 -- Is_Synchronized_Tagged_Type --
17758 ---------------------------------
17760 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
17761 Kind : constant Entity_Kind := Ekind (Base_Type (E));
17764 -- A task or protected type derived from an interface is a tagged type.
17765 -- Such a tagged type is called a synchronized tagged type, as are
17766 -- synchronized interfaces and private extensions whose declaration
17767 -- includes the reserved word synchronized.
17769 return (Is_Tagged_Type (E)
17770 and then (Kind = E_Task_Type
17772 Kind = E_Protected_Type))
17775 and then Is_Synchronized_Interface (E))
17777 (Ekind (E) = E_Record_Type_With_Private
17778 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
17779 and then (Synchronized_Present (Parent (E))
17780 or else Is_Synchronized_Interface (Etype (E))));
17781 end Is_Synchronized_Tagged_Type;
17787 function Is_Transfer (N : Node_Id) return Boolean is
17788 Kind : constant Node_Kind := Nkind (N);
17791 if Kind = N_Simple_Return_Statement
17793 Kind = N_Extended_Return_Statement
17795 Kind = N_Goto_Statement
17797 Kind = N_Raise_Statement
17799 Kind = N_Requeue_Statement
17803 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
17804 and then No (Condition (N))
17808 elsif Kind = N_Procedure_Call_Statement
17809 and then Is_Entity_Name (Name (N))
17810 and then Present (Entity (Name (N)))
17811 and then No_Return (Entity (Name (N)))
17815 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
17827 function Is_True (U : Uint) return Boolean is
17832 --------------------------------------
17833 -- Is_Unchecked_Conversion_Instance --
17834 --------------------------------------
17836 function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is
17840 -- Look for a function whose generic parent is the predefined intrinsic
17841 -- function Unchecked_Conversion, or for one that renames such an
17844 if Ekind (Id) = E_Function then
17845 Par := Parent (Id);
17847 if Nkind (Par) = N_Function_Specification then
17848 Par := Generic_Parent (Par);
17850 if Present (Par) then
17852 Chars (Par) = Name_Unchecked_Conversion
17853 and then Is_Intrinsic_Subprogram (Par)
17854 and then In_Predefined_Unit (Par);
17857 Present (Alias (Id))
17858 and then Is_Unchecked_Conversion_Instance (Alias (Id));
17864 end Is_Unchecked_Conversion_Instance;
17866 -------------------------------
17867 -- Is_Universal_Numeric_Type --
17868 -------------------------------
17870 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
17872 return T = Universal_Integer or else T = Universal_Real;
17873 end Is_Universal_Numeric_Type;
17875 ------------------------------
17876 -- Is_User_Defined_Equality --
17877 ------------------------------
17879 function Is_User_Defined_Equality (Id : Entity_Id) return Boolean is
17881 return Ekind (Id) = E_Function
17882 and then Chars (Id) = Name_Op_Eq
17883 and then Comes_From_Source (Id)
17885 -- Internally generated equalities have a full type declaration
17886 -- as their parent.
17888 and then Nkind (Parent (Id)) = N_Function_Specification;
17889 end Is_User_Defined_Equality;
17891 --------------------------------------
17892 -- Is_Validation_Variable_Reference --
17893 --------------------------------------
17895 function Is_Validation_Variable_Reference (N : Node_Id) return Boolean is
17896 Var : constant Node_Id := Unqual_Conv (N);
17897 Var_Id : Entity_Id;
17902 if Is_Entity_Name (Var) then
17903 Var_Id := Entity (Var);
17908 and then Ekind (Var_Id) = E_Variable
17909 and then Present (Validated_Object (Var_Id));
17910 end Is_Validation_Variable_Reference;
17912 ----------------------------
17913 -- Is_Variable_Size_Array --
17914 ----------------------------
17916 function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
17920 pragma Assert (Is_Array_Type (E));
17922 -- Check if some index is initialized with a non-constant value
17924 Idx := First_Index (E);
17925 while Present (Idx) loop
17926 if Nkind (Idx) = N_Range then
17927 if not Is_Constant_Bound (Low_Bound (Idx))
17928 or else not Is_Constant_Bound (High_Bound (Idx))
17934 Idx := Next_Index (Idx);
17938 end Is_Variable_Size_Array;
17940 -----------------------------
17941 -- Is_Variable_Size_Record --
17942 -----------------------------
17944 function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
17946 Comp_Typ : Entity_Id;
17949 pragma Assert (Is_Record_Type (E));
17951 Comp := First_Component (E);
17952 while Present (Comp) loop
17953 Comp_Typ := Underlying_Type (Etype (Comp));
17955 -- Recursive call if the record type has discriminants
17957 if Is_Record_Type (Comp_Typ)
17958 and then Has_Discriminants (Comp_Typ)
17959 and then Is_Variable_Size_Record (Comp_Typ)
17963 elsif Is_Array_Type (Comp_Typ)
17964 and then Is_Variable_Size_Array (Comp_Typ)
17969 Next_Component (Comp);
17973 end Is_Variable_Size_Record;
17979 function Is_Variable
17981 Use_Original_Node : Boolean := True) return Boolean
17983 Orig_Node : Node_Id;
17985 function In_Protected_Function (E : Entity_Id) return Boolean;
17986 -- Within a protected function, the private components of the enclosing
17987 -- protected type are constants. A function nested within a (protected)
17988 -- procedure is not itself protected. Within the body of a protected
17989 -- function the current instance of the protected type is a constant.
17991 function Is_Variable_Prefix (P : Node_Id) return Boolean;
17992 -- Prefixes can involve implicit dereferences, in which case we must
17993 -- test for the case of a reference of a constant access type, which can
17994 -- can never be a variable.
17996 ---------------------------
17997 -- In_Protected_Function --
17998 ---------------------------
18000 function In_Protected_Function (E : Entity_Id) return Boolean is
18005 -- E is the current instance of a type
18007 if Is_Type (E) then
18016 if not Is_Protected_Type (Prot) then
18020 S := Current_Scope;
18021 while Present (S) and then S /= Prot loop
18022 if Ekind (S) = E_Function and then Scope (S) = Prot then
18031 end In_Protected_Function;
18033 ------------------------
18034 -- Is_Variable_Prefix --
18035 ------------------------
18037 function Is_Variable_Prefix (P : Node_Id) return Boolean is
18039 if Is_Access_Type (Etype (P)) then
18040 return not Is_Access_Constant (Root_Type (Etype (P)));
18042 -- For the case of an indexed component whose prefix has a packed
18043 -- array type, the prefix has been rewritten into a type conversion.
18044 -- Determine variable-ness from the converted expression.
18046 elsif Nkind (P) = N_Type_Conversion
18047 and then not Comes_From_Source (P)
18048 and then Is_Array_Type (Etype (P))
18049 and then Is_Packed (Etype (P))
18051 return Is_Variable (Expression (P));
18054 return Is_Variable (P);
18056 end Is_Variable_Prefix;
18058 -- Start of processing for Is_Variable
18061 -- Special check, allow x'Deref(expr) as a variable
18063 if Nkind (N) = N_Attribute_Reference
18064 and then Attribute_Name (N) = Name_Deref
18069 -- Check if we perform the test on the original node since this may be a
18070 -- test of syntactic categories which must not be disturbed by whatever
18071 -- rewriting might have occurred. For example, an aggregate, which is
18072 -- certainly NOT a variable, could be turned into a variable by
18075 if Use_Original_Node then
18076 Orig_Node := Original_Node (N);
18081 -- Definitely OK if Assignment_OK is set. Since this is something that
18082 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
18084 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
18087 -- Normally we go to the original node, but there is one exception where
18088 -- we use the rewritten node, namely when it is an explicit dereference.
18089 -- The generated code may rewrite a prefix which is an access type with
18090 -- an explicit dereference. The dereference is a variable, even though
18091 -- the original node may not be (since it could be a constant of the
18094 -- In Ada 2005 we have a further case to consider: the prefix may be a
18095 -- function call given in prefix notation. The original node appears to
18096 -- be a selected component, but we need to examine the call.
18098 elsif Nkind (N) = N_Explicit_Dereference
18099 and then Nkind (Orig_Node) /= N_Explicit_Dereference
18100 and then Present (Etype (Orig_Node))
18101 and then Is_Access_Type (Etype (Orig_Node))
18103 -- Note that if the prefix is an explicit dereference that does not
18104 -- come from source, we must check for a rewritten function call in
18105 -- prefixed notation before other forms of rewriting, to prevent a
18109 (Nkind (Orig_Node) = N_Function_Call
18110 and then not Is_Access_Constant (Etype (Prefix (N))))
18112 Is_Variable_Prefix (Original_Node (Prefix (N)));
18114 -- in Ada 2012, the dereference may have been added for a type with
18115 -- a declared implicit dereference aspect. Check that it is not an
18116 -- access to constant.
18118 elsif Nkind (N) = N_Explicit_Dereference
18119 and then Present (Etype (Orig_Node))
18120 and then Ada_Version >= Ada_2012
18121 and then Has_Implicit_Dereference (Etype (Orig_Node))
18123 return not Is_Access_Constant (Etype (Prefix (N)));
18125 -- A function call is never a variable
18127 elsif Nkind (N) = N_Function_Call then
18130 -- All remaining checks use the original node
18132 elsif Is_Entity_Name (Orig_Node)
18133 and then Present (Entity (Orig_Node))
18136 E : constant Entity_Id := Entity (Orig_Node);
18137 K : constant Entity_Kind := Ekind (E);
18140 if Is_Loop_Parameter (E) then
18144 return (K = E_Variable
18145 and then Nkind (Parent (E)) /= N_Exception_Handler)
18146 or else (K = E_Component
18147 and then not In_Protected_Function (E))
18148 or else K = E_Out_Parameter
18149 or else K = E_In_Out_Parameter
18150 or else K = E_Generic_In_Out_Parameter
18152 -- Current instance of type. If this is a protected type, check
18153 -- we are not within the body of one of its protected functions.
18155 or else (Is_Type (E)
18156 and then In_Open_Scopes (E)
18157 and then not In_Protected_Function (E))
18159 or else (Is_Incomplete_Or_Private_Type (E)
18160 and then In_Open_Scopes (Full_View (E)));
18164 case Nkind (Orig_Node) is
18165 when N_Indexed_Component
18168 return Is_Variable_Prefix (Prefix (Orig_Node));
18170 when N_Selected_Component =>
18171 return (Is_Variable (Selector_Name (Orig_Node))
18172 and then Is_Variable_Prefix (Prefix (Orig_Node)))
18174 (Nkind (N) = N_Expanded_Name
18175 and then Scope (Entity (N)) = Entity (Prefix (N)));
18177 -- For an explicit dereference, the type of the prefix cannot
18178 -- be an access to constant or an access to subprogram.
18180 when N_Explicit_Dereference =>
18182 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
18184 return Is_Access_Type (Typ)
18185 and then not Is_Access_Constant (Root_Type (Typ))
18186 and then Ekind (Typ) /= E_Access_Subprogram_Type;
18189 -- The type conversion is the case where we do not deal with the
18190 -- context dependent special case of an actual parameter. Thus
18191 -- the type conversion is only considered a variable for the
18192 -- purposes of this routine if the target type is tagged. However,
18193 -- a type conversion is considered to be a variable if it does not
18194 -- come from source (this deals for example with the conversions
18195 -- of expressions to their actual subtypes).
18197 when N_Type_Conversion =>
18198 return Is_Variable (Expression (Orig_Node))
18200 (not Comes_From_Source (Orig_Node)
18202 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
18204 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
18206 -- GNAT allows an unchecked type conversion as a variable. This
18207 -- only affects the generation of internal expanded code, since
18208 -- calls to instantiations of Unchecked_Conversion are never
18209 -- considered variables (since they are function calls).
18211 when N_Unchecked_Type_Conversion =>
18212 return Is_Variable (Expression (Orig_Node));
18220 ---------------------------
18221 -- Is_Visibly_Controlled --
18222 ---------------------------
18224 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
18225 Root : constant Entity_Id := Root_Type (T);
18227 return Chars (Scope (Root)) = Name_Finalization
18228 and then Chars (Scope (Scope (Root))) = Name_Ada
18229 and then Scope (Scope (Scope (Root))) = Standard_Standard;
18230 end Is_Visibly_Controlled;
18232 --------------------------
18233 -- Is_Volatile_Function --
18234 --------------------------
18236 function Is_Volatile_Function (Func_Id : Entity_Id) return Boolean is
18238 pragma Assert (Ekind_In (Func_Id, E_Function, E_Generic_Function));
18240 -- A function declared within a protected type is volatile
18242 if Is_Protected_Type (Scope (Func_Id)) then
18245 -- An instance of Ada.Unchecked_Conversion is a volatile function if
18246 -- either the source or the target are effectively volatile.
18248 elsif Is_Unchecked_Conversion_Instance (Func_Id)
18249 and then Has_Effectively_Volatile_Profile (Func_Id)
18253 -- Otherwise the function is treated as volatile if it is subject to
18254 -- enabled pragma Volatile_Function.
18258 Is_Enabled_Pragma (Get_Pragma (Func_Id, Pragma_Volatile_Function));
18260 end Is_Volatile_Function;
18262 ------------------------
18263 -- Is_Volatile_Object --
18264 ------------------------
18266 function Is_Volatile_Object (N : Node_Id) return Boolean is
18267 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
18268 -- If prefix is an implicit dereference, examine designated type
18270 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
18271 -- Determines if given object has volatile components
18273 ------------------------
18274 -- Is_Volatile_Prefix --
18275 ------------------------
18277 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
18278 Typ : constant Entity_Id := Etype (N);
18281 if Is_Access_Type (Typ) then
18283 Dtyp : constant Entity_Id := Designated_Type (Typ);
18286 return Is_Volatile (Dtyp)
18287 or else Has_Volatile_Components (Dtyp);
18291 return Object_Has_Volatile_Components (N);
18293 end Is_Volatile_Prefix;
18295 ------------------------------------
18296 -- Object_Has_Volatile_Components --
18297 ------------------------------------
18299 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
18300 Typ : constant Entity_Id := Etype (N);
18303 if Is_Volatile (Typ)
18304 or else Has_Volatile_Components (Typ)
18308 elsif Is_Entity_Name (N)
18309 and then (Has_Volatile_Components (Entity (N))
18310 or else Is_Volatile (Entity (N)))
18314 elsif Nkind (N) = N_Indexed_Component
18315 or else Nkind (N) = N_Selected_Component
18317 return Is_Volatile_Prefix (Prefix (N));
18322 end Object_Has_Volatile_Components;
18324 -- Start of processing for Is_Volatile_Object
18327 if Nkind (N) = N_Defining_Identifier then
18328 return Is_Volatile (N) or else Is_Volatile (Etype (N));
18330 elsif Nkind (N) = N_Expanded_Name then
18331 return Is_Volatile_Object (Entity (N));
18333 elsif Is_Volatile (Etype (N))
18334 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
18338 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component)
18339 and then Is_Volatile_Prefix (Prefix (N))
18343 elsif Nkind (N) = N_Selected_Component
18344 and then Is_Volatile (Entity (Selector_Name (N)))
18351 end Is_Volatile_Object;
18353 -----------------------------
18354 -- Iterate_Call_Parameters --
18355 -----------------------------
18357 procedure Iterate_Call_Parameters (Call : Node_Id) is
18358 Actual : Node_Id := First_Actual (Call);
18359 Formal : Entity_Id := First_Formal (Get_Called_Entity (Call));
18362 while Present (Formal) and then Present (Actual) loop
18363 Handle_Parameter (Formal, Actual);
18365 Next_Formal (Formal);
18366 Next_Actual (Actual);
18369 pragma Assert (No (Formal));
18370 pragma Assert (No (Actual));
18371 end Iterate_Call_Parameters;
18373 ---------------------------
18374 -- Itype_Has_Declaration --
18375 ---------------------------
18377 function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
18379 pragma Assert (Is_Itype (Id));
18380 return Present (Parent (Id))
18381 and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
18382 N_Subtype_Declaration)
18383 and then Defining_Entity (Parent (Id)) = Id;
18384 end Itype_Has_Declaration;
18386 -------------------------
18387 -- Kill_Current_Values --
18388 -------------------------
18390 procedure Kill_Current_Values
18392 Last_Assignment_Only : Boolean := False)
18395 if Is_Assignable (Ent) then
18396 Set_Last_Assignment (Ent, Empty);
18399 if Is_Object (Ent) then
18400 if not Last_Assignment_Only then
18402 Set_Current_Value (Ent, Empty);
18404 -- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
18405 -- for a constant. Once the constant is elaborated, its value is
18406 -- not changed, therefore the associated flags that describe the
18407 -- value should not be modified either.
18409 if Ekind (Ent) = E_Constant then
18412 -- Non-constant entities
18415 if not Can_Never_Be_Null (Ent) then
18416 Set_Is_Known_Non_Null (Ent, False);
18419 Set_Is_Known_Null (Ent, False);
18421 -- Reset the Is_Known_Valid flag unless the type is always
18422 -- valid. This does not apply to a loop parameter because its
18423 -- bounds are defined by the loop header and therefore always
18426 if not Is_Known_Valid (Etype (Ent))
18427 and then Ekind (Ent) /= E_Loop_Parameter
18429 Set_Is_Known_Valid (Ent, False);
18434 end Kill_Current_Values;
18436 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
18439 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
18440 -- Clear current value for entity E and all entities chained to E
18442 ------------------------------------------
18443 -- Kill_Current_Values_For_Entity_Chain --
18444 ------------------------------------------
18446 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
18450 while Present (Ent) loop
18451 Kill_Current_Values (Ent, Last_Assignment_Only);
18454 end Kill_Current_Values_For_Entity_Chain;
18456 -- Start of processing for Kill_Current_Values
18459 -- Kill all saved checks, a special case of killing saved values
18461 if not Last_Assignment_Only then
18465 -- Loop through relevant scopes, which includes the current scope and
18466 -- any parent scopes if the current scope is a block or a package.
18468 S := Current_Scope;
18471 -- Clear current values of all entities in current scope
18473 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
18475 -- If scope is a package, also clear current values of all private
18476 -- entities in the scope.
18478 if Is_Package_Or_Generic_Package (S)
18479 or else Is_Concurrent_Type (S)
18481 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
18484 -- If this is a not a subprogram, deal with parents
18486 if not Is_Subprogram (S) then
18488 exit Scope_Loop when S = Standard_Standard;
18492 end loop Scope_Loop;
18493 end Kill_Current_Values;
18495 --------------------------
18496 -- Kill_Size_Check_Code --
18497 --------------------------
18499 procedure Kill_Size_Check_Code (E : Entity_Id) is
18501 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
18502 and then Present (Size_Check_Code (E))
18504 Remove (Size_Check_Code (E));
18505 Set_Size_Check_Code (E, Empty);
18507 end Kill_Size_Check_Code;
18509 --------------------
18510 -- Known_Non_Null --
18511 --------------------
18513 function Known_Non_Null (N : Node_Id) return Boolean is
18514 Status : constant Null_Status_Kind := Null_Status (N);
18521 -- The expression yields a non-null value ignoring simple flow analysis
18523 if Status = Is_Non_Null then
18526 -- Otherwise check whether N is a reference to an entity that appears
18527 -- within a conditional construct.
18529 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
18531 -- First check if we are in decisive conditional
18533 Get_Current_Value_Condition (N, Op, Val);
18535 if Known_Null (Val) then
18536 if Op = N_Op_Eq then
18538 elsif Op = N_Op_Ne then
18543 -- If OK to do replacement, test Is_Known_Non_Null flag
18547 if OK_To_Do_Constant_Replacement (Id) then
18548 return Is_Known_Non_Null (Id);
18552 -- Otherwise it is not possible to determine whether N yields a non-null
18556 end Known_Non_Null;
18562 function Known_Null (N : Node_Id) return Boolean is
18563 Status : constant Null_Status_Kind := Null_Status (N);
18570 -- The expression yields a null value ignoring simple flow analysis
18572 if Status = Is_Null then
18575 -- Otherwise check whether N is a reference to an entity that appears
18576 -- within a conditional construct.
18578 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
18580 -- First check if we are in decisive conditional
18582 Get_Current_Value_Condition (N, Op, Val);
18584 if Known_Null (Val) then
18585 if Op = N_Op_Eq then
18587 elsif Op = N_Op_Ne then
18592 -- If OK to do replacement, test Is_Known_Null flag
18596 if OK_To_Do_Constant_Replacement (Id) then
18597 return Is_Known_Null (Id);
18601 -- Otherwise it is not possible to determine whether N yields a null
18607 --------------------------
18608 -- Known_To_Be_Assigned --
18609 --------------------------
18611 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
18612 P : constant Node_Id := Parent (N);
18617 -- Test left side of assignment
18619 when N_Assignment_Statement =>
18620 return N = Name (P);
18622 -- Function call arguments are never lvalues
18624 when N_Function_Call =>
18627 -- Positional parameter for procedure or accept call
18629 when N_Accept_Statement
18630 | N_Procedure_Call_Statement
18638 Proc := Get_Subprogram_Entity (P);
18644 -- If we are not a list member, something is strange, so
18645 -- be conservative and return False.
18647 if not Is_List_Member (N) then
18651 -- We are going to find the right formal by stepping forward
18652 -- through the formals, as we step backwards in the actuals.
18654 Form := First_Formal (Proc);
18657 -- If no formal, something is weird, so be conservative
18658 -- and return False.
18665 exit when No (Act);
18666 Next_Formal (Form);
18669 return Ekind (Form) /= E_In_Parameter;
18672 -- Named parameter for procedure or accept call
18674 when N_Parameter_Association =>
18680 Proc := Get_Subprogram_Entity (Parent (P));
18686 -- Loop through formals to find the one that matches
18688 Form := First_Formal (Proc);
18690 -- If no matching formal, that's peculiar, some kind of
18691 -- previous error, so return False to be conservative.
18692 -- Actually this also happens in legal code in the case
18693 -- where P is a parameter association for an Extra_Formal???
18699 -- Else test for match
18701 if Chars (Form) = Chars (Selector_Name (P)) then
18702 return Ekind (Form) /= E_In_Parameter;
18705 Next_Formal (Form);
18709 -- Test for appearing in a conversion that itself appears
18710 -- in an lvalue context, since this should be an lvalue.
18712 when N_Type_Conversion =>
18713 return Known_To_Be_Assigned (P);
18715 -- All other references are definitely not known to be modifications
18720 end Known_To_Be_Assigned;
18722 ---------------------------
18723 -- Last_Source_Statement --
18724 ---------------------------
18726 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
18730 N := Last (Statements (HSS));
18731 while Present (N) loop
18732 exit when Comes_From_Source (N);
18737 end Last_Source_Statement;
18739 -----------------------
18740 -- Mark_Coextensions --
18741 -----------------------
18743 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
18744 Is_Dynamic : Boolean;
18745 -- Indicates whether the context causes nested coextensions to be
18746 -- dynamic or static
18748 function Mark_Allocator (N : Node_Id) return Traverse_Result;
18749 -- Recognize an allocator node and label it as a dynamic coextension
18751 --------------------
18752 -- Mark_Allocator --
18753 --------------------
18755 function Mark_Allocator (N : Node_Id) return Traverse_Result is
18757 if Nkind (N) = N_Allocator then
18759 Set_Is_Static_Coextension (N, False);
18760 Set_Is_Dynamic_Coextension (N);
18762 -- If the allocator expression is potentially dynamic, it may
18763 -- be expanded out of order and require dynamic allocation
18764 -- anyway, so we treat the coextension itself as dynamic.
18765 -- Potential optimization ???
18767 elsif Nkind (Expression (N)) = N_Qualified_Expression
18768 and then Nkind (Expression (Expression (N))) = N_Op_Concat
18770 Set_Is_Static_Coextension (N, False);
18771 Set_Is_Dynamic_Coextension (N);
18773 Set_Is_Dynamic_Coextension (N, False);
18774 Set_Is_Static_Coextension (N);
18779 end Mark_Allocator;
18781 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
18783 -- Start of processing for Mark_Coextensions
18786 -- An allocator that appears on the right-hand side of an assignment is
18787 -- treated as a potentially dynamic coextension when the right-hand side
18788 -- is an allocator or a qualified expression.
18790 -- Obj := new ...'(new Coextension ...);
18792 if Nkind (Context_Nod) = N_Assignment_Statement then
18794 Nkind_In (Expression (Context_Nod), N_Allocator,
18795 N_Qualified_Expression);
18797 -- An allocator that appears within the expression of a simple return
18798 -- statement is treated as a potentially dynamic coextension when the
18799 -- expression is either aggregate, allocator, or qualified expression.
18801 -- return (new Coextension ...);
18802 -- return new ...'(new Coextension ...);
18804 elsif Nkind (Context_Nod) = N_Simple_Return_Statement then
18806 Nkind_In (Expression (Context_Nod), N_Aggregate,
18808 N_Qualified_Expression);
18810 -- An alloctor that appears within the initialization expression of an
18811 -- object declaration is considered a potentially dynamic coextension
18812 -- when the initialization expression is an allocator or a qualified
18815 -- Obj : ... := new ...'(new Coextension ...);
18817 -- A similar case arises when the object declaration is part of an
18818 -- extended return statement.
18820 -- return Obj : ... := new ...'(new Coextension ...);
18821 -- return Obj : ... := (new Coextension ...);
18823 elsif Nkind (Context_Nod) = N_Object_Declaration then
18825 Nkind_In (Root_Nod, N_Allocator, N_Qualified_Expression)
18827 Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
18829 -- This routine should not be called with constructs that cannot contain
18833 raise Program_Error;
18836 Mark_Allocators (Root_Nod);
18837 end Mark_Coextensions;
18839 ---------------------------------
18840 -- Mark_Elaboration_Attributes --
18841 ---------------------------------
18843 procedure Mark_Elaboration_Attributes
18844 (N_Id : Node_Or_Entity_Id;
18845 Checks : Boolean := False;
18846 Level : Boolean := False;
18847 Modes : Boolean := False;
18848 Warnings : Boolean := False)
18850 function Elaboration_Checks_OK
18851 (Target_Id : Entity_Id;
18852 Context_Id : Entity_Id) return Boolean;
18853 -- Determine whether elaboration checks are enabled for target Target_Id
18854 -- which resides within context Context_Id.
18856 procedure Mark_Elaboration_Attributes_Id (Id : Entity_Id);
18857 -- Preserve relevant attributes of the context in arbitrary entity Id
18859 procedure Mark_Elaboration_Attributes_Node (N : Node_Id);
18860 -- Preserve relevant attributes of the context in arbitrary node N
18862 ---------------------------
18863 -- Elaboration_Checks_OK --
18864 ---------------------------
18866 function Elaboration_Checks_OK
18867 (Target_Id : Entity_Id;
18868 Context_Id : Entity_Id) return Boolean
18870 Encl_Scop : Entity_Id;
18873 -- Elaboration checks are suppressed for the target
18875 if Elaboration_Checks_Suppressed (Target_Id) then
18879 -- Otherwise elaboration checks are OK for the target, but may be
18880 -- suppressed for the context where the target is declared.
18882 Encl_Scop := Context_Id;
18883 while Present (Encl_Scop) and then Encl_Scop /= Standard_Standard loop
18884 if Elaboration_Checks_Suppressed (Encl_Scop) then
18888 Encl_Scop := Scope (Encl_Scop);
18891 -- Neither the target nor its declarative context have elaboration
18892 -- checks suppressed.
18895 end Elaboration_Checks_OK;
18897 ------------------------------------
18898 -- Mark_Elaboration_Attributes_Id --
18899 ------------------------------------
18901 procedure Mark_Elaboration_Attributes_Id (Id : Entity_Id) is
18903 -- Mark the status of elaboration checks in effect. Do not reset the
18904 -- status in case the entity is reanalyzed with checks suppressed.
18906 if Checks and then not Is_Elaboration_Checks_OK_Id (Id) then
18907 Set_Is_Elaboration_Checks_OK_Id (Id,
18908 Elaboration_Checks_OK
18910 Context_Id => Scope (Id)));
18913 -- Mark the status of elaboration warnings in effect. Do not reset
18914 -- the status in case the entity is reanalyzed with warnings off.
18916 if Warnings and then not Is_Elaboration_Warnings_OK_Id (Id) then
18917 Set_Is_Elaboration_Warnings_OK_Id (Id, Elab_Warnings);
18919 end Mark_Elaboration_Attributes_Id;
18921 --------------------------------------
18922 -- Mark_Elaboration_Attributes_Node --
18923 --------------------------------------
18925 procedure Mark_Elaboration_Attributes_Node (N : Node_Id) is
18926 function Extract_Name (N : Node_Id) return Node_Id;
18927 -- Obtain the Name attribute of call or instantiation N
18933 function Extract_Name (N : Node_Id) return Node_Id is
18939 -- A call to an entry family appears in indexed form
18941 if Nkind (Nam) = N_Indexed_Component then
18942 Nam := Prefix (Nam);
18945 -- The name may also appear in qualified form
18947 if Nkind (Nam) = N_Selected_Component then
18948 Nam := Selector_Name (Nam);
18956 Context_Id : Entity_Id;
18959 -- Start of processing for Mark_Elaboration_Attributes_Node
18962 -- Mark the status of elaboration checks in effect. Do not reset the
18963 -- status in case the node is reanalyzed with checks suppressed.
18965 if Checks and then not Is_Elaboration_Checks_OK_Node (N) then
18967 -- Assignments, attribute references, and variable references do
18968 -- not have a "declarative" context.
18970 Context_Id := Empty;
18972 -- The status of elaboration checks for calls and instantiations
18973 -- depends on the most recent pragma Suppress/Unsuppress, as well
18974 -- as the suppression status of the context where the target is
18978 -- function Func ...;
18982 -- procedure Main is
18983 -- pragma Suppress (Elaboration_Checks, Pack);
18984 -- X : ... := Pack.Func;
18987 -- In the example above, the call to Func has elaboration checks
18988 -- enabled because there is no active general purpose suppression
18989 -- pragma, however the elaboration checks of Pack are explicitly
18990 -- suppressed. As a result the elaboration checks of the call must
18991 -- be disabled in order to preserve this dependency.
18993 if Nkind_In (N, N_Entry_Call_Statement,
18995 N_Function_Instantiation,
18996 N_Package_Instantiation,
18997 N_Procedure_Call_Statement,
18998 N_Procedure_Instantiation)
19000 Nam := Extract_Name (N);
19002 if Is_Entity_Name (Nam) and then Present (Entity (Nam)) then
19003 Context_Id := Scope (Entity (Nam));
19007 Set_Is_Elaboration_Checks_OK_Node (N,
19008 Elaboration_Checks_OK
19009 (Target_Id => Empty,
19010 Context_Id => Context_Id));
19013 -- Mark the enclosing level of the node. Do not reset the status in
19014 -- case the node is relocated and reanalyzed.
19016 if Level and then not Is_Declaration_Level_Node (N) then
19017 Set_Is_Declaration_Level_Node (N,
19018 Find_Enclosing_Level (N) = Declaration_Level);
19021 -- Mark the Ghost and SPARK mode in effect
19024 if Ghost_Mode = Ignore then
19025 Set_Is_Ignored_Ghost_Node (N);
19028 if SPARK_Mode = On then
19029 Set_Is_SPARK_Mode_On_Node (N);
19033 -- Mark the status of elaboration warnings in effect. Do not reset
19034 -- the status in case the node is reanalyzed with warnings off.
19036 if Warnings and then not Is_Elaboration_Warnings_OK_Node (N) then
19037 Set_Is_Elaboration_Warnings_OK_Node (N, Elab_Warnings);
19039 end Mark_Elaboration_Attributes_Node;
19041 -- Start of processing for Mark_Elaboration_Attributes
19044 -- Do not capture any elaboration-related attributes when switch -gnatH
19045 -- (legacy elaboration checking mode enabled) is in effect because the
19046 -- attributes are useless to the legacy model.
19048 if Legacy_Elaboration_Checks then
19052 if Nkind (N_Id) in N_Entity then
19053 Mark_Elaboration_Attributes_Id (N_Id);
19055 Mark_Elaboration_Attributes_Node (N_Id);
19057 end Mark_Elaboration_Attributes;
19059 ----------------------------------------
19060 -- Mark_Save_Invocation_Graph_Of_Body --
19061 ----------------------------------------
19063 procedure Mark_Save_Invocation_Graph_Of_Body is
19064 Main : constant Node_Id := Cunit (Main_Unit);
19065 Main_Unit : constant Node_Id := Unit (Main);
19066 Aux_Id : Entity_Id;
19069 Set_Save_Invocation_Graph_Of_Body (Main);
19071 -- Assume that the main unit does not have a complimentary unit
19075 -- Obtain the complimentary unit of the main unit
19077 if Nkind_In (Main_Unit, N_Generic_Package_Declaration,
19078 N_Generic_Subprogram_Declaration,
19079 N_Package_Declaration,
19080 N_Subprogram_Declaration)
19082 Aux_Id := Corresponding_Body (Main_Unit);
19084 elsif Nkind_In (Main_Unit, N_Package_Body,
19086 N_Subprogram_Renaming_Declaration)
19088 Aux_Id := Corresponding_Spec (Main_Unit);
19091 if Present (Aux_Id) then
19092 Set_Save_Invocation_Graph_Of_Body
19093 (Parent (Unit_Declaration_Node (Aux_Id)));
19095 end Mark_Save_Invocation_Graph_Of_Body;
19097 ----------------------------------
19098 -- Matching_Static_Array_Bounds --
19099 ----------------------------------
19101 function Matching_Static_Array_Bounds
19103 R_Typ : Node_Id) return Boolean
19105 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
19106 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
19108 L_Index : Node_Id := Empty; -- init to ...
19109 R_Index : Node_Id := Empty; -- ...avoid warnings
19118 if L_Ndims /= R_Ndims then
19122 -- Unconstrained types do not have static bounds
19124 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
19128 -- First treat specially the first dimension, as the lower bound and
19129 -- length of string literals are not stored like those of arrays.
19131 if Ekind (L_Typ) = E_String_Literal_Subtype then
19132 L_Low := String_Literal_Low_Bound (L_Typ);
19133 L_Len := String_Literal_Length (L_Typ);
19135 L_Index := First_Index (L_Typ);
19136 Get_Index_Bounds (L_Index, L_Low, L_High);
19138 if Is_OK_Static_Expression (L_Low)
19140 Is_OK_Static_Expression (L_High)
19142 if Expr_Value (L_High) < Expr_Value (L_Low) then
19145 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
19152 if Ekind (R_Typ) = E_String_Literal_Subtype then
19153 R_Low := String_Literal_Low_Bound (R_Typ);
19154 R_Len := String_Literal_Length (R_Typ);
19156 R_Index := First_Index (R_Typ);
19157 Get_Index_Bounds (R_Index, R_Low, R_High);
19159 if Is_OK_Static_Expression (R_Low)
19161 Is_OK_Static_Expression (R_High)
19163 if Expr_Value (R_High) < Expr_Value (R_Low) then
19166 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
19173 if (Is_OK_Static_Expression (L_Low)
19175 Is_OK_Static_Expression (R_Low))
19176 and then Expr_Value (L_Low) = Expr_Value (R_Low)
19177 and then L_Len = R_Len
19184 -- Then treat all other dimensions
19186 for Indx in 2 .. L_Ndims loop
19190 Get_Index_Bounds (L_Index, L_Low, L_High);
19191 Get_Index_Bounds (R_Index, R_Low, R_High);
19193 if (Is_OK_Static_Expression (L_Low) and then
19194 Is_OK_Static_Expression (L_High) and then
19195 Is_OK_Static_Expression (R_Low) and then
19196 Is_OK_Static_Expression (R_High))
19197 and then (Expr_Value (L_Low) = Expr_Value (R_Low)
19199 Expr_Value (L_High) = Expr_Value (R_High))
19207 -- If we fall through the loop, all indexes matched
19210 end Matching_Static_Array_Bounds;
19212 -------------------
19213 -- May_Be_Lvalue --
19214 -------------------
19216 function May_Be_Lvalue (N : Node_Id) return Boolean is
19217 P : constant Node_Id := Parent (N);
19222 -- Test left side of assignment
19224 when N_Assignment_Statement =>
19225 return N = Name (P);
19227 -- Test prefix of component or attribute. Note that the prefix of an
19228 -- explicit or implicit dereference cannot be an l-value. In the case
19229 -- of a 'Read attribute, the reference can be an actual in the
19230 -- argument list of the attribute.
19232 when N_Attribute_Reference =>
19233 return (N = Prefix (P)
19234 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P)))
19236 Attribute_Name (P) = Name_Read;
19238 -- For an expanded name, the name is an lvalue if the expanded name
19239 -- is an lvalue, but the prefix is never an lvalue, since it is just
19240 -- the scope where the name is found.
19242 when N_Expanded_Name =>
19243 if N = Prefix (P) then
19244 return May_Be_Lvalue (P);
19249 -- For a selected component A.B, A is certainly an lvalue if A.B is.
19250 -- B is a little interesting, if we have A.B := 3, there is some
19251 -- discussion as to whether B is an lvalue or not, we choose to say
19252 -- it is. Note however that A is not an lvalue if it is of an access
19253 -- type since this is an implicit dereference.
19255 when N_Selected_Component =>
19257 and then Present (Etype (N))
19258 and then Is_Access_Type (Etype (N))
19262 return May_Be_Lvalue (P);
19265 -- For an indexed component or slice, the index or slice bounds is
19266 -- never an lvalue. The prefix is an lvalue if the indexed component
19267 -- or slice is an lvalue, except if it is an access type, where we
19268 -- have an implicit dereference.
19270 when N_Indexed_Component
19274 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
19278 return May_Be_Lvalue (P);
19281 -- Prefix of a reference is an lvalue if the reference is an lvalue
19283 when N_Reference =>
19284 return May_Be_Lvalue (P);
19286 -- Prefix of explicit dereference is never an lvalue
19288 when N_Explicit_Dereference =>
19291 -- Positional parameter for subprogram, entry, or accept call.
19292 -- In older versions of Ada function call arguments are never
19293 -- lvalues. In Ada 2012 functions can have in-out parameters.
19295 when N_Accept_Statement
19296 | N_Entry_Call_Statement
19297 | N_Subprogram_Call
19299 if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
19303 -- The following mechanism is clumsy and fragile. A single flag
19304 -- set in Resolve_Actuals would be preferable ???
19312 Proc := Get_Subprogram_Entity (P);
19318 -- If we are not a list member, something is strange, so be
19319 -- conservative and return True.
19321 if not Is_List_Member (N) then
19325 -- We are going to find the right formal by stepping forward
19326 -- through the formals, as we step backwards in the actuals.
19328 Form := First_Formal (Proc);
19331 -- If no formal, something is weird, so be conservative and
19339 exit when No (Act);
19340 Next_Formal (Form);
19343 return Ekind (Form) /= E_In_Parameter;
19346 -- Named parameter for procedure or accept call
19348 when N_Parameter_Association =>
19354 Proc := Get_Subprogram_Entity (Parent (P));
19360 -- Loop through formals to find the one that matches
19362 Form := First_Formal (Proc);
19364 -- If no matching formal, that's peculiar, some kind of
19365 -- previous error, so return True to be conservative.
19366 -- Actually happens with legal code for an unresolved call
19367 -- where we may get the wrong homonym???
19373 -- Else test for match
19375 if Chars (Form) = Chars (Selector_Name (P)) then
19376 return Ekind (Form) /= E_In_Parameter;
19379 Next_Formal (Form);
19383 -- Test for appearing in a conversion that itself appears in an
19384 -- lvalue context, since this should be an lvalue.
19386 when N_Type_Conversion =>
19387 return May_Be_Lvalue (P);
19389 -- Test for appearance in object renaming declaration
19391 when N_Object_Renaming_Declaration =>
19394 -- All other references are definitely not lvalues
19405 function Might_Raise (N : Node_Id) return Boolean is
19406 Result : Boolean := False;
19408 function Process (N : Node_Id) return Traverse_Result;
19409 -- Set Result to True if we find something that could raise an exception
19415 function Process (N : Node_Id) return Traverse_Result is
19417 if Nkind_In (N, N_Procedure_Call_Statement,
19420 N_Raise_Constraint_Error,
19421 N_Raise_Program_Error,
19422 N_Raise_Storage_Error)
19431 procedure Set_Result is new Traverse_Proc (Process);
19433 -- Start of processing for Might_Raise
19436 -- False if exceptions can't be propagated
19438 if No_Exception_Handlers_Set then
19442 -- If the checks handled by the back end are not disabled, we cannot
19443 -- ensure that no exception will be raised.
19445 if not Access_Checks_Suppressed (Empty)
19446 or else not Discriminant_Checks_Suppressed (Empty)
19447 or else not Range_Checks_Suppressed (Empty)
19448 or else not Index_Checks_Suppressed (Empty)
19449 or else Opt.Stack_Checking_Enabled
19458 --------------------------------
19459 -- Nearest_Enclosing_Instance --
19460 --------------------------------
19462 function Nearest_Enclosing_Instance (E : Entity_Id) return Entity_Id is
19467 while Present (Inst) and then Inst /= Standard_Standard loop
19468 if Is_Generic_Instance (Inst) then
19472 Inst := Scope (Inst);
19476 end Nearest_Enclosing_Instance;
19478 ------------------------
19479 -- Needs_Finalization --
19480 ------------------------
19482 function Needs_Finalization (Typ : Entity_Id) return Boolean is
19483 function Has_Some_Controlled_Component
19484 (Input_Typ : Entity_Id) return Boolean;
19485 -- Determine whether type Input_Typ has at least one controlled
19488 -----------------------------------
19489 -- Has_Some_Controlled_Component --
19490 -----------------------------------
19492 function Has_Some_Controlled_Component
19493 (Input_Typ : Entity_Id) return Boolean
19498 -- When a type is already frozen and has at least one controlled
19499 -- component, or is manually decorated, it is sufficient to inspect
19500 -- flag Has_Controlled_Component.
19502 if Has_Controlled_Component (Input_Typ) then
19505 -- Otherwise inspect the internals of the type
19507 elsif not Is_Frozen (Input_Typ) then
19508 if Is_Array_Type (Input_Typ) then
19509 return Needs_Finalization (Component_Type (Input_Typ));
19511 elsif Is_Record_Type (Input_Typ) then
19512 Comp := First_Component (Input_Typ);
19513 while Present (Comp) loop
19514 if Needs_Finalization (Etype (Comp)) then
19518 Next_Component (Comp);
19524 end Has_Some_Controlled_Component;
19526 -- Start of processing for Needs_Finalization
19529 -- Certain run-time configurations and targets do not provide support
19530 -- for controlled types.
19532 if Restriction_Active (No_Finalization) then
19535 -- C++ types are not considered controlled. It is assumed that the non-
19536 -- Ada side will handle their clean up.
19538 elsif Convention (Typ) = Convention_CPP then
19541 -- Class-wide types are treated as controlled because derivations from
19542 -- the root type may introduce controlled components.
19544 elsif Is_Class_Wide_Type (Typ) then
19547 -- Concurrent types are controlled as long as their corresponding record
19550 elsif Is_Concurrent_Type (Typ)
19551 and then Present (Corresponding_Record_Type (Typ))
19552 and then Needs_Finalization (Corresponding_Record_Type (Typ))
19556 -- Otherwise the type is controlled when it is either derived from type
19557 -- [Limited_]Controlled and not subject to aspect Disable_Controlled, or
19558 -- contains at least one controlled component.
19562 Is_Controlled (Typ) or else Has_Some_Controlled_Component (Typ);
19564 end Needs_Finalization;
19566 ----------------------
19567 -- Needs_One_Actual --
19568 ----------------------
19570 function Needs_One_Actual (E : Entity_Id) return Boolean is
19571 Formal : Entity_Id;
19574 -- Ada 2005 or later, and formals present. The first formal must be
19575 -- of a type that supports prefix notation: a controlling argument,
19576 -- a class-wide type, or an access to such.
19578 if Ada_Version >= Ada_2005
19579 and then Present (First_Formal (E))
19580 and then No (Default_Value (First_Formal (E)))
19582 (Is_Controlling_Formal (First_Formal (E))
19583 or else Is_Class_Wide_Type (Etype (First_Formal (E)))
19584 or else Is_Anonymous_Access_Type (Etype (First_Formal (E))))
19586 Formal := Next_Formal (First_Formal (E));
19587 while Present (Formal) loop
19588 if No (Default_Value (Formal)) then
19592 Next_Formal (Formal);
19597 -- Ada 83/95 or no formals
19602 end Needs_One_Actual;
19604 ---------------------------------
19605 -- Needs_Simple_Initialization --
19606 ---------------------------------
19608 function Needs_Simple_Initialization
19610 Consider_IS : Boolean := True) return Boolean
19612 Consider_IS_NS : constant Boolean :=
19613 Normalize_Scalars or (Initialize_Scalars and Consider_IS);
19616 -- Never need initialization if it is suppressed
19618 if Initialization_Suppressed (Typ) then
19622 -- Check for private type, in which case test applies to the underlying
19623 -- type of the private type.
19625 if Is_Private_Type (Typ) then
19627 RT : constant Entity_Id := Underlying_Type (Typ);
19629 if Present (RT) then
19630 return Needs_Simple_Initialization (RT);
19636 -- Scalar type with Default_Value aspect requires initialization
19638 elsif Is_Scalar_Type (Typ) and then Has_Default_Aspect (Typ) then
19641 -- Cases needing simple initialization are access types, and, if pragma
19642 -- Normalize_Scalars or Initialize_Scalars is in effect, then all scalar
19645 elsif Is_Access_Type (Typ)
19646 or else (Consider_IS_NS and then (Is_Scalar_Type (Typ)))
19650 -- If Initialize/Normalize_Scalars is in effect, string objects also
19651 -- need initialization, unless they are created in the course of
19652 -- expanding an aggregate (since in the latter case they will be
19653 -- filled with appropriate initializing values before they are used).
19655 elsif Consider_IS_NS
19656 and then Is_Standard_String_Type (Typ)
19658 (not Is_Itype (Typ)
19659 or else Nkind (Associated_Node_For_Itype (Typ)) /= N_Aggregate)
19666 end Needs_Simple_Initialization;
19668 -------------------------------------
19669 -- Needs_Variable_Reference_Marker --
19670 -------------------------------------
19672 function Needs_Variable_Reference_Marker
19674 Calls_OK : Boolean) return Boolean
19676 function Within_Suitable_Context (Ref : Node_Id) return Boolean;
19677 -- Deteremine whether variable reference Ref appears within a suitable
19678 -- context that allows the creation of a marker.
19680 -----------------------------
19681 -- Within_Suitable_Context --
19682 -----------------------------
19684 function Within_Suitable_Context (Ref : Node_Id) return Boolean is
19689 while Present (Par) loop
19691 -- The context is not suitable when the reference appears within
19692 -- the formal part of an instantiation which acts as compilation
19693 -- unit because there is no proper list for the insertion of the
19696 if Nkind (Par) = N_Generic_Association
19697 and then Nkind (Parent (Par)) in N_Generic_Instantiation
19698 and then Nkind (Parent (Parent (Par))) = N_Compilation_Unit
19702 -- The context is not suitable when the reference appears within
19703 -- a pragma. If the pragma has run-time semantics, the reference
19704 -- will be reconsidered once the pragma is expanded.
19706 elsif Nkind (Par) = N_Pragma then
19709 -- The context is not suitable when the reference appears within a
19710 -- subprogram call, and the caller requests this behavior.
19713 and then Nkind_In (Par, N_Entry_Call_Statement,
19715 N_Procedure_Call_Statement)
19719 -- Prevent the search from going too far
19721 elsif Is_Body_Or_Package_Declaration (Par) then
19725 Par := Parent (Par);
19729 end Within_Suitable_Context;
19734 Var_Id : Entity_Id;
19736 -- Start of processing for Needs_Variable_Reference_Marker
19739 -- No marker needs to be created when switch -gnatH (legacy elaboration
19740 -- checking mode enabled) is in effect because the legacy ABE mechanism
19741 -- does not use markers.
19743 if Legacy_Elaboration_Checks then
19746 -- No marker needs to be created for ASIS because ABE diagnostics and
19747 -- checks are not performed in this mode.
19749 elsif ASIS_Mode then
19752 -- No marker needs to be created when the reference is preanalyzed
19753 -- because the marker will be inserted in the wrong place.
19755 elsif Preanalysis_Active then
19758 -- Only references warrant a marker
19760 elsif not Nkind_In (N, N_Expanded_Name, N_Identifier) then
19763 -- Only source references warrant a marker
19765 elsif not Comes_From_Source (N) then
19768 -- No marker needs to be created when the reference is erroneous, left
19769 -- in a bad state, or does not denote a variable.
19771 elsif not (Present (Entity (N))
19772 and then Ekind (Entity (N)) = E_Variable
19773 and then Entity (N) /= Any_Id)
19778 Var_Id := Entity (N);
19779 Prag := SPARK_Pragma (Var_Id);
19781 -- Both the variable and reference must appear in SPARK_Mode On regions
19782 -- because this elaboration scenario falls under the SPARK rules.
19784 if not (Comes_From_Source (Var_Id)
19785 and then Present (Prag)
19786 and then Get_SPARK_Mode_From_Annotation (Prag) = On
19787 and then Is_SPARK_Mode_On_Node (N))
19791 -- No marker needs to be created when the reference does not appear
19792 -- within a suitable context (see body for details).
19794 -- Performance note: parent traversal
19796 elsif not Within_Suitable_Context (N) then
19800 -- At this point it is known that the variable reference will play a
19801 -- role in ABE diagnostics and requires a marker.
19804 end Needs_Variable_Reference_Marker;
19806 ------------------------
19807 -- New_Copy_List_Tree --
19808 ------------------------
19810 function New_Copy_List_Tree (List : List_Id) return List_Id is
19815 if List = No_List then
19822 while Present (E) loop
19823 Append (New_Copy_Tree (E), NL);
19829 end New_Copy_List_Tree;
19831 -------------------
19832 -- New_Copy_Tree --
19833 -------------------
19835 -- The following tables play a key role in replicating entities and Itypes.
19836 -- They are intentionally declared at the library level rather than within
19837 -- New_Copy_Tree to avoid elaborating them on each call. This performance
19838 -- optimization saves up to 2% of the entire compilation time spent in the
19839 -- front end. Care should be taken to reset the tables on each new call to
19842 NCT_Table_Max : constant := 511;
19844 subtype NCT_Table_Index is Nat range 0 .. NCT_Table_Max - 1;
19846 function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index;
19847 -- Obtain the hash value of node or entity Key
19849 --------------------
19850 -- NCT_Table_Hash --
19851 --------------------
19853 function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index is
19855 return NCT_Table_Index (Key mod NCT_Table_Max);
19856 end NCT_Table_Hash;
19858 ----------------------
19859 -- NCT_New_Entities --
19860 ----------------------
19862 -- The following table maps old entities and Itypes to their corresponding
19863 -- new entities and Itypes.
19867 package NCT_New_Entities is new Simple_HTable (
19868 Header_Num => NCT_Table_Index,
19869 Element => Entity_Id,
19870 No_Element => Empty,
19872 Hash => NCT_Table_Hash,
19875 ------------------------
19876 -- NCT_Pending_Itypes --
19877 ------------------------
19879 -- The following table maps old Associated_Node_For_Itype nodes to a set of
19880 -- new itypes. Given a set of old Itypes Aaa, Bbb, and Ccc, where all three
19881 -- have the same Associated_Node_For_Itype Ppp, and their corresponding new
19882 -- Itypes Xxx, Yyy, Zzz, the table contains the following mapping:
19884 -- Ppp -> (Xxx, Yyy, Zzz)
19886 -- The set is expressed as an Elist
19888 package NCT_Pending_Itypes is new Simple_HTable (
19889 Header_Num => NCT_Table_Index,
19890 Element => Elist_Id,
19891 No_Element => No_Elist,
19893 Hash => NCT_Table_Hash,
19896 NCT_Tables_In_Use : Boolean := False;
19897 -- This flag keeps track of whether the two tables NCT_New_Entities and
19898 -- NCT_Pending_Itypes are in use. The flag is part of an optimization
19899 -- where certain operations are not performed if the tables are not in
19900 -- use. This saves up to 8% of the entire compilation time spent in the
19903 -------------------
19904 -- New_Copy_Tree --
19905 -------------------
19907 function New_Copy_Tree
19909 Map : Elist_Id := No_Elist;
19910 New_Sloc : Source_Ptr := No_Location;
19911 New_Scope : Entity_Id := Empty;
19912 Scopes_In_EWA_OK : Boolean := False) return Node_Id
19914 -- This routine performs low-level tree manipulations and needs access
19915 -- to the internals of the tree.
19917 use Atree.Unchecked_Access;
19918 use Atree_Private_Part;
19920 EWA_Level : Nat := 0;
19921 -- This counter keeps track of how many N_Expression_With_Actions nodes
19922 -- are encountered during a depth-first traversal of the subtree. These
19923 -- nodes may define new entities in their Actions lists and thus require
19924 -- special processing.
19926 EWA_Inner_Scope_Level : Nat := 0;
19927 -- This counter keeps track of how many scoping constructs appear within
19928 -- an N_Expression_With_Actions node.
19930 procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id);
19931 pragma Inline (Add_New_Entity);
19932 -- Add an entry in the NCT_New_Entities table which maps key Old_Id to
19933 -- value New_Id. Old_Id is an entity which appears within the Actions
19934 -- list of an N_Expression_With_Actions node, or within an entity map.
19935 -- New_Id is the corresponding new entity generated during Phase 1.
19937 procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id);
19938 pragma Inline (Add_New_Entity);
19939 -- Add an entry in the NCT_Pending_Itypes which maps key Assoc_Nod to
19940 -- value Itype. Assoc_Nod is the associated node of an itype. Itype is
19943 procedure Build_NCT_Tables (Entity_Map : Elist_Id);
19944 pragma Inline (Build_NCT_Tables);
19945 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with the
19946 -- information supplied in entity map Entity_Map. The format of the
19947 -- entity map must be as follows:
19949 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
19951 function Copy_Any_Node_With_Replacement
19952 (N : Node_Or_Entity_Id) return Node_Or_Entity_Id;
19953 pragma Inline (Copy_Any_Node_With_Replacement);
19954 -- Replicate entity or node N by invoking one of the following routines:
19956 -- Copy_Node_With_Replacement
19957 -- Corresponding_Entity
19959 function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id;
19960 -- Replicate the elements of entity list List
19962 function Copy_Field_With_Replacement
19964 Old_Par : Node_Id := Empty;
19965 New_Par : Node_Id := Empty;
19966 Semantic : Boolean := False) return Union_Id;
19967 -- Replicate field Field by invoking one of the following routines:
19969 -- Copy_Elist_With_Replacement
19970 -- Copy_List_With_Replacement
19971 -- Copy_Node_With_Replacement
19972 -- Corresponding_Entity
19974 -- If the field is not an entity list, entity, itype, syntactic list,
19975 -- or node, then the field is returned unchanged. The routine always
19976 -- replicates entities, itypes, and valid syntactic fields. Old_Par is
19977 -- the expected parent of a syntactic field. New_Par is the new parent
19978 -- associated with a replicated syntactic field. Flag Semantic should
19979 -- be set when the input is a semantic field.
19981 function Copy_List_With_Replacement (List : List_Id) return List_Id;
19982 -- Replicate the elements of syntactic list List
19984 function Copy_Node_With_Replacement (N : Node_Id) return Node_Id;
19985 -- Replicate node N
19987 function Corresponding_Entity (Id : Entity_Id) return Entity_Id;
19988 pragma Inline (Corresponding_Entity);
19989 -- Return the corresponding new entity of Id generated during Phase 1.
19990 -- If there is no such entity, return Id.
19992 function In_Entity_Map
19994 Entity_Map : Elist_Id) return Boolean;
19995 pragma Inline (In_Entity_Map);
19996 -- Determine whether entity Id is one of the old ids specified in entity
19997 -- map Entity_Map. The format of the entity map must be as follows:
19999 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
20001 procedure Update_CFS_Sloc (N : Node_Or_Entity_Id);
20002 pragma Inline (Update_CFS_Sloc);
20003 -- Update the Comes_From_Source and Sloc attributes of node or entity N
20005 procedure Update_First_Real_Statement
20006 (Old_HSS : Node_Id;
20007 New_HSS : Node_Id);
20008 pragma Inline (Update_First_Real_Statement);
20009 -- Update semantic attribute First_Real_Statement of handled sequence of
20010 -- statements New_HSS based on handled sequence of statements Old_HSS.
20012 procedure Update_Named_Associations
20013 (Old_Call : Node_Id;
20014 New_Call : Node_Id);
20015 pragma Inline (Update_Named_Associations);
20016 -- Update semantic chain First/Next_Named_Association of call New_call
20017 -- based on call Old_Call.
20019 procedure Update_New_Entities (Entity_Map : Elist_Id);
20020 pragma Inline (Update_New_Entities);
20021 -- Update the semantic attributes of all new entities generated during
20022 -- Phase 1 that do not appear in entity map Entity_Map. The format of
20023 -- the entity map must be as follows:
20025 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
20027 procedure Update_Pending_Itypes
20028 (Old_Assoc : Node_Id;
20029 New_Assoc : Node_Id);
20030 pragma Inline (Update_Pending_Itypes);
20031 -- Update semantic attribute Associated_Node_For_Itype to refer to node
20032 -- New_Assoc for all itypes whose associated node is Old_Assoc.
20034 procedure Update_Semantic_Fields (Id : Entity_Id);
20035 pragma Inline (Update_Semantic_Fields);
20036 -- Subsidiary to Update_New_Entities. Update semantic fields of entity
20039 procedure Visit_Any_Node (N : Node_Or_Entity_Id);
20040 pragma Inline (Visit_Any_Node);
20041 -- Visit entity of node N by invoking one of the following routines:
20047 procedure Visit_Elist (List : Elist_Id);
20048 -- Visit the elements of entity list List
20050 procedure Visit_Entity (Id : Entity_Id);
20051 -- Visit entity Id. This action may create a new entity of Id and save
20052 -- it in table NCT_New_Entities.
20054 procedure Visit_Field
20056 Par_Nod : Node_Id := Empty;
20057 Semantic : Boolean := False);
20058 -- Visit field Field by invoking one of the following routines:
20066 -- If the field is not an entity list, entity, itype, syntactic list,
20067 -- or node, then the field is not visited. The routine always visits
20068 -- valid syntactic fields. Par_Nod is the expected parent of the
20069 -- syntactic field. Flag Semantic should be set when the input is a
20072 procedure Visit_Itype (Itype : Entity_Id);
20073 -- Visit itype Itype. This action may create a new entity for Itype and
20074 -- save it in table NCT_New_Entities. In addition, the routine may map
20075 -- the associated node of Itype to the new itype in NCT_Pending_Itypes.
20077 procedure Visit_List (List : List_Id);
20078 -- Visit the elements of syntactic list List
20080 procedure Visit_Node (N : Node_Id);
20083 procedure Visit_Semantic_Fields (Id : Entity_Id);
20084 pragma Inline (Visit_Semantic_Fields);
20085 -- Subsidiary to Visit_Entity and Visit_Itype. Visit common semantic
20086 -- fields of entity or itype Id.
20088 --------------------
20089 -- Add_New_Entity --
20090 --------------------
20092 procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id) is
20094 pragma Assert (Present (Old_Id));
20095 pragma Assert (Present (New_Id));
20096 pragma Assert (Nkind (Old_Id) in N_Entity);
20097 pragma Assert (Nkind (New_Id) in N_Entity);
20099 NCT_Tables_In_Use := True;
20101 -- Sanity check the NCT_New_Entities table. No previous mapping with
20102 -- key Old_Id should exist.
20104 pragma Assert (No (NCT_New_Entities.Get (Old_Id)));
20106 -- Establish the mapping
20108 -- Old_Id -> New_Id
20110 NCT_New_Entities.Set (Old_Id, New_Id);
20111 end Add_New_Entity;
20113 -----------------------
20114 -- Add_Pending_Itype --
20115 -----------------------
20117 procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id) is
20121 pragma Assert (Present (Assoc_Nod));
20122 pragma Assert (Present (Itype));
20123 pragma Assert (Nkind (Itype) in N_Entity);
20124 pragma Assert (Is_Itype (Itype));
20126 NCT_Tables_In_Use := True;
20128 -- It is not possible to sanity check the NCT_Pendint_Itypes table
20129 -- directly because a single node may act as the associated node for
20130 -- multiple itypes.
20132 Itypes := NCT_Pending_Itypes.Get (Assoc_Nod);
20134 if No (Itypes) then
20135 Itypes := New_Elmt_List;
20136 NCT_Pending_Itypes.Set (Assoc_Nod, Itypes);
20139 -- Establish the mapping
20141 -- Assoc_Nod -> (Itype, ...)
20143 -- Avoid inserting the same itype multiple times. This involves a
20144 -- linear search, however the set of itypes with the same associated
20145 -- node is very small.
20147 Append_Unique_Elmt (Itype, Itypes);
20148 end Add_Pending_Itype;
20150 ----------------------
20151 -- Build_NCT_Tables --
20152 ----------------------
20154 procedure Build_NCT_Tables (Entity_Map : Elist_Id) is
20156 Old_Id : Entity_Id;
20157 New_Id : Entity_Id;
20160 -- Nothing to do when there is no entity map
20162 if No (Entity_Map) then
20166 Elmt := First_Elmt (Entity_Map);
20167 while Present (Elmt) loop
20169 -- Extract the (Old_Id, New_Id) pair from the entity map
20171 Old_Id := Node (Elmt);
20174 New_Id := Node (Elmt);
20177 -- Establish the following mapping within table NCT_New_Entities
20179 -- Old_Id -> New_Id
20181 Add_New_Entity (Old_Id, New_Id);
20183 -- Establish the following mapping within table NCT_Pending_Itypes
20184 -- when the new entity is an itype.
20186 -- Assoc_Nod -> (New_Id, ...)
20188 -- IMPORTANT: the associated node is that of the old itype because
20189 -- the node will be replicated in Phase 2.
20191 if Is_Itype (Old_Id) then
20193 (Assoc_Nod => Associated_Node_For_Itype (Old_Id),
20197 end Build_NCT_Tables;
20199 ------------------------------------
20200 -- Copy_Any_Node_With_Replacement --
20201 ------------------------------------
20203 function Copy_Any_Node_With_Replacement
20204 (N : Node_Or_Entity_Id) return Node_Or_Entity_Id
20207 if Nkind (N) in N_Entity then
20208 return Corresponding_Entity (N);
20210 return Copy_Node_With_Replacement (N);
20212 end Copy_Any_Node_With_Replacement;
20214 ---------------------------------
20215 -- Copy_Elist_With_Replacement --
20216 ---------------------------------
20218 function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id is
20223 -- Copy the contents of the old list. Note that the list itself may
20224 -- be empty, in which case the routine returns a new empty list. This
20225 -- avoids sharing lists between subtrees. The element of an entity
20226 -- list could be an entity or a node, hence the invocation of routine
20227 -- Copy_Any_Node_With_Replacement.
20229 if Present (List) then
20230 Result := New_Elmt_List;
20232 Elmt := First_Elmt (List);
20233 while Present (Elmt) loop
20235 (Copy_Any_Node_With_Replacement (Node (Elmt)), Result);
20240 -- Otherwise the list does not exist
20243 Result := No_Elist;
20247 end Copy_Elist_With_Replacement;
20249 ---------------------------------
20250 -- Copy_Field_With_Replacement --
20251 ---------------------------------
20253 function Copy_Field_With_Replacement
20255 Old_Par : Node_Id := Empty;
20256 New_Par : Node_Id := Empty;
20257 Semantic : Boolean := False) return Union_Id
20260 -- The field is empty
20262 if Field = Union_Id (Empty) then
20265 -- The field is an entity/itype/node
20267 elsif Field in Node_Range then
20269 Old_N : constant Node_Id := Node_Id (Field);
20270 Syntactic : constant Boolean := Parent (Old_N) = Old_Par;
20275 -- The field is an entity/itype
20277 if Nkind (Old_N) in N_Entity then
20279 -- An entity/itype is always replicated
20281 New_N := Corresponding_Entity (Old_N);
20283 -- Update the parent pointer when the entity is a syntactic
20284 -- field. Note that itypes do not have parent pointers.
20286 if Syntactic and then New_N /= Old_N then
20287 Set_Parent (New_N, New_Par);
20290 -- The field is a node
20293 -- A node is replicated when it is either a syntactic field
20294 -- or when the caller treats it as a semantic attribute.
20296 if Syntactic or else Semantic then
20297 New_N := Copy_Node_With_Replacement (Old_N);
20299 -- Update the parent pointer when the node is a syntactic
20302 if Syntactic and then New_N /= Old_N then
20303 Set_Parent (New_N, New_Par);
20306 -- Otherwise the node is returned unchanged
20313 return Union_Id (New_N);
20316 -- The field is an entity list
20318 elsif Field in Elist_Range then
20319 return Union_Id (Copy_Elist_With_Replacement (Elist_Id (Field)));
20321 -- The field is a syntactic list
20323 elsif Field in List_Range then
20325 Old_List : constant List_Id := List_Id (Field);
20326 Syntactic : constant Boolean := Parent (Old_List) = Old_Par;
20328 New_List : List_Id;
20331 -- A list is replicated when it is either a syntactic field or
20332 -- when the caller treats it as a semantic attribute.
20334 if Syntactic or else Semantic then
20335 New_List := Copy_List_With_Replacement (Old_List);
20337 -- Update the parent pointer when the list is a syntactic
20340 if Syntactic and then New_List /= Old_List then
20341 Set_Parent (New_List, New_Par);
20344 -- Otherwise the list is returned unchanged
20347 New_List := Old_List;
20350 return Union_Id (New_List);
20353 -- Otherwise the field denotes an attribute that does not need to be
20354 -- replicated (Chars, literals, etc).
20359 end Copy_Field_With_Replacement;
20361 --------------------------------
20362 -- Copy_List_With_Replacement --
20363 --------------------------------
20365 function Copy_List_With_Replacement (List : List_Id) return List_Id is
20370 -- Copy the contents of the old list. Note that the list itself may
20371 -- be empty, in which case the routine returns a new empty list. This
20372 -- avoids sharing lists between subtrees. The element of a syntactic
20373 -- list is always a node, never an entity or itype, hence the call to
20374 -- routine Copy_Node_With_Replacement.
20376 if Present (List) then
20377 Result := New_List;
20379 Elmt := First (List);
20380 while Present (Elmt) loop
20381 Append (Copy_Node_With_Replacement (Elmt), Result);
20386 -- Otherwise the list does not exist
20393 end Copy_List_With_Replacement;
20395 --------------------------------
20396 -- Copy_Node_With_Replacement --
20397 --------------------------------
20399 function Copy_Node_With_Replacement (N : Node_Id) return Node_Id is
20403 -- Assume that the node must be returned unchanged
20407 if N > Empty_Or_Error then
20408 pragma Assert (Nkind (N) not in N_Entity);
20410 Result := New_Copy (N);
20412 Set_Field1 (Result,
20413 Copy_Field_With_Replacement
20414 (Field => Field1 (Result),
20416 New_Par => Result));
20418 Set_Field2 (Result,
20419 Copy_Field_With_Replacement
20420 (Field => Field2 (Result),
20422 New_Par => Result));
20424 Set_Field3 (Result,
20425 Copy_Field_With_Replacement
20426 (Field => Field3 (Result),
20428 New_Par => Result));
20430 Set_Field4 (Result,
20431 Copy_Field_With_Replacement
20432 (Field => Field4 (Result),
20434 New_Par => Result));
20436 Set_Field5 (Result,
20437 Copy_Field_With_Replacement
20438 (Field => Field5 (Result),
20440 New_Par => Result));
20442 -- Update the Comes_From_Source and Sloc attributes of the node
20443 -- in case the caller has supplied new values.
20445 Update_CFS_Sloc (Result);
20447 -- Update the Associated_Node_For_Itype attribute of all itypes
20448 -- created during Phase 1 whose associated node is N. As a result
20449 -- the Associated_Node_For_Itype refers to the replicated node.
20450 -- No action needs to be taken when the Associated_Node_For_Itype
20451 -- refers to an entity because this was already handled during
20452 -- Phase 1, in Visit_Itype.
20454 Update_Pending_Itypes
20456 New_Assoc => Result);
20458 -- Update the First/Next_Named_Association chain for a replicated
20461 if Nkind_In (N, N_Entry_Call_Statement,
20463 N_Procedure_Call_Statement)
20465 Update_Named_Associations
20467 New_Call => Result);
20469 -- Update the Renamed_Object attribute of a replicated object
20472 elsif Nkind (N) = N_Object_Renaming_Declaration then
20473 Set_Renamed_Object (Defining_Entity (Result), Name (Result));
20475 -- Update the First_Real_Statement attribute of a replicated
20476 -- handled sequence of statements.
20478 elsif Nkind (N) = N_Handled_Sequence_Of_Statements then
20479 Update_First_Real_Statement
20481 New_HSS => Result);
20483 -- Update the Chars attribute of identifiers
20485 elsif Nkind (N) = N_Identifier then
20487 -- The Entity field of identifiers that denote aspects is used
20488 -- to store arbitrary expressions (and hence we must check that
20489 -- they reference an actual entity before copying their Chars
20492 if Present (Entity (Result))
20493 and then Nkind (Entity (Result)) in N_Entity
20495 Set_Chars (Result, Chars (Entity (Result)));
20501 end Copy_Node_With_Replacement;
20503 --------------------------
20504 -- Corresponding_Entity --
20505 --------------------------
20507 function Corresponding_Entity (Id : Entity_Id) return Entity_Id is
20508 New_Id : Entity_Id;
20509 Result : Entity_Id;
20512 -- Assume that the entity must be returned unchanged
20516 if Id > Empty_Or_Error then
20517 pragma Assert (Nkind (Id) in N_Entity);
20519 -- Determine whether the entity has a corresponding new entity
20520 -- generated during Phase 1 and if it does, use it.
20522 if NCT_Tables_In_Use then
20523 New_Id := NCT_New_Entities.Get (Id);
20525 if Present (New_Id) then
20532 end Corresponding_Entity;
20534 -------------------
20535 -- In_Entity_Map --
20536 -------------------
20538 function In_Entity_Map
20540 Entity_Map : Elist_Id) return Boolean
20543 Old_Id : Entity_Id;
20546 -- The entity map contains pairs (Old_Id, New_Id). The advancement
20547 -- step always skips the New_Id portion of the pair.
20549 if Present (Entity_Map) then
20550 Elmt := First_Elmt (Entity_Map);
20551 while Present (Elmt) loop
20552 Old_Id := Node (Elmt);
20554 if Old_Id = Id then
20566 ---------------------
20567 -- Update_CFS_Sloc --
20568 ---------------------
20570 procedure Update_CFS_Sloc (N : Node_Or_Entity_Id) is
20572 -- A new source location defaults the Comes_From_Source attribute
20574 if New_Sloc /= No_Location then
20575 Set_Comes_From_Source (N, Default_Node.Comes_From_Source);
20576 Set_Sloc (N, New_Sloc);
20578 end Update_CFS_Sloc;
20580 ---------------------------------
20581 -- Update_First_Real_Statement --
20582 ---------------------------------
20584 procedure Update_First_Real_Statement
20585 (Old_HSS : Node_Id;
20588 Old_First_Stmt : constant Node_Id := First_Real_Statement (Old_HSS);
20590 New_Stmt : Node_Id;
20591 Old_Stmt : Node_Id;
20594 -- Recreate the First_Real_Statement attribute of a handled sequence
20595 -- of statements by traversing the statement lists of both sequences
20598 if Present (Old_First_Stmt) then
20599 New_Stmt := First (Statements (New_HSS));
20600 Old_Stmt := First (Statements (Old_HSS));
20601 while Present (Old_Stmt) and then Old_Stmt /= Old_First_Stmt loop
20606 pragma Assert (Present (New_Stmt));
20607 pragma Assert (Present (Old_Stmt));
20609 Set_First_Real_Statement (New_HSS, New_Stmt);
20611 end Update_First_Real_Statement;
20613 -------------------------------
20614 -- Update_Named_Associations --
20615 -------------------------------
20617 procedure Update_Named_Associations
20618 (Old_Call : Node_Id;
20619 New_Call : Node_Id)
20622 New_Next : Node_Id;
20624 Old_Next : Node_Id;
20627 if No (First_Named_Actual (Old_Call)) then
20631 -- Recreate the First/Next_Named_Actual chain of a call by traversing
20632 -- the chains of both the old and new calls in parallel.
20634 New_Act := First (Parameter_Associations (New_Call));
20635 Old_Act := First (Parameter_Associations (Old_Call));
20636 while Present (Old_Act) loop
20637 if Nkind (Old_Act) = N_Parameter_Association
20638 and then Explicit_Actual_Parameter (Old_Act)
20639 = First_Named_Actual (Old_Call)
20641 Set_First_Named_Actual (New_Call,
20642 Explicit_Actual_Parameter (New_Act));
20645 if Nkind (Old_Act) = N_Parameter_Association
20646 and then Present (Next_Named_Actual (Old_Act))
20648 -- Scan the actual parameter list to find the next suitable
20649 -- named actual. Note that the list may be out of order.
20651 New_Next := First (Parameter_Associations (New_Call));
20652 Old_Next := First (Parameter_Associations (Old_Call));
20653 while Nkind (Old_Next) /= N_Parameter_Association
20654 or else Explicit_Actual_Parameter (Old_Next) /=
20655 Next_Named_Actual (Old_Act)
20661 Set_Next_Named_Actual (New_Act,
20662 Explicit_Actual_Parameter (New_Next));
20668 end Update_Named_Associations;
20670 -------------------------
20671 -- Update_New_Entities --
20672 -------------------------
20674 procedure Update_New_Entities (Entity_Map : Elist_Id) is
20675 New_Id : Entity_Id := Empty;
20676 Old_Id : Entity_Id := Empty;
20679 if NCT_Tables_In_Use then
20680 NCT_New_Entities.Get_First (Old_Id, New_Id);
20682 -- Update the semantic fields of all new entities created during
20683 -- Phase 1 which were not supplied via an entity map.
20684 -- ??? Is there a better way of distinguishing those?
20686 while Present (Old_Id) and then Present (New_Id) loop
20687 if not (Present (Entity_Map)
20688 and then In_Entity_Map (Old_Id, Entity_Map))
20690 Update_Semantic_Fields (New_Id);
20693 NCT_New_Entities.Get_Next (Old_Id, New_Id);
20696 end Update_New_Entities;
20698 ---------------------------
20699 -- Update_Pending_Itypes --
20700 ---------------------------
20702 procedure Update_Pending_Itypes
20703 (Old_Assoc : Node_Id;
20704 New_Assoc : Node_Id)
20710 if NCT_Tables_In_Use then
20711 Itypes := NCT_Pending_Itypes.Get (Old_Assoc);
20713 -- Update the Associated_Node_For_Itype attribute for all itypes
20714 -- which originally refer to Old_Assoc to designate New_Assoc.
20716 if Present (Itypes) then
20717 Item := First_Elmt (Itypes);
20718 while Present (Item) loop
20719 Set_Associated_Node_For_Itype (Node (Item), New_Assoc);
20725 end Update_Pending_Itypes;
20727 ----------------------------
20728 -- Update_Semantic_Fields --
20729 ----------------------------
20731 procedure Update_Semantic_Fields (Id : Entity_Id) is
20733 -- Discriminant_Constraint
20735 if Is_Type (Id) and then Has_Discriminants (Base_Type (Id)) then
20736 Set_Discriminant_Constraint (Id, Elist_Id (
20737 Copy_Field_With_Replacement
20738 (Field => Union_Id (Discriminant_Constraint (Id)),
20739 Semantic => True)));
20744 Set_Etype (Id, Node_Id (
20745 Copy_Field_With_Replacement
20746 (Field => Union_Id (Etype (Id)),
20747 Semantic => True)));
20750 -- Packed_Array_Impl_Type
20752 if Is_Array_Type (Id) then
20753 if Present (First_Index (Id)) then
20754 Set_First_Index (Id, First (List_Id (
20755 Copy_Field_With_Replacement
20756 (Field => Union_Id (List_Containing (First_Index (Id))),
20757 Semantic => True))));
20760 if Is_Packed (Id) then
20761 Set_Packed_Array_Impl_Type (Id, Node_Id (
20762 Copy_Field_With_Replacement
20763 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
20764 Semantic => True)));
20770 Set_Prev_Entity (Id, Node_Id (
20771 Copy_Field_With_Replacement
20772 (Field => Union_Id (Prev_Entity (Id)),
20773 Semantic => True)));
20777 Set_Next_Entity (Id, Node_Id (
20778 Copy_Field_With_Replacement
20779 (Field => Union_Id (Next_Entity (Id)),
20780 Semantic => True)));
20784 if Is_Discrete_Type (Id) then
20785 Set_Scalar_Range (Id, Node_Id (
20786 Copy_Field_With_Replacement
20787 (Field => Union_Id (Scalar_Range (Id)),
20788 Semantic => True)));
20793 -- Update the scope when the caller specified an explicit one
20795 if Present (New_Scope) then
20796 Set_Scope (Id, New_Scope);
20798 Set_Scope (Id, Node_Id (
20799 Copy_Field_With_Replacement
20800 (Field => Union_Id (Scope (Id)),
20801 Semantic => True)));
20803 end Update_Semantic_Fields;
20805 --------------------
20806 -- Visit_Any_Node --
20807 --------------------
20809 procedure Visit_Any_Node (N : Node_Or_Entity_Id) is
20811 if Nkind (N) in N_Entity then
20812 if Is_Itype (N) then
20820 end Visit_Any_Node;
20826 procedure Visit_Elist (List : Elist_Id) is
20830 -- The element of an entity list could be an entity, itype, or a
20831 -- node, hence the call to Visit_Any_Node.
20833 if Present (List) then
20834 Elmt := First_Elmt (List);
20835 while Present (Elmt) loop
20836 Visit_Any_Node (Node (Elmt));
20847 procedure Visit_Entity (Id : Entity_Id) is
20848 New_Id : Entity_Id;
20851 pragma Assert (Nkind (Id) in N_Entity);
20852 pragma Assert (not Is_Itype (Id));
20854 -- Nothing to do when the entity is not defined in the Actions list
20855 -- of an N_Expression_With_Actions node.
20857 if EWA_Level = 0 then
20860 -- Nothing to do when the entity is defined in a scoping construct
20861 -- within an N_Expression_With_Actions node, unless the caller has
20862 -- requested their replication.
20864 -- ??? should this restriction be eliminated?
20866 elsif EWA_Inner_Scope_Level > 0 and then not Scopes_In_EWA_OK then
20869 -- Nothing to do when the entity does not denote a construct that
20870 -- may appear within an N_Expression_With_Actions node. Relaxing
20871 -- this restriction leads to a performance penalty.
20873 -- ??? this list is flaky, and may hide dormant bugs
20874 -- Should functions be included???
20876 -- Loop parameters appear within quantified expressions and contain
20877 -- an entity declaration that must be replaced when the expander is
20878 -- active if the expression has been preanalyzed or analyzed.
20880 elsif not Ekind_In (Id, E_Block,
20886 and then not Is_Type (Id)
20890 elsif Ekind (Id) = E_Loop_Parameter
20891 and then No (Etype (Condition (Parent (Parent (Id)))))
20895 -- Nothing to do when the entity was already visited
20897 elsif NCT_Tables_In_Use
20898 and then Present (NCT_New_Entities.Get (Id))
20902 -- Nothing to do when the declaration node of the entity is not in
20903 -- the subtree being replicated.
20905 elsif not In_Subtree
20906 (N => Declaration_Node (Id),
20912 -- Create a new entity by directly copying the old entity. This
20913 -- action causes all attributes of the old entity to be inherited.
20915 New_Id := New_Copy (Id);
20917 -- Create a new name for the new entity because the back end needs
20918 -- distinct names for debugging purposes.
20920 Set_Chars (New_Id, New_Internal_Name ('T'));
20922 -- Update the Comes_From_Source and Sloc attributes of the entity in
20923 -- case the caller has supplied new values.
20925 Update_CFS_Sloc (New_Id);
20927 -- Establish the following mapping within table NCT_New_Entities:
20931 Add_New_Entity (Id, New_Id);
20933 -- Deal with the semantic fields of entities. The fields are visited
20934 -- because they may mention entities which reside within the subtree
20937 Visit_Semantic_Fields (Id);
20944 procedure Visit_Field
20946 Par_Nod : Node_Id := Empty;
20947 Semantic : Boolean := False)
20950 -- The field is empty
20952 if Field = Union_Id (Empty) then
20955 -- The field is an entity/itype/node
20957 elsif Field in Node_Range then
20959 N : constant Node_Id := Node_Id (Field);
20962 -- The field is an entity/itype
20964 if Nkind (N) in N_Entity then
20966 -- Itypes are always visited
20968 if Is_Itype (N) then
20971 -- An entity is visited when it is either a syntactic field
20972 -- or when the caller treats it as a semantic attribute.
20974 elsif Parent (N) = Par_Nod or else Semantic then
20978 -- The field is a node
20981 -- A node is visited when it is either a syntactic field or
20982 -- when the caller treats it as a semantic attribute.
20984 if Parent (N) = Par_Nod or else Semantic then
20990 -- The field is an entity list
20992 elsif Field in Elist_Range then
20993 Visit_Elist (Elist_Id (Field));
20995 -- The field is a syntax list
20997 elsif Field in List_Range then
20999 List : constant List_Id := List_Id (Field);
21002 -- A syntax list is visited when it is either a syntactic field
21003 -- or when the caller treats it as a semantic attribute.
21005 if Parent (List) = Par_Nod or else Semantic then
21010 -- Otherwise the field denotes information which does not need to be
21011 -- visited (chars, literals, etc.).
21022 procedure Visit_Itype (Itype : Entity_Id) is
21023 New_Assoc : Node_Id;
21024 New_Itype : Entity_Id;
21025 Old_Assoc : Node_Id;
21028 pragma Assert (Nkind (Itype) in N_Entity);
21029 pragma Assert (Is_Itype (Itype));
21031 -- Itypes that describe the designated type of access to subprograms
21032 -- have the structure of subprogram declarations, with signatures,
21033 -- etc. Either we duplicate the signatures completely, or choose to
21034 -- share such itypes, which is fine because their elaboration will
21035 -- have no side effects.
21037 if Ekind (Itype) = E_Subprogram_Type then
21040 -- Nothing to do if the itype was already visited
21042 elsif NCT_Tables_In_Use
21043 and then Present (NCT_New_Entities.Get (Itype))
21047 -- Nothing to do if the associated node of the itype is not within
21048 -- the subtree being replicated.
21050 elsif not In_Subtree
21051 (N => Associated_Node_For_Itype (Itype),
21057 -- Create a new itype by directly copying the old itype. This action
21058 -- causes all attributes of the old itype to be inherited.
21060 New_Itype := New_Copy (Itype);
21062 -- Create a new name for the new itype because the back end requires
21063 -- distinct names for debugging purposes.
21065 Set_Chars (New_Itype, New_Internal_Name ('T'));
21067 -- Update the Comes_From_Source and Sloc attributes of the itype in
21068 -- case the caller has supplied new values.
21070 Update_CFS_Sloc (New_Itype);
21072 -- Establish the following mapping within table NCT_New_Entities:
21074 -- Itype -> New_Itype
21076 Add_New_Entity (Itype, New_Itype);
21078 -- The new itype must be unfrozen because the resulting subtree may
21079 -- be inserted anywhere and cause an earlier or later freezing.
21081 if Present (Freeze_Node (New_Itype)) then
21082 Set_Freeze_Node (New_Itype, Empty);
21083 Set_Is_Frozen (New_Itype, False);
21086 -- If a record subtype is simply copied, the entity list will be
21087 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
21088 -- ??? What does this do?
21090 if Ekind_In (Itype, E_Class_Wide_Subtype, E_Record_Subtype) then
21091 Set_Cloned_Subtype (New_Itype, Itype);
21094 -- The associated node may denote an entity, in which case it may
21095 -- already have a new corresponding entity created during a prior
21096 -- call to Visit_Entity or Visit_Itype for the same subtree.
21099 -- Old_Assoc ---------> New_Assoc
21101 -- Created by Visit_Itype
21102 -- Itype -------------> New_Itype
21103 -- ANFI = Old_Assoc ANFI = Old_Assoc < must be updated
21105 -- In the example above, Old_Assoc is an arbitrary entity that was
21106 -- already visited for the same subtree and has a corresponding new
21107 -- entity New_Assoc. Old_Assoc was inherited by New_Itype by virtue
21108 -- of copying entities, however it must be updated to New_Assoc.
21110 Old_Assoc := Associated_Node_For_Itype (Itype);
21112 if Nkind (Old_Assoc) in N_Entity then
21113 if NCT_Tables_In_Use then
21114 New_Assoc := NCT_New_Entities.Get (Old_Assoc);
21116 if Present (New_Assoc) then
21117 Set_Associated_Node_For_Itype (New_Itype, New_Assoc);
21121 -- Otherwise the associated node denotes a node. Postpone the update
21122 -- until Phase 2 when the node is replicated. Establish the following
21123 -- mapping within table NCT_Pending_Itypes:
21125 -- Old_Assoc -> (New_Type, ...)
21128 Add_Pending_Itype (Old_Assoc, New_Itype);
21131 -- Deal with the semantic fields of itypes. The fields are visited
21132 -- because they may mention entities that reside within the subtree
21135 Visit_Semantic_Fields (Itype);
21142 procedure Visit_List (List : List_Id) is
21146 -- Note that the element of a syntactic list is always a node, never
21147 -- an entity or itype, hence the call to Visit_Node.
21149 if Present (List) then
21150 Elmt := First (List);
21151 while Present (Elmt) loop
21163 procedure Visit_Node (N : Node_Or_Entity_Id) is
21165 pragma Assert (Nkind (N) not in N_Entity);
21167 -- If the node is a quantified expression and expander is active,
21168 -- it contains an implicit declaration that may require a new entity
21169 -- when the condition has already been (pre)analyzed.
21171 if Nkind (N) = N_Expression_With_Actions
21173 (Nkind (N) = N_Quantified_Expression and then Expander_Active)
21175 EWA_Level := EWA_Level + 1;
21177 elsif EWA_Level > 0
21178 and then Nkind_In (N, N_Block_Statement,
21180 N_Subprogram_Declaration)
21182 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level + 1;
21186 (Field => Field1 (N),
21190 (Field => Field2 (N),
21194 (Field => Field3 (N),
21198 (Field => Field4 (N),
21202 (Field => Field5 (N),
21206 and then Nkind_In (N, N_Block_Statement,
21208 N_Subprogram_Declaration)
21210 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level - 1;
21212 elsif Nkind (N) = N_Expression_With_Actions then
21213 EWA_Level := EWA_Level - 1;
21217 ---------------------------
21218 -- Visit_Semantic_Fields --
21219 ---------------------------
21221 procedure Visit_Semantic_Fields (Id : Entity_Id) is
21223 pragma Assert (Nkind (Id) in N_Entity);
21225 -- Discriminant_Constraint
21227 if Is_Type (Id) and then Has_Discriminants (Base_Type (Id)) then
21229 (Field => Union_Id (Discriminant_Constraint (Id)),
21236 (Field => Union_Id (Etype (Id)),
21240 -- Packed_Array_Impl_Type
21242 if Is_Array_Type (Id) then
21243 if Present (First_Index (Id)) then
21245 (Field => Union_Id (List_Containing (First_Index (Id))),
21249 if Is_Packed (Id) then
21251 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
21258 if Is_Discrete_Type (Id) then
21260 (Field => Union_Id (Scalar_Range (Id)),
21263 end Visit_Semantic_Fields;
21265 -- Start of processing for New_Copy_Tree
21268 -- Routine New_Copy_Tree performs a deep copy of a subtree by creating
21269 -- shallow copies for each node within, and then updating the child and
21270 -- parent pointers accordingly. This process is straightforward, however
21271 -- the routine must deal with the following complications:
21273 -- * Entities defined within N_Expression_With_Actions nodes must be
21274 -- replicated rather than shared to avoid introducing two identical
21275 -- symbols within the same scope. Note that no other expression can
21276 -- currently define entities.
21279 -- Source_Low : ...;
21280 -- Source_High : ...;
21282 -- <reference to Source_Low>
21283 -- <reference to Source_High>
21286 -- New_Copy_Tree handles this case by first creating new entities
21287 -- and then updating all existing references to point to these new
21294 -- <reference to New_Low>
21295 -- <reference to New_High>
21298 -- * Itypes defined within the subtree must be replicated to avoid any
21299 -- dependencies on invalid or inaccessible data.
21301 -- subtype Source_Itype is ... range Source_Low .. Source_High;
21303 -- New_Copy_Tree handles this case by first creating a new itype in
21304 -- the same fashion as entities, and then updating various relevant
21307 -- subtype New_Itype is ... range New_Low .. New_High;
21309 -- * The Associated_Node_For_Itype field of itypes must be updated to
21310 -- reference the proper replicated entity or node.
21312 -- * Semantic fields of entities such as Etype and Scope must be
21313 -- updated to reference the proper replicated entities.
21315 -- * Semantic fields of nodes such as First_Real_Statement must be
21316 -- updated to reference the proper replicated nodes.
21318 -- Finally, quantified expressions contain an implicit delaration for
21319 -- the bound variable. Given that quantified expressions appearing
21320 -- in contracts are copied to create pragmas and eventually checking
21321 -- procedures, a new bound variable must be created for each copy, to
21322 -- prevent multiple declarations of the same symbol.
21324 -- To meet all these demands, routine New_Copy_Tree is split into two
21327 -- Phase 1 traverses the tree in order to locate entities and itypes
21328 -- defined within the subtree. New entities are generated and saved in
21329 -- table NCT_New_Entities. The semantic fields of all new entities and
21330 -- itypes are then updated accordingly.
21332 -- Phase 2 traverses the tree in order to replicate each node. Various
21333 -- semantic fields of nodes and entities are updated accordingly.
21335 -- Preparatory phase. Clear the contents of tables NCT_New_Entities and
21336 -- NCT_Pending_Itypes in case a previous call to New_Copy_Tree left some
21339 if NCT_Tables_In_Use then
21340 NCT_Tables_In_Use := False;
21342 NCT_New_Entities.Reset;
21343 NCT_Pending_Itypes.Reset;
21346 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with data
21347 -- supplied by a linear entity map. The tables offer faster access to
21350 Build_NCT_Tables (Map);
21352 -- Execute Phase 1. Traverse the subtree and generate new entities for
21353 -- the following cases:
21355 -- * An entity defined within an N_Expression_With_Actions node
21357 -- * An itype referenced within the subtree where the associated node
21358 -- is also in the subtree.
21360 -- All new entities are accessible via table NCT_New_Entities, which
21361 -- contains mappings of the form:
21363 -- Old_Entity -> New_Entity
21364 -- Old_Itype -> New_Itype
21366 -- In addition, the associated nodes of all new itypes are mapped in
21367 -- table NCT_Pending_Itypes:
21369 -- Assoc_Nod -> (New_Itype1, New_Itype2, .., New_ItypeN)
21371 Visit_Any_Node (Source);
21373 -- Update the semantic attributes of all new entities generated during
21374 -- Phase 1 before starting Phase 2. The updates could be performed in
21375 -- routine Corresponding_Entity, however this may cause the same entity
21376 -- to be updated multiple times, effectively generating useless nodes.
21377 -- Keeping the updates separates from Phase 2 ensures that only one set
21378 -- of attributes is generated for an entity at any one time.
21380 Update_New_Entities (Map);
21382 -- Execute Phase 2. Replicate the source subtree one node at a time.
21383 -- The following transformations take place:
21385 -- * References to entities and itypes are updated to refer to the
21386 -- new entities and itypes generated during Phase 1.
21388 -- * All Associated_Node_For_Itype attributes of itypes are updated
21389 -- to refer to the new replicated Associated_Node_For_Itype.
21391 return Copy_Node_With_Replacement (Source);
21394 -------------------------
21395 -- New_External_Entity --
21396 -------------------------
21398 function New_External_Entity
21399 (Kind : Entity_Kind;
21400 Scope_Id : Entity_Id;
21401 Sloc_Value : Source_Ptr;
21402 Related_Id : Entity_Id;
21403 Suffix : Character;
21404 Suffix_Index : Int := 0;
21405 Prefix : Character := ' ') return Entity_Id
21407 N : constant Entity_Id :=
21408 Make_Defining_Identifier (Sloc_Value,
21410 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
21413 Set_Ekind (N, Kind);
21414 Set_Is_Internal (N, True);
21415 Append_Entity (N, Scope_Id);
21416 Set_Public_Status (N);
21418 if Kind in Type_Kind then
21419 Init_Size_Align (N);
21423 end New_External_Entity;
21425 -------------------------
21426 -- New_Internal_Entity --
21427 -------------------------
21429 function New_Internal_Entity
21430 (Kind : Entity_Kind;
21431 Scope_Id : Entity_Id;
21432 Sloc_Value : Source_Ptr;
21433 Id_Char : Character) return Entity_Id
21435 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
21438 Set_Ekind (N, Kind);
21439 Set_Is_Internal (N, True);
21440 Append_Entity (N, Scope_Id);
21442 if Kind in Type_Kind then
21443 Init_Size_Align (N);
21447 end New_Internal_Entity;
21453 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
21454 Par : constant Node_Id := Parent (Actual_Id);
21458 -- If we are pointing at a positional parameter, it is a member of a
21459 -- node list (the list of parameters), and the next parameter is the
21460 -- next node on the list, unless we hit a parameter association, then
21461 -- we shift to using the chain whose head is the First_Named_Actual in
21462 -- the parent, and then is threaded using the Next_Named_Actual of the
21463 -- Parameter_Association. All this fiddling is because the original node
21464 -- list is in the textual call order, and what we need is the
21465 -- declaration order.
21467 if Is_List_Member (Actual_Id) then
21468 N := Next (Actual_Id);
21470 if Nkind (N) = N_Parameter_Association then
21472 -- In case of a build-in-place call, the call will no longer be a
21473 -- call; it will have been rewritten.
21475 if Nkind_In (Par, N_Entry_Call_Statement,
21477 N_Procedure_Call_Statement)
21479 return First_Named_Actual (Par);
21481 -- In case of a call rewritten in GNATprove mode while "inlining
21482 -- for proof" go to the original call.
21484 elsif Nkind (Par) = N_Null_Statement then
21488 Nkind (Original_Node (Par)) in N_Subprogram_Call);
21490 return First_Named_Actual (Original_Node (Par));
21499 return Next_Named_Actual (Parent (Actual_Id));
21503 procedure Next_Actual (Actual_Id : in out Node_Id) is
21505 Actual_Id := Next_Actual (Actual_Id);
21512 function Next_Global (Node : Node_Id) return Node_Id is
21514 -- The global item may either be in a list, or by itself, in which case
21515 -- there is no next global item with the same mode.
21517 if Is_List_Member (Node) then
21518 return Next (Node);
21524 procedure Next_Global (Node : in out Node_Id) is
21526 Node := Next_Global (Node);
21529 ----------------------------------
21530 -- New_Requires_Transient_Scope --
21531 ----------------------------------
21533 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
21534 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean;
21535 -- This is called for untagged records and protected types, with
21536 -- nondefaulted discriminants. Returns True if the size of function
21537 -- results is known at the call site, False otherwise. Returns False
21538 -- if there is a variant part that depends on the discriminants of
21539 -- this type, or if there is an array constrained by the discriminants
21540 -- of this type. ???Currently, this is overly conservative (the array
21541 -- could be nested inside some other record that is constrained by
21542 -- nondiscriminants). That is, the recursive calls are too conservative.
21544 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean;
21545 -- Returns True if Typ is a nonlimited record with defaulted
21546 -- discriminants whose max size makes it unsuitable for allocating on
21547 -- the primary stack.
21549 ------------------------------
21550 -- Caller_Known_Size_Record --
21551 ------------------------------
21553 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean is
21554 pragma Assert (Typ = Underlying_Type (Typ));
21557 if Has_Variant_Part (Typ) and then not Is_Definite_Subtype (Typ) then
21565 Comp := First_Entity (Typ);
21566 while Present (Comp) loop
21568 -- Only look at E_Component entities. No need to look at
21569 -- E_Discriminant entities, and we must ignore internal
21570 -- subtypes generated for constrained components.
21572 if Ekind (Comp) = E_Component then
21574 Comp_Type : constant Entity_Id :=
21575 Underlying_Type (Etype (Comp));
21578 if Is_Record_Type (Comp_Type)
21580 Is_Protected_Type (Comp_Type)
21582 if not Caller_Known_Size_Record (Comp_Type) then
21586 elsif Is_Array_Type (Comp_Type) then
21587 if Size_Depends_On_Discriminant (Comp_Type) then
21594 Next_Entity (Comp);
21599 end Caller_Known_Size_Record;
21601 ------------------------------
21602 -- Large_Max_Size_Mutable --
21603 ------------------------------
21605 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean is
21606 pragma Assert (Typ = Underlying_Type (Typ));
21608 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean;
21609 -- Returns true if the discrete type T has a large range
21611 ----------------------------
21612 -- Is_Large_Discrete_Type --
21613 ----------------------------
21615 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean is
21616 Threshold : constant Int := 16;
21617 -- Arbitrary threshold above which we consider it "large". We want
21618 -- a fairly large threshold, because these large types really
21619 -- shouldn't have default discriminants in the first place, in
21623 return UI_To_Int (RM_Size (T)) > Threshold;
21624 end Is_Large_Discrete_Type;
21626 -- Start of processing for Large_Max_Size_Mutable
21629 if Is_Record_Type (Typ)
21630 and then not Is_Limited_View (Typ)
21631 and then Has_Defaulted_Discriminants (Typ)
21633 -- Loop through the components, looking for an array whose upper
21634 -- bound(s) depends on discriminants, where both the subtype of
21635 -- the discriminant and the index subtype are too large.
21641 Comp := First_Entity (Typ);
21642 while Present (Comp) loop
21643 if Ekind (Comp) = E_Component then
21645 Comp_Type : constant Entity_Id :=
21646 Underlying_Type (Etype (Comp));
21653 if Is_Array_Type (Comp_Type) then
21654 Indx := First_Index (Comp_Type);
21656 while Present (Indx) loop
21657 Ityp := Etype (Indx);
21658 Hi := Type_High_Bound (Ityp);
21660 if Nkind (Hi) = N_Identifier
21661 and then Ekind (Entity (Hi)) = E_Discriminant
21662 and then Is_Large_Discrete_Type (Ityp)
21663 and then Is_Large_Discrete_Type
21664 (Etype (Entity (Hi)))
21675 Next_Entity (Comp);
21681 end Large_Max_Size_Mutable;
21683 -- Local declarations
21685 Typ : constant Entity_Id := Underlying_Type (Id);
21687 -- Start of processing for New_Requires_Transient_Scope
21690 -- This is a private type which is not completed yet. This can only
21691 -- happen in a default expression (of a formal parameter or of a
21692 -- record component). Do not expand transient scope in this case.
21697 -- Do not expand transient scope for non-existent procedure return or
21698 -- string literal types.
21700 elsif Typ = Standard_Void_Type
21701 or else Ekind (Typ) = E_String_Literal_Subtype
21705 -- If Typ is a generic formal incomplete type, then we want to look at
21706 -- the actual type.
21708 elsif Ekind (Typ) = E_Record_Subtype
21709 and then Present (Cloned_Subtype (Typ))
21711 return New_Requires_Transient_Scope (Cloned_Subtype (Typ));
21713 -- Functions returning specific tagged types may dispatch on result, so
21714 -- their returned value is allocated on the secondary stack, even in the
21715 -- definite case. We must treat nondispatching functions the same way,
21716 -- because access-to-function types can point at both, so the calling
21717 -- conventions must be compatible. Is_Tagged_Type includes controlled
21718 -- types and class-wide types. Controlled type temporaries need
21721 -- ???It's not clear why we need to return noncontrolled types with
21722 -- controlled components on the secondary stack.
21724 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
21727 -- Untagged definite subtypes are known size. This includes all
21728 -- elementary [sub]types. Tasks are known size even if they have
21729 -- discriminants. So we return False here, with one exception:
21730 -- For a type like:
21731 -- type T (Last : Natural := 0) is
21732 -- X : String (1 .. Last);
21734 -- we return True. That's because for "P(F(...));", where F returns T,
21735 -- we don't know the size of the result at the call site, so if we
21736 -- allocated it on the primary stack, we would have to allocate the
21737 -- maximum size, which is way too big.
21739 elsif Is_Definite_Subtype (Typ) or else Is_Task_Type (Typ) then
21740 return Large_Max_Size_Mutable (Typ);
21742 -- Indefinite (discriminated) untagged record or protected type
21744 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
21745 return not Caller_Known_Size_Record (Typ);
21747 -- Unconstrained array
21750 pragma Assert (Is_Array_Type (Typ) and not Is_Definite_Subtype (Typ));
21753 end New_Requires_Transient_Scope;
21755 ------------------------
21756 -- No_Caching_Enabled --
21757 ------------------------
21759 function No_Caching_Enabled (Id : Entity_Id) return Boolean is
21760 Prag : constant Node_Id := Get_Pragma (Id, Pragma_No_Caching);
21764 if Present (Prag) then
21765 Arg1 := First (Pragma_Argument_Associations (Prag));
21767 -- The pragma has an optional Boolean expression, the related
21768 -- property is enabled only when the expression evaluates to True.
21770 if Present (Arg1) then
21771 return Is_True (Expr_Value (Get_Pragma_Arg (Arg1)));
21773 -- Otherwise the lack of expression enables the property by
21780 -- The property was never set in the first place
21785 end No_Caching_Enabled;
21787 --------------------------
21788 -- No_Heap_Finalization --
21789 --------------------------
21791 function No_Heap_Finalization (Typ : Entity_Id) return Boolean is
21793 if Ekind_In (Typ, E_Access_Type, E_General_Access_Type)
21794 and then Is_Library_Level_Entity (Typ)
21796 -- A global No_Heap_Finalization pragma applies to all library-level
21797 -- named access-to-object types.
21799 if Present (No_Heap_Finalization_Pragma) then
21802 -- The library-level named access-to-object type itself is subject to
21803 -- pragma No_Heap_Finalization.
21805 elsif Present (Get_Pragma (Typ, Pragma_No_Heap_Finalization)) then
21811 end No_Heap_Finalization;
21813 -----------------------
21814 -- Normalize_Actuals --
21815 -----------------------
21817 -- Chain actuals according to formals of subprogram. If there are no named
21818 -- associations, the chain is simply the list of Parameter Associations,
21819 -- since the order is the same as the declaration order. If there are named
21820 -- associations, then the First_Named_Actual field in the N_Function_Call
21821 -- or N_Procedure_Call_Statement node points to the Parameter_Association
21822 -- node for the parameter that comes first in declaration order. The
21823 -- remaining named parameters are then chained in declaration order using
21824 -- Next_Named_Actual.
21826 -- This routine also verifies that the number of actuals is compatible with
21827 -- the number and default values of formals, but performs no type checking
21828 -- (type checking is done by the caller).
21830 -- If the matching succeeds, Success is set to True and the caller proceeds
21831 -- with type-checking. If the match is unsuccessful, then Success is set to
21832 -- False, and the caller attempts a different interpretation, if there is
21835 -- If the flag Report is on, the call is not overloaded, and a failure to
21836 -- match can be reported here, rather than in the caller.
21838 procedure Normalize_Actuals
21842 Success : out Boolean)
21844 Actuals : constant List_Id := Parameter_Associations (N);
21845 Actual : Node_Id := Empty;
21846 Formal : Entity_Id;
21847 Last : Node_Id := Empty;
21848 First_Named : Node_Id := Empty;
21851 Formals_To_Match : Integer := 0;
21852 Actuals_To_Match : Integer := 0;
21854 procedure Chain (A : Node_Id);
21855 -- Add named actual at the proper place in the list, using the
21856 -- Next_Named_Actual link.
21858 function Reporting return Boolean;
21859 -- Determines if an error is to be reported. To report an error, we
21860 -- need Report to be True, and also we do not report errors caused
21861 -- by calls to init procs that occur within other init procs. Such
21862 -- errors must always be cascaded errors, since if all the types are
21863 -- declared correctly, the compiler will certainly build decent calls.
21869 procedure Chain (A : Node_Id) is
21873 -- Call node points to first actual in list
21875 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
21878 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
21882 Set_Next_Named_Actual (Last, Empty);
21889 function Reporting return Boolean is
21894 elsif not Within_Init_Proc then
21897 elsif Is_Init_Proc (Entity (Name (N))) then
21905 -- Start of processing for Normalize_Actuals
21908 if Is_Access_Type (S) then
21910 -- The name in the call is a function call that returns an access
21911 -- to subprogram. The designated type has the list of formals.
21913 Formal := First_Formal (Designated_Type (S));
21915 Formal := First_Formal (S);
21918 while Present (Formal) loop
21919 Formals_To_Match := Formals_To_Match + 1;
21920 Next_Formal (Formal);
21923 -- Find if there is a named association, and verify that no positional
21924 -- associations appear after named ones.
21926 if Present (Actuals) then
21927 Actual := First (Actuals);
21930 while Present (Actual)
21931 and then Nkind (Actual) /= N_Parameter_Association
21933 Actuals_To_Match := Actuals_To_Match + 1;
21937 if No (Actual) and Actuals_To_Match = Formals_To_Match then
21939 -- Most common case: positional notation, no defaults
21944 elsif Actuals_To_Match > Formals_To_Match then
21946 -- Too many actuals: will not work
21949 if Is_Entity_Name (Name (N)) then
21950 Error_Msg_N ("too many arguments in call to&", Name (N));
21952 Error_Msg_N ("too many arguments in call", N);
21960 First_Named := Actual;
21962 while Present (Actual) loop
21963 if Nkind (Actual) /= N_Parameter_Association then
21965 ("positional parameters not allowed after named ones", Actual);
21970 Actuals_To_Match := Actuals_To_Match + 1;
21976 if Present (Actuals) then
21977 Actual := First (Actuals);
21980 Formal := First_Formal (S);
21981 while Present (Formal) loop
21983 -- Match the formals in order. If the corresponding actual is
21984 -- positional, nothing to do. Else scan the list of named actuals
21985 -- to find the one with the right name.
21987 if Present (Actual)
21988 and then Nkind (Actual) /= N_Parameter_Association
21991 Actuals_To_Match := Actuals_To_Match - 1;
21992 Formals_To_Match := Formals_To_Match - 1;
21995 -- For named parameters, search the list of actuals to find
21996 -- one that matches the next formal name.
21998 Actual := First_Named;
22000 while Present (Actual) loop
22001 if Chars (Selector_Name (Actual)) = Chars (Formal) then
22004 Actuals_To_Match := Actuals_To_Match - 1;
22005 Formals_To_Match := Formals_To_Match - 1;
22013 if Ekind (Formal) /= E_In_Parameter
22014 or else No (Default_Value (Formal))
22017 if (Comes_From_Source (S)
22018 or else Sloc (S) = Standard_Location)
22019 and then Is_Overloadable (S)
22023 Nkind_In (Parent (N), N_Procedure_Call_Statement,
22025 N_Parameter_Association)
22026 and then Ekind (S) /= E_Function
22028 Set_Etype (N, Etype (S));
22031 Error_Msg_Name_1 := Chars (S);
22032 Error_Msg_Sloc := Sloc (S);
22034 ("missing argument for parameter & "
22035 & "in call to % declared #", N, Formal);
22038 elsif Is_Overloadable (S) then
22039 Error_Msg_Name_1 := Chars (S);
22041 -- Point to type derivation that generated the
22044 Error_Msg_Sloc := Sloc (Parent (S));
22047 ("missing argument for parameter & "
22048 & "in call to % (inherited) #", N, Formal);
22052 ("missing argument for parameter &", N, Formal);
22060 Formals_To_Match := Formals_To_Match - 1;
22065 Next_Formal (Formal);
22068 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
22075 -- Find some superfluous named actual that did not get
22076 -- attached to the list of associations.
22078 Actual := First (Actuals);
22079 while Present (Actual) loop
22080 if Nkind (Actual) = N_Parameter_Association
22081 and then Actual /= Last
22082 and then No (Next_Named_Actual (Actual))
22084 -- A validity check may introduce a copy of a call that
22085 -- includes an extra actual (for example for an unrelated
22086 -- accessibility check). Check that the extra actual matches
22087 -- some extra formal, which must exist already because
22088 -- subprogram must be frozen at this point.
22090 if Present (Extra_Formals (S))
22091 and then not Comes_From_Source (Actual)
22092 and then Nkind (Actual) = N_Parameter_Association
22093 and then Chars (Extra_Formals (S)) =
22094 Chars (Selector_Name (Actual))
22099 ("unmatched actual & in call", Selector_Name (Actual));
22111 end Normalize_Actuals;
22113 --------------------------------
22114 -- Note_Possible_Modification --
22115 --------------------------------
22117 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
22118 Modification_Comes_From_Source : constant Boolean :=
22119 Comes_From_Source (Parent (N));
22125 -- Loop to find referenced entity, if there is one
22131 if Is_Entity_Name (Exp) then
22132 Ent := Entity (Exp);
22134 -- If the entity is missing, it is an undeclared identifier,
22135 -- and there is nothing to annotate.
22141 elsif Nkind (Exp) = N_Explicit_Dereference then
22143 P : constant Node_Id := Prefix (Exp);
22146 -- In formal verification mode, keep track of all reads and
22147 -- writes through explicit dereferences.
22149 if GNATprove_Mode then
22150 SPARK_Specific.Generate_Dereference (N, 'm');
22153 if Nkind (P) = N_Selected_Component
22154 and then Present (Entry_Formal (Entity (Selector_Name (P))))
22156 -- Case of a reference to an entry formal
22158 Ent := Entry_Formal (Entity (Selector_Name (P)));
22160 elsif Nkind (P) = N_Identifier
22161 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
22162 and then Present (Expression (Parent (Entity (P))))
22163 and then Nkind (Expression (Parent (Entity (P)))) =
22166 -- Case of a reference to a value on which side effects have
22169 Exp := Prefix (Expression (Parent (Entity (P))));
22177 elsif Nkind_In (Exp, N_Type_Conversion,
22178 N_Unchecked_Type_Conversion)
22180 Exp := Expression (Exp);
22183 elsif Nkind_In (Exp, N_Slice,
22184 N_Indexed_Component,
22185 N_Selected_Component)
22187 -- Special check, if the prefix is an access type, then return
22188 -- since we are modifying the thing pointed to, not the prefix.
22189 -- When we are expanding, most usually the prefix is replaced
22190 -- by an explicit dereference, and this test is not needed, but
22191 -- in some cases (notably -gnatc mode and generics) when we do
22192 -- not do full expansion, we need this special test.
22194 if Is_Access_Type (Etype (Prefix (Exp))) then
22197 -- Otherwise go to prefix and keep going
22200 Exp := Prefix (Exp);
22204 -- All other cases, not a modification
22210 -- Now look for entity being referenced
22212 if Present (Ent) then
22213 if Is_Object (Ent) then
22214 if Comes_From_Source (Exp)
22215 or else Modification_Comes_From_Source
22217 -- Give warning if pragma unmodified is given and we are
22218 -- sure this is a modification.
22220 if Has_Pragma_Unmodified (Ent) and then Sure then
22222 -- Note that the entity may be present only as a result
22223 -- of pragma Unused.
22225 if Has_Pragma_Unused (Ent) then
22226 Error_Msg_NE ("??pragma Unused given for &!", N, Ent);
22229 ("??pragma Unmodified given for &!", N, Ent);
22233 Set_Never_Set_In_Source (Ent, False);
22236 Set_Is_True_Constant (Ent, False);
22237 Set_Current_Value (Ent, Empty);
22238 Set_Is_Known_Null (Ent, False);
22240 if not Can_Never_Be_Null (Ent) then
22241 Set_Is_Known_Non_Null (Ent, False);
22244 -- Follow renaming chain
22246 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
22247 and then Present (Renamed_Object (Ent))
22249 Exp := Renamed_Object (Ent);
22251 -- If the entity is the loop variable in an iteration over
22252 -- a container, retrieve container expression to indicate
22253 -- possible modification.
22255 if Present (Related_Expression (Ent))
22256 and then Nkind (Parent (Related_Expression (Ent))) =
22257 N_Iterator_Specification
22259 Exp := Original_Node (Related_Expression (Ent));
22264 -- The expression may be the renaming of a subcomponent of an
22265 -- array or container. The assignment to the subcomponent is
22266 -- a modification of the container.
22268 elsif Comes_From_Source (Original_Node (Exp))
22269 and then Nkind_In (Original_Node (Exp), N_Selected_Component,
22270 N_Indexed_Component)
22272 Exp := Prefix (Original_Node (Exp));
22276 -- Generate a reference only if the assignment comes from
22277 -- source. This excludes, for example, calls to a dispatching
22278 -- assignment operation when the left-hand side is tagged. In
22279 -- GNATprove mode, we need those references also on generated
22280 -- code, as these are used to compute the local effects of
22283 if Modification_Comes_From_Source or GNATprove_Mode then
22284 Generate_Reference (Ent, Exp, 'm');
22286 -- If the target of the assignment is the bound variable
22287 -- in an iterator, indicate that the corresponding array
22288 -- or container is also modified.
22290 if Ada_Version >= Ada_2012
22291 and then Nkind (Parent (Ent)) = N_Iterator_Specification
22294 Domain : constant Node_Id := Name (Parent (Ent));
22297 -- TBD : in the full version of the construct, the
22298 -- domain of iteration can be given by an expression.
22300 if Is_Entity_Name (Domain) then
22301 Generate_Reference (Entity (Domain), Exp, 'm');
22302 Set_Is_True_Constant (Entity (Domain), False);
22303 Set_Never_Set_In_Source (Entity (Domain), False);
22312 -- If we are sure this is a modification from source, and we know
22313 -- this modifies a constant, then give an appropriate warning.
22316 and then Modification_Comes_From_Source
22317 and then Overlays_Constant (Ent)
22318 and then Address_Clause_Overlay_Warnings
22321 Addr : constant Node_Id := Address_Clause (Ent);
22326 Find_Overlaid_Entity (Addr, O_Ent, Off);
22328 Error_Msg_Sloc := Sloc (Addr);
22330 ("??constant& may be modified via address clause#",
22341 end Note_Possible_Modification;
22347 function Null_Status (N : Node_Id) return Null_Status_Kind is
22348 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean;
22349 -- Determine whether definition Def carries a null exclusion
22351 function Null_Status_Of_Entity (Id : Entity_Id) return Null_Status_Kind;
22352 -- Determine the null status of arbitrary entity Id
22354 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind;
22355 -- Determine the null status of type Typ
22357 ---------------------------
22358 -- Is_Null_Excluding_Def --
22359 ---------------------------
22361 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean is
22364 Nkind_In (Def, N_Access_Definition,
22365 N_Access_Function_Definition,
22366 N_Access_Procedure_Definition,
22367 N_Access_To_Object_Definition,
22368 N_Component_Definition,
22369 N_Derived_Type_Definition)
22370 and then Null_Exclusion_Present (Def);
22371 end Is_Null_Excluding_Def;
22373 ---------------------------
22374 -- Null_Status_Of_Entity --
22375 ---------------------------
22377 function Null_Status_Of_Entity
22378 (Id : Entity_Id) return Null_Status_Kind
22380 Decl : constant Node_Id := Declaration_Node (Id);
22384 -- The value of an imported or exported entity may be set externally
22385 -- regardless of a null exclusion. As a result, the value cannot be
22386 -- determined statically.
22388 if Is_Imported (Id) or else Is_Exported (Id) then
22391 elsif Nkind_In (Decl, N_Component_Declaration,
22392 N_Discriminant_Specification,
22393 N_Formal_Object_Declaration,
22394 N_Object_Declaration,
22395 N_Object_Renaming_Declaration,
22396 N_Parameter_Specification)
22398 -- A component declaration yields a non-null value when either
22399 -- its component definition or access definition carries a null
22402 if Nkind (Decl) = N_Component_Declaration then
22403 Def := Component_Definition (Decl);
22405 if Is_Null_Excluding_Def (Def) then
22406 return Is_Non_Null;
22409 Def := Access_Definition (Def);
22411 if Present (Def) and then Is_Null_Excluding_Def (Def) then
22412 return Is_Non_Null;
22415 -- A formal object declaration yields a non-null value if its
22416 -- access definition carries a null exclusion. If the object is
22417 -- default initialized, then the value depends on the expression.
22419 elsif Nkind (Decl) = N_Formal_Object_Declaration then
22420 Def := Access_Definition (Decl);
22422 if Present (Def) and then Is_Null_Excluding_Def (Def) then
22423 return Is_Non_Null;
22426 -- A constant may yield a null or non-null value depending on its
22427 -- initialization expression.
22429 elsif Ekind (Id) = E_Constant then
22430 return Null_Status (Constant_Value (Id));
22432 -- The construct yields a non-null value when it has a null
22435 elsif Null_Exclusion_Present (Decl) then
22436 return Is_Non_Null;
22438 -- An object renaming declaration yields a non-null value if its
22439 -- access definition carries a null exclusion. Otherwise the value
22440 -- depends on the renamed name.
22442 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
22443 Def := Access_Definition (Decl);
22445 if Present (Def) and then Is_Null_Excluding_Def (Def) then
22446 return Is_Non_Null;
22449 return Null_Status (Name (Decl));
22454 -- At this point the declaration of the entity does not carry a null
22455 -- exclusion and lacks an initialization expression. Check the status
22458 return Null_Status_Of_Type (Etype (Id));
22459 end Null_Status_Of_Entity;
22461 -------------------------
22462 -- Null_Status_Of_Type --
22463 -------------------------
22465 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind is
22470 -- Traverse the type chain looking for types with null exclusion
22473 while Present (Curr) and then Etype (Curr) /= Curr loop
22474 Decl := Parent (Curr);
22476 -- Guard against itypes which do not always have declarations. A
22477 -- type yields a non-null value if it carries a null exclusion.
22479 if Present (Decl) then
22480 if Nkind (Decl) = N_Full_Type_Declaration
22481 and then Is_Null_Excluding_Def (Type_Definition (Decl))
22483 return Is_Non_Null;
22485 elsif Nkind (Decl) = N_Subtype_Declaration
22486 and then Null_Exclusion_Present (Decl)
22488 return Is_Non_Null;
22492 Curr := Etype (Curr);
22495 -- The type chain does not contain any null excluding types
22498 end Null_Status_Of_Type;
22500 -- Start of processing for Null_Status
22503 -- Prevent cascaded errors or infinite loops when trying to determine
22504 -- the null status of an erroneous construct.
22506 if Error_Posted (N) then
22509 -- An allocator always creates a non-null value
22511 elsif Nkind (N) = N_Allocator then
22512 return Is_Non_Null;
22514 -- Taking the 'Access of something yields a non-null value
22516 elsif Nkind (N) = N_Attribute_Reference
22517 and then Nam_In (Attribute_Name (N), Name_Access,
22518 Name_Unchecked_Access,
22519 Name_Unrestricted_Access)
22521 return Is_Non_Null;
22523 -- "null" yields null
22525 elsif Nkind (N) = N_Null then
22528 -- Check the status of the operand of a type conversion
22530 elsif Nkind (N) = N_Type_Conversion then
22531 return Null_Status (Expression (N));
22533 -- The input denotes a reference to an entity. Determine whether the
22534 -- entity or its type yields a null or non-null value.
22536 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
22537 return Null_Status_Of_Entity (Entity (N));
22540 -- Otherwise it is not possible to determine the null status of the
22541 -- subexpression at compile time without resorting to simple flow
22547 --------------------------------------
22548 -- Null_To_Null_Address_Convert_OK --
22549 --------------------------------------
22551 function Null_To_Null_Address_Convert_OK
22553 Typ : Entity_Id := Empty) return Boolean
22556 if not Relaxed_RM_Semantics then
22560 if Nkind (N) = N_Null then
22561 return Present (Typ) and then Is_Descendant_Of_Address (Typ);
22563 elsif Nkind_In (N, N_Op_Eq, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt, N_Op_Ne)
22566 L : constant Node_Id := Left_Opnd (N);
22567 R : constant Node_Id := Right_Opnd (N);
22570 -- We check the Etype of the complementary operand since the
22571 -- N_Null node is not decorated at this stage.
22574 ((Nkind (L) = N_Null
22575 and then Is_Descendant_Of_Address (Etype (R)))
22577 (Nkind (R) = N_Null
22578 and then Is_Descendant_Of_Address (Etype (L))));
22583 end Null_To_Null_Address_Convert_OK;
22585 ---------------------------------
22586 -- Number_Of_Elements_In_Array --
22587 ---------------------------------
22589 function Number_Of_Elements_In_Array (T : Entity_Id) return Int is
22597 pragma Assert (Is_Array_Type (T));
22599 Indx := First_Index (T);
22600 while Present (Indx) loop
22601 Typ := Underlying_Type (Etype (Indx));
22603 -- Never look at junk bounds of a generic type
22605 if Is_Generic_Type (Typ) then
22609 -- Check the array bounds are known at compile time and return zero
22610 -- if they are not.
22612 Low := Type_Low_Bound (Typ);
22613 High := Type_High_Bound (Typ);
22615 if not Compile_Time_Known_Value (Low) then
22617 elsif not Compile_Time_Known_Value (High) then
22621 Num * UI_To_Int ((Expr_Value (High) - Expr_Value (Low) + 1));
22628 end Number_Of_Elements_In_Array;
22630 -------------------------
22631 -- Object_Access_Level --
22632 -------------------------
22634 -- Returns the static accessibility level of the view denoted by Obj. Note
22635 -- that the value returned is the result of a call to Scope_Depth. Only
22636 -- scope depths associated with dynamic scopes can actually be returned.
22637 -- Since only relative levels matter for accessibility checking, the fact
22638 -- that the distance between successive levels of accessibility is not
22639 -- always one is immaterial (invariant: if level(E2) is deeper than
22640 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
22642 function Object_Access_Level (Obj : Node_Id) return Uint is
22643 function Is_Interface_Conversion (N : Node_Id) return Boolean;
22644 -- Determine whether N is a construct of the form
22645 -- Some_Type (Operand._tag'Address)
22646 -- This construct appears in the context of dispatching calls.
22648 function Reference_To (Obj : Node_Id) return Node_Id;
22649 -- An explicit dereference is created when removing side effects from
22650 -- expressions for constraint checking purposes. In this case a local
22651 -- access type is created for it. The correct access level is that of
22652 -- the original source node. We detect this case by noting that the
22653 -- prefix of the dereference is created by an object declaration whose
22654 -- initial expression is a reference.
22656 -----------------------------
22657 -- Is_Interface_Conversion --
22658 -----------------------------
22660 function Is_Interface_Conversion (N : Node_Id) return Boolean is
22662 return Nkind (N) = N_Unchecked_Type_Conversion
22663 and then Nkind (Expression (N)) = N_Attribute_Reference
22664 and then Attribute_Name (Expression (N)) = Name_Address;
22665 end Is_Interface_Conversion;
22671 function Reference_To (Obj : Node_Id) return Node_Id is
22672 Pref : constant Node_Id := Prefix (Obj);
22674 if Is_Entity_Name (Pref)
22675 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
22676 and then Present (Expression (Parent (Entity (Pref))))
22677 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
22679 return (Prefix (Expression (Parent (Entity (Pref)))));
22689 -- Start of processing for Object_Access_Level
22692 if Nkind (Obj) = N_Defining_Identifier
22693 or else Is_Entity_Name (Obj)
22695 if Nkind (Obj) = N_Defining_Identifier then
22701 if Is_Prival (E) then
22702 E := Prival_Link (E);
22705 -- If E is a type then it denotes a current instance. For this case
22706 -- we add one to the normal accessibility level of the type to ensure
22707 -- that current instances are treated as always being deeper than
22708 -- than the level of any visible named access type (see 3.10.2(21)).
22710 if Is_Type (E) then
22711 return Type_Access_Level (E) + 1;
22713 elsif Present (Renamed_Object (E)) then
22714 return Object_Access_Level (Renamed_Object (E));
22716 -- Similarly, if E is a component of the current instance of a
22717 -- protected type, any instance of it is assumed to be at a deeper
22718 -- level than the type. For a protected object (whose type is an
22719 -- anonymous protected type) its components are at the same level
22720 -- as the type itself.
22722 elsif not Is_Overloadable (E)
22723 and then Ekind (Scope (E)) = E_Protected_Type
22724 and then Comes_From_Source (Scope (E))
22726 return Type_Access_Level (Scope (E)) + 1;
22729 -- Aliased formals of functions take their access level from the
22730 -- point of call, i.e. require a dynamic check. For static check
22731 -- purposes, this is smaller than the level of the subprogram
22732 -- itself. For procedures the aliased makes no difference.
22735 and then Is_Aliased (E)
22736 and then Ekind (Scope (E)) = E_Function
22738 return Type_Access_Level (Etype (E));
22741 return Scope_Depth (Enclosing_Dynamic_Scope (E));
22745 elsif Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
22746 if Is_Access_Type (Etype (Prefix (Obj))) then
22747 return Type_Access_Level (Etype (Prefix (Obj)));
22749 return Object_Access_Level (Prefix (Obj));
22752 elsif Nkind (Obj) = N_Explicit_Dereference then
22754 -- If the prefix is a selected access discriminant then we make a
22755 -- recursive call on the prefix, which will in turn check the level
22756 -- of the prefix object of the selected discriminant.
22758 -- In Ada 2012, if the discriminant has implicit dereference and
22759 -- the context is a selected component, treat this as an object of
22760 -- unknown scope (see below). This is necessary in compile-only mode;
22761 -- otherwise expansion will already have transformed the prefix into
22764 if Nkind (Prefix (Obj)) = N_Selected_Component
22765 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
22767 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
22769 (not Has_Implicit_Dereference
22770 (Entity (Selector_Name (Prefix (Obj))))
22771 or else Nkind (Parent (Obj)) /= N_Selected_Component)
22773 return Object_Access_Level (Prefix (Obj));
22775 -- Detect an interface conversion in the context of a dispatching
22776 -- call. Use the original form of the conversion to find the access
22777 -- level of the operand.
22779 elsif Is_Interface (Etype (Obj))
22780 and then Is_Interface_Conversion (Prefix (Obj))
22781 and then Nkind (Original_Node (Obj)) = N_Type_Conversion
22783 return Object_Access_Level (Original_Node (Obj));
22785 elsif not Comes_From_Source (Obj) then
22787 Ref : constant Node_Id := Reference_To (Obj);
22789 if Present (Ref) then
22790 return Object_Access_Level (Ref);
22792 return Type_Access_Level (Etype (Prefix (Obj)));
22797 return Type_Access_Level (Etype (Prefix (Obj)));
22800 elsif Nkind_In (Obj, N_Type_Conversion, N_Unchecked_Type_Conversion) then
22801 return Object_Access_Level (Expression (Obj));
22803 elsif Nkind (Obj) = N_Function_Call then
22805 -- Function results are objects, so we get either the access level of
22806 -- the function or, in the case of an indirect call, the level of the
22807 -- access-to-subprogram type. (This code is used for Ada 95, but it
22808 -- looks wrong, because it seems that we should be checking the level
22809 -- of the call itself, even for Ada 95. However, using the Ada 2005
22810 -- version of the code causes regressions in several tests that are
22811 -- compiled with -gnat95. ???)
22813 if Ada_Version < Ada_2005 then
22814 if Is_Entity_Name (Name (Obj)) then
22815 return Subprogram_Access_Level (Entity (Name (Obj)));
22817 return Type_Access_Level (Etype (Prefix (Name (Obj))));
22820 -- For Ada 2005, the level of the result object of a function call is
22821 -- defined to be the level of the call's innermost enclosing master.
22822 -- We determine that by querying the depth of the innermost enclosing
22826 Return_Master_Scope_Depth_Of_Call : declare
22827 function Innermost_Master_Scope_Depth
22828 (N : Node_Id) return Uint;
22829 -- Returns the scope depth of the given node's innermost
22830 -- enclosing dynamic scope (effectively the accessibility
22831 -- level of the innermost enclosing master).
22833 ----------------------------------
22834 -- Innermost_Master_Scope_Depth --
22835 ----------------------------------
22837 function Innermost_Master_Scope_Depth
22838 (N : Node_Id) return Uint
22840 Node_Par : Node_Id := Parent (N);
22843 -- Locate the nearest enclosing node (by traversing Parents)
22844 -- that Defining_Entity can be applied to, and return the
22845 -- depth of that entity's nearest enclosing dynamic scope.
22847 while Present (Node_Par) loop
22848 case Nkind (Node_Par) is
22849 when N_Abstract_Subprogram_Declaration
22850 | N_Block_Statement
22852 | N_Component_Declaration
22854 | N_Entry_Declaration
22855 | N_Exception_Declaration
22856 | N_Formal_Object_Declaration
22857 | N_Formal_Package_Declaration
22858 | N_Formal_Subprogram_Declaration
22859 | N_Formal_Type_Declaration
22860 | N_Full_Type_Declaration
22861 | N_Function_Specification
22862 | N_Generic_Declaration
22863 | N_Generic_Instantiation
22864 | N_Implicit_Label_Declaration
22865 | N_Incomplete_Type_Declaration
22866 | N_Loop_Parameter_Specification
22867 | N_Number_Declaration
22868 | N_Object_Declaration
22869 | N_Package_Declaration
22870 | N_Package_Specification
22871 | N_Parameter_Specification
22872 | N_Private_Extension_Declaration
22873 | N_Private_Type_Declaration
22874 | N_Procedure_Specification
22876 | N_Protected_Type_Declaration
22877 | N_Renaming_Declaration
22878 | N_Single_Protected_Declaration
22879 | N_Single_Task_Declaration
22880 | N_Subprogram_Declaration
22881 | N_Subtype_Declaration
22883 | N_Task_Type_Declaration
22886 (Nearest_Dynamic_Scope
22887 (Defining_Entity (Node_Par)));
22889 -- For a return statement within a function, return
22890 -- the depth of the function itself. This is not just
22891 -- a small optimization, but matters when analyzing
22892 -- the expression in an expression function before
22893 -- the body is created.
22895 when N_Simple_Return_Statement =>
22896 if Ekind (Current_Scope) = E_Function then
22897 return Scope_Depth (Current_Scope);
22904 Node_Par := Parent (Node_Par);
22907 pragma Assert (False);
22909 -- Should never reach the following return
22911 return Scope_Depth (Current_Scope) + 1;
22912 end Innermost_Master_Scope_Depth;
22914 -- Start of processing for Return_Master_Scope_Depth_Of_Call
22917 return Innermost_Master_Scope_Depth (Obj);
22918 end Return_Master_Scope_Depth_Of_Call;
22921 -- For convenience we handle qualified expressions, even though they
22922 -- aren't technically object names.
22924 elsif Nkind (Obj) = N_Qualified_Expression then
22925 return Object_Access_Level (Expression (Obj));
22927 -- Ditto for aggregates. They have the level of the temporary that
22928 -- will hold their value.
22930 elsif Nkind (Obj) = N_Aggregate then
22931 return Object_Access_Level (Current_Scope);
22933 -- Otherwise return the scope level of Standard. (If there are cases
22934 -- that fall through to this point they will be treated as having
22935 -- global accessibility for now. ???)
22938 return Scope_Depth (Standard_Standard);
22940 end Object_Access_Level;
22942 ----------------------------------
22943 -- Old_Requires_Transient_Scope --
22944 ----------------------------------
22946 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
22947 Typ : constant Entity_Id := Underlying_Type (Id);
22950 -- This is a private type which is not completed yet. This can only
22951 -- happen in a default expression (of a formal parameter or of a
22952 -- record component). Do not expand transient scope in this case.
22957 -- Do not expand transient scope for non-existent procedure return
22959 elsif Typ = Standard_Void_Type then
22962 -- Elementary types do not require a transient scope
22964 elsif Is_Elementary_Type (Typ) then
22967 -- Generally, indefinite subtypes require a transient scope, since the
22968 -- back end cannot generate temporaries, since this is not a valid type
22969 -- for declaring an object. It might be possible to relax this in the
22970 -- future, e.g. by declaring the maximum possible space for the type.
22972 elsif not Is_Definite_Subtype (Typ) then
22975 -- Functions returning tagged types may dispatch on result so their
22976 -- returned value is allocated on the secondary stack. Controlled
22977 -- type temporaries need finalization.
22979 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
22984 elsif Is_Record_Type (Typ) then
22989 Comp := First_Entity (Typ);
22990 while Present (Comp) loop
22991 if Ekind (Comp) = E_Component then
22993 -- ???It's not clear we need a full recursive call to
22994 -- Old_Requires_Transient_Scope here. Note that the
22995 -- following can't happen.
22997 pragma Assert (Is_Definite_Subtype (Etype (Comp)));
22998 pragma Assert (not Has_Controlled_Component (Etype (Comp)));
23000 if Old_Requires_Transient_Scope (Etype (Comp)) then
23005 Next_Entity (Comp);
23011 -- String literal types never require transient scope
23013 elsif Ekind (Typ) = E_String_Literal_Subtype then
23016 -- Array type. Note that we already know that this is a constrained
23017 -- array, since unconstrained arrays will fail the indefinite test.
23019 elsif Is_Array_Type (Typ) then
23021 -- If component type requires a transient scope, the array does too
23023 if Old_Requires_Transient_Scope (Component_Type (Typ)) then
23026 -- Otherwise, we only need a transient scope if the size depends on
23027 -- the value of one or more discriminants.
23030 return Size_Depends_On_Discriminant (Typ);
23033 -- All other cases do not require a transient scope
23036 pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
23039 end Old_Requires_Transient_Scope;
23041 ---------------------------------
23042 -- Original_Aspect_Pragma_Name --
23043 ---------------------------------
23045 function Original_Aspect_Pragma_Name (N : Node_Id) return Name_Id is
23047 Item_Nam : Name_Id;
23050 pragma Assert (Nkind_In (N, N_Aspect_Specification, N_Pragma));
23054 -- The pragma was generated to emulate an aspect, use the original
23055 -- aspect specification.
23057 if Nkind (Item) = N_Pragma and then From_Aspect_Specification (Item) then
23058 Item := Corresponding_Aspect (Item);
23061 -- Retrieve the name of the aspect/pragma. Note that Pre, Pre_Class,
23062 -- Post and Post_Class rewrite their pragma identifier to preserve the
23064 -- ??? this is kludgey
23066 if Nkind (Item) = N_Pragma then
23067 Item_Nam := Chars (Original_Node (Pragma_Identifier (Item)));
23070 pragma Assert (Nkind (Item) = N_Aspect_Specification);
23071 Item_Nam := Chars (Identifier (Item));
23074 -- Deal with 'Class by converting the name to its _XXX form
23076 if Class_Present (Item) then
23077 if Item_Nam = Name_Invariant then
23078 Item_Nam := Name_uInvariant;
23080 elsif Item_Nam = Name_Post then
23081 Item_Nam := Name_uPost;
23083 elsif Item_Nam = Name_Pre then
23084 Item_Nam := Name_uPre;
23086 elsif Nam_In (Item_Nam, Name_Type_Invariant,
23087 Name_Type_Invariant_Class)
23089 Item_Nam := Name_uType_Invariant;
23091 -- Nothing to do for other cases (e.g. a Check that derived from
23092 -- Pre_Class and has the flag set). Also we do nothing if the name
23093 -- is already in special _xxx form.
23099 end Original_Aspect_Pragma_Name;
23101 --------------------------------------
23102 -- Original_Corresponding_Operation --
23103 --------------------------------------
23105 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
23107 Typ : constant Entity_Id := Find_Dispatching_Type (S);
23110 -- If S is an inherited primitive S2 the original corresponding
23111 -- operation of S is the original corresponding operation of S2
23113 if Present (Alias (S))
23114 and then Find_Dispatching_Type (Alias (S)) /= Typ
23116 return Original_Corresponding_Operation (Alias (S));
23118 -- If S overrides an inherited subprogram S2 the original corresponding
23119 -- operation of S is the original corresponding operation of S2
23121 elsif Present (Overridden_Operation (S)) then
23122 return Original_Corresponding_Operation (Overridden_Operation (S));
23124 -- otherwise it is S itself
23129 end Original_Corresponding_Operation;
23131 -------------------
23132 -- Output_Entity --
23133 -------------------
23135 procedure Output_Entity (Id : Entity_Id) is
23139 Scop := Scope (Id);
23141 -- The entity may lack a scope when it is in the process of being
23142 -- analyzed. Use the current scope as an approximation.
23145 Scop := Current_Scope;
23148 Output_Name (Chars (Id), Scop);
23155 procedure Output_Name (Nam : Name_Id; Scop : Entity_Id := Current_Scope) is
23159 (Get_Qualified_Name
23166 ----------------------
23167 -- Policy_In_Effect --
23168 ----------------------
23170 function Policy_In_Effect (Policy : Name_Id) return Name_Id is
23171 function Policy_In_List (List : Node_Id) return Name_Id;
23172 -- Determine the mode of a policy in a N_Pragma list
23174 --------------------
23175 -- Policy_In_List --
23176 --------------------
23178 function Policy_In_List (List : Node_Id) return Name_Id is
23185 while Present (Prag) loop
23186 Arg1 := First (Pragma_Argument_Associations (Prag));
23187 Arg2 := Next (Arg1);
23189 Arg1 := Get_Pragma_Arg (Arg1);
23190 Arg2 := Get_Pragma_Arg (Arg2);
23192 -- The current Check_Policy pragma matches the requested policy or
23193 -- appears in the single argument form (Assertion, policy_id).
23195 if Nam_In (Chars (Arg1), Name_Assertion, Policy) then
23196 return Chars (Arg2);
23199 Prag := Next_Pragma (Prag);
23203 end Policy_In_List;
23209 -- Start of processing for Policy_In_Effect
23212 if not Is_Valid_Assertion_Kind (Policy) then
23213 raise Program_Error;
23216 -- Inspect all policy pragmas that appear within scopes (if any)
23218 Kind := Policy_In_List (Check_Policy_List);
23220 -- Inspect all configuration policy pragmas (if any)
23222 if Kind = No_Name then
23223 Kind := Policy_In_List (Check_Policy_List_Config);
23226 -- The context lacks policy pragmas, determine the mode based on whether
23227 -- assertions are enabled at the configuration level. This ensures that
23228 -- the policy is preserved when analyzing generics.
23230 if Kind = No_Name then
23231 if Assertions_Enabled_Config then
23232 Kind := Name_Check;
23234 Kind := Name_Ignore;
23238 -- In CodePeer mode and GNATprove mode, we need to consider all
23239 -- assertions, unless they are disabled. Force Name_Check on
23240 -- ignored assertions.
23242 if Nam_In (Kind, Name_Ignore, Name_Off)
23243 and then (CodePeer_Mode or GNATprove_Mode)
23245 Kind := Name_Check;
23249 end Policy_In_Effect;
23251 ----------------------------------
23252 -- Predicate_Tests_On_Arguments --
23253 ----------------------------------
23255 function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean is
23257 -- Always test predicates on indirect call
23259 if Ekind (Subp) = E_Subprogram_Type then
23262 -- Do not test predicates on call to generated default Finalize, since
23263 -- we are not interested in whether something we are finalizing (and
23264 -- typically destroying) satisfies its predicates.
23266 elsif Chars (Subp) = Name_Finalize
23267 and then not Comes_From_Source (Subp)
23271 -- Do not test predicates on any internally generated routines
23273 elsif Is_Internal_Name (Chars (Subp)) then
23276 -- Do not test predicates on call to Init_Proc, since if needed the
23277 -- predicate test will occur at some other point.
23279 elsif Is_Init_Proc (Subp) then
23282 -- Do not test predicates on call to predicate function, since this
23283 -- would cause infinite recursion.
23285 elsif Ekind (Subp) = E_Function
23286 and then (Is_Predicate_Function (Subp)
23288 Is_Predicate_Function_M (Subp))
23292 -- For now, no other exceptions
23297 end Predicate_Tests_On_Arguments;
23299 -----------------------
23300 -- Private_Component --
23301 -----------------------
23303 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
23304 Ancestor : constant Entity_Id := Base_Type (Type_Id);
23306 function Trace_Components
23308 Check : Boolean) return Entity_Id;
23309 -- Recursive function that does the work, and checks against circular
23310 -- definition for each subcomponent type.
23312 ----------------------
23313 -- Trace_Components --
23314 ----------------------
23316 function Trace_Components
23318 Check : Boolean) return Entity_Id
23320 Btype : constant Entity_Id := Base_Type (T);
23321 Component : Entity_Id;
23323 Candidate : Entity_Id := Empty;
23326 if Check and then Btype = Ancestor then
23327 Error_Msg_N ("circular type definition", Type_Id);
23331 if Is_Private_Type (Btype) and then not Is_Generic_Type (Btype) then
23332 if Present (Full_View (Btype))
23333 and then Is_Record_Type (Full_View (Btype))
23334 and then not Is_Frozen (Btype)
23336 -- To indicate that the ancestor depends on a private type, the
23337 -- current Btype is sufficient. However, to check for circular
23338 -- definition we must recurse on the full view.
23340 Candidate := Trace_Components (Full_View (Btype), True);
23342 if Candidate = Any_Type then
23352 elsif Is_Array_Type (Btype) then
23353 return Trace_Components (Component_Type (Btype), True);
23355 elsif Is_Record_Type (Btype) then
23356 Component := First_Entity (Btype);
23357 while Present (Component)
23358 and then Comes_From_Source (Component)
23360 -- Skip anonymous types generated by constrained components
23362 if not Is_Type (Component) then
23363 P := Trace_Components (Etype (Component), True);
23365 if Present (P) then
23366 if P = Any_Type then
23374 Next_Entity (Component);
23382 end Trace_Components;
23384 -- Start of processing for Private_Component
23387 return Trace_Components (Type_Id, False);
23388 end Private_Component;
23390 ---------------------------
23391 -- Primitive_Names_Match --
23392 ---------------------------
23394 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
23395 function Non_Internal_Name (E : Entity_Id) return Name_Id;
23396 -- Given an internal name, returns the corresponding non-internal name
23398 ------------------------
23399 -- Non_Internal_Name --
23400 ------------------------
23402 function Non_Internal_Name (E : Entity_Id) return Name_Id is
23404 Get_Name_String (Chars (E));
23405 Name_Len := Name_Len - 1;
23407 end Non_Internal_Name;
23409 -- Start of processing for Primitive_Names_Match
23412 pragma Assert (Present (E1) and then Present (E2));
23414 return Chars (E1) = Chars (E2)
23416 (not Is_Internal_Name (Chars (E1))
23417 and then Is_Internal_Name (Chars (E2))
23418 and then Non_Internal_Name (E2) = Chars (E1))
23420 (not Is_Internal_Name (Chars (E2))
23421 and then Is_Internal_Name (Chars (E1))
23422 and then Non_Internal_Name (E1) = Chars (E2))
23424 (Is_Predefined_Dispatching_Operation (E1)
23425 and then Is_Predefined_Dispatching_Operation (E2)
23426 and then Same_TSS (E1, E2))
23428 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
23429 end Primitive_Names_Match;
23431 -----------------------
23432 -- Process_End_Label --
23433 -----------------------
23435 procedure Process_End_Label
23444 Label_Ref : Boolean;
23445 -- Set True if reference to end label itself is required
23448 -- Gets set to the operator symbol or identifier that references the
23449 -- entity Ent. For the child unit case, this is the identifier from the
23450 -- designator. For other cases, this is simply Endl.
23452 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
23453 -- N is an identifier node that appears as a parent unit reference in
23454 -- the case where Ent is a child unit. This procedure generates an
23455 -- appropriate cross-reference entry. E is the corresponding entity.
23457 -------------------------
23458 -- Generate_Parent_Ref --
23459 -------------------------
23461 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
23463 -- If names do not match, something weird, skip reference
23465 if Chars (E) = Chars (N) then
23467 -- Generate the reference. We do NOT consider this as a reference
23468 -- for unreferenced symbol purposes.
23470 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
23472 if Style_Check then
23473 Style.Check_Identifier (N, E);
23476 end Generate_Parent_Ref;
23478 -- Start of processing for Process_End_Label
23481 -- If no node, ignore. This happens in some error situations, and
23482 -- also for some internally generated structures where no end label
23483 -- references are required in any case.
23489 -- Nothing to do if no End_Label, happens for internally generated
23490 -- constructs where we don't want an end label reference anyway. Also
23491 -- nothing to do if Endl is a string literal, which means there was
23492 -- some prior error (bad operator symbol)
23494 Endl := End_Label (N);
23496 if No (Endl) or else Nkind (Endl) = N_String_Literal then
23500 -- Reference node is not in extended main source unit
23502 if not In_Extended_Main_Source_Unit (N) then
23504 -- Generally we do not collect references except for the extended
23505 -- main source unit. The one exception is the 'e' entry for a
23506 -- package spec, where it is useful for a client to have the
23507 -- ending information to define scopes.
23513 Label_Ref := False;
23515 -- For this case, we can ignore any parent references, but we
23516 -- need the package name itself for the 'e' entry.
23518 if Nkind (Endl) = N_Designator then
23519 Endl := Identifier (Endl);
23523 -- Reference is in extended main source unit
23528 -- For designator, generate references for the parent entries
23530 if Nkind (Endl) = N_Designator then
23532 -- Generate references for the prefix if the END line comes from
23533 -- source (otherwise we do not need these references) We climb the
23534 -- scope stack to find the expected entities.
23536 if Comes_From_Source (Endl) then
23537 Nam := Name (Endl);
23538 Scop := Current_Scope;
23539 while Nkind (Nam) = N_Selected_Component loop
23540 Scop := Scope (Scop);
23541 exit when No (Scop);
23542 Generate_Parent_Ref (Selector_Name (Nam), Scop);
23543 Nam := Prefix (Nam);
23546 if Present (Scop) then
23547 Generate_Parent_Ref (Nam, Scope (Scop));
23551 Endl := Identifier (Endl);
23555 -- If the end label is not for the given entity, then either we have
23556 -- some previous error, or this is a generic instantiation for which
23557 -- we do not need to make a cross-reference in this case anyway. In
23558 -- either case we simply ignore the call.
23560 if Chars (Ent) /= Chars (Endl) then
23564 -- If label was really there, then generate a normal reference and then
23565 -- adjust the location in the end label to point past the name (which
23566 -- should almost always be the semicolon).
23568 Loc := Sloc (Endl);
23570 if Comes_From_Source (Endl) then
23572 -- If a label reference is required, then do the style check and
23573 -- generate an l-type cross-reference entry for the label
23576 if Style_Check then
23577 Style.Check_Identifier (Endl, Ent);
23580 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
23583 -- Set the location to point past the label (normally this will
23584 -- mean the semicolon immediately following the label). This is
23585 -- done for the sake of the 'e' or 't' entry generated below.
23587 Get_Decoded_Name_String (Chars (Endl));
23588 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
23591 -- In SPARK mode, no missing label is allowed for packages and
23592 -- subprogram bodies. Detect those cases by testing whether
23593 -- Process_End_Label was called for a body (Typ = 't') or a package.
23595 if Restriction_Check_Required (SPARK_05)
23596 and then (Typ = 't' or else Ekind (Ent) = E_Package)
23598 Error_Msg_Node_1 := Endl;
23599 Check_SPARK_05_Restriction
23600 ("`END &` required", Endl, Force => True);
23604 -- Now generate the e/t reference
23606 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
23608 -- Restore Sloc, in case modified above, since we have an identifier
23609 -- and the normal Sloc should be left set in the tree.
23611 Set_Sloc (Endl, Loc);
23612 end Process_End_Label;
23614 --------------------------------
23615 -- Propagate_Concurrent_Flags --
23616 --------------------------------
23618 procedure Propagate_Concurrent_Flags
23620 Comp_Typ : Entity_Id)
23623 if Has_Task (Comp_Typ) then
23624 Set_Has_Task (Typ);
23627 if Has_Protected (Comp_Typ) then
23628 Set_Has_Protected (Typ);
23631 if Has_Timing_Event (Comp_Typ) then
23632 Set_Has_Timing_Event (Typ);
23634 end Propagate_Concurrent_Flags;
23636 ------------------------------
23637 -- Propagate_DIC_Attributes --
23638 ------------------------------
23640 procedure Propagate_DIC_Attributes
23642 From_Typ : Entity_Id)
23644 DIC_Proc : Entity_Id;
23647 if Present (Typ) and then Present (From_Typ) then
23648 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
23650 -- Nothing to do if both the source and the destination denote the
23653 if From_Typ = Typ then
23656 -- Nothing to do when the destination denotes an incomplete type
23657 -- because the DIC is associated with the current instance of a
23658 -- private type, thus it can never apply to an incomplete type.
23660 elsif Is_Incomplete_Type (Typ) then
23664 DIC_Proc := DIC_Procedure (From_Typ);
23666 -- The setting of the attributes is intentionally conservative. This
23667 -- prevents accidental clobbering of enabled attributes.
23669 if Has_Inherited_DIC (From_Typ)
23670 and then not Has_Inherited_DIC (Typ)
23672 Set_Has_Inherited_DIC (Typ);
23675 if Has_Own_DIC (From_Typ) and then not Has_Own_DIC (Typ) then
23676 Set_Has_Own_DIC (Typ);
23679 if Present (DIC_Proc) and then No (DIC_Procedure (Typ)) then
23680 Set_DIC_Procedure (Typ, DIC_Proc);
23683 end Propagate_DIC_Attributes;
23685 ------------------------------------
23686 -- Propagate_Invariant_Attributes --
23687 ------------------------------------
23689 procedure Propagate_Invariant_Attributes
23691 From_Typ : Entity_Id)
23693 Full_IP : Entity_Id;
23694 Part_IP : Entity_Id;
23697 if Present (Typ) and then Present (From_Typ) then
23698 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
23700 -- Nothing to do if both the source and the destination denote the
23703 if From_Typ = Typ then
23707 Full_IP := Invariant_Procedure (From_Typ);
23708 Part_IP := Partial_Invariant_Procedure (From_Typ);
23710 -- The setting of the attributes is intentionally conservative. This
23711 -- prevents accidental clobbering of enabled attributes.
23713 if Has_Inheritable_Invariants (From_Typ)
23714 and then not Has_Inheritable_Invariants (Typ)
23716 Set_Has_Inheritable_Invariants (Typ);
23719 if Has_Inherited_Invariants (From_Typ)
23720 and then not Has_Inherited_Invariants (Typ)
23722 Set_Has_Inherited_Invariants (Typ);
23725 if Has_Own_Invariants (From_Typ)
23726 and then not Has_Own_Invariants (Typ)
23728 Set_Has_Own_Invariants (Typ);
23731 if Present (Full_IP) and then No (Invariant_Procedure (Typ)) then
23732 Set_Invariant_Procedure (Typ, Full_IP);
23735 if Present (Part_IP) and then No (Partial_Invariant_Procedure (Typ))
23737 Set_Partial_Invariant_Procedure (Typ, Part_IP);
23740 end Propagate_Invariant_Attributes;
23742 ---------------------------------------
23743 -- Record_Possible_Part_Of_Reference --
23744 ---------------------------------------
23746 procedure Record_Possible_Part_Of_Reference
23747 (Var_Id : Entity_Id;
23750 Encap : constant Entity_Id := Encapsulating_State (Var_Id);
23754 -- The variable is a constituent of a single protected/task type. Such
23755 -- a variable acts as a component of the type and must appear within a
23756 -- specific region (SPARK RM 9(3)). Instead of recording the reference,
23757 -- verify its legality now.
23759 if Present (Encap) and then Is_Single_Concurrent_Object (Encap) then
23760 Check_Part_Of_Reference (Var_Id, Ref);
23762 -- The variable is subject to pragma Part_Of and may eventually become a
23763 -- constituent of a single protected/task type. Record the reference to
23764 -- verify its placement when the contract of the variable is analyzed.
23766 elsif Present (Get_Pragma (Var_Id, Pragma_Part_Of)) then
23767 Refs := Part_Of_References (Var_Id);
23770 Refs := New_Elmt_List;
23771 Set_Part_Of_References (Var_Id, Refs);
23774 Append_Elmt (Ref, Refs);
23776 end Record_Possible_Part_Of_Reference;
23782 function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
23783 Seen : Boolean := False;
23785 function Is_Reference (N : Node_Id) return Traverse_Result;
23786 -- Determine whether node N denotes a reference to Id. If this is the
23787 -- case, set global flag Seen to True and stop the traversal.
23793 function Is_Reference (N : Node_Id) return Traverse_Result is
23795 if Is_Entity_Name (N)
23796 and then Present (Entity (N))
23797 and then Entity (N) = Id
23806 procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
23808 -- Start of processing for Referenced
23811 Inspect_Expression (Expr);
23815 ------------------------------------
23816 -- References_Generic_Formal_Type --
23817 ------------------------------------
23819 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
23821 function Process (N : Node_Id) return Traverse_Result;
23822 -- Process one node in search for generic formal type
23828 function Process (N : Node_Id) return Traverse_Result is
23830 if Nkind (N) in N_Has_Entity then
23832 E : constant Entity_Id := Entity (N);
23834 if Present (E) then
23835 if Is_Generic_Type (E) then
23837 elsif Present (Etype (E))
23838 and then Is_Generic_Type (Etype (E))
23849 function Traverse is new Traverse_Func (Process);
23850 -- Traverse tree to look for generic type
23853 if Inside_A_Generic then
23854 return Traverse (N) = Abandon;
23858 end References_Generic_Formal_Type;
23860 -------------------------------
23861 -- Remove_Entity_And_Homonym --
23862 -------------------------------
23864 procedure Remove_Entity_And_Homonym (Id : Entity_Id) is
23866 Remove_Entity (Id);
23867 Remove_Homonym (Id);
23868 end Remove_Entity_And_Homonym;
23870 --------------------
23871 -- Remove_Homonym --
23872 --------------------
23874 procedure Remove_Homonym (Id : Entity_Id) is
23876 Prev : Entity_Id := Empty;
23879 if Id = Current_Entity (Id) then
23880 if Present (Homonym (Id)) then
23881 Set_Current_Entity (Homonym (Id));
23883 Set_Name_Entity_Id (Chars (Id), Empty);
23887 Hom := Current_Entity (Id);
23888 while Present (Hom) and then Hom /= Id loop
23890 Hom := Homonym (Hom);
23893 -- If Id is not on the homonym chain, nothing to do
23895 if Present (Hom) then
23896 Set_Homonym (Prev, Homonym (Id));
23899 end Remove_Homonym;
23901 ------------------------------
23902 -- Remove_Overloaded_Entity --
23903 ------------------------------
23905 procedure Remove_Overloaded_Entity (Id : Entity_Id) is
23906 procedure Remove_Primitive_Of (Typ : Entity_Id);
23907 -- Remove primitive subprogram Id from the list of primitives that
23908 -- belong to type Typ.
23910 -------------------------
23911 -- Remove_Primitive_Of --
23912 -------------------------
23914 procedure Remove_Primitive_Of (Typ : Entity_Id) is
23918 if Is_Tagged_Type (Typ) then
23919 Prims := Direct_Primitive_Operations (Typ);
23921 if Present (Prims) then
23922 Remove (Prims, Id);
23925 end Remove_Primitive_Of;
23929 Formal : Entity_Id;
23931 -- Start of processing for Remove_Overloaded_Entity
23934 Remove_Entity_And_Homonym (Id);
23936 -- The entity denotes a primitive subprogram. Remove it from the list of
23937 -- primitives of the associated controlling type.
23939 if Ekind_In (Id, E_Function, E_Procedure) and then Is_Primitive (Id) then
23940 Formal := First_Formal (Id);
23941 while Present (Formal) loop
23942 if Is_Controlling_Formal (Formal) then
23943 Remove_Primitive_Of (Etype (Formal));
23947 Next_Formal (Formal);
23950 if Ekind (Id) = E_Function and then Has_Controlling_Result (Id) then
23951 Remove_Primitive_Of (Etype (Id));
23954 end Remove_Overloaded_Entity;
23956 ---------------------
23957 -- Rep_To_Pos_Flag --
23958 ---------------------
23960 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
23962 return New_Occurrence_Of
23963 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
23964 end Rep_To_Pos_Flag;
23966 --------------------
23967 -- Require_Entity --
23968 --------------------
23970 procedure Require_Entity (N : Node_Id) is
23972 if Is_Entity_Name (N) and then No (Entity (N)) then
23973 if Total_Errors_Detected /= 0 then
23974 Set_Entity (N, Any_Id);
23976 raise Program_Error;
23979 end Require_Entity;
23981 ------------------------------
23982 -- Requires_Transient_Scope --
23983 ------------------------------
23985 -- A transient scope is required when variable-sized temporaries are
23986 -- allocated on the secondary stack, or when finalization actions must be
23987 -- generated before the next instruction.
23989 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
23990 Old_Result : constant Boolean := Old_Requires_Transient_Scope (Id);
23993 if Debug_Flag_QQ then
23998 New_Result : constant Boolean := New_Requires_Transient_Scope (Id);
24001 -- Assert that we're not putting things on the secondary stack if we
24002 -- didn't before; we are trying to AVOID secondary stack when
24005 if not Old_Result then
24006 pragma Assert (not New_Result);
24010 if New_Result /= Old_Result then
24011 Results_Differ (Id, Old_Result, New_Result);
24016 end Requires_Transient_Scope;
24018 --------------------
24019 -- Results_Differ --
24020 --------------------
24022 procedure Results_Differ
24028 if False then -- False to disable; True for debugging
24029 Treepr.Print_Tree_Node (Id);
24031 if Old_Val = New_Val then
24032 raise Program_Error;
24035 end Results_Differ;
24037 --------------------------
24038 -- Reset_Analyzed_Flags --
24039 --------------------------
24041 procedure Reset_Analyzed_Flags (N : Node_Id) is
24042 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
24043 -- Function used to reset Analyzed flags in tree. Note that we do
24044 -- not reset Analyzed flags in entities, since there is no need to
24045 -- reanalyze entities, and indeed, it is wrong to do so, since it
24046 -- can result in generating auxiliary stuff more than once.
24048 --------------------
24049 -- Clear_Analyzed --
24050 --------------------
24052 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
24054 if Nkind (N) not in N_Entity then
24055 Set_Analyzed (N, False);
24059 end Clear_Analyzed;
24061 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
24063 -- Start of processing for Reset_Analyzed_Flags
24066 Reset_Analyzed (N);
24067 end Reset_Analyzed_Flags;
24069 ------------------------
24070 -- Restore_SPARK_Mode --
24071 ------------------------
24073 procedure Restore_SPARK_Mode
24074 (Mode : SPARK_Mode_Type;
24078 SPARK_Mode := Mode;
24079 SPARK_Mode_Pragma := Prag;
24080 end Restore_SPARK_Mode;
24082 --------------------------------
24083 -- Returns_Unconstrained_Type --
24084 --------------------------------
24086 function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
24088 return Ekind (Subp) = E_Function
24089 and then not Is_Scalar_Type (Etype (Subp))
24090 and then not Is_Access_Type (Etype (Subp))
24091 and then not Is_Constrained (Etype (Subp));
24092 end Returns_Unconstrained_Type;
24094 ----------------------------
24095 -- Root_Type_Of_Full_View --
24096 ----------------------------
24098 function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id is
24099 Rtyp : constant Entity_Id := Root_Type (T);
24102 -- The root type of the full view may itself be a private type. Keep
24103 -- looking for the ultimate derivation parent.
24105 if Is_Private_Type (Rtyp) and then Present (Full_View (Rtyp)) then
24106 return Root_Type_Of_Full_View (Full_View (Rtyp));
24110 end Root_Type_Of_Full_View;
24112 ---------------------------
24113 -- Safe_To_Capture_Value --
24114 ---------------------------
24116 function Safe_To_Capture_Value
24119 Cond : Boolean := False) return Boolean
24122 -- The only entities for which we track constant values are variables
24123 -- which are not renamings, constants, out parameters, and in out
24124 -- parameters, so check if we have this case.
24126 -- Note: it may seem odd to track constant values for constants, but in
24127 -- fact this routine is used for other purposes than simply capturing
24128 -- the value. In particular, the setting of Known[_Non]_Null.
24130 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
24132 Ekind_In (Ent, E_Constant, E_Out_Parameter, E_In_Out_Parameter)
24136 -- For conditionals, we also allow loop parameters and all formals,
24137 -- including in parameters.
24139 elsif Cond and then Ekind_In (Ent, E_Loop_Parameter, E_In_Parameter) then
24142 -- For all other cases, not just unsafe, but impossible to capture
24143 -- Current_Value, since the above are the only entities which have
24144 -- Current_Value fields.
24150 -- Skip if volatile or aliased, since funny things might be going on in
24151 -- these cases which we cannot necessarily track. Also skip any variable
24152 -- for which an address clause is given, or whose address is taken. Also
24153 -- never capture value of library level variables (an attempt to do so
24154 -- can occur in the case of package elaboration code).
24156 if Treat_As_Volatile (Ent)
24157 or else Is_Aliased (Ent)
24158 or else Present (Address_Clause (Ent))
24159 or else Address_Taken (Ent)
24160 or else (Is_Library_Level_Entity (Ent)
24161 and then Ekind (Ent) = E_Variable)
24166 -- OK, all above conditions are met. We also require that the scope of
24167 -- the reference be the same as the scope of the entity, not counting
24168 -- packages and blocks and loops.
24171 E_Scope : constant Entity_Id := Scope (Ent);
24172 R_Scope : Entity_Id;
24175 R_Scope := Current_Scope;
24176 while R_Scope /= Standard_Standard loop
24177 exit when R_Scope = E_Scope;
24179 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
24182 R_Scope := Scope (R_Scope);
24187 -- We also require that the reference does not appear in a context
24188 -- where it is not sure to be executed (i.e. a conditional context
24189 -- or an exception handler). We skip this if Cond is True, since the
24190 -- capturing of values from conditional tests handles this ok.
24203 -- Seems dubious that case expressions are not handled here ???
24206 while Present (P) loop
24207 if Nkind (P) = N_If_Statement
24208 or else Nkind (P) = N_Case_Statement
24209 or else (Nkind (P) in N_Short_Circuit
24210 and then Desc = Right_Opnd (P))
24211 or else (Nkind (P) = N_If_Expression
24212 and then Desc /= First (Expressions (P)))
24213 or else Nkind (P) = N_Exception_Handler
24214 or else Nkind (P) = N_Selective_Accept
24215 or else Nkind (P) = N_Conditional_Entry_Call
24216 or else Nkind (P) = N_Timed_Entry_Call
24217 or else Nkind (P) = N_Asynchronous_Select
24225 -- A special Ada 2012 case: the original node may be part
24226 -- of the else_actions of a conditional expression, in which
24227 -- case it might not have been expanded yet, and appears in
24228 -- a non-syntactic list of actions. In that case it is clearly
24229 -- not safe to save a value.
24232 and then Is_List_Member (Desc)
24233 and then No (Parent (List_Containing (Desc)))
24241 -- OK, looks safe to set value
24244 end Safe_To_Capture_Value;
24250 function Same_Name (N1, N2 : Node_Id) return Boolean is
24251 K1 : constant Node_Kind := Nkind (N1);
24252 K2 : constant Node_Kind := Nkind (N2);
24255 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
24256 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
24258 return Chars (N1) = Chars (N2);
24260 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
24261 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
24263 return Same_Name (Selector_Name (N1), Selector_Name (N2))
24264 and then Same_Name (Prefix (N1), Prefix (N2));
24275 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
24276 N1 : constant Node_Id := Original_Node (Node1);
24277 N2 : constant Node_Id := Original_Node (Node2);
24278 -- We do the tests on original nodes, since we are most interested
24279 -- in the original source, not any expansion that got in the way.
24281 K1 : constant Node_Kind := Nkind (N1);
24282 K2 : constant Node_Kind := Nkind (N2);
24285 -- First case, both are entities with same entity
24287 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
24289 EN1 : constant Entity_Id := Entity (N1);
24290 EN2 : constant Entity_Id := Entity (N2);
24292 if Present (EN1) and then Present (EN2)
24293 and then (Ekind_In (EN1, E_Variable, E_Constant)
24294 or else Is_Formal (EN1))
24302 -- Second case, selected component with same selector, same record
24304 if K1 = N_Selected_Component
24305 and then K2 = N_Selected_Component
24306 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
24308 return Same_Object (Prefix (N1), Prefix (N2));
24310 -- Third case, indexed component with same subscripts, same array
24312 elsif K1 = N_Indexed_Component
24313 and then K2 = N_Indexed_Component
24314 and then Same_Object (Prefix (N1), Prefix (N2))
24319 E1 := First (Expressions (N1));
24320 E2 := First (Expressions (N2));
24321 while Present (E1) loop
24322 if not Same_Value (E1, E2) then
24333 -- Fourth case, slice of same array with same bounds
24336 and then K2 = N_Slice
24337 and then Nkind (Discrete_Range (N1)) = N_Range
24338 and then Nkind (Discrete_Range (N2)) = N_Range
24339 and then Same_Value (Low_Bound (Discrete_Range (N1)),
24340 Low_Bound (Discrete_Range (N2)))
24341 and then Same_Value (High_Bound (Discrete_Range (N1)),
24342 High_Bound (Discrete_Range (N2)))
24344 return Same_Name (Prefix (N1), Prefix (N2));
24346 -- All other cases, not clearly the same object
24357 function Same_Type (T1, T2 : Entity_Id) return Boolean is
24362 elsif not Is_Constrained (T1)
24363 and then not Is_Constrained (T2)
24364 and then Base_Type (T1) = Base_Type (T2)
24368 -- For now don't bother with case of identical constraints, to be
24369 -- fiddled with later on perhaps (this is only used for optimization
24370 -- purposes, so it is not critical to do a best possible job)
24381 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
24383 if Compile_Time_Known_Value (Node1)
24384 and then Compile_Time_Known_Value (Node2)
24386 -- Handle properly compile-time expressions that are not
24389 if Is_String_Type (Etype (Node1)) then
24390 return Expr_Value_S (Node1) = Expr_Value_S (Node2);
24393 return Expr_Value (Node1) = Expr_Value (Node2);
24396 elsif Same_Object (Node1, Node2) then
24403 --------------------
24404 -- Set_SPARK_Mode --
24405 --------------------
24407 procedure Set_SPARK_Mode (Context : Entity_Id) is
24409 -- Do not consider illegal or partially decorated constructs
24411 if Ekind (Context) = E_Void or else Error_Posted (Context) then
24414 elsif Present (SPARK_Pragma (Context)) then
24416 (Mode => Get_SPARK_Mode_From_Annotation (SPARK_Pragma (Context)),
24417 Prag => SPARK_Pragma (Context));
24419 end Set_SPARK_Mode;
24421 -------------------------
24422 -- Scalar_Part_Present --
24423 -------------------------
24425 function Scalar_Part_Present (Typ : Entity_Id) return Boolean is
24426 Val_Typ : constant Entity_Id := Validated_View (Typ);
24430 if Is_Scalar_Type (Val_Typ) then
24433 elsif Is_Array_Type (Val_Typ) then
24434 return Scalar_Part_Present (Component_Type (Val_Typ));
24436 elsif Is_Record_Type (Val_Typ) then
24437 Field := First_Component_Or_Discriminant (Val_Typ);
24438 while Present (Field) loop
24439 if Scalar_Part_Present (Etype (Field)) then
24443 Next_Component_Or_Discriminant (Field);
24448 end Scalar_Part_Present;
24450 ------------------------
24451 -- Scope_Is_Transient --
24452 ------------------------
24454 function Scope_Is_Transient return Boolean is
24456 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
24457 end Scope_Is_Transient;
24463 function Scope_Within
24464 (Inner : Entity_Id;
24465 Outer : Entity_Id) return Boolean
24471 while Present (Curr) and then Curr /= Standard_Standard loop
24472 Curr := Scope (Curr);
24474 if Curr = Outer then
24477 -- A selective accept body appears within a task type, but the
24478 -- enclosing subprogram is the procedure of the task body.
24480 elsif Ekind (Curr) = E_Task_Type
24481 and then Outer = Task_Body_Procedure (Curr)
24485 -- Ditto for the body of a protected operation
24487 elsif Is_Subprogram (Curr)
24488 and then Outer = Protected_Body_Subprogram (Curr)
24492 -- Outside of its scope, a synchronized type may just be private
24494 elsif Is_Private_Type (Curr)
24495 and then Present (Full_View (Curr))
24496 and then Is_Concurrent_Type (Full_View (Curr))
24498 return Scope_Within (Full_View (Curr), Outer);
24505 --------------------------
24506 -- Scope_Within_Or_Same --
24507 --------------------------
24509 function Scope_Within_Or_Same
24510 (Inner : Entity_Id;
24511 Outer : Entity_Id) return Boolean
24513 Curr : Entity_Id := Inner;
24516 -- Similar to the above, but check for scope identity first
24518 while Present (Curr) and then Curr /= Standard_Standard loop
24519 if Curr = Outer then
24522 elsif Ekind (Curr) = E_Task_Type
24523 and then Outer = Task_Body_Procedure (Curr)
24527 elsif Is_Subprogram (Curr)
24528 and then Outer = Protected_Body_Subprogram (Curr)
24532 elsif Is_Private_Type (Curr)
24533 and then Present (Full_View (Curr))
24535 if Full_View (Curr) = Outer then
24538 return Scope_Within (Full_View (Curr), Outer);
24542 Curr := Scope (Curr);
24546 end Scope_Within_Or_Same;
24548 --------------------
24549 -- Set_Convention --
24550 --------------------
24552 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
24554 Basic_Set_Convention (E, Val);
24557 and then Is_Access_Subprogram_Type (Base_Type (E))
24558 and then Has_Foreign_Convention (E)
24560 Set_Can_Use_Internal_Rep (E, False);
24563 -- If E is an object, including a component, and the type of E is an
24564 -- anonymous access type with no convention set, then also set the
24565 -- convention of the anonymous access type. We do not do this for
24566 -- anonymous protected types, since protected types always have the
24567 -- default convention.
24569 if Present (Etype (E))
24570 and then (Is_Object (E)
24572 -- Allow E_Void (happens for pragma Convention appearing
24573 -- in the middle of a record applying to a component)
24575 or else Ekind (E) = E_Void)
24578 Typ : constant Entity_Id := Etype (E);
24581 if Ekind_In (Typ, E_Anonymous_Access_Type,
24582 E_Anonymous_Access_Subprogram_Type)
24583 and then not Has_Convention_Pragma (Typ)
24585 Basic_Set_Convention (Typ, Val);
24586 Set_Has_Convention_Pragma (Typ);
24588 -- And for the access subprogram type, deal similarly with the
24589 -- designated E_Subprogram_Type, which is always internal.
24591 if Ekind (Typ) = E_Anonymous_Access_Subprogram_Type then
24593 Dtype : constant Entity_Id := Designated_Type (Typ);
24595 if Ekind (Dtype) = E_Subprogram_Type
24596 and then not Has_Convention_Pragma (Dtype)
24598 Basic_Set_Convention (Dtype, Val);
24599 Set_Has_Convention_Pragma (Dtype);
24606 end Set_Convention;
24608 ------------------------
24609 -- Set_Current_Entity --
24610 ------------------------
24612 -- The given entity is to be set as the currently visible definition of its
24613 -- associated name (i.e. the Node_Id associated with its name). All we have
24614 -- to do is to get the name from the identifier, and then set the
24615 -- associated Node_Id to point to the given entity.
24617 procedure Set_Current_Entity (E : Entity_Id) is
24619 Set_Name_Entity_Id (Chars (E), E);
24620 end Set_Current_Entity;
24622 ---------------------------
24623 -- Set_Debug_Info_Needed --
24624 ---------------------------
24626 procedure Set_Debug_Info_Needed (T : Entity_Id) is
24628 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
24629 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
24630 -- Used to set debug info in a related node if not set already
24632 --------------------------------------
24633 -- Set_Debug_Info_Needed_If_Not_Set --
24634 --------------------------------------
24636 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
24638 if Present (E) and then not Needs_Debug_Info (E) then
24639 Set_Debug_Info_Needed (E);
24641 -- For a private type, indicate that the full view also needs
24642 -- debug information.
24645 and then Is_Private_Type (E)
24646 and then Present (Full_View (E))
24648 Set_Debug_Info_Needed (Full_View (E));
24651 end Set_Debug_Info_Needed_If_Not_Set;
24653 -- Start of processing for Set_Debug_Info_Needed
24656 -- Nothing to do if there is no available entity
24661 -- Nothing to do for an entity with suppressed debug information
24663 elsif Debug_Info_Off (T) then
24666 -- Nothing to do for an ignored Ghost entity because the entity will be
24667 -- eliminated from the tree.
24669 elsif Is_Ignored_Ghost_Entity (T) then
24672 -- Nothing to do if entity comes from a predefined file. Library files
24673 -- are compiled without debug information, but inlined bodies of these
24674 -- routines may appear in user code, and debug information on them ends
24675 -- up complicating debugging the user code.
24677 elsif In_Inlined_Body and then In_Predefined_Unit (T) then
24678 Set_Needs_Debug_Info (T, False);
24681 -- Set flag in entity itself. Note that we will go through the following
24682 -- circuitry even if the flag is already set on T. That's intentional,
24683 -- it makes sure that the flag will be set in subsidiary entities.
24685 Set_Needs_Debug_Info (T);
24687 -- Set flag on subsidiary entities if not set already
24689 if Is_Object (T) then
24690 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
24692 elsif Is_Type (T) then
24693 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
24695 if Is_Record_Type (T) then
24697 Ent : Entity_Id := First_Entity (T);
24699 while Present (Ent) loop
24700 Set_Debug_Info_Needed_If_Not_Set (Ent);
24705 -- For a class wide subtype, we also need debug information
24706 -- for the equivalent type.
24708 if Ekind (T) = E_Class_Wide_Subtype then
24709 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
24712 elsif Is_Array_Type (T) then
24713 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
24716 Indx : Node_Id := First_Index (T);
24718 while Present (Indx) loop
24719 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
24720 Indx := Next_Index (Indx);
24724 -- For a packed array type, we also need debug information for
24725 -- the type used to represent the packed array. Conversely, we
24726 -- also need it for the former if we need it for the latter.
24728 if Is_Packed (T) then
24729 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Impl_Type (T));
24732 if Is_Packed_Array_Impl_Type (T) then
24733 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
24736 elsif Is_Access_Type (T) then
24737 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
24739 elsif Is_Private_Type (T) then
24741 FV : constant Entity_Id := Full_View (T);
24744 Set_Debug_Info_Needed_If_Not_Set (FV);
24746 -- If the full view is itself a derived private type, we need
24747 -- debug information on its underlying type.
24750 and then Is_Private_Type (FV)
24751 and then Present (Underlying_Full_View (FV))
24753 Set_Needs_Debug_Info (Underlying_Full_View (FV));
24757 elsif Is_Protected_Type (T) then
24758 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
24760 elsif Is_Scalar_Type (T) then
24762 -- If the subrange bounds are materialized by dedicated constant
24763 -- objects, also include them in the debug info to make sure the
24764 -- debugger can properly use them.
24766 if Present (Scalar_Range (T))
24767 and then Nkind (Scalar_Range (T)) = N_Range
24770 Low_Bnd : constant Node_Id := Type_Low_Bound (T);
24771 High_Bnd : constant Node_Id := Type_High_Bound (T);
24774 if Is_Entity_Name (Low_Bnd) then
24775 Set_Debug_Info_Needed_If_Not_Set (Entity (Low_Bnd));
24778 if Is_Entity_Name (High_Bnd) then
24779 Set_Debug_Info_Needed_If_Not_Set (Entity (High_Bnd));
24785 end Set_Debug_Info_Needed;
24787 ----------------------------
24788 -- Set_Entity_With_Checks --
24789 ----------------------------
24791 procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id) is
24792 Val_Actual : Entity_Id;
24794 Post_Node : Node_Id;
24797 -- Unconditionally set the entity
24799 Set_Entity (N, Val);
24801 -- The node to post on is the selector in the case of an expanded name,
24802 -- and otherwise the node itself.
24804 if Nkind (N) = N_Expanded_Name then
24805 Post_Node := Selector_Name (N);
24810 -- Check for violation of No_Fixed_IO
24812 if Restriction_Check_Required (No_Fixed_IO)
24814 ((RTU_Loaded (Ada_Text_IO)
24815 and then (Is_RTE (Val, RE_Decimal_IO)
24817 Is_RTE (Val, RE_Fixed_IO)))
24820 (RTU_Loaded (Ada_Wide_Text_IO)
24821 and then (Is_RTE (Val, RO_WT_Decimal_IO)
24823 Is_RTE (Val, RO_WT_Fixed_IO)))
24826 (RTU_Loaded (Ada_Wide_Wide_Text_IO)
24827 and then (Is_RTE (Val, RO_WW_Decimal_IO)
24829 Is_RTE (Val, RO_WW_Fixed_IO))))
24831 -- A special extra check, don't complain about a reference from within
24832 -- the Ada.Interrupts package itself!
24834 and then not In_Same_Extended_Unit (N, Val)
24836 Check_Restriction (No_Fixed_IO, Post_Node);
24839 -- Remaining checks are only done on source nodes. Note that we test
24840 -- for violation of No_Fixed_IO even on non-source nodes, because the
24841 -- cases for checking violations of this restriction are instantiations
24842 -- where the reference in the instance has Comes_From_Source False.
24844 if not Comes_From_Source (N) then
24848 -- Check for violation of No_Abort_Statements, which is triggered by
24849 -- call to Ada.Task_Identification.Abort_Task.
24851 if Restriction_Check_Required (No_Abort_Statements)
24852 and then (Is_RTE (Val, RE_Abort_Task))
24854 -- A special extra check, don't complain about a reference from within
24855 -- the Ada.Task_Identification package itself!
24857 and then not In_Same_Extended_Unit (N, Val)
24859 Check_Restriction (No_Abort_Statements, Post_Node);
24862 if Val = Standard_Long_Long_Integer then
24863 Check_Restriction (No_Long_Long_Integers, Post_Node);
24866 -- Check for violation of No_Dynamic_Attachment
24868 if Restriction_Check_Required (No_Dynamic_Attachment)
24869 and then RTU_Loaded (Ada_Interrupts)
24870 and then (Is_RTE (Val, RE_Is_Reserved) or else
24871 Is_RTE (Val, RE_Is_Attached) or else
24872 Is_RTE (Val, RE_Current_Handler) or else
24873 Is_RTE (Val, RE_Attach_Handler) or else
24874 Is_RTE (Val, RE_Exchange_Handler) or else
24875 Is_RTE (Val, RE_Detach_Handler) or else
24876 Is_RTE (Val, RE_Reference))
24878 -- A special extra check, don't complain about a reference from within
24879 -- the Ada.Interrupts package itself!
24881 and then not In_Same_Extended_Unit (N, Val)
24883 Check_Restriction (No_Dynamic_Attachment, Post_Node);
24886 -- Check for No_Implementation_Identifiers
24888 if Restriction_Check_Required (No_Implementation_Identifiers) then
24890 -- We have an implementation defined entity if it is marked as
24891 -- implementation defined, or is defined in a package marked as
24892 -- implementation defined. However, library packages themselves
24893 -- are excluded (we don't want to flag Interfaces itself, just
24894 -- the entities within it).
24896 if (Is_Implementation_Defined (Val)
24898 (Present (Scope (Val))
24899 and then Is_Implementation_Defined (Scope (Val))))
24900 and then not (Ekind_In (Val, E_Package, E_Generic_Package)
24901 and then Is_Library_Level_Entity (Val))
24903 Check_Restriction (No_Implementation_Identifiers, Post_Node);
24907 -- Do the style check
24910 and then not Suppress_Style_Checks (Val)
24911 and then not In_Instance
24913 if Nkind (N) = N_Identifier then
24915 elsif Nkind (N) = N_Expanded_Name then
24916 Nod := Selector_Name (N);
24921 -- A special situation arises for derived operations, where we want
24922 -- to do the check against the parent (since the Sloc of the derived
24923 -- operation points to the derived type declaration itself).
24926 while not Comes_From_Source (Val_Actual)
24927 and then Nkind (Val_Actual) in N_Entity
24928 and then (Ekind (Val_Actual) = E_Enumeration_Literal
24929 or else Is_Subprogram_Or_Generic_Subprogram (Val_Actual))
24930 and then Present (Alias (Val_Actual))
24932 Val_Actual := Alias (Val_Actual);
24935 -- Renaming declarations for generic actuals do not come from source,
24936 -- and have a different name from that of the entity they rename, so
24937 -- there is no style check to perform here.
24939 if Chars (Nod) = Chars (Val_Actual) then
24940 Style.Check_Identifier (Nod, Val_Actual);
24944 Set_Entity (N, Val);
24945 end Set_Entity_With_Checks;
24947 ------------------------------
24948 -- Set_Invalid_Scalar_Value --
24949 ------------------------------
24951 procedure Set_Invalid_Scalar_Value
24952 (Scal_Typ : Float_Scalar_Id;
24955 Slot : Ureal renames Invalid_Floats (Scal_Typ);
24958 -- Detect an attempt to set a different value for the same scalar type
24960 pragma Assert (Slot = No_Ureal);
24962 end Set_Invalid_Scalar_Value;
24964 ------------------------------
24965 -- Set_Invalid_Scalar_Value --
24966 ------------------------------
24968 procedure Set_Invalid_Scalar_Value
24969 (Scal_Typ : Integer_Scalar_Id;
24972 Slot : Uint renames Invalid_Integers (Scal_Typ);
24975 -- Detect an attempt to set a different value for the same scalar type
24977 pragma Assert (Slot = No_Uint);
24979 end Set_Invalid_Scalar_Value;
24981 ------------------------
24982 -- Set_Name_Entity_Id --
24983 ------------------------
24985 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
24987 Set_Name_Table_Int (Id, Int (Val));
24988 end Set_Name_Entity_Id;
24990 ---------------------
24991 -- Set_Next_Actual --
24992 ---------------------
24994 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
24996 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
24997 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
24999 end Set_Next_Actual;
25001 ----------------------------------
25002 -- Set_Optimize_Alignment_Flags --
25003 ----------------------------------
25005 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
25007 if Optimize_Alignment = 'S' then
25008 Set_Optimize_Alignment_Space (E);
25009 elsif Optimize_Alignment = 'T' then
25010 Set_Optimize_Alignment_Time (E);
25012 end Set_Optimize_Alignment_Flags;
25014 -----------------------
25015 -- Set_Public_Status --
25016 -----------------------
25018 procedure Set_Public_Status (Id : Entity_Id) is
25019 S : constant Entity_Id := Current_Scope;
25021 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
25022 -- Determines if E is defined within handled statement sequence or
25023 -- an if statement, returns True if so, False otherwise.
25025 ----------------------
25026 -- Within_HSS_Or_If --
25027 ----------------------
25029 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
25032 N := Declaration_Node (E);
25039 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
25045 end Within_HSS_Or_If;
25047 -- Start of processing for Set_Public_Status
25050 -- Everything in the scope of Standard is public
25052 if S = Standard_Standard then
25053 Set_Is_Public (Id);
25055 -- Entity is definitely not public if enclosing scope is not public
25057 elsif not Is_Public (S) then
25060 -- An object or function declaration that occurs in a handled sequence
25061 -- of statements or within an if statement is the declaration for a
25062 -- temporary object or local subprogram generated by the expander. It
25063 -- never needs to be made public and furthermore, making it public can
25064 -- cause back end problems.
25066 elsif Nkind_In (Parent (Id), N_Object_Declaration,
25067 N_Function_Specification)
25068 and then Within_HSS_Or_If (Id)
25072 -- Entities in public packages or records are public
25074 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
25075 Set_Is_Public (Id);
25077 -- The bounds of an entry family declaration can generate object
25078 -- declarations that are visible to the back-end, e.g. in the
25079 -- the declaration of a composite type that contains tasks.
25081 elsif Is_Concurrent_Type (S)
25082 and then not Has_Completion (S)
25083 and then Nkind (Parent (Id)) = N_Object_Declaration
25085 Set_Is_Public (Id);
25087 end Set_Public_Status;
25089 -----------------------------
25090 -- Set_Referenced_Modified --
25091 -----------------------------
25093 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
25097 -- Deal with indexed or selected component where prefix is modified
25099 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
25100 Pref := Prefix (N);
25102 -- If prefix is access type, then it is the designated object that is
25103 -- being modified, which means we have no entity to set the flag on.
25105 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
25108 -- Otherwise chase the prefix
25111 Set_Referenced_Modified (Pref, Out_Param);
25114 -- Otherwise see if we have an entity name (only other case to process)
25116 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
25117 Set_Referenced_As_LHS (Entity (N), not Out_Param);
25118 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
25120 end Set_Referenced_Modified;
25126 procedure Set_Rep_Info (T1 : Entity_Id; T2 : Entity_Id) is
25128 Set_Is_Atomic (T1, Is_Atomic (T2));
25129 Set_Is_Independent (T1, Is_Independent (T2));
25130 Set_Is_Volatile_Full_Access (T1, Is_Volatile_Full_Access (T2));
25132 if Is_Base_Type (T1) then
25133 Set_Is_Volatile (T1, Is_Volatile (T2));
25137 ----------------------------
25138 -- Set_Scope_Is_Transient --
25139 ----------------------------
25141 procedure Set_Scope_Is_Transient (V : Boolean := True) is
25143 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
25144 end Set_Scope_Is_Transient;
25146 -------------------
25147 -- Set_Size_Info --
25148 -------------------
25150 procedure Set_Size_Info (T1, T2 : Entity_Id) is
25152 -- We copy Esize, but not RM_Size, since in general RM_Size is
25153 -- subtype specific and does not get inherited by all subtypes.
25155 Set_Esize (T1, Esize (T2));
25156 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
25158 if Is_Discrete_Or_Fixed_Point_Type (T1)
25160 Is_Discrete_Or_Fixed_Point_Type (T2)
25162 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
25165 Set_Alignment (T1, Alignment (T2));
25168 ------------------------------
25169 -- Should_Ignore_Pragma_Par --
25170 ------------------------------
25172 function Should_Ignore_Pragma_Par (Prag_Name : Name_Id) return Boolean is
25173 pragma Assert (Compiler_State = Parsing);
25174 -- This one can't work during semantic analysis, because we don't have a
25175 -- correct Current_Source_File.
25177 Result : constant Boolean :=
25178 Get_Name_Table_Boolean3 (Prag_Name)
25179 and then not Is_Internal_File_Name
25180 (File_Name (Current_Source_File));
25183 end Should_Ignore_Pragma_Par;
25185 ------------------------------
25186 -- Should_Ignore_Pragma_Sem --
25187 ------------------------------
25189 function Should_Ignore_Pragma_Sem (N : Node_Id) return Boolean is
25190 pragma Assert (Compiler_State = Analyzing);
25191 Prag_Name : constant Name_Id := Pragma_Name (N);
25192 Result : constant Boolean :=
25193 Get_Name_Table_Boolean3 (Prag_Name)
25194 and then not In_Internal_Unit (N);
25198 end Should_Ignore_Pragma_Sem;
25200 --------------------
25201 -- Static_Boolean --
25202 --------------------
25204 function Static_Boolean (N : Node_Id) return Uint is
25206 Analyze_And_Resolve (N, Standard_Boolean);
25209 or else Error_Posted (N)
25210 or else Etype (N) = Any_Type
25215 if Is_OK_Static_Expression (N) then
25216 if not Raises_Constraint_Error (N) then
25217 return Expr_Value (N);
25222 elsif Etype (N) = Any_Type then
25226 Flag_Non_Static_Expr
25227 ("static boolean expression required here", N);
25230 end Static_Boolean;
25232 --------------------
25233 -- Static_Integer --
25234 --------------------
25236 function Static_Integer (N : Node_Id) return Uint is
25238 Analyze_And_Resolve (N, Any_Integer);
25241 or else Error_Posted (N)
25242 or else Etype (N) = Any_Type
25247 if Is_OK_Static_Expression (N) then
25248 if not Raises_Constraint_Error (N) then
25249 return Expr_Value (N);
25254 elsif Etype (N) = Any_Type then
25258 Flag_Non_Static_Expr
25259 ("static integer expression required here", N);
25262 end Static_Integer;
25264 --------------------------
25265 -- Statically_Different --
25266 --------------------------
25268 function Statically_Different (E1, E2 : Node_Id) return Boolean is
25269 R1 : constant Node_Id := Get_Referenced_Object (E1);
25270 R2 : constant Node_Id := Get_Referenced_Object (E2);
25272 return Is_Entity_Name (R1)
25273 and then Is_Entity_Name (R2)
25274 and then Entity (R1) /= Entity (R2)
25275 and then not Is_Formal (Entity (R1))
25276 and then not Is_Formal (Entity (R2));
25277 end Statically_Different;
25279 --------------------------------------
25280 -- Subject_To_Loop_Entry_Attributes --
25281 --------------------------------------
25283 function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
25289 -- The expansion mechanism transform a loop subject to at least one
25290 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
25291 -- the conditional part.
25293 if Nkind_In (Stmt, N_Block_Statement, N_If_Statement)
25294 and then Nkind (Original_Node (N)) = N_Loop_Statement
25296 Stmt := Original_Node (N);
25300 Nkind (Stmt) = N_Loop_Statement
25301 and then Present (Identifier (Stmt))
25302 and then Present (Entity (Identifier (Stmt)))
25303 and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
25304 end Subject_To_Loop_Entry_Attributes;
25306 -----------------------------
25307 -- Subprogram_Access_Level --
25308 -----------------------------
25310 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
25312 if Present (Alias (Subp)) then
25313 return Subprogram_Access_Level (Alias (Subp));
25315 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
25317 end Subprogram_Access_Level;
25319 ---------------------
25320 -- Subprogram_Name --
25321 ---------------------
25323 function Subprogram_Name (N : Node_Id) return String is
25324 Buf : Bounded_String;
25325 Ent : Node_Id := N;
25329 while Present (Ent) loop
25330 case Nkind (Ent) is
25331 when N_Subprogram_Body =>
25332 Ent := Defining_Unit_Name (Specification (Ent));
25335 when N_Subprogram_Declaration =>
25336 Nod := Corresponding_Body (Ent);
25338 if Present (Nod) then
25341 Ent := Defining_Unit_Name (Specification (Ent));
25346 when N_Subprogram_Instantiation
25348 | N_Package_Specification
25350 Ent := Defining_Unit_Name (Ent);
25353 when N_Protected_Type_Declaration =>
25354 Ent := Corresponding_Body (Ent);
25357 when N_Protected_Body
25360 Ent := Defining_Identifier (Ent);
25367 Ent := Parent (Ent);
25371 return "unknown subprogram:unknown file:0:0";
25374 -- If the subprogram is a child unit, use its simple name to start the
25375 -- construction of the fully qualified name.
25377 if Nkind (Ent) = N_Defining_Program_Unit_Name then
25378 Ent := Defining_Identifier (Ent);
25381 Append_Entity_Name (Buf, Ent);
25383 -- Append homonym number if needed
25385 if Nkind (N) in N_Entity and then Has_Homonym (N) then
25387 H : Entity_Id := Homonym (N);
25391 while Present (H) loop
25392 if Scope (H) = Scope (N) then
25406 -- Append source location of Ent to Buf so that the string will
25407 -- look like "subp:file:line:col".
25410 Loc : constant Source_Ptr := Sloc (Ent);
25413 Append (Buf, Reference_Name (Get_Source_File_Index (Loc)));
25415 Append (Buf, Nat (Get_Logical_Line_Number (Loc)));
25417 Append (Buf, Nat (Get_Column_Number (Loc)));
25421 end Subprogram_Name;
25423 -------------------------------
25424 -- Support_Atomic_Primitives --
25425 -------------------------------
25427 function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
25431 -- Verify the alignment of Typ is known
25433 if not Known_Alignment (Typ) then
25437 if Known_Static_Esize (Typ) then
25438 Size := UI_To_Int (Esize (Typ));
25440 -- If the Esize (Object_Size) is unknown at compile time, look at the
25441 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
25443 elsif Known_Static_RM_Size (Typ) then
25444 Size := UI_To_Int (RM_Size (Typ));
25446 -- Otherwise, the size is considered to be unknown.
25452 -- Check that the size of the component is 8, 16, 32, or 64 bits and
25453 -- that Typ is properly aligned.
25456 when 8 | 16 | 32 | 64 =>
25457 return Size = UI_To_Int (Alignment (Typ)) * 8;
25462 end Support_Atomic_Primitives;
25468 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
25470 if Debug_Flag_W then
25471 for J in 0 .. Scope_Stack.Last loop
25476 Write_Name (Chars (E));
25477 Write_Str (" from ");
25478 Write_Location (Sloc (N));
25483 -----------------------
25484 -- Transfer_Entities --
25485 -----------------------
25487 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
25488 procedure Set_Public_Status_Of (Id : Entity_Id);
25489 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
25490 -- Set_Public_Status. If successful and Id denotes a record type, set
25491 -- the Is_Public attribute of its fields.
25493 --------------------------
25494 -- Set_Public_Status_Of --
25495 --------------------------
25497 procedure Set_Public_Status_Of (Id : Entity_Id) is
25501 if not Is_Public (Id) then
25502 Set_Public_Status (Id);
25504 -- When the input entity is a public record type, ensure that all
25505 -- its internal fields are also exposed to the linker. The fields
25506 -- of a class-wide type are never made public.
25509 and then Is_Record_Type (Id)
25510 and then not Is_Class_Wide_Type (Id)
25512 Field := First_Entity (Id);
25513 while Present (Field) loop
25514 Set_Is_Public (Field);
25515 Next_Entity (Field);
25519 end Set_Public_Status_Of;
25523 Full_Id : Entity_Id;
25526 -- Start of processing for Transfer_Entities
25529 Id := First_Entity (From);
25531 if Present (Id) then
25533 -- Merge the entity chain of the source scope with that of the
25534 -- destination scope.
25536 if Present (Last_Entity (To)) then
25537 Link_Entities (Last_Entity (To), Id);
25539 Set_First_Entity (To, Id);
25542 Set_Last_Entity (To, Last_Entity (From));
25544 -- Inspect the entities of the source scope and update their Scope
25547 while Present (Id) loop
25548 Set_Scope (Id, To);
25549 Set_Public_Status_Of (Id);
25551 -- Handle an internally generated full view for a private type
25553 if Is_Private_Type (Id)
25554 and then Present (Full_View (Id))
25555 and then Is_Itype (Full_View (Id))
25557 Full_Id := Full_View (Id);
25559 Set_Scope (Full_Id, To);
25560 Set_Public_Status_Of (Full_Id);
25566 Set_First_Entity (From, Empty);
25567 Set_Last_Entity (From, Empty);
25569 end Transfer_Entities;
25571 ------------------------
25572 -- Traverse_More_Func --
25573 ------------------------
25575 function Traverse_More_Func (Node : Node_Id) return Traverse_Final_Result is
25577 Processing_Itype : Boolean := False;
25578 -- Set to True while traversing the nodes under an Itype, to prevent
25579 -- looping on Itype handling during that traversal.
25581 function Process_More (N : Node_Id) return Traverse_Result;
25582 -- Wrapper over the Process callback to handle parts of the AST that
25583 -- are not normally traversed as syntactic children.
25585 function Traverse_Rec (N : Node_Id) return Traverse_Final_Result;
25586 -- Main recursive traversal implemented as an instantiation of
25587 -- Traverse_Func over a modified Process callback.
25593 function Process_More (N : Node_Id) return Traverse_Result is
25595 procedure Traverse_More (N : Node_Id;
25596 Res : in out Traverse_Result);
25597 procedure Traverse_More (L : List_Id;
25598 Res : in out Traverse_Result);
25599 -- Traverse a node or list and update the traversal result to value
25600 -- Abandon when needed.
25602 -------------------
25603 -- Traverse_More --
25604 -------------------
25606 procedure Traverse_More (N : Node_Id;
25607 Res : in out Traverse_Result)
25610 -- Do not process any more nodes if Abandon was reached
25612 if Res = Abandon then
25616 if Traverse_Rec (N) = Abandon then
25621 procedure Traverse_More (L : List_Id;
25622 Res : in out Traverse_Result)
25624 N : Node_Id := First (L);
25627 -- Do not process any more nodes if Abandon was reached
25629 if Res = Abandon then
25633 while Present (N) loop
25634 Traverse_More (N, Res);
25642 Result : Traverse_Result;
25644 -- Start of processing for Process_More
25647 -- Initial callback to Process. Return immediately on Skip/Abandon.
25648 -- Otherwise update the value of Node for further processing of
25649 -- non-syntactic children.
25651 Result := Process (N);
25654 when OK => Node := N;
25655 when OK_Orig => Node := Original_Node (N);
25656 when Skip => return Skip;
25657 when Abandon => return Abandon;
25660 -- Process the relevant semantic children which are a logical part of
25661 -- the AST under this node before returning for the processing of
25662 -- syntactic children.
25664 -- Start with all non-syntactic lists of action nodes
25666 case Nkind (Node) is
25667 when N_Component_Association =>
25668 Traverse_More (Loop_Actions (Node), Result);
25670 when N_Elsif_Part =>
25671 Traverse_More (Condition_Actions (Node), Result);
25673 when N_Short_Circuit =>
25674 Traverse_More (Actions (Node), Result);
25676 when N_Case_Expression_Alternative =>
25677 Traverse_More (Actions (Node), Result);
25679 when N_Iterated_Component_Association =>
25680 Traverse_More (Loop_Actions (Node), Result);
25682 when N_Iteration_Scheme =>
25683 Traverse_More (Condition_Actions (Node), Result);
25685 when N_If_Expression =>
25686 Traverse_More (Then_Actions (Node), Result);
25687 Traverse_More (Else_Actions (Node), Result);
25689 -- Various nodes have a field Actions as a syntactic node,
25690 -- so it will be traversed in the regular syntactic traversal.
25692 when N_Compilation_Unit_Aux
25693 | N_Compound_Statement
25694 | N_Expression_With_Actions
25703 -- If Process_Itypes is True, process unattached nodes which come
25704 -- from Itypes. This only concerns currently ranges of scalar
25705 -- (possibly as index) types. This traversal is protected against
25706 -- looping with Processing_Itype.
25709 and then not Processing_Itype
25710 and then Nkind (Node) in N_Has_Etype
25711 and then Present (Etype (Node))
25712 and then Is_Itype (Etype (Node))
25715 Typ : constant Entity_Id := Etype (Node);
25717 Processing_Itype := True;
25719 case Ekind (Typ) is
25720 when Scalar_Kind =>
25721 Traverse_More (Scalar_Range (Typ), Result);
25725 Index : Node_Id := First_Index (Typ);
25728 while Present (Index) loop
25729 if Nkind (Index) in N_Has_Entity then
25730 Rng := Scalar_Range (Entity (Index));
25735 Traverse_More (Rng, Result);
25736 Next_Index (Index);
25743 Processing_Itype := False;
25750 -- Define Traverse_Rec as a renaming of the instantiation, as an
25751 -- instantiation cannot complete a previous spec.
25753 function Traverse_Recursive is new Traverse_Func (Process_More);
25754 function Traverse_Rec (N : Node_Id) return Traverse_Final_Result
25755 renames Traverse_Recursive;
25757 -- Start of processing for Traverse_More_Func
25760 return Traverse_Rec (Node);
25761 end Traverse_More_Func;
25763 ------------------------
25764 -- Traverse_More_Proc --
25765 ------------------------
25767 procedure Traverse_More_Proc (Node : Node_Id) is
25768 function Traverse is new Traverse_More_Func (Process, Process_Itypes);
25769 Discard : Traverse_Final_Result;
25770 pragma Warnings (Off, Discard);
25772 Discard := Traverse (Node);
25773 end Traverse_More_Proc;
25775 -----------------------
25776 -- Type_Access_Level --
25777 -----------------------
25779 function Type_Access_Level (Typ : Entity_Id) return Uint is
25783 Btyp := Base_Type (Typ);
25785 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
25786 -- simply use the level where the type is declared. This is true for
25787 -- stand-alone object declarations, and for anonymous access types
25788 -- associated with components the level is the same as that of the
25789 -- enclosing composite type. However, special treatment is needed for
25790 -- the cases of access parameters, return objects of an anonymous access
25791 -- type, and, in Ada 95, access discriminants of limited types.
25793 if Is_Access_Type (Btyp) then
25794 if Ekind (Btyp) = E_Anonymous_Access_Type then
25796 -- If the type is a nonlocal anonymous access type (such as for
25797 -- an access parameter) we treat it as being declared at the
25798 -- library level to ensure that names such as X.all'access don't
25799 -- fail static accessibility checks.
25801 if not Is_Local_Anonymous_Access (Typ) then
25802 return Scope_Depth (Standard_Standard);
25804 -- If this is a return object, the accessibility level is that of
25805 -- the result subtype of the enclosing function. The test here is
25806 -- little complicated, because we have to account for extended
25807 -- return statements that have been rewritten as blocks, in which
25808 -- case we have to find and the Is_Return_Object attribute of the
25809 -- itype's associated object. It would be nice to find a way to
25810 -- simplify this test, but it doesn't seem worthwhile to add a new
25811 -- flag just for purposes of this test. ???
25813 elsif Ekind (Scope (Btyp)) = E_Return_Statement
25816 and then Nkind (Associated_Node_For_Itype (Btyp)) =
25817 N_Object_Declaration
25818 and then Is_Return_Object
25819 (Defining_Identifier
25820 (Associated_Node_For_Itype (Btyp))))
25826 Scop := Scope (Scope (Btyp));
25827 while Present (Scop) loop
25828 exit when Ekind (Scop) = E_Function;
25829 Scop := Scope (Scop);
25832 -- Treat the return object's type as having the level of the
25833 -- function's result subtype (as per RM05-6.5(5.3/2)).
25835 return Type_Access_Level (Etype (Scop));
25840 Btyp := Root_Type (Btyp);
25842 -- The accessibility level of anonymous access types associated with
25843 -- discriminants is that of the current instance of the type, and
25844 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
25846 -- AI-402: access discriminants have accessibility based on the
25847 -- object rather than the type in Ada 2005, so the above paragraph
25850 -- ??? Needs completion with rules from AI-416
25852 if Ada_Version <= Ada_95
25853 and then Ekind (Typ) = E_Anonymous_Access_Type
25854 and then Present (Associated_Node_For_Itype (Typ))
25855 and then Nkind (Associated_Node_For_Itype (Typ)) =
25856 N_Discriminant_Specification
25858 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
25862 -- Return library level for a generic formal type. This is done because
25863 -- RM(10.3.2) says that "The statically deeper relationship does not
25864 -- apply to ... a descendant of a generic formal type". Rather than
25865 -- checking at each point where a static accessibility check is
25866 -- performed to see if we are dealing with a formal type, this rule is
25867 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
25868 -- return extreme values for a formal type; Deepest_Type_Access_Level
25869 -- returns Int'Last. By calling the appropriate function from among the
25870 -- two, we ensure that the static accessibility check will pass if we
25871 -- happen to run into a formal type. More specifically, we should call
25872 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
25873 -- call occurs as part of a static accessibility check and the error
25874 -- case is the case where the type's level is too shallow (as opposed
25877 if Is_Generic_Type (Root_Type (Btyp)) then
25878 return Scope_Depth (Standard_Standard);
25881 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
25882 end Type_Access_Level;
25884 ------------------------------------
25885 -- Type_Without_Stream_Operation --
25886 ------------------------------------
25888 function Type_Without_Stream_Operation
25890 Op : TSS_Name_Type := TSS_Null) return Entity_Id
25892 BT : constant Entity_Id := Base_Type (T);
25893 Op_Missing : Boolean;
25896 if not Restriction_Active (No_Default_Stream_Attributes) then
25900 if Is_Elementary_Type (T) then
25901 if Op = TSS_Null then
25903 No (TSS (BT, TSS_Stream_Read))
25904 or else No (TSS (BT, TSS_Stream_Write));
25907 Op_Missing := No (TSS (BT, Op));
25916 elsif Is_Array_Type (T) then
25917 return Type_Without_Stream_Operation (Component_Type (T), Op);
25919 elsif Is_Record_Type (T) then
25925 Comp := First_Component (T);
25926 while Present (Comp) loop
25927 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
25929 if Present (C_Typ) then
25933 Next_Component (Comp);
25939 elsif Is_Private_Type (T) and then Present (Full_View (T)) then
25940 return Type_Without_Stream_Operation (Full_View (T), Op);
25944 end Type_Without_Stream_Operation;
25946 ---------------------
25947 -- Ultimate_Prefix --
25948 ---------------------
25950 function Ultimate_Prefix (N : Node_Id) return Node_Id is
25955 while Nkind_In (Pref, N_Explicit_Dereference,
25956 N_Indexed_Component,
25957 N_Selected_Component,
25960 Pref := Prefix (Pref);
25964 end Ultimate_Prefix;
25966 ----------------------------
25967 -- Unique_Defining_Entity --
25968 ----------------------------
25970 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
25972 return Unique_Entity (Defining_Entity (N));
25973 end Unique_Defining_Entity;
25975 -------------------
25976 -- Unique_Entity --
25977 -------------------
25979 function Unique_Entity (E : Entity_Id) return Entity_Id is
25980 U : Entity_Id := E;
25986 if Present (Full_View (E)) then
25987 U := Full_View (E);
25991 if Nkind (Parent (E)) = N_Entry_Body then
25993 Prot_Item : Entity_Id;
25994 Prot_Type : Entity_Id;
25997 if Ekind (E) = E_Entry then
25998 Prot_Type := Scope (E);
26000 -- Bodies of entry families are nested within an extra scope
26001 -- that contains an entry index declaration.
26004 Prot_Type := Scope (Scope (E));
26007 -- A protected type may be declared as a private type, in
26008 -- which case we need to get its full view.
26010 if Is_Private_Type (Prot_Type) then
26011 Prot_Type := Full_View (Prot_Type);
26014 -- Full view may not be present on error, in which case
26015 -- return E by default.
26017 if Present (Prot_Type) then
26018 pragma Assert (Ekind (Prot_Type) = E_Protected_Type);
26020 -- Traverse the entity list of the protected type and
26021 -- locate an entry declaration which matches the entry
26024 Prot_Item := First_Entity (Prot_Type);
26025 while Present (Prot_Item) loop
26026 if Ekind (Prot_Item) in Entry_Kind
26027 and then Corresponding_Body (Parent (Prot_Item)) = E
26033 Next_Entity (Prot_Item);
26039 when Formal_Kind =>
26040 if Present (Spec_Entity (E)) then
26041 U := Spec_Entity (E);
26044 when E_Package_Body =>
26047 if Nkind (P) = N_Defining_Program_Unit_Name then
26051 if Nkind (P) = N_Package_Body
26052 and then Present (Corresponding_Spec (P))
26054 U := Corresponding_Spec (P);
26056 elsif Nkind (P) = N_Package_Body_Stub
26057 and then Present (Corresponding_Spec_Of_Stub (P))
26059 U := Corresponding_Spec_Of_Stub (P);
26062 when E_Protected_Body =>
26065 if Nkind (P) = N_Protected_Body
26066 and then Present (Corresponding_Spec (P))
26068 U := Corresponding_Spec (P);
26070 elsif Nkind (P) = N_Protected_Body_Stub
26071 and then Present (Corresponding_Spec_Of_Stub (P))
26073 U := Corresponding_Spec_Of_Stub (P);
26075 if Is_Single_Protected_Object (U) then
26080 if Is_Private_Type (U) then
26081 U := Full_View (U);
26084 when E_Subprogram_Body =>
26087 if Nkind (P) = N_Defining_Program_Unit_Name then
26093 if Nkind (P) = N_Subprogram_Body
26094 and then Present (Corresponding_Spec (P))
26096 U := Corresponding_Spec (P);
26098 elsif Nkind (P) = N_Subprogram_Body_Stub
26099 and then Present (Corresponding_Spec_Of_Stub (P))
26101 U := Corresponding_Spec_Of_Stub (P);
26103 elsif Nkind (P) = N_Subprogram_Renaming_Declaration then
26104 U := Corresponding_Spec (P);
26107 when E_Task_Body =>
26110 if Nkind (P) = N_Task_Body
26111 and then Present (Corresponding_Spec (P))
26113 U := Corresponding_Spec (P);
26115 elsif Nkind (P) = N_Task_Body_Stub
26116 and then Present (Corresponding_Spec_Of_Stub (P))
26118 U := Corresponding_Spec_Of_Stub (P);
26120 if Is_Single_Task_Object (U) then
26125 if Is_Private_Type (U) then
26126 U := Full_View (U);
26130 if Present (Full_View (E)) then
26131 U := Full_View (E);
26145 function Unique_Name (E : Entity_Id) return String is
26147 -- Names in E_Subprogram_Body or E_Package_Body entities are not
26148 -- reliable, as they may not include the overloading suffix. Instead,
26149 -- when looking for the name of E or one of its enclosing scope, we get
26150 -- the name of the corresponding Unique_Entity.
26152 U : constant Entity_Id := Unique_Entity (E);
26154 function This_Name return String;
26160 function This_Name return String is
26162 return Get_Name_String (Chars (U));
26165 -- Start of processing for Unique_Name
26168 if E = Standard_Standard
26169 or else Has_Fully_Qualified_Name (E)
26173 elsif Ekind (E) = E_Enumeration_Literal then
26174 return Unique_Name (Etype (E)) & "__" & This_Name;
26178 S : constant Entity_Id := Scope (U);
26179 pragma Assert (Present (S));
26182 -- Prefix names of predefined types with standard__, but leave
26183 -- names of user-defined packages and subprograms without prefix
26184 -- (even if technically they are nested in the Standard package).
26186 if S = Standard_Standard then
26187 if Ekind (U) = E_Package or else Is_Subprogram (U) then
26190 return Unique_Name (S) & "__" & This_Name;
26193 -- For intances of generic subprograms use the name of the related
26194 -- instace and skip the scope of its wrapper package.
26196 elsif Is_Wrapper_Package (S) then
26197 pragma Assert (Scope (S) = Scope (Related_Instance (S)));
26198 -- Wrapper package and the instantiation are in the same scope
26201 Enclosing_Name : constant String :=
26202 Unique_Name (Scope (S)) & "__" &
26203 Get_Name_String (Chars (Related_Instance (S)));
26206 if Is_Subprogram (U)
26207 and then not Is_Generic_Actual_Subprogram (U)
26209 return Enclosing_Name;
26211 return Enclosing_Name & "__" & This_Name;
26215 elsif Is_Child_Unit (U) then
26216 return Child_Prefix & Unique_Name (S) & "__" & This_Name;
26218 return Unique_Name (S) & "__" & This_Name;
26224 ---------------------
26225 -- Unit_Is_Visible --
26226 ---------------------
26228 function Unit_Is_Visible (U : Entity_Id) return Boolean is
26229 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
26230 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
26232 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
26233 -- For a child unit, check whether unit appears in a with_clause
26236 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
26237 -- Scan the context clause of one compilation unit looking for a
26238 -- with_clause for the unit in question.
26240 ----------------------------
26241 -- Unit_In_Parent_Context --
26242 ----------------------------
26244 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
26246 if Unit_In_Context (Par_Unit) then
26249 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
26250 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
26255 end Unit_In_Parent_Context;
26257 ---------------------
26258 -- Unit_In_Context --
26259 ---------------------
26261 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
26265 Clause := First (Context_Items (Comp_Unit));
26266 while Present (Clause) loop
26267 if Nkind (Clause) = N_With_Clause then
26268 if Library_Unit (Clause) = U then
26271 -- The with_clause may denote a renaming of the unit we are
26272 -- looking for, eg. Text_IO which renames Ada.Text_IO.
26275 Renamed_Entity (Entity (Name (Clause))) =
26276 Defining_Entity (Unit (U))
26286 end Unit_In_Context;
26288 -- Start of processing for Unit_Is_Visible
26291 -- The currrent unit is directly visible
26296 elsif Unit_In_Context (Curr) then
26299 -- If the current unit is a body, check the context of the spec
26301 elsif Nkind (Unit (Curr)) = N_Package_Body
26303 (Nkind (Unit (Curr)) = N_Subprogram_Body
26304 and then not Acts_As_Spec (Unit (Curr)))
26306 if Unit_In_Context (Library_Unit (Curr)) then
26311 -- If the spec is a child unit, examine the parents
26313 if Is_Child_Unit (Curr_Entity) then
26314 if Nkind (Unit (Curr)) in N_Unit_Body then
26316 Unit_In_Parent_Context
26317 (Parent_Spec (Unit (Library_Unit (Curr))));
26319 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
26325 end Unit_Is_Visible;
26327 ------------------------------
26328 -- Universal_Interpretation --
26329 ------------------------------
26331 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
26332 Index : Interp_Index;
26336 -- The argument may be a formal parameter of an operator or subprogram
26337 -- with multiple interpretations, or else an expression for an actual.
26339 if Nkind (Opnd) = N_Defining_Identifier
26340 or else not Is_Overloaded (Opnd)
26342 if Etype (Opnd) = Universal_Integer
26343 or else Etype (Opnd) = Universal_Real
26345 return Etype (Opnd);
26351 Get_First_Interp (Opnd, Index, It);
26352 while Present (It.Typ) loop
26353 if It.Typ = Universal_Integer
26354 or else It.Typ = Universal_Real
26359 Get_Next_Interp (Index, It);
26364 end Universal_Interpretation;
26370 function Unqualify (Expr : Node_Id) return Node_Id is
26372 -- Recurse to handle unlikely case of multiple levels of qualification
26374 if Nkind (Expr) = N_Qualified_Expression then
26375 return Unqualify (Expression (Expr));
26377 -- Normal case, not a qualified expression
26388 function Unqual_Conv (Expr : Node_Id) return Node_Id is
26390 -- Recurse to handle unlikely case of multiple levels of qualification
26391 -- and/or conversion.
26393 if Nkind_In (Expr, N_Qualified_Expression,
26395 N_Unchecked_Type_Conversion)
26397 return Unqual_Conv (Expression (Expr));
26399 -- Normal case, not a qualified expression
26406 --------------------
26407 -- Validated_View --
26408 --------------------
26410 function Validated_View (Typ : Entity_Id) return Entity_Id is
26411 Continue : Boolean;
26412 Val_Typ : Entity_Id;
26416 Val_Typ := Base_Type (Typ);
26418 -- Obtain the full view of the input type by stripping away concurrency,
26419 -- derivations, and privacy.
26421 while Continue loop
26424 if Is_Concurrent_Type (Val_Typ) then
26425 if Present (Corresponding_Record_Type (Val_Typ)) then
26427 Val_Typ := Corresponding_Record_Type (Val_Typ);
26430 elsif Is_Derived_Type (Val_Typ) then
26432 Val_Typ := Etype (Val_Typ);
26434 elsif Is_Private_Type (Val_Typ) then
26435 if Present (Underlying_Full_View (Val_Typ)) then
26437 Val_Typ := Underlying_Full_View (Val_Typ);
26439 elsif Present (Full_View (Val_Typ)) then
26441 Val_Typ := Full_View (Val_Typ);
26447 end Validated_View;
26449 -----------------------
26450 -- Visible_Ancestors --
26451 -----------------------
26453 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
26459 pragma Assert (Is_Record_Type (Typ) and then Is_Tagged_Type (Typ));
26461 -- Collect all the parents and progenitors of Typ. If the full-view of
26462 -- private parents and progenitors is available then it is used to
26463 -- generate the list of visible ancestors; otherwise their partial
26464 -- view is added to the resulting list.
26469 Use_Full_View => True);
26473 Ifaces_List => List_2,
26474 Exclude_Parents => True,
26475 Use_Full_View => True);
26477 -- Join the two lists. Avoid duplications because an interface may
26478 -- simultaneously be parent and progenitor of a type.
26480 Elmt := First_Elmt (List_2);
26481 while Present (Elmt) loop
26482 Append_Unique_Elmt (Node (Elmt), List_1);
26487 end Visible_Ancestors;
26489 ----------------------
26490 -- Within_Init_Proc --
26491 ----------------------
26493 function Within_Init_Proc return Boolean is
26497 S := Current_Scope;
26498 while not Is_Overloadable (S) loop
26499 if S = Standard_Standard then
26506 return Is_Init_Proc (S);
26507 end Within_Init_Proc;
26509 ---------------------------
26510 -- Within_Protected_Type --
26511 ---------------------------
26513 function Within_Protected_Type (E : Entity_Id) return Boolean is
26514 Scop : Entity_Id := Scope (E);
26517 while Present (Scop) loop
26518 if Ekind (Scop) = E_Protected_Type then
26522 Scop := Scope (Scop);
26526 end Within_Protected_Type;
26532 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
26534 return Scope_Within_Or_Same (Scope (E), S);
26537 ----------------------------
26538 -- Within_Subprogram_Call --
26539 ----------------------------
26541 function Within_Subprogram_Call (N : Node_Id) return Boolean is
26545 -- Climb the parent chain looking for a function or procedure call
26548 while Present (Par) loop
26549 if Nkind_In (Par, N_Entry_Call_Statement,
26551 N_Procedure_Call_Statement)
26555 -- Prevent the search from going too far
26557 elsif Is_Body_Or_Package_Declaration (Par) then
26561 Par := Parent (Par);
26565 end Within_Subprogram_Call;
26571 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
26572 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
26573 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
26575 Matching_Field : Entity_Id;
26576 -- Entity to give a more precise suggestion on how to write a one-
26577 -- element positional aggregate.
26579 function Has_One_Matching_Field return Boolean;
26580 -- Determines if Expec_Type is a record type with a single component or
26581 -- discriminant whose type matches the found type or is one dimensional
26582 -- array whose component type matches the found type. In the case of
26583 -- one discriminant, we ignore the variant parts. That's not accurate,
26584 -- but good enough for the warning.
26586 ----------------------------
26587 -- Has_One_Matching_Field --
26588 ----------------------------
26590 function Has_One_Matching_Field return Boolean is
26594 Matching_Field := Empty;
26596 if Is_Array_Type (Expec_Type)
26597 and then Number_Dimensions (Expec_Type) = 1
26598 and then Covers (Etype (Component_Type (Expec_Type)), Found_Type)
26600 -- Use type name if available. This excludes multidimensional
26601 -- arrays and anonymous arrays.
26603 if Comes_From_Source (Expec_Type) then
26604 Matching_Field := Expec_Type;
26606 -- For an assignment, use name of target
26608 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
26609 and then Is_Entity_Name (Name (Parent (Expr)))
26611 Matching_Field := Entity (Name (Parent (Expr)));
26616 elsif not Is_Record_Type (Expec_Type) then
26620 E := First_Entity (Expec_Type);
26625 elsif not Ekind_In (E, E_Discriminant, E_Component)
26626 or else Nam_In (Chars (E), Name_uTag, Name_uParent)
26635 if not Covers (Etype (E), Found_Type) then
26638 elsif Present (Next_Entity (E))
26639 and then (Ekind (E) = E_Component
26640 or else Ekind (Next_Entity (E)) = E_Discriminant)
26645 Matching_Field := E;
26649 end Has_One_Matching_Field;
26651 -- Start of processing for Wrong_Type
26654 -- Don't output message if either type is Any_Type, or if a message
26655 -- has already been posted for this node. We need to do the latter
26656 -- check explicitly (it is ordinarily done in Errout), because we
26657 -- are using ! to force the output of the error messages.
26659 if Expec_Type = Any_Type
26660 or else Found_Type = Any_Type
26661 or else Error_Posted (Expr)
26665 -- If one of the types is a Taft-Amendment type and the other it its
26666 -- completion, it must be an illegal use of a TAT in the spec, for
26667 -- which an error was already emitted. Avoid cascaded errors.
26669 elsif Is_Incomplete_Type (Expec_Type)
26670 and then Has_Completion_In_Body (Expec_Type)
26671 and then Full_View (Expec_Type) = Etype (Expr)
26675 elsif Is_Incomplete_Type (Etype (Expr))
26676 and then Has_Completion_In_Body (Etype (Expr))
26677 and then Full_View (Etype (Expr)) = Expec_Type
26681 -- In an instance, there is an ongoing problem with completion of
26682 -- type derived from private types. Their structure is what Gigi
26683 -- expects, but the Etype is the parent type rather than the
26684 -- derived private type itself. Do not flag error in this case. The
26685 -- private completion is an entity without a parent, like an Itype.
26686 -- Similarly, full and partial views may be incorrect in the instance.
26687 -- There is no simple way to insure that it is consistent ???
26689 -- A similar view discrepancy can happen in an inlined body, for the
26690 -- same reason: inserted body may be outside of the original package
26691 -- and only partial views are visible at the point of insertion.
26693 elsif In_Instance or else In_Inlined_Body then
26694 if Etype (Etype (Expr)) = Etype (Expected_Type)
26696 (Has_Private_Declaration (Expected_Type)
26697 or else Has_Private_Declaration (Etype (Expr)))
26698 and then No (Parent (Expected_Type))
26702 elsif Nkind (Parent (Expr)) = N_Qualified_Expression
26703 and then Entity (Subtype_Mark (Parent (Expr))) = Expected_Type
26707 elsif Is_Private_Type (Expected_Type)
26708 and then Present (Full_View (Expected_Type))
26709 and then Covers (Full_View (Expected_Type), Etype (Expr))
26713 -- Conversely, type of expression may be the private one
26715 elsif Is_Private_Type (Base_Type (Etype (Expr)))
26716 and then Full_View (Base_Type (Etype (Expr))) = Expected_Type
26722 -- An interesting special check. If the expression is parenthesized
26723 -- and its type corresponds to the type of the sole component of the
26724 -- expected record type, or to the component type of the expected one
26725 -- dimensional array type, then assume we have a bad aggregate attempt.
26727 if Nkind (Expr) in N_Subexpr
26728 and then Paren_Count (Expr) /= 0
26729 and then Has_One_Matching_Field
26731 Error_Msg_N ("positional aggregate cannot have one component", Expr);
26733 if Present (Matching_Field) then
26734 if Is_Array_Type (Expec_Type) then
26736 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
26739 ("\write instead `& ='> ...`", Expr, Matching_Field);
26743 -- Another special check, if we are looking for a pool-specific access
26744 -- type and we found an E_Access_Attribute_Type, then we have the case
26745 -- of an Access attribute being used in a context which needs a pool-
26746 -- specific type, which is never allowed. The one extra check we make
26747 -- is that the expected designated type covers the Found_Type.
26749 elsif Is_Access_Type (Expec_Type)
26750 and then Ekind (Found_Type) = E_Access_Attribute_Type
26751 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
26752 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
26754 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
26756 Error_Msg_N -- CODEFIX
26757 ("result must be general access type!", Expr);
26758 Error_Msg_NE -- CODEFIX
26759 ("add ALL to }!", Expr, Expec_Type);
26761 -- Another special check, if the expected type is an integer type,
26762 -- but the expression is of type System.Address, and the parent is
26763 -- an addition or subtraction operation whose left operand is the
26764 -- expression in question and whose right operand is of an integral
26765 -- type, then this is an attempt at address arithmetic, so give
26766 -- appropriate message.
26768 elsif Is_Integer_Type (Expec_Type)
26769 and then Is_RTE (Found_Type, RE_Address)
26770 and then Nkind_In (Parent (Expr), N_Op_Add, N_Op_Subtract)
26771 and then Expr = Left_Opnd (Parent (Expr))
26772 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
26775 ("address arithmetic not predefined in package System",
26778 ("\possible missing with/use of System.Storage_Elements",
26782 -- If the expected type is an anonymous access type, as for access
26783 -- parameters and discriminants, the error is on the designated types.
26785 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
26786 if Comes_From_Source (Expec_Type) then
26787 Error_Msg_NE ("expected}!", Expr, Expec_Type);
26790 ("expected an access type with designated}",
26791 Expr, Designated_Type (Expec_Type));
26794 if Is_Access_Type (Found_Type)
26795 and then not Comes_From_Source (Found_Type)
26798 ("\\found an access type with designated}!",
26799 Expr, Designated_Type (Found_Type));
26801 if From_Limited_With (Found_Type) then
26802 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
26803 Error_Msg_Qual_Level := 99;
26804 Error_Msg_NE -- CODEFIX
26805 ("\\missing `WITH &;", Expr, Scope (Found_Type));
26806 Error_Msg_Qual_Level := 0;
26808 Error_Msg_NE ("found}!", Expr, Found_Type);
26812 -- Normal case of one type found, some other type expected
26815 -- If the names of the two types are the same, see if some number
26816 -- of levels of qualification will help. Don't try more than three
26817 -- levels, and if we get to standard, it's no use (and probably
26818 -- represents an error in the compiler) Also do not bother with
26819 -- internal scope names.
26822 Expec_Scope : Entity_Id;
26823 Found_Scope : Entity_Id;
26826 Expec_Scope := Expec_Type;
26827 Found_Scope := Found_Type;
26829 for Levels in Nat range 0 .. 3 loop
26830 if Chars (Expec_Scope) /= Chars (Found_Scope) then
26831 Error_Msg_Qual_Level := Levels;
26835 Expec_Scope := Scope (Expec_Scope);
26836 Found_Scope := Scope (Found_Scope);
26838 exit when Expec_Scope = Standard_Standard
26839 or else Found_Scope = Standard_Standard
26840 or else not Comes_From_Source (Expec_Scope)
26841 or else not Comes_From_Source (Found_Scope);
26845 if Is_Record_Type (Expec_Type)
26846 and then Present (Corresponding_Remote_Type (Expec_Type))
26848 Error_Msg_NE ("expected}!", Expr,
26849 Corresponding_Remote_Type (Expec_Type));
26851 Error_Msg_NE ("expected}!", Expr, Expec_Type);
26854 if Is_Entity_Name (Expr)
26855 and then Is_Package_Or_Generic_Package (Entity (Expr))
26857 Error_Msg_N ("\\found package name!", Expr);
26859 elsif Is_Entity_Name (Expr)
26860 and then Ekind_In (Entity (Expr), E_Procedure, E_Generic_Procedure)
26862 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
26864 ("found procedure name, possibly missing Access attribute!",
26868 ("\\found procedure name instead of function!", Expr);
26871 elsif Nkind (Expr) = N_Function_Call
26872 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
26873 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
26874 and then No (Parameter_Associations (Expr))
26877 ("found function name, possibly missing Access attribute!",
26880 -- Catch common error: a prefix or infix operator which is not
26881 -- directly visible because the type isn't.
26883 elsif Nkind (Expr) in N_Op
26884 and then Is_Overloaded (Expr)
26885 and then not Is_Immediately_Visible (Expec_Type)
26886 and then not Is_Potentially_Use_Visible (Expec_Type)
26887 and then not In_Use (Expec_Type)
26888 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
26891 ("operator of the type is not directly visible!", Expr);
26893 elsif Ekind (Found_Type) = E_Void
26894 and then Present (Parent (Found_Type))
26895 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
26897 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
26900 Error_Msg_NE ("\\found}!", Expr, Found_Type);
26903 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
26904 -- of the same modular type, and (M1 and M2) = 0 was intended.
26906 if Expec_Type = Standard_Boolean
26907 and then Is_Modular_Integer_Type (Found_Type)
26908 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
26909 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
26912 Op : constant Node_Id := Right_Opnd (Parent (Expr));
26913 L : constant Node_Id := Left_Opnd (Op);
26914 R : constant Node_Id := Right_Opnd (Op);
26917 -- The case for the message is when the left operand of the
26918 -- comparison is the same modular type, or when it is an
26919 -- integer literal (or other universal integer expression),
26920 -- which would have been typed as the modular type if the
26921 -- parens had been there.
26923 if (Etype (L) = Found_Type
26925 Etype (L) = Universal_Integer)
26926 and then Is_Integer_Type (Etype (R))
26929 ("\\possible missing parens for modular operation", Expr);
26934 -- Reset error message qualification indication
26936 Error_Msg_Qual_Level := 0;
26940 --------------------------------
26941 -- Yields_Synchronized_Object --
26942 --------------------------------
26944 function Yields_Synchronized_Object (Typ : Entity_Id) return Boolean is
26945 Has_Sync_Comp : Boolean := False;
26949 -- An array type yields a synchronized object if its component type
26950 -- yields a synchronized object.
26952 if Is_Array_Type (Typ) then
26953 return Yields_Synchronized_Object (Component_Type (Typ));
26955 -- A descendant of type Ada.Synchronous_Task_Control.Suspension_Object
26956 -- yields a synchronized object by default.
26958 elsif Is_Descendant_Of_Suspension_Object (Typ) then
26961 -- A protected type yields a synchronized object by default
26963 elsif Is_Protected_Type (Typ) then
26966 -- A record type or type extension yields a synchronized object when its
26967 -- discriminants (if any) lack default values and all components are of
26968 -- a type that yields a synchronized object.
26970 elsif Is_Record_Type (Typ) then
26972 -- Inspect all entities defined in the scope of the type, looking for
26973 -- components of a type that does not yield a synchronized object or
26974 -- for discriminants with default values.
26976 Id := First_Entity (Typ);
26977 while Present (Id) loop
26978 if Comes_From_Source (Id) then
26979 if Ekind (Id) = E_Component then
26980 if Yields_Synchronized_Object (Etype (Id)) then
26981 Has_Sync_Comp := True;
26983 -- The component does not yield a synchronized object
26989 elsif Ekind (Id) = E_Discriminant
26990 and then Present (Expression (Parent (Id)))
26999 -- Ensure that the parent type of a type extension yields a
27000 -- synchronized object.
27002 if Etype (Typ) /= Typ
27003 and then not Is_Private_Type (Etype (Typ))
27004 and then not Yields_Synchronized_Object (Etype (Typ))
27009 -- If we get here, then all discriminants lack default values and all
27010 -- components are of a type that yields a synchronized object.
27012 return Has_Sync_Comp;
27014 -- A synchronized interface type yields a synchronized object by default
27016 elsif Is_Synchronized_Interface (Typ) then
27019 -- A task type yields a synchronized object by default
27021 elsif Is_Task_Type (Typ) then
27024 -- A private type yields a synchronized object if its underlying type
27027 elsif Is_Private_Type (Typ)
27028 and then Present (Underlying_Type (Typ))
27030 return Yields_Synchronized_Object (Underlying_Type (Typ));
27032 -- Otherwise the type does not yield a synchronized object
27037 end Yields_Synchronized_Object;
27039 ---------------------------
27040 -- Yields_Universal_Type --
27041 ---------------------------
27043 function Yields_Universal_Type (N : Node_Id) return Boolean is
27045 -- Integer and real literals are of a universal type
27047 if Nkind_In (N, N_Integer_Literal, N_Real_Literal) then
27050 -- The values of certain attributes are of a universal type
27052 elsif Nkind (N) = N_Attribute_Reference then
27054 Universal_Type_Attribute (Get_Attribute_Id (Attribute_Name (N)));
27056 -- ??? There are possibly other cases to consider
27061 end Yields_Universal_Type;
27064 Erroutc.Subprogram_Name_Ptr := Subprogram_Name'Access;