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_Descendent_Of_Address (T1)
276 and then Is_Private_Type (T1)
277 and then Is_Integer_Type (T2))
279 (Is_Descendent_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 -- Append_Inherited_Subprogram --
439 ---------------------------------
441 procedure Append_Inherited_Subprogram (S : Entity_Id) is
442 Par : constant Entity_Id := Alias (S);
443 -- The parent subprogram
445 Scop : constant Entity_Id := Scope (Par);
446 -- The scope of definition of the parent subprogram
448 Typ : constant Entity_Id := Defining_Entity (Parent (S));
449 -- The derived type of which S is a primitive operation
455 if Ekind (Current_Scope) = E_Package
456 and then In_Private_Part (Current_Scope)
457 and then Has_Private_Declaration (Typ)
458 and then Is_Tagged_Type (Typ)
459 and then Scop = Current_Scope
461 -- The inherited operation is available at the earliest place after
462 -- the derived type declaration ( RM 7.3.1 (6/1)). This is only
463 -- relevant for type extensions. If the parent operation appears
464 -- after the type extension, the operation is not visible.
467 (Visible_Declarations
468 (Package_Specification (Current_Scope)));
469 while Present (Decl) loop
470 if Nkind (Decl) = N_Private_Extension_Declaration
471 and then Defining_Entity (Decl) = Typ
473 if Sloc (Decl) > Sloc (Par) then
474 Next_E := Next_Entity (Par);
475 Set_Next_Entity (Par, S);
476 Set_Next_Entity (S, Next_E);
488 -- If partial view is not a type extension, or it appears before the
489 -- subprogram declaration, insert normally at end of entity list.
491 Append_Entity (S, Current_Scope);
492 end Append_Inherited_Subprogram;
494 -----------------------------------------
495 -- Apply_Compile_Time_Constraint_Error --
496 -----------------------------------------
498 procedure Apply_Compile_Time_Constraint_Error
501 Reason : RT_Exception_Code;
502 Ent : Entity_Id := Empty;
503 Typ : Entity_Id := Empty;
504 Loc : Source_Ptr := No_Location;
505 Rep : Boolean := True;
506 Warn : Boolean := False)
508 Stat : constant Boolean := Is_Static_Expression (N);
509 R_Stat : constant Node_Id :=
510 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
521 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
527 -- Now we replace the node by an N_Raise_Constraint_Error node
528 -- This does not need reanalyzing, so set it as analyzed now.
531 Set_Analyzed (N, True);
534 Set_Raises_Constraint_Error (N);
536 -- Now deal with possible local raise handling
538 Possible_Local_Raise (N, Standard_Constraint_Error);
540 -- If the original expression was marked as static, the result is
541 -- still marked as static, but the Raises_Constraint_Error flag is
542 -- always set so that further static evaluation is not attempted.
545 Set_Is_Static_Expression (N);
547 end Apply_Compile_Time_Constraint_Error;
549 ---------------------------
550 -- Async_Readers_Enabled --
551 ---------------------------
553 function Async_Readers_Enabled (Id : Entity_Id) return Boolean is
555 return Has_Enabled_Property (Id, Name_Async_Readers);
556 end Async_Readers_Enabled;
558 ---------------------------
559 -- Async_Writers_Enabled --
560 ---------------------------
562 function Async_Writers_Enabled (Id : Entity_Id) return Boolean is
564 return Has_Enabled_Property (Id, Name_Async_Writers);
565 end Async_Writers_Enabled;
567 --------------------------------------
568 -- Available_Full_View_Of_Component --
569 --------------------------------------
571 function Available_Full_View_Of_Component (T : Entity_Id) return Boolean is
572 ST : constant Entity_Id := Scope (T);
573 SCT : constant Entity_Id := Scope (Component_Type (T));
575 return In_Open_Scopes (ST)
576 and then In_Open_Scopes (SCT)
577 and then Scope_Depth (ST) >= Scope_Depth (SCT);
578 end Available_Full_View_Of_Component;
584 procedure Bad_Attribute
587 Warn : Boolean := False)
590 Error_Msg_Warn := Warn;
591 Error_Msg_N ("unrecognized attribute&<<", N);
593 -- Check for possible misspelling
595 Error_Msg_Name_1 := First_Attribute_Name;
596 while Error_Msg_Name_1 <= Last_Attribute_Name loop
597 if Is_Bad_Spelling_Of (Nam, Error_Msg_Name_1) then
598 Error_Msg_N -- CODEFIX
599 ("\possible misspelling of %<<", N);
603 Error_Msg_Name_1 := Error_Msg_Name_1 + 1;
607 --------------------------------
608 -- Bad_Predicated_Subtype_Use --
609 --------------------------------
611 procedure Bad_Predicated_Subtype_Use
615 Suggest_Static : Boolean := False)
620 -- Avoid cascaded errors
622 if Error_Posted (N) then
626 if Inside_A_Generic then
627 Gen := Current_Scope;
628 while Present (Gen) and then Ekind (Gen) /= E_Generic_Package loop
636 if Is_Generic_Formal (Typ) and then Is_Discrete_Type (Typ) then
637 Set_No_Predicate_On_Actual (Typ);
640 elsif Has_Predicates (Typ) then
641 if Is_Generic_Actual_Type (Typ) then
643 -- The restriction on loop parameters is only that the type
644 -- should have no dynamic predicates.
646 if Nkind (Parent (N)) = N_Loop_Parameter_Specification
647 and then not Has_Dynamic_Predicate_Aspect (Typ)
648 and then Is_OK_Static_Subtype (Typ)
653 Gen := Current_Scope;
654 while not Is_Generic_Instance (Gen) loop
658 pragma Assert (Present (Gen));
660 if Ekind (Gen) = E_Package and then In_Package_Body (Gen) then
661 Error_Msg_Warn := SPARK_Mode /= On;
662 Error_Msg_FE (Msg & "<<", N, Typ);
663 Error_Msg_F ("\Program_Error [<<", N);
666 Make_Raise_Program_Error (Sloc (N),
667 Reason => PE_Bad_Predicated_Generic_Type));
670 Error_Msg_FE (Msg & "<<", N, Typ);
674 Error_Msg_FE (Msg, N, Typ);
677 -- Emit an optional suggestion on how to remedy the error if the
678 -- context warrants it.
680 if Suggest_Static and then Has_Static_Predicate (Typ) then
681 Error_Msg_FE ("\predicate of & should be marked static", N, Typ);
684 end Bad_Predicated_Subtype_Use;
686 -----------------------------------------
687 -- Bad_Unordered_Enumeration_Reference --
688 -----------------------------------------
690 function Bad_Unordered_Enumeration_Reference
692 T : Entity_Id) return Boolean
695 return Is_Enumeration_Type (T)
696 and then Warn_On_Unordered_Enumeration_Type
697 and then not Is_Generic_Type (T)
698 and then Comes_From_Source (N)
699 and then not Has_Pragma_Ordered (T)
700 and then not In_Same_Extended_Unit (N, T);
701 end Bad_Unordered_Enumeration_Reference;
703 --------------------------
704 -- Build_Actual_Subtype --
705 --------------------------
707 function Build_Actual_Subtype
709 N : Node_Or_Entity_Id) return Node_Id
712 -- Normally Sloc (N), but may point to corresponding body in some cases
714 Constraints : List_Id;
720 Disc_Type : Entity_Id;
726 if Nkind (N) = N_Defining_Identifier then
727 Obj := New_Occurrence_Of (N, Loc);
729 -- If this is a formal parameter of a subprogram declaration, and
730 -- we are compiling the body, we want the declaration for the
731 -- actual subtype to carry the source position of the body, to
732 -- prevent anomalies in gdb when stepping through the code.
734 if Is_Formal (N) then
736 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
738 if Nkind (Decl) = N_Subprogram_Declaration
739 and then Present (Corresponding_Body (Decl))
741 Loc := Sloc (Corresponding_Body (Decl));
750 if Is_Array_Type (T) then
751 Constraints := New_List;
752 for J in 1 .. Number_Dimensions (T) loop
754 -- Build an array subtype declaration with the nominal subtype and
755 -- the bounds of the actual. Add the declaration in front of the
756 -- local declarations for the subprogram, for analysis before any
757 -- reference to the formal in the body.
760 Make_Attribute_Reference (Loc,
762 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
763 Attribute_Name => Name_First,
764 Expressions => New_List (
765 Make_Integer_Literal (Loc, J)));
768 Make_Attribute_Reference (Loc,
770 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
771 Attribute_Name => Name_Last,
772 Expressions => New_List (
773 Make_Integer_Literal (Loc, J)));
775 Append (Make_Range (Loc, Lo, Hi), Constraints);
778 -- If the type has unknown discriminants there is no constrained
779 -- subtype to build. This is never called for a formal or for a
780 -- lhs, so returning the type is ok ???
782 elsif Has_Unknown_Discriminants (T) then
786 Constraints := New_List;
788 -- Type T is a generic derived type, inherit the discriminants from
791 if Is_Private_Type (T)
792 and then No (Full_View (T))
794 -- T was flagged as an error if it was declared as a formal
795 -- derived type with known discriminants. In this case there
796 -- is no need to look at the parent type since T already carries
797 -- its own discriminants.
799 and then not Error_Posted (T)
801 Disc_Type := Etype (Base_Type (T));
806 Discr := First_Discriminant (Disc_Type);
807 while Present (Discr) loop
808 Append_To (Constraints,
809 Make_Selected_Component (Loc,
811 Duplicate_Subexpr_No_Checks (Obj),
812 Selector_Name => New_Occurrence_Of (Discr, Loc)));
813 Next_Discriminant (Discr);
817 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
818 Set_Is_Internal (Subt);
821 Make_Subtype_Declaration (Loc,
822 Defining_Identifier => Subt,
823 Subtype_Indication =>
824 Make_Subtype_Indication (Loc,
825 Subtype_Mark => New_Occurrence_Of (T, Loc),
827 Make_Index_Or_Discriminant_Constraint (Loc,
828 Constraints => Constraints)));
830 Mark_Rewrite_Insertion (Decl);
832 end Build_Actual_Subtype;
834 ---------------------------------------
835 -- Build_Actual_Subtype_Of_Component --
836 ---------------------------------------
838 function Build_Actual_Subtype_Of_Component
840 N : Node_Id) return Node_Id
842 Loc : constant Source_Ptr := Sloc (N);
843 P : constant Node_Id := Prefix (N);
846 Index_Typ : Entity_Id;
848 Desig_Typ : Entity_Id;
849 -- This is either a copy of T, or if T is an access type, then it is
850 -- the directly designated type of this access type.
852 function Build_Actual_Array_Constraint return List_Id;
853 -- If one or more of the bounds of the component depends on
854 -- discriminants, build actual constraint using the discriminants
857 function Build_Actual_Record_Constraint return List_Id;
858 -- Similar to previous one, for discriminated components constrained
859 -- by the discriminant of the enclosing object.
861 -----------------------------------
862 -- Build_Actual_Array_Constraint --
863 -----------------------------------
865 function Build_Actual_Array_Constraint return List_Id is
866 Constraints : constant List_Id := New_List;
874 Indx := First_Index (Desig_Typ);
875 while Present (Indx) loop
876 Old_Lo := Type_Low_Bound (Etype (Indx));
877 Old_Hi := Type_High_Bound (Etype (Indx));
879 if Denotes_Discriminant (Old_Lo) then
881 Make_Selected_Component (Loc,
882 Prefix => New_Copy_Tree (P),
883 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
886 Lo := New_Copy_Tree (Old_Lo);
888 -- The new bound will be reanalyzed in the enclosing
889 -- declaration. For literal bounds that come from a type
890 -- declaration, the type of the context must be imposed, so
891 -- insure that analysis will take place. For non-universal
892 -- types this is not strictly necessary.
894 Set_Analyzed (Lo, False);
897 if Denotes_Discriminant (Old_Hi) then
899 Make_Selected_Component (Loc,
900 Prefix => New_Copy_Tree (P),
901 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
904 Hi := New_Copy_Tree (Old_Hi);
905 Set_Analyzed (Hi, False);
908 Append (Make_Range (Loc, Lo, Hi), Constraints);
913 end Build_Actual_Array_Constraint;
915 ------------------------------------
916 -- Build_Actual_Record_Constraint --
917 ------------------------------------
919 function Build_Actual_Record_Constraint return List_Id is
920 Constraints : constant List_Id := New_List;
925 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
926 while Present (D) loop
927 if Denotes_Discriminant (Node (D)) then
928 D_Val := Make_Selected_Component (Loc,
929 Prefix => New_Copy_Tree (P),
930 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
933 D_Val := New_Copy_Tree (Node (D));
936 Append (D_Val, Constraints);
941 end Build_Actual_Record_Constraint;
943 -- Start of processing for Build_Actual_Subtype_Of_Component
946 -- Why the test for Spec_Expression mode here???
948 if In_Spec_Expression then
951 -- More comments for the rest of this body would be good ???
953 elsif Nkind (N) = N_Explicit_Dereference then
954 if Is_Composite_Type (T)
955 and then not Is_Constrained (T)
956 and then not (Is_Class_Wide_Type (T)
957 and then Is_Constrained (Root_Type (T)))
958 and then not Has_Unknown_Discriminants (T)
960 -- If the type of the dereference is already constrained, it is an
963 if Is_Array_Type (Etype (N))
964 and then Is_Constrained (Etype (N))
968 Remove_Side_Effects (P);
969 return Build_Actual_Subtype (T, N);
976 if Ekind (T) = E_Access_Subtype then
977 Desig_Typ := Designated_Type (T);
982 if Ekind (Desig_Typ) = E_Array_Subtype then
983 Id := First_Index (Desig_Typ);
984 while Present (Id) loop
985 Index_Typ := Underlying_Type (Etype (Id));
987 if Denotes_Discriminant (Type_Low_Bound (Index_Typ))
989 Denotes_Discriminant (Type_High_Bound (Index_Typ))
991 Remove_Side_Effects (P);
993 Build_Component_Subtype
994 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
1000 elsif Is_Composite_Type (Desig_Typ)
1001 and then Has_Discriminants (Desig_Typ)
1002 and then not Has_Unknown_Discriminants (Desig_Typ)
1004 if Is_Private_Type (Desig_Typ)
1005 and then No (Discriminant_Constraint (Desig_Typ))
1007 Desig_Typ := Full_View (Desig_Typ);
1010 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1011 while Present (D) loop
1012 if Denotes_Discriminant (Node (D)) then
1013 Remove_Side_Effects (P);
1015 Build_Component_Subtype (
1016 Build_Actual_Record_Constraint, Loc, Base_Type (T));
1023 -- If none of the above, the actual and nominal subtypes are the same
1026 end Build_Actual_Subtype_Of_Component;
1028 -----------------------------
1029 -- Build_Component_Subtype --
1030 -----------------------------
1032 function Build_Component_Subtype
1035 T : Entity_Id) return Node_Id
1041 -- Unchecked_Union components do not require component subtypes
1043 if Is_Unchecked_Union (T) then
1047 Subt := Make_Temporary (Loc, 'S');
1048 Set_Is_Internal (Subt);
1051 Make_Subtype_Declaration (Loc,
1052 Defining_Identifier => Subt,
1053 Subtype_Indication =>
1054 Make_Subtype_Indication (Loc,
1055 Subtype_Mark => New_Occurrence_Of (Base_Type (T), Loc),
1057 Make_Index_Or_Discriminant_Constraint (Loc,
1058 Constraints => C)));
1060 Mark_Rewrite_Insertion (Decl);
1062 end Build_Component_Subtype;
1064 ----------------------------------
1065 -- Build_Default_Init_Cond_Call --
1066 ----------------------------------
1068 function Build_Default_Init_Cond_Call
1071 Typ : Entity_Id) return Node_Id
1073 Proc_Id : constant Entity_Id := Default_Init_Cond_Procedure (Typ);
1074 Formal_Typ : constant Entity_Id := Etype (First_Formal (Proc_Id));
1078 Make_Procedure_Call_Statement (Loc,
1079 Name => New_Occurrence_Of (Proc_Id, Loc),
1080 Parameter_Associations => New_List (
1081 Make_Unchecked_Type_Conversion (Loc,
1082 Subtype_Mark => New_Occurrence_Of (Formal_Typ, Loc),
1083 Expression => New_Occurrence_Of (Obj_Id, Loc))));
1084 end Build_Default_Init_Cond_Call;
1086 ----------------------------------------------
1087 -- Build_Default_Init_Cond_Procedure_Bodies --
1088 ----------------------------------------------
1090 procedure Build_Default_Init_Cond_Procedure_Bodies (Priv_Decls : List_Id) is
1091 procedure Build_Default_Init_Cond_Procedure_Body (Typ : Entity_Id);
1092 -- If type Typ is subject to pragma Default_Initial_Condition, build the
1093 -- body of the procedure which verifies the assumption of the pragma at
1094 -- run time. The generated body is added after the type declaration.
1096 --------------------------------------------
1097 -- Build_Default_Init_Cond_Procedure_Body --
1098 --------------------------------------------
1100 procedure Build_Default_Init_Cond_Procedure_Body (Typ : Entity_Id) is
1101 Param_Id : Entity_Id;
1102 -- The entity of the sole formal parameter of the default initial
1103 -- condition procedure.
1105 procedure Replace_Type_Reference (N : Node_Id);
1106 -- Replace a single reference to type Typ with a reference to formal
1107 -- parameter Param_Id.
1109 ----------------------------
1110 -- Replace_Type_Reference --
1111 ----------------------------
1113 procedure Replace_Type_Reference (N : Node_Id) is
1115 Rewrite (N, New_Occurrence_Of (Param_Id, Sloc (N)));
1116 end Replace_Type_Reference;
1118 procedure Replace_Type_References is
1119 new Replace_Type_References_Generic (Replace_Type_Reference);
1123 Loc : constant Source_Ptr := Sloc (Typ);
1124 Prag : constant Node_Id :=
1125 Get_Pragma (Typ, Pragma_Default_Initial_Condition);
1126 Proc_Id : constant Entity_Id := Default_Init_Cond_Procedure (Typ);
1127 Spec_Decl : constant Node_Id := Unit_Declaration_Node (Proc_Id);
1128 Body_Decl : Node_Id;
1132 Save_Ghost_Mode : constant Ghost_Mode_Type := Ghost_Mode;
1134 -- Start of processing for Build_Default_Init_Cond_Procedure_Body
1137 -- The procedure should be generated only for [sub]types subject to
1138 -- pragma Default_Initial_Condition. Types that inherit the pragma do
1139 -- not get this specialized procedure.
1141 pragma Assert (Has_Default_Init_Cond (Typ));
1142 pragma Assert (Present (Prag));
1143 pragma Assert (Present (Proc_Id));
1145 -- Nothing to do if the body was already built
1147 if Present (Corresponding_Body (Spec_Decl)) then
1151 -- The related type may be subject to pragma Ghost. Set the mode now
1152 -- to ensure that the analysis and expansion produce Ghost nodes.
1154 Set_Ghost_Mode_From_Entity (Typ);
1156 Param_Id := First_Formal (Proc_Id);
1158 -- The pragma has an argument. Note that the argument is analyzed
1159 -- after all references to the current instance of the type are
1162 if Present (Pragma_Argument_Associations (Prag)) then
1164 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
1166 if Nkind (Expr) = N_Null then
1167 Stmt := Make_Null_Statement (Loc);
1169 -- Preserve the original argument of the pragma by replicating it.
1170 -- Replace all references to the current instance of the type with
1171 -- references to the formal parameter.
1174 Expr := New_Copy_Tree (Expr);
1175 Replace_Type_References (Expr, Typ);
1178 -- pragma Check (Default_Initial_Condition, <Expr>);
1182 Pragma_Identifier =>
1183 Make_Identifier (Loc, Name_Check),
1185 Pragma_Argument_Associations => New_List (
1186 Make_Pragma_Argument_Association (Loc,
1188 Make_Identifier (Loc,
1189 Chars => Name_Default_Initial_Condition)),
1190 Make_Pragma_Argument_Association (Loc,
1191 Expression => Expr)));
1194 -- Otherwise the pragma appears without an argument
1197 Stmt := Make_Null_Statement (Loc);
1201 -- procedure <Typ>Default_Init_Cond (I : <Typ>) is
1204 -- end <Typ>Default_Init_Cond;
1207 Make_Subprogram_Body (Loc,
1209 Copy_Separate_Tree (Specification (Spec_Decl)),
1210 Declarations => Empty_List,
1211 Handled_Statement_Sequence =>
1212 Make_Handled_Sequence_Of_Statements (Loc,
1213 Statements => New_List (Stmt)));
1215 -- Link the spec and body of the default initial condition procedure
1216 -- to prevent the generation of a duplicate body.
1218 Set_Corresponding_Body (Spec_Decl, Defining_Entity (Body_Decl));
1219 Set_Corresponding_Spec (Body_Decl, Proc_Id);
1221 Insert_After_And_Analyze (Declaration_Node (Typ), Body_Decl);
1222 Ghost_Mode := Save_Ghost_Mode;
1223 end Build_Default_Init_Cond_Procedure_Body;
1230 -- Start of processing for Build_Default_Init_Cond_Procedure_Bodies
1233 -- Inspect the private declarations looking for [sub]type declarations
1235 Decl := First (Priv_Decls);
1236 while Present (Decl) loop
1237 if Nkind_In (Decl, N_Full_Type_Declaration,
1238 N_Subtype_Declaration)
1240 Typ := Defining_Entity (Decl);
1242 -- Guard against partially decorate types due to previous errors
1244 if Is_Type (Typ) then
1246 -- If the type is subject to pragma Default_Initial_Condition,
1247 -- generate the body of the internal procedure which verifies
1248 -- the assertion of the pragma at run time.
1250 if Has_Default_Init_Cond (Typ) then
1251 Build_Default_Init_Cond_Procedure_Body (Typ);
1253 -- A derived type inherits the default initial condition
1254 -- procedure from its parent type.
1256 elsif Has_Inherited_Default_Init_Cond (Typ) then
1257 Inherit_Default_Init_Cond_Procedure (Typ);
1264 end Build_Default_Init_Cond_Procedure_Bodies;
1266 ---------------------------------------------------
1267 -- Build_Default_Init_Cond_Procedure_Declaration --
1268 ---------------------------------------------------
1270 procedure Build_Default_Init_Cond_Procedure_Declaration (Typ : Entity_Id) is
1271 Loc : constant Source_Ptr := Sloc (Typ);
1272 Prag : constant Node_Id :=
1273 Get_Pragma (Typ, Pragma_Default_Initial_Condition);
1275 Save_Ghost_Mode : constant Ghost_Mode_Type := Ghost_Mode;
1277 Proc_Id : Entity_Id;
1280 -- The procedure should be generated only for types subject to pragma
1281 -- Default_Initial_Condition. Types that inherit the pragma do not get
1282 -- this specialized procedure.
1284 pragma Assert (Has_Default_Init_Cond (Typ));
1285 pragma Assert (Present (Prag));
1287 -- Nothing to do if default initial condition procedure already built
1289 if Present (Default_Init_Cond_Procedure (Typ)) then
1293 -- The related type may be subject to pragma Ghost. Set the mode now to
1294 -- ensure that the analysis and expansion produce Ghost nodes.
1296 Set_Ghost_Mode_From_Entity (Typ);
1299 Make_Defining_Identifier (Loc,
1300 Chars => New_External_Name (Chars (Typ), "Default_Init_Cond"));
1302 -- Associate default initial condition procedure with the private type
1304 Set_Ekind (Proc_Id, E_Procedure);
1305 Set_Is_Default_Init_Cond_Procedure (Proc_Id);
1306 Set_Default_Init_Cond_Procedure (Typ, Proc_Id);
1308 -- Mark the default initial condition procedure explicitly as Ghost
1309 -- because it does not come from source.
1311 if Ghost_Mode > None then
1312 Set_Is_Ghost_Entity (Proc_Id);
1316 -- procedure <Typ>Default_Init_Cond (Inn : <Typ>);
1318 Insert_After_And_Analyze (Prag,
1319 Make_Subprogram_Declaration (Loc,
1321 Make_Procedure_Specification (Loc,
1322 Defining_Unit_Name => Proc_Id,
1323 Parameter_Specifications => New_List (
1324 Make_Parameter_Specification (Loc,
1325 Defining_Identifier => Make_Temporary (Loc, 'I'),
1326 Parameter_Type => New_Occurrence_Of (Typ, Loc))))));
1328 Ghost_Mode := Save_Ghost_Mode;
1329 end Build_Default_Init_Cond_Procedure_Declaration;
1331 ---------------------------
1332 -- Build_Default_Subtype --
1333 ---------------------------
1335 function Build_Default_Subtype
1337 N : Node_Id) return Entity_Id
1339 Loc : constant Source_Ptr := Sloc (N);
1343 -- The base type that is to be constrained by the defaults
1346 if not Has_Discriminants (T) or else Is_Constrained (T) then
1350 Bas := Base_Type (T);
1352 -- If T is non-private but its base type is private, this is the
1353 -- completion of a subtype declaration whose parent type is private
1354 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1355 -- are to be found in the full view of the base. Check that the private
1356 -- status of T and its base differ.
1358 if Is_Private_Type (Bas)
1359 and then not Is_Private_Type (T)
1360 and then Present (Full_View (Bas))
1362 Bas := Full_View (Bas);
1365 Disc := First_Discriminant (T);
1367 if No (Discriminant_Default_Value (Disc)) then
1372 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
1373 Constraints : constant List_Id := New_List;
1377 while Present (Disc) loop
1378 Append_To (Constraints,
1379 New_Copy_Tree (Discriminant_Default_Value (Disc)));
1380 Next_Discriminant (Disc);
1384 Make_Subtype_Declaration (Loc,
1385 Defining_Identifier => Act,
1386 Subtype_Indication =>
1387 Make_Subtype_Indication (Loc,
1388 Subtype_Mark => New_Occurrence_Of (Bas, Loc),
1390 Make_Index_Or_Discriminant_Constraint (Loc,
1391 Constraints => Constraints)));
1393 Insert_Action (N, Decl);
1395 -- If the context is a component declaration the subtype declaration
1396 -- will be analyzed when the enclosing type is frozen, otherwise do
1399 if Ekind (Current_Scope) /= E_Record_Type then
1405 end Build_Default_Subtype;
1407 --------------------------------------------
1408 -- Build_Discriminal_Subtype_Of_Component --
1409 --------------------------------------------
1411 function Build_Discriminal_Subtype_Of_Component
1412 (T : Entity_Id) return Node_Id
1414 Loc : constant Source_Ptr := Sloc (T);
1418 function Build_Discriminal_Array_Constraint return List_Id;
1419 -- If one or more of the bounds of the component depends on
1420 -- discriminants, build actual constraint using the discriminants
1423 function Build_Discriminal_Record_Constraint return List_Id;
1424 -- Similar to previous one, for discriminated components constrained by
1425 -- the discriminant of the enclosing object.
1427 ----------------------------------------
1428 -- Build_Discriminal_Array_Constraint --
1429 ----------------------------------------
1431 function Build_Discriminal_Array_Constraint return List_Id is
1432 Constraints : constant List_Id := New_List;
1440 Indx := First_Index (T);
1441 while Present (Indx) loop
1442 Old_Lo := Type_Low_Bound (Etype (Indx));
1443 Old_Hi := Type_High_Bound (Etype (Indx));
1445 if Denotes_Discriminant (Old_Lo) then
1446 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
1449 Lo := New_Copy_Tree (Old_Lo);
1452 if Denotes_Discriminant (Old_Hi) then
1453 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
1456 Hi := New_Copy_Tree (Old_Hi);
1459 Append (Make_Range (Loc, Lo, Hi), Constraints);
1464 end Build_Discriminal_Array_Constraint;
1466 -----------------------------------------
1467 -- Build_Discriminal_Record_Constraint --
1468 -----------------------------------------
1470 function Build_Discriminal_Record_Constraint return List_Id is
1471 Constraints : constant List_Id := New_List;
1476 D := First_Elmt (Discriminant_Constraint (T));
1477 while Present (D) loop
1478 if Denotes_Discriminant (Node (D)) then
1480 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
1482 D_Val := New_Copy_Tree (Node (D));
1485 Append (D_Val, Constraints);
1490 end Build_Discriminal_Record_Constraint;
1492 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1495 if Ekind (T) = E_Array_Subtype then
1496 Id := First_Index (T);
1497 while Present (Id) loop
1498 if Denotes_Discriminant (Type_Low_Bound (Etype (Id)))
1500 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
1502 return Build_Component_Subtype
1503 (Build_Discriminal_Array_Constraint, Loc, T);
1509 elsif Ekind (T) = E_Record_Subtype
1510 and then Has_Discriminants (T)
1511 and then not Has_Unknown_Discriminants (T)
1513 D := First_Elmt (Discriminant_Constraint (T));
1514 while Present (D) loop
1515 if Denotes_Discriminant (Node (D)) then
1516 return Build_Component_Subtype
1517 (Build_Discriminal_Record_Constraint, Loc, T);
1524 -- If none of the above, the actual and nominal subtypes are the same
1527 end Build_Discriminal_Subtype_Of_Component;
1529 ------------------------------
1530 -- Build_Elaboration_Entity --
1531 ------------------------------
1533 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
1534 Loc : constant Source_Ptr := Sloc (N);
1536 Elab_Ent : Entity_Id;
1538 procedure Set_Package_Name (Ent : Entity_Id);
1539 -- Given an entity, sets the fully qualified name of the entity in
1540 -- Name_Buffer, with components separated by double underscores. This
1541 -- is a recursive routine that climbs the scope chain to Standard.
1543 ----------------------
1544 -- Set_Package_Name --
1545 ----------------------
1547 procedure Set_Package_Name (Ent : Entity_Id) is
1549 if Scope (Ent) /= Standard_Standard then
1550 Set_Package_Name (Scope (Ent));
1553 Nam : constant String := Get_Name_String (Chars (Ent));
1555 Name_Buffer (Name_Len + 1) := '_';
1556 Name_Buffer (Name_Len + 2) := '_';
1557 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
1558 Name_Len := Name_Len + Nam'Length + 2;
1562 Get_Name_String (Chars (Ent));
1564 end Set_Package_Name;
1566 -- Start of processing for Build_Elaboration_Entity
1569 -- Ignore call if already constructed
1571 if Present (Elaboration_Entity (Spec_Id)) then
1574 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1575 -- no role in analysis.
1577 elsif ASIS_Mode then
1580 -- See if we need elaboration entity. We always need it for the dynamic
1581 -- elaboration model, since it is needed to properly generate the PE
1582 -- exception for access before elaboration.
1584 elsif Dynamic_Elaboration_Checks then
1587 -- For the static model, we don't need the elaboration counter if this
1588 -- unit is sure to have no elaboration code, since that means there
1589 -- is no elaboration unit to be called. Note that we can't just decide
1590 -- after the fact by looking to see whether there was elaboration code,
1591 -- because that's too late to make this decision.
1593 elsif Restriction_Active (No_Elaboration_Code) then
1596 -- Similarly, for the static model, we can skip the elaboration counter
1597 -- if we have the No_Multiple_Elaboration restriction, since for the
1598 -- static model, that's the only purpose of the counter (to avoid
1599 -- multiple elaboration).
1601 elsif Restriction_Active (No_Multiple_Elaboration) then
1605 -- Here we need the elaboration entity
1607 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1608 -- name with dots replaced by double underscore. We have to manually
1609 -- construct this name, since it will be elaborated in the outer scope,
1610 -- and thus will not have the unit name automatically prepended.
1612 Set_Package_Name (Spec_Id);
1613 Add_Str_To_Name_Buffer ("_E");
1615 -- Create elaboration counter
1617 Elab_Ent := Make_Defining_Identifier (Loc, Chars => Name_Find);
1618 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
1621 Make_Object_Declaration (Loc,
1622 Defining_Identifier => Elab_Ent,
1623 Object_Definition =>
1624 New_Occurrence_Of (Standard_Short_Integer, Loc),
1625 Expression => Make_Integer_Literal (Loc, Uint_0));
1627 Push_Scope (Standard_Standard);
1628 Add_Global_Declaration (Decl);
1631 -- Reset True_Constant indication, since we will indeed assign a value
1632 -- to the variable in the binder main. We also kill the Current_Value
1633 -- and Last_Assignment fields for the same reason.
1635 Set_Is_True_Constant (Elab_Ent, False);
1636 Set_Current_Value (Elab_Ent, Empty);
1637 Set_Last_Assignment (Elab_Ent, Empty);
1639 -- We do not want any further qualification of the name (if we did not
1640 -- do this, we would pick up the name of the generic package in the case
1641 -- of a library level generic instantiation).
1643 Set_Has_Qualified_Name (Elab_Ent);
1644 Set_Has_Fully_Qualified_Name (Elab_Ent);
1645 end Build_Elaboration_Entity;
1647 --------------------------------
1648 -- Build_Explicit_Dereference --
1649 --------------------------------
1651 procedure Build_Explicit_Dereference
1655 Loc : constant Source_Ptr := Sloc (Expr);
1658 -- An entity of a type with a reference aspect is overloaded with
1659 -- both interpretations: with and without the dereference. Now that
1660 -- the dereference is made explicit, set the type of the node properly,
1661 -- to prevent anomalies in the backend. Same if the expression is an
1662 -- overloaded function call whose return type has a reference aspect.
1664 if Is_Entity_Name (Expr) then
1665 Set_Etype (Expr, Etype (Entity (Expr)));
1667 elsif Nkind (Expr) = N_Function_Call then
1668 Set_Etype (Expr, Etype (Name (Expr)));
1671 Set_Is_Overloaded (Expr, False);
1673 -- The expression will often be a generalized indexing that yields a
1674 -- container element that is then dereferenced, in which case the
1675 -- generalized indexing call is also non-overloaded.
1677 if Nkind (Expr) = N_Indexed_Component
1678 and then Present (Generalized_Indexing (Expr))
1680 Set_Is_Overloaded (Generalized_Indexing (Expr), False);
1684 Make_Explicit_Dereference (Loc,
1686 Make_Selected_Component (Loc,
1687 Prefix => Relocate_Node (Expr),
1688 Selector_Name => New_Occurrence_Of (Disc, Loc))));
1689 Set_Etype (Prefix (Expr), Etype (Disc));
1690 Set_Etype (Expr, Designated_Type (Etype (Disc)));
1691 end Build_Explicit_Dereference;
1693 -----------------------------------
1694 -- Cannot_Raise_Constraint_Error --
1695 -----------------------------------
1697 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
1699 if Compile_Time_Known_Value (Expr) then
1702 elsif Do_Range_Check (Expr) then
1705 elsif Raises_Constraint_Error (Expr) then
1709 case Nkind (Expr) is
1710 when N_Identifier =>
1713 when N_Expanded_Name =>
1716 when N_Selected_Component =>
1717 return not Do_Discriminant_Check (Expr);
1719 when N_Attribute_Reference =>
1720 if Do_Overflow_Check (Expr) then
1723 elsif No (Expressions (Expr)) then
1731 N := First (Expressions (Expr));
1732 while Present (N) loop
1733 if Cannot_Raise_Constraint_Error (N) then
1744 when N_Type_Conversion =>
1745 if Do_Overflow_Check (Expr)
1746 or else Do_Length_Check (Expr)
1747 or else Do_Tag_Check (Expr)
1751 return Cannot_Raise_Constraint_Error (Expression (Expr));
1754 when N_Unchecked_Type_Conversion =>
1755 return Cannot_Raise_Constraint_Error (Expression (Expr));
1758 if Do_Overflow_Check (Expr) then
1761 return Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1768 if Do_Division_Check (Expr)
1770 Do_Overflow_Check (Expr)
1775 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1777 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1796 N_Op_Shift_Right_Arithmetic |
1800 if Do_Overflow_Check (Expr) then
1804 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1806 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1813 end Cannot_Raise_Constraint_Error;
1815 -----------------------------------------
1816 -- Check_Dynamically_Tagged_Expression --
1817 -----------------------------------------
1819 procedure Check_Dynamically_Tagged_Expression
1822 Related_Nod : Node_Id)
1825 pragma Assert (Is_Tagged_Type (Typ));
1827 -- In order to avoid spurious errors when analyzing the expanded code,
1828 -- this check is done only for nodes that come from source and for
1829 -- actuals of generic instantiations.
1831 if (Comes_From_Source (Related_Nod)
1832 or else In_Generic_Actual (Expr))
1833 and then (Is_Class_Wide_Type (Etype (Expr))
1834 or else Is_Dynamically_Tagged (Expr))
1835 and then Is_Tagged_Type (Typ)
1836 and then not Is_Class_Wide_Type (Typ)
1838 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
1840 end Check_Dynamically_Tagged_Expression;
1842 --------------------------
1843 -- Check_Fully_Declared --
1844 --------------------------
1846 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
1848 if Ekind (T) = E_Incomplete_Type then
1850 -- Ada 2005 (AI-50217): If the type is available through a limited
1851 -- with_clause, verify that its full view has been analyzed.
1853 if From_Limited_With (T)
1854 and then Present (Non_Limited_View (T))
1855 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1857 -- The non-limited view is fully declared
1863 ("premature usage of incomplete}", N, First_Subtype (T));
1866 -- Need comments for these tests ???
1868 elsif Has_Private_Component (T)
1869 and then not Is_Generic_Type (Root_Type (T))
1870 and then not In_Spec_Expression
1872 -- Special case: if T is the anonymous type created for a single
1873 -- task or protected object, use the name of the source object.
1875 if Is_Concurrent_Type (T)
1876 and then not Comes_From_Source (T)
1877 and then Nkind (N) = N_Object_Declaration
1880 ("type of& has incomplete component",
1881 N, Defining_Identifier (N));
1884 ("premature usage of incomplete}",
1885 N, First_Subtype (T));
1888 end Check_Fully_Declared;
1890 -------------------------------------------
1891 -- Check_Function_With_Address_Parameter --
1892 -------------------------------------------
1894 procedure Check_Function_With_Address_Parameter (Subp_Id : Entity_Id) is
1899 F := First_Formal (Subp_Id);
1900 while Present (F) loop
1903 if Is_Private_Type (T) and then Present (Full_View (T)) then
1907 if Is_Descendent_Of_Address (T) or else Is_Limited_Type (T) then
1908 Set_Is_Pure (Subp_Id, False);
1914 end Check_Function_With_Address_Parameter;
1916 -------------------------------------
1917 -- Check_Function_Writable_Actuals --
1918 -------------------------------------
1920 procedure Check_Function_Writable_Actuals (N : Node_Id) is
1921 Writable_Actuals_List : Elist_Id := No_Elist;
1922 Identifiers_List : Elist_Id := No_Elist;
1923 Aggr_Error_Node : Node_Id := Empty;
1924 Error_Node : Node_Id := Empty;
1926 procedure Collect_Identifiers (N : Node_Id);
1927 -- In a single traversal of subtree N collect in Writable_Actuals_List
1928 -- all the actuals of functions with writable actuals, and in the list
1929 -- Identifiers_List collect all the identifiers that are not actuals of
1930 -- functions with writable actuals. If a writable actual is referenced
1931 -- twice as writable actual then Error_Node is set to reference its
1932 -- second occurrence, the error is reported, and the tree traversal
1935 function Get_Function_Id (Call : Node_Id) return Entity_Id;
1936 -- Return the entity associated with the function call
1938 procedure Preanalyze_Without_Errors (N : Node_Id);
1939 -- Preanalyze N without reporting errors. Very dubious, you can't just
1940 -- go analyzing things more than once???
1942 -------------------------
1943 -- Collect_Identifiers --
1944 -------------------------
1946 procedure Collect_Identifiers (N : Node_Id) is
1948 function Check_Node (N : Node_Id) return Traverse_Result;
1949 -- Process a single node during the tree traversal to collect the
1950 -- writable actuals of functions and all the identifiers which are
1951 -- not writable actuals of functions.
1953 function Contains (List : Elist_Id; N : Node_Id) return Boolean;
1954 -- Returns True if List has a node whose Entity is Entity (N)
1956 -------------------------
1957 -- Check_Function_Call --
1958 -------------------------
1960 function Check_Node (N : Node_Id) return Traverse_Result is
1961 Is_Writable_Actual : Boolean := False;
1965 if Nkind (N) = N_Identifier then
1967 -- No analysis possible if the entity is not decorated
1969 if No (Entity (N)) then
1972 -- Don't collect identifiers of packages, called functions, etc
1974 elsif Ekind_In (Entity (N), E_Package,
1981 -- For rewritten nodes, continue the traversal in the original
1982 -- subtree. Needed to handle aggregates in original expressions
1983 -- extracted from the tree by Remove_Side_Effects.
1985 elsif Is_Rewrite_Substitution (N) then
1986 Collect_Identifiers (Original_Node (N));
1989 -- For now we skip aggregate discriminants, since they require
1990 -- performing the analysis in two phases to identify conflicts:
1991 -- first one analyzing discriminants and second one analyzing
1992 -- the rest of components (since at run time, discriminants are
1993 -- evaluated prior to components): too much computation cost
1994 -- to identify a corner case???
1996 elsif Nkind (Parent (N)) = N_Component_Association
1997 and then Nkind_In (Parent (Parent (N)),
1999 N_Extension_Aggregate)
2002 Choice : constant Node_Id := First (Choices (Parent (N)));
2005 if Ekind (Entity (N)) = E_Discriminant then
2008 elsif Expression (Parent (N)) = N
2009 and then Nkind (Choice) = N_Identifier
2010 and then Ekind (Entity (Choice)) = E_Discriminant
2016 -- Analyze if N is a writable actual of a function
2018 elsif Nkind (Parent (N)) = N_Function_Call then
2020 Call : constant Node_Id := Parent (N);
2025 Id := Get_Function_Id (Call);
2027 -- In case of previous error, no check is possible
2033 if Ekind_In (Id, E_Function, E_Generic_Function)
2034 and then Has_Out_Or_In_Out_Parameter (Id)
2036 Formal := First_Formal (Id);
2037 Actual := First_Actual (Call);
2038 while Present (Actual) and then Present (Formal) loop
2040 if Ekind_In (Formal, E_Out_Parameter,
2043 Is_Writable_Actual := True;
2049 Next_Formal (Formal);
2050 Next_Actual (Actual);
2056 if Is_Writable_Actual then
2058 -- Skip checking the error in non-elementary types since
2059 -- RM 6.4.1(6.15/3) is restricted to elementary types, but
2060 -- store this actual in Writable_Actuals_List since it is
2061 -- needed to perform checks on other constructs that have
2062 -- arbitrary order of evaluation (for example, aggregates).
2064 if not Is_Elementary_Type (Etype (N)) then
2065 if not Contains (Writable_Actuals_List, N) then
2066 Append_New_Elmt (N, To => Writable_Actuals_List);
2069 -- Second occurrence of an elementary type writable actual
2071 elsif Contains (Writable_Actuals_List, N) then
2073 -- Report the error on the second occurrence of the
2074 -- identifier. We cannot assume that N is the second
2075 -- occurrence (according to their location in the
2076 -- sources), since Traverse_Func walks through Field2
2077 -- last (see comment in the body of Traverse_Func).
2083 Elmt := First_Elmt (Writable_Actuals_List);
2084 while Present (Elmt)
2085 and then Entity (Node (Elmt)) /= Entity (N)
2090 if Sloc (N) > Sloc (Node (Elmt)) then
2093 Error_Node := Node (Elmt);
2097 ("value may be affected by call to & "
2098 & "because order of evaluation is arbitrary",
2103 -- First occurrence of a elementary type writable actual
2106 Append_New_Elmt (N, To => Writable_Actuals_List);
2110 if Identifiers_List = No_Elist then
2111 Identifiers_List := New_Elmt_List;
2114 Append_Unique_Elmt (N, Identifiers_List);
2127 N : Node_Id) return Boolean
2129 pragma Assert (Nkind (N) in N_Has_Entity);
2134 if List = No_Elist then
2138 Elmt := First_Elmt (List);
2139 while Present (Elmt) loop
2140 if Entity (Node (Elmt)) = Entity (N) then
2154 procedure Do_Traversal is new Traverse_Proc (Check_Node);
2155 -- The traversal procedure
2157 -- Start of processing for Collect_Identifiers
2160 if Present (Error_Node) then
2164 if Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
2169 end Collect_Identifiers;
2171 ---------------------
2172 -- Get_Function_Id --
2173 ---------------------
2175 function Get_Function_Id (Call : Node_Id) return Entity_Id is
2176 Nam : constant Node_Id := Name (Call);
2180 if Nkind (Nam) = N_Explicit_Dereference then
2182 pragma Assert (Ekind (Id) = E_Subprogram_Type);
2184 elsif Nkind (Nam) = N_Selected_Component then
2185 Id := Entity (Selector_Name (Nam));
2187 elsif Nkind (Nam) = N_Indexed_Component then
2188 Id := Entity (Selector_Name (Prefix (Nam)));
2195 end Get_Function_Id;
2197 -------------------------------
2198 -- Preanalyze_Without_Errors --
2199 -------------------------------
2201 procedure Preanalyze_Without_Errors (N : Node_Id) is
2202 Status : constant Boolean := Get_Ignore_Errors;
2204 Set_Ignore_Errors (True);
2206 Set_Ignore_Errors (Status);
2207 end Preanalyze_Without_Errors;
2209 -- Start of processing for Check_Function_Writable_Actuals
2212 -- The check only applies to Ada 2012 code on which Check_Actuals has
2213 -- been set, and only to constructs that have multiple constituents
2214 -- whose order of evaluation is not specified by the language.
2216 if Ada_Version < Ada_2012
2217 or else not Check_Actuals (N)
2218 or else (not (Nkind (N) in N_Op)
2219 and then not (Nkind (N) in N_Membership_Test)
2220 and then not Nkind_In (N, N_Range,
2222 N_Extension_Aggregate,
2223 N_Full_Type_Declaration,
2225 N_Procedure_Call_Statement,
2226 N_Entry_Call_Statement))
2227 or else (Nkind (N) = N_Full_Type_Declaration
2228 and then not Is_Record_Type (Defining_Identifier (N)))
2230 -- In addition, this check only applies to source code, not to code
2231 -- generated by constraint checks.
2233 or else not Comes_From_Source (N)
2238 -- If a construct C has two or more direct constituents that are names
2239 -- or expressions whose evaluation may occur in an arbitrary order, at
2240 -- least one of which contains a function call with an in out or out
2241 -- parameter, then the construct is legal only if: for each name N that
2242 -- is passed as a parameter of mode in out or out to some inner function
2243 -- call C2 (not including the construct C itself), there is no other
2244 -- name anywhere within a direct constituent of the construct C other
2245 -- than the one containing C2, that is known to refer to the same
2246 -- object (RM 6.4.1(6.17/3)).
2250 Collect_Identifiers (Low_Bound (N));
2251 Collect_Identifiers (High_Bound (N));
2253 when N_Op | N_Membership_Test =>
2258 Collect_Identifiers (Left_Opnd (N));
2260 if Present (Right_Opnd (N)) then
2261 Collect_Identifiers (Right_Opnd (N));
2264 if Nkind_In (N, N_In, N_Not_In)
2265 and then Present (Alternatives (N))
2267 Expr := First (Alternatives (N));
2268 while Present (Expr) loop
2269 Collect_Identifiers (Expr);
2276 when N_Full_Type_Declaration =>
2278 function Get_Record_Part (N : Node_Id) return Node_Id;
2279 -- Return the record part of this record type definition
2281 function Get_Record_Part (N : Node_Id) return Node_Id is
2282 Type_Def : constant Node_Id := Type_Definition (N);
2284 if Nkind (Type_Def) = N_Derived_Type_Definition then
2285 return Record_Extension_Part (Type_Def);
2289 end Get_Record_Part;
2292 Def_Id : Entity_Id := Defining_Identifier (N);
2293 Rec : Node_Id := Get_Record_Part (N);
2296 -- No need to perform any analysis if the record has no
2299 if No (Rec) or else No (Component_List (Rec)) then
2303 -- Collect the identifiers starting from the deepest
2304 -- derivation. Done to report the error in the deepest
2308 if Present (Component_List (Rec)) then
2309 Comp := First (Component_Items (Component_List (Rec)));
2310 while Present (Comp) loop
2311 if Nkind (Comp) = N_Component_Declaration
2312 and then Present (Expression (Comp))
2314 Collect_Identifiers (Expression (Comp));
2321 exit when No (Underlying_Type (Etype (Def_Id)))
2322 or else Base_Type (Underlying_Type (Etype (Def_Id)))
2325 Def_Id := Base_Type (Underlying_Type (Etype (Def_Id)));
2326 Rec := Get_Record_Part (Parent (Def_Id));
2330 when N_Subprogram_Call |
2331 N_Entry_Call_Statement =>
2333 Id : constant Entity_Id := Get_Function_Id (N);
2338 Formal := First_Formal (Id);
2339 Actual := First_Actual (N);
2340 while Present (Actual) and then Present (Formal) loop
2341 if Ekind_In (Formal, E_Out_Parameter,
2344 Collect_Identifiers (Actual);
2347 Next_Formal (Formal);
2348 Next_Actual (Actual);
2353 N_Extension_Aggregate =>
2357 Comp_Expr : Node_Id;
2360 -- Handle the N_Others_Choice of array aggregates with static
2361 -- bounds. There is no need to perform this analysis in
2362 -- aggregates without static bounds since we cannot evaluate
2363 -- if the N_Others_Choice covers several elements. There is
2364 -- no need to handle the N_Others choice of record aggregates
2365 -- since at this stage it has been already expanded by
2366 -- Resolve_Record_Aggregate.
2368 if Is_Array_Type (Etype (N))
2369 and then Nkind (N) = N_Aggregate
2370 and then Present (Aggregate_Bounds (N))
2371 and then Compile_Time_Known_Bounds (Etype (N))
2372 and then Expr_Value (High_Bound (Aggregate_Bounds (N)))
2374 Expr_Value (Low_Bound (Aggregate_Bounds (N)))
2377 Count_Components : Uint := Uint_0;
2378 Num_Components : Uint;
2379 Others_Assoc : Node_Id;
2380 Others_Choice : Node_Id := Empty;
2381 Others_Box_Present : Boolean := False;
2384 -- Count positional associations
2386 if Present (Expressions (N)) then
2387 Comp_Expr := First (Expressions (N));
2388 while Present (Comp_Expr) loop
2389 Count_Components := Count_Components + 1;
2394 -- Count the rest of elements and locate the N_Others
2397 Assoc := First (Component_Associations (N));
2398 while Present (Assoc) loop
2399 Choice := First (Choices (Assoc));
2400 while Present (Choice) loop
2401 if Nkind (Choice) = N_Others_Choice then
2402 Others_Assoc := Assoc;
2403 Others_Choice := Choice;
2404 Others_Box_Present := Box_Present (Assoc);
2406 -- Count several components
2408 elsif Nkind_In (Choice, N_Range,
2409 N_Subtype_Indication)
2410 or else (Is_Entity_Name (Choice)
2411 and then Is_Type (Entity (Choice)))
2416 Get_Index_Bounds (Choice, L, H);
2418 (Compile_Time_Known_Value (L)
2419 and then Compile_Time_Known_Value (H));
2422 + Expr_Value (H) - Expr_Value (L) + 1;
2425 -- Count single component. No other case available
2426 -- since we are handling an aggregate with static
2430 pragma Assert (Is_OK_Static_Expression (Choice)
2431 or else Nkind (Choice) = N_Identifier
2432 or else Nkind (Choice) = N_Integer_Literal);
2434 Count_Components := Count_Components + 1;
2444 Expr_Value (High_Bound (Aggregate_Bounds (N))) -
2445 Expr_Value (Low_Bound (Aggregate_Bounds (N))) + 1;
2447 pragma Assert (Count_Components <= Num_Components);
2449 -- Handle the N_Others choice if it covers several
2452 if Present (Others_Choice)
2453 and then (Num_Components - Count_Components) > 1
2455 if not Others_Box_Present then
2457 -- At this stage, if expansion is active, the
2458 -- expression of the others choice has not been
2459 -- analyzed. Hence we generate a duplicate and
2460 -- we analyze it silently to have available the
2461 -- minimum decoration required to collect the
2464 if not Expander_Active then
2465 Comp_Expr := Expression (Others_Assoc);
2468 New_Copy_Tree (Expression (Others_Assoc));
2469 Preanalyze_Without_Errors (Comp_Expr);
2472 Collect_Identifiers (Comp_Expr);
2474 if Writable_Actuals_List /= No_Elist then
2476 -- As suggested by Robert, at current stage we
2477 -- report occurrences of this case as warnings.
2480 ("writable function parameter may affect "
2481 & "value in other component because order "
2482 & "of evaluation is unspecified??",
2483 Node (First_Elmt (Writable_Actuals_List)));
2489 -- For an array aggregate, a discrete_choice_list that has
2490 -- a nonstatic range is considered as two or more separate
2491 -- occurrences of the expression (RM 6.4.1(20/3)).
2493 elsif Is_Array_Type (Etype (N))
2494 and then Nkind (N) = N_Aggregate
2495 and then Present (Aggregate_Bounds (N))
2496 and then not Compile_Time_Known_Bounds (Etype (N))
2498 -- Collect identifiers found in the dynamic bounds
2501 Count_Components : Natural := 0;
2502 Low, High : Node_Id;
2505 Assoc := First (Component_Associations (N));
2506 while Present (Assoc) loop
2507 Choice := First (Choices (Assoc));
2508 while Present (Choice) loop
2509 if Nkind_In (Choice, N_Range,
2510 N_Subtype_Indication)
2511 or else (Is_Entity_Name (Choice)
2512 and then Is_Type (Entity (Choice)))
2514 Get_Index_Bounds (Choice, Low, High);
2516 if not Compile_Time_Known_Value (Low) then
2517 Collect_Identifiers (Low);
2519 if No (Aggr_Error_Node) then
2520 Aggr_Error_Node := Low;
2524 if not Compile_Time_Known_Value (High) then
2525 Collect_Identifiers (High);
2527 if No (Aggr_Error_Node) then
2528 Aggr_Error_Node := High;
2532 -- The RM rule is violated if there is more than
2533 -- a single choice in a component association.
2536 Count_Components := Count_Components + 1;
2538 if No (Aggr_Error_Node)
2539 and then Count_Components > 1
2541 Aggr_Error_Node := Choice;
2544 if not Compile_Time_Known_Value (Choice) then
2545 Collect_Identifiers (Choice);
2557 -- Handle ancestor part of extension aggregates
2559 if Nkind (N) = N_Extension_Aggregate then
2560 Collect_Identifiers (Ancestor_Part (N));
2563 -- Handle positional associations
2565 if Present (Expressions (N)) then
2566 Comp_Expr := First (Expressions (N));
2567 while Present (Comp_Expr) loop
2568 if not Is_OK_Static_Expression (Comp_Expr) then
2569 Collect_Identifiers (Comp_Expr);
2576 -- Handle discrete associations
2578 if Present (Component_Associations (N)) then
2579 Assoc := First (Component_Associations (N));
2580 while Present (Assoc) loop
2582 if not Box_Present (Assoc) then
2583 Choice := First (Choices (Assoc));
2584 while Present (Choice) loop
2586 -- For now we skip discriminants since it requires
2587 -- performing the analysis in two phases: first one
2588 -- analyzing discriminants and second one analyzing
2589 -- the rest of components since discriminants are
2590 -- evaluated prior to components: too much extra
2591 -- work to detect a corner case???
2593 if Nkind (Choice) in N_Has_Entity
2594 and then Present (Entity (Choice))
2595 and then Ekind (Entity (Choice)) = E_Discriminant
2599 elsif Box_Present (Assoc) then
2603 if not Analyzed (Expression (Assoc)) then
2605 New_Copy_Tree (Expression (Assoc));
2606 Set_Parent (Comp_Expr, Parent (N));
2607 Preanalyze_Without_Errors (Comp_Expr);
2609 Comp_Expr := Expression (Assoc);
2612 Collect_Identifiers (Comp_Expr);
2628 -- No further action needed if we already reported an error
2630 if Present (Error_Node) then
2634 -- Check violation of RM 6.20/3 in aggregates
2636 if Present (Aggr_Error_Node)
2637 and then Writable_Actuals_List /= No_Elist
2640 ("value may be affected by call in other component because they "
2641 & "are evaluated in unspecified order",
2642 Node (First_Elmt (Writable_Actuals_List)));
2646 -- Check if some writable argument of a function is referenced
2648 if Writable_Actuals_List /= No_Elist
2649 and then Identifiers_List /= No_Elist
2656 Elmt_1 := First_Elmt (Writable_Actuals_List);
2657 while Present (Elmt_1) loop
2658 Elmt_2 := First_Elmt (Identifiers_List);
2659 while Present (Elmt_2) loop
2660 if Entity (Node (Elmt_1)) = Entity (Node (Elmt_2)) then
2661 case Nkind (Parent (Node (Elmt_2))) is
2663 N_Component_Association |
2664 N_Component_Declaration =>
2666 ("value may be affected by call in other "
2667 & "component because they are evaluated "
2668 & "in unspecified order",
2671 when N_In | N_Not_In =>
2673 ("value may be affected by call in other "
2674 & "alternative because they are evaluated "
2675 & "in unspecified order",
2680 ("value of actual may be affected by call in "
2681 & "other actual because they are evaluated "
2682 & "in unspecified order",
2694 end Check_Function_Writable_Actuals;
2696 --------------------------------
2697 -- Check_Implicit_Dereference --
2698 --------------------------------
2700 procedure Check_Implicit_Dereference (N : Node_Id; Typ : Entity_Id) is
2706 if Nkind (N) = N_Indexed_Component
2707 and then Present (Generalized_Indexing (N))
2709 Nam := Generalized_Indexing (N);
2714 if Ada_Version < Ada_2012
2715 or else not Has_Implicit_Dereference (Base_Type (Typ))
2719 elsif not Comes_From_Source (N)
2720 and then Nkind (N) /= N_Indexed_Component
2724 elsif Is_Entity_Name (Nam) and then Is_Type (Entity (Nam)) then
2728 Disc := First_Discriminant (Typ);
2729 while Present (Disc) loop
2730 if Has_Implicit_Dereference (Disc) then
2731 Desig := Designated_Type (Etype (Disc));
2732 Add_One_Interp (Nam, Disc, Desig);
2734 -- If the node is a generalized indexing, add interpretation
2735 -- to that node as well, for subsequent resolution.
2737 if Nkind (N) = N_Indexed_Component then
2738 Add_One_Interp (N, Disc, Desig);
2741 -- If the operation comes from a generic unit and the context
2742 -- is a selected component, the selector name may be global
2743 -- and set in the instance already. Remove the entity to
2744 -- force resolution of the selected component, and the
2745 -- generation of an explicit dereference if needed.
2748 and then Nkind (Parent (Nam)) = N_Selected_Component
2750 Set_Entity (Selector_Name (Parent (Nam)), Empty);
2756 Next_Discriminant (Disc);
2759 end Check_Implicit_Dereference;
2761 ----------------------------------
2762 -- Check_Internal_Protected_Use --
2763 ----------------------------------
2765 procedure Check_Internal_Protected_Use (N : Node_Id; Nam : Entity_Id) is
2771 while Present (S) loop
2772 if S = Standard_Standard then
2775 elsif Ekind (S) = E_Function
2776 and then Ekind (Scope (S)) = E_Protected_Type
2785 if Scope (Nam) = Prot and then Ekind (Nam) /= E_Function then
2787 -- An indirect function call (e.g. a callback within a protected
2788 -- function body) is not statically illegal. If the access type is
2789 -- anonymous and is the type of an access parameter, the scope of Nam
2790 -- will be the protected type, but it is not a protected operation.
2792 if Ekind (Nam) = E_Subprogram_Type
2794 Nkind (Associated_Node_For_Itype (Nam)) = N_Function_Specification
2798 elsif Nkind (N) = N_Subprogram_Renaming_Declaration then
2800 ("within protected function cannot use protected "
2801 & "procedure in renaming or as generic actual", N);
2803 elsif Nkind (N) = N_Attribute_Reference then
2805 ("within protected function cannot take access of "
2806 & " protected procedure", N);
2810 ("within protected function, protected object is constant", N);
2812 ("\cannot call operation that may modify it", N);
2815 end Check_Internal_Protected_Use;
2817 ---------------------------------------
2818 -- Check_Later_Vs_Basic_Declarations --
2819 ---------------------------------------
2821 procedure Check_Later_Vs_Basic_Declarations
2823 During_Parsing : Boolean)
2825 Body_Sloc : Source_Ptr;
2828 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
2829 -- Return whether Decl is considered as a declarative item.
2830 -- When During_Parsing is True, the semantics of Ada 83 is followed.
2831 -- When During_Parsing is False, the semantics of SPARK is followed.
2833 -------------------------------
2834 -- Is_Later_Declarative_Item --
2835 -------------------------------
2837 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
2839 if Nkind (Decl) in N_Later_Decl_Item then
2842 elsif Nkind (Decl) = N_Pragma then
2845 elsif During_Parsing then
2848 -- In SPARK, a package declaration is not considered as a later
2849 -- declarative item.
2851 elsif Nkind (Decl) = N_Package_Declaration then
2854 -- In SPARK, a renaming is considered as a later declarative item
2856 elsif Nkind (Decl) in N_Renaming_Declaration then
2862 end Is_Later_Declarative_Item;
2864 -- Start of processing for Check_Later_Vs_Basic_Declarations
2867 Decl := First (Decls);
2869 -- Loop through sequence of basic declarative items
2871 Outer : while Present (Decl) loop
2872 if not Nkind_In (Decl, N_Subprogram_Body, N_Package_Body, N_Task_Body)
2873 and then Nkind (Decl) not in N_Body_Stub
2877 -- Once a body is encountered, we only allow later declarative
2878 -- items. The inner loop checks the rest of the list.
2881 Body_Sloc := Sloc (Decl);
2883 Inner : while Present (Decl) loop
2884 if not Is_Later_Declarative_Item (Decl) then
2885 if During_Parsing then
2886 if Ada_Version = Ada_83 then
2887 Error_Msg_Sloc := Body_Sloc;
2889 ("(Ada 83) decl cannot appear after body#", Decl);
2892 Error_Msg_Sloc := Body_Sloc;
2893 Check_SPARK_05_Restriction
2894 ("decl cannot appear after body#", Decl);
2902 end Check_Later_Vs_Basic_Declarations;
2904 ---------------------------
2905 -- Check_No_Hidden_State --
2906 ---------------------------
2908 procedure Check_No_Hidden_State (Id : Entity_Id) is
2909 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean;
2910 -- Determine whether the entity of a package denoted by Pkg has a null
2913 -----------------------------
2914 -- Has_Null_Abstract_State --
2915 -----------------------------
2917 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean is
2918 States : constant Elist_Id := Abstract_States (Pkg);
2921 -- Check first available state of related package. A null abstract
2922 -- state always appears as the sole element of the state list.
2926 and then Is_Null_State (Node (First_Elmt (States)));
2927 end Has_Null_Abstract_State;
2931 Context : Entity_Id := Empty;
2932 Not_Visible : Boolean := False;
2935 -- Start of processing for Check_No_Hidden_State
2938 pragma Assert (Ekind_In (Id, E_Abstract_State, E_Variable));
2940 -- Find the proper context where the object or state appears
2943 while Present (Scop) loop
2946 -- Keep track of the context's visibility
2948 Not_Visible := Not_Visible or else In_Private_Part (Context);
2950 -- Prevent the search from going too far
2952 if Context = Standard_Standard then
2955 -- Objects and states that appear immediately within a subprogram or
2956 -- inside a construct nested within a subprogram do not introduce a
2957 -- hidden state. They behave as local variable declarations.
2959 elsif Is_Subprogram (Context) then
2962 -- When examining a package body, use the entity of the spec as it
2963 -- carries the abstract state declarations.
2965 elsif Ekind (Context) = E_Package_Body then
2966 Context := Spec_Entity (Context);
2969 -- Stop the traversal when a package subject to a null abstract state
2972 if Ekind_In (Context, E_Generic_Package, E_Package)
2973 and then Has_Null_Abstract_State (Context)
2978 Scop := Scope (Scop);
2981 -- At this point we know that there is at least one package with a null
2982 -- abstract state in visibility. Emit an error message unconditionally
2983 -- if the entity being processed is a state because the placement of the
2984 -- related package is irrelevant. This is not the case for objects as
2985 -- the intermediate context matters.
2987 if Present (Context)
2988 and then (Ekind (Id) = E_Abstract_State or else Not_Visible)
2990 Error_Msg_N ("cannot introduce hidden state &", Id);
2991 Error_Msg_NE ("\package & has null abstract state", Id, Context);
2993 end Check_No_Hidden_State;
2995 ----------------------------------------
2996 -- Check_Nonvolatile_Function_Profile --
2997 ----------------------------------------
2999 procedure Check_Nonvolatile_Function_Profile (Func_Id : Entity_Id) is
3003 -- Inspect all formal parameters
3005 Formal := First_Formal (Func_Id);
3006 while Present (Formal) loop
3007 if Is_Effectively_Volatile (Etype (Formal)) then
3009 ("nonvolatile function & cannot have a volatile parameter",
3013 Next_Formal (Formal);
3016 -- Inspect the return type
3018 if Is_Effectively_Volatile (Etype (Func_Id)) then
3020 ("nonvolatile function & cannot have a volatile return type",
3023 end Check_Nonvolatile_Function_Profile;
3025 ------------------------------------------
3026 -- Check_Potentially_Blocking_Operation --
3027 ------------------------------------------
3029 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
3033 -- N is one of the potentially blocking operations listed in 9.5.1(8).
3034 -- When pragma Detect_Blocking is active, the run time will raise
3035 -- Program_Error. Here we only issue a warning, since we generally
3036 -- support the use of potentially blocking operations in the absence
3039 -- Indirect blocking through a subprogram call cannot be diagnosed
3040 -- statically without interprocedural analysis, so we do not attempt
3043 S := Scope (Current_Scope);
3044 while Present (S) and then S /= Standard_Standard loop
3045 if Is_Protected_Type (S) then
3047 ("potentially blocking operation in protected operation??", N);
3053 end Check_Potentially_Blocking_Operation;
3055 ---------------------------------
3056 -- Check_Result_And_Post_State --
3057 ---------------------------------
3059 procedure Check_Result_And_Post_State (Subp_Id : Entity_Id) is
3060 procedure Check_Result_And_Post_State_In_Pragma
3062 Result_Seen : in out Boolean);
3063 -- Determine whether pragma Prag mentions attribute 'Result and whether
3064 -- the pragma contains an expression that evaluates differently in pre-
3065 -- and post-state. Prag is a [refined] postcondition or a contract-cases
3066 -- pragma. Result_Seen is set when the pragma mentions attribute 'Result
3068 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean;
3069 -- Determine whether subprogram Subp_Id contains at least one IN OUT
3070 -- formal parameter.
3072 -------------------------------------------
3073 -- Check_Result_And_Post_State_In_Pragma --
3074 -------------------------------------------
3076 procedure Check_Result_And_Post_State_In_Pragma
3078 Result_Seen : in out Boolean)
3080 procedure Check_Expression (Expr : Node_Id);
3081 -- Perform the 'Result and post-state checks on a given expression
3083 function Is_Function_Result (N : Node_Id) return Traverse_Result;
3084 -- Attempt to find attribute 'Result in a subtree denoted by N
3086 function Is_Trivial_Boolean (N : Node_Id) return Boolean;
3087 -- Determine whether source node N denotes "True" or "False"
3089 function Mentions_Post_State (N : Node_Id) return Boolean;
3090 -- Determine whether a subtree denoted by N mentions any construct
3091 -- that denotes a post-state.
3093 procedure Check_Function_Result is
3094 new Traverse_Proc (Is_Function_Result);
3096 ----------------------
3097 -- Check_Expression --
3098 ----------------------
3100 procedure Check_Expression (Expr : Node_Id) is
3102 if not Is_Trivial_Boolean (Expr) then
3103 Check_Function_Result (Expr);
3105 if not Mentions_Post_State (Expr) then
3106 if Pragma_Name (Prag) = Name_Contract_Cases then
3108 ("contract case does not check the outcome of calling "
3109 & "&?T?", Expr, Subp_Id);
3111 elsif Pragma_Name (Prag) = Name_Refined_Post then
3113 ("refined postcondition does not check the outcome of "
3114 & "calling &?T?", Prag, Subp_Id);
3118 ("postcondition does not check the outcome of calling "
3119 & "&?T?", Prag, Subp_Id);
3123 end Check_Expression;
3125 ------------------------
3126 -- Is_Function_Result --
3127 ------------------------
3129 function Is_Function_Result (N : Node_Id) return Traverse_Result is
3131 if Is_Attribute_Result (N) then
3132 Result_Seen := True;
3135 -- Continue the traversal
3140 end Is_Function_Result;
3142 ------------------------
3143 -- Is_Trivial_Boolean --
3144 ------------------------
3146 function Is_Trivial_Boolean (N : Node_Id) return Boolean is
3149 Comes_From_Source (N)
3150 and then Is_Entity_Name (N)
3151 and then (Entity (N) = Standard_True
3153 Entity (N) = Standard_False);
3154 end Is_Trivial_Boolean;
3156 -------------------------
3157 -- Mentions_Post_State --
3158 -------------------------
3160 function Mentions_Post_State (N : Node_Id) return Boolean is
3161 Post_State_Seen : Boolean := False;
3163 function Is_Post_State (N : Node_Id) return Traverse_Result;
3164 -- Attempt to find a construct that denotes a post-state. If this
3165 -- is the case, set flag Post_State_Seen.
3171 function Is_Post_State (N : Node_Id) return Traverse_Result is
3175 if Nkind_In (N, N_Explicit_Dereference, N_Function_Call) then
3176 Post_State_Seen := True;
3179 elsif Nkind_In (N, N_Expanded_Name, N_Identifier) then
3182 -- The entity may be modifiable through an implicit
3186 or else Ekind (Ent) in Assignable_Kind
3187 or else (Is_Access_Type (Etype (Ent))
3188 and then Nkind (Parent (N)) =
3189 N_Selected_Component)
3191 Post_State_Seen := True;
3195 elsif Nkind (N) = N_Attribute_Reference then
3196 if Attribute_Name (N) = Name_Old then
3199 elsif Attribute_Name (N) = Name_Result then
3200 Post_State_Seen := True;
3208 procedure Find_Post_State is new Traverse_Proc (Is_Post_State);
3210 -- Start of processing for Mentions_Post_State
3213 Find_Post_State (N);
3215 return Post_State_Seen;
3216 end Mentions_Post_State;
3220 Expr : constant Node_Id :=
3222 (First (Pragma_Argument_Associations (Prag)));
3223 Nam : constant Name_Id := Pragma_Name (Prag);
3226 -- Start of processing for Check_Result_And_Post_State_In_Pragma
3229 -- Examine all consequences
3231 if Nam = Name_Contract_Cases then
3232 CCase := First (Component_Associations (Expr));
3233 while Present (CCase) loop
3234 Check_Expression (Expression (CCase));
3239 -- Examine the expression of a postcondition
3241 else pragma Assert (Nam_In (Nam, Name_Postcondition,
3242 Name_Refined_Post));
3243 Check_Expression (Expr);
3245 end Check_Result_And_Post_State_In_Pragma;
3247 --------------------------
3248 -- Has_In_Out_Parameter --
3249 --------------------------
3251 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean is
3255 -- Traverse the formals looking for an IN OUT parameter
3257 Formal := First_Formal (Subp_Id);
3258 while Present (Formal) loop
3259 if Ekind (Formal) = E_In_Out_Parameter then
3263 Next_Formal (Formal);
3267 end Has_In_Out_Parameter;
3271 Items : constant Node_Id := Contract (Subp_Id);
3272 Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id);
3273 Case_Prag : Node_Id := Empty;
3274 Post_Prag : Node_Id := Empty;
3276 Seen_In_Case : Boolean := False;
3277 Seen_In_Post : Boolean := False;
3278 Spec_Id : Entity_Id;
3280 -- Start of processing for Check_Result_And_Post_State
3283 -- The lack of attribute 'Result or a post-state is classified as a
3284 -- suspicious contract. Do not perform the check if the corresponding
3285 -- swich is not set.
3287 if not Warn_On_Suspicious_Contract then
3290 -- Nothing to do if there is no contract
3292 elsif No (Items) then
3296 -- Retrieve the entity of the subprogram spec (if any)
3298 if Nkind (Subp_Decl) = N_Subprogram_Body
3299 and then Present (Corresponding_Spec (Subp_Decl))
3301 Spec_Id := Corresponding_Spec (Subp_Decl);
3303 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
3304 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
3306 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
3312 -- Examine all postconditions for attribute 'Result and a post-state
3314 Prag := Pre_Post_Conditions (Items);
3315 while Present (Prag) loop
3316 if Nam_In (Pragma_Name (Prag), Name_Postcondition,
3318 and then not Error_Posted (Prag)
3321 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Post);
3324 Prag := Next_Pragma (Prag);
3327 -- Examine the contract cases of the subprogram for attribute 'Result
3328 -- and a post-state.
3330 Prag := Contract_Test_Cases (Items);
3331 while Present (Prag) loop
3332 if Pragma_Name (Prag) = Name_Contract_Cases
3333 and then not Error_Posted (Prag)
3336 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Case);
3339 Prag := Next_Pragma (Prag);
3342 -- Do not emit any errors if the subprogram is not a function
3344 if not Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
3347 -- Regardless of whether the function has postconditions or contract
3348 -- cases, or whether they mention attribute 'Result, an IN OUT formal
3349 -- parameter is always treated as a result.
3351 elsif Has_In_Out_Parameter (Spec_Id) then
3354 -- The function has both a postcondition and contract cases and they do
3355 -- not mention attribute 'Result.
3357 elsif Present (Case_Prag)
3358 and then not Seen_In_Case
3359 and then Present (Post_Prag)
3360 and then not Seen_In_Post
3363 ("neither postcondition nor contract cases mention function "
3364 & "result?T?", Post_Prag);
3366 -- The function has contract cases only and they do not mention
3367 -- attribute 'Result.
3369 elsif Present (Case_Prag) and then not Seen_In_Case then
3370 Error_Msg_N ("contract cases do not mention result?T?", Case_Prag);
3372 -- The function has postconditions only and they do not mention
3373 -- attribute 'Result.
3375 elsif Present (Post_Prag) and then not Seen_In_Post then
3377 ("postcondition does not mention function result?T?", Post_Prag);
3379 end Check_Result_And_Post_State;
3381 ------------------------------
3382 -- Check_Unprotected_Access --
3383 ------------------------------
3385 procedure Check_Unprotected_Access
3389 Cont_Encl_Typ : Entity_Id;
3390 Pref_Encl_Typ : Entity_Id;
3392 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
3393 -- Check whether Obj is a private component of a protected object.
3394 -- Return the protected type where the component resides, Empty
3397 function Is_Public_Operation return Boolean;
3398 -- Verify that the enclosing operation is callable from outside the
3399 -- protected object, to minimize false positives.
3401 ------------------------------
3402 -- Enclosing_Protected_Type --
3403 ------------------------------
3405 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
3407 if Is_Entity_Name (Obj) then
3409 Ent : Entity_Id := Entity (Obj);
3412 -- The object can be a renaming of a private component, use
3413 -- the original record component.
3415 if Is_Prival (Ent) then
3416 Ent := Prival_Link (Ent);
3419 if Is_Protected_Type (Scope (Ent)) then
3425 -- For indexed and selected components, recursively check the prefix
3427 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
3428 return Enclosing_Protected_Type (Prefix (Obj));
3430 -- The object does not denote a protected component
3435 end Enclosing_Protected_Type;
3437 -------------------------
3438 -- Is_Public_Operation --
3439 -------------------------
3441 function Is_Public_Operation return Boolean is
3447 while Present (S) and then S /= Pref_Encl_Typ loop
3448 if Scope (S) = Pref_Encl_Typ then
3449 E := First_Entity (Pref_Encl_Typ);
3451 and then E /= First_Private_Entity (Pref_Encl_Typ)
3465 end Is_Public_Operation;
3467 -- Start of processing for Check_Unprotected_Access
3470 if Nkind (Expr) = N_Attribute_Reference
3471 and then Attribute_Name (Expr) = Name_Unchecked_Access
3473 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
3474 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
3476 -- Check whether we are trying to export a protected component to a
3477 -- context with an equal or lower access level.
3479 if Present (Pref_Encl_Typ)
3480 and then No (Cont_Encl_Typ)
3481 and then Is_Public_Operation
3482 and then Scope_Depth (Pref_Encl_Typ) >=
3483 Object_Access_Level (Context)
3486 ("??possible unprotected access to protected data", Expr);
3489 end Check_Unprotected_Access;
3491 ------------------------------
3492 -- Check_Unused_Body_States --
3493 ------------------------------
3495 procedure Check_Unused_Body_States (Body_Id : Entity_Id) is
3496 Legal_Constits : Boolean := True;
3497 -- This flag designates whether all constituents of pragma Refined_State
3498 -- are legal. The flag is used to suppress the generation of potentially
3499 -- misleading error messages due to a malformed pragma.
3501 procedure Process_Refinement_Clause
3504 -- Inspect all constituents of refinement clause Clause and remove any
3505 -- matches from body state list States.
3507 -------------------------------
3508 -- Process_Refinement_Clause --
3509 -------------------------------
3511 procedure Process_Refinement_Clause
3515 procedure Process_Constituent (Constit : Node_Id);
3516 -- Remove constituent Constit from body state list States
3518 -------------------------
3519 -- Process_Constituent --
3520 -------------------------
3522 procedure Process_Constituent (Constit : Node_Id) is
3523 Constit_Id : Entity_Id;
3526 if Error_Posted (Constit) then
3527 Legal_Constits := False;
3530 -- Guard against illegal constituents. Only abstract states and
3531 -- objects can appear on the right hand side of a refinement.
3533 if Is_Entity_Name (Constit) then
3534 Constit_Id := Entity_Of (Constit);
3536 if Present (Constit_Id)
3537 and then Ekind_In (Constit_Id, E_Abstract_State,
3541 Remove (States, Constit_Id);
3544 end Process_Constituent;
3550 -- Start of processing for Process_Refinement_Clause
3553 if Nkind (Clause) = N_Component_Association then
3554 Constit := Expression (Clause);
3556 -- Multiple constituents appear as an aggregate
3558 if Nkind (Constit) = N_Aggregate then
3559 Constit := First (Expressions (Constit));
3560 while Present (Constit) loop
3561 Process_Constituent (Constit);
3565 -- Various forms of a single constituent
3568 Process_Constituent (Constit);
3571 end Process_Refinement_Clause;
3575 Prag : constant Node_Id :=
3576 Get_Pragma (Body_Id, Pragma_Refined_State);
3577 Spec_Id : constant Entity_Id := Spec_Entity (Body_Id);
3581 -- Start of processing for Check_Unused_Body_States
3584 -- Inspect the clauses of pragma Refined_State and determine whether all
3585 -- visible states declared within the body of the package participate in
3588 if Present (Prag) then
3589 Clause := Expression (Get_Argument (Prag, Spec_Id));
3590 States := Collect_Body_States (Body_Id);
3592 -- Multiple non-null state refinements appear as an aggregate
3594 if Nkind (Clause) = N_Aggregate then
3595 Clause := First (Component_Associations (Clause));
3596 while Present (Clause) loop
3597 Process_Refinement_Clause (Clause, States);
3601 -- Various forms of a single state refinement
3604 Process_Refinement_Clause (Clause, States);
3607 -- Ensure that all abstract states and objects declared in the body
3608 -- state space of the related package are utilized as constituents.
3610 if Legal_Constits then
3611 Report_Unused_Body_States (Body_Id, States);
3614 end Check_Unused_Body_States;
3616 -------------------------
3617 -- Collect_Body_States --
3618 -------------------------
3620 function Collect_Body_States (Body_Id : Entity_Id) return Elist_Id is
3621 procedure Collect_Visible_States
3622 (Pack_Id : Entity_Id;
3623 States : in out Elist_Id);
3624 -- Gather the entities of all abstract states and objects declared in
3625 -- the visible state space of package Pack_Id.
3627 ----------------------------
3628 -- Collect_Visible_States --
3629 ----------------------------
3631 procedure Collect_Visible_States
3632 (Pack_Id : Entity_Id;
3633 States : in out Elist_Id)
3635 Item_Id : Entity_Id;
3638 -- Traverse the entity chain of the package and inspect all visible
3641 Item_Id := First_Entity (Pack_Id);
3642 while Present (Item_Id) and then not In_Private_Part (Item_Id) loop
3644 -- Do not consider internally generated items as those cannot be
3645 -- named and participate in refinement.
3647 if not Comes_From_Source (Item_Id) then
3650 elsif Ekind (Item_Id) = E_Abstract_State then
3651 Append_New_Elmt (Item_Id, States);
3653 -- Do not consider objects that map generic formals to their
3654 -- actuals, as the formals cannot be named from the outside and
3655 -- participate in refinement.
3657 elsif Ekind_In (Item_Id, E_Constant, E_Variable)
3658 and then No (Corresponding_Generic_Association
3659 (Declaration_Node (Item_Id)))
3661 Append_New_Elmt (Item_Id, States);
3663 -- Recursively gather the visible states of a nested package
3665 elsif Ekind (Item_Id) = E_Package then
3666 Collect_Visible_States (Item_Id, States);
3669 Next_Entity (Item_Id);
3671 end Collect_Visible_States;
3675 Body_Decl : constant Node_Id := Unit_Declaration_Node (Body_Id);
3677 Item_Id : Entity_Id;
3678 States : Elist_Id := No_Elist;
3680 -- Start of processing for Collect_Body_States
3683 -- Inspect the declarations of the body looking for source objects,
3684 -- packages and package instantiations.
3686 Decl := First (Declarations (Body_Decl));
3687 while Present (Decl) loop
3689 -- Capture source objects as internally generated temporaries cannot
3690 -- be named and participate in refinement.
3692 if Nkind (Decl) = N_Object_Declaration then
3693 Item_Id := Defining_Entity (Decl);
3695 if Comes_From_Source (Item_Id) then
3696 Append_New_Elmt (Item_Id, States);
3699 -- Capture the visible abstract states and objects of a source
3700 -- package [instantiation].
3702 elsif Nkind (Decl) = N_Package_Declaration then
3703 Item_Id := Defining_Entity (Decl);
3705 if Comes_From_Source (Item_Id) then
3706 Collect_Visible_States (Item_Id, States);
3714 end Collect_Body_States;
3716 ------------------------
3717 -- Collect_Interfaces --
3718 ------------------------
3720 procedure Collect_Interfaces
3722 Ifaces_List : out Elist_Id;
3723 Exclude_Parents : Boolean := False;
3724 Use_Full_View : Boolean := True)
3726 procedure Collect (Typ : Entity_Id);
3727 -- Subsidiary subprogram used to traverse the whole list
3728 -- of directly and indirectly implemented interfaces
3734 procedure Collect (Typ : Entity_Id) is
3735 Ancestor : Entity_Id;
3743 -- Handle private types and subtypes
3746 and then Is_Private_Type (Typ)
3747 and then Present (Full_View (Typ))
3749 Full_T := Full_View (Typ);
3751 if Ekind (Full_T) = E_Record_Subtype then
3752 Full_T := Full_View (Etype (Typ));
3756 -- Include the ancestor if we are generating the whole list of
3757 -- abstract interfaces.
3759 if Etype (Full_T) /= Typ
3761 -- Protect the frontend against wrong sources. For example:
3764 -- type A is tagged null record;
3765 -- type B is new A with private;
3766 -- type C is new A with private;
3768 -- type B is new C with null record;
3769 -- type C is new B with null record;
3772 and then Etype (Full_T) /= T
3774 Ancestor := Etype (Full_T);
3777 if Is_Interface (Ancestor) and then not Exclude_Parents then
3778 Append_Unique_Elmt (Ancestor, Ifaces_List);
3782 -- Traverse the graph of ancestor interfaces
3784 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
3785 Id := First (Abstract_Interface_List (Full_T));
3786 while Present (Id) loop
3787 Iface := Etype (Id);
3789 -- Protect against wrong uses. For example:
3790 -- type I is interface;
3791 -- type O is tagged null record;
3792 -- type Wrong is new I and O with null record; -- ERROR
3794 if Is_Interface (Iface) then
3796 and then Etype (T) /= T
3797 and then Interface_Present_In_Ancestor (Etype (T), Iface)
3802 Append_Unique_Elmt (Iface, Ifaces_List);
3811 -- Start of processing for Collect_Interfaces
3814 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
3815 Ifaces_List := New_Elmt_List;
3817 end Collect_Interfaces;
3819 ----------------------------------
3820 -- Collect_Interface_Components --
3821 ----------------------------------
3823 procedure Collect_Interface_Components
3824 (Tagged_Type : Entity_Id;
3825 Components_List : out Elist_Id)
3827 procedure Collect (Typ : Entity_Id);
3828 -- Subsidiary subprogram used to climb to the parents
3834 procedure Collect (Typ : Entity_Id) is
3835 Tag_Comp : Entity_Id;
3836 Parent_Typ : Entity_Id;
3839 -- Handle private types
3841 if Present (Full_View (Etype (Typ))) then
3842 Parent_Typ := Full_View (Etype (Typ));
3844 Parent_Typ := Etype (Typ);
3847 if Parent_Typ /= Typ
3849 -- Protect the frontend against wrong sources. For example:
3852 -- type A is tagged null record;
3853 -- type B is new A with private;
3854 -- type C is new A with private;
3856 -- type B is new C with null record;
3857 -- type C is new B with null record;
3860 and then Parent_Typ /= Tagged_Type
3862 Collect (Parent_Typ);
3865 -- Collect the components containing tags of secondary dispatch
3868 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
3869 while Present (Tag_Comp) loop
3870 pragma Assert (Present (Related_Type (Tag_Comp)));
3871 Append_Elmt (Tag_Comp, Components_List);
3873 Tag_Comp := Next_Tag_Component (Tag_Comp);
3877 -- Start of processing for Collect_Interface_Components
3880 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
3881 and then Is_Tagged_Type (Tagged_Type));
3883 Components_List := New_Elmt_List;
3884 Collect (Tagged_Type);
3885 end Collect_Interface_Components;
3887 -----------------------------
3888 -- Collect_Interfaces_Info --
3889 -----------------------------
3891 procedure Collect_Interfaces_Info
3893 Ifaces_List : out Elist_Id;
3894 Components_List : out Elist_Id;
3895 Tags_List : out Elist_Id)
3897 Comps_List : Elist_Id;
3898 Comp_Elmt : Elmt_Id;
3899 Comp_Iface : Entity_Id;
3900 Iface_Elmt : Elmt_Id;
3903 function Search_Tag (Iface : Entity_Id) return Entity_Id;
3904 -- Search for the secondary tag associated with the interface type
3905 -- Iface that is implemented by T.
3911 function Search_Tag (Iface : Entity_Id) return Entity_Id is
3914 if not Is_CPP_Class (T) then
3915 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
3917 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
3921 and then Is_Tag (Node (ADT))
3922 and then Related_Type (Node (ADT)) /= Iface
3924 -- Skip secondary dispatch table referencing thunks to user
3925 -- defined primitives covered by this interface.
3927 pragma Assert (Has_Suffix (Node (ADT), 'P'));
3930 -- Skip secondary dispatch tables of Ada types
3932 if not Is_CPP_Class (T) then
3934 -- Skip secondary dispatch table referencing thunks to
3935 -- predefined primitives.
3937 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
3940 -- Skip secondary dispatch table referencing user-defined
3941 -- primitives covered by this interface.
3943 pragma Assert (Has_Suffix (Node (ADT), 'D'));
3946 -- Skip secondary dispatch table referencing predefined
3949 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
3954 pragma Assert (Is_Tag (Node (ADT)));
3958 -- Start of processing for Collect_Interfaces_Info
3961 Collect_Interfaces (T, Ifaces_List);
3962 Collect_Interface_Components (T, Comps_List);
3964 -- Search for the record component and tag associated with each
3965 -- interface type of T.
3967 Components_List := New_Elmt_List;
3968 Tags_List := New_Elmt_List;
3970 Iface_Elmt := First_Elmt (Ifaces_List);
3971 while Present (Iface_Elmt) loop
3972 Iface := Node (Iface_Elmt);
3974 -- Associate the primary tag component and the primary dispatch table
3975 -- with all the interfaces that are parents of T
3977 if Is_Ancestor (Iface, T, Use_Full_View => True) then
3978 Append_Elmt (First_Tag_Component (T), Components_List);
3979 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
3981 -- Otherwise search for the tag component and secondary dispatch
3985 Comp_Elmt := First_Elmt (Comps_List);
3986 while Present (Comp_Elmt) loop
3987 Comp_Iface := Related_Type (Node (Comp_Elmt));
3989 if Comp_Iface = Iface
3990 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
3992 Append_Elmt (Node (Comp_Elmt), Components_List);
3993 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
3997 Next_Elmt (Comp_Elmt);
3999 pragma Assert (Present (Comp_Elmt));
4002 Next_Elmt (Iface_Elmt);
4004 end Collect_Interfaces_Info;
4006 ---------------------
4007 -- Collect_Parents --
4008 ---------------------
4010 procedure Collect_Parents
4012 List : out Elist_Id;
4013 Use_Full_View : Boolean := True)
4015 Current_Typ : Entity_Id := T;
4016 Parent_Typ : Entity_Id;
4019 List := New_Elmt_List;
4021 -- No action if the if the type has no parents
4023 if T = Etype (T) then
4028 Parent_Typ := Etype (Current_Typ);
4030 if Is_Private_Type (Parent_Typ)
4031 and then Present (Full_View (Parent_Typ))
4032 and then Use_Full_View
4034 Parent_Typ := Full_View (Base_Type (Parent_Typ));
4037 Append_Elmt (Parent_Typ, List);
4039 exit when Parent_Typ = Current_Typ;
4040 Current_Typ := Parent_Typ;
4042 end Collect_Parents;
4044 ----------------------------------
4045 -- Collect_Primitive_Operations --
4046 ----------------------------------
4048 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
4049 B_Type : constant Entity_Id := Base_Type (T);
4050 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
4051 B_Scope : Entity_Id := Scope (B_Type);
4055 Is_Type_In_Pkg : Boolean;
4056 Formal_Derived : Boolean := False;
4059 function Match (E : Entity_Id) return Boolean;
4060 -- True if E's base type is B_Type, or E is of an anonymous access type
4061 -- and the base type of its designated type is B_Type.
4067 function Match (E : Entity_Id) return Boolean is
4068 Etyp : Entity_Id := Etype (E);
4071 if Ekind (Etyp) = E_Anonymous_Access_Type then
4072 Etyp := Designated_Type (Etyp);
4075 -- In Ada 2012 a primitive operation may have a formal of an
4076 -- incomplete view of the parent type.
4078 return Base_Type (Etyp) = B_Type
4080 (Ada_Version >= Ada_2012
4081 and then Ekind (Etyp) = E_Incomplete_Type
4082 and then Full_View (Etyp) = B_Type);
4085 -- Start of processing for Collect_Primitive_Operations
4088 -- For tagged types, the primitive operations are collected as they
4089 -- are declared, and held in an explicit list which is simply returned.
4091 if Is_Tagged_Type (B_Type) then
4092 return Primitive_Operations (B_Type);
4094 -- An untagged generic type that is a derived type inherits the
4095 -- primitive operations of its parent type. Other formal types only
4096 -- have predefined operators, which are not explicitly represented.
4098 elsif Is_Generic_Type (B_Type) then
4099 if Nkind (B_Decl) = N_Formal_Type_Declaration
4100 and then Nkind (Formal_Type_Definition (B_Decl)) =
4101 N_Formal_Derived_Type_Definition
4103 Formal_Derived := True;
4105 return New_Elmt_List;
4109 Op_List := New_Elmt_List;
4111 if B_Scope = Standard_Standard then
4112 if B_Type = Standard_String then
4113 Append_Elmt (Standard_Op_Concat, Op_List);
4115 elsif B_Type = Standard_Wide_String then
4116 Append_Elmt (Standard_Op_Concatw, Op_List);
4122 -- Locate the primitive subprograms of the type
4125 -- The primitive operations appear after the base type, except
4126 -- if the derivation happens within the private part of B_Scope
4127 -- and the type is a private type, in which case both the type
4128 -- and some primitive operations may appear before the base
4129 -- type, and the list of candidates starts after the type.
4131 if In_Open_Scopes (B_Scope)
4132 and then Scope (T) = B_Scope
4133 and then In_Private_Part (B_Scope)
4135 Id := Next_Entity (T);
4137 -- In Ada 2012, If the type has an incomplete partial view, there
4138 -- may be primitive operations declared before the full view, so
4139 -- we need to start scanning from the incomplete view, which is
4140 -- earlier on the entity chain.
4142 elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration
4143 and then Present (Incomplete_View (Parent (B_Type)))
4145 Id := Defining_Entity (Incomplete_View (Parent (B_Type)));
4148 Id := Next_Entity (B_Type);
4151 -- Set flag if this is a type in a package spec
4154 Is_Package_Or_Generic_Package (B_Scope)
4156 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
4159 while Present (Id) loop
4161 -- Test whether the result type or any of the parameter types of
4162 -- each subprogram following the type match that type when the
4163 -- type is declared in a package spec, is a derived type, or the
4164 -- subprogram is marked as primitive. (The Is_Primitive test is
4165 -- needed to find primitives of nonderived types in declarative
4166 -- parts that happen to override the predefined "=" operator.)
4168 -- Note that generic formal subprograms are not considered to be
4169 -- primitive operations and thus are never inherited.
4171 if Is_Overloadable (Id)
4172 and then (Is_Type_In_Pkg
4173 or else Is_Derived_Type (B_Type)
4174 or else Is_Primitive (Id))
4175 and then Nkind (Parent (Parent (Id)))
4176 not in N_Formal_Subprogram_Declaration
4184 Formal := First_Formal (Id);
4185 while Present (Formal) loop
4186 if Match (Formal) then
4191 Next_Formal (Formal);
4195 -- For a formal derived type, the only primitives are the ones
4196 -- inherited from the parent type. Operations appearing in the
4197 -- package declaration are not primitive for it.
4200 and then (not Formal_Derived or else Present (Alias (Id)))
4202 -- In the special case of an equality operator aliased to
4203 -- an overriding dispatching equality belonging to the same
4204 -- type, we don't include it in the list of primitives.
4205 -- This avoids inheriting multiple equality operators when
4206 -- deriving from untagged private types whose full type is
4207 -- tagged, which can otherwise cause ambiguities. Note that
4208 -- this should only happen for this kind of untagged parent
4209 -- type, since normally dispatching operations are inherited
4210 -- using the type's Primitive_Operations list.
4212 if Chars (Id) = Name_Op_Eq
4213 and then Is_Dispatching_Operation (Id)
4214 and then Present (Alias (Id))
4215 and then Present (Overridden_Operation (Alias (Id)))
4216 and then Base_Type (Etype (First_Entity (Id))) =
4217 Base_Type (Etype (First_Entity (Alias (Id))))
4221 -- Include the subprogram in the list of primitives
4224 Append_Elmt (Id, Op_List);
4231 -- For a type declared in System, some of its operations may
4232 -- appear in the target-specific extension to System.
4235 and then B_Scope = RTU_Entity (System)
4236 and then Present_System_Aux
4238 B_Scope := System_Aux_Id;
4239 Id := First_Entity (System_Aux_Id);
4245 end Collect_Primitive_Operations;
4247 -----------------------------------
4248 -- Compile_Time_Constraint_Error --
4249 -----------------------------------
4251 function Compile_Time_Constraint_Error
4254 Ent : Entity_Id := Empty;
4255 Loc : Source_Ptr := No_Location;
4256 Warn : Boolean := False) return Node_Id
4258 Msgc : String (1 .. Msg'Length + 3);
4259 -- Copy of message, with room for possible ?? or << and ! at end
4265 -- Start of processing for Compile_Time_Constraint_Error
4268 -- If this is a warning, convert it into an error if we are in code
4269 -- subject to SPARK_Mode being set ON.
4271 Error_Msg_Warn := SPARK_Mode /= On;
4273 -- A static constraint error in an instance body is not a fatal error.
4274 -- we choose to inhibit the message altogether, because there is no
4275 -- obvious node (for now) on which to post it. On the other hand the
4276 -- offending node must be replaced with a constraint_error in any case.
4278 -- No messages are generated if we already posted an error on this node
4280 if not Error_Posted (N) then
4281 if Loc /= No_Location then
4287 -- Copy message to Msgc, converting any ? in the message into
4288 -- < instead, so that we have an error in GNATprove mode.
4292 for J in 1 .. Msgl loop
4293 if Msg (J) = '?' and then (J = 1 or else Msg (J) /= ''') then
4296 Msgc (J) := Msg (J);
4300 -- Message is a warning, even in Ada 95 case
4302 if Msg (Msg'Last) = '?' or else Msg (Msg'Last) = '<' then
4305 -- In Ada 83, all messages are warnings. In the private part and
4306 -- the body of an instance, constraint_checks are only warnings.
4307 -- We also make this a warning if the Warn parameter is set.
4310 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
4318 elsif In_Instance_Not_Visible then
4325 -- Otherwise we have a real error message (Ada 95 static case)
4326 -- and we make this an unconditional message. Note that in the
4327 -- warning case we do not make the message unconditional, it seems
4328 -- quite reasonable to delete messages like this (about exceptions
4329 -- that will be raised) in dead code.
4337 -- One more test, skip the warning if the related expression is
4338 -- statically unevaluated, since we don't want to warn about what
4339 -- will happen when something is evaluated if it never will be
4342 if not Is_Statically_Unevaluated (N) then
4343 Error_Msg_Warn := SPARK_Mode /= On;
4345 if Present (Ent) then
4346 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
4348 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
4353 -- Check whether the context is an Init_Proc
4355 if Inside_Init_Proc then
4357 Conc_Typ : constant Entity_Id :=
4358 Corresponding_Concurrent_Type
4359 (Entity (Parameter_Type (First
4360 (Parameter_Specifications
4361 (Parent (Current_Scope))))));
4364 -- Don't complain if the corresponding concurrent type
4365 -- doesn't come from source (i.e. a single task/protected
4368 if Present (Conc_Typ)
4369 and then not Comes_From_Source (Conc_Typ)
4372 ("\& [<<", N, Standard_Constraint_Error, Eloc);
4375 if GNATprove_Mode then
4377 ("\& would have been raised for objects of this "
4378 & "type", N, Standard_Constraint_Error, Eloc);
4381 ("\& will be raised for objects of this type??",
4382 N, Standard_Constraint_Error, Eloc);
4388 Error_Msg_NEL ("\& [<<", N, Standard_Constraint_Error, Eloc);
4392 Error_Msg ("\static expression fails Constraint_Check", Eloc);
4393 Set_Error_Posted (N);
4399 end Compile_Time_Constraint_Error;
4401 -----------------------
4402 -- Conditional_Delay --
4403 -----------------------
4405 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
4407 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
4408 Set_Has_Delayed_Freeze (New_Ent);
4410 end Conditional_Delay;
4412 ----------------------------
4413 -- Contains_Refined_State --
4414 ----------------------------
4416 function Contains_Refined_State (Prag : Node_Id) return Boolean is
4417 function Has_State_In_Dependency (List : Node_Id) return Boolean;
4418 -- Determine whether a dependency list mentions a state with a visible
4421 function Has_State_In_Global (List : Node_Id) return Boolean;
4422 -- Determine whether a global list mentions a state with a visible
4425 function Is_Refined_State (Item : Node_Id) return Boolean;
4426 -- Determine whether Item is a reference to an abstract state with a
4427 -- visible refinement.
4429 -----------------------------
4430 -- Has_State_In_Dependency --
4431 -----------------------------
4433 function Has_State_In_Dependency (List : Node_Id) return Boolean is
4438 -- A null dependency list does not mention any states
4440 if Nkind (List) = N_Null then
4443 -- Dependency clauses appear as component associations of an
4446 elsif Nkind (List) = N_Aggregate
4447 and then Present (Component_Associations (List))
4449 Clause := First (Component_Associations (List));
4450 while Present (Clause) loop
4452 -- Inspect the outputs of a dependency clause
4454 Output := First (Choices (Clause));
4455 while Present (Output) loop
4456 if Is_Refined_State (Output) then
4463 -- Inspect the outputs of a dependency clause
4465 if Is_Refined_State (Expression (Clause)) then
4472 -- If we get here, then none of the dependency clauses mention a
4473 -- state with visible refinement.
4477 -- An illegal pragma managed to sneak in
4480 raise Program_Error;
4482 end Has_State_In_Dependency;
4484 -------------------------
4485 -- Has_State_In_Global --
4486 -------------------------
4488 function Has_State_In_Global (List : Node_Id) return Boolean is
4492 -- A null global list does not mention any states
4494 if Nkind (List) = N_Null then
4497 -- Simple global list or moded global list declaration
4499 elsif Nkind (List) = N_Aggregate then
4501 -- The declaration of a simple global list appear as a collection
4504 if Present (Expressions (List)) then
4505 Item := First (Expressions (List));
4506 while Present (Item) loop
4507 if Is_Refined_State (Item) then
4514 -- The declaration of a moded global list appears as a collection
4515 -- of component associations where individual choices denote
4519 Item := First (Component_Associations (List));
4520 while Present (Item) loop
4521 if Has_State_In_Global (Expression (Item)) then
4529 -- If we get here, then the simple/moded global list did not
4530 -- mention any states with a visible refinement.
4534 -- Single global item declaration
4536 elsif Is_Entity_Name (List) then
4537 return Is_Refined_State (List);
4539 -- An illegal pragma managed to sneak in
4542 raise Program_Error;
4544 end Has_State_In_Global;
4546 ----------------------
4547 -- Is_Refined_State --
4548 ----------------------
4550 function Is_Refined_State (Item : Node_Id) return Boolean is
4552 Item_Id : Entity_Id;
4555 if Nkind (Item) = N_Null then
4558 -- States cannot be subject to attribute 'Result. This case arises
4559 -- in dependency relations.
4561 elsif Nkind (Item) = N_Attribute_Reference
4562 and then Attribute_Name (Item) = Name_Result
4566 -- Multiple items appear as an aggregate. This case arises in
4567 -- dependency relations.
4569 elsif Nkind (Item) = N_Aggregate
4570 and then Present (Expressions (Item))
4572 Elmt := First (Expressions (Item));
4573 while Present (Elmt) loop
4574 if Is_Refined_State (Elmt) then
4581 -- If we get here, then none of the inputs or outputs reference a
4582 -- state with visible refinement.
4589 Item_Id := Entity_Of (Item);
4593 and then Ekind (Item_Id) = E_Abstract_State
4594 and then Has_Visible_Refinement (Item_Id);
4596 end Is_Refined_State;
4600 Arg : constant Node_Id :=
4601 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
4602 Nam : constant Name_Id := Pragma_Name (Prag);
4604 -- Start of processing for Contains_Refined_State
4607 if Nam = Name_Depends then
4608 return Has_State_In_Dependency (Arg);
4610 else pragma Assert (Nam = Name_Global);
4611 return Has_State_In_Global (Arg);
4613 end Contains_Refined_State;
4615 -------------------------
4616 -- Copy_Component_List --
4617 -------------------------
4619 function Copy_Component_List
4621 Loc : Source_Ptr) return List_Id
4624 Comps : constant List_Id := New_List;
4627 Comp := First_Component (Underlying_Type (R_Typ));
4628 while Present (Comp) loop
4629 if Comes_From_Source (Comp) then
4631 Comp_Decl : constant Node_Id := Declaration_Node (Comp);
4634 Make_Component_Declaration (Loc,
4635 Defining_Identifier =>
4636 Make_Defining_Identifier (Loc, Chars (Comp)),
4637 Component_Definition =>
4639 (Component_Definition (Comp_Decl), New_Sloc => Loc)));
4643 Next_Component (Comp);
4647 end Copy_Component_List;
4649 -------------------------
4650 -- Copy_Parameter_List --
4651 -------------------------
4653 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
4654 Loc : constant Source_Ptr := Sloc (Subp_Id);
4659 if No (First_Formal (Subp_Id)) then
4663 Formal := First_Formal (Subp_Id);
4664 while Present (Formal) loop
4666 Make_Parameter_Specification (Loc,
4667 Defining_Identifier =>
4668 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
4669 In_Present => In_Present (Parent (Formal)),
4670 Out_Present => Out_Present (Parent (Formal)),
4672 New_Occurrence_Of (Etype (Formal), Loc),
4674 New_Copy_Tree (Expression (Parent (Formal)))));
4676 Next_Formal (Formal);
4681 end Copy_Parameter_List;
4683 --------------------------
4684 -- Copy_Subprogram_Spec --
4685 --------------------------
4687 function Copy_Subprogram_Spec (Spec : Node_Id) return Node_Id is
4689 Formal_Spec : Node_Id;
4693 -- The structure of the original tree must be replicated without any
4694 -- alterations. Use New_Copy_Tree for this purpose.
4696 Result := New_Copy_Tree (Spec);
4698 -- Create a new entity for the defining unit name
4700 Def_Id := Defining_Unit_Name (Result);
4701 Set_Defining_Unit_Name (Result,
4702 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
4704 -- Create new entities for the formal parameters
4706 if Present (Parameter_Specifications (Result)) then
4707 Formal_Spec := First (Parameter_Specifications (Result));
4708 while Present (Formal_Spec) loop
4709 Def_Id := Defining_Identifier (Formal_Spec);
4710 Set_Defining_Identifier (Formal_Spec,
4711 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
4718 end Copy_Subprogram_Spec;
4720 --------------------------------
4721 -- Corresponding_Generic_Type --
4722 --------------------------------
4724 function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id is
4730 if not Is_Generic_Actual_Type (T) then
4733 -- If the actual is the actual of an enclosing instance, resolution
4734 -- was correct in the generic.
4736 elsif Nkind (Parent (T)) = N_Subtype_Declaration
4737 and then Is_Entity_Name (Subtype_Indication (Parent (T)))
4739 Is_Generic_Actual_Type (Entity (Subtype_Indication (Parent (T))))
4746 if Is_Wrapper_Package (Inst) then
4747 Inst := Related_Instance (Inst);
4752 (Specification (Unit_Declaration_Node (Inst)));
4754 -- Generic actual has the same name as the corresponding formal
4756 Typ := First_Entity (Gen);
4757 while Present (Typ) loop
4758 if Chars (Typ) = Chars (T) then
4767 end Corresponding_Generic_Type;
4769 --------------------
4770 -- Current_Entity --
4771 --------------------
4773 -- The currently visible definition for a given identifier is the
4774 -- one most chained at the start of the visibility chain, i.e. the
4775 -- one that is referenced by the Node_Id value of the name of the
4776 -- given identifier.
4778 function Current_Entity (N : Node_Id) return Entity_Id is
4780 return Get_Name_Entity_Id (Chars (N));
4783 -----------------------------
4784 -- Current_Entity_In_Scope --
4785 -----------------------------
4787 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
4789 CS : constant Entity_Id := Current_Scope;
4791 Transient_Case : constant Boolean := Scope_Is_Transient;
4794 E := Get_Name_Entity_Id (Chars (N));
4796 and then Scope (E) /= CS
4797 and then (not Transient_Case or else Scope (E) /= Scope (CS))
4803 end Current_Entity_In_Scope;
4809 function Current_Scope return Entity_Id is
4811 if Scope_Stack.Last = -1 then
4812 return Standard_Standard;
4815 C : constant Entity_Id :=
4816 Scope_Stack.Table (Scope_Stack.Last).Entity;
4821 return Standard_Standard;
4827 ------------------------
4828 -- Current_Subprogram --
4829 ------------------------
4831 function Current_Subprogram return Entity_Id is
4832 Scop : constant Entity_Id := Current_Scope;
4834 if Is_Subprogram_Or_Generic_Subprogram (Scop) then
4837 return Enclosing_Subprogram (Scop);
4839 end Current_Subprogram;
4841 ----------------------------------
4842 -- Deepest_Type_Access_Level --
4843 ----------------------------------
4845 function Deepest_Type_Access_Level (Typ : Entity_Id) return Uint is
4847 if Ekind (Typ) = E_Anonymous_Access_Type
4848 and then not Is_Local_Anonymous_Access (Typ)
4849 and then Nkind (Associated_Node_For_Itype (Typ)) = N_Object_Declaration
4851 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
4855 Scope_Depth (Enclosing_Dynamic_Scope
4856 (Defining_Identifier
4857 (Associated_Node_For_Itype (Typ))));
4859 -- For generic formal type, return Int'Last (infinite).
4860 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
4862 elsif Is_Generic_Type (Root_Type (Typ)) then
4863 return UI_From_Int (Int'Last);
4866 return Type_Access_Level (Typ);
4868 end Deepest_Type_Access_Level;
4870 ---------------------
4871 -- Defining_Entity --
4872 ---------------------
4874 function Defining_Entity (N : Node_Id) return Entity_Id is
4875 K : constant Node_Kind := Nkind (N);
4876 Err : Entity_Id := Empty;
4881 N_Subprogram_Declaration |
4882 N_Abstract_Subprogram_Declaration |
4884 N_Package_Declaration |
4885 N_Subprogram_Renaming_Declaration |
4886 N_Subprogram_Body_Stub |
4887 N_Generic_Subprogram_Declaration |
4888 N_Generic_Package_Declaration |
4889 N_Formal_Subprogram_Declaration |
4890 N_Expression_Function
4892 return Defining_Entity (Specification (N));
4895 N_Component_Declaration |
4896 N_Defining_Program_Unit_Name |
4897 N_Discriminant_Specification |
4899 N_Entry_Declaration |
4900 N_Entry_Index_Specification |
4901 N_Exception_Declaration |
4902 N_Exception_Renaming_Declaration |
4903 N_Formal_Object_Declaration |
4904 N_Formal_Package_Declaration |
4905 N_Formal_Type_Declaration |
4906 N_Full_Type_Declaration |
4907 N_Implicit_Label_Declaration |
4908 N_Incomplete_Type_Declaration |
4909 N_Loop_Parameter_Specification |
4910 N_Number_Declaration |
4911 N_Object_Declaration |
4912 N_Object_Renaming_Declaration |
4913 N_Package_Body_Stub |
4914 N_Parameter_Specification |
4915 N_Private_Extension_Declaration |
4916 N_Private_Type_Declaration |
4918 N_Protected_Body_Stub |
4919 N_Protected_Type_Declaration |
4920 N_Single_Protected_Declaration |
4921 N_Single_Task_Declaration |
4922 N_Subtype_Declaration |
4925 N_Task_Type_Declaration
4927 return Defining_Identifier (N);
4930 return Defining_Entity (Proper_Body (N));
4933 N_Function_Instantiation |
4934 N_Function_Specification |
4935 N_Generic_Function_Renaming_Declaration |
4936 N_Generic_Package_Renaming_Declaration |
4937 N_Generic_Procedure_Renaming_Declaration |
4939 N_Package_Instantiation |
4940 N_Package_Renaming_Declaration |
4941 N_Package_Specification |
4942 N_Procedure_Instantiation |
4943 N_Procedure_Specification
4946 Nam : constant Node_Id := Defining_Unit_Name (N);
4949 if Nkind (Nam) in N_Entity then
4952 -- For Error, make up a name and attach to declaration
4953 -- so we can continue semantic analysis
4955 elsif Nam = Error then
4956 Err := Make_Temporary (Sloc (N), 'T');
4957 Set_Defining_Unit_Name (N, Err);
4961 -- If not an entity, get defining identifier
4964 return Defining_Identifier (Nam);
4972 return Entity (Identifier (N));
4975 raise Program_Error;
4978 end Defining_Entity;
4980 --------------------------
4981 -- Denotes_Discriminant --
4982 --------------------------
4984 function Denotes_Discriminant
4986 Check_Concurrent : Boolean := False) return Boolean
4991 if not Is_Entity_Name (N) or else No (Entity (N)) then
4997 -- If we are checking for a protected type, the discriminant may have
4998 -- been rewritten as the corresponding discriminal of the original type
4999 -- or of the corresponding concurrent record, depending on whether we
5000 -- are in the spec or body of the protected type.
5002 return Ekind (E) = E_Discriminant
5005 and then Ekind (E) = E_In_Parameter
5006 and then Present (Discriminal_Link (E))
5008 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
5010 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
5012 end Denotes_Discriminant;
5014 -------------------------
5015 -- Denotes_Same_Object --
5016 -------------------------
5018 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
5019 Obj1 : Node_Id := A1;
5020 Obj2 : Node_Id := A2;
5022 function Has_Prefix (N : Node_Id) return Boolean;
5023 -- Return True if N has attribute Prefix
5025 function Is_Renaming (N : Node_Id) return Boolean;
5026 -- Return true if N names a renaming entity
5028 function Is_Valid_Renaming (N : Node_Id) return Boolean;
5029 -- For renamings, return False if the prefix of any dereference within
5030 -- the renamed object_name is a variable, or any expression within the
5031 -- renamed object_name contains references to variables or calls on
5032 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
5038 function Has_Prefix (N : Node_Id) return Boolean is
5042 N_Attribute_Reference,
5044 N_Explicit_Dereference,
5045 N_Indexed_Component,
5047 N_Selected_Component,
5055 function Is_Renaming (N : Node_Id) return Boolean is
5057 return Is_Entity_Name (N)
5058 and then Present (Renamed_Entity (Entity (N)));
5061 -----------------------
5062 -- Is_Valid_Renaming --
5063 -----------------------
5065 function Is_Valid_Renaming (N : Node_Id) return Boolean is
5067 function Check_Renaming (N : Node_Id) return Boolean;
5068 -- Recursive function used to traverse all the prefixes of N
5070 function Check_Renaming (N : Node_Id) return Boolean is
5073 and then not Check_Renaming (Renamed_Entity (Entity (N)))
5078 if Nkind (N) = N_Indexed_Component then
5083 Indx := First (Expressions (N));
5084 while Present (Indx) loop
5085 if not Is_OK_Static_Expression (Indx) then
5094 if Has_Prefix (N) then
5096 P : constant Node_Id := Prefix (N);
5099 if Nkind (N) = N_Explicit_Dereference
5100 and then Is_Variable (P)
5104 elsif Is_Entity_Name (P)
5105 and then Ekind (Entity (P)) = E_Function
5109 elsif Nkind (P) = N_Function_Call then
5113 -- Recursion to continue traversing the prefix of the
5114 -- renaming expression
5116 return Check_Renaming (P);
5123 -- Start of processing for Is_Valid_Renaming
5126 return Check_Renaming (N);
5127 end Is_Valid_Renaming;
5129 -- Start of processing for Denotes_Same_Object
5132 -- Both names statically denote the same stand-alone object or parameter
5133 -- (RM 6.4.1(6.5/3))
5135 if Is_Entity_Name (Obj1)
5136 and then Is_Entity_Name (Obj2)
5137 and then Entity (Obj1) = Entity (Obj2)
5142 -- For renamings, the prefix of any dereference within the renamed
5143 -- object_name is not a variable, and any expression within the
5144 -- renamed object_name contains no references to variables nor
5145 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
5147 if Is_Renaming (Obj1) then
5148 if Is_Valid_Renaming (Obj1) then
5149 Obj1 := Renamed_Entity (Entity (Obj1));
5155 if Is_Renaming (Obj2) then
5156 if Is_Valid_Renaming (Obj2) then
5157 Obj2 := Renamed_Entity (Entity (Obj2));
5163 -- No match if not same node kind (such cases are handled by
5164 -- Denotes_Same_Prefix)
5166 if Nkind (Obj1) /= Nkind (Obj2) then
5169 -- After handling valid renamings, one of the two names statically
5170 -- denoted a renaming declaration whose renamed object_name is known
5171 -- to denote the same object as the other (RM 6.4.1(6.10/3))
5173 elsif Is_Entity_Name (Obj1) then
5174 if Is_Entity_Name (Obj2) then
5175 return Entity (Obj1) = Entity (Obj2);
5180 -- Both names are selected_components, their prefixes are known to
5181 -- denote the same object, and their selector_names denote the same
5182 -- component (RM 6.4.1(6.6/3)).
5184 elsif Nkind (Obj1) = N_Selected_Component then
5185 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
5187 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
5189 -- Both names are dereferences and the dereferenced names are known to
5190 -- denote the same object (RM 6.4.1(6.7/3))
5192 elsif Nkind (Obj1) = N_Explicit_Dereference then
5193 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
5195 -- Both names are indexed_components, their prefixes are known to denote
5196 -- the same object, and each of the pairs of corresponding index values
5197 -- are either both static expressions with the same static value or both
5198 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
5200 elsif Nkind (Obj1) = N_Indexed_Component then
5201 if not Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
5209 Indx1 := First (Expressions (Obj1));
5210 Indx2 := First (Expressions (Obj2));
5211 while Present (Indx1) loop
5213 -- Indexes must denote the same static value or same object
5215 if Is_OK_Static_Expression (Indx1) then
5216 if not Is_OK_Static_Expression (Indx2) then
5219 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
5223 elsif not Denotes_Same_Object (Indx1, Indx2) then
5235 -- Both names are slices, their prefixes are known to denote the same
5236 -- object, and the two slices have statically matching index constraints
5237 -- (RM 6.4.1(6.9/3))
5239 elsif Nkind (Obj1) = N_Slice
5240 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
5243 Lo1, Lo2, Hi1, Hi2 : Node_Id;
5246 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
5247 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
5249 -- Check whether bounds are statically identical. There is no
5250 -- attempt to detect partial overlap of slices.
5252 return Denotes_Same_Object (Lo1, Lo2)
5254 Denotes_Same_Object (Hi1, Hi2);
5257 -- In the recursion, literals appear as indexes
5259 elsif Nkind (Obj1) = N_Integer_Literal
5261 Nkind (Obj2) = N_Integer_Literal
5263 return Intval (Obj1) = Intval (Obj2);
5268 end Denotes_Same_Object;
5270 -------------------------
5271 -- Denotes_Same_Prefix --
5272 -------------------------
5274 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
5277 if Is_Entity_Name (A1) then
5278 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
5279 and then not Is_Access_Type (Etype (A1))
5281 return Denotes_Same_Object (A1, Prefix (A2))
5282 or else Denotes_Same_Prefix (A1, Prefix (A2));
5287 elsif Is_Entity_Name (A2) then
5288 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
5290 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
5292 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
5295 Root1, Root2 : Node_Id;
5296 Depth1, Depth2 : Int := 0;
5299 Root1 := Prefix (A1);
5300 while not Is_Entity_Name (Root1) loop
5302 (Root1, N_Selected_Component, N_Indexed_Component)
5306 Root1 := Prefix (Root1);
5309 Depth1 := Depth1 + 1;
5312 Root2 := Prefix (A2);
5313 while not Is_Entity_Name (Root2) loop
5314 if not Nkind_In (Root2, N_Selected_Component,
5315 N_Indexed_Component)
5319 Root2 := Prefix (Root2);
5322 Depth2 := Depth2 + 1;
5325 -- If both have the same depth and they do not denote the same
5326 -- object, they are disjoint and no warning is needed.
5328 if Depth1 = Depth2 then
5331 elsif Depth1 > Depth2 then
5332 Root1 := Prefix (A1);
5333 for J in 1 .. Depth1 - Depth2 - 1 loop
5334 Root1 := Prefix (Root1);
5337 return Denotes_Same_Object (Root1, A2);
5340 Root2 := Prefix (A2);
5341 for J in 1 .. Depth2 - Depth1 - 1 loop
5342 Root2 := Prefix (Root2);
5345 return Denotes_Same_Object (A1, Root2);
5352 end Denotes_Same_Prefix;
5354 ----------------------
5355 -- Denotes_Variable --
5356 ----------------------
5358 function Denotes_Variable (N : Node_Id) return Boolean is
5360 return Is_Variable (N) and then Paren_Count (N) = 0;
5361 end Denotes_Variable;
5363 -----------------------------
5364 -- Depends_On_Discriminant --
5365 -----------------------------
5367 function Depends_On_Discriminant (N : Node_Id) return Boolean is
5372 Get_Index_Bounds (N, L, H);
5373 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
5374 end Depends_On_Discriminant;
5376 -------------------------
5377 -- Designate_Same_Unit --
5378 -------------------------
5380 function Designate_Same_Unit
5382 Name2 : Node_Id) return Boolean
5384 K1 : constant Node_Kind := Nkind (Name1);
5385 K2 : constant Node_Kind := Nkind (Name2);
5387 function Prefix_Node (N : Node_Id) return Node_Id;
5388 -- Returns the parent unit name node of a defining program unit name
5389 -- or the prefix if N is a selected component or an expanded name.
5391 function Select_Node (N : Node_Id) return Node_Id;
5392 -- Returns the defining identifier node of a defining program unit
5393 -- name or the selector node if N is a selected component or an
5400 function Prefix_Node (N : Node_Id) return Node_Id is
5402 if Nkind (N) = N_Defining_Program_Unit_Name then
5413 function Select_Node (N : Node_Id) return Node_Id is
5415 if Nkind (N) = N_Defining_Program_Unit_Name then
5416 return Defining_Identifier (N);
5418 return Selector_Name (N);
5422 -- Start of processing for Designate_Same_Unit
5425 if Nkind_In (K1, N_Identifier, N_Defining_Identifier)
5427 Nkind_In (K2, N_Identifier, N_Defining_Identifier)
5429 return Chars (Name1) = Chars (Name2);
5431 elsif Nkind_In (K1, N_Expanded_Name,
5432 N_Selected_Component,
5433 N_Defining_Program_Unit_Name)
5435 Nkind_In (K2, N_Expanded_Name,
5436 N_Selected_Component,
5437 N_Defining_Program_Unit_Name)
5440 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
5442 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
5447 end Designate_Same_Unit;
5449 ------------------------------------------
5450 -- function Dynamic_Accessibility_Level --
5451 ------------------------------------------
5453 function Dynamic_Accessibility_Level (Expr : Node_Id) return Node_Id is
5455 Loc : constant Source_Ptr := Sloc (Expr);
5457 function Make_Level_Literal (Level : Uint) return Node_Id;
5458 -- Construct an integer literal representing an accessibility level
5459 -- with its type set to Natural.
5461 ------------------------
5462 -- Make_Level_Literal --
5463 ------------------------
5465 function Make_Level_Literal (Level : Uint) return Node_Id is
5466 Result : constant Node_Id := Make_Integer_Literal (Loc, Level);
5468 Set_Etype (Result, Standard_Natural);
5470 end Make_Level_Literal;
5472 -- Start of processing for Dynamic_Accessibility_Level
5475 if Is_Entity_Name (Expr) then
5478 if Present (Renamed_Object (E)) then
5479 return Dynamic_Accessibility_Level (Renamed_Object (E));
5482 if Is_Formal (E) or else Ekind_In (E, E_Variable, E_Constant) then
5483 if Present (Extra_Accessibility (E)) then
5484 return New_Occurrence_Of (Extra_Accessibility (E), Loc);
5489 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
5491 case Nkind (Expr) is
5493 -- For access discriminant, the level of the enclosing object
5495 when N_Selected_Component =>
5496 if Ekind (Entity (Selector_Name (Expr))) = E_Discriminant
5497 and then Ekind (Etype (Entity (Selector_Name (Expr)))) =
5498 E_Anonymous_Access_Type
5500 return Make_Level_Literal (Object_Access_Level (Expr));
5503 when N_Attribute_Reference =>
5504 case Get_Attribute_Id (Attribute_Name (Expr)) is
5506 -- For X'Access, the level of the prefix X
5508 when Attribute_Access =>
5509 return Make_Level_Literal
5510 (Object_Access_Level (Prefix (Expr)));
5512 -- Treat the unchecked attributes as library-level
5514 when Attribute_Unchecked_Access |
5515 Attribute_Unrestricted_Access =>
5516 return Make_Level_Literal (Scope_Depth (Standard_Standard));
5518 -- No other access-valued attributes
5521 raise Program_Error;
5526 -- Unimplemented: depends on context. As an actual parameter where
5527 -- formal type is anonymous, use
5528 -- Scope_Depth (Current_Scope) + 1.
5529 -- For other cases, see 3.10.2(14/3) and following. ???
5533 when N_Type_Conversion =>
5534 if not Is_Local_Anonymous_Access (Etype (Expr)) then
5536 -- Handle type conversions introduced for a rename of an
5537 -- Ada 2012 stand-alone object of an anonymous access type.
5539 return Dynamic_Accessibility_Level (Expression (Expr));
5546 return Make_Level_Literal (Type_Access_Level (Etype (Expr)));
5547 end Dynamic_Accessibility_Level;
5549 -----------------------------------
5550 -- Effective_Extra_Accessibility --
5551 -----------------------------------
5553 function Effective_Extra_Accessibility (Id : Entity_Id) return Entity_Id is
5555 if Present (Renamed_Object (Id))
5556 and then Is_Entity_Name (Renamed_Object (Id))
5558 return Effective_Extra_Accessibility (Entity (Renamed_Object (Id)));
5560 return Extra_Accessibility (Id);
5562 end Effective_Extra_Accessibility;
5564 -----------------------------
5565 -- Effective_Reads_Enabled --
5566 -----------------------------
5568 function Effective_Reads_Enabled (Id : Entity_Id) return Boolean is
5570 return Has_Enabled_Property (Id, Name_Effective_Reads);
5571 end Effective_Reads_Enabled;
5573 ------------------------------
5574 -- Effective_Writes_Enabled --
5575 ------------------------------
5577 function Effective_Writes_Enabled (Id : Entity_Id) return Boolean is
5579 return Has_Enabled_Property (Id, Name_Effective_Writes);
5580 end Effective_Writes_Enabled;
5582 ------------------------------
5583 -- Enclosing_Comp_Unit_Node --
5584 ------------------------------
5586 function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id is
5587 Current_Node : Node_Id;
5591 while Present (Current_Node)
5592 and then Nkind (Current_Node) /= N_Compilation_Unit
5594 Current_Node := Parent (Current_Node);
5597 if Nkind (Current_Node) /= N_Compilation_Unit then
5600 return Current_Node;
5602 end Enclosing_Comp_Unit_Node;
5604 --------------------------
5605 -- Enclosing_CPP_Parent --
5606 --------------------------
5608 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
5609 Parent_Typ : Entity_Id := Typ;
5612 while not Is_CPP_Class (Parent_Typ)
5613 and then Etype (Parent_Typ) /= Parent_Typ
5615 Parent_Typ := Etype (Parent_Typ);
5617 if Is_Private_Type (Parent_Typ) then
5618 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5622 pragma Assert (Is_CPP_Class (Parent_Typ));
5624 end Enclosing_CPP_Parent;
5626 ---------------------------
5627 -- Enclosing_Declaration --
5628 ---------------------------
5630 function Enclosing_Declaration (N : Node_Id) return Node_Id is
5631 Decl : Node_Id := N;
5634 while Present (Decl)
5635 and then not (Nkind (Decl) in N_Declaration
5637 Nkind (Decl) in N_Later_Decl_Item)
5639 Decl := Parent (Decl);
5643 end Enclosing_Declaration;
5645 ----------------------------
5646 -- Enclosing_Generic_Body --
5647 ----------------------------
5649 function Enclosing_Generic_Body
5650 (N : Node_Id) return Node_Id
5658 while Present (P) loop
5659 if Nkind (P) = N_Package_Body
5660 or else Nkind (P) = N_Subprogram_Body
5662 Spec := Corresponding_Spec (P);
5664 if Present (Spec) then
5665 Decl := Unit_Declaration_Node (Spec);
5667 if Nkind (Decl) = N_Generic_Package_Declaration
5668 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
5679 end Enclosing_Generic_Body;
5681 ----------------------------
5682 -- Enclosing_Generic_Unit --
5683 ----------------------------
5685 function Enclosing_Generic_Unit
5686 (N : Node_Id) return Node_Id
5694 while Present (P) loop
5695 if Nkind (P) = N_Generic_Package_Declaration
5696 or else Nkind (P) = N_Generic_Subprogram_Declaration
5700 elsif Nkind (P) = N_Package_Body
5701 or else Nkind (P) = N_Subprogram_Body
5703 Spec := Corresponding_Spec (P);
5705 if Present (Spec) then
5706 Decl := Unit_Declaration_Node (Spec);
5708 if Nkind (Decl) = N_Generic_Package_Declaration
5709 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
5720 end Enclosing_Generic_Unit;
5722 -------------------------------
5723 -- Enclosing_Lib_Unit_Entity --
5724 -------------------------------
5726 function Enclosing_Lib_Unit_Entity
5727 (E : Entity_Id := Current_Scope) return Entity_Id
5729 Unit_Entity : Entity_Id;
5732 -- Look for enclosing library unit entity by following scope links.
5733 -- Equivalent to, but faster than indexing through the scope stack.
5736 while (Present (Scope (Unit_Entity))
5737 and then Scope (Unit_Entity) /= Standard_Standard)
5738 and not Is_Child_Unit (Unit_Entity)
5740 Unit_Entity := Scope (Unit_Entity);
5744 end Enclosing_Lib_Unit_Entity;
5746 -----------------------------
5747 -- Enclosing_Lib_Unit_Node --
5748 -----------------------------
5750 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
5751 Encl_Unit : Node_Id;
5754 Encl_Unit := Enclosing_Comp_Unit_Node (N);
5755 while Present (Encl_Unit)
5756 and then Nkind (Unit (Encl_Unit)) = N_Subunit
5758 Encl_Unit := Library_Unit (Encl_Unit);
5762 end Enclosing_Lib_Unit_Node;
5764 -----------------------
5765 -- Enclosing_Package --
5766 -----------------------
5768 function Enclosing_Package (E : Entity_Id) return Entity_Id is
5769 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
5772 if Dynamic_Scope = Standard_Standard then
5773 return Standard_Standard;
5775 elsif Dynamic_Scope = Empty then
5778 elsif Ekind_In (Dynamic_Scope, E_Package, E_Package_Body,
5781 return Dynamic_Scope;
5784 return Enclosing_Package (Dynamic_Scope);
5786 end Enclosing_Package;
5788 -------------------------------------
5789 -- Enclosing_Package_Or_Subprogram --
5790 -------------------------------------
5792 function Enclosing_Package_Or_Subprogram (E : Entity_Id) return Entity_Id is
5797 while Present (S) loop
5798 if Is_Package_Or_Generic_Package (S)
5799 or else Ekind (S) = E_Package_Body
5803 elsif Is_Subprogram_Or_Generic_Subprogram (S)
5804 or else Ekind (S) = E_Subprogram_Body
5814 end Enclosing_Package_Or_Subprogram;
5816 --------------------------
5817 -- Enclosing_Subprogram --
5818 --------------------------
5820 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
5821 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
5824 if Dynamic_Scope = Standard_Standard then
5827 elsif Dynamic_Scope = Empty then
5830 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
5831 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
5833 elsif Ekind (Dynamic_Scope) = E_Block
5834 or else Ekind (Dynamic_Scope) = E_Return_Statement
5836 return Enclosing_Subprogram (Dynamic_Scope);
5838 elsif Ekind (Dynamic_Scope) = E_Task_Type then
5839 return Get_Task_Body_Procedure (Dynamic_Scope);
5841 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
5842 and then Present (Full_View (Dynamic_Scope))
5843 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
5845 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
5847 -- No body is generated if the protected operation is eliminated
5849 elsif Convention (Dynamic_Scope) = Convention_Protected
5850 and then not Is_Eliminated (Dynamic_Scope)
5851 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
5853 return Protected_Body_Subprogram (Dynamic_Scope);
5856 return Dynamic_Scope;
5858 end Enclosing_Subprogram;
5860 ------------------------
5861 -- Ensure_Freeze_Node --
5862 ------------------------
5864 procedure Ensure_Freeze_Node (E : Entity_Id) is
5867 if No (Freeze_Node (E)) then
5868 FN := Make_Freeze_Entity (Sloc (E));
5869 Set_Has_Delayed_Freeze (E);
5870 Set_Freeze_Node (E, FN);
5871 Set_Access_Types_To_Process (FN, No_Elist);
5872 Set_TSS_Elist (FN, No_Elist);
5875 end Ensure_Freeze_Node;
5881 procedure Enter_Name (Def_Id : Entity_Id) is
5882 C : constant Entity_Id := Current_Entity (Def_Id);
5883 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
5884 S : constant Entity_Id := Current_Scope;
5887 Generate_Definition (Def_Id);
5889 -- Add new name to current scope declarations. Check for duplicate
5890 -- declaration, which may or may not be a genuine error.
5894 -- Case of previous entity entered because of a missing declaration
5895 -- or else a bad subtype indication. Best is to use the new entity,
5896 -- and make the previous one invisible.
5898 if Etype (E) = Any_Type then
5899 Set_Is_Immediately_Visible (E, False);
5901 -- Case of renaming declaration constructed for package instances.
5902 -- if there is an explicit declaration with the same identifier,
5903 -- the renaming is not immediately visible any longer, but remains
5904 -- visible through selected component notation.
5906 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
5907 and then not Comes_From_Source (E)
5909 Set_Is_Immediately_Visible (E, False);
5911 -- The new entity may be the package renaming, which has the same
5912 -- same name as a generic formal which has been seen already.
5914 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
5915 and then not Comes_From_Source (Def_Id)
5917 Set_Is_Immediately_Visible (E, False);
5919 -- For a fat pointer corresponding to a remote access to subprogram,
5920 -- we use the same identifier as the RAS type, so that the proper
5921 -- name appears in the stub. This type is only retrieved through
5922 -- the RAS type and never by visibility, and is not added to the
5923 -- visibility list (see below).
5925 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
5926 and then Ekind (Def_Id) = E_Record_Type
5927 and then Present (Corresponding_Remote_Type (Def_Id))
5931 -- Case of an implicit operation or derived literal. The new entity
5932 -- hides the implicit one, which is removed from all visibility,
5933 -- i.e. the entity list of its scope, and homonym chain of its name.
5935 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
5936 or else Is_Internal (E)
5940 Prev_Vis : Entity_Id;
5941 Decl : constant Node_Id := Parent (E);
5944 -- If E is an implicit declaration, it cannot be the first
5945 -- entity in the scope.
5947 Prev := First_Entity (Current_Scope);
5948 while Present (Prev) and then Next_Entity (Prev) /= E loop
5954 -- If E is not on the entity chain of the current scope,
5955 -- it is an implicit declaration in the generic formal
5956 -- part of a generic subprogram. When analyzing the body,
5957 -- the generic formals are visible but not on the entity
5958 -- chain of the subprogram. The new entity will become
5959 -- the visible one in the body.
5962 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
5966 Set_Next_Entity (Prev, Next_Entity (E));
5968 if No (Next_Entity (Prev)) then
5969 Set_Last_Entity (Current_Scope, Prev);
5972 if E = Current_Entity (E) then
5976 Prev_Vis := Current_Entity (E);
5977 while Homonym (Prev_Vis) /= E loop
5978 Prev_Vis := Homonym (Prev_Vis);
5982 if Present (Prev_Vis) then
5984 -- Skip E in the visibility chain
5986 Set_Homonym (Prev_Vis, Homonym (E));
5989 Set_Name_Entity_Id (Chars (E), Homonym (E));
5994 -- This section of code could use a comment ???
5996 elsif Present (Etype (E))
5997 and then Is_Concurrent_Type (Etype (E))
6002 -- If the homograph is a protected component renaming, it should not
6003 -- be hiding the current entity. Such renamings are treated as weak
6006 elsif Is_Prival (E) then
6007 Set_Is_Immediately_Visible (E, False);
6009 -- In this case the current entity is a protected component renaming.
6010 -- Perform minimal decoration by setting the scope and return since
6011 -- the prival should not be hiding other visible entities.
6013 elsif Is_Prival (Def_Id) then
6014 Set_Scope (Def_Id, Current_Scope);
6017 -- Analogous to privals, the discriminal generated for an entry index
6018 -- parameter acts as a weak declaration. Perform minimal decoration
6019 -- to avoid bogus errors.
6021 elsif Is_Discriminal (Def_Id)
6022 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
6024 Set_Scope (Def_Id, Current_Scope);
6027 -- In the body or private part of an instance, a type extension may
6028 -- introduce a component with the same name as that of an actual. The
6029 -- legality rule is not enforced, but the semantics of the full type
6030 -- with two components of same name are not clear at this point???
6032 elsif In_Instance_Not_Visible then
6035 -- When compiling a package body, some child units may have become
6036 -- visible. They cannot conflict with local entities that hide them.
6038 elsif Is_Child_Unit (E)
6039 and then In_Open_Scopes (Scope (E))
6040 and then not Is_Immediately_Visible (E)
6044 -- Conversely, with front-end inlining we may compile the parent body
6045 -- first, and a child unit subsequently. The context is now the
6046 -- parent spec, and body entities are not visible.
6048 elsif Is_Child_Unit (Def_Id)
6049 and then Is_Package_Body_Entity (E)
6050 and then not In_Package_Body (Current_Scope)
6054 -- Case of genuine duplicate declaration
6057 Error_Msg_Sloc := Sloc (E);
6059 -- If the previous declaration is an incomplete type declaration
6060 -- this may be an attempt to complete it with a private type. The
6061 -- following avoids confusing cascaded errors.
6063 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
6064 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
6067 ("incomplete type cannot be completed with a private " &
6068 "declaration", Parent (Def_Id));
6069 Set_Is_Immediately_Visible (E, False);
6070 Set_Full_View (E, Def_Id);
6072 -- An inherited component of a record conflicts with a new
6073 -- discriminant. The discriminant is inserted first in the scope,
6074 -- but the error should be posted on it, not on the component.
6076 elsif Ekind (E) = E_Discriminant
6077 and then Present (Scope (Def_Id))
6078 and then Scope (Def_Id) /= Current_Scope
6080 Error_Msg_Sloc := Sloc (Def_Id);
6081 Error_Msg_N ("& conflicts with declaration#", E);
6084 -- If the name of the unit appears in its own context clause, a
6085 -- dummy package with the name has already been created, and the
6086 -- error emitted. Try to continue quietly.
6088 elsif Error_Posted (E)
6089 and then Sloc (E) = No_Location
6090 and then Nkind (Parent (E)) = N_Package_Specification
6091 and then Current_Scope = Standard_Standard
6093 Set_Scope (Def_Id, Current_Scope);
6097 Error_Msg_N ("& conflicts with declaration#", Def_Id);
6099 -- Avoid cascaded messages with duplicate components in
6102 if Ekind_In (E, E_Component, E_Discriminant) then
6107 if Nkind (Parent (Parent (Def_Id))) =
6108 N_Generic_Subprogram_Declaration
6110 Defining_Entity (Specification (Parent (Parent (Def_Id))))
6112 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
6115 -- If entity is in standard, then we are in trouble, because it
6116 -- means that we have a library package with a duplicated name.
6117 -- That's hard to recover from, so abort.
6119 if S = Standard_Standard then
6120 raise Unrecoverable_Error;
6122 -- Otherwise we continue with the declaration. Having two
6123 -- identical declarations should not cause us too much trouble.
6131 -- If we fall through, declaration is OK, at least OK enough to continue
6133 -- If Def_Id is a discriminant or a record component we are in the midst
6134 -- of inheriting components in a derived record definition. Preserve
6135 -- their Ekind and Etype.
6137 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
6140 -- If a type is already set, leave it alone (happens when a type
6141 -- declaration is reanalyzed following a call to the optimizer).
6143 elsif Present (Etype (Def_Id)) then
6146 -- Otherwise, the kind E_Void insures that premature uses of the entity
6147 -- will be detected. Any_Type insures that no cascaded errors will occur
6150 Set_Ekind (Def_Id, E_Void);
6151 Set_Etype (Def_Id, Any_Type);
6154 -- Inherited discriminants and components in derived record types are
6155 -- immediately visible. Itypes are not.
6157 -- Unless the Itype is for a record type with a corresponding remote
6158 -- type (what is that about, it was not commented ???)
6160 if Ekind_In (Def_Id, E_Discriminant, E_Component)
6162 ((not Is_Record_Type (Def_Id)
6163 or else No (Corresponding_Remote_Type (Def_Id)))
6164 and then not Is_Itype (Def_Id))
6166 Set_Is_Immediately_Visible (Def_Id);
6167 Set_Current_Entity (Def_Id);
6170 Set_Homonym (Def_Id, C);
6171 Append_Entity (Def_Id, S);
6172 Set_Public_Status (Def_Id);
6174 -- Declaring a homonym is not allowed in SPARK ...
6176 if Present (C) and then Restriction_Check_Required (SPARK_05) then
6178 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
6179 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
6180 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
6183 -- ... unless the new declaration is in a subprogram, and the
6184 -- visible declaration is a variable declaration or a parameter
6185 -- specification outside that subprogram.
6187 if Present (Enclosing_Subp)
6188 and then Nkind_In (Parent (C), N_Object_Declaration,
6189 N_Parameter_Specification)
6190 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
6194 -- ... or the new declaration is in a package, and the visible
6195 -- declaration occurs outside that package.
6197 elsif Present (Enclosing_Pack)
6198 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
6202 -- ... or the new declaration is a component declaration in a
6203 -- record type definition.
6205 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
6208 -- Don't issue error for non-source entities
6210 elsif Comes_From_Source (Def_Id)
6211 and then Comes_From_Source (C)
6213 Error_Msg_Sloc := Sloc (C);
6214 Check_SPARK_05_Restriction
6215 ("redeclaration of identifier &#", Def_Id);
6220 -- Warn if new entity hides an old one
6222 if Warn_On_Hiding and then Present (C)
6224 -- Don't warn for record components since they always have a well
6225 -- defined scope which does not confuse other uses. Note that in
6226 -- some cases, Ekind has not been set yet.
6228 and then Ekind (C) /= E_Component
6229 and then Ekind (C) /= E_Discriminant
6230 and then Nkind (Parent (C)) /= N_Component_Declaration
6231 and then Ekind (Def_Id) /= E_Component
6232 and then Ekind (Def_Id) /= E_Discriminant
6233 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
6235 -- Don't warn for one character variables. It is too common to use
6236 -- such variables as locals and will just cause too many false hits.
6238 and then Length_Of_Name (Chars (C)) /= 1
6240 -- Don't warn for non-source entities
6242 and then Comes_From_Source (C)
6243 and then Comes_From_Source (Def_Id)
6245 -- Don't warn unless entity in question is in extended main source
6247 and then In_Extended_Main_Source_Unit (Def_Id)
6249 -- Finally, the hidden entity must be either immediately visible or
6250 -- use visible (i.e. from a used package).
6253 (Is_Immediately_Visible (C)
6255 Is_Potentially_Use_Visible (C))
6257 Error_Msg_Sloc := Sloc (C);
6258 Error_Msg_N ("declaration hides &#?h?", Def_Id);
6266 function Entity_Of (N : Node_Id) return Entity_Id is
6272 if Is_Entity_Name (N) then
6275 -- Follow a possible chain of renamings to reach the root renamed
6278 while Present (Id) and then Present (Renamed_Object (Id)) loop
6279 if Is_Entity_Name (Renamed_Object (Id)) then
6280 Id := Entity (Renamed_Object (Id));
6291 --------------------------
6292 -- Explain_Limited_Type --
6293 --------------------------
6295 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
6299 -- For array, component type must be limited
6301 if Is_Array_Type (T) then
6302 Error_Msg_Node_2 := T;
6304 ("\component type& of type& is limited", N, Component_Type (T));
6305 Explain_Limited_Type (Component_Type (T), N);
6307 elsif Is_Record_Type (T) then
6309 -- No need for extra messages if explicit limited record
6311 if Is_Limited_Record (Base_Type (T)) then
6315 -- Otherwise find a limited component. Check only components that
6316 -- come from source, or inherited components that appear in the
6317 -- source of the ancestor.
6319 C := First_Component (T);
6320 while Present (C) loop
6321 if Is_Limited_Type (Etype (C))
6323 (Comes_From_Source (C)
6325 (Present (Original_Record_Component (C))
6327 Comes_From_Source (Original_Record_Component (C))))
6329 Error_Msg_Node_2 := T;
6330 Error_Msg_NE ("\component& of type& has limited type", N, C);
6331 Explain_Limited_Type (Etype (C), N);
6338 -- The type may be declared explicitly limited, even if no component
6339 -- of it is limited, in which case we fall out of the loop.
6342 end Explain_Limited_Type;
6344 -------------------------------
6345 -- Extensions_Visible_Status --
6346 -------------------------------
6348 function Extensions_Visible_Status
6349 (Id : Entity_Id) return Extensions_Visible_Mode
6358 -- When a formal parameter is subject to Extensions_Visible, the pragma
6359 -- is stored in the contract of related subprogram.
6361 if Is_Formal (Id) then
6364 elsif Is_Subprogram_Or_Generic_Subprogram (Id) then
6367 -- No other construct carries this pragma
6370 return Extensions_Visible_None;
6373 Prag := Get_Pragma (Subp, Pragma_Extensions_Visible);
6375 -- In certain cases analysis may request the Extensions_Visible status
6376 -- of an expression function before the pragma has been analyzed yet.
6377 -- Inspect the declarative items after the expression function looking
6378 -- for the pragma (if any).
6380 if No (Prag) and then Is_Expression_Function (Subp) then
6381 Decl := Next (Unit_Declaration_Node (Subp));
6382 while Present (Decl) loop
6383 if Nkind (Decl) = N_Pragma
6384 and then Pragma_Name (Decl) = Name_Extensions_Visible
6389 -- A source construct ends the region where Extensions_Visible may
6390 -- appear, stop the traversal. An expanded expression function is
6391 -- no longer a source construct, but it must still be recognized.
6393 elsif Comes_From_Source (Decl)
6395 (Nkind_In (Decl, N_Subprogram_Body,
6396 N_Subprogram_Declaration)
6397 and then Is_Expression_Function (Defining_Entity (Decl)))
6406 -- Extract the value from the Boolean expression (if any)
6408 if Present (Prag) then
6409 Arg := First (Pragma_Argument_Associations (Prag));
6411 if Present (Arg) then
6412 Expr := Get_Pragma_Arg (Arg);
6414 -- When the associated subprogram is an expression function, the
6415 -- argument of the pragma may not have been analyzed.
6417 if not Analyzed (Expr) then
6418 Preanalyze_And_Resolve (Expr, Standard_Boolean);
6421 -- Guard against cascading errors when the argument of pragma
6422 -- Extensions_Visible is not a valid static Boolean expression.
6424 if Error_Posted (Expr) then
6425 return Extensions_Visible_None;
6427 elsif Is_True (Expr_Value (Expr)) then
6428 return Extensions_Visible_True;
6431 return Extensions_Visible_False;
6434 -- Otherwise the aspect or pragma defaults to True
6437 return Extensions_Visible_True;
6440 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
6441 -- directly specified. In SPARK code, its value defaults to "False".
6443 elsif SPARK_Mode = On then
6444 return Extensions_Visible_False;
6446 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
6450 return Extensions_Visible_True;
6452 end Extensions_Visible_Status;
6458 procedure Find_Actual
6460 Formal : out Entity_Id;
6463 Context : constant Node_Id := Parent (N);
6468 if Nkind_In (Context, N_Indexed_Component, N_Selected_Component)
6469 and then N = Prefix (Context)
6471 Find_Actual (Context, Formal, Call);
6474 elsif Nkind (Context) = N_Parameter_Association
6475 and then N = Explicit_Actual_Parameter (Context)
6477 Call := Parent (Context);
6479 elsif Nkind_In (Context, N_Entry_Call_Statement,
6481 N_Procedure_Call_Statement)
6491 -- If we have a call to a subprogram look for the parameter. Note that
6492 -- we exclude overloaded calls, since we don't know enough to be sure
6493 -- of giving the right answer in this case.
6495 if Nkind_In (Call, N_Entry_Call_Statement,
6497 N_Procedure_Call_Statement)
6499 Call_Nam := Name (Call);
6501 -- A call to a protected or task entry appears as a selected
6502 -- component rather than an expanded name.
6504 if Nkind (Call_Nam) = N_Selected_Component then
6505 Call_Nam := Selector_Name (Call_Nam);
6508 if Is_Entity_Name (Call_Nam)
6509 and then Present (Entity (Call_Nam))
6510 and then Is_Overloadable (Entity (Call_Nam))
6511 and then not Is_Overloaded (Call_Nam)
6513 -- If node is name in call it is not an actual
6515 if N = Call_Nam then
6521 -- Fall here if we are definitely a parameter
6523 Actual := First_Actual (Call);
6524 Formal := First_Formal (Entity (Call_Nam));
6525 while Present (Formal) and then Present (Actual) loop
6529 -- An actual that is the prefix in a prefixed call may have
6530 -- been rewritten in the call, after the deferred reference
6531 -- was collected. Check if sloc and kinds and names match.
6533 elsif Sloc (Actual) = Sloc (N)
6534 and then Nkind (Actual) = N_Identifier
6535 and then Nkind (Actual) = Nkind (N)
6536 and then Chars (Actual) = Chars (N)
6541 Actual := Next_Actual (Actual);
6542 Formal := Next_Formal (Formal);
6548 -- Fall through here if we did not find matching actual
6554 ---------------------------
6555 -- Find_Body_Discriminal --
6556 ---------------------------
6558 function Find_Body_Discriminal
6559 (Spec_Discriminant : Entity_Id) return Entity_Id
6565 -- If expansion is suppressed, then the scope can be the concurrent type
6566 -- itself rather than a corresponding concurrent record type.
6568 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
6569 Tsk := Scope (Spec_Discriminant);
6572 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
6574 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
6577 -- Find discriminant of original concurrent type, and use its current
6578 -- discriminal, which is the renaming within the task/protected body.
6580 Disc := First_Discriminant (Tsk);
6581 while Present (Disc) loop
6582 if Chars (Disc) = Chars (Spec_Discriminant) then
6583 return Discriminal (Disc);
6586 Next_Discriminant (Disc);
6589 -- That loop should always succeed in finding a matching entry and
6590 -- returning. Fatal error if not.
6592 raise Program_Error;
6593 end Find_Body_Discriminal;
6595 -------------------------------------
6596 -- Find_Corresponding_Discriminant --
6597 -------------------------------------
6599 function Find_Corresponding_Discriminant
6601 Typ : Entity_Id) return Entity_Id
6603 Par_Disc : Entity_Id;
6604 Old_Disc : Entity_Id;
6605 New_Disc : Entity_Id;
6608 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
6610 -- The original type may currently be private, and the discriminant
6611 -- only appear on its full view.
6613 if Is_Private_Type (Scope (Par_Disc))
6614 and then not Has_Discriminants (Scope (Par_Disc))
6615 and then Present (Full_View (Scope (Par_Disc)))
6617 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
6619 Old_Disc := First_Discriminant (Scope (Par_Disc));
6622 if Is_Class_Wide_Type (Typ) then
6623 New_Disc := First_Discriminant (Root_Type (Typ));
6625 New_Disc := First_Discriminant (Typ);
6628 while Present (Old_Disc) and then Present (New_Disc) loop
6629 if Old_Disc = Par_Disc then
6633 Next_Discriminant (Old_Disc);
6634 Next_Discriminant (New_Disc);
6637 -- Should always find it
6639 raise Program_Error;
6640 end Find_Corresponding_Discriminant;
6642 ----------------------------------
6643 -- Find_Enclosing_Iterator_Loop --
6644 ----------------------------------
6646 function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id is
6651 -- Traverse the scope chain looking for an iterator loop. Such loops are
6652 -- usually transformed into blocks, hence the use of Original_Node.
6655 while Present (S) and then S /= Standard_Standard loop
6656 if Ekind (S) = E_Loop
6657 and then Nkind (Parent (S)) = N_Implicit_Label_Declaration
6659 Constr := Original_Node (Label_Construct (Parent (S)));
6661 if Nkind (Constr) = N_Loop_Statement
6662 and then Present (Iteration_Scheme (Constr))
6663 and then Nkind (Iterator_Specification
6664 (Iteration_Scheme (Constr))) =
6665 N_Iterator_Specification
6675 end Find_Enclosing_Iterator_Loop;
6677 ------------------------------------
6678 -- Find_Loop_In_Conditional_Block --
6679 ------------------------------------
6681 function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is
6687 if Nkind (Stmt) = N_If_Statement then
6688 Stmt := First (Then_Statements (Stmt));
6691 pragma Assert (Nkind (Stmt) = N_Block_Statement);
6693 -- Inspect the statements of the conditional block. In general the loop
6694 -- should be the first statement in the statement sequence of the block,
6695 -- but the finalization machinery may have introduced extra object
6698 Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
6699 while Present (Stmt) loop
6700 if Nkind (Stmt) = N_Loop_Statement then
6707 -- The expansion of attribute 'Loop_Entry produced a malformed block
6709 raise Program_Error;
6710 end Find_Loop_In_Conditional_Block;
6712 --------------------------
6713 -- Find_Overlaid_Entity --
6714 --------------------------
6716 procedure Find_Overlaid_Entity
6718 Ent : out Entity_Id;
6724 -- We are looking for one of the two following forms:
6726 -- for X'Address use Y'Address
6730 -- Const : constant Address := expr;
6732 -- for X'Address use Const;
6734 -- In the second case, the expr is either Y'Address, or recursively a
6735 -- constant that eventually references Y'Address.
6740 if Nkind (N) = N_Attribute_Definition_Clause
6741 and then Chars (N) = Name_Address
6743 Expr := Expression (N);
6745 -- This loop checks the form of the expression for Y'Address,
6746 -- using recursion to deal with intermediate constants.
6749 -- Check for Y'Address
6751 if Nkind (Expr) = N_Attribute_Reference
6752 and then Attribute_Name (Expr) = Name_Address
6754 Expr := Prefix (Expr);
6757 -- Check for Const where Const is a constant entity
6759 elsif Is_Entity_Name (Expr)
6760 and then Ekind (Entity (Expr)) = E_Constant
6762 Expr := Constant_Value (Entity (Expr));
6764 -- Anything else does not need checking
6771 -- This loop checks the form of the prefix for an entity, using
6772 -- recursion to deal with intermediate components.
6775 -- Check for Y where Y is an entity
6777 if Is_Entity_Name (Expr) then
6778 Ent := Entity (Expr);
6781 -- Check for components
6784 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component)
6786 Expr := Prefix (Expr);
6789 -- Anything else does not need checking
6796 end Find_Overlaid_Entity;
6798 -------------------------
6799 -- Find_Parameter_Type --
6800 -------------------------
6802 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
6804 if Nkind (Param) /= N_Parameter_Specification then
6807 -- For an access parameter, obtain the type from the formal entity
6808 -- itself, because access to subprogram nodes do not carry a type.
6809 -- Shouldn't we always use the formal entity ???
6811 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
6812 return Etype (Defining_Identifier (Param));
6815 return Etype (Parameter_Type (Param));
6817 end Find_Parameter_Type;
6819 -----------------------------------
6820 -- Find_Placement_In_State_Space --
6821 -----------------------------------
6823 procedure Find_Placement_In_State_Space
6824 (Item_Id : Entity_Id;
6825 Placement : out State_Space_Kind;
6826 Pack_Id : out Entity_Id)
6828 Context : Entity_Id;
6831 -- Assume that the item does not appear in the state space of a package
6833 Placement := Not_In_Package;
6836 -- Climb the scope stack and examine the enclosing context
6838 Context := Scope (Item_Id);
6839 while Present (Context) and then Context /= Standard_Standard loop
6840 if Ekind (Context) = E_Package then
6843 -- A package body is a cut off point for the traversal as the item
6844 -- cannot be visible to the outside from this point on. Note that
6845 -- this test must be done first as a body is also classified as a
6848 if In_Package_Body (Context) then
6849 Placement := Body_State_Space;
6852 -- The private part of a package is a cut off point for the
6853 -- traversal as the item cannot be visible to the outside from
6856 elsif In_Private_Part (Context) then
6857 Placement := Private_State_Space;
6860 -- When the item appears in the visible state space of a package,
6861 -- continue to climb the scope stack as this may not be the final
6865 Placement := Visible_State_Space;
6867 -- The visible state space of a child unit acts as the proper
6868 -- placement of an item.
6870 if Is_Child_Unit (Context) then
6875 -- The item or its enclosing package appear in a construct that has
6879 Placement := Not_In_Package;
6883 Context := Scope (Context);
6885 end Find_Placement_In_State_Space;
6887 ------------------------
6888 -- Find_Specific_Type --
6889 ------------------------
6891 function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
6892 Typ : Entity_Id := Root_Type (CW);
6895 if Ekind (Typ) = E_Incomplete_Type then
6896 if From_Limited_With (Typ) then
6897 Typ := Non_Limited_View (Typ);
6899 Typ := Full_View (Typ);
6903 if Is_Private_Type (Typ)
6904 and then not Is_Tagged_Type (Typ)
6905 and then Present (Full_View (Typ))
6907 return Full_View (Typ);
6911 end Find_Specific_Type;
6913 -----------------------------
6914 -- Find_Static_Alternative --
6915 -----------------------------
6917 function Find_Static_Alternative (N : Node_Id) return Node_Id is
6918 Expr : constant Node_Id := Expression (N);
6919 Val : constant Uint := Expr_Value (Expr);
6924 Alt := First (Alternatives (N));
6927 if Nkind (Alt) /= N_Pragma then
6928 Choice := First (Discrete_Choices (Alt));
6929 while Present (Choice) loop
6931 -- Others choice, always matches
6933 if Nkind (Choice) = N_Others_Choice then
6936 -- Range, check if value is in the range
6938 elsif Nkind (Choice) = N_Range then
6940 Val >= Expr_Value (Low_Bound (Choice))
6942 Val <= Expr_Value (High_Bound (Choice));
6944 -- Choice is a subtype name. Note that we know it must
6945 -- be a static subtype, since otherwise it would have
6946 -- been diagnosed as illegal.
6948 elsif Is_Entity_Name (Choice)
6949 and then Is_Type (Entity (Choice))
6951 exit Search when Is_In_Range (Expr, Etype (Choice),
6952 Assume_Valid => False);
6954 -- Choice is a subtype indication
6956 elsif Nkind (Choice) = N_Subtype_Indication then
6958 C : constant Node_Id := Constraint (Choice);
6959 R : constant Node_Id := Range_Expression (C);
6963 Val >= Expr_Value (Low_Bound (R))
6965 Val <= Expr_Value (High_Bound (R));
6968 -- Choice is a simple expression
6971 exit Search when Val = Expr_Value (Choice);
6979 pragma Assert (Present (Alt));
6982 -- The above loop *must* terminate by finding a match, since
6983 -- we know the case statement is valid, and the value of the
6984 -- expression is known at compile time. When we fall out of
6985 -- the loop, Alt points to the alternative that we know will
6986 -- be selected at run time.
6989 end Find_Static_Alternative;
6995 function First_Actual (Node : Node_Id) return Node_Id is
6999 if No (Parameter_Associations (Node)) then
7003 N := First (Parameter_Associations (Node));
7005 if Nkind (N) = N_Parameter_Association then
7006 return First_Named_Actual (Node);
7012 -----------------------
7013 -- Gather_Components --
7014 -----------------------
7016 procedure Gather_Components
7018 Comp_List : Node_Id;
7019 Governed_By : List_Id;
7021 Report_Errors : out Boolean)
7025 Discrete_Choice : Node_Id;
7026 Comp_Item : Node_Id;
7028 Discrim : Entity_Id;
7029 Discrim_Name : Node_Id;
7030 Discrim_Value : Node_Id;
7033 Report_Errors := False;
7035 if No (Comp_List) or else Null_Present (Comp_List) then
7038 elsif Present (Component_Items (Comp_List)) then
7039 Comp_Item := First (Component_Items (Comp_List));
7045 while Present (Comp_Item) loop
7047 -- Skip the tag of a tagged record, the interface tags, as well
7048 -- as all items that are not user components (anonymous types,
7049 -- rep clauses, Parent field, controller field).
7051 if Nkind (Comp_Item) = N_Component_Declaration then
7053 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
7055 if not Is_Tag (Comp) and then Chars (Comp) /= Name_uParent then
7056 Append_Elmt (Comp, Into);
7064 if No (Variant_Part (Comp_List)) then
7067 Discrim_Name := Name (Variant_Part (Comp_List));
7068 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
7071 -- Look for the discriminant that governs this variant part.
7072 -- The discriminant *must* be in the Governed_By List
7074 Assoc := First (Governed_By);
7075 Find_Constraint : loop
7076 Discrim := First (Choices (Assoc));
7077 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
7078 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
7080 Chars (Corresponding_Discriminant (Entity (Discrim))) =
7081 Chars (Discrim_Name))
7082 or else Chars (Original_Record_Component (Entity (Discrim)))
7083 = Chars (Discrim_Name);
7085 if No (Next (Assoc)) then
7086 if not Is_Constrained (Typ)
7087 and then Is_Derived_Type (Typ)
7088 and then Present (Stored_Constraint (Typ))
7090 -- If the type is a tagged type with inherited discriminants,
7091 -- use the stored constraint on the parent in order to find
7092 -- the values of discriminants that are otherwise hidden by an
7093 -- explicit constraint. Renamed discriminants are handled in
7096 -- If several parent discriminants are renamed by a single
7097 -- discriminant of the derived type, the call to obtain the
7098 -- Corresponding_Discriminant field only retrieves the last
7099 -- of them. We recover the constraint on the others from the
7100 -- Stored_Constraint as well.
7107 D := First_Discriminant (Etype (Typ));
7108 C := First_Elmt (Stored_Constraint (Typ));
7109 while Present (D) and then Present (C) loop
7110 if Chars (Discrim_Name) = Chars (D) then
7111 if Is_Entity_Name (Node (C))
7112 and then Entity (Node (C)) = Entity (Discrim)
7114 -- D is renamed by Discrim, whose value is given in
7121 Make_Component_Association (Sloc (Typ),
7123 (New_Occurrence_Of (D, Sloc (Typ))),
7124 Duplicate_Subexpr_No_Checks (Node (C)));
7126 exit Find_Constraint;
7129 Next_Discriminant (D);
7136 if No (Next (Assoc)) then
7137 Error_Msg_NE (" missing value for discriminant&",
7138 First (Governed_By), Discrim_Name);
7139 Report_Errors := True;
7144 end loop Find_Constraint;
7146 Discrim_Value := Expression (Assoc);
7148 if not Is_OK_Static_Expression (Discrim_Value) then
7150 -- If the variant part is governed by a discriminant of the type
7151 -- this is an error. If the variant part and the discriminant are
7152 -- inherited from an ancestor this is legal (AI05-120) unless the
7153 -- components are being gathered for an aggregate, in which case
7154 -- the caller must check Report_Errors.
7156 if Scope (Original_Record_Component
7157 ((Entity (First (Choices (Assoc)))))) = Typ
7160 ("value for discriminant & must be static!",
7161 Discrim_Value, Discrim);
7162 Why_Not_Static (Discrim_Value);
7165 Report_Errors := True;
7169 Search_For_Discriminant_Value : declare
7175 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
7178 Find_Discrete_Value : while Present (Variant) loop
7179 Discrete_Choice := First (Discrete_Choices (Variant));
7180 while Present (Discrete_Choice) loop
7181 exit Find_Discrete_Value when
7182 Nkind (Discrete_Choice) = N_Others_Choice;
7184 Get_Index_Bounds (Discrete_Choice, Low, High);
7186 UI_Low := Expr_Value (Low);
7187 UI_High := Expr_Value (High);
7189 exit Find_Discrete_Value when
7190 UI_Low <= UI_Discrim_Value
7192 UI_High >= UI_Discrim_Value;
7194 Next (Discrete_Choice);
7197 Next_Non_Pragma (Variant);
7198 end loop Find_Discrete_Value;
7199 end Search_For_Discriminant_Value;
7201 if No (Variant) then
7203 ("value of discriminant & is out of range", Discrim_Value, Discrim);
7204 Report_Errors := True;
7208 -- If we have found the corresponding choice, recursively add its
7209 -- components to the Into list. The nested components are part of
7210 -- the same record type.
7213 (Typ, Component_List (Variant), Governed_By, Into, Report_Errors);
7214 end Gather_Components;
7216 ------------------------
7217 -- Get_Actual_Subtype --
7218 ------------------------
7220 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
7221 Typ : constant Entity_Id := Etype (N);
7222 Utyp : Entity_Id := Underlying_Type (Typ);
7231 -- If what we have is an identifier that references a subprogram
7232 -- formal, or a variable or constant object, then we get the actual
7233 -- subtype from the referenced entity if one has been built.
7235 if Nkind (N) = N_Identifier
7237 (Is_Formal (Entity (N))
7238 or else Ekind (Entity (N)) = E_Constant
7239 or else Ekind (Entity (N)) = E_Variable)
7240 and then Present (Actual_Subtype (Entity (N)))
7242 return Actual_Subtype (Entity (N));
7244 -- Actual subtype of unchecked union is always itself. We never need
7245 -- the "real" actual subtype. If we did, we couldn't get it anyway
7246 -- because the discriminant is not available. The restrictions on
7247 -- Unchecked_Union are designed to make sure that this is OK.
7249 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
7252 -- Here for the unconstrained case, we must find actual subtype
7253 -- No actual subtype is available, so we must build it on the fly.
7255 -- Checking the type, not the underlying type, for constrainedness
7256 -- seems to be necessary. Maybe all the tests should be on the type???
7258 elsif (not Is_Constrained (Typ))
7259 and then (Is_Array_Type (Utyp)
7260 or else (Is_Record_Type (Utyp)
7261 and then Has_Discriminants (Utyp)))
7262 and then not Has_Unknown_Discriminants (Utyp)
7263 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
7265 -- Nothing to do if in spec expression (why not???)
7267 if In_Spec_Expression then
7270 elsif Is_Private_Type (Typ) and then not Has_Discriminants (Typ) then
7272 -- If the type has no discriminants, there is no subtype to
7273 -- build, even if the underlying type is discriminated.
7277 -- Else build the actual subtype
7280 Decl := Build_Actual_Subtype (Typ, N);
7281 Atyp := Defining_Identifier (Decl);
7283 -- If Build_Actual_Subtype generated a new declaration then use it
7287 -- The actual subtype is an Itype, so analyze the declaration,
7288 -- but do not attach it to the tree, to get the type defined.
7290 Set_Parent (Decl, N);
7291 Set_Is_Itype (Atyp);
7292 Analyze (Decl, Suppress => All_Checks);
7293 Set_Associated_Node_For_Itype (Atyp, N);
7294 Set_Has_Delayed_Freeze (Atyp, False);
7296 -- We need to freeze the actual subtype immediately. This is
7297 -- needed, because otherwise this Itype will not get frozen
7298 -- at all, and it is always safe to freeze on creation because
7299 -- any associated types must be frozen at this point.
7301 Freeze_Itype (Atyp, N);
7304 -- Otherwise we did not build a declaration, so return original
7311 -- For all remaining cases, the actual subtype is the same as
7312 -- the nominal type.
7317 end Get_Actual_Subtype;
7319 -------------------------------------
7320 -- Get_Actual_Subtype_If_Available --
7321 -------------------------------------
7323 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
7324 Typ : constant Entity_Id := Etype (N);
7327 -- If what we have is an identifier that references a subprogram
7328 -- formal, or a variable or constant object, then we get the actual
7329 -- subtype from the referenced entity if one has been built.
7331 if Nkind (N) = N_Identifier
7333 (Is_Formal (Entity (N))
7334 or else Ekind (Entity (N)) = E_Constant
7335 or else Ekind (Entity (N)) = E_Variable)
7336 and then Present (Actual_Subtype (Entity (N)))
7338 return Actual_Subtype (Entity (N));
7340 -- Otherwise the Etype of N is returned unchanged
7345 end Get_Actual_Subtype_If_Available;
7347 ------------------------
7348 -- Get_Body_From_Stub --
7349 ------------------------
7351 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
7353 return Proper_Body (Unit (Library_Unit (N)));
7354 end Get_Body_From_Stub;
7356 ---------------------
7357 -- Get_Cursor_Type --
7358 ---------------------
7360 function Get_Cursor_Type
7362 Typ : Entity_Id) return Entity_Id
7366 First_Op : Entity_Id;
7370 -- If error already detected, return
7372 if Error_Posted (Aspect) then
7376 -- The cursor type for an Iterable aspect is the return type of a
7377 -- non-overloaded First primitive operation. Locate association for
7380 Assoc := First (Component_Associations (Expression (Aspect)));
7382 while Present (Assoc) loop
7383 if Chars (First (Choices (Assoc))) = Name_First then
7384 First_Op := Expression (Assoc);
7391 if First_Op = Any_Id then
7392 Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
7398 -- Locate function with desired name and profile in scope of type
7400 Func := First_Entity (Scope (Typ));
7401 while Present (Func) loop
7402 if Chars (Func) = Chars (First_Op)
7403 and then Ekind (Func) = E_Function
7404 and then Present (First_Formal (Func))
7405 and then Etype (First_Formal (Func)) = Typ
7406 and then No (Next_Formal (First_Formal (Func)))
7408 if Cursor /= Any_Type then
7410 ("Operation First for iterable type must be unique", Aspect);
7413 Cursor := Etype (Func);
7420 -- If not found, no way to resolve remaining primitives.
7422 if Cursor = Any_Type then
7424 ("No legal primitive operation First for Iterable type", Aspect);
7428 end Get_Cursor_Type;
7430 function Get_Cursor_Type (Typ : Entity_Id) return Entity_Id is
7432 return Etype (Get_Iterable_Type_Primitive (Typ, Name_First));
7433 end Get_Cursor_Type;
7435 -------------------------------
7436 -- Get_Default_External_Name --
7437 -------------------------------
7439 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
7441 Get_Decoded_Name_String (Chars (E));
7443 if Opt.External_Name_Imp_Casing = Uppercase then
7444 Set_Casing (All_Upper_Case);
7446 Set_Casing (All_Lower_Case);
7450 Make_String_Literal (Sloc (E),
7451 Strval => String_From_Name_Buffer);
7452 end Get_Default_External_Name;
7454 --------------------------
7455 -- Get_Enclosing_Object --
7456 --------------------------
7458 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
7460 if Is_Entity_Name (N) then
7464 when N_Indexed_Component |
7466 N_Selected_Component =>
7468 -- If not generating code, a dereference may be left implicit.
7469 -- In thoses cases, return Empty.
7471 if Is_Access_Type (Etype (Prefix (N))) then
7474 return Get_Enclosing_Object (Prefix (N));
7477 when N_Type_Conversion =>
7478 return Get_Enclosing_Object (Expression (N));
7484 end Get_Enclosing_Object;
7486 ---------------------------
7487 -- Get_Enum_Lit_From_Pos --
7488 ---------------------------
7490 function Get_Enum_Lit_From_Pos
7493 Loc : Source_Ptr) return Node_Id
7495 Btyp : Entity_Id := Base_Type (T);
7499 -- In the case where the literal is of type Character, Wide_Character
7500 -- or Wide_Wide_Character or of a type derived from them, there needs
7501 -- to be some special handling since there is no explicit chain of
7502 -- literals to search. Instead, an N_Character_Literal node is created
7503 -- with the appropriate Char_Code and Chars fields.
7505 if Is_Standard_Character_Type (T) then
7506 Set_Character_Literal_Name (UI_To_CC (Pos));
7508 Make_Character_Literal (Loc,
7510 Char_Literal_Value => Pos);
7512 -- For all other cases, we have a complete table of literals, and
7513 -- we simply iterate through the chain of literal until the one
7514 -- with the desired position value is found.
7517 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
7518 Btyp := Full_View (Btyp);
7521 Lit := First_Literal (Btyp);
7522 for J in 1 .. UI_To_Int (Pos) loop
7526 return New_Occurrence_Of (Lit, Loc);
7528 end Get_Enum_Lit_From_Pos;
7530 ------------------------
7531 -- Get_Generic_Entity --
7532 ------------------------
7534 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
7535 Ent : constant Entity_Id := Entity (Name (N));
7537 if Present (Renamed_Object (Ent)) then
7538 return Renamed_Object (Ent);
7542 end Get_Generic_Entity;
7544 -------------------------------------
7545 -- Get_Incomplete_View_Of_Ancestor --
7546 -------------------------------------
7548 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
7549 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
7550 Par_Scope : Entity_Id;
7551 Par_Type : Entity_Id;
7554 -- The incomplete view of an ancestor is only relevant for private
7555 -- derived types in child units.
7557 if not Is_Derived_Type (E)
7558 or else not Is_Child_Unit (Cur_Unit)
7563 Par_Scope := Scope (Cur_Unit);
7564 if No (Par_Scope) then
7568 Par_Type := Etype (Base_Type (E));
7570 -- Traverse list of ancestor types until we find one declared in
7571 -- a parent or grandparent unit (two levels seem sufficient).
7573 while Present (Par_Type) loop
7574 if Scope (Par_Type) = Par_Scope
7575 or else Scope (Par_Type) = Scope (Par_Scope)
7579 elsif not Is_Derived_Type (Par_Type) then
7583 Par_Type := Etype (Base_Type (Par_Type));
7587 -- If none found, there is no relevant ancestor type.
7591 end Get_Incomplete_View_Of_Ancestor;
7593 ----------------------
7594 -- Get_Index_Bounds --
7595 ----------------------
7597 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
7598 Kind : constant Node_Kind := Nkind (N);
7602 if Kind = N_Range then
7604 H := High_Bound (N);
7606 elsif Kind = N_Subtype_Indication then
7607 R := Range_Expression (Constraint (N));
7615 L := Low_Bound (Range_Expression (Constraint (N)));
7616 H := High_Bound (Range_Expression (Constraint (N)));
7619 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
7620 if Error_Posted (Scalar_Range (Entity (N))) then
7624 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
7625 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
7628 L := Low_Bound (Scalar_Range (Entity (N)));
7629 H := High_Bound (Scalar_Range (Entity (N)));
7633 -- N is an expression, indicating a range with one value
7638 end Get_Index_Bounds;
7640 ---------------------------------
7641 -- Get_Iterable_Type_Primitive --
7642 ---------------------------------
7644 function Get_Iterable_Type_Primitive
7646 Nam : Name_Id) return Entity_Id
7648 Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
7656 Assoc := First (Component_Associations (Funcs));
7657 while Present (Assoc) loop
7658 if Chars (First (Choices (Assoc))) = Nam then
7659 return Entity (Expression (Assoc));
7662 Assoc := Next (Assoc);
7667 end Get_Iterable_Type_Primitive;
7669 ----------------------------------
7670 -- Get_Library_Unit_Name_string --
7671 ----------------------------------
7673 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
7674 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
7677 Get_Unit_Name_String (Unit_Name_Id);
7679 -- Remove seven last character (" (spec)" or " (body)")
7681 Name_Len := Name_Len - 7;
7682 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
7683 end Get_Library_Unit_Name_String;
7685 ------------------------
7686 -- Get_Name_Entity_Id --
7687 ------------------------
7689 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
7691 return Entity_Id (Get_Name_Table_Int (Id));
7692 end Get_Name_Entity_Id;
7694 ------------------------------
7695 -- Get_Name_From_CTC_Pragma --
7696 ------------------------------
7698 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
7699 Arg : constant Node_Id :=
7700 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
7702 return Strval (Expr_Value_S (Arg));
7703 end Get_Name_From_CTC_Pragma;
7705 -----------------------
7706 -- Get_Parent_Entity --
7707 -----------------------
7709 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
7711 if Nkind (Unit) = N_Package_Body
7712 and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
7714 return Defining_Entity
7715 (Specification (Instance_Spec (Original_Node (Unit))));
7716 elsif Nkind (Unit) = N_Package_Instantiation then
7717 return Defining_Entity (Specification (Instance_Spec (Unit)));
7719 return Defining_Entity (Unit);
7721 end Get_Parent_Entity;
7726 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
7728 return Get_Pragma_Id (Pragma_Name (N));
7731 -----------------------
7732 -- Get_Reason_String --
7733 -----------------------
7735 procedure Get_Reason_String (N : Node_Id) is
7737 if Nkind (N) = N_String_Literal then
7738 Store_String_Chars (Strval (N));
7740 elsif Nkind (N) = N_Op_Concat then
7741 Get_Reason_String (Left_Opnd (N));
7742 Get_Reason_String (Right_Opnd (N));
7744 -- If not of required form, error
7748 ("Reason for pragma Warnings has wrong form", N);
7750 ("\must be string literal or concatenation of string literals", N);
7753 end Get_Reason_String;
7755 --------------------------------
7756 -- Get_Reference_Discriminant --
7757 --------------------------------
7759 function Get_Reference_Discriminant (Typ : Entity_Id) return Entity_Id is
7763 D := First_Discriminant (Typ);
7764 while Present (D) loop
7765 if Has_Implicit_Dereference (D) then
7768 Next_Discriminant (D);
7772 end Get_Reference_Discriminant;
7774 ---------------------------
7775 -- Get_Referenced_Object --
7776 ---------------------------
7778 function Get_Referenced_Object (N : Node_Id) return Node_Id is
7783 while Is_Entity_Name (R)
7784 and then Present (Renamed_Object (Entity (R)))
7786 R := Renamed_Object (Entity (R));
7790 end Get_Referenced_Object;
7792 ------------------------
7793 -- Get_Renamed_Entity --
7794 ------------------------
7796 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
7801 while Present (Renamed_Entity (R)) loop
7802 R := Renamed_Entity (R);
7806 end Get_Renamed_Entity;
7808 -----------------------
7809 -- Get_Return_Object --
7810 -----------------------
7812 function Get_Return_Object (N : Node_Id) return Entity_Id is
7816 Decl := First (Return_Object_Declarations (N));
7817 while Present (Decl) loop
7818 exit when Nkind (Decl) = N_Object_Declaration
7819 and then Is_Return_Object (Defining_Identifier (Decl));
7823 pragma Assert (Present (Decl));
7824 return Defining_Identifier (Decl);
7825 end Get_Return_Object;
7827 ---------------------------
7828 -- Get_Subprogram_Entity --
7829 ---------------------------
7831 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
7833 Subp_Id : Entity_Id;
7836 if Nkind (Nod) = N_Accept_Statement then
7837 Subp := Entry_Direct_Name (Nod);
7839 elsif Nkind (Nod) = N_Slice then
7840 Subp := Prefix (Nod);
7846 -- Strip the subprogram call
7849 if Nkind_In (Subp, N_Explicit_Dereference,
7850 N_Indexed_Component,
7851 N_Selected_Component)
7853 Subp := Prefix (Subp);
7855 elsif Nkind_In (Subp, N_Type_Conversion,
7856 N_Unchecked_Type_Conversion)
7858 Subp := Expression (Subp);
7865 -- Extract the entity of the subprogram call
7867 if Is_Entity_Name (Subp) then
7868 Subp_Id := Entity (Subp);
7870 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
7871 Subp_Id := Directly_Designated_Type (Subp_Id);
7874 if Is_Subprogram (Subp_Id) then
7880 -- The search did not find a construct that denotes a subprogram
7885 end Get_Subprogram_Entity;
7887 -----------------------------
7888 -- Get_Task_Body_Procedure --
7889 -----------------------------
7891 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
7893 -- Note: A task type may be the completion of a private type with
7894 -- discriminants. When performing elaboration checks on a task
7895 -- declaration, the current view of the type may be the private one,
7896 -- and the procedure that holds the body of the task is held in its
7899 -- This is an odd function, why not have Task_Body_Procedure do
7900 -- the following digging???
7902 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
7903 end Get_Task_Body_Procedure;
7905 -------------------------
7906 -- Get_User_Defined_Eq --
7907 -------------------------
7909 function Get_User_Defined_Eq (E : Entity_Id) return Entity_Id is
7914 Prim := First_Elmt (Collect_Primitive_Operations (E));
7915 while Present (Prim) loop
7918 if Chars (Op) = Name_Op_Eq
7919 and then Etype (Op) = Standard_Boolean
7920 and then Etype (First_Formal (Op)) = E
7921 and then Etype (Next_Formal (First_Formal (Op))) = E
7930 end Get_User_Defined_Eq;
7932 -----------------------
7933 -- Has_Access_Values --
7934 -----------------------
7936 function Has_Access_Values (T : Entity_Id) return Boolean is
7937 Typ : constant Entity_Id := Underlying_Type (T);
7940 -- Case of a private type which is not completed yet. This can only
7941 -- happen in the case of a generic format type appearing directly, or
7942 -- as a component of the type to which this function is being applied
7943 -- at the top level. Return False in this case, since we certainly do
7944 -- not know that the type contains access types.
7949 elsif Is_Access_Type (Typ) then
7952 elsif Is_Array_Type (Typ) then
7953 return Has_Access_Values (Component_Type (Typ));
7955 elsif Is_Record_Type (Typ) then
7960 -- Loop to Check components
7962 Comp := First_Component_Or_Discriminant (Typ);
7963 while Present (Comp) loop
7965 -- Check for access component, tag field does not count, even
7966 -- though it is implemented internally using an access type.
7968 if Has_Access_Values (Etype (Comp))
7969 and then Chars (Comp) /= Name_uTag
7974 Next_Component_Or_Discriminant (Comp);
7983 end Has_Access_Values;
7985 ------------------------------
7986 -- Has_Compatible_Alignment --
7987 ------------------------------
7989 function Has_Compatible_Alignment
7991 Expr : Node_Id) return Alignment_Result
7993 function Has_Compatible_Alignment_Internal
7996 Default : Alignment_Result) return Alignment_Result;
7997 -- This is the internal recursive function that actually does the work.
7998 -- There is one additional parameter, which says what the result should
7999 -- be if no alignment information is found, and there is no definite
8000 -- indication of compatible alignments. At the outer level, this is set
8001 -- to Unknown, but for internal recursive calls in the case where types
8002 -- are known to be correct, it is set to Known_Compatible.
8004 ---------------------------------------
8005 -- Has_Compatible_Alignment_Internal --
8006 ---------------------------------------
8008 function Has_Compatible_Alignment_Internal
8011 Default : Alignment_Result) return Alignment_Result
8013 Result : Alignment_Result := Known_Compatible;
8014 -- Holds the current status of the result. Note that once a value of
8015 -- Known_Incompatible is set, it is sticky and does not get changed
8016 -- to Unknown (the value in Result only gets worse as we go along,
8019 Offs : Uint := No_Uint;
8020 -- Set to a factor of the offset from the base object when Expr is a
8021 -- selected or indexed component, based on Component_Bit_Offset and
8022 -- Component_Size respectively. A negative value is used to represent
8023 -- a value which is not known at compile time.
8025 procedure Check_Prefix;
8026 -- Checks the prefix recursively in the case where the expression
8027 -- is an indexed or selected component.
8029 procedure Set_Result (R : Alignment_Result);
8030 -- If R represents a worse outcome (unknown instead of known
8031 -- compatible, or known incompatible), then set Result to R.
8037 procedure Check_Prefix is
8039 -- The subtlety here is that in doing a recursive call to check
8040 -- the prefix, we have to decide what to do in the case where we
8041 -- don't find any specific indication of an alignment problem.
8043 -- At the outer level, we normally set Unknown as the result in
8044 -- this case, since we can only set Known_Compatible if we really
8045 -- know that the alignment value is OK, but for the recursive
8046 -- call, in the case where the types match, and we have not
8047 -- specified a peculiar alignment for the object, we are only
8048 -- concerned about suspicious rep clauses, the default case does
8049 -- not affect us, since the compiler will, in the absence of such
8050 -- rep clauses, ensure that the alignment is correct.
8052 if Default = Known_Compatible
8054 (Etype (Obj) = Etype (Expr)
8055 and then (Unknown_Alignment (Obj)
8057 Alignment (Obj) = Alignment (Etype (Obj))))
8060 (Has_Compatible_Alignment_Internal
8061 (Obj, Prefix (Expr), Known_Compatible));
8063 -- In all other cases, we need a full check on the prefix
8067 (Has_Compatible_Alignment_Internal
8068 (Obj, Prefix (Expr), Unknown));
8076 procedure Set_Result (R : Alignment_Result) is
8083 -- Start of processing for Has_Compatible_Alignment_Internal
8086 -- If Expr is a selected component, we must make sure there is no
8087 -- potentially troublesome component clause, and that the record is
8090 if Nkind (Expr) = N_Selected_Component then
8092 -- Packed record always generate unknown alignment
8094 if Is_Packed (Etype (Prefix (Expr))) then
8095 Set_Result (Unknown);
8098 -- Check prefix and component offset
8101 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
8103 -- If Expr is an indexed component, we must make sure there is no
8104 -- potentially troublesome Component_Size clause and that the array
8105 -- is not bit-packed.
8107 elsif Nkind (Expr) = N_Indexed_Component then
8109 Typ : constant Entity_Id := Etype (Prefix (Expr));
8110 Ind : constant Node_Id := First_Index (Typ);
8113 -- Bit packed array always generates unknown alignment
8115 if Is_Bit_Packed_Array (Typ) then
8116 Set_Result (Unknown);
8119 -- Check prefix and component offset
8122 Offs := Component_Size (Typ);
8124 -- Small optimization: compute the full offset when possible
8127 and then Offs > Uint_0
8128 and then Present (Ind)
8129 and then Nkind (Ind) = N_Range
8130 and then Compile_Time_Known_Value (Low_Bound (Ind))
8131 and then Compile_Time_Known_Value (First (Expressions (Expr)))
8133 Offs := Offs * (Expr_Value (First (Expressions (Expr)))
8134 - Expr_Value (Low_Bound ((Ind))));
8139 -- If we have a null offset, the result is entirely determined by
8140 -- the base object and has already been computed recursively.
8142 if Offs = Uint_0 then
8145 -- Case where we know the alignment of the object
8147 elsif Known_Alignment (Obj) then
8149 ObjA : constant Uint := Alignment (Obj);
8150 ExpA : Uint := No_Uint;
8151 SizA : Uint := No_Uint;
8154 -- If alignment of Obj is 1, then we are always OK
8157 Set_Result (Known_Compatible);
8159 -- Alignment of Obj is greater than 1, so we need to check
8162 -- If we have an offset, see if it is compatible
8164 if Offs /= No_Uint and Offs > Uint_0 then
8165 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
8166 Set_Result (Known_Incompatible);
8169 -- See if Expr is an object with known alignment
8171 elsif Is_Entity_Name (Expr)
8172 and then Known_Alignment (Entity (Expr))
8174 ExpA := Alignment (Entity (Expr));
8176 -- Otherwise, we can use the alignment of the type of
8177 -- Expr given that we already checked for
8178 -- discombobulating rep clauses for the cases of indexed
8179 -- and selected components above.
8181 elsif Known_Alignment (Etype (Expr)) then
8182 ExpA := Alignment (Etype (Expr));
8184 -- Otherwise the alignment is unknown
8187 Set_Result (Default);
8190 -- If we got an alignment, see if it is acceptable
8192 if ExpA /= No_Uint and then ExpA < ObjA then
8193 Set_Result (Known_Incompatible);
8196 -- If Expr is not a piece of a larger object, see if size
8197 -- is given. If so, check that it is not too small for the
8198 -- required alignment.
8200 if Offs /= No_Uint then
8203 -- See if Expr is an object with known size
8205 elsif Is_Entity_Name (Expr)
8206 and then Known_Static_Esize (Entity (Expr))
8208 SizA := Esize (Entity (Expr));
8210 -- Otherwise, we check the object size of the Expr type
8212 elsif Known_Static_Esize (Etype (Expr)) then
8213 SizA := Esize (Etype (Expr));
8216 -- If we got a size, see if it is a multiple of the Obj
8217 -- alignment, if not, then the alignment cannot be
8218 -- acceptable, since the size is always a multiple of the
8221 if SizA /= No_Uint then
8222 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
8223 Set_Result (Known_Incompatible);
8229 -- If we do not know required alignment, any non-zero offset is a
8230 -- potential problem (but certainly may be OK, so result is unknown).
8232 elsif Offs /= No_Uint then
8233 Set_Result (Unknown);
8235 -- If we can't find the result by direct comparison of alignment
8236 -- values, then there is still one case that we can determine known
8237 -- result, and that is when we can determine that the types are the
8238 -- same, and no alignments are specified. Then we known that the
8239 -- alignments are compatible, even if we don't know the alignment
8240 -- value in the front end.
8242 elsif Etype (Obj) = Etype (Expr) then
8244 -- Types are the same, but we have to check for possible size
8245 -- and alignments on the Expr object that may make the alignment
8246 -- different, even though the types are the same.
8248 if Is_Entity_Name (Expr) then
8250 -- First check alignment of the Expr object. Any alignment less
8251 -- than Maximum_Alignment is worrisome since this is the case
8252 -- where we do not know the alignment of Obj.
8254 if Known_Alignment (Entity (Expr))
8255 and then UI_To_Int (Alignment (Entity (Expr))) <
8256 Ttypes.Maximum_Alignment
8258 Set_Result (Unknown);
8260 -- Now check size of Expr object. Any size that is not an
8261 -- even multiple of Maximum_Alignment is also worrisome
8262 -- since it may cause the alignment of the object to be less
8263 -- than the alignment of the type.
8265 elsif Known_Static_Esize (Entity (Expr))
8267 (UI_To_Int (Esize (Entity (Expr))) mod
8268 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
8271 Set_Result (Unknown);
8273 -- Otherwise same type is decisive
8276 Set_Result (Known_Compatible);
8280 -- Another case to deal with is when there is an explicit size or
8281 -- alignment clause when the types are not the same. If so, then the
8282 -- result is Unknown. We don't need to do this test if the Default is
8283 -- Unknown, since that result will be set in any case.
8285 elsif Default /= Unknown
8286 and then (Has_Size_Clause (Etype (Expr))
8288 Has_Alignment_Clause (Etype (Expr)))
8290 Set_Result (Unknown);
8292 -- If no indication found, set default
8295 Set_Result (Default);
8298 -- Return worst result found
8301 end Has_Compatible_Alignment_Internal;
8303 -- Start of processing for Has_Compatible_Alignment
8306 -- If Obj has no specified alignment, then set alignment from the type
8307 -- alignment. Perhaps we should always do this, but for sure we should
8308 -- do it when there is an address clause since we can do more if the
8309 -- alignment is known.
8311 if Unknown_Alignment (Obj) then
8312 Set_Alignment (Obj, Alignment (Etype (Obj)));
8315 -- Now do the internal call that does all the work
8317 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
8318 end Has_Compatible_Alignment;
8320 ----------------------
8321 -- Has_Declarations --
8322 ----------------------
8324 function Has_Declarations (N : Node_Id) return Boolean is
8326 return Nkind_In (Nkind (N), N_Accept_Statement,
8328 N_Compilation_Unit_Aux,
8334 N_Package_Specification);
8335 end Has_Declarations;
8337 ---------------------------------
8338 -- Has_Defaulted_Discriminants --
8339 ---------------------------------
8341 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
8343 return Has_Discriminants (Typ)
8344 and then Present (First_Discriminant (Typ))
8345 and then Present (Discriminant_Default_Value
8346 (First_Discriminant (Typ)));
8347 end Has_Defaulted_Discriminants;
8353 function Has_Denormals (E : Entity_Id) return Boolean is
8355 return Is_Floating_Point_Type (E) and then Denorm_On_Target;
8358 -------------------------------------------
8359 -- Has_Discriminant_Dependent_Constraint --
8360 -------------------------------------------
8362 function Has_Discriminant_Dependent_Constraint
8363 (Comp : Entity_Id) return Boolean
8365 Comp_Decl : constant Node_Id := Parent (Comp);
8366 Subt_Indic : Node_Id;
8371 -- Discriminants can't depend on discriminants
8373 if Ekind (Comp) = E_Discriminant then
8377 Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl));
8379 if Nkind (Subt_Indic) = N_Subtype_Indication then
8380 Constr := Constraint (Subt_Indic);
8382 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
8383 Assn := First (Constraints (Constr));
8384 while Present (Assn) loop
8385 case Nkind (Assn) is
8386 when N_Subtype_Indication |
8390 if Depends_On_Discriminant (Assn) then
8394 when N_Discriminant_Association =>
8395 if Depends_On_Discriminant (Expression (Assn)) then
8410 end Has_Discriminant_Dependent_Constraint;
8412 --------------------------------------
8413 -- Has_Effectively_Volatile_Profile --
8414 --------------------------------------
8416 function Has_Effectively_Volatile_Profile
8417 (Subp_Id : Entity_Id) return Boolean
8422 -- Inspect the formal parameters looking for an effectively volatile
8425 Formal := First_Formal (Subp_Id);
8426 while Present (Formal) loop
8427 if Is_Effectively_Volatile (Etype (Formal)) then
8431 Next_Formal (Formal);
8434 -- Inspect the return type of functions
8436 if Ekind_In (Subp_Id, E_Function, E_Generic_Function)
8437 and then Is_Effectively_Volatile (Etype (Subp_Id))
8443 end Has_Effectively_Volatile_Profile;
8445 --------------------------
8446 -- Has_Enabled_Property --
8447 --------------------------
8449 function Has_Enabled_Property
8450 (Item_Id : Entity_Id;
8451 Property : Name_Id) return Boolean
8453 function State_Has_Enabled_Property return Boolean;
8454 -- Determine whether a state denoted by Item_Id has the property enabled
8456 function Variable_Has_Enabled_Property return Boolean;
8457 -- Determine whether a variable denoted by Item_Id has the property
8460 --------------------------------
8461 -- State_Has_Enabled_Property --
8462 --------------------------------
8464 function State_Has_Enabled_Property return Boolean is
8465 Decl : constant Node_Id := Parent (Item_Id);
8473 -- The declaration of an external abstract state appears as an
8474 -- extension aggregate. If this is not the case, properties can never
8477 if Nkind (Decl) /= N_Extension_Aggregate then
8481 -- When External appears as a simple option, it automatically enables
8484 Opt := First (Expressions (Decl));
8485 while Present (Opt) loop
8486 if Nkind (Opt) = N_Identifier
8487 and then Chars (Opt) = Name_External
8495 -- When External specifies particular properties, inspect those and
8496 -- find the desired one (if any).
8498 Opt := First (Component_Associations (Decl));
8499 while Present (Opt) loop
8500 Opt_Nam := First (Choices (Opt));
8502 if Nkind (Opt_Nam) = N_Identifier
8503 and then Chars (Opt_Nam) = Name_External
8505 Props := Expression (Opt);
8507 -- Multiple properties appear as an aggregate
8509 if Nkind (Props) = N_Aggregate then
8511 -- Simple property form
8513 Prop := First (Expressions (Props));
8514 while Present (Prop) loop
8515 if Chars (Prop) = Property then
8522 -- Property with expression form
8524 Prop := First (Component_Associations (Props));
8525 while Present (Prop) loop
8526 Prop_Nam := First (Choices (Prop));
8528 -- The property can be represented in two ways:
8529 -- others => <value>
8530 -- <property> => <value>
8532 if Nkind (Prop_Nam) = N_Others_Choice
8533 or else (Nkind (Prop_Nam) = N_Identifier
8534 and then Chars (Prop_Nam) = Property)
8536 return Is_True (Expr_Value (Expression (Prop)));
8545 return Chars (Props) = Property;
8553 end State_Has_Enabled_Property;
8555 -----------------------------------
8556 -- Variable_Has_Enabled_Property --
8557 -----------------------------------
8559 function Variable_Has_Enabled_Property return Boolean is
8560 function Is_Enabled (Prag : Node_Id) return Boolean;
8561 -- Determine whether property pragma Prag (if present) denotes an
8562 -- enabled property.
8568 function Is_Enabled (Prag : Node_Id) return Boolean is
8572 if Present (Prag) then
8573 Arg1 := First (Pragma_Argument_Associations (Prag));
8575 -- The pragma has an optional Boolean expression, the related
8576 -- property is enabled only when the expression evaluates to
8579 if Present (Arg1) then
8580 return Is_True (Expr_Value (Get_Pragma_Arg (Arg1)));
8582 -- Otherwise the lack of expression enables the property by
8589 -- The property was never set in the first place
8598 AR : constant Node_Id :=
8599 Get_Pragma (Item_Id, Pragma_Async_Readers);
8600 AW : constant Node_Id :=
8601 Get_Pragma (Item_Id, Pragma_Async_Writers);
8602 ER : constant Node_Id :=
8603 Get_Pragma (Item_Id, Pragma_Effective_Reads);
8604 EW : constant Node_Id :=
8605 Get_Pragma (Item_Id, Pragma_Effective_Writes);
8607 -- Start of processing for Variable_Has_Enabled_Property
8610 -- A non-effectively volatile object can never possess external
8613 if not Is_Effectively_Volatile (Item_Id) then
8616 -- External properties related to variables come in two flavors -
8617 -- explicit and implicit. The explicit case is characterized by the
8618 -- presence of a property pragma with an optional Boolean flag. The
8619 -- property is enabled when the flag evaluates to True or the flag is
8620 -- missing altogether.
8622 elsif Property = Name_Async_Readers and then Is_Enabled (AR) then
8625 elsif Property = Name_Async_Writers and then Is_Enabled (AW) then
8628 elsif Property = Name_Effective_Reads and then Is_Enabled (ER) then
8631 elsif Property = Name_Effective_Writes and then Is_Enabled (EW) then
8634 -- The implicit case lacks all property pragmas
8636 elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then
8642 end Variable_Has_Enabled_Property;
8644 -- Start of processing for Has_Enabled_Property
8647 -- Abstract states and variables have a flexible scheme of specifying
8648 -- external properties.
8650 if Ekind (Item_Id) = E_Abstract_State then
8651 return State_Has_Enabled_Property;
8653 elsif Ekind (Item_Id) = E_Variable then
8654 return Variable_Has_Enabled_Property;
8656 -- Otherwise a property is enabled when the related item is effectively
8660 return Is_Effectively_Volatile (Item_Id);
8662 end Has_Enabled_Property;
8664 --------------------
8665 -- Has_Infinities --
8666 --------------------
8668 function Has_Infinities (E : Entity_Id) return Boolean is
8671 Is_Floating_Point_Type (E)
8672 and then Nkind (Scalar_Range (E)) = N_Range
8673 and then Includes_Infinities (Scalar_Range (E));
8676 --------------------
8677 -- Has_Interfaces --
8678 --------------------
8680 function Has_Interfaces
8682 Use_Full_View : Boolean := True) return Boolean
8684 Typ : Entity_Id := Base_Type (T);
8687 -- Handle concurrent types
8689 if Is_Concurrent_Type (Typ) then
8690 Typ := Corresponding_Record_Type (Typ);
8693 if not Present (Typ)
8694 or else not Is_Record_Type (Typ)
8695 or else not Is_Tagged_Type (Typ)
8700 -- Handle private types
8702 if Use_Full_View and then Present (Full_View (Typ)) then
8703 Typ := Full_View (Typ);
8706 -- Handle concurrent record types
8708 if Is_Concurrent_Record_Type (Typ)
8709 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
8715 if Is_Interface (Typ)
8717 (Is_Record_Type (Typ)
8718 and then Present (Interfaces (Typ))
8719 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
8724 exit when Etype (Typ) = Typ
8726 -- Handle private types
8728 or else (Present (Full_View (Etype (Typ)))
8729 and then Full_View (Etype (Typ)) = Typ)
8731 -- Protect frontend against wrong sources with cyclic derivations
8733 or else Etype (Typ) = T;
8735 -- Climb to the ancestor type handling private types
8737 if Present (Full_View (Etype (Typ))) then
8738 Typ := Full_View (Etype (Typ));
8747 ---------------------------------
8748 -- Has_No_Obvious_Side_Effects --
8749 ---------------------------------
8751 function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
8753 -- For now, just handle literals, constants, and non-volatile
8754 -- variables and expressions combining these with operators or
8755 -- short circuit forms.
8757 if Nkind (N) in N_Numeric_Or_String_Literal then
8760 elsif Nkind (N) = N_Character_Literal then
8763 elsif Nkind (N) in N_Unary_Op then
8764 return Has_No_Obvious_Side_Effects (Right_Opnd (N));
8766 elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
8767 return Has_No_Obvious_Side_Effects (Left_Opnd (N))
8769 Has_No_Obvious_Side_Effects (Right_Opnd (N));
8771 elsif Nkind (N) = N_Expression_With_Actions
8772 and then Is_Empty_List (Actions (N))
8774 return Has_No_Obvious_Side_Effects (Expression (N));
8776 elsif Nkind (N) in N_Has_Entity then
8777 return Present (Entity (N))
8778 and then Ekind_In (Entity (N), E_Variable,
8780 E_Enumeration_Literal,
8784 and then not Is_Volatile (Entity (N));
8789 end Has_No_Obvious_Side_Effects;
8791 ------------------------
8792 -- Has_Null_Exclusion --
8793 ------------------------
8795 function Has_Null_Exclusion (N : Node_Id) return Boolean is
8798 when N_Access_Definition |
8799 N_Access_Function_Definition |
8800 N_Access_Procedure_Definition |
8801 N_Access_To_Object_Definition |
8803 N_Derived_Type_Definition |
8804 N_Function_Specification |
8805 N_Subtype_Declaration =>
8806 return Null_Exclusion_Present (N);
8808 when N_Component_Definition |
8809 N_Formal_Object_Declaration |
8810 N_Object_Renaming_Declaration =>
8811 if Present (Subtype_Mark (N)) then
8812 return Null_Exclusion_Present (N);
8813 else pragma Assert (Present (Access_Definition (N)));
8814 return Null_Exclusion_Present (Access_Definition (N));
8817 when N_Discriminant_Specification =>
8818 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
8819 return Null_Exclusion_Present (Discriminant_Type (N));
8821 return Null_Exclusion_Present (N);
8824 when N_Object_Declaration =>
8825 if Nkind (Object_Definition (N)) = N_Access_Definition then
8826 return Null_Exclusion_Present (Object_Definition (N));
8828 return Null_Exclusion_Present (N);
8831 when N_Parameter_Specification =>
8832 if Nkind (Parameter_Type (N)) = N_Access_Definition then
8833 return Null_Exclusion_Present (Parameter_Type (N));
8835 return Null_Exclusion_Present (N);
8842 end Has_Null_Exclusion;
8844 ------------------------
8845 -- Has_Null_Extension --
8846 ------------------------
8848 function Has_Null_Extension (T : Entity_Id) return Boolean is
8849 B : constant Entity_Id := Base_Type (T);
8854 if Nkind (Parent (B)) = N_Full_Type_Declaration
8855 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
8857 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
8859 if Present (Ext) then
8860 if Null_Present (Ext) then
8863 Comps := Component_List (Ext);
8865 -- The null component list is rewritten during analysis to
8866 -- include the parent component. Any other component indicates
8867 -- that the extension was not originally null.
8869 return Null_Present (Comps)
8870 or else No (Next (First (Component_Items (Comps))));
8879 end Has_Null_Extension;
8881 -------------------------------
8882 -- Has_Overriding_Initialize --
8883 -------------------------------
8885 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
8886 BT : constant Entity_Id := Base_Type (T);
8890 if Is_Controlled (BT) then
8891 if Is_RTU (Scope (BT), Ada_Finalization) then
8894 elsif Present (Primitive_Operations (BT)) then
8895 P := First_Elmt (Primitive_Operations (BT));
8896 while Present (P) loop
8898 Init : constant Entity_Id := Node (P);
8899 Formal : constant Entity_Id := First_Formal (Init);
8901 if Ekind (Init) = E_Procedure
8902 and then Chars (Init) = Name_Initialize
8903 and then Comes_From_Source (Init)
8904 and then Present (Formal)
8905 and then Etype (Formal) = BT
8906 and then No (Next_Formal (Formal))
8907 and then (Ada_Version < Ada_2012
8908 or else not Null_Present (Parent (Init)))
8918 -- Here if type itself does not have a non-null Initialize operation:
8919 -- check immediate ancestor.
8921 if Is_Derived_Type (BT)
8922 and then Has_Overriding_Initialize (Etype (BT))
8929 end Has_Overriding_Initialize;
8931 --------------------------------------
8932 -- Has_Preelaborable_Initialization --
8933 --------------------------------------
8935 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
8938 procedure Check_Components (E : Entity_Id);
8939 -- Check component/discriminant chain, sets Has_PE False if a component
8940 -- or discriminant does not meet the preelaborable initialization rules.
8942 ----------------------
8943 -- Check_Components --
8944 ----------------------
8946 procedure Check_Components (E : Entity_Id) is
8950 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
8951 -- Returns True if and only if the expression denoted by N does not
8952 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
8954 ---------------------------------
8955 -- Is_Preelaborable_Expression --
8956 ---------------------------------
8958 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
8962 Comp_Type : Entity_Id;
8963 Is_Array_Aggr : Boolean;
8966 if Is_OK_Static_Expression (N) then
8969 elsif Nkind (N) = N_Null then
8972 -- Attributes are allowed in general, even if their prefix is a
8973 -- formal type. (It seems that certain attributes known not to be
8974 -- static might not be allowed, but there are no rules to prevent
8977 elsif Nkind (N) = N_Attribute_Reference then
8980 -- The name of a discriminant evaluated within its parent type is
8981 -- defined to be preelaborable (10.2.1(8)). Note that we test for
8982 -- names that denote discriminals as well as discriminants to
8983 -- catch references occurring within init procs.
8985 elsif Is_Entity_Name (N)
8987 (Ekind (Entity (N)) = E_Discriminant
8988 or else (Ekind_In (Entity (N), E_Constant, E_In_Parameter)
8989 and then Present (Discriminal_Link (Entity (N)))))
8993 elsif Nkind (N) = N_Qualified_Expression then
8994 return Is_Preelaborable_Expression (Expression (N));
8996 -- For aggregates we have to check that each of the associations
8997 -- is preelaborable.
8999 elsif Nkind_In (N, N_Aggregate, N_Extension_Aggregate) then
9000 Is_Array_Aggr := Is_Array_Type (Etype (N));
9002 if Is_Array_Aggr then
9003 Comp_Type := Component_Type (Etype (N));
9006 -- Check the ancestor part of extension aggregates, which must
9007 -- be either the name of a type that has preelaborable init or
9008 -- an expression that is preelaborable.
9010 if Nkind (N) = N_Extension_Aggregate then
9012 Anc_Part : constant Node_Id := Ancestor_Part (N);
9015 if Is_Entity_Name (Anc_Part)
9016 and then Is_Type (Entity (Anc_Part))
9018 if not Has_Preelaborable_Initialization
9024 elsif not Is_Preelaborable_Expression (Anc_Part) then
9030 -- Check positional associations
9032 Exp := First (Expressions (N));
9033 while Present (Exp) loop
9034 if not Is_Preelaborable_Expression (Exp) then
9041 -- Check named associations
9043 Assn := First (Component_Associations (N));
9044 while Present (Assn) loop
9045 Choice := First (Choices (Assn));
9046 while Present (Choice) loop
9047 if Is_Array_Aggr then
9048 if Nkind (Choice) = N_Others_Choice then
9051 elsif Nkind (Choice) = N_Range then
9052 if not Is_OK_Static_Range (Choice) then
9056 elsif not Is_OK_Static_Expression (Choice) then
9061 Comp_Type := Etype (Choice);
9067 -- If the association has a <> at this point, then we have
9068 -- to check whether the component's type has preelaborable
9069 -- initialization. Note that this only occurs when the
9070 -- association's corresponding component does not have a
9071 -- default expression, the latter case having already been
9072 -- expanded as an expression for the association.
9074 if Box_Present (Assn) then
9075 if not Has_Preelaborable_Initialization (Comp_Type) then
9079 -- In the expression case we check whether the expression
9080 -- is preelaborable.
9083 not Is_Preelaborable_Expression (Expression (Assn))
9091 -- If we get here then aggregate as a whole is preelaborable
9095 -- All other cases are not preelaborable
9100 end Is_Preelaborable_Expression;
9102 -- Start of processing for Check_Components
9105 -- Loop through entities of record or protected type
9108 while Present (Ent) loop
9110 -- We are interested only in components and discriminants
9117 -- Get default expression if any. If there is no declaration
9118 -- node, it means we have an internal entity. The parent and
9119 -- tag fields are examples of such entities. For such cases,
9120 -- we just test the type of the entity.
9122 if Present (Declaration_Node (Ent)) then
9123 Exp := Expression (Declaration_Node (Ent));
9126 when E_Discriminant =>
9128 -- Note: for a renamed discriminant, the Declaration_Node
9129 -- may point to the one from the ancestor, and have a
9130 -- different expression, so use the proper attribute to
9131 -- retrieve the expression from the derived constraint.
9133 Exp := Discriminant_Default_Value (Ent);
9136 goto Check_Next_Entity;
9139 -- A component has PI if it has no default expression and the
9140 -- component type has PI.
9143 if not Has_Preelaborable_Initialization (Etype (Ent)) then
9148 -- Require the default expression to be preelaborable
9150 elsif not Is_Preelaborable_Expression (Exp) then
9155 <<Check_Next_Entity>>
9158 end Check_Components;
9160 -- Start of processing for Has_Preelaborable_Initialization
9163 -- Immediate return if already marked as known preelaborable init. This
9164 -- covers types for which this function has already been called once
9165 -- and returned True (in which case the result is cached), and also
9166 -- types to which a pragma Preelaborable_Initialization applies.
9168 if Known_To_Have_Preelab_Init (E) then
9172 -- If the type is a subtype representing a generic actual type, then
9173 -- test whether its base type has preelaborable initialization since
9174 -- the subtype representing the actual does not inherit this attribute
9175 -- from the actual or formal. (but maybe it should???)
9177 if Is_Generic_Actual_Type (E) then
9178 return Has_Preelaborable_Initialization (Base_Type (E));
9181 -- All elementary types have preelaborable initialization
9183 if Is_Elementary_Type (E) then
9186 -- Array types have PI if the component type has PI
9188 elsif Is_Array_Type (E) then
9189 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
9191 -- A derived type has preelaborable initialization if its parent type
9192 -- has preelaborable initialization and (in the case of a derived record
9193 -- extension) if the non-inherited components all have preelaborable
9194 -- initialization. However, a user-defined controlled type with an
9195 -- overriding Initialize procedure does not have preelaborable
9198 elsif Is_Derived_Type (E) then
9200 -- If the derived type is a private extension then it doesn't have
9201 -- preelaborable initialization.
9203 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
9207 -- First check whether ancestor type has preelaborable initialization
9209 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
9211 -- If OK, check extension components (if any)
9213 if Has_PE and then Is_Record_Type (E) then
9214 Check_Components (First_Entity (E));
9217 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
9218 -- with a user defined Initialize procedure does not have PI. If
9219 -- the type is untagged, the control primitives come from a component
9220 -- that has already been checked.
9223 and then Is_Controlled (E)
9224 and then Is_Tagged_Type (E)
9225 and then Has_Overriding_Initialize (E)
9230 -- Private types not derived from a type having preelaborable init and
9231 -- that are not marked with pragma Preelaborable_Initialization do not
9232 -- have preelaborable initialization.
9234 elsif Is_Private_Type (E) then
9237 -- Record type has PI if it is non private and all components have PI
9239 elsif Is_Record_Type (E) then
9241 Check_Components (First_Entity (E));
9243 -- Protected types must not have entries, and components must meet
9244 -- same set of rules as for record components.
9246 elsif Is_Protected_Type (E) then
9247 if Has_Entries (E) then
9251 Check_Components (First_Entity (E));
9252 Check_Components (First_Private_Entity (E));
9255 -- Type System.Address always has preelaborable initialization
9257 elsif Is_RTE (E, RE_Address) then
9260 -- In all other cases, type does not have preelaborable initialization
9266 -- If type has preelaborable initialization, cache result
9269 Set_Known_To_Have_Preelab_Init (E);
9273 end Has_Preelaborable_Initialization;
9275 ---------------------------
9276 -- Has_Private_Component --
9277 ---------------------------
9279 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
9280 Btype : Entity_Id := Base_Type (Type_Id);
9281 Component : Entity_Id;
9284 if Error_Posted (Type_Id)
9285 or else Error_Posted (Btype)
9290 if Is_Class_Wide_Type (Btype) then
9291 Btype := Root_Type (Btype);
9294 if Is_Private_Type (Btype) then
9296 UT : constant Entity_Id := Underlying_Type (Btype);
9299 if No (Full_View (Btype)) then
9300 return not Is_Generic_Type (Btype)
9302 not Is_Generic_Type (Root_Type (Btype));
9304 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
9307 return not Is_Frozen (UT) and then Has_Private_Component (UT);
9311 elsif Is_Array_Type (Btype) then
9312 return Has_Private_Component (Component_Type (Btype));
9314 elsif Is_Record_Type (Btype) then
9315 Component := First_Component (Btype);
9316 while Present (Component) loop
9317 if Has_Private_Component (Etype (Component)) then
9321 Next_Component (Component);
9326 elsif Is_Protected_Type (Btype)
9327 and then Present (Corresponding_Record_Type (Btype))
9329 return Has_Private_Component (Corresponding_Record_Type (Btype));
9334 end Has_Private_Component;
9336 ----------------------
9337 -- Has_Signed_Zeros --
9338 ----------------------
9340 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
9342 return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target;
9343 end Has_Signed_Zeros;
9345 ------------------------------
9346 -- Has_Significant_Contract --
9347 ------------------------------
9349 function Has_Significant_Contract (Subp_Id : Entity_Id) return Boolean is
9350 Subp_Nam : constant Name_Id := Chars (Subp_Id);
9353 -- _Finalizer procedure
9355 if Subp_Nam = Name_uFinalizer then
9358 -- _Postconditions procedure
9360 elsif Subp_Nam = Name_uPostconditions then
9363 -- Predicate function
9365 elsif Ekind (Subp_Id) = E_Function
9366 and then Is_Predicate_Function (Subp_Id)
9372 elsif Get_TSS_Name (Subp_Id) /= TSS_Null then
9378 end Has_Significant_Contract;
9380 -----------------------------
9381 -- Has_Static_Array_Bounds --
9382 -----------------------------
9384 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
9385 Ndims : constant Nat := Number_Dimensions (Typ);
9392 -- Unconstrained types do not have static bounds
9394 if not Is_Constrained (Typ) then
9398 -- First treat string literals specially, as the lower bound and length
9399 -- of string literals are not stored like those of arrays.
9401 -- A string literal always has static bounds
9403 if Ekind (Typ) = E_String_Literal_Subtype then
9407 -- Treat all dimensions in turn
9409 Index := First_Index (Typ);
9410 for Indx in 1 .. Ndims loop
9412 -- In case of an illegal index which is not a discrete type, return
9413 -- that the type is not static.
9415 if not Is_Discrete_Type (Etype (Index))
9416 or else Etype (Index) = Any_Type
9421 Get_Index_Bounds (Index, Low, High);
9423 if Error_Posted (Low) or else Error_Posted (High) then
9427 if Is_OK_Static_Expression (Low)
9429 Is_OK_Static_Expression (High)
9439 -- If we fall through the loop, all indexes matched
9442 end Has_Static_Array_Bounds;
9448 function Has_Stream (T : Entity_Id) return Boolean is
9455 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
9458 elsif Is_Array_Type (T) then
9459 return Has_Stream (Component_Type (T));
9461 elsif Is_Record_Type (T) then
9462 E := First_Component (T);
9463 while Present (E) loop
9464 if Has_Stream (Etype (E)) then
9473 elsif Is_Private_Type (T) then
9474 return Has_Stream (Underlying_Type (T));
9485 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
9487 Get_Name_String (Chars (E));
9488 return Name_Buffer (Name_Len) = Suffix;
9495 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
9497 Get_Name_String (Chars (E));
9498 Add_Char_To_Name_Buffer (Suffix);
9506 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
9508 pragma Assert (Has_Suffix (E, Suffix));
9509 Get_Name_String (Chars (E));
9510 Name_Len := Name_Len - 1;
9514 --------------------------
9515 -- Has_Tagged_Component --
9516 --------------------------
9518 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
9522 if Is_Private_Type (Typ) and then Present (Underlying_Type (Typ)) then
9523 return Has_Tagged_Component (Underlying_Type (Typ));
9525 elsif Is_Array_Type (Typ) then
9526 return Has_Tagged_Component (Component_Type (Typ));
9528 elsif Is_Tagged_Type (Typ) then
9531 elsif Is_Record_Type (Typ) then
9532 Comp := First_Component (Typ);
9533 while Present (Comp) loop
9534 if Has_Tagged_Component (Etype (Comp)) then
9538 Next_Component (Comp);
9546 end Has_Tagged_Component;
9548 ----------------------------
9549 -- Has_Volatile_Component --
9550 ----------------------------
9552 function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
9556 if Has_Volatile_Components (Typ) then
9559 elsif Is_Array_Type (Typ) then
9560 return Is_Volatile (Component_Type (Typ));
9562 elsif Is_Record_Type (Typ) then
9563 Comp := First_Component (Typ);
9564 while Present (Comp) loop
9565 if Is_Volatile_Object (Comp) then
9569 Comp := Next_Component (Comp);
9574 end Has_Volatile_Component;
9576 -------------------------
9577 -- Implementation_Kind --
9578 -------------------------
9580 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
9581 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
9584 pragma Assert (Present (Impl_Prag));
9585 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
9586 return Chars (Get_Pragma_Arg (Arg));
9587 end Implementation_Kind;
9589 --------------------------
9590 -- Implements_Interface --
9591 --------------------------
9593 function Implements_Interface
9594 (Typ_Ent : Entity_Id;
9595 Iface_Ent : Entity_Id;
9596 Exclude_Parents : Boolean := False) return Boolean
9598 Ifaces_List : Elist_Id;
9600 Iface : Entity_Id := Base_Type (Iface_Ent);
9601 Typ : Entity_Id := Base_Type (Typ_Ent);
9604 if Is_Class_Wide_Type (Typ) then
9605 Typ := Root_Type (Typ);
9608 if not Has_Interfaces (Typ) then
9612 if Is_Class_Wide_Type (Iface) then
9613 Iface := Root_Type (Iface);
9616 Collect_Interfaces (Typ, Ifaces_List);
9618 Elmt := First_Elmt (Ifaces_List);
9619 while Present (Elmt) loop
9620 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
9621 and then Exclude_Parents
9625 elsif Node (Elmt) = Iface then
9633 end Implements_Interface;
9635 ------------------------------------
9636 -- In_Assertion_Expression_Pragma --
9637 ------------------------------------
9639 function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is
9641 Prag : Node_Id := Empty;
9644 -- Climb the parent chain looking for an enclosing pragma
9647 while Present (Par) loop
9648 if Nkind (Par) = N_Pragma then
9652 -- Precondition-like pragmas are expanded into if statements, check
9653 -- the original node instead.
9655 elsif Nkind (Original_Node (Par)) = N_Pragma then
9656 Prag := Original_Node (Par);
9659 -- The expansion of attribute 'Old generates a constant to capture
9660 -- the result of the prefix. If the parent traversal reaches
9661 -- one of these constants, then the node technically came from a
9662 -- postcondition-like pragma. Note that the Ekind is not tested here
9663 -- because N may be the expression of an object declaration which is
9664 -- currently being analyzed. Such objects carry Ekind of E_Void.
9666 elsif Nkind (Par) = N_Object_Declaration
9667 and then Constant_Present (Par)
9668 and then Stores_Attribute_Old_Prefix (Defining_Entity (Par))
9672 -- Prevent the search from going too far
9674 elsif Is_Body_Or_Package_Declaration (Par) then
9678 Par := Parent (Par);
9683 and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag));
9684 end In_Assertion_Expression_Pragma;
9690 function In_Instance return Boolean is
9691 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
9696 while Present (S) and then S /= Standard_Standard loop
9697 if Ekind_In (S, E_Function, E_Package, E_Procedure)
9698 and then Is_Generic_Instance (S)
9700 -- A child instance is always compiled in the context of a parent
9701 -- instance. Nevertheless, the actuals are not analyzed in an
9702 -- instance context. We detect this case by examining the current
9703 -- compilation unit, which must be a child instance, and checking
9704 -- that it is not currently on the scope stack.
9706 if Is_Child_Unit (Curr_Unit)
9707 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
9708 N_Package_Instantiation
9709 and then not In_Open_Scopes (Curr_Unit)
9723 ----------------------
9724 -- In_Instance_Body --
9725 ----------------------
9727 function In_Instance_Body return Boolean is
9732 while Present (S) and then S /= Standard_Standard loop
9733 if Ekind_In (S, E_Function, E_Procedure)
9734 and then Is_Generic_Instance (S)
9738 elsif Ekind (S) = E_Package
9739 and then In_Package_Body (S)
9740 and then Is_Generic_Instance (S)
9749 end In_Instance_Body;
9751 -----------------------------
9752 -- In_Instance_Not_Visible --
9753 -----------------------------
9755 function In_Instance_Not_Visible return Boolean is
9760 while Present (S) and then S /= Standard_Standard loop
9761 if Ekind_In (S, E_Function, E_Procedure)
9762 and then Is_Generic_Instance (S)
9766 elsif Ekind (S) = E_Package
9767 and then (In_Package_Body (S) or else In_Private_Part (S))
9768 and then Is_Generic_Instance (S)
9777 end In_Instance_Not_Visible;
9779 ------------------------------
9780 -- In_Instance_Visible_Part --
9781 ------------------------------
9783 function In_Instance_Visible_Part return Boolean is
9788 while Present (S) and then S /= Standard_Standard loop
9789 if Ekind (S) = E_Package
9790 and then Is_Generic_Instance (S)
9791 and then not In_Package_Body (S)
9792 and then not In_Private_Part (S)
9801 end In_Instance_Visible_Part;
9803 ---------------------
9804 -- In_Package_Body --
9805 ---------------------
9807 function In_Package_Body return Boolean is
9812 while Present (S) and then S /= Standard_Standard loop
9813 if Ekind (S) = E_Package and then In_Package_Body (S) then
9821 end In_Package_Body;
9823 --------------------------------
9824 -- In_Parameter_Specification --
9825 --------------------------------
9827 function In_Parameter_Specification (N : Node_Id) return Boolean is
9832 while Present (PN) loop
9833 if Nkind (PN) = N_Parameter_Specification then
9841 end In_Parameter_Specification;
9843 --------------------------
9844 -- In_Pragma_Expression --
9845 --------------------------
9847 function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean is
9854 elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
9860 end In_Pragma_Expression;
9862 -------------------------------------
9863 -- In_Reverse_Storage_Order_Object --
9864 -------------------------------------
9866 function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
9868 Btyp : Entity_Id := Empty;
9871 -- Climb up indexed components
9875 case Nkind (Pref) is
9876 when N_Selected_Component =>
9877 Pref := Prefix (Pref);
9880 when N_Indexed_Component =>
9881 Pref := Prefix (Pref);
9889 if Present (Pref) then
9890 Btyp := Base_Type (Etype (Pref));
9893 return Present (Btyp)
9894 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
9895 and then Reverse_Storage_Order (Btyp);
9896 end In_Reverse_Storage_Order_Object;
9898 --------------------------------------
9899 -- In_Subprogram_Or_Concurrent_Unit --
9900 --------------------------------------
9902 function In_Subprogram_Or_Concurrent_Unit return Boolean is
9907 -- Use scope chain to check successively outer scopes
9913 if K in Subprogram_Kind
9914 or else K in Concurrent_Kind
9915 or else K in Generic_Subprogram_Kind
9919 elsif E = Standard_Standard then
9925 end In_Subprogram_Or_Concurrent_Unit;
9927 ---------------------
9928 -- In_Visible_Part --
9929 ---------------------
9931 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
9933 return Is_Package_Or_Generic_Package (Scope_Id)
9934 and then In_Open_Scopes (Scope_Id)
9935 and then not In_Package_Body (Scope_Id)
9936 and then not In_Private_Part (Scope_Id);
9937 end In_Visible_Part;
9939 --------------------------------
9940 -- Incomplete_Or_Partial_View --
9941 --------------------------------
9943 function Incomplete_Or_Partial_View (Id : Entity_Id) return Entity_Id is
9944 function Inspect_Decls
9946 Taft : Boolean := False) return Entity_Id;
9947 -- Check whether a declarative region contains the incomplete or partial
9954 function Inspect_Decls
9956 Taft : Boolean := False) return Entity_Id
9962 Decl := First (Decls);
9963 while Present (Decl) loop
9967 if Nkind (Decl) = N_Incomplete_Type_Declaration then
9968 Match := Defining_Identifier (Decl);
9972 if Nkind_In (Decl, N_Private_Extension_Declaration,
9973 N_Private_Type_Declaration)
9975 Match := Defining_Identifier (Decl);
9980 and then Present (Full_View (Match))
9981 and then Full_View (Match) = Id
9996 -- Start of processing for Incomplete_Or_Partial_View
9999 -- Deferred constant or incomplete type case
10001 Prev := Current_Entity_In_Scope (Id);
10004 and then (Is_Incomplete_Type (Prev) or else Ekind (Prev) = E_Constant)
10005 and then Present (Full_View (Prev))
10006 and then Full_View (Prev) = Id
10011 -- Private or Taft amendment type case
10014 Pkg : constant Entity_Id := Scope (Id);
10015 Pkg_Decl : Node_Id := Pkg;
10018 if Present (Pkg) and then Ekind (Pkg) = E_Package then
10019 while Nkind (Pkg_Decl) /= N_Package_Specification loop
10020 Pkg_Decl := Parent (Pkg_Decl);
10023 -- It is knows that Typ has a private view, look for it in the
10024 -- visible declarations of the enclosing scope. A special case
10025 -- of this is when the two views have been exchanged - the full
10026 -- appears earlier than the private.
10028 if Has_Private_Declaration (Id) then
10029 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
10031 -- Exchanged view case, look in the private declarations
10034 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
10039 -- Otherwise if this is the package body, then Typ is a potential
10040 -- Taft amendment type. The incomplete view should be located in
10041 -- the private declarations of the enclosing scope.
10043 elsif In_Package_Body (Pkg) then
10044 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
10049 -- The type has no incomplete or private view
10052 end Incomplete_Or_Partial_View;
10054 -----------------------------------------
10055 -- Inherit_Default_Init_Cond_Procedure --
10056 -----------------------------------------
10058 procedure Inherit_Default_Init_Cond_Procedure (Typ : Entity_Id) is
10059 Par_Typ : constant Entity_Id := Etype (Typ);
10062 -- A derived type inherits the default initial condition procedure of
10063 -- its parent type.
10065 if No (Default_Init_Cond_Procedure (Typ)) then
10066 Set_Default_Init_Cond_Procedure
10067 (Typ, Default_Init_Cond_Procedure (Par_Typ));
10069 end Inherit_Default_Init_Cond_Procedure;
10071 ----------------------------
10072 -- Inherit_Rep_Item_Chain --
10073 ----------------------------
10075 procedure Inherit_Rep_Item_Chain (Typ : Entity_Id; From_Typ : Entity_Id) is
10076 From_Item : constant Node_Id := First_Rep_Item (From_Typ);
10077 Item : Node_Id := Empty;
10078 Last_Item : Node_Id := Empty;
10081 -- Reach the end of the destination type's chain (if any) and capture
10084 Item := First_Rep_Item (Typ);
10085 while Present (Item) loop
10087 -- Do not inherit a chain that has been inherited already
10089 if Item = From_Item then
10094 Item := Next_Rep_Item (Item);
10097 -- When the destination type has a rep item chain, the chain of the
10098 -- source type is appended to it.
10100 if Present (Last_Item) then
10101 Set_Next_Rep_Item (Last_Item, From_Item);
10103 -- Otherwise the destination type directly inherits the rep item chain
10104 -- of the source type (if any).
10107 Set_First_Rep_Item (Typ, From_Item);
10109 end Inherit_Rep_Item_Chain;
10111 ---------------------------------
10112 -- Insert_Explicit_Dereference --
10113 ---------------------------------
10115 procedure Insert_Explicit_Dereference (N : Node_Id) is
10116 New_Prefix : constant Node_Id := Relocate_Node (N);
10117 Ent : Entity_Id := Empty;
10124 Save_Interps (N, New_Prefix);
10127 Make_Explicit_Dereference (Sloc (Parent (N)),
10128 Prefix => New_Prefix));
10130 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
10132 if Is_Overloaded (New_Prefix) then
10134 -- The dereference is also overloaded, and its interpretations are
10135 -- the designated types of the interpretations of the original node.
10137 Set_Etype (N, Any_Type);
10139 Get_First_Interp (New_Prefix, I, It);
10140 while Present (It.Nam) loop
10143 if Is_Access_Type (T) then
10144 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
10147 Get_Next_Interp (I, It);
10153 -- Prefix is unambiguous: mark the original prefix (which might
10154 -- Come_From_Source) as a reference, since the new (relocated) one
10155 -- won't be taken into account.
10157 if Is_Entity_Name (New_Prefix) then
10158 Ent := Entity (New_Prefix);
10159 Pref := New_Prefix;
10161 -- For a retrieval of a subcomponent of some composite object,
10162 -- retrieve the ultimate entity if there is one.
10164 elsif Nkind_In (New_Prefix, N_Selected_Component,
10165 N_Indexed_Component)
10167 Pref := Prefix (New_Prefix);
10168 while Present (Pref)
10169 and then Nkind_In (Pref, N_Selected_Component,
10170 N_Indexed_Component)
10172 Pref := Prefix (Pref);
10175 if Present (Pref) and then Is_Entity_Name (Pref) then
10176 Ent := Entity (Pref);
10180 -- Place the reference on the entity node
10182 if Present (Ent) then
10183 Generate_Reference (Ent, Pref);
10186 end Insert_Explicit_Dereference;
10188 ------------------------------------------
10189 -- Inspect_Deferred_Constant_Completion --
10190 ------------------------------------------
10192 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
10196 Decl := First (Decls);
10197 while Present (Decl) loop
10199 -- Deferred constant signature
10201 if Nkind (Decl) = N_Object_Declaration
10202 and then Constant_Present (Decl)
10203 and then No (Expression (Decl))
10205 -- No need to check internally generated constants
10207 and then Comes_From_Source (Decl)
10209 -- The constant is not completed. A full object declaration or a
10210 -- pragma Import complete a deferred constant.
10212 and then not Has_Completion (Defining_Identifier (Decl))
10215 ("constant declaration requires initialization expression",
10216 Defining_Identifier (Decl));
10219 Decl := Next (Decl);
10221 end Inspect_Deferred_Constant_Completion;
10223 -----------------------------
10224 -- Install_Generic_Formals --
10225 -----------------------------
10227 procedure Install_Generic_Formals (Subp_Id : Entity_Id) is
10231 pragma Assert (Is_Generic_Subprogram (Subp_Id));
10233 E := First_Entity (Subp_Id);
10234 while Present (E) loop
10235 Install_Entity (E);
10238 end Install_Generic_Formals;
10240 -----------------------------
10241 -- Is_Actual_Out_Parameter --
10242 -----------------------------
10244 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
10245 Formal : Entity_Id;
10248 Find_Actual (N, Formal, Call);
10249 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
10250 end Is_Actual_Out_Parameter;
10252 -------------------------
10253 -- Is_Actual_Parameter --
10254 -------------------------
10256 function Is_Actual_Parameter (N : Node_Id) return Boolean is
10257 PK : constant Node_Kind := Nkind (Parent (N));
10261 when N_Parameter_Association =>
10262 return N = Explicit_Actual_Parameter (Parent (N));
10264 when N_Subprogram_Call =>
10265 return Is_List_Member (N)
10267 List_Containing (N) = Parameter_Associations (Parent (N));
10272 end Is_Actual_Parameter;
10274 --------------------------------
10275 -- Is_Actual_Tagged_Parameter --
10276 --------------------------------
10278 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
10279 Formal : Entity_Id;
10282 Find_Actual (N, Formal, Call);
10283 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
10284 end Is_Actual_Tagged_Parameter;
10286 ---------------------
10287 -- Is_Aliased_View --
10288 ---------------------
10290 function Is_Aliased_View (Obj : Node_Id) return Boolean is
10294 if Is_Entity_Name (Obj) then
10301 or else (Present (Renamed_Object (E))
10302 and then Is_Aliased_View (Renamed_Object (E)))))
10304 or else ((Is_Formal (E)
10305 or else Ekind_In (E, E_Generic_In_Out_Parameter,
10306 E_Generic_In_Parameter))
10307 and then Is_Tagged_Type (Etype (E)))
10309 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
10311 -- Current instance of type, either directly or as rewritten
10312 -- reference to the current object.
10314 or else (Is_Entity_Name (Original_Node (Obj))
10315 and then Present (Entity (Original_Node (Obj)))
10316 and then Is_Type (Entity (Original_Node (Obj))))
10318 or else (Is_Type (E) and then E = Current_Scope)
10320 or else (Is_Incomplete_Or_Private_Type (E)
10321 and then Full_View (E) = Current_Scope)
10323 -- Ada 2012 AI05-0053: the return object of an extended return
10324 -- statement is aliased if its type is immutably limited.
10326 or else (Is_Return_Object (E)
10327 and then Is_Limited_View (Etype (E)));
10329 elsif Nkind (Obj) = N_Selected_Component then
10330 return Is_Aliased (Entity (Selector_Name (Obj)));
10332 elsif Nkind (Obj) = N_Indexed_Component then
10333 return Has_Aliased_Components (Etype (Prefix (Obj)))
10335 (Is_Access_Type (Etype (Prefix (Obj)))
10336 and then Has_Aliased_Components
10337 (Designated_Type (Etype (Prefix (Obj)))));
10339 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
10340 return Is_Tagged_Type (Etype (Obj))
10341 and then Is_Aliased_View (Expression (Obj));
10343 elsif Nkind (Obj) = N_Explicit_Dereference then
10344 return Nkind (Original_Node (Obj)) /= N_Function_Call;
10349 end Is_Aliased_View;
10351 -------------------------
10352 -- Is_Ancestor_Package --
10353 -------------------------
10355 function Is_Ancestor_Package
10357 E2 : Entity_Id) return Boolean
10363 while Present (Par) and then Par /= Standard_Standard loop
10368 Par := Scope (Par);
10372 end Is_Ancestor_Package;
10374 ----------------------
10375 -- Is_Atomic_Object --
10376 ----------------------
10378 function Is_Atomic_Object (N : Node_Id) return Boolean is
10380 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
10381 -- Determines if given object has atomic components
10383 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
10384 -- If prefix is an implicit dereference, examine designated type
10386 ----------------------
10387 -- Is_Atomic_Prefix --
10388 ----------------------
10390 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
10392 if Is_Access_Type (Etype (N)) then
10394 Has_Atomic_Components (Designated_Type (Etype (N)));
10396 return Object_Has_Atomic_Components (N);
10398 end Is_Atomic_Prefix;
10400 ----------------------------------
10401 -- Object_Has_Atomic_Components --
10402 ----------------------------------
10404 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
10406 if Has_Atomic_Components (Etype (N))
10407 or else Is_Atomic (Etype (N))
10411 elsif Is_Entity_Name (N)
10412 and then (Has_Atomic_Components (Entity (N))
10413 or else Is_Atomic (Entity (N)))
10417 elsif Nkind (N) = N_Selected_Component
10418 and then Is_Atomic (Entity (Selector_Name (N)))
10422 elsif Nkind (N) = N_Indexed_Component
10423 or else Nkind (N) = N_Selected_Component
10425 return Is_Atomic_Prefix (Prefix (N));
10430 end Object_Has_Atomic_Components;
10432 -- Start of processing for Is_Atomic_Object
10435 -- Predicate is not relevant to subprograms
10437 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
10440 elsif Is_Atomic (Etype (N))
10441 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
10445 elsif Nkind (N) = N_Selected_Component
10446 and then Is_Atomic (Entity (Selector_Name (N)))
10450 elsif Nkind (N) = N_Indexed_Component
10451 or else Nkind (N) = N_Selected_Component
10453 return Is_Atomic_Prefix (Prefix (N));
10458 end Is_Atomic_Object;
10460 -----------------------------
10461 -- Is_Atomic_Or_VFA_Object --
10462 -----------------------------
10464 function Is_Atomic_Or_VFA_Object (N : Node_Id) return Boolean is
10466 return Is_Atomic_Object (N)
10467 or else (Is_Object_Reference (N)
10468 and then Is_Entity_Name (N)
10469 and then (Is_Volatile_Full_Access (Entity (N))
10471 Is_Volatile_Full_Access (Etype (Entity (N)))));
10472 end Is_Atomic_Or_VFA_Object;
10474 -------------------------
10475 -- Is_Attribute_Result --
10476 -------------------------
10478 function Is_Attribute_Result (N : Node_Id) return Boolean is
10480 return Nkind (N) = N_Attribute_Reference
10481 and then Attribute_Name (N) = Name_Result;
10482 end Is_Attribute_Result;
10484 -------------------------
10485 -- Is_Attribute_Update --
10486 -------------------------
10488 function Is_Attribute_Update (N : Node_Id) return Boolean is
10490 return Nkind (N) = N_Attribute_Reference
10491 and then Attribute_Name (N) = Name_Update;
10492 end Is_Attribute_Update;
10494 ------------------------------------
10495 -- Is_Body_Or_Package_Declaration --
10496 ------------------------------------
10498 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
10500 return Nkind_In (N, N_Entry_Body,
10502 N_Package_Declaration,
10506 end Is_Body_Or_Package_Declaration;
10508 -----------------------
10509 -- Is_Bounded_String --
10510 -----------------------
10512 function Is_Bounded_String (T : Entity_Id) return Boolean is
10513 Under : constant Entity_Id := Underlying_Type (Root_Type (T));
10516 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
10517 -- Super_String, or one of the [Wide_]Wide_ versions. This will
10518 -- be True for all the Bounded_String types in instances of the
10519 -- Generic_Bounded_Length generics, and for types derived from those.
10521 return Present (Under)
10522 and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
10523 Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
10524 Is_RTE (Root_Type (Under), RO_WW_Super_String));
10525 end Is_Bounded_String;
10527 -------------------------
10528 -- Is_Child_Or_Sibling --
10529 -------------------------
10531 function Is_Child_Or_Sibling
10532 (Pack_1 : Entity_Id;
10533 Pack_2 : Entity_Id) return Boolean
10535 function Distance_From_Standard (Pack : Entity_Id) return Nat;
10536 -- Given an arbitrary package, return the number of "climbs" necessary
10537 -- to reach scope Standard_Standard.
10539 procedure Equalize_Depths
10540 (Pack : in out Entity_Id;
10541 Depth : in out Nat;
10542 Depth_To_Reach : Nat);
10543 -- Given an arbitrary package, its depth and a target depth to reach,
10544 -- climb the scope chain until the said depth is reached. The pointer
10545 -- to the package and its depth a modified during the climb.
10547 ----------------------------
10548 -- Distance_From_Standard --
10549 ----------------------------
10551 function Distance_From_Standard (Pack : Entity_Id) return Nat is
10558 while Present (Scop) and then Scop /= Standard_Standard loop
10560 Scop := Scope (Scop);
10564 end Distance_From_Standard;
10566 ---------------------
10567 -- Equalize_Depths --
10568 ---------------------
10570 procedure Equalize_Depths
10571 (Pack : in out Entity_Id;
10572 Depth : in out Nat;
10573 Depth_To_Reach : Nat)
10576 -- The package must be at a greater or equal depth
10578 if Depth < Depth_To_Reach then
10579 raise Program_Error;
10582 -- Climb the scope chain until the desired depth is reached
10584 while Present (Pack) and then Depth /= Depth_To_Reach loop
10585 Pack := Scope (Pack);
10586 Depth := Depth - 1;
10588 end Equalize_Depths;
10592 P_1 : Entity_Id := Pack_1;
10593 P_1_Child : Boolean := False;
10594 P_1_Depth : Nat := Distance_From_Standard (P_1);
10595 P_2 : Entity_Id := Pack_2;
10596 P_2_Child : Boolean := False;
10597 P_2_Depth : Nat := Distance_From_Standard (P_2);
10599 -- Start of processing for Is_Child_Or_Sibling
10603 (Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
10605 -- Both packages denote the same entity, therefore they cannot be
10606 -- children or siblings.
10611 -- One of the packages is at a deeper level than the other. Note that
10612 -- both may still come from differen hierarchies.
10620 elsif P_1_Depth > P_2_Depth then
10623 Depth => P_1_Depth,
10624 Depth_To_Reach => P_2_Depth);
10633 elsif P_2_Depth > P_1_Depth then
10636 Depth => P_2_Depth,
10637 Depth_To_Reach => P_1_Depth);
10641 -- At this stage the package pointers have been elevated to the same
10642 -- depth. If the related entities are the same, then one package is a
10643 -- potential child of the other:
10647 -- X became P_1 P_2 or vica versa
10653 return Is_Child_Unit (Pack_1);
10655 else pragma Assert (P_2_Child);
10656 return Is_Child_Unit (Pack_2);
10659 -- The packages may come from the same package chain or from entirely
10660 -- different hierarcies. To determine this, climb the scope stack until
10661 -- a common root is found.
10663 -- (root) (root 1) (root 2)
10668 while Present (P_1) and then Present (P_2) loop
10670 -- The two packages may be siblings
10673 return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2);
10676 P_1 := Scope (P_1);
10677 P_2 := Scope (P_2);
10682 end Is_Child_Or_Sibling;
10684 -----------------------------
10685 -- Is_Concurrent_Interface --
10686 -----------------------------
10688 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
10690 return Is_Interface (T)
10692 (Is_Protected_Interface (T)
10693 or else Is_Synchronized_Interface (T)
10694 or else Is_Task_Interface (T));
10695 end Is_Concurrent_Interface;
10697 -----------------------
10698 -- Is_Constant_Bound --
10699 -----------------------
10701 function Is_Constant_Bound (Exp : Node_Id) return Boolean is
10703 if Compile_Time_Known_Value (Exp) then
10706 elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
10707 return Is_Constant_Object (Entity (Exp))
10708 or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
10710 elsif Nkind (Exp) in N_Binary_Op then
10711 return Is_Constant_Bound (Left_Opnd (Exp))
10712 and then Is_Constant_Bound (Right_Opnd (Exp))
10713 and then Scope (Entity (Exp)) = Standard_Standard;
10718 end Is_Constant_Bound;
10720 ---------------------------
10721 -- Is_Container_Element --
10722 ---------------------------
10724 function Is_Container_Element (Exp : Node_Id) return Boolean is
10725 Loc : constant Source_Ptr := Sloc (Exp);
10726 Pref : constant Node_Id := Prefix (Exp);
10729 -- Call to an indexing aspect
10731 Cont_Typ : Entity_Id;
10732 -- The type of the container being accessed
10734 Elem_Typ : Entity_Id;
10735 -- Its element type
10737 Indexing : Entity_Id;
10738 Is_Const : Boolean;
10739 -- Indicates that constant indexing is used, and the element is thus
10742 Ref_Typ : Entity_Id;
10743 -- The reference type returned by the indexing operation
10746 -- If C is a container, in a context that imposes the element type of
10747 -- that container, the indexing notation C (X) is rewritten as:
10749 -- Indexing (C, X).Discr.all
10751 -- where Indexing is one of the indexing aspects of the container.
10752 -- If the context does not require a reference, the construct can be
10757 -- First, verify that the construct has the proper form
10759 if not Expander_Active then
10762 elsif Nkind (Pref) /= N_Selected_Component then
10765 elsif Nkind (Prefix (Pref)) /= N_Function_Call then
10769 Call := Prefix (Pref);
10770 Ref_Typ := Etype (Call);
10773 if not Has_Implicit_Dereference (Ref_Typ)
10774 or else No (First (Parameter_Associations (Call)))
10775 or else not Is_Entity_Name (Name (Call))
10780 -- Retrieve type of container object, and its iterator aspects
10782 Cont_Typ := Etype (First (Parameter_Associations (Call)));
10783 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Constant_Indexing);
10786 if No (Indexing) then
10788 -- Container should have at least one indexing operation
10792 elsif Entity (Name (Call)) /= Entity (Indexing) then
10794 -- This may be a variable indexing operation
10796 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Variable_Indexing);
10799 or else Entity (Name (Call)) /= Entity (Indexing)
10808 Elem_Typ := Find_Value_Of_Aspect (Cont_Typ, Aspect_Iterator_Element);
10810 if No (Elem_Typ) or else Entity (Elem_Typ) /= Etype (Exp) then
10814 -- Check that the expression is not the target of an assignment, in
10815 -- which case the rewriting is not possible.
10817 if not Is_Const then
10823 while Present (Par)
10825 if Nkind (Parent (Par)) = N_Assignment_Statement
10826 and then Par = Name (Parent (Par))
10830 -- A renaming produces a reference, and the transformation
10833 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
10837 (Nkind (Parent (Par)), N_Function_Call,
10838 N_Procedure_Call_Statement,
10839 N_Entry_Call_Statement)
10841 -- Check that the element is not part of an actual for an
10842 -- in-out parameter.
10849 F := First_Formal (Entity (Name (Parent (Par))));
10850 A := First (Parameter_Associations (Parent (Par)));
10851 while Present (F) loop
10852 if A = Par and then Ekind (F) /= E_In_Parameter then
10861 -- E_In_Parameter in a call: element is not modified.
10866 Par := Parent (Par);
10871 -- The expression has the proper form and the context requires the
10872 -- element type. Retrieve the Element function of the container and
10873 -- rewrite the construct as a call to it.
10879 Op := First_Elmt (Primitive_Operations (Cont_Typ));
10880 while Present (Op) loop
10881 exit when Chars (Node (Op)) = Name_Element;
10890 Make_Function_Call (Loc,
10891 Name => New_Occurrence_Of (Node (Op), Loc),
10892 Parameter_Associations => Parameter_Associations (Call)));
10893 Analyze_And_Resolve (Exp, Entity (Elem_Typ));
10897 end Is_Container_Element;
10899 ----------------------------
10900 -- Is_Contract_Annotation --
10901 ----------------------------
10903 function Is_Contract_Annotation (Item : Node_Id) return Boolean is
10905 return Is_Package_Contract_Annotation (Item)
10907 Is_Subprogram_Contract_Annotation (Item);
10908 end Is_Contract_Annotation;
10910 --------------------------------------
10911 -- Is_Controlling_Limited_Procedure --
10912 --------------------------------------
10914 function Is_Controlling_Limited_Procedure
10915 (Proc_Nam : Entity_Id) return Boolean
10917 Param_Typ : Entity_Id := Empty;
10920 if Ekind (Proc_Nam) = E_Procedure
10921 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
10923 Param_Typ := Etype (Parameter_Type (First (
10924 Parameter_Specifications (Parent (Proc_Nam)))));
10926 -- In this case where an Itype was created, the procedure call has been
10929 elsif Present (Associated_Node_For_Itype (Proc_Nam))
10930 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
10932 Present (Parameter_Associations
10933 (Associated_Node_For_Itype (Proc_Nam)))
10936 Etype (First (Parameter_Associations
10937 (Associated_Node_For_Itype (Proc_Nam))));
10940 if Present (Param_Typ) then
10942 Is_Interface (Param_Typ)
10943 and then Is_Limited_Record (Param_Typ);
10947 end Is_Controlling_Limited_Procedure;
10949 -----------------------------
10950 -- Is_CPP_Constructor_Call --
10951 -----------------------------
10953 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
10955 return Nkind (N) = N_Function_Call
10956 and then Is_CPP_Class (Etype (Etype (N)))
10957 and then Is_Constructor (Entity (Name (N)))
10958 and then Is_Imported (Entity (Name (N)));
10959 end Is_CPP_Constructor_Call;
10961 -------------------------
10962 -- Is_Current_Instance --
10963 -------------------------
10965 function Is_Current_Instance (N : Node_Id) return Boolean is
10966 Typ : constant Entity_Id := Entity (N);
10970 -- Simplest case: entity is a concurrent type and we are currently
10971 -- inside the body. This will eventually be expanded into a
10972 -- call to Self (for tasks) or _object (for protected objects).
10974 if Is_Concurrent_Type (Typ) and then In_Open_Scopes (Typ) then
10978 -- Check whether the context is a (sub)type declaration for the
10982 while Present (P) loop
10983 if Nkind_In (P, N_Full_Type_Declaration,
10984 N_Private_Type_Declaration,
10985 N_Subtype_Declaration)
10986 and then Comes_From_Source (P)
10987 and then Defining_Entity (P) = Typ
10996 -- In any other context this is not a current occurrence
10999 end Is_Current_Instance;
11001 --------------------
11002 -- Is_Declaration --
11003 --------------------
11005 function Is_Declaration (N : Node_Id) return Boolean is
11008 when N_Abstract_Subprogram_Declaration |
11009 N_Exception_Declaration |
11010 N_Exception_Renaming_Declaration |
11011 N_Full_Type_Declaration |
11012 N_Generic_Function_Renaming_Declaration |
11013 N_Generic_Package_Declaration |
11014 N_Generic_Package_Renaming_Declaration |
11015 N_Generic_Procedure_Renaming_Declaration |
11016 N_Generic_Subprogram_Declaration |
11017 N_Number_Declaration |
11018 N_Object_Declaration |
11019 N_Object_Renaming_Declaration |
11020 N_Package_Declaration |
11021 N_Package_Renaming_Declaration |
11022 N_Private_Extension_Declaration |
11023 N_Private_Type_Declaration |
11024 N_Subprogram_Declaration |
11025 N_Subprogram_Renaming_Declaration |
11026 N_Subtype_Declaration =>
11032 end Is_Declaration;
11034 --------------------------------
11035 -- Is_Declared_Within_Variant --
11036 --------------------------------
11038 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
11039 Comp_Decl : constant Node_Id := Parent (Comp);
11040 Comp_List : constant Node_Id := Parent (Comp_Decl);
11042 return Nkind (Parent (Comp_List)) = N_Variant;
11043 end Is_Declared_Within_Variant;
11045 ----------------------------------------------
11046 -- Is_Dependent_Component_Of_Mutable_Object --
11047 ----------------------------------------------
11049 function Is_Dependent_Component_Of_Mutable_Object
11050 (Object : Node_Id) return Boolean
11053 Prefix_Type : Entity_Id;
11054 P_Aliased : Boolean := False;
11057 Deref : Node_Id := Object;
11058 -- Dereference node, in something like X.all.Y(2)
11060 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
11063 -- Find the dereference node if any
11065 while Nkind_In (Deref, N_Indexed_Component,
11066 N_Selected_Component,
11069 Deref := Prefix (Deref);
11072 -- Ada 2005: If we have a component or slice of a dereference,
11073 -- something like X.all.Y (2), and the type of X is access-to-constant,
11074 -- Is_Variable will return False, because it is indeed a constant
11075 -- view. But it might be a view of a variable object, so we want the
11076 -- following condition to be True in that case.
11078 if Is_Variable (Object)
11079 or else (Ada_Version >= Ada_2005
11080 and then Nkind (Deref) = N_Explicit_Dereference)
11082 if Nkind (Object) = N_Selected_Component then
11083 P := Prefix (Object);
11084 Prefix_Type := Etype (P);
11086 if Is_Entity_Name (P) then
11087 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
11088 Prefix_Type := Base_Type (Prefix_Type);
11091 if Is_Aliased (Entity (P)) then
11095 -- A discriminant check on a selected component may be expanded
11096 -- into a dereference when removing side-effects. Recover the
11097 -- original node and its type, which may be unconstrained.
11099 elsif Nkind (P) = N_Explicit_Dereference
11100 and then not (Comes_From_Source (P))
11102 P := Original_Node (P);
11103 Prefix_Type := Etype (P);
11106 -- Check for prefix being an aliased component???
11112 -- A heap object is constrained by its initial value
11114 -- Ada 2005 (AI-363): Always assume the object could be mutable in
11115 -- the dereferenced case, since the access value might denote an
11116 -- unconstrained aliased object, whereas in Ada 95 the designated
11117 -- object is guaranteed to be constrained. A worst-case assumption
11118 -- has to apply in Ada 2005 because we can't tell at compile
11119 -- time whether the object is "constrained by its initial value"
11120 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
11121 -- rules (these rules are acknowledged to need fixing).
11123 if Ada_Version < Ada_2005 then
11124 if Is_Access_Type (Prefix_Type)
11125 or else Nkind (P) = N_Explicit_Dereference
11130 else pragma Assert (Ada_Version >= Ada_2005);
11131 if Is_Access_Type (Prefix_Type) then
11133 -- If the access type is pool-specific, and there is no
11134 -- constrained partial view of the designated type, then the
11135 -- designated object is known to be constrained.
11137 if Ekind (Prefix_Type) = E_Access_Type
11138 and then not Object_Type_Has_Constrained_Partial_View
11139 (Typ => Designated_Type (Prefix_Type),
11140 Scop => Current_Scope)
11144 -- Otherwise (general access type, or there is a constrained
11145 -- partial view of the designated type), we need to check
11146 -- based on the designated type.
11149 Prefix_Type := Designated_Type (Prefix_Type);
11155 Original_Record_Component (Entity (Selector_Name (Object)));
11157 -- As per AI-0017, the renaming is illegal in a generic body, even
11158 -- if the subtype is indefinite.
11160 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
11162 if not Is_Constrained (Prefix_Type)
11163 and then (Is_Definite_Subtype (Prefix_Type)
11165 (Is_Generic_Type (Prefix_Type)
11166 and then Ekind (Current_Scope) = E_Generic_Package
11167 and then In_Package_Body (Current_Scope)))
11169 and then (Is_Declared_Within_Variant (Comp)
11170 or else Has_Discriminant_Dependent_Constraint (Comp))
11171 and then (not P_Aliased or else Ada_Version >= Ada_2005)
11175 -- If the prefix is of an access type at this point, then we want
11176 -- to return False, rather than calling this function recursively
11177 -- on the access object (which itself might be a discriminant-
11178 -- dependent component of some other object, but that isn't
11179 -- relevant to checking the object passed to us). This avoids
11180 -- issuing wrong errors when compiling with -gnatc, where there
11181 -- can be implicit dereferences that have not been expanded.
11183 elsif Is_Access_Type (Etype (Prefix (Object))) then
11188 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
11191 elsif Nkind (Object) = N_Indexed_Component
11192 or else Nkind (Object) = N_Slice
11194 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
11196 -- A type conversion that Is_Variable is a view conversion:
11197 -- go back to the denoted object.
11199 elsif Nkind (Object) = N_Type_Conversion then
11201 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
11206 end Is_Dependent_Component_Of_Mutable_Object;
11208 ---------------------
11209 -- Is_Dereferenced --
11210 ---------------------
11212 function Is_Dereferenced (N : Node_Id) return Boolean is
11213 P : constant Node_Id := Parent (N);
11215 return Nkind_In (P, N_Selected_Component,
11216 N_Explicit_Dereference,
11217 N_Indexed_Component,
11219 and then Prefix (P) = N;
11220 end Is_Dereferenced;
11222 ----------------------
11223 -- Is_Descendent_Of --
11224 ----------------------
11226 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
11231 pragma Assert (Nkind (T1) in N_Entity);
11232 pragma Assert (Nkind (T2) in N_Entity);
11234 T := Base_Type (T1);
11236 -- Immediate return if the types match
11241 -- Comment needed here ???
11243 elsif Ekind (T) = E_Class_Wide_Type then
11244 return Etype (T) = T2;
11252 -- Done if we found the type we are looking for
11257 -- Done if no more derivations to check
11264 -- Following test catches error cases resulting from prev errors
11266 elsif No (Etyp) then
11269 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
11272 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
11276 T := Base_Type (Etyp);
11279 end Is_Descendent_Of;
11281 ---------------------------------------------
11282 -- Is_Double_Precision_Floating_Point_Type --
11283 ---------------------------------------------
11285 function Is_Double_Precision_Floating_Point_Type
11286 (E : Entity_Id) return Boolean is
11288 return Is_Floating_Point_Type (E)
11289 and then Machine_Radix_Value (E) = Uint_2
11290 and then Machine_Mantissa_Value (E) = UI_From_Int (53)
11291 and then Machine_Emax_Value (E) = Uint_2 ** Uint_10
11292 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_10);
11293 end Is_Double_Precision_Floating_Point_Type;
11295 -----------------------------
11296 -- Is_Effectively_Volatile --
11297 -----------------------------
11299 function Is_Effectively_Volatile (Id : Entity_Id) return Boolean is
11300 function Is_Descendant_Of_Suspension_Object
11301 (Typ : Entity_Id) return Boolean;
11302 -- Determine whether type Typ is a descendant of type Suspension_Object
11303 -- defined in Ada.Synchronous_Task_Control.
11305 ----------------------------------------
11306 -- Is_Descendant_Of_Suspension_Object --
11307 ----------------------------------------
11309 function Is_Descendant_Of_Suspension_Object
11310 (Typ : Entity_Id) return Boolean
11312 Cur_Typ : Entity_Id;
11313 Par_Typ : Entity_Id;
11316 -- Climb the type derivation chain checking each parent type against
11317 -- Suspension_Object.
11319 Cur_Typ := Base_Type (Typ);
11320 while Present (Cur_Typ) loop
11321 Par_Typ := Etype (Cur_Typ);
11323 -- The current type is a match
11325 if Is_Suspension_Object (Cur_Typ) then
11328 -- Stop the traversal once the root of the derivation chain has
11329 -- been reached. In that case the current type is its own base
11332 elsif Cur_Typ = Par_Typ then
11336 Cur_Typ := Base_Type (Par_Typ);
11340 end Is_Descendant_Of_Suspension_Object;
11342 -- Start of processing for Is_Effectively_Volatile
11345 if Is_Type (Id) then
11347 -- An arbitrary type is effectively volatile when it is subject to
11348 -- pragma Atomic or Volatile.
11350 if Is_Volatile (Id) then
11353 -- An array type is effectively volatile when it is subject to pragma
11354 -- Atomic_Components or Volatile_Components or its compolent type is
11355 -- effectively volatile.
11357 elsif Is_Array_Type (Id) then
11359 Has_Volatile_Components (Id)
11361 Is_Effectively_Volatile (Component_Type (Base_Type (Id)));
11363 -- A protected type is always volatile
11365 elsif Is_Protected_Type (Id) then
11368 -- A descendant of Ada.Synchronous_Task_Control.Suspension_Object is
11369 -- automatically volatile.
11371 elsif Is_Descendant_Of_Suspension_Object (Id) then
11374 -- Otherwise the type is not effectively volatile
11380 -- Otherwise Id denotes an object
11385 or else Has_Volatile_Components (Id)
11386 or else Is_Effectively_Volatile (Etype (Id));
11388 end Is_Effectively_Volatile;
11390 ------------------------------------
11391 -- Is_Effectively_Volatile_Object --
11392 ------------------------------------
11394 function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean is
11396 if Is_Entity_Name (N) then
11397 return Is_Effectively_Volatile (Entity (N));
11399 elsif Nkind (N) = N_Expanded_Name then
11400 return Is_Effectively_Volatile (Entity (N));
11402 elsif Nkind (N) = N_Indexed_Component then
11403 return Is_Effectively_Volatile_Object (Prefix (N));
11405 elsif Nkind (N) = N_Selected_Component then
11407 Is_Effectively_Volatile_Object (Prefix (N))
11409 Is_Effectively_Volatile_Object (Selector_Name (N));
11414 end Is_Effectively_Volatile_Object;
11416 -------------------
11417 -- Is_Entry_Body --
11418 -------------------
11420 function Is_Entry_Body (Id : Entity_Id) return Boolean is
11423 Ekind_In (Id, E_Entry, E_Entry_Family)
11424 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Body;
11427 --------------------------
11428 -- Is_Entry_Declaration --
11429 --------------------------
11431 function Is_Entry_Declaration (Id : Entity_Id) return Boolean is
11434 Ekind_In (Id, E_Entry, E_Entry_Family)
11435 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Declaration;
11436 end Is_Entry_Declaration;
11438 ----------------------------
11439 -- Is_Expression_Function --
11440 ----------------------------
11442 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
11446 if Ekind (Subp) /= E_Function then
11450 Decl := Unit_Declaration_Node (Subp);
11451 return Nkind (Decl) = N_Subprogram_Declaration
11453 (Nkind (Original_Node (Decl)) = N_Expression_Function
11455 (Present (Corresponding_Body (Decl))
11457 Nkind (Original_Node
11458 (Unit_Declaration_Node
11459 (Corresponding_Body (Decl)))) =
11460 N_Expression_Function));
11462 end Is_Expression_Function;
11464 -----------------------
11465 -- Is_EVF_Expression --
11466 -----------------------
11468 function Is_EVF_Expression (N : Node_Id) return Boolean is
11469 Orig_N : constant Node_Id := Original_Node (N);
11475 -- Detect a reference to a formal parameter of a specific tagged type
11476 -- whose related subprogram is subject to pragma Expresions_Visible with
11479 if Is_Entity_Name (N) and then Present (Entity (N)) then
11484 and then Is_Specific_Tagged_Type (Etype (Id))
11485 and then Extensions_Visible_Status (Id) =
11486 Extensions_Visible_False;
11488 -- A case expression is an EVF expression when it contains at least one
11489 -- EVF dependent_expression. Note that a case expression may have been
11490 -- expanded, hence the use of Original_Node.
11492 elsif Nkind (Orig_N) = N_Case_Expression then
11493 Alt := First (Alternatives (Orig_N));
11494 while Present (Alt) loop
11495 if Is_EVF_Expression (Expression (Alt)) then
11502 -- An if expression is an EVF expression when it contains at least one
11503 -- EVF dependent_expression. Note that an if expression may have been
11504 -- expanded, hence the use of Original_Node.
11506 elsif Nkind (Orig_N) = N_If_Expression then
11507 Expr := Next (First (Expressions (Orig_N)));
11508 while Present (Expr) loop
11509 if Is_EVF_Expression (Expr) then
11516 -- A qualified expression or a type conversion is an EVF expression when
11517 -- its operand is an EVF expression.
11519 elsif Nkind_In (N, N_Qualified_Expression,
11520 N_Unchecked_Type_Conversion,
11523 return Is_EVF_Expression (Expression (N));
11525 -- Attributes 'Loop_Entry, 'Old, and 'Update are EVF expressions when
11526 -- their prefix denotes an EVF expression.
11528 elsif Nkind (N) = N_Attribute_Reference
11529 and then Nam_In (Attribute_Name (N), Name_Loop_Entry,
11533 return Is_EVF_Expression (Prefix (N));
11537 end Is_EVF_Expression;
11543 function Is_False (U : Uint) return Boolean is
11548 ---------------------------
11549 -- Is_Fixed_Model_Number --
11550 ---------------------------
11552 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
11553 S : constant Ureal := Small_Value (T);
11554 M : Urealp.Save_Mark;
11558 R := (U = UR_Trunc (U / S) * S);
11559 Urealp.Release (M);
11561 end Is_Fixed_Model_Number;
11563 -------------------------------
11564 -- Is_Fully_Initialized_Type --
11565 -------------------------------
11567 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
11571 if Is_Scalar_Type (Typ) then
11573 -- A scalar type with an aspect Default_Value is fully initialized
11575 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
11576 -- of a scalar type, but we don't take that into account here, since
11577 -- we don't want these to affect warnings.
11579 return Has_Default_Aspect (Typ);
11581 elsif Is_Access_Type (Typ) then
11584 elsif Is_Array_Type (Typ) then
11585 if Is_Fully_Initialized_Type (Component_Type (Typ))
11586 or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
11591 -- An interesting case, if we have a constrained type one of whose
11592 -- bounds is known to be null, then there are no elements to be
11593 -- initialized, so all the elements are initialized.
11595 if Is_Constrained (Typ) then
11598 Indx_Typ : Entity_Id;
11599 Lbd, Hbd : Node_Id;
11602 Indx := First_Index (Typ);
11603 while Present (Indx) loop
11604 if Etype (Indx) = Any_Type then
11607 -- If index is a range, use directly
11609 elsif Nkind (Indx) = N_Range then
11610 Lbd := Low_Bound (Indx);
11611 Hbd := High_Bound (Indx);
11614 Indx_Typ := Etype (Indx);
11616 if Is_Private_Type (Indx_Typ) then
11617 Indx_Typ := Full_View (Indx_Typ);
11620 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
11623 Lbd := Type_Low_Bound (Indx_Typ);
11624 Hbd := Type_High_Bound (Indx_Typ);
11628 if Compile_Time_Known_Value (Lbd)
11630 Compile_Time_Known_Value (Hbd)
11632 if Expr_Value (Hbd) < Expr_Value (Lbd) then
11642 -- If no null indexes, then type is not fully initialized
11648 elsif Is_Record_Type (Typ) then
11649 if Has_Discriminants (Typ)
11651 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
11652 and then Is_Fully_Initialized_Variant (Typ)
11657 -- We consider bounded string types to be fully initialized, because
11658 -- otherwise we get false alarms when the Data component is not
11659 -- default-initialized.
11661 if Is_Bounded_String (Typ) then
11665 -- Controlled records are considered to be fully initialized if
11666 -- there is a user defined Initialize routine. This may not be
11667 -- entirely correct, but as the spec notes, we are guessing here
11668 -- what is best from the point of view of issuing warnings.
11670 if Is_Controlled (Typ) then
11672 Utyp : constant Entity_Id := Underlying_Type (Typ);
11675 if Present (Utyp) then
11677 Init : constant Entity_Id :=
11678 (Find_Optional_Prim_Op
11679 (Underlying_Type (Typ), Name_Initialize));
11683 and then Comes_From_Source (Init)
11685 Is_Predefined_File_Name
11686 (File_Name (Get_Source_File_Index (Sloc (Init))))
11690 elsif Has_Null_Extension (Typ)
11692 Is_Fully_Initialized_Type
11693 (Etype (Base_Type (Typ)))
11702 -- Otherwise see if all record components are initialized
11708 Ent := First_Entity (Typ);
11709 while Present (Ent) loop
11710 if Ekind (Ent) = E_Component
11711 and then (No (Parent (Ent))
11712 or else No (Expression (Parent (Ent))))
11713 and then not Is_Fully_Initialized_Type (Etype (Ent))
11715 -- Special VM case for tag components, which need to be
11716 -- defined in this case, but are never initialized as VMs
11717 -- are using other dispatching mechanisms. Ignore this
11718 -- uninitialized case. Note that this applies both to the
11719 -- uTag entry and the main vtable pointer (CPP_Class case).
11721 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
11730 -- No uninitialized components, so type is fully initialized.
11731 -- Note that this catches the case of no components as well.
11735 elsif Is_Concurrent_Type (Typ) then
11738 elsif Is_Private_Type (Typ) then
11740 U : constant Entity_Id := Underlying_Type (Typ);
11746 return Is_Fully_Initialized_Type (U);
11753 end Is_Fully_Initialized_Type;
11755 ----------------------------------
11756 -- Is_Fully_Initialized_Variant --
11757 ----------------------------------
11759 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
11760 Loc : constant Source_Ptr := Sloc (Typ);
11761 Constraints : constant List_Id := New_List;
11762 Components : constant Elist_Id := New_Elmt_List;
11763 Comp_Elmt : Elmt_Id;
11765 Comp_List : Node_Id;
11767 Discr_Val : Node_Id;
11769 Report_Errors : Boolean;
11770 pragma Warnings (Off, Report_Errors);
11773 if Serious_Errors_Detected > 0 then
11777 if Is_Record_Type (Typ)
11778 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
11779 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
11781 Comp_List := Component_List (Type_Definition (Parent (Typ)));
11783 Discr := First_Discriminant (Typ);
11784 while Present (Discr) loop
11785 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
11786 Discr_Val := Expression (Parent (Discr));
11788 if Present (Discr_Val)
11789 and then Is_OK_Static_Expression (Discr_Val)
11791 Append_To (Constraints,
11792 Make_Component_Association (Loc,
11793 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
11794 Expression => New_Copy (Discr_Val)));
11802 Next_Discriminant (Discr);
11807 Comp_List => Comp_List,
11808 Governed_By => Constraints,
11809 Into => Components,
11810 Report_Errors => Report_Errors);
11812 -- Check that each component present is fully initialized
11814 Comp_Elmt := First_Elmt (Components);
11815 while Present (Comp_Elmt) loop
11816 Comp_Id := Node (Comp_Elmt);
11818 if Ekind (Comp_Id) = E_Component
11819 and then (No (Parent (Comp_Id))
11820 or else No (Expression (Parent (Comp_Id))))
11821 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
11826 Next_Elmt (Comp_Elmt);
11831 elsif Is_Private_Type (Typ) then
11833 U : constant Entity_Id := Underlying_Type (Typ);
11839 return Is_Fully_Initialized_Variant (U);
11846 end Is_Fully_Initialized_Variant;
11848 ------------------------------------
11849 -- Is_Generic_Declaration_Or_Body --
11850 ------------------------------------
11852 function Is_Generic_Declaration_Or_Body (Decl : Node_Id) return Boolean is
11853 Spec_Decl : Node_Id;
11856 -- Package/subprogram body
11858 if Nkind_In (Decl, N_Package_Body, N_Subprogram_Body)
11859 and then Present (Corresponding_Spec (Decl))
11861 Spec_Decl := Unit_Declaration_Node (Corresponding_Spec (Decl));
11863 -- Package/subprogram body stub
11865 elsif Nkind_In (Decl, N_Package_Body_Stub, N_Subprogram_Body_Stub)
11866 and then Present (Corresponding_Spec_Of_Stub (Decl))
11869 Unit_Declaration_Node (Corresponding_Spec_Of_Stub (Decl));
11877 -- Rather than inspecting the defining entity of the spec declaration,
11878 -- look at its Nkind. This takes care of the case where the analysis of
11879 -- a generic body modifies the Ekind of its spec to allow for recursive
11883 Nkind_In (Spec_Decl, N_Generic_Package_Declaration,
11884 N_Generic_Subprogram_Declaration);
11885 end Is_Generic_Declaration_Or_Body;
11887 ----------------------------
11888 -- Is_Inherited_Operation --
11889 ----------------------------
11891 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
11892 pragma Assert (Is_Overloadable (E));
11893 Kind : constant Node_Kind := Nkind (Parent (E));
11895 return Kind = N_Full_Type_Declaration
11896 or else Kind = N_Private_Extension_Declaration
11897 or else Kind = N_Subtype_Declaration
11898 or else (Ekind (E) = E_Enumeration_Literal
11899 and then Is_Derived_Type (Etype (E)));
11900 end Is_Inherited_Operation;
11902 -------------------------------------
11903 -- Is_Inherited_Operation_For_Type --
11904 -------------------------------------
11906 function Is_Inherited_Operation_For_Type
11908 Typ : Entity_Id) return Boolean
11911 -- Check that the operation has been created by the type declaration
11913 return Is_Inherited_Operation (E)
11914 and then Defining_Identifier (Parent (E)) = Typ;
11915 end Is_Inherited_Operation_For_Type;
11921 function Is_Iterator (Typ : Entity_Id) return Boolean is
11922 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean;
11923 -- Determine whether type Iter_Typ is a predefined forward or reversible
11926 ----------------------
11927 -- Denotes_Iterator --
11928 ----------------------
11930 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean is
11933 Nam_In (Chars (Iter_Typ), Name_Forward_Iterator,
11934 Name_Reversible_Iterator)
11935 and then Is_Predefined_File_Name
11936 (Unit_File_Name (Get_Source_Unit (Iter_Typ)));
11937 end Denotes_Iterator;
11941 Iface_Elmt : Elmt_Id;
11944 -- Start of processing for Is_Iterator
11947 -- The type may be a subtype of a descendant of the proper instance of
11948 -- the predefined interface type, so we must use the root type of the
11949 -- given type. The same is done for Is_Reversible_Iterator.
11951 if Is_Class_Wide_Type (Typ)
11952 and then Denotes_Iterator (Root_Type (Typ))
11956 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
11959 elsif Present (Find_Value_Of_Aspect (Typ, Aspect_Iterable)) then
11963 Collect_Interfaces (Typ, Ifaces);
11965 Iface_Elmt := First_Elmt (Ifaces);
11966 while Present (Iface_Elmt) loop
11967 if Denotes_Iterator (Node (Iface_Elmt)) then
11971 Next_Elmt (Iface_Elmt);
11978 ----------------------------
11979 -- Is_Iterator_Over_Array --
11980 ----------------------------
11982 function Is_Iterator_Over_Array (N : Node_Id) return Boolean is
11983 Container : constant Node_Id := Name (N);
11984 Container_Typ : constant Entity_Id := Base_Type (Etype (Container));
11986 return Is_Array_Type (Container_Typ);
11987 end Is_Iterator_Over_Array;
11993 -- We seem to have a lot of overlapping functions that do similar things
11994 -- (testing for left hand sides or lvalues???).
11996 function Is_LHS (N : Node_Id) return Is_LHS_Result is
11997 P : constant Node_Id := Parent (N);
12000 -- Return True if we are the left hand side of an assignment statement
12002 if Nkind (P) = N_Assignment_Statement then
12003 if Name (P) = N then
12009 -- Case of prefix of indexed or selected component or slice
12011 elsif Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
12012 and then N = Prefix (P)
12014 -- Here we have the case where the parent P is N.Q or N(Q .. R).
12015 -- If P is an LHS, then N is also effectively an LHS, but there
12016 -- is an important exception. If N is of an access type, then
12017 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
12018 -- case this makes N.all a left hand side but not N itself.
12020 -- If we don't know the type yet, this is the case where we return
12021 -- Unknown, since the answer depends on the type which is unknown.
12023 if No (Etype (N)) then
12026 -- We have an Etype set, so we can check it
12028 elsif Is_Access_Type (Etype (N)) then
12031 -- OK, not access type case, so just test whole expression
12037 -- All other cases are not left hand sides
12044 -----------------------------
12045 -- Is_Library_Level_Entity --
12046 -----------------------------
12048 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
12050 -- The following is a small optimization, and it also properly handles
12051 -- discriminals, which in task bodies might appear in expressions before
12052 -- the corresponding procedure has been created, and which therefore do
12053 -- not have an assigned scope.
12055 if Is_Formal (E) then
12059 -- Normal test is simply that the enclosing dynamic scope is Standard
12061 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
12062 end Is_Library_Level_Entity;
12064 --------------------------------
12065 -- Is_Limited_Class_Wide_Type --
12066 --------------------------------
12068 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
12071 Is_Class_Wide_Type (Typ)
12072 and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
12073 end Is_Limited_Class_Wide_Type;
12075 ---------------------------------
12076 -- Is_Local_Variable_Reference --
12077 ---------------------------------
12079 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
12081 if not Is_Entity_Name (Expr) then
12086 Ent : constant Entity_Id := Entity (Expr);
12087 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
12089 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
12092 return Present (Sub) and then Sub = Current_Subprogram;
12096 end Is_Local_Variable_Reference;
12098 -------------------------
12099 -- Is_Object_Reference --
12100 -------------------------
12102 function Is_Object_Reference (N : Node_Id) return Boolean is
12104 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean;
12105 -- Determine whether N is the name of an internally-generated renaming
12107 --------------------------------------
12108 -- Is_Internally_Generated_Renaming --
12109 --------------------------------------
12111 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean is
12116 while Present (P) loop
12117 if Nkind (P) = N_Object_Renaming_Declaration then
12118 return not Comes_From_Source (P);
12119 elsif Is_List_Member (P) then
12127 end Is_Internally_Generated_Renaming;
12129 -- Start of processing for Is_Object_Reference
12132 if Is_Entity_Name (N) then
12133 return Present (Entity (N)) and then Is_Object (Entity (N));
12137 when N_Indexed_Component | N_Slice =>
12139 Is_Object_Reference (Prefix (N))
12140 or else Is_Access_Type (Etype (Prefix (N)));
12142 -- In Ada 95, a function call is a constant object; a procedure
12145 when N_Function_Call =>
12146 return Etype (N) /= Standard_Void_Type;
12148 -- Attributes 'Input, 'Loop_Entry, 'Old and 'Result produce
12151 when N_Attribute_Reference =>
12153 Nam_In (Attribute_Name (N), Name_Input,
12158 when N_Selected_Component =>
12160 Is_Object_Reference (Selector_Name (N))
12162 (Is_Object_Reference (Prefix (N))
12163 or else Is_Access_Type (Etype (Prefix (N))));
12165 when N_Explicit_Dereference =>
12168 -- A view conversion of a tagged object is an object reference
12170 when N_Type_Conversion =>
12171 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
12172 and then Is_Tagged_Type (Etype (Expression (N)))
12173 and then Is_Object_Reference (Expression (N));
12175 -- An unchecked type conversion is considered to be an object if
12176 -- the operand is an object (this construction arises only as a
12177 -- result of expansion activities).
12179 when N_Unchecked_Type_Conversion =>
12182 -- Allow string literals to act as objects as long as they appear
12183 -- in internally-generated renamings. The expansion of iterators
12184 -- may generate such renamings when the range involves a string
12187 when N_String_Literal =>
12188 return Is_Internally_Generated_Renaming (Parent (N));
12190 -- AI05-0003: In Ada 2012 a qualified expression is a name.
12191 -- This allows disambiguation of function calls and the use
12192 -- of aggregates in more contexts.
12194 when N_Qualified_Expression =>
12195 if Ada_Version < Ada_2012 then
12198 return Is_Object_Reference (Expression (N))
12199 or else Nkind (Expression (N)) = N_Aggregate;
12206 end Is_Object_Reference;
12208 -----------------------------------
12209 -- Is_OK_Variable_For_Out_Formal --
12210 -----------------------------------
12212 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
12214 Note_Possible_Modification (AV, Sure => True);
12216 -- We must reject parenthesized variable names. Comes_From_Source is
12217 -- checked because there are currently cases where the compiler violates
12218 -- this rule (e.g. passing a task object to its controlled Initialize
12219 -- routine). This should be properly documented in sinfo???
12221 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
12224 -- A variable is always allowed
12226 elsif Is_Variable (AV) then
12229 -- Generalized indexing operations are rewritten as explicit
12230 -- dereferences, and it is only during resolution that we can
12231 -- check whether the context requires an access_to_variable type.
12233 elsif Nkind (AV) = N_Explicit_Dereference
12234 and then Ada_Version >= Ada_2012
12235 and then Nkind (Original_Node (AV)) = N_Indexed_Component
12236 and then Present (Etype (Original_Node (AV)))
12237 and then Has_Implicit_Dereference (Etype (Original_Node (AV)))
12239 return not Is_Access_Constant (Etype (Prefix (AV)));
12241 -- Unchecked conversions are allowed only if they come from the
12242 -- generated code, which sometimes uses unchecked conversions for out
12243 -- parameters in cases where code generation is unaffected. We tell
12244 -- source unchecked conversions by seeing if they are rewrites of
12245 -- an original Unchecked_Conversion function call, or of an explicit
12246 -- conversion of a function call or an aggregate (as may happen in the
12247 -- expansion of a packed array aggregate).
12249 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
12250 if Nkind_In (Original_Node (AV), N_Function_Call, N_Aggregate) then
12253 elsif Comes_From_Source (AV)
12254 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
12258 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
12259 return Is_OK_Variable_For_Out_Formal (Expression (AV));
12265 -- Normal type conversions are allowed if argument is a variable
12267 elsif Nkind (AV) = N_Type_Conversion then
12268 if Is_Variable (Expression (AV))
12269 and then Paren_Count (Expression (AV)) = 0
12271 Note_Possible_Modification (Expression (AV), Sure => True);
12274 -- We also allow a non-parenthesized expression that raises
12275 -- constraint error if it rewrites what used to be a variable
12277 elsif Raises_Constraint_Error (Expression (AV))
12278 and then Paren_Count (Expression (AV)) = 0
12279 and then Is_Variable (Original_Node (Expression (AV)))
12283 -- Type conversion of something other than a variable
12289 -- If this node is rewritten, then test the original form, if that is
12290 -- OK, then we consider the rewritten node OK (for example, if the
12291 -- original node is a conversion, then Is_Variable will not be true
12292 -- but we still want to allow the conversion if it converts a variable).
12294 elsif Original_Node (AV) /= AV then
12296 -- In Ada 2012, the explicit dereference may be a rewritten call to a
12297 -- Reference function.
12299 if Ada_Version >= Ada_2012
12300 and then Nkind (Original_Node (AV)) = N_Function_Call
12302 Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
12305 -- Check that this is not a constant reference.
12307 return not Is_Access_Constant (Etype (Prefix (AV)));
12309 elsif Has_Implicit_Dereference (Etype (Original_Node (AV))) then
12311 not Is_Access_Constant (Etype
12312 (Get_Reference_Discriminant (Etype (Original_Node (AV)))));
12315 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
12318 -- All other non-variables are rejected
12323 end Is_OK_Variable_For_Out_Formal;
12325 ------------------------------------
12326 -- Is_Package_Contract_Annotation --
12327 ------------------------------------
12329 function Is_Package_Contract_Annotation (Item : Node_Id) return Boolean is
12333 if Nkind (Item) = N_Aspect_Specification then
12334 Nam := Chars (Identifier (Item));
12336 else pragma Assert (Nkind (Item) = N_Pragma);
12337 Nam := Pragma_Name (Item);
12340 return Nam = Name_Abstract_State
12341 or else Nam = Name_Initial_Condition
12342 or else Nam = Name_Initializes
12343 or else Nam = Name_Refined_State;
12344 end Is_Package_Contract_Annotation;
12346 -----------------------------------
12347 -- Is_Partially_Initialized_Type --
12348 -----------------------------------
12350 function Is_Partially_Initialized_Type
12352 Include_Implicit : Boolean := True) return Boolean
12355 if Is_Scalar_Type (Typ) then
12358 elsif Is_Access_Type (Typ) then
12359 return Include_Implicit;
12361 elsif Is_Array_Type (Typ) then
12363 -- If component type is partially initialized, so is array type
12365 if Is_Partially_Initialized_Type
12366 (Component_Type (Typ), Include_Implicit)
12370 -- Otherwise we are only partially initialized if we are fully
12371 -- initialized (this is the empty array case, no point in us
12372 -- duplicating that code here).
12375 return Is_Fully_Initialized_Type (Typ);
12378 elsif Is_Record_Type (Typ) then
12380 -- A discriminated type is always partially initialized if in
12383 if Has_Discriminants (Typ) and then Include_Implicit then
12386 -- A tagged type is always partially initialized
12388 elsif Is_Tagged_Type (Typ) then
12391 -- Case of non-discriminated record
12397 Component_Present : Boolean := False;
12398 -- Set True if at least one component is present. If no
12399 -- components are present, then record type is fully
12400 -- initialized (another odd case, like the null array).
12403 -- Loop through components
12405 Ent := First_Entity (Typ);
12406 while Present (Ent) loop
12407 if Ekind (Ent) = E_Component then
12408 Component_Present := True;
12410 -- If a component has an initialization expression then
12411 -- the enclosing record type is partially initialized
12413 if Present (Parent (Ent))
12414 and then Present (Expression (Parent (Ent)))
12418 -- If a component is of a type which is itself partially
12419 -- initialized, then the enclosing record type is also.
12421 elsif Is_Partially_Initialized_Type
12422 (Etype (Ent), Include_Implicit)
12431 -- No initialized components found. If we found any components
12432 -- they were all uninitialized so the result is false.
12434 if Component_Present then
12437 -- But if we found no components, then all the components are
12438 -- initialized so we consider the type to be initialized.
12446 -- Concurrent types are always fully initialized
12448 elsif Is_Concurrent_Type (Typ) then
12451 -- For a private type, go to underlying type. If there is no underlying
12452 -- type then just assume this partially initialized. Not clear if this
12453 -- can happen in a non-error case, but no harm in testing for this.
12455 elsif Is_Private_Type (Typ) then
12457 U : constant Entity_Id := Underlying_Type (Typ);
12462 return Is_Partially_Initialized_Type (U, Include_Implicit);
12466 -- For any other type (are there any?) assume partially initialized
12471 end Is_Partially_Initialized_Type;
12473 ------------------------------------
12474 -- Is_Potentially_Persistent_Type --
12475 ------------------------------------
12477 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
12482 -- For private type, test corresponding full type
12484 if Is_Private_Type (T) then
12485 return Is_Potentially_Persistent_Type (Full_View (T));
12487 -- Scalar types are potentially persistent
12489 elsif Is_Scalar_Type (T) then
12492 -- Record type is potentially persistent if not tagged and the types of
12493 -- all it components are potentially persistent, and no component has
12494 -- an initialization expression.
12496 elsif Is_Record_Type (T)
12497 and then not Is_Tagged_Type (T)
12498 and then not Is_Partially_Initialized_Type (T)
12500 Comp := First_Component (T);
12501 while Present (Comp) loop
12502 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
12505 Next_Entity (Comp);
12511 -- Array type is potentially persistent if its component type is
12512 -- potentially persistent and if all its constraints are static.
12514 elsif Is_Array_Type (T) then
12515 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
12519 Indx := First_Index (T);
12520 while Present (Indx) loop
12521 if not Is_OK_Static_Subtype (Etype (Indx)) then
12530 -- All other types are not potentially persistent
12535 end Is_Potentially_Persistent_Type;
12537 --------------------------------
12538 -- Is_Potentially_Unevaluated --
12539 --------------------------------
12541 function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is
12549 -- A postcondition whose expression is a short-circuit is broken down
12550 -- into individual aspects for better exception reporting. The original
12551 -- short-circuit expression is rewritten as the second operand, and an
12552 -- occurrence of 'Old in that operand is potentially unevaluated.
12553 -- See Sem_ch13.adb for details of this transformation.
12555 if Nkind (Original_Node (Par)) = N_And_Then then
12559 while not Nkind_In (Par, N_If_Expression,
12567 Par := Parent (Par);
12569 -- If the context is not an expression, or if is the result of
12570 -- expansion of an enclosing construct (such as another attribute)
12571 -- the predicate does not apply.
12573 if Nkind (Par) not in N_Subexpr
12574 or else not Comes_From_Source (Par)
12580 if Nkind (Par) = N_If_Expression then
12581 return Is_Elsif (Par) or else Expr /= First (Expressions (Par));
12583 elsif Nkind (Par) = N_Case_Expression then
12584 return Expr /= Expression (Par);
12586 elsif Nkind_In (Par, N_And_Then, N_Or_Else) then
12587 return Expr = Right_Opnd (Par);
12589 elsif Nkind_In (Par, N_In, N_Not_In) then
12590 return Expr /= Left_Opnd (Par);
12595 end Is_Potentially_Unevaluated;
12597 ---------------------------------
12598 -- Is_Protected_Self_Reference --
12599 ---------------------------------
12601 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
12603 function In_Access_Definition (N : Node_Id) return Boolean;
12604 -- Returns true if N belongs to an access definition
12606 --------------------------
12607 -- In_Access_Definition --
12608 --------------------------
12610 function In_Access_Definition (N : Node_Id) return Boolean is
12615 while Present (P) loop
12616 if Nkind (P) = N_Access_Definition then
12624 end In_Access_Definition;
12626 -- Start of processing for Is_Protected_Self_Reference
12629 -- Verify that prefix is analyzed and has the proper form. Note that
12630 -- the attributes Elab_Spec, Elab_Body and Elab_Subp_Body which also
12631 -- produce the address of an entity, do not analyze their prefix
12632 -- because they denote entities that are not necessarily visible.
12633 -- Neither of them can apply to a protected type.
12635 return Ada_Version >= Ada_2005
12636 and then Is_Entity_Name (N)
12637 and then Present (Entity (N))
12638 and then Is_Protected_Type (Entity (N))
12639 and then In_Open_Scopes (Entity (N))
12640 and then not In_Access_Definition (N);
12641 end Is_Protected_Self_Reference;
12643 -----------------------------
12644 -- Is_RCI_Pkg_Spec_Or_Body --
12645 -----------------------------
12647 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
12649 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
12650 -- Return True if the unit of Cunit is an RCI package declaration
12652 ---------------------------
12653 -- Is_RCI_Pkg_Decl_Cunit --
12654 ---------------------------
12656 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
12657 The_Unit : constant Node_Id := Unit (Cunit);
12660 if Nkind (The_Unit) /= N_Package_Declaration then
12664 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
12665 end Is_RCI_Pkg_Decl_Cunit;
12667 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
12670 return Is_RCI_Pkg_Decl_Cunit (Cunit)
12672 (Nkind (Unit (Cunit)) = N_Package_Body
12673 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
12674 end Is_RCI_Pkg_Spec_Or_Body;
12676 -----------------------------------------
12677 -- Is_Remote_Access_To_Class_Wide_Type --
12678 -----------------------------------------
12680 function Is_Remote_Access_To_Class_Wide_Type
12681 (E : Entity_Id) return Boolean
12684 -- A remote access to class-wide type is a general access to object type
12685 -- declared in the visible part of a Remote_Types or Remote_Call_
12688 return Ekind (E) = E_General_Access_Type
12689 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
12690 end Is_Remote_Access_To_Class_Wide_Type;
12692 -----------------------------------------
12693 -- Is_Remote_Access_To_Subprogram_Type --
12694 -----------------------------------------
12696 function Is_Remote_Access_To_Subprogram_Type
12697 (E : Entity_Id) return Boolean
12700 return (Ekind (E) = E_Access_Subprogram_Type
12701 or else (Ekind (E) = E_Record_Type
12702 and then Present (Corresponding_Remote_Type (E))))
12703 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
12704 end Is_Remote_Access_To_Subprogram_Type;
12706 --------------------
12707 -- Is_Remote_Call --
12708 --------------------
12710 function Is_Remote_Call (N : Node_Id) return Boolean is
12712 if Nkind (N) not in N_Subprogram_Call then
12714 -- An entry call cannot be remote
12718 elsif Nkind (Name (N)) in N_Has_Entity
12719 and then Is_Remote_Call_Interface (Entity (Name (N)))
12721 -- A subprogram declared in the spec of a RCI package is remote
12725 elsif Nkind (Name (N)) = N_Explicit_Dereference
12726 and then Is_Remote_Access_To_Subprogram_Type
12727 (Etype (Prefix (Name (N))))
12729 -- The dereference of a RAS is a remote call
12733 elsif Present (Controlling_Argument (N))
12734 and then Is_Remote_Access_To_Class_Wide_Type
12735 (Etype (Controlling_Argument (N)))
12737 -- Any primitive operation call with a controlling argument of
12738 -- a RACW type is a remote call.
12743 -- All other calls are local calls
12746 end Is_Remote_Call;
12748 ----------------------
12749 -- Is_Renamed_Entry --
12750 ----------------------
12752 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
12753 Orig_Node : Node_Id := Empty;
12754 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
12756 function Is_Entry (Nam : Node_Id) return Boolean;
12757 -- Determine whether Nam is an entry. Traverse selectors if there are
12758 -- nested selected components.
12764 function Is_Entry (Nam : Node_Id) return Boolean is
12766 if Nkind (Nam) = N_Selected_Component then
12767 return Is_Entry (Selector_Name (Nam));
12770 return Ekind (Entity (Nam)) = E_Entry;
12773 -- Start of processing for Is_Renamed_Entry
12776 if Present (Alias (Proc_Nam)) then
12777 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
12780 -- Look for a rewritten subprogram renaming declaration
12782 if Nkind (Subp_Decl) = N_Subprogram_Declaration
12783 and then Present (Original_Node (Subp_Decl))
12785 Orig_Node := Original_Node (Subp_Decl);
12788 -- The rewritten subprogram is actually an entry
12790 if Present (Orig_Node)
12791 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
12792 and then Is_Entry (Name (Orig_Node))
12798 end Is_Renamed_Entry;
12800 -----------------------------
12801 -- Is_Renaming_Declaration --
12802 -----------------------------
12804 function Is_Renaming_Declaration (N : Node_Id) return Boolean is
12807 when N_Exception_Renaming_Declaration |
12808 N_Generic_Function_Renaming_Declaration |
12809 N_Generic_Package_Renaming_Declaration |
12810 N_Generic_Procedure_Renaming_Declaration |
12811 N_Object_Renaming_Declaration |
12812 N_Package_Renaming_Declaration |
12813 N_Subprogram_Renaming_Declaration =>
12819 end Is_Renaming_Declaration;
12821 ----------------------------
12822 -- Is_Reversible_Iterator --
12823 ----------------------------
12825 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
12826 Ifaces_List : Elist_Id;
12827 Iface_Elmt : Elmt_Id;
12831 if Is_Class_Wide_Type (Typ)
12832 and then Chars (Root_Type (Typ)) = Name_Reversible_Iterator
12833 and then Is_Predefined_File_Name
12834 (Unit_File_Name (Get_Source_Unit (Root_Type (Typ))))
12838 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
12842 Collect_Interfaces (Typ, Ifaces_List);
12844 Iface_Elmt := First_Elmt (Ifaces_List);
12845 while Present (Iface_Elmt) loop
12846 Iface := Node (Iface_Elmt);
12847 if Chars (Iface) = Name_Reversible_Iterator
12849 Is_Predefined_File_Name
12850 (Unit_File_Name (Get_Source_Unit (Iface)))
12855 Next_Elmt (Iface_Elmt);
12860 end Is_Reversible_Iterator;
12862 ----------------------
12863 -- Is_Selector_Name --
12864 ----------------------
12866 function Is_Selector_Name (N : Node_Id) return Boolean is
12868 if not Is_List_Member (N) then
12870 P : constant Node_Id := Parent (N);
12872 return Nkind_In (P, N_Expanded_Name,
12873 N_Generic_Association,
12874 N_Parameter_Association,
12875 N_Selected_Component)
12876 and then Selector_Name (P) = N;
12881 L : constant List_Id := List_Containing (N);
12882 P : constant Node_Id := Parent (L);
12884 return (Nkind (P) = N_Discriminant_Association
12885 and then Selector_Names (P) = L)
12887 (Nkind (P) = N_Component_Association
12888 and then Choices (P) = L);
12891 end Is_Selector_Name;
12893 ---------------------------------------------
12894 -- Is_Single_Precision_Floating_Point_Type --
12895 ---------------------------------------------
12897 function Is_Single_Precision_Floating_Point_Type
12898 (E : Entity_Id) return Boolean is
12900 return Is_Floating_Point_Type (E)
12901 and then Machine_Radix_Value (E) = Uint_2
12902 and then Machine_Mantissa_Value (E) = Uint_24
12903 and then Machine_Emax_Value (E) = Uint_2 ** Uint_7
12904 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_7);
12905 end Is_Single_Precision_Floating_Point_Type;
12907 -------------------------------------
12908 -- Is_SPARK_05_Initialization_Expr --
12909 -------------------------------------
12911 function Is_SPARK_05_Initialization_Expr (N : Node_Id) return Boolean is
12914 Comp_Assn : Node_Id;
12915 Orig_N : constant Node_Id := Original_Node (N);
12920 if not Comes_From_Source (Orig_N) then
12924 pragma Assert (Nkind (Orig_N) in N_Subexpr);
12926 case Nkind (Orig_N) is
12927 when N_Character_Literal |
12928 N_Integer_Literal |
12930 N_String_Literal =>
12933 when N_Identifier |
12935 if Is_Entity_Name (Orig_N)
12936 and then Present (Entity (Orig_N)) -- needed in some cases
12938 case Ekind (Entity (Orig_N)) is
12940 E_Enumeration_Literal |
12945 if Is_Type (Entity (Orig_N)) then
12953 when N_Qualified_Expression |
12954 N_Type_Conversion =>
12955 Is_Ok := Is_SPARK_05_Initialization_Expr (Expression (Orig_N));
12958 Is_Ok := Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
12962 N_Membership_Test =>
12963 Is_Ok := Is_SPARK_05_Initialization_Expr (Left_Opnd (Orig_N))
12965 Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
12968 N_Extension_Aggregate =>
12969 if Nkind (Orig_N) = N_Extension_Aggregate then
12971 Is_SPARK_05_Initialization_Expr (Ancestor_Part (Orig_N));
12974 Expr := First (Expressions (Orig_N));
12975 while Present (Expr) loop
12976 if not Is_SPARK_05_Initialization_Expr (Expr) then
12984 Comp_Assn := First (Component_Associations (Orig_N));
12985 while Present (Comp_Assn) loop
12986 Expr := Expression (Comp_Assn);
12988 -- Note: test for Present here needed for box assocation
12991 and then not Is_SPARK_05_Initialization_Expr (Expr)
13000 when N_Attribute_Reference =>
13001 if Nkind (Prefix (Orig_N)) in N_Subexpr then
13002 Is_Ok := Is_SPARK_05_Initialization_Expr (Prefix (Orig_N));
13005 Expr := First (Expressions (Orig_N));
13006 while Present (Expr) loop
13007 if not Is_SPARK_05_Initialization_Expr (Expr) then
13015 -- Selected components might be expanded named not yet resolved, so
13016 -- default on the safe side. (Eg on sparklex.ads)
13018 when N_Selected_Component =>
13027 end Is_SPARK_05_Initialization_Expr;
13029 ----------------------------------
13030 -- Is_SPARK_05_Object_Reference --
13031 ----------------------------------
13033 function Is_SPARK_05_Object_Reference (N : Node_Id) return Boolean is
13035 if Is_Entity_Name (N) then
13036 return Present (Entity (N))
13038 (Ekind_In (Entity (N), E_Constant, E_Variable)
13039 or else Ekind (Entity (N)) in Formal_Kind);
13043 when N_Selected_Component =>
13044 return Is_SPARK_05_Object_Reference (Prefix (N));
13050 end Is_SPARK_05_Object_Reference;
13052 -----------------------------
13053 -- Is_Specific_Tagged_Type --
13054 -----------------------------
13056 function Is_Specific_Tagged_Type (Typ : Entity_Id) return Boolean is
13057 Full_Typ : Entity_Id;
13060 -- Handle private types
13062 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
13063 Full_Typ := Full_View (Typ);
13068 -- A specific tagged type is a non-class-wide tagged type
13070 return Is_Tagged_Type (Full_Typ) and not Is_Class_Wide_Type (Full_Typ);
13071 end Is_Specific_Tagged_Type;
13077 function Is_Statement (N : Node_Id) return Boolean is
13080 Nkind (N) in N_Statement_Other_Than_Procedure_Call
13081 or else Nkind (N) = N_Procedure_Call_Statement;
13084 ---------------------------------------
13085 -- Is_Subprogram_Contract_Annotation --
13086 ---------------------------------------
13088 function Is_Subprogram_Contract_Annotation
13089 (Item : Node_Id) return Boolean
13094 if Nkind (Item) = N_Aspect_Specification then
13095 Nam := Chars (Identifier (Item));
13097 else pragma Assert (Nkind (Item) = N_Pragma);
13098 Nam := Pragma_Name (Item);
13101 return Nam = Name_Contract_Cases
13102 or else Nam = Name_Depends
13103 or else Nam = Name_Extensions_Visible
13104 or else Nam = Name_Global
13105 or else Nam = Name_Post
13106 or else Nam = Name_Post_Class
13107 or else Nam = Name_Postcondition
13108 or else Nam = Name_Pre
13109 or else Nam = Name_Pre_Class
13110 or else Nam = Name_Precondition
13111 or else Nam = Name_Refined_Depends
13112 or else Nam = Name_Refined_Global
13113 or else Nam = Name_Refined_Post
13114 or else Nam = Name_Test_Case;
13115 end Is_Subprogram_Contract_Annotation;
13117 --------------------------------------------------
13118 -- Is_Subprogram_Stub_Without_Prior_Declaration --
13119 --------------------------------------------------
13121 function Is_Subprogram_Stub_Without_Prior_Declaration
13122 (N : Node_Id) return Boolean
13125 -- A subprogram stub without prior declaration serves as declaration for
13126 -- the actual subprogram body. As such, it has an attached defining
13127 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
13129 return Nkind (N) = N_Subprogram_Body_Stub
13130 and then Ekind (Defining_Entity (N)) /= E_Subprogram_Body;
13131 end Is_Subprogram_Stub_Without_Prior_Declaration;
13133 --------------------------
13134 -- Is_Suspension_Object --
13135 --------------------------
13137 function Is_Suspension_Object (Id : Entity_Id) return Boolean is
13139 -- This approach does an exact name match rather than to rely on
13140 -- RTSfind. Routine Is_Effectively_Volatile is used by clients of the
13141 -- front end at point where all auxiliary tables are locked and any
13142 -- modifications to them are treated as violations. Do not tamper with
13143 -- the tables, instead examine the Chars fields of all the scopes of Id.
13146 Chars (Id) = Name_Suspension_Object
13147 and then Present (Scope (Id))
13148 and then Chars (Scope (Id)) = Name_Synchronous_Task_Control
13149 and then Present (Scope (Scope (Id)))
13150 and then Chars (Scope (Scope (Id))) = Name_Ada
13151 and then Present (Scope (Scope (Scope (Id))))
13152 and then Scope (Scope (Scope (Id))) = Standard_Standard;
13153 end Is_Suspension_Object;
13155 ---------------------------------
13156 -- Is_Synchronized_Tagged_Type --
13157 ---------------------------------
13159 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
13160 Kind : constant Entity_Kind := Ekind (Base_Type (E));
13163 -- A task or protected type derived from an interface is a tagged type.
13164 -- Such a tagged type is called a synchronized tagged type, as are
13165 -- synchronized interfaces and private extensions whose declaration
13166 -- includes the reserved word synchronized.
13168 return (Is_Tagged_Type (E)
13169 and then (Kind = E_Task_Type
13171 Kind = E_Protected_Type))
13174 and then Is_Synchronized_Interface (E))
13176 (Ekind (E) = E_Record_Type_With_Private
13177 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
13178 and then (Synchronized_Present (Parent (E))
13179 or else Is_Synchronized_Interface (Etype (E))));
13180 end Is_Synchronized_Tagged_Type;
13186 function Is_Transfer (N : Node_Id) return Boolean is
13187 Kind : constant Node_Kind := Nkind (N);
13190 if Kind = N_Simple_Return_Statement
13192 Kind = N_Extended_Return_Statement
13194 Kind = N_Goto_Statement
13196 Kind = N_Raise_Statement
13198 Kind = N_Requeue_Statement
13202 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
13203 and then No (Condition (N))
13207 elsif Kind = N_Procedure_Call_Statement
13208 and then Is_Entity_Name (Name (N))
13209 and then Present (Entity (Name (N)))
13210 and then No_Return (Entity (Name (N)))
13214 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
13226 function Is_True (U : Uint) return Boolean is
13231 --------------------------------------
13232 -- Is_Unchecked_Conversion_Instance --
13233 --------------------------------------
13235 function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is
13236 Gen_Par : Entity_Id;
13239 -- Look for a function whose generic parent is the predefined intrinsic
13240 -- function Unchecked_Conversion.
13242 if Ekind (Id) = E_Function then
13243 Gen_Par := Generic_Parent (Parent (Id));
13247 and then Chars (Gen_Par) = Name_Unchecked_Conversion
13248 and then Is_Intrinsic_Subprogram (Gen_Par)
13249 and then Is_Predefined_File_Name
13250 (Unit_File_Name (Get_Source_Unit (Gen_Par)));
13254 end Is_Unchecked_Conversion_Instance;
13256 -------------------------------
13257 -- Is_Universal_Numeric_Type --
13258 -------------------------------
13260 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
13262 return T = Universal_Integer or else T = Universal_Real;
13263 end Is_Universal_Numeric_Type;
13265 ----------------------------
13266 -- Is_Variable_Size_Array --
13267 ----------------------------
13269 function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
13273 pragma Assert (Is_Array_Type (E));
13275 -- Check if some index is initialized with a non-constant value
13277 Idx := First_Index (E);
13278 while Present (Idx) loop
13279 if Nkind (Idx) = N_Range then
13280 if not Is_Constant_Bound (Low_Bound (Idx))
13281 or else not Is_Constant_Bound (High_Bound (Idx))
13287 Idx := Next_Index (Idx);
13291 end Is_Variable_Size_Array;
13293 -----------------------------
13294 -- Is_Variable_Size_Record --
13295 -----------------------------
13297 function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
13299 Comp_Typ : Entity_Id;
13302 pragma Assert (Is_Record_Type (E));
13304 Comp := First_Entity (E);
13305 while Present (Comp) loop
13306 Comp_Typ := Etype (Comp);
13308 -- Recursive call if the record type has discriminants
13310 if Is_Record_Type (Comp_Typ)
13311 and then Has_Discriminants (Comp_Typ)
13312 and then Is_Variable_Size_Record (Comp_Typ)
13316 elsif Is_Array_Type (Comp_Typ)
13317 and then Is_Variable_Size_Array (Comp_Typ)
13322 Next_Entity (Comp);
13326 end Is_Variable_Size_Record;
13332 function Is_Variable
13334 Use_Original_Node : Boolean := True) return Boolean
13336 Orig_Node : Node_Id;
13338 function In_Protected_Function (E : Entity_Id) return Boolean;
13339 -- Within a protected function, the private components of the enclosing
13340 -- protected type are constants. A function nested within a (protected)
13341 -- procedure is not itself protected. Within the body of a protected
13342 -- function the current instance of the protected type is a constant.
13344 function Is_Variable_Prefix (P : Node_Id) return Boolean;
13345 -- Prefixes can involve implicit dereferences, in which case we must
13346 -- test for the case of a reference of a constant access type, which can
13347 -- can never be a variable.
13349 ---------------------------
13350 -- In_Protected_Function --
13351 ---------------------------
13353 function In_Protected_Function (E : Entity_Id) return Boolean is
13358 -- E is the current instance of a type
13360 if Is_Type (E) then
13369 if not Is_Protected_Type (Prot) then
13373 S := Current_Scope;
13374 while Present (S) and then S /= Prot loop
13375 if Ekind (S) = E_Function and then Scope (S) = Prot then
13384 end In_Protected_Function;
13386 ------------------------
13387 -- Is_Variable_Prefix --
13388 ------------------------
13390 function Is_Variable_Prefix (P : Node_Id) return Boolean is
13392 if Is_Access_Type (Etype (P)) then
13393 return not Is_Access_Constant (Root_Type (Etype (P)));
13395 -- For the case of an indexed component whose prefix has a packed
13396 -- array type, the prefix has been rewritten into a type conversion.
13397 -- Determine variable-ness from the converted expression.
13399 elsif Nkind (P) = N_Type_Conversion
13400 and then not Comes_From_Source (P)
13401 and then Is_Array_Type (Etype (P))
13402 and then Is_Packed (Etype (P))
13404 return Is_Variable (Expression (P));
13407 return Is_Variable (P);
13409 end Is_Variable_Prefix;
13411 -- Start of processing for Is_Variable
13414 -- Special check, allow x'Deref(expr) as a variable
13416 if Nkind (N) = N_Attribute_Reference
13417 and then Attribute_Name (N) = Name_Deref
13422 -- Check if we perform the test on the original node since this may be a
13423 -- test of syntactic categories which must not be disturbed by whatever
13424 -- rewriting might have occurred. For example, an aggregate, which is
13425 -- certainly NOT a variable, could be turned into a variable by
13428 if Use_Original_Node then
13429 Orig_Node := Original_Node (N);
13434 -- Definitely OK if Assignment_OK is set. Since this is something that
13435 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
13437 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
13440 -- Normally we go to the original node, but there is one exception where
13441 -- we use the rewritten node, namely when it is an explicit dereference.
13442 -- The generated code may rewrite a prefix which is an access type with
13443 -- an explicit dereference. The dereference is a variable, even though
13444 -- the original node may not be (since it could be a constant of the
13447 -- In Ada 2005 we have a further case to consider: the prefix may be a
13448 -- function call given in prefix notation. The original node appears to
13449 -- be a selected component, but we need to examine the call.
13451 elsif Nkind (N) = N_Explicit_Dereference
13452 and then Nkind (Orig_Node) /= N_Explicit_Dereference
13453 and then Present (Etype (Orig_Node))
13454 and then Is_Access_Type (Etype (Orig_Node))
13456 -- Note that if the prefix is an explicit dereference that does not
13457 -- come from source, we must check for a rewritten function call in
13458 -- prefixed notation before other forms of rewriting, to prevent a
13462 (Nkind (Orig_Node) = N_Function_Call
13463 and then not Is_Access_Constant (Etype (Prefix (N))))
13465 Is_Variable_Prefix (Original_Node (Prefix (N)));
13467 -- in Ada 2012, the dereference may have been added for a type with
13468 -- a declared implicit dereference aspect. Check that it is not an
13469 -- access to constant.
13471 elsif Nkind (N) = N_Explicit_Dereference
13472 and then Present (Etype (Orig_Node))
13473 and then Ada_Version >= Ada_2012
13474 and then Has_Implicit_Dereference (Etype (Orig_Node))
13476 return not Is_Access_Constant (Etype (Prefix (N)));
13478 -- A function call is never a variable
13480 elsif Nkind (N) = N_Function_Call then
13483 -- All remaining checks use the original node
13485 elsif Is_Entity_Name (Orig_Node)
13486 and then Present (Entity (Orig_Node))
13489 E : constant Entity_Id := Entity (Orig_Node);
13490 K : constant Entity_Kind := Ekind (E);
13493 return (K = E_Variable
13494 and then Nkind (Parent (E)) /= N_Exception_Handler)
13495 or else (K = E_Component
13496 and then not In_Protected_Function (E))
13497 or else K = E_Out_Parameter
13498 or else K = E_In_Out_Parameter
13499 or else K = E_Generic_In_Out_Parameter
13501 -- Current instance of type. If this is a protected type, check
13502 -- we are not within the body of one of its protected functions.
13504 or else (Is_Type (E)
13505 and then In_Open_Scopes (E)
13506 and then not In_Protected_Function (E))
13508 or else (Is_Incomplete_Or_Private_Type (E)
13509 and then In_Open_Scopes (Full_View (E)));
13513 case Nkind (Orig_Node) is
13514 when N_Indexed_Component | N_Slice =>
13515 return Is_Variable_Prefix (Prefix (Orig_Node));
13517 when N_Selected_Component =>
13518 return (Is_Variable (Selector_Name (Orig_Node))
13519 and then Is_Variable_Prefix (Prefix (Orig_Node)))
13521 (Nkind (N) = N_Expanded_Name
13522 and then Scope (Entity (N)) = Entity (Prefix (N)));
13524 -- For an explicit dereference, the type of the prefix cannot
13525 -- be an access to constant or an access to subprogram.
13527 when N_Explicit_Dereference =>
13529 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
13531 return Is_Access_Type (Typ)
13532 and then not Is_Access_Constant (Root_Type (Typ))
13533 and then Ekind (Typ) /= E_Access_Subprogram_Type;
13536 -- The type conversion is the case where we do not deal with the
13537 -- context dependent special case of an actual parameter. Thus
13538 -- the type conversion is only considered a variable for the
13539 -- purposes of this routine if the target type is tagged. However,
13540 -- a type conversion is considered to be a variable if it does not
13541 -- come from source (this deals for example with the conversions
13542 -- of expressions to their actual subtypes).
13544 when N_Type_Conversion =>
13545 return Is_Variable (Expression (Orig_Node))
13547 (not Comes_From_Source (Orig_Node)
13549 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
13551 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
13553 -- GNAT allows an unchecked type conversion as a variable. This
13554 -- only affects the generation of internal expanded code, since
13555 -- calls to instantiations of Unchecked_Conversion are never
13556 -- considered variables (since they are function calls).
13558 when N_Unchecked_Type_Conversion =>
13559 return Is_Variable (Expression (Orig_Node));
13567 ---------------------------
13568 -- Is_Visibly_Controlled --
13569 ---------------------------
13571 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
13572 Root : constant Entity_Id := Root_Type (T);
13574 return Chars (Scope (Root)) = Name_Finalization
13575 and then Chars (Scope (Scope (Root))) = Name_Ada
13576 and then Scope (Scope (Scope (Root))) = Standard_Standard;
13577 end Is_Visibly_Controlled;
13579 --------------------------
13580 -- Is_Volatile_Function --
13581 --------------------------
13583 function Is_Volatile_Function (Func_Id : Entity_Id) return Boolean is
13585 -- The caller must ensure that Func_Id denotes a function
13587 pragma Assert (Ekind_In (Func_Id, E_Function, E_Generic_Function));
13589 -- A protected function is automatically volatile
13591 if Is_Primitive (Func_Id)
13592 and then Present (First_Formal (Func_Id))
13593 and then Is_Protected_Type (Etype (First_Formal (Func_Id)))
13597 -- An instance of Ada.Unchecked_Conversion is a volatile function if
13598 -- either the source or the target are effectively volatile.
13600 elsif Is_Unchecked_Conversion_Instance (Func_Id)
13601 and then Has_Effectively_Volatile_Profile (Func_Id)
13605 -- Otherwise the function is treated as volatile if it is subject to
13606 -- enabled pragma Volatile_Function.
13610 Is_Enabled_Pragma (Get_Pragma (Func_Id, Pragma_Volatile_Function));
13612 end Is_Volatile_Function;
13614 ------------------------
13615 -- Is_Volatile_Object --
13616 ------------------------
13618 function Is_Volatile_Object (N : Node_Id) return Boolean is
13620 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
13621 -- If prefix is an implicit dereference, examine designated type
13623 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
13624 -- Determines if given object has volatile components
13626 ------------------------
13627 -- Is_Volatile_Prefix --
13628 ------------------------
13630 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
13631 Typ : constant Entity_Id := Etype (N);
13634 if Is_Access_Type (Typ) then
13636 Dtyp : constant Entity_Id := Designated_Type (Typ);
13639 return Is_Volatile (Dtyp)
13640 or else Has_Volatile_Components (Dtyp);
13644 return Object_Has_Volatile_Components (N);
13646 end Is_Volatile_Prefix;
13648 ------------------------------------
13649 -- Object_Has_Volatile_Components --
13650 ------------------------------------
13652 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
13653 Typ : constant Entity_Id := Etype (N);
13656 if Is_Volatile (Typ)
13657 or else Has_Volatile_Components (Typ)
13661 elsif Is_Entity_Name (N)
13662 and then (Has_Volatile_Components (Entity (N))
13663 or else Is_Volatile (Entity (N)))
13667 elsif Nkind (N) = N_Indexed_Component
13668 or else Nkind (N) = N_Selected_Component
13670 return Is_Volatile_Prefix (Prefix (N));
13675 end Object_Has_Volatile_Components;
13677 -- Start of processing for Is_Volatile_Object
13680 if Nkind (N) = N_Defining_Identifier then
13681 return Is_Volatile (N) or else Is_Volatile (Etype (N));
13683 elsif Nkind (N) = N_Expanded_Name then
13684 return Is_Volatile_Object (Entity (N));
13686 elsif Is_Volatile (Etype (N))
13687 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
13691 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component)
13692 and then Is_Volatile_Prefix (Prefix (N))
13696 elsif Nkind (N) = N_Selected_Component
13697 and then Is_Volatile (Entity (Selector_Name (N)))
13704 end Is_Volatile_Object;
13706 ---------------------------
13707 -- Itype_Has_Declaration --
13708 ---------------------------
13710 function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
13712 pragma Assert (Is_Itype (Id));
13713 return Present (Parent (Id))
13714 and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
13715 N_Subtype_Declaration)
13716 and then Defining_Entity (Parent (Id)) = Id;
13717 end Itype_Has_Declaration;
13719 -------------------------
13720 -- Kill_Current_Values --
13721 -------------------------
13723 procedure Kill_Current_Values
13725 Last_Assignment_Only : Boolean := False)
13728 if Is_Assignable (Ent) then
13729 Set_Last_Assignment (Ent, Empty);
13732 if Is_Object (Ent) then
13733 if not Last_Assignment_Only then
13735 Set_Current_Value (Ent, Empty);
13737 -- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
13738 -- for a constant. Once the constant is elaborated, its value is
13739 -- not changed, therefore the associated flags that describe the
13740 -- value should not be modified either.
13742 if Ekind (Ent) = E_Constant then
13745 -- Non-constant entities
13748 if not Can_Never_Be_Null (Ent) then
13749 Set_Is_Known_Non_Null (Ent, False);
13752 Set_Is_Known_Null (Ent, False);
13754 -- Reset the Is_Known_Valid flag unless the type is always
13755 -- valid. This does not apply to a loop parameter because its
13756 -- bounds are defined by the loop header and therefore always
13759 if not Is_Known_Valid (Etype (Ent))
13760 and then Ekind (Ent) /= E_Loop_Parameter
13762 Set_Is_Known_Valid (Ent, False);
13767 end Kill_Current_Values;
13769 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
13772 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
13773 -- Clear current value for entity E and all entities chained to E
13775 ------------------------------------------
13776 -- Kill_Current_Values_For_Entity_Chain --
13777 ------------------------------------------
13779 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
13783 while Present (Ent) loop
13784 Kill_Current_Values (Ent, Last_Assignment_Only);
13787 end Kill_Current_Values_For_Entity_Chain;
13789 -- Start of processing for Kill_Current_Values
13792 -- Kill all saved checks, a special case of killing saved values
13794 if not Last_Assignment_Only then
13798 -- Loop through relevant scopes, which includes the current scope and
13799 -- any parent scopes if the current scope is a block or a package.
13801 S := Current_Scope;
13804 -- Clear current values of all entities in current scope
13806 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
13808 -- If scope is a package, also clear current values of all private
13809 -- entities in the scope.
13811 if Is_Package_Or_Generic_Package (S)
13812 or else Is_Concurrent_Type (S)
13814 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
13817 -- If this is a not a subprogram, deal with parents
13819 if not Is_Subprogram (S) then
13821 exit Scope_Loop when S = Standard_Standard;
13825 end loop Scope_Loop;
13826 end Kill_Current_Values;
13828 --------------------------
13829 -- Kill_Size_Check_Code --
13830 --------------------------
13832 procedure Kill_Size_Check_Code (E : Entity_Id) is
13834 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
13835 and then Present (Size_Check_Code (E))
13837 Remove (Size_Check_Code (E));
13838 Set_Size_Check_Code (E, Empty);
13840 end Kill_Size_Check_Code;
13842 --------------------------
13843 -- Known_To_Be_Assigned --
13844 --------------------------
13846 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
13847 P : constant Node_Id := Parent (N);
13852 -- Test left side of assignment
13854 when N_Assignment_Statement =>
13855 return N = Name (P);
13857 -- Function call arguments are never lvalues
13859 when N_Function_Call =>
13862 -- Positional parameter for procedure or accept call
13864 when N_Procedure_Call_Statement |
13873 Proc := Get_Subprogram_Entity (P);
13879 -- If we are not a list member, something is strange, so
13880 -- be conservative and return False.
13882 if not Is_List_Member (N) then
13886 -- We are going to find the right formal by stepping forward
13887 -- through the formals, as we step backwards in the actuals.
13889 Form := First_Formal (Proc);
13892 -- If no formal, something is weird, so be conservative
13893 -- and return False.
13900 exit when No (Act);
13901 Next_Formal (Form);
13904 return Ekind (Form) /= E_In_Parameter;
13907 -- Named parameter for procedure or accept call
13909 when N_Parameter_Association =>
13915 Proc := Get_Subprogram_Entity (Parent (P));
13921 -- Loop through formals to find the one that matches
13923 Form := First_Formal (Proc);
13925 -- If no matching formal, that's peculiar, some kind of
13926 -- previous error, so return False to be conservative.
13927 -- Actually this also happens in legal code in the case
13928 -- where P is a parameter association for an Extra_Formal???
13934 -- Else test for match
13936 if Chars (Form) = Chars (Selector_Name (P)) then
13937 return Ekind (Form) /= E_In_Parameter;
13940 Next_Formal (Form);
13944 -- Test for appearing in a conversion that itself appears
13945 -- in an lvalue context, since this should be an lvalue.
13947 when N_Type_Conversion =>
13948 return Known_To_Be_Assigned (P);
13950 -- All other references are definitely not known to be modifications
13956 end Known_To_Be_Assigned;
13958 ---------------------------
13959 -- Last_Source_Statement --
13960 ---------------------------
13962 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
13966 N := Last (Statements (HSS));
13967 while Present (N) loop
13968 exit when Comes_From_Source (N);
13973 end Last_Source_Statement;
13975 ----------------------------------
13976 -- Matching_Static_Array_Bounds --
13977 ----------------------------------
13979 function Matching_Static_Array_Bounds
13981 R_Typ : Node_Id) return Boolean
13983 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
13984 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
13996 if L_Ndims /= R_Ndims then
14000 -- Unconstrained types do not have static bounds
14002 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
14006 -- First treat specially the first dimension, as the lower bound and
14007 -- length of string literals are not stored like those of arrays.
14009 if Ekind (L_Typ) = E_String_Literal_Subtype then
14010 L_Low := String_Literal_Low_Bound (L_Typ);
14011 L_Len := String_Literal_Length (L_Typ);
14013 L_Index := First_Index (L_Typ);
14014 Get_Index_Bounds (L_Index, L_Low, L_High);
14016 if Is_OK_Static_Expression (L_Low)
14018 Is_OK_Static_Expression (L_High)
14020 if Expr_Value (L_High) < Expr_Value (L_Low) then
14023 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
14030 if Ekind (R_Typ) = E_String_Literal_Subtype then
14031 R_Low := String_Literal_Low_Bound (R_Typ);
14032 R_Len := String_Literal_Length (R_Typ);
14034 R_Index := First_Index (R_Typ);
14035 Get_Index_Bounds (R_Index, R_Low, R_High);
14037 if Is_OK_Static_Expression (R_Low)
14039 Is_OK_Static_Expression (R_High)
14041 if Expr_Value (R_High) < Expr_Value (R_Low) then
14044 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
14051 if (Is_OK_Static_Expression (L_Low)
14053 Is_OK_Static_Expression (R_Low))
14054 and then Expr_Value (L_Low) = Expr_Value (R_Low)
14055 and then L_Len = R_Len
14062 -- Then treat all other dimensions
14064 for Indx in 2 .. L_Ndims loop
14068 Get_Index_Bounds (L_Index, L_Low, L_High);
14069 Get_Index_Bounds (R_Index, R_Low, R_High);
14071 if (Is_OK_Static_Expression (L_Low) and then
14072 Is_OK_Static_Expression (L_High) and then
14073 Is_OK_Static_Expression (R_Low) and then
14074 Is_OK_Static_Expression (R_High))
14075 and then (Expr_Value (L_Low) = Expr_Value (R_Low)
14077 Expr_Value (L_High) = Expr_Value (R_High))
14085 -- If we fall through the loop, all indexes matched
14088 end Matching_Static_Array_Bounds;
14090 -------------------
14091 -- May_Be_Lvalue --
14092 -------------------
14094 function May_Be_Lvalue (N : Node_Id) return Boolean is
14095 P : constant Node_Id := Parent (N);
14100 -- Test left side of assignment
14102 when N_Assignment_Statement =>
14103 return N = Name (P);
14105 -- Test prefix of component or attribute. Note that the prefix of an
14106 -- explicit or implicit dereference cannot be an l-value.
14108 when N_Attribute_Reference =>
14109 return N = Prefix (P)
14110 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
14112 -- For an expanded name, the name is an lvalue if the expanded name
14113 -- is an lvalue, but the prefix is never an lvalue, since it is just
14114 -- the scope where the name is found.
14116 when N_Expanded_Name =>
14117 if N = Prefix (P) then
14118 return May_Be_Lvalue (P);
14123 -- For a selected component A.B, A is certainly an lvalue if A.B is.
14124 -- B is a little interesting, if we have A.B := 3, there is some
14125 -- discussion as to whether B is an lvalue or not, we choose to say
14126 -- it is. Note however that A is not an lvalue if it is of an access
14127 -- type since this is an implicit dereference.
14129 when N_Selected_Component =>
14131 and then Present (Etype (N))
14132 and then Is_Access_Type (Etype (N))
14136 return May_Be_Lvalue (P);
14139 -- For an indexed component or slice, the index or slice bounds is
14140 -- never an lvalue. The prefix is an lvalue if the indexed component
14141 -- or slice is an lvalue, except if it is an access type, where we
14142 -- have an implicit dereference.
14144 when N_Indexed_Component | N_Slice =>
14146 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
14150 return May_Be_Lvalue (P);
14153 -- Prefix of a reference is an lvalue if the reference is an lvalue
14155 when N_Reference =>
14156 return May_Be_Lvalue (P);
14158 -- Prefix of explicit dereference is never an lvalue
14160 when N_Explicit_Dereference =>
14163 -- Positional parameter for subprogram, entry, or accept call.
14164 -- In older versions of Ada function call arguments are never
14165 -- lvalues. In Ada 2012 functions can have in-out parameters.
14167 when N_Subprogram_Call |
14168 N_Entry_Call_Statement |
14171 if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
14175 -- The following mechanism is clumsy and fragile. A single flag
14176 -- set in Resolve_Actuals would be preferable ???
14184 Proc := Get_Subprogram_Entity (P);
14190 -- If we are not a list member, something is strange, so be
14191 -- conservative and return True.
14193 if not Is_List_Member (N) then
14197 -- We are going to find the right formal by stepping forward
14198 -- through the formals, as we step backwards in the actuals.
14200 Form := First_Formal (Proc);
14203 -- If no formal, something is weird, so be conservative and
14211 exit when No (Act);
14212 Next_Formal (Form);
14215 return Ekind (Form) /= E_In_Parameter;
14218 -- Named parameter for procedure or accept call
14220 when N_Parameter_Association =>
14226 Proc := Get_Subprogram_Entity (Parent (P));
14232 -- Loop through formals to find the one that matches
14234 Form := First_Formal (Proc);
14236 -- If no matching formal, that's peculiar, some kind of
14237 -- previous error, so return True to be conservative.
14238 -- Actually happens with legal code for an unresolved call
14239 -- where we may get the wrong homonym???
14245 -- Else test for match
14247 if Chars (Form) = Chars (Selector_Name (P)) then
14248 return Ekind (Form) /= E_In_Parameter;
14251 Next_Formal (Form);
14255 -- Test for appearing in a conversion that itself appears in an
14256 -- lvalue context, since this should be an lvalue.
14258 when N_Type_Conversion =>
14259 return May_Be_Lvalue (P);
14261 -- Test for appearance in object renaming declaration
14263 when N_Object_Renaming_Declaration =>
14266 -- All other references are definitely not lvalues
14274 -----------------------
14275 -- Mark_Coextensions --
14276 -----------------------
14278 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
14279 Is_Dynamic : Boolean;
14280 -- Indicates whether the context causes nested coextensions to be
14281 -- dynamic or static
14283 function Mark_Allocator (N : Node_Id) return Traverse_Result;
14284 -- Recognize an allocator node and label it as a dynamic coextension
14286 --------------------
14287 -- Mark_Allocator --
14288 --------------------
14290 function Mark_Allocator (N : Node_Id) return Traverse_Result is
14292 if Nkind (N) = N_Allocator then
14294 Set_Is_Dynamic_Coextension (N);
14296 -- If the allocator expression is potentially dynamic, it may
14297 -- be expanded out of order and require dynamic allocation
14298 -- anyway, so we treat the coextension itself as dynamic.
14299 -- Potential optimization ???
14301 elsif Nkind (Expression (N)) = N_Qualified_Expression
14302 and then Nkind (Expression (Expression (N))) = N_Op_Concat
14304 Set_Is_Dynamic_Coextension (N);
14306 Set_Is_Static_Coextension (N);
14311 end Mark_Allocator;
14313 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
14315 -- Start of processing for Mark_Coextensions
14318 -- An allocator that appears on the right-hand side of an assignment is
14319 -- treated as a potentially dynamic coextension when the right-hand side
14320 -- is an allocator or a qualified expression.
14322 -- Obj := new ...'(new Coextension ...);
14324 if Nkind (Context_Nod) = N_Assignment_Statement then
14326 Nkind_In (Expression (Context_Nod), N_Allocator,
14327 N_Qualified_Expression);
14329 -- An allocator that appears within the expression of a simple return
14330 -- statement is treated as a potentially dynamic coextension when the
14331 -- expression is either aggregate, allocator, or qualified expression.
14333 -- return (new Coextension ...);
14334 -- return new ...'(new Coextension ...);
14336 elsif Nkind (Context_Nod) = N_Simple_Return_Statement then
14338 Nkind_In (Expression (Context_Nod), N_Aggregate,
14340 N_Qualified_Expression);
14342 -- An alloctor that appears within the initialization expression of an
14343 -- object declaration is considered a potentially dynamic coextension
14344 -- when the initialization expression is an allocator or a qualified
14347 -- Obj : ... := new ...'(new Coextension ...);
14349 -- A similar case arises when the object declaration is part of an
14350 -- extended return statement.
14352 -- return Obj : ... := new ...'(new Coextension ...);
14353 -- return Obj : ... := (new Coextension ...);
14355 elsif Nkind (Context_Nod) = N_Object_Declaration then
14357 Nkind_In (Root_Nod, N_Allocator, N_Qualified_Expression)
14359 Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
14361 -- This routine should not be called with constructs that cannot contain
14365 raise Program_Error;
14368 Mark_Allocators (Root_Nod);
14369 end Mark_Coextensions;
14371 ----------------------
14372 -- Needs_One_Actual --
14373 ----------------------
14375 function Needs_One_Actual (E : Entity_Id) return Boolean is
14376 Formal : Entity_Id;
14379 -- Ada 2005 or later, and formals present
14381 if Ada_Version >= Ada_2005 and then Present (First_Formal (E)) then
14382 Formal := Next_Formal (First_Formal (E));
14383 while Present (Formal) loop
14384 if No (Default_Value (Formal)) then
14388 Next_Formal (Formal);
14393 -- Ada 83/95 or no formals
14398 end Needs_One_Actual;
14400 ------------------------
14401 -- New_Copy_List_Tree --
14402 ------------------------
14404 function New_Copy_List_Tree (List : List_Id) return List_Id is
14409 if List = No_List then
14416 while Present (E) loop
14417 Append (New_Copy_Tree (E), NL);
14423 end New_Copy_List_Tree;
14425 --------------------------------------------------
14426 -- New_Copy_Tree Auxiliary Data and Subprograms --
14427 --------------------------------------------------
14429 use Atree.Unchecked_Access;
14430 use Atree_Private_Part;
14432 -- Our approach here requires a two pass traversal of the tree. The
14433 -- first pass visits all nodes that eventually will be copied looking
14434 -- for defining Itypes. If any defining Itypes are found, then they are
14435 -- copied, and an entry is added to the replacement map. In the second
14436 -- phase, the tree is copied, using the replacement map to replace any
14437 -- Itype references within the copied tree.
14439 -- The following hash tables are used if the Map supplied has more
14440 -- than hash threshold entries to speed up access to the map. If
14441 -- there are fewer entries, then the map is searched sequentially
14442 -- (because setting up a hash table for only a few entries takes
14443 -- more time than it saves.
14445 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
14446 -- Hash function used for hash operations
14448 -------------------
14449 -- New_Copy_Hash --
14450 -------------------
14452 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
14454 return Nat (E) mod (NCT_Header_Num'Last + 1);
14461 -- The hash table NCT_Assoc associates old entities in the table
14462 -- with their corresponding new entities (i.e. the pairs of entries
14463 -- presented in the original Map argument are Key-Element pairs).
14465 package NCT_Assoc is new Simple_HTable (
14466 Header_Num => NCT_Header_Num,
14467 Element => Entity_Id,
14468 No_Element => Empty,
14470 Hash => New_Copy_Hash,
14471 Equal => Types."=");
14473 ---------------------
14474 -- NCT_Itype_Assoc --
14475 ---------------------
14477 -- The hash table NCT_Itype_Assoc contains entries only for those
14478 -- old nodes which have a non-empty Associated_Node_For_Itype set.
14479 -- The key is the associated node, and the element is the new node
14480 -- itself (NOT the associated node for the new node).
14482 package NCT_Itype_Assoc is new Simple_HTable (
14483 Header_Num => NCT_Header_Num,
14484 Element => Entity_Id,
14485 No_Element => Empty,
14487 Hash => New_Copy_Hash,
14488 Equal => Types."=");
14490 -------------------
14491 -- New_Copy_Tree --
14492 -------------------
14494 function New_Copy_Tree
14496 Map : Elist_Id := No_Elist;
14497 New_Sloc : Source_Ptr := No_Location;
14498 New_Scope : Entity_Id := Empty) return Node_Id
14500 Actual_Map : Elist_Id := Map;
14501 -- This is the actual map for the copy. It is initialized with the
14502 -- given elements, and then enlarged as required for Itypes that are
14503 -- copied during the first phase of the copy operation. The visit
14504 -- procedures add elements to this map as Itypes are encountered.
14505 -- The reason we cannot use Map directly, is that it may well be
14506 -- (and normally is) initialized to No_Elist, and if we have mapped
14507 -- entities, we have to reset it to point to a real Elist.
14509 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
14510 -- Called during second phase to map entities into their corresponding
14511 -- copies using Actual_Map. If the argument is not an entity, or is not
14512 -- in Actual_Map, then it is returned unchanged.
14514 procedure Build_NCT_Hash_Tables;
14515 -- Builds hash tables (number of elements >= threshold value)
14517 function Copy_Elist_With_Replacement
14518 (Old_Elist : Elist_Id) return Elist_Id;
14519 -- Called during second phase to copy element list doing replacements
14521 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
14522 -- Called during the second phase to process a copied Itype. The actual
14523 -- copy happened during the first phase (so that we could make the entry
14524 -- in the mapping), but we still have to deal with the descendents of
14525 -- the copied Itype and copy them where necessary.
14527 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
14528 -- Called during second phase to copy list doing replacements
14530 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
14531 -- Called during second phase to copy node doing replacements
14533 procedure Visit_Elist (E : Elist_Id);
14534 -- Called during first phase to visit all elements of an Elist
14536 procedure Visit_Field (F : Union_Id; N : Node_Id);
14537 -- Visit a single field, recursing to call Visit_Node or Visit_List
14538 -- if the field is a syntactic descendent of the current node (i.e.
14539 -- its parent is Node N).
14541 procedure Visit_Itype (Old_Itype : Entity_Id);
14542 -- Called during first phase to visit subsidiary fields of a defining
14543 -- Itype, and also create a copy and make an entry in the replacement
14544 -- map for the new copy.
14546 procedure Visit_List (L : List_Id);
14547 -- Called during first phase to visit all elements of a List
14549 procedure Visit_Node (N : Node_Or_Entity_Id);
14550 -- Called during first phase to visit a node and all its subtrees
14556 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
14561 if not Has_Extension (N) or else No (Actual_Map) then
14564 elsif NCT_Hash_Tables_Used then
14565 Ent := NCT_Assoc.Get (Entity_Id (N));
14567 if Present (Ent) then
14573 -- No hash table used, do serial search
14576 E := First_Elmt (Actual_Map);
14577 while Present (E) loop
14578 if Node (E) = N then
14579 return Node (Next_Elmt (E));
14581 E := Next_Elmt (Next_Elmt (E));
14589 ---------------------------
14590 -- Build_NCT_Hash_Tables --
14591 ---------------------------
14593 procedure Build_NCT_Hash_Tables is
14597 if NCT_Hash_Table_Setup then
14599 NCT_Itype_Assoc.Reset;
14602 Elmt := First_Elmt (Actual_Map);
14603 while Present (Elmt) loop
14604 Ent := Node (Elmt);
14606 -- Get new entity, and associate old and new
14609 NCT_Assoc.Set (Ent, Node (Elmt));
14611 if Is_Type (Ent) then
14613 Anode : constant Entity_Id :=
14614 Associated_Node_For_Itype (Ent);
14617 if Present (Anode) then
14619 -- Enter a link between the associated node of the
14620 -- old Itype and the new Itype, for updating later
14621 -- when node is copied.
14623 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
14631 NCT_Hash_Tables_Used := True;
14632 NCT_Hash_Table_Setup := True;
14633 end Build_NCT_Hash_Tables;
14635 ---------------------------------
14636 -- Copy_Elist_With_Replacement --
14637 ---------------------------------
14639 function Copy_Elist_With_Replacement
14640 (Old_Elist : Elist_Id) return Elist_Id
14643 New_Elist : Elist_Id;
14646 if No (Old_Elist) then
14650 New_Elist := New_Elmt_List;
14652 M := First_Elmt (Old_Elist);
14653 while Present (M) loop
14654 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
14660 end Copy_Elist_With_Replacement;
14662 ---------------------------------
14663 -- Copy_Itype_With_Replacement --
14664 ---------------------------------
14666 -- This routine exactly parallels its phase one analog Visit_Itype,
14668 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
14670 -- Translate Next_Entity, Scope and Etype fields, in case they
14671 -- reference entities that have been mapped into copies.
14673 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
14674 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
14676 if Present (New_Scope) then
14677 Set_Scope (New_Itype, New_Scope);
14679 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
14682 -- Copy referenced fields
14684 if Is_Discrete_Type (New_Itype) then
14685 Set_Scalar_Range (New_Itype,
14686 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
14688 elsif Has_Discriminants (Base_Type (New_Itype)) then
14689 Set_Discriminant_Constraint (New_Itype,
14690 Copy_Elist_With_Replacement
14691 (Discriminant_Constraint (New_Itype)));
14693 elsif Is_Array_Type (New_Itype) then
14694 if Present (First_Index (New_Itype)) then
14695 Set_First_Index (New_Itype,
14696 First (Copy_List_With_Replacement
14697 (List_Containing (First_Index (New_Itype)))));
14700 if Is_Packed (New_Itype) then
14701 Set_Packed_Array_Impl_Type (New_Itype,
14702 Copy_Node_With_Replacement
14703 (Packed_Array_Impl_Type (New_Itype)));
14706 end Copy_Itype_With_Replacement;
14708 --------------------------------
14709 -- Copy_List_With_Replacement --
14710 --------------------------------
14712 function Copy_List_With_Replacement
14713 (Old_List : List_Id) return List_Id
14715 New_List : List_Id;
14719 if Old_List = No_List then
14723 New_List := Empty_List;
14725 E := First (Old_List);
14726 while Present (E) loop
14727 Append (Copy_Node_With_Replacement (E), New_List);
14733 end Copy_List_With_Replacement;
14735 --------------------------------
14736 -- Copy_Node_With_Replacement --
14737 --------------------------------
14739 function Copy_Node_With_Replacement
14740 (Old_Node : Node_Id) return Node_Id
14742 New_Node : Node_Id;
14744 procedure Adjust_Named_Associations
14745 (Old_Node : Node_Id;
14746 New_Node : Node_Id);
14747 -- If a call node has named associations, these are chained through
14748 -- the First_Named_Actual, Next_Named_Actual links. These must be
14749 -- propagated separately to the new parameter list, because these
14750 -- are not syntactic fields.
14752 function Copy_Field_With_Replacement
14753 (Field : Union_Id) return Union_Id;
14754 -- Given Field, which is a field of Old_Node, return a copy of it
14755 -- if it is a syntactic field (i.e. its parent is Node), setting
14756 -- the parent of the copy to poit to New_Node. Otherwise returns
14757 -- the field (possibly mapped if it is an entity).
14759 -------------------------------
14760 -- Adjust_Named_Associations --
14761 -------------------------------
14763 procedure Adjust_Named_Associations
14764 (Old_Node : Node_Id;
14765 New_Node : Node_Id)
14770 Old_Next : Node_Id;
14771 New_Next : Node_Id;
14774 Old_E := First (Parameter_Associations (Old_Node));
14775 New_E := First (Parameter_Associations (New_Node));
14776 while Present (Old_E) loop
14777 if Nkind (Old_E) = N_Parameter_Association
14778 and then Present (Next_Named_Actual (Old_E))
14780 if First_Named_Actual (Old_Node)
14781 = Explicit_Actual_Parameter (Old_E)
14783 Set_First_Named_Actual
14784 (New_Node, Explicit_Actual_Parameter (New_E));
14787 -- Now scan parameter list from the beginning,to locate
14788 -- next named actual, which can be out of order.
14790 Old_Next := First (Parameter_Associations (Old_Node));
14791 New_Next := First (Parameter_Associations (New_Node));
14793 while Nkind (Old_Next) /= N_Parameter_Association
14794 or else Explicit_Actual_Parameter (Old_Next) /=
14795 Next_Named_Actual (Old_E)
14801 Set_Next_Named_Actual
14802 (New_E, Explicit_Actual_Parameter (New_Next));
14808 end Adjust_Named_Associations;
14810 ---------------------------------
14811 -- Copy_Field_With_Replacement --
14812 ---------------------------------
14814 function Copy_Field_With_Replacement
14815 (Field : Union_Id) return Union_Id
14818 if Field = Union_Id (Empty) then
14821 elsif Field in Node_Range then
14823 Old_N : constant Node_Id := Node_Id (Field);
14827 -- If syntactic field, as indicated by the parent pointer
14828 -- being set, then copy the referenced node recursively.
14830 if Parent (Old_N) = Old_Node then
14831 New_N := Copy_Node_With_Replacement (Old_N);
14833 if New_N /= Old_N then
14834 Set_Parent (New_N, New_Node);
14837 -- For semantic fields, update possible entity reference
14838 -- from the replacement map.
14841 New_N := Assoc (Old_N);
14844 return Union_Id (New_N);
14847 elsif Field in List_Range then
14849 Old_L : constant List_Id := List_Id (Field);
14853 -- If syntactic field, as indicated by the parent pointer,
14854 -- then recursively copy the entire referenced list.
14856 if Parent (Old_L) = Old_Node then
14857 New_L := Copy_List_With_Replacement (Old_L);
14858 Set_Parent (New_L, New_Node);
14860 -- For semantic list, just returned unchanged
14866 return Union_Id (New_L);
14869 -- Anything other than a list or a node is returned unchanged
14874 end Copy_Field_With_Replacement;
14876 -- Start of processing for Copy_Node_With_Replacement
14879 if Old_Node <= Empty_Or_Error then
14882 elsif Has_Extension (Old_Node) then
14883 return Assoc (Old_Node);
14886 New_Node := New_Copy (Old_Node);
14888 -- If the node we are copying is the associated node of a
14889 -- previously copied Itype, then adjust the associated node
14890 -- of the copy of that Itype accordingly.
14892 if Present (Actual_Map) then
14898 -- Case of hash table used
14900 if NCT_Hash_Tables_Used then
14901 Ent := NCT_Itype_Assoc.Get (Old_Node);
14903 if Present (Ent) then
14904 Set_Associated_Node_For_Itype (Ent, New_Node);
14907 -- Case of no hash table used
14910 E := First_Elmt (Actual_Map);
14911 while Present (E) loop
14912 if Is_Itype (Node (E))
14914 Old_Node = Associated_Node_For_Itype (Node (E))
14916 Set_Associated_Node_For_Itype
14917 (Node (Next_Elmt (E)), New_Node);
14920 E := Next_Elmt (Next_Elmt (E));
14926 -- Recursively copy descendents
14929 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
14931 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
14933 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
14935 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
14937 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
14939 -- Adjust Sloc of new node if necessary
14941 if New_Sloc /= No_Location then
14942 Set_Sloc (New_Node, New_Sloc);
14944 -- If we adjust the Sloc, then we are essentially making
14945 -- a completely new node, so the Comes_From_Source flag
14946 -- should be reset to the proper default value.
14948 Nodes.Table (New_Node).Comes_From_Source :=
14949 Default_Node.Comes_From_Source;
14952 -- If the node is call and has named associations,
14953 -- set the corresponding links in the copy.
14955 if (Nkind (Old_Node) = N_Function_Call
14956 or else Nkind (Old_Node) = N_Entry_Call_Statement
14958 Nkind (Old_Node) = N_Procedure_Call_Statement)
14959 and then Present (First_Named_Actual (Old_Node))
14961 Adjust_Named_Associations (Old_Node, New_Node);
14964 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
14965 -- The replacement mechanism applies to entities, and is not used
14966 -- here. Eventually we may need a more general graph-copying
14967 -- routine. For now, do a sequential search to find desired node.
14969 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
14970 and then Present (First_Real_Statement (Old_Node))
14973 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
14977 N1 := First (Statements (Old_Node));
14978 N2 := First (Statements (New_Node));
14980 while N1 /= Old_F loop
14985 Set_First_Real_Statement (New_Node, N2);
14990 -- All done, return copied node
14993 end Copy_Node_With_Replacement;
14999 procedure Visit_Elist (E : Elist_Id) is
15002 if Present (E) then
15003 Elmt := First_Elmt (E);
15005 while Elmt /= No_Elmt loop
15006 Visit_Node (Node (Elmt));
15016 procedure Visit_Field (F : Union_Id; N : Node_Id) is
15018 if F = Union_Id (Empty) then
15021 elsif F in Node_Range then
15023 -- Copy node if it is syntactic, i.e. its parent pointer is
15024 -- set to point to the field that referenced it (certain
15025 -- Itypes will also meet this criterion, which is fine, since
15026 -- these are clearly Itypes that do need to be copied, since
15027 -- we are copying their parent.)
15029 if Parent (Node_Id (F)) = N then
15030 Visit_Node (Node_Id (F));
15033 -- Another case, if we are pointing to an Itype, then we want
15034 -- to copy it if its associated node is somewhere in the tree
15037 -- Note: the exclusion of self-referential copies is just an
15038 -- optimization, since the search of the already copied list
15039 -- would catch it, but it is a common case (Etype pointing
15040 -- to itself for an Itype that is a base type).
15042 elsif Has_Extension (Node_Id (F))
15043 and then Is_Itype (Entity_Id (F))
15044 and then Node_Id (F) /= N
15050 P := Associated_Node_For_Itype (Node_Id (F));
15051 while Present (P) loop
15053 Visit_Node (Node_Id (F));
15060 -- An Itype whose parent is not being copied definitely
15061 -- should NOT be copied, since it does not belong in any
15062 -- sense to the copied subtree.
15068 elsif F in List_Range and then Parent (List_Id (F)) = N then
15069 Visit_List (List_Id (F));
15078 procedure Visit_Itype (Old_Itype : Entity_Id) is
15079 New_Itype : Entity_Id;
15084 -- Itypes that describe the designated type of access to subprograms
15085 -- have the structure of subprogram declarations, with signatures,
15086 -- etc. Either we duplicate the signatures completely, or choose to
15087 -- share such itypes, which is fine because their elaboration will
15088 -- have no side effects.
15090 if Ekind (Old_Itype) = E_Subprogram_Type then
15094 New_Itype := New_Copy (Old_Itype);
15096 -- The new Itype has all the attributes of the old one, and
15097 -- we just copy the contents of the entity. However, the back-end
15098 -- needs different names for debugging purposes, so we create a
15099 -- new internal name for it in all cases.
15101 Set_Chars (New_Itype, New_Internal_Name ('T'));
15103 -- If our associated node is an entity that has already been copied,
15104 -- then set the associated node of the copy to point to the right
15105 -- copy. If we have copied an Itype that is itself the associated
15106 -- node of some previously copied Itype, then we set the right
15107 -- pointer in the other direction.
15109 if Present (Actual_Map) then
15111 -- Case of hash tables used
15113 if NCT_Hash_Tables_Used then
15115 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
15117 if Present (Ent) then
15118 Set_Associated_Node_For_Itype (New_Itype, Ent);
15121 Ent := NCT_Itype_Assoc.Get (Old_Itype);
15122 if Present (Ent) then
15123 Set_Associated_Node_For_Itype (Ent, New_Itype);
15125 -- If the hash table has no association for this Itype and
15126 -- its associated node, enter one now.
15129 NCT_Itype_Assoc.Set
15130 (Associated_Node_For_Itype (Old_Itype), New_Itype);
15133 -- Case of hash tables not used
15136 E := First_Elmt (Actual_Map);
15137 while Present (E) loop
15138 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
15139 Set_Associated_Node_For_Itype
15140 (New_Itype, Node (Next_Elmt (E)));
15143 if Is_Type (Node (E))
15144 and then Old_Itype = Associated_Node_For_Itype (Node (E))
15146 Set_Associated_Node_For_Itype
15147 (Node (Next_Elmt (E)), New_Itype);
15150 E := Next_Elmt (Next_Elmt (E));
15155 if Present (Freeze_Node (New_Itype)) then
15156 Set_Is_Frozen (New_Itype, False);
15157 Set_Freeze_Node (New_Itype, Empty);
15160 -- Add new association to map
15162 if No (Actual_Map) then
15163 Actual_Map := New_Elmt_List;
15166 Append_Elmt (Old_Itype, Actual_Map);
15167 Append_Elmt (New_Itype, Actual_Map);
15169 if NCT_Hash_Tables_Used then
15170 NCT_Assoc.Set (Old_Itype, New_Itype);
15173 NCT_Table_Entries := NCT_Table_Entries + 1;
15175 if NCT_Table_Entries > NCT_Hash_Threshold then
15176 Build_NCT_Hash_Tables;
15180 -- If a record subtype is simply copied, the entity list will be
15181 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
15183 if Ekind_In (Old_Itype, E_Record_Subtype, E_Class_Wide_Subtype) then
15184 Set_Cloned_Subtype (New_Itype, Old_Itype);
15187 -- Visit descendents that eventually get copied
15189 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
15191 if Is_Discrete_Type (Old_Itype) then
15192 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
15194 elsif Has_Discriminants (Base_Type (Old_Itype)) then
15195 -- ??? This should involve call to Visit_Field
15196 Visit_Elist (Discriminant_Constraint (Old_Itype));
15198 elsif Is_Array_Type (Old_Itype) then
15199 if Present (First_Index (Old_Itype)) then
15200 Visit_Field (Union_Id (List_Containing
15201 (First_Index (Old_Itype))),
15205 if Is_Packed (Old_Itype) then
15206 Visit_Field (Union_Id (Packed_Array_Impl_Type (Old_Itype)),
15216 procedure Visit_List (L : List_Id) is
15219 if L /= No_List then
15222 while Present (N) loop
15233 procedure Visit_Node (N : Node_Or_Entity_Id) is
15235 -- Start of processing for Visit_Node
15238 -- Handle case of an Itype, which must be copied
15240 if Has_Extension (N) and then Is_Itype (N) then
15242 -- Nothing to do if already in the list. This can happen with an
15243 -- Itype entity that appears more than once in the tree.
15244 -- Note that we do not want to visit descendents in this case.
15246 -- Test for already in list when hash table is used
15248 if NCT_Hash_Tables_Used then
15249 if Present (NCT_Assoc.Get (Entity_Id (N))) then
15253 -- Test for already in list when hash table not used
15259 if Present (Actual_Map) then
15260 E := First_Elmt (Actual_Map);
15261 while Present (E) loop
15262 if Node (E) = N then
15265 E := Next_Elmt (Next_Elmt (E));
15275 -- Visit descendents
15277 Visit_Field (Field1 (N), N);
15278 Visit_Field (Field2 (N), N);
15279 Visit_Field (Field3 (N), N);
15280 Visit_Field (Field4 (N), N);
15281 Visit_Field (Field5 (N), N);
15284 -- Start of processing for New_Copy_Tree
15289 -- See if we should use hash table
15291 if No (Actual_Map) then
15292 NCT_Hash_Tables_Used := False;
15299 NCT_Table_Entries := 0;
15301 Elmt := First_Elmt (Actual_Map);
15302 while Present (Elmt) loop
15303 NCT_Table_Entries := NCT_Table_Entries + 1;
15308 if NCT_Table_Entries > NCT_Hash_Threshold then
15309 Build_NCT_Hash_Tables;
15311 NCT_Hash_Tables_Used := False;
15316 -- Hash table set up if required, now start phase one by visiting
15317 -- top node (we will recursively visit the descendents).
15319 Visit_Node (Source);
15321 -- Now the second phase of the copy can start. First we process
15322 -- all the mapped entities, copying their descendents.
15324 if Present (Actual_Map) then
15327 New_Itype : Entity_Id;
15329 Elmt := First_Elmt (Actual_Map);
15330 while Present (Elmt) loop
15332 New_Itype := Node (Elmt);
15333 Copy_Itype_With_Replacement (New_Itype);
15339 -- Now we can copy the actual tree
15341 return Copy_Node_With_Replacement (Source);
15344 -------------------------
15345 -- New_External_Entity --
15346 -------------------------
15348 function New_External_Entity
15349 (Kind : Entity_Kind;
15350 Scope_Id : Entity_Id;
15351 Sloc_Value : Source_Ptr;
15352 Related_Id : Entity_Id;
15353 Suffix : Character;
15354 Suffix_Index : Nat := 0;
15355 Prefix : Character := ' ') return Entity_Id
15357 N : constant Entity_Id :=
15358 Make_Defining_Identifier (Sloc_Value,
15360 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
15363 Set_Ekind (N, Kind);
15364 Set_Is_Internal (N, True);
15365 Append_Entity (N, Scope_Id);
15366 Set_Public_Status (N);
15368 if Kind in Type_Kind then
15369 Init_Size_Align (N);
15373 end New_External_Entity;
15375 -------------------------
15376 -- New_Internal_Entity --
15377 -------------------------
15379 function New_Internal_Entity
15380 (Kind : Entity_Kind;
15381 Scope_Id : Entity_Id;
15382 Sloc_Value : Source_Ptr;
15383 Id_Char : Character) return Entity_Id
15385 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
15388 Set_Ekind (N, Kind);
15389 Set_Is_Internal (N, True);
15390 Append_Entity (N, Scope_Id);
15392 if Kind in Type_Kind then
15393 Init_Size_Align (N);
15397 end New_Internal_Entity;
15403 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
15407 -- If we are pointing at a positional parameter, it is a member of a
15408 -- node list (the list of parameters), and the next parameter is the
15409 -- next node on the list, unless we hit a parameter association, then
15410 -- we shift to using the chain whose head is the First_Named_Actual in
15411 -- the parent, and then is threaded using the Next_Named_Actual of the
15412 -- Parameter_Association. All this fiddling is because the original node
15413 -- list is in the textual call order, and what we need is the
15414 -- declaration order.
15416 if Is_List_Member (Actual_Id) then
15417 N := Next (Actual_Id);
15419 if Nkind (N) = N_Parameter_Association then
15420 return First_Named_Actual (Parent (Actual_Id));
15426 return Next_Named_Actual (Parent (Actual_Id));
15430 procedure Next_Actual (Actual_Id : in out Node_Id) is
15432 Actual_Id := Next_Actual (Actual_Id);
15435 -----------------------
15436 -- Normalize_Actuals --
15437 -----------------------
15439 -- Chain actuals according to formals of subprogram. If there are no named
15440 -- associations, the chain is simply the list of Parameter Associations,
15441 -- since the order is the same as the declaration order. If there are named
15442 -- associations, then the First_Named_Actual field in the N_Function_Call
15443 -- or N_Procedure_Call_Statement node points to the Parameter_Association
15444 -- node for the parameter that comes first in declaration order. The
15445 -- remaining named parameters are then chained in declaration order using
15446 -- Next_Named_Actual.
15448 -- This routine also verifies that the number of actuals is compatible with
15449 -- the number and default values of formals, but performs no type checking
15450 -- (type checking is done by the caller).
15452 -- If the matching succeeds, Success is set to True and the caller proceeds
15453 -- with type-checking. If the match is unsuccessful, then Success is set to
15454 -- False, and the caller attempts a different interpretation, if there is
15457 -- If the flag Report is on, the call is not overloaded, and a failure to
15458 -- match can be reported here, rather than in the caller.
15460 procedure Normalize_Actuals
15464 Success : out Boolean)
15466 Actuals : constant List_Id := Parameter_Associations (N);
15467 Actual : Node_Id := Empty;
15468 Formal : Entity_Id;
15469 Last : Node_Id := Empty;
15470 First_Named : Node_Id := Empty;
15473 Formals_To_Match : Integer := 0;
15474 Actuals_To_Match : Integer := 0;
15476 procedure Chain (A : Node_Id);
15477 -- Add named actual at the proper place in the list, using the
15478 -- Next_Named_Actual link.
15480 function Reporting return Boolean;
15481 -- Determines if an error is to be reported. To report an error, we
15482 -- need Report to be True, and also we do not report errors caused
15483 -- by calls to init procs that occur within other init procs. Such
15484 -- errors must always be cascaded errors, since if all the types are
15485 -- declared correctly, the compiler will certainly build decent calls.
15491 procedure Chain (A : Node_Id) is
15495 -- Call node points to first actual in list
15497 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
15500 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
15504 Set_Next_Named_Actual (Last, Empty);
15511 function Reporting return Boolean is
15516 elsif not Within_Init_Proc then
15519 elsif Is_Init_Proc (Entity (Name (N))) then
15527 -- Start of processing for Normalize_Actuals
15530 if Is_Access_Type (S) then
15532 -- The name in the call is a function call that returns an access
15533 -- to subprogram. The designated type has the list of formals.
15535 Formal := First_Formal (Designated_Type (S));
15537 Formal := First_Formal (S);
15540 while Present (Formal) loop
15541 Formals_To_Match := Formals_To_Match + 1;
15542 Next_Formal (Formal);
15545 -- Find if there is a named association, and verify that no positional
15546 -- associations appear after named ones.
15548 if Present (Actuals) then
15549 Actual := First (Actuals);
15552 while Present (Actual)
15553 and then Nkind (Actual) /= N_Parameter_Association
15555 Actuals_To_Match := Actuals_To_Match + 1;
15559 if No (Actual) and Actuals_To_Match = Formals_To_Match then
15561 -- Most common case: positional notation, no defaults
15566 elsif Actuals_To_Match > Formals_To_Match then
15568 -- Too many actuals: will not work
15571 if Is_Entity_Name (Name (N)) then
15572 Error_Msg_N ("too many arguments in call to&", Name (N));
15574 Error_Msg_N ("too many arguments in call", N);
15582 First_Named := Actual;
15584 while Present (Actual) loop
15585 if Nkind (Actual) /= N_Parameter_Association then
15587 ("positional parameters not allowed after named ones", Actual);
15592 Actuals_To_Match := Actuals_To_Match + 1;
15598 if Present (Actuals) then
15599 Actual := First (Actuals);
15602 Formal := First_Formal (S);
15603 while Present (Formal) loop
15605 -- Match the formals in order. If the corresponding actual is
15606 -- positional, nothing to do. Else scan the list of named actuals
15607 -- to find the one with the right name.
15609 if Present (Actual)
15610 and then Nkind (Actual) /= N_Parameter_Association
15613 Actuals_To_Match := Actuals_To_Match - 1;
15614 Formals_To_Match := Formals_To_Match - 1;
15617 -- For named parameters, search the list of actuals to find
15618 -- one that matches the next formal name.
15620 Actual := First_Named;
15622 while Present (Actual) loop
15623 if Chars (Selector_Name (Actual)) = Chars (Formal) then
15626 Actuals_To_Match := Actuals_To_Match - 1;
15627 Formals_To_Match := Formals_To_Match - 1;
15635 if Ekind (Formal) /= E_In_Parameter
15636 or else No (Default_Value (Formal))
15639 if (Comes_From_Source (S)
15640 or else Sloc (S) = Standard_Location)
15641 and then Is_Overloadable (S)
15645 Nkind_In (Parent (N), N_Procedure_Call_Statement,
15647 N_Parameter_Association)
15648 and then Ekind (S) /= E_Function
15650 Set_Etype (N, Etype (S));
15653 Error_Msg_Name_1 := Chars (S);
15654 Error_Msg_Sloc := Sloc (S);
15656 ("missing argument for parameter & "
15657 & "in call to % declared #", N, Formal);
15660 elsif Is_Overloadable (S) then
15661 Error_Msg_Name_1 := Chars (S);
15663 -- Point to type derivation that generated the
15666 Error_Msg_Sloc := Sloc (Parent (S));
15669 ("missing argument for parameter & "
15670 & "in call to % (inherited) #", N, Formal);
15674 ("missing argument for parameter &", N, Formal);
15682 Formals_To_Match := Formals_To_Match - 1;
15687 Next_Formal (Formal);
15690 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
15697 -- Find some superfluous named actual that did not get
15698 -- attached to the list of associations.
15700 Actual := First (Actuals);
15701 while Present (Actual) loop
15702 if Nkind (Actual) = N_Parameter_Association
15703 and then Actual /= Last
15704 and then No (Next_Named_Actual (Actual))
15706 Error_Msg_N ("unmatched actual & in call",
15707 Selector_Name (Actual));
15718 end Normalize_Actuals;
15720 --------------------------------
15721 -- Note_Possible_Modification --
15722 --------------------------------
15724 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
15725 Modification_Comes_From_Source : constant Boolean :=
15726 Comes_From_Source (Parent (N));
15732 -- Loop to find referenced entity, if there is one
15738 if Is_Entity_Name (Exp) then
15739 Ent := Entity (Exp);
15741 -- If the entity is missing, it is an undeclared identifier,
15742 -- and there is nothing to annotate.
15748 elsif Nkind (Exp) = N_Explicit_Dereference then
15750 P : constant Node_Id := Prefix (Exp);
15753 -- In formal verification mode, keep track of all reads and
15754 -- writes through explicit dereferences.
15756 if GNATprove_Mode then
15757 SPARK_Specific.Generate_Dereference (N, 'm');
15760 if Nkind (P) = N_Selected_Component
15761 and then Present (Entry_Formal (Entity (Selector_Name (P))))
15763 -- Case of a reference to an entry formal
15765 Ent := Entry_Formal (Entity (Selector_Name (P)));
15767 elsif Nkind (P) = N_Identifier
15768 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
15769 and then Present (Expression (Parent (Entity (P))))
15770 and then Nkind (Expression (Parent (Entity (P)))) =
15773 -- Case of a reference to a value on which side effects have
15776 Exp := Prefix (Expression (Parent (Entity (P))));
15784 elsif Nkind_In (Exp, N_Type_Conversion,
15785 N_Unchecked_Type_Conversion)
15787 Exp := Expression (Exp);
15790 elsif Nkind_In (Exp, N_Slice,
15791 N_Indexed_Component,
15792 N_Selected_Component)
15794 -- Special check, if the prefix is an access type, then return
15795 -- since we are modifying the thing pointed to, not the prefix.
15796 -- When we are expanding, most usually the prefix is replaced
15797 -- by an explicit dereference, and this test is not needed, but
15798 -- in some cases (notably -gnatc mode and generics) when we do
15799 -- not do full expansion, we need this special test.
15801 if Is_Access_Type (Etype (Prefix (Exp))) then
15804 -- Otherwise go to prefix and keep going
15807 Exp := Prefix (Exp);
15811 -- All other cases, not a modification
15817 -- Now look for entity being referenced
15819 if Present (Ent) then
15820 if Is_Object (Ent) then
15821 if Comes_From_Source (Exp)
15822 or else Modification_Comes_From_Source
15824 -- Give warning if pragma unmodified given and we are
15825 -- sure this is a modification.
15827 if Has_Pragma_Unmodified (Ent) and then Sure then
15828 Error_Msg_NE ("??pragma Unmodified given for &!", N, Ent);
15831 Set_Never_Set_In_Source (Ent, False);
15834 Set_Is_True_Constant (Ent, False);
15835 Set_Current_Value (Ent, Empty);
15836 Set_Is_Known_Null (Ent, False);
15838 if not Can_Never_Be_Null (Ent) then
15839 Set_Is_Known_Non_Null (Ent, False);
15842 -- Follow renaming chain
15844 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
15845 and then Present (Renamed_Object (Ent))
15847 Exp := Renamed_Object (Ent);
15849 -- If the entity is the loop variable in an iteration over
15850 -- a container, retrieve container expression to indicate
15851 -- possible modification.
15853 if Present (Related_Expression (Ent))
15854 and then Nkind (Parent (Related_Expression (Ent))) =
15855 N_Iterator_Specification
15857 Exp := Original_Node (Related_Expression (Ent));
15862 -- The expression may be the renaming of a subcomponent of an
15863 -- array or container. The assignment to the subcomponent is
15864 -- a modification of the container.
15866 elsif Comes_From_Source (Original_Node (Exp))
15867 and then Nkind_In (Original_Node (Exp), N_Selected_Component,
15868 N_Indexed_Component)
15870 Exp := Prefix (Original_Node (Exp));
15874 -- Generate a reference only if the assignment comes from
15875 -- source. This excludes, for example, calls to a dispatching
15876 -- assignment operation when the left-hand side is tagged. In
15877 -- GNATprove mode, we need those references also on generated
15878 -- code, as these are used to compute the local effects of
15881 if Modification_Comes_From_Source or GNATprove_Mode then
15882 Generate_Reference (Ent, Exp, 'm');
15884 -- If the target of the assignment is the bound variable
15885 -- in an iterator, indicate that the corresponding array
15886 -- or container is also modified.
15888 if Ada_Version >= Ada_2012
15889 and then Nkind (Parent (Ent)) = N_Iterator_Specification
15892 Domain : constant Node_Id := Name (Parent (Ent));
15895 -- TBD : in the full version of the construct, the
15896 -- domain of iteration can be given by an expression.
15898 if Is_Entity_Name (Domain) then
15899 Generate_Reference (Entity (Domain), Exp, 'm');
15900 Set_Is_True_Constant (Entity (Domain), False);
15901 Set_Never_Set_In_Source (Entity (Domain), False);
15910 -- If we are sure this is a modification from source, and we know
15911 -- this modifies a constant, then give an appropriate warning.
15913 if Overlays_Constant (Ent)
15914 and then (Modification_Comes_From_Source and Sure)
15917 A : constant Node_Id := Address_Clause (Ent);
15919 if Present (A) then
15921 Exp : constant Node_Id := Expression (A);
15923 if Nkind (Exp) = N_Attribute_Reference
15924 and then Attribute_Name (Exp) = Name_Address
15925 and then Is_Entity_Name (Prefix (Exp))
15927 Error_Msg_Sloc := Sloc (A);
15929 ("constant& may be modified via address "
15930 & "clause#??", N, Entity (Prefix (Exp)));
15943 end Note_Possible_Modification;
15945 -------------------------
15946 -- Object_Access_Level --
15947 -------------------------
15949 -- Returns the static accessibility level of the view denoted by Obj. Note
15950 -- that the value returned is the result of a call to Scope_Depth. Only
15951 -- scope depths associated with dynamic scopes can actually be returned.
15952 -- Since only relative levels matter for accessibility checking, the fact
15953 -- that the distance between successive levels of accessibility is not
15954 -- always one is immaterial (invariant: if level(E2) is deeper than
15955 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
15957 function Object_Access_Level (Obj : Node_Id) return Uint is
15958 function Is_Interface_Conversion (N : Node_Id) return Boolean;
15959 -- Determine whether N is a construct of the form
15960 -- Some_Type (Operand._tag'Address)
15961 -- This construct appears in the context of dispatching calls.
15963 function Reference_To (Obj : Node_Id) return Node_Id;
15964 -- An explicit dereference is created when removing side-effects from
15965 -- expressions for constraint checking purposes. In this case a local
15966 -- access type is created for it. The correct access level is that of
15967 -- the original source node. We detect this case by noting that the
15968 -- prefix of the dereference is created by an object declaration whose
15969 -- initial expression is a reference.
15971 -----------------------------
15972 -- Is_Interface_Conversion --
15973 -----------------------------
15975 function Is_Interface_Conversion (N : Node_Id) return Boolean is
15977 return Nkind (N) = N_Unchecked_Type_Conversion
15978 and then Nkind (Expression (N)) = N_Attribute_Reference
15979 and then Attribute_Name (Expression (N)) = Name_Address;
15980 end Is_Interface_Conversion;
15986 function Reference_To (Obj : Node_Id) return Node_Id is
15987 Pref : constant Node_Id := Prefix (Obj);
15989 if Is_Entity_Name (Pref)
15990 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
15991 and then Present (Expression (Parent (Entity (Pref))))
15992 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
15994 return (Prefix (Expression (Parent (Entity (Pref)))));
16004 -- Start of processing for Object_Access_Level
16007 if Nkind (Obj) = N_Defining_Identifier
16008 or else Is_Entity_Name (Obj)
16010 if Nkind (Obj) = N_Defining_Identifier then
16016 if Is_Prival (E) then
16017 E := Prival_Link (E);
16020 -- If E is a type then it denotes a current instance. For this case
16021 -- we add one to the normal accessibility level of the type to ensure
16022 -- that current instances are treated as always being deeper than
16023 -- than the level of any visible named access type (see 3.10.2(21)).
16025 if Is_Type (E) then
16026 return Type_Access_Level (E) + 1;
16028 elsif Present (Renamed_Object (E)) then
16029 return Object_Access_Level (Renamed_Object (E));
16031 -- Similarly, if E is a component of the current instance of a
16032 -- protected type, any instance of it is assumed to be at a deeper
16033 -- level than the type. For a protected object (whose type is an
16034 -- anonymous protected type) its components are at the same level
16035 -- as the type itself.
16037 elsif not Is_Overloadable (E)
16038 and then Ekind (Scope (E)) = E_Protected_Type
16039 and then Comes_From_Source (Scope (E))
16041 return Type_Access_Level (Scope (E)) + 1;
16044 -- Aliased formals take their access level from the point of call.
16045 -- This is smaller than the level of the subprogram itself.
16047 if Is_Formal (E) and then Is_Aliased (E) then
16048 return Type_Access_Level (Etype (E));
16051 return Scope_Depth (Enclosing_Dynamic_Scope (E));
16055 elsif Nkind (Obj) = N_Selected_Component then
16056 if Is_Access_Type (Etype (Prefix (Obj))) then
16057 return Type_Access_Level (Etype (Prefix (Obj)));
16059 return Object_Access_Level (Prefix (Obj));
16062 elsif Nkind (Obj) = N_Indexed_Component then
16063 if Is_Access_Type (Etype (Prefix (Obj))) then
16064 return Type_Access_Level (Etype (Prefix (Obj)));
16066 return Object_Access_Level (Prefix (Obj));
16069 elsif Nkind (Obj) = N_Explicit_Dereference then
16071 -- If the prefix is a selected access discriminant then we make a
16072 -- recursive call on the prefix, which will in turn check the level
16073 -- of the prefix object of the selected discriminant.
16075 -- In Ada 2012, if the discriminant has implicit dereference and
16076 -- the context is a selected component, treat this as an object of
16077 -- unknown scope (see below). This is necessary in compile-only mode;
16078 -- otherwise expansion will already have transformed the prefix into
16081 if Nkind (Prefix (Obj)) = N_Selected_Component
16082 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
16084 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
16086 (not Has_Implicit_Dereference
16087 (Entity (Selector_Name (Prefix (Obj))))
16088 or else Nkind (Parent (Obj)) /= N_Selected_Component)
16090 return Object_Access_Level (Prefix (Obj));
16092 -- Detect an interface conversion in the context of a dispatching
16093 -- call. Use the original form of the conversion to find the access
16094 -- level of the operand.
16096 elsif Is_Interface (Etype (Obj))
16097 and then Is_Interface_Conversion (Prefix (Obj))
16098 and then Nkind (Original_Node (Obj)) = N_Type_Conversion
16100 return Object_Access_Level (Original_Node (Obj));
16102 elsif not Comes_From_Source (Obj) then
16104 Ref : constant Node_Id := Reference_To (Obj);
16106 if Present (Ref) then
16107 return Object_Access_Level (Ref);
16109 return Type_Access_Level (Etype (Prefix (Obj)));
16114 return Type_Access_Level (Etype (Prefix (Obj)));
16117 elsif Nkind_In (Obj, N_Type_Conversion, N_Unchecked_Type_Conversion) then
16118 return Object_Access_Level (Expression (Obj));
16120 elsif Nkind (Obj) = N_Function_Call then
16122 -- Function results are objects, so we get either the access level of
16123 -- the function or, in the case of an indirect call, the level of the
16124 -- access-to-subprogram type. (This code is used for Ada 95, but it
16125 -- looks wrong, because it seems that we should be checking the level
16126 -- of the call itself, even for Ada 95. However, using the Ada 2005
16127 -- version of the code causes regressions in several tests that are
16128 -- compiled with -gnat95. ???)
16130 if Ada_Version < Ada_2005 then
16131 if Is_Entity_Name (Name (Obj)) then
16132 return Subprogram_Access_Level (Entity (Name (Obj)));
16134 return Type_Access_Level (Etype (Prefix (Name (Obj))));
16137 -- For Ada 2005, the level of the result object of a function call is
16138 -- defined to be the level of the call's innermost enclosing master.
16139 -- We determine that by querying the depth of the innermost enclosing
16143 Return_Master_Scope_Depth_Of_Call : declare
16145 function Innermost_Master_Scope_Depth
16146 (N : Node_Id) return Uint;
16147 -- Returns the scope depth of the given node's innermost
16148 -- enclosing dynamic scope (effectively the accessibility
16149 -- level of the innermost enclosing master).
16151 ----------------------------------
16152 -- Innermost_Master_Scope_Depth --
16153 ----------------------------------
16155 function Innermost_Master_Scope_Depth
16156 (N : Node_Id) return Uint
16158 Node_Par : Node_Id := Parent (N);
16161 -- Locate the nearest enclosing node (by traversing Parents)
16162 -- that Defining_Entity can be applied to, and return the
16163 -- depth of that entity's nearest enclosing dynamic scope.
16165 while Present (Node_Par) loop
16166 case Nkind (Node_Par) is
16167 when N_Component_Declaration |
16168 N_Entry_Declaration |
16169 N_Formal_Object_Declaration |
16170 N_Formal_Type_Declaration |
16171 N_Full_Type_Declaration |
16172 N_Incomplete_Type_Declaration |
16173 N_Loop_Parameter_Specification |
16174 N_Object_Declaration |
16175 N_Protected_Type_Declaration |
16176 N_Private_Extension_Declaration |
16177 N_Private_Type_Declaration |
16178 N_Subtype_Declaration |
16179 N_Function_Specification |
16180 N_Procedure_Specification |
16181 N_Task_Type_Declaration |
16183 N_Generic_Instantiation |
16185 N_Implicit_Label_Declaration |
16186 N_Package_Declaration |
16187 N_Single_Task_Declaration |
16188 N_Subprogram_Declaration |
16189 N_Generic_Declaration |
16190 N_Renaming_Declaration |
16191 N_Block_Statement |
16192 N_Formal_Subprogram_Declaration |
16193 N_Abstract_Subprogram_Declaration |
16195 N_Exception_Declaration |
16196 N_Formal_Package_Declaration |
16197 N_Number_Declaration |
16198 N_Package_Specification |
16199 N_Parameter_Specification |
16200 N_Single_Protected_Declaration |
16204 (Nearest_Dynamic_Scope
16205 (Defining_Entity (Node_Par)));
16211 Node_Par := Parent (Node_Par);
16214 pragma Assert (False);
16216 -- Should never reach the following return
16218 return Scope_Depth (Current_Scope) + 1;
16219 end Innermost_Master_Scope_Depth;
16221 -- Start of processing for Return_Master_Scope_Depth_Of_Call
16224 return Innermost_Master_Scope_Depth (Obj);
16225 end Return_Master_Scope_Depth_Of_Call;
16228 -- For convenience we handle qualified expressions, even though they
16229 -- aren't technically object names.
16231 elsif Nkind (Obj) = N_Qualified_Expression then
16232 return Object_Access_Level (Expression (Obj));
16234 -- Ditto for aggregates. They have the level of the temporary that
16235 -- will hold their value.
16237 elsif Nkind (Obj) = N_Aggregate then
16238 return Object_Access_Level (Current_Scope);
16240 -- Otherwise return the scope level of Standard. (If there are cases
16241 -- that fall through to this point they will be treated as having
16242 -- global accessibility for now. ???)
16245 return Scope_Depth (Standard_Standard);
16247 end Object_Access_Level;
16249 ---------------------------------
16250 -- Original_Aspect_Pragma_Name --
16251 ---------------------------------
16253 function Original_Aspect_Pragma_Name (N : Node_Id) return Name_Id is
16255 Item_Nam : Name_Id;
16258 pragma Assert (Nkind_In (N, N_Aspect_Specification, N_Pragma));
16262 -- The pragma was generated to emulate an aspect, use the original
16263 -- aspect specification.
16265 if Nkind (Item) = N_Pragma and then From_Aspect_Specification (Item) then
16266 Item := Corresponding_Aspect (Item);
16269 -- Retrieve the name of the aspect/pragma. Note that Pre, Pre_Class,
16270 -- Post and Post_Class rewrite their pragma identifier to preserve the
16272 -- ??? this is kludgey
16274 if Nkind (Item) = N_Pragma then
16275 Item_Nam := Chars (Original_Node (Pragma_Identifier (Item)));
16278 pragma Assert (Nkind (Item) = N_Aspect_Specification);
16279 Item_Nam := Chars (Identifier (Item));
16282 -- Deal with 'Class by converting the name to its _XXX form
16284 if Class_Present (Item) then
16285 if Item_Nam = Name_Invariant then
16286 Item_Nam := Name_uInvariant;
16288 elsif Item_Nam = Name_Post then
16289 Item_Nam := Name_uPost;
16291 elsif Item_Nam = Name_Pre then
16292 Item_Nam := Name_uPre;
16294 elsif Nam_In (Item_Nam, Name_Type_Invariant,
16295 Name_Type_Invariant_Class)
16297 Item_Nam := Name_uType_Invariant;
16299 -- Nothing to do for other cases (e.g. a Check that derived from
16300 -- Pre_Class and has the flag set). Also we do nothing if the name
16301 -- is already in special _xxx form.
16307 end Original_Aspect_Pragma_Name;
16309 --------------------------------------
16310 -- Original_Corresponding_Operation --
16311 --------------------------------------
16313 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
16315 Typ : constant Entity_Id := Find_Dispatching_Type (S);
16318 -- If S is an inherited primitive S2 the original corresponding
16319 -- operation of S is the original corresponding operation of S2
16321 if Present (Alias (S))
16322 and then Find_Dispatching_Type (Alias (S)) /= Typ
16324 return Original_Corresponding_Operation (Alias (S));
16326 -- If S overrides an inherited subprogram S2 the original corresponding
16327 -- operation of S is the original corresponding operation of S2
16329 elsif Present (Overridden_Operation (S)) then
16330 return Original_Corresponding_Operation (Overridden_Operation (S));
16332 -- otherwise it is S itself
16337 end Original_Corresponding_Operation;
16339 ----------------------
16340 -- Policy_In_Effect --
16341 ----------------------
16343 function Policy_In_Effect (Policy : Name_Id) return Name_Id is
16344 function Policy_In_List (List : Node_Id) return Name_Id;
16345 -- Determine the mode of a policy in a N_Pragma list
16347 --------------------
16348 -- Policy_In_List --
16349 --------------------
16351 function Policy_In_List (List : Node_Id) return Name_Id is
16358 while Present (Prag) loop
16359 Arg1 := First (Pragma_Argument_Associations (Prag));
16360 Arg2 := Next (Arg1);
16362 Arg1 := Get_Pragma_Arg (Arg1);
16363 Arg2 := Get_Pragma_Arg (Arg2);
16365 -- The current Check_Policy pragma matches the requested policy or
16366 -- appears in the single argument form (Assertion, policy_id).
16368 if Nam_In (Chars (Arg1), Name_Assertion, Policy) then
16369 return Chars (Arg2);
16372 Prag := Next_Pragma (Prag);
16376 end Policy_In_List;
16382 -- Start of processing for Policy_In_Effect
16385 if not Is_Valid_Assertion_Kind (Policy) then
16386 raise Program_Error;
16389 -- Inspect all policy pragmas that appear within scopes (if any)
16391 Kind := Policy_In_List (Check_Policy_List);
16393 -- Inspect all configuration policy pragmas (if any)
16395 if Kind = No_Name then
16396 Kind := Policy_In_List (Check_Policy_List_Config);
16399 -- The context lacks policy pragmas, determine the mode based on whether
16400 -- assertions are enabled at the configuration level. This ensures that
16401 -- the policy is preserved when analyzing generics.
16403 if Kind = No_Name then
16404 if Assertions_Enabled_Config then
16405 Kind := Name_Check;
16407 Kind := Name_Ignore;
16412 end Policy_In_Effect;
16414 ----------------------------------
16415 -- Predicate_Tests_On_Arguments --
16416 ----------------------------------
16418 function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean is
16420 -- Always test predicates on indirect call
16422 if Ekind (Subp) = E_Subprogram_Type then
16425 -- Do not test predicates on call to generated default Finalize, since
16426 -- we are not interested in whether something we are finalizing (and
16427 -- typically destroying) satisfies its predicates.
16429 elsif Chars (Subp) = Name_Finalize
16430 and then not Comes_From_Source (Subp)
16434 -- Do not test predicates on any internally generated routines
16436 elsif Is_Internal_Name (Chars (Subp)) then
16439 -- Do not test predicates on call to Init_Proc, since if needed the
16440 -- predicate test will occur at some other point.
16442 elsif Is_Init_Proc (Subp) then
16445 -- Do not test predicates on call to predicate function, since this
16446 -- would cause infinite recursion.
16448 elsif Ekind (Subp) = E_Function
16449 and then (Is_Predicate_Function (Subp)
16451 Is_Predicate_Function_M (Subp))
16455 -- For now, no other exceptions
16460 end Predicate_Tests_On_Arguments;
16462 -----------------------
16463 -- Private_Component --
16464 -----------------------
16466 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
16467 Ancestor : constant Entity_Id := Base_Type (Type_Id);
16469 function Trace_Components
16471 Check : Boolean) return Entity_Id;
16472 -- Recursive function that does the work, and checks against circular
16473 -- definition for each subcomponent type.
16475 ----------------------
16476 -- Trace_Components --
16477 ----------------------
16479 function Trace_Components
16481 Check : Boolean) return Entity_Id
16483 Btype : constant Entity_Id := Base_Type (T);
16484 Component : Entity_Id;
16486 Candidate : Entity_Id := Empty;
16489 if Check and then Btype = Ancestor then
16490 Error_Msg_N ("circular type definition", Type_Id);
16494 if Is_Private_Type (Btype) and then not Is_Generic_Type (Btype) then
16495 if Present (Full_View (Btype))
16496 and then Is_Record_Type (Full_View (Btype))
16497 and then not Is_Frozen (Btype)
16499 -- To indicate that the ancestor depends on a private type, the
16500 -- current Btype is sufficient. However, to check for circular
16501 -- definition we must recurse on the full view.
16503 Candidate := Trace_Components (Full_View (Btype), True);
16505 if Candidate = Any_Type then
16515 elsif Is_Array_Type (Btype) then
16516 return Trace_Components (Component_Type (Btype), True);
16518 elsif Is_Record_Type (Btype) then
16519 Component := First_Entity (Btype);
16520 while Present (Component)
16521 and then Comes_From_Source (Component)
16523 -- Skip anonymous types generated by constrained components
16525 if not Is_Type (Component) then
16526 P := Trace_Components (Etype (Component), True);
16528 if Present (P) then
16529 if P = Any_Type then
16537 Next_Entity (Component);
16545 end Trace_Components;
16547 -- Start of processing for Private_Component
16550 return Trace_Components (Type_Id, False);
16551 end Private_Component;
16553 ---------------------------
16554 -- Primitive_Names_Match --
16555 ---------------------------
16557 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
16559 function Non_Internal_Name (E : Entity_Id) return Name_Id;
16560 -- Given an internal name, returns the corresponding non-internal name
16562 ------------------------
16563 -- Non_Internal_Name --
16564 ------------------------
16566 function Non_Internal_Name (E : Entity_Id) return Name_Id is
16568 Get_Name_String (Chars (E));
16569 Name_Len := Name_Len - 1;
16571 end Non_Internal_Name;
16573 -- Start of processing for Primitive_Names_Match
16576 pragma Assert (Present (E1) and then Present (E2));
16578 return Chars (E1) = Chars (E2)
16580 (not Is_Internal_Name (Chars (E1))
16581 and then Is_Internal_Name (Chars (E2))
16582 and then Non_Internal_Name (E2) = Chars (E1))
16584 (not Is_Internal_Name (Chars (E2))
16585 and then Is_Internal_Name (Chars (E1))
16586 and then Non_Internal_Name (E1) = Chars (E2))
16588 (Is_Predefined_Dispatching_Operation (E1)
16589 and then Is_Predefined_Dispatching_Operation (E2)
16590 and then Same_TSS (E1, E2))
16592 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
16593 end Primitive_Names_Match;
16595 -----------------------
16596 -- Process_End_Label --
16597 -----------------------
16599 procedure Process_End_Label
16608 Label_Ref : Boolean;
16609 -- Set True if reference to end label itself is required
16612 -- Gets set to the operator symbol or identifier that references the
16613 -- entity Ent. For the child unit case, this is the identifier from the
16614 -- designator. For other cases, this is simply Endl.
16616 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
16617 -- N is an identifier node that appears as a parent unit reference in
16618 -- the case where Ent is a child unit. This procedure generates an
16619 -- appropriate cross-reference entry. E is the corresponding entity.
16621 -------------------------
16622 -- Generate_Parent_Ref --
16623 -------------------------
16625 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
16627 -- If names do not match, something weird, skip reference
16629 if Chars (E) = Chars (N) then
16631 -- Generate the reference. We do NOT consider this as a reference
16632 -- for unreferenced symbol purposes.
16634 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
16636 if Style_Check then
16637 Style.Check_Identifier (N, E);
16640 end Generate_Parent_Ref;
16642 -- Start of processing for Process_End_Label
16645 -- If no node, ignore. This happens in some error situations, and
16646 -- also for some internally generated structures where no end label
16647 -- references are required in any case.
16653 -- Nothing to do if no End_Label, happens for internally generated
16654 -- constructs where we don't want an end label reference anyway. Also
16655 -- nothing to do if Endl is a string literal, which means there was
16656 -- some prior error (bad operator symbol)
16658 Endl := End_Label (N);
16660 if No (Endl) or else Nkind (Endl) = N_String_Literal then
16664 -- Reference node is not in extended main source unit
16666 if not In_Extended_Main_Source_Unit (N) then
16668 -- Generally we do not collect references except for the extended
16669 -- main source unit. The one exception is the 'e' entry for a
16670 -- package spec, where it is useful for a client to have the
16671 -- ending information to define scopes.
16677 Label_Ref := False;
16679 -- For this case, we can ignore any parent references, but we
16680 -- need the package name itself for the 'e' entry.
16682 if Nkind (Endl) = N_Designator then
16683 Endl := Identifier (Endl);
16687 -- Reference is in extended main source unit
16692 -- For designator, generate references for the parent entries
16694 if Nkind (Endl) = N_Designator then
16696 -- Generate references for the prefix if the END line comes from
16697 -- source (otherwise we do not need these references) We climb the
16698 -- scope stack to find the expected entities.
16700 if Comes_From_Source (Endl) then
16701 Nam := Name (Endl);
16702 Scop := Current_Scope;
16703 while Nkind (Nam) = N_Selected_Component loop
16704 Scop := Scope (Scop);
16705 exit when No (Scop);
16706 Generate_Parent_Ref (Selector_Name (Nam), Scop);
16707 Nam := Prefix (Nam);
16710 if Present (Scop) then
16711 Generate_Parent_Ref (Nam, Scope (Scop));
16715 Endl := Identifier (Endl);
16719 -- If the end label is not for the given entity, then either we have
16720 -- some previous error, or this is a generic instantiation for which
16721 -- we do not need to make a cross-reference in this case anyway. In
16722 -- either case we simply ignore the call.
16724 if Chars (Ent) /= Chars (Endl) then
16728 -- If label was really there, then generate a normal reference and then
16729 -- adjust the location in the end label to point past the name (which
16730 -- should almost always be the semicolon).
16732 Loc := Sloc (Endl);
16734 if Comes_From_Source (Endl) then
16736 -- If a label reference is required, then do the style check and
16737 -- generate an l-type cross-reference entry for the label
16740 if Style_Check then
16741 Style.Check_Identifier (Endl, Ent);
16744 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
16747 -- Set the location to point past the label (normally this will
16748 -- mean the semicolon immediately following the label). This is
16749 -- done for the sake of the 'e' or 't' entry generated below.
16751 Get_Decoded_Name_String (Chars (Endl));
16752 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
16755 -- In SPARK mode, no missing label is allowed for packages and
16756 -- subprogram bodies. Detect those cases by testing whether
16757 -- Process_End_Label was called for a body (Typ = 't') or a package.
16759 if Restriction_Check_Required (SPARK_05)
16760 and then (Typ = 't' or else Ekind (Ent) = E_Package)
16762 Error_Msg_Node_1 := Endl;
16763 Check_SPARK_05_Restriction
16764 ("`END &` required", Endl, Force => True);
16768 -- Now generate the e/t reference
16770 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
16772 -- Restore Sloc, in case modified above, since we have an identifier
16773 -- and the normal Sloc should be left set in the tree.
16775 Set_Sloc (Endl, Loc);
16776 end Process_End_Label;
16782 function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
16783 Seen : Boolean := False;
16785 function Is_Reference (N : Node_Id) return Traverse_Result;
16786 -- Determine whether node N denotes a reference to Id. If this is the
16787 -- case, set global flag Seen to True and stop the traversal.
16793 function Is_Reference (N : Node_Id) return Traverse_Result is
16795 if Is_Entity_Name (N)
16796 and then Present (Entity (N))
16797 and then Entity (N) = Id
16806 procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
16808 -- Start of processing for Referenced
16811 Inspect_Expression (Expr);
16815 ------------------------------------
16816 -- References_Generic_Formal_Type --
16817 ------------------------------------
16819 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
16821 function Process (N : Node_Id) return Traverse_Result;
16822 -- Process one node in search for generic formal type
16828 function Process (N : Node_Id) return Traverse_Result is
16830 if Nkind (N) in N_Has_Entity then
16832 E : constant Entity_Id := Entity (N);
16834 if Present (E) then
16835 if Is_Generic_Type (E) then
16837 elsif Present (Etype (E))
16838 and then Is_Generic_Type (Etype (E))
16849 function Traverse is new Traverse_Func (Process);
16850 -- Traverse tree to look for generic type
16853 if Inside_A_Generic then
16854 return Traverse (N) = Abandon;
16858 end References_Generic_Formal_Type;
16860 --------------------
16861 -- Remove_Homonym --
16862 --------------------
16864 procedure Remove_Homonym (E : Entity_Id) is
16865 Prev : Entity_Id := Empty;
16869 if E = Current_Entity (E) then
16870 if Present (Homonym (E)) then
16871 Set_Current_Entity (Homonym (E));
16873 Set_Name_Entity_Id (Chars (E), Empty);
16877 H := Current_Entity (E);
16878 while Present (H) and then H /= E loop
16883 -- If E is not on the homonym chain, nothing to do
16885 if Present (H) then
16886 Set_Homonym (Prev, Homonym (E));
16889 end Remove_Homonym;
16891 ------------------------------
16892 -- Remove_Overloaded_Entity --
16893 ------------------------------
16895 procedure Remove_Overloaded_Entity (Id : Entity_Id) is
16896 procedure Remove_Primitive_Of (Typ : Entity_Id);
16897 -- Remove primitive subprogram Id from the list of primitives that
16898 -- belong to type Typ.
16900 -------------------------
16901 -- Remove_Primitive_Of --
16902 -------------------------
16904 procedure Remove_Primitive_Of (Typ : Entity_Id) is
16908 if Is_Tagged_Type (Typ) then
16909 Prims := Direct_Primitive_Operations (Typ);
16911 if Present (Prims) then
16912 Remove (Prims, Id);
16915 end Remove_Primitive_Of;
16919 Scop : constant Entity_Id := Scope (Id);
16920 Formal : Entity_Id;
16921 Prev_Id : Entity_Id;
16923 -- Start of processing for Remove_Overloaded_Entity
16926 -- Remove the entity from the homonym chain. When the entity is the
16927 -- head of the chain, associate the entry in the name table with its
16928 -- homonym effectively making it the new head of the chain.
16930 if Current_Entity (Id) = Id then
16931 Set_Name_Entity_Id (Chars (Id), Homonym (Id));
16933 -- Otherwise link the previous and next homonyms
16936 Prev_Id := Current_Entity (Id);
16937 while Present (Prev_Id) and then Homonym (Prev_Id) /= Id loop
16938 Prev_Id := Homonym (Prev_Id);
16941 Set_Homonym (Prev_Id, Homonym (Id));
16944 -- Remove the entity from the scope entity chain. When the entity is
16945 -- the head of the chain, set the next entity as the new head of the
16948 if First_Entity (Scop) = Id then
16950 Set_First_Entity (Scop, Next_Entity (Id));
16952 -- Otherwise the entity is either in the middle of the chain or it acts
16953 -- as its tail. Traverse and link the previous and next entities.
16956 Prev_Id := First_Entity (Scop);
16957 while Present (Prev_Id) and then Next_Entity (Prev_Id) /= Id loop
16958 Next_Entity (Prev_Id);
16961 Set_Next_Entity (Prev_Id, Next_Entity (Id));
16964 -- Handle the case where the entity acts as the tail of the scope entity
16967 if Last_Entity (Scop) = Id then
16968 Set_Last_Entity (Scop, Prev_Id);
16971 -- The entity denotes a primitive subprogram. Remove it from the list of
16972 -- primitives of the associated controlling type.
16974 if Ekind_In (Id, E_Function, E_Procedure) and then Is_Primitive (Id) then
16975 Formal := First_Formal (Id);
16976 while Present (Formal) loop
16977 if Is_Controlling_Formal (Formal) then
16978 Remove_Primitive_Of (Etype (Formal));
16982 Next_Formal (Formal);
16985 if Ekind (Id) = E_Function and then Has_Controlling_Result (Id) then
16986 Remove_Primitive_Of (Etype (Id));
16989 end Remove_Overloaded_Entity;
16991 ---------------------
16992 -- Rep_To_Pos_Flag --
16993 ---------------------
16995 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
16997 return New_Occurrence_Of
16998 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
16999 end Rep_To_Pos_Flag;
17001 -------------------------------
17002 -- Report_Unused_Body_States --
17003 -------------------------------
17005 procedure Report_Unused_Body_States
17006 (Body_Id : Entity_Id;
17009 Posted : Boolean := False;
17010 State_Elmt : Elmt_Id;
17011 State_Id : Entity_Id;
17014 if Present (States) then
17015 State_Elmt := First_Elmt (States);
17016 while Present (State_Elmt) loop
17017 State_Id := Node (State_Elmt);
17019 -- Constants are part of the hidden state of a package, but the
17020 -- compiler cannot determine whether they have variable input
17021 -- (SPARK RM 7.1.1(2)) and cannot classify them properly as a
17022 -- hidden state. Do not emit an error when a constant does not
17023 -- participate in a state refinement, even though it acts as a
17026 if Ekind (State_Id) = E_Constant then
17029 -- Generate an error message of the form:
17031 -- body of package ... has unused hidden states
17032 -- abstract state ... defined at ...
17033 -- variable ... defined at ...
17039 ("body of package & has unused hidden states", Body_Id);
17042 Error_Msg_Sloc := Sloc (State_Id);
17044 if Ekind (State_Id) = E_Abstract_State then
17046 ("\abstract state & defined #", Body_Id, State_Id);
17049 SPARK_Msg_NE ("\variable & defined #", Body_Id, State_Id);
17053 Next_Elmt (State_Elmt);
17056 end Report_Unused_Body_States;
17058 --------------------
17059 -- Require_Entity --
17060 --------------------
17062 procedure Require_Entity (N : Node_Id) is
17064 if Is_Entity_Name (N) and then No (Entity (N)) then
17065 if Total_Errors_Detected /= 0 then
17066 Set_Entity (N, Any_Id);
17068 raise Program_Error;
17071 end Require_Entity;
17073 -------------------------------
17074 -- Requires_State_Refinement --
17075 -------------------------------
17077 function Requires_State_Refinement
17078 (Spec_Id : Entity_Id;
17079 Body_Id : Entity_Id) return Boolean
17081 function Mode_Is_Off (Prag : Node_Id) return Boolean;
17082 -- Given pragma SPARK_Mode, determine whether the mode is Off
17088 function Mode_Is_Off (Prag : Node_Id) return Boolean is
17092 -- The default SPARK mode is On
17098 Mode := Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
17100 -- Then the pragma lacks an argument, the default mode is On
17105 return Chars (Mode) = Name_Off;
17109 -- Start of processing for Requires_State_Refinement
17112 -- A package that does not define at least one abstract state cannot
17113 -- possibly require refinement.
17115 if No (Abstract_States (Spec_Id)) then
17118 -- The package instroduces a single null state which does not merit
17121 elsif Has_Null_Abstract_State (Spec_Id) then
17124 -- Check whether the package body is subject to pragma SPARK_Mode. If
17125 -- it is and the mode is Off, the package body is considered to be in
17126 -- regular Ada and does not require refinement.
17128 elsif Mode_Is_Off (SPARK_Pragma (Body_Id)) then
17131 -- The body's SPARK_Mode may be inherited from a similar pragma that
17132 -- appears in the private declarations of the spec. The pragma we are
17133 -- interested appears as the second entry in SPARK_Pragma.
17135 elsif Present (SPARK_Pragma (Spec_Id))
17136 and then Mode_Is_Off (Next_Pragma (SPARK_Pragma (Spec_Id)))
17140 -- The spec defines at least one abstract state and the body has no way
17141 -- of circumventing the refinement.
17146 end Requires_State_Refinement;
17148 ------------------------------
17149 -- Requires_Transient_Scope --
17150 ------------------------------
17152 -- A transient scope is required when variable-sized temporaries are
17153 -- allocated on the secondary stack, or when finalization actions must be
17154 -- generated before the next instruction.
17156 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
17157 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
17158 -- ???We retain the old and new algorithms for Requires_Transient_Scope for
17159 -- the time being. New_Requires_Transient_Scope is used by default; the
17160 -- debug switch -gnatdQ can be used to do Old_Requires_Transient_Scope
17161 -- instead. The intent is to use this temporarily to measure before/after
17162 -- efficiency. Note: when this temporary code is removed, the documentation
17163 -- of dQ in debug.adb should be removed.
17165 procedure Results_Differ (Id : Entity_Id);
17166 -- ???Debugging code. Called when the Old_ and New_ results differ. Will be
17167 -- removed when New_Requires_Transient_Scope becomes
17168 -- Requires_Transient_Scope and Old_Requires_Transient_Scope is eliminated.
17170 procedure Results_Differ (Id : Entity_Id) is
17172 if False then -- False to disable; True for debugging
17173 Treepr.Print_Tree_Node (Id);
17175 if Old_Requires_Transient_Scope (Id) =
17176 New_Requires_Transient_Scope (Id)
17178 raise Program_Error;
17181 end Results_Differ;
17183 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
17184 Old_Result : constant Boolean := Old_Requires_Transient_Scope (Id);
17187 if Debug_Flag_QQ then
17192 New_Result : constant Boolean := New_Requires_Transient_Scope (Id);
17195 -- Assert that we're not putting things on the secondary stack if we
17196 -- didn't before; we are trying to AVOID secondary stack when
17199 if not Old_Result then
17200 pragma Assert (not New_Result);
17204 if New_Result /= Old_Result then
17205 Results_Differ (Id);
17210 end Requires_Transient_Scope;
17212 ----------------------------------
17213 -- Old_Requires_Transient_Scope --
17214 ----------------------------------
17216 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
17217 Typ : constant Entity_Id := Underlying_Type (Id);
17220 -- This is a private type which is not completed yet. This can only
17221 -- happen in a default expression (of a formal parameter or of a
17222 -- record component). Do not expand transient scope in this case.
17227 -- Do not expand transient scope for non-existent procedure return
17229 elsif Typ = Standard_Void_Type then
17232 -- Elementary types do not require a transient scope
17234 elsif Is_Elementary_Type (Typ) then
17237 -- Generally, indefinite subtypes require a transient scope, since the
17238 -- back end cannot generate temporaries, since this is not a valid type
17239 -- for declaring an object. It might be possible to relax this in the
17240 -- future, e.g. by declaring the maximum possible space for the type.
17242 elsif not Is_Definite_Subtype (Typ) then
17245 -- Functions returning tagged types may dispatch on result so their
17246 -- returned value is allocated on the secondary stack. Controlled
17247 -- type temporaries need finalization.
17249 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
17254 elsif Is_Record_Type (Typ) then
17259 Comp := First_Entity (Typ);
17260 while Present (Comp) loop
17261 if Ekind (Comp) = E_Component then
17263 -- ???It's not clear we need a full recursive call to
17264 -- Old_Requires_Transient_Scope here. Note that the
17265 -- following can't happen.
17267 pragma Assert (Is_Definite_Subtype (Etype (Comp)));
17268 pragma Assert (not Has_Controlled_Component (Etype (Comp)));
17270 if Old_Requires_Transient_Scope (Etype (Comp)) then
17275 Next_Entity (Comp);
17281 -- String literal types never require transient scope
17283 elsif Ekind (Typ) = E_String_Literal_Subtype then
17286 -- Array type. Note that we already know that this is a constrained
17287 -- array, since unconstrained arrays will fail the indefinite test.
17289 elsif Is_Array_Type (Typ) then
17291 -- If component type requires a transient scope, the array does too
17293 if Old_Requires_Transient_Scope (Component_Type (Typ)) then
17296 -- Otherwise, we only need a transient scope if the size depends on
17297 -- the value of one or more discriminants.
17300 return Size_Depends_On_Discriminant (Typ);
17303 -- All other cases do not require a transient scope
17306 pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
17309 end Old_Requires_Transient_Scope;
17311 ----------------------------------
17312 -- New_Requires_Transient_Scope --
17313 ----------------------------------
17315 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
17317 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean;
17318 -- This is called for untagged records and protected types, with
17319 -- nondefaulted discriminants. Returns True if the size of function
17320 -- results is known at the call site, False otherwise. Returns False
17321 -- if there is a variant part that depends on the discriminants of
17322 -- this type, or if there is an array constrained by the discriminants
17323 -- of this type. ???Currently, this is overly conservative (the array
17324 -- could be nested inside some other record that is constrained by
17325 -- nondiscriminants). That is, the recursive calls are too conservative.
17327 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean;
17328 -- Returns True if Typ is a nonlimited record with defaulted
17329 -- discriminants whose max size makes it unsuitable for allocating on
17330 -- the primary stack.
17332 ------------------------------
17333 -- Caller_Known_Size_Record --
17334 ------------------------------
17336 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean is
17337 pragma Assert (Typ = Underlying_Type (Typ));
17340 if Has_Variant_Part (Typ) and then not Is_Definite_Subtype (Typ) then
17348 Comp := First_Entity (Typ);
17349 while Present (Comp) loop
17351 -- Only look at E_Component entities. No need to look at
17352 -- E_Discriminant entities, and we must ignore internal
17353 -- subtypes generated for constrained components.
17355 if Ekind (Comp) = E_Component then
17357 Comp_Type : constant Entity_Id :=
17358 Underlying_Type (Etype (Comp));
17361 if Is_Record_Type (Comp_Type)
17363 Is_Protected_Type (Comp_Type)
17365 if not Caller_Known_Size_Record (Comp_Type) then
17369 elsif Is_Array_Type (Comp_Type) then
17370 if Size_Depends_On_Discriminant (Comp_Type) then
17377 Next_Entity (Comp);
17382 end Caller_Known_Size_Record;
17384 ------------------------------
17385 -- Large_Max_Size_Mutable --
17386 ------------------------------
17388 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean is
17389 pragma Assert (Typ = Underlying_Type (Typ));
17391 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean;
17392 -- Returns true if the discrete type T has a large range
17394 ----------------------------
17395 -- Is_Large_Discrete_Type --
17396 ----------------------------
17398 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean is
17399 Threshold : constant Int := 16;
17400 -- Arbitrary threshold above which we consider it "large". We want
17401 -- a fairly large threshold, because these large types really
17402 -- shouldn't have default discriminants in the first place, in
17406 return UI_To_Int (RM_Size (T)) > Threshold;
17407 end Is_Large_Discrete_Type;
17410 if Is_Record_Type (Typ)
17411 and then not Is_Limited_View (Typ)
17412 and then Has_Defaulted_Discriminants (Typ)
17414 -- Loop through the components, looking for an array whose upper
17415 -- bound(s) depends on discriminants, where both the subtype of
17416 -- the discriminant and the index subtype are too large.
17422 Comp := First_Entity (Typ);
17423 while Present (Comp) loop
17424 if Ekind (Comp) = E_Component then
17426 Comp_Type : constant Entity_Id :=
17427 Underlying_Type (Etype (Comp));
17433 if Is_Array_Type (Comp_Type) then
17434 Indx := First_Index (Comp_Type);
17436 while Present (Indx) loop
17437 Ityp := Etype (Indx);
17438 Hi := Type_High_Bound (Ityp);
17440 if Nkind (Hi) = N_Identifier
17441 and then Ekind (Entity (Hi)) = E_Discriminant
17442 and then Is_Large_Discrete_Type (Ityp)
17443 and then Is_Large_Discrete_Type
17444 (Etype (Entity (Hi)))
17455 Next_Entity (Comp);
17461 end Large_Max_Size_Mutable;
17463 -- Local declarations
17465 Typ : constant Entity_Id := Underlying_Type (Id);
17467 -- Start of processing for New_Requires_Transient_Scope
17470 -- This is a private type which is not completed yet. This can only
17471 -- happen in a default expression (of a formal parameter or of a
17472 -- record component). Do not expand transient scope in this case.
17477 -- Do not expand transient scope for non-existent procedure return or
17478 -- string literal types.
17480 elsif Typ = Standard_Void_Type
17481 or else Ekind (Typ) = E_String_Literal_Subtype
17485 -- If Typ is a generic formal incomplete type, then we want to look at
17486 -- the actual type.
17488 elsif Ekind (Typ) = E_Record_Subtype
17489 and then Present (Cloned_Subtype (Typ))
17491 return New_Requires_Transient_Scope (Cloned_Subtype (Typ));
17493 -- Functions returning specific tagged types may dispatch on result, so
17494 -- their returned value is allocated on the secondary stack, even in the
17495 -- definite case. We must treat nondispatching functions the same way,
17496 -- because access-to-function types can point at both, so the calling
17497 -- conventions must be compatible. Is_Tagged_Type includes controlled
17498 -- types and class-wide types. Controlled type temporaries need
17501 -- ???It's not clear why we need to return noncontrolled types with
17502 -- controlled components on the secondary stack.
17504 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
17507 -- Untagged definite subtypes are known size. This includes all
17508 -- elementary [sub]types. Tasks are known size even if they have
17509 -- discriminants. So we return False here, with one exception:
17510 -- For a type like:
17511 -- type T (Last : Natural := 0) is
17512 -- X : String (1 .. Last);
17514 -- we return True. That's because for "P(F(...));", where F returns T,
17515 -- we don't know the size of the result at the call site, so if we
17516 -- allocated it on the primary stack, we would have to allocate the
17517 -- maximum size, which is way too big.
17519 elsif Is_Definite_Subtype (Typ) or else Is_Task_Type (Typ) then
17520 return Large_Max_Size_Mutable (Typ);
17522 -- Indefinite (discriminated) untagged record or protected type
17524 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
17525 return not Caller_Known_Size_Record (Typ);
17527 -- Unconstrained array
17530 pragma Assert (Is_Array_Type (Typ) and not Is_Definite_Subtype (Typ));
17533 end New_Requires_Transient_Scope;
17535 --------------------------
17536 -- Reset_Analyzed_Flags --
17537 --------------------------
17539 procedure Reset_Analyzed_Flags (N : Node_Id) is
17541 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
17542 -- Function used to reset Analyzed flags in tree. Note that we do
17543 -- not reset Analyzed flags in entities, since there is no need to
17544 -- reanalyze entities, and indeed, it is wrong to do so, since it
17545 -- can result in generating auxiliary stuff more than once.
17547 --------------------
17548 -- Clear_Analyzed --
17549 --------------------
17551 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
17553 if not Has_Extension (N) then
17554 Set_Analyzed (N, False);
17558 end Clear_Analyzed;
17560 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
17562 -- Start of processing for Reset_Analyzed_Flags
17565 Reset_Analyzed (N);
17566 end Reset_Analyzed_Flags;
17568 ------------------------
17569 -- Restore_SPARK_Mode --
17570 ------------------------
17572 procedure Restore_SPARK_Mode (Mode : SPARK_Mode_Type) is
17574 SPARK_Mode := Mode;
17575 end Restore_SPARK_Mode;
17577 --------------------------------
17578 -- Returns_Unconstrained_Type --
17579 --------------------------------
17581 function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
17583 return Ekind (Subp) = E_Function
17584 and then not Is_Scalar_Type (Etype (Subp))
17585 and then not Is_Access_Type (Etype (Subp))
17586 and then not Is_Constrained (Etype (Subp));
17587 end Returns_Unconstrained_Type;
17589 ----------------------------
17590 -- Root_Type_Of_Full_View --
17591 ----------------------------
17593 function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id is
17594 Rtyp : constant Entity_Id := Root_Type (T);
17597 -- The root type of the full view may itself be a private type. Keep
17598 -- looking for the ultimate derivation parent.
17600 if Is_Private_Type (Rtyp) and then Present (Full_View (Rtyp)) then
17601 return Root_Type_Of_Full_View (Full_View (Rtyp));
17605 end Root_Type_Of_Full_View;
17607 ---------------------------
17608 -- Safe_To_Capture_Value --
17609 ---------------------------
17611 function Safe_To_Capture_Value
17614 Cond : Boolean := False) return Boolean
17617 -- The only entities for which we track constant values are variables
17618 -- which are not renamings, constants, out parameters, and in out
17619 -- parameters, so check if we have this case.
17621 -- Note: it may seem odd to track constant values for constants, but in
17622 -- fact this routine is used for other purposes than simply capturing
17623 -- the value. In particular, the setting of Known[_Non]_Null.
17625 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
17627 Ekind_In (Ent, E_Constant, E_Out_Parameter, E_In_Out_Parameter)
17631 -- For conditionals, we also allow loop parameters and all formals,
17632 -- including in parameters.
17634 elsif Cond and then Ekind_In (Ent, E_Loop_Parameter, E_In_Parameter) then
17637 -- For all other cases, not just unsafe, but impossible to capture
17638 -- Current_Value, since the above are the only entities which have
17639 -- Current_Value fields.
17645 -- Skip if volatile or aliased, since funny things might be going on in
17646 -- these cases which we cannot necessarily track. Also skip any variable
17647 -- for which an address clause is given, or whose address is taken. Also
17648 -- never capture value of library level variables (an attempt to do so
17649 -- can occur in the case of package elaboration code).
17651 if Treat_As_Volatile (Ent)
17652 or else Is_Aliased (Ent)
17653 or else Present (Address_Clause (Ent))
17654 or else Address_Taken (Ent)
17655 or else (Is_Library_Level_Entity (Ent)
17656 and then Ekind (Ent) = E_Variable)
17661 -- OK, all above conditions are met. We also require that the scope of
17662 -- the reference be the same as the scope of the entity, not counting
17663 -- packages and blocks and loops.
17666 E_Scope : constant Entity_Id := Scope (Ent);
17667 R_Scope : Entity_Id;
17670 R_Scope := Current_Scope;
17671 while R_Scope /= Standard_Standard loop
17672 exit when R_Scope = E_Scope;
17674 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
17677 R_Scope := Scope (R_Scope);
17682 -- We also require that the reference does not appear in a context
17683 -- where it is not sure to be executed (i.e. a conditional context
17684 -- or an exception handler). We skip this if Cond is True, since the
17685 -- capturing of values from conditional tests handles this ok.
17698 -- Seems dubious that case expressions are not handled here ???
17701 while Present (P) loop
17702 if Nkind (P) = N_If_Statement
17703 or else Nkind (P) = N_Case_Statement
17704 or else (Nkind (P) in N_Short_Circuit
17705 and then Desc = Right_Opnd (P))
17706 or else (Nkind (P) = N_If_Expression
17707 and then Desc /= First (Expressions (P)))
17708 or else Nkind (P) = N_Exception_Handler
17709 or else Nkind (P) = N_Selective_Accept
17710 or else Nkind (P) = N_Conditional_Entry_Call
17711 or else Nkind (P) = N_Timed_Entry_Call
17712 or else Nkind (P) = N_Asynchronous_Select
17720 -- A special Ada 2012 case: the original node may be part
17721 -- of the else_actions of a conditional expression, in which
17722 -- case it might not have been expanded yet, and appears in
17723 -- a non-syntactic list of actions. In that case it is clearly
17724 -- not safe to save a value.
17727 and then Is_List_Member (Desc)
17728 and then No (Parent (List_Containing (Desc)))
17736 -- OK, looks safe to set value
17739 end Safe_To_Capture_Value;
17745 function Same_Name (N1, N2 : Node_Id) return Boolean is
17746 K1 : constant Node_Kind := Nkind (N1);
17747 K2 : constant Node_Kind := Nkind (N2);
17750 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
17751 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
17753 return Chars (N1) = Chars (N2);
17755 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
17756 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
17758 return Same_Name (Selector_Name (N1), Selector_Name (N2))
17759 and then Same_Name (Prefix (N1), Prefix (N2));
17770 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
17771 N1 : constant Node_Id := Original_Node (Node1);
17772 N2 : constant Node_Id := Original_Node (Node2);
17773 -- We do the tests on original nodes, since we are most interested
17774 -- in the original source, not any expansion that got in the way.
17776 K1 : constant Node_Kind := Nkind (N1);
17777 K2 : constant Node_Kind := Nkind (N2);
17780 -- First case, both are entities with same entity
17782 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
17784 EN1 : constant Entity_Id := Entity (N1);
17785 EN2 : constant Entity_Id := Entity (N2);
17787 if Present (EN1) and then Present (EN2)
17788 and then (Ekind_In (EN1, E_Variable, E_Constant)
17789 or else Is_Formal (EN1))
17797 -- Second case, selected component with same selector, same record
17799 if K1 = N_Selected_Component
17800 and then K2 = N_Selected_Component
17801 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
17803 return Same_Object (Prefix (N1), Prefix (N2));
17805 -- Third case, indexed component with same subscripts, same array
17807 elsif K1 = N_Indexed_Component
17808 and then K2 = N_Indexed_Component
17809 and then Same_Object (Prefix (N1), Prefix (N2))
17814 E1 := First (Expressions (N1));
17815 E2 := First (Expressions (N2));
17816 while Present (E1) loop
17817 if not Same_Value (E1, E2) then
17828 -- Fourth case, slice of same array with same bounds
17831 and then K2 = N_Slice
17832 and then Nkind (Discrete_Range (N1)) = N_Range
17833 and then Nkind (Discrete_Range (N2)) = N_Range
17834 and then Same_Value (Low_Bound (Discrete_Range (N1)),
17835 Low_Bound (Discrete_Range (N2)))
17836 and then Same_Value (High_Bound (Discrete_Range (N1)),
17837 High_Bound (Discrete_Range (N2)))
17839 return Same_Name (Prefix (N1), Prefix (N2));
17841 -- All other cases, not clearly the same object
17852 function Same_Type (T1, T2 : Entity_Id) return Boolean is
17857 elsif not Is_Constrained (T1)
17858 and then not Is_Constrained (T2)
17859 and then Base_Type (T1) = Base_Type (T2)
17863 -- For now don't bother with case of identical constraints, to be
17864 -- fiddled with later on perhaps (this is only used for optimization
17865 -- purposes, so it is not critical to do a best possible job)
17876 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
17878 if Compile_Time_Known_Value (Node1)
17879 and then Compile_Time_Known_Value (Node2)
17880 and then Expr_Value (Node1) = Expr_Value (Node2)
17883 elsif Same_Object (Node1, Node2) then
17890 -----------------------------
17891 -- Save_SPARK_Mode_And_Set --
17892 -----------------------------
17894 procedure Save_SPARK_Mode_And_Set
17895 (Context : Entity_Id;
17896 Mode : out SPARK_Mode_Type)
17899 -- Save the current mode in effect
17901 Mode := SPARK_Mode;
17903 -- Do not consider illegal or partially decorated constructs
17905 if Ekind (Context) = E_Void or else Error_Posted (Context) then
17908 elsif Present (SPARK_Pragma (Context)) then
17909 SPARK_Mode := Get_SPARK_Mode_From_Pragma (SPARK_Pragma (Context));
17911 end Save_SPARK_Mode_And_Set;
17913 -------------------------
17914 -- Scalar_Part_Present --
17915 -------------------------
17917 function Scalar_Part_Present (T : Entity_Id) return Boolean is
17921 if Is_Scalar_Type (T) then
17924 elsif Is_Array_Type (T) then
17925 return Scalar_Part_Present (Component_Type (T));
17927 elsif Is_Record_Type (T) or else Has_Discriminants (T) then
17928 C := First_Component_Or_Discriminant (T);
17929 while Present (C) loop
17930 if Scalar_Part_Present (Etype (C)) then
17933 Next_Component_Or_Discriminant (C);
17939 end Scalar_Part_Present;
17941 ------------------------
17942 -- Scope_Is_Transient --
17943 ------------------------
17945 function Scope_Is_Transient return Boolean is
17947 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
17948 end Scope_Is_Transient;
17954 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
17959 while Scop /= Standard_Standard loop
17960 Scop := Scope (Scop);
17962 if Scop = Scope2 then
17970 --------------------------
17971 -- Scope_Within_Or_Same --
17972 --------------------------
17974 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
17979 while Scop /= Standard_Standard loop
17980 if Scop = Scope2 then
17983 Scop := Scope (Scop);
17988 end Scope_Within_Or_Same;
17990 --------------------
17991 -- Set_Convention --
17992 --------------------
17994 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
17996 Basic_Set_Convention (E, Val);
17999 and then Is_Access_Subprogram_Type (Base_Type (E))
18000 and then Has_Foreign_Convention (E)
18003 -- A pragma Convention in an instance may apply to the subtype
18004 -- created for a formal, in which case we have already verified
18005 -- that conventions of actual and formal match and there is nothing
18006 -- to flag on the subtype.
18008 if In_Instance then
18011 Set_Can_Use_Internal_Rep (E, False);
18015 -- If E is an object or component, and the type of E is an anonymous
18016 -- access type with no convention set, then also set the convention of
18017 -- the anonymous access type. We do not do this for anonymous protected
18018 -- types, since protected types always have the default convention.
18020 if Present (Etype (E))
18021 and then (Is_Object (E)
18022 or else Ekind (E) = E_Component
18024 -- Allow E_Void (happens for pragma Convention appearing
18025 -- in the middle of a record applying to a component)
18027 or else Ekind (E) = E_Void)
18030 Typ : constant Entity_Id := Etype (E);
18033 if Ekind_In (Typ, E_Anonymous_Access_Type,
18034 E_Anonymous_Access_Subprogram_Type)
18035 and then not Has_Convention_Pragma (Typ)
18037 Basic_Set_Convention (Typ, Val);
18038 Set_Has_Convention_Pragma (Typ);
18040 -- And for the access subprogram type, deal similarly with the
18041 -- designated E_Subprogram_Type if it is also internal (which
18044 if Ekind (Typ) = E_Anonymous_Access_Subprogram_Type then
18046 Dtype : constant Entity_Id := Designated_Type (Typ);
18048 if Ekind (Dtype) = E_Subprogram_Type
18049 and then Is_Itype (Dtype)
18050 and then not Has_Convention_Pragma (Dtype)
18052 Basic_Set_Convention (Dtype, Val);
18053 Set_Has_Convention_Pragma (Dtype);
18060 end Set_Convention;
18062 ------------------------
18063 -- Set_Current_Entity --
18064 ------------------------
18066 -- The given entity is to be set as the currently visible definition of its
18067 -- associated name (i.e. the Node_Id associated with its name). All we have
18068 -- to do is to get the name from the identifier, and then set the
18069 -- associated Node_Id to point to the given entity.
18071 procedure Set_Current_Entity (E : Entity_Id) is
18073 Set_Name_Entity_Id (Chars (E), E);
18074 end Set_Current_Entity;
18076 ---------------------------
18077 -- Set_Debug_Info_Needed --
18078 ---------------------------
18080 procedure Set_Debug_Info_Needed (T : Entity_Id) is
18082 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
18083 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
18084 -- Used to set debug info in a related node if not set already
18086 --------------------------------------
18087 -- Set_Debug_Info_Needed_If_Not_Set --
18088 --------------------------------------
18090 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
18092 if Present (E) and then not Needs_Debug_Info (E) then
18093 Set_Debug_Info_Needed (E);
18095 -- For a private type, indicate that the full view also needs
18096 -- debug information.
18099 and then Is_Private_Type (E)
18100 and then Present (Full_View (E))
18102 Set_Debug_Info_Needed (Full_View (E));
18105 end Set_Debug_Info_Needed_If_Not_Set;
18107 -- Start of processing for Set_Debug_Info_Needed
18110 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
18111 -- indicates that Debug_Info_Needed is never required for the entity.
18112 -- Nothing to do if entity comes from a predefined file. Library files
18113 -- are compiled without debug information, but inlined bodies of these
18114 -- routines may appear in user code, and debug information on them ends
18115 -- up complicating debugging the user code.
18118 or else Debug_Info_Off (T)
18122 elsif In_Inlined_Body
18123 and then Is_Predefined_File_Name
18124 (Unit_File_Name (Get_Source_Unit (Sloc (T))))
18126 Set_Needs_Debug_Info (T, False);
18129 -- Set flag in entity itself. Note that we will go through the following
18130 -- circuitry even if the flag is already set on T. That's intentional,
18131 -- it makes sure that the flag will be set in subsidiary entities.
18133 Set_Needs_Debug_Info (T);
18135 -- Set flag on subsidiary entities if not set already
18137 if Is_Object (T) then
18138 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
18140 elsif Is_Type (T) then
18141 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
18143 if Is_Record_Type (T) then
18145 Ent : Entity_Id := First_Entity (T);
18147 while Present (Ent) loop
18148 Set_Debug_Info_Needed_If_Not_Set (Ent);
18153 -- For a class wide subtype, we also need debug information
18154 -- for the equivalent type.
18156 if Ekind (T) = E_Class_Wide_Subtype then
18157 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
18160 elsif Is_Array_Type (T) then
18161 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
18164 Indx : Node_Id := First_Index (T);
18166 while Present (Indx) loop
18167 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
18168 Indx := Next_Index (Indx);
18172 -- For a packed array type, we also need debug information for
18173 -- the type used to represent the packed array. Conversely, we
18174 -- also need it for the former if we need it for the latter.
18176 if Is_Packed (T) then
18177 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Impl_Type (T));
18180 if Is_Packed_Array_Impl_Type (T) then
18181 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
18184 elsif Is_Access_Type (T) then
18185 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
18187 elsif Is_Private_Type (T) then
18189 FV : constant Entity_Id := Full_View (T);
18192 Set_Debug_Info_Needed_If_Not_Set (FV);
18194 -- If the full view is itself a derived private type, we need
18195 -- debug information on its underlying type.
18198 and then Is_Private_Type (FV)
18199 and then Present (Underlying_Full_View (FV))
18201 Set_Needs_Debug_Info (Underlying_Full_View (FV));
18205 elsif Is_Protected_Type (T) then
18206 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
18208 elsif Is_Scalar_Type (T) then
18210 -- If the subrange bounds are materialized by dedicated constant
18211 -- objects, also include them in the debug info to make sure the
18212 -- debugger can properly use them.
18214 if Present (Scalar_Range (T))
18215 and then Nkind (Scalar_Range (T)) = N_Range
18218 Low_Bnd : constant Node_Id := Type_Low_Bound (T);
18219 High_Bnd : constant Node_Id := Type_High_Bound (T);
18222 if Is_Entity_Name (Low_Bnd) then
18223 Set_Debug_Info_Needed_If_Not_Set (Entity (Low_Bnd));
18226 if Is_Entity_Name (High_Bnd) then
18227 Set_Debug_Info_Needed_If_Not_Set (Entity (High_Bnd));
18233 end Set_Debug_Info_Needed;
18235 ----------------------------
18236 -- Set_Entity_With_Checks --
18237 ----------------------------
18239 procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id) is
18240 Val_Actual : Entity_Id;
18242 Post_Node : Node_Id;
18245 -- Unconditionally set the entity
18247 Set_Entity (N, Val);
18249 -- The node to post on is the selector in the case of an expanded name,
18250 -- and otherwise the node itself.
18252 if Nkind (N) = N_Expanded_Name then
18253 Post_Node := Selector_Name (N);
18258 -- Check for violation of No_Fixed_IO
18260 if Restriction_Check_Required (No_Fixed_IO)
18262 ((RTU_Loaded (Ada_Text_IO)
18263 and then (Is_RTE (Val, RE_Decimal_IO)
18265 Is_RTE (Val, RE_Fixed_IO)))
18268 (RTU_Loaded (Ada_Wide_Text_IO)
18269 and then (Is_RTE (Val, RO_WT_Decimal_IO)
18271 Is_RTE (Val, RO_WT_Fixed_IO)))
18274 (RTU_Loaded (Ada_Wide_Wide_Text_IO)
18275 and then (Is_RTE (Val, RO_WW_Decimal_IO)
18277 Is_RTE (Val, RO_WW_Fixed_IO))))
18279 -- A special extra check, don't complain about a reference from within
18280 -- the Ada.Interrupts package itself!
18282 and then not In_Same_Extended_Unit (N, Val)
18284 Check_Restriction (No_Fixed_IO, Post_Node);
18287 -- Remaining checks are only done on source nodes. Note that we test
18288 -- for violation of No_Fixed_IO even on non-source nodes, because the
18289 -- cases for checking violations of this restriction are instantiations
18290 -- where the reference in the instance has Comes_From_Source False.
18292 if not Comes_From_Source (N) then
18296 -- Check for violation of No_Abort_Statements, which is triggered by
18297 -- call to Ada.Task_Identification.Abort_Task.
18299 if Restriction_Check_Required (No_Abort_Statements)
18300 and then (Is_RTE (Val, RE_Abort_Task))
18302 -- A special extra check, don't complain about a reference from within
18303 -- the Ada.Task_Identification package itself!
18305 and then not In_Same_Extended_Unit (N, Val)
18307 Check_Restriction (No_Abort_Statements, Post_Node);
18310 if Val = Standard_Long_Long_Integer then
18311 Check_Restriction (No_Long_Long_Integers, Post_Node);
18314 -- Check for violation of No_Dynamic_Attachment
18316 if Restriction_Check_Required (No_Dynamic_Attachment)
18317 and then RTU_Loaded (Ada_Interrupts)
18318 and then (Is_RTE (Val, RE_Is_Reserved) or else
18319 Is_RTE (Val, RE_Is_Attached) or else
18320 Is_RTE (Val, RE_Current_Handler) or else
18321 Is_RTE (Val, RE_Attach_Handler) or else
18322 Is_RTE (Val, RE_Exchange_Handler) or else
18323 Is_RTE (Val, RE_Detach_Handler) or else
18324 Is_RTE (Val, RE_Reference))
18326 -- A special extra check, don't complain about a reference from within
18327 -- the Ada.Interrupts package itself!
18329 and then not In_Same_Extended_Unit (N, Val)
18331 Check_Restriction (No_Dynamic_Attachment, Post_Node);
18334 -- Check for No_Implementation_Identifiers
18336 if Restriction_Check_Required (No_Implementation_Identifiers) then
18338 -- We have an implementation defined entity if it is marked as
18339 -- implementation defined, or is defined in a package marked as
18340 -- implementation defined. However, library packages themselves
18341 -- are excluded (we don't want to flag Interfaces itself, just
18342 -- the entities within it).
18344 if (Is_Implementation_Defined (Val)
18346 (Present (Scope (Val))
18347 and then Is_Implementation_Defined (Scope (Val))))
18348 and then not (Ekind_In (Val, E_Package, E_Generic_Package)
18349 and then Is_Library_Level_Entity (Val))
18351 Check_Restriction (No_Implementation_Identifiers, Post_Node);
18355 -- Do the style check
18358 and then not Suppress_Style_Checks (Val)
18359 and then not In_Instance
18361 if Nkind (N) = N_Identifier then
18363 elsif Nkind (N) = N_Expanded_Name then
18364 Nod := Selector_Name (N);
18369 -- A special situation arises for derived operations, where we want
18370 -- to do the check against the parent (since the Sloc of the derived
18371 -- operation points to the derived type declaration itself).
18374 while not Comes_From_Source (Val_Actual)
18375 and then Nkind (Val_Actual) in N_Entity
18376 and then (Ekind (Val_Actual) = E_Enumeration_Literal
18377 or else Is_Subprogram_Or_Generic_Subprogram (Val_Actual))
18378 and then Present (Alias (Val_Actual))
18380 Val_Actual := Alias (Val_Actual);
18383 -- Renaming declarations for generic actuals do not come from source,
18384 -- and have a different name from that of the entity they rename, so
18385 -- there is no style check to perform here.
18387 if Chars (Nod) = Chars (Val_Actual) then
18388 Style.Check_Identifier (Nod, Val_Actual);
18392 Set_Entity (N, Val);
18393 end Set_Entity_With_Checks;
18395 ------------------------
18396 -- Set_Name_Entity_Id --
18397 ------------------------
18399 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
18401 Set_Name_Table_Int (Id, Int (Val));
18402 end Set_Name_Entity_Id;
18404 ---------------------
18405 -- Set_Next_Actual --
18406 ---------------------
18408 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
18410 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
18411 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
18413 end Set_Next_Actual;
18415 ----------------------------------
18416 -- Set_Optimize_Alignment_Flags --
18417 ----------------------------------
18419 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
18421 if Optimize_Alignment = 'S' then
18422 Set_Optimize_Alignment_Space (E);
18423 elsif Optimize_Alignment = 'T' then
18424 Set_Optimize_Alignment_Time (E);
18426 end Set_Optimize_Alignment_Flags;
18428 -----------------------
18429 -- Set_Public_Status --
18430 -----------------------
18432 procedure Set_Public_Status (Id : Entity_Id) is
18433 S : constant Entity_Id := Current_Scope;
18435 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
18436 -- Determines if E is defined within handled statement sequence or
18437 -- an if statement, returns True if so, False otherwise.
18439 ----------------------
18440 -- Within_HSS_Or_If --
18441 ----------------------
18443 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
18446 N := Declaration_Node (E);
18453 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
18459 end Within_HSS_Or_If;
18461 -- Start of processing for Set_Public_Status
18464 -- Everything in the scope of Standard is public
18466 if S = Standard_Standard then
18467 Set_Is_Public (Id);
18469 -- Entity is definitely not public if enclosing scope is not public
18471 elsif not Is_Public (S) then
18474 -- An object or function declaration that occurs in a handled sequence
18475 -- of statements or within an if statement is the declaration for a
18476 -- temporary object or local subprogram generated by the expander. It
18477 -- never needs to be made public and furthermore, making it public can
18478 -- cause back end problems.
18480 elsif Nkind_In (Parent (Id), N_Object_Declaration,
18481 N_Function_Specification)
18482 and then Within_HSS_Or_If (Id)
18486 -- Entities in public packages or records are public
18488 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
18489 Set_Is_Public (Id);
18491 -- The bounds of an entry family declaration can generate object
18492 -- declarations that are visible to the back-end, e.g. in the
18493 -- the declaration of a composite type that contains tasks.
18495 elsif Is_Concurrent_Type (S)
18496 and then not Has_Completion (S)
18497 and then Nkind (Parent (Id)) = N_Object_Declaration
18499 Set_Is_Public (Id);
18501 end Set_Public_Status;
18503 -----------------------------
18504 -- Set_Referenced_Modified --
18505 -----------------------------
18507 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
18511 -- Deal with indexed or selected component where prefix is modified
18513 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
18514 Pref := Prefix (N);
18516 -- If prefix is access type, then it is the designated object that is
18517 -- being modified, which means we have no entity to set the flag on.
18519 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
18522 -- Otherwise chase the prefix
18525 Set_Referenced_Modified (Pref, Out_Param);
18528 -- Otherwise see if we have an entity name (only other case to process)
18530 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
18531 Set_Referenced_As_LHS (Entity (N), not Out_Param);
18532 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
18534 end Set_Referenced_Modified;
18536 ----------------------------
18537 -- Set_Scope_Is_Transient --
18538 ----------------------------
18540 procedure Set_Scope_Is_Transient (V : Boolean := True) is
18542 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
18543 end Set_Scope_Is_Transient;
18545 -------------------
18546 -- Set_Size_Info --
18547 -------------------
18549 procedure Set_Size_Info (T1, T2 : Entity_Id) is
18551 -- We copy Esize, but not RM_Size, since in general RM_Size is
18552 -- subtype specific and does not get inherited by all subtypes.
18554 Set_Esize (T1, Esize (T2));
18555 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
18557 if Is_Discrete_Or_Fixed_Point_Type (T1)
18559 Is_Discrete_Or_Fixed_Point_Type (T2)
18561 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
18564 Set_Alignment (T1, Alignment (T2));
18567 --------------------
18568 -- Static_Boolean --
18569 --------------------
18571 function Static_Boolean (N : Node_Id) return Uint is
18573 Analyze_And_Resolve (N, Standard_Boolean);
18576 or else Error_Posted (N)
18577 or else Etype (N) = Any_Type
18582 if Is_OK_Static_Expression (N) then
18583 if not Raises_Constraint_Error (N) then
18584 return Expr_Value (N);
18589 elsif Etype (N) = Any_Type then
18593 Flag_Non_Static_Expr
18594 ("static boolean expression required here", N);
18597 end Static_Boolean;
18599 --------------------
18600 -- Static_Integer --
18601 --------------------
18603 function Static_Integer (N : Node_Id) return Uint is
18605 Analyze_And_Resolve (N, Any_Integer);
18608 or else Error_Posted (N)
18609 or else Etype (N) = Any_Type
18614 if Is_OK_Static_Expression (N) then
18615 if not Raises_Constraint_Error (N) then
18616 return Expr_Value (N);
18621 elsif Etype (N) = Any_Type then
18625 Flag_Non_Static_Expr
18626 ("static integer expression required here", N);
18629 end Static_Integer;
18631 --------------------------
18632 -- Statically_Different --
18633 --------------------------
18635 function Statically_Different (E1, E2 : Node_Id) return Boolean is
18636 R1 : constant Node_Id := Get_Referenced_Object (E1);
18637 R2 : constant Node_Id := Get_Referenced_Object (E2);
18639 return Is_Entity_Name (R1)
18640 and then Is_Entity_Name (R2)
18641 and then Entity (R1) /= Entity (R2)
18642 and then not Is_Formal (Entity (R1))
18643 and then not Is_Formal (Entity (R2));
18644 end Statically_Different;
18646 --------------------------------------
18647 -- Subject_To_Loop_Entry_Attributes --
18648 --------------------------------------
18650 function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
18656 -- The expansion mechanism transform a loop subject to at least one
18657 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
18658 -- the conditional part.
18660 if Nkind_In (Stmt, N_Block_Statement, N_If_Statement)
18661 and then Nkind (Original_Node (N)) = N_Loop_Statement
18663 Stmt := Original_Node (N);
18667 Nkind (Stmt) = N_Loop_Statement
18668 and then Present (Identifier (Stmt))
18669 and then Present (Entity (Identifier (Stmt)))
18670 and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
18671 end Subject_To_Loop_Entry_Attributes;
18673 -----------------------------
18674 -- Subprogram_Access_Level --
18675 -----------------------------
18677 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
18679 if Present (Alias (Subp)) then
18680 return Subprogram_Access_Level (Alias (Subp));
18682 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
18684 end Subprogram_Access_Level;
18686 -------------------------------
18687 -- Support_Atomic_Primitives --
18688 -------------------------------
18690 function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
18694 -- Verify the alignment of Typ is known
18696 if not Known_Alignment (Typ) then
18700 if Known_Static_Esize (Typ) then
18701 Size := UI_To_Int (Esize (Typ));
18703 -- If the Esize (Object_Size) is unknown at compile time, look at the
18704 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
18706 elsif Known_Static_RM_Size (Typ) then
18707 Size := UI_To_Int (RM_Size (Typ));
18709 -- Otherwise, the size is considered to be unknown.
18715 -- Check that the size of the component is 8, 16, 32 or 64 bits and that
18716 -- Typ is properly aligned.
18719 when 8 | 16 | 32 | 64 =>
18720 return Size = UI_To_Int (Alignment (Typ)) * 8;
18724 end Support_Atomic_Primitives;
18730 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
18732 if Debug_Flag_W then
18733 for J in 0 .. Scope_Stack.Last loop
18738 Write_Name (Chars (E));
18739 Write_Str (" from ");
18740 Write_Location (Sloc (N));
18745 -----------------------
18746 -- Transfer_Entities --
18747 -----------------------
18749 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
18750 procedure Set_Public_Status_Of (Id : Entity_Id);
18751 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
18752 -- Set_Public_Status. If successfull and Id denotes a record type, set
18753 -- the Is_Public attribute of its fields.
18755 --------------------------
18756 -- Set_Public_Status_Of --
18757 --------------------------
18759 procedure Set_Public_Status_Of (Id : Entity_Id) is
18763 if not Is_Public (Id) then
18764 Set_Public_Status (Id);
18766 -- When the input entity is a public record type, ensure that all
18767 -- its internal fields are also exposed to the linker. The fields
18768 -- of a class-wide type are never made public.
18771 and then Is_Record_Type (Id)
18772 and then not Is_Class_Wide_Type (Id)
18774 Field := First_Entity (Id);
18775 while Present (Field) loop
18776 Set_Is_Public (Field);
18777 Next_Entity (Field);
18781 end Set_Public_Status_Of;
18785 Full_Id : Entity_Id;
18788 -- Start of processing for Transfer_Entities
18791 Id := First_Entity (From);
18793 if Present (Id) then
18795 -- Merge the entity chain of the source scope with that of the
18796 -- destination scope.
18798 if Present (Last_Entity (To)) then
18799 Set_Next_Entity (Last_Entity (To), Id);
18801 Set_First_Entity (To, Id);
18804 Set_Last_Entity (To, Last_Entity (From));
18806 -- Inspect the entities of the source scope and update their Scope
18809 while Present (Id) loop
18810 Set_Scope (Id, To);
18811 Set_Public_Status_Of (Id);
18813 -- Handle an internally generated full view for a private type
18815 if Is_Private_Type (Id)
18816 and then Present (Full_View (Id))
18817 and then Is_Itype (Full_View (Id))
18819 Full_Id := Full_View (Id);
18821 Set_Scope (Full_Id, To);
18822 Set_Public_Status_Of (Full_Id);
18828 Set_First_Entity (From, Empty);
18829 Set_Last_Entity (From, Empty);
18831 end Transfer_Entities;
18833 -----------------------
18834 -- Type_Access_Level --
18835 -----------------------
18837 function Type_Access_Level (Typ : Entity_Id) return Uint is
18841 Btyp := Base_Type (Typ);
18843 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
18844 -- simply use the level where the type is declared. This is true for
18845 -- stand-alone object declarations, and for anonymous access types
18846 -- associated with components the level is the same as that of the
18847 -- enclosing composite type. However, special treatment is needed for
18848 -- the cases of access parameters, return objects of an anonymous access
18849 -- type, and, in Ada 95, access discriminants of limited types.
18851 if Is_Access_Type (Btyp) then
18852 if Ekind (Btyp) = E_Anonymous_Access_Type then
18854 -- If the type is a nonlocal anonymous access type (such as for
18855 -- an access parameter) we treat it as being declared at the
18856 -- library level to ensure that names such as X.all'access don't
18857 -- fail static accessibility checks.
18859 if not Is_Local_Anonymous_Access (Typ) then
18860 return Scope_Depth (Standard_Standard);
18862 -- If this is a return object, the accessibility level is that of
18863 -- the result subtype of the enclosing function. The test here is
18864 -- little complicated, because we have to account for extended
18865 -- return statements that have been rewritten as blocks, in which
18866 -- case we have to find and the Is_Return_Object attribute of the
18867 -- itype's associated object. It would be nice to find a way to
18868 -- simplify this test, but it doesn't seem worthwhile to add a new
18869 -- flag just for purposes of this test. ???
18871 elsif Ekind (Scope (Btyp)) = E_Return_Statement
18874 and then Nkind (Associated_Node_For_Itype (Btyp)) =
18875 N_Object_Declaration
18876 and then Is_Return_Object
18877 (Defining_Identifier
18878 (Associated_Node_For_Itype (Btyp))))
18884 Scop := Scope (Scope (Btyp));
18885 while Present (Scop) loop
18886 exit when Ekind (Scop) = E_Function;
18887 Scop := Scope (Scop);
18890 -- Treat the return object's type as having the level of the
18891 -- function's result subtype (as per RM05-6.5(5.3/2)).
18893 return Type_Access_Level (Etype (Scop));
18898 Btyp := Root_Type (Btyp);
18900 -- The accessibility level of anonymous access types associated with
18901 -- discriminants is that of the current instance of the type, and
18902 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
18904 -- AI-402: access discriminants have accessibility based on the
18905 -- object rather than the type in Ada 2005, so the above paragraph
18908 -- ??? Needs completion with rules from AI-416
18910 if Ada_Version <= Ada_95
18911 and then Ekind (Typ) = E_Anonymous_Access_Type
18912 and then Present (Associated_Node_For_Itype (Typ))
18913 and then Nkind (Associated_Node_For_Itype (Typ)) =
18914 N_Discriminant_Specification
18916 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
18920 -- Return library level for a generic formal type. This is done because
18921 -- RM(10.3.2) says that "The statically deeper relationship does not
18922 -- apply to ... a descendant of a generic formal type". Rather than
18923 -- checking at each point where a static accessibility check is
18924 -- performed to see if we are dealing with a formal type, this rule is
18925 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
18926 -- return extreme values for a formal type; Deepest_Type_Access_Level
18927 -- returns Int'Last. By calling the appropriate function from among the
18928 -- two, we ensure that the static accessibility check will pass if we
18929 -- happen to run into a formal type. More specifically, we should call
18930 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
18931 -- call occurs as part of a static accessibility check and the error
18932 -- case is the case where the type's level is too shallow (as opposed
18935 if Is_Generic_Type (Root_Type (Btyp)) then
18936 return Scope_Depth (Standard_Standard);
18939 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
18940 end Type_Access_Level;
18942 ------------------------------------
18943 -- Type_Without_Stream_Operation --
18944 ------------------------------------
18946 function Type_Without_Stream_Operation
18948 Op : TSS_Name_Type := TSS_Null) return Entity_Id
18950 BT : constant Entity_Id := Base_Type (T);
18951 Op_Missing : Boolean;
18954 if not Restriction_Active (No_Default_Stream_Attributes) then
18958 if Is_Elementary_Type (T) then
18959 if Op = TSS_Null then
18961 No (TSS (BT, TSS_Stream_Read))
18962 or else No (TSS (BT, TSS_Stream_Write));
18965 Op_Missing := No (TSS (BT, Op));
18974 elsif Is_Array_Type (T) then
18975 return Type_Without_Stream_Operation (Component_Type (T), Op);
18977 elsif Is_Record_Type (T) then
18983 Comp := First_Component (T);
18984 while Present (Comp) loop
18985 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
18987 if Present (C_Typ) then
18991 Next_Component (Comp);
18997 elsif Is_Private_Type (T) and then Present (Full_View (T)) then
18998 return Type_Without_Stream_Operation (Full_View (T), Op);
19002 end Type_Without_Stream_Operation;
19004 ----------------------------
19005 -- Unique_Defining_Entity --
19006 ----------------------------
19008 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
19010 return Unique_Entity (Defining_Entity (N));
19011 end Unique_Defining_Entity;
19013 -------------------
19014 -- Unique_Entity --
19015 -------------------
19017 function Unique_Entity (E : Entity_Id) return Entity_Id is
19018 U : Entity_Id := E;
19024 if Present (Full_View (E)) then
19025 U := Full_View (E);
19029 if Nkind (Parent (E)) = N_Entry_Body then
19031 Prot_Item : Entity_Id;
19033 -- Traverse the entity list of the protected type and locate
19034 -- an entry declaration which matches the entry body.
19036 Prot_Item := First_Entity (Scope (E));
19037 while Present (Prot_Item) loop
19038 if Ekind (Prot_Item) = E_Entry
19039 and then Corresponding_Body (Parent (Prot_Item)) = E
19045 Next_Entity (Prot_Item);
19050 when Formal_Kind =>
19051 if Present (Spec_Entity (E)) then
19052 U := Spec_Entity (E);
19055 when E_Package_Body =>
19058 if Nkind (P) = N_Defining_Program_Unit_Name then
19062 if Nkind (P) = N_Package_Body
19063 and then Present (Corresponding_Spec (P))
19065 U := Corresponding_Spec (P);
19067 elsif Nkind (P) = N_Package_Body_Stub
19068 and then Present (Corresponding_Spec_Of_Stub (P))
19070 U := Corresponding_Spec_Of_Stub (P);
19073 when E_Protected_Body =>
19076 if Nkind (P) = N_Protected_Body
19077 and then Present (Corresponding_Spec (P))
19079 U := Corresponding_Spec (P);
19081 elsif Nkind (P) = N_Protected_Body_Stub
19082 and then Present (Corresponding_Spec_Of_Stub (P))
19084 U := Corresponding_Spec_Of_Stub (P);
19087 when E_Subprogram_Body =>
19090 if Nkind (P) = N_Defining_Program_Unit_Name then
19096 if Nkind (P) = N_Subprogram_Body
19097 and then Present (Corresponding_Spec (P))
19099 U := Corresponding_Spec (P);
19101 elsif Nkind (P) = N_Subprogram_Body_Stub
19102 and then Present (Corresponding_Spec_Of_Stub (P))
19104 U := Corresponding_Spec_Of_Stub (P);
19107 when E_Task_Body =>
19110 if Nkind (P) = N_Task_Body
19111 and then Present (Corresponding_Spec (P))
19113 U := Corresponding_Spec (P);
19115 elsif Nkind (P) = N_Task_Body_Stub
19116 and then Present (Corresponding_Spec_Of_Stub (P))
19118 U := Corresponding_Spec_Of_Stub (P);
19122 if Present (Full_View (E)) then
19123 U := Full_View (E);
19137 function Unique_Name (E : Entity_Id) return String is
19139 -- Names of E_Subprogram_Body or E_Package_Body entities are not
19140 -- reliable, as they may not include the overloading suffix. Instead,
19141 -- when looking for the name of E or one of its enclosing scope, we get
19142 -- the name of the corresponding Unique_Entity.
19144 function Get_Scoped_Name (E : Entity_Id) return String;
19145 -- Return the name of E prefixed by all the names of the scopes to which
19146 -- E belongs, except for Standard.
19148 ---------------------
19149 -- Get_Scoped_Name --
19150 ---------------------
19152 function Get_Scoped_Name (E : Entity_Id) return String is
19153 Name : constant String := Get_Name_String (Chars (E));
19155 if Has_Fully_Qualified_Name (E)
19156 or else Scope (E) = Standard_Standard
19160 return Get_Scoped_Name (Unique_Entity (Scope (E))) & "__" & Name;
19162 end Get_Scoped_Name;
19164 -- Start of processing for Unique_Name
19167 if E = Standard_Standard then
19168 return Get_Name_String (Name_Standard);
19170 elsif Scope (E) = Standard_Standard
19171 and then not (Ekind (E) = E_Package or else Is_Subprogram (E))
19173 return Get_Name_String (Name_Standard) & "__" &
19174 Get_Name_String (Chars (E));
19176 elsif Ekind (E) = E_Enumeration_Literal then
19177 return Unique_Name (Etype (E)) & "__" & Get_Name_String (Chars (E));
19180 return Get_Scoped_Name (Unique_Entity (E));
19184 ---------------------
19185 -- Unit_Is_Visible --
19186 ---------------------
19188 function Unit_Is_Visible (U : Entity_Id) return Boolean is
19189 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
19190 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
19192 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
19193 -- For a child unit, check whether unit appears in a with_clause
19196 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
19197 -- Scan the context clause of one compilation unit looking for a
19198 -- with_clause for the unit in question.
19200 ----------------------------
19201 -- Unit_In_Parent_Context --
19202 ----------------------------
19204 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
19206 if Unit_In_Context (Par_Unit) then
19209 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
19210 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
19215 end Unit_In_Parent_Context;
19217 ---------------------
19218 -- Unit_In_Context --
19219 ---------------------
19221 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
19225 Clause := First (Context_Items (Comp_Unit));
19226 while Present (Clause) loop
19227 if Nkind (Clause) = N_With_Clause then
19228 if Library_Unit (Clause) = U then
19231 -- The with_clause may denote a renaming of the unit we are
19232 -- looking for, eg. Text_IO which renames Ada.Text_IO.
19235 Renamed_Entity (Entity (Name (Clause))) =
19236 Defining_Entity (Unit (U))
19246 end Unit_In_Context;
19248 -- Start of processing for Unit_Is_Visible
19251 -- The currrent unit is directly visible
19256 elsif Unit_In_Context (Curr) then
19259 -- If the current unit is a body, check the context of the spec
19261 elsif Nkind (Unit (Curr)) = N_Package_Body
19263 (Nkind (Unit (Curr)) = N_Subprogram_Body
19264 and then not Acts_As_Spec (Unit (Curr)))
19266 if Unit_In_Context (Library_Unit (Curr)) then
19271 -- If the spec is a child unit, examine the parents
19273 if Is_Child_Unit (Curr_Entity) then
19274 if Nkind (Unit (Curr)) in N_Unit_Body then
19276 Unit_In_Parent_Context
19277 (Parent_Spec (Unit (Library_Unit (Curr))));
19279 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
19285 end Unit_Is_Visible;
19287 ------------------------------
19288 -- Universal_Interpretation --
19289 ------------------------------
19291 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
19292 Index : Interp_Index;
19296 -- The argument may be a formal parameter of an operator or subprogram
19297 -- with multiple interpretations, or else an expression for an actual.
19299 if Nkind (Opnd) = N_Defining_Identifier
19300 or else not Is_Overloaded (Opnd)
19302 if Etype (Opnd) = Universal_Integer
19303 or else Etype (Opnd) = Universal_Real
19305 return Etype (Opnd);
19311 Get_First_Interp (Opnd, Index, It);
19312 while Present (It.Typ) loop
19313 if It.Typ = Universal_Integer
19314 or else It.Typ = Universal_Real
19319 Get_Next_Interp (Index, It);
19324 end Universal_Interpretation;
19330 function Unqualify (Expr : Node_Id) return Node_Id is
19332 -- Recurse to handle unlikely case of multiple levels of qualification
19334 if Nkind (Expr) = N_Qualified_Expression then
19335 return Unqualify (Expression (Expr));
19337 -- Normal case, not a qualified expression
19344 -----------------------
19345 -- Visible_Ancestors --
19346 -----------------------
19348 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
19354 pragma Assert (Is_Record_Type (Typ) and then Is_Tagged_Type (Typ));
19356 -- Collect all the parents and progenitors of Typ. If the full-view of
19357 -- private parents and progenitors is available then it is used to
19358 -- generate the list of visible ancestors; otherwise their partial
19359 -- view is added to the resulting list.
19364 Use_Full_View => True);
19368 Ifaces_List => List_2,
19369 Exclude_Parents => True,
19370 Use_Full_View => True);
19372 -- Join the two lists. Avoid duplications because an interface may
19373 -- simultaneously be parent and progenitor of a type.
19375 Elmt := First_Elmt (List_2);
19376 while Present (Elmt) loop
19377 Append_Unique_Elmt (Node (Elmt), List_1);
19382 end Visible_Ancestors;
19384 ----------------------
19385 -- Within_Init_Proc --
19386 ----------------------
19388 function Within_Init_Proc return Boolean is
19392 S := Current_Scope;
19393 while not Is_Overloadable (S) loop
19394 if S = Standard_Standard then
19401 return Is_Init_Proc (S);
19402 end Within_Init_Proc;
19408 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
19415 elsif SE = Standard_Standard then
19427 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
19428 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
19429 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
19431 Matching_Field : Entity_Id;
19432 -- Entity to give a more precise suggestion on how to write a one-
19433 -- element positional aggregate.
19435 function Has_One_Matching_Field return Boolean;
19436 -- Determines if Expec_Type is a record type with a single component or
19437 -- discriminant whose type matches the found type or is one dimensional
19438 -- array whose component type matches the found type. In the case of
19439 -- one discriminant, we ignore the variant parts. That's not accurate,
19440 -- but good enough for the warning.
19442 ----------------------------
19443 -- Has_One_Matching_Field --
19444 ----------------------------
19446 function Has_One_Matching_Field return Boolean is
19450 Matching_Field := Empty;
19452 if Is_Array_Type (Expec_Type)
19453 and then Number_Dimensions (Expec_Type) = 1
19454 and then Covers (Etype (Component_Type (Expec_Type)), Found_Type)
19456 -- Use type name if available. This excludes multidimensional
19457 -- arrays and anonymous arrays.
19459 if Comes_From_Source (Expec_Type) then
19460 Matching_Field := Expec_Type;
19462 -- For an assignment, use name of target
19464 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
19465 and then Is_Entity_Name (Name (Parent (Expr)))
19467 Matching_Field := Entity (Name (Parent (Expr)));
19472 elsif not Is_Record_Type (Expec_Type) then
19476 E := First_Entity (Expec_Type);
19481 elsif not Ekind_In (E, E_Discriminant, E_Component)
19482 or else Nam_In (Chars (E), Name_uTag, Name_uParent)
19491 if not Covers (Etype (E), Found_Type) then
19494 elsif Present (Next_Entity (E))
19495 and then (Ekind (E) = E_Component
19496 or else Ekind (Next_Entity (E)) = E_Discriminant)
19501 Matching_Field := E;
19505 end Has_One_Matching_Field;
19507 -- Start of processing for Wrong_Type
19510 -- Don't output message if either type is Any_Type, or if a message
19511 -- has already been posted for this node. We need to do the latter
19512 -- check explicitly (it is ordinarily done in Errout), because we
19513 -- are using ! to force the output of the error messages.
19515 if Expec_Type = Any_Type
19516 or else Found_Type = Any_Type
19517 or else Error_Posted (Expr)
19521 -- If one of the types is a Taft-Amendment type and the other it its
19522 -- completion, it must be an illegal use of a TAT in the spec, for
19523 -- which an error was already emitted. Avoid cascaded errors.
19525 elsif Is_Incomplete_Type (Expec_Type)
19526 and then Has_Completion_In_Body (Expec_Type)
19527 and then Full_View (Expec_Type) = Etype (Expr)
19531 elsif Is_Incomplete_Type (Etype (Expr))
19532 and then Has_Completion_In_Body (Etype (Expr))
19533 and then Full_View (Etype (Expr)) = Expec_Type
19537 -- In an instance, there is an ongoing problem with completion of
19538 -- type derived from private types. Their structure is what Gigi
19539 -- expects, but the Etype is the parent type rather than the
19540 -- derived private type itself. Do not flag error in this case. The
19541 -- private completion is an entity without a parent, like an Itype.
19542 -- Similarly, full and partial views may be incorrect in the instance.
19543 -- There is no simple way to insure that it is consistent ???
19545 -- A similar view discrepancy can happen in an inlined body, for the
19546 -- same reason: inserted body may be outside of the original package
19547 -- and only partial views are visible at the point of insertion.
19549 elsif In_Instance or else In_Inlined_Body then
19550 if Etype (Etype (Expr)) = Etype (Expected_Type)
19552 (Has_Private_Declaration (Expected_Type)
19553 or else Has_Private_Declaration (Etype (Expr)))
19554 and then No (Parent (Expected_Type))
19558 elsif Nkind (Parent (Expr)) = N_Qualified_Expression
19559 and then Entity (Subtype_Mark (Parent (Expr))) = Expected_Type
19563 elsif Is_Private_Type (Expected_Type)
19564 and then Present (Full_View (Expected_Type))
19565 and then Covers (Full_View (Expected_Type), Etype (Expr))
19569 -- Conversely, type of expression may be the private one
19571 elsif Is_Private_Type (Base_Type (Etype (Expr)))
19572 and then Full_View (Base_Type (Etype (Expr))) = Expected_Type
19578 -- An interesting special check. If the expression is parenthesized
19579 -- and its type corresponds to the type of the sole component of the
19580 -- expected record type, or to the component type of the expected one
19581 -- dimensional array type, then assume we have a bad aggregate attempt.
19583 if Nkind (Expr) in N_Subexpr
19584 and then Paren_Count (Expr) /= 0
19585 and then Has_One_Matching_Field
19587 Error_Msg_N ("positional aggregate cannot have one component", Expr);
19589 if Present (Matching_Field) then
19590 if Is_Array_Type (Expec_Type) then
19592 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
19595 ("\write instead `& ='> ...`", Expr, Matching_Field);
19599 -- Another special check, if we are looking for a pool-specific access
19600 -- type and we found an E_Access_Attribute_Type, then we have the case
19601 -- of an Access attribute being used in a context which needs a pool-
19602 -- specific type, which is never allowed. The one extra check we make
19603 -- is that the expected designated type covers the Found_Type.
19605 elsif Is_Access_Type (Expec_Type)
19606 and then Ekind (Found_Type) = E_Access_Attribute_Type
19607 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
19608 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
19610 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
19612 Error_Msg_N -- CODEFIX
19613 ("result must be general access type!", Expr);
19614 Error_Msg_NE -- CODEFIX
19615 ("add ALL to }!", Expr, Expec_Type);
19617 -- Another special check, if the expected type is an integer type,
19618 -- but the expression is of type System.Address, and the parent is
19619 -- an addition or subtraction operation whose left operand is the
19620 -- expression in question and whose right operand is of an integral
19621 -- type, then this is an attempt at address arithmetic, so give
19622 -- appropriate message.
19624 elsif Is_Integer_Type (Expec_Type)
19625 and then Is_RTE (Found_Type, RE_Address)
19626 and then Nkind_In (Parent (Expr), N_Op_Add, N_Op_Subtract)
19627 and then Expr = Left_Opnd (Parent (Expr))
19628 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
19631 ("address arithmetic not predefined in package System",
19634 ("\possible missing with/use of System.Storage_Elements",
19638 -- If the expected type is an anonymous access type, as for access
19639 -- parameters and discriminants, the error is on the designated types.
19641 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
19642 if Comes_From_Source (Expec_Type) then
19643 Error_Msg_NE ("expected}!", Expr, Expec_Type);
19646 ("expected an access type with designated}",
19647 Expr, Designated_Type (Expec_Type));
19650 if Is_Access_Type (Found_Type)
19651 and then not Comes_From_Source (Found_Type)
19654 ("\\found an access type with designated}!",
19655 Expr, Designated_Type (Found_Type));
19657 if From_Limited_With (Found_Type) then
19658 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
19659 Error_Msg_Qual_Level := 99;
19660 Error_Msg_NE -- CODEFIX
19661 ("\\missing `WITH &;", Expr, Scope (Found_Type));
19662 Error_Msg_Qual_Level := 0;
19664 Error_Msg_NE ("found}!", Expr, Found_Type);
19668 -- Normal case of one type found, some other type expected
19671 -- If the names of the two types are the same, see if some number
19672 -- of levels of qualification will help. Don't try more than three
19673 -- levels, and if we get to standard, it's no use (and probably
19674 -- represents an error in the compiler) Also do not bother with
19675 -- internal scope names.
19678 Expec_Scope : Entity_Id;
19679 Found_Scope : Entity_Id;
19682 Expec_Scope := Expec_Type;
19683 Found_Scope := Found_Type;
19685 for Levels in Int range 0 .. 3 loop
19686 if Chars (Expec_Scope) /= Chars (Found_Scope) then
19687 Error_Msg_Qual_Level := Levels;
19691 Expec_Scope := Scope (Expec_Scope);
19692 Found_Scope := Scope (Found_Scope);
19694 exit when Expec_Scope = Standard_Standard
19695 or else Found_Scope = Standard_Standard
19696 or else not Comes_From_Source (Expec_Scope)
19697 or else not Comes_From_Source (Found_Scope);
19701 if Is_Record_Type (Expec_Type)
19702 and then Present (Corresponding_Remote_Type (Expec_Type))
19704 Error_Msg_NE ("expected}!", Expr,
19705 Corresponding_Remote_Type (Expec_Type));
19707 Error_Msg_NE ("expected}!", Expr, Expec_Type);
19710 if Is_Entity_Name (Expr)
19711 and then Is_Package_Or_Generic_Package (Entity (Expr))
19713 Error_Msg_N ("\\found package name!", Expr);
19715 elsif Is_Entity_Name (Expr)
19716 and then Ekind_In (Entity (Expr), E_Procedure, E_Generic_Procedure)
19718 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
19720 ("found procedure name, possibly missing Access attribute!",
19724 ("\\found procedure name instead of function!", Expr);
19727 elsif Nkind (Expr) = N_Function_Call
19728 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
19729 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
19730 and then No (Parameter_Associations (Expr))
19733 ("found function name, possibly missing Access attribute!",
19736 -- Catch common error: a prefix or infix operator which is not
19737 -- directly visible because the type isn't.
19739 elsif Nkind (Expr) in N_Op
19740 and then Is_Overloaded (Expr)
19741 and then not Is_Immediately_Visible (Expec_Type)
19742 and then not Is_Potentially_Use_Visible (Expec_Type)
19743 and then not In_Use (Expec_Type)
19744 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
19747 ("operator of the type is not directly visible!", Expr);
19749 elsif Ekind (Found_Type) = E_Void
19750 and then Present (Parent (Found_Type))
19751 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
19753 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
19756 Error_Msg_NE ("\\found}!", Expr, Found_Type);
19759 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
19760 -- of the same modular type, and (M1 and M2) = 0 was intended.
19762 if Expec_Type = Standard_Boolean
19763 and then Is_Modular_Integer_Type (Found_Type)
19764 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
19765 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
19768 Op : constant Node_Id := Right_Opnd (Parent (Expr));
19769 L : constant Node_Id := Left_Opnd (Op);
19770 R : constant Node_Id := Right_Opnd (Op);
19773 -- The case for the message is when the left operand of the
19774 -- comparison is the same modular type, or when it is an
19775 -- integer literal (or other universal integer expression),
19776 -- which would have been typed as the modular type if the
19777 -- parens had been there.
19779 if (Etype (L) = Found_Type
19781 Etype (L) = Universal_Integer)
19782 and then Is_Integer_Type (Etype (R))
19785 ("\\possible missing parens for modular operation", Expr);
19790 -- Reset error message qualification indication
19792 Error_Msg_Qual_Level := 0;