1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2015, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Treepr; -- ???For debugging code below
28 with Aspects; use Aspects;
29 with Atree; use Atree;
30 with Casing; use Casing;
31 with Checks; use Checks;
32 with Debug; use Debug;
33 with Elists; use Elists;
34 with Errout; use Errout;
35 with Exp_Ch11; use Exp_Ch11;
36 with Exp_Disp; use Exp_Disp;
37 with Exp_Util; use Exp_Util;
38 with Fname; use Fname;
39 with Freeze; use Freeze;
40 with Ghost; use Ghost;
42 with Lib.Xref; use Lib.Xref;
43 with Namet.Sp; use Namet.Sp;
44 with Nlists; use Nlists;
45 with Nmake; use Nmake;
46 with Output; use Output;
47 with Restrict; use Restrict;
48 with Rident; use Rident;
49 with Rtsfind; use Rtsfind;
51 with Sem_Aux; use Sem_Aux;
52 with Sem_Attr; use Sem_Attr;
53 with Sem_Ch6; use Sem_Ch6;
54 with Sem_Ch8; use Sem_Ch8;
55 with Sem_Ch13; use Sem_Ch13;
56 with Sem_Disp; use Sem_Disp;
57 with Sem_Eval; use Sem_Eval;
58 with Sem_Prag; use Sem_Prag;
59 with Sem_Res; use Sem_Res;
60 with Sem_Warn; use Sem_Warn;
61 with Sem_Type; use Sem_Type;
62 with Sinfo; use Sinfo;
63 with Sinput; use Sinput;
64 with Stand; use Stand;
66 with Stringt; use Stringt;
67 with Targparm; use Targparm;
68 with Tbuild; use Tbuild;
69 with Ttypes; use Ttypes;
70 with Uname; use Uname;
72 with GNAT.HTable; use GNAT.HTable;
74 package body Sem_Util is
76 ----------------------------------------
77 -- Global Variables for New_Copy_Tree --
78 ----------------------------------------
80 -- These global variables are used by New_Copy_Tree. See description of the
81 -- body of this subprogram for details. Global variables can be safely used
82 -- by New_Copy_Tree, since there is no case of a recursive call from the
83 -- processing inside New_Copy_Tree.
85 NCT_Hash_Threshold : constant := 20;
86 -- If there are more than this number of pairs of entries in the map, then
87 -- Hash_Tables_Used will be set, and the hash tables will be initialized
88 -- and used for the searches.
90 NCT_Hash_Tables_Used : Boolean := False;
91 -- Set to True if hash tables are in use
93 NCT_Table_Entries : Nat := 0;
94 -- Count entries in table to see if threshold is reached
96 NCT_Hash_Table_Setup : Boolean := False;
97 -- Set to True if hash table contains data. We set this True if we setup
98 -- the hash table with data, and leave it set permanently from then on,
99 -- this is a signal that second and subsequent users of the hash table
100 -- must clear the old entries before reuse.
102 subtype NCT_Header_Num is Int range 0 .. 511;
103 -- Defines range of headers in hash tables (512 headers)
105 -----------------------
106 -- Local Subprograms --
107 -----------------------
109 function Build_Component_Subtype
112 T : Entity_Id) return Node_Id;
113 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
114 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
115 -- Loc is the source location, T is the original subtype.
117 function Has_Enabled_Property
118 (Item_Id : Entity_Id;
119 Property : Name_Id) return Boolean;
120 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
121 -- Determine whether an abstract state or a variable denoted by entity
122 -- Item_Id has enabled property Property.
124 function Has_Null_Extension (T : Entity_Id) return Boolean;
125 -- T is a derived tagged type. Check whether the type extension is null.
126 -- If the parent type is fully initialized, T can be treated as such.
128 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
129 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
130 -- with discriminants whose default values are static, examine only the
131 -- components in the selected variant to determine whether all of them
134 ------------------------------
135 -- Abstract_Interface_List --
136 ------------------------------
138 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
142 if Is_Concurrent_Type (Typ) then
144 -- If we are dealing with a synchronized subtype, go to the base
145 -- type, whose declaration has the interface list.
147 -- Shouldn't this be Declaration_Node???
149 Nod := Parent (Base_Type (Typ));
151 if Nkind (Nod) = N_Full_Type_Declaration then
155 elsif Ekind (Typ) = E_Record_Type_With_Private then
156 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
157 Nod := Type_Definition (Parent (Typ));
159 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
160 if Present (Full_View (Typ))
162 Nkind (Parent (Full_View (Typ))) = N_Full_Type_Declaration
164 Nod := Type_Definition (Parent (Full_View (Typ)));
166 -- If the full-view is not available we cannot do anything else
167 -- here (the source has errors).
173 -- Support for generic formals with interfaces is still missing ???
175 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
180 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
184 elsif Ekind (Typ) = E_Record_Subtype then
185 Nod := Type_Definition (Parent (Etype (Typ)));
187 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
189 -- Recurse, because parent may still be a private extension. Also
190 -- note that the full view of the subtype or the full view of its
191 -- base type may (both) be unavailable.
193 return Abstract_Interface_List (Etype (Typ));
195 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
196 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
197 Nod := Formal_Type_Definition (Parent (Typ));
199 Nod := Type_Definition (Parent (Typ));
203 return Interface_List (Nod);
204 end Abstract_Interface_List;
206 --------------------------------
207 -- Add_Access_Type_To_Process --
208 --------------------------------
210 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
214 Ensure_Freeze_Node (E);
215 L := Access_Types_To_Process (Freeze_Node (E));
219 Set_Access_Types_To_Process (Freeze_Node (E), L);
223 end Add_Access_Type_To_Process;
225 --------------------------
226 -- Add_Block_Identifier --
227 --------------------------
229 procedure Add_Block_Identifier (N : Node_Id; Id : out Entity_Id) is
230 Loc : constant Source_Ptr := Sloc (N);
233 pragma Assert (Nkind (N) = N_Block_Statement);
235 -- The block already has a label, return its entity
237 if Present (Identifier (N)) then
238 Id := Entity (Identifier (N));
240 -- Create a new block label and set its attributes
243 Id := New_Internal_Entity (E_Block, Current_Scope, Loc, 'B');
244 Set_Etype (Id, Standard_Void_Type);
247 Set_Identifier (N, New_Occurrence_Of (Id, Loc));
248 Set_Block_Node (Id, Identifier (N));
250 end Add_Block_Identifier;
252 ----------------------------
253 -- Add_Global_Declaration --
254 ----------------------------
256 procedure Add_Global_Declaration (N : Node_Id) is
257 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
260 if No (Declarations (Aux_Node)) then
261 Set_Declarations (Aux_Node, New_List);
264 Append_To (Declarations (Aux_Node), N);
266 end Add_Global_Declaration;
268 --------------------------------
269 -- Address_Integer_Convert_OK --
270 --------------------------------
272 function Address_Integer_Convert_OK (T1, T2 : Entity_Id) return Boolean is
274 if Allow_Integer_Address
275 and then ((Is_Descendant_Of_Address (T1)
276 and then Is_Private_Type (T1)
277 and then Is_Integer_Type (T2))
279 (Is_Descendant_Of_Address (T2)
280 and then Is_Private_Type (T2)
281 and then Is_Integer_Type (T1)))
287 end Address_Integer_Convert_OK;
293 -- For now, just 8/16/32/64. but analyze later if AAMP is special???
295 function Addressable (V : Uint) return Boolean is
297 return V = Uint_8 or else
303 function Addressable (V : Int) return Boolean is
311 ---------------------------------
312 -- Aggregate_Constraint_Checks --
313 ---------------------------------
315 procedure Aggregate_Constraint_Checks
317 Check_Typ : Entity_Id)
319 Exp_Typ : constant Entity_Id := Etype (Exp);
322 if Raises_Constraint_Error (Exp) then
326 -- Ada 2005 (AI-230): Generate a conversion to an anonymous access
327 -- component's type to force the appropriate accessibility checks.
329 -- Ada 2005 (AI-231): Generate conversion to the null-excluding
330 -- type to force the corresponding run-time check
332 if Is_Access_Type (Check_Typ)
333 and then ((Is_Local_Anonymous_Access (Check_Typ))
334 or else (Can_Never_Be_Null (Check_Typ)
335 and then not Can_Never_Be_Null (Exp_Typ)))
337 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
338 Analyze_And_Resolve (Exp, Check_Typ);
339 Check_Unset_Reference (Exp);
342 -- This is really expansion activity, so make sure that expansion is
343 -- on and is allowed. In GNATprove mode, we also want check flags to
344 -- be added in the tree, so that the formal verification can rely on
345 -- those to be present. In GNATprove mode for formal verification, some
346 -- treatment typically only done during expansion needs to be performed
347 -- on the tree, but it should not be applied inside generics. Otherwise,
348 -- this breaks the name resolution mechanism for generic instances.
350 if not Expander_Active
351 and (Inside_A_Generic or not Full_Analysis or not GNATprove_Mode)
356 -- First check if we have to insert discriminant checks
358 if Has_Discriminants (Exp_Typ) then
359 Apply_Discriminant_Check (Exp, Check_Typ);
361 -- Next emit length checks for array aggregates
363 elsif Is_Array_Type (Exp_Typ) then
364 Apply_Length_Check (Exp, Check_Typ);
366 -- Finally emit scalar and string checks. If we are dealing with a
367 -- scalar literal we need to check by hand because the Etype of
368 -- literals is not necessarily correct.
370 elsif Is_Scalar_Type (Exp_Typ)
371 and then Compile_Time_Known_Value (Exp)
373 if Is_Out_Of_Range (Exp, Base_Type (Check_Typ)) then
374 Apply_Compile_Time_Constraint_Error
375 (Exp, "value not in range of}??", CE_Range_Check_Failed,
376 Ent => Base_Type (Check_Typ),
377 Typ => Base_Type (Check_Typ));
379 elsif Is_Out_Of_Range (Exp, Check_Typ) then
380 Apply_Compile_Time_Constraint_Error
381 (Exp, "value not in range of}??", CE_Range_Check_Failed,
385 elsif not Range_Checks_Suppressed (Check_Typ) then
386 Apply_Scalar_Range_Check (Exp, Check_Typ);
389 -- Verify that target type is also scalar, to prevent view anomalies
390 -- in instantiations.
392 elsif (Is_Scalar_Type (Exp_Typ)
393 or else Nkind (Exp) = N_String_Literal)
394 and then Is_Scalar_Type (Check_Typ)
395 and then Exp_Typ /= Check_Typ
397 if Is_Entity_Name (Exp)
398 and then Ekind (Entity (Exp)) = E_Constant
400 -- If expression is a constant, it is worthwhile checking whether
401 -- it is a bound of the type.
403 if (Is_Entity_Name (Type_Low_Bound (Check_Typ))
404 and then Entity (Exp) = Entity (Type_Low_Bound (Check_Typ)))
406 (Is_Entity_Name (Type_High_Bound (Check_Typ))
407 and then Entity (Exp) = Entity (Type_High_Bound (Check_Typ)))
412 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
413 Analyze_And_Resolve (Exp, Check_Typ);
414 Check_Unset_Reference (Exp);
417 -- Could use a comment on this case ???
420 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
421 Analyze_And_Resolve (Exp, Check_Typ);
422 Check_Unset_Reference (Exp);
426 end Aggregate_Constraint_Checks;
428 -----------------------
429 -- Alignment_In_Bits --
430 -----------------------
432 function Alignment_In_Bits (E : Entity_Id) return Uint is
434 return Alignment (E) * System_Storage_Unit;
435 end Alignment_In_Bits;
437 --------------------------------------
438 -- All_Composite_Constraints_Static --
439 --------------------------------------
441 function All_Composite_Constraints_Static
442 (Constr : Node_Id) return Boolean
445 if No (Constr) or else Error_Posted (Constr) then
449 case Nkind (Constr) is
451 if Nkind (Constr) in N_Has_Entity
452 and then Present (Entity (Constr))
454 if Is_Type (Entity (Constr)) then
456 not Is_Discrete_Type (Entity (Constr))
457 or else Is_OK_Static_Subtype (Entity (Constr));
460 elsif Nkind (Constr) = N_Range then
462 Is_OK_Static_Expression (Low_Bound (Constr))
464 Is_OK_Static_Expression (High_Bound (Constr));
466 elsif Nkind (Constr) = N_Attribute_Reference
467 and then Attribute_Name (Constr) = Name_Range
470 Is_OK_Static_Expression
471 (Type_Low_Bound (Etype (Prefix (Constr))))
473 Is_OK_Static_Expression
474 (Type_High_Bound (Etype (Prefix (Constr))));
478 not Present (Etype (Constr)) -- previous error
479 or else not Is_Discrete_Type (Etype (Constr))
480 or else Is_OK_Static_Expression (Constr);
482 when N_Discriminant_Association =>
483 return All_Composite_Constraints_Static (Expression (Constr));
485 when N_Range_Constraint =>
487 All_Composite_Constraints_Static (Range_Expression (Constr));
489 when N_Index_Or_Discriminant_Constraint =>
491 One_Cstr : Entity_Id;
493 One_Cstr := First (Constraints (Constr));
494 while Present (One_Cstr) loop
495 if not All_Composite_Constraints_Static (One_Cstr) then
505 when N_Subtype_Indication =>
507 All_Composite_Constraints_Static (Subtype_Mark (Constr))
509 All_Composite_Constraints_Static (Constraint (Constr));
514 end All_Composite_Constraints_Static;
516 ---------------------------------
517 -- Append_Inherited_Subprogram --
518 ---------------------------------
520 procedure Append_Inherited_Subprogram (S : Entity_Id) is
521 Par : constant Entity_Id := Alias (S);
522 -- The parent subprogram
524 Scop : constant Entity_Id := Scope (Par);
525 -- The scope of definition of the parent subprogram
527 Typ : constant Entity_Id := Defining_Entity (Parent (S));
528 -- The derived type of which S is a primitive operation
534 if Ekind (Current_Scope) = E_Package
535 and then In_Private_Part (Current_Scope)
536 and then Has_Private_Declaration (Typ)
537 and then Is_Tagged_Type (Typ)
538 and then Scop = Current_Scope
540 -- The inherited operation is available at the earliest place after
541 -- the derived type declaration ( RM 7.3.1 (6/1)). This is only
542 -- relevant for type extensions. If the parent operation appears
543 -- after the type extension, the operation is not visible.
546 (Visible_Declarations
547 (Package_Specification (Current_Scope)));
548 while Present (Decl) loop
549 if Nkind (Decl) = N_Private_Extension_Declaration
550 and then Defining_Entity (Decl) = Typ
552 if Sloc (Decl) > Sloc (Par) then
553 Next_E := Next_Entity (Par);
554 Set_Next_Entity (Par, S);
555 Set_Next_Entity (S, Next_E);
567 -- If partial view is not a type extension, or it appears before the
568 -- subprogram declaration, insert normally at end of entity list.
570 Append_Entity (S, Current_Scope);
571 end Append_Inherited_Subprogram;
573 -----------------------------------------
574 -- Apply_Compile_Time_Constraint_Error --
575 -----------------------------------------
577 procedure Apply_Compile_Time_Constraint_Error
580 Reason : RT_Exception_Code;
581 Ent : Entity_Id := Empty;
582 Typ : Entity_Id := Empty;
583 Loc : Source_Ptr := No_Location;
584 Rep : Boolean := True;
585 Warn : Boolean := False)
587 Stat : constant Boolean := Is_Static_Expression (N);
588 R_Stat : constant Node_Id :=
589 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
600 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
606 -- Now we replace the node by an N_Raise_Constraint_Error node
607 -- This does not need reanalyzing, so set it as analyzed now.
610 Set_Analyzed (N, True);
613 Set_Raises_Constraint_Error (N);
615 -- Now deal with possible local raise handling
617 Possible_Local_Raise (N, Standard_Constraint_Error);
619 -- If the original expression was marked as static, the result is
620 -- still marked as static, but the Raises_Constraint_Error flag is
621 -- always set so that further static evaluation is not attempted.
624 Set_Is_Static_Expression (N);
626 end Apply_Compile_Time_Constraint_Error;
628 ---------------------------
629 -- Async_Readers_Enabled --
630 ---------------------------
632 function Async_Readers_Enabled (Id : Entity_Id) return Boolean is
634 return Has_Enabled_Property (Id, Name_Async_Readers);
635 end Async_Readers_Enabled;
637 ---------------------------
638 -- Async_Writers_Enabled --
639 ---------------------------
641 function Async_Writers_Enabled (Id : Entity_Id) return Boolean is
643 return Has_Enabled_Property (Id, Name_Async_Writers);
644 end Async_Writers_Enabled;
646 --------------------------------------
647 -- Available_Full_View_Of_Component --
648 --------------------------------------
650 function Available_Full_View_Of_Component (T : Entity_Id) return Boolean is
651 ST : constant Entity_Id := Scope (T);
652 SCT : constant Entity_Id := Scope (Component_Type (T));
654 return In_Open_Scopes (ST)
655 and then In_Open_Scopes (SCT)
656 and then Scope_Depth (ST) >= Scope_Depth (SCT);
657 end Available_Full_View_Of_Component;
663 procedure Bad_Attribute
666 Warn : Boolean := False)
669 Error_Msg_Warn := Warn;
670 Error_Msg_N ("unrecognized attribute&<<", N);
672 -- Check for possible misspelling
674 Error_Msg_Name_1 := First_Attribute_Name;
675 while Error_Msg_Name_1 <= Last_Attribute_Name loop
676 if Is_Bad_Spelling_Of (Nam, Error_Msg_Name_1) then
677 Error_Msg_N -- CODEFIX
678 ("\possible misspelling of %<<", N);
682 Error_Msg_Name_1 := Error_Msg_Name_1 + 1;
686 --------------------------------
687 -- Bad_Predicated_Subtype_Use --
688 --------------------------------
690 procedure Bad_Predicated_Subtype_Use
694 Suggest_Static : Boolean := False)
699 -- Avoid cascaded errors
701 if Error_Posted (N) then
705 if Inside_A_Generic then
706 Gen := Current_Scope;
707 while Present (Gen) and then Ekind (Gen) /= E_Generic_Package loop
715 if Is_Generic_Formal (Typ) and then Is_Discrete_Type (Typ) then
716 Set_No_Predicate_On_Actual (Typ);
719 elsif Has_Predicates (Typ) then
720 if Is_Generic_Actual_Type (Typ) then
722 -- The restriction on loop parameters is only that the type
723 -- should have no dynamic predicates.
725 if Nkind (Parent (N)) = N_Loop_Parameter_Specification
726 and then not Has_Dynamic_Predicate_Aspect (Typ)
727 and then Is_OK_Static_Subtype (Typ)
732 Gen := Current_Scope;
733 while not Is_Generic_Instance (Gen) loop
737 pragma Assert (Present (Gen));
739 if Ekind (Gen) = E_Package and then In_Package_Body (Gen) then
740 Error_Msg_Warn := SPARK_Mode /= On;
741 Error_Msg_FE (Msg & "<<", N, Typ);
742 Error_Msg_F ("\Program_Error [<<", N);
745 Make_Raise_Program_Error (Sloc (N),
746 Reason => PE_Bad_Predicated_Generic_Type));
749 Error_Msg_FE (Msg & "<<", N, Typ);
753 Error_Msg_FE (Msg, N, Typ);
756 -- Emit an optional suggestion on how to remedy the error if the
757 -- context warrants it.
759 if Suggest_Static and then Has_Static_Predicate (Typ) then
760 Error_Msg_FE ("\predicate of & should be marked static", N, Typ);
763 end Bad_Predicated_Subtype_Use;
765 -----------------------------------------
766 -- Bad_Unordered_Enumeration_Reference --
767 -----------------------------------------
769 function Bad_Unordered_Enumeration_Reference
771 T : Entity_Id) return Boolean
774 return Is_Enumeration_Type (T)
775 and then Warn_On_Unordered_Enumeration_Type
776 and then not Is_Generic_Type (T)
777 and then Comes_From_Source (N)
778 and then not Has_Pragma_Ordered (T)
779 and then not In_Same_Extended_Unit (N, T);
780 end Bad_Unordered_Enumeration_Reference;
782 --------------------------
783 -- Build_Actual_Subtype --
784 --------------------------
786 function Build_Actual_Subtype
788 N : Node_Or_Entity_Id) return Node_Id
791 -- Normally Sloc (N), but may point to corresponding body in some cases
793 Constraints : List_Id;
799 Disc_Type : Entity_Id;
805 if Nkind (N) = N_Defining_Identifier then
806 Obj := New_Occurrence_Of (N, Loc);
808 -- If this is a formal parameter of a subprogram declaration, and
809 -- we are compiling the body, we want the declaration for the
810 -- actual subtype to carry the source position of the body, to
811 -- prevent anomalies in gdb when stepping through the code.
813 if Is_Formal (N) then
815 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
817 if Nkind (Decl) = N_Subprogram_Declaration
818 and then Present (Corresponding_Body (Decl))
820 Loc := Sloc (Corresponding_Body (Decl));
829 if Is_Array_Type (T) then
830 Constraints := New_List;
831 for J in 1 .. Number_Dimensions (T) loop
833 -- Build an array subtype declaration with the nominal subtype and
834 -- the bounds of the actual. Add the declaration in front of the
835 -- local declarations for the subprogram, for analysis before any
836 -- reference to the formal in the body.
839 Make_Attribute_Reference (Loc,
841 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
842 Attribute_Name => Name_First,
843 Expressions => New_List (
844 Make_Integer_Literal (Loc, J)));
847 Make_Attribute_Reference (Loc,
849 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
850 Attribute_Name => Name_Last,
851 Expressions => New_List (
852 Make_Integer_Literal (Loc, J)));
854 Append (Make_Range (Loc, Lo, Hi), Constraints);
857 -- If the type has unknown discriminants there is no constrained
858 -- subtype to build. This is never called for a formal or for a
859 -- lhs, so returning the type is ok ???
861 elsif Has_Unknown_Discriminants (T) then
865 Constraints := New_List;
867 -- Type T is a generic derived type, inherit the discriminants from
870 if Is_Private_Type (T)
871 and then No (Full_View (T))
873 -- T was flagged as an error if it was declared as a formal
874 -- derived type with known discriminants. In this case there
875 -- is no need to look at the parent type since T already carries
876 -- its own discriminants.
878 and then not Error_Posted (T)
880 Disc_Type := Etype (Base_Type (T));
885 Discr := First_Discriminant (Disc_Type);
886 while Present (Discr) loop
887 Append_To (Constraints,
888 Make_Selected_Component (Loc,
890 Duplicate_Subexpr_No_Checks (Obj),
891 Selector_Name => New_Occurrence_Of (Discr, Loc)));
892 Next_Discriminant (Discr);
896 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
897 Set_Is_Internal (Subt);
900 Make_Subtype_Declaration (Loc,
901 Defining_Identifier => Subt,
902 Subtype_Indication =>
903 Make_Subtype_Indication (Loc,
904 Subtype_Mark => New_Occurrence_Of (T, Loc),
906 Make_Index_Or_Discriminant_Constraint (Loc,
907 Constraints => Constraints)));
909 Mark_Rewrite_Insertion (Decl);
911 end Build_Actual_Subtype;
913 ---------------------------------------
914 -- Build_Actual_Subtype_Of_Component --
915 ---------------------------------------
917 function Build_Actual_Subtype_Of_Component
919 N : Node_Id) return Node_Id
921 Loc : constant Source_Ptr := Sloc (N);
922 P : constant Node_Id := Prefix (N);
925 Index_Typ : Entity_Id;
927 Desig_Typ : Entity_Id;
928 -- This is either a copy of T, or if T is an access type, then it is
929 -- the directly designated type of this access type.
931 function Build_Actual_Array_Constraint return List_Id;
932 -- If one or more of the bounds of the component depends on
933 -- discriminants, build actual constraint using the discriminants
936 function Build_Actual_Record_Constraint return List_Id;
937 -- Similar to previous one, for discriminated components constrained
938 -- by the discriminant of the enclosing object.
940 -----------------------------------
941 -- Build_Actual_Array_Constraint --
942 -----------------------------------
944 function Build_Actual_Array_Constraint return List_Id is
945 Constraints : constant List_Id := New_List;
953 Indx := First_Index (Desig_Typ);
954 while Present (Indx) loop
955 Old_Lo := Type_Low_Bound (Etype (Indx));
956 Old_Hi := Type_High_Bound (Etype (Indx));
958 if Denotes_Discriminant (Old_Lo) then
960 Make_Selected_Component (Loc,
961 Prefix => New_Copy_Tree (P),
962 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
965 Lo := New_Copy_Tree (Old_Lo);
967 -- The new bound will be reanalyzed in the enclosing
968 -- declaration. For literal bounds that come from a type
969 -- declaration, the type of the context must be imposed, so
970 -- insure that analysis will take place. For non-universal
971 -- types this is not strictly necessary.
973 Set_Analyzed (Lo, False);
976 if Denotes_Discriminant (Old_Hi) then
978 Make_Selected_Component (Loc,
979 Prefix => New_Copy_Tree (P),
980 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
983 Hi := New_Copy_Tree (Old_Hi);
984 Set_Analyzed (Hi, False);
987 Append (Make_Range (Loc, Lo, Hi), Constraints);
992 end Build_Actual_Array_Constraint;
994 ------------------------------------
995 -- Build_Actual_Record_Constraint --
996 ------------------------------------
998 function Build_Actual_Record_Constraint return List_Id is
999 Constraints : constant List_Id := New_List;
1004 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1005 while Present (D) loop
1006 if Denotes_Discriminant (Node (D)) then
1007 D_Val := Make_Selected_Component (Loc,
1008 Prefix => New_Copy_Tree (P),
1009 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
1012 D_Val := New_Copy_Tree (Node (D));
1015 Append (D_Val, Constraints);
1020 end Build_Actual_Record_Constraint;
1022 -- Start of processing for Build_Actual_Subtype_Of_Component
1025 -- Why the test for Spec_Expression mode here???
1027 if In_Spec_Expression then
1030 -- More comments for the rest of this body would be good ???
1032 elsif Nkind (N) = N_Explicit_Dereference then
1033 if Is_Composite_Type (T)
1034 and then not Is_Constrained (T)
1035 and then not (Is_Class_Wide_Type (T)
1036 and then Is_Constrained (Root_Type (T)))
1037 and then not Has_Unknown_Discriminants (T)
1039 -- If the type of the dereference is already constrained, it is an
1042 if Is_Array_Type (Etype (N))
1043 and then Is_Constrained (Etype (N))
1047 Remove_Side_Effects (P);
1048 return Build_Actual_Subtype (T, N);
1055 if Ekind (T) = E_Access_Subtype then
1056 Desig_Typ := Designated_Type (T);
1061 if Ekind (Desig_Typ) = E_Array_Subtype then
1062 Id := First_Index (Desig_Typ);
1063 while Present (Id) loop
1064 Index_Typ := Underlying_Type (Etype (Id));
1066 if Denotes_Discriminant (Type_Low_Bound (Index_Typ))
1068 Denotes_Discriminant (Type_High_Bound (Index_Typ))
1070 Remove_Side_Effects (P);
1072 Build_Component_Subtype
1073 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
1079 elsif Is_Composite_Type (Desig_Typ)
1080 and then Has_Discriminants (Desig_Typ)
1081 and then not Has_Unknown_Discriminants (Desig_Typ)
1083 if Is_Private_Type (Desig_Typ)
1084 and then No (Discriminant_Constraint (Desig_Typ))
1086 Desig_Typ := Full_View (Desig_Typ);
1089 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1090 while Present (D) loop
1091 if Denotes_Discriminant (Node (D)) then
1092 Remove_Side_Effects (P);
1094 Build_Component_Subtype (
1095 Build_Actual_Record_Constraint, Loc, Base_Type (T));
1102 -- If none of the above, the actual and nominal subtypes are the same
1105 end Build_Actual_Subtype_Of_Component;
1107 -----------------------------
1108 -- Build_Component_Subtype --
1109 -----------------------------
1111 function Build_Component_Subtype
1114 T : Entity_Id) return Node_Id
1120 -- Unchecked_Union components do not require component subtypes
1122 if Is_Unchecked_Union (T) then
1126 Subt := Make_Temporary (Loc, 'S');
1127 Set_Is_Internal (Subt);
1130 Make_Subtype_Declaration (Loc,
1131 Defining_Identifier => Subt,
1132 Subtype_Indication =>
1133 Make_Subtype_Indication (Loc,
1134 Subtype_Mark => New_Occurrence_Of (Base_Type (T), Loc),
1136 Make_Index_Or_Discriminant_Constraint (Loc,
1137 Constraints => C)));
1139 Mark_Rewrite_Insertion (Decl);
1141 end Build_Component_Subtype;
1143 ----------------------------------
1144 -- Build_Default_Init_Cond_Call --
1145 ----------------------------------
1147 function Build_Default_Init_Cond_Call
1150 Typ : Entity_Id) return Node_Id
1152 Proc_Id : constant Entity_Id := Default_Init_Cond_Procedure (Typ);
1153 Formal_Typ : constant Entity_Id := Etype (First_Formal (Proc_Id));
1157 Make_Procedure_Call_Statement (Loc,
1158 Name => New_Occurrence_Of (Proc_Id, Loc),
1159 Parameter_Associations => New_List (
1160 Make_Unchecked_Type_Conversion (Loc,
1161 Subtype_Mark => New_Occurrence_Of (Formal_Typ, Loc),
1162 Expression => New_Occurrence_Of (Obj_Id, Loc))));
1163 end Build_Default_Init_Cond_Call;
1165 ----------------------------------------------
1166 -- Build_Default_Init_Cond_Procedure_Bodies --
1167 ----------------------------------------------
1169 procedure Build_Default_Init_Cond_Procedure_Bodies (Priv_Decls : List_Id) is
1170 procedure Build_Default_Init_Cond_Procedure_Body (Typ : Entity_Id);
1171 -- If type Typ is subject to pragma Default_Initial_Condition, build the
1172 -- body of the procedure which verifies the assumption of the pragma at
1173 -- run time. The generated body is added after the type declaration.
1175 --------------------------------------------
1176 -- Build_Default_Init_Cond_Procedure_Body --
1177 --------------------------------------------
1179 procedure Build_Default_Init_Cond_Procedure_Body (Typ : Entity_Id) is
1180 Param_Id : Entity_Id;
1181 -- The entity of the sole formal parameter of the default initial
1182 -- condition procedure.
1184 procedure Replace_Type_Reference (N : Node_Id);
1185 -- Replace a single reference to type Typ with a reference to formal
1186 -- parameter Param_Id.
1188 ----------------------------
1189 -- Replace_Type_Reference --
1190 ----------------------------
1192 procedure Replace_Type_Reference (N : Node_Id) is
1194 Rewrite (N, New_Occurrence_Of (Param_Id, Sloc (N)));
1195 end Replace_Type_Reference;
1197 procedure Replace_Type_References is
1198 new Replace_Type_References_Generic (Replace_Type_Reference);
1202 Loc : constant Source_Ptr := Sloc (Typ);
1203 Prag : constant Node_Id :=
1204 Get_Pragma (Typ, Pragma_Default_Initial_Condition);
1205 Proc_Id : constant Entity_Id := Default_Init_Cond_Procedure (Typ);
1206 Spec_Decl : constant Node_Id := Unit_Declaration_Node (Proc_Id);
1207 Body_Decl : Node_Id;
1211 Save_Ghost_Mode : constant Ghost_Mode_Type := Ghost_Mode;
1213 -- Start of processing for Build_Default_Init_Cond_Procedure_Body
1216 -- The procedure should be generated only for [sub]types subject to
1217 -- pragma Default_Initial_Condition. Types that inherit the pragma do
1218 -- not get this specialized procedure.
1220 pragma Assert (Has_Default_Init_Cond (Typ));
1221 pragma Assert (Present (Prag));
1222 pragma Assert (Present (Proc_Id));
1224 -- Nothing to do if the body was already built
1226 if Present (Corresponding_Body (Spec_Decl)) then
1230 -- The related type may be subject to pragma Ghost. Set the mode now
1231 -- to ensure that the analysis and expansion produce Ghost nodes.
1233 Set_Ghost_Mode_From_Entity (Typ);
1235 Param_Id := First_Formal (Proc_Id);
1237 -- The pragma has an argument. Note that the argument is analyzed
1238 -- after all references to the current instance of the type are
1241 if Present (Pragma_Argument_Associations (Prag)) then
1243 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
1245 if Nkind (Expr) = N_Null then
1246 Stmt := Make_Null_Statement (Loc);
1248 -- Preserve the original argument of the pragma by replicating it.
1249 -- Replace all references to the current instance of the type with
1250 -- references to the formal parameter.
1253 Expr := New_Copy_Tree (Expr);
1254 Replace_Type_References (Expr, Typ);
1257 -- pragma Check (Default_Initial_Condition, <Expr>);
1261 Pragma_Identifier =>
1262 Make_Identifier (Loc, Name_Check),
1264 Pragma_Argument_Associations => New_List (
1265 Make_Pragma_Argument_Association (Loc,
1267 Make_Identifier (Loc,
1268 Chars => Name_Default_Initial_Condition)),
1269 Make_Pragma_Argument_Association (Loc,
1270 Expression => Expr)));
1273 -- Otherwise the pragma appears without an argument
1276 Stmt := Make_Null_Statement (Loc);
1280 -- procedure <Typ>Default_Init_Cond (I : <Typ>) is
1283 -- end <Typ>Default_Init_Cond;
1286 Make_Subprogram_Body (Loc,
1288 Copy_Separate_Tree (Specification (Spec_Decl)),
1289 Declarations => Empty_List,
1290 Handled_Statement_Sequence =>
1291 Make_Handled_Sequence_Of_Statements (Loc,
1292 Statements => New_List (Stmt)));
1294 -- Link the spec and body of the default initial condition procedure
1295 -- to prevent the generation of a duplicate body.
1297 Set_Corresponding_Body (Spec_Decl, Defining_Entity (Body_Decl));
1298 Set_Corresponding_Spec (Body_Decl, Proc_Id);
1300 Insert_After_And_Analyze (Declaration_Node (Typ), Body_Decl);
1301 Ghost_Mode := Save_Ghost_Mode;
1302 end Build_Default_Init_Cond_Procedure_Body;
1309 -- Start of processing for Build_Default_Init_Cond_Procedure_Bodies
1312 -- Inspect the private declarations looking for [sub]type declarations
1314 Decl := First (Priv_Decls);
1315 while Present (Decl) loop
1316 if Nkind_In (Decl, N_Full_Type_Declaration,
1317 N_Subtype_Declaration)
1319 Typ := Defining_Entity (Decl);
1321 -- Guard against partially decorate types due to previous errors
1323 if Is_Type (Typ) then
1325 -- If the type is subject to pragma Default_Initial_Condition,
1326 -- generate the body of the internal procedure which verifies
1327 -- the assertion of the pragma at run time.
1329 if Has_Default_Init_Cond (Typ) then
1330 Build_Default_Init_Cond_Procedure_Body (Typ);
1332 -- A derived type inherits the default initial condition
1333 -- procedure from its parent type.
1335 elsif Has_Inherited_Default_Init_Cond (Typ) then
1336 Inherit_Default_Init_Cond_Procedure (Typ);
1343 end Build_Default_Init_Cond_Procedure_Bodies;
1345 ---------------------------------------------------
1346 -- Build_Default_Init_Cond_Procedure_Declaration --
1347 ---------------------------------------------------
1349 procedure Build_Default_Init_Cond_Procedure_Declaration (Typ : Entity_Id) is
1350 Loc : constant Source_Ptr := Sloc (Typ);
1351 Prag : constant Node_Id :=
1352 Get_Pragma (Typ, Pragma_Default_Initial_Condition);
1354 Save_Ghost_Mode : constant Ghost_Mode_Type := Ghost_Mode;
1356 Proc_Id : Entity_Id;
1359 -- The procedure should be generated only for types subject to pragma
1360 -- Default_Initial_Condition. Types that inherit the pragma do not get
1361 -- this specialized procedure.
1363 pragma Assert (Has_Default_Init_Cond (Typ));
1364 pragma Assert (Present (Prag));
1366 -- Nothing to do if default initial condition procedure already built
1368 if Present (Default_Init_Cond_Procedure (Typ)) then
1372 -- The related type may be subject to pragma Ghost. Set the mode now to
1373 -- ensure that the analysis and expansion produce Ghost nodes.
1375 Set_Ghost_Mode_From_Entity (Typ);
1378 Make_Defining_Identifier (Loc,
1379 Chars => New_External_Name (Chars (Typ), "Default_Init_Cond"));
1381 -- Associate default initial condition procedure with the private type
1383 Set_Ekind (Proc_Id, E_Procedure);
1384 Set_Is_Default_Init_Cond_Procedure (Proc_Id);
1385 Set_Default_Init_Cond_Procedure (Typ, Proc_Id);
1387 -- Mark the default initial condition procedure explicitly as Ghost
1388 -- because it does not come from source.
1390 if Ghost_Mode > None then
1391 Set_Is_Ghost_Entity (Proc_Id);
1395 -- procedure <Typ>Default_Init_Cond (Inn : <Typ>);
1397 Insert_After_And_Analyze (Prag,
1398 Make_Subprogram_Declaration (Loc,
1400 Make_Procedure_Specification (Loc,
1401 Defining_Unit_Name => Proc_Id,
1402 Parameter_Specifications => New_List (
1403 Make_Parameter_Specification (Loc,
1404 Defining_Identifier => Make_Temporary (Loc, 'I'),
1405 Parameter_Type => New_Occurrence_Of (Typ, Loc))))));
1407 Ghost_Mode := Save_Ghost_Mode;
1408 end Build_Default_Init_Cond_Procedure_Declaration;
1410 ---------------------------
1411 -- Build_Default_Subtype --
1412 ---------------------------
1414 function Build_Default_Subtype
1416 N : Node_Id) return Entity_Id
1418 Loc : constant Source_Ptr := Sloc (N);
1422 -- The base type that is to be constrained by the defaults
1425 if not Has_Discriminants (T) or else Is_Constrained (T) then
1429 Bas := Base_Type (T);
1431 -- If T is non-private but its base type is private, this is the
1432 -- completion of a subtype declaration whose parent type is private
1433 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1434 -- are to be found in the full view of the base. Check that the private
1435 -- status of T and its base differ.
1437 if Is_Private_Type (Bas)
1438 and then not Is_Private_Type (T)
1439 and then Present (Full_View (Bas))
1441 Bas := Full_View (Bas);
1444 Disc := First_Discriminant (T);
1446 if No (Discriminant_Default_Value (Disc)) then
1451 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
1452 Constraints : constant List_Id := New_List;
1456 while Present (Disc) loop
1457 Append_To (Constraints,
1458 New_Copy_Tree (Discriminant_Default_Value (Disc)));
1459 Next_Discriminant (Disc);
1463 Make_Subtype_Declaration (Loc,
1464 Defining_Identifier => Act,
1465 Subtype_Indication =>
1466 Make_Subtype_Indication (Loc,
1467 Subtype_Mark => New_Occurrence_Of (Bas, Loc),
1469 Make_Index_Or_Discriminant_Constraint (Loc,
1470 Constraints => Constraints)));
1472 Insert_Action (N, Decl);
1474 -- If the context is a component declaration the subtype declaration
1475 -- will be analyzed when the enclosing type is frozen, otherwise do
1478 if Ekind (Current_Scope) /= E_Record_Type then
1484 end Build_Default_Subtype;
1486 --------------------------------------------
1487 -- Build_Discriminal_Subtype_Of_Component --
1488 --------------------------------------------
1490 function Build_Discriminal_Subtype_Of_Component
1491 (T : Entity_Id) return Node_Id
1493 Loc : constant Source_Ptr := Sloc (T);
1497 function Build_Discriminal_Array_Constraint return List_Id;
1498 -- If one or more of the bounds of the component depends on
1499 -- discriminants, build actual constraint using the discriminants
1502 function Build_Discriminal_Record_Constraint return List_Id;
1503 -- Similar to previous one, for discriminated components constrained by
1504 -- the discriminant of the enclosing object.
1506 ----------------------------------------
1507 -- Build_Discriminal_Array_Constraint --
1508 ----------------------------------------
1510 function Build_Discriminal_Array_Constraint return List_Id is
1511 Constraints : constant List_Id := New_List;
1519 Indx := First_Index (T);
1520 while Present (Indx) loop
1521 Old_Lo := Type_Low_Bound (Etype (Indx));
1522 Old_Hi := Type_High_Bound (Etype (Indx));
1524 if Denotes_Discriminant (Old_Lo) then
1525 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
1528 Lo := New_Copy_Tree (Old_Lo);
1531 if Denotes_Discriminant (Old_Hi) then
1532 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
1535 Hi := New_Copy_Tree (Old_Hi);
1538 Append (Make_Range (Loc, Lo, Hi), Constraints);
1543 end Build_Discriminal_Array_Constraint;
1545 -----------------------------------------
1546 -- Build_Discriminal_Record_Constraint --
1547 -----------------------------------------
1549 function Build_Discriminal_Record_Constraint return List_Id is
1550 Constraints : constant List_Id := New_List;
1555 D := First_Elmt (Discriminant_Constraint (T));
1556 while Present (D) loop
1557 if Denotes_Discriminant (Node (D)) then
1559 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
1561 D_Val := New_Copy_Tree (Node (D));
1564 Append (D_Val, Constraints);
1569 end Build_Discriminal_Record_Constraint;
1571 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1574 if Ekind (T) = E_Array_Subtype then
1575 Id := First_Index (T);
1576 while Present (Id) loop
1577 if Denotes_Discriminant (Type_Low_Bound (Etype (Id)))
1579 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
1581 return Build_Component_Subtype
1582 (Build_Discriminal_Array_Constraint, Loc, T);
1588 elsif Ekind (T) = E_Record_Subtype
1589 and then Has_Discriminants (T)
1590 and then not Has_Unknown_Discriminants (T)
1592 D := First_Elmt (Discriminant_Constraint (T));
1593 while Present (D) loop
1594 if Denotes_Discriminant (Node (D)) then
1595 return Build_Component_Subtype
1596 (Build_Discriminal_Record_Constraint, Loc, T);
1603 -- If none of the above, the actual and nominal subtypes are the same
1606 end Build_Discriminal_Subtype_Of_Component;
1608 ------------------------------
1609 -- Build_Elaboration_Entity --
1610 ------------------------------
1612 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
1613 Loc : constant Source_Ptr := Sloc (N);
1615 Elab_Ent : Entity_Id;
1617 procedure Set_Package_Name (Ent : Entity_Id);
1618 -- Given an entity, sets the fully qualified name of the entity in
1619 -- Name_Buffer, with components separated by double underscores. This
1620 -- is a recursive routine that climbs the scope chain to Standard.
1622 ----------------------
1623 -- Set_Package_Name --
1624 ----------------------
1626 procedure Set_Package_Name (Ent : Entity_Id) is
1628 if Scope (Ent) /= Standard_Standard then
1629 Set_Package_Name (Scope (Ent));
1632 Nam : constant String := Get_Name_String (Chars (Ent));
1634 Name_Buffer (Name_Len + 1) := '_';
1635 Name_Buffer (Name_Len + 2) := '_';
1636 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
1637 Name_Len := Name_Len + Nam'Length + 2;
1641 Get_Name_String (Chars (Ent));
1643 end Set_Package_Name;
1645 -- Start of processing for Build_Elaboration_Entity
1648 -- Ignore call if already constructed
1650 if Present (Elaboration_Entity (Spec_Id)) then
1653 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1654 -- no role in analysis.
1656 elsif ASIS_Mode then
1659 -- See if we need elaboration entity. We always need it for the dynamic
1660 -- elaboration model, since it is needed to properly generate the PE
1661 -- exception for access before elaboration.
1663 elsif Dynamic_Elaboration_Checks then
1666 -- For the static model, we don't need the elaboration counter if this
1667 -- unit is sure to have no elaboration code, since that means there
1668 -- is no elaboration unit to be called. Note that we can't just decide
1669 -- after the fact by looking to see whether there was elaboration code,
1670 -- because that's too late to make this decision.
1672 elsif Restriction_Active (No_Elaboration_Code) then
1675 -- Similarly, for the static model, we can skip the elaboration counter
1676 -- if we have the No_Multiple_Elaboration restriction, since for the
1677 -- static model, that's the only purpose of the counter (to avoid
1678 -- multiple elaboration).
1680 elsif Restriction_Active (No_Multiple_Elaboration) then
1684 -- Here we need the elaboration entity
1686 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1687 -- name with dots replaced by double underscore. We have to manually
1688 -- construct this name, since it will be elaborated in the outer scope,
1689 -- and thus will not have the unit name automatically prepended.
1691 Set_Package_Name (Spec_Id);
1692 Add_Str_To_Name_Buffer ("_E");
1694 -- Create elaboration counter
1696 Elab_Ent := Make_Defining_Identifier (Loc, Chars => Name_Find);
1697 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
1700 Make_Object_Declaration (Loc,
1701 Defining_Identifier => Elab_Ent,
1702 Object_Definition =>
1703 New_Occurrence_Of (Standard_Short_Integer, Loc),
1704 Expression => Make_Integer_Literal (Loc, Uint_0));
1706 Push_Scope (Standard_Standard);
1707 Add_Global_Declaration (Decl);
1710 -- Reset True_Constant indication, since we will indeed assign a value
1711 -- to the variable in the binder main. We also kill the Current_Value
1712 -- and Last_Assignment fields for the same reason.
1714 Set_Is_True_Constant (Elab_Ent, False);
1715 Set_Current_Value (Elab_Ent, Empty);
1716 Set_Last_Assignment (Elab_Ent, Empty);
1718 -- We do not want any further qualification of the name (if we did not
1719 -- do this, we would pick up the name of the generic package in the case
1720 -- of a library level generic instantiation).
1722 Set_Has_Qualified_Name (Elab_Ent);
1723 Set_Has_Fully_Qualified_Name (Elab_Ent);
1724 end Build_Elaboration_Entity;
1726 --------------------------------
1727 -- Build_Explicit_Dereference --
1728 --------------------------------
1730 procedure Build_Explicit_Dereference
1734 Loc : constant Source_Ptr := Sloc (Expr);
1739 -- An entity of a type with a reference aspect is overloaded with
1740 -- both interpretations: with and without the dereference. Now that
1741 -- the dereference is made explicit, set the type of the node properly,
1742 -- to prevent anomalies in the backend. Same if the expression is an
1743 -- overloaded function call whose return type has a reference aspect.
1745 if Is_Entity_Name (Expr) then
1746 Set_Etype (Expr, Etype (Entity (Expr)));
1748 elsif Nkind (Expr) = N_Function_Call then
1750 -- If the name of the indexing function is overloaded, locate the one
1751 -- whose return type has an implicit dereference on the desired
1752 -- discriminant, and set entity and type of function call.
1754 if Is_Overloaded (Name (Expr)) then
1755 Get_First_Interp (Name (Expr), I, It);
1757 while Present (It.Nam) loop
1758 if Ekind ((It.Typ)) = E_Record_Type
1759 and then First_Entity ((It.Typ)) = Disc
1761 Set_Entity (Name (Expr), It.Nam);
1762 Set_Etype (Name (Expr), Etype (It.Nam));
1766 Get_Next_Interp (I, It);
1770 -- Set type of call from resolved function name.
1772 Set_Etype (Expr, Etype (Name (Expr)));
1775 Set_Is_Overloaded (Expr, False);
1777 -- The expression will often be a generalized indexing that yields a
1778 -- container element that is then dereferenced, in which case the
1779 -- generalized indexing call is also non-overloaded.
1781 if Nkind (Expr) = N_Indexed_Component
1782 and then Present (Generalized_Indexing (Expr))
1784 Set_Is_Overloaded (Generalized_Indexing (Expr), False);
1788 Make_Explicit_Dereference (Loc,
1790 Make_Selected_Component (Loc,
1791 Prefix => Relocate_Node (Expr),
1792 Selector_Name => New_Occurrence_Of (Disc, Loc))));
1793 Set_Etype (Prefix (Expr), Etype (Disc));
1794 Set_Etype (Expr, Designated_Type (Etype (Disc)));
1795 end Build_Explicit_Dereference;
1797 -----------------------------------
1798 -- Cannot_Raise_Constraint_Error --
1799 -----------------------------------
1801 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
1803 if Compile_Time_Known_Value (Expr) then
1806 elsif Do_Range_Check (Expr) then
1809 elsif Raises_Constraint_Error (Expr) then
1813 case Nkind (Expr) is
1814 when N_Identifier =>
1817 when N_Expanded_Name =>
1820 when N_Selected_Component =>
1821 return not Do_Discriminant_Check (Expr);
1823 when N_Attribute_Reference =>
1824 if Do_Overflow_Check (Expr) then
1827 elsif No (Expressions (Expr)) then
1835 N := First (Expressions (Expr));
1836 while Present (N) loop
1837 if Cannot_Raise_Constraint_Error (N) then
1848 when N_Type_Conversion =>
1849 if Do_Overflow_Check (Expr)
1850 or else Do_Length_Check (Expr)
1851 or else Do_Tag_Check (Expr)
1855 return Cannot_Raise_Constraint_Error (Expression (Expr));
1858 when N_Unchecked_Type_Conversion =>
1859 return Cannot_Raise_Constraint_Error (Expression (Expr));
1862 if Do_Overflow_Check (Expr) then
1865 return Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1872 if Do_Division_Check (Expr)
1874 Do_Overflow_Check (Expr)
1879 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1881 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1900 N_Op_Shift_Right_Arithmetic |
1904 if Do_Overflow_Check (Expr) then
1908 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1910 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1917 end Cannot_Raise_Constraint_Error;
1919 -----------------------------
1920 -- Check_Part_Of_Reference --
1921 -----------------------------
1923 procedure Check_Part_Of_Reference (Var_Id : Entity_Id; Ref : Node_Id) is
1924 Conc_Typ : constant Entity_Id := Encapsulating_State (Var_Id);
1926 OK_Use : Boolean := False;
1929 Spec_Id : Entity_Id;
1932 -- Traverse the parent chain looking for a suitable context for the
1933 -- reference to the concurrent constituent.
1935 Par := Parent (Ref);
1936 while Present (Par) loop
1937 if Nkind (Par) = N_Pragma then
1938 Prag_Nam := Pragma_Name (Par);
1940 -- A concurrent constituent is allowed to appear in pragmas
1941 -- Initial_Condition and Initializes as this is part of the
1942 -- elaboration checks for the constituent (SPARK RM 9.3).
1944 if Nam_In (Prag_Nam, Name_Initial_Condition, Name_Initializes) then
1948 -- When the reference appears within pragma Depends or Global,
1949 -- check whether the pragma applies to a single task type. Note
1950 -- that the pragma is not encapsulated by the type definition,
1951 -- but this is still a valid context.
1953 elsif Nam_In (Prag_Nam, Name_Depends, Name_Global) then
1954 Decl := Find_Related_Declaration_Or_Body (Par);
1956 if Nkind (Decl) = N_Object_Declaration
1957 and then Defining_Entity (Decl) = Conc_Typ
1964 -- The reference appears somewhere in the definition of the single
1965 -- protected/task type (SPARK RM 9.3).
1967 elsif Nkind_In (Par, N_Single_Protected_Declaration,
1968 N_Single_Task_Declaration)
1969 and then Defining_Entity (Par) = Conc_Typ
1974 -- The reference appears within the expanded declaration or the body
1975 -- of the single protected/task type (SPARK RM 9.3).
1977 elsif Nkind_In (Par, N_Protected_Body,
1978 N_Protected_Type_Declaration,
1980 N_Task_Type_Declaration)
1982 Spec_Id := Unique_Defining_Entity (Par);
1984 if Present (Anonymous_Object (Spec_Id))
1985 and then Anonymous_Object (Spec_Id) = Conc_Typ
1991 -- The reference has been relocated within an internally generated
1992 -- package or subprogram. Assume that the reference is legal as the
1993 -- real check was already performed in the original context of the
1996 elsif Nkind_In (Par, N_Package_Body,
1997 N_Package_Declaration,
1999 N_Subprogram_Declaration)
2000 and then not Comes_From_Source (Par)
2005 -- The reference has been relocated to an inlined body for GNATprove.
2006 -- Assume that the reference is legal as the real check was already
2007 -- performed in the original context of the reference.
2009 elsif GNATprove_Mode
2010 and then Nkind (Par) = N_Subprogram_Body
2011 and then Chars (Defining_Entity (Par)) = Name_uParent
2017 Par := Parent (Par);
2020 -- The reference is illegal as it appears outside the definition or
2021 -- body of the single protected/task type.
2025 ("reference to variable & cannot appear in this context",
2027 Error_Msg_Name_1 := Chars (Var_Id);
2029 if Ekind (Conc_Typ) = E_Protected_Type then
2031 ("\% is constituent of single protected type &", Ref, Conc_Typ);
2034 ("\% is constituent of single task type &", Ref, Conc_Typ);
2037 end Check_Part_Of_Reference;
2039 -----------------------------------------
2040 -- Check_Dynamically_Tagged_Expression --
2041 -----------------------------------------
2043 procedure Check_Dynamically_Tagged_Expression
2046 Related_Nod : Node_Id)
2049 pragma Assert (Is_Tagged_Type (Typ));
2051 -- In order to avoid spurious errors when analyzing the expanded code,
2052 -- this check is done only for nodes that come from source and for
2053 -- actuals of generic instantiations.
2055 if (Comes_From_Source (Related_Nod)
2056 or else In_Generic_Actual (Expr))
2057 and then (Is_Class_Wide_Type (Etype (Expr))
2058 or else Is_Dynamically_Tagged (Expr))
2059 and then Is_Tagged_Type (Typ)
2060 and then not Is_Class_Wide_Type (Typ)
2062 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
2064 end Check_Dynamically_Tagged_Expression;
2066 --------------------------
2067 -- Check_Fully_Declared --
2068 --------------------------
2070 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
2072 if Ekind (T) = E_Incomplete_Type then
2074 -- Ada 2005 (AI-50217): If the type is available through a limited
2075 -- with_clause, verify that its full view has been analyzed.
2077 if From_Limited_With (T)
2078 and then Present (Non_Limited_View (T))
2079 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
2081 -- The non-limited view is fully declared
2087 ("premature usage of incomplete}", N, First_Subtype (T));
2090 -- Need comments for these tests ???
2092 elsif Has_Private_Component (T)
2093 and then not Is_Generic_Type (Root_Type (T))
2094 and then not In_Spec_Expression
2096 -- Special case: if T is the anonymous type created for a single
2097 -- task or protected object, use the name of the source object.
2099 if Is_Concurrent_Type (T)
2100 and then not Comes_From_Source (T)
2101 and then Nkind (N) = N_Object_Declaration
2104 ("type of& has incomplete component",
2105 N, Defining_Identifier (N));
2108 ("premature usage of incomplete}",
2109 N, First_Subtype (T));
2112 end Check_Fully_Declared;
2114 -------------------------------------------
2115 -- Check_Function_With_Address_Parameter --
2116 -------------------------------------------
2118 procedure Check_Function_With_Address_Parameter (Subp_Id : Entity_Id) is
2123 F := First_Formal (Subp_Id);
2124 while Present (F) loop
2127 if Is_Private_Type (T) and then Present (Full_View (T)) then
2131 if Is_Descendant_Of_Address (T) or else Is_Limited_Type (T) then
2132 Set_Is_Pure (Subp_Id, False);
2138 end Check_Function_With_Address_Parameter;
2140 -------------------------------------
2141 -- Check_Function_Writable_Actuals --
2142 -------------------------------------
2144 procedure Check_Function_Writable_Actuals (N : Node_Id) is
2145 Writable_Actuals_List : Elist_Id := No_Elist;
2146 Identifiers_List : Elist_Id := No_Elist;
2147 Aggr_Error_Node : Node_Id := Empty;
2148 Error_Node : Node_Id := Empty;
2150 procedure Collect_Identifiers (N : Node_Id);
2151 -- In a single traversal of subtree N collect in Writable_Actuals_List
2152 -- all the actuals of functions with writable actuals, and in the list
2153 -- Identifiers_List collect all the identifiers that are not actuals of
2154 -- functions with writable actuals. If a writable actual is referenced
2155 -- twice as writable actual then Error_Node is set to reference its
2156 -- second occurrence, the error is reported, and the tree traversal
2159 function Get_Function_Id (Call : Node_Id) return Entity_Id;
2160 -- Return the entity associated with the function call
2162 procedure Preanalyze_Without_Errors (N : Node_Id);
2163 -- Preanalyze N without reporting errors. Very dubious, you can't just
2164 -- go analyzing things more than once???
2166 -------------------------
2167 -- Collect_Identifiers --
2168 -------------------------
2170 procedure Collect_Identifiers (N : Node_Id) is
2172 function Check_Node (N : Node_Id) return Traverse_Result;
2173 -- Process a single node during the tree traversal to collect the
2174 -- writable actuals of functions and all the identifiers which are
2175 -- not writable actuals of functions.
2177 function Contains (List : Elist_Id; N : Node_Id) return Boolean;
2178 -- Returns True if List has a node whose Entity is Entity (N)
2180 -------------------------
2181 -- Check_Function_Call --
2182 -------------------------
2184 function Check_Node (N : Node_Id) return Traverse_Result is
2185 Is_Writable_Actual : Boolean := False;
2189 if Nkind (N) = N_Identifier then
2191 -- No analysis possible if the entity is not decorated
2193 if No (Entity (N)) then
2196 -- Don't collect identifiers of packages, called functions, etc
2198 elsif Ekind_In (Entity (N), E_Package,
2205 -- For rewritten nodes, continue the traversal in the original
2206 -- subtree. Needed to handle aggregates in original expressions
2207 -- extracted from the tree by Remove_Side_Effects.
2209 elsif Is_Rewrite_Substitution (N) then
2210 Collect_Identifiers (Original_Node (N));
2213 -- For now we skip aggregate discriminants, since they require
2214 -- performing the analysis in two phases to identify conflicts:
2215 -- first one analyzing discriminants and second one analyzing
2216 -- the rest of components (since at run time, discriminants are
2217 -- evaluated prior to components): too much computation cost
2218 -- to identify a corner case???
2220 elsif Nkind (Parent (N)) = N_Component_Association
2221 and then Nkind_In (Parent (Parent (N)),
2223 N_Extension_Aggregate)
2226 Choice : constant Node_Id := First (Choices (Parent (N)));
2229 if Ekind (Entity (N)) = E_Discriminant then
2232 elsif Expression (Parent (N)) = N
2233 and then Nkind (Choice) = N_Identifier
2234 and then Ekind (Entity (Choice)) = E_Discriminant
2240 -- Analyze if N is a writable actual of a function
2242 elsif Nkind (Parent (N)) = N_Function_Call then
2244 Call : constant Node_Id := Parent (N);
2249 Id := Get_Function_Id (Call);
2251 -- In case of previous error, no check is possible
2257 if Ekind_In (Id, E_Function, E_Generic_Function)
2258 and then Has_Out_Or_In_Out_Parameter (Id)
2260 Formal := First_Formal (Id);
2261 Actual := First_Actual (Call);
2262 while Present (Actual) and then Present (Formal) loop
2264 if Ekind_In (Formal, E_Out_Parameter,
2267 Is_Writable_Actual := True;
2273 Next_Formal (Formal);
2274 Next_Actual (Actual);
2280 if Is_Writable_Actual then
2282 -- Skip checking the error in non-elementary types since
2283 -- RM 6.4.1(6.15/3) is restricted to elementary types, but
2284 -- store this actual in Writable_Actuals_List since it is
2285 -- needed to perform checks on other constructs that have
2286 -- arbitrary order of evaluation (for example, aggregates).
2288 if not Is_Elementary_Type (Etype (N)) then
2289 if not Contains (Writable_Actuals_List, N) then
2290 Append_New_Elmt (N, To => Writable_Actuals_List);
2293 -- Second occurrence of an elementary type writable actual
2295 elsif Contains (Writable_Actuals_List, N) then
2297 -- Report the error on the second occurrence of the
2298 -- identifier. We cannot assume that N is the second
2299 -- occurrence (according to their location in the
2300 -- sources), since Traverse_Func walks through Field2
2301 -- last (see comment in the body of Traverse_Func).
2307 Elmt := First_Elmt (Writable_Actuals_List);
2308 while Present (Elmt)
2309 and then Entity (Node (Elmt)) /= Entity (N)
2314 if Sloc (N) > Sloc (Node (Elmt)) then
2317 Error_Node := Node (Elmt);
2321 ("value may be affected by call to & "
2322 & "because order of evaluation is arbitrary",
2327 -- First occurrence of a elementary type writable actual
2330 Append_New_Elmt (N, To => Writable_Actuals_List);
2334 if Identifiers_List = No_Elist then
2335 Identifiers_List := New_Elmt_List;
2338 Append_Unique_Elmt (N, Identifiers_List);
2351 N : Node_Id) return Boolean
2353 pragma Assert (Nkind (N) in N_Has_Entity);
2358 if List = No_Elist then
2362 Elmt := First_Elmt (List);
2363 while Present (Elmt) loop
2364 if Entity (Node (Elmt)) = Entity (N) then
2378 procedure Do_Traversal is new Traverse_Proc (Check_Node);
2379 -- The traversal procedure
2381 -- Start of processing for Collect_Identifiers
2384 if Present (Error_Node) then
2388 if Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
2393 end Collect_Identifiers;
2395 ---------------------
2396 -- Get_Function_Id --
2397 ---------------------
2399 function Get_Function_Id (Call : Node_Id) return Entity_Id is
2400 Nam : constant Node_Id := Name (Call);
2404 if Nkind (Nam) = N_Explicit_Dereference then
2406 pragma Assert (Ekind (Id) = E_Subprogram_Type);
2408 elsif Nkind (Nam) = N_Selected_Component then
2409 Id := Entity (Selector_Name (Nam));
2411 elsif Nkind (Nam) = N_Indexed_Component then
2412 Id := Entity (Selector_Name (Prefix (Nam)));
2419 end Get_Function_Id;
2421 -------------------------------
2422 -- Preanalyze_Without_Errors --
2423 -------------------------------
2425 procedure Preanalyze_Without_Errors (N : Node_Id) is
2426 Status : constant Boolean := Get_Ignore_Errors;
2428 Set_Ignore_Errors (True);
2430 Set_Ignore_Errors (Status);
2431 end Preanalyze_Without_Errors;
2433 -- Start of processing for Check_Function_Writable_Actuals
2436 -- The check only applies to Ada 2012 code on which Check_Actuals has
2437 -- been set, and only to constructs that have multiple constituents
2438 -- whose order of evaluation is not specified by the language.
2440 if Ada_Version < Ada_2012
2441 or else not Check_Actuals (N)
2442 or else (not (Nkind (N) in N_Op)
2443 and then not (Nkind (N) in N_Membership_Test)
2444 and then not Nkind_In (N, N_Range,
2446 N_Extension_Aggregate,
2447 N_Full_Type_Declaration,
2449 N_Procedure_Call_Statement,
2450 N_Entry_Call_Statement))
2451 or else (Nkind (N) = N_Full_Type_Declaration
2452 and then not Is_Record_Type (Defining_Identifier (N)))
2454 -- In addition, this check only applies to source code, not to code
2455 -- generated by constraint checks.
2457 or else not Comes_From_Source (N)
2462 -- If a construct C has two or more direct constituents that are names
2463 -- or expressions whose evaluation may occur in an arbitrary order, at
2464 -- least one of which contains a function call with an in out or out
2465 -- parameter, then the construct is legal only if: for each name N that
2466 -- is passed as a parameter of mode in out or out to some inner function
2467 -- call C2 (not including the construct C itself), there is no other
2468 -- name anywhere within a direct constituent of the construct C other
2469 -- than the one containing C2, that is known to refer to the same
2470 -- object (RM 6.4.1(6.17/3)).
2474 Collect_Identifiers (Low_Bound (N));
2475 Collect_Identifiers (High_Bound (N));
2477 when N_Op | N_Membership_Test =>
2482 Collect_Identifiers (Left_Opnd (N));
2484 if Present (Right_Opnd (N)) then
2485 Collect_Identifiers (Right_Opnd (N));
2488 if Nkind_In (N, N_In, N_Not_In)
2489 and then Present (Alternatives (N))
2491 Expr := First (Alternatives (N));
2492 while Present (Expr) loop
2493 Collect_Identifiers (Expr);
2500 when N_Full_Type_Declaration =>
2502 function Get_Record_Part (N : Node_Id) return Node_Id;
2503 -- Return the record part of this record type definition
2505 function Get_Record_Part (N : Node_Id) return Node_Id is
2506 Type_Def : constant Node_Id := Type_Definition (N);
2508 if Nkind (Type_Def) = N_Derived_Type_Definition then
2509 return Record_Extension_Part (Type_Def);
2513 end Get_Record_Part;
2516 Def_Id : Entity_Id := Defining_Identifier (N);
2517 Rec : Node_Id := Get_Record_Part (N);
2520 -- No need to perform any analysis if the record has no
2523 if No (Rec) or else No (Component_List (Rec)) then
2527 -- Collect the identifiers starting from the deepest
2528 -- derivation. Done to report the error in the deepest
2532 if Present (Component_List (Rec)) then
2533 Comp := First (Component_Items (Component_List (Rec)));
2534 while Present (Comp) loop
2535 if Nkind (Comp) = N_Component_Declaration
2536 and then Present (Expression (Comp))
2538 Collect_Identifiers (Expression (Comp));
2545 exit when No (Underlying_Type (Etype (Def_Id)))
2546 or else Base_Type (Underlying_Type (Etype (Def_Id)))
2549 Def_Id := Base_Type (Underlying_Type (Etype (Def_Id)));
2550 Rec := Get_Record_Part (Parent (Def_Id));
2554 when N_Subprogram_Call |
2555 N_Entry_Call_Statement =>
2557 Id : constant Entity_Id := Get_Function_Id (N);
2562 Formal := First_Formal (Id);
2563 Actual := First_Actual (N);
2564 while Present (Actual) and then Present (Formal) loop
2565 if Ekind_In (Formal, E_Out_Parameter,
2568 Collect_Identifiers (Actual);
2571 Next_Formal (Formal);
2572 Next_Actual (Actual);
2577 N_Extension_Aggregate =>
2581 Comp_Expr : Node_Id;
2584 -- Handle the N_Others_Choice of array aggregates with static
2585 -- bounds. There is no need to perform this analysis in
2586 -- aggregates without static bounds since we cannot evaluate
2587 -- if the N_Others_Choice covers several elements. There is
2588 -- no need to handle the N_Others choice of record aggregates
2589 -- since at this stage it has been already expanded by
2590 -- Resolve_Record_Aggregate.
2592 if Is_Array_Type (Etype (N))
2593 and then Nkind (N) = N_Aggregate
2594 and then Present (Aggregate_Bounds (N))
2595 and then Compile_Time_Known_Bounds (Etype (N))
2596 and then Expr_Value (High_Bound (Aggregate_Bounds (N)))
2598 Expr_Value (Low_Bound (Aggregate_Bounds (N)))
2601 Count_Components : Uint := Uint_0;
2602 Num_Components : Uint;
2603 Others_Assoc : Node_Id;
2604 Others_Choice : Node_Id := Empty;
2605 Others_Box_Present : Boolean := False;
2608 -- Count positional associations
2610 if Present (Expressions (N)) then
2611 Comp_Expr := First (Expressions (N));
2612 while Present (Comp_Expr) loop
2613 Count_Components := Count_Components + 1;
2618 -- Count the rest of elements and locate the N_Others
2621 Assoc := First (Component_Associations (N));
2622 while Present (Assoc) loop
2623 Choice := First (Choices (Assoc));
2624 while Present (Choice) loop
2625 if Nkind (Choice) = N_Others_Choice then
2626 Others_Assoc := Assoc;
2627 Others_Choice := Choice;
2628 Others_Box_Present := Box_Present (Assoc);
2630 -- Count several components
2632 elsif Nkind_In (Choice, N_Range,
2633 N_Subtype_Indication)
2634 or else (Is_Entity_Name (Choice)
2635 and then Is_Type (Entity (Choice)))
2640 Get_Index_Bounds (Choice, L, H);
2642 (Compile_Time_Known_Value (L)
2643 and then Compile_Time_Known_Value (H));
2646 + Expr_Value (H) - Expr_Value (L) + 1;
2649 -- Count single component. No other case available
2650 -- since we are handling an aggregate with static
2654 pragma Assert (Is_OK_Static_Expression (Choice)
2655 or else Nkind (Choice) = N_Identifier
2656 or else Nkind (Choice) = N_Integer_Literal);
2658 Count_Components := Count_Components + 1;
2668 Expr_Value (High_Bound (Aggregate_Bounds (N))) -
2669 Expr_Value (Low_Bound (Aggregate_Bounds (N))) + 1;
2671 pragma Assert (Count_Components <= Num_Components);
2673 -- Handle the N_Others choice if it covers several
2676 if Present (Others_Choice)
2677 and then (Num_Components - Count_Components) > 1
2679 if not Others_Box_Present then
2681 -- At this stage, if expansion is active, the
2682 -- expression of the others choice has not been
2683 -- analyzed. Hence we generate a duplicate and
2684 -- we analyze it silently to have available the
2685 -- minimum decoration required to collect the
2688 if not Expander_Active then
2689 Comp_Expr := Expression (Others_Assoc);
2692 New_Copy_Tree (Expression (Others_Assoc));
2693 Preanalyze_Without_Errors (Comp_Expr);
2696 Collect_Identifiers (Comp_Expr);
2698 if Writable_Actuals_List /= No_Elist then
2700 -- As suggested by Robert, at current stage we
2701 -- report occurrences of this case as warnings.
2704 ("writable function parameter may affect "
2705 & "value in other component because order "
2706 & "of evaluation is unspecified??",
2707 Node (First_Elmt (Writable_Actuals_List)));
2713 -- For an array aggregate, a discrete_choice_list that has
2714 -- a nonstatic range is considered as two or more separate
2715 -- occurrences of the expression (RM 6.4.1(20/3)).
2717 elsif Is_Array_Type (Etype (N))
2718 and then Nkind (N) = N_Aggregate
2719 and then Present (Aggregate_Bounds (N))
2720 and then not Compile_Time_Known_Bounds (Etype (N))
2722 -- Collect identifiers found in the dynamic bounds
2725 Count_Components : Natural := 0;
2726 Low, High : Node_Id;
2729 Assoc := First (Component_Associations (N));
2730 while Present (Assoc) loop
2731 Choice := First (Choices (Assoc));
2732 while Present (Choice) loop
2733 if Nkind_In (Choice, N_Range,
2734 N_Subtype_Indication)
2735 or else (Is_Entity_Name (Choice)
2736 and then Is_Type (Entity (Choice)))
2738 Get_Index_Bounds (Choice, Low, High);
2740 if not Compile_Time_Known_Value (Low) then
2741 Collect_Identifiers (Low);
2743 if No (Aggr_Error_Node) then
2744 Aggr_Error_Node := Low;
2748 if not Compile_Time_Known_Value (High) then
2749 Collect_Identifiers (High);
2751 if No (Aggr_Error_Node) then
2752 Aggr_Error_Node := High;
2756 -- The RM rule is violated if there is more than
2757 -- a single choice in a component association.
2760 Count_Components := Count_Components + 1;
2762 if No (Aggr_Error_Node)
2763 and then Count_Components > 1
2765 Aggr_Error_Node := Choice;
2768 if not Compile_Time_Known_Value (Choice) then
2769 Collect_Identifiers (Choice);
2781 -- Handle ancestor part of extension aggregates
2783 if Nkind (N) = N_Extension_Aggregate then
2784 Collect_Identifiers (Ancestor_Part (N));
2787 -- Handle positional associations
2789 if Present (Expressions (N)) then
2790 Comp_Expr := First (Expressions (N));
2791 while Present (Comp_Expr) loop
2792 if not Is_OK_Static_Expression (Comp_Expr) then
2793 Collect_Identifiers (Comp_Expr);
2800 -- Handle discrete associations
2802 if Present (Component_Associations (N)) then
2803 Assoc := First (Component_Associations (N));
2804 while Present (Assoc) loop
2806 if not Box_Present (Assoc) then
2807 Choice := First (Choices (Assoc));
2808 while Present (Choice) loop
2810 -- For now we skip discriminants since it requires
2811 -- performing the analysis in two phases: first one
2812 -- analyzing discriminants and second one analyzing
2813 -- the rest of components since discriminants are
2814 -- evaluated prior to components: too much extra
2815 -- work to detect a corner case???
2817 if Nkind (Choice) in N_Has_Entity
2818 and then Present (Entity (Choice))
2819 and then Ekind (Entity (Choice)) = E_Discriminant
2823 elsif Box_Present (Assoc) then
2827 if not Analyzed (Expression (Assoc)) then
2829 New_Copy_Tree (Expression (Assoc));
2830 Set_Parent (Comp_Expr, Parent (N));
2831 Preanalyze_Without_Errors (Comp_Expr);
2833 Comp_Expr := Expression (Assoc);
2836 Collect_Identifiers (Comp_Expr);
2852 -- No further action needed if we already reported an error
2854 if Present (Error_Node) then
2858 -- Check violation of RM 6.20/3 in aggregates
2860 if Present (Aggr_Error_Node)
2861 and then Writable_Actuals_List /= No_Elist
2864 ("value may be affected by call in other component because they "
2865 & "are evaluated in unspecified order",
2866 Node (First_Elmt (Writable_Actuals_List)));
2870 -- Check if some writable argument of a function is referenced
2872 if Writable_Actuals_List /= No_Elist
2873 and then Identifiers_List /= No_Elist
2880 Elmt_1 := First_Elmt (Writable_Actuals_List);
2881 while Present (Elmt_1) loop
2882 Elmt_2 := First_Elmt (Identifiers_List);
2883 while Present (Elmt_2) loop
2884 if Entity (Node (Elmt_1)) = Entity (Node (Elmt_2)) then
2885 case Nkind (Parent (Node (Elmt_2))) is
2887 N_Component_Association |
2888 N_Component_Declaration =>
2890 ("value may be affected by call in other "
2891 & "component because they are evaluated "
2892 & "in unspecified order",
2895 when N_In | N_Not_In =>
2897 ("value may be affected by call in other "
2898 & "alternative because they are evaluated "
2899 & "in unspecified order",
2904 ("value of actual may be affected by call in "
2905 & "other actual because they are evaluated "
2906 & "in unspecified order",
2918 end Check_Function_Writable_Actuals;
2920 --------------------------------
2921 -- Check_Implicit_Dereference --
2922 --------------------------------
2924 procedure Check_Implicit_Dereference (N : Node_Id; Typ : Entity_Id) is
2930 if Nkind (N) = N_Indexed_Component
2931 and then Present (Generalized_Indexing (N))
2933 Nam := Generalized_Indexing (N);
2938 if Ada_Version < Ada_2012
2939 or else not Has_Implicit_Dereference (Base_Type (Typ))
2943 elsif not Comes_From_Source (N)
2944 and then Nkind (N) /= N_Indexed_Component
2948 elsif Is_Entity_Name (Nam) and then Is_Type (Entity (Nam)) then
2952 Disc := First_Discriminant (Typ);
2953 while Present (Disc) loop
2954 if Has_Implicit_Dereference (Disc) then
2955 Desig := Designated_Type (Etype (Disc));
2956 Add_One_Interp (Nam, Disc, Desig);
2958 -- If the node is a generalized indexing, add interpretation
2959 -- to that node as well, for subsequent resolution.
2961 if Nkind (N) = N_Indexed_Component then
2962 Add_One_Interp (N, Disc, Desig);
2965 -- If the operation comes from a generic unit and the context
2966 -- is a selected component, the selector name may be global
2967 -- and set in the instance already. Remove the entity to
2968 -- force resolution of the selected component, and the
2969 -- generation of an explicit dereference if needed.
2972 and then Nkind (Parent (Nam)) = N_Selected_Component
2974 Set_Entity (Selector_Name (Parent (Nam)), Empty);
2980 Next_Discriminant (Disc);
2983 end Check_Implicit_Dereference;
2985 ----------------------------------
2986 -- Check_Internal_Protected_Use --
2987 ----------------------------------
2989 procedure Check_Internal_Protected_Use (N : Node_Id; Nam : Entity_Id) is
2995 while Present (S) loop
2996 if S = Standard_Standard then
2999 elsif Ekind (S) = E_Function
3000 and then Ekind (Scope (S)) = E_Protected_Type
3009 if Scope (Nam) = Prot and then Ekind (Nam) /= E_Function then
3011 -- An indirect function call (e.g. a callback within a protected
3012 -- function body) is not statically illegal. If the access type is
3013 -- anonymous and is the type of an access parameter, the scope of Nam
3014 -- will be the protected type, but it is not a protected operation.
3016 if Ekind (Nam) = E_Subprogram_Type
3018 Nkind (Associated_Node_For_Itype (Nam)) = N_Function_Specification
3022 elsif Nkind (N) = N_Subprogram_Renaming_Declaration then
3024 ("within protected function cannot use protected "
3025 & "procedure in renaming or as generic actual", N);
3027 elsif Nkind (N) = N_Attribute_Reference then
3029 ("within protected function cannot take access of "
3030 & " protected procedure", N);
3034 ("within protected function, protected object is constant", N);
3036 ("\cannot call operation that may modify it", N);
3039 end Check_Internal_Protected_Use;
3041 ---------------------------------------
3042 -- Check_Later_Vs_Basic_Declarations --
3043 ---------------------------------------
3045 procedure Check_Later_Vs_Basic_Declarations
3047 During_Parsing : Boolean)
3049 Body_Sloc : Source_Ptr;
3052 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
3053 -- Return whether Decl is considered as a declarative item.
3054 -- When During_Parsing is True, the semantics of Ada 83 is followed.
3055 -- When During_Parsing is False, the semantics of SPARK is followed.
3057 -------------------------------
3058 -- Is_Later_Declarative_Item --
3059 -------------------------------
3061 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
3063 if Nkind (Decl) in N_Later_Decl_Item then
3066 elsif Nkind (Decl) = N_Pragma then
3069 elsif During_Parsing then
3072 -- In SPARK, a package declaration is not considered as a later
3073 -- declarative item.
3075 elsif Nkind (Decl) = N_Package_Declaration then
3078 -- In SPARK, a renaming is considered as a later declarative item
3080 elsif Nkind (Decl) in N_Renaming_Declaration then
3086 end Is_Later_Declarative_Item;
3088 -- Start of processing for Check_Later_Vs_Basic_Declarations
3091 Decl := First (Decls);
3093 -- Loop through sequence of basic declarative items
3095 Outer : while Present (Decl) loop
3096 if not Nkind_In (Decl, N_Subprogram_Body, N_Package_Body, N_Task_Body)
3097 and then Nkind (Decl) not in N_Body_Stub
3101 -- Once a body is encountered, we only allow later declarative
3102 -- items. The inner loop checks the rest of the list.
3105 Body_Sloc := Sloc (Decl);
3107 Inner : while Present (Decl) loop
3108 if not Is_Later_Declarative_Item (Decl) then
3109 if During_Parsing then
3110 if Ada_Version = Ada_83 then
3111 Error_Msg_Sloc := Body_Sloc;
3113 ("(Ada 83) decl cannot appear after body#", Decl);
3116 Error_Msg_Sloc := Body_Sloc;
3117 Check_SPARK_05_Restriction
3118 ("decl cannot appear after body#", Decl);
3126 end Check_Later_Vs_Basic_Declarations;
3128 ---------------------------
3129 -- Check_No_Hidden_State --
3130 ---------------------------
3132 procedure Check_No_Hidden_State (Id : Entity_Id) is
3133 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean;
3134 -- Determine whether the entity of a package denoted by Pkg has a null
3137 -----------------------------
3138 -- Has_Null_Abstract_State --
3139 -----------------------------
3141 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean is
3142 States : constant Elist_Id := Abstract_States (Pkg);
3145 -- Check first available state of related package. A null abstract
3146 -- state always appears as the sole element of the state list.
3150 and then Is_Null_State (Node (First_Elmt (States)));
3151 end Has_Null_Abstract_State;
3155 Context : Entity_Id := Empty;
3156 Not_Visible : Boolean := False;
3159 -- Start of processing for Check_No_Hidden_State
3162 pragma Assert (Ekind_In (Id, E_Abstract_State, E_Variable));
3164 -- Find the proper context where the object or state appears
3167 while Present (Scop) loop
3170 -- Keep track of the context's visibility
3172 Not_Visible := Not_Visible or else In_Private_Part (Context);
3174 -- Prevent the search from going too far
3176 if Context = Standard_Standard then
3179 -- Objects and states that appear immediately within a subprogram or
3180 -- inside a construct nested within a subprogram do not introduce a
3181 -- hidden state. They behave as local variable declarations.
3183 elsif Is_Subprogram (Context) then
3186 -- When examining a package body, use the entity of the spec as it
3187 -- carries the abstract state declarations.
3189 elsif Ekind (Context) = E_Package_Body then
3190 Context := Spec_Entity (Context);
3193 -- Stop the traversal when a package subject to a null abstract state
3196 if Ekind_In (Context, E_Generic_Package, E_Package)
3197 and then Has_Null_Abstract_State (Context)
3202 Scop := Scope (Scop);
3205 -- At this point we know that there is at least one package with a null
3206 -- abstract state in visibility. Emit an error message unconditionally
3207 -- if the entity being processed is a state because the placement of the
3208 -- related package is irrelevant. This is not the case for objects as
3209 -- the intermediate context matters.
3211 if Present (Context)
3212 and then (Ekind (Id) = E_Abstract_State or else Not_Visible)
3214 Error_Msg_N ("cannot introduce hidden state &", Id);
3215 Error_Msg_NE ("\package & has null abstract state", Id, Context);
3217 end Check_No_Hidden_State;
3219 ----------------------------------------
3220 -- Check_Nonvolatile_Function_Profile --
3221 ----------------------------------------
3223 procedure Check_Nonvolatile_Function_Profile (Func_Id : Entity_Id) is
3227 -- Inspect all formal parameters
3229 Formal := First_Formal (Func_Id);
3230 while Present (Formal) loop
3231 if Is_Effectively_Volatile (Etype (Formal)) then
3233 ("nonvolatile function & cannot have a volatile parameter",
3237 Next_Formal (Formal);
3240 -- Inspect the return type
3242 if Is_Effectively_Volatile (Etype (Func_Id)) then
3244 ("nonvolatile function & cannot have a volatile return type",
3245 Result_Definition (Parent (Func_Id)), Func_Id);
3247 end Check_Nonvolatile_Function_Profile;
3249 ------------------------------------------
3250 -- Check_Potentially_Blocking_Operation --
3251 ------------------------------------------
3253 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
3257 -- N is one of the potentially blocking operations listed in 9.5.1(8).
3258 -- When pragma Detect_Blocking is active, the run time will raise
3259 -- Program_Error. Here we only issue a warning, since we generally
3260 -- support the use of potentially blocking operations in the absence
3263 -- Indirect blocking through a subprogram call cannot be diagnosed
3264 -- statically without interprocedural analysis, so we do not attempt
3267 S := Scope (Current_Scope);
3268 while Present (S) and then S /= Standard_Standard loop
3269 if Is_Protected_Type (S) then
3271 ("potentially blocking operation in protected operation??", N);
3277 end Check_Potentially_Blocking_Operation;
3279 ---------------------------------
3280 -- Check_Result_And_Post_State --
3281 ---------------------------------
3283 procedure Check_Result_And_Post_State (Subp_Id : Entity_Id) is
3284 procedure Check_Result_And_Post_State_In_Pragma
3286 Result_Seen : in out Boolean);
3287 -- Determine whether pragma Prag mentions attribute 'Result and whether
3288 -- the pragma contains an expression that evaluates differently in pre-
3289 -- and post-state. Prag is a [refined] postcondition or a contract-cases
3290 -- pragma. Result_Seen is set when the pragma mentions attribute 'Result
3292 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean;
3293 -- Determine whether subprogram Subp_Id contains at least one IN OUT
3294 -- formal parameter.
3296 -------------------------------------------
3297 -- Check_Result_And_Post_State_In_Pragma --
3298 -------------------------------------------
3300 procedure Check_Result_And_Post_State_In_Pragma
3302 Result_Seen : in out Boolean)
3304 procedure Check_Expression (Expr : Node_Id);
3305 -- Perform the 'Result and post-state checks on a given expression
3307 function Is_Function_Result (N : Node_Id) return Traverse_Result;
3308 -- Attempt to find attribute 'Result in a subtree denoted by N
3310 function Is_Trivial_Boolean (N : Node_Id) return Boolean;
3311 -- Determine whether source node N denotes "True" or "False"
3313 function Mentions_Post_State (N : Node_Id) return Boolean;
3314 -- Determine whether a subtree denoted by N mentions any construct
3315 -- that denotes a post-state.
3317 procedure Check_Function_Result is
3318 new Traverse_Proc (Is_Function_Result);
3320 ----------------------
3321 -- Check_Expression --
3322 ----------------------
3324 procedure Check_Expression (Expr : Node_Id) is
3326 if not Is_Trivial_Boolean (Expr) then
3327 Check_Function_Result (Expr);
3329 if not Mentions_Post_State (Expr) then
3330 if Pragma_Name (Prag) = Name_Contract_Cases then
3332 ("contract case does not check the outcome of calling "
3333 & "&?T?", Expr, Subp_Id);
3335 elsif Pragma_Name (Prag) = Name_Refined_Post then
3337 ("refined postcondition does not check the outcome of "
3338 & "calling &?T?", Prag, Subp_Id);
3342 ("postcondition does not check the outcome of calling "
3343 & "&?T?", Prag, Subp_Id);
3347 end Check_Expression;
3349 ------------------------
3350 -- Is_Function_Result --
3351 ------------------------
3353 function Is_Function_Result (N : Node_Id) return Traverse_Result is
3355 if Is_Attribute_Result (N) then
3356 Result_Seen := True;
3359 -- Continue the traversal
3364 end Is_Function_Result;
3366 ------------------------
3367 -- Is_Trivial_Boolean --
3368 ------------------------
3370 function Is_Trivial_Boolean (N : Node_Id) return Boolean is
3373 Comes_From_Source (N)
3374 and then Is_Entity_Name (N)
3375 and then (Entity (N) = Standard_True
3377 Entity (N) = Standard_False);
3378 end Is_Trivial_Boolean;
3380 -------------------------
3381 -- Mentions_Post_State --
3382 -------------------------
3384 function Mentions_Post_State (N : Node_Id) return Boolean is
3385 Post_State_Seen : Boolean := False;
3387 function Is_Post_State (N : Node_Id) return Traverse_Result;
3388 -- Attempt to find a construct that denotes a post-state. If this
3389 -- is the case, set flag Post_State_Seen.
3395 function Is_Post_State (N : Node_Id) return Traverse_Result is
3399 if Nkind_In (N, N_Explicit_Dereference, N_Function_Call) then
3400 Post_State_Seen := True;
3403 elsif Nkind_In (N, N_Expanded_Name, N_Identifier) then
3406 -- The entity may be modifiable through an implicit
3410 or else Ekind (Ent) in Assignable_Kind
3411 or else (Is_Access_Type (Etype (Ent))
3412 and then Nkind (Parent (N)) =
3413 N_Selected_Component)
3415 Post_State_Seen := True;
3419 elsif Nkind (N) = N_Attribute_Reference then
3420 if Attribute_Name (N) = Name_Old then
3423 elsif Attribute_Name (N) = Name_Result then
3424 Post_State_Seen := True;
3432 procedure Find_Post_State is new Traverse_Proc (Is_Post_State);
3434 -- Start of processing for Mentions_Post_State
3437 Find_Post_State (N);
3439 return Post_State_Seen;
3440 end Mentions_Post_State;
3444 Expr : constant Node_Id :=
3446 (First (Pragma_Argument_Associations (Prag)));
3447 Nam : constant Name_Id := Pragma_Name (Prag);
3450 -- Start of processing for Check_Result_And_Post_State_In_Pragma
3453 -- Examine all consequences
3455 if Nam = Name_Contract_Cases then
3456 CCase := First (Component_Associations (Expr));
3457 while Present (CCase) loop
3458 Check_Expression (Expression (CCase));
3463 -- Examine the expression of a postcondition
3465 else pragma Assert (Nam_In (Nam, Name_Postcondition,
3466 Name_Refined_Post));
3467 Check_Expression (Expr);
3469 end Check_Result_And_Post_State_In_Pragma;
3471 --------------------------
3472 -- Has_In_Out_Parameter --
3473 --------------------------
3475 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean is
3479 -- Traverse the formals looking for an IN OUT parameter
3481 Formal := First_Formal (Subp_Id);
3482 while Present (Formal) loop
3483 if Ekind (Formal) = E_In_Out_Parameter then
3487 Next_Formal (Formal);
3491 end Has_In_Out_Parameter;
3495 Items : constant Node_Id := Contract (Subp_Id);
3496 Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id);
3497 Case_Prag : Node_Id := Empty;
3498 Post_Prag : Node_Id := Empty;
3500 Seen_In_Case : Boolean := False;
3501 Seen_In_Post : Boolean := False;
3502 Spec_Id : Entity_Id;
3504 -- Start of processing for Check_Result_And_Post_State
3507 -- The lack of attribute 'Result or a post-state is classified as a
3508 -- suspicious contract. Do not perform the check if the corresponding
3509 -- swich is not set.
3511 if not Warn_On_Suspicious_Contract then
3514 -- Nothing to do if there is no contract
3516 elsif No (Items) then
3520 -- Retrieve the entity of the subprogram spec (if any)
3522 if Nkind (Subp_Decl) = N_Subprogram_Body
3523 and then Present (Corresponding_Spec (Subp_Decl))
3525 Spec_Id := Corresponding_Spec (Subp_Decl);
3527 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
3528 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
3530 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
3536 -- Examine all postconditions for attribute 'Result and a post-state
3538 Prag := Pre_Post_Conditions (Items);
3539 while Present (Prag) loop
3540 if Nam_In (Pragma_Name (Prag), Name_Postcondition,
3542 and then not Error_Posted (Prag)
3545 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Post);
3548 Prag := Next_Pragma (Prag);
3551 -- Examine the contract cases of the subprogram for attribute 'Result
3552 -- and a post-state.
3554 Prag := Contract_Test_Cases (Items);
3555 while Present (Prag) loop
3556 if Pragma_Name (Prag) = Name_Contract_Cases
3557 and then not Error_Posted (Prag)
3560 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Case);
3563 Prag := Next_Pragma (Prag);
3566 -- Do not emit any errors if the subprogram is not a function
3568 if not Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
3571 -- Regardless of whether the function has postconditions or contract
3572 -- cases, or whether they mention attribute 'Result, an IN OUT formal
3573 -- parameter is always treated as a result.
3575 elsif Has_In_Out_Parameter (Spec_Id) then
3578 -- The function has both a postcondition and contract cases and they do
3579 -- not mention attribute 'Result.
3581 elsif Present (Case_Prag)
3582 and then not Seen_In_Case
3583 and then Present (Post_Prag)
3584 and then not Seen_In_Post
3587 ("neither postcondition nor contract cases mention function "
3588 & "result?T?", Post_Prag);
3590 -- The function has contract cases only and they do not mention
3591 -- attribute 'Result.
3593 elsif Present (Case_Prag) and then not Seen_In_Case then
3594 Error_Msg_N ("contract cases do not mention result?T?", Case_Prag);
3596 -- The function has postconditions only and they do not mention
3597 -- attribute 'Result.
3599 elsif Present (Post_Prag) and then not Seen_In_Post then
3601 ("postcondition does not mention function result?T?", Post_Prag);
3603 end Check_Result_And_Post_State;
3605 ------------------------------
3606 -- Check_Unprotected_Access --
3607 ------------------------------
3609 procedure Check_Unprotected_Access
3613 Cont_Encl_Typ : Entity_Id;
3614 Pref_Encl_Typ : Entity_Id;
3616 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
3617 -- Check whether Obj is a private component of a protected object.
3618 -- Return the protected type where the component resides, Empty
3621 function Is_Public_Operation return Boolean;
3622 -- Verify that the enclosing operation is callable from outside the
3623 -- protected object, to minimize false positives.
3625 ------------------------------
3626 -- Enclosing_Protected_Type --
3627 ------------------------------
3629 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
3631 if Is_Entity_Name (Obj) then
3633 Ent : Entity_Id := Entity (Obj);
3636 -- The object can be a renaming of a private component, use
3637 -- the original record component.
3639 if Is_Prival (Ent) then
3640 Ent := Prival_Link (Ent);
3643 if Is_Protected_Type (Scope (Ent)) then
3649 -- For indexed and selected components, recursively check the prefix
3651 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
3652 return Enclosing_Protected_Type (Prefix (Obj));
3654 -- The object does not denote a protected component
3659 end Enclosing_Protected_Type;
3661 -------------------------
3662 -- Is_Public_Operation --
3663 -------------------------
3665 function Is_Public_Operation return Boolean is
3671 while Present (S) and then S /= Pref_Encl_Typ loop
3672 if Scope (S) = Pref_Encl_Typ then
3673 E := First_Entity (Pref_Encl_Typ);
3675 and then E /= First_Private_Entity (Pref_Encl_Typ)
3689 end Is_Public_Operation;
3691 -- Start of processing for Check_Unprotected_Access
3694 if Nkind (Expr) = N_Attribute_Reference
3695 and then Attribute_Name (Expr) = Name_Unchecked_Access
3697 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
3698 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
3700 -- Check whether we are trying to export a protected component to a
3701 -- context with an equal or lower access level.
3703 if Present (Pref_Encl_Typ)
3704 and then No (Cont_Encl_Typ)
3705 and then Is_Public_Operation
3706 and then Scope_Depth (Pref_Encl_Typ) >=
3707 Object_Access_Level (Context)
3710 ("??possible unprotected access to protected data", Expr);
3713 end Check_Unprotected_Access;
3715 ------------------------------
3716 -- Check_Unused_Body_States --
3717 ------------------------------
3719 procedure Check_Unused_Body_States (Body_Id : Entity_Id) is
3720 procedure Process_Refinement_Clause
3723 -- Inspect all constituents of refinement clause Clause and remove any
3724 -- matches from body state list States.
3726 procedure Report_Unused_Body_States (States : Elist_Id);
3727 -- Emit errors for each abstract state or object found in list States
3729 -------------------------------
3730 -- Process_Refinement_Clause --
3731 -------------------------------
3733 procedure Process_Refinement_Clause
3737 procedure Process_Constituent (Constit : Node_Id);
3738 -- Remove constituent Constit from body state list States
3740 -------------------------
3741 -- Process_Constituent --
3742 -------------------------
3744 procedure Process_Constituent (Constit : Node_Id) is
3745 Constit_Id : Entity_Id;
3748 -- Guard against illegal constituents. Only abstract states and
3749 -- objects can appear on the right hand side of a refinement.
3751 if Is_Entity_Name (Constit) then
3752 Constit_Id := Entity_Of (Constit);
3754 if Present (Constit_Id)
3755 and then Ekind_In (Constit_Id, E_Abstract_State,
3759 Remove (States, Constit_Id);
3762 end Process_Constituent;
3768 -- Start of processing for Process_Refinement_Clause
3771 if Nkind (Clause) = N_Component_Association then
3772 Constit := Expression (Clause);
3774 -- Multiple constituents appear as an aggregate
3776 if Nkind (Constit) = N_Aggregate then
3777 Constit := First (Expressions (Constit));
3778 while Present (Constit) loop
3779 Process_Constituent (Constit);
3783 -- Various forms of a single constituent
3786 Process_Constituent (Constit);
3789 end Process_Refinement_Clause;
3791 -------------------------------
3792 -- Report_Unused_Body_States --
3793 -------------------------------
3795 procedure Report_Unused_Body_States (States : Elist_Id) is
3796 Posted : Boolean := False;
3797 State_Elmt : Elmt_Id;
3798 State_Id : Entity_Id;
3801 if Present (States) then
3802 State_Elmt := First_Elmt (States);
3803 while Present (State_Elmt) loop
3804 State_Id := Node (State_Elmt);
3806 -- Constants are part of the hidden state of a package, but the
3807 -- compiler cannot determine whether they have variable input
3808 -- (SPARK RM 7.1.1(2)) and cannot classify them properly as a
3809 -- hidden state. Do not emit an error when a constant does not
3810 -- participate in a state refinement, even though it acts as a
3813 if Ekind (State_Id) = E_Constant then
3816 -- Generate an error message of the form:
3818 -- body of package ... has unused hidden states
3819 -- abstract state ... defined at ...
3820 -- variable ... defined at ...
3826 ("body of package & has unused hidden states", Body_Id);
3829 Error_Msg_Sloc := Sloc (State_Id);
3831 if Ekind (State_Id) = E_Abstract_State then
3833 ("\abstract state & defined #", Body_Id, State_Id);
3836 SPARK_Msg_NE ("\variable & defined #", Body_Id, State_Id);
3840 Next_Elmt (State_Elmt);
3843 end Report_Unused_Body_States;
3847 Prag : constant Node_Id := Get_Pragma (Body_Id, Pragma_Refined_State);
3848 Spec_Id : constant Entity_Id := Spec_Entity (Body_Id);
3852 -- Start of processing for Check_Unused_Body_States
3855 -- Inspect the clauses of pragma Refined_State and determine whether all
3856 -- visible states declared within the package body participate in the
3859 if Present (Prag) then
3860 Clause := Expression (Get_Argument (Prag, Spec_Id));
3861 States := Collect_Body_States (Body_Id);
3863 -- Multiple non-null state refinements appear as an aggregate
3865 if Nkind (Clause) = N_Aggregate then
3866 Clause := First (Component_Associations (Clause));
3867 while Present (Clause) loop
3868 Process_Refinement_Clause (Clause, States);
3872 -- Various forms of a single state refinement
3875 Process_Refinement_Clause (Clause, States);
3878 -- Ensure that all abstract states and objects declared in the
3879 -- package body state space are utilized as constituents.
3881 Report_Unused_Body_States (States);
3883 end Check_Unused_Body_States;
3885 -------------------------
3886 -- Collect_Body_States --
3887 -------------------------
3889 function Collect_Body_States (Body_Id : Entity_Id) return Elist_Id is
3890 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean;
3891 -- Determine whether object Obj_Id is a suitable visible state of a
3894 procedure Collect_Visible_States
3895 (Pack_Id : Entity_Id;
3896 States : in out Elist_Id);
3897 -- Gather the entities of all abstract states and objects declared in
3898 -- the visible state space of package Pack_Id.
3900 ----------------------------
3901 -- Collect_Visible_States --
3902 ----------------------------
3904 procedure Collect_Visible_States
3905 (Pack_Id : Entity_Id;
3906 States : in out Elist_Id)
3908 Item_Id : Entity_Id;
3911 -- Traverse the entity chain of the package and inspect all visible
3914 Item_Id := First_Entity (Pack_Id);
3915 while Present (Item_Id) and then not In_Private_Part (Item_Id) loop
3917 -- Do not consider internally generated items as those cannot be
3918 -- named and participate in refinement.
3920 if not Comes_From_Source (Item_Id) then
3923 elsif Ekind (Item_Id) = E_Abstract_State then
3924 Append_New_Elmt (Item_Id, States);
3926 elsif Ekind_In (Item_Id, E_Constant, E_Variable)
3927 and then Is_Visible_Object (Item_Id)
3929 Append_New_Elmt (Item_Id, States);
3931 -- Recursively gather the visible states of a nested package
3933 elsif Ekind (Item_Id) = E_Package then
3934 Collect_Visible_States (Item_Id, States);
3937 Next_Entity (Item_Id);
3939 end Collect_Visible_States;
3941 -----------------------
3942 -- Is_Visible_Object --
3943 -----------------------
3945 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean is
3947 -- Objects that map generic formals to their actuals are not visible
3948 -- from outside the generic instantiation.
3950 if Present (Corresponding_Generic_Association
3951 (Declaration_Node (Obj_Id)))
3955 -- Constituents of a single protected/task type act as components of
3956 -- the type and are not visible from outside the type.
3958 elsif Ekind (Obj_Id) = E_Variable
3959 and then Present (Encapsulating_State (Obj_Id))
3960 and then Is_Single_Concurrent_Object (Encapsulating_State (Obj_Id))
3967 end Is_Visible_Object;
3971 Body_Decl : constant Node_Id := Unit_Declaration_Node (Body_Id);
3973 Item_Id : Entity_Id;
3974 States : Elist_Id := No_Elist;
3976 -- Start of processing for Collect_Body_States
3979 -- Inspect the declarations of the body looking for source objects,
3980 -- packages and package instantiations. Note that even though this
3981 -- processing is very similar to Collect_Visible_States, a package
3982 -- body does not have a First/Next_Entity list.
3984 Decl := First (Declarations (Body_Decl));
3985 while Present (Decl) loop
3987 -- Capture source objects as internally generated temporaries cannot
3988 -- be named and participate in refinement.
3990 if Nkind (Decl) = N_Object_Declaration then
3991 Item_Id := Defining_Entity (Decl);
3993 if Comes_From_Source (Item_Id)
3994 and then Is_Visible_Object (Item_Id)
3996 Append_New_Elmt (Item_Id, States);
3999 -- Capture the visible abstract states and objects of a source
4000 -- package [instantiation].
4002 elsif Nkind (Decl) = N_Package_Declaration then
4003 Item_Id := Defining_Entity (Decl);
4005 if Comes_From_Source (Item_Id) then
4006 Collect_Visible_States (Item_Id, States);
4014 end Collect_Body_States;
4016 ------------------------
4017 -- Collect_Interfaces --
4018 ------------------------
4020 procedure Collect_Interfaces
4022 Ifaces_List : out Elist_Id;
4023 Exclude_Parents : Boolean := False;
4024 Use_Full_View : Boolean := True)
4026 procedure Collect (Typ : Entity_Id);
4027 -- Subsidiary subprogram used to traverse the whole list
4028 -- of directly and indirectly implemented interfaces
4034 procedure Collect (Typ : Entity_Id) is
4035 Ancestor : Entity_Id;
4043 -- Handle private types and subtypes
4046 and then Is_Private_Type (Typ)
4047 and then Present (Full_View (Typ))
4049 Full_T := Full_View (Typ);
4051 if Ekind (Full_T) = E_Record_Subtype then
4052 Full_T := Full_View (Etype (Typ));
4056 -- Include the ancestor if we are generating the whole list of
4057 -- abstract interfaces.
4059 if Etype (Full_T) /= Typ
4061 -- Protect the frontend against wrong sources. For example:
4064 -- type A is tagged null record;
4065 -- type B is new A with private;
4066 -- type C is new A with private;
4068 -- type B is new C with null record;
4069 -- type C is new B with null record;
4072 and then Etype (Full_T) /= T
4074 Ancestor := Etype (Full_T);
4077 if Is_Interface (Ancestor) and then not Exclude_Parents then
4078 Append_Unique_Elmt (Ancestor, Ifaces_List);
4082 -- Traverse the graph of ancestor interfaces
4084 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
4085 Id := First (Abstract_Interface_List (Full_T));
4086 while Present (Id) loop
4087 Iface := Etype (Id);
4089 -- Protect against wrong uses. For example:
4090 -- type I is interface;
4091 -- type O is tagged null record;
4092 -- type Wrong is new I and O with null record; -- ERROR
4094 if Is_Interface (Iface) then
4096 and then Etype (T) /= T
4097 and then Interface_Present_In_Ancestor (Etype (T), Iface)
4102 Append_Unique_Elmt (Iface, Ifaces_List);
4111 -- Start of processing for Collect_Interfaces
4114 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
4115 Ifaces_List := New_Elmt_List;
4117 end Collect_Interfaces;
4119 ----------------------------------
4120 -- Collect_Interface_Components --
4121 ----------------------------------
4123 procedure Collect_Interface_Components
4124 (Tagged_Type : Entity_Id;
4125 Components_List : out Elist_Id)
4127 procedure Collect (Typ : Entity_Id);
4128 -- Subsidiary subprogram used to climb to the parents
4134 procedure Collect (Typ : Entity_Id) is
4135 Tag_Comp : Entity_Id;
4136 Parent_Typ : Entity_Id;
4139 -- Handle private types
4141 if Present (Full_View (Etype (Typ))) then
4142 Parent_Typ := Full_View (Etype (Typ));
4144 Parent_Typ := Etype (Typ);
4147 if Parent_Typ /= Typ
4149 -- Protect the frontend against wrong sources. For example:
4152 -- type A is tagged null record;
4153 -- type B is new A with private;
4154 -- type C is new A with private;
4156 -- type B is new C with null record;
4157 -- type C is new B with null record;
4160 and then Parent_Typ /= Tagged_Type
4162 Collect (Parent_Typ);
4165 -- Collect the components containing tags of secondary dispatch
4168 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
4169 while Present (Tag_Comp) loop
4170 pragma Assert (Present (Related_Type (Tag_Comp)));
4171 Append_Elmt (Tag_Comp, Components_List);
4173 Tag_Comp := Next_Tag_Component (Tag_Comp);
4177 -- Start of processing for Collect_Interface_Components
4180 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
4181 and then Is_Tagged_Type (Tagged_Type));
4183 Components_List := New_Elmt_List;
4184 Collect (Tagged_Type);
4185 end Collect_Interface_Components;
4187 -----------------------------
4188 -- Collect_Interfaces_Info --
4189 -----------------------------
4191 procedure Collect_Interfaces_Info
4193 Ifaces_List : out Elist_Id;
4194 Components_List : out Elist_Id;
4195 Tags_List : out Elist_Id)
4197 Comps_List : Elist_Id;
4198 Comp_Elmt : Elmt_Id;
4199 Comp_Iface : Entity_Id;
4200 Iface_Elmt : Elmt_Id;
4203 function Search_Tag (Iface : Entity_Id) return Entity_Id;
4204 -- Search for the secondary tag associated with the interface type
4205 -- Iface that is implemented by T.
4211 function Search_Tag (Iface : Entity_Id) return Entity_Id is
4214 if not Is_CPP_Class (T) then
4215 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
4217 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
4221 and then Is_Tag (Node (ADT))
4222 and then Related_Type (Node (ADT)) /= Iface
4224 -- Skip secondary dispatch table referencing thunks to user
4225 -- defined primitives covered by this interface.
4227 pragma Assert (Has_Suffix (Node (ADT), 'P'));
4230 -- Skip secondary dispatch tables of Ada types
4232 if not Is_CPP_Class (T) then
4234 -- Skip secondary dispatch table referencing thunks to
4235 -- predefined primitives.
4237 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
4240 -- Skip secondary dispatch table referencing user-defined
4241 -- primitives covered by this interface.
4243 pragma Assert (Has_Suffix (Node (ADT), 'D'));
4246 -- Skip secondary dispatch table referencing predefined
4249 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
4254 pragma Assert (Is_Tag (Node (ADT)));
4258 -- Start of processing for Collect_Interfaces_Info
4261 Collect_Interfaces (T, Ifaces_List);
4262 Collect_Interface_Components (T, Comps_List);
4264 -- Search for the record component and tag associated with each
4265 -- interface type of T.
4267 Components_List := New_Elmt_List;
4268 Tags_List := New_Elmt_List;
4270 Iface_Elmt := First_Elmt (Ifaces_List);
4271 while Present (Iface_Elmt) loop
4272 Iface := Node (Iface_Elmt);
4274 -- Associate the primary tag component and the primary dispatch table
4275 -- with all the interfaces that are parents of T
4277 if Is_Ancestor (Iface, T, Use_Full_View => True) then
4278 Append_Elmt (First_Tag_Component (T), Components_List);
4279 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
4281 -- Otherwise search for the tag component and secondary dispatch
4285 Comp_Elmt := First_Elmt (Comps_List);
4286 while Present (Comp_Elmt) loop
4287 Comp_Iface := Related_Type (Node (Comp_Elmt));
4289 if Comp_Iface = Iface
4290 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
4292 Append_Elmt (Node (Comp_Elmt), Components_List);
4293 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
4297 Next_Elmt (Comp_Elmt);
4299 pragma Assert (Present (Comp_Elmt));
4302 Next_Elmt (Iface_Elmt);
4304 end Collect_Interfaces_Info;
4306 ---------------------
4307 -- Collect_Parents --
4308 ---------------------
4310 procedure Collect_Parents
4312 List : out Elist_Id;
4313 Use_Full_View : Boolean := True)
4315 Current_Typ : Entity_Id := T;
4316 Parent_Typ : Entity_Id;
4319 List := New_Elmt_List;
4321 -- No action if the if the type has no parents
4323 if T = Etype (T) then
4328 Parent_Typ := Etype (Current_Typ);
4330 if Is_Private_Type (Parent_Typ)
4331 and then Present (Full_View (Parent_Typ))
4332 and then Use_Full_View
4334 Parent_Typ := Full_View (Base_Type (Parent_Typ));
4337 Append_Elmt (Parent_Typ, List);
4339 exit when Parent_Typ = Current_Typ;
4340 Current_Typ := Parent_Typ;
4342 end Collect_Parents;
4344 ----------------------------------
4345 -- Collect_Primitive_Operations --
4346 ----------------------------------
4348 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
4349 B_Type : constant Entity_Id := Base_Type (T);
4350 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
4351 B_Scope : Entity_Id := Scope (B_Type);
4355 Is_Type_In_Pkg : Boolean;
4356 Formal_Derived : Boolean := False;
4359 function Match (E : Entity_Id) return Boolean;
4360 -- True if E's base type is B_Type, or E is of an anonymous access type
4361 -- and the base type of its designated type is B_Type.
4367 function Match (E : Entity_Id) return Boolean is
4368 Etyp : Entity_Id := Etype (E);
4371 if Ekind (Etyp) = E_Anonymous_Access_Type then
4372 Etyp := Designated_Type (Etyp);
4375 -- In Ada 2012 a primitive operation may have a formal of an
4376 -- incomplete view of the parent type.
4378 return Base_Type (Etyp) = B_Type
4380 (Ada_Version >= Ada_2012
4381 and then Ekind (Etyp) = E_Incomplete_Type
4382 and then Full_View (Etyp) = B_Type);
4385 -- Start of processing for Collect_Primitive_Operations
4388 -- For tagged types, the primitive operations are collected as they
4389 -- are declared, and held in an explicit list which is simply returned.
4391 if Is_Tagged_Type (B_Type) then
4392 return Primitive_Operations (B_Type);
4394 -- An untagged generic type that is a derived type inherits the
4395 -- primitive operations of its parent type. Other formal types only
4396 -- have predefined operators, which are not explicitly represented.
4398 elsif Is_Generic_Type (B_Type) then
4399 if Nkind (B_Decl) = N_Formal_Type_Declaration
4400 and then Nkind (Formal_Type_Definition (B_Decl)) =
4401 N_Formal_Derived_Type_Definition
4403 Formal_Derived := True;
4405 return New_Elmt_List;
4409 Op_List := New_Elmt_List;
4411 if B_Scope = Standard_Standard then
4412 if B_Type = Standard_String then
4413 Append_Elmt (Standard_Op_Concat, Op_List);
4415 elsif B_Type = Standard_Wide_String then
4416 Append_Elmt (Standard_Op_Concatw, Op_List);
4422 -- Locate the primitive subprograms of the type
4425 -- The primitive operations appear after the base type, except
4426 -- if the derivation happens within the private part of B_Scope
4427 -- and the type is a private type, in which case both the type
4428 -- and some primitive operations may appear before the base
4429 -- type, and the list of candidates starts after the type.
4431 if In_Open_Scopes (B_Scope)
4432 and then Scope (T) = B_Scope
4433 and then In_Private_Part (B_Scope)
4435 Id := Next_Entity (T);
4437 -- In Ada 2012, If the type has an incomplete partial view, there
4438 -- may be primitive operations declared before the full view, so
4439 -- we need to start scanning from the incomplete view, which is
4440 -- earlier on the entity chain.
4442 elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration
4443 and then Present (Incomplete_View (Parent (B_Type)))
4445 Id := Defining_Entity (Incomplete_View (Parent (B_Type)));
4447 -- If T is a derived from a type with an incomplete view declared
4448 -- elsewhere, that incomplete view is irrelevant, we want the
4449 -- operations in the scope of T.
4451 if Scope (Id) /= Scope (B_Type) then
4452 Id := Next_Entity (B_Type);
4456 Id := Next_Entity (B_Type);
4459 -- Set flag if this is a type in a package spec
4462 Is_Package_Or_Generic_Package (B_Scope)
4464 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
4467 while Present (Id) loop
4469 -- Test whether the result type or any of the parameter types of
4470 -- each subprogram following the type match that type when the
4471 -- type is declared in a package spec, is a derived type, or the
4472 -- subprogram is marked as primitive. (The Is_Primitive test is
4473 -- needed to find primitives of nonderived types in declarative
4474 -- parts that happen to override the predefined "=" operator.)
4476 -- Note that generic formal subprograms are not considered to be
4477 -- primitive operations and thus are never inherited.
4479 if Is_Overloadable (Id)
4480 and then (Is_Type_In_Pkg
4481 or else Is_Derived_Type (B_Type)
4482 or else Is_Primitive (Id))
4483 and then Nkind (Parent (Parent (Id)))
4484 not in N_Formal_Subprogram_Declaration
4492 Formal := First_Formal (Id);
4493 while Present (Formal) loop
4494 if Match (Formal) then
4499 Next_Formal (Formal);
4503 -- For a formal derived type, the only primitives are the ones
4504 -- inherited from the parent type. Operations appearing in the
4505 -- package declaration are not primitive for it.
4508 and then (not Formal_Derived or else Present (Alias (Id)))
4510 -- In the special case of an equality operator aliased to
4511 -- an overriding dispatching equality belonging to the same
4512 -- type, we don't include it in the list of primitives.
4513 -- This avoids inheriting multiple equality operators when
4514 -- deriving from untagged private types whose full type is
4515 -- tagged, which can otherwise cause ambiguities. Note that
4516 -- this should only happen for this kind of untagged parent
4517 -- type, since normally dispatching operations are inherited
4518 -- using the type's Primitive_Operations list.
4520 if Chars (Id) = Name_Op_Eq
4521 and then Is_Dispatching_Operation (Id)
4522 and then Present (Alias (Id))
4523 and then Present (Overridden_Operation (Alias (Id)))
4524 and then Base_Type (Etype (First_Entity (Id))) =
4525 Base_Type (Etype (First_Entity (Alias (Id))))
4529 -- Include the subprogram in the list of primitives
4532 Append_Elmt (Id, Op_List);
4539 -- For a type declared in System, some of its operations may
4540 -- appear in the target-specific extension to System.
4543 and then B_Scope = RTU_Entity (System)
4544 and then Present_System_Aux
4546 B_Scope := System_Aux_Id;
4547 Id := First_Entity (System_Aux_Id);
4553 end Collect_Primitive_Operations;
4555 -----------------------------------
4556 -- Compile_Time_Constraint_Error --
4557 -----------------------------------
4559 function Compile_Time_Constraint_Error
4562 Ent : Entity_Id := Empty;
4563 Loc : Source_Ptr := No_Location;
4564 Warn : Boolean := False) return Node_Id
4566 Msgc : String (1 .. Msg'Length + 3);
4567 -- Copy of message, with room for possible ?? or << and ! at end
4573 -- Start of processing for Compile_Time_Constraint_Error
4576 -- If this is a warning, convert it into an error if we are in code
4577 -- subject to SPARK_Mode being set ON.
4579 Error_Msg_Warn := SPARK_Mode /= On;
4581 -- A static constraint error in an instance body is not a fatal error.
4582 -- we choose to inhibit the message altogether, because there is no
4583 -- obvious node (for now) on which to post it. On the other hand the
4584 -- offending node must be replaced with a constraint_error in any case.
4586 -- No messages are generated if we already posted an error on this node
4588 if not Error_Posted (N) then
4589 if Loc /= No_Location then
4595 -- Copy message to Msgc, converting any ? in the message into
4596 -- < instead, so that we have an error in GNATprove mode.
4600 for J in 1 .. Msgl loop
4601 if Msg (J) = '?' and then (J = 1 or else Msg (J) /= ''') then
4604 Msgc (J) := Msg (J);
4608 -- Message is a warning, even in Ada 95 case
4610 if Msg (Msg'Last) = '?' or else Msg (Msg'Last) = '<' then
4613 -- In Ada 83, all messages are warnings. In the private part and
4614 -- the body of an instance, constraint_checks are only warnings.
4615 -- We also make this a warning if the Warn parameter is set.
4618 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
4626 elsif In_Instance_Not_Visible then
4633 -- Otherwise we have a real error message (Ada 95 static case)
4634 -- and we make this an unconditional message. Note that in the
4635 -- warning case we do not make the message unconditional, it seems
4636 -- quite reasonable to delete messages like this (about exceptions
4637 -- that will be raised) in dead code.
4645 -- One more test, skip the warning if the related expression is
4646 -- statically unevaluated, since we don't want to warn about what
4647 -- will happen when something is evaluated if it never will be
4650 if not Is_Statically_Unevaluated (N) then
4651 Error_Msg_Warn := SPARK_Mode /= On;
4653 if Present (Ent) then
4654 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
4656 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
4661 -- Check whether the context is an Init_Proc
4663 if Inside_Init_Proc then
4665 Conc_Typ : constant Entity_Id :=
4666 Corresponding_Concurrent_Type
4667 (Entity (Parameter_Type (First
4668 (Parameter_Specifications
4669 (Parent (Current_Scope))))));
4672 -- Don't complain if the corresponding concurrent type
4673 -- doesn't come from source (i.e. a single task/protected
4676 if Present (Conc_Typ)
4677 and then not Comes_From_Source (Conc_Typ)
4680 ("\& [<<", N, Standard_Constraint_Error, Eloc);
4683 if GNATprove_Mode then
4685 ("\& would have been raised for objects of this "
4686 & "type", N, Standard_Constraint_Error, Eloc);
4689 ("\& will be raised for objects of this type??",
4690 N, Standard_Constraint_Error, Eloc);
4696 Error_Msg_NEL ("\& [<<", N, Standard_Constraint_Error, Eloc);
4700 Error_Msg ("\static expression fails Constraint_Check", Eloc);
4701 Set_Error_Posted (N);
4707 end Compile_Time_Constraint_Error;
4709 -----------------------
4710 -- Conditional_Delay --
4711 -----------------------
4713 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
4715 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
4716 Set_Has_Delayed_Freeze (New_Ent);
4718 end Conditional_Delay;
4720 ----------------------------
4721 -- Contains_Refined_State --
4722 ----------------------------
4724 function Contains_Refined_State (Prag : Node_Id) return Boolean is
4725 function Has_State_In_Dependency (List : Node_Id) return Boolean;
4726 -- Determine whether a dependency list mentions a state with a visible
4729 function Has_State_In_Global (List : Node_Id) return Boolean;
4730 -- Determine whether a global list mentions a state with a visible
4733 function Is_Refined_State (Item : Node_Id) return Boolean;
4734 -- Determine whether Item is a reference to an abstract state with a
4735 -- visible refinement.
4737 -----------------------------
4738 -- Has_State_In_Dependency --
4739 -----------------------------
4741 function Has_State_In_Dependency (List : Node_Id) return Boolean is
4746 -- A null dependency list does not mention any states
4748 if Nkind (List) = N_Null then
4751 -- Dependency clauses appear as component associations of an
4754 elsif Nkind (List) = N_Aggregate
4755 and then Present (Component_Associations (List))
4757 Clause := First (Component_Associations (List));
4758 while Present (Clause) loop
4760 -- Inspect the outputs of a dependency clause
4762 Output := First (Choices (Clause));
4763 while Present (Output) loop
4764 if Is_Refined_State (Output) then
4771 -- Inspect the outputs of a dependency clause
4773 if Is_Refined_State (Expression (Clause)) then
4780 -- If we get here, then none of the dependency clauses mention a
4781 -- state with visible refinement.
4785 -- An illegal pragma managed to sneak in
4788 raise Program_Error;
4790 end Has_State_In_Dependency;
4792 -------------------------
4793 -- Has_State_In_Global --
4794 -------------------------
4796 function Has_State_In_Global (List : Node_Id) return Boolean is
4800 -- A null global list does not mention any states
4802 if Nkind (List) = N_Null then
4805 -- Simple global list or moded global list declaration
4807 elsif Nkind (List) = N_Aggregate then
4809 -- The declaration of a simple global list appear as a collection
4812 if Present (Expressions (List)) then
4813 Item := First (Expressions (List));
4814 while Present (Item) loop
4815 if Is_Refined_State (Item) then
4822 -- The declaration of a moded global list appears as a collection
4823 -- of component associations where individual choices denote
4827 Item := First (Component_Associations (List));
4828 while Present (Item) loop
4829 if Has_State_In_Global (Expression (Item)) then
4837 -- If we get here, then the simple/moded global list did not
4838 -- mention any states with a visible refinement.
4842 -- Single global item declaration
4844 elsif Is_Entity_Name (List) then
4845 return Is_Refined_State (List);
4847 -- An illegal pragma managed to sneak in
4850 raise Program_Error;
4852 end Has_State_In_Global;
4854 ----------------------
4855 -- Is_Refined_State --
4856 ----------------------
4858 function Is_Refined_State (Item : Node_Id) return Boolean is
4860 Item_Id : Entity_Id;
4863 if Nkind (Item) = N_Null then
4866 -- States cannot be subject to attribute 'Result. This case arises
4867 -- in dependency relations.
4869 elsif Nkind (Item) = N_Attribute_Reference
4870 and then Attribute_Name (Item) = Name_Result
4874 -- Multiple items appear as an aggregate. This case arises in
4875 -- dependency relations.
4877 elsif Nkind (Item) = N_Aggregate
4878 and then Present (Expressions (Item))
4880 Elmt := First (Expressions (Item));
4881 while Present (Elmt) loop
4882 if Is_Refined_State (Elmt) then
4889 -- If we get here, then none of the inputs or outputs reference a
4890 -- state with visible refinement.
4897 Item_Id := Entity_Of (Item);
4901 and then Ekind (Item_Id) = E_Abstract_State
4902 and then Has_Visible_Refinement (Item_Id);
4904 end Is_Refined_State;
4908 Arg : constant Node_Id :=
4909 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
4910 Nam : constant Name_Id := Pragma_Name (Prag);
4912 -- Start of processing for Contains_Refined_State
4915 if Nam = Name_Depends then
4916 return Has_State_In_Dependency (Arg);
4918 else pragma Assert (Nam = Name_Global);
4919 return Has_State_In_Global (Arg);
4921 end Contains_Refined_State;
4923 -------------------------
4924 -- Copy_Component_List --
4925 -------------------------
4927 function Copy_Component_List
4929 Loc : Source_Ptr) return List_Id
4932 Comps : constant List_Id := New_List;
4935 Comp := First_Component (Underlying_Type (R_Typ));
4936 while Present (Comp) loop
4937 if Comes_From_Source (Comp) then
4939 Comp_Decl : constant Node_Id := Declaration_Node (Comp);
4942 Make_Component_Declaration (Loc,
4943 Defining_Identifier =>
4944 Make_Defining_Identifier (Loc, Chars (Comp)),
4945 Component_Definition =>
4947 (Component_Definition (Comp_Decl), New_Sloc => Loc)));
4951 Next_Component (Comp);
4955 end Copy_Component_List;
4957 -------------------------
4958 -- Copy_Parameter_List --
4959 -------------------------
4961 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
4962 Loc : constant Source_Ptr := Sloc (Subp_Id);
4967 if No (First_Formal (Subp_Id)) then
4971 Formal := First_Formal (Subp_Id);
4972 while Present (Formal) loop
4974 Make_Parameter_Specification (Loc,
4975 Defining_Identifier =>
4976 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
4977 In_Present => In_Present (Parent (Formal)),
4978 Out_Present => Out_Present (Parent (Formal)),
4980 New_Occurrence_Of (Etype (Formal), Loc),
4982 New_Copy_Tree (Expression (Parent (Formal)))));
4984 Next_Formal (Formal);
4989 end Copy_Parameter_List;
4991 --------------------------
4992 -- Copy_Subprogram_Spec --
4993 --------------------------
4995 function Copy_Subprogram_Spec (Spec : Node_Id) return Node_Id is
4997 Formal_Spec : Node_Id;
5001 -- The structure of the original tree must be replicated without any
5002 -- alterations. Use New_Copy_Tree for this purpose.
5004 Result := New_Copy_Tree (Spec);
5006 -- Create a new entity for the defining unit name
5008 Def_Id := Defining_Unit_Name (Result);
5009 Set_Defining_Unit_Name (Result,
5010 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
5012 -- Create new entities for the formal parameters
5014 if Present (Parameter_Specifications (Result)) then
5015 Formal_Spec := First (Parameter_Specifications (Result));
5016 while Present (Formal_Spec) loop
5017 Def_Id := Defining_Identifier (Formal_Spec);
5018 Set_Defining_Identifier (Formal_Spec,
5019 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
5026 end Copy_Subprogram_Spec;
5028 --------------------------------
5029 -- Corresponding_Generic_Type --
5030 --------------------------------
5032 function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id is
5038 if not Is_Generic_Actual_Type (T) then
5041 -- If the actual is the actual of an enclosing instance, resolution
5042 -- was correct in the generic.
5044 elsif Nkind (Parent (T)) = N_Subtype_Declaration
5045 and then Is_Entity_Name (Subtype_Indication (Parent (T)))
5047 Is_Generic_Actual_Type (Entity (Subtype_Indication (Parent (T))))
5054 if Is_Wrapper_Package (Inst) then
5055 Inst := Related_Instance (Inst);
5060 (Specification (Unit_Declaration_Node (Inst)));
5062 -- Generic actual has the same name as the corresponding formal
5064 Typ := First_Entity (Gen);
5065 while Present (Typ) loop
5066 if Chars (Typ) = Chars (T) then
5075 end Corresponding_Generic_Type;
5077 --------------------
5078 -- Current_Entity --
5079 --------------------
5081 -- The currently visible definition for a given identifier is the
5082 -- one most chained at the start of the visibility chain, i.e. the
5083 -- one that is referenced by the Node_Id value of the name of the
5084 -- given identifier.
5086 function Current_Entity (N : Node_Id) return Entity_Id is
5088 return Get_Name_Entity_Id (Chars (N));
5091 -----------------------------
5092 -- Current_Entity_In_Scope --
5093 -----------------------------
5095 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
5097 CS : constant Entity_Id := Current_Scope;
5099 Transient_Case : constant Boolean := Scope_Is_Transient;
5102 E := Get_Name_Entity_Id (Chars (N));
5104 and then Scope (E) /= CS
5105 and then (not Transient_Case or else Scope (E) /= Scope (CS))
5111 end Current_Entity_In_Scope;
5117 function Current_Scope return Entity_Id is
5119 if Scope_Stack.Last = -1 then
5120 return Standard_Standard;
5123 C : constant Entity_Id :=
5124 Scope_Stack.Table (Scope_Stack.Last).Entity;
5129 return Standard_Standard;
5135 ------------------------
5136 -- Current_Subprogram --
5137 ------------------------
5139 function Current_Subprogram return Entity_Id is
5140 Scop : constant Entity_Id := Current_Scope;
5142 if Is_Subprogram_Or_Generic_Subprogram (Scop) then
5145 return Enclosing_Subprogram (Scop);
5147 end Current_Subprogram;
5149 ----------------------------------
5150 -- Deepest_Type_Access_Level --
5151 ----------------------------------
5153 function Deepest_Type_Access_Level (Typ : Entity_Id) return Uint is
5155 if Ekind (Typ) = E_Anonymous_Access_Type
5156 and then not Is_Local_Anonymous_Access (Typ)
5157 and then Nkind (Associated_Node_For_Itype (Typ)) = N_Object_Declaration
5159 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
5163 Scope_Depth (Enclosing_Dynamic_Scope
5164 (Defining_Identifier
5165 (Associated_Node_For_Itype (Typ))));
5167 -- For generic formal type, return Int'Last (infinite).
5168 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
5170 elsif Is_Generic_Type (Root_Type (Typ)) then
5171 return UI_From_Int (Int'Last);
5174 return Type_Access_Level (Typ);
5176 end Deepest_Type_Access_Level;
5178 ---------------------
5179 -- Defining_Entity --
5180 ---------------------
5182 function Defining_Entity
5184 Empty_On_Errors : Boolean := False) return Entity_Id
5186 Err : Entity_Id := Empty;
5190 when N_Abstract_Subprogram_Declaration |
5191 N_Expression_Function |
5192 N_Formal_Subprogram_Declaration |
5193 N_Generic_Package_Declaration |
5194 N_Generic_Subprogram_Declaration |
5195 N_Package_Declaration |
5197 N_Subprogram_Body_Stub |
5198 N_Subprogram_Declaration |
5199 N_Subprogram_Renaming_Declaration
5201 return Defining_Entity (Specification (N));
5203 when N_Component_Declaration |
5204 N_Defining_Program_Unit_Name |
5205 N_Discriminant_Specification |
5207 N_Entry_Declaration |
5208 N_Entry_Index_Specification |
5209 N_Exception_Declaration |
5210 N_Exception_Renaming_Declaration |
5211 N_Formal_Object_Declaration |
5212 N_Formal_Package_Declaration |
5213 N_Formal_Type_Declaration |
5214 N_Full_Type_Declaration |
5215 N_Implicit_Label_Declaration |
5216 N_Incomplete_Type_Declaration |
5217 N_Loop_Parameter_Specification |
5218 N_Number_Declaration |
5219 N_Object_Declaration |
5220 N_Object_Renaming_Declaration |
5221 N_Package_Body_Stub |
5222 N_Parameter_Specification |
5223 N_Private_Extension_Declaration |
5224 N_Private_Type_Declaration |
5226 N_Protected_Body_Stub |
5227 N_Protected_Type_Declaration |
5228 N_Single_Protected_Declaration |
5229 N_Single_Task_Declaration |
5230 N_Subtype_Declaration |
5233 N_Task_Type_Declaration
5235 return Defining_Identifier (N);
5238 return Defining_Entity (Proper_Body (N));
5240 when N_Function_Instantiation |
5241 N_Function_Specification |
5242 N_Generic_Function_Renaming_Declaration |
5243 N_Generic_Package_Renaming_Declaration |
5244 N_Generic_Procedure_Renaming_Declaration |
5246 N_Package_Instantiation |
5247 N_Package_Renaming_Declaration |
5248 N_Package_Specification |
5249 N_Procedure_Instantiation |
5250 N_Procedure_Specification
5253 Nam : constant Node_Id := Defining_Unit_Name (N);
5256 if Nkind (Nam) in N_Entity then
5259 -- For Error, make up a name and attach to declaration so we
5260 -- can continue semantic analysis.
5262 elsif Nam = Error then
5263 if Empty_On_Errors then
5266 Err := Make_Temporary (Sloc (N), 'T');
5267 Set_Defining_Unit_Name (N, Err);
5272 -- If not an entity, get defining identifier
5275 return Defining_Identifier (Nam);
5279 when N_Block_Statement |
5281 return Entity (Identifier (N));
5284 if Empty_On_Errors then
5287 raise Program_Error;
5291 end Defining_Entity;
5293 --------------------------
5294 -- Denotes_Discriminant --
5295 --------------------------
5297 function Denotes_Discriminant
5299 Check_Concurrent : Boolean := False) return Boolean
5304 if not Is_Entity_Name (N) or else No (Entity (N)) then
5310 -- If we are checking for a protected type, the discriminant may have
5311 -- been rewritten as the corresponding discriminal of the original type
5312 -- or of the corresponding concurrent record, depending on whether we
5313 -- are in the spec or body of the protected type.
5315 return Ekind (E) = E_Discriminant
5318 and then Ekind (E) = E_In_Parameter
5319 and then Present (Discriminal_Link (E))
5321 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
5323 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
5324 end Denotes_Discriminant;
5326 -------------------------
5327 -- Denotes_Same_Object --
5328 -------------------------
5330 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
5331 Obj1 : Node_Id := A1;
5332 Obj2 : Node_Id := A2;
5334 function Has_Prefix (N : Node_Id) return Boolean;
5335 -- Return True if N has attribute Prefix
5337 function Is_Renaming (N : Node_Id) return Boolean;
5338 -- Return true if N names a renaming entity
5340 function Is_Valid_Renaming (N : Node_Id) return Boolean;
5341 -- For renamings, return False if the prefix of any dereference within
5342 -- the renamed object_name is a variable, or any expression within the
5343 -- renamed object_name contains references to variables or calls on
5344 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
5350 function Has_Prefix (N : Node_Id) return Boolean is
5354 N_Attribute_Reference,
5356 N_Explicit_Dereference,
5357 N_Indexed_Component,
5359 N_Selected_Component,
5367 function Is_Renaming (N : Node_Id) return Boolean is
5369 return Is_Entity_Name (N)
5370 and then Present (Renamed_Entity (Entity (N)));
5373 -----------------------
5374 -- Is_Valid_Renaming --
5375 -----------------------
5377 function Is_Valid_Renaming (N : Node_Id) return Boolean is
5379 function Check_Renaming (N : Node_Id) return Boolean;
5380 -- Recursive function used to traverse all the prefixes of N
5382 function Check_Renaming (N : Node_Id) return Boolean is
5385 and then not Check_Renaming (Renamed_Entity (Entity (N)))
5390 if Nkind (N) = N_Indexed_Component then
5395 Indx := First (Expressions (N));
5396 while Present (Indx) loop
5397 if not Is_OK_Static_Expression (Indx) then
5406 if Has_Prefix (N) then
5408 P : constant Node_Id := Prefix (N);
5411 if Nkind (N) = N_Explicit_Dereference
5412 and then Is_Variable (P)
5416 elsif Is_Entity_Name (P)
5417 and then Ekind (Entity (P)) = E_Function
5421 elsif Nkind (P) = N_Function_Call then
5425 -- Recursion to continue traversing the prefix of the
5426 -- renaming expression
5428 return Check_Renaming (P);
5435 -- Start of processing for Is_Valid_Renaming
5438 return Check_Renaming (N);
5439 end Is_Valid_Renaming;
5441 -- Start of processing for Denotes_Same_Object
5444 -- Both names statically denote the same stand-alone object or parameter
5445 -- (RM 6.4.1(6.5/3))
5447 if Is_Entity_Name (Obj1)
5448 and then Is_Entity_Name (Obj2)
5449 and then Entity (Obj1) = Entity (Obj2)
5454 -- For renamings, the prefix of any dereference within the renamed
5455 -- object_name is not a variable, and any expression within the
5456 -- renamed object_name contains no references to variables nor
5457 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
5459 if Is_Renaming (Obj1) then
5460 if Is_Valid_Renaming (Obj1) then
5461 Obj1 := Renamed_Entity (Entity (Obj1));
5467 if Is_Renaming (Obj2) then
5468 if Is_Valid_Renaming (Obj2) then
5469 Obj2 := Renamed_Entity (Entity (Obj2));
5475 -- No match if not same node kind (such cases are handled by
5476 -- Denotes_Same_Prefix)
5478 if Nkind (Obj1) /= Nkind (Obj2) then
5481 -- After handling valid renamings, one of the two names statically
5482 -- denoted a renaming declaration whose renamed object_name is known
5483 -- to denote the same object as the other (RM 6.4.1(6.10/3))
5485 elsif Is_Entity_Name (Obj1) then
5486 if Is_Entity_Name (Obj2) then
5487 return Entity (Obj1) = Entity (Obj2);
5492 -- Both names are selected_components, their prefixes are known to
5493 -- denote the same object, and their selector_names denote the same
5494 -- component (RM 6.4.1(6.6/3)).
5496 elsif Nkind (Obj1) = N_Selected_Component then
5497 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
5499 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
5501 -- Both names are dereferences and the dereferenced names are known to
5502 -- denote the same object (RM 6.4.1(6.7/3))
5504 elsif Nkind (Obj1) = N_Explicit_Dereference then
5505 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
5507 -- Both names are indexed_components, their prefixes are known to denote
5508 -- the same object, and each of the pairs of corresponding index values
5509 -- are either both static expressions with the same static value or both
5510 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
5512 elsif Nkind (Obj1) = N_Indexed_Component then
5513 if not Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
5521 Indx1 := First (Expressions (Obj1));
5522 Indx2 := First (Expressions (Obj2));
5523 while Present (Indx1) loop
5525 -- Indexes must denote the same static value or same object
5527 if Is_OK_Static_Expression (Indx1) then
5528 if not Is_OK_Static_Expression (Indx2) then
5531 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
5535 elsif not Denotes_Same_Object (Indx1, Indx2) then
5547 -- Both names are slices, their prefixes are known to denote the same
5548 -- object, and the two slices have statically matching index constraints
5549 -- (RM 6.4.1(6.9/3))
5551 elsif Nkind (Obj1) = N_Slice
5552 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
5555 Lo1, Lo2, Hi1, Hi2 : Node_Id;
5558 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
5559 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
5561 -- Check whether bounds are statically identical. There is no
5562 -- attempt to detect partial overlap of slices.
5564 return Denotes_Same_Object (Lo1, Lo2)
5566 Denotes_Same_Object (Hi1, Hi2);
5569 -- In the recursion, literals appear as indexes
5571 elsif Nkind (Obj1) = N_Integer_Literal
5573 Nkind (Obj2) = N_Integer_Literal
5575 return Intval (Obj1) = Intval (Obj2);
5580 end Denotes_Same_Object;
5582 -------------------------
5583 -- Denotes_Same_Prefix --
5584 -------------------------
5586 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
5588 if Is_Entity_Name (A1) then
5589 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
5590 and then not Is_Access_Type (Etype (A1))
5592 return Denotes_Same_Object (A1, Prefix (A2))
5593 or else Denotes_Same_Prefix (A1, Prefix (A2));
5598 elsif Is_Entity_Name (A2) then
5599 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
5601 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
5603 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
5606 Root1, Root2 : Node_Id;
5607 Depth1, Depth2 : Int := 0;
5610 Root1 := Prefix (A1);
5611 while not Is_Entity_Name (Root1) loop
5613 (Root1, N_Selected_Component, N_Indexed_Component)
5617 Root1 := Prefix (Root1);
5620 Depth1 := Depth1 + 1;
5623 Root2 := Prefix (A2);
5624 while not Is_Entity_Name (Root2) loop
5625 if not Nkind_In (Root2, N_Selected_Component,
5626 N_Indexed_Component)
5630 Root2 := Prefix (Root2);
5633 Depth2 := Depth2 + 1;
5636 -- If both have the same depth and they do not denote the same
5637 -- object, they are disjoint and no warning is needed.
5639 if Depth1 = Depth2 then
5642 elsif Depth1 > Depth2 then
5643 Root1 := Prefix (A1);
5644 for J in 1 .. Depth1 - Depth2 - 1 loop
5645 Root1 := Prefix (Root1);
5648 return Denotes_Same_Object (Root1, A2);
5651 Root2 := Prefix (A2);
5652 for J in 1 .. Depth2 - Depth1 - 1 loop
5653 Root2 := Prefix (Root2);
5656 return Denotes_Same_Object (A1, Root2);
5663 end Denotes_Same_Prefix;
5665 ----------------------
5666 -- Denotes_Variable --
5667 ----------------------
5669 function Denotes_Variable (N : Node_Id) return Boolean is
5671 return Is_Variable (N) and then Paren_Count (N) = 0;
5672 end Denotes_Variable;
5674 -----------------------------
5675 -- Depends_On_Discriminant --
5676 -----------------------------
5678 function Depends_On_Discriminant (N : Node_Id) return Boolean is
5683 Get_Index_Bounds (N, L, H);
5684 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
5685 end Depends_On_Discriminant;
5687 -------------------------
5688 -- Designate_Same_Unit --
5689 -------------------------
5691 function Designate_Same_Unit
5693 Name2 : Node_Id) return Boolean
5695 K1 : constant Node_Kind := Nkind (Name1);
5696 K2 : constant Node_Kind := Nkind (Name2);
5698 function Prefix_Node (N : Node_Id) return Node_Id;
5699 -- Returns the parent unit name node of a defining program unit name
5700 -- or the prefix if N is a selected component or an expanded name.
5702 function Select_Node (N : Node_Id) return Node_Id;
5703 -- Returns the defining identifier node of a defining program unit
5704 -- name or the selector node if N is a selected component or an
5711 function Prefix_Node (N : Node_Id) return Node_Id is
5713 if Nkind (N) = N_Defining_Program_Unit_Name then
5724 function Select_Node (N : Node_Id) return Node_Id is
5726 if Nkind (N) = N_Defining_Program_Unit_Name then
5727 return Defining_Identifier (N);
5729 return Selector_Name (N);
5733 -- Start of processing for Designate_Same_Unit
5736 if Nkind_In (K1, N_Identifier, N_Defining_Identifier)
5738 Nkind_In (K2, N_Identifier, N_Defining_Identifier)
5740 return Chars (Name1) = Chars (Name2);
5742 elsif Nkind_In (K1, N_Expanded_Name,
5743 N_Selected_Component,
5744 N_Defining_Program_Unit_Name)
5746 Nkind_In (K2, N_Expanded_Name,
5747 N_Selected_Component,
5748 N_Defining_Program_Unit_Name)
5751 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
5753 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
5758 end Designate_Same_Unit;
5760 ------------------------------------------
5761 -- function Dynamic_Accessibility_Level --
5762 ------------------------------------------
5764 function Dynamic_Accessibility_Level (Expr : Node_Id) return Node_Id is
5766 Loc : constant Source_Ptr := Sloc (Expr);
5768 function Make_Level_Literal (Level : Uint) return Node_Id;
5769 -- Construct an integer literal representing an accessibility level
5770 -- with its type set to Natural.
5772 ------------------------
5773 -- Make_Level_Literal --
5774 ------------------------
5776 function Make_Level_Literal (Level : Uint) return Node_Id is
5777 Result : constant Node_Id := Make_Integer_Literal (Loc, Level);
5779 Set_Etype (Result, Standard_Natural);
5781 end Make_Level_Literal;
5783 -- Start of processing for Dynamic_Accessibility_Level
5786 if Is_Entity_Name (Expr) then
5789 if Present (Renamed_Object (E)) then
5790 return Dynamic_Accessibility_Level (Renamed_Object (E));
5793 if Is_Formal (E) or else Ekind_In (E, E_Variable, E_Constant) then
5794 if Present (Extra_Accessibility (E)) then
5795 return New_Occurrence_Of (Extra_Accessibility (E), Loc);
5800 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
5802 case Nkind (Expr) is
5804 -- For access discriminant, the level of the enclosing object
5806 when N_Selected_Component =>
5807 if Ekind (Entity (Selector_Name (Expr))) = E_Discriminant
5808 and then Ekind (Etype (Entity (Selector_Name (Expr)))) =
5809 E_Anonymous_Access_Type
5811 return Make_Level_Literal (Object_Access_Level (Expr));
5814 when N_Attribute_Reference =>
5815 case Get_Attribute_Id (Attribute_Name (Expr)) is
5817 -- For X'Access, the level of the prefix X
5819 when Attribute_Access =>
5820 return Make_Level_Literal
5821 (Object_Access_Level (Prefix (Expr)));
5823 -- Treat the unchecked attributes as library-level
5825 when Attribute_Unchecked_Access |
5826 Attribute_Unrestricted_Access =>
5827 return Make_Level_Literal (Scope_Depth (Standard_Standard));
5829 -- No other access-valued attributes
5832 raise Program_Error;
5837 -- Unimplemented: depends on context. As an actual parameter where
5838 -- formal type is anonymous, use
5839 -- Scope_Depth (Current_Scope) + 1.
5840 -- For other cases, see 3.10.2(14/3) and following. ???
5844 when N_Type_Conversion =>
5845 if not Is_Local_Anonymous_Access (Etype (Expr)) then
5847 -- Handle type conversions introduced for a rename of an
5848 -- Ada 2012 stand-alone object of an anonymous access type.
5850 return Dynamic_Accessibility_Level (Expression (Expr));
5857 return Make_Level_Literal (Type_Access_Level (Etype (Expr)));
5858 end Dynamic_Accessibility_Level;
5860 -----------------------------------
5861 -- Effective_Extra_Accessibility --
5862 -----------------------------------
5864 function Effective_Extra_Accessibility (Id : Entity_Id) return Entity_Id is
5866 if Present (Renamed_Object (Id))
5867 and then Is_Entity_Name (Renamed_Object (Id))
5869 return Effective_Extra_Accessibility (Entity (Renamed_Object (Id)));
5871 return Extra_Accessibility (Id);
5873 end Effective_Extra_Accessibility;
5875 -----------------------------
5876 -- Effective_Reads_Enabled --
5877 -----------------------------
5879 function Effective_Reads_Enabled (Id : Entity_Id) return Boolean is
5881 return Has_Enabled_Property (Id, Name_Effective_Reads);
5882 end Effective_Reads_Enabled;
5884 ------------------------------
5885 -- Effective_Writes_Enabled --
5886 ------------------------------
5888 function Effective_Writes_Enabled (Id : Entity_Id) return Boolean is
5890 return Has_Enabled_Property (Id, Name_Effective_Writes);
5891 end Effective_Writes_Enabled;
5893 ------------------------------
5894 -- Enclosing_Comp_Unit_Node --
5895 ------------------------------
5897 function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id is
5898 Current_Node : Node_Id;
5902 while Present (Current_Node)
5903 and then Nkind (Current_Node) /= N_Compilation_Unit
5905 Current_Node := Parent (Current_Node);
5908 if Nkind (Current_Node) /= N_Compilation_Unit then
5911 return Current_Node;
5913 end Enclosing_Comp_Unit_Node;
5915 --------------------------
5916 -- Enclosing_CPP_Parent --
5917 --------------------------
5919 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
5920 Parent_Typ : Entity_Id := Typ;
5923 while not Is_CPP_Class (Parent_Typ)
5924 and then Etype (Parent_Typ) /= Parent_Typ
5926 Parent_Typ := Etype (Parent_Typ);
5928 if Is_Private_Type (Parent_Typ) then
5929 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5933 pragma Assert (Is_CPP_Class (Parent_Typ));
5935 end Enclosing_CPP_Parent;
5937 ---------------------------
5938 -- Enclosing_Declaration --
5939 ---------------------------
5941 function Enclosing_Declaration (N : Node_Id) return Node_Id is
5942 Decl : Node_Id := N;
5945 while Present (Decl)
5946 and then not (Nkind (Decl) in N_Declaration
5948 Nkind (Decl) in N_Later_Decl_Item)
5950 Decl := Parent (Decl);
5954 end Enclosing_Declaration;
5956 ----------------------------
5957 -- Enclosing_Generic_Body --
5958 ----------------------------
5960 function Enclosing_Generic_Body
5961 (N : Node_Id) return Node_Id
5969 while Present (P) loop
5970 if Nkind (P) = N_Package_Body
5971 or else Nkind (P) = N_Subprogram_Body
5973 Spec := Corresponding_Spec (P);
5975 if Present (Spec) then
5976 Decl := Unit_Declaration_Node (Spec);
5978 if Nkind (Decl) = N_Generic_Package_Declaration
5979 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
5990 end Enclosing_Generic_Body;
5992 ----------------------------
5993 -- Enclosing_Generic_Unit --
5994 ----------------------------
5996 function Enclosing_Generic_Unit
5997 (N : Node_Id) return Node_Id
6005 while Present (P) loop
6006 if Nkind (P) = N_Generic_Package_Declaration
6007 or else Nkind (P) = N_Generic_Subprogram_Declaration
6011 elsif Nkind (P) = N_Package_Body
6012 or else Nkind (P) = N_Subprogram_Body
6014 Spec := Corresponding_Spec (P);
6016 if Present (Spec) then
6017 Decl := Unit_Declaration_Node (Spec);
6019 if Nkind (Decl) = N_Generic_Package_Declaration
6020 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
6031 end Enclosing_Generic_Unit;
6033 -------------------------------
6034 -- Enclosing_Lib_Unit_Entity --
6035 -------------------------------
6037 function Enclosing_Lib_Unit_Entity
6038 (E : Entity_Id := Current_Scope) return Entity_Id
6040 Unit_Entity : Entity_Id;
6043 -- Look for enclosing library unit entity by following scope links.
6044 -- Equivalent to, but faster than indexing through the scope stack.
6047 while (Present (Scope (Unit_Entity))
6048 and then Scope (Unit_Entity) /= Standard_Standard)
6049 and not Is_Child_Unit (Unit_Entity)
6051 Unit_Entity := Scope (Unit_Entity);
6055 end Enclosing_Lib_Unit_Entity;
6057 -----------------------------
6058 -- Enclosing_Lib_Unit_Node --
6059 -----------------------------
6061 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
6062 Encl_Unit : Node_Id;
6065 Encl_Unit := Enclosing_Comp_Unit_Node (N);
6066 while Present (Encl_Unit)
6067 and then Nkind (Unit (Encl_Unit)) = N_Subunit
6069 Encl_Unit := Library_Unit (Encl_Unit);
6073 end Enclosing_Lib_Unit_Node;
6075 -----------------------
6076 -- Enclosing_Package --
6077 -----------------------
6079 function Enclosing_Package (E : Entity_Id) return Entity_Id is
6080 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
6083 if Dynamic_Scope = Standard_Standard then
6084 return Standard_Standard;
6086 elsif Dynamic_Scope = Empty then
6089 elsif Ekind_In (Dynamic_Scope, E_Package, E_Package_Body,
6092 return Dynamic_Scope;
6095 return Enclosing_Package (Dynamic_Scope);
6097 end Enclosing_Package;
6099 -------------------------------------
6100 -- Enclosing_Package_Or_Subprogram --
6101 -------------------------------------
6103 function Enclosing_Package_Or_Subprogram (E : Entity_Id) return Entity_Id is
6108 while Present (S) loop
6109 if Is_Package_Or_Generic_Package (S)
6110 or else Ekind (S) = E_Package_Body
6114 elsif Is_Subprogram_Or_Generic_Subprogram (S)
6115 or else Ekind (S) = E_Subprogram_Body
6125 end Enclosing_Package_Or_Subprogram;
6127 --------------------------
6128 -- Enclosing_Subprogram --
6129 --------------------------
6131 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
6132 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
6135 if Dynamic_Scope = Standard_Standard then
6138 elsif Dynamic_Scope = Empty then
6141 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
6142 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
6144 elsif Ekind (Dynamic_Scope) = E_Block
6145 or else Ekind (Dynamic_Scope) = E_Return_Statement
6147 return Enclosing_Subprogram (Dynamic_Scope);
6149 elsif Ekind (Dynamic_Scope) = E_Task_Type then
6150 return Get_Task_Body_Procedure (Dynamic_Scope);
6152 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
6153 and then Present (Full_View (Dynamic_Scope))
6154 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
6156 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
6158 -- No body is generated if the protected operation is eliminated
6160 elsif Convention (Dynamic_Scope) = Convention_Protected
6161 and then not Is_Eliminated (Dynamic_Scope)
6162 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
6164 return Protected_Body_Subprogram (Dynamic_Scope);
6167 return Dynamic_Scope;
6169 end Enclosing_Subprogram;
6171 ------------------------
6172 -- Ensure_Freeze_Node --
6173 ------------------------
6175 procedure Ensure_Freeze_Node (E : Entity_Id) is
6178 if No (Freeze_Node (E)) then
6179 FN := Make_Freeze_Entity (Sloc (E));
6180 Set_Has_Delayed_Freeze (E);
6181 Set_Freeze_Node (E, FN);
6182 Set_Access_Types_To_Process (FN, No_Elist);
6183 Set_TSS_Elist (FN, No_Elist);
6186 end Ensure_Freeze_Node;
6192 procedure Enter_Name (Def_Id : Entity_Id) is
6193 C : constant Entity_Id := Current_Entity (Def_Id);
6194 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
6195 S : constant Entity_Id := Current_Scope;
6198 Generate_Definition (Def_Id);
6200 -- Add new name to current scope declarations. Check for duplicate
6201 -- declaration, which may or may not be a genuine error.
6205 -- Case of previous entity entered because of a missing declaration
6206 -- or else a bad subtype indication. Best is to use the new entity,
6207 -- and make the previous one invisible.
6209 if Etype (E) = Any_Type then
6210 Set_Is_Immediately_Visible (E, False);
6212 -- Case of renaming declaration constructed for package instances.
6213 -- if there is an explicit declaration with the same identifier,
6214 -- the renaming is not immediately visible any longer, but remains
6215 -- visible through selected component notation.
6217 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
6218 and then not Comes_From_Source (E)
6220 Set_Is_Immediately_Visible (E, False);
6222 -- The new entity may be the package renaming, which has the same
6223 -- same name as a generic formal which has been seen already.
6225 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
6226 and then not Comes_From_Source (Def_Id)
6228 Set_Is_Immediately_Visible (E, False);
6230 -- For a fat pointer corresponding to a remote access to subprogram,
6231 -- we use the same identifier as the RAS type, so that the proper
6232 -- name appears in the stub. This type is only retrieved through
6233 -- the RAS type and never by visibility, and is not added to the
6234 -- visibility list (see below).
6236 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
6237 and then Ekind (Def_Id) = E_Record_Type
6238 and then Present (Corresponding_Remote_Type (Def_Id))
6242 -- Case of an implicit operation or derived literal. The new entity
6243 -- hides the implicit one, which is removed from all visibility,
6244 -- i.e. the entity list of its scope, and homonym chain of its name.
6246 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
6247 or else Is_Internal (E)
6251 Prev_Vis : Entity_Id;
6252 Decl : constant Node_Id := Parent (E);
6255 -- If E is an implicit declaration, it cannot be the first
6256 -- entity in the scope.
6258 Prev := First_Entity (Current_Scope);
6259 while Present (Prev) and then Next_Entity (Prev) /= E loop
6265 -- If E is not on the entity chain of the current scope,
6266 -- it is an implicit declaration in the generic formal
6267 -- part of a generic subprogram. When analyzing the body,
6268 -- the generic formals are visible but not on the entity
6269 -- chain of the subprogram. The new entity will become
6270 -- the visible one in the body.
6273 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
6277 Set_Next_Entity (Prev, Next_Entity (E));
6279 if No (Next_Entity (Prev)) then
6280 Set_Last_Entity (Current_Scope, Prev);
6283 if E = Current_Entity (E) then
6287 Prev_Vis := Current_Entity (E);
6288 while Homonym (Prev_Vis) /= E loop
6289 Prev_Vis := Homonym (Prev_Vis);
6293 if Present (Prev_Vis) then
6295 -- Skip E in the visibility chain
6297 Set_Homonym (Prev_Vis, Homonym (E));
6300 Set_Name_Entity_Id (Chars (E), Homonym (E));
6305 -- This section of code could use a comment ???
6307 elsif Present (Etype (E))
6308 and then Is_Concurrent_Type (Etype (E))
6313 -- If the homograph is a protected component renaming, it should not
6314 -- be hiding the current entity. Such renamings are treated as weak
6317 elsif Is_Prival (E) then
6318 Set_Is_Immediately_Visible (E, False);
6320 -- In this case the current entity is a protected component renaming.
6321 -- Perform minimal decoration by setting the scope and return since
6322 -- the prival should not be hiding other visible entities.
6324 elsif Is_Prival (Def_Id) then
6325 Set_Scope (Def_Id, Current_Scope);
6328 -- Analogous to privals, the discriminal generated for an entry index
6329 -- parameter acts as a weak declaration. Perform minimal decoration
6330 -- to avoid bogus errors.
6332 elsif Is_Discriminal (Def_Id)
6333 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
6335 Set_Scope (Def_Id, Current_Scope);
6338 -- In the body or private part of an instance, a type extension may
6339 -- introduce a component with the same name as that of an actual. The
6340 -- legality rule is not enforced, but the semantics of the full type
6341 -- with two components of same name are not clear at this point???
6343 elsif In_Instance_Not_Visible then
6346 -- When compiling a package body, some child units may have become
6347 -- visible. They cannot conflict with local entities that hide them.
6349 elsif Is_Child_Unit (E)
6350 and then In_Open_Scopes (Scope (E))
6351 and then not Is_Immediately_Visible (E)
6355 -- Conversely, with front-end inlining we may compile the parent body
6356 -- first, and a child unit subsequently. The context is now the
6357 -- parent spec, and body entities are not visible.
6359 elsif Is_Child_Unit (Def_Id)
6360 and then Is_Package_Body_Entity (E)
6361 and then not In_Package_Body (Current_Scope)
6365 -- Case of genuine duplicate declaration
6368 Error_Msg_Sloc := Sloc (E);
6370 -- If the previous declaration is an incomplete type declaration
6371 -- this may be an attempt to complete it with a private type. The
6372 -- following avoids confusing cascaded errors.
6374 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
6375 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
6378 ("incomplete type cannot be completed with a private " &
6379 "declaration", Parent (Def_Id));
6380 Set_Is_Immediately_Visible (E, False);
6381 Set_Full_View (E, Def_Id);
6383 -- An inherited component of a record conflicts with a new
6384 -- discriminant. The discriminant is inserted first in the scope,
6385 -- but the error should be posted on it, not on the component.
6387 elsif Ekind (E) = E_Discriminant
6388 and then Present (Scope (Def_Id))
6389 and then Scope (Def_Id) /= Current_Scope
6391 Error_Msg_Sloc := Sloc (Def_Id);
6392 Error_Msg_N ("& conflicts with declaration#", E);
6395 -- If the name of the unit appears in its own context clause, a
6396 -- dummy package with the name has already been created, and the
6397 -- error emitted. Try to continue quietly.
6399 elsif Error_Posted (E)
6400 and then Sloc (E) = No_Location
6401 and then Nkind (Parent (E)) = N_Package_Specification
6402 and then Current_Scope = Standard_Standard
6404 Set_Scope (Def_Id, Current_Scope);
6408 Error_Msg_N ("& conflicts with declaration#", Def_Id);
6410 -- Avoid cascaded messages with duplicate components in
6413 if Ekind_In (E, E_Component, E_Discriminant) then
6418 if Nkind (Parent (Parent (Def_Id))) =
6419 N_Generic_Subprogram_Declaration
6421 Defining_Entity (Specification (Parent (Parent (Def_Id))))
6423 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
6426 -- If entity is in standard, then we are in trouble, because it
6427 -- means that we have a library package with a duplicated name.
6428 -- That's hard to recover from, so abort.
6430 if S = Standard_Standard then
6431 raise Unrecoverable_Error;
6433 -- Otherwise we continue with the declaration. Having two
6434 -- identical declarations should not cause us too much trouble.
6442 -- If we fall through, declaration is OK, at least OK enough to continue
6444 -- If Def_Id is a discriminant or a record component we are in the midst
6445 -- of inheriting components in a derived record definition. Preserve
6446 -- their Ekind and Etype.
6448 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
6451 -- If a type is already set, leave it alone (happens when a type
6452 -- declaration is reanalyzed following a call to the optimizer).
6454 elsif Present (Etype (Def_Id)) then
6457 -- Otherwise, the kind E_Void insures that premature uses of the entity
6458 -- will be detected. Any_Type insures that no cascaded errors will occur
6461 Set_Ekind (Def_Id, E_Void);
6462 Set_Etype (Def_Id, Any_Type);
6465 -- Inherited discriminants and components in derived record types are
6466 -- immediately visible. Itypes are not.
6468 -- Unless the Itype is for a record type with a corresponding remote
6469 -- type (what is that about, it was not commented ???)
6471 if Ekind_In (Def_Id, E_Discriminant, E_Component)
6473 ((not Is_Record_Type (Def_Id)
6474 or else No (Corresponding_Remote_Type (Def_Id)))
6475 and then not Is_Itype (Def_Id))
6477 Set_Is_Immediately_Visible (Def_Id);
6478 Set_Current_Entity (Def_Id);
6481 Set_Homonym (Def_Id, C);
6482 Append_Entity (Def_Id, S);
6483 Set_Public_Status (Def_Id);
6485 -- Declaring a homonym is not allowed in SPARK ...
6487 if Present (C) and then Restriction_Check_Required (SPARK_05) then
6489 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
6490 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
6491 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
6494 -- ... unless the new declaration is in a subprogram, and the
6495 -- visible declaration is a variable declaration or a parameter
6496 -- specification outside that subprogram.
6498 if Present (Enclosing_Subp)
6499 and then Nkind_In (Parent (C), N_Object_Declaration,
6500 N_Parameter_Specification)
6501 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
6505 -- ... or the new declaration is in a package, and the visible
6506 -- declaration occurs outside that package.
6508 elsif Present (Enclosing_Pack)
6509 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
6513 -- ... or the new declaration is a component declaration in a
6514 -- record type definition.
6516 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
6519 -- Don't issue error for non-source entities
6521 elsif Comes_From_Source (Def_Id)
6522 and then Comes_From_Source (C)
6524 Error_Msg_Sloc := Sloc (C);
6525 Check_SPARK_05_Restriction
6526 ("redeclaration of identifier &#", Def_Id);
6531 -- Warn if new entity hides an old one
6533 if Warn_On_Hiding and then Present (C)
6535 -- Don't warn for record components since they always have a well
6536 -- defined scope which does not confuse other uses. Note that in
6537 -- some cases, Ekind has not been set yet.
6539 and then Ekind (C) /= E_Component
6540 and then Ekind (C) /= E_Discriminant
6541 and then Nkind (Parent (C)) /= N_Component_Declaration
6542 and then Ekind (Def_Id) /= E_Component
6543 and then Ekind (Def_Id) /= E_Discriminant
6544 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
6546 -- Don't warn for one character variables. It is too common to use
6547 -- such variables as locals and will just cause too many false hits.
6549 and then Length_Of_Name (Chars (C)) /= 1
6551 -- Don't warn for non-source entities
6553 and then Comes_From_Source (C)
6554 and then Comes_From_Source (Def_Id)
6556 -- Don't warn unless entity in question is in extended main source
6558 and then In_Extended_Main_Source_Unit (Def_Id)
6560 -- Finally, the hidden entity must be either immediately visible or
6561 -- use visible (i.e. from a used package).
6564 (Is_Immediately_Visible (C)
6566 Is_Potentially_Use_Visible (C))
6568 Error_Msg_Sloc := Sloc (C);
6569 Error_Msg_N ("declaration hides &#?h?", Def_Id);
6577 function Entity_Of (N : Node_Id) return Entity_Id is
6583 if Is_Entity_Name (N) then
6586 -- Follow a possible chain of renamings to reach the root renamed
6590 and then Is_Object (Id)
6591 and then Present (Renamed_Object (Id))
6593 if Is_Entity_Name (Renamed_Object (Id)) then
6594 Id := Entity (Renamed_Object (Id));
6605 --------------------------
6606 -- Explain_Limited_Type --
6607 --------------------------
6609 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
6613 -- For array, component type must be limited
6615 if Is_Array_Type (T) then
6616 Error_Msg_Node_2 := T;
6618 ("\component type& of type& is limited", N, Component_Type (T));
6619 Explain_Limited_Type (Component_Type (T), N);
6621 elsif Is_Record_Type (T) then
6623 -- No need for extra messages if explicit limited record
6625 if Is_Limited_Record (Base_Type (T)) then
6629 -- Otherwise find a limited component. Check only components that
6630 -- come from source, or inherited components that appear in the
6631 -- source of the ancestor.
6633 C := First_Component (T);
6634 while Present (C) loop
6635 if Is_Limited_Type (Etype (C))
6637 (Comes_From_Source (C)
6639 (Present (Original_Record_Component (C))
6641 Comes_From_Source (Original_Record_Component (C))))
6643 Error_Msg_Node_2 := T;
6644 Error_Msg_NE ("\component& of type& has limited type", N, C);
6645 Explain_Limited_Type (Etype (C), N);
6652 -- The type may be declared explicitly limited, even if no component
6653 -- of it is limited, in which case we fall out of the loop.
6656 end Explain_Limited_Type;
6658 -------------------------------
6659 -- Extensions_Visible_Status --
6660 -------------------------------
6662 function Extensions_Visible_Status
6663 (Id : Entity_Id) return Extensions_Visible_Mode
6672 -- When a formal parameter is subject to Extensions_Visible, the pragma
6673 -- is stored in the contract of related subprogram.
6675 if Is_Formal (Id) then
6678 elsif Is_Subprogram_Or_Generic_Subprogram (Id) then
6681 -- No other construct carries this pragma
6684 return Extensions_Visible_None;
6687 Prag := Get_Pragma (Subp, Pragma_Extensions_Visible);
6689 -- In certain cases analysis may request the Extensions_Visible status
6690 -- of an expression function before the pragma has been analyzed yet.
6691 -- Inspect the declarative items after the expression function looking
6692 -- for the pragma (if any).
6694 if No (Prag) and then Is_Expression_Function (Subp) then
6695 Decl := Next (Unit_Declaration_Node (Subp));
6696 while Present (Decl) loop
6697 if Nkind (Decl) = N_Pragma
6698 and then Pragma_Name (Decl) = Name_Extensions_Visible
6703 -- A source construct ends the region where Extensions_Visible may
6704 -- appear, stop the traversal. An expanded expression function is
6705 -- no longer a source construct, but it must still be recognized.
6707 elsif Comes_From_Source (Decl)
6709 (Nkind_In (Decl, N_Subprogram_Body,
6710 N_Subprogram_Declaration)
6711 and then Is_Expression_Function (Defining_Entity (Decl)))
6720 -- Extract the value from the Boolean expression (if any)
6722 if Present (Prag) then
6723 Arg := First (Pragma_Argument_Associations (Prag));
6725 if Present (Arg) then
6726 Expr := Get_Pragma_Arg (Arg);
6728 -- When the associated subprogram is an expression function, the
6729 -- argument of the pragma may not have been analyzed.
6731 if not Analyzed (Expr) then
6732 Preanalyze_And_Resolve (Expr, Standard_Boolean);
6735 -- Guard against cascading errors when the argument of pragma
6736 -- Extensions_Visible is not a valid static Boolean expression.
6738 if Error_Posted (Expr) then
6739 return Extensions_Visible_None;
6741 elsif Is_True (Expr_Value (Expr)) then
6742 return Extensions_Visible_True;
6745 return Extensions_Visible_False;
6748 -- Otherwise the aspect or pragma defaults to True
6751 return Extensions_Visible_True;
6754 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
6755 -- directly specified. In SPARK code, its value defaults to "False".
6757 elsif SPARK_Mode = On then
6758 return Extensions_Visible_False;
6760 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
6764 return Extensions_Visible_True;
6766 end Extensions_Visible_Status;
6772 procedure Find_Actual
6774 Formal : out Entity_Id;
6777 Context : constant Node_Id := Parent (N);
6782 if Nkind_In (Context, N_Indexed_Component, N_Selected_Component)
6783 and then N = Prefix (Context)
6785 Find_Actual (Context, Formal, Call);
6788 elsif Nkind (Context) = N_Parameter_Association
6789 and then N = Explicit_Actual_Parameter (Context)
6791 Call := Parent (Context);
6793 elsif Nkind_In (Context, N_Entry_Call_Statement,
6795 N_Procedure_Call_Statement)
6805 -- If we have a call to a subprogram look for the parameter. Note that
6806 -- we exclude overloaded calls, since we don't know enough to be sure
6807 -- of giving the right answer in this case.
6809 if Nkind_In (Call, N_Entry_Call_Statement,
6811 N_Procedure_Call_Statement)
6813 Call_Nam := Name (Call);
6815 -- A call to a protected or task entry appears as a selected
6816 -- component rather than an expanded name.
6818 if Nkind (Call_Nam) = N_Selected_Component then
6819 Call_Nam := Selector_Name (Call_Nam);
6822 if Is_Entity_Name (Call_Nam)
6823 and then Present (Entity (Call_Nam))
6824 and then Is_Overloadable (Entity (Call_Nam))
6825 and then not Is_Overloaded (Call_Nam)
6827 -- If node is name in call it is not an actual
6829 if N = Call_Nam then
6835 -- Fall here if we are definitely a parameter
6837 Actual := First_Actual (Call);
6838 Formal := First_Formal (Entity (Call_Nam));
6839 while Present (Formal) and then Present (Actual) loop
6843 -- An actual that is the prefix in a prefixed call may have
6844 -- been rewritten in the call, after the deferred reference
6845 -- was collected. Check if sloc and kinds and names match.
6847 elsif Sloc (Actual) = Sloc (N)
6848 and then Nkind (Actual) = N_Identifier
6849 and then Nkind (Actual) = Nkind (N)
6850 and then Chars (Actual) = Chars (N)
6855 Actual := Next_Actual (Actual);
6856 Formal := Next_Formal (Formal);
6862 -- Fall through here if we did not find matching actual
6868 ---------------------------
6869 -- Find_Body_Discriminal --
6870 ---------------------------
6872 function Find_Body_Discriminal
6873 (Spec_Discriminant : Entity_Id) return Entity_Id
6879 -- If expansion is suppressed, then the scope can be the concurrent type
6880 -- itself rather than a corresponding concurrent record type.
6882 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
6883 Tsk := Scope (Spec_Discriminant);
6886 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
6888 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
6891 -- Find discriminant of original concurrent type, and use its current
6892 -- discriminal, which is the renaming within the task/protected body.
6894 Disc := First_Discriminant (Tsk);
6895 while Present (Disc) loop
6896 if Chars (Disc) = Chars (Spec_Discriminant) then
6897 return Discriminal (Disc);
6900 Next_Discriminant (Disc);
6903 -- That loop should always succeed in finding a matching entry and
6904 -- returning. Fatal error if not.
6906 raise Program_Error;
6907 end Find_Body_Discriminal;
6909 -------------------------------------
6910 -- Find_Corresponding_Discriminant --
6911 -------------------------------------
6913 function Find_Corresponding_Discriminant
6915 Typ : Entity_Id) return Entity_Id
6917 Par_Disc : Entity_Id;
6918 Old_Disc : Entity_Id;
6919 New_Disc : Entity_Id;
6922 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
6924 -- The original type may currently be private, and the discriminant
6925 -- only appear on its full view.
6927 if Is_Private_Type (Scope (Par_Disc))
6928 and then not Has_Discriminants (Scope (Par_Disc))
6929 and then Present (Full_View (Scope (Par_Disc)))
6931 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
6933 Old_Disc := First_Discriminant (Scope (Par_Disc));
6936 if Is_Class_Wide_Type (Typ) then
6937 New_Disc := First_Discriminant (Root_Type (Typ));
6939 New_Disc := First_Discriminant (Typ);
6942 while Present (Old_Disc) and then Present (New_Disc) loop
6943 if Old_Disc = Par_Disc then
6947 Next_Discriminant (Old_Disc);
6948 Next_Discriminant (New_Disc);
6951 -- Should always find it
6953 raise Program_Error;
6954 end Find_Corresponding_Discriminant;
6956 ----------------------------------
6957 -- Find_Enclosing_Iterator_Loop --
6958 ----------------------------------
6960 function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id is
6965 -- Traverse the scope chain looking for an iterator loop. Such loops are
6966 -- usually transformed into blocks, hence the use of Original_Node.
6969 while Present (S) and then S /= Standard_Standard loop
6970 if Ekind (S) = E_Loop
6971 and then Nkind (Parent (S)) = N_Implicit_Label_Declaration
6973 Constr := Original_Node (Label_Construct (Parent (S)));
6975 if Nkind (Constr) = N_Loop_Statement
6976 and then Present (Iteration_Scheme (Constr))
6977 and then Nkind (Iterator_Specification
6978 (Iteration_Scheme (Constr))) =
6979 N_Iterator_Specification
6989 end Find_Enclosing_Iterator_Loop;
6991 ------------------------------------
6992 -- Find_Loop_In_Conditional_Block --
6993 ------------------------------------
6995 function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is
7001 if Nkind (Stmt) = N_If_Statement then
7002 Stmt := First (Then_Statements (Stmt));
7005 pragma Assert (Nkind (Stmt) = N_Block_Statement);
7007 -- Inspect the statements of the conditional block. In general the loop
7008 -- should be the first statement in the statement sequence of the block,
7009 -- but the finalization machinery may have introduced extra object
7012 Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
7013 while Present (Stmt) loop
7014 if Nkind (Stmt) = N_Loop_Statement then
7021 -- The expansion of attribute 'Loop_Entry produced a malformed block
7023 raise Program_Error;
7024 end Find_Loop_In_Conditional_Block;
7026 --------------------------
7027 -- Find_Overlaid_Entity --
7028 --------------------------
7030 procedure Find_Overlaid_Entity
7032 Ent : out Entity_Id;
7038 -- We are looking for one of the two following forms:
7040 -- for X'Address use Y'Address
7044 -- Const : constant Address := expr;
7046 -- for X'Address use Const;
7048 -- In the second case, the expr is either Y'Address, or recursively a
7049 -- constant that eventually references Y'Address.
7054 if Nkind (N) = N_Attribute_Definition_Clause
7055 and then Chars (N) = Name_Address
7057 Expr := Expression (N);
7059 -- This loop checks the form of the expression for Y'Address,
7060 -- using recursion to deal with intermediate constants.
7063 -- Check for Y'Address
7065 if Nkind (Expr) = N_Attribute_Reference
7066 and then Attribute_Name (Expr) = Name_Address
7068 Expr := Prefix (Expr);
7071 -- Check for Const where Const is a constant entity
7073 elsif Is_Entity_Name (Expr)
7074 and then Ekind (Entity (Expr)) = E_Constant
7076 Expr := Constant_Value (Entity (Expr));
7078 -- Anything else does not need checking
7085 -- This loop checks the form of the prefix for an entity, using
7086 -- recursion to deal with intermediate components.
7089 -- Check for Y where Y is an entity
7091 if Is_Entity_Name (Expr) then
7092 Ent := Entity (Expr);
7095 -- Check for components
7098 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component)
7100 Expr := Prefix (Expr);
7103 -- Anything else does not need checking
7110 end Find_Overlaid_Entity;
7112 -------------------------
7113 -- Find_Parameter_Type --
7114 -------------------------
7116 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
7118 if Nkind (Param) /= N_Parameter_Specification then
7121 -- For an access parameter, obtain the type from the formal entity
7122 -- itself, because access to subprogram nodes do not carry a type.
7123 -- Shouldn't we always use the formal entity ???
7125 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
7126 return Etype (Defining_Identifier (Param));
7129 return Etype (Parameter_Type (Param));
7131 end Find_Parameter_Type;
7133 -----------------------------------
7134 -- Find_Placement_In_State_Space --
7135 -----------------------------------
7137 procedure Find_Placement_In_State_Space
7138 (Item_Id : Entity_Id;
7139 Placement : out State_Space_Kind;
7140 Pack_Id : out Entity_Id)
7142 Context : Entity_Id;
7145 -- Assume that the item does not appear in the state space of a package
7147 Placement := Not_In_Package;
7150 -- Climb the scope stack and examine the enclosing context
7152 Context := Scope (Item_Id);
7153 while Present (Context) and then Context /= Standard_Standard loop
7154 if Ekind (Context) = E_Package then
7157 -- A package body is a cut off point for the traversal as the item
7158 -- cannot be visible to the outside from this point on. Note that
7159 -- this test must be done first as a body is also classified as a
7162 if In_Package_Body (Context) then
7163 Placement := Body_State_Space;
7166 -- The private part of a package is a cut off point for the
7167 -- traversal as the item cannot be visible to the outside from
7170 elsif In_Private_Part (Context) then
7171 Placement := Private_State_Space;
7174 -- When the item appears in the visible state space of a package,
7175 -- continue to climb the scope stack as this may not be the final
7179 Placement := Visible_State_Space;
7181 -- The visible state space of a child unit acts as the proper
7182 -- placement of an item.
7184 if Is_Child_Unit (Context) then
7189 -- The item or its enclosing package appear in a construct that has
7193 Placement := Not_In_Package;
7197 Context := Scope (Context);
7199 end Find_Placement_In_State_Space;
7201 ------------------------
7202 -- Find_Specific_Type --
7203 ------------------------
7205 function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
7206 Typ : Entity_Id := Root_Type (CW);
7209 if Ekind (Typ) = E_Incomplete_Type then
7210 if From_Limited_With (Typ) then
7211 Typ := Non_Limited_View (Typ);
7213 Typ := Full_View (Typ);
7217 if Is_Private_Type (Typ)
7218 and then not Is_Tagged_Type (Typ)
7219 and then Present (Full_View (Typ))
7221 return Full_View (Typ);
7225 end Find_Specific_Type;
7227 -----------------------------
7228 -- Find_Static_Alternative --
7229 -----------------------------
7231 function Find_Static_Alternative (N : Node_Id) return Node_Id is
7232 Expr : constant Node_Id := Expression (N);
7233 Val : constant Uint := Expr_Value (Expr);
7238 Alt := First (Alternatives (N));
7241 if Nkind (Alt) /= N_Pragma then
7242 Choice := First (Discrete_Choices (Alt));
7243 while Present (Choice) loop
7245 -- Others choice, always matches
7247 if Nkind (Choice) = N_Others_Choice then
7250 -- Range, check if value is in the range
7252 elsif Nkind (Choice) = N_Range then
7254 Val >= Expr_Value (Low_Bound (Choice))
7256 Val <= Expr_Value (High_Bound (Choice));
7258 -- Choice is a subtype name. Note that we know it must
7259 -- be a static subtype, since otherwise it would have
7260 -- been diagnosed as illegal.
7262 elsif Is_Entity_Name (Choice)
7263 and then Is_Type (Entity (Choice))
7265 exit Search when Is_In_Range (Expr, Etype (Choice),
7266 Assume_Valid => False);
7268 -- Choice is a subtype indication
7270 elsif Nkind (Choice) = N_Subtype_Indication then
7272 C : constant Node_Id := Constraint (Choice);
7273 R : constant Node_Id := Range_Expression (C);
7277 Val >= Expr_Value (Low_Bound (R))
7279 Val <= Expr_Value (High_Bound (R));
7282 -- Choice is a simple expression
7285 exit Search when Val = Expr_Value (Choice);
7293 pragma Assert (Present (Alt));
7296 -- The above loop *must* terminate by finding a match, since
7297 -- we know the case statement is valid, and the value of the
7298 -- expression is known at compile time. When we fall out of
7299 -- the loop, Alt points to the alternative that we know will
7300 -- be selected at run time.
7303 end Find_Static_Alternative;
7309 function First_Actual (Node : Node_Id) return Node_Id is
7313 if No (Parameter_Associations (Node)) then
7317 N := First (Parameter_Associations (Node));
7319 if Nkind (N) = N_Parameter_Association then
7320 return First_Named_Actual (Node);
7330 function Fix_Msg (Id : Entity_Id; Msg : String) return String is
7331 Is_Task : constant Boolean :=
7332 Ekind_In (Id, E_Task_Body, E_Task_Type)
7333 or else Is_Single_Task_Object (Id);
7334 Msg_Last : constant Natural := Msg'Last;
7335 Msg_Index : Natural;
7336 Res : String (Msg'Range) := (others => ' ');
7337 Res_Index : Natural;
7340 -- Copy all characters from the input message Msg to result Res with
7341 -- suitable replacements.
7343 Msg_Index := Msg'First;
7344 Res_Index := Res'First;
7345 while Msg_Index <= Msg_Last loop
7347 -- Replace "subprogram" with a different word
7349 if Msg_Index <= Msg_Last - 10
7350 and then Msg (Msg_Index .. Msg_Index + 9) = "subprogram"
7352 if Ekind_In (Id, E_Entry, E_Entry_Family) then
7353 Res (Res_Index .. Res_Index + 4) := "entry";
7354 Res_Index := Res_Index + 5;
7357 Res (Res_Index .. Res_Index + 8) := "task type";
7358 Res_Index := Res_Index + 9;
7361 Res (Res_Index .. Res_Index + 9) := "subprogram";
7362 Res_Index := Res_Index + 10;
7365 Msg_Index := Msg_Index + 10;
7367 -- Replace "protected" with a different word
7369 elsif Msg_Index <= Msg_Last - 9
7370 and then Msg (Msg_Index .. Msg_Index + 8) = "protected"
7373 Res (Res_Index .. Res_Index + 3) := "task";
7374 Res_Index := Res_Index + 4;
7375 Msg_Index := Msg_Index + 9;
7377 -- Otherwise copy the character
7380 Res (Res_Index) := Msg (Msg_Index);
7381 Msg_Index := Msg_Index + 1;
7382 Res_Index := Res_Index + 1;
7386 return Res (Res'First .. Res_Index - 1);
7389 -----------------------
7390 -- Gather_Components --
7391 -----------------------
7393 procedure Gather_Components
7395 Comp_List : Node_Id;
7396 Governed_By : List_Id;
7398 Report_Errors : out Boolean)
7402 Discrete_Choice : Node_Id;
7403 Comp_Item : Node_Id;
7405 Discrim : Entity_Id;
7406 Discrim_Name : Node_Id;
7407 Discrim_Value : Node_Id;
7410 Report_Errors := False;
7412 if No (Comp_List) or else Null_Present (Comp_List) then
7415 elsif Present (Component_Items (Comp_List)) then
7416 Comp_Item := First (Component_Items (Comp_List));
7422 while Present (Comp_Item) loop
7424 -- Skip the tag of a tagged record, the interface tags, as well
7425 -- as all items that are not user components (anonymous types,
7426 -- rep clauses, Parent field, controller field).
7428 if Nkind (Comp_Item) = N_Component_Declaration then
7430 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
7432 if not Is_Tag (Comp) and then Chars (Comp) /= Name_uParent then
7433 Append_Elmt (Comp, Into);
7441 if No (Variant_Part (Comp_List)) then
7444 Discrim_Name := Name (Variant_Part (Comp_List));
7445 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
7448 -- Look for the discriminant that governs this variant part.
7449 -- The discriminant *must* be in the Governed_By List
7451 Assoc := First (Governed_By);
7452 Find_Constraint : loop
7453 Discrim := First (Choices (Assoc));
7454 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
7455 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
7457 Chars (Corresponding_Discriminant (Entity (Discrim))) =
7458 Chars (Discrim_Name))
7459 or else Chars (Original_Record_Component (Entity (Discrim)))
7460 = Chars (Discrim_Name);
7462 if No (Next (Assoc)) then
7463 if not Is_Constrained (Typ)
7464 and then Is_Derived_Type (Typ)
7465 and then Present (Stored_Constraint (Typ))
7467 -- If the type is a tagged type with inherited discriminants,
7468 -- use the stored constraint on the parent in order to find
7469 -- the values of discriminants that are otherwise hidden by an
7470 -- explicit constraint. Renamed discriminants are handled in
7473 -- If several parent discriminants are renamed by a single
7474 -- discriminant of the derived type, the call to obtain the
7475 -- Corresponding_Discriminant field only retrieves the last
7476 -- of them. We recover the constraint on the others from the
7477 -- Stored_Constraint as well.
7484 D := First_Discriminant (Etype (Typ));
7485 C := First_Elmt (Stored_Constraint (Typ));
7486 while Present (D) and then Present (C) loop
7487 if Chars (Discrim_Name) = Chars (D) then
7488 if Is_Entity_Name (Node (C))
7489 and then Entity (Node (C)) = Entity (Discrim)
7491 -- D is renamed by Discrim, whose value is given in
7498 Make_Component_Association (Sloc (Typ),
7500 (New_Occurrence_Of (D, Sloc (Typ))),
7501 Duplicate_Subexpr_No_Checks (Node (C)));
7503 exit Find_Constraint;
7506 Next_Discriminant (D);
7513 if No (Next (Assoc)) then
7514 Error_Msg_NE (" missing value for discriminant&",
7515 First (Governed_By), Discrim_Name);
7516 Report_Errors := True;
7521 end loop Find_Constraint;
7523 Discrim_Value := Expression (Assoc);
7525 if not Is_OK_Static_Expression (Discrim_Value) then
7527 -- If the variant part is governed by a discriminant of the type
7528 -- this is an error. If the variant part and the discriminant are
7529 -- inherited from an ancestor this is legal (AI05-120) unless the
7530 -- components are being gathered for an aggregate, in which case
7531 -- the caller must check Report_Errors.
7533 if Scope (Original_Record_Component
7534 ((Entity (First (Choices (Assoc)))))) = Typ
7537 ("value for discriminant & must be static!",
7538 Discrim_Value, Discrim);
7539 Why_Not_Static (Discrim_Value);
7542 Report_Errors := True;
7546 Search_For_Discriminant_Value : declare
7552 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
7555 Find_Discrete_Value : while Present (Variant) loop
7556 Discrete_Choice := First (Discrete_Choices (Variant));
7557 while Present (Discrete_Choice) loop
7558 exit Find_Discrete_Value when
7559 Nkind (Discrete_Choice) = N_Others_Choice;
7561 Get_Index_Bounds (Discrete_Choice, Low, High);
7563 UI_Low := Expr_Value (Low);
7564 UI_High := Expr_Value (High);
7566 exit Find_Discrete_Value when
7567 UI_Low <= UI_Discrim_Value
7569 UI_High >= UI_Discrim_Value;
7571 Next (Discrete_Choice);
7574 Next_Non_Pragma (Variant);
7575 end loop Find_Discrete_Value;
7576 end Search_For_Discriminant_Value;
7578 if No (Variant) then
7580 ("value of discriminant & is out of range", Discrim_Value, Discrim);
7581 Report_Errors := True;
7585 -- If we have found the corresponding choice, recursively add its
7586 -- components to the Into list. The nested components are part of
7587 -- the same record type.
7590 (Typ, Component_List (Variant), Governed_By, Into, Report_Errors);
7591 end Gather_Components;
7593 ------------------------
7594 -- Get_Actual_Subtype --
7595 ------------------------
7597 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
7598 Typ : constant Entity_Id := Etype (N);
7599 Utyp : Entity_Id := Underlying_Type (Typ);
7608 -- If what we have is an identifier that references a subprogram
7609 -- formal, or a variable or constant object, then we get the actual
7610 -- subtype from the referenced entity if one has been built.
7612 if Nkind (N) = N_Identifier
7614 (Is_Formal (Entity (N))
7615 or else Ekind (Entity (N)) = E_Constant
7616 or else Ekind (Entity (N)) = E_Variable)
7617 and then Present (Actual_Subtype (Entity (N)))
7619 return Actual_Subtype (Entity (N));
7621 -- Actual subtype of unchecked union is always itself. We never need
7622 -- the "real" actual subtype. If we did, we couldn't get it anyway
7623 -- because the discriminant is not available. The restrictions on
7624 -- Unchecked_Union are designed to make sure that this is OK.
7626 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
7629 -- Here for the unconstrained case, we must find actual subtype
7630 -- No actual subtype is available, so we must build it on the fly.
7632 -- Checking the type, not the underlying type, for constrainedness
7633 -- seems to be necessary. Maybe all the tests should be on the type???
7635 elsif (not Is_Constrained (Typ))
7636 and then (Is_Array_Type (Utyp)
7637 or else (Is_Record_Type (Utyp)
7638 and then Has_Discriminants (Utyp)))
7639 and then not Has_Unknown_Discriminants (Utyp)
7640 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
7642 -- Nothing to do if in spec expression (why not???)
7644 if In_Spec_Expression then
7647 elsif Is_Private_Type (Typ) and then not Has_Discriminants (Typ) then
7649 -- If the type has no discriminants, there is no subtype to
7650 -- build, even if the underlying type is discriminated.
7654 -- Else build the actual subtype
7657 Decl := Build_Actual_Subtype (Typ, N);
7658 Atyp := Defining_Identifier (Decl);
7660 -- If Build_Actual_Subtype generated a new declaration then use it
7664 -- The actual subtype is an Itype, so analyze the declaration,
7665 -- but do not attach it to the tree, to get the type defined.
7667 Set_Parent (Decl, N);
7668 Set_Is_Itype (Atyp);
7669 Analyze (Decl, Suppress => All_Checks);
7670 Set_Associated_Node_For_Itype (Atyp, N);
7671 Set_Has_Delayed_Freeze (Atyp, False);
7673 -- We need to freeze the actual subtype immediately. This is
7674 -- needed, because otherwise this Itype will not get frozen
7675 -- at all, and it is always safe to freeze on creation because
7676 -- any associated types must be frozen at this point.
7678 Freeze_Itype (Atyp, N);
7681 -- Otherwise we did not build a declaration, so return original
7688 -- For all remaining cases, the actual subtype is the same as
7689 -- the nominal type.
7694 end Get_Actual_Subtype;
7696 -------------------------------------
7697 -- Get_Actual_Subtype_If_Available --
7698 -------------------------------------
7700 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
7701 Typ : constant Entity_Id := Etype (N);
7704 -- If what we have is an identifier that references a subprogram
7705 -- formal, or a variable or constant object, then we get the actual
7706 -- subtype from the referenced entity if one has been built.
7708 if Nkind (N) = N_Identifier
7710 (Is_Formal (Entity (N))
7711 or else Ekind (Entity (N)) = E_Constant
7712 or else Ekind (Entity (N)) = E_Variable)
7713 and then Present (Actual_Subtype (Entity (N)))
7715 return Actual_Subtype (Entity (N));
7717 -- Otherwise the Etype of N is returned unchanged
7722 end Get_Actual_Subtype_If_Available;
7724 ------------------------
7725 -- Get_Body_From_Stub --
7726 ------------------------
7728 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
7730 return Proper_Body (Unit (Library_Unit (N)));
7731 end Get_Body_From_Stub;
7733 ---------------------
7734 -- Get_Cursor_Type --
7735 ---------------------
7737 function Get_Cursor_Type
7739 Typ : Entity_Id) return Entity_Id
7743 First_Op : Entity_Id;
7747 -- If error already detected, return
7749 if Error_Posted (Aspect) then
7753 -- The cursor type for an Iterable aspect is the return type of a
7754 -- non-overloaded First primitive operation. Locate association for
7757 Assoc := First (Component_Associations (Expression (Aspect)));
7759 while Present (Assoc) loop
7760 if Chars (First (Choices (Assoc))) = Name_First then
7761 First_Op := Expression (Assoc);
7768 if First_Op = Any_Id then
7769 Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
7775 -- Locate function with desired name and profile in scope of type
7776 -- In the rare case where the type is an integer type, a base type
7777 -- is created for it, check that the base type of the first formal
7778 -- of First matches the base type of the domain.
7780 Func := First_Entity (Scope (Typ));
7781 while Present (Func) loop
7782 if Chars (Func) = Chars (First_Op)
7783 and then Ekind (Func) = E_Function
7784 and then Present (First_Formal (Func))
7785 and then Base_Type (Etype (First_Formal (Func))) = Base_Type (Typ)
7786 and then No (Next_Formal (First_Formal (Func)))
7788 if Cursor /= Any_Type then
7790 ("Operation First for iterable type must be unique", Aspect);
7793 Cursor := Etype (Func);
7800 -- If not found, no way to resolve remaining primitives.
7802 if Cursor = Any_Type then
7804 ("No legal primitive operation First for Iterable type", Aspect);
7808 end Get_Cursor_Type;
7810 function Get_Cursor_Type (Typ : Entity_Id) return Entity_Id is
7812 return Etype (Get_Iterable_Type_Primitive (Typ, Name_First));
7813 end Get_Cursor_Type;
7815 -------------------------------
7816 -- Get_Default_External_Name --
7817 -------------------------------
7819 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
7821 Get_Decoded_Name_String (Chars (E));
7823 if Opt.External_Name_Imp_Casing = Uppercase then
7824 Set_Casing (All_Upper_Case);
7826 Set_Casing (All_Lower_Case);
7830 Make_String_Literal (Sloc (E),
7831 Strval => String_From_Name_Buffer);
7832 end Get_Default_External_Name;
7834 --------------------------
7835 -- Get_Enclosing_Object --
7836 --------------------------
7838 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
7840 if Is_Entity_Name (N) then
7844 when N_Indexed_Component |
7846 N_Selected_Component =>
7848 -- If not generating code, a dereference may be left implicit.
7849 -- In thoses cases, return Empty.
7851 if Is_Access_Type (Etype (Prefix (N))) then
7854 return Get_Enclosing_Object (Prefix (N));
7857 when N_Type_Conversion =>
7858 return Get_Enclosing_Object (Expression (N));
7864 end Get_Enclosing_Object;
7866 ---------------------------
7867 -- Get_Enum_Lit_From_Pos --
7868 ---------------------------
7870 function Get_Enum_Lit_From_Pos
7873 Loc : Source_Ptr) return Node_Id
7875 Btyp : Entity_Id := Base_Type (T);
7879 -- In the case where the literal is of type Character, Wide_Character
7880 -- or Wide_Wide_Character or of a type derived from them, there needs
7881 -- to be some special handling since there is no explicit chain of
7882 -- literals to search. Instead, an N_Character_Literal node is created
7883 -- with the appropriate Char_Code and Chars fields.
7885 if Is_Standard_Character_Type (T) then
7886 Set_Character_Literal_Name (UI_To_CC (Pos));
7888 Make_Character_Literal (Loc,
7890 Char_Literal_Value => Pos);
7892 -- For all other cases, we have a complete table of literals, and
7893 -- we simply iterate through the chain of literal until the one
7894 -- with the desired position value is found.
7897 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
7898 Btyp := Full_View (Btyp);
7901 Lit := First_Literal (Btyp);
7902 for J in 1 .. UI_To_Int (Pos) loop
7906 return New_Occurrence_Of (Lit, Loc);
7908 end Get_Enum_Lit_From_Pos;
7910 ------------------------
7911 -- Get_Generic_Entity --
7912 ------------------------
7914 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
7915 Ent : constant Entity_Id := Entity (Name (N));
7917 if Present (Renamed_Object (Ent)) then
7918 return Renamed_Object (Ent);
7922 end Get_Generic_Entity;
7924 -------------------------------------
7925 -- Get_Incomplete_View_Of_Ancestor --
7926 -------------------------------------
7928 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
7929 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
7930 Par_Scope : Entity_Id;
7931 Par_Type : Entity_Id;
7934 -- The incomplete view of an ancestor is only relevant for private
7935 -- derived types in child units.
7937 if not Is_Derived_Type (E)
7938 or else not Is_Child_Unit (Cur_Unit)
7943 Par_Scope := Scope (Cur_Unit);
7944 if No (Par_Scope) then
7948 Par_Type := Etype (Base_Type (E));
7950 -- Traverse list of ancestor types until we find one declared in
7951 -- a parent or grandparent unit (two levels seem sufficient).
7953 while Present (Par_Type) loop
7954 if Scope (Par_Type) = Par_Scope
7955 or else Scope (Par_Type) = Scope (Par_Scope)
7959 elsif not Is_Derived_Type (Par_Type) then
7963 Par_Type := Etype (Base_Type (Par_Type));
7967 -- If none found, there is no relevant ancestor type.
7971 end Get_Incomplete_View_Of_Ancestor;
7973 ----------------------
7974 -- Get_Index_Bounds --
7975 ----------------------
7977 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
7978 Kind : constant Node_Kind := Nkind (N);
7982 if Kind = N_Range then
7984 H := High_Bound (N);
7986 elsif Kind = N_Subtype_Indication then
7987 R := Range_Expression (Constraint (N));
7995 L := Low_Bound (Range_Expression (Constraint (N)));
7996 H := High_Bound (Range_Expression (Constraint (N)));
7999 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
8000 if Error_Posted (Scalar_Range (Entity (N))) then
8004 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
8005 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
8008 L := Low_Bound (Scalar_Range (Entity (N)));
8009 H := High_Bound (Scalar_Range (Entity (N)));
8013 -- N is an expression, indicating a range with one value
8018 end Get_Index_Bounds;
8020 ---------------------------------
8021 -- Get_Iterable_Type_Primitive --
8022 ---------------------------------
8024 function Get_Iterable_Type_Primitive
8026 Nam : Name_Id) return Entity_Id
8028 Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
8036 Assoc := First (Component_Associations (Funcs));
8037 while Present (Assoc) loop
8038 if Chars (First (Choices (Assoc))) = Nam then
8039 return Entity (Expression (Assoc));
8042 Assoc := Next (Assoc);
8047 end Get_Iterable_Type_Primitive;
8049 ----------------------------------
8050 -- Get_Library_Unit_Name_string --
8051 ----------------------------------
8053 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
8054 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
8057 Get_Unit_Name_String (Unit_Name_Id);
8059 -- Remove seven last character (" (spec)" or " (body)")
8061 Name_Len := Name_Len - 7;
8062 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
8063 end Get_Library_Unit_Name_String;
8065 ------------------------
8066 -- Get_Name_Entity_Id --
8067 ------------------------
8069 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
8071 return Entity_Id (Get_Name_Table_Int (Id));
8072 end Get_Name_Entity_Id;
8074 ------------------------------
8075 -- Get_Name_From_CTC_Pragma --
8076 ------------------------------
8078 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
8079 Arg : constant Node_Id :=
8080 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
8082 return Strval (Expr_Value_S (Arg));
8083 end Get_Name_From_CTC_Pragma;
8085 -----------------------
8086 -- Get_Parent_Entity --
8087 -----------------------
8089 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
8091 if Nkind (Unit) = N_Package_Body
8092 and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
8094 return Defining_Entity
8095 (Specification (Instance_Spec (Original_Node (Unit))));
8096 elsif Nkind (Unit) = N_Package_Instantiation then
8097 return Defining_Entity (Specification (Instance_Spec (Unit)));
8099 return Defining_Entity (Unit);
8101 end Get_Parent_Entity;
8107 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
8109 return Get_Pragma_Id (Pragma_Name (N));
8112 -----------------------
8113 -- Get_Reason_String --
8114 -----------------------
8116 procedure Get_Reason_String (N : Node_Id) is
8118 if Nkind (N) = N_String_Literal then
8119 Store_String_Chars (Strval (N));
8121 elsif Nkind (N) = N_Op_Concat then
8122 Get_Reason_String (Left_Opnd (N));
8123 Get_Reason_String (Right_Opnd (N));
8125 -- If not of required form, error
8129 ("Reason for pragma Warnings has wrong form", N);
8131 ("\must be string literal or concatenation of string literals", N);
8134 end Get_Reason_String;
8136 --------------------------------
8137 -- Get_Reference_Discriminant --
8138 --------------------------------
8140 function Get_Reference_Discriminant (Typ : Entity_Id) return Entity_Id is
8144 D := First_Discriminant (Typ);
8145 while Present (D) loop
8146 if Has_Implicit_Dereference (D) then
8149 Next_Discriminant (D);
8153 end Get_Reference_Discriminant;
8155 ---------------------------
8156 -- Get_Referenced_Object --
8157 ---------------------------
8159 function Get_Referenced_Object (N : Node_Id) return Node_Id is
8164 while Is_Entity_Name (R)
8165 and then Present (Renamed_Object (Entity (R)))
8167 R := Renamed_Object (Entity (R));
8171 end Get_Referenced_Object;
8173 ------------------------
8174 -- Get_Renamed_Entity --
8175 ------------------------
8177 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
8182 while Present (Renamed_Entity (R)) loop
8183 R := Renamed_Entity (R);
8187 end Get_Renamed_Entity;
8189 -----------------------
8190 -- Get_Return_Object --
8191 -----------------------
8193 function Get_Return_Object (N : Node_Id) return Entity_Id is
8197 Decl := First (Return_Object_Declarations (N));
8198 while Present (Decl) loop
8199 exit when Nkind (Decl) = N_Object_Declaration
8200 and then Is_Return_Object (Defining_Identifier (Decl));
8204 pragma Assert (Present (Decl));
8205 return Defining_Identifier (Decl);
8206 end Get_Return_Object;
8208 ---------------------------
8209 -- Get_Subprogram_Entity --
8210 ---------------------------
8212 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
8214 Subp_Id : Entity_Id;
8217 if Nkind (Nod) = N_Accept_Statement then
8218 Subp := Entry_Direct_Name (Nod);
8220 elsif Nkind (Nod) = N_Slice then
8221 Subp := Prefix (Nod);
8227 -- Strip the subprogram call
8230 if Nkind_In (Subp, N_Explicit_Dereference,
8231 N_Indexed_Component,
8232 N_Selected_Component)
8234 Subp := Prefix (Subp);
8236 elsif Nkind_In (Subp, N_Type_Conversion,
8237 N_Unchecked_Type_Conversion)
8239 Subp := Expression (Subp);
8246 -- Extract the entity of the subprogram call
8248 if Is_Entity_Name (Subp) then
8249 Subp_Id := Entity (Subp);
8251 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
8252 Subp_Id := Directly_Designated_Type (Subp_Id);
8255 if Is_Subprogram (Subp_Id) then
8261 -- The search did not find a construct that denotes a subprogram
8266 end Get_Subprogram_Entity;
8268 -----------------------------
8269 -- Get_Task_Body_Procedure --
8270 -----------------------------
8272 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
8274 -- Note: A task type may be the completion of a private type with
8275 -- discriminants. When performing elaboration checks on a task
8276 -- declaration, the current view of the type may be the private one,
8277 -- and the procedure that holds the body of the task is held in its
8280 -- This is an odd function, why not have Task_Body_Procedure do
8281 -- the following digging???
8283 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
8284 end Get_Task_Body_Procedure;
8286 -------------------------
8287 -- Get_User_Defined_Eq --
8288 -------------------------
8290 function Get_User_Defined_Eq (E : Entity_Id) return Entity_Id is
8295 Prim := First_Elmt (Collect_Primitive_Operations (E));
8296 while Present (Prim) loop
8299 if Chars (Op) = Name_Op_Eq
8300 and then Etype (Op) = Standard_Boolean
8301 and then Etype (First_Formal (Op)) = E
8302 and then Etype (Next_Formal (First_Formal (Op))) = E
8311 end Get_User_Defined_Eq;
8313 -----------------------
8314 -- Has_Access_Values --
8315 -----------------------
8317 function Has_Access_Values (T : Entity_Id) return Boolean is
8318 Typ : constant Entity_Id := Underlying_Type (T);
8321 -- Case of a private type which is not completed yet. This can only
8322 -- happen in the case of a generic format type appearing directly, or
8323 -- as a component of the type to which this function is being applied
8324 -- at the top level. Return False in this case, since we certainly do
8325 -- not know that the type contains access types.
8330 elsif Is_Access_Type (Typ) then
8333 elsif Is_Array_Type (Typ) then
8334 return Has_Access_Values (Component_Type (Typ));
8336 elsif Is_Record_Type (Typ) then
8341 -- Loop to Check components
8343 Comp := First_Component_Or_Discriminant (Typ);
8344 while Present (Comp) loop
8346 -- Check for access component, tag field does not count, even
8347 -- though it is implemented internally using an access type.
8349 if Has_Access_Values (Etype (Comp))
8350 and then Chars (Comp) /= Name_uTag
8355 Next_Component_Or_Discriminant (Comp);
8364 end Has_Access_Values;
8366 ------------------------------
8367 -- Has_Compatible_Alignment --
8368 ------------------------------
8370 function Has_Compatible_Alignment
8373 Layout_Done : Boolean) return Alignment_Result
8375 function Has_Compatible_Alignment_Internal
8378 Layout_Done : Boolean;
8379 Default : Alignment_Result) return Alignment_Result;
8380 -- This is the internal recursive function that actually does the work.
8381 -- There is one additional parameter, which says what the result should
8382 -- be if no alignment information is found, and there is no definite
8383 -- indication of compatible alignments. At the outer level, this is set
8384 -- to Unknown, but for internal recursive calls in the case where types
8385 -- are known to be correct, it is set to Known_Compatible.
8387 ---------------------------------------
8388 -- Has_Compatible_Alignment_Internal --
8389 ---------------------------------------
8391 function Has_Compatible_Alignment_Internal
8394 Layout_Done : Boolean;
8395 Default : Alignment_Result) return Alignment_Result
8397 Result : Alignment_Result := Known_Compatible;
8398 -- Holds the current status of the result. Note that once a value of
8399 -- Known_Incompatible is set, it is sticky and does not get changed
8400 -- to Unknown (the value in Result only gets worse as we go along,
8403 Offs : Uint := No_Uint;
8404 -- Set to a factor of the offset from the base object when Expr is a
8405 -- selected or indexed component, based on Component_Bit_Offset and
8406 -- Component_Size respectively. A negative value is used to represent
8407 -- a value which is not known at compile time.
8409 procedure Check_Prefix;
8410 -- Checks the prefix recursively in the case where the expression
8411 -- is an indexed or selected component.
8413 procedure Set_Result (R : Alignment_Result);
8414 -- If R represents a worse outcome (unknown instead of known
8415 -- compatible, or known incompatible), then set Result to R.
8421 procedure Check_Prefix is
8423 -- The subtlety here is that in doing a recursive call to check
8424 -- the prefix, we have to decide what to do in the case where we
8425 -- don't find any specific indication of an alignment problem.
8427 -- At the outer level, we normally set Unknown as the result in
8428 -- this case, since we can only set Known_Compatible if we really
8429 -- know that the alignment value is OK, but for the recursive
8430 -- call, in the case where the types match, and we have not
8431 -- specified a peculiar alignment for the object, we are only
8432 -- concerned about suspicious rep clauses, the default case does
8433 -- not affect us, since the compiler will, in the absence of such
8434 -- rep clauses, ensure that the alignment is correct.
8436 if Default = Known_Compatible
8438 (Etype (Obj) = Etype (Expr)
8439 and then (Unknown_Alignment (Obj)
8441 Alignment (Obj) = Alignment (Etype (Obj))))
8444 (Has_Compatible_Alignment_Internal
8445 (Obj, Prefix (Expr), Layout_Done, Known_Compatible));
8447 -- In all other cases, we need a full check on the prefix
8451 (Has_Compatible_Alignment_Internal
8452 (Obj, Prefix (Expr), Layout_Done, Unknown));
8460 procedure Set_Result (R : Alignment_Result) is
8467 -- Start of processing for Has_Compatible_Alignment_Internal
8470 -- If Expr is a selected component, we must make sure there is no
8471 -- potentially troublesome component clause and that the record is
8472 -- not packed if the layout is not done.
8474 if Nkind (Expr) = N_Selected_Component then
8476 -- Packing generates unknown alignment if layout is not done
8478 if Is_Packed (Etype (Prefix (Expr))) and then not Layout_Done then
8479 Set_Result (Unknown);
8482 -- Check prefix and component offset
8485 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
8487 -- If Expr is an indexed component, we must make sure there is no
8488 -- potentially troublesome Component_Size clause and that the array
8489 -- is not bit-packed if the layout is not done.
8491 elsif Nkind (Expr) = N_Indexed_Component then
8493 Typ : constant Entity_Id := Etype (Prefix (Expr));
8494 Ind : constant Node_Id := First_Index (Typ);
8497 -- Packing generates unknown alignment if layout is not done
8499 if Is_Bit_Packed_Array (Typ) and then not Layout_Done then
8500 Set_Result (Unknown);
8503 -- Check prefix and component offset
8506 Offs := Component_Size (Typ);
8508 -- Small optimization: compute the full offset when possible
8511 and then Offs > Uint_0
8512 and then Present (Ind)
8513 and then Nkind (Ind) = N_Range
8514 and then Compile_Time_Known_Value (Low_Bound (Ind))
8515 and then Compile_Time_Known_Value (First (Expressions (Expr)))
8517 Offs := Offs * (Expr_Value (First (Expressions (Expr)))
8518 - Expr_Value (Low_Bound ((Ind))));
8523 -- If we have a null offset, the result is entirely determined by
8524 -- the base object and has already been computed recursively.
8526 if Offs = Uint_0 then
8529 -- Case where we know the alignment of the object
8531 elsif Known_Alignment (Obj) then
8533 ObjA : constant Uint := Alignment (Obj);
8534 ExpA : Uint := No_Uint;
8535 SizA : Uint := No_Uint;
8538 -- If alignment of Obj is 1, then we are always OK
8541 Set_Result (Known_Compatible);
8543 -- Alignment of Obj is greater than 1, so we need to check
8546 -- If we have an offset, see if it is compatible
8548 if Offs /= No_Uint and Offs > Uint_0 then
8549 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
8550 Set_Result (Known_Incompatible);
8553 -- See if Expr is an object with known alignment
8555 elsif Is_Entity_Name (Expr)
8556 and then Known_Alignment (Entity (Expr))
8558 ExpA := Alignment (Entity (Expr));
8560 -- Otherwise, we can use the alignment of the type of
8561 -- Expr given that we already checked for
8562 -- discombobulating rep clauses for the cases of indexed
8563 -- and selected components above.
8565 elsif Known_Alignment (Etype (Expr)) then
8566 ExpA := Alignment (Etype (Expr));
8568 -- Otherwise the alignment is unknown
8571 Set_Result (Default);
8574 -- If we got an alignment, see if it is acceptable
8576 if ExpA /= No_Uint and then ExpA < ObjA then
8577 Set_Result (Known_Incompatible);
8580 -- If Expr is not a piece of a larger object, see if size
8581 -- is given. If so, check that it is not too small for the
8582 -- required alignment.
8584 if Offs /= No_Uint then
8587 -- See if Expr is an object with known size
8589 elsif Is_Entity_Name (Expr)
8590 and then Known_Static_Esize (Entity (Expr))
8592 SizA := Esize (Entity (Expr));
8594 -- Otherwise, we check the object size of the Expr type
8596 elsif Known_Static_Esize (Etype (Expr)) then
8597 SizA := Esize (Etype (Expr));
8600 -- If we got a size, see if it is a multiple of the Obj
8601 -- alignment, if not, then the alignment cannot be
8602 -- acceptable, since the size is always a multiple of the
8605 if SizA /= No_Uint then
8606 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
8607 Set_Result (Known_Incompatible);
8613 -- If we do not know required alignment, any non-zero offset is a
8614 -- potential problem (but certainly may be OK, so result is unknown).
8616 elsif Offs /= No_Uint then
8617 Set_Result (Unknown);
8619 -- If we can't find the result by direct comparison of alignment
8620 -- values, then there is still one case that we can determine known
8621 -- result, and that is when we can determine that the types are the
8622 -- same, and no alignments are specified. Then we known that the
8623 -- alignments are compatible, even if we don't know the alignment
8624 -- value in the front end.
8626 elsif Etype (Obj) = Etype (Expr) then
8628 -- Types are the same, but we have to check for possible size
8629 -- and alignments on the Expr object that may make the alignment
8630 -- different, even though the types are the same.
8632 if Is_Entity_Name (Expr) then
8634 -- First check alignment of the Expr object. Any alignment less
8635 -- than Maximum_Alignment is worrisome since this is the case
8636 -- where we do not know the alignment of Obj.
8638 if Known_Alignment (Entity (Expr))
8639 and then UI_To_Int (Alignment (Entity (Expr))) <
8640 Ttypes.Maximum_Alignment
8642 Set_Result (Unknown);
8644 -- Now check size of Expr object. Any size that is not an
8645 -- even multiple of Maximum_Alignment is also worrisome
8646 -- since it may cause the alignment of the object to be less
8647 -- than the alignment of the type.
8649 elsif Known_Static_Esize (Entity (Expr))
8651 (UI_To_Int (Esize (Entity (Expr))) mod
8652 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
8655 Set_Result (Unknown);
8657 -- Otherwise same type is decisive
8660 Set_Result (Known_Compatible);
8664 -- Another case to deal with is when there is an explicit size or
8665 -- alignment clause when the types are not the same. If so, then the
8666 -- result is Unknown. We don't need to do this test if the Default is
8667 -- Unknown, since that result will be set in any case.
8669 elsif Default /= Unknown
8670 and then (Has_Size_Clause (Etype (Expr))
8672 Has_Alignment_Clause (Etype (Expr)))
8674 Set_Result (Unknown);
8676 -- If no indication found, set default
8679 Set_Result (Default);
8682 -- Return worst result found
8685 end Has_Compatible_Alignment_Internal;
8687 -- Start of processing for Has_Compatible_Alignment
8690 -- If Obj has no specified alignment, then set alignment from the type
8691 -- alignment. Perhaps we should always do this, but for sure we should
8692 -- do it when there is an address clause since we can do more if the
8693 -- alignment is known.
8695 if Unknown_Alignment (Obj) then
8696 Set_Alignment (Obj, Alignment (Etype (Obj)));
8699 -- Now do the internal call that does all the work
8702 Has_Compatible_Alignment_Internal (Obj, Expr, Layout_Done, Unknown);
8703 end Has_Compatible_Alignment;
8705 ----------------------
8706 -- Has_Declarations --
8707 ----------------------
8709 function Has_Declarations (N : Node_Id) return Boolean is
8711 return Nkind_In (Nkind (N), N_Accept_Statement,
8713 N_Compilation_Unit_Aux,
8719 N_Package_Specification);
8720 end Has_Declarations;
8722 ---------------------------------
8723 -- Has_Defaulted_Discriminants --
8724 ---------------------------------
8726 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
8728 return Has_Discriminants (Typ)
8729 and then Present (First_Discriminant (Typ))
8730 and then Present (Discriminant_Default_Value
8731 (First_Discriminant (Typ)));
8732 end Has_Defaulted_Discriminants;
8738 function Has_Denormals (E : Entity_Id) return Boolean is
8740 return Is_Floating_Point_Type (E) and then Denorm_On_Target;
8743 -------------------------------------------
8744 -- Has_Discriminant_Dependent_Constraint --
8745 -------------------------------------------
8747 function Has_Discriminant_Dependent_Constraint
8748 (Comp : Entity_Id) return Boolean
8750 Comp_Decl : constant Node_Id := Parent (Comp);
8751 Subt_Indic : Node_Id;
8756 -- Discriminants can't depend on discriminants
8758 if Ekind (Comp) = E_Discriminant then
8762 Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl));
8764 if Nkind (Subt_Indic) = N_Subtype_Indication then
8765 Constr := Constraint (Subt_Indic);
8767 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
8768 Assn := First (Constraints (Constr));
8769 while Present (Assn) loop
8770 case Nkind (Assn) is
8771 when N_Subtype_Indication |
8775 if Depends_On_Discriminant (Assn) then
8779 when N_Discriminant_Association =>
8780 if Depends_On_Discriminant (Expression (Assn)) then
8795 end Has_Discriminant_Dependent_Constraint;
8797 --------------------------------------
8798 -- Has_Effectively_Volatile_Profile --
8799 --------------------------------------
8801 function Has_Effectively_Volatile_Profile
8802 (Subp_Id : Entity_Id) return Boolean
8807 -- Inspect the formal parameters looking for an effectively volatile
8810 Formal := First_Formal (Subp_Id);
8811 while Present (Formal) loop
8812 if Is_Effectively_Volatile (Etype (Formal)) then
8816 Next_Formal (Formal);
8819 -- Inspect the return type of functions
8821 if Ekind_In (Subp_Id, E_Function, E_Generic_Function)
8822 and then Is_Effectively_Volatile (Etype (Subp_Id))
8828 end Has_Effectively_Volatile_Profile;
8830 --------------------------
8831 -- Has_Enabled_Property --
8832 --------------------------
8834 function Has_Enabled_Property
8835 (Item_Id : Entity_Id;
8836 Property : Name_Id) return Boolean
8838 function State_Has_Enabled_Property return Boolean;
8839 -- Determine whether a state denoted by Item_Id has the property enabled
8841 function Variable_Has_Enabled_Property return Boolean;
8842 -- Determine whether a variable denoted by Item_Id has the property
8845 --------------------------------
8846 -- State_Has_Enabled_Property --
8847 --------------------------------
8849 function State_Has_Enabled_Property return Boolean is
8850 Decl : constant Node_Id := Parent (Item_Id);
8858 -- The declaration of an external abstract state appears as an
8859 -- extension aggregate. If this is not the case, properties can never
8862 if Nkind (Decl) /= N_Extension_Aggregate then
8866 -- When External appears as a simple option, it automatically enables
8869 Opt := First (Expressions (Decl));
8870 while Present (Opt) loop
8871 if Nkind (Opt) = N_Identifier
8872 and then Chars (Opt) = Name_External
8880 -- When External specifies particular properties, inspect those and
8881 -- find the desired one (if any).
8883 Opt := First (Component_Associations (Decl));
8884 while Present (Opt) loop
8885 Opt_Nam := First (Choices (Opt));
8887 if Nkind (Opt_Nam) = N_Identifier
8888 and then Chars (Opt_Nam) = Name_External
8890 Props := Expression (Opt);
8892 -- Multiple properties appear as an aggregate
8894 if Nkind (Props) = N_Aggregate then
8896 -- Simple property form
8898 Prop := First (Expressions (Props));
8899 while Present (Prop) loop
8900 if Chars (Prop) = Property then
8907 -- Property with expression form
8909 Prop := First (Component_Associations (Props));
8910 while Present (Prop) loop
8911 Prop_Nam := First (Choices (Prop));
8913 -- The property can be represented in two ways:
8914 -- others => <value>
8915 -- <property> => <value>
8917 if Nkind (Prop_Nam) = N_Others_Choice
8918 or else (Nkind (Prop_Nam) = N_Identifier
8919 and then Chars (Prop_Nam) = Property)
8921 return Is_True (Expr_Value (Expression (Prop)));
8930 return Chars (Props) = Property;
8938 end State_Has_Enabled_Property;
8940 -----------------------------------
8941 -- Variable_Has_Enabled_Property --
8942 -----------------------------------
8944 function Variable_Has_Enabled_Property return Boolean is
8945 function Is_Enabled (Prag : Node_Id) return Boolean;
8946 -- Determine whether property pragma Prag (if present) denotes an
8947 -- enabled property.
8953 function Is_Enabled (Prag : Node_Id) return Boolean is
8957 if Present (Prag) then
8958 Arg1 := First (Pragma_Argument_Associations (Prag));
8960 -- The pragma has an optional Boolean expression, the related
8961 -- property is enabled only when the expression evaluates to
8964 if Present (Arg1) then
8965 return Is_True (Expr_Value (Get_Pragma_Arg (Arg1)));
8967 -- Otherwise the lack of expression enables the property by
8974 -- The property was never set in the first place
8983 AR : constant Node_Id :=
8984 Get_Pragma (Item_Id, Pragma_Async_Readers);
8985 AW : constant Node_Id :=
8986 Get_Pragma (Item_Id, Pragma_Async_Writers);
8987 ER : constant Node_Id :=
8988 Get_Pragma (Item_Id, Pragma_Effective_Reads);
8989 EW : constant Node_Id :=
8990 Get_Pragma (Item_Id, Pragma_Effective_Writes);
8992 -- Start of processing for Variable_Has_Enabled_Property
8995 -- A non-effectively volatile object can never possess external
8998 if not Is_Effectively_Volatile (Item_Id) then
9001 -- External properties related to variables come in two flavors -
9002 -- explicit and implicit. The explicit case is characterized by the
9003 -- presence of a property pragma with an optional Boolean flag. The
9004 -- property is enabled when the flag evaluates to True or the flag is
9005 -- missing altogether.
9007 elsif Property = Name_Async_Readers and then Is_Enabled (AR) then
9010 elsif Property = Name_Async_Writers and then Is_Enabled (AW) then
9013 elsif Property = Name_Effective_Reads and then Is_Enabled (ER) then
9016 elsif Property = Name_Effective_Writes and then Is_Enabled (EW) then
9019 -- The implicit case lacks all property pragmas
9021 elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then
9027 end Variable_Has_Enabled_Property;
9029 -- Start of processing for Has_Enabled_Property
9032 -- Abstract states and variables have a flexible scheme of specifying
9033 -- external properties.
9035 if Ekind (Item_Id) = E_Abstract_State then
9036 return State_Has_Enabled_Property;
9038 elsif Ekind (Item_Id) = E_Variable then
9039 return Variable_Has_Enabled_Property;
9041 -- Otherwise a property is enabled when the related item is effectively
9045 return Is_Effectively_Volatile (Item_Id);
9047 end Has_Enabled_Property;
9049 -------------------------------------
9050 -- Has_Full_Default_Initialization --
9051 -------------------------------------
9053 function Has_Full_Default_Initialization (Typ : Entity_Id) return Boolean is
9059 -- A private type and its full view is fully default initialized when it
9060 -- is subject to pragma Default_Initial_Condition without an argument or
9061 -- with a non-null argument. Since any type may act as the full view of
9062 -- a private type, this check must be performed prior to the specialized
9065 if Has_Default_Init_Cond (Typ)
9066 or else Has_Inherited_Default_Init_Cond (Typ)
9068 Prag := Get_Pragma (Typ, Pragma_Default_Initial_Condition);
9070 -- Pragma Default_Initial_Condition must be present if one of the
9071 -- related entity flags is set.
9073 pragma Assert (Present (Prag));
9074 Arg := First (Pragma_Argument_Associations (Prag));
9076 -- A non-null argument guarantees full default initialization
9078 if Present (Arg) then
9079 return Nkind (Arg) /= N_Null;
9081 -- Otherwise the missing argument defaults the pragma to "True" which
9082 -- is considered a non-null argument (see above).
9089 -- A scalar type is fully default initialized if it is subject to aspect
9092 if Is_Scalar_Type (Typ) then
9093 return Has_Default_Aspect (Typ);
9095 -- An array type is fully default initialized if its element type is
9096 -- scalar and the array type carries aspect Default_Component_Value or
9097 -- the element type is fully default initialized.
9099 elsif Is_Array_Type (Typ) then
9101 Has_Default_Aspect (Typ)
9102 or else Has_Full_Default_Initialization (Component_Type (Typ));
9104 -- A protected type, record type or type extension is fully default
9105 -- initialized if all its components either carry an initialization
9106 -- expression or have a type that is fully default initialized. The
9107 -- parent type of a type extension must be fully default initialized.
9109 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
9111 -- Inspect all entities defined in the scope of the type, looking for
9112 -- uninitialized components.
9114 Comp := First_Entity (Typ);
9115 while Present (Comp) loop
9116 if Ekind (Comp) = E_Component
9117 and then Comes_From_Source (Comp)
9118 and then No (Expression (Parent (Comp)))
9119 and then not Has_Full_Default_Initialization (Etype (Comp))
9127 -- Ensure that the parent type of a type extension is fully default
9130 if Etype (Typ) /= Typ
9131 and then not Has_Full_Default_Initialization (Etype (Typ))
9136 -- If we get here, then all components and parent portion are fully
9137 -- default initialized.
9141 -- A task type is fully default initialized by default
9143 elsif Is_Task_Type (Typ) then
9146 -- Otherwise the type is not fully default initialized
9151 end Has_Full_Default_Initialization;
9153 --------------------
9154 -- Has_Infinities --
9155 --------------------
9157 function Has_Infinities (E : Entity_Id) return Boolean is
9160 Is_Floating_Point_Type (E)
9161 and then Nkind (Scalar_Range (E)) = N_Range
9162 and then Includes_Infinities (Scalar_Range (E));
9165 --------------------
9166 -- Has_Interfaces --
9167 --------------------
9169 function Has_Interfaces
9171 Use_Full_View : Boolean := True) return Boolean
9173 Typ : Entity_Id := Base_Type (T);
9176 -- Handle concurrent types
9178 if Is_Concurrent_Type (Typ) then
9179 Typ := Corresponding_Record_Type (Typ);
9182 if not Present (Typ)
9183 or else not Is_Record_Type (Typ)
9184 or else not Is_Tagged_Type (Typ)
9189 -- Handle private types
9191 if Use_Full_View and then Present (Full_View (Typ)) then
9192 Typ := Full_View (Typ);
9195 -- Handle concurrent record types
9197 if Is_Concurrent_Record_Type (Typ)
9198 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
9204 if Is_Interface (Typ)
9206 (Is_Record_Type (Typ)
9207 and then Present (Interfaces (Typ))
9208 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
9213 exit when Etype (Typ) = Typ
9215 -- Handle private types
9217 or else (Present (Full_View (Etype (Typ)))
9218 and then Full_View (Etype (Typ)) = Typ)
9220 -- Protect frontend against wrong sources with cyclic derivations
9222 or else Etype (Typ) = T;
9224 -- Climb to the ancestor type handling private types
9226 if Present (Full_View (Etype (Typ))) then
9227 Typ := Full_View (Etype (Typ));
9236 ---------------------------------
9237 -- Has_No_Obvious_Side_Effects --
9238 ---------------------------------
9240 function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
9242 -- For now, just handle literals, constants, and non-volatile
9243 -- variables and expressions combining these with operators or
9244 -- short circuit forms.
9246 if Nkind (N) in N_Numeric_Or_String_Literal then
9249 elsif Nkind (N) = N_Character_Literal then
9252 elsif Nkind (N) in N_Unary_Op then
9253 return Has_No_Obvious_Side_Effects (Right_Opnd (N));
9255 elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
9256 return Has_No_Obvious_Side_Effects (Left_Opnd (N))
9258 Has_No_Obvious_Side_Effects (Right_Opnd (N));
9260 elsif Nkind (N) = N_Expression_With_Actions
9261 and then Is_Empty_List (Actions (N))
9263 return Has_No_Obvious_Side_Effects (Expression (N));
9265 elsif Nkind (N) in N_Has_Entity then
9266 return Present (Entity (N))
9267 and then Ekind_In (Entity (N), E_Variable,
9269 E_Enumeration_Literal,
9273 and then not Is_Volatile (Entity (N));
9278 end Has_No_Obvious_Side_Effects;
9280 -----------------------------
9281 -- Has_Non_Null_Refinement --
9282 -----------------------------
9284 function Has_Non_Null_Refinement (Id : Entity_Id) return Boolean is
9286 pragma Assert (Ekind (Id) = E_Abstract_State);
9288 -- For a refinement to be non-null, the first constituent must be
9289 -- anything other than null.
9291 if Present (Refinement_Constituents (Id)) then
9293 Nkind (Node (First_Elmt (Refinement_Constituents (Id)))) /= N_Null;
9297 end Has_Non_Null_Refinement;
9299 ------------------------
9300 -- Has_Null_Exclusion --
9301 ------------------------
9303 function Has_Null_Exclusion (N : Node_Id) return Boolean is
9306 when N_Access_Definition |
9307 N_Access_Function_Definition |
9308 N_Access_Procedure_Definition |
9309 N_Access_To_Object_Definition |
9311 N_Derived_Type_Definition |
9312 N_Function_Specification |
9313 N_Subtype_Declaration =>
9314 return Null_Exclusion_Present (N);
9316 when N_Component_Definition |
9317 N_Formal_Object_Declaration |
9318 N_Object_Renaming_Declaration =>
9319 if Present (Subtype_Mark (N)) then
9320 return Null_Exclusion_Present (N);
9321 else pragma Assert (Present (Access_Definition (N)));
9322 return Null_Exclusion_Present (Access_Definition (N));
9325 when N_Discriminant_Specification =>
9326 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
9327 return Null_Exclusion_Present (Discriminant_Type (N));
9329 return Null_Exclusion_Present (N);
9332 when N_Object_Declaration =>
9333 if Nkind (Object_Definition (N)) = N_Access_Definition then
9334 return Null_Exclusion_Present (Object_Definition (N));
9336 return Null_Exclusion_Present (N);
9339 when N_Parameter_Specification =>
9340 if Nkind (Parameter_Type (N)) = N_Access_Definition then
9341 return Null_Exclusion_Present (Parameter_Type (N));
9343 return Null_Exclusion_Present (N);
9350 end Has_Null_Exclusion;
9352 ------------------------
9353 -- Has_Null_Extension --
9354 ------------------------
9356 function Has_Null_Extension (T : Entity_Id) return Boolean is
9357 B : constant Entity_Id := Base_Type (T);
9362 if Nkind (Parent (B)) = N_Full_Type_Declaration
9363 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
9365 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
9367 if Present (Ext) then
9368 if Null_Present (Ext) then
9371 Comps := Component_List (Ext);
9373 -- The null component list is rewritten during analysis to
9374 -- include the parent component. Any other component indicates
9375 -- that the extension was not originally null.
9377 return Null_Present (Comps)
9378 or else No (Next (First (Component_Items (Comps))));
9387 end Has_Null_Extension;
9389 -------------------------
9390 -- Has_Null_Refinement --
9391 -------------------------
9393 function Has_Null_Refinement (Id : Entity_Id) return Boolean is
9395 pragma Assert (Ekind (Id) = E_Abstract_State);
9397 -- For a refinement to be null, the state's sole constituent must be a
9400 if Present (Refinement_Constituents (Id)) then
9402 Nkind (Node (First_Elmt (Refinement_Constituents (Id)))) = N_Null;
9406 end Has_Null_Refinement;
9408 -------------------------------
9409 -- Has_Overriding_Initialize --
9410 -------------------------------
9412 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
9413 BT : constant Entity_Id := Base_Type (T);
9417 if Is_Controlled (BT) then
9418 if Is_RTU (Scope (BT), Ada_Finalization) then
9421 elsif Present (Primitive_Operations (BT)) then
9422 P := First_Elmt (Primitive_Operations (BT));
9423 while Present (P) loop
9425 Init : constant Entity_Id := Node (P);
9426 Formal : constant Entity_Id := First_Formal (Init);
9428 if Ekind (Init) = E_Procedure
9429 and then Chars (Init) = Name_Initialize
9430 and then Comes_From_Source (Init)
9431 and then Present (Formal)
9432 and then Etype (Formal) = BT
9433 and then No (Next_Formal (Formal))
9434 and then (Ada_Version < Ada_2012
9435 or else not Null_Present (Parent (Init)))
9445 -- Here if type itself does not have a non-null Initialize operation:
9446 -- check immediate ancestor.
9448 if Is_Derived_Type (BT)
9449 and then Has_Overriding_Initialize (Etype (BT))
9456 end Has_Overriding_Initialize;
9458 --------------------------------------
9459 -- Has_Preelaborable_Initialization --
9460 --------------------------------------
9462 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
9465 procedure Check_Components (E : Entity_Id);
9466 -- Check component/discriminant chain, sets Has_PE False if a component
9467 -- or discriminant does not meet the preelaborable initialization rules.
9469 ----------------------
9470 -- Check_Components --
9471 ----------------------
9473 procedure Check_Components (E : Entity_Id) is
9477 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
9478 -- Returns True if and only if the expression denoted by N does not
9479 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
9481 ---------------------------------
9482 -- Is_Preelaborable_Expression --
9483 ---------------------------------
9485 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
9489 Comp_Type : Entity_Id;
9490 Is_Array_Aggr : Boolean;
9493 if Is_OK_Static_Expression (N) then
9496 elsif Nkind (N) = N_Null then
9499 -- Attributes are allowed in general, even if their prefix is a
9500 -- formal type. (It seems that certain attributes known not to be
9501 -- static might not be allowed, but there are no rules to prevent
9504 elsif Nkind (N) = N_Attribute_Reference then
9507 -- The name of a discriminant evaluated within its parent type is
9508 -- defined to be preelaborable (10.2.1(8)). Note that we test for
9509 -- names that denote discriminals as well as discriminants to
9510 -- catch references occurring within init procs.
9512 elsif Is_Entity_Name (N)
9514 (Ekind (Entity (N)) = E_Discriminant
9515 or else (Ekind_In (Entity (N), E_Constant, E_In_Parameter)
9516 and then Present (Discriminal_Link (Entity (N)))))
9520 elsif Nkind (N) = N_Qualified_Expression then
9521 return Is_Preelaborable_Expression (Expression (N));
9523 -- For aggregates we have to check that each of the associations
9524 -- is preelaborable.
9526 elsif Nkind_In (N, N_Aggregate, N_Extension_Aggregate) then
9527 Is_Array_Aggr := Is_Array_Type (Etype (N));
9529 if Is_Array_Aggr then
9530 Comp_Type := Component_Type (Etype (N));
9533 -- Check the ancestor part of extension aggregates, which must
9534 -- be either the name of a type that has preelaborable init or
9535 -- an expression that is preelaborable.
9537 if Nkind (N) = N_Extension_Aggregate then
9539 Anc_Part : constant Node_Id := Ancestor_Part (N);
9542 if Is_Entity_Name (Anc_Part)
9543 and then Is_Type (Entity (Anc_Part))
9545 if not Has_Preelaborable_Initialization
9551 elsif not Is_Preelaborable_Expression (Anc_Part) then
9557 -- Check positional associations
9559 Exp := First (Expressions (N));
9560 while Present (Exp) loop
9561 if not Is_Preelaborable_Expression (Exp) then
9568 -- Check named associations
9570 Assn := First (Component_Associations (N));
9571 while Present (Assn) loop
9572 Choice := First (Choices (Assn));
9573 while Present (Choice) loop
9574 if Is_Array_Aggr then
9575 if Nkind (Choice) = N_Others_Choice then
9578 elsif Nkind (Choice) = N_Range then
9579 if not Is_OK_Static_Range (Choice) then
9583 elsif not Is_OK_Static_Expression (Choice) then
9588 Comp_Type := Etype (Choice);
9594 -- If the association has a <> at this point, then we have
9595 -- to check whether the component's type has preelaborable
9596 -- initialization. Note that this only occurs when the
9597 -- association's corresponding component does not have a
9598 -- default expression, the latter case having already been
9599 -- expanded as an expression for the association.
9601 if Box_Present (Assn) then
9602 if not Has_Preelaborable_Initialization (Comp_Type) then
9606 -- In the expression case we check whether the expression
9607 -- is preelaborable.
9610 not Is_Preelaborable_Expression (Expression (Assn))
9618 -- If we get here then aggregate as a whole is preelaborable
9622 -- All other cases are not preelaborable
9627 end Is_Preelaborable_Expression;
9629 -- Start of processing for Check_Components
9632 -- Loop through entities of record or protected type
9635 while Present (Ent) loop
9637 -- We are interested only in components and discriminants
9644 -- Get default expression if any. If there is no declaration
9645 -- node, it means we have an internal entity. The parent and
9646 -- tag fields are examples of such entities. For such cases,
9647 -- we just test the type of the entity.
9649 if Present (Declaration_Node (Ent)) then
9650 Exp := Expression (Declaration_Node (Ent));
9653 when E_Discriminant =>
9655 -- Note: for a renamed discriminant, the Declaration_Node
9656 -- may point to the one from the ancestor, and have a
9657 -- different expression, so use the proper attribute to
9658 -- retrieve the expression from the derived constraint.
9660 Exp := Discriminant_Default_Value (Ent);
9663 goto Check_Next_Entity;
9666 -- A component has PI if it has no default expression and the
9667 -- component type has PI.
9670 if not Has_Preelaborable_Initialization (Etype (Ent)) then
9675 -- Require the default expression to be preelaborable
9677 elsif not Is_Preelaborable_Expression (Exp) then
9682 <<Check_Next_Entity>>
9685 end Check_Components;
9687 -- Start of processing for Has_Preelaborable_Initialization
9690 -- Immediate return if already marked as known preelaborable init. This
9691 -- covers types for which this function has already been called once
9692 -- and returned True (in which case the result is cached), and also
9693 -- types to which a pragma Preelaborable_Initialization applies.
9695 if Known_To_Have_Preelab_Init (E) then
9699 -- If the type is a subtype representing a generic actual type, then
9700 -- test whether its base type has preelaborable initialization since
9701 -- the subtype representing the actual does not inherit this attribute
9702 -- from the actual or formal. (but maybe it should???)
9704 if Is_Generic_Actual_Type (E) then
9705 return Has_Preelaborable_Initialization (Base_Type (E));
9708 -- All elementary types have preelaborable initialization
9710 if Is_Elementary_Type (E) then
9713 -- Array types have PI if the component type has PI
9715 elsif Is_Array_Type (E) then
9716 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
9718 -- A derived type has preelaborable initialization if its parent type
9719 -- has preelaborable initialization and (in the case of a derived record
9720 -- extension) if the non-inherited components all have preelaborable
9721 -- initialization. However, a user-defined controlled type with an
9722 -- overriding Initialize procedure does not have preelaborable
9725 elsif Is_Derived_Type (E) then
9727 -- If the derived type is a private extension then it doesn't have
9728 -- preelaborable initialization.
9730 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
9734 -- First check whether ancestor type has preelaborable initialization
9736 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
9738 -- If OK, check extension components (if any)
9740 if Has_PE and then Is_Record_Type (E) then
9741 Check_Components (First_Entity (E));
9744 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
9745 -- with a user defined Initialize procedure does not have PI. If
9746 -- the type is untagged, the control primitives come from a component
9747 -- that has already been checked.
9750 and then Is_Controlled (E)
9751 and then Is_Tagged_Type (E)
9752 and then Has_Overriding_Initialize (E)
9757 -- Private types not derived from a type having preelaborable init and
9758 -- that are not marked with pragma Preelaborable_Initialization do not
9759 -- have preelaborable initialization.
9761 elsif Is_Private_Type (E) then
9764 -- Record type has PI if it is non private and all components have PI
9766 elsif Is_Record_Type (E) then
9768 Check_Components (First_Entity (E));
9770 -- Protected types must not have entries, and components must meet
9771 -- same set of rules as for record components.
9773 elsif Is_Protected_Type (E) then
9774 if Has_Entries (E) then
9778 Check_Components (First_Entity (E));
9779 Check_Components (First_Private_Entity (E));
9782 -- Type System.Address always has preelaborable initialization
9784 elsif Is_RTE (E, RE_Address) then
9787 -- In all other cases, type does not have preelaborable initialization
9793 -- If type has preelaborable initialization, cache result
9796 Set_Known_To_Have_Preelab_Init (E);
9800 end Has_Preelaborable_Initialization;
9802 ---------------------------
9803 -- Has_Private_Component --
9804 ---------------------------
9806 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
9807 Btype : Entity_Id := Base_Type (Type_Id);
9808 Component : Entity_Id;
9811 if Error_Posted (Type_Id)
9812 or else Error_Posted (Btype)
9817 if Is_Class_Wide_Type (Btype) then
9818 Btype := Root_Type (Btype);
9821 if Is_Private_Type (Btype) then
9823 UT : constant Entity_Id := Underlying_Type (Btype);
9826 if No (Full_View (Btype)) then
9827 return not Is_Generic_Type (Btype)
9829 not Is_Generic_Type (Root_Type (Btype));
9831 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
9834 return not Is_Frozen (UT) and then Has_Private_Component (UT);
9838 elsif Is_Array_Type (Btype) then
9839 return Has_Private_Component (Component_Type (Btype));
9841 elsif Is_Record_Type (Btype) then
9842 Component := First_Component (Btype);
9843 while Present (Component) loop
9844 if Has_Private_Component (Etype (Component)) then
9848 Next_Component (Component);
9853 elsif Is_Protected_Type (Btype)
9854 and then Present (Corresponding_Record_Type (Btype))
9856 return Has_Private_Component (Corresponding_Record_Type (Btype));
9861 end Has_Private_Component;
9863 ----------------------
9864 -- Has_Signed_Zeros --
9865 ----------------------
9867 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
9869 return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target;
9870 end Has_Signed_Zeros;
9872 ------------------------------
9873 -- Has_Significant_Contract --
9874 ------------------------------
9876 function Has_Significant_Contract (Subp_Id : Entity_Id) return Boolean is
9877 Subp_Nam : constant Name_Id := Chars (Subp_Id);
9880 -- _Finalizer procedure
9882 if Subp_Nam = Name_uFinalizer then
9885 -- _Postconditions procedure
9887 elsif Subp_Nam = Name_uPostconditions then
9890 -- Predicate function
9892 elsif Ekind (Subp_Id) = E_Function
9893 and then Is_Predicate_Function (Subp_Id)
9899 elsif Get_TSS_Name (Subp_Id) /= TSS_Null then
9905 end Has_Significant_Contract;
9907 -----------------------------
9908 -- Has_Static_Array_Bounds --
9909 -----------------------------
9911 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
9912 Ndims : constant Nat := Number_Dimensions (Typ);
9919 -- Unconstrained types do not have static bounds
9921 if not Is_Constrained (Typ) then
9925 -- First treat string literals specially, as the lower bound and length
9926 -- of string literals are not stored like those of arrays.
9928 -- A string literal always has static bounds
9930 if Ekind (Typ) = E_String_Literal_Subtype then
9934 -- Treat all dimensions in turn
9936 Index := First_Index (Typ);
9937 for Indx in 1 .. Ndims loop
9939 -- In case of an illegal index which is not a discrete type, return
9940 -- that the type is not static.
9942 if not Is_Discrete_Type (Etype (Index))
9943 or else Etype (Index) = Any_Type
9948 Get_Index_Bounds (Index, Low, High);
9950 if Error_Posted (Low) or else Error_Posted (High) then
9954 if Is_OK_Static_Expression (Low)
9956 Is_OK_Static_Expression (High)
9966 -- If we fall through the loop, all indexes matched
9969 end Has_Static_Array_Bounds;
9975 function Has_Stream (T : Entity_Id) return Boolean is
9982 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
9985 elsif Is_Array_Type (T) then
9986 return Has_Stream (Component_Type (T));
9988 elsif Is_Record_Type (T) then
9989 E := First_Component (T);
9990 while Present (E) loop
9991 if Has_Stream (Etype (E)) then
10000 elsif Is_Private_Type (T) then
10001 return Has_Stream (Underlying_Type (T));
10012 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
10014 Get_Name_String (Chars (E));
10015 return Name_Buffer (Name_Len) = Suffix;
10022 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
10024 Get_Name_String (Chars (E));
10025 Add_Char_To_Name_Buffer (Suffix);
10029 -------------------
10030 -- Remove_Suffix --
10031 -------------------
10033 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
10035 pragma Assert (Has_Suffix (E, Suffix));
10036 Get_Name_String (Chars (E));
10037 Name_Len := Name_Len - 1;
10041 --------------------------
10042 -- Has_Tagged_Component --
10043 --------------------------
10045 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
10049 if Is_Private_Type (Typ) and then Present (Underlying_Type (Typ)) then
10050 return Has_Tagged_Component (Underlying_Type (Typ));
10052 elsif Is_Array_Type (Typ) then
10053 return Has_Tagged_Component (Component_Type (Typ));
10055 elsif Is_Tagged_Type (Typ) then
10058 elsif Is_Record_Type (Typ) then
10059 Comp := First_Component (Typ);
10060 while Present (Comp) loop
10061 if Has_Tagged_Component (Etype (Comp)) then
10065 Next_Component (Comp);
10073 end Has_Tagged_Component;
10075 -----------------------------
10076 -- Has_Undefined_Reference --
10077 -----------------------------
10079 function Has_Undefined_Reference (Expr : Node_Id) return Boolean is
10080 Has_Undef_Ref : Boolean := False;
10081 -- Flag set when expression Expr contains at least one undefined
10084 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result;
10085 -- Determine whether N denotes a reference and if it does, whether it is
10088 ----------------------------
10089 -- Is_Undefined_Reference --
10090 ----------------------------
10092 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result is
10094 if Is_Entity_Name (N)
10095 and then Present (Entity (N))
10096 and then Entity (N) = Any_Id
10098 Has_Undef_Ref := True;
10103 end Is_Undefined_Reference;
10105 procedure Find_Undefined_References is
10106 new Traverse_Proc (Is_Undefined_Reference);
10108 -- Start of processing for Has_Undefined_Reference
10111 Find_Undefined_References (Expr);
10113 return Has_Undef_Ref;
10114 end Has_Undefined_Reference;
10116 ----------------------------
10117 -- Has_Volatile_Component --
10118 ----------------------------
10120 function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
10124 if Has_Volatile_Components (Typ) then
10127 elsif Is_Array_Type (Typ) then
10128 return Is_Volatile (Component_Type (Typ));
10130 elsif Is_Record_Type (Typ) then
10131 Comp := First_Component (Typ);
10132 while Present (Comp) loop
10133 if Is_Volatile_Object (Comp) then
10137 Comp := Next_Component (Comp);
10142 end Has_Volatile_Component;
10144 -------------------------
10145 -- Implementation_Kind --
10146 -------------------------
10148 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
10149 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
10152 pragma Assert (Present (Impl_Prag));
10153 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
10154 return Chars (Get_Pragma_Arg (Arg));
10155 end Implementation_Kind;
10157 --------------------------
10158 -- Implements_Interface --
10159 --------------------------
10161 function Implements_Interface
10162 (Typ_Ent : Entity_Id;
10163 Iface_Ent : Entity_Id;
10164 Exclude_Parents : Boolean := False) return Boolean
10166 Ifaces_List : Elist_Id;
10168 Iface : Entity_Id := Base_Type (Iface_Ent);
10169 Typ : Entity_Id := Base_Type (Typ_Ent);
10172 if Is_Class_Wide_Type (Typ) then
10173 Typ := Root_Type (Typ);
10176 if not Has_Interfaces (Typ) then
10180 if Is_Class_Wide_Type (Iface) then
10181 Iface := Root_Type (Iface);
10184 Collect_Interfaces (Typ, Ifaces_List);
10186 Elmt := First_Elmt (Ifaces_List);
10187 while Present (Elmt) loop
10188 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
10189 and then Exclude_Parents
10193 elsif Node (Elmt) = Iface then
10201 end Implements_Interface;
10203 ------------------------------------
10204 -- In_Assertion_Expression_Pragma --
10205 ------------------------------------
10207 function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is
10209 Prag : Node_Id := Empty;
10212 -- Climb the parent chain looking for an enclosing pragma
10215 while Present (Par) loop
10216 if Nkind (Par) = N_Pragma then
10220 -- Precondition-like pragmas are expanded into if statements, check
10221 -- the original node instead.
10223 elsif Nkind (Original_Node (Par)) = N_Pragma then
10224 Prag := Original_Node (Par);
10227 -- The expansion of attribute 'Old generates a constant to capture
10228 -- the result of the prefix. If the parent traversal reaches
10229 -- one of these constants, then the node technically came from a
10230 -- postcondition-like pragma. Note that the Ekind is not tested here
10231 -- because N may be the expression of an object declaration which is
10232 -- currently being analyzed. Such objects carry Ekind of E_Void.
10234 elsif Nkind (Par) = N_Object_Declaration
10235 and then Constant_Present (Par)
10236 and then Stores_Attribute_Old_Prefix (Defining_Entity (Par))
10240 -- Prevent the search from going too far
10242 elsif Is_Body_Or_Package_Declaration (Par) then
10246 Par := Parent (Par);
10251 and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag));
10252 end In_Assertion_Expression_Pragma;
10258 function In_Instance return Boolean is
10259 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
10263 S := Current_Scope;
10264 while Present (S) and then S /= Standard_Standard loop
10265 if Ekind_In (S, E_Function, E_Package, E_Procedure)
10266 and then Is_Generic_Instance (S)
10268 -- A child instance is always compiled in the context of a parent
10269 -- instance. Nevertheless, the actuals are not analyzed in an
10270 -- instance context. We detect this case by examining the current
10271 -- compilation unit, which must be a child instance, and checking
10272 -- that it is not currently on the scope stack.
10274 if Is_Child_Unit (Curr_Unit)
10275 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
10276 N_Package_Instantiation
10277 and then not In_Open_Scopes (Curr_Unit)
10291 ----------------------
10292 -- In_Instance_Body --
10293 ----------------------
10295 function In_Instance_Body return Boolean is
10299 S := Current_Scope;
10300 while Present (S) and then S /= Standard_Standard loop
10301 if Ekind_In (S, E_Function, E_Procedure)
10302 and then Is_Generic_Instance (S)
10306 elsif Ekind (S) = E_Package
10307 and then In_Package_Body (S)
10308 and then Is_Generic_Instance (S)
10317 end In_Instance_Body;
10319 -----------------------------
10320 -- In_Instance_Not_Visible --
10321 -----------------------------
10323 function In_Instance_Not_Visible return Boolean is
10327 S := Current_Scope;
10328 while Present (S) and then S /= Standard_Standard loop
10329 if Ekind_In (S, E_Function, E_Procedure)
10330 and then Is_Generic_Instance (S)
10334 elsif Ekind (S) = E_Package
10335 and then (In_Package_Body (S) or else In_Private_Part (S))
10336 and then Is_Generic_Instance (S)
10345 end In_Instance_Not_Visible;
10347 ------------------------------
10348 -- In_Instance_Visible_Part --
10349 ------------------------------
10351 function In_Instance_Visible_Part return Boolean is
10355 S := Current_Scope;
10356 while Present (S) and then S /= Standard_Standard loop
10357 if Ekind (S) = E_Package
10358 and then Is_Generic_Instance (S)
10359 and then not In_Package_Body (S)
10360 and then not In_Private_Part (S)
10369 end In_Instance_Visible_Part;
10371 ---------------------
10372 -- In_Package_Body --
10373 ---------------------
10375 function In_Package_Body return Boolean is
10379 S := Current_Scope;
10380 while Present (S) and then S /= Standard_Standard loop
10381 if Ekind (S) = E_Package and then In_Package_Body (S) then
10389 end In_Package_Body;
10391 --------------------------------
10392 -- In_Parameter_Specification --
10393 --------------------------------
10395 function In_Parameter_Specification (N : Node_Id) return Boolean is
10400 while Present (PN) loop
10401 if Nkind (PN) = N_Parameter_Specification then
10409 end In_Parameter_Specification;
10411 --------------------------
10412 -- In_Pragma_Expression --
10413 --------------------------
10415 function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean is
10422 elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
10428 end In_Pragma_Expression;
10430 -------------------------------------
10431 -- In_Reverse_Storage_Order_Object --
10432 -------------------------------------
10434 function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
10436 Btyp : Entity_Id := Empty;
10439 -- Climb up indexed components
10443 case Nkind (Pref) is
10444 when N_Selected_Component =>
10445 Pref := Prefix (Pref);
10448 when N_Indexed_Component =>
10449 Pref := Prefix (Pref);
10457 if Present (Pref) then
10458 Btyp := Base_Type (Etype (Pref));
10461 return Present (Btyp)
10462 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
10463 and then Reverse_Storage_Order (Btyp);
10464 end In_Reverse_Storage_Order_Object;
10466 --------------------------------------
10467 -- In_Subprogram_Or_Concurrent_Unit --
10468 --------------------------------------
10470 function In_Subprogram_Or_Concurrent_Unit return Boolean is
10475 -- Use scope chain to check successively outer scopes
10477 E := Current_Scope;
10481 if K in Subprogram_Kind
10482 or else K in Concurrent_Kind
10483 or else K in Generic_Subprogram_Kind
10487 elsif E = Standard_Standard then
10493 end In_Subprogram_Or_Concurrent_Unit;
10495 ---------------------
10496 -- In_Visible_Part --
10497 ---------------------
10499 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
10501 return Is_Package_Or_Generic_Package (Scope_Id)
10502 and then In_Open_Scopes (Scope_Id)
10503 and then not In_Package_Body (Scope_Id)
10504 and then not In_Private_Part (Scope_Id);
10505 end In_Visible_Part;
10507 --------------------------------
10508 -- Incomplete_Or_Partial_View --
10509 --------------------------------
10511 function Incomplete_Or_Partial_View (Id : Entity_Id) return Entity_Id is
10512 function Inspect_Decls
10514 Taft : Boolean := False) return Entity_Id;
10515 -- Check whether a declarative region contains the incomplete or partial
10518 -------------------
10519 -- Inspect_Decls --
10520 -------------------
10522 function Inspect_Decls
10524 Taft : Boolean := False) return Entity_Id
10530 Decl := First (Decls);
10531 while Present (Decl) loop
10535 if Nkind (Decl) = N_Incomplete_Type_Declaration then
10536 Match := Defining_Identifier (Decl);
10540 if Nkind_In (Decl, N_Private_Extension_Declaration,
10541 N_Private_Type_Declaration)
10543 Match := Defining_Identifier (Decl);
10548 and then Present (Full_View (Match))
10549 and then Full_View (Match) = Id
10564 -- Start of processing for Incomplete_Or_Partial_View
10567 -- Deferred constant or incomplete type case
10569 Prev := Current_Entity_In_Scope (Id);
10572 and then (Is_Incomplete_Type (Prev) or else Ekind (Prev) = E_Constant)
10573 and then Present (Full_View (Prev))
10574 and then Full_View (Prev) = Id
10579 -- Private or Taft amendment type case
10582 Pkg : constant Entity_Id := Scope (Id);
10583 Pkg_Decl : Node_Id := Pkg;
10586 if Present (Pkg) and then Ekind (Pkg) = E_Package then
10587 while Nkind (Pkg_Decl) /= N_Package_Specification loop
10588 Pkg_Decl := Parent (Pkg_Decl);
10591 -- It is knows that Typ has a private view, look for it in the
10592 -- visible declarations of the enclosing scope. A special case
10593 -- of this is when the two views have been exchanged - the full
10594 -- appears earlier than the private.
10596 if Has_Private_Declaration (Id) then
10597 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
10599 -- Exchanged view case, look in the private declarations
10602 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
10607 -- Otherwise if this is the package body, then Typ is a potential
10608 -- Taft amendment type. The incomplete view should be located in
10609 -- the private declarations of the enclosing scope.
10611 elsif In_Package_Body (Pkg) then
10612 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
10617 -- The type has no incomplete or private view
10620 end Incomplete_Or_Partial_View;
10622 -----------------------------------------
10623 -- Inherit_Default_Init_Cond_Procedure --
10624 -----------------------------------------
10626 procedure Inherit_Default_Init_Cond_Procedure (Typ : Entity_Id) is
10627 Par_Typ : constant Entity_Id := Etype (Typ);
10630 -- A derived type inherits the default initial condition procedure of
10631 -- its parent type.
10633 if No (Default_Init_Cond_Procedure (Typ)) then
10634 Set_Default_Init_Cond_Procedure
10635 (Typ, Default_Init_Cond_Procedure (Par_Typ));
10637 end Inherit_Default_Init_Cond_Procedure;
10639 ----------------------------
10640 -- Inherit_Rep_Item_Chain --
10641 ----------------------------
10643 procedure Inherit_Rep_Item_Chain (Typ : Entity_Id; From_Typ : Entity_Id) is
10644 From_Item : constant Node_Id := First_Rep_Item (From_Typ);
10645 Item : Node_Id := Empty;
10646 Last_Item : Node_Id := Empty;
10649 -- Reach the end of the destination type's chain (if any) and capture
10652 Item := First_Rep_Item (Typ);
10653 while Present (Item) loop
10655 -- Do not inherit a chain that has been inherited already
10657 if Item = From_Item then
10662 Item := Next_Rep_Item (Item);
10665 Item := First_Rep_Item (From_Typ);
10667 -- Additional check when both parent and current type have rep.
10668 -- items, to prevent circularities when the derivation completes
10669 -- a private declaration and inherits from both views of the parent.
10670 -- There may be a remaining problem with the proper ordering of
10671 -- attribute specifications and aspects on the chains of the four
10672 -- entities involved. ???
10674 if Present (Item) and then Present (From_Item) then
10675 while Present (Item) loop
10676 if Item = First_Rep_Item (Typ) then
10680 Item := Next_Rep_Item (Item);
10684 -- When the destination type has a rep item chain, the chain of the
10685 -- source type is appended to it.
10687 if Present (Last_Item) then
10688 Set_Next_Rep_Item (Last_Item, From_Item);
10690 -- Otherwise the destination type directly inherits the rep item chain
10691 -- of the source type (if any).
10694 Set_First_Rep_Item (Typ, From_Item);
10696 end Inherit_Rep_Item_Chain;
10698 ---------------------------------
10699 -- Insert_Explicit_Dereference --
10700 ---------------------------------
10702 procedure Insert_Explicit_Dereference (N : Node_Id) is
10703 New_Prefix : constant Node_Id := Relocate_Node (N);
10704 Ent : Entity_Id := Empty;
10711 Save_Interps (N, New_Prefix);
10714 Make_Explicit_Dereference (Sloc (Parent (N)),
10715 Prefix => New_Prefix));
10717 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
10719 if Is_Overloaded (New_Prefix) then
10721 -- The dereference is also overloaded, and its interpretations are
10722 -- the designated types of the interpretations of the original node.
10724 Set_Etype (N, Any_Type);
10726 Get_First_Interp (New_Prefix, I, It);
10727 while Present (It.Nam) loop
10730 if Is_Access_Type (T) then
10731 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
10734 Get_Next_Interp (I, It);
10740 -- Prefix is unambiguous: mark the original prefix (which might
10741 -- Come_From_Source) as a reference, since the new (relocated) one
10742 -- won't be taken into account.
10744 if Is_Entity_Name (New_Prefix) then
10745 Ent := Entity (New_Prefix);
10746 Pref := New_Prefix;
10748 -- For a retrieval of a subcomponent of some composite object,
10749 -- retrieve the ultimate entity if there is one.
10751 elsif Nkind_In (New_Prefix, N_Selected_Component,
10752 N_Indexed_Component)
10754 Pref := Prefix (New_Prefix);
10755 while Present (Pref)
10756 and then Nkind_In (Pref, N_Selected_Component,
10757 N_Indexed_Component)
10759 Pref := Prefix (Pref);
10762 if Present (Pref) and then Is_Entity_Name (Pref) then
10763 Ent := Entity (Pref);
10767 -- Place the reference on the entity node
10769 if Present (Ent) then
10770 Generate_Reference (Ent, Pref);
10773 end Insert_Explicit_Dereference;
10775 ------------------------------------------
10776 -- Inspect_Deferred_Constant_Completion --
10777 ------------------------------------------
10779 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
10783 Decl := First (Decls);
10784 while Present (Decl) loop
10786 -- Deferred constant signature
10788 if Nkind (Decl) = N_Object_Declaration
10789 and then Constant_Present (Decl)
10790 and then No (Expression (Decl))
10792 -- No need to check internally generated constants
10794 and then Comes_From_Source (Decl)
10796 -- The constant is not completed. A full object declaration or a
10797 -- pragma Import complete a deferred constant.
10799 and then not Has_Completion (Defining_Identifier (Decl))
10802 ("constant declaration requires initialization expression",
10803 Defining_Identifier (Decl));
10806 Decl := Next (Decl);
10808 end Inspect_Deferred_Constant_Completion;
10810 -----------------------------
10811 -- Install_Generic_Formals --
10812 -----------------------------
10814 procedure Install_Generic_Formals (Subp_Id : Entity_Id) is
10818 pragma Assert (Is_Generic_Subprogram (Subp_Id));
10820 E := First_Entity (Subp_Id);
10821 while Present (E) loop
10822 Install_Entity (E);
10825 end Install_Generic_Formals;
10827 -----------------------------
10828 -- Is_Actual_Out_Parameter --
10829 -----------------------------
10831 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
10832 Formal : Entity_Id;
10835 Find_Actual (N, Formal, Call);
10836 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
10837 end Is_Actual_Out_Parameter;
10839 -------------------------
10840 -- Is_Actual_Parameter --
10841 -------------------------
10843 function Is_Actual_Parameter (N : Node_Id) return Boolean is
10844 PK : constant Node_Kind := Nkind (Parent (N));
10848 when N_Parameter_Association =>
10849 return N = Explicit_Actual_Parameter (Parent (N));
10851 when N_Subprogram_Call =>
10852 return Is_List_Member (N)
10854 List_Containing (N) = Parameter_Associations (Parent (N));
10859 end Is_Actual_Parameter;
10861 --------------------------------
10862 -- Is_Actual_Tagged_Parameter --
10863 --------------------------------
10865 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
10866 Formal : Entity_Id;
10869 Find_Actual (N, Formal, Call);
10870 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
10871 end Is_Actual_Tagged_Parameter;
10873 ---------------------
10874 -- Is_Aliased_View --
10875 ---------------------
10877 function Is_Aliased_View (Obj : Node_Id) return Boolean is
10881 if Is_Entity_Name (Obj) then
10888 or else (Present (Renamed_Object (E))
10889 and then Is_Aliased_View (Renamed_Object (E)))))
10891 or else ((Is_Formal (E)
10892 or else Ekind_In (E, E_Generic_In_Out_Parameter,
10893 E_Generic_In_Parameter))
10894 and then Is_Tagged_Type (Etype (E)))
10896 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
10898 -- Current instance of type, either directly or as rewritten
10899 -- reference to the current object.
10901 or else (Is_Entity_Name (Original_Node (Obj))
10902 and then Present (Entity (Original_Node (Obj)))
10903 and then Is_Type (Entity (Original_Node (Obj))))
10905 or else (Is_Type (E) and then E = Current_Scope)
10907 or else (Is_Incomplete_Or_Private_Type (E)
10908 and then Full_View (E) = Current_Scope)
10910 -- Ada 2012 AI05-0053: the return object of an extended return
10911 -- statement is aliased if its type is immutably limited.
10913 or else (Is_Return_Object (E)
10914 and then Is_Limited_View (Etype (E)));
10916 elsif Nkind (Obj) = N_Selected_Component then
10917 return Is_Aliased (Entity (Selector_Name (Obj)));
10919 elsif Nkind (Obj) = N_Indexed_Component then
10920 return Has_Aliased_Components (Etype (Prefix (Obj)))
10922 (Is_Access_Type (Etype (Prefix (Obj)))
10923 and then Has_Aliased_Components
10924 (Designated_Type (Etype (Prefix (Obj)))));
10926 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
10927 return Is_Tagged_Type (Etype (Obj))
10928 and then Is_Aliased_View (Expression (Obj));
10930 elsif Nkind (Obj) = N_Explicit_Dereference then
10931 return Nkind (Original_Node (Obj)) /= N_Function_Call;
10936 end Is_Aliased_View;
10938 -------------------------
10939 -- Is_Ancestor_Package --
10940 -------------------------
10942 function Is_Ancestor_Package
10944 E2 : Entity_Id) return Boolean
10950 while Present (Par) and then Par /= Standard_Standard loop
10955 Par := Scope (Par);
10959 end Is_Ancestor_Package;
10961 ----------------------
10962 -- Is_Atomic_Object --
10963 ----------------------
10965 function Is_Atomic_Object (N : Node_Id) return Boolean is
10967 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
10968 -- Determines if given object has atomic components
10970 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
10971 -- If prefix is an implicit dereference, examine designated type
10973 ----------------------
10974 -- Is_Atomic_Prefix --
10975 ----------------------
10977 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
10979 if Is_Access_Type (Etype (N)) then
10981 Has_Atomic_Components (Designated_Type (Etype (N)));
10983 return Object_Has_Atomic_Components (N);
10985 end Is_Atomic_Prefix;
10987 ----------------------------------
10988 -- Object_Has_Atomic_Components --
10989 ----------------------------------
10991 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
10993 if Has_Atomic_Components (Etype (N))
10994 or else Is_Atomic (Etype (N))
10998 elsif Is_Entity_Name (N)
10999 and then (Has_Atomic_Components (Entity (N))
11000 or else Is_Atomic (Entity (N)))
11004 elsif Nkind (N) = N_Selected_Component
11005 and then Is_Atomic (Entity (Selector_Name (N)))
11009 elsif Nkind (N) = N_Indexed_Component
11010 or else Nkind (N) = N_Selected_Component
11012 return Is_Atomic_Prefix (Prefix (N));
11017 end Object_Has_Atomic_Components;
11019 -- Start of processing for Is_Atomic_Object
11022 -- Predicate is not relevant to subprograms
11024 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
11027 elsif Is_Atomic (Etype (N))
11028 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
11032 elsif Nkind (N) = N_Selected_Component
11033 and then Is_Atomic (Entity (Selector_Name (N)))
11037 elsif Nkind (N) = N_Indexed_Component
11038 or else Nkind (N) = N_Selected_Component
11040 return Is_Atomic_Prefix (Prefix (N));
11045 end Is_Atomic_Object;
11047 -----------------------------
11048 -- Is_Atomic_Or_VFA_Object --
11049 -----------------------------
11051 function Is_Atomic_Or_VFA_Object (N : Node_Id) return Boolean is
11053 return Is_Atomic_Object (N)
11054 or else (Is_Object_Reference (N)
11055 and then Is_Entity_Name (N)
11056 and then (Is_Volatile_Full_Access (Entity (N))
11058 Is_Volatile_Full_Access (Etype (Entity (N)))));
11059 end Is_Atomic_Or_VFA_Object;
11061 -------------------------
11062 -- Is_Attribute_Result --
11063 -------------------------
11065 function Is_Attribute_Result (N : Node_Id) return Boolean is
11067 return Nkind (N) = N_Attribute_Reference
11068 and then Attribute_Name (N) = Name_Result;
11069 end Is_Attribute_Result;
11071 -------------------------
11072 -- Is_Attribute_Update --
11073 -------------------------
11075 function Is_Attribute_Update (N : Node_Id) return Boolean is
11077 return Nkind (N) = N_Attribute_Reference
11078 and then Attribute_Name (N) = Name_Update;
11079 end Is_Attribute_Update;
11081 ------------------------------------
11082 -- Is_Body_Or_Package_Declaration --
11083 ------------------------------------
11085 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
11087 return Nkind_In (N, N_Entry_Body,
11089 N_Package_Declaration,
11093 end Is_Body_Or_Package_Declaration;
11095 -----------------------
11096 -- Is_Bounded_String --
11097 -----------------------
11099 function Is_Bounded_String (T : Entity_Id) return Boolean is
11100 Under : constant Entity_Id := Underlying_Type (Root_Type (T));
11103 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
11104 -- Super_String, or one of the [Wide_]Wide_ versions. This will
11105 -- be True for all the Bounded_String types in instances of the
11106 -- Generic_Bounded_Length generics, and for types derived from those.
11108 return Present (Under)
11109 and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
11110 Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
11111 Is_RTE (Root_Type (Under), RO_WW_Super_String));
11112 end Is_Bounded_String;
11114 -------------------------
11115 -- Is_Child_Or_Sibling --
11116 -------------------------
11118 function Is_Child_Or_Sibling
11119 (Pack_1 : Entity_Id;
11120 Pack_2 : Entity_Id) return Boolean
11122 function Distance_From_Standard (Pack : Entity_Id) return Nat;
11123 -- Given an arbitrary package, return the number of "climbs" necessary
11124 -- to reach scope Standard_Standard.
11126 procedure Equalize_Depths
11127 (Pack : in out Entity_Id;
11128 Depth : in out Nat;
11129 Depth_To_Reach : Nat);
11130 -- Given an arbitrary package, its depth and a target depth to reach,
11131 -- climb the scope chain until the said depth is reached. The pointer
11132 -- to the package and its depth a modified during the climb.
11134 ----------------------------
11135 -- Distance_From_Standard --
11136 ----------------------------
11138 function Distance_From_Standard (Pack : Entity_Id) return Nat is
11145 while Present (Scop) and then Scop /= Standard_Standard loop
11147 Scop := Scope (Scop);
11151 end Distance_From_Standard;
11153 ---------------------
11154 -- Equalize_Depths --
11155 ---------------------
11157 procedure Equalize_Depths
11158 (Pack : in out Entity_Id;
11159 Depth : in out Nat;
11160 Depth_To_Reach : Nat)
11163 -- The package must be at a greater or equal depth
11165 if Depth < Depth_To_Reach then
11166 raise Program_Error;
11169 -- Climb the scope chain until the desired depth is reached
11171 while Present (Pack) and then Depth /= Depth_To_Reach loop
11172 Pack := Scope (Pack);
11173 Depth := Depth - 1;
11175 end Equalize_Depths;
11179 P_1 : Entity_Id := Pack_1;
11180 P_1_Child : Boolean := False;
11181 P_1_Depth : Nat := Distance_From_Standard (P_1);
11182 P_2 : Entity_Id := Pack_2;
11183 P_2_Child : Boolean := False;
11184 P_2_Depth : Nat := Distance_From_Standard (P_2);
11186 -- Start of processing for Is_Child_Or_Sibling
11190 (Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
11192 -- Both packages denote the same entity, therefore they cannot be
11193 -- children or siblings.
11198 -- One of the packages is at a deeper level than the other. Note that
11199 -- both may still come from differen hierarchies.
11207 elsif P_1_Depth > P_2_Depth then
11210 Depth => P_1_Depth,
11211 Depth_To_Reach => P_2_Depth);
11220 elsif P_2_Depth > P_1_Depth then
11223 Depth => P_2_Depth,
11224 Depth_To_Reach => P_1_Depth);
11228 -- At this stage the package pointers have been elevated to the same
11229 -- depth. If the related entities are the same, then one package is a
11230 -- potential child of the other:
11234 -- X became P_1 P_2 or vica versa
11240 return Is_Child_Unit (Pack_1);
11242 else pragma Assert (P_2_Child);
11243 return Is_Child_Unit (Pack_2);
11246 -- The packages may come from the same package chain or from entirely
11247 -- different hierarcies. To determine this, climb the scope stack until
11248 -- a common root is found.
11250 -- (root) (root 1) (root 2)
11255 while Present (P_1) and then Present (P_2) loop
11257 -- The two packages may be siblings
11260 return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2);
11263 P_1 := Scope (P_1);
11264 P_2 := Scope (P_2);
11269 end Is_Child_Or_Sibling;
11271 -----------------------------
11272 -- Is_Concurrent_Interface --
11273 -----------------------------
11275 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
11277 return Is_Interface (T)
11279 (Is_Protected_Interface (T)
11280 or else Is_Synchronized_Interface (T)
11281 or else Is_Task_Interface (T));
11282 end Is_Concurrent_Interface;
11284 -----------------------
11285 -- Is_Constant_Bound --
11286 -----------------------
11288 function Is_Constant_Bound (Exp : Node_Id) return Boolean is
11290 if Compile_Time_Known_Value (Exp) then
11293 elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
11294 return Is_Constant_Object (Entity (Exp))
11295 or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
11297 elsif Nkind (Exp) in N_Binary_Op then
11298 return Is_Constant_Bound (Left_Opnd (Exp))
11299 and then Is_Constant_Bound (Right_Opnd (Exp))
11300 and then Scope (Entity (Exp)) = Standard_Standard;
11305 end Is_Constant_Bound;
11307 ---------------------------
11308 -- Is_Container_Element --
11309 ---------------------------
11311 function Is_Container_Element (Exp : Node_Id) return Boolean is
11312 Loc : constant Source_Ptr := Sloc (Exp);
11313 Pref : constant Node_Id := Prefix (Exp);
11316 -- Call to an indexing aspect
11318 Cont_Typ : Entity_Id;
11319 -- The type of the container being accessed
11321 Elem_Typ : Entity_Id;
11322 -- Its element type
11324 Indexing : Entity_Id;
11325 Is_Const : Boolean;
11326 -- Indicates that constant indexing is used, and the element is thus
11329 Ref_Typ : Entity_Id;
11330 -- The reference type returned by the indexing operation
11333 -- If C is a container, in a context that imposes the element type of
11334 -- that container, the indexing notation C (X) is rewritten as:
11336 -- Indexing (C, X).Discr.all
11338 -- where Indexing is one of the indexing aspects of the container.
11339 -- If the context does not require a reference, the construct can be
11344 -- First, verify that the construct has the proper form
11346 if not Expander_Active then
11349 elsif Nkind (Pref) /= N_Selected_Component then
11352 elsif Nkind (Prefix (Pref)) /= N_Function_Call then
11356 Call := Prefix (Pref);
11357 Ref_Typ := Etype (Call);
11360 if not Has_Implicit_Dereference (Ref_Typ)
11361 or else No (First (Parameter_Associations (Call)))
11362 or else not Is_Entity_Name (Name (Call))
11367 -- Retrieve type of container object, and its iterator aspects
11369 Cont_Typ := Etype (First (Parameter_Associations (Call)));
11370 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Constant_Indexing);
11373 if No (Indexing) then
11375 -- Container should have at least one indexing operation
11379 elsif Entity (Name (Call)) /= Entity (Indexing) then
11381 -- This may be a variable indexing operation
11383 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Variable_Indexing);
11386 or else Entity (Name (Call)) /= Entity (Indexing)
11395 Elem_Typ := Find_Value_Of_Aspect (Cont_Typ, Aspect_Iterator_Element);
11397 if No (Elem_Typ) or else Entity (Elem_Typ) /= Etype (Exp) then
11401 -- Check that the expression is not the target of an assignment, in
11402 -- which case the rewriting is not possible.
11404 if not Is_Const then
11410 while Present (Par)
11412 if Nkind (Parent (Par)) = N_Assignment_Statement
11413 and then Par = Name (Parent (Par))
11417 -- A renaming produces a reference, and the transformation
11420 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
11424 (Nkind (Parent (Par)), N_Function_Call,
11425 N_Procedure_Call_Statement,
11426 N_Entry_Call_Statement)
11428 -- Check that the element is not part of an actual for an
11429 -- in-out parameter.
11436 F := First_Formal (Entity (Name (Parent (Par))));
11437 A := First (Parameter_Associations (Parent (Par)));
11438 while Present (F) loop
11439 if A = Par and then Ekind (F) /= E_In_Parameter then
11448 -- E_In_Parameter in a call: element is not modified.
11453 Par := Parent (Par);
11458 -- The expression has the proper form and the context requires the
11459 -- element type. Retrieve the Element function of the container and
11460 -- rewrite the construct as a call to it.
11466 Op := First_Elmt (Primitive_Operations (Cont_Typ));
11467 while Present (Op) loop
11468 exit when Chars (Node (Op)) = Name_Element;
11477 Make_Function_Call (Loc,
11478 Name => New_Occurrence_Of (Node (Op), Loc),
11479 Parameter_Associations => Parameter_Associations (Call)));
11480 Analyze_And_Resolve (Exp, Entity (Elem_Typ));
11484 end Is_Container_Element;
11486 ----------------------------
11487 -- Is_Contract_Annotation --
11488 ----------------------------
11490 function Is_Contract_Annotation (Item : Node_Id) return Boolean is
11492 return Is_Package_Contract_Annotation (Item)
11494 Is_Subprogram_Contract_Annotation (Item);
11495 end Is_Contract_Annotation;
11497 --------------------------------------
11498 -- Is_Controlling_Limited_Procedure --
11499 --------------------------------------
11501 function Is_Controlling_Limited_Procedure
11502 (Proc_Nam : Entity_Id) return Boolean
11504 Param_Typ : Entity_Id := Empty;
11507 if Ekind (Proc_Nam) = E_Procedure
11508 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
11510 Param_Typ := Etype (Parameter_Type (First (
11511 Parameter_Specifications (Parent (Proc_Nam)))));
11513 -- In this case where an Itype was created, the procedure call has been
11516 elsif Present (Associated_Node_For_Itype (Proc_Nam))
11517 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
11519 Present (Parameter_Associations
11520 (Associated_Node_For_Itype (Proc_Nam)))
11523 Etype (First (Parameter_Associations
11524 (Associated_Node_For_Itype (Proc_Nam))));
11527 if Present (Param_Typ) then
11529 Is_Interface (Param_Typ)
11530 and then Is_Limited_Record (Param_Typ);
11534 end Is_Controlling_Limited_Procedure;
11536 -----------------------------
11537 -- Is_CPP_Constructor_Call --
11538 -----------------------------
11540 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
11542 return Nkind (N) = N_Function_Call
11543 and then Is_CPP_Class (Etype (Etype (N)))
11544 and then Is_Constructor (Entity (Name (N)))
11545 and then Is_Imported (Entity (Name (N)));
11546 end Is_CPP_Constructor_Call;
11548 -------------------------
11549 -- Is_Current_Instance --
11550 -------------------------
11552 function Is_Current_Instance (N : Node_Id) return Boolean is
11553 Typ : constant Entity_Id := Entity (N);
11557 -- Simplest case: entity is a concurrent type and we are currently
11558 -- inside the body. This will eventually be expanded into a
11559 -- call to Self (for tasks) or _object (for protected objects).
11561 if Is_Concurrent_Type (Typ) and then In_Open_Scopes (Typ) then
11565 -- Check whether the context is a (sub)type declaration for the
11569 while Present (P) loop
11570 if Nkind_In (P, N_Full_Type_Declaration,
11571 N_Private_Type_Declaration,
11572 N_Subtype_Declaration)
11573 and then Comes_From_Source (P)
11574 and then Defining_Entity (P) = Typ
11578 -- A subtype name may appear in an aspect specification for a
11579 -- Predicate_Failure aspect, for which we do not construct a
11580 -- wrapper procedure. The subtype will be replaced by the
11581 -- expression being tested when the corresponding predicate
11582 -- check is expanded.
11584 elsif Nkind (P) = N_Aspect_Specification
11585 and then Nkind (Parent (P)) = N_Subtype_Declaration
11589 elsif Nkind (P) = N_Pragma
11591 Get_Pragma_Id (Pragma_Name (P)) = Pragma_Predicate_Failure
11600 -- In any other context this is not a current occurrence
11603 end Is_Current_Instance;
11605 --------------------
11606 -- Is_Declaration --
11607 --------------------
11609 function Is_Declaration (N : Node_Id) return Boolean is
11612 when N_Abstract_Subprogram_Declaration |
11613 N_Exception_Declaration |
11614 N_Exception_Renaming_Declaration |
11615 N_Full_Type_Declaration |
11616 N_Generic_Function_Renaming_Declaration |
11617 N_Generic_Package_Declaration |
11618 N_Generic_Package_Renaming_Declaration |
11619 N_Generic_Procedure_Renaming_Declaration |
11620 N_Generic_Subprogram_Declaration |
11621 N_Number_Declaration |
11622 N_Object_Declaration |
11623 N_Object_Renaming_Declaration |
11624 N_Package_Declaration |
11625 N_Package_Renaming_Declaration |
11626 N_Private_Extension_Declaration |
11627 N_Private_Type_Declaration |
11628 N_Subprogram_Declaration |
11629 N_Subprogram_Renaming_Declaration |
11630 N_Subtype_Declaration =>
11636 end Is_Declaration;
11638 --------------------------------
11639 -- Is_Declared_Within_Variant --
11640 --------------------------------
11642 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
11643 Comp_Decl : constant Node_Id := Parent (Comp);
11644 Comp_List : constant Node_Id := Parent (Comp_Decl);
11646 return Nkind (Parent (Comp_List)) = N_Variant;
11647 end Is_Declared_Within_Variant;
11649 ----------------------------------------------
11650 -- Is_Dependent_Component_Of_Mutable_Object --
11651 ----------------------------------------------
11653 function Is_Dependent_Component_Of_Mutable_Object
11654 (Object : Node_Id) return Boolean
11657 Prefix_Type : Entity_Id;
11658 P_Aliased : Boolean := False;
11661 Deref : Node_Id := Object;
11662 -- Dereference node, in something like X.all.Y(2)
11664 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
11667 -- Find the dereference node if any
11669 while Nkind_In (Deref, N_Indexed_Component,
11670 N_Selected_Component,
11673 Deref := Prefix (Deref);
11676 -- Ada 2005: If we have a component or slice of a dereference,
11677 -- something like X.all.Y (2), and the type of X is access-to-constant,
11678 -- Is_Variable will return False, because it is indeed a constant
11679 -- view. But it might be a view of a variable object, so we want the
11680 -- following condition to be True in that case.
11682 if Is_Variable (Object)
11683 or else (Ada_Version >= Ada_2005
11684 and then Nkind (Deref) = N_Explicit_Dereference)
11686 if Nkind (Object) = N_Selected_Component then
11687 P := Prefix (Object);
11688 Prefix_Type := Etype (P);
11690 if Is_Entity_Name (P) then
11691 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
11692 Prefix_Type := Base_Type (Prefix_Type);
11695 if Is_Aliased (Entity (P)) then
11699 -- A discriminant check on a selected component may be expanded
11700 -- into a dereference when removing side-effects. Recover the
11701 -- original node and its type, which may be unconstrained.
11703 elsif Nkind (P) = N_Explicit_Dereference
11704 and then not (Comes_From_Source (P))
11706 P := Original_Node (P);
11707 Prefix_Type := Etype (P);
11710 -- Check for prefix being an aliased component???
11716 -- A heap object is constrained by its initial value
11718 -- Ada 2005 (AI-363): Always assume the object could be mutable in
11719 -- the dereferenced case, since the access value might denote an
11720 -- unconstrained aliased object, whereas in Ada 95 the designated
11721 -- object is guaranteed to be constrained. A worst-case assumption
11722 -- has to apply in Ada 2005 because we can't tell at compile
11723 -- time whether the object is "constrained by its initial value"
11724 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
11725 -- rules (these rules are acknowledged to need fixing).
11727 if Ada_Version < Ada_2005 then
11728 if Is_Access_Type (Prefix_Type)
11729 or else Nkind (P) = N_Explicit_Dereference
11734 else pragma Assert (Ada_Version >= Ada_2005);
11735 if Is_Access_Type (Prefix_Type) then
11737 -- If the access type is pool-specific, and there is no
11738 -- constrained partial view of the designated type, then the
11739 -- designated object is known to be constrained.
11741 if Ekind (Prefix_Type) = E_Access_Type
11742 and then not Object_Type_Has_Constrained_Partial_View
11743 (Typ => Designated_Type (Prefix_Type),
11744 Scop => Current_Scope)
11748 -- Otherwise (general access type, or there is a constrained
11749 -- partial view of the designated type), we need to check
11750 -- based on the designated type.
11753 Prefix_Type := Designated_Type (Prefix_Type);
11759 Original_Record_Component (Entity (Selector_Name (Object)));
11761 -- As per AI-0017, the renaming is illegal in a generic body, even
11762 -- if the subtype is indefinite.
11764 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
11766 if not Is_Constrained (Prefix_Type)
11767 and then (Is_Definite_Subtype (Prefix_Type)
11769 (Is_Generic_Type (Prefix_Type)
11770 and then Ekind (Current_Scope) = E_Generic_Package
11771 and then In_Package_Body (Current_Scope)))
11773 and then (Is_Declared_Within_Variant (Comp)
11774 or else Has_Discriminant_Dependent_Constraint (Comp))
11775 and then (not P_Aliased or else Ada_Version >= Ada_2005)
11779 -- If the prefix is of an access type at this point, then we want
11780 -- to return False, rather than calling this function recursively
11781 -- on the access object (which itself might be a discriminant-
11782 -- dependent component of some other object, but that isn't
11783 -- relevant to checking the object passed to us). This avoids
11784 -- issuing wrong errors when compiling with -gnatc, where there
11785 -- can be implicit dereferences that have not been expanded.
11787 elsif Is_Access_Type (Etype (Prefix (Object))) then
11792 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
11795 elsif Nkind (Object) = N_Indexed_Component
11796 or else Nkind (Object) = N_Slice
11798 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
11800 -- A type conversion that Is_Variable is a view conversion:
11801 -- go back to the denoted object.
11803 elsif Nkind (Object) = N_Type_Conversion then
11805 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
11810 end Is_Dependent_Component_Of_Mutable_Object;
11812 ---------------------
11813 -- Is_Dereferenced --
11814 ---------------------
11816 function Is_Dereferenced (N : Node_Id) return Boolean is
11817 P : constant Node_Id := Parent (N);
11819 return Nkind_In (P, N_Selected_Component,
11820 N_Explicit_Dereference,
11821 N_Indexed_Component,
11823 and then Prefix (P) = N;
11824 end Is_Dereferenced;
11826 ----------------------
11827 -- Is_Descendant_Of --
11828 ----------------------
11830 function Is_Descendant_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
11835 pragma Assert (Nkind (T1) in N_Entity);
11836 pragma Assert (Nkind (T2) in N_Entity);
11838 T := Base_Type (T1);
11840 -- Immediate return if the types match
11845 -- Comment needed here ???
11847 elsif Ekind (T) = E_Class_Wide_Type then
11848 return Etype (T) = T2;
11856 -- Done if we found the type we are looking for
11861 -- Done if no more derivations to check
11868 -- Following test catches error cases resulting from prev errors
11870 elsif No (Etyp) then
11873 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
11876 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
11880 T := Base_Type (Etyp);
11883 end Is_Descendant_Of;
11885 ----------------------------------------
11886 -- Is_Descendant_Of_Suspension_Object --
11887 ----------------------------------------
11889 function Is_Descendant_Of_Suspension_Object
11890 (Typ : Entity_Id) return Boolean
11892 Cur_Typ : Entity_Id;
11893 Par_Typ : Entity_Id;
11896 -- Climb the type derivation chain checking each parent type against
11897 -- Suspension_Object.
11899 Cur_Typ := Base_Type (Typ);
11900 while Present (Cur_Typ) loop
11901 Par_Typ := Etype (Cur_Typ);
11903 -- The current type is a match
11905 if Is_Suspension_Object (Cur_Typ) then
11908 -- Stop the traversal once the root of the derivation chain has been
11909 -- reached. In that case the current type is its own base type.
11911 elsif Cur_Typ = Par_Typ then
11915 Cur_Typ := Base_Type (Par_Typ);
11919 end Is_Descendant_Of_Suspension_Object;
11921 ---------------------------------------------
11922 -- Is_Double_Precision_Floating_Point_Type --
11923 ---------------------------------------------
11925 function Is_Double_Precision_Floating_Point_Type
11926 (E : Entity_Id) return Boolean is
11928 return Is_Floating_Point_Type (E)
11929 and then Machine_Radix_Value (E) = Uint_2
11930 and then Machine_Mantissa_Value (E) = UI_From_Int (53)
11931 and then Machine_Emax_Value (E) = Uint_2 ** Uint_10
11932 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_10);
11933 end Is_Double_Precision_Floating_Point_Type;
11935 -----------------------------
11936 -- Is_Effectively_Volatile --
11937 -----------------------------
11939 function Is_Effectively_Volatile (Id : Entity_Id) return Boolean is
11941 if Is_Type (Id) then
11943 -- An arbitrary type is effectively volatile when it is subject to
11944 -- pragma Atomic or Volatile.
11946 if Is_Volatile (Id) then
11949 -- An array type is effectively volatile when it is subject to pragma
11950 -- Atomic_Components or Volatile_Components or its compolent type is
11951 -- effectively volatile.
11953 elsif Is_Array_Type (Id) then
11955 Has_Volatile_Components (Id)
11957 Is_Effectively_Volatile (Component_Type (Base_Type (Id)));
11959 -- A protected type is always volatile
11961 elsif Is_Protected_Type (Id) then
11964 -- A descendant of Ada.Synchronous_Task_Control.Suspension_Object is
11965 -- automatically volatile.
11967 elsif Is_Descendant_Of_Suspension_Object (Id) then
11970 -- Otherwise the type is not effectively volatile
11976 -- Otherwise Id denotes an object
11981 or else Has_Volatile_Components (Id)
11982 or else Is_Effectively_Volatile (Etype (Id));
11984 end Is_Effectively_Volatile;
11986 ------------------------------------
11987 -- Is_Effectively_Volatile_Object --
11988 ------------------------------------
11990 function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean is
11992 if Is_Entity_Name (N) then
11993 return Is_Effectively_Volatile (Entity (N));
11995 elsif Nkind (N) = N_Expanded_Name then
11996 return Is_Effectively_Volatile (Entity (N));
11998 elsif Nkind (N) = N_Indexed_Component then
11999 return Is_Effectively_Volatile_Object (Prefix (N));
12001 elsif Nkind (N) = N_Selected_Component then
12003 Is_Effectively_Volatile_Object (Prefix (N))
12005 Is_Effectively_Volatile_Object (Selector_Name (N));
12010 end Is_Effectively_Volatile_Object;
12012 -------------------
12013 -- Is_Entry_Body --
12014 -------------------
12016 function Is_Entry_Body (Id : Entity_Id) return Boolean is
12019 Ekind_In (Id, E_Entry, E_Entry_Family)
12020 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Body;
12023 --------------------------
12024 -- Is_Entry_Declaration --
12025 --------------------------
12027 function Is_Entry_Declaration (Id : Entity_Id) return Boolean is
12030 Ekind_In (Id, E_Entry, E_Entry_Family)
12031 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Declaration;
12032 end Is_Entry_Declaration;
12034 ----------------------------
12035 -- Is_Expression_Function --
12036 ----------------------------
12038 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
12040 if Ekind_In (Subp, E_Function, E_Subprogram_Body) then
12042 Nkind (Original_Node (Unit_Declaration_Node (Subp))) =
12043 N_Expression_Function;
12047 end Is_Expression_Function;
12049 ------------------------------------------
12050 -- Is_Expression_Function_Or_Completion --
12051 ------------------------------------------
12053 function Is_Expression_Function_Or_Completion
12054 (Subp : Entity_Id) return Boolean
12056 Subp_Decl : Node_Id;
12059 if Ekind (Subp) = E_Function then
12060 Subp_Decl := Unit_Declaration_Node (Subp);
12062 -- The function declaration is either an expression function or is
12063 -- completed by an expression function body.
12066 Is_Expression_Function (Subp)
12067 or else (Nkind (Subp_Decl) = N_Subprogram_Declaration
12068 and then Present (Corresponding_Body (Subp_Decl))
12069 and then Is_Expression_Function
12070 (Corresponding_Body (Subp_Decl)));
12072 elsif Ekind (Subp) = E_Subprogram_Body then
12073 return Is_Expression_Function (Subp);
12078 end Is_Expression_Function_Or_Completion;
12080 -----------------------
12081 -- Is_EVF_Expression --
12082 -----------------------
12084 function Is_EVF_Expression (N : Node_Id) return Boolean is
12085 Orig_N : constant Node_Id := Original_Node (N);
12091 -- Detect a reference to a formal parameter of a specific tagged type
12092 -- whose related subprogram is subject to pragma Expresions_Visible with
12095 if Is_Entity_Name (N) and then Present (Entity (N)) then
12100 and then Is_Specific_Tagged_Type (Etype (Id))
12101 and then Extensions_Visible_Status (Id) =
12102 Extensions_Visible_False;
12104 -- A case expression is an EVF expression when it contains at least one
12105 -- EVF dependent_expression. Note that a case expression may have been
12106 -- expanded, hence the use of Original_Node.
12108 elsif Nkind (Orig_N) = N_Case_Expression then
12109 Alt := First (Alternatives (Orig_N));
12110 while Present (Alt) loop
12111 if Is_EVF_Expression (Expression (Alt)) then
12118 -- An if expression is an EVF expression when it contains at least one
12119 -- EVF dependent_expression. Note that an if expression may have been
12120 -- expanded, hence the use of Original_Node.
12122 elsif Nkind (Orig_N) = N_If_Expression then
12123 Expr := Next (First (Expressions (Orig_N)));
12124 while Present (Expr) loop
12125 if Is_EVF_Expression (Expr) then
12132 -- A qualified expression or a type conversion is an EVF expression when
12133 -- its operand is an EVF expression.
12135 elsif Nkind_In (N, N_Qualified_Expression,
12136 N_Unchecked_Type_Conversion,
12139 return Is_EVF_Expression (Expression (N));
12141 -- Attributes 'Loop_Entry, 'Old, and 'Update are EVF expressions when
12142 -- their prefix denotes an EVF expression.
12144 elsif Nkind (N) = N_Attribute_Reference
12145 and then Nam_In (Attribute_Name (N), Name_Loop_Entry,
12149 return Is_EVF_Expression (Prefix (N));
12153 end Is_EVF_Expression;
12159 function Is_False (U : Uint) return Boolean is
12164 ---------------------------
12165 -- Is_Fixed_Model_Number --
12166 ---------------------------
12168 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
12169 S : constant Ureal := Small_Value (T);
12170 M : Urealp.Save_Mark;
12174 R := (U = UR_Trunc (U / S) * S);
12175 Urealp.Release (M);
12177 end Is_Fixed_Model_Number;
12179 -------------------------------
12180 -- Is_Fully_Initialized_Type --
12181 -------------------------------
12183 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
12187 if Is_Scalar_Type (Typ) then
12189 -- A scalar type with an aspect Default_Value is fully initialized
12191 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
12192 -- of a scalar type, but we don't take that into account here, since
12193 -- we don't want these to affect warnings.
12195 return Has_Default_Aspect (Typ);
12197 elsif Is_Access_Type (Typ) then
12200 elsif Is_Array_Type (Typ) then
12201 if Is_Fully_Initialized_Type (Component_Type (Typ))
12202 or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
12207 -- An interesting case, if we have a constrained type one of whose
12208 -- bounds is known to be null, then there are no elements to be
12209 -- initialized, so all the elements are initialized.
12211 if Is_Constrained (Typ) then
12214 Indx_Typ : Entity_Id;
12215 Lbd, Hbd : Node_Id;
12218 Indx := First_Index (Typ);
12219 while Present (Indx) loop
12220 if Etype (Indx) = Any_Type then
12223 -- If index is a range, use directly
12225 elsif Nkind (Indx) = N_Range then
12226 Lbd := Low_Bound (Indx);
12227 Hbd := High_Bound (Indx);
12230 Indx_Typ := Etype (Indx);
12232 if Is_Private_Type (Indx_Typ) then
12233 Indx_Typ := Full_View (Indx_Typ);
12236 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
12239 Lbd := Type_Low_Bound (Indx_Typ);
12240 Hbd := Type_High_Bound (Indx_Typ);
12244 if Compile_Time_Known_Value (Lbd)
12246 Compile_Time_Known_Value (Hbd)
12248 if Expr_Value (Hbd) < Expr_Value (Lbd) then
12258 -- If no null indexes, then type is not fully initialized
12264 elsif Is_Record_Type (Typ) then
12265 if Has_Discriminants (Typ)
12267 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
12268 and then Is_Fully_Initialized_Variant (Typ)
12273 -- We consider bounded string types to be fully initialized, because
12274 -- otherwise we get false alarms when the Data component is not
12275 -- default-initialized.
12277 if Is_Bounded_String (Typ) then
12281 -- Controlled records are considered to be fully initialized if
12282 -- there is a user defined Initialize routine. This may not be
12283 -- entirely correct, but as the spec notes, we are guessing here
12284 -- what is best from the point of view of issuing warnings.
12286 if Is_Controlled (Typ) then
12288 Utyp : constant Entity_Id := Underlying_Type (Typ);
12291 if Present (Utyp) then
12293 Init : constant Entity_Id :=
12294 (Find_Optional_Prim_Op
12295 (Underlying_Type (Typ), Name_Initialize));
12299 and then Comes_From_Source (Init)
12301 Is_Predefined_File_Name
12302 (File_Name (Get_Source_File_Index (Sloc (Init))))
12306 elsif Has_Null_Extension (Typ)
12308 Is_Fully_Initialized_Type
12309 (Etype (Base_Type (Typ)))
12318 -- Otherwise see if all record components are initialized
12324 Ent := First_Entity (Typ);
12325 while Present (Ent) loop
12326 if Ekind (Ent) = E_Component
12327 and then (No (Parent (Ent))
12328 or else No (Expression (Parent (Ent))))
12329 and then not Is_Fully_Initialized_Type (Etype (Ent))
12331 -- Special VM case for tag components, which need to be
12332 -- defined in this case, but are never initialized as VMs
12333 -- are using other dispatching mechanisms. Ignore this
12334 -- uninitialized case. Note that this applies both to the
12335 -- uTag entry and the main vtable pointer (CPP_Class case).
12337 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
12346 -- No uninitialized components, so type is fully initialized.
12347 -- Note that this catches the case of no components as well.
12351 elsif Is_Concurrent_Type (Typ) then
12354 elsif Is_Private_Type (Typ) then
12356 U : constant Entity_Id := Underlying_Type (Typ);
12362 return Is_Fully_Initialized_Type (U);
12369 end Is_Fully_Initialized_Type;
12371 ----------------------------------
12372 -- Is_Fully_Initialized_Variant --
12373 ----------------------------------
12375 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
12376 Loc : constant Source_Ptr := Sloc (Typ);
12377 Constraints : constant List_Id := New_List;
12378 Components : constant Elist_Id := New_Elmt_List;
12379 Comp_Elmt : Elmt_Id;
12381 Comp_List : Node_Id;
12383 Discr_Val : Node_Id;
12385 Report_Errors : Boolean;
12386 pragma Warnings (Off, Report_Errors);
12389 if Serious_Errors_Detected > 0 then
12393 if Is_Record_Type (Typ)
12394 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
12395 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
12397 Comp_List := Component_List (Type_Definition (Parent (Typ)));
12399 Discr := First_Discriminant (Typ);
12400 while Present (Discr) loop
12401 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
12402 Discr_Val := Expression (Parent (Discr));
12404 if Present (Discr_Val)
12405 and then Is_OK_Static_Expression (Discr_Val)
12407 Append_To (Constraints,
12408 Make_Component_Association (Loc,
12409 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
12410 Expression => New_Copy (Discr_Val)));
12418 Next_Discriminant (Discr);
12423 Comp_List => Comp_List,
12424 Governed_By => Constraints,
12425 Into => Components,
12426 Report_Errors => Report_Errors);
12428 -- Check that each component present is fully initialized
12430 Comp_Elmt := First_Elmt (Components);
12431 while Present (Comp_Elmt) loop
12432 Comp_Id := Node (Comp_Elmt);
12434 if Ekind (Comp_Id) = E_Component
12435 and then (No (Parent (Comp_Id))
12436 or else No (Expression (Parent (Comp_Id))))
12437 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
12442 Next_Elmt (Comp_Elmt);
12447 elsif Is_Private_Type (Typ) then
12449 U : constant Entity_Id := Underlying_Type (Typ);
12455 return Is_Fully_Initialized_Variant (U);
12462 end Is_Fully_Initialized_Variant;
12464 ------------------------------------
12465 -- Is_Generic_Declaration_Or_Body --
12466 ------------------------------------
12468 function Is_Generic_Declaration_Or_Body (Decl : Node_Id) return Boolean is
12469 Spec_Decl : Node_Id;
12472 -- Package/subprogram body
12474 if Nkind_In (Decl, N_Package_Body, N_Subprogram_Body)
12475 and then Present (Corresponding_Spec (Decl))
12477 Spec_Decl := Unit_Declaration_Node (Corresponding_Spec (Decl));
12479 -- Package/subprogram body stub
12481 elsif Nkind_In (Decl, N_Package_Body_Stub, N_Subprogram_Body_Stub)
12482 and then Present (Corresponding_Spec_Of_Stub (Decl))
12485 Unit_Declaration_Node (Corresponding_Spec_Of_Stub (Decl));
12493 -- Rather than inspecting the defining entity of the spec declaration,
12494 -- look at its Nkind. This takes care of the case where the analysis of
12495 -- a generic body modifies the Ekind of its spec to allow for recursive
12499 Nkind_In (Spec_Decl, N_Generic_Package_Declaration,
12500 N_Generic_Subprogram_Declaration);
12501 end Is_Generic_Declaration_Or_Body;
12503 ----------------------------
12504 -- Is_Inherited_Operation --
12505 ----------------------------
12507 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
12508 pragma Assert (Is_Overloadable (E));
12509 Kind : constant Node_Kind := Nkind (Parent (E));
12511 return Kind = N_Full_Type_Declaration
12512 or else Kind = N_Private_Extension_Declaration
12513 or else Kind = N_Subtype_Declaration
12514 or else (Ekind (E) = E_Enumeration_Literal
12515 and then Is_Derived_Type (Etype (E)));
12516 end Is_Inherited_Operation;
12518 -------------------------------------
12519 -- Is_Inherited_Operation_For_Type --
12520 -------------------------------------
12522 function Is_Inherited_Operation_For_Type
12524 Typ : Entity_Id) return Boolean
12527 -- Check that the operation has been created by the type declaration
12529 return Is_Inherited_Operation (E)
12530 and then Defining_Identifier (Parent (E)) = Typ;
12531 end Is_Inherited_Operation_For_Type;
12537 function Is_Iterator (Typ : Entity_Id) return Boolean is
12538 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean;
12539 -- Determine whether type Iter_Typ is a predefined forward or reversible
12542 ----------------------
12543 -- Denotes_Iterator --
12544 ----------------------
12546 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean is
12549 Nam_In (Chars (Iter_Typ), Name_Forward_Iterator,
12550 Name_Reversible_Iterator)
12551 and then Is_Predefined_File_Name
12552 (Unit_File_Name (Get_Source_Unit (Iter_Typ)));
12553 end Denotes_Iterator;
12557 Iface_Elmt : Elmt_Id;
12560 -- Start of processing for Is_Iterator
12563 -- The type may be a subtype of a descendant of the proper instance of
12564 -- the predefined interface type, so we must use the root type of the
12565 -- given type. The same is done for Is_Reversible_Iterator.
12567 if Is_Class_Wide_Type (Typ)
12568 and then Denotes_Iterator (Root_Type (Typ))
12572 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
12575 elsif Present (Find_Value_Of_Aspect (Typ, Aspect_Iterable)) then
12579 Collect_Interfaces (Typ, Ifaces);
12581 Iface_Elmt := First_Elmt (Ifaces);
12582 while Present (Iface_Elmt) loop
12583 if Denotes_Iterator (Node (Iface_Elmt)) then
12587 Next_Elmt (Iface_Elmt);
12594 ----------------------------
12595 -- Is_Iterator_Over_Array --
12596 ----------------------------
12598 function Is_Iterator_Over_Array (N : Node_Id) return Boolean is
12599 Container : constant Node_Id := Name (N);
12600 Container_Typ : constant Entity_Id := Base_Type (Etype (Container));
12602 return Is_Array_Type (Container_Typ);
12603 end Is_Iterator_Over_Array;
12609 -- We seem to have a lot of overlapping functions that do similar things
12610 -- (testing for left hand sides or lvalues???).
12612 function Is_LHS (N : Node_Id) return Is_LHS_Result is
12613 P : constant Node_Id := Parent (N);
12616 -- Return True if we are the left hand side of an assignment statement
12618 if Nkind (P) = N_Assignment_Statement then
12619 if Name (P) = N then
12625 -- Case of prefix of indexed or selected component or slice
12627 elsif Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
12628 and then N = Prefix (P)
12630 -- Here we have the case where the parent P is N.Q or N(Q .. R).
12631 -- If P is an LHS, then N is also effectively an LHS, but there
12632 -- is an important exception. If N is of an access type, then
12633 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
12634 -- case this makes N.all a left hand side but not N itself.
12636 -- If we don't know the type yet, this is the case where we return
12637 -- Unknown, since the answer depends on the type which is unknown.
12639 if No (Etype (N)) then
12642 -- We have an Etype set, so we can check it
12644 elsif Is_Access_Type (Etype (N)) then
12647 -- OK, not access type case, so just test whole expression
12653 -- All other cases are not left hand sides
12660 -----------------------------
12661 -- Is_Library_Level_Entity --
12662 -----------------------------
12664 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
12666 -- The following is a small optimization, and it also properly handles
12667 -- discriminals, which in task bodies might appear in expressions before
12668 -- the corresponding procedure has been created, and which therefore do
12669 -- not have an assigned scope.
12671 if Is_Formal (E) then
12675 -- Normal test is simply that the enclosing dynamic scope is Standard
12677 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
12678 end Is_Library_Level_Entity;
12680 --------------------------------
12681 -- Is_Limited_Class_Wide_Type --
12682 --------------------------------
12684 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
12687 Is_Class_Wide_Type (Typ)
12688 and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
12689 end Is_Limited_Class_Wide_Type;
12691 ---------------------------------
12692 -- Is_Local_Variable_Reference --
12693 ---------------------------------
12695 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
12697 if not Is_Entity_Name (Expr) then
12702 Ent : constant Entity_Id := Entity (Expr);
12703 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
12705 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
12708 return Present (Sub) and then Sub = Current_Subprogram;
12712 end Is_Local_Variable_Reference;
12714 -----------------------------------------------
12715 -- Is_Nontrivial_Default_Init_Cond_Procedure --
12716 -----------------------------------------------
12718 function Is_Nontrivial_Default_Init_Cond_Procedure
12719 (Id : Entity_Id) return Boolean
12721 Body_Decl : Node_Id;
12725 if Ekind (Id) = E_Procedure
12726 and then Is_Default_Init_Cond_Procedure (Id)
12729 Unit_Declaration_Node
12730 (Corresponding_Body (Unit_Declaration_Node (Id)));
12732 -- The body of the Default_Initial_Condition procedure must contain
12733 -- at least one statement, otherwise the generation of the subprogram
12736 pragma Assert (Present (Handled_Statement_Sequence (Body_Decl)));
12738 -- To qualify as nontrivial, the first statement of the procedure
12739 -- must be a check in the form of an if statement. If the original
12740 -- Default_Initial_Condition expression was folded, then the first
12741 -- statement is not a check.
12743 Stmt := First (Statements (Handled_Statement_Sequence (Body_Decl)));
12746 Nkind (Stmt) = N_If_Statement
12747 and then Nkind (Original_Node (Stmt)) = N_Pragma;
12751 end Is_Nontrivial_Default_Init_Cond_Procedure;
12753 -------------------------
12754 -- Is_Object_Reference --
12755 -------------------------
12757 function Is_Object_Reference (N : Node_Id) return Boolean is
12758 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean;
12759 -- Determine whether N is the name of an internally-generated renaming
12761 --------------------------------------
12762 -- Is_Internally_Generated_Renaming --
12763 --------------------------------------
12765 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean is
12770 while Present (P) loop
12771 if Nkind (P) = N_Object_Renaming_Declaration then
12772 return not Comes_From_Source (P);
12773 elsif Is_List_Member (P) then
12781 end Is_Internally_Generated_Renaming;
12783 -- Start of processing for Is_Object_Reference
12786 if Is_Entity_Name (N) then
12787 return Present (Entity (N)) and then Is_Object (Entity (N));
12791 when N_Indexed_Component | N_Slice =>
12793 Is_Object_Reference (Prefix (N))
12794 or else Is_Access_Type (Etype (Prefix (N)));
12796 -- In Ada 95, a function call is a constant object; a procedure
12799 when N_Function_Call =>
12800 return Etype (N) /= Standard_Void_Type;
12802 -- Attributes 'Input, 'Loop_Entry, 'Old and 'Result produce
12805 when N_Attribute_Reference =>
12807 Nam_In (Attribute_Name (N), Name_Input,
12812 when N_Selected_Component =>
12814 Is_Object_Reference (Selector_Name (N))
12816 (Is_Object_Reference (Prefix (N))
12817 or else Is_Access_Type (Etype (Prefix (N))));
12819 when N_Explicit_Dereference =>
12822 -- A view conversion of a tagged object is an object reference
12824 when N_Type_Conversion =>
12825 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
12826 and then Is_Tagged_Type (Etype (Expression (N)))
12827 and then Is_Object_Reference (Expression (N));
12829 -- An unchecked type conversion is considered to be an object if
12830 -- the operand is an object (this construction arises only as a
12831 -- result of expansion activities).
12833 when N_Unchecked_Type_Conversion =>
12836 -- Allow string literals to act as objects as long as they appear
12837 -- in internally-generated renamings. The expansion of iterators
12838 -- may generate such renamings when the range involves a string
12841 when N_String_Literal =>
12842 return Is_Internally_Generated_Renaming (Parent (N));
12844 -- AI05-0003: In Ada 2012 a qualified expression is a name.
12845 -- This allows disambiguation of function calls and the use
12846 -- of aggregates in more contexts.
12848 when N_Qualified_Expression =>
12849 if Ada_Version < Ada_2012 then
12852 return Is_Object_Reference (Expression (N))
12853 or else Nkind (Expression (N)) = N_Aggregate;
12860 end Is_Object_Reference;
12862 -----------------------------------
12863 -- Is_OK_Variable_For_Out_Formal --
12864 -----------------------------------
12866 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
12868 Note_Possible_Modification (AV, Sure => True);
12870 -- We must reject parenthesized variable names. Comes_From_Source is
12871 -- checked because there are currently cases where the compiler violates
12872 -- this rule (e.g. passing a task object to its controlled Initialize
12873 -- routine). This should be properly documented in sinfo???
12875 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
12878 -- A variable is always allowed
12880 elsif Is_Variable (AV) then
12883 -- Generalized indexing operations are rewritten as explicit
12884 -- dereferences, and it is only during resolution that we can
12885 -- check whether the context requires an access_to_variable type.
12887 elsif Nkind (AV) = N_Explicit_Dereference
12888 and then Ada_Version >= Ada_2012
12889 and then Nkind (Original_Node (AV)) = N_Indexed_Component
12890 and then Present (Etype (Original_Node (AV)))
12891 and then Has_Implicit_Dereference (Etype (Original_Node (AV)))
12893 return not Is_Access_Constant (Etype (Prefix (AV)));
12895 -- Unchecked conversions are allowed only if they come from the
12896 -- generated code, which sometimes uses unchecked conversions for out
12897 -- parameters in cases where code generation is unaffected. We tell
12898 -- source unchecked conversions by seeing if they are rewrites of
12899 -- an original Unchecked_Conversion function call, or of an explicit
12900 -- conversion of a function call or an aggregate (as may happen in the
12901 -- expansion of a packed array aggregate).
12903 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
12904 if Nkind_In (Original_Node (AV), N_Function_Call, N_Aggregate) then
12907 elsif Comes_From_Source (AV)
12908 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
12912 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
12913 return Is_OK_Variable_For_Out_Formal (Expression (AV));
12919 -- Normal type conversions are allowed if argument is a variable
12921 elsif Nkind (AV) = N_Type_Conversion then
12922 if Is_Variable (Expression (AV))
12923 and then Paren_Count (Expression (AV)) = 0
12925 Note_Possible_Modification (Expression (AV), Sure => True);
12928 -- We also allow a non-parenthesized expression that raises
12929 -- constraint error if it rewrites what used to be a variable
12931 elsif Raises_Constraint_Error (Expression (AV))
12932 and then Paren_Count (Expression (AV)) = 0
12933 and then Is_Variable (Original_Node (Expression (AV)))
12937 -- Type conversion of something other than a variable
12943 -- If this node is rewritten, then test the original form, if that is
12944 -- OK, then we consider the rewritten node OK (for example, if the
12945 -- original node is a conversion, then Is_Variable will not be true
12946 -- but we still want to allow the conversion if it converts a variable).
12948 elsif Original_Node (AV) /= AV then
12950 -- In Ada 2012, the explicit dereference may be a rewritten call to a
12951 -- Reference function.
12953 if Ada_Version >= Ada_2012
12954 and then Nkind (Original_Node (AV)) = N_Function_Call
12956 Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
12959 -- Check that this is not a constant reference.
12961 return not Is_Access_Constant (Etype (Prefix (AV)));
12963 elsif Has_Implicit_Dereference (Etype (Original_Node (AV))) then
12965 not Is_Access_Constant (Etype
12966 (Get_Reference_Discriminant (Etype (Original_Node (AV)))));
12969 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
12972 -- All other non-variables are rejected
12977 end Is_OK_Variable_For_Out_Formal;
12979 ------------------------------------
12980 -- Is_Package_Contract_Annotation --
12981 ------------------------------------
12983 function Is_Package_Contract_Annotation (Item : Node_Id) return Boolean is
12987 if Nkind (Item) = N_Aspect_Specification then
12988 Nam := Chars (Identifier (Item));
12990 else pragma Assert (Nkind (Item) = N_Pragma);
12991 Nam := Pragma_Name (Item);
12994 return Nam = Name_Abstract_State
12995 or else Nam = Name_Initial_Condition
12996 or else Nam = Name_Initializes
12997 or else Nam = Name_Refined_State;
12998 end Is_Package_Contract_Annotation;
13000 -----------------------------------
13001 -- Is_Partially_Initialized_Type --
13002 -----------------------------------
13004 function Is_Partially_Initialized_Type
13006 Include_Implicit : Boolean := True) return Boolean
13009 if Is_Scalar_Type (Typ) then
13012 elsif Is_Access_Type (Typ) then
13013 return Include_Implicit;
13015 elsif Is_Array_Type (Typ) then
13017 -- If component type is partially initialized, so is array type
13019 if Is_Partially_Initialized_Type
13020 (Component_Type (Typ), Include_Implicit)
13024 -- Otherwise we are only partially initialized if we are fully
13025 -- initialized (this is the empty array case, no point in us
13026 -- duplicating that code here).
13029 return Is_Fully_Initialized_Type (Typ);
13032 elsif Is_Record_Type (Typ) then
13034 -- A discriminated type is always partially initialized if in
13037 if Has_Discriminants (Typ) and then Include_Implicit then
13040 -- A tagged type is always partially initialized
13042 elsif Is_Tagged_Type (Typ) then
13045 -- Case of non-discriminated record
13051 Component_Present : Boolean := False;
13052 -- Set True if at least one component is present. If no
13053 -- components are present, then record type is fully
13054 -- initialized (another odd case, like the null array).
13057 -- Loop through components
13059 Ent := First_Entity (Typ);
13060 while Present (Ent) loop
13061 if Ekind (Ent) = E_Component then
13062 Component_Present := True;
13064 -- If a component has an initialization expression then
13065 -- the enclosing record type is partially initialized
13067 if Present (Parent (Ent))
13068 and then Present (Expression (Parent (Ent)))
13072 -- If a component is of a type which is itself partially
13073 -- initialized, then the enclosing record type is also.
13075 elsif Is_Partially_Initialized_Type
13076 (Etype (Ent), Include_Implicit)
13085 -- No initialized components found. If we found any components
13086 -- they were all uninitialized so the result is false.
13088 if Component_Present then
13091 -- But if we found no components, then all the components are
13092 -- initialized so we consider the type to be initialized.
13100 -- Concurrent types are always fully initialized
13102 elsif Is_Concurrent_Type (Typ) then
13105 -- For a private type, go to underlying type. If there is no underlying
13106 -- type then just assume this partially initialized. Not clear if this
13107 -- can happen in a non-error case, but no harm in testing for this.
13109 elsif Is_Private_Type (Typ) then
13111 U : constant Entity_Id := Underlying_Type (Typ);
13116 return Is_Partially_Initialized_Type (U, Include_Implicit);
13120 -- For any other type (are there any?) assume partially initialized
13125 end Is_Partially_Initialized_Type;
13127 ------------------------------------
13128 -- Is_Potentially_Persistent_Type --
13129 ------------------------------------
13131 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
13136 -- For private type, test corresponding full type
13138 if Is_Private_Type (T) then
13139 return Is_Potentially_Persistent_Type (Full_View (T));
13141 -- Scalar types are potentially persistent
13143 elsif Is_Scalar_Type (T) then
13146 -- Record type is potentially persistent if not tagged and the types of
13147 -- all it components are potentially persistent, and no component has
13148 -- an initialization expression.
13150 elsif Is_Record_Type (T)
13151 and then not Is_Tagged_Type (T)
13152 and then not Is_Partially_Initialized_Type (T)
13154 Comp := First_Component (T);
13155 while Present (Comp) loop
13156 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
13159 Next_Entity (Comp);
13165 -- Array type is potentially persistent if its component type is
13166 -- potentially persistent and if all its constraints are static.
13168 elsif Is_Array_Type (T) then
13169 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
13173 Indx := First_Index (T);
13174 while Present (Indx) loop
13175 if not Is_OK_Static_Subtype (Etype (Indx)) then
13184 -- All other types are not potentially persistent
13189 end Is_Potentially_Persistent_Type;
13191 --------------------------------
13192 -- Is_Potentially_Unevaluated --
13193 --------------------------------
13195 function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is
13203 -- A postcondition whose expression is a short-circuit is broken down
13204 -- into individual aspects for better exception reporting. The original
13205 -- short-circuit expression is rewritten as the second operand, and an
13206 -- occurrence of 'Old in that operand is potentially unevaluated.
13207 -- See Sem_ch13.adb for details of this transformation.
13209 if Nkind (Original_Node (Par)) = N_And_Then then
13213 while not Nkind_In (Par, N_If_Expression,
13221 Par := Parent (Par);
13223 -- If the context is not an expression, or if is the result of
13224 -- expansion of an enclosing construct (such as another attribute)
13225 -- the predicate does not apply.
13227 if Nkind (Par) not in N_Subexpr
13228 or else not Comes_From_Source (Par)
13234 if Nkind (Par) = N_If_Expression then
13235 return Is_Elsif (Par) or else Expr /= First (Expressions (Par));
13237 elsif Nkind (Par) = N_Case_Expression then
13238 return Expr /= Expression (Par);
13240 elsif Nkind_In (Par, N_And_Then, N_Or_Else) then
13241 return Expr = Right_Opnd (Par);
13243 elsif Nkind_In (Par, N_In, N_Not_In) then
13244 return Expr /= Left_Opnd (Par);
13249 end Is_Potentially_Unevaluated;
13251 ---------------------------------
13252 -- Is_Protected_Self_Reference --
13253 ---------------------------------
13255 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
13257 function In_Access_Definition (N : Node_Id) return Boolean;
13258 -- Returns true if N belongs to an access definition
13260 --------------------------
13261 -- In_Access_Definition --
13262 --------------------------
13264 function In_Access_Definition (N : Node_Id) return Boolean is
13269 while Present (P) loop
13270 if Nkind (P) = N_Access_Definition then
13278 end In_Access_Definition;
13280 -- Start of processing for Is_Protected_Self_Reference
13283 -- Verify that prefix is analyzed and has the proper form. Note that
13284 -- the attributes Elab_Spec, Elab_Body and Elab_Subp_Body which also
13285 -- produce the address of an entity, do not analyze their prefix
13286 -- because they denote entities that are not necessarily visible.
13287 -- Neither of them can apply to a protected type.
13289 return Ada_Version >= Ada_2005
13290 and then Is_Entity_Name (N)
13291 and then Present (Entity (N))
13292 and then Is_Protected_Type (Entity (N))
13293 and then In_Open_Scopes (Entity (N))
13294 and then not In_Access_Definition (N);
13295 end Is_Protected_Self_Reference;
13297 -----------------------------
13298 -- Is_RCI_Pkg_Spec_Or_Body --
13299 -----------------------------
13301 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
13303 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
13304 -- Return True if the unit of Cunit is an RCI package declaration
13306 ---------------------------
13307 -- Is_RCI_Pkg_Decl_Cunit --
13308 ---------------------------
13310 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
13311 The_Unit : constant Node_Id := Unit (Cunit);
13314 if Nkind (The_Unit) /= N_Package_Declaration then
13318 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
13319 end Is_RCI_Pkg_Decl_Cunit;
13321 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
13324 return Is_RCI_Pkg_Decl_Cunit (Cunit)
13326 (Nkind (Unit (Cunit)) = N_Package_Body
13327 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
13328 end Is_RCI_Pkg_Spec_Or_Body;
13330 -----------------------------------------
13331 -- Is_Remote_Access_To_Class_Wide_Type --
13332 -----------------------------------------
13334 function Is_Remote_Access_To_Class_Wide_Type
13335 (E : Entity_Id) return Boolean
13338 -- A remote access to class-wide type is a general access to object type
13339 -- declared in the visible part of a Remote_Types or Remote_Call_
13342 return Ekind (E) = E_General_Access_Type
13343 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
13344 end Is_Remote_Access_To_Class_Wide_Type;
13346 -----------------------------------------
13347 -- Is_Remote_Access_To_Subprogram_Type --
13348 -----------------------------------------
13350 function Is_Remote_Access_To_Subprogram_Type
13351 (E : Entity_Id) return Boolean
13354 return (Ekind (E) = E_Access_Subprogram_Type
13355 or else (Ekind (E) = E_Record_Type
13356 and then Present (Corresponding_Remote_Type (E))))
13357 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
13358 end Is_Remote_Access_To_Subprogram_Type;
13360 --------------------
13361 -- Is_Remote_Call --
13362 --------------------
13364 function Is_Remote_Call (N : Node_Id) return Boolean is
13366 if Nkind (N) not in N_Subprogram_Call then
13368 -- An entry call cannot be remote
13372 elsif Nkind (Name (N)) in N_Has_Entity
13373 and then Is_Remote_Call_Interface (Entity (Name (N)))
13375 -- A subprogram declared in the spec of a RCI package is remote
13379 elsif Nkind (Name (N)) = N_Explicit_Dereference
13380 and then Is_Remote_Access_To_Subprogram_Type
13381 (Etype (Prefix (Name (N))))
13383 -- The dereference of a RAS is a remote call
13387 elsif Present (Controlling_Argument (N))
13388 and then Is_Remote_Access_To_Class_Wide_Type
13389 (Etype (Controlling_Argument (N)))
13391 -- Any primitive operation call with a controlling argument of
13392 -- a RACW type is a remote call.
13397 -- All other calls are local calls
13400 end Is_Remote_Call;
13402 ----------------------
13403 -- Is_Renamed_Entry --
13404 ----------------------
13406 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
13407 Orig_Node : Node_Id := Empty;
13408 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
13410 function Is_Entry (Nam : Node_Id) return Boolean;
13411 -- Determine whether Nam is an entry. Traverse selectors if there are
13412 -- nested selected components.
13418 function Is_Entry (Nam : Node_Id) return Boolean is
13420 if Nkind (Nam) = N_Selected_Component then
13421 return Is_Entry (Selector_Name (Nam));
13424 return Ekind (Entity (Nam)) = E_Entry;
13427 -- Start of processing for Is_Renamed_Entry
13430 if Present (Alias (Proc_Nam)) then
13431 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
13434 -- Look for a rewritten subprogram renaming declaration
13436 if Nkind (Subp_Decl) = N_Subprogram_Declaration
13437 and then Present (Original_Node (Subp_Decl))
13439 Orig_Node := Original_Node (Subp_Decl);
13442 -- The rewritten subprogram is actually an entry
13444 if Present (Orig_Node)
13445 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
13446 and then Is_Entry (Name (Orig_Node))
13452 end Is_Renamed_Entry;
13454 -----------------------------
13455 -- Is_Renaming_Declaration --
13456 -----------------------------
13458 function Is_Renaming_Declaration (N : Node_Id) return Boolean is
13461 when N_Exception_Renaming_Declaration |
13462 N_Generic_Function_Renaming_Declaration |
13463 N_Generic_Package_Renaming_Declaration |
13464 N_Generic_Procedure_Renaming_Declaration |
13465 N_Object_Renaming_Declaration |
13466 N_Package_Renaming_Declaration |
13467 N_Subprogram_Renaming_Declaration =>
13473 end Is_Renaming_Declaration;
13475 ----------------------------
13476 -- Is_Reversible_Iterator --
13477 ----------------------------
13479 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
13480 Ifaces_List : Elist_Id;
13481 Iface_Elmt : Elmt_Id;
13485 if Is_Class_Wide_Type (Typ)
13486 and then Chars (Root_Type (Typ)) = Name_Reversible_Iterator
13487 and then Is_Predefined_File_Name
13488 (Unit_File_Name (Get_Source_Unit (Root_Type (Typ))))
13492 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
13496 Collect_Interfaces (Typ, Ifaces_List);
13498 Iface_Elmt := First_Elmt (Ifaces_List);
13499 while Present (Iface_Elmt) loop
13500 Iface := Node (Iface_Elmt);
13501 if Chars (Iface) = Name_Reversible_Iterator
13503 Is_Predefined_File_Name
13504 (Unit_File_Name (Get_Source_Unit (Iface)))
13509 Next_Elmt (Iface_Elmt);
13514 end Is_Reversible_Iterator;
13516 ----------------------
13517 -- Is_Selector_Name --
13518 ----------------------
13520 function Is_Selector_Name (N : Node_Id) return Boolean is
13522 if not Is_List_Member (N) then
13524 P : constant Node_Id := Parent (N);
13526 return Nkind_In (P, N_Expanded_Name,
13527 N_Generic_Association,
13528 N_Parameter_Association,
13529 N_Selected_Component)
13530 and then Selector_Name (P) = N;
13535 L : constant List_Id := List_Containing (N);
13536 P : constant Node_Id := Parent (L);
13538 return (Nkind (P) = N_Discriminant_Association
13539 and then Selector_Names (P) = L)
13541 (Nkind (P) = N_Component_Association
13542 and then Choices (P) = L);
13545 end Is_Selector_Name;
13547 ---------------------------------
13548 -- Is_Single_Concurrent_Object --
13549 ---------------------------------
13551 function Is_Single_Concurrent_Object (Id : Entity_Id) return Boolean is
13554 Is_Single_Protected_Object (Id) or else Is_Single_Task_Object (Id);
13555 end Is_Single_Concurrent_Object;
13557 -------------------------------
13558 -- Is_Single_Concurrent_Type --
13559 -------------------------------
13561 function Is_Single_Concurrent_Type (Id : Entity_Id) return Boolean is
13564 Ekind_In (Id, E_Protected_Type, E_Task_Type)
13565 and then Is_Single_Concurrent_Type_Declaration
13566 (Declaration_Node (Id));
13567 end Is_Single_Concurrent_Type;
13569 -------------------------------------------
13570 -- Is_Single_Concurrent_Type_Declaration --
13571 -------------------------------------------
13573 function Is_Single_Concurrent_Type_Declaration
13574 (N : Node_Id) return Boolean
13577 return Nkind_In (Original_Node (N), N_Single_Protected_Declaration,
13578 N_Single_Task_Declaration);
13579 end Is_Single_Concurrent_Type_Declaration;
13581 ---------------------------------------------
13582 -- Is_Single_Precision_Floating_Point_Type --
13583 ---------------------------------------------
13585 function Is_Single_Precision_Floating_Point_Type
13586 (E : Entity_Id) return Boolean is
13588 return Is_Floating_Point_Type (E)
13589 and then Machine_Radix_Value (E) = Uint_2
13590 and then Machine_Mantissa_Value (E) = Uint_24
13591 and then Machine_Emax_Value (E) = Uint_2 ** Uint_7
13592 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_7);
13593 end Is_Single_Precision_Floating_Point_Type;
13595 --------------------------------
13596 -- Is_Single_Protected_Object --
13597 --------------------------------
13599 function Is_Single_Protected_Object (Id : Entity_Id) return Boolean is
13602 Ekind (Id) = E_Variable
13603 and then Ekind (Etype (Id)) = E_Protected_Type
13604 and then Is_Single_Concurrent_Type (Etype (Id));
13605 end Is_Single_Protected_Object;
13607 ---------------------------
13608 -- Is_Single_Task_Object --
13609 ---------------------------
13611 function Is_Single_Task_Object (Id : Entity_Id) return Boolean is
13614 Ekind (Id) = E_Variable
13615 and then Ekind (Etype (Id)) = E_Task_Type
13616 and then Is_Single_Concurrent_Type (Etype (Id));
13617 end Is_Single_Task_Object;
13619 -------------------------------------
13620 -- Is_SPARK_05_Initialization_Expr --
13621 -------------------------------------
13623 function Is_SPARK_05_Initialization_Expr (N : Node_Id) return Boolean is
13626 Comp_Assn : Node_Id;
13627 Orig_N : constant Node_Id := Original_Node (N);
13632 if not Comes_From_Source (Orig_N) then
13636 pragma Assert (Nkind (Orig_N) in N_Subexpr);
13638 case Nkind (Orig_N) is
13639 when N_Character_Literal |
13640 N_Integer_Literal |
13642 N_String_Literal =>
13645 when N_Identifier |
13647 if Is_Entity_Name (Orig_N)
13648 and then Present (Entity (Orig_N)) -- needed in some cases
13650 case Ekind (Entity (Orig_N)) is
13652 E_Enumeration_Literal |
13657 if Is_Type (Entity (Orig_N)) then
13665 when N_Qualified_Expression |
13666 N_Type_Conversion =>
13667 Is_Ok := Is_SPARK_05_Initialization_Expr (Expression (Orig_N));
13670 Is_Ok := Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
13674 N_Membership_Test =>
13675 Is_Ok := Is_SPARK_05_Initialization_Expr (Left_Opnd (Orig_N))
13677 Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
13680 N_Extension_Aggregate =>
13681 if Nkind (Orig_N) = N_Extension_Aggregate then
13683 Is_SPARK_05_Initialization_Expr (Ancestor_Part (Orig_N));
13686 Expr := First (Expressions (Orig_N));
13687 while Present (Expr) loop
13688 if not Is_SPARK_05_Initialization_Expr (Expr) then
13696 Comp_Assn := First (Component_Associations (Orig_N));
13697 while Present (Comp_Assn) loop
13698 Expr := Expression (Comp_Assn);
13700 -- Note: test for Present here needed for box assocation
13703 and then not Is_SPARK_05_Initialization_Expr (Expr)
13712 when N_Attribute_Reference =>
13713 if Nkind (Prefix (Orig_N)) in N_Subexpr then
13714 Is_Ok := Is_SPARK_05_Initialization_Expr (Prefix (Orig_N));
13717 Expr := First (Expressions (Orig_N));
13718 while Present (Expr) loop
13719 if not Is_SPARK_05_Initialization_Expr (Expr) then
13727 -- Selected components might be expanded named not yet resolved, so
13728 -- default on the safe side. (Eg on sparklex.ads)
13730 when N_Selected_Component =>
13739 end Is_SPARK_05_Initialization_Expr;
13741 ----------------------------------
13742 -- Is_SPARK_05_Object_Reference --
13743 ----------------------------------
13745 function Is_SPARK_05_Object_Reference (N : Node_Id) return Boolean is
13747 if Is_Entity_Name (N) then
13748 return Present (Entity (N))
13750 (Ekind_In (Entity (N), E_Constant, E_Variable)
13751 or else Ekind (Entity (N)) in Formal_Kind);
13755 when N_Selected_Component =>
13756 return Is_SPARK_05_Object_Reference (Prefix (N));
13762 end Is_SPARK_05_Object_Reference;
13764 -----------------------------
13765 -- Is_Specific_Tagged_Type --
13766 -----------------------------
13768 function Is_Specific_Tagged_Type (Typ : Entity_Id) return Boolean is
13769 Full_Typ : Entity_Id;
13772 -- Handle private types
13774 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
13775 Full_Typ := Full_View (Typ);
13780 -- A specific tagged type is a non-class-wide tagged type
13782 return Is_Tagged_Type (Full_Typ) and not Is_Class_Wide_Type (Full_Typ);
13783 end Is_Specific_Tagged_Type;
13789 function Is_Statement (N : Node_Id) return Boolean is
13792 Nkind (N) in N_Statement_Other_Than_Procedure_Call
13793 or else Nkind (N) = N_Procedure_Call_Statement;
13796 ---------------------------------------
13797 -- Is_Subprogram_Contract_Annotation --
13798 ---------------------------------------
13800 function Is_Subprogram_Contract_Annotation
13801 (Item : Node_Id) return Boolean
13806 if Nkind (Item) = N_Aspect_Specification then
13807 Nam := Chars (Identifier (Item));
13809 else pragma Assert (Nkind (Item) = N_Pragma);
13810 Nam := Pragma_Name (Item);
13813 return Nam = Name_Contract_Cases
13814 or else Nam = Name_Depends
13815 or else Nam = Name_Extensions_Visible
13816 or else Nam = Name_Global
13817 or else Nam = Name_Post
13818 or else Nam = Name_Post_Class
13819 or else Nam = Name_Postcondition
13820 or else Nam = Name_Pre
13821 or else Nam = Name_Pre_Class
13822 or else Nam = Name_Precondition
13823 or else Nam = Name_Refined_Depends
13824 or else Nam = Name_Refined_Global
13825 or else Nam = Name_Refined_Post
13826 or else Nam = Name_Test_Case;
13827 end Is_Subprogram_Contract_Annotation;
13829 --------------------------------------------------
13830 -- Is_Subprogram_Stub_Without_Prior_Declaration --
13831 --------------------------------------------------
13833 function Is_Subprogram_Stub_Without_Prior_Declaration
13834 (N : Node_Id) return Boolean
13837 -- A subprogram stub without prior declaration serves as declaration for
13838 -- the actual subprogram body. As such, it has an attached defining
13839 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
13841 return Nkind (N) = N_Subprogram_Body_Stub
13842 and then Ekind (Defining_Entity (N)) /= E_Subprogram_Body;
13843 end Is_Subprogram_Stub_Without_Prior_Declaration;
13845 --------------------------
13846 -- Is_Suspension_Object --
13847 --------------------------
13849 function Is_Suspension_Object (Id : Entity_Id) return Boolean is
13851 -- This approach does an exact name match rather than to rely on
13852 -- RTSfind. Routine Is_Effectively_Volatile is used by clients of the
13853 -- front end at point where all auxiliary tables are locked and any
13854 -- modifications to them are treated as violations. Do not tamper with
13855 -- the tables, instead examine the Chars fields of all the scopes of Id.
13858 Chars (Id) = Name_Suspension_Object
13859 and then Present (Scope (Id))
13860 and then Chars (Scope (Id)) = Name_Synchronous_Task_Control
13861 and then Present (Scope (Scope (Id)))
13862 and then Chars (Scope (Scope (Id))) = Name_Ada
13863 and then Present (Scope (Scope (Scope (Id))))
13864 and then Scope (Scope (Scope (Id))) = Standard_Standard;
13865 end Is_Suspension_Object;
13867 ----------------------------
13868 -- Is_Synchronized_Object --
13869 ----------------------------
13871 function Is_Synchronized_Object (Id : Entity_Id) return Boolean is
13875 if Is_Object (Id) then
13877 -- The object is synchronized if it is of a type that yields a
13878 -- synchronized object.
13880 if Yields_Synchronized_Object (Etype (Id)) then
13883 -- The object is synchronized if it is atomic and Async_Writers is
13886 elsif Is_Atomic (Id) and then Async_Writers_Enabled (Id) then
13889 -- A constant is a synchronized object by default
13891 elsif Ekind (Id) = E_Constant then
13894 -- A variable is a synchronized object if it is subject to pragma
13895 -- Constant_After_Elaboration.
13897 elsif Ekind (Id) = E_Variable then
13898 Prag := Get_Pragma (Id, Pragma_Constant_After_Elaboration);
13900 return Present (Prag) and then Is_Enabled_Pragma (Prag);
13904 -- Otherwise the input is not an object or it does not qualify as a
13905 -- synchronized object.
13908 end Is_Synchronized_Object;
13910 ---------------------------------
13911 -- Is_Synchronized_Tagged_Type --
13912 ---------------------------------
13914 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
13915 Kind : constant Entity_Kind := Ekind (Base_Type (E));
13918 -- A task or protected type derived from an interface is a tagged type.
13919 -- Such a tagged type is called a synchronized tagged type, as are
13920 -- synchronized interfaces and private extensions whose declaration
13921 -- includes the reserved word synchronized.
13923 return (Is_Tagged_Type (E)
13924 and then (Kind = E_Task_Type
13926 Kind = E_Protected_Type))
13929 and then Is_Synchronized_Interface (E))
13931 (Ekind (E) = E_Record_Type_With_Private
13932 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
13933 and then (Synchronized_Present (Parent (E))
13934 or else Is_Synchronized_Interface (Etype (E))));
13935 end Is_Synchronized_Tagged_Type;
13941 function Is_Transfer (N : Node_Id) return Boolean is
13942 Kind : constant Node_Kind := Nkind (N);
13945 if Kind = N_Simple_Return_Statement
13947 Kind = N_Extended_Return_Statement
13949 Kind = N_Goto_Statement
13951 Kind = N_Raise_Statement
13953 Kind = N_Requeue_Statement
13957 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
13958 and then No (Condition (N))
13962 elsif Kind = N_Procedure_Call_Statement
13963 and then Is_Entity_Name (Name (N))
13964 and then Present (Entity (Name (N)))
13965 and then No_Return (Entity (Name (N)))
13969 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
13981 function Is_True (U : Uint) return Boolean is
13986 --------------------------------------
13987 -- Is_Unchecked_Conversion_Instance --
13988 --------------------------------------
13990 function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is
13991 Gen_Par : Entity_Id;
13994 -- Look for a function whose generic parent is the predefined intrinsic
13995 -- function Unchecked_Conversion.
13997 if Ekind (Id) = E_Function then
13998 Gen_Par := Generic_Parent (Parent (Id));
14002 and then Chars (Gen_Par) = Name_Unchecked_Conversion
14003 and then Is_Intrinsic_Subprogram (Gen_Par)
14004 and then Is_Predefined_File_Name
14005 (Unit_File_Name (Get_Source_Unit (Gen_Par)));
14009 end Is_Unchecked_Conversion_Instance;
14011 -------------------------------
14012 -- Is_Universal_Numeric_Type --
14013 -------------------------------
14015 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
14017 return T = Universal_Integer or else T = Universal_Real;
14018 end Is_Universal_Numeric_Type;
14020 ----------------------------
14021 -- Is_Variable_Size_Array --
14022 ----------------------------
14024 function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
14028 pragma Assert (Is_Array_Type (E));
14030 -- Check if some index is initialized with a non-constant value
14032 Idx := First_Index (E);
14033 while Present (Idx) loop
14034 if Nkind (Idx) = N_Range then
14035 if not Is_Constant_Bound (Low_Bound (Idx))
14036 or else not Is_Constant_Bound (High_Bound (Idx))
14042 Idx := Next_Index (Idx);
14046 end Is_Variable_Size_Array;
14048 -----------------------------
14049 -- Is_Variable_Size_Record --
14050 -----------------------------
14052 function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
14054 Comp_Typ : Entity_Id;
14057 pragma Assert (Is_Record_Type (E));
14059 Comp := First_Entity (E);
14060 while Present (Comp) loop
14061 Comp_Typ := Etype (Comp);
14063 -- Recursive call if the record type has discriminants
14065 if Is_Record_Type (Comp_Typ)
14066 and then Has_Discriminants (Comp_Typ)
14067 and then Is_Variable_Size_Record (Comp_Typ)
14071 elsif Is_Array_Type (Comp_Typ)
14072 and then Is_Variable_Size_Array (Comp_Typ)
14077 Next_Entity (Comp);
14081 end Is_Variable_Size_Record;
14087 function Is_Variable
14089 Use_Original_Node : Boolean := True) return Boolean
14091 Orig_Node : Node_Id;
14093 function In_Protected_Function (E : Entity_Id) return Boolean;
14094 -- Within a protected function, the private components of the enclosing
14095 -- protected type are constants. A function nested within a (protected)
14096 -- procedure is not itself protected. Within the body of a protected
14097 -- function the current instance of the protected type is a constant.
14099 function Is_Variable_Prefix (P : Node_Id) return Boolean;
14100 -- Prefixes can involve implicit dereferences, in which case we must
14101 -- test for the case of a reference of a constant access type, which can
14102 -- can never be a variable.
14104 ---------------------------
14105 -- In_Protected_Function --
14106 ---------------------------
14108 function In_Protected_Function (E : Entity_Id) return Boolean is
14113 -- E is the current instance of a type
14115 if Is_Type (E) then
14124 if not Is_Protected_Type (Prot) then
14128 S := Current_Scope;
14129 while Present (S) and then S /= Prot loop
14130 if Ekind (S) = E_Function and then Scope (S) = Prot then
14139 end In_Protected_Function;
14141 ------------------------
14142 -- Is_Variable_Prefix --
14143 ------------------------
14145 function Is_Variable_Prefix (P : Node_Id) return Boolean is
14147 if Is_Access_Type (Etype (P)) then
14148 return not Is_Access_Constant (Root_Type (Etype (P)));
14150 -- For the case of an indexed component whose prefix has a packed
14151 -- array type, the prefix has been rewritten into a type conversion.
14152 -- Determine variable-ness from the converted expression.
14154 elsif Nkind (P) = N_Type_Conversion
14155 and then not Comes_From_Source (P)
14156 and then Is_Array_Type (Etype (P))
14157 and then Is_Packed (Etype (P))
14159 return Is_Variable (Expression (P));
14162 return Is_Variable (P);
14164 end Is_Variable_Prefix;
14166 -- Start of processing for Is_Variable
14169 -- Special check, allow x'Deref(expr) as a variable
14171 if Nkind (N) = N_Attribute_Reference
14172 and then Attribute_Name (N) = Name_Deref
14177 -- Check if we perform the test on the original node since this may be a
14178 -- test of syntactic categories which must not be disturbed by whatever
14179 -- rewriting might have occurred. For example, an aggregate, which is
14180 -- certainly NOT a variable, could be turned into a variable by
14183 if Use_Original_Node then
14184 Orig_Node := Original_Node (N);
14189 -- Definitely OK if Assignment_OK is set. Since this is something that
14190 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
14192 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
14195 -- Normally we go to the original node, but there is one exception where
14196 -- we use the rewritten node, namely when it is an explicit dereference.
14197 -- The generated code may rewrite a prefix which is an access type with
14198 -- an explicit dereference. The dereference is a variable, even though
14199 -- the original node may not be (since it could be a constant of the
14202 -- In Ada 2005 we have a further case to consider: the prefix may be a
14203 -- function call given in prefix notation. The original node appears to
14204 -- be a selected component, but we need to examine the call.
14206 elsif Nkind (N) = N_Explicit_Dereference
14207 and then Nkind (Orig_Node) /= N_Explicit_Dereference
14208 and then Present (Etype (Orig_Node))
14209 and then Is_Access_Type (Etype (Orig_Node))
14211 -- Note that if the prefix is an explicit dereference that does not
14212 -- come from source, we must check for a rewritten function call in
14213 -- prefixed notation before other forms of rewriting, to prevent a
14217 (Nkind (Orig_Node) = N_Function_Call
14218 and then not Is_Access_Constant (Etype (Prefix (N))))
14220 Is_Variable_Prefix (Original_Node (Prefix (N)));
14222 -- in Ada 2012, the dereference may have been added for a type with
14223 -- a declared implicit dereference aspect. Check that it is not an
14224 -- access to constant.
14226 elsif Nkind (N) = N_Explicit_Dereference
14227 and then Present (Etype (Orig_Node))
14228 and then Ada_Version >= Ada_2012
14229 and then Has_Implicit_Dereference (Etype (Orig_Node))
14231 return not Is_Access_Constant (Etype (Prefix (N)));
14233 -- A function call is never a variable
14235 elsif Nkind (N) = N_Function_Call then
14238 -- All remaining checks use the original node
14240 elsif Is_Entity_Name (Orig_Node)
14241 and then Present (Entity (Orig_Node))
14244 E : constant Entity_Id := Entity (Orig_Node);
14245 K : constant Entity_Kind := Ekind (E);
14248 return (K = E_Variable
14249 and then Nkind (Parent (E)) /= N_Exception_Handler)
14250 or else (K = E_Component
14251 and then not In_Protected_Function (E))
14252 or else K = E_Out_Parameter
14253 or else K = E_In_Out_Parameter
14254 or else K = E_Generic_In_Out_Parameter
14256 -- Current instance of type. If this is a protected type, check
14257 -- we are not within the body of one of its protected functions.
14259 or else (Is_Type (E)
14260 and then In_Open_Scopes (E)
14261 and then not In_Protected_Function (E))
14263 or else (Is_Incomplete_Or_Private_Type (E)
14264 and then In_Open_Scopes (Full_View (E)));
14268 case Nkind (Orig_Node) is
14269 when N_Indexed_Component | N_Slice =>
14270 return Is_Variable_Prefix (Prefix (Orig_Node));
14272 when N_Selected_Component =>
14273 return (Is_Variable (Selector_Name (Orig_Node))
14274 and then Is_Variable_Prefix (Prefix (Orig_Node)))
14276 (Nkind (N) = N_Expanded_Name
14277 and then Scope (Entity (N)) = Entity (Prefix (N)));
14279 -- For an explicit dereference, the type of the prefix cannot
14280 -- be an access to constant or an access to subprogram.
14282 when N_Explicit_Dereference =>
14284 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
14286 return Is_Access_Type (Typ)
14287 and then not Is_Access_Constant (Root_Type (Typ))
14288 and then Ekind (Typ) /= E_Access_Subprogram_Type;
14291 -- The type conversion is the case where we do not deal with the
14292 -- context dependent special case of an actual parameter. Thus
14293 -- the type conversion is only considered a variable for the
14294 -- purposes of this routine if the target type is tagged. However,
14295 -- a type conversion is considered to be a variable if it does not
14296 -- come from source (this deals for example with the conversions
14297 -- of expressions to their actual subtypes).
14299 when N_Type_Conversion =>
14300 return Is_Variable (Expression (Orig_Node))
14302 (not Comes_From_Source (Orig_Node)
14304 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
14306 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
14308 -- GNAT allows an unchecked type conversion as a variable. This
14309 -- only affects the generation of internal expanded code, since
14310 -- calls to instantiations of Unchecked_Conversion are never
14311 -- considered variables (since they are function calls).
14313 when N_Unchecked_Type_Conversion =>
14314 return Is_Variable (Expression (Orig_Node));
14322 ---------------------------
14323 -- Is_Visibly_Controlled --
14324 ---------------------------
14326 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
14327 Root : constant Entity_Id := Root_Type (T);
14329 return Chars (Scope (Root)) = Name_Finalization
14330 and then Chars (Scope (Scope (Root))) = Name_Ada
14331 and then Scope (Scope (Scope (Root))) = Standard_Standard;
14332 end Is_Visibly_Controlled;
14334 --------------------------
14335 -- Is_Volatile_Function --
14336 --------------------------
14338 function Is_Volatile_Function (Func_Id : Entity_Id) return Boolean is
14340 -- The caller must ensure that Func_Id denotes a function
14342 pragma Assert (Ekind_In (Func_Id, E_Function, E_Generic_Function));
14344 -- A protected function is automatically volatile
14346 if Is_Primitive (Func_Id)
14347 and then Present (First_Formal (Func_Id))
14348 and then Is_Protected_Type (Etype (First_Formal (Func_Id)))
14349 and then Etype (First_Formal (Func_Id)) = Scope (Func_Id)
14353 -- An instance of Ada.Unchecked_Conversion is a volatile function if
14354 -- either the source or the target are effectively volatile.
14356 elsif Is_Unchecked_Conversion_Instance (Func_Id)
14357 and then Has_Effectively_Volatile_Profile (Func_Id)
14361 -- Otherwise the function is treated as volatile if it is subject to
14362 -- enabled pragma Volatile_Function.
14366 Is_Enabled_Pragma (Get_Pragma (Func_Id, Pragma_Volatile_Function));
14368 end Is_Volatile_Function;
14370 ------------------------
14371 -- Is_Volatile_Object --
14372 ------------------------
14374 function Is_Volatile_Object (N : Node_Id) return Boolean is
14376 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
14377 -- If prefix is an implicit dereference, examine designated type
14379 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
14380 -- Determines if given object has volatile components
14382 ------------------------
14383 -- Is_Volatile_Prefix --
14384 ------------------------
14386 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
14387 Typ : constant Entity_Id := Etype (N);
14390 if Is_Access_Type (Typ) then
14392 Dtyp : constant Entity_Id := Designated_Type (Typ);
14395 return Is_Volatile (Dtyp)
14396 or else Has_Volatile_Components (Dtyp);
14400 return Object_Has_Volatile_Components (N);
14402 end Is_Volatile_Prefix;
14404 ------------------------------------
14405 -- Object_Has_Volatile_Components --
14406 ------------------------------------
14408 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
14409 Typ : constant Entity_Id := Etype (N);
14412 if Is_Volatile (Typ)
14413 or else Has_Volatile_Components (Typ)
14417 elsif Is_Entity_Name (N)
14418 and then (Has_Volatile_Components (Entity (N))
14419 or else Is_Volatile (Entity (N)))
14423 elsif Nkind (N) = N_Indexed_Component
14424 or else Nkind (N) = N_Selected_Component
14426 return Is_Volatile_Prefix (Prefix (N));
14431 end Object_Has_Volatile_Components;
14433 -- Start of processing for Is_Volatile_Object
14436 if Nkind (N) = N_Defining_Identifier then
14437 return Is_Volatile (N) or else Is_Volatile (Etype (N));
14439 elsif Nkind (N) = N_Expanded_Name then
14440 return Is_Volatile_Object (Entity (N));
14442 elsif Is_Volatile (Etype (N))
14443 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
14447 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component)
14448 and then Is_Volatile_Prefix (Prefix (N))
14452 elsif Nkind (N) = N_Selected_Component
14453 and then Is_Volatile (Entity (Selector_Name (N)))
14460 end Is_Volatile_Object;
14462 ---------------------------
14463 -- Itype_Has_Declaration --
14464 ---------------------------
14466 function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
14468 pragma Assert (Is_Itype (Id));
14469 return Present (Parent (Id))
14470 and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
14471 N_Subtype_Declaration)
14472 and then Defining_Entity (Parent (Id)) = Id;
14473 end Itype_Has_Declaration;
14475 -------------------------
14476 -- Kill_Current_Values --
14477 -------------------------
14479 procedure Kill_Current_Values
14481 Last_Assignment_Only : Boolean := False)
14484 if Is_Assignable (Ent) then
14485 Set_Last_Assignment (Ent, Empty);
14488 if Is_Object (Ent) then
14489 if not Last_Assignment_Only then
14491 Set_Current_Value (Ent, Empty);
14493 -- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
14494 -- for a constant. Once the constant is elaborated, its value is
14495 -- not changed, therefore the associated flags that describe the
14496 -- value should not be modified either.
14498 if Ekind (Ent) = E_Constant then
14501 -- Non-constant entities
14504 if not Can_Never_Be_Null (Ent) then
14505 Set_Is_Known_Non_Null (Ent, False);
14508 Set_Is_Known_Null (Ent, False);
14510 -- Reset the Is_Known_Valid flag unless the type is always
14511 -- valid. This does not apply to a loop parameter because its
14512 -- bounds are defined by the loop header and therefore always
14515 if not Is_Known_Valid (Etype (Ent))
14516 and then Ekind (Ent) /= E_Loop_Parameter
14518 Set_Is_Known_Valid (Ent, False);
14523 end Kill_Current_Values;
14525 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
14528 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
14529 -- Clear current value for entity E and all entities chained to E
14531 ------------------------------------------
14532 -- Kill_Current_Values_For_Entity_Chain --
14533 ------------------------------------------
14535 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
14539 while Present (Ent) loop
14540 Kill_Current_Values (Ent, Last_Assignment_Only);
14543 end Kill_Current_Values_For_Entity_Chain;
14545 -- Start of processing for Kill_Current_Values
14548 -- Kill all saved checks, a special case of killing saved values
14550 if not Last_Assignment_Only then
14554 -- Loop through relevant scopes, which includes the current scope and
14555 -- any parent scopes if the current scope is a block or a package.
14557 S := Current_Scope;
14560 -- Clear current values of all entities in current scope
14562 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
14564 -- If scope is a package, also clear current values of all private
14565 -- entities in the scope.
14567 if Is_Package_Or_Generic_Package (S)
14568 or else Is_Concurrent_Type (S)
14570 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
14573 -- If this is a not a subprogram, deal with parents
14575 if not Is_Subprogram (S) then
14577 exit Scope_Loop when S = Standard_Standard;
14581 end loop Scope_Loop;
14582 end Kill_Current_Values;
14584 --------------------------
14585 -- Kill_Size_Check_Code --
14586 --------------------------
14588 procedure Kill_Size_Check_Code (E : Entity_Id) is
14590 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
14591 and then Present (Size_Check_Code (E))
14593 Remove (Size_Check_Code (E));
14594 Set_Size_Check_Code (E, Empty);
14596 end Kill_Size_Check_Code;
14598 --------------------------
14599 -- Known_To_Be_Assigned --
14600 --------------------------
14602 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
14603 P : constant Node_Id := Parent (N);
14608 -- Test left side of assignment
14610 when N_Assignment_Statement =>
14611 return N = Name (P);
14613 -- Function call arguments are never lvalues
14615 when N_Function_Call =>
14618 -- Positional parameter for procedure or accept call
14620 when N_Procedure_Call_Statement |
14629 Proc := Get_Subprogram_Entity (P);
14635 -- If we are not a list member, something is strange, so
14636 -- be conservative and return False.
14638 if not Is_List_Member (N) then
14642 -- We are going to find the right formal by stepping forward
14643 -- through the formals, as we step backwards in the actuals.
14645 Form := First_Formal (Proc);
14648 -- If no formal, something is weird, so be conservative
14649 -- and return False.
14656 exit when No (Act);
14657 Next_Formal (Form);
14660 return Ekind (Form) /= E_In_Parameter;
14663 -- Named parameter for procedure or accept call
14665 when N_Parameter_Association =>
14671 Proc := Get_Subprogram_Entity (Parent (P));
14677 -- Loop through formals to find the one that matches
14679 Form := First_Formal (Proc);
14681 -- If no matching formal, that's peculiar, some kind of
14682 -- previous error, so return False to be conservative.
14683 -- Actually this also happens in legal code in the case
14684 -- where P is a parameter association for an Extra_Formal???
14690 -- Else test for match
14692 if Chars (Form) = Chars (Selector_Name (P)) then
14693 return Ekind (Form) /= E_In_Parameter;
14696 Next_Formal (Form);
14700 -- Test for appearing in a conversion that itself appears
14701 -- in an lvalue context, since this should be an lvalue.
14703 when N_Type_Conversion =>
14704 return Known_To_Be_Assigned (P);
14706 -- All other references are definitely not known to be modifications
14712 end Known_To_Be_Assigned;
14714 ---------------------------
14715 -- Last_Source_Statement --
14716 ---------------------------
14718 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
14722 N := Last (Statements (HSS));
14723 while Present (N) loop
14724 exit when Comes_From_Source (N);
14729 end Last_Source_Statement;
14731 ----------------------------------
14732 -- Matching_Static_Array_Bounds --
14733 ----------------------------------
14735 function Matching_Static_Array_Bounds
14737 R_Typ : Node_Id) return Boolean
14739 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
14740 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
14752 if L_Ndims /= R_Ndims then
14756 -- Unconstrained types do not have static bounds
14758 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
14762 -- First treat specially the first dimension, as the lower bound and
14763 -- length of string literals are not stored like those of arrays.
14765 if Ekind (L_Typ) = E_String_Literal_Subtype then
14766 L_Low := String_Literal_Low_Bound (L_Typ);
14767 L_Len := String_Literal_Length (L_Typ);
14769 L_Index := First_Index (L_Typ);
14770 Get_Index_Bounds (L_Index, L_Low, L_High);
14772 if Is_OK_Static_Expression (L_Low)
14774 Is_OK_Static_Expression (L_High)
14776 if Expr_Value (L_High) < Expr_Value (L_Low) then
14779 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
14786 if Ekind (R_Typ) = E_String_Literal_Subtype then
14787 R_Low := String_Literal_Low_Bound (R_Typ);
14788 R_Len := String_Literal_Length (R_Typ);
14790 R_Index := First_Index (R_Typ);
14791 Get_Index_Bounds (R_Index, R_Low, R_High);
14793 if Is_OK_Static_Expression (R_Low)
14795 Is_OK_Static_Expression (R_High)
14797 if Expr_Value (R_High) < Expr_Value (R_Low) then
14800 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
14807 if (Is_OK_Static_Expression (L_Low)
14809 Is_OK_Static_Expression (R_Low))
14810 and then Expr_Value (L_Low) = Expr_Value (R_Low)
14811 and then L_Len = R_Len
14818 -- Then treat all other dimensions
14820 for Indx in 2 .. L_Ndims loop
14824 Get_Index_Bounds (L_Index, L_Low, L_High);
14825 Get_Index_Bounds (R_Index, R_Low, R_High);
14827 if (Is_OK_Static_Expression (L_Low) and then
14828 Is_OK_Static_Expression (L_High) and then
14829 Is_OK_Static_Expression (R_Low) and then
14830 Is_OK_Static_Expression (R_High))
14831 and then (Expr_Value (L_Low) = Expr_Value (R_Low)
14833 Expr_Value (L_High) = Expr_Value (R_High))
14841 -- If we fall through the loop, all indexes matched
14844 end Matching_Static_Array_Bounds;
14846 -------------------
14847 -- May_Be_Lvalue --
14848 -------------------
14850 function May_Be_Lvalue (N : Node_Id) return Boolean is
14851 P : constant Node_Id := Parent (N);
14856 -- Test left side of assignment
14858 when N_Assignment_Statement =>
14859 return N = Name (P);
14861 -- Test prefix of component or attribute. Note that the prefix of an
14862 -- explicit or implicit dereference cannot be an l-value.
14864 when N_Attribute_Reference =>
14865 return N = Prefix (P)
14866 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
14868 -- For an expanded name, the name is an lvalue if the expanded name
14869 -- is an lvalue, but the prefix is never an lvalue, since it is just
14870 -- the scope where the name is found.
14872 when N_Expanded_Name =>
14873 if N = Prefix (P) then
14874 return May_Be_Lvalue (P);
14879 -- For a selected component A.B, A is certainly an lvalue if A.B is.
14880 -- B is a little interesting, if we have A.B := 3, there is some
14881 -- discussion as to whether B is an lvalue or not, we choose to say
14882 -- it is. Note however that A is not an lvalue if it is of an access
14883 -- type since this is an implicit dereference.
14885 when N_Selected_Component =>
14887 and then Present (Etype (N))
14888 and then Is_Access_Type (Etype (N))
14892 return May_Be_Lvalue (P);
14895 -- For an indexed component or slice, the index or slice bounds is
14896 -- never an lvalue. The prefix is an lvalue if the indexed component
14897 -- or slice is an lvalue, except if it is an access type, where we
14898 -- have an implicit dereference.
14900 when N_Indexed_Component | N_Slice =>
14902 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
14906 return May_Be_Lvalue (P);
14909 -- Prefix of a reference is an lvalue if the reference is an lvalue
14911 when N_Reference =>
14912 return May_Be_Lvalue (P);
14914 -- Prefix of explicit dereference is never an lvalue
14916 when N_Explicit_Dereference =>
14919 -- Positional parameter for subprogram, entry, or accept call.
14920 -- In older versions of Ada function call arguments are never
14921 -- lvalues. In Ada 2012 functions can have in-out parameters.
14923 when N_Subprogram_Call |
14924 N_Entry_Call_Statement |
14927 if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
14931 -- The following mechanism is clumsy and fragile. A single flag
14932 -- set in Resolve_Actuals would be preferable ???
14940 Proc := Get_Subprogram_Entity (P);
14946 -- If we are not a list member, something is strange, so be
14947 -- conservative and return True.
14949 if not Is_List_Member (N) then
14953 -- We are going to find the right formal by stepping forward
14954 -- through the formals, as we step backwards in the actuals.
14956 Form := First_Formal (Proc);
14959 -- If no formal, something is weird, so be conservative and
14967 exit when No (Act);
14968 Next_Formal (Form);
14971 return Ekind (Form) /= E_In_Parameter;
14974 -- Named parameter for procedure or accept call
14976 when N_Parameter_Association =>
14982 Proc := Get_Subprogram_Entity (Parent (P));
14988 -- Loop through formals to find the one that matches
14990 Form := First_Formal (Proc);
14992 -- If no matching formal, that's peculiar, some kind of
14993 -- previous error, so return True to be conservative.
14994 -- Actually happens with legal code for an unresolved call
14995 -- where we may get the wrong homonym???
15001 -- Else test for match
15003 if Chars (Form) = Chars (Selector_Name (P)) then
15004 return Ekind (Form) /= E_In_Parameter;
15007 Next_Formal (Form);
15011 -- Test for appearing in a conversion that itself appears in an
15012 -- lvalue context, since this should be an lvalue.
15014 when N_Type_Conversion =>
15015 return May_Be_Lvalue (P);
15017 -- Test for appearance in object renaming declaration
15019 when N_Object_Renaming_Declaration =>
15022 -- All other references are definitely not lvalues
15030 -----------------------
15031 -- Mark_Coextensions --
15032 -----------------------
15034 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
15035 Is_Dynamic : Boolean;
15036 -- Indicates whether the context causes nested coextensions to be
15037 -- dynamic or static
15039 function Mark_Allocator (N : Node_Id) return Traverse_Result;
15040 -- Recognize an allocator node and label it as a dynamic coextension
15042 --------------------
15043 -- Mark_Allocator --
15044 --------------------
15046 function Mark_Allocator (N : Node_Id) return Traverse_Result is
15048 if Nkind (N) = N_Allocator then
15050 Set_Is_Dynamic_Coextension (N);
15052 -- If the allocator expression is potentially dynamic, it may
15053 -- be expanded out of order and require dynamic allocation
15054 -- anyway, so we treat the coextension itself as dynamic.
15055 -- Potential optimization ???
15057 elsif Nkind (Expression (N)) = N_Qualified_Expression
15058 and then Nkind (Expression (Expression (N))) = N_Op_Concat
15060 Set_Is_Dynamic_Coextension (N);
15062 Set_Is_Static_Coextension (N);
15067 end Mark_Allocator;
15069 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
15071 -- Start of processing for Mark_Coextensions
15074 -- An allocator that appears on the right-hand side of an assignment is
15075 -- treated as a potentially dynamic coextension when the right-hand side
15076 -- is an allocator or a qualified expression.
15078 -- Obj := new ...'(new Coextension ...);
15080 if Nkind (Context_Nod) = N_Assignment_Statement then
15082 Nkind_In (Expression (Context_Nod), N_Allocator,
15083 N_Qualified_Expression);
15085 -- An allocator that appears within the expression of a simple return
15086 -- statement is treated as a potentially dynamic coextension when the
15087 -- expression is either aggregate, allocator, or qualified expression.
15089 -- return (new Coextension ...);
15090 -- return new ...'(new Coextension ...);
15092 elsif Nkind (Context_Nod) = N_Simple_Return_Statement then
15094 Nkind_In (Expression (Context_Nod), N_Aggregate,
15096 N_Qualified_Expression);
15098 -- An alloctor that appears within the initialization expression of an
15099 -- object declaration is considered a potentially dynamic coextension
15100 -- when the initialization expression is an allocator or a qualified
15103 -- Obj : ... := new ...'(new Coextension ...);
15105 -- A similar case arises when the object declaration is part of an
15106 -- extended return statement.
15108 -- return Obj : ... := new ...'(new Coextension ...);
15109 -- return Obj : ... := (new Coextension ...);
15111 elsif Nkind (Context_Nod) = N_Object_Declaration then
15113 Nkind_In (Root_Nod, N_Allocator, N_Qualified_Expression)
15115 Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
15117 -- This routine should not be called with constructs that cannot contain
15121 raise Program_Error;
15124 Mark_Allocators (Root_Nod);
15125 end Mark_Coextensions;
15127 ----------------------
15128 -- Needs_One_Actual --
15129 ----------------------
15131 function Needs_One_Actual (E : Entity_Id) return Boolean is
15132 Formal : Entity_Id;
15135 -- Ada 2005 or later, and formals present
15137 if Ada_Version >= Ada_2005 and then Present (First_Formal (E)) then
15138 Formal := Next_Formal (First_Formal (E));
15139 while Present (Formal) loop
15140 if No (Default_Value (Formal)) then
15144 Next_Formal (Formal);
15149 -- Ada 83/95 or no formals
15154 end Needs_One_Actual;
15156 ------------------------
15157 -- New_Copy_List_Tree --
15158 ------------------------
15160 function New_Copy_List_Tree (List : List_Id) return List_Id is
15165 if List = No_List then
15172 while Present (E) loop
15173 Append (New_Copy_Tree (E), NL);
15179 end New_Copy_List_Tree;
15181 --------------------------------------------------
15182 -- New_Copy_Tree Auxiliary Data and Subprograms --
15183 --------------------------------------------------
15185 use Atree.Unchecked_Access;
15186 use Atree_Private_Part;
15188 -- Our approach here requires a two pass traversal of the tree. The
15189 -- first pass visits all nodes that eventually will be copied looking
15190 -- for defining Itypes. If any defining Itypes are found, then they are
15191 -- copied, and an entry is added to the replacement map. In the second
15192 -- phase, the tree is copied, using the replacement map to replace any
15193 -- Itype references within the copied tree.
15195 -- The following hash tables are used if the Map supplied has more
15196 -- than hash threshold entries to speed up access to the map. If
15197 -- there are fewer entries, then the map is searched sequentially
15198 -- (because setting up a hash table for only a few entries takes
15199 -- more time than it saves.
15201 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
15202 -- Hash function used for hash operations
15204 -------------------
15205 -- New_Copy_Hash --
15206 -------------------
15208 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
15210 return Nat (E) mod (NCT_Header_Num'Last + 1);
15217 -- The hash table NCT_Assoc associates old entities in the table
15218 -- with their corresponding new entities (i.e. the pairs of entries
15219 -- presented in the original Map argument are Key-Element pairs).
15221 package NCT_Assoc is new Simple_HTable (
15222 Header_Num => NCT_Header_Num,
15223 Element => Entity_Id,
15224 No_Element => Empty,
15226 Hash => New_Copy_Hash,
15227 Equal => Types."=");
15229 ---------------------
15230 -- NCT_Itype_Assoc --
15231 ---------------------
15233 -- The hash table NCT_Itype_Assoc contains entries only for those
15234 -- old nodes which have a non-empty Associated_Node_For_Itype set.
15235 -- The key is the associated node, and the element is the new node
15236 -- itself (NOT the associated node for the new node).
15238 package NCT_Itype_Assoc is new Simple_HTable (
15239 Header_Num => NCT_Header_Num,
15240 Element => Entity_Id,
15241 No_Element => Empty,
15243 Hash => New_Copy_Hash,
15244 Equal => Types."=");
15246 -------------------
15247 -- New_Copy_Tree --
15248 -------------------
15250 function New_Copy_Tree
15252 Map : Elist_Id := No_Elist;
15253 New_Sloc : Source_Ptr := No_Location;
15254 New_Scope : Entity_Id := Empty) return Node_Id
15256 Actual_Map : Elist_Id := Map;
15257 -- This is the actual map for the copy. It is initialized with the
15258 -- given elements, and then enlarged as required for Itypes that are
15259 -- copied during the first phase of the copy operation. The visit
15260 -- procedures add elements to this map as Itypes are encountered.
15261 -- The reason we cannot use Map directly, is that it may well be
15262 -- (and normally is) initialized to No_Elist, and if we have mapped
15263 -- entities, we have to reset it to point to a real Elist.
15265 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
15266 -- Called during second phase to map entities into their corresponding
15267 -- copies using Actual_Map. If the argument is not an entity, or is not
15268 -- in Actual_Map, then it is returned unchanged.
15270 procedure Build_NCT_Hash_Tables;
15271 -- Builds hash tables (number of elements >= threshold value)
15273 function Copy_Elist_With_Replacement
15274 (Old_Elist : Elist_Id) return Elist_Id;
15275 -- Called during second phase to copy element list doing replacements
15277 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
15278 -- Called during the second phase to process a copied Itype. The actual
15279 -- copy happened during the first phase (so that we could make the entry
15280 -- in the mapping), but we still have to deal with the descendants of
15281 -- the copied Itype and copy them where necessary.
15283 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
15284 -- Called during second phase to copy list doing replacements
15286 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
15287 -- Called during second phase to copy node doing replacements
15289 procedure Visit_Elist (E : Elist_Id);
15290 -- Called during first phase to visit all elements of an Elist
15292 procedure Visit_Field (F : Union_Id; N : Node_Id);
15293 -- Visit a single field, recursing to call Visit_Node or Visit_List
15294 -- if the field is a syntactic descendant of the current node (i.e.
15295 -- its parent is Node N).
15297 procedure Visit_Itype (Old_Itype : Entity_Id);
15298 -- Called during first phase to visit subsidiary fields of a defining
15299 -- Itype, and also create a copy and make an entry in the replacement
15300 -- map for the new copy.
15302 procedure Visit_List (L : List_Id);
15303 -- Called during first phase to visit all elements of a List
15305 procedure Visit_Node (N : Node_Or_Entity_Id);
15306 -- Called during first phase to visit a node and all its subtrees
15312 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
15317 if not Has_Extension (N) or else No (Actual_Map) then
15320 elsif NCT_Hash_Tables_Used then
15321 Ent := NCT_Assoc.Get (Entity_Id (N));
15323 if Present (Ent) then
15329 -- No hash table used, do serial search
15332 E := First_Elmt (Actual_Map);
15333 while Present (E) loop
15334 if Node (E) = N then
15335 return Node (Next_Elmt (E));
15337 E := Next_Elmt (Next_Elmt (E));
15345 ---------------------------
15346 -- Build_NCT_Hash_Tables --
15347 ---------------------------
15349 procedure Build_NCT_Hash_Tables is
15353 if NCT_Hash_Table_Setup then
15355 NCT_Itype_Assoc.Reset;
15358 Elmt := First_Elmt (Actual_Map);
15359 while Present (Elmt) loop
15360 Ent := Node (Elmt);
15362 -- Get new entity, and associate old and new
15365 NCT_Assoc.Set (Ent, Node (Elmt));
15367 if Is_Type (Ent) then
15369 Anode : constant Entity_Id :=
15370 Associated_Node_For_Itype (Ent);
15373 if Present (Anode) then
15375 -- Enter a link between the associated node of the
15376 -- old Itype and the new Itype, for updating later
15377 -- when node is copied.
15379 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
15387 NCT_Hash_Tables_Used := True;
15388 NCT_Hash_Table_Setup := True;
15389 end Build_NCT_Hash_Tables;
15391 ---------------------------------
15392 -- Copy_Elist_With_Replacement --
15393 ---------------------------------
15395 function Copy_Elist_With_Replacement
15396 (Old_Elist : Elist_Id) return Elist_Id
15399 New_Elist : Elist_Id;
15402 if No (Old_Elist) then
15406 New_Elist := New_Elmt_List;
15408 M := First_Elmt (Old_Elist);
15409 while Present (M) loop
15410 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
15416 end Copy_Elist_With_Replacement;
15418 ---------------------------------
15419 -- Copy_Itype_With_Replacement --
15420 ---------------------------------
15422 -- This routine exactly parallels its phase one analog Visit_Itype,
15424 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
15426 -- Translate Next_Entity, Scope and Etype fields, in case they
15427 -- reference entities that have been mapped into copies.
15429 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
15430 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
15432 if Present (New_Scope) then
15433 Set_Scope (New_Itype, New_Scope);
15435 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
15438 -- Copy referenced fields
15440 if Is_Discrete_Type (New_Itype) then
15441 Set_Scalar_Range (New_Itype,
15442 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
15444 elsif Has_Discriminants (Base_Type (New_Itype)) then
15445 Set_Discriminant_Constraint (New_Itype,
15446 Copy_Elist_With_Replacement
15447 (Discriminant_Constraint (New_Itype)));
15449 elsif Is_Array_Type (New_Itype) then
15450 if Present (First_Index (New_Itype)) then
15451 Set_First_Index (New_Itype,
15452 First (Copy_List_With_Replacement
15453 (List_Containing (First_Index (New_Itype)))));
15456 if Is_Packed (New_Itype) then
15457 Set_Packed_Array_Impl_Type (New_Itype,
15458 Copy_Node_With_Replacement
15459 (Packed_Array_Impl_Type (New_Itype)));
15462 end Copy_Itype_With_Replacement;
15464 --------------------------------
15465 -- Copy_List_With_Replacement --
15466 --------------------------------
15468 function Copy_List_With_Replacement
15469 (Old_List : List_Id) return List_Id
15471 New_List : List_Id;
15475 if Old_List = No_List then
15479 New_List := Empty_List;
15481 E := First (Old_List);
15482 while Present (E) loop
15483 Append (Copy_Node_With_Replacement (E), New_List);
15489 end Copy_List_With_Replacement;
15491 --------------------------------
15492 -- Copy_Node_With_Replacement --
15493 --------------------------------
15495 function Copy_Node_With_Replacement
15496 (Old_Node : Node_Id) return Node_Id
15498 New_Node : Node_Id;
15500 procedure Adjust_Named_Associations
15501 (Old_Node : Node_Id;
15502 New_Node : Node_Id);
15503 -- If a call node has named associations, these are chained through
15504 -- the First_Named_Actual, Next_Named_Actual links. These must be
15505 -- propagated separately to the new parameter list, because these
15506 -- are not syntactic fields.
15508 function Copy_Field_With_Replacement
15509 (Field : Union_Id) return Union_Id;
15510 -- Given Field, which is a field of Old_Node, return a copy of it
15511 -- if it is a syntactic field (i.e. its parent is Node), setting
15512 -- the parent of the copy to poit to New_Node. Otherwise returns
15513 -- the field (possibly mapped if it is an entity).
15515 -------------------------------
15516 -- Adjust_Named_Associations --
15517 -------------------------------
15519 procedure Adjust_Named_Associations
15520 (Old_Node : Node_Id;
15521 New_Node : Node_Id)
15526 Old_Next : Node_Id;
15527 New_Next : Node_Id;
15530 Old_E := First (Parameter_Associations (Old_Node));
15531 New_E := First (Parameter_Associations (New_Node));
15532 while Present (Old_E) loop
15533 if Nkind (Old_E) = N_Parameter_Association
15534 and then Present (Next_Named_Actual (Old_E))
15536 if First_Named_Actual (Old_Node)
15537 = Explicit_Actual_Parameter (Old_E)
15539 Set_First_Named_Actual
15540 (New_Node, Explicit_Actual_Parameter (New_E));
15543 -- Now scan parameter list from the beginning,to locate
15544 -- next named actual, which can be out of order.
15546 Old_Next := First (Parameter_Associations (Old_Node));
15547 New_Next := First (Parameter_Associations (New_Node));
15549 while Nkind (Old_Next) /= N_Parameter_Association
15550 or else Explicit_Actual_Parameter (Old_Next) /=
15551 Next_Named_Actual (Old_E)
15557 Set_Next_Named_Actual
15558 (New_E, Explicit_Actual_Parameter (New_Next));
15564 end Adjust_Named_Associations;
15566 ---------------------------------
15567 -- Copy_Field_With_Replacement --
15568 ---------------------------------
15570 function Copy_Field_With_Replacement
15571 (Field : Union_Id) return Union_Id
15574 if Field = Union_Id (Empty) then
15577 elsif Field in Node_Range then
15579 Old_N : constant Node_Id := Node_Id (Field);
15583 -- If syntactic field, as indicated by the parent pointer
15584 -- being set, then copy the referenced node recursively.
15586 if Parent (Old_N) = Old_Node then
15587 New_N := Copy_Node_With_Replacement (Old_N);
15589 if New_N /= Old_N then
15590 Set_Parent (New_N, New_Node);
15593 -- For semantic fields, update possible entity reference
15594 -- from the replacement map.
15597 New_N := Assoc (Old_N);
15600 return Union_Id (New_N);
15603 elsif Field in List_Range then
15605 Old_L : constant List_Id := List_Id (Field);
15609 -- If syntactic field, as indicated by the parent pointer,
15610 -- then recursively copy the entire referenced list.
15612 if Parent (Old_L) = Old_Node then
15613 New_L := Copy_List_With_Replacement (Old_L);
15614 Set_Parent (New_L, New_Node);
15616 -- For semantic list, just returned unchanged
15622 return Union_Id (New_L);
15625 -- Anything other than a list or a node is returned unchanged
15630 end Copy_Field_With_Replacement;
15632 -- Start of processing for Copy_Node_With_Replacement
15635 if Old_Node <= Empty_Or_Error then
15638 elsif Has_Extension (Old_Node) then
15639 return Assoc (Old_Node);
15642 New_Node := New_Copy (Old_Node);
15644 -- If the node we are copying is the associated node of a
15645 -- previously copied Itype, then adjust the associated node
15646 -- of the copy of that Itype accordingly.
15648 if Present (Actual_Map) then
15654 -- Case of hash table used
15656 if NCT_Hash_Tables_Used then
15657 Ent := NCT_Itype_Assoc.Get (Old_Node);
15659 if Present (Ent) then
15660 Set_Associated_Node_For_Itype (Ent, New_Node);
15663 -- Case of no hash table used
15666 E := First_Elmt (Actual_Map);
15667 while Present (E) loop
15668 if Is_Itype (Node (E))
15670 Old_Node = Associated_Node_For_Itype (Node (E))
15672 Set_Associated_Node_For_Itype
15673 (Node (Next_Elmt (E)), New_Node);
15676 E := Next_Elmt (Next_Elmt (E));
15682 -- Recursively copy descendants
15685 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
15687 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
15689 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
15691 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
15693 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
15695 -- Adjust Sloc of new node if necessary
15697 if New_Sloc /= No_Location then
15698 Set_Sloc (New_Node, New_Sloc);
15700 -- If we adjust the Sloc, then we are essentially making
15701 -- a completely new node, so the Comes_From_Source flag
15702 -- should be reset to the proper default value.
15704 Nodes.Table (New_Node).Comes_From_Source :=
15705 Default_Node.Comes_From_Source;
15708 -- If the node is call and has named associations,
15709 -- set the corresponding links in the copy.
15711 if (Nkind (Old_Node) = N_Function_Call
15712 or else Nkind (Old_Node) = N_Entry_Call_Statement
15714 Nkind (Old_Node) = N_Procedure_Call_Statement)
15715 and then Present (First_Named_Actual (Old_Node))
15717 Adjust_Named_Associations (Old_Node, New_Node);
15720 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
15721 -- The replacement mechanism applies to entities, and is not used
15722 -- here. Eventually we may need a more general graph-copying
15723 -- routine. For now, do a sequential search to find desired node.
15725 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
15726 and then Present (First_Real_Statement (Old_Node))
15729 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
15733 N1 := First (Statements (Old_Node));
15734 N2 := First (Statements (New_Node));
15736 while N1 /= Old_F loop
15741 Set_First_Real_Statement (New_Node, N2);
15746 -- All done, return copied node
15749 end Copy_Node_With_Replacement;
15755 procedure Visit_Elist (E : Elist_Id) is
15758 if Present (E) then
15759 Elmt := First_Elmt (E);
15761 while Elmt /= No_Elmt loop
15762 Visit_Node (Node (Elmt));
15772 procedure Visit_Field (F : Union_Id; N : Node_Id) is
15774 if F = Union_Id (Empty) then
15777 elsif F in Node_Range then
15779 -- Copy node if it is syntactic, i.e. its parent pointer is
15780 -- set to point to the field that referenced it (certain
15781 -- Itypes will also meet this criterion, which is fine, since
15782 -- these are clearly Itypes that do need to be copied, since
15783 -- we are copying their parent.)
15785 if Parent (Node_Id (F)) = N then
15786 Visit_Node (Node_Id (F));
15789 -- Another case, if we are pointing to an Itype, then we want
15790 -- to copy it if its associated node is somewhere in the tree
15793 -- Note: the exclusion of self-referential copies is just an
15794 -- optimization, since the search of the already copied list
15795 -- would catch it, but it is a common case (Etype pointing
15796 -- to itself for an Itype that is a base type).
15798 elsif Has_Extension (Node_Id (F))
15799 and then Is_Itype (Entity_Id (F))
15800 and then Node_Id (F) /= N
15806 P := Associated_Node_For_Itype (Node_Id (F));
15807 while Present (P) loop
15809 Visit_Node (Node_Id (F));
15816 -- An Itype whose parent is not being copied definitely
15817 -- should NOT be copied, since it does not belong in any
15818 -- sense to the copied subtree.
15824 elsif F in List_Range and then Parent (List_Id (F)) = N then
15825 Visit_List (List_Id (F));
15834 procedure Visit_Itype (Old_Itype : Entity_Id) is
15835 New_Itype : Entity_Id;
15840 -- Itypes that describe the designated type of access to subprograms
15841 -- have the structure of subprogram declarations, with signatures,
15842 -- etc. Either we duplicate the signatures completely, or choose to
15843 -- share such itypes, which is fine because their elaboration will
15844 -- have no side effects.
15846 if Ekind (Old_Itype) = E_Subprogram_Type then
15850 New_Itype := New_Copy (Old_Itype);
15852 -- The new Itype has all the attributes of the old one, and
15853 -- we just copy the contents of the entity. However, the back-end
15854 -- needs different names for debugging purposes, so we create a
15855 -- new internal name for it in all cases.
15857 Set_Chars (New_Itype, New_Internal_Name ('T'));
15859 -- If our associated node is an entity that has already been copied,
15860 -- then set the associated node of the copy to point to the right
15861 -- copy. If we have copied an Itype that is itself the associated
15862 -- node of some previously copied Itype, then we set the right
15863 -- pointer in the other direction.
15865 if Present (Actual_Map) then
15867 -- Case of hash tables used
15869 if NCT_Hash_Tables_Used then
15871 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
15873 if Present (Ent) then
15874 Set_Associated_Node_For_Itype (New_Itype, Ent);
15877 Ent := NCT_Itype_Assoc.Get (Old_Itype);
15878 if Present (Ent) then
15879 Set_Associated_Node_For_Itype (Ent, New_Itype);
15881 -- If the hash table has no association for this Itype and
15882 -- its associated node, enter one now.
15885 NCT_Itype_Assoc.Set
15886 (Associated_Node_For_Itype (Old_Itype), New_Itype);
15889 -- Case of hash tables not used
15892 E := First_Elmt (Actual_Map);
15893 while Present (E) loop
15894 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
15895 Set_Associated_Node_For_Itype
15896 (New_Itype, Node (Next_Elmt (E)));
15899 if Is_Type (Node (E))
15900 and then Old_Itype = Associated_Node_For_Itype (Node (E))
15902 Set_Associated_Node_For_Itype
15903 (Node (Next_Elmt (E)), New_Itype);
15906 E := Next_Elmt (Next_Elmt (E));
15911 if Present (Freeze_Node (New_Itype)) then
15912 Set_Is_Frozen (New_Itype, False);
15913 Set_Freeze_Node (New_Itype, Empty);
15916 -- Add new association to map
15918 if No (Actual_Map) then
15919 Actual_Map := New_Elmt_List;
15922 Append_Elmt (Old_Itype, Actual_Map);
15923 Append_Elmt (New_Itype, Actual_Map);
15925 if NCT_Hash_Tables_Used then
15926 NCT_Assoc.Set (Old_Itype, New_Itype);
15929 NCT_Table_Entries := NCT_Table_Entries + 1;
15931 if NCT_Table_Entries > NCT_Hash_Threshold then
15932 Build_NCT_Hash_Tables;
15936 -- If a record subtype is simply copied, the entity list will be
15937 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
15939 if Ekind_In (Old_Itype, E_Record_Subtype, E_Class_Wide_Subtype) then
15940 Set_Cloned_Subtype (New_Itype, Old_Itype);
15943 -- Visit descendants that eventually get copied
15945 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
15947 if Is_Discrete_Type (Old_Itype) then
15948 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
15950 elsif Has_Discriminants (Base_Type (Old_Itype)) then
15951 -- ??? This should involve call to Visit_Field
15952 Visit_Elist (Discriminant_Constraint (Old_Itype));
15954 elsif Is_Array_Type (Old_Itype) then
15955 if Present (First_Index (Old_Itype)) then
15956 Visit_Field (Union_Id (List_Containing
15957 (First_Index (Old_Itype))),
15961 if Is_Packed (Old_Itype) then
15962 Visit_Field (Union_Id (Packed_Array_Impl_Type (Old_Itype)),
15972 procedure Visit_List (L : List_Id) is
15975 if L /= No_List then
15978 while Present (N) loop
15989 procedure Visit_Node (N : Node_Or_Entity_Id) is
15991 -- Start of processing for Visit_Node
15994 -- Handle case of an Itype, which must be copied
15996 if Has_Extension (N) and then Is_Itype (N) then
15998 -- Nothing to do if already in the list. This can happen with an
15999 -- Itype entity that appears more than once in the tree.
16000 -- Note that we do not want to visit descendants in this case.
16002 -- Test for already in list when hash table is used
16004 if NCT_Hash_Tables_Used then
16005 if Present (NCT_Assoc.Get (Entity_Id (N))) then
16009 -- Test for already in list when hash table not used
16015 if Present (Actual_Map) then
16016 E := First_Elmt (Actual_Map);
16017 while Present (E) loop
16018 if Node (E) = N then
16021 E := Next_Elmt (Next_Elmt (E));
16031 -- Visit descendants
16033 Visit_Field (Field1 (N), N);
16034 Visit_Field (Field2 (N), N);
16035 Visit_Field (Field3 (N), N);
16036 Visit_Field (Field4 (N), N);
16037 Visit_Field (Field5 (N), N);
16040 -- Start of processing for New_Copy_Tree
16045 -- See if we should use hash table
16047 if No (Actual_Map) then
16048 NCT_Hash_Tables_Used := False;
16055 NCT_Table_Entries := 0;
16057 Elmt := First_Elmt (Actual_Map);
16058 while Present (Elmt) loop
16059 NCT_Table_Entries := NCT_Table_Entries + 1;
16064 if NCT_Table_Entries > NCT_Hash_Threshold then
16065 Build_NCT_Hash_Tables;
16067 NCT_Hash_Tables_Used := False;
16072 -- Hash table set up if required, now start phase one by visiting
16073 -- top node (we will recursively visit the descendants).
16075 Visit_Node (Source);
16077 -- Now the second phase of the copy can start. First we process
16078 -- all the mapped entities, copying their descendants.
16080 if Present (Actual_Map) then
16083 New_Itype : Entity_Id;
16085 Elmt := First_Elmt (Actual_Map);
16086 while Present (Elmt) loop
16088 New_Itype := Node (Elmt);
16090 if Is_Itype (New_Itype) then
16091 Copy_Itype_With_Replacement (New_Itype);
16098 -- Now we can copy the actual tree
16100 return Copy_Node_With_Replacement (Source);
16103 -------------------------
16104 -- New_External_Entity --
16105 -------------------------
16107 function New_External_Entity
16108 (Kind : Entity_Kind;
16109 Scope_Id : Entity_Id;
16110 Sloc_Value : Source_Ptr;
16111 Related_Id : Entity_Id;
16112 Suffix : Character;
16113 Suffix_Index : Nat := 0;
16114 Prefix : Character := ' ') return Entity_Id
16116 N : constant Entity_Id :=
16117 Make_Defining_Identifier (Sloc_Value,
16119 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
16122 Set_Ekind (N, Kind);
16123 Set_Is_Internal (N, True);
16124 Append_Entity (N, Scope_Id);
16125 Set_Public_Status (N);
16127 if Kind in Type_Kind then
16128 Init_Size_Align (N);
16132 end New_External_Entity;
16134 -------------------------
16135 -- New_Internal_Entity --
16136 -------------------------
16138 function New_Internal_Entity
16139 (Kind : Entity_Kind;
16140 Scope_Id : Entity_Id;
16141 Sloc_Value : Source_Ptr;
16142 Id_Char : Character) return Entity_Id
16144 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
16147 Set_Ekind (N, Kind);
16148 Set_Is_Internal (N, True);
16149 Append_Entity (N, Scope_Id);
16151 if Kind in Type_Kind then
16152 Init_Size_Align (N);
16156 end New_Internal_Entity;
16162 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
16166 -- If we are pointing at a positional parameter, it is a member of a
16167 -- node list (the list of parameters), and the next parameter is the
16168 -- next node on the list, unless we hit a parameter association, then
16169 -- we shift to using the chain whose head is the First_Named_Actual in
16170 -- the parent, and then is threaded using the Next_Named_Actual of the
16171 -- Parameter_Association. All this fiddling is because the original node
16172 -- list is in the textual call order, and what we need is the
16173 -- declaration order.
16175 if Is_List_Member (Actual_Id) then
16176 N := Next (Actual_Id);
16178 if Nkind (N) = N_Parameter_Association then
16179 return First_Named_Actual (Parent (Actual_Id));
16185 return Next_Named_Actual (Parent (Actual_Id));
16189 procedure Next_Actual (Actual_Id : in out Node_Id) is
16191 Actual_Id := Next_Actual (Actual_Id);
16194 -----------------------
16195 -- Normalize_Actuals --
16196 -----------------------
16198 -- Chain actuals according to formals of subprogram. If there are no named
16199 -- associations, the chain is simply the list of Parameter Associations,
16200 -- since the order is the same as the declaration order. If there are named
16201 -- associations, then the First_Named_Actual field in the N_Function_Call
16202 -- or N_Procedure_Call_Statement node points to the Parameter_Association
16203 -- node for the parameter that comes first in declaration order. The
16204 -- remaining named parameters are then chained in declaration order using
16205 -- Next_Named_Actual.
16207 -- This routine also verifies that the number of actuals is compatible with
16208 -- the number and default values of formals, but performs no type checking
16209 -- (type checking is done by the caller).
16211 -- If the matching succeeds, Success is set to True and the caller proceeds
16212 -- with type-checking. If the match is unsuccessful, then Success is set to
16213 -- False, and the caller attempts a different interpretation, if there is
16216 -- If the flag Report is on, the call is not overloaded, and a failure to
16217 -- match can be reported here, rather than in the caller.
16219 procedure Normalize_Actuals
16223 Success : out Boolean)
16225 Actuals : constant List_Id := Parameter_Associations (N);
16226 Actual : Node_Id := Empty;
16227 Formal : Entity_Id;
16228 Last : Node_Id := Empty;
16229 First_Named : Node_Id := Empty;
16232 Formals_To_Match : Integer := 0;
16233 Actuals_To_Match : Integer := 0;
16235 procedure Chain (A : Node_Id);
16236 -- Add named actual at the proper place in the list, using the
16237 -- Next_Named_Actual link.
16239 function Reporting return Boolean;
16240 -- Determines if an error is to be reported. To report an error, we
16241 -- need Report to be True, and also we do not report errors caused
16242 -- by calls to init procs that occur within other init procs. Such
16243 -- errors must always be cascaded errors, since if all the types are
16244 -- declared correctly, the compiler will certainly build decent calls.
16250 procedure Chain (A : Node_Id) is
16254 -- Call node points to first actual in list
16256 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
16259 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
16263 Set_Next_Named_Actual (Last, Empty);
16270 function Reporting return Boolean is
16275 elsif not Within_Init_Proc then
16278 elsif Is_Init_Proc (Entity (Name (N))) then
16286 -- Start of processing for Normalize_Actuals
16289 if Is_Access_Type (S) then
16291 -- The name in the call is a function call that returns an access
16292 -- to subprogram. The designated type has the list of formals.
16294 Formal := First_Formal (Designated_Type (S));
16296 Formal := First_Formal (S);
16299 while Present (Formal) loop
16300 Formals_To_Match := Formals_To_Match + 1;
16301 Next_Formal (Formal);
16304 -- Find if there is a named association, and verify that no positional
16305 -- associations appear after named ones.
16307 if Present (Actuals) then
16308 Actual := First (Actuals);
16311 while Present (Actual)
16312 and then Nkind (Actual) /= N_Parameter_Association
16314 Actuals_To_Match := Actuals_To_Match + 1;
16318 if No (Actual) and Actuals_To_Match = Formals_To_Match then
16320 -- Most common case: positional notation, no defaults
16325 elsif Actuals_To_Match > Formals_To_Match then
16327 -- Too many actuals: will not work
16330 if Is_Entity_Name (Name (N)) then
16331 Error_Msg_N ("too many arguments in call to&", Name (N));
16333 Error_Msg_N ("too many arguments in call", N);
16341 First_Named := Actual;
16343 while Present (Actual) loop
16344 if Nkind (Actual) /= N_Parameter_Association then
16346 ("positional parameters not allowed after named ones", Actual);
16351 Actuals_To_Match := Actuals_To_Match + 1;
16357 if Present (Actuals) then
16358 Actual := First (Actuals);
16361 Formal := First_Formal (S);
16362 while Present (Formal) loop
16364 -- Match the formals in order. If the corresponding actual is
16365 -- positional, nothing to do. Else scan the list of named actuals
16366 -- to find the one with the right name.
16368 if Present (Actual)
16369 and then Nkind (Actual) /= N_Parameter_Association
16372 Actuals_To_Match := Actuals_To_Match - 1;
16373 Formals_To_Match := Formals_To_Match - 1;
16376 -- For named parameters, search the list of actuals to find
16377 -- one that matches the next formal name.
16379 Actual := First_Named;
16381 while Present (Actual) loop
16382 if Chars (Selector_Name (Actual)) = Chars (Formal) then
16385 Actuals_To_Match := Actuals_To_Match - 1;
16386 Formals_To_Match := Formals_To_Match - 1;
16394 if Ekind (Formal) /= E_In_Parameter
16395 or else No (Default_Value (Formal))
16398 if (Comes_From_Source (S)
16399 or else Sloc (S) = Standard_Location)
16400 and then Is_Overloadable (S)
16404 Nkind_In (Parent (N), N_Procedure_Call_Statement,
16406 N_Parameter_Association)
16407 and then Ekind (S) /= E_Function
16409 Set_Etype (N, Etype (S));
16412 Error_Msg_Name_1 := Chars (S);
16413 Error_Msg_Sloc := Sloc (S);
16415 ("missing argument for parameter & "
16416 & "in call to % declared #", N, Formal);
16419 elsif Is_Overloadable (S) then
16420 Error_Msg_Name_1 := Chars (S);
16422 -- Point to type derivation that generated the
16425 Error_Msg_Sloc := Sloc (Parent (S));
16428 ("missing argument for parameter & "
16429 & "in call to % (inherited) #", N, Formal);
16433 ("missing argument for parameter &", N, Formal);
16441 Formals_To_Match := Formals_To_Match - 1;
16446 Next_Formal (Formal);
16449 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
16456 -- Find some superfluous named actual that did not get
16457 -- attached to the list of associations.
16459 Actual := First (Actuals);
16460 while Present (Actual) loop
16461 if Nkind (Actual) = N_Parameter_Association
16462 and then Actual /= Last
16463 and then No (Next_Named_Actual (Actual))
16465 Error_Msg_N ("unmatched actual & in call",
16466 Selector_Name (Actual));
16477 end Normalize_Actuals;
16479 --------------------------------
16480 -- Note_Possible_Modification --
16481 --------------------------------
16483 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
16484 Modification_Comes_From_Source : constant Boolean :=
16485 Comes_From_Source (Parent (N));
16491 -- Loop to find referenced entity, if there is one
16497 if Is_Entity_Name (Exp) then
16498 Ent := Entity (Exp);
16500 -- If the entity is missing, it is an undeclared identifier,
16501 -- and there is nothing to annotate.
16507 elsif Nkind (Exp) = N_Explicit_Dereference then
16509 P : constant Node_Id := Prefix (Exp);
16512 -- In formal verification mode, keep track of all reads and
16513 -- writes through explicit dereferences.
16515 if GNATprove_Mode then
16516 SPARK_Specific.Generate_Dereference (N, 'm');
16519 if Nkind (P) = N_Selected_Component
16520 and then Present (Entry_Formal (Entity (Selector_Name (P))))
16522 -- Case of a reference to an entry formal
16524 Ent := Entry_Formal (Entity (Selector_Name (P)));
16526 elsif Nkind (P) = N_Identifier
16527 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
16528 and then Present (Expression (Parent (Entity (P))))
16529 and then Nkind (Expression (Parent (Entity (P)))) =
16532 -- Case of a reference to a value on which side effects have
16535 Exp := Prefix (Expression (Parent (Entity (P))));
16543 elsif Nkind_In (Exp, N_Type_Conversion,
16544 N_Unchecked_Type_Conversion)
16546 Exp := Expression (Exp);
16549 elsif Nkind_In (Exp, N_Slice,
16550 N_Indexed_Component,
16551 N_Selected_Component)
16553 -- Special check, if the prefix is an access type, then return
16554 -- since we are modifying the thing pointed to, not the prefix.
16555 -- When we are expanding, most usually the prefix is replaced
16556 -- by an explicit dereference, and this test is not needed, but
16557 -- in some cases (notably -gnatc mode and generics) when we do
16558 -- not do full expansion, we need this special test.
16560 if Is_Access_Type (Etype (Prefix (Exp))) then
16563 -- Otherwise go to prefix and keep going
16566 Exp := Prefix (Exp);
16570 -- All other cases, not a modification
16576 -- Now look for entity being referenced
16578 if Present (Ent) then
16579 if Is_Object (Ent) then
16580 if Comes_From_Source (Exp)
16581 or else Modification_Comes_From_Source
16583 -- Give warning if pragma unmodified given and we are
16584 -- sure this is a modification.
16586 if Has_Pragma_Unmodified (Ent) and then Sure then
16587 Error_Msg_NE ("??pragma Unmodified given for &!", N, Ent);
16590 Set_Never_Set_In_Source (Ent, False);
16593 Set_Is_True_Constant (Ent, False);
16594 Set_Current_Value (Ent, Empty);
16595 Set_Is_Known_Null (Ent, False);
16597 if not Can_Never_Be_Null (Ent) then
16598 Set_Is_Known_Non_Null (Ent, False);
16601 -- Follow renaming chain
16603 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
16604 and then Present (Renamed_Object (Ent))
16606 Exp := Renamed_Object (Ent);
16608 -- If the entity is the loop variable in an iteration over
16609 -- a container, retrieve container expression to indicate
16610 -- possible modification.
16612 if Present (Related_Expression (Ent))
16613 and then Nkind (Parent (Related_Expression (Ent))) =
16614 N_Iterator_Specification
16616 Exp := Original_Node (Related_Expression (Ent));
16621 -- The expression may be the renaming of a subcomponent of an
16622 -- array or container. The assignment to the subcomponent is
16623 -- a modification of the container.
16625 elsif Comes_From_Source (Original_Node (Exp))
16626 and then Nkind_In (Original_Node (Exp), N_Selected_Component,
16627 N_Indexed_Component)
16629 Exp := Prefix (Original_Node (Exp));
16633 -- Generate a reference only if the assignment comes from
16634 -- source. This excludes, for example, calls to a dispatching
16635 -- assignment operation when the left-hand side is tagged. In
16636 -- GNATprove mode, we need those references also on generated
16637 -- code, as these are used to compute the local effects of
16640 if Modification_Comes_From_Source or GNATprove_Mode then
16641 Generate_Reference (Ent, Exp, 'm');
16643 -- If the target of the assignment is the bound variable
16644 -- in an iterator, indicate that the corresponding array
16645 -- or container is also modified.
16647 if Ada_Version >= Ada_2012
16648 and then Nkind (Parent (Ent)) = N_Iterator_Specification
16651 Domain : constant Node_Id := Name (Parent (Ent));
16654 -- TBD : in the full version of the construct, the
16655 -- domain of iteration can be given by an expression.
16657 if Is_Entity_Name (Domain) then
16658 Generate_Reference (Entity (Domain), Exp, 'm');
16659 Set_Is_True_Constant (Entity (Domain), False);
16660 Set_Never_Set_In_Source (Entity (Domain), False);
16669 -- If we are sure this is a modification from source, and we know
16670 -- this modifies a constant, then give an appropriate warning.
16673 and then Modification_Comes_From_Source
16674 and then Overlays_Constant (Ent)
16675 and then Address_Clause_Overlay_Warnings
16678 Addr : constant Node_Id := Address_Clause (Ent);
16683 Find_Overlaid_Entity (Addr, O_Ent, Off);
16685 Error_Msg_Sloc := Sloc (Addr);
16687 ("??constant& may be modified via address clause#",
16698 end Note_Possible_Modification;
16700 -------------------------
16701 -- Object_Access_Level --
16702 -------------------------
16704 -- Returns the static accessibility level of the view denoted by Obj. Note
16705 -- that the value returned is the result of a call to Scope_Depth. Only
16706 -- scope depths associated with dynamic scopes can actually be returned.
16707 -- Since only relative levels matter for accessibility checking, the fact
16708 -- that the distance between successive levels of accessibility is not
16709 -- always one is immaterial (invariant: if level(E2) is deeper than
16710 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
16712 function Object_Access_Level (Obj : Node_Id) return Uint is
16713 function Is_Interface_Conversion (N : Node_Id) return Boolean;
16714 -- Determine whether N is a construct of the form
16715 -- Some_Type (Operand._tag'Address)
16716 -- This construct appears in the context of dispatching calls.
16718 function Reference_To (Obj : Node_Id) return Node_Id;
16719 -- An explicit dereference is created when removing side-effects from
16720 -- expressions for constraint checking purposes. In this case a local
16721 -- access type is created for it. The correct access level is that of
16722 -- the original source node. We detect this case by noting that the
16723 -- prefix of the dereference is created by an object declaration whose
16724 -- initial expression is a reference.
16726 -----------------------------
16727 -- Is_Interface_Conversion --
16728 -----------------------------
16730 function Is_Interface_Conversion (N : Node_Id) return Boolean is
16732 return Nkind (N) = N_Unchecked_Type_Conversion
16733 and then Nkind (Expression (N)) = N_Attribute_Reference
16734 and then Attribute_Name (Expression (N)) = Name_Address;
16735 end Is_Interface_Conversion;
16741 function Reference_To (Obj : Node_Id) return Node_Id is
16742 Pref : constant Node_Id := Prefix (Obj);
16744 if Is_Entity_Name (Pref)
16745 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
16746 and then Present (Expression (Parent (Entity (Pref))))
16747 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
16749 return (Prefix (Expression (Parent (Entity (Pref)))));
16759 -- Start of processing for Object_Access_Level
16762 if Nkind (Obj) = N_Defining_Identifier
16763 or else Is_Entity_Name (Obj)
16765 if Nkind (Obj) = N_Defining_Identifier then
16771 if Is_Prival (E) then
16772 E := Prival_Link (E);
16775 -- If E is a type then it denotes a current instance. For this case
16776 -- we add one to the normal accessibility level of the type to ensure
16777 -- that current instances are treated as always being deeper than
16778 -- than the level of any visible named access type (see 3.10.2(21)).
16780 if Is_Type (E) then
16781 return Type_Access_Level (E) + 1;
16783 elsif Present (Renamed_Object (E)) then
16784 return Object_Access_Level (Renamed_Object (E));
16786 -- Similarly, if E is a component of the current instance of a
16787 -- protected type, any instance of it is assumed to be at a deeper
16788 -- level than the type. For a protected object (whose type is an
16789 -- anonymous protected type) its components are at the same level
16790 -- as the type itself.
16792 elsif not Is_Overloadable (E)
16793 and then Ekind (Scope (E)) = E_Protected_Type
16794 and then Comes_From_Source (Scope (E))
16796 return Type_Access_Level (Scope (E)) + 1;
16799 -- Aliased formals of functions take their access level from the
16800 -- point of call, i.e. require a dynamic check. For static check
16801 -- purposes, this is smaller than the level of the subprogram
16802 -- itself. For procedures the aliased makes no difference.
16805 and then Is_Aliased (E)
16806 and then Ekind (Scope (E)) = E_Function
16808 return Type_Access_Level (Etype (E));
16811 return Scope_Depth (Enclosing_Dynamic_Scope (E));
16815 elsif Nkind (Obj) = N_Selected_Component then
16816 if Is_Access_Type (Etype (Prefix (Obj))) then
16817 return Type_Access_Level (Etype (Prefix (Obj)));
16819 return Object_Access_Level (Prefix (Obj));
16822 elsif Nkind (Obj) = N_Indexed_Component then
16823 if Is_Access_Type (Etype (Prefix (Obj))) then
16824 return Type_Access_Level (Etype (Prefix (Obj)));
16826 return Object_Access_Level (Prefix (Obj));
16829 elsif Nkind (Obj) = N_Explicit_Dereference then
16831 -- If the prefix is a selected access discriminant then we make a
16832 -- recursive call on the prefix, which will in turn check the level
16833 -- of the prefix object of the selected discriminant.
16835 -- In Ada 2012, if the discriminant has implicit dereference and
16836 -- the context is a selected component, treat this as an object of
16837 -- unknown scope (see below). This is necessary in compile-only mode;
16838 -- otherwise expansion will already have transformed the prefix into
16841 if Nkind (Prefix (Obj)) = N_Selected_Component
16842 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
16844 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
16846 (not Has_Implicit_Dereference
16847 (Entity (Selector_Name (Prefix (Obj))))
16848 or else Nkind (Parent (Obj)) /= N_Selected_Component)
16850 return Object_Access_Level (Prefix (Obj));
16852 -- Detect an interface conversion in the context of a dispatching
16853 -- call. Use the original form of the conversion to find the access
16854 -- level of the operand.
16856 elsif Is_Interface (Etype (Obj))
16857 and then Is_Interface_Conversion (Prefix (Obj))
16858 and then Nkind (Original_Node (Obj)) = N_Type_Conversion
16860 return Object_Access_Level (Original_Node (Obj));
16862 elsif not Comes_From_Source (Obj) then
16864 Ref : constant Node_Id := Reference_To (Obj);
16866 if Present (Ref) then
16867 return Object_Access_Level (Ref);
16869 return Type_Access_Level (Etype (Prefix (Obj)));
16874 return Type_Access_Level (Etype (Prefix (Obj)));
16877 elsif Nkind_In (Obj, N_Type_Conversion, N_Unchecked_Type_Conversion) then
16878 return Object_Access_Level (Expression (Obj));
16880 elsif Nkind (Obj) = N_Function_Call then
16882 -- Function results are objects, so we get either the access level of
16883 -- the function or, in the case of an indirect call, the level of the
16884 -- access-to-subprogram type. (This code is used for Ada 95, but it
16885 -- looks wrong, because it seems that we should be checking the level
16886 -- of the call itself, even for Ada 95. However, using the Ada 2005
16887 -- version of the code causes regressions in several tests that are
16888 -- compiled with -gnat95. ???)
16890 if Ada_Version < Ada_2005 then
16891 if Is_Entity_Name (Name (Obj)) then
16892 return Subprogram_Access_Level (Entity (Name (Obj)));
16894 return Type_Access_Level (Etype (Prefix (Name (Obj))));
16897 -- For Ada 2005, the level of the result object of a function call is
16898 -- defined to be the level of the call's innermost enclosing master.
16899 -- We determine that by querying the depth of the innermost enclosing
16903 Return_Master_Scope_Depth_Of_Call : declare
16905 function Innermost_Master_Scope_Depth
16906 (N : Node_Id) return Uint;
16907 -- Returns the scope depth of the given node's innermost
16908 -- enclosing dynamic scope (effectively the accessibility
16909 -- level of the innermost enclosing master).
16911 ----------------------------------
16912 -- Innermost_Master_Scope_Depth --
16913 ----------------------------------
16915 function Innermost_Master_Scope_Depth
16916 (N : Node_Id) return Uint
16918 Node_Par : Node_Id := Parent (N);
16921 -- Locate the nearest enclosing node (by traversing Parents)
16922 -- that Defining_Entity can be applied to, and return the
16923 -- depth of that entity's nearest enclosing dynamic scope.
16925 while Present (Node_Par) loop
16926 case Nkind (Node_Par) is
16927 when N_Component_Declaration |
16928 N_Entry_Declaration |
16929 N_Formal_Object_Declaration |
16930 N_Formal_Type_Declaration |
16931 N_Full_Type_Declaration |
16932 N_Incomplete_Type_Declaration |
16933 N_Loop_Parameter_Specification |
16934 N_Object_Declaration |
16935 N_Protected_Type_Declaration |
16936 N_Private_Extension_Declaration |
16937 N_Private_Type_Declaration |
16938 N_Subtype_Declaration |
16939 N_Function_Specification |
16940 N_Procedure_Specification |
16941 N_Task_Type_Declaration |
16943 N_Generic_Instantiation |
16945 N_Implicit_Label_Declaration |
16946 N_Package_Declaration |
16947 N_Single_Task_Declaration |
16948 N_Subprogram_Declaration |
16949 N_Generic_Declaration |
16950 N_Renaming_Declaration |
16951 N_Block_Statement |
16952 N_Formal_Subprogram_Declaration |
16953 N_Abstract_Subprogram_Declaration |
16955 N_Exception_Declaration |
16956 N_Formal_Package_Declaration |
16957 N_Number_Declaration |
16958 N_Package_Specification |
16959 N_Parameter_Specification |
16960 N_Single_Protected_Declaration |
16964 (Nearest_Dynamic_Scope
16965 (Defining_Entity (Node_Par)));
16971 Node_Par := Parent (Node_Par);
16974 pragma Assert (False);
16976 -- Should never reach the following return
16978 return Scope_Depth (Current_Scope) + 1;
16979 end Innermost_Master_Scope_Depth;
16981 -- Start of processing for Return_Master_Scope_Depth_Of_Call
16984 return Innermost_Master_Scope_Depth (Obj);
16985 end Return_Master_Scope_Depth_Of_Call;
16988 -- For convenience we handle qualified expressions, even though they
16989 -- aren't technically object names.
16991 elsif Nkind (Obj) = N_Qualified_Expression then
16992 return Object_Access_Level (Expression (Obj));
16994 -- Ditto for aggregates. They have the level of the temporary that
16995 -- will hold their value.
16997 elsif Nkind (Obj) = N_Aggregate then
16998 return Object_Access_Level (Current_Scope);
17000 -- Otherwise return the scope level of Standard. (If there are cases
17001 -- that fall through to this point they will be treated as having
17002 -- global accessibility for now. ???)
17005 return Scope_Depth (Standard_Standard);
17007 end Object_Access_Level;
17009 ---------------------------------
17010 -- Original_Aspect_Pragma_Name --
17011 ---------------------------------
17013 function Original_Aspect_Pragma_Name (N : Node_Id) return Name_Id is
17015 Item_Nam : Name_Id;
17018 pragma Assert (Nkind_In (N, N_Aspect_Specification, N_Pragma));
17022 -- The pragma was generated to emulate an aspect, use the original
17023 -- aspect specification.
17025 if Nkind (Item) = N_Pragma and then From_Aspect_Specification (Item) then
17026 Item := Corresponding_Aspect (Item);
17029 -- Retrieve the name of the aspect/pragma. Note that Pre, Pre_Class,
17030 -- Post and Post_Class rewrite their pragma identifier to preserve the
17032 -- ??? this is kludgey
17034 if Nkind (Item) = N_Pragma then
17035 Item_Nam := Chars (Original_Node (Pragma_Identifier (Item)));
17038 pragma Assert (Nkind (Item) = N_Aspect_Specification);
17039 Item_Nam := Chars (Identifier (Item));
17042 -- Deal with 'Class by converting the name to its _XXX form
17044 if Class_Present (Item) then
17045 if Item_Nam = Name_Invariant then
17046 Item_Nam := Name_uInvariant;
17048 elsif Item_Nam = Name_Post then
17049 Item_Nam := Name_uPost;
17051 elsif Item_Nam = Name_Pre then
17052 Item_Nam := Name_uPre;
17054 elsif Nam_In (Item_Nam, Name_Type_Invariant,
17055 Name_Type_Invariant_Class)
17057 Item_Nam := Name_uType_Invariant;
17059 -- Nothing to do for other cases (e.g. a Check that derived from
17060 -- Pre_Class and has the flag set). Also we do nothing if the name
17061 -- is already in special _xxx form.
17067 end Original_Aspect_Pragma_Name;
17069 --------------------------------------
17070 -- Original_Corresponding_Operation --
17071 --------------------------------------
17073 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
17075 Typ : constant Entity_Id := Find_Dispatching_Type (S);
17078 -- If S is an inherited primitive S2 the original corresponding
17079 -- operation of S is the original corresponding operation of S2
17081 if Present (Alias (S))
17082 and then Find_Dispatching_Type (Alias (S)) /= Typ
17084 return Original_Corresponding_Operation (Alias (S));
17086 -- If S overrides an inherited subprogram S2 the original corresponding
17087 -- operation of S is the original corresponding operation of S2
17089 elsif Present (Overridden_Operation (S)) then
17090 return Original_Corresponding_Operation (Overridden_Operation (S));
17092 -- otherwise it is S itself
17097 end Original_Corresponding_Operation;
17099 ----------------------
17100 -- Policy_In_Effect --
17101 ----------------------
17103 function Policy_In_Effect (Policy : Name_Id) return Name_Id is
17104 function Policy_In_List (List : Node_Id) return Name_Id;
17105 -- Determine the mode of a policy in a N_Pragma list
17107 --------------------
17108 -- Policy_In_List --
17109 --------------------
17111 function Policy_In_List (List : Node_Id) return Name_Id is
17118 while Present (Prag) loop
17119 Arg1 := First (Pragma_Argument_Associations (Prag));
17120 Arg2 := Next (Arg1);
17122 Arg1 := Get_Pragma_Arg (Arg1);
17123 Arg2 := Get_Pragma_Arg (Arg2);
17125 -- The current Check_Policy pragma matches the requested policy or
17126 -- appears in the single argument form (Assertion, policy_id).
17128 if Nam_In (Chars (Arg1), Name_Assertion, Policy) then
17129 return Chars (Arg2);
17132 Prag := Next_Pragma (Prag);
17136 end Policy_In_List;
17142 -- Start of processing for Policy_In_Effect
17145 if not Is_Valid_Assertion_Kind (Policy) then
17146 raise Program_Error;
17149 -- Inspect all policy pragmas that appear within scopes (if any)
17151 Kind := Policy_In_List (Check_Policy_List);
17153 -- Inspect all configuration policy pragmas (if any)
17155 if Kind = No_Name then
17156 Kind := Policy_In_List (Check_Policy_List_Config);
17159 -- The context lacks policy pragmas, determine the mode based on whether
17160 -- assertions are enabled at the configuration level. This ensures that
17161 -- the policy is preserved when analyzing generics.
17163 if Kind = No_Name then
17164 if Assertions_Enabled_Config then
17165 Kind := Name_Check;
17167 Kind := Name_Ignore;
17172 end Policy_In_Effect;
17174 ----------------------------------
17175 -- Predicate_Tests_On_Arguments --
17176 ----------------------------------
17178 function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean is
17180 -- Always test predicates on indirect call
17182 if Ekind (Subp) = E_Subprogram_Type then
17185 -- Do not test predicates on call to generated default Finalize, since
17186 -- we are not interested in whether something we are finalizing (and
17187 -- typically destroying) satisfies its predicates.
17189 elsif Chars (Subp) = Name_Finalize
17190 and then not Comes_From_Source (Subp)
17194 -- Do not test predicates on any internally generated routines
17196 elsif Is_Internal_Name (Chars (Subp)) then
17199 -- Do not test predicates on call to Init_Proc, since if needed the
17200 -- predicate test will occur at some other point.
17202 elsif Is_Init_Proc (Subp) then
17205 -- Do not test predicates on call to predicate function, since this
17206 -- would cause infinite recursion.
17208 elsif Ekind (Subp) = E_Function
17209 and then (Is_Predicate_Function (Subp)
17211 Is_Predicate_Function_M (Subp))
17215 -- For now, no other exceptions
17220 end Predicate_Tests_On_Arguments;
17222 -----------------------
17223 -- Private_Component --
17224 -----------------------
17226 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
17227 Ancestor : constant Entity_Id := Base_Type (Type_Id);
17229 function Trace_Components
17231 Check : Boolean) return Entity_Id;
17232 -- Recursive function that does the work, and checks against circular
17233 -- definition for each subcomponent type.
17235 ----------------------
17236 -- Trace_Components --
17237 ----------------------
17239 function Trace_Components
17241 Check : Boolean) return Entity_Id
17243 Btype : constant Entity_Id := Base_Type (T);
17244 Component : Entity_Id;
17246 Candidate : Entity_Id := Empty;
17249 if Check and then Btype = Ancestor then
17250 Error_Msg_N ("circular type definition", Type_Id);
17254 if Is_Private_Type (Btype) and then not Is_Generic_Type (Btype) then
17255 if Present (Full_View (Btype))
17256 and then Is_Record_Type (Full_View (Btype))
17257 and then not Is_Frozen (Btype)
17259 -- To indicate that the ancestor depends on a private type, the
17260 -- current Btype is sufficient. However, to check for circular
17261 -- definition we must recurse on the full view.
17263 Candidate := Trace_Components (Full_View (Btype), True);
17265 if Candidate = Any_Type then
17275 elsif Is_Array_Type (Btype) then
17276 return Trace_Components (Component_Type (Btype), True);
17278 elsif Is_Record_Type (Btype) then
17279 Component := First_Entity (Btype);
17280 while Present (Component)
17281 and then Comes_From_Source (Component)
17283 -- Skip anonymous types generated by constrained components
17285 if not Is_Type (Component) then
17286 P := Trace_Components (Etype (Component), True);
17288 if Present (P) then
17289 if P = Any_Type then
17297 Next_Entity (Component);
17305 end Trace_Components;
17307 -- Start of processing for Private_Component
17310 return Trace_Components (Type_Id, False);
17311 end Private_Component;
17313 ---------------------------
17314 -- Primitive_Names_Match --
17315 ---------------------------
17317 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
17319 function Non_Internal_Name (E : Entity_Id) return Name_Id;
17320 -- Given an internal name, returns the corresponding non-internal name
17322 ------------------------
17323 -- Non_Internal_Name --
17324 ------------------------
17326 function Non_Internal_Name (E : Entity_Id) return Name_Id is
17328 Get_Name_String (Chars (E));
17329 Name_Len := Name_Len - 1;
17331 end Non_Internal_Name;
17333 -- Start of processing for Primitive_Names_Match
17336 pragma Assert (Present (E1) and then Present (E2));
17338 return Chars (E1) = Chars (E2)
17340 (not Is_Internal_Name (Chars (E1))
17341 and then Is_Internal_Name (Chars (E2))
17342 and then Non_Internal_Name (E2) = Chars (E1))
17344 (not Is_Internal_Name (Chars (E2))
17345 and then Is_Internal_Name (Chars (E1))
17346 and then Non_Internal_Name (E1) = Chars (E2))
17348 (Is_Predefined_Dispatching_Operation (E1)
17349 and then Is_Predefined_Dispatching_Operation (E2)
17350 and then Same_TSS (E1, E2))
17352 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
17353 end Primitive_Names_Match;
17355 -----------------------
17356 -- Process_End_Label --
17357 -----------------------
17359 procedure Process_End_Label
17368 Label_Ref : Boolean;
17369 -- Set True if reference to end label itself is required
17372 -- Gets set to the operator symbol or identifier that references the
17373 -- entity Ent. For the child unit case, this is the identifier from the
17374 -- designator. For other cases, this is simply Endl.
17376 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
17377 -- N is an identifier node that appears as a parent unit reference in
17378 -- the case where Ent is a child unit. This procedure generates an
17379 -- appropriate cross-reference entry. E is the corresponding entity.
17381 -------------------------
17382 -- Generate_Parent_Ref --
17383 -------------------------
17385 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
17387 -- If names do not match, something weird, skip reference
17389 if Chars (E) = Chars (N) then
17391 -- Generate the reference. We do NOT consider this as a reference
17392 -- for unreferenced symbol purposes.
17394 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
17396 if Style_Check then
17397 Style.Check_Identifier (N, E);
17400 end Generate_Parent_Ref;
17402 -- Start of processing for Process_End_Label
17405 -- If no node, ignore. This happens in some error situations, and
17406 -- also for some internally generated structures where no end label
17407 -- references are required in any case.
17413 -- Nothing to do if no End_Label, happens for internally generated
17414 -- constructs where we don't want an end label reference anyway. Also
17415 -- nothing to do if Endl is a string literal, which means there was
17416 -- some prior error (bad operator symbol)
17418 Endl := End_Label (N);
17420 if No (Endl) or else Nkind (Endl) = N_String_Literal then
17424 -- Reference node is not in extended main source unit
17426 if not In_Extended_Main_Source_Unit (N) then
17428 -- Generally we do not collect references except for the extended
17429 -- main source unit. The one exception is the 'e' entry for a
17430 -- package spec, where it is useful for a client to have the
17431 -- ending information to define scopes.
17437 Label_Ref := False;
17439 -- For this case, we can ignore any parent references, but we
17440 -- need the package name itself for the 'e' entry.
17442 if Nkind (Endl) = N_Designator then
17443 Endl := Identifier (Endl);
17447 -- Reference is in extended main source unit
17452 -- For designator, generate references for the parent entries
17454 if Nkind (Endl) = N_Designator then
17456 -- Generate references for the prefix if the END line comes from
17457 -- source (otherwise we do not need these references) We climb the
17458 -- scope stack to find the expected entities.
17460 if Comes_From_Source (Endl) then
17461 Nam := Name (Endl);
17462 Scop := Current_Scope;
17463 while Nkind (Nam) = N_Selected_Component loop
17464 Scop := Scope (Scop);
17465 exit when No (Scop);
17466 Generate_Parent_Ref (Selector_Name (Nam), Scop);
17467 Nam := Prefix (Nam);
17470 if Present (Scop) then
17471 Generate_Parent_Ref (Nam, Scope (Scop));
17475 Endl := Identifier (Endl);
17479 -- If the end label is not for the given entity, then either we have
17480 -- some previous error, or this is a generic instantiation for which
17481 -- we do not need to make a cross-reference in this case anyway. In
17482 -- either case we simply ignore the call.
17484 if Chars (Ent) /= Chars (Endl) then
17488 -- If label was really there, then generate a normal reference and then
17489 -- adjust the location in the end label to point past the name (which
17490 -- should almost always be the semicolon).
17492 Loc := Sloc (Endl);
17494 if Comes_From_Source (Endl) then
17496 -- If a label reference is required, then do the style check and
17497 -- generate an l-type cross-reference entry for the label
17500 if Style_Check then
17501 Style.Check_Identifier (Endl, Ent);
17504 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
17507 -- Set the location to point past the label (normally this will
17508 -- mean the semicolon immediately following the label). This is
17509 -- done for the sake of the 'e' or 't' entry generated below.
17511 Get_Decoded_Name_String (Chars (Endl));
17512 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
17515 -- In SPARK mode, no missing label is allowed for packages and
17516 -- subprogram bodies. Detect those cases by testing whether
17517 -- Process_End_Label was called for a body (Typ = 't') or a package.
17519 if Restriction_Check_Required (SPARK_05)
17520 and then (Typ = 't' or else Ekind (Ent) = E_Package)
17522 Error_Msg_Node_1 := Endl;
17523 Check_SPARK_05_Restriction
17524 ("`END &` required", Endl, Force => True);
17528 -- Now generate the e/t reference
17530 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
17532 -- Restore Sloc, in case modified above, since we have an identifier
17533 -- and the normal Sloc should be left set in the tree.
17535 Set_Sloc (Endl, Loc);
17536 end Process_End_Label;
17538 ---------------------------------------
17539 -- Record_Possible_Part_Of_Reference --
17540 ---------------------------------------
17542 procedure Record_Possible_Part_Of_Reference
17543 (Var_Id : Entity_Id;
17546 Encap : constant Entity_Id := Encapsulating_State (Var_Id);
17550 -- The variable is a constituent of a single protected/task type. Such
17551 -- a variable acts as a component of the type and must appear within a
17552 -- specific region (SPARK RM 9.3). Instead of recording the reference,
17553 -- verify its legality now.
17555 if Present (Encap) and then Is_Single_Concurrent_Object (Encap) then
17556 Check_Part_Of_Reference (Var_Id, Ref);
17558 -- The variable is subject to pragma Part_Of and may eventually become a
17559 -- constituent of a single protected/task type. Record the reference to
17560 -- verify its placement when the contract of the variable is analyzed.
17562 elsif Present (Get_Pragma (Var_Id, Pragma_Part_Of)) then
17563 Refs := Part_Of_References (Var_Id);
17566 Refs := New_Elmt_List;
17567 Set_Part_Of_References (Var_Id, Refs);
17570 Append_Elmt (Ref, Refs);
17572 end Record_Possible_Part_Of_Reference;
17578 function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
17579 Seen : Boolean := False;
17581 function Is_Reference (N : Node_Id) return Traverse_Result;
17582 -- Determine whether node N denotes a reference to Id. If this is the
17583 -- case, set global flag Seen to True and stop the traversal.
17589 function Is_Reference (N : Node_Id) return Traverse_Result is
17591 if Is_Entity_Name (N)
17592 and then Present (Entity (N))
17593 and then Entity (N) = Id
17602 procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
17604 -- Start of processing for Referenced
17607 Inspect_Expression (Expr);
17611 ------------------------------------
17612 -- References_Generic_Formal_Type --
17613 ------------------------------------
17615 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
17617 function Process (N : Node_Id) return Traverse_Result;
17618 -- Process one node in search for generic formal type
17624 function Process (N : Node_Id) return Traverse_Result is
17626 if Nkind (N) in N_Has_Entity then
17628 E : constant Entity_Id := Entity (N);
17630 if Present (E) then
17631 if Is_Generic_Type (E) then
17633 elsif Present (Etype (E))
17634 and then Is_Generic_Type (Etype (E))
17645 function Traverse is new Traverse_Func (Process);
17646 -- Traverse tree to look for generic type
17649 if Inside_A_Generic then
17650 return Traverse (N) = Abandon;
17654 end References_Generic_Formal_Type;
17656 --------------------
17657 -- Remove_Homonym --
17658 --------------------
17660 procedure Remove_Homonym (E : Entity_Id) is
17661 Prev : Entity_Id := Empty;
17665 if E = Current_Entity (E) then
17666 if Present (Homonym (E)) then
17667 Set_Current_Entity (Homonym (E));
17669 Set_Name_Entity_Id (Chars (E), Empty);
17673 H := Current_Entity (E);
17674 while Present (H) and then H /= E loop
17679 -- If E is not on the homonym chain, nothing to do
17681 if Present (H) then
17682 Set_Homonym (Prev, Homonym (E));
17685 end Remove_Homonym;
17687 ------------------------------
17688 -- Remove_Overloaded_Entity --
17689 ------------------------------
17691 procedure Remove_Overloaded_Entity (Id : Entity_Id) is
17692 procedure Remove_Primitive_Of (Typ : Entity_Id);
17693 -- Remove primitive subprogram Id from the list of primitives that
17694 -- belong to type Typ.
17696 -------------------------
17697 -- Remove_Primitive_Of --
17698 -------------------------
17700 procedure Remove_Primitive_Of (Typ : Entity_Id) is
17704 if Is_Tagged_Type (Typ) then
17705 Prims := Direct_Primitive_Operations (Typ);
17707 if Present (Prims) then
17708 Remove (Prims, Id);
17711 end Remove_Primitive_Of;
17715 Scop : constant Entity_Id := Scope (Id);
17716 Formal : Entity_Id;
17717 Prev_Id : Entity_Id;
17719 -- Start of processing for Remove_Overloaded_Entity
17722 -- Remove the entity from the homonym chain. When the entity is the
17723 -- head of the chain, associate the entry in the name table with its
17724 -- homonym effectively making it the new head of the chain.
17726 if Current_Entity (Id) = Id then
17727 Set_Name_Entity_Id (Chars (Id), Homonym (Id));
17729 -- Otherwise link the previous and next homonyms
17732 Prev_Id := Current_Entity (Id);
17733 while Present (Prev_Id) and then Homonym (Prev_Id) /= Id loop
17734 Prev_Id := Homonym (Prev_Id);
17737 Set_Homonym (Prev_Id, Homonym (Id));
17740 -- Remove the entity from the scope entity chain. When the entity is
17741 -- the head of the chain, set the next entity as the new head of the
17744 if First_Entity (Scop) = Id then
17746 Set_First_Entity (Scop, Next_Entity (Id));
17748 -- Otherwise the entity is either in the middle of the chain or it acts
17749 -- as its tail. Traverse and link the previous and next entities.
17752 Prev_Id := First_Entity (Scop);
17753 while Present (Prev_Id) and then Next_Entity (Prev_Id) /= Id loop
17754 Next_Entity (Prev_Id);
17757 Set_Next_Entity (Prev_Id, Next_Entity (Id));
17760 -- Handle the case where the entity acts as the tail of the scope entity
17763 if Last_Entity (Scop) = Id then
17764 Set_Last_Entity (Scop, Prev_Id);
17767 -- The entity denotes a primitive subprogram. Remove it from the list of
17768 -- primitives of the associated controlling type.
17770 if Ekind_In (Id, E_Function, E_Procedure) and then Is_Primitive (Id) then
17771 Formal := First_Formal (Id);
17772 while Present (Formal) loop
17773 if Is_Controlling_Formal (Formal) then
17774 Remove_Primitive_Of (Etype (Formal));
17778 Next_Formal (Formal);
17781 if Ekind (Id) = E_Function and then Has_Controlling_Result (Id) then
17782 Remove_Primitive_Of (Etype (Id));
17785 end Remove_Overloaded_Entity;
17787 ---------------------
17788 -- Rep_To_Pos_Flag --
17789 ---------------------
17791 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
17793 return New_Occurrence_Of
17794 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
17795 end Rep_To_Pos_Flag;
17797 --------------------
17798 -- Require_Entity --
17799 --------------------
17801 procedure Require_Entity (N : Node_Id) is
17803 if Is_Entity_Name (N) and then No (Entity (N)) then
17804 if Total_Errors_Detected /= 0 then
17805 Set_Entity (N, Any_Id);
17807 raise Program_Error;
17810 end Require_Entity;
17812 -------------------------------
17813 -- Requires_State_Refinement --
17814 -------------------------------
17816 function Requires_State_Refinement
17817 (Spec_Id : Entity_Id;
17818 Body_Id : Entity_Id) return Boolean
17820 function Mode_Is_Off (Prag : Node_Id) return Boolean;
17821 -- Given pragma SPARK_Mode, determine whether the mode is Off
17827 function Mode_Is_Off (Prag : Node_Id) return Boolean is
17831 -- The default SPARK mode is On
17837 Mode := Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
17839 -- Then the pragma lacks an argument, the default mode is On
17844 return Chars (Mode) = Name_Off;
17848 -- Start of processing for Requires_State_Refinement
17851 -- A package that does not define at least one abstract state cannot
17852 -- possibly require refinement.
17854 if No (Abstract_States (Spec_Id)) then
17857 -- The package instroduces a single null state which does not merit
17860 elsif Has_Null_Abstract_State (Spec_Id) then
17863 -- Check whether the package body is subject to pragma SPARK_Mode. If
17864 -- it is and the mode is Off, the package body is considered to be in
17865 -- regular Ada and does not require refinement.
17867 elsif Mode_Is_Off (SPARK_Pragma (Body_Id)) then
17870 -- The body's SPARK_Mode may be inherited from a similar pragma that
17871 -- appears in the private declarations of the spec. The pragma we are
17872 -- interested appears as the second entry in SPARK_Pragma.
17874 elsif Present (SPARK_Pragma (Spec_Id))
17875 and then Mode_Is_Off (Next_Pragma (SPARK_Pragma (Spec_Id)))
17879 -- The spec defines at least one abstract state and the body has no way
17880 -- of circumventing the refinement.
17885 end Requires_State_Refinement;
17887 ------------------------------
17888 -- Requires_Transient_Scope --
17889 ------------------------------
17891 -- A transient scope is required when variable-sized temporaries are
17892 -- allocated on the secondary stack, or when finalization actions must be
17893 -- generated before the next instruction.
17895 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
17896 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
17897 -- ???We retain the old and new algorithms for Requires_Transient_Scope for
17898 -- the time being. New_Requires_Transient_Scope is used by default; the
17899 -- debug switch -gnatdQ can be used to do Old_Requires_Transient_Scope
17900 -- instead. The intent is to use this temporarily to measure before/after
17901 -- efficiency. Note: when this temporary code is removed, the documentation
17902 -- of dQ in debug.adb should be removed.
17904 procedure Results_Differ (Id : Entity_Id);
17905 -- ???Debugging code. Called when the Old_ and New_ results differ. Will be
17906 -- removed when New_Requires_Transient_Scope becomes
17907 -- Requires_Transient_Scope and Old_Requires_Transient_Scope is eliminated.
17909 procedure Results_Differ (Id : Entity_Id) is
17911 if False then -- False to disable; True for debugging
17912 Treepr.Print_Tree_Node (Id);
17914 if Old_Requires_Transient_Scope (Id) =
17915 New_Requires_Transient_Scope (Id)
17917 raise Program_Error;
17920 end Results_Differ;
17922 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
17923 Old_Result : constant Boolean := Old_Requires_Transient_Scope (Id);
17926 if Debug_Flag_QQ then
17931 New_Result : constant Boolean := New_Requires_Transient_Scope (Id);
17934 -- Assert that we're not putting things on the secondary stack if we
17935 -- didn't before; we are trying to AVOID secondary stack when
17938 if not Old_Result then
17939 pragma Assert (not New_Result);
17943 if New_Result /= Old_Result then
17944 Results_Differ (Id);
17949 end Requires_Transient_Scope;
17951 ----------------------------------
17952 -- Old_Requires_Transient_Scope --
17953 ----------------------------------
17955 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
17956 Typ : constant Entity_Id := Underlying_Type (Id);
17959 -- This is a private type which is not completed yet. This can only
17960 -- happen in a default expression (of a formal parameter or of a
17961 -- record component). Do not expand transient scope in this case.
17966 -- Do not expand transient scope for non-existent procedure return
17968 elsif Typ = Standard_Void_Type then
17971 -- Elementary types do not require a transient scope
17973 elsif Is_Elementary_Type (Typ) then
17976 -- Generally, indefinite subtypes require a transient scope, since the
17977 -- back end cannot generate temporaries, since this is not a valid type
17978 -- for declaring an object. It might be possible to relax this in the
17979 -- future, e.g. by declaring the maximum possible space for the type.
17981 elsif not Is_Definite_Subtype (Typ) then
17984 -- Functions returning tagged types may dispatch on result so their
17985 -- returned value is allocated on the secondary stack. Controlled
17986 -- type temporaries need finalization.
17988 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
17993 elsif Is_Record_Type (Typ) then
17998 Comp := First_Entity (Typ);
17999 while Present (Comp) loop
18000 if Ekind (Comp) = E_Component then
18002 -- ???It's not clear we need a full recursive call to
18003 -- Old_Requires_Transient_Scope here. Note that the
18004 -- following can't happen.
18006 pragma Assert (Is_Definite_Subtype (Etype (Comp)));
18007 pragma Assert (not Has_Controlled_Component (Etype (Comp)));
18009 if Old_Requires_Transient_Scope (Etype (Comp)) then
18014 Next_Entity (Comp);
18020 -- String literal types never require transient scope
18022 elsif Ekind (Typ) = E_String_Literal_Subtype then
18025 -- Array type. Note that we already know that this is a constrained
18026 -- array, since unconstrained arrays will fail the indefinite test.
18028 elsif Is_Array_Type (Typ) then
18030 -- If component type requires a transient scope, the array does too
18032 if Old_Requires_Transient_Scope (Component_Type (Typ)) then
18035 -- Otherwise, we only need a transient scope if the size depends on
18036 -- the value of one or more discriminants.
18039 return Size_Depends_On_Discriminant (Typ);
18042 -- All other cases do not require a transient scope
18045 pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
18048 end Old_Requires_Transient_Scope;
18050 ----------------------------------
18051 -- New_Requires_Transient_Scope --
18052 ----------------------------------
18054 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
18056 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean;
18057 -- This is called for untagged records and protected types, with
18058 -- nondefaulted discriminants. Returns True if the size of function
18059 -- results is known at the call site, False otherwise. Returns False
18060 -- if there is a variant part that depends on the discriminants of
18061 -- this type, or if there is an array constrained by the discriminants
18062 -- of this type. ???Currently, this is overly conservative (the array
18063 -- could be nested inside some other record that is constrained by
18064 -- nondiscriminants). That is, the recursive calls are too conservative.
18066 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean;
18067 -- Returns True if Typ is a nonlimited record with defaulted
18068 -- discriminants whose max size makes it unsuitable for allocating on
18069 -- the primary stack.
18071 ------------------------------
18072 -- Caller_Known_Size_Record --
18073 ------------------------------
18075 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean is
18076 pragma Assert (Typ = Underlying_Type (Typ));
18079 if Has_Variant_Part (Typ) and then not Is_Definite_Subtype (Typ) then
18087 Comp := First_Entity (Typ);
18088 while Present (Comp) loop
18090 -- Only look at E_Component entities. No need to look at
18091 -- E_Discriminant entities, and we must ignore internal
18092 -- subtypes generated for constrained components.
18094 if Ekind (Comp) = E_Component then
18096 Comp_Type : constant Entity_Id :=
18097 Underlying_Type (Etype (Comp));
18100 if Is_Record_Type (Comp_Type)
18102 Is_Protected_Type (Comp_Type)
18104 if not Caller_Known_Size_Record (Comp_Type) then
18108 elsif Is_Array_Type (Comp_Type) then
18109 if Size_Depends_On_Discriminant (Comp_Type) then
18116 Next_Entity (Comp);
18121 end Caller_Known_Size_Record;
18123 ------------------------------
18124 -- Large_Max_Size_Mutable --
18125 ------------------------------
18127 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean is
18128 pragma Assert (Typ = Underlying_Type (Typ));
18130 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean;
18131 -- Returns true if the discrete type T has a large range
18133 ----------------------------
18134 -- Is_Large_Discrete_Type --
18135 ----------------------------
18137 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean is
18138 Threshold : constant Int := 16;
18139 -- Arbitrary threshold above which we consider it "large". We want
18140 -- a fairly large threshold, because these large types really
18141 -- shouldn't have default discriminants in the first place, in
18145 return UI_To_Int (RM_Size (T)) > Threshold;
18146 end Is_Large_Discrete_Type;
18149 if Is_Record_Type (Typ)
18150 and then not Is_Limited_View (Typ)
18151 and then Has_Defaulted_Discriminants (Typ)
18153 -- Loop through the components, looking for an array whose upper
18154 -- bound(s) depends on discriminants, where both the subtype of
18155 -- the discriminant and the index subtype are too large.
18161 Comp := First_Entity (Typ);
18162 while Present (Comp) loop
18163 if Ekind (Comp) = E_Component then
18165 Comp_Type : constant Entity_Id :=
18166 Underlying_Type (Etype (Comp));
18172 if Is_Array_Type (Comp_Type) then
18173 Indx := First_Index (Comp_Type);
18175 while Present (Indx) loop
18176 Ityp := Etype (Indx);
18177 Hi := Type_High_Bound (Ityp);
18179 if Nkind (Hi) = N_Identifier
18180 and then Ekind (Entity (Hi)) = E_Discriminant
18181 and then Is_Large_Discrete_Type (Ityp)
18182 and then Is_Large_Discrete_Type
18183 (Etype (Entity (Hi)))
18194 Next_Entity (Comp);
18200 end Large_Max_Size_Mutable;
18202 -- Local declarations
18204 Typ : constant Entity_Id := Underlying_Type (Id);
18206 -- Start of processing for New_Requires_Transient_Scope
18209 -- This is a private type which is not completed yet. This can only
18210 -- happen in a default expression (of a formal parameter or of a
18211 -- record component). Do not expand transient scope in this case.
18216 -- Do not expand transient scope for non-existent procedure return or
18217 -- string literal types.
18219 elsif Typ = Standard_Void_Type
18220 or else Ekind (Typ) = E_String_Literal_Subtype
18224 -- If Typ is a generic formal incomplete type, then we want to look at
18225 -- the actual type.
18227 elsif Ekind (Typ) = E_Record_Subtype
18228 and then Present (Cloned_Subtype (Typ))
18230 return New_Requires_Transient_Scope (Cloned_Subtype (Typ));
18232 -- Functions returning specific tagged types may dispatch on result, so
18233 -- their returned value is allocated on the secondary stack, even in the
18234 -- definite case. We must treat nondispatching functions the same way,
18235 -- because access-to-function types can point at both, so the calling
18236 -- conventions must be compatible. Is_Tagged_Type includes controlled
18237 -- types and class-wide types. Controlled type temporaries need
18240 -- ???It's not clear why we need to return noncontrolled types with
18241 -- controlled components on the secondary stack.
18243 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
18246 -- Untagged definite subtypes are known size. This includes all
18247 -- elementary [sub]types. Tasks are known size even if they have
18248 -- discriminants. So we return False here, with one exception:
18249 -- For a type like:
18250 -- type T (Last : Natural := 0) is
18251 -- X : String (1 .. Last);
18253 -- we return True. That's because for "P(F(...));", where F returns T,
18254 -- we don't know the size of the result at the call site, so if we
18255 -- allocated it on the primary stack, we would have to allocate the
18256 -- maximum size, which is way too big.
18258 elsif Is_Definite_Subtype (Typ) or else Is_Task_Type (Typ) then
18259 return Large_Max_Size_Mutable (Typ);
18261 -- Indefinite (discriminated) untagged record or protected type
18263 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
18264 return not Caller_Known_Size_Record (Typ);
18266 -- Unconstrained array
18269 pragma Assert (Is_Array_Type (Typ) and not Is_Definite_Subtype (Typ));
18272 end New_Requires_Transient_Scope;
18274 --------------------------
18275 -- Reset_Analyzed_Flags --
18276 --------------------------
18278 procedure Reset_Analyzed_Flags (N : Node_Id) is
18280 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
18281 -- Function used to reset Analyzed flags in tree. Note that we do
18282 -- not reset Analyzed flags in entities, since there is no need to
18283 -- reanalyze entities, and indeed, it is wrong to do so, since it
18284 -- can result in generating auxiliary stuff more than once.
18286 --------------------
18287 -- Clear_Analyzed --
18288 --------------------
18290 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
18292 if not Has_Extension (N) then
18293 Set_Analyzed (N, False);
18297 end Clear_Analyzed;
18299 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
18301 -- Start of processing for Reset_Analyzed_Flags
18304 Reset_Analyzed (N);
18305 end Reset_Analyzed_Flags;
18307 ------------------------
18308 -- Restore_SPARK_Mode --
18309 ------------------------
18311 procedure Restore_SPARK_Mode (Mode : SPARK_Mode_Type) is
18313 SPARK_Mode := Mode;
18314 end Restore_SPARK_Mode;
18316 --------------------------------
18317 -- Returns_Unconstrained_Type --
18318 --------------------------------
18320 function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
18322 return Ekind (Subp) = E_Function
18323 and then not Is_Scalar_Type (Etype (Subp))
18324 and then not Is_Access_Type (Etype (Subp))
18325 and then not Is_Constrained (Etype (Subp));
18326 end Returns_Unconstrained_Type;
18328 ----------------------------
18329 -- Root_Type_Of_Full_View --
18330 ----------------------------
18332 function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id is
18333 Rtyp : constant Entity_Id := Root_Type (T);
18336 -- The root type of the full view may itself be a private type. Keep
18337 -- looking for the ultimate derivation parent.
18339 if Is_Private_Type (Rtyp) and then Present (Full_View (Rtyp)) then
18340 return Root_Type_Of_Full_View (Full_View (Rtyp));
18344 end Root_Type_Of_Full_View;
18346 ---------------------------
18347 -- Safe_To_Capture_Value --
18348 ---------------------------
18350 function Safe_To_Capture_Value
18353 Cond : Boolean := False) return Boolean
18356 -- The only entities for which we track constant values are variables
18357 -- which are not renamings, constants, out parameters, and in out
18358 -- parameters, so check if we have this case.
18360 -- Note: it may seem odd to track constant values for constants, but in
18361 -- fact this routine is used for other purposes than simply capturing
18362 -- the value. In particular, the setting of Known[_Non]_Null.
18364 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
18366 Ekind_In (Ent, E_Constant, E_Out_Parameter, E_In_Out_Parameter)
18370 -- For conditionals, we also allow loop parameters and all formals,
18371 -- including in parameters.
18373 elsif Cond and then Ekind_In (Ent, E_Loop_Parameter, E_In_Parameter) then
18376 -- For all other cases, not just unsafe, but impossible to capture
18377 -- Current_Value, since the above are the only entities which have
18378 -- Current_Value fields.
18384 -- Skip if volatile or aliased, since funny things might be going on in
18385 -- these cases which we cannot necessarily track. Also skip any variable
18386 -- for which an address clause is given, or whose address is taken. Also
18387 -- never capture value of library level variables (an attempt to do so
18388 -- can occur in the case of package elaboration code).
18390 if Treat_As_Volatile (Ent)
18391 or else Is_Aliased (Ent)
18392 or else Present (Address_Clause (Ent))
18393 or else Address_Taken (Ent)
18394 or else (Is_Library_Level_Entity (Ent)
18395 and then Ekind (Ent) = E_Variable)
18400 -- OK, all above conditions are met. We also require that the scope of
18401 -- the reference be the same as the scope of the entity, not counting
18402 -- packages and blocks and loops.
18405 E_Scope : constant Entity_Id := Scope (Ent);
18406 R_Scope : Entity_Id;
18409 R_Scope := Current_Scope;
18410 while R_Scope /= Standard_Standard loop
18411 exit when R_Scope = E_Scope;
18413 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
18416 R_Scope := Scope (R_Scope);
18421 -- We also require that the reference does not appear in a context
18422 -- where it is not sure to be executed (i.e. a conditional context
18423 -- or an exception handler). We skip this if Cond is True, since the
18424 -- capturing of values from conditional tests handles this ok.
18437 -- Seems dubious that case expressions are not handled here ???
18440 while Present (P) loop
18441 if Nkind (P) = N_If_Statement
18442 or else Nkind (P) = N_Case_Statement
18443 or else (Nkind (P) in N_Short_Circuit
18444 and then Desc = Right_Opnd (P))
18445 or else (Nkind (P) = N_If_Expression
18446 and then Desc /= First (Expressions (P)))
18447 or else Nkind (P) = N_Exception_Handler
18448 or else Nkind (P) = N_Selective_Accept
18449 or else Nkind (P) = N_Conditional_Entry_Call
18450 or else Nkind (P) = N_Timed_Entry_Call
18451 or else Nkind (P) = N_Asynchronous_Select
18459 -- A special Ada 2012 case: the original node may be part
18460 -- of the else_actions of a conditional expression, in which
18461 -- case it might not have been expanded yet, and appears in
18462 -- a non-syntactic list of actions. In that case it is clearly
18463 -- not safe to save a value.
18466 and then Is_List_Member (Desc)
18467 and then No (Parent (List_Containing (Desc)))
18475 -- OK, looks safe to set value
18478 end Safe_To_Capture_Value;
18484 function Same_Name (N1, N2 : Node_Id) return Boolean is
18485 K1 : constant Node_Kind := Nkind (N1);
18486 K2 : constant Node_Kind := Nkind (N2);
18489 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
18490 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
18492 return Chars (N1) = Chars (N2);
18494 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
18495 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
18497 return Same_Name (Selector_Name (N1), Selector_Name (N2))
18498 and then Same_Name (Prefix (N1), Prefix (N2));
18509 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
18510 N1 : constant Node_Id := Original_Node (Node1);
18511 N2 : constant Node_Id := Original_Node (Node2);
18512 -- We do the tests on original nodes, since we are most interested
18513 -- in the original source, not any expansion that got in the way.
18515 K1 : constant Node_Kind := Nkind (N1);
18516 K2 : constant Node_Kind := Nkind (N2);
18519 -- First case, both are entities with same entity
18521 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
18523 EN1 : constant Entity_Id := Entity (N1);
18524 EN2 : constant Entity_Id := Entity (N2);
18526 if Present (EN1) and then Present (EN2)
18527 and then (Ekind_In (EN1, E_Variable, E_Constant)
18528 or else Is_Formal (EN1))
18536 -- Second case, selected component with same selector, same record
18538 if K1 = N_Selected_Component
18539 and then K2 = N_Selected_Component
18540 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
18542 return Same_Object (Prefix (N1), Prefix (N2));
18544 -- Third case, indexed component with same subscripts, same array
18546 elsif K1 = N_Indexed_Component
18547 and then K2 = N_Indexed_Component
18548 and then Same_Object (Prefix (N1), Prefix (N2))
18553 E1 := First (Expressions (N1));
18554 E2 := First (Expressions (N2));
18555 while Present (E1) loop
18556 if not Same_Value (E1, E2) then
18567 -- Fourth case, slice of same array with same bounds
18570 and then K2 = N_Slice
18571 and then Nkind (Discrete_Range (N1)) = N_Range
18572 and then Nkind (Discrete_Range (N2)) = N_Range
18573 and then Same_Value (Low_Bound (Discrete_Range (N1)),
18574 Low_Bound (Discrete_Range (N2)))
18575 and then Same_Value (High_Bound (Discrete_Range (N1)),
18576 High_Bound (Discrete_Range (N2)))
18578 return Same_Name (Prefix (N1), Prefix (N2));
18580 -- All other cases, not clearly the same object
18591 function Same_Type (T1, T2 : Entity_Id) return Boolean is
18596 elsif not Is_Constrained (T1)
18597 and then not Is_Constrained (T2)
18598 and then Base_Type (T1) = Base_Type (T2)
18602 -- For now don't bother with case of identical constraints, to be
18603 -- fiddled with later on perhaps (this is only used for optimization
18604 -- purposes, so it is not critical to do a best possible job)
18615 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
18617 if Compile_Time_Known_Value (Node1)
18618 and then Compile_Time_Known_Value (Node2)
18619 and then Expr_Value (Node1) = Expr_Value (Node2)
18622 elsif Same_Object (Node1, Node2) then
18629 -----------------------------
18630 -- Save_SPARK_Mode_And_Set --
18631 -----------------------------
18633 procedure Save_SPARK_Mode_And_Set
18634 (Context : Entity_Id;
18635 Mode : out SPARK_Mode_Type)
18638 -- Save the current mode in effect
18640 Mode := SPARK_Mode;
18642 -- Do not consider illegal or partially decorated constructs
18644 if Ekind (Context) = E_Void or else Error_Posted (Context) then
18647 elsif Present (SPARK_Pragma (Context)) then
18648 SPARK_Mode := Get_SPARK_Mode_From_Annotation (SPARK_Pragma (Context));
18650 end Save_SPARK_Mode_And_Set;
18652 -------------------------
18653 -- Scalar_Part_Present --
18654 -------------------------
18656 function Scalar_Part_Present (T : Entity_Id) return Boolean is
18660 if Is_Scalar_Type (T) then
18663 elsif Is_Array_Type (T) then
18664 return Scalar_Part_Present (Component_Type (T));
18666 elsif Is_Record_Type (T) or else Has_Discriminants (T) then
18667 C := First_Component_Or_Discriminant (T);
18668 while Present (C) loop
18669 if Scalar_Part_Present (Etype (C)) then
18672 Next_Component_Or_Discriminant (C);
18678 end Scalar_Part_Present;
18680 ------------------------
18681 -- Scope_Is_Transient --
18682 ------------------------
18684 function Scope_Is_Transient return Boolean is
18686 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
18687 end Scope_Is_Transient;
18693 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
18698 while Scop /= Standard_Standard loop
18699 Scop := Scope (Scop);
18701 if Scop = Scope2 then
18709 --------------------------
18710 -- Scope_Within_Or_Same --
18711 --------------------------
18713 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
18718 while Scop /= Standard_Standard loop
18719 if Scop = Scope2 then
18722 Scop := Scope (Scop);
18727 end Scope_Within_Or_Same;
18729 --------------------
18730 -- Set_Convention --
18731 --------------------
18733 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
18735 Basic_Set_Convention (E, Val);
18738 and then Is_Access_Subprogram_Type (Base_Type (E))
18739 and then Has_Foreign_Convention (E)
18742 -- A pragma Convention in an instance may apply to the subtype
18743 -- created for a formal, in which case we have already verified
18744 -- that conventions of actual and formal match and there is nothing
18745 -- to flag on the subtype.
18747 if In_Instance then
18750 Set_Can_Use_Internal_Rep (E, False);
18754 -- If E is an object or component, and the type of E is an anonymous
18755 -- access type with no convention set, then also set the convention of
18756 -- the anonymous access type. We do not do this for anonymous protected
18757 -- types, since protected types always have the default convention.
18759 if Present (Etype (E))
18760 and then (Is_Object (E)
18761 or else Ekind (E) = E_Component
18763 -- Allow E_Void (happens for pragma Convention appearing
18764 -- in the middle of a record applying to a component)
18766 or else Ekind (E) = E_Void)
18769 Typ : constant Entity_Id := Etype (E);
18772 if Ekind_In (Typ, E_Anonymous_Access_Type,
18773 E_Anonymous_Access_Subprogram_Type)
18774 and then not Has_Convention_Pragma (Typ)
18776 Basic_Set_Convention (Typ, Val);
18777 Set_Has_Convention_Pragma (Typ);
18779 -- And for the access subprogram type, deal similarly with the
18780 -- designated E_Subprogram_Type if it is also internal (which
18783 if Ekind (Typ) = E_Anonymous_Access_Subprogram_Type then
18785 Dtype : constant Entity_Id := Designated_Type (Typ);
18787 if Ekind (Dtype) = E_Subprogram_Type
18788 and then Is_Itype (Dtype)
18789 and then not Has_Convention_Pragma (Dtype)
18791 Basic_Set_Convention (Dtype, Val);
18792 Set_Has_Convention_Pragma (Dtype);
18799 end Set_Convention;
18801 ------------------------
18802 -- Set_Current_Entity --
18803 ------------------------
18805 -- The given entity is to be set as the currently visible definition of its
18806 -- associated name (i.e. the Node_Id associated with its name). All we have
18807 -- to do is to get the name from the identifier, and then set the
18808 -- associated Node_Id to point to the given entity.
18810 procedure Set_Current_Entity (E : Entity_Id) is
18812 Set_Name_Entity_Id (Chars (E), E);
18813 end Set_Current_Entity;
18815 ---------------------------
18816 -- Set_Debug_Info_Needed --
18817 ---------------------------
18819 procedure Set_Debug_Info_Needed (T : Entity_Id) is
18821 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
18822 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
18823 -- Used to set debug info in a related node if not set already
18825 --------------------------------------
18826 -- Set_Debug_Info_Needed_If_Not_Set --
18827 --------------------------------------
18829 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
18831 if Present (E) and then not Needs_Debug_Info (E) then
18832 Set_Debug_Info_Needed (E);
18834 -- For a private type, indicate that the full view also needs
18835 -- debug information.
18838 and then Is_Private_Type (E)
18839 and then Present (Full_View (E))
18841 Set_Debug_Info_Needed (Full_View (E));
18844 end Set_Debug_Info_Needed_If_Not_Set;
18846 -- Start of processing for Set_Debug_Info_Needed
18849 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
18850 -- indicates that Debug_Info_Needed is never required for the entity.
18851 -- Nothing to do if entity comes from a predefined file. Library files
18852 -- are compiled without debug information, but inlined bodies of these
18853 -- routines may appear in user code, and debug information on them ends
18854 -- up complicating debugging the user code.
18857 or else Debug_Info_Off (T)
18861 elsif In_Inlined_Body
18862 and then Is_Predefined_File_Name
18863 (Unit_File_Name (Get_Source_Unit (Sloc (T))))
18865 Set_Needs_Debug_Info (T, False);
18868 -- Set flag in entity itself. Note that we will go through the following
18869 -- circuitry even if the flag is already set on T. That's intentional,
18870 -- it makes sure that the flag will be set in subsidiary entities.
18872 Set_Needs_Debug_Info (T);
18874 -- Set flag on subsidiary entities if not set already
18876 if Is_Object (T) then
18877 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
18879 elsif Is_Type (T) then
18880 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
18882 if Is_Record_Type (T) then
18884 Ent : Entity_Id := First_Entity (T);
18886 while Present (Ent) loop
18887 Set_Debug_Info_Needed_If_Not_Set (Ent);
18892 -- For a class wide subtype, we also need debug information
18893 -- for the equivalent type.
18895 if Ekind (T) = E_Class_Wide_Subtype then
18896 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
18899 elsif Is_Array_Type (T) then
18900 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
18903 Indx : Node_Id := First_Index (T);
18905 while Present (Indx) loop
18906 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
18907 Indx := Next_Index (Indx);
18911 -- For a packed array type, we also need debug information for
18912 -- the type used to represent the packed array. Conversely, we
18913 -- also need it for the former if we need it for the latter.
18915 if Is_Packed (T) then
18916 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Impl_Type (T));
18919 if Is_Packed_Array_Impl_Type (T) then
18920 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
18923 elsif Is_Access_Type (T) then
18924 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
18926 elsif Is_Private_Type (T) then
18928 FV : constant Entity_Id := Full_View (T);
18931 Set_Debug_Info_Needed_If_Not_Set (FV);
18933 -- If the full view is itself a derived private type, we need
18934 -- debug information on its underlying type.
18937 and then Is_Private_Type (FV)
18938 and then Present (Underlying_Full_View (FV))
18940 Set_Needs_Debug_Info (Underlying_Full_View (FV));
18944 elsif Is_Protected_Type (T) then
18945 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
18947 elsif Is_Scalar_Type (T) then
18949 -- If the subrange bounds are materialized by dedicated constant
18950 -- objects, also include them in the debug info to make sure the
18951 -- debugger can properly use them.
18953 if Present (Scalar_Range (T))
18954 and then Nkind (Scalar_Range (T)) = N_Range
18957 Low_Bnd : constant Node_Id := Type_Low_Bound (T);
18958 High_Bnd : constant Node_Id := Type_High_Bound (T);
18961 if Is_Entity_Name (Low_Bnd) then
18962 Set_Debug_Info_Needed_If_Not_Set (Entity (Low_Bnd));
18965 if Is_Entity_Name (High_Bnd) then
18966 Set_Debug_Info_Needed_If_Not_Set (Entity (High_Bnd));
18972 end Set_Debug_Info_Needed;
18974 ----------------------------
18975 -- Set_Entity_With_Checks --
18976 ----------------------------
18978 procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id) is
18979 Val_Actual : Entity_Id;
18981 Post_Node : Node_Id;
18984 -- Unconditionally set the entity
18986 Set_Entity (N, Val);
18988 -- The node to post on is the selector in the case of an expanded name,
18989 -- and otherwise the node itself.
18991 if Nkind (N) = N_Expanded_Name then
18992 Post_Node := Selector_Name (N);
18997 -- Check for violation of No_Fixed_IO
18999 if Restriction_Check_Required (No_Fixed_IO)
19001 ((RTU_Loaded (Ada_Text_IO)
19002 and then (Is_RTE (Val, RE_Decimal_IO)
19004 Is_RTE (Val, RE_Fixed_IO)))
19007 (RTU_Loaded (Ada_Wide_Text_IO)
19008 and then (Is_RTE (Val, RO_WT_Decimal_IO)
19010 Is_RTE (Val, RO_WT_Fixed_IO)))
19013 (RTU_Loaded (Ada_Wide_Wide_Text_IO)
19014 and then (Is_RTE (Val, RO_WW_Decimal_IO)
19016 Is_RTE (Val, RO_WW_Fixed_IO))))
19018 -- A special extra check, don't complain about a reference from within
19019 -- the Ada.Interrupts package itself!
19021 and then not In_Same_Extended_Unit (N, Val)
19023 Check_Restriction (No_Fixed_IO, Post_Node);
19026 -- Remaining checks are only done on source nodes. Note that we test
19027 -- for violation of No_Fixed_IO even on non-source nodes, because the
19028 -- cases for checking violations of this restriction are instantiations
19029 -- where the reference in the instance has Comes_From_Source False.
19031 if not Comes_From_Source (N) then
19035 -- Check for violation of No_Abort_Statements, which is triggered by
19036 -- call to Ada.Task_Identification.Abort_Task.
19038 if Restriction_Check_Required (No_Abort_Statements)
19039 and then (Is_RTE (Val, RE_Abort_Task))
19041 -- A special extra check, don't complain about a reference from within
19042 -- the Ada.Task_Identification package itself!
19044 and then not In_Same_Extended_Unit (N, Val)
19046 Check_Restriction (No_Abort_Statements, Post_Node);
19049 if Val = Standard_Long_Long_Integer then
19050 Check_Restriction (No_Long_Long_Integers, Post_Node);
19053 -- Check for violation of No_Dynamic_Attachment
19055 if Restriction_Check_Required (No_Dynamic_Attachment)
19056 and then RTU_Loaded (Ada_Interrupts)
19057 and then (Is_RTE (Val, RE_Is_Reserved) or else
19058 Is_RTE (Val, RE_Is_Attached) or else
19059 Is_RTE (Val, RE_Current_Handler) or else
19060 Is_RTE (Val, RE_Attach_Handler) or else
19061 Is_RTE (Val, RE_Exchange_Handler) or else
19062 Is_RTE (Val, RE_Detach_Handler) or else
19063 Is_RTE (Val, RE_Reference))
19065 -- A special extra check, don't complain about a reference from within
19066 -- the Ada.Interrupts package itself!
19068 and then not In_Same_Extended_Unit (N, Val)
19070 Check_Restriction (No_Dynamic_Attachment, Post_Node);
19073 -- Check for No_Implementation_Identifiers
19075 if Restriction_Check_Required (No_Implementation_Identifiers) then
19077 -- We have an implementation defined entity if it is marked as
19078 -- implementation defined, or is defined in a package marked as
19079 -- implementation defined. However, library packages themselves
19080 -- are excluded (we don't want to flag Interfaces itself, just
19081 -- the entities within it).
19083 if (Is_Implementation_Defined (Val)
19085 (Present (Scope (Val))
19086 and then Is_Implementation_Defined (Scope (Val))))
19087 and then not (Ekind_In (Val, E_Package, E_Generic_Package)
19088 and then Is_Library_Level_Entity (Val))
19090 Check_Restriction (No_Implementation_Identifiers, Post_Node);
19094 -- Do the style check
19097 and then not Suppress_Style_Checks (Val)
19098 and then not In_Instance
19100 if Nkind (N) = N_Identifier then
19102 elsif Nkind (N) = N_Expanded_Name then
19103 Nod := Selector_Name (N);
19108 -- A special situation arises for derived operations, where we want
19109 -- to do the check against the parent (since the Sloc of the derived
19110 -- operation points to the derived type declaration itself).
19113 while not Comes_From_Source (Val_Actual)
19114 and then Nkind (Val_Actual) in N_Entity
19115 and then (Ekind (Val_Actual) = E_Enumeration_Literal
19116 or else Is_Subprogram_Or_Generic_Subprogram (Val_Actual))
19117 and then Present (Alias (Val_Actual))
19119 Val_Actual := Alias (Val_Actual);
19122 -- Renaming declarations for generic actuals do not come from source,
19123 -- and have a different name from that of the entity they rename, so
19124 -- there is no style check to perform here.
19126 if Chars (Nod) = Chars (Val_Actual) then
19127 Style.Check_Identifier (Nod, Val_Actual);
19131 Set_Entity (N, Val);
19132 end Set_Entity_With_Checks;
19134 ------------------------
19135 -- Set_Name_Entity_Id --
19136 ------------------------
19138 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
19140 Set_Name_Table_Int (Id, Int (Val));
19141 end Set_Name_Entity_Id;
19143 ---------------------
19144 -- Set_Next_Actual --
19145 ---------------------
19147 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
19149 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
19150 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
19152 end Set_Next_Actual;
19154 ----------------------------------
19155 -- Set_Optimize_Alignment_Flags --
19156 ----------------------------------
19158 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
19160 if Optimize_Alignment = 'S' then
19161 Set_Optimize_Alignment_Space (E);
19162 elsif Optimize_Alignment = 'T' then
19163 Set_Optimize_Alignment_Time (E);
19165 end Set_Optimize_Alignment_Flags;
19167 -----------------------
19168 -- Set_Public_Status --
19169 -----------------------
19171 procedure Set_Public_Status (Id : Entity_Id) is
19172 S : constant Entity_Id := Current_Scope;
19174 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
19175 -- Determines if E is defined within handled statement sequence or
19176 -- an if statement, returns True if so, False otherwise.
19178 ----------------------
19179 -- Within_HSS_Or_If --
19180 ----------------------
19182 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
19185 N := Declaration_Node (E);
19192 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
19198 end Within_HSS_Or_If;
19200 -- Start of processing for Set_Public_Status
19203 -- Everything in the scope of Standard is public
19205 if S = Standard_Standard then
19206 Set_Is_Public (Id);
19208 -- Entity is definitely not public if enclosing scope is not public
19210 elsif not Is_Public (S) then
19213 -- An object or function declaration that occurs in a handled sequence
19214 -- of statements or within an if statement is the declaration for a
19215 -- temporary object or local subprogram generated by the expander. It
19216 -- never needs to be made public and furthermore, making it public can
19217 -- cause back end problems.
19219 elsif Nkind_In (Parent (Id), N_Object_Declaration,
19220 N_Function_Specification)
19221 and then Within_HSS_Or_If (Id)
19225 -- Entities in public packages or records are public
19227 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
19228 Set_Is_Public (Id);
19230 -- The bounds of an entry family declaration can generate object
19231 -- declarations that are visible to the back-end, e.g. in the
19232 -- the declaration of a composite type that contains tasks.
19234 elsif Is_Concurrent_Type (S)
19235 and then not Has_Completion (S)
19236 and then Nkind (Parent (Id)) = N_Object_Declaration
19238 Set_Is_Public (Id);
19240 end Set_Public_Status;
19242 -----------------------------
19243 -- Set_Referenced_Modified --
19244 -----------------------------
19246 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
19250 -- Deal with indexed or selected component where prefix is modified
19252 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
19253 Pref := Prefix (N);
19255 -- If prefix is access type, then it is the designated object that is
19256 -- being modified, which means we have no entity to set the flag on.
19258 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
19261 -- Otherwise chase the prefix
19264 Set_Referenced_Modified (Pref, Out_Param);
19267 -- Otherwise see if we have an entity name (only other case to process)
19269 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
19270 Set_Referenced_As_LHS (Entity (N), not Out_Param);
19271 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
19273 end Set_Referenced_Modified;
19275 ----------------------------
19276 -- Set_Scope_Is_Transient --
19277 ----------------------------
19279 procedure Set_Scope_Is_Transient (V : Boolean := True) is
19281 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
19282 end Set_Scope_Is_Transient;
19284 -------------------
19285 -- Set_Size_Info --
19286 -------------------
19288 procedure Set_Size_Info (T1, T2 : Entity_Id) is
19290 -- We copy Esize, but not RM_Size, since in general RM_Size is
19291 -- subtype specific and does not get inherited by all subtypes.
19293 Set_Esize (T1, Esize (T2));
19294 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
19296 if Is_Discrete_Or_Fixed_Point_Type (T1)
19298 Is_Discrete_Or_Fixed_Point_Type (T2)
19300 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
19303 Set_Alignment (T1, Alignment (T2));
19306 --------------------
19307 -- Static_Boolean --
19308 --------------------
19310 function Static_Boolean (N : Node_Id) return Uint is
19312 Analyze_And_Resolve (N, Standard_Boolean);
19315 or else Error_Posted (N)
19316 or else Etype (N) = Any_Type
19321 if Is_OK_Static_Expression (N) then
19322 if not Raises_Constraint_Error (N) then
19323 return Expr_Value (N);
19328 elsif Etype (N) = Any_Type then
19332 Flag_Non_Static_Expr
19333 ("static boolean expression required here", N);
19336 end Static_Boolean;
19338 --------------------
19339 -- Static_Integer --
19340 --------------------
19342 function Static_Integer (N : Node_Id) return Uint is
19344 Analyze_And_Resolve (N, Any_Integer);
19347 or else Error_Posted (N)
19348 or else Etype (N) = Any_Type
19353 if Is_OK_Static_Expression (N) then
19354 if not Raises_Constraint_Error (N) then
19355 return Expr_Value (N);
19360 elsif Etype (N) = Any_Type then
19364 Flag_Non_Static_Expr
19365 ("static integer expression required here", N);
19368 end Static_Integer;
19370 --------------------------
19371 -- Statically_Different --
19372 --------------------------
19374 function Statically_Different (E1, E2 : Node_Id) return Boolean is
19375 R1 : constant Node_Id := Get_Referenced_Object (E1);
19376 R2 : constant Node_Id := Get_Referenced_Object (E2);
19378 return Is_Entity_Name (R1)
19379 and then Is_Entity_Name (R2)
19380 and then Entity (R1) /= Entity (R2)
19381 and then not Is_Formal (Entity (R1))
19382 and then not Is_Formal (Entity (R2));
19383 end Statically_Different;
19385 --------------------------------------
19386 -- Subject_To_Loop_Entry_Attributes --
19387 --------------------------------------
19389 function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
19395 -- The expansion mechanism transform a loop subject to at least one
19396 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
19397 -- the conditional part.
19399 if Nkind_In (Stmt, N_Block_Statement, N_If_Statement)
19400 and then Nkind (Original_Node (N)) = N_Loop_Statement
19402 Stmt := Original_Node (N);
19406 Nkind (Stmt) = N_Loop_Statement
19407 and then Present (Identifier (Stmt))
19408 and then Present (Entity (Identifier (Stmt)))
19409 and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
19410 end Subject_To_Loop_Entry_Attributes;
19412 -----------------------------
19413 -- Subprogram_Access_Level --
19414 -----------------------------
19416 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
19418 if Present (Alias (Subp)) then
19419 return Subprogram_Access_Level (Alias (Subp));
19421 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
19423 end Subprogram_Access_Level;
19425 -------------------------------
19426 -- Support_Atomic_Primitives --
19427 -------------------------------
19429 function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
19433 -- Verify the alignment of Typ is known
19435 if not Known_Alignment (Typ) then
19439 if Known_Static_Esize (Typ) then
19440 Size := UI_To_Int (Esize (Typ));
19442 -- If the Esize (Object_Size) is unknown at compile time, look at the
19443 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
19445 elsif Known_Static_RM_Size (Typ) then
19446 Size := UI_To_Int (RM_Size (Typ));
19448 -- Otherwise, the size is considered to be unknown.
19454 -- Check that the size of the component is 8, 16, 32 or 64 bits and that
19455 -- Typ is properly aligned.
19458 when 8 | 16 | 32 | 64 =>
19459 return Size = UI_To_Int (Alignment (Typ)) * 8;
19463 end Support_Atomic_Primitives;
19469 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
19471 if Debug_Flag_W then
19472 for J in 0 .. Scope_Stack.Last loop
19477 Write_Name (Chars (E));
19478 Write_Str (" from ");
19479 Write_Location (Sloc (N));
19484 -----------------------
19485 -- Transfer_Entities --
19486 -----------------------
19488 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
19489 procedure Set_Public_Status_Of (Id : Entity_Id);
19490 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
19491 -- Set_Public_Status. If successfull and Id denotes a record type, set
19492 -- the Is_Public attribute of its fields.
19494 --------------------------
19495 -- Set_Public_Status_Of --
19496 --------------------------
19498 procedure Set_Public_Status_Of (Id : Entity_Id) is
19502 if not Is_Public (Id) then
19503 Set_Public_Status (Id);
19505 -- When the input entity is a public record type, ensure that all
19506 -- its internal fields are also exposed to the linker. The fields
19507 -- of a class-wide type are never made public.
19510 and then Is_Record_Type (Id)
19511 and then not Is_Class_Wide_Type (Id)
19513 Field := First_Entity (Id);
19514 while Present (Field) loop
19515 Set_Is_Public (Field);
19516 Next_Entity (Field);
19520 end Set_Public_Status_Of;
19524 Full_Id : Entity_Id;
19527 -- Start of processing for Transfer_Entities
19530 Id := First_Entity (From);
19532 if Present (Id) then
19534 -- Merge the entity chain of the source scope with that of the
19535 -- destination scope.
19537 if Present (Last_Entity (To)) then
19538 Set_Next_Entity (Last_Entity (To), Id);
19540 Set_First_Entity (To, Id);
19543 Set_Last_Entity (To, Last_Entity (From));
19545 -- Inspect the entities of the source scope and update their Scope
19548 while Present (Id) loop
19549 Set_Scope (Id, To);
19550 Set_Public_Status_Of (Id);
19552 -- Handle an internally generated full view for a private type
19554 if Is_Private_Type (Id)
19555 and then Present (Full_View (Id))
19556 and then Is_Itype (Full_View (Id))
19558 Full_Id := Full_View (Id);
19560 Set_Scope (Full_Id, To);
19561 Set_Public_Status_Of (Full_Id);
19567 Set_First_Entity (From, Empty);
19568 Set_Last_Entity (From, Empty);
19570 end Transfer_Entities;
19572 -----------------------
19573 -- Type_Access_Level --
19574 -----------------------
19576 function Type_Access_Level (Typ : Entity_Id) return Uint is
19580 Btyp := Base_Type (Typ);
19582 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
19583 -- simply use the level where the type is declared. This is true for
19584 -- stand-alone object declarations, and for anonymous access types
19585 -- associated with components the level is the same as that of the
19586 -- enclosing composite type. However, special treatment is needed for
19587 -- the cases of access parameters, return objects of an anonymous access
19588 -- type, and, in Ada 95, access discriminants of limited types.
19590 if Is_Access_Type (Btyp) then
19591 if Ekind (Btyp) = E_Anonymous_Access_Type then
19593 -- If the type is a nonlocal anonymous access type (such as for
19594 -- an access parameter) we treat it as being declared at the
19595 -- library level to ensure that names such as X.all'access don't
19596 -- fail static accessibility checks.
19598 if not Is_Local_Anonymous_Access (Typ) then
19599 return Scope_Depth (Standard_Standard);
19601 -- If this is a return object, the accessibility level is that of
19602 -- the result subtype of the enclosing function. The test here is
19603 -- little complicated, because we have to account for extended
19604 -- return statements that have been rewritten as blocks, in which
19605 -- case we have to find and the Is_Return_Object attribute of the
19606 -- itype's associated object. It would be nice to find a way to
19607 -- simplify this test, but it doesn't seem worthwhile to add a new
19608 -- flag just for purposes of this test. ???
19610 elsif Ekind (Scope (Btyp)) = E_Return_Statement
19613 and then Nkind (Associated_Node_For_Itype (Btyp)) =
19614 N_Object_Declaration
19615 and then Is_Return_Object
19616 (Defining_Identifier
19617 (Associated_Node_For_Itype (Btyp))))
19623 Scop := Scope (Scope (Btyp));
19624 while Present (Scop) loop
19625 exit when Ekind (Scop) = E_Function;
19626 Scop := Scope (Scop);
19629 -- Treat the return object's type as having the level of the
19630 -- function's result subtype (as per RM05-6.5(5.3/2)).
19632 return Type_Access_Level (Etype (Scop));
19637 Btyp := Root_Type (Btyp);
19639 -- The accessibility level of anonymous access types associated with
19640 -- discriminants is that of the current instance of the type, and
19641 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
19643 -- AI-402: access discriminants have accessibility based on the
19644 -- object rather than the type in Ada 2005, so the above paragraph
19647 -- ??? Needs completion with rules from AI-416
19649 if Ada_Version <= Ada_95
19650 and then Ekind (Typ) = E_Anonymous_Access_Type
19651 and then Present (Associated_Node_For_Itype (Typ))
19652 and then Nkind (Associated_Node_For_Itype (Typ)) =
19653 N_Discriminant_Specification
19655 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
19659 -- Return library level for a generic formal type. This is done because
19660 -- RM(10.3.2) says that "The statically deeper relationship does not
19661 -- apply to ... a descendant of a generic formal type". Rather than
19662 -- checking at each point where a static accessibility check is
19663 -- performed to see if we are dealing with a formal type, this rule is
19664 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
19665 -- return extreme values for a formal type; Deepest_Type_Access_Level
19666 -- returns Int'Last. By calling the appropriate function from among the
19667 -- two, we ensure that the static accessibility check will pass if we
19668 -- happen to run into a formal type. More specifically, we should call
19669 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
19670 -- call occurs as part of a static accessibility check and the error
19671 -- case is the case where the type's level is too shallow (as opposed
19674 if Is_Generic_Type (Root_Type (Btyp)) then
19675 return Scope_Depth (Standard_Standard);
19678 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
19679 end Type_Access_Level;
19681 ------------------------------------
19682 -- Type_Without_Stream_Operation --
19683 ------------------------------------
19685 function Type_Without_Stream_Operation
19687 Op : TSS_Name_Type := TSS_Null) return Entity_Id
19689 BT : constant Entity_Id := Base_Type (T);
19690 Op_Missing : Boolean;
19693 if not Restriction_Active (No_Default_Stream_Attributes) then
19697 if Is_Elementary_Type (T) then
19698 if Op = TSS_Null then
19700 No (TSS (BT, TSS_Stream_Read))
19701 or else No (TSS (BT, TSS_Stream_Write));
19704 Op_Missing := No (TSS (BT, Op));
19713 elsif Is_Array_Type (T) then
19714 return Type_Without_Stream_Operation (Component_Type (T), Op);
19716 elsif Is_Record_Type (T) then
19722 Comp := First_Component (T);
19723 while Present (Comp) loop
19724 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
19726 if Present (C_Typ) then
19730 Next_Component (Comp);
19736 elsif Is_Private_Type (T) and then Present (Full_View (T)) then
19737 return Type_Without_Stream_Operation (Full_View (T), Op);
19741 end Type_Without_Stream_Operation;
19743 ----------------------------
19744 -- Unique_Defining_Entity --
19745 ----------------------------
19747 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
19749 return Unique_Entity (Defining_Entity (N));
19750 end Unique_Defining_Entity;
19752 -------------------
19753 -- Unique_Entity --
19754 -------------------
19756 function Unique_Entity (E : Entity_Id) return Entity_Id is
19757 U : Entity_Id := E;
19763 if Present (Full_View (E)) then
19764 U := Full_View (E);
19768 if Nkind (Parent (E)) = N_Entry_Body then
19770 Prot_Item : Entity_Id;
19772 -- Traverse the entity list of the protected type and locate
19773 -- an entry declaration which matches the entry body.
19775 Prot_Item := First_Entity (Scope (E));
19776 while Present (Prot_Item) loop
19777 if Ekind (Prot_Item) = E_Entry
19778 and then Corresponding_Body (Parent (Prot_Item)) = E
19784 Next_Entity (Prot_Item);
19789 when Formal_Kind =>
19790 if Present (Spec_Entity (E)) then
19791 U := Spec_Entity (E);
19794 when E_Package_Body =>
19797 if Nkind (P) = N_Defining_Program_Unit_Name then
19801 if Nkind (P) = N_Package_Body
19802 and then Present (Corresponding_Spec (P))
19804 U := Corresponding_Spec (P);
19806 elsif Nkind (P) = N_Package_Body_Stub
19807 and then Present (Corresponding_Spec_Of_Stub (P))
19809 U := Corresponding_Spec_Of_Stub (P);
19812 when E_Protected_Body =>
19815 if Nkind (P) = N_Protected_Body
19816 and then Present (Corresponding_Spec (P))
19818 U := Corresponding_Spec (P);
19820 elsif Nkind (P) = N_Protected_Body_Stub
19821 and then Present (Corresponding_Spec_Of_Stub (P))
19823 U := Corresponding_Spec_Of_Stub (P);
19826 when E_Subprogram_Body =>
19829 if Nkind (P) = N_Defining_Program_Unit_Name then
19835 if Nkind (P) = N_Subprogram_Body
19836 and then Present (Corresponding_Spec (P))
19838 U := Corresponding_Spec (P);
19840 elsif Nkind (P) = N_Subprogram_Body_Stub
19841 and then Present (Corresponding_Spec_Of_Stub (P))
19843 U := Corresponding_Spec_Of_Stub (P);
19846 when E_Task_Body =>
19849 if Nkind (P) = N_Task_Body
19850 and then Present (Corresponding_Spec (P))
19852 U := Corresponding_Spec (P);
19854 elsif Nkind (P) = N_Task_Body_Stub
19855 and then Present (Corresponding_Spec_Of_Stub (P))
19857 U := Corresponding_Spec_Of_Stub (P);
19861 if Present (Full_View (E)) then
19862 U := Full_View (E);
19876 function Unique_Name (E : Entity_Id) return String is
19878 -- Names of E_Subprogram_Body or E_Package_Body entities are not
19879 -- reliable, as they may not include the overloading suffix. Instead,
19880 -- when looking for the name of E or one of its enclosing scope, we get
19881 -- the name of the corresponding Unique_Entity.
19883 function Get_Scoped_Name (E : Entity_Id) return String;
19884 -- Return the name of E prefixed by all the names of the scopes to which
19885 -- E belongs, except for Standard.
19887 ---------------------
19888 -- Get_Scoped_Name --
19889 ---------------------
19891 function Get_Scoped_Name (E : Entity_Id) return String is
19892 Name : constant String := Get_Name_String (Chars (E));
19894 if Has_Fully_Qualified_Name (E)
19895 or else Scope (E) = Standard_Standard
19899 return Get_Scoped_Name (Unique_Entity (Scope (E))) & "__" & Name;
19901 end Get_Scoped_Name;
19903 -- Start of processing for Unique_Name
19906 if E = Standard_Standard then
19907 return Get_Name_String (Name_Standard);
19909 elsif Scope (E) = Standard_Standard
19910 and then not (Ekind (E) = E_Package or else Is_Subprogram (E))
19912 return Get_Name_String (Name_Standard) & "__" &
19913 Get_Name_String (Chars (E));
19915 elsif Ekind (E) = E_Enumeration_Literal then
19916 return Unique_Name (Etype (E)) & "__" & Get_Name_String (Chars (E));
19919 return Get_Scoped_Name (Unique_Entity (E));
19923 ---------------------
19924 -- Unit_Is_Visible --
19925 ---------------------
19927 function Unit_Is_Visible (U : Entity_Id) return Boolean is
19928 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
19929 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
19931 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
19932 -- For a child unit, check whether unit appears in a with_clause
19935 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
19936 -- Scan the context clause of one compilation unit looking for a
19937 -- with_clause for the unit in question.
19939 ----------------------------
19940 -- Unit_In_Parent_Context --
19941 ----------------------------
19943 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
19945 if Unit_In_Context (Par_Unit) then
19948 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
19949 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
19954 end Unit_In_Parent_Context;
19956 ---------------------
19957 -- Unit_In_Context --
19958 ---------------------
19960 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
19964 Clause := First (Context_Items (Comp_Unit));
19965 while Present (Clause) loop
19966 if Nkind (Clause) = N_With_Clause then
19967 if Library_Unit (Clause) = U then
19970 -- The with_clause may denote a renaming of the unit we are
19971 -- looking for, eg. Text_IO which renames Ada.Text_IO.
19974 Renamed_Entity (Entity (Name (Clause))) =
19975 Defining_Entity (Unit (U))
19985 end Unit_In_Context;
19987 -- Start of processing for Unit_Is_Visible
19990 -- The currrent unit is directly visible
19995 elsif Unit_In_Context (Curr) then
19998 -- If the current unit is a body, check the context of the spec
20000 elsif Nkind (Unit (Curr)) = N_Package_Body
20002 (Nkind (Unit (Curr)) = N_Subprogram_Body
20003 and then not Acts_As_Spec (Unit (Curr)))
20005 if Unit_In_Context (Library_Unit (Curr)) then
20010 -- If the spec is a child unit, examine the parents
20012 if Is_Child_Unit (Curr_Entity) then
20013 if Nkind (Unit (Curr)) in N_Unit_Body then
20015 Unit_In_Parent_Context
20016 (Parent_Spec (Unit (Library_Unit (Curr))));
20018 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
20024 end Unit_Is_Visible;
20026 ------------------------------
20027 -- Universal_Interpretation --
20028 ------------------------------
20030 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
20031 Index : Interp_Index;
20035 -- The argument may be a formal parameter of an operator or subprogram
20036 -- with multiple interpretations, or else an expression for an actual.
20038 if Nkind (Opnd) = N_Defining_Identifier
20039 or else not Is_Overloaded (Opnd)
20041 if Etype (Opnd) = Universal_Integer
20042 or else Etype (Opnd) = Universal_Real
20044 return Etype (Opnd);
20050 Get_First_Interp (Opnd, Index, It);
20051 while Present (It.Typ) loop
20052 if It.Typ = Universal_Integer
20053 or else It.Typ = Universal_Real
20058 Get_Next_Interp (Index, It);
20063 end Universal_Interpretation;
20069 function Unqualify (Expr : Node_Id) return Node_Id is
20071 -- Recurse to handle unlikely case of multiple levels of qualification
20073 if Nkind (Expr) = N_Qualified_Expression then
20074 return Unqualify (Expression (Expr));
20076 -- Normal case, not a qualified expression
20083 -----------------------
20084 -- Visible_Ancestors --
20085 -----------------------
20087 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
20093 pragma Assert (Is_Record_Type (Typ) and then Is_Tagged_Type (Typ));
20095 -- Collect all the parents and progenitors of Typ. If the full-view of
20096 -- private parents and progenitors is available then it is used to
20097 -- generate the list of visible ancestors; otherwise their partial
20098 -- view is added to the resulting list.
20103 Use_Full_View => True);
20107 Ifaces_List => List_2,
20108 Exclude_Parents => True,
20109 Use_Full_View => True);
20111 -- Join the two lists. Avoid duplications because an interface may
20112 -- simultaneously be parent and progenitor of a type.
20114 Elmt := First_Elmt (List_2);
20115 while Present (Elmt) loop
20116 Append_Unique_Elmt (Node (Elmt), List_1);
20121 end Visible_Ancestors;
20123 ----------------------
20124 -- Within_Init_Proc --
20125 ----------------------
20127 function Within_Init_Proc return Boolean is
20131 S := Current_Scope;
20132 while not Is_Overloadable (S) loop
20133 if S = Standard_Standard then
20140 return Is_Init_Proc (S);
20141 end Within_Init_Proc;
20147 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
20154 elsif SE = Standard_Standard then
20166 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
20167 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
20168 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
20170 Matching_Field : Entity_Id;
20171 -- Entity to give a more precise suggestion on how to write a one-
20172 -- element positional aggregate.
20174 function Has_One_Matching_Field return Boolean;
20175 -- Determines if Expec_Type is a record type with a single component or
20176 -- discriminant whose type matches the found type or is one dimensional
20177 -- array whose component type matches the found type. In the case of
20178 -- one discriminant, we ignore the variant parts. That's not accurate,
20179 -- but good enough for the warning.
20181 ----------------------------
20182 -- Has_One_Matching_Field --
20183 ----------------------------
20185 function Has_One_Matching_Field return Boolean is
20189 Matching_Field := Empty;
20191 if Is_Array_Type (Expec_Type)
20192 and then Number_Dimensions (Expec_Type) = 1
20193 and then Covers (Etype (Component_Type (Expec_Type)), Found_Type)
20195 -- Use type name if available. This excludes multidimensional
20196 -- arrays and anonymous arrays.
20198 if Comes_From_Source (Expec_Type) then
20199 Matching_Field := Expec_Type;
20201 -- For an assignment, use name of target
20203 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
20204 and then Is_Entity_Name (Name (Parent (Expr)))
20206 Matching_Field := Entity (Name (Parent (Expr)));
20211 elsif not Is_Record_Type (Expec_Type) then
20215 E := First_Entity (Expec_Type);
20220 elsif not Ekind_In (E, E_Discriminant, E_Component)
20221 or else Nam_In (Chars (E), Name_uTag, Name_uParent)
20230 if not Covers (Etype (E), Found_Type) then
20233 elsif Present (Next_Entity (E))
20234 and then (Ekind (E) = E_Component
20235 or else Ekind (Next_Entity (E)) = E_Discriminant)
20240 Matching_Field := E;
20244 end Has_One_Matching_Field;
20246 -- Start of processing for Wrong_Type
20249 -- Don't output message if either type is Any_Type, or if a message
20250 -- has already been posted for this node. We need to do the latter
20251 -- check explicitly (it is ordinarily done in Errout), because we
20252 -- are using ! to force the output of the error messages.
20254 if Expec_Type = Any_Type
20255 or else Found_Type = Any_Type
20256 or else Error_Posted (Expr)
20260 -- If one of the types is a Taft-Amendment type and the other it its
20261 -- completion, it must be an illegal use of a TAT in the spec, for
20262 -- which an error was already emitted. Avoid cascaded errors.
20264 elsif Is_Incomplete_Type (Expec_Type)
20265 and then Has_Completion_In_Body (Expec_Type)
20266 and then Full_View (Expec_Type) = Etype (Expr)
20270 elsif Is_Incomplete_Type (Etype (Expr))
20271 and then Has_Completion_In_Body (Etype (Expr))
20272 and then Full_View (Etype (Expr)) = Expec_Type
20276 -- In an instance, there is an ongoing problem with completion of
20277 -- type derived from private types. Their structure is what Gigi
20278 -- expects, but the Etype is the parent type rather than the
20279 -- derived private type itself. Do not flag error in this case. The
20280 -- private completion is an entity without a parent, like an Itype.
20281 -- Similarly, full and partial views may be incorrect in the instance.
20282 -- There is no simple way to insure that it is consistent ???
20284 -- A similar view discrepancy can happen in an inlined body, for the
20285 -- same reason: inserted body may be outside of the original package
20286 -- and only partial views are visible at the point of insertion.
20288 elsif In_Instance or else In_Inlined_Body then
20289 if Etype (Etype (Expr)) = Etype (Expected_Type)
20291 (Has_Private_Declaration (Expected_Type)
20292 or else Has_Private_Declaration (Etype (Expr)))
20293 and then No (Parent (Expected_Type))
20297 elsif Nkind (Parent (Expr)) = N_Qualified_Expression
20298 and then Entity (Subtype_Mark (Parent (Expr))) = Expected_Type
20302 elsif Is_Private_Type (Expected_Type)
20303 and then Present (Full_View (Expected_Type))
20304 and then Covers (Full_View (Expected_Type), Etype (Expr))
20308 -- Conversely, type of expression may be the private one
20310 elsif Is_Private_Type (Base_Type (Etype (Expr)))
20311 and then Full_View (Base_Type (Etype (Expr))) = Expected_Type
20317 -- An interesting special check. If the expression is parenthesized
20318 -- and its type corresponds to the type of the sole component of the
20319 -- expected record type, or to the component type of the expected one
20320 -- dimensional array type, then assume we have a bad aggregate attempt.
20322 if Nkind (Expr) in N_Subexpr
20323 and then Paren_Count (Expr) /= 0
20324 and then Has_One_Matching_Field
20326 Error_Msg_N ("positional aggregate cannot have one component", Expr);
20328 if Present (Matching_Field) then
20329 if Is_Array_Type (Expec_Type) then
20331 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
20334 ("\write instead `& ='> ...`", Expr, Matching_Field);
20338 -- Another special check, if we are looking for a pool-specific access
20339 -- type and we found an E_Access_Attribute_Type, then we have the case
20340 -- of an Access attribute being used in a context which needs a pool-
20341 -- specific type, which is never allowed. The one extra check we make
20342 -- is that the expected designated type covers the Found_Type.
20344 elsif Is_Access_Type (Expec_Type)
20345 and then Ekind (Found_Type) = E_Access_Attribute_Type
20346 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
20347 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
20349 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
20351 Error_Msg_N -- CODEFIX
20352 ("result must be general access type!", Expr);
20353 Error_Msg_NE -- CODEFIX
20354 ("add ALL to }!", Expr, Expec_Type);
20356 -- Another special check, if the expected type is an integer type,
20357 -- but the expression is of type System.Address, and the parent is
20358 -- an addition or subtraction operation whose left operand is the
20359 -- expression in question and whose right operand is of an integral
20360 -- type, then this is an attempt at address arithmetic, so give
20361 -- appropriate message.
20363 elsif Is_Integer_Type (Expec_Type)
20364 and then Is_RTE (Found_Type, RE_Address)
20365 and then Nkind_In (Parent (Expr), N_Op_Add, N_Op_Subtract)
20366 and then Expr = Left_Opnd (Parent (Expr))
20367 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
20370 ("address arithmetic not predefined in package System",
20373 ("\possible missing with/use of System.Storage_Elements",
20377 -- If the expected type is an anonymous access type, as for access
20378 -- parameters and discriminants, the error is on the designated types.
20380 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
20381 if Comes_From_Source (Expec_Type) then
20382 Error_Msg_NE ("expected}!", Expr, Expec_Type);
20385 ("expected an access type with designated}",
20386 Expr, Designated_Type (Expec_Type));
20389 if Is_Access_Type (Found_Type)
20390 and then not Comes_From_Source (Found_Type)
20393 ("\\found an access type with designated}!",
20394 Expr, Designated_Type (Found_Type));
20396 if From_Limited_With (Found_Type) then
20397 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
20398 Error_Msg_Qual_Level := 99;
20399 Error_Msg_NE -- CODEFIX
20400 ("\\missing `WITH &;", Expr, Scope (Found_Type));
20401 Error_Msg_Qual_Level := 0;
20403 Error_Msg_NE ("found}!", Expr, Found_Type);
20407 -- Normal case of one type found, some other type expected
20410 -- If the names of the two types are the same, see if some number
20411 -- of levels of qualification will help. Don't try more than three
20412 -- levels, and if we get to standard, it's no use (and probably
20413 -- represents an error in the compiler) Also do not bother with
20414 -- internal scope names.
20417 Expec_Scope : Entity_Id;
20418 Found_Scope : Entity_Id;
20421 Expec_Scope := Expec_Type;
20422 Found_Scope := Found_Type;
20424 for Levels in Nat range 0 .. 3 loop
20425 if Chars (Expec_Scope) /= Chars (Found_Scope) then
20426 Error_Msg_Qual_Level := Levels;
20430 Expec_Scope := Scope (Expec_Scope);
20431 Found_Scope := Scope (Found_Scope);
20433 exit when Expec_Scope = Standard_Standard
20434 or else Found_Scope = Standard_Standard
20435 or else not Comes_From_Source (Expec_Scope)
20436 or else not Comes_From_Source (Found_Scope);
20440 if Is_Record_Type (Expec_Type)
20441 and then Present (Corresponding_Remote_Type (Expec_Type))
20443 Error_Msg_NE ("expected}!", Expr,
20444 Corresponding_Remote_Type (Expec_Type));
20446 Error_Msg_NE ("expected}!", Expr, Expec_Type);
20449 if Is_Entity_Name (Expr)
20450 and then Is_Package_Or_Generic_Package (Entity (Expr))
20452 Error_Msg_N ("\\found package name!", Expr);
20454 elsif Is_Entity_Name (Expr)
20455 and then Ekind_In (Entity (Expr), E_Procedure, E_Generic_Procedure)
20457 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
20459 ("found procedure name, possibly missing Access attribute!",
20463 ("\\found procedure name instead of function!", Expr);
20466 elsif Nkind (Expr) = N_Function_Call
20467 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
20468 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
20469 and then No (Parameter_Associations (Expr))
20472 ("found function name, possibly missing Access attribute!",
20475 -- Catch common error: a prefix or infix operator which is not
20476 -- directly visible because the type isn't.
20478 elsif Nkind (Expr) in N_Op
20479 and then Is_Overloaded (Expr)
20480 and then not Is_Immediately_Visible (Expec_Type)
20481 and then not Is_Potentially_Use_Visible (Expec_Type)
20482 and then not In_Use (Expec_Type)
20483 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
20486 ("operator of the type is not directly visible!", Expr);
20488 elsif Ekind (Found_Type) = E_Void
20489 and then Present (Parent (Found_Type))
20490 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
20492 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
20495 Error_Msg_NE ("\\found}!", Expr, Found_Type);
20498 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
20499 -- of the same modular type, and (M1 and M2) = 0 was intended.
20501 if Expec_Type = Standard_Boolean
20502 and then Is_Modular_Integer_Type (Found_Type)
20503 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
20504 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
20507 Op : constant Node_Id := Right_Opnd (Parent (Expr));
20508 L : constant Node_Id := Left_Opnd (Op);
20509 R : constant Node_Id := Right_Opnd (Op);
20512 -- The case for the message is when the left operand of the
20513 -- comparison is the same modular type, or when it is an
20514 -- integer literal (or other universal integer expression),
20515 -- which would have been typed as the modular type if the
20516 -- parens had been there.
20518 if (Etype (L) = Found_Type
20520 Etype (L) = Universal_Integer)
20521 and then Is_Integer_Type (Etype (R))
20524 ("\\possible missing parens for modular operation", Expr);
20529 -- Reset error message qualification indication
20531 Error_Msg_Qual_Level := 0;
20535 --------------------------------
20536 -- Yields_Synchronized_Object --
20537 --------------------------------
20539 function Yields_Synchronized_Object (Typ : Entity_Id) return Boolean is
20540 Has_Sync_Comp : Boolean := False;
20544 -- An array type yields a synchronized object if its component type
20545 -- yields a synchronized object.
20547 if Is_Array_Type (Typ) then
20548 return Yields_Synchronized_Object (Component_Type (Typ));
20550 -- A descendant of type Ada.Synchronous_Task_Control.Suspension_Object
20551 -- yields a synchronized object by default.
20553 elsif Is_Descendant_Of_Suspension_Object (Typ) then
20556 -- A protected type yields a synchronized object by default
20558 elsif Is_Protected_Type (Typ) then
20561 -- A record type or type extension yields a synchronized object when its
20562 -- discriminants (if any) lack default values and all components are of
20563 -- a type that yelds a synchronized object.
20565 elsif Is_Record_Type (Typ) then
20567 -- Inspect all entities defined in the scope of the type, looking for
20568 -- components of a type that does not yeld a synchronized object or
20569 -- for discriminants with default values.
20571 Id := First_Entity (Typ);
20572 while Present (Id) loop
20573 if Comes_From_Source (Id) then
20574 if Ekind (Id) = E_Component then
20575 if Yields_Synchronized_Object (Etype (Id)) then
20576 Has_Sync_Comp := True;
20578 -- The component does not yield a synchronized object
20584 elsif Ekind (Id) = E_Discriminant
20585 and then Present (Expression (Parent (Id)))
20594 -- Ensure that the parent type of a type extension yields a
20595 -- synchronized object.
20597 if Etype (Typ) /= Typ
20598 and then not Yields_Synchronized_Object (Etype (Typ))
20603 -- If we get here, then all discriminants lack default values and all
20604 -- components are of a type that yields a synchronized object.
20606 return Has_Sync_Comp;
20608 -- A synchronized interface type yields a synchronized object by default
20610 elsif Is_Synchronized_Interface (Typ) then
20613 -- A task type yelds a synchronized object by default
20615 elsif Is_Task_Type (Typ) then
20618 -- Otherwise the type does not yield a synchronized object
20623 end Yields_Synchronized_Object;