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));
602 -- In GNATprove mode, do not replace the node with an exception raised.
603 -- In such a case, either the call to Compile_Time_Constraint_Error
604 -- issues an error which stops analysis, or it issues a warning in
605 -- a few cases where a suitable check flag is set for GNATprove to
606 -- generate a check message.
608 if not Rep or GNATprove_Mode then
612 -- Now we replace the node by an N_Raise_Constraint_Error node
613 -- This does not need reanalyzing, so set it as analyzed now.
616 Set_Analyzed (N, True);
619 Set_Raises_Constraint_Error (N);
621 -- Now deal with possible local raise handling
623 Possible_Local_Raise (N, Standard_Constraint_Error);
625 -- If the original expression was marked as static, the result is
626 -- still marked as static, but the Raises_Constraint_Error flag is
627 -- always set so that further static evaluation is not attempted.
630 Set_Is_Static_Expression (N);
632 end Apply_Compile_Time_Constraint_Error;
634 ---------------------------
635 -- Async_Readers_Enabled --
636 ---------------------------
638 function Async_Readers_Enabled (Id : Entity_Id) return Boolean is
640 return Has_Enabled_Property (Id, Name_Async_Readers);
641 end Async_Readers_Enabled;
643 ---------------------------
644 -- Async_Writers_Enabled --
645 ---------------------------
647 function Async_Writers_Enabled (Id : Entity_Id) return Boolean is
649 return Has_Enabled_Property (Id, Name_Async_Writers);
650 end Async_Writers_Enabled;
652 --------------------------------------
653 -- Available_Full_View_Of_Component --
654 --------------------------------------
656 function Available_Full_View_Of_Component (T : Entity_Id) return Boolean is
657 ST : constant Entity_Id := Scope (T);
658 SCT : constant Entity_Id := Scope (Component_Type (T));
660 return In_Open_Scopes (ST)
661 and then In_Open_Scopes (SCT)
662 and then Scope_Depth (ST) >= Scope_Depth (SCT);
663 end Available_Full_View_Of_Component;
669 procedure Bad_Attribute
672 Warn : Boolean := False)
675 Error_Msg_Warn := Warn;
676 Error_Msg_N ("unrecognized attribute&<<", N);
678 -- Check for possible misspelling
680 Error_Msg_Name_1 := First_Attribute_Name;
681 while Error_Msg_Name_1 <= Last_Attribute_Name loop
682 if Is_Bad_Spelling_Of (Nam, Error_Msg_Name_1) then
683 Error_Msg_N -- CODEFIX
684 ("\possible misspelling of %<<", N);
688 Error_Msg_Name_1 := Error_Msg_Name_1 + 1;
692 --------------------------------
693 -- Bad_Predicated_Subtype_Use --
694 --------------------------------
696 procedure Bad_Predicated_Subtype_Use
700 Suggest_Static : Boolean := False)
705 -- Avoid cascaded errors
707 if Error_Posted (N) then
711 if Inside_A_Generic then
712 Gen := Current_Scope;
713 while Present (Gen) and then Ekind (Gen) /= E_Generic_Package loop
721 if Is_Generic_Formal (Typ) and then Is_Discrete_Type (Typ) then
722 Set_No_Predicate_On_Actual (Typ);
725 elsif Has_Predicates (Typ) then
726 if Is_Generic_Actual_Type (Typ) then
728 -- The restriction on loop parameters is only that the type
729 -- should have no dynamic predicates.
731 if Nkind (Parent (N)) = N_Loop_Parameter_Specification
732 and then not Has_Dynamic_Predicate_Aspect (Typ)
733 and then Is_OK_Static_Subtype (Typ)
738 Gen := Current_Scope;
739 while not Is_Generic_Instance (Gen) loop
743 pragma Assert (Present (Gen));
745 if Ekind (Gen) = E_Package and then In_Package_Body (Gen) then
746 Error_Msg_Warn := SPARK_Mode /= On;
747 Error_Msg_FE (Msg & "<<", N, Typ);
748 Error_Msg_F ("\Program_Error [<<", N);
751 Make_Raise_Program_Error (Sloc (N),
752 Reason => PE_Bad_Predicated_Generic_Type));
755 Error_Msg_FE (Msg & "<<", N, Typ);
759 Error_Msg_FE (Msg, N, Typ);
762 -- Emit an optional suggestion on how to remedy the error if the
763 -- context warrants it.
765 if Suggest_Static and then Has_Static_Predicate (Typ) then
766 Error_Msg_FE ("\predicate of & should be marked static", N, Typ);
769 end Bad_Predicated_Subtype_Use;
771 -----------------------------------------
772 -- Bad_Unordered_Enumeration_Reference --
773 -----------------------------------------
775 function Bad_Unordered_Enumeration_Reference
777 T : Entity_Id) return Boolean
780 return Is_Enumeration_Type (T)
781 and then Warn_On_Unordered_Enumeration_Type
782 and then not Is_Generic_Type (T)
783 and then Comes_From_Source (N)
784 and then not Has_Pragma_Ordered (T)
785 and then not In_Same_Extended_Unit (N, T);
786 end Bad_Unordered_Enumeration_Reference;
788 --------------------------
789 -- Build_Actual_Subtype --
790 --------------------------
792 function Build_Actual_Subtype
794 N : Node_Or_Entity_Id) return Node_Id
797 -- Normally Sloc (N), but may point to corresponding body in some cases
799 Constraints : List_Id;
805 Disc_Type : Entity_Id;
811 if Nkind (N) = N_Defining_Identifier then
812 Obj := New_Occurrence_Of (N, Loc);
814 -- If this is a formal parameter of a subprogram declaration, and
815 -- we are compiling the body, we want the declaration for the
816 -- actual subtype to carry the source position of the body, to
817 -- prevent anomalies in gdb when stepping through the code.
819 if Is_Formal (N) then
821 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
823 if Nkind (Decl) = N_Subprogram_Declaration
824 and then Present (Corresponding_Body (Decl))
826 Loc := Sloc (Corresponding_Body (Decl));
835 if Is_Array_Type (T) then
836 Constraints := New_List;
837 for J in 1 .. Number_Dimensions (T) loop
839 -- Build an array subtype declaration with the nominal subtype and
840 -- the bounds of the actual. Add the declaration in front of the
841 -- local declarations for the subprogram, for analysis before any
842 -- reference to the formal in the body.
845 Make_Attribute_Reference (Loc,
847 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
848 Attribute_Name => Name_First,
849 Expressions => New_List (
850 Make_Integer_Literal (Loc, J)));
853 Make_Attribute_Reference (Loc,
855 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
856 Attribute_Name => Name_Last,
857 Expressions => New_List (
858 Make_Integer_Literal (Loc, J)));
860 Append (Make_Range (Loc, Lo, Hi), Constraints);
863 -- If the type has unknown discriminants there is no constrained
864 -- subtype to build. This is never called for a formal or for a
865 -- lhs, so returning the type is ok ???
867 elsif Has_Unknown_Discriminants (T) then
871 Constraints := New_List;
873 -- Type T is a generic derived type, inherit the discriminants from
876 if Is_Private_Type (T)
877 and then No (Full_View (T))
879 -- T was flagged as an error if it was declared as a formal
880 -- derived type with known discriminants. In this case there
881 -- is no need to look at the parent type since T already carries
882 -- its own discriminants.
884 and then not Error_Posted (T)
886 Disc_Type := Etype (Base_Type (T));
891 Discr := First_Discriminant (Disc_Type);
892 while Present (Discr) loop
893 Append_To (Constraints,
894 Make_Selected_Component (Loc,
896 Duplicate_Subexpr_No_Checks (Obj),
897 Selector_Name => New_Occurrence_Of (Discr, Loc)));
898 Next_Discriminant (Discr);
902 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
903 Set_Is_Internal (Subt);
906 Make_Subtype_Declaration (Loc,
907 Defining_Identifier => Subt,
908 Subtype_Indication =>
909 Make_Subtype_Indication (Loc,
910 Subtype_Mark => New_Occurrence_Of (T, Loc),
912 Make_Index_Or_Discriminant_Constraint (Loc,
913 Constraints => Constraints)));
915 Mark_Rewrite_Insertion (Decl);
917 end Build_Actual_Subtype;
919 ---------------------------------------
920 -- Build_Actual_Subtype_Of_Component --
921 ---------------------------------------
923 function Build_Actual_Subtype_Of_Component
925 N : Node_Id) return Node_Id
927 Loc : constant Source_Ptr := Sloc (N);
928 P : constant Node_Id := Prefix (N);
931 Index_Typ : Entity_Id;
933 Desig_Typ : Entity_Id;
934 -- This is either a copy of T, or if T is an access type, then it is
935 -- the directly designated type of this access type.
937 function Build_Actual_Array_Constraint return List_Id;
938 -- If one or more of the bounds of the component depends on
939 -- discriminants, build actual constraint using the discriminants
942 function Build_Actual_Record_Constraint return List_Id;
943 -- Similar to previous one, for discriminated components constrained
944 -- by the discriminant of the enclosing object.
946 -----------------------------------
947 -- Build_Actual_Array_Constraint --
948 -----------------------------------
950 function Build_Actual_Array_Constraint return List_Id is
951 Constraints : constant List_Id := New_List;
959 Indx := First_Index (Desig_Typ);
960 while Present (Indx) loop
961 Old_Lo := Type_Low_Bound (Etype (Indx));
962 Old_Hi := Type_High_Bound (Etype (Indx));
964 if Denotes_Discriminant (Old_Lo) then
966 Make_Selected_Component (Loc,
967 Prefix => New_Copy_Tree (P),
968 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
971 Lo := New_Copy_Tree (Old_Lo);
973 -- The new bound will be reanalyzed in the enclosing
974 -- declaration. For literal bounds that come from a type
975 -- declaration, the type of the context must be imposed, so
976 -- insure that analysis will take place. For non-universal
977 -- types this is not strictly necessary.
979 Set_Analyzed (Lo, False);
982 if Denotes_Discriminant (Old_Hi) then
984 Make_Selected_Component (Loc,
985 Prefix => New_Copy_Tree (P),
986 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
989 Hi := New_Copy_Tree (Old_Hi);
990 Set_Analyzed (Hi, False);
993 Append (Make_Range (Loc, Lo, Hi), Constraints);
998 end Build_Actual_Array_Constraint;
1000 ------------------------------------
1001 -- Build_Actual_Record_Constraint --
1002 ------------------------------------
1004 function Build_Actual_Record_Constraint return List_Id is
1005 Constraints : constant List_Id := New_List;
1010 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1011 while Present (D) loop
1012 if Denotes_Discriminant (Node (D)) then
1013 D_Val := Make_Selected_Component (Loc,
1014 Prefix => New_Copy_Tree (P),
1015 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
1018 D_Val := New_Copy_Tree (Node (D));
1021 Append (D_Val, Constraints);
1026 end Build_Actual_Record_Constraint;
1028 -- Start of processing for Build_Actual_Subtype_Of_Component
1031 -- Why the test for Spec_Expression mode here???
1033 if In_Spec_Expression then
1036 -- More comments for the rest of this body would be good ???
1038 elsif Nkind (N) = N_Explicit_Dereference then
1039 if Is_Composite_Type (T)
1040 and then not Is_Constrained (T)
1041 and then not (Is_Class_Wide_Type (T)
1042 and then Is_Constrained (Root_Type (T)))
1043 and then not Has_Unknown_Discriminants (T)
1045 -- If the type of the dereference is already constrained, it is an
1048 if Is_Array_Type (Etype (N))
1049 and then Is_Constrained (Etype (N))
1053 Remove_Side_Effects (P);
1054 return Build_Actual_Subtype (T, N);
1061 if Ekind (T) = E_Access_Subtype then
1062 Desig_Typ := Designated_Type (T);
1067 if Ekind (Desig_Typ) = E_Array_Subtype then
1068 Id := First_Index (Desig_Typ);
1069 while Present (Id) loop
1070 Index_Typ := Underlying_Type (Etype (Id));
1072 if Denotes_Discriminant (Type_Low_Bound (Index_Typ))
1074 Denotes_Discriminant (Type_High_Bound (Index_Typ))
1076 Remove_Side_Effects (P);
1078 Build_Component_Subtype
1079 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
1085 elsif Is_Composite_Type (Desig_Typ)
1086 and then Has_Discriminants (Desig_Typ)
1087 and then not Has_Unknown_Discriminants (Desig_Typ)
1089 if Is_Private_Type (Desig_Typ)
1090 and then No (Discriminant_Constraint (Desig_Typ))
1092 Desig_Typ := Full_View (Desig_Typ);
1095 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1096 while Present (D) loop
1097 if Denotes_Discriminant (Node (D)) then
1098 Remove_Side_Effects (P);
1100 Build_Component_Subtype (
1101 Build_Actual_Record_Constraint, Loc, Base_Type (T));
1108 -- If none of the above, the actual and nominal subtypes are the same
1111 end Build_Actual_Subtype_Of_Component;
1113 -----------------------------
1114 -- Build_Component_Subtype --
1115 -----------------------------
1117 function Build_Component_Subtype
1120 T : Entity_Id) return Node_Id
1126 -- Unchecked_Union components do not require component subtypes
1128 if Is_Unchecked_Union (T) then
1132 Subt := Make_Temporary (Loc, 'S');
1133 Set_Is_Internal (Subt);
1136 Make_Subtype_Declaration (Loc,
1137 Defining_Identifier => Subt,
1138 Subtype_Indication =>
1139 Make_Subtype_Indication (Loc,
1140 Subtype_Mark => New_Occurrence_Of (Base_Type (T), Loc),
1142 Make_Index_Or_Discriminant_Constraint (Loc,
1143 Constraints => C)));
1145 Mark_Rewrite_Insertion (Decl);
1147 end Build_Component_Subtype;
1149 ----------------------------------
1150 -- Build_Default_Init_Cond_Call --
1151 ----------------------------------
1153 function Build_Default_Init_Cond_Call
1156 Typ : Entity_Id) return Node_Id
1158 Proc_Id : constant Entity_Id := Default_Init_Cond_Procedure (Typ);
1159 Formal_Typ : constant Entity_Id := Etype (First_Formal (Proc_Id));
1163 Make_Procedure_Call_Statement (Loc,
1164 Name => New_Occurrence_Of (Proc_Id, Loc),
1165 Parameter_Associations => New_List (
1166 Make_Unchecked_Type_Conversion (Loc,
1167 Subtype_Mark => New_Occurrence_Of (Formal_Typ, Loc),
1168 Expression => New_Occurrence_Of (Obj_Id, Loc))));
1169 end Build_Default_Init_Cond_Call;
1171 ----------------------------------------------
1172 -- Build_Default_Init_Cond_Procedure_Bodies --
1173 ----------------------------------------------
1175 procedure Build_Default_Init_Cond_Procedure_Bodies (Priv_Decls : List_Id) is
1176 procedure Build_Default_Init_Cond_Procedure_Body (Typ : Entity_Id);
1177 -- If type Typ is subject to pragma Default_Initial_Condition, build the
1178 -- body of the procedure which verifies the assumption of the pragma at
1179 -- run time. The generated body is added after the type declaration.
1181 --------------------------------------------
1182 -- Build_Default_Init_Cond_Procedure_Body --
1183 --------------------------------------------
1185 procedure Build_Default_Init_Cond_Procedure_Body (Typ : Entity_Id) is
1186 Param_Id : Entity_Id;
1187 -- The entity of the sole formal parameter of the default initial
1188 -- condition procedure.
1190 procedure Replace_Type_Reference (N : Node_Id);
1191 -- Replace a single reference to type Typ with a reference to formal
1192 -- parameter Param_Id.
1194 ----------------------------
1195 -- Replace_Type_Reference --
1196 ----------------------------
1198 procedure Replace_Type_Reference (N : Node_Id) is
1200 Rewrite (N, New_Occurrence_Of (Param_Id, Sloc (N)));
1201 end Replace_Type_Reference;
1203 procedure Replace_Type_References is
1204 new Replace_Type_References_Generic (Replace_Type_Reference);
1208 Loc : constant Source_Ptr := Sloc (Typ);
1209 Prag : constant Node_Id :=
1210 Get_Pragma (Typ, Pragma_Default_Initial_Condition);
1211 Proc_Id : constant Entity_Id := Default_Init_Cond_Procedure (Typ);
1212 Spec_Decl : constant Node_Id := Unit_Declaration_Node (Proc_Id);
1213 Body_Decl : Node_Id;
1217 Save_Ghost_Mode : constant Ghost_Mode_Type := Ghost_Mode;
1219 -- Start of processing for Build_Default_Init_Cond_Procedure_Body
1222 -- The procedure should be generated only for [sub]types subject to
1223 -- pragma Default_Initial_Condition. Types that inherit the pragma do
1224 -- not get this specialized procedure.
1226 pragma Assert (Has_Default_Init_Cond (Typ));
1227 pragma Assert (Present (Prag));
1228 pragma Assert (Present (Proc_Id));
1230 -- Nothing to do if the body was already built
1232 if Present (Corresponding_Body (Spec_Decl)) then
1236 -- The related type may be subject to pragma Ghost. Set the mode now
1237 -- to ensure that the analysis and expansion produce Ghost nodes.
1239 Set_Ghost_Mode_From_Entity (Typ);
1241 Param_Id := First_Formal (Proc_Id);
1243 -- The pragma has an argument. Note that the argument is analyzed
1244 -- after all references to the current instance of the type are
1247 if Present (Pragma_Argument_Associations (Prag)) then
1249 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
1251 if Nkind (Expr) = N_Null then
1252 Stmt := Make_Null_Statement (Loc);
1254 -- Preserve the original argument of the pragma by replicating it.
1255 -- Replace all references to the current instance of the type with
1256 -- references to the formal parameter.
1259 Expr := New_Copy_Tree (Expr);
1260 Replace_Type_References (Expr, Typ);
1263 -- pragma Check (Default_Initial_Condition, <Expr>);
1267 Pragma_Identifier =>
1268 Make_Identifier (Loc, Name_Check),
1270 Pragma_Argument_Associations => New_List (
1271 Make_Pragma_Argument_Association (Loc,
1273 Make_Identifier (Loc,
1274 Chars => Name_Default_Initial_Condition)),
1275 Make_Pragma_Argument_Association (Loc,
1276 Expression => Expr)));
1279 -- Otherwise the pragma appears without an argument
1282 Stmt := Make_Null_Statement (Loc);
1286 -- procedure <Typ>Default_Init_Cond (I : <Typ>) is
1289 -- end <Typ>Default_Init_Cond;
1292 Make_Subprogram_Body (Loc,
1294 Copy_Separate_Tree (Specification (Spec_Decl)),
1295 Declarations => Empty_List,
1296 Handled_Statement_Sequence =>
1297 Make_Handled_Sequence_Of_Statements (Loc,
1298 Statements => New_List (Stmt)));
1300 -- Link the spec and body of the default initial condition procedure
1301 -- to prevent the generation of a duplicate body.
1303 Set_Corresponding_Body (Spec_Decl, Defining_Entity (Body_Decl));
1304 Set_Corresponding_Spec (Body_Decl, Proc_Id);
1306 Insert_After_And_Analyze (Declaration_Node (Typ), Body_Decl);
1307 Ghost_Mode := Save_Ghost_Mode;
1308 end Build_Default_Init_Cond_Procedure_Body;
1315 -- Start of processing for Build_Default_Init_Cond_Procedure_Bodies
1318 -- Inspect the private declarations looking for [sub]type declarations
1320 Decl := First (Priv_Decls);
1321 while Present (Decl) loop
1322 if Nkind_In (Decl, N_Full_Type_Declaration,
1323 N_Subtype_Declaration)
1325 Typ := Defining_Entity (Decl);
1327 -- Guard against partially decorate types due to previous errors
1329 if Is_Type (Typ) then
1331 -- If the type is subject to pragma Default_Initial_Condition,
1332 -- generate the body of the internal procedure which verifies
1333 -- the assertion of the pragma at run time.
1335 if Has_Default_Init_Cond (Typ) then
1336 Build_Default_Init_Cond_Procedure_Body (Typ);
1338 -- A derived type inherits the default initial condition
1339 -- procedure from its parent type.
1341 elsif Has_Inherited_Default_Init_Cond (Typ) then
1342 Inherit_Default_Init_Cond_Procedure (Typ);
1349 end Build_Default_Init_Cond_Procedure_Bodies;
1351 ---------------------------------------------------
1352 -- Build_Default_Init_Cond_Procedure_Declaration --
1353 ---------------------------------------------------
1355 procedure Build_Default_Init_Cond_Procedure_Declaration (Typ : Entity_Id) is
1356 Loc : constant Source_Ptr := Sloc (Typ);
1357 Prag : constant Node_Id :=
1358 Get_Pragma (Typ, Pragma_Default_Initial_Condition);
1360 Save_Ghost_Mode : constant Ghost_Mode_Type := Ghost_Mode;
1362 Proc_Id : Entity_Id;
1365 -- The procedure should be generated only for types subject to pragma
1366 -- Default_Initial_Condition. Types that inherit the pragma do not get
1367 -- this specialized procedure.
1369 pragma Assert (Has_Default_Init_Cond (Typ));
1370 pragma Assert (Present (Prag));
1372 -- Nothing to do if default initial condition procedure already built
1374 if Present (Default_Init_Cond_Procedure (Typ)) then
1378 -- The related type may be subject to pragma Ghost. Set the mode now to
1379 -- ensure that the analysis and expansion produce Ghost nodes.
1381 Set_Ghost_Mode_From_Entity (Typ);
1384 Make_Defining_Identifier (Loc,
1385 Chars => New_External_Name (Chars (Typ), "Default_Init_Cond"));
1387 -- Associate default initial condition procedure with the private type
1389 Set_Ekind (Proc_Id, E_Procedure);
1390 Set_Is_Default_Init_Cond_Procedure (Proc_Id);
1391 Set_Default_Init_Cond_Procedure (Typ, Proc_Id);
1393 -- Mark the default initial condition procedure explicitly as Ghost
1394 -- because it does not come from source.
1396 if Ghost_Mode > None then
1397 Set_Is_Ghost_Entity (Proc_Id);
1401 -- procedure <Typ>Default_Init_Cond (Inn : <Typ>);
1403 Insert_After_And_Analyze (Prag,
1404 Make_Subprogram_Declaration (Loc,
1406 Make_Procedure_Specification (Loc,
1407 Defining_Unit_Name => Proc_Id,
1408 Parameter_Specifications => New_List (
1409 Make_Parameter_Specification (Loc,
1410 Defining_Identifier => Make_Temporary (Loc, 'I'),
1411 Parameter_Type => New_Occurrence_Of (Typ, Loc))))));
1413 Ghost_Mode := Save_Ghost_Mode;
1414 end Build_Default_Init_Cond_Procedure_Declaration;
1416 ---------------------------
1417 -- Build_Default_Subtype --
1418 ---------------------------
1420 function Build_Default_Subtype
1422 N : Node_Id) return Entity_Id
1424 Loc : constant Source_Ptr := Sloc (N);
1428 -- The base type that is to be constrained by the defaults
1431 if not Has_Discriminants (T) or else Is_Constrained (T) then
1435 Bas := Base_Type (T);
1437 -- If T is non-private but its base type is private, this is the
1438 -- completion of a subtype declaration whose parent type is private
1439 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1440 -- are to be found in the full view of the base. Check that the private
1441 -- status of T and its base differ.
1443 if Is_Private_Type (Bas)
1444 and then not Is_Private_Type (T)
1445 and then Present (Full_View (Bas))
1447 Bas := Full_View (Bas);
1450 Disc := First_Discriminant (T);
1452 if No (Discriminant_Default_Value (Disc)) then
1457 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
1458 Constraints : constant List_Id := New_List;
1462 while Present (Disc) loop
1463 Append_To (Constraints,
1464 New_Copy_Tree (Discriminant_Default_Value (Disc)));
1465 Next_Discriminant (Disc);
1469 Make_Subtype_Declaration (Loc,
1470 Defining_Identifier => Act,
1471 Subtype_Indication =>
1472 Make_Subtype_Indication (Loc,
1473 Subtype_Mark => New_Occurrence_Of (Bas, Loc),
1475 Make_Index_Or_Discriminant_Constraint (Loc,
1476 Constraints => Constraints)));
1478 Insert_Action (N, Decl);
1480 -- If the context is a component declaration the subtype declaration
1481 -- will be analyzed when the enclosing type is frozen, otherwise do
1484 if Ekind (Current_Scope) /= E_Record_Type then
1490 end Build_Default_Subtype;
1492 --------------------------------------------
1493 -- Build_Discriminal_Subtype_Of_Component --
1494 --------------------------------------------
1496 function Build_Discriminal_Subtype_Of_Component
1497 (T : Entity_Id) return Node_Id
1499 Loc : constant Source_Ptr := Sloc (T);
1503 function Build_Discriminal_Array_Constraint return List_Id;
1504 -- If one or more of the bounds of the component depends on
1505 -- discriminants, build actual constraint using the discriminants
1508 function Build_Discriminal_Record_Constraint return List_Id;
1509 -- Similar to previous one, for discriminated components constrained by
1510 -- the discriminant of the enclosing object.
1512 ----------------------------------------
1513 -- Build_Discriminal_Array_Constraint --
1514 ----------------------------------------
1516 function Build_Discriminal_Array_Constraint return List_Id is
1517 Constraints : constant List_Id := New_List;
1525 Indx := First_Index (T);
1526 while Present (Indx) loop
1527 Old_Lo := Type_Low_Bound (Etype (Indx));
1528 Old_Hi := Type_High_Bound (Etype (Indx));
1530 if Denotes_Discriminant (Old_Lo) then
1531 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
1534 Lo := New_Copy_Tree (Old_Lo);
1537 if Denotes_Discriminant (Old_Hi) then
1538 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
1541 Hi := New_Copy_Tree (Old_Hi);
1544 Append (Make_Range (Loc, Lo, Hi), Constraints);
1549 end Build_Discriminal_Array_Constraint;
1551 -----------------------------------------
1552 -- Build_Discriminal_Record_Constraint --
1553 -----------------------------------------
1555 function Build_Discriminal_Record_Constraint return List_Id is
1556 Constraints : constant List_Id := New_List;
1561 D := First_Elmt (Discriminant_Constraint (T));
1562 while Present (D) loop
1563 if Denotes_Discriminant (Node (D)) then
1565 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
1567 D_Val := New_Copy_Tree (Node (D));
1570 Append (D_Val, Constraints);
1575 end Build_Discriminal_Record_Constraint;
1577 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1580 if Ekind (T) = E_Array_Subtype then
1581 Id := First_Index (T);
1582 while Present (Id) loop
1583 if Denotes_Discriminant (Type_Low_Bound (Etype (Id)))
1585 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
1587 return Build_Component_Subtype
1588 (Build_Discriminal_Array_Constraint, Loc, T);
1594 elsif Ekind (T) = E_Record_Subtype
1595 and then Has_Discriminants (T)
1596 and then not Has_Unknown_Discriminants (T)
1598 D := First_Elmt (Discriminant_Constraint (T));
1599 while Present (D) loop
1600 if Denotes_Discriminant (Node (D)) then
1601 return Build_Component_Subtype
1602 (Build_Discriminal_Record_Constraint, Loc, T);
1609 -- If none of the above, the actual and nominal subtypes are the same
1612 end Build_Discriminal_Subtype_Of_Component;
1614 ------------------------------
1615 -- Build_Elaboration_Entity --
1616 ------------------------------
1618 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
1619 Loc : constant Source_Ptr := Sloc (N);
1621 Elab_Ent : Entity_Id;
1623 procedure Set_Package_Name (Ent : Entity_Id);
1624 -- Given an entity, sets the fully qualified name of the entity in
1625 -- Name_Buffer, with components separated by double underscores. This
1626 -- is a recursive routine that climbs the scope chain to Standard.
1628 ----------------------
1629 -- Set_Package_Name --
1630 ----------------------
1632 procedure Set_Package_Name (Ent : Entity_Id) is
1634 if Scope (Ent) /= Standard_Standard then
1635 Set_Package_Name (Scope (Ent));
1638 Nam : constant String := Get_Name_String (Chars (Ent));
1640 Name_Buffer (Name_Len + 1) := '_';
1641 Name_Buffer (Name_Len + 2) := '_';
1642 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
1643 Name_Len := Name_Len + Nam'Length + 2;
1647 Get_Name_String (Chars (Ent));
1649 end Set_Package_Name;
1651 -- Start of processing for Build_Elaboration_Entity
1654 -- Ignore call if already constructed
1656 if Present (Elaboration_Entity (Spec_Id)) then
1659 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1660 -- no role in analysis.
1662 elsif ASIS_Mode then
1665 -- See if we need elaboration entity.
1667 -- We always need an elaboration entity when preserving control flow, as
1668 -- we want to remain explicit about the unit's elaboration order.
1670 elsif Opt.Suppress_Control_Flow_Optimizations then
1673 -- We always need an elaboration entity for the dynamic elaboration
1674 -- model, since it is needed to properly generate the PE exception for
1675 -- access before elaboration.
1677 elsif Dynamic_Elaboration_Checks then
1680 -- For the static model, we don't need the elaboration counter if this
1681 -- unit is sure to have no elaboration code, since that means there
1682 -- is no elaboration unit to be called. Note that we can't just decide
1683 -- after the fact by looking to see whether there was elaboration code,
1684 -- because that's too late to make this decision.
1686 elsif Restriction_Active (No_Elaboration_Code) then
1689 -- Similarly, for the static model, we can skip the elaboration counter
1690 -- if we have the No_Multiple_Elaboration restriction, since for the
1691 -- static model, that's the only purpose of the counter (to avoid
1692 -- multiple elaboration).
1694 elsif Restriction_Active (No_Multiple_Elaboration) then
1698 -- Here we need the elaboration entity
1700 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1701 -- name with dots replaced by double underscore. We have to manually
1702 -- construct this name, since it will be elaborated in the outer scope,
1703 -- and thus will not have the unit name automatically prepended.
1705 Set_Package_Name (Spec_Id);
1706 Add_Str_To_Name_Buffer ("_E");
1708 -- Create elaboration counter
1710 Elab_Ent := Make_Defining_Identifier (Loc, Chars => Name_Find);
1711 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
1714 Make_Object_Declaration (Loc,
1715 Defining_Identifier => Elab_Ent,
1716 Object_Definition =>
1717 New_Occurrence_Of (Standard_Short_Integer, Loc),
1718 Expression => Make_Integer_Literal (Loc, Uint_0));
1720 Push_Scope (Standard_Standard);
1721 Add_Global_Declaration (Decl);
1724 -- Reset True_Constant indication, since we will indeed assign a value
1725 -- to the variable in the binder main. We also kill the Current_Value
1726 -- and Last_Assignment fields for the same reason.
1728 Set_Is_True_Constant (Elab_Ent, False);
1729 Set_Current_Value (Elab_Ent, Empty);
1730 Set_Last_Assignment (Elab_Ent, Empty);
1732 -- We do not want any further qualification of the name (if we did not
1733 -- do this, we would pick up the name of the generic package in the case
1734 -- of a library level generic instantiation).
1736 Set_Has_Qualified_Name (Elab_Ent);
1737 Set_Has_Fully_Qualified_Name (Elab_Ent);
1738 end Build_Elaboration_Entity;
1740 --------------------------------
1741 -- Build_Explicit_Dereference --
1742 --------------------------------
1744 procedure Build_Explicit_Dereference
1748 Loc : constant Source_Ptr := Sloc (Expr);
1753 -- An entity of a type with a reference aspect is overloaded with
1754 -- both interpretations: with and without the dereference. Now that
1755 -- the dereference is made explicit, set the type of the node properly,
1756 -- to prevent anomalies in the backend. Same if the expression is an
1757 -- overloaded function call whose return type has a reference aspect.
1759 if Is_Entity_Name (Expr) then
1760 Set_Etype (Expr, Etype (Entity (Expr)));
1762 -- The designated entity will not be examined again when resolving
1763 -- the dereference, so generate a reference to it now.
1765 Generate_Reference (Entity (Expr), Expr);
1767 elsif Nkind (Expr) = N_Function_Call then
1769 -- If the name of the indexing function is overloaded, locate the one
1770 -- whose return type has an implicit dereference on the desired
1771 -- discriminant, and set entity and type of function call.
1773 if Is_Overloaded (Name (Expr)) then
1774 Get_First_Interp (Name (Expr), I, It);
1776 while Present (It.Nam) loop
1777 if Ekind ((It.Typ)) = E_Record_Type
1778 and then First_Entity ((It.Typ)) = Disc
1780 Set_Entity (Name (Expr), It.Nam);
1781 Set_Etype (Name (Expr), Etype (It.Nam));
1785 Get_Next_Interp (I, It);
1789 -- Set type of call from resolved function name.
1791 Set_Etype (Expr, Etype (Name (Expr)));
1794 Set_Is_Overloaded (Expr, False);
1796 -- The expression will often be a generalized indexing that yields a
1797 -- container element that is then dereferenced, in which case the
1798 -- generalized indexing call is also non-overloaded.
1800 if Nkind (Expr) = N_Indexed_Component
1801 and then Present (Generalized_Indexing (Expr))
1803 Set_Is_Overloaded (Generalized_Indexing (Expr), False);
1807 Make_Explicit_Dereference (Loc,
1809 Make_Selected_Component (Loc,
1810 Prefix => Relocate_Node (Expr),
1811 Selector_Name => New_Occurrence_Of (Disc, Loc))));
1812 Set_Etype (Prefix (Expr), Etype (Disc));
1813 Set_Etype (Expr, Designated_Type (Etype (Disc)));
1814 end Build_Explicit_Dereference;
1816 -----------------------------------
1817 -- Cannot_Raise_Constraint_Error --
1818 -----------------------------------
1820 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
1822 if Compile_Time_Known_Value (Expr) then
1825 elsif Do_Range_Check (Expr) then
1828 elsif Raises_Constraint_Error (Expr) then
1832 case Nkind (Expr) is
1833 when N_Identifier =>
1836 when N_Expanded_Name =>
1839 when N_Selected_Component =>
1840 return not Do_Discriminant_Check (Expr);
1842 when N_Attribute_Reference =>
1843 if Do_Overflow_Check (Expr) then
1846 elsif No (Expressions (Expr)) then
1854 N := First (Expressions (Expr));
1855 while Present (N) loop
1856 if Cannot_Raise_Constraint_Error (N) then
1867 when N_Type_Conversion =>
1868 if Do_Overflow_Check (Expr)
1869 or else Do_Length_Check (Expr)
1870 or else Do_Tag_Check (Expr)
1874 return Cannot_Raise_Constraint_Error (Expression (Expr));
1877 when N_Unchecked_Type_Conversion =>
1878 return Cannot_Raise_Constraint_Error (Expression (Expr));
1881 if Do_Overflow_Check (Expr) then
1884 return Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1891 if Do_Division_Check (Expr)
1893 Do_Overflow_Check (Expr)
1898 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1900 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1919 N_Op_Shift_Right_Arithmetic |
1923 if Do_Overflow_Check (Expr) then
1927 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1929 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1936 end Cannot_Raise_Constraint_Error;
1938 -----------------------------
1939 -- Check_Part_Of_Reference --
1940 -----------------------------
1942 procedure Check_Part_Of_Reference (Var_Id : Entity_Id; Ref : Node_Id) is
1943 Conc_Typ : constant Entity_Id := Encapsulating_State (Var_Id);
1945 OK_Use : Boolean := False;
1948 Spec_Id : Entity_Id;
1951 -- Traverse the parent chain looking for a suitable context for the
1952 -- reference to the concurrent constituent.
1954 Par := Parent (Ref);
1955 while Present (Par) loop
1956 if Nkind (Par) = N_Pragma then
1957 Prag_Nam := Pragma_Name (Par);
1959 -- A concurrent constituent is allowed to appear in pragmas
1960 -- Initial_Condition and Initializes as this is part of the
1961 -- elaboration checks for the constituent (SPARK RM 9.3).
1963 if Nam_In (Prag_Nam, Name_Initial_Condition, Name_Initializes) then
1967 -- When the reference appears within pragma Depends or Global,
1968 -- check whether the pragma applies to a single task type. Note
1969 -- that the pragma is not encapsulated by the type definition,
1970 -- but this is still a valid context.
1972 elsif Nam_In (Prag_Nam, Name_Depends, Name_Global) then
1973 Decl := Find_Related_Declaration_Or_Body (Par);
1975 if Nkind (Decl) = N_Object_Declaration
1976 and then Defining_Entity (Decl) = Conc_Typ
1983 -- The reference appears somewhere in the definition of the single
1984 -- protected/task type (SPARK RM 9.3).
1986 elsif Nkind_In (Par, N_Single_Protected_Declaration,
1987 N_Single_Task_Declaration)
1988 and then Defining_Entity (Par) = Conc_Typ
1993 -- The reference appears within the expanded declaration or the body
1994 -- of the single protected/task type (SPARK RM 9.3).
1996 elsif Nkind_In (Par, N_Protected_Body,
1997 N_Protected_Type_Declaration,
1999 N_Task_Type_Declaration)
2001 Spec_Id := Unique_Defining_Entity (Par);
2003 if Present (Anonymous_Object (Spec_Id))
2004 and then Anonymous_Object (Spec_Id) = Conc_Typ
2010 -- The reference has been relocated within an internally generated
2011 -- package or subprogram. Assume that the reference is legal as the
2012 -- real check was already performed in the original context of the
2015 elsif Nkind_In (Par, N_Package_Body,
2016 N_Package_Declaration,
2018 N_Subprogram_Declaration)
2019 and then not Comes_From_Source (Par)
2024 -- The reference has been relocated to an inlined body for GNATprove.
2025 -- Assume that the reference is legal as the real check was already
2026 -- performed in the original context of the reference.
2028 elsif GNATprove_Mode
2029 and then Nkind (Par) = N_Subprogram_Body
2030 and then Chars (Defining_Entity (Par)) = Name_uParent
2036 Par := Parent (Par);
2039 -- The reference is illegal as it appears outside the definition or
2040 -- body of the single protected/task type.
2044 ("reference to variable & cannot appear in this context",
2046 Error_Msg_Name_1 := Chars (Var_Id);
2048 if Ekind (Conc_Typ) = E_Protected_Type then
2050 ("\% is constituent of single protected type &", Ref, Conc_Typ);
2053 ("\% is constituent of single task type &", Ref, Conc_Typ);
2056 end Check_Part_Of_Reference;
2058 -----------------------------------------
2059 -- Check_Dynamically_Tagged_Expression --
2060 -----------------------------------------
2062 procedure Check_Dynamically_Tagged_Expression
2065 Related_Nod : Node_Id)
2068 pragma Assert (Is_Tagged_Type (Typ));
2070 -- In order to avoid spurious errors when analyzing the expanded code,
2071 -- this check is done only for nodes that come from source and for
2072 -- actuals of generic instantiations.
2074 if (Comes_From_Source (Related_Nod)
2075 or else In_Generic_Actual (Expr))
2076 and then (Is_Class_Wide_Type (Etype (Expr))
2077 or else Is_Dynamically_Tagged (Expr))
2078 and then Is_Tagged_Type (Typ)
2079 and then not Is_Class_Wide_Type (Typ)
2081 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
2083 end Check_Dynamically_Tagged_Expression;
2085 --------------------------
2086 -- Check_Fully_Declared --
2087 --------------------------
2089 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
2091 if Ekind (T) = E_Incomplete_Type then
2093 -- Ada 2005 (AI-50217): If the type is available through a limited
2094 -- with_clause, verify that its full view has been analyzed.
2096 if From_Limited_With (T)
2097 and then Present (Non_Limited_View (T))
2098 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
2100 -- The non-limited view is fully declared
2106 ("premature usage of incomplete}", N, First_Subtype (T));
2109 -- Need comments for these tests ???
2111 elsif Has_Private_Component (T)
2112 and then not Is_Generic_Type (Root_Type (T))
2113 and then not In_Spec_Expression
2115 -- Special case: if T is the anonymous type created for a single
2116 -- task or protected object, use the name of the source object.
2118 if Is_Concurrent_Type (T)
2119 and then not Comes_From_Source (T)
2120 and then Nkind (N) = N_Object_Declaration
2123 ("type of& has incomplete component",
2124 N, Defining_Identifier (N));
2127 ("premature usage of incomplete}",
2128 N, First_Subtype (T));
2131 end Check_Fully_Declared;
2133 -------------------------------------------
2134 -- Check_Function_With_Address_Parameter --
2135 -------------------------------------------
2137 procedure Check_Function_With_Address_Parameter (Subp_Id : Entity_Id) is
2142 F := First_Formal (Subp_Id);
2143 while Present (F) loop
2146 if Is_Private_Type (T) and then Present (Full_View (T)) then
2150 if Is_Descendant_Of_Address (T) or else Is_Limited_Type (T) then
2151 Set_Is_Pure (Subp_Id, False);
2157 end Check_Function_With_Address_Parameter;
2159 -------------------------------------
2160 -- Check_Function_Writable_Actuals --
2161 -------------------------------------
2163 procedure Check_Function_Writable_Actuals (N : Node_Id) is
2164 Writable_Actuals_List : Elist_Id := No_Elist;
2165 Identifiers_List : Elist_Id := No_Elist;
2166 Aggr_Error_Node : Node_Id := Empty;
2167 Error_Node : Node_Id := Empty;
2169 procedure Collect_Identifiers (N : Node_Id);
2170 -- In a single traversal of subtree N collect in Writable_Actuals_List
2171 -- all the actuals of functions with writable actuals, and in the list
2172 -- Identifiers_List collect all the identifiers that are not actuals of
2173 -- functions with writable actuals. If a writable actual is referenced
2174 -- twice as writable actual then Error_Node is set to reference its
2175 -- second occurrence, the error is reported, and the tree traversal
2178 function Get_Function_Id (Call : Node_Id) return Entity_Id;
2179 -- Return the entity associated with the function call
2181 procedure Preanalyze_Without_Errors (N : Node_Id);
2182 -- Preanalyze N without reporting errors. Very dubious, you can't just
2183 -- go analyzing things more than once???
2185 -------------------------
2186 -- Collect_Identifiers --
2187 -------------------------
2189 procedure Collect_Identifiers (N : Node_Id) is
2191 function Check_Node (N : Node_Id) return Traverse_Result;
2192 -- Process a single node during the tree traversal to collect the
2193 -- writable actuals of functions and all the identifiers which are
2194 -- not writable actuals of functions.
2196 function Contains (List : Elist_Id; N : Node_Id) return Boolean;
2197 -- Returns True if List has a node whose Entity is Entity (N)
2199 -------------------------
2200 -- Check_Function_Call --
2201 -------------------------
2203 function Check_Node (N : Node_Id) return Traverse_Result is
2204 Is_Writable_Actual : Boolean := False;
2208 if Nkind (N) = N_Identifier then
2210 -- No analysis possible if the entity is not decorated
2212 if No (Entity (N)) then
2215 -- Don't collect identifiers of packages, called functions, etc
2217 elsif Ekind_In (Entity (N), E_Package,
2224 -- For rewritten nodes, continue the traversal in the original
2225 -- subtree. Needed to handle aggregates in original expressions
2226 -- extracted from the tree by Remove_Side_Effects.
2228 elsif Is_Rewrite_Substitution (N) then
2229 Collect_Identifiers (Original_Node (N));
2232 -- For now we skip aggregate discriminants, since they require
2233 -- performing the analysis in two phases to identify conflicts:
2234 -- first one analyzing discriminants and second one analyzing
2235 -- the rest of components (since at run time, discriminants are
2236 -- evaluated prior to components): too much computation cost
2237 -- to identify a corner case???
2239 elsif Nkind (Parent (N)) = N_Component_Association
2240 and then Nkind_In (Parent (Parent (N)),
2242 N_Extension_Aggregate)
2245 Choice : constant Node_Id := First (Choices (Parent (N)));
2248 if Ekind (Entity (N)) = E_Discriminant then
2251 elsif Expression (Parent (N)) = N
2252 and then Nkind (Choice) = N_Identifier
2253 and then Ekind (Entity (Choice)) = E_Discriminant
2259 -- Analyze if N is a writable actual of a function
2261 elsif Nkind (Parent (N)) = N_Function_Call then
2263 Call : constant Node_Id := Parent (N);
2268 Id := Get_Function_Id (Call);
2270 -- In case of previous error, no check is possible
2276 if Ekind_In (Id, E_Function, E_Generic_Function)
2277 and then Has_Out_Or_In_Out_Parameter (Id)
2279 Formal := First_Formal (Id);
2280 Actual := First_Actual (Call);
2281 while Present (Actual) and then Present (Formal) loop
2283 if Ekind_In (Formal, E_Out_Parameter,
2286 Is_Writable_Actual := True;
2292 Next_Formal (Formal);
2293 Next_Actual (Actual);
2299 if Is_Writable_Actual then
2301 -- Skip checking the error in non-elementary types since
2302 -- RM 6.4.1(6.15/3) is restricted to elementary types, but
2303 -- store this actual in Writable_Actuals_List since it is
2304 -- needed to perform checks on other constructs that have
2305 -- arbitrary order of evaluation (for example, aggregates).
2307 if not Is_Elementary_Type (Etype (N)) then
2308 if not Contains (Writable_Actuals_List, N) then
2309 Append_New_Elmt (N, To => Writable_Actuals_List);
2312 -- Second occurrence of an elementary type writable actual
2314 elsif Contains (Writable_Actuals_List, N) then
2316 -- Report the error on the second occurrence of the
2317 -- identifier. We cannot assume that N is the second
2318 -- occurrence (according to their location in the
2319 -- sources), since Traverse_Func walks through Field2
2320 -- last (see comment in the body of Traverse_Func).
2326 Elmt := First_Elmt (Writable_Actuals_List);
2327 while Present (Elmt)
2328 and then Entity (Node (Elmt)) /= Entity (N)
2333 if Sloc (N) > Sloc (Node (Elmt)) then
2336 Error_Node := Node (Elmt);
2340 ("value may be affected by call to & "
2341 & "because order of evaluation is arbitrary",
2346 -- First occurrence of a elementary type writable actual
2349 Append_New_Elmt (N, To => Writable_Actuals_List);
2353 if Identifiers_List = No_Elist then
2354 Identifiers_List := New_Elmt_List;
2357 Append_Unique_Elmt (N, Identifiers_List);
2370 N : Node_Id) return Boolean
2372 pragma Assert (Nkind (N) in N_Has_Entity);
2377 if List = No_Elist then
2381 Elmt := First_Elmt (List);
2382 while Present (Elmt) loop
2383 if Entity (Node (Elmt)) = Entity (N) then
2397 procedure Do_Traversal is new Traverse_Proc (Check_Node);
2398 -- The traversal procedure
2400 -- Start of processing for Collect_Identifiers
2403 if Present (Error_Node) then
2407 if Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
2412 end Collect_Identifiers;
2414 ---------------------
2415 -- Get_Function_Id --
2416 ---------------------
2418 function Get_Function_Id (Call : Node_Id) return Entity_Id is
2419 Nam : constant Node_Id := Name (Call);
2423 if Nkind (Nam) = N_Explicit_Dereference then
2425 pragma Assert (Ekind (Id) = E_Subprogram_Type);
2427 elsif Nkind (Nam) = N_Selected_Component then
2428 Id := Entity (Selector_Name (Nam));
2430 elsif Nkind (Nam) = N_Indexed_Component then
2431 Id := Entity (Selector_Name (Prefix (Nam)));
2438 end Get_Function_Id;
2440 -------------------------------
2441 -- Preanalyze_Without_Errors --
2442 -------------------------------
2444 procedure Preanalyze_Without_Errors (N : Node_Id) is
2445 Status : constant Boolean := Get_Ignore_Errors;
2447 Set_Ignore_Errors (True);
2449 Set_Ignore_Errors (Status);
2450 end Preanalyze_Without_Errors;
2452 -- Start of processing for Check_Function_Writable_Actuals
2455 -- The check only applies to Ada 2012 code on which Check_Actuals has
2456 -- been set, and only to constructs that have multiple constituents
2457 -- whose order of evaluation is not specified by the language.
2459 if Ada_Version < Ada_2012
2460 or else not Check_Actuals (N)
2461 or else (not (Nkind (N) in N_Op)
2462 and then not (Nkind (N) in N_Membership_Test)
2463 and then not Nkind_In (N, N_Range,
2465 N_Extension_Aggregate,
2466 N_Full_Type_Declaration,
2468 N_Procedure_Call_Statement,
2469 N_Entry_Call_Statement))
2470 or else (Nkind (N) = N_Full_Type_Declaration
2471 and then not Is_Record_Type (Defining_Identifier (N)))
2473 -- In addition, this check only applies to source code, not to code
2474 -- generated by constraint checks.
2476 or else not Comes_From_Source (N)
2481 -- If a construct C has two or more direct constituents that are names
2482 -- or expressions whose evaluation may occur in an arbitrary order, at
2483 -- least one of which contains a function call with an in out or out
2484 -- parameter, then the construct is legal only if: for each name N that
2485 -- is passed as a parameter of mode in out or out to some inner function
2486 -- call C2 (not including the construct C itself), there is no other
2487 -- name anywhere within a direct constituent of the construct C other
2488 -- than the one containing C2, that is known to refer to the same
2489 -- object (RM 6.4.1(6.17/3)).
2493 Collect_Identifiers (Low_Bound (N));
2494 Collect_Identifiers (High_Bound (N));
2496 when N_Op | N_Membership_Test =>
2501 Collect_Identifiers (Left_Opnd (N));
2503 if Present (Right_Opnd (N)) then
2504 Collect_Identifiers (Right_Opnd (N));
2507 if Nkind_In (N, N_In, N_Not_In)
2508 and then Present (Alternatives (N))
2510 Expr := First (Alternatives (N));
2511 while Present (Expr) loop
2512 Collect_Identifiers (Expr);
2519 when N_Full_Type_Declaration =>
2521 function Get_Record_Part (N : Node_Id) return Node_Id;
2522 -- Return the record part of this record type definition
2524 function Get_Record_Part (N : Node_Id) return Node_Id is
2525 Type_Def : constant Node_Id := Type_Definition (N);
2527 if Nkind (Type_Def) = N_Derived_Type_Definition then
2528 return Record_Extension_Part (Type_Def);
2532 end Get_Record_Part;
2535 Def_Id : Entity_Id := Defining_Identifier (N);
2536 Rec : Node_Id := Get_Record_Part (N);
2539 -- No need to perform any analysis if the record has no
2542 if No (Rec) or else No (Component_List (Rec)) then
2546 -- Collect the identifiers starting from the deepest
2547 -- derivation. Done to report the error in the deepest
2551 if Present (Component_List (Rec)) then
2552 Comp := First (Component_Items (Component_List (Rec)));
2553 while Present (Comp) loop
2554 if Nkind (Comp) = N_Component_Declaration
2555 and then Present (Expression (Comp))
2557 Collect_Identifiers (Expression (Comp));
2564 exit when No (Underlying_Type (Etype (Def_Id)))
2565 or else Base_Type (Underlying_Type (Etype (Def_Id)))
2568 Def_Id := Base_Type (Underlying_Type (Etype (Def_Id)));
2569 Rec := Get_Record_Part (Parent (Def_Id));
2573 when N_Subprogram_Call |
2574 N_Entry_Call_Statement =>
2576 Id : constant Entity_Id := Get_Function_Id (N);
2581 Formal := First_Formal (Id);
2582 Actual := First_Actual (N);
2583 while Present (Actual) and then Present (Formal) loop
2584 if Ekind_In (Formal, E_Out_Parameter,
2587 Collect_Identifiers (Actual);
2590 Next_Formal (Formal);
2591 Next_Actual (Actual);
2596 N_Extension_Aggregate =>
2600 Comp_Expr : Node_Id;
2603 -- Handle the N_Others_Choice of array aggregates with static
2604 -- bounds. There is no need to perform this analysis in
2605 -- aggregates without static bounds since we cannot evaluate
2606 -- if the N_Others_Choice covers several elements. There is
2607 -- no need to handle the N_Others choice of record aggregates
2608 -- since at this stage it has been already expanded by
2609 -- Resolve_Record_Aggregate.
2611 if Is_Array_Type (Etype (N))
2612 and then Nkind (N) = N_Aggregate
2613 and then Present (Aggregate_Bounds (N))
2614 and then Compile_Time_Known_Bounds (Etype (N))
2615 and then Expr_Value (High_Bound (Aggregate_Bounds (N)))
2617 Expr_Value (Low_Bound (Aggregate_Bounds (N)))
2620 Count_Components : Uint := Uint_0;
2621 Num_Components : Uint;
2622 Others_Assoc : Node_Id;
2623 Others_Choice : Node_Id := Empty;
2624 Others_Box_Present : Boolean := False;
2627 -- Count positional associations
2629 if Present (Expressions (N)) then
2630 Comp_Expr := First (Expressions (N));
2631 while Present (Comp_Expr) loop
2632 Count_Components := Count_Components + 1;
2637 -- Count the rest of elements and locate the N_Others
2640 Assoc := First (Component_Associations (N));
2641 while Present (Assoc) loop
2642 Choice := First (Choices (Assoc));
2643 while Present (Choice) loop
2644 if Nkind (Choice) = N_Others_Choice then
2645 Others_Assoc := Assoc;
2646 Others_Choice := Choice;
2647 Others_Box_Present := Box_Present (Assoc);
2649 -- Count several components
2651 elsif Nkind_In (Choice, N_Range,
2652 N_Subtype_Indication)
2653 or else (Is_Entity_Name (Choice)
2654 and then Is_Type (Entity (Choice)))
2659 Get_Index_Bounds (Choice, L, H);
2661 (Compile_Time_Known_Value (L)
2662 and then Compile_Time_Known_Value (H));
2665 + Expr_Value (H) - Expr_Value (L) + 1;
2668 -- Count single component. No other case available
2669 -- since we are handling an aggregate with static
2673 pragma Assert (Is_OK_Static_Expression (Choice)
2674 or else Nkind (Choice) = N_Identifier
2675 or else Nkind (Choice) = N_Integer_Literal);
2677 Count_Components := Count_Components + 1;
2687 Expr_Value (High_Bound (Aggregate_Bounds (N))) -
2688 Expr_Value (Low_Bound (Aggregate_Bounds (N))) + 1;
2690 pragma Assert (Count_Components <= Num_Components);
2692 -- Handle the N_Others choice if it covers several
2695 if Present (Others_Choice)
2696 and then (Num_Components - Count_Components) > 1
2698 if not Others_Box_Present then
2700 -- At this stage, if expansion is active, the
2701 -- expression of the others choice has not been
2702 -- analyzed. Hence we generate a duplicate and
2703 -- we analyze it silently to have available the
2704 -- minimum decoration required to collect the
2707 if not Expander_Active then
2708 Comp_Expr := Expression (Others_Assoc);
2711 New_Copy_Tree (Expression (Others_Assoc));
2712 Preanalyze_Without_Errors (Comp_Expr);
2715 Collect_Identifiers (Comp_Expr);
2717 if Writable_Actuals_List /= No_Elist then
2719 -- As suggested by Robert, at current stage we
2720 -- report occurrences of this case as warnings.
2723 ("writable function parameter may affect "
2724 & "value in other component because order "
2725 & "of evaluation is unspecified??",
2726 Node (First_Elmt (Writable_Actuals_List)));
2732 -- For an array aggregate, a discrete_choice_list that has
2733 -- a nonstatic range is considered as two or more separate
2734 -- occurrences of the expression (RM 6.4.1(20/3)).
2736 elsif Is_Array_Type (Etype (N))
2737 and then Nkind (N) = N_Aggregate
2738 and then Present (Aggregate_Bounds (N))
2739 and then not Compile_Time_Known_Bounds (Etype (N))
2741 -- Collect identifiers found in the dynamic bounds
2744 Count_Components : Natural := 0;
2745 Low, High : Node_Id;
2748 Assoc := First (Component_Associations (N));
2749 while Present (Assoc) loop
2750 Choice := First (Choices (Assoc));
2751 while Present (Choice) loop
2752 if Nkind_In (Choice, N_Range,
2753 N_Subtype_Indication)
2754 or else (Is_Entity_Name (Choice)
2755 and then Is_Type (Entity (Choice)))
2757 Get_Index_Bounds (Choice, Low, High);
2759 if not Compile_Time_Known_Value (Low) then
2760 Collect_Identifiers (Low);
2762 if No (Aggr_Error_Node) then
2763 Aggr_Error_Node := Low;
2767 if not Compile_Time_Known_Value (High) then
2768 Collect_Identifiers (High);
2770 if No (Aggr_Error_Node) then
2771 Aggr_Error_Node := High;
2775 -- The RM rule is violated if there is more than
2776 -- a single choice in a component association.
2779 Count_Components := Count_Components + 1;
2781 if No (Aggr_Error_Node)
2782 and then Count_Components > 1
2784 Aggr_Error_Node := Choice;
2787 if not Compile_Time_Known_Value (Choice) then
2788 Collect_Identifiers (Choice);
2800 -- Handle ancestor part of extension aggregates
2802 if Nkind (N) = N_Extension_Aggregate then
2803 Collect_Identifiers (Ancestor_Part (N));
2806 -- Handle positional associations
2808 if Present (Expressions (N)) then
2809 Comp_Expr := First (Expressions (N));
2810 while Present (Comp_Expr) loop
2811 if not Is_OK_Static_Expression (Comp_Expr) then
2812 Collect_Identifiers (Comp_Expr);
2819 -- Handle discrete associations
2821 if Present (Component_Associations (N)) then
2822 Assoc := First (Component_Associations (N));
2823 while Present (Assoc) loop
2825 if not Box_Present (Assoc) then
2826 Choice := First (Choices (Assoc));
2827 while Present (Choice) loop
2829 -- For now we skip discriminants since it requires
2830 -- performing the analysis in two phases: first one
2831 -- analyzing discriminants and second one analyzing
2832 -- the rest of components since discriminants are
2833 -- evaluated prior to components: too much extra
2834 -- work to detect a corner case???
2836 if Nkind (Choice) in N_Has_Entity
2837 and then Present (Entity (Choice))
2838 and then Ekind (Entity (Choice)) = E_Discriminant
2842 elsif Box_Present (Assoc) then
2846 if not Analyzed (Expression (Assoc)) then
2848 New_Copy_Tree (Expression (Assoc));
2849 Set_Parent (Comp_Expr, Parent (N));
2850 Preanalyze_Without_Errors (Comp_Expr);
2852 Comp_Expr := Expression (Assoc);
2855 Collect_Identifiers (Comp_Expr);
2871 -- No further action needed if we already reported an error
2873 if Present (Error_Node) then
2877 -- Check violation of RM 6.20/3 in aggregates
2879 if Present (Aggr_Error_Node)
2880 and then Writable_Actuals_List /= No_Elist
2883 ("value may be affected by call in other component because they "
2884 & "are evaluated in unspecified order",
2885 Node (First_Elmt (Writable_Actuals_List)));
2889 -- Check if some writable argument of a function is referenced
2891 if Writable_Actuals_List /= No_Elist
2892 and then Identifiers_List /= No_Elist
2899 Elmt_1 := First_Elmt (Writable_Actuals_List);
2900 while Present (Elmt_1) loop
2901 Elmt_2 := First_Elmt (Identifiers_List);
2902 while Present (Elmt_2) loop
2903 if Entity (Node (Elmt_1)) = Entity (Node (Elmt_2)) then
2904 case Nkind (Parent (Node (Elmt_2))) is
2906 N_Component_Association |
2907 N_Component_Declaration =>
2909 ("value may be affected by call in other "
2910 & "component because they are evaluated "
2911 & "in unspecified order",
2914 when N_In | N_Not_In =>
2916 ("value may be affected by call in other "
2917 & "alternative because they are evaluated "
2918 & "in unspecified order",
2923 ("value of actual may be affected by call in "
2924 & "other actual because they are evaluated "
2925 & "in unspecified order",
2937 end Check_Function_Writable_Actuals;
2939 --------------------------------
2940 -- Check_Implicit_Dereference --
2941 --------------------------------
2943 procedure Check_Implicit_Dereference (N : Node_Id; Typ : Entity_Id) is
2949 if Nkind (N) = N_Indexed_Component
2950 and then Present (Generalized_Indexing (N))
2952 Nam := Generalized_Indexing (N);
2957 if Ada_Version < Ada_2012
2958 or else not Has_Implicit_Dereference (Base_Type (Typ))
2962 elsif not Comes_From_Source (N)
2963 and then Nkind (N) /= N_Indexed_Component
2967 elsif Is_Entity_Name (Nam) and then Is_Type (Entity (Nam)) then
2971 Disc := First_Discriminant (Typ);
2972 while Present (Disc) loop
2973 if Has_Implicit_Dereference (Disc) then
2974 Desig := Designated_Type (Etype (Disc));
2975 Add_One_Interp (Nam, Disc, Desig);
2977 -- If the node is a generalized indexing, add interpretation
2978 -- to that node as well, for subsequent resolution.
2980 if Nkind (N) = N_Indexed_Component then
2981 Add_One_Interp (N, Disc, Desig);
2984 -- If the operation comes from a generic unit and the context
2985 -- is a selected component, the selector name may be global
2986 -- and set in the instance already. Remove the entity to
2987 -- force resolution of the selected component, and the
2988 -- generation of an explicit dereference if needed.
2991 and then Nkind (Parent (Nam)) = N_Selected_Component
2993 Set_Entity (Selector_Name (Parent (Nam)), Empty);
2999 Next_Discriminant (Disc);
3002 end Check_Implicit_Dereference;
3004 ----------------------------------
3005 -- Check_Internal_Protected_Use --
3006 ----------------------------------
3008 procedure Check_Internal_Protected_Use (N : Node_Id; Nam : Entity_Id) is
3014 while Present (S) loop
3015 if S = Standard_Standard then
3018 elsif Ekind (S) = E_Function
3019 and then Ekind (Scope (S)) = E_Protected_Type
3028 if Scope (Nam) = Prot and then Ekind (Nam) /= E_Function then
3030 -- An indirect function call (e.g. a callback within a protected
3031 -- function body) is not statically illegal. If the access type is
3032 -- anonymous and is the type of an access parameter, the scope of Nam
3033 -- will be the protected type, but it is not a protected operation.
3035 if Ekind (Nam) = E_Subprogram_Type
3037 Nkind (Associated_Node_For_Itype (Nam)) = N_Function_Specification
3041 elsif Nkind (N) = N_Subprogram_Renaming_Declaration then
3043 ("within protected function cannot use protected "
3044 & "procedure in renaming or as generic actual", N);
3046 elsif Nkind (N) = N_Attribute_Reference then
3048 ("within protected function cannot take access of "
3049 & " protected procedure", N);
3053 ("within protected function, protected object is constant", N);
3055 ("\cannot call operation that may modify it", N);
3058 end Check_Internal_Protected_Use;
3060 ---------------------------------------
3061 -- Check_Later_Vs_Basic_Declarations --
3062 ---------------------------------------
3064 procedure Check_Later_Vs_Basic_Declarations
3066 During_Parsing : Boolean)
3068 Body_Sloc : Source_Ptr;
3071 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
3072 -- Return whether Decl is considered as a declarative item.
3073 -- When During_Parsing is True, the semantics of Ada 83 is followed.
3074 -- When During_Parsing is False, the semantics of SPARK is followed.
3076 -------------------------------
3077 -- Is_Later_Declarative_Item --
3078 -------------------------------
3080 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
3082 if Nkind (Decl) in N_Later_Decl_Item then
3085 elsif Nkind (Decl) = N_Pragma then
3088 elsif During_Parsing then
3091 -- In SPARK, a package declaration is not considered as a later
3092 -- declarative item.
3094 elsif Nkind (Decl) = N_Package_Declaration then
3097 -- In SPARK, a renaming is considered as a later declarative item
3099 elsif Nkind (Decl) in N_Renaming_Declaration then
3105 end Is_Later_Declarative_Item;
3107 -- Start of processing for Check_Later_Vs_Basic_Declarations
3110 Decl := First (Decls);
3112 -- Loop through sequence of basic declarative items
3114 Outer : while Present (Decl) loop
3115 if not Nkind_In (Decl, N_Subprogram_Body, N_Package_Body, N_Task_Body)
3116 and then Nkind (Decl) not in N_Body_Stub
3120 -- Once a body is encountered, we only allow later declarative
3121 -- items. The inner loop checks the rest of the list.
3124 Body_Sloc := Sloc (Decl);
3126 Inner : while Present (Decl) loop
3127 if not Is_Later_Declarative_Item (Decl) then
3128 if During_Parsing then
3129 if Ada_Version = Ada_83 then
3130 Error_Msg_Sloc := Body_Sloc;
3132 ("(Ada 83) decl cannot appear after body#", Decl);
3135 Error_Msg_Sloc := Body_Sloc;
3136 Check_SPARK_05_Restriction
3137 ("decl cannot appear after body#", Decl);
3145 end Check_Later_Vs_Basic_Declarations;
3147 ---------------------------
3148 -- Check_No_Hidden_State --
3149 ---------------------------
3151 procedure Check_No_Hidden_State (Id : Entity_Id) is
3152 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean;
3153 -- Determine whether the entity of a package denoted by Pkg has a null
3156 -----------------------------
3157 -- Has_Null_Abstract_State --
3158 -----------------------------
3160 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean is
3161 States : constant Elist_Id := Abstract_States (Pkg);
3164 -- Check first available state of related package. A null abstract
3165 -- state always appears as the sole element of the state list.
3169 and then Is_Null_State (Node (First_Elmt (States)));
3170 end Has_Null_Abstract_State;
3174 Context : Entity_Id := Empty;
3175 Not_Visible : Boolean := False;
3178 -- Start of processing for Check_No_Hidden_State
3181 pragma Assert (Ekind_In (Id, E_Abstract_State, E_Variable));
3183 -- Find the proper context where the object or state appears
3186 while Present (Scop) loop
3189 -- Keep track of the context's visibility
3191 Not_Visible := Not_Visible or else In_Private_Part (Context);
3193 -- Prevent the search from going too far
3195 if Context = Standard_Standard then
3198 -- Objects and states that appear immediately within a subprogram or
3199 -- inside a construct nested within a subprogram do not introduce a
3200 -- hidden state. They behave as local variable declarations.
3202 elsif Is_Subprogram (Context) then
3205 -- When examining a package body, use the entity of the spec as it
3206 -- carries the abstract state declarations.
3208 elsif Ekind (Context) = E_Package_Body then
3209 Context := Spec_Entity (Context);
3212 -- Stop the traversal when a package subject to a null abstract state
3215 if Ekind_In (Context, E_Generic_Package, E_Package)
3216 and then Has_Null_Abstract_State (Context)
3221 Scop := Scope (Scop);
3224 -- At this point we know that there is at least one package with a null
3225 -- abstract state in visibility. Emit an error message unconditionally
3226 -- if the entity being processed is a state because the placement of the
3227 -- related package is irrelevant. This is not the case for objects as
3228 -- the intermediate context matters.
3230 if Present (Context)
3231 and then (Ekind (Id) = E_Abstract_State or else Not_Visible)
3233 Error_Msg_N ("cannot introduce hidden state &", Id);
3234 Error_Msg_NE ("\package & has null abstract state", Id, Context);
3236 end Check_No_Hidden_State;
3238 ----------------------------------------
3239 -- Check_Nonvolatile_Function_Profile --
3240 ----------------------------------------
3242 procedure Check_Nonvolatile_Function_Profile (Func_Id : Entity_Id) is
3246 -- Inspect all formal parameters
3248 Formal := First_Formal (Func_Id);
3249 while Present (Formal) loop
3250 if Is_Effectively_Volatile (Etype (Formal)) then
3252 ("nonvolatile function & cannot have a volatile parameter",
3256 Next_Formal (Formal);
3259 -- Inspect the return type
3261 if Is_Effectively_Volatile (Etype (Func_Id)) then
3263 ("nonvolatile function & cannot have a volatile return type",
3264 Result_Definition (Parent (Func_Id)), Func_Id);
3266 end Check_Nonvolatile_Function_Profile;
3268 ------------------------------------------
3269 -- Check_Potentially_Blocking_Operation --
3270 ------------------------------------------
3272 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
3276 -- N is one of the potentially blocking operations listed in 9.5.1(8).
3277 -- When pragma Detect_Blocking is active, the run time will raise
3278 -- Program_Error. Here we only issue a warning, since we generally
3279 -- support the use of potentially blocking operations in the absence
3282 -- Indirect blocking through a subprogram call cannot be diagnosed
3283 -- statically without interprocedural analysis, so we do not attempt
3286 S := Scope (Current_Scope);
3287 while Present (S) and then S /= Standard_Standard loop
3288 if Is_Protected_Type (S) then
3290 ("potentially blocking operation in protected operation??", N);
3296 end Check_Potentially_Blocking_Operation;
3298 ---------------------------------
3299 -- Check_Result_And_Post_State --
3300 ---------------------------------
3302 procedure Check_Result_And_Post_State (Subp_Id : Entity_Id) is
3303 procedure Check_Result_And_Post_State_In_Pragma
3305 Result_Seen : in out Boolean);
3306 -- Determine whether pragma Prag mentions attribute 'Result and whether
3307 -- the pragma contains an expression that evaluates differently in pre-
3308 -- and post-state. Prag is a [refined] postcondition or a contract-cases
3309 -- pragma. Result_Seen is set when the pragma mentions attribute 'Result
3311 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean;
3312 -- Determine whether subprogram Subp_Id contains at least one IN OUT
3313 -- formal parameter.
3315 -------------------------------------------
3316 -- Check_Result_And_Post_State_In_Pragma --
3317 -------------------------------------------
3319 procedure Check_Result_And_Post_State_In_Pragma
3321 Result_Seen : in out Boolean)
3323 procedure Check_Expression (Expr : Node_Id);
3324 -- Perform the 'Result and post-state checks on a given expression
3326 function Is_Function_Result (N : Node_Id) return Traverse_Result;
3327 -- Attempt to find attribute 'Result in a subtree denoted by N
3329 function Is_Trivial_Boolean (N : Node_Id) return Boolean;
3330 -- Determine whether source node N denotes "True" or "False"
3332 function Mentions_Post_State (N : Node_Id) return Boolean;
3333 -- Determine whether a subtree denoted by N mentions any construct
3334 -- that denotes a post-state.
3336 procedure Check_Function_Result is
3337 new Traverse_Proc (Is_Function_Result);
3339 ----------------------
3340 -- Check_Expression --
3341 ----------------------
3343 procedure Check_Expression (Expr : Node_Id) is
3345 if not Is_Trivial_Boolean (Expr) then
3346 Check_Function_Result (Expr);
3348 if not Mentions_Post_State (Expr) then
3349 if Pragma_Name (Prag) = Name_Contract_Cases then
3351 ("contract case does not check the outcome of calling "
3352 & "&?T?", Expr, Subp_Id);
3354 elsif Pragma_Name (Prag) = Name_Refined_Post then
3356 ("refined postcondition does not check the outcome of "
3357 & "calling &?T?", Prag, Subp_Id);
3361 ("postcondition does not check the outcome of calling "
3362 & "&?T?", Prag, Subp_Id);
3366 end Check_Expression;
3368 ------------------------
3369 -- Is_Function_Result --
3370 ------------------------
3372 function Is_Function_Result (N : Node_Id) return Traverse_Result is
3374 if Is_Attribute_Result (N) then
3375 Result_Seen := True;
3378 -- Continue the traversal
3383 end Is_Function_Result;
3385 ------------------------
3386 -- Is_Trivial_Boolean --
3387 ------------------------
3389 function Is_Trivial_Boolean (N : Node_Id) return Boolean is
3392 Comes_From_Source (N)
3393 and then Is_Entity_Name (N)
3394 and then (Entity (N) = Standard_True
3396 Entity (N) = Standard_False);
3397 end Is_Trivial_Boolean;
3399 -------------------------
3400 -- Mentions_Post_State --
3401 -------------------------
3403 function Mentions_Post_State (N : Node_Id) return Boolean is
3404 Post_State_Seen : Boolean := False;
3406 function Is_Post_State (N : Node_Id) return Traverse_Result;
3407 -- Attempt to find a construct that denotes a post-state. If this
3408 -- is the case, set flag Post_State_Seen.
3414 function Is_Post_State (N : Node_Id) return Traverse_Result is
3418 if Nkind_In (N, N_Explicit_Dereference, N_Function_Call) then
3419 Post_State_Seen := True;
3422 elsif Nkind_In (N, N_Expanded_Name, N_Identifier) then
3425 -- The entity may be modifiable through an implicit
3429 or else Ekind (Ent) in Assignable_Kind
3430 or else (Is_Access_Type (Etype (Ent))
3431 and then Nkind (Parent (N)) =
3432 N_Selected_Component)
3434 Post_State_Seen := True;
3438 elsif Nkind (N) = N_Attribute_Reference then
3439 if Attribute_Name (N) = Name_Old then
3442 elsif Attribute_Name (N) = Name_Result then
3443 Post_State_Seen := True;
3451 procedure Find_Post_State is new Traverse_Proc (Is_Post_State);
3453 -- Start of processing for Mentions_Post_State
3456 Find_Post_State (N);
3458 return Post_State_Seen;
3459 end Mentions_Post_State;
3463 Expr : constant Node_Id :=
3465 (First (Pragma_Argument_Associations (Prag)));
3466 Nam : constant Name_Id := Pragma_Name (Prag);
3469 -- Start of processing for Check_Result_And_Post_State_In_Pragma
3472 -- Examine all consequences
3474 if Nam = Name_Contract_Cases then
3475 CCase := First (Component_Associations (Expr));
3476 while Present (CCase) loop
3477 Check_Expression (Expression (CCase));
3482 -- Examine the expression of a postcondition
3484 else pragma Assert (Nam_In (Nam, Name_Postcondition,
3485 Name_Refined_Post));
3486 Check_Expression (Expr);
3488 end Check_Result_And_Post_State_In_Pragma;
3490 --------------------------
3491 -- Has_In_Out_Parameter --
3492 --------------------------
3494 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean is
3498 -- Traverse the formals looking for an IN OUT parameter
3500 Formal := First_Formal (Subp_Id);
3501 while Present (Formal) loop
3502 if Ekind (Formal) = E_In_Out_Parameter then
3506 Next_Formal (Formal);
3510 end Has_In_Out_Parameter;
3514 Items : constant Node_Id := Contract (Subp_Id);
3515 Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id);
3516 Case_Prag : Node_Id := Empty;
3517 Post_Prag : Node_Id := Empty;
3519 Seen_In_Case : Boolean := False;
3520 Seen_In_Post : Boolean := False;
3521 Spec_Id : Entity_Id;
3523 -- Start of processing for Check_Result_And_Post_State
3526 -- The lack of attribute 'Result or a post-state is classified as a
3527 -- suspicious contract. Do not perform the check if the corresponding
3528 -- swich is not set.
3530 if not Warn_On_Suspicious_Contract then
3533 -- Nothing to do if there is no contract
3535 elsif No (Items) then
3539 -- Retrieve the entity of the subprogram spec (if any)
3541 if Nkind (Subp_Decl) = N_Subprogram_Body
3542 and then Present (Corresponding_Spec (Subp_Decl))
3544 Spec_Id := Corresponding_Spec (Subp_Decl);
3546 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
3547 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
3549 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
3555 -- Examine all postconditions for attribute 'Result and a post-state
3557 Prag := Pre_Post_Conditions (Items);
3558 while Present (Prag) loop
3559 if Nam_In (Pragma_Name (Prag), Name_Postcondition,
3561 and then not Error_Posted (Prag)
3564 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Post);
3567 Prag := Next_Pragma (Prag);
3570 -- Examine the contract cases of the subprogram for attribute 'Result
3571 -- and a post-state.
3573 Prag := Contract_Test_Cases (Items);
3574 while Present (Prag) loop
3575 if Pragma_Name (Prag) = Name_Contract_Cases
3576 and then not Error_Posted (Prag)
3579 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Case);
3582 Prag := Next_Pragma (Prag);
3585 -- Do not emit any errors if the subprogram is not a function
3587 if not Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
3590 -- Regardless of whether the function has postconditions or contract
3591 -- cases, or whether they mention attribute 'Result, an IN OUT formal
3592 -- parameter is always treated as a result.
3594 elsif Has_In_Out_Parameter (Spec_Id) then
3597 -- The function has both a postcondition and contract cases and they do
3598 -- not mention attribute 'Result.
3600 elsif Present (Case_Prag)
3601 and then not Seen_In_Case
3602 and then Present (Post_Prag)
3603 and then not Seen_In_Post
3606 ("neither postcondition nor contract cases mention function "
3607 & "result?T?", Post_Prag);
3609 -- The function has contract cases only and they do not mention
3610 -- attribute 'Result.
3612 elsif Present (Case_Prag) and then not Seen_In_Case then
3613 Error_Msg_N ("contract cases do not mention result?T?", Case_Prag);
3615 -- The function has postconditions only and they do not mention
3616 -- attribute 'Result.
3618 elsif Present (Post_Prag) and then not Seen_In_Post then
3620 ("postcondition does not mention function result?T?", Post_Prag);
3622 end Check_Result_And_Post_State;
3624 ------------------------------
3625 -- Check_Unprotected_Access --
3626 ------------------------------
3628 procedure Check_Unprotected_Access
3632 Cont_Encl_Typ : Entity_Id;
3633 Pref_Encl_Typ : Entity_Id;
3635 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
3636 -- Check whether Obj is a private component of a protected object.
3637 -- Return the protected type where the component resides, Empty
3640 function Is_Public_Operation return Boolean;
3641 -- Verify that the enclosing operation is callable from outside the
3642 -- protected object, to minimize false positives.
3644 ------------------------------
3645 -- Enclosing_Protected_Type --
3646 ------------------------------
3648 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
3650 if Is_Entity_Name (Obj) then
3652 Ent : Entity_Id := Entity (Obj);
3655 -- The object can be a renaming of a private component, use
3656 -- the original record component.
3658 if Is_Prival (Ent) then
3659 Ent := Prival_Link (Ent);
3662 if Is_Protected_Type (Scope (Ent)) then
3668 -- For indexed and selected components, recursively check the prefix
3670 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
3671 return Enclosing_Protected_Type (Prefix (Obj));
3673 -- The object does not denote a protected component
3678 end Enclosing_Protected_Type;
3680 -------------------------
3681 -- Is_Public_Operation --
3682 -------------------------
3684 function Is_Public_Operation return Boolean is
3690 while Present (S) and then S /= Pref_Encl_Typ loop
3691 if Scope (S) = Pref_Encl_Typ then
3692 E := First_Entity (Pref_Encl_Typ);
3694 and then E /= First_Private_Entity (Pref_Encl_Typ)
3708 end Is_Public_Operation;
3710 -- Start of processing for Check_Unprotected_Access
3713 if Nkind (Expr) = N_Attribute_Reference
3714 and then Attribute_Name (Expr) = Name_Unchecked_Access
3716 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
3717 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
3719 -- Check whether we are trying to export a protected component to a
3720 -- context with an equal or lower access level.
3722 if Present (Pref_Encl_Typ)
3723 and then No (Cont_Encl_Typ)
3724 and then Is_Public_Operation
3725 and then Scope_Depth (Pref_Encl_Typ) >=
3726 Object_Access_Level (Context)
3729 ("??possible unprotected access to protected data", Expr);
3732 end Check_Unprotected_Access;
3734 ------------------------------
3735 -- Check_Unused_Body_States --
3736 ------------------------------
3738 procedure Check_Unused_Body_States (Body_Id : Entity_Id) is
3739 procedure Process_Refinement_Clause
3742 -- Inspect all constituents of refinement clause Clause and remove any
3743 -- matches from body state list States.
3745 procedure Report_Unused_Body_States (States : Elist_Id);
3746 -- Emit errors for each abstract state or object found in list States
3748 -------------------------------
3749 -- Process_Refinement_Clause --
3750 -------------------------------
3752 procedure Process_Refinement_Clause
3756 procedure Process_Constituent (Constit : Node_Id);
3757 -- Remove constituent Constit from body state list States
3759 -------------------------
3760 -- Process_Constituent --
3761 -------------------------
3763 procedure Process_Constituent (Constit : Node_Id) is
3764 Constit_Id : Entity_Id;
3767 -- Guard against illegal constituents. Only abstract states and
3768 -- objects can appear on the right hand side of a refinement.
3770 if Is_Entity_Name (Constit) then
3771 Constit_Id := Entity_Of (Constit);
3773 if Present (Constit_Id)
3774 and then Ekind_In (Constit_Id, E_Abstract_State,
3778 Remove (States, Constit_Id);
3781 end Process_Constituent;
3787 -- Start of processing for Process_Refinement_Clause
3790 if Nkind (Clause) = N_Component_Association then
3791 Constit := Expression (Clause);
3793 -- Multiple constituents appear as an aggregate
3795 if Nkind (Constit) = N_Aggregate then
3796 Constit := First (Expressions (Constit));
3797 while Present (Constit) loop
3798 Process_Constituent (Constit);
3802 -- Various forms of a single constituent
3805 Process_Constituent (Constit);
3808 end Process_Refinement_Clause;
3810 -------------------------------
3811 -- Report_Unused_Body_States --
3812 -------------------------------
3814 procedure Report_Unused_Body_States (States : Elist_Id) is
3815 Posted : Boolean := False;
3816 State_Elmt : Elmt_Id;
3817 State_Id : Entity_Id;
3820 if Present (States) then
3821 State_Elmt := First_Elmt (States);
3822 while Present (State_Elmt) loop
3823 State_Id := Node (State_Elmt);
3825 -- Constants are part of the hidden state of a package, but the
3826 -- compiler cannot determine whether they have variable input
3827 -- (SPARK RM 7.1.1(2)) and cannot classify them properly as a
3828 -- hidden state. Do not emit an error when a constant does not
3829 -- participate in a state refinement, even though it acts as a
3832 if Ekind (State_Id) = E_Constant then
3835 -- Generate an error message of the form:
3837 -- body of package ... has unused hidden states
3838 -- abstract state ... defined at ...
3839 -- variable ... defined at ...
3845 ("body of package & has unused hidden states", Body_Id);
3848 Error_Msg_Sloc := Sloc (State_Id);
3850 if Ekind (State_Id) = E_Abstract_State then
3852 ("\abstract state & defined #", Body_Id, State_Id);
3855 SPARK_Msg_NE ("\variable & defined #", Body_Id, State_Id);
3859 Next_Elmt (State_Elmt);
3862 end Report_Unused_Body_States;
3866 Prag : constant Node_Id := Get_Pragma (Body_Id, Pragma_Refined_State);
3867 Spec_Id : constant Entity_Id := Spec_Entity (Body_Id);
3871 -- Start of processing for Check_Unused_Body_States
3874 -- Inspect the clauses of pragma Refined_State and determine whether all
3875 -- visible states declared within the package body participate in the
3878 if Present (Prag) then
3879 Clause := Expression (Get_Argument (Prag, Spec_Id));
3880 States := Collect_Body_States (Body_Id);
3882 -- Multiple non-null state refinements appear as an aggregate
3884 if Nkind (Clause) = N_Aggregate then
3885 Clause := First (Component_Associations (Clause));
3886 while Present (Clause) loop
3887 Process_Refinement_Clause (Clause, States);
3891 -- Various forms of a single state refinement
3894 Process_Refinement_Clause (Clause, States);
3897 -- Ensure that all abstract states and objects declared in the
3898 -- package body state space are utilized as constituents.
3900 Report_Unused_Body_States (States);
3902 end Check_Unused_Body_States;
3904 -------------------------
3905 -- Collect_Body_States --
3906 -------------------------
3908 function Collect_Body_States (Body_Id : Entity_Id) return Elist_Id is
3909 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean;
3910 -- Determine whether object Obj_Id is a suitable visible state of a
3913 procedure Collect_Visible_States
3914 (Pack_Id : Entity_Id;
3915 States : in out Elist_Id);
3916 -- Gather the entities of all abstract states and objects declared in
3917 -- the visible state space of package Pack_Id.
3919 ----------------------------
3920 -- Collect_Visible_States --
3921 ----------------------------
3923 procedure Collect_Visible_States
3924 (Pack_Id : Entity_Id;
3925 States : in out Elist_Id)
3927 Item_Id : Entity_Id;
3930 -- Traverse the entity chain of the package and inspect all visible
3933 Item_Id := First_Entity (Pack_Id);
3934 while Present (Item_Id) and then not In_Private_Part (Item_Id) loop
3936 -- Do not consider internally generated items as those cannot be
3937 -- named and participate in refinement.
3939 if not Comes_From_Source (Item_Id) then
3942 elsif Ekind (Item_Id) = E_Abstract_State then
3943 Append_New_Elmt (Item_Id, States);
3945 elsif Ekind_In (Item_Id, E_Constant, E_Variable)
3946 and then Is_Visible_Object (Item_Id)
3948 Append_New_Elmt (Item_Id, States);
3950 -- Recursively gather the visible states of a nested package
3952 elsif Ekind (Item_Id) = E_Package then
3953 Collect_Visible_States (Item_Id, States);
3956 Next_Entity (Item_Id);
3958 end Collect_Visible_States;
3960 -----------------------
3961 -- Is_Visible_Object --
3962 -----------------------
3964 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean is
3966 -- Objects that map generic formals to their actuals are not visible
3967 -- from outside the generic instantiation.
3969 if Present (Corresponding_Generic_Association
3970 (Declaration_Node (Obj_Id)))
3974 -- Constituents of a single protected/task type act as components of
3975 -- the type and are not visible from outside the type.
3977 elsif Ekind (Obj_Id) = E_Variable
3978 and then Present (Encapsulating_State (Obj_Id))
3979 and then Is_Single_Concurrent_Object (Encapsulating_State (Obj_Id))
3986 end Is_Visible_Object;
3990 Body_Decl : constant Node_Id := Unit_Declaration_Node (Body_Id);
3992 Item_Id : Entity_Id;
3993 States : Elist_Id := No_Elist;
3995 -- Start of processing for Collect_Body_States
3998 -- Inspect the declarations of the body looking for source objects,
3999 -- packages and package instantiations. Note that even though this
4000 -- processing is very similar to Collect_Visible_States, a package
4001 -- body does not have a First/Next_Entity list.
4003 Decl := First (Declarations (Body_Decl));
4004 while Present (Decl) loop
4006 -- Capture source objects as internally generated temporaries cannot
4007 -- be named and participate in refinement.
4009 if Nkind (Decl) = N_Object_Declaration then
4010 Item_Id := Defining_Entity (Decl);
4012 if Comes_From_Source (Item_Id)
4013 and then Is_Visible_Object (Item_Id)
4015 Append_New_Elmt (Item_Id, States);
4018 -- Capture the visible abstract states and objects of a source
4019 -- package [instantiation].
4021 elsif Nkind (Decl) = N_Package_Declaration then
4022 Item_Id := Defining_Entity (Decl);
4024 if Comes_From_Source (Item_Id) then
4025 Collect_Visible_States (Item_Id, States);
4033 end Collect_Body_States;
4035 ------------------------
4036 -- Collect_Interfaces --
4037 ------------------------
4039 procedure Collect_Interfaces
4041 Ifaces_List : out Elist_Id;
4042 Exclude_Parents : Boolean := False;
4043 Use_Full_View : Boolean := True)
4045 procedure Collect (Typ : Entity_Id);
4046 -- Subsidiary subprogram used to traverse the whole list
4047 -- of directly and indirectly implemented interfaces
4053 procedure Collect (Typ : Entity_Id) is
4054 Ancestor : Entity_Id;
4062 -- Handle private types and subtypes
4065 and then Is_Private_Type (Typ)
4066 and then Present (Full_View (Typ))
4068 Full_T := Full_View (Typ);
4070 if Ekind (Full_T) = E_Record_Subtype then
4071 Full_T := Full_View (Etype (Typ));
4075 -- Include the ancestor if we are generating the whole list of
4076 -- abstract interfaces.
4078 if Etype (Full_T) /= Typ
4080 -- Protect the frontend against wrong sources. For example:
4083 -- type A is tagged null record;
4084 -- type B is new A with private;
4085 -- type C is new A with private;
4087 -- type B is new C with null record;
4088 -- type C is new B with null record;
4091 and then Etype (Full_T) /= T
4093 Ancestor := Etype (Full_T);
4096 if Is_Interface (Ancestor) and then not Exclude_Parents then
4097 Append_Unique_Elmt (Ancestor, Ifaces_List);
4101 -- Traverse the graph of ancestor interfaces
4103 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
4104 Id := First (Abstract_Interface_List (Full_T));
4105 while Present (Id) loop
4106 Iface := Etype (Id);
4108 -- Protect against wrong uses. For example:
4109 -- type I is interface;
4110 -- type O is tagged null record;
4111 -- type Wrong is new I and O with null record; -- ERROR
4113 if Is_Interface (Iface) then
4115 and then Etype (T) /= T
4116 and then Interface_Present_In_Ancestor (Etype (T), Iface)
4121 Append_Unique_Elmt (Iface, Ifaces_List);
4130 -- Start of processing for Collect_Interfaces
4133 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
4134 Ifaces_List := New_Elmt_List;
4136 end Collect_Interfaces;
4138 ----------------------------------
4139 -- Collect_Interface_Components --
4140 ----------------------------------
4142 procedure Collect_Interface_Components
4143 (Tagged_Type : Entity_Id;
4144 Components_List : out Elist_Id)
4146 procedure Collect (Typ : Entity_Id);
4147 -- Subsidiary subprogram used to climb to the parents
4153 procedure Collect (Typ : Entity_Id) is
4154 Tag_Comp : Entity_Id;
4155 Parent_Typ : Entity_Id;
4158 -- Handle private types
4160 if Present (Full_View (Etype (Typ))) then
4161 Parent_Typ := Full_View (Etype (Typ));
4163 Parent_Typ := Etype (Typ);
4166 if Parent_Typ /= Typ
4168 -- Protect the frontend against wrong sources. For example:
4171 -- type A is tagged null record;
4172 -- type B is new A with private;
4173 -- type C is new A with private;
4175 -- type B is new C with null record;
4176 -- type C is new B with null record;
4179 and then Parent_Typ /= Tagged_Type
4181 Collect (Parent_Typ);
4184 -- Collect the components containing tags of secondary dispatch
4187 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
4188 while Present (Tag_Comp) loop
4189 pragma Assert (Present (Related_Type (Tag_Comp)));
4190 Append_Elmt (Tag_Comp, Components_List);
4192 Tag_Comp := Next_Tag_Component (Tag_Comp);
4196 -- Start of processing for Collect_Interface_Components
4199 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
4200 and then Is_Tagged_Type (Tagged_Type));
4202 Components_List := New_Elmt_List;
4203 Collect (Tagged_Type);
4204 end Collect_Interface_Components;
4206 -----------------------------
4207 -- Collect_Interfaces_Info --
4208 -----------------------------
4210 procedure Collect_Interfaces_Info
4212 Ifaces_List : out Elist_Id;
4213 Components_List : out Elist_Id;
4214 Tags_List : out Elist_Id)
4216 Comps_List : Elist_Id;
4217 Comp_Elmt : Elmt_Id;
4218 Comp_Iface : Entity_Id;
4219 Iface_Elmt : Elmt_Id;
4222 function Search_Tag (Iface : Entity_Id) return Entity_Id;
4223 -- Search for the secondary tag associated with the interface type
4224 -- Iface that is implemented by T.
4230 function Search_Tag (Iface : Entity_Id) return Entity_Id is
4233 if not Is_CPP_Class (T) then
4234 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
4236 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
4240 and then Is_Tag (Node (ADT))
4241 and then Related_Type (Node (ADT)) /= Iface
4243 -- Skip secondary dispatch table referencing thunks to user
4244 -- defined primitives covered by this interface.
4246 pragma Assert (Has_Suffix (Node (ADT), 'P'));
4249 -- Skip secondary dispatch tables of Ada types
4251 if not Is_CPP_Class (T) then
4253 -- Skip secondary dispatch table referencing thunks to
4254 -- predefined primitives.
4256 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
4259 -- Skip secondary dispatch table referencing user-defined
4260 -- primitives covered by this interface.
4262 pragma Assert (Has_Suffix (Node (ADT), 'D'));
4265 -- Skip secondary dispatch table referencing predefined
4268 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
4273 pragma Assert (Is_Tag (Node (ADT)));
4277 -- Start of processing for Collect_Interfaces_Info
4280 Collect_Interfaces (T, Ifaces_List);
4281 Collect_Interface_Components (T, Comps_List);
4283 -- Search for the record component and tag associated with each
4284 -- interface type of T.
4286 Components_List := New_Elmt_List;
4287 Tags_List := New_Elmt_List;
4289 Iface_Elmt := First_Elmt (Ifaces_List);
4290 while Present (Iface_Elmt) loop
4291 Iface := Node (Iface_Elmt);
4293 -- Associate the primary tag component and the primary dispatch table
4294 -- with all the interfaces that are parents of T
4296 if Is_Ancestor (Iface, T, Use_Full_View => True) then
4297 Append_Elmt (First_Tag_Component (T), Components_List);
4298 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
4300 -- Otherwise search for the tag component and secondary dispatch
4304 Comp_Elmt := First_Elmt (Comps_List);
4305 while Present (Comp_Elmt) loop
4306 Comp_Iface := Related_Type (Node (Comp_Elmt));
4308 if Comp_Iface = Iface
4309 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
4311 Append_Elmt (Node (Comp_Elmt), Components_List);
4312 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
4316 Next_Elmt (Comp_Elmt);
4318 pragma Assert (Present (Comp_Elmt));
4321 Next_Elmt (Iface_Elmt);
4323 end Collect_Interfaces_Info;
4325 ---------------------
4326 -- Collect_Parents --
4327 ---------------------
4329 procedure Collect_Parents
4331 List : out Elist_Id;
4332 Use_Full_View : Boolean := True)
4334 Current_Typ : Entity_Id := T;
4335 Parent_Typ : Entity_Id;
4338 List := New_Elmt_List;
4340 -- No action if the if the type has no parents
4342 if T = Etype (T) then
4347 Parent_Typ := Etype (Current_Typ);
4349 if Is_Private_Type (Parent_Typ)
4350 and then Present (Full_View (Parent_Typ))
4351 and then Use_Full_View
4353 Parent_Typ := Full_View (Base_Type (Parent_Typ));
4356 Append_Elmt (Parent_Typ, List);
4358 exit when Parent_Typ = Current_Typ;
4359 Current_Typ := Parent_Typ;
4361 end Collect_Parents;
4363 ----------------------------------
4364 -- Collect_Primitive_Operations --
4365 ----------------------------------
4367 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
4368 B_Type : constant Entity_Id := Base_Type (T);
4369 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
4370 B_Scope : Entity_Id := Scope (B_Type);
4374 Is_Type_In_Pkg : Boolean;
4375 Formal_Derived : Boolean := False;
4378 function Match (E : Entity_Id) return Boolean;
4379 -- True if E's base type is B_Type, or E is of an anonymous access type
4380 -- and the base type of its designated type is B_Type.
4386 function Match (E : Entity_Id) return Boolean is
4387 Etyp : Entity_Id := Etype (E);
4390 if Ekind (Etyp) = E_Anonymous_Access_Type then
4391 Etyp := Designated_Type (Etyp);
4394 -- In Ada 2012 a primitive operation may have a formal of an
4395 -- incomplete view of the parent type.
4397 return Base_Type (Etyp) = B_Type
4399 (Ada_Version >= Ada_2012
4400 and then Ekind (Etyp) = E_Incomplete_Type
4401 and then Full_View (Etyp) = B_Type);
4404 -- Start of processing for Collect_Primitive_Operations
4407 -- For tagged types, the primitive operations are collected as they
4408 -- are declared, and held in an explicit list which is simply returned.
4410 if Is_Tagged_Type (B_Type) then
4411 return Primitive_Operations (B_Type);
4413 -- An untagged generic type that is a derived type inherits the
4414 -- primitive operations of its parent type. Other formal types only
4415 -- have predefined operators, which are not explicitly represented.
4417 elsif Is_Generic_Type (B_Type) then
4418 if Nkind (B_Decl) = N_Formal_Type_Declaration
4419 and then Nkind (Formal_Type_Definition (B_Decl)) =
4420 N_Formal_Derived_Type_Definition
4422 Formal_Derived := True;
4424 return New_Elmt_List;
4428 Op_List := New_Elmt_List;
4430 if B_Scope = Standard_Standard then
4431 if B_Type = Standard_String then
4432 Append_Elmt (Standard_Op_Concat, Op_List);
4434 elsif B_Type = Standard_Wide_String then
4435 Append_Elmt (Standard_Op_Concatw, Op_List);
4441 -- Locate the primitive subprograms of the type
4444 -- The primitive operations appear after the base type, except
4445 -- if the derivation happens within the private part of B_Scope
4446 -- and the type is a private type, in which case both the type
4447 -- and some primitive operations may appear before the base
4448 -- type, and the list of candidates starts after the type.
4450 if In_Open_Scopes (B_Scope)
4451 and then Scope (T) = B_Scope
4452 and then In_Private_Part (B_Scope)
4454 Id := Next_Entity (T);
4456 -- In Ada 2012, If the type has an incomplete partial view, there
4457 -- may be primitive operations declared before the full view, so
4458 -- we need to start scanning from the incomplete view, which is
4459 -- earlier on the entity chain.
4461 elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration
4462 and then Present (Incomplete_View (Parent (B_Type)))
4464 Id := Defining_Entity (Incomplete_View (Parent (B_Type)));
4466 -- If T is a derived from a type with an incomplete view declared
4467 -- elsewhere, that incomplete view is irrelevant, we want the
4468 -- operations in the scope of T.
4470 if Scope (Id) /= Scope (B_Type) then
4471 Id := Next_Entity (B_Type);
4475 Id := Next_Entity (B_Type);
4478 -- Set flag if this is a type in a package spec
4481 Is_Package_Or_Generic_Package (B_Scope)
4483 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
4486 while Present (Id) loop
4488 -- Test whether the result type or any of the parameter types of
4489 -- each subprogram following the type match that type when the
4490 -- type is declared in a package spec, is a derived type, or the
4491 -- subprogram is marked as primitive. (The Is_Primitive test is
4492 -- needed to find primitives of nonderived types in declarative
4493 -- parts that happen to override the predefined "=" operator.)
4495 -- Note that generic formal subprograms are not considered to be
4496 -- primitive operations and thus are never inherited.
4498 if Is_Overloadable (Id)
4499 and then (Is_Type_In_Pkg
4500 or else Is_Derived_Type (B_Type)
4501 or else Is_Primitive (Id))
4502 and then Nkind (Parent (Parent (Id)))
4503 not in N_Formal_Subprogram_Declaration
4511 Formal := First_Formal (Id);
4512 while Present (Formal) loop
4513 if Match (Formal) then
4518 Next_Formal (Formal);
4522 -- For a formal derived type, the only primitives are the ones
4523 -- inherited from the parent type. Operations appearing in the
4524 -- package declaration are not primitive for it.
4527 and then (not Formal_Derived or else Present (Alias (Id)))
4529 -- In the special case of an equality operator aliased to
4530 -- an overriding dispatching equality belonging to the same
4531 -- type, we don't include it in the list of primitives.
4532 -- This avoids inheriting multiple equality operators when
4533 -- deriving from untagged private types whose full type is
4534 -- tagged, which can otherwise cause ambiguities. Note that
4535 -- this should only happen for this kind of untagged parent
4536 -- type, since normally dispatching operations are inherited
4537 -- using the type's Primitive_Operations list.
4539 if Chars (Id) = Name_Op_Eq
4540 and then Is_Dispatching_Operation (Id)
4541 and then Present (Alias (Id))
4542 and then Present (Overridden_Operation (Alias (Id)))
4543 and then Base_Type (Etype (First_Entity (Id))) =
4544 Base_Type (Etype (First_Entity (Alias (Id))))
4548 -- Include the subprogram in the list of primitives
4551 Append_Elmt (Id, Op_List);
4558 -- For a type declared in System, some of its operations may
4559 -- appear in the target-specific extension to System.
4562 and then B_Scope = RTU_Entity (System)
4563 and then Present_System_Aux
4565 B_Scope := System_Aux_Id;
4566 Id := First_Entity (System_Aux_Id);
4572 end Collect_Primitive_Operations;
4574 -----------------------------------
4575 -- Compile_Time_Constraint_Error --
4576 -----------------------------------
4578 function Compile_Time_Constraint_Error
4581 Ent : Entity_Id := Empty;
4582 Loc : Source_Ptr := No_Location;
4583 Warn : Boolean := False) return Node_Id
4585 Msgc : String (1 .. Msg'Length + 3);
4586 -- Copy of message, with room for possible ?? or << and ! at end
4592 -- Start of processing for Compile_Time_Constraint_Error
4595 -- If this is a warning, convert it into an error if we are in code
4596 -- subject to SPARK_Mode being set On, unless Warn is True to force a
4597 -- warning. The rationale is that a compile-time constraint error should
4598 -- lead to an error instead of a warning when SPARK_Mode is On, but in
4599 -- a few cases we prefer to issue a warning and generate both a suitable
4600 -- run-time error in GNAT and a suitable check message in GNATprove.
4601 -- Those cases are those that likely correspond to deactivated SPARK
4602 -- code, so that this kind of code can be compiled and analyzed instead
4603 -- of being rejected.
4605 Error_Msg_Warn := Warn or SPARK_Mode /= On;
4607 -- A static constraint error in an instance body is not a fatal error.
4608 -- we choose to inhibit the message altogether, because there is no
4609 -- obvious node (for now) on which to post it. On the other hand the
4610 -- offending node must be replaced with a constraint_error in any case.
4612 -- No messages are generated if we already posted an error on this node
4614 if not Error_Posted (N) then
4615 if Loc /= No_Location then
4621 -- Copy message to Msgc, converting any ? in the message into
4622 -- < instead, so that we have an error in GNATprove mode.
4626 for J in 1 .. Msgl loop
4627 if Msg (J) = '?' and then (J = 1 or else Msg (J) /= ''') then
4630 Msgc (J) := Msg (J);
4634 -- Message is a warning, even in Ada 95 case
4636 if Msg (Msg'Last) = '?' or else Msg (Msg'Last) = '<' then
4639 -- In Ada 83, all messages are warnings. In the private part and
4640 -- the body of an instance, constraint_checks are only warnings.
4641 -- We also make this a warning if the Warn parameter is set.
4644 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
4652 elsif In_Instance_Not_Visible then
4659 -- Otherwise we have a real error message (Ada 95 static case)
4660 -- and we make this an unconditional message. Note that in the
4661 -- warning case we do not make the message unconditional, it seems
4662 -- quite reasonable to delete messages like this (about exceptions
4663 -- that will be raised) in dead code.
4671 -- One more test, skip the warning if the related expression is
4672 -- statically unevaluated, since we don't want to warn about what
4673 -- will happen when something is evaluated if it never will be
4676 if not Is_Statically_Unevaluated (N) then
4677 if Present (Ent) then
4678 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
4680 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
4685 -- Check whether the context is an Init_Proc
4687 if Inside_Init_Proc then
4689 Conc_Typ : constant Entity_Id :=
4690 Corresponding_Concurrent_Type
4691 (Entity (Parameter_Type (First
4692 (Parameter_Specifications
4693 (Parent (Current_Scope))))));
4696 -- Don't complain if the corresponding concurrent type
4697 -- doesn't come from source (i.e. a single task/protected
4700 if Present (Conc_Typ)
4701 and then not Comes_From_Source (Conc_Typ)
4704 ("\& [<<", N, Standard_Constraint_Error, Eloc);
4707 if GNATprove_Mode then
4709 ("\& would have been raised for objects of this "
4710 & "type", N, Standard_Constraint_Error, Eloc);
4713 ("\& will be raised for objects of this type??",
4714 N, Standard_Constraint_Error, Eloc);
4720 Error_Msg_NEL ("\& [<<", N, Standard_Constraint_Error, Eloc);
4724 Error_Msg ("\static expression fails Constraint_Check", Eloc);
4725 Set_Error_Posted (N);
4731 end Compile_Time_Constraint_Error;
4733 -----------------------
4734 -- Conditional_Delay --
4735 -----------------------
4737 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
4739 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
4740 Set_Has_Delayed_Freeze (New_Ent);
4742 end Conditional_Delay;
4744 ----------------------------
4745 -- Contains_Refined_State --
4746 ----------------------------
4748 function Contains_Refined_State (Prag : Node_Id) return Boolean is
4749 function Has_State_In_Dependency (List : Node_Id) return Boolean;
4750 -- Determine whether a dependency list mentions a state with a visible
4753 function Has_State_In_Global (List : Node_Id) return Boolean;
4754 -- Determine whether a global list mentions a state with a visible
4757 function Is_Refined_State (Item : Node_Id) return Boolean;
4758 -- Determine whether Item is a reference to an abstract state with a
4759 -- visible refinement.
4761 -----------------------------
4762 -- Has_State_In_Dependency --
4763 -----------------------------
4765 function Has_State_In_Dependency (List : Node_Id) return Boolean is
4770 -- A null dependency list does not mention any states
4772 if Nkind (List) = N_Null then
4775 -- Dependency clauses appear as component associations of an
4778 elsif Nkind (List) = N_Aggregate
4779 and then Present (Component_Associations (List))
4781 Clause := First (Component_Associations (List));
4782 while Present (Clause) loop
4784 -- Inspect the outputs of a dependency clause
4786 Output := First (Choices (Clause));
4787 while Present (Output) loop
4788 if Is_Refined_State (Output) then
4795 -- Inspect the outputs of a dependency clause
4797 if Is_Refined_State (Expression (Clause)) then
4804 -- If we get here, then none of the dependency clauses mention a
4805 -- state with visible refinement.
4809 -- An illegal pragma managed to sneak in
4812 raise Program_Error;
4814 end Has_State_In_Dependency;
4816 -------------------------
4817 -- Has_State_In_Global --
4818 -------------------------
4820 function Has_State_In_Global (List : Node_Id) return Boolean is
4824 -- A null global list does not mention any states
4826 if Nkind (List) = N_Null then
4829 -- Simple global list or moded global list declaration
4831 elsif Nkind (List) = N_Aggregate then
4833 -- The declaration of a simple global list appear as a collection
4836 if Present (Expressions (List)) then
4837 Item := First (Expressions (List));
4838 while Present (Item) loop
4839 if Is_Refined_State (Item) then
4846 -- The declaration of a moded global list appears as a collection
4847 -- of component associations where individual choices denote
4851 Item := First (Component_Associations (List));
4852 while Present (Item) loop
4853 if Has_State_In_Global (Expression (Item)) then
4861 -- If we get here, then the simple/moded global list did not
4862 -- mention any states with a visible refinement.
4866 -- Single global item declaration
4868 elsif Is_Entity_Name (List) then
4869 return Is_Refined_State (List);
4871 -- An illegal pragma managed to sneak in
4874 raise Program_Error;
4876 end Has_State_In_Global;
4878 ----------------------
4879 -- Is_Refined_State --
4880 ----------------------
4882 function Is_Refined_State (Item : Node_Id) return Boolean is
4884 Item_Id : Entity_Id;
4887 if Nkind (Item) = N_Null then
4890 -- States cannot be subject to attribute 'Result. This case arises
4891 -- in dependency relations.
4893 elsif Nkind (Item) = N_Attribute_Reference
4894 and then Attribute_Name (Item) = Name_Result
4898 -- Multiple items appear as an aggregate. This case arises in
4899 -- dependency relations.
4901 elsif Nkind (Item) = N_Aggregate
4902 and then Present (Expressions (Item))
4904 Elmt := First (Expressions (Item));
4905 while Present (Elmt) loop
4906 if Is_Refined_State (Elmt) then
4913 -- If we get here, then none of the inputs or outputs reference a
4914 -- state with visible refinement.
4921 Item_Id := Entity_Of (Item);
4925 and then Ekind (Item_Id) = E_Abstract_State
4926 and then Has_Visible_Refinement (Item_Id);
4928 end Is_Refined_State;
4932 Arg : constant Node_Id :=
4933 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
4934 Nam : constant Name_Id := Pragma_Name (Prag);
4936 -- Start of processing for Contains_Refined_State
4939 if Nam = Name_Depends then
4940 return Has_State_In_Dependency (Arg);
4942 else pragma Assert (Nam = Name_Global);
4943 return Has_State_In_Global (Arg);
4945 end Contains_Refined_State;
4947 -------------------------
4948 -- Copy_Component_List --
4949 -------------------------
4951 function Copy_Component_List
4953 Loc : Source_Ptr) return List_Id
4956 Comps : constant List_Id := New_List;
4959 Comp := First_Component (Underlying_Type (R_Typ));
4960 while Present (Comp) loop
4961 if Comes_From_Source (Comp) then
4963 Comp_Decl : constant Node_Id := Declaration_Node (Comp);
4966 Make_Component_Declaration (Loc,
4967 Defining_Identifier =>
4968 Make_Defining_Identifier (Loc, Chars (Comp)),
4969 Component_Definition =>
4971 (Component_Definition (Comp_Decl), New_Sloc => Loc)));
4975 Next_Component (Comp);
4979 end Copy_Component_List;
4981 -------------------------
4982 -- Copy_Parameter_List --
4983 -------------------------
4985 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
4986 Loc : constant Source_Ptr := Sloc (Subp_Id);
4991 if No (First_Formal (Subp_Id)) then
4995 Formal := First_Formal (Subp_Id);
4996 while Present (Formal) loop
4998 Make_Parameter_Specification (Loc,
4999 Defining_Identifier =>
5000 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
5001 In_Present => In_Present (Parent (Formal)),
5002 Out_Present => Out_Present (Parent (Formal)),
5004 New_Occurrence_Of (Etype (Formal), Loc),
5006 New_Copy_Tree (Expression (Parent (Formal)))));
5008 Next_Formal (Formal);
5013 end Copy_Parameter_List;
5015 --------------------------
5016 -- Copy_Subprogram_Spec --
5017 --------------------------
5019 function Copy_Subprogram_Spec (Spec : Node_Id) return Node_Id is
5021 Formal_Spec : Node_Id;
5025 -- The structure of the original tree must be replicated without any
5026 -- alterations. Use New_Copy_Tree for this purpose.
5028 Result := New_Copy_Tree (Spec);
5030 -- Create a new entity for the defining unit name
5032 Def_Id := Defining_Unit_Name (Result);
5033 Set_Defining_Unit_Name (Result,
5034 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
5036 -- Create new entities for the formal parameters
5038 if Present (Parameter_Specifications (Result)) then
5039 Formal_Spec := First (Parameter_Specifications (Result));
5040 while Present (Formal_Spec) loop
5041 Def_Id := Defining_Identifier (Formal_Spec);
5042 Set_Defining_Identifier (Formal_Spec,
5043 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
5050 end Copy_Subprogram_Spec;
5052 --------------------------------
5053 -- Corresponding_Generic_Type --
5054 --------------------------------
5056 function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id is
5062 if not Is_Generic_Actual_Type (T) then
5065 -- If the actual is the actual of an enclosing instance, resolution
5066 -- was correct in the generic.
5068 elsif Nkind (Parent (T)) = N_Subtype_Declaration
5069 and then Is_Entity_Name (Subtype_Indication (Parent (T)))
5071 Is_Generic_Actual_Type (Entity (Subtype_Indication (Parent (T))))
5078 if Is_Wrapper_Package (Inst) then
5079 Inst := Related_Instance (Inst);
5084 (Specification (Unit_Declaration_Node (Inst)));
5086 -- Generic actual has the same name as the corresponding formal
5088 Typ := First_Entity (Gen);
5089 while Present (Typ) loop
5090 if Chars (Typ) = Chars (T) then
5099 end Corresponding_Generic_Type;
5101 --------------------
5102 -- Current_Entity --
5103 --------------------
5105 -- The currently visible definition for a given identifier is the
5106 -- one most chained at the start of the visibility chain, i.e. the
5107 -- one that is referenced by the Node_Id value of the name of the
5108 -- given identifier.
5110 function Current_Entity (N : Node_Id) return Entity_Id is
5112 return Get_Name_Entity_Id (Chars (N));
5115 -----------------------------
5116 -- Current_Entity_In_Scope --
5117 -----------------------------
5119 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
5121 CS : constant Entity_Id := Current_Scope;
5123 Transient_Case : constant Boolean := Scope_Is_Transient;
5126 E := Get_Name_Entity_Id (Chars (N));
5128 and then Scope (E) /= CS
5129 and then (not Transient_Case or else Scope (E) /= Scope (CS))
5135 end Current_Entity_In_Scope;
5141 function Current_Scope return Entity_Id is
5143 if Scope_Stack.Last = -1 then
5144 return Standard_Standard;
5147 C : constant Entity_Id :=
5148 Scope_Stack.Table (Scope_Stack.Last).Entity;
5153 return Standard_Standard;
5159 ----------------------------
5160 -- Current_Scope_No_Loops --
5161 ----------------------------
5163 function Current_Scope_No_Loops return Entity_Id is
5167 -- Examine the scope stack starting from the current scope and skip any
5168 -- internally generated loops.
5171 while Present (S) and then S /= Standard_Standard loop
5172 if Ekind (S) = E_Loop and then not Comes_From_Source (S) then
5180 end Current_Scope_No_Loops;
5182 ------------------------
5183 -- Current_Subprogram --
5184 ------------------------
5186 function Current_Subprogram return Entity_Id is
5187 Scop : constant Entity_Id := Current_Scope;
5189 if Is_Subprogram_Or_Generic_Subprogram (Scop) then
5192 return Enclosing_Subprogram (Scop);
5194 end Current_Subprogram;
5196 ----------------------------------
5197 -- Deepest_Type_Access_Level --
5198 ----------------------------------
5200 function Deepest_Type_Access_Level (Typ : Entity_Id) return Uint is
5202 if Ekind (Typ) = E_Anonymous_Access_Type
5203 and then not Is_Local_Anonymous_Access (Typ)
5204 and then Nkind (Associated_Node_For_Itype (Typ)) = N_Object_Declaration
5206 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
5210 Scope_Depth (Enclosing_Dynamic_Scope
5211 (Defining_Identifier
5212 (Associated_Node_For_Itype (Typ))));
5214 -- For generic formal type, return Int'Last (infinite).
5215 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
5217 elsif Is_Generic_Type (Root_Type (Typ)) then
5218 return UI_From_Int (Int'Last);
5221 return Type_Access_Level (Typ);
5223 end Deepest_Type_Access_Level;
5225 ---------------------
5226 -- Defining_Entity --
5227 ---------------------
5229 function Defining_Entity
5231 Empty_On_Errors : Boolean := False) return Entity_Id
5233 Err : Entity_Id := Empty;
5237 when N_Abstract_Subprogram_Declaration |
5238 N_Expression_Function |
5239 N_Formal_Subprogram_Declaration |
5240 N_Generic_Package_Declaration |
5241 N_Generic_Subprogram_Declaration |
5242 N_Package_Declaration |
5244 N_Subprogram_Body_Stub |
5245 N_Subprogram_Declaration |
5246 N_Subprogram_Renaming_Declaration
5248 return Defining_Entity (Specification (N));
5250 when N_Component_Declaration |
5251 N_Defining_Program_Unit_Name |
5252 N_Discriminant_Specification |
5254 N_Entry_Declaration |
5255 N_Entry_Index_Specification |
5256 N_Exception_Declaration |
5257 N_Exception_Renaming_Declaration |
5258 N_Formal_Object_Declaration |
5259 N_Formal_Package_Declaration |
5260 N_Formal_Type_Declaration |
5261 N_Full_Type_Declaration |
5262 N_Implicit_Label_Declaration |
5263 N_Incomplete_Type_Declaration |
5264 N_Loop_Parameter_Specification |
5265 N_Number_Declaration |
5266 N_Object_Declaration |
5267 N_Object_Renaming_Declaration |
5268 N_Package_Body_Stub |
5269 N_Parameter_Specification |
5270 N_Private_Extension_Declaration |
5271 N_Private_Type_Declaration |
5273 N_Protected_Body_Stub |
5274 N_Protected_Type_Declaration |
5275 N_Single_Protected_Declaration |
5276 N_Single_Task_Declaration |
5277 N_Subtype_Declaration |
5280 N_Task_Type_Declaration
5282 return Defining_Identifier (N);
5285 return Defining_Entity (Proper_Body (N));
5287 when N_Function_Instantiation |
5288 N_Function_Specification |
5289 N_Generic_Function_Renaming_Declaration |
5290 N_Generic_Package_Renaming_Declaration |
5291 N_Generic_Procedure_Renaming_Declaration |
5293 N_Package_Instantiation |
5294 N_Package_Renaming_Declaration |
5295 N_Package_Specification |
5296 N_Procedure_Instantiation |
5297 N_Procedure_Specification
5300 Nam : constant Node_Id := Defining_Unit_Name (N);
5303 if Nkind (Nam) in N_Entity then
5306 -- For Error, make up a name and attach to declaration so we
5307 -- can continue semantic analysis.
5309 elsif Nam = Error then
5310 if Empty_On_Errors then
5313 Err := Make_Temporary (Sloc (N), 'T');
5314 Set_Defining_Unit_Name (N, Err);
5319 -- If not an entity, get defining identifier
5322 return Defining_Identifier (Nam);
5326 when N_Block_Statement |
5328 return Entity (Identifier (N));
5331 if Empty_On_Errors then
5334 raise Program_Error;
5338 end Defining_Entity;
5340 --------------------------
5341 -- Denotes_Discriminant --
5342 --------------------------
5344 function Denotes_Discriminant
5346 Check_Concurrent : Boolean := False) return Boolean
5351 if not Is_Entity_Name (N) or else No (Entity (N)) then
5357 -- If we are checking for a protected type, the discriminant may have
5358 -- been rewritten as the corresponding discriminal of the original type
5359 -- or of the corresponding concurrent record, depending on whether we
5360 -- are in the spec or body of the protected type.
5362 return Ekind (E) = E_Discriminant
5365 and then Ekind (E) = E_In_Parameter
5366 and then Present (Discriminal_Link (E))
5368 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
5370 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
5371 end Denotes_Discriminant;
5373 -------------------------
5374 -- Denotes_Same_Object --
5375 -------------------------
5377 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
5378 Obj1 : Node_Id := A1;
5379 Obj2 : Node_Id := A2;
5381 function Has_Prefix (N : Node_Id) return Boolean;
5382 -- Return True if N has attribute Prefix
5384 function Is_Renaming (N : Node_Id) return Boolean;
5385 -- Return true if N names a renaming entity
5387 function Is_Valid_Renaming (N : Node_Id) return Boolean;
5388 -- For renamings, return False if the prefix of any dereference within
5389 -- the renamed object_name is a variable, or any expression within the
5390 -- renamed object_name contains references to variables or calls on
5391 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
5397 function Has_Prefix (N : Node_Id) return Boolean is
5401 N_Attribute_Reference,
5403 N_Explicit_Dereference,
5404 N_Indexed_Component,
5406 N_Selected_Component,
5414 function Is_Renaming (N : Node_Id) return Boolean is
5416 return Is_Entity_Name (N)
5417 and then Present (Renamed_Entity (Entity (N)));
5420 -----------------------
5421 -- Is_Valid_Renaming --
5422 -----------------------
5424 function Is_Valid_Renaming (N : Node_Id) return Boolean is
5426 function Check_Renaming (N : Node_Id) return Boolean;
5427 -- Recursive function used to traverse all the prefixes of N
5429 function Check_Renaming (N : Node_Id) return Boolean is
5432 and then not Check_Renaming (Renamed_Entity (Entity (N)))
5437 if Nkind (N) = N_Indexed_Component then
5442 Indx := First (Expressions (N));
5443 while Present (Indx) loop
5444 if not Is_OK_Static_Expression (Indx) then
5453 if Has_Prefix (N) then
5455 P : constant Node_Id := Prefix (N);
5458 if Nkind (N) = N_Explicit_Dereference
5459 and then Is_Variable (P)
5463 elsif Is_Entity_Name (P)
5464 and then Ekind (Entity (P)) = E_Function
5468 elsif Nkind (P) = N_Function_Call then
5472 -- Recursion to continue traversing the prefix of the
5473 -- renaming expression
5475 return Check_Renaming (P);
5482 -- Start of processing for Is_Valid_Renaming
5485 return Check_Renaming (N);
5486 end Is_Valid_Renaming;
5488 -- Start of processing for Denotes_Same_Object
5491 -- Both names statically denote the same stand-alone object or parameter
5492 -- (RM 6.4.1(6.5/3))
5494 if Is_Entity_Name (Obj1)
5495 and then Is_Entity_Name (Obj2)
5496 and then Entity (Obj1) = Entity (Obj2)
5501 -- For renamings, the prefix of any dereference within the renamed
5502 -- object_name is not a variable, and any expression within the
5503 -- renamed object_name contains no references to variables nor
5504 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
5506 if Is_Renaming (Obj1) then
5507 if Is_Valid_Renaming (Obj1) then
5508 Obj1 := Renamed_Entity (Entity (Obj1));
5514 if Is_Renaming (Obj2) then
5515 if Is_Valid_Renaming (Obj2) then
5516 Obj2 := Renamed_Entity (Entity (Obj2));
5522 -- No match if not same node kind (such cases are handled by
5523 -- Denotes_Same_Prefix)
5525 if Nkind (Obj1) /= Nkind (Obj2) then
5528 -- After handling valid renamings, one of the two names statically
5529 -- denoted a renaming declaration whose renamed object_name is known
5530 -- to denote the same object as the other (RM 6.4.1(6.10/3))
5532 elsif Is_Entity_Name (Obj1) then
5533 if Is_Entity_Name (Obj2) then
5534 return Entity (Obj1) = Entity (Obj2);
5539 -- Both names are selected_components, their prefixes are known to
5540 -- denote the same object, and their selector_names denote the same
5541 -- component (RM 6.4.1(6.6/3)).
5543 elsif Nkind (Obj1) = N_Selected_Component then
5544 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
5546 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
5548 -- Both names are dereferences and the dereferenced names are known to
5549 -- denote the same object (RM 6.4.1(6.7/3))
5551 elsif Nkind (Obj1) = N_Explicit_Dereference then
5552 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
5554 -- Both names are indexed_components, their prefixes are known to denote
5555 -- the same object, and each of the pairs of corresponding index values
5556 -- are either both static expressions with the same static value or both
5557 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
5559 elsif Nkind (Obj1) = N_Indexed_Component then
5560 if not Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
5568 Indx1 := First (Expressions (Obj1));
5569 Indx2 := First (Expressions (Obj2));
5570 while Present (Indx1) loop
5572 -- Indexes must denote the same static value or same object
5574 if Is_OK_Static_Expression (Indx1) then
5575 if not Is_OK_Static_Expression (Indx2) then
5578 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
5582 elsif not Denotes_Same_Object (Indx1, Indx2) then
5594 -- Both names are slices, their prefixes are known to denote the same
5595 -- object, and the two slices have statically matching index constraints
5596 -- (RM 6.4.1(6.9/3))
5598 elsif Nkind (Obj1) = N_Slice
5599 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
5602 Lo1, Lo2, Hi1, Hi2 : Node_Id;
5605 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
5606 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
5608 -- Check whether bounds are statically identical. There is no
5609 -- attempt to detect partial overlap of slices.
5611 return Denotes_Same_Object (Lo1, Lo2)
5613 Denotes_Same_Object (Hi1, Hi2);
5616 -- In the recursion, literals appear as indexes
5618 elsif Nkind (Obj1) = N_Integer_Literal
5620 Nkind (Obj2) = N_Integer_Literal
5622 return Intval (Obj1) = Intval (Obj2);
5627 end Denotes_Same_Object;
5629 -------------------------
5630 -- Denotes_Same_Prefix --
5631 -------------------------
5633 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
5635 if Is_Entity_Name (A1) then
5636 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
5637 and then not Is_Access_Type (Etype (A1))
5639 return Denotes_Same_Object (A1, Prefix (A2))
5640 or else Denotes_Same_Prefix (A1, Prefix (A2));
5645 elsif Is_Entity_Name (A2) then
5646 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
5648 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
5650 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
5653 Root1, Root2 : Node_Id;
5654 Depth1, Depth2 : Nat := 0;
5657 Root1 := Prefix (A1);
5658 while not Is_Entity_Name (Root1) loop
5660 (Root1, N_Selected_Component, N_Indexed_Component)
5664 Root1 := Prefix (Root1);
5667 Depth1 := Depth1 + 1;
5670 Root2 := Prefix (A2);
5671 while not Is_Entity_Name (Root2) loop
5672 if not Nkind_In (Root2, N_Selected_Component,
5673 N_Indexed_Component)
5677 Root2 := Prefix (Root2);
5680 Depth2 := Depth2 + 1;
5683 -- If both have the same depth and they do not denote the same
5684 -- object, they are disjoint and no warning is needed.
5686 if Depth1 = Depth2 then
5689 elsif Depth1 > Depth2 then
5690 Root1 := Prefix (A1);
5691 for J in 1 .. Depth1 - Depth2 - 1 loop
5692 Root1 := Prefix (Root1);
5695 return Denotes_Same_Object (Root1, A2);
5698 Root2 := Prefix (A2);
5699 for J in 1 .. Depth2 - Depth1 - 1 loop
5700 Root2 := Prefix (Root2);
5703 return Denotes_Same_Object (A1, Root2);
5710 end Denotes_Same_Prefix;
5712 ----------------------
5713 -- Denotes_Variable --
5714 ----------------------
5716 function Denotes_Variable (N : Node_Id) return Boolean is
5718 return Is_Variable (N) and then Paren_Count (N) = 0;
5719 end Denotes_Variable;
5721 -----------------------------
5722 -- Depends_On_Discriminant --
5723 -----------------------------
5725 function Depends_On_Discriminant (N : Node_Id) return Boolean is
5730 Get_Index_Bounds (N, L, H);
5731 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
5732 end Depends_On_Discriminant;
5734 -------------------------
5735 -- Designate_Same_Unit --
5736 -------------------------
5738 function Designate_Same_Unit
5740 Name2 : Node_Id) return Boolean
5742 K1 : constant Node_Kind := Nkind (Name1);
5743 K2 : constant Node_Kind := Nkind (Name2);
5745 function Prefix_Node (N : Node_Id) return Node_Id;
5746 -- Returns the parent unit name node of a defining program unit name
5747 -- or the prefix if N is a selected component or an expanded name.
5749 function Select_Node (N : Node_Id) return Node_Id;
5750 -- Returns the defining identifier node of a defining program unit
5751 -- name or the selector node if N is a selected component or an
5758 function Prefix_Node (N : Node_Id) return Node_Id is
5760 if Nkind (N) = N_Defining_Program_Unit_Name then
5771 function Select_Node (N : Node_Id) return Node_Id is
5773 if Nkind (N) = N_Defining_Program_Unit_Name then
5774 return Defining_Identifier (N);
5776 return Selector_Name (N);
5780 -- Start of processing for Designate_Same_Unit
5783 if Nkind_In (K1, N_Identifier, N_Defining_Identifier)
5785 Nkind_In (K2, N_Identifier, N_Defining_Identifier)
5787 return Chars (Name1) = Chars (Name2);
5789 elsif Nkind_In (K1, N_Expanded_Name,
5790 N_Selected_Component,
5791 N_Defining_Program_Unit_Name)
5793 Nkind_In (K2, N_Expanded_Name,
5794 N_Selected_Component,
5795 N_Defining_Program_Unit_Name)
5798 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
5800 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
5805 end Designate_Same_Unit;
5807 ------------------------------------------
5808 -- function Dynamic_Accessibility_Level --
5809 ------------------------------------------
5811 function Dynamic_Accessibility_Level (Expr : Node_Id) return Node_Id is
5813 Loc : constant Source_Ptr := Sloc (Expr);
5815 function Make_Level_Literal (Level : Uint) return Node_Id;
5816 -- Construct an integer literal representing an accessibility level
5817 -- with its type set to Natural.
5819 ------------------------
5820 -- Make_Level_Literal --
5821 ------------------------
5823 function Make_Level_Literal (Level : Uint) return Node_Id is
5824 Result : constant Node_Id := Make_Integer_Literal (Loc, Level);
5826 Set_Etype (Result, Standard_Natural);
5828 end Make_Level_Literal;
5830 -- Start of processing for Dynamic_Accessibility_Level
5833 if Is_Entity_Name (Expr) then
5836 if Present (Renamed_Object (E)) then
5837 return Dynamic_Accessibility_Level (Renamed_Object (E));
5840 if Is_Formal (E) or else Ekind_In (E, E_Variable, E_Constant) then
5841 if Present (Extra_Accessibility (E)) then
5842 return New_Occurrence_Of (Extra_Accessibility (E), Loc);
5847 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
5849 case Nkind (Expr) is
5851 -- For access discriminant, the level of the enclosing object
5853 when N_Selected_Component =>
5854 if Ekind (Entity (Selector_Name (Expr))) = E_Discriminant
5855 and then Ekind (Etype (Entity (Selector_Name (Expr)))) =
5856 E_Anonymous_Access_Type
5858 return Make_Level_Literal (Object_Access_Level (Expr));
5861 when N_Attribute_Reference =>
5862 case Get_Attribute_Id (Attribute_Name (Expr)) is
5864 -- For X'Access, the level of the prefix X
5866 when Attribute_Access =>
5867 return Make_Level_Literal
5868 (Object_Access_Level (Prefix (Expr)));
5870 -- Treat the unchecked attributes as library-level
5872 when Attribute_Unchecked_Access |
5873 Attribute_Unrestricted_Access =>
5874 return Make_Level_Literal (Scope_Depth (Standard_Standard));
5876 -- No other access-valued attributes
5879 raise Program_Error;
5884 -- Unimplemented: depends on context. As an actual parameter where
5885 -- formal type is anonymous, use
5886 -- Scope_Depth (Current_Scope) + 1.
5887 -- For other cases, see 3.10.2(14/3) and following. ???
5891 when N_Type_Conversion =>
5892 if not Is_Local_Anonymous_Access (Etype (Expr)) then
5894 -- Handle type conversions introduced for a rename of an
5895 -- Ada 2012 stand-alone object of an anonymous access type.
5897 return Dynamic_Accessibility_Level (Expression (Expr));
5904 return Make_Level_Literal (Type_Access_Level (Etype (Expr)));
5905 end Dynamic_Accessibility_Level;
5907 -----------------------------------
5908 -- Effective_Extra_Accessibility --
5909 -----------------------------------
5911 function Effective_Extra_Accessibility (Id : Entity_Id) return Entity_Id is
5913 if Present (Renamed_Object (Id))
5914 and then Is_Entity_Name (Renamed_Object (Id))
5916 return Effective_Extra_Accessibility (Entity (Renamed_Object (Id)));
5918 return Extra_Accessibility (Id);
5920 end Effective_Extra_Accessibility;
5922 -----------------------------
5923 -- Effective_Reads_Enabled --
5924 -----------------------------
5926 function Effective_Reads_Enabled (Id : Entity_Id) return Boolean is
5928 return Has_Enabled_Property (Id, Name_Effective_Reads);
5929 end Effective_Reads_Enabled;
5931 ------------------------------
5932 -- Effective_Writes_Enabled --
5933 ------------------------------
5935 function Effective_Writes_Enabled (Id : Entity_Id) return Boolean is
5937 return Has_Enabled_Property (Id, Name_Effective_Writes);
5938 end Effective_Writes_Enabled;
5940 ------------------------------
5941 -- Enclosing_Comp_Unit_Node --
5942 ------------------------------
5944 function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id is
5945 Current_Node : Node_Id;
5949 while Present (Current_Node)
5950 and then Nkind (Current_Node) /= N_Compilation_Unit
5952 Current_Node := Parent (Current_Node);
5955 if Nkind (Current_Node) /= N_Compilation_Unit then
5958 return Current_Node;
5960 end Enclosing_Comp_Unit_Node;
5962 --------------------------
5963 -- Enclosing_CPP_Parent --
5964 --------------------------
5966 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
5967 Parent_Typ : Entity_Id := Typ;
5970 while not Is_CPP_Class (Parent_Typ)
5971 and then Etype (Parent_Typ) /= Parent_Typ
5973 Parent_Typ := Etype (Parent_Typ);
5975 if Is_Private_Type (Parent_Typ) then
5976 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5980 pragma Assert (Is_CPP_Class (Parent_Typ));
5982 end Enclosing_CPP_Parent;
5984 ---------------------------
5985 -- Enclosing_Declaration --
5986 ---------------------------
5988 function Enclosing_Declaration (N : Node_Id) return Node_Id is
5989 Decl : Node_Id := N;
5992 while Present (Decl)
5993 and then not (Nkind (Decl) in N_Declaration
5995 Nkind (Decl) in N_Later_Decl_Item)
5997 Decl := Parent (Decl);
6001 end Enclosing_Declaration;
6003 ----------------------------
6004 -- Enclosing_Generic_Body --
6005 ----------------------------
6007 function Enclosing_Generic_Body
6008 (N : Node_Id) return Node_Id
6016 while Present (P) loop
6017 if Nkind (P) = N_Package_Body
6018 or else Nkind (P) = N_Subprogram_Body
6020 Spec := Corresponding_Spec (P);
6022 if Present (Spec) then
6023 Decl := Unit_Declaration_Node (Spec);
6025 if Nkind (Decl) = N_Generic_Package_Declaration
6026 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
6037 end Enclosing_Generic_Body;
6039 ----------------------------
6040 -- Enclosing_Generic_Unit --
6041 ----------------------------
6043 function Enclosing_Generic_Unit
6044 (N : Node_Id) return Node_Id
6052 while Present (P) loop
6053 if Nkind (P) = N_Generic_Package_Declaration
6054 or else Nkind (P) = N_Generic_Subprogram_Declaration
6058 elsif Nkind (P) = N_Package_Body
6059 or else Nkind (P) = N_Subprogram_Body
6061 Spec := Corresponding_Spec (P);
6063 if Present (Spec) then
6064 Decl := Unit_Declaration_Node (Spec);
6066 if Nkind (Decl) = N_Generic_Package_Declaration
6067 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
6078 end Enclosing_Generic_Unit;
6080 -------------------------------
6081 -- Enclosing_Lib_Unit_Entity --
6082 -------------------------------
6084 function Enclosing_Lib_Unit_Entity
6085 (E : Entity_Id := Current_Scope) return Entity_Id
6087 Unit_Entity : Entity_Id;
6090 -- Look for enclosing library unit entity by following scope links.
6091 -- Equivalent to, but faster than indexing through the scope stack.
6094 while (Present (Scope (Unit_Entity))
6095 and then Scope (Unit_Entity) /= Standard_Standard)
6096 and not Is_Child_Unit (Unit_Entity)
6098 Unit_Entity := Scope (Unit_Entity);
6102 end Enclosing_Lib_Unit_Entity;
6104 -----------------------------
6105 -- Enclosing_Lib_Unit_Node --
6106 -----------------------------
6108 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
6109 Encl_Unit : Node_Id;
6112 Encl_Unit := Enclosing_Comp_Unit_Node (N);
6113 while Present (Encl_Unit)
6114 and then Nkind (Unit (Encl_Unit)) = N_Subunit
6116 Encl_Unit := Library_Unit (Encl_Unit);
6120 end Enclosing_Lib_Unit_Node;
6122 -----------------------
6123 -- Enclosing_Package --
6124 -----------------------
6126 function Enclosing_Package (E : Entity_Id) return Entity_Id is
6127 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
6130 if Dynamic_Scope = Standard_Standard then
6131 return Standard_Standard;
6133 elsif Dynamic_Scope = Empty then
6136 elsif Ekind_In (Dynamic_Scope, E_Package, E_Package_Body,
6139 return Dynamic_Scope;
6142 return Enclosing_Package (Dynamic_Scope);
6144 end Enclosing_Package;
6146 -------------------------------------
6147 -- Enclosing_Package_Or_Subprogram --
6148 -------------------------------------
6150 function Enclosing_Package_Or_Subprogram (E : Entity_Id) return Entity_Id is
6155 while Present (S) loop
6156 if Is_Package_Or_Generic_Package (S)
6157 or else Ekind (S) = E_Package_Body
6161 elsif Is_Subprogram_Or_Generic_Subprogram (S)
6162 or else Ekind (S) = E_Subprogram_Body
6172 end Enclosing_Package_Or_Subprogram;
6174 --------------------------
6175 -- Enclosing_Subprogram --
6176 --------------------------
6178 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
6179 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
6182 if Dynamic_Scope = Standard_Standard then
6185 elsif Dynamic_Scope = Empty then
6188 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
6189 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
6191 elsif Ekind (Dynamic_Scope) = E_Block
6192 or else Ekind (Dynamic_Scope) = E_Return_Statement
6194 return Enclosing_Subprogram (Dynamic_Scope);
6196 elsif Ekind (Dynamic_Scope) = E_Task_Type then
6197 return Get_Task_Body_Procedure (Dynamic_Scope);
6199 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
6200 and then Present (Full_View (Dynamic_Scope))
6201 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
6203 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
6205 -- No body is generated if the protected operation is eliminated
6207 elsif Convention (Dynamic_Scope) = Convention_Protected
6208 and then not Is_Eliminated (Dynamic_Scope)
6209 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
6211 return Protected_Body_Subprogram (Dynamic_Scope);
6214 return Dynamic_Scope;
6216 end Enclosing_Subprogram;
6218 ------------------------
6219 -- Ensure_Freeze_Node --
6220 ------------------------
6222 procedure Ensure_Freeze_Node (E : Entity_Id) is
6225 if No (Freeze_Node (E)) then
6226 FN := Make_Freeze_Entity (Sloc (E));
6227 Set_Has_Delayed_Freeze (E);
6228 Set_Freeze_Node (E, FN);
6229 Set_Access_Types_To_Process (FN, No_Elist);
6230 Set_TSS_Elist (FN, No_Elist);
6233 end Ensure_Freeze_Node;
6239 procedure Enter_Name (Def_Id : Entity_Id) is
6240 C : constant Entity_Id := Current_Entity (Def_Id);
6241 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
6242 S : constant Entity_Id := Current_Scope;
6245 Generate_Definition (Def_Id);
6247 -- Add new name to current scope declarations. Check for duplicate
6248 -- declaration, which may or may not be a genuine error.
6252 -- Case of previous entity entered because of a missing declaration
6253 -- or else a bad subtype indication. Best is to use the new entity,
6254 -- and make the previous one invisible.
6256 if Etype (E) = Any_Type then
6257 Set_Is_Immediately_Visible (E, False);
6259 -- Case of renaming declaration constructed for package instances.
6260 -- if there is an explicit declaration with the same identifier,
6261 -- the renaming is not immediately visible any longer, but remains
6262 -- visible through selected component notation.
6264 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
6265 and then not Comes_From_Source (E)
6267 Set_Is_Immediately_Visible (E, False);
6269 -- The new entity may be the package renaming, which has the same
6270 -- same name as a generic formal which has been seen already.
6272 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
6273 and then not Comes_From_Source (Def_Id)
6275 Set_Is_Immediately_Visible (E, False);
6277 -- For a fat pointer corresponding to a remote access to subprogram,
6278 -- we use the same identifier as the RAS type, so that the proper
6279 -- name appears in the stub. This type is only retrieved through
6280 -- the RAS type and never by visibility, and is not added to the
6281 -- visibility list (see below).
6283 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
6284 and then Ekind (Def_Id) = E_Record_Type
6285 and then Present (Corresponding_Remote_Type (Def_Id))
6289 -- Case of an implicit operation or derived literal. The new entity
6290 -- hides the implicit one, which is removed from all visibility,
6291 -- i.e. the entity list of its scope, and homonym chain of its name.
6293 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
6294 or else Is_Internal (E)
6298 Prev_Vis : Entity_Id;
6299 Decl : constant Node_Id := Parent (E);
6302 -- If E is an implicit declaration, it cannot be the first
6303 -- entity in the scope.
6305 Prev := First_Entity (Current_Scope);
6306 while Present (Prev) and then Next_Entity (Prev) /= E loop
6312 -- If E is not on the entity chain of the current scope,
6313 -- it is an implicit declaration in the generic formal
6314 -- part of a generic subprogram. When analyzing the body,
6315 -- the generic formals are visible but not on the entity
6316 -- chain of the subprogram. The new entity will become
6317 -- the visible one in the body.
6320 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
6324 Set_Next_Entity (Prev, Next_Entity (E));
6326 if No (Next_Entity (Prev)) then
6327 Set_Last_Entity (Current_Scope, Prev);
6330 if E = Current_Entity (E) then
6334 Prev_Vis := Current_Entity (E);
6335 while Homonym (Prev_Vis) /= E loop
6336 Prev_Vis := Homonym (Prev_Vis);
6340 if Present (Prev_Vis) then
6342 -- Skip E in the visibility chain
6344 Set_Homonym (Prev_Vis, Homonym (E));
6347 Set_Name_Entity_Id (Chars (E), Homonym (E));
6352 -- This section of code could use a comment ???
6354 elsif Present (Etype (E))
6355 and then Is_Concurrent_Type (Etype (E))
6360 -- If the homograph is a protected component renaming, it should not
6361 -- be hiding the current entity. Such renamings are treated as weak
6364 elsif Is_Prival (E) then
6365 Set_Is_Immediately_Visible (E, False);
6367 -- In this case the current entity is a protected component renaming.
6368 -- Perform minimal decoration by setting the scope and return since
6369 -- the prival should not be hiding other visible entities.
6371 elsif Is_Prival (Def_Id) then
6372 Set_Scope (Def_Id, Current_Scope);
6375 -- Analogous to privals, the discriminal generated for an entry index
6376 -- parameter acts as a weak declaration. Perform minimal decoration
6377 -- to avoid bogus errors.
6379 elsif Is_Discriminal (Def_Id)
6380 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
6382 Set_Scope (Def_Id, Current_Scope);
6385 -- In the body or private part of an instance, a type extension may
6386 -- introduce a component with the same name as that of an actual. The
6387 -- legality rule is not enforced, but the semantics of the full type
6388 -- with two components of same name are not clear at this point???
6390 elsif In_Instance_Not_Visible then
6393 -- When compiling a package body, some child units may have become
6394 -- visible. They cannot conflict with local entities that hide them.
6396 elsif Is_Child_Unit (E)
6397 and then In_Open_Scopes (Scope (E))
6398 and then not Is_Immediately_Visible (E)
6402 -- Conversely, with front-end inlining we may compile the parent body
6403 -- first, and a child unit subsequently. The context is now the
6404 -- parent spec, and body entities are not visible.
6406 elsif Is_Child_Unit (Def_Id)
6407 and then Is_Package_Body_Entity (E)
6408 and then not In_Package_Body (Current_Scope)
6412 -- Case of genuine duplicate declaration
6415 Error_Msg_Sloc := Sloc (E);
6417 -- If the previous declaration is an incomplete type declaration
6418 -- this may be an attempt to complete it with a private type. The
6419 -- following avoids confusing cascaded errors.
6421 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
6422 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
6425 ("incomplete type cannot be completed with a private " &
6426 "declaration", Parent (Def_Id));
6427 Set_Is_Immediately_Visible (E, False);
6428 Set_Full_View (E, Def_Id);
6430 -- An inherited component of a record conflicts with a new
6431 -- discriminant. The discriminant is inserted first in the scope,
6432 -- but the error should be posted on it, not on the component.
6434 elsif Ekind (E) = E_Discriminant
6435 and then Present (Scope (Def_Id))
6436 and then Scope (Def_Id) /= Current_Scope
6438 Error_Msg_Sloc := Sloc (Def_Id);
6439 Error_Msg_N ("& conflicts with declaration#", E);
6442 -- If the name of the unit appears in its own context clause, a
6443 -- dummy package with the name has already been created, and the
6444 -- error emitted. Try to continue quietly.
6446 elsif Error_Posted (E)
6447 and then Sloc (E) = No_Location
6448 and then Nkind (Parent (E)) = N_Package_Specification
6449 and then Current_Scope = Standard_Standard
6451 Set_Scope (Def_Id, Current_Scope);
6455 Error_Msg_N ("& conflicts with declaration#", Def_Id);
6457 -- Avoid cascaded messages with duplicate components in
6460 if Ekind_In (E, E_Component, E_Discriminant) then
6465 if Nkind (Parent (Parent (Def_Id))) =
6466 N_Generic_Subprogram_Declaration
6468 Defining_Entity (Specification (Parent (Parent (Def_Id))))
6470 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
6473 -- If entity is in standard, then we are in trouble, because it
6474 -- means that we have a library package with a duplicated name.
6475 -- That's hard to recover from, so abort.
6477 if S = Standard_Standard then
6478 raise Unrecoverable_Error;
6480 -- Otherwise we continue with the declaration. Having two
6481 -- identical declarations should not cause us too much trouble.
6489 -- If we fall through, declaration is OK, at least OK enough to continue
6491 -- If Def_Id is a discriminant or a record component we are in the midst
6492 -- of inheriting components in a derived record definition. Preserve
6493 -- their Ekind and Etype.
6495 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
6498 -- If a type is already set, leave it alone (happens when a type
6499 -- declaration is reanalyzed following a call to the optimizer).
6501 elsif Present (Etype (Def_Id)) then
6504 -- Otherwise, the kind E_Void insures that premature uses of the entity
6505 -- will be detected. Any_Type insures that no cascaded errors will occur
6508 Set_Ekind (Def_Id, E_Void);
6509 Set_Etype (Def_Id, Any_Type);
6512 -- Inherited discriminants and components in derived record types are
6513 -- immediately visible. Itypes are not.
6515 -- Unless the Itype is for a record type with a corresponding remote
6516 -- type (what is that about, it was not commented ???)
6518 if Ekind_In (Def_Id, E_Discriminant, E_Component)
6520 ((not Is_Record_Type (Def_Id)
6521 or else No (Corresponding_Remote_Type (Def_Id)))
6522 and then not Is_Itype (Def_Id))
6524 Set_Is_Immediately_Visible (Def_Id);
6525 Set_Current_Entity (Def_Id);
6528 Set_Homonym (Def_Id, C);
6529 Append_Entity (Def_Id, S);
6530 Set_Public_Status (Def_Id);
6532 -- Declaring a homonym is not allowed in SPARK ...
6534 if Present (C) and then Restriction_Check_Required (SPARK_05) then
6536 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
6537 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
6538 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
6541 -- ... unless the new declaration is in a subprogram, and the
6542 -- visible declaration is a variable declaration or a parameter
6543 -- specification outside that subprogram.
6545 if Present (Enclosing_Subp)
6546 and then Nkind_In (Parent (C), N_Object_Declaration,
6547 N_Parameter_Specification)
6548 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
6552 -- ... or the new declaration is in a package, and the visible
6553 -- declaration occurs outside that package.
6555 elsif Present (Enclosing_Pack)
6556 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
6560 -- ... or the new declaration is a component declaration in a
6561 -- record type definition.
6563 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
6566 -- Don't issue error for non-source entities
6568 elsif Comes_From_Source (Def_Id)
6569 and then Comes_From_Source (C)
6571 Error_Msg_Sloc := Sloc (C);
6572 Check_SPARK_05_Restriction
6573 ("redeclaration of identifier &#", Def_Id);
6578 -- Warn if new entity hides an old one
6580 if Warn_On_Hiding and then Present (C)
6582 -- Don't warn for record components since they always have a well
6583 -- defined scope which does not confuse other uses. Note that in
6584 -- some cases, Ekind has not been set yet.
6586 and then Ekind (C) /= E_Component
6587 and then Ekind (C) /= E_Discriminant
6588 and then Nkind (Parent (C)) /= N_Component_Declaration
6589 and then Ekind (Def_Id) /= E_Component
6590 and then Ekind (Def_Id) /= E_Discriminant
6591 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
6593 -- Don't warn for one character variables. It is too common to use
6594 -- such variables as locals and will just cause too many false hits.
6596 and then Length_Of_Name (Chars (C)) /= 1
6598 -- Don't warn for non-source entities
6600 and then Comes_From_Source (C)
6601 and then Comes_From_Source (Def_Id)
6603 -- Don't warn unless entity in question is in extended main source
6605 and then In_Extended_Main_Source_Unit (Def_Id)
6607 -- Finally, the hidden entity must be either immediately visible or
6608 -- use visible (i.e. from a used package).
6611 (Is_Immediately_Visible (C)
6613 Is_Potentially_Use_Visible (C))
6615 Error_Msg_Sloc := Sloc (C);
6616 Error_Msg_N ("declaration hides &#?h?", Def_Id);
6624 function Entity_Of (N : Node_Id) return Entity_Id is
6630 if Is_Entity_Name (N) then
6633 -- Follow a possible chain of renamings to reach the root renamed
6637 and then Is_Object (Id)
6638 and then Present (Renamed_Object (Id))
6640 if Is_Entity_Name (Renamed_Object (Id)) then
6641 Id := Entity (Renamed_Object (Id));
6652 --------------------------
6653 -- Explain_Limited_Type --
6654 --------------------------
6656 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
6660 -- For array, component type must be limited
6662 if Is_Array_Type (T) then
6663 Error_Msg_Node_2 := T;
6665 ("\component type& of type& is limited", N, Component_Type (T));
6666 Explain_Limited_Type (Component_Type (T), N);
6668 elsif Is_Record_Type (T) then
6670 -- No need for extra messages if explicit limited record
6672 if Is_Limited_Record (Base_Type (T)) then
6676 -- Otherwise find a limited component. Check only components that
6677 -- come from source, or inherited components that appear in the
6678 -- source of the ancestor.
6680 C := First_Component (T);
6681 while Present (C) loop
6682 if Is_Limited_Type (Etype (C))
6684 (Comes_From_Source (C)
6686 (Present (Original_Record_Component (C))
6688 Comes_From_Source (Original_Record_Component (C))))
6690 Error_Msg_Node_2 := T;
6691 Error_Msg_NE ("\component& of type& has limited type", N, C);
6692 Explain_Limited_Type (Etype (C), N);
6699 -- The type may be declared explicitly limited, even if no component
6700 -- of it is limited, in which case we fall out of the loop.
6703 end Explain_Limited_Type;
6705 -------------------------------
6706 -- Extensions_Visible_Status --
6707 -------------------------------
6709 function Extensions_Visible_Status
6710 (Id : Entity_Id) return Extensions_Visible_Mode
6719 -- When a formal parameter is subject to Extensions_Visible, the pragma
6720 -- is stored in the contract of related subprogram.
6722 if Is_Formal (Id) then
6725 elsif Is_Subprogram_Or_Generic_Subprogram (Id) then
6728 -- No other construct carries this pragma
6731 return Extensions_Visible_None;
6734 Prag := Get_Pragma (Subp, Pragma_Extensions_Visible);
6736 -- In certain cases analysis may request the Extensions_Visible status
6737 -- of an expression function before the pragma has been analyzed yet.
6738 -- Inspect the declarative items after the expression function looking
6739 -- for the pragma (if any).
6741 if No (Prag) and then Is_Expression_Function (Subp) then
6742 Decl := Next (Unit_Declaration_Node (Subp));
6743 while Present (Decl) loop
6744 if Nkind (Decl) = N_Pragma
6745 and then Pragma_Name (Decl) = Name_Extensions_Visible
6750 -- A source construct ends the region where Extensions_Visible may
6751 -- appear, stop the traversal. An expanded expression function is
6752 -- no longer a source construct, but it must still be recognized.
6754 elsif Comes_From_Source (Decl)
6756 (Nkind_In (Decl, N_Subprogram_Body,
6757 N_Subprogram_Declaration)
6758 and then Is_Expression_Function (Defining_Entity (Decl)))
6767 -- Extract the value from the Boolean expression (if any)
6769 if Present (Prag) then
6770 Arg := First (Pragma_Argument_Associations (Prag));
6772 if Present (Arg) then
6773 Expr := Get_Pragma_Arg (Arg);
6775 -- When the associated subprogram is an expression function, the
6776 -- argument of the pragma may not have been analyzed.
6778 if not Analyzed (Expr) then
6779 Preanalyze_And_Resolve (Expr, Standard_Boolean);
6782 -- Guard against cascading errors when the argument of pragma
6783 -- Extensions_Visible is not a valid static Boolean expression.
6785 if Error_Posted (Expr) then
6786 return Extensions_Visible_None;
6788 elsif Is_True (Expr_Value (Expr)) then
6789 return Extensions_Visible_True;
6792 return Extensions_Visible_False;
6795 -- Otherwise the aspect or pragma defaults to True
6798 return Extensions_Visible_True;
6801 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
6802 -- directly specified. In SPARK code, its value defaults to "False".
6804 elsif SPARK_Mode = On then
6805 return Extensions_Visible_False;
6807 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
6811 return Extensions_Visible_True;
6813 end Extensions_Visible_Status;
6819 procedure Find_Actual
6821 Formal : out Entity_Id;
6824 Context : constant Node_Id := Parent (N);
6829 if Nkind_In (Context, N_Indexed_Component, N_Selected_Component)
6830 and then N = Prefix (Context)
6832 Find_Actual (Context, Formal, Call);
6835 elsif Nkind (Context) = N_Parameter_Association
6836 and then N = Explicit_Actual_Parameter (Context)
6838 Call := Parent (Context);
6840 elsif Nkind_In (Context, N_Entry_Call_Statement,
6842 N_Procedure_Call_Statement)
6852 -- If we have a call to a subprogram look for the parameter. Note that
6853 -- we exclude overloaded calls, since we don't know enough to be sure
6854 -- of giving the right answer in this case.
6856 if Nkind_In (Call, N_Entry_Call_Statement,
6858 N_Procedure_Call_Statement)
6860 Call_Nam := Name (Call);
6862 -- A call to a protected or task entry appears as a selected
6863 -- component rather than an expanded name.
6865 if Nkind (Call_Nam) = N_Selected_Component then
6866 Call_Nam := Selector_Name (Call_Nam);
6869 if Is_Entity_Name (Call_Nam)
6870 and then Present (Entity (Call_Nam))
6871 and then Is_Overloadable (Entity (Call_Nam))
6872 and then not Is_Overloaded (Call_Nam)
6874 -- If node is name in call it is not an actual
6876 if N = Call_Nam then
6882 -- Fall here if we are definitely a parameter
6884 Actual := First_Actual (Call);
6885 Formal := First_Formal (Entity (Call_Nam));
6886 while Present (Formal) and then Present (Actual) loop
6890 -- An actual that is the prefix in a prefixed call may have
6891 -- been rewritten in the call, after the deferred reference
6892 -- was collected. Check if sloc and kinds and names match.
6894 elsif Sloc (Actual) = Sloc (N)
6895 and then Nkind (Actual) = N_Identifier
6896 and then Nkind (Actual) = Nkind (N)
6897 and then Chars (Actual) = Chars (N)
6902 Actual := Next_Actual (Actual);
6903 Formal := Next_Formal (Formal);
6909 -- Fall through here if we did not find matching actual
6915 ---------------------------
6916 -- Find_Body_Discriminal --
6917 ---------------------------
6919 function Find_Body_Discriminal
6920 (Spec_Discriminant : Entity_Id) return Entity_Id
6926 -- If expansion is suppressed, then the scope can be the concurrent type
6927 -- itself rather than a corresponding concurrent record type.
6929 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
6930 Tsk := Scope (Spec_Discriminant);
6933 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
6935 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
6938 -- Find discriminant of original concurrent type, and use its current
6939 -- discriminal, which is the renaming within the task/protected body.
6941 Disc := First_Discriminant (Tsk);
6942 while Present (Disc) loop
6943 if Chars (Disc) = Chars (Spec_Discriminant) then
6944 return Discriminal (Disc);
6947 Next_Discriminant (Disc);
6950 -- That loop should always succeed in finding a matching entry and
6951 -- returning. Fatal error if not.
6953 raise Program_Error;
6954 end Find_Body_Discriminal;
6956 -------------------------------------
6957 -- Find_Corresponding_Discriminant --
6958 -------------------------------------
6960 function Find_Corresponding_Discriminant
6962 Typ : Entity_Id) return Entity_Id
6964 Par_Disc : Entity_Id;
6965 Old_Disc : Entity_Id;
6966 New_Disc : Entity_Id;
6969 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
6971 -- The original type may currently be private, and the discriminant
6972 -- only appear on its full view.
6974 if Is_Private_Type (Scope (Par_Disc))
6975 and then not Has_Discriminants (Scope (Par_Disc))
6976 and then Present (Full_View (Scope (Par_Disc)))
6978 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
6980 Old_Disc := First_Discriminant (Scope (Par_Disc));
6983 if Is_Class_Wide_Type (Typ) then
6984 New_Disc := First_Discriminant (Root_Type (Typ));
6986 New_Disc := First_Discriminant (Typ);
6989 while Present (Old_Disc) and then Present (New_Disc) loop
6990 if Old_Disc = Par_Disc then
6994 Next_Discriminant (Old_Disc);
6995 Next_Discriminant (New_Disc);
6998 -- Should always find it
7000 raise Program_Error;
7001 end Find_Corresponding_Discriminant;
7003 ----------------------------------
7004 -- Find_Enclosing_Iterator_Loop --
7005 ----------------------------------
7007 function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id is
7012 -- Traverse the scope chain looking for an iterator loop. Such loops are
7013 -- usually transformed into blocks, hence the use of Original_Node.
7016 while Present (S) and then S /= Standard_Standard loop
7017 if Ekind (S) = E_Loop
7018 and then Nkind (Parent (S)) = N_Implicit_Label_Declaration
7020 Constr := Original_Node (Label_Construct (Parent (S)));
7022 if Nkind (Constr) = N_Loop_Statement
7023 and then Present (Iteration_Scheme (Constr))
7024 and then Nkind (Iterator_Specification
7025 (Iteration_Scheme (Constr))) =
7026 N_Iterator_Specification
7036 end Find_Enclosing_Iterator_Loop;
7038 ------------------------------------
7039 -- Find_Loop_In_Conditional_Block --
7040 ------------------------------------
7042 function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is
7048 if Nkind (Stmt) = N_If_Statement then
7049 Stmt := First (Then_Statements (Stmt));
7052 pragma Assert (Nkind (Stmt) = N_Block_Statement);
7054 -- Inspect the statements of the conditional block. In general the loop
7055 -- should be the first statement in the statement sequence of the block,
7056 -- but the finalization machinery may have introduced extra object
7059 Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
7060 while Present (Stmt) loop
7061 if Nkind (Stmt) = N_Loop_Statement then
7068 -- The expansion of attribute 'Loop_Entry produced a malformed block
7070 raise Program_Error;
7071 end Find_Loop_In_Conditional_Block;
7073 --------------------------
7074 -- Find_Overlaid_Entity --
7075 --------------------------
7077 procedure Find_Overlaid_Entity
7079 Ent : out Entity_Id;
7085 -- We are looking for one of the two following forms:
7087 -- for X'Address use Y'Address
7091 -- Const : constant Address := expr;
7093 -- for X'Address use Const;
7095 -- In the second case, the expr is either Y'Address, or recursively a
7096 -- constant that eventually references Y'Address.
7101 if Nkind (N) = N_Attribute_Definition_Clause
7102 and then Chars (N) = Name_Address
7104 Expr := Expression (N);
7106 -- This loop checks the form of the expression for Y'Address,
7107 -- using recursion to deal with intermediate constants.
7110 -- Check for Y'Address
7112 if Nkind (Expr) = N_Attribute_Reference
7113 and then Attribute_Name (Expr) = Name_Address
7115 Expr := Prefix (Expr);
7118 -- Check for Const where Const is a constant entity
7120 elsif Is_Entity_Name (Expr)
7121 and then Ekind (Entity (Expr)) = E_Constant
7123 Expr := Constant_Value (Entity (Expr));
7125 -- Anything else does not need checking
7132 -- This loop checks the form of the prefix for an entity, using
7133 -- recursion to deal with intermediate components.
7136 -- Check for Y where Y is an entity
7138 if Is_Entity_Name (Expr) then
7139 Ent := Entity (Expr);
7142 -- Check for components
7145 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component)
7147 Expr := Prefix (Expr);
7150 -- Anything else does not need checking
7157 end Find_Overlaid_Entity;
7159 -------------------------
7160 -- Find_Parameter_Type --
7161 -------------------------
7163 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
7165 if Nkind (Param) /= N_Parameter_Specification then
7168 -- For an access parameter, obtain the type from the formal entity
7169 -- itself, because access to subprogram nodes do not carry a type.
7170 -- Shouldn't we always use the formal entity ???
7172 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
7173 return Etype (Defining_Identifier (Param));
7176 return Etype (Parameter_Type (Param));
7178 end Find_Parameter_Type;
7180 -----------------------------------
7181 -- Find_Placement_In_State_Space --
7182 -----------------------------------
7184 procedure Find_Placement_In_State_Space
7185 (Item_Id : Entity_Id;
7186 Placement : out State_Space_Kind;
7187 Pack_Id : out Entity_Id)
7189 Context : Entity_Id;
7192 -- Assume that the item does not appear in the state space of a package
7194 Placement := Not_In_Package;
7197 -- Climb the scope stack and examine the enclosing context
7199 Context := Scope (Item_Id);
7200 while Present (Context) and then Context /= Standard_Standard loop
7201 if Ekind (Context) = E_Package then
7204 -- A package body is a cut off point for the traversal as the item
7205 -- cannot be visible to the outside from this point on. Note that
7206 -- this test must be done first as a body is also classified as a
7209 if In_Package_Body (Context) then
7210 Placement := Body_State_Space;
7213 -- The private part of a package is a cut off point for the
7214 -- traversal as the item cannot be visible to the outside from
7217 elsif In_Private_Part (Context) then
7218 Placement := Private_State_Space;
7221 -- When the item appears in the visible state space of a package,
7222 -- continue to climb the scope stack as this may not be the final
7226 Placement := Visible_State_Space;
7228 -- The visible state space of a child unit acts as the proper
7229 -- placement of an item.
7231 if Is_Child_Unit (Context) then
7236 -- The item or its enclosing package appear in a construct that has
7240 Placement := Not_In_Package;
7244 Context := Scope (Context);
7246 end Find_Placement_In_State_Space;
7248 ------------------------
7249 -- Find_Specific_Type --
7250 ------------------------
7252 function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
7253 Typ : Entity_Id := Root_Type (CW);
7256 if Ekind (Typ) = E_Incomplete_Type then
7257 if From_Limited_With (Typ) then
7258 Typ := Non_Limited_View (Typ);
7260 Typ := Full_View (Typ);
7264 if Is_Private_Type (Typ)
7265 and then not Is_Tagged_Type (Typ)
7266 and then Present (Full_View (Typ))
7268 return Full_View (Typ);
7272 end Find_Specific_Type;
7274 -----------------------------
7275 -- Find_Static_Alternative --
7276 -----------------------------
7278 function Find_Static_Alternative (N : Node_Id) return Node_Id is
7279 Expr : constant Node_Id := Expression (N);
7280 Val : constant Uint := Expr_Value (Expr);
7285 Alt := First (Alternatives (N));
7288 if Nkind (Alt) /= N_Pragma then
7289 Choice := First (Discrete_Choices (Alt));
7290 while Present (Choice) loop
7292 -- Others choice, always matches
7294 if Nkind (Choice) = N_Others_Choice then
7297 -- Range, check if value is in the range
7299 elsif Nkind (Choice) = N_Range then
7301 Val >= Expr_Value (Low_Bound (Choice))
7303 Val <= Expr_Value (High_Bound (Choice));
7305 -- Choice is a subtype name. Note that we know it must
7306 -- be a static subtype, since otherwise it would have
7307 -- been diagnosed as illegal.
7309 elsif Is_Entity_Name (Choice)
7310 and then Is_Type (Entity (Choice))
7312 exit Search when Is_In_Range (Expr, Etype (Choice),
7313 Assume_Valid => False);
7315 -- Choice is a subtype indication
7317 elsif Nkind (Choice) = N_Subtype_Indication then
7319 C : constant Node_Id := Constraint (Choice);
7320 R : constant Node_Id := Range_Expression (C);
7324 Val >= Expr_Value (Low_Bound (R))
7326 Val <= Expr_Value (High_Bound (R));
7329 -- Choice is a simple expression
7332 exit Search when Val = Expr_Value (Choice);
7340 pragma Assert (Present (Alt));
7343 -- The above loop *must* terminate by finding a match, since
7344 -- we know the case statement is valid, and the value of the
7345 -- expression is known at compile time. When we fall out of
7346 -- the loop, Alt points to the alternative that we know will
7347 -- be selected at run time.
7350 end Find_Static_Alternative;
7356 function First_Actual (Node : Node_Id) return Node_Id is
7360 if No (Parameter_Associations (Node)) then
7364 N := First (Parameter_Associations (Node));
7366 if Nkind (N) = N_Parameter_Association then
7367 return First_Named_Actual (Node);
7377 function Fix_Msg (Id : Entity_Id; Msg : String) return String is
7378 Is_Task : constant Boolean :=
7379 Ekind_In (Id, E_Task_Body, E_Task_Type)
7380 or else Is_Single_Task_Object (Id);
7381 Msg_Last : constant Natural := Msg'Last;
7382 Msg_Index : Natural;
7383 Res : String (Msg'Range) := (others => ' ');
7384 Res_Index : Natural;
7387 -- Copy all characters from the input message Msg to result Res with
7388 -- suitable replacements.
7390 Msg_Index := Msg'First;
7391 Res_Index := Res'First;
7392 while Msg_Index <= Msg_Last loop
7394 -- Replace "subprogram" with a different word
7396 if Msg_Index <= Msg_Last - 10
7397 and then Msg (Msg_Index .. Msg_Index + 9) = "subprogram"
7399 if Ekind_In (Id, E_Entry, E_Entry_Family) then
7400 Res (Res_Index .. Res_Index + 4) := "entry";
7401 Res_Index := Res_Index + 5;
7404 Res (Res_Index .. Res_Index + 8) := "task type";
7405 Res_Index := Res_Index + 9;
7408 Res (Res_Index .. Res_Index + 9) := "subprogram";
7409 Res_Index := Res_Index + 10;
7412 Msg_Index := Msg_Index + 10;
7414 -- Replace "protected" with a different word
7416 elsif Msg_Index <= Msg_Last - 9
7417 and then Msg (Msg_Index .. Msg_Index + 8) = "protected"
7420 Res (Res_Index .. Res_Index + 3) := "task";
7421 Res_Index := Res_Index + 4;
7422 Msg_Index := Msg_Index + 9;
7424 -- Otherwise copy the character
7427 Res (Res_Index) := Msg (Msg_Index);
7428 Msg_Index := Msg_Index + 1;
7429 Res_Index := Res_Index + 1;
7433 return Res (Res'First .. Res_Index - 1);
7436 -----------------------
7437 -- Gather_Components --
7438 -----------------------
7440 procedure Gather_Components
7442 Comp_List : Node_Id;
7443 Governed_By : List_Id;
7445 Report_Errors : out Boolean)
7449 Discrete_Choice : Node_Id;
7450 Comp_Item : Node_Id;
7452 Discrim : Entity_Id;
7453 Discrim_Name : Node_Id;
7454 Discrim_Value : Node_Id;
7457 Report_Errors := False;
7459 if No (Comp_List) or else Null_Present (Comp_List) then
7462 elsif Present (Component_Items (Comp_List)) then
7463 Comp_Item := First (Component_Items (Comp_List));
7469 while Present (Comp_Item) loop
7471 -- Skip the tag of a tagged record, the interface tags, as well
7472 -- as all items that are not user components (anonymous types,
7473 -- rep clauses, Parent field, controller field).
7475 if Nkind (Comp_Item) = N_Component_Declaration then
7477 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
7479 if not Is_Tag (Comp) and then Chars (Comp) /= Name_uParent then
7480 Append_Elmt (Comp, Into);
7488 if No (Variant_Part (Comp_List)) then
7491 Discrim_Name := Name (Variant_Part (Comp_List));
7492 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
7495 -- Look for the discriminant that governs this variant part.
7496 -- The discriminant *must* be in the Governed_By List
7498 Assoc := First (Governed_By);
7499 Find_Constraint : loop
7500 Discrim := First (Choices (Assoc));
7501 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
7502 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
7504 Chars (Corresponding_Discriminant (Entity (Discrim))) =
7505 Chars (Discrim_Name))
7506 or else Chars (Original_Record_Component (Entity (Discrim)))
7507 = Chars (Discrim_Name);
7509 if No (Next (Assoc)) then
7510 if not Is_Constrained (Typ)
7511 and then Is_Derived_Type (Typ)
7512 and then Present (Stored_Constraint (Typ))
7514 -- If the type is a tagged type with inherited discriminants,
7515 -- use the stored constraint on the parent in order to find
7516 -- the values of discriminants that are otherwise hidden by an
7517 -- explicit constraint. Renamed discriminants are handled in
7520 -- If several parent discriminants are renamed by a single
7521 -- discriminant of the derived type, the call to obtain the
7522 -- Corresponding_Discriminant field only retrieves the last
7523 -- of them. We recover the constraint on the others from the
7524 -- Stored_Constraint as well.
7531 D := First_Discriminant (Etype (Typ));
7532 C := First_Elmt (Stored_Constraint (Typ));
7533 while Present (D) and then Present (C) loop
7534 if Chars (Discrim_Name) = Chars (D) then
7535 if Is_Entity_Name (Node (C))
7536 and then Entity (Node (C)) = Entity (Discrim)
7538 -- D is renamed by Discrim, whose value is given in
7545 Make_Component_Association (Sloc (Typ),
7547 (New_Occurrence_Of (D, Sloc (Typ))),
7548 Duplicate_Subexpr_No_Checks (Node (C)));
7550 exit Find_Constraint;
7553 Next_Discriminant (D);
7560 if No (Next (Assoc)) then
7561 Error_Msg_NE (" missing value for discriminant&",
7562 First (Governed_By), Discrim_Name);
7563 Report_Errors := True;
7568 end loop Find_Constraint;
7570 Discrim_Value := Expression (Assoc);
7572 if not Is_OK_Static_Expression (Discrim_Value) then
7574 -- If the variant part is governed by a discriminant of the type
7575 -- this is an error. If the variant part and the discriminant are
7576 -- inherited from an ancestor this is legal (AI05-120) unless the
7577 -- components are being gathered for an aggregate, in which case
7578 -- the caller must check Report_Errors.
7580 if Scope (Original_Record_Component
7581 ((Entity (First (Choices (Assoc)))))) = Typ
7584 ("value for discriminant & must be static!",
7585 Discrim_Value, Discrim);
7586 Why_Not_Static (Discrim_Value);
7589 Report_Errors := True;
7593 Search_For_Discriminant_Value : declare
7599 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
7602 Find_Discrete_Value : while Present (Variant) loop
7603 Discrete_Choice := First (Discrete_Choices (Variant));
7604 while Present (Discrete_Choice) loop
7605 exit Find_Discrete_Value when
7606 Nkind (Discrete_Choice) = N_Others_Choice;
7608 Get_Index_Bounds (Discrete_Choice, Low, High);
7610 UI_Low := Expr_Value (Low);
7611 UI_High := Expr_Value (High);
7613 exit Find_Discrete_Value when
7614 UI_Low <= UI_Discrim_Value
7616 UI_High >= UI_Discrim_Value;
7618 Next (Discrete_Choice);
7621 Next_Non_Pragma (Variant);
7622 end loop Find_Discrete_Value;
7623 end Search_For_Discriminant_Value;
7625 if No (Variant) then
7627 ("value of discriminant & is out of range", Discrim_Value, Discrim);
7628 Report_Errors := True;
7632 -- If we have found the corresponding choice, recursively add its
7633 -- components to the Into list. The nested components are part of
7634 -- the same record type.
7637 (Typ, Component_List (Variant), Governed_By, Into, Report_Errors);
7638 end Gather_Components;
7640 ------------------------
7641 -- Get_Actual_Subtype --
7642 ------------------------
7644 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
7645 Typ : constant Entity_Id := Etype (N);
7646 Utyp : Entity_Id := Underlying_Type (Typ);
7655 -- If what we have is an identifier that references a subprogram
7656 -- formal, or a variable or constant object, then we get the actual
7657 -- subtype from the referenced entity if one has been built.
7659 if Nkind (N) = N_Identifier
7661 (Is_Formal (Entity (N))
7662 or else Ekind (Entity (N)) = E_Constant
7663 or else Ekind (Entity (N)) = E_Variable)
7664 and then Present (Actual_Subtype (Entity (N)))
7666 return Actual_Subtype (Entity (N));
7668 -- Actual subtype of unchecked union is always itself. We never need
7669 -- the "real" actual subtype. If we did, we couldn't get it anyway
7670 -- because the discriminant is not available. The restrictions on
7671 -- Unchecked_Union are designed to make sure that this is OK.
7673 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
7676 -- Here for the unconstrained case, we must find actual subtype
7677 -- No actual subtype is available, so we must build it on the fly.
7679 -- Checking the type, not the underlying type, for constrainedness
7680 -- seems to be necessary. Maybe all the tests should be on the type???
7682 elsif (not Is_Constrained (Typ))
7683 and then (Is_Array_Type (Utyp)
7684 or else (Is_Record_Type (Utyp)
7685 and then Has_Discriminants (Utyp)))
7686 and then not Has_Unknown_Discriminants (Utyp)
7687 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
7689 -- Nothing to do if in spec expression (why not???)
7691 if In_Spec_Expression then
7694 elsif Is_Private_Type (Typ) and then not Has_Discriminants (Typ) then
7696 -- If the type has no discriminants, there is no subtype to
7697 -- build, even if the underlying type is discriminated.
7701 -- Else build the actual subtype
7704 Decl := Build_Actual_Subtype (Typ, N);
7705 Atyp := Defining_Identifier (Decl);
7707 -- If Build_Actual_Subtype generated a new declaration then use it
7711 -- The actual subtype is an Itype, so analyze the declaration,
7712 -- but do not attach it to the tree, to get the type defined.
7714 Set_Parent (Decl, N);
7715 Set_Is_Itype (Atyp);
7716 Analyze (Decl, Suppress => All_Checks);
7717 Set_Associated_Node_For_Itype (Atyp, N);
7718 Set_Has_Delayed_Freeze (Atyp, False);
7720 -- We need to freeze the actual subtype immediately. This is
7721 -- needed, because otherwise this Itype will not get frozen
7722 -- at all, and it is always safe to freeze on creation because
7723 -- any associated types must be frozen at this point.
7725 Freeze_Itype (Atyp, N);
7728 -- Otherwise we did not build a declaration, so return original
7735 -- For all remaining cases, the actual subtype is the same as
7736 -- the nominal type.
7741 end Get_Actual_Subtype;
7743 -------------------------------------
7744 -- Get_Actual_Subtype_If_Available --
7745 -------------------------------------
7747 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
7748 Typ : constant Entity_Id := Etype (N);
7751 -- If what we have is an identifier that references a subprogram
7752 -- formal, or a variable or constant object, then we get the actual
7753 -- subtype from the referenced entity if one has been built.
7755 if Nkind (N) = N_Identifier
7757 (Is_Formal (Entity (N))
7758 or else Ekind (Entity (N)) = E_Constant
7759 or else Ekind (Entity (N)) = E_Variable)
7760 and then Present (Actual_Subtype (Entity (N)))
7762 return Actual_Subtype (Entity (N));
7764 -- Otherwise the Etype of N is returned unchanged
7769 end Get_Actual_Subtype_If_Available;
7771 ------------------------
7772 -- Get_Body_From_Stub --
7773 ------------------------
7775 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
7777 return Proper_Body (Unit (Library_Unit (N)));
7778 end Get_Body_From_Stub;
7780 ---------------------
7781 -- Get_Cursor_Type --
7782 ---------------------
7784 function Get_Cursor_Type
7786 Typ : Entity_Id) return Entity_Id
7790 First_Op : Entity_Id;
7794 -- If error already detected, return
7796 if Error_Posted (Aspect) then
7800 -- The cursor type for an Iterable aspect is the return type of a
7801 -- non-overloaded First primitive operation. Locate association for
7804 Assoc := First (Component_Associations (Expression (Aspect)));
7806 while Present (Assoc) loop
7807 if Chars (First (Choices (Assoc))) = Name_First then
7808 First_Op := Expression (Assoc);
7815 if First_Op = Any_Id then
7816 Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
7822 -- Locate function with desired name and profile in scope of type
7823 -- In the rare case where the type is an integer type, a base type
7824 -- is created for it, check that the base type of the first formal
7825 -- of First matches the base type of the domain.
7827 Func := First_Entity (Scope (Typ));
7828 while Present (Func) loop
7829 if Chars (Func) = Chars (First_Op)
7830 and then Ekind (Func) = E_Function
7831 and then Present (First_Formal (Func))
7832 and then Base_Type (Etype (First_Formal (Func))) = Base_Type (Typ)
7833 and then No (Next_Formal (First_Formal (Func)))
7835 if Cursor /= Any_Type then
7837 ("Operation First for iterable type must be unique", Aspect);
7840 Cursor := Etype (Func);
7847 -- If not found, no way to resolve remaining primitives.
7849 if Cursor = Any_Type then
7851 ("No legal primitive operation First for Iterable type", Aspect);
7855 end Get_Cursor_Type;
7857 function Get_Cursor_Type (Typ : Entity_Id) return Entity_Id is
7859 return Etype (Get_Iterable_Type_Primitive (Typ, Name_First));
7860 end Get_Cursor_Type;
7862 -------------------------------
7863 -- Get_Default_External_Name --
7864 -------------------------------
7866 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
7868 Get_Decoded_Name_String (Chars (E));
7870 if Opt.External_Name_Imp_Casing = Uppercase then
7871 Set_Casing (All_Upper_Case);
7873 Set_Casing (All_Lower_Case);
7877 Make_String_Literal (Sloc (E),
7878 Strval => String_From_Name_Buffer);
7879 end Get_Default_External_Name;
7881 --------------------------
7882 -- Get_Enclosing_Object --
7883 --------------------------
7885 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
7887 if Is_Entity_Name (N) then
7891 when N_Indexed_Component |
7893 N_Selected_Component =>
7895 -- If not generating code, a dereference may be left implicit.
7896 -- In thoses cases, return Empty.
7898 if Is_Access_Type (Etype (Prefix (N))) then
7901 return Get_Enclosing_Object (Prefix (N));
7904 when N_Type_Conversion =>
7905 return Get_Enclosing_Object (Expression (N));
7911 end Get_Enclosing_Object;
7913 ---------------------------
7914 -- Get_Enum_Lit_From_Pos --
7915 ---------------------------
7917 function Get_Enum_Lit_From_Pos
7920 Loc : Source_Ptr) return Node_Id
7922 Btyp : Entity_Id := Base_Type (T);
7926 -- In the case where the literal is of type Character, Wide_Character
7927 -- or Wide_Wide_Character or of a type derived from them, there needs
7928 -- to be some special handling since there is no explicit chain of
7929 -- literals to search. Instead, an N_Character_Literal node is created
7930 -- with the appropriate Char_Code and Chars fields.
7932 if Is_Standard_Character_Type (T) then
7933 Set_Character_Literal_Name (UI_To_CC (Pos));
7935 Make_Character_Literal (Loc,
7937 Char_Literal_Value => Pos);
7939 -- For all other cases, we have a complete table of literals, and
7940 -- we simply iterate through the chain of literal until the one
7941 -- with the desired position value is found.
7944 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
7945 Btyp := Full_View (Btyp);
7948 Lit := First_Literal (Btyp);
7949 for J in 1 .. UI_To_Int (Pos) loop
7953 return New_Occurrence_Of (Lit, Loc);
7955 end Get_Enum_Lit_From_Pos;
7957 ------------------------
7958 -- Get_Generic_Entity --
7959 ------------------------
7961 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
7962 Ent : constant Entity_Id := Entity (Name (N));
7964 if Present (Renamed_Object (Ent)) then
7965 return Renamed_Object (Ent);
7969 end Get_Generic_Entity;
7971 -------------------------------------
7972 -- Get_Incomplete_View_Of_Ancestor --
7973 -------------------------------------
7975 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
7976 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
7977 Par_Scope : Entity_Id;
7978 Par_Type : Entity_Id;
7981 -- The incomplete view of an ancestor is only relevant for private
7982 -- derived types in child units.
7984 if not Is_Derived_Type (E)
7985 or else not Is_Child_Unit (Cur_Unit)
7990 Par_Scope := Scope (Cur_Unit);
7991 if No (Par_Scope) then
7995 Par_Type := Etype (Base_Type (E));
7997 -- Traverse list of ancestor types until we find one declared in
7998 -- a parent or grandparent unit (two levels seem sufficient).
8000 while Present (Par_Type) loop
8001 if Scope (Par_Type) = Par_Scope
8002 or else Scope (Par_Type) = Scope (Par_Scope)
8006 elsif not Is_Derived_Type (Par_Type) then
8010 Par_Type := Etype (Base_Type (Par_Type));
8014 -- If none found, there is no relevant ancestor type.
8018 end Get_Incomplete_View_Of_Ancestor;
8020 ----------------------
8021 -- Get_Index_Bounds --
8022 ----------------------
8024 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
8025 Kind : constant Node_Kind := Nkind (N);
8029 if Kind = N_Range then
8031 H := High_Bound (N);
8033 elsif Kind = N_Subtype_Indication then
8034 R := Range_Expression (Constraint (N));
8042 L := Low_Bound (Range_Expression (Constraint (N)));
8043 H := High_Bound (Range_Expression (Constraint (N)));
8046 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
8047 if Error_Posted (Scalar_Range (Entity (N))) then
8051 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
8052 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
8055 L := Low_Bound (Scalar_Range (Entity (N)));
8056 H := High_Bound (Scalar_Range (Entity (N)));
8060 -- N is an expression, indicating a range with one value
8065 end Get_Index_Bounds;
8067 ---------------------------------
8068 -- Get_Iterable_Type_Primitive --
8069 ---------------------------------
8071 function Get_Iterable_Type_Primitive
8073 Nam : Name_Id) return Entity_Id
8075 Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
8083 Assoc := First (Component_Associations (Funcs));
8084 while Present (Assoc) loop
8085 if Chars (First (Choices (Assoc))) = Nam then
8086 return Entity (Expression (Assoc));
8089 Assoc := Next (Assoc);
8094 end Get_Iterable_Type_Primitive;
8096 ----------------------------------
8097 -- Get_Library_Unit_Name_string --
8098 ----------------------------------
8100 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
8101 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
8104 Get_Unit_Name_String (Unit_Name_Id);
8106 -- Remove seven last character (" (spec)" or " (body)")
8108 Name_Len := Name_Len - 7;
8109 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
8110 end Get_Library_Unit_Name_String;
8112 ------------------------
8113 -- Get_Name_Entity_Id --
8114 ------------------------
8116 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
8118 return Entity_Id (Get_Name_Table_Int (Id));
8119 end Get_Name_Entity_Id;
8121 ------------------------------
8122 -- Get_Name_From_CTC_Pragma --
8123 ------------------------------
8125 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
8126 Arg : constant Node_Id :=
8127 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
8129 return Strval (Expr_Value_S (Arg));
8130 end Get_Name_From_CTC_Pragma;
8132 -----------------------
8133 -- Get_Parent_Entity --
8134 -----------------------
8136 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
8138 if Nkind (Unit) = N_Package_Body
8139 and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
8141 return Defining_Entity
8142 (Specification (Instance_Spec (Original_Node (Unit))));
8143 elsif Nkind (Unit) = N_Package_Instantiation then
8144 return Defining_Entity (Specification (Instance_Spec (Unit)));
8146 return Defining_Entity (Unit);
8148 end Get_Parent_Entity;
8154 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
8156 return Get_Pragma_Id (Pragma_Name (N));
8159 -----------------------
8160 -- Get_Reason_String --
8161 -----------------------
8163 procedure Get_Reason_String (N : Node_Id) is
8165 if Nkind (N) = N_String_Literal then
8166 Store_String_Chars (Strval (N));
8168 elsif Nkind (N) = N_Op_Concat then
8169 Get_Reason_String (Left_Opnd (N));
8170 Get_Reason_String (Right_Opnd (N));
8172 -- If not of required form, error
8176 ("Reason for pragma Warnings has wrong form", N);
8178 ("\must be string literal or concatenation of string literals", N);
8181 end Get_Reason_String;
8183 --------------------------------
8184 -- Get_Reference_Discriminant --
8185 --------------------------------
8187 function Get_Reference_Discriminant (Typ : Entity_Id) return Entity_Id is
8191 D := First_Discriminant (Typ);
8192 while Present (D) loop
8193 if Has_Implicit_Dereference (D) then
8196 Next_Discriminant (D);
8200 end Get_Reference_Discriminant;
8202 ---------------------------
8203 -- Get_Referenced_Object --
8204 ---------------------------
8206 function Get_Referenced_Object (N : Node_Id) return Node_Id is
8211 while Is_Entity_Name (R)
8212 and then Present (Renamed_Object (Entity (R)))
8214 R := Renamed_Object (Entity (R));
8218 end Get_Referenced_Object;
8220 ------------------------
8221 -- Get_Renamed_Entity --
8222 ------------------------
8224 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
8229 while Present (Renamed_Entity (R)) loop
8230 R := Renamed_Entity (R);
8234 end Get_Renamed_Entity;
8236 -----------------------
8237 -- Get_Return_Object --
8238 -----------------------
8240 function Get_Return_Object (N : Node_Id) return Entity_Id is
8244 Decl := First (Return_Object_Declarations (N));
8245 while Present (Decl) loop
8246 exit when Nkind (Decl) = N_Object_Declaration
8247 and then Is_Return_Object (Defining_Identifier (Decl));
8251 pragma Assert (Present (Decl));
8252 return Defining_Identifier (Decl);
8253 end Get_Return_Object;
8255 ---------------------------
8256 -- Get_Subprogram_Entity --
8257 ---------------------------
8259 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
8261 Subp_Id : Entity_Id;
8264 if Nkind (Nod) = N_Accept_Statement then
8265 Subp := Entry_Direct_Name (Nod);
8267 elsif Nkind (Nod) = N_Slice then
8268 Subp := Prefix (Nod);
8274 -- Strip the subprogram call
8277 if Nkind_In (Subp, N_Explicit_Dereference,
8278 N_Indexed_Component,
8279 N_Selected_Component)
8281 Subp := Prefix (Subp);
8283 elsif Nkind_In (Subp, N_Type_Conversion,
8284 N_Unchecked_Type_Conversion)
8286 Subp := Expression (Subp);
8293 -- Extract the entity of the subprogram call
8295 if Is_Entity_Name (Subp) then
8296 Subp_Id := Entity (Subp);
8298 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
8299 Subp_Id := Directly_Designated_Type (Subp_Id);
8302 if Is_Subprogram (Subp_Id) then
8308 -- The search did not find a construct that denotes a subprogram
8313 end Get_Subprogram_Entity;
8315 -----------------------------
8316 -- Get_Task_Body_Procedure --
8317 -----------------------------
8319 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
8321 -- Note: A task type may be the completion of a private type with
8322 -- discriminants. When performing elaboration checks on a task
8323 -- declaration, the current view of the type may be the private one,
8324 -- and the procedure that holds the body of the task is held in its
8327 -- This is an odd function, why not have Task_Body_Procedure do
8328 -- the following digging???
8330 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
8331 end Get_Task_Body_Procedure;
8333 -------------------------
8334 -- Get_User_Defined_Eq --
8335 -------------------------
8337 function Get_User_Defined_Eq (E : Entity_Id) return Entity_Id is
8342 Prim := First_Elmt (Collect_Primitive_Operations (E));
8343 while Present (Prim) loop
8346 if Chars (Op) = Name_Op_Eq
8347 and then Etype (Op) = Standard_Boolean
8348 and then Etype (First_Formal (Op)) = E
8349 and then Etype (Next_Formal (First_Formal (Op))) = E
8358 end Get_User_Defined_Eq;
8360 -----------------------
8361 -- Has_Access_Values --
8362 -----------------------
8364 function Has_Access_Values (T : Entity_Id) return Boolean is
8365 Typ : constant Entity_Id := Underlying_Type (T);
8368 -- Case of a private type which is not completed yet. This can only
8369 -- happen in the case of a generic format type appearing directly, or
8370 -- as a component of the type to which this function is being applied
8371 -- at the top level. Return False in this case, since we certainly do
8372 -- not know that the type contains access types.
8377 elsif Is_Access_Type (Typ) then
8380 elsif Is_Array_Type (Typ) then
8381 return Has_Access_Values (Component_Type (Typ));
8383 elsif Is_Record_Type (Typ) then
8388 -- Loop to Check components
8390 Comp := First_Component_Or_Discriminant (Typ);
8391 while Present (Comp) loop
8393 -- Check for access component, tag field does not count, even
8394 -- though it is implemented internally using an access type.
8396 if Has_Access_Values (Etype (Comp))
8397 and then Chars (Comp) /= Name_uTag
8402 Next_Component_Or_Discriminant (Comp);
8411 end Has_Access_Values;
8413 ------------------------------
8414 -- Has_Compatible_Alignment --
8415 ------------------------------
8417 function Has_Compatible_Alignment
8420 Layout_Done : Boolean) return Alignment_Result
8422 function Has_Compatible_Alignment_Internal
8425 Layout_Done : Boolean;
8426 Default : Alignment_Result) return Alignment_Result;
8427 -- This is the internal recursive function that actually does the work.
8428 -- There is one additional parameter, which says what the result should
8429 -- be if no alignment information is found, and there is no definite
8430 -- indication of compatible alignments. At the outer level, this is set
8431 -- to Unknown, but for internal recursive calls in the case where types
8432 -- are known to be correct, it is set to Known_Compatible.
8434 ---------------------------------------
8435 -- Has_Compatible_Alignment_Internal --
8436 ---------------------------------------
8438 function Has_Compatible_Alignment_Internal
8441 Layout_Done : Boolean;
8442 Default : Alignment_Result) return Alignment_Result
8444 Result : Alignment_Result := Known_Compatible;
8445 -- Holds the current status of the result. Note that once a value of
8446 -- Known_Incompatible is set, it is sticky and does not get changed
8447 -- to Unknown (the value in Result only gets worse as we go along,
8450 Offs : Uint := No_Uint;
8451 -- Set to a factor of the offset from the base object when Expr is a
8452 -- selected or indexed component, based on Component_Bit_Offset and
8453 -- Component_Size respectively. A negative value is used to represent
8454 -- a value which is not known at compile time.
8456 procedure Check_Prefix;
8457 -- Checks the prefix recursively in the case where the expression
8458 -- is an indexed or selected component.
8460 procedure Set_Result (R : Alignment_Result);
8461 -- If R represents a worse outcome (unknown instead of known
8462 -- compatible, or known incompatible), then set Result to R.
8468 procedure Check_Prefix is
8470 -- The subtlety here is that in doing a recursive call to check
8471 -- the prefix, we have to decide what to do in the case where we
8472 -- don't find any specific indication of an alignment problem.
8474 -- At the outer level, we normally set Unknown as the result in
8475 -- this case, since we can only set Known_Compatible if we really
8476 -- know that the alignment value is OK, but for the recursive
8477 -- call, in the case where the types match, and we have not
8478 -- specified a peculiar alignment for the object, we are only
8479 -- concerned about suspicious rep clauses, the default case does
8480 -- not affect us, since the compiler will, in the absence of such
8481 -- rep clauses, ensure that the alignment is correct.
8483 if Default = Known_Compatible
8485 (Etype (Obj) = Etype (Expr)
8486 and then (Unknown_Alignment (Obj)
8488 Alignment (Obj) = Alignment (Etype (Obj))))
8491 (Has_Compatible_Alignment_Internal
8492 (Obj, Prefix (Expr), Layout_Done, Known_Compatible));
8494 -- In all other cases, we need a full check on the prefix
8498 (Has_Compatible_Alignment_Internal
8499 (Obj, Prefix (Expr), Layout_Done, Unknown));
8507 procedure Set_Result (R : Alignment_Result) is
8514 -- Start of processing for Has_Compatible_Alignment_Internal
8517 -- If Expr is a selected component, we must make sure there is no
8518 -- potentially troublesome component clause and that the record is
8519 -- not packed if the layout is not done.
8521 if Nkind (Expr) = N_Selected_Component then
8523 -- Packing generates unknown alignment if layout is not done
8525 if Is_Packed (Etype (Prefix (Expr))) and then not Layout_Done then
8526 Set_Result (Unknown);
8529 -- Check prefix and component offset
8532 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
8534 -- If Expr is an indexed component, we must make sure there is no
8535 -- potentially troublesome Component_Size clause and that the array
8536 -- is not bit-packed if the layout is not done.
8538 elsif Nkind (Expr) = N_Indexed_Component then
8540 Typ : constant Entity_Id := Etype (Prefix (Expr));
8541 Ind : constant Node_Id := First_Index (Typ);
8544 -- Packing generates unknown alignment if layout is not done
8546 if Is_Bit_Packed_Array (Typ) and then not Layout_Done then
8547 Set_Result (Unknown);
8550 -- Check prefix and component offset
8553 Offs := Component_Size (Typ);
8555 -- Small optimization: compute the full offset when possible
8558 and then Offs > Uint_0
8559 and then Present (Ind)
8560 and then Nkind (Ind) = N_Range
8561 and then Compile_Time_Known_Value (Low_Bound (Ind))
8562 and then Compile_Time_Known_Value (First (Expressions (Expr)))
8564 Offs := Offs * (Expr_Value (First (Expressions (Expr)))
8565 - Expr_Value (Low_Bound ((Ind))));
8570 -- If we have a null offset, the result is entirely determined by
8571 -- the base object and has already been computed recursively.
8573 if Offs = Uint_0 then
8576 -- Case where we know the alignment of the object
8578 elsif Known_Alignment (Obj) then
8580 ObjA : constant Uint := Alignment (Obj);
8581 ExpA : Uint := No_Uint;
8582 SizA : Uint := No_Uint;
8585 -- If alignment of Obj is 1, then we are always OK
8588 Set_Result (Known_Compatible);
8590 -- Alignment of Obj is greater than 1, so we need to check
8593 -- If we have an offset, see if it is compatible
8595 if Offs /= No_Uint and Offs > Uint_0 then
8596 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
8597 Set_Result (Known_Incompatible);
8600 -- See if Expr is an object with known alignment
8602 elsif Is_Entity_Name (Expr)
8603 and then Known_Alignment (Entity (Expr))
8605 ExpA := Alignment (Entity (Expr));
8607 -- Otherwise, we can use the alignment of the type of
8608 -- Expr given that we already checked for
8609 -- discombobulating rep clauses for the cases of indexed
8610 -- and selected components above.
8612 elsif Known_Alignment (Etype (Expr)) then
8613 ExpA := Alignment (Etype (Expr));
8615 -- Otherwise the alignment is unknown
8618 Set_Result (Default);
8621 -- If we got an alignment, see if it is acceptable
8623 if ExpA /= No_Uint and then ExpA < ObjA then
8624 Set_Result (Known_Incompatible);
8627 -- If Expr is not a piece of a larger object, see if size
8628 -- is given. If so, check that it is not too small for the
8629 -- required alignment.
8631 if Offs /= No_Uint then
8634 -- See if Expr is an object with known size
8636 elsif Is_Entity_Name (Expr)
8637 and then Known_Static_Esize (Entity (Expr))
8639 SizA := Esize (Entity (Expr));
8641 -- Otherwise, we check the object size of the Expr type
8643 elsif Known_Static_Esize (Etype (Expr)) then
8644 SizA := Esize (Etype (Expr));
8647 -- If we got a size, see if it is a multiple of the Obj
8648 -- alignment, if not, then the alignment cannot be
8649 -- acceptable, since the size is always a multiple of the
8652 if SizA /= No_Uint then
8653 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
8654 Set_Result (Known_Incompatible);
8660 -- If we do not know required alignment, any non-zero offset is a
8661 -- potential problem (but certainly may be OK, so result is unknown).
8663 elsif Offs /= No_Uint then
8664 Set_Result (Unknown);
8666 -- If we can't find the result by direct comparison of alignment
8667 -- values, then there is still one case that we can determine known
8668 -- result, and that is when we can determine that the types are the
8669 -- same, and no alignments are specified. Then we known that the
8670 -- alignments are compatible, even if we don't know the alignment
8671 -- value in the front end.
8673 elsif Etype (Obj) = Etype (Expr) then
8675 -- Types are the same, but we have to check for possible size
8676 -- and alignments on the Expr object that may make the alignment
8677 -- different, even though the types are the same.
8679 if Is_Entity_Name (Expr) then
8681 -- First check alignment of the Expr object. Any alignment less
8682 -- than Maximum_Alignment is worrisome since this is the case
8683 -- where we do not know the alignment of Obj.
8685 if Known_Alignment (Entity (Expr))
8686 and then UI_To_Int (Alignment (Entity (Expr))) <
8687 Ttypes.Maximum_Alignment
8689 Set_Result (Unknown);
8691 -- Now check size of Expr object. Any size that is not an
8692 -- even multiple of Maximum_Alignment is also worrisome
8693 -- since it may cause the alignment of the object to be less
8694 -- than the alignment of the type.
8696 elsif Known_Static_Esize (Entity (Expr))
8698 (UI_To_Int (Esize (Entity (Expr))) mod
8699 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
8702 Set_Result (Unknown);
8704 -- Otherwise same type is decisive
8707 Set_Result (Known_Compatible);
8711 -- Another case to deal with is when there is an explicit size or
8712 -- alignment clause when the types are not the same. If so, then the
8713 -- result is Unknown. We don't need to do this test if the Default is
8714 -- Unknown, since that result will be set in any case.
8716 elsif Default /= Unknown
8717 and then (Has_Size_Clause (Etype (Expr))
8719 Has_Alignment_Clause (Etype (Expr)))
8721 Set_Result (Unknown);
8723 -- If no indication found, set default
8726 Set_Result (Default);
8729 -- Return worst result found
8732 end Has_Compatible_Alignment_Internal;
8734 -- Start of processing for Has_Compatible_Alignment
8737 -- If Obj has no specified alignment, then set alignment from the type
8738 -- alignment. Perhaps we should always do this, but for sure we should
8739 -- do it when there is an address clause since we can do more if the
8740 -- alignment is known.
8742 if Unknown_Alignment (Obj) then
8743 Set_Alignment (Obj, Alignment (Etype (Obj)));
8746 -- Now do the internal call that does all the work
8749 Has_Compatible_Alignment_Internal (Obj, Expr, Layout_Done, Unknown);
8750 end Has_Compatible_Alignment;
8752 ----------------------
8753 -- Has_Declarations --
8754 ----------------------
8756 function Has_Declarations (N : Node_Id) return Boolean is
8758 return Nkind_In (Nkind (N), N_Accept_Statement,
8760 N_Compilation_Unit_Aux,
8766 N_Package_Specification);
8767 end Has_Declarations;
8769 ---------------------------------
8770 -- Has_Defaulted_Discriminants --
8771 ---------------------------------
8773 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
8775 return Has_Discriminants (Typ)
8776 and then Present (First_Discriminant (Typ))
8777 and then Present (Discriminant_Default_Value
8778 (First_Discriminant (Typ)));
8779 end Has_Defaulted_Discriminants;
8785 function Has_Denormals (E : Entity_Id) return Boolean is
8787 return Is_Floating_Point_Type (E) and then Denorm_On_Target;
8790 -------------------------------------------
8791 -- Has_Discriminant_Dependent_Constraint --
8792 -------------------------------------------
8794 function Has_Discriminant_Dependent_Constraint
8795 (Comp : Entity_Id) return Boolean
8797 Comp_Decl : constant Node_Id := Parent (Comp);
8798 Subt_Indic : Node_Id;
8803 -- Discriminants can't depend on discriminants
8805 if Ekind (Comp) = E_Discriminant then
8809 Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl));
8811 if Nkind (Subt_Indic) = N_Subtype_Indication then
8812 Constr := Constraint (Subt_Indic);
8814 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
8815 Assn := First (Constraints (Constr));
8816 while Present (Assn) loop
8817 case Nkind (Assn) is
8818 when N_Subtype_Indication |
8822 if Depends_On_Discriminant (Assn) then
8826 when N_Discriminant_Association =>
8827 if Depends_On_Discriminant (Expression (Assn)) then
8842 end Has_Discriminant_Dependent_Constraint;
8844 --------------------------------------
8845 -- Has_Effectively_Volatile_Profile --
8846 --------------------------------------
8848 function Has_Effectively_Volatile_Profile
8849 (Subp_Id : Entity_Id) return Boolean
8854 -- Inspect the formal parameters looking for an effectively volatile
8857 Formal := First_Formal (Subp_Id);
8858 while Present (Formal) loop
8859 if Is_Effectively_Volatile (Etype (Formal)) then
8863 Next_Formal (Formal);
8866 -- Inspect the return type of functions
8868 if Ekind_In (Subp_Id, E_Function, E_Generic_Function)
8869 and then Is_Effectively_Volatile (Etype (Subp_Id))
8875 end Has_Effectively_Volatile_Profile;
8877 --------------------------
8878 -- Has_Enabled_Property --
8879 --------------------------
8881 function Has_Enabled_Property
8882 (Item_Id : Entity_Id;
8883 Property : Name_Id) return Boolean
8885 function State_Has_Enabled_Property return Boolean;
8886 -- Determine whether a state denoted by Item_Id has the property enabled
8888 function Variable_Has_Enabled_Property return Boolean;
8889 -- Determine whether a variable denoted by Item_Id has the property
8892 --------------------------------
8893 -- State_Has_Enabled_Property --
8894 --------------------------------
8896 function State_Has_Enabled_Property return Boolean is
8897 Decl : constant Node_Id := Parent (Item_Id);
8905 -- The declaration of an external abstract state appears as an
8906 -- extension aggregate. If this is not the case, properties can never
8909 if Nkind (Decl) /= N_Extension_Aggregate then
8913 -- When External appears as a simple option, it automatically enables
8916 Opt := First (Expressions (Decl));
8917 while Present (Opt) loop
8918 if Nkind (Opt) = N_Identifier
8919 and then Chars (Opt) = Name_External
8927 -- When External specifies particular properties, inspect those and
8928 -- find the desired one (if any).
8930 Opt := First (Component_Associations (Decl));
8931 while Present (Opt) loop
8932 Opt_Nam := First (Choices (Opt));
8934 if Nkind (Opt_Nam) = N_Identifier
8935 and then Chars (Opt_Nam) = Name_External
8937 Props := Expression (Opt);
8939 -- Multiple properties appear as an aggregate
8941 if Nkind (Props) = N_Aggregate then
8943 -- Simple property form
8945 Prop := First (Expressions (Props));
8946 while Present (Prop) loop
8947 if Chars (Prop) = Property then
8954 -- Property with expression form
8956 Prop := First (Component_Associations (Props));
8957 while Present (Prop) loop
8958 Prop_Nam := First (Choices (Prop));
8960 -- The property can be represented in two ways:
8961 -- others => <value>
8962 -- <property> => <value>
8964 if Nkind (Prop_Nam) = N_Others_Choice
8965 or else (Nkind (Prop_Nam) = N_Identifier
8966 and then Chars (Prop_Nam) = Property)
8968 return Is_True (Expr_Value (Expression (Prop)));
8977 return Chars (Props) = Property;
8985 end State_Has_Enabled_Property;
8987 -----------------------------------
8988 -- Variable_Has_Enabled_Property --
8989 -----------------------------------
8991 function Variable_Has_Enabled_Property return Boolean is
8992 function Is_Enabled (Prag : Node_Id) return Boolean;
8993 -- Determine whether property pragma Prag (if present) denotes an
8994 -- enabled property.
9000 function Is_Enabled (Prag : Node_Id) return Boolean is
9004 if Present (Prag) then
9005 Arg1 := First (Pragma_Argument_Associations (Prag));
9007 -- The pragma has an optional Boolean expression, the related
9008 -- property is enabled only when the expression evaluates to
9011 if Present (Arg1) then
9012 return Is_True (Expr_Value (Get_Pragma_Arg (Arg1)));
9014 -- Otherwise the lack of expression enables the property by
9021 -- The property was never set in the first place
9030 AR : constant Node_Id :=
9031 Get_Pragma (Item_Id, Pragma_Async_Readers);
9032 AW : constant Node_Id :=
9033 Get_Pragma (Item_Id, Pragma_Async_Writers);
9034 ER : constant Node_Id :=
9035 Get_Pragma (Item_Id, Pragma_Effective_Reads);
9036 EW : constant Node_Id :=
9037 Get_Pragma (Item_Id, Pragma_Effective_Writes);
9039 -- Start of processing for Variable_Has_Enabled_Property
9042 -- A non-effectively volatile object can never possess external
9045 if not Is_Effectively_Volatile (Item_Id) then
9048 -- External properties related to variables come in two flavors -
9049 -- explicit and implicit. The explicit case is characterized by the
9050 -- presence of a property pragma with an optional Boolean flag. The
9051 -- property is enabled when the flag evaluates to True or the flag is
9052 -- missing altogether.
9054 elsif Property = Name_Async_Readers and then Is_Enabled (AR) then
9057 elsif Property = Name_Async_Writers and then Is_Enabled (AW) then
9060 elsif Property = Name_Effective_Reads and then Is_Enabled (ER) then
9063 elsif Property = Name_Effective_Writes and then Is_Enabled (EW) then
9066 -- The implicit case lacks all property pragmas
9068 elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then
9074 end Variable_Has_Enabled_Property;
9076 -- Start of processing for Has_Enabled_Property
9079 -- Abstract states and variables have a flexible scheme of specifying
9080 -- external properties.
9082 if Ekind (Item_Id) = E_Abstract_State then
9083 return State_Has_Enabled_Property;
9085 elsif Ekind (Item_Id) = E_Variable then
9086 return Variable_Has_Enabled_Property;
9088 -- Otherwise a property is enabled when the related item is effectively
9092 return Is_Effectively_Volatile (Item_Id);
9094 end Has_Enabled_Property;
9096 -------------------------------------
9097 -- Has_Full_Default_Initialization --
9098 -------------------------------------
9100 function Has_Full_Default_Initialization (Typ : Entity_Id) return Boolean is
9106 -- A private type and its full view is fully default initialized when it
9107 -- is subject to pragma Default_Initial_Condition without an argument or
9108 -- with a non-null argument. Since any type may act as the full view of
9109 -- a private type, this check must be performed prior to the specialized
9112 if Has_Default_Init_Cond (Typ)
9113 or else Has_Inherited_Default_Init_Cond (Typ)
9115 Prag := Get_Pragma (Typ, Pragma_Default_Initial_Condition);
9117 -- Pragma Default_Initial_Condition must be present if one of the
9118 -- related entity flags is set.
9120 pragma Assert (Present (Prag));
9121 Arg := First (Pragma_Argument_Associations (Prag));
9123 -- A non-null argument guarantees full default initialization
9125 if Present (Arg) then
9126 return Nkind (Arg) /= N_Null;
9128 -- Otherwise the missing argument defaults the pragma to "True" which
9129 -- is considered a non-null argument (see above).
9136 -- A scalar type is fully default initialized if it is subject to aspect
9139 if Is_Scalar_Type (Typ) then
9140 return Has_Default_Aspect (Typ);
9142 -- An array type is fully default initialized if its element type is
9143 -- scalar and the array type carries aspect Default_Component_Value or
9144 -- the element type is fully default initialized.
9146 elsif Is_Array_Type (Typ) then
9148 Has_Default_Aspect (Typ)
9149 or else Has_Full_Default_Initialization (Component_Type (Typ));
9151 -- A protected type, record type or type extension is fully default
9152 -- initialized if all its components either carry an initialization
9153 -- expression or have a type that is fully default initialized. The
9154 -- parent type of a type extension must be fully default initialized.
9156 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
9158 -- Inspect all entities defined in the scope of the type, looking for
9159 -- uninitialized components.
9161 Comp := First_Entity (Typ);
9162 while Present (Comp) loop
9163 if Ekind (Comp) = E_Component
9164 and then Comes_From_Source (Comp)
9165 and then No (Expression (Parent (Comp)))
9166 and then not Has_Full_Default_Initialization (Etype (Comp))
9174 -- Ensure that the parent type of a type extension is fully default
9177 if Etype (Typ) /= Typ
9178 and then not Has_Full_Default_Initialization (Etype (Typ))
9183 -- If we get here, then all components and parent portion are fully
9184 -- default initialized.
9188 -- A task type is fully default initialized by default
9190 elsif Is_Task_Type (Typ) then
9193 -- Otherwise the type is not fully default initialized
9198 end Has_Full_Default_Initialization;
9200 --------------------
9201 -- Has_Infinities --
9202 --------------------
9204 function Has_Infinities (E : Entity_Id) return Boolean is
9207 Is_Floating_Point_Type (E)
9208 and then Nkind (Scalar_Range (E)) = N_Range
9209 and then Includes_Infinities (Scalar_Range (E));
9212 --------------------
9213 -- Has_Interfaces --
9214 --------------------
9216 function Has_Interfaces
9218 Use_Full_View : Boolean := True) return Boolean
9220 Typ : Entity_Id := Base_Type (T);
9223 -- Handle concurrent types
9225 if Is_Concurrent_Type (Typ) then
9226 Typ := Corresponding_Record_Type (Typ);
9229 if not Present (Typ)
9230 or else not Is_Record_Type (Typ)
9231 or else not Is_Tagged_Type (Typ)
9236 -- Handle private types
9238 if Use_Full_View and then Present (Full_View (Typ)) then
9239 Typ := Full_View (Typ);
9242 -- Handle concurrent record types
9244 if Is_Concurrent_Record_Type (Typ)
9245 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
9251 if Is_Interface (Typ)
9253 (Is_Record_Type (Typ)
9254 and then Present (Interfaces (Typ))
9255 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
9260 exit when Etype (Typ) = Typ
9262 -- Handle private types
9264 or else (Present (Full_View (Etype (Typ)))
9265 and then Full_View (Etype (Typ)) = Typ)
9267 -- Protect frontend against wrong sources with cyclic derivations
9269 or else Etype (Typ) = T;
9271 -- Climb to the ancestor type handling private types
9273 if Present (Full_View (Etype (Typ))) then
9274 Typ := Full_View (Etype (Typ));
9283 ---------------------------------
9284 -- Has_No_Obvious_Side_Effects --
9285 ---------------------------------
9287 function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
9289 -- For now, just handle literals, constants, and non-volatile
9290 -- variables and expressions combining these with operators or
9291 -- short circuit forms.
9293 if Nkind (N) in N_Numeric_Or_String_Literal then
9296 elsif Nkind (N) = N_Character_Literal then
9299 elsif Nkind (N) in N_Unary_Op then
9300 return Has_No_Obvious_Side_Effects (Right_Opnd (N));
9302 elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
9303 return Has_No_Obvious_Side_Effects (Left_Opnd (N))
9305 Has_No_Obvious_Side_Effects (Right_Opnd (N));
9307 elsif Nkind (N) = N_Expression_With_Actions
9308 and then Is_Empty_List (Actions (N))
9310 return Has_No_Obvious_Side_Effects (Expression (N));
9312 elsif Nkind (N) in N_Has_Entity then
9313 return Present (Entity (N))
9314 and then Ekind_In (Entity (N), E_Variable,
9316 E_Enumeration_Literal,
9320 and then not Is_Volatile (Entity (N));
9325 end Has_No_Obvious_Side_Effects;
9327 -----------------------------
9328 -- Has_Non_Null_Refinement --
9329 -----------------------------
9331 function Has_Non_Null_Refinement (Id : Entity_Id) return Boolean is
9333 pragma Assert (Ekind (Id) = E_Abstract_State);
9335 -- For a refinement to be non-null, the first constituent must be
9336 -- anything other than null.
9338 if Present (Refinement_Constituents (Id)) then
9340 Nkind (Node (First_Elmt (Refinement_Constituents (Id)))) /= N_Null;
9344 end Has_Non_Null_Refinement;
9346 ------------------------
9347 -- Has_Null_Exclusion --
9348 ------------------------
9350 function Has_Null_Exclusion (N : Node_Id) return Boolean is
9353 when N_Access_Definition |
9354 N_Access_Function_Definition |
9355 N_Access_Procedure_Definition |
9356 N_Access_To_Object_Definition |
9358 N_Derived_Type_Definition |
9359 N_Function_Specification |
9360 N_Subtype_Declaration =>
9361 return Null_Exclusion_Present (N);
9363 when N_Component_Definition |
9364 N_Formal_Object_Declaration |
9365 N_Object_Renaming_Declaration =>
9366 if Present (Subtype_Mark (N)) then
9367 return Null_Exclusion_Present (N);
9368 else pragma Assert (Present (Access_Definition (N)));
9369 return Null_Exclusion_Present (Access_Definition (N));
9372 when N_Discriminant_Specification =>
9373 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
9374 return Null_Exclusion_Present (Discriminant_Type (N));
9376 return Null_Exclusion_Present (N);
9379 when N_Object_Declaration =>
9380 if Nkind (Object_Definition (N)) = N_Access_Definition then
9381 return Null_Exclusion_Present (Object_Definition (N));
9383 return Null_Exclusion_Present (N);
9386 when N_Parameter_Specification =>
9387 if Nkind (Parameter_Type (N)) = N_Access_Definition then
9388 return Null_Exclusion_Present (Parameter_Type (N));
9390 return Null_Exclusion_Present (N);
9397 end Has_Null_Exclusion;
9399 ------------------------
9400 -- Has_Null_Extension --
9401 ------------------------
9403 function Has_Null_Extension (T : Entity_Id) return Boolean is
9404 B : constant Entity_Id := Base_Type (T);
9409 if Nkind (Parent (B)) = N_Full_Type_Declaration
9410 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
9412 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
9414 if Present (Ext) then
9415 if Null_Present (Ext) then
9418 Comps := Component_List (Ext);
9420 -- The null component list is rewritten during analysis to
9421 -- include the parent component. Any other component indicates
9422 -- that the extension was not originally null.
9424 return Null_Present (Comps)
9425 or else No (Next (First (Component_Items (Comps))));
9434 end Has_Null_Extension;
9436 -------------------------
9437 -- Has_Null_Refinement --
9438 -------------------------
9440 function Has_Null_Refinement (Id : Entity_Id) return Boolean is
9442 pragma Assert (Ekind (Id) = E_Abstract_State);
9444 -- For a refinement to be null, the state's sole constituent must be a
9447 if Present (Refinement_Constituents (Id)) then
9449 Nkind (Node (First_Elmt (Refinement_Constituents (Id)))) = N_Null;
9453 end Has_Null_Refinement;
9455 -------------------------------
9456 -- Has_Overriding_Initialize --
9457 -------------------------------
9459 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
9460 BT : constant Entity_Id := Base_Type (T);
9464 if Is_Controlled (BT) then
9465 if Is_RTU (Scope (BT), Ada_Finalization) then
9468 elsif Present (Primitive_Operations (BT)) then
9469 P := First_Elmt (Primitive_Operations (BT));
9470 while Present (P) loop
9472 Init : constant Entity_Id := Node (P);
9473 Formal : constant Entity_Id := First_Formal (Init);
9475 if Ekind (Init) = E_Procedure
9476 and then Chars (Init) = Name_Initialize
9477 and then Comes_From_Source (Init)
9478 and then Present (Formal)
9479 and then Etype (Formal) = BT
9480 and then No (Next_Formal (Formal))
9481 and then (Ada_Version < Ada_2012
9482 or else not Null_Present (Parent (Init)))
9492 -- Here if type itself does not have a non-null Initialize operation:
9493 -- check immediate ancestor.
9495 if Is_Derived_Type (BT)
9496 and then Has_Overriding_Initialize (Etype (BT))
9503 end Has_Overriding_Initialize;
9505 --------------------------------------
9506 -- Has_Preelaborable_Initialization --
9507 --------------------------------------
9509 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
9512 procedure Check_Components (E : Entity_Id);
9513 -- Check component/discriminant chain, sets Has_PE False if a component
9514 -- or discriminant does not meet the preelaborable initialization rules.
9516 ----------------------
9517 -- Check_Components --
9518 ----------------------
9520 procedure Check_Components (E : Entity_Id) is
9524 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
9525 -- Returns True if and only if the expression denoted by N does not
9526 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
9528 ---------------------------------
9529 -- Is_Preelaborable_Expression --
9530 ---------------------------------
9532 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
9536 Comp_Type : Entity_Id;
9537 Is_Array_Aggr : Boolean;
9540 if Is_OK_Static_Expression (N) then
9543 elsif Nkind (N) = N_Null then
9546 -- Attributes are allowed in general, even if their prefix is a
9547 -- formal type. (It seems that certain attributes known not to be
9548 -- static might not be allowed, but there are no rules to prevent
9551 elsif Nkind (N) = N_Attribute_Reference then
9554 -- The name of a discriminant evaluated within its parent type is
9555 -- defined to be preelaborable (10.2.1(8)). Note that we test for
9556 -- names that denote discriminals as well as discriminants to
9557 -- catch references occurring within init procs.
9559 elsif Is_Entity_Name (N)
9561 (Ekind (Entity (N)) = E_Discriminant
9562 or else (Ekind_In (Entity (N), E_Constant, E_In_Parameter)
9563 and then Present (Discriminal_Link (Entity (N)))))
9567 elsif Nkind (N) = N_Qualified_Expression then
9568 return Is_Preelaborable_Expression (Expression (N));
9570 -- For aggregates we have to check that each of the associations
9571 -- is preelaborable.
9573 elsif Nkind_In (N, N_Aggregate, N_Extension_Aggregate) then
9574 Is_Array_Aggr := Is_Array_Type (Etype (N));
9576 if Is_Array_Aggr then
9577 Comp_Type := Component_Type (Etype (N));
9580 -- Check the ancestor part of extension aggregates, which must
9581 -- be either the name of a type that has preelaborable init or
9582 -- an expression that is preelaborable.
9584 if Nkind (N) = N_Extension_Aggregate then
9586 Anc_Part : constant Node_Id := Ancestor_Part (N);
9589 if Is_Entity_Name (Anc_Part)
9590 and then Is_Type (Entity (Anc_Part))
9592 if not Has_Preelaborable_Initialization
9598 elsif not Is_Preelaborable_Expression (Anc_Part) then
9604 -- Check positional associations
9606 Exp := First (Expressions (N));
9607 while Present (Exp) loop
9608 if not Is_Preelaborable_Expression (Exp) then
9615 -- Check named associations
9617 Assn := First (Component_Associations (N));
9618 while Present (Assn) loop
9619 Choice := First (Choices (Assn));
9620 while Present (Choice) loop
9621 if Is_Array_Aggr then
9622 if Nkind (Choice) = N_Others_Choice then
9625 elsif Nkind (Choice) = N_Range then
9626 if not Is_OK_Static_Range (Choice) then
9630 elsif not Is_OK_Static_Expression (Choice) then
9635 Comp_Type := Etype (Choice);
9641 -- If the association has a <> at this point, then we have
9642 -- to check whether the component's type has preelaborable
9643 -- initialization. Note that this only occurs when the
9644 -- association's corresponding component does not have a
9645 -- default expression, the latter case having already been
9646 -- expanded as an expression for the association.
9648 if Box_Present (Assn) then
9649 if not Has_Preelaborable_Initialization (Comp_Type) then
9653 -- In the expression case we check whether the expression
9654 -- is preelaborable.
9657 not Is_Preelaborable_Expression (Expression (Assn))
9665 -- If we get here then aggregate as a whole is preelaborable
9669 -- All other cases are not preelaborable
9674 end Is_Preelaborable_Expression;
9676 -- Start of processing for Check_Components
9679 -- Loop through entities of record or protected type
9682 while Present (Ent) loop
9684 -- We are interested only in components and discriminants
9691 -- Get default expression if any. If there is no declaration
9692 -- node, it means we have an internal entity. The parent and
9693 -- tag fields are examples of such entities. For such cases,
9694 -- we just test the type of the entity.
9696 if Present (Declaration_Node (Ent)) then
9697 Exp := Expression (Declaration_Node (Ent));
9700 when E_Discriminant =>
9702 -- Note: for a renamed discriminant, the Declaration_Node
9703 -- may point to the one from the ancestor, and have a
9704 -- different expression, so use the proper attribute to
9705 -- retrieve the expression from the derived constraint.
9707 Exp := Discriminant_Default_Value (Ent);
9710 goto Check_Next_Entity;
9713 -- A component has PI if it has no default expression and the
9714 -- component type has PI.
9717 if not Has_Preelaborable_Initialization (Etype (Ent)) then
9722 -- Require the default expression to be preelaborable
9724 elsif not Is_Preelaborable_Expression (Exp) then
9729 <<Check_Next_Entity>>
9732 end Check_Components;
9734 -- Start of processing for Has_Preelaborable_Initialization
9737 -- Immediate return if already marked as known preelaborable init. This
9738 -- covers types for which this function has already been called once
9739 -- and returned True (in which case the result is cached), and also
9740 -- types to which a pragma Preelaborable_Initialization applies.
9742 if Known_To_Have_Preelab_Init (E) then
9746 -- If the type is a subtype representing a generic actual type, then
9747 -- test whether its base type has preelaborable initialization since
9748 -- the subtype representing the actual does not inherit this attribute
9749 -- from the actual or formal. (but maybe it should???)
9751 if Is_Generic_Actual_Type (E) then
9752 return Has_Preelaborable_Initialization (Base_Type (E));
9755 -- All elementary types have preelaborable initialization
9757 if Is_Elementary_Type (E) then
9760 -- Array types have PI if the component type has PI
9762 elsif Is_Array_Type (E) then
9763 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
9765 -- A derived type has preelaborable initialization if its parent type
9766 -- has preelaborable initialization and (in the case of a derived record
9767 -- extension) if the non-inherited components all have preelaborable
9768 -- initialization. However, a user-defined controlled type with an
9769 -- overriding Initialize procedure does not have preelaborable
9772 elsif Is_Derived_Type (E) then
9774 -- If the derived type is a private extension then it doesn't have
9775 -- preelaborable initialization.
9777 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
9781 -- First check whether ancestor type has preelaborable initialization
9783 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
9785 -- If OK, check extension components (if any)
9787 if Has_PE and then Is_Record_Type (E) then
9788 Check_Components (First_Entity (E));
9791 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
9792 -- with a user defined Initialize procedure does not have PI. If
9793 -- the type is untagged, the control primitives come from a component
9794 -- that has already been checked.
9797 and then Is_Controlled (E)
9798 and then Is_Tagged_Type (E)
9799 and then Has_Overriding_Initialize (E)
9804 -- Private types not derived from a type having preelaborable init and
9805 -- that are not marked with pragma Preelaborable_Initialization do not
9806 -- have preelaborable initialization.
9808 elsif Is_Private_Type (E) then
9811 -- Record type has PI if it is non private and all components have PI
9813 elsif Is_Record_Type (E) then
9815 Check_Components (First_Entity (E));
9817 -- Protected types must not have entries, and components must meet
9818 -- same set of rules as for record components.
9820 elsif Is_Protected_Type (E) then
9821 if Has_Entries (E) then
9825 Check_Components (First_Entity (E));
9826 Check_Components (First_Private_Entity (E));
9829 -- Type System.Address always has preelaborable initialization
9831 elsif Is_RTE (E, RE_Address) then
9834 -- In all other cases, type does not have preelaborable initialization
9840 -- If type has preelaborable initialization, cache result
9843 Set_Known_To_Have_Preelab_Init (E);
9847 end Has_Preelaborable_Initialization;
9849 ---------------------------
9850 -- Has_Private_Component --
9851 ---------------------------
9853 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
9854 Btype : Entity_Id := Base_Type (Type_Id);
9855 Component : Entity_Id;
9858 if Error_Posted (Type_Id)
9859 or else Error_Posted (Btype)
9864 if Is_Class_Wide_Type (Btype) then
9865 Btype := Root_Type (Btype);
9868 if Is_Private_Type (Btype) then
9870 UT : constant Entity_Id := Underlying_Type (Btype);
9873 if No (Full_View (Btype)) then
9874 return not Is_Generic_Type (Btype)
9876 not Is_Generic_Type (Root_Type (Btype));
9878 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
9881 return not Is_Frozen (UT) and then Has_Private_Component (UT);
9885 elsif Is_Array_Type (Btype) then
9886 return Has_Private_Component (Component_Type (Btype));
9888 elsif Is_Record_Type (Btype) then
9889 Component := First_Component (Btype);
9890 while Present (Component) loop
9891 if Has_Private_Component (Etype (Component)) then
9895 Next_Component (Component);
9900 elsif Is_Protected_Type (Btype)
9901 and then Present (Corresponding_Record_Type (Btype))
9903 return Has_Private_Component (Corresponding_Record_Type (Btype));
9908 end Has_Private_Component;
9910 ----------------------
9911 -- Has_Signed_Zeros --
9912 ----------------------
9914 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
9916 return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target;
9917 end Has_Signed_Zeros;
9919 ------------------------------
9920 -- Has_Significant_Contract --
9921 ------------------------------
9923 function Has_Significant_Contract (Subp_Id : Entity_Id) return Boolean is
9924 Subp_Nam : constant Name_Id := Chars (Subp_Id);
9927 -- _Finalizer procedure
9929 if Subp_Nam = Name_uFinalizer then
9932 -- _Postconditions procedure
9934 elsif Subp_Nam = Name_uPostconditions then
9937 -- Predicate function
9939 elsif Ekind (Subp_Id) = E_Function
9940 and then Is_Predicate_Function (Subp_Id)
9946 elsif Get_TSS_Name (Subp_Id) /= TSS_Null then
9952 end Has_Significant_Contract;
9954 -----------------------------
9955 -- Has_Static_Array_Bounds --
9956 -----------------------------
9958 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
9959 Ndims : constant Nat := Number_Dimensions (Typ);
9966 -- Unconstrained types do not have static bounds
9968 if not Is_Constrained (Typ) then
9972 -- First treat string literals specially, as the lower bound and length
9973 -- of string literals are not stored like those of arrays.
9975 -- A string literal always has static bounds
9977 if Ekind (Typ) = E_String_Literal_Subtype then
9981 -- Treat all dimensions in turn
9983 Index := First_Index (Typ);
9984 for Indx in 1 .. Ndims loop
9986 -- In case of an illegal index which is not a discrete type, return
9987 -- that the type is not static.
9989 if not Is_Discrete_Type (Etype (Index))
9990 or else Etype (Index) = Any_Type
9995 Get_Index_Bounds (Index, Low, High);
9997 if Error_Posted (Low) or else Error_Posted (High) then
10001 if Is_OK_Static_Expression (Low)
10003 Is_OK_Static_Expression (High)
10013 -- If we fall through the loop, all indexes matched
10016 end Has_Static_Array_Bounds;
10022 function Has_Stream (T : Entity_Id) return Boolean is
10029 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
10032 elsif Is_Array_Type (T) then
10033 return Has_Stream (Component_Type (T));
10035 elsif Is_Record_Type (T) then
10036 E := First_Component (T);
10037 while Present (E) loop
10038 if Has_Stream (Etype (E)) then
10041 Next_Component (E);
10047 elsif Is_Private_Type (T) then
10048 return Has_Stream (Underlying_Type (T));
10059 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
10061 Get_Name_String (Chars (E));
10062 return Name_Buffer (Name_Len) = Suffix;
10069 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
10071 Get_Name_String (Chars (E));
10072 Add_Char_To_Name_Buffer (Suffix);
10076 -------------------
10077 -- Remove_Suffix --
10078 -------------------
10080 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
10082 pragma Assert (Has_Suffix (E, Suffix));
10083 Get_Name_String (Chars (E));
10084 Name_Len := Name_Len - 1;
10088 --------------------------
10089 -- Has_Tagged_Component --
10090 --------------------------
10092 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
10096 if Is_Private_Type (Typ) and then Present (Underlying_Type (Typ)) then
10097 return Has_Tagged_Component (Underlying_Type (Typ));
10099 elsif Is_Array_Type (Typ) then
10100 return Has_Tagged_Component (Component_Type (Typ));
10102 elsif Is_Tagged_Type (Typ) then
10105 elsif Is_Record_Type (Typ) then
10106 Comp := First_Component (Typ);
10107 while Present (Comp) loop
10108 if Has_Tagged_Component (Etype (Comp)) then
10112 Next_Component (Comp);
10120 end Has_Tagged_Component;
10122 -----------------------------
10123 -- Has_Undefined_Reference --
10124 -----------------------------
10126 function Has_Undefined_Reference (Expr : Node_Id) return Boolean is
10127 Has_Undef_Ref : Boolean := False;
10128 -- Flag set when expression Expr contains at least one undefined
10131 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result;
10132 -- Determine whether N denotes a reference and if it does, whether it is
10135 ----------------------------
10136 -- Is_Undefined_Reference --
10137 ----------------------------
10139 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result is
10141 if Is_Entity_Name (N)
10142 and then Present (Entity (N))
10143 and then Entity (N) = Any_Id
10145 Has_Undef_Ref := True;
10150 end Is_Undefined_Reference;
10152 procedure Find_Undefined_References is
10153 new Traverse_Proc (Is_Undefined_Reference);
10155 -- Start of processing for Has_Undefined_Reference
10158 Find_Undefined_References (Expr);
10160 return Has_Undef_Ref;
10161 end Has_Undefined_Reference;
10163 ----------------------------
10164 -- Has_Volatile_Component --
10165 ----------------------------
10167 function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
10171 if Has_Volatile_Components (Typ) then
10174 elsif Is_Array_Type (Typ) then
10175 return Is_Volatile (Component_Type (Typ));
10177 elsif Is_Record_Type (Typ) then
10178 Comp := First_Component (Typ);
10179 while Present (Comp) loop
10180 if Is_Volatile_Object (Comp) then
10184 Comp := Next_Component (Comp);
10189 end Has_Volatile_Component;
10191 -------------------------
10192 -- Implementation_Kind --
10193 -------------------------
10195 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
10196 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
10199 pragma Assert (Present (Impl_Prag));
10200 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
10201 return Chars (Get_Pragma_Arg (Arg));
10202 end Implementation_Kind;
10204 --------------------------
10205 -- Implements_Interface --
10206 --------------------------
10208 function Implements_Interface
10209 (Typ_Ent : Entity_Id;
10210 Iface_Ent : Entity_Id;
10211 Exclude_Parents : Boolean := False) return Boolean
10213 Ifaces_List : Elist_Id;
10215 Iface : Entity_Id := Base_Type (Iface_Ent);
10216 Typ : Entity_Id := Base_Type (Typ_Ent);
10219 if Is_Class_Wide_Type (Typ) then
10220 Typ := Root_Type (Typ);
10223 if not Has_Interfaces (Typ) then
10227 if Is_Class_Wide_Type (Iface) then
10228 Iface := Root_Type (Iface);
10231 Collect_Interfaces (Typ, Ifaces_List);
10233 Elmt := First_Elmt (Ifaces_List);
10234 while Present (Elmt) loop
10235 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
10236 and then Exclude_Parents
10240 elsif Node (Elmt) = Iface then
10248 end Implements_Interface;
10250 ------------------------------------
10251 -- In_Assertion_Expression_Pragma --
10252 ------------------------------------
10254 function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is
10256 Prag : Node_Id := Empty;
10259 -- Climb the parent chain looking for an enclosing pragma
10262 while Present (Par) loop
10263 if Nkind (Par) = N_Pragma then
10267 -- Precondition-like pragmas are expanded into if statements, check
10268 -- the original node instead.
10270 elsif Nkind (Original_Node (Par)) = N_Pragma then
10271 Prag := Original_Node (Par);
10274 -- The expansion of attribute 'Old generates a constant to capture
10275 -- the result of the prefix. If the parent traversal reaches
10276 -- one of these constants, then the node technically came from a
10277 -- postcondition-like pragma. Note that the Ekind is not tested here
10278 -- because N may be the expression of an object declaration which is
10279 -- currently being analyzed. Such objects carry Ekind of E_Void.
10281 elsif Nkind (Par) = N_Object_Declaration
10282 and then Constant_Present (Par)
10283 and then Stores_Attribute_Old_Prefix (Defining_Entity (Par))
10287 -- Prevent the search from going too far
10289 elsif Is_Body_Or_Package_Declaration (Par) then
10293 Par := Parent (Par);
10298 and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag));
10299 end In_Assertion_Expression_Pragma;
10305 function In_Instance return Boolean is
10306 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
10310 S := Current_Scope;
10311 while Present (S) and then S /= Standard_Standard loop
10312 if Ekind_In (S, E_Function, E_Package, E_Procedure)
10313 and then Is_Generic_Instance (S)
10315 -- A child instance is always compiled in the context of a parent
10316 -- instance. Nevertheless, the actuals are not analyzed in an
10317 -- instance context. We detect this case by examining the current
10318 -- compilation unit, which must be a child instance, and checking
10319 -- that it is not currently on the scope stack.
10321 if Is_Child_Unit (Curr_Unit)
10322 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
10323 N_Package_Instantiation
10324 and then not In_Open_Scopes (Curr_Unit)
10338 ----------------------
10339 -- In_Instance_Body --
10340 ----------------------
10342 function In_Instance_Body return Boolean is
10346 S := Current_Scope;
10347 while Present (S) and then S /= Standard_Standard loop
10348 if Ekind_In (S, E_Function, E_Procedure)
10349 and then Is_Generic_Instance (S)
10353 elsif Ekind (S) = E_Package
10354 and then In_Package_Body (S)
10355 and then Is_Generic_Instance (S)
10364 end In_Instance_Body;
10366 -----------------------------
10367 -- In_Instance_Not_Visible --
10368 -----------------------------
10370 function In_Instance_Not_Visible return Boolean is
10374 S := Current_Scope;
10375 while Present (S) and then S /= Standard_Standard loop
10376 if Ekind_In (S, E_Function, E_Procedure)
10377 and then Is_Generic_Instance (S)
10381 elsif Ekind (S) = E_Package
10382 and then (In_Package_Body (S) or else In_Private_Part (S))
10383 and then Is_Generic_Instance (S)
10392 end In_Instance_Not_Visible;
10394 ------------------------------
10395 -- In_Instance_Visible_Part --
10396 ------------------------------
10398 function In_Instance_Visible_Part return Boolean is
10402 S := Current_Scope;
10403 while Present (S) and then S /= Standard_Standard loop
10404 if Ekind (S) = E_Package
10405 and then Is_Generic_Instance (S)
10406 and then not In_Package_Body (S)
10407 and then not In_Private_Part (S)
10416 end In_Instance_Visible_Part;
10418 ---------------------
10419 -- In_Package_Body --
10420 ---------------------
10422 function In_Package_Body return Boolean is
10426 S := Current_Scope;
10427 while Present (S) and then S /= Standard_Standard loop
10428 if Ekind (S) = E_Package and then In_Package_Body (S) then
10436 end In_Package_Body;
10438 --------------------------------
10439 -- In_Parameter_Specification --
10440 --------------------------------
10442 function In_Parameter_Specification (N : Node_Id) return Boolean is
10447 while Present (PN) loop
10448 if Nkind (PN) = N_Parameter_Specification then
10456 end In_Parameter_Specification;
10458 --------------------------
10459 -- In_Pragma_Expression --
10460 --------------------------
10462 function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean is
10469 elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
10475 end In_Pragma_Expression;
10477 -------------------------------------
10478 -- In_Reverse_Storage_Order_Object --
10479 -------------------------------------
10481 function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
10483 Btyp : Entity_Id := Empty;
10486 -- Climb up indexed components
10490 case Nkind (Pref) is
10491 when N_Selected_Component =>
10492 Pref := Prefix (Pref);
10495 when N_Indexed_Component =>
10496 Pref := Prefix (Pref);
10504 if Present (Pref) then
10505 Btyp := Base_Type (Etype (Pref));
10508 return Present (Btyp)
10509 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
10510 and then Reverse_Storage_Order (Btyp);
10511 end In_Reverse_Storage_Order_Object;
10513 --------------------------------------
10514 -- In_Subprogram_Or_Concurrent_Unit --
10515 --------------------------------------
10517 function In_Subprogram_Or_Concurrent_Unit return Boolean is
10522 -- Use scope chain to check successively outer scopes
10524 E := Current_Scope;
10528 if K in Subprogram_Kind
10529 or else K in Concurrent_Kind
10530 or else K in Generic_Subprogram_Kind
10534 elsif E = Standard_Standard then
10540 end In_Subprogram_Or_Concurrent_Unit;
10542 ---------------------
10543 -- In_Visible_Part --
10544 ---------------------
10546 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
10548 return Is_Package_Or_Generic_Package (Scope_Id)
10549 and then In_Open_Scopes (Scope_Id)
10550 and then not In_Package_Body (Scope_Id)
10551 and then not In_Private_Part (Scope_Id);
10552 end In_Visible_Part;
10554 --------------------------------
10555 -- Incomplete_Or_Partial_View --
10556 --------------------------------
10558 function Incomplete_Or_Partial_View (Id : Entity_Id) return Entity_Id is
10559 function Inspect_Decls
10561 Taft : Boolean := False) return Entity_Id;
10562 -- Check whether a declarative region contains the incomplete or partial
10565 -------------------
10566 -- Inspect_Decls --
10567 -------------------
10569 function Inspect_Decls
10571 Taft : Boolean := False) return Entity_Id
10577 Decl := First (Decls);
10578 while Present (Decl) loop
10582 if Nkind (Decl) = N_Incomplete_Type_Declaration then
10583 Match := Defining_Identifier (Decl);
10587 if Nkind_In (Decl, N_Private_Extension_Declaration,
10588 N_Private_Type_Declaration)
10590 Match := Defining_Identifier (Decl);
10595 and then Present (Full_View (Match))
10596 and then Full_View (Match) = Id
10611 -- Start of processing for Incomplete_Or_Partial_View
10614 -- Deferred constant or incomplete type case
10616 Prev := Current_Entity_In_Scope (Id);
10619 and then (Is_Incomplete_Type (Prev) or else Ekind (Prev) = E_Constant)
10620 and then Present (Full_View (Prev))
10621 and then Full_View (Prev) = Id
10626 -- Private or Taft amendment type case
10629 Pkg : constant Entity_Id := Scope (Id);
10630 Pkg_Decl : Node_Id := Pkg;
10633 if Present (Pkg) and then Ekind (Pkg) = E_Package then
10634 while Nkind (Pkg_Decl) /= N_Package_Specification loop
10635 Pkg_Decl := Parent (Pkg_Decl);
10638 -- It is knows that Typ has a private view, look for it in the
10639 -- visible declarations of the enclosing scope. A special case
10640 -- of this is when the two views have been exchanged - the full
10641 -- appears earlier than the private.
10643 if Has_Private_Declaration (Id) then
10644 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
10646 -- Exchanged view case, look in the private declarations
10649 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
10654 -- Otherwise if this is the package body, then Typ is a potential
10655 -- Taft amendment type. The incomplete view should be located in
10656 -- the private declarations of the enclosing scope.
10658 elsif In_Package_Body (Pkg) then
10659 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
10664 -- The type has no incomplete or private view
10667 end Incomplete_Or_Partial_View;
10669 -----------------------------------------
10670 -- Inherit_Default_Init_Cond_Procedure --
10671 -----------------------------------------
10673 procedure Inherit_Default_Init_Cond_Procedure (Typ : Entity_Id) is
10674 Par_Typ : constant Entity_Id := Etype (Typ);
10677 -- A derived type inherits the default initial condition procedure of
10678 -- its parent type.
10680 if No (Default_Init_Cond_Procedure (Typ)) then
10681 Set_Default_Init_Cond_Procedure
10682 (Typ, Default_Init_Cond_Procedure (Par_Typ));
10684 end Inherit_Default_Init_Cond_Procedure;
10686 ----------------------------
10687 -- Inherit_Rep_Item_Chain --
10688 ----------------------------
10690 procedure Inherit_Rep_Item_Chain (Typ : Entity_Id; From_Typ : Entity_Id) is
10691 From_Item : constant Node_Id := First_Rep_Item (From_Typ);
10692 Item : Node_Id := Empty;
10693 Last_Item : Node_Id := Empty;
10696 -- Reach the end of the destination type's chain (if any) and capture
10699 Item := First_Rep_Item (Typ);
10700 while Present (Item) loop
10702 -- Do not inherit a chain that has been inherited already
10704 if Item = From_Item then
10709 Item := Next_Rep_Item (Item);
10712 Item := First_Rep_Item (From_Typ);
10714 -- Additional check when both parent and current type have rep.
10715 -- items, to prevent circularities when the derivation completes
10716 -- a private declaration and inherits from both views of the parent.
10717 -- There may be a remaining problem with the proper ordering of
10718 -- attribute specifications and aspects on the chains of the four
10719 -- entities involved. ???
10721 if Present (Item) and then Present (From_Item) then
10722 while Present (Item) loop
10723 if Item = First_Rep_Item (Typ) then
10727 Item := Next_Rep_Item (Item);
10731 -- When the destination type has a rep item chain, the chain of the
10732 -- source type is appended to it.
10734 if Present (Last_Item) then
10735 Set_Next_Rep_Item (Last_Item, From_Item);
10737 -- Otherwise the destination type directly inherits the rep item chain
10738 -- of the source type (if any).
10741 Set_First_Rep_Item (Typ, From_Item);
10743 end Inherit_Rep_Item_Chain;
10745 ---------------------------------
10746 -- Insert_Explicit_Dereference --
10747 ---------------------------------
10749 procedure Insert_Explicit_Dereference (N : Node_Id) is
10750 New_Prefix : constant Node_Id := Relocate_Node (N);
10751 Ent : Entity_Id := Empty;
10758 Save_Interps (N, New_Prefix);
10761 Make_Explicit_Dereference (Sloc (Parent (N)),
10762 Prefix => New_Prefix));
10764 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
10766 if Is_Overloaded (New_Prefix) then
10768 -- The dereference is also overloaded, and its interpretations are
10769 -- the designated types of the interpretations of the original node.
10771 Set_Etype (N, Any_Type);
10773 Get_First_Interp (New_Prefix, I, It);
10774 while Present (It.Nam) loop
10777 if Is_Access_Type (T) then
10778 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
10781 Get_Next_Interp (I, It);
10787 -- Prefix is unambiguous: mark the original prefix (which might
10788 -- Come_From_Source) as a reference, since the new (relocated) one
10789 -- won't be taken into account.
10791 if Is_Entity_Name (New_Prefix) then
10792 Ent := Entity (New_Prefix);
10793 Pref := New_Prefix;
10795 -- For a retrieval of a subcomponent of some composite object,
10796 -- retrieve the ultimate entity if there is one.
10798 elsif Nkind_In (New_Prefix, N_Selected_Component,
10799 N_Indexed_Component)
10801 Pref := Prefix (New_Prefix);
10802 while Present (Pref)
10803 and then Nkind_In (Pref, N_Selected_Component,
10804 N_Indexed_Component)
10806 Pref := Prefix (Pref);
10809 if Present (Pref) and then Is_Entity_Name (Pref) then
10810 Ent := Entity (Pref);
10814 -- Place the reference on the entity node
10816 if Present (Ent) then
10817 Generate_Reference (Ent, Pref);
10820 end Insert_Explicit_Dereference;
10822 ------------------------------------------
10823 -- Inspect_Deferred_Constant_Completion --
10824 ------------------------------------------
10826 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
10830 Decl := First (Decls);
10831 while Present (Decl) loop
10833 -- Deferred constant signature
10835 if Nkind (Decl) = N_Object_Declaration
10836 and then Constant_Present (Decl)
10837 and then No (Expression (Decl))
10839 -- No need to check internally generated constants
10841 and then Comes_From_Source (Decl)
10843 -- The constant is not completed. A full object declaration or a
10844 -- pragma Import complete a deferred constant.
10846 and then not Has_Completion (Defining_Identifier (Decl))
10849 ("constant declaration requires initialization expression",
10850 Defining_Identifier (Decl));
10853 Decl := Next (Decl);
10855 end Inspect_Deferred_Constant_Completion;
10857 -----------------------------
10858 -- Install_Generic_Formals --
10859 -----------------------------
10861 procedure Install_Generic_Formals (Subp_Id : Entity_Id) is
10865 pragma Assert (Is_Generic_Subprogram (Subp_Id));
10867 E := First_Entity (Subp_Id);
10868 while Present (E) loop
10869 Install_Entity (E);
10872 end Install_Generic_Formals;
10874 -----------------------------
10875 -- Is_Actual_Out_Parameter --
10876 -----------------------------
10878 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
10879 Formal : Entity_Id;
10882 Find_Actual (N, Formal, Call);
10883 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
10884 end Is_Actual_Out_Parameter;
10886 -------------------------
10887 -- Is_Actual_Parameter --
10888 -------------------------
10890 function Is_Actual_Parameter (N : Node_Id) return Boolean is
10891 PK : constant Node_Kind := Nkind (Parent (N));
10895 when N_Parameter_Association =>
10896 return N = Explicit_Actual_Parameter (Parent (N));
10898 when N_Subprogram_Call =>
10899 return Is_List_Member (N)
10901 List_Containing (N) = Parameter_Associations (Parent (N));
10906 end Is_Actual_Parameter;
10908 --------------------------------
10909 -- Is_Actual_Tagged_Parameter --
10910 --------------------------------
10912 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
10913 Formal : Entity_Id;
10916 Find_Actual (N, Formal, Call);
10917 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
10918 end Is_Actual_Tagged_Parameter;
10920 ---------------------
10921 -- Is_Aliased_View --
10922 ---------------------
10924 function Is_Aliased_View (Obj : Node_Id) return Boolean is
10928 if Is_Entity_Name (Obj) then
10935 or else (Present (Renamed_Object (E))
10936 and then Is_Aliased_View (Renamed_Object (E)))))
10938 or else ((Is_Formal (E)
10939 or else Ekind_In (E, E_Generic_In_Out_Parameter,
10940 E_Generic_In_Parameter))
10941 and then Is_Tagged_Type (Etype (E)))
10943 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
10945 -- Current instance of type, either directly or as rewritten
10946 -- reference to the current object.
10948 or else (Is_Entity_Name (Original_Node (Obj))
10949 and then Present (Entity (Original_Node (Obj)))
10950 and then Is_Type (Entity (Original_Node (Obj))))
10952 or else (Is_Type (E) and then E = Current_Scope)
10954 or else (Is_Incomplete_Or_Private_Type (E)
10955 and then Full_View (E) = Current_Scope)
10957 -- Ada 2012 AI05-0053: the return object of an extended return
10958 -- statement is aliased if its type is immutably limited.
10960 or else (Is_Return_Object (E)
10961 and then Is_Limited_View (Etype (E)));
10963 elsif Nkind (Obj) = N_Selected_Component then
10964 return Is_Aliased (Entity (Selector_Name (Obj)));
10966 elsif Nkind (Obj) = N_Indexed_Component then
10967 return Has_Aliased_Components (Etype (Prefix (Obj)))
10969 (Is_Access_Type (Etype (Prefix (Obj)))
10970 and then Has_Aliased_Components
10971 (Designated_Type (Etype (Prefix (Obj)))));
10973 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
10974 return Is_Tagged_Type (Etype (Obj))
10975 and then Is_Aliased_View (Expression (Obj));
10977 elsif Nkind (Obj) = N_Explicit_Dereference then
10978 return Nkind (Original_Node (Obj)) /= N_Function_Call;
10983 end Is_Aliased_View;
10985 -------------------------
10986 -- Is_Ancestor_Package --
10987 -------------------------
10989 function Is_Ancestor_Package
10991 E2 : Entity_Id) return Boolean
10997 while Present (Par) and then Par /= Standard_Standard loop
11002 Par := Scope (Par);
11006 end Is_Ancestor_Package;
11008 ----------------------
11009 -- Is_Atomic_Object --
11010 ----------------------
11012 function Is_Atomic_Object (N : Node_Id) return Boolean is
11014 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
11015 -- Determines if given object has atomic components
11017 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
11018 -- If prefix is an implicit dereference, examine designated type
11020 ----------------------
11021 -- Is_Atomic_Prefix --
11022 ----------------------
11024 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
11026 if Is_Access_Type (Etype (N)) then
11028 Has_Atomic_Components (Designated_Type (Etype (N)));
11030 return Object_Has_Atomic_Components (N);
11032 end Is_Atomic_Prefix;
11034 ----------------------------------
11035 -- Object_Has_Atomic_Components --
11036 ----------------------------------
11038 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
11040 if Has_Atomic_Components (Etype (N))
11041 or else Is_Atomic (Etype (N))
11045 elsif Is_Entity_Name (N)
11046 and then (Has_Atomic_Components (Entity (N))
11047 or else Is_Atomic (Entity (N)))
11051 elsif Nkind (N) = N_Selected_Component
11052 and then Is_Atomic (Entity (Selector_Name (N)))
11056 elsif Nkind (N) = N_Indexed_Component
11057 or else Nkind (N) = N_Selected_Component
11059 return Is_Atomic_Prefix (Prefix (N));
11064 end Object_Has_Atomic_Components;
11066 -- Start of processing for Is_Atomic_Object
11069 -- Predicate is not relevant to subprograms
11071 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
11074 elsif Is_Atomic (Etype (N))
11075 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
11079 elsif Nkind (N) = N_Selected_Component
11080 and then Is_Atomic (Entity (Selector_Name (N)))
11084 elsif Nkind (N) = N_Indexed_Component
11085 or else Nkind (N) = N_Selected_Component
11087 return Is_Atomic_Prefix (Prefix (N));
11092 end Is_Atomic_Object;
11094 -----------------------------
11095 -- Is_Atomic_Or_VFA_Object --
11096 -----------------------------
11098 function Is_Atomic_Or_VFA_Object (N : Node_Id) return Boolean is
11100 return Is_Atomic_Object (N)
11101 or else (Is_Object_Reference (N)
11102 and then Is_Entity_Name (N)
11103 and then (Is_Volatile_Full_Access (Entity (N))
11105 Is_Volatile_Full_Access (Etype (Entity (N)))));
11106 end Is_Atomic_Or_VFA_Object;
11108 -------------------------
11109 -- Is_Attribute_Result --
11110 -------------------------
11112 function Is_Attribute_Result (N : Node_Id) return Boolean is
11114 return Nkind (N) = N_Attribute_Reference
11115 and then Attribute_Name (N) = Name_Result;
11116 end Is_Attribute_Result;
11118 -------------------------
11119 -- Is_Attribute_Update --
11120 -------------------------
11122 function Is_Attribute_Update (N : Node_Id) return Boolean is
11124 return Nkind (N) = N_Attribute_Reference
11125 and then Attribute_Name (N) = Name_Update;
11126 end Is_Attribute_Update;
11128 ------------------------------------
11129 -- Is_Body_Or_Package_Declaration --
11130 ------------------------------------
11132 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
11134 return Nkind_In (N, N_Entry_Body,
11136 N_Package_Declaration,
11140 end Is_Body_Or_Package_Declaration;
11142 -----------------------
11143 -- Is_Bounded_String --
11144 -----------------------
11146 function Is_Bounded_String (T : Entity_Id) return Boolean is
11147 Under : constant Entity_Id := Underlying_Type (Root_Type (T));
11150 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
11151 -- Super_String, or one of the [Wide_]Wide_ versions. This will
11152 -- be True for all the Bounded_String types in instances of the
11153 -- Generic_Bounded_Length generics, and for types derived from those.
11155 return Present (Under)
11156 and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
11157 Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
11158 Is_RTE (Root_Type (Under), RO_WW_Super_String));
11159 end Is_Bounded_String;
11161 -------------------------
11162 -- Is_Child_Or_Sibling --
11163 -------------------------
11165 function Is_Child_Or_Sibling
11166 (Pack_1 : Entity_Id;
11167 Pack_2 : Entity_Id) return Boolean
11169 function Distance_From_Standard (Pack : Entity_Id) return Nat;
11170 -- Given an arbitrary package, return the number of "climbs" necessary
11171 -- to reach scope Standard_Standard.
11173 procedure Equalize_Depths
11174 (Pack : in out Entity_Id;
11175 Depth : in out Nat;
11176 Depth_To_Reach : Nat);
11177 -- Given an arbitrary package, its depth and a target depth to reach,
11178 -- climb the scope chain until the said depth is reached. The pointer
11179 -- to the package and its depth a modified during the climb.
11181 ----------------------------
11182 -- Distance_From_Standard --
11183 ----------------------------
11185 function Distance_From_Standard (Pack : Entity_Id) return Nat is
11192 while Present (Scop) and then Scop /= Standard_Standard loop
11194 Scop := Scope (Scop);
11198 end Distance_From_Standard;
11200 ---------------------
11201 -- Equalize_Depths --
11202 ---------------------
11204 procedure Equalize_Depths
11205 (Pack : in out Entity_Id;
11206 Depth : in out Nat;
11207 Depth_To_Reach : Nat)
11210 -- The package must be at a greater or equal depth
11212 if Depth < Depth_To_Reach then
11213 raise Program_Error;
11216 -- Climb the scope chain until the desired depth is reached
11218 while Present (Pack) and then Depth /= Depth_To_Reach loop
11219 Pack := Scope (Pack);
11220 Depth := Depth - 1;
11222 end Equalize_Depths;
11226 P_1 : Entity_Id := Pack_1;
11227 P_1_Child : Boolean := False;
11228 P_1_Depth : Nat := Distance_From_Standard (P_1);
11229 P_2 : Entity_Id := Pack_2;
11230 P_2_Child : Boolean := False;
11231 P_2_Depth : Nat := Distance_From_Standard (P_2);
11233 -- Start of processing for Is_Child_Or_Sibling
11237 (Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
11239 -- Both packages denote the same entity, therefore they cannot be
11240 -- children or siblings.
11245 -- One of the packages is at a deeper level than the other. Note that
11246 -- both may still come from differen hierarchies.
11254 elsif P_1_Depth > P_2_Depth then
11257 Depth => P_1_Depth,
11258 Depth_To_Reach => P_2_Depth);
11267 elsif P_2_Depth > P_1_Depth then
11270 Depth => P_2_Depth,
11271 Depth_To_Reach => P_1_Depth);
11275 -- At this stage the package pointers have been elevated to the same
11276 -- depth. If the related entities are the same, then one package is a
11277 -- potential child of the other:
11281 -- X became P_1 P_2 or vica versa
11287 return Is_Child_Unit (Pack_1);
11289 else pragma Assert (P_2_Child);
11290 return Is_Child_Unit (Pack_2);
11293 -- The packages may come from the same package chain or from entirely
11294 -- different hierarcies. To determine this, climb the scope stack until
11295 -- a common root is found.
11297 -- (root) (root 1) (root 2)
11302 while Present (P_1) and then Present (P_2) loop
11304 -- The two packages may be siblings
11307 return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2);
11310 P_1 := Scope (P_1);
11311 P_2 := Scope (P_2);
11316 end Is_Child_Or_Sibling;
11318 -----------------------------
11319 -- Is_Concurrent_Interface --
11320 -----------------------------
11322 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
11324 return Is_Interface (T)
11326 (Is_Protected_Interface (T)
11327 or else Is_Synchronized_Interface (T)
11328 or else Is_Task_Interface (T));
11329 end Is_Concurrent_Interface;
11331 -----------------------
11332 -- Is_Constant_Bound --
11333 -----------------------
11335 function Is_Constant_Bound (Exp : Node_Id) return Boolean is
11337 if Compile_Time_Known_Value (Exp) then
11340 elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
11341 return Is_Constant_Object (Entity (Exp))
11342 or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
11344 elsif Nkind (Exp) in N_Binary_Op then
11345 return Is_Constant_Bound (Left_Opnd (Exp))
11346 and then Is_Constant_Bound (Right_Opnd (Exp))
11347 and then Scope (Entity (Exp)) = Standard_Standard;
11352 end Is_Constant_Bound;
11354 ---------------------------
11355 -- Is_Container_Element --
11356 ---------------------------
11358 function Is_Container_Element (Exp : Node_Id) return Boolean is
11359 Loc : constant Source_Ptr := Sloc (Exp);
11360 Pref : constant Node_Id := Prefix (Exp);
11363 -- Call to an indexing aspect
11365 Cont_Typ : Entity_Id;
11366 -- The type of the container being accessed
11368 Elem_Typ : Entity_Id;
11369 -- Its element type
11371 Indexing : Entity_Id;
11372 Is_Const : Boolean;
11373 -- Indicates that constant indexing is used, and the element is thus
11376 Ref_Typ : Entity_Id;
11377 -- The reference type returned by the indexing operation
11380 -- If C is a container, in a context that imposes the element type of
11381 -- that container, the indexing notation C (X) is rewritten as:
11383 -- Indexing (C, X).Discr.all
11385 -- where Indexing is one of the indexing aspects of the container.
11386 -- If the context does not require a reference, the construct can be
11391 -- First, verify that the construct has the proper form
11393 if not Expander_Active then
11396 elsif Nkind (Pref) /= N_Selected_Component then
11399 elsif Nkind (Prefix (Pref)) /= N_Function_Call then
11403 Call := Prefix (Pref);
11404 Ref_Typ := Etype (Call);
11407 if not Has_Implicit_Dereference (Ref_Typ)
11408 or else No (First (Parameter_Associations (Call)))
11409 or else not Is_Entity_Name (Name (Call))
11414 -- Retrieve type of container object, and its iterator aspects
11416 Cont_Typ := Etype (First (Parameter_Associations (Call)));
11417 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Constant_Indexing);
11420 if No (Indexing) then
11422 -- Container should have at least one indexing operation
11426 elsif Entity (Name (Call)) /= Entity (Indexing) then
11428 -- This may be a variable indexing operation
11430 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Variable_Indexing);
11433 or else Entity (Name (Call)) /= Entity (Indexing)
11442 Elem_Typ := Find_Value_Of_Aspect (Cont_Typ, Aspect_Iterator_Element);
11444 if No (Elem_Typ) or else Entity (Elem_Typ) /= Etype (Exp) then
11448 -- Check that the expression is not the target of an assignment, in
11449 -- which case the rewriting is not possible.
11451 if not Is_Const then
11457 while Present (Par)
11459 if Nkind (Parent (Par)) = N_Assignment_Statement
11460 and then Par = Name (Parent (Par))
11464 -- A renaming produces a reference, and the transformation
11467 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
11471 (Nkind (Parent (Par)), N_Function_Call,
11472 N_Procedure_Call_Statement,
11473 N_Entry_Call_Statement)
11475 -- Check that the element is not part of an actual for an
11476 -- in-out parameter.
11483 F := First_Formal (Entity (Name (Parent (Par))));
11484 A := First (Parameter_Associations (Parent (Par)));
11485 while Present (F) loop
11486 if A = Par and then Ekind (F) /= E_In_Parameter then
11495 -- E_In_Parameter in a call: element is not modified.
11500 Par := Parent (Par);
11505 -- The expression has the proper form and the context requires the
11506 -- element type. Retrieve the Element function of the container and
11507 -- rewrite the construct as a call to it.
11513 Op := First_Elmt (Primitive_Operations (Cont_Typ));
11514 while Present (Op) loop
11515 exit when Chars (Node (Op)) = Name_Element;
11524 Make_Function_Call (Loc,
11525 Name => New_Occurrence_Of (Node (Op), Loc),
11526 Parameter_Associations => Parameter_Associations (Call)));
11527 Analyze_And_Resolve (Exp, Entity (Elem_Typ));
11531 end Is_Container_Element;
11533 ----------------------------
11534 -- Is_Contract_Annotation --
11535 ----------------------------
11537 function Is_Contract_Annotation (Item : Node_Id) return Boolean is
11539 return Is_Package_Contract_Annotation (Item)
11541 Is_Subprogram_Contract_Annotation (Item);
11542 end Is_Contract_Annotation;
11544 --------------------------------------
11545 -- Is_Controlling_Limited_Procedure --
11546 --------------------------------------
11548 function Is_Controlling_Limited_Procedure
11549 (Proc_Nam : Entity_Id) return Boolean
11551 Param_Typ : Entity_Id := Empty;
11554 if Ekind (Proc_Nam) = E_Procedure
11555 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
11557 Param_Typ := Etype (Parameter_Type (First (
11558 Parameter_Specifications (Parent (Proc_Nam)))));
11560 -- In this case where an Itype was created, the procedure call has been
11563 elsif Present (Associated_Node_For_Itype (Proc_Nam))
11564 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
11566 Present (Parameter_Associations
11567 (Associated_Node_For_Itype (Proc_Nam)))
11570 Etype (First (Parameter_Associations
11571 (Associated_Node_For_Itype (Proc_Nam))));
11574 if Present (Param_Typ) then
11576 Is_Interface (Param_Typ)
11577 and then Is_Limited_Record (Param_Typ);
11581 end Is_Controlling_Limited_Procedure;
11583 -----------------------------
11584 -- Is_CPP_Constructor_Call --
11585 -----------------------------
11587 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
11589 return Nkind (N) = N_Function_Call
11590 and then Is_CPP_Class (Etype (Etype (N)))
11591 and then Is_Constructor (Entity (Name (N)))
11592 and then Is_Imported (Entity (Name (N)));
11593 end Is_CPP_Constructor_Call;
11595 -------------------------
11596 -- Is_Current_Instance --
11597 -------------------------
11599 function Is_Current_Instance (N : Node_Id) return Boolean is
11600 Typ : constant Entity_Id := Entity (N);
11604 -- Simplest case: entity is a concurrent type and we are currently
11605 -- inside the body. This will eventually be expanded into a
11606 -- call to Self (for tasks) or _object (for protected objects).
11608 if Is_Concurrent_Type (Typ) and then In_Open_Scopes (Typ) then
11612 -- Check whether the context is a (sub)type declaration for the
11616 while Present (P) loop
11617 if Nkind_In (P, N_Full_Type_Declaration,
11618 N_Private_Type_Declaration,
11619 N_Subtype_Declaration)
11620 and then Comes_From_Source (P)
11621 and then Defining_Entity (P) = Typ
11625 -- A subtype name may appear in an aspect specification for a
11626 -- Predicate_Failure aspect, for which we do not construct a
11627 -- wrapper procedure. The subtype will be replaced by the
11628 -- expression being tested when the corresponding predicate
11629 -- check is expanded.
11631 elsif Nkind (P) = N_Aspect_Specification
11632 and then Nkind (Parent (P)) = N_Subtype_Declaration
11636 elsif Nkind (P) = N_Pragma
11638 Get_Pragma_Id (Pragma_Name (P)) = Pragma_Predicate_Failure
11647 -- In any other context this is not a current occurrence
11650 end Is_Current_Instance;
11652 --------------------
11653 -- Is_Declaration --
11654 --------------------
11656 function Is_Declaration (N : Node_Id) return Boolean is
11659 when N_Abstract_Subprogram_Declaration |
11660 N_Exception_Declaration |
11661 N_Exception_Renaming_Declaration |
11662 N_Full_Type_Declaration |
11663 N_Generic_Function_Renaming_Declaration |
11664 N_Generic_Package_Declaration |
11665 N_Generic_Package_Renaming_Declaration |
11666 N_Generic_Procedure_Renaming_Declaration |
11667 N_Generic_Subprogram_Declaration |
11668 N_Number_Declaration |
11669 N_Object_Declaration |
11670 N_Object_Renaming_Declaration |
11671 N_Package_Declaration |
11672 N_Package_Renaming_Declaration |
11673 N_Private_Extension_Declaration |
11674 N_Private_Type_Declaration |
11675 N_Subprogram_Declaration |
11676 N_Subprogram_Renaming_Declaration |
11677 N_Subtype_Declaration =>
11683 end Is_Declaration;
11685 --------------------------------
11686 -- Is_Declared_Within_Variant --
11687 --------------------------------
11689 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
11690 Comp_Decl : constant Node_Id := Parent (Comp);
11691 Comp_List : constant Node_Id := Parent (Comp_Decl);
11693 return Nkind (Parent (Comp_List)) = N_Variant;
11694 end Is_Declared_Within_Variant;
11696 ----------------------------------------------
11697 -- Is_Dependent_Component_Of_Mutable_Object --
11698 ----------------------------------------------
11700 function Is_Dependent_Component_Of_Mutable_Object
11701 (Object : Node_Id) return Boolean
11704 Prefix_Type : Entity_Id;
11705 P_Aliased : Boolean := False;
11708 Deref : Node_Id := Object;
11709 -- Dereference node, in something like X.all.Y(2)
11711 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
11714 -- Find the dereference node if any
11716 while Nkind_In (Deref, N_Indexed_Component,
11717 N_Selected_Component,
11720 Deref := Prefix (Deref);
11723 -- Ada 2005: If we have a component or slice of a dereference,
11724 -- something like X.all.Y (2), and the type of X is access-to-constant,
11725 -- Is_Variable will return False, because it is indeed a constant
11726 -- view. But it might be a view of a variable object, so we want the
11727 -- following condition to be True in that case.
11729 if Is_Variable (Object)
11730 or else (Ada_Version >= Ada_2005
11731 and then Nkind (Deref) = N_Explicit_Dereference)
11733 if Nkind (Object) = N_Selected_Component then
11734 P := Prefix (Object);
11735 Prefix_Type := Etype (P);
11737 if Is_Entity_Name (P) then
11738 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
11739 Prefix_Type := Base_Type (Prefix_Type);
11742 if Is_Aliased (Entity (P)) then
11746 -- A discriminant check on a selected component may be expanded
11747 -- into a dereference when removing side-effects. Recover the
11748 -- original node and its type, which may be unconstrained.
11750 elsif Nkind (P) = N_Explicit_Dereference
11751 and then not (Comes_From_Source (P))
11753 P := Original_Node (P);
11754 Prefix_Type := Etype (P);
11757 -- Check for prefix being an aliased component???
11763 -- A heap object is constrained by its initial value
11765 -- Ada 2005 (AI-363): Always assume the object could be mutable in
11766 -- the dereferenced case, since the access value might denote an
11767 -- unconstrained aliased object, whereas in Ada 95 the designated
11768 -- object is guaranteed to be constrained. A worst-case assumption
11769 -- has to apply in Ada 2005 because we can't tell at compile
11770 -- time whether the object is "constrained by its initial value"
11771 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
11772 -- rules (these rules are acknowledged to need fixing).
11774 if Ada_Version < Ada_2005 then
11775 if Is_Access_Type (Prefix_Type)
11776 or else Nkind (P) = N_Explicit_Dereference
11781 else pragma Assert (Ada_Version >= Ada_2005);
11782 if Is_Access_Type (Prefix_Type) then
11784 -- If the access type is pool-specific, and there is no
11785 -- constrained partial view of the designated type, then the
11786 -- designated object is known to be constrained.
11788 if Ekind (Prefix_Type) = E_Access_Type
11789 and then not Object_Type_Has_Constrained_Partial_View
11790 (Typ => Designated_Type (Prefix_Type),
11791 Scop => Current_Scope)
11795 -- Otherwise (general access type, or there is a constrained
11796 -- partial view of the designated type), we need to check
11797 -- based on the designated type.
11800 Prefix_Type := Designated_Type (Prefix_Type);
11806 Original_Record_Component (Entity (Selector_Name (Object)));
11808 -- As per AI-0017, the renaming is illegal in a generic body, even
11809 -- if the subtype is indefinite.
11811 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
11813 if not Is_Constrained (Prefix_Type)
11814 and then (Is_Definite_Subtype (Prefix_Type)
11816 (Is_Generic_Type (Prefix_Type)
11817 and then Ekind (Current_Scope) = E_Generic_Package
11818 and then In_Package_Body (Current_Scope)))
11820 and then (Is_Declared_Within_Variant (Comp)
11821 or else Has_Discriminant_Dependent_Constraint (Comp))
11822 and then (not P_Aliased or else Ada_Version >= Ada_2005)
11826 -- If the prefix is of an access type at this point, then we want
11827 -- to return False, rather than calling this function recursively
11828 -- on the access object (which itself might be a discriminant-
11829 -- dependent component of some other object, but that isn't
11830 -- relevant to checking the object passed to us). This avoids
11831 -- issuing wrong errors when compiling with -gnatc, where there
11832 -- can be implicit dereferences that have not been expanded.
11834 elsif Is_Access_Type (Etype (Prefix (Object))) then
11839 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
11842 elsif Nkind (Object) = N_Indexed_Component
11843 or else Nkind (Object) = N_Slice
11845 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
11847 -- A type conversion that Is_Variable is a view conversion:
11848 -- go back to the denoted object.
11850 elsif Nkind (Object) = N_Type_Conversion then
11852 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
11857 end Is_Dependent_Component_Of_Mutable_Object;
11859 ---------------------
11860 -- Is_Dereferenced --
11861 ---------------------
11863 function Is_Dereferenced (N : Node_Id) return Boolean is
11864 P : constant Node_Id := Parent (N);
11866 return Nkind_In (P, N_Selected_Component,
11867 N_Explicit_Dereference,
11868 N_Indexed_Component,
11870 and then Prefix (P) = N;
11871 end Is_Dereferenced;
11873 ----------------------
11874 -- Is_Descendant_Of --
11875 ----------------------
11877 function Is_Descendant_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
11882 pragma Assert (Nkind (T1) in N_Entity);
11883 pragma Assert (Nkind (T2) in N_Entity);
11885 T := Base_Type (T1);
11887 -- Immediate return if the types match
11892 -- Comment needed here ???
11894 elsif Ekind (T) = E_Class_Wide_Type then
11895 return Etype (T) = T2;
11903 -- Done if we found the type we are looking for
11908 -- Done if no more derivations to check
11915 -- Following test catches error cases resulting from prev errors
11917 elsif No (Etyp) then
11920 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
11923 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
11927 T := Base_Type (Etyp);
11930 end Is_Descendant_Of;
11932 ----------------------------------------
11933 -- Is_Descendant_Of_Suspension_Object --
11934 ----------------------------------------
11936 function Is_Descendant_Of_Suspension_Object
11937 (Typ : Entity_Id) return Boolean
11939 Cur_Typ : Entity_Id;
11940 Par_Typ : Entity_Id;
11943 -- Climb the type derivation chain checking each parent type against
11944 -- Suspension_Object.
11946 Cur_Typ := Base_Type (Typ);
11947 while Present (Cur_Typ) loop
11948 Par_Typ := Etype (Cur_Typ);
11950 -- The current type is a match
11952 if Is_Suspension_Object (Cur_Typ) then
11955 -- Stop the traversal once the root of the derivation chain has been
11956 -- reached. In that case the current type is its own base type.
11958 elsif Cur_Typ = Par_Typ then
11962 Cur_Typ := Base_Type (Par_Typ);
11966 end Is_Descendant_Of_Suspension_Object;
11968 ---------------------------------------------
11969 -- Is_Double_Precision_Floating_Point_Type --
11970 ---------------------------------------------
11972 function Is_Double_Precision_Floating_Point_Type
11973 (E : Entity_Id) return Boolean is
11975 return Is_Floating_Point_Type (E)
11976 and then Machine_Radix_Value (E) = Uint_2
11977 and then Machine_Mantissa_Value (E) = UI_From_Int (53)
11978 and then Machine_Emax_Value (E) = Uint_2 ** Uint_10
11979 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_10);
11980 end Is_Double_Precision_Floating_Point_Type;
11982 -----------------------------
11983 -- Is_Effectively_Volatile --
11984 -----------------------------
11986 function Is_Effectively_Volatile (Id : Entity_Id) return Boolean is
11988 if Is_Type (Id) then
11990 -- An arbitrary type is effectively volatile when it is subject to
11991 -- pragma Atomic or Volatile.
11993 if Is_Volatile (Id) then
11996 -- An array type is effectively volatile when it is subject to pragma
11997 -- Atomic_Components or Volatile_Components or its compolent type is
11998 -- effectively volatile.
12000 elsif Is_Array_Type (Id) then
12002 Has_Volatile_Components (Id)
12004 Is_Effectively_Volatile (Component_Type (Base_Type (Id)));
12006 -- A protected type is always volatile
12008 elsif Is_Protected_Type (Id) then
12011 -- A descendant of Ada.Synchronous_Task_Control.Suspension_Object is
12012 -- automatically volatile.
12014 elsif Is_Descendant_Of_Suspension_Object (Id) then
12017 -- Otherwise the type is not effectively volatile
12023 -- Otherwise Id denotes an object
12028 or else Has_Volatile_Components (Id)
12029 or else Is_Effectively_Volatile (Etype (Id));
12031 end Is_Effectively_Volatile;
12033 ------------------------------------
12034 -- Is_Effectively_Volatile_Object --
12035 ------------------------------------
12037 function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean is
12039 if Is_Entity_Name (N) then
12040 return Is_Effectively_Volatile (Entity (N));
12042 elsif Nkind (N) = N_Expanded_Name then
12043 return Is_Effectively_Volatile (Entity (N));
12045 elsif Nkind (N) = N_Indexed_Component then
12046 return Is_Effectively_Volatile_Object (Prefix (N));
12048 elsif Nkind (N) = N_Selected_Component then
12050 Is_Effectively_Volatile_Object (Prefix (N))
12052 Is_Effectively_Volatile_Object (Selector_Name (N));
12057 end Is_Effectively_Volatile_Object;
12059 -------------------
12060 -- Is_Entry_Body --
12061 -------------------
12063 function Is_Entry_Body (Id : Entity_Id) return Boolean is
12066 Ekind_In (Id, E_Entry, E_Entry_Family)
12067 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Body;
12070 --------------------------
12071 -- Is_Entry_Declaration --
12072 --------------------------
12074 function Is_Entry_Declaration (Id : Entity_Id) return Boolean is
12077 Ekind_In (Id, E_Entry, E_Entry_Family)
12078 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Declaration;
12079 end Is_Entry_Declaration;
12081 ----------------------------
12082 -- Is_Expression_Function --
12083 ----------------------------
12085 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
12087 if Ekind_In (Subp, E_Function, E_Subprogram_Body) then
12089 Nkind (Original_Node (Unit_Declaration_Node (Subp))) =
12090 N_Expression_Function;
12094 end Is_Expression_Function;
12096 ------------------------------------------
12097 -- Is_Expression_Function_Or_Completion --
12098 ------------------------------------------
12100 function Is_Expression_Function_Or_Completion
12101 (Subp : Entity_Id) return Boolean
12103 Subp_Decl : Node_Id;
12106 if Ekind (Subp) = E_Function then
12107 Subp_Decl := Unit_Declaration_Node (Subp);
12109 -- The function declaration is either an expression function or is
12110 -- completed by an expression function body.
12113 Is_Expression_Function (Subp)
12114 or else (Nkind (Subp_Decl) = N_Subprogram_Declaration
12115 and then Present (Corresponding_Body (Subp_Decl))
12116 and then Is_Expression_Function
12117 (Corresponding_Body (Subp_Decl)));
12119 elsif Ekind (Subp) = E_Subprogram_Body then
12120 return Is_Expression_Function (Subp);
12125 end Is_Expression_Function_Or_Completion;
12127 -----------------------
12128 -- Is_EVF_Expression --
12129 -----------------------
12131 function Is_EVF_Expression (N : Node_Id) return Boolean is
12132 Orig_N : constant Node_Id := Original_Node (N);
12138 -- Detect a reference to a formal parameter of a specific tagged type
12139 -- whose related subprogram is subject to pragma Expresions_Visible with
12142 if Is_Entity_Name (N) and then Present (Entity (N)) then
12147 and then Is_Specific_Tagged_Type (Etype (Id))
12148 and then Extensions_Visible_Status (Id) =
12149 Extensions_Visible_False;
12151 -- A case expression is an EVF expression when it contains at least one
12152 -- EVF dependent_expression. Note that a case expression may have been
12153 -- expanded, hence the use of Original_Node.
12155 elsif Nkind (Orig_N) = N_Case_Expression then
12156 Alt := First (Alternatives (Orig_N));
12157 while Present (Alt) loop
12158 if Is_EVF_Expression (Expression (Alt)) then
12165 -- An if expression is an EVF expression when it contains at least one
12166 -- EVF dependent_expression. Note that an if expression may have been
12167 -- expanded, hence the use of Original_Node.
12169 elsif Nkind (Orig_N) = N_If_Expression then
12170 Expr := Next (First (Expressions (Orig_N)));
12171 while Present (Expr) loop
12172 if Is_EVF_Expression (Expr) then
12179 -- A qualified expression or a type conversion is an EVF expression when
12180 -- its operand is an EVF expression.
12182 elsif Nkind_In (N, N_Qualified_Expression,
12183 N_Unchecked_Type_Conversion,
12186 return Is_EVF_Expression (Expression (N));
12188 -- Attributes 'Loop_Entry, 'Old, and 'Update are EVF expressions when
12189 -- their prefix denotes an EVF expression.
12191 elsif Nkind (N) = N_Attribute_Reference
12192 and then Nam_In (Attribute_Name (N), Name_Loop_Entry,
12196 return Is_EVF_Expression (Prefix (N));
12200 end Is_EVF_Expression;
12206 function Is_False (U : Uint) return Boolean is
12211 ---------------------------
12212 -- Is_Fixed_Model_Number --
12213 ---------------------------
12215 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
12216 S : constant Ureal := Small_Value (T);
12217 M : Urealp.Save_Mark;
12221 R := (U = UR_Trunc (U / S) * S);
12222 Urealp.Release (M);
12224 end Is_Fixed_Model_Number;
12226 -------------------------------
12227 -- Is_Fully_Initialized_Type --
12228 -------------------------------
12230 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
12234 if Is_Scalar_Type (Typ) then
12236 -- A scalar type with an aspect Default_Value is fully initialized
12238 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
12239 -- of a scalar type, but we don't take that into account here, since
12240 -- we don't want these to affect warnings.
12242 return Has_Default_Aspect (Typ);
12244 elsif Is_Access_Type (Typ) then
12247 elsif Is_Array_Type (Typ) then
12248 if Is_Fully_Initialized_Type (Component_Type (Typ))
12249 or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
12254 -- An interesting case, if we have a constrained type one of whose
12255 -- bounds is known to be null, then there are no elements to be
12256 -- initialized, so all the elements are initialized.
12258 if Is_Constrained (Typ) then
12261 Indx_Typ : Entity_Id;
12262 Lbd, Hbd : Node_Id;
12265 Indx := First_Index (Typ);
12266 while Present (Indx) loop
12267 if Etype (Indx) = Any_Type then
12270 -- If index is a range, use directly
12272 elsif Nkind (Indx) = N_Range then
12273 Lbd := Low_Bound (Indx);
12274 Hbd := High_Bound (Indx);
12277 Indx_Typ := Etype (Indx);
12279 if Is_Private_Type (Indx_Typ) then
12280 Indx_Typ := Full_View (Indx_Typ);
12283 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
12286 Lbd := Type_Low_Bound (Indx_Typ);
12287 Hbd := Type_High_Bound (Indx_Typ);
12291 if Compile_Time_Known_Value (Lbd)
12293 Compile_Time_Known_Value (Hbd)
12295 if Expr_Value (Hbd) < Expr_Value (Lbd) then
12305 -- If no null indexes, then type is not fully initialized
12311 elsif Is_Record_Type (Typ) then
12312 if Has_Discriminants (Typ)
12314 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
12315 and then Is_Fully_Initialized_Variant (Typ)
12320 -- We consider bounded string types to be fully initialized, because
12321 -- otherwise we get false alarms when the Data component is not
12322 -- default-initialized.
12324 if Is_Bounded_String (Typ) then
12328 -- Controlled records are considered to be fully initialized if
12329 -- there is a user defined Initialize routine. This may not be
12330 -- entirely correct, but as the spec notes, we are guessing here
12331 -- what is best from the point of view of issuing warnings.
12333 if Is_Controlled (Typ) then
12335 Utyp : constant Entity_Id := Underlying_Type (Typ);
12338 if Present (Utyp) then
12340 Init : constant Entity_Id :=
12341 (Find_Optional_Prim_Op
12342 (Underlying_Type (Typ), Name_Initialize));
12346 and then Comes_From_Source (Init)
12348 Is_Predefined_File_Name
12349 (File_Name (Get_Source_File_Index (Sloc (Init))))
12353 elsif Has_Null_Extension (Typ)
12355 Is_Fully_Initialized_Type
12356 (Etype (Base_Type (Typ)))
12365 -- Otherwise see if all record components are initialized
12371 Ent := First_Entity (Typ);
12372 while Present (Ent) loop
12373 if Ekind (Ent) = E_Component
12374 and then (No (Parent (Ent))
12375 or else No (Expression (Parent (Ent))))
12376 and then not Is_Fully_Initialized_Type (Etype (Ent))
12378 -- Special VM case for tag components, which need to be
12379 -- defined in this case, but are never initialized as VMs
12380 -- are using other dispatching mechanisms. Ignore this
12381 -- uninitialized case. Note that this applies both to the
12382 -- uTag entry and the main vtable pointer (CPP_Class case).
12384 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
12393 -- No uninitialized components, so type is fully initialized.
12394 -- Note that this catches the case of no components as well.
12398 elsif Is_Concurrent_Type (Typ) then
12401 elsif Is_Private_Type (Typ) then
12403 U : constant Entity_Id := Underlying_Type (Typ);
12409 return Is_Fully_Initialized_Type (U);
12416 end Is_Fully_Initialized_Type;
12418 ----------------------------------
12419 -- Is_Fully_Initialized_Variant --
12420 ----------------------------------
12422 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
12423 Loc : constant Source_Ptr := Sloc (Typ);
12424 Constraints : constant List_Id := New_List;
12425 Components : constant Elist_Id := New_Elmt_List;
12426 Comp_Elmt : Elmt_Id;
12428 Comp_List : Node_Id;
12430 Discr_Val : Node_Id;
12432 Report_Errors : Boolean;
12433 pragma Warnings (Off, Report_Errors);
12436 if Serious_Errors_Detected > 0 then
12440 if Is_Record_Type (Typ)
12441 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
12442 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
12444 Comp_List := Component_List (Type_Definition (Parent (Typ)));
12446 Discr := First_Discriminant (Typ);
12447 while Present (Discr) loop
12448 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
12449 Discr_Val := Expression (Parent (Discr));
12451 if Present (Discr_Val)
12452 and then Is_OK_Static_Expression (Discr_Val)
12454 Append_To (Constraints,
12455 Make_Component_Association (Loc,
12456 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
12457 Expression => New_Copy (Discr_Val)));
12465 Next_Discriminant (Discr);
12470 Comp_List => Comp_List,
12471 Governed_By => Constraints,
12472 Into => Components,
12473 Report_Errors => Report_Errors);
12475 -- Check that each component present is fully initialized
12477 Comp_Elmt := First_Elmt (Components);
12478 while Present (Comp_Elmt) loop
12479 Comp_Id := Node (Comp_Elmt);
12481 if Ekind (Comp_Id) = E_Component
12482 and then (No (Parent (Comp_Id))
12483 or else No (Expression (Parent (Comp_Id))))
12484 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
12489 Next_Elmt (Comp_Elmt);
12494 elsif Is_Private_Type (Typ) then
12496 U : constant Entity_Id := Underlying_Type (Typ);
12502 return Is_Fully_Initialized_Variant (U);
12509 end Is_Fully_Initialized_Variant;
12511 ------------------------------------
12512 -- Is_Generic_Declaration_Or_Body --
12513 ------------------------------------
12515 function Is_Generic_Declaration_Or_Body (Decl : Node_Id) return Boolean is
12516 Spec_Decl : Node_Id;
12519 -- Package/subprogram body
12521 if Nkind_In (Decl, N_Package_Body, N_Subprogram_Body)
12522 and then Present (Corresponding_Spec (Decl))
12524 Spec_Decl := Unit_Declaration_Node (Corresponding_Spec (Decl));
12526 -- Package/subprogram body stub
12528 elsif Nkind_In (Decl, N_Package_Body_Stub, N_Subprogram_Body_Stub)
12529 and then Present (Corresponding_Spec_Of_Stub (Decl))
12532 Unit_Declaration_Node (Corresponding_Spec_Of_Stub (Decl));
12540 -- Rather than inspecting the defining entity of the spec declaration,
12541 -- look at its Nkind. This takes care of the case where the analysis of
12542 -- a generic body modifies the Ekind of its spec to allow for recursive
12546 Nkind_In (Spec_Decl, N_Generic_Package_Declaration,
12547 N_Generic_Subprogram_Declaration);
12548 end Is_Generic_Declaration_Or_Body;
12550 ----------------------------
12551 -- Is_Inherited_Operation --
12552 ----------------------------
12554 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
12555 pragma Assert (Is_Overloadable (E));
12556 Kind : constant Node_Kind := Nkind (Parent (E));
12558 return Kind = N_Full_Type_Declaration
12559 or else Kind = N_Private_Extension_Declaration
12560 or else Kind = N_Subtype_Declaration
12561 or else (Ekind (E) = E_Enumeration_Literal
12562 and then Is_Derived_Type (Etype (E)));
12563 end Is_Inherited_Operation;
12565 -------------------------------------
12566 -- Is_Inherited_Operation_For_Type --
12567 -------------------------------------
12569 function Is_Inherited_Operation_For_Type
12571 Typ : Entity_Id) return Boolean
12574 -- Check that the operation has been created by the type declaration
12576 return Is_Inherited_Operation (E)
12577 and then Defining_Identifier (Parent (E)) = Typ;
12578 end Is_Inherited_Operation_For_Type;
12584 function Is_Iterator (Typ : Entity_Id) return Boolean is
12585 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean;
12586 -- Determine whether type Iter_Typ is a predefined forward or reversible
12589 ----------------------
12590 -- Denotes_Iterator --
12591 ----------------------
12593 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean is
12596 Nam_In (Chars (Iter_Typ), Name_Forward_Iterator,
12597 Name_Reversible_Iterator)
12598 and then Is_Predefined_File_Name
12599 (Unit_File_Name (Get_Source_Unit (Iter_Typ)));
12600 end Denotes_Iterator;
12604 Iface_Elmt : Elmt_Id;
12607 -- Start of processing for Is_Iterator
12610 -- The type may be a subtype of a descendant of the proper instance of
12611 -- the predefined interface type, so we must use the root type of the
12612 -- given type. The same is done for Is_Reversible_Iterator.
12614 if Is_Class_Wide_Type (Typ)
12615 and then Denotes_Iterator (Root_Type (Typ))
12619 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
12622 elsif Present (Find_Value_Of_Aspect (Typ, Aspect_Iterable)) then
12626 Collect_Interfaces (Typ, Ifaces);
12628 Iface_Elmt := First_Elmt (Ifaces);
12629 while Present (Iface_Elmt) loop
12630 if Denotes_Iterator (Node (Iface_Elmt)) then
12634 Next_Elmt (Iface_Elmt);
12641 ----------------------------
12642 -- Is_Iterator_Over_Array --
12643 ----------------------------
12645 function Is_Iterator_Over_Array (N : Node_Id) return Boolean is
12646 Container : constant Node_Id := Name (N);
12647 Container_Typ : constant Entity_Id := Base_Type (Etype (Container));
12649 return Is_Array_Type (Container_Typ);
12650 end Is_Iterator_Over_Array;
12656 -- We seem to have a lot of overlapping functions that do similar things
12657 -- (testing for left hand sides or lvalues???).
12659 function Is_LHS (N : Node_Id) return Is_LHS_Result is
12660 P : constant Node_Id := Parent (N);
12663 -- Return True if we are the left hand side of an assignment statement
12665 if Nkind (P) = N_Assignment_Statement then
12666 if Name (P) = N then
12672 -- Case of prefix of indexed or selected component or slice
12674 elsif Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
12675 and then N = Prefix (P)
12677 -- Here we have the case where the parent P is N.Q or N(Q .. R).
12678 -- If P is an LHS, then N is also effectively an LHS, but there
12679 -- is an important exception. If N is of an access type, then
12680 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
12681 -- case this makes N.all a left hand side but not N itself.
12683 -- If we don't know the type yet, this is the case where we return
12684 -- Unknown, since the answer depends on the type which is unknown.
12686 if No (Etype (N)) then
12689 -- We have an Etype set, so we can check it
12691 elsif Is_Access_Type (Etype (N)) then
12694 -- OK, not access type case, so just test whole expression
12700 -- All other cases are not left hand sides
12707 -----------------------------
12708 -- Is_Library_Level_Entity --
12709 -----------------------------
12711 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
12713 -- The following is a small optimization, and it also properly handles
12714 -- discriminals, which in task bodies might appear in expressions before
12715 -- the corresponding procedure has been created, and which therefore do
12716 -- not have an assigned scope.
12718 if Is_Formal (E) then
12722 -- Normal test is simply that the enclosing dynamic scope is Standard
12724 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
12725 end Is_Library_Level_Entity;
12727 --------------------------------
12728 -- Is_Limited_Class_Wide_Type --
12729 --------------------------------
12731 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
12734 Is_Class_Wide_Type (Typ)
12735 and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
12736 end Is_Limited_Class_Wide_Type;
12738 ---------------------------------
12739 -- Is_Local_Variable_Reference --
12740 ---------------------------------
12742 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
12744 if not Is_Entity_Name (Expr) then
12749 Ent : constant Entity_Id := Entity (Expr);
12750 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
12752 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
12755 return Present (Sub) and then Sub = Current_Subprogram;
12759 end Is_Local_Variable_Reference;
12761 -----------------------------------------------
12762 -- Is_Nontrivial_Default_Init_Cond_Procedure --
12763 -----------------------------------------------
12765 function Is_Nontrivial_Default_Init_Cond_Procedure
12766 (Id : Entity_Id) return Boolean
12768 Body_Decl : Node_Id;
12772 if Ekind (Id) = E_Procedure
12773 and then Is_Default_Init_Cond_Procedure (Id)
12776 Unit_Declaration_Node
12777 (Corresponding_Body (Unit_Declaration_Node (Id)));
12779 -- The body of the Default_Initial_Condition procedure must contain
12780 -- at least one statement, otherwise the generation of the subprogram
12783 pragma Assert (Present (Handled_Statement_Sequence (Body_Decl)));
12785 -- To qualify as nontrivial, the first statement of the procedure
12786 -- must be a check in the form of an if statement. If the original
12787 -- Default_Initial_Condition expression was folded, then the first
12788 -- statement is not a check.
12790 Stmt := First (Statements (Handled_Statement_Sequence (Body_Decl)));
12793 Nkind (Stmt) = N_If_Statement
12794 and then Nkind (Original_Node (Stmt)) = N_Pragma;
12798 end Is_Nontrivial_Default_Init_Cond_Procedure;
12800 -------------------------
12801 -- Is_Object_Reference --
12802 -------------------------
12804 function Is_Object_Reference (N : Node_Id) return Boolean is
12805 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean;
12806 -- Determine whether N is the name of an internally-generated renaming
12808 --------------------------------------
12809 -- Is_Internally_Generated_Renaming --
12810 --------------------------------------
12812 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean is
12817 while Present (P) loop
12818 if Nkind (P) = N_Object_Renaming_Declaration then
12819 return not Comes_From_Source (P);
12820 elsif Is_List_Member (P) then
12828 end Is_Internally_Generated_Renaming;
12830 -- Start of processing for Is_Object_Reference
12833 if Is_Entity_Name (N) then
12834 return Present (Entity (N)) and then Is_Object (Entity (N));
12838 when N_Indexed_Component | N_Slice =>
12840 Is_Object_Reference (Prefix (N))
12841 or else Is_Access_Type (Etype (Prefix (N)));
12843 -- In Ada 95, a function call is a constant object; a procedure
12846 when N_Function_Call =>
12847 return Etype (N) /= Standard_Void_Type;
12849 -- Attributes 'Input, 'Loop_Entry, 'Old and 'Result produce
12852 when N_Attribute_Reference =>
12854 Nam_In (Attribute_Name (N), Name_Input,
12859 when N_Selected_Component =>
12861 Is_Object_Reference (Selector_Name (N))
12863 (Is_Object_Reference (Prefix (N))
12864 or else Is_Access_Type (Etype (Prefix (N))));
12866 when N_Explicit_Dereference =>
12869 -- A view conversion of a tagged object is an object reference
12871 when N_Type_Conversion =>
12872 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
12873 and then Is_Tagged_Type (Etype (Expression (N)))
12874 and then Is_Object_Reference (Expression (N));
12876 -- An unchecked type conversion is considered to be an object if
12877 -- the operand is an object (this construction arises only as a
12878 -- result of expansion activities).
12880 when N_Unchecked_Type_Conversion =>
12883 -- Allow string literals to act as objects as long as they appear
12884 -- in internally-generated renamings. The expansion of iterators
12885 -- may generate such renamings when the range involves a string
12888 when N_String_Literal =>
12889 return Is_Internally_Generated_Renaming (Parent (N));
12891 -- AI05-0003: In Ada 2012 a qualified expression is a name.
12892 -- This allows disambiguation of function calls and the use
12893 -- of aggregates in more contexts.
12895 when N_Qualified_Expression =>
12896 if Ada_Version < Ada_2012 then
12899 return Is_Object_Reference (Expression (N))
12900 or else Nkind (Expression (N)) = N_Aggregate;
12907 end Is_Object_Reference;
12909 -----------------------------------
12910 -- Is_OK_Variable_For_Out_Formal --
12911 -----------------------------------
12913 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
12915 Note_Possible_Modification (AV, Sure => True);
12917 -- We must reject parenthesized variable names. Comes_From_Source is
12918 -- checked because there are currently cases where the compiler violates
12919 -- this rule (e.g. passing a task object to its controlled Initialize
12920 -- routine). This should be properly documented in sinfo???
12922 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
12925 -- A variable is always allowed
12927 elsif Is_Variable (AV) then
12930 -- Generalized indexing operations are rewritten as explicit
12931 -- dereferences, and it is only during resolution that we can
12932 -- check whether the context requires an access_to_variable type.
12934 elsif Nkind (AV) = N_Explicit_Dereference
12935 and then Ada_Version >= Ada_2012
12936 and then Nkind (Original_Node (AV)) = N_Indexed_Component
12937 and then Present (Etype (Original_Node (AV)))
12938 and then Has_Implicit_Dereference (Etype (Original_Node (AV)))
12940 return not Is_Access_Constant (Etype (Prefix (AV)));
12942 -- Unchecked conversions are allowed only if they come from the
12943 -- generated code, which sometimes uses unchecked conversions for out
12944 -- parameters in cases where code generation is unaffected. We tell
12945 -- source unchecked conversions by seeing if they are rewrites of
12946 -- an original Unchecked_Conversion function call, or of an explicit
12947 -- conversion of a function call or an aggregate (as may happen in the
12948 -- expansion of a packed array aggregate).
12950 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
12951 if Nkind_In (Original_Node (AV), N_Function_Call, N_Aggregate) then
12954 elsif Comes_From_Source (AV)
12955 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
12959 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
12960 return Is_OK_Variable_For_Out_Formal (Expression (AV));
12966 -- Normal type conversions are allowed if argument is a variable
12968 elsif Nkind (AV) = N_Type_Conversion then
12969 if Is_Variable (Expression (AV))
12970 and then Paren_Count (Expression (AV)) = 0
12972 Note_Possible_Modification (Expression (AV), Sure => True);
12975 -- We also allow a non-parenthesized expression that raises
12976 -- constraint error if it rewrites what used to be a variable
12978 elsif Raises_Constraint_Error (Expression (AV))
12979 and then Paren_Count (Expression (AV)) = 0
12980 and then Is_Variable (Original_Node (Expression (AV)))
12984 -- Type conversion of something other than a variable
12990 -- If this node is rewritten, then test the original form, if that is
12991 -- OK, then we consider the rewritten node OK (for example, if the
12992 -- original node is a conversion, then Is_Variable will not be true
12993 -- but we still want to allow the conversion if it converts a variable).
12995 elsif Original_Node (AV) /= AV then
12997 -- In Ada 2012, the explicit dereference may be a rewritten call to a
12998 -- Reference function.
13000 if Ada_Version >= Ada_2012
13001 and then Nkind (Original_Node (AV)) = N_Function_Call
13003 Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
13006 -- Check that this is not a constant reference.
13008 return not Is_Access_Constant (Etype (Prefix (AV)));
13010 elsif Has_Implicit_Dereference (Etype (Original_Node (AV))) then
13012 not Is_Access_Constant (Etype
13013 (Get_Reference_Discriminant (Etype (Original_Node (AV)))));
13016 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
13019 -- All other non-variables are rejected
13024 end Is_OK_Variable_For_Out_Formal;
13026 ----------------------------
13027 -- Is_OK_Volatile_Context --
13028 ----------------------------
13030 function Is_OK_Volatile_Context
13031 (Context : Node_Id;
13032 Obj_Ref : Node_Id) return Boolean
13034 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean;
13035 -- Determine whether an arbitrary node denotes a call to a protected
13036 -- entry, function or procedure in prefixed form where the prefix is
13039 function Within_Check (Nod : Node_Id) return Boolean;
13040 -- Determine whether an arbitrary node appears in a check node
13042 function Within_Subprogram_Call (Nod : Node_Id) return Boolean;
13043 -- Determine whether an arbitrary node appears in a procedure call
13045 function Within_Volatile_Function (Id : Entity_Id) return Boolean;
13046 -- Determine whether an arbitrary entity appears in a volatile function
13048 ---------------------------------
13049 -- Is_Protected_Operation_Call --
13050 ---------------------------------
13052 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean is
13057 -- A call to a protected operations retains its selected component
13058 -- form as opposed to other prefixed calls that are transformed in
13061 if Nkind (Nod) = N_Selected_Component then
13062 Pref := Prefix (Nod);
13063 Subp := Selector_Name (Nod);
13067 and then Present (Etype (Pref))
13068 and then Is_Protected_Type (Etype (Pref))
13069 and then Is_Entity_Name (Subp)
13070 and then Present (Entity (Subp))
13071 and then Ekind_In (Entity (Subp), E_Entry,
13078 end Is_Protected_Operation_Call;
13084 function Within_Check (Nod : Node_Id) return Boolean is
13088 -- Climb the parent chain looking for a check node
13091 while Present (Par) loop
13092 if Nkind (Par) in N_Raise_xxx_Error then
13095 -- Prevent the search from going too far
13097 elsif Is_Body_Or_Package_Declaration (Par) then
13101 Par := Parent (Par);
13107 ----------------------------
13108 -- Within_Subprogram_Call --
13109 ----------------------------
13111 function Within_Subprogram_Call (Nod : Node_Id) return Boolean is
13115 -- Climb the parent chain looking for a function or procedure call
13118 while Present (Par) loop
13119 if Nkind_In (Par, N_Entry_Call_Statement,
13121 N_Procedure_Call_Statement)
13125 -- Prevent the search from going too far
13127 elsif Is_Body_Or_Package_Declaration (Par) then
13131 Par := Parent (Par);
13135 end Within_Subprogram_Call;
13137 ------------------------------
13138 -- Within_Volatile_Function --
13139 ------------------------------
13141 function Within_Volatile_Function (Id : Entity_Id) return Boolean is
13142 Func_Id : Entity_Id;
13145 -- Traverse the scope stack looking for a [generic] function
13148 while Present (Func_Id) and then Func_Id /= Standard_Standard loop
13149 if Ekind_In (Func_Id, E_Function, E_Generic_Function) then
13150 return Is_Volatile_Function (Func_Id);
13153 Func_Id := Scope (Func_Id);
13157 end Within_Volatile_Function;
13161 Obj_Id : Entity_Id;
13163 -- Start of processing for Is_OK_Volatile_Context
13166 -- The volatile object appears on either side of an assignment
13168 if Nkind (Context) = N_Assignment_Statement then
13171 -- The volatile object is part of the initialization expression of
13174 elsif Nkind (Context) = N_Object_Declaration
13175 and then Present (Expression (Context))
13176 and then Expression (Context) = Obj_Ref
13178 Obj_Id := Defining_Entity (Context);
13180 -- The volatile object acts as the initialization expression of an
13181 -- extended return statement. This is valid context as long as the
13182 -- function is volatile.
13184 if Is_Return_Object (Obj_Id) then
13185 return Within_Volatile_Function (Obj_Id);
13187 -- Otherwise this is a normal object initialization
13193 -- The volatile object acts as the name of a renaming declaration
13195 elsif Nkind (Context) = N_Object_Renaming_Declaration
13196 and then Name (Context) = Obj_Ref
13200 -- The volatile object appears as an actual parameter in a call to an
13201 -- instance of Unchecked_Conversion whose result is renamed.
13203 elsif Nkind (Context) = N_Function_Call
13204 and then Is_Entity_Name (Name (Context))
13205 and then Is_Unchecked_Conversion_Instance (Entity (Name (Context)))
13206 and then Nkind (Parent (Context)) = N_Object_Renaming_Declaration
13210 -- The volatile object is actually the prefix in a protected entry,
13211 -- function, or procedure call.
13213 elsif Is_Protected_Operation_Call (Context) then
13216 -- The volatile object appears as the expression of a simple return
13217 -- statement that applies to a volatile function.
13219 elsif Nkind (Context) = N_Simple_Return_Statement
13220 and then Expression (Context) = Obj_Ref
13223 Within_Volatile_Function (Return_Statement_Entity (Context));
13225 -- The volatile object appears as the prefix of a name occurring in a
13226 -- non-interfering context.
13228 elsif Nkind_In (Context, N_Attribute_Reference,
13229 N_Explicit_Dereference,
13230 N_Indexed_Component,
13231 N_Selected_Component,
13233 and then Prefix (Context) = Obj_Ref
13234 and then Is_OK_Volatile_Context
13235 (Context => Parent (Context),
13236 Obj_Ref => Context)
13240 -- The volatile object appears as the expression of a type conversion
13241 -- occurring in a non-interfering context.
13243 elsif Nkind_In (Context, N_Type_Conversion,
13244 N_Unchecked_Type_Conversion)
13245 and then Expression (Context) = Obj_Ref
13246 and then Is_OK_Volatile_Context
13247 (Context => Parent (Context),
13248 Obj_Ref => Context)
13252 -- Allow references to volatile objects in various checks. This is
13253 -- not a direct SPARK 2014 requirement.
13255 elsif Within_Check (Context) then
13258 -- Assume that references to effectively volatile objects that appear
13259 -- as actual parameters in a subprogram call are always legal. A full
13260 -- legality check is done when the actuals are resolved.
13262 elsif Within_Subprogram_Call (Context) then
13265 -- Otherwise the context is not suitable for an effectively volatile
13271 end Is_OK_Volatile_Context;
13273 ------------------------------------
13274 -- Is_Package_Contract_Annotation --
13275 ------------------------------------
13277 function Is_Package_Contract_Annotation (Item : Node_Id) return Boolean is
13281 if Nkind (Item) = N_Aspect_Specification then
13282 Nam := Chars (Identifier (Item));
13284 else pragma Assert (Nkind (Item) = N_Pragma);
13285 Nam := Pragma_Name (Item);
13288 return Nam = Name_Abstract_State
13289 or else Nam = Name_Initial_Condition
13290 or else Nam = Name_Initializes
13291 or else Nam = Name_Refined_State;
13292 end Is_Package_Contract_Annotation;
13294 -----------------------------------
13295 -- Is_Partially_Initialized_Type --
13296 -----------------------------------
13298 function Is_Partially_Initialized_Type
13300 Include_Implicit : Boolean := True) return Boolean
13303 if Is_Scalar_Type (Typ) then
13306 elsif Is_Access_Type (Typ) then
13307 return Include_Implicit;
13309 elsif Is_Array_Type (Typ) then
13311 -- If component type is partially initialized, so is array type
13313 if Is_Partially_Initialized_Type
13314 (Component_Type (Typ), Include_Implicit)
13318 -- Otherwise we are only partially initialized if we are fully
13319 -- initialized (this is the empty array case, no point in us
13320 -- duplicating that code here).
13323 return Is_Fully_Initialized_Type (Typ);
13326 elsif Is_Record_Type (Typ) then
13328 -- A discriminated type is always partially initialized if in
13331 if Has_Discriminants (Typ) and then Include_Implicit then
13334 -- A tagged type is always partially initialized
13336 elsif Is_Tagged_Type (Typ) then
13339 -- Case of non-discriminated record
13345 Component_Present : Boolean := False;
13346 -- Set True if at least one component is present. If no
13347 -- components are present, then record type is fully
13348 -- initialized (another odd case, like the null array).
13351 -- Loop through components
13353 Ent := First_Entity (Typ);
13354 while Present (Ent) loop
13355 if Ekind (Ent) = E_Component then
13356 Component_Present := True;
13358 -- If a component has an initialization expression then
13359 -- the enclosing record type is partially initialized
13361 if Present (Parent (Ent))
13362 and then Present (Expression (Parent (Ent)))
13366 -- If a component is of a type which is itself partially
13367 -- initialized, then the enclosing record type is also.
13369 elsif Is_Partially_Initialized_Type
13370 (Etype (Ent), Include_Implicit)
13379 -- No initialized components found. If we found any components
13380 -- they were all uninitialized so the result is false.
13382 if Component_Present then
13385 -- But if we found no components, then all the components are
13386 -- initialized so we consider the type to be initialized.
13394 -- Concurrent types are always fully initialized
13396 elsif Is_Concurrent_Type (Typ) then
13399 -- For a private type, go to underlying type. If there is no underlying
13400 -- type then just assume this partially initialized. Not clear if this
13401 -- can happen in a non-error case, but no harm in testing for this.
13403 elsif Is_Private_Type (Typ) then
13405 U : constant Entity_Id := Underlying_Type (Typ);
13410 return Is_Partially_Initialized_Type (U, Include_Implicit);
13414 -- For any other type (are there any?) assume partially initialized
13419 end Is_Partially_Initialized_Type;
13421 ------------------------------------
13422 -- Is_Potentially_Persistent_Type --
13423 ------------------------------------
13425 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
13430 -- For private type, test corresponding full type
13432 if Is_Private_Type (T) then
13433 return Is_Potentially_Persistent_Type (Full_View (T));
13435 -- Scalar types are potentially persistent
13437 elsif Is_Scalar_Type (T) then
13440 -- Record type is potentially persistent if not tagged and the types of
13441 -- all it components are potentially persistent, and no component has
13442 -- an initialization expression.
13444 elsif Is_Record_Type (T)
13445 and then not Is_Tagged_Type (T)
13446 and then not Is_Partially_Initialized_Type (T)
13448 Comp := First_Component (T);
13449 while Present (Comp) loop
13450 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
13453 Next_Entity (Comp);
13459 -- Array type is potentially persistent if its component type is
13460 -- potentially persistent and if all its constraints are static.
13462 elsif Is_Array_Type (T) then
13463 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
13467 Indx := First_Index (T);
13468 while Present (Indx) loop
13469 if not Is_OK_Static_Subtype (Etype (Indx)) then
13478 -- All other types are not potentially persistent
13483 end Is_Potentially_Persistent_Type;
13485 --------------------------------
13486 -- Is_Potentially_Unevaluated --
13487 --------------------------------
13489 function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is
13497 -- A postcondition whose expression is a short-circuit is broken down
13498 -- into individual aspects for better exception reporting. The original
13499 -- short-circuit expression is rewritten as the second operand, and an
13500 -- occurrence of 'Old in that operand is potentially unevaluated.
13501 -- See Sem_ch13.adb for details of this transformation.
13503 if Nkind (Original_Node (Par)) = N_And_Then then
13507 while not Nkind_In (Par, N_If_Expression,
13515 Par := Parent (Par);
13517 -- If the context is not an expression, or if is the result of
13518 -- expansion of an enclosing construct (such as another attribute)
13519 -- the predicate does not apply.
13521 if Nkind (Par) not in N_Subexpr
13522 or else not Comes_From_Source (Par)
13528 if Nkind (Par) = N_If_Expression then
13529 return Is_Elsif (Par) or else Expr /= First (Expressions (Par));
13531 elsif Nkind (Par) = N_Case_Expression then
13532 return Expr /= Expression (Par);
13534 elsif Nkind_In (Par, N_And_Then, N_Or_Else) then
13535 return Expr = Right_Opnd (Par);
13537 elsif Nkind_In (Par, N_In, N_Not_In) then
13538 return Expr /= Left_Opnd (Par);
13543 end Is_Potentially_Unevaluated;
13545 ---------------------------------
13546 -- Is_Protected_Self_Reference --
13547 ---------------------------------
13549 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
13551 function In_Access_Definition (N : Node_Id) return Boolean;
13552 -- Returns true if N belongs to an access definition
13554 --------------------------
13555 -- In_Access_Definition --
13556 --------------------------
13558 function In_Access_Definition (N : Node_Id) return Boolean is
13563 while Present (P) loop
13564 if Nkind (P) = N_Access_Definition then
13572 end In_Access_Definition;
13574 -- Start of processing for Is_Protected_Self_Reference
13577 -- Verify that prefix is analyzed and has the proper form. Note that
13578 -- the attributes Elab_Spec, Elab_Body and Elab_Subp_Body which also
13579 -- produce the address of an entity, do not analyze their prefix
13580 -- because they denote entities that are not necessarily visible.
13581 -- Neither of them can apply to a protected type.
13583 return Ada_Version >= Ada_2005
13584 and then Is_Entity_Name (N)
13585 and then Present (Entity (N))
13586 and then Is_Protected_Type (Entity (N))
13587 and then In_Open_Scopes (Entity (N))
13588 and then not In_Access_Definition (N);
13589 end Is_Protected_Self_Reference;
13591 -----------------------------
13592 -- Is_RCI_Pkg_Spec_Or_Body --
13593 -----------------------------
13595 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
13597 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
13598 -- Return True if the unit of Cunit is an RCI package declaration
13600 ---------------------------
13601 -- Is_RCI_Pkg_Decl_Cunit --
13602 ---------------------------
13604 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
13605 The_Unit : constant Node_Id := Unit (Cunit);
13608 if Nkind (The_Unit) /= N_Package_Declaration then
13612 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
13613 end Is_RCI_Pkg_Decl_Cunit;
13615 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
13618 return Is_RCI_Pkg_Decl_Cunit (Cunit)
13620 (Nkind (Unit (Cunit)) = N_Package_Body
13621 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
13622 end Is_RCI_Pkg_Spec_Or_Body;
13624 -----------------------------------------
13625 -- Is_Remote_Access_To_Class_Wide_Type --
13626 -----------------------------------------
13628 function Is_Remote_Access_To_Class_Wide_Type
13629 (E : Entity_Id) return Boolean
13632 -- A remote access to class-wide type is a general access to object type
13633 -- declared in the visible part of a Remote_Types or Remote_Call_
13636 return Ekind (E) = E_General_Access_Type
13637 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
13638 end Is_Remote_Access_To_Class_Wide_Type;
13640 -----------------------------------------
13641 -- Is_Remote_Access_To_Subprogram_Type --
13642 -----------------------------------------
13644 function Is_Remote_Access_To_Subprogram_Type
13645 (E : Entity_Id) return Boolean
13648 return (Ekind (E) = E_Access_Subprogram_Type
13649 or else (Ekind (E) = E_Record_Type
13650 and then Present (Corresponding_Remote_Type (E))))
13651 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
13652 end Is_Remote_Access_To_Subprogram_Type;
13654 --------------------
13655 -- Is_Remote_Call --
13656 --------------------
13658 function Is_Remote_Call (N : Node_Id) return Boolean is
13660 if Nkind (N) not in N_Subprogram_Call then
13662 -- An entry call cannot be remote
13666 elsif Nkind (Name (N)) in N_Has_Entity
13667 and then Is_Remote_Call_Interface (Entity (Name (N)))
13669 -- A subprogram declared in the spec of a RCI package is remote
13673 elsif Nkind (Name (N)) = N_Explicit_Dereference
13674 and then Is_Remote_Access_To_Subprogram_Type
13675 (Etype (Prefix (Name (N))))
13677 -- The dereference of a RAS is a remote call
13681 elsif Present (Controlling_Argument (N))
13682 and then Is_Remote_Access_To_Class_Wide_Type
13683 (Etype (Controlling_Argument (N)))
13685 -- Any primitive operation call with a controlling argument of
13686 -- a RACW type is a remote call.
13691 -- All other calls are local calls
13694 end Is_Remote_Call;
13696 ----------------------
13697 -- Is_Renamed_Entry --
13698 ----------------------
13700 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
13701 Orig_Node : Node_Id := Empty;
13702 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
13704 function Is_Entry (Nam : Node_Id) return Boolean;
13705 -- Determine whether Nam is an entry. Traverse selectors if there are
13706 -- nested selected components.
13712 function Is_Entry (Nam : Node_Id) return Boolean is
13714 if Nkind (Nam) = N_Selected_Component then
13715 return Is_Entry (Selector_Name (Nam));
13718 return Ekind (Entity (Nam)) = E_Entry;
13721 -- Start of processing for Is_Renamed_Entry
13724 if Present (Alias (Proc_Nam)) then
13725 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
13728 -- Look for a rewritten subprogram renaming declaration
13730 if Nkind (Subp_Decl) = N_Subprogram_Declaration
13731 and then Present (Original_Node (Subp_Decl))
13733 Orig_Node := Original_Node (Subp_Decl);
13736 -- The rewritten subprogram is actually an entry
13738 if Present (Orig_Node)
13739 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
13740 and then Is_Entry (Name (Orig_Node))
13746 end Is_Renamed_Entry;
13748 -----------------------------
13749 -- Is_Renaming_Declaration --
13750 -----------------------------
13752 function Is_Renaming_Declaration (N : Node_Id) return Boolean is
13755 when N_Exception_Renaming_Declaration |
13756 N_Generic_Function_Renaming_Declaration |
13757 N_Generic_Package_Renaming_Declaration |
13758 N_Generic_Procedure_Renaming_Declaration |
13759 N_Object_Renaming_Declaration |
13760 N_Package_Renaming_Declaration |
13761 N_Subprogram_Renaming_Declaration =>
13767 end Is_Renaming_Declaration;
13769 ----------------------------
13770 -- Is_Reversible_Iterator --
13771 ----------------------------
13773 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
13774 Ifaces_List : Elist_Id;
13775 Iface_Elmt : Elmt_Id;
13779 if Is_Class_Wide_Type (Typ)
13780 and then Chars (Root_Type (Typ)) = Name_Reversible_Iterator
13781 and then Is_Predefined_File_Name
13782 (Unit_File_Name (Get_Source_Unit (Root_Type (Typ))))
13786 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
13790 Collect_Interfaces (Typ, Ifaces_List);
13792 Iface_Elmt := First_Elmt (Ifaces_List);
13793 while Present (Iface_Elmt) loop
13794 Iface := Node (Iface_Elmt);
13795 if Chars (Iface) = Name_Reversible_Iterator
13797 Is_Predefined_File_Name
13798 (Unit_File_Name (Get_Source_Unit (Iface)))
13803 Next_Elmt (Iface_Elmt);
13808 end Is_Reversible_Iterator;
13810 ----------------------
13811 -- Is_Selector_Name --
13812 ----------------------
13814 function Is_Selector_Name (N : Node_Id) return Boolean is
13816 if not Is_List_Member (N) then
13818 P : constant Node_Id := Parent (N);
13820 return Nkind_In (P, N_Expanded_Name,
13821 N_Generic_Association,
13822 N_Parameter_Association,
13823 N_Selected_Component)
13824 and then Selector_Name (P) = N;
13829 L : constant List_Id := List_Containing (N);
13830 P : constant Node_Id := Parent (L);
13832 return (Nkind (P) = N_Discriminant_Association
13833 and then Selector_Names (P) = L)
13835 (Nkind (P) = N_Component_Association
13836 and then Choices (P) = L);
13839 end Is_Selector_Name;
13841 ---------------------------------
13842 -- Is_Single_Concurrent_Object --
13843 ---------------------------------
13845 function Is_Single_Concurrent_Object (Id : Entity_Id) return Boolean is
13848 Is_Single_Protected_Object (Id) or else Is_Single_Task_Object (Id);
13849 end Is_Single_Concurrent_Object;
13851 -------------------------------
13852 -- Is_Single_Concurrent_Type --
13853 -------------------------------
13855 function Is_Single_Concurrent_Type (Id : Entity_Id) return Boolean is
13858 Ekind_In (Id, E_Protected_Type, E_Task_Type)
13859 and then Is_Single_Concurrent_Type_Declaration
13860 (Declaration_Node (Id));
13861 end Is_Single_Concurrent_Type;
13863 -------------------------------------------
13864 -- Is_Single_Concurrent_Type_Declaration --
13865 -------------------------------------------
13867 function Is_Single_Concurrent_Type_Declaration
13868 (N : Node_Id) return Boolean
13871 return Nkind_In (Original_Node (N), N_Single_Protected_Declaration,
13872 N_Single_Task_Declaration);
13873 end Is_Single_Concurrent_Type_Declaration;
13875 ---------------------------------------------
13876 -- Is_Single_Precision_Floating_Point_Type --
13877 ---------------------------------------------
13879 function Is_Single_Precision_Floating_Point_Type
13880 (E : Entity_Id) return Boolean is
13882 return Is_Floating_Point_Type (E)
13883 and then Machine_Radix_Value (E) = Uint_2
13884 and then Machine_Mantissa_Value (E) = Uint_24
13885 and then Machine_Emax_Value (E) = Uint_2 ** Uint_7
13886 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_7);
13887 end Is_Single_Precision_Floating_Point_Type;
13889 --------------------------------
13890 -- Is_Single_Protected_Object --
13891 --------------------------------
13893 function Is_Single_Protected_Object (Id : Entity_Id) return Boolean is
13896 Ekind (Id) = E_Variable
13897 and then Ekind (Etype (Id)) = E_Protected_Type
13898 and then Is_Single_Concurrent_Type (Etype (Id));
13899 end Is_Single_Protected_Object;
13901 ---------------------------
13902 -- Is_Single_Task_Object --
13903 ---------------------------
13905 function Is_Single_Task_Object (Id : Entity_Id) return Boolean is
13908 Ekind (Id) = E_Variable
13909 and then Ekind (Etype (Id)) = E_Task_Type
13910 and then Is_Single_Concurrent_Type (Etype (Id));
13911 end Is_Single_Task_Object;
13913 -------------------------------------
13914 -- Is_SPARK_05_Initialization_Expr --
13915 -------------------------------------
13917 function Is_SPARK_05_Initialization_Expr (N : Node_Id) return Boolean is
13920 Comp_Assn : Node_Id;
13921 Orig_N : constant Node_Id := Original_Node (N);
13926 if not Comes_From_Source (Orig_N) then
13930 pragma Assert (Nkind (Orig_N) in N_Subexpr);
13932 case Nkind (Orig_N) is
13933 when N_Character_Literal |
13934 N_Integer_Literal |
13936 N_String_Literal =>
13939 when N_Identifier |
13941 if Is_Entity_Name (Orig_N)
13942 and then Present (Entity (Orig_N)) -- needed in some cases
13944 case Ekind (Entity (Orig_N)) is
13946 E_Enumeration_Literal |
13951 if Is_Type (Entity (Orig_N)) then
13959 when N_Qualified_Expression |
13960 N_Type_Conversion =>
13961 Is_Ok := Is_SPARK_05_Initialization_Expr (Expression (Orig_N));
13964 Is_Ok := Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
13968 N_Membership_Test =>
13969 Is_Ok := Is_SPARK_05_Initialization_Expr (Left_Opnd (Orig_N))
13971 Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
13974 N_Extension_Aggregate =>
13975 if Nkind (Orig_N) = N_Extension_Aggregate then
13977 Is_SPARK_05_Initialization_Expr (Ancestor_Part (Orig_N));
13980 Expr := First (Expressions (Orig_N));
13981 while Present (Expr) loop
13982 if not Is_SPARK_05_Initialization_Expr (Expr) then
13990 Comp_Assn := First (Component_Associations (Orig_N));
13991 while Present (Comp_Assn) loop
13992 Expr := Expression (Comp_Assn);
13994 -- Note: test for Present here needed for box assocation
13997 and then not Is_SPARK_05_Initialization_Expr (Expr)
14006 when N_Attribute_Reference =>
14007 if Nkind (Prefix (Orig_N)) in N_Subexpr then
14008 Is_Ok := Is_SPARK_05_Initialization_Expr (Prefix (Orig_N));
14011 Expr := First (Expressions (Orig_N));
14012 while Present (Expr) loop
14013 if not Is_SPARK_05_Initialization_Expr (Expr) then
14021 -- Selected components might be expanded named not yet resolved, so
14022 -- default on the safe side. (Eg on sparklex.ads)
14024 when N_Selected_Component =>
14033 end Is_SPARK_05_Initialization_Expr;
14035 ----------------------------------
14036 -- Is_SPARK_05_Object_Reference --
14037 ----------------------------------
14039 function Is_SPARK_05_Object_Reference (N : Node_Id) return Boolean is
14041 if Is_Entity_Name (N) then
14042 return Present (Entity (N))
14044 (Ekind_In (Entity (N), E_Constant, E_Variable)
14045 or else Ekind (Entity (N)) in Formal_Kind);
14049 when N_Selected_Component =>
14050 return Is_SPARK_05_Object_Reference (Prefix (N));
14056 end Is_SPARK_05_Object_Reference;
14058 -----------------------------
14059 -- Is_Specific_Tagged_Type --
14060 -----------------------------
14062 function Is_Specific_Tagged_Type (Typ : Entity_Id) return Boolean is
14063 Full_Typ : Entity_Id;
14066 -- Handle private types
14068 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
14069 Full_Typ := Full_View (Typ);
14074 -- A specific tagged type is a non-class-wide tagged type
14076 return Is_Tagged_Type (Full_Typ) and not Is_Class_Wide_Type (Full_Typ);
14077 end Is_Specific_Tagged_Type;
14083 function Is_Statement (N : Node_Id) return Boolean is
14086 Nkind (N) in N_Statement_Other_Than_Procedure_Call
14087 or else Nkind (N) = N_Procedure_Call_Statement;
14090 ---------------------------------------
14091 -- Is_Subprogram_Contract_Annotation --
14092 ---------------------------------------
14094 function Is_Subprogram_Contract_Annotation
14095 (Item : Node_Id) return Boolean
14100 if Nkind (Item) = N_Aspect_Specification then
14101 Nam := Chars (Identifier (Item));
14103 else pragma Assert (Nkind (Item) = N_Pragma);
14104 Nam := Pragma_Name (Item);
14107 return Nam = Name_Contract_Cases
14108 or else Nam = Name_Depends
14109 or else Nam = Name_Extensions_Visible
14110 or else Nam = Name_Global
14111 or else Nam = Name_Post
14112 or else Nam = Name_Post_Class
14113 or else Nam = Name_Postcondition
14114 or else Nam = Name_Pre
14115 or else Nam = Name_Pre_Class
14116 or else Nam = Name_Precondition
14117 or else Nam = Name_Refined_Depends
14118 or else Nam = Name_Refined_Global
14119 or else Nam = Name_Refined_Post
14120 or else Nam = Name_Test_Case;
14121 end Is_Subprogram_Contract_Annotation;
14123 --------------------------------------------------
14124 -- Is_Subprogram_Stub_Without_Prior_Declaration --
14125 --------------------------------------------------
14127 function Is_Subprogram_Stub_Without_Prior_Declaration
14128 (N : Node_Id) return Boolean
14131 -- A subprogram stub without prior declaration serves as declaration for
14132 -- the actual subprogram body. As such, it has an attached defining
14133 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
14135 return Nkind (N) = N_Subprogram_Body_Stub
14136 and then Ekind (Defining_Entity (N)) /= E_Subprogram_Body;
14137 end Is_Subprogram_Stub_Without_Prior_Declaration;
14139 --------------------------
14140 -- Is_Suspension_Object --
14141 --------------------------
14143 function Is_Suspension_Object (Id : Entity_Id) return Boolean is
14145 -- This approach does an exact name match rather than to rely on
14146 -- RTSfind. Routine Is_Effectively_Volatile is used by clients of the
14147 -- front end at point where all auxiliary tables are locked and any
14148 -- modifications to them are treated as violations. Do not tamper with
14149 -- the tables, instead examine the Chars fields of all the scopes of Id.
14152 Chars (Id) = Name_Suspension_Object
14153 and then Present (Scope (Id))
14154 and then Chars (Scope (Id)) = Name_Synchronous_Task_Control
14155 and then Present (Scope (Scope (Id)))
14156 and then Chars (Scope (Scope (Id))) = Name_Ada
14157 and then Present (Scope (Scope (Scope (Id))))
14158 and then Scope (Scope (Scope (Id))) = Standard_Standard;
14159 end Is_Suspension_Object;
14161 ----------------------------
14162 -- Is_Synchronized_Object --
14163 ----------------------------
14165 function Is_Synchronized_Object (Id : Entity_Id) return Boolean is
14169 if Is_Object (Id) then
14171 -- The object is synchronized if it is of a type that yields a
14172 -- synchronized object.
14174 if Yields_Synchronized_Object (Etype (Id)) then
14177 -- The object is synchronized if it is atomic and Async_Writers is
14180 elsif Is_Atomic (Id) and then Async_Writers_Enabled (Id) then
14183 -- A constant is a synchronized object by default
14185 elsif Ekind (Id) = E_Constant then
14188 -- A variable is a synchronized object if it is subject to pragma
14189 -- Constant_After_Elaboration.
14191 elsif Ekind (Id) = E_Variable then
14192 Prag := Get_Pragma (Id, Pragma_Constant_After_Elaboration);
14194 return Present (Prag) and then Is_Enabled_Pragma (Prag);
14198 -- Otherwise the input is not an object or it does not qualify as a
14199 -- synchronized object.
14202 end Is_Synchronized_Object;
14204 ---------------------------------
14205 -- Is_Synchronized_Tagged_Type --
14206 ---------------------------------
14208 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
14209 Kind : constant Entity_Kind := Ekind (Base_Type (E));
14212 -- A task or protected type derived from an interface is a tagged type.
14213 -- Such a tagged type is called a synchronized tagged type, as are
14214 -- synchronized interfaces and private extensions whose declaration
14215 -- includes the reserved word synchronized.
14217 return (Is_Tagged_Type (E)
14218 and then (Kind = E_Task_Type
14220 Kind = E_Protected_Type))
14223 and then Is_Synchronized_Interface (E))
14225 (Ekind (E) = E_Record_Type_With_Private
14226 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
14227 and then (Synchronized_Present (Parent (E))
14228 or else Is_Synchronized_Interface (Etype (E))));
14229 end Is_Synchronized_Tagged_Type;
14235 function Is_Transfer (N : Node_Id) return Boolean is
14236 Kind : constant Node_Kind := Nkind (N);
14239 if Kind = N_Simple_Return_Statement
14241 Kind = N_Extended_Return_Statement
14243 Kind = N_Goto_Statement
14245 Kind = N_Raise_Statement
14247 Kind = N_Requeue_Statement
14251 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
14252 and then No (Condition (N))
14256 elsif Kind = N_Procedure_Call_Statement
14257 and then Is_Entity_Name (Name (N))
14258 and then Present (Entity (Name (N)))
14259 and then No_Return (Entity (Name (N)))
14263 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
14275 function Is_True (U : Uint) return Boolean is
14280 --------------------------------------
14281 -- Is_Unchecked_Conversion_Instance --
14282 --------------------------------------
14284 function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is
14286 Gen_Par : Entity_Id;
14289 -- Look for a function whose generic parent is the predefined intrinsic
14290 -- function Unchecked_Conversion.
14292 if Ekind (Id) = E_Function then
14293 Par := Parent (Id);
14295 if Nkind (Par) /= N_Function_Specification then
14299 Gen_Par := Generic_Parent (Par);
14303 and then Chars (Gen_Par) = Name_Unchecked_Conversion
14304 and then Is_Intrinsic_Subprogram (Gen_Par)
14305 and then Is_Predefined_File_Name
14306 (Unit_File_Name (Get_Source_Unit (Gen_Par)));
14310 end Is_Unchecked_Conversion_Instance;
14312 -------------------------------
14313 -- Is_Universal_Numeric_Type --
14314 -------------------------------
14316 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
14318 return T = Universal_Integer or else T = Universal_Real;
14319 end Is_Universal_Numeric_Type;
14321 ----------------------------
14322 -- Is_Variable_Size_Array --
14323 ----------------------------
14325 function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
14329 pragma Assert (Is_Array_Type (E));
14331 -- Check if some index is initialized with a non-constant value
14333 Idx := First_Index (E);
14334 while Present (Idx) loop
14335 if Nkind (Idx) = N_Range then
14336 if not Is_Constant_Bound (Low_Bound (Idx))
14337 or else not Is_Constant_Bound (High_Bound (Idx))
14343 Idx := Next_Index (Idx);
14347 end Is_Variable_Size_Array;
14349 -----------------------------
14350 -- Is_Variable_Size_Record --
14351 -----------------------------
14353 function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
14355 Comp_Typ : Entity_Id;
14358 pragma Assert (Is_Record_Type (E));
14360 Comp := First_Entity (E);
14361 while Present (Comp) loop
14362 Comp_Typ := Etype (Comp);
14364 -- Recursive call if the record type has discriminants
14366 if Is_Record_Type (Comp_Typ)
14367 and then Has_Discriminants (Comp_Typ)
14368 and then Is_Variable_Size_Record (Comp_Typ)
14372 elsif Is_Array_Type (Comp_Typ)
14373 and then Is_Variable_Size_Array (Comp_Typ)
14378 Next_Entity (Comp);
14382 end Is_Variable_Size_Record;
14388 function Is_Variable
14390 Use_Original_Node : Boolean := True) return Boolean
14392 Orig_Node : Node_Id;
14394 function In_Protected_Function (E : Entity_Id) return Boolean;
14395 -- Within a protected function, the private components of the enclosing
14396 -- protected type are constants. A function nested within a (protected)
14397 -- procedure is not itself protected. Within the body of a protected
14398 -- function the current instance of the protected type is a constant.
14400 function Is_Variable_Prefix (P : Node_Id) return Boolean;
14401 -- Prefixes can involve implicit dereferences, in which case we must
14402 -- test for the case of a reference of a constant access type, which can
14403 -- can never be a variable.
14405 ---------------------------
14406 -- In_Protected_Function --
14407 ---------------------------
14409 function In_Protected_Function (E : Entity_Id) return Boolean is
14414 -- E is the current instance of a type
14416 if Is_Type (E) then
14425 if not Is_Protected_Type (Prot) then
14429 S := Current_Scope;
14430 while Present (S) and then S /= Prot loop
14431 if Ekind (S) = E_Function and then Scope (S) = Prot then
14440 end In_Protected_Function;
14442 ------------------------
14443 -- Is_Variable_Prefix --
14444 ------------------------
14446 function Is_Variable_Prefix (P : Node_Id) return Boolean is
14448 if Is_Access_Type (Etype (P)) then
14449 return not Is_Access_Constant (Root_Type (Etype (P)));
14451 -- For the case of an indexed component whose prefix has a packed
14452 -- array type, the prefix has been rewritten into a type conversion.
14453 -- Determine variable-ness from the converted expression.
14455 elsif Nkind (P) = N_Type_Conversion
14456 and then not Comes_From_Source (P)
14457 and then Is_Array_Type (Etype (P))
14458 and then Is_Packed (Etype (P))
14460 return Is_Variable (Expression (P));
14463 return Is_Variable (P);
14465 end Is_Variable_Prefix;
14467 -- Start of processing for Is_Variable
14470 -- Special check, allow x'Deref(expr) as a variable
14472 if Nkind (N) = N_Attribute_Reference
14473 and then Attribute_Name (N) = Name_Deref
14478 -- Check if we perform the test on the original node since this may be a
14479 -- test of syntactic categories which must not be disturbed by whatever
14480 -- rewriting might have occurred. For example, an aggregate, which is
14481 -- certainly NOT a variable, could be turned into a variable by
14484 if Use_Original_Node then
14485 Orig_Node := Original_Node (N);
14490 -- Definitely OK if Assignment_OK is set. Since this is something that
14491 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
14493 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
14496 -- Normally we go to the original node, but there is one exception where
14497 -- we use the rewritten node, namely when it is an explicit dereference.
14498 -- The generated code may rewrite a prefix which is an access type with
14499 -- an explicit dereference. The dereference is a variable, even though
14500 -- the original node may not be (since it could be a constant of the
14503 -- In Ada 2005 we have a further case to consider: the prefix may be a
14504 -- function call given in prefix notation. The original node appears to
14505 -- be a selected component, but we need to examine the call.
14507 elsif Nkind (N) = N_Explicit_Dereference
14508 and then Nkind (Orig_Node) /= N_Explicit_Dereference
14509 and then Present (Etype (Orig_Node))
14510 and then Is_Access_Type (Etype (Orig_Node))
14512 -- Note that if the prefix is an explicit dereference that does not
14513 -- come from source, we must check for a rewritten function call in
14514 -- prefixed notation before other forms of rewriting, to prevent a
14518 (Nkind (Orig_Node) = N_Function_Call
14519 and then not Is_Access_Constant (Etype (Prefix (N))))
14521 Is_Variable_Prefix (Original_Node (Prefix (N)));
14523 -- in Ada 2012, the dereference may have been added for a type with
14524 -- a declared implicit dereference aspect. Check that it is not an
14525 -- access to constant.
14527 elsif Nkind (N) = N_Explicit_Dereference
14528 and then Present (Etype (Orig_Node))
14529 and then Ada_Version >= Ada_2012
14530 and then Has_Implicit_Dereference (Etype (Orig_Node))
14532 return not Is_Access_Constant (Etype (Prefix (N)));
14534 -- A function call is never a variable
14536 elsif Nkind (N) = N_Function_Call then
14539 -- All remaining checks use the original node
14541 elsif Is_Entity_Name (Orig_Node)
14542 and then Present (Entity (Orig_Node))
14545 E : constant Entity_Id := Entity (Orig_Node);
14546 K : constant Entity_Kind := Ekind (E);
14549 return (K = E_Variable
14550 and then Nkind (Parent (E)) /= N_Exception_Handler)
14551 or else (K = E_Component
14552 and then not In_Protected_Function (E))
14553 or else K = E_Out_Parameter
14554 or else K = E_In_Out_Parameter
14555 or else K = E_Generic_In_Out_Parameter
14557 -- Current instance of type. If this is a protected type, check
14558 -- we are not within the body of one of its protected functions.
14560 or else (Is_Type (E)
14561 and then In_Open_Scopes (E)
14562 and then not In_Protected_Function (E))
14564 or else (Is_Incomplete_Or_Private_Type (E)
14565 and then In_Open_Scopes (Full_View (E)));
14569 case Nkind (Orig_Node) is
14570 when N_Indexed_Component | N_Slice =>
14571 return Is_Variable_Prefix (Prefix (Orig_Node));
14573 when N_Selected_Component =>
14574 return (Is_Variable (Selector_Name (Orig_Node))
14575 and then Is_Variable_Prefix (Prefix (Orig_Node)))
14577 (Nkind (N) = N_Expanded_Name
14578 and then Scope (Entity (N)) = Entity (Prefix (N)));
14580 -- For an explicit dereference, the type of the prefix cannot
14581 -- be an access to constant or an access to subprogram.
14583 when N_Explicit_Dereference =>
14585 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
14587 return Is_Access_Type (Typ)
14588 and then not Is_Access_Constant (Root_Type (Typ))
14589 and then Ekind (Typ) /= E_Access_Subprogram_Type;
14592 -- The type conversion is the case where we do not deal with the
14593 -- context dependent special case of an actual parameter. Thus
14594 -- the type conversion is only considered a variable for the
14595 -- purposes of this routine if the target type is tagged. However,
14596 -- a type conversion is considered to be a variable if it does not
14597 -- come from source (this deals for example with the conversions
14598 -- of expressions to their actual subtypes).
14600 when N_Type_Conversion =>
14601 return Is_Variable (Expression (Orig_Node))
14603 (not Comes_From_Source (Orig_Node)
14605 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
14607 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
14609 -- GNAT allows an unchecked type conversion as a variable. This
14610 -- only affects the generation of internal expanded code, since
14611 -- calls to instantiations of Unchecked_Conversion are never
14612 -- considered variables (since they are function calls).
14614 when N_Unchecked_Type_Conversion =>
14615 return Is_Variable (Expression (Orig_Node));
14623 ---------------------------
14624 -- Is_Visibly_Controlled --
14625 ---------------------------
14627 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
14628 Root : constant Entity_Id := Root_Type (T);
14630 return Chars (Scope (Root)) = Name_Finalization
14631 and then Chars (Scope (Scope (Root))) = Name_Ada
14632 and then Scope (Scope (Scope (Root))) = Standard_Standard;
14633 end Is_Visibly_Controlled;
14635 --------------------------
14636 -- Is_Volatile_Function --
14637 --------------------------
14639 function Is_Volatile_Function (Func_Id : Entity_Id) return Boolean is
14641 -- The caller must ensure that Func_Id denotes a function
14643 pragma Assert (Ekind_In (Func_Id, E_Function, E_Generic_Function));
14645 -- A protected function is automatically volatile
14647 if Is_Primitive (Func_Id)
14648 and then Present (First_Formal (Func_Id))
14649 and then Is_Protected_Type (Etype (First_Formal (Func_Id)))
14650 and then Etype (First_Formal (Func_Id)) = Scope (Func_Id)
14654 -- An instance of Ada.Unchecked_Conversion is a volatile function if
14655 -- either the source or the target are effectively volatile.
14657 elsif Is_Unchecked_Conversion_Instance (Func_Id)
14658 and then Has_Effectively_Volatile_Profile (Func_Id)
14662 -- Otherwise the function is treated as volatile if it is subject to
14663 -- enabled pragma Volatile_Function.
14667 Is_Enabled_Pragma (Get_Pragma (Func_Id, Pragma_Volatile_Function));
14669 end Is_Volatile_Function;
14671 ------------------------
14672 -- Is_Volatile_Object --
14673 ------------------------
14675 function Is_Volatile_Object (N : Node_Id) return Boolean is
14677 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
14678 -- If prefix is an implicit dereference, examine designated type
14680 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
14681 -- Determines if given object has volatile components
14683 ------------------------
14684 -- Is_Volatile_Prefix --
14685 ------------------------
14687 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
14688 Typ : constant Entity_Id := Etype (N);
14691 if Is_Access_Type (Typ) then
14693 Dtyp : constant Entity_Id := Designated_Type (Typ);
14696 return Is_Volatile (Dtyp)
14697 or else Has_Volatile_Components (Dtyp);
14701 return Object_Has_Volatile_Components (N);
14703 end Is_Volatile_Prefix;
14705 ------------------------------------
14706 -- Object_Has_Volatile_Components --
14707 ------------------------------------
14709 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
14710 Typ : constant Entity_Id := Etype (N);
14713 if Is_Volatile (Typ)
14714 or else Has_Volatile_Components (Typ)
14718 elsif Is_Entity_Name (N)
14719 and then (Has_Volatile_Components (Entity (N))
14720 or else Is_Volatile (Entity (N)))
14724 elsif Nkind (N) = N_Indexed_Component
14725 or else Nkind (N) = N_Selected_Component
14727 return Is_Volatile_Prefix (Prefix (N));
14732 end Object_Has_Volatile_Components;
14734 -- Start of processing for Is_Volatile_Object
14737 if Nkind (N) = N_Defining_Identifier then
14738 return Is_Volatile (N) or else Is_Volatile (Etype (N));
14740 elsif Nkind (N) = N_Expanded_Name then
14741 return Is_Volatile_Object (Entity (N));
14743 elsif Is_Volatile (Etype (N))
14744 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
14748 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component)
14749 and then Is_Volatile_Prefix (Prefix (N))
14753 elsif Nkind (N) = N_Selected_Component
14754 and then Is_Volatile (Entity (Selector_Name (N)))
14761 end Is_Volatile_Object;
14763 ---------------------------
14764 -- Itype_Has_Declaration --
14765 ---------------------------
14767 function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
14769 pragma Assert (Is_Itype (Id));
14770 return Present (Parent (Id))
14771 and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
14772 N_Subtype_Declaration)
14773 and then Defining_Entity (Parent (Id)) = Id;
14774 end Itype_Has_Declaration;
14776 -------------------------
14777 -- Kill_Current_Values --
14778 -------------------------
14780 procedure Kill_Current_Values
14782 Last_Assignment_Only : Boolean := False)
14785 if Is_Assignable (Ent) then
14786 Set_Last_Assignment (Ent, Empty);
14789 if Is_Object (Ent) then
14790 if not Last_Assignment_Only then
14792 Set_Current_Value (Ent, Empty);
14794 -- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
14795 -- for a constant. Once the constant is elaborated, its value is
14796 -- not changed, therefore the associated flags that describe the
14797 -- value should not be modified either.
14799 if Ekind (Ent) = E_Constant then
14802 -- Non-constant entities
14805 if not Can_Never_Be_Null (Ent) then
14806 Set_Is_Known_Non_Null (Ent, False);
14809 Set_Is_Known_Null (Ent, False);
14811 -- Reset the Is_Known_Valid flag unless the type is always
14812 -- valid. This does not apply to a loop parameter because its
14813 -- bounds are defined by the loop header and therefore always
14816 if not Is_Known_Valid (Etype (Ent))
14817 and then Ekind (Ent) /= E_Loop_Parameter
14819 Set_Is_Known_Valid (Ent, False);
14824 end Kill_Current_Values;
14826 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
14829 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
14830 -- Clear current value for entity E and all entities chained to E
14832 ------------------------------------------
14833 -- Kill_Current_Values_For_Entity_Chain --
14834 ------------------------------------------
14836 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
14840 while Present (Ent) loop
14841 Kill_Current_Values (Ent, Last_Assignment_Only);
14844 end Kill_Current_Values_For_Entity_Chain;
14846 -- Start of processing for Kill_Current_Values
14849 -- Kill all saved checks, a special case of killing saved values
14851 if not Last_Assignment_Only then
14855 -- Loop through relevant scopes, which includes the current scope and
14856 -- any parent scopes if the current scope is a block or a package.
14858 S := Current_Scope;
14861 -- Clear current values of all entities in current scope
14863 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
14865 -- If scope is a package, also clear current values of all private
14866 -- entities in the scope.
14868 if Is_Package_Or_Generic_Package (S)
14869 or else Is_Concurrent_Type (S)
14871 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
14874 -- If this is a not a subprogram, deal with parents
14876 if not Is_Subprogram (S) then
14878 exit Scope_Loop when S = Standard_Standard;
14882 end loop Scope_Loop;
14883 end Kill_Current_Values;
14885 --------------------------
14886 -- Kill_Size_Check_Code --
14887 --------------------------
14889 procedure Kill_Size_Check_Code (E : Entity_Id) is
14891 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
14892 and then Present (Size_Check_Code (E))
14894 Remove (Size_Check_Code (E));
14895 Set_Size_Check_Code (E, Empty);
14897 end Kill_Size_Check_Code;
14899 --------------------------
14900 -- Known_To_Be_Assigned --
14901 --------------------------
14903 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
14904 P : constant Node_Id := Parent (N);
14909 -- Test left side of assignment
14911 when N_Assignment_Statement =>
14912 return N = Name (P);
14914 -- Function call arguments are never lvalues
14916 when N_Function_Call =>
14919 -- Positional parameter for procedure or accept call
14921 when N_Procedure_Call_Statement |
14930 Proc := Get_Subprogram_Entity (P);
14936 -- If we are not a list member, something is strange, so
14937 -- be conservative and return False.
14939 if not Is_List_Member (N) then
14943 -- We are going to find the right formal by stepping forward
14944 -- through the formals, as we step backwards in the actuals.
14946 Form := First_Formal (Proc);
14949 -- If no formal, something is weird, so be conservative
14950 -- and return False.
14957 exit when No (Act);
14958 Next_Formal (Form);
14961 return Ekind (Form) /= E_In_Parameter;
14964 -- Named parameter for procedure or accept call
14966 when N_Parameter_Association =>
14972 Proc := Get_Subprogram_Entity (Parent (P));
14978 -- Loop through formals to find the one that matches
14980 Form := First_Formal (Proc);
14982 -- If no matching formal, that's peculiar, some kind of
14983 -- previous error, so return False to be conservative.
14984 -- Actually this also happens in legal code in the case
14985 -- where P is a parameter association for an Extra_Formal???
14991 -- Else test for match
14993 if Chars (Form) = Chars (Selector_Name (P)) then
14994 return Ekind (Form) /= E_In_Parameter;
14997 Next_Formal (Form);
15001 -- Test for appearing in a conversion that itself appears
15002 -- in an lvalue context, since this should be an lvalue.
15004 when N_Type_Conversion =>
15005 return Known_To_Be_Assigned (P);
15007 -- All other references are definitely not known to be modifications
15013 end Known_To_Be_Assigned;
15015 ---------------------------
15016 -- Last_Source_Statement --
15017 ---------------------------
15019 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
15023 N := Last (Statements (HSS));
15024 while Present (N) loop
15025 exit when Comes_From_Source (N);
15030 end Last_Source_Statement;
15032 ----------------------------------
15033 -- Matching_Static_Array_Bounds --
15034 ----------------------------------
15036 function Matching_Static_Array_Bounds
15038 R_Typ : Node_Id) return Boolean
15040 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
15041 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
15053 if L_Ndims /= R_Ndims then
15057 -- Unconstrained types do not have static bounds
15059 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
15063 -- First treat specially the first dimension, as the lower bound and
15064 -- length of string literals are not stored like those of arrays.
15066 if Ekind (L_Typ) = E_String_Literal_Subtype then
15067 L_Low := String_Literal_Low_Bound (L_Typ);
15068 L_Len := String_Literal_Length (L_Typ);
15070 L_Index := First_Index (L_Typ);
15071 Get_Index_Bounds (L_Index, L_Low, L_High);
15073 if Is_OK_Static_Expression (L_Low)
15075 Is_OK_Static_Expression (L_High)
15077 if Expr_Value (L_High) < Expr_Value (L_Low) then
15080 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
15087 if Ekind (R_Typ) = E_String_Literal_Subtype then
15088 R_Low := String_Literal_Low_Bound (R_Typ);
15089 R_Len := String_Literal_Length (R_Typ);
15091 R_Index := First_Index (R_Typ);
15092 Get_Index_Bounds (R_Index, R_Low, R_High);
15094 if Is_OK_Static_Expression (R_Low)
15096 Is_OK_Static_Expression (R_High)
15098 if Expr_Value (R_High) < Expr_Value (R_Low) then
15101 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
15108 if (Is_OK_Static_Expression (L_Low)
15110 Is_OK_Static_Expression (R_Low))
15111 and then Expr_Value (L_Low) = Expr_Value (R_Low)
15112 and then L_Len = R_Len
15119 -- Then treat all other dimensions
15121 for Indx in 2 .. L_Ndims loop
15125 Get_Index_Bounds (L_Index, L_Low, L_High);
15126 Get_Index_Bounds (R_Index, R_Low, R_High);
15128 if (Is_OK_Static_Expression (L_Low) and then
15129 Is_OK_Static_Expression (L_High) and then
15130 Is_OK_Static_Expression (R_Low) and then
15131 Is_OK_Static_Expression (R_High))
15132 and then (Expr_Value (L_Low) = Expr_Value (R_Low)
15134 Expr_Value (L_High) = Expr_Value (R_High))
15142 -- If we fall through the loop, all indexes matched
15145 end Matching_Static_Array_Bounds;
15147 -------------------
15148 -- May_Be_Lvalue --
15149 -------------------
15151 function May_Be_Lvalue (N : Node_Id) return Boolean is
15152 P : constant Node_Id := Parent (N);
15157 -- Test left side of assignment
15159 when N_Assignment_Statement =>
15160 return N = Name (P);
15162 -- Test prefix of component or attribute. Note that the prefix of an
15163 -- explicit or implicit dereference cannot be an l-value.
15165 when N_Attribute_Reference =>
15166 return N = Prefix (P)
15167 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
15169 -- For an expanded name, the name is an lvalue if the expanded name
15170 -- is an lvalue, but the prefix is never an lvalue, since it is just
15171 -- the scope where the name is found.
15173 when N_Expanded_Name =>
15174 if N = Prefix (P) then
15175 return May_Be_Lvalue (P);
15180 -- For a selected component A.B, A is certainly an lvalue if A.B is.
15181 -- B is a little interesting, if we have A.B := 3, there is some
15182 -- discussion as to whether B is an lvalue or not, we choose to say
15183 -- it is. Note however that A is not an lvalue if it is of an access
15184 -- type since this is an implicit dereference.
15186 when N_Selected_Component =>
15188 and then Present (Etype (N))
15189 and then Is_Access_Type (Etype (N))
15193 return May_Be_Lvalue (P);
15196 -- For an indexed component or slice, the index or slice bounds is
15197 -- never an lvalue. The prefix is an lvalue if the indexed component
15198 -- or slice is an lvalue, except if it is an access type, where we
15199 -- have an implicit dereference.
15201 when N_Indexed_Component | N_Slice =>
15203 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
15207 return May_Be_Lvalue (P);
15210 -- Prefix of a reference is an lvalue if the reference is an lvalue
15212 when N_Reference =>
15213 return May_Be_Lvalue (P);
15215 -- Prefix of explicit dereference is never an lvalue
15217 when N_Explicit_Dereference =>
15220 -- Positional parameter for subprogram, entry, or accept call.
15221 -- In older versions of Ada function call arguments are never
15222 -- lvalues. In Ada 2012 functions can have in-out parameters.
15224 when N_Subprogram_Call |
15225 N_Entry_Call_Statement |
15228 if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
15232 -- The following mechanism is clumsy and fragile. A single flag
15233 -- set in Resolve_Actuals would be preferable ???
15241 Proc := Get_Subprogram_Entity (P);
15247 -- If we are not a list member, something is strange, so be
15248 -- conservative and return True.
15250 if not Is_List_Member (N) then
15254 -- We are going to find the right formal by stepping forward
15255 -- through the formals, as we step backwards in the actuals.
15257 Form := First_Formal (Proc);
15260 -- If no formal, something is weird, so be conservative and
15268 exit when No (Act);
15269 Next_Formal (Form);
15272 return Ekind (Form) /= E_In_Parameter;
15275 -- Named parameter for procedure or accept call
15277 when N_Parameter_Association =>
15283 Proc := Get_Subprogram_Entity (Parent (P));
15289 -- Loop through formals to find the one that matches
15291 Form := First_Formal (Proc);
15293 -- If no matching formal, that's peculiar, some kind of
15294 -- previous error, so return True to be conservative.
15295 -- Actually happens with legal code for an unresolved call
15296 -- where we may get the wrong homonym???
15302 -- Else test for match
15304 if Chars (Form) = Chars (Selector_Name (P)) then
15305 return Ekind (Form) /= E_In_Parameter;
15308 Next_Formal (Form);
15312 -- Test for appearing in a conversion that itself appears in an
15313 -- lvalue context, since this should be an lvalue.
15315 when N_Type_Conversion =>
15316 return May_Be_Lvalue (P);
15318 -- Test for appearance in object renaming declaration
15320 when N_Object_Renaming_Declaration =>
15323 -- All other references are definitely not lvalues
15331 -----------------------
15332 -- Mark_Coextensions --
15333 -----------------------
15335 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
15336 Is_Dynamic : Boolean;
15337 -- Indicates whether the context causes nested coextensions to be
15338 -- dynamic or static
15340 function Mark_Allocator (N : Node_Id) return Traverse_Result;
15341 -- Recognize an allocator node and label it as a dynamic coextension
15343 --------------------
15344 -- Mark_Allocator --
15345 --------------------
15347 function Mark_Allocator (N : Node_Id) return Traverse_Result is
15349 if Nkind (N) = N_Allocator then
15351 Set_Is_Dynamic_Coextension (N);
15353 -- If the allocator expression is potentially dynamic, it may
15354 -- be expanded out of order and require dynamic allocation
15355 -- anyway, so we treat the coextension itself as dynamic.
15356 -- Potential optimization ???
15358 elsif Nkind (Expression (N)) = N_Qualified_Expression
15359 and then Nkind (Expression (Expression (N))) = N_Op_Concat
15361 Set_Is_Dynamic_Coextension (N);
15363 Set_Is_Static_Coextension (N);
15368 end Mark_Allocator;
15370 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
15372 -- Start of processing for Mark_Coextensions
15375 -- An allocator that appears on the right-hand side of an assignment is
15376 -- treated as a potentially dynamic coextension when the right-hand side
15377 -- is an allocator or a qualified expression.
15379 -- Obj := new ...'(new Coextension ...);
15381 if Nkind (Context_Nod) = N_Assignment_Statement then
15383 Nkind_In (Expression (Context_Nod), N_Allocator,
15384 N_Qualified_Expression);
15386 -- An allocator that appears within the expression of a simple return
15387 -- statement is treated as a potentially dynamic coextension when the
15388 -- expression is either aggregate, allocator, or qualified expression.
15390 -- return (new Coextension ...);
15391 -- return new ...'(new Coextension ...);
15393 elsif Nkind (Context_Nod) = N_Simple_Return_Statement then
15395 Nkind_In (Expression (Context_Nod), N_Aggregate,
15397 N_Qualified_Expression);
15399 -- An alloctor that appears within the initialization expression of an
15400 -- object declaration is considered a potentially dynamic coextension
15401 -- when the initialization expression is an allocator or a qualified
15404 -- Obj : ... := new ...'(new Coextension ...);
15406 -- A similar case arises when the object declaration is part of an
15407 -- extended return statement.
15409 -- return Obj : ... := new ...'(new Coextension ...);
15410 -- return Obj : ... := (new Coextension ...);
15412 elsif Nkind (Context_Nod) = N_Object_Declaration then
15414 Nkind_In (Root_Nod, N_Allocator, N_Qualified_Expression)
15416 Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
15418 -- This routine should not be called with constructs that cannot contain
15422 raise Program_Error;
15425 Mark_Allocators (Root_Nod);
15426 end Mark_Coextensions;
15428 ----------------------
15429 -- Needs_One_Actual --
15430 ----------------------
15432 function Needs_One_Actual (E : Entity_Id) return Boolean is
15433 Formal : Entity_Id;
15436 -- Ada 2005 or later, and formals present
15438 if Ada_Version >= Ada_2005 and then Present (First_Formal (E)) then
15439 Formal := Next_Formal (First_Formal (E));
15440 while Present (Formal) loop
15441 if No (Default_Value (Formal)) then
15445 Next_Formal (Formal);
15450 -- Ada 83/95 or no formals
15455 end Needs_One_Actual;
15457 ------------------------
15458 -- New_Copy_List_Tree --
15459 ------------------------
15461 function New_Copy_List_Tree (List : List_Id) return List_Id is
15466 if List = No_List then
15473 while Present (E) loop
15474 Append (New_Copy_Tree (E), NL);
15480 end New_Copy_List_Tree;
15482 --------------------------------------------------
15483 -- New_Copy_Tree Auxiliary Data and Subprograms --
15484 --------------------------------------------------
15486 use Atree.Unchecked_Access;
15487 use Atree_Private_Part;
15489 -- Our approach here requires a two pass traversal of the tree. The
15490 -- first pass visits all nodes that eventually will be copied looking
15491 -- for defining Itypes. If any defining Itypes are found, then they are
15492 -- copied, and an entry is added to the replacement map. In the second
15493 -- phase, the tree is copied, using the replacement map to replace any
15494 -- Itype references within the copied tree.
15496 -- The following hash tables are used if the Map supplied has more
15497 -- than hash threshold entries to speed up access to the map. If
15498 -- there are fewer entries, then the map is searched sequentially
15499 -- (because setting up a hash table for only a few entries takes
15500 -- more time than it saves.
15502 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
15503 -- Hash function used for hash operations
15505 -------------------
15506 -- New_Copy_Hash --
15507 -------------------
15509 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
15511 return Nat (E) mod (NCT_Header_Num'Last + 1);
15518 -- The hash table NCT_Assoc associates old entities in the table
15519 -- with their corresponding new entities (i.e. the pairs of entries
15520 -- presented in the original Map argument are Key-Element pairs).
15522 package NCT_Assoc is new Simple_HTable (
15523 Header_Num => NCT_Header_Num,
15524 Element => Entity_Id,
15525 No_Element => Empty,
15527 Hash => New_Copy_Hash,
15528 Equal => Types."=");
15530 ---------------------
15531 -- NCT_Itype_Assoc --
15532 ---------------------
15534 -- The hash table NCT_Itype_Assoc contains entries only for those
15535 -- old nodes which have a non-empty Associated_Node_For_Itype set.
15536 -- The key is the associated node, and the element is the new node
15537 -- itself (NOT the associated node for the new node).
15539 package NCT_Itype_Assoc is new Simple_HTable (
15540 Header_Num => NCT_Header_Num,
15541 Element => Entity_Id,
15542 No_Element => Empty,
15544 Hash => New_Copy_Hash,
15545 Equal => Types."=");
15547 -------------------
15548 -- New_Copy_Tree --
15549 -------------------
15551 function New_Copy_Tree
15553 Map : Elist_Id := No_Elist;
15554 New_Sloc : Source_Ptr := No_Location;
15555 New_Scope : Entity_Id := Empty) return Node_Id
15557 Actual_Map : Elist_Id := Map;
15558 -- This is the actual map for the copy. It is initialized with the
15559 -- given elements, and then enlarged as required for Itypes that are
15560 -- copied during the first phase of the copy operation. The visit
15561 -- procedures add elements to this map as Itypes are encountered.
15562 -- The reason we cannot use Map directly, is that it may well be
15563 -- (and normally is) initialized to No_Elist, and if we have mapped
15564 -- entities, we have to reset it to point to a real Elist.
15566 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
15567 -- Called during second phase to map entities into their corresponding
15568 -- copies using Actual_Map. If the argument is not an entity, or is not
15569 -- in Actual_Map, then it is returned unchanged.
15571 procedure Build_NCT_Hash_Tables;
15572 -- Builds hash tables (number of elements >= threshold value)
15574 function Copy_Elist_With_Replacement
15575 (Old_Elist : Elist_Id) return Elist_Id;
15576 -- Called during second phase to copy element list doing replacements
15578 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
15579 -- Called during the second phase to process a copied Itype. The actual
15580 -- copy happened during the first phase (so that we could make the entry
15581 -- in the mapping), but we still have to deal with the descendants of
15582 -- the copied Itype and copy them where necessary.
15584 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
15585 -- Called during second phase to copy list doing replacements
15587 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
15588 -- Called during second phase to copy node doing replacements
15590 procedure Visit_Elist (E : Elist_Id);
15591 -- Called during first phase to visit all elements of an Elist
15593 procedure Visit_Field (F : Union_Id; N : Node_Id);
15594 -- Visit a single field, recursing to call Visit_Node or Visit_List
15595 -- if the field is a syntactic descendant of the current node (i.e.
15596 -- its parent is Node N).
15598 procedure Visit_Itype (Old_Itype : Entity_Id);
15599 -- Called during first phase to visit subsidiary fields of a defining
15600 -- Itype, and also create a copy and make an entry in the replacement
15601 -- map for the new copy.
15603 procedure Visit_List (L : List_Id);
15604 -- Called during first phase to visit all elements of a List
15606 procedure Visit_Node (N : Node_Or_Entity_Id);
15607 -- Called during first phase to visit a node and all its subtrees
15613 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
15618 if not Has_Extension (N) or else No (Actual_Map) then
15621 elsif NCT_Hash_Tables_Used then
15622 Ent := NCT_Assoc.Get (Entity_Id (N));
15624 if Present (Ent) then
15630 -- No hash table used, do serial search
15633 E := First_Elmt (Actual_Map);
15634 while Present (E) loop
15635 if Node (E) = N then
15636 return Node (Next_Elmt (E));
15638 E := Next_Elmt (Next_Elmt (E));
15646 ---------------------------
15647 -- Build_NCT_Hash_Tables --
15648 ---------------------------
15650 procedure Build_NCT_Hash_Tables is
15654 if NCT_Hash_Table_Setup then
15656 NCT_Itype_Assoc.Reset;
15659 Elmt := First_Elmt (Actual_Map);
15660 while Present (Elmt) loop
15661 Ent := Node (Elmt);
15663 -- Get new entity, and associate old and new
15666 NCT_Assoc.Set (Ent, Node (Elmt));
15668 if Is_Type (Ent) then
15670 Anode : constant Entity_Id :=
15671 Associated_Node_For_Itype (Ent);
15674 if Present (Anode) then
15676 -- Enter a link between the associated node of the
15677 -- old Itype and the new Itype, for updating later
15678 -- when node is copied.
15680 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
15688 NCT_Hash_Tables_Used := True;
15689 NCT_Hash_Table_Setup := True;
15690 end Build_NCT_Hash_Tables;
15692 ---------------------------------
15693 -- Copy_Elist_With_Replacement --
15694 ---------------------------------
15696 function Copy_Elist_With_Replacement
15697 (Old_Elist : Elist_Id) return Elist_Id
15700 New_Elist : Elist_Id;
15703 if No (Old_Elist) then
15707 New_Elist := New_Elmt_List;
15709 M := First_Elmt (Old_Elist);
15710 while Present (M) loop
15711 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
15717 end Copy_Elist_With_Replacement;
15719 ---------------------------------
15720 -- Copy_Itype_With_Replacement --
15721 ---------------------------------
15723 -- This routine exactly parallels its phase one analog Visit_Itype,
15725 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
15727 -- Translate Next_Entity, Scope and Etype fields, in case they
15728 -- reference entities that have been mapped into copies.
15730 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
15731 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
15733 if Present (New_Scope) then
15734 Set_Scope (New_Itype, New_Scope);
15736 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
15739 -- Copy referenced fields
15741 if Is_Discrete_Type (New_Itype) then
15742 Set_Scalar_Range (New_Itype,
15743 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
15745 elsif Has_Discriminants (Base_Type (New_Itype)) then
15746 Set_Discriminant_Constraint (New_Itype,
15747 Copy_Elist_With_Replacement
15748 (Discriminant_Constraint (New_Itype)));
15750 elsif Is_Array_Type (New_Itype) then
15751 if Present (First_Index (New_Itype)) then
15752 Set_First_Index (New_Itype,
15753 First (Copy_List_With_Replacement
15754 (List_Containing (First_Index (New_Itype)))));
15757 if Is_Packed (New_Itype) then
15758 Set_Packed_Array_Impl_Type (New_Itype,
15759 Copy_Node_With_Replacement
15760 (Packed_Array_Impl_Type (New_Itype)));
15763 end Copy_Itype_With_Replacement;
15765 --------------------------------
15766 -- Copy_List_With_Replacement --
15767 --------------------------------
15769 function Copy_List_With_Replacement
15770 (Old_List : List_Id) return List_Id
15772 New_List : List_Id;
15776 if Old_List = No_List then
15780 New_List := Empty_List;
15782 E := First (Old_List);
15783 while Present (E) loop
15784 Append (Copy_Node_With_Replacement (E), New_List);
15790 end Copy_List_With_Replacement;
15792 --------------------------------
15793 -- Copy_Node_With_Replacement --
15794 --------------------------------
15796 function Copy_Node_With_Replacement
15797 (Old_Node : Node_Id) return Node_Id
15799 New_Node : Node_Id;
15801 procedure Adjust_Named_Associations
15802 (Old_Node : Node_Id;
15803 New_Node : Node_Id);
15804 -- If a call node has named associations, these are chained through
15805 -- the First_Named_Actual, Next_Named_Actual links. These must be
15806 -- propagated separately to the new parameter list, because these
15807 -- are not syntactic fields.
15809 function Copy_Field_With_Replacement
15810 (Field : Union_Id) return Union_Id;
15811 -- Given Field, which is a field of Old_Node, return a copy of it
15812 -- if it is a syntactic field (i.e. its parent is Node), setting
15813 -- the parent of the copy to poit to New_Node. Otherwise returns
15814 -- the field (possibly mapped if it is an entity).
15816 -------------------------------
15817 -- Adjust_Named_Associations --
15818 -------------------------------
15820 procedure Adjust_Named_Associations
15821 (Old_Node : Node_Id;
15822 New_Node : Node_Id)
15827 Old_Next : Node_Id;
15828 New_Next : Node_Id;
15831 Old_E := First (Parameter_Associations (Old_Node));
15832 New_E := First (Parameter_Associations (New_Node));
15833 while Present (Old_E) loop
15834 if Nkind (Old_E) = N_Parameter_Association
15835 and then Present (Next_Named_Actual (Old_E))
15837 if First_Named_Actual (Old_Node)
15838 = Explicit_Actual_Parameter (Old_E)
15840 Set_First_Named_Actual
15841 (New_Node, Explicit_Actual_Parameter (New_E));
15844 -- Now scan parameter list from the beginning,to locate
15845 -- next named actual, which can be out of order.
15847 Old_Next := First (Parameter_Associations (Old_Node));
15848 New_Next := First (Parameter_Associations (New_Node));
15850 while Nkind (Old_Next) /= N_Parameter_Association
15851 or else Explicit_Actual_Parameter (Old_Next) /=
15852 Next_Named_Actual (Old_E)
15858 Set_Next_Named_Actual
15859 (New_E, Explicit_Actual_Parameter (New_Next));
15865 end Adjust_Named_Associations;
15867 ---------------------------------
15868 -- Copy_Field_With_Replacement --
15869 ---------------------------------
15871 function Copy_Field_With_Replacement
15872 (Field : Union_Id) return Union_Id
15875 if Field = Union_Id (Empty) then
15878 elsif Field in Node_Range then
15880 Old_N : constant Node_Id := Node_Id (Field);
15884 -- If syntactic field, as indicated by the parent pointer
15885 -- being set, then copy the referenced node recursively.
15887 if Parent (Old_N) = Old_Node then
15888 New_N := Copy_Node_With_Replacement (Old_N);
15890 if New_N /= Old_N then
15891 Set_Parent (New_N, New_Node);
15894 -- For semantic fields, update possible entity reference
15895 -- from the replacement map.
15898 New_N := Assoc (Old_N);
15901 return Union_Id (New_N);
15904 elsif Field in List_Range then
15906 Old_L : constant List_Id := List_Id (Field);
15910 -- If syntactic field, as indicated by the parent pointer,
15911 -- then recursively copy the entire referenced list.
15913 if Parent (Old_L) = Old_Node then
15914 New_L := Copy_List_With_Replacement (Old_L);
15915 Set_Parent (New_L, New_Node);
15917 -- For semantic list, just returned unchanged
15923 return Union_Id (New_L);
15926 -- Anything other than a list or a node is returned unchanged
15931 end Copy_Field_With_Replacement;
15933 -- Start of processing for Copy_Node_With_Replacement
15936 if Old_Node <= Empty_Or_Error then
15939 elsif Has_Extension (Old_Node) then
15940 return Assoc (Old_Node);
15943 New_Node := New_Copy (Old_Node);
15945 -- If the node we are copying is the associated node of a
15946 -- previously copied Itype, then adjust the associated node
15947 -- of the copy of that Itype accordingly.
15949 if Present (Actual_Map) then
15955 -- Case of hash table used
15957 if NCT_Hash_Tables_Used then
15958 Ent := NCT_Itype_Assoc.Get (Old_Node);
15960 if Present (Ent) then
15961 Set_Associated_Node_For_Itype (Ent, New_Node);
15964 -- Case of no hash table used
15967 E := First_Elmt (Actual_Map);
15968 while Present (E) loop
15969 if Is_Itype (Node (E))
15971 Old_Node = Associated_Node_For_Itype (Node (E))
15973 Set_Associated_Node_For_Itype
15974 (Node (Next_Elmt (E)), New_Node);
15977 E := Next_Elmt (Next_Elmt (E));
15983 -- Recursively copy descendants
15986 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
15988 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
15990 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
15992 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
15994 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
15996 -- Adjust Sloc of new node if necessary
15998 if New_Sloc /= No_Location then
15999 Set_Sloc (New_Node, New_Sloc);
16001 -- If we adjust the Sloc, then we are essentially making a
16002 -- completely new node, so the Comes_From_Source flag should
16003 -- be reset to the proper default value.
16005 Set_Comes_From_Source
16006 (New_Node, Default_Node.Comes_From_Source);
16009 -- If the node is a call and has named associations, set the
16010 -- corresponding links in the copy.
16012 if Nkind_In (Old_Node, N_Entry_Call_Statement,
16014 N_Procedure_Call_Statement)
16015 and then Present (First_Named_Actual (Old_Node))
16017 Adjust_Named_Associations (Old_Node, New_Node);
16020 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
16021 -- The replacement mechanism applies to entities, and is not used
16022 -- here. Eventually we may need a more general graph-copying
16023 -- routine. For now, do a sequential search to find desired node.
16025 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
16026 and then Present (First_Real_Statement (Old_Node))
16029 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
16033 N1 := First (Statements (Old_Node));
16034 N2 := First (Statements (New_Node));
16036 while N1 /= Old_F loop
16041 Set_First_Real_Statement (New_Node, N2);
16046 -- All done, return copied node
16049 end Copy_Node_With_Replacement;
16055 procedure Visit_Elist (E : Elist_Id) is
16058 if Present (E) then
16059 Elmt := First_Elmt (E);
16061 while Elmt /= No_Elmt loop
16062 Visit_Node (Node (Elmt));
16072 procedure Visit_Field (F : Union_Id; N : Node_Id) is
16074 if F = Union_Id (Empty) then
16077 elsif F in Node_Range then
16079 -- Copy node if it is syntactic, i.e. its parent pointer is
16080 -- set to point to the field that referenced it (certain
16081 -- Itypes will also meet this criterion, which is fine, since
16082 -- these are clearly Itypes that do need to be copied, since
16083 -- we are copying their parent.)
16085 if Parent (Node_Id (F)) = N then
16086 Visit_Node (Node_Id (F));
16089 -- Another case, if we are pointing to an Itype, then we want
16090 -- to copy it if its associated node is somewhere in the tree
16093 -- Note: the exclusion of self-referential copies is just an
16094 -- optimization, since the search of the already copied list
16095 -- would catch it, but it is a common case (Etype pointing
16096 -- to itself for an Itype that is a base type).
16098 elsif Has_Extension (Node_Id (F))
16099 and then Is_Itype (Entity_Id (F))
16100 and then Node_Id (F) /= N
16106 P := Associated_Node_For_Itype (Node_Id (F));
16107 while Present (P) loop
16109 Visit_Node (Node_Id (F));
16116 -- An Itype whose parent is not being copied definitely
16117 -- should NOT be copied, since it does not belong in any
16118 -- sense to the copied subtree.
16124 elsif F in List_Range and then Parent (List_Id (F)) = N then
16125 Visit_List (List_Id (F));
16134 procedure Visit_Itype (Old_Itype : Entity_Id) is
16135 New_Itype : Entity_Id;
16140 -- Itypes that describe the designated type of access to subprograms
16141 -- have the structure of subprogram declarations, with signatures,
16142 -- etc. Either we duplicate the signatures completely, or choose to
16143 -- share such itypes, which is fine because their elaboration will
16144 -- have no side effects.
16146 if Ekind (Old_Itype) = E_Subprogram_Type then
16150 New_Itype := New_Copy (Old_Itype);
16152 -- The new Itype has all the attributes of the old one, and
16153 -- we just copy the contents of the entity. However, the back-end
16154 -- needs different names for debugging purposes, so we create a
16155 -- new internal name for it in all cases.
16157 Set_Chars (New_Itype, New_Internal_Name ('T'));
16159 -- If our associated node is an entity that has already been copied,
16160 -- then set the associated node of the copy to point to the right
16161 -- copy. If we have copied an Itype that is itself the associated
16162 -- node of some previously copied Itype, then we set the right
16163 -- pointer in the other direction.
16165 if Present (Actual_Map) then
16167 -- Case of hash tables used
16169 if NCT_Hash_Tables_Used then
16171 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
16173 if Present (Ent) then
16174 Set_Associated_Node_For_Itype (New_Itype, Ent);
16177 Ent := NCT_Itype_Assoc.Get (Old_Itype);
16178 if Present (Ent) then
16179 Set_Associated_Node_For_Itype (Ent, New_Itype);
16181 -- If the hash table has no association for this Itype and
16182 -- its associated node, enter one now.
16185 NCT_Itype_Assoc.Set
16186 (Associated_Node_For_Itype (Old_Itype), New_Itype);
16189 -- Case of hash tables not used
16192 E := First_Elmt (Actual_Map);
16193 while Present (E) loop
16194 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
16195 Set_Associated_Node_For_Itype
16196 (New_Itype, Node (Next_Elmt (E)));
16199 if Is_Type (Node (E))
16200 and then Old_Itype = Associated_Node_For_Itype (Node (E))
16202 Set_Associated_Node_For_Itype
16203 (Node (Next_Elmt (E)), New_Itype);
16206 E := Next_Elmt (Next_Elmt (E));
16211 if Present (Freeze_Node (New_Itype)) then
16212 Set_Is_Frozen (New_Itype, False);
16213 Set_Freeze_Node (New_Itype, Empty);
16216 -- Add new association to map
16218 if No (Actual_Map) then
16219 Actual_Map := New_Elmt_List;
16222 Append_Elmt (Old_Itype, Actual_Map);
16223 Append_Elmt (New_Itype, Actual_Map);
16225 if NCT_Hash_Tables_Used then
16226 NCT_Assoc.Set (Old_Itype, New_Itype);
16229 NCT_Table_Entries := NCT_Table_Entries + 1;
16231 if NCT_Table_Entries > NCT_Hash_Threshold then
16232 Build_NCT_Hash_Tables;
16236 -- If a record subtype is simply copied, the entity list will be
16237 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
16239 if Ekind_In (Old_Itype, E_Record_Subtype, E_Class_Wide_Subtype) then
16240 Set_Cloned_Subtype (New_Itype, Old_Itype);
16243 -- Visit descendants that eventually get copied
16245 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
16247 if Is_Discrete_Type (Old_Itype) then
16248 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
16250 elsif Has_Discriminants (Base_Type (Old_Itype)) then
16251 -- ??? This should involve call to Visit_Field
16252 Visit_Elist (Discriminant_Constraint (Old_Itype));
16254 elsif Is_Array_Type (Old_Itype) then
16255 if Present (First_Index (Old_Itype)) then
16256 Visit_Field (Union_Id (List_Containing
16257 (First_Index (Old_Itype))),
16261 if Is_Packed (Old_Itype) then
16262 Visit_Field (Union_Id (Packed_Array_Impl_Type (Old_Itype)),
16272 procedure Visit_List (L : List_Id) is
16275 if L /= No_List then
16278 while Present (N) loop
16289 procedure Visit_Node (N : Node_Or_Entity_Id) is
16291 -- Start of processing for Visit_Node
16294 -- Handle case of an Itype, which must be copied
16296 if Has_Extension (N) and then Is_Itype (N) then
16298 -- Nothing to do if already in the list. This can happen with an
16299 -- Itype entity that appears more than once in the tree.
16300 -- Note that we do not want to visit descendants in this case.
16302 -- Test for already in list when hash table is used
16304 if NCT_Hash_Tables_Used then
16305 if Present (NCT_Assoc.Get (Entity_Id (N))) then
16309 -- Test for already in list when hash table not used
16315 if Present (Actual_Map) then
16316 E := First_Elmt (Actual_Map);
16317 while Present (E) loop
16318 if Node (E) = N then
16321 E := Next_Elmt (Next_Elmt (E));
16331 -- Visit descendants
16333 Visit_Field (Field1 (N), N);
16334 Visit_Field (Field2 (N), N);
16335 Visit_Field (Field3 (N), N);
16336 Visit_Field (Field4 (N), N);
16337 Visit_Field (Field5 (N), N);
16340 -- Start of processing for New_Copy_Tree
16345 -- See if we should use hash table
16347 if No (Actual_Map) then
16348 NCT_Hash_Tables_Used := False;
16355 NCT_Table_Entries := 0;
16357 Elmt := First_Elmt (Actual_Map);
16358 while Present (Elmt) loop
16359 NCT_Table_Entries := NCT_Table_Entries + 1;
16364 if NCT_Table_Entries > NCT_Hash_Threshold then
16365 Build_NCT_Hash_Tables;
16367 NCT_Hash_Tables_Used := False;
16372 -- Hash table set up if required, now start phase one by visiting
16373 -- top node (we will recursively visit the descendants).
16375 Visit_Node (Source);
16377 -- Now the second phase of the copy can start. First we process
16378 -- all the mapped entities, copying their descendants.
16380 if Present (Actual_Map) then
16383 New_Itype : Entity_Id;
16385 Elmt := First_Elmt (Actual_Map);
16386 while Present (Elmt) loop
16388 New_Itype := Node (Elmt);
16390 if Is_Itype (New_Itype) then
16391 Copy_Itype_With_Replacement (New_Itype);
16398 -- Now we can copy the actual tree
16400 return Copy_Node_With_Replacement (Source);
16403 -------------------------
16404 -- New_External_Entity --
16405 -------------------------
16407 function New_External_Entity
16408 (Kind : Entity_Kind;
16409 Scope_Id : Entity_Id;
16410 Sloc_Value : Source_Ptr;
16411 Related_Id : Entity_Id;
16412 Suffix : Character;
16413 Suffix_Index : Nat := 0;
16414 Prefix : Character := ' ') return Entity_Id
16416 N : constant Entity_Id :=
16417 Make_Defining_Identifier (Sloc_Value,
16419 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
16422 Set_Ekind (N, Kind);
16423 Set_Is_Internal (N, True);
16424 Append_Entity (N, Scope_Id);
16425 Set_Public_Status (N);
16427 if Kind in Type_Kind then
16428 Init_Size_Align (N);
16432 end New_External_Entity;
16434 -------------------------
16435 -- New_Internal_Entity --
16436 -------------------------
16438 function New_Internal_Entity
16439 (Kind : Entity_Kind;
16440 Scope_Id : Entity_Id;
16441 Sloc_Value : Source_Ptr;
16442 Id_Char : Character) return Entity_Id
16444 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
16447 Set_Ekind (N, Kind);
16448 Set_Is_Internal (N, True);
16449 Append_Entity (N, Scope_Id);
16451 if Kind in Type_Kind then
16452 Init_Size_Align (N);
16456 end New_Internal_Entity;
16462 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
16466 -- If we are pointing at a positional parameter, it is a member of a
16467 -- node list (the list of parameters), and the next parameter is the
16468 -- next node on the list, unless we hit a parameter association, then
16469 -- we shift to using the chain whose head is the First_Named_Actual in
16470 -- the parent, and then is threaded using the Next_Named_Actual of the
16471 -- Parameter_Association. All this fiddling is because the original node
16472 -- list is in the textual call order, and what we need is the
16473 -- declaration order.
16475 if Is_List_Member (Actual_Id) then
16476 N := Next (Actual_Id);
16478 if Nkind (N) = N_Parameter_Association then
16479 return First_Named_Actual (Parent (Actual_Id));
16485 return Next_Named_Actual (Parent (Actual_Id));
16489 procedure Next_Actual (Actual_Id : in out Node_Id) is
16491 Actual_Id := Next_Actual (Actual_Id);
16494 -----------------------
16495 -- Normalize_Actuals --
16496 -----------------------
16498 -- Chain actuals according to formals of subprogram. If there are no named
16499 -- associations, the chain is simply the list of Parameter Associations,
16500 -- since the order is the same as the declaration order. If there are named
16501 -- associations, then the First_Named_Actual field in the N_Function_Call
16502 -- or N_Procedure_Call_Statement node points to the Parameter_Association
16503 -- node for the parameter that comes first in declaration order. The
16504 -- remaining named parameters are then chained in declaration order using
16505 -- Next_Named_Actual.
16507 -- This routine also verifies that the number of actuals is compatible with
16508 -- the number and default values of formals, but performs no type checking
16509 -- (type checking is done by the caller).
16511 -- If the matching succeeds, Success is set to True and the caller proceeds
16512 -- with type-checking. If the match is unsuccessful, then Success is set to
16513 -- False, and the caller attempts a different interpretation, if there is
16516 -- If the flag Report is on, the call is not overloaded, and a failure to
16517 -- match can be reported here, rather than in the caller.
16519 procedure Normalize_Actuals
16523 Success : out Boolean)
16525 Actuals : constant List_Id := Parameter_Associations (N);
16526 Actual : Node_Id := Empty;
16527 Formal : Entity_Id;
16528 Last : Node_Id := Empty;
16529 First_Named : Node_Id := Empty;
16532 Formals_To_Match : Integer := 0;
16533 Actuals_To_Match : Integer := 0;
16535 procedure Chain (A : Node_Id);
16536 -- Add named actual at the proper place in the list, using the
16537 -- Next_Named_Actual link.
16539 function Reporting return Boolean;
16540 -- Determines if an error is to be reported. To report an error, we
16541 -- need Report to be True, and also we do not report errors caused
16542 -- by calls to init procs that occur within other init procs. Such
16543 -- errors must always be cascaded errors, since if all the types are
16544 -- declared correctly, the compiler will certainly build decent calls.
16550 procedure Chain (A : Node_Id) is
16554 -- Call node points to first actual in list
16556 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
16559 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
16563 Set_Next_Named_Actual (Last, Empty);
16570 function Reporting return Boolean is
16575 elsif not Within_Init_Proc then
16578 elsif Is_Init_Proc (Entity (Name (N))) then
16586 -- Start of processing for Normalize_Actuals
16589 if Is_Access_Type (S) then
16591 -- The name in the call is a function call that returns an access
16592 -- to subprogram. The designated type has the list of formals.
16594 Formal := First_Formal (Designated_Type (S));
16596 Formal := First_Formal (S);
16599 while Present (Formal) loop
16600 Formals_To_Match := Formals_To_Match + 1;
16601 Next_Formal (Formal);
16604 -- Find if there is a named association, and verify that no positional
16605 -- associations appear after named ones.
16607 if Present (Actuals) then
16608 Actual := First (Actuals);
16611 while Present (Actual)
16612 and then Nkind (Actual) /= N_Parameter_Association
16614 Actuals_To_Match := Actuals_To_Match + 1;
16618 if No (Actual) and Actuals_To_Match = Formals_To_Match then
16620 -- Most common case: positional notation, no defaults
16625 elsif Actuals_To_Match > Formals_To_Match then
16627 -- Too many actuals: will not work
16630 if Is_Entity_Name (Name (N)) then
16631 Error_Msg_N ("too many arguments in call to&", Name (N));
16633 Error_Msg_N ("too many arguments in call", N);
16641 First_Named := Actual;
16643 while Present (Actual) loop
16644 if Nkind (Actual) /= N_Parameter_Association then
16646 ("positional parameters not allowed after named ones", Actual);
16651 Actuals_To_Match := Actuals_To_Match + 1;
16657 if Present (Actuals) then
16658 Actual := First (Actuals);
16661 Formal := First_Formal (S);
16662 while Present (Formal) loop
16664 -- Match the formals in order. If the corresponding actual is
16665 -- positional, nothing to do. Else scan the list of named actuals
16666 -- to find the one with the right name.
16668 if Present (Actual)
16669 and then Nkind (Actual) /= N_Parameter_Association
16672 Actuals_To_Match := Actuals_To_Match - 1;
16673 Formals_To_Match := Formals_To_Match - 1;
16676 -- For named parameters, search the list of actuals to find
16677 -- one that matches the next formal name.
16679 Actual := First_Named;
16681 while Present (Actual) loop
16682 if Chars (Selector_Name (Actual)) = Chars (Formal) then
16685 Actuals_To_Match := Actuals_To_Match - 1;
16686 Formals_To_Match := Formals_To_Match - 1;
16694 if Ekind (Formal) /= E_In_Parameter
16695 or else No (Default_Value (Formal))
16698 if (Comes_From_Source (S)
16699 or else Sloc (S) = Standard_Location)
16700 and then Is_Overloadable (S)
16704 Nkind_In (Parent (N), N_Procedure_Call_Statement,
16706 N_Parameter_Association)
16707 and then Ekind (S) /= E_Function
16709 Set_Etype (N, Etype (S));
16712 Error_Msg_Name_1 := Chars (S);
16713 Error_Msg_Sloc := Sloc (S);
16715 ("missing argument for parameter & "
16716 & "in call to % declared #", N, Formal);
16719 elsif Is_Overloadable (S) then
16720 Error_Msg_Name_1 := Chars (S);
16722 -- Point to type derivation that generated the
16725 Error_Msg_Sloc := Sloc (Parent (S));
16728 ("missing argument for parameter & "
16729 & "in call to % (inherited) #", N, Formal);
16733 ("missing argument for parameter &", N, Formal);
16741 Formals_To_Match := Formals_To_Match - 1;
16746 Next_Formal (Formal);
16749 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
16756 -- Find some superfluous named actual that did not get
16757 -- attached to the list of associations.
16759 Actual := First (Actuals);
16760 while Present (Actual) loop
16761 if Nkind (Actual) = N_Parameter_Association
16762 and then Actual /= Last
16763 and then No (Next_Named_Actual (Actual))
16765 Error_Msg_N ("unmatched actual & in call",
16766 Selector_Name (Actual));
16777 end Normalize_Actuals;
16779 --------------------------------
16780 -- Note_Possible_Modification --
16781 --------------------------------
16783 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
16784 Modification_Comes_From_Source : constant Boolean :=
16785 Comes_From_Source (Parent (N));
16791 -- Loop to find referenced entity, if there is one
16797 if Is_Entity_Name (Exp) then
16798 Ent := Entity (Exp);
16800 -- If the entity is missing, it is an undeclared identifier,
16801 -- and there is nothing to annotate.
16807 elsif Nkind (Exp) = N_Explicit_Dereference then
16809 P : constant Node_Id := Prefix (Exp);
16812 -- In formal verification mode, keep track of all reads and
16813 -- writes through explicit dereferences.
16815 if GNATprove_Mode then
16816 SPARK_Specific.Generate_Dereference (N, 'm');
16819 if Nkind (P) = N_Selected_Component
16820 and then Present (Entry_Formal (Entity (Selector_Name (P))))
16822 -- Case of a reference to an entry formal
16824 Ent := Entry_Formal (Entity (Selector_Name (P)));
16826 elsif Nkind (P) = N_Identifier
16827 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
16828 and then Present (Expression (Parent (Entity (P))))
16829 and then Nkind (Expression (Parent (Entity (P)))) =
16832 -- Case of a reference to a value on which side effects have
16835 Exp := Prefix (Expression (Parent (Entity (P))));
16843 elsif Nkind_In (Exp, N_Type_Conversion,
16844 N_Unchecked_Type_Conversion)
16846 Exp := Expression (Exp);
16849 elsif Nkind_In (Exp, N_Slice,
16850 N_Indexed_Component,
16851 N_Selected_Component)
16853 -- Special check, if the prefix is an access type, then return
16854 -- since we are modifying the thing pointed to, not the prefix.
16855 -- When we are expanding, most usually the prefix is replaced
16856 -- by an explicit dereference, and this test is not needed, but
16857 -- in some cases (notably -gnatc mode and generics) when we do
16858 -- not do full expansion, we need this special test.
16860 if Is_Access_Type (Etype (Prefix (Exp))) then
16863 -- Otherwise go to prefix and keep going
16866 Exp := Prefix (Exp);
16870 -- All other cases, not a modification
16876 -- Now look for entity being referenced
16878 if Present (Ent) then
16879 if Is_Object (Ent) then
16880 if Comes_From_Source (Exp)
16881 or else Modification_Comes_From_Source
16883 -- Give warning if pragma unmodified given and we are
16884 -- sure this is a modification.
16886 if Has_Pragma_Unmodified (Ent) and then Sure then
16887 Error_Msg_NE ("??pragma Unmodified given for &!", N, Ent);
16890 Set_Never_Set_In_Source (Ent, False);
16893 Set_Is_True_Constant (Ent, False);
16894 Set_Current_Value (Ent, Empty);
16895 Set_Is_Known_Null (Ent, False);
16897 if not Can_Never_Be_Null (Ent) then
16898 Set_Is_Known_Non_Null (Ent, False);
16901 -- Follow renaming chain
16903 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
16904 and then Present (Renamed_Object (Ent))
16906 Exp := Renamed_Object (Ent);
16908 -- If the entity is the loop variable in an iteration over
16909 -- a container, retrieve container expression to indicate
16910 -- possible modification.
16912 if Present (Related_Expression (Ent))
16913 and then Nkind (Parent (Related_Expression (Ent))) =
16914 N_Iterator_Specification
16916 Exp := Original_Node (Related_Expression (Ent));
16921 -- The expression may be the renaming of a subcomponent of an
16922 -- array or container. The assignment to the subcomponent is
16923 -- a modification of the container.
16925 elsif Comes_From_Source (Original_Node (Exp))
16926 and then Nkind_In (Original_Node (Exp), N_Selected_Component,
16927 N_Indexed_Component)
16929 Exp := Prefix (Original_Node (Exp));
16933 -- Generate a reference only if the assignment comes from
16934 -- source. This excludes, for example, calls to a dispatching
16935 -- assignment operation when the left-hand side is tagged. In
16936 -- GNATprove mode, we need those references also on generated
16937 -- code, as these are used to compute the local effects of
16940 if Modification_Comes_From_Source or GNATprove_Mode then
16941 Generate_Reference (Ent, Exp, 'm');
16943 -- If the target of the assignment is the bound variable
16944 -- in an iterator, indicate that the corresponding array
16945 -- or container is also modified.
16947 if Ada_Version >= Ada_2012
16948 and then Nkind (Parent (Ent)) = N_Iterator_Specification
16951 Domain : constant Node_Id := Name (Parent (Ent));
16954 -- TBD : in the full version of the construct, the
16955 -- domain of iteration can be given by an expression.
16957 if Is_Entity_Name (Domain) then
16958 Generate_Reference (Entity (Domain), Exp, 'm');
16959 Set_Is_True_Constant (Entity (Domain), False);
16960 Set_Never_Set_In_Source (Entity (Domain), False);
16969 -- If we are sure this is a modification from source, and we know
16970 -- this modifies a constant, then give an appropriate warning.
16973 and then Modification_Comes_From_Source
16974 and then Overlays_Constant (Ent)
16975 and then Address_Clause_Overlay_Warnings
16978 Addr : constant Node_Id := Address_Clause (Ent);
16983 Find_Overlaid_Entity (Addr, O_Ent, Off);
16985 Error_Msg_Sloc := Sloc (Addr);
16987 ("??constant& may be modified via address clause#",
16998 end Note_Possible_Modification;
17000 -------------------------
17001 -- Object_Access_Level --
17002 -------------------------
17004 -- Returns the static accessibility level of the view denoted by Obj. Note
17005 -- that the value returned is the result of a call to Scope_Depth. Only
17006 -- scope depths associated with dynamic scopes can actually be returned.
17007 -- Since only relative levels matter for accessibility checking, the fact
17008 -- that the distance between successive levels of accessibility is not
17009 -- always one is immaterial (invariant: if level(E2) is deeper than
17010 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
17012 function Object_Access_Level (Obj : Node_Id) return Uint is
17013 function Is_Interface_Conversion (N : Node_Id) return Boolean;
17014 -- Determine whether N is a construct of the form
17015 -- Some_Type (Operand._tag'Address)
17016 -- This construct appears in the context of dispatching calls.
17018 function Reference_To (Obj : Node_Id) return Node_Id;
17019 -- An explicit dereference is created when removing side-effects from
17020 -- expressions for constraint checking purposes. In this case a local
17021 -- access type is created for it. The correct access level is that of
17022 -- the original source node. We detect this case by noting that the
17023 -- prefix of the dereference is created by an object declaration whose
17024 -- initial expression is a reference.
17026 -----------------------------
17027 -- Is_Interface_Conversion --
17028 -----------------------------
17030 function Is_Interface_Conversion (N : Node_Id) return Boolean is
17032 return Nkind (N) = N_Unchecked_Type_Conversion
17033 and then Nkind (Expression (N)) = N_Attribute_Reference
17034 and then Attribute_Name (Expression (N)) = Name_Address;
17035 end Is_Interface_Conversion;
17041 function Reference_To (Obj : Node_Id) return Node_Id is
17042 Pref : constant Node_Id := Prefix (Obj);
17044 if Is_Entity_Name (Pref)
17045 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
17046 and then Present (Expression (Parent (Entity (Pref))))
17047 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
17049 return (Prefix (Expression (Parent (Entity (Pref)))));
17059 -- Start of processing for Object_Access_Level
17062 if Nkind (Obj) = N_Defining_Identifier
17063 or else Is_Entity_Name (Obj)
17065 if Nkind (Obj) = N_Defining_Identifier then
17071 if Is_Prival (E) then
17072 E := Prival_Link (E);
17075 -- If E is a type then it denotes a current instance. For this case
17076 -- we add one to the normal accessibility level of the type to ensure
17077 -- that current instances are treated as always being deeper than
17078 -- than the level of any visible named access type (see 3.10.2(21)).
17080 if Is_Type (E) then
17081 return Type_Access_Level (E) + 1;
17083 elsif Present (Renamed_Object (E)) then
17084 return Object_Access_Level (Renamed_Object (E));
17086 -- Similarly, if E is a component of the current instance of a
17087 -- protected type, any instance of it is assumed to be at a deeper
17088 -- level than the type. For a protected object (whose type is an
17089 -- anonymous protected type) its components are at the same level
17090 -- as the type itself.
17092 elsif not Is_Overloadable (E)
17093 and then Ekind (Scope (E)) = E_Protected_Type
17094 and then Comes_From_Source (Scope (E))
17096 return Type_Access_Level (Scope (E)) + 1;
17099 -- Aliased formals of functions take their access level from the
17100 -- point of call, i.e. require a dynamic check. For static check
17101 -- purposes, this is smaller than the level of the subprogram
17102 -- itself. For procedures the aliased makes no difference.
17105 and then Is_Aliased (E)
17106 and then Ekind (Scope (E)) = E_Function
17108 return Type_Access_Level (Etype (E));
17111 return Scope_Depth (Enclosing_Dynamic_Scope (E));
17115 elsif Nkind (Obj) = N_Selected_Component then
17116 if Is_Access_Type (Etype (Prefix (Obj))) then
17117 return Type_Access_Level (Etype (Prefix (Obj)));
17119 return Object_Access_Level (Prefix (Obj));
17122 elsif Nkind (Obj) = N_Indexed_Component then
17123 if Is_Access_Type (Etype (Prefix (Obj))) then
17124 return Type_Access_Level (Etype (Prefix (Obj)));
17126 return Object_Access_Level (Prefix (Obj));
17129 elsif Nkind (Obj) = N_Explicit_Dereference then
17131 -- If the prefix is a selected access discriminant then we make a
17132 -- recursive call on the prefix, which will in turn check the level
17133 -- of the prefix object of the selected discriminant.
17135 -- In Ada 2012, if the discriminant has implicit dereference and
17136 -- the context is a selected component, treat this as an object of
17137 -- unknown scope (see below). This is necessary in compile-only mode;
17138 -- otherwise expansion will already have transformed the prefix into
17141 if Nkind (Prefix (Obj)) = N_Selected_Component
17142 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
17144 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
17146 (not Has_Implicit_Dereference
17147 (Entity (Selector_Name (Prefix (Obj))))
17148 or else Nkind (Parent (Obj)) /= N_Selected_Component)
17150 return Object_Access_Level (Prefix (Obj));
17152 -- Detect an interface conversion in the context of a dispatching
17153 -- call. Use the original form of the conversion to find the access
17154 -- level of the operand.
17156 elsif Is_Interface (Etype (Obj))
17157 and then Is_Interface_Conversion (Prefix (Obj))
17158 and then Nkind (Original_Node (Obj)) = N_Type_Conversion
17160 return Object_Access_Level (Original_Node (Obj));
17162 elsif not Comes_From_Source (Obj) then
17164 Ref : constant Node_Id := Reference_To (Obj);
17166 if Present (Ref) then
17167 return Object_Access_Level (Ref);
17169 return Type_Access_Level (Etype (Prefix (Obj)));
17174 return Type_Access_Level (Etype (Prefix (Obj)));
17177 elsif Nkind_In (Obj, N_Type_Conversion, N_Unchecked_Type_Conversion) then
17178 return Object_Access_Level (Expression (Obj));
17180 elsif Nkind (Obj) = N_Function_Call then
17182 -- Function results are objects, so we get either the access level of
17183 -- the function or, in the case of an indirect call, the level of the
17184 -- access-to-subprogram type. (This code is used for Ada 95, but it
17185 -- looks wrong, because it seems that we should be checking the level
17186 -- of the call itself, even for Ada 95. However, using the Ada 2005
17187 -- version of the code causes regressions in several tests that are
17188 -- compiled with -gnat95. ???)
17190 if Ada_Version < Ada_2005 then
17191 if Is_Entity_Name (Name (Obj)) then
17192 return Subprogram_Access_Level (Entity (Name (Obj)));
17194 return Type_Access_Level (Etype (Prefix (Name (Obj))));
17197 -- For Ada 2005, the level of the result object of a function call is
17198 -- defined to be the level of the call's innermost enclosing master.
17199 -- We determine that by querying the depth of the innermost enclosing
17203 Return_Master_Scope_Depth_Of_Call : declare
17205 function Innermost_Master_Scope_Depth
17206 (N : Node_Id) return Uint;
17207 -- Returns the scope depth of the given node's innermost
17208 -- enclosing dynamic scope (effectively the accessibility
17209 -- level of the innermost enclosing master).
17211 ----------------------------------
17212 -- Innermost_Master_Scope_Depth --
17213 ----------------------------------
17215 function Innermost_Master_Scope_Depth
17216 (N : Node_Id) return Uint
17218 Node_Par : Node_Id := Parent (N);
17221 -- Locate the nearest enclosing node (by traversing Parents)
17222 -- that Defining_Entity can be applied to, and return the
17223 -- depth of that entity's nearest enclosing dynamic scope.
17225 while Present (Node_Par) loop
17226 case Nkind (Node_Par) is
17227 when N_Component_Declaration |
17228 N_Entry_Declaration |
17229 N_Formal_Object_Declaration |
17230 N_Formal_Type_Declaration |
17231 N_Full_Type_Declaration |
17232 N_Incomplete_Type_Declaration |
17233 N_Loop_Parameter_Specification |
17234 N_Object_Declaration |
17235 N_Protected_Type_Declaration |
17236 N_Private_Extension_Declaration |
17237 N_Private_Type_Declaration |
17238 N_Subtype_Declaration |
17239 N_Function_Specification |
17240 N_Procedure_Specification |
17241 N_Task_Type_Declaration |
17243 N_Generic_Instantiation |
17245 N_Implicit_Label_Declaration |
17246 N_Package_Declaration |
17247 N_Single_Task_Declaration |
17248 N_Subprogram_Declaration |
17249 N_Generic_Declaration |
17250 N_Renaming_Declaration |
17251 N_Block_Statement |
17252 N_Formal_Subprogram_Declaration |
17253 N_Abstract_Subprogram_Declaration |
17255 N_Exception_Declaration |
17256 N_Formal_Package_Declaration |
17257 N_Number_Declaration |
17258 N_Package_Specification |
17259 N_Parameter_Specification |
17260 N_Single_Protected_Declaration |
17264 (Nearest_Dynamic_Scope
17265 (Defining_Entity (Node_Par)));
17271 Node_Par := Parent (Node_Par);
17274 pragma Assert (False);
17276 -- Should never reach the following return
17278 return Scope_Depth (Current_Scope) + 1;
17279 end Innermost_Master_Scope_Depth;
17281 -- Start of processing for Return_Master_Scope_Depth_Of_Call
17284 return Innermost_Master_Scope_Depth (Obj);
17285 end Return_Master_Scope_Depth_Of_Call;
17288 -- For convenience we handle qualified expressions, even though they
17289 -- aren't technically object names.
17291 elsif Nkind (Obj) = N_Qualified_Expression then
17292 return Object_Access_Level (Expression (Obj));
17294 -- Ditto for aggregates. They have the level of the temporary that
17295 -- will hold their value.
17297 elsif Nkind (Obj) = N_Aggregate then
17298 return Object_Access_Level (Current_Scope);
17300 -- Otherwise return the scope level of Standard. (If there are cases
17301 -- that fall through to this point they will be treated as having
17302 -- global accessibility for now. ???)
17305 return Scope_Depth (Standard_Standard);
17307 end Object_Access_Level;
17309 ---------------------------------
17310 -- Original_Aspect_Pragma_Name --
17311 ---------------------------------
17313 function Original_Aspect_Pragma_Name (N : Node_Id) return Name_Id is
17315 Item_Nam : Name_Id;
17318 pragma Assert (Nkind_In (N, N_Aspect_Specification, N_Pragma));
17322 -- The pragma was generated to emulate an aspect, use the original
17323 -- aspect specification.
17325 if Nkind (Item) = N_Pragma and then From_Aspect_Specification (Item) then
17326 Item := Corresponding_Aspect (Item);
17329 -- Retrieve the name of the aspect/pragma. Note that Pre, Pre_Class,
17330 -- Post and Post_Class rewrite their pragma identifier to preserve the
17332 -- ??? this is kludgey
17334 if Nkind (Item) = N_Pragma then
17335 Item_Nam := Chars (Original_Node (Pragma_Identifier (Item)));
17338 pragma Assert (Nkind (Item) = N_Aspect_Specification);
17339 Item_Nam := Chars (Identifier (Item));
17342 -- Deal with 'Class by converting the name to its _XXX form
17344 if Class_Present (Item) then
17345 if Item_Nam = Name_Invariant then
17346 Item_Nam := Name_uInvariant;
17348 elsif Item_Nam = Name_Post then
17349 Item_Nam := Name_uPost;
17351 elsif Item_Nam = Name_Pre then
17352 Item_Nam := Name_uPre;
17354 elsif Nam_In (Item_Nam, Name_Type_Invariant,
17355 Name_Type_Invariant_Class)
17357 Item_Nam := Name_uType_Invariant;
17359 -- Nothing to do for other cases (e.g. a Check that derived from
17360 -- Pre_Class and has the flag set). Also we do nothing if the name
17361 -- is already in special _xxx form.
17367 end Original_Aspect_Pragma_Name;
17369 --------------------------------------
17370 -- Original_Corresponding_Operation --
17371 --------------------------------------
17373 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
17375 Typ : constant Entity_Id := Find_Dispatching_Type (S);
17378 -- If S is an inherited primitive S2 the original corresponding
17379 -- operation of S is the original corresponding operation of S2
17381 if Present (Alias (S))
17382 and then Find_Dispatching_Type (Alias (S)) /= Typ
17384 return Original_Corresponding_Operation (Alias (S));
17386 -- If S overrides an inherited subprogram S2 the original corresponding
17387 -- operation of S is the original corresponding operation of S2
17389 elsif Present (Overridden_Operation (S)) then
17390 return Original_Corresponding_Operation (Overridden_Operation (S));
17392 -- otherwise it is S itself
17397 end Original_Corresponding_Operation;
17399 ----------------------
17400 -- Policy_In_Effect --
17401 ----------------------
17403 function Policy_In_Effect (Policy : Name_Id) return Name_Id is
17404 function Policy_In_List (List : Node_Id) return Name_Id;
17405 -- Determine the mode of a policy in a N_Pragma list
17407 --------------------
17408 -- Policy_In_List --
17409 --------------------
17411 function Policy_In_List (List : Node_Id) return Name_Id is
17418 while Present (Prag) loop
17419 Arg1 := First (Pragma_Argument_Associations (Prag));
17420 Arg2 := Next (Arg1);
17422 Arg1 := Get_Pragma_Arg (Arg1);
17423 Arg2 := Get_Pragma_Arg (Arg2);
17425 -- The current Check_Policy pragma matches the requested policy or
17426 -- appears in the single argument form (Assertion, policy_id).
17428 if Nam_In (Chars (Arg1), Name_Assertion, Policy) then
17429 return Chars (Arg2);
17432 Prag := Next_Pragma (Prag);
17436 end Policy_In_List;
17442 -- Start of processing for Policy_In_Effect
17445 if not Is_Valid_Assertion_Kind (Policy) then
17446 raise Program_Error;
17449 -- Inspect all policy pragmas that appear within scopes (if any)
17451 Kind := Policy_In_List (Check_Policy_List);
17453 -- Inspect all configuration policy pragmas (if any)
17455 if Kind = No_Name then
17456 Kind := Policy_In_List (Check_Policy_List_Config);
17459 -- The context lacks policy pragmas, determine the mode based on whether
17460 -- assertions are enabled at the configuration level. This ensures that
17461 -- the policy is preserved when analyzing generics.
17463 if Kind = No_Name then
17464 if Assertions_Enabled_Config then
17465 Kind := Name_Check;
17467 Kind := Name_Ignore;
17472 end Policy_In_Effect;
17474 ----------------------------------
17475 -- Predicate_Tests_On_Arguments --
17476 ----------------------------------
17478 function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean is
17480 -- Always test predicates on indirect call
17482 if Ekind (Subp) = E_Subprogram_Type then
17485 -- Do not test predicates on call to generated default Finalize, since
17486 -- we are not interested in whether something we are finalizing (and
17487 -- typically destroying) satisfies its predicates.
17489 elsif Chars (Subp) = Name_Finalize
17490 and then not Comes_From_Source (Subp)
17494 -- Do not test predicates on any internally generated routines
17496 elsif Is_Internal_Name (Chars (Subp)) then
17499 -- Do not test predicates on call to Init_Proc, since if needed the
17500 -- predicate test will occur at some other point.
17502 elsif Is_Init_Proc (Subp) then
17505 -- Do not test predicates on call to predicate function, since this
17506 -- would cause infinite recursion.
17508 elsif Ekind (Subp) = E_Function
17509 and then (Is_Predicate_Function (Subp)
17511 Is_Predicate_Function_M (Subp))
17515 -- For now, no other exceptions
17520 end Predicate_Tests_On_Arguments;
17522 -----------------------
17523 -- Private_Component --
17524 -----------------------
17526 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
17527 Ancestor : constant Entity_Id := Base_Type (Type_Id);
17529 function Trace_Components
17531 Check : Boolean) return Entity_Id;
17532 -- Recursive function that does the work, and checks against circular
17533 -- definition for each subcomponent type.
17535 ----------------------
17536 -- Trace_Components --
17537 ----------------------
17539 function Trace_Components
17541 Check : Boolean) return Entity_Id
17543 Btype : constant Entity_Id := Base_Type (T);
17544 Component : Entity_Id;
17546 Candidate : Entity_Id := Empty;
17549 if Check and then Btype = Ancestor then
17550 Error_Msg_N ("circular type definition", Type_Id);
17554 if Is_Private_Type (Btype) and then not Is_Generic_Type (Btype) then
17555 if Present (Full_View (Btype))
17556 and then Is_Record_Type (Full_View (Btype))
17557 and then not Is_Frozen (Btype)
17559 -- To indicate that the ancestor depends on a private type, the
17560 -- current Btype is sufficient. However, to check for circular
17561 -- definition we must recurse on the full view.
17563 Candidate := Trace_Components (Full_View (Btype), True);
17565 if Candidate = Any_Type then
17575 elsif Is_Array_Type (Btype) then
17576 return Trace_Components (Component_Type (Btype), True);
17578 elsif Is_Record_Type (Btype) then
17579 Component := First_Entity (Btype);
17580 while Present (Component)
17581 and then Comes_From_Source (Component)
17583 -- Skip anonymous types generated by constrained components
17585 if not Is_Type (Component) then
17586 P := Trace_Components (Etype (Component), True);
17588 if Present (P) then
17589 if P = Any_Type then
17597 Next_Entity (Component);
17605 end Trace_Components;
17607 -- Start of processing for Private_Component
17610 return Trace_Components (Type_Id, False);
17611 end Private_Component;
17613 ---------------------------
17614 -- Primitive_Names_Match --
17615 ---------------------------
17617 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
17619 function Non_Internal_Name (E : Entity_Id) return Name_Id;
17620 -- Given an internal name, returns the corresponding non-internal name
17622 ------------------------
17623 -- Non_Internal_Name --
17624 ------------------------
17626 function Non_Internal_Name (E : Entity_Id) return Name_Id is
17628 Get_Name_String (Chars (E));
17629 Name_Len := Name_Len - 1;
17631 end Non_Internal_Name;
17633 -- Start of processing for Primitive_Names_Match
17636 pragma Assert (Present (E1) and then Present (E2));
17638 return Chars (E1) = Chars (E2)
17640 (not Is_Internal_Name (Chars (E1))
17641 and then Is_Internal_Name (Chars (E2))
17642 and then Non_Internal_Name (E2) = Chars (E1))
17644 (not Is_Internal_Name (Chars (E2))
17645 and then Is_Internal_Name (Chars (E1))
17646 and then Non_Internal_Name (E1) = Chars (E2))
17648 (Is_Predefined_Dispatching_Operation (E1)
17649 and then Is_Predefined_Dispatching_Operation (E2)
17650 and then Same_TSS (E1, E2))
17652 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
17653 end Primitive_Names_Match;
17655 -----------------------
17656 -- Process_End_Label --
17657 -----------------------
17659 procedure Process_End_Label
17668 Label_Ref : Boolean;
17669 -- Set True if reference to end label itself is required
17672 -- Gets set to the operator symbol or identifier that references the
17673 -- entity Ent. For the child unit case, this is the identifier from the
17674 -- designator. For other cases, this is simply Endl.
17676 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
17677 -- N is an identifier node that appears as a parent unit reference in
17678 -- the case where Ent is a child unit. This procedure generates an
17679 -- appropriate cross-reference entry. E is the corresponding entity.
17681 -------------------------
17682 -- Generate_Parent_Ref --
17683 -------------------------
17685 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
17687 -- If names do not match, something weird, skip reference
17689 if Chars (E) = Chars (N) then
17691 -- Generate the reference. We do NOT consider this as a reference
17692 -- for unreferenced symbol purposes.
17694 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
17696 if Style_Check then
17697 Style.Check_Identifier (N, E);
17700 end Generate_Parent_Ref;
17702 -- Start of processing for Process_End_Label
17705 -- If no node, ignore. This happens in some error situations, and
17706 -- also for some internally generated structures where no end label
17707 -- references are required in any case.
17713 -- Nothing to do if no End_Label, happens for internally generated
17714 -- constructs where we don't want an end label reference anyway. Also
17715 -- nothing to do if Endl is a string literal, which means there was
17716 -- some prior error (bad operator symbol)
17718 Endl := End_Label (N);
17720 if No (Endl) or else Nkind (Endl) = N_String_Literal then
17724 -- Reference node is not in extended main source unit
17726 if not In_Extended_Main_Source_Unit (N) then
17728 -- Generally we do not collect references except for the extended
17729 -- main source unit. The one exception is the 'e' entry for a
17730 -- package spec, where it is useful for a client to have the
17731 -- ending information to define scopes.
17737 Label_Ref := False;
17739 -- For this case, we can ignore any parent references, but we
17740 -- need the package name itself for the 'e' entry.
17742 if Nkind (Endl) = N_Designator then
17743 Endl := Identifier (Endl);
17747 -- Reference is in extended main source unit
17752 -- For designator, generate references for the parent entries
17754 if Nkind (Endl) = N_Designator then
17756 -- Generate references for the prefix if the END line comes from
17757 -- source (otherwise we do not need these references) We climb the
17758 -- scope stack to find the expected entities.
17760 if Comes_From_Source (Endl) then
17761 Nam := Name (Endl);
17762 Scop := Current_Scope;
17763 while Nkind (Nam) = N_Selected_Component loop
17764 Scop := Scope (Scop);
17765 exit when No (Scop);
17766 Generate_Parent_Ref (Selector_Name (Nam), Scop);
17767 Nam := Prefix (Nam);
17770 if Present (Scop) then
17771 Generate_Parent_Ref (Nam, Scope (Scop));
17775 Endl := Identifier (Endl);
17779 -- If the end label is not for the given entity, then either we have
17780 -- some previous error, or this is a generic instantiation for which
17781 -- we do not need to make a cross-reference in this case anyway. In
17782 -- either case we simply ignore the call.
17784 if Chars (Ent) /= Chars (Endl) then
17788 -- If label was really there, then generate a normal reference and then
17789 -- adjust the location in the end label to point past the name (which
17790 -- should almost always be the semicolon).
17792 Loc := Sloc (Endl);
17794 if Comes_From_Source (Endl) then
17796 -- If a label reference is required, then do the style check and
17797 -- generate an l-type cross-reference entry for the label
17800 if Style_Check then
17801 Style.Check_Identifier (Endl, Ent);
17804 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
17807 -- Set the location to point past the label (normally this will
17808 -- mean the semicolon immediately following the label). This is
17809 -- done for the sake of the 'e' or 't' entry generated below.
17811 Get_Decoded_Name_String (Chars (Endl));
17812 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
17815 -- In SPARK mode, no missing label is allowed for packages and
17816 -- subprogram bodies. Detect those cases by testing whether
17817 -- Process_End_Label was called for a body (Typ = 't') or a package.
17819 if Restriction_Check_Required (SPARK_05)
17820 and then (Typ = 't' or else Ekind (Ent) = E_Package)
17822 Error_Msg_Node_1 := Endl;
17823 Check_SPARK_05_Restriction
17824 ("`END &` required", Endl, Force => True);
17828 -- Now generate the e/t reference
17830 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
17832 -- Restore Sloc, in case modified above, since we have an identifier
17833 -- and the normal Sloc should be left set in the tree.
17835 Set_Sloc (Endl, Loc);
17836 end Process_End_Label;
17838 ---------------------------------------
17839 -- Record_Possible_Part_Of_Reference --
17840 ---------------------------------------
17842 procedure Record_Possible_Part_Of_Reference
17843 (Var_Id : Entity_Id;
17846 Encap : constant Entity_Id := Encapsulating_State (Var_Id);
17850 -- The variable is a constituent of a single protected/task type. Such
17851 -- a variable acts as a component of the type and must appear within a
17852 -- specific region (SPARK RM 9.3). Instead of recording the reference,
17853 -- verify its legality now.
17855 if Present (Encap) and then Is_Single_Concurrent_Object (Encap) then
17856 Check_Part_Of_Reference (Var_Id, Ref);
17858 -- The variable is subject to pragma Part_Of and may eventually become a
17859 -- constituent of a single protected/task type. Record the reference to
17860 -- verify its placement when the contract of the variable is analyzed.
17862 elsif Present (Get_Pragma (Var_Id, Pragma_Part_Of)) then
17863 Refs := Part_Of_References (Var_Id);
17866 Refs := New_Elmt_List;
17867 Set_Part_Of_References (Var_Id, Refs);
17870 Append_Elmt (Ref, Refs);
17872 end Record_Possible_Part_Of_Reference;
17878 function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
17879 Seen : Boolean := False;
17881 function Is_Reference (N : Node_Id) return Traverse_Result;
17882 -- Determine whether node N denotes a reference to Id. If this is the
17883 -- case, set global flag Seen to True and stop the traversal.
17889 function Is_Reference (N : Node_Id) return Traverse_Result is
17891 if Is_Entity_Name (N)
17892 and then Present (Entity (N))
17893 and then Entity (N) = Id
17902 procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
17904 -- Start of processing for Referenced
17907 Inspect_Expression (Expr);
17911 ------------------------------------
17912 -- References_Generic_Formal_Type --
17913 ------------------------------------
17915 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
17917 function Process (N : Node_Id) return Traverse_Result;
17918 -- Process one node in search for generic formal type
17924 function Process (N : Node_Id) return Traverse_Result is
17926 if Nkind (N) in N_Has_Entity then
17928 E : constant Entity_Id := Entity (N);
17930 if Present (E) then
17931 if Is_Generic_Type (E) then
17933 elsif Present (Etype (E))
17934 and then Is_Generic_Type (Etype (E))
17945 function Traverse is new Traverse_Func (Process);
17946 -- Traverse tree to look for generic type
17949 if Inside_A_Generic then
17950 return Traverse (N) = Abandon;
17954 end References_Generic_Formal_Type;
17956 --------------------
17957 -- Remove_Homonym --
17958 --------------------
17960 procedure Remove_Homonym (E : Entity_Id) is
17961 Prev : Entity_Id := Empty;
17965 if E = Current_Entity (E) then
17966 if Present (Homonym (E)) then
17967 Set_Current_Entity (Homonym (E));
17969 Set_Name_Entity_Id (Chars (E), Empty);
17973 H := Current_Entity (E);
17974 while Present (H) and then H /= E loop
17979 -- If E is not on the homonym chain, nothing to do
17981 if Present (H) then
17982 Set_Homonym (Prev, Homonym (E));
17985 end Remove_Homonym;
17987 ------------------------------
17988 -- Remove_Overloaded_Entity --
17989 ------------------------------
17991 procedure Remove_Overloaded_Entity (Id : Entity_Id) is
17992 procedure Remove_Primitive_Of (Typ : Entity_Id);
17993 -- Remove primitive subprogram Id from the list of primitives that
17994 -- belong to type Typ.
17996 -------------------------
17997 -- Remove_Primitive_Of --
17998 -------------------------
18000 procedure Remove_Primitive_Of (Typ : Entity_Id) is
18004 if Is_Tagged_Type (Typ) then
18005 Prims := Direct_Primitive_Operations (Typ);
18007 if Present (Prims) then
18008 Remove (Prims, Id);
18011 end Remove_Primitive_Of;
18015 Scop : constant Entity_Id := Scope (Id);
18016 Formal : Entity_Id;
18017 Prev_Id : Entity_Id;
18019 -- Start of processing for Remove_Overloaded_Entity
18022 -- Remove the entity from the homonym chain. When the entity is the
18023 -- head of the chain, associate the entry in the name table with its
18024 -- homonym effectively making it the new head of the chain.
18026 if Current_Entity (Id) = Id then
18027 Set_Name_Entity_Id (Chars (Id), Homonym (Id));
18029 -- Otherwise link the previous and next homonyms
18032 Prev_Id := Current_Entity (Id);
18033 while Present (Prev_Id) and then Homonym (Prev_Id) /= Id loop
18034 Prev_Id := Homonym (Prev_Id);
18037 Set_Homonym (Prev_Id, Homonym (Id));
18040 -- Remove the entity from the scope entity chain. When the entity is
18041 -- the head of the chain, set the next entity as the new head of the
18044 if First_Entity (Scop) = Id then
18046 Set_First_Entity (Scop, Next_Entity (Id));
18048 -- Otherwise the entity is either in the middle of the chain or it acts
18049 -- as its tail. Traverse and link the previous and next entities.
18052 Prev_Id := First_Entity (Scop);
18053 while Present (Prev_Id) and then Next_Entity (Prev_Id) /= Id loop
18054 Next_Entity (Prev_Id);
18057 Set_Next_Entity (Prev_Id, Next_Entity (Id));
18060 -- Handle the case where the entity acts as the tail of the scope entity
18063 if Last_Entity (Scop) = Id then
18064 Set_Last_Entity (Scop, Prev_Id);
18067 -- The entity denotes a primitive subprogram. Remove it from the list of
18068 -- primitives of the associated controlling type.
18070 if Ekind_In (Id, E_Function, E_Procedure) and then Is_Primitive (Id) then
18071 Formal := First_Formal (Id);
18072 while Present (Formal) loop
18073 if Is_Controlling_Formal (Formal) then
18074 Remove_Primitive_Of (Etype (Formal));
18078 Next_Formal (Formal);
18081 if Ekind (Id) = E_Function and then Has_Controlling_Result (Id) then
18082 Remove_Primitive_Of (Etype (Id));
18085 end Remove_Overloaded_Entity;
18087 ---------------------
18088 -- Rep_To_Pos_Flag --
18089 ---------------------
18091 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
18093 return New_Occurrence_Of
18094 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
18095 end Rep_To_Pos_Flag;
18097 --------------------
18098 -- Require_Entity --
18099 --------------------
18101 procedure Require_Entity (N : Node_Id) is
18103 if Is_Entity_Name (N) and then No (Entity (N)) then
18104 if Total_Errors_Detected /= 0 then
18105 Set_Entity (N, Any_Id);
18107 raise Program_Error;
18110 end Require_Entity;
18112 -------------------------------
18113 -- Requires_State_Refinement --
18114 -------------------------------
18116 function Requires_State_Refinement
18117 (Spec_Id : Entity_Id;
18118 Body_Id : Entity_Id) return Boolean
18120 function Mode_Is_Off (Prag : Node_Id) return Boolean;
18121 -- Given pragma SPARK_Mode, determine whether the mode is Off
18127 function Mode_Is_Off (Prag : Node_Id) return Boolean is
18131 -- The default SPARK mode is On
18137 Mode := Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
18139 -- Then the pragma lacks an argument, the default mode is On
18144 return Chars (Mode) = Name_Off;
18148 -- Start of processing for Requires_State_Refinement
18151 -- A package that does not define at least one abstract state cannot
18152 -- possibly require refinement.
18154 if No (Abstract_States (Spec_Id)) then
18157 -- The package instroduces a single null state which does not merit
18160 elsif Has_Null_Abstract_State (Spec_Id) then
18163 -- Check whether the package body is subject to pragma SPARK_Mode. If
18164 -- it is and the mode is Off, the package body is considered to be in
18165 -- regular Ada and does not require refinement.
18167 elsif Mode_Is_Off (SPARK_Pragma (Body_Id)) then
18170 -- The body's SPARK_Mode may be inherited from a similar pragma that
18171 -- appears in the private declarations of the spec. The pragma we are
18172 -- interested appears as the second entry in SPARK_Pragma.
18174 elsif Present (SPARK_Pragma (Spec_Id))
18175 and then Mode_Is_Off (Next_Pragma (SPARK_Pragma (Spec_Id)))
18179 -- The spec defines at least one abstract state and the body has no way
18180 -- of circumventing the refinement.
18185 end Requires_State_Refinement;
18187 ------------------------------
18188 -- Requires_Transient_Scope --
18189 ------------------------------
18191 -- A transient scope is required when variable-sized temporaries are
18192 -- allocated on the secondary stack, or when finalization actions must be
18193 -- generated before the next instruction.
18195 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
18196 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
18197 -- ???We retain the old and new algorithms for Requires_Transient_Scope for
18198 -- the time being. New_Requires_Transient_Scope is used by default; the
18199 -- debug switch -gnatdQ can be used to do Old_Requires_Transient_Scope
18200 -- instead. The intent is to use this temporarily to measure before/after
18201 -- efficiency. Note: when this temporary code is removed, the documentation
18202 -- of dQ in debug.adb should be removed.
18204 procedure Results_Differ (Id : Entity_Id);
18205 -- ???Debugging code. Called when the Old_ and New_ results differ. Will be
18206 -- removed when New_Requires_Transient_Scope becomes
18207 -- Requires_Transient_Scope and Old_Requires_Transient_Scope is eliminated.
18209 procedure Results_Differ (Id : Entity_Id) is
18211 if False then -- False to disable; True for debugging
18212 Treepr.Print_Tree_Node (Id);
18214 if Old_Requires_Transient_Scope (Id) =
18215 New_Requires_Transient_Scope (Id)
18217 raise Program_Error;
18220 end Results_Differ;
18222 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
18223 Old_Result : constant Boolean := Old_Requires_Transient_Scope (Id);
18226 if Debug_Flag_QQ then
18231 New_Result : constant Boolean := New_Requires_Transient_Scope (Id);
18234 -- Assert that we're not putting things on the secondary stack if we
18235 -- didn't before; we are trying to AVOID secondary stack when
18238 if not Old_Result then
18239 pragma Assert (not New_Result);
18243 if New_Result /= Old_Result then
18244 Results_Differ (Id);
18249 end Requires_Transient_Scope;
18251 ----------------------------------
18252 -- Old_Requires_Transient_Scope --
18253 ----------------------------------
18255 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
18256 Typ : constant Entity_Id := Underlying_Type (Id);
18259 -- This is a private type which is not completed yet. This can only
18260 -- happen in a default expression (of a formal parameter or of a
18261 -- record component). Do not expand transient scope in this case.
18266 -- Do not expand transient scope for non-existent procedure return
18268 elsif Typ = Standard_Void_Type then
18271 -- Elementary types do not require a transient scope
18273 elsif Is_Elementary_Type (Typ) then
18276 -- Generally, indefinite subtypes require a transient scope, since the
18277 -- back end cannot generate temporaries, since this is not a valid type
18278 -- for declaring an object. It might be possible to relax this in the
18279 -- future, e.g. by declaring the maximum possible space for the type.
18281 elsif not Is_Definite_Subtype (Typ) then
18284 -- Functions returning tagged types may dispatch on result so their
18285 -- returned value is allocated on the secondary stack. Controlled
18286 -- type temporaries need finalization.
18288 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
18293 elsif Is_Record_Type (Typ) then
18298 Comp := First_Entity (Typ);
18299 while Present (Comp) loop
18300 if Ekind (Comp) = E_Component then
18302 -- ???It's not clear we need a full recursive call to
18303 -- Old_Requires_Transient_Scope here. Note that the
18304 -- following can't happen.
18306 pragma Assert (Is_Definite_Subtype (Etype (Comp)));
18307 pragma Assert (not Has_Controlled_Component (Etype (Comp)));
18309 if Old_Requires_Transient_Scope (Etype (Comp)) then
18314 Next_Entity (Comp);
18320 -- String literal types never require transient scope
18322 elsif Ekind (Typ) = E_String_Literal_Subtype then
18325 -- Array type. Note that we already know that this is a constrained
18326 -- array, since unconstrained arrays will fail the indefinite test.
18328 elsif Is_Array_Type (Typ) then
18330 -- If component type requires a transient scope, the array does too
18332 if Old_Requires_Transient_Scope (Component_Type (Typ)) then
18335 -- Otherwise, we only need a transient scope if the size depends on
18336 -- the value of one or more discriminants.
18339 return Size_Depends_On_Discriminant (Typ);
18342 -- All other cases do not require a transient scope
18345 pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
18348 end Old_Requires_Transient_Scope;
18350 ----------------------------------
18351 -- New_Requires_Transient_Scope --
18352 ----------------------------------
18354 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
18356 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean;
18357 -- This is called for untagged records and protected types, with
18358 -- nondefaulted discriminants. Returns True if the size of function
18359 -- results is known at the call site, False otherwise. Returns False
18360 -- if there is a variant part that depends on the discriminants of
18361 -- this type, or if there is an array constrained by the discriminants
18362 -- of this type. ???Currently, this is overly conservative (the array
18363 -- could be nested inside some other record that is constrained by
18364 -- nondiscriminants). That is, the recursive calls are too conservative.
18366 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean;
18367 -- Returns True if Typ is a nonlimited record with defaulted
18368 -- discriminants whose max size makes it unsuitable for allocating on
18369 -- the primary stack.
18371 ------------------------------
18372 -- Caller_Known_Size_Record --
18373 ------------------------------
18375 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean is
18376 pragma Assert (Typ = Underlying_Type (Typ));
18379 if Has_Variant_Part (Typ) and then not Is_Definite_Subtype (Typ) then
18387 Comp := First_Entity (Typ);
18388 while Present (Comp) loop
18390 -- Only look at E_Component entities. No need to look at
18391 -- E_Discriminant entities, and we must ignore internal
18392 -- subtypes generated for constrained components.
18394 if Ekind (Comp) = E_Component then
18396 Comp_Type : constant Entity_Id :=
18397 Underlying_Type (Etype (Comp));
18400 if Is_Record_Type (Comp_Type)
18402 Is_Protected_Type (Comp_Type)
18404 if not Caller_Known_Size_Record (Comp_Type) then
18408 elsif Is_Array_Type (Comp_Type) then
18409 if Size_Depends_On_Discriminant (Comp_Type) then
18416 Next_Entity (Comp);
18421 end Caller_Known_Size_Record;
18423 ------------------------------
18424 -- Large_Max_Size_Mutable --
18425 ------------------------------
18427 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean is
18428 pragma Assert (Typ = Underlying_Type (Typ));
18430 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean;
18431 -- Returns true if the discrete type T has a large range
18433 ----------------------------
18434 -- Is_Large_Discrete_Type --
18435 ----------------------------
18437 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean is
18438 Threshold : constant Int := 16;
18439 -- Arbitrary threshold above which we consider it "large". We want
18440 -- a fairly large threshold, because these large types really
18441 -- shouldn't have default discriminants in the first place, in
18445 return UI_To_Int (RM_Size (T)) > Threshold;
18446 end Is_Large_Discrete_Type;
18449 if Is_Record_Type (Typ)
18450 and then not Is_Limited_View (Typ)
18451 and then Has_Defaulted_Discriminants (Typ)
18453 -- Loop through the components, looking for an array whose upper
18454 -- bound(s) depends on discriminants, where both the subtype of
18455 -- the discriminant and the index subtype are too large.
18461 Comp := First_Entity (Typ);
18462 while Present (Comp) loop
18463 if Ekind (Comp) = E_Component then
18465 Comp_Type : constant Entity_Id :=
18466 Underlying_Type (Etype (Comp));
18472 if Is_Array_Type (Comp_Type) then
18473 Indx := First_Index (Comp_Type);
18475 while Present (Indx) loop
18476 Ityp := Etype (Indx);
18477 Hi := Type_High_Bound (Ityp);
18479 if Nkind (Hi) = N_Identifier
18480 and then Ekind (Entity (Hi)) = E_Discriminant
18481 and then Is_Large_Discrete_Type (Ityp)
18482 and then Is_Large_Discrete_Type
18483 (Etype (Entity (Hi)))
18494 Next_Entity (Comp);
18500 end Large_Max_Size_Mutable;
18502 -- Local declarations
18504 Typ : constant Entity_Id := Underlying_Type (Id);
18506 -- Start of processing for New_Requires_Transient_Scope
18509 -- This is a private type which is not completed yet. This can only
18510 -- happen in a default expression (of a formal parameter or of a
18511 -- record component). Do not expand transient scope in this case.
18516 -- Do not expand transient scope for non-existent procedure return or
18517 -- string literal types.
18519 elsif Typ = Standard_Void_Type
18520 or else Ekind (Typ) = E_String_Literal_Subtype
18524 -- If Typ is a generic formal incomplete type, then we want to look at
18525 -- the actual type.
18527 elsif Ekind (Typ) = E_Record_Subtype
18528 and then Present (Cloned_Subtype (Typ))
18530 return New_Requires_Transient_Scope (Cloned_Subtype (Typ));
18532 -- Functions returning specific tagged types may dispatch on result, so
18533 -- their returned value is allocated on the secondary stack, even in the
18534 -- definite case. We must treat nondispatching functions the same way,
18535 -- because access-to-function types can point at both, so the calling
18536 -- conventions must be compatible. Is_Tagged_Type includes controlled
18537 -- types and class-wide types. Controlled type temporaries need
18540 -- ???It's not clear why we need to return noncontrolled types with
18541 -- controlled components on the secondary stack.
18543 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
18546 -- Untagged definite subtypes are known size. This includes all
18547 -- elementary [sub]types. Tasks are known size even if they have
18548 -- discriminants. So we return False here, with one exception:
18549 -- For a type like:
18550 -- type T (Last : Natural := 0) is
18551 -- X : String (1 .. Last);
18553 -- we return True. That's because for "P(F(...));", where F returns T,
18554 -- we don't know the size of the result at the call site, so if we
18555 -- allocated it on the primary stack, we would have to allocate the
18556 -- maximum size, which is way too big.
18558 elsif Is_Definite_Subtype (Typ) or else Is_Task_Type (Typ) then
18559 return Large_Max_Size_Mutable (Typ);
18561 -- Indefinite (discriminated) untagged record or protected type
18563 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
18564 return not Caller_Known_Size_Record (Typ);
18566 -- Unconstrained array
18569 pragma Assert (Is_Array_Type (Typ) and not Is_Definite_Subtype (Typ));
18572 end New_Requires_Transient_Scope;
18574 --------------------------
18575 -- Reset_Analyzed_Flags --
18576 --------------------------
18578 procedure Reset_Analyzed_Flags (N : Node_Id) is
18580 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
18581 -- Function used to reset Analyzed flags in tree. Note that we do
18582 -- not reset Analyzed flags in entities, since there is no need to
18583 -- reanalyze entities, and indeed, it is wrong to do so, since it
18584 -- can result in generating auxiliary stuff more than once.
18586 --------------------
18587 -- Clear_Analyzed --
18588 --------------------
18590 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
18592 if not Has_Extension (N) then
18593 Set_Analyzed (N, False);
18597 end Clear_Analyzed;
18599 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
18601 -- Start of processing for Reset_Analyzed_Flags
18604 Reset_Analyzed (N);
18605 end Reset_Analyzed_Flags;
18607 ------------------------
18608 -- Restore_SPARK_Mode --
18609 ------------------------
18611 procedure Restore_SPARK_Mode (Mode : SPARK_Mode_Type) is
18613 SPARK_Mode := Mode;
18614 end Restore_SPARK_Mode;
18616 --------------------------------
18617 -- Returns_Unconstrained_Type --
18618 --------------------------------
18620 function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
18622 return Ekind (Subp) = E_Function
18623 and then not Is_Scalar_Type (Etype (Subp))
18624 and then not Is_Access_Type (Etype (Subp))
18625 and then not Is_Constrained (Etype (Subp));
18626 end Returns_Unconstrained_Type;
18628 ----------------------------
18629 -- Root_Type_Of_Full_View --
18630 ----------------------------
18632 function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id is
18633 Rtyp : constant Entity_Id := Root_Type (T);
18636 -- The root type of the full view may itself be a private type. Keep
18637 -- looking for the ultimate derivation parent.
18639 if Is_Private_Type (Rtyp) and then Present (Full_View (Rtyp)) then
18640 return Root_Type_Of_Full_View (Full_View (Rtyp));
18644 end Root_Type_Of_Full_View;
18646 ---------------------------
18647 -- Safe_To_Capture_Value --
18648 ---------------------------
18650 function Safe_To_Capture_Value
18653 Cond : Boolean := False) return Boolean
18656 -- The only entities for which we track constant values are variables
18657 -- which are not renamings, constants, out parameters, and in out
18658 -- parameters, so check if we have this case.
18660 -- Note: it may seem odd to track constant values for constants, but in
18661 -- fact this routine is used for other purposes than simply capturing
18662 -- the value. In particular, the setting of Known[_Non]_Null.
18664 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
18666 Ekind_In (Ent, E_Constant, E_Out_Parameter, E_In_Out_Parameter)
18670 -- For conditionals, we also allow loop parameters and all formals,
18671 -- including in parameters.
18673 elsif Cond and then Ekind_In (Ent, E_Loop_Parameter, E_In_Parameter) then
18676 -- For all other cases, not just unsafe, but impossible to capture
18677 -- Current_Value, since the above are the only entities which have
18678 -- Current_Value fields.
18684 -- Skip if volatile or aliased, since funny things might be going on in
18685 -- these cases which we cannot necessarily track. Also skip any variable
18686 -- for which an address clause is given, or whose address is taken. Also
18687 -- never capture value of library level variables (an attempt to do so
18688 -- can occur in the case of package elaboration code).
18690 if Treat_As_Volatile (Ent)
18691 or else Is_Aliased (Ent)
18692 or else Present (Address_Clause (Ent))
18693 or else Address_Taken (Ent)
18694 or else (Is_Library_Level_Entity (Ent)
18695 and then Ekind (Ent) = E_Variable)
18700 -- OK, all above conditions are met. We also require that the scope of
18701 -- the reference be the same as the scope of the entity, not counting
18702 -- packages and blocks and loops.
18705 E_Scope : constant Entity_Id := Scope (Ent);
18706 R_Scope : Entity_Id;
18709 R_Scope := Current_Scope;
18710 while R_Scope /= Standard_Standard loop
18711 exit when R_Scope = E_Scope;
18713 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
18716 R_Scope := Scope (R_Scope);
18721 -- We also require that the reference does not appear in a context
18722 -- where it is not sure to be executed (i.e. a conditional context
18723 -- or an exception handler). We skip this if Cond is True, since the
18724 -- capturing of values from conditional tests handles this ok.
18737 -- Seems dubious that case expressions are not handled here ???
18740 while Present (P) loop
18741 if Nkind (P) = N_If_Statement
18742 or else Nkind (P) = N_Case_Statement
18743 or else (Nkind (P) in N_Short_Circuit
18744 and then Desc = Right_Opnd (P))
18745 or else (Nkind (P) = N_If_Expression
18746 and then Desc /= First (Expressions (P)))
18747 or else Nkind (P) = N_Exception_Handler
18748 or else Nkind (P) = N_Selective_Accept
18749 or else Nkind (P) = N_Conditional_Entry_Call
18750 or else Nkind (P) = N_Timed_Entry_Call
18751 or else Nkind (P) = N_Asynchronous_Select
18759 -- A special Ada 2012 case: the original node may be part
18760 -- of the else_actions of a conditional expression, in which
18761 -- case it might not have been expanded yet, and appears in
18762 -- a non-syntactic list of actions. In that case it is clearly
18763 -- not safe to save a value.
18766 and then Is_List_Member (Desc)
18767 and then No (Parent (List_Containing (Desc)))
18775 -- OK, looks safe to set value
18778 end Safe_To_Capture_Value;
18784 function Same_Name (N1, N2 : Node_Id) return Boolean is
18785 K1 : constant Node_Kind := Nkind (N1);
18786 K2 : constant Node_Kind := Nkind (N2);
18789 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
18790 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
18792 return Chars (N1) = Chars (N2);
18794 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
18795 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
18797 return Same_Name (Selector_Name (N1), Selector_Name (N2))
18798 and then Same_Name (Prefix (N1), Prefix (N2));
18809 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
18810 N1 : constant Node_Id := Original_Node (Node1);
18811 N2 : constant Node_Id := Original_Node (Node2);
18812 -- We do the tests on original nodes, since we are most interested
18813 -- in the original source, not any expansion that got in the way.
18815 K1 : constant Node_Kind := Nkind (N1);
18816 K2 : constant Node_Kind := Nkind (N2);
18819 -- First case, both are entities with same entity
18821 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
18823 EN1 : constant Entity_Id := Entity (N1);
18824 EN2 : constant Entity_Id := Entity (N2);
18826 if Present (EN1) and then Present (EN2)
18827 and then (Ekind_In (EN1, E_Variable, E_Constant)
18828 or else Is_Formal (EN1))
18836 -- Second case, selected component with same selector, same record
18838 if K1 = N_Selected_Component
18839 and then K2 = N_Selected_Component
18840 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
18842 return Same_Object (Prefix (N1), Prefix (N2));
18844 -- Third case, indexed component with same subscripts, same array
18846 elsif K1 = N_Indexed_Component
18847 and then K2 = N_Indexed_Component
18848 and then Same_Object (Prefix (N1), Prefix (N2))
18853 E1 := First (Expressions (N1));
18854 E2 := First (Expressions (N2));
18855 while Present (E1) loop
18856 if not Same_Value (E1, E2) then
18867 -- Fourth case, slice of same array with same bounds
18870 and then K2 = N_Slice
18871 and then Nkind (Discrete_Range (N1)) = N_Range
18872 and then Nkind (Discrete_Range (N2)) = N_Range
18873 and then Same_Value (Low_Bound (Discrete_Range (N1)),
18874 Low_Bound (Discrete_Range (N2)))
18875 and then Same_Value (High_Bound (Discrete_Range (N1)),
18876 High_Bound (Discrete_Range (N2)))
18878 return Same_Name (Prefix (N1), Prefix (N2));
18880 -- All other cases, not clearly the same object
18891 function Same_Type (T1, T2 : Entity_Id) return Boolean is
18896 elsif not Is_Constrained (T1)
18897 and then not Is_Constrained (T2)
18898 and then Base_Type (T1) = Base_Type (T2)
18902 -- For now don't bother with case of identical constraints, to be
18903 -- fiddled with later on perhaps (this is only used for optimization
18904 -- purposes, so it is not critical to do a best possible job)
18915 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
18917 if Compile_Time_Known_Value (Node1)
18918 and then Compile_Time_Known_Value (Node2)
18919 and then Expr_Value (Node1) = Expr_Value (Node2)
18922 elsif Same_Object (Node1, Node2) then
18929 -----------------------------
18930 -- Save_SPARK_Mode_And_Set --
18931 -----------------------------
18933 procedure Save_SPARK_Mode_And_Set
18934 (Context : Entity_Id;
18935 Mode : out SPARK_Mode_Type)
18938 -- Save the current mode in effect
18940 Mode := SPARK_Mode;
18942 -- Do not consider illegal or partially decorated constructs
18944 if Ekind (Context) = E_Void or else Error_Posted (Context) then
18947 elsif Present (SPARK_Pragma (Context)) then
18948 SPARK_Mode := Get_SPARK_Mode_From_Annotation (SPARK_Pragma (Context));
18950 end Save_SPARK_Mode_And_Set;
18952 -------------------------
18953 -- Scalar_Part_Present --
18954 -------------------------
18956 function Scalar_Part_Present (T : Entity_Id) return Boolean is
18960 if Is_Scalar_Type (T) then
18963 elsif Is_Array_Type (T) then
18964 return Scalar_Part_Present (Component_Type (T));
18966 elsif Is_Record_Type (T) or else Has_Discriminants (T) then
18967 C := First_Component_Or_Discriminant (T);
18968 while Present (C) loop
18969 if Scalar_Part_Present (Etype (C)) then
18972 Next_Component_Or_Discriminant (C);
18978 end Scalar_Part_Present;
18980 ------------------------
18981 -- Scope_Is_Transient --
18982 ------------------------
18984 function Scope_Is_Transient return Boolean is
18986 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
18987 end Scope_Is_Transient;
18993 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
18998 while Scop /= Standard_Standard loop
18999 Scop := Scope (Scop);
19001 if Scop = Scope2 then
19009 --------------------------
19010 -- Scope_Within_Or_Same --
19011 --------------------------
19013 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
19018 while Scop /= Standard_Standard loop
19019 if Scop = Scope2 then
19022 Scop := Scope (Scop);
19027 end Scope_Within_Or_Same;
19029 --------------------
19030 -- Set_Convention --
19031 --------------------
19033 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
19035 Basic_Set_Convention (E, Val);
19038 and then Is_Access_Subprogram_Type (Base_Type (E))
19039 and then Has_Foreign_Convention (E)
19042 -- A pragma Convention in an instance may apply to the subtype
19043 -- created for a formal, in which case we have already verified
19044 -- that conventions of actual and formal match and there is nothing
19045 -- to flag on the subtype.
19047 if In_Instance then
19050 Set_Can_Use_Internal_Rep (E, False);
19054 -- If E is an object or component, and the type of E is an anonymous
19055 -- access type with no convention set, then also set the convention of
19056 -- the anonymous access type. We do not do this for anonymous protected
19057 -- types, since protected types always have the default convention.
19059 if Present (Etype (E))
19060 and then (Is_Object (E)
19061 or else Ekind (E) = E_Component
19063 -- Allow E_Void (happens for pragma Convention appearing
19064 -- in the middle of a record applying to a component)
19066 or else Ekind (E) = E_Void)
19069 Typ : constant Entity_Id := Etype (E);
19072 if Ekind_In (Typ, E_Anonymous_Access_Type,
19073 E_Anonymous_Access_Subprogram_Type)
19074 and then not Has_Convention_Pragma (Typ)
19076 Basic_Set_Convention (Typ, Val);
19077 Set_Has_Convention_Pragma (Typ);
19079 -- And for the access subprogram type, deal similarly with the
19080 -- designated E_Subprogram_Type if it is also internal (which
19083 if Ekind (Typ) = E_Anonymous_Access_Subprogram_Type then
19085 Dtype : constant Entity_Id := Designated_Type (Typ);
19087 if Ekind (Dtype) = E_Subprogram_Type
19088 and then Is_Itype (Dtype)
19089 and then not Has_Convention_Pragma (Dtype)
19091 Basic_Set_Convention (Dtype, Val);
19092 Set_Has_Convention_Pragma (Dtype);
19099 end Set_Convention;
19101 ------------------------
19102 -- Set_Current_Entity --
19103 ------------------------
19105 -- The given entity is to be set as the currently visible definition of its
19106 -- associated name (i.e. the Node_Id associated with its name). All we have
19107 -- to do is to get the name from the identifier, and then set the
19108 -- associated Node_Id to point to the given entity.
19110 procedure Set_Current_Entity (E : Entity_Id) is
19112 Set_Name_Entity_Id (Chars (E), E);
19113 end Set_Current_Entity;
19115 ---------------------------
19116 -- Set_Debug_Info_Needed --
19117 ---------------------------
19119 procedure Set_Debug_Info_Needed (T : Entity_Id) is
19121 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
19122 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
19123 -- Used to set debug info in a related node if not set already
19125 --------------------------------------
19126 -- Set_Debug_Info_Needed_If_Not_Set --
19127 --------------------------------------
19129 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
19131 if Present (E) and then not Needs_Debug_Info (E) then
19132 Set_Debug_Info_Needed (E);
19134 -- For a private type, indicate that the full view also needs
19135 -- debug information.
19138 and then Is_Private_Type (E)
19139 and then Present (Full_View (E))
19141 Set_Debug_Info_Needed (Full_View (E));
19144 end Set_Debug_Info_Needed_If_Not_Set;
19146 -- Start of processing for Set_Debug_Info_Needed
19149 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
19150 -- indicates that Debug_Info_Needed is never required for the entity.
19151 -- Nothing to do if entity comes from a predefined file. Library files
19152 -- are compiled without debug information, but inlined bodies of these
19153 -- routines may appear in user code, and debug information on them ends
19154 -- up complicating debugging the user code.
19157 or else Debug_Info_Off (T)
19161 elsif In_Inlined_Body
19162 and then Is_Predefined_File_Name
19163 (Unit_File_Name (Get_Source_Unit (Sloc (T))))
19165 Set_Needs_Debug_Info (T, False);
19168 -- Set flag in entity itself. Note that we will go through the following
19169 -- circuitry even if the flag is already set on T. That's intentional,
19170 -- it makes sure that the flag will be set in subsidiary entities.
19172 Set_Needs_Debug_Info (T);
19174 -- Set flag on subsidiary entities if not set already
19176 if Is_Object (T) then
19177 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
19179 elsif Is_Type (T) then
19180 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
19182 if Is_Record_Type (T) then
19184 Ent : Entity_Id := First_Entity (T);
19186 while Present (Ent) loop
19187 Set_Debug_Info_Needed_If_Not_Set (Ent);
19192 -- For a class wide subtype, we also need debug information
19193 -- for the equivalent type.
19195 if Ekind (T) = E_Class_Wide_Subtype then
19196 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
19199 elsif Is_Array_Type (T) then
19200 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
19203 Indx : Node_Id := First_Index (T);
19205 while Present (Indx) loop
19206 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
19207 Indx := Next_Index (Indx);
19211 -- For a packed array type, we also need debug information for
19212 -- the type used to represent the packed array. Conversely, we
19213 -- also need it for the former if we need it for the latter.
19215 if Is_Packed (T) then
19216 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Impl_Type (T));
19219 if Is_Packed_Array_Impl_Type (T) then
19220 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
19223 elsif Is_Access_Type (T) then
19224 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
19226 elsif Is_Private_Type (T) then
19228 FV : constant Entity_Id := Full_View (T);
19231 Set_Debug_Info_Needed_If_Not_Set (FV);
19233 -- If the full view is itself a derived private type, we need
19234 -- debug information on its underlying type.
19237 and then Is_Private_Type (FV)
19238 and then Present (Underlying_Full_View (FV))
19240 Set_Needs_Debug_Info (Underlying_Full_View (FV));
19244 elsif Is_Protected_Type (T) then
19245 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
19247 elsif Is_Scalar_Type (T) then
19249 -- If the subrange bounds are materialized by dedicated constant
19250 -- objects, also include them in the debug info to make sure the
19251 -- debugger can properly use them.
19253 if Present (Scalar_Range (T))
19254 and then Nkind (Scalar_Range (T)) = N_Range
19257 Low_Bnd : constant Node_Id := Type_Low_Bound (T);
19258 High_Bnd : constant Node_Id := Type_High_Bound (T);
19261 if Is_Entity_Name (Low_Bnd) then
19262 Set_Debug_Info_Needed_If_Not_Set (Entity (Low_Bnd));
19265 if Is_Entity_Name (High_Bnd) then
19266 Set_Debug_Info_Needed_If_Not_Set (Entity (High_Bnd));
19272 end Set_Debug_Info_Needed;
19274 ----------------------------
19275 -- Set_Entity_With_Checks --
19276 ----------------------------
19278 procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id) is
19279 Val_Actual : Entity_Id;
19281 Post_Node : Node_Id;
19284 -- Unconditionally set the entity
19286 Set_Entity (N, Val);
19288 -- The node to post on is the selector in the case of an expanded name,
19289 -- and otherwise the node itself.
19291 if Nkind (N) = N_Expanded_Name then
19292 Post_Node := Selector_Name (N);
19297 -- Check for violation of No_Fixed_IO
19299 if Restriction_Check_Required (No_Fixed_IO)
19301 ((RTU_Loaded (Ada_Text_IO)
19302 and then (Is_RTE (Val, RE_Decimal_IO)
19304 Is_RTE (Val, RE_Fixed_IO)))
19307 (RTU_Loaded (Ada_Wide_Text_IO)
19308 and then (Is_RTE (Val, RO_WT_Decimal_IO)
19310 Is_RTE (Val, RO_WT_Fixed_IO)))
19313 (RTU_Loaded (Ada_Wide_Wide_Text_IO)
19314 and then (Is_RTE (Val, RO_WW_Decimal_IO)
19316 Is_RTE (Val, RO_WW_Fixed_IO))))
19318 -- A special extra check, don't complain about a reference from within
19319 -- the Ada.Interrupts package itself!
19321 and then not In_Same_Extended_Unit (N, Val)
19323 Check_Restriction (No_Fixed_IO, Post_Node);
19326 -- Remaining checks are only done on source nodes. Note that we test
19327 -- for violation of No_Fixed_IO even on non-source nodes, because the
19328 -- cases for checking violations of this restriction are instantiations
19329 -- where the reference in the instance has Comes_From_Source False.
19331 if not Comes_From_Source (N) then
19335 -- Check for violation of No_Abort_Statements, which is triggered by
19336 -- call to Ada.Task_Identification.Abort_Task.
19338 if Restriction_Check_Required (No_Abort_Statements)
19339 and then (Is_RTE (Val, RE_Abort_Task))
19341 -- A special extra check, don't complain about a reference from within
19342 -- the Ada.Task_Identification package itself!
19344 and then not In_Same_Extended_Unit (N, Val)
19346 Check_Restriction (No_Abort_Statements, Post_Node);
19349 if Val = Standard_Long_Long_Integer then
19350 Check_Restriction (No_Long_Long_Integers, Post_Node);
19353 -- Check for violation of No_Dynamic_Attachment
19355 if Restriction_Check_Required (No_Dynamic_Attachment)
19356 and then RTU_Loaded (Ada_Interrupts)
19357 and then (Is_RTE (Val, RE_Is_Reserved) or else
19358 Is_RTE (Val, RE_Is_Attached) or else
19359 Is_RTE (Val, RE_Current_Handler) or else
19360 Is_RTE (Val, RE_Attach_Handler) or else
19361 Is_RTE (Val, RE_Exchange_Handler) or else
19362 Is_RTE (Val, RE_Detach_Handler) or else
19363 Is_RTE (Val, RE_Reference))
19365 -- A special extra check, don't complain about a reference from within
19366 -- the Ada.Interrupts package itself!
19368 and then not In_Same_Extended_Unit (N, Val)
19370 Check_Restriction (No_Dynamic_Attachment, Post_Node);
19373 -- Check for No_Implementation_Identifiers
19375 if Restriction_Check_Required (No_Implementation_Identifiers) then
19377 -- We have an implementation defined entity if it is marked as
19378 -- implementation defined, or is defined in a package marked as
19379 -- implementation defined. However, library packages themselves
19380 -- are excluded (we don't want to flag Interfaces itself, just
19381 -- the entities within it).
19383 if (Is_Implementation_Defined (Val)
19385 (Present (Scope (Val))
19386 and then Is_Implementation_Defined (Scope (Val))))
19387 and then not (Ekind_In (Val, E_Package, E_Generic_Package)
19388 and then Is_Library_Level_Entity (Val))
19390 Check_Restriction (No_Implementation_Identifiers, Post_Node);
19394 -- Do the style check
19397 and then not Suppress_Style_Checks (Val)
19398 and then not In_Instance
19400 if Nkind (N) = N_Identifier then
19402 elsif Nkind (N) = N_Expanded_Name then
19403 Nod := Selector_Name (N);
19408 -- A special situation arises for derived operations, where we want
19409 -- to do the check against the parent (since the Sloc of the derived
19410 -- operation points to the derived type declaration itself).
19413 while not Comes_From_Source (Val_Actual)
19414 and then Nkind (Val_Actual) in N_Entity
19415 and then (Ekind (Val_Actual) = E_Enumeration_Literal
19416 or else Is_Subprogram_Or_Generic_Subprogram (Val_Actual))
19417 and then Present (Alias (Val_Actual))
19419 Val_Actual := Alias (Val_Actual);
19422 -- Renaming declarations for generic actuals do not come from source,
19423 -- and have a different name from that of the entity they rename, so
19424 -- there is no style check to perform here.
19426 if Chars (Nod) = Chars (Val_Actual) then
19427 Style.Check_Identifier (Nod, Val_Actual);
19431 Set_Entity (N, Val);
19432 end Set_Entity_With_Checks;
19434 ------------------------
19435 -- Set_Name_Entity_Id --
19436 ------------------------
19438 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
19440 Set_Name_Table_Int (Id, Int (Val));
19441 end Set_Name_Entity_Id;
19443 ---------------------
19444 -- Set_Next_Actual --
19445 ---------------------
19447 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
19449 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
19450 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
19452 end Set_Next_Actual;
19454 ----------------------------------
19455 -- Set_Optimize_Alignment_Flags --
19456 ----------------------------------
19458 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
19460 if Optimize_Alignment = 'S' then
19461 Set_Optimize_Alignment_Space (E);
19462 elsif Optimize_Alignment = 'T' then
19463 Set_Optimize_Alignment_Time (E);
19465 end Set_Optimize_Alignment_Flags;
19467 -----------------------
19468 -- Set_Public_Status --
19469 -----------------------
19471 procedure Set_Public_Status (Id : Entity_Id) is
19472 S : constant Entity_Id := Current_Scope;
19474 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
19475 -- Determines if E is defined within handled statement sequence or
19476 -- an if statement, returns True if so, False otherwise.
19478 ----------------------
19479 -- Within_HSS_Or_If --
19480 ----------------------
19482 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
19485 N := Declaration_Node (E);
19492 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
19498 end Within_HSS_Or_If;
19500 -- Start of processing for Set_Public_Status
19503 -- Everything in the scope of Standard is public
19505 if S = Standard_Standard then
19506 Set_Is_Public (Id);
19508 -- Entity is definitely not public if enclosing scope is not public
19510 elsif not Is_Public (S) then
19513 -- An object or function declaration that occurs in a handled sequence
19514 -- of statements or within an if statement is the declaration for a
19515 -- temporary object or local subprogram generated by the expander. It
19516 -- never needs to be made public and furthermore, making it public can
19517 -- cause back end problems.
19519 elsif Nkind_In (Parent (Id), N_Object_Declaration,
19520 N_Function_Specification)
19521 and then Within_HSS_Or_If (Id)
19525 -- Entities in public packages or records are public
19527 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
19528 Set_Is_Public (Id);
19530 -- The bounds of an entry family declaration can generate object
19531 -- declarations that are visible to the back-end, e.g. in the
19532 -- the declaration of a composite type that contains tasks.
19534 elsif Is_Concurrent_Type (S)
19535 and then not Has_Completion (S)
19536 and then Nkind (Parent (Id)) = N_Object_Declaration
19538 Set_Is_Public (Id);
19540 end Set_Public_Status;
19542 -----------------------------
19543 -- Set_Referenced_Modified --
19544 -----------------------------
19546 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
19550 -- Deal with indexed or selected component where prefix is modified
19552 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
19553 Pref := Prefix (N);
19555 -- If prefix is access type, then it is the designated object that is
19556 -- being modified, which means we have no entity to set the flag on.
19558 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
19561 -- Otherwise chase the prefix
19564 Set_Referenced_Modified (Pref, Out_Param);
19567 -- Otherwise see if we have an entity name (only other case to process)
19569 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
19570 Set_Referenced_As_LHS (Entity (N), not Out_Param);
19571 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
19573 end Set_Referenced_Modified;
19575 ----------------------------
19576 -- Set_Scope_Is_Transient --
19577 ----------------------------
19579 procedure Set_Scope_Is_Transient (V : Boolean := True) is
19581 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
19582 end Set_Scope_Is_Transient;
19584 -------------------
19585 -- Set_Size_Info --
19586 -------------------
19588 procedure Set_Size_Info (T1, T2 : Entity_Id) is
19590 -- We copy Esize, but not RM_Size, since in general RM_Size is
19591 -- subtype specific and does not get inherited by all subtypes.
19593 Set_Esize (T1, Esize (T2));
19594 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
19596 if Is_Discrete_Or_Fixed_Point_Type (T1)
19598 Is_Discrete_Or_Fixed_Point_Type (T2)
19600 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
19603 Set_Alignment (T1, Alignment (T2));
19606 --------------------
19607 -- Static_Boolean --
19608 --------------------
19610 function Static_Boolean (N : Node_Id) return Uint is
19612 Analyze_And_Resolve (N, Standard_Boolean);
19615 or else Error_Posted (N)
19616 or else Etype (N) = Any_Type
19621 if Is_OK_Static_Expression (N) then
19622 if not Raises_Constraint_Error (N) then
19623 return Expr_Value (N);
19628 elsif Etype (N) = Any_Type then
19632 Flag_Non_Static_Expr
19633 ("static boolean expression required here", N);
19636 end Static_Boolean;
19638 --------------------
19639 -- Static_Integer --
19640 --------------------
19642 function Static_Integer (N : Node_Id) return Uint is
19644 Analyze_And_Resolve (N, Any_Integer);
19647 or else Error_Posted (N)
19648 or else Etype (N) = Any_Type
19653 if Is_OK_Static_Expression (N) then
19654 if not Raises_Constraint_Error (N) then
19655 return Expr_Value (N);
19660 elsif Etype (N) = Any_Type then
19664 Flag_Non_Static_Expr
19665 ("static integer expression required here", N);
19668 end Static_Integer;
19670 --------------------------
19671 -- Statically_Different --
19672 --------------------------
19674 function Statically_Different (E1, E2 : Node_Id) return Boolean is
19675 R1 : constant Node_Id := Get_Referenced_Object (E1);
19676 R2 : constant Node_Id := Get_Referenced_Object (E2);
19678 return Is_Entity_Name (R1)
19679 and then Is_Entity_Name (R2)
19680 and then Entity (R1) /= Entity (R2)
19681 and then not Is_Formal (Entity (R1))
19682 and then not Is_Formal (Entity (R2));
19683 end Statically_Different;
19685 --------------------------------------
19686 -- Subject_To_Loop_Entry_Attributes --
19687 --------------------------------------
19689 function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
19695 -- The expansion mechanism transform a loop subject to at least one
19696 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
19697 -- the conditional part.
19699 if Nkind_In (Stmt, N_Block_Statement, N_If_Statement)
19700 and then Nkind (Original_Node (N)) = N_Loop_Statement
19702 Stmt := Original_Node (N);
19706 Nkind (Stmt) = N_Loop_Statement
19707 and then Present (Identifier (Stmt))
19708 and then Present (Entity (Identifier (Stmt)))
19709 and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
19710 end Subject_To_Loop_Entry_Attributes;
19712 -----------------------------
19713 -- Subprogram_Access_Level --
19714 -----------------------------
19716 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
19718 if Present (Alias (Subp)) then
19719 return Subprogram_Access_Level (Alias (Subp));
19721 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
19723 end Subprogram_Access_Level;
19725 -------------------------------
19726 -- Support_Atomic_Primitives --
19727 -------------------------------
19729 function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
19733 -- Verify the alignment of Typ is known
19735 if not Known_Alignment (Typ) then
19739 if Known_Static_Esize (Typ) then
19740 Size := UI_To_Int (Esize (Typ));
19742 -- If the Esize (Object_Size) is unknown at compile time, look at the
19743 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
19745 elsif Known_Static_RM_Size (Typ) then
19746 Size := UI_To_Int (RM_Size (Typ));
19748 -- Otherwise, the size is considered to be unknown.
19754 -- Check that the size of the component is 8, 16, 32 or 64 bits and that
19755 -- Typ is properly aligned.
19758 when 8 | 16 | 32 | 64 =>
19759 return Size = UI_To_Int (Alignment (Typ)) * 8;
19763 end Support_Atomic_Primitives;
19769 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
19771 if Debug_Flag_W then
19772 for J in 0 .. Scope_Stack.Last loop
19777 Write_Name (Chars (E));
19778 Write_Str (" from ");
19779 Write_Location (Sloc (N));
19784 -----------------------
19785 -- Transfer_Entities --
19786 -----------------------
19788 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
19789 procedure Set_Public_Status_Of (Id : Entity_Id);
19790 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
19791 -- Set_Public_Status. If successfull and Id denotes a record type, set
19792 -- the Is_Public attribute of its fields.
19794 --------------------------
19795 -- Set_Public_Status_Of --
19796 --------------------------
19798 procedure Set_Public_Status_Of (Id : Entity_Id) is
19802 if not Is_Public (Id) then
19803 Set_Public_Status (Id);
19805 -- When the input entity is a public record type, ensure that all
19806 -- its internal fields are also exposed to the linker. The fields
19807 -- of a class-wide type are never made public.
19810 and then Is_Record_Type (Id)
19811 and then not Is_Class_Wide_Type (Id)
19813 Field := First_Entity (Id);
19814 while Present (Field) loop
19815 Set_Is_Public (Field);
19816 Next_Entity (Field);
19820 end Set_Public_Status_Of;
19824 Full_Id : Entity_Id;
19827 -- Start of processing for Transfer_Entities
19830 Id := First_Entity (From);
19832 if Present (Id) then
19834 -- Merge the entity chain of the source scope with that of the
19835 -- destination scope.
19837 if Present (Last_Entity (To)) then
19838 Set_Next_Entity (Last_Entity (To), Id);
19840 Set_First_Entity (To, Id);
19843 Set_Last_Entity (To, Last_Entity (From));
19845 -- Inspect the entities of the source scope and update their Scope
19848 while Present (Id) loop
19849 Set_Scope (Id, To);
19850 Set_Public_Status_Of (Id);
19852 -- Handle an internally generated full view for a private type
19854 if Is_Private_Type (Id)
19855 and then Present (Full_View (Id))
19856 and then Is_Itype (Full_View (Id))
19858 Full_Id := Full_View (Id);
19860 Set_Scope (Full_Id, To);
19861 Set_Public_Status_Of (Full_Id);
19867 Set_First_Entity (From, Empty);
19868 Set_Last_Entity (From, Empty);
19870 end Transfer_Entities;
19872 -----------------------
19873 -- Type_Access_Level --
19874 -----------------------
19876 function Type_Access_Level (Typ : Entity_Id) return Uint is
19880 Btyp := Base_Type (Typ);
19882 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
19883 -- simply use the level where the type is declared. This is true for
19884 -- stand-alone object declarations, and for anonymous access types
19885 -- associated with components the level is the same as that of the
19886 -- enclosing composite type. However, special treatment is needed for
19887 -- the cases of access parameters, return objects of an anonymous access
19888 -- type, and, in Ada 95, access discriminants of limited types.
19890 if Is_Access_Type (Btyp) then
19891 if Ekind (Btyp) = E_Anonymous_Access_Type then
19893 -- If the type is a nonlocal anonymous access type (such as for
19894 -- an access parameter) we treat it as being declared at the
19895 -- library level to ensure that names such as X.all'access don't
19896 -- fail static accessibility checks.
19898 if not Is_Local_Anonymous_Access (Typ) then
19899 return Scope_Depth (Standard_Standard);
19901 -- If this is a return object, the accessibility level is that of
19902 -- the result subtype of the enclosing function. The test here is
19903 -- little complicated, because we have to account for extended
19904 -- return statements that have been rewritten as blocks, in which
19905 -- case we have to find and the Is_Return_Object attribute of the
19906 -- itype's associated object. It would be nice to find a way to
19907 -- simplify this test, but it doesn't seem worthwhile to add a new
19908 -- flag just for purposes of this test. ???
19910 elsif Ekind (Scope (Btyp)) = E_Return_Statement
19913 and then Nkind (Associated_Node_For_Itype (Btyp)) =
19914 N_Object_Declaration
19915 and then Is_Return_Object
19916 (Defining_Identifier
19917 (Associated_Node_For_Itype (Btyp))))
19923 Scop := Scope (Scope (Btyp));
19924 while Present (Scop) loop
19925 exit when Ekind (Scop) = E_Function;
19926 Scop := Scope (Scop);
19929 -- Treat the return object's type as having the level of the
19930 -- function's result subtype (as per RM05-6.5(5.3/2)).
19932 return Type_Access_Level (Etype (Scop));
19937 Btyp := Root_Type (Btyp);
19939 -- The accessibility level of anonymous access types associated with
19940 -- discriminants is that of the current instance of the type, and
19941 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
19943 -- AI-402: access discriminants have accessibility based on the
19944 -- object rather than the type in Ada 2005, so the above paragraph
19947 -- ??? Needs completion with rules from AI-416
19949 if Ada_Version <= Ada_95
19950 and then Ekind (Typ) = E_Anonymous_Access_Type
19951 and then Present (Associated_Node_For_Itype (Typ))
19952 and then Nkind (Associated_Node_For_Itype (Typ)) =
19953 N_Discriminant_Specification
19955 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
19959 -- Return library level for a generic formal type. This is done because
19960 -- RM(10.3.2) says that "The statically deeper relationship does not
19961 -- apply to ... a descendant of a generic formal type". Rather than
19962 -- checking at each point where a static accessibility check is
19963 -- performed to see if we are dealing with a formal type, this rule is
19964 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
19965 -- return extreme values for a formal type; Deepest_Type_Access_Level
19966 -- returns Int'Last. By calling the appropriate function from among the
19967 -- two, we ensure that the static accessibility check will pass if we
19968 -- happen to run into a formal type. More specifically, we should call
19969 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
19970 -- call occurs as part of a static accessibility check and the error
19971 -- case is the case where the type's level is too shallow (as opposed
19974 if Is_Generic_Type (Root_Type (Btyp)) then
19975 return Scope_Depth (Standard_Standard);
19978 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
19979 end Type_Access_Level;
19981 ------------------------------------
19982 -- Type_Without_Stream_Operation --
19983 ------------------------------------
19985 function Type_Without_Stream_Operation
19987 Op : TSS_Name_Type := TSS_Null) return Entity_Id
19989 BT : constant Entity_Id := Base_Type (T);
19990 Op_Missing : Boolean;
19993 if not Restriction_Active (No_Default_Stream_Attributes) then
19997 if Is_Elementary_Type (T) then
19998 if Op = TSS_Null then
20000 No (TSS (BT, TSS_Stream_Read))
20001 or else No (TSS (BT, TSS_Stream_Write));
20004 Op_Missing := No (TSS (BT, Op));
20013 elsif Is_Array_Type (T) then
20014 return Type_Without_Stream_Operation (Component_Type (T), Op);
20016 elsif Is_Record_Type (T) then
20022 Comp := First_Component (T);
20023 while Present (Comp) loop
20024 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
20026 if Present (C_Typ) then
20030 Next_Component (Comp);
20036 elsif Is_Private_Type (T) and then Present (Full_View (T)) then
20037 return Type_Without_Stream_Operation (Full_View (T), Op);
20041 end Type_Without_Stream_Operation;
20043 ----------------------------
20044 -- Unique_Defining_Entity --
20045 ----------------------------
20047 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
20049 return Unique_Entity (Defining_Entity (N));
20050 end Unique_Defining_Entity;
20052 -------------------
20053 -- Unique_Entity --
20054 -------------------
20056 function Unique_Entity (E : Entity_Id) return Entity_Id is
20057 U : Entity_Id := E;
20063 if Present (Full_View (E)) then
20064 U := Full_View (E);
20068 if Nkind (Parent (E)) = N_Entry_Body then
20070 Prot_Item : Entity_Id;
20072 -- Traverse the entity list of the protected type and locate
20073 -- an entry declaration which matches the entry body.
20075 Prot_Item := First_Entity (Scope (E));
20076 while Present (Prot_Item) loop
20077 if Ekind (Prot_Item) = E_Entry
20078 and then Corresponding_Body (Parent (Prot_Item)) = E
20084 Next_Entity (Prot_Item);
20089 when Formal_Kind =>
20090 if Present (Spec_Entity (E)) then
20091 U := Spec_Entity (E);
20094 when E_Package_Body =>
20097 if Nkind (P) = N_Defining_Program_Unit_Name then
20101 if Nkind (P) = N_Package_Body
20102 and then Present (Corresponding_Spec (P))
20104 U := Corresponding_Spec (P);
20106 elsif Nkind (P) = N_Package_Body_Stub
20107 and then Present (Corresponding_Spec_Of_Stub (P))
20109 U := Corresponding_Spec_Of_Stub (P);
20112 when E_Protected_Body =>
20115 if Nkind (P) = N_Protected_Body
20116 and then Present (Corresponding_Spec (P))
20118 U := Corresponding_Spec (P);
20120 elsif Nkind (P) = N_Protected_Body_Stub
20121 and then Present (Corresponding_Spec_Of_Stub (P))
20123 U := Corresponding_Spec_Of_Stub (P);
20126 when E_Subprogram_Body =>
20129 if Nkind (P) = N_Defining_Program_Unit_Name then
20135 if Nkind (P) = N_Subprogram_Body
20136 and then Present (Corresponding_Spec (P))
20138 U := Corresponding_Spec (P);
20140 elsif Nkind (P) = N_Subprogram_Body_Stub
20141 and then Present (Corresponding_Spec_Of_Stub (P))
20143 U := Corresponding_Spec_Of_Stub (P);
20146 when E_Task_Body =>
20149 if Nkind (P) = N_Task_Body
20150 and then Present (Corresponding_Spec (P))
20152 U := Corresponding_Spec (P);
20154 elsif Nkind (P) = N_Task_Body_Stub
20155 and then Present (Corresponding_Spec_Of_Stub (P))
20157 U := Corresponding_Spec_Of_Stub (P);
20161 if Present (Full_View (E)) then
20162 U := Full_View (E);
20176 function Unique_Name (E : Entity_Id) return String is
20178 -- Names of E_Subprogram_Body or E_Package_Body entities are not
20179 -- reliable, as they may not include the overloading suffix. Instead,
20180 -- when looking for the name of E or one of its enclosing scope, we get
20181 -- the name of the corresponding Unique_Entity.
20183 function Get_Scoped_Name (E : Entity_Id) return String;
20184 -- Return the name of E prefixed by all the names of the scopes to which
20185 -- E belongs, except for Standard.
20187 ---------------------
20188 -- Get_Scoped_Name --
20189 ---------------------
20191 function Get_Scoped_Name (E : Entity_Id) return String is
20192 Name : constant String := Get_Name_String (Chars (E));
20194 if Has_Fully_Qualified_Name (E)
20195 or else Scope (E) = Standard_Standard
20199 return Get_Scoped_Name (Unique_Entity (Scope (E))) & "__" & Name;
20201 end Get_Scoped_Name;
20203 -- Start of processing for Unique_Name
20206 if E = Standard_Standard then
20207 return Get_Name_String (Name_Standard);
20209 elsif Scope (E) = Standard_Standard
20210 and then not (Ekind (E) = E_Package or else Is_Subprogram (E))
20212 return Get_Name_String (Name_Standard) & "__" &
20213 Get_Name_String (Chars (E));
20215 elsif Ekind (E) = E_Enumeration_Literal then
20216 return Unique_Name (Etype (E)) & "__" & Get_Name_String (Chars (E));
20219 return Get_Scoped_Name (Unique_Entity (E));
20223 ---------------------
20224 -- Unit_Is_Visible --
20225 ---------------------
20227 function Unit_Is_Visible (U : Entity_Id) return Boolean is
20228 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
20229 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
20231 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
20232 -- For a child unit, check whether unit appears in a with_clause
20235 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
20236 -- Scan the context clause of one compilation unit looking for a
20237 -- with_clause for the unit in question.
20239 ----------------------------
20240 -- Unit_In_Parent_Context --
20241 ----------------------------
20243 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
20245 if Unit_In_Context (Par_Unit) then
20248 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
20249 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
20254 end Unit_In_Parent_Context;
20256 ---------------------
20257 -- Unit_In_Context --
20258 ---------------------
20260 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
20264 Clause := First (Context_Items (Comp_Unit));
20265 while Present (Clause) loop
20266 if Nkind (Clause) = N_With_Clause then
20267 if Library_Unit (Clause) = U then
20270 -- The with_clause may denote a renaming of the unit we are
20271 -- looking for, eg. Text_IO which renames Ada.Text_IO.
20274 Renamed_Entity (Entity (Name (Clause))) =
20275 Defining_Entity (Unit (U))
20285 end Unit_In_Context;
20287 -- Start of processing for Unit_Is_Visible
20290 -- The currrent unit is directly visible
20295 elsif Unit_In_Context (Curr) then
20298 -- If the current unit is a body, check the context of the spec
20300 elsif Nkind (Unit (Curr)) = N_Package_Body
20302 (Nkind (Unit (Curr)) = N_Subprogram_Body
20303 and then not Acts_As_Spec (Unit (Curr)))
20305 if Unit_In_Context (Library_Unit (Curr)) then
20310 -- If the spec is a child unit, examine the parents
20312 if Is_Child_Unit (Curr_Entity) then
20313 if Nkind (Unit (Curr)) in N_Unit_Body then
20315 Unit_In_Parent_Context
20316 (Parent_Spec (Unit (Library_Unit (Curr))));
20318 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
20324 end Unit_Is_Visible;
20326 ------------------------------
20327 -- Universal_Interpretation --
20328 ------------------------------
20330 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
20331 Index : Interp_Index;
20335 -- The argument may be a formal parameter of an operator or subprogram
20336 -- with multiple interpretations, or else an expression for an actual.
20338 if Nkind (Opnd) = N_Defining_Identifier
20339 or else not Is_Overloaded (Opnd)
20341 if Etype (Opnd) = Universal_Integer
20342 or else Etype (Opnd) = Universal_Real
20344 return Etype (Opnd);
20350 Get_First_Interp (Opnd, Index, It);
20351 while Present (It.Typ) loop
20352 if It.Typ = Universal_Integer
20353 or else It.Typ = Universal_Real
20358 Get_Next_Interp (Index, It);
20363 end Universal_Interpretation;
20369 function Unqualify (Expr : Node_Id) return Node_Id is
20371 -- Recurse to handle unlikely case of multiple levels of qualification
20373 if Nkind (Expr) = N_Qualified_Expression then
20374 return Unqualify (Expression (Expr));
20376 -- Normal case, not a qualified expression
20383 -----------------------
20384 -- Visible_Ancestors --
20385 -----------------------
20387 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
20393 pragma Assert (Is_Record_Type (Typ) and then Is_Tagged_Type (Typ));
20395 -- Collect all the parents and progenitors of Typ. If the full-view of
20396 -- private parents and progenitors is available then it is used to
20397 -- generate the list of visible ancestors; otherwise their partial
20398 -- view is added to the resulting list.
20403 Use_Full_View => True);
20407 Ifaces_List => List_2,
20408 Exclude_Parents => True,
20409 Use_Full_View => True);
20411 -- Join the two lists. Avoid duplications because an interface may
20412 -- simultaneously be parent and progenitor of a type.
20414 Elmt := First_Elmt (List_2);
20415 while Present (Elmt) loop
20416 Append_Unique_Elmt (Node (Elmt), List_1);
20421 end Visible_Ancestors;
20423 ----------------------
20424 -- Within_Init_Proc --
20425 ----------------------
20427 function Within_Init_Proc return Boolean is
20431 S := Current_Scope;
20432 while not Is_Overloadable (S) loop
20433 if S = Standard_Standard then
20440 return Is_Init_Proc (S);
20441 end Within_Init_Proc;
20447 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
20449 return Scope_Within_Or_Same (Scope (E), S);
20456 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
20457 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
20458 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
20460 Matching_Field : Entity_Id;
20461 -- Entity to give a more precise suggestion on how to write a one-
20462 -- element positional aggregate.
20464 function Has_One_Matching_Field return Boolean;
20465 -- Determines if Expec_Type is a record type with a single component or
20466 -- discriminant whose type matches the found type or is one dimensional
20467 -- array whose component type matches the found type. In the case of
20468 -- one discriminant, we ignore the variant parts. That's not accurate,
20469 -- but good enough for the warning.
20471 ----------------------------
20472 -- Has_One_Matching_Field --
20473 ----------------------------
20475 function Has_One_Matching_Field return Boolean is
20479 Matching_Field := Empty;
20481 if Is_Array_Type (Expec_Type)
20482 and then Number_Dimensions (Expec_Type) = 1
20483 and then Covers (Etype (Component_Type (Expec_Type)), Found_Type)
20485 -- Use type name if available. This excludes multidimensional
20486 -- arrays and anonymous arrays.
20488 if Comes_From_Source (Expec_Type) then
20489 Matching_Field := Expec_Type;
20491 -- For an assignment, use name of target
20493 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
20494 and then Is_Entity_Name (Name (Parent (Expr)))
20496 Matching_Field := Entity (Name (Parent (Expr)));
20501 elsif not Is_Record_Type (Expec_Type) then
20505 E := First_Entity (Expec_Type);
20510 elsif not Ekind_In (E, E_Discriminant, E_Component)
20511 or else Nam_In (Chars (E), Name_uTag, Name_uParent)
20520 if not Covers (Etype (E), Found_Type) then
20523 elsif Present (Next_Entity (E))
20524 and then (Ekind (E) = E_Component
20525 or else Ekind (Next_Entity (E)) = E_Discriminant)
20530 Matching_Field := E;
20534 end Has_One_Matching_Field;
20536 -- Start of processing for Wrong_Type
20539 -- Don't output message if either type is Any_Type, or if a message
20540 -- has already been posted for this node. We need to do the latter
20541 -- check explicitly (it is ordinarily done in Errout), because we
20542 -- are using ! to force the output of the error messages.
20544 if Expec_Type = Any_Type
20545 or else Found_Type = Any_Type
20546 or else Error_Posted (Expr)
20550 -- If one of the types is a Taft-Amendment type and the other it its
20551 -- completion, it must be an illegal use of a TAT in the spec, for
20552 -- which an error was already emitted. Avoid cascaded errors.
20554 elsif Is_Incomplete_Type (Expec_Type)
20555 and then Has_Completion_In_Body (Expec_Type)
20556 and then Full_View (Expec_Type) = Etype (Expr)
20560 elsif Is_Incomplete_Type (Etype (Expr))
20561 and then Has_Completion_In_Body (Etype (Expr))
20562 and then Full_View (Etype (Expr)) = Expec_Type
20566 -- In an instance, there is an ongoing problem with completion of
20567 -- type derived from private types. Their structure is what Gigi
20568 -- expects, but the Etype is the parent type rather than the
20569 -- derived private type itself. Do not flag error in this case. The
20570 -- private completion is an entity without a parent, like an Itype.
20571 -- Similarly, full and partial views may be incorrect in the instance.
20572 -- There is no simple way to insure that it is consistent ???
20574 -- A similar view discrepancy can happen in an inlined body, for the
20575 -- same reason: inserted body may be outside of the original package
20576 -- and only partial views are visible at the point of insertion.
20578 elsif In_Instance or else In_Inlined_Body then
20579 if Etype (Etype (Expr)) = Etype (Expected_Type)
20581 (Has_Private_Declaration (Expected_Type)
20582 or else Has_Private_Declaration (Etype (Expr)))
20583 and then No (Parent (Expected_Type))
20587 elsif Nkind (Parent (Expr)) = N_Qualified_Expression
20588 and then Entity (Subtype_Mark (Parent (Expr))) = Expected_Type
20592 elsif Is_Private_Type (Expected_Type)
20593 and then Present (Full_View (Expected_Type))
20594 and then Covers (Full_View (Expected_Type), Etype (Expr))
20598 -- Conversely, type of expression may be the private one
20600 elsif Is_Private_Type (Base_Type (Etype (Expr)))
20601 and then Full_View (Base_Type (Etype (Expr))) = Expected_Type
20607 -- An interesting special check. If the expression is parenthesized
20608 -- and its type corresponds to the type of the sole component of the
20609 -- expected record type, or to the component type of the expected one
20610 -- dimensional array type, then assume we have a bad aggregate attempt.
20612 if Nkind (Expr) in N_Subexpr
20613 and then Paren_Count (Expr) /= 0
20614 and then Has_One_Matching_Field
20616 Error_Msg_N ("positional aggregate cannot have one component", Expr);
20618 if Present (Matching_Field) then
20619 if Is_Array_Type (Expec_Type) then
20621 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
20624 ("\write instead `& ='> ...`", Expr, Matching_Field);
20628 -- Another special check, if we are looking for a pool-specific access
20629 -- type and we found an E_Access_Attribute_Type, then we have the case
20630 -- of an Access attribute being used in a context which needs a pool-
20631 -- specific type, which is never allowed. The one extra check we make
20632 -- is that the expected designated type covers the Found_Type.
20634 elsif Is_Access_Type (Expec_Type)
20635 and then Ekind (Found_Type) = E_Access_Attribute_Type
20636 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
20637 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
20639 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
20641 Error_Msg_N -- CODEFIX
20642 ("result must be general access type!", Expr);
20643 Error_Msg_NE -- CODEFIX
20644 ("add ALL to }!", Expr, Expec_Type);
20646 -- Another special check, if the expected type is an integer type,
20647 -- but the expression is of type System.Address, and the parent is
20648 -- an addition or subtraction operation whose left operand is the
20649 -- expression in question and whose right operand is of an integral
20650 -- type, then this is an attempt at address arithmetic, so give
20651 -- appropriate message.
20653 elsif Is_Integer_Type (Expec_Type)
20654 and then Is_RTE (Found_Type, RE_Address)
20655 and then Nkind_In (Parent (Expr), N_Op_Add, N_Op_Subtract)
20656 and then Expr = Left_Opnd (Parent (Expr))
20657 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
20660 ("address arithmetic not predefined in package System",
20663 ("\possible missing with/use of System.Storage_Elements",
20667 -- If the expected type is an anonymous access type, as for access
20668 -- parameters and discriminants, the error is on the designated types.
20670 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
20671 if Comes_From_Source (Expec_Type) then
20672 Error_Msg_NE ("expected}!", Expr, Expec_Type);
20675 ("expected an access type with designated}",
20676 Expr, Designated_Type (Expec_Type));
20679 if Is_Access_Type (Found_Type)
20680 and then not Comes_From_Source (Found_Type)
20683 ("\\found an access type with designated}!",
20684 Expr, Designated_Type (Found_Type));
20686 if From_Limited_With (Found_Type) then
20687 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
20688 Error_Msg_Qual_Level := 99;
20689 Error_Msg_NE -- CODEFIX
20690 ("\\missing `WITH &;", Expr, Scope (Found_Type));
20691 Error_Msg_Qual_Level := 0;
20693 Error_Msg_NE ("found}!", Expr, Found_Type);
20697 -- Normal case of one type found, some other type expected
20700 -- If the names of the two types are the same, see if some number
20701 -- of levels of qualification will help. Don't try more than three
20702 -- levels, and if we get to standard, it's no use (and probably
20703 -- represents an error in the compiler) Also do not bother with
20704 -- internal scope names.
20707 Expec_Scope : Entity_Id;
20708 Found_Scope : Entity_Id;
20711 Expec_Scope := Expec_Type;
20712 Found_Scope := Found_Type;
20714 for Levels in Nat range 0 .. 3 loop
20715 if Chars (Expec_Scope) /= Chars (Found_Scope) then
20716 Error_Msg_Qual_Level := Levels;
20720 Expec_Scope := Scope (Expec_Scope);
20721 Found_Scope := Scope (Found_Scope);
20723 exit when Expec_Scope = Standard_Standard
20724 or else Found_Scope = Standard_Standard
20725 or else not Comes_From_Source (Expec_Scope)
20726 or else not Comes_From_Source (Found_Scope);
20730 if Is_Record_Type (Expec_Type)
20731 and then Present (Corresponding_Remote_Type (Expec_Type))
20733 Error_Msg_NE ("expected}!", Expr,
20734 Corresponding_Remote_Type (Expec_Type));
20736 Error_Msg_NE ("expected}!", Expr, Expec_Type);
20739 if Is_Entity_Name (Expr)
20740 and then Is_Package_Or_Generic_Package (Entity (Expr))
20742 Error_Msg_N ("\\found package name!", Expr);
20744 elsif Is_Entity_Name (Expr)
20745 and then Ekind_In (Entity (Expr), E_Procedure, E_Generic_Procedure)
20747 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
20749 ("found procedure name, possibly missing Access attribute!",
20753 ("\\found procedure name instead of function!", Expr);
20756 elsif Nkind (Expr) = N_Function_Call
20757 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
20758 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
20759 and then No (Parameter_Associations (Expr))
20762 ("found function name, possibly missing Access attribute!",
20765 -- Catch common error: a prefix or infix operator which is not
20766 -- directly visible because the type isn't.
20768 elsif Nkind (Expr) in N_Op
20769 and then Is_Overloaded (Expr)
20770 and then not Is_Immediately_Visible (Expec_Type)
20771 and then not Is_Potentially_Use_Visible (Expec_Type)
20772 and then not In_Use (Expec_Type)
20773 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
20776 ("operator of the type is not directly visible!", Expr);
20778 elsif Ekind (Found_Type) = E_Void
20779 and then Present (Parent (Found_Type))
20780 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
20782 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
20785 Error_Msg_NE ("\\found}!", Expr, Found_Type);
20788 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
20789 -- of the same modular type, and (M1 and M2) = 0 was intended.
20791 if Expec_Type = Standard_Boolean
20792 and then Is_Modular_Integer_Type (Found_Type)
20793 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
20794 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
20797 Op : constant Node_Id := Right_Opnd (Parent (Expr));
20798 L : constant Node_Id := Left_Opnd (Op);
20799 R : constant Node_Id := Right_Opnd (Op);
20802 -- The case for the message is when the left operand of the
20803 -- comparison is the same modular type, or when it is an
20804 -- integer literal (or other universal integer expression),
20805 -- which would have been typed as the modular type if the
20806 -- parens had been there.
20808 if (Etype (L) = Found_Type
20810 Etype (L) = Universal_Integer)
20811 and then Is_Integer_Type (Etype (R))
20814 ("\\possible missing parens for modular operation", Expr);
20819 -- Reset error message qualification indication
20821 Error_Msg_Qual_Level := 0;
20825 --------------------------------
20826 -- Yields_Synchronized_Object --
20827 --------------------------------
20829 function Yields_Synchronized_Object (Typ : Entity_Id) return Boolean is
20830 Has_Sync_Comp : Boolean := False;
20834 -- An array type yields a synchronized object if its component type
20835 -- yields a synchronized object.
20837 if Is_Array_Type (Typ) then
20838 return Yields_Synchronized_Object (Component_Type (Typ));
20840 -- A descendant of type Ada.Synchronous_Task_Control.Suspension_Object
20841 -- yields a synchronized object by default.
20843 elsif Is_Descendant_Of_Suspension_Object (Typ) then
20846 -- A protected type yields a synchronized object by default
20848 elsif Is_Protected_Type (Typ) then
20851 -- A record type or type extension yields a synchronized object when its
20852 -- discriminants (if any) lack default values and all components are of
20853 -- a type that yelds a synchronized object.
20855 elsif Is_Record_Type (Typ) then
20857 -- Inspect all entities defined in the scope of the type, looking for
20858 -- components of a type that does not yeld a synchronized object or
20859 -- for discriminants with default values.
20861 Id := First_Entity (Typ);
20862 while Present (Id) loop
20863 if Comes_From_Source (Id) then
20864 if Ekind (Id) = E_Component then
20865 if Yields_Synchronized_Object (Etype (Id)) then
20866 Has_Sync_Comp := True;
20868 -- The component does not yield a synchronized object
20874 elsif Ekind (Id) = E_Discriminant
20875 and then Present (Expression (Parent (Id)))
20884 -- Ensure that the parent type of a type extension yields a
20885 -- synchronized object.
20887 if Etype (Typ) /= Typ
20888 and then not Yields_Synchronized_Object (Etype (Typ))
20893 -- If we get here, then all discriminants lack default values and all
20894 -- components are of a type that yields a synchronized object.
20896 return Has_Sync_Comp;
20898 -- A synchronized interface type yields a synchronized object by default
20900 elsif Is_Synchronized_Interface (Typ) then
20903 -- A task type yelds a synchronized object by default
20905 elsif Is_Task_Type (Typ) then
20908 -- Otherwise the type does not yield a synchronized object
20913 end Yields_Synchronized_Object;