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 Aspects; use Aspects;
27 with Atree; use Atree;
28 with Casing; use Casing;
29 with Checks; use Checks;
30 with Debug; use Debug;
31 with Elists; use Elists;
32 with Errout; use Errout;
33 with Exp_Ch11; use Exp_Ch11;
34 with Exp_Disp; use Exp_Disp;
35 with Exp_Util; use Exp_Util;
36 with Fname; use Fname;
37 with Freeze; use Freeze;
39 with Lib.Xref; use Lib.Xref;
40 with Namet.Sp; use Namet.Sp;
41 with Nlists; use Nlists;
42 with Nmake; use Nmake;
43 with Output; use Output;
44 with Restrict; use Restrict;
45 with Rident; use Rident;
46 with Rtsfind; use Rtsfind;
48 with Sem_Aux; use Sem_Aux;
49 with Sem_Attr; use Sem_Attr;
50 with Sem_Ch6; use Sem_Ch6;
51 with Sem_Ch8; use Sem_Ch8;
52 with Sem_Ch12; use Sem_Ch12;
53 with Sem_Ch13; use Sem_Ch13;
54 with Sem_Disp; use Sem_Disp;
55 with Sem_Eval; use Sem_Eval;
56 with Sem_Prag; use Sem_Prag;
57 with Sem_Res; use Sem_Res;
58 with Sem_Warn; use Sem_Warn;
59 with Sem_Type; use Sem_Type;
60 with Sinfo; use Sinfo;
61 with Sinput; use Sinput;
62 with Stand; use Stand;
64 with Stringt; use Stringt;
65 with Targparm; use Targparm;
66 with Tbuild; use Tbuild;
67 with Ttypes; use Ttypes;
68 with Uname; use Uname;
70 with GNAT.HTable; use GNAT.HTable;
72 package body Sem_Util is
74 ----------------------------------------
75 -- Global Variables for New_Copy_Tree --
76 ----------------------------------------
78 -- These global variables are used by New_Copy_Tree. See description of the
79 -- body of this subprogram for details. Global variables can be safely used
80 -- by New_Copy_Tree, since there is no case of a recursive call from the
81 -- processing inside New_Copy_Tree.
83 NCT_Hash_Threshold : constant := 20;
84 -- If there are more than this number of pairs of entries in the map, then
85 -- Hash_Tables_Used will be set, and the hash tables will be initialized
86 -- and used for the searches.
88 NCT_Hash_Tables_Used : Boolean := False;
89 -- Set to True if hash tables are in use
91 NCT_Table_Entries : Nat := 0;
92 -- Count entries in table to see if threshold is reached
94 NCT_Hash_Table_Setup : Boolean := False;
95 -- Set to True if hash table contains data. We set this True if we setup
96 -- the hash table with data, and leave it set permanently from then on,
97 -- this is a signal that second and subsequent users of the hash table
98 -- must clear the old entries before reuse.
100 subtype NCT_Header_Num is Int range 0 .. 511;
101 -- Defines range of headers in hash tables (512 headers)
103 -----------------------
104 -- Local Subprograms --
105 -----------------------
107 function Build_Component_Subtype
110 T : Entity_Id) return Node_Id;
111 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
112 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
113 -- Loc is the source location, T is the original subtype.
115 function Has_Enabled_Property
116 (Item_Id : Entity_Id;
117 Property : Name_Id) return Boolean;
118 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
119 -- Determine whether an abstract state or a variable denoted by entity
120 -- Item_Id has enabled property Property.
122 function Has_Null_Extension (T : Entity_Id) return Boolean;
123 -- T is a derived tagged type. Check whether the type extension is null.
124 -- If the parent type is fully initialized, T can be treated as such.
126 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
127 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
128 -- with discriminants whose default values are static, examine only the
129 -- components in the selected variant to determine whether all of them
132 ------------------------------
133 -- Abstract_Interface_List --
134 ------------------------------
136 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
140 if Is_Concurrent_Type (Typ) then
142 -- If we are dealing with a synchronized subtype, go to the base
143 -- type, whose declaration has the interface list.
145 -- Shouldn't this be Declaration_Node???
147 Nod := Parent (Base_Type (Typ));
149 if Nkind (Nod) = N_Full_Type_Declaration then
153 elsif Ekind (Typ) = E_Record_Type_With_Private then
154 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
155 Nod := Type_Definition (Parent (Typ));
157 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
158 if Present (Full_View (Typ))
160 Nkind (Parent (Full_View (Typ))) = N_Full_Type_Declaration
162 Nod := Type_Definition (Parent (Full_View (Typ)));
164 -- If the full-view is not available we cannot do anything else
165 -- here (the source has errors).
171 -- Support for generic formals with interfaces is still missing ???
173 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
178 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
182 elsif Ekind (Typ) = E_Record_Subtype then
183 Nod := Type_Definition (Parent (Etype (Typ)));
185 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
187 -- Recurse, because parent may still be a private extension. Also
188 -- note that the full view of the subtype or the full view of its
189 -- base type may (both) be unavailable.
191 return Abstract_Interface_List (Etype (Typ));
193 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
194 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
195 Nod := Formal_Type_Definition (Parent (Typ));
197 Nod := Type_Definition (Parent (Typ));
201 return Interface_List (Nod);
202 end Abstract_Interface_List;
204 --------------------------------
205 -- Add_Access_Type_To_Process --
206 --------------------------------
208 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
212 Ensure_Freeze_Node (E);
213 L := Access_Types_To_Process (Freeze_Node (E));
217 Set_Access_Types_To_Process (Freeze_Node (E), L);
221 end Add_Access_Type_To_Process;
223 --------------------------
224 -- Add_Block_Identifier --
225 --------------------------
227 procedure Add_Block_Identifier (N : Node_Id; Id : out Entity_Id) is
228 Loc : constant Source_Ptr := Sloc (N);
231 pragma Assert (Nkind (N) = N_Block_Statement);
233 -- The block already has a label, return its entity
235 if Present (Identifier (N)) then
236 Id := Entity (Identifier (N));
238 -- Create a new block label and set its attributes
241 Id := New_Internal_Entity (E_Block, Current_Scope, Loc, 'B');
242 Set_Etype (Id, Standard_Void_Type);
245 Set_Identifier (N, New_Occurrence_Of (Id, Loc));
246 Set_Block_Node (Id, Identifier (N));
248 end Add_Block_Identifier;
250 -----------------------
251 -- Add_Contract_Item --
252 -----------------------
254 procedure Add_Contract_Item (Prag : Node_Id; Id : Entity_Id) is
255 Items : Node_Id := Contract (Id);
257 procedure Add_Classification;
258 -- Prepend Prag to the list of classifications
260 procedure Add_Contract_Test_Case;
261 -- Prepend Prag to the list of contract and test cases
263 procedure Add_Pre_Post_Condition;
264 -- Prepend Prag to the list of pre- and postconditions
266 ------------------------
267 -- Add_Classification --
268 ------------------------
270 procedure Add_Classification is
272 Set_Next_Pragma (Prag, Classifications (Items));
273 Set_Classifications (Items, Prag);
274 end Add_Classification;
276 ----------------------------
277 -- Add_Contract_Test_Case --
278 ----------------------------
280 procedure Add_Contract_Test_Case is
282 Set_Next_Pragma (Prag, Contract_Test_Cases (Items));
283 Set_Contract_Test_Cases (Items, Prag);
284 end Add_Contract_Test_Case;
286 ----------------------------
287 -- Add_Pre_Post_Condition --
288 ----------------------------
290 procedure Add_Pre_Post_Condition is
292 Set_Next_Pragma (Prag, Pre_Post_Conditions (Items));
293 Set_Pre_Post_Conditions (Items, Prag);
294 end Add_Pre_Post_Condition;
300 -- Start of processing for Add_Contract_Item
303 -- A contract must contain only pragmas
305 pragma Assert (Nkind (Prag) = N_Pragma);
306 Prag_Nam := Pragma_Name (Prag);
308 -- Create a new contract when adding the first item
311 Items := Make_Contract (Sloc (Id));
312 Set_Contract (Id, Items);
315 -- Contract items related to [generic] packages or instantiations. The
316 -- applicable pragmas are:
320 -- Part_Of (instantiation only)
322 if Ekind_In (Id, E_Generic_Package, E_Package) then
323 if Nam_In (Prag_Nam, Name_Abstract_State,
324 Name_Initial_Condition,
329 -- Indicator Part_Of must be associated with a package instantiation
331 elsif Prag_Nam = Name_Part_Of and then Is_Generic_Instance (Id) then
334 -- The pragma is not a proper contract item
340 -- Contract items related to package bodies. The applicable pragmas are:
343 elsif Ekind (Id) = E_Package_Body then
344 if Prag_Nam = Name_Refined_State then
347 -- The pragma is not a proper contract item
353 -- Contract items related to subprogram or entry declarations. The
354 -- applicable pragmas are:
357 -- Extensions_Visible
363 elsif Ekind_In (Id, E_Entry, E_Entry_Family)
364 or else Is_Generic_Subprogram (Id)
365 or else Is_Subprogram (Id)
367 if Nam_In (Prag_Nam, Name_Postcondition, Name_Precondition) then
368 Add_Pre_Post_Condition;
370 elsif Nam_In (Prag_Nam, Name_Contract_Cases, Name_Test_Case) then
371 Add_Contract_Test_Case;
373 elsif Nam_In (Prag_Nam, Name_Depends,
374 Name_Extensions_Visible,
379 -- The pragma is not a proper contract item
385 -- Contract items related to subprogram bodies. Applicable pragmas are:
392 elsif Ekind (Id) = E_Subprogram_Body then
393 if Nam_In (Prag_Nam, Name_Refined_Depends, Name_Refined_Global) then
396 elsif Nam_In (Prag_Nam, Name_Postcondition,
400 Add_Pre_Post_Condition;
402 -- The pragma is not a proper contract item
408 -- Contract items related to variables. Applicable pragmas are:
415 elsif Ekind (Id) = E_Variable then
416 if Nam_In (Prag_Nam, Name_Async_Readers,
418 Name_Effective_Reads,
419 Name_Effective_Writes,
424 -- The pragma is not a proper contract item
430 end Add_Contract_Item;
432 ----------------------------
433 -- Add_Global_Declaration --
434 ----------------------------
436 procedure Add_Global_Declaration (N : Node_Id) is
437 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
440 if No (Declarations (Aux_Node)) then
441 Set_Declarations (Aux_Node, New_List);
444 Append_To (Declarations (Aux_Node), N);
446 end Add_Global_Declaration;
448 --------------------------------
449 -- Address_Integer_Convert_OK --
450 --------------------------------
452 function Address_Integer_Convert_OK (T1, T2 : Entity_Id) return Boolean is
454 if Allow_Integer_Address
455 and then ((Is_Descendent_Of_Address (T1)
456 and then Is_Private_Type (T1)
457 and then Is_Integer_Type (T2))
459 (Is_Descendent_Of_Address (T2)
460 and then Is_Private_Type (T2)
461 and then Is_Integer_Type (T1)))
467 end Address_Integer_Convert_OK;
473 -- For now, just 8/16/32/64. but analyze later if AAMP is special???
475 function Addressable (V : Uint) return Boolean is
477 return V = Uint_8 or else
483 function Addressable (V : Int) return Boolean is
491 ---------------------------------
492 -- Aggregate_Constraint_Checks --
493 ---------------------------------
495 procedure Aggregate_Constraint_Checks
497 Check_Typ : Entity_Id)
499 Exp_Typ : constant Entity_Id := Etype (Exp);
502 if Raises_Constraint_Error (Exp) then
506 -- Ada 2005 (AI-230): Generate a conversion to an anonymous access
507 -- component's type to force the appropriate accessibility checks.
509 -- Ada 2005 (AI-231): Generate conversion to the null-excluding
510 -- type to force the corresponding run-time check
512 if Is_Access_Type (Check_Typ)
513 and then ((Is_Local_Anonymous_Access (Check_Typ))
514 or else (Can_Never_Be_Null (Check_Typ)
515 and then not Can_Never_Be_Null (Exp_Typ)))
517 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
518 Analyze_And_Resolve (Exp, Check_Typ);
519 Check_Unset_Reference (Exp);
522 -- This is really expansion activity, so make sure that expansion is
523 -- on and is allowed. In GNATprove mode, we also want check flags to
524 -- be added in the tree, so that the formal verification can rely on
525 -- those to be present. In GNATprove mode for formal verification, some
526 -- treatment typically only done during expansion needs to be performed
527 -- on the tree, but it should not be applied inside generics. Otherwise,
528 -- this breaks the name resolution mechanism for generic instances.
530 if not Expander_Active
531 and (Inside_A_Generic or not Full_Analysis or not GNATprove_Mode)
536 -- First check if we have to insert discriminant checks
538 if Has_Discriminants (Exp_Typ) then
539 Apply_Discriminant_Check (Exp, Check_Typ);
541 -- Next emit length checks for array aggregates
543 elsif Is_Array_Type (Exp_Typ) then
544 Apply_Length_Check (Exp, Check_Typ);
546 -- Finally emit scalar and string checks. If we are dealing with a
547 -- scalar literal we need to check by hand because the Etype of
548 -- literals is not necessarily correct.
550 elsif Is_Scalar_Type (Exp_Typ)
551 and then Compile_Time_Known_Value (Exp)
553 if Is_Out_Of_Range (Exp, Base_Type (Check_Typ)) then
554 Apply_Compile_Time_Constraint_Error
555 (Exp, "value not in range of}??", CE_Range_Check_Failed,
556 Ent => Base_Type (Check_Typ),
557 Typ => Base_Type (Check_Typ));
559 elsif Is_Out_Of_Range (Exp, Check_Typ) then
560 Apply_Compile_Time_Constraint_Error
561 (Exp, "value not in range of}??", CE_Range_Check_Failed,
565 elsif not Range_Checks_Suppressed (Check_Typ) then
566 Apply_Scalar_Range_Check (Exp, Check_Typ);
569 -- Verify that target type is also scalar, to prevent view anomalies
570 -- in instantiations.
572 elsif (Is_Scalar_Type (Exp_Typ)
573 or else Nkind (Exp) = N_String_Literal)
574 and then Is_Scalar_Type (Check_Typ)
575 and then Exp_Typ /= Check_Typ
577 if Is_Entity_Name (Exp)
578 and then Ekind (Entity (Exp)) = E_Constant
580 -- If expression is a constant, it is worthwhile checking whether
581 -- it is a bound of the type.
583 if (Is_Entity_Name (Type_Low_Bound (Check_Typ))
584 and then Entity (Exp) = Entity (Type_Low_Bound (Check_Typ)))
586 (Is_Entity_Name (Type_High_Bound (Check_Typ))
587 and then Entity (Exp) = Entity (Type_High_Bound (Check_Typ)))
592 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
593 Analyze_And_Resolve (Exp, Check_Typ);
594 Check_Unset_Reference (Exp);
597 -- Could use a comment on this case ???
600 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
601 Analyze_And_Resolve (Exp, Check_Typ);
602 Check_Unset_Reference (Exp);
606 end Aggregate_Constraint_Checks;
608 -----------------------
609 -- Alignment_In_Bits --
610 -----------------------
612 function Alignment_In_Bits (E : Entity_Id) return Uint is
614 return Alignment (E) * System_Storage_Unit;
615 end Alignment_In_Bits;
617 ---------------------------------
618 -- Append_Inherited_Subprogram --
619 ---------------------------------
621 procedure Append_Inherited_Subprogram (S : Entity_Id) is
622 Par : constant Entity_Id := Alias (S);
623 -- The parent subprogram
625 Scop : constant Entity_Id := Scope (Par);
626 -- The scope of definition of the parent subprogram
628 Typ : constant Entity_Id := Defining_Entity (Parent (S));
629 -- The derived type of which S is a primitive operation
635 if Ekind (Current_Scope) = E_Package
636 and then In_Private_Part (Current_Scope)
637 and then Has_Private_Declaration (Typ)
638 and then Is_Tagged_Type (Typ)
639 and then Scop = Current_Scope
641 -- The inherited operation is available at the earliest place after
642 -- the derived type declaration ( RM 7.3.1 (6/1)). This is only
643 -- relevant for type extensions. If the parent operation appears
644 -- after the type extension, the operation is not visible.
647 (Visible_Declarations
648 (Package_Specification (Current_Scope)));
649 while Present (Decl) loop
650 if Nkind (Decl) = N_Private_Extension_Declaration
651 and then Defining_Entity (Decl) = Typ
653 if Sloc (Decl) > Sloc (Par) then
654 Next_E := Next_Entity (Par);
655 Set_Next_Entity (Par, S);
656 Set_Next_Entity (S, Next_E);
668 -- If partial view is not a type extension, or it appears before the
669 -- subprogram declaration, insert normally at end of entity list.
671 Append_Entity (S, Current_Scope);
672 end Append_Inherited_Subprogram;
674 -----------------------------------------
675 -- Apply_Compile_Time_Constraint_Error --
676 -----------------------------------------
678 procedure Apply_Compile_Time_Constraint_Error
681 Reason : RT_Exception_Code;
682 Ent : Entity_Id := Empty;
683 Typ : Entity_Id := Empty;
684 Loc : Source_Ptr := No_Location;
685 Rep : Boolean := True;
686 Warn : Boolean := False)
688 Stat : constant Boolean := Is_Static_Expression (N);
689 R_Stat : constant Node_Id :=
690 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
701 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
707 -- Now we replace the node by an N_Raise_Constraint_Error node
708 -- This does not need reanalyzing, so set it as analyzed now.
711 Set_Analyzed (N, True);
714 Set_Raises_Constraint_Error (N);
716 -- Now deal with possible local raise handling
718 Possible_Local_Raise (N, Standard_Constraint_Error);
720 -- If the original expression was marked as static, the result is
721 -- still marked as static, but the Raises_Constraint_Error flag is
722 -- always set so that further static evaluation is not attempted.
725 Set_Is_Static_Expression (N);
727 end Apply_Compile_Time_Constraint_Error;
729 ---------------------------
730 -- Async_Readers_Enabled --
731 ---------------------------
733 function Async_Readers_Enabled (Id : Entity_Id) return Boolean is
735 return Has_Enabled_Property (Id, Name_Async_Readers);
736 end Async_Readers_Enabled;
738 ---------------------------
739 -- Async_Writers_Enabled --
740 ---------------------------
742 function Async_Writers_Enabled (Id : Entity_Id) return Boolean is
744 return Has_Enabled_Property (Id, Name_Async_Writers);
745 end Async_Writers_Enabled;
747 --------------------------------------
748 -- Available_Full_View_Of_Component --
749 --------------------------------------
751 function Available_Full_View_Of_Component (T : Entity_Id) return Boolean is
752 ST : constant Entity_Id := Scope (T);
753 SCT : constant Entity_Id := Scope (Component_Type (T));
755 return In_Open_Scopes (ST)
756 and then In_Open_Scopes (SCT)
757 and then Scope_Depth (ST) >= Scope_Depth (SCT);
758 end Available_Full_View_Of_Component;
764 procedure Bad_Attribute
767 Warn : Boolean := False)
770 Error_Msg_Warn := Warn;
771 Error_Msg_N ("unrecognized attribute&<<", N);
773 -- Check for possible misspelling
775 Error_Msg_Name_1 := First_Attribute_Name;
776 while Error_Msg_Name_1 <= Last_Attribute_Name loop
777 if Is_Bad_Spelling_Of (Nam, Error_Msg_Name_1) then
778 Error_Msg_N -- CODEFIX
779 ("\possible misspelling of %<<", N);
783 Error_Msg_Name_1 := Error_Msg_Name_1 + 1;
787 --------------------------------
788 -- Bad_Predicated_Subtype_Use --
789 --------------------------------
791 procedure Bad_Predicated_Subtype_Use
795 Suggest_Static : Boolean := False)
800 -- Avoid cascaded errors
802 if Error_Posted (N) then
806 if Inside_A_Generic then
807 Gen := Current_Scope;
808 while Present (Gen) and then Ekind (Gen) /= E_Generic_Package loop
816 if Is_Generic_Formal (Typ) and then Is_Discrete_Type (Typ) then
817 Set_No_Predicate_On_Actual (Typ);
820 elsif Has_Predicates (Typ) then
821 if Is_Generic_Actual_Type (Typ) then
823 -- The restriction on loop parameters is only that the type
824 -- should have no dynamic predicates.
826 if Nkind (Parent (N)) = N_Loop_Parameter_Specification
827 and then not Has_Dynamic_Predicate_Aspect (Typ)
828 and then Is_OK_Static_Subtype (Typ)
833 Gen := Current_Scope;
834 while not Is_Generic_Instance (Gen) loop
838 pragma Assert (Present (Gen));
840 if Ekind (Gen) = E_Package and then In_Package_Body (Gen) then
841 Error_Msg_Warn := SPARK_Mode /= On;
842 Error_Msg_FE (Msg & "<<", N, Typ);
843 Error_Msg_F ("\Program_Error [<<", N);
846 Make_Raise_Program_Error (Sloc (N),
847 Reason => PE_Bad_Predicated_Generic_Type));
850 Error_Msg_FE (Msg & "<<", N, Typ);
854 Error_Msg_FE (Msg, N, Typ);
857 -- Emit an optional suggestion on how to remedy the error if the
858 -- context warrants it.
860 if Suggest_Static and then Has_Static_Predicate (Typ) then
861 Error_Msg_FE ("\predicate of & should be marked static", N, Typ);
864 end Bad_Predicated_Subtype_Use;
866 -----------------------------------------
867 -- Bad_Unordered_Enumeration_Reference --
868 -----------------------------------------
870 function Bad_Unordered_Enumeration_Reference
872 T : Entity_Id) return Boolean
875 return Is_Enumeration_Type (T)
876 and then Warn_On_Unordered_Enumeration_Type
877 and then not Is_Generic_Type (T)
878 and then Comes_From_Source (N)
879 and then not Has_Pragma_Ordered (T)
880 and then not In_Same_Extended_Unit (N, T);
881 end Bad_Unordered_Enumeration_Reference;
883 --------------------------
884 -- Build_Actual_Subtype --
885 --------------------------
887 function Build_Actual_Subtype
889 N : Node_Or_Entity_Id) return Node_Id
892 -- Normally Sloc (N), but may point to corresponding body in some cases
894 Constraints : List_Id;
900 Disc_Type : Entity_Id;
906 if Nkind (N) = N_Defining_Identifier then
907 Obj := New_Occurrence_Of (N, Loc);
909 -- If this is a formal parameter of a subprogram declaration, and
910 -- we are compiling the body, we want the declaration for the
911 -- actual subtype to carry the source position of the body, to
912 -- prevent anomalies in gdb when stepping through the code.
914 if Is_Formal (N) then
916 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
918 if Nkind (Decl) = N_Subprogram_Declaration
919 and then Present (Corresponding_Body (Decl))
921 Loc := Sloc (Corresponding_Body (Decl));
930 if Is_Array_Type (T) then
931 Constraints := New_List;
932 for J in 1 .. Number_Dimensions (T) loop
934 -- Build an array subtype declaration with the nominal subtype and
935 -- the bounds of the actual. Add the declaration in front of the
936 -- local declarations for the subprogram, for analysis before any
937 -- reference to the formal in the body.
940 Make_Attribute_Reference (Loc,
942 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
943 Attribute_Name => Name_First,
944 Expressions => New_List (
945 Make_Integer_Literal (Loc, J)));
948 Make_Attribute_Reference (Loc,
950 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
951 Attribute_Name => Name_Last,
952 Expressions => New_List (
953 Make_Integer_Literal (Loc, J)));
955 Append (Make_Range (Loc, Lo, Hi), Constraints);
958 -- If the type has unknown discriminants there is no constrained
959 -- subtype to build. This is never called for a formal or for a
960 -- lhs, so returning the type is ok ???
962 elsif Has_Unknown_Discriminants (T) then
966 Constraints := New_List;
968 -- Type T is a generic derived type, inherit the discriminants from
971 if Is_Private_Type (T)
972 and then No (Full_View (T))
974 -- T was flagged as an error if it was declared as a formal
975 -- derived type with known discriminants. In this case there
976 -- is no need to look at the parent type since T already carries
977 -- its own discriminants.
979 and then not Error_Posted (T)
981 Disc_Type := Etype (Base_Type (T));
986 Discr := First_Discriminant (Disc_Type);
987 while Present (Discr) loop
988 Append_To (Constraints,
989 Make_Selected_Component (Loc,
991 Duplicate_Subexpr_No_Checks (Obj),
992 Selector_Name => New_Occurrence_Of (Discr, Loc)));
993 Next_Discriminant (Discr);
997 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
998 Set_Is_Internal (Subt);
1001 Make_Subtype_Declaration (Loc,
1002 Defining_Identifier => Subt,
1003 Subtype_Indication =>
1004 Make_Subtype_Indication (Loc,
1005 Subtype_Mark => New_Occurrence_Of (T, Loc),
1007 Make_Index_Or_Discriminant_Constraint (Loc,
1008 Constraints => Constraints)));
1010 Mark_Rewrite_Insertion (Decl);
1012 end Build_Actual_Subtype;
1014 ---------------------------------------
1015 -- Build_Actual_Subtype_Of_Component --
1016 ---------------------------------------
1018 function Build_Actual_Subtype_Of_Component
1020 N : Node_Id) return Node_Id
1022 Loc : constant Source_Ptr := Sloc (N);
1023 P : constant Node_Id := Prefix (N);
1026 Index_Typ : Entity_Id;
1028 Desig_Typ : Entity_Id;
1029 -- This is either a copy of T, or if T is an access type, then it is
1030 -- the directly designated type of this access type.
1032 function Build_Actual_Array_Constraint return List_Id;
1033 -- If one or more of the bounds of the component depends on
1034 -- discriminants, build actual constraint using the discriminants
1037 function Build_Actual_Record_Constraint return List_Id;
1038 -- Similar to previous one, for discriminated components constrained
1039 -- by the discriminant of the enclosing object.
1041 -----------------------------------
1042 -- Build_Actual_Array_Constraint --
1043 -----------------------------------
1045 function Build_Actual_Array_Constraint return List_Id is
1046 Constraints : constant List_Id := New_List;
1054 Indx := First_Index (Desig_Typ);
1055 while Present (Indx) loop
1056 Old_Lo := Type_Low_Bound (Etype (Indx));
1057 Old_Hi := Type_High_Bound (Etype (Indx));
1059 if Denotes_Discriminant (Old_Lo) then
1061 Make_Selected_Component (Loc,
1062 Prefix => New_Copy_Tree (P),
1063 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
1066 Lo := New_Copy_Tree (Old_Lo);
1068 -- The new bound will be reanalyzed in the enclosing
1069 -- declaration. For literal bounds that come from a type
1070 -- declaration, the type of the context must be imposed, so
1071 -- insure that analysis will take place. For non-universal
1072 -- types this is not strictly necessary.
1074 Set_Analyzed (Lo, False);
1077 if Denotes_Discriminant (Old_Hi) then
1079 Make_Selected_Component (Loc,
1080 Prefix => New_Copy_Tree (P),
1081 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
1084 Hi := New_Copy_Tree (Old_Hi);
1085 Set_Analyzed (Hi, False);
1088 Append (Make_Range (Loc, Lo, Hi), Constraints);
1093 end Build_Actual_Array_Constraint;
1095 ------------------------------------
1096 -- Build_Actual_Record_Constraint --
1097 ------------------------------------
1099 function Build_Actual_Record_Constraint return List_Id is
1100 Constraints : constant List_Id := New_List;
1105 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1106 while Present (D) loop
1107 if Denotes_Discriminant (Node (D)) then
1108 D_Val := Make_Selected_Component (Loc,
1109 Prefix => New_Copy_Tree (P),
1110 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
1113 D_Val := New_Copy_Tree (Node (D));
1116 Append (D_Val, Constraints);
1121 end Build_Actual_Record_Constraint;
1123 -- Start of processing for Build_Actual_Subtype_Of_Component
1126 -- Why the test for Spec_Expression mode here???
1128 if In_Spec_Expression then
1131 -- More comments for the rest of this body would be good ???
1133 elsif Nkind (N) = N_Explicit_Dereference then
1134 if Is_Composite_Type (T)
1135 and then not Is_Constrained (T)
1136 and then not (Is_Class_Wide_Type (T)
1137 and then Is_Constrained (Root_Type (T)))
1138 and then not Has_Unknown_Discriminants (T)
1140 -- If the type of the dereference is already constrained, it is an
1143 if Is_Array_Type (Etype (N))
1144 and then Is_Constrained (Etype (N))
1148 Remove_Side_Effects (P);
1149 return Build_Actual_Subtype (T, N);
1156 if Ekind (T) = E_Access_Subtype then
1157 Desig_Typ := Designated_Type (T);
1162 if Ekind (Desig_Typ) = E_Array_Subtype then
1163 Id := First_Index (Desig_Typ);
1164 while Present (Id) loop
1165 Index_Typ := Underlying_Type (Etype (Id));
1167 if Denotes_Discriminant (Type_Low_Bound (Index_Typ))
1169 Denotes_Discriminant (Type_High_Bound (Index_Typ))
1171 Remove_Side_Effects (P);
1173 Build_Component_Subtype
1174 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
1180 elsif Is_Composite_Type (Desig_Typ)
1181 and then Has_Discriminants (Desig_Typ)
1182 and then not Has_Unknown_Discriminants (Desig_Typ)
1184 if Is_Private_Type (Desig_Typ)
1185 and then No (Discriminant_Constraint (Desig_Typ))
1187 Desig_Typ := Full_View (Desig_Typ);
1190 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1191 while Present (D) loop
1192 if Denotes_Discriminant (Node (D)) then
1193 Remove_Side_Effects (P);
1195 Build_Component_Subtype (
1196 Build_Actual_Record_Constraint, Loc, Base_Type (T));
1203 -- If none of the above, the actual and nominal subtypes are the same
1206 end Build_Actual_Subtype_Of_Component;
1208 -----------------------------
1209 -- Build_Component_Subtype --
1210 -----------------------------
1212 function Build_Component_Subtype
1215 T : Entity_Id) return Node_Id
1221 -- Unchecked_Union components do not require component subtypes
1223 if Is_Unchecked_Union (T) then
1227 Subt := Make_Temporary (Loc, 'S');
1228 Set_Is_Internal (Subt);
1231 Make_Subtype_Declaration (Loc,
1232 Defining_Identifier => Subt,
1233 Subtype_Indication =>
1234 Make_Subtype_Indication (Loc,
1235 Subtype_Mark => New_Occurrence_Of (Base_Type (T), Loc),
1237 Make_Index_Or_Discriminant_Constraint (Loc,
1238 Constraints => C)));
1240 Mark_Rewrite_Insertion (Decl);
1242 end Build_Component_Subtype;
1244 ----------------------------------
1245 -- Build_Default_Init_Cond_Call --
1246 ----------------------------------
1248 function Build_Default_Init_Cond_Call
1251 Typ : Entity_Id) return Node_Id
1253 Proc_Id : constant Entity_Id := Default_Init_Cond_Procedure (Typ);
1254 Formal_Typ : constant Entity_Id := Etype (First_Formal (Proc_Id));
1258 Make_Procedure_Call_Statement (Loc,
1259 Name => New_Occurrence_Of (Proc_Id, Loc),
1260 Parameter_Associations => New_List (
1261 Make_Unchecked_Type_Conversion (Loc,
1262 Subtype_Mark => New_Occurrence_Of (Formal_Typ, Loc),
1263 Expression => New_Occurrence_Of (Obj_Id, Loc))));
1264 end Build_Default_Init_Cond_Call;
1266 ----------------------------------------------
1267 -- Build_Default_Init_Cond_Procedure_Bodies --
1268 ----------------------------------------------
1270 procedure Build_Default_Init_Cond_Procedure_Bodies (Priv_Decls : List_Id) is
1271 procedure Build_Default_Init_Cond_Procedure_Body (Typ : Entity_Id);
1272 -- If type Typ is subject to pragma Default_Initial_Condition, build the
1273 -- body of the procedure which verifies the assumption of the pragma at
1274 -- run time. The generated body is added after the type declaration.
1276 --------------------------------------------
1277 -- Build_Default_Init_Cond_Procedure_Body --
1278 --------------------------------------------
1280 procedure Build_Default_Init_Cond_Procedure_Body (Typ : Entity_Id) is
1281 Param_Id : Entity_Id;
1282 -- The entity of the sole formal parameter of the default initial
1283 -- condition procedure.
1285 procedure Replace_Type_Reference (N : Node_Id);
1286 -- Replace a single reference to type Typ with a reference to formal
1287 -- parameter Param_Id.
1289 ----------------------------
1290 -- Replace_Type_Reference --
1291 ----------------------------
1293 procedure Replace_Type_Reference (N : Node_Id) is
1295 Rewrite (N, New_Occurrence_Of (Param_Id, Sloc (N)));
1296 end Replace_Type_Reference;
1298 procedure Replace_Type_References is
1299 new Replace_Type_References_Generic (Replace_Type_Reference);
1303 Loc : constant Source_Ptr := Sloc (Typ);
1304 Prag : constant Node_Id :=
1305 Get_Pragma (Typ, Pragma_Default_Initial_Condition);
1306 Proc_Id : constant Entity_Id := Default_Init_Cond_Procedure (Typ);
1307 Spec_Decl : constant Node_Id := Unit_Declaration_Node (Proc_Id);
1308 Body_Decl : Node_Id;
1312 -- Start of processing for Build_Default_Init_Cond_Procedure_Body
1315 -- The procedure should be generated only for [sub]types subject to
1316 -- pragma Default_Initial_Condition. Types that inherit the pragma do
1317 -- not get this specialized procedure.
1319 pragma Assert (Has_Default_Init_Cond (Typ));
1320 pragma Assert (Present (Prag));
1321 pragma Assert (Present (Proc_Id));
1323 -- Nothing to do if the body was already built
1325 if Present (Corresponding_Body (Spec_Decl)) then
1329 Param_Id := First_Formal (Proc_Id);
1331 -- The pragma has an argument. Note that the argument is analyzed
1332 -- after all references to the current instance of the type are
1335 if Present (Pragma_Argument_Associations (Prag)) then
1337 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
1339 if Nkind (Expr) = N_Null then
1340 Stmt := Make_Null_Statement (Loc);
1342 -- Preserve the original argument of the pragma by replicating it.
1343 -- Replace all references to the current instance of the type with
1344 -- references to the formal parameter.
1347 Expr := New_Copy_Tree (Expr);
1348 Replace_Type_References (Expr, Typ);
1351 -- pragma Check (Default_Initial_Condition, <Expr>);
1355 Pragma_Identifier =>
1356 Make_Identifier (Loc, Name_Check),
1358 Pragma_Argument_Associations => New_List (
1359 Make_Pragma_Argument_Association (Loc,
1361 Make_Identifier (Loc,
1362 Chars => Name_Default_Initial_Condition)),
1363 Make_Pragma_Argument_Association (Loc,
1364 Expression => Expr)));
1367 -- Otherwise the pragma appears without an argument
1370 Stmt := Make_Null_Statement (Loc);
1374 -- procedure <Typ>Default_Init_Cond (I : <Typ>) is
1377 -- end <Typ>Default_Init_Cond;
1380 Make_Subprogram_Body (Loc,
1382 Copy_Separate_Tree (Specification (Spec_Decl)),
1383 Declarations => Empty_List,
1384 Handled_Statement_Sequence =>
1385 Make_Handled_Sequence_Of_Statements (Loc,
1386 Statements => New_List (Stmt)));
1388 -- Link the spec and body of the default initial condition procedure
1389 -- to prevent the generation of a duplicate body.
1391 Set_Corresponding_Body (Spec_Decl, Defining_Entity (Body_Decl));
1392 Set_Corresponding_Spec (Body_Decl, Proc_Id);
1394 Insert_After_And_Analyze (Declaration_Node (Typ), Body_Decl);
1395 end Build_Default_Init_Cond_Procedure_Body;
1402 -- Start of processing for Build_Default_Init_Cond_Procedure_Bodies
1405 -- Inspect the private declarations looking for [sub]type declarations
1407 Decl := First (Priv_Decls);
1408 while Present (Decl) loop
1409 if Nkind_In (Decl, N_Full_Type_Declaration,
1410 N_Subtype_Declaration)
1412 Typ := Defining_Entity (Decl);
1414 -- Guard against partially decorate types due to previous errors
1416 if Is_Type (Typ) then
1418 -- If the type is subject to pragma Default_Initial_Condition,
1419 -- generate the body of the internal procedure which verifies
1420 -- the assertion of the pragma at run time.
1422 if Has_Default_Init_Cond (Typ) then
1423 Build_Default_Init_Cond_Procedure_Body (Typ);
1425 -- A derived type inherits the default initial condition
1426 -- procedure from its parent type.
1428 elsif Has_Inherited_Default_Init_Cond (Typ) then
1429 Inherit_Default_Init_Cond_Procedure (Typ);
1436 end Build_Default_Init_Cond_Procedure_Bodies;
1438 ---------------------------------------------------
1439 -- Build_Default_Init_Cond_Procedure_Declaration --
1440 ---------------------------------------------------
1442 procedure Build_Default_Init_Cond_Procedure_Declaration (Typ : Entity_Id) is
1443 Loc : constant Source_Ptr := Sloc (Typ);
1444 Prag : constant Node_Id :=
1445 Get_Pragma (Typ, Pragma_Default_Initial_Condition);
1446 Proc_Id : Entity_Id;
1449 -- The procedure should be generated only for types subject to pragma
1450 -- Default_Initial_Condition. Types that inherit the pragma do not get
1451 -- this specialized procedure.
1453 pragma Assert (Has_Default_Init_Cond (Typ));
1454 pragma Assert (Present (Prag));
1456 -- Nothing to do if default initial condition procedure already built
1458 if Present (Default_Init_Cond_Procedure (Typ)) then
1463 Make_Defining_Identifier (Loc,
1464 Chars => New_External_Name (Chars (Typ), "Default_Init_Cond"));
1466 -- Associate default initial condition procedure with the private type
1468 Set_Ekind (Proc_Id, E_Procedure);
1469 Set_Is_Default_Init_Cond_Procedure (Proc_Id);
1470 Set_Default_Init_Cond_Procedure (Typ, Proc_Id);
1473 -- procedure <Typ>Default_Init_Cond (Inn : <Typ>);
1475 Insert_After_And_Analyze (Prag,
1476 Make_Subprogram_Declaration (Loc,
1478 Make_Procedure_Specification (Loc,
1479 Defining_Unit_Name => Proc_Id,
1480 Parameter_Specifications => New_List (
1481 Make_Parameter_Specification (Loc,
1482 Defining_Identifier => Make_Temporary (Loc, 'I'),
1483 Parameter_Type => New_Occurrence_Of (Typ, Loc))))));
1484 end Build_Default_Init_Cond_Procedure_Declaration;
1486 ---------------------------
1487 -- Build_Default_Subtype --
1488 ---------------------------
1490 function Build_Default_Subtype
1492 N : Node_Id) return Entity_Id
1494 Loc : constant Source_Ptr := Sloc (N);
1498 -- The base type that is to be constrained by the defaults
1501 if not Has_Discriminants (T) or else Is_Constrained (T) then
1505 Bas := Base_Type (T);
1507 -- If T is non-private but its base type is private, this is the
1508 -- completion of a subtype declaration whose parent type is private
1509 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1510 -- are to be found in the full view of the base. Check that the private
1511 -- status of T and its base differ.
1513 if Is_Private_Type (Bas)
1514 and then not Is_Private_Type (T)
1515 and then Present (Full_View (Bas))
1517 Bas := Full_View (Bas);
1520 Disc := First_Discriminant (T);
1522 if No (Discriminant_Default_Value (Disc)) then
1527 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
1528 Constraints : constant List_Id := New_List;
1532 while Present (Disc) loop
1533 Append_To (Constraints,
1534 New_Copy_Tree (Discriminant_Default_Value (Disc)));
1535 Next_Discriminant (Disc);
1539 Make_Subtype_Declaration (Loc,
1540 Defining_Identifier => Act,
1541 Subtype_Indication =>
1542 Make_Subtype_Indication (Loc,
1543 Subtype_Mark => New_Occurrence_Of (Bas, Loc),
1545 Make_Index_Or_Discriminant_Constraint (Loc,
1546 Constraints => Constraints)));
1548 Insert_Action (N, Decl);
1550 -- If the context is a component declaration the subtype declaration
1551 -- will be analyzed when the enclosing type is frozen, otherwise do
1554 if Ekind (Current_Scope) /= E_Record_Type then
1560 end Build_Default_Subtype;
1562 --------------------------------------------
1563 -- Build_Discriminal_Subtype_Of_Component --
1564 --------------------------------------------
1566 function Build_Discriminal_Subtype_Of_Component
1567 (T : Entity_Id) return Node_Id
1569 Loc : constant Source_Ptr := Sloc (T);
1573 function Build_Discriminal_Array_Constraint return List_Id;
1574 -- If one or more of the bounds of the component depends on
1575 -- discriminants, build actual constraint using the discriminants
1578 function Build_Discriminal_Record_Constraint return List_Id;
1579 -- Similar to previous one, for discriminated components constrained by
1580 -- the discriminant of the enclosing object.
1582 ----------------------------------------
1583 -- Build_Discriminal_Array_Constraint --
1584 ----------------------------------------
1586 function Build_Discriminal_Array_Constraint return List_Id is
1587 Constraints : constant List_Id := New_List;
1595 Indx := First_Index (T);
1596 while Present (Indx) loop
1597 Old_Lo := Type_Low_Bound (Etype (Indx));
1598 Old_Hi := Type_High_Bound (Etype (Indx));
1600 if Denotes_Discriminant (Old_Lo) then
1601 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
1604 Lo := New_Copy_Tree (Old_Lo);
1607 if Denotes_Discriminant (Old_Hi) then
1608 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
1611 Hi := New_Copy_Tree (Old_Hi);
1614 Append (Make_Range (Loc, Lo, Hi), Constraints);
1619 end Build_Discriminal_Array_Constraint;
1621 -----------------------------------------
1622 -- Build_Discriminal_Record_Constraint --
1623 -----------------------------------------
1625 function Build_Discriminal_Record_Constraint return List_Id is
1626 Constraints : constant List_Id := New_List;
1631 D := First_Elmt (Discriminant_Constraint (T));
1632 while Present (D) loop
1633 if Denotes_Discriminant (Node (D)) then
1635 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
1637 D_Val := New_Copy_Tree (Node (D));
1640 Append (D_Val, Constraints);
1645 end Build_Discriminal_Record_Constraint;
1647 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1650 if Ekind (T) = E_Array_Subtype then
1651 Id := First_Index (T);
1652 while Present (Id) loop
1653 if Denotes_Discriminant (Type_Low_Bound (Etype (Id)))
1655 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
1657 return Build_Component_Subtype
1658 (Build_Discriminal_Array_Constraint, Loc, T);
1664 elsif Ekind (T) = E_Record_Subtype
1665 and then Has_Discriminants (T)
1666 and then not Has_Unknown_Discriminants (T)
1668 D := First_Elmt (Discriminant_Constraint (T));
1669 while Present (D) loop
1670 if Denotes_Discriminant (Node (D)) then
1671 return Build_Component_Subtype
1672 (Build_Discriminal_Record_Constraint, Loc, T);
1679 -- If none of the above, the actual and nominal subtypes are the same
1682 end Build_Discriminal_Subtype_Of_Component;
1684 ------------------------------
1685 -- Build_Elaboration_Entity --
1686 ------------------------------
1688 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
1689 Loc : constant Source_Ptr := Sloc (N);
1691 Elab_Ent : Entity_Id;
1693 procedure Set_Package_Name (Ent : Entity_Id);
1694 -- Given an entity, sets the fully qualified name of the entity in
1695 -- Name_Buffer, with components separated by double underscores. This
1696 -- is a recursive routine that climbs the scope chain to Standard.
1698 ----------------------
1699 -- Set_Package_Name --
1700 ----------------------
1702 procedure Set_Package_Name (Ent : Entity_Id) is
1704 if Scope (Ent) /= Standard_Standard then
1705 Set_Package_Name (Scope (Ent));
1708 Nam : constant String := Get_Name_String (Chars (Ent));
1710 Name_Buffer (Name_Len + 1) := '_';
1711 Name_Buffer (Name_Len + 2) := '_';
1712 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
1713 Name_Len := Name_Len + Nam'Length + 2;
1717 Get_Name_String (Chars (Ent));
1719 end Set_Package_Name;
1721 -- Start of processing for Build_Elaboration_Entity
1724 -- Ignore call if already constructed
1726 if Present (Elaboration_Entity (Spec_Id)) then
1729 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1730 -- no role in analysis.
1732 elsif ASIS_Mode then
1735 -- See if we need elaboration entity. We always need it for the dynamic
1736 -- elaboration model, since it is needed to properly generate the PE
1737 -- exception for access before elaboration.
1739 elsif Dynamic_Elaboration_Checks then
1742 -- For the static model, we don't need the elaboration counter if this
1743 -- unit is sure to have no elaboration code, since that means there
1744 -- is no elaboration unit to be called. Note that we can't just decide
1745 -- after the fact by looking to see whether there was elaboration code,
1746 -- because that's too late to make this decision.
1748 elsif Restriction_Active (No_Elaboration_Code) then
1751 -- Similarly, for the static model, we can skip the elaboration counter
1752 -- if we have the No_Multiple_Elaboration restriction, since for the
1753 -- static model, that's the only purpose of the counter (to avoid
1754 -- multiple elaboration).
1756 elsif Restriction_Active (No_Multiple_Elaboration) then
1760 -- Here we need the elaboration entity
1762 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1763 -- name with dots replaced by double underscore. We have to manually
1764 -- construct this name, since it will be elaborated in the outer scope,
1765 -- and thus will not have the unit name automatically prepended.
1767 Set_Package_Name (Spec_Id);
1768 Add_Str_To_Name_Buffer ("_E");
1770 -- Create elaboration counter
1772 Elab_Ent := Make_Defining_Identifier (Loc, Chars => Name_Find);
1773 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
1776 Make_Object_Declaration (Loc,
1777 Defining_Identifier => Elab_Ent,
1778 Object_Definition =>
1779 New_Occurrence_Of (Standard_Short_Integer, Loc),
1780 Expression => Make_Integer_Literal (Loc, Uint_0));
1782 Push_Scope (Standard_Standard);
1783 Add_Global_Declaration (Decl);
1786 -- Reset True_Constant indication, since we will indeed assign a value
1787 -- to the variable in the binder main. We also kill the Current_Value
1788 -- and Last_Assignment fields for the same reason.
1790 Set_Is_True_Constant (Elab_Ent, False);
1791 Set_Current_Value (Elab_Ent, Empty);
1792 Set_Last_Assignment (Elab_Ent, Empty);
1794 -- We do not want any further qualification of the name (if we did not
1795 -- do this, we would pick up the name of the generic package in the case
1796 -- of a library level generic instantiation).
1798 Set_Has_Qualified_Name (Elab_Ent);
1799 Set_Has_Fully_Qualified_Name (Elab_Ent);
1800 end Build_Elaboration_Entity;
1802 --------------------------------
1803 -- Build_Explicit_Dereference --
1804 --------------------------------
1806 procedure Build_Explicit_Dereference
1810 Loc : constant Source_Ptr := Sloc (Expr);
1813 -- An entity of a type with a reference aspect is overloaded with
1814 -- both interpretations: with and without the dereference. Now that
1815 -- the dereference is made explicit, set the type of the node properly,
1816 -- to prevent anomalies in the backend. Same if the expression is an
1817 -- overloaded function call whose return type has a reference aspect.
1819 if Is_Entity_Name (Expr) then
1820 Set_Etype (Expr, Etype (Entity (Expr)));
1822 elsif Nkind (Expr) = N_Function_Call then
1823 Set_Etype (Expr, Etype (Name (Expr)));
1826 Set_Is_Overloaded (Expr, False);
1828 -- The expression will often be a generalized indexing that yields a
1829 -- container element that is then dereferenced, in which case the
1830 -- generalized indexing call is also non-overloaded.
1832 if Nkind (Expr) = N_Indexed_Component
1833 and then Present (Generalized_Indexing (Expr))
1835 Set_Is_Overloaded (Generalized_Indexing (Expr), False);
1839 Make_Explicit_Dereference (Loc,
1841 Make_Selected_Component (Loc,
1842 Prefix => Relocate_Node (Expr),
1843 Selector_Name => New_Occurrence_Of (Disc, Loc))));
1844 Set_Etype (Prefix (Expr), Etype (Disc));
1845 Set_Etype (Expr, Designated_Type (Etype (Disc)));
1846 end Build_Explicit_Dereference;
1848 -----------------------------------
1849 -- Cannot_Raise_Constraint_Error --
1850 -----------------------------------
1852 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
1854 if Compile_Time_Known_Value (Expr) then
1857 elsif Do_Range_Check (Expr) then
1860 elsif Raises_Constraint_Error (Expr) then
1864 case Nkind (Expr) is
1865 when N_Identifier =>
1868 when N_Expanded_Name =>
1871 when N_Selected_Component =>
1872 return not Do_Discriminant_Check (Expr);
1874 when N_Attribute_Reference =>
1875 if Do_Overflow_Check (Expr) then
1878 elsif No (Expressions (Expr)) then
1886 N := First (Expressions (Expr));
1887 while Present (N) loop
1888 if Cannot_Raise_Constraint_Error (N) then
1899 when N_Type_Conversion =>
1900 if Do_Overflow_Check (Expr)
1901 or else Do_Length_Check (Expr)
1902 or else Do_Tag_Check (Expr)
1906 return Cannot_Raise_Constraint_Error (Expression (Expr));
1909 when N_Unchecked_Type_Conversion =>
1910 return Cannot_Raise_Constraint_Error (Expression (Expr));
1913 if Do_Overflow_Check (Expr) then
1916 return Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1923 if Do_Division_Check (Expr)
1925 Do_Overflow_Check (Expr)
1930 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1932 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1951 N_Op_Shift_Right_Arithmetic |
1955 if Do_Overflow_Check (Expr) then
1959 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1961 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1968 end Cannot_Raise_Constraint_Error;
1970 -----------------------------------------
1971 -- Check_Dynamically_Tagged_Expression --
1972 -----------------------------------------
1974 procedure Check_Dynamically_Tagged_Expression
1977 Related_Nod : Node_Id)
1980 pragma Assert (Is_Tagged_Type (Typ));
1982 -- In order to avoid spurious errors when analyzing the expanded code,
1983 -- this check is done only for nodes that come from source and for
1984 -- actuals of generic instantiations.
1986 if (Comes_From_Source (Related_Nod)
1987 or else In_Generic_Actual (Expr))
1988 and then (Is_Class_Wide_Type (Etype (Expr))
1989 or else Is_Dynamically_Tagged (Expr))
1990 and then Is_Tagged_Type (Typ)
1991 and then not Is_Class_Wide_Type (Typ)
1993 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
1995 end Check_Dynamically_Tagged_Expression;
1997 --------------------------
1998 -- Check_Fully_Declared --
1999 --------------------------
2001 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
2003 if Ekind (T) = E_Incomplete_Type then
2005 -- Ada 2005 (AI-50217): If the type is available through a limited
2006 -- with_clause, verify that its full view has been analyzed.
2008 if From_Limited_With (T)
2009 and then Present (Non_Limited_View (T))
2010 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
2012 -- The non-limited view is fully declared
2018 ("premature usage of incomplete}", N, First_Subtype (T));
2021 -- Need comments for these tests ???
2023 elsif Has_Private_Component (T)
2024 and then not Is_Generic_Type (Root_Type (T))
2025 and then not In_Spec_Expression
2027 -- Special case: if T is the anonymous type created for a single
2028 -- task or protected object, use the name of the source object.
2030 if Is_Concurrent_Type (T)
2031 and then not Comes_From_Source (T)
2032 and then Nkind (N) = N_Object_Declaration
2035 ("type of& has incomplete component",
2036 N, Defining_Identifier (N));
2039 ("premature usage of incomplete}",
2040 N, First_Subtype (T));
2043 end Check_Fully_Declared;
2045 -------------------------------------
2046 -- Check_Function_Writable_Actuals --
2047 -------------------------------------
2049 procedure Check_Function_Writable_Actuals (N : Node_Id) is
2050 Writable_Actuals_List : Elist_Id := No_Elist;
2051 Identifiers_List : Elist_Id := No_Elist;
2052 Error_Node : Node_Id := Empty;
2054 procedure Collect_Identifiers (N : Node_Id);
2055 -- In a single traversal of subtree N collect in Writable_Actuals_List
2056 -- all the actuals of functions with writable actuals, and in the list
2057 -- Identifiers_List collect all the identifiers that are not actuals of
2058 -- functions with writable actuals. If a writable actual is referenced
2059 -- twice as writable actual then Error_Node is set to reference its
2060 -- second occurrence, the error is reported, and the tree traversal
2063 function Get_Function_Id (Call : Node_Id) return Entity_Id;
2064 -- Return the entity associated with the function call
2066 procedure Preanalyze_Without_Errors (N : Node_Id);
2067 -- Preanalyze N without reporting errors. Very dubious, you can't just
2068 -- go analyzing things more than once???
2070 -------------------------
2071 -- Collect_Identifiers --
2072 -------------------------
2074 procedure Collect_Identifiers (N : Node_Id) is
2076 function Check_Node (N : Node_Id) return Traverse_Result;
2077 -- Process a single node during the tree traversal to collect the
2078 -- writable actuals of functions and all the identifiers which are
2079 -- not writable actuals of functions.
2081 function Contains (List : Elist_Id; N : Node_Id) return Boolean;
2082 -- Returns True if List has a node whose Entity is Entity (N)
2084 -------------------------
2085 -- Check_Function_Call --
2086 -------------------------
2088 function Check_Node (N : Node_Id) return Traverse_Result is
2089 Is_Writable_Actual : Boolean := False;
2093 if Nkind (N) = N_Identifier then
2095 -- No analysis possible if the entity is not decorated
2097 if No (Entity (N)) then
2100 -- Don't collect identifiers of packages, called functions, etc
2102 elsif Ekind_In (Entity (N), E_Package,
2109 -- Analyze if N is a writable actual of a function
2111 elsif Nkind (Parent (N)) = N_Function_Call then
2113 Call : constant Node_Id := Parent (N);
2118 Id := Get_Function_Id (Call);
2120 -- In case of previous error, no check is possible
2126 Formal := First_Formal (Id);
2127 Actual := First_Actual (Call);
2128 while Present (Actual) and then Present (Formal) loop
2130 if Ekind_In (Formal, E_Out_Parameter,
2133 Is_Writable_Actual := True;
2139 Next_Formal (Formal);
2140 Next_Actual (Actual);
2145 if Is_Writable_Actual then
2146 if Contains (Writable_Actuals_List, N) then
2148 ("value may be affected by call to& "
2149 & "because order of evaluation is arbitrary", N, Id);
2154 Append_New_Elmt (N, To => Writable_Actuals_List);
2157 if Identifiers_List = No_Elist then
2158 Identifiers_List := New_Elmt_List;
2161 Append_Unique_Elmt (N, Identifiers_List);
2174 N : Node_Id) return Boolean
2176 pragma Assert (Nkind (N) in N_Has_Entity);
2181 if List = No_Elist then
2185 Elmt := First_Elmt (List);
2186 while Present (Elmt) loop
2187 if Entity (Node (Elmt)) = Entity (N) then
2201 procedure Do_Traversal is new Traverse_Proc (Check_Node);
2202 -- The traversal procedure
2204 -- Start of processing for Collect_Identifiers
2207 if Present (Error_Node) then
2211 if Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
2216 end Collect_Identifiers;
2218 ---------------------
2219 -- Get_Function_Id --
2220 ---------------------
2222 function Get_Function_Id (Call : Node_Id) return Entity_Id is
2223 Nam : constant Node_Id := Name (Call);
2227 if Nkind (Nam) = N_Explicit_Dereference then
2229 pragma Assert (Ekind (Id) = E_Subprogram_Type);
2231 elsif Nkind (Nam) = N_Selected_Component then
2232 Id := Entity (Selector_Name (Nam));
2234 elsif Nkind (Nam) = N_Indexed_Component then
2235 Id := Entity (Selector_Name (Prefix (Nam)));
2242 end Get_Function_Id;
2244 ---------------------------
2245 -- Preanalyze_Expression --
2246 ---------------------------
2248 procedure Preanalyze_Without_Errors (N : Node_Id) is
2249 Status : constant Boolean := Get_Ignore_Errors;
2251 Set_Ignore_Errors (True);
2253 Set_Ignore_Errors (Status);
2254 end Preanalyze_Without_Errors;
2256 -- Start of processing for Check_Function_Writable_Actuals
2259 -- The check only applies to Ada 2012 code, and only to constructs that
2260 -- have multiple constituents whose order of evaluation is not specified
2263 if Ada_Version < Ada_2012
2264 or else (not (Nkind (N) in N_Op)
2265 and then not (Nkind (N) in N_Membership_Test)
2266 and then not Nkind_In (N, N_Range,
2268 N_Extension_Aggregate,
2269 N_Full_Type_Declaration,
2271 N_Procedure_Call_Statement,
2272 N_Entry_Call_Statement))
2273 or else (Nkind (N) = N_Full_Type_Declaration
2274 and then not Is_Record_Type (Defining_Identifier (N)))
2276 -- In addition, this check only applies to source code, not to code
2277 -- generated by constraint checks.
2279 or else not Comes_From_Source (N)
2284 -- If a construct C has two or more direct constituents that are names
2285 -- or expressions whose evaluation may occur in an arbitrary order, at
2286 -- least one of which contains a function call with an in out or out
2287 -- parameter, then the construct is legal only if: for each name N that
2288 -- is passed as a parameter of mode in out or out to some inner function
2289 -- call C2 (not including the construct C itself), there is no other
2290 -- name anywhere within a direct constituent of the construct C other
2291 -- than the one containing C2, that is known to refer to the same
2292 -- object (RM 6.4.1(6.17/3)).
2296 Collect_Identifiers (Low_Bound (N));
2297 Collect_Identifiers (High_Bound (N));
2299 when N_Op | N_Membership_Test =>
2304 Collect_Identifiers (Left_Opnd (N));
2306 if Present (Right_Opnd (N)) then
2307 Collect_Identifiers (Right_Opnd (N));
2310 if Nkind_In (N, N_In, N_Not_In)
2311 and then Present (Alternatives (N))
2313 Expr := First (Alternatives (N));
2314 while Present (Expr) loop
2315 Collect_Identifiers (Expr);
2322 when N_Full_Type_Declaration =>
2324 function Get_Record_Part (N : Node_Id) return Node_Id;
2325 -- Return the record part of this record type definition
2327 function Get_Record_Part (N : Node_Id) return Node_Id is
2328 Type_Def : constant Node_Id := Type_Definition (N);
2330 if Nkind (Type_Def) = N_Derived_Type_Definition then
2331 return Record_Extension_Part (Type_Def);
2335 end Get_Record_Part;
2338 Def_Id : Entity_Id := Defining_Identifier (N);
2339 Rec : Node_Id := Get_Record_Part (N);
2342 -- No need to perform any analysis if the record has no
2345 if No (Rec) or else No (Component_List (Rec)) then
2349 -- Collect the identifiers starting from the deepest
2350 -- derivation. Done to report the error in the deepest
2354 if Present (Component_List (Rec)) then
2355 Comp := First (Component_Items (Component_List (Rec)));
2356 while Present (Comp) loop
2357 if Nkind (Comp) = N_Component_Declaration
2358 and then Present (Expression (Comp))
2360 Collect_Identifiers (Expression (Comp));
2367 exit when No (Underlying_Type (Etype (Def_Id)))
2368 or else Base_Type (Underlying_Type (Etype (Def_Id)))
2371 Def_Id := Base_Type (Underlying_Type (Etype (Def_Id)));
2372 Rec := Get_Record_Part (Parent (Def_Id));
2376 when N_Subprogram_Call |
2377 N_Entry_Call_Statement =>
2379 Id : constant Entity_Id := Get_Function_Id (N);
2384 Formal := First_Formal (Id);
2385 Actual := First_Actual (N);
2386 while Present (Actual) and then Present (Formal) loop
2387 if Ekind_In (Formal, E_Out_Parameter,
2390 Collect_Identifiers (Actual);
2393 Next_Formal (Formal);
2394 Next_Actual (Actual);
2399 N_Extension_Aggregate =>
2403 Comp_Expr : Node_Id;
2406 -- Handle the N_Others_Choice of array aggregates with static
2407 -- bounds. There is no need to perform this analysis in
2408 -- aggregates without static bounds since we cannot evaluate
2409 -- if the N_Others_Choice covers several elements. There is
2410 -- no need to handle the N_Others choice of record aggregates
2411 -- since at this stage it has been already expanded by
2412 -- Resolve_Record_Aggregate.
2414 if Is_Array_Type (Etype (N))
2415 and then Nkind (N) = N_Aggregate
2416 and then Present (Aggregate_Bounds (N))
2417 and then Compile_Time_Known_Bounds (Etype (N))
2418 and then Expr_Value (High_Bound (Aggregate_Bounds (N)))
2420 Expr_Value (Low_Bound (Aggregate_Bounds (N)))
2423 Count_Components : Uint := Uint_0;
2424 Num_Components : Uint;
2425 Others_Assoc : Node_Id;
2426 Others_Choice : Node_Id := Empty;
2427 Others_Box_Present : Boolean := False;
2430 -- Count positional associations
2432 if Present (Expressions (N)) then
2433 Comp_Expr := First (Expressions (N));
2434 while Present (Comp_Expr) loop
2435 Count_Components := Count_Components + 1;
2440 -- Count the rest of elements and locate the N_Others
2443 Assoc := First (Component_Associations (N));
2444 while Present (Assoc) loop
2445 Choice := First (Choices (Assoc));
2446 while Present (Choice) loop
2447 if Nkind (Choice) = N_Others_Choice then
2448 Others_Assoc := Assoc;
2449 Others_Choice := Choice;
2450 Others_Box_Present := Box_Present (Assoc);
2452 -- Count several components
2454 elsif Nkind_In (Choice, N_Range,
2455 N_Subtype_Indication)
2456 or else (Is_Entity_Name (Choice)
2457 and then Is_Type (Entity (Choice)))
2462 Get_Index_Bounds (Choice, L, H);
2464 (Compile_Time_Known_Value (L)
2465 and then Compile_Time_Known_Value (H));
2468 + Expr_Value (H) - Expr_Value (L) + 1;
2471 -- Count single component. No other case available
2472 -- since we are handling an aggregate with static
2476 pragma Assert (Is_OK_Static_Expression (Choice)
2477 or else Nkind (Choice) = N_Identifier
2478 or else Nkind (Choice) = N_Integer_Literal);
2480 Count_Components := Count_Components + 1;
2490 Expr_Value (High_Bound (Aggregate_Bounds (N))) -
2491 Expr_Value (Low_Bound (Aggregate_Bounds (N))) + 1;
2493 pragma Assert (Count_Components <= Num_Components);
2495 -- Handle the N_Others choice if it covers several
2498 if Present (Others_Choice)
2499 and then (Num_Components - Count_Components) > 1
2501 if not Others_Box_Present then
2503 -- At this stage, if expansion is active, the
2504 -- expression of the others choice has not been
2505 -- analyzed. Hence we generate a duplicate and
2506 -- we analyze it silently to have available the
2507 -- minimum decoration required to collect the
2510 if not Expander_Active then
2511 Comp_Expr := Expression (Others_Assoc);
2514 New_Copy_Tree (Expression (Others_Assoc));
2515 Preanalyze_Without_Errors (Comp_Expr);
2518 Collect_Identifiers (Comp_Expr);
2520 if Writable_Actuals_List /= No_Elist then
2522 -- As suggested by Robert, at current stage we
2523 -- report occurrences of this case as warnings.
2526 ("writable function parameter may affect "
2527 & "value in other component because order "
2528 & "of evaluation is unspecified??",
2529 Node (First_Elmt (Writable_Actuals_List)));
2536 -- Handle ancestor part of extension aggregates
2538 if Nkind (N) = N_Extension_Aggregate then
2539 Collect_Identifiers (Ancestor_Part (N));
2542 -- Handle positional associations
2544 if Present (Expressions (N)) then
2545 Comp_Expr := First (Expressions (N));
2546 while Present (Comp_Expr) loop
2547 if not Is_OK_Static_Expression (Comp_Expr) then
2548 Collect_Identifiers (Comp_Expr);
2555 -- Handle discrete associations
2557 if Present (Component_Associations (N)) then
2558 Assoc := First (Component_Associations (N));
2559 while Present (Assoc) loop
2561 if not Box_Present (Assoc) then
2562 Choice := First (Choices (Assoc));
2563 while Present (Choice) loop
2565 -- For now we skip discriminants since it requires
2566 -- performing the analysis in two phases: first one
2567 -- analyzing discriminants and second one analyzing
2568 -- the rest of components since discriminants are
2569 -- evaluated prior to components: too much extra
2570 -- work to detect a corner case???
2572 if Nkind (Choice) in N_Has_Entity
2573 and then Present (Entity (Choice))
2574 and then Ekind (Entity (Choice)) = E_Discriminant
2578 elsif Box_Present (Assoc) then
2582 if not Analyzed (Expression (Assoc)) then
2584 New_Copy_Tree (Expression (Assoc));
2585 Set_Parent (Comp_Expr, Parent (N));
2586 Preanalyze_Without_Errors (Comp_Expr);
2588 Comp_Expr := Expression (Assoc);
2591 Collect_Identifiers (Comp_Expr);
2607 -- No further action needed if we already reported an error
2609 if Present (Error_Node) then
2613 -- Check if some writable argument of a function is referenced
2615 if Writable_Actuals_List /= No_Elist
2616 and then Identifiers_List /= No_Elist
2623 Elmt_1 := First_Elmt (Writable_Actuals_List);
2624 while Present (Elmt_1) loop
2625 Elmt_2 := First_Elmt (Identifiers_List);
2626 while Present (Elmt_2) loop
2627 if Entity (Node (Elmt_1)) = Entity (Node (Elmt_2)) then
2628 case Nkind (Parent (Node (Elmt_2))) is
2630 N_Component_Association |
2631 N_Component_Declaration =>
2633 ("value may be affected by call in other "
2634 & "component because they are evaluated "
2635 & "in unspecified order",
2638 when N_In | N_Not_In =>
2640 ("value may be affected by call in other "
2641 & "alternative because they are evaluated "
2642 & "in unspecified order",
2647 ("value of actual may be affected by call in "
2648 & "other actual because they are evaluated "
2649 & "in unspecified order",
2661 end Check_Function_Writable_Actuals;
2663 --------------------------------
2664 -- Check_Implicit_Dereference --
2665 --------------------------------
2667 procedure Check_Implicit_Dereference (N : Node_Id; Typ : Entity_Id) is
2673 if Nkind (N) = N_Indexed_Component
2674 and then Present (Generalized_Indexing (N))
2676 Nam := Generalized_Indexing (N);
2681 if Ada_Version < Ada_2012
2682 or else not Has_Implicit_Dereference (Base_Type (Typ))
2686 elsif not Comes_From_Source (N)
2687 and then Nkind (N) /= N_Indexed_Component
2691 elsif Is_Entity_Name (Nam) and then Is_Type (Entity (Nam)) then
2695 Disc := First_Discriminant (Typ);
2696 while Present (Disc) loop
2697 if Has_Implicit_Dereference (Disc) then
2698 Desig := Designated_Type (Etype (Disc));
2699 Add_One_Interp (Nam, Disc, Desig);
2701 -- If the node is a generalized indexing, add interpretation
2702 -- to that node as well, for subsequent resolution.
2704 if Nkind (N) = N_Indexed_Component then
2705 Add_One_Interp (N, Disc, Desig);
2708 -- If the operation comes from a generic unit and the context
2709 -- is a selected component, the selector name may be global
2710 -- and set in the instance already. Remove the entity to
2711 -- force resolution of the selected component, and the
2712 -- generation of an explicit dereference if needed.
2715 and then Nkind (Parent (Nam)) = N_Selected_Component
2717 Set_Entity (Selector_Name (Parent (Nam)), Empty);
2723 Next_Discriminant (Disc);
2726 end Check_Implicit_Dereference;
2728 ----------------------------------
2729 -- Check_Internal_Protected_Use --
2730 ----------------------------------
2732 procedure Check_Internal_Protected_Use (N : Node_Id; Nam : Entity_Id) is
2738 while Present (S) loop
2739 if S = Standard_Standard then
2742 elsif Ekind (S) = E_Function
2743 and then Ekind (Scope (S)) = E_Protected_Type
2752 if Scope (Nam) = Prot and then Ekind (Nam) /= E_Function then
2754 -- An indirect function call (e.g. a callback within a protected
2755 -- function body) is not statically illegal. If the access type is
2756 -- anonymous and is the type of an access parameter, the scope of Nam
2757 -- will be the protected type, but it is not a protected operation.
2759 if Ekind (Nam) = E_Subprogram_Type
2761 Nkind (Associated_Node_For_Itype (Nam)) = N_Function_Specification
2765 elsif Nkind (N) = N_Subprogram_Renaming_Declaration then
2767 ("within protected function cannot use protected "
2768 & "procedure in renaming or as generic actual", N);
2770 elsif Nkind (N) = N_Attribute_Reference then
2772 ("within protected function cannot take access of "
2773 & " protected procedure", N);
2777 ("within protected function, protected object is constant", N);
2779 ("\cannot call operation that may modify it", N);
2782 end Check_Internal_Protected_Use;
2784 ---------------------------------------
2785 -- Check_Later_Vs_Basic_Declarations --
2786 ---------------------------------------
2788 procedure Check_Later_Vs_Basic_Declarations
2790 During_Parsing : Boolean)
2792 Body_Sloc : Source_Ptr;
2795 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
2796 -- Return whether Decl is considered as a declarative item.
2797 -- When During_Parsing is True, the semantics of Ada 83 is followed.
2798 -- When During_Parsing is False, the semantics of SPARK is followed.
2800 -------------------------------
2801 -- Is_Later_Declarative_Item --
2802 -------------------------------
2804 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
2806 if Nkind (Decl) in N_Later_Decl_Item then
2809 elsif Nkind (Decl) = N_Pragma then
2812 elsif During_Parsing then
2815 -- In SPARK, a package declaration is not considered as a later
2816 -- declarative item.
2818 elsif Nkind (Decl) = N_Package_Declaration then
2821 -- In SPARK, a renaming is considered as a later declarative item
2823 elsif Nkind (Decl) in N_Renaming_Declaration then
2829 end Is_Later_Declarative_Item;
2831 -- Start of Check_Later_Vs_Basic_Declarations
2834 Decl := First (Decls);
2836 -- Loop through sequence of basic declarative items
2838 Outer : while Present (Decl) loop
2839 if not Nkind_In (Decl, N_Subprogram_Body, N_Package_Body, N_Task_Body)
2840 and then Nkind (Decl) not in N_Body_Stub
2844 -- Once a body is encountered, we only allow later declarative
2845 -- items. The inner loop checks the rest of the list.
2848 Body_Sloc := Sloc (Decl);
2850 Inner : while Present (Decl) loop
2851 if not Is_Later_Declarative_Item (Decl) then
2852 if During_Parsing then
2853 if Ada_Version = Ada_83 then
2854 Error_Msg_Sloc := Body_Sloc;
2856 ("(Ada 83) decl cannot appear after body#", Decl);
2859 Error_Msg_Sloc := Body_Sloc;
2860 Check_SPARK_05_Restriction
2861 ("decl cannot appear after body#", Decl);
2869 end Check_Later_Vs_Basic_Declarations;
2871 -------------------------
2872 -- Check_Nested_Access --
2873 -------------------------
2875 procedure Check_Nested_Access (Ent : Entity_Id) is
2876 Scop : constant Entity_Id := Current_Scope;
2877 Current_Subp : Entity_Id;
2878 Enclosing : Entity_Id;
2881 -- Currently only enabled for VM back-ends for efficiency
2883 if VM_Target /= No_VM
2884 and then Ekind_In (Ent, E_Variable, E_Constant, E_Loop_Parameter)
2885 and then Scope (Ent) /= Empty
2886 and then not Is_Library_Level_Entity (Ent)
2888 -- Comment the exclusion of imported entities ???
2890 and then not Is_Imported (Ent)
2892 -- Get current subprogram that is relevant
2894 if Is_Subprogram (Scop)
2895 or else Is_Generic_Subprogram (Scop)
2896 or else Is_Entry (Scop)
2898 Current_Subp := Scop;
2900 Current_Subp := Current_Subprogram;
2903 Enclosing := Enclosing_Subprogram (Ent);
2905 -- Set flag if uplevel reference
2907 if Enclosing /= Empty and then Enclosing /= Current_Subp then
2908 Set_Has_Uplevel_Reference (Ent, True);
2911 end Check_Nested_Access;
2913 ---------------------------
2914 -- Check_No_Hidden_State --
2915 ---------------------------
2917 procedure Check_No_Hidden_State (Id : Entity_Id) is
2918 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean;
2919 -- Determine whether the entity of a package denoted by Pkg has a null
2922 -----------------------------
2923 -- Has_Null_Abstract_State --
2924 -----------------------------
2926 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean is
2927 States : constant Elist_Id := Abstract_States (Pkg);
2930 -- Check first available state of related package. A null abstract
2931 -- state always appears as the sole element of the state list.
2935 and then Is_Null_State (Node (First_Elmt (States)));
2936 end Has_Null_Abstract_State;
2940 Context : Entity_Id := Empty;
2941 Not_Visible : Boolean := False;
2944 -- Start of processing for Check_No_Hidden_State
2947 pragma Assert (Ekind_In (Id, E_Abstract_State, E_Variable));
2949 -- Find the proper context where the object or state appears
2952 while Present (Scop) loop
2955 -- Keep track of the context's visibility
2957 Not_Visible := Not_Visible or else In_Private_Part (Context);
2959 -- Prevent the search from going too far
2961 if Context = Standard_Standard then
2964 -- Objects and states that appear immediately within a subprogram or
2965 -- inside a construct nested within a subprogram do not introduce a
2966 -- hidden state. They behave as local variable declarations.
2968 elsif Is_Subprogram (Context) then
2971 -- When examining a package body, use the entity of the spec as it
2972 -- carries the abstract state declarations.
2974 elsif Ekind (Context) = E_Package_Body then
2975 Context := Spec_Entity (Context);
2978 -- Stop the traversal when a package subject to a null abstract state
2981 if Ekind_In (Context, E_Generic_Package, E_Package)
2982 and then Has_Null_Abstract_State (Context)
2987 Scop := Scope (Scop);
2990 -- At this point we know that there is at least one package with a null
2991 -- abstract state in visibility. Emit an error message unconditionally
2992 -- if the entity being processed is a state because the placement of the
2993 -- related package is irrelevant. This is not the case for objects as
2994 -- the intermediate context matters.
2996 if Present (Context)
2997 and then (Ekind (Id) = E_Abstract_State or else Not_Visible)
2999 Error_Msg_N ("cannot introduce hidden state &", Id);
3000 Error_Msg_NE ("\package & has null abstract state", Id, Context);
3002 end Check_No_Hidden_State;
3004 ------------------------------------------
3005 -- Check_Potentially_Blocking_Operation --
3006 ------------------------------------------
3008 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
3012 -- N is one of the potentially blocking operations listed in 9.5.1(8).
3013 -- When pragma Detect_Blocking is active, the run time will raise
3014 -- Program_Error. Here we only issue a warning, since we generally
3015 -- support the use of potentially blocking operations in the absence
3018 -- Indirect blocking through a subprogram call cannot be diagnosed
3019 -- statically without interprocedural analysis, so we do not attempt
3022 S := Scope (Current_Scope);
3023 while Present (S) and then S /= Standard_Standard loop
3024 if Is_Protected_Type (S) then
3026 ("potentially blocking operation in protected operation??", N);
3032 end Check_Potentially_Blocking_Operation;
3034 ---------------------------------
3035 -- Check_Result_And_Post_State --
3036 ---------------------------------
3038 procedure Check_Result_And_Post_State (Subp_Id : Entity_Id) is
3039 procedure Check_Result_And_Post_State_In_Pragma
3041 Result_Seen : in out Boolean);
3042 -- Determine whether pragma Prag mentions attribute 'Result and whether
3043 -- the pragma contains an expression that evaluates differently in pre-
3044 -- and post-state. Prag is a [refined] postcondition or a contract-cases
3045 -- pragma. Result_Seen is set when the pragma mentions attribute 'Result
3047 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean;
3048 -- Determine whether subprogram Subp_Id contains at least one IN OUT
3049 -- formal parameter.
3051 -------------------------------------------
3052 -- Check_Result_And_Post_State_In_Pragma --
3053 -------------------------------------------
3055 procedure Check_Result_And_Post_State_In_Pragma
3057 Result_Seen : in out Boolean)
3059 procedure Check_Expression (Expr : Node_Id);
3060 -- Perform the 'Result and post-state checks on a given expression
3062 function Is_Function_Result (N : Node_Id) return Traverse_Result;
3063 -- Attempt to find attribute 'Result in a subtree denoted by N
3065 function Is_Trivial_Boolean (N : Node_Id) return Boolean;
3066 -- Determine whether source node N denotes "True" or "False"
3068 function Mentions_Post_State (N : Node_Id) return Boolean;
3069 -- Determine whether a subtree denoted by N mentions any construct
3070 -- that denotes a post-state.
3072 procedure Check_Function_Result is
3073 new Traverse_Proc (Is_Function_Result);
3075 ----------------------
3076 -- Check_Expression --
3077 ----------------------
3079 procedure Check_Expression (Expr : Node_Id) is
3081 if not Is_Trivial_Boolean (Expr) then
3082 Check_Function_Result (Expr);
3084 if not Mentions_Post_State (Expr) then
3085 if Pragma_Name (Prag) = Name_Contract_Cases then
3087 ("contract case does not check the outcome of calling "
3088 & "&?T?", Expr, Subp_Id);
3090 elsif Pragma_Name (Prag) = Name_Refined_Post then
3092 ("refined postcondition does not check the outcome of "
3093 & "calling &?T?", Prag, Subp_Id);
3097 ("postcondition does not check the outcome of calling "
3098 & "&?T?", Prag, Subp_Id);
3102 end Check_Expression;
3104 ------------------------
3105 -- Is_Function_Result --
3106 ------------------------
3108 function Is_Function_Result (N : Node_Id) return Traverse_Result is
3110 if Is_Attribute_Result (N) then
3111 Result_Seen := True;
3114 -- Continue the traversal
3119 end Is_Function_Result;
3121 ------------------------
3122 -- Is_Trivial_Boolean --
3123 ------------------------
3125 function Is_Trivial_Boolean (N : Node_Id) return Boolean is
3128 Comes_From_Source (N)
3129 and then Is_Entity_Name (N)
3130 and then (Entity (N) = Standard_True
3132 Entity (N) = Standard_False);
3133 end Is_Trivial_Boolean;
3135 -------------------------
3136 -- Mentions_Post_State --
3137 -------------------------
3139 function Mentions_Post_State (N : Node_Id) return Boolean is
3140 Post_State_Seen : Boolean := False;
3142 function Is_Post_State (N : Node_Id) return Traverse_Result;
3143 -- Attempt to find a construct that denotes a post-state. If this
3144 -- is the case, set flag Post_State_Seen.
3150 function Is_Post_State (N : Node_Id) return Traverse_Result is
3154 if Nkind_In (N, N_Explicit_Dereference, N_Function_Call) then
3155 Post_State_Seen := True;
3158 elsif Nkind_In (N, N_Expanded_Name, N_Identifier) then
3161 -- The entity may be modifiable through an implicit
3165 or else Ekind (Ent) in Assignable_Kind
3166 or else (Is_Access_Type (Etype (Ent))
3167 and then Nkind (Parent (N)) =
3168 N_Selected_Component)
3170 Post_State_Seen := True;
3174 elsif Nkind (N) = N_Attribute_Reference then
3175 if Attribute_Name (N) = Name_Old then
3178 elsif Attribute_Name (N) = Name_Result then
3179 Post_State_Seen := True;
3187 procedure Find_Post_State is new Traverse_Proc (Is_Post_State);
3189 -- Start of processing for Mentions_Post_State
3192 Find_Post_State (N);
3194 return Post_State_Seen;
3195 end Mentions_Post_State;
3199 Expr : constant Node_Id :=
3201 (First (Pragma_Argument_Associations (Prag)));
3202 Nam : constant Name_Id := Pragma_Name (Prag);
3205 -- Start of processing for Check_Result_And_Post_State_In_Pragma
3208 -- Examine all consequences
3210 if Nam = Name_Contract_Cases then
3211 CCase := First (Component_Associations (Expr));
3212 while Present (CCase) loop
3213 Check_Expression (Expression (CCase));
3218 -- Examine the expression of a postcondition
3220 else pragma Assert (Nam_In (Nam, Name_Postcondition,
3221 Name_Refined_Post));
3222 Check_Expression (Expr);
3224 end Check_Result_And_Post_State_In_Pragma;
3226 --------------------------
3227 -- Has_In_Out_Parameter --
3228 --------------------------
3230 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean is
3234 -- Traverse the formals looking for an IN OUT parameter
3236 Formal := First_Formal (Subp_Id);
3237 while Present (Formal) loop
3238 if Ekind (Formal) = E_In_Out_Parameter then
3242 Next_Formal (Formal);
3246 end Has_In_Out_Parameter;
3250 Items : constant Node_Id := Contract (Subp_Id);
3251 Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id);
3252 Case_Prag : Node_Id := Empty;
3253 Post_Prag : Node_Id := Empty;
3255 Seen_In_Case : Boolean := False;
3256 Seen_In_Post : Boolean := False;
3257 Spec_Id : Entity_Id;
3259 -- Start of processing for Check_Result_And_Post_State
3262 -- The lack of attribute 'Result or a post-state is classified as a
3263 -- suspicious contract. Do not perform the check if the corresponding
3264 -- swich is not set.
3266 if not Warn_On_Suspicious_Contract then
3269 -- Nothing to do if there is no contract
3271 elsif No (Items) then
3275 -- Retrieve the entity of the subprogram spec (if any)
3277 if Nkind (Subp_Decl) = N_Subprogram_Body
3278 and then Present (Corresponding_Spec (Subp_Decl))
3280 Spec_Id := Corresponding_Spec (Subp_Decl);
3282 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
3283 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
3285 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
3291 -- Examine all postconditions for attribute 'Result and a post-state
3293 Prag := Pre_Post_Conditions (Items);
3294 while Present (Prag) loop
3295 if Nam_In (Pragma_Name (Prag), Name_Postcondition,
3297 and then not Error_Posted (Prag)
3300 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Post);
3303 Prag := Next_Pragma (Prag);
3306 -- Examine the contract cases of the subprogram for attribute 'Result
3307 -- and a post-state.
3309 Prag := Contract_Test_Cases (Items);
3310 while Present (Prag) loop
3311 if Pragma_Name (Prag) = Name_Contract_Cases
3312 and then not Error_Posted (Prag)
3315 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Case);
3318 Prag := Next_Pragma (Prag);
3321 -- Do not emit any errors if the subprogram is not a function
3323 if not Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
3326 -- Regardless of whether the function has postconditions or contract
3327 -- cases, or whether they mention attribute 'Result, an IN OUT formal
3328 -- parameter is always treated as a result.
3330 elsif Has_In_Out_Parameter (Spec_Id) then
3333 -- The function has both a postcondition and contract cases and they do
3334 -- not mention attribute 'Result.
3336 elsif Present (Case_Prag)
3337 and then not Seen_In_Case
3338 and then Present (Post_Prag)
3339 and then not Seen_In_Post
3342 ("neither postcondition nor contract cases mention function "
3343 & "result?T?", Post_Prag);
3345 -- The function has contract cases only and they do not mention
3346 -- attribute 'Result.
3348 elsif Present (Case_Prag) and then not Seen_In_Case then
3349 Error_Msg_N ("contract cases do not mention result?T?", Case_Prag);
3351 -- The function has postconditions only and they do not mention
3352 -- attribute 'Result.
3354 elsif Present (Post_Prag) and then not Seen_In_Post then
3356 ("postcondition does not mention function result?T?", Post_Prag);
3358 end Check_Result_And_Post_State;
3360 ------------------------------
3361 -- Check_Unprotected_Access --
3362 ------------------------------
3364 procedure Check_Unprotected_Access
3368 Cont_Encl_Typ : Entity_Id;
3369 Pref_Encl_Typ : Entity_Id;
3371 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
3372 -- Check whether Obj is a private component of a protected object.
3373 -- Return the protected type where the component resides, Empty
3376 function Is_Public_Operation return Boolean;
3377 -- Verify that the enclosing operation is callable from outside the
3378 -- protected object, to minimize false positives.
3380 ------------------------------
3381 -- Enclosing_Protected_Type --
3382 ------------------------------
3384 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
3386 if Is_Entity_Name (Obj) then
3388 Ent : Entity_Id := Entity (Obj);
3391 -- The object can be a renaming of a private component, use
3392 -- the original record component.
3394 if Is_Prival (Ent) then
3395 Ent := Prival_Link (Ent);
3398 if Is_Protected_Type (Scope (Ent)) then
3404 -- For indexed and selected components, recursively check the prefix
3406 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
3407 return Enclosing_Protected_Type (Prefix (Obj));
3409 -- The object does not denote a protected component
3414 end Enclosing_Protected_Type;
3416 -------------------------
3417 -- Is_Public_Operation --
3418 -------------------------
3420 function Is_Public_Operation return Boolean is
3426 while Present (S) and then S /= Pref_Encl_Typ loop
3427 if Scope (S) = Pref_Encl_Typ then
3428 E := First_Entity (Pref_Encl_Typ);
3430 and then E /= First_Private_Entity (Pref_Encl_Typ)
3444 end Is_Public_Operation;
3446 -- Start of processing for Check_Unprotected_Access
3449 if Nkind (Expr) = N_Attribute_Reference
3450 and then Attribute_Name (Expr) = Name_Unchecked_Access
3452 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
3453 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
3455 -- Check whether we are trying to export a protected component to a
3456 -- context with an equal or lower access level.
3458 if Present (Pref_Encl_Typ)
3459 and then No (Cont_Encl_Typ)
3460 and then Is_Public_Operation
3461 and then Scope_Depth (Pref_Encl_Typ) >=
3462 Object_Access_Level (Context)
3465 ("??possible unprotected access to protected data", Expr);
3468 end Check_Unprotected_Access;
3470 ------------------------
3471 -- Collect_Interfaces --
3472 ------------------------
3474 procedure Collect_Interfaces
3476 Ifaces_List : out Elist_Id;
3477 Exclude_Parents : Boolean := False;
3478 Use_Full_View : Boolean := True)
3480 procedure Collect (Typ : Entity_Id);
3481 -- Subsidiary subprogram used to traverse the whole list
3482 -- of directly and indirectly implemented interfaces
3488 procedure Collect (Typ : Entity_Id) is
3489 Ancestor : Entity_Id;
3497 -- Handle private types and subtypes
3500 and then Is_Private_Type (Typ)
3501 and then Present (Full_View (Typ))
3503 Full_T := Full_View (Typ);
3505 if Ekind (Full_T) = E_Record_Subtype then
3506 Full_T := Full_View (Etype (Typ));
3510 -- Include the ancestor if we are generating the whole list of
3511 -- abstract interfaces.
3513 if Etype (Full_T) /= Typ
3515 -- Protect the frontend against wrong sources. For example:
3518 -- type A is tagged null record;
3519 -- type B is new A with private;
3520 -- type C is new A with private;
3522 -- type B is new C with null record;
3523 -- type C is new B with null record;
3526 and then Etype (Full_T) /= T
3528 Ancestor := Etype (Full_T);
3531 if Is_Interface (Ancestor) and then not Exclude_Parents then
3532 Append_Unique_Elmt (Ancestor, Ifaces_List);
3536 -- Traverse the graph of ancestor interfaces
3538 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
3539 Id := First (Abstract_Interface_List (Full_T));
3540 while Present (Id) loop
3541 Iface := Etype (Id);
3543 -- Protect against wrong uses. For example:
3544 -- type I is interface;
3545 -- type O is tagged null record;
3546 -- type Wrong is new I and O with null record; -- ERROR
3548 if Is_Interface (Iface) then
3550 and then Etype (T) /= T
3551 and then Interface_Present_In_Ancestor (Etype (T), Iface)
3556 Append_Unique_Elmt (Iface, Ifaces_List);
3565 -- Start of processing for Collect_Interfaces
3568 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
3569 Ifaces_List := New_Elmt_List;
3571 end Collect_Interfaces;
3573 ----------------------------------
3574 -- Collect_Interface_Components --
3575 ----------------------------------
3577 procedure Collect_Interface_Components
3578 (Tagged_Type : Entity_Id;
3579 Components_List : out Elist_Id)
3581 procedure Collect (Typ : Entity_Id);
3582 -- Subsidiary subprogram used to climb to the parents
3588 procedure Collect (Typ : Entity_Id) is
3589 Tag_Comp : Entity_Id;
3590 Parent_Typ : Entity_Id;
3593 -- Handle private types
3595 if Present (Full_View (Etype (Typ))) then
3596 Parent_Typ := Full_View (Etype (Typ));
3598 Parent_Typ := Etype (Typ);
3601 if Parent_Typ /= Typ
3603 -- Protect the frontend against wrong sources. For example:
3606 -- type A is tagged null record;
3607 -- type B is new A with private;
3608 -- type C is new A with private;
3610 -- type B is new C with null record;
3611 -- type C is new B with null record;
3614 and then Parent_Typ /= Tagged_Type
3616 Collect (Parent_Typ);
3619 -- Collect the components containing tags of secondary dispatch
3622 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
3623 while Present (Tag_Comp) loop
3624 pragma Assert (Present (Related_Type (Tag_Comp)));
3625 Append_Elmt (Tag_Comp, Components_List);
3627 Tag_Comp := Next_Tag_Component (Tag_Comp);
3631 -- Start of processing for Collect_Interface_Components
3634 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
3635 and then Is_Tagged_Type (Tagged_Type));
3637 Components_List := New_Elmt_List;
3638 Collect (Tagged_Type);
3639 end Collect_Interface_Components;
3641 -----------------------------
3642 -- Collect_Interfaces_Info --
3643 -----------------------------
3645 procedure Collect_Interfaces_Info
3647 Ifaces_List : out Elist_Id;
3648 Components_List : out Elist_Id;
3649 Tags_List : out Elist_Id)
3651 Comps_List : Elist_Id;
3652 Comp_Elmt : Elmt_Id;
3653 Comp_Iface : Entity_Id;
3654 Iface_Elmt : Elmt_Id;
3657 function Search_Tag (Iface : Entity_Id) return Entity_Id;
3658 -- Search for the secondary tag associated with the interface type
3659 -- Iface that is implemented by T.
3665 function Search_Tag (Iface : Entity_Id) return Entity_Id is
3668 if not Is_CPP_Class (T) then
3669 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
3671 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
3675 and then Is_Tag (Node (ADT))
3676 and then Related_Type (Node (ADT)) /= Iface
3678 -- Skip secondary dispatch table referencing thunks to user
3679 -- defined primitives covered by this interface.
3681 pragma Assert (Has_Suffix (Node (ADT), 'P'));
3684 -- Skip secondary dispatch tables of Ada types
3686 if not Is_CPP_Class (T) then
3688 -- Skip secondary dispatch table referencing thunks to
3689 -- predefined primitives.
3691 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
3694 -- Skip secondary dispatch table referencing user-defined
3695 -- primitives covered by this interface.
3697 pragma Assert (Has_Suffix (Node (ADT), 'D'));
3700 -- Skip secondary dispatch table referencing predefined
3703 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
3708 pragma Assert (Is_Tag (Node (ADT)));
3712 -- Start of processing for Collect_Interfaces_Info
3715 Collect_Interfaces (T, Ifaces_List);
3716 Collect_Interface_Components (T, Comps_List);
3718 -- Search for the record component and tag associated with each
3719 -- interface type of T.
3721 Components_List := New_Elmt_List;
3722 Tags_List := New_Elmt_List;
3724 Iface_Elmt := First_Elmt (Ifaces_List);
3725 while Present (Iface_Elmt) loop
3726 Iface := Node (Iface_Elmt);
3728 -- Associate the primary tag component and the primary dispatch table
3729 -- with all the interfaces that are parents of T
3731 if Is_Ancestor (Iface, T, Use_Full_View => True) then
3732 Append_Elmt (First_Tag_Component (T), Components_List);
3733 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
3735 -- Otherwise search for the tag component and secondary dispatch
3739 Comp_Elmt := First_Elmt (Comps_List);
3740 while Present (Comp_Elmt) loop
3741 Comp_Iface := Related_Type (Node (Comp_Elmt));
3743 if Comp_Iface = Iface
3744 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
3746 Append_Elmt (Node (Comp_Elmt), Components_List);
3747 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
3751 Next_Elmt (Comp_Elmt);
3753 pragma Assert (Present (Comp_Elmt));
3756 Next_Elmt (Iface_Elmt);
3758 end Collect_Interfaces_Info;
3760 ---------------------
3761 -- Collect_Parents --
3762 ---------------------
3764 procedure Collect_Parents
3766 List : out Elist_Id;
3767 Use_Full_View : Boolean := True)
3769 Current_Typ : Entity_Id := T;
3770 Parent_Typ : Entity_Id;
3773 List := New_Elmt_List;
3775 -- No action if the if the type has no parents
3777 if T = Etype (T) then
3782 Parent_Typ := Etype (Current_Typ);
3784 if Is_Private_Type (Parent_Typ)
3785 and then Present (Full_View (Parent_Typ))
3786 and then Use_Full_View
3788 Parent_Typ := Full_View (Base_Type (Parent_Typ));
3791 Append_Elmt (Parent_Typ, List);
3793 exit when Parent_Typ = Current_Typ;
3794 Current_Typ := Parent_Typ;
3796 end Collect_Parents;
3798 ----------------------------------
3799 -- Collect_Primitive_Operations --
3800 ----------------------------------
3802 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
3803 B_Type : constant Entity_Id := Base_Type (T);
3804 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
3805 B_Scope : Entity_Id := Scope (B_Type);
3809 Is_Type_In_Pkg : Boolean;
3810 Formal_Derived : Boolean := False;
3813 function Match (E : Entity_Id) return Boolean;
3814 -- True if E's base type is B_Type, or E is of an anonymous access type
3815 -- and the base type of its designated type is B_Type.
3821 function Match (E : Entity_Id) return Boolean is
3822 Etyp : Entity_Id := Etype (E);
3825 if Ekind (Etyp) = E_Anonymous_Access_Type then
3826 Etyp := Designated_Type (Etyp);
3829 -- In Ada 2012 a primitive operation may have a formal of an
3830 -- incomplete view of the parent type.
3832 return Base_Type (Etyp) = B_Type
3834 (Ada_Version >= Ada_2012
3835 and then Ekind (Etyp) = E_Incomplete_Type
3836 and then Full_View (Etyp) = B_Type);
3839 -- Start of processing for Collect_Primitive_Operations
3842 -- For tagged types, the primitive operations are collected as they
3843 -- are declared, and held in an explicit list which is simply returned.
3845 if Is_Tagged_Type (B_Type) then
3846 return Primitive_Operations (B_Type);
3848 -- An untagged generic type that is a derived type inherits the
3849 -- primitive operations of its parent type. Other formal types only
3850 -- have predefined operators, which are not explicitly represented.
3852 elsif Is_Generic_Type (B_Type) then
3853 if Nkind (B_Decl) = N_Formal_Type_Declaration
3854 and then Nkind (Formal_Type_Definition (B_Decl)) =
3855 N_Formal_Derived_Type_Definition
3857 Formal_Derived := True;
3859 return New_Elmt_List;
3863 Op_List := New_Elmt_List;
3865 if B_Scope = Standard_Standard then
3866 if B_Type = Standard_String then
3867 Append_Elmt (Standard_Op_Concat, Op_List);
3869 elsif B_Type = Standard_Wide_String then
3870 Append_Elmt (Standard_Op_Concatw, Op_List);
3876 -- Locate the primitive subprograms of the type
3879 -- The primitive operations appear after the base type, except
3880 -- if the derivation happens within the private part of B_Scope
3881 -- and the type is a private type, in which case both the type
3882 -- and some primitive operations may appear before the base
3883 -- type, and the list of candidates starts after the type.
3885 if In_Open_Scopes (B_Scope)
3886 and then Scope (T) = B_Scope
3887 and then In_Private_Part (B_Scope)
3889 Id := Next_Entity (T);
3891 -- In Ada 2012, If the type has an incomplete partial view, there
3892 -- may be primitive operations declared before the full view, so
3893 -- we need to start scanning from the incomplete view, which is
3894 -- earlier on the entity chain.
3896 elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration
3897 and then Present (Incomplete_View (Parent (B_Type)))
3899 Id := Defining_Entity (Incomplete_View (Parent (B_Type)));
3902 Id := Next_Entity (B_Type);
3905 -- Set flag if this is a type in a package spec
3908 Is_Package_Or_Generic_Package (B_Scope)
3910 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
3913 while Present (Id) loop
3915 -- Test whether the result type or any of the parameter types of
3916 -- each subprogram following the type match that type when the
3917 -- type is declared in a package spec, is a derived type, or the
3918 -- subprogram is marked as primitive. (The Is_Primitive test is
3919 -- needed to find primitives of nonderived types in declarative
3920 -- parts that happen to override the predefined "=" operator.)
3922 -- Note that generic formal subprograms are not considered to be
3923 -- primitive operations and thus are never inherited.
3925 if Is_Overloadable (Id)
3926 and then (Is_Type_In_Pkg
3927 or else Is_Derived_Type (B_Type)
3928 or else Is_Primitive (Id))
3929 and then Nkind (Parent (Parent (Id)))
3930 not in N_Formal_Subprogram_Declaration
3938 Formal := First_Formal (Id);
3939 while Present (Formal) loop
3940 if Match (Formal) then
3945 Next_Formal (Formal);
3949 -- For a formal derived type, the only primitives are the ones
3950 -- inherited from the parent type. Operations appearing in the
3951 -- package declaration are not primitive for it.
3954 and then (not Formal_Derived or else Present (Alias (Id)))
3956 -- In the special case of an equality operator aliased to
3957 -- an overriding dispatching equality belonging to the same
3958 -- type, we don't include it in the list of primitives.
3959 -- This avoids inheriting multiple equality operators when
3960 -- deriving from untagged private types whose full type is
3961 -- tagged, which can otherwise cause ambiguities. Note that
3962 -- this should only happen for this kind of untagged parent
3963 -- type, since normally dispatching operations are inherited
3964 -- using the type's Primitive_Operations list.
3966 if Chars (Id) = Name_Op_Eq
3967 and then Is_Dispatching_Operation (Id)
3968 and then Present (Alias (Id))
3969 and then Present (Overridden_Operation (Alias (Id)))
3970 and then Base_Type (Etype (First_Entity (Id))) =
3971 Base_Type (Etype (First_Entity (Alias (Id))))
3975 -- Include the subprogram in the list of primitives
3978 Append_Elmt (Id, Op_List);
3985 -- For a type declared in System, some of its operations may
3986 -- appear in the target-specific extension to System.
3989 and then B_Scope = RTU_Entity (System)
3990 and then Present_System_Aux
3992 B_Scope := System_Aux_Id;
3993 Id := First_Entity (System_Aux_Id);
3999 end Collect_Primitive_Operations;
4001 -----------------------------------
4002 -- Compile_Time_Constraint_Error --
4003 -----------------------------------
4005 function Compile_Time_Constraint_Error
4008 Ent : Entity_Id := Empty;
4009 Loc : Source_Ptr := No_Location;
4010 Warn : Boolean := False) return Node_Id
4012 Msgc : String (1 .. Msg'Length + 3);
4013 -- Copy of message, with room for possible ?? or << and ! at end
4019 -- Start of processing for Compile_Time_Constraint_Error
4022 -- If this is a warning, convert it into an error if we are in code
4023 -- subject to SPARK_Mode being set ON.
4025 Error_Msg_Warn := SPARK_Mode /= On;
4027 -- A static constraint error in an instance body is not a fatal error.
4028 -- we choose to inhibit the message altogether, because there is no
4029 -- obvious node (for now) on which to post it. On the other hand the
4030 -- offending node must be replaced with a constraint_error in any case.
4032 -- No messages are generated if we already posted an error on this node
4034 if not Error_Posted (N) then
4035 if Loc /= No_Location then
4041 -- Copy message to Msgc, converting any ? in the message into
4042 -- < instead, so that we have an error in GNATprove mode.
4046 for J in 1 .. Msgl loop
4047 if Msg (J) = '?' and then (J = 1 or else Msg (J) /= ''') then
4050 Msgc (J) := Msg (J);
4054 -- Message is a warning, even in Ada 95 case
4056 if Msg (Msg'Last) = '?' or else Msg (Msg'Last) = '<' then
4059 -- In Ada 83, all messages are warnings. In the private part and
4060 -- the body of an instance, constraint_checks are only warnings.
4061 -- We also make this a warning if the Warn parameter is set.
4064 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
4072 elsif In_Instance_Not_Visible then
4079 -- Otherwise we have a real error message (Ada 95 static case)
4080 -- and we make this an unconditional message. Note that in the
4081 -- warning case we do not make the message unconditional, it seems
4082 -- quite reasonable to delete messages like this (about exceptions
4083 -- that will be raised) in dead code.
4091 -- One more test, skip the warning if the related expression is
4092 -- statically unevaluated, since we don't want to warn about what
4093 -- will happen when something is evaluated if it never will be
4096 if not Is_Statically_Unevaluated (N) then
4097 Error_Msg_Warn := SPARK_Mode /= On;
4099 if Present (Ent) then
4100 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
4102 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
4107 -- Check whether the context is an Init_Proc
4109 if Inside_Init_Proc then
4111 Conc_Typ : constant Entity_Id :=
4112 Corresponding_Concurrent_Type
4113 (Entity (Parameter_Type (First
4114 (Parameter_Specifications
4115 (Parent (Current_Scope))))));
4118 -- Don't complain if the corresponding concurrent type
4119 -- doesn't come from source (i.e. a single task/protected
4122 if Present (Conc_Typ)
4123 and then not Comes_From_Source (Conc_Typ)
4126 ("\& [<<", N, Standard_Constraint_Error, Eloc);
4129 if GNATprove_Mode then
4131 ("\& would have been raised for objects of this "
4132 & "type", N, Standard_Constraint_Error, Eloc);
4135 ("\& will be raised for objects of this type??",
4136 N, Standard_Constraint_Error, Eloc);
4142 Error_Msg_NEL ("\& [<<", N, Standard_Constraint_Error, Eloc);
4146 Error_Msg ("\static expression fails Constraint_Check", Eloc);
4147 Set_Error_Posted (N);
4153 end Compile_Time_Constraint_Error;
4155 -----------------------
4156 -- Conditional_Delay --
4157 -----------------------
4159 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
4161 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
4162 Set_Has_Delayed_Freeze (New_Ent);
4164 end Conditional_Delay;
4166 ----------------------------
4167 -- Contains_Refined_State --
4168 ----------------------------
4170 function Contains_Refined_State (Prag : Node_Id) return Boolean is
4171 function Has_State_In_Dependency (List : Node_Id) return Boolean;
4172 -- Determine whether a dependency list mentions a state with a visible
4175 function Has_State_In_Global (List : Node_Id) return Boolean;
4176 -- Determine whether a global list mentions a state with a visible
4179 function Is_Refined_State (Item : Node_Id) return Boolean;
4180 -- Determine whether Item is a reference to an abstract state with a
4181 -- visible refinement.
4183 -----------------------------
4184 -- Has_State_In_Dependency --
4185 -----------------------------
4187 function Has_State_In_Dependency (List : Node_Id) return Boolean is
4192 -- A null dependency list does not mention any states
4194 if Nkind (List) = N_Null then
4197 -- Dependency clauses appear as component associations of an
4200 elsif Nkind (List) = N_Aggregate
4201 and then Present (Component_Associations (List))
4203 Clause := First (Component_Associations (List));
4204 while Present (Clause) loop
4206 -- Inspect the outputs of a dependency clause
4208 Output := First (Choices (Clause));
4209 while Present (Output) loop
4210 if Is_Refined_State (Output) then
4217 -- Inspect the outputs of a dependency clause
4219 if Is_Refined_State (Expression (Clause)) then
4226 -- If we get here, then none of the dependency clauses mention a
4227 -- state with visible refinement.
4231 -- An illegal pragma managed to sneak in
4234 raise Program_Error;
4236 end Has_State_In_Dependency;
4238 -------------------------
4239 -- Has_State_In_Global --
4240 -------------------------
4242 function Has_State_In_Global (List : Node_Id) return Boolean is
4246 -- A null global list does not mention any states
4248 if Nkind (List) = N_Null then
4251 -- Simple global list or moded global list declaration
4253 elsif Nkind (List) = N_Aggregate then
4255 -- The declaration of a simple global list appear as a collection
4258 if Present (Expressions (List)) then
4259 Item := First (Expressions (List));
4260 while Present (Item) loop
4261 if Is_Refined_State (Item) then
4268 -- The declaration of a moded global list appears as a collection
4269 -- of component associations where individual choices denote
4273 Item := First (Component_Associations (List));
4274 while Present (Item) loop
4275 if Has_State_In_Global (Expression (Item)) then
4283 -- If we get here, then the simple/moded global list did not
4284 -- mention any states with a visible refinement.
4288 -- Single global item declaration
4290 elsif Is_Entity_Name (List) then
4291 return Is_Refined_State (List);
4293 -- An illegal pragma managed to sneak in
4296 raise Program_Error;
4298 end Has_State_In_Global;
4300 ----------------------
4301 -- Is_Refined_State --
4302 ----------------------
4304 function Is_Refined_State (Item : Node_Id) return Boolean is
4306 Item_Id : Entity_Id;
4309 if Nkind (Item) = N_Null then
4312 -- States cannot be subject to attribute 'Result. This case arises
4313 -- in dependency relations.
4315 elsif Nkind (Item) = N_Attribute_Reference
4316 and then Attribute_Name (Item) = Name_Result
4320 -- Multiple items appear as an aggregate. This case arises in
4321 -- dependency relations.
4323 elsif Nkind (Item) = N_Aggregate
4324 and then Present (Expressions (Item))
4326 Elmt := First (Expressions (Item));
4327 while Present (Elmt) loop
4328 if Is_Refined_State (Elmt) then
4335 -- If we get here, then none of the inputs or outputs reference a
4336 -- state with visible refinement.
4343 Item_Id := Entity_Of (Item);
4347 and then Ekind (Item_Id) = E_Abstract_State
4348 and then Has_Visible_Refinement (Item_Id);
4350 end Is_Refined_State;
4354 Arg : constant Node_Id :=
4355 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
4356 Nam : constant Name_Id := Pragma_Name (Prag);
4358 -- Start of processing for Contains_Refined_State
4361 if Nam = Name_Depends then
4362 return Has_State_In_Dependency (Arg);
4364 else pragma Assert (Nam = Name_Global);
4365 return Has_State_In_Global (Arg);
4367 end Contains_Refined_State;
4369 -------------------------
4370 -- Copy_Component_List --
4371 -------------------------
4373 function Copy_Component_List
4375 Loc : Source_Ptr) return List_Id
4378 Comps : constant List_Id := New_List;
4381 Comp := First_Component (Underlying_Type (R_Typ));
4382 while Present (Comp) loop
4383 if Comes_From_Source (Comp) then
4385 Comp_Decl : constant Node_Id := Declaration_Node (Comp);
4388 Make_Component_Declaration (Loc,
4389 Defining_Identifier =>
4390 Make_Defining_Identifier (Loc, Chars (Comp)),
4391 Component_Definition =>
4393 (Component_Definition (Comp_Decl), New_Sloc => Loc)));
4397 Next_Component (Comp);
4401 end Copy_Component_List;
4403 -------------------------
4404 -- Copy_Parameter_List --
4405 -------------------------
4407 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
4408 Loc : constant Source_Ptr := Sloc (Subp_Id);
4413 if No (First_Formal (Subp_Id)) then
4417 Formal := First_Formal (Subp_Id);
4418 while Present (Formal) loop
4420 Make_Parameter_Specification (Loc,
4421 Defining_Identifier =>
4422 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
4423 In_Present => In_Present (Parent (Formal)),
4424 Out_Present => Out_Present (Parent (Formal)),
4426 New_Occurrence_Of (Etype (Formal), Loc),
4428 New_Copy_Tree (Expression (Parent (Formal)))));
4430 Next_Formal (Formal);
4435 end Copy_Parameter_List;
4437 --------------------------
4438 -- Copy_Subprogram_Spec --
4439 --------------------------
4441 function Copy_Subprogram_Spec (Spec : Node_Id) return Node_Id is
4443 Formal_Spec : Node_Id;
4447 -- The structure of the original tree must be replicated without any
4448 -- alterations. Use New_Copy_Tree for this purpose.
4450 Result := New_Copy_Tree (Spec);
4452 -- Create a new entity for the defining unit name
4454 Def_Id := Defining_Unit_Name (Result);
4455 Set_Defining_Unit_Name (Result,
4456 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
4458 -- Create new entities for the formal parameters
4460 if Present (Parameter_Specifications (Result)) then
4461 Formal_Spec := First (Parameter_Specifications (Result));
4462 while Present (Formal_Spec) loop
4463 Def_Id := Defining_Identifier (Formal_Spec);
4464 Set_Defining_Identifier (Formal_Spec,
4465 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
4472 end Copy_Subprogram_Spec;
4474 --------------------------------
4475 -- Corresponding_Generic_Type --
4476 --------------------------------
4478 function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id is
4484 if not Is_Generic_Actual_Type (T) then
4487 -- If the actual is the actual of an enclosing instance, resolution
4488 -- was correct in the generic.
4490 elsif Nkind (Parent (T)) = N_Subtype_Declaration
4491 and then Is_Entity_Name (Subtype_Indication (Parent (T)))
4493 Is_Generic_Actual_Type (Entity (Subtype_Indication (Parent (T))))
4500 if Is_Wrapper_Package (Inst) then
4501 Inst := Related_Instance (Inst);
4506 (Specification (Unit_Declaration_Node (Inst)));
4508 -- Generic actual has the same name as the corresponding formal
4510 Typ := First_Entity (Gen);
4511 while Present (Typ) loop
4512 if Chars (Typ) = Chars (T) then
4521 end Corresponding_Generic_Type;
4523 ---------------------------
4524 -- Corresponding_Spec_Of --
4525 ---------------------------
4527 function Corresponding_Spec_Of (Decl : Node_Id) return Entity_Id is
4529 if Nkind_In (Decl, N_Package_Body, N_Subprogram_Body)
4530 and then Present (Corresponding_Spec (Decl))
4532 return Corresponding_Spec (Decl);
4534 elsif Nkind_In (Decl, N_Package_Body_Stub, N_Subprogram_Body_Stub)
4535 and then Present (Corresponding_Spec_Of_Stub (Decl))
4537 return Corresponding_Spec_Of_Stub (Decl);
4540 return Defining_Entity (Decl);
4542 end Corresponding_Spec_Of;
4544 -----------------------------
4545 -- Create_Generic_Contract --
4546 -----------------------------
4548 procedure Create_Generic_Contract (Unit : Node_Id) is
4549 Templ : constant Node_Id := Original_Node (Unit);
4550 Templ_Id : constant Entity_Id := Defining_Entity (Templ);
4552 procedure Add_Generic_Contract_Pragma (Prag : Node_Id);
4553 -- Add a single contract-related source pragma Prag to the contract of
4554 -- generic template Templ_Id.
4556 ---------------------------------
4557 -- Add_Generic_Contract_Pragma --
4558 ---------------------------------
4560 procedure Add_Generic_Contract_Pragma (Prag : Node_Id) is
4561 Prag_Templ : Node_Id;
4564 -- Mark the pragma to prevent the premature capture of global
4565 -- references when capturing global references of the context
4566 -- (see Save_References_In_Pragma).
4568 Set_Is_Generic_Contract_Pragma (Prag);
4570 -- Pragmas that apply to a generic subprogram declaration are not
4571 -- part of the semantic structure of the generic template:
4574 -- procedure Example (Formal : Integer);
4575 -- pragma Precondition (Formal > 0);
4577 -- Create a generic template for such pragmas and link the template
4578 -- of the pragma with the generic template.
4580 if Nkind (Templ) = N_Generic_Subprogram_Declaration then
4582 (Prag, Copy_Generic_Node (Prag, Empty, Instantiating => False));
4583 Prag_Templ := Original_Node (Prag);
4585 Set_Is_Generic_Contract_Pragma (Prag_Templ);
4586 Add_Contract_Item (Prag_Templ, Templ_Id);
4588 -- Otherwise link the pragma with the generic template
4591 Add_Contract_Item (Prag, Templ_Id);
4593 end Add_Generic_Contract_Pragma;
4597 Context : constant Node_Id := Parent (Unit);
4598 Decl : Node_Id := Empty;
4600 -- Start of processing for Create_Generic_Contract
4603 -- A generic package declaration carries contract-related source pragmas
4604 -- in its visible declarations.
4606 if Nkind (Templ) = N_Generic_Package_Declaration then
4607 Set_Ekind (Templ_Id, E_Generic_Package);
4609 if Present (Visible_Declarations (Specification (Templ))) then
4610 Decl := First (Visible_Declarations (Specification (Templ)));
4613 -- A generic package body carries contract-related source pragmas in its
4616 elsif Nkind (Templ) = N_Package_Body then
4617 Set_Ekind (Templ_Id, E_Package_Body);
4619 if Present (Declarations (Templ)) then
4620 Decl := First (Declarations (Templ));
4623 -- Generic subprogram declaration
4625 elsif Nkind (Templ) = N_Generic_Subprogram_Declaration then
4626 if Nkind (Specification (Templ)) = N_Function_Specification then
4627 Set_Ekind (Templ_Id, E_Generic_Function);
4629 Set_Ekind (Templ_Id, E_Generic_Procedure);
4632 -- When the generic subprogram acts as a compilation unit, inspect
4633 -- the Pragmas_After list for contract-related source pragmas.
4635 if Nkind (Context) = N_Compilation_Unit then
4636 if Present (Aux_Decls_Node (Context))
4637 and then Present (Pragmas_After (Aux_Decls_Node (Context)))
4639 Decl := First (Pragmas_After (Aux_Decls_Node (Context)));
4642 -- Otherwise inspect the successive declarations for contract-related
4646 Decl := Next (Unit);
4649 -- A generic subprogram body carries contract-related source pragmas in
4650 -- its declarations.
4652 elsif Nkind (Templ) = N_Subprogram_Body then
4653 Set_Ekind (Templ_Id, E_Subprogram_Body);
4655 if Present (Declarations (Templ)) then
4656 Decl := First (Declarations (Templ));
4660 -- Inspect the relevant declarations looking for contract-related source
4661 -- pragmas and add them to the contract of the generic unit.
4663 while Present (Decl) loop
4664 if Comes_From_Source (Decl) then
4665 if Nkind (Decl) = N_Pragma then
4667 -- The source pragma is a contract annotation
4669 if Is_Contract_Annotation (Decl) then
4670 Add_Generic_Contract_Pragma (Decl);
4673 -- The region where a contract-related source pragma may appear
4674 -- ends with the first source non-pragma declaration or statement.
4683 end Create_Generic_Contract;
4685 --------------------
4686 -- Current_Entity --
4687 --------------------
4689 -- The currently visible definition for a given identifier is the
4690 -- one most chained at the start of the visibility chain, i.e. the
4691 -- one that is referenced by the Node_Id value of the name of the
4692 -- given identifier.
4694 function Current_Entity (N : Node_Id) return Entity_Id is
4696 return Get_Name_Entity_Id (Chars (N));
4699 -----------------------------
4700 -- Current_Entity_In_Scope --
4701 -----------------------------
4703 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
4705 CS : constant Entity_Id := Current_Scope;
4707 Transient_Case : constant Boolean := Scope_Is_Transient;
4710 E := Get_Name_Entity_Id (Chars (N));
4712 and then Scope (E) /= CS
4713 and then (not Transient_Case or else Scope (E) /= Scope (CS))
4719 end Current_Entity_In_Scope;
4725 function Current_Scope return Entity_Id is
4727 if Scope_Stack.Last = -1 then
4728 return Standard_Standard;
4731 C : constant Entity_Id :=
4732 Scope_Stack.Table (Scope_Stack.Last).Entity;
4737 return Standard_Standard;
4743 ------------------------
4744 -- Current_Subprogram --
4745 ------------------------
4747 function Current_Subprogram return Entity_Id is
4748 Scop : constant Entity_Id := Current_Scope;
4750 if Is_Subprogram_Or_Generic_Subprogram (Scop) then
4753 return Enclosing_Subprogram (Scop);
4755 end Current_Subprogram;
4757 ----------------------------------
4758 -- Deepest_Type_Access_Level --
4759 ----------------------------------
4761 function Deepest_Type_Access_Level (Typ : Entity_Id) return Uint is
4763 if Ekind (Typ) = E_Anonymous_Access_Type
4764 and then not Is_Local_Anonymous_Access (Typ)
4765 and then Nkind (Associated_Node_For_Itype (Typ)) = N_Object_Declaration
4767 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
4771 Scope_Depth (Enclosing_Dynamic_Scope
4772 (Defining_Identifier
4773 (Associated_Node_For_Itype (Typ))));
4775 -- For generic formal type, return Int'Last (infinite).
4776 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
4778 elsif Is_Generic_Type (Root_Type (Typ)) then
4779 return UI_From_Int (Int'Last);
4782 return Type_Access_Level (Typ);
4784 end Deepest_Type_Access_Level;
4786 ---------------------
4787 -- Defining_Entity --
4788 ---------------------
4790 function Defining_Entity (N : Node_Id) return Entity_Id is
4791 K : constant Node_Kind := Nkind (N);
4792 Err : Entity_Id := Empty;
4797 N_Subprogram_Declaration |
4798 N_Abstract_Subprogram_Declaration |
4800 N_Package_Declaration |
4801 N_Subprogram_Renaming_Declaration |
4802 N_Subprogram_Body_Stub |
4803 N_Generic_Subprogram_Declaration |
4804 N_Generic_Package_Declaration |
4805 N_Formal_Subprogram_Declaration |
4806 N_Expression_Function
4808 return Defining_Entity (Specification (N));
4811 N_Component_Declaration |
4812 N_Defining_Program_Unit_Name |
4813 N_Discriminant_Specification |
4815 N_Entry_Declaration |
4816 N_Entry_Index_Specification |
4817 N_Exception_Declaration |
4818 N_Exception_Renaming_Declaration |
4819 N_Formal_Object_Declaration |
4820 N_Formal_Package_Declaration |
4821 N_Formal_Type_Declaration |
4822 N_Full_Type_Declaration |
4823 N_Implicit_Label_Declaration |
4824 N_Incomplete_Type_Declaration |
4825 N_Loop_Parameter_Specification |
4826 N_Number_Declaration |
4827 N_Object_Declaration |
4828 N_Object_Renaming_Declaration |
4829 N_Package_Body_Stub |
4830 N_Parameter_Specification |
4831 N_Private_Extension_Declaration |
4832 N_Private_Type_Declaration |
4834 N_Protected_Body_Stub |
4835 N_Protected_Type_Declaration |
4836 N_Single_Protected_Declaration |
4837 N_Single_Task_Declaration |
4838 N_Subtype_Declaration |
4841 N_Task_Type_Declaration
4843 return Defining_Identifier (N);
4846 return Defining_Entity (Proper_Body (N));
4849 N_Function_Instantiation |
4850 N_Function_Specification |
4851 N_Generic_Function_Renaming_Declaration |
4852 N_Generic_Package_Renaming_Declaration |
4853 N_Generic_Procedure_Renaming_Declaration |
4855 N_Package_Instantiation |
4856 N_Package_Renaming_Declaration |
4857 N_Package_Specification |
4858 N_Procedure_Instantiation |
4859 N_Procedure_Specification
4862 Nam : constant Node_Id := Defining_Unit_Name (N);
4865 if Nkind (Nam) in N_Entity then
4868 -- For Error, make up a name and attach to declaration
4869 -- so we can continue semantic analysis
4871 elsif Nam = Error then
4872 Err := Make_Temporary (Sloc (N), 'T');
4873 Set_Defining_Unit_Name (N, Err);
4877 -- If not an entity, get defining identifier
4880 return Defining_Identifier (Nam);
4888 return Entity (Identifier (N));
4891 raise Program_Error;
4894 end Defining_Entity;
4896 --------------------------
4897 -- Denotes_Discriminant --
4898 --------------------------
4900 function Denotes_Discriminant
4902 Check_Concurrent : Boolean := False) return Boolean
4907 if not Is_Entity_Name (N) or else No (Entity (N)) then
4913 -- If we are checking for a protected type, the discriminant may have
4914 -- been rewritten as the corresponding discriminal of the original type
4915 -- or of the corresponding concurrent record, depending on whether we
4916 -- are in the spec or body of the protected type.
4918 return Ekind (E) = E_Discriminant
4921 and then Ekind (E) = E_In_Parameter
4922 and then Present (Discriminal_Link (E))
4924 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
4926 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
4928 end Denotes_Discriminant;
4930 -------------------------
4931 -- Denotes_Same_Object --
4932 -------------------------
4934 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
4935 Obj1 : Node_Id := A1;
4936 Obj2 : Node_Id := A2;
4938 function Has_Prefix (N : Node_Id) return Boolean;
4939 -- Return True if N has attribute Prefix
4941 function Is_Renaming (N : Node_Id) return Boolean;
4942 -- Return true if N names a renaming entity
4944 function Is_Valid_Renaming (N : Node_Id) return Boolean;
4945 -- For renamings, return False if the prefix of any dereference within
4946 -- the renamed object_name is a variable, or any expression within the
4947 -- renamed object_name contains references to variables or calls on
4948 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
4954 function Has_Prefix (N : Node_Id) return Boolean is
4958 N_Attribute_Reference,
4960 N_Explicit_Dereference,
4961 N_Indexed_Component,
4963 N_Selected_Component,
4971 function Is_Renaming (N : Node_Id) return Boolean is
4973 return Is_Entity_Name (N)
4974 and then Present (Renamed_Entity (Entity (N)));
4977 -----------------------
4978 -- Is_Valid_Renaming --
4979 -----------------------
4981 function Is_Valid_Renaming (N : Node_Id) return Boolean is
4983 function Check_Renaming (N : Node_Id) return Boolean;
4984 -- Recursive function used to traverse all the prefixes of N
4986 function Check_Renaming (N : Node_Id) return Boolean is
4989 and then not Check_Renaming (Renamed_Entity (Entity (N)))
4994 if Nkind (N) = N_Indexed_Component then
4999 Indx := First (Expressions (N));
5000 while Present (Indx) loop
5001 if not Is_OK_Static_Expression (Indx) then
5010 if Has_Prefix (N) then
5012 P : constant Node_Id := Prefix (N);
5015 if Nkind (N) = N_Explicit_Dereference
5016 and then Is_Variable (P)
5020 elsif Is_Entity_Name (P)
5021 and then Ekind (Entity (P)) = E_Function
5025 elsif Nkind (P) = N_Function_Call then
5029 -- Recursion to continue traversing the prefix of the
5030 -- renaming expression
5032 return Check_Renaming (P);
5039 -- Start of processing for Is_Valid_Renaming
5042 return Check_Renaming (N);
5043 end Is_Valid_Renaming;
5045 -- Start of processing for Denotes_Same_Object
5048 -- Both names statically denote the same stand-alone object or parameter
5049 -- (RM 6.4.1(6.5/3))
5051 if Is_Entity_Name (Obj1)
5052 and then Is_Entity_Name (Obj2)
5053 and then Entity (Obj1) = Entity (Obj2)
5058 -- For renamings, the prefix of any dereference within the renamed
5059 -- object_name is not a variable, and any expression within the
5060 -- renamed object_name contains no references to variables nor
5061 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
5063 if Is_Renaming (Obj1) then
5064 if Is_Valid_Renaming (Obj1) then
5065 Obj1 := Renamed_Entity (Entity (Obj1));
5071 if Is_Renaming (Obj2) then
5072 if Is_Valid_Renaming (Obj2) then
5073 Obj2 := Renamed_Entity (Entity (Obj2));
5079 -- No match if not same node kind (such cases are handled by
5080 -- Denotes_Same_Prefix)
5082 if Nkind (Obj1) /= Nkind (Obj2) then
5085 -- After handling valid renamings, one of the two names statically
5086 -- denoted a renaming declaration whose renamed object_name is known
5087 -- to denote the same object as the other (RM 6.4.1(6.10/3))
5089 elsif Is_Entity_Name (Obj1) then
5090 if Is_Entity_Name (Obj2) then
5091 return Entity (Obj1) = Entity (Obj2);
5096 -- Both names are selected_components, their prefixes are known to
5097 -- denote the same object, and their selector_names denote the same
5098 -- component (RM 6.4.1(6.6/3)).
5100 elsif Nkind (Obj1) = N_Selected_Component then
5101 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
5103 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
5105 -- Both names are dereferences and the dereferenced names are known to
5106 -- denote the same object (RM 6.4.1(6.7/3))
5108 elsif Nkind (Obj1) = N_Explicit_Dereference then
5109 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
5111 -- Both names are indexed_components, their prefixes are known to denote
5112 -- the same object, and each of the pairs of corresponding index values
5113 -- are either both static expressions with the same static value or both
5114 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
5116 elsif Nkind (Obj1) = N_Indexed_Component then
5117 if not Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
5125 Indx1 := First (Expressions (Obj1));
5126 Indx2 := First (Expressions (Obj2));
5127 while Present (Indx1) loop
5129 -- Indexes must denote the same static value or same object
5131 if Is_OK_Static_Expression (Indx1) then
5132 if not Is_OK_Static_Expression (Indx2) then
5135 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
5139 elsif not Denotes_Same_Object (Indx1, Indx2) then
5151 -- Both names are slices, their prefixes are known to denote the same
5152 -- object, and the two slices have statically matching index constraints
5153 -- (RM 6.4.1(6.9/3))
5155 elsif Nkind (Obj1) = N_Slice
5156 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
5159 Lo1, Lo2, Hi1, Hi2 : Node_Id;
5162 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
5163 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
5165 -- Check whether bounds are statically identical. There is no
5166 -- attempt to detect partial overlap of slices.
5168 return Denotes_Same_Object (Lo1, Lo2)
5170 Denotes_Same_Object (Hi1, Hi2);
5173 -- In the recursion, literals appear as indexes
5175 elsif Nkind (Obj1) = N_Integer_Literal
5177 Nkind (Obj2) = N_Integer_Literal
5179 return Intval (Obj1) = Intval (Obj2);
5184 end Denotes_Same_Object;
5186 -------------------------
5187 -- Denotes_Same_Prefix --
5188 -------------------------
5190 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
5193 if Is_Entity_Name (A1) then
5194 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
5195 and then not Is_Access_Type (Etype (A1))
5197 return Denotes_Same_Object (A1, Prefix (A2))
5198 or else Denotes_Same_Prefix (A1, Prefix (A2));
5203 elsif Is_Entity_Name (A2) then
5204 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
5206 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
5208 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
5211 Root1, Root2 : Node_Id;
5212 Depth1, Depth2 : Int := 0;
5215 Root1 := Prefix (A1);
5216 while not Is_Entity_Name (Root1) loop
5218 (Root1, N_Selected_Component, N_Indexed_Component)
5222 Root1 := Prefix (Root1);
5225 Depth1 := Depth1 + 1;
5228 Root2 := Prefix (A2);
5229 while not Is_Entity_Name (Root2) loop
5230 if not Nkind_In (Root2, N_Selected_Component,
5231 N_Indexed_Component)
5235 Root2 := Prefix (Root2);
5238 Depth2 := Depth2 + 1;
5241 -- If both have the same depth and they do not denote the same
5242 -- object, they are disjoint and no warning is needed.
5244 if Depth1 = Depth2 then
5247 elsif Depth1 > Depth2 then
5248 Root1 := Prefix (A1);
5249 for J in 1 .. Depth1 - Depth2 - 1 loop
5250 Root1 := Prefix (Root1);
5253 return Denotes_Same_Object (Root1, A2);
5256 Root2 := Prefix (A2);
5257 for J in 1 .. Depth2 - Depth1 - 1 loop
5258 Root2 := Prefix (Root2);
5261 return Denotes_Same_Object (A1, Root2);
5268 end Denotes_Same_Prefix;
5270 ----------------------
5271 -- Denotes_Variable --
5272 ----------------------
5274 function Denotes_Variable (N : Node_Id) return Boolean is
5276 return Is_Variable (N) and then Paren_Count (N) = 0;
5277 end Denotes_Variable;
5279 -----------------------------
5280 -- Depends_On_Discriminant --
5281 -----------------------------
5283 function Depends_On_Discriminant (N : Node_Id) return Boolean is
5288 Get_Index_Bounds (N, L, H);
5289 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
5290 end Depends_On_Discriminant;
5292 -------------------------
5293 -- Designate_Same_Unit --
5294 -------------------------
5296 function Designate_Same_Unit
5298 Name2 : Node_Id) return Boolean
5300 K1 : constant Node_Kind := Nkind (Name1);
5301 K2 : constant Node_Kind := Nkind (Name2);
5303 function Prefix_Node (N : Node_Id) return Node_Id;
5304 -- Returns the parent unit name node of a defining program unit name
5305 -- or the prefix if N is a selected component or an expanded name.
5307 function Select_Node (N : Node_Id) return Node_Id;
5308 -- Returns the defining identifier node of a defining program unit
5309 -- name or the selector node if N is a selected component or an
5316 function Prefix_Node (N : Node_Id) return Node_Id is
5318 if Nkind (N) = N_Defining_Program_Unit_Name then
5329 function Select_Node (N : Node_Id) return Node_Id is
5331 if Nkind (N) = N_Defining_Program_Unit_Name then
5332 return Defining_Identifier (N);
5334 return Selector_Name (N);
5338 -- Start of processing for Designate_Same_Unit
5341 if Nkind_In (K1, N_Identifier, N_Defining_Identifier)
5343 Nkind_In (K2, N_Identifier, N_Defining_Identifier)
5345 return Chars (Name1) = Chars (Name2);
5347 elsif Nkind_In (K1, N_Expanded_Name,
5348 N_Selected_Component,
5349 N_Defining_Program_Unit_Name)
5351 Nkind_In (K2, N_Expanded_Name,
5352 N_Selected_Component,
5353 N_Defining_Program_Unit_Name)
5356 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
5358 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
5363 end Designate_Same_Unit;
5365 ------------------------------------------
5366 -- function Dynamic_Accessibility_Level --
5367 ------------------------------------------
5369 function Dynamic_Accessibility_Level (Expr : Node_Id) return Node_Id is
5371 Loc : constant Source_Ptr := Sloc (Expr);
5373 function Make_Level_Literal (Level : Uint) return Node_Id;
5374 -- Construct an integer literal representing an accessibility level
5375 -- with its type set to Natural.
5377 ------------------------
5378 -- Make_Level_Literal --
5379 ------------------------
5381 function Make_Level_Literal (Level : Uint) return Node_Id is
5382 Result : constant Node_Id := Make_Integer_Literal (Loc, Level);
5384 Set_Etype (Result, Standard_Natural);
5386 end Make_Level_Literal;
5388 -- Start of processing for Dynamic_Accessibility_Level
5391 if Is_Entity_Name (Expr) then
5394 if Present (Renamed_Object (E)) then
5395 return Dynamic_Accessibility_Level (Renamed_Object (E));
5398 if Is_Formal (E) or else Ekind_In (E, E_Variable, E_Constant) then
5399 if Present (Extra_Accessibility (E)) then
5400 return New_Occurrence_Of (Extra_Accessibility (E), Loc);
5405 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
5407 case Nkind (Expr) is
5409 -- For access discriminant, the level of the enclosing object
5411 when N_Selected_Component =>
5412 if Ekind (Entity (Selector_Name (Expr))) = E_Discriminant
5413 and then Ekind (Etype (Entity (Selector_Name (Expr)))) =
5414 E_Anonymous_Access_Type
5416 return Make_Level_Literal (Object_Access_Level (Expr));
5419 when N_Attribute_Reference =>
5420 case Get_Attribute_Id (Attribute_Name (Expr)) is
5422 -- For X'Access, the level of the prefix X
5424 when Attribute_Access =>
5425 return Make_Level_Literal
5426 (Object_Access_Level (Prefix (Expr)));
5428 -- Treat the unchecked attributes as library-level
5430 when Attribute_Unchecked_Access |
5431 Attribute_Unrestricted_Access =>
5432 return Make_Level_Literal (Scope_Depth (Standard_Standard));
5434 -- No other access-valued attributes
5437 raise Program_Error;
5442 -- Unimplemented: depends on context. As an actual parameter where
5443 -- formal type is anonymous, use
5444 -- Scope_Depth (Current_Scope) + 1.
5445 -- For other cases, see 3.10.2(14/3) and following. ???
5449 when N_Type_Conversion =>
5450 if not Is_Local_Anonymous_Access (Etype (Expr)) then
5452 -- Handle type conversions introduced for a rename of an
5453 -- Ada 2012 stand-alone object of an anonymous access type.
5455 return Dynamic_Accessibility_Level (Expression (Expr));
5462 return Make_Level_Literal (Type_Access_Level (Etype (Expr)));
5463 end Dynamic_Accessibility_Level;
5465 -----------------------------------
5466 -- Effective_Extra_Accessibility --
5467 -----------------------------------
5469 function Effective_Extra_Accessibility (Id : Entity_Id) return Entity_Id is
5471 if Present (Renamed_Object (Id))
5472 and then Is_Entity_Name (Renamed_Object (Id))
5474 return Effective_Extra_Accessibility (Entity (Renamed_Object (Id)));
5476 return Extra_Accessibility (Id);
5478 end Effective_Extra_Accessibility;
5480 -----------------------------
5481 -- Effective_Reads_Enabled --
5482 -----------------------------
5484 function Effective_Reads_Enabled (Id : Entity_Id) return Boolean is
5486 return Has_Enabled_Property (Id, Name_Effective_Reads);
5487 end Effective_Reads_Enabled;
5489 ------------------------------
5490 -- Effective_Writes_Enabled --
5491 ------------------------------
5493 function Effective_Writes_Enabled (Id : Entity_Id) return Boolean is
5495 return Has_Enabled_Property (Id, Name_Effective_Writes);
5496 end Effective_Writes_Enabled;
5498 ------------------------------
5499 -- Enclosing_Comp_Unit_Node --
5500 ------------------------------
5502 function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id is
5503 Current_Node : Node_Id;
5507 while Present (Current_Node)
5508 and then Nkind (Current_Node) /= N_Compilation_Unit
5510 Current_Node := Parent (Current_Node);
5513 if Nkind (Current_Node) /= N_Compilation_Unit then
5516 return Current_Node;
5518 end Enclosing_Comp_Unit_Node;
5520 --------------------------
5521 -- Enclosing_CPP_Parent --
5522 --------------------------
5524 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
5525 Parent_Typ : Entity_Id := Typ;
5528 while not Is_CPP_Class (Parent_Typ)
5529 and then Etype (Parent_Typ) /= Parent_Typ
5531 Parent_Typ := Etype (Parent_Typ);
5533 if Is_Private_Type (Parent_Typ) then
5534 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5538 pragma Assert (Is_CPP_Class (Parent_Typ));
5540 end Enclosing_CPP_Parent;
5542 ----------------------------
5543 -- Enclosing_Generic_Body --
5544 ----------------------------
5546 function Enclosing_Generic_Body
5547 (N : Node_Id) return Node_Id
5555 while Present (P) loop
5556 if Nkind (P) = N_Package_Body
5557 or else Nkind (P) = N_Subprogram_Body
5559 Spec := Corresponding_Spec (P);
5561 if Present (Spec) then
5562 Decl := Unit_Declaration_Node (Spec);
5564 if Nkind (Decl) = N_Generic_Package_Declaration
5565 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
5576 end Enclosing_Generic_Body;
5578 ----------------------------
5579 -- Enclosing_Generic_Unit --
5580 ----------------------------
5582 function Enclosing_Generic_Unit
5583 (N : Node_Id) return Node_Id
5591 while Present (P) loop
5592 if Nkind (P) = N_Generic_Package_Declaration
5593 or else Nkind (P) = N_Generic_Subprogram_Declaration
5597 elsif Nkind (P) = N_Package_Body
5598 or else Nkind (P) = N_Subprogram_Body
5600 Spec := Corresponding_Spec (P);
5602 if Present (Spec) then
5603 Decl := Unit_Declaration_Node (Spec);
5605 if Nkind (Decl) = N_Generic_Package_Declaration
5606 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
5617 end Enclosing_Generic_Unit;
5619 -------------------------------
5620 -- Enclosing_Lib_Unit_Entity --
5621 -------------------------------
5623 function Enclosing_Lib_Unit_Entity
5624 (E : Entity_Id := Current_Scope) return Entity_Id
5626 Unit_Entity : Entity_Id;
5629 -- Look for enclosing library unit entity by following scope links.
5630 -- Equivalent to, but faster than indexing through the scope stack.
5633 while (Present (Scope (Unit_Entity))
5634 and then Scope (Unit_Entity) /= Standard_Standard)
5635 and not Is_Child_Unit (Unit_Entity)
5637 Unit_Entity := Scope (Unit_Entity);
5641 end Enclosing_Lib_Unit_Entity;
5643 -----------------------
5644 -- Enclosing_Package --
5645 -----------------------
5647 function Enclosing_Package (E : Entity_Id) return Entity_Id is
5648 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
5651 if Dynamic_Scope = Standard_Standard then
5652 return Standard_Standard;
5654 elsif Dynamic_Scope = Empty then
5657 elsif Ekind_In (Dynamic_Scope, E_Package, E_Package_Body,
5660 return Dynamic_Scope;
5663 return Enclosing_Package (Dynamic_Scope);
5665 end Enclosing_Package;
5667 --------------------------
5668 -- Enclosing_Subprogram --
5669 --------------------------
5671 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
5672 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
5675 if Dynamic_Scope = Standard_Standard then
5678 elsif Dynamic_Scope = Empty then
5681 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
5682 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
5684 elsif Ekind (Dynamic_Scope) = E_Block
5685 or else Ekind (Dynamic_Scope) = E_Return_Statement
5687 return Enclosing_Subprogram (Dynamic_Scope);
5689 elsif Ekind (Dynamic_Scope) = E_Task_Type then
5690 return Get_Task_Body_Procedure (Dynamic_Scope);
5692 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
5693 and then Present (Full_View (Dynamic_Scope))
5694 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
5696 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
5698 -- No body is generated if the protected operation is eliminated
5700 elsif Convention (Dynamic_Scope) = Convention_Protected
5701 and then not Is_Eliminated (Dynamic_Scope)
5702 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
5704 return Protected_Body_Subprogram (Dynamic_Scope);
5707 return Dynamic_Scope;
5709 end Enclosing_Subprogram;
5711 ------------------------
5712 -- Ensure_Freeze_Node --
5713 ------------------------
5715 procedure Ensure_Freeze_Node (E : Entity_Id) is
5718 if No (Freeze_Node (E)) then
5719 FN := Make_Freeze_Entity (Sloc (E));
5720 Set_Has_Delayed_Freeze (E);
5721 Set_Freeze_Node (E, FN);
5722 Set_Access_Types_To_Process (FN, No_Elist);
5723 Set_TSS_Elist (FN, No_Elist);
5726 end Ensure_Freeze_Node;
5732 procedure Enter_Name (Def_Id : Entity_Id) is
5733 C : constant Entity_Id := Current_Entity (Def_Id);
5734 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
5735 S : constant Entity_Id := Current_Scope;
5738 Generate_Definition (Def_Id);
5740 -- Add new name to current scope declarations. Check for duplicate
5741 -- declaration, which may or may not be a genuine error.
5745 -- Case of previous entity entered because of a missing declaration
5746 -- or else a bad subtype indication. Best is to use the new entity,
5747 -- and make the previous one invisible.
5749 if Etype (E) = Any_Type then
5750 Set_Is_Immediately_Visible (E, False);
5752 -- Case of renaming declaration constructed for package instances.
5753 -- if there is an explicit declaration with the same identifier,
5754 -- the renaming is not immediately visible any longer, but remains
5755 -- visible through selected component notation.
5757 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
5758 and then not Comes_From_Source (E)
5760 Set_Is_Immediately_Visible (E, False);
5762 -- The new entity may be the package renaming, which has the same
5763 -- same name as a generic formal which has been seen already.
5765 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
5766 and then not Comes_From_Source (Def_Id)
5768 Set_Is_Immediately_Visible (E, False);
5770 -- For a fat pointer corresponding to a remote access to subprogram,
5771 -- we use the same identifier as the RAS type, so that the proper
5772 -- name appears in the stub. This type is only retrieved through
5773 -- the RAS type and never by visibility, and is not added to the
5774 -- visibility list (see below).
5776 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
5777 and then Ekind (Def_Id) = E_Record_Type
5778 and then Present (Corresponding_Remote_Type (Def_Id))
5782 -- Case of an implicit operation or derived literal. The new entity
5783 -- hides the implicit one, which is removed from all visibility,
5784 -- i.e. the entity list of its scope, and homonym chain of its name.
5786 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
5787 or else Is_Internal (E)
5791 Prev_Vis : Entity_Id;
5792 Decl : constant Node_Id := Parent (E);
5795 -- If E is an implicit declaration, it cannot be the first
5796 -- entity in the scope.
5798 Prev := First_Entity (Current_Scope);
5799 while Present (Prev) and then Next_Entity (Prev) /= E loop
5805 -- If E is not on the entity chain of the current scope,
5806 -- it is an implicit declaration in the generic formal
5807 -- part of a generic subprogram. When analyzing the body,
5808 -- the generic formals are visible but not on the entity
5809 -- chain of the subprogram. The new entity will become
5810 -- the visible one in the body.
5813 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
5817 Set_Next_Entity (Prev, Next_Entity (E));
5819 if No (Next_Entity (Prev)) then
5820 Set_Last_Entity (Current_Scope, Prev);
5823 if E = Current_Entity (E) then
5827 Prev_Vis := Current_Entity (E);
5828 while Homonym (Prev_Vis) /= E loop
5829 Prev_Vis := Homonym (Prev_Vis);
5833 if Present (Prev_Vis) then
5835 -- Skip E in the visibility chain
5837 Set_Homonym (Prev_Vis, Homonym (E));
5840 Set_Name_Entity_Id (Chars (E), Homonym (E));
5845 -- This section of code could use a comment ???
5847 elsif Present (Etype (E))
5848 and then Is_Concurrent_Type (Etype (E))
5853 -- If the homograph is a protected component renaming, it should not
5854 -- be hiding the current entity. Such renamings are treated as weak
5857 elsif Is_Prival (E) then
5858 Set_Is_Immediately_Visible (E, False);
5860 -- In this case the current entity is a protected component renaming.
5861 -- Perform minimal decoration by setting the scope and return since
5862 -- the prival should not be hiding other visible entities.
5864 elsif Is_Prival (Def_Id) then
5865 Set_Scope (Def_Id, Current_Scope);
5868 -- Analogous to privals, the discriminal generated for an entry index
5869 -- parameter acts as a weak declaration. Perform minimal decoration
5870 -- to avoid bogus errors.
5872 elsif Is_Discriminal (Def_Id)
5873 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
5875 Set_Scope (Def_Id, Current_Scope);
5878 -- In the body or private part of an instance, a type extension may
5879 -- introduce a component with the same name as that of an actual. The
5880 -- legality rule is not enforced, but the semantics of the full type
5881 -- with two components of same name are not clear at this point???
5883 elsif In_Instance_Not_Visible then
5886 -- When compiling a package body, some child units may have become
5887 -- visible. They cannot conflict with local entities that hide them.
5889 elsif Is_Child_Unit (E)
5890 and then In_Open_Scopes (Scope (E))
5891 and then not Is_Immediately_Visible (E)
5895 -- Conversely, with front-end inlining we may compile the parent body
5896 -- first, and a child unit subsequently. The context is now the
5897 -- parent spec, and body entities are not visible.
5899 elsif Is_Child_Unit (Def_Id)
5900 and then Is_Package_Body_Entity (E)
5901 and then not In_Package_Body (Current_Scope)
5905 -- Case of genuine duplicate declaration
5908 Error_Msg_Sloc := Sloc (E);
5910 -- If the previous declaration is an incomplete type declaration
5911 -- this may be an attempt to complete it with a private type. The
5912 -- following avoids confusing cascaded errors.
5914 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
5915 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
5918 ("incomplete type cannot be completed with a private " &
5919 "declaration", Parent (Def_Id));
5920 Set_Is_Immediately_Visible (E, False);
5921 Set_Full_View (E, Def_Id);
5923 -- An inherited component of a record conflicts with a new
5924 -- discriminant. The discriminant is inserted first in the scope,
5925 -- but the error should be posted on it, not on the component.
5927 elsif Ekind (E) = E_Discriminant
5928 and then Present (Scope (Def_Id))
5929 and then Scope (Def_Id) /= Current_Scope
5931 Error_Msg_Sloc := Sloc (Def_Id);
5932 Error_Msg_N ("& conflicts with declaration#", E);
5935 -- If the name of the unit appears in its own context clause, a
5936 -- dummy package with the name has already been created, and the
5937 -- error emitted. Try to continue quietly.
5939 elsif Error_Posted (E)
5940 and then Sloc (E) = No_Location
5941 and then Nkind (Parent (E)) = N_Package_Specification
5942 and then Current_Scope = Standard_Standard
5944 Set_Scope (Def_Id, Current_Scope);
5948 Error_Msg_N ("& conflicts with declaration#", Def_Id);
5950 -- Avoid cascaded messages with duplicate components in
5953 if Ekind_In (E, E_Component, E_Discriminant) then
5958 if Nkind (Parent (Parent (Def_Id))) =
5959 N_Generic_Subprogram_Declaration
5961 Defining_Entity (Specification (Parent (Parent (Def_Id))))
5963 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
5966 -- If entity is in standard, then we are in trouble, because it
5967 -- means that we have a library package with a duplicated name.
5968 -- That's hard to recover from, so abort.
5970 if S = Standard_Standard then
5971 raise Unrecoverable_Error;
5973 -- Otherwise we continue with the declaration. Having two
5974 -- identical declarations should not cause us too much trouble.
5982 -- If we fall through, declaration is OK, at least OK enough to continue
5984 -- If Def_Id is a discriminant or a record component we are in the midst
5985 -- of inheriting components in a derived record definition. Preserve
5986 -- their Ekind and Etype.
5988 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
5991 -- If a type is already set, leave it alone (happens when a type
5992 -- declaration is reanalyzed following a call to the optimizer).
5994 elsif Present (Etype (Def_Id)) then
5997 -- Otherwise, the kind E_Void insures that premature uses of the entity
5998 -- will be detected. Any_Type insures that no cascaded errors will occur
6001 Set_Ekind (Def_Id, E_Void);
6002 Set_Etype (Def_Id, Any_Type);
6005 -- Inherited discriminants and components in derived record types are
6006 -- immediately visible. Itypes are not.
6008 -- Unless the Itype is for a record type with a corresponding remote
6009 -- type (what is that about, it was not commented ???)
6011 if Ekind_In (Def_Id, E_Discriminant, E_Component)
6013 ((not Is_Record_Type (Def_Id)
6014 or else No (Corresponding_Remote_Type (Def_Id)))
6015 and then not Is_Itype (Def_Id))
6017 Set_Is_Immediately_Visible (Def_Id);
6018 Set_Current_Entity (Def_Id);
6021 Set_Homonym (Def_Id, C);
6022 Append_Entity (Def_Id, S);
6023 Set_Public_Status (Def_Id);
6025 -- Declaring a homonym is not allowed in SPARK ...
6027 if Present (C) and then Restriction_Check_Required (SPARK_05) then
6029 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
6030 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
6031 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
6034 -- ... unless the new declaration is in a subprogram, and the
6035 -- visible declaration is a variable declaration or a parameter
6036 -- specification outside that subprogram.
6038 if Present (Enclosing_Subp)
6039 and then Nkind_In (Parent (C), N_Object_Declaration,
6040 N_Parameter_Specification)
6041 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
6045 -- ... or the new declaration is in a package, and the visible
6046 -- declaration occurs outside that package.
6048 elsif Present (Enclosing_Pack)
6049 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
6053 -- ... or the new declaration is a component declaration in a
6054 -- record type definition.
6056 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
6059 -- Don't issue error for non-source entities
6061 elsif Comes_From_Source (Def_Id)
6062 and then Comes_From_Source (C)
6064 Error_Msg_Sloc := Sloc (C);
6065 Check_SPARK_05_Restriction
6066 ("redeclaration of identifier &#", Def_Id);
6071 -- Warn if new entity hides an old one
6073 if Warn_On_Hiding and then Present (C)
6075 -- Don't warn for record components since they always have a well
6076 -- defined scope which does not confuse other uses. Note that in
6077 -- some cases, Ekind has not been set yet.
6079 and then Ekind (C) /= E_Component
6080 and then Ekind (C) /= E_Discriminant
6081 and then Nkind (Parent (C)) /= N_Component_Declaration
6082 and then Ekind (Def_Id) /= E_Component
6083 and then Ekind (Def_Id) /= E_Discriminant
6084 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
6086 -- Don't warn for one character variables. It is too common to use
6087 -- such variables as locals and will just cause too many false hits.
6089 and then Length_Of_Name (Chars (C)) /= 1
6091 -- Don't warn for non-source entities
6093 and then Comes_From_Source (C)
6094 and then Comes_From_Source (Def_Id)
6096 -- Don't warn unless entity in question is in extended main source
6098 and then In_Extended_Main_Source_Unit (Def_Id)
6100 -- Finally, the hidden entity must be either immediately visible or
6101 -- use visible (i.e. from a used package).
6104 (Is_Immediately_Visible (C)
6106 Is_Potentially_Use_Visible (C))
6108 Error_Msg_Sloc := Sloc (C);
6109 Error_Msg_N ("declaration hides &#?h?", Def_Id);
6117 function Entity_Of (N : Node_Id) return Entity_Id is
6123 if Is_Entity_Name (N) then
6126 -- Follow a possible chain of renamings to reach the root renamed
6129 while Present (Id) and then Present (Renamed_Object (Id)) loop
6130 if Is_Entity_Name (Renamed_Object (Id)) then
6131 Id := Entity (Renamed_Object (Id));
6142 --------------------------
6143 -- Explain_Limited_Type --
6144 --------------------------
6146 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
6150 -- For array, component type must be limited
6152 if Is_Array_Type (T) then
6153 Error_Msg_Node_2 := T;
6155 ("\component type& of type& is limited", N, Component_Type (T));
6156 Explain_Limited_Type (Component_Type (T), N);
6158 elsif Is_Record_Type (T) then
6160 -- No need for extra messages if explicit limited record
6162 if Is_Limited_Record (Base_Type (T)) then
6166 -- Otherwise find a limited component. Check only components that
6167 -- come from source, or inherited components that appear in the
6168 -- source of the ancestor.
6170 C := First_Component (T);
6171 while Present (C) loop
6172 if Is_Limited_Type (Etype (C))
6174 (Comes_From_Source (C)
6176 (Present (Original_Record_Component (C))
6178 Comes_From_Source (Original_Record_Component (C))))
6180 Error_Msg_Node_2 := T;
6181 Error_Msg_NE ("\component& of type& has limited type", N, C);
6182 Explain_Limited_Type (Etype (C), N);
6189 -- The type may be declared explicitly limited, even if no component
6190 -- of it is limited, in which case we fall out of the loop.
6193 end Explain_Limited_Type;
6195 -------------------------------
6196 -- Extensions_Visible_Status --
6197 -------------------------------
6199 function Extensions_Visible_Status
6200 (Id : Entity_Id) return Extensions_Visible_Mode
6209 -- When a formal parameter is subject to Extensions_Visible, the pragma
6210 -- is stored in the contract of related subprogram.
6212 if Is_Formal (Id) then
6215 elsif Is_Subprogram_Or_Generic_Subprogram (Id) then
6218 -- No other construct carries this pragma
6221 return Extensions_Visible_None;
6224 Prag := Get_Pragma (Subp, Pragma_Extensions_Visible);
6226 -- In certain cases analysis may request the Extensions_Visible status
6227 -- of an expression function before the pragma has been analyzed yet.
6228 -- Inspect the declarative items after the expression function looking
6229 -- for the pragma (if any).
6231 if No (Prag) and then Is_Expression_Function (Subp) then
6232 Decl := Next (Unit_Declaration_Node (Subp));
6233 while Present (Decl) loop
6234 if Nkind (Decl) = N_Pragma
6235 and then Pragma_Name (Decl) = Name_Extensions_Visible
6240 -- A source construct ends the region where Extensions_Visible may
6241 -- appear, stop the traversal. An expanded expression function is
6242 -- no longer a source construct, but it must still be recognized.
6244 elsif Comes_From_Source (Decl)
6246 (Nkind_In (Decl, N_Subprogram_Body,
6247 N_Subprogram_Declaration)
6248 and then Is_Expression_Function (Defining_Entity (Decl)))
6257 -- Extract the value from the Boolean expression (if any)
6259 if Present (Prag) then
6260 Arg := First (Pragma_Argument_Associations (Prag));
6262 if Present (Arg) then
6263 Expr := Get_Pragma_Arg (Arg);
6265 -- When the associated subprogram is an expression function, the
6266 -- argument of the pragma may not have been analyzed.
6268 if not Analyzed (Expr) then
6269 Preanalyze_And_Resolve (Expr, Standard_Boolean);
6272 -- Guard against cascading errors when the argument of pragma
6273 -- Extensions_Visible is not a valid static Boolean expression.
6275 if Error_Posted (Expr) then
6276 return Extensions_Visible_None;
6278 elsif Is_True (Expr_Value (Expr)) then
6279 return Extensions_Visible_True;
6282 return Extensions_Visible_False;
6285 -- Otherwise the aspect or pragma defaults to True
6288 return Extensions_Visible_True;
6291 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
6292 -- directly specified. In SPARK code, its value defaults to "False".
6294 elsif SPARK_Mode = On then
6295 return Extensions_Visible_False;
6297 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
6301 return Extensions_Visible_True;
6303 end Extensions_Visible_Status;
6309 procedure Find_Actual
6311 Formal : out Entity_Id;
6314 Parnt : constant Node_Id := Parent (N);
6318 if Nkind_In (Parnt, N_Indexed_Component, N_Selected_Component)
6319 and then N = Prefix (Parnt)
6321 Find_Actual (Parnt, Formal, Call);
6324 elsif Nkind (Parnt) = N_Parameter_Association
6325 and then N = Explicit_Actual_Parameter (Parnt)
6327 Call := Parent (Parnt);
6329 elsif Nkind (Parnt) in N_Subprogram_Call then
6338 -- If we have a call to a subprogram look for the parameter. Note that
6339 -- we exclude overloaded calls, since we don't know enough to be sure
6340 -- of giving the right answer in this case.
6342 if Nkind_In (Call, N_Function_Call, N_Procedure_Call_Statement)
6343 and then Is_Entity_Name (Name (Call))
6344 and then Present (Entity (Name (Call)))
6345 and then Is_Overloadable (Entity (Name (Call)))
6346 and then not Is_Overloaded (Name (Call))
6348 -- If node is name in call it is not an actual
6350 if N = Name (Call) then
6356 -- Fall here if we are definitely a parameter
6358 Actual := First_Actual (Call);
6359 Formal := First_Formal (Entity (Name (Call)));
6360 while Present (Formal) and then Present (Actual) loop
6364 -- An actual that is the prefix in a prefixed call may have
6365 -- been rewritten in the call, after the deferred reference
6366 -- was collected. Check if sloc and kinds and names match.
6368 elsif Sloc (Actual) = Sloc (N)
6369 and then Nkind (Actual) = N_Identifier
6370 and then Nkind (Actual) = Nkind (N)
6371 and then Chars (Actual) = Chars (N)
6376 Actual := Next_Actual (Actual);
6377 Formal := Next_Formal (Formal);
6382 -- Fall through here if we did not find matching actual
6388 ---------------------------
6389 -- Find_Body_Discriminal --
6390 ---------------------------
6392 function Find_Body_Discriminal
6393 (Spec_Discriminant : Entity_Id) return Entity_Id
6399 -- If expansion is suppressed, then the scope can be the concurrent type
6400 -- itself rather than a corresponding concurrent record type.
6402 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
6403 Tsk := Scope (Spec_Discriminant);
6406 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
6408 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
6411 -- Find discriminant of original concurrent type, and use its current
6412 -- discriminal, which is the renaming within the task/protected body.
6414 Disc := First_Discriminant (Tsk);
6415 while Present (Disc) loop
6416 if Chars (Disc) = Chars (Spec_Discriminant) then
6417 return Discriminal (Disc);
6420 Next_Discriminant (Disc);
6423 -- That loop should always succeed in finding a matching entry and
6424 -- returning. Fatal error if not.
6426 raise Program_Error;
6427 end Find_Body_Discriminal;
6429 -------------------------------------
6430 -- Find_Corresponding_Discriminant --
6431 -------------------------------------
6433 function Find_Corresponding_Discriminant
6435 Typ : Entity_Id) return Entity_Id
6437 Par_Disc : Entity_Id;
6438 Old_Disc : Entity_Id;
6439 New_Disc : Entity_Id;
6442 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
6444 -- The original type may currently be private, and the discriminant
6445 -- only appear on its full view.
6447 if Is_Private_Type (Scope (Par_Disc))
6448 and then not Has_Discriminants (Scope (Par_Disc))
6449 and then Present (Full_View (Scope (Par_Disc)))
6451 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
6453 Old_Disc := First_Discriminant (Scope (Par_Disc));
6456 if Is_Class_Wide_Type (Typ) then
6457 New_Disc := First_Discriminant (Root_Type (Typ));
6459 New_Disc := First_Discriminant (Typ);
6462 while Present (Old_Disc) and then Present (New_Disc) loop
6463 if Old_Disc = Par_Disc then
6467 Next_Discriminant (Old_Disc);
6468 Next_Discriminant (New_Disc);
6471 -- Should always find it
6473 raise Program_Error;
6474 end Find_Corresponding_Discriminant;
6476 ----------------------------------
6477 -- Find_Enclosing_Iterator_Loop --
6478 ----------------------------------
6480 function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id is
6485 -- Traverse the scope chain looking for an iterator loop. Such loops are
6486 -- usually transformed into blocks, hence the use of Original_Node.
6489 while Present (S) and then S /= Standard_Standard loop
6490 if Ekind (S) = E_Loop
6491 and then Nkind (Parent (S)) = N_Implicit_Label_Declaration
6493 Constr := Original_Node (Label_Construct (Parent (S)));
6495 if Nkind (Constr) = N_Loop_Statement
6496 and then Present (Iteration_Scheme (Constr))
6497 and then Nkind (Iterator_Specification
6498 (Iteration_Scheme (Constr))) =
6499 N_Iterator_Specification
6509 end Find_Enclosing_Iterator_Loop;
6511 ------------------------------------
6512 -- Find_Loop_In_Conditional_Block --
6513 ------------------------------------
6515 function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is
6521 if Nkind (Stmt) = N_If_Statement then
6522 Stmt := First (Then_Statements (Stmt));
6525 pragma Assert (Nkind (Stmt) = N_Block_Statement);
6527 -- Inspect the statements of the conditional block. In general the loop
6528 -- should be the first statement in the statement sequence of the block,
6529 -- but the finalization machinery may have introduced extra object
6532 Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
6533 while Present (Stmt) loop
6534 if Nkind (Stmt) = N_Loop_Statement then
6541 -- The expansion of attribute 'Loop_Entry produced a malformed block
6543 raise Program_Error;
6544 end Find_Loop_In_Conditional_Block;
6546 --------------------------
6547 -- Find_Overlaid_Entity --
6548 --------------------------
6550 procedure Find_Overlaid_Entity
6552 Ent : out Entity_Id;
6558 -- We are looking for one of the two following forms:
6560 -- for X'Address use Y'Address
6564 -- Const : constant Address := expr;
6566 -- for X'Address use Const;
6568 -- In the second case, the expr is either Y'Address, or recursively a
6569 -- constant that eventually references Y'Address.
6574 if Nkind (N) = N_Attribute_Definition_Clause
6575 and then Chars (N) = Name_Address
6577 Expr := Expression (N);
6579 -- This loop checks the form of the expression for Y'Address,
6580 -- using recursion to deal with intermediate constants.
6583 -- Check for Y'Address
6585 if Nkind (Expr) = N_Attribute_Reference
6586 and then Attribute_Name (Expr) = Name_Address
6588 Expr := Prefix (Expr);
6591 -- Check for Const where Const is a constant entity
6593 elsif Is_Entity_Name (Expr)
6594 and then Ekind (Entity (Expr)) = E_Constant
6596 Expr := Constant_Value (Entity (Expr));
6598 -- Anything else does not need checking
6605 -- This loop checks the form of the prefix for an entity, using
6606 -- recursion to deal with intermediate components.
6609 -- Check for Y where Y is an entity
6611 if Is_Entity_Name (Expr) then
6612 Ent := Entity (Expr);
6615 -- Check for components
6618 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component)
6620 Expr := Prefix (Expr);
6623 -- Anything else does not need checking
6630 end Find_Overlaid_Entity;
6632 -------------------------
6633 -- Find_Parameter_Type --
6634 -------------------------
6636 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
6638 if Nkind (Param) /= N_Parameter_Specification then
6641 -- For an access parameter, obtain the type from the formal entity
6642 -- itself, because access to subprogram nodes do not carry a type.
6643 -- Shouldn't we always use the formal entity ???
6645 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
6646 return Etype (Defining_Identifier (Param));
6649 return Etype (Parameter_Type (Param));
6651 end Find_Parameter_Type;
6653 -----------------------------------
6654 -- Find_Placement_In_State_Space --
6655 -----------------------------------
6657 procedure Find_Placement_In_State_Space
6658 (Item_Id : Entity_Id;
6659 Placement : out State_Space_Kind;
6660 Pack_Id : out Entity_Id)
6662 Context : Entity_Id;
6665 -- Assume that the item does not appear in the state space of a package
6667 Placement := Not_In_Package;
6670 -- Climb the scope stack and examine the enclosing context
6672 Context := Scope (Item_Id);
6673 while Present (Context) and then Context /= Standard_Standard loop
6674 if Ekind (Context) = E_Package then
6677 -- A package body is a cut off point for the traversal as the item
6678 -- cannot be visible to the outside from this point on. Note that
6679 -- this test must be done first as a body is also classified as a
6682 if In_Package_Body (Context) then
6683 Placement := Body_State_Space;
6686 -- The private part of a package is a cut off point for the
6687 -- traversal as the item cannot be visible to the outside from
6690 elsif In_Private_Part (Context) then
6691 Placement := Private_State_Space;
6694 -- When the item appears in the visible state space of a package,
6695 -- continue to climb the scope stack as this may not be the final
6699 Placement := Visible_State_Space;
6701 -- The visible state space of a child unit acts as the proper
6702 -- placement of an item.
6704 if Is_Child_Unit (Context) then
6709 -- The item or its enclosing package appear in a construct that has
6713 Placement := Not_In_Package;
6717 Context := Scope (Context);
6719 end Find_Placement_In_State_Space;
6721 ------------------------
6722 -- Find_Specific_Type --
6723 ------------------------
6725 function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
6726 Typ : Entity_Id := Root_Type (CW);
6729 if Ekind (Typ) = E_Incomplete_Type then
6730 if From_Limited_With (Typ) then
6731 Typ := Non_Limited_View (Typ);
6733 Typ := Full_View (Typ);
6737 if Is_Private_Type (Typ)
6738 and then not Is_Tagged_Type (Typ)
6739 and then Present (Full_View (Typ))
6741 return Full_View (Typ);
6745 end Find_Specific_Type;
6747 -----------------------------
6748 -- Find_Static_Alternative --
6749 -----------------------------
6751 function Find_Static_Alternative (N : Node_Id) return Node_Id is
6752 Expr : constant Node_Id := Expression (N);
6753 Val : constant Uint := Expr_Value (Expr);
6758 Alt := First (Alternatives (N));
6761 if Nkind (Alt) /= N_Pragma then
6762 Choice := First (Discrete_Choices (Alt));
6763 while Present (Choice) loop
6765 -- Others choice, always matches
6767 if Nkind (Choice) = N_Others_Choice then
6770 -- Range, check if value is in the range
6772 elsif Nkind (Choice) = N_Range then
6774 Val >= Expr_Value (Low_Bound (Choice))
6776 Val <= Expr_Value (High_Bound (Choice));
6778 -- Choice is a subtype name. Note that we know it must
6779 -- be a static subtype, since otherwise it would have
6780 -- been diagnosed as illegal.
6782 elsif Is_Entity_Name (Choice)
6783 and then Is_Type (Entity (Choice))
6785 exit Search when Is_In_Range (Expr, Etype (Choice),
6786 Assume_Valid => False);
6788 -- Choice is a subtype indication
6790 elsif Nkind (Choice) = N_Subtype_Indication then
6792 C : constant Node_Id := Constraint (Choice);
6793 R : constant Node_Id := Range_Expression (C);
6797 Val >= Expr_Value (Low_Bound (R))
6799 Val <= Expr_Value (High_Bound (R));
6802 -- Choice is a simple expression
6805 exit Search when Val = Expr_Value (Choice);
6813 pragma Assert (Present (Alt));
6816 -- The above loop *must* terminate by finding a match, since
6817 -- we know the case statement is valid, and the value of the
6818 -- expression is known at compile time. When we fall out of
6819 -- the loop, Alt points to the alternative that we know will
6820 -- be selected at run time.
6823 end Find_Static_Alternative;
6829 function First_Actual (Node : Node_Id) return Node_Id is
6833 if No (Parameter_Associations (Node)) then
6837 N := First (Parameter_Associations (Node));
6839 if Nkind (N) = N_Parameter_Association then
6840 return First_Named_Actual (Node);
6846 -----------------------
6847 -- Gather_Components --
6848 -----------------------
6850 procedure Gather_Components
6852 Comp_List : Node_Id;
6853 Governed_By : List_Id;
6855 Report_Errors : out Boolean)
6859 Discrete_Choice : Node_Id;
6860 Comp_Item : Node_Id;
6862 Discrim : Entity_Id;
6863 Discrim_Name : Node_Id;
6864 Discrim_Value : Node_Id;
6867 Report_Errors := False;
6869 if No (Comp_List) or else Null_Present (Comp_List) then
6872 elsif Present (Component_Items (Comp_List)) then
6873 Comp_Item := First (Component_Items (Comp_List));
6879 while Present (Comp_Item) loop
6881 -- Skip the tag of a tagged record, the interface tags, as well
6882 -- as all items that are not user components (anonymous types,
6883 -- rep clauses, Parent field, controller field).
6885 if Nkind (Comp_Item) = N_Component_Declaration then
6887 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
6889 if not Is_Tag (Comp) and then Chars (Comp) /= Name_uParent then
6890 Append_Elmt (Comp, Into);
6898 if No (Variant_Part (Comp_List)) then
6901 Discrim_Name := Name (Variant_Part (Comp_List));
6902 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
6905 -- Look for the discriminant that governs this variant part.
6906 -- The discriminant *must* be in the Governed_By List
6908 Assoc := First (Governed_By);
6909 Find_Constraint : loop
6910 Discrim := First (Choices (Assoc));
6911 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
6912 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
6914 Chars (Corresponding_Discriminant (Entity (Discrim))) =
6915 Chars (Discrim_Name))
6916 or else Chars (Original_Record_Component (Entity (Discrim)))
6917 = Chars (Discrim_Name);
6919 if No (Next (Assoc)) then
6920 if not Is_Constrained (Typ)
6921 and then Is_Derived_Type (Typ)
6922 and then Present (Stored_Constraint (Typ))
6924 -- If the type is a tagged type with inherited discriminants,
6925 -- use the stored constraint on the parent in order to find
6926 -- the values of discriminants that are otherwise hidden by an
6927 -- explicit constraint. Renamed discriminants are handled in
6930 -- If several parent discriminants are renamed by a single
6931 -- discriminant of the derived type, the call to obtain the
6932 -- Corresponding_Discriminant field only retrieves the last
6933 -- of them. We recover the constraint on the others from the
6934 -- Stored_Constraint as well.
6941 D := First_Discriminant (Etype (Typ));
6942 C := First_Elmt (Stored_Constraint (Typ));
6943 while Present (D) and then Present (C) loop
6944 if Chars (Discrim_Name) = Chars (D) then
6945 if Is_Entity_Name (Node (C))
6946 and then Entity (Node (C)) = Entity (Discrim)
6948 -- D is renamed by Discrim, whose value is given in
6955 Make_Component_Association (Sloc (Typ),
6957 (New_Occurrence_Of (D, Sloc (Typ))),
6958 Duplicate_Subexpr_No_Checks (Node (C)));
6960 exit Find_Constraint;
6963 Next_Discriminant (D);
6970 if No (Next (Assoc)) then
6971 Error_Msg_NE (" missing value for discriminant&",
6972 First (Governed_By), Discrim_Name);
6973 Report_Errors := True;
6978 end loop Find_Constraint;
6980 Discrim_Value := Expression (Assoc);
6982 if not Is_OK_Static_Expression (Discrim_Value) then
6984 -- If the variant part is governed by a discriminant of the type
6985 -- this is an error. If the variant part and the discriminant are
6986 -- inherited from an ancestor this is legal (AI05-120) unless the
6987 -- components are being gathered for an aggregate, in which case
6988 -- the caller must check Report_Errors.
6990 if Scope (Original_Record_Component
6991 ((Entity (First (Choices (Assoc)))))) = Typ
6994 ("value for discriminant & must be static!",
6995 Discrim_Value, Discrim);
6996 Why_Not_Static (Discrim_Value);
6999 Report_Errors := True;
7003 Search_For_Discriminant_Value : declare
7009 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
7012 Find_Discrete_Value : while Present (Variant) loop
7013 Discrete_Choice := First (Discrete_Choices (Variant));
7014 while Present (Discrete_Choice) loop
7015 exit Find_Discrete_Value when
7016 Nkind (Discrete_Choice) = N_Others_Choice;
7018 Get_Index_Bounds (Discrete_Choice, Low, High);
7020 UI_Low := Expr_Value (Low);
7021 UI_High := Expr_Value (High);
7023 exit Find_Discrete_Value when
7024 UI_Low <= UI_Discrim_Value
7026 UI_High >= UI_Discrim_Value;
7028 Next (Discrete_Choice);
7031 Next_Non_Pragma (Variant);
7032 end loop Find_Discrete_Value;
7033 end Search_For_Discriminant_Value;
7035 if No (Variant) then
7037 ("value of discriminant & is out of range", Discrim_Value, Discrim);
7038 Report_Errors := True;
7042 -- If we have found the corresponding choice, recursively add its
7043 -- components to the Into list.
7046 (Empty, Component_List (Variant), Governed_By, Into, Report_Errors);
7047 end Gather_Components;
7049 ------------------------
7050 -- Get_Actual_Subtype --
7051 ------------------------
7053 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
7054 Typ : constant Entity_Id := Etype (N);
7055 Utyp : Entity_Id := Underlying_Type (Typ);
7064 -- If what we have is an identifier that references a subprogram
7065 -- formal, or a variable or constant object, then we get the actual
7066 -- subtype from the referenced entity if one has been built.
7068 if Nkind (N) = N_Identifier
7070 (Is_Formal (Entity (N))
7071 or else Ekind (Entity (N)) = E_Constant
7072 or else Ekind (Entity (N)) = E_Variable)
7073 and then Present (Actual_Subtype (Entity (N)))
7075 return Actual_Subtype (Entity (N));
7077 -- Actual subtype of unchecked union is always itself. We never need
7078 -- the "real" actual subtype. If we did, we couldn't get it anyway
7079 -- because the discriminant is not available. The restrictions on
7080 -- Unchecked_Union are designed to make sure that this is OK.
7082 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
7085 -- Here for the unconstrained case, we must find actual subtype
7086 -- No actual subtype is available, so we must build it on the fly.
7088 -- Checking the type, not the underlying type, for constrainedness
7089 -- seems to be necessary. Maybe all the tests should be on the type???
7091 elsif (not Is_Constrained (Typ))
7092 and then (Is_Array_Type (Utyp)
7093 or else (Is_Record_Type (Utyp)
7094 and then Has_Discriminants (Utyp)))
7095 and then not Has_Unknown_Discriminants (Utyp)
7096 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
7098 -- Nothing to do if in spec expression (why not???)
7100 if In_Spec_Expression then
7103 elsif Is_Private_Type (Typ) and then not Has_Discriminants (Typ) then
7105 -- If the type has no discriminants, there is no subtype to
7106 -- build, even if the underlying type is discriminated.
7110 -- Else build the actual subtype
7113 Decl := Build_Actual_Subtype (Typ, N);
7114 Atyp := Defining_Identifier (Decl);
7116 -- If Build_Actual_Subtype generated a new declaration then use it
7120 -- The actual subtype is an Itype, so analyze the declaration,
7121 -- but do not attach it to the tree, to get the type defined.
7123 Set_Parent (Decl, N);
7124 Set_Is_Itype (Atyp);
7125 Analyze (Decl, Suppress => All_Checks);
7126 Set_Associated_Node_For_Itype (Atyp, N);
7127 Set_Has_Delayed_Freeze (Atyp, False);
7129 -- We need to freeze the actual subtype immediately. This is
7130 -- needed, because otherwise this Itype will not get frozen
7131 -- at all, and it is always safe to freeze on creation because
7132 -- any associated types must be frozen at this point.
7134 Freeze_Itype (Atyp, N);
7137 -- Otherwise we did not build a declaration, so return original
7144 -- For all remaining cases, the actual subtype is the same as
7145 -- the nominal type.
7150 end Get_Actual_Subtype;
7152 -------------------------------------
7153 -- Get_Actual_Subtype_If_Available --
7154 -------------------------------------
7156 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
7157 Typ : constant Entity_Id := Etype (N);
7160 -- If what we have is an identifier that references a subprogram
7161 -- formal, or a variable or constant object, then we get the actual
7162 -- subtype from the referenced entity if one has been built.
7164 if Nkind (N) = N_Identifier
7166 (Is_Formal (Entity (N))
7167 or else Ekind (Entity (N)) = E_Constant
7168 or else Ekind (Entity (N)) = E_Variable)
7169 and then Present (Actual_Subtype (Entity (N)))
7171 return Actual_Subtype (Entity (N));
7173 -- Otherwise the Etype of N is returned unchanged
7178 end Get_Actual_Subtype_If_Available;
7180 ------------------------
7181 -- Get_Body_From_Stub --
7182 ------------------------
7184 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
7186 return Proper_Body (Unit (Library_Unit (N)));
7187 end Get_Body_From_Stub;
7189 ---------------------
7190 -- Get_Cursor_Type --
7191 ---------------------
7193 function Get_Cursor_Type
7195 Typ : Entity_Id) return Entity_Id
7199 First_Op : Entity_Id;
7203 -- If error already detected, return
7205 if Error_Posted (Aspect) then
7209 -- The cursor type for an Iterable aspect is the return type of a
7210 -- non-overloaded First primitive operation. Locate association for
7213 Assoc := First (Component_Associations (Expression (Aspect)));
7215 while Present (Assoc) loop
7216 if Chars (First (Choices (Assoc))) = Name_First then
7217 First_Op := Expression (Assoc);
7224 if First_Op = Any_Id then
7225 Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
7231 -- Locate function with desired name and profile in scope of type
7233 Func := First_Entity (Scope (Typ));
7234 while Present (Func) loop
7235 if Chars (Func) = Chars (First_Op)
7236 and then Ekind (Func) = E_Function
7237 and then Present (First_Formal (Func))
7238 and then Etype (First_Formal (Func)) = Typ
7239 and then No (Next_Formal (First_Formal (Func)))
7241 if Cursor /= Any_Type then
7243 ("Operation First for iterable type must be unique", Aspect);
7246 Cursor := Etype (Func);
7253 -- If not found, no way to resolve remaining primitives.
7255 if Cursor = Any_Type then
7257 ("No legal primitive operation First for Iterable type", Aspect);
7261 end Get_Cursor_Type;
7263 -------------------------------
7264 -- Get_Default_External_Name --
7265 -------------------------------
7267 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
7269 Get_Decoded_Name_String (Chars (E));
7271 if Opt.External_Name_Imp_Casing = Uppercase then
7272 Set_Casing (All_Upper_Case);
7274 Set_Casing (All_Lower_Case);
7278 Make_String_Literal (Sloc (E),
7279 Strval => String_From_Name_Buffer);
7280 end Get_Default_External_Name;
7282 --------------------------
7283 -- Get_Enclosing_Object --
7284 --------------------------
7286 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
7288 if Is_Entity_Name (N) then
7292 when N_Indexed_Component |
7294 N_Selected_Component =>
7296 -- If not generating code, a dereference may be left implicit.
7297 -- In thoses cases, return Empty.
7299 if Is_Access_Type (Etype (Prefix (N))) then
7302 return Get_Enclosing_Object (Prefix (N));
7305 when N_Type_Conversion =>
7306 return Get_Enclosing_Object (Expression (N));
7312 end Get_Enclosing_Object;
7314 ---------------------------
7315 -- Get_Enum_Lit_From_Pos --
7316 ---------------------------
7318 function Get_Enum_Lit_From_Pos
7321 Loc : Source_Ptr) return Node_Id
7323 Btyp : Entity_Id := Base_Type (T);
7327 -- In the case where the literal is of type Character, Wide_Character
7328 -- or Wide_Wide_Character or of a type derived from them, there needs
7329 -- to be some special handling since there is no explicit chain of
7330 -- literals to search. Instead, an N_Character_Literal node is created
7331 -- with the appropriate Char_Code and Chars fields.
7333 if Is_Standard_Character_Type (T) then
7334 Set_Character_Literal_Name (UI_To_CC (Pos));
7336 Make_Character_Literal (Loc,
7338 Char_Literal_Value => Pos);
7340 -- For all other cases, we have a complete table of literals, and
7341 -- we simply iterate through the chain of literal until the one
7342 -- with the desired position value is found.
7345 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
7346 Btyp := Full_View (Btyp);
7349 Lit := First_Literal (Btyp);
7350 for J in 1 .. UI_To_Int (Pos) loop
7354 return New_Occurrence_Of (Lit, Loc);
7356 end Get_Enum_Lit_From_Pos;
7358 ------------------------
7359 -- Get_Generic_Entity --
7360 ------------------------
7362 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
7363 Ent : constant Entity_Id := Entity (Name (N));
7365 if Present (Renamed_Object (Ent)) then
7366 return Renamed_Object (Ent);
7370 end Get_Generic_Entity;
7372 -------------------------------------
7373 -- Get_Incomplete_View_Of_Ancestor --
7374 -------------------------------------
7376 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
7377 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
7378 Par_Scope : Entity_Id;
7379 Par_Type : Entity_Id;
7382 -- The incomplete view of an ancestor is only relevant for private
7383 -- derived types in child units.
7385 if not Is_Derived_Type (E)
7386 or else not Is_Child_Unit (Cur_Unit)
7391 Par_Scope := Scope (Cur_Unit);
7392 if No (Par_Scope) then
7396 Par_Type := Etype (Base_Type (E));
7398 -- Traverse list of ancestor types until we find one declared in
7399 -- a parent or grandparent unit (two levels seem sufficient).
7401 while Present (Par_Type) loop
7402 if Scope (Par_Type) = Par_Scope
7403 or else Scope (Par_Type) = Scope (Par_Scope)
7407 elsif not Is_Derived_Type (Par_Type) then
7411 Par_Type := Etype (Base_Type (Par_Type));
7415 -- If none found, there is no relevant ancestor type.
7419 end Get_Incomplete_View_Of_Ancestor;
7421 ----------------------
7422 -- Get_Index_Bounds --
7423 ----------------------
7425 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
7426 Kind : constant Node_Kind := Nkind (N);
7430 if Kind = N_Range then
7432 H := High_Bound (N);
7434 elsif Kind = N_Subtype_Indication then
7435 R := Range_Expression (Constraint (N));
7443 L := Low_Bound (Range_Expression (Constraint (N)));
7444 H := High_Bound (Range_Expression (Constraint (N)));
7447 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
7448 if Error_Posted (Scalar_Range (Entity (N))) then
7452 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
7453 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
7456 L := Low_Bound (Scalar_Range (Entity (N)));
7457 H := High_Bound (Scalar_Range (Entity (N)));
7461 -- N is an expression, indicating a range with one value
7466 end Get_Index_Bounds;
7468 ---------------------------------
7469 -- Get_Iterable_Type_Primitive --
7470 ---------------------------------
7472 function Get_Iterable_Type_Primitive
7474 Nam : Name_Id) return Entity_Id
7476 Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
7484 Assoc := First (Component_Associations (Funcs));
7485 while Present (Assoc) loop
7486 if Chars (First (Choices (Assoc))) = Nam then
7487 return Entity (Expression (Assoc));
7490 Assoc := Next (Assoc);
7495 end Get_Iterable_Type_Primitive;
7497 ----------------------------------
7498 -- Get_Library_Unit_Name_string --
7499 ----------------------------------
7501 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
7502 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
7505 Get_Unit_Name_String (Unit_Name_Id);
7507 -- Remove seven last character (" (spec)" or " (body)")
7509 Name_Len := Name_Len - 7;
7510 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
7511 end Get_Library_Unit_Name_String;
7513 ------------------------
7514 -- Get_Name_Entity_Id --
7515 ------------------------
7517 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
7519 return Entity_Id (Get_Name_Table_Int (Id));
7520 end Get_Name_Entity_Id;
7522 ------------------------------
7523 -- Get_Name_From_CTC_Pragma --
7524 ------------------------------
7526 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
7527 Arg : constant Node_Id :=
7528 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
7530 return Strval (Expr_Value_S (Arg));
7531 end Get_Name_From_CTC_Pragma;
7533 -----------------------
7534 -- Get_Parent_Entity --
7535 -----------------------
7537 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
7539 if Nkind (Unit) = N_Package_Body
7540 and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
7542 return Defining_Entity
7543 (Specification (Instance_Spec (Original_Node (Unit))));
7544 elsif Nkind (Unit) = N_Package_Instantiation then
7545 return Defining_Entity (Specification (Instance_Spec (Unit)));
7547 return Defining_Entity (Unit);
7549 end Get_Parent_Entity;
7554 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
7556 return Get_Pragma_Id (Pragma_Name (N));
7559 -----------------------
7560 -- Get_Reason_String --
7561 -----------------------
7563 procedure Get_Reason_String (N : Node_Id) is
7565 if Nkind (N) = N_String_Literal then
7566 Store_String_Chars (Strval (N));
7568 elsif Nkind (N) = N_Op_Concat then
7569 Get_Reason_String (Left_Opnd (N));
7570 Get_Reason_String (Right_Opnd (N));
7572 -- If not of required form, error
7576 ("Reason for pragma Warnings has wrong form", N);
7578 ("\must be string literal or concatenation of string literals", N);
7581 end Get_Reason_String;
7583 ---------------------------
7584 -- Get_Referenced_Object --
7585 ---------------------------
7587 function Get_Referenced_Object (N : Node_Id) return Node_Id is
7592 while Is_Entity_Name (R)
7593 and then Present (Renamed_Object (Entity (R)))
7595 R := Renamed_Object (Entity (R));
7599 end Get_Referenced_Object;
7601 ------------------------
7602 -- Get_Renamed_Entity --
7603 ------------------------
7605 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
7610 while Present (Renamed_Entity (R)) loop
7611 R := Renamed_Entity (R);
7615 end Get_Renamed_Entity;
7617 -------------------------
7618 -- Get_Subprogram_Body --
7619 -------------------------
7621 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
7625 Decl := Unit_Declaration_Node (E);
7627 if Nkind (Decl) = N_Subprogram_Body then
7630 -- The below comment is bad, because it is possible for
7631 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
7633 else -- Nkind (Decl) = N_Subprogram_Declaration
7635 if Present (Corresponding_Body (Decl)) then
7636 return Unit_Declaration_Node (Corresponding_Body (Decl));
7638 -- Imported subprogram case
7644 end Get_Subprogram_Body;
7646 ---------------------------
7647 -- Get_Subprogram_Entity --
7648 ---------------------------
7650 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
7652 Subp_Id : Entity_Id;
7655 if Nkind (Nod) = N_Accept_Statement then
7656 Subp := Entry_Direct_Name (Nod);
7658 elsif Nkind (Nod) = N_Slice then
7659 Subp := Prefix (Nod);
7665 -- Strip the subprogram call
7668 if Nkind_In (Subp, N_Explicit_Dereference,
7669 N_Indexed_Component,
7670 N_Selected_Component)
7672 Subp := Prefix (Subp);
7674 elsif Nkind_In (Subp, N_Type_Conversion,
7675 N_Unchecked_Type_Conversion)
7677 Subp := Expression (Subp);
7684 -- Extract the entity of the subprogram call
7686 if Is_Entity_Name (Subp) then
7687 Subp_Id := Entity (Subp);
7689 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
7690 Subp_Id := Directly_Designated_Type (Subp_Id);
7693 if Is_Subprogram (Subp_Id) then
7699 -- The search did not find a construct that denotes a subprogram
7704 end Get_Subprogram_Entity;
7706 -----------------------------
7707 -- Get_Task_Body_Procedure --
7708 -----------------------------
7710 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
7712 -- Note: A task type may be the completion of a private type with
7713 -- discriminants. When performing elaboration checks on a task
7714 -- declaration, the current view of the type may be the private one,
7715 -- and the procedure that holds the body of the task is held in its
7718 -- This is an odd function, why not have Task_Body_Procedure do
7719 -- the following digging???
7721 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
7722 end Get_Task_Body_Procedure;
7724 -----------------------
7725 -- Has_Access_Values --
7726 -----------------------
7728 function Has_Access_Values (T : Entity_Id) return Boolean is
7729 Typ : constant Entity_Id := Underlying_Type (T);
7732 -- Case of a private type which is not completed yet. This can only
7733 -- happen in the case of a generic format type appearing directly, or
7734 -- as a component of the type to which this function is being applied
7735 -- at the top level. Return False in this case, since we certainly do
7736 -- not know that the type contains access types.
7741 elsif Is_Access_Type (Typ) then
7744 elsif Is_Array_Type (Typ) then
7745 return Has_Access_Values (Component_Type (Typ));
7747 elsif Is_Record_Type (Typ) then
7752 -- Loop to Check components
7754 Comp := First_Component_Or_Discriminant (Typ);
7755 while Present (Comp) loop
7757 -- Check for access component, tag field does not count, even
7758 -- though it is implemented internally using an access type.
7760 if Has_Access_Values (Etype (Comp))
7761 and then Chars (Comp) /= Name_uTag
7766 Next_Component_Or_Discriminant (Comp);
7775 end Has_Access_Values;
7777 ------------------------------
7778 -- Has_Compatible_Alignment --
7779 ------------------------------
7781 function Has_Compatible_Alignment
7783 Expr : Node_Id) return Alignment_Result
7785 function Has_Compatible_Alignment_Internal
7788 Default : Alignment_Result) return Alignment_Result;
7789 -- This is the internal recursive function that actually does the work.
7790 -- There is one additional parameter, which says what the result should
7791 -- be if no alignment information is found, and there is no definite
7792 -- indication of compatible alignments. At the outer level, this is set
7793 -- to Unknown, but for internal recursive calls in the case where types
7794 -- are known to be correct, it is set to Known_Compatible.
7796 ---------------------------------------
7797 -- Has_Compatible_Alignment_Internal --
7798 ---------------------------------------
7800 function Has_Compatible_Alignment_Internal
7803 Default : Alignment_Result) return Alignment_Result
7805 Result : Alignment_Result := Known_Compatible;
7806 -- Holds the current status of the result. Note that once a value of
7807 -- Known_Incompatible is set, it is sticky and does not get changed
7808 -- to Unknown (the value in Result only gets worse as we go along,
7811 Offs : Uint := No_Uint;
7812 -- Set to a factor of the offset from the base object when Expr is a
7813 -- selected or indexed component, based on Component_Bit_Offset and
7814 -- Component_Size respectively. A negative value is used to represent
7815 -- a value which is not known at compile time.
7817 procedure Check_Prefix;
7818 -- Checks the prefix recursively in the case where the expression
7819 -- is an indexed or selected component.
7821 procedure Set_Result (R : Alignment_Result);
7822 -- If R represents a worse outcome (unknown instead of known
7823 -- compatible, or known incompatible), then set Result to R.
7829 procedure Check_Prefix is
7831 -- The subtlety here is that in doing a recursive call to check
7832 -- the prefix, we have to decide what to do in the case where we
7833 -- don't find any specific indication of an alignment problem.
7835 -- At the outer level, we normally set Unknown as the result in
7836 -- this case, since we can only set Known_Compatible if we really
7837 -- know that the alignment value is OK, but for the recursive
7838 -- call, in the case where the types match, and we have not
7839 -- specified a peculiar alignment for the object, we are only
7840 -- concerned about suspicious rep clauses, the default case does
7841 -- not affect us, since the compiler will, in the absence of such
7842 -- rep clauses, ensure that the alignment is correct.
7844 if Default = Known_Compatible
7846 (Etype (Obj) = Etype (Expr)
7847 and then (Unknown_Alignment (Obj)
7849 Alignment (Obj) = Alignment (Etype (Obj))))
7852 (Has_Compatible_Alignment_Internal
7853 (Obj, Prefix (Expr), Known_Compatible));
7855 -- In all other cases, we need a full check on the prefix
7859 (Has_Compatible_Alignment_Internal
7860 (Obj, Prefix (Expr), Unknown));
7868 procedure Set_Result (R : Alignment_Result) is
7875 -- Start of processing for Has_Compatible_Alignment_Internal
7878 -- If Expr is a selected component, we must make sure there is no
7879 -- potentially troublesome component clause, and that the record is
7882 if Nkind (Expr) = N_Selected_Component then
7884 -- Packed record always generate unknown alignment
7886 if Is_Packed (Etype (Prefix (Expr))) then
7887 Set_Result (Unknown);
7890 -- Check prefix and component offset
7893 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
7895 -- If Expr is an indexed component, we must make sure there is no
7896 -- potentially troublesome Component_Size clause and that the array
7897 -- is not bit-packed.
7899 elsif Nkind (Expr) = N_Indexed_Component then
7901 Typ : constant Entity_Id := Etype (Prefix (Expr));
7902 Ind : constant Node_Id := First_Index (Typ);
7905 -- Bit packed array always generates unknown alignment
7907 if Is_Bit_Packed_Array (Typ) then
7908 Set_Result (Unknown);
7911 -- Check prefix and component offset
7914 Offs := Component_Size (Typ);
7916 -- Small optimization: compute the full offset when possible
7919 and then Offs > Uint_0
7920 and then Present (Ind)
7921 and then Nkind (Ind) = N_Range
7922 and then Compile_Time_Known_Value (Low_Bound (Ind))
7923 and then Compile_Time_Known_Value (First (Expressions (Expr)))
7925 Offs := Offs * (Expr_Value (First (Expressions (Expr)))
7926 - Expr_Value (Low_Bound ((Ind))));
7931 -- If we have a null offset, the result is entirely determined by
7932 -- the base object and has already been computed recursively.
7934 if Offs = Uint_0 then
7937 -- Case where we know the alignment of the object
7939 elsif Known_Alignment (Obj) then
7941 ObjA : constant Uint := Alignment (Obj);
7942 ExpA : Uint := No_Uint;
7943 SizA : Uint := No_Uint;
7946 -- If alignment of Obj is 1, then we are always OK
7949 Set_Result (Known_Compatible);
7951 -- Alignment of Obj is greater than 1, so we need to check
7954 -- If we have an offset, see if it is compatible
7956 if Offs /= No_Uint and Offs > Uint_0 then
7957 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
7958 Set_Result (Known_Incompatible);
7961 -- See if Expr is an object with known alignment
7963 elsif Is_Entity_Name (Expr)
7964 and then Known_Alignment (Entity (Expr))
7966 ExpA := Alignment (Entity (Expr));
7968 -- Otherwise, we can use the alignment of the type of
7969 -- Expr given that we already checked for
7970 -- discombobulating rep clauses for the cases of indexed
7971 -- and selected components above.
7973 elsif Known_Alignment (Etype (Expr)) then
7974 ExpA := Alignment (Etype (Expr));
7976 -- Otherwise the alignment is unknown
7979 Set_Result (Default);
7982 -- If we got an alignment, see if it is acceptable
7984 if ExpA /= No_Uint and then ExpA < ObjA then
7985 Set_Result (Known_Incompatible);
7988 -- If Expr is not a piece of a larger object, see if size
7989 -- is given. If so, check that it is not too small for the
7990 -- required alignment.
7992 if Offs /= No_Uint then
7995 -- See if Expr is an object with known size
7997 elsif Is_Entity_Name (Expr)
7998 and then Known_Static_Esize (Entity (Expr))
8000 SizA := Esize (Entity (Expr));
8002 -- Otherwise, we check the object size of the Expr type
8004 elsif Known_Static_Esize (Etype (Expr)) then
8005 SizA := Esize (Etype (Expr));
8008 -- If we got a size, see if it is a multiple of the Obj
8009 -- alignment, if not, then the alignment cannot be
8010 -- acceptable, since the size is always a multiple of the
8013 if SizA /= No_Uint then
8014 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
8015 Set_Result (Known_Incompatible);
8021 -- If we do not know required alignment, any non-zero offset is a
8022 -- potential problem (but certainly may be OK, so result is unknown).
8024 elsif Offs /= No_Uint then
8025 Set_Result (Unknown);
8027 -- If we can't find the result by direct comparison of alignment
8028 -- values, then there is still one case that we can determine known
8029 -- result, and that is when we can determine that the types are the
8030 -- same, and no alignments are specified. Then we known that the
8031 -- alignments are compatible, even if we don't know the alignment
8032 -- value in the front end.
8034 elsif Etype (Obj) = Etype (Expr) then
8036 -- Types are the same, but we have to check for possible size
8037 -- and alignments on the Expr object that may make the alignment
8038 -- different, even though the types are the same.
8040 if Is_Entity_Name (Expr) then
8042 -- First check alignment of the Expr object. Any alignment less
8043 -- than Maximum_Alignment is worrisome since this is the case
8044 -- where we do not know the alignment of Obj.
8046 if Known_Alignment (Entity (Expr))
8047 and then UI_To_Int (Alignment (Entity (Expr))) <
8048 Ttypes.Maximum_Alignment
8050 Set_Result (Unknown);
8052 -- Now check size of Expr object. Any size that is not an
8053 -- even multiple of Maximum_Alignment is also worrisome
8054 -- since it may cause the alignment of the object to be less
8055 -- than the alignment of the type.
8057 elsif Known_Static_Esize (Entity (Expr))
8059 (UI_To_Int (Esize (Entity (Expr))) mod
8060 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
8063 Set_Result (Unknown);
8065 -- Otherwise same type is decisive
8068 Set_Result (Known_Compatible);
8072 -- Another case to deal with is when there is an explicit size or
8073 -- alignment clause when the types are not the same. If so, then the
8074 -- result is Unknown. We don't need to do this test if the Default is
8075 -- Unknown, since that result will be set in any case.
8077 elsif Default /= Unknown
8078 and then (Has_Size_Clause (Etype (Expr))
8080 Has_Alignment_Clause (Etype (Expr)))
8082 Set_Result (Unknown);
8084 -- If no indication found, set default
8087 Set_Result (Default);
8090 -- Return worst result found
8093 end Has_Compatible_Alignment_Internal;
8095 -- Start of processing for Has_Compatible_Alignment
8098 -- If Obj has no specified alignment, then set alignment from the type
8099 -- alignment. Perhaps we should always do this, but for sure we should
8100 -- do it when there is an address clause since we can do more if the
8101 -- alignment is known.
8103 if Unknown_Alignment (Obj) then
8104 Set_Alignment (Obj, Alignment (Etype (Obj)));
8107 -- Now do the internal call that does all the work
8109 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
8110 end Has_Compatible_Alignment;
8112 ----------------------
8113 -- Has_Declarations --
8114 ----------------------
8116 function Has_Declarations (N : Node_Id) return Boolean is
8118 return Nkind_In (Nkind (N), N_Accept_Statement,
8120 N_Compilation_Unit_Aux,
8126 N_Package_Specification);
8127 end Has_Declarations;
8129 ---------------------------------
8130 -- Has_Defaulted_Discriminants --
8131 ---------------------------------
8133 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
8135 return Has_Discriminants (Typ)
8136 and then Present (First_Discriminant (Typ))
8137 and then Present (Discriminant_Default_Value
8138 (First_Discriminant (Typ)));
8139 end Has_Defaulted_Discriminants;
8145 function Has_Denormals (E : Entity_Id) return Boolean is
8147 return Is_Floating_Point_Type (E) and then Denorm_On_Target;
8150 -------------------------------------------
8151 -- Has_Discriminant_Dependent_Constraint --
8152 -------------------------------------------
8154 function Has_Discriminant_Dependent_Constraint
8155 (Comp : Entity_Id) return Boolean
8157 Comp_Decl : constant Node_Id := Parent (Comp);
8158 Subt_Indic : Node_Id;
8163 -- Discriminants can't depend on discriminants
8165 if Ekind (Comp) = E_Discriminant then
8169 Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl));
8171 if Nkind (Subt_Indic) = N_Subtype_Indication then
8172 Constr := Constraint (Subt_Indic);
8174 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
8175 Assn := First (Constraints (Constr));
8176 while Present (Assn) loop
8177 case Nkind (Assn) is
8178 when N_Subtype_Indication |
8182 if Depends_On_Discriminant (Assn) then
8186 when N_Discriminant_Association =>
8187 if Depends_On_Discriminant (Expression (Assn)) then
8202 end Has_Discriminant_Dependent_Constraint;
8204 --------------------------
8205 -- Has_Enabled_Property --
8206 --------------------------
8208 function Has_Enabled_Property
8209 (Item_Id : Entity_Id;
8210 Property : Name_Id) return Boolean
8212 function State_Has_Enabled_Property return Boolean;
8213 -- Determine whether a state denoted by Item_Id has the property enabled
8215 function Variable_Has_Enabled_Property return Boolean;
8216 -- Determine whether a variable denoted by Item_Id has the property
8219 --------------------------------
8220 -- State_Has_Enabled_Property --
8221 --------------------------------
8223 function State_Has_Enabled_Property return Boolean is
8224 Decl : constant Node_Id := Parent (Item_Id);
8232 -- The declaration of an external abstract state appears as an
8233 -- extension aggregate. If this is not the case, properties can never
8236 if Nkind (Decl) /= N_Extension_Aggregate then
8240 -- When External appears as a simple option, it automatically enables
8243 Opt := First (Expressions (Decl));
8244 while Present (Opt) loop
8245 if Nkind (Opt) = N_Identifier
8246 and then Chars (Opt) = Name_External
8254 -- When External specifies particular properties, inspect those and
8255 -- find the desired one (if any).
8257 Opt := First (Component_Associations (Decl));
8258 while Present (Opt) loop
8259 Opt_Nam := First (Choices (Opt));
8261 if Nkind (Opt_Nam) = N_Identifier
8262 and then Chars (Opt_Nam) = Name_External
8264 Props := Expression (Opt);
8266 -- Multiple properties appear as an aggregate
8268 if Nkind (Props) = N_Aggregate then
8270 -- Simple property form
8272 Prop := First (Expressions (Props));
8273 while Present (Prop) loop
8274 if Chars (Prop) = Property then
8281 -- Property with expression form
8283 Prop := First (Component_Associations (Props));
8284 while Present (Prop) loop
8285 Prop_Nam := First (Choices (Prop));
8287 -- The property can be represented in two ways:
8288 -- others => <value>
8289 -- <property> => <value>
8291 if Nkind (Prop_Nam) = N_Others_Choice
8292 or else (Nkind (Prop_Nam) = N_Identifier
8293 and then Chars (Prop_Nam) = Property)
8295 return Is_True (Expr_Value (Expression (Prop)));
8304 return Chars (Props) = Property;
8312 end State_Has_Enabled_Property;
8314 -----------------------------------
8315 -- Variable_Has_Enabled_Property --
8316 -----------------------------------
8318 function Variable_Has_Enabled_Property return Boolean is
8319 function Is_Enabled (Prag : Node_Id) return Boolean;
8320 -- Determine whether property pragma Prag (if present) denotes an
8321 -- enabled property.
8327 function Is_Enabled (Prag : Node_Id) return Boolean is
8331 if Present (Prag) then
8332 Arg2 := Next (First (Pragma_Argument_Associations (Prag)));
8334 -- The pragma has an optional Boolean expression, the related
8335 -- property is enabled only when the expression evaluates to
8338 if Present (Arg2) then
8339 return Is_True (Expr_Value (Get_Pragma_Arg (Arg2)));
8341 -- Otherwise the lack of expression enables the property by
8348 -- The property was never set in the first place
8357 AR : constant Node_Id :=
8358 Get_Pragma (Item_Id, Pragma_Async_Readers);
8359 AW : constant Node_Id :=
8360 Get_Pragma (Item_Id, Pragma_Async_Writers);
8361 ER : constant Node_Id :=
8362 Get_Pragma (Item_Id, Pragma_Effective_Reads);
8363 EW : constant Node_Id :=
8364 Get_Pragma (Item_Id, Pragma_Effective_Writes);
8366 -- Start of processing for Variable_Has_Enabled_Property
8369 -- A non-effectively volatile object can never possess external
8372 if not Is_Effectively_Volatile (Item_Id) then
8375 -- External properties related to variables come in two flavors -
8376 -- explicit and implicit. The explicit case is characterized by the
8377 -- presence of a property pragma with an optional Boolean flag. The
8378 -- property is enabled when the flag evaluates to True or the flag is
8379 -- missing altogether.
8381 elsif Property = Name_Async_Readers and then Is_Enabled (AR) then
8384 elsif Property = Name_Async_Writers and then Is_Enabled (AW) then
8387 elsif Property = Name_Effective_Reads and then Is_Enabled (ER) then
8390 elsif Property = Name_Effective_Writes and then Is_Enabled (EW) then
8393 -- The implicit case lacks all property pragmas
8395 elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then
8401 end Variable_Has_Enabled_Property;
8403 -- Start of processing for Has_Enabled_Property
8406 -- Abstract states and variables have a flexible scheme of specifying
8407 -- external properties.
8409 if Ekind (Item_Id) = E_Abstract_State then
8410 return State_Has_Enabled_Property;
8412 elsif Ekind (Item_Id) = E_Variable then
8413 return Variable_Has_Enabled_Property;
8415 -- Otherwise a property is enabled when the related item is effectively
8419 return Is_Effectively_Volatile (Item_Id);
8421 end Has_Enabled_Property;
8423 --------------------
8424 -- Has_Infinities --
8425 --------------------
8427 function Has_Infinities (E : Entity_Id) return Boolean is
8430 Is_Floating_Point_Type (E)
8431 and then Nkind (Scalar_Range (E)) = N_Range
8432 and then Includes_Infinities (Scalar_Range (E));
8435 --------------------
8436 -- Has_Interfaces --
8437 --------------------
8439 function Has_Interfaces
8441 Use_Full_View : Boolean := True) return Boolean
8443 Typ : Entity_Id := Base_Type (T);
8446 -- Handle concurrent types
8448 if Is_Concurrent_Type (Typ) then
8449 Typ := Corresponding_Record_Type (Typ);
8452 if not Present (Typ)
8453 or else not Is_Record_Type (Typ)
8454 or else not Is_Tagged_Type (Typ)
8459 -- Handle private types
8461 if Use_Full_View and then Present (Full_View (Typ)) then
8462 Typ := Full_View (Typ);
8465 -- Handle concurrent record types
8467 if Is_Concurrent_Record_Type (Typ)
8468 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
8474 if Is_Interface (Typ)
8476 (Is_Record_Type (Typ)
8477 and then Present (Interfaces (Typ))
8478 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
8483 exit when Etype (Typ) = Typ
8485 -- Handle private types
8487 or else (Present (Full_View (Etype (Typ)))
8488 and then Full_View (Etype (Typ)) = Typ)
8490 -- Protect frontend against wrong sources with cyclic derivations
8492 or else Etype (Typ) = T;
8494 -- Climb to the ancestor type handling private types
8496 if Present (Full_View (Etype (Typ))) then
8497 Typ := Full_View (Etype (Typ));
8506 ---------------------------------
8507 -- Has_No_Obvious_Side_Effects --
8508 ---------------------------------
8510 function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
8512 -- For now, just handle literals, constants, and non-volatile
8513 -- variables and expressions combining these with operators or
8514 -- short circuit forms.
8516 if Nkind (N) in N_Numeric_Or_String_Literal then
8519 elsif Nkind (N) = N_Character_Literal then
8522 elsif Nkind (N) in N_Unary_Op then
8523 return Has_No_Obvious_Side_Effects (Right_Opnd (N));
8525 elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
8526 return Has_No_Obvious_Side_Effects (Left_Opnd (N))
8528 Has_No_Obvious_Side_Effects (Right_Opnd (N));
8530 elsif Nkind (N) = N_Expression_With_Actions
8531 and then Is_Empty_List (Actions (N))
8533 return Has_No_Obvious_Side_Effects (Expression (N));
8535 elsif Nkind (N) in N_Has_Entity then
8536 return Present (Entity (N))
8537 and then Ekind_In (Entity (N), E_Variable,
8539 E_Enumeration_Literal,
8543 and then not Is_Volatile (Entity (N));
8548 end Has_No_Obvious_Side_Effects;
8550 ------------------------
8551 -- Has_Null_Exclusion --
8552 ------------------------
8554 function Has_Null_Exclusion (N : Node_Id) return Boolean is
8557 when N_Access_Definition |
8558 N_Access_Function_Definition |
8559 N_Access_Procedure_Definition |
8560 N_Access_To_Object_Definition |
8562 N_Derived_Type_Definition |
8563 N_Function_Specification |
8564 N_Subtype_Declaration =>
8565 return Null_Exclusion_Present (N);
8567 when N_Component_Definition |
8568 N_Formal_Object_Declaration |
8569 N_Object_Renaming_Declaration =>
8570 if Present (Subtype_Mark (N)) then
8571 return Null_Exclusion_Present (N);
8572 else pragma Assert (Present (Access_Definition (N)));
8573 return Null_Exclusion_Present (Access_Definition (N));
8576 when N_Discriminant_Specification =>
8577 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
8578 return Null_Exclusion_Present (Discriminant_Type (N));
8580 return Null_Exclusion_Present (N);
8583 when N_Object_Declaration =>
8584 if Nkind (Object_Definition (N)) = N_Access_Definition then
8585 return Null_Exclusion_Present (Object_Definition (N));
8587 return Null_Exclusion_Present (N);
8590 when N_Parameter_Specification =>
8591 if Nkind (Parameter_Type (N)) = N_Access_Definition then
8592 return Null_Exclusion_Present (Parameter_Type (N));
8594 return Null_Exclusion_Present (N);
8601 end Has_Null_Exclusion;
8603 ------------------------
8604 -- Has_Null_Extension --
8605 ------------------------
8607 function Has_Null_Extension (T : Entity_Id) return Boolean is
8608 B : constant Entity_Id := Base_Type (T);
8613 if Nkind (Parent (B)) = N_Full_Type_Declaration
8614 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
8616 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
8618 if Present (Ext) then
8619 if Null_Present (Ext) then
8622 Comps := Component_List (Ext);
8624 -- The null component list is rewritten during analysis to
8625 -- include the parent component. Any other component indicates
8626 -- that the extension was not originally null.
8628 return Null_Present (Comps)
8629 or else No (Next (First (Component_Items (Comps))));
8638 end Has_Null_Extension;
8640 -------------------------------
8641 -- Has_Overriding_Initialize --
8642 -------------------------------
8644 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
8645 BT : constant Entity_Id := Base_Type (T);
8649 if Is_Controlled (BT) then
8650 if Is_RTU (Scope (BT), Ada_Finalization) then
8653 elsif Present (Primitive_Operations (BT)) then
8654 P := First_Elmt (Primitive_Operations (BT));
8655 while Present (P) loop
8657 Init : constant Entity_Id := Node (P);
8658 Formal : constant Entity_Id := First_Formal (Init);
8660 if Ekind (Init) = E_Procedure
8661 and then Chars (Init) = Name_Initialize
8662 and then Comes_From_Source (Init)
8663 and then Present (Formal)
8664 and then Etype (Formal) = BT
8665 and then No (Next_Formal (Formal))
8666 and then (Ada_Version < Ada_2012
8667 or else not Null_Present (Parent (Init)))
8677 -- Here if type itself does not have a non-null Initialize operation:
8678 -- check immediate ancestor.
8680 if Is_Derived_Type (BT)
8681 and then Has_Overriding_Initialize (Etype (BT))
8688 end Has_Overriding_Initialize;
8690 --------------------------------------
8691 -- Has_Preelaborable_Initialization --
8692 --------------------------------------
8694 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
8697 procedure Check_Components (E : Entity_Id);
8698 -- Check component/discriminant chain, sets Has_PE False if a component
8699 -- or discriminant does not meet the preelaborable initialization rules.
8701 ----------------------
8702 -- Check_Components --
8703 ----------------------
8705 procedure Check_Components (E : Entity_Id) is
8709 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
8710 -- Returns True if and only if the expression denoted by N does not
8711 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
8713 ---------------------------------
8714 -- Is_Preelaborable_Expression --
8715 ---------------------------------
8717 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
8721 Comp_Type : Entity_Id;
8722 Is_Array_Aggr : Boolean;
8725 if Is_OK_Static_Expression (N) then
8728 elsif Nkind (N) = N_Null then
8731 -- Attributes are allowed in general, even if their prefix is a
8732 -- formal type. (It seems that certain attributes known not to be
8733 -- static might not be allowed, but there are no rules to prevent
8736 elsif Nkind (N) = N_Attribute_Reference then
8739 -- The name of a discriminant evaluated within its parent type is
8740 -- defined to be preelaborable (10.2.1(8)). Note that we test for
8741 -- names that denote discriminals as well as discriminants to
8742 -- catch references occurring within init procs.
8744 elsif Is_Entity_Name (N)
8746 (Ekind (Entity (N)) = E_Discriminant
8747 or else (Ekind_In (Entity (N), E_Constant, E_In_Parameter)
8748 and then Present (Discriminal_Link (Entity (N)))))
8752 elsif Nkind (N) = N_Qualified_Expression then
8753 return Is_Preelaborable_Expression (Expression (N));
8755 -- For aggregates we have to check that each of the associations
8756 -- is preelaborable.
8758 elsif Nkind_In (N, N_Aggregate, N_Extension_Aggregate) then
8759 Is_Array_Aggr := Is_Array_Type (Etype (N));
8761 if Is_Array_Aggr then
8762 Comp_Type := Component_Type (Etype (N));
8765 -- Check the ancestor part of extension aggregates, which must
8766 -- be either the name of a type that has preelaborable init or
8767 -- an expression that is preelaborable.
8769 if Nkind (N) = N_Extension_Aggregate then
8771 Anc_Part : constant Node_Id := Ancestor_Part (N);
8774 if Is_Entity_Name (Anc_Part)
8775 and then Is_Type (Entity (Anc_Part))
8777 if not Has_Preelaborable_Initialization
8783 elsif not Is_Preelaborable_Expression (Anc_Part) then
8789 -- Check positional associations
8791 Exp := First (Expressions (N));
8792 while Present (Exp) loop
8793 if not Is_Preelaborable_Expression (Exp) then
8800 -- Check named associations
8802 Assn := First (Component_Associations (N));
8803 while Present (Assn) loop
8804 Choice := First (Choices (Assn));
8805 while Present (Choice) loop
8806 if Is_Array_Aggr then
8807 if Nkind (Choice) = N_Others_Choice then
8810 elsif Nkind (Choice) = N_Range then
8811 if not Is_OK_Static_Range (Choice) then
8815 elsif not Is_OK_Static_Expression (Choice) then
8820 Comp_Type := Etype (Choice);
8826 -- If the association has a <> at this point, then we have
8827 -- to check whether the component's type has preelaborable
8828 -- initialization. Note that this only occurs when the
8829 -- association's corresponding component does not have a
8830 -- default expression, the latter case having already been
8831 -- expanded as an expression for the association.
8833 if Box_Present (Assn) then
8834 if not Has_Preelaborable_Initialization (Comp_Type) then
8838 -- In the expression case we check whether the expression
8839 -- is preelaborable.
8842 not Is_Preelaborable_Expression (Expression (Assn))
8850 -- If we get here then aggregate as a whole is preelaborable
8854 -- All other cases are not preelaborable
8859 end Is_Preelaborable_Expression;
8861 -- Start of processing for Check_Components
8864 -- Loop through entities of record or protected type
8867 while Present (Ent) loop
8869 -- We are interested only in components and discriminants
8876 -- Get default expression if any. If there is no declaration
8877 -- node, it means we have an internal entity. The parent and
8878 -- tag fields are examples of such entities. For such cases,
8879 -- we just test the type of the entity.
8881 if Present (Declaration_Node (Ent)) then
8882 Exp := Expression (Declaration_Node (Ent));
8885 when E_Discriminant =>
8887 -- Note: for a renamed discriminant, the Declaration_Node
8888 -- may point to the one from the ancestor, and have a
8889 -- different expression, so use the proper attribute to
8890 -- retrieve the expression from the derived constraint.
8892 Exp := Discriminant_Default_Value (Ent);
8895 goto Check_Next_Entity;
8898 -- A component has PI if it has no default expression and the
8899 -- component type has PI.
8902 if not Has_Preelaborable_Initialization (Etype (Ent)) then
8907 -- Require the default expression to be preelaborable
8909 elsif not Is_Preelaborable_Expression (Exp) then
8914 <<Check_Next_Entity>>
8917 end Check_Components;
8919 -- Start of processing for Has_Preelaborable_Initialization
8922 -- Immediate return if already marked as known preelaborable init. This
8923 -- covers types for which this function has already been called once
8924 -- and returned True (in which case the result is cached), and also
8925 -- types to which a pragma Preelaborable_Initialization applies.
8927 if Known_To_Have_Preelab_Init (E) then
8931 -- If the type is a subtype representing a generic actual type, then
8932 -- test whether its base type has preelaborable initialization since
8933 -- the subtype representing the actual does not inherit this attribute
8934 -- from the actual or formal. (but maybe it should???)
8936 if Is_Generic_Actual_Type (E) then
8937 return Has_Preelaborable_Initialization (Base_Type (E));
8940 -- All elementary types have preelaborable initialization
8942 if Is_Elementary_Type (E) then
8945 -- Array types have PI if the component type has PI
8947 elsif Is_Array_Type (E) then
8948 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
8950 -- A derived type has preelaborable initialization if its parent type
8951 -- has preelaborable initialization and (in the case of a derived record
8952 -- extension) if the non-inherited components all have preelaborable
8953 -- initialization. However, a user-defined controlled type with an
8954 -- overriding Initialize procedure does not have preelaborable
8957 elsif Is_Derived_Type (E) then
8959 -- If the derived type is a private extension then it doesn't have
8960 -- preelaborable initialization.
8962 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
8966 -- First check whether ancestor type has preelaborable initialization
8968 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
8970 -- If OK, check extension components (if any)
8972 if Has_PE and then Is_Record_Type (E) then
8973 Check_Components (First_Entity (E));
8976 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
8977 -- with a user defined Initialize procedure does not have PI. If
8978 -- the type is untagged, the control primitives come from a component
8979 -- that has already been checked.
8982 and then Is_Controlled (E)
8983 and then Is_Tagged_Type (E)
8984 and then Has_Overriding_Initialize (E)
8989 -- Private types not derived from a type having preelaborable init and
8990 -- that are not marked with pragma Preelaborable_Initialization do not
8991 -- have preelaborable initialization.
8993 elsif Is_Private_Type (E) then
8996 -- Record type has PI if it is non private and all components have PI
8998 elsif Is_Record_Type (E) then
9000 Check_Components (First_Entity (E));
9002 -- Protected types must not have entries, and components must meet
9003 -- same set of rules as for record components.
9005 elsif Is_Protected_Type (E) then
9006 if Has_Entries (E) then
9010 Check_Components (First_Entity (E));
9011 Check_Components (First_Private_Entity (E));
9014 -- Type System.Address always has preelaborable initialization
9016 elsif Is_RTE (E, RE_Address) then
9019 -- In all other cases, type does not have preelaborable initialization
9025 -- If type has preelaborable initialization, cache result
9028 Set_Known_To_Have_Preelab_Init (E);
9032 end Has_Preelaborable_Initialization;
9034 ---------------------------
9035 -- Has_Private_Component --
9036 ---------------------------
9038 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
9039 Btype : Entity_Id := Base_Type (Type_Id);
9040 Component : Entity_Id;
9043 if Error_Posted (Type_Id)
9044 or else Error_Posted (Btype)
9049 if Is_Class_Wide_Type (Btype) then
9050 Btype := Root_Type (Btype);
9053 if Is_Private_Type (Btype) then
9055 UT : constant Entity_Id := Underlying_Type (Btype);
9058 if No (Full_View (Btype)) then
9059 return not Is_Generic_Type (Btype)
9061 not Is_Generic_Type (Root_Type (Btype));
9063 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
9066 return not Is_Frozen (UT) and then Has_Private_Component (UT);
9070 elsif Is_Array_Type (Btype) then
9071 return Has_Private_Component (Component_Type (Btype));
9073 elsif Is_Record_Type (Btype) then
9074 Component := First_Component (Btype);
9075 while Present (Component) loop
9076 if Has_Private_Component (Etype (Component)) then
9080 Next_Component (Component);
9085 elsif Is_Protected_Type (Btype)
9086 and then Present (Corresponding_Record_Type (Btype))
9088 return Has_Private_Component (Corresponding_Record_Type (Btype));
9093 end Has_Private_Component;
9095 ----------------------
9096 -- Has_Signed_Zeros --
9097 ----------------------
9099 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
9101 return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target;
9102 end Has_Signed_Zeros;
9104 ------------------------------
9105 -- Has_Significant_Contract --
9106 ------------------------------
9108 function Has_Significant_Contract (Subp_Id : Entity_Id) return Boolean is
9109 Subp_Nam : constant Name_Id := Chars (Subp_Id);
9112 -- _Finalizer procedure
9114 if Subp_Nam = Name_uFinalizer then
9117 -- _Postconditions procedure
9119 elsif Subp_Nam = Name_uPostconditions then
9122 -- Predicate function
9124 elsif Ekind (Subp_Id) = E_Function
9125 and then Is_Predicate_Function (Subp_Id)
9131 elsif Get_TSS_Name (Subp_Id) /= TSS_Null then
9137 end Has_Significant_Contract;
9139 -----------------------------
9140 -- Has_Static_Array_Bounds --
9141 -----------------------------
9143 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
9144 Ndims : constant Nat := Number_Dimensions (Typ);
9151 -- Unconstrained types do not have static bounds
9153 if not Is_Constrained (Typ) then
9157 -- First treat string literals specially, as the lower bound and length
9158 -- of string literals are not stored like those of arrays.
9160 -- A string literal always has static bounds
9162 if Ekind (Typ) = E_String_Literal_Subtype then
9166 -- Treat all dimensions in turn
9168 Index := First_Index (Typ);
9169 for Indx in 1 .. Ndims loop
9171 -- In case of an illegal index which is not a discrete type, return
9172 -- that the type is not static.
9174 if not Is_Discrete_Type (Etype (Index))
9175 or else Etype (Index) = Any_Type
9180 Get_Index_Bounds (Index, Low, High);
9182 if Error_Posted (Low) or else Error_Posted (High) then
9186 if Is_OK_Static_Expression (Low)
9188 Is_OK_Static_Expression (High)
9198 -- If we fall through the loop, all indexes matched
9201 end Has_Static_Array_Bounds;
9207 function Has_Stream (T : Entity_Id) return Boolean is
9214 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
9217 elsif Is_Array_Type (T) then
9218 return Has_Stream (Component_Type (T));
9220 elsif Is_Record_Type (T) then
9221 E := First_Component (T);
9222 while Present (E) loop
9223 if Has_Stream (Etype (E)) then
9232 elsif Is_Private_Type (T) then
9233 return Has_Stream (Underlying_Type (T));
9244 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
9246 Get_Name_String (Chars (E));
9247 return Name_Buffer (Name_Len) = Suffix;
9254 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
9256 Get_Name_String (Chars (E));
9257 Add_Char_To_Name_Buffer (Suffix);
9265 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
9267 pragma Assert (Has_Suffix (E, Suffix));
9268 Get_Name_String (Chars (E));
9269 Name_Len := Name_Len - 1;
9273 --------------------------
9274 -- Has_Tagged_Component --
9275 --------------------------
9277 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
9281 if Is_Private_Type (Typ) and then Present (Underlying_Type (Typ)) then
9282 return Has_Tagged_Component (Underlying_Type (Typ));
9284 elsif Is_Array_Type (Typ) then
9285 return Has_Tagged_Component (Component_Type (Typ));
9287 elsif Is_Tagged_Type (Typ) then
9290 elsif Is_Record_Type (Typ) then
9291 Comp := First_Component (Typ);
9292 while Present (Comp) loop
9293 if Has_Tagged_Component (Etype (Comp)) then
9297 Next_Component (Comp);
9305 end Has_Tagged_Component;
9307 ----------------------------
9308 -- Has_Volatile_Component --
9309 ----------------------------
9311 function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
9315 if Has_Volatile_Components (Typ) then
9318 elsif Is_Array_Type (Typ) then
9319 return Is_Volatile (Component_Type (Typ));
9321 elsif Is_Record_Type (Typ) then
9322 Comp := First_Component (Typ);
9323 while Present (Comp) loop
9324 if Is_Volatile_Object (Comp) then
9328 Comp := Next_Component (Comp);
9333 end Has_Volatile_Component;
9335 -------------------------
9336 -- Implementation_Kind --
9337 -------------------------
9339 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
9340 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
9343 pragma Assert (Present (Impl_Prag));
9344 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
9345 return Chars (Get_Pragma_Arg (Arg));
9346 end Implementation_Kind;
9348 --------------------------
9349 -- Implements_Interface --
9350 --------------------------
9352 function Implements_Interface
9353 (Typ_Ent : Entity_Id;
9354 Iface_Ent : Entity_Id;
9355 Exclude_Parents : Boolean := False) return Boolean
9357 Ifaces_List : Elist_Id;
9359 Iface : Entity_Id := Base_Type (Iface_Ent);
9360 Typ : Entity_Id := Base_Type (Typ_Ent);
9363 if Is_Class_Wide_Type (Typ) then
9364 Typ := Root_Type (Typ);
9367 if not Has_Interfaces (Typ) then
9371 if Is_Class_Wide_Type (Iface) then
9372 Iface := Root_Type (Iface);
9375 Collect_Interfaces (Typ, Ifaces_List);
9377 Elmt := First_Elmt (Ifaces_List);
9378 while Present (Elmt) loop
9379 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
9380 and then Exclude_Parents
9384 elsif Node (Elmt) = Iface then
9392 end Implements_Interface;
9394 ------------------------------------
9395 -- In_Assertion_Expression_Pragma --
9396 ------------------------------------
9398 function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is
9400 Prag : Node_Id := Empty;
9403 -- Climb the parent chain looking for an enclosing pragma
9406 while Present (Par) loop
9407 if Nkind (Par) = N_Pragma then
9411 -- Precondition-like pragmas are expanded into if statements, check
9412 -- the original node instead.
9414 elsif Nkind (Original_Node (Par)) = N_Pragma then
9415 Prag := Original_Node (Par);
9418 -- The expansion of attribute 'Old generates a constant to capture
9419 -- the result of the prefix. If the parent traversal reaches
9420 -- one of these constants, then the node technically came from a
9421 -- postcondition-like pragma. Note that the Ekind is not tested here
9422 -- because N may be the expression of an object declaration which is
9423 -- currently being analyzed. Such objects carry Ekind of E_Void.
9425 elsif Nkind (Par) = N_Object_Declaration
9426 and then Constant_Present (Par)
9427 and then Stores_Attribute_Old_Prefix (Defining_Entity (Par))
9431 -- Prevent the search from going too far
9433 elsif Is_Body_Or_Package_Declaration (Par) then
9437 Par := Parent (Par);
9442 and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag));
9443 end In_Assertion_Expression_Pragma;
9449 function In_Instance return Boolean is
9450 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
9455 while Present (S) and then S /= Standard_Standard loop
9456 if Ekind_In (S, E_Function, E_Package, E_Procedure)
9457 and then Is_Generic_Instance (S)
9459 -- A child instance is always compiled in the context of a parent
9460 -- instance. Nevertheless, the actuals are not analyzed in an
9461 -- instance context. We detect this case by examining the current
9462 -- compilation unit, which must be a child instance, and checking
9463 -- that it is not currently on the scope stack.
9465 if Is_Child_Unit (Curr_Unit)
9466 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
9467 N_Package_Instantiation
9468 and then not In_Open_Scopes (Curr_Unit)
9482 ----------------------
9483 -- In_Instance_Body --
9484 ----------------------
9486 function In_Instance_Body return Boolean is
9491 while Present (S) and then S /= Standard_Standard loop
9492 if Ekind_In (S, E_Function, E_Procedure)
9493 and then Is_Generic_Instance (S)
9497 elsif Ekind (S) = E_Package
9498 and then In_Package_Body (S)
9499 and then Is_Generic_Instance (S)
9508 end In_Instance_Body;
9510 -----------------------------
9511 -- In_Instance_Not_Visible --
9512 -----------------------------
9514 function In_Instance_Not_Visible return Boolean is
9519 while Present (S) and then S /= Standard_Standard loop
9520 if Ekind_In (S, E_Function, E_Procedure)
9521 and then Is_Generic_Instance (S)
9525 elsif Ekind (S) = E_Package
9526 and then (In_Package_Body (S) or else In_Private_Part (S))
9527 and then Is_Generic_Instance (S)
9536 end In_Instance_Not_Visible;
9538 ------------------------------
9539 -- In_Instance_Visible_Part --
9540 ------------------------------
9542 function In_Instance_Visible_Part return Boolean is
9547 while Present (S) and then S /= Standard_Standard loop
9548 if Ekind (S) = E_Package
9549 and then Is_Generic_Instance (S)
9550 and then not In_Package_Body (S)
9551 and then not In_Private_Part (S)
9560 end In_Instance_Visible_Part;
9562 ---------------------
9563 -- In_Package_Body --
9564 ---------------------
9566 function In_Package_Body return Boolean is
9571 while Present (S) and then S /= Standard_Standard loop
9572 if Ekind (S) = E_Package and then In_Package_Body (S) then
9580 end In_Package_Body;
9582 --------------------------------
9583 -- In_Parameter_Specification --
9584 --------------------------------
9586 function In_Parameter_Specification (N : Node_Id) return Boolean is
9591 while Present (PN) loop
9592 if Nkind (PN) = N_Parameter_Specification then
9600 end In_Parameter_Specification;
9602 --------------------------
9603 -- In_Pragma_Expression --
9604 --------------------------
9606 function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean is
9613 elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
9619 end In_Pragma_Expression;
9621 -------------------------------------
9622 -- In_Reverse_Storage_Order_Object --
9623 -------------------------------------
9625 function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
9627 Btyp : Entity_Id := Empty;
9630 -- Climb up indexed components
9634 case Nkind (Pref) is
9635 when N_Selected_Component =>
9636 Pref := Prefix (Pref);
9639 when N_Indexed_Component =>
9640 Pref := Prefix (Pref);
9648 if Present (Pref) then
9649 Btyp := Base_Type (Etype (Pref));
9652 return Present (Btyp)
9653 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
9654 and then Reverse_Storage_Order (Btyp);
9655 end In_Reverse_Storage_Order_Object;
9657 --------------------------------------
9658 -- In_Subprogram_Or_Concurrent_Unit --
9659 --------------------------------------
9661 function In_Subprogram_Or_Concurrent_Unit return Boolean is
9666 -- Use scope chain to check successively outer scopes
9672 if K in Subprogram_Kind
9673 or else K in Concurrent_Kind
9674 or else K in Generic_Subprogram_Kind
9678 elsif E = Standard_Standard then
9684 end In_Subprogram_Or_Concurrent_Unit;
9686 ---------------------
9687 -- In_Visible_Part --
9688 ---------------------
9690 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
9692 return Is_Package_Or_Generic_Package (Scope_Id)
9693 and then In_Open_Scopes (Scope_Id)
9694 and then not In_Package_Body (Scope_Id)
9695 and then not In_Private_Part (Scope_Id);
9696 end In_Visible_Part;
9698 --------------------------------
9699 -- Incomplete_Or_Partial_View --
9700 --------------------------------
9702 function Incomplete_Or_Partial_View (Id : Entity_Id) return Entity_Id is
9703 function Inspect_Decls
9705 Taft : Boolean := False) return Entity_Id;
9706 -- Check whether a declarative region contains the incomplete or partial
9713 function Inspect_Decls
9715 Taft : Boolean := False) return Entity_Id
9721 Decl := First (Decls);
9722 while Present (Decl) loop
9726 if Nkind (Decl) = N_Incomplete_Type_Declaration then
9727 Match := Defining_Identifier (Decl);
9731 if Nkind_In (Decl, N_Private_Extension_Declaration,
9732 N_Private_Type_Declaration)
9734 Match := Defining_Identifier (Decl);
9739 and then Present (Full_View (Match))
9740 and then Full_View (Match) = Id
9755 -- Start of processing for Incomplete_Or_Partial_View
9758 -- Deferred constant or incomplete type case
9760 Prev := Current_Entity_In_Scope (Id);
9763 and then (Is_Incomplete_Type (Prev) or else Ekind (Prev) = E_Constant)
9764 and then Present (Full_View (Prev))
9765 and then Full_View (Prev) = Id
9770 -- Private or Taft amendment type case
9773 Pkg : constant Entity_Id := Scope (Id);
9774 Pkg_Decl : Node_Id := Pkg;
9777 if Present (Pkg) and then Ekind (Pkg) = E_Package then
9778 while Nkind (Pkg_Decl) /= N_Package_Specification loop
9779 Pkg_Decl := Parent (Pkg_Decl);
9782 -- It is knows that Typ has a private view, look for it in the
9783 -- visible declarations of the enclosing scope. A special case
9784 -- of this is when the two views have been exchanged - the full
9785 -- appears earlier than the private.
9787 if Has_Private_Declaration (Id) then
9788 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
9790 -- Exchanged view case, look in the private declarations
9793 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
9798 -- Otherwise if this is the package body, then Typ is a potential
9799 -- Taft amendment type. The incomplete view should be located in
9800 -- the private declarations of the enclosing scope.
9802 elsif In_Package_Body (Pkg) then
9803 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
9808 -- The type has no incomplete or private view
9811 end Incomplete_Or_Partial_View;
9813 -----------------------------------------
9814 -- Inherit_Default_Init_Cond_Procedure --
9815 -----------------------------------------
9817 procedure Inherit_Default_Init_Cond_Procedure (Typ : Entity_Id) is
9818 Par_Typ : constant Entity_Id := Etype (Typ);
9821 -- A derived type inherits the default initial condition procedure of
9824 if No (Default_Init_Cond_Procedure (Typ)) then
9825 Set_Default_Init_Cond_Procedure
9826 (Typ, Default_Init_Cond_Procedure (Par_Typ));
9828 end Inherit_Default_Init_Cond_Procedure;
9830 ----------------------------
9831 -- Inherit_Rep_Item_Chain --
9832 ----------------------------
9834 procedure Inherit_Rep_Item_Chain (Typ : Entity_Id; From_Typ : Entity_Id) is
9835 From_Item : constant Node_Id := First_Rep_Item (From_Typ);
9836 Item : Node_Id := Empty;
9837 Last_Item : Node_Id := Empty;
9840 -- Reach the end of the destination type's chain (if any) and capture
9843 Item := First_Rep_Item (Typ);
9844 while Present (Item) loop
9846 -- Do not inherit a chain that has been inherited already
9848 if Item = From_Item then
9853 Item := Next_Rep_Item (Item);
9856 -- When the destination type has a rep item chain, the chain of the
9857 -- source type is appended to it.
9859 if Present (Last_Item) then
9860 Set_Next_Rep_Item (Last_Item, From_Item);
9862 -- Otherwise the destination type directly inherits the rep item chain
9863 -- of the source type (if any).
9866 Set_First_Rep_Item (Typ, From_Item);
9868 end Inherit_Rep_Item_Chain;
9870 ---------------------------------
9871 -- Inherit_Subprogram_Contract --
9872 ---------------------------------
9874 procedure Inherit_Subprogram_Contract
9876 From_Subp : Entity_Id)
9878 procedure Inherit_Pragma (Prag_Id : Pragma_Id);
9879 -- Propagate a pragma denoted by Prag_Id from From_Subp's contract to
9882 --------------------
9883 -- Inherit_Pragma --
9884 --------------------
9886 procedure Inherit_Pragma (Prag_Id : Pragma_Id) is
9887 Prag : constant Node_Id := Get_Pragma (From_Subp, Prag_Id);
9891 -- A pragma cannot be part of more than one First_Pragma/Next_Pragma
9892 -- chains, therefore the node must be replicated. The new pragma is
9893 -- flagged is inherited for distrinction purposes.
9895 if Present (Prag) then
9896 New_Prag := New_Copy_Tree (Prag);
9897 Set_Is_Inherited (New_Prag);
9899 Add_Contract_Item (New_Prag, Subp);
9903 -- Start of processing for Inherit_Subprogram_Contract
9906 -- Inheritance is carried out only when both entities are subprograms
9909 if Is_Subprogram_Or_Generic_Subprogram (Subp)
9910 and then Is_Subprogram_Or_Generic_Subprogram (From_Subp)
9911 and then Present (Contract (From_Subp))
9913 Inherit_Pragma (Pragma_Extensions_Visible);
9915 end Inherit_Subprogram_Contract;
9917 ---------------------------------
9918 -- Insert_Explicit_Dereference --
9919 ---------------------------------
9921 procedure Insert_Explicit_Dereference (N : Node_Id) is
9922 New_Prefix : constant Node_Id := Relocate_Node (N);
9923 Ent : Entity_Id := Empty;
9930 Save_Interps (N, New_Prefix);
9933 Make_Explicit_Dereference (Sloc (Parent (N)),
9934 Prefix => New_Prefix));
9936 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
9938 if Is_Overloaded (New_Prefix) then
9940 -- The dereference is also overloaded, and its interpretations are
9941 -- the designated types of the interpretations of the original node.
9943 Set_Etype (N, Any_Type);
9945 Get_First_Interp (New_Prefix, I, It);
9946 while Present (It.Nam) loop
9949 if Is_Access_Type (T) then
9950 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
9953 Get_Next_Interp (I, It);
9959 -- Prefix is unambiguous: mark the original prefix (which might
9960 -- Come_From_Source) as a reference, since the new (relocated) one
9961 -- won't be taken into account.
9963 if Is_Entity_Name (New_Prefix) then
9964 Ent := Entity (New_Prefix);
9967 -- For a retrieval of a subcomponent of some composite object,
9968 -- retrieve the ultimate entity if there is one.
9970 elsif Nkind_In (New_Prefix, N_Selected_Component,
9971 N_Indexed_Component)
9973 Pref := Prefix (New_Prefix);
9974 while Present (Pref)
9975 and then Nkind_In (Pref, N_Selected_Component,
9976 N_Indexed_Component)
9978 Pref := Prefix (Pref);
9981 if Present (Pref) and then Is_Entity_Name (Pref) then
9982 Ent := Entity (Pref);
9986 -- Place the reference on the entity node
9988 if Present (Ent) then
9989 Generate_Reference (Ent, Pref);
9992 end Insert_Explicit_Dereference;
9994 ------------------------------------------
9995 -- Inspect_Deferred_Constant_Completion --
9996 ------------------------------------------
9998 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
10002 Decl := First (Decls);
10003 while Present (Decl) loop
10005 -- Deferred constant signature
10007 if Nkind (Decl) = N_Object_Declaration
10008 and then Constant_Present (Decl)
10009 and then No (Expression (Decl))
10011 -- No need to check internally generated constants
10013 and then Comes_From_Source (Decl)
10015 -- The constant is not completed. A full object declaration or a
10016 -- pragma Import complete a deferred constant.
10018 and then not Has_Completion (Defining_Identifier (Decl))
10021 ("constant declaration requires initialization expression",
10022 Defining_Identifier (Decl));
10025 Decl := Next (Decl);
10027 end Inspect_Deferred_Constant_Completion;
10029 -----------------------------
10030 -- Install_Generic_Formals --
10031 -----------------------------
10033 procedure Install_Generic_Formals (Subp_Id : Entity_Id) is
10037 pragma Assert (Is_Generic_Subprogram (Subp_Id));
10039 E := First_Entity (Subp_Id);
10040 while Present (E) loop
10041 Install_Entity (E);
10044 end Install_Generic_Formals;
10046 -----------------------------
10047 -- Is_Actual_Out_Parameter --
10048 -----------------------------
10050 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
10051 Formal : Entity_Id;
10054 Find_Actual (N, Formal, Call);
10055 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
10056 end Is_Actual_Out_Parameter;
10058 -------------------------
10059 -- Is_Actual_Parameter --
10060 -------------------------
10062 function Is_Actual_Parameter (N : Node_Id) return Boolean is
10063 PK : constant Node_Kind := Nkind (Parent (N));
10067 when N_Parameter_Association =>
10068 return N = Explicit_Actual_Parameter (Parent (N));
10070 when N_Subprogram_Call =>
10071 return Is_List_Member (N)
10073 List_Containing (N) = Parameter_Associations (Parent (N));
10078 end Is_Actual_Parameter;
10080 --------------------------------
10081 -- Is_Actual_Tagged_Parameter --
10082 --------------------------------
10084 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
10085 Formal : Entity_Id;
10088 Find_Actual (N, Formal, Call);
10089 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
10090 end Is_Actual_Tagged_Parameter;
10092 ---------------------
10093 -- Is_Aliased_View --
10094 ---------------------
10096 function Is_Aliased_View (Obj : Node_Id) return Boolean is
10100 if Is_Entity_Name (Obj) then
10107 or else (Present (Renamed_Object (E))
10108 and then Is_Aliased_View (Renamed_Object (E)))))
10110 or else ((Is_Formal (E)
10111 or else Ekind_In (E, E_Generic_In_Out_Parameter,
10112 E_Generic_In_Parameter))
10113 and then Is_Tagged_Type (Etype (E)))
10115 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
10117 -- Current instance of type, either directly or as rewritten
10118 -- reference to the current object.
10120 or else (Is_Entity_Name (Original_Node (Obj))
10121 and then Present (Entity (Original_Node (Obj)))
10122 and then Is_Type (Entity (Original_Node (Obj))))
10124 or else (Is_Type (E) and then E = Current_Scope)
10126 or else (Is_Incomplete_Or_Private_Type (E)
10127 and then Full_View (E) = Current_Scope)
10129 -- Ada 2012 AI05-0053: the return object of an extended return
10130 -- statement is aliased if its type is immutably limited.
10132 or else (Is_Return_Object (E)
10133 and then Is_Limited_View (Etype (E)));
10135 elsif Nkind (Obj) = N_Selected_Component then
10136 return Is_Aliased (Entity (Selector_Name (Obj)));
10138 elsif Nkind (Obj) = N_Indexed_Component then
10139 return Has_Aliased_Components (Etype (Prefix (Obj)))
10141 (Is_Access_Type (Etype (Prefix (Obj)))
10142 and then Has_Aliased_Components
10143 (Designated_Type (Etype (Prefix (Obj)))));
10145 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
10146 return Is_Tagged_Type (Etype (Obj))
10147 and then Is_Aliased_View (Expression (Obj));
10149 elsif Nkind (Obj) = N_Explicit_Dereference then
10150 return Nkind (Original_Node (Obj)) /= N_Function_Call;
10155 end Is_Aliased_View;
10157 -------------------------
10158 -- Is_Ancestor_Package --
10159 -------------------------
10161 function Is_Ancestor_Package
10163 E2 : Entity_Id) return Boolean
10169 while Present (Par) and then Par /= Standard_Standard loop
10174 Par := Scope (Par);
10178 end Is_Ancestor_Package;
10180 ----------------------
10181 -- Is_Atomic_Object --
10182 ----------------------
10184 function Is_Atomic_Object (N : Node_Id) return Boolean is
10186 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
10187 -- Determines if given object has atomic components
10189 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
10190 -- If prefix is an implicit dereference, examine designated type
10192 ----------------------
10193 -- Is_Atomic_Prefix --
10194 ----------------------
10196 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
10198 if Is_Access_Type (Etype (N)) then
10200 Has_Atomic_Components (Designated_Type (Etype (N)));
10202 return Object_Has_Atomic_Components (N);
10204 end Is_Atomic_Prefix;
10206 ----------------------------------
10207 -- Object_Has_Atomic_Components --
10208 ----------------------------------
10210 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
10212 if Has_Atomic_Components (Etype (N))
10213 or else Is_Atomic (Etype (N))
10217 elsif Is_Entity_Name (N)
10218 and then (Has_Atomic_Components (Entity (N))
10219 or else Is_Atomic (Entity (N)))
10223 elsif Nkind (N) = N_Selected_Component
10224 and then Is_Atomic (Entity (Selector_Name (N)))
10228 elsif Nkind (N) = N_Indexed_Component
10229 or else Nkind (N) = N_Selected_Component
10231 return Is_Atomic_Prefix (Prefix (N));
10236 end Object_Has_Atomic_Components;
10238 -- Start of processing for Is_Atomic_Object
10241 -- Predicate is not relevant to subprograms
10243 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
10246 elsif Is_Atomic (Etype (N))
10247 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
10251 elsif Nkind (N) = N_Selected_Component
10252 and then Is_Atomic (Entity (Selector_Name (N)))
10256 elsif Nkind (N) = N_Indexed_Component
10257 or else Nkind (N) = N_Selected_Component
10259 return Is_Atomic_Prefix (Prefix (N));
10264 end Is_Atomic_Object;
10266 -------------------------
10267 -- Is_Attribute_Result --
10268 -------------------------
10270 function Is_Attribute_Result (N : Node_Id) return Boolean is
10272 return Nkind (N) = N_Attribute_Reference
10273 and then Attribute_Name (N) = Name_Result;
10274 end Is_Attribute_Result;
10276 ------------------------------------
10277 -- Is_Body_Or_Package_Declaration --
10278 ------------------------------------
10280 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
10282 return Nkind_In (N, N_Entry_Body,
10284 N_Package_Declaration,
10288 end Is_Body_Or_Package_Declaration;
10290 -----------------------
10291 -- Is_Bounded_String --
10292 -----------------------
10294 function Is_Bounded_String (T : Entity_Id) return Boolean is
10295 Under : constant Entity_Id := Underlying_Type (Root_Type (T));
10298 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
10299 -- Super_String, or one of the [Wide_]Wide_ versions. This will
10300 -- be True for all the Bounded_String types in instances of the
10301 -- Generic_Bounded_Length generics, and for types derived from those.
10303 return Present (Under)
10304 and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
10305 Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
10306 Is_RTE (Root_Type (Under), RO_WW_Super_String));
10307 end Is_Bounded_String;
10309 -------------------------
10310 -- Is_Child_Or_Sibling --
10311 -------------------------
10313 function Is_Child_Or_Sibling
10314 (Pack_1 : Entity_Id;
10315 Pack_2 : Entity_Id) return Boolean
10317 function Distance_From_Standard (Pack : Entity_Id) return Nat;
10318 -- Given an arbitrary package, return the number of "climbs" necessary
10319 -- to reach scope Standard_Standard.
10321 procedure Equalize_Depths
10322 (Pack : in out Entity_Id;
10323 Depth : in out Nat;
10324 Depth_To_Reach : Nat);
10325 -- Given an arbitrary package, its depth and a target depth to reach,
10326 -- climb the scope chain until the said depth is reached. The pointer
10327 -- to the package and its depth a modified during the climb.
10329 ----------------------------
10330 -- Distance_From_Standard --
10331 ----------------------------
10333 function Distance_From_Standard (Pack : Entity_Id) return Nat is
10340 while Present (Scop) and then Scop /= Standard_Standard loop
10342 Scop := Scope (Scop);
10346 end Distance_From_Standard;
10348 ---------------------
10349 -- Equalize_Depths --
10350 ---------------------
10352 procedure Equalize_Depths
10353 (Pack : in out Entity_Id;
10354 Depth : in out Nat;
10355 Depth_To_Reach : Nat)
10358 -- The package must be at a greater or equal depth
10360 if Depth < Depth_To_Reach then
10361 raise Program_Error;
10364 -- Climb the scope chain until the desired depth is reached
10366 while Present (Pack) and then Depth /= Depth_To_Reach loop
10367 Pack := Scope (Pack);
10368 Depth := Depth - 1;
10370 end Equalize_Depths;
10374 P_1 : Entity_Id := Pack_1;
10375 P_1_Child : Boolean := False;
10376 P_1_Depth : Nat := Distance_From_Standard (P_1);
10377 P_2 : Entity_Id := Pack_2;
10378 P_2_Child : Boolean := False;
10379 P_2_Depth : Nat := Distance_From_Standard (P_2);
10381 -- Start of processing for Is_Child_Or_Sibling
10385 (Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
10387 -- Both packages denote the same entity, therefore they cannot be
10388 -- children or siblings.
10393 -- One of the packages is at a deeper level than the other. Note that
10394 -- both may still come from differen hierarchies.
10402 elsif P_1_Depth > P_2_Depth then
10405 Depth => P_1_Depth,
10406 Depth_To_Reach => P_2_Depth);
10415 elsif P_2_Depth > P_1_Depth then
10418 Depth => P_2_Depth,
10419 Depth_To_Reach => P_1_Depth);
10423 -- At this stage the package pointers have been elevated to the same
10424 -- depth. If the related entities are the same, then one package is a
10425 -- potential child of the other:
10429 -- X became P_1 P_2 or vica versa
10435 return Is_Child_Unit (Pack_1);
10437 else pragma Assert (P_2_Child);
10438 return Is_Child_Unit (Pack_2);
10441 -- The packages may come from the same package chain or from entirely
10442 -- different hierarcies. To determine this, climb the scope stack until
10443 -- a common root is found.
10445 -- (root) (root 1) (root 2)
10450 while Present (P_1) and then Present (P_2) loop
10452 -- The two packages may be siblings
10455 return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2);
10458 P_1 := Scope (P_1);
10459 P_2 := Scope (P_2);
10464 end Is_Child_Or_Sibling;
10466 -----------------------------
10467 -- Is_Concurrent_Interface --
10468 -----------------------------
10470 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
10472 return Is_Interface (T)
10474 (Is_Protected_Interface (T)
10475 or else Is_Synchronized_Interface (T)
10476 or else Is_Task_Interface (T));
10477 end Is_Concurrent_Interface;
10479 -----------------------
10480 -- Is_Constant_Bound --
10481 -----------------------
10483 function Is_Constant_Bound (Exp : Node_Id) return Boolean is
10485 if Compile_Time_Known_Value (Exp) then
10488 elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
10489 return Is_Constant_Object (Entity (Exp))
10490 or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
10492 elsif Nkind (Exp) in N_Binary_Op then
10493 return Is_Constant_Bound (Left_Opnd (Exp))
10494 and then Is_Constant_Bound (Right_Opnd (Exp))
10495 and then Scope (Entity (Exp)) = Standard_Standard;
10500 end Is_Constant_Bound;
10502 ---------------------------
10503 -- Is_Container_Element --
10504 ---------------------------
10506 function Is_Container_Element (Exp : Node_Id) return Boolean is
10507 Loc : constant Source_Ptr := Sloc (Exp);
10508 Pref : constant Node_Id := Prefix (Exp);
10511 -- Call to an indexing aspect
10513 Cont_Typ : Entity_Id;
10514 -- The type of the container being accessed
10516 Elem_Typ : Entity_Id;
10517 -- Its element type
10519 Indexing : Entity_Id;
10520 Is_Const : Boolean;
10521 -- Indicates that constant indexing is used, and the element is thus
10524 Ref_Typ : Entity_Id;
10525 -- The reference type returned by the indexing operation
10528 -- If C is a container, in a context that imposes the element type of
10529 -- that container, the indexing notation C (X) is rewritten as:
10531 -- Indexing (C, X).Discr.all
10533 -- where Indexing is one of the indexing aspects of the container.
10534 -- If the context does not require a reference, the construct can be
10539 -- First, verify that the construct has the proper form
10541 if not Expander_Active then
10544 elsif Nkind (Pref) /= N_Selected_Component then
10547 elsif Nkind (Prefix (Pref)) /= N_Function_Call then
10551 Call := Prefix (Pref);
10552 Ref_Typ := Etype (Call);
10555 if not Has_Implicit_Dereference (Ref_Typ)
10556 or else No (First (Parameter_Associations (Call)))
10557 or else not Is_Entity_Name (Name (Call))
10562 -- Retrieve type of container object, and its iterator aspects
10564 Cont_Typ := Etype (First (Parameter_Associations (Call)));
10565 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Constant_Indexing);
10568 if No (Indexing) then
10570 -- Container should have at least one indexing operation
10574 elsif Entity (Name (Call)) /= Entity (Indexing) then
10576 -- This may be a variable indexing operation
10578 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Variable_Indexing);
10581 or else Entity (Name (Call)) /= Entity (Indexing)
10590 Elem_Typ := Find_Value_Of_Aspect (Cont_Typ, Aspect_Iterator_Element);
10592 if No (Elem_Typ) or else Entity (Elem_Typ) /= Etype (Exp) then
10596 -- Check that the expression is not the target of an assignment, in
10597 -- which case the rewriting is not possible.
10599 if not Is_Const then
10605 while Present (Par)
10607 if Nkind (Parent (Par)) = N_Assignment_Statement
10608 and then Par = Name (Parent (Par))
10612 -- A renaming produces a reference, and the transformation
10615 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
10619 (Nkind (Parent (Par)), N_Function_Call,
10620 N_Procedure_Call_Statement,
10621 N_Entry_Call_Statement)
10623 -- Check that the element is not part of an actual for an
10624 -- in-out parameter.
10631 F := First_Formal (Entity (Name (Parent (Par))));
10632 A := First (Parameter_Associations (Parent (Par)));
10633 while Present (F) loop
10634 if A = Par and then Ekind (F) /= E_In_Parameter then
10643 -- E_In_Parameter in a call: element is not modified.
10648 Par := Parent (Par);
10653 -- The expression has the proper form and the context requires the
10654 -- element type. Retrieve the Element function of the container and
10655 -- rewrite the construct as a call to it.
10661 Op := First_Elmt (Primitive_Operations (Cont_Typ));
10662 while Present (Op) loop
10663 exit when Chars (Node (Op)) = Name_Element;
10672 Make_Function_Call (Loc,
10673 Name => New_Occurrence_Of (Node (Op), Loc),
10674 Parameter_Associations => Parameter_Associations (Call)));
10675 Analyze_And_Resolve (Exp, Entity (Elem_Typ));
10679 end Is_Container_Element;
10681 ----------------------------
10682 -- Is_Contract_Annotation --
10683 ----------------------------
10685 function Is_Contract_Annotation (Item : Node_Id) return Boolean is
10687 return Is_Package_Contract_Annotation (Item)
10689 Is_Subprogram_Contract_Annotation (Item);
10690 end Is_Contract_Annotation;
10692 --------------------------------------
10693 -- Is_Controlling_Limited_Procedure --
10694 --------------------------------------
10696 function Is_Controlling_Limited_Procedure
10697 (Proc_Nam : Entity_Id) return Boolean
10699 Param_Typ : Entity_Id := Empty;
10702 if Ekind (Proc_Nam) = E_Procedure
10703 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
10705 Param_Typ := Etype (Parameter_Type (First (
10706 Parameter_Specifications (Parent (Proc_Nam)))));
10708 -- In this case where an Itype was created, the procedure call has been
10711 elsif Present (Associated_Node_For_Itype (Proc_Nam))
10712 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
10714 Present (Parameter_Associations
10715 (Associated_Node_For_Itype (Proc_Nam)))
10718 Etype (First (Parameter_Associations
10719 (Associated_Node_For_Itype (Proc_Nam))));
10722 if Present (Param_Typ) then
10724 Is_Interface (Param_Typ)
10725 and then Is_Limited_Record (Param_Typ);
10729 end Is_Controlling_Limited_Procedure;
10731 -----------------------------
10732 -- Is_CPP_Constructor_Call --
10733 -----------------------------
10735 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
10737 return Nkind (N) = N_Function_Call
10738 and then Is_CPP_Class (Etype (Etype (N)))
10739 and then Is_Constructor (Entity (Name (N)))
10740 and then Is_Imported (Entity (Name (N)));
10741 end Is_CPP_Constructor_Call;
10743 --------------------
10744 -- Is_Declaration --
10745 --------------------
10747 function Is_Declaration (N : Node_Id) return Boolean is
10750 when N_Abstract_Subprogram_Declaration |
10751 N_Exception_Declaration |
10752 N_Exception_Renaming_Declaration |
10753 N_Full_Type_Declaration |
10754 N_Generic_Function_Renaming_Declaration |
10755 N_Generic_Package_Declaration |
10756 N_Generic_Package_Renaming_Declaration |
10757 N_Generic_Procedure_Renaming_Declaration |
10758 N_Generic_Subprogram_Declaration |
10759 N_Number_Declaration |
10760 N_Object_Declaration |
10761 N_Object_Renaming_Declaration |
10762 N_Package_Declaration |
10763 N_Package_Renaming_Declaration |
10764 N_Private_Extension_Declaration |
10765 N_Private_Type_Declaration |
10766 N_Subprogram_Declaration |
10767 N_Subprogram_Renaming_Declaration |
10768 N_Subtype_Declaration =>
10774 end Is_Declaration;
10780 function Is_Delegate (T : Entity_Id) return Boolean is
10781 Desig_Type : Entity_Id;
10784 if VM_Target /= CLI_Target then
10788 -- Access-to-subprograms are delegates in CIL
10790 if Ekind (T) = E_Access_Subprogram_Type then
10794 if not Is_Access_Type (T) then
10796 -- A delegate is a managed pointer. If no designated type is defined
10797 -- it means that it's not a delegate.
10802 Desig_Type := Etype (Directly_Designated_Type (T));
10804 if not Is_Tagged_Type (Desig_Type) then
10808 -- Test if the type is inherited from [mscorlib]System.Delegate
10810 while Etype (Desig_Type) /= Desig_Type loop
10811 if Chars (Scope (Desig_Type)) /= No_Name
10812 and then Is_Imported (Scope (Desig_Type))
10813 and then Get_Name_String (Chars (Scope (Desig_Type))) = "delegate"
10818 Desig_Type := Etype (Desig_Type);
10824 ----------------------------------------------
10825 -- Is_Dependent_Component_Of_Mutable_Object --
10826 ----------------------------------------------
10828 function Is_Dependent_Component_Of_Mutable_Object
10829 (Object : Node_Id) return Boolean
10831 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
10832 -- Returns True if and only if Comp is declared within a variant part
10834 --------------------------------
10835 -- Is_Declared_Within_Variant --
10836 --------------------------------
10838 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
10839 Comp_Decl : constant Node_Id := Parent (Comp);
10840 Comp_List : constant Node_Id := Parent (Comp_Decl);
10842 return Nkind (Parent (Comp_List)) = N_Variant;
10843 end Is_Declared_Within_Variant;
10846 Prefix_Type : Entity_Id;
10847 P_Aliased : Boolean := False;
10850 Deref : Node_Id := Object;
10851 -- Dereference node, in something like X.all.Y(2)
10853 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
10856 -- Find the dereference node if any
10858 while Nkind_In (Deref, N_Indexed_Component,
10859 N_Selected_Component,
10862 Deref := Prefix (Deref);
10865 -- Ada 2005: If we have a component or slice of a dereference,
10866 -- something like X.all.Y (2), and the type of X is access-to-constant,
10867 -- Is_Variable will return False, because it is indeed a constant
10868 -- view. But it might be a view of a variable object, so we want the
10869 -- following condition to be True in that case.
10871 if Is_Variable (Object)
10872 or else (Ada_Version >= Ada_2005
10873 and then Nkind (Deref) = N_Explicit_Dereference)
10875 if Nkind (Object) = N_Selected_Component then
10876 P := Prefix (Object);
10877 Prefix_Type := Etype (P);
10879 if Is_Entity_Name (P) then
10880 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
10881 Prefix_Type := Base_Type (Prefix_Type);
10884 if Is_Aliased (Entity (P)) then
10888 -- A discriminant check on a selected component may be expanded
10889 -- into a dereference when removing side-effects. Recover the
10890 -- original node and its type, which may be unconstrained.
10892 elsif Nkind (P) = N_Explicit_Dereference
10893 and then not (Comes_From_Source (P))
10895 P := Original_Node (P);
10896 Prefix_Type := Etype (P);
10899 -- Check for prefix being an aliased component???
10905 -- A heap object is constrained by its initial value
10907 -- Ada 2005 (AI-363): Always assume the object could be mutable in
10908 -- the dereferenced case, since the access value might denote an
10909 -- unconstrained aliased object, whereas in Ada 95 the designated
10910 -- object is guaranteed to be constrained. A worst-case assumption
10911 -- has to apply in Ada 2005 because we can't tell at compile
10912 -- time whether the object is "constrained by its initial value"
10913 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
10914 -- rules (these rules are acknowledged to need fixing).
10916 if Ada_Version < Ada_2005 then
10917 if Is_Access_Type (Prefix_Type)
10918 or else Nkind (P) = N_Explicit_Dereference
10923 else pragma Assert (Ada_Version >= Ada_2005);
10924 if Is_Access_Type (Prefix_Type) then
10926 -- If the access type is pool-specific, and there is no
10927 -- constrained partial view of the designated type, then the
10928 -- designated object is known to be constrained.
10930 if Ekind (Prefix_Type) = E_Access_Type
10931 and then not Object_Type_Has_Constrained_Partial_View
10932 (Typ => Designated_Type (Prefix_Type),
10933 Scop => Current_Scope)
10937 -- Otherwise (general access type, or there is a constrained
10938 -- partial view of the designated type), we need to check
10939 -- based on the designated type.
10942 Prefix_Type := Designated_Type (Prefix_Type);
10948 Original_Record_Component (Entity (Selector_Name (Object)));
10950 -- As per AI-0017, the renaming is illegal in a generic body, even
10951 -- if the subtype is indefinite.
10953 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
10955 if not Is_Constrained (Prefix_Type)
10956 and then (not Is_Indefinite_Subtype (Prefix_Type)
10958 (Is_Generic_Type (Prefix_Type)
10959 and then Ekind (Current_Scope) = E_Generic_Package
10960 and then In_Package_Body (Current_Scope)))
10962 and then (Is_Declared_Within_Variant (Comp)
10963 or else Has_Discriminant_Dependent_Constraint (Comp))
10964 and then (not P_Aliased or else Ada_Version >= Ada_2005)
10968 -- If the prefix is of an access type at this point, then we want
10969 -- to return False, rather than calling this function recursively
10970 -- on the access object (which itself might be a discriminant-
10971 -- dependent component of some other object, but that isn't
10972 -- relevant to checking the object passed to us). This avoids
10973 -- issuing wrong errors when compiling with -gnatc, where there
10974 -- can be implicit dereferences that have not been expanded.
10976 elsif Is_Access_Type (Etype (Prefix (Object))) then
10981 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
10984 elsif Nkind (Object) = N_Indexed_Component
10985 or else Nkind (Object) = N_Slice
10987 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
10989 -- A type conversion that Is_Variable is a view conversion:
10990 -- go back to the denoted object.
10992 elsif Nkind (Object) = N_Type_Conversion then
10994 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
10999 end Is_Dependent_Component_Of_Mutable_Object;
11001 ---------------------
11002 -- Is_Dereferenced --
11003 ---------------------
11005 function Is_Dereferenced (N : Node_Id) return Boolean is
11006 P : constant Node_Id := Parent (N);
11008 return Nkind_In (P, N_Selected_Component,
11009 N_Explicit_Dereference,
11010 N_Indexed_Component,
11012 and then Prefix (P) = N;
11013 end Is_Dereferenced;
11015 ----------------------
11016 -- Is_Descendent_Of --
11017 ----------------------
11019 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
11024 pragma Assert (Nkind (T1) in N_Entity);
11025 pragma Assert (Nkind (T2) in N_Entity);
11027 T := Base_Type (T1);
11029 -- Immediate return if the types match
11034 -- Comment needed here ???
11036 elsif Ekind (T) = E_Class_Wide_Type then
11037 return Etype (T) = T2;
11045 -- Done if we found the type we are looking for
11050 -- Done if no more derivations to check
11057 -- Following test catches error cases resulting from prev errors
11059 elsif No (Etyp) then
11062 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
11065 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
11069 T := Base_Type (Etyp);
11072 end Is_Descendent_Of;
11074 -----------------------------
11075 -- Is_Effectively_Volatile --
11076 -----------------------------
11078 function Is_Effectively_Volatile (Id : Entity_Id) return Boolean is
11080 if Is_Type (Id) then
11082 -- An arbitrary type is effectively volatile when it is subject to
11083 -- pragma Atomic or Volatile.
11085 if Is_Volatile (Id) then
11088 -- An array type is effectively volatile when it is subject to pragma
11089 -- Atomic_Components or Volatile_Components or its compolent type is
11090 -- effectively volatile.
11092 elsif Is_Array_Type (Id) then
11094 Has_Volatile_Components (Id)
11096 Is_Effectively_Volatile (Component_Type (Base_Type (Id)));
11102 -- Otherwise Id denotes an object
11107 or else Has_Volatile_Components (Id)
11108 or else Is_Effectively_Volatile (Etype (Id));
11110 end Is_Effectively_Volatile;
11112 ------------------------------------
11113 -- Is_Effectively_Volatile_Object --
11114 ------------------------------------
11116 function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean is
11118 if Is_Entity_Name (N) then
11119 return Is_Effectively_Volatile (Entity (N));
11121 elsif Nkind (N) = N_Expanded_Name then
11122 return Is_Effectively_Volatile (Entity (N));
11124 elsif Nkind (N) = N_Indexed_Component then
11125 return Is_Effectively_Volatile_Object (Prefix (N));
11127 elsif Nkind (N) = N_Selected_Component then
11129 Is_Effectively_Volatile_Object (Prefix (N))
11131 Is_Effectively_Volatile_Object (Selector_Name (N));
11136 end Is_Effectively_Volatile_Object;
11138 ----------------------------
11139 -- Is_Expression_Function --
11140 ----------------------------
11142 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
11146 if Ekind (Subp) /= E_Function then
11150 Decl := Unit_Declaration_Node (Subp);
11151 return Nkind (Decl) = N_Subprogram_Declaration
11153 (Nkind (Original_Node (Decl)) = N_Expression_Function
11155 (Present (Corresponding_Body (Decl))
11157 Nkind (Original_Node
11158 (Unit_Declaration_Node
11159 (Corresponding_Body (Decl)))) =
11160 N_Expression_Function));
11162 end Is_Expression_Function;
11164 -----------------------
11165 -- Is_EVF_Expression --
11166 -----------------------
11168 function Is_EVF_Expression (N : Node_Id) return Boolean is
11169 Orig_N : constant Node_Id := Original_Node (N);
11175 -- Detect a reference to a formal parameter of a specific tagged type
11176 -- whose related subprogram is subject to pragma Expresions_Visible with
11179 if Is_Entity_Name (N) and then Present (Entity (N)) then
11184 and then Is_Specific_Tagged_Type (Etype (Id))
11185 and then Extensions_Visible_Status (Id) =
11186 Extensions_Visible_False;
11188 -- A case expression is an EVF expression when it contains at least one
11189 -- EVF dependent_expression. Note that a case expression may have been
11190 -- expanded, hence the use of Original_Node.
11192 elsif Nkind (Orig_N) = N_Case_Expression then
11193 Alt := First (Alternatives (Orig_N));
11194 while Present (Alt) loop
11195 if Is_EVF_Expression (Expression (Alt)) then
11202 -- An if expression is an EVF expression when it contains at least one
11203 -- EVF dependent_expression. Note that an if expression may have been
11204 -- expanded, hence the use of Original_Node.
11206 elsif Nkind (Orig_N) = N_If_Expression then
11207 Expr := Next (First (Expressions (Orig_N)));
11208 while Present (Expr) loop
11209 if Is_EVF_Expression (Expr) then
11216 -- A qualified expression or a type conversion is an EVF expression when
11217 -- its operand is an EVF expression.
11219 elsif Nkind_In (N, N_Qualified_Expression,
11220 N_Unchecked_Type_Conversion,
11223 return Is_EVF_Expression (Expression (N));
11225 -- Attributes 'Loop_Entry, 'Old and 'Update are an EVF expression when
11226 -- their prefix denotes an EVF expression.
11228 elsif Nkind (N) = N_Attribute_Reference
11229 and then Nam_In (Attribute_Name (N), Name_Loop_Entry,
11233 return Is_EVF_Expression (Prefix (N));
11237 end Is_EVF_Expression;
11243 function Is_False (U : Uint) return Boolean is
11248 ---------------------------
11249 -- Is_Fixed_Model_Number --
11250 ---------------------------
11252 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
11253 S : constant Ureal := Small_Value (T);
11254 M : Urealp.Save_Mark;
11258 R := (U = UR_Trunc (U / S) * S);
11259 Urealp.Release (M);
11261 end Is_Fixed_Model_Number;
11263 -------------------------------
11264 -- Is_Fully_Initialized_Type --
11265 -------------------------------
11267 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
11271 if Is_Scalar_Type (Typ) then
11273 -- A scalar type with an aspect Default_Value is fully initialized
11275 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
11276 -- of a scalar type, but we don't take that into account here, since
11277 -- we don't want these to affect warnings.
11279 return Has_Default_Aspect (Typ);
11281 elsif Is_Access_Type (Typ) then
11284 elsif Is_Array_Type (Typ) then
11285 if Is_Fully_Initialized_Type (Component_Type (Typ))
11286 or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
11291 -- An interesting case, if we have a constrained type one of whose
11292 -- bounds is known to be null, then there are no elements to be
11293 -- initialized, so all the elements are initialized.
11295 if Is_Constrained (Typ) then
11298 Indx_Typ : Entity_Id;
11299 Lbd, Hbd : Node_Id;
11302 Indx := First_Index (Typ);
11303 while Present (Indx) loop
11304 if Etype (Indx) = Any_Type then
11307 -- If index is a range, use directly
11309 elsif Nkind (Indx) = N_Range then
11310 Lbd := Low_Bound (Indx);
11311 Hbd := High_Bound (Indx);
11314 Indx_Typ := Etype (Indx);
11316 if Is_Private_Type (Indx_Typ) then
11317 Indx_Typ := Full_View (Indx_Typ);
11320 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
11323 Lbd := Type_Low_Bound (Indx_Typ);
11324 Hbd := Type_High_Bound (Indx_Typ);
11328 if Compile_Time_Known_Value (Lbd)
11330 Compile_Time_Known_Value (Hbd)
11332 if Expr_Value (Hbd) < Expr_Value (Lbd) then
11342 -- If no null indexes, then type is not fully initialized
11348 elsif Is_Record_Type (Typ) then
11349 if Has_Discriminants (Typ)
11351 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
11352 and then Is_Fully_Initialized_Variant (Typ)
11357 -- We consider bounded string types to be fully initialized, because
11358 -- otherwise we get false alarms when the Data component is not
11359 -- default-initialized.
11361 if Is_Bounded_String (Typ) then
11365 -- Controlled records are considered to be fully initialized if
11366 -- there is a user defined Initialize routine. This may not be
11367 -- entirely correct, but as the spec notes, we are guessing here
11368 -- what is best from the point of view of issuing warnings.
11370 if Is_Controlled (Typ) then
11372 Utyp : constant Entity_Id := Underlying_Type (Typ);
11375 if Present (Utyp) then
11377 Init : constant Entity_Id :=
11379 (Underlying_Type (Typ), Name_Initialize));
11383 and then Comes_From_Source (Init)
11385 Is_Predefined_File_Name
11386 (File_Name (Get_Source_File_Index (Sloc (Init))))
11390 elsif Has_Null_Extension (Typ)
11392 Is_Fully_Initialized_Type
11393 (Etype (Base_Type (Typ)))
11402 -- Otherwise see if all record components are initialized
11408 Ent := First_Entity (Typ);
11409 while Present (Ent) loop
11410 if Ekind (Ent) = E_Component
11411 and then (No (Parent (Ent))
11412 or else No (Expression (Parent (Ent))))
11413 and then not Is_Fully_Initialized_Type (Etype (Ent))
11415 -- Special VM case for tag components, which need to be
11416 -- defined in this case, but are never initialized as VMs
11417 -- are using other dispatching mechanisms. Ignore this
11418 -- uninitialized case. Note that this applies both to the
11419 -- uTag entry and the main vtable pointer (CPP_Class case).
11421 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
11430 -- No uninitialized components, so type is fully initialized.
11431 -- Note that this catches the case of no components as well.
11435 elsif Is_Concurrent_Type (Typ) then
11438 elsif Is_Private_Type (Typ) then
11440 U : constant Entity_Id := Underlying_Type (Typ);
11446 return Is_Fully_Initialized_Type (U);
11453 end Is_Fully_Initialized_Type;
11455 ----------------------------------
11456 -- Is_Fully_Initialized_Variant --
11457 ----------------------------------
11459 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
11460 Loc : constant Source_Ptr := Sloc (Typ);
11461 Constraints : constant List_Id := New_List;
11462 Components : constant Elist_Id := New_Elmt_List;
11463 Comp_Elmt : Elmt_Id;
11465 Comp_List : Node_Id;
11467 Discr_Val : Node_Id;
11469 Report_Errors : Boolean;
11470 pragma Warnings (Off, Report_Errors);
11473 if Serious_Errors_Detected > 0 then
11477 if Is_Record_Type (Typ)
11478 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
11479 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
11481 Comp_List := Component_List (Type_Definition (Parent (Typ)));
11483 Discr := First_Discriminant (Typ);
11484 while Present (Discr) loop
11485 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
11486 Discr_Val := Expression (Parent (Discr));
11488 if Present (Discr_Val)
11489 and then Is_OK_Static_Expression (Discr_Val)
11491 Append_To (Constraints,
11492 Make_Component_Association (Loc,
11493 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
11494 Expression => New_Copy (Discr_Val)));
11502 Next_Discriminant (Discr);
11507 Comp_List => Comp_List,
11508 Governed_By => Constraints,
11509 Into => Components,
11510 Report_Errors => Report_Errors);
11512 -- Check that each component present is fully initialized
11514 Comp_Elmt := First_Elmt (Components);
11515 while Present (Comp_Elmt) loop
11516 Comp_Id := Node (Comp_Elmt);
11518 if Ekind (Comp_Id) = E_Component
11519 and then (No (Parent (Comp_Id))
11520 or else No (Expression (Parent (Comp_Id))))
11521 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
11526 Next_Elmt (Comp_Elmt);
11531 elsif Is_Private_Type (Typ) then
11533 U : constant Entity_Id := Underlying_Type (Typ);
11539 return Is_Fully_Initialized_Variant (U);
11546 end Is_Fully_Initialized_Variant;
11548 ------------------------------------
11549 -- Is_Generic_Declaration_Or_Body --
11550 ------------------------------------
11552 function Is_Generic_Declaration_Or_Body (Decl : Node_Id) return Boolean is
11553 Spec_Decl : Node_Id;
11556 -- Package/subprogram body
11558 if Nkind_In (Decl, N_Package_Body, N_Subprogram_Body)
11559 and then Present (Corresponding_Spec (Decl))
11561 Spec_Decl := Unit_Declaration_Node (Corresponding_Spec (Decl));
11563 -- Package/subprogram body stub
11565 elsif Nkind_In (Decl, N_Package_Body_Stub, N_Subprogram_Body_Stub)
11566 and then Present (Corresponding_Spec_Of_Stub (Decl))
11569 Unit_Declaration_Node (Corresponding_Spec_Of_Stub (Decl));
11577 -- Rather than inspecting the defining entity of the spec declaration,
11578 -- look at its Nkind. This takes care of the case where the analysis of
11579 -- a generic body modifies the Ekind of its spec to allow for recursive
11583 Nkind_In (Spec_Decl, N_Generic_Package_Declaration,
11584 N_Generic_Subprogram_Declaration);
11585 end Is_Generic_Declaration_Or_Body;
11587 ----------------------------
11588 -- Is_Inherited_Operation --
11589 ----------------------------
11591 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
11592 pragma Assert (Is_Overloadable (E));
11593 Kind : constant Node_Kind := Nkind (Parent (E));
11595 return Kind = N_Full_Type_Declaration
11596 or else Kind = N_Private_Extension_Declaration
11597 or else Kind = N_Subtype_Declaration
11598 or else (Ekind (E) = E_Enumeration_Literal
11599 and then Is_Derived_Type (Etype (E)));
11600 end Is_Inherited_Operation;
11602 -------------------------------------
11603 -- Is_Inherited_Operation_For_Type --
11604 -------------------------------------
11606 function Is_Inherited_Operation_For_Type
11608 Typ : Entity_Id) return Boolean
11611 -- Check that the operation has been created by the type declaration
11613 return Is_Inherited_Operation (E)
11614 and then Defining_Identifier (Parent (E)) = Typ;
11615 end Is_Inherited_Operation_For_Type;
11621 function Is_Iterator (Typ : Entity_Id) return Boolean is
11622 Ifaces_List : Elist_Id;
11623 Iface_Elmt : Elmt_Id;
11627 if Is_Class_Wide_Type (Typ)
11628 and then Nam_In (Chars (Etype (Typ)), Name_Forward_Iterator,
11629 Name_Reversible_Iterator)
11631 Is_Predefined_File_Name
11632 (Unit_File_Name (Get_Source_Unit (Etype (Typ))))
11636 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
11639 elsif Present (Find_Value_Of_Aspect (Typ, Aspect_Iterable)) then
11643 Collect_Interfaces (Typ, Ifaces_List);
11645 Iface_Elmt := First_Elmt (Ifaces_List);
11646 while Present (Iface_Elmt) loop
11647 Iface := Node (Iface_Elmt);
11648 if Chars (Iface) = Name_Forward_Iterator
11650 Is_Predefined_File_Name
11651 (Unit_File_Name (Get_Source_Unit (Iface)))
11656 Next_Elmt (Iface_Elmt);
11667 -- We seem to have a lot of overlapping functions that do similar things
11668 -- (testing for left hand sides or lvalues???).
11670 function Is_LHS (N : Node_Id) return Is_LHS_Result is
11671 P : constant Node_Id := Parent (N);
11674 -- Return True if we are the left hand side of an assignment statement
11676 if Nkind (P) = N_Assignment_Statement then
11677 if Name (P) = N then
11683 -- Case of prefix of indexed or selected component or slice
11685 elsif Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
11686 and then N = Prefix (P)
11688 -- Here we have the case where the parent P is N.Q or N(Q .. R).
11689 -- If P is an LHS, then N is also effectively an LHS, but there
11690 -- is an important exception. If N is of an access type, then
11691 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
11692 -- case this makes N.all a left hand side but not N itself.
11694 -- If we don't know the type yet, this is the case where we return
11695 -- Unknown, since the answer depends on the type which is unknown.
11697 if No (Etype (N)) then
11700 -- We have an Etype set, so we can check it
11702 elsif Is_Access_Type (Etype (N)) then
11705 -- OK, not access type case, so just test whole expression
11711 -- All other cases are not left hand sides
11718 -----------------------------
11719 -- Is_Library_Level_Entity --
11720 -----------------------------
11722 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
11724 -- The following is a small optimization, and it also properly handles
11725 -- discriminals, which in task bodies might appear in expressions before
11726 -- the corresponding procedure has been created, and which therefore do
11727 -- not have an assigned scope.
11729 if Is_Formal (E) then
11733 -- Normal test is simply that the enclosing dynamic scope is Standard
11735 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
11736 end Is_Library_Level_Entity;
11738 --------------------------------
11739 -- Is_Limited_Class_Wide_Type --
11740 --------------------------------
11742 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
11745 Is_Class_Wide_Type (Typ)
11746 and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
11747 end Is_Limited_Class_Wide_Type;
11749 ---------------------------------
11750 -- Is_Local_Variable_Reference --
11751 ---------------------------------
11753 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
11755 if not Is_Entity_Name (Expr) then
11760 Ent : constant Entity_Id := Entity (Expr);
11761 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
11763 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
11766 return Present (Sub) and then Sub = Current_Subprogram;
11770 end Is_Local_Variable_Reference;
11772 -------------------------
11773 -- Is_Object_Reference --
11774 -------------------------
11776 function Is_Object_Reference (N : Node_Id) return Boolean is
11778 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean;
11779 -- Determine whether N is the name of an internally-generated renaming
11781 --------------------------------------
11782 -- Is_Internally_Generated_Renaming --
11783 --------------------------------------
11785 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean is
11790 while Present (P) loop
11791 if Nkind (P) = N_Object_Renaming_Declaration then
11792 return not Comes_From_Source (P);
11793 elsif Is_List_Member (P) then
11801 end Is_Internally_Generated_Renaming;
11803 -- Start of processing for Is_Object_Reference
11806 if Is_Entity_Name (N) then
11807 return Present (Entity (N)) and then Is_Object (Entity (N));
11811 when N_Indexed_Component | N_Slice =>
11813 Is_Object_Reference (Prefix (N))
11814 or else Is_Access_Type (Etype (Prefix (N)));
11816 -- In Ada 95, a function call is a constant object; a procedure
11819 when N_Function_Call =>
11820 return Etype (N) /= Standard_Void_Type;
11822 -- Attributes 'Input, 'Old and 'Result produce objects
11824 when N_Attribute_Reference =>
11827 (Attribute_Name (N), Name_Input, Name_Old, Name_Result);
11829 when N_Selected_Component =>
11831 Is_Object_Reference (Selector_Name (N))
11833 (Is_Object_Reference (Prefix (N))
11834 or else Is_Access_Type (Etype (Prefix (N))));
11836 when N_Explicit_Dereference =>
11839 -- A view conversion of a tagged object is an object reference
11841 when N_Type_Conversion =>
11842 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
11843 and then Is_Tagged_Type (Etype (Expression (N)))
11844 and then Is_Object_Reference (Expression (N));
11846 -- An unchecked type conversion is considered to be an object if
11847 -- the operand is an object (this construction arises only as a
11848 -- result of expansion activities).
11850 when N_Unchecked_Type_Conversion =>
11853 -- Allow string literals to act as objects as long as they appear
11854 -- in internally-generated renamings. The expansion of iterators
11855 -- may generate such renamings when the range involves a string
11858 when N_String_Literal =>
11859 return Is_Internally_Generated_Renaming (Parent (N));
11861 -- AI05-0003: In Ada 2012 a qualified expression is a name.
11862 -- This allows disambiguation of function calls and the use
11863 -- of aggregates in more contexts.
11865 when N_Qualified_Expression =>
11866 if Ada_Version < Ada_2012 then
11869 return Is_Object_Reference (Expression (N))
11870 or else Nkind (Expression (N)) = N_Aggregate;
11877 end Is_Object_Reference;
11879 -----------------------------------
11880 -- Is_OK_Variable_For_Out_Formal --
11881 -----------------------------------
11883 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
11885 Note_Possible_Modification (AV, Sure => True);
11887 -- We must reject parenthesized variable names. Comes_From_Source is
11888 -- checked because there are currently cases where the compiler violates
11889 -- this rule (e.g. passing a task object to its controlled Initialize
11890 -- routine). This should be properly documented in sinfo???
11892 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
11895 -- A variable is always allowed
11897 elsif Is_Variable (AV) then
11900 -- Generalized indexing operations are rewritten as explicit
11901 -- dereferences, and it is only during resolution that we can
11902 -- check whether the context requires an access_to_variable type.
11904 elsif Nkind (AV) = N_Explicit_Dereference
11905 and then Ada_Version >= Ada_2012
11906 and then Nkind (Original_Node (AV)) = N_Indexed_Component
11907 and then Present (Etype (Original_Node (AV)))
11908 and then Has_Implicit_Dereference (Etype (Original_Node (AV)))
11910 return not Is_Access_Constant (Etype (Prefix (AV)));
11912 -- Unchecked conversions are allowed only if they come from the
11913 -- generated code, which sometimes uses unchecked conversions for out
11914 -- parameters in cases where code generation is unaffected. We tell
11915 -- source unchecked conversions by seeing if they are rewrites of
11916 -- an original Unchecked_Conversion function call, or of an explicit
11917 -- conversion of a function call or an aggregate (as may happen in the
11918 -- expansion of a packed array aggregate).
11920 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
11921 if Nkind_In (Original_Node (AV), N_Function_Call, N_Aggregate) then
11924 elsif Comes_From_Source (AV)
11925 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
11929 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
11930 return Is_OK_Variable_For_Out_Formal (Expression (AV));
11936 -- Normal type conversions are allowed if argument is a variable
11938 elsif Nkind (AV) = N_Type_Conversion then
11939 if Is_Variable (Expression (AV))
11940 and then Paren_Count (Expression (AV)) = 0
11942 Note_Possible_Modification (Expression (AV), Sure => True);
11945 -- We also allow a non-parenthesized expression that raises
11946 -- constraint error if it rewrites what used to be a variable
11948 elsif Raises_Constraint_Error (Expression (AV))
11949 and then Paren_Count (Expression (AV)) = 0
11950 and then Is_Variable (Original_Node (Expression (AV)))
11954 -- Type conversion of something other than a variable
11960 -- If this node is rewritten, then test the original form, if that is
11961 -- OK, then we consider the rewritten node OK (for example, if the
11962 -- original node is a conversion, then Is_Variable will not be true
11963 -- but we still want to allow the conversion if it converts a variable).
11965 elsif Original_Node (AV) /= AV then
11967 -- In Ada 2012, the explicit dereference may be a rewritten call to a
11968 -- Reference function.
11970 if Ada_Version >= Ada_2012
11971 and then Nkind (Original_Node (AV)) = N_Function_Call
11973 Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
11978 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
11981 -- All other non-variables are rejected
11986 end Is_OK_Variable_For_Out_Formal;
11988 ------------------------------------
11989 -- Is_Package_Contract_Annotation --
11990 ------------------------------------
11992 function Is_Package_Contract_Annotation (Item : Node_Id) return Boolean is
11996 if Nkind (Item) = N_Aspect_Specification then
11997 Nam := Chars (Identifier (Item));
11999 else pragma Assert (Nkind (Item) = N_Pragma);
12000 Nam := Pragma_Name (Item);
12003 return Nam = Name_Abstract_State
12004 or else Nam = Name_Initial_Condition
12005 or else Nam = Name_Initializes
12006 or else Nam = Name_Refined_State;
12007 end Is_Package_Contract_Annotation;
12009 -----------------------------------
12010 -- Is_Partially_Initialized_Type --
12011 -----------------------------------
12013 function Is_Partially_Initialized_Type
12015 Include_Implicit : Boolean := True) return Boolean
12018 if Is_Scalar_Type (Typ) then
12021 elsif Is_Access_Type (Typ) then
12022 return Include_Implicit;
12024 elsif Is_Array_Type (Typ) then
12026 -- If component type is partially initialized, so is array type
12028 if Is_Partially_Initialized_Type
12029 (Component_Type (Typ), Include_Implicit)
12033 -- Otherwise we are only partially initialized if we are fully
12034 -- initialized (this is the empty array case, no point in us
12035 -- duplicating that code here).
12038 return Is_Fully_Initialized_Type (Typ);
12041 elsif Is_Record_Type (Typ) then
12043 -- A discriminated type is always partially initialized if in
12046 if Has_Discriminants (Typ) and then Include_Implicit then
12049 -- A tagged type is always partially initialized
12051 elsif Is_Tagged_Type (Typ) then
12054 -- Case of non-discriminated record
12060 Component_Present : Boolean := False;
12061 -- Set True if at least one component is present. If no
12062 -- components are present, then record type is fully
12063 -- initialized (another odd case, like the null array).
12066 -- Loop through components
12068 Ent := First_Entity (Typ);
12069 while Present (Ent) loop
12070 if Ekind (Ent) = E_Component then
12071 Component_Present := True;
12073 -- If a component has an initialization expression then
12074 -- the enclosing record type is partially initialized
12076 if Present (Parent (Ent))
12077 and then Present (Expression (Parent (Ent)))
12081 -- If a component is of a type which is itself partially
12082 -- initialized, then the enclosing record type is also.
12084 elsif Is_Partially_Initialized_Type
12085 (Etype (Ent), Include_Implicit)
12094 -- No initialized components found. If we found any components
12095 -- they were all uninitialized so the result is false.
12097 if Component_Present then
12100 -- But if we found no components, then all the components are
12101 -- initialized so we consider the type to be initialized.
12109 -- Concurrent types are always fully initialized
12111 elsif Is_Concurrent_Type (Typ) then
12114 -- For a private type, go to underlying type. If there is no underlying
12115 -- type then just assume this partially initialized. Not clear if this
12116 -- can happen in a non-error case, but no harm in testing for this.
12118 elsif Is_Private_Type (Typ) then
12120 U : constant Entity_Id := Underlying_Type (Typ);
12125 return Is_Partially_Initialized_Type (U, Include_Implicit);
12129 -- For any other type (are there any?) assume partially initialized
12134 end Is_Partially_Initialized_Type;
12136 ------------------------------------
12137 -- Is_Potentially_Persistent_Type --
12138 ------------------------------------
12140 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
12145 -- For private type, test corresponding full type
12147 if Is_Private_Type (T) then
12148 return Is_Potentially_Persistent_Type (Full_View (T));
12150 -- Scalar types are potentially persistent
12152 elsif Is_Scalar_Type (T) then
12155 -- Record type is potentially persistent if not tagged and the types of
12156 -- all it components are potentially persistent, and no component has
12157 -- an initialization expression.
12159 elsif Is_Record_Type (T)
12160 and then not Is_Tagged_Type (T)
12161 and then not Is_Partially_Initialized_Type (T)
12163 Comp := First_Component (T);
12164 while Present (Comp) loop
12165 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
12168 Next_Entity (Comp);
12174 -- Array type is potentially persistent if its component type is
12175 -- potentially persistent and if all its constraints are static.
12177 elsif Is_Array_Type (T) then
12178 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
12182 Indx := First_Index (T);
12183 while Present (Indx) loop
12184 if not Is_OK_Static_Subtype (Etype (Indx)) then
12193 -- All other types are not potentially persistent
12198 end Is_Potentially_Persistent_Type;
12200 --------------------------------
12201 -- Is_Potentially_Unevaluated --
12202 --------------------------------
12204 function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is
12212 -- A postcondition whose expression is a short-circuit is broken down
12213 -- into individual aspects for better exception reporting. The original
12214 -- short-circuit expression is rewritten as the second operand, and an
12215 -- occurrence of 'Old in that operand is potentially unevaluated.
12216 -- See Sem_ch13.adb for details of this transformation.
12218 if Nkind (Original_Node (Par)) = N_And_Then then
12222 while not Nkind_In (Par, N_If_Expression,
12230 Par := Parent (Par);
12232 -- If the context is not an expression, or if is the result of
12233 -- expansion of an enclosing construct (such as another attribute)
12234 -- the predicate does not apply.
12236 if Nkind (Par) not in N_Subexpr
12237 or else not Comes_From_Source (Par)
12243 if Nkind (Par) = N_If_Expression then
12244 return Is_Elsif (Par) or else Expr /= First (Expressions (Par));
12246 elsif Nkind (Par) = N_Case_Expression then
12247 return Expr /= Expression (Par);
12249 elsif Nkind_In (Par, N_And_Then, N_Or_Else) then
12250 return Expr = Right_Opnd (Par);
12252 elsif Nkind_In (Par, N_In, N_Not_In) then
12253 return Expr /= Left_Opnd (Par);
12258 end Is_Potentially_Unevaluated;
12260 ---------------------------------
12261 -- Is_Protected_Self_Reference --
12262 ---------------------------------
12264 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
12266 function In_Access_Definition (N : Node_Id) return Boolean;
12267 -- Returns true if N belongs to an access definition
12269 --------------------------
12270 -- In_Access_Definition --
12271 --------------------------
12273 function In_Access_Definition (N : Node_Id) return Boolean is
12278 while Present (P) loop
12279 if Nkind (P) = N_Access_Definition then
12287 end In_Access_Definition;
12289 -- Start of processing for Is_Protected_Self_Reference
12292 -- Verify that prefix is analyzed and has the proper form. Note that
12293 -- the attributes Elab_Spec, Elab_Body, Elab_Subp_Body and UET_Address,
12294 -- which also produce the address of an entity, do not analyze their
12295 -- prefix because they denote entities that are not necessarily visible.
12296 -- Neither of them can apply to a protected type.
12298 return Ada_Version >= Ada_2005
12299 and then Is_Entity_Name (N)
12300 and then Present (Entity (N))
12301 and then Is_Protected_Type (Entity (N))
12302 and then In_Open_Scopes (Entity (N))
12303 and then not In_Access_Definition (N);
12304 end Is_Protected_Self_Reference;
12306 -----------------------------
12307 -- Is_RCI_Pkg_Spec_Or_Body --
12308 -----------------------------
12310 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
12312 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
12313 -- Return True if the unit of Cunit is an RCI package declaration
12315 ---------------------------
12316 -- Is_RCI_Pkg_Decl_Cunit --
12317 ---------------------------
12319 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
12320 The_Unit : constant Node_Id := Unit (Cunit);
12323 if Nkind (The_Unit) /= N_Package_Declaration then
12327 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
12328 end Is_RCI_Pkg_Decl_Cunit;
12330 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
12333 return Is_RCI_Pkg_Decl_Cunit (Cunit)
12335 (Nkind (Unit (Cunit)) = N_Package_Body
12336 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
12337 end Is_RCI_Pkg_Spec_Or_Body;
12339 -----------------------------------------
12340 -- Is_Remote_Access_To_Class_Wide_Type --
12341 -----------------------------------------
12343 function Is_Remote_Access_To_Class_Wide_Type
12344 (E : Entity_Id) return Boolean
12347 -- A remote access to class-wide type is a general access to object type
12348 -- declared in the visible part of a Remote_Types or Remote_Call_
12351 return Ekind (E) = E_General_Access_Type
12352 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
12353 end Is_Remote_Access_To_Class_Wide_Type;
12355 -----------------------------------------
12356 -- Is_Remote_Access_To_Subprogram_Type --
12357 -----------------------------------------
12359 function Is_Remote_Access_To_Subprogram_Type
12360 (E : Entity_Id) return Boolean
12363 return (Ekind (E) = E_Access_Subprogram_Type
12364 or else (Ekind (E) = E_Record_Type
12365 and then Present (Corresponding_Remote_Type (E))))
12366 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
12367 end Is_Remote_Access_To_Subprogram_Type;
12369 --------------------
12370 -- Is_Remote_Call --
12371 --------------------
12373 function Is_Remote_Call (N : Node_Id) return Boolean is
12375 if Nkind (N) not in N_Subprogram_Call then
12377 -- An entry call cannot be remote
12381 elsif Nkind (Name (N)) in N_Has_Entity
12382 and then Is_Remote_Call_Interface (Entity (Name (N)))
12384 -- A subprogram declared in the spec of a RCI package is remote
12388 elsif Nkind (Name (N)) = N_Explicit_Dereference
12389 and then Is_Remote_Access_To_Subprogram_Type
12390 (Etype (Prefix (Name (N))))
12392 -- The dereference of a RAS is a remote call
12396 elsif Present (Controlling_Argument (N))
12397 and then Is_Remote_Access_To_Class_Wide_Type
12398 (Etype (Controlling_Argument (N)))
12400 -- Any primitive operation call with a controlling argument of
12401 -- a RACW type is a remote call.
12406 -- All other calls are local calls
12409 end Is_Remote_Call;
12411 ----------------------
12412 -- Is_Renamed_Entry --
12413 ----------------------
12415 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
12416 Orig_Node : Node_Id := Empty;
12417 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
12419 function Is_Entry (Nam : Node_Id) return Boolean;
12420 -- Determine whether Nam is an entry. Traverse selectors if there are
12421 -- nested selected components.
12427 function Is_Entry (Nam : Node_Id) return Boolean is
12429 if Nkind (Nam) = N_Selected_Component then
12430 return Is_Entry (Selector_Name (Nam));
12433 return Ekind (Entity (Nam)) = E_Entry;
12436 -- Start of processing for Is_Renamed_Entry
12439 if Present (Alias (Proc_Nam)) then
12440 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
12443 -- Look for a rewritten subprogram renaming declaration
12445 if Nkind (Subp_Decl) = N_Subprogram_Declaration
12446 and then Present (Original_Node (Subp_Decl))
12448 Orig_Node := Original_Node (Subp_Decl);
12451 -- The rewritten subprogram is actually an entry
12453 if Present (Orig_Node)
12454 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
12455 and then Is_Entry (Name (Orig_Node))
12461 end Is_Renamed_Entry;
12463 ----------------------------
12464 -- Is_Reversible_Iterator --
12465 ----------------------------
12467 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
12468 Ifaces_List : Elist_Id;
12469 Iface_Elmt : Elmt_Id;
12473 if Is_Class_Wide_Type (Typ)
12474 and then Chars (Etype (Typ)) = Name_Reversible_Iterator
12475 and then Is_Predefined_File_Name
12476 (Unit_File_Name (Get_Source_Unit (Etype (Typ))))
12480 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
12484 Collect_Interfaces (Typ, Ifaces_List);
12486 Iface_Elmt := First_Elmt (Ifaces_List);
12487 while Present (Iface_Elmt) loop
12488 Iface := Node (Iface_Elmt);
12489 if Chars (Iface) = Name_Reversible_Iterator
12491 Is_Predefined_File_Name
12492 (Unit_File_Name (Get_Source_Unit (Iface)))
12497 Next_Elmt (Iface_Elmt);
12502 end Is_Reversible_Iterator;
12504 ----------------------
12505 -- Is_Selector_Name --
12506 ----------------------
12508 function Is_Selector_Name (N : Node_Id) return Boolean is
12510 if not Is_List_Member (N) then
12512 P : constant Node_Id := Parent (N);
12514 return Nkind_In (P, N_Expanded_Name,
12515 N_Generic_Association,
12516 N_Parameter_Association,
12517 N_Selected_Component)
12518 and then Selector_Name (P) = N;
12523 L : constant List_Id := List_Containing (N);
12524 P : constant Node_Id := Parent (L);
12526 return (Nkind (P) = N_Discriminant_Association
12527 and then Selector_Names (P) = L)
12529 (Nkind (P) = N_Component_Association
12530 and then Choices (P) = L);
12533 end Is_Selector_Name;
12535 -------------------------------------
12536 -- Is_SPARK_05_Initialization_Expr --
12537 -------------------------------------
12539 function Is_SPARK_05_Initialization_Expr (N : Node_Id) return Boolean is
12542 Comp_Assn : Node_Id;
12543 Orig_N : constant Node_Id := Original_Node (N);
12548 if not Comes_From_Source (Orig_N) then
12552 pragma Assert (Nkind (Orig_N) in N_Subexpr);
12554 case Nkind (Orig_N) is
12555 when N_Character_Literal |
12556 N_Integer_Literal |
12558 N_String_Literal =>
12561 when N_Identifier |
12563 if Is_Entity_Name (Orig_N)
12564 and then Present (Entity (Orig_N)) -- needed in some cases
12566 case Ekind (Entity (Orig_N)) is
12568 E_Enumeration_Literal |
12573 if Is_Type (Entity (Orig_N)) then
12581 when N_Qualified_Expression |
12582 N_Type_Conversion =>
12583 Is_Ok := Is_SPARK_05_Initialization_Expr (Expression (Orig_N));
12586 Is_Ok := Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
12590 N_Membership_Test =>
12591 Is_Ok := Is_SPARK_05_Initialization_Expr (Left_Opnd (Orig_N))
12593 Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
12596 N_Extension_Aggregate =>
12597 if Nkind (Orig_N) = N_Extension_Aggregate then
12599 Is_SPARK_05_Initialization_Expr (Ancestor_Part (Orig_N));
12602 Expr := First (Expressions (Orig_N));
12603 while Present (Expr) loop
12604 if not Is_SPARK_05_Initialization_Expr (Expr) then
12612 Comp_Assn := First (Component_Associations (Orig_N));
12613 while Present (Comp_Assn) loop
12614 Expr := Expression (Comp_Assn);
12616 -- Note: test for Present here needed for box assocation
12619 and then not Is_SPARK_05_Initialization_Expr (Expr)
12628 when N_Attribute_Reference =>
12629 if Nkind (Prefix (Orig_N)) in N_Subexpr then
12630 Is_Ok := Is_SPARK_05_Initialization_Expr (Prefix (Orig_N));
12633 Expr := First (Expressions (Orig_N));
12634 while Present (Expr) loop
12635 if not Is_SPARK_05_Initialization_Expr (Expr) then
12643 -- Selected components might be expanded named not yet resolved, so
12644 -- default on the safe side. (Eg on sparklex.ads)
12646 when N_Selected_Component =>
12655 end Is_SPARK_05_Initialization_Expr;
12657 ----------------------------------
12658 -- Is_SPARK_05_Object_Reference --
12659 ----------------------------------
12661 function Is_SPARK_05_Object_Reference (N : Node_Id) return Boolean is
12663 if Is_Entity_Name (N) then
12664 return Present (Entity (N))
12666 (Ekind_In (Entity (N), E_Constant, E_Variable)
12667 or else Ekind (Entity (N)) in Formal_Kind);
12671 when N_Selected_Component =>
12672 return Is_SPARK_05_Object_Reference (Prefix (N));
12678 end Is_SPARK_05_Object_Reference;
12680 -----------------------------
12681 -- Is_Specific_Tagged_Type --
12682 -----------------------------
12684 function Is_Specific_Tagged_Type (Typ : Entity_Id) return Boolean is
12685 Full_Typ : Entity_Id;
12688 -- Handle private types
12690 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
12691 Full_Typ := Full_View (Typ);
12696 -- A specific tagged type is a non-class-wide tagged type
12698 return Is_Tagged_Type (Full_Typ) and not Is_Class_Wide_Type (Full_Typ);
12699 end Is_Specific_Tagged_Type;
12705 function Is_Statement (N : Node_Id) return Boolean is
12708 Nkind (N) in N_Statement_Other_Than_Procedure_Call
12709 or else Nkind (N) = N_Procedure_Call_Statement;
12712 ---------------------------------------
12713 -- Is_Subprogram_Contract_Annotation --
12714 ---------------------------------------
12716 function Is_Subprogram_Contract_Annotation
12717 (Item : Node_Id) return Boolean
12722 if Nkind (Item) = N_Aspect_Specification then
12723 Nam := Chars (Identifier (Item));
12725 else pragma Assert (Nkind (Item) = N_Pragma);
12726 Nam := Pragma_Name (Item);
12729 return Nam = Name_Contract_Cases
12730 or else Nam = Name_Depends
12731 or else Nam = Name_Extensions_Visible
12732 or else Nam = Name_Global
12733 or else Nam = Name_Post
12734 or else Nam = Name_Post_Class
12735 or else Nam = Name_Postcondition
12736 or else Nam = Name_Pre
12737 or else Nam = Name_Pre_Class
12738 or else Nam = Name_Precondition
12739 or else Nam = Name_Refined_Depends
12740 or else Nam = Name_Refined_Global
12741 or else Nam = Name_Refined_Post
12742 or else Nam = Name_Test_Case;
12743 end Is_Subprogram_Contract_Annotation;
12745 --------------------------------------------------
12746 -- Is_Subprogram_Stub_Without_Prior_Declaration --
12747 --------------------------------------------------
12749 function Is_Subprogram_Stub_Without_Prior_Declaration
12750 (N : Node_Id) return Boolean
12753 -- A subprogram stub without prior declaration serves as declaration for
12754 -- the actual subprogram body. As such, it has an attached defining
12755 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
12757 return Nkind (N) = N_Subprogram_Body_Stub
12758 and then Ekind (Defining_Entity (N)) /= E_Subprogram_Body;
12759 end Is_Subprogram_Stub_Without_Prior_Declaration;
12761 ---------------------------------
12762 -- Is_Synchronized_Tagged_Type --
12763 ---------------------------------
12765 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
12766 Kind : constant Entity_Kind := Ekind (Base_Type (E));
12769 -- A task or protected type derived from an interface is a tagged type.
12770 -- Such a tagged type is called a synchronized tagged type, as are
12771 -- synchronized interfaces and private extensions whose declaration
12772 -- includes the reserved word synchronized.
12774 return (Is_Tagged_Type (E)
12775 and then (Kind = E_Task_Type
12777 Kind = E_Protected_Type))
12780 and then Is_Synchronized_Interface (E))
12782 (Ekind (E) = E_Record_Type_With_Private
12783 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
12784 and then (Synchronized_Present (Parent (E))
12785 or else Is_Synchronized_Interface (Etype (E))));
12786 end Is_Synchronized_Tagged_Type;
12792 function Is_Transfer (N : Node_Id) return Boolean is
12793 Kind : constant Node_Kind := Nkind (N);
12796 if Kind = N_Simple_Return_Statement
12798 Kind = N_Extended_Return_Statement
12800 Kind = N_Goto_Statement
12802 Kind = N_Raise_Statement
12804 Kind = N_Requeue_Statement
12808 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
12809 and then No (Condition (N))
12813 elsif Kind = N_Procedure_Call_Statement
12814 and then Is_Entity_Name (Name (N))
12815 and then Present (Entity (Name (N)))
12816 and then No_Return (Entity (Name (N)))
12820 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
12832 function Is_True (U : Uint) return Boolean is
12837 --------------------------------------
12838 -- Is_Unchecked_Conversion_Instance --
12839 --------------------------------------
12841 function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is
12842 Gen_Par : Entity_Id;
12845 -- Look for a function whose generic parent is the predefined intrinsic
12846 -- function Unchecked_Conversion.
12848 if Ekind (Id) = E_Function then
12849 Gen_Par := Generic_Parent (Parent (Id));
12853 and then Chars (Gen_Par) = Name_Unchecked_Conversion
12854 and then Is_Intrinsic_Subprogram (Gen_Par)
12855 and then Is_Predefined_File_Name
12856 (Unit_File_Name (Get_Source_Unit (Gen_Par)));
12860 end Is_Unchecked_Conversion_Instance;
12862 -------------------------------
12863 -- Is_Universal_Numeric_Type --
12864 -------------------------------
12866 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
12868 return T = Universal_Integer or else T = Universal_Real;
12869 end Is_Universal_Numeric_Type;
12871 -------------------
12872 -- Is_Value_Type --
12873 -------------------
12875 function Is_Value_Type (T : Entity_Id) return Boolean is
12877 return VM_Target = CLI_Target
12878 and then Nkind (T) in N_Has_Chars
12879 and then Chars (T) /= No_Name
12880 and then Get_Name_String (Chars (T)) = "valuetype";
12883 ----------------------------
12884 -- Is_Variable_Size_Array --
12885 ----------------------------
12887 function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
12891 pragma Assert (Is_Array_Type (E));
12893 -- Check if some index is initialized with a non-constant value
12895 Idx := First_Index (E);
12896 while Present (Idx) loop
12897 if Nkind (Idx) = N_Range then
12898 if not Is_Constant_Bound (Low_Bound (Idx))
12899 or else not Is_Constant_Bound (High_Bound (Idx))
12905 Idx := Next_Index (Idx);
12909 end Is_Variable_Size_Array;
12911 -----------------------------
12912 -- Is_Variable_Size_Record --
12913 -----------------------------
12915 function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
12917 Comp_Typ : Entity_Id;
12920 pragma Assert (Is_Record_Type (E));
12922 Comp := First_Entity (E);
12923 while Present (Comp) loop
12924 Comp_Typ := Etype (Comp);
12926 -- Recursive call if the record type has discriminants
12928 if Is_Record_Type (Comp_Typ)
12929 and then Has_Discriminants (Comp_Typ)
12930 and then Is_Variable_Size_Record (Comp_Typ)
12934 elsif Is_Array_Type (Comp_Typ)
12935 and then Is_Variable_Size_Array (Comp_Typ)
12940 Next_Entity (Comp);
12944 end Is_Variable_Size_Record;
12950 function Is_Variable
12952 Use_Original_Node : Boolean := True) return Boolean
12954 Orig_Node : Node_Id;
12956 function In_Protected_Function (E : Entity_Id) return Boolean;
12957 -- Within a protected function, the private components of the enclosing
12958 -- protected type are constants. A function nested within a (protected)
12959 -- procedure is not itself protected. Within the body of a protected
12960 -- function the current instance of the protected type is a constant.
12962 function Is_Variable_Prefix (P : Node_Id) return Boolean;
12963 -- Prefixes can involve implicit dereferences, in which case we must
12964 -- test for the case of a reference of a constant access type, which can
12965 -- can never be a variable.
12967 ---------------------------
12968 -- In_Protected_Function --
12969 ---------------------------
12971 function In_Protected_Function (E : Entity_Id) return Boolean is
12976 -- E is the current instance of a type
12978 if Is_Type (E) then
12987 if not Is_Protected_Type (Prot) then
12991 S := Current_Scope;
12992 while Present (S) and then S /= Prot loop
12993 if Ekind (S) = E_Function and then Scope (S) = Prot then
13002 end In_Protected_Function;
13004 ------------------------
13005 -- Is_Variable_Prefix --
13006 ------------------------
13008 function Is_Variable_Prefix (P : Node_Id) return Boolean is
13010 if Is_Access_Type (Etype (P)) then
13011 return not Is_Access_Constant (Root_Type (Etype (P)));
13013 -- For the case of an indexed component whose prefix has a packed
13014 -- array type, the prefix has been rewritten into a type conversion.
13015 -- Determine variable-ness from the converted expression.
13017 elsif Nkind (P) = N_Type_Conversion
13018 and then not Comes_From_Source (P)
13019 and then Is_Array_Type (Etype (P))
13020 and then Is_Packed (Etype (P))
13022 return Is_Variable (Expression (P));
13025 return Is_Variable (P);
13027 end Is_Variable_Prefix;
13029 -- Start of processing for Is_Variable
13032 -- Special check, allow x'Deref(expr) as a variable
13034 if Nkind (N) = N_Attribute_Reference
13035 and then Attribute_Name (N) = Name_Deref
13040 -- Check if we perform the test on the original node since this may be a
13041 -- test of syntactic categories which must not be disturbed by whatever
13042 -- rewriting might have occurred. For example, an aggregate, which is
13043 -- certainly NOT a variable, could be turned into a variable by
13046 if Use_Original_Node then
13047 Orig_Node := Original_Node (N);
13052 -- Definitely OK if Assignment_OK is set. Since this is something that
13053 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
13055 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
13058 -- Normally we go to the original node, but there is one exception where
13059 -- we use the rewritten node, namely when it is an explicit dereference.
13060 -- The generated code may rewrite a prefix which is an access type with
13061 -- an explicit dereference. The dereference is a variable, even though
13062 -- the original node may not be (since it could be a constant of the
13065 -- In Ada 2005 we have a further case to consider: the prefix may be a
13066 -- function call given in prefix notation. The original node appears to
13067 -- be a selected component, but we need to examine the call.
13069 elsif Nkind (N) = N_Explicit_Dereference
13070 and then Nkind (Orig_Node) /= N_Explicit_Dereference
13071 and then Present (Etype (Orig_Node))
13072 and then Is_Access_Type (Etype (Orig_Node))
13074 -- Note that if the prefix is an explicit dereference that does not
13075 -- come from source, we must check for a rewritten function call in
13076 -- prefixed notation before other forms of rewriting, to prevent a
13080 (Nkind (Orig_Node) = N_Function_Call
13081 and then not Is_Access_Constant (Etype (Prefix (N))))
13083 Is_Variable_Prefix (Original_Node (Prefix (N)));
13085 -- in Ada 2012, the dereference may have been added for a type with
13086 -- a declared implicit dereference aspect. Check that it is not an
13087 -- access to constant.
13089 elsif Nkind (N) = N_Explicit_Dereference
13090 and then Present (Etype (Orig_Node))
13091 and then Ada_Version >= Ada_2012
13092 and then Has_Implicit_Dereference (Etype (Orig_Node))
13094 return not Is_Access_Constant (Etype (Prefix (N)));
13096 -- A function call is never a variable
13098 elsif Nkind (N) = N_Function_Call then
13101 -- All remaining checks use the original node
13103 elsif Is_Entity_Name (Orig_Node)
13104 and then Present (Entity (Orig_Node))
13107 E : constant Entity_Id := Entity (Orig_Node);
13108 K : constant Entity_Kind := Ekind (E);
13111 return (K = E_Variable
13112 and then Nkind (Parent (E)) /= N_Exception_Handler)
13113 or else (K = E_Component
13114 and then not In_Protected_Function (E))
13115 or else K = E_Out_Parameter
13116 or else K = E_In_Out_Parameter
13117 or else K = E_Generic_In_Out_Parameter
13119 -- Current instance of type. If this is a protected type, check
13120 -- we are not within the body of one of its protected functions.
13122 or else (Is_Type (E)
13123 and then In_Open_Scopes (E)
13124 and then not In_Protected_Function (E))
13126 or else (Is_Incomplete_Or_Private_Type (E)
13127 and then In_Open_Scopes (Full_View (E)));
13131 case Nkind (Orig_Node) is
13132 when N_Indexed_Component | N_Slice =>
13133 return Is_Variable_Prefix (Prefix (Orig_Node));
13135 when N_Selected_Component =>
13136 return (Is_Variable (Selector_Name (Orig_Node))
13137 and then Is_Variable_Prefix (Prefix (Orig_Node)))
13139 (Nkind (N) = N_Expanded_Name
13140 and then Scope (Entity (N)) = Entity (Prefix (N)));
13142 -- For an explicit dereference, the type of the prefix cannot
13143 -- be an access to constant or an access to subprogram.
13145 when N_Explicit_Dereference =>
13147 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
13149 return Is_Access_Type (Typ)
13150 and then not Is_Access_Constant (Root_Type (Typ))
13151 and then Ekind (Typ) /= E_Access_Subprogram_Type;
13154 -- The type conversion is the case where we do not deal with the
13155 -- context dependent special case of an actual parameter. Thus
13156 -- the type conversion is only considered a variable for the
13157 -- purposes of this routine if the target type is tagged. However,
13158 -- a type conversion is considered to be a variable if it does not
13159 -- come from source (this deals for example with the conversions
13160 -- of expressions to their actual subtypes).
13162 when N_Type_Conversion =>
13163 return Is_Variable (Expression (Orig_Node))
13165 (not Comes_From_Source (Orig_Node)
13167 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
13169 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
13171 -- GNAT allows an unchecked type conversion as a variable. This
13172 -- only affects the generation of internal expanded code, since
13173 -- calls to instantiations of Unchecked_Conversion are never
13174 -- considered variables (since they are function calls).
13176 when N_Unchecked_Type_Conversion =>
13177 return Is_Variable (Expression (Orig_Node));
13185 ---------------------------
13186 -- Is_Visibly_Controlled --
13187 ---------------------------
13189 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
13190 Root : constant Entity_Id := Root_Type (T);
13192 return Chars (Scope (Root)) = Name_Finalization
13193 and then Chars (Scope (Scope (Root))) = Name_Ada
13194 and then Scope (Scope (Scope (Root))) = Standard_Standard;
13195 end Is_Visibly_Controlled;
13197 ------------------------
13198 -- Is_Volatile_Object --
13199 ------------------------
13201 function Is_Volatile_Object (N : Node_Id) return Boolean is
13203 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
13204 -- If prefix is an implicit dereference, examine designated type
13206 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
13207 -- Determines if given object has volatile components
13209 ------------------------
13210 -- Is_Volatile_Prefix --
13211 ------------------------
13213 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
13214 Typ : constant Entity_Id := Etype (N);
13217 if Is_Access_Type (Typ) then
13219 Dtyp : constant Entity_Id := Designated_Type (Typ);
13222 return Is_Volatile (Dtyp)
13223 or else Has_Volatile_Components (Dtyp);
13227 return Object_Has_Volatile_Components (N);
13229 end Is_Volatile_Prefix;
13231 ------------------------------------
13232 -- Object_Has_Volatile_Components --
13233 ------------------------------------
13235 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
13236 Typ : constant Entity_Id := Etype (N);
13239 if Is_Volatile (Typ)
13240 or else Has_Volatile_Components (Typ)
13244 elsif Is_Entity_Name (N)
13245 and then (Has_Volatile_Components (Entity (N))
13246 or else Is_Volatile (Entity (N)))
13250 elsif Nkind (N) = N_Indexed_Component
13251 or else Nkind (N) = N_Selected_Component
13253 return Is_Volatile_Prefix (Prefix (N));
13258 end Object_Has_Volatile_Components;
13260 -- Start of processing for Is_Volatile_Object
13263 if Nkind (N) = N_Defining_Identifier then
13264 return Is_Volatile (N) or else Is_Volatile (Etype (N));
13266 elsif Nkind (N) = N_Expanded_Name then
13267 return Is_Volatile_Object (Entity (N));
13269 elsif Is_Volatile (Etype (N))
13270 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
13274 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component)
13275 and then Is_Volatile_Prefix (Prefix (N))
13279 elsif Nkind (N) = N_Selected_Component
13280 and then Is_Volatile (Entity (Selector_Name (N)))
13287 end Is_Volatile_Object;
13289 ---------------------------
13290 -- Itype_Has_Declaration --
13291 ---------------------------
13293 function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
13295 pragma Assert (Is_Itype (Id));
13296 return Present (Parent (Id))
13297 and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
13298 N_Subtype_Declaration)
13299 and then Defining_Entity (Parent (Id)) = Id;
13300 end Itype_Has_Declaration;
13302 -------------------------
13303 -- Kill_Current_Values --
13304 -------------------------
13306 procedure Kill_Current_Values
13308 Last_Assignment_Only : Boolean := False)
13311 if Is_Assignable (Ent) then
13312 Set_Last_Assignment (Ent, Empty);
13315 if Is_Object (Ent) then
13316 if not Last_Assignment_Only then
13318 Set_Current_Value (Ent, Empty);
13320 -- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
13321 -- for a constant. Once the constant is elaborated, its value is
13322 -- not changed, therefore the associated flags that describe the
13323 -- value should not be modified either.
13325 if Ekind (Ent) = E_Constant then
13328 -- Non-constant entities
13331 if not Can_Never_Be_Null (Ent) then
13332 Set_Is_Known_Non_Null (Ent, False);
13335 Set_Is_Known_Null (Ent, False);
13337 -- Reset the Is_Known_Valid flag unless the type is always
13338 -- valid. This does not apply to a loop parameter because its
13339 -- bounds are defined by the loop header and therefore always
13342 if not Is_Known_Valid (Etype (Ent))
13343 and then Ekind (Ent) /= E_Loop_Parameter
13345 Set_Is_Known_Valid (Ent, False);
13350 end Kill_Current_Values;
13352 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
13355 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
13356 -- Clear current value for entity E and all entities chained to E
13358 ------------------------------------------
13359 -- Kill_Current_Values_For_Entity_Chain --
13360 ------------------------------------------
13362 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
13366 while Present (Ent) loop
13367 Kill_Current_Values (Ent, Last_Assignment_Only);
13370 end Kill_Current_Values_For_Entity_Chain;
13372 -- Start of processing for Kill_Current_Values
13375 -- Kill all saved checks, a special case of killing saved values
13377 if not Last_Assignment_Only then
13381 -- Loop through relevant scopes, which includes the current scope and
13382 -- any parent scopes if the current scope is a block or a package.
13384 S := Current_Scope;
13387 -- Clear current values of all entities in current scope
13389 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
13391 -- If scope is a package, also clear current values of all private
13392 -- entities in the scope.
13394 if Is_Package_Or_Generic_Package (S)
13395 or else Is_Concurrent_Type (S)
13397 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
13400 -- If this is a not a subprogram, deal with parents
13402 if not Is_Subprogram (S) then
13404 exit Scope_Loop when S = Standard_Standard;
13408 end loop Scope_Loop;
13409 end Kill_Current_Values;
13411 --------------------------
13412 -- Kill_Size_Check_Code --
13413 --------------------------
13415 procedure Kill_Size_Check_Code (E : Entity_Id) is
13417 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
13418 and then Present (Size_Check_Code (E))
13420 Remove (Size_Check_Code (E));
13421 Set_Size_Check_Code (E, Empty);
13423 end Kill_Size_Check_Code;
13425 --------------------------
13426 -- Known_To_Be_Assigned --
13427 --------------------------
13429 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
13430 P : constant Node_Id := Parent (N);
13435 -- Test left side of assignment
13437 when N_Assignment_Statement =>
13438 return N = Name (P);
13440 -- Function call arguments are never lvalues
13442 when N_Function_Call =>
13445 -- Positional parameter for procedure or accept call
13447 when N_Procedure_Call_Statement |
13456 Proc := Get_Subprogram_Entity (P);
13462 -- If we are not a list member, something is strange, so
13463 -- be conservative and return False.
13465 if not Is_List_Member (N) then
13469 -- We are going to find the right formal by stepping forward
13470 -- through the formals, as we step backwards in the actuals.
13472 Form := First_Formal (Proc);
13475 -- If no formal, something is weird, so be conservative
13476 -- and return False.
13483 exit when No (Act);
13484 Next_Formal (Form);
13487 return Ekind (Form) /= E_In_Parameter;
13490 -- Named parameter for procedure or accept call
13492 when N_Parameter_Association =>
13498 Proc := Get_Subprogram_Entity (Parent (P));
13504 -- Loop through formals to find the one that matches
13506 Form := First_Formal (Proc);
13508 -- If no matching formal, that's peculiar, some kind of
13509 -- previous error, so return False to be conservative.
13510 -- Actually this also happens in legal code in the case
13511 -- where P is a parameter association for an Extra_Formal???
13517 -- Else test for match
13519 if Chars (Form) = Chars (Selector_Name (P)) then
13520 return Ekind (Form) /= E_In_Parameter;
13523 Next_Formal (Form);
13527 -- Test for appearing in a conversion that itself appears
13528 -- in an lvalue context, since this should be an lvalue.
13530 when N_Type_Conversion =>
13531 return Known_To_Be_Assigned (P);
13533 -- All other references are definitely not known to be modifications
13539 end Known_To_Be_Assigned;
13541 ---------------------------
13542 -- Last_Source_Statement --
13543 ---------------------------
13545 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
13549 N := Last (Statements (HSS));
13550 while Present (N) loop
13551 exit when Comes_From_Source (N);
13556 end Last_Source_Statement;
13558 ----------------------------------
13559 -- Matching_Static_Array_Bounds --
13560 ----------------------------------
13562 function Matching_Static_Array_Bounds
13564 R_Typ : Node_Id) return Boolean
13566 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
13567 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
13579 if L_Ndims /= R_Ndims then
13583 -- Unconstrained types do not have static bounds
13585 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
13589 -- First treat specially the first dimension, as the lower bound and
13590 -- length of string literals are not stored like those of arrays.
13592 if Ekind (L_Typ) = E_String_Literal_Subtype then
13593 L_Low := String_Literal_Low_Bound (L_Typ);
13594 L_Len := String_Literal_Length (L_Typ);
13596 L_Index := First_Index (L_Typ);
13597 Get_Index_Bounds (L_Index, L_Low, L_High);
13599 if Is_OK_Static_Expression (L_Low)
13601 Is_OK_Static_Expression (L_High)
13603 if Expr_Value (L_High) < Expr_Value (L_Low) then
13606 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
13613 if Ekind (R_Typ) = E_String_Literal_Subtype then
13614 R_Low := String_Literal_Low_Bound (R_Typ);
13615 R_Len := String_Literal_Length (R_Typ);
13617 R_Index := First_Index (R_Typ);
13618 Get_Index_Bounds (R_Index, R_Low, R_High);
13620 if Is_OK_Static_Expression (R_Low)
13622 Is_OK_Static_Expression (R_High)
13624 if Expr_Value (R_High) < Expr_Value (R_Low) then
13627 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
13634 if (Is_OK_Static_Expression (L_Low)
13636 Is_OK_Static_Expression (R_Low))
13637 and then Expr_Value (L_Low) = Expr_Value (R_Low)
13638 and then L_Len = R_Len
13645 -- Then treat all other dimensions
13647 for Indx in 2 .. L_Ndims loop
13651 Get_Index_Bounds (L_Index, L_Low, L_High);
13652 Get_Index_Bounds (R_Index, R_Low, R_High);
13654 if (Is_OK_Static_Expression (L_Low) and then
13655 Is_OK_Static_Expression (L_High) and then
13656 Is_OK_Static_Expression (R_Low) and then
13657 Is_OK_Static_Expression (R_High))
13658 and then (Expr_Value (L_Low) = Expr_Value (R_Low)
13660 Expr_Value (L_High) = Expr_Value (R_High))
13668 -- If we fall through the loop, all indexes matched
13671 end Matching_Static_Array_Bounds;
13673 -------------------
13674 -- May_Be_Lvalue --
13675 -------------------
13677 function May_Be_Lvalue (N : Node_Id) return Boolean is
13678 P : constant Node_Id := Parent (N);
13683 -- Test left side of assignment
13685 when N_Assignment_Statement =>
13686 return N = Name (P);
13688 -- Test prefix of component or attribute. Note that the prefix of an
13689 -- explicit or implicit dereference cannot be an l-value.
13691 when N_Attribute_Reference =>
13692 return N = Prefix (P)
13693 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
13695 -- For an expanded name, the name is an lvalue if the expanded name
13696 -- is an lvalue, but the prefix is never an lvalue, since it is just
13697 -- the scope where the name is found.
13699 when N_Expanded_Name =>
13700 if N = Prefix (P) then
13701 return May_Be_Lvalue (P);
13706 -- For a selected component A.B, A is certainly an lvalue if A.B is.
13707 -- B is a little interesting, if we have A.B := 3, there is some
13708 -- discussion as to whether B is an lvalue or not, we choose to say
13709 -- it is. Note however that A is not an lvalue if it is of an access
13710 -- type since this is an implicit dereference.
13712 when N_Selected_Component =>
13714 and then Present (Etype (N))
13715 and then Is_Access_Type (Etype (N))
13719 return May_Be_Lvalue (P);
13722 -- For an indexed component or slice, the index or slice bounds is
13723 -- never an lvalue. The prefix is an lvalue if the indexed component
13724 -- or slice is an lvalue, except if it is an access type, where we
13725 -- have an implicit dereference.
13727 when N_Indexed_Component | N_Slice =>
13729 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
13733 return May_Be_Lvalue (P);
13736 -- Prefix of a reference is an lvalue if the reference is an lvalue
13738 when N_Reference =>
13739 return May_Be_Lvalue (P);
13741 -- Prefix of explicit dereference is never an lvalue
13743 when N_Explicit_Dereference =>
13746 -- Positional parameter for subprogram, entry, or accept call.
13747 -- In older versions of Ada function call arguments are never
13748 -- lvalues. In Ada 2012 functions can have in-out parameters.
13750 when N_Subprogram_Call |
13751 N_Entry_Call_Statement |
13754 if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
13758 -- The following mechanism is clumsy and fragile. A single flag
13759 -- set in Resolve_Actuals would be preferable ???
13767 Proc := Get_Subprogram_Entity (P);
13773 -- If we are not a list member, something is strange, so be
13774 -- conservative and return True.
13776 if not Is_List_Member (N) then
13780 -- We are going to find the right formal by stepping forward
13781 -- through the formals, as we step backwards in the actuals.
13783 Form := First_Formal (Proc);
13786 -- If no formal, something is weird, so be conservative and
13794 exit when No (Act);
13795 Next_Formal (Form);
13798 return Ekind (Form) /= E_In_Parameter;
13801 -- Named parameter for procedure or accept call
13803 when N_Parameter_Association =>
13809 Proc := Get_Subprogram_Entity (Parent (P));
13815 -- Loop through formals to find the one that matches
13817 Form := First_Formal (Proc);
13819 -- If no matching formal, that's peculiar, some kind of
13820 -- previous error, so return True to be conservative.
13821 -- Actually happens with legal code for an unresolved call
13822 -- where we may get the wrong homonym???
13828 -- Else test for match
13830 if Chars (Form) = Chars (Selector_Name (P)) then
13831 return Ekind (Form) /= E_In_Parameter;
13834 Next_Formal (Form);
13838 -- Test for appearing in a conversion that itself appears in an
13839 -- lvalue context, since this should be an lvalue.
13841 when N_Type_Conversion =>
13842 return May_Be_Lvalue (P);
13844 -- Test for appearance in object renaming declaration
13846 when N_Object_Renaming_Declaration =>
13849 -- All other references are definitely not lvalues
13857 -----------------------
13858 -- Mark_Coextensions --
13859 -----------------------
13861 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
13862 Is_Dynamic : Boolean;
13863 -- Indicates whether the context causes nested coextensions to be
13864 -- dynamic or static
13866 function Mark_Allocator (N : Node_Id) return Traverse_Result;
13867 -- Recognize an allocator node and label it as a dynamic coextension
13869 --------------------
13870 -- Mark_Allocator --
13871 --------------------
13873 function Mark_Allocator (N : Node_Id) return Traverse_Result is
13875 if Nkind (N) = N_Allocator then
13877 Set_Is_Dynamic_Coextension (N);
13879 -- If the allocator expression is potentially dynamic, it may
13880 -- be expanded out of order and require dynamic allocation
13881 -- anyway, so we treat the coextension itself as dynamic.
13882 -- Potential optimization ???
13884 elsif Nkind (Expression (N)) = N_Qualified_Expression
13885 and then Nkind (Expression (Expression (N))) = N_Op_Concat
13887 Set_Is_Dynamic_Coextension (N);
13889 Set_Is_Static_Coextension (N);
13894 end Mark_Allocator;
13896 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
13898 -- Start of processing Mark_Coextensions
13901 case Nkind (Context_Nod) is
13903 -- Comment here ???
13905 when N_Assignment_Statement =>
13906 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
13908 -- An allocator that is a component of a returned aggregate
13909 -- must be dynamic.
13911 when N_Simple_Return_Statement =>
13913 Expr : constant Node_Id := Expression (Context_Nod);
13916 Nkind (Expr) = N_Allocator
13918 (Nkind (Expr) = N_Qualified_Expression
13919 and then Nkind (Expression (Expr)) = N_Aggregate);
13922 -- An alloctor within an object declaration in an extended return
13923 -- statement is of necessity dynamic.
13925 when N_Object_Declaration =>
13926 Is_Dynamic := Nkind (Root_Nod) = N_Allocator
13928 Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
13930 -- This routine should not be called for constructs which may not
13931 -- contain coextensions.
13934 raise Program_Error;
13937 Mark_Allocators (Root_Nod);
13938 end Mark_Coextensions;
13940 ----------------------
13941 -- Needs_One_Actual --
13942 ----------------------
13944 function Needs_One_Actual (E : Entity_Id) return Boolean is
13945 Formal : Entity_Id;
13948 -- Ada 2005 or later, and formals present
13950 if Ada_Version >= Ada_2005 and then Present (First_Formal (E)) then
13951 Formal := Next_Formal (First_Formal (E));
13952 while Present (Formal) loop
13953 if No (Default_Value (Formal)) then
13957 Next_Formal (Formal);
13962 -- Ada 83/95 or no formals
13967 end Needs_One_Actual;
13969 ------------------------
13970 -- New_Copy_List_Tree --
13971 ------------------------
13973 function New_Copy_List_Tree (List : List_Id) return List_Id is
13978 if List = No_List then
13985 while Present (E) loop
13986 Append (New_Copy_Tree (E), NL);
13992 end New_Copy_List_Tree;
13994 --------------------------------------------------
13995 -- New_Copy_Tree Auxiliary Data and Subprograms --
13996 --------------------------------------------------
13998 use Atree.Unchecked_Access;
13999 use Atree_Private_Part;
14001 -- Our approach here requires a two pass traversal of the tree. The
14002 -- first pass visits all nodes that eventually will be copied looking
14003 -- for defining Itypes. If any defining Itypes are found, then they are
14004 -- copied, and an entry is added to the replacement map. In the second
14005 -- phase, the tree is copied, using the replacement map to replace any
14006 -- Itype references within the copied tree.
14008 -- The following hash tables are used if the Map supplied has more
14009 -- than hash threshold entries to speed up access to the map. If
14010 -- there are fewer entries, then the map is searched sequentially
14011 -- (because setting up a hash table for only a few entries takes
14012 -- more time than it saves.
14014 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
14015 -- Hash function used for hash operations
14017 -------------------
14018 -- New_Copy_Hash --
14019 -------------------
14021 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
14023 return Nat (E) mod (NCT_Header_Num'Last + 1);
14030 -- The hash table NCT_Assoc associates old entities in the table
14031 -- with their corresponding new entities (i.e. the pairs of entries
14032 -- presented in the original Map argument are Key-Element pairs).
14034 package NCT_Assoc is new Simple_HTable (
14035 Header_Num => NCT_Header_Num,
14036 Element => Entity_Id,
14037 No_Element => Empty,
14039 Hash => New_Copy_Hash,
14040 Equal => Types."=");
14042 ---------------------
14043 -- NCT_Itype_Assoc --
14044 ---------------------
14046 -- The hash table NCT_Itype_Assoc contains entries only for those
14047 -- old nodes which have a non-empty Associated_Node_For_Itype set.
14048 -- The key is the associated node, and the element is the new node
14049 -- itself (NOT the associated node for the new node).
14051 package NCT_Itype_Assoc is new Simple_HTable (
14052 Header_Num => NCT_Header_Num,
14053 Element => Entity_Id,
14054 No_Element => Empty,
14056 Hash => New_Copy_Hash,
14057 Equal => Types."=");
14059 -------------------
14060 -- New_Copy_Tree --
14061 -------------------
14063 function New_Copy_Tree
14065 Map : Elist_Id := No_Elist;
14066 New_Sloc : Source_Ptr := No_Location;
14067 New_Scope : Entity_Id := Empty) return Node_Id
14069 Actual_Map : Elist_Id := Map;
14070 -- This is the actual map for the copy. It is initialized with the
14071 -- given elements, and then enlarged as required for Itypes that are
14072 -- copied during the first phase of the copy operation. The visit
14073 -- procedures add elements to this map as Itypes are encountered.
14074 -- The reason we cannot use Map directly, is that it may well be
14075 -- (and normally is) initialized to No_Elist, and if we have mapped
14076 -- entities, we have to reset it to point to a real Elist.
14078 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
14079 -- Called during second phase to map entities into their corresponding
14080 -- copies using Actual_Map. If the argument is not an entity, or is not
14081 -- in Actual_Map, then it is returned unchanged.
14083 procedure Build_NCT_Hash_Tables;
14084 -- Builds hash tables (number of elements >= threshold value)
14086 function Copy_Elist_With_Replacement
14087 (Old_Elist : Elist_Id) return Elist_Id;
14088 -- Called during second phase to copy element list doing replacements
14090 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
14091 -- Called during the second phase to process a copied Itype. The actual
14092 -- copy happened during the first phase (so that we could make the entry
14093 -- in the mapping), but we still have to deal with the descendents of
14094 -- the copied Itype and copy them where necessary.
14096 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
14097 -- Called during second phase to copy list doing replacements
14099 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
14100 -- Called during second phase to copy node doing replacements
14102 procedure Visit_Elist (E : Elist_Id);
14103 -- Called during first phase to visit all elements of an Elist
14105 procedure Visit_Field (F : Union_Id; N : Node_Id);
14106 -- Visit a single field, recursing to call Visit_Node or Visit_List
14107 -- if the field is a syntactic descendent of the current node (i.e.
14108 -- its parent is Node N).
14110 procedure Visit_Itype (Old_Itype : Entity_Id);
14111 -- Called during first phase to visit subsidiary fields of a defining
14112 -- Itype, and also create a copy and make an entry in the replacement
14113 -- map for the new copy.
14115 procedure Visit_List (L : List_Id);
14116 -- Called during first phase to visit all elements of a List
14118 procedure Visit_Node (N : Node_Or_Entity_Id);
14119 -- Called during first phase to visit a node and all its subtrees
14125 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
14130 if not Has_Extension (N) or else No (Actual_Map) then
14133 elsif NCT_Hash_Tables_Used then
14134 Ent := NCT_Assoc.Get (Entity_Id (N));
14136 if Present (Ent) then
14142 -- No hash table used, do serial search
14145 E := First_Elmt (Actual_Map);
14146 while Present (E) loop
14147 if Node (E) = N then
14148 return Node (Next_Elmt (E));
14150 E := Next_Elmt (Next_Elmt (E));
14158 ---------------------------
14159 -- Build_NCT_Hash_Tables --
14160 ---------------------------
14162 procedure Build_NCT_Hash_Tables is
14166 if NCT_Hash_Table_Setup then
14168 NCT_Itype_Assoc.Reset;
14171 Elmt := First_Elmt (Actual_Map);
14172 while Present (Elmt) loop
14173 Ent := Node (Elmt);
14175 -- Get new entity, and associate old and new
14178 NCT_Assoc.Set (Ent, Node (Elmt));
14180 if Is_Type (Ent) then
14182 Anode : constant Entity_Id :=
14183 Associated_Node_For_Itype (Ent);
14186 if Present (Anode) then
14188 -- Enter a link between the associated node of the
14189 -- old Itype and the new Itype, for updating later
14190 -- when node is copied.
14192 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
14200 NCT_Hash_Tables_Used := True;
14201 NCT_Hash_Table_Setup := True;
14202 end Build_NCT_Hash_Tables;
14204 ---------------------------------
14205 -- Copy_Elist_With_Replacement --
14206 ---------------------------------
14208 function Copy_Elist_With_Replacement
14209 (Old_Elist : Elist_Id) return Elist_Id
14212 New_Elist : Elist_Id;
14215 if No (Old_Elist) then
14219 New_Elist := New_Elmt_List;
14221 M := First_Elmt (Old_Elist);
14222 while Present (M) loop
14223 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
14229 end Copy_Elist_With_Replacement;
14231 ---------------------------------
14232 -- Copy_Itype_With_Replacement --
14233 ---------------------------------
14235 -- This routine exactly parallels its phase one analog Visit_Itype,
14237 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
14239 -- Translate Next_Entity, Scope and Etype fields, in case they
14240 -- reference entities that have been mapped into copies.
14242 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
14243 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
14245 if Present (New_Scope) then
14246 Set_Scope (New_Itype, New_Scope);
14248 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
14251 -- Copy referenced fields
14253 if Is_Discrete_Type (New_Itype) then
14254 Set_Scalar_Range (New_Itype,
14255 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
14257 elsif Has_Discriminants (Base_Type (New_Itype)) then
14258 Set_Discriminant_Constraint (New_Itype,
14259 Copy_Elist_With_Replacement
14260 (Discriminant_Constraint (New_Itype)));
14262 elsif Is_Array_Type (New_Itype) then
14263 if Present (First_Index (New_Itype)) then
14264 Set_First_Index (New_Itype,
14265 First (Copy_List_With_Replacement
14266 (List_Containing (First_Index (New_Itype)))));
14269 if Is_Packed (New_Itype) then
14270 Set_Packed_Array_Impl_Type (New_Itype,
14271 Copy_Node_With_Replacement
14272 (Packed_Array_Impl_Type (New_Itype)));
14275 end Copy_Itype_With_Replacement;
14277 --------------------------------
14278 -- Copy_List_With_Replacement --
14279 --------------------------------
14281 function Copy_List_With_Replacement
14282 (Old_List : List_Id) return List_Id
14284 New_List : List_Id;
14288 if Old_List = No_List then
14292 New_List := Empty_List;
14294 E := First (Old_List);
14295 while Present (E) loop
14296 Append (Copy_Node_With_Replacement (E), New_List);
14302 end Copy_List_With_Replacement;
14304 --------------------------------
14305 -- Copy_Node_With_Replacement --
14306 --------------------------------
14308 function Copy_Node_With_Replacement
14309 (Old_Node : Node_Id) return Node_Id
14311 New_Node : Node_Id;
14313 procedure Adjust_Named_Associations
14314 (Old_Node : Node_Id;
14315 New_Node : Node_Id);
14316 -- If a call node has named associations, these are chained through
14317 -- the First_Named_Actual, Next_Named_Actual links. These must be
14318 -- propagated separately to the new parameter list, because these
14319 -- are not syntactic fields.
14321 function Copy_Field_With_Replacement
14322 (Field : Union_Id) return Union_Id;
14323 -- Given Field, which is a field of Old_Node, return a copy of it
14324 -- if it is a syntactic field (i.e. its parent is Node), setting
14325 -- the parent of the copy to poit to New_Node. Otherwise returns
14326 -- the field (possibly mapped if it is an entity).
14328 -------------------------------
14329 -- Adjust_Named_Associations --
14330 -------------------------------
14332 procedure Adjust_Named_Associations
14333 (Old_Node : Node_Id;
14334 New_Node : Node_Id)
14339 Old_Next : Node_Id;
14340 New_Next : Node_Id;
14343 Old_E := First (Parameter_Associations (Old_Node));
14344 New_E := First (Parameter_Associations (New_Node));
14345 while Present (Old_E) loop
14346 if Nkind (Old_E) = N_Parameter_Association
14347 and then Present (Next_Named_Actual (Old_E))
14349 if First_Named_Actual (Old_Node)
14350 = Explicit_Actual_Parameter (Old_E)
14352 Set_First_Named_Actual
14353 (New_Node, Explicit_Actual_Parameter (New_E));
14356 -- Now scan parameter list from the beginning,to locate
14357 -- next named actual, which can be out of order.
14359 Old_Next := First (Parameter_Associations (Old_Node));
14360 New_Next := First (Parameter_Associations (New_Node));
14362 while Nkind (Old_Next) /= N_Parameter_Association
14363 or else Explicit_Actual_Parameter (Old_Next) /=
14364 Next_Named_Actual (Old_E)
14370 Set_Next_Named_Actual
14371 (New_E, Explicit_Actual_Parameter (New_Next));
14377 end Adjust_Named_Associations;
14379 ---------------------------------
14380 -- Copy_Field_With_Replacement --
14381 ---------------------------------
14383 function Copy_Field_With_Replacement
14384 (Field : Union_Id) return Union_Id
14387 if Field = Union_Id (Empty) then
14390 elsif Field in Node_Range then
14392 Old_N : constant Node_Id := Node_Id (Field);
14396 -- If syntactic field, as indicated by the parent pointer
14397 -- being set, then copy the referenced node recursively.
14399 if Parent (Old_N) = Old_Node then
14400 New_N := Copy_Node_With_Replacement (Old_N);
14402 if New_N /= Old_N then
14403 Set_Parent (New_N, New_Node);
14406 -- For semantic fields, update possible entity reference
14407 -- from the replacement map.
14410 New_N := Assoc (Old_N);
14413 return Union_Id (New_N);
14416 elsif Field in List_Range then
14418 Old_L : constant List_Id := List_Id (Field);
14422 -- If syntactic field, as indicated by the parent pointer,
14423 -- then recursively copy the entire referenced list.
14425 if Parent (Old_L) = Old_Node then
14426 New_L := Copy_List_With_Replacement (Old_L);
14427 Set_Parent (New_L, New_Node);
14429 -- For semantic list, just returned unchanged
14435 return Union_Id (New_L);
14438 -- Anything other than a list or a node is returned unchanged
14443 end Copy_Field_With_Replacement;
14445 -- Start of processing for Copy_Node_With_Replacement
14448 if Old_Node <= Empty_Or_Error then
14451 elsif Has_Extension (Old_Node) then
14452 return Assoc (Old_Node);
14455 New_Node := New_Copy (Old_Node);
14457 -- If the node we are copying is the associated node of a
14458 -- previously copied Itype, then adjust the associated node
14459 -- of the copy of that Itype accordingly.
14461 if Present (Actual_Map) then
14467 -- Case of hash table used
14469 if NCT_Hash_Tables_Used then
14470 Ent := NCT_Itype_Assoc.Get (Old_Node);
14472 if Present (Ent) then
14473 Set_Associated_Node_For_Itype (Ent, New_Node);
14476 -- Case of no hash table used
14479 E := First_Elmt (Actual_Map);
14480 while Present (E) loop
14481 if Is_Itype (Node (E))
14483 Old_Node = Associated_Node_For_Itype (Node (E))
14485 Set_Associated_Node_For_Itype
14486 (Node (Next_Elmt (E)), New_Node);
14489 E := Next_Elmt (Next_Elmt (E));
14495 -- Recursively copy descendents
14498 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
14500 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
14502 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
14504 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
14506 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
14508 -- Adjust Sloc of new node if necessary
14510 if New_Sloc /= No_Location then
14511 Set_Sloc (New_Node, New_Sloc);
14513 -- If we adjust the Sloc, then we are essentially making
14514 -- a completely new node, so the Comes_From_Source flag
14515 -- should be reset to the proper default value.
14517 Nodes.Table (New_Node).Comes_From_Source :=
14518 Default_Node.Comes_From_Source;
14521 -- If the node is call and has named associations,
14522 -- set the corresponding links in the copy.
14524 if (Nkind (Old_Node) = N_Function_Call
14525 or else Nkind (Old_Node) = N_Entry_Call_Statement
14527 Nkind (Old_Node) = N_Procedure_Call_Statement)
14528 and then Present (First_Named_Actual (Old_Node))
14530 Adjust_Named_Associations (Old_Node, New_Node);
14533 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
14534 -- The replacement mechanism applies to entities, and is not used
14535 -- here. Eventually we may need a more general graph-copying
14536 -- routine. For now, do a sequential search to find desired node.
14538 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
14539 and then Present (First_Real_Statement (Old_Node))
14542 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
14546 N1 := First (Statements (Old_Node));
14547 N2 := First (Statements (New_Node));
14549 while N1 /= Old_F loop
14554 Set_First_Real_Statement (New_Node, N2);
14559 -- All done, return copied node
14562 end Copy_Node_With_Replacement;
14568 procedure Visit_Elist (E : Elist_Id) is
14571 if Present (E) then
14572 Elmt := First_Elmt (E);
14574 while Elmt /= No_Elmt loop
14575 Visit_Node (Node (Elmt));
14585 procedure Visit_Field (F : Union_Id; N : Node_Id) is
14587 if F = Union_Id (Empty) then
14590 elsif F in Node_Range then
14592 -- Copy node if it is syntactic, i.e. its parent pointer is
14593 -- set to point to the field that referenced it (certain
14594 -- Itypes will also meet this criterion, which is fine, since
14595 -- these are clearly Itypes that do need to be copied, since
14596 -- we are copying their parent.)
14598 if Parent (Node_Id (F)) = N then
14599 Visit_Node (Node_Id (F));
14602 -- Another case, if we are pointing to an Itype, then we want
14603 -- to copy it if its associated node is somewhere in the tree
14606 -- Note: the exclusion of self-referential copies is just an
14607 -- optimization, since the search of the already copied list
14608 -- would catch it, but it is a common case (Etype pointing
14609 -- to itself for an Itype that is a base type).
14611 elsif Has_Extension (Node_Id (F))
14612 and then Is_Itype (Entity_Id (F))
14613 and then Node_Id (F) /= N
14619 P := Associated_Node_For_Itype (Node_Id (F));
14620 while Present (P) loop
14622 Visit_Node (Node_Id (F));
14629 -- An Itype whose parent is not being copied definitely
14630 -- should NOT be copied, since it does not belong in any
14631 -- sense to the copied subtree.
14637 elsif F in List_Range and then Parent (List_Id (F)) = N then
14638 Visit_List (List_Id (F));
14647 procedure Visit_Itype (Old_Itype : Entity_Id) is
14648 New_Itype : Entity_Id;
14653 -- Itypes that describe the designated type of access to subprograms
14654 -- have the structure of subprogram declarations, with signatures,
14655 -- etc. Either we duplicate the signatures completely, or choose to
14656 -- share such itypes, which is fine because their elaboration will
14657 -- have no side effects.
14659 if Ekind (Old_Itype) = E_Subprogram_Type then
14663 New_Itype := New_Copy (Old_Itype);
14665 -- The new Itype has all the attributes of the old one, and
14666 -- we just copy the contents of the entity. However, the back-end
14667 -- needs different names for debugging purposes, so we create a
14668 -- new internal name for it in all cases.
14670 Set_Chars (New_Itype, New_Internal_Name ('T'));
14672 -- If our associated node is an entity that has already been copied,
14673 -- then set the associated node of the copy to point to the right
14674 -- copy. If we have copied an Itype that is itself the associated
14675 -- node of some previously copied Itype, then we set the right
14676 -- pointer in the other direction.
14678 if Present (Actual_Map) then
14680 -- Case of hash tables used
14682 if NCT_Hash_Tables_Used then
14684 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
14686 if Present (Ent) then
14687 Set_Associated_Node_For_Itype (New_Itype, Ent);
14690 Ent := NCT_Itype_Assoc.Get (Old_Itype);
14691 if Present (Ent) then
14692 Set_Associated_Node_For_Itype (Ent, New_Itype);
14694 -- If the hash table has no association for this Itype and
14695 -- its associated node, enter one now.
14698 NCT_Itype_Assoc.Set
14699 (Associated_Node_For_Itype (Old_Itype), New_Itype);
14702 -- Case of hash tables not used
14705 E := First_Elmt (Actual_Map);
14706 while Present (E) loop
14707 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
14708 Set_Associated_Node_For_Itype
14709 (New_Itype, Node (Next_Elmt (E)));
14712 if Is_Type (Node (E))
14713 and then Old_Itype = Associated_Node_For_Itype (Node (E))
14715 Set_Associated_Node_For_Itype
14716 (Node (Next_Elmt (E)), New_Itype);
14719 E := Next_Elmt (Next_Elmt (E));
14724 if Present (Freeze_Node (New_Itype)) then
14725 Set_Is_Frozen (New_Itype, False);
14726 Set_Freeze_Node (New_Itype, Empty);
14729 -- Add new association to map
14731 if No (Actual_Map) then
14732 Actual_Map := New_Elmt_List;
14735 Append_Elmt (Old_Itype, Actual_Map);
14736 Append_Elmt (New_Itype, Actual_Map);
14738 if NCT_Hash_Tables_Used then
14739 NCT_Assoc.Set (Old_Itype, New_Itype);
14742 NCT_Table_Entries := NCT_Table_Entries + 1;
14744 if NCT_Table_Entries > NCT_Hash_Threshold then
14745 Build_NCT_Hash_Tables;
14749 -- If a record subtype is simply copied, the entity list will be
14750 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
14752 if Ekind_In (Old_Itype, E_Record_Subtype, E_Class_Wide_Subtype) then
14753 Set_Cloned_Subtype (New_Itype, Old_Itype);
14756 -- Visit descendents that eventually get copied
14758 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
14760 if Is_Discrete_Type (Old_Itype) then
14761 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
14763 elsif Has_Discriminants (Base_Type (Old_Itype)) then
14764 -- ??? This should involve call to Visit_Field
14765 Visit_Elist (Discriminant_Constraint (Old_Itype));
14767 elsif Is_Array_Type (Old_Itype) then
14768 if Present (First_Index (Old_Itype)) then
14769 Visit_Field (Union_Id (List_Containing
14770 (First_Index (Old_Itype))),
14774 if Is_Packed (Old_Itype) then
14775 Visit_Field (Union_Id (Packed_Array_Impl_Type (Old_Itype)),
14785 procedure Visit_List (L : List_Id) is
14788 if L /= No_List then
14791 while Present (N) loop
14802 procedure Visit_Node (N : Node_Or_Entity_Id) is
14804 -- Start of processing for Visit_Node
14807 -- Handle case of an Itype, which must be copied
14809 if Has_Extension (N) and then Is_Itype (N) then
14811 -- Nothing to do if already in the list. This can happen with an
14812 -- Itype entity that appears more than once in the tree.
14813 -- Note that we do not want to visit descendents in this case.
14815 -- Test for already in list when hash table is used
14817 if NCT_Hash_Tables_Used then
14818 if Present (NCT_Assoc.Get (Entity_Id (N))) then
14822 -- Test for already in list when hash table not used
14828 if Present (Actual_Map) then
14829 E := First_Elmt (Actual_Map);
14830 while Present (E) loop
14831 if Node (E) = N then
14834 E := Next_Elmt (Next_Elmt (E));
14844 -- Visit descendents
14846 Visit_Field (Field1 (N), N);
14847 Visit_Field (Field2 (N), N);
14848 Visit_Field (Field3 (N), N);
14849 Visit_Field (Field4 (N), N);
14850 Visit_Field (Field5 (N), N);
14853 -- Start of processing for New_Copy_Tree
14858 -- See if we should use hash table
14860 if No (Actual_Map) then
14861 NCT_Hash_Tables_Used := False;
14868 NCT_Table_Entries := 0;
14870 Elmt := First_Elmt (Actual_Map);
14871 while Present (Elmt) loop
14872 NCT_Table_Entries := NCT_Table_Entries + 1;
14877 if NCT_Table_Entries > NCT_Hash_Threshold then
14878 Build_NCT_Hash_Tables;
14880 NCT_Hash_Tables_Used := False;
14885 -- Hash table set up if required, now start phase one by visiting
14886 -- top node (we will recursively visit the descendents).
14888 Visit_Node (Source);
14890 -- Now the second phase of the copy can start. First we process
14891 -- all the mapped entities, copying their descendents.
14893 if Present (Actual_Map) then
14896 New_Itype : Entity_Id;
14898 Elmt := First_Elmt (Actual_Map);
14899 while Present (Elmt) loop
14901 New_Itype := Node (Elmt);
14902 Copy_Itype_With_Replacement (New_Itype);
14908 -- Now we can copy the actual tree
14910 return Copy_Node_With_Replacement (Source);
14913 -------------------------
14914 -- New_External_Entity --
14915 -------------------------
14917 function New_External_Entity
14918 (Kind : Entity_Kind;
14919 Scope_Id : Entity_Id;
14920 Sloc_Value : Source_Ptr;
14921 Related_Id : Entity_Id;
14922 Suffix : Character;
14923 Suffix_Index : Nat := 0;
14924 Prefix : Character := ' ') return Entity_Id
14926 N : constant Entity_Id :=
14927 Make_Defining_Identifier (Sloc_Value,
14929 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
14932 Set_Ekind (N, Kind);
14933 Set_Is_Internal (N, True);
14934 Append_Entity (N, Scope_Id);
14935 Set_Public_Status (N);
14937 if Kind in Type_Kind then
14938 Init_Size_Align (N);
14942 end New_External_Entity;
14944 -------------------------
14945 -- New_Internal_Entity --
14946 -------------------------
14948 function New_Internal_Entity
14949 (Kind : Entity_Kind;
14950 Scope_Id : Entity_Id;
14951 Sloc_Value : Source_Ptr;
14952 Id_Char : Character) return Entity_Id
14954 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
14957 Set_Ekind (N, Kind);
14958 Set_Is_Internal (N, True);
14959 Append_Entity (N, Scope_Id);
14961 if Kind in Type_Kind then
14962 Init_Size_Align (N);
14966 end New_Internal_Entity;
14972 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
14976 -- If we are pointing at a positional parameter, it is a member of a
14977 -- node list (the list of parameters), and the next parameter is the
14978 -- next node on the list, unless we hit a parameter association, then
14979 -- we shift to using the chain whose head is the First_Named_Actual in
14980 -- the parent, and then is threaded using the Next_Named_Actual of the
14981 -- Parameter_Association. All this fiddling is because the original node
14982 -- list is in the textual call order, and what we need is the
14983 -- declaration order.
14985 if Is_List_Member (Actual_Id) then
14986 N := Next (Actual_Id);
14988 if Nkind (N) = N_Parameter_Association then
14989 return First_Named_Actual (Parent (Actual_Id));
14995 return Next_Named_Actual (Parent (Actual_Id));
14999 procedure Next_Actual (Actual_Id : in out Node_Id) is
15001 Actual_Id := Next_Actual (Actual_Id);
15004 -----------------------
15005 -- Normalize_Actuals --
15006 -----------------------
15008 -- Chain actuals according to formals of subprogram. If there are no named
15009 -- associations, the chain is simply the list of Parameter Associations,
15010 -- since the order is the same as the declaration order. If there are named
15011 -- associations, then the First_Named_Actual field in the N_Function_Call
15012 -- or N_Procedure_Call_Statement node points to the Parameter_Association
15013 -- node for the parameter that comes first in declaration order. The
15014 -- remaining named parameters are then chained in declaration order using
15015 -- Next_Named_Actual.
15017 -- This routine also verifies that the number of actuals is compatible with
15018 -- the number and default values of formals, but performs no type checking
15019 -- (type checking is done by the caller).
15021 -- If the matching succeeds, Success is set to True and the caller proceeds
15022 -- with type-checking. If the match is unsuccessful, then Success is set to
15023 -- False, and the caller attempts a different interpretation, if there is
15026 -- If the flag Report is on, the call is not overloaded, and a failure to
15027 -- match can be reported here, rather than in the caller.
15029 procedure Normalize_Actuals
15033 Success : out Boolean)
15035 Actuals : constant List_Id := Parameter_Associations (N);
15036 Actual : Node_Id := Empty;
15037 Formal : Entity_Id;
15038 Last : Node_Id := Empty;
15039 First_Named : Node_Id := Empty;
15042 Formals_To_Match : Integer := 0;
15043 Actuals_To_Match : Integer := 0;
15045 procedure Chain (A : Node_Id);
15046 -- Add named actual at the proper place in the list, using the
15047 -- Next_Named_Actual link.
15049 function Reporting return Boolean;
15050 -- Determines if an error is to be reported. To report an error, we
15051 -- need Report to be True, and also we do not report errors caused
15052 -- by calls to init procs that occur within other init procs. Such
15053 -- errors must always be cascaded errors, since if all the types are
15054 -- declared correctly, the compiler will certainly build decent calls.
15060 procedure Chain (A : Node_Id) is
15064 -- Call node points to first actual in list
15066 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
15069 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
15073 Set_Next_Named_Actual (Last, Empty);
15080 function Reporting return Boolean is
15085 elsif not Within_Init_Proc then
15088 elsif Is_Init_Proc (Entity (Name (N))) then
15096 -- Start of processing for Normalize_Actuals
15099 if Is_Access_Type (S) then
15101 -- The name in the call is a function call that returns an access
15102 -- to subprogram. The designated type has the list of formals.
15104 Formal := First_Formal (Designated_Type (S));
15106 Formal := First_Formal (S);
15109 while Present (Formal) loop
15110 Formals_To_Match := Formals_To_Match + 1;
15111 Next_Formal (Formal);
15114 -- Find if there is a named association, and verify that no positional
15115 -- associations appear after named ones.
15117 if Present (Actuals) then
15118 Actual := First (Actuals);
15121 while Present (Actual)
15122 and then Nkind (Actual) /= N_Parameter_Association
15124 Actuals_To_Match := Actuals_To_Match + 1;
15128 if No (Actual) and Actuals_To_Match = Formals_To_Match then
15130 -- Most common case: positional notation, no defaults
15135 elsif Actuals_To_Match > Formals_To_Match then
15137 -- Too many actuals: will not work
15140 if Is_Entity_Name (Name (N)) then
15141 Error_Msg_N ("too many arguments in call to&", Name (N));
15143 Error_Msg_N ("too many arguments in call", N);
15151 First_Named := Actual;
15153 while Present (Actual) loop
15154 if Nkind (Actual) /= N_Parameter_Association then
15156 ("positional parameters not allowed after named ones", Actual);
15161 Actuals_To_Match := Actuals_To_Match + 1;
15167 if Present (Actuals) then
15168 Actual := First (Actuals);
15171 Formal := First_Formal (S);
15172 while Present (Formal) loop
15174 -- Match the formals in order. If the corresponding actual is
15175 -- positional, nothing to do. Else scan the list of named actuals
15176 -- to find the one with the right name.
15178 if Present (Actual)
15179 and then Nkind (Actual) /= N_Parameter_Association
15182 Actuals_To_Match := Actuals_To_Match - 1;
15183 Formals_To_Match := Formals_To_Match - 1;
15186 -- For named parameters, search the list of actuals to find
15187 -- one that matches the next formal name.
15189 Actual := First_Named;
15191 while Present (Actual) loop
15192 if Chars (Selector_Name (Actual)) = Chars (Formal) then
15195 Actuals_To_Match := Actuals_To_Match - 1;
15196 Formals_To_Match := Formals_To_Match - 1;
15204 if Ekind (Formal) /= E_In_Parameter
15205 or else No (Default_Value (Formal))
15208 if (Comes_From_Source (S)
15209 or else Sloc (S) = Standard_Location)
15210 and then Is_Overloadable (S)
15214 Nkind_In (Parent (N), N_Procedure_Call_Statement,
15216 N_Parameter_Association)
15217 and then Ekind (S) /= E_Function
15219 Set_Etype (N, Etype (S));
15222 Error_Msg_Name_1 := Chars (S);
15223 Error_Msg_Sloc := Sloc (S);
15225 ("missing argument for parameter & "
15226 & "in call to % declared #", N, Formal);
15229 elsif Is_Overloadable (S) then
15230 Error_Msg_Name_1 := Chars (S);
15232 -- Point to type derivation that generated the
15235 Error_Msg_Sloc := Sloc (Parent (S));
15238 ("missing argument for parameter & "
15239 & "in call to % (inherited) #", N, Formal);
15243 ("missing argument for parameter &", N, Formal);
15251 Formals_To_Match := Formals_To_Match - 1;
15256 Next_Formal (Formal);
15259 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
15266 -- Find some superfluous named actual that did not get
15267 -- attached to the list of associations.
15269 Actual := First (Actuals);
15270 while Present (Actual) loop
15271 if Nkind (Actual) = N_Parameter_Association
15272 and then Actual /= Last
15273 and then No (Next_Named_Actual (Actual))
15275 Error_Msg_N ("unmatched actual & in call",
15276 Selector_Name (Actual));
15287 end Normalize_Actuals;
15289 --------------------------------
15290 -- Note_Possible_Modification --
15291 --------------------------------
15293 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
15294 Modification_Comes_From_Source : constant Boolean :=
15295 Comes_From_Source (Parent (N));
15301 -- Loop to find referenced entity, if there is one
15307 if Is_Entity_Name (Exp) then
15308 Ent := Entity (Exp);
15310 -- If the entity is missing, it is an undeclared identifier,
15311 -- and there is nothing to annotate.
15317 elsif Nkind (Exp) = N_Explicit_Dereference then
15319 P : constant Node_Id := Prefix (Exp);
15322 -- In formal verification mode, keep track of all reads and
15323 -- writes through explicit dereferences.
15325 if GNATprove_Mode then
15326 SPARK_Specific.Generate_Dereference (N, 'm');
15329 if Nkind (P) = N_Selected_Component
15330 and then Present (Entry_Formal (Entity (Selector_Name (P))))
15332 -- Case of a reference to an entry formal
15334 Ent := Entry_Formal (Entity (Selector_Name (P)));
15336 elsif Nkind (P) = N_Identifier
15337 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
15338 and then Present (Expression (Parent (Entity (P))))
15339 and then Nkind (Expression (Parent (Entity (P)))) =
15342 -- Case of a reference to a value on which side effects have
15345 Exp := Prefix (Expression (Parent (Entity (P))));
15353 elsif Nkind_In (Exp, N_Type_Conversion,
15354 N_Unchecked_Type_Conversion)
15356 Exp := Expression (Exp);
15359 elsif Nkind_In (Exp, N_Slice,
15360 N_Indexed_Component,
15361 N_Selected_Component)
15363 -- Special check, if the prefix is an access type, then return
15364 -- since we are modifying the thing pointed to, not the prefix.
15365 -- When we are expanding, most usually the prefix is replaced
15366 -- by an explicit dereference, and this test is not needed, but
15367 -- in some cases (notably -gnatc mode and generics) when we do
15368 -- not do full expansion, we need this special test.
15370 if Is_Access_Type (Etype (Prefix (Exp))) then
15373 -- Otherwise go to prefix and keep going
15376 Exp := Prefix (Exp);
15380 -- All other cases, not a modification
15386 -- Now look for entity being referenced
15388 if Present (Ent) then
15389 if Is_Object (Ent) then
15390 if Comes_From_Source (Exp)
15391 or else Modification_Comes_From_Source
15393 -- Give warning if pragma unmodified given and we are
15394 -- sure this is a modification.
15396 if Has_Pragma_Unmodified (Ent) and then Sure then
15397 Error_Msg_NE ("??pragma Unmodified given for &!", N, Ent);
15400 Set_Never_Set_In_Source (Ent, False);
15403 Set_Is_True_Constant (Ent, False);
15404 Set_Current_Value (Ent, Empty);
15405 Set_Is_Known_Null (Ent, False);
15407 if not Can_Never_Be_Null (Ent) then
15408 Set_Is_Known_Non_Null (Ent, False);
15411 -- Follow renaming chain
15413 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
15414 and then Present (Renamed_Object (Ent))
15416 Exp := Renamed_Object (Ent);
15418 -- If the entity is the loop variable in an iteration over
15419 -- a container, retrieve container expression to indicate
15420 -- possible modification.
15422 if Present (Related_Expression (Ent))
15423 and then Nkind (Parent (Related_Expression (Ent))) =
15424 N_Iterator_Specification
15426 Exp := Original_Node (Related_Expression (Ent));
15431 -- The expression may be the renaming of a subcomponent of an
15432 -- array or container. The assignment to the subcomponent is
15433 -- a modification of the container.
15435 elsif Comes_From_Source (Original_Node (Exp))
15436 and then Nkind_In (Original_Node (Exp), N_Selected_Component,
15437 N_Indexed_Component)
15439 Exp := Prefix (Original_Node (Exp));
15443 -- Generate a reference only if the assignment comes from
15444 -- source. This excludes, for example, calls to a dispatching
15445 -- assignment operation when the left-hand side is tagged. In
15446 -- GNATprove mode, we need those references also on generated
15447 -- code, as these are used to compute the local effects of
15450 if Modification_Comes_From_Source or GNATprove_Mode then
15451 Generate_Reference (Ent, Exp, 'm');
15453 -- If the target of the assignment is the bound variable
15454 -- in an iterator, indicate that the corresponding array
15455 -- or container is also modified.
15457 if Ada_Version >= Ada_2012
15458 and then Nkind (Parent (Ent)) = N_Iterator_Specification
15461 Domain : constant Node_Id := Name (Parent (Ent));
15464 -- TBD : in the full version of the construct, the
15465 -- domain of iteration can be given by an expression.
15467 if Is_Entity_Name (Domain) then
15468 Generate_Reference (Entity (Domain), Exp, 'm');
15469 Set_Is_True_Constant (Entity (Domain), False);
15470 Set_Never_Set_In_Source (Entity (Domain), False);
15476 Check_Nested_Access (Ent);
15481 -- If we are sure this is a modification from source, and we know
15482 -- this modifies a constant, then give an appropriate warning.
15484 if Overlays_Constant (Ent)
15485 and then (Modification_Comes_From_Source and Sure)
15488 A : constant Node_Id := Address_Clause (Ent);
15490 if Present (A) then
15492 Exp : constant Node_Id := Expression (A);
15494 if Nkind (Exp) = N_Attribute_Reference
15495 and then Attribute_Name (Exp) = Name_Address
15496 and then Is_Entity_Name (Prefix (Exp))
15498 Error_Msg_Sloc := Sloc (A);
15500 ("constant& may be modified via address "
15501 & "clause#??", N, Entity (Prefix (Exp)));
15514 end Note_Possible_Modification;
15516 -------------------------
15517 -- Object_Access_Level --
15518 -------------------------
15520 -- Returns the static accessibility level of the view denoted by Obj. Note
15521 -- that the value returned is the result of a call to Scope_Depth. Only
15522 -- scope depths associated with dynamic scopes can actually be returned.
15523 -- Since only relative levels matter for accessibility checking, the fact
15524 -- that the distance between successive levels of accessibility is not
15525 -- always one is immaterial (invariant: if level(E2) is deeper than
15526 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
15528 function Object_Access_Level (Obj : Node_Id) return Uint is
15529 function Is_Interface_Conversion (N : Node_Id) return Boolean;
15530 -- Determine whether N is a construct of the form
15531 -- Some_Type (Operand._tag'Address)
15532 -- This construct appears in the context of dispatching calls.
15534 function Reference_To (Obj : Node_Id) return Node_Id;
15535 -- An explicit dereference is created when removing side-effects from
15536 -- expressions for constraint checking purposes. In this case a local
15537 -- access type is created for it. The correct access level is that of
15538 -- the original source node. We detect this case by noting that the
15539 -- prefix of the dereference is created by an object declaration whose
15540 -- initial expression is a reference.
15542 -----------------------------
15543 -- Is_Interface_Conversion --
15544 -----------------------------
15546 function Is_Interface_Conversion (N : Node_Id) return Boolean is
15548 return Nkind (N) = N_Unchecked_Type_Conversion
15549 and then Nkind (Expression (N)) = N_Attribute_Reference
15550 and then Attribute_Name (Expression (N)) = Name_Address;
15551 end Is_Interface_Conversion;
15557 function Reference_To (Obj : Node_Id) return Node_Id is
15558 Pref : constant Node_Id := Prefix (Obj);
15560 if Is_Entity_Name (Pref)
15561 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
15562 and then Present (Expression (Parent (Entity (Pref))))
15563 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
15565 return (Prefix (Expression (Parent (Entity (Pref)))));
15575 -- Start of processing for Object_Access_Level
15578 if Nkind (Obj) = N_Defining_Identifier
15579 or else Is_Entity_Name (Obj)
15581 if Nkind (Obj) = N_Defining_Identifier then
15587 if Is_Prival (E) then
15588 E := Prival_Link (E);
15591 -- If E is a type then it denotes a current instance. For this case
15592 -- we add one to the normal accessibility level of the type to ensure
15593 -- that current instances are treated as always being deeper than
15594 -- than the level of any visible named access type (see 3.10.2(21)).
15596 if Is_Type (E) then
15597 return Type_Access_Level (E) + 1;
15599 elsif Present (Renamed_Object (E)) then
15600 return Object_Access_Level (Renamed_Object (E));
15602 -- Similarly, if E is a component of the current instance of a
15603 -- protected type, any instance of it is assumed to be at a deeper
15604 -- level than the type. For a protected object (whose type is an
15605 -- anonymous protected type) its components are at the same level
15606 -- as the type itself.
15608 elsif not Is_Overloadable (E)
15609 and then Ekind (Scope (E)) = E_Protected_Type
15610 and then Comes_From_Source (Scope (E))
15612 return Type_Access_Level (Scope (E)) + 1;
15615 -- Aliased formals take their access level from the point of call.
15616 -- This is smaller than the level of the subprogram itself.
15618 if Is_Formal (E) and then Is_Aliased (E) then
15619 return Type_Access_Level (Etype (E));
15622 return Scope_Depth (Enclosing_Dynamic_Scope (E));
15626 elsif Nkind (Obj) = N_Selected_Component then
15627 if Is_Access_Type (Etype (Prefix (Obj))) then
15628 return Type_Access_Level (Etype (Prefix (Obj)));
15630 return Object_Access_Level (Prefix (Obj));
15633 elsif Nkind (Obj) = N_Indexed_Component then
15634 if Is_Access_Type (Etype (Prefix (Obj))) then
15635 return Type_Access_Level (Etype (Prefix (Obj)));
15637 return Object_Access_Level (Prefix (Obj));
15640 elsif Nkind (Obj) = N_Explicit_Dereference then
15642 -- If the prefix is a selected access discriminant then we make a
15643 -- recursive call on the prefix, which will in turn check the level
15644 -- of the prefix object of the selected discriminant.
15646 -- In Ada 2012, if the discriminant has implicit dereference and
15647 -- the context is a selected component, treat this as an object of
15648 -- unknown scope (see below). This is necessary in compile-only mode;
15649 -- otherwise expansion will already have transformed the prefix into
15652 if Nkind (Prefix (Obj)) = N_Selected_Component
15653 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
15655 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
15657 (not Has_Implicit_Dereference
15658 (Entity (Selector_Name (Prefix (Obj))))
15659 or else Nkind (Parent (Obj)) /= N_Selected_Component)
15661 return Object_Access_Level (Prefix (Obj));
15663 -- Detect an interface conversion in the context of a dispatching
15664 -- call. Use the original form of the conversion to find the access
15665 -- level of the operand.
15667 elsif Is_Interface (Etype (Obj))
15668 and then Is_Interface_Conversion (Prefix (Obj))
15669 and then Nkind (Original_Node (Obj)) = N_Type_Conversion
15671 return Object_Access_Level (Original_Node (Obj));
15673 elsif not Comes_From_Source (Obj) then
15675 Ref : constant Node_Id := Reference_To (Obj);
15677 if Present (Ref) then
15678 return Object_Access_Level (Ref);
15680 return Type_Access_Level (Etype (Prefix (Obj)));
15685 return Type_Access_Level (Etype (Prefix (Obj)));
15688 elsif Nkind_In (Obj, N_Type_Conversion, N_Unchecked_Type_Conversion) then
15689 return Object_Access_Level (Expression (Obj));
15691 elsif Nkind (Obj) = N_Function_Call then
15693 -- Function results are objects, so we get either the access level of
15694 -- the function or, in the case of an indirect call, the level of the
15695 -- access-to-subprogram type. (This code is used for Ada 95, but it
15696 -- looks wrong, because it seems that we should be checking the level
15697 -- of the call itself, even for Ada 95. However, using the Ada 2005
15698 -- version of the code causes regressions in several tests that are
15699 -- compiled with -gnat95. ???)
15701 if Ada_Version < Ada_2005 then
15702 if Is_Entity_Name (Name (Obj)) then
15703 return Subprogram_Access_Level (Entity (Name (Obj)));
15705 return Type_Access_Level (Etype (Prefix (Name (Obj))));
15708 -- For Ada 2005, the level of the result object of a function call is
15709 -- defined to be the level of the call's innermost enclosing master.
15710 -- We determine that by querying the depth of the innermost enclosing
15714 Return_Master_Scope_Depth_Of_Call : declare
15716 function Innermost_Master_Scope_Depth
15717 (N : Node_Id) return Uint;
15718 -- Returns the scope depth of the given node's innermost
15719 -- enclosing dynamic scope (effectively the accessibility
15720 -- level of the innermost enclosing master).
15722 ----------------------------------
15723 -- Innermost_Master_Scope_Depth --
15724 ----------------------------------
15726 function Innermost_Master_Scope_Depth
15727 (N : Node_Id) return Uint
15729 Node_Par : Node_Id := Parent (N);
15732 -- Locate the nearest enclosing node (by traversing Parents)
15733 -- that Defining_Entity can be applied to, and return the
15734 -- depth of that entity's nearest enclosing dynamic scope.
15736 while Present (Node_Par) loop
15737 case Nkind (Node_Par) is
15738 when N_Component_Declaration |
15739 N_Entry_Declaration |
15740 N_Formal_Object_Declaration |
15741 N_Formal_Type_Declaration |
15742 N_Full_Type_Declaration |
15743 N_Incomplete_Type_Declaration |
15744 N_Loop_Parameter_Specification |
15745 N_Object_Declaration |
15746 N_Protected_Type_Declaration |
15747 N_Private_Extension_Declaration |
15748 N_Private_Type_Declaration |
15749 N_Subtype_Declaration |
15750 N_Function_Specification |
15751 N_Procedure_Specification |
15752 N_Task_Type_Declaration |
15754 N_Generic_Instantiation |
15756 N_Implicit_Label_Declaration |
15757 N_Package_Declaration |
15758 N_Single_Task_Declaration |
15759 N_Subprogram_Declaration |
15760 N_Generic_Declaration |
15761 N_Renaming_Declaration |
15762 N_Block_Statement |
15763 N_Formal_Subprogram_Declaration |
15764 N_Abstract_Subprogram_Declaration |
15766 N_Exception_Declaration |
15767 N_Formal_Package_Declaration |
15768 N_Number_Declaration |
15769 N_Package_Specification |
15770 N_Parameter_Specification |
15771 N_Single_Protected_Declaration |
15775 (Nearest_Dynamic_Scope
15776 (Defining_Entity (Node_Par)));
15782 Node_Par := Parent (Node_Par);
15785 pragma Assert (False);
15787 -- Should never reach the following return
15789 return Scope_Depth (Current_Scope) + 1;
15790 end Innermost_Master_Scope_Depth;
15792 -- Start of processing for Return_Master_Scope_Depth_Of_Call
15795 return Innermost_Master_Scope_Depth (Obj);
15796 end Return_Master_Scope_Depth_Of_Call;
15799 -- For convenience we handle qualified expressions, even though they
15800 -- aren't technically object names.
15802 elsif Nkind (Obj) = N_Qualified_Expression then
15803 return Object_Access_Level (Expression (Obj));
15805 -- Ditto for aggregates. They have the level of the temporary that
15806 -- will hold their value.
15808 elsif Nkind (Obj) = N_Aggregate then
15809 return Object_Access_Level (Current_Scope);
15811 -- Otherwise return the scope level of Standard. (If there are cases
15812 -- that fall through to this point they will be treated as having
15813 -- global accessibility for now. ???)
15816 return Scope_Depth (Standard_Standard);
15818 end Object_Access_Level;
15820 ---------------------------------
15821 -- Original_Aspect_Pragma_Name --
15822 ---------------------------------
15824 function Original_Aspect_Pragma_Name (N : Node_Id) return Name_Id is
15826 Item_Nam : Name_Id;
15829 pragma Assert (Nkind_In (N, N_Aspect_Specification, N_Pragma));
15833 -- The pragma was generated to emulate an aspect, use the original
15834 -- aspect specification.
15836 if Nkind (Item) = N_Pragma and then From_Aspect_Specification (Item) then
15837 Item := Corresponding_Aspect (Item);
15840 -- Retrieve the name of the aspect/pragma. Note that Pre, Pre_Class,
15841 -- Post and Post_Class rewrite their pragma identifier to preserve the
15843 -- ??? this is kludgey
15845 if Nkind (Item) = N_Pragma then
15846 Item_Nam := Chars (Original_Node (Pragma_Identifier (Item)));
15849 pragma Assert (Nkind (Item) = N_Aspect_Specification);
15850 Item_Nam := Chars (Identifier (Item));
15853 -- Deal with 'Class by converting the name to its _XXX form
15855 if Class_Present (Item) then
15856 if Item_Nam = Name_Invariant then
15857 Item_Nam := Name_uInvariant;
15859 elsif Item_Nam = Name_Post then
15860 Item_Nam := Name_uPost;
15862 elsif Item_Nam = Name_Pre then
15863 Item_Nam := Name_uPre;
15865 elsif Nam_In (Item_Nam, Name_Type_Invariant,
15866 Name_Type_Invariant_Class)
15868 Item_Nam := Name_uType_Invariant;
15870 -- Nothing to do for other cases (e.g. a Check that derived from
15871 -- Pre_Class and has the flag set). Also we do nothing if the name
15872 -- is already in special _xxx form.
15878 end Original_Aspect_Pragma_Name;
15880 --------------------------------------
15881 -- Original_Corresponding_Operation --
15882 --------------------------------------
15884 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
15886 Typ : constant Entity_Id := Find_Dispatching_Type (S);
15889 -- If S is an inherited primitive S2 the original corresponding
15890 -- operation of S is the original corresponding operation of S2
15892 if Present (Alias (S))
15893 and then Find_Dispatching_Type (Alias (S)) /= Typ
15895 return Original_Corresponding_Operation (Alias (S));
15897 -- If S overrides an inherited subprogram S2 the original corresponding
15898 -- operation of S is the original corresponding operation of S2
15900 elsif Present (Overridden_Operation (S)) then
15901 return Original_Corresponding_Operation (Overridden_Operation (S));
15903 -- otherwise it is S itself
15908 end Original_Corresponding_Operation;
15910 ----------------------
15911 -- Policy_In_Effect --
15912 ----------------------
15914 function Policy_In_Effect (Policy : Name_Id) return Name_Id is
15915 function Policy_In_List (List : Node_Id) return Name_Id;
15916 -- Determine the the mode of a policy in a N_Pragma list
15918 --------------------
15919 -- Policy_In_List --
15920 --------------------
15922 function Policy_In_List (List : Node_Id) return Name_Id is
15929 while Present (Prag) loop
15930 Arg := First (Pragma_Argument_Associations (Prag));
15931 Expr := Get_Pragma_Arg (Arg);
15933 -- The current Check_Policy pragma matches the requested policy,
15934 -- return the second argument which denotes the policy identifier.
15936 if Chars (Expr) = Policy then
15937 return Chars (Get_Pragma_Arg (Next (Arg)));
15940 Prag := Next_Pragma (Prag);
15944 end Policy_In_List;
15950 -- Start of processing for Policy_In_Effect
15953 if not Is_Valid_Assertion_Kind (Policy) then
15954 raise Program_Error;
15957 -- Inspect all policy pragmas that appear within scopes (if any)
15959 Kind := Policy_In_List (Check_Policy_List);
15961 -- Inspect all configuration policy pragmas (if any)
15963 if Kind = No_Name then
15964 Kind := Policy_In_List (Check_Policy_List_Config);
15967 -- The context lacks policy pragmas, determine the mode based on whether
15968 -- assertions are enabled at the configuration level. This ensures that
15969 -- the policy is preserved when analyzing generics.
15971 if Kind = No_Name then
15972 if Assertions_Enabled_Config then
15973 Kind := Name_Check;
15975 Kind := Name_Ignore;
15980 end Policy_In_Effect;
15982 ----------------------------------
15983 -- Predicate_Tests_On_Arguments --
15984 ----------------------------------
15986 function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean is
15988 -- Always test predicates on indirect call
15990 if Ekind (Subp) = E_Subprogram_Type then
15993 -- Do not test predicates on call to generated default Finalize, since
15994 -- we are not interested in whether something we are finalizing (and
15995 -- typically destroying) satisfies its predicates.
15997 elsif Chars (Subp) = Name_Finalize
15998 and then not Comes_From_Source (Subp)
16002 -- Do not test predicates on any internally generated routines
16004 elsif Is_Internal_Name (Chars (Subp)) then
16007 -- Do not test predicates on call to Init_Proc, since if needed the
16008 -- predicate test will occur at some other point.
16010 elsif Is_Init_Proc (Subp) then
16013 -- Do not test predicates on call to predicate function, since this
16014 -- would cause infinite recursion.
16016 elsif Ekind (Subp) = E_Function
16017 and then (Is_Predicate_Function (Subp)
16019 Is_Predicate_Function_M (Subp))
16023 -- For now, no other exceptions
16028 end Predicate_Tests_On_Arguments;
16030 -----------------------
16031 -- Private_Component --
16032 -----------------------
16034 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
16035 Ancestor : constant Entity_Id := Base_Type (Type_Id);
16037 function Trace_Components
16039 Check : Boolean) return Entity_Id;
16040 -- Recursive function that does the work, and checks against circular
16041 -- definition for each subcomponent type.
16043 ----------------------
16044 -- Trace_Components --
16045 ----------------------
16047 function Trace_Components
16049 Check : Boolean) return Entity_Id
16051 Btype : constant Entity_Id := Base_Type (T);
16052 Component : Entity_Id;
16054 Candidate : Entity_Id := Empty;
16057 if Check and then Btype = Ancestor then
16058 Error_Msg_N ("circular type definition", Type_Id);
16062 if Is_Private_Type (Btype) and then not Is_Generic_Type (Btype) then
16063 if Present (Full_View (Btype))
16064 and then Is_Record_Type (Full_View (Btype))
16065 and then not Is_Frozen (Btype)
16067 -- To indicate that the ancestor depends on a private type, the
16068 -- current Btype is sufficient. However, to check for circular
16069 -- definition we must recurse on the full view.
16071 Candidate := Trace_Components (Full_View (Btype), True);
16073 if Candidate = Any_Type then
16083 elsif Is_Array_Type (Btype) then
16084 return Trace_Components (Component_Type (Btype), True);
16086 elsif Is_Record_Type (Btype) then
16087 Component := First_Entity (Btype);
16088 while Present (Component)
16089 and then Comes_From_Source (Component)
16091 -- Skip anonymous types generated by constrained components
16093 if not Is_Type (Component) then
16094 P := Trace_Components (Etype (Component), True);
16096 if Present (P) then
16097 if P = Any_Type then
16105 Next_Entity (Component);
16113 end Trace_Components;
16115 -- Start of processing for Private_Component
16118 return Trace_Components (Type_Id, False);
16119 end Private_Component;
16121 ---------------------------
16122 -- Primitive_Names_Match --
16123 ---------------------------
16125 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
16127 function Non_Internal_Name (E : Entity_Id) return Name_Id;
16128 -- Given an internal name, returns the corresponding non-internal name
16130 ------------------------
16131 -- Non_Internal_Name --
16132 ------------------------
16134 function Non_Internal_Name (E : Entity_Id) return Name_Id is
16136 Get_Name_String (Chars (E));
16137 Name_Len := Name_Len - 1;
16139 end Non_Internal_Name;
16141 -- Start of processing for Primitive_Names_Match
16144 pragma Assert (Present (E1) and then Present (E2));
16146 return Chars (E1) = Chars (E2)
16148 (not Is_Internal_Name (Chars (E1))
16149 and then Is_Internal_Name (Chars (E2))
16150 and then Non_Internal_Name (E2) = Chars (E1))
16152 (not Is_Internal_Name (Chars (E2))
16153 and then Is_Internal_Name (Chars (E1))
16154 and then Non_Internal_Name (E1) = Chars (E2))
16156 (Is_Predefined_Dispatching_Operation (E1)
16157 and then Is_Predefined_Dispatching_Operation (E2)
16158 and then Same_TSS (E1, E2))
16160 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
16161 end Primitive_Names_Match;
16163 -----------------------
16164 -- Process_End_Label --
16165 -----------------------
16167 procedure Process_End_Label
16176 Label_Ref : Boolean;
16177 -- Set True if reference to end label itself is required
16180 -- Gets set to the operator symbol or identifier that references the
16181 -- entity Ent. For the child unit case, this is the identifier from the
16182 -- designator. For other cases, this is simply Endl.
16184 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
16185 -- N is an identifier node that appears as a parent unit reference in
16186 -- the case where Ent is a child unit. This procedure generates an
16187 -- appropriate cross-reference entry. E is the corresponding entity.
16189 -------------------------
16190 -- Generate_Parent_Ref --
16191 -------------------------
16193 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
16195 -- If names do not match, something weird, skip reference
16197 if Chars (E) = Chars (N) then
16199 -- Generate the reference. We do NOT consider this as a reference
16200 -- for unreferenced symbol purposes.
16202 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
16204 if Style_Check then
16205 Style.Check_Identifier (N, E);
16208 end Generate_Parent_Ref;
16210 -- Start of processing for Process_End_Label
16213 -- If no node, ignore. This happens in some error situations, and
16214 -- also for some internally generated structures where no end label
16215 -- references are required in any case.
16221 -- Nothing to do if no End_Label, happens for internally generated
16222 -- constructs where we don't want an end label reference anyway. Also
16223 -- nothing to do if Endl is a string literal, which means there was
16224 -- some prior error (bad operator symbol)
16226 Endl := End_Label (N);
16228 if No (Endl) or else Nkind (Endl) = N_String_Literal then
16232 -- Reference node is not in extended main source unit
16234 if not In_Extended_Main_Source_Unit (N) then
16236 -- Generally we do not collect references except for the extended
16237 -- main source unit. The one exception is the 'e' entry for a
16238 -- package spec, where it is useful for a client to have the
16239 -- ending information to define scopes.
16245 Label_Ref := False;
16247 -- For this case, we can ignore any parent references, but we
16248 -- need the package name itself for the 'e' entry.
16250 if Nkind (Endl) = N_Designator then
16251 Endl := Identifier (Endl);
16255 -- Reference is in extended main source unit
16260 -- For designator, generate references for the parent entries
16262 if Nkind (Endl) = N_Designator then
16264 -- Generate references for the prefix if the END line comes from
16265 -- source (otherwise we do not need these references) We climb the
16266 -- scope stack to find the expected entities.
16268 if Comes_From_Source (Endl) then
16269 Nam := Name (Endl);
16270 Scop := Current_Scope;
16271 while Nkind (Nam) = N_Selected_Component loop
16272 Scop := Scope (Scop);
16273 exit when No (Scop);
16274 Generate_Parent_Ref (Selector_Name (Nam), Scop);
16275 Nam := Prefix (Nam);
16278 if Present (Scop) then
16279 Generate_Parent_Ref (Nam, Scope (Scop));
16283 Endl := Identifier (Endl);
16287 -- If the end label is not for the given entity, then either we have
16288 -- some previous error, or this is a generic instantiation for which
16289 -- we do not need to make a cross-reference in this case anyway. In
16290 -- either case we simply ignore the call.
16292 if Chars (Ent) /= Chars (Endl) then
16296 -- If label was really there, then generate a normal reference and then
16297 -- adjust the location in the end label to point past the name (which
16298 -- should almost always be the semicolon).
16300 Loc := Sloc (Endl);
16302 if Comes_From_Source (Endl) then
16304 -- If a label reference is required, then do the style check and
16305 -- generate an l-type cross-reference entry for the label
16308 if Style_Check then
16309 Style.Check_Identifier (Endl, Ent);
16312 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
16315 -- Set the location to point past the label (normally this will
16316 -- mean the semicolon immediately following the label). This is
16317 -- done for the sake of the 'e' or 't' entry generated below.
16319 Get_Decoded_Name_String (Chars (Endl));
16320 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
16323 -- In SPARK mode, no missing label is allowed for packages and
16324 -- subprogram bodies. Detect those cases by testing whether
16325 -- Process_End_Label was called for a body (Typ = 't') or a package.
16327 if Restriction_Check_Required (SPARK_05)
16328 and then (Typ = 't' or else Ekind (Ent) = E_Package)
16330 Error_Msg_Node_1 := Endl;
16331 Check_SPARK_05_Restriction
16332 ("`END &` required", Endl, Force => True);
16336 -- Now generate the e/t reference
16338 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
16340 -- Restore Sloc, in case modified above, since we have an identifier
16341 -- and the normal Sloc should be left set in the tree.
16343 Set_Sloc (Endl, Loc);
16344 end Process_End_Label;
16350 function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
16351 Seen : Boolean := False;
16353 function Is_Reference (N : Node_Id) return Traverse_Result;
16354 -- Determine whether node N denotes a reference to Id. If this is the
16355 -- case, set global flag Seen to True and stop the traversal.
16361 function Is_Reference (N : Node_Id) return Traverse_Result is
16363 if Is_Entity_Name (N)
16364 and then Present (Entity (N))
16365 and then Entity (N) = Id
16374 procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
16376 -- Start of processing for Referenced
16379 Inspect_Expression (Expr);
16383 ------------------------------------
16384 -- References_Generic_Formal_Type --
16385 ------------------------------------
16387 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
16389 function Process (N : Node_Id) return Traverse_Result;
16390 -- Process one node in search for generic formal type
16396 function Process (N : Node_Id) return Traverse_Result is
16398 if Nkind (N) in N_Has_Entity then
16400 E : constant Entity_Id := Entity (N);
16402 if Present (E) then
16403 if Is_Generic_Type (E) then
16405 elsif Present (Etype (E))
16406 and then Is_Generic_Type (Etype (E))
16417 function Traverse is new Traverse_Func (Process);
16418 -- Traverse tree to look for generic type
16421 if Inside_A_Generic then
16422 return Traverse (N) = Abandon;
16426 end References_Generic_Formal_Type;
16428 --------------------
16429 -- Remove_Homonym --
16430 --------------------
16432 procedure Remove_Homonym (E : Entity_Id) is
16433 Prev : Entity_Id := Empty;
16437 if E = Current_Entity (E) then
16438 if Present (Homonym (E)) then
16439 Set_Current_Entity (Homonym (E));
16441 Set_Name_Entity_Id (Chars (E), Empty);
16445 H := Current_Entity (E);
16446 while Present (H) and then H /= E loop
16451 -- If E is not on the homonym chain, nothing to do
16453 if Present (H) then
16454 Set_Homonym (Prev, Homonym (E));
16457 end Remove_Homonym;
16459 ---------------------
16460 -- Rep_To_Pos_Flag --
16461 ---------------------
16463 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
16465 return New_Occurrence_Of
16466 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
16467 end Rep_To_Pos_Flag;
16469 --------------------
16470 -- Require_Entity --
16471 --------------------
16473 procedure Require_Entity (N : Node_Id) is
16475 if Is_Entity_Name (N) and then No (Entity (N)) then
16476 if Total_Errors_Detected /= 0 then
16477 Set_Entity (N, Any_Id);
16479 raise Program_Error;
16482 end Require_Entity;
16484 -------------------------------
16485 -- Requires_State_Refinement --
16486 -------------------------------
16488 function Requires_State_Refinement
16489 (Spec_Id : Entity_Id;
16490 Body_Id : Entity_Id) return Boolean
16492 function Mode_Is_Off (Prag : Node_Id) return Boolean;
16493 -- Given pragma SPARK_Mode, determine whether the mode is Off
16499 function Mode_Is_Off (Prag : Node_Id) return Boolean is
16503 -- The default SPARK mode is On
16509 Mode := Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
16511 -- Then the pragma lacks an argument, the default mode is On
16516 return Chars (Mode) = Name_Off;
16520 -- Start of processing for Requires_State_Refinement
16523 -- A package that does not define at least one abstract state cannot
16524 -- possibly require refinement.
16526 if No (Abstract_States (Spec_Id)) then
16529 -- The package instroduces a single null state which does not merit
16532 elsif Has_Null_Abstract_State (Spec_Id) then
16535 -- Check whether the package body is subject to pragma SPARK_Mode. If
16536 -- it is and the mode is Off, the package body is considered to be in
16537 -- regular Ada and does not require refinement.
16539 elsif Mode_Is_Off (SPARK_Pragma (Body_Id)) then
16542 -- The body's SPARK_Mode may be inherited from a similar pragma that
16543 -- appears in the private declarations of the spec. The pragma we are
16544 -- interested appears as the second entry in SPARK_Pragma.
16546 elsif Present (SPARK_Pragma (Spec_Id))
16547 and then Mode_Is_Off (Next_Pragma (SPARK_Pragma (Spec_Id)))
16551 -- The spec defines at least one abstract state and the body has no way
16552 -- of circumventing the refinement.
16557 end Requires_State_Refinement;
16559 ------------------------------
16560 -- Requires_Transient_Scope --
16561 ------------------------------
16563 -- A transient scope is required when variable-sized temporaries are
16564 -- allocated in the primary or secondary stack, or when finalization
16565 -- actions must be generated before the next instruction.
16567 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
16568 Typ : constant Entity_Id := Underlying_Type (Id);
16570 -- Start of processing for Requires_Transient_Scope
16573 -- This is a private type which is not completed yet. This can only
16574 -- happen in a default expression (of a formal parameter or of a
16575 -- record component). Do not expand transient scope in this case
16580 -- Do not expand transient scope for non-existent procedure return
16582 elsif Typ = Standard_Void_Type then
16585 -- Elementary types do not require a transient scope
16587 elsif Is_Elementary_Type (Typ) then
16590 -- Generally, indefinite subtypes require a transient scope, since the
16591 -- back end cannot generate temporaries, since this is not a valid type
16592 -- for declaring an object. It might be possible to relax this in the
16593 -- future, e.g. by declaring the maximum possible space for the type.
16595 elsif Is_Indefinite_Subtype (Typ) then
16598 -- Functions returning tagged types may dispatch on result so their
16599 -- returned value is allocated on the secondary stack. Controlled
16600 -- type temporaries need finalization.
16602 elsif Is_Tagged_Type (Typ)
16603 or else Has_Controlled_Component (Typ)
16605 return not Is_Value_Type (Typ);
16609 elsif Is_Record_Type (Typ) then
16613 Comp := First_Entity (Typ);
16614 while Present (Comp) loop
16615 if Ekind (Comp) = E_Component
16616 and then Requires_Transient_Scope (Etype (Comp))
16620 Next_Entity (Comp);
16627 -- String literal types never require transient scope
16629 elsif Ekind (Typ) = E_String_Literal_Subtype then
16632 -- Array type. Note that we already know that this is a constrained
16633 -- array, since unconstrained arrays will fail the indefinite test.
16635 elsif Is_Array_Type (Typ) then
16637 -- If component type requires a transient scope, the array does too
16639 if Requires_Transient_Scope (Component_Type (Typ)) then
16642 -- Otherwise, we only need a transient scope if the size depends on
16643 -- the value of one or more discriminants.
16646 return Size_Depends_On_Discriminant (Typ);
16649 -- All other cases do not require a transient scope
16654 end Requires_Transient_Scope;
16656 --------------------------
16657 -- Reset_Analyzed_Flags --
16658 --------------------------
16660 procedure Reset_Analyzed_Flags (N : Node_Id) is
16662 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
16663 -- Function used to reset Analyzed flags in tree. Note that we do
16664 -- not reset Analyzed flags in entities, since there is no need to
16665 -- reanalyze entities, and indeed, it is wrong to do so, since it
16666 -- can result in generating auxiliary stuff more than once.
16668 --------------------
16669 -- Clear_Analyzed --
16670 --------------------
16672 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
16674 if not Has_Extension (N) then
16675 Set_Analyzed (N, False);
16679 end Clear_Analyzed;
16681 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
16683 -- Start of processing for Reset_Analyzed_Flags
16686 Reset_Analyzed (N);
16687 end Reset_Analyzed_Flags;
16689 ------------------------
16690 -- Restore_SPARK_Mode --
16691 ------------------------
16693 procedure Restore_SPARK_Mode (Mode : SPARK_Mode_Type) is
16695 SPARK_Mode := Mode;
16696 end Restore_SPARK_Mode;
16698 --------------------------------
16699 -- Returns_Unconstrained_Type --
16700 --------------------------------
16702 function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
16704 return Ekind (Subp) = E_Function
16705 and then not Is_Scalar_Type (Etype (Subp))
16706 and then not Is_Access_Type (Etype (Subp))
16707 and then not Is_Constrained (Etype (Subp));
16708 end Returns_Unconstrained_Type;
16710 ----------------------------
16711 -- Root_Type_Of_Full_View --
16712 ----------------------------
16714 function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id is
16715 Rtyp : constant Entity_Id := Root_Type (T);
16718 -- The root type of the full view may itself be a private type. Keep
16719 -- looking for the ultimate derivation parent.
16721 if Is_Private_Type (Rtyp) and then Present (Full_View (Rtyp)) then
16722 return Root_Type_Of_Full_View (Full_View (Rtyp));
16726 end Root_Type_Of_Full_View;
16728 ---------------------------
16729 -- Safe_To_Capture_Value --
16730 ---------------------------
16732 function Safe_To_Capture_Value
16735 Cond : Boolean := False) return Boolean
16738 -- The only entities for which we track constant values are variables
16739 -- which are not renamings, constants, out parameters, and in out
16740 -- parameters, so check if we have this case.
16742 -- Note: it may seem odd to track constant values for constants, but in
16743 -- fact this routine is used for other purposes than simply capturing
16744 -- the value. In particular, the setting of Known[_Non]_Null.
16746 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
16748 Ekind_In (Ent, E_Constant, E_Out_Parameter, E_In_Out_Parameter)
16752 -- For conditionals, we also allow loop parameters and all formals,
16753 -- including in parameters.
16755 elsif Cond and then Ekind_In (Ent, E_Loop_Parameter, E_In_Parameter) then
16758 -- For all other cases, not just unsafe, but impossible to capture
16759 -- Current_Value, since the above are the only entities which have
16760 -- Current_Value fields.
16766 -- Skip if volatile or aliased, since funny things might be going on in
16767 -- these cases which we cannot necessarily track. Also skip any variable
16768 -- for which an address clause is given, or whose address is taken. Also
16769 -- never capture value of library level variables (an attempt to do so
16770 -- can occur in the case of package elaboration code).
16772 if Treat_As_Volatile (Ent)
16773 or else Is_Aliased (Ent)
16774 or else Present (Address_Clause (Ent))
16775 or else Address_Taken (Ent)
16776 or else (Is_Library_Level_Entity (Ent)
16777 and then Ekind (Ent) = E_Variable)
16782 -- OK, all above conditions are met. We also require that the scope of
16783 -- the reference be the same as the scope of the entity, not counting
16784 -- packages and blocks and loops.
16787 E_Scope : constant Entity_Id := Scope (Ent);
16788 R_Scope : Entity_Id;
16791 R_Scope := Current_Scope;
16792 while R_Scope /= Standard_Standard loop
16793 exit when R_Scope = E_Scope;
16795 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
16798 R_Scope := Scope (R_Scope);
16803 -- We also require that the reference does not appear in a context
16804 -- where it is not sure to be executed (i.e. a conditional context
16805 -- or an exception handler). We skip this if Cond is True, since the
16806 -- capturing of values from conditional tests handles this ok.
16819 -- Seems dubious that case expressions are not handled here ???
16822 while Present (P) loop
16823 if Nkind (P) = N_If_Statement
16824 or else Nkind (P) = N_Case_Statement
16825 or else (Nkind (P) in N_Short_Circuit
16826 and then Desc = Right_Opnd (P))
16827 or else (Nkind (P) = N_If_Expression
16828 and then Desc /= First (Expressions (P)))
16829 or else Nkind (P) = N_Exception_Handler
16830 or else Nkind (P) = N_Selective_Accept
16831 or else Nkind (P) = N_Conditional_Entry_Call
16832 or else Nkind (P) = N_Timed_Entry_Call
16833 or else Nkind (P) = N_Asynchronous_Select
16841 -- A special Ada 2012 case: the original node may be part
16842 -- of the else_actions of a conditional expression, in which
16843 -- case it might not have been expanded yet, and appears in
16844 -- a non-syntactic list of actions. In that case it is clearly
16845 -- not safe to save a value.
16848 and then Is_List_Member (Desc)
16849 and then No (Parent (List_Containing (Desc)))
16857 -- OK, looks safe to set value
16860 end Safe_To_Capture_Value;
16866 function Same_Name (N1, N2 : Node_Id) return Boolean is
16867 K1 : constant Node_Kind := Nkind (N1);
16868 K2 : constant Node_Kind := Nkind (N2);
16871 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
16872 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
16874 return Chars (N1) = Chars (N2);
16876 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
16877 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
16879 return Same_Name (Selector_Name (N1), Selector_Name (N2))
16880 and then Same_Name (Prefix (N1), Prefix (N2));
16891 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
16892 N1 : constant Node_Id := Original_Node (Node1);
16893 N2 : constant Node_Id := Original_Node (Node2);
16894 -- We do the tests on original nodes, since we are most interested
16895 -- in the original source, not any expansion that got in the way.
16897 K1 : constant Node_Kind := Nkind (N1);
16898 K2 : constant Node_Kind := Nkind (N2);
16901 -- First case, both are entities with same entity
16903 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
16905 EN1 : constant Entity_Id := Entity (N1);
16906 EN2 : constant Entity_Id := Entity (N2);
16908 if Present (EN1) and then Present (EN2)
16909 and then (Ekind_In (EN1, E_Variable, E_Constant)
16910 or else Is_Formal (EN1))
16918 -- Second case, selected component with same selector, same record
16920 if K1 = N_Selected_Component
16921 and then K2 = N_Selected_Component
16922 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
16924 return Same_Object (Prefix (N1), Prefix (N2));
16926 -- Third case, indexed component with same subscripts, same array
16928 elsif K1 = N_Indexed_Component
16929 and then K2 = N_Indexed_Component
16930 and then Same_Object (Prefix (N1), Prefix (N2))
16935 E1 := First (Expressions (N1));
16936 E2 := First (Expressions (N2));
16937 while Present (E1) loop
16938 if not Same_Value (E1, E2) then
16949 -- Fourth case, slice of same array with same bounds
16952 and then K2 = N_Slice
16953 and then Nkind (Discrete_Range (N1)) = N_Range
16954 and then Nkind (Discrete_Range (N2)) = N_Range
16955 and then Same_Value (Low_Bound (Discrete_Range (N1)),
16956 Low_Bound (Discrete_Range (N2)))
16957 and then Same_Value (High_Bound (Discrete_Range (N1)),
16958 High_Bound (Discrete_Range (N2)))
16960 return Same_Name (Prefix (N1), Prefix (N2));
16962 -- All other cases, not clearly the same object
16973 function Same_Type (T1, T2 : Entity_Id) return Boolean is
16978 elsif not Is_Constrained (T1)
16979 and then not Is_Constrained (T2)
16980 and then Base_Type (T1) = Base_Type (T2)
16984 -- For now don't bother with case of identical constraints, to be
16985 -- fiddled with later on perhaps (this is only used for optimization
16986 -- purposes, so it is not critical to do a best possible job)
16997 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
16999 if Compile_Time_Known_Value (Node1)
17000 and then Compile_Time_Known_Value (Node2)
17001 and then Expr_Value (Node1) = Expr_Value (Node2)
17004 elsif Same_Object (Node1, Node2) then
17011 -----------------------------
17012 -- Save_SPARK_Mode_And_Set --
17013 -----------------------------
17015 procedure Save_SPARK_Mode_And_Set
17016 (Context : Entity_Id;
17017 Mode : out SPARK_Mode_Type)
17020 -- Save the current mode in effect
17022 Mode := SPARK_Mode;
17024 -- Do not consider illegal or partially decorated constructs
17026 if Ekind (Context) = E_Void or else Error_Posted (Context) then
17029 elsif Present (SPARK_Pragma (Context)) then
17030 SPARK_Mode := Get_SPARK_Mode_From_Pragma (SPARK_Pragma (Context));
17032 end Save_SPARK_Mode_And_Set;
17034 -------------------------
17035 -- Scalar_Part_Present --
17036 -------------------------
17038 function Scalar_Part_Present (T : Entity_Id) return Boolean is
17042 if Is_Scalar_Type (T) then
17045 elsif Is_Array_Type (T) then
17046 return Scalar_Part_Present (Component_Type (T));
17048 elsif Is_Record_Type (T) or else Has_Discriminants (T) then
17049 C := First_Component_Or_Discriminant (T);
17050 while Present (C) loop
17051 if Scalar_Part_Present (Etype (C)) then
17054 Next_Component_Or_Discriminant (C);
17060 end Scalar_Part_Present;
17062 ------------------------
17063 -- Scope_Is_Transient --
17064 ------------------------
17066 function Scope_Is_Transient return Boolean is
17068 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
17069 end Scope_Is_Transient;
17075 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
17080 while Scop /= Standard_Standard loop
17081 Scop := Scope (Scop);
17083 if Scop = Scope2 then
17091 --------------------------
17092 -- Scope_Within_Or_Same --
17093 --------------------------
17095 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
17100 while Scop /= Standard_Standard loop
17101 if Scop = Scope2 then
17104 Scop := Scope (Scop);
17109 end Scope_Within_Or_Same;
17111 --------------------
17112 -- Set_Convention --
17113 --------------------
17115 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
17117 Basic_Set_Convention (E, Val);
17120 and then Is_Access_Subprogram_Type (Base_Type (E))
17121 and then Has_Foreign_Convention (E)
17124 -- A pragma Convention in an instance may apply to the subtype
17125 -- created for a formal, in which case we have already verified
17126 -- that conventions of actual and formal match and there is nothing
17127 -- to flag on the subtype.
17129 if In_Instance then
17132 Set_Can_Use_Internal_Rep (E, False);
17136 -- If E is an object or component, and the type of E is an anonymous
17137 -- access type with no convention set, then also set the convention of
17138 -- the anonymous access type. We do not do this for anonymous protected
17139 -- types, since protected types always have the default convention.
17141 if Present (Etype (E))
17142 and then (Is_Object (E)
17143 or else Ekind (E) = E_Component
17145 -- Allow E_Void (happens for pragma Convention appearing
17146 -- in the middle of a record applying to a component)
17148 or else Ekind (E) = E_Void)
17151 Typ : constant Entity_Id := Etype (E);
17154 if Ekind_In (Typ, E_Anonymous_Access_Type,
17155 E_Anonymous_Access_Subprogram_Type)
17156 and then not Has_Convention_Pragma (Typ)
17158 Basic_Set_Convention (Typ, Val);
17159 Set_Has_Convention_Pragma (Typ);
17161 -- And for the access subprogram type, deal similarly with the
17162 -- designated E_Subprogram_Type if it is also internal (which
17165 if Ekind (Typ) = E_Anonymous_Access_Subprogram_Type then
17167 Dtype : constant Entity_Id := Designated_Type (Typ);
17169 if Ekind (Dtype) = E_Subprogram_Type
17170 and then Is_Itype (Dtype)
17171 and then not Has_Convention_Pragma (Dtype)
17173 Basic_Set_Convention (Dtype, Val);
17174 Set_Has_Convention_Pragma (Dtype);
17181 end Set_Convention;
17183 ------------------------
17184 -- Set_Current_Entity --
17185 ------------------------
17187 -- The given entity is to be set as the currently visible definition of its
17188 -- associated name (i.e. the Node_Id associated with its name). All we have
17189 -- to do is to get the name from the identifier, and then set the
17190 -- associated Node_Id to point to the given entity.
17192 procedure Set_Current_Entity (E : Entity_Id) is
17194 Set_Name_Entity_Id (Chars (E), E);
17195 end Set_Current_Entity;
17197 ---------------------------
17198 -- Set_Debug_Info_Needed --
17199 ---------------------------
17201 procedure Set_Debug_Info_Needed (T : Entity_Id) is
17203 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
17204 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
17205 -- Used to set debug info in a related node if not set already
17207 --------------------------------------
17208 -- Set_Debug_Info_Needed_If_Not_Set --
17209 --------------------------------------
17211 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
17213 if Present (E) and then not Needs_Debug_Info (E) then
17214 Set_Debug_Info_Needed (E);
17216 -- For a private type, indicate that the full view also needs
17217 -- debug information.
17220 and then Is_Private_Type (E)
17221 and then Present (Full_View (E))
17223 Set_Debug_Info_Needed (Full_View (E));
17226 end Set_Debug_Info_Needed_If_Not_Set;
17228 -- Start of processing for Set_Debug_Info_Needed
17231 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
17232 -- indicates that Debug_Info_Needed is never required for the entity.
17233 -- Nothing to do if entity comes from a predefined file. Library files
17234 -- are compiled without debug information, but inlined bodies of these
17235 -- routines may appear in user code, and debug information on them ends
17236 -- up complicating debugging the user code.
17239 or else Debug_Info_Off (T)
17243 elsif In_Inlined_Body
17244 and then Is_Predefined_File_Name
17245 (Unit_File_Name (Get_Source_Unit (Sloc (T))))
17247 Set_Needs_Debug_Info (T, False);
17250 -- Set flag in entity itself. Note that we will go through the following
17251 -- circuitry even if the flag is already set on T. That's intentional,
17252 -- it makes sure that the flag will be set in subsidiary entities.
17254 Set_Needs_Debug_Info (T);
17256 -- Set flag on subsidiary entities if not set already
17258 if Is_Object (T) then
17259 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
17261 elsif Is_Type (T) then
17262 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
17264 if Is_Record_Type (T) then
17266 Ent : Entity_Id := First_Entity (T);
17268 while Present (Ent) loop
17269 Set_Debug_Info_Needed_If_Not_Set (Ent);
17274 -- For a class wide subtype, we also need debug information
17275 -- for the equivalent type.
17277 if Ekind (T) = E_Class_Wide_Subtype then
17278 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
17281 elsif Is_Array_Type (T) then
17282 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
17285 Indx : Node_Id := First_Index (T);
17287 while Present (Indx) loop
17288 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
17289 Indx := Next_Index (Indx);
17293 -- For a packed array type, we also need debug information for
17294 -- the type used to represent the packed array. Conversely, we
17295 -- also need it for the former if we need it for the latter.
17297 if Is_Packed (T) then
17298 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Impl_Type (T));
17301 if Is_Packed_Array_Impl_Type (T) then
17302 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
17305 elsif Is_Access_Type (T) then
17306 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
17308 elsif Is_Private_Type (T) then
17309 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
17311 elsif Is_Protected_Type (T) then
17312 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
17314 elsif Is_Scalar_Type (T) then
17316 -- If the subrange bounds are materialized by dedicated constant
17317 -- objects, also include them in the debug info to make sure the
17318 -- debugger can properly use them.
17320 if Present (Scalar_Range (T))
17321 and then Nkind (Scalar_Range (T)) = N_Range
17324 Low_Bnd : constant Node_Id := Type_Low_Bound (T);
17325 High_Bnd : constant Node_Id := Type_High_Bound (T);
17328 if Is_Entity_Name (Low_Bnd) then
17329 Set_Debug_Info_Needed_If_Not_Set (Entity (Low_Bnd));
17332 if Is_Entity_Name (High_Bnd) then
17333 Set_Debug_Info_Needed_If_Not_Set (Entity (High_Bnd));
17339 end Set_Debug_Info_Needed;
17341 ----------------------------
17342 -- Set_Entity_With_Checks --
17343 ----------------------------
17345 procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id) is
17346 Val_Actual : Entity_Id;
17348 Post_Node : Node_Id;
17351 -- Unconditionally set the entity
17353 Set_Entity (N, Val);
17355 -- The node to post on is the selector in the case of an expanded name,
17356 -- and otherwise the node itself.
17358 if Nkind (N) = N_Expanded_Name then
17359 Post_Node := Selector_Name (N);
17364 -- Check for violation of No_Fixed_IO
17366 if Restriction_Check_Required (No_Fixed_IO)
17368 ((RTU_Loaded (Ada_Text_IO)
17369 and then (Is_RTE (Val, RE_Decimal_IO)
17371 Is_RTE (Val, RE_Fixed_IO)))
17374 (RTU_Loaded (Ada_Wide_Text_IO)
17375 and then (Is_RTE (Val, RO_WT_Decimal_IO)
17377 Is_RTE (Val, RO_WT_Fixed_IO)))
17380 (RTU_Loaded (Ada_Wide_Wide_Text_IO)
17381 and then (Is_RTE (Val, RO_WW_Decimal_IO)
17383 Is_RTE (Val, RO_WW_Fixed_IO))))
17385 -- A special extra check, don't complain about a reference from within
17386 -- the Ada.Interrupts package itself!
17388 and then not In_Same_Extended_Unit (N, Val)
17390 Check_Restriction (No_Fixed_IO, Post_Node);
17393 -- Remaining checks are only done on source nodes. Note that we test
17394 -- for violation of No_Fixed_IO even on non-source nodes, because the
17395 -- cases for checking violations of this restriction are instantiations
17396 -- where the reference in the instance has Comes_From_Source False.
17398 if not Comes_From_Source (N) then
17402 -- Check for violation of No_Abort_Statements, which is triggered by
17403 -- call to Ada.Task_Identification.Abort_Task.
17405 if Restriction_Check_Required (No_Abort_Statements)
17406 and then (Is_RTE (Val, RE_Abort_Task))
17408 -- A special extra check, don't complain about a reference from within
17409 -- the Ada.Task_Identification package itself!
17411 and then not In_Same_Extended_Unit (N, Val)
17413 Check_Restriction (No_Abort_Statements, Post_Node);
17416 if Val = Standard_Long_Long_Integer then
17417 Check_Restriction (No_Long_Long_Integers, Post_Node);
17420 -- Check for violation of No_Dynamic_Attachment
17422 if Restriction_Check_Required (No_Dynamic_Attachment)
17423 and then RTU_Loaded (Ada_Interrupts)
17424 and then (Is_RTE (Val, RE_Is_Reserved) or else
17425 Is_RTE (Val, RE_Is_Attached) or else
17426 Is_RTE (Val, RE_Current_Handler) or else
17427 Is_RTE (Val, RE_Attach_Handler) or else
17428 Is_RTE (Val, RE_Exchange_Handler) or else
17429 Is_RTE (Val, RE_Detach_Handler) or else
17430 Is_RTE (Val, RE_Reference))
17432 -- A special extra check, don't complain about a reference from within
17433 -- the Ada.Interrupts package itself!
17435 and then not In_Same_Extended_Unit (N, Val)
17437 Check_Restriction (No_Dynamic_Attachment, Post_Node);
17440 -- Check for No_Implementation_Identifiers
17442 if Restriction_Check_Required (No_Implementation_Identifiers) then
17444 -- We have an implementation defined entity if it is marked as
17445 -- implementation defined, or is defined in a package marked as
17446 -- implementation defined. However, library packages themselves
17447 -- are excluded (we don't want to flag Interfaces itself, just
17448 -- the entities within it).
17450 if (Is_Implementation_Defined (Val)
17452 (Present (Scope (Val))
17453 and then Is_Implementation_Defined (Scope (Val))))
17454 and then not (Ekind_In (Val, E_Package, E_Generic_Package)
17455 and then Is_Library_Level_Entity (Val))
17457 Check_Restriction (No_Implementation_Identifiers, Post_Node);
17461 -- Do the style check
17464 and then not Suppress_Style_Checks (Val)
17465 and then not In_Instance
17467 if Nkind (N) = N_Identifier then
17469 elsif Nkind (N) = N_Expanded_Name then
17470 Nod := Selector_Name (N);
17475 -- A special situation arises for derived operations, where we want
17476 -- to do the check against the parent (since the Sloc of the derived
17477 -- operation points to the derived type declaration itself).
17480 while not Comes_From_Source (Val_Actual)
17481 and then Nkind (Val_Actual) in N_Entity
17482 and then (Ekind (Val_Actual) = E_Enumeration_Literal
17483 or else Is_Subprogram_Or_Generic_Subprogram (Val_Actual))
17484 and then Present (Alias (Val_Actual))
17486 Val_Actual := Alias (Val_Actual);
17489 -- Renaming declarations for generic actuals do not come from source,
17490 -- and have a different name from that of the entity they rename, so
17491 -- there is no style check to perform here.
17493 if Chars (Nod) = Chars (Val_Actual) then
17494 Style.Check_Identifier (Nod, Val_Actual);
17498 Set_Entity (N, Val);
17499 end Set_Entity_With_Checks;
17501 ------------------------
17502 -- Set_Name_Entity_Id --
17503 ------------------------
17505 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
17507 Set_Name_Table_Int (Id, Int (Val));
17508 end Set_Name_Entity_Id;
17510 ---------------------
17511 -- Set_Next_Actual --
17512 ---------------------
17514 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
17516 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
17517 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
17519 end Set_Next_Actual;
17521 ----------------------------------
17522 -- Set_Optimize_Alignment_Flags --
17523 ----------------------------------
17525 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
17527 if Optimize_Alignment = 'S' then
17528 Set_Optimize_Alignment_Space (E);
17529 elsif Optimize_Alignment = 'T' then
17530 Set_Optimize_Alignment_Time (E);
17532 end Set_Optimize_Alignment_Flags;
17534 -----------------------
17535 -- Set_Public_Status --
17536 -----------------------
17538 procedure Set_Public_Status (Id : Entity_Id) is
17539 S : constant Entity_Id := Current_Scope;
17541 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
17542 -- Determines if E is defined within handled statement sequence or
17543 -- an if statement, returns True if so, False otherwise.
17545 ----------------------
17546 -- Within_HSS_Or_If --
17547 ----------------------
17549 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
17552 N := Declaration_Node (E);
17559 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
17565 end Within_HSS_Or_If;
17567 -- Start of processing for Set_Public_Status
17570 -- Everything in the scope of Standard is public
17572 if S = Standard_Standard then
17573 Set_Is_Public (Id);
17575 -- Entity is definitely not public if enclosing scope is not public
17577 elsif not Is_Public (S) then
17580 -- An object or function declaration that occurs in a handled sequence
17581 -- of statements or within an if statement is the declaration for a
17582 -- temporary object or local subprogram generated by the expander. It
17583 -- never needs to be made public and furthermore, making it public can
17584 -- cause back end problems.
17586 elsif Nkind_In (Parent (Id), N_Object_Declaration,
17587 N_Function_Specification)
17588 and then Within_HSS_Or_If (Id)
17592 -- Entities in public packages or records are public
17594 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
17595 Set_Is_Public (Id);
17597 -- The bounds of an entry family declaration can generate object
17598 -- declarations that are visible to the back-end, e.g. in the
17599 -- the declaration of a composite type that contains tasks.
17601 elsif Is_Concurrent_Type (S)
17602 and then not Has_Completion (S)
17603 and then Nkind (Parent (Id)) = N_Object_Declaration
17605 Set_Is_Public (Id);
17607 end Set_Public_Status;
17609 -----------------------------
17610 -- Set_Referenced_Modified --
17611 -----------------------------
17613 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
17617 -- Deal with indexed or selected component where prefix is modified
17619 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
17620 Pref := Prefix (N);
17622 -- If prefix is access type, then it is the designated object that is
17623 -- being modified, which means we have no entity to set the flag on.
17625 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
17628 -- Otherwise chase the prefix
17631 Set_Referenced_Modified (Pref, Out_Param);
17634 -- Otherwise see if we have an entity name (only other case to process)
17636 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
17637 Set_Referenced_As_LHS (Entity (N), not Out_Param);
17638 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
17640 end Set_Referenced_Modified;
17642 ----------------------------
17643 -- Set_Scope_Is_Transient --
17644 ----------------------------
17646 procedure Set_Scope_Is_Transient (V : Boolean := True) is
17648 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
17649 end Set_Scope_Is_Transient;
17651 -------------------
17652 -- Set_Size_Info --
17653 -------------------
17655 procedure Set_Size_Info (T1, T2 : Entity_Id) is
17657 -- We copy Esize, but not RM_Size, since in general RM_Size is
17658 -- subtype specific and does not get inherited by all subtypes.
17660 Set_Esize (T1, Esize (T2));
17661 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
17663 if Is_Discrete_Or_Fixed_Point_Type (T1)
17665 Is_Discrete_Or_Fixed_Point_Type (T2)
17667 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
17670 Set_Alignment (T1, Alignment (T2));
17673 --------------------
17674 -- Static_Boolean --
17675 --------------------
17677 function Static_Boolean (N : Node_Id) return Uint is
17679 Analyze_And_Resolve (N, Standard_Boolean);
17682 or else Error_Posted (N)
17683 or else Etype (N) = Any_Type
17688 if Is_OK_Static_Expression (N) then
17689 if not Raises_Constraint_Error (N) then
17690 return Expr_Value (N);
17695 elsif Etype (N) = Any_Type then
17699 Flag_Non_Static_Expr
17700 ("static boolean expression required here", N);
17703 end Static_Boolean;
17705 --------------------
17706 -- Static_Integer --
17707 --------------------
17709 function Static_Integer (N : Node_Id) return Uint is
17711 Analyze_And_Resolve (N, Any_Integer);
17714 or else Error_Posted (N)
17715 or else Etype (N) = Any_Type
17720 if Is_OK_Static_Expression (N) then
17721 if not Raises_Constraint_Error (N) then
17722 return Expr_Value (N);
17727 elsif Etype (N) = Any_Type then
17731 Flag_Non_Static_Expr
17732 ("static integer expression required here", N);
17735 end Static_Integer;
17737 --------------------------
17738 -- Statically_Different --
17739 --------------------------
17741 function Statically_Different (E1, E2 : Node_Id) return Boolean is
17742 R1 : constant Node_Id := Get_Referenced_Object (E1);
17743 R2 : constant Node_Id := Get_Referenced_Object (E2);
17745 return Is_Entity_Name (R1)
17746 and then Is_Entity_Name (R2)
17747 and then Entity (R1) /= Entity (R2)
17748 and then not Is_Formal (Entity (R1))
17749 and then not Is_Formal (Entity (R2));
17750 end Statically_Different;
17752 --------------------------------------
17753 -- Subject_To_Loop_Entry_Attributes --
17754 --------------------------------------
17756 function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
17762 -- The expansion mechanism transform a loop subject to at least one
17763 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
17764 -- the conditional part.
17766 if Nkind_In (Stmt, N_Block_Statement, N_If_Statement)
17767 and then Nkind (Original_Node (N)) = N_Loop_Statement
17769 Stmt := Original_Node (N);
17773 Nkind (Stmt) = N_Loop_Statement
17774 and then Present (Identifier (Stmt))
17775 and then Present (Entity (Identifier (Stmt)))
17776 and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
17777 end Subject_To_Loop_Entry_Attributes;
17779 -----------------------------
17780 -- Subprogram_Access_Level --
17781 -----------------------------
17783 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
17785 if Present (Alias (Subp)) then
17786 return Subprogram_Access_Level (Alias (Subp));
17788 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
17790 end Subprogram_Access_Level;
17792 -------------------------------
17793 -- Support_Atomic_Primitives --
17794 -------------------------------
17796 function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
17800 -- Verify the alignment of Typ is known
17802 if not Known_Alignment (Typ) then
17806 if Known_Static_Esize (Typ) then
17807 Size := UI_To_Int (Esize (Typ));
17809 -- If the Esize (Object_Size) is unknown at compile time, look at the
17810 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
17812 elsif Known_Static_RM_Size (Typ) then
17813 Size := UI_To_Int (RM_Size (Typ));
17815 -- Otherwise, the size is considered to be unknown.
17821 -- Check that the size of the component is 8, 16, 32 or 64 bits and that
17822 -- Typ is properly aligned.
17825 when 8 | 16 | 32 | 64 =>
17826 return Size = UI_To_Int (Alignment (Typ)) * 8;
17830 end Support_Atomic_Primitives;
17836 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
17838 if Debug_Flag_W then
17839 for J in 0 .. Scope_Stack.Last loop
17844 Write_Name (Chars (E));
17845 Write_Str (" from ");
17846 Write_Location (Sloc (N));
17851 -----------------------
17852 -- Transfer_Entities --
17853 -----------------------
17855 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
17856 procedure Set_Public_Status_Of (Id : Entity_Id);
17857 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
17858 -- Set_Public_Status. If successfull and Id denotes a record type, set
17859 -- the Is_Public attribute of its fields.
17861 --------------------------
17862 -- Set_Public_Status_Of --
17863 --------------------------
17865 procedure Set_Public_Status_Of (Id : Entity_Id) is
17869 if not Is_Public (Id) then
17870 Set_Public_Status (Id);
17872 -- When the input entity is a public record type, ensure that all
17873 -- its internal fields are also exposed to the linker. The fields
17874 -- of a class-wide type are never made public.
17877 and then Is_Record_Type (Id)
17878 and then not Is_Class_Wide_Type (Id)
17880 Field := First_Entity (Id);
17881 while Present (Field) loop
17882 Set_Is_Public (Field);
17883 Next_Entity (Field);
17887 end Set_Public_Status_Of;
17891 Full_Id : Entity_Id;
17894 -- Start of processing for Transfer_Entities
17897 Id := First_Entity (From);
17899 if Present (Id) then
17901 -- Merge the entity chain of the source scope with that of the
17902 -- destination scope.
17904 if Present (Last_Entity (To)) then
17905 Set_Next_Entity (Last_Entity (To), Id);
17907 Set_First_Entity (To, Id);
17910 Set_Last_Entity (To, Last_Entity (From));
17912 -- Inspect the entities of the source scope and update their Scope
17915 while Present (Id) loop
17916 Set_Scope (Id, To);
17917 Set_Public_Status_Of (Id);
17919 -- Handle an internally generated full view for a private type
17921 if Is_Private_Type (Id)
17922 and then Present (Full_View (Id))
17923 and then Is_Itype (Full_View (Id))
17925 Full_Id := Full_View (Id);
17927 Set_Scope (Full_Id, To);
17928 Set_Public_Status_Of (Full_Id);
17934 Set_First_Entity (From, Empty);
17935 Set_Last_Entity (From, Empty);
17937 end Transfer_Entities;
17939 -----------------------
17940 -- Type_Access_Level --
17941 -----------------------
17943 function Type_Access_Level (Typ : Entity_Id) return Uint is
17947 Btyp := Base_Type (Typ);
17949 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
17950 -- simply use the level where the type is declared. This is true for
17951 -- stand-alone object declarations, and for anonymous access types
17952 -- associated with components the level is the same as that of the
17953 -- enclosing composite type. However, special treatment is needed for
17954 -- the cases of access parameters, return objects of an anonymous access
17955 -- type, and, in Ada 95, access discriminants of limited types.
17957 if Is_Access_Type (Btyp) then
17958 if Ekind (Btyp) = E_Anonymous_Access_Type then
17960 -- If the type is a nonlocal anonymous access type (such as for
17961 -- an access parameter) we treat it as being declared at the
17962 -- library level to ensure that names such as X.all'access don't
17963 -- fail static accessibility checks.
17965 if not Is_Local_Anonymous_Access (Typ) then
17966 return Scope_Depth (Standard_Standard);
17968 -- If this is a return object, the accessibility level is that of
17969 -- the result subtype of the enclosing function. The test here is
17970 -- little complicated, because we have to account for extended
17971 -- return statements that have been rewritten as blocks, in which
17972 -- case we have to find and the Is_Return_Object attribute of the
17973 -- itype's associated object. It would be nice to find a way to
17974 -- simplify this test, but it doesn't seem worthwhile to add a new
17975 -- flag just for purposes of this test. ???
17977 elsif Ekind (Scope (Btyp)) = E_Return_Statement
17980 and then Nkind (Associated_Node_For_Itype (Btyp)) =
17981 N_Object_Declaration
17982 and then Is_Return_Object
17983 (Defining_Identifier
17984 (Associated_Node_For_Itype (Btyp))))
17990 Scop := Scope (Scope (Btyp));
17991 while Present (Scop) loop
17992 exit when Ekind (Scop) = E_Function;
17993 Scop := Scope (Scop);
17996 -- Treat the return object's type as having the level of the
17997 -- function's result subtype (as per RM05-6.5(5.3/2)).
17999 return Type_Access_Level (Etype (Scop));
18004 Btyp := Root_Type (Btyp);
18006 -- The accessibility level of anonymous access types associated with
18007 -- discriminants is that of the current instance of the type, and
18008 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
18010 -- AI-402: access discriminants have accessibility based on the
18011 -- object rather than the type in Ada 2005, so the above paragraph
18014 -- ??? Needs completion with rules from AI-416
18016 if Ada_Version <= Ada_95
18017 and then Ekind (Typ) = E_Anonymous_Access_Type
18018 and then Present (Associated_Node_For_Itype (Typ))
18019 and then Nkind (Associated_Node_For_Itype (Typ)) =
18020 N_Discriminant_Specification
18022 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
18026 -- Return library level for a generic formal type. This is done because
18027 -- RM(10.3.2) says that "The statically deeper relationship does not
18028 -- apply to ... a descendant of a generic formal type". Rather than
18029 -- checking at each point where a static accessibility check is
18030 -- performed to see if we are dealing with a formal type, this rule is
18031 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
18032 -- return extreme values for a formal type; Deepest_Type_Access_Level
18033 -- returns Int'Last. By calling the appropriate function from among the
18034 -- two, we ensure that the static accessibility check will pass if we
18035 -- happen to run into a formal type. More specifically, we should call
18036 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
18037 -- call occurs as part of a static accessibility check and the error
18038 -- case is the case where the type's level is too shallow (as opposed
18041 if Is_Generic_Type (Root_Type (Btyp)) then
18042 return Scope_Depth (Standard_Standard);
18045 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
18046 end Type_Access_Level;
18048 ------------------------------------
18049 -- Type_Without_Stream_Operation --
18050 ------------------------------------
18052 function Type_Without_Stream_Operation
18054 Op : TSS_Name_Type := TSS_Null) return Entity_Id
18056 BT : constant Entity_Id := Base_Type (T);
18057 Op_Missing : Boolean;
18060 if not Restriction_Active (No_Default_Stream_Attributes) then
18064 if Is_Elementary_Type (T) then
18065 if Op = TSS_Null then
18067 No (TSS (BT, TSS_Stream_Read))
18068 or else No (TSS (BT, TSS_Stream_Write));
18071 Op_Missing := No (TSS (BT, Op));
18080 elsif Is_Array_Type (T) then
18081 return Type_Without_Stream_Operation (Component_Type (T), Op);
18083 elsif Is_Record_Type (T) then
18089 Comp := First_Component (T);
18090 while Present (Comp) loop
18091 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
18093 if Present (C_Typ) then
18097 Next_Component (Comp);
18103 elsif Is_Private_Type (T) and then Present (Full_View (T)) then
18104 return Type_Without_Stream_Operation (Full_View (T), Op);
18108 end Type_Without_Stream_Operation;
18110 ----------------------------
18111 -- Unique_Defining_Entity --
18112 ----------------------------
18114 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
18116 return Unique_Entity (Defining_Entity (N));
18117 end Unique_Defining_Entity;
18119 -------------------
18120 -- Unique_Entity --
18121 -------------------
18123 function Unique_Entity (E : Entity_Id) return Entity_Id is
18124 U : Entity_Id := E;
18130 if Present (Full_View (E)) then
18131 U := Full_View (E);
18135 if Present (Full_View (E)) then
18136 U := Full_View (E);
18139 when E_Package_Body =>
18142 if Nkind (P) = N_Defining_Program_Unit_Name then
18146 U := Corresponding_Spec (P);
18148 when E_Subprogram_Body =>
18151 if Nkind (P) = N_Defining_Program_Unit_Name then
18157 if Nkind (P) = N_Subprogram_Body_Stub then
18158 if Present (Library_Unit (P)) then
18160 -- Get to the function or procedure (generic) entity through
18161 -- the body entity.
18164 Unique_Entity (Defining_Entity (Get_Body_From_Stub (P)));
18167 U := Corresponding_Spec (P);
18170 when Formal_Kind =>
18171 if Present (Spec_Entity (E)) then
18172 U := Spec_Entity (E);
18186 function Unique_Name (E : Entity_Id) return String is
18188 -- Names of E_Subprogram_Body or E_Package_Body entities are not
18189 -- reliable, as they may not include the overloading suffix. Instead,
18190 -- when looking for the name of E or one of its enclosing scope, we get
18191 -- the name of the corresponding Unique_Entity.
18193 function Get_Scoped_Name (E : Entity_Id) return String;
18194 -- Return the name of E prefixed by all the names of the scopes to which
18195 -- E belongs, except for Standard.
18197 ---------------------
18198 -- Get_Scoped_Name --
18199 ---------------------
18201 function Get_Scoped_Name (E : Entity_Id) return String is
18202 Name : constant String := Get_Name_String (Chars (E));
18204 if Has_Fully_Qualified_Name (E)
18205 or else Scope (E) = Standard_Standard
18209 return Get_Scoped_Name (Unique_Entity (Scope (E))) & "__" & Name;
18211 end Get_Scoped_Name;
18213 -- Start of processing for Unique_Name
18216 if E = Standard_Standard then
18217 return Get_Name_String (Name_Standard);
18219 elsif Scope (E) = Standard_Standard
18220 and then not (Ekind (E) = E_Package or else Is_Subprogram (E))
18222 return Get_Name_String (Name_Standard) & "__" &
18223 Get_Name_String (Chars (E));
18225 elsif Ekind (E) = E_Enumeration_Literal then
18226 return Unique_Name (Etype (E)) & "__" & Get_Name_String (Chars (E));
18229 return Get_Scoped_Name (Unique_Entity (E));
18233 ---------------------
18234 -- Unit_Is_Visible --
18235 ---------------------
18237 function Unit_Is_Visible (U : Entity_Id) return Boolean is
18238 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
18239 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
18241 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
18242 -- For a child unit, check whether unit appears in a with_clause
18245 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
18246 -- Scan the context clause of one compilation unit looking for a
18247 -- with_clause for the unit in question.
18249 ----------------------------
18250 -- Unit_In_Parent_Context --
18251 ----------------------------
18253 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
18255 if Unit_In_Context (Par_Unit) then
18258 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
18259 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
18264 end Unit_In_Parent_Context;
18266 ---------------------
18267 -- Unit_In_Context --
18268 ---------------------
18270 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
18274 Clause := First (Context_Items (Comp_Unit));
18275 while Present (Clause) loop
18276 if Nkind (Clause) = N_With_Clause then
18277 if Library_Unit (Clause) = U then
18280 -- The with_clause may denote a renaming of the unit we are
18281 -- looking for, eg. Text_IO which renames Ada.Text_IO.
18284 Renamed_Entity (Entity (Name (Clause))) =
18285 Defining_Entity (Unit (U))
18295 end Unit_In_Context;
18297 -- Start of processing for Unit_Is_Visible
18300 -- The currrent unit is directly visible
18305 elsif Unit_In_Context (Curr) then
18308 -- If the current unit is a body, check the context of the spec
18310 elsif Nkind (Unit (Curr)) = N_Package_Body
18312 (Nkind (Unit (Curr)) = N_Subprogram_Body
18313 and then not Acts_As_Spec (Unit (Curr)))
18315 if Unit_In_Context (Library_Unit (Curr)) then
18320 -- If the spec is a child unit, examine the parents
18322 if Is_Child_Unit (Curr_Entity) then
18323 if Nkind (Unit (Curr)) in N_Unit_Body then
18325 Unit_In_Parent_Context
18326 (Parent_Spec (Unit (Library_Unit (Curr))));
18328 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
18334 end Unit_Is_Visible;
18336 ------------------------------
18337 -- Universal_Interpretation --
18338 ------------------------------
18340 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
18341 Index : Interp_Index;
18345 -- The argument may be a formal parameter of an operator or subprogram
18346 -- with multiple interpretations, or else an expression for an actual.
18348 if Nkind (Opnd) = N_Defining_Identifier
18349 or else not Is_Overloaded (Opnd)
18351 if Etype (Opnd) = Universal_Integer
18352 or else Etype (Opnd) = Universal_Real
18354 return Etype (Opnd);
18360 Get_First_Interp (Opnd, Index, It);
18361 while Present (It.Typ) loop
18362 if It.Typ = Universal_Integer
18363 or else It.Typ = Universal_Real
18368 Get_Next_Interp (Index, It);
18373 end Universal_Interpretation;
18379 function Unqualify (Expr : Node_Id) return Node_Id is
18381 -- Recurse to handle unlikely case of multiple levels of qualification
18383 if Nkind (Expr) = N_Qualified_Expression then
18384 return Unqualify (Expression (Expr));
18386 -- Normal case, not a qualified expression
18393 -----------------------
18394 -- Visible_Ancestors --
18395 -----------------------
18397 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
18403 pragma Assert (Is_Record_Type (Typ) and then Is_Tagged_Type (Typ));
18405 -- Collect all the parents and progenitors of Typ. If the full-view of
18406 -- private parents and progenitors is available then it is used to
18407 -- generate the list of visible ancestors; otherwise their partial
18408 -- view is added to the resulting list.
18413 Use_Full_View => True);
18417 Ifaces_List => List_2,
18418 Exclude_Parents => True,
18419 Use_Full_View => True);
18421 -- Join the two lists. Avoid duplications because an interface may
18422 -- simultaneously be parent and progenitor of a type.
18424 Elmt := First_Elmt (List_2);
18425 while Present (Elmt) loop
18426 Append_Unique_Elmt (Node (Elmt), List_1);
18431 end Visible_Ancestors;
18433 ----------------------
18434 -- Within_Init_Proc --
18435 ----------------------
18437 function Within_Init_Proc return Boolean is
18441 S := Current_Scope;
18442 while not Is_Overloadable (S) loop
18443 if S = Standard_Standard then
18450 return Is_Init_Proc (S);
18451 end Within_Init_Proc;
18457 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
18464 elsif SE = Standard_Standard then
18476 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
18477 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
18478 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
18480 Matching_Field : Entity_Id;
18481 -- Entity to give a more precise suggestion on how to write a one-
18482 -- element positional aggregate.
18484 function Has_One_Matching_Field return Boolean;
18485 -- Determines if Expec_Type is a record type with a single component or
18486 -- discriminant whose type matches the found type or is one dimensional
18487 -- array whose component type matches the found type. In the case of
18488 -- one discriminant, we ignore the variant parts. That's not accurate,
18489 -- but good enough for the warning.
18491 ----------------------------
18492 -- Has_One_Matching_Field --
18493 ----------------------------
18495 function Has_One_Matching_Field return Boolean is
18499 Matching_Field := Empty;
18501 if Is_Array_Type (Expec_Type)
18502 and then Number_Dimensions (Expec_Type) = 1
18503 and then Covers (Etype (Component_Type (Expec_Type)), Found_Type)
18505 -- Use type name if available. This excludes multidimensional
18506 -- arrays and anonymous arrays.
18508 if Comes_From_Source (Expec_Type) then
18509 Matching_Field := Expec_Type;
18511 -- For an assignment, use name of target
18513 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
18514 and then Is_Entity_Name (Name (Parent (Expr)))
18516 Matching_Field := Entity (Name (Parent (Expr)));
18521 elsif not Is_Record_Type (Expec_Type) then
18525 E := First_Entity (Expec_Type);
18530 elsif not Ekind_In (E, E_Discriminant, E_Component)
18531 or else Nam_In (Chars (E), Name_uTag, Name_uParent)
18540 if not Covers (Etype (E), Found_Type) then
18543 elsif Present (Next_Entity (E))
18544 and then (Ekind (E) = E_Component
18545 or else Ekind (Next_Entity (E)) = E_Discriminant)
18550 Matching_Field := E;
18554 end Has_One_Matching_Field;
18556 -- Start of processing for Wrong_Type
18559 -- Don't output message if either type is Any_Type, or if a message
18560 -- has already been posted for this node. We need to do the latter
18561 -- check explicitly (it is ordinarily done in Errout), because we
18562 -- are using ! to force the output of the error messages.
18564 if Expec_Type = Any_Type
18565 or else Found_Type = Any_Type
18566 or else Error_Posted (Expr)
18570 -- If one of the types is a Taft-Amendment type and the other it its
18571 -- completion, it must be an illegal use of a TAT in the spec, for
18572 -- which an error was already emitted. Avoid cascaded errors.
18574 elsif Is_Incomplete_Type (Expec_Type)
18575 and then Has_Completion_In_Body (Expec_Type)
18576 and then Full_View (Expec_Type) = Etype (Expr)
18580 elsif Is_Incomplete_Type (Etype (Expr))
18581 and then Has_Completion_In_Body (Etype (Expr))
18582 and then Full_View (Etype (Expr)) = Expec_Type
18586 -- In an instance, there is an ongoing problem with completion of
18587 -- type derived from private types. Their structure is what Gigi
18588 -- expects, but the Etype is the parent type rather than the
18589 -- derived private type itself. Do not flag error in this case. The
18590 -- private completion is an entity without a parent, like an Itype.
18591 -- Similarly, full and partial views may be incorrect in the instance.
18592 -- There is no simple way to insure that it is consistent ???
18594 -- A similar view discrepancy can happen in an inlined body, for the
18595 -- same reason: inserted body may be outside of the original package
18596 -- and only partial views are visible at the point of insertion.
18598 elsif In_Instance or else In_Inlined_Body then
18599 if Etype (Etype (Expr)) = Etype (Expected_Type)
18601 (Has_Private_Declaration (Expected_Type)
18602 or else Has_Private_Declaration (Etype (Expr)))
18603 and then No (Parent (Expected_Type))
18607 elsif Nkind (Parent (Expr)) = N_Qualified_Expression
18608 and then Entity (Subtype_Mark (Parent (Expr))) = Expected_Type
18612 elsif Is_Private_Type (Expected_Type)
18613 and then Present (Full_View (Expected_Type))
18614 and then Covers (Full_View (Expected_Type), Etype (Expr))
18620 -- An interesting special check. If the expression is parenthesized
18621 -- and its type corresponds to the type of the sole component of the
18622 -- expected record type, or to the component type of the expected one
18623 -- dimensional array type, then assume we have a bad aggregate attempt.
18625 if Nkind (Expr) in N_Subexpr
18626 and then Paren_Count (Expr) /= 0
18627 and then Has_One_Matching_Field
18629 Error_Msg_N ("positional aggregate cannot have one component", Expr);
18630 if Present (Matching_Field) then
18631 if Is_Array_Type (Expec_Type) then
18633 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
18637 ("\write instead `& ='> ...`", Expr, Matching_Field);
18641 -- Another special check, if we are looking for a pool-specific access
18642 -- type and we found an E_Access_Attribute_Type, then we have the case
18643 -- of an Access attribute being used in a context which needs a pool-
18644 -- specific type, which is never allowed. The one extra check we make
18645 -- is that the expected designated type covers the Found_Type.
18647 elsif Is_Access_Type (Expec_Type)
18648 and then Ekind (Found_Type) = E_Access_Attribute_Type
18649 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
18650 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
18652 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
18654 Error_Msg_N -- CODEFIX
18655 ("result must be general access type!", Expr);
18656 Error_Msg_NE -- CODEFIX
18657 ("add ALL to }!", Expr, Expec_Type);
18659 -- Another special check, if the expected type is an integer type,
18660 -- but the expression is of type System.Address, and the parent is
18661 -- an addition or subtraction operation whose left operand is the
18662 -- expression in question and whose right operand is of an integral
18663 -- type, then this is an attempt at address arithmetic, so give
18664 -- appropriate message.
18666 elsif Is_Integer_Type (Expec_Type)
18667 and then Is_RTE (Found_Type, RE_Address)
18668 and then Nkind_In (Parent (Expr), N_Op_Add, N_Op_Subtract)
18669 and then Expr = Left_Opnd (Parent (Expr))
18670 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
18673 ("address arithmetic not predefined in package System",
18676 ("\possible missing with/use of System.Storage_Elements",
18680 -- If the expected type is an anonymous access type, as for access
18681 -- parameters and discriminants, the error is on the designated types.
18683 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
18684 if Comes_From_Source (Expec_Type) then
18685 Error_Msg_NE ("expected}!", Expr, Expec_Type);
18688 ("expected an access type with designated}",
18689 Expr, Designated_Type (Expec_Type));
18692 if Is_Access_Type (Found_Type)
18693 and then not Comes_From_Source (Found_Type)
18696 ("\\found an access type with designated}!",
18697 Expr, Designated_Type (Found_Type));
18699 if From_Limited_With (Found_Type) then
18700 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
18701 Error_Msg_Qual_Level := 99;
18702 Error_Msg_NE -- CODEFIX
18703 ("\\missing `WITH &;", Expr, Scope (Found_Type));
18704 Error_Msg_Qual_Level := 0;
18706 Error_Msg_NE ("found}!", Expr, Found_Type);
18710 -- Normal case of one type found, some other type expected
18713 -- If the names of the two types are the same, see if some number
18714 -- of levels of qualification will help. Don't try more than three
18715 -- levels, and if we get to standard, it's no use (and probably
18716 -- represents an error in the compiler) Also do not bother with
18717 -- internal scope names.
18720 Expec_Scope : Entity_Id;
18721 Found_Scope : Entity_Id;
18724 Expec_Scope := Expec_Type;
18725 Found_Scope := Found_Type;
18727 for Levels in Int range 0 .. 3 loop
18728 if Chars (Expec_Scope) /= Chars (Found_Scope) then
18729 Error_Msg_Qual_Level := Levels;
18733 Expec_Scope := Scope (Expec_Scope);
18734 Found_Scope := Scope (Found_Scope);
18736 exit when Expec_Scope = Standard_Standard
18737 or else Found_Scope = Standard_Standard
18738 or else not Comes_From_Source (Expec_Scope)
18739 or else not Comes_From_Source (Found_Scope);
18743 if Is_Record_Type (Expec_Type)
18744 and then Present (Corresponding_Remote_Type (Expec_Type))
18746 Error_Msg_NE ("expected}!", Expr,
18747 Corresponding_Remote_Type (Expec_Type));
18749 Error_Msg_NE ("expected}!", Expr, Expec_Type);
18752 if Is_Entity_Name (Expr)
18753 and then Is_Package_Or_Generic_Package (Entity (Expr))
18755 Error_Msg_N ("\\found package name!", Expr);
18757 elsif Is_Entity_Name (Expr)
18758 and then Ekind_In (Entity (Expr), E_Procedure, E_Generic_Procedure)
18760 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
18762 ("found procedure name, possibly missing Access attribute!",
18766 ("\\found procedure name instead of function!", Expr);
18769 elsif Nkind (Expr) = N_Function_Call
18770 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
18771 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
18772 and then No (Parameter_Associations (Expr))
18775 ("found function name, possibly missing Access attribute!",
18778 -- Catch common error: a prefix or infix operator which is not
18779 -- directly visible because the type isn't.
18781 elsif Nkind (Expr) in N_Op
18782 and then Is_Overloaded (Expr)
18783 and then not Is_Immediately_Visible (Expec_Type)
18784 and then not Is_Potentially_Use_Visible (Expec_Type)
18785 and then not In_Use (Expec_Type)
18786 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
18789 ("operator of the type is not directly visible!", Expr);
18791 elsif Ekind (Found_Type) = E_Void
18792 and then Present (Parent (Found_Type))
18793 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
18795 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
18798 Error_Msg_NE ("\\found}!", Expr, Found_Type);
18801 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
18802 -- of the same modular type, and (M1 and M2) = 0 was intended.
18804 if Expec_Type = Standard_Boolean
18805 and then Is_Modular_Integer_Type (Found_Type)
18806 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
18807 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
18810 Op : constant Node_Id := Right_Opnd (Parent (Expr));
18811 L : constant Node_Id := Left_Opnd (Op);
18812 R : constant Node_Id := Right_Opnd (Op);
18815 -- The case for the message is when the left operand of the
18816 -- comparison is the same modular type, or when it is an
18817 -- integer literal (or other universal integer expression),
18818 -- which would have been typed as the modular type if the
18819 -- parens had been there.
18821 if (Etype (L) = Found_Type
18823 Etype (L) = Universal_Integer)
18824 and then Is_Integer_Type (Etype (R))
18827 ("\\possible missing parens for modular operation", Expr);
18832 -- Reset error message qualification indication
18834 Error_Msg_Qual_Level := 0;