1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2011, 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 Atree; use Atree;
27 with Casing; use Casing;
28 with Checks; use Checks;
29 with Debug; use Debug;
30 with Errout; use Errout;
31 with Elists; use Elists;
32 with Exp_Ch11; use Exp_Ch11;
33 with Exp_Disp; use Exp_Disp;
34 with Exp_Tss; use Exp_Tss;
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 Nlists; use Nlists;
41 with Output; use Output;
43 with Restrict; use Restrict;
44 with Rident; use Rident;
45 with Rtsfind; use Rtsfind;
47 with Sem_Aux; use Sem_Aux;
48 with Sem_Attr; use Sem_Attr;
49 with Sem_Ch8; use Sem_Ch8;
50 with Sem_Disp; use Sem_Disp;
51 with Sem_Eval; use Sem_Eval;
52 with Sem_Res; use Sem_Res;
53 with Sem_Type; use Sem_Type;
54 with Sinfo; use Sinfo;
55 with Sinput; use Sinput;
56 with Stand; use Stand;
58 with Stringt; use Stringt;
60 with Targparm; use Targparm;
61 with Tbuild; use Tbuild;
62 with Ttypes; use Ttypes;
63 with Uname; use Uname;
65 with GNAT.HTable; use GNAT.HTable;
67 package body Sem_Util is
69 ----------------------------------------
70 -- Global_Variables for New_Copy_Tree --
71 ----------------------------------------
73 -- These global variables are used by New_Copy_Tree. See description
74 -- of the body of this subprogram for details. Global variables can be
75 -- safely used by New_Copy_Tree, since there is no case of a recursive
76 -- call from the processing inside New_Copy_Tree.
78 NCT_Hash_Threshold : constant := 20;
79 -- If there are more than this number of pairs of entries in the
80 -- map, then Hash_Tables_Used will be set, and the hash tables will
81 -- be initialized and used for the searches.
83 NCT_Hash_Tables_Used : Boolean := False;
84 -- Set to True if hash tables are in use
86 NCT_Table_Entries : Nat;
87 -- Count entries in table to see if threshold is reached
89 NCT_Hash_Table_Setup : Boolean := False;
90 -- Set to True if hash table contains data. We set this True if we
91 -- setup the hash table with data, and leave it set permanently
92 -- from then on, this is a signal that second and subsequent users
93 -- of the hash table must clear the old entries before reuse.
95 subtype NCT_Header_Num is Int range 0 .. 511;
96 -- Defines range of headers in hash tables (512 headers)
98 ----------------------------------
99 -- Order Dependence (AI05-0144) --
100 ----------------------------------
102 -- Each actual in a call is entered into the table below. A flag indicates
103 -- whether the corresponding formal is OUT or IN OUT. Each top-level call
104 -- (procedure call, condition, assignment) examines all the actuals for a
105 -- possible order dependence. The table is reset after each such check.
106 -- The actuals to be checked in a call to Check_Order_Dependence are at
107 -- positions 1 .. Last.
109 type Actual_Name is record
111 Is_Writable : Boolean;
114 package Actuals_In_Call is new Table.Table (
115 Table_Component_Type => Actual_Name,
116 Table_Index_Type => Int,
117 Table_Low_Bound => 0,
119 Table_Increment => 100,
120 Table_Name => "Actuals");
122 -----------------------
123 -- Local Subprograms --
124 -----------------------
126 function Build_Component_Subtype
129 T : Entity_Id) return Node_Id;
130 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
131 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
132 -- Loc is the source location, T is the original subtype.
134 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
135 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
136 -- with discriminants whose default values are static, examine only the
137 -- components in the selected variant to determine whether all of them
140 function Has_Null_Extension (T : Entity_Id) return Boolean;
141 -- T is a derived tagged type. Check whether the type extension is null.
142 -- If the parent type is fully initialized, T can be treated as such.
144 ------------------------------
145 -- Abstract_Interface_List --
146 ------------------------------
148 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
152 if Is_Concurrent_Type (Typ) then
154 -- If we are dealing with a synchronized subtype, go to the base
155 -- type, whose declaration has the interface list.
157 -- Shouldn't this be Declaration_Node???
159 Nod := Parent (Base_Type (Typ));
161 if Nkind (Nod) = N_Full_Type_Declaration then
165 elsif Ekind (Typ) = E_Record_Type_With_Private then
166 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
167 Nod := Type_Definition (Parent (Typ));
169 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
170 if Present (Full_View (Typ))
171 and then Nkind (Parent (Full_View (Typ)))
172 = N_Full_Type_Declaration
174 Nod := Type_Definition (Parent (Full_View (Typ)));
176 -- If the full-view is not available we cannot do anything else
177 -- here (the source has errors).
183 -- Support for generic formals with interfaces is still missing ???
185 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
190 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
194 elsif Ekind (Typ) = E_Record_Subtype then
195 Nod := Type_Definition (Parent (Etype (Typ)));
197 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
199 -- Recurse, because parent may still be a private extension. Also
200 -- note that the full view of the subtype or the full view of its
201 -- base type may (both) be unavailable.
203 return Abstract_Interface_List (Etype (Typ));
205 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
206 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
207 Nod := Formal_Type_Definition (Parent (Typ));
209 Nod := Type_Definition (Parent (Typ));
213 return Interface_List (Nod);
214 end Abstract_Interface_List;
216 --------------------------------
217 -- Add_Access_Type_To_Process --
218 --------------------------------
220 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
224 Ensure_Freeze_Node (E);
225 L := Access_Types_To_Process (Freeze_Node (E));
229 Set_Access_Types_To_Process (Freeze_Node (E), L);
233 end Add_Access_Type_To_Process;
235 ----------------------------
236 -- Add_Global_Declaration --
237 ----------------------------
239 procedure Add_Global_Declaration (N : Node_Id) is
240 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
243 if No (Declarations (Aux_Node)) then
244 Set_Declarations (Aux_Node, New_List);
247 Append_To (Declarations (Aux_Node), N);
249 end Add_Global_Declaration;
255 -- For now, just 8/16/32/64. but analyze later if AAMP is special???
257 function Addressable (V : Uint) return Boolean is
259 return V = Uint_8 or else
265 function Addressable (V : Int) return Boolean is
273 -----------------------
274 -- Alignment_In_Bits --
275 -----------------------
277 function Alignment_In_Bits (E : Entity_Id) return Uint is
279 return Alignment (E) * System_Storage_Unit;
280 end Alignment_In_Bits;
282 -----------------------------------------
283 -- Apply_Compile_Time_Constraint_Error --
284 -----------------------------------------
286 procedure Apply_Compile_Time_Constraint_Error
289 Reason : RT_Exception_Code;
290 Ent : Entity_Id := Empty;
291 Typ : Entity_Id := Empty;
292 Loc : Source_Ptr := No_Location;
293 Rep : Boolean := True;
294 Warn : Boolean := False)
296 Stat : constant Boolean := Is_Static_Expression (N);
297 R_Stat : constant Node_Id :=
298 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
309 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
315 -- Now we replace the node by an N_Raise_Constraint_Error node
316 -- This does not need reanalyzing, so set it as analyzed now.
319 Set_Analyzed (N, True);
322 Set_Raises_Constraint_Error (N);
324 -- Now deal with possible local raise handling
326 Possible_Local_Raise (N, Standard_Constraint_Error);
328 -- If the original expression was marked as static, the result is
329 -- still marked as static, but the Raises_Constraint_Error flag is
330 -- always set so that further static evaluation is not attempted.
333 Set_Is_Static_Expression (N);
335 end Apply_Compile_Time_Constraint_Error;
337 --------------------------------
338 -- Bad_Predicated_Subtype_Use --
339 --------------------------------
341 procedure Bad_Predicated_Subtype_Use
347 if Has_Predicates (Typ) then
348 if Is_Generic_Actual_Type (Typ) then
349 Error_Msg_FE (Msg & '?', N, Typ);
350 Error_Msg_F ("\Program_Error will be raised at run time?", N);
352 Make_Raise_Program_Error (Sloc (N),
353 Reason => PE_Bad_Predicated_Generic_Type));
356 Error_Msg_FE (Msg, N, Typ);
359 end Bad_Predicated_Subtype_Use;
361 --------------------------
362 -- Build_Actual_Subtype --
363 --------------------------
365 function Build_Actual_Subtype
367 N : Node_Or_Entity_Id) return Node_Id
370 -- Normally Sloc (N), but may point to corresponding body in some cases
372 Constraints : List_Id;
378 Disc_Type : Entity_Id;
384 if Nkind (N) = N_Defining_Identifier then
385 Obj := New_Reference_To (N, Loc);
387 -- If this is a formal parameter of a subprogram declaration, and
388 -- we are compiling the body, we want the declaration for the
389 -- actual subtype to carry the source position of the body, to
390 -- prevent anomalies in gdb when stepping through the code.
392 if Is_Formal (N) then
394 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
396 if Nkind (Decl) = N_Subprogram_Declaration
397 and then Present (Corresponding_Body (Decl))
399 Loc := Sloc (Corresponding_Body (Decl));
408 if Is_Array_Type (T) then
409 Constraints := New_List;
410 for J in 1 .. Number_Dimensions (T) loop
412 -- Build an array subtype declaration with the nominal subtype and
413 -- the bounds of the actual. Add the declaration in front of the
414 -- local declarations for the subprogram, for analysis before any
415 -- reference to the formal in the body.
418 Make_Attribute_Reference (Loc,
420 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
421 Attribute_Name => Name_First,
422 Expressions => New_List (
423 Make_Integer_Literal (Loc, J)));
426 Make_Attribute_Reference (Loc,
428 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
429 Attribute_Name => Name_Last,
430 Expressions => New_List (
431 Make_Integer_Literal (Loc, J)));
433 Append (Make_Range (Loc, Lo, Hi), Constraints);
436 -- If the type has unknown discriminants there is no constrained
437 -- subtype to build. This is never called for a formal or for a
438 -- lhs, so returning the type is ok ???
440 elsif Has_Unknown_Discriminants (T) then
444 Constraints := New_List;
446 -- Type T is a generic derived type, inherit the discriminants from
449 if Is_Private_Type (T)
450 and then No (Full_View (T))
452 -- T was flagged as an error if it was declared as a formal
453 -- derived type with known discriminants. In this case there
454 -- is no need to look at the parent type since T already carries
455 -- its own discriminants.
457 and then not Error_Posted (T)
459 Disc_Type := Etype (Base_Type (T));
464 Discr := First_Discriminant (Disc_Type);
465 while Present (Discr) loop
466 Append_To (Constraints,
467 Make_Selected_Component (Loc,
469 Duplicate_Subexpr_No_Checks (Obj),
470 Selector_Name => New_Occurrence_Of (Discr, Loc)));
471 Next_Discriminant (Discr);
475 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
476 Set_Is_Internal (Subt);
479 Make_Subtype_Declaration (Loc,
480 Defining_Identifier => Subt,
481 Subtype_Indication =>
482 Make_Subtype_Indication (Loc,
483 Subtype_Mark => New_Reference_To (T, Loc),
485 Make_Index_Or_Discriminant_Constraint (Loc,
486 Constraints => Constraints)));
488 Mark_Rewrite_Insertion (Decl);
490 end Build_Actual_Subtype;
492 ---------------------------------------
493 -- Build_Actual_Subtype_Of_Component --
494 ---------------------------------------
496 function Build_Actual_Subtype_Of_Component
498 N : Node_Id) return Node_Id
500 Loc : constant Source_Ptr := Sloc (N);
501 P : constant Node_Id := Prefix (N);
504 Indx_Type : Entity_Id;
506 Deaccessed_T : Entity_Id;
507 -- This is either a copy of T, or if T is an access type, then it is
508 -- the directly designated type of this access type.
510 function Build_Actual_Array_Constraint return List_Id;
511 -- If one or more of the bounds of the component depends on
512 -- discriminants, build actual constraint using the discriminants
515 function Build_Actual_Record_Constraint return List_Id;
516 -- Similar to previous one, for discriminated components constrained
517 -- by the discriminant of the enclosing object.
519 -----------------------------------
520 -- Build_Actual_Array_Constraint --
521 -----------------------------------
523 function Build_Actual_Array_Constraint return List_Id is
524 Constraints : constant List_Id := New_List;
532 Indx := First_Index (Deaccessed_T);
533 while Present (Indx) loop
534 Old_Lo := Type_Low_Bound (Etype (Indx));
535 Old_Hi := Type_High_Bound (Etype (Indx));
537 if Denotes_Discriminant (Old_Lo) then
539 Make_Selected_Component (Loc,
540 Prefix => New_Copy_Tree (P),
541 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
544 Lo := New_Copy_Tree (Old_Lo);
546 -- The new bound will be reanalyzed in the enclosing
547 -- declaration. For literal bounds that come from a type
548 -- declaration, the type of the context must be imposed, so
549 -- insure that analysis will take place. For non-universal
550 -- types this is not strictly necessary.
552 Set_Analyzed (Lo, False);
555 if Denotes_Discriminant (Old_Hi) then
557 Make_Selected_Component (Loc,
558 Prefix => New_Copy_Tree (P),
559 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
562 Hi := New_Copy_Tree (Old_Hi);
563 Set_Analyzed (Hi, False);
566 Append (Make_Range (Loc, Lo, Hi), Constraints);
571 end Build_Actual_Array_Constraint;
573 ------------------------------------
574 -- Build_Actual_Record_Constraint --
575 ------------------------------------
577 function Build_Actual_Record_Constraint return List_Id is
578 Constraints : constant List_Id := New_List;
583 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
584 while Present (D) loop
585 if Denotes_Discriminant (Node (D)) then
586 D_Val := Make_Selected_Component (Loc,
587 Prefix => New_Copy_Tree (P),
588 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
591 D_Val := New_Copy_Tree (Node (D));
594 Append (D_Val, Constraints);
599 end Build_Actual_Record_Constraint;
601 -- Start of processing for Build_Actual_Subtype_Of_Component
604 -- Why the test for Spec_Expression mode here???
606 if In_Spec_Expression then
609 -- More comments for the rest of this body would be good ???
611 elsif Nkind (N) = N_Explicit_Dereference then
612 if Is_Composite_Type (T)
613 and then not Is_Constrained (T)
614 and then not (Is_Class_Wide_Type (T)
615 and then Is_Constrained (Root_Type (T)))
616 and then not Has_Unknown_Discriminants (T)
618 -- If the type of the dereference is already constrained, it is an
621 if Is_Array_Type (Etype (N))
622 and then Is_Constrained (Etype (N))
626 Remove_Side_Effects (P);
627 return Build_Actual_Subtype (T, N);
634 if Ekind (T) = E_Access_Subtype then
635 Deaccessed_T := Designated_Type (T);
640 if Ekind (Deaccessed_T) = E_Array_Subtype then
641 Id := First_Index (Deaccessed_T);
642 while Present (Id) loop
643 Indx_Type := Underlying_Type (Etype (Id));
645 if Denotes_Discriminant (Type_Low_Bound (Indx_Type))
647 Denotes_Discriminant (Type_High_Bound (Indx_Type))
649 Remove_Side_Effects (P);
651 Build_Component_Subtype
652 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
658 elsif Is_Composite_Type (Deaccessed_T)
659 and then Has_Discriminants (Deaccessed_T)
660 and then not Has_Unknown_Discriminants (Deaccessed_T)
662 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
663 while Present (D) loop
664 if Denotes_Discriminant (Node (D)) then
665 Remove_Side_Effects (P);
667 Build_Component_Subtype (
668 Build_Actual_Record_Constraint, Loc, Base_Type (T));
675 -- If none of the above, the actual and nominal subtypes are the same
678 end Build_Actual_Subtype_Of_Component;
680 -----------------------------
681 -- Build_Component_Subtype --
682 -----------------------------
684 function Build_Component_Subtype
687 T : Entity_Id) return Node_Id
693 -- Unchecked_Union components do not require component subtypes
695 if Is_Unchecked_Union (T) then
699 Subt := Make_Temporary (Loc, 'S');
700 Set_Is_Internal (Subt);
703 Make_Subtype_Declaration (Loc,
704 Defining_Identifier => Subt,
705 Subtype_Indication =>
706 Make_Subtype_Indication (Loc,
707 Subtype_Mark => New_Reference_To (Base_Type (T), Loc),
709 Make_Index_Or_Discriminant_Constraint (Loc,
712 Mark_Rewrite_Insertion (Decl);
714 end Build_Component_Subtype;
716 ---------------------------
717 -- Build_Default_Subtype --
718 ---------------------------
720 function Build_Default_Subtype
722 N : Node_Id) return Entity_Id
724 Loc : constant Source_Ptr := Sloc (N);
728 if not Has_Discriminants (T) or else Is_Constrained (T) then
732 Disc := First_Discriminant (T);
734 if No (Discriminant_Default_Value (Disc)) then
739 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
740 Constraints : constant List_Id := New_List;
744 while Present (Disc) loop
745 Append_To (Constraints,
746 New_Copy_Tree (Discriminant_Default_Value (Disc)));
747 Next_Discriminant (Disc);
751 Make_Subtype_Declaration (Loc,
752 Defining_Identifier => Act,
753 Subtype_Indication =>
754 Make_Subtype_Indication (Loc,
755 Subtype_Mark => New_Occurrence_Of (T, Loc),
757 Make_Index_Or_Discriminant_Constraint (Loc,
758 Constraints => Constraints)));
760 Insert_Action (N, Decl);
764 end Build_Default_Subtype;
766 --------------------------------------------
767 -- Build_Discriminal_Subtype_Of_Component --
768 --------------------------------------------
770 function Build_Discriminal_Subtype_Of_Component
771 (T : Entity_Id) return Node_Id
773 Loc : constant Source_Ptr := Sloc (T);
777 function Build_Discriminal_Array_Constraint return List_Id;
778 -- If one or more of the bounds of the component depends on
779 -- discriminants, build actual constraint using the discriminants
782 function Build_Discriminal_Record_Constraint return List_Id;
783 -- Similar to previous one, for discriminated components constrained
784 -- by the discriminant of the enclosing object.
786 ----------------------------------------
787 -- Build_Discriminal_Array_Constraint --
788 ----------------------------------------
790 function Build_Discriminal_Array_Constraint return List_Id is
791 Constraints : constant List_Id := New_List;
799 Indx := First_Index (T);
800 while Present (Indx) loop
801 Old_Lo := Type_Low_Bound (Etype (Indx));
802 Old_Hi := Type_High_Bound (Etype (Indx));
804 if Denotes_Discriminant (Old_Lo) then
805 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
808 Lo := New_Copy_Tree (Old_Lo);
811 if Denotes_Discriminant (Old_Hi) then
812 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
815 Hi := New_Copy_Tree (Old_Hi);
818 Append (Make_Range (Loc, Lo, Hi), Constraints);
823 end Build_Discriminal_Array_Constraint;
825 -----------------------------------------
826 -- Build_Discriminal_Record_Constraint --
827 -----------------------------------------
829 function Build_Discriminal_Record_Constraint return List_Id is
830 Constraints : constant List_Id := New_List;
835 D := First_Elmt (Discriminant_Constraint (T));
836 while Present (D) loop
837 if Denotes_Discriminant (Node (D)) then
839 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
842 D_Val := New_Copy_Tree (Node (D));
845 Append (D_Val, Constraints);
850 end Build_Discriminal_Record_Constraint;
852 -- Start of processing for Build_Discriminal_Subtype_Of_Component
855 if Ekind (T) = E_Array_Subtype then
856 Id := First_Index (T);
857 while Present (Id) loop
858 if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) or else
859 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
861 return Build_Component_Subtype
862 (Build_Discriminal_Array_Constraint, Loc, T);
868 elsif Ekind (T) = E_Record_Subtype
869 and then Has_Discriminants (T)
870 and then not Has_Unknown_Discriminants (T)
872 D := First_Elmt (Discriminant_Constraint (T));
873 while Present (D) loop
874 if Denotes_Discriminant (Node (D)) then
875 return Build_Component_Subtype
876 (Build_Discriminal_Record_Constraint, Loc, T);
883 -- If none of the above, the actual and nominal subtypes are the same
886 end Build_Discriminal_Subtype_Of_Component;
888 ------------------------------
889 -- Build_Elaboration_Entity --
890 ------------------------------
892 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
893 Loc : constant Source_Ptr := Sloc (N);
895 Elab_Ent : Entity_Id;
897 procedure Set_Package_Name (Ent : Entity_Id);
898 -- Given an entity, sets the fully qualified name of the entity in
899 -- Name_Buffer, with components separated by double underscores. This
900 -- is a recursive routine that climbs the scope chain to Standard.
902 ----------------------
903 -- Set_Package_Name --
904 ----------------------
906 procedure Set_Package_Name (Ent : Entity_Id) is
908 if Scope (Ent) /= Standard_Standard then
909 Set_Package_Name (Scope (Ent));
912 Nam : constant String := Get_Name_String (Chars (Ent));
914 Name_Buffer (Name_Len + 1) := '_';
915 Name_Buffer (Name_Len + 2) := '_';
916 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
917 Name_Len := Name_Len + Nam'Length + 2;
921 Get_Name_String (Chars (Ent));
923 end Set_Package_Name;
925 -- Start of processing for Build_Elaboration_Entity
928 -- Ignore if already constructed
930 if Present (Elaboration_Entity (Spec_Id)) then
934 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
935 -- name with dots replaced by double underscore. We have to manually
936 -- construct this name, since it will be elaborated in the outer scope,
937 -- and thus will not have the unit name automatically prepended.
939 Set_Package_Name (Spec_Id);
943 Name_Buffer (Name_Len + 1) := '_';
944 Name_Buffer (Name_Len + 2) := 'E';
945 Name_Len := Name_Len + 2;
947 -- Create elaboration flag
950 Make_Defining_Identifier (Loc, Chars => Name_Find);
951 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
954 Make_Object_Declaration (Loc,
955 Defining_Identifier => Elab_Ent,
957 New_Occurrence_Of (Standard_Boolean, Loc),
959 New_Occurrence_Of (Standard_False, Loc));
961 Push_Scope (Standard_Standard);
962 Add_Global_Declaration (Decl);
965 -- Reset True_Constant indication, since we will indeed assign a value
966 -- to the variable in the binder main. We also kill the Current_Value
967 -- and Last_Assignment fields for the same reason.
969 Set_Is_True_Constant (Elab_Ent, False);
970 Set_Current_Value (Elab_Ent, Empty);
971 Set_Last_Assignment (Elab_Ent, Empty);
973 -- We do not want any further qualification of the name (if we did
974 -- not do this, we would pick up the name of the generic package
975 -- in the case of a library level generic instantiation).
977 Set_Has_Qualified_Name (Elab_Ent);
978 Set_Has_Fully_Qualified_Name (Elab_Ent);
979 end Build_Elaboration_Entity;
981 -----------------------------------
982 -- Cannot_Raise_Constraint_Error --
983 -----------------------------------
985 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
987 if Compile_Time_Known_Value (Expr) then
990 elsif Do_Range_Check (Expr) then
993 elsif Raises_Constraint_Error (Expr) then
1001 when N_Expanded_Name =>
1004 when N_Selected_Component =>
1005 return not Do_Discriminant_Check (Expr);
1007 when N_Attribute_Reference =>
1008 if Do_Overflow_Check (Expr) then
1011 elsif No (Expressions (Expr)) then
1019 N := First (Expressions (Expr));
1020 while Present (N) loop
1021 if Cannot_Raise_Constraint_Error (N) then
1032 when N_Type_Conversion =>
1033 if Do_Overflow_Check (Expr)
1034 or else Do_Length_Check (Expr)
1035 or else Do_Tag_Check (Expr)
1040 Cannot_Raise_Constraint_Error (Expression (Expr));
1043 when N_Unchecked_Type_Conversion =>
1044 return Cannot_Raise_Constraint_Error (Expression (Expr));
1047 if Do_Overflow_Check (Expr) then
1051 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1058 if Do_Division_Check (Expr)
1059 or else Do_Overflow_Check (Expr)
1064 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1066 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1085 N_Op_Shift_Right_Arithmetic |
1089 if Do_Overflow_Check (Expr) then
1093 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1095 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1102 end Cannot_Raise_Constraint_Error;
1104 ---------------------------------------
1105 -- Check_Later_Vs_Basic_Declarations --
1106 ---------------------------------------
1108 procedure Check_Later_Vs_Basic_Declarations
1110 During_Parsing : Boolean)
1112 Body_Sloc : Source_Ptr;
1115 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
1116 -- Return whether Decl is considered as a declarative item.
1117 -- When During_Parsing is True, the semantics of Ada 83 is followed.
1118 -- When During_Parsing is False, the semantics of SPARK is followed.
1120 -------------------------------
1121 -- Is_Later_Declarative_Item --
1122 -------------------------------
1124 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
1126 if Nkind (Decl) in N_Later_Decl_Item then
1129 elsif Nkind (Decl) = N_Pragma then
1132 elsif During_Parsing then
1135 -- In SPARK, a package declaration is not considered as a later
1136 -- declarative item.
1138 elsif Nkind (Decl) = N_Package_Declaration then
1141 -- In SPARK, a renaming is considered as a later declarative item
1143 elsif Nkind (Decl) in N_Renaming_Declaration then
1149 end Is_Later_Declarative_Item;
1151 -- Start of Check_Later_Vs_Basic_Declarations
1154 Decl := First (Decls);
1156 -- Loop through sequence of basic declarative items
1158 Outer : while Present (Decl) loop
1159 if Nkind (Decl) /= N_Subprogram_Body
1160 and then Nkind (Decl) /= N_Package_Body
1161 and then Nkind (Decl) /= N_Task_Body
1162 and then Nkind (Decl) not in N_Body_Stub
1166 -- Once a body is encountered, we only allow later declarative
1167 -- items. The inner loop checks the rest of the list.
1170 Body_Sloc := Sloc (Decl);
1172 Inner : while Present (Decl) loop
1173 if not Is_Later_Declarative_Item (Decl) then
1174 if During_Parsing then
1175 if Ada_Version = Ada_83 then
1176 Error_Msg_Sloc := Body_Sloc;
1178 ("(Ada 83) decl cannot appear after body#", Decl);
1181 Error_Msg_Sloc := Body_Sloc;
1182 Check_Formal_Restriction
1183 ("decl cannot appear after body#", Decl);
1191 end Check_Later_Vs_Basic_Declarations;
1193 -----------------------------------------
1194 -- Check_Dynamically_Tagged_Expression --
1195 -----------------------------------------
1197 procedure Check_Dynamically_Tagged_Expression
1200 Related_Nod : Node_Id)
1203 pragma Assert (Is_Tagged_Type (Typ));
1205 -- In order to avoid spurious errors when analyzing the expanded code,
1206 -- this check is done only for nodes that come from source and for
1207 -- actuals of generic instantiations.
1209 if (Comes_From_Source (Related_Nod)
1210 or else In_Generic_Actual (Expr))
1211 and then (Is_Class_Wide_Type (Etype (Expr))
1212 or else Is_Dynamically_Tagged (Expr))
1213 and then Is_Tagged_Type (Typ)
1214 and then not Is_Class_Wide_Type (Typ)
1216 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
1218 end Check_Dynamically_Tagged_Expression;
1220 --------------------------
1221 -- Check_Fully_Declared --
1222 --------------------------
1224 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
1226 if Ekind (T) = E_Incomplete_Type then
1228 -- Ada 2005 (AI-50217): If the type is available through a limited
1229 -- with_clause, verify that its full view has been analyzed.
1231 if From_With_Type (T)
1232 and then Present (Non_Limited_View (T))
1233 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1235 -- The non-limited view is fully declared
1240 ("premature usage of incomplete}", N, First_Subtype (T));
1243 -- Need comments for these tests ???
1245 elsif Has_Private_Component (T)
1246 and then not Is_Generic_Type (Root_Type (T))
1247 and then not In_Spec_Expression
1249 -- Special case: if T is the anonymous type created for a single
1250 -- task or protected object, use the name of the source object.
1252 if Is_Concurrent_Type (T)
1253 and then not Comes_From_Source (T)
1254 and then Nkind (N) = N_Object_Declaration
1256 Error_Msg_NE ("type of& has incomplete component", N,
1257 Defining_Identifier (N));
1261 ("premature usage of incomplete}", N, First_Subtype (T));
1264 end Check_Fully_Declared;
1266 -------------------------
1267 -- Check_Nested_Access --
1268 -------------------------
1270 procedure Check_Nested_Access (Ent : Entity_Id) is
1271 Scop : constant Entity_Id := Current_Scope;
1272 Current_Subp : Entity_Id;
1273 Enclosing : Entity_Id;
1276 -- Currently only enabled for VM back-ends for efficiency, should we
1277 -- enable it more systematically ???
1279 -- Check for Is_Imported needs commenting below ???
1281 if VM_Target /= No_VM
1282 and then (Ekind (Ent) = E_Variable
1284 Ekind (Ent) = E_Constant
1286 Ekind (Ent) = E_Loop_Parameter)
1287 and then Scope (Ent) /= Empty
1288 and then not Is_Library_Level_Entity (Ent)
1289 and then not Is_Imported (Ent)
1291 if Is_Subprogram (Scop)
1292 or else Is_Generic_Subprogram (Scop)
1293 or else Is_Entry (Scop)
1295 Current_Subp := Scop;
1297 Current_Subp := Current_Subprogram;
1300 Enclosing := Enclosing_Subprogram (Ent);
1302 if Enclosing /= Empty
1303 and then Enclosing /= Current_Subp
1305 Set_Has_Up_Level_Access (Ent, True);
1308 end Check_Nested_Access;
1310 ----------------------------
1311 -- Check_Order_Dependence --
1312 ----------------------------
1314 procedure Check_Order_Dependence is
1319 if Ada_Version < Ada_2012 then
1323 -- Ada 2012 AI04-0144-2: Dangerous order dependence. Actuals in nested
1324 -- calls within a construct have been collected. If one of them is
1325 -- writable and overlaps with another one, evaluation of the enclosing
1326 -- construct is nondeterministic. This is illegal in Ada 2012, but is
1327 -- treated as a warning for now.
1329 for J in 1 .. Actuals_In_Call.Last loop
1330 if Actuals_In_Call.Table (J).Is_Writable then
1331 Act1 := Actuals_In_Call.Table (J).Act;
1333 if Nkind (Act1) = N_Attribute_Reference then
1334 Act1 := Prefix (Act1);
1337 for K in 1 .. Actuals_In_Call.Last loop
1339 Act2 := Actuals_In_Call.Table (K).Act;
1341 if Nkind (Act2) = N_Attribute_Reference then
1342 Act2 := Prefix (Act2);
1345 if Actuals_In_Call.Table (K).Is_Writable
1352 elsif Denotes_Same_Object (Act1, Act2)
1353 and then Parent (Act1) /= Parent (Act2)
1356 ("result may differ if evaluated "
1357 & "after other actual in expression?", Act1);
1364 -- Remove checked actuals from table
1366 Actuals_In_Call.Set_Last (0);
1367 end Check_Order_Dependence;
1369 ------------------------------------------
1370 -- Check_Potentially_Blocking_Operation --
1371 ------------------------------------------
1373 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
1377 -- N is one of the potentially blocking operations listed in 9.5.1(8).
1378 -- When pragma Detect_Blocking is active, the run time will raise
1379 -- Program_Error. Here we only issue a warning, since we generally
1380 -- support the use of potentially blocking operations in the absence
1383 -- Indirect blocking through a subprogram call cannot be diagnosed
1384 -- statically without interprocedural analysis, so we do not attempt
1387 S := Scope (Current_Scope);
1388 while Present (S) and then S /= Standard_Standard loop
1389 if Is_Protected_Type (S) then
1391 ("potentially blocking operation in protected operation?", N);
1397 end Check_Potentially_Blocking_Operation;
1399 ------------------------------
1400 -- Check_Unprotected_Access --
1401 ------------------------------
1403 procedure Check_Unprotected_Access
1407 Cont_Encl_Typ : Entity_Id;
1408 Pref_Encl_Typ : Entity_Id;
1410 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
1411 -- Check whether Obj is a private component of a protected object.
1412 -- Return the protected type where the component resides, Empty
1415 function Is_Public_Operation return Boolean;
1416 -- Verify that the enclosing operation is callable from outside the
1417 -- protected object, to minimize false positives.
1419 ------------------------------
1420 -- Enclosing_Protected_Type --
1421 ------------------------------
1423 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
1425 if Is_Entity_Name (Obj) then
1427 Ent : Entity_Id := Entity (Obj);
1430 -- The object can be a renaming of a private component, use
1431 -- the original record component.
1433 if Is_Prival (Ent) then
1434 Ent := Prival_Link (Ent);
1437 if Is_Protected_Type (Scope (Ent)) then
1443 -- For indexed and selected components, recursively check the prefix
1445 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
1446 return Enclosing_Protected_Type (Prefix (Obj));
1448 -- The object does not denote a protected component
1453 end Enclosing_Protected_Type;
1455 -------------------------
1456 -- Is_Public_Operation --
1457 -------------------------
1459 function Is_Public_Operation return Boolean is
1466 and then S /= Pref_Encl_Typ
1468 if Scope (S) = Pref_Encl_Typ then
1469 E := First_Entity (Pref_Encl_Typ);
1471 and then E /= First_Private_Entity (Pref_Encl_Typ)
1484 end Is_Public_Operation;
1486 -- Start of processing for Check_Unprotected_Access
1489 if Nkind (Expr) = N_Attribute_Reference
1490 and then Attribute_Name (Expr) = Name_Unchecked_Access
1492 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
1493 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
1495 -- Check whether we are trying to export a protected component to a
1496 -- context with an equal or lower access level.
1498 if Present (Pref_Encl_Typ)
1499 and then No (Cont_Encl_Typ)
1500 and then Is_Public_Operation
1501 and then Scope_Depth (Pref_Encl_Typ) >=
1502 Object_Access_Level (Context)
1505 ("?possible unprotected access to protected data", Expr);
1508 end Check_Unprotected_Access;
1514 procedure Check_VMS (Construct : Node_Id) is
1516 if not OpenVMS_On_Target then
1518 ("this construct is allowed only in Open'V'M'S", Construct);
1522 ------------------------
1523 -- Collect_Interfaces --
1524 ------------------------
1526 procedure Collect_Interfaces
1528 Ifaces_List : out Elist_Id;
1529 Exclude_Parents : Boolean := False;
1530 Use_Full_View : Boolean := True)
1532 procedure Collect (Typ : Entity_Id);
1533 -- Subsidiary subprogram used to traverse the whole list
1534 -- of directly and indirectly implemented interfaces
1540 procedure Collect (Typ : Entity_Id) is
1541 Ancestor : Entity_Id;
1549 -- Handle private types
1552 and then Is_Private_Type (Typ)
1553 and then Present (Full_View (Typ))
1555 Full_T := Full_View (Typ);
1558 -- Include the ancestor if we are generating the whole list of
1559 -- abstract interfaces.
1561 if Etype (Full_T) /= Typ
1563 -- Protect the frontend against wrong sources. For example:
1566 -- type A is tagged null record;
1567 -- type B is new A with private;
1568 -- type C is new A with private;
1570 -- type B is new C with null record;
1571 -- type C is new B with null record;
1574 and then Etype (Full_T) /= T
1576 Ancestor := Etype (Full_T);
1579 if Is_Interface (Ancestor)
1580 and then not Exclude_Parents
1582 Append_Unique_Elmt (Ancestor, Ifaces_List);
1586 -- Traverse the graph of ancestor interfaces
1588 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
1589 Id := First (Abstract_Interface_List (Full_T));
1590 while Present (Id) loop
1591 Iface := Etype (Id);
1593 -- Protect against wrong uses. For example:
1594 -- type I is interface;
1595 -- type O is tagged null record;
1596 -- type Wrong is new I and O with null record; -- ERROR
1598 if Is_Interface (Iface) then
1600 and then Etype (T) /= T
1601 and then Interface_Present_In_Ancestor (Etype (T), Iface)
1606 Append_Unique_Elmt (Iface, Ifaces_List);
1615 -- Start of processing for Collect_Interfaces
1618 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
1619 Ifaces_List := New_Elmt_List;
1621 end Collect_Interfaces;
1623 ----------------------------------
1624 -- Collect_Interface_Components --
1625 ----------------------------------
1627 procedure Collect_Interface_Components
1628 (Tagged_Type : Entity_Id;
1629 Components_List : out Elist_Id)
1631 procedure Collect (Typ : Entity_Id);
1632 -- Subsidiary subprogram used to climb to the parents
1638 procedure Collect (Typ : Entity_Id) is
1639 Tag_Comp : Entity_Id;
1640 Parent_Typ : Entity_Id;
1643 -- Handle private types
1645 if Present (Full_View (Etype (Typ))) then
1646 Parent_Typ := Full_View (Etype (Typ));
1648 Parent_Typ := Etype (Typ);
1651 if Parent_Typ /= Typ
1653 -- Protect the frontend against wrong sources. For example:
1656 -- type A is tagged null record;
1657 -- type B is new A with private;
1658 -- type C is new A with private;
1660 -- type B is new C with null record;
1661 -- type C is new B with null record;
1664 and then Parent_Typ /= Tagged_Type
1666 Collect (Parent_Typ);
1669 -- Collect the components containing tags of secondary dispatch
1672 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
1673 while Present (Tag_Comp) loop
1674 pragma Assert (Present (Related_Type (Tag_Comp)));
1675 Append_Elmt (Tag_Comp, Components_List);
1677 Tag_Comp := Next_Tag_Component (Tag_Comp);
1681 -- Start of processing for Collect_Interface_Components
1684 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
1685 and then Is_Tagged_Type (Tagged_Type));
1687 Components_List := New_Elmt_List;
1688 Collect (Tagged_Type);
1689 end Collect_Interface_Components;
1691 -----------------------------
1692 -- Collect_Interfaces_Info --
1693 -----------------------------
1695 procedure Collect_Interfaces_Info
1697 Ifaces_List : out Elist_Id;
1698 Components_List : out Elist_Id;
1699 Tags_List : out Elist_Id)
1701 Comps_List : Elist_Id;
1702 Comp_Elmt : Elmt_Id;
1703 Comp_Iface : Entity_Id;
1704 Iface_Elmt : Elmt_Id;
1707 function Search_Tag (Iface : Entity_Id) return Entity_Id;
1708 -- Search for the secondary tag associated with the interface type
1709 -- Iface that is implemented by T.
1715 function Search_Tag (Iface : Entity_Id) return Entity_Id is
1718 if not Is_CPP_Class (T) then
1719 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
1721 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
1725 and then Is_Tag (Node (ADT))
1726 and then Related_Type (Node (ADT)) /= Iface
1728 -- Skip secondary dispatch table referencing thunks to user
1729 -- defined primitives covered by this interface.
1731 pragma Assert (Has_Suffix (Node (ADT), 'P'));
1734 -- Skip secondary dispatch tables of Ada types
1736 if not Is_CPP_Class (T) then
1738 -- Skip secondary dispatch table referencing thunks to
1739 -- predefined primitives.
1741 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
1744 -- Skip secondary dispatch table referencing user-defined
1745 -- primitives covered by this interface.
1747 pragma Assert (Has_Suffix (Node (ADT), 'D'));
1750 -- Skip secondary dispatch table referencing predefined
1753 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
1758 pragma Assert (Is_Tag (Node (ADT)));
1762 -- Start of processing for Collect_Interfaces_Info
1765 Collect_Interfaces (T, Ifaces_List);
1766 Collect_Interface_Components (T, Comps_List);
1768 -- Search for the record component and tag associated with each
1769 -- interface type of T.
1771 Components_List := New_Elmt_List;
1772 Tags_List := New_Elmt_List;
1774 Iface_Elmt := First_Elmt (Ifaces_List);
1775 while Present (Iface_Elmt) loop
1776 Iface := Node (Iface_Elmt);
1778 -- Associate the primary tag component and the primary dispatch table
1779 -- with all the interfaces that are parents of T
1781 if Is_Ancestor (Iface, T, Use_Full_View => True) then
1782 Append_Elmt (First_Tag_Component (T), Components_List);
1783 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
1785 -- Otherwise search for the tag component and secondary dispatch
1789 Comp_Elmt := First_Elmt (Comps_List);
1790 while Present (Comp_Elmt) loop
1791 Comp_Iface := Related_Type (Node (Comp_Elmt));
1793 if Comp_Iface = Iface
1794 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
1796 Append_Elmt (Node (Comp_Elmt), Components_List);
1797 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
1801 Next_Elmt (Comp_Elmt);
1803 pragma Assert (Present (Comp_Elmt));
1806 Next_Elmt (Iface_Elmt);
1808 end Collect_Interfaces_Info;
1810 ---------------------
1811 -- Collect_Parents --
1812 ---------------------
1814 procedure Collect_Parents
1816 List : out Elist_Id;
1817 Use_Full_View : Boolean := True)
1819 Current_Typ : Entity_Id := T;
1820 Parent_Typ : Entity_Id;
1823 List := New_Elmt_List;
1825 -- No action if the if the type has no parents
1827 if T = Etype (T) then
1832 Parent_Typ := Etype (Current_Typ);
1834 if Is_Private_Type (Parent_Typ)
1835 and then Present (Full_View (Parent_Typ))
1836 and then Use_Full_View
1838 Parent_Typ := Full_View (Base_Type (Parent_Typ));
1841 Append_Elmt (Parent_Typ, List);
1843 exit when Parent_Typ = Current_Typ;
1844 Current_Typ := Parent_Typ;
1846 end Collect_Parents;
1848 ----------------------------------
1849 -- Collect_Primitive_Operations --
1850 ----------------------------------
1852 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
1853 B_Type : constant Entity_Id := Base_Type (T);
1854 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
1855 B_Scope : Entity_Id := Scope (B_Type);
1859 Formal_Derived : Boolean := False;
1862 function Match (E : Entity_Id) return Boolean;
1863 -- True if E's base type is B_Type, or E is of an anonymous access type
1864 -- and the base type of its designated type is B_Type.
1870 function Match (E : Entity_Id) return Boolean is
1871 Etyp : Entity_Id := Etype (E);
1874 if Ekind (Etyp) = E_Anonymous_Access_Type then
1875 Etyp := Designated_Type (Etyp);
1878 return Base_Type (Etyp) = B_Type;
1881 -- Start of processing for Collect_Primitive_Operations
1884 -- For tagged types, the primitive operations are collected as they
1885 -- are declared, and held in an explicit list which is simply returned.
1887 if Is_Tagged_Type (B_Type) then
1888 return Primitive_Operations (B_Type);
1890 -- An untagged generic type that is a derived type inherits the
1891 -- primitive operations of its parent type. Other formal types only
1892 -- have predefined operators, which are not explicitly represented.
1894 elsif Is_Generic_Type (B_Type) then
1895 if Nkind (B_Decl) = N_Formal_Type_Declaration
1896 and then Nkind (Formal_Type_Definition (B_Decl))
1897 = N_Formal_Derived_Type_Definition
1899 Formal_Derived := True;
1901 return New_Elmt_List;
1905 Op_List := New_Elmt_List;
1907 if B_Scope = Standard_Standard then
1908 if B_Type = Standard_String then
1909 Append_Elmt (Standard_Op_Concat, Op_List);
1911 elsif B_Type = Standard_Wide_String then
1912 Append_Elmt (Standard_Op_Concatw, Op_List);
1918 elsif (Is_Package_Or_Generic_Package (B_Scope)
1920 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
1922 or else Is_Derived_Type (B_Type)
1924 -- The primitive operations appear after the base type, except
1925 -- if the derivation happens within the private part of B_Scope
1926 -- and the type is a private type, in which case both the type
1927 -- and some primitive operations may appear before the base
1928 -- type, and the list of candidates starts after the type.
1930 if In_Open_Scopes (B_Scope)
1931 and then Scope (T) = B_Scope
1932 and then In_Private_Part (B_Scope)
1934 Id := Next_Entity (T);
1936 Id := Next_Entity (B_Type);
1939 while Present (Id) loop
1941 -- Note that generic formal subprograms are not
1942 -- considered to be primitive operations and thus
1943 -- are never inherited.
1945 if Is_Overloadable (Id)
1946 and then Nkind (Parent (Parent (Id)))
1947 not in N_Formal_Subprogram_Declaration
1955 Formal := First_Formal (Id);
1956 while Present (Formal) loop
1957 if Match (Formal) then
1962 Next_Formal (Formal);
1966 -- For a formal derived type, the only primitives are the
1967 -- ones inherited from the parent type. Operations appearing
1968 -- in the package declaration are not primitive for it.
1971 and then (not Formal_Derived
1972 or else Present (Alias (Id)))
1974 -- In the special case of an equality operator aliased to
1975 -- an overriding dispatching equality belonging to the same
1976 -- type, we don't include it in the list of primitives.
1977 -- This avoids inheriting multiple equality operators when
1978 -- deriving from untagged private types whose full type is
1979 -- tagged, which can otherwise cause ambiguities. Note that
1980 -- this should only happen for this kind of untagged parent
1981 -- type, since normally dispatching operations are inherited
1982 -- using the type's Primitive_Operations list.
1984 if Chars (Id) = Name_Op_Eq
1985 and then Is_Dispatching_Operation (Id)
1986 and then Present (Alias (Id))
1987 and then Present (Overridden_Operation (Alias (Id)))
1988 and then Base_Type (Etype (First_Entity (Id))) =
1989 Base_Type (Etype (First_Entity (Alias (Id))))
1993 -- Include the subprogram in the list of primitives
1996 Append_Elmt (Id, Op_List);
2003 -- For a type declared in System, some of its operations may
2004 -- appear in the target-specific extension to System.
2007 and then B_Scope = RTU_Entity (System)
2008 and then Present_System_Aux
2010 B_Scope := System_Aux_Id;
2011 Id := First_Entity (System_Aux_Id);
2017 end Collect_Primitive_Operations;
2019 -----------------------------------
2020 -- Compile_Time_Constraint_Error --
2021 -----------------------------------
2023 function Compile_Time_Constraint_Error
2026 Ent : Entity_Id := Empty;
2027 Loc : Source_Ptr := No_Location;
2028 Warn : Boolean := False) return Node_Id
2030 Msgc : String (1 .. Msg'Length + 2);
2031 -- Copy of message, with room for possible ? and ! at end
2041 -- A static constraint error in an instance body is not a fatal error.
2042 -- we choose to inhibit the message altogether, because there is no
2043 -- obvious node (for now) on which to post it. On the other hand the
2044 -- offending node must be replaced with a constraint_error in any case.
2046 -- No messages are generated if we already posted an error on this node
2048 if not Error_Posted (N) then
2049 if Loc /= No_Location then
2055 Msgc (1 .. Msg'Length) := Msg;
2058 -- Message is a warning, even in Ada 95 case
2060 if Msg (Msg'Last) = '?' then
2063 -- In Ada 83, all messages are warnings. In the private part and
2064 -- the body of an instance, constraint_checks are only warnings.
2065 -- We also make this a warning if the Warn parameter is set.
2068 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
2074 elsif In_Instance_Not_Visible then
2079 -- Otherwise we have a real error message (Ada 95 static case)
2080 -- and we make this an unconditional message. Note that in the
2081 -- warning case we do not make the message unconditional, it seems
2082 -- quite reasonable to delete messages like this (about exceptions
2083 -- that will be raised) in dead code.
2091 -- Should we generate a warning? The answer is not quite yes. The
2092 -- very annoying exception occurs in the case of a short circuit
2093 -- operator where the left operand is static and decisive. Climb
2094 -- parents to see if that is the case we have here. Conditional
2095 -- expressions with decisive conditions are a similar situation.
2103 -- And then with False as left operand
2105 if Nkind (P) = N_And_Then
2106 and then Compile_Time_Known_Value (Left_Opnd (P))
2107 and then Is_False (Expr_Value (Left_Opnd (P)))
2112 -- OR ELSE with True as left operand
2114 elsif Nkind (P) = N_Or_Else
2115 and then Compile_Time_Known_Value (Left_Opnd (P))
2116 and then Is_True (Expr_Value (Left_Opnd (P)))
2121 -- Conditional expression
2123 elsif Nkind (P) = N_Conditional_Expression then
2125 Cond : constant Node_Id := First (Expressions (P));
2126 Texp : constant Node_Id := Next (Cond);
2127 Fexp : constant Node_Id := Next (Texp);
2130 if Compile_Time_Known_Value (Cond) then
2132 -- Condition is True and we are in the right operand
2134 if Is_True (Expr_Value (Cond))
2135 and then OldP = Fexp
2140 -- Condition is False and we are in the left operand
2142 elsif Is_False (Expr_Value (Cond))
2143 and then OldP = Texp
2151 -- Special case for component association in aggregates, where
2152 -- we want to keep climbing up to the parent aggregate.
2154 elsif Nkind (P) = N_Component_Association
2155 and then Nkind (Parent (P)) = N_Aggregate
2159 -- Keep going if within subexpression
2162 exit when Nkind (P) not in N_Subexpr;
2167 if Present (Ent) then
2168 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
2170 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
2174 if Inside_Init_Proc then
2176 ("\?& will be raised for objects of this type",
2177 N, Standard_Constraint_Error, Eloc);
2180 ("\?& will be raised at run time",
2181 N, Standard_Constraint_Error, Eloc);
2186 ("\static expression fails Constraint_Check", Eloc);
2187 Set_Error_Posted (N);
2193 end Compile_Time_Constraint_Error;
2195 -----------------------
2196 -- Conditional_Delay --
2197 -----------------------
2199 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
2201 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
2202 Set_Has_Delayed_Freeze (New_Ent);
2204 end Conditional_Delay;
2206 -------------------------
2207 -- Copy_Parameter_List --
2208 -------------------------
2210 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
2211 Loc : constant Source_Ptr := Sloc (Subp_Id);
2216 if No (First_Formal (Subp_Id)) then
2220 Formal := First_Formal (Subp_Id);
2221 while Present (Formal) loop
2223 (Make_Parameter_Specification (Loc,
2224 Defining_Identifier =>
2225 Make_Defining_Identifier (Sloc (Formal),
2226 Chars => Chars (Formal)),
2227 In_Present => In_Present (Parent (Formal)),
2228 Out_Present => Out_Present (Parent (Formal)),
2230 New_Reference_To (Etype (Formal), Loc),
2232 New_Copy_Tree (Expression (Parent (Formal)))),
2235 Next_Formal (Formal);
2240 end Copy_Parameter_List;
2242 --------------------
2243 -- Current_Entity --
2244 --------------------
2246 -- The currently visible definition for a given identifier is the
2247 -- one most chained at the start of the visibility chain, i.e. the
2248 -- one that is referenced by the Node_Id value of the name of the
2249 -- given identifier.
2251 function Current_Entity (N : Node_Id) return Entity_Id is
2253 return Get_Name_Entity_Id (Chars (N));
2256 -----------------------------
2257 -- Current_Entity_In_Scope --
2258 -----------------------------
2260 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
2262 CS : constant Entity_Id := Current_Scope;
2264 Transient_Case : constant Boolean := Scope_Is_Transient;
2267 E := Get_Name_Entity_Id (Chars (N));
2269 and then Scope (E) /= CS
2270 and then (not Transient_Case or else Scope (E) /= Scope (CS))
2276 end Current_Entity_In_Scope;
2282 function Current_Scope return Entity_Id is
2284 if Scope_Stack.Last = -1 then
2285 return Standard_Standard;
2288 C : constant Entity_Id :=
2289 Scope_Stack.Table (Scope_Stack.Last).Entity;
2294 return Standard_Standard;
2300 ------------------------
2301 -- Current_Subprogram --
2302 ------------------------
2304 function Current_Subprogram return Entity_Id is
2305 Scop : constant Entity_Id := Current_Scope;
2307 if Is_Subprogram (Scop) or else Is_Generic_Subprogram (Scop) then
2310 return Enclosing_Subprogram (Scop);
2312 end Current_Subprogram;
2314 ---------------------
2315 -- Defining_Entity --
2316 ---------------------
2318 function Defining_Entity (N : Node_Id) return Entity_Id is
2319 K : constant Node_Kind := Nkind (N);
2320 Err : Entity_Id := Empty;
2325 N_Subprogram_Declaration |
2326 N_Abstract_Subprogram_Declaration |
2328 N_Package_Declaration |
2329 N_Subprogram_Renaming_Declaration |
2330 N_Subprogram_Body_Stub |
2331 N_Generic_Subprogram_Declaration |
2332 N_Generic_Package_Declaration |
2333 N_Formal_Subprogram_Declaration
2335 return Defining_Entity (Specification (N));
2338 N_Component_Declaration |
2339 N_Defining_Program_Unit_Name |
2340 N_Discriminant_Specification |
2342 N_Entry_Declaration |
2343 N_Entry_Index_Specification |
2344 N_Exception_Declaration |
2345 N_Exception_Renaming_Declaration |
2346 N_Formal_Object_Declaration |
2347 N_Formal_Package_Declaration |
2348 N_Formal_Type_Declaration |
2349 N_Full_Type_Declaration |
2350 N_Implicit_Label_Declaration |
2351 N_Incomplete_Type_Declaration |
2352 N_Loop_Parameter_Specification |
2353 N_Number_Declaration |
2354 N_Object_Declaration |
2355 N_Object_Renaming_Declaration |
2356 N_Package_Body_Stub |
2357 N_Parameter_Specification |
2358 N_Private_Extension_Declaration |
2359 N_Private_Type_Declaration |
2361 N_Protected_Body_Stub |
2362 N_Protected_Type_Declaration |
2363 N_Single_Protected_Declaration |
2364 N_Single_Task_Declaration |
2365 N_Subtype_Declaration |
2368 N_Task_Type_Declaration
2370 return Defining_Identifier (N);
2373 return Defining_Entity (Proper_Body (N));
2376 N_Function_Instantiation |
2377 N_Function_Specification |
2378 N_Generic_Function_Renaming_Declaration |
2379 N_Generic_Package_Renaming_Declaration |
2380 N_Generic_Procedure_Renaming_Declaration |
2382 N_Package_Instantiation |
2383 N_Package_Renaming_Declaration |
2384 N_Package_Specification |
2385 N_Procedure_Instantiation |
2386 N_Procedure_Specification
2389 Nam : constant Node_Id := Defining_Unit_Name (N);
2392 if Nkind (Nam) in N_Entity then
2395 -- For Error, make up a name and attach to declaration
2396 -- so we can continue semantic analysis
2398 elsif Nam = Error then
2399 Err := Make_Temporary (Sloc (N), 'T');
2400 Set_Defining_Unit_Name (N, Err);
2403 -- If not an entity, get defining identifier
2406 return Defining_Identifier (Nam);
2410 when N_Block_Statement =>
2411 return Entity (Identifier (N));
2414 raise Program_Error;
2417 end Defining_Entity;
2419 --------------------------
2420 -- Denotes_Discriminant --
2421 --------------------------
2423 function Denotes_Discriminant
2425 Check_Concurrent : Boolean := False) return Boolean
2429 if not Is_Entity_Name (N)
2430 or else No (Entity (N))
2437 -- If we are checking for a protected type, the discriminant may have
2438 -- been rewritten as the corresponding discriminal of the original type
2439 -- or of the corresponding concurrent record, depending on whether we
2440 -- are in the spec or body of the protected type.
2442 return Ekind (E) = E_Discriminant
2445 and then Ekind (E) = E_In_Parameter
2446 and then Present (Discriminal_Link (E))
2448 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
2450 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
2452 end Denotes_Discriminant;
2454 -------------------------
2455 -- Denotes_Same_Object --
2456 -------------------------
2458 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
2459 Obj1 : Node_Id := A1;
2460 Obj2 : Node_Id := A2;
2462 procedure Check_Renaming (Obj : in out Node_Id);
2463 -- If an object is a renaming, examine renamed object. If it is a
2464 -- dereference of a variable, or an indexed expression with non-constant
2465 -- indexes, no overlap check can be reported.
2467 --------------------
2468 -- Check_Renaming --
2469 --------------------
2471 procedure Check_Renaming (Obj : in out Node_Id) is
2473 if Is_Entity_Name (Obj)
2474 and then Present (Renamed_Entity (Entity (Obj)))
2476 Obj := Renamed_Entity (Entity (Obj));
2477 if Nkind (Obj) = N_Explicit_Dereference
2478 and then Is_Variable (Prefix (Obj))
2482 elsif Nkind (Obj) = N_Indexed_Component then
2487 Indx := First (Expressions (Obj));
2488 while Present (Indx) loop
2489 if not Is_OK_Static_Expression (Indx) then
2501 -- Start of processing for Denotes_Same_Object
2504 Check_Renaming (Obj1);
2505 Check_Renaming (Obj2);
2513 -- If we have entity names, then must be same entity
2515 if Is_Entity_Name (Obj1) then
2516 if Is_Entity_Name (Obj2) then
2517 return Entity (Obj1) = Entity (Obj2);
2522 -- No match if not same node kind
2524 elsif Nkind (Obj1) /= Nkind (Obj2) then
2527 -- For selected components, must have same prefix and selector
2529 elsif Nkind (Obj1) = N_Selected_Component then
2530 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
2532 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
2534 -- For explicit dereferences, prefixes must be same
2536 elsif Nkind (Obj1) = N_Explicit_Dereference then
2537 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
2539 -- For indexed components, prefixes and all subscripts must be the same
2541 elsif Nkind (Obj1) = N_Indexed_Component then
2542 if Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
2548 Indx1 := First (Expressions (Obj1));
2549 Indx2 := First (Expressions (Obj2));
2550 while Present (Indx1) loop
2552 -- Indexes must denote the same static value or same object
2554 if Is_OK_Static_Expression (Indx1) then
2555 if not Is_OK_Static_Expression (Indx2) then
2558 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
2562 elsif not Denotes_Same_Object (Indx1, Indx2) then
2576 -- For slices, prefixes must match and bounds must match
2578 elsif Nkind (Obj1) = N_Slice
2579 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
2582 Lo1, Lo2, Hi1, Hi2 : Node_Id;
2585 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
2586 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
2588 -- Check whether bounds are statically identical. There is no
2589 -- attempt to detect partial overlap of slices.
2591 return Denotes_Same_Object (Lo1, Lo2)
2592 and then Denotes_Same_Object (Hi1, Hi2);
2595 -- Literals will appear as indexes. Isn't this where we should check
2596 -- Known_At_Compile_Time at least if we are generating warnings ???
2598 elsif Nkind (Obj1) = N_Integer_Literal then
2599 return Intval (Obj1) = Intval (Obj2);
2604 end Denotes_Same_Object;
2606 -------------------------
2607 -- Denotes_Same_Prefix --
2608 -------------------------
2610 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
2613 if Is_Entity_Name (A1) then
2614 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
2615 and then not Is_Access_Type (Etype (A1))
2617 return Denotes_Same_Object (A1, Prefix (A2))
2618 or else Denotes_Same_Prefix (A1, Prefix (A2));
2623 elsif Is_Entity_Name (A2) then
2624 return Denotes_Same_Prefix (A2, A1);
2626 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
2628 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
2631 Root1, Root2 : Node_Id;
2632 Depth1, Depth2 : Int := 0;
2635 Root1 := Prefix (A1);
2636 while not Is_Entity_Name (Root1) loop
2638 (Root1, N_Selected_Component, N_Indexed_Component)
2642 Root1 := Prefix (Root1);
2645 Depth1 := Depth1 + 1;
2648 Root2 := Prefix (A2);
2649 while not Is_Entity_Name (Root2) loop
2651 (Root2, N_Selected_Component, N_Indexed_Component)
2655 Root2 := Prefix (Root2);
2658 Depth2 := Depth2 + 1;
2661 -- If both have the same depth and they do not denote the same
2662 -- object, they are disjoint and not warning is needed.
2664 if Depth1 = Depth2 then
2667 elsif Depth1 > Depth2 then
2668 Root1 := Prefix (A1);
2669 for I in 1 .. Depth1 - Depth2 - 1 loop
2670 Root1 := Prefix (Root1);
2673 return Denotes_Same_Object (Root1, A2);
2676 Root2 := Prefix (A2);
2677 for I in 1 .. Depth2 - Depth1 - 1 loop
2678 Root2 := Prefix (Root2);
2681 return Denotes_Same_Object (A1, Root2);
2688 end Denotes_Same_Prefix;
2690 ----------------------
2691 -- Denotes_Variable --
2692 ----------------------
2694 function Denotes_Variable (N : Node_Id) return Boolean is
2696 return Is_Variable (N) and then Paren_Count (N) = 0;
2697 end Denotes_Variable;
2699 -----------------------------
2700 -- Depends_On_Discriminant --
2701 -----------------------------
2703 function Depends_On_Discriminant (N : Node_Id) return Boolean is
2708 Get_Index_Bounds (N, L, H);
2709 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
2710 end Depends_On_Discriminant;
2712 -------------------------
2713 -- Designate_Same_Unit --
2714 -------------------------
2716 function Designate_Same_Unit
2718 Name2 : Node_Id) return Boolean
2720 K1 : constant Node_Kind := Nkind (Name1);
2721 K2 : constant Node_Kind := Nkind (Name2);
2723 function Prefix_Node (N : Node_Id) return Node_Id;
2724 -- Returns the parent unit name node of a defining program unit name
2725 -- or the prefix if N is a selected component or an expanded name.
2727 function Select_Node (N : Node_Id) return Node_Id;
2728 -- Returns the defining identifier node of a defining program unit
2729 -- name or the selector node if N is a selected component or an
2736 function Prefix_Node (N : Node_Id) return Node_Id is
2738 if Nkind (N) = N_Defining_Program_Unit_Name then
2750 function Select_Node (N : Node_Id) return Node_Id is
2752 if Nkind (N) = N_Defining_Program_Unit_Name then
2753 return Defining_Identifier (N);
2756 return Selector_Name (N);
2760 -- Start of processing for Designate_Next_Unit
2763 if (K1 = N_Identifier or else
2764 K1 = N_Defining_Identifier)
2766 (K2 = N_Identifier or else
2767 K2 = N_Defining_Identifier)
2769 return Chars (Name1) = Chars (Name2);
2772 (K1 = N_Expanded_Name or else
2773 K1 = N_Selected_Component or else
2774 K1 = N_Defining_Program_Unit_Name)
2776 (K2 = N_Expanded_Name or else
2777 K2 = N_Selected_Component or else
2778 K2 = N_Defining_Program_Unit_Name)
2781 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
2783 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
2788 end Designate_Same_Unit;
2790 --------------------------
2791 -- Enclosing_CPP_Parent --
2792 --------------------------
2794 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
2795 Parent_Typ : Entity_Id := Typ;
2798 while not Is_CPP_Class (Parent_Typ)
2799 and then Etype (Parent_Typ) /= Parent_Typ
2801 Parent_Typ := Etype (Parent_Typ);
2803 if Is_Private_Type (Parent_Typ) then
2804 Parent_Typ := Full_View (Base_Type (Parent_Typ));
2808 pragma Assert (Is_CPP_Class (Parent_Typ));
2810 end Enclosing_CPP_Parent;
2812 ----------------------------
2813 -- Enclosing_Generic_Body --
2814 ----------------------------
2816 function Enclosing_Generic_Body
2817 (N : Node_Id) return Node_Id
2825 while Present (P) loop
2826 if Nkind (P) = N_Package_Body
2827 or else Nkind (P) = N_Subprogram_Body
2829 Spec := Corresponding_Spec (P);
2831 if Present (Spec) then
2832 Decl := Unit_Declaration_Node (Spec);
2834 if Nkind (Decl) = N_Generic_Package_Declaration
2835 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2846 end Enclosing_Generic_Body;
2848 ----------------------------
2849 -- Enclosing_Generic_Unit --
2850 ----------------------------
2852 function Enclosing_Generic_Unit
2853 (N : Node_Id) return Node_Id
2861 while Present (P) loop
2862 if Nkind (P) = N_Generic_Package_Declaration
2863 or else Nkind (P) = N_Generic_Subprogram_Declaration
2867 elsif Nkind (P) = N_Package_Body
2868 or else Nkind (P) = N_Subprogram_Body
2870 Spec := Corresponding_Spec (P);
2872 if Present (Spec) then
2873 Decl := Unit_Declaration_Node (Spec);
2875 if Nkind (Decl) = N_Generic_Package_Declaration
2876 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2887 end Enclosing_Generic_Unit;
2889 -------------------------------
2890 -- Enclosing_Lib_Unit_Entity --
2891 -------------------------------
2893 function Enclosing_Lib_Unit_Entity return Entity_Id is
2894 Unit_Entity : Entity_Id;
2897 -- Look for enclosing library unit entity by following scope links.
2898 -- Equivalent to, but faster than indexing through the scope stack.
2900 Unit_Entity := Current_Scope;
2901 while (Present (Scope (Unit_Entity))
2902 and then Scope (Unit_Entity) /= Standard_Standard)
2903 and not Is_Child_Unit (Unit_Entity)
2905 Unit_Entity := Scope (Unit_Entity);
2909 end Enclosing_Lib_Unit_Entity;
2911 -----------------------------
2912 -- Enclosing_Lib_Unit_Node --
2913 -----------------------------
2915 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
2916 Current_Node : Node_Id;
2920 while Present (Current_Node)
2921 and then Nkind (Current_Node) /= N_Compilation_Unit
2923 Current_Node := Parent (Current_Node);
2926 if Nkind (Current_Node) /= N_Compilation_Unit then
2930 return Current_Node;
2931 end Enclosing_Lib_Unit_Node;
2933 -----------------------
2934 -- Enclosing_Package --
2935 -----------------------
2937 function Enclosing_Package (E : Entity_Id) return Entity_Id is
2938 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
2941 if Dynamic_Scope = Standard_Standard then
2942 return Standard_Standard;
2944 elsif Dynamic_Scope = Empty then
2947 elsif Ekind_In (Dynamic_Scope, E_Package, E_Package_Body,
2950 return Dynamic_Scope;
2953 return Enclosing_Package (Dynamic_Scope);
2955 end Enclosing_Package;
2957 --------------------------
2958 -- Enclosing_Subprogram --
2959 --------------------------
2961 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
2962 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
2965 if Dynamic_Scope = Standard_Standard then
2968 elsif Dynamic_Scope = Empty then
2971 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
2972 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
2974 elsif Ekind (Dynamic_Scope) = E_Block
2975 or else Ekind (Dynamic_Scope) = E_Return_Statement
2977 return Enclosing_Subprogram (Dynamic_Scope);
2979 elsif Ekind (Dynamic_Scope) = E_Task_Type then
2980 return Get_Task_Body_Procedure (Dynamic_Scope);
2982 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
2983 and then Present (Full_View (Dynamic_Scope))
2984 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
2986 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
2988 -- No body is generated if the protected operation is eliminated
2990 elsif Convention (Dynamic_Scope) = Convention_Protected
2991 and then not Is_Eliminated (Dynamic_Scope)
2992 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
2994 return Protected_Body_Subprogram (Dynamic_Scope);
2997 return Dynamic_Scope;
2999 end Enclosing_Subprogram;
3001 ------------------------
3002 -- Ensure_Freeze_Node --
3003 ------------------------
3005 procedure Ensure_Freeze_Node (E : Entity_Id) is
3009 if No (Freeze_Node (E)) then
3010 FN := Make_Freeze_Entity (Sloc (E));
3011 Set_Has_Delayed_Freeze (E);
3012 Set_Freeze_Node (E, FN);
3013 Set_Access_Types_To_Process (FN, No_Elist);
3014 Set_TSS_Elist (FN, No_Elist);
3017 end Ensure_Freeze_Node;
3023 procedure Enter_Name (Def_Id : Entity_Id) is
3024 C : constant Entity_Id := Current_Entity (Def_Id);
3025 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
3026 S : constant Entity_Id := Current_Scope;
3029 Generate_Definition (Def_Id);
3031 -- Add new name to current scope declarations. Check for duplicate
3032 -- declaration, which may or may not be a genuine error.
3036 -- Case of previous entity entered because of a missing declaration
3037 -- or else a bad subtype indication. Best is to use the new entity,
3038 -- and make the previous one invisible.
3040 if Etype (E) = Any_Type then
3041 Set_Is_Immediately_Visible (E, False);
3043 -- Case of renaming declaration constructed for package instances.
3044 -- if there is an explicit declaration with the same identifier,
3045 -- the renaming is not immediately visible any longer, but remains
3046 -- visible through selected component notation.
3048 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
3049 and then not Comes_From_Source (E)
3051 Set_Is_Immediately_Visible (E, False);
3053 -- The new entity may be the package renaming, which has the same
3054 -- same name as a generic formal which has been seen already.
3056 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
3057 and then not Comes_From_Source (Def_Id)
3059 Set_Is_Immediately_Visible (E, False);
3061 -- For a fat pointer corresponding to a remote access to subprogram,
3062 -- we use the same identifier as the RAS type, so that the proper
3063 -- name appears in the stub. This type is only retrieved through
3064 -- the RAS type and never by visibility, and is not added to the
3065 -- visibility list (see below).
3067 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
3068 and then Present (Corresponding_Remote_Type (Def_Id))
3072 -- A controller component for a type extension overrides the
3073 -- inherited component.
3075 elsif Chars (E) = Name_uController then
3078 -- Case of an implicit operation or derived literal. The new entity
3079 -- hides the implicit one, which is removed from all visibility,
3080 -- i.e. the entity list of its scope, and homonym chain of its name.
3082 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
3083 or else Is_Internal (E)
3087 Prev_Vis : Entity_Id;
3088 Decl : constant Node_Id := Parent (E);
3091 -- If E is an implicit declaration, it cannot be the first
3092 -- entity in the scope.
3094 Prev := First_Entity (Current_Scope);
3095 while Present (Prev)
3096 and then Next_Entity (Prev) /= E
3103 -- If E is not on the entity chain of the current scope,
3104 -- it is an implicit declaration in the generic formal
3105 -- part of a generic subprogram. When analyzing the body,
3106 -- the generic formals are visible but not on the entity
3107 -- chain of the subprogram. The new entity will become
3108 -- the visible one in the body.
3111 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
3115 Set_Next_Entity (Prev, Next_Entity (E));
3117 if No (Next_Entity (Prev)) then
3118 Set_Last_Entity (Current_Scope, Prev);
3121 if E = Current_Entity (E) then
3125 Prev_Vis := Current_Entity (E);
3126 while Homonym (Prev_Vis) /= E loop
3127 Prev_Vis := Homonym (Prev_Vis);
3131 if Present (Prev_Vis) then
3133 -- Skip E in the visibility chain
3135 Set_Homonym (Prev_Vis, Homonym (E));
3138 Set_Name_Entity_Id (Chars (E), Homonym (E));
3143 -- This section of code could use a comment ???
3145 elsif Present (Etype (E))
3146 and then Is_Concurrent_Type (Etype (E))
3151 -- If the homograph is a protected component renaming, it should not
3152 -- be hiding the current entity. Such renamings are treated as weak
3155 elsif Is_Prival (E) then
3156 Set_Is_Immediately_Visible (E, False);
3158 -- In this case the current entity is a protected component renaming.
3159 -- Perform minimal decoration by setting the scope and return since
3160 -- the prival should not be hiding other visible entities.
3162 elsif Is_Prival (Def_Id) then
3163 Set_Scope (Def_Id, Current_Scope);
3166 -- Analogous to privals, the discriminal generated for an entry index
3167 -- parameter acts as a weak declaration. Perform minimal decoration
3168 -- to avoid bogus errors.
3170 elsif Is_Discriminal (Def_Id)
3171 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
3173 Set_Scope (Def_Id, Current_Scope);
3176 -- In the body or private part of an instance, a type extension may
3177 -- introduce a component with the same name as that of an actual. The
3178 -- legality rule is not enforced, but the semantics of the full type
3179 -- with two components of same name are not clear at this point???
3181 elsif In_Instance_Not_Visible then
3184 -- When compiling a package body, some child units may have become
3185 -- visible. They cannot conflict with local entities that hide them.
3187 elsif Is_Child_Unit (E)
3188 and then In_Open_Scopes (Scope (E))
3189 and then not Is_Immediately_Visible (E)
3193 -- Conversely, with front-end inlining we may compile the parent body
3194 -- first, and a child unit subsequently. The context is now the
3195 -- parent spec, and body entities are not visible.
3197 elsif Is_Child_Unit (Def_Id)
3198 and then Is_Package_Body_Entity (E)
3199 and then not In_Package_Body (Current_Scope)
3203 -- Case of genuine duplicate declaration
3206 Error_Msg_Sloc := Sloc (E);
3208 -- If the previous declaration is an incomplete type declaration
3209 -- this may be an attempt to complete it with a private type. The
3210 -- following avoids confusing cascaded errors.
3212 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
3213 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
3216 ("incomplete type cannot be completed with a private " &
3217 "declaration", Parent (Def_Id));
3218 Set_Is_Immediately_Visible (E, False);
3219 Set_Full_View (E, Def_Id);
3221 -- An inherited component of a record conflicts with a new
3222 -- discriminant. The discriminant is inserted first in the scope,
3223 -- but the error should be posted on it, not on the component.
3225 elsif Ekind (E) = E_Discriminant
3226 and then Present (Scope (Def_Id))
3227 and then Scope (Def_Id) /= Current_Scope
3229 Error_Msg_Sloc := Sloc (Def_Id);
3230 Error_Msg_N ("& conflicts with declaration#", E);
3233 -- If the name of the unit appears in its own context clause, a
3234 -- dummy package with the name has already been created, and the
3235 -- error emitted. Try to continue quietly.
3237 elsif Error_Posted (E)
3238 and then Sloc (E) = No_Location
3239 and then Nkind (Parent (E)) = N_Package_Specification
3240 and then Current_Scope = Standard_Standard
3242 Set_Scope (Def_Id, Current_Scope);
3246 Error_Msg_N ("& conflicts with declaration#", Def_Id);
3248 -- Avoid cascaded messages with duplicate components in
3251 if Ekind_In (E, E_Component, E_Discriminant) then
3256 if Nkind (Parent (Parent (Def_Id))) =
3257 N_Generic_Subprogram_Declaration
3259 Defining_Entity (Specification (Parent (Parent (Def_Id))))
3261 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
3264 -- If entity is in standard, then we are in trouble, because it
3265 -- means that we have a library package with a duplicated name.
3266 -- That's hard to recover from, so abort!
3268 if S = Standard_Standard then
3269 raise Unrecoverable_Error;
3271 -- Otherwise we continue with the declaration. Having two
3272 -- identical declarations should not cause us too much trouble!
3280 -- If we fall through, declaration is OK, at least OK enough to continue
3282 -- If Def_Id is a discriminant or a record component we are in the midst
3283 -- of inheriting components in a derived record definition. Preserve
3284 -- their Ekind and Etype.
3286 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
3289 -- If a type is already set, leave it alone (happens when a type
3290 -- declaration is reanalyzed following a call to the optimizer).
3292 elsif Present (Etype (Def_Id)) then
3295 -- Otherwise, the kind E_Void insures that premature uses of the entity
3296 -- will be detected. Any_Type insures that no cascaded errors will occur
3299 Set_Ekind (Def_Id, E_Void);
3300 Set_Etype (Def_Id, Any_Type);
3303 -- Inherited discriminants and components in derived record types are
3304 -- immediately visible. Itypes are not.
3306 if Ekind_In (Def_Id, E_Discriminant, E_Component)
3307 or else (No (Corresponding_Remote_Type (Def_Id))
3308 and then not Is_Itype (Def_Id))
3310 Set_Is_Immediately_Visible (Def_Id);
3311 Set_Current_Entity (Def_Id);
3314 Set_Homonym (Def_Id, C);
3315 Append_Entity (Def_Id, S);
3316 Set_Public_Status (Def_Id);
3318 -- Declaring a homonym is not allowed in SPARK or ALFA ...
3321 and then (Restriction_Check_Required (SPARK)
3322 or else Formal_Verification_Mode)
3326 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
3327 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
3328 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
3331 -- ... unless the new declaration is in a subprogram, and the
3332 -- visible declaration is a variable declaration or a parameter
3333 -- specification outside that subprogram.
3335 if Present (Enclosing_Subp)
3336 and then Nkind_In (Parent (C), N_Object_Declaration,
3337 N_Parameter_Specification)
3338 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
3342 -- ... or the new declaration is in a package, and the visible
3343 -- declaration occurs outside that package.
3345 elsif Present (Enclosing_Pack)
3346 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
3350 -- ... or the new declaration is a component declaration in a
3351 -- record type definition.
3353 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
3356 -- Don't issue error for non-source entities
3358 elsif Comes_From_Source (Def_Id)
3359 and then Comes_From_Source (C)
3361 Error_Msg_Sloc := Sloc (C);
3362 Check_Formal_Restriction
3363 ("redeclaration of identifier &#", Def_Id);
3368 -- Warn if new entity hides an old one
3370 if Warn_On_Hiding and then Present (C)
3372 -- Don't warn for record components since they always have a well
3373 -- defined scope which does not confuse other uses. Note that in
3374 -- some cases, Ekind has not been set yet.
3376 and then Ekind (C) /= E_Component
3377 and then Ekind (C) /= E_Discriminant
3378 and then Nkind (Parent (C)) /= N_Component_Declaration
3379 and then Ekind (Def_Id) /= E_Component
3380 and then Ekind (Def_Id) /= E_Discriminant
3381 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
3383 -- Don't warn for one character variables. It is too common to use
3384 -- such variables as locals and will just cause too many false hits.
3386 and then Length_Of_Name (Chars (C)) /= 1
3388 -- Don't warn for non-source entities
3390 and then Comes_From_Source (C)
3391 and then Comes_From_Source (Def_Id)
3393 -- Don't warn unless entity in question is in extended main source
3395 and then In_Extended_Main_Source_Unit (Def_Id)
3397 -- Finally, the hidden entity must be either immediately visible or
3398 -- use visible (i.e. from a used package).
3401 (Is_Immediately_Visible (C)
3403 Is_Potentially_Use_Visible (C))
3405 Error_Msg_Sloc := Sloc (C);
3406 Error_Msg_N ("declaration hides &#?", Def_Id);
3410 --------------------------
3411 -- Explain_Limited_Type --
3412 --------------------------
3414 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
3418 -- For array, component type must be limited
3420 if Is_Array_Type (T) then
3421 Error_Msg_Node_2 := T;
3423 ("\component type& of type& is limited", N, Component_Type (T));
3424 Explain_Limited_Type (Component_Type (T), N);
3426 elsif Is_Record_Type (T) then
3428 -- No need for extra messages if explicit limited record
3430 if Is_Limited_Record (Base_Type (T)) then
3434 -- Otherwise find a limited component. Check only components that
3435 -- come from source, or inherited components that appear in the
3436 -- source of the ancestor.
3438 C := First_Component (T);
3439 while Present (C) loop
3440 if Is_Limited_Type (Etype (C))
3442 (Comes_From_Source (C)
3444 (Present (Original_Record_Component (C))
3446 Comes_From_Source (Original_Record_Component (C))))
3448 Error_Msg_Node_2 := T;
3449 Error_Msg_NE ("\component& of type& has limited type", N, C);
3450 Explain_Limited_Type (Etype (C), N);
3457 -- The type may be declared explicitly limited, even if no component
3458 -- of it is limited, in which case we fall out of the loop.
3461 end Explain_Limited_Type;
3467 procedure Find_Actual
3469 Formal : out Entity_Id;
3472 Parnt : constant Node_Id := Parent (N);
3476 if (Nkind (Parnt) = N_Indexed_Component
3478 Nkind (Parnt) = N_Selected_Component)
3479 and then N = Prefix (Parnt)
3481 Find_Actual (Parnt, Formal, Call);
3484 elsif Nkind (Parnt) = N_Parameter_Association
3485 and then N = Explicit_Actual_Parameter (Parnt)
3487 Call := Parent (Parnt);
3489 elsif Nkind_In (Parnt, N_Procedure_Call_Statement, N_Function_Call) then
3498 -- If we have a call to a subprogram look for the parameter. Note that
3499 -- we exclude overloaded calls, since we don't know enough to be sure
3500 -- of giving the right answer in this case.
3502 if Is_Entity_Name (Name (Call))
3503 and then Present (Entity (Name (Call)))
3504 and then Is_Overloadable (Entity (Name (Call)))
3505 and then not Is_Overloaded (Name (Call))
3507 -- Fall here if we are definitely a parameter
3509 Actual := First_Actual (Call);
3510 Formal := First_Formal (Entity (Name (Call)));
3511 while Present (Formal) and then Present (Actual) loop
3515 Actual := Next_Actual (Actual);
3516 Formal := Next_Formal (Formal);
3521 -- Fall through here if we did not find matching actual
3527 ---------------------------
3528 -- Find_Body_Discriminal --
3529 ---------------------------
3531 function Find_Body_Discriminal
3532 (Spec_Discriminant : Entity_Id) return Entity_Id
3534 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
3536 Tsk : constant Entity_Id :=
3537 Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
3541 -- Find discriminant of original concurrent type, and use its current
3542 -- discriminal, which is the renaming within the task/protected body.
3544 Disc := First_Discriminant (Tsk);
3545 while Present (Disc) loop
3546 if Chars (Disc) = Chars (Spec_Discriminant) then
3547 return Discriminal (Disc);
3550 Next_Discriminant (Disc);
3553 -- That loop should always succeed in finding a matching entry and
3554 -- returning. Fatal error if not.
3556 raise Program_Error;
3557 end Find_Body_Discriminal;
3559 -------------------------------------
3560 -- Find_Corresponding_Discriminant --
3561 -------------------------------------
3563 function Find_Corresponding_Discriminant
3565 Typ : Entity_Id) return Entity_Id
3567 Par_Disc : Entity_Id;
3568 Old_Disc : Entity_Id;
3569 New_Disc : Entity_Id;
3572 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
3574 -- The original type may currently be private, and the discriminant
3575 -- only appear on its full view.
3577 if Is_Private_Type (Scope (Par_Disc))
3578 and then not Has_Discriminants (Scope (Par_Disc))
3579 and then Present (Full_View (Scope (Par_Disc)))
3581 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
3583 Old_Disc := First_Discriminant (Scope (Par_Disc));
3586 if Is_Class_Wide_Type (Typ) then
3587 New_Disc := First_Discriminant (Root_Type (Typ));
3589 New_Disc := First_Discriminant (Typ);
3592 while Present (Old_Disc) and then Present (New_Disc) loop
3593 if Old_Disc = Par_Disc then
3596 Next_Discriminant (Old_Disc);
3597 Next_Discriminant (New_Disc);
3601 -- Should always find it
3603 raise Program_Error;
3604 end Find_Corresponding_Discriminant;
3606 --------------------------
3607 -- Find_Overlaid_Entity --
3608 --------------------------
3610 procedure Find_Overlaid_Entity
3612 Ent : out Entity_Id;
3618 -- We are looking for one of the two following forms:
3620 -- for X'Address use Y'Address
3624 -- Const : constant Address := expr;
3626 -- for X'Address use Const;
3628 -- In the second case, the expr is either Y'Address, or recursively a
3629 -- constant that eventually references Y'Address.
3634 if Nkind (N) = N_Attribute_Definition_Clause
3635 and then Chars (N) = Name_Address
3637 Expr := Expression (N);
3639 -- This loop checks the form of the expression for Y'Address,
3640 -- using recursion to deal with intermediate constants.
3643 -- Check for Y'Address
3645 if Nkind (Expr) = N_Attribute_Reference
3646 and then Attribute_Name (Expr) = Name_Address
3648 Expr := Prefix (Expr);
3651 -- Check for Const where Const is a constant entity
3653 elsif Is_Entity_Name (Expr)
3654 and then Ekind (Entity (Expr)) = E_Constant
3656 Expr := Constant_Value (Entity (Expr));
3658 -- Anything else does not need checking
3665 -- This loop checks the form of the prefix for an entity,
3666 -- using recursion to deal with intermediate components.
3669 -- Check for Y where Y is an entity
3671 if Is_Entity_Name (Expr) then
3672 Ent := Entity (Expr);
3675 -- Check for components
3678 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component) then
3680 Expr := Prefix (Expr);
3683 -- Anything else does not need checking
3690 end Find_Overlaid_Entity;
3692 -------------------------
3693 -- Find_Parameter_Type --
3694 -------------------------
3696 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
3698 if Nkind (Param) /= N_Parameter_Specification then
3701 -- For an access parameter, obtain the type from the formal entity
3702 -- itself, because access to subprogram nodes do not carry a type.
3703 -- Shouldn't we always use the formal entity ???
3705 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
3706 return Etype (Defining_Identifier (Param));
3709 return Etype (Parameter_Type (Param));
3711 end Find_Parameter_Type;
3713 -----------------------------
3714 -- Find_Static_Alternative --
3715 -----------------------------
3717 function Find_Static_Alternative (N : Node_Id) return Node_Id is
3718 Expr : constant Node_Id := Expression (N);
3719 Val : constant Uint := Expr_Value (Expr);
3724 Alt := First (Alternatives (N));
3727 if Nkind (Alt) /= N_Pragma then
3728 Choice := First (Discrete_Choices (Alt));
3729 while Present (Choice) loop
3731 -- Others choice, always matches
3733 if Nkind (Choice) = N_Others_Choice then
3736 -- Range, check if value is in the range
3738 elsif Nkind (Choice) = N_Range then
3740 Val >= Expr_Value (Low_Bound (Choice))
3742 Val <= Expr_Value (High_Bound (Choice));
3744 -- Choice is a subtype name. Note that we know it must
3745 -- be a static subtype, since otherwise it would have
3746 -- been diagnosed as illegal.
3748 elsif Is_Entity_Name (Choice)
3749 and then Is_Type (Entity (Choice))
3751 exit Search when Is_In_Range (Expr, Etype (Choice),
3752 Assume_Valid => False);
3754 -- Choice is a subtype indication
3756 elsif Nkind (Choice) = N_Subtype_Indication then
3758 C : constant Node_Id := Constraint (Choice);
3759 R : constant Node_Id := Range_Expression (C);
3763 Val >= Expr_Value (Low_Bound (R))
3765 Val <= Expr_Value (High_Bound (R));
3768 -- Choice is a simple expression
3771 exit Search when Val = Expr_Value (Choice);
3779 pragma Assert (Present (Alt));
3782 -- The above loop *must* terminate by finding a match, since
3783 -- we know the case statement is valid, and the value of the
3784 -- expression is known at compile time. When we fall out of
3785 -- the loop, Alt points to the alternative that we know will
3786 -- be selected at run time.
3789 end Find_Static_Alternative;
3795 function First_Actual (Node : Node_Id) return Node_Id is
3799 if No (Parameter_Associations (Node)) then
3803 N := First (Parameter_Associations (Node));
3805 if Nkind (N) = N_Parameter_Association then
3806 return First_Named_Actual (Node);
3812 -----------------------
3813 -- Gather_Components --
3814 -----------------------
3816 procedure Gather_Components
3818 Comp_List : Node_Id;
3819 Governed_By : List_Id;
3821 Report_Errors : out Boolean)
3825 Discrete_Choice : Node_Id;
3826 Comp_Item : Node_Id;
3828 Discrim : Entity_Id;
3829 Discrim_Name : Node_Id;
3830 Discrim_Value : Node_Id;
3833 Report_Errors := False;
3835 if No (Comp_List) or else Null_Present (Comp_List) then
3838 elsif Present (Component_Items (Comp_List)) then
3839 Comp_Item := First (Component_Items (Comp_List));
3845 while Present (Comp_Item) loop
3847 -- Skip the tag of a tagged record, the interface tags, as well
3848 -- as all items that are not user components (anonymous types,
3849 -- rep clauses, Parent field, controller field).
3851 if Nkind (Comp_Item) = N_Component_Declaration then
3853 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
3855 if not Is_Tag (Comp)
3856 and then Chars (Comp) /= Name_uParent
3857 and then Chars (Comp) /= Name_uController
3859 Append_Elmt (Comp, Into);
3867 if No (Variant_Part (Comp_List)) then
3870 Discrim_Name := Name (Variant_Part (Comp_List));
3871 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
3874 -- Look for the discriminant that governs this variant part.
3875 -- The discriminant *must* be in the Governed_By List
3877 Assoc := First (Governed_By);
3878 Find_Constraint : loop
3879 Discrim := First (Choices (Assoc));
3880 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
3881 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
3883 Chars (Corresponding_Discriminant (Entity (Discrim)))
3884 = Chars (Discrim_Name))
3885 or else Chars (Original_Record_Component (Entity (Discrim)))
3886 = Chars (Discrim_Name);
3888 if No (Next (Assoc)) then
3889 if not Is_Constrained (Typ)
3890 and then Is_Derived_Type (Typ)
3891 and then Present (Stored_Constraint (Typ))
3893 -- If the type is a tagged type with inherited discriminants,
3894 -- use the stored constraint on the parent in order to find
3895 -- the values of discriminants that are otherwise hidden by an
3896 -- explicit constraint. Renamed discriminants are handled in
3899 -- If several parent discriminants are renamed by a single
3900 -- discriminant of the derived type, the call to obtain the
3901 -- Corresponding_Discriminant field only retrieves the last
3902 -- of them. We recover the constraint on the others from the
3903 -- Stored_Constraint as well.
3910 D := First_Discriminant (Etype (Typ));
3911 C := First_Elmt (Stored_Constraint (Typ));
3912 while Present (D) and then Present (C) loop
3913 if Chars (Discrim_Name) = Chars (D) then
3914 if Is_Entity_Name (Node (C))
3915 and then Entity (Node (C)) = Entity (Discrim)
3917 -- D is renamed by Discrim, whose value is given in
3924 Make_Component_Association (Sloc (Typ),
3926 (New_Occurrence_Of (D, Sloc (Typ))),
3927 Duplicate_Subexpr_No_Checks (Node (C)));
3929 exit Find_Constraint;
3932 Next_Discriminant (D);
3939 if No (Next (Assoc)) then
3940 Error_Msg_NE (" missing value for discriminant&",
3941 First (Governed_By), Discrim_Name);
3942 Report_Errors := True;
3947 end loop Find_Constraint;
3949 Discrim_Value := Expression (Assoc);
3951 if not Is_OK_Static_Expression (Discrim_Value) then
3953 ("value for discriminant & must be static!",
3954 Discrim_Value, Discrim);
3955 Why_Not_Static (Discrim_Value);
3956 Report_Errors := True;
3960 Search_For_Discriminant_Value : declare
3966 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
3969 Find_Discrete_Value : while Present (Variant) loop
3970 Discrete_Choice := First (Discrete_Choices (Variant));
3971 while Present (Discrete_Choice) loop
3973 exit Find_Discrete_Value when
3974 Nkind (Discrete_Choice) = N_Others_Choice;
3976 Get_Index_Bounds (Discrete_Choice, Low, High);
3978 UI_Low := Expr_Value (Low);
3979 UI_High := Expr_Value (High);
3981 exit Find_Discrete_Value when
3982 UI_Low <= UI_Discrim_Value
3984 UI_High >= UI_Discrim_Value;
3986 Next (Discrete_Choice);
3989 Next_Non_Pragma (Variant);
3990 end loop Find_Discrete_Value;
3991 end Search_For_Discriminant_Value;
3993 if No (Variant) then
3995 ("value of discriminant & is out of range", Discrim_Value, Discrim);
3996 Report_Errors := True;
4000 -- If we have found the corresponding choice, recursively add its
4001 -- components to the Into list.
4003 Gather_Components (Empty,
4004 Component_List (Variant), Governed_By, Into, Report_Errors);
4005 end Gather_Components;
4007 ------------------------
4008 -- Get_Actual_Subtype --
4009 ------------------------
4011 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
4012 Typ : constant Entity_Id := Etype (N);
4013 Utyp : Entity_Id := Underlying_Type (Typ);
4022 -- If what we have is an identifier that references a subprogram
4023 -- formal, or a variable or constant object, then we get the actual
4024 -- subtype from the referenced entity if one has been built.
4026 if Nkind (N) = N_Identifier
4028 (Is_Formal (Entity (N))
4029 or else Ekind (Entity (N)) = E_Constant
4030 or else Ekind (Entity (N)) = E_Variable)
4031 and then Present (Actual_Subtype (Entity (N)))
4033 return Actual_Subtype (Entity (N));
4035 -- Actual subtype of unchecked union is always itself. We never need
4036 -- the "real" actual subtype. If we did, we couldn't get it anyway
4037 -- because the discriminant is not available. The restrictions on
4038 -- Unchecked_Union are designed to make sure that this is OK.
4040 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
4043 -- Here for the unconstrained case, we must find actual subtype
4044 -- No actual subtype is available, so we must build it on the fly.
4046 -- Checking the type, not the underlying type, for constrainedness
4047 -- seems to be necessary. Maybe all the tests should be on the type???
4049 elsif (not Is_Constrained (Typ))
4050 and then (Is_Array_Type (Utyp)
4051 or else (Is_Record_Type (Utyp)
4052 and then Has_Discriminants (Utyp)))
4053 and then not Has_Unknown_Discriminants (Utyp)
4054 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
4056 -- Nothing to do if in spec expression (why not???)
4058 if In_Spec_Expression then
4061 elsif Is_Private_Type (Typ)
4062 and then not Has_Discriminants (Typ)
4064 -- If the type has no discriminants, there is no subtype to
4065 -- build, even if the underlying type is discriminated.
4069 -- Else build the actual subtype
4072 Decl := Build_Actual_Subtype (Typ, N);
4073 Atyp := Defining_Identifier (Decl);
4075 -- If Build_Actual_Subtype generated a new declaration then use it
4079 -- The actual subtype is an Itype, so analyze the declaration,
4080 -- but do not attach it to the tree, to get the type defined.
4082 Set_Parent (Decl, N);
4083 Set_Is_Itype (Atyp);
4084 Analyze (Decl, Suppress => All_Checks);
4085 Set_Associated_Node_For_Itype (Atyp, N);
4086 Set_Has_Delayed_Freeze (Atyp, False);
4088 -- We need to freeze the actual subtype immediately. This is
4089 -- needed, because otherwise this Itype will not get frozen
4090 -- at all, and it is always safe to freeze on creation because
4091 -- any associated types must be frozen at this point.
4093 Freeze_Itype (Atyp, N);
4096 -- Otherwise we did not build a declaration, so return original
4103 -- For all remaining cases, the actual subtype is the same as
4104 -- the nominal type.
4109 end Get_Actual_Subtype;
4111 -------------------------------------
4112 -- Get_Actual_Subtype_If_Available --
4113 -------------------------------------
4115 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
4116 Typ : constant Entity_Id := Etype (N);
4119 -- If what we have is an identifier that references a subprogram
4120 -- formal, or a variable or constant object, then we get the actual
4121 -- subtype from the referenced entity if one has been built.
4123 if Nkind (N) = N_Identifier
4125 (Is_Formal (Entity (N))
4126 or else Ekind (Entity (N)) = E_Constant
4127 or else Ekind (Entity (N)) = E_Variable)
4128 and then Present (Actual_Subtype (Entity (N)))
4130 return Actual_Subtype (Entity (N));
4132 -- Otherwise the Etype of N is returned unchanged
4137 end Get_Actual_Subtype_If_Available;
4139 -------------------------------
4140 -- Get_Default_External_Name --
4141 -------------------------------
4143 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
4145 Get_Decoded_Name_String (Chars (E));
4147 if Opt.External_Name_Imp_Casing = Uppercase then
4148 Set_Casing (All_Upper_Case);
4150 Set_Casing (All_Lower_Case);
4154 Make_String_Literal (Sloc (E),
4155 Strval => String_From_Name_Buffer);
4156 end Get_Default_External_Name;
4158 ---------------------------
4159 -- Get_Enum_Lit_From_Pos --
4160 ---------------------------
4162 function Get_Enum_Lit_From_Pos
4165 Loc : Source_Ptr) return Node_Id
4170 -- In the case where the literal is of type Character, Wide_Character
4171 -- or Wide_Wide_Character or of a type derived from them, there needs
4172 -- to be some special handling since there is no explicit chain of
4173 -- literals to search. Instead, an N_Character_Literal node is created
4174 -- with the appropriate Char_Code and Chars fields.
4176 if Is_Standard_Character_Type (T) then
4177 Set_Character_Literal_Name (UI_To_CC (Pos));
4179 Make_Character_Literal (Loc,
4181 Char_Literal_Value => Pos);
4183 -- For all other cases, we have a complete table of literals, and
4184 -- we simply iterate through the chain of literal until the one
4185 -- with the desired position value is found.
4189 Lit := First_Literal (Base_Type (T));
4190 for J in 1 .. UI_To_Int (Pos) loop
4194 return New_Occurrence_Of (Lit, Loc);
4196 end Get_Enum_Lit_From_Pos;
4198 ------------------------
4199 -- Get_Generic_Entity --
4200 ------------------------
4202 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
4203 Ent : constant Entity_Id := Entity (Name (N));
4205 if Present (Renamed_Object (Ent)) then
4206 return Renamed_Object (Ent);
4210 end Get_Generic_Entity;
4212 ----------------------
4213 -- Get_Index_Bounds --
4214 ----------------------
4216 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
4217 Kind : constant Node_Kind := Nkind (N);
4221 if Kind = N_Range then
4223 H := High_Bound (N);
4225 elsif Kind = N_Subtype_Indication then
4226 R := Range_Expression (Constraint (N));
4234 L := Low_Bound (Range_Expression (Constraint (N)));
4235 H := High_Bound (Range_Expression (Constraint (N)));
4238 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
4239 if Error_Posted (Scalar_Range (Entity (N))) then
4243 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
4244 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
4247 L := Low_Bound (Scalar_Range (Entity (N)));
4248 H := High_Bound (Scalar_Range (Entity (N)));
4252 -- N is an expression, indicating a range with one value
4257 end Get_Index_Bounds;
4259 ----------------------------------
4260 -- Get_Library_Unit_Name_string --
4261 ----------------------------------
4263 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
4264 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
4267 Get_Unit_Name_String (Unit_Name_Id);
4269 -- Remove seven last character (" (spec)" or " (body)")
4271 Name_Len := Name_Len - 7;
4272 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
4273 end Get_Library_Unit_Name_String;
4275 ------------------------
4276 -- Get_Name_Entity_Id --
4277 ------------------------
4279 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
4281 return Entity_Id (Get_Name_Table_Info (Id));
4282 end Get_Name_Entity_Id;
4288 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
4290 return Get_Pragma_Id (Pragma_Name (N));
4293 ---------------------------
4294 -- Get_Referenced_Object --
4295 ---------------------------
4297 function Get_Referenced_Object (N : Node_Id) return Node_Id is
4302 while Is_Entity_Name (R)
4303 and then Present (Renamed_Object (Entity (R)))
4305 R := Renamed_Object (Entity (R));
4309 end Get_Referenced_Object;
4311 ------------------------
4312 -- Get_Renamed_Entity --
4313 ------------------------
4315 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
4320 while Present (Renamed_Entity (R)) loop
4321 R := Renamed_Entity (R);
4325 end Get_Renamed_Entity;
4327 -------------------------
4328 -- Get_Subprogram_Body --
4329 -------------------------
4331 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
4335 Decl := Unit_Declaration_Node (E);
4337 if Nkind (Decl) = N_Subprogram_Body then
4340 -- The below comment is bad, because it is possible for
4341 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
4343 else -- Nkind (Decl) = N_Subprogram_Declaration
4345 if Present (Corresponding_Body (Decl)) then
4346 return Unit_Declaration_Node (Corresponding_Body (Decl));
4348 -- Imported subprogram case
4354 end Get_Subprogram_Body;
4356 ---------------------------
4357 -- Get_Subprogram_Entity --
4358 ---------------------------
4360 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
4365 if Nkind (Nod) = N_Accept_Statement then
4366 Nam := Entry_Direct_Name (Nod);
4368 -- For an entry call, the prefix of the call is a selected component.
4369 -- Need additional code for internal calls ???
4371 elsif Nkind (Nod) = N_Entry_Call_Statement then
4372 if Nkind (Name (Nod)) = N_Selected_Component then
4373 Nam := Entity (Selector_Name (Name (Nod)));
4382 if Nkind (Nam) = N_Explicit_Dereference then
4383 Proc := Etype (Prefix (Nam));
4384 elsif Is_Entity_Name (Nam) then
4385 Proc := Entity (Nam);
4390 if Is_Object (Proc) then
4391 Proc := Etype (Proc);
4394 if Ekind (Proc) = E_Access_Subprogram_Type then
4395 Proc := Directly_Designated_Type (Proc);
4398 if not Is_Subprogram (Proc)
4399 and then Ekind (Proc) /= E_Subprogram_Type
4405 end Get_Subprogram_Entity;
4407 -----------------------------
4408 -- Get_Task_Body_Procedure --
4409 -----------------------------
4411 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
4413 -- Note: A task type may be the completion of a private type with
4414 -- discriminants. When performing elaboration checks on a task
4415 -- declaration, the current view of the type may be the private one,
4416 -- and the procedure that holds the body of the task is held in its
4419 -- This is an odd function, why not have Task_Body_Procedure do
4420 -- the following digging???
4422 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
4423 end Get_Task_Body_Procedure;
4425 -----------------------
4426 -- Has_Access_Values --
4427 -----------------------
4429 function Has_Access_Values (T : Entity_Id) return Boolean is
4430 Typ : constant Entity_Id := Underlying_Type (T);
4433 -- Case of a private type which is not completed yet. This can only
4434 -- happen in the case of a generic format type appearing directly, or
4435 -- as a component of the type to which this function is being applied
4436 -- at the top level. Return False in this case, since we certainly do
4437 -- not know that the type contains access types.
4442 elsif Is_Access_Type (Typ) then
4445 elsif Is_Array_Type (Typ) then
4446 return Has_Access_Values (Component_Type (Typ));
4448 elsif Is_Record_Type (Typ) then
4453 -- Loop to Check components
4455 Comp := First_Component_Or_Discriminant (Typ);
4456 while Present (Comp) loop
4458 -- Check for access component, tag field does not count, even
4459 -- though it is implemented internally using an access type.
4461 if Has_Access_Values (Etype (Comp))
4462 and then Chars (Comp) /= Name_uTag
4467 Next_Component_Or_Discriminant (Comp);
4476 end Has_Access_Values;
4478 ------------------------------
4479 -- Has_Compatible_Alignment --
4480 ------------------------------
4482 function Has_Compatible_Alignment
4484 Expr : Node_Id) return Alignment_Result
4486 function Has_Compatible_Alignment_Internal
4489 Default : Alignment_Result) return Alignment_Result;
4490 -- This is the internal recursive function that actually does the work.
4491 -- There is one additional parameter, which says what the result should
4492 -- be if no alignment information is found, and there is no definite
4493 -- indication of compatible alignments. At the outer level, this is set
4494 -- to Unknown, but for internal recursive calls in the case where types
4495 -- are known to be correct, it is set to Known_Compatible.
4497 ---------------------------------------
4498 -- Has_Compatible_Alignment_Internal --
4499 ---------------------------------------
4501 function Has_Compatible_Alignment_Internal
4504 Default : Alignment_Result) return Alignment_Result
4506 Result : Alignment_Result := Known_Compatible;
4507 -- Holds the current status of the result. Note that once a value of
4508 -- Known_Incompatible is set, it is sticky and does not get changed
4509 -- to Unknown (the value in Result only gets worse as we go along,
4512 Offs : Uint := No_Uint;
4513 -- Set to a factor of the offset from the base object when Expr is a
4514 -- selected or indexed component, based on Component_Bit_Offset and
4515 -- Component_Size respectively. A negative value is used to represent
4516 -- a value which is not known at compile time.
4518 procedure Check_Prefix;
4519 -- Checks the prefix recursively in the case where the expression
4520 -- is an indexed or selected component.
4522 procedure Set_Result (R : Alignment_Result);
4523 -- If R represents a worse outcome (unknown instead of known
4524 -- compatible, or known incompatible), then set Result to R.
4530 procedure Check_Prefix is
4532 -- The subtlety here is that in doing a recursive call to check
4533 -- the prefix, we have to decide what to do in the case where we
4534 -- don't find any specific indication of an alignment problem.
4536 -- At the outer level, we normally set Unknown as the result in
4537 -- this case, since we can only set Known_Compatible if we really
4538 -- know that the alignment value is OK, but for the recursive
4539 -- call, in the case where the types match, and we have not
4540 -- specified a peculiar alignment for the object, we are only
4541 -- concerned about suspicious rep clauses, the default case does
4542 -- not affect us, since the compiler will, in the absence of such
4543 -- rep clauses, ensure that the alignment is correct.
4545 if Default = Known_Compatible
4547 (Etype (Obj) = Etype (Expr)
4548 and then (Unknown_Alignment (Obj)
4550 Alignment (Obj) = Alignment (Etype (Obj))))
4553 (Has_Compatible_Alignment_Internal
4554 (Obj, Prefix (Expr), Known_Compatible));
4556 -- In all other cases, we need a full check on the prefix
4560 (Has_Compatible_Alignment_Internal
4561 (Obj, Prefix (Expr), Unknown));
4569 procedure Set_Result (R : Alignment_Result) is
4576 -- Start of processing for Has_Compatible_Alignment_Internal
4579 -- If Expr is a selected component, we must make sure there is no
4580 -- potentially troublesome component clause, and that the record is
4583 if Nkind (Expr) = N_Selected_Component then
4585 -- Packed record always generate unknown alignment
4587 if Is_Packed (Etype (Prefix (Expr))) then
4588 Set_Result (Unknown);
4591 -- Check prefix and component offset
4594 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
4596 -- If Expr is an indexed component, we must make sure there is no
4597 -- potentially troublesome Component_Size clause and that the array
4598 -- is not bit-packed.
4600 elsif Nkind (Expr) = N_Indexed_Component then
4602 Typ : constant Entity_Id := Etype (Prefix (Expr));
4603 Ind : constant Node_Id := First_Index (Typ);
4606 -- Bit packed array always generates unknown alignment
4608 if Is_Bit_Packed_Array (Typ) then
4609 Set_Result (Unknown);
4612 -- Check prefix and component offset
4615 Offs := Component_Size (Typ);
4617 -- Small optimization: compute the full offset when possible
4620 and then Offs > Uint_0
4621 and then Present (Ind)
4622 and then Nkind (Ind) = N_Range
4623 and then Compile_Time_Known_Value (Low_Bound (Ind))
4624 and then Compile_Time_Known_Value (First (Expressions (Expr)))
4626 Offs := Offs * (Expr_Value (First (Expressions (Expr)))
4627 - Expr_Value (Low_Bound ((Ind))));
4632 -- If we have a null offset, the result is entirely determined by
4633 -- the base object and has already been computed recursively.
4635 if Offs = Uint_0 then
4638 -- Case where we know the alignment of the object
4640 elsif Known_Alignment (Obj) then
4642 ObjA : constant Uint := Alignment (Obj);
4643 ExpA : Uint := No_Uint;
4644 SizA : Uint := No_Uint;
4647 -- If alignment of Obj is 1, then we are always OK
4650 Set_Result (Known_Compatible);
4652 -- Alignment of Obj is greater than 1, so we need to check
4655 -- If we have an offset, see if it is compatible
4657 if Offs /= No_Uint and Offs > Uint_0 then
4658 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
4659 Set_Result (Known_Incompatible);
4662 -- See if Expr is an object with known alignment
4664 elsif Is_Entity_Name (Expr)
4665 and then Known_Alignment (Entity (Expr))
4667 ExpA := Alignment (Entity (Expr));
4669 -- Otherwise, we can use the alignment of the type of
4670 -- Expr given that we already checked for
4671 -- discombobulating rep clauses for the cases of indexed
4672 -- and selected components above.
4674 elsif Known_Alignment (Etype (Expr)) then
4675 ExpA := Alignment (Etype (Expr));
4677 -- Otherwise the alignment is unknown
4680 Set_Result (Default);
4683 -- If we got an alignment, see if it is acceptable
4685 if ExpA /= No_Uint and then ExpA < ObjA then
4686 Set_Result (Known_Incompatible);
4689 -- If Expr is not a piece of a larger object, see if size
4690 -- is given. If so, check that it is not too small for the
4691 -- required alignment.
4693 if Offs /= No_Uint then
4696 -- See if Expr is an object with known size
4698 elsif Is_Entity_Name (Expr)
4699 and then Known_Static_Esize (Entity (Expr))
4701 SizA := Esize (Entity (Expr));
4703 -- Otherwise, we check the object size of the Expr type
4705 elsif Known_Static_Esize (Etype (Expr)) then
4706 SizA := Esize (Etype (Expr));
4709 -- If we got a size, see if it is a multiple of the Obj
4710 -- alignment, if not, then the alignment cannot be
4711 -- acceptable, since the size is always a multiple of the
4714 if SizA /= No_Uint then
4715 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
4716 Set_Result (Known_Incompatible);
4722 -- If we do not know required alignment, any non-zero offset is a
4723 -- potential problem (but certainly may be OK, so result is unknown).
4725 elsif Offs /= No_Uint then
4726 Set_Result (Unknown);
4728 -- If we can't find the result by direct comparison of alignment
4729 -- values, then there is still one case that we can determine known
4730 -- result, and that is when we can determine that the types are the
4731 -- same, and no alignments are specified. Then we known that the
4732 -- alignments are compatible, even if we don't know the alignment
4733 -- value in the front end.
4735 elsif Etype (Obj) = Etype (Expr) then
4737 -- Types are the same, but we have to check for possible size
4738 -- and alignments on the Expr object that may make the alignment
4739 -- different, even though the types are the same.
4741 if Is_Entity_Name (Expr) then
4743 -- First check alignment of the Expr object. Any alignment less
4744 -- than Maximum_Alignment is worrisome since this is the case
4745 -- where we do not know the alignment of Obj.
4747 if Known_Alignment (Entity (Expr))
4749 UI_To_Int (Alignment (Entity (Expr))) <
4750 Ttypes.Maximum_Alignment
4752 Set_Result (Unknown);
4754 -- Now check size of Expr object. Any size that is not an
4755 -- even multiple of Maximum_Alignment is also worrisome
4756 -- since it may cause the alignment of the object to be less
4757 -- than the alignment of the type.
4759 elsif Known_Static_Esize (Entity (Expr))
4761 (UI_To_Int (Esize (Entity (Expr))) mod
4762 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
4765 Set_Result (Unknown);
4767 -- Otherwise same type is decisive
4770 Set_Result (Known_Compatible);
4774 -- Another case to deal with is when there is an explicit size or
4775 -- alignment clause when the types are not the same. If so, then the
4776 -- result is Unknown. We don't need to do this test if the Default is
4777 -- Unknown, since that result will be set in any case.
4779 elsif Default /= Unknown
4780 and then (Has_Size_Clause (Etype (Expr))
4782 Has_Alignment_Clause (Etype (Expr)))
4784 Set_Result (Unknown);
4786 -- If no indication found, set default
4789 Set_Result (Default);
4792 -- Return worst result found
4795 end Has_Compatible_Alignment_Internal;
4797 -- Start of processing for Has_Compatible_Alignment
4800 -- If Obj has no specified alignment, then set alignment from the type
4801 -- alignment. Perhaps we should always do this, but for sure we should
4802 -- do it when there is an address clause since we can do more if the
4803 -- alignment is known.
4805 if Unknown_Alignment (Obj) then
4806 Set_Alignment (Obj, Alignment (Etype (Obj)));
4809 -- Now do the internal call that does all the work
4811 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
4812 end Has_Compatible_Alignment;
4814 ----------------------
4815 -- Has_Declarations --
4816 ----------------------
4818 function Has_Declarations (N : Node_Id) return Boolean is
4820 return Nkind_In (Nkind (N), N_Accept_Statement,
4822 N_Compilation_Unit_Aux,
4828 N_Package_Specification);
4829 end Has_Declarations;
4831 -------------------------------------------
4832 -- Has_Discriminant_Dependent_Constraint --
4833 -------------------------------------------
4835 function Has_Discriminant_Dependent_Constraint
4836 (Comp : Entity_Id) return Boolean
4838 Comp_Decl : constant Node_Id := Parent (Comp);
4839 Subt_Indic : constant Node_Id :=
4840 Subtype_Indication (Component_Definition (Comp_Decl));
4845 if Nkind (Subt_Indic) = N_Subtype_Indication then
4846 Constr := Constraint (Subt_Indic);
4848 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
4849 Assn := First (Constraints (Constr));
4850 while Present (Assn) loop
4851 case Nkind (Assn) is
4852 when N_Subtype_Indication |
4856 if Depends_On_Discriminant (Assn) then
4860 when N_Discriminant_Association =>
4861 if Depends_On_Discriminant (Expression (Assn)) then
4876 end Has_Discriminant_Dependent_Constraint;
4878 --------------------
4879 -- Has_Infinities --
4880 --------------------
4882 function Has_Infinities (E : Entity_Id) return Boolean is
4885 Is_Floating_Point_Type (E)
4886 and then Nkind (Scalar_Range (E)) = N_Range
4887 and then Includes_Infinities (Scalar_Range (E));
4890 --------------------
4891 -- Has_Interfaces --
4892 --------------------
4894 function Has_Interfaces
4896 Use_Full_View : Boolean := True) return Boolean
4898 Typ : Entity_Id := Base_Type (T);
4901 -- Handle concurrent types
4903 if Is_Concurrent_Type (Typ) then
4904 Typ := Corresponding_Record_Type (Typ);
4907 if not Present (Typ)
4908 or else not Is_Record_Type (Typ)
4909 or else not Is_Tagged_Type (Typ)
4914 -- Handle private types
4917 and then Present (Full_View (Typ))
4919 Typ := Full_View (Typ);
4922 -- Handle concurrent record types
4924 if Is_Concurrent_Record_Type (Typ)
4925 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
4931 if Is_Interface (Typ)
4933 (Is_Record_Type (Typ)
4934 and then Present (Interfaces (Typ))
4935 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
4940 exit when Etype (Typ) = Typ
4942 -- Handle private types
4944 or else (Present (Full_View (Etype (Typ)))
4945 and then Full_View (Etype (Typ)) = Typ)
4947 -- Protect the frontend against wrong source with cyclic
4950 or else Etype (Typ) = T;
4952 -- Climb to the ancestor type handling private types
4954 if Present (Full_View (Etype (Typ))) then
4955 Typ := Full_View (Etype (Typ));
4964 ------------------------
4965 -- Has_Null_Exclusion --
4966 ------------------------
4968 function Has_Null_Exclusion (N : Node_Id) return Boolean is
4971 when N_Access_Definition |
4972 N_Access_Function_Definition |
4973 N_Access_Procedure_Definition |
4974 N_Access_To_Object_Definition |
4976 N_Derived_Type_Definition |
4977 N_Function_Specification |
4978 N_Subtype_Declaration =>
4979 return Null_Exclusion_Present (N);
4981 when N_Component_Definition |
4982 N_Formal_Object_Declaration |
4983 N_Object_Renaming_Declaration =>
4984 if Present (Subtype_Mark (N)) then
4985 return Null_Exclusion_Present (N);
4986 else pragma Assert (Present (Access_Definition (N)));
4987 return Null_Exclusion_Present (Access_Definition (N));
4990 when N_Discriminant_Specification =>
4991 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
4992 return Null_Exclusion_Present (Discriminant_Type (N));
4994 return Null_Exclusion_Present (N);
4997 when N_Object_Declaration =>
4998 if Nkind (Object_Definition (N)) = N_Access_Definition then
4999 return Null_Exclusion_Present (Object_Definition (N));
5001 return Null_Exclusion_Present (N);
5004 when N_Parameter_Specification =>
5005 if Nkind (Parameter_Type (N)) = N_Access_Definition then
5006 return Null_Exclusion_Present (Parameter_Type (N));
5008 return Null_Exclusion_Present (N);
5015 end Has_Null_Exclusion;
5017 ------------------------
5018 -- Has_Null_Extension --
5019 ------------------------
5021 function Has_Null_Extension (T : Entity_Id) return Boolean is
5022 B : constant Entity_Id := Base_Type (T);
5027 if Nkind (Parent (B)) = N_Full_Type_Declaration
5028 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
5030 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
5032 if Present (Ext) then
5033 if Null_Present (Ext) then
5036 Comps := Component_List (Ext);
5038 -- The null component list is rewritten during analysis to
5039 -- include the parent component. Any other component indicates
5040 -- that the extension was not originally null.
5042 return Null_Present (Comps)
5043 or else No (Next (First (Component_Items (Comps))));
5052 end Has_Null_Extension;
5054 -------------------------------
5055 -- Has_Overriding_Initialize --
5056 -------------------------------
5058 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
5059 BT : constant Entity_Id := Base_Type (T);
5063 if Is_Controlled (BT) then
5064 if Is_RTU (Scope (BT), Ada_Finalization) then
5067 elsif Present (Primitive_Operations (BT)) then
5068 P := First_Elmt (Primitive_Operations (BT));
5069 while Present (P) loop
5071 Init : constant Entity_Id := Node (P);
5072 Formal : constant Entity_Id := First_Formal (Init);
5074 if Ekind (Init) = E_Procedure
5075 and then Chars (Init) = Name_Initialize
5076 and then Comes_From_Source (Init)
5077 and then Present (Formal)
5078 and then Etype (Formal) = BT
5079 and then No (Next_Formal (Formal))
5080 and then (Ada_Version < Ada_2012
5081 or else not Null_Present (Parent (Init)))
5091 -- Here if type itself does not have a non-null Initialize operation:
5092 -- check immediate ancestor.
5094 if Is_Derived_Type (BT)
5095 and then Has_Overriding_Initialize (Etype (BT))
5102 end Has_Overriding_Initialize;
5104 --------------------------------------
5105 -- Has_Preelaborable_Initialization --
5106 --------------------------------------
5108 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
5111 procedure Check_Components (E : Entity_Id);
5112 -- Check component/discriminant chain, sets Has_PE False if a component
5113 -- or discriminant does not meet the preelaborable initialization rules.
5115 ----------------------
5116 -- Check_Components --
5117 ----------------------
5119 procedure Check_Components (E : Entity_Id) is
5123 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
5124 -- Returns True if and only if the expression denoted by N does not
5125 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
5127 ---------------------------------
5128 -- Is_Preelaborable_Expression --
5129 ---------------------------------
5131 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
5135 Comp_Type : Entity_Id;
5136 Is_Array_Aggr : Boolean;
5139 if Is_Static_Expression (N) then
5142 elsif Nkind (N) = N_Null then
5145 -- Attributes are allowed in general, even if their prefix is a
5146 -- formal type. (It seems that certain attributes known not to be
5147 -- static might not be allowed, but there are no rules to prevent
5150 elsif Nkind (N) = N_Attribute_Reference then
5153 -- The name of a discriminant evaluated within its parent type is
5154 -- defined to be preelaborable (10.2.1(8)). Note that we test for
5155 -- names that denote discriminals as well as discriminants to
5156 -- catch references occurring within init procs.
5158 elsif Is_Entity_Name (N)
5160 (Ekind (Entity (N)) = E_Discriminant
5162 ((Ekind (Entity (N)) = E_Constant
5163 or else Ekind (Entity (N)) = E_In_Parameter)
5164 and then Present (Discriminal_Link (Entity (N)))))
5168 elsif Nkind (N) = N_Qualified_Expression then
5169 return Is_Preelaborable_Expression (Expression (N));
5171 -- For aggregates we have to check that each of the associations
5172 -- is preelaborable.
5174 elsif Nkind (N) = N_Aggregate
5175 or else Nkind (N) = N_Extension_Aggregate
5177 Is_Array_Aggr := Is_Array_Type (Etype (N));
5179 if Is_Array_Aggr then
5180 Comp_Type := Component_Type (Etype (N));
5183 -- Check the ancestor part of extension aggregates, which must
5184 -- be either the name of a type that has preelaborable init or
5185 -- an expression that is preelaborable.
5187 if Nkind (N) = N_Extension_Aggregate then
5189 Anc_Part : constant Node_Id := Ancestor_Part (N);
5192 if Is_Entity_Name (Anc_Part)
5193 and then Is_Type (Entity (Anc_Part))
5195 if not Has_Preelaborable_Initialization
5201 elsif not Is_Preelaborable_Expression (Anc_Part) then
5207 -- Check positional associations
5209 Exp := First (Expressions (N));
5210 while Present (Exp) loop
5211 if not Is_Preelaborable_Expression (Exp) then
5218 -- Check named associations
5220 Assn := First (Component_Associations (N));
5221 while Present (Assn) loop
5222 Choice := First (Choices (Assn));
5223 while Present (Choice) loop
5224 if Is_Array_Aggr then
5225 if Nkind (Choice) = N_Others_Choice then
5228 elsif Nkind (Choice) = N_Range then
5229 if not Is_Static_Range (Choice) then
5233 elsif not Is_Static_Expression (Choice) then
5238 Comp_Type := Etype (Choice);
5244 -- If the association has a <> at this point, then we have
5245 -- to check whether the component's type has preelaborable
5246 -- initialization. Note that this only occurs when the
5247 -- association's corresponding component does not have a
5248 -- default expression, the latter case having already been
5249 -- expanded as an expression for the association.
5251 if Box_Present (Assn) then
5252 if not Has_Preelaborable_Initialization (Comp_Type) then
5256 -- In the expression case we check whether the expression
5257 -- is preelaborable.
5260 not Is_Preelaborable_Expression (Expression (Assn))
5268 -- If we get here then aggregate as a whole is preelaborable
5272 -- All other cases are not preelaborable
5277 end Is_Preelaborable_Expression;
5279 -- Start of processing for Check_Components
5282 -- Loop through entities of record or protected type
5285 while Present (Ent) loop
5287 -- We are interested only in components and discriminants
5294 -- Get default expression if any. If there is no declaration
5295 -- node, it means we have an internal entity. The parent and
5296 -- tag fields are examples of such entities. For such cases,
5297 -- we just test the type of the entity.
5299 if Present (Declaration_Node (Ent)) then
5300 Exp := Expression (Declaration_Node (Ent));
5303 when E_Discriminant =>
5305 -- Note: for a renamed discriminant, the Declaration_Node
5306 -- may point to the one from the ancestor, and have a
5307 -- different expression, so use the proper attribute to
5308 -- retrieve the expression from the derived constraint.
5310 Exp := Discriminant_Default_Value (Ent);
5313 goto Check_Next_Entity;
5316 -- A component has PI if it has no default expression and the
5317 -- component type has PI.
5320 if not Has_Preelaborable_Initialization (Etype (Ent)) then
5325 -- Require the default expression to be preelaborable
5327 elsif not Is_Preelaborable_Expression (Exp) then
5332 <<Check_Next_Entity>>
5335 end Check_Components;
5337 -- Start of processing for Has_Preelaborable_Initialization
5340 -- Immediate return if already marked as known preelaborable init. This
5341 -- covers types for which this function has already been called once
5342 -- and returned True (in which case the result is cached), and also
5343 -- types to which a pragma Preelaborable_Initialization applies.
5345 if Known_To_Have_Preelab_Init (E) then
5349 -- If the type is a subtype representing a generic actual type, then
5350 -- test whether its base type has preelaborable initialization since
5351 -- the subtype representing the actual does not inherit this attribute
5352 -- from the actual or formal. (but maybe it should???)
5354 if Is_Generic_Actual_Type (E) then
5355 return Has_Preelaborable_Initialization (Base_Type (E));
5358 -- All elementary types have preelaborable initialization
5360 if Is_Elementary_Type (E) then
5363 -- Array types have PI if the component type has PI
5365 elsif Is_Array_Type (E) then
5366 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
5368 -- A derived type has preelaborable initialization if its parent type
5369 -- has preelaborable initialization and (in the case of a derived record
5370 -- extension) if the non-inherited components all have preelaborable
5371 -- initialization. However, a user-defined controlled type with an
5372 -- overriding Initialize procedure does not have preelaborable
5375 elsif Is_Derived_Type (E) then
5377 -- If the derived type is a private extension then it doesn't have
5378 -- preelaborable initialization.
5380 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
5384 -- First check whether ancestor type has preelaborable initialization
5386 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
5388 -- If OK, check extension components (if any)
5390 if Has_PE and then Is_Record_Type (E) then
5391 Check_Components (First_Entity (E));
5394 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
5395 -- with a user defined Initialize procedure does not have PI.
5398 and then Is_Controlled (E)
5399 and then Has_Overriding_Initialize (E)
5404 -- Private types not derived from a type having preelaborable init and
5405 -- that are not marked with pragma Preelaborable_Initialization do not
5406 -- have preelaborable initialization.
5408 elsif Is_Private_Type (E) then
5411 -- Record type has PI if it is non private and all components have PI
5413 elsif Is_Record_Type (E) then
5415 Check_Components (First_Entity (E));
5417 -- Protected types must not have entries, and components must meet
5418 -- same set of rules as for record components.
5420 elsif Is_Protected_Type (E) then
5421 if Has_Entries (E) then
5425 Check_Components (First_Entity (E));
5426 Check_Components (First_Private_Entity (E));
5429 -- Type System.Address always has preelaborable initialization
5431 elsif Is_RTE (E, RE_Address) then
5434 -- In all other cases, type does not have preelaborable initialization
5440 -- If type has preelaborable initialization, cache result
5443 Set_Known_To_Have_Preelab_Init (E);
5447 end Has_Preelaborable_Initialization;
5449 ---------------------------
5450 -- Has_Private_Component --
5451 ---------------------------
5453 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
5454 Btype : Entity_Id := Base_Type (Type_Id);
5455 Component : Entity_Id;
5458 if Error_Posted (Type_Id)
5459 or else Error_Posted (Btype)
5464 if Is_Class_Wide_Type (Btype) then
5465 Btype := Root_Type (Btype);
5468 if Is_Private_Type (Btype) then
5470 UT : constant Entity_Id := Underlying_Type (Btype);
5473 if No (Full_View (Btype)) then
5474 return not Is_Generic_Type (Btype)
5475 and then not Is_Generic_Type (Root_Type (Btype));
5477 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
5480 return not Is_Frozen (UT) and then Has_Private_Component (UT);
5484 elsif Is_Array_Type (Btype) then
5485 return Has_Private_Component (Component_Type (Btype));
5487 elsif Is_Record_Type (Btype) then
5488 Component := First_Component (Btype);
5489 while Present (Component) loop
5490 if Has_Private_Component (Etype (Component)) then
5494 Next_Component (Component);
5499 elsif Is_Protected_Type (Btype)
5500 and then Present (Corresponding_Record_Type (Btype))
5502 return Has_Private_Component (Corresponding_Record_Type (Btype));
5507 end Has_Private_Component;
5513 function Has_Stream (T : Entity_Id) return Boolean is
5520 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
5523 elsif Is_Array_Type (T) then
5524 return Has_Stream (Component_Type (T));
5526 elsif Is_Record_Type (T) then
5527 E := First_Component (T);
5528 while Present (E) loop
5529 if Has_Stream (Etype (E)) then
5538 elsif Is_Private_Type (T) then
5539 return Has_Stream (Underlying_Type (T));
5550 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
5552 Get_Name_String (Chars (E));
5553 return Name_Buffer (Name_Len) = Suffix;
5556 --------------------------
5557 -- Has_Tagged_Component --
5558 --------------------------
5560 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
5564 if Is_Private_Type (Typ)
5565 and then Present (Underlying_Type (Typ))
5567 return Has_Tagged_Component (Underlying_Type (Typ));
5569 elsif Is_Array_Type (Typ) then
5570 return Has_Tagged_Component (Component_Type (Typ));
5572 elsif Is_Tagged_Type (Typ) then
5575 elsif Is_Record_Type (Typ) then
5576 Comp := First_Component (Typ);
5577 while Present (Comp) loop
5578 if Has_Tagged_Component (Etype (Comp)) then
5582 Next_Component (Comp);
5590 end Has_Tagged_Component;
5592 -------------------------
5593 -- Implementation_Kind --
5594 -------------------------
5596 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
5597 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
5599 pragma Assert (Present (Impl_Prag));
5601 Chars (Expression (Last (Pragma_Argument_Associations (Impl_Prag))));
5602 end Implementation_Kind;
5604 --------------------------
5605 -- Implements_Interface --
5606 --------------------------
5608 function Implements_Interface
5609 (Typ_Ent : Entity_Id;
5610 Iface_Ent : Entity_Id;
5611 Exclude_Parents : Boolean := False) return Boolean
5613 Ifaces_List : Elist_Id;
5615 Iface : Entity_Id := Base_Type (Iface_Ent);
5616 Typ : Entity_Id := Base_Type (Typ_Ent);
5619 if Is_Class_Wide_Type (Typ) then
5620 Typ := Root_Type (Typ);
5623 if not Has_Interfaces (Typ) then
5627 if Is_Class_Wide_Type (Iface) then
5628 Iface := Root_Type (Iface);
5631 Collect_Interfaces (Typ, Ifaces_List);
5633 Elmt := First_Elmt (Ifaces_List);
5634 while Present (Elmt) loop
5635 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
5636 and then Exclude_Parents
5640 elsif Node (Elmt) = Iface then
5648 end Implements_Interface;
5654 function In_Instance return Boolean is
5655 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
5661 and then S /= Standard_Standard
5663 if (Ekind (S) = E_Function
5664 or else Ekind (S) = E_Package
5665 or else Ekind (S) = E_Procedure)
5666 and then Is_Generic_Instance (S)
5668 -- A child instance is always compiled in the context of a parent
5669 -- instance. Nevertheless, the actuals are not analyzed in an
5670 -- instance context. We detect this case by examining the current
5671 -- compilation unit, which must be a child instance, and checking
5672 -- that it is not currently on the scope stack.
5674 if Is_Child_Unit (Curr_Unit)
5676 Nkind (Unit (Cunit (Current_Sem_Unit)))
5677 = N_Package_Instantiation
5678 and then not In_Open_Scopes (Curr_Unit)
5692 ----------------------
5693 -- In_Instance_Body --
5694 ----------------------
5696 function In_Instance_Body return Boolean is
5702 and then S /= Standard_Standard
5704 if (Ekind (S) = E_Function
5705 or else Ekind (S) = E_Procedure)
5706 and then Is_Generic_Instance (S)
5710 elsif Ekind (S) = E_Package
5711 and then In_Package_Body (S)
5712 and then Is_Generic_Instance (S)
5721 end In_Instance_Body;
5723 -----------------------------
5724 -- In_Instance_Not_Visible --
5725 -----------------------------
5727 function In_Instance_Not_Visible return Boolean is
5733 and then S /= Standard_Standard
5735 if (Ekind (S) = E_Function
5736 or else Ekind (S) = E_Procedure)
5737 and then Is_Generic_Instance (S)
5741 elsif Ekind (S) = E_Package
5742 and then (In_Package_Body (S) or else In_Private_Part (S))
5743 and then Is_Generic_Instance (S)
5752 end In_Instance_Not_Visible;
5754 ------------------------------
5755 -- In_Instance_Visible_Part --
5756 ------------------------------
5758 function In_Instance_Visible_Part return Boolean is
5764 and then S /= Standard_Standard
5766 if Ekind (S) = E_Package
5767 and then Is_Generic_Instance (S)
5768 and then not In_Package_Body (S)
5769 and then not In_Private_Part (S)
5778 end In_Instance_Visible_Part;
5780 ---------------------
5781 -- In_Package_Body --
5782 ---------------------
5784 function In_Package_Body return Boolean is
5790 and then S /= Standard_Standard
5792 if Ekind (S) = E_Package
5793 and then In_Package_Body (S)
5802 end In_Package_Body;
5804 --------------------------------
5805 -- In_Parameter_Specification --
5806 --------------------------------
5808 function In_Parameter_Specification (N : Node_Id) return Boolean is
5813 while Present (PN) loop
5814 if Nkind (PN) = N_Parameter_Specification then
5822 end In_Parameter_Specification;
5824 --------------------------------------
5825 -- In_Subprogram_Or_Concurrent_Unit --
5826 --------------------------------------
5828 function In_Subprogram_Or_Concurrent_Unit return Boolean is
5833 -- Use scope chain to check successively outer scopes
5839 if K in Subprogram_Kind
5840 or else K in Concurrent_Kind
5841 or else K in Generic_Subprogram_Kind
5845 elsif E = Standard_Standard then
5851 end In_Subprogram_Or_Concurrent_Unit;
5853 ---------------------
5854 -- In_Visible_Part --
5855 ---------------------
5857 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
5860 Is_Package_Or_Generic_Package (Scope_Id)
5861 and then In_Open_Scopes (Scope_Id)
5862 and then not In_Package_Body (Scope_Id)
5863 and then not In_Private_Part (Scope_Id);
5864 end In_Visible_Part;
5866 ---------------------------------
5867 -- Insert_Explicit_Dereference --
5868 ---------------------------------
5870 procedure Insert_Explicit_Dereference (N : Node_Id) is
5871 New_Prefix : constant Node_Id := Relocate_Node (N);
5872 Ent : Entity_Id := Empty;
5879 Save_Interps (N, New_Prefix);
5882 Make_Explicit_Dereference (Sloc (Parent (N)),
5883 Prefix => New_Prefix));
5885 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
5887 if Is_Overloaded (New_Prefix) then
5889 -- The dereference is also overloaded, and its interpretations are
5890 -- the designated types of the interpretations of the original node.
5892 Set_Etype (N, Any_Type);
5894 Get_First_Interp (New_Prefix, I, It);
5895 while Present (It.Nam) loop
5898 if Is_Access_Type (T) then
5899 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
5902 Get_Next_Interp (I, It);
5908 -- Prefix is unambiguous: mark the original prefix (which might
5909 -- Come_From_Source) as a reference, since the new (relocated) one
5910 -- won't be taken into account.
5912 if Is_Entity_Name (New_Prefix) then
5913 Ent := Entity (New_Prefix);
5916 -- For a retrieval of a subcomponent of some composite object,
5917 -- retrieve the ultimate entity if there is one.
5919 elsif Nkind (New_Prefix) = N_Selected_Component
5920 or else Nkind (New_Prefix) = N_Indexed_Component
5922 Pref := Prefix (New_Prefix);
5923 while Present (Pref)
5925 (Nkind (Pref) = N_Selected_Component
5926 or else Nkind (Pref) = N_Indexed_Component)
5928 Pref := Prefix (Pref);
5931 if Present (Pref) and then Is_Entity_Name (Pref) then
5932 Ent := Entity (Pref);
5936 -- Place the reference on the entity node
5938 if Present (Ent) then
5939 Generate_Reference (Ent, Pref);
5942 end Insert_Explicit_Dereference;
5944 ------------------------------------------
5945 -- Inspect_Deferred_Constant_Completion --
5946 ------------------------------------------
5948 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
5952 Decl := First (Decls);
5953 while Present (Decl) loop
5955 -- Deferred constant signature
5957 if Nkind (Decl) = N_Object_Declaration
5958 and then Constant_Present (Decl)
5959 and then No (Expression (Decl))
5961 -- No need to check internally generated constants
5963 and then Comes_From_Source (Decl)
5965 -- The constant is not completed. A full object declaration or a
5966 -- pragma Import complete a deferred constant.
5968 and then not Has_Completion (Defining_Identifier (Decl))
5971 ("constant declaration requires initialization expression",
5972 Defining_Identifier (Decl));
5975 Decl := Next (Decl);
5977 end Inspect_Deferred_Constant_Completion;
5979 -----------------------------
5980 -- Is_Actual_Out_Parameter --
5981 -----------------------------
5983 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
5987 Find_Actual (N, Formal, Call);
5988 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
5989 end Is_Actual_Out_Parameter;
5991 -------------------------
5992 -- Is_Actual_Parameter --
5993 -------------------------
5995 function Is_Actual_Parameter (N : Node_Id) return Boolean is
5996 PK : constant Node_Kind := Nkind (Parent (N));
6000 when N_Parameter_Association =>
6001 return N = Explicit_Actual_Parameter (Parent (N));
6003 when N_Function_Call | N_Procedure_Call_Statement =>
6004 return Is_List_Member (N)
6006 List_Containing (N) = Parameter_Associations (Parent (N));
6011 end Is_Actual_Parameter;
6013 --------------------------------
6014 -- Is_Actual_Tagged_Parameter --
6015 --------------------------------
6017 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
6021 Find_Actual (N, Formal, Call);
6022 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
6023 end Is_Actual_Tagged_Parameter;
6025 ---------------------
6026 -- Is_Aliased_View --
6027 ---------------------
6029 function Is_Aliased_View (Obj : Node_Id) return Boolean is
6033 if Is_Entity_Name (Obj) then
6041 or else (Present (Renamed_Object (E))
6042 and then Is_Aliased_View (Renamed_Object (E)))))
6044 or else ((Is_Formal (E)
6045 or else Ekind (E) = E_Generic_In_Out_Parameter
6046 or else Ekind (E) = E_Generic_In_Parameter)
6047 and then Is_Tagged_Type (Etype (E)))
6049 or else (Is_Concurrent_Type (E)
6050 and then In_Open_Scopes (E))
6052 -- Current instance of type, either directly or as rewritten
6053 -- reference to the current object.
6055 or else (Is_Entity_Name (Original_Node (Obj))
6056 and then Present (Entity (Original_Node (Obj)))
6057 and then Is_Type (Entity (Original_Node (Obj))))
6059 or else (Is_Type (E) and then E = Current_Scope)
6061 or else (Is_Incomplete_Or_Private_Type (E)
6062 and then Full_View (E) = Current_Scope);
6064 elsif Nkind (Obj) = N_Selected_Component then
6065 return Is_Aliased (Entity (Selector_Name (Obj)));
6067 elsif Nkind (Obj) = N_Indexed_Component then
6068 return Has_Aliased_Components (Etype (Prefix (Obj)))
6070 (Is_Access_Type (Etype (Prefix (Obj)))
6072 Has_Aliased_Components
6073 (Designated_Type (Etype (Prefix (Obj)))));
6075 elsif Nkind (Obj) = N_Unchecked_Type_Conversion
6076 or else Nkind (Obj) = N_Type_Conversion
6078 return Is_Tagged_Type (Etype (Obj))
6079 and then Is_Aliased_View (Expression (Obj));
6081 elsif Nkind (Obj) = N_Explicit_Dereference then
6082 return Nkind (Original_Node (Obj)) /= N_Function_Call;
6087 end Is_Aliased_View;
6089 -------------------------
6090 -- Is_Ancestor_Package --
6091 -------------------------
6093 function Is_Ancestor_Package
6095 E2 : Entity_Id) return Boolean
6102 and then Par /= Standard_Standard
6112 end Is_Ancestor_Package;
6114 ----------------------
6115 -- Is_Atomic_Object --
6116 ----------------------
6118 function Is_Atomic_Object (N : Node_Id) return Boolean is
6120 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
6121 -- Determines if given object has atomic components
6123 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
6124 -- If prefix is an implicit dereference, examine designated type
6126 ----------------------
6127 -- Is_Atomic_Prefix --
6128 ----------------------
6130 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
6132 if Is_Access_Type (Etype (N)) then
6134 Has_Atomic_Components (Designated_Type (Etype (N)));
6136 return Object_Has_Atomic_Components (N);
6138 end Is_Atomic_Prefix;
6140 ----------------------------------
6141 -- Object_Has_Atomic_Components --
6142 ----------------------------------
6144 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
6146 if Has_Atomic_Components (Etype (N))
6147 or else Is_Atomic (Etype (N))
6151 elsif Is_Entity_Name (N)
6152 and then (Has_Atomic_Components (Entity (N))
6153 or else Is_Atomic (Entity (N)))
6157 elsif Nkind (N) = N_Indexed_Component
6158 or else Nkind (N) = N_Selected_Component
6160 return Is_Atomic_Prefix (Prefix (N));
6165 end Object_Has_Atomic_Components;
6167 -- Start of processing for Is_Atomic_Object
6170 -- Predicate is not relevant to subprograms
6172 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
6175 elsif Is_Atomic (Etype (N))
6176 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
6180 elsif Nkind (N) = N_Indexed_Component
6181 or else Nkind (N) = N_Selected_Component
6183 return Is_Atomic_Prefix (Prefix (N));
6188 end Is_Atomic_Object;
6190 -------------------------
6191 -- Is_Coextension_Root --
6192 -------------------------
6194 function Is_Coextension_Root (N : Node_Id) return Boolean is
6197 Nkind (N) = N_Allocator
6198 and then Present (Coextensions (N))
6200 -- Anonymous access discriminants carry a list of all nested
6201 -- controlled coextensions.
6203 and then not Is_Dynamic_Coextension (N)
6204 and then not Is_Static_Coextension (N);
6205 end Is_Coextension_Root;
6207 -----------------------------
6208 -- Is_Concurrent_Interface --
6209 -----------------------------
6211 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
6216 (Is_Protected_Interface (T)
6217 or else Is_Synchronized_Interface (T)
6218 or else Is_Task_Interface (T));
6219 end Is_Concurrent_Interface;
6221 --------------------------------------
6222 -- Is_Controlling_Limited_Procedure --
6223 --------------------------------------
6225 function Is_Controlling_Limited_Procedure
6226 (Proc_Nam : Entity_Id) return Boolean
6228 Param_Typ : Entity_Id := Empty;
6231 if Ekind (Proc_Nam) = E_Procedure
6232 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
6234 Param_Typ := Etype (Parameter_Type (First (
6235 Parameter_Specifications (Parent (Proc_Nam)))));
6237 -- In this case where an Itype was created, the procedure call has been
6240 elsif Present (Associated_Node_For_Itype (Proc_Nam))
6241 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
6243 Present (Parameter_Associations
6244 (Associated_Node_For_Itype (Proc_Nam)))
6247 Etype (First (Parameter_Associations
6248 (Associated_Node_For_Itype (Proc_Nam))));
6251 if Present (Param_Typ) then
6253 Is_Interface (Param_Typ)
6254 and then Is_Limited_Record (Param_Typ);
6258 end Is_Controlling_Limited_Procedure;
6260 -----------------------------
6261 -- Is_CPP_Constructor_Call --
6262 -----------------------------
6264 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
6266 return Nkind (N) = N_Function_Call
6267 and then Is_CPP_Class (Etype (Etype (N)))
6268 and then Is_Constructor (Entity (Name (N)))
6269 and then Is_Imported (Entity (Name (N)));
6270 end Is_CPP_Constructor_Call;
6276 function Is_Delegate (T : Entity_Id) return Boolean is
6277 Desig_Type : Entity_Id;
6280 if VM_Target /= CLI_Target then
6284 -- Access-to-subprograms are delegates in CIL
6286 if Ekind (T) = E_Access_Subprogram_Type then
6290 if Ekind (T) not in Access_Kind then
6292 -- A delegate is a managed pointer. If no designated type is defined
6293 -- it means that it's not a delegate.
6298 Desig_Type := Etype (Directly_Designated_Type (T));
6300 if not Is_Tagged_Type (Desig_Type) then
6304 -- Test if the type is inherited from [mscorlib]System.Delegate
6306 while Etype (Desig_Type) /= Desig_Type loop
6307 if Chars (Scope (Desig_Type)) /= No_Name
6308 and then Is_Imported (Scope (Desig_Type))
6309 and then Get_Name_String (Chars (Scope (Desig_Type))) = "delegate"
6314 Desig_Type := Etype (Desig_Type);
6320 ----------------------------------------------
6321 -- Is_Dependent_Component_Of_Mutable_Object --
6322 ----------------------------------------------
6324 function Is_Dependent_Component_Of_Mutable_Object
6325 (Object : Node_Id) return Boolean
6328 Prefix_Type : Entity_Id;
6329 P_Aliased : Boolean := False;
6332 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
6333 -- Returns True if and only if Comp is declared within a variant part
6335 --------------------------------
6336 -- Is_Declared_Within_Variant --
6337 --------------------------------
6339 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
6340 Comp_Decl : constant Node_Id := Parent (Comp);
6341 Comp_List : constant Node_Id := Parent (Comp_Decl);
6343 return Nkind (Parent (Comp_List)) = N_Variant;
6344 end Is_Declared_Within_Variant;
6346 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
6349 if Is_Variable (Object) then
6351 if Nkind (Object) = N_Selected_Component then
6352 P := Prefix (Object);
6353 Prefix_Type := Etype (P);
6355 if Is_Entity_Name (P) then
6357 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
6358 Prefix_Type := Base_Type (Prefix_Type);
6361 if Is_Aliased (Entity (P)) then
6365 -- A discriminant check on a selected component may be expanded
6366 -- into a dereference when removing side-effects. Recover the
6367 -- original node and its type, which may be unconstrained.
6369 elsif Nkind (P) = N_Explicit_Dereference
6370 and then not (Comes_From_Source (P))
6372 P := Original_Node (P);
6373 Prefix_Type := Etype (P);
6376 -- Check for prefix being an aliased component???
6382 -- A heap object is constrained by its initial value
6384 -- Ada 2005 (AI-363): Always assume the object could be mutable in
6385 -- the dereferenced case, since the access value might denote an
6386 -- unconstrained aliased object, whereas in Ada 95 the designated
6387 -- object is guaranteed to be constrained. A worst-case assumption
6388 -- has to apply in Ada 2005 because we can't tell at compile time
6389 -- whether the object is "constrained by its initial value"
6390 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
6391 -- semantic rules -- these rules are acknowledged to need fixing).
6393 if Ada_Version < Ada_2005 then
6394 if Is_Access_Type (Prefix_Type)
6395 or else Nkind (P) = N_Explicit_Dereference
6400 elsif Ada_Version >= Ada_2005 then
6401 if Is_Access_Type (Prefix_Type) then
6403 -- If the access type is pool-specific, and there is no
6404 -- constrained partial view of the designated type, then the
6405 -- designated object is known to be constrained.
6407 if Ekind (Prefix_Type) = E_Access_Type
6408 and then not Has_Constrained_Partial_View
6409 (Designated_Type (Prefix_Type))
6413 -- Otherwise (general access type, or there is a constrained
6414 -- partial view of the designated type), we need to check
6415 -- based on the designated type.
6418 Prefix_Type := Designated_Type (Prefix_Type);
6424 Original_Record_Component (Entity (Selector_Name (Object)));
6426 -- As per AI-0017, the renaming is illegal in a generic body, even
6427 -- if the subtype is indefinite.
6429 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
6431 if not Is_Constrained (Prefix_Type)
6432 and then (not Is_Indefinite_Subtype (Prefix_Type)
6434 (Is_Generic_Type (Prefix_Type)
6435 and then Ekind (Current_Scope) = E_Generic_Package
6436 and then In_Package_Body (Current_Scope)))
6438 and then (Is_Declared_Within_Variant (Comp)
6439 or else Has_Discriminant_Dependent_Constraint (Comp))
6440 and then (not P_Aliased or else Ada_Version >= Ada_2005)
6446 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
6450 elsif Nkind (Object) = N_Indexed_Component
6451 or else Nkind (Object) = N_Slice
6453 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
6455 -- A type conversion that Is_Variable is a view conversion:
6456 -- go back to the denoted object.
6458 elsif Nkind (Object) = N_Type_Conversion then
6460 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
6465 end Is_Dependent_Component_Of_Mutable_Object;
6467 ---------------------
6468 -- Is_Dereferenced --
6469 ---------------------
6471 function Is_Dereferenced (N : Node_Id) return Boolean is
6472 P : constant Node_Id := Parent (N);
6475 (Nkind (P) = N_Selected_Component
6477 Nkind (P) = N_Explicit_Dereference
6479 Nkind (P) = N_Indexed_Component
6481 Nkind (P) = N_Slice)
6482 and then Prefix (P) = N;
6483 end Is_Dereferenced;
6485 ----------------------
6486 -- Is_Descendent_Of --
6487 ----------------------
6489 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
6494 pragma Assert (Nkind (T1) in N_Entity);
6495 pragma Assert (Nkind (T2) in N_Entity);
6497 T := Base_Type (T1);
6499 -- Immediate return if the types match
6504 -- Comment needed here ???
6506 elsif Ekind (T) = E_Class_Wide_Type then
6507 return Etype (T) = T2;
6515 -- Done if we found the type we are looking for
6520 -- Done if no more derivations to check
6527 -- Following test catches error cases resulting from prev errors
6529 elsif No (Etyp) then
6532 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
6535 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
6539 T := Base_Type (Etyp);
6542 end Is_Descendent_Of;
6544 ----------------------------
6545 -- Is_Expression_Function --
6546 ----------------------------
6548 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
6549 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
6552 return Ekind (Subp) = E_Function
6553 and then Nkind (Decl) = N_Subprogram_Declaration
6555 (Nkind (Original_Node (Decl)) = N_Expression_Function
6557 (Present (Corresponding_Body (Decl))
6559 Nkind (Original_Node
6560 (Unit_Declaration_Node (Corresponding_Body (Decl))))
6561 = N_Expression_Function));
6562 end Is_Expression_Function;
6568 function Is_False (U : Uint) return Boolean is
6573 ---------------------------
6574 -- Is_Fixed_Model_Number --
6575 ---------------------------
6577 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
6578 S : constant Ureal := Small_Value (T);
6579 M : Urealp.Save_Mark;
6583 R := (U = UR_Trunc (U / S) * S);
6586 end Is_Fixed_Model_Number;
6588 -------------------------------
6589 -- Is_Fully_Initialized_Type --
6590 -------------------------------
6592 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
6594 if Is_Scalar_Type (Typ) then
6597 elsif Is_Access_Type (Typ) then
6600 elsif Is_Array_Type (Typ) then
6601 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
6605 -- An interesting case, if we have a constrained type one of whose
6606 -- bounds is known to be null, then there are no elements to be
6607 -- initialized, so all the elements are initialized!
6609 if Is_Constrained (Typ) then
6612 Indx_Typ : Entity_Id;
6616 Indx := First_Index (Typ);
6617 while Present (Indx) loop
6618 if Etype (Indx) = Any_Type then
6621 -- If index is a range, use directly
6623 elsif Nkind (Indx) = N_Range then
6624 Lbd := Low_Bound (Indx);
6625 Hbd := High_Bound (Indx);
6628 Indx_Typ := Etype (Indx);
6630 if Is_Private_Type (Indx_Typ) then
6631 Indx_Typ := Full_View (Indx_Typ);
6634 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
6637 Lbd := Type_Low_Bound (Indx_Typ);
6638 Hbd := Type_High_Bound (Indx_Typ);
6642 if Compile_Time_Known_Value (Lbd)
6643 and then Compile_Time_Known_Value (Hbd)
6645 if Expr_Value (Hbd) < Expr_Value (Lbd) then
6655 -- If no null indexes, then type is not fully initialized
6661 elsif Is_Record_Type (Typ) then
6662 if Has_Discriminants (Typ)
6664 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
6665 and then Is_Fully_Initialized_Variant (Typ)
6670 -- Controlled records are considered to be fully initialized if
6671 -- there is a user defined Initialize routine. This may not be
6672 -- entirely correct, but as the spec notes, we are guessing here
6673 -- what is best from the point of view of issuing warnings.
6675 if Is_Controlled (Typ) then
6677 Utyp : constant Entity_Id := Underlying_Type (Typ);
6680 if Present (Utyp) then
6682 Init : constant Entity_Id :=
6684 (Underlying_Type (Typ), Name_Initialize));
6688 and then Comes_From_Source (Init)
6690 Is_Predefined_File_Name
6691 (File_Name (Get_Source_File_Index (Sloc (Init))))
6695 elsif Has_Null_Extension (Typ)
6697 Is_Fully_Initialized_Type
6698 (Etype (Base_Type (Typ)))
6707 -- Otherwise see if all record components are initialized
6713 Ent := First_Entity (Typ);
6714 while Present (Ent) loop
6715 if Chars (Ent) = Name_uController then
6718 elsif Ekind (Ent) = E_Component
6719 and then (No (Parent (Ent))
6720 or else No (Expression (Parent (Ent))))
6721 and then not Is_Fully_Initialized_Type (Etype (Ent))
6723 -- Special VM case for tag components, which need to be
6724 -- defined in this case, but are never initialized as VMs
6725 -- are using other dispatching mechanisms. Ignore this
6726 -- uninitialized case. Note that this applies both to the
6727 -- uTag entry and the main vtable pointer (CPP_Class case).
6729 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
6738 -- No uninitialized components, so type is fully initialized.
6739 -- Note that this catches the case of no components as well.
6743 elsif Is_Concurrent_Type (Typ) then
6746 elsif Is_Private_Type (Typ) then
6748 U : constant Entity_Id := Underlying_Type (Typ);
6754 return Is_Fully_Initialized_Type (U);
6761 end Is_Fully_Initialized_Type;
6763 ----------------------------------
6764 -- Is_Fully_Initialized_Variant --
6765 ----------------------------------
6767 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
6768 Loc : constant Source_Ptr := Sloc (Typ);
6769 Constraints : constant List_Id := New_List;
6770 Components : constant Elist_Id := New_Elmt_List;
6771 Comp_Elmt : Elmt_Id;
6773 Comp_List : Node_Id;
6775 Discr_Val : Node_Id;
6777 Report_Errors : Boolean;
6778 pragma Warnings (Off, Report_Errors);
6781 if Serious_Errors_Detected > 0 then
6785 if Is_Record_Type (Typ)
6786 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
6787 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
6789 Comp_List := Component_List (Type_Definition (Parent (Typ)));
6791 Discr := First_Discriminant (Typ);
6792 while Present (Discr) loop
6793 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
6794 Discr_Val := Expression (Parent (Discr));
6796 if Present (Discr_Val)
6797 and then Is_OK_Static_Expression (Discr_Val)
6799 Append_To (Constraints,
6800 Make_Component_Association (Loc,
6801 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
6802 Expression => New_Copy (Discr_Val)));
6810 Next_Discriminant (Discr);
6815 Comp_List => Comp_List,
6816 Governed_By => Constraints,
6818 Report_Errors => Report_Errors);
6820 -- Check that each component present is fully initialized
6822 Comp_Elmt := First_Elmt (Components);
6823 while Present (Comp_Elmt) loop
6824 Comp_Id := Node (Comp_Elmt);
6826 if Ekind (Comp_Id) = E_Component
6827 and then (No (Parent (Comp_Id))
6828 or else No (Expression (Parent (Comp_Id))))
6829 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
6834 Next_Elmt (Comp_Elmt);
6839 elsif Is_Private_Type (Typ) then
6841 U : constant Entity_Id := Underlying_Type (Typ);
6847 return Is_Fully_Initialized_Variant (U);
6853 end Is_Fully_Initialized_Variant;
6859 -- We seem to have a lot of overlapping functions that do similar things
6860 -- (testing for left hand sides or lvalues???). Anyway, since this one is
6861 -- purely syntactic, it should be in Sem_Aux I would think???
6863 function Is_LHS (N : Node_Id) return Boolean is
6864 P : constant Node_Id := Parent (N);
6867 if Nkind (P) = N_Assignment_Statement then
6868 return Name (P) = N;
6871 Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
6873 return N = Prefix (P) and then Is_LHS (P);
6880 ----------------------------
6881 -- Is_Inherited_Operation --
6882 ----------------------------
6884 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
6885 Kind : constant Node_Kind := Nkind (Parent (E));
6887 pragma Assert (Is_Overloadable (E));
6888 return Kind = N_Full_Type_Declaration
6889 or else Kind = N_Private_Extension_Declaration
6890 or else Kind = N_Subtype_Declaration
6891 or else (Ekind (E) = E_Enumeration_Literal
6892 and then Is_Derived_Type (Etype (E)));
6893 end Is_Inherited_Operation;
6895 -------------------------------------
6896 -- Is_Inherited_Operation_For_Type --
6897 -------------------------------------
6899 function Is_Inherited_Operation_For_Type
6900 (E : Entity_Id; Typ : Entity_Id) return Boolean
6903 return Is_Inherited_Operation (E)
6904 and then Etype (Parent (E)) = Typ;
6905 end Is_Inherited_Operation_For_Type;
6907 -----------------------------
6908 -- Is_Library_Level_Entity --
6909 -----------------------------
6911 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
6913 -- The following is a small optimization, and it also properly handles
6914 -- discriminals, which in task bodies might appear in expressions before
6915 -- the corresponding procedure has been created, and which therefore do
6916 -- not have an assigned scope.
6918 if Is_Formal (E) then
6922 -- Normal test is simply that the enclosing dynamic scope is Standard
6924 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
6925 end Is_Library_Level_Entity;
6927 ---------------------------------
6928 -- Is_Local_Variable_Reference --
6929 ---------------------------------
6931 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
6933 if not Is_Entity_Name (Expr) then
6938 Ent : constant Entity_Id := Entity (Expr);
6939 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
6941 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
6944 return Present (Sub) and then Sub = Current_Subprogram;
6948 end Is_Local_Variable_Reference;
6950 -------------------------
6951 -- Is_Object_Reference --
6952 -------------------------
6954 function Is_Object_Reference (N : Node_Id) return Boolean is
6956 if Is_Entity_Name (N) then
6957 return Present (Entity (N)) and then Is_Object (Entity (N));
6961 when N_Indexed_Component | N_Slice =>
6963 Is_Object_Reference (Prefix (N))
6964 or else Is_Access_Type (Etype (Prefix (N)));
6966 -- In Ada95, a function call is a constant object; a procedure
6969 when N_Function_Call =>
6970 return Etype (N) /= Standard_Void_Type;
6972 -- A reference to the stream attribute Input is a function call
6974 when N_Attribute_Reference =>
6975 return Attribute_Name (N) = Name_Input;
6977 when N_Selected_Component =>
6979 Is_Object_Reference (Selector_Name (N))
6981 (Is_Object_Reference (Prefix (N))
6982 or else Is_Access_Type (Etype (Prefix (N))));
6984 when N_Explicit_Dereference =>
6987 -- A view conversion of a tagged object is an object reference
6989 when N_Type_Conversion =>
6990 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
6991 and then Is_Tagged_Type (Etype (Expression (N)))
6992 and then Is_Object_Reference (Expression (N));
6994 -- An unchecked type conversion is considered to be an object if
6995 -- the operand is an object (this construction arises only as a
6996 -- result of expansion activities).
6998 when N_Unchecked_Type_Conversion =>
7005 end Is_Object_Reference;
7007 -----------------------------------
7008 -- Is_OK_Variable_For_Out_Formal --
7009 -----------------------------------
7011 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
7013 Note_Possible_Modification (AV, Sure => True);
7015 -- We must reject parenthesized variable names. The check for
7016 -- Comes_From_Source is present because there are currently
7017 -- cases where the compiler violates this rule (e.g. passing
7018 -- a task object to its controlled Initialize routine).
7020 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
7023 -- A variable is always allowed
7025 elsif Is_Variable (AV) then
7028 -- Unchecked conversions are allowed only if they come from the
7029 -- generated code, which sometimes uses unchecked conversions for out
7030 -- parameters in cases where code generation is unaffected. We tell
7031 -- source unchecked conversions by seeing if they are rewrites of an
7032 -- original Unchecked_Conversion function call, or of an explicit
7033 -- conversion of a function call.
7035 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
7036 if Nkind (Original_Node (AV)) = N_Function_Call then
7039 elsif Comes_From_Source (AV)
7040 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
7044 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
7045 return Is_OK_Variable_For_Out_Formal (Expression (AV));
7051 -- Normal type conversions are allowed if argument is a variable
7053 elsif Nkind (AV) = N_Type_Conversion then
7054 if Is_Variable (Expression (AV))
7055 and then Paren_Count (Expression (AV)) = 0
7057 Note_Possible_Modification (Expression (AV), Sure => True);
7060 -- We also allow a non-parenthesized expression that raises
7061 -- constraint error if it rewrites what used to be a variable
7063 elsif Raises_Constraint_Error (Expression (AV))
7064 and then Paren_Count (Expression (AV)) = 0
7065 and then Is_Variable (Original_Node (Expression (AV)))
7069 -- Type conversion of something other than a variable
7075 -- If this node is rewritten, then test the original form, if that is
7076 -- OK, then we consider the rewritten node OK (for example, if the
7077 -- original node is a conversion, then Is_Variable will not be true
7078 -- but we still want to allow the conversion if it converts a variable).
7080 elsif Original_Node (AV) /= AV then
7081 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
7083 -- All other non-variables are rejected
7088 end Is_OK_Variable_For_Out_Formal;
7090 -----------------------------------
7091 -- Is_Partially_Initialized_Type --
7092 -----------------------------------
7094 function Is_Partially_Initialized_Type
7096 Include_Implicit : Boolean := True) return Boolean
7099 if Is_Scalar_Type (Typ) then
7102 elsif Is_Access_Type (Typ) then
7103 return Include_Implicit;
7105 elsif Is_Array_Type (Typ) then
7107 -- If component type is partially initialized, so is array type
7109 if Is_Partially_Initialized_Type
7110 (Component_Type (Typ), Include_Implicit)
7114 -- Otherwise we are only partially initialized if we are fully
7115 -- initialized (this is the empty array case, no point in us
7116 -- duplicating that code here).
7119 return Is_Fully_Initialized_Type (Typ);
7122 elsif Is_Record_Type (Typ) then
7124 -- A discriminated type is always partially initialized if in
7127 if Has_Discriminants (Typ) and then Include_Implicit then
7130 -- A tagged type is always partially initialized
7132 elsif Is_Tagged_Type (Typ) then
7135 -- Case of non-discriminated record
7141 Component_Present : Boolean := False;
7142 -- Set True if at least one component is present. If no
7143 -- components are present, then record type is fully
7144 -- initialized (another odd case, like the null array).
7147 -- Loop through components
7149 Ent := First_Entity (Typ);
7150 while Present (Ent) loop
7151 if Ekind (Ent) = E_Component then
7152 Component_Present := True;
7154 -- If a component has an initialization expression then
7155 -- the enclosing record type is partially initialized
7157 if Present (Parent (Ent))
7158 and then Present (Expression (Parent (Ent)))
7162 -- If a component is of a type which is itself partially
7163 -- initialized, then the enclosing record type is also.
7165 elsif Is_Partially_Initialized_Type
7166 (Etype (Ent), Include_Implicit)
7175 -- No initialized components found. If we found any components
7176 -- they were all uninitialized so the result is false.
7178 if Component_Present then
7181 -- But if we found no components, then all the components are
7182 -- initialized so we consider the type to be initialized.
7190 -- Concurrent types are always fully initialized
7192 elsif Is_Concurrent_Type (Typ) then
7195 -- For a private type, go to underlying type. If there is no underlying
7196 -- type then just assume this partially initialized. Not clear if this
7197 -- can happen in a non-error case, but no harm in testing for this.
7199 elsif Is_Private_Type (Typ) then
7201 U : constant Entity_Id := Underlying_Type (Typ);
7206 return Is_Partially_Initialized_Type (U, Include_Implicit);
7210 -- For any other type (are there any?) assume partially initialized
7215 end Is_Partially_Initialized_Type;
7217 ------------------------------------
7218 -- Is_Potentially_Persistent_Type --
7219 ------------------------------------
7221 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
7226 -- For private type, test corresponding full type
7228 if Is_Private_Type (T) then
7229 return Is_Potentially_Persistent_Type (Full_View (T));
7231 -- Scalar types are potentially persistent
7233 elsif Is_Scalar_Type (T) then
7236 -- Record type is potentially persistent if not tagged and the types of
7237 -- all it components are potentially persistent, and no component has
7238 -- an initialization expression.
7240 elsif Is_Record_Type (T)
7241 and then not Is_Tagged_Type (T)
7242 and then not Is_Partially_Initialized_Type (T)
7244 Comp := First_Component (T);
7245 while Present (Comp) loop
7246 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
7255 -- Array type is potentially persistent if its component type is
7256 -- potentially persistent and if all its constraints are static.
7258 elsif Is_Array_Type (T) then
7259 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
7263 Indx := First_Index (T);
7264 while Present (Indx) loop
7265 if not Is_OK_Static_Subtype (Etype (Indx)) then
7274 -- All other types are not potentially persistent
7279 end Is_Potentially_Persistent_Type;
7281 ---------------------------------
7282 -- Is_Protected_Self_Reference --
7283 ---------------------------------
7285 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
7287 function In_Access_Definition (N : Node_Id) return Boolean;
7288 -- Returns true if N belongs to an access definition
7290 --------------------------
7291 -- In_Access_Definition --
7292 --------------------------
7294 function In_Access_Definition (N : Node_Id) return Boolean is
7299 while Present (P) loop
7300 if Nkind (P) = N_Access_Definition then
7308 end In_Access_Definition;
7310 -- Start of processing for Is_Protected_Self_Reference
7313 -- Verify that prefix is analyzed and has the proper form. Note that
7314 -- the attributes Elab_Spec, Elab_Body, and UET_Address, which also
7315 -- produce the address of an entity, do not analyze their prefix
7316 -- because they denote entities that are not necessarily visible.
7317 -- Neither of them can apply to a protected type.
7319 return Ada_Version >= Ada_2005
7320 and then Is_Entity_Name (N)
7321 and then Present (Entity (N))
7322 and then Is_Protected_Type (Entity (N))
7323 and then In_Open_Scopes (Entity (N))
7324 and then not In_Access_Definition (N);
7325 end Is_Protected_Self_Reference;
7327 -----------------------------
7328 -- Is_RCI_Pkg_Spec_Or_Body --
7329 -----------------------------
7331 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
7333 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
7334 -- Return True if the unit of Cunit is an RCI package declaration
7336 ---------------------------
7337 -- Is_RCI_Pkg_Decl_Cunit --
7338 ---------------------------
7340 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
7341 The_Unit : constant Node_Id := Unit (Cunit);
7344 if Nkind (The_Unit) /= N_Package_Declaration then
7348 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
7349 end Is_RCI_Pkg_Decl_Cunit;
7351 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
7354 return Is_RCI_Pkg_Decl_Cunit (Cunit)
7356 (Nkind (Unit (Cunit)) = N_Package_Body
7357 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
7358 end Is_RCI_Pkg_Spec_Or_Body;
7360 -----------------------------------------
7361 -- Is_Remote_Access_To_Class_Wide_Type --
7362 -----------------------------------------
7364 function Is_Remote_Access_To_Class_Wide_Type
7365 (E : Entity_Id) return Boolean
7368 -- A remote access to class-wide type is a general access to object type
7369 -- declared in the visible part of a Remote_Types or Remote_Call_
7372 return Ekind (E) = E_General_Access_Type
7373 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
7374 end Is_Remote_Access_To_Class_Wide_Type;
7376 -----------------------------------------
7377 -- Is_Remote_Access_To_Subprogram_Type --
7378 -----------------------------------------
7380 function Is_Remote_Access_To_Subprogram_Type
7381 (E : Entity_Id) return Boolean
7384 return (Ekind (E) = E_Access_Subprogram_Type
7385 or else (Ekind (E) = E_Record_Type
7386 and then Present (Corresponding_Remote_Type (E))))
7387 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
7388 end Is_Remote_Access_To_Subprogram_Type;
7390 --------------------
7391 -- Is_Remote_Call --
7392 --------------------
7394 function Is_Remote_Call (N : Node_Id) return Boolean is
7396 if Nkind (N) /= N_Procedure_Call_Statement
7397 and then Nkind (N) /= N_Function_Call
7399 -- An entry call cannot be remote
7403 elsif Nkind (Name (N)) in N_Has_Entity
7404 and then Is_Remote_Call_Interface (Entity (Name (N)))
7406 -- A subprogram declared in the spec of a RCI package is remote
7410 elsif Nkind (Name (N)) = N_Explicit_Dereference
7411 and then Is_Remote_Access_To_Subprogram_Type
7412 (Etype (Prefix (Name (N))))
7414 -- The dereference of a RAS is a remote call
7418 elsif Present (Controlling_Argument (N))
7419 and then Is_Remote_Access_To_Class_Wide_Type
7420 (Etype (Controlling_Argument (N)))
7422 -- Any primitive operation call with a controlling argument of
7423 -- a RACW type is a remote call.
7428 -- All other calls are local calls
7433 ----------------------
7434 -- Is_Renamed_Entry --
7435 ----------------------
7437 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
7438 Orig_Node : Node_Id := Empty;
7439 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
7441 function Is_Entry (Nam : Node_Id) return Boolean;
7442 -- Determine whether Nam is an entry. Traverse selectors if there are
7443 -- nested selected components.
7449 function Is_Entry (Nam : Node_Id) return Boolean is
7451 if Nkind (Nam) = N_Selected_Component then
7452 return Is_Entry (Selector_Name (Nam));
7455 return Ekind (Entity (Nam)) = E_Entry;
7458 -- Start of processing for Is_Renamed_Entry
7461 if Present (Alias (Proc_Nam)) then
7462 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
7465 -- Look for a rewritten subprogram renaming declaration
7467 if Nkind (Subp_Decl) = N_Subprogram_Declaration
7468 and then Present (Original_Node (Subp_Decl))
7470 Orig_Node := Original_Node (Subp_Decl);
7473 -- The rewritten subprogram is actually an entry
7475 if Present (Orig_Node)
7476 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
7477 and then Is_Entry (Name (Orig_Node))
7483 end Is_Renamed_Entry;
7485 ----------------------
7486 -- Is_Selector_Name --
7487 ----------------------
7489 function Is_Selector_Name (N : Node_Id) return Boolean is
7491 if not Is_List_Member (N) then
7493 P : constant Node_Id := Parent (N);
7494 K : constant Node_Kind := Nkind (P);
7497 (K = N_Expanded_Name or else
7498 K = N_Generic_Association or else
7499 K = N_Parameter_Association or else
7500 K = N_Selected_Component)
7501 and then Selector_Name (P) = N;
7506 L : constant List_Id := List_Containing (N);
7507 P : constant Node_Id := Parent (L);
7509 return (Nkind (P) = N_Discriminant_Association
7510 and then Selector_Names (P) = L)
7512 (Nkind (P) = N_Component_Association
7513 and then Choices (P) = L);
7516 end Is_Selector_Name;
7518 ----------------------------------
7519 -- Is_SPARK_Initialization_Expr --
7520 ----------------------------------
7522 function Is_SPARK_Initialization_Expr (N : Node_Id) return Boolean is
7525 Comp_Assn : Node_Id;
7526 Orig_N : constant Node_Id := Original_Node (N);
7531 if not Comes_From_Source (Orig_N) then
7535 pragma Assert (Nkind (Orig_N) in N_Subexpr);
7537 case Nkind (Orig_N) is
7538 when N_Character_Literal |
7546 if Is_Entity_Name (Orig_N)
7547 and then Present (Entity (Orig_N)) -- needed in some cases
7549 case Ekind (Entity (Orig_N)) is
7551 E_Enumeration_Literal |
7556 if Is_Type (Entity (Orig_N)) then
7564 when N_Qualified_Expression |
7565 N_Type_Conversion =>
7566 Is_Ok := Is_SPARK_Initialization_Expr (Expression (Orig_N));
7569 Is_Ok := Is_SPARK_Initialization_Expr (Right_Opnd (Orig_N));
7573 N_Membership_Test =>
7574 Is_Ok := Is_SPARK_Initialization_Expr (Left_Opnd (Orig_N))
7575 and then Is_SPARK_Initialization_Expr (Right_Opnd (Orig_N));
7578 N_Extension_Aggregate =>
7579 if Nkind (Orig_N) = N_Extension_Aggregate then
7580 Is_Ok := Is_SPARK_Initialization_Expr (Ancestor_Part (Orig_N));
7583 Expr := First (Expressions (Orig_N));
7584 while Present (Expr) loop
7585 if not Is_SPARK_Initialization_Expr (Expr) then
7593 Comp_Assn := First (Component_Associations (Orig_N));
7594 while Present (Comp_Assn) loop
7595 Expr := Expression (Comp_Assn);
7596 if Present (Expr) -- needed for box association
7597 and then not Is_SPARK_Initialization_Expr (Expr)
7606 when N_Attribute_Reference =>
7607 if Nkind (Prefix (Orig_N)) in N_Subexpr then
7608 Is_Ok := Is_SPARK_Initialization_Expr (Prefix (Orig_N));
7611 Expr := First (Expressions (Orig_N));
7612 while Present (Expr) loop
7613 if not Is_SPARK_Initialization_Expr (Expr) then
7621 -- Selected components might be expanded named not yet resolved, so
7622 -- default on the safe side. (Eg on sparklex.ads)
7624 when N_Selected_Component =>
7633 end Is_SPARK_Initialization_Expr;
7635 -------------------------------
7636 -- Is_SPARK_Object_Reference --
7637 -------------------------------
7639 function Is_SPARK_Object_Reference (N : Node_Id) return Boolean is
7641 if Is_Entity_Name (N) then
7642 return Present (Entity (N))
7644 (Ekind_In (Entity (N), E_Constant, E_Variable)
7645 or else Ekind (Entity (N)) in Formal_Kind);
7649 when N_Selected_Component =>
7650 return Is_SPARK_Object_Reference (Prefix (N));
7656 end Is_SPARK_Object_Reference;
7662 function Is_Statement (N : Node_Id) return Boolean is
7665 Nkind (N) in N_Statement_Other_Than_Procedure_Call
7666 or else Nkind (N) = N_Procedure_Call_Statement;
7669 ---------------------------------
7670 -- Is_Synchronized_Tagged_Type --
7671 ---------------------------------
7673 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
7674 Kind : constant Entity_Kind := Ekind (Base_Type (E));
7677 -- A task or protected type derived from an interface is a tagged type.
7678 -- Such a tagged type is called a synchronized tagged type, as are
7679 -- synchronized interfaces and private extensions whose declaration
7680 -- includes the reserved word synchronized.
7682 return (Is_Tagged_Type (E)
7683 and then (Kind = E_Task_Type
7684 or else Kind = E_Protected_Type))
7687 and then Is_Synchronized_Interface (E))
7689 (Ekind (E) = E_Record_Type_With_Private
7690 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
7691 and then (Synchronized_Present (Parent (E))
7692 or else Is_Synchronized_Interface (Etype (E))));
7693 end Is_Synchronized_Tagged_Type;
7699 function Is_Transfer (N : Node_Id) return Boolean is
7700 Kind : constant Node_Kind := Nkind (N);
7703 if Kind = N_Simple_Return_Statement
7705 Kind = N_Extended_Return_Statement
7707 Kind = N_Goto_Statement
7709 Kind = N_Raise_Statement
7711 Kind = N_Requeue_Statement
7715 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
7716 and then No (Condition (N))
7720 elsif Kind = N_Procedure_Call_Statement
7721 and then Is_Entity_Name (Name (N))
7722 and then Present (Entity (Name (N)))
7723 and then No_Return (Entity (Name (N)))
7727 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
7739 function Is_True (U : Uint) return Boolean is
7744 -------------------------------
7745 -- Is_Universal_Numeric_Type --
7746 -------------------------------
7748 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
7750 return T = Universal_Integer or else T = Universal_Real;
7751 end Is_Universal_Numeric_Type;
7757 function Is_Value_Type (T : Entity_Id) return Boolean is
7759 return VM_Target = CLI_Target
7760 and then Nkind (T) in N_Has_Chars
7761 and then Chars (T) /= No_Name
7762 and then Get_Name_String (Chars (T)) = "valuetype";
7765 ---------------------
7766 -- Is_VMS_Operator --
7767 ---------------------
7769 function Is_VMS_Operator (Op : Entity_Id) return Boolean is
7771 -- The VMS operators are declared in a child of System that is loaded
7772 -- through pragma Extend_System. In some rare cases a program is run
7773 -- with this extension but without indicating that the target is VMS.
7775 return Ekind (Op) = E_Function
7776 and then Is_Intrinsic_Subprogram (Op)
7778 ((Present_System_Aux
7779 and then Scope (Op) = System_Aux_Id)
7782 and then Scope (Scope (Op)) = RTU_Entity (System)));
7783 end Is_VMS_Operator;
7789 function Is_Variable
7791 Use_Original_Node : Boolean := True) return Boolean
7793 Orig_Node : Node_Id;
7795 function In_Protected_Function (E : Entity_Id) return Boolean;
7796 -- Within a protected function, the private components of the enclosing
7797 -- protected type are constants. A function nested within a (protected)
7798 -- procedure is not itself protected.
7800 function Is_Variable_Prefix (P : Node_Id) return Boolean;
7801 -- Prefixes can involve implicit dereferences, in which case we must
7802 -- test for the case of a reference of a constant access type, which can
7803 -- can never be a variable.
7805 ---------------------------
7806 -- In_Protected_Function --
7807 ---------------------------
7809 function In_Protected_Function (E : Entity_Id) return Boolean is
7810 Prot : constant Entity_Id := Scope (E);
7814 if not Is_Protected_Type (Prot) then
7818 while Present (S) and then S /= Prot loop
7819 if Ekind (S) = E_Function and then Scope (S) = Prot then
7828 end In_Protected_Function;
7830 ------------------------
7831 -- Is_Variable_Prefix --
7832 ------------------------
7834 function Is_Variable_Prefix (P : Node_Id) return Boolean is
7836 if Is_Access_Type (Etype (P)) then
7837 return not Is_Access_Constant (Root_Type (Etype (P)));
7839 -- For the case of an indexed component whose prefix has a packed
7840 -- array type, the prefix has been rewritten into a type conversion.
7841 -- Determine variable-ness from the converted expression.
7843 elsif Nkind (P) = N_Type_Conversion
7844 and then not Comes_From_Source (P)
7845 and then Is_Array_Type (Etype (P))
7846 and then Is_Packed (Etype (P))
7848 return Is_Variable (Expression (P));
7851 return Is_Variable (P);
7853 end Is_Variable_Prefix;
7855 -- Start of processing for Is_Variable
7858 -- Check if we perform the test on the original node since this may be a
7859 -- test of syntactic categories which must not be disturbed by whatever
7860 -- rewriting might have occurred. For example, an aggregate, which is
7861 -- certainly NOT a variable, could be turned into a variable by
7864 if Use_Original_Node then
7865 Orig_Node := Original_Node (N);
7870 -- Definitely OK if Assignment_OK is set. Since this is something that
7871 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
7873 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
7876 -- Normally we go to the original node, but there is one exception where
7877 -- we use the rewritten node, namely when it is an explicit dereference.
7878 -- The generated code may rewrite a prefix which is an access type with
7879 -- an explicit dereference. The dereference is a variable, even though
7880 -- the original node may not be (since it could be a constant of the
7883 -- In Ada 2005 we have a further case to consider: the prefix may be a
7884 -- function call given in prefix notation. The original node appears to
7885 -- be a selected component, but we need to examine the call.
7887 elsif Nkind (N) = N_Explicit_Dereference
7888 and then Nkind (Orig_Node) /= N_Explicit_Dereference
7889 and then Present (Etype (Orig_Node))
7890 and then Is_Access_Type (Etype (Orig_Node))
7892 -- Note that if the prefix is an explicit dereference that does not
7893 -- come from source, we must check for a rewritten function call in
7894 -- prefixed notation before other forms of rewriting, to prevent a
7898 (Nkind (Orig_Node) = N_Function_Call
7899 and then not Is_Access_Constant (Etype (Prefix (N))))
7901 Is_Variable_Prefix (Original_Node (Prefix (N)));
7903 -- A function call is never a variable
7905 elsif Nkind (N) = N_Function_Call then
7908 -- All remaining checks use the original node
7910 elsif Is_Entity_Name (Orig_Node)
7911 and then Present (Entity (Orig_Node))
7914 E : constant Entity_Id := Entity (Orig_Node);
7915 K : constant Entity_Kind := Ekind (E);
7918 return (K = E_Variable
7919 and then Nkind (Parent (E)) /= N_Exception_Handler)
7920 or else (K = E_Component
7921 and then not In_Protected_Function (E))
7922 or else K = E_Out_Parameter
7923 or else K = E_In_Out_Parameter
7924 or else K = E_Generic_In_Out_Parameter
7926 -- Current instance of type:
7928 or else (Is_Type (E) and then In_Open_Scopes (E))
7929 or else (Is_Incomplete_Or_Private_Type (E)
7930 and then In_Open_Scopes (Full_View (E)));
7934 case Nkind (Orig_Node) is
7935 when N_Indexed_Component | N_Slice =>
7936 return Is_Variable_Prefix (Prefix (Orig_Node));
7938 when N_Selected_Component =>
7939 return Is_Variable_Prefix (Prefix (Orig_Node))
7940 and then Is_Variable (Selector_Name (Orig_Node));
7942 -- For an explicit dereference, the type of the prefix cannot
7943 -- be an access to constant or an access to subprogram.
7945 when N_Explicit_Dereference =>
7947 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
7949 return Is_Access_Type (Typ)
7950 and then not Is_Access_Constant (Root_Type (Typ))
7951 and then Ekind (Typ) /= E_Access_Subprogram_Type;
7954 -- The type conversion is the case where we do not deal with the
7955 -- context dependent special case of an actual parameter. Thus
7956 -- the type conversion is only considered a variable for the
7957 -- purposes of this routine if the target type is tagged. However,
7958 -- a type conversion is considered to be a variable if it does not
7959 -- come from source (this deals for example with the conversions
7960 -- of expressions to their actual subtypes).
7962 when N_Type_Conversion =>
7963 return Is_Variable (Expression (Orig_Node))
7965 (not Comes_From_Source (Orig_Node)
7967 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
7969 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
7971 -- GNAT allows an unchecked type conversion as a variable. This
7972 -- only affects the generation of internal expanded code, since
7973 -- calls to instantiations of Unchecked_Conversion are never
7974 -- considered variables (since they are function calls).
7975 -- This is also true for expression actions.
7977 when N_Unchecked_Type_Conversion =>
7978 return Is_Variable (Expression (Orig_Node));
7986 ---------------------------
7987 -- Is_Visibly_Controlled --
7988 ---------------------------
7990 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
7991 Root : constant Entity_Id := Root_Type (T);
7993 return Chars (Scope (Root)) = Name_Finalization
7994 and then Chars (Scope (Scope (Root))) = Name_Ada
7995 and then Scope (Scope (Scope (Root))) = Standard_Standard;
7996 end Is_Visibly_Controlled;
7998 ------------------------
7999 -- Is_Volatile_Object --
8000 ------------------------
8002 function Is_Volatile_Object (N : Node_Id) return Boolean is
8004 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
8005 -- Determines if given object has volatile components
8007 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
8008 -- If prefix is an implicit dereference, examine designated type
8010 ------------------------
8011 -- Is_Volatile_Prefix --
8012 ------------------------
8014 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
8015 Typ : constant Entity_Id := Etype (N);
8018 if Is_Access_Type (Typ) then
8020 Dtyp : constant Entity_Id := Designated_Type (Typ);
8023 return Is_Volatile (Dtyp)
8024 or else Has_Volatile_Components (Dtyp);
8028 return Object_Has_Volatile_Components (N);
8030 end Is_Volatile_Prefix;
8032 ------------------------------------
8033 -- Object_Has_Volatile_Components --
8034 ------------------------------------
8036 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
8037 Typ : constant Entity_Id := Etype (N);
8040 if Is_Volatile (Typ)
8041 or else Has_Volatile_Components (Typ)
8045 elsif Is_Entity_Name (N)
8046 and then (Has_Volatile_Components (Entity (N))
8047 or else Is_Volatile (Entity (N)))
8051 elsif Nkind (N) = N_Indexed_Component
8052 or else Nkind (N) = N_Selected_Component
8054 return Is_Volatile_Prefix (Prefix (N));
8059 end Object_Has_Volatile_Components;
8061 -- Start of processing for Is_Volatile_Object
8064 if Is_Volatile (Etype (N))
8065 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
8069 elsif Nkind (N) = N_Indexed_Component
8070 or else Nkind (N) = N_Selected_Component
8072 return Is_Volatile_Prefix (Prefix (N));
8077 end Is_Volatile_Object;
8079 -------------------------
8080 -- Kill_Current_Values --
8081 -------------------------
8083 procedure Kill_Current_Values
8085 Last_Assignment_Only : Boolean := False)
8088 -- ??? do we have to worry about clearing cached checks?
8090 if Is_Assignable (Ent) then
8091 Set_Last_Assignment (Ent, Empty);
8094 if Is_Object (Ent) then
8095 if not Last_Assignment_Only then
8097 Set_Current_Value (Ent, Empty);
8099 if not Can_Never_Be_Null (Ent) then
8100 Set_Is_Known_Non_Null (Ent, False);
8103 Set_Is_Known_Null (Ent, False);
8105 -- Reset Is_Known_Valid unless type is always valid, or if we have
8106 -- a loop parameter (loop parameters are always valid, since their
8107 -- bounds are defined by the bounds given in the loop header).
8109 if not Is_Known_Valid (Etype (Ent))
8110 and then Ekind (Ent) /= E_Loop_Parameter
8112 Set_Is_Known_Valid (Ent, False);
8116 end Kill_Current_Values;
8118 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
8121 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
8122 -- Clear current value for entity E and all entities chained to E
8124 ------------------------------------------
8125 -- Kill_Current_Values_For_Entity_Chain --
8126 ------------------------------------------
8128 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
8132 while Present (Ent) loop
8133 Kill_Current_Values (Ent, Last_Assignment_Only);
8136 end Kill_Current_Values_For_Entity_Chain;
8138 -- Start of processing for Kill_Current_Values
8141 -- Kill all saved checks, a special case of killing saved values
8143 if not Last_Assignment_Only then
8147 -- Loop through relevant scopes, which includes the current scope and
8148 -- any parent scopes if the current scope is a block or a package.
8153 -- Clear current values of all entities in current scope
8155 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
8157 -- If scope is a package, also clear current values of all
8158 -- private entities in the scope.
8160 if Is_Package_Or_Generic_Package (S)
8161 or else Is_Concurrent_Type (S)
8163 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
8166 -- If this is a not a subprogram, deal with parents
8168 if not Is_Subprogram (S) then
8170 exit Scope_Loop when S = Standard_Standard;
8174 end loop Scope_Loop;
8175 end Kill_Current_Values;
8177 --------------------------
8178 -- Kill_Size_Check_Code --
8179 --------------------------
8181 procedure Kill_Size_Check_Code (E : Entity_Id) is
8183 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
8184 and then Present (Size_Check_Code (E))
8186 Remove (Size_Check_Code (E));
8187 Set_Size_Check_Code (E, Empty);
8189 end Kill_Size_Check_Code;
8191 --------------------------
8192 -- Known_To_Be_Assigned --
8193 --------------------------
8195 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
8196 P : constant Node_Id := Parent (N);
8201 -- Test left side of assignment
8203 when N_Assignment_Statement =>
8204 return N = Name (P);
8206 -- Function call arguments are never lvalues
8208 when N_Function_Call =>
8211 -- Positional parameter for procedure or accept call
8213 when N_Procedure_Call_Statement |
8222 Proc := Get_Subprogram_Entity (P);
8228 -- If we are not a list member, something is strange, so
8229 -- be conservative and return False.
8231 if not Is_List_Member (N) then
8235 -- We are going to find the right formal by stepping forward
8236 -- through the formals, as we step backwards in the actuals.
8238 Form := First_Formal (Proc);
8241 -- If no formal, something is weird, so be conservative
8242 -- and return False.
8253 return Ekind (Form) /= E_In_Parameter;
8256 -- Named parameter for procedure or accept call
8258 when N_Parameter_Association =>
8264 Proc := Get_Subprogram_Entity (Parent (P));
8270 -- Loop through formals to find the one that matches
8272 Form := First_Formal (Proc);
8274 -- If no matching formal, that's peculiar, some kind of
8275 -- previous error, so return False to be conservative.
8281 -- Else test for match
8283 if Chars (Form) = Chars (Selector_Name (P)) then
8284 return Ekind (Form) /= E_In_Parameter;
8291 -- Test for appearing in a conversion that itself appears
8292 -- in an lvalue context, since this should be an lvalue.
8294 when N_Type_Conversion =>
8295 return Known_To_Be_Assigned (P);
8297 -- All other references are definitely not known to be modifications
8303 end Known_To_Be_Assigned;
8305 ---------------------------
8306 -- Last_Source_Statement --
8307 ---------------------------
8309 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
8313 N := Last (Statements (HSS));
8314 while Present (N) loop
8315 exit when Comes_From_Source (N);
8320 end Last_Source_Statement;
8322 ----------------------------------
8323 -- Matching_Static_Array_Bounds --
8324 ----------------------------------
8326 function Matching_Static_Array_Bounds
8328 R_Typ : Node_Id) return Boolean
8330 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
8331 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
8343 if L_Ndims /= R_Ndims then
8347 -- Unconstrained types do not have static bounds
8349 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
8353 -- First treat specially the first dimension, as the lower bound and
8354 -- length of string literals are not stored like those of arrays.
8356 if Ekind (L_Typ) = E_String_Literal_Subtype then
8357 L_Low := String_Literal_Low_Bound (L_Typ);
8358 L_Len := String_Literal_Length (L_Typ);
8360 L_Index := First_Index (L_Typ);
8361 Get_Index_Bounds (L_Index, L_Low, L_High);
8363 if Is_OK_Static_Expression (L_Low)
8364 and then Is_OK_Static_Expression (L_High)
8366 if Expr_Value (L_High) < Expr_Value (L_Low) then
8369 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
8376 if Ekind (R_Typ) = E_String_Literal_Subtype then
8377 R_Low := String_Literal_Low_Bound (R_Typ);
8378 R_Len := String_Literal_Length (R_Typ);
8380 R_Index := First_Index (R_Typ);
8381 Get_Index_Bounds (R_Index, R_Low, R_High);
8383 if Is_OK_Static_Expression (R_Low)
8384 and then Is_OK_Static_Expression (R_High)
8386 if Expr_Value (R_High) < Expr_Value (R_Low) then
8389 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
8396 if Is_OK_Static_Expression (L_Low)
8397 and then Is_OK_Static_Expression (R_Low)
8398 and then Expr_Value (L_Low) = Expr_Value (R_Low)
8399 and then L_Len = R_Len
8406 -- Then treat all other dimensions
8408 for Indx in 2 .. L_Ndims loop
8412 Get_Index_Bounds (L_Index, L_Low, L_High);
8413 Get_Index_Bounds (R_Index, R_Low, R_High);
8415 if Is_OK_Static_Expression (L_Low)
8416 and then Is_OK_Static_Expression (L_High)
8417 and then Is_OK_Static_Expression (R_Low)
8418 and then Is_OK_Static_Expression (R_High)
8419 and then Expr_Value (L_Low) = Expr_Value (R_Low)
8420 and then Expr_Value (L_High) = Expr_Value (R_High)
8428 -- If we fall through the loop, all indexes matched
8431 end Matching_Static_Array_Bounds;
8437 function May_Be_Lvalue (N : Node_Id) return Boolean is
8438 P : constant Node_Id := Parent (N);
8443 -- Test left side of assignment
8445 when N_Assignment_Statement =>
8446 return N = Name (P);
8448 -- Test prefix of component or attribute. Note that the prefix of an
8449 -- explicit or implicit dereference cannot be an l-value.
8451 when N_Attribute_Reference =>
8452 return N = Prefix (P)
8453 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
8455 -- For an expanded name, the name is an lvalue if the expanded name
8456 -- is an lvalue, but the prefix is never an lvalue, since it is just
8457 -- the scope where the name is found.
8459 when N_Expanded_Name =>
8460 if N = Prefix (P) then
8461 return May_Be_Lvalue (P);
8466 -- For a selected component A.B, A is certainly an lvalue if A.B is.
8467 -- B is a little interesting, if we have A.B := 3, there is some
8468 -- discussion as to whether B is an lvalue or not, we choose to say
8469 -- it is. Note however that A is not an lvalue if it is of an access
8470 -- type since this is an implicit dereference.
8472 when N_Selected_Component =>
8474 and then Present (Etype (N))
8475 and then Is_Access_Type (Etype (N))
8479 return May_Be_Lvalue (P);
8482 -- For an indexed component or slice, the index or slice bounds is
8483 -- never an lvalue. The prefix is an lvalue if the indexed component
8484 -- or slice is an lvalue, except if it is an access type, where we
8485 -- have an implicit dereference.
8487 when N_Indexed_Component =>
8489 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
8493 return May_Be_Lvalue (P);
8496 -- Prefix of a reference is an lvalue if the reference is an lvalue
8499 return May_Be_Lvalue (P);
8501 -- Prefix of explicit dereference is never an lvalue
8503 when N_Explicit_Dereference =>
8506 -- Positional parameter for subprogram, entry, or accept call.
8507 -- In older versions of Ada function call arguments are never
8508 -- lvalues. In Ada 2012 functions can have in-out parameters.
8510 when N_Function_Call |
8511 N_Procedure_Call_Statement |
8512 N_Entry_Call_Statement |
8515 if Nkind (P) = N_Function_Call
8516 and then Ada_Version < Ada_2012
8521 -- The following mechanism is clumsy and fragile. A single
8522 -- flag set in Resolve_Actuals would be preferable ???
8530 Proc := Get_Subprogram_Entity (P);
8536 -- If we are not a list member, something is strange, so
8537 -- be conservative and return True.
8539 if not Is_List_Member (N) then
8543 -- We are going to find the right formal by stepping forward
8544 -- through the formals, as we step backwards in the actuals.
8546 Form := First_Formal (Proc);
8549 -- If no formal, something is weird, so be conservative
8561 return Ekind (Form) /= E_In_Parameter;
8564 -- Named parameter for procedure or accept call
8566 when N_Parameter_Association =>
8572 Proc := Get_Subprogram_Entity (Parent (P));
8578 -- Loop through formals to find the one that matches
8580 Form := First_Formal (Proc);
8582 -- If no matching formal, that's peculiar, some kind of
8583 -- previous error, so return True to be conservative.
8589 -- Else test for match
8591 if Chars (Form) = Chars (Selector_Name (P)) then
8592 return Ekind (Form) /= E_In_Parameter;
8599 -- Test for appearing in a conversion that itself appears in an
8600 -- lvalue context, since this should be an lvalue.
8602 when N_Type_Conversion =>
8603 return May_Be_Lvalue (P);
8605 -- Test for appearance in object renaming declaration
8607 when N_Object_Renaming_Declaration =>
8610 -- All other references are definitely not lvalues
8618 -----------------------
8619 -- Mark_Coextensions --
8620 -----------------------
8622 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
8623 Is_Dynamic : Boolean;
8624 -- Indicates whether the context causes nested coextensions to be
8625 -- dynamic or static
8627 function Mark_Allocator (N : Node_Id) return Traverse_Result;
8628 -- Recognize an allocator node and label it as a dynamic coextension
8630 --------------------
8631 -- Mark_Allocator --
8632 --------------------
8634 function Mark_Allocator (N : Node_Id) return Traverse_Result is
8636 if Nkind (N) = N_Allocator then
8638 Set_Is_Dynamic_Coextension (N);
8640 -- If the allocator expression is potentially dynamic, it may
8641 -- be expanded out of order and require dynamic allocation
8642 -- anyway, so we treat the coextension itself as dynamic.
8643 -- Potential optimization ???
8645 elsif Nkind (Expression (N)) = N_Qualified_Expression
8646 and then Nkind (Expression (Expression (N))) = N_Op_Concat
8648 Set_Is_Dynamic_Coextension (N);
8651 Set_Is_Static_Coextension (N);
8658 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
8660 -- Start of processing Mark_Coextensions
8663 case Nkind (Context_Nod) is
8664 when N_Assignment_Statement |
8665 N_Simple_Return_Statement =>
8666 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
8668 when N_Object_Declaration =>
8669 Is_Dynamic := Nkind (Root_Nod) = N_Allocator;
8671 -- This routine should not be called for constructs which may not
8672 -- contain coextensions.
8675 raise Program_Error;
8678 Mark_Allocators (Root_Nod);
8679 end Mark_Coextensions;
8681 ----------------------
8682 -- Needs_One_Actual --
8683 ----------------------
8685 function Needs_One_Actual (E : Entity_Id) return Boolean is
8689 if Ada_Version >= Ada_2005
8690 and then Present (First_Formal (E))
8692 Formal := Next_Formal (First_Formal (E));
8693 while Present (Formal) loop
8694 if No (Default_Value (Formal)) then
8698 Next_Formal (Formal);
8706 end Needs_One_Actual;
8708 ------------------------
8709 -- New_Copy_List_Tree --
8710 ------------------------
8712 function New_Copy_List_Tree (List : List_Id) return List_Id is
8717 if List = No_List then
8724 while Present (E) loop
8725 Append (New_Copy_Tree (E), NL);
8731 end New_Copy_List_Tree;
8737 use Atree.Unchecked_Access;
8738 use Atree_Private_Part;
8740 -- Our approach here requires a two pass traversal of the tree. The
8741 -- first pass visits all nodes that eventually will be copied looking
8742 -- for defining Itypes. If any defining Itypes are found, then they are
8743 -- copied, and an entry is added to the replacement map. In the second
8744 -- phase, the tree is copied, using the replacement map to replace any
8745 -- Itype references within the copied tree.
8747 -- The following hash tables are used if the Map supplied has more
8748 -- than hash threshold entries to speed up access to the map. If
8749 -- there are fewer entries, then the map is searched sequentially
8750 -- (because setting up a hash table for only a few entries takes
8751 -- more time than it saves.
8753 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
8754 -- Hash function used for hash operations
8760 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
8762 return Nat (E) mod (NCT_Header_Num'Last + 1);
8769 -- The hash table NCT_Assoc associates old entities in the table
8770 -- with their corresponding new entities (i.e. the pairs of entries
8771 -- presented in the original Map argument are Key-Element pairs).
8773 package NCT_Assoc is new Simple_HTable (
8774 Header_Num => NCT_Header_Num,
8775 Element => Entity_Id,
8776 No_Element => Empty,
8778 Hash => New_Copy_Hash,
8779 Equal => Types."=");
8781 ---------------------
8782 -- NCT_Itype_Assoc --
8783 ---------------------
8785 -- The hash table NCT_Itype_Assoc contains entries only for those
8786 -- old nodes which have a non-empty Associated_Node_For_Itype set.
8787 -- The key is the associated node, and the element is the new node
8788 -- itself (NOT the associated node for the new node).
8790 package NCT_Itype_Assoc is new Simple_HTable (
8791 Header_Num => NCT_Header_Num,
8792 Element => Entity_Id,
8793 No_Element => Empty,
8795 Hash => New_Copy_Hash,
8796 Equal => Types."=");
8798 -- Start of processing for New_Copy_Tree function
8800 function New_Copy_Tree
8802 Map : Elist_Id := No_Elist;
8803 New_Sloc : Source_Ptr := No_Location;
8804 New_Scope : Entity_Id := Empty) return Node_Id
8806 Actual_Map : Elist_Id := Map;
8807 -- This is the actual map for the copy. It is initialized with the
8808 -- given elements, and then enlarged as required for Itypes that are
8809 -- copied during the first phase of the copy operation. The visit
8810 -- procedures add elements to this map as Itypes are encountered.
8811 -- The reason we cannot use Map directly, is that it may well be
8812 -- (and normally is) initialized to No_Elist, and if we have mapped
8813 -- entities, we have to reset it to point to a real Elist.
8815 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
8816 -- Called during second phase to map entities into their corresponding
8817 -- copies using Actual_Map. If the argument is not an entity, or is not
8818 -- in Actual_Map, then it is returned unchanged.
8820 procedure Build_NCT_Hash_Tables;
8821 -- Builds hash tables (number of elements >= threshold value)
8823 function Copy_Elist_With_Replacement
8824 (Old_Elist : Elist_Id) return Elist_Id;
8825 -- Called during second phase to copy element list doing replacements
8827 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
8828 -- Called during the second phase to process a copied Itype. The actual
8829 -- copy happened during the first phase (so that we could make the entry
8830 -- in the mapping), but we still have to deal with the descendents of
8831 -- the copied Itype and copy them where necessary.
8833 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
8834 -- Called during second phase to copy list doing replacements
8836 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
8837 -- Called during second phase to copy node doing replacements
8839 procedure Visit_Elist (E : Elist_Id);
8840 -- Called during first phase to visit all elements of an Elist
8842 procedure Visit_Field (F : Union_Id; N : Node_Id);
8843 -- Visit a single field, recursing to call Visit_Node or Visit_List
8844 -- if the field is a syntactic descendent of the current node (i.e.
8845 -- its parent is Node N).
8847 procedure Visit_Itype (Old_Itype : Entity_Id);
8848 -- Called during first phase to visit subsidiary fields of a defining
8849 -- Itype, and also create a copy and make an entry in the replacement
8850 -- map for the new copy.
8852 procedure Visit_List (L : List_Id);
8853 -- Called during first phase to visit all elements of a List
8855 procedure Visit_Node (N : Node_Or_Entity_Id);
8856 -- Called during first phase to visit a node and all its subtrees
8862 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
8867 if not Has_Extension (N) or else No (Actual_Map) then
8870 elsif NCT_Hash_Tables_Used then
8871 Ent := NCT_Assoc.Get (Entity_Id (N));
8873 if Present (Ent) then
8879 -- No hash table used, do serial search
8882 E := First_Elmt (Actual_Map);
8883 while Present (E) loop
8884 if Node (E) = N then
8885 return Node (Next_Elmt (E));
8887 E := Next_Elmt (Next_Elmt (E));
8895 ---------------------------
8896 -- Build_NCT_Hash_Tables --
8897 ---------------------------
8899 procedure Build_NCT_Hash_Tables is
8903 if NCT_Hash_Table_Setup then
8905 NCT_Itype_Assoc.Reset;
8908 Elmt := First_Elmt (Actual_Map);
8909 while Present (Elmt) loop
8912 -- Get new entity, and associate old and new
8915 NCT_Assoc.Set (Ent, Node (Elmt));
8917 if Is_Type (Ent) then
8919 Anode : constant Entity_Id :=
8920 Associated_Node_For_Itype (Ent);
8923 if Present (Anode) then
8925 -- Enter a link between the associated node of the
8926 -- old Itype and the new Itype, for updating later
8927 -- when node is copied.
8929 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
8937 NCT_Hash_Tables_Used := True;
8938 NCT_Hash_Table_Setup := True;
8939 end Build_NCT_Hash_Tables;
8941 ---------------------------------
8942 -- Copy_Elist_With_Replacement --
8943 ---------------------------------
8945 function Copy_Elist_With_Replacement
8946 (Old_Elist : Elist_Id) return Elist_Id
8949 New_Elist : Elist_Id;
8952 if No (Old_Elist) then
8956 New_Elist := New_Elmt_List;
8958 M := First_Elmt (Old_Elist);
8959 while Present (M) loop
8960 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
8966 end Copy_Elist_With_Replacement;
8968 ---------------------------------
8969 -- Copy_Itype_With_Replacement --
8970 ---------------------------------
8972 -- This routine exactly parallels its phase one analog Visit_Itype,
8974 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
8976 -- Translate Next_Entity, Scope and Etype fields, in case they
8977 -- reference entities that have been mapped into copies.
8979 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
8980 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
8982 if Present (New_Scope) then
8983 Set_Scope (New_Itype, New_Scope);
8985 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
8988 -- Copy referenced fields
8990 if Is_Discrete_Type (New_Itype) then
8991 Set_Scalar_Range (New_Itype,
8992 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
8994 elsif Has_Discriminants (Base_Type (New_Itype)) then
8995 Set_Discriminant_Constraint (New_Itype,
8996 Copy_Elist_With_Replacement
8997 (Discriminant_Constraint (New_Itype)));
8999 elsif Is_Array_Type (New_Itype) then
9000 if Present (First_Index (New_Itype)) then
9001 Set_First_Index (New_Itype,
9002 First (Copy_List_With_Replacement
9003 (List_Containing (First_Index (New_Itype)))));
9006 if Is_Packed (New_Itype) then
9007 Set_Packed_Array_Type (New_Itype,
9008 Copy_Node_With_Replacement
9009 (Packed_Array_Type (New_Itype)));
9012 end Copy_Itype_With_Replacement;
9014 --------------------------------
9015 -- Copy_List_With_Replacement --
9016 --------------------------------
9018 function Copy_List_With_Replacement
9019 (Old_List : List_Id) return List_Id
9025 if Old_List = No_List then
9029 New_List := Empty_List;
9031 E := First (Old_List);
9032 while Present (E) loop
9033 Append (Copy_Node_With_Replacement (E), New_List);
9039 end Copy_List_With_Replacement;
9041 --------------------------------
9042 -- Copy_Node_With_Replacement --
9043 --------------------------------
9045 function Copy_Node_With_Replacement
9046 (Old_Node : Node_Id) return Node_Id
9050 procedure Adjust_Named_Associations
9051 (Old_Node : Node_Id;
9052 New_Node : Node_Id);
9053 -- If a call node has named associations, these are chained through
9054 -- the First_Named_Actual, Next_Named_Actual links. These must be
9055 -- propagated separately to the new parameter list, because these
9056 -- are not syntactic fields.
9058 function Copy_Field_With_Replacement
9059 (Field : Union_Id) return Union_Id;
9060 -- Given Field, which is a field of Old_Node, return a copy of it
9061 -- if it is a syntactic field (i.e. its parent is Node), setting
9062 -- the parent of the copy to poit to New_Node. Otherwise returns
9063 -- the field (possibly mapped if it is an entity).
9065 -------------------------------
9066 -- Adjust_Named_Associations --
9067 -------------------------------
9069 procedure Adjust_Named_Associations
9070 (Old_Node : Node_Id;
9080 Old_E := First (Parameter_Associations (Old_Node));
9081 New_E := First (Parameter_Associations (New_Node));
9082 while Present (Old_E) loop
9083 if Nkind (Old_E) = N_Parameter_Association
9084 and then Present (Next_Named_Actual (Old_E))
9086 if First_Named_Actual (Old_Node)
9087 = Explicit_Actual_Parameter (Old_E)
9089 Set_First_Named_Actual
9090 (New_Node, Explicit_Actual_Parameter (New_E));
9093 -- Now scan parameter list from the beginning,to locate
9094 -- next named actual, which can be out of order.
9096 Old_Next := First (Parameter_Associations (Old_Node));
9097 New_Next := First (Parameter_Associations (New_Node));
9099 while Nkind (Old_Next) /= N_Parameter_Association
9100 or else Explicit_Actual_Parameter (Old_Next)
9101 /= Next_Named_Actual (Old_E)
9107 Set_Next_Named_Actual
9108 (New_E, Explicit_Actual_Parameter (New_Next));
9114 end Adjust_Named_Associations;
9116 ---------------------------------
9117 -- Copy_Field_With_Replacement --
9118 ---------------------------------
9120 function Copy_Field_With_Replacement
9121 (Field : Union_Id) return Union_Id
9124 if Field = Union_Id (Empty) then
9127 elsif Field in Node_Range then
9129 Old_N : constant Node_Id := Node_Id (Field);
9133 -- If syntactic field, as indicated by the parent pointer
9134 -- being set, then copy the referenced node recursively.
9136 if Parent (Old_N) = Old_Node then
9137 New_N := Copy_Node_With_Replacement (Old_N);
9139 if New_N /= Old_N then
9140 Set_Parent (New_N, New_Node);
9143 -- For semantic fields, update possible entity reference
9144 -- from the replacement map.
9147 New_N := Assoc (Old_N);
9150 return Union_Id (New_N);
9153 elsif Field in List_Range then
9155 Old_L : constant List_Id := List_Id (Field);
9159 -- If syntactic field, as indicated by the parent pointer,
9160 -- then recursively copy the entire referenced list.
9162 if Parent (Old_L) = Old_Node then
9163 New_L := Copy_List_With_Replacement (Old_L);
9164 Set_Parent (New_L, New_Node);
9166 -- For semantic list, just returned unchanged
9172 return Union_Id (New_L);
9175 -- Anything other than a list or a node is returned unchanged
9180 end Copy_Field_With_Replacement;
9182 -- Start of processing for Copy_Node_With_Replacement
9185 if Old_Node <= Empty_Or_Error then
9188 elsif Has_Extension (Old_Node) then
9189 return Assoc (Old_Node);
9192 New_Node := New_Copy (Old_Node);
9194 -- If the node we are copying is the associated node of a
9195 -- previously copied Itype, then adjust the associated node
9196 -- of the copy of that Itype accordingly.
9198 if Present (Actual_Map) then
9204 -- Case of hash table used
9206 if NCT_Hash_Tables_Used then
9207 Ent := NCT_Itype_Assoc.Get (Old_Node);
9209 if Present (Ent) then
9210 Set_Associated_Node_For_Itype (Ent, New_Node);
9213 -- Case of no hash table used
9216 E := First_Elmt (Actual_Map);
9217 while Present (E) loop
9218 if Is_Itype (Node (E))
9220 Old_Node = Associated_Node_For_Itype (Node (E))
9222 Set_Associated_Node_For_Itype
9223 (Node (Next_Elmt (E)), New_Node);
9226 E := Next_Elmt (Next_Elmt (E));
9232 -- Recursively copy descendents
9235 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
9237 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
9239 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
9241 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
9243 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
9245 -- Adjust Sloc of new node if necessary
9247 if New_Sloc /= No_Location then
9248 Set_Sloc (New_Node, New_Sloc);
9250 -- If we adjust the Sloc, then we are essentially making
9251 -- a completely new node, so the Comes_From_Source flag
9252 -- should be reset to the proper default value.
9254 Nodes.Table (New_Node).Comes_From_Source :=
9255 Default_Node.Comes_From_Source;
9258 -- If the node is call and has named associations,
9259 -- set the corresponding links in the copy.
9261 if (Nkind (Old_Node) = N_Function_Call
9262 or else Nkind (Old_Node) = N_Entry_Call_Statement
9264 Nkind (Old_Node) = N_Procedure_Call_Statement)
9265 and then Present (First_Named_Actual (Old_Node))
9267 Adjust_Named_Associations (Old_Node, New_Node);
9270 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
9271 -- The replacement mechanism applies to entities, and is not used
9272 -- here. Eventually we may need a more general graph-copying
9273 -- routine. For now, do a sequential search to find desired node.
9275 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
9276 and then Present (First_Real_Statement (Old_Node))
9279 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
9283 N1 := First (Statements (Old_Node));
9284 N2 := First (Statements (New_Node));
9286 while N1 /= Old_F loop
9291 Set_First_Real_Statement (New_Node, N2);
9296 -- All done, return copied node
9299 end Copy_Node_With_Replacement;
9305 procedure Visit_Elist (E : Elist_Id) is
9309 Elmt := First_Elmt (E);
9311 while Elmt /= No_Elmt loop
9312 Visit_Node (Node (Elmt));
9322 procedure Visit_Field (F : Union_Id; N : Node_Id) is
9324 if F = Union_Id (Empty) then
9327 elsif F in Node_Range then
9329 -- Copy node if it is syntactic, i.e. its parent pointer is
9330 -- set to point to the field that referenced it (certain
9331 -- Itypes will also meet this criterion, which is fine, since
9332 -- these are clearly Itypes that do need to be copied, since
9333 -- we are copying their parent.)
9335 if Parent (Node_Id (F)) = N then
9336 Visit_Node (Node_Id (F));
9339 -- Another case, if we are pointing to an Itype, then we want
9340 -- to copy it if its associated node is somewhere in the tree
9343 -- Note: the exclusion of self-referential copies is just an
9344 -- optimization, since the search of the already copied list
9345 -- would catch it, but it is a common case (Etype pointing
9346 -- to itself for an Itype that is a base type).
9348 elsif Has_Extension (Node_Id (F))
9349 and then Is_Itype (Entity_Id (F))
9350 and then Node_Id (F) /= N
9356 P := Associated_Node_For_Itype (Node_Id (F));
9357 while Present (P) loop
9359 Visit_Node (Node_Id (F));
9366 -- An Itype whose parent is not being copied definitely
9367 -- should NOT be copied, since it does not belong in any
9368 -- sense to the copied subtree.
9374 elsif F in List_Range
9375 and then Parent (List_Id (F)) = N
9377 Visit_List (List_Id (F));
9386 procedure Visit_Itype (Old_Itype : Entity_Id) is
9387 New_Itype : Entity_Id;
9392 -- Itypes that describe the designated type of access to subprograms
9393 -- have the structure of subprogram declarations, with signatures,
9394 -- etc. Either we duplicate the signatures completely, or choose to
9395 -- share such itypes, which is fine because their elaboration will
9396 -- have no side effects.
9398 if Ekind (Old_Itype) = E_Subprogram_Type then
9402 New_Itype := New_Copy (Old_Itype);
9404 -- The new Itype has all the attributes of the old one, and
9405 -- we just copy the contents of the entity. However, the back-end
9406 -- needs different names for debugging purposes, so we create a
9407 -- new internal name for it in all cases.
9409 Set_Chars (New_Itype, New_Internal_Name ('T'));
9411 -- If our associated node is an entity that has already been copied,
9412 -- then set the associated node of the copy to point to the right
9413 -- copy. If we have copied an Itype that is itself the associated
9414 -- node of some previously copied Itype, then we set the right
9415 -- pointer in the other direction.
9417 if Present (Actual_Map) then
9419 -- Case of hash tables used
9421 if NCT_Hash_Tables_Used then
9423 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
9425 if Present (Ent) then
9426 Set_Associated_Node_For_Itype (New_Itype, Ent);
9429 Ent := NCT_Itype_Assoc.Get (Old_Itype);
9430 if Present (Ent) then
9431 Set_Associated_Node_For_Itype (Ent, New_Itype);
9433 -- If the hash table has no association for this Itype and
9434 -- its associated node, enter one now.
9438 (Associated_Node_For_Itype (Old_Itype), New_Itype);
9441 -- Case of hash tables not used
9444 E := First_Elmt (Actual_Map);
9445 while Present (E) loop
9446 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
9447 Set_Associated_Node_For_Itype
9448 (New_Itype, Node (Next_Elmt (E)));
9451 if Is_Type (Node (E))
9453 Old_Itype = Associated_Node_For_Itype (Node (E))
9455 Set_Associated_Node_For_Itype
9456 (Node (Next_Elmt (E)), New_Itype);
9459 E := Next_Elmt (Next_Elmt (E));
9464 if Present (Freeze_Node (New_Itype)) then
9465 Set_Is_Frozen (New_Itype, False);
9466 Set_Freeze_Node (New_Itype, Empty);
9469 -- Add new association to map
9471 if No (Actual_Map) then
9472 Actual_Map := New_Elmt_List;
9475 Append_Elmt (Old_Itype, Actual_Map);
9476 Append_Elmt (New_Itype, Actual_Map);
9478 if NCT_Hash_Tables_Used then
9479 NCT_Assoc.Set (Old_Itype, New_Itype);
9482 NCT_Table_Entries := NCT_Table_Entries + 1;
9484 if NCT_Table_Entries > NCT_Hash_Threshold then
9485 Build_NCT_Hash_Tables;
9489 -- If a record subtype is simply copied, the entity list will be
9490 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
9492 if Ekind_In (Old_Itype, E_Record_Subtype, E_Class_Wide_Subtype) then
9493 Set_Cloned_Subtype (New_Itype, Old_Itype);
9496 -- Visit descendents that eventually get copied
9498 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
9500 if Is_Discrete_Type (Old_Itype) then
9501 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
9503 elsif Has_Discriminants (Base_Type (Old_Itype)) then
9504 -- ??? This should involve call to Visit_Field
9505 Visit_Elist (Discriminant_Constraint (Old_Itype));
9507 elsif Is_Array_Type (Old_Itype) then
9508 if Present (First_Index (Old_Itype)) then
9509 Visit_Field (Union_Id (List_Containing
9510 (First_Index (Old_Itype))),
9514 if Is_Packed (Old_Itype) then
9515 Visit_Field (Union_Id (Packed_Array_Type (Old_Itype)),
9525 procedure Visit_List (L : List_Id) is
9528 if L /= No_List then
9531 while Present (N) loop
9542 procedure Visit_Node (N : Node_Or_Entity_Id) is
9544 -- Start of processing for Visit_Node
9547 -- Handle case of an Itype, which must be copied
9549 if Has_Extension (N)
9550 and then Is_Itype (N)
9552 -- Nothing to do if already in the list. This can happen with an
9553 -- Itype entity that appears more than once in the tree.
9554 -- Note that we do not want to visit descendents in this case.
9556 -- Test for already in list when hash table is used
9558 if NCT_Hash_Tables_Used then
9559 if Present (NCT_Assoc.Get (Entity_Id (N))) then
9563 -- Test for already in list when hash table not used
9569 if Present (Actual_Map) then
9570 E := First_Elmt (Actual_Map);
9571 while Present (E) loop
9572 if Node (E) = N then
9575 E := Next_Elmt (Next_Elmt (E));
9585 -- Visit descendents
9587 Visit_Field (Field1 (N), N);
9588 Visit_Field (Field2 (N), N);
9589 Visit_Field (Field3 (N), N);
9590 Visit_Field (Field4 (N), N);
9591 Visit_Field (Field5 (N), N);
9594 -- Start of processing for New_Copy_Tree
9599 -- See if we should use hash table
9601 if No (Actual_Map) then
9602 NCT_Hash_Tables_Used := False;
9609 NCT_Table_Entries := 0;
9611 Elmt := First_Elmt (Actual_Map);
9612 while Present (Elmt) loop
9613 NCT_Table_Entries := NCT_Table_Entries + 1;
9618 if NCT_Table_Entries > NCT_Hash_Threshold then
9619 Build_NCT_Hash_Tables;
9621 NCT_Hash_Tables_Used := False;
9626 -- Hash table set up if required, now start phase one by visiting
9627 -- top node (we will recursively visit the descendents).
9629 Visit_Node (Source);
9631 -- Now the second phase of the copy can start. First we process
9632 -- all the mapped entities, copying their descendents.
9634 if Present (Actual_Map) then
9637 New_Itype : Entity_Id;
9639 Elmt := First_Elmt (Actual_Map);
9640 while Present (Elmt) loop
9642 New_Itype := Node (Elmt);
9643 Copy_Itype_With_Replacement (New_Itype);
9649 -- Now we can copy the actual tree
9651 return Copy_Node_With_Replacement (Source);
9654 -------------------------
9655 -- New_External_Entity --
9656 -------------------------
9658 function New_External_Entity
9659 (Kind : Entity_Kind;
9660 Scope_Id : Entity_Id;
9661 Sloc_Value : Source_Ptr;
9662 Related_Id : Entity_Id;
9664 Suffix_Index : Nat := 0;
9665 Prefix : Character := ' ') return Entity_Id
9667 N : constant Entity_Id :=
9668 Make_Defining_Identifier (Sloc_Value,
9670 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
9673 Set_Ekind (N, Kind);
9674 Set_Is_Internal (N, True);
9675 Append_Entity (N, Scope_Id);
9676 Set_Public_Status (N);
9678 if Kind in Type_Kind then
9679 Init_Size_Align (N);
9683 end New_External_Entity;
9685 -------------------------
9686 -- New_Internal_Entity --
9687 -------------------------
9689 function New_Internal_Entity
9690 (Kind : Entity_Kind;
9691 Scope_Id : Entity_Id;
9692 Sloc_Value : Source_Ptr;
9693 Id_Char : Character) return Entity_Id
9695 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
9698 Set_Ekind (N, Kind);
9699 Set_Is_Internal (N, True);
9700 Append_Entity (N, Scope_Id);
9702 if Kind in Type_Kind then
9703 Init_Size_Align (N);
9707 end New_Internal_Entity;
9713 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
9717 -- If we are pointing at a positional parameter, it is a member of a
9718 -- node list (the list of parameters), and the next parameter is the
9719 -- next node on the list, unless we hit a parameter association, then
9720 -- we shift to using the chain whose head is the First_Named_Actual in
9721 -- the parent, and then is threaded using the Next_Named_Actual of the
9722 -- Parameter_Association. All this fiddling is because the original node
9723 -- list is in the textual call order, and what we need is the
9724 -- declaration order.
9726 if Is_List_Member (Actual_Id) then
9727 N := Next (Actual_Id);
9729 if Nkind (N) = N_Parameter_Association then
9730 return First_Named_Actual (Parent (Actual_Id));
9736 return Next_Named_Actual (Parent (Actual_Id));
9740 procedure Next_Actual (Actual_Id : in out Node_Id) is
9742 Actual_Id := Next_Actual (Actual_Id);
9745 -----------------------
9746 -- Normalize_Actuals --
9747 -----------------------
9749 -- Chain actuals according to formals of subprogram. If there are no named
9750 -- associations, the chain is simply the list of Parameter Associations,
9751 -- since the order is the same as the declaration order. If there are named
9752 -- associations, then the First_Named_Actual field in the N_Function_Call
9753 -- or N_Procedure_Call_Statement node points to the Parameter_Association
9754 -- node for the parameter that comes first in declaration order. The
9755 -- remaining named parameters are then chained in declaration order using
9756 -- Next_Named_Actual.
9758 -- This routine also verifies that the number of actuals is compatible with
9759 -- the number and default values of formals, but performs no type checking
9760 -- (type checking is done by the caller).
9762 -- If the matching succeeds, Success is set to True and the caller proceeds
9763 -- with type-checking. If the match is unsuccessful, then Success is set to
9764 -- False, and the caller attempts a different interpretation, if there is
9767 -- If the flag Report is on, the call is not overloaded, and a failure to
9768 -- match can be reported here, rather than in the caller.
9770 procedure Normalize_Actuals
9774 Success : out Boolean)
9776 Actuals : constant List_Id := Parameter_Associations (N);
9777 Actual : Node_Id := Empty;
9779 Last : Node_Id := Empty;
9780 First_Named : Node_Id := Empty;
9783 Formals_To_Match : Integer := 0;
9784 Actuals_To_Match : Integer := 0;
9786 procedure Chain (A : Node_Id);
9787 -- Add named actual at the proper place in the list, using the
9788 -- Next_Named_Actual link.
9790 function Reporting return Boolean;
9791 -- Determines if an error is to be reported. To report an error, we
9792 -- need Report to be True, and also we do not report errors caused
9793 -- by calls to init procs that occur within other init procs. Such
9794 -- errors must always be cascaded errors, since if all the types are
9795 -- declared correctly, the compiler will certainly build decent calls!
9801 procedure Chain (A : Node_Id) is
9805 -- Call node points to first actual in list
9807 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
9810 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
9814 Set_Next_Named_Actual (Last, Empty);
9821 function Reporting return Boolean is
9826 elsif not Within_Init_Proc then
9829 elsif Is_Init_Proc (Entity (Name (N))) then
9837 -- Start of processing for Normalize_Actuals
9840 if Is_Access_Type (S) then
9842 -- The name in the call is a function call that returns an access
9843 -- to subprogram. The designated type has the list of formals.
9845 Formal := First_Formal (Designated_Type (S));
9847 Formal := First_Formal (S);
9850 while Present (Formal) loop
9851 Formals_To_Match := Formals_To_Match + 1;
9852 Next_Formal (Formal);
9855 -- Find if there is a named association, and verify that no positional
9856 -- associations appear after named ones.
9858 if Present (Actuals) then
9859 Actual := First (Actuals);
9862 while Present (Actual)
9863 and then Nkind (Actual) /= N_Parameter_Association
9865 Actuals_To_Match := Actuals_To_Match + 1;
9869 if No (Actual) and Actuals_To_Match = Formals_To_Match then
9871 -- Most common case: positional notation, no defaults
9876 elsif Actuals_To_Match > Formals_To_Match then
9878 -- Too many actuals: will not work
9881 if Is_Entity_Name (Name (N)) then
9882 Error_Msg_N ("too many arguments in call to&", Name (N));
9884 Error_Msg_N ("too many arguments in call", N);
9892 First_Named := Actual;
9894 while Present (Actual) loop
9895 if Nkind (Actual) /= N_Parameter_Association then
9897 ("positional parameters not allowed after named ones", Actual);
9902 Actuals_To_Match := Actuals_To_Match + 1;
9908 if Present (Actuals) then
9909 Actual := First (Actuals);
9912 Formal := First_Formal (S);
9913 while Present (Formal) loop
9915 -- Match the formals in order. If the corresponding actual is
9916 -- positional, nothing to do. Else scan the list of named actuals
9917 -- to find the one with the right name.
9920 and then Nkind (Actual) /= N_Parameter_Association
9923 Actuals_To_Match := Actuals_To_Match - 1;
9924 Formals_To_Match := Formals_To_Match - 1;
9927 -- For named parameters, search the list of actuals to find
9928 -- one that matches the next formal name.
9930 Actual := First_Named;
9932 while Present (Actual) loop
9933 if Chars (Selector_Name (Actual)) = Chars (Formal) then
9936 Actuals_To_Match := Actuals_To_Match - 1;
9937 Formals_To_Match := Formals_To_Match - 1;
9945 if Ekind (Formal) /= E_In_Parameter
9946 or else No (Default_Value (Formal))
9949 if (Comes_From_Source (S)
9950 or else Sloc (S) = Standard_Location)
9951 and then Is_Overloadable (S)
9955 (Nkind (Parent (N)) = N_Procedure_Call_Statement
9957 (Nkind (Parent (N)) = N_Function_Call
9959 Nkind (Parent (N)) = N_Parameter_Association))
9960 and then Ekind (S) /= E_Function
9962 Set_Etype (N, Etype (S));
9964 Error_Msg_Name_1 := Chars (S);
9965 Error_Msg_Sloc := Sloc (S);
9967 ("missing argument for parameter & " &
9968 "in call to % declared #", N, Formal);
9971 elsif Is_Overloadable (S) then
9972 Error_Msg_Name_1 := Chars (S);
9974 -- Point to type derivation that generated the
9977 Error_Msg_Sloc := Sloc (Parent (S));
9980 ("missing argument for parameter & " &
9981 "in call to % (inherited) #", N, Formal);
9985 ("missing argument for parameter &", N, Formal);
9993 Formals_To_Match := Formals_To_Match - 1;
9998 Next_Formal (Formal);
10001 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
10008 -- Find some superfluous named actual that did not get
10009 -- attached to the list of associations.
10011 Actual := First (Actuals);
10012 while Present (Actual) loop
10013 if Nkind (Actual) = N_Parameter_Association
10014 and then Actual /= Last
10015 and then No (Next_Named_Actual (Actual))
10017 Error_Msg_N ("unmatched actual & in call",
10018 Selector_Name (Actual));
10029 end Normalize_Actuals;
10031 --------------------------------
10032 -- Note_Possible_Modification --
10033 --------------------------------
10035 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
10036 Modification_Comes_From_Source : constant Boolean :=
10037 Comes_From_Source (Parent (N));
10043 -- Loop to find referenced entity, if there is one
10050 if Is_Entity_Name (Exp) then
10051 Ent := Entity (Exp);
10053 -- If the entity is missing, it is an undeclared identifier,
10054 -- and there is nothing to annotate.
10060 elsif Nkind (Exp) = N_Explicit_Dereference then
10062 P : constant Node_Id := Prefix (Exp);
10065 if Nkind (P) = N_Selected_Component
10067 Entry_Formal (Entity (Selector_Name (P))))
10069 -- Case of a reference to an entry formal
10071 Ent := Entry_Formal (Entity (Selector_Name (P)));
10073 elsif Nkind (P) = N_Identifier
10074 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
10075 and then Present (Expression (Parent (Entity (P))))
10076 and then Nkind (Expression (Parent (Entity (P))))
10079 -- Case of a reference to a value on which side effects have
10082 Exp := Prefix (Expression (Parent (Entity (P))));
10091 elsif Nkind (Exp) = N_Type_Conversion
10092 or else Nkind (Exp) = N_Unchecked_Type_Conversion
10094 Exp := Expression (Exp);
10097 elsif Nkind (Exp) = N_Slice
10098 or else Nkind (Exp) = N_Indexed_Component
10099 or else Nkind (Exp) = N_Selected_Component
10101 Exp := Prefix (Exp);
10108 -- Now look for entity being referenced
10110 if Present (Ent) then
10111 if Is_Object (Ent) then
10112 if Comes_From_Source (Exp)
10113 or else Modification_Comes_From_Source
10115 -- Give warning if pragma unmodified given and we are
10116 -- sure this is a modification.
10118 if Has_Pragma_Unmodified (Ent) and then Sure then
10119 Error_Msg_NE ("?pragma Unmodified given for &!", N, Ent);
10122 Set_Never_Set_In_Source (Ent, False);
10125 Set_Is_True_Constant (Ent, False);
10126 Set_Current_Value (Ent, Empty);
10127 Set_Is_Known_Null (Ent, False);
10129 if not Can_Never_Be_Null (Ent) then
10130 Set_Is_Known_Non_Null (Ent, False);
10133 -- Follow renaming chain
10135 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
10136 and then Present (Renamed_Object (Ent))
10138 Exp := Renamed_Object (Ent);
10142 -- Generate a reference only if the assignment comes from
10143 -- source. This excludes, for example, calls to a dispatching
10144 -- assignment operation when the left-hand side is tagged.
10146 if Modification_Comes_From_Source then
10147 Generate_Reference (Ent, Exp, 'm');
10149 -- If the target of the assignment is the bound variable
10150 -- in an iterator, indicate that the corresponding array
10151 -- or container is also modified.
10153 if Ada_Version >= Ada_2012
10155 Nkind (Parent (Ent)) = N_Iterator_Specification
10158 Domain : constant Node_Id := Name (Parent (Ent));
10161 -- TBD : in the full version of the construct, the
10162 -- domain of iteration can be given by an expression.
10164 if Is_Entity_Name (Domain) then
10165 Generate_Reference (Entity (Domain), Exp, 'm');
10166 Set_Is_True_Constant (Entity (Domain), False);
10167 Set_Never_Set_In_Source (Entity (Domain), False);
10173 Check_Nested_Access (Ent);
10178 -- If we are sure this is a modification from source, and we know
10179 -- this modifies a constant, then give an appropriate warning.
10181 if Overlays_Constant (Ent)
10182 and then Modification_Comes_From_Source
10186 A : constant Node_Id := Address_Clause (Ent);
10188 if Present (A) then
10190 Exp : constant Node_Id := Expression (A);
10192 if Nkind (Exp) = N_Attribute_Reference
10193 and then Attribute_Name (Exp) = Name_Address
10194 and then Is_Entity_Name (Prefix (Exp))
10196 Error_Msg_Sloc := Sloc (A);
10198 ("constant& may be modified via address clause#?",
10199 N, Entity (Prefix (Exp)));
10209 end Note_Possible_Modification;
10211 -------------------------
10212 -- Object_Access_Level --
10213 -------------------------
10215 function Object_Access_Level (Obj : Node_Id) return Uint is
10218 -- Returns the static accessibility level of the view denoted by Obj. Note
10219 -- that the value returned is the result of a call to Scope_Depth. Only
10220 -- scope depths associated with dynamic scopes can actually be returned.
10221 -- Since only relative levels matter for accessibility checking, the fact
10222 -- that the distance between successive levels of accessibility is not
10223 -- always one is immaterial (invariant: if level(E2) is deeper than
10224 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
10226 function Reference_To (Obj : Node_Id) return Node_Id;
10227 -- An explicit dereference is created when removing side-effects from
10228 -- expressions for constraint checking purposes. In this case a local
10229 -- access type is created for it. The correct access level is that of
10230 -- the original source node. We detect this case by noting that the
10231 -- prefix of the dereference is created by an object declaration whose
10232 -- initial expression is a reference.
10238 function Reference_To (Obj : Node_Id) return Node_Id is
10239 Pref : constant Node_Id := Prefix (Obj);
10241 if Is_Entity_Name (Pref)
10242 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
10243 and then Present (Expression (Parent (Entity (Pref))))
10244 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
10246 return (Prefix (Expression (Parent (Entity (Pref)))));
10252 -- Start of processing for Object_Access_Level
10255 if Is_Entity_Name (Obj) then
10258 if Is_Prival (E) then
10259 E := Prival_Link (E);
10262 -- If E is a type then it denotes a current instance. For this case
10263 -- we add one to the normal accessibility level of the type to ensure
10264 -- that current instances are treated as always being deeper than
10265 -- than the level of any visible named access type (see 3.10.2(21)).
10267 if Is_Type (E) then
10268 return Type_Access_Level (E) + 1;
10270 elsif Present (Renamed_Object (E)) then
10271 return Object_Access_Level (Renamed_Object (E));
10273 -- Similarly, if E is a component of the current instance of a
10274 -- protected type, any instance of it is assumed to be at a deeper
10275 -- level than the type. For a protected object (whose type is an
10276 -- anonymous protected type) its components are at the same level
10277 -- as the type itself.
10279 elsif not Is_Overloadable (E)
10280 and then Ekind (Scope (E)) = E_Protected_Type
10281 and then Comes_From_Source (Scope (E))
10283 return Type_Access_Level (Scope (E)) + 1;
10286 return Scope_Depth (Enclosing_Dynamic_Scope (E));
10289 elsif Nkind (Obj) = N_Selected_Component then
10290 if Is_Access_Type (Etype (Prefix (Obj))) then
10291 return Type_Access_Level (Etype (Prefix (Obj)));
10293 return Object_Access_Level (Prefix (Obj));
10296 elsif Nkind (Obj) = N_Indexed_Component then
10297 if Is_Access_Type (Etype (Prefix (Obj))) then
10298 return Type_Access_Level (Etype (Prefix (Obj)));
10300 return Object_Access_Level (Prefix (Obj));
10303 elsif Nkind (Obj) = N_Explicit_Dereference then
10305 -- If the prefix is a selected access discriminant then we make a
10306 -- recursive call on the prefix, which will in turn check the level
10307 -- of the prefix object of the selected discriminant.
10309 if Nkind (Prefix (Obj)) = N_Selected_Component
10310 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
10312 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
10314 return Object_Access_Level (Prefix (Obj));
10316 elsif not (Comes_From_Source (Obj)) then
10318 Ref : constant Node_Id := Reference_To (Obj);
10320 if Present (Ref) then
10321 return Object_Access_Level (Ref);
10323 return Type_Access_Level (Etype (Prefix (Obj)));
10328 return Type_Access_Level (Etype (Prefix (Obj)));
10331 elsif Nkind (Obj) = N_Type_Conversion
10332 or else Nkind (Obj) = N_Unchecked_Type_Conversion
10334 return Object_Access_Level (Expression (Obj));
10336 elsif Nkind (Obj) = N_Function_Call then
10338 -- Function results are objects, so we get either the access level of
10339 -- the function or, in the case of an indirect call, the level of the
10340 -- access-to-subprogram type. (This code is used for Ada 95, but it
10341 -- looks wrong, because it seems that we should be checking the level
10342 -- of the call itself, even for Ada 95. However, using the Ada 2005
10343 -- version of the code causes regressions in several tests that are
10344 -- compiled with -gnat95. ???)
10346 if Ada_Version < Ada_2005 then
10347 if Is_Entity_Name (Name (Obj)) then
10348 return Subprogram_Access_Level (Entity (Name (Obj)));
10350 return Type_Access_Level (Etype (Prefix (Name (Obj))));
10353 -- For Ada 2005, the level of the result object of a function call is
10354 -- defined to be the level of the call's innermost enclosing master.
10355 -- We determine that by querying the depth of the innermost enclosing
10359 Return_Master_Scope_Depth_Of_Call : declare
10361 function Innermost_Master_Scope_Depth
10362 (N : Node_Id) return Uint;
10363 -- Returns the scope depth of the given node's innermost
10364 -- enclosing dynamic scope (effectively the accessibility
10365 -- level of the innermost enclosing master).
10367 ----------------------------------
10368 -- Innermost_Master_Scope_Depth --
10369 ----------------------------------
10371 function Innermost_Master_Scope_Depth
10372 (N : Node_Id) return Uint
10374 Node_Par : Node_Id := Parent (N);
10377 -- Locate the nearest enclosing node (by traversing Parents)
10378 -- that Defining_Entity can be applied to, and return the
10379 -- depth of that entity's nearest enclosing dynamic scope.
10381 while Present (Node_Par) loop
10382 case Nkind (Node_Par) is
10383 when N_Component_Declaration |
10384 N_Entry_Declaration |
10385 N_Formal_Object_Declaration |
10386 N_Formal_Type_Declaration |
10387 N_Full_Type_Declaration |
10388 N_Incomplete_Type_Declaration |
10389 N_Loop_Parameter_Specification |
10390 N_Object_Declaration |
10391 N_Protected_Type_Declaration |
10392 N_Private_Extension_Declaration |
10393 N_Private_Type_Declaration |
10394 N_Subtype_Declaration |
10395 N_Function_Specification |
10396 N_Procedure_Specification |
10397 N_Task_Type_Declaration |
10399 N_Generic_Instantiation |
10401 N_Implicit_Label_Declaration |
10402 N_Package_Declaration |
10403 N_Single_Task_Declaration |
10404 N_Subprogram_Declaration |
10405 N_Generic_Declaration |
10406 N_Renaming_Declaration |
10407 N_Block_Statement |
10408 N_Formal_Subprogram_Declaration |
10409 N_Abstract_Subprogram_Declaration |
10411 N_Exception_Declaration |
10412 N_Formal_Package_Declaration |
10413 N_Number_Declaration |
10414 N_Package_Specification |
10415 N_Parameter_Specification |
10416 N_Single_Protected_Declaration |
10420 (Nearest_Dynamic_Scope
10421 (Defining_Entity (Node_Par)));
10427 Node_Par := Parent (Node_Par);
10430 pragma Assert (False);
10432 -- Should never reach the following return
10434 return Scope_Depth (Current_Scope) + 1;
10435 end Innermost_Master_Scope_Depth;
10437 -- Start of processing for Return_Master_Scope_Depth_Of_Call
10440 return Innermost_Master_Scope_Depth (Obj);
10441 end Return_Master_Scope_Depth_Of_Call;
10444 -- For convenience we handle qualified expressions, even though
10445 -- they aren't technically object names.
10447 elsif Nkind (Obj) = N_Qualified_Expression then
10448 return Object_Access_Level (Expression (Obj));
10450 -- Otherwise return the scope level of Standard.
10451 -- (If there are cases that fall through
10452 -- to this point they will be treated as
10453 -- having global accessibility for now. ???)
10456 return Scope_Depth (Standard_Standard);
10458 end Object_Access_Level;
10460 --------------------------------------
10461 -- Original_Corresponding_Operation --
10462 --------------------------------------
10464 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
10466 Typ : constant Entity_Id := Find_Dispatching_Type (S);
10469 -- If S is an inherited primitive S2 the original corresponding
10470 -- operation of S is the original corresponding operation of S2
10472 if Present (Alias (S))
10473 and then Find_Dispatching_Type (Alias (S)) /= Typ
10475 return Original_Corresponding_Operation (Alias (S));
10477 -- If S overrides an inherited subprogram S2 the original corresponding
10478 -- operation of S is the original corresponding operation of S2
10480 elsif Present (Overridden_Operation (S)) then
10481 return Original_Corresponding_Operation (Overridden_Operation (S));
10483 -- otherwise it is S itself
10488 end Original_Corresponding_Operation;
10490 -----------------------
10491 -- Private_Component --
10492 -----------------------
10494 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
10495 Ancestor : constant Entity_Id := Base_Type (Type_Id);
10497 function Trace_Components
10499 Check : Boolean) return Entity_Id;
10500 -- Recursive function that does the work, and checks against circular
10501 -- definition for each subcomponent type.
10503 ----------------------
10504 -- Trace_Components --
10505 ----------------------
10507 function Trace_Components
10509 Check : Boolean) return Entity_Id
10511 Btype : constant Entity_Id := Base_Type (T);
10512 Component : Entity_Id;
10514 Candidate : Entity_Id := Empty;
10517 if Check and then Btype = Ancestor then
10518 Error_Msg_N ("circular type definition", Type_Id);
10522 if Is_Private_Type (Btype)
10523 and then not Is_Generic_Type (Btype)
10525 if Present (Full_View (Btype))
10526 and then Is_Record_Type (Full_View (Btype))
10527 and then not Is_Frozen (Btype)
10529 -- To indicate that the ancestor depends on a private type, the
10530 -- current Btype is sufficient. However, to check for circular
10531 -- definition we must recurse on the full view.
10533 Candidate := Trace_Components (Full_View (Btype), True);
10535 if Candidate = Any_Type then
10545 elsif Is_Array_Type (Btype) then
10546 return Trace_Components (Component_Type (Btype), True);
10548 elsif Is_Record_Type (Btype) then
10549 Component := First_Entity (Btype);
10550 while Present (Component) loop
10552 -- Skip anonymous types generated by constrained components
10554 if not Is_Type (Component) then
10555 P := Trace_Components (Etype (Component), True);
10557 if Present (P) then
10558 if P = Any_Type then
10566 Next_Entity (Component);
10574 end Trace_Components;
10576 -- Start of processing for Private_Component
10579 return Trace_Components (Type_Id, False);
10580 end Private_Component;
10582 ---------------------------
10583 -- Primitive_Names_Match --
10584 ---------------------------
10586 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
10588 function Non_Internal_Name (E : Entity_Id) return Name_Id;
10589 -- Given an internal name, returns the corresponding non-internal name
10591 ------------------------
10592 -- Non_Internal_Name --
10593 ------------------------
10595 function Non_Internal_Name (E : Entity_Id) return Name_Id is
10597 Get_Name_String (Chars (E));
10598 Name_Len := Name_Len - 1;
10600 end Non_Internal_Name;
10602 -- Start of processing for Primitive_Names_Match
10605 pragma Assert (Present (E1) and then Present (E2));
10607 return Chars (E1) = Chars (E2)
10609 (not Is_Internal_Name (Chars (E1))
10610 and then Is_Internal_Name (Chars (E2))
10611 and then Non_Internal_Name (E2) = Chars (E1))
10613 (not Is_Internal_Name (Chars (E2))
10614 and then Is_Internal_Name (Chars (E1))
10615 and then Non_Internal_Name (E1) = Chars (E2))
10617 (Is_Predefined_Dispatching_Operation (E1)
10618 and then Is_Predefined_Dispatching_Operation (E2)
10619 and then Same_TSS (E1, E2))
10621 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
10622 end Primitive_Names_Match;
10624 -----------------------
10625 -- Process_End_Label --
10626 -----------------------
10628 procedure Process_End_Label
10637 Label_Ref : Boolean;
10638 -- Set True if reference to end label itself is required
10641 -- Gets set to the operator symbol or identifier that references the
10642 -- entity Ent. For the child unit case, this is the identifier from the
10643 -- designator. For other cases, this is simply Endl.
10645 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
10646 -- N is an identifier node that appears as a parent unit reference in
10647 -- the case where Ent is a child unit. This procedure generates an
10648 -- appropriate cross-reference entry. E is the corresponding entity.
10650 -------------------------
10651 -- Generate_Parent_Ref --
10652 -------------------------
10654 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
10656 -- If names do not match, something weird, skip reference
10658 if Chars (E) = Chars (N) then
10660 -- Generate the reference. We do NOT consider this as a reference
10661 -- for unreferenced symbol purposes.
10663 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
10665 if Style_Check then
10666 Style.Check_Identifier (N, E);
10669 end Generate_Parent_Ref;
10671 -- Start of processing for Process_End_Label
10674 -- If no node, ignore. This happens in some error situations, and
10675 -- also for some internally generated structures where no end label
10676 -- references are required in any case.
10682 -- Nothing to do if no End_Label, happens for internally generated
10683 -- constructs where we don't want an end label reference anyway. Also
10684 -- nothing to do if Endl is a string literal, which means there was
10685 -- some prior error (bad operator symbol)
10687 Endl := End_Label (N);
10689 if No (Endl) or else Nkind (Endl) = N_String_Literal then
10693 -- Reference node is not in extended main source unit
10695 if not In_Extended_Main_Source_Unit (N) then
10697 -- Generally we do not collect references except for the extended
10698 -- main source unit. The one exception is the 'e' entry for a
10699 -- package spec, where it is useful for a client to have the
10700 -- ending information to define scopes.
10706 Label_Ref := False;
10708 -- For this case, we can ignore any parent references, but we
10709 -- need the package name itself for the 'e' entry.
10711 if Nkind (Endl) = N_Designator then
10712 Endl := Identifier (Endl);
10716 -- Reference is in extended main source unit
10721 -- For designator, generate references for the parent entries
10723 if Nkind (Endl) = N_Designator then
10725 -- Generate references for the prefix if the END line comes from
10726 -- source (otherwise we do not need these references) We climb the
10727 -- scope stack to find the expected entities.
10729 if Comes_From_Source (Endl) then
10730 Nam := Name (Endl);
10731 Scop := Current_Scope;
10732 while Nkind (Nam) = N_Selected_Component loop
10733 Scop := Scope (Scop);
10734 exit when No (Scop);
10735 Generate_Parent_Ref (Selector_Name (Nam), Scop);
10736 Nam := Prefix (Nam);
10739 if Present (Scop) then
10740 Generate_Parent_Ref (Nam, Scope (Scop));
10744 Endl := Identifier (Endl);
10748 -- If the end label is not for the given entity, then either we have
10749 -- some previous error, or this is a generic instantiation for which
10750 -- we do not need to make a cross-reference in this case anyway. In
10751 -- either case we simply ignore the call.
10753 if Chars (Ent) /= Chars (Endl) then
10757 -- If label was really there, then generate a normal reference and then
10758 -- adjust the location in the end label to point past the name (which
10759 -- should almost always be the semicolon).
10761 Loc := Sloc (Endl);
10763 if Comes_From_Source (Endl) then
10765 -- If a label reference is required, then do the style check and
10766 -- generate an l-type cross-reference entry for the label
10769 if Style_Check then
10770 Style.Check_Identifier (Endl, Ent);
10773 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
10776 -- Set the location to point past the label (normally this will
10777 -- mean the semicolon immediately following the label). This is
10778 -- done for the sake of the 'e' or 't' entry generated below.
10780 Get_Decoded_Name_String (Chars (Endl));
10781 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
10784 -- In SPARK mode, no missing label is allowed for packages and
10785 -- subprogram bodies. Detect those cases by testing whether
10786 -- Process_End_Label was called for a body (Typ = 't') or a package.
10788 if (SPARK_Mode or else Restriction_Check_Required (SPARK))
10789 and then (Typ = 't' or else Ekind (Ent) = E_Package)
10791 Error_Msg_Node_1 := Endl;
10792 Check_Formal_Restriction ("`END &` required", Endl, Force => True);
10796 -- Now generate the e/t reference
10798 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
10800 -- Restore Sloc, in case modified above, since we have an identifier
10801 -- and the normal Sloc should be left set in the tree.
10803 Set_Sloc (Endl, Loc);
10804 end Process_End_Label;
10806 ------------------------------------
10807 -- References_Generic_Formal_Type --
10808 ------------------------------------
10810 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
10812 function Process (N : Node_Id) return Traverse_Result;
10813 -- Process one node in search for generic formal type
10819 function Process (N : Node_Id) return Traverse_Result is
10821 if Nkind (N) in N_Has_Entity then
10823 E : constant Entity_Id := Entity (N);
10825 if Present (E) then
10826 if Is_Generic_Type (E) then
10828 elsif Present (Etype (E))
10829 and then Is_Generic_Type (Etype (E))
10840 function Traverse is new Traverse_Func (Process);
10841 -- Traverse tree to look for generic type
10844 if Inside_A_Generic then
10845 return Traverse (N) = Abandon;
10849 end References_Generic_Formal_Type;
10851 --------------------
10852 -- Remove_Homonym --
10853 --------------------
10855 procedure Remove_Homonym (E : Entity_Id) is
10856 Prev : Entity_Id := Empty;
10860 if E = Current_Entity (E) then
10861 if Present (Homonym (E)) then
10862 Set_Current_Entity (Homonym (E));
10864 Set_Name_Entity_Id (Chars (E), Empty);
10867 H := Current_Entity (E);
10868 while Present (H) and then H /= E loop
10873 Set_Homonym (Prev, Homonym (E));
10875 end Remove_Homonym;
10877 ---------------------
10878 -- Rep_To_Pos_Flag --
10879 ---------------------
10881 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
10883 return New_Occurrence_Of
10884 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
10885 end Rep_To_Pos_Flag;
10887 --------------------
10888 -- Require_Entity --
10889 --------------------
10891 procedure Require_Entity (N : Node_Id) is
10893 if Is_Entity_Name (N) and then No (Entity (N)) then
10894 if Total_Errors_Detected /= 0 then
10895 Set_Entity (N, Any_Id);
10897 raise Program_Error;
10900 end Require_Entity;
10902 ------------------------------
10903 -- Requires_Transient_Scope --
10904 ------------------------------
10906 -- A transient scope is required when variable-sized temporaries are
10907 -- allocated in the primary or secondary stack, or when finalization
10908 -- actions must be generated before the next instruction.
10910 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
10911 Typ : constant Entity_Id := Underlying_Type (Id);
10913 -- Start of processing for Requires_Transient_Scope
10916 -- This is a private type which is not completed yet. This can only
10917 -- happen in a default expression (of a formal parameter or of a
10918 -- record component). Do not expand transient scope in this case
10923 -- Do not expand transient scope for non-existent procedure return
10925 elsif Typ = Standard_Void_Type then
10928 -- Elementary types do not require a transient scope
10930 elsif Is_Elementary_Type (Typ) then
10933 -- Generally, indefinite subtypes require a transient scope, since the
10934 -- back end cannot generate temporaries, since this is not a valid type
10935 -- for declaring an object. It might be possible to relax this in the
10936 -- future, e.g. by declaring the maximum possible space for the type.
10938 elsif Is_Indefinite_Subtype (Typ) then
10941 -- Functions returning tagged types may dispatch on result so their
10942 -- returned value is allocated on the secondary stack. Controlled
10943 -- type temporaries need finalization.
10945 elsif Is_Tagged_Type (Typ)
10946 or else Has_Controlled_Component (Typ)
10948 return not Is_Value_Type (Typ);
10952 elsif Is_Record_Type (Typ) then
10956 Comp := First_Entity (Typ);
10957 while Present (Comp) loop
10958 if Ekind (Comp) = E_Component
10959 and then Requires_Transient_Scope (Etype (Comp))
10963 Next_Entity (Comp);
10970 -- String literal types never require transient scope
10972 elsif Ekind (Typ) = E_String_Literal_Subtype then
10975 -- Array type. Note that we already know that this is a constrained
10976 -- array, since unconstrained arrays will fail the indefinite test.
10978 elsif Is_Array_Type (Typ) then
10980 -- If component type requires a transient scope, the array does too
10982 if Requires_Transient_Scope (Component_Type (Typ)) then
10985 -- Otherwise, we only need a transient scope if the size depends on
10986 -- the value of one or more discriminants.
10989 return Size_Depends_On_Discriminant (Typ);
10992 -- All other cases do not require a transient scope
10997 end Requires_Transient_Scope;
10999 --------------------------
11000 -- Reset_Analyzed_Flags --
11001 --------------------------
11003 procedure Reset_Analyzed_Flags (N : Node_Id) is
11005 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
11006 -- Function used to reset Analyzed flags in tree. Note that we do
11007 -- not reset Analyzed flags in entities, since there is no need to
11008 -- reanalyze entities, and indeed, it is wrong to do so, since it
11009 -- can result in generating auxiliary stuff more than once.
11011 --------------------
11012 -- Clear_Analyzed --
11013 --------------------
11015 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
11017 if not Has_Extension (N) then
11018 Set_Analyzed (N, False);
11022 end Clear_Analyzed;
11024 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
11026 -- Start of processing for Reset_Analyzed_Flags
11029 Reset_Analyzed (N);
11030 end Reset_Analyzed_Flags;
11032 ---------------------------
11033 -- Safe_To_Capture_Value --
11034 ---------------------------
11036 function Safe_To_Capture_Value
11039 Cond : Boolean := False) return Boolean
11042 -- The only entities for which we track constant values are variables
11043 -- which are not renamings, constants, out parameters, and in out
11044 -- parameters, so check if we have this case.
11046 -- Note: it may seem odd to track constant values for constants, but in
11047 -- fact this routine is used for other purposes than simply capturing
11048 -- the value. In particular, the setting of Known[_Non]_Null.
11050 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
11052 Ekind (Ent) = E_Constant
11054 Ekind (Ent) = E_Out_Parameter
11056 Ekind (Ent) = E_In_Out_Parameter
11060 -- For conditionals, we also allow loop parameters and all formals,
11061 -- including in parameters.
11065 (Ekind (Ent) = E_Loop_Parameter
11067 Ekind (Ent) = E_In_Parameter)
11071 -- For all other cases, not just unsafe, but impossible to capture
11072 -- Current_Value, since the above are the only entities which have
11073 -- Current_Value fields.
11079 -- Skip if volatile or aliased, since funny things might be going on in
11080 -- these cases which we cannot necessarily track. Also skip any variable
11081 -- for which an address clause is given, or whose address is taken. Also
11082 -- never capture value of library level variables (an attempt to do so
11083 -- can occur in the case of package elaboration code).
11085 if Treat_As_Volatile (Ent)
11086 or else Is_Aliased (Ent)
11087 or else Present (Address_Clause (Ent))
11088 or else Address_Taken (Ent)
11089 or else (Is_Library_Level_Entity (Ent)
11090 and then Ekind (Ent) = E_Variable)
11095 -- OK, all above conditions are met. We also require that the scope of
11096 -- the reference be the same as the scope of the entity, not counting
11097 -- packages and blocks and loops.
11100 E_Scope : constant Entity_Id := Scope (Ent);
11101 R_Scope : Entity_Id;
11104 R_Scope := Current_Scope;
11105 while R_Scope /= Standard_Standard loop
11106 exit when R_Scope = E_Scope;
11108 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
11111 R_Scope := Scope (R_Scope);
11116 -- We also require that the reference does not appear in a context
11117 -- where it is not sure to be executed (i.e. a conditional context
11118 -- or an exception handler). We skip this if Cond is True, since the
11119 -- capturing of values from conditional tests handles this ok.
11133 while Present (P) loop
11134 if Nkind (P) = N_If_Statement
11135 or else Nkind (P) = N_Case_Statement
11136 or else (Nkind (P) in N_Short_Circuit
11137 and then Desc = Right_Opnd (P))
11138 or else (Nkind (P) = N_Conditional_Expression
11139 and then Desc /= First (Expressions (P)))
11140 or else Nkind (P) = N_Exception_Handler
11141 or else Nkind (P) = N_Selective_Accept
11142 or else Nkind (P) = N_Conditional_Entry_Call
11143 or else Nkind (P) = N_Timed_Entry_Call
11144 or else Nkind (P) = N_Asynchronous_Select
11154 -- OK, looks safe to set value
11157 end Safe_To_Capture_Value;
11163 function Same_Name (N1, N2 : Node_Id) return Boolean is
11164 K1 : constant Node_Kind := Nkind (N1);
11165 K2 : constant Node_Kind := Nkind (N2);
11168 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
11169 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
11171 return Chars (N1) = Chars (N2);
11173 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
11174 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
11176 return Same_Name (Selector_Name (N1), Selector_Name (N2))
11177 and then Same_Name (Prefix (N1), Prefix (N2));
11188 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
11189 N1 : constant Node_Id := Original_Node (Node1);
11190 N2 : constant Node_Id := Original_Node (Node2);
11191 -- We do the tests on original nodes, since we are most interested
11192 -- in the original source, not any expansion that got in the way.
11194 K1 : constant Node_Kind := Nkind (N1);
11195 K2 : constant Node_Kind := Nkind (N2);
11198 -- First case, both are entities with same entity
11200 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
11202 EN1 : constant Entity_Id := Entity (N1);
11203 EN2 : constant Entity_Id := Entity (N2);
11205 if Present (EN1) and then Present (EN2)
11206 and then (Ekind_In (EN1, E_Variable, E_Constant)
11207 or else Is_Formal (EN1))
11215 -- Second case, selected component with same selector, same record
11217 if K1 = N_Selected_Component
11218 and then K2 = N_Selected_Component
11219 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
11221 return Same_Object (Prefix (N1), Prefix (N2));
11223 -- Third case, indexed component with same subscripts, same array
11225 elsif K1 = N_Indexed_Component
11226 and then K2 = N_Indexed_Component
11227 and then Same_Object (Prefix (N1), Prefix (N2))
11232 E1 := First (Expressions (N1));
11233 E2 := First (Expressions (N2));
11234 while Present (E1) loop
11235 if not Same_Value (E1, E2) then
11246 -- Fourth case, slice of same array with same bounds
11249 and then K2 = N_Slice
11250 and then Nkind (Discrete_Range (N1)) = N_Range
11251 and then Nkind (Discrete_Range (N2)) = N_Range
11252 and then Same_Value (Low_Bound (Discrete_Range (N1)),
11253 Low_Bound (Discrete_Range (N2)))
11254 and then Same_Value (High_Bound (Discrete_Range (N1)),
11255 High_Bound (Discrete_Range (N2)))
11257 return Same_Name (Prefix (N1), Prefix (N2));
11259 -- All other cases, not clearly the same object
11270 function Same_Type (T1, T2 : Entity_Id) return Boolean is
11275 elsif not Is_Constrained (T1)
11276 and then not Is_Constrained (T2)
11277 and then Base_Type (T1) = Base_Type (T2)
11281 -- For now don't bother with case of identical constraints, to be
11282 -- fiddled with later on perhaps (this is only used for optimization
11283 -- purposes, so it is not critical to do a best possible job)
11294 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
11296 if Compile_Time_Known_Value (Node1)
11297 and then Compile_Time_Known_Value (Node2)
11298 and then Expr_Value (Node1) = Expr_Value (Node2)
11301 elsif Same_Object (Node1, Node2) then
11312 procedure Save_Actual (N : Node_Id; Writable : Boolean := False) is
11314 if Ada_Version < Ada_2012 then
11317 elsif Is_Entity_Name (N)
11319 Nkind_In (N, N_Indexed_Component, N_Selected_Component, N_Slice)
11321 (Nkind (N) = N_Attribute_Reference
11322 and then Attribute_Name (N) = Name_Access)
11325 -- We are only interested in IN OUT parameters of inner calls
11328 or else Nkind (Parent (N)) = N_Function_Call
11329 or else Nkind (Parent (N)) in N_Op
11331 Actuals_In_Call.Increment_Last;
11332 Actuals_In_Call.Table (Actuals_In_Call.Last) := (N, Writable);
11337 ------------------------
11338 -- Scope_Is_Transient --
11339 ------------------------
11341 function Scope_Is_Transient return Boolean is
11343 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
11344 end Scope_Is_Transient;
11350 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
11355 while Scop /= Standard_Standard loop
11356 Scop := Scope (Scop);
11358 if Scop = Scope2 then
11366 --------------------------
11367 -- Scope_Within_Or_Same --
11368 --------------------------
11370 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
11375 while Scop /= Standard_Standard loop
11376 if Scop = Scope2 then
11379 Scop := Scope (Scop);
11384 end Scope_Within_Or_Same;
11386 --------------------
11387 -- Set_Convention --
11388 --------------------
11390 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
11392 Basic_Set_Convention (E, Val);
11395 and then Is_Access_Subprogram_Type (Base_Type (E))
11396 and then Has_Foreign_Convention (E)
11398 Set_Can_Use_Internal_Rep (E, False);
11400 end Set_Convention;
11402 ------------------------
11403 -- Set_Current_Entity --
11404 ------------------------
11406 -- The given entity is to be set as the currently visible definition
11407 -- of its associated name (i.e. the Node_Id associated with its name).
11408 -- All we have to do is to get the name from the identifier, and
11409 -- then set the associated Node_Id to point to the given entity.
11411 procedure Set_Current_Entity (E : Entity_Id) is
11413 Set_Name_Entity_Id (Chars (E), E);
11414 end Set_Current_Entity;
11416 ---------------------------
11417 -- Set_Debug_Info_Needed --
11418 ---------------------------
11420 procedure Set_Debug_Info_Needed (T : Entity_Id) is
11422 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
11423 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
11424 -- Used to set debug info in a related node if not set already
11426 --------------------------------------
11427 -- Set_Debug_Info_Needed_If_Not_Set --
11428 --------------------------------------
11430 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
11433 and then not Needs_Debug_Info (E)
11435 Set_Debug_Info_Needed (E);
11437 -- For a private type, indicate that the full view also needs
11438 -- debug information.
11441 and then Is_Private_Type (E)
11442 and then Present (Full_View (E))
11444 Set_Debug_Info_Needed (Full_View (E));
11447 end Set_Debug_Info_Needed_If_Not_Set;
11449 -- Start of processing for Set_Debug_Info_Needed
11452 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
11453 -- indicates that Debug_Info_Needed is never required for the entity.
11456 or else Debug_Info_Off (T)
11461 -- Set flag in entity itself. Note that we will go through the following
11462 -- circuitry even if the flag is already set on T. That's intentional,
11463 -- it makes sure that the flag will be set in subsidiary entities.
11465 Set_Needs_Debug_Info (T);
11467 -- Set flag on subsidiary entities if not set already
11469 if Is_Object (T) then
11470 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
11472 elsif Is_Type (T) then
11473 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
11475 if Is_Record_Type (T) then
11477 Ent : Entity_Id := First_Entity (T);
11479 while Present (Ent) loop
11480 Set_Debug_Info_Needed_If_Not_Set (Ent);
11485 -- For a class wide subtype, we also need debug information
11486 -- for the equivalent type.
11488 if Ekind (T) = E_Class_Wide_Subtype then
11489 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
11492 elsif Is_Array_Type (T) then
11493 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
11496 Indx : Node_Id := First_Index (T);
11498 while Present (Indx) loop
11499 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
11500 Indx := Next_Index (Indx);
11504 if Is_Packed (T) then
11505 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Type (T));
11508 elsif Is_Access_Type (T) then
11509 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
11511 elsif Is_Private_Type (T) then
11512 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
11514 elsif Is_Protected_Type (T) then
11515 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
11518 end Set_Debug_Info_Needed;
11520 ---------------------------------
11521 -- Set_Entity_With_Style_Check --
11522 ---------------------------------
11524 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
11525 Val_Actual : Entity_Id;
11529 Set_Entity (N, Val);
11532 and then not Suppress_Style_Checks (Val)
11533 and then not In_Instance
11535 if Nkind (N) = N_Identifier then
11537 elsif Nkind (N) = N_Expanded_Name then
11538 Nod := Selector_Name (N);
11543 -- A special situation arises for derived operations, where we want
11544 -- to do the check against the parent (since the Sloc of the derived
11545 -- operation points to the derived type declaration itself).
11548 while not Comes_From_Source (Val_Actual)
11549 and then Nkind (Val_Actual) in N_Entity
11550 and then (Ekind (Val_Actual) = E_Enumeration_Literal
11551 or else Is_Subprogram (Val_Actual)
11552 or else Is_Generic_Subprogram (Val_Actual))
11553 and then Present (Alias (Val_Actual))
11555 Val_Actual := Alias (Val_Actual);
11558 -- Renaming declarations for generic actuals do not come from source,
11559 -- and have a different name from that of the entity they rename, so
11560 -- there is no style check to perform here.
11562 if Chars (Nod) = Chars (Val_Actual) then
11563 Style.Check_Identifier (Nod, Val_Actual);
11567 Set_Entity (N, Val);
11568 end Set_Entity_With_Style_Check;
11570 ------------------------
11571 -- Set_Name_Entity_Id --
11572 ------------------------
11574 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
11576 Set_Name_Table_Info (Id, Int (Val));
11577 end Set_Name_Entity_Id;
11579 ---------------------
11580 -- Set_Next_Actual --
11581 ---------------------
11583 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
11585 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
11586 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
11588 end Set_Next_Actual;
11590 ----------------------------------
11591 -- Set_Optimize_Alignment_Flags --
11592 ----------------------------------
11594 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
11596 if Optimize_Alignment = 'S' then
11597 Set_Optimize_Alignment_Space (E);
11598 elsif Optimize_Alignment = 'T' then
11599 Set_Optimize_Alignment_Time (E);
11601 end Set_Optimize_Alignment_Flags;
11603 -----------------------
11604 -- Set_Public_Status --
11605 -----------------------
11607 procedure Set_Public_Status (Id : Entity_Id) is
11608 S : constant Entity_Id := Current_Scope;
11610 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
11611 -- Determines if E is defined within handled statement sequence or
11612 -- an if statement, returns True if so, False otherwise.
11614 ----------------------
11615 -- Within_HSS_Or_If --
11616 ----------------------
11618 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
11621 N := Declaration_Node (E);
11628 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
11634 end Within_HSS_Or_If;
11636 -- Start of processing for Set_Public_Status
11639 -- Everything in the scope of Standard is public
11641 if S = Standard_Standard then
11642 Set_Is_Public (Id);
11644 -- Entity is definitely not public if enclosing scope is not public
11646 elsif not Is_Public (S) then
11649 -- An object or function declaration that occurs in a handled sequence
11650 -- of statements or within an if statement is the declaration for a
11651 -- temporary object or local subprogram generated by the expander. It
11652 -- never needs to be made public and furthermore, making it public can
11653 -- cause back end problems.
11655 elsif Nkind_In (Parent (Id), N_Object_Declaration,
11656 N_Function_Specification)
11657 and then Within_HSS_Or_If (Id)
11661 -- Entities in public packages or records are public
11663 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
11664 Set_Is_Public (Id);
11666 -- The bounds of an entry family declaration can generate object
11667 -- declarations that are visible to the back-end, e.g. in the
11668 -- the declaration of a composite type that contains tasks.
11670 elsif Is_Concurrent_Type (S)
11671 and then not Has_Completion (S)
11672 and then Nkind (Parent (Id)) = N_Object_Declaration
11674 Set_Is_Public (Id);
11676 end Set_Public_Status;
11678 -----------------------------
11679 -- Set_Referenced_Modified --
11680 -----------------------------
11682 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
11686 -- Deal with indexed or selected component where prefix is modified
11688 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
11689 Pref := Prefix (N);
11691 -- If prefix is access type, then it is the designated object that is
11692 -- being modified, which means we have no entity to set the flag on.
11694 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
11697 -- Otherwise chase the prefix
11700 Set_Referenced_Modified (Pref, Out_Param);
11703 -- Otherwise see if we have an entity name (only other case to process)
11705 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
11706 Set_Referenced_As_LHS (Entity (N), not Out_Param);
11707 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
11709 end Set_Referenced_Modified;
11711 ----------------------------
11712 -- Set_Scope_Is_Transient --
11713 ----------------------------
11715 procedure Set_Scope_Is_Transient (V : Boolean := True) is
11717 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
11718 end Set_Scope_Is_Transient;
11720 -------------------
11721 -- Set_Size_Info --
11722 -------------------
11724 procedure Set_Size_Info (T1, T2 : Entity_Id) is
11726 -- We copy Esize, but not RM_Size, since in general RM_Size is
11727 -- subtype specific and does not get inherited by all subtypes.
11729 Set_Esize (T1, Esize (T2));
11730 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
11732 if Is_Discrete_Or_Fixed_Point_Type (T1)
11734 Is_Discrete_Or_Fixed_Point_Type (T2)
11736 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
11739 Set_Alignment (T1, Alignment (T2));
11742 --------------------
11743 -- Static_Boolean --
11744 --------------------
11746 function Static_Boolean (N : Node_Id) return Uint is
11748 Analyze_And_Resolve (N, Standard_Boolean);
11751 or else Error_Posted (N)
11752 or else Etype (N) = Any_Type
11757 if Is_Static_Expression (N) then
11758 if not Raises_Constraint_Error (N) then
11759 return Expr_Value (N);
11764 elsif Etype (N) = Any_Type then
11768 Flag_Non_Static_Expr
11769 ("static boolean expression required here", N);
11772 end Static_Boolean;
11774 --------------------
11775 -- Static_Integer --
11776 --------------------
11778 function Static_Integer (N : Node_Id) return Uint is
11780 Analyze_And_Resolve (N, Any_Integer);
11783 or else Error_Posted (N)
11784 or else Etype (N) = Any_Type
11789 if Is_Static_Expression (N) then
11790 if not Raises_Constraint_Error (N) then
11791 return Expr_Value (N);
11796 elsif Etype (N) = Any_Type then
11800 Flag_Non_Static_Expr
11801 ("static integer expression required here", N);
11804 end Static_Integer;
11806 --------------------------
11807 -- Statically_Different --
11808 --------------------------
11810 function Statically_Different (E1, E2 : Node_Id) return Boolean is
11811 R1 : constant Node_Id := Get_Referenced_Object (E1);
11812 R2 : constant Node_Id := Get_Referenced_Object (E2);
11814 return Is_Entity_Name (R1)
11815 and then Is_Entity_Name (R2)
11816 and then Entity (R1) /= Entity (R2)
11817 and then not Is_Formal (Entity (R1))
11818 and then not Is_Formal (Entity (R2));
11819 end Statically_Different;
11821 -----------------------------
11822 -- Subprogram_Access_Level --
11823 -----------------------------
11825 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
11827 if Present (Alias (Subp)) then
11828 return Subprogram_Access_Level (Alias (Subp));
11830 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
11832 end Subprogram_Access_Level;
11838 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
11840 if Debug_Flag_W then
11841 for J in 0 .. Scope_Stack.Last loop
11846 Write_Name (Chars (E));
11847 Write_Str (" from ");
11848 Write_Location (Sloc (N));
11853 -----------------------
11854 -- Transfer_Entities --
11855 -----------------------
11857 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
11858 Ent : Entity_Id := First_Entity (From);
11865 if (Last_Entity (To)) = Empty then
11866 Set_First_Entity (To, Ent);
11868 Set_Next_Entity (Last_Entity (To), Ent);
11871 Set_Last_Entity (To, Last_Entity (From));
11873 while Present (Ent) loop
11874 Set_Scope (Ent, To);
11876 if not Is_Public (Ent) then
11877 Set_Public_Status (Ent);
11880 and then Ekind (Ent) = E_Record_Subtype
11883 -- The components of the propagated Itype must be public
11889 Comp := First_Entity (Ent);
11890 while Present (Comp) loop
11891 Set_Is_Public (Comp);
11892 Next_Entity (Comp);
11901 Set_First_Entity (From, Empty);
11902 Set_Last_Entity (From, Empty);
11903 end Transfer_Entities;
11905 -----------------------
11906 -- Type_Access_Level --
11907 -----------------------
11909 function Type_Access_Level (Typ : Entity_Id) return Uint is
11913 Btyp := Base_Type (Typ);
11915 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
11916 -- simply use the level where the type is declared. This is true for
11917 -- stand-alone object declarations, and for anonymous access types
11918 -- associated with components the level is the same as that of the
11919 -- enclosing composite type. However, special treatment is needed for
11920 -- the cases of access parameters, return objects of an anonymous access
11921 -- type, and, in Ada 95, access discriminants of limited types.
11923 if Ekind (Btyp) in Access_Kind then
11924 if Ekind (Btyp) = E_Anonymous_Access_Type then
11926 -- If the type is a nonlocal anonymous access type (such as for
11927 -- an access parameter) we treat it as being declared at the
11928 -- library level to ensure that names such as X.all'access don't
11929 -- fail static accessibility checks.
11931 if not Is_Local_Anonymous_Access (Typ) then
11932 return Scope_Depth (Standard_Standard);
11934 -- If this is a return object, the accessibility level is that of
11935 -- the result subtype of the enclosing function. The test here is
11936 -- little complicated, because we have to account for extended
11937 -- return statements that have been rewritten as blocks, in which
11938 -- case we have to find and the Is_Return_Object attribute of the
11939 -- itype's associated object. It would be nice to find a way to
11940 -- simplify this test, but it doesn't seem worthwhile to add a new
11941 -- flag just for purposes of this test. ???
11943 elsif Ekind (Scope (Btyp)) = E_Return_Statement
11946 and then Nkind (Associated_Node_For_Itype (Btyp)) =
11947 N_Object_Declaration
11948 and then Is_Return_Object
11949 (Defining_Identifier
11950 (Associated_Node_For_Itype (Btyp))))
11956 Scop := Scope (Scope (Btyp));
11957 while Present (Scop) loop
11958 exit when Ekind (Scop) = E_Function;
11959 Scop := Scope (Scop);
11962 -- Treat the return object's type as having the level of the
11963 -- function's result subtype (as per RM05-6.5(5.3/2)).
11965 return Type_Access_Level (Etype (Scop));
11970 Btyp := Root_Type (Btyp);
11972 -- The accessibility level of anonymous access types associated with
11973 -- discriminants is that of the current instance of the type, and
11974 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
11976 -- AI-402: access discriminants have accessibility based on the
11977 -- object rather than the type in Ada 2005, so the above paragraph
11980 -- ??? Needs completion with rules from AI-416
11982 if Ada_Version <= Ada_95
11983 and then Ekind (Typ) = E_Anonymous_Access_Type
11984 and then Present (Associated_Node_For_Itype (Typ))
11985 and then Nkind (Associated_Node_For_Itype (Typ)) =
11986 N_Discriminant_Specification
11988 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
11992 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
11993 end Type_Access_Level;
11995 --------------------------
11996 -- Unit_Declaration_Node --
11997 --------------------------
11999 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
12000 N : Node_Id := Parent (Unit_Id);
12003 -- Predefined operators do not have a full function declaration
12005 if Ekind (Unit_Id) = E_Operator then
12009 -- Isn't there some better way to express the following ???
12011 while Nkind (N) /= N_Abstract_Subprogram_Declaration
12012 and then Nkind (N) /= N_Formal_Package_Declaration
12013 and then Nkind (N) /= N_Function_Instantiation
12014 and then Nkind (N) /= N_Generic_Package_Declaration
12015 and then Nkind (N) /= N_Generic_Subprogram_Declaration
12016 and then Nkind (N) /= N_Package_Declaration
12017 and then Nkind (N) /= N_Package_Body
12018 and then Nkind (N) /= N_Package_Instantiation
12019 and then Nkind (N) /= N_Package_Renaming_Declaration
12020 and then Nkind (N) /= N_Procedure_Instantiation
12021 and then Nkind (N) /= N_Protected_Body
12022 and then Nkind (N) /= N_Subprogram_Declaration
12023 and then Nkind (N) /= N_Subprogram_Body
12024 and then Nkind (N) /= N_Subprogram_Body_Stub
12025 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
12026 and then Nkind (N) /= N_Task_Body
12027 and then Nkind (N) /= N_Task_Type_Declaration
12028 and then Nkind (N) not in N_Formal_Subprogram_Declaration
12029 and then Nkind (N) not in N_Generic_Renaming_Declaration
12032 pragma Assert (Present (N));
12036 end Unit_Declaration_Node;
12038 ---------------------
12039 -- Unit_Is_Visible --
12040 ---------------------
12042 function Unit_Is_Visible (U : Entity_Id) return Boolean is
12043 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
12044 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
12046 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
12047 -- For a child unit, check whether unit appears in a with_clause
12050 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
12051 -- Scan the context clause of one compilation unit looking for a
12052 -- with_clause for the unit in question.
12054 ----------------------------
12055 -- Unit_In_Parent_Context --
12056 ----------------------------
12058 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
12060 if Unit_In_Context (Par_Unit) then
12063 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
12064 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
12069 end Unit_In_Parent_Context;
12071 ---------------------
12072 -- Unit_In_Context --
12073 ---------------------
12075 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
12079 Clause := First (Context_Items (Comp_Unit));
12080 while Present (Clause) loop
12081 if Nkind (Clause) = N_With_Clause then
12082 if Library_Unit (Clause) = U then
12085 -- The with_clause may denote a renaming of the unit we are
12086 -- looking for, eg. Text_IO which renames Ada.Text_IO.
12089 Renamed_Entity (Entity (Name (Clause))) =
12090 Defining_Entity (Unit (U))
12100 end Unit_In_Context;
12102 -- Start of processing for Unit_Is_Visible
12105 -- The currrent unit is directly visible.
12110 elsif Unit_In_Context (Curr) then
12113 -- If the current unit is a body, check the context of the spec.
12115 elsif Nkind (Unit (Curr)) = N_Package_Body
12117 (Nkind (Unit (Curr)) = N_Subprogram_Body
12118 and then not Acts_As_Spec (Unit (Curr)))
12120 if Unit_In_Context (Library_Unit (Curr)) then
12125 -- If the spec is a child unit, examine the parents.
12127 if Is_Child_Unit (Curr_Entity) then
12128 if Nkind (Unit (Curr)) in N_Unit_Body then
12130 Unit_In_Parent_Context
12131 (Parent_Spec (Unit (Library_Unit (Curr))));
12133 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
12139 end Unit_Is_Visible;
12141 ------------------------------
12142 -- Universal_Interpretation --
12143 ------------------------------
12145 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
12146 Index : Interp_Index;
12150 -- The argument may be a formal parameter of an operator or subprogram
12151 -- with multiple interpretations, or else an expression for an actual.
12153 if Nkind (Opnd) = N_Defining_Identifier
12154 or else not Is_Overloaded (Opnd)
12156 if Etype (Opnd) = Universal_Integer
12157 or else Etype (Opnd) = Universal_Real
12159 return Etype (Opnd);
12165 Get_First_Interp (Opnd, Index, It);
12166 while Present (It.Typ) loop
12167 if It.Typ = Universal_Integer
12168 or else It.Typ = Universal_Real
12173 Get_Next_Interp (Index, It);
12178 end Universal_Interpretation;
12184 function Unqualify (Expr : Node_Id) return Node_Id is
12186 -- Recurse to handle unlikely case of multiple levels of qualification
12188 if Nkind (Expr) = N_Qualified_Expression then
12189 return Unqualify (Expression (Expr));
12191 -- Normal case, not a qualified expression
12198 -----------------------
12199 -- Visible_Ancestors --
12200 -----------------------
12202 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
12208 pragma Assert (Is_Record_Type (Typ)
12209 and then Is_Tagged_Type (Typ));
12211 -- Collect all the parents and progenitors of Typ. If the full-view of
12212 -- private parents and progenitors is available then it is used to
12213 -- generate the list of visible ancestors; otherwise their partial
12214 -- view is added to the resulting list.
12219 Use_Full_View => True);
12223 Ifaces_List => List_2,
12224 Exclude_Parents => True,
12225 Use_Full_View => True);
12227 -- Join the two lists. Avoid duplications because an interface may
12228 -- simultaneously be parent and progenitor of a type.
12230 Elmt := First_Elmt (List_2);
12231 while Present (Elmt) loop
12232 Append_Unique_Elmt (Node (Elmt), List_1);
12237 end Visible_Ancestors;
12239 ----------------------
12240 -- Within_Init_Proc --
12241 ----------------------
12243 function Within_Init_Proc return Boolean is
12247 S := Current_Scope;
12248 while not Is_Overloadable (S) loop
12249 if S = Standard_Standard then
12256 return Is_Init_Proc (S);
12257 end Within_Init_Proc;
12263 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
12264 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
12265 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
12267 function Has_One_Matching_Field return Boolean;
12268 -- Determines if Expec_Type is a record type with a single component or
12269 -- discriminant whose type matches the found type or is one dimensional
12270 -- array whose component type matches the found type.
12272 ----------------------------
12273 -- Has_One_Matching_Field --
12274 ----------------------------
12276 function Has_One_Matching_Field return Boolean is
12280 if Is_Array_Type (Expec_Type)
12281 and then Number_Dimensions (Expec_Type) = 1
12283 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
12287 elsif not Is_Record_Type (Expec_Type) then
12291 E := First_Entity (Expec_Type);
12296 elsif (Ekind (E) /= E_Discriminant
12297 and then Ekind (E) /= E_Component)
12298 or else (Chars (E) = Name_uTag
12299 or else Chars (E) = Name_uParent)
12308 if not Covers (Etype (E), Found_Type) then
12311 elsif Present (Next_Entity (E)) then
12318 end Has_One_Matching_Field;
12320 -- Start of processing for Wrong_Type
12323 -- Don't output message if either type is Any_Type, or if a message
12324 -- has already been posted for this node. We need to do the latter
12325 -- check explicitly (it is ordinarily done in Errout), because we
12326 -- are using ! to force the output of the error messages.
12328 if Expec_Type = Any_Type
12329 or else Found_Type = Any_Type
12330 or else Error_Posted (Expr)
12334 -- In an instance, there is an ongoing problem with completion of
12335 -- type derived from private types. Their structure is what Gigi
12336 -- expects, but the Etype is the parent type rather than the
12337 -- derived private type itself. Do not flag error in this case. The
12338 -- private completion is an entity without a parent, like an Itype.
12339 -- Similarly, full and partial views may be incorrect in the instance.
12340 -- There is no simple way to insure that it is consistent ???
12342 elsif In_Instance then
12343 if Etype (Etype (Expr)) = Etype (Expected_Type)
12345 (Has_Private_Declaration (Expected_Type)
12346 or else Has_Private_Declaration (Etype (Expr)))
12347 and then No (Parent (Expected_Type))
12353 -- An interesting special check. If the expression is parenthesized
12354 -- and its type corresponds to the type of the sole component of the
12355 -- expected record type, or to the component type of the expected one
12356 -- dimensional array type, then assume we have a bad aggregate attempt.
12358 if Nkind (Expr) in N_Subexpr
12359 and then Paren_Count (Expr) /= 0
12360 and then Has_One_Matching_Field
12362 Error_Msg_N ("positional aggregate cannot have one component", Expr);
12364 -- Another special check, if we are looking for a pool-specific access
12365 -- type and we found an E_Access_Attribute_Type, then we have the case
12366 -- of an Access attribute being used in a context which needs a pool-
12367 -- specific type, which is never allowed. The one extra check we make
12368 -- is that the expected designated type covers the Found_Type.
12370 elsif Is_Access_Type (Expec_Type)
12371 and then Ekind (Found_Type) = E_Access_Attribute_Type
12372 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
12373 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
12375 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
12377 Error_Msg_N -- CODEFIX
12378 ("result must be general access type!", Expr);
12379 Error_Msg_NE -- CODEFIX
12380 ("add ALL to }!", Expr, Expec_Type);
12382 -- Another special check, if the expected type is an integer type,
12383 -- but the expression is of type System.Address, and the parent is
12384 -- an addition or subtraction operation whose left operand is the
12385 -- expression in question and whose right operand is of an integral
12386 -- type, then this is an attempt at address arithmetic, so give
12387 -- appropriate message.
12389 elsif Is_Integer_Type (Expec_Type)
12390 and then Is_RTE (Found_Type, RE_Address)
12391 and then (Nkind (Parent (Expr)) = N_Op_Add
12393 Nkind (Parent (Expr)) = N_Op_Subtract)
12394 and then Expr = Left_Opnd (Parent (Expr))
12395 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
12398 ("address arithmetic not predefined in package System",
12401 ("\possible missing with/use of System.Storage_Elements",
12405 -- If the expected type is an anonymous access type, as for access
12406 -- parameters and discriminants, the error is on the designated types.
12408 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
12409 if Comes_From_Source (Expec_Type) then
12410 Error_Msg_NE ("expected}!", Expr, Expec_Type);
12413 ("expected an access type with designated}",
12414 Expr, Designated_Type (Expec_Type));
12417 if Is_Access_Type (Found_Type)
12418 and then not Comes_From_Source (Found_Type)
12421 ("\\found an access type with designated}!",
12422 Expr, Designated_Type (Found_Type));
12424 if From_With_Type (Found_Type) then
12425 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
12426 Error_Msg_Qual_Level := 99;
12427 Error_Msg_NE -- CODEFIX
12428 ("\\missing `WITH &;", Expr, Scope (Found_Type));
12429 Error_Msg_Qual_Level := 0;
12431 Error_Msg_NE ("found}!", Expr, Found_Type);
12435 -- Normal case of one type found, some other type expected
12438 -- If the names of the two types are the same, see if some number
12439 -- of levels of qualification will help. Don't try more than three
12440 -- levels, and if we get to standard, it's no use (and probably
12441 -- represents an error in the compiler) Also do not bother with
12442 -- internal scope names.
12445 Expec_Scope : Entity_Id;
12446 Found_Scope : Entity_Id;
12449 Expec_Scope := Expec_Type;
12450 Found_Scope := Found_Type;
12452 for Levels in Int range 0 .. 3 loop
12453 if Chars (Expec_Scope) /= Chars (Found_Scope) then
12454 Error_Msg_Qual_Level := Levels;
12458 Expec_Scope := Scope (Expec_Scope);
12459 Found_Scope := Scope (Found_Scope);
12461 exit when Expec_Scope = Standard_Standard
12462 or else Found_Scope = Standard_Standard
12463 or else not Comes_From_Source (Expec_Scope)
12464 or else not Comes_From_Source (Found_Scope);
12468 if Is_Record_Type (Expec_Type)
12469 and then Present (Corresponding_Remote_Type (Expec_Type))
12471 Error_Msg_NE ("expected}!", Expr,
12472 Corresponding_Remote_Type (Expec_Type));
12474 Error_Msg_NE ("expected}!", Expr, Expec_Type);
12477 if Is_Entity_Name (Expr)
12478 and then Is_Package_Or_Generic_Package (Entity (Expr))
12480 Error_Msg_N ("\\found package name!", Expr);
12482 elsif Is_Entity_Name (Expr)
12484 (Ekind (Entity (Expr)) = E_Procedure
12486 Ekind (Entity (Expr)) = E_Generic_Procedure)
12488 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
12490 ("found procedure name, possibly missing Access attribute!",
12494 ("\\found procedure name instead of function!", Expr);
12497 elsif Nkind (Expr) = N_Function_Call
12498 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
12499 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
12500 and then No (Parameter_Associations (Expr))
12503 ("found function name, possibly missing Access attribute!",
12506 -- Catch common error: a prefix or infix operator which is not
12507 -- directly visible because the type isn't.
12509 elsif Nkind (Expr) in N_Op
12510 and then Is_Overloaded (Expr)
12511 and then not Is_Immediately_Visible (Expec_Type)
12512 and then not Is_Potentially_Use_Visible (Expec_Type)
12513 and then not In_Use (Expec_Type)
12514 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
12517 ("operator of the type is not directly visible!", Expr);
12519 elsif Ekind (Found_Type) = E_Void
12520 and then Present (Parent (Found_Type))
12521 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
12523 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
12526 Error_Msg_NE ("\\found}!", Expr, Found_Type);
12529 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
12530 -- of the same modular type, and (M1 and M2) = 0 was intended.
12532 if Expec_Type = Standard_Boolean
12533 and then Is_Modular_Integer_Type (Found_Type)
12534 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
12535 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
12538 Op : constant Node_Id := Right_Opnd (Parent (Expr));
12539 L : constant Node_Id := Left_Opnd (Op);
12540 R : constant Node_Id := Right_Opnd (Op);
12542 -- The case for the message is when the left operand of the
12543 -- comparison is the same modular type, or when it is an
12544 -- integer literal (or other universal integer expression),
12545 -- which would have been typed as the modular type if the
12546 -- parens had been there.
12548 if (Etype (L) = Found_Type
12550 Etype (L) = Universal_Integer)
12551 and then Is_Integer_Type (Etype (R))
12554 ("\\possible missing parens for modular operation", Expr);
12559 -- Reset error message qualification indication
12561 Error_Msg_Qual_Level := 0;