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;
6548 function Is_False (U : Uint) return Boolean is
6553 ---------------------------
6554 -- Is_Fixed_Model_Number --
6555 ---------------------------
6557 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
6558 S : constant Ureal := Small_Value (T);
6559 M : Urealp.Save_Mark;
6563 R := (U = UR_Trunc (U / S) * S);
6566 end Is_Fixed_Model_Number;
6568 -------------------------------
6569 -- Is_Fully_Initialized_Type --
6570 -------------------------------
6572 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
6574 if Is_Scalar_Type (Typ) then
6577 elsif Is_Access_Type (Typ) then
6580 elsif Is_Array_Type (Typ) then
6581 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
6585 -- An interesting case, if we have a constrained type one of whose
6586 -- bounds is known to be null, then there are no elements to be
6587 -- initialized, so all the elements are initialized!
6589 if Is_Constrained (Typ) then
6592 Indx_Typ : Entity_Id;
6596 Indx := First_Index (Typ);
6597 while Present (Indx) loop
6598 if Etype (Indx) = Any_Type then
6601 -- If index is a range, use directly
6603 elsif Nkind (Indx) = N_Range then
6604 Lbd := Low_Bound (Indx);
6605 Hbd := High_Bound (Indx);
6608 Indx_Typ := Etype (Indx);
6610 if Is_Private_Type (Indx_Typ) then
6611 Indx_Typ := Full_View (Indx_Typ);
6614 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
6617 Lbd := Type_Low_Bound (Indx_Typ);
6618 Hbd := Type_High_Bound (Indx_Typ);
6622 if Compile_Time_Known_Value (Lbd)
6623 and then Compile_Time_Known_Value (Hbd)
6625 if Expr_Value (Hbd) < Expr_Value (Lbd) then
6635 -- If no null indexes, then type is not fully initialized
6641 elsif Is_Record_Type (Typ) then
6642 if Has_Discriminants (Typ)
6644 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
6645 and then Is_Fully_Initialized_Variant (Typ)
6650 -- Controlled records are considered to be fully initialized if
6651 -- there is a user defined Initialize routine. This may not be
6652 -- entirely correct, but as the spec notes, we are guessing here
6653 -- what is best from the point of view of issuing warnings.
6655 if Is_Controlled (Typ) then
6657 Utyp : constant Entity_Id := Underlying_Type (Typ);
6660 if Present (Utyp) then
6662 Init : constant Entity_Id :=
6664 (Underlying_Type (Typ), Name_Initialize));
6668 and then Comes_From_Source (Init)
6670 Is_Predefined_File_Name
6671 (File_Name (Get_Source_File_Index (Sloc (Init))))
6675 elsif Has_Null_Extension (Typ)
6677 Is_Fully_Initialized_Type
6678 (Etype (Base_Type (Typ)))
6687 -- Otherwise see if all record components are initialized
6693 Ent := First_Entity (Typ);
6694 while Present (Ent) loop
6695 if Chars (Ent) = Name_uController then
6698 elsif Ekind (Ent) = E_Component
6699 and then (No (Parent (Ent))
6700 or else No (Expression (Parent (Ent))))
6701 and then not Is_Fully_Initialized_Type (Etype (Ent))
6703 -- Special VM case for tag components, which need to be
6704 -- defined in this case, but are never initialized as VMs
6705 -- are using other dispatching mechanisms. Ignore this
6706 -- uninitialized case. Note that this applies both to the
6707 -- uTag entry and the main vtable pointer (CPP_Class case).
6709 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
6718 -- No uninitialized components, so type is fully initialized.
6719 -- Note that this catches the case of no components as well.
6723 elsif Is_Concurrent_Type (Typ) then
6726 elsif Is_Private_Type (Typ) then
6728 U : constant Entity_Id := Underlying_Type (Typ);
6734 return Is_Fully_Initialized_Type (U);
6741 end Is_Fully_Initialized_Type;
6743 ----------------------------------
6744 -- Is_Fully_Initialized_Variant --
6745 ----------------------------------
6747 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
6748 Loc : constant Source_Ptr := Sloc (Typ);
6749 Constraints : constant List_Id := New_List;
6750 Components : constant Elist_Id := New_Elmt_List;
6751 Comp_Elmt : Elmt_Id;
6753 Comp_List : Node_Id;
6755 Discr_Val : Node_Id;
6757 Report_Errors : Boolean;
6758 pragma Warnings (Off, Report_Errors);
6761 if Serious_Errors_Detected > 0 then
6765 if Is_Record_Type (Typ)
6766 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
6767 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
6769 Comp_List := Component_List (Type_Definition (Parent (Typ)));
6771 Discr := First_Discriminant (Typ);
6772 while Present (Discr) loop
6773 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
6774 Discr_Val := Expression (Parent (Discr));
6776 if Present (Discr_Val)
6777 and then Is_OK_Static_Expression (Discr_Val)
6779 Append_To (Constraints,
6780 Make_Component_Association (Loc,
6781 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
6782 Expression => New_Copy (Discr_Val)));
6790 Next_Discriminant (Discr);
6795 Comp_List => Comp_List,
6796 Governed_By => Constraints,
6798 Report_Errors => Report_Errors);
6800 -- Check that each component present is fully initialized
6802 Comp_Elmt := First_Elmt (Components);
6803 while Present (Comp_Elmt) loop
6804 Comp_Id := Node (Comp_Elmt);
6806 if Ekind (Comp_Id) = E_Component
6807 and then (No (Parent (Comp_Id))
6808 or else No (Expression (Parent (Comp_Id))))
6809 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
6814 Next_Elmt (Comp_Elmt);
6819 elsif Is_Private_Type (Typ) then
6821 U : constant Entity_Id := Underlying_Type (Typ);
6827 return Is_Fully_Initialized_Variant (U);
6833 end Is_Fully_Initialized_Variant;
6839 -- We seem to have a lot of overlapping functions that do similar things
6840 -- (testing for left hand sides or lvalues???). Anyway, since this one is
6841 -- purely syntactic, it should be in Sem_Aux I would think???
6843 function Is_LHS (N : Node_Id) return Boolean is
6844 P : constant Node_Id := Parent (N);
6847 if Nkind (P) = N_Assignment_Statement then
6848 return Name (P) = N;
6851 Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
6853 return N = Prefix (P) and then Is_LHS (P);
6860 ----------------------------
6861 -- Is_Inherited_Operation --
6862 ----------------------------
6864 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
6865 Kind : constant Node_Kind := Nkind (Parent (E));
6867 pragma Assert (Is_Overloadable (E));
6868 return Kind = N_Full_Type_Declaration
6869 or else Kind = N_Private_Extension_Declaration
6870 or else Kind = N_Subtype_Declaration
6871 or else (Ekind (E) = E_Enumeration_Literal
6872 and then Is_Derived_Type (Etype (E)));
6873 end Is_Inherited_Operation;
6875 -------------------------------------
6876 -- Is_Inherited_Operation_For_Type --
6877 -------------------------------------
6879 function Is_Inherited_Operation_For_Type
6880 (E : Entity_Id; Typ : Entity_Id) return Boolean
6883 return Is_Inherited_Operation (E)
6884 and then Etype (Parent (E)) = Typ;
6885 end Is_Inherited_Operation_For_Type;
6887 -----------------------------
6888 -- Is_Library_Level_Entity --
6889 -----------------------------
6891 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
6893 -- The following is a small optimization, and it also properly handles
6894 -- discriminals, which in task bodies might appear in expressions before
6895 -- the corresponding procedure has been created, and which therefore do
6896 -- not have an assigned scope.
6898 if Is_Formal (E) then
6902 -- Normal test is simply that the enclosing dynamic scope is Standard
6904 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
6905 end Is_Library_Level_Entity;
6907 ---------------------------------
6908 -- Is_Local_Variable_Reference --
6909 ---------------------------------
6911 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
6913 if not Is_Entity_Name (Expr) then
6918 Ent : constant Entity_Id := Entity (Expr);
6919 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
6921 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
6924 return Present (Sub) and then Sub = Current_Subprogram;
6928 end Is_Local_Variable_Reference;
6930 -------------------------
6931 -- Is_Object_Reference --
6932 -------------------------
6934 function Is_Object_Reference (N : Node_Id) return Boolean is
6936 if Is_Entity_Name (N) then
6937 return Present (Entity (N)) and then Is_Object (Entity (N));
6941 when N_Indexed_Component | N_Slice =>
6943 Is_Object_Reference (Prefix (N))
6944 or else Is_Access_Type (Etype (Prefix (N)));
6946 -- In Ada95, a function call is a constant object; a procedure
6949 when N_Function_Call =>
6950 return Etype (N) /= Standard_Void_Type;
6952 -- A reference to the stream attribute Input is a function call
6954 when N_Attribute_Reference =>
6955 return Attribute_Name (N) = Name_Input;
6957 when N_Selected_Component =>
6959 Is_Object_Reference (Selector_Name (N))
6961 (Is_Object_Reference (Prefix (N))
6962 or else Is_Access_Type (Etype (Prefix (N))));
6964 when N_Explicit_Dereference =>
6967 -- A view conversion of a tagged object is an object reference
6969 when N_Type_Conversion =>
6970 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
6971 and then Is_Tagged_Type (Etype (Expression (N)))
6972 and then Is_Object_Reference (Expression (N));
6974 -- An unchecked type conversion is considered to be an object if
6975 -- the operand is an object (this construction arises only as a
6976 -- result of expansion activities).
6978 when N_Unchecked_Type_Conversion =>
6985 end Is_Object_Reference;
6987 -----------------------------------
6988 -- Is_OK_Variable_For_Out_Formal --
6989 -----------------------------------
6991 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
6993 Note_Possible_Modification (AV, Sure => True);
6995 -- We must reject parenthesized variable names. The check for
6996 -- Comes_From_Source is present because there are currently
6997 -- cases where the compiler violates this rule (e.g. passing
6998 -- a task object to its controlled Initialize routine).
7000 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
7003 -- A variable is always allowed
7005 elsif Is_Variable (AV) then
7008 -- Unchecked conversions are allowed only if they come from the
7009 -- generated code, which sometimes uses unchecked conversions for out
7010 -- parameters in cases where code generation is unaffected. We tell
7011 -- source unchecked conversions by seeing if they are rewrites of an
7012 -- original Unchecked_Conversion function call, or of an explicit
7013 -- conversion of a function call.
7015 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
7016 if Nkind (Original_Node (AV)) = N_Function_Call then
7019 elsif Comes_From_Source (AV)
7020 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
7024 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
7025 return Is_OK_Variable_For_Out_Formal (Expression (AV));
7031 -- Normal type conversions are allowed if argument is a variable
7033 elsif Nkind (AV) = N_Type_Conversion then
7034 if Is_Variable (Expression (AV))
7035 and then Paren_Count (Expression (AV)) = 0
7037 Note_Possible_Modification (Expression (AV), Sure => True);
7040 -- We also allow a non-parenthesized expression that raises
7041 -- constraint error if it rewrites what used to be a variable
7043 elsif Raises_Constraint_Error (Expression (AV))
7044 and then Paren_Count (Expression (AV)) = 0
7045 and then Is_Variable (Original_Node (Expression (AV)))
7049 -- Type conversion of something other than a variable
7055 -- If this node is rewritten, then test the original form, if that is
7056 -- OK, then we consider the rewritten node OK (for example, if the
7057 -- original node is a conversion, then Is_Variable will not be true
7058 -- but we still want to allow the conversion if it converts a variable).
7060 elsif Original_Node (AV) /= AV then
7061 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
7063 -- All other non-variables are rejected
7068 end Is_OK_Variable_For_Out_Formal;
7070 -----------------------------------
7071 -- Is_Partially_Initialized_Type --
7072 -----------------------------------
7074 function Is_Partially_Initialized_Type
7076 Include_Implicit : Boolean := True) return Boolean
7079 if Is_Scalar_Type (Typ) then
7082 elsif Is_Access_Type (Typ) then
7083 return Include_Implicit;
7085 elsif Is_Array_Type (Typ) then
7087 -- If component type is partially initialized, so is array type
7089 if Is_Partially_Initialized_Type
7090 (Component_Type (Typ), Include_Implicit)
7094 -- Otherwise we are only partially initialized if we are fully
7095 -- initialized (this is the empty array case, no point in us
7096 -- duplicating that code here).
7099 return Is_Fully_Initialized_Type (Typ);
7102 elsif Is_Record_Type (Typ) then
7104 -- A discriminated type is always partially initialized if in
7107 if Has_Discriminants (Typ) and then Include_Implicit then
7110 -- A tagged type is always partially initialized
7112 elsif Is_Tagged_Type (Typ) then
7115 -- Case of non-discriminated record
7121 Component_Present : Boolean := False;
7122 -- Set True if at least one component is present. If no
7123 -- components are present, then record type is fully
7124 -- initialized (another odd case, like the null array).
7127 -- Loop through components
7129 Ent := First_Entity (Typ);
7130 while Present (Ent) loop
7131 if Ekind (Ent) = E_Component then
7132 Component_Present := True;
7134 -- If a component has an initialization expression then
7135 -- the enclosing record type is partially initialized
7137 if Present (Parent (Ent))
7138 and then Present (Expression (Parent (Ent)))
7142 -- If a component is of a type which is itself partially
7143 -- initialized, then the enclosing record type is also.
7145 elsif Is_Partially_Initialized_Type
7146 (Etype (Ent), Include_Implicit)
7155 -- No initialized components found. If we found any components
7156 -- they were all uninitialized so the result is false.
7158 if Component_Present then
7161 -- But if we found no components, then all the components are
7162 -- initialized so we consider the type to be initialized.
7170 -- Concurrent types are always fully initialized
7172 elsif Is_Concurrent_Type (Typ) then
7175 -- For a private type, go to underlying type. If there is no underlying
7176 -- type then just assume this partially initialized. Not clear if this
7177 -- can happen in a non-error case, but no harm in testing for this.
7179 elsif Is_Private_Type (Typ) then
7181 U : constant Entity_Id := Underlying_Type (Typ);
7186 return Is_Partially_Initialized_Type (U, Include_Implicit);
7190 -- For any other type (are there any?) assume partially initialized
7195 end Is_Partially_Initialized_Type;
7197 ------------------------------------
7198 -- Is_Potentially_Persistent_Type --
7199 ------------------------------------
7201 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
7206 -- For private type, test corresponding full type
7208 if Is_Private_Type (T) then
7209 return Is_Potentially_Persistent_Type (Full_View (T));
7211 -- Scalar types are potentially persistent
7213 elsif Is_Scalar_Type (T) then
7216 -- Record type is potentially persistent if not tagged and the types of
7217 -- all it components are potentially persistent, and no component has
7218 -- an initialization expression.
7220 elsif Is_Record_Type (T)
7221 and then not Is_Tagged_Type (T)
7222 and then not Is_Partially_Initialized_Type (T)
7224 Comp := First_Component (T);
7225 while Present (Comp) loop
7226 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
7235 -- Array type is potentially persistent if its component type is
7236 -- potentially persistent and if all its constraints are static.
7238 elsif Is_Array_Type (T) then
7239 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
7243 Indx := First_Index (T);
7244 while Present (Indx) loop
7245 if not Is_OK_Static_Subtype (Etype (Indx)) then
7254 -- All other types are not potentially persistent
7259 end Is_Potentially_Persistent_Type;
7261 ---------------------------------
7262 -- Is_Protected_Self_Reference --
7263 ---------------------------------
7265 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
7267 function In_Access_Definition (N : Node_Id) return Boolean;
7268 -- Returns true if N belongs to an access definition
7270 --------------------------
7271 -- In_Access_Definition --
7272 --------------------------
7274 function In_Access_Definition (N : Node_Id) return Boolean is
7279 while Present (P) loop
7280 if Nkind (P) = N_Access_Definition then
7288 end In_Access_Definition;
7290 -- Start of processing for Is_Protected_Self_Reference
7293 -- Verify that prefix is analyzed and has the proper form. Note that
7294 -- the attributes Elab_Spec, Elab_Body, and UET_Address, which also
7295 -- produce the address of an entity, do not analyze their prefix
7296 -- because they denote entities that are not necessarily visible.
7297 -- Neither of them can apply to a protected type.
7299 return Ada_Version >= Ada_2005
7300 and then Is_Entity_Name (N)
7301 and then Present (Entity (N))
7302 and then Is_Protected_Type (Entity (N))
7303 and then In_Open_Scopes (Entity (N))
7304 and then not In_Access_Definition (N);
7305 end Is_Protected_Self_Reference;
7307 -----------------------------
7308 -- Is_RCI_Pkg_Spec_Or_Body --
7309 -----------------------------
7311 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
7313 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
7314 -- Return True if the unit of Cunit is an RCI package declaration
7316 ---------------------------
7317 -- Is_RCI_Pkg_Decl_Cunit --
7318 ---------------------------
7320 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
7321 The_Unit : constant Node_Id := Unit (Cunit);
7324 if Nkind (The_Unit) /= N_Package_Declaration then
7328 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
7329 end Is_RCI_Pkg_Decl_Cunit;
7331 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
7334 return Is_RCI_Pkg_Decl_Cunit (Cunit)
7336 (Nkind (Unit (Cunit)) = N_Package_Body
7337 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
7338 end Is_RCI_Pkg_Spec_Or_Body;
7340 -----------------------------------------
7341 -- Is_Remote_Access_To_Class_Wide_Type --
7342 -----------------------------------------
7344 function Is_Remote_Access_To_Class_Wide_Type
7345 (E : Entity_Id) return Boolean
7348 -- A remote access to class-wide type is a general access to object type
7349 -- declared in the visible part of a Remote_Types or Remote_Call_
7352 return Ekind (E) = E_General_Access_Type
7353 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
7354 end Is_Remote_Access_To_Class_Wide_Type;
7356 -----------------------------------------
7357 -- Is_Remote_Access_To_Subprogram_Type --
7358 -----------------------------------------
7360 function Is_Remote_Access_To_Subprogram_Type
7361 (E : Entity_Id) return Boolean
7364 return (Ekind (E) = E_Access_Subprogram_Type
7365 or else (Ekind (E) = E_Record_Type
7366 and then Present (Corresponding_Remote_Type (E))))
7367 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
7368 end Is_Remote_Access_To_Subprogram_Type;
7370 --------------------
7371 -- Is_Remote_Call --
7372 --------------------
7374 function Is_Remote_Call (N : Node_Id) return Boolean is
7376 if Nkind (N) /= N_Procedure_Call_Statement
7377 and then Nkind (N) /= N_Function_Call
7379 -- An entry call cannot be remote
7383 elsif Nkind (Name (N)) in N_Has_Entity
7384 and then Is_Remote_Call_Interface (Entity (Name (N)))
7386 -- A subprogram declared in the spec of a RCI package is remote
7390 elsif Nkind (Name (N)) = N_Explicit_Dereference
7391 and then Is_Remote_Access_To_Subprogram_Type
7392 (Etype (Prefix (Name (N))))
7394 -- The dereference of a RAS is a remote call
7398 elsif Present (Controlling_Argument (N))
7399 and then Is_Remote_Access_To_Class_Wide_Type
7400 (Etype (Controlling_Argument (N)))
7402 -- Any primitive operation call with a controlling argument of
7403 -- a RACW type is a remote call.
7408 -- All other calls are local calls
7413 ----------------------
7414 -- Is_Renamed_Entry --
7415 ----------------------
7417 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
7418 Orig_Node : Node_Id := Empty;
7419 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
7421 function Is_Entry (Nam : Node_Id) return Boolean;
7422 -- Determine whether Nam is an entry. Traverse selectors if there are
7423 -- nested selected components.
7429 function Is_Entry (Nam : Node_Id) return Boolean is
7431 if Nkind (Nam) = N_Selected_Component then
7432 return Is_Entry (Selector_Name (Nam));
7435 return Ekind (Entity (Nam)) = E_Entry;
7438 -- Start of processing for Is_Renamed_Entry
7441 if Present (Alias (Proc_Nam)) then
7442 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
7445 -- Look for a rewritten subprogram renaming declaration
7447 if Nkind (Subp_Decl) = N_Subprogram_Declaration
7448 and then Present (Original_Node (Subp_Decl))
7450 Orig_Node := Original_Node (Subp_Decl);
7453 -- The rewritten subprogram is actually an entry
7455 if Present (Orig_Node)
7456 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
7457 and then Is_Entry (Name (Orig_Node))
7463 end Is_Renamed_Entry;
7465 ----------------------
7466 -- Is_Selector_Name --
7467 ----------------------
7469 function Is_Selector_Name (N : Node_Id) return Boolean is
7471 if not Is_List_Member (N) then
7473 P : constant Node_Id := Parent (N);
7474 K : constant Node_Kind := Nkind (P);
7477 (K = N_Expanded_Name or else
7478 K = N_Generic_Association or else
7479 K = N_Parameter_Association or else
7480 K = N_Selected_Component)
7481 and then Selector_Name (P) = N;
7486 L : constant List_Id := List_Containing (N);
7487 P : constant Node_Id := Parent (L);
7489 return (Nkind (P) = N_Discriminant_Association
7490 and then Selector_Names (P) = L)
7492 (Nkind (P) = N_Component_Association
7493 and then Choices (P) = L);
7496 end Is_Selector_Name;
7498 ----------------------------------
7499 -- Is_SPARK_Initialization_Expr --
7500 ----------------------------------
7502 function Is_SPARK_Initialization_Expr (N : Node_Id) return Boolean is
7505 Comp_Assn : Node_Id;
7506 Orig_N : constant Node_Id := Original_Node (N);
7511 if not Comes_From_Source (Orig_N) then
7515 pragma Assert (Nkind (Orig_N) in N_Subexpr);
7517 case Nkind (Orig_N) is
7518 when N_Character_Literal |
7526 if Is_Entity_Name (Orig_N)
7527 and then Present (Entity (Orig_N)) -- needed in some cases
7529 case Ekind (Entity (Orig_N)) is
7531 E_Enumeration_Literal |
7536 if Is_Type (Entity (Orig_N)) then
7544 when N_Qualified_Expression |
7545 N_Type_Conversion =>
7546 Is_Ok := Is_SPARK_Initialization_Expr (Expression (Orig_N));
7549 Is_Ok := Is_SPARK_Initialization_Expr (Right_Opnd (Orig_N));
7553 N_Membership_Test =>
7554 Is_Ok := Is_SPARK_Initialization_Expr (Left_Opnd (Orig_N))
7555 and then Is_SPARK_Initialization_Expr (Right_Opnd (Orig_N));
7558 N_Extension_Aggregate =>
7559 if Nkind (Orig_N) = N_Extension_Aggregate then
7560 Is_Ok := Is_SPARK_Initialization_Expr (Ancestor_Part (Orig_N));
7563 Expr := First (Expressions (Orig_N));
7564 while Present (Expr) loop
7565 if not Is_SPARK_Initialization_Expr (Expr) then
7573 Comp_Assn := First (Component_Associations (Orig_N));
7574 while Present (Comp_Assn) loop
7575 Expr := Expression (Comp_Assn);
7576 if Present (Expr) -- needed for box association
7577 and then not Is_SPARK_Initialization_Expr (Expr)
7586 when N_Attribute_Reference =>
7587 if Nkind (Prefix (Orig_N)) in N_Subexpr then
7588 Is_Ok := Is_SPARK_Initialization_Expr (Prefix (Orig_N));
7591 Expr := First (Expressions (Orig_N));
7592 while Present (Expr) loop
7593 if not Is_SPARK_Initialization_Expr (Expr) then
7601 -- Selected components might be expanded named not yet resolved, so
7602 -- default on the safe side. (Eg on sparklex.ads)
7604 when N_Selected_Component =>
7613 end Is_SPARK_Initialization_Expr;
7615 -------------------------------
7616 -- Is_SPARK_Object_Reference --
7617 -------------------------------
7619 function Is_SPARK_Object_Reference (N : Node_Id) return Boolean is
7621 if Is_Entity_Name (N) then
7622 return Present (Entity (N))
7624 (Ekind_In (Entity (N), E_Constant, E_Variable)
7625 or else Ekind (Entity (N)) in Formal_Kind);
7629 when N_Selected_Component =>
7630 return Is_SPARK_Object_Reference (Prefix (N));
7636 end Is_SPARK_Object_Reference;
7642 function Is_Statement (N : Node_Id) return Boolean is
7645 Nkind (N) in N_Statement_Other_Than_Procedure_Call
7646 or else Nkind (N) = N_Procedure_Call_Statement;
7649 ---------------------------------
7650 -- Is_Synchronized_Tagged_Type --
7651 ---------------------------------
7653 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
7654 Kind : constant Entity_Kind := Ekind (Base_Type (E));
7657 -- A task or protected type derived from an interface is a tagged type.
7658 -- Such a tagged type is called a synchronized tagged type, as are
7659 -- synchronized interfaces and private extensions whose declaration
7660 -- includes the reserved word synchronized.
7662 return (Is_Tagged_Type (E)
7663 and then (Kind = E_Task_Type
7664 or else Kind = E_Protected_Type))
7667 and then Is_Synchronized_Interface (E))
7669 (Ekind (E) = E_Record_Type_With_Private
7670 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
7671 and then (Synchronized_Present (Parent (E))
7672 or else Is_Synchronized_Interface (Etype (E))));
7673 end Is_Synchronized_Tagged_Type;
7679 function Is_Transfer (N : Node_Id) return Boolean is
7680 Kind : constant Node_Kind := Nkind (N);
7683 if Kind = N_Simple_Return_Statement
7685 Kind = N_Extended_Return_Statement
7687 Kind = N_Goto_Statement
7689 Kind = N_Raise_Statement
7691 Kind = N_Requeue_Statement
7695 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
7696 and then No (Condition (N))
7700 elsif Kind = N_Procedure_Call_Statement
7701 and then Is_Entity_Name (Name (N))
7702 and then Present (Entity (Name (N)))
7703 and then No_Return (Entity (Name (N)))
7707 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
7719 function Is_True (U : Uint) return Boolean is
7724 -------------------------------
7725 -- Is_Universal_Numeric_Type --
7726 -------------------------------
7728 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
7730 return T = Universal_Integer or else T = Universal_Real;
7731 end Is_Universal_Numeric_Type;
7737 function Is_Value_Type (T : Entity_Id) return Boolean is
7739 return VM_Target = CLI_Target
7740 and then Nkind (T) in N_Has_Chars
7741 and then Chars (T) /= No_Name
7742 and then Get_Name_String (Chars (T)) = "valuetype";
7745 ---------------------
7746 -- Is_VMS_Operator --
7747 ---------------------
7749 function Is_VMS_Operator (Op : Entity_Id) return Boolean is
7751 -- The VMS operators are declared in a child of System that is loaded
7752 -- through pragma Extend_System. In some rare cases a program is run
7753 -- with this extension but without indicating that the target is VMS.
7755 return Ekind (Op) = E_Function
7756 and then Is_Intrinsic_Subprogram (Op)
7758 ((Present_System_Aux
7759 and then Scope (Op) = System_Aux_Id)
7762 and then Scope (Scope (Op)) = RTU_Entity (System)));
7763 end Is_VMS_Operator;
7769 function Is_Variable
7771 Use_Original_Node : Boolean := True) return Boolean
7773 Orig_Node : Node_Id;
7775 function In_Protected_Function (E : Entity_Id) return Boolean;
7776 -- Within a protected function, the private components of the enclosing
7777 -- protected type are constants. A function nested within a (protected)
7778 -- procedure is not itself protected.
7780 function Is_Variable_Prefix (P : Node_Id) return Boolean;
7781 -- Prefixes can involve implicit dereferences, in which case we must
7782 -- test for the case of a reference of a constant access type, which can
7783 -- can never be a variable.
7785 ---------------------------
7786 -- In_Protected_Function --
7787 ---------------------------
7789 function In_Protected_Function (E : Entity_Id) return Boolean is
7790 Prot : constant Entity_Id := Scope (E);
7794 if not Is_Protected_Type (Prot) then
7798 while Present (S) and then S /= Prot loop
7799 if Ekind (S) = E_Function and then Scope (S) = Prot then
7808 end In_Protected_Function;
7810 ------------------------
7811 -- Is_Variable_Prefix --
7812 ------------------------
7814 function Is_Variable_Prefix (P : Node_Id) return Boolean is
7816 if Is_Access_Type (Etype (P)) then
7817 return not Is_Access_Constant (Root_Type (Etype (P)));
7819 -- For the case of an indexed component whose prefix has a packed
7820 -- array type, the prefix has been rewritten into a type conversion.
7821 -- Determine variable-ness from the converted expression.
7823 elsif Nkind (P) = N_Type_Conversion
7824 and then not Comes_From_Source (P)
7825 and then Is_Array_Type (Etype (P))
7826 and then Is_Packed (Etype (P))
7828 return Is_Variable (Expression (P));
7831 return Is_Variable (P);
7833 end Is_Variable_Prefix;
7835 -- Start of processing for Is_Variable
7838 -- Check if we perform the test on the original node since this may be a
7839 -- test of syntactic categories which must not be disturbed by whatever
7840 -- rewriting might have occurred. For example, an aggregate, which is
7841 -- certainly NOT a variable, could be turned into a variable by
7844 if Use_Original_Node then
7845 Orig_Node := Original_Node (N);
7850 -- Definitely OK if Assignment_OK is set. Since this is something that
7851 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
7853 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
7856 -- Normally we go to the original node, but there is one exception where
7857 -- we use the rewritten node, namely when it is an explicit dereference.
7858 -- The generated code may rewrite a prefix which is an access type with
7859 -- an explicit dereference. The dereference is a variable, even though
7860 -- the original node may not be (since it could be a constant of the
7863 -- In Ada 2005 we have a further case to consider: the prefix may be a
7864 -- function call given in prefix notation. The original node appears to
7865 -- be a selected component, but we need to examine the call.
7867 elsif Nkind (N) = N_Explicit_Dereference
7868 and then Nkind (Orig_Node) /= N_Explicit_Dereference
7869 and then Present (Etype (Orig_Node))
7870 and then Is_Access_Type (Etype (Orig_Node))
7872 -- Note that if the prefix is an explicit dereference that does not
7873 -- come from source, we must check for a rewritten function call in
7874 -- prefixed notation before other forms of rewriting, to prevent a
7878 (Nkind (Orig_Node) = N_Function_Call
7879 and then not Is_Access_Constant (Etype (Prefix (N))))
7881 Is_Variable_Prefix (Original_Node (Prefix (N)));
7883 -- A function call is never a variable
7885 elsif Nkind (N) = N_Function_Call then
7888 -- All remaining checks use the original node
7890 elsif Is_Entity_Name (Orig_Node)
7891 and then Present (Entity (Orig_Node))
7894 E : constant Entity_Id := Entity (Orig_Node);
7895 K : constant Entity_Kind := Ekind (E);
7898 return (K = E_Variable
7899 and then Nkind (Parent (E)) /= N_Exception_Handler)
7900 or else (K = E_Component
7901 and then not In_Protected_Function (E))
7902 or else K = E_Out_Parameter
7903 or else K = E_In_Out_Parameter
7904 or else K = E_Generic_In_Out_Parameter
7906 -- Current instance of type:
7908 or else (Is_Type (E) and then In_Open_Scopes (E))
7909 or else (Is_Incomplete_Or_Private_Type (E)
7910 and then In_Open_Scopes (Full_View (E)));
7914 case Nkind (Orig_Node) is
7915 when N_Indexed_Component | N_Slice =>
7916 return Is_Variable_Prefix (Prefix (Orig_Node));
7918 when N_Selected_Component =>
7919 return Is_Variable_Prefix (Prefix (Orig_Node))
7920 and then Is_Variable (Selector_Name (Orig_Node));
7922 -- For an explicit dereference, the type of the prefix cannot
7923 -- be an access to constant or an access to subprogram.
7925 when N_Explicit_Dereference =>
7927 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
7929 return Is_Access_Type (Typ)
7930 and then not Is_Access_Constant (Root_Type (Typ))
7931 and then Ekind (Typ) /= E_Access_Subprogram_Type;
7934 -- The type conversion is the case where we do not deal with the
7935 -- context dependent special case of an actual parameter. Thus
7936 -- the type conversion is only considered a variable for the
7937 -- purposes of this routine if the target type is tagged. However,
7938 -- a type conversion is considered to be a variable if it does not
7939 -- come from source (this deals for example with the conversions
7940 -- of expressions to their actual subtypes).
7942 when N_Type_Conversion =>
7943 return Is_Variable (Expression (Orig_Node))
7945 (not Comes_From_Source (Orig_Node)
7947 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
7949 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
7951 -- GNAT allows an unchecked type conversion as a variable. This
7952 -- only affects the generation of internal expanded code, since
7953 -- calls to instantiations of Unchecked_Conversion are never
7954 -- considered variables (since they are function calls).
7955 -- This is also true for expression actions.
7957 when N_Unchecked_Type_Conversion =>
7958 return Is_Variable (Expression (Orig_Node));
7966 ---------------------------
7967 -- Is_Visibly_Controlled --
7968 ---------------------------
7970 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
7971 Root : constant Entity_Id := Root_Type (T);
7973 return Chars (Scope (Root)) = Name_Finalization
7974 and then Chars (Scope (Scope (Root))) = Name_Ada
7975 and then Scope (Scope (Scope (Root))) = Standard_Standard;
7976 end Is_Visibly_Controlled;
7978 ------------------------
7979 -- Is_Volatile_Object --
7980 ------------------------
7982 function Is_Volatile_Object (N : Node_Id) return Boolean is
7984 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
7985 -- Determines if given object has volatile components
7987 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
7988 -- If prefix is an implicit dereference, examine designated type
7990 ------------------------
7991 -- Is_Volatile_Prefix --
7992 ------------------------
7994 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
7995 Typ : constant Entity_Id := Etype (N);
7998 if Is_Access_Type (Typ) then
8000 Dtyp : constant Entity_Id := Designated_Type (Typ);
8003 return Is_Volatile (Dtyp)
8004 or else Has_Volatile_Components (Dtyp);
8008 return Object_Has_Volatile_Components (N);
8010 end Is_Volatile_Prefix;
8012 ------------------------------------
8013 -- Object_Has_Volatile_Components --
8014 ------------------------------------
8016 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
8017 Typ : constant Entity_Id := Etype (N);
8020 if Is_Volatile (Typ)
8021 or else Has_Volatile_Components (Typ)
8025 elsif Is_Entity_Name (N)
8026 and then (Has_Volatile_Components (Entity (N))
8027 or else Is_Volatile (Entity (N)))
8031 elsif Nkind (N) = N_Indexed_Component
8032 or else Nkind (N) = N_Selected_Component
8034 return Is_Volatile_Prefix (Prefix (N));
8039 end Object_Has_Volatile_Components;
8041 -- Start of processing for Is_Volatile_Object
8044 if Is_Volatile (Etype (N))
8045 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
8049 elsif Nkind (N) = N_Indexed_Component
8050 or else Nkind (N) = N_Selected_Component
8052 return Is_Volatile_Prefix (Prefix (N));
8057 end Is_Volatile_Object;
8059 -------------------------
8060 -- Kill_Current_Values --
8061 -------------------------
8063 procedure Kill_Current_Values
8065 Last_Assignment_Only : Boolean := False)
8068 -- ??? do we have to worry about clearing cached checks?
8070 if Is_Assignable (Ent) then
8071 Set_Last_Assignment (Ent, Empty);
8074 if Is_Object (Ent) then
8075 if not Last_Assignment_Only then
8077 Set_Current_Value (Ent, Empty);
8079 if not Can_Never_Be_Null (Ent) then
8080 Set_Is_Known_Non_Null (Ent, False);
8083 Set_Is_Known_Null (Ent, False);
8085 -- Reset Is_Known_Valid unless type is always valid, or if we have
8086 -- a loop parameter (loop parameters are always valid, since their
8087 -- bounds are defined by the bounds given in the loop header).
8089 if not Is_Known_Valid (Etype (Ent))
8090 and then Ekind (Ent) /= E_Loop_Parameter
8092 Set_Is_Known_Valid (Ent, False);
8096 end Kill_Current_Values;
8098 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
8101 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
8102 -- Clear current value for entity E and all entities chained to E
8104 ------------------------------------------
8105 -- Kill_Current_Values_For_Entity_Chain --
8106 ------------------------------------------
8108 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
8112 while Present (Ent) loop
8113 Kill_Current_Values (Ent, Last_Assignment_Only);
8116 end Kill_Current_Values_For_Entity_Chain;
8118 -- Start of processing for Kill_Current_Values
8121 -- Kill all saved checks, a special case of killing saved values
8123 if not Last_Assignment_Only then
8127 -- Loop through relevant scopes, which includes the current scope and
8128 -- any parent scopes if the current scope is a block or a package.
8133 -- Clear current values of all entities in current scope
8135 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
8137 -- If scope is a package, also clear current values of all
8138 -- private entities in the scope.
8140 if Is_Package_Or_Generic_Package (S)
8141 or else Is_Concurrent_Type (S)
8143 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
8146 -- If this is a not a subprogram, deal with parents
8148 if not Is_Subprogram (S) then
8150 exit Scope_Loop when S = Standard_Standard;
8154 end loop Scope_Loop;
8155 end Kill_Current_Values;
8157 --------------------------
8158 -- Kill_Size_Check_Code --
8159 --------------------------
8161 procedure Kill_Size_Check_Code (E : Entity_Id) is
8163 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
8164 and then Present (Size_Check_Code (E))
8166 Remove (Size_Check_Code (E));
8167 Set_Size_Check_Code (E, Empty);
8169 end Kill_Size_Check_Code;
8171 --------------------------
8172 -- Known_To_Be_Assigned --
8173 --------------------------
8175 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
8176 P : constant Node_Id := Parent (N);
8181 -- Test left side of assignment
8183 when N_Assignment_Statement =>
8184 return N = Name (P);
8186 -- Function call arguments are never lvalues
8188 when N_Function_Call =>
8191 -- Positional parameter for procedure or accept call
8193 when N_Procedure_Call_Statement |
8202 Proc := Get_Subprogram_Entity (P);
8208 -- If we are not a list member, something is strange, so
8209 -- be conservative and return False.
8211 if not Is_List_Member (N) then
8215 -- We are going to find the right formal by stepping forward
8216 -- through the formals, as we step backwards in the actuals.
8218 Form := First_Formal (Proc);
8221 -- If no formal, something is weird, so be conservative
8222 -- and return False.
8233 return Ekind (Form) /= E_In_Parameter;
8236 -- Named parameter for procedure or accept call
8238 when N_Parameter_Association =>
8244 Proc := Get_Subprogram_Entity (Parent (P));
8250 -- Loop through formals to find the one that matches
8252 Form := First_Formal (Proc);
8254 -- If no matching formal, that's peculiar, some kind of
8255 -- previous error, so return False to be conservative.
8261 -- Else test for match
8263 if Chars (Form) = Chars (Selector_Name (P)) then
8264 return Ekind (Form) /= E_In_Parameter;
8271 -- Test for appearing in a conversion that itself appears
8272 -- in an lvalue context, since this should be an lvalue.
8274 when N_Type_Conversion =>
8275 return Known_To_Be_Assigned (P);
8277 -- All other references are definitely not known to be modifications
8283 end Known_To_Be_Assigned;
8285 ---------------------------
8286 -- Last_Source_Statement --
8287 ---------------------------
8289 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
8293 N := Last (Statements (HSS));
8294 while Present (N) loop
8295 exit when Comes_From_Source (N);
8300 end Last_Source_Statement;
8302 ----------------------------------
8303 -- Matching_Static_Array_Bounds --
8304 ----------------------------------
8306 function Matching_Static_Array_Bounds
8308 R_Typ : Node_Id) return Boolean
8310 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
8311 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
8323 if L_Ndims /= R_Ndims then
8327 -- Unconstrained types do not have static bounds
8329 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
8333 -- First treat specially the first dimension, as the lower bound and
8334 -- length of string literals are not stored like those of arrays.
8336 if Ekind (L_Typ) = E_String_Literal_Subtype then
8337 L_Low := String_Literal_Low_Bound (L_Typ);
8338 L_Len := String_Literal_Length (L_Typ);
8340 L_Index := First_Index (L_Typ);
8341 Get_Index_Bounds (L_Index, L_Low, L_High);
8343 if Is_OK_Static_Expression (L_Low)
8344 and then Is_OK_Static_Expression (L_High)
8346 if Expr_Value (L_High) < Expr_Value (L_Low) then
8349 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
8356 if Ekind (R_Typ) = E_String_Literal_Subtype then
8357 R_Low := String_Literal_Low_Bound (R_Typ);
8358 R_Len := String_Literal_Length (R_Typ);
8360 R_Index := First_Index (R_Typ);
8361 Get_Index_Bounds (R_Index, R_Low, R_High);
8363 if Is_OK_Static_Expression (R_Low)
8364 and then Is_OK_Static_Expression (R_High)
8366 if Expr_Value (R_High) < Expr_Value (R_Low) then
8369 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
8376 if Is_OK_Static_Expression (L_Low)
8377 and then Is_OK_Static_Expression (R_Low)
8378 and then Expr_Value (L_Low) = Expr_Value (R_Low)
8379 and then L_Len = R_Len
8386 -- Then treat all other dimensions
8388 for Indx in 2 .. L_Ndims loop
8392 Get_Index_Bounds (L_Index, L_Low, L_High);
8393 Get_Index_Bounds (R_Index, R_Low, R_High);
8395 if Is_OK_Static_Expression (L_Low)
8396 and then Is_OK_Static_Expression (L_High)
8397 and then Is_OK_Static_Expression (R_Low)
8398 and then Is_OK_Static_Expression (R_High)
8399 and then Expr_Value (L_Low) = Expr_Value (R_Low)
8400 and then Expr_Value (L_High) = Expr_Value (R_High)
8408 -- If we fall through the loop, all indexes matched
8411 end Matching_Static_Array_Bounds;
8417 function May_Be_Lvalue (N : Node_Id) return Boolean is
8418 P : constant Node_Id := Parent (N);
8423 -- Test left side of assignment
8425 when N_Assignment_Statement =>
8426 return N = Name (P);
8428 -- Test prefix of component or attribute. Note that the prefix of an
8429 -- explicit or implicit dereference cannot be an l-value.
8431 when N_Attribute_Reference =>
8432 return N = Prefix (P)
8433 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
8435 -- For an expanded name, the name is an lvalue if the expanded name
8436 -- is an lvalue, but the prefix is never an lvalue, since it is just
8437 -- the scope where the name is found.
8439 when N_Expanded_Name =>
8440 if N = Prefix (P) then
8441 return May_Be_Lvalue (P);
8446 -- For a selected component A.B, A is certainly an lvalue if A.B is.
8447 -- B is a little interesting, if we have A.B := 3, there is some
8448 -- discussion as to whether B is an lvalue or not, we choose to say
8449 -- it is. Note however that A is not an lvalue if it is of an access
8450 -- type since this is an implicit dereference.
8452 when N_Selected_Component =>
8454 and then Present (Etype (N))
8455 and then Is_Access_Type (Etype (N))
8459 return May_Be_Lvalue (P);
8462 -- For an indexed component or slice, the index or slice bounds is
8463 -- never an lvalue. The prefix is an lvalue if the indexed component
8464 -- or slice is an lvalue, except if it is an access type, where we
8465 -- have an implicit dereference.
8467 when N_Indexed_Component =>
8469 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
8473 return May_Be_Lvalue (P);
8476 -- Prefix of a reference is an lvalue if the reference is an lvalue
8479 return May_Be_Lvalue (P);
8481 -- Prefix of explicit dereference is never an lvalue
8483 when N_Explicit_Dereference =>
8486 -- Positional parameter for subprogram, entry, or accept call.
8487 -- In older versions of Ada function call arguments are never
8488 -- lvalues. In Ada 2012 functions can have in-out parameters.
8490 when N_Function_Call |
8491 N_Procedure_Call_Statement |
8492 N_Entry_Call_Statement |
8495 if Nkind (P) = N_Function_Call
8496 and then Ada_Version < Ada_2012
8501 -- The following mechanism is clumsy and fragile. A single
8502 -- flag set in Resolve_Actuals would be preferable ???
8510 Proc := Get_Subprogram_Entity (P);
8516 -- If we are not a list member, something is strange, so
8517 -- be conservative and return True.
8519 if not Is_List_Member (N) then
8523 -- We are going to find the right formal by stepping forward
8524 -- through the formals, as we step backwards in the actuals.
8526 Form := First_Formal (Proc);
8529 -- If no formal, something is weird, so be conservative
8541 return Ekind (Form) /= E_In_Parameter;
8544 -- Named parameter for procedure or accept call
8546 when N_Parameter_Association =>
8552 Proc := Get_Subprogram_Entity (Parent (P));
8558 -- Loop through formals to find the one that matches
8560 Form := First_Formal (Proc);
8562 -- If no matching formal, that's peculiar, some kind of
8563 -- previous error, so return True to be conservative.
8569 -- Else test for match
8571 if Chars (Form) = Chars (Selector_Name (P)) then
8572 return Ekind (Form) /= E_In_Parameter;
8579 -- Test for appearing in a conversion that itself appears in an
8580 -- lvalue context, since this should be an lvalue.
8582 when N_Type_Conversion =>
8583 return May_Be_Lvalue (P);
8585 -- Test for appearance in object renaming declaration
8587 when N_Object_Renaming_Declaration =>
8590 -- All other references are definitely not lvalues
8598 -----------------------
8599 -- Mark_Coextensions --
8600 -----------------------
8602 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
8603 Is_Dynamic : Boolean;
8604 -- Indicates whether the context causes nested coextensions to be
8605 -- dynamic or static
8607 function Mark_Allocator (N : Node_Id) return Traverse_Result;
8608 -- Recognize an allocator node and label it as a dynamic coextension
8610 --------------------
8611 -- Mark_Allocator --
8612 --------------------
8614 function Mark_Allocator (N : Node_Id) return Traverse_Result is
8616 if Nkind (N) = N_Allocator then
8618 Set_Is_Dynamic_Coextension (N);
8620 -- If the allocator expression is potentially dynamic, it may
8621 -- be expanded out of order and require dynamic allocation
8622 -- anyway, so we treat the coextension itself as dynamic.
8623 -- Potential optimization ???
8625 elsif Nkind (Expression (N)) = N_Qualified_Expression
8626 and then Nkind (Expression (Expression (N))) = N_Op_Concat
8628 Set_Is_Dynamic_Coextension (N);
8631 Set_Is_Static_Coextension (N);
8638 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
8640 -- Start of processing Mark_Coextensions
8643 case Nkind (Context_Nod) is
8644 when N_Assignment_Statement |
8645 N_Simple_Return_Statement =>
8646 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
8648 when N_Object_Declaration =>
8649 Is_Dynamic := Nkind (Root_Nod) = N_Allocator;
8651 -- This routine should not be called for constructs which may not
8652 -- contain coextensions.
8655 raise Program_Error;
8658 Mark_Allocators (Root_Nod);
8659 end Mark_Coextensions;
8661 ----------------------
8662 -- Needs_One_Actual --
8663 ----------------------
8665 function Needs_One_Actual (E : Entity_Id) return Boolean is
8669 if Ada_Version >= Ada_2005
8670 and then Present (First_Formal (E))
8672 Formal := Next_Formal (First_Formal (E));
8673 while Present (Formal) loop
8674 if No (Default_Value (Formal)) then
8678 Next_Formal (Formal);
8686 end Needs_One_Actual;
8688 ------------------------
8689 -- New_Copy_List_Tree --
8690 ------------------------
8692 function New_Copy_List_Tree (List : List_Id) return List_Id is
8697 if List = No_List then
8704 while Present (E) loop
8705 Append (New_Copy_Tree (E), NL);
8711 end New_Copy_List_Tree;
8717 use Atree.Unchecked_Access;
8718 use Atree_Private_Part;
8720 -- Our approach here requires a two pass traversal of the tree. The
8721 -- first pass visits all nodes that eventually will be copied looking
8722 -- for defining Itypes. If any defining Itypes are found, then they are
8723 -- copied, and an entry is added to the replacement map. In the second
8724 -- phase, the tree is copied, using the replacement map to replace any
8725 -- Itype references within the copied tree.
8727 -- The following hash tables are used if the Map supplied has more
8728 -- than hash threshold entries to speed up access to the map. If
8729 -- there are fewer entries, then the map is searched sequentially
8730 -- (because setting up a hash table for only a few entries takes
8731 -- more time than it saves.
8733 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
8734 -- Hash function used for hash operations
8740 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
8742 return Nat (E) mod (NCT_Header_Num'Last + 1);
8749 -- The hash table NCT_Assoc associates old entities in the table
8750 -- with their corresponding new entities (i.e. the pairs of entries
8751 -- presented in the original Map argument are Key-Element pairs).
8753 package NCT_Assoc is new Simple_HTable (
8754 Header_Num => NCT_Header_Num,
8755 Element => Entity_Id,
8756 No_Element => Empty,
8758 Hash => New_Copy_Hash,
8759 Equal => Types."=");
8761 ---------------------
8762 -- NCT_Itype_Assoc --
8763 ---------------------
8765 -- The hash table NCT_Itype_Assoc contains entries only for those
8766 -- old nodes which have a non-empty Associated_Node_For_Itype set.
8767 -- The key is the associated node, and the element is the new node
8768 -- itself (NOT the associated node for the new node).
8770 package NCT_Itype_Assoc is new Simple_HTable (
8771 Header_Num => NCT_Header_Num,
8772 Element => Entity_Id,
8773 No_Element => Empty,
8775 Hash => New_Copy_Hash,
8776 Equal => Types."=");
8778 -- Start of processing for New_Copy_Tree function
8780 function New_Copy_Tree
8782 Map : Elist_Id := No_Elist;
8783 New_Sloc : Source_Ptr := No_Location;
8784 New_Scope : Entity_Id := Empty) return Node_Id
8786 Actual_Map : Elist_Id := Map;
8787 -- This is the actual map for the copy. It is initialized with the
8788 -- given elements, and then enlarged as required for Itypes that are
8789 -- copied during the first phase of the copy operation. The visit
8790 -- procedures add elements to this map as Itypes are encountered.
8791 -- The reason we cannot use Map directly, is that it may well be
8792 -- (and normally is) initialized to No_Elist, and if we have mapped
8793 -- entities, we have to reset it to point to a real Elist.
8795 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
8796 -- Called during second phase to map entities into their corresponding
8797 -- copies using Actual_Map. If the argument is not an entity, or is not
8798 -- in Actual_Map, then it is returned unchanged.
8800 procedure Build_NCT_Hash_Tables;
8801 -- Builds hash tables (number of elements >= threshold value)
8803 function Copy_Elist_With_Replacement
8804 (Old_Elist : Elist_Id) return Elist_Id;
8805 -- Called during second phase to copy element list doing replacements
8807 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
8808 -- Called during the second phase to process a copied Itype. The actual
8809 -- copy happened during the first phase (so that we could make the entry
8810 -- in the mapping), but we still have to deal with the descendents of
8811 -- the copied Itype and copy them where necessary.
8813 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
8814 -- Called during second phase to copy list doing replacements
8816 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
8817 -- Called during second phase to copy node doing replacements
8819 procedure Visit_Elist (E : Elist_Id);
8820 -- Called during first phase to visit all elements of an Elist
8822 procedure Visit_Field (F : Union_Id; N : Node_Id);
8823 -- Visit a single field, recursing to call Visit_Node or Visit_List
8824 -- if the field is a syntactic descendent of the current node (i.e.
8825 -- its parent is Node N).
8827 procedure Visit_Itype (Old_Itype : Entity_Id);
8828 -- Called during first phase to visit subsidiary fields of a defining
8829 -- Itype, and also create a copy and make an entry in the replacement
8830 -- map for the new copy.
8832 procedure Visit_List (L : List_Id);
8833 -- Called during first phase to visit all elements of a List
8835 procedure Visit_Node (N : Node_Or_Entity_Id);
8836 -- Called during first phase to visit a node and all its subtrees
8842 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
8847 if not Has_Extension (N) or else No (Actual_Map) then
8850 elsif NCT_Hash_Tables_Used then
8851 Ent := NCT_Assoc.Get (Entity_Id (N));
8853 if Present (Ent) then
8859 -- No hash table used, do serial search
8862 E := First_Elmt (Actual_Map);
8863 while Present (E) loop
8864 if Node (E) = N then
8865 return Node (Next_Elmt (E));
8867 E := Next_Elmt (Next_Elmt (E));
8875 ---------------------------
8876 -- Build_NCT_Hash_Tables --
8877 ---------------------------
8879 procedure Build_NCT_Hash_Tables is
8883 if NCT_Hash_Table_Setup then
8885 NCT_Itype_Assoc.Reset;
8888 Elmt := First_Elmt (Actual_Map);
8889 while Present (Elmt) loop
8892 -- Get new entity, and associate old and new
8895 NCT_Assoc.Set (Ent, Node (Elmt));
8897 if Is_Type (Ent) then
8899 Anode : constant Entity_Id :=
8900 Associated_Node_For_Itype (Ent);
8903 if Present (Anode) then
8905 -- Enter a link between the associated node of the
8906 -- old Itype and the new Itype, for updating later
8907 -- when node is copied.
8909 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
8917 NCT_Hash_Tables_Used := True;
8918 NCT_Hash_Table_Setup := True;
8919 end Build_NCT_Hash_Tables;
8921 ---------------------------------
8922 -- Copy_Elist_With_Replacement --
8923 ---------------------------------
8925 function Copy_Elist_With_Replacement
8926 (Old_Elist : Elist_Id) return Elist_Id
8929 New_Elist : Elist_Id;
8932 if No (Old_Elist) then
8936 New_Elist := New_Elmt_List;
8938 M := First_Elmt (Old_Elist);
8939 while Present (M) loop
8940 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
8946 end Copy_Elist_With_Replacement;
8948 ---------------------------------
8949 -- Copy_Itype_With_Replacement --
8950 ---------------------------------
8952 -- This routine exactly parallels its phase one analog Visit_Itype,
8954 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
8956 -- Translate Next_Entity, Scope and Etype fields, in case they
8957 -- reference entities that have been mapped into copies.
8959 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
8960 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
8962 if Present (New_Scope) then
8963 Set_Scope (New_Itype, New_Scope);
8965 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
8968 -- Copy referenced fields
8970 if Is_Discrete_Type (New_Itype) then
8971 Set_Scalar_Range (New_Itype,
8972 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
8974 elsif Has_Discriminants (Base_Type (New_Itype)) then
8975 Set_Discriminant_Constraint (New_Itype,
8976 Copy_Elist_With_Replacement
8977 (Discriminant_Constraint (New_Itype)));
8979 elsif Is_Array_Type (New_Itype) then
8980 if Present (First_Index (New_Itype)) then
8981 Set_First_Index (New_Itype,
8982 First (Copy_List_With_Replacement
8983 (List_Containing (First_Index (New_Itype)))));
8986 if Is_Packed (New_Itype) then
8987 Set_Packed_Array_Type (New_Itype,
8988 Copy_Node_With_Replacement
8989 (Packed_Array_Type (New_Itype)));
8992 end Copy_Itype_With_Replacement;
8994 --------------------------------
8995 -- Copy_List_With_Replacement --
8996 --------------------------------
8998 function Copy_List_With_Replacement
8999 (Old_List : List_Id) return List_Id
9005 if Old_List = No_List then
9009 New_List := Empty_List;
9011 E := First (Old_List);
9012 while Present (E) loop
9013 Append (Copy_Node_With_Replacement (E), New_List);
9019 end Copy_List_With_Replacement;
9021 --------------------------------
9022 -- Copy_Node_With_Replacement --
9023 --------------------------------
9025 function Copy_Node_With_Replacement
9026 (Old_Node : Node_Id) return Node_Id
9030 procedure Adjust_Named_Associations
9031 (Old_Node : Node_Id;
9032 New_Node : Node_Id);
9033 -- If a call node has named associations, these are chained through
9034 -- the First_Named_Actual, Next_Named_Actual links. These must be
9035 -- propagated separately to the new parameter list, because these
9036 -- are not syntactic fields.
9038 function Copy_Field_With_Replacement
9039 (Field : Union_Id) return Union_Id;
9040 -- Given Field, which is a field of Old_Node, return a copy of it
9041 -- if it is a syntactic field (i.e. its parent is Node), setting
9042 -- the parent of the copy to poit to New_Node. Otherwise returns
9043 -- the field (possibly mapped if it is an entity).
9045 -------------------------------
9046 -- Adjust_Named_Associations --
9047 -------------------------------
9049 procedure Adjust_Named_Associations
9050 (Old_Node : Node_Id;
9060 Old_E := First (Parameter_Associations (Old_Node));
9061 New_E := First (Parameter_Associations (New_Node));
9062 while Present (Old_E) loop
9063 if Nkind (Old_E) = N_Parameter_Association
9064 and then Present (Next_Named_Actual (Old_E))
9066 if First_Named_Actual (Old_Node)
9067 = Explicit_Actual_Parameter (Old_E)
9069 Set_First_Named_Actual
9070 (New_Node, Explicit_Actual_Parameter (New_E));
9073 -- Now scan parameter list from the beginning,to locate
9074 -- next named actual, which can be out of order.
9076 Old_Next := First (Parameter_Associations (Old_Node));
9077 New_Next := First (Parameter_Associations (New_Node));
9079 while Nkind (Old_Next) /= N_Parameter_Association
9080 or else Explicit_Actual_Parameter (Old_Next)
9081 /= Next_Named_Actual (Old_E)
9087 Set_Next_Named_Actual
9088 (New_E, Explicit_Actual_Parameter (New_Next));
9094 end Adjust_Named_Associations;
9096 ---------------------------------
9097 -- Copy_Field_With_Replacement --
9098 ---------------------------------
9100 function Copy_Field_With_Replacement
9101 (Field : Union_Id) return Union_Id
9104 if Field = Union_Id (Empty) then
9107 elsif Field in Node_Range then
9109 Old_N : constant Node_Id := Node_Id (Field);
9113 -- If syntactic field, as indicated by the parent pointer
9114 -- being set, then copy the referenced node recursively.
9116 if Parent (Old_N) = Old_Node then
9117 New_N := Copy_Node_With_Replacement (Old_N);
9119 if New_N /= Old_N then
9120 Set_Parent (New_N, New_Node);
9123 -- For semantic fields, update possible entity reference
9124 -- from the replacement map.
9127 New_N := Assoc (Old_N);
9130 return Union_Id (New_N);
9133 elsif Field in List_Range then
9135 Old_L : constant List_Id := List_Id (Field);
9139 -- If syntactic field, as indicated by the parent pointer,
9140 -- then recursively copy the entire referenced list.
9142 if Parent (Old_L) = Old_Node then
9143 New_L := Copy_List_With_Replacement (Old_L);
9144 Set_Parent (New_L, New_Node);
9146 -- For semantic list, just returned unchanged
9152 return Union_Id (New_L);
9155 -- Anything other than a list or a node is returned unchanged
9160 end Copy_Field_With_Replacement;
9162 -- Start of processing for Copy_Node_With_Replacement
9165 if Old_Node <= Empty_Or_Error then
9168 elsif Has_Extension (Old_Node) then
9169 return Assoc (Old_Node);
9172 New_Node := New_Copy (Old_Node);
9174 -- If the node we are copying is the associated node of a
9175 -- previously copied Itype, then adjust the associated node
9176 -- of the copy of that Itype accordingly.
9178 if Present (Actual_Map) then
9184 -- Case of hash table used
9186 if NCT_Hash_Tables_Used then
9187 Ent := NCT_Itype_Assoc.Get (Old_Node);
9189 if Present (Ent) then
9190 Set_Associated_Node_For_Itype (Ent, New_Node);
9193 -- Case of no hash table used
9196 E := First_Elmt (Actual_Map);
9197 while Present (E) loop
9198 if Is_Itype (Node (E))
9200 Old_Node = Associated_Node_For_Itype (Node (E))
9202 Set_Associated_Node_For_Itype
9203 (Node (Next_Elmt (E)), New_Node);
9206 E := Next_Elmt (Next_Elmt (E));
9212 -- Recursively copy descendents
9215 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
9217 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
9219 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
9221 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
9223 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
9225 -- Adjust Sloc of new node if necessary
9227 if New_Sloc /= No_Location then
9228 Set_Sloc (New_Node, New_Sloc);
9230 -- If we adjust the Sloc, then we are essentially making
9231 -- a completely new node, so the Comes_From_Source flag
9232 -- should be reset to the proper default value.
9234 Nodes.Table (New_Node).Comes_From_Source :=
9235 Default_Node.Comes_From_Source;
9238 -- If the node is call and has named associations,
9239 -- set the corresponding links in the copy.
9241 if (Nkind (Old_Node) = N_Function_Call
9242 or else Nkind (Old_Node) = N_Entry_Call_Statement
9244 Nkind (Old_Node) = N_Procedure_Call_Statement)
9245 and then Present (First_Named_Actual (Old_Node))
9247 Adjust_Named_Associations (Old_Node, New_Node);
9250 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
9251 -- The replacement mechanism applies to entities, and is not used
9252 -- here. Eventually we may need a more general graph-copying
9253 -- routine. For now, do a sequential search to find desired node.
9255 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
9256 and then Present (First_Real_Statement (Old_Node))
9259 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
9263 N1 := First (Statements (Old_Node));
9264 N2 := First (Statements (New_Node));
9266 while N1 /= Old_F loop
9271 Set_First_Real_Statement (New_Node, N2);
9276 -- All done, return copied node
9279 end Copy_Node_With_Replacement;
9285 procedure Visit_Elist (E : Elist_Id) is
9289 Elmt := First_Elmt (E);
9291 while Elmt /= No_Elmt loop
9292 Visit_Node (Node (Elmt));
9302 procedure Visit_Field (F : Union_Id; N : Node_Id) is
9304 if F = Union_Id (Empty) then
9307 elsif F in Node_Range then
9309 -- Copy node if it is syntactic, i.e. its parent pointer is
9310 -- set to point to the field that referenced it (certain
9311 -- Itypes will also meet this criterion, which is fine, since
9312 -- these are clearly Itypes that do need to be copied, since
9313 -- we are copying their parent.)
9315 if Parent (Node_Id (F)) = N then
9316 Visit_Node (Node_Id (F));
9319 -- Another case, if we are pointing to an Itype, then we want
9320 -- to copy it if its associated node is somewhere in the tree
9323 -- Note: the exclusion of self-referential copies is just an
9324 -- optimization, since the search of the already copied list
9325 -- would catch it, but it is a common case (Etype pointing
9326 -- to itself for an Itype that is a base type).
9328 elsif Has_Extension (Node_Id (F))
9329 and then Is_Itype (Entity_Id (F))
9330 and then Node_Id (F) /= N
9336 P := Associated_Node_For_Itype (Node_Id (F));
9337 while Present (P) loop
9339 Visit_Node (Node_Id (F));
9346 -- An Itype whose parent is not being copied definitely
9347 -- should NOT be copied, since it does not belong in any
9348 -- sense to the copied subtree.
9354 elsif F in List_Range
9355 and then Parent (List_Id (F)) = N
9357 Visit_List (List_Id (F));
9366 procedure Visit_Itype (Old_Itype : Entity_Id) is
9367 New_Itype : Entity_Id;
9372 -- Itypes that describe the designated type of access to subprograms
9373 -- have the structure of subprogram declarations, with signatures,
9374 -- etc. Either we duplicate the signatures completely, or choose to
9375 -- share such itypes, which is fine because their elaboration will
9376 -- have no side effects.
9378 if Ekind (Old_Itype) = E_Subprogram_Type then
9382 New_Itype := New_Copy (Old_Itype);
9384 -- The new Itype has all the attributes of the old one, and
9385 -- we just copy the contents of the entity. However, the back-end
9386 -- needs different names for debugging purposes, so we create a
9387 -- new internal name for it in all cases.
9389 Set_Chars (New_Itype, New_Internal_Name ('T'));
9391 -- If our associated node is an entity that has already been copied,
9392 -- then set the associated node of the copy to point to the right
9393 -- copy. If we have copied an Itype that is itself the associated
9394 -- node of some previously copied Itype, then we set the right
9395 -- pointer in the other direction.
9397 if Present (Actual_Map) then
9399 -- Case of hash tables used
9401 if NCT_Hash_Tables_Used then
9403 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
9405 if Present (Ent) then
9406 Set_Associated_Node_For_Itype (New_Itype, Ent);
9409 Ent := NCT_Itype_Assoc.Get (Old_Itype);
9410 if Present (Ent) then
9411 Set_Associated_Node_For_Itype (Ent, New_Itype);
9413 -- If the hash table has no association for this Itype and
9414 -- its associated node, enter one now.
9418 (Associated_Node_For_Itype (Old_Itype), New_Itype);
9421 -- Case of hash tables not used
9424 E := First_Elmt (Actual_Map);
9425 while Present (E) loop
9426 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
9427 Set_Associated_Node_For_Itype
9428 (New_Itype, Node (Next_Elmt (E)));
9431 if Is_Type (Node (E))
9433 Old_Itype = Associated_Node_For_Itype (Node (E))
9435 Set_Associated_Node_For_Itype
9436 (Node (Next_Elmt (E)), New_Itype);
9439 E := Next_Elmt (Next_Elmt (E));
9444 if Present (Freeze_Node (New_Itype)) then
9445 Set_Is_Frozen (New_Itype, False);
9446 Set_Freeze_Node (New_Itype, Empty);
9449 -- Add new association to map
9451 if No (Actual_Map) then
9452 Actual_Map := New_Elmt_List;
9455 Append_Elmt (Old_Itype, Actual_Map);
9456 Append_Elmt (New_Itype, Actual_Map);
9458 if NCT_Hash_Tables_Used then
9459 NCT_Assoc.Set (Old_Itype, New_Itype);
9462 NCT_Table_Entries := NCT_Table_Entries + 1;
9464 if NCT_Table_Entries > NCT_Hash_Threshold then
9465 Build_NCT_Hash_Tables;
9469 -- If a record subtype is simply copied, the entity list will be
9470 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
9472 if Ekind_In (Old_Itype, E_Record_Subtype, E_Class_Wide_Subtype) then
9473 Set_Cloned_Subtype (New_Itype, Old_Itype);
9476 -- Visit descendents that eventually get copied
9478 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
9480 if Is_Discrete_Type (Old_Itype) then
9481 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
9483 elsif Has_Discriminants (Base_Type (Old_Itype)) then
9484 -- ??? This should involve call to Visit_Field
9485 Visit_Elist (Discriminant_Constraint (Old_Itype));
9487 elsif Is_Array_Type (Old_Itype) then
9488 if Present (First_Index (Old_Itype)) then
9489 Visit_Field (Union_Id (List_Containing
9490 (First_Index (Old_Itype))),
9494 if Is_Packed (Old_Itype) then
9495 Visit_Field (Union_Id (Packed_Array_Type (Old_Itype)),
9505 procedure Visit_List (L : List_Id) is
9508 if L /= No_List then
9511 while Present (N) loop
9522 procedure Visit_Node (N : Node_Or_Entity_Id) is
9524 -- Start of processing for Visit_Node
9527 -- Handle case of an Itype, which must be copied
9529 if Has_Extension (N)
9530 and then Is_Itype (N)
9532 -- Nothing to do if already in the list. This can happen with an
9533 -- Itype entity that appears more than once in the tree.
9534 -- Note that we do not want to visit descendents in this case.
9536 -- Test for already in list when hash table is used
9538 if NCT_Hash_Tables_Used then
9539 if Present (NCT_Assoc.Get (Entity_Id (N))) then
9543 -- Test for already in list when hash table not used
9549 if Present (Actual_Map) then
9550 E := First_Elmt (Actual_Map);
9551 while Present (E) loop
9552 if Node (E) = N then
9555 E := Next_Elmt (Next_Elmt (E));
9565 -- Visit descendents
9567 Visit_Field (Field1 (N), N);
9568 Visit_Field (Field2 (N), N);
9569 Visit_Field (Field3 (N), N);
9570 Visit_Field (Field4 (N), N);
9571 Visit_Field (Field5 (N), N);
9574 -- Start of processing for New_Copy_Tree
9579 -- See if we should use hash table
9581 if No (Actual_Map) then
9582 NCT_Hash_Tables_Used := False;
9589 NCT_Table_Entries := 0;
9591 Elmt := First_Elmt (Actual_Map);
9592 while Present (Elmt) loop
9593 NCT_Table_Entries := NCT_Table_Entries + 1;
9598 if NCT_Table_Entries > NCT_Hash_Threshold then
9599 Build_NCT_Hash_Tables;
9601 NCT_Hash_Tables_Used := False;
9606 -- Hash table set up if required, now start phase one by visiting
9607 -- top node (we will recursively visit the descendents).
9609 Visit_Node (Source);
9611 -- Now the second phase of the copy can start. First we process
9612 -- all the mapped entities, copying their descendents.
9614 if Present (Actual_Map) then
9617 New_Itype : Entity_Id;
9619 Elmt := First_Elmt (Actual_Map);
9620 while Present (Elmt) loop
9622 New_Itype := Node (Elmt);
9623 Copy_Itype_With_Replacement (New_Itype);
9629 -- Now we can copy the actual tree
9631 return Copy_Node_With_Replacement (Source);
9634 -------------------------
9635 -- New_External_Entity --
9636 -------------------------
9638 function New_External_Entity
9639 (Kind : Entity_Kind;
9640 Scope_Id : Entity_Id;
9641 Sloc_Value : Source_Ptr;
9642 Related_Id : Entity_Id;
9644 Suffix_Index : Nat := 0;
9645 Prefix : Character := ' ') return Entity_Id
9647 N : constant Entity_Id :=
9648 Make_Defining_Identifier (Sloc_Value,
9650 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
9653 Set_Ekind (N, Kind);
9654 Set_Is_Internal (N, True);
9655 Append_Entity (N, Scope_Id);
9656 Set_Public_Status (N);
9658 if Kind in Type_Kind then
9659 Init_Size_Align (N);
9663 end New_External_Entity;
9665 -------------------------
9666 -- New_Internal_Entity --
9667 -------------------------
9669 function New_Internal_Entity
9670 (Kind : Entity_Kind;
9671 Scope_Id : Entity_Id;
9672 Sloc_Value : Source_Ptr;
9673 Id_Char : Character) return Entity_Id
9675 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
9678 Set_Ekind (N, Kind);
9679 Set_Is_Internal (N, True);
9680 Append_Entity (N, Scope_Id);
9682 if Kind in Type_Kind then
9683 Init_Size_Align (N);
9687 end New_Internal_Entity;
9693 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
9697 -- If we are pointing at a positional parameter, it is a member of a
9698 -- node list (the list of parameters), and the next parameter is the
9699 -- next node on the list, unless we hit a parameter association, then
9700 -- we shift to using the chain whose head is the First_Named_Actual in
9701 -- the parent, and then is threaded using the Next_Named_Actual of the
9702 -- Parameter_Association. All this fiddling is because the original node
9703 -- list is in the textual call order, and what we need is the
9704 -- declaration order.
9706 if Is_List_Member (Actual_Id) then
9707 N := Next (Actual_Id);
9709 if Nkind (N) = N_Parameter_Association then
9710 return First_Named_Actual (Parent (Actual_Id));
9716 return Next_Named_Actual (Parent (Actual_Id));
9720 procedure Next_Actual (Actual_Id : in out Node_Id) is
9722 Actual_Id := Next_Actual (Actual_Id);
9725 -----------------------
9726 -- Normalize_Actuals --
9727 -----------------------
9729 -- Chain actuals according to formals of subprogram. If there are no named
9730 -- associations, the chain is simply the list of Parameter Associations,
9731 -- since the order is the same as the declaration order. If there are named
9732 -- associations, then the First_Named_Actual field in the N_Function_Call
9733 -- or N_Procedure_Call_Statement node points to the Parameter_Association
9734 -- node for the parameter that comes first in declaration order. The
9735 -- remaining named parameters are then chained in declaration order using
9736 -- Next_Named_Actual.
9738 -- This routine also verifies that the number of actuals is compatible with
9739 -- the number and default values of formals, but performs no type checking
9740 -- (type checking is done by the caller).
9742 -- If the matching succeeds, Success is set to True and the caller proceeds
9743 -- with type-checking. If the match is unsuccessful, then Success is set to
9744 -- False, and the caller attempts a different interpretation, if there is
9747 -- If the flag Report is on, the call is not overloaded, and a failure to
9748 -- match can be reported here, rather than in the caller.
9750 procedure Normalize_Actuals
9754 Success : out Boolean)
9756 Actuals : constant List_Id := Parameter_Associations (N);
9757 Actual : Node_Id := Empty;
9759 Last : Node_Id := Empty;
9760 First_Named : Node_Id := Empty;
9763 Formals_To_Match : Integer := 0;
9764 Actuals_To_Match : Integer := 0;
9766 procedure Chain (A : Node_Id);
9767 -- Add named actual at the proper place in the list, using the
9768 -- Next_Named_Actual link.
9770 function Reporting return Boolean;
9771 -- Determines if an error is to be reported. To report an error, we
9772 -- need Report to be True, and also we do not report errors caused
9773 -- by calls to init procs that occur within other init procs. Such
9774 -- errors must always be cascaded errors, since if all the types are
9775 -- declared correctly, the compiler will certainly build decent calls!
9781 procedure Chain (A : Node_Id) is
9785 -- Call node points to first actual in list
9787 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
9790 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
9794 Set_Next_Named_Actual (Last, Empty);
9801 function Reporting return Boolean is
9806 elsif not Within_Init_Proc then
9809 elsif Is_Init_Proc (Entity (Name (N))) then
9817 -- Start of processing for Normalize_Actuals
9820 if Is_Access_Type (S) then
9822 -- The name in the call is a function call that returns an access
9823 -- to subprogram. The designated type has the list of formals.
9825 Formal := First_Formal (Designated_Type (S));
9827 Formal := First_Formal (S);
9830 while Present (Formal) loop
9831 Formals_To_Match := Formals_To_Match + 1;
9832 Next_Formal (Formal);
9835 -- Find if there is a named association, and verify that no positional
9836 -- associations appear after named ones.
9838 if Present (Actuals) then
9839 Actual := First (Actuals);
9842 while Present (Actual)
9843 and then Nkind (Actual) /= N_Parameter_Association
9845 Actuals_To_Match := Actuals_To_Match + 1;
9849 if No (Actual) and Actuals_To_Match = Formals_To_Match then
9851 -- Most common case: positional notation, no defaults
9856 elsif Actuals_To_Match > Formals_To_Match then
9858 -- Too many actuals: will not work
9861 if Is_Entity_Name (Name (N)) then
9862 Error_Msg_N ("too many arguments in call to&", Name (N));
9864 Error_Msg_N ("too many arguments in call", N);
9872 First_Named := Actual;
9874 while Present (Actual) loop
9875 if Nkind (Actual) /= N_Parameter_Association then
9877 ("positional parameters not allowed after named ones", Actual);
9882 Actuals_To_Match := Actuals_To_Match + 1;
9888 if Present (Actuals) then
9889 Actual := First (Actuals);
9892 Formal := First_Formal (S);
9893 while Present (Formal) loop
9895 -- Match the formals in order. If the corresponding actual is
9896 -- positional, nothing to do. Else scan the list of named actuals
9897 -- to find the one with the right name.
9900 and then Nkind (Actual) /= N_Parameter_Association
9903 Actuals_To_Match := Actuals_To_Match - 1;
9904 Formals_To_Match := Formals_To_Match - 1;
9907 -- For named parameters, search the list of actuals to find
9908 -- one that matches the next formal name.
9910 Actual := First_Named;
9912 while Present (Actual) loop
9913 if Chars (Selector_Name (Actual)) = Chars (Formal) then
9916 Actuals_To_Match := Actuals_To_Match - 1;
9917 Formals_To_Match := Formals_To_Match - 1;
9925 if Ekind (Formal) /= E_In_Parameter
9926 or else No (Default_Value (Formal))
9929 if (Comes_From_Source (S)
9930 or else Sloc (S) = Standard_Location)
9931 and then Is_Overloadable (S)
9935 (Nkind (Parent (N)) = N_Procedure_Call_Statement
9937 (Nkind (Parent (N)) = N_Function_Call
9939 Nkind (Parent (N)) = N_Parameter_Association))
9940 and then Ekind (S) /= E_Function
9942 Set_Etype (N, Etype (S));
9944 Error_Msg_Name_1 := Chars (S);
9945 Error_Msg_Sloc := Sloc (S);
9947 ("missing argument for parameter & " &
9948 "in call to % declared #", N, Formal);
9951 elsif Is_Overloadable (S) then
9952 Error_Msg_Name_1 := Chars (S);
9954 -- Point to type derivation that generated the
9957 Error_Msg_Sloc := Sloc (Parent (S));
9960 ("missing argument for parameter & " &
9961 "in call to % (inherited) #", N, Formal);
9965 ("missing argument for parameter &", N, Formal);
9973 Formals_To_Match := Formals_To_Match - 1;
9978 Next_Formal (Formal);
9981 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
9988 -- Find some superfluous named actual that did not get
9989 -- attached to the list of associations.
9991 Actual := First (Actuals);
9992 while Present (Actual) loop
9993 if Nkind (Actual) = N_Parameter_Association
9994 and then Actual /= Last
9995 and then No (Next_Named_Actual (Actual))
9997 Error_Msg_N ("unmatched actual & in call",
9998 Selector_Name (Actual));
10009 end Normalize_Actuals;
10011 --------------------------------
10012 -- Note_Possible_Modification --
10013 --------------------------------
10015 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
10016 Modification_Comes_From_Source : constant Boolean :=
10017 Comes_From_Source (Parent (N));
10023 -- Loop to find referenced entity, if there is one
10030 if Is_Entity_Name (Exp) then
10031 Ent := Entity (Exp);
10033 -- If the entity is missing, it is an undeclared identifier,
10034 -- and there is nothing to annotate.
10040 elsif Nkind (Exp) = N_Explicit_Dereference then
10042 P : constant Node_Id := Prefix (Exp);
10045 if Nkind (P) = N_Selected_Component
10047 Entry_Formal (Entity (Selector_Name (P))))
10049 -- Case of a reference to an entry formal
10051 Ent := Entry_Formal (Entity (Selector_Name (P)));
10053 elsif Nkind (P) = N_Identifier
10054 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
10055 and then Present (Expression (Parent (Entity (P))))
10056 and then Nkind (Expression (Parent (Entity (P))))
10059 -- Case of a reference to a value on which side effects have
10062 Exp := Prefix (Expression (Parent (Entity (P))));
10071 elsif Nkind (Exp) = N_Type_Conversion
10072 or else Nkind (Exp) = N_Unchecked_Type_Conversion
10074 Exp := Expression (Exp);
10077 elsif Nkind (Exp) = N_Slice
10078 or else Nkind (Exp) = N_Indexed_Component
10079 or else Nkind (Exp) = N_Selected_Component
10081 Exp := Prefix (Exp);
10088 -- Now look for entity being referenced
10090 if Present (Ent) then
10091 if Is_Object (Ent) then
10092 if Comes_From_Source (Exp)
10093 or else Modification_Comes_From_Source
10095 -- Give warning if pragma unmodified given and we are
10096 -- sure this is a modification.
10098 if Has_Pragma_Unmodified (Ent) and then Sure then
10099 Error_Msg_NE ("?pragma Unmodified given for &!", N, Ent);
10102 Set_Never_Set_In_Source (Ent, False);
10105 Set_Is_True_Constant (Ent, False);
10106 Set_Current_Value (Ent, Empty);
10107 Set_Is_Known_Null (Ent, False);
10109 if not Can_Never_Be_Null (Ent) then
10110 Set_Is_Known_Non_Null (Ent, False);
10113 -- Follow renaming chain
10115 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
10116 and then Present (Renamed_Object (Ent))
10118 Exp := Renamed_Object (Ent);
10122 -- Generate a reference only if the assignment comes from
10123 -- source. This excludes, for example, calls to a dispatching
10124 -- assignment operation when the left-hand side is tagged.
10126 if Modification_Comes_From_Source then
10127 Generate_Reference (Ent, Exp, 'm');
10129 -- If the target of the assignment is the bound variable
10130 -- in an iterator, indicate that the corresponding array
10131 -- or container is also modified.
10133 if Ada_Version >= Ada_2012
10135 Nkind (Parent (Ent)) = N_Iterator_Specification
10138 Domain : constant Node_Id := Name (Parent (Ent));
10141 -- TBD : in the full version of the construct, the
10142 -- domain of iteration can be given by an expression.
10144 if Is_Entity_Name (Domain) then
10145 Generate_Reference (Entity (Domain), Exp, 'm');
10146 Set_Is_True_Constant (Entity (Domain), False);
10147 Set_Never_Set_In_Source (Entity (Domain), False);
10153 Check_Nested_Access (Ent);
10158 -- If we are sure this is a modification from source, and we know
10159 -- this modifies a constant, then give an appropriate warning.
10161 if Overlays_Constant (Ent)
10162 and then Modification_Comes_From_Source
10166 A : constant Node_Id := Address_Clause (Ent);
10168 if Present (A) then
10170 Exp : constant Node_Id := Expression (A);
10172 if Nkind (Exp) = N_Attribute_Reference
10173 and then Attribute_Name (Exp) = Name_Address
10174 and then Is_Entity_Name (Prefix (Exp))
10176 Error_Msg_Sloc := Sloc (A);
10178 ("constant& may be modified via address clause#?",
10179 N, Entity (Prefix (Exp)));
10189 end Note_Possible_Modification;
10191 -------------------------
10192 -- Object_Access_Level --
10193 -------------------------
10195 function Object_Access_Level (Obj : Node_Id) return Uint is
10198 -- Returns the static accessibility level of the view denoted by Obj. Note
10199 -- that the value returned is the result of a call to Scope_Depth. Only
10200 -- scope depths associated with dynamic scopes can actually be returned.
10201 -- Since only relative levels matter for accessibility checking, the fact
10202 -- that the distance between successive levels of accessibility is not
10203 -- always one is immaterial (invariant: if level(E2) is deeper than
10204 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
10206 function Reference_To (Obj : Node_Id) return Node_Id;
10207 -- An explicit dereference is created when removing side-effects from
10208 -- expressions for constraint checking purposes. In this case a local
10209 -- access type is created for it. The correct access level is that of
10210 -- the original source node. We detect this case by noting that the
10211 -- prefix of the dereference is created by an object declaration whose
10212 -- initial expression is a reference.
10218 function Reference_To (Obj : Node_Id) return Node_Id is
10219 Pref : constant Node_Id := Prefix (Obj);
10221 if Is_Entity_Name (Pref)
10222 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
10223 and then Present (Expression (Parent (Entity (Pref))))
10224 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
10226 return (Prefix (Expression (Parent (Entity (Pref)))));
10232 -- Start of processing for Object_Access_Level
10235 if Is_Entity_Name (Obj) then
10238 if Is_Prival (E) then
10239 E := Prival_Link (E);
10242 -- If E is a type then it denotes a current instance. For this case
10243 -- we add one to the normal accessibility level of the type to ensure
10244 -- that current instances are treated as always being deeper than
10245 -- than the level of any visible named access type (see 3.10.2(21)).
10247 if Is_Type (E) then
10248 return Type_Access_Level (E) + 1;
10250 elsif Present (Renamed_Object (E)) then
10251 return Object_Access_Level (Renamed_Object (E));
10253 -- Similarly, if E is a component of the current instance of a
10254 -- protected type, any instance of it is assumed to be at a deeper
10255 -- level than the type. For a protected object (whose type is an
10256 -- anonymous protected type) its components are at the same level
10257 -- as the type itself.
10259 elsif not Is_Overloadable (E)
10260 and then Ekind (Scope (E)) = E_Protected_Type
10261 and then Comes_From_Source (Scope (E))
10263 return Type_Access_Level (Scope (E)) + 1;
10266 return Scope_Depth (Enclosing_Dynamic_Scope (E));
10269 elsif Nkind (Obj) = N_Selected_Component then
10270 if Is_Access_Type (Etype (Prefix (Obj))) then
10271 return Type_Access_Level (Etype (Prefix (Obj)));
10273 return Object_Access_Level (Prefix (Obj));
10276 elsif Nkind (Obj) = N_Indexed_Component then
10277 if Is_Access_Type (Etype (Prefix (Obj))) then
10278 return Type_Access_Level (Etype (Prefix (Obj)));
10280 return Object_Access_Level (Prefix (Obj));
10283 elsif Nkind (Obj) = N_Explicit_Dereference then
10285 -- If the prefix is a selected access discriminant then we make a
10286 -- recursive call on the prefix, which will in turn check the level
10287 -- of the prefix object of the selected discriminant.
10289 if Nkind (Prefix (Obj)) = N_Selected_Component
10290 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
10292 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
10294 return Object_Access_Level (Prefix (Obj));
10296 elsif not (Comes_From_Source (Obj)) then
10298 Ref : constant Node_Id := Reference_To (Obj);
10300 if Present (Ref) then
10301 return Object_Access_Level (Ref);
10303 return Type_Access_Level (Etype (Prefix (Obj)));
10308 return Type_Access_Level (Etype (Prefix (Obj)));
10311 elsif Nkind (Obj) = N_Type_Conversion
10312 or else Nkind (Obj) = N_Unchecked_Type_Conversion
10314 return Object_Access_Level (Expression (Obj));
10316 elsif Nkind (Obj) = N_Function_Call then
10318 -- Function results are objects, so we get either the access level of
10319 -- the function or, in the case of an indirect call, the level of the
10320 -- access-to-subprogram type. (This code is used for Ada 95, but it
10321 -- looks wrong, because it seems that we should be checking the level
10322 -- of the call itself, even for Ada 95. However, using the Ada 2005
10323 -- version of the code causes regressions in several tests that are
10324 -- compiled with -gnat95. ???)
10326 if Ada_Version < Ada_2005 then
10327 if Is_Entity_Name (Name (Obj)) then
10328 return Subprogram_Access_Level (Entity (Name (Obj)));
10330 return Type_Access_Level (Etype (Prefix (Name (Obj))));
10333 -- For Ada 2005, the level of the result object of a function call is
10334 -- defined to be the level of the call's innermost enclosing master.
10335 -- We determine that by querying the depth of the innermost enclosing
10339 Return_Master_Scope_Depth_Of_Call : declare
10341 function Innermost_Master_Scope_Depth
10342 (N : Node_Id) return Uint;
10343 -- Returns the scope depth of the given node's innermost
10344 -- enclosing dynamic scope (effectively the accessibility
10345 -- level of the innermost enclosing master).
10347 ----------------------------------
10348 -- Innermost_Master_Scope_Depth --
10349 ----------------------------------
10351 function Innermost_Master_Scope_Depth
10352 (N : Node_Id) return Uint
10354 Node_Par : Node_Id := Parent (N);
10357 -- Locate the nearest enclosing node (by traversing Parents)
10358 -- that Defining_Entity can be applied to, and return the
10359 -- depth of that entity's nearest enclosing dynamic scope.
10361 while Present (Node_Par) loop
10362 case Nkind (Node_Par) is
10363 when N_Component_Declaration |
10364 N_Entry_Declaration |
10365 N_Formal_Object_Declaration |
10366 N_Formal_Type_Declaration |
10367 N_Full_Type_Declaration |
10368 N_Incomplete_Type_Declaration |
10369 N_Loop_Parameter_Specification |
10370 N_Object_Declaration |
10371 N_Protected_Type_Declaration |
10372 N_Private_Extension_Declaration |
10373 N_Private_Type_Declaration |
10374 N_Subtype_Declaration |
10375 N_Function_Specification |
10376 N_Procedure_Specification |
10377 N_Task_Type_Declaration |
10379 N_Generic_Instantiation |
10381 N_Implicit_Label_Declaration |
10382 N_Package_Declaration |
10383 N_Single_Task_Declaration |
10384 N_Subprogram_Declaration |
10385 N_Generic_Declaration |
10386 N_Renaming_Declaration |
10387 N_Block_Statement |
10388 N_Formal_Subprogram_Declaration |
10389 N_Abstract_Subprogram_Declaration |
10391 N_Exception_Declaration |
10392 N_Formal_Package_Declaration |
10393 N_Number_Declaration |
10394 N_Package_Specification |
10395 N_Parameter_Specification |
10396 N_Single_Protected_Declaration |
10400 (Nearest_Dynamic_Scope
10401 (Defining_Entity (Node_Par)));
10407 Node_Par := Parent (Node_Par);
10410 pragma Assert (False);
10412 -- Should never reach the following return
10414 return Scope_Depth (Current_Scope) + 1;
10415 end Innermost_Master_Scope_Depth;
10417 -- Start of processing for Return_Master_Scope_Depth_Of_Call
10420 return Innermost_Master_Scope_Depth (Obj);
10421 end Return_Master_Scope_Depth_Of_Call;
10424 -- For convenience we handle qualified expressions, even though
10425 -- they aren't technically object names.
10427 elsif Nkind (Obj) = N_Qualified_Expression then
10428 return Object_Access_Level (Expression (Obj));
10430 -- Otherwise return the scope level of Standard.
10431 -- (If there are cases that fall through
10432 -- to this point they will be treated as
10433 -- having global accessibility for now. ???)
10436 return Scope_Depth (Standard_Standard);
10438 end Object_Access_Level;
10440 --------------------------------------
10441 -- Original_Corresponding_Operation --
10442 --------------------------------------
10444 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
10446 Typ : constant Entity_Id := Find_Dispatching_Type (S);
10449 -- If S is an inherited primitive S2 the original corresponding
10450 -- operation of S is the original corresponding operation of S2
10452 if Present (Alias (S))
10453 and then Find_Dispatching_Type (Alias (S)) /= Typ
10455 return Original_Corresponding_Operation (Alias (S));
10457 -- If S overrides an inherited subprogram S2 the original corresponding
10458 -- operation of S is the original corresponding operation of S2
10460 elsif Present (Overridden_Operation (S)) then
10461 return Original_Corresponding_Operation (Overridden_Operation (S));
10463 -- otherwise it is S itself
10468 end Original_Corresponding_Operation;
10470 -----------------------
10471 -- Private_Component --
10472 -----------------------
10474 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
10475 Ancestor : constant Entity_Id := Base_Type (Type_Id);
10477 function Trace_Components
10479 Check : Boolean) return Entity_Id;
10480 -- Recursive function that does the work, and checks against circular
10481 -- definition for each subcomponent type.
10483 ----------------------
10484 -- Trace_Components --
10485 ----------------------
10487 function Trace_Components
10489 Check : Boolean) return Entity_Id
10491 Btype : constant Entity_Id := Base_Type (T);
10492 Component : Entity_Id;
10494 Candidate : Entity_Id := Empty;
10497 if Check and then Btype = Ancestor then
10498 Error_Msg_N ("circular type definition", Type_Id);
10502 if Is_Private_Type (Btype)
10503 and then not Is_Generic_Type (Btype)
10505 if Present (Full_View (Btype))
10506 and then Is_Record_Type (Full_View (Btype))
10507 and then not Is_Frozen (Btype)
10509 -- To indicate that the ancestor depends on a private type, the
10510 -- current Btype is sufficient. However, to check for circular
10511 -- definition we must recurse on the full view.
10513 Candidate := Trace_Components (Full_View (Btype), True);
10515 if Candidate = Any_Type then
10525 elsif Is_Array_Type (Btype) then
10526 return Trace_Components (Component_Type (Btype), True);
10528 elsif Is_Record_Type (Btype) then
10529 Component := First_Entity (Btype);
10530 while Present (Component) loop
10532 -- Skip anonymous types generated by constrained components
10534 if not Is_Type (Component) then
10535 P := Trace_Components (Etype (Component), True);
10537 if Present (P) then
10538 if P = Any_Type then
10546 Next_Entity (Component);
10554 end Trace_Components;
10556 -- Start of processing for Private_Component
10559 return Trace_Components (Type_Id, False);
10560 end Private_Component;
10562 ---------------------------
10563 -- Primitive_Names_Match --
10564 ---------------------------
10566 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
10568 function Non_Internal_Name (E : Entity_Id) return Name_Id;
10569 -- Given an internal name, returns the corresponding non-internal name
10571 ------------------------
10572 -- Non_Internal_Name --
10573 ------------------------
10575 function Non_Internal_Name (E : Entity_Id) return Name_Id is
10577 Get_Name_String (Chars (E));
10578 Name_Len := Name_Len - 1;
10580 end Non_Internal_Name;
10582 -- Start of processing for Primitive_Names_Match
10585 pragma Assert (Present (E1) and then Present (E2));
10587 return Chars (E1) = Chars (E2)
10589 (not Is_Internal_Name (Chars (E1))
10590 and then Is_Internal_Name (Chars (E2))
10591 and then Non_Internal_Name (E2) = Chars (E1))
10593 (not Is_Internal_Name (Chars (E2))
10594 and then Is_Internal_Name (Chars (E1))
10595 and then Non_Internal_Name (E1) = Chars (E2))
10597 (Is_Predefined_Dispatching_Operation (E1)
10598 and then Is_Predefined_Dispatching_Operation (E2)
10599 and then Same_TSS (E1, E2))
10601 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
10602 end Primitive_Names_Match;
10604 -----------------------
10605 -- Process_End_Label --
10606 -----------------------
10608 procedure Process_End_Label
10617 Label_Ref : Boolean;
10618 -- Set True if reference to end label itself is required
10621 -- Gets set to the operator symbol or identifier that references the
10622 -- entity Ent. For the child unit case, this is the identifier from the
10623 -- designator. For other cases, this is simply Endl.
10625 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
10626 -- N is an identifier node that appears as a parent unit reference in
10627 -- the case where Ent is a child unit. This procedure generates an
10628 -- appropriate cross-reference entry. E is the corresponding entity.
10630 -------------------------
10631 -- Generate_Parent_Ref --
10632 -------------------------
10634 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
10636 -- If names do not match, something weird, skip reference
10638 if Chars (E) = Chars (N) then
10640 -- Generate the reference. We do NOT consider this as a reference
10641 -- for unreferenced symbol purposes.
10643 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
10645 if Style_Check then
10646 Style.Check_Identifier (N, E);
10649 end Generate_Parent_Ref;
10651 -- Start of processing for Process_End_Label
10654 -- If no node, ignore. This happens in some error situations, and
10655 -- also for some internally generated structures where no end label
10656 -- references are required in any case.
10662 -- Nothing to do if no End_Label, happens for internally generated
10663 -- constructs where we don't want an end label reference anyway. Also
10664 -- nothing to do if Endl is a string literal, which means there was
10665 -- some prior error (bad operator symbol)
10667 Endl := End_Label (N);
10669 if No (Endl) or else Nkind (Endl) = N_String_Literal then
10673 -- Reference node is not in extended main source unit
10675 if not In_Extended_Main_Source_Unit (N) then
10677 -- Generally we do not collect references except for the extended
10678 -- main source unit. The one exception is the 'e' entry for a
10679 -- package spec, where it is useful for a client to have the
10680 -- ending information to define scopes.
10686 Label_Ref := False;
10688 -- For this case, we can ignore any parent references, but we
10689 -- need the package name itself for the 'e' entry.
10691 if Nkind (Endl) = N_Designator then
10692 Endl := Identifier (Endl);
10696 -- Reference is in extended main source unit
10701 -- For designator, generate references for the parent entries
10703 if Nkind (Endl) = N_Designator then
10705 -- Generate references for the prefix if the END line comes from
10706 -- source (otherwise we do not need these references) We climb the
10707 -- scope stack to find the expected entities.
10709 if Comes_From_Source (Endl) then
10710 Nam := Name (Endl);
10711 Scop := Current_Scope;
10712 while Nkind (Nam) = N_Selected_Component loop
10713 Scop := Scope (Scop);
10714 exit when No (Scop);
10715 Generate_Parent_Ref (Selector_Name (Nam), Scop);
10716 Nam := Prefix (Nam);
10719 if Present (Scop) then
10720 Generate_Parent_Ref (Nam, Scope (Scop));
10724 Endl := Identifier (Endl);
10728 -- If the end label is not for the given entity, then either we have
10729 -- some previous error, or this is a generic instantiation for which
10730 -- we do not need to make a cross-reference in this case anyway. In
10731 -- either case we simply ignore the call.
10733 if Chars (Ent) /= Chars (Endl) then
10737 -- If label was really there, then generate a normal reference and then
10738 -- adjust the location in the end label to point past the name (which
10739 -- should almost always be the semicolon).
10741 Loc := Sloc (Endl);
10743 if Comes_From_Source (Endl) then
10745 -- If a label reference is required, then do the style check and
10746 -- generate an l-type cross-reference entry for the label
10749 if Style_Check then
10750 Style.Check_Identifier (Endl, Ent);
10753 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
10756 -- Set the location to point past the label (normally this will
10757 -- mean the semicolon immediately following the label). This is
10758 -- done for the sake of the 'e' or 't' entry generated below.
10760 Get_Decoded_Name_String (Chars (Endl));
10761 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
10764 -- In SPARK mode, no missing label is allowed for packages and
10765 -- subprogram bodies. Detect those cases by testing whether
10766 -- Process_End_Label was called for a body (Typ = 't') or a package.
10768 if (SPARK_Mode or else Restriction_Check_Required (SPARK))
10769 and then (Typ = 't' or else Ekind (Ent) = E_Package)
10771 Error_Msg_Node_1 := Endl;
10772 Check_Formal_Restriction ("`END &` required", Endl, Force => True);
10776 -- Now generate the e/t reference
10778 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
10780 -- Restore Sloc, in case modified above, since we have an identifier
10781 -- and the normal Sloc should be left set in the tree.
10783 Set_Sloc (Endl, Loc);
10784 end Process_End_Label;
10786 ------------------------------------
10787 -- References_Generic_Formal_Type --
10788 ------------------------------------
10790 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
10792 function Process (N : Node_Id) return Traverse_Result;
10793 -- Process one node in search for generic formal type
10799 function Process (N : Node_Id) return Traverse_Result is
10801 if Nkind (N) in N_Has_Entity then
10803 E : constant Entity_Id := Entity (N);
10805 if Present (E) then
10806 if Is_Generic_Type (E) then
10808 elsif Present (Etype (E))
10809 and then Is_Generic_Type (Etype (E))
10820 function Traverse is new Traverse_Func (Process);
10821 -- Traverse tree to look for generic type
10824 if Inside_A_Generic then
10825 return Traverse (N) = Abandon;
10829 end References_Generic_Formal_Type;
10831 --------------------
10832 -- Remove_Homonym --
10833 --------------------
10835 procedure Remove_Homonym (E : Entity_Id) is
10836 Prev : Entity_Id := Empty;
10840 if E = Current_Entity (E) then
10841 if Present (Homonym (E)) then
10842 Set_Current_Entity (Homonym (E));
10844 Set_Name_Entity_Id (Chars (E), Empty);
10847 H := Current_Entity (E);
10848 while Present (H) and then H /= E loop
10853 Set_Homonym (Prev, Homonym (E));
10855 end Remove_Homonym;
10857 ---------------------
10858 -- Rep_To_Pos_Flag --
10859 ---------------------
10861 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
10863 return New_Occurrence_Of
10864 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
10865 end Rep_To_Pos_Flag;
10867 --------------------
10868 -- Require_Entity --
10869 --------------------
10871 procedure Require_Entity (N : Node_Id) is
10873 if Is_Entity_Name (N) and then No (Entity (N)) then
10874 if Total_Errors_Detected /= 0 then
10875 Set_Entity (N, Any_Id);
10877 raise Program_Error;
10880 end Require_Entity;
10882 ------------------------------
10883 -- Requires_Transient_Scope --
10884 ------------------------------
10886 -- A transient scope is required when variable-sized temporaries are
10887 -- allocated in the primary or secondary stack, or when finalization
10888 -- actions must be generated before the next instruction.
10890 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
10891 Typ : constant Entity_Id := Underlying_Type (Id);
10893 -- Start of processing for Requires_Transient_Scope
10896 -- This is a private type which is not completed yet. This can only
10897 -- happen in a default expression (of a formal parameter or of a
10898 -- record component). Do not expand transient scope in this case
10903 -- Do not expand transient scope for non-existent procedure return
10905 elsif Typ = Standard_Void_Type then
10908 -- Elementary types do not require a transient scope
10910 elsif Is_Elementary_Type (Typ) then
10913 -- Generally, indefinite subtypes require a transient scope, since the
10914 -- back end cannot generate temporaries, since this is not a valid type
10915 -- for declaring an object. It might be possible to relax this in the
10916 -- future, e.g. by declaring the maximum possible space for the type.
10918 elsif Is_Indefinite_Subtype (Typ) then
10921 -- Functions returning tagged types may dispatch on result so their
10922 -- returned value is allocated on the secondary stack. Controlled
10923 -- type temporaries need finalization.
10925 elsif Is_Tagged_Type (Typ)
10926 or else Has_Controlled_Component (Typ)
10928 return not Is_Value_Type (Typ);
10932 elsif Is_Record_Type (Typ) then
10936 Comp := First_Entity (Typ);
10937 while Present (Comp) loop
10938 if Ekind (Comp) = E_Component
10939 and then Requires_Transient_Scope (Etype (Comp))
10943 Next_Entity (Comp);
10950 -- String literal types never require transient scope
10952 elsif Ekind (Typ) = E_String_Literal_Subtype then
10955 -- Array type. Note that we already know that this is a constrained
10956 -- array, since unconstrained arrays will fail the indefinite test.
10958 elsif Is_Array_Type (Typ) then
10960 -- If component type requires a transient scope, the array does too
10962 if Requires_Transient_Scope (Component_Type (Typ)) then
10965 -- Otherwise, we only need a transient scope if the size depends on
10966 -- the value of one or more discriminants.
10969 return Size_Depends_On_Discriminant (Typ);
10972 -- All other cases do not require a transient scope
10977 end Requires_Transient_Scope;
10979 --------------------------
10980 -- Reset_Analyzed_Flags --
10981 --------------------------
10983 procedure Reset_Analyzed_Flags (N : Node_Id) is
10985 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
10986 -- Function used to reset Analyzed flags in tree. Note that we do
10987 -- not reset Analyzed flags in entities, since there is no need to
10988 -- reanalyze entities, and indeed, it is wrong to do so, since it
10989 -- can result in generating auxiliary stuff more than once.
10991 --------------------
10992 -- Clear_Analyzed --
10993 --------------------
10995 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
10997 if not Has_Extension (N) then
10998 Set_Analyzed (N, False);
11002 end Clear_Analyzed;
11004 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
11006 -- Start of processing for Reset_Analyzed_Flags
11009 Reset_Analyzed (N);
11010 end Reset_Analyzed_Flags;
11012 ---------------------------
11013 -- Safe_To_Capture_Value --
11014 ---------------------------
11016 function Safe_To_Capture_Value
11019 Cond : Boolean := False) return Boolean
11022 -- The only entities for which we track constant values are variables
11023 -- which are not renamings, constants, out parameters, and in out
11024 -- parameters, so check if we have this case.
11026 -- Note: it may seem odd to track constant values for constants, but in
11027 -- fact this routine is used for other purposes than simply capturing
11028 -- the value. In particular, the setting of Known[_Non]_Null.
11030 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
11032 Ekind (Ent) = E_Constant
11034 Ekind (Ent) = E_Out_Parameter
11036 Ekind (Ent) = E_In_Out_Parameter
11040 -- For conditionals, we also allow loop parameters and all formals,
11041 -- including in parameters.
11045 (Ekind (Ent) = E_Loop_Parameter
11047 Ekind (Ent) = E_In_Parameter)
11051 -- For all other cases, not just unsafe, but impossible to capture
11052 -- Current_Value, since the above are the only entities which have
11053 -- Current_Value fields.
11059 -- Skip if volatile or aliased, since funny things might be going on in
11060 -- these cases which we cannot necessarily track. Also skip any variable
11061 -- for which an address clause is given, or whose address is taken. Also
11062 -- never capture value of library level variables (an attempt to do so
11063 -- can occur in the case of package elaboration code).
11065 if Treat_As_Volatile (Ent)
11066 or else Is_Aliased (Ent)
11067 or else Present (Address_Clause (Ent))
11068 or else Address_Taken (Ent)
11069 or else (Is_Library_Level_Entity (Ent)
11070 and then Ekind (Ent) = E_Variable)
11075 -- OK, all above conditions are met. We also require that the scope of
11076 -- the reference be the same as the scope of the entity, not counting
11077 -- packages and blocks and loops.
11080 E_Scope : constant Entity_Id := Scope (Ent);
11081 R_Scope : Entity_Id;
11084 R_Scope := Current_Scope;
11085 while R_Scope /= Standard_Standard loop
11086 exit when R_Scope = E_Scope;
11088 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
11091 R_Scope := Scope (R_Scope);
11096 -- We also require that the reference does not appear in a context
11097 -- where it is not sure to be executed (i.e. a conditional context
11098 -- or an exception handler). We skip this if Cond is True, since the
11099 -- capturing of values from conditional tests handles this ok.
11113 while Present (P) loop
11114 if Nkind (P) = N_If_Statement
11115 or else Nkind (P) = N_Case_Statement
11116 or else (Nkind (P) in N_Short_Circuit
11117 and then Desc = Right_Opnd (P))
11118 or else (Nkind (P) = N_Conditional_Expression
11119 and then Desc /= First (Expressions (P)))
11120 or else Nkind (P) = N_Exception_Handler
11121 or else Nkind (P) = N_Selective_Accept
11122 or else Nkind (P) = N_Conditional_Entry_Call
11123 or else Nkind (P) = N_Timed_Entry_Call
11124 or else Nkind (P) = N_Asynchronous_Select
11134 -- OK, looks safe to set value
11137 end Safe_To_Capture_Value;
11143 function Same_Name (N1, N2 : Node_Id) return Boolean is
11144 K1 : constant Node_Kind := Nkind (N1);
11145 K2 : constant Node_Kind := Nkind (N2);
11148 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
11149 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
11151 return Chars (N1) = Chars (N2);
11153 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
11154 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
11156 return Same_Name (Selector_Name (N1), Selector_Name (N2))
11157 and then Same_Name (Prefix (N1), Prefix (N2));
11168 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
11169 N1 : constant Node_Id := Original_Node (Node1);
11170 N2 : constant Node_Id := Original_Node (Node2);
11171 -- We do the tests on original nodes, since we are most interested
11172 -- in the original source, not any expansion that got in the way.
11174 K1 : constant Node_Kind := Nkind (N1);
11175 K2 : constant Node_Kind := Nkind (N2);
11178 -- First case, both are entities with same entity
11180 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
11182 EN1 : constant Entity_Id := Entity (N1);
11183 EN2 : constant Entity_Id := Entity (N2);
11185 if Present (EN1) and then Present (EN2)
11186 and then (Ekind_In (EN1, E_Variable, E_Constant)
11187 or else Is_Formal (EN1))
11195 -- Second case, selected component with same selector, same record
11197 if K1 = N_Selected_Component
11198 and then K2 = N_Selected_Component
11199 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
11201 return Same_Object (Prefix (N1), Prefix (N2));
11203 -- Third case, indexed component with same subscripts, same array
11205 elsif K1 = N_Indexed_Component
11206 and then K2 = N_Indexed_Component
11207 and then Same_Object (Prefix (N1), Prefix (N2))
11212 E1 := First (Expressions (N1));
11213 E2 := First (Expressions (N2));
11214 while Present (E1) loop
11215 if not Same_Value (E1, E2) then
11226 -- Fourth case, slice of same array with same bounds
11229 and then K2 = N_Slice
11230 and then Nkind (Discrete_Range (N1)) = N_Range
11231 and then Nkind (Discrete_Range (N2)) = N_Range
11232 and then Same_Value (Low_Bound (Discrete_Range (N1)),
11233 Low_Bound (Discrete_Range (N2)))
11234 and then Same_Value (High_Bound (Discrete_Range (N1)),
11235 High_Bound (Discrete_Range (N2)))
11237 return Same_Name (Prefix (N1), Prefix (N2));
11239 -- All other cases, not clearly the same object
11250 function Same_Type (T1, T2 : Entity_Id) return Boolean is
11255 elsif not Is_Constrained (T1)
11256 and then not Is_Constrained (T2)
11257 and then Base_Type (T1) = Base_Type (T2)
11261 -- For now don't bother with case of identical constraints, to be
11262 -- fiddled with later on perhaps (this is only used for optimization
11263 -- purposes, so it is not critical to do a best possible job)
11274 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
11276 if Compile_Time_Known_Value (Node1)
11277 and then Compile_Time_Known_Value (Node2)
11278 and then Expr_Value (Node1) = Expr_Value (Node2)
11281 elsif Same_Object (Node1, Node2) then
11292 procedure Save_Actual (N : Node_Id; Writable : Boolean := False) is
11294 if Ada_Version < Ada_2012 then
11297 elsif Is_Entity_Name (N)
11299 Nkind_In (N, N_Indexed_Component, N_Selected_Component, N_Slice)
11301 (Nkind (N) = N_Attribute_Reference
11302 and then Attribute_Name (N) = Name_Access)
11305 -- We are only interested in IN OUT parameters of inner calls
11308 or else Nkind (Parent (N)) = N_Function_Call
11309 or else Nkind (Parent (N)) in N_Op
11311 Actuals_In_Call.Increment_Last;
11312 Actuals_In_Call.Table (Actuals_In_Call.Last) := (N, Writable);
11317 ------------------------
11318 -- Scope_Is_Transient --
11319 ------------------------
11321 function Scope_Is_Transient return Boolean is
11323 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
11324 end Scope_Is_Transient;
11330 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
11335 while Scop /= Standard_Standard loop
11336 Scop := Scope (Scop);
11338 if Scop = Scope2 then
11346 --------------------------
11347 -- Scope_Within_Or_Same --
11348 --------------------------
11350 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
11355 while Scop /= Standard_Standard loop
11356 if Scop = Scope2 then
11359 Scop := Scope (Scop);
11364 end Scope_Within_Or_Same;
11366 --------------------
11367 -- Set_Convention --
11368 --------------------
11370 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
11372 Basic_Set_Convention (E, Val);
11375 and then Is_Access_Subprogram_Type (Base_Type (E))
11376 and then Has_Foreign_Convention (E)
11378 Set_Can_Use_Internal_Rep (E, False);
11380 end Set_Convention;
11382 ------------------------
11383 -- Set_Current_Entity --
11384 ------------------------
11386 -- The given entity is to be set as the currently visible definition
11387 -- of its associated name (i.e. the Node_Id associated with its name).
11388 -- All we have to do is to get the name from the identifier, and
11389 -- then set the associated Node_Id to point to the given entity.
11391 procedure Set_Current_Entity (E : Entity_Id) is
11393 Set_Name_Entity_Id (Chars (E), E);
11394 end Set_Current_Entity;
11396 ---------------------------
11397 -- Set_Debug_Info_Needed --
11398 ---------------------------
11400 procedure Set_Debug_Info_Needed (T : Entity_Id) is
11402 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
11403 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
11404 -- Used to set debug info in a related node if not set already
11406 --------------------------------------
11407 -- Set_Debug_Info_Needed_If_Not_Set --
11408 --------------------------------------
11410 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
11413 and then not Needs_Debug_Info (E)
11415 Set_Debug_Info_Needed (E);
11417 -- For a private type, indicate that the full view also needs
11418 -- debug information.
11421 and then Is_Private_Type (E)
11422 and then Present (Full_View (E))
11424 Set_Debug_Info_Needed (Full_View (E));
11427 end Set_Debug_Info_Needed_If_Not_Set;
11429 -- Start of processing for Set_Debug_Info_Needed
11432 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
11433 -- indicates that Debug_Info_Needed is never required for the entity.
11436 or else Debug_Info_Off (T)
11441 -- Set flag in entity itself. Note that we will go through the following
11442 -- circuitry even if the flag is already set on T. That's intentional,
11443 -- it makes sure that the flag will be set in subsidiary entities.
11445 Set_Needs_Debug_Info (T);
11447 -- Set flag on subsidiary entities if not set already
11449 if Is_Object (T) then
11450 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
11452 elsif Is_Type (T) then
11453 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
11455 if Is_Record_Type (T) then
11457 Ent : Entity_Id := First_Entity (T);
11459 while Present (Ent) loop
11460 Set_Debug_Info_Needed_If_Not_Set (Ent);
11465 -- For a class wide subtype, we also need debug information
11466 -- for the equivalent type.
11468 if Ekind (T) = E_Class_Wide_Subtype then
11469 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
11472 elsif Is_Array_Type (T) then
11473 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
11476 Indx : Node_Id := First_Index (T);
11478 while Present (Indx) loop
11479 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
11480 Indx := Next_Index (Indx);
11484 if Is_Packed (T) then
11485 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Type (T));
11488 elsif Is_Access_Type (T) then
11489 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
11491 elsif Is_Private_Type (T) then
11492 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
11494 elsif Is_Protected_Type (T) then
11495 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
11498 end Set_Debug_Info_Needed;
11500 ---------------------------------
11501 -- Set_Entity_With_Style_Check --
11502 ---------------------------------
11504 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
11505 Val_Actual : Entity_Id;
11509 Set_Entity (N, Val);
11512 and then not Suppress_Style_Checks (Val)
11513 and then not In_Instance
11515 if Nkind (N) = N_Identifier then
11517 elsif Nkind (N) = N_Expanded_Name then
11518 Nod := Selector_Name (N);
11523 -- A special situation arises for derived operations, where we want
11524 -- to do the check against the parent (since the Sloc of the derived
11525 -- operation points to the derived type declaration itself).
11528 while not Comes_From_Source (Val_Actual)
11529 and then Nkind (Val_Actual) in N_Entity
11530 and then (Ekind (Val_Actual) = E_Enumeration_Literal
11531 or else Is_Subprogram (Val_Actual)
11532 or else Is_Generic_Subprogram (Val_Actual))
11533 and then Present (Alias (Val_Actual))
11535 Val_Actual := Alias (Val_Actual);
11538 -- Renaming declarations for generic actuals do not come from source,
11539 -- and have a different name from that of the entity they rename, so
11540 -- there is no style check to perform here.
11542 if Chars (Nod) = Chars (Val_Actual) then
11543 Style.Check_Identifier (Nod, Val_Actual);
11547 Set_Entity (N, Val);
11548 end Set_Entity_With_Style_Check;
11550 ------------------------
11551 -- Set_Name_Entity_Id --
11552 ------------------------
11554 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
11556 Set_Name_Table_Info (Id, Int (Val));
11557 end Set_Name_Entity_Id;
11559 ---------------------
11560 -- Set_Next_Actual --
11561 ---------------------
11563 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
11565 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
11566 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
11568 end Set_Next_Actual;
11570 ----------------------------------
11571 -- Set_Optimize_Alignment_Flags --
11572 ----------------------------------
11574 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
11576 if Optimize_Alignment = 'S' then
11577 Set_Optimize_Alignment_Space (E);
11578 elsif Optimize_Alignment = 'T' then
11579 Set_Optimize_Alignment_Time (E);
11581 end Set_Optimize_Alignment_Flags;
11583 -----------------------
11584 -- Set_Public_Status --
11585 -----------------------
11587 procedure Set_Public_Status (Id : Entity_Id) is
11588 S : constant Entity_Id := Current_Scope;
11590 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
11591 -- Determines if E is defined within handled statement sequence or
11592 -- an if statement, returns True if so, False otherwise.
11594 ----------------------
11595 -- Within_HSS_Or_If --
11596 ----------------------
11598 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
11601 N := Declaration_Node (E);
11608 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
11614 end Within_HSS_Or_If;
11616 -- Start of processing for Set_Public_Status
11619 -- Everything in the scope of Standard is public
11621 if S = Standard_Standard then
11622 Set_Is_Public (Id);
11624 -- Entity is definitely not public if enclosing scope is not public
11626 elsif not Is_Public (S) then
11629 -- An object or function declaration that occurs in a handled sequence
11630 -- of statements or within an if statement is the declaration for a
11631 -- temporary object or local subprogram generated by the expander. It
11632 -- never needs to be made public and furthermore, making it public can
11633 -- cause back end problems.
11635 elsif Nkind_In (Parent (Id), N_Object_Declaration,
11636 N_Function_Specification)
11637 and then Within_HSS_Or_If (Id)
11641 -- Entities in public packages or records are public
11643 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
11644 Set_Is_Public (Id);
11646 -- The bounds of an entry family declaration can generate object
11647 -- declarations that are visible to the back-end, e.g. in the
11648 -- the declaration of a composite type that contains tasks.
11650 elsif Is_Concurrent_Type (S)
11651 and then not Has_Completion (S)
11652 and then Nkind (Parent (Id)) = N_Object_Declaration
11654 Set_Is_Public (Id);
11656 end Set_Public_Status;
11658 -----------------------------
11659 -- Set_Referenced_Modified --
11660 -----------------------------
11662 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
11666 -- Deal with indexed or selected component where prefix is modified
11668 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
11669 Pref := Prefix (N);
11671 -- If prefix is access type, then it is the designated object that is
11672 -- being modified, which means we have no entity to set the flag on.
11674 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
11677 -- Otherwise chase the prefix
11680 Set_Referenced_Modified (Pref, Out_Param);
11683 -- Otherwise see if we have an entity name (only other case to process)
11685 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
11686 Set_Referenced_As_LHS (Entity (N), not Out_Param);
11687 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
11689 end Set_Referenced_Modified;
11691 ----------------------------
11692 -- Set_Scope_Is_Transient --
11693 ----------------------------
11695 procedure Set_Scope_Is_Transient (V : Boolean := True) is
11697 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
11698 end Set_Scope_Is_Transient;
11700 -------------------
11701 -- Set_Size_Info --
11702 -------------------
11704 procedure Set_Size_Info (T1, T2 : Entity_Id) is
11706 -- We copy Esize, but not RM_Size, since in general RM_Size is
11707 -- subtype specific and does not get inherited by all subtypes.
11709 Set_Esize (T1, Esize (T2));
11710 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
11712 if Is_Discrete_Or_Fixed_Point_Type (T1)
11714 Is_Discrete_Or_Fixed_Point_Type (T2)
11716 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
11719 Set_Alignment (T1, Alignment (T2));
11722 --------------------
11723 -- Static_Boolean --
11724 --------------------
11726 function Static_Boolean (N : Node_Id) return Uint is
11728 Analyze_And_Resolve (N, Standard_Boolean);
11731 or else Error_Posted (N)
11732 or else Etype (N) = Any_Type
11737 if Is_Static_Expression (N) then
11738 if not Raises_Constraint_Error (N) then
11739 return Expr_Value (N);
11744 elsif Etype (N) = Any_Type then
11748 Flag_Non_Static_Expr
11749 ("static boolean expression required here", N);
11752 end Static_Boolean;
11754 --------------------
11755 -- Static_Integer --
11756 --------------------
11758 function Static_Integer (N : Node_Id) return Uint is
11760 Analyze_And_Resolve (N, Any_Integer);
11763 or else Error_Posted (N)
11764 or else Etype (N) = Any_Type
11769 if Is_Static_Expression (N) then
11770 if not Raises_Constraint_Error (N) then
11771 return Expr_Value (N);
11776 elsif Etype (N) = Any_Type then
11780 Flag_Non_Static_Expr
11781 ("static integer expression required here", N);
11784 end Static_Integer;
11786 --------------------------
11787 -- Statically_Different --
11788 --------------------------
11790 function Statically_Different (E1, E2 : Node_Id) return Boolean is
11791 R1 : constant Node_Id := Get_Referenced_Object (E1);
11792 R2 : constant Node_Id := Get_Referenced_Object (E2);
11794 return Is_Entity_Name (R1)
11795 and then Is_Entity_Name (R2)
11796 and then Entity (R1) /= Entity (R2)
11797 and then not Is_Formal (Entity (R1))
11798 and then not Is_Formal (Entity (R2));
11799 end Statically_Different;
11801 -----------------------------
11802 -- Subprogram_Access_Level --
11803 -----------------------------
11805 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
11807 if Present (Alias (Subp)) then
11808 return Subprogram_Access_Level (Alias (Subp));
11810 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
11812 end Subprogram_Access_Level;
11818 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
11820 if Debug_Flag_W then
11821 for J in 0 .. Scope_Stack.Last loop
11826 Write_Name (Chars (E));
11827 Write_Str (" from ");
11828 Write_Location (Sloc (N));
11833 -----------------------
11834 -- Transfer_Entities --
11835 -----------------------
11837 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
11838 Ent : Entity_Id := First_Entity (From);
11845 if (Last_Entity (To)) = Empty then
11846 Set_First_Entity (To, Ent);
11848 Set_Next_Entity (Last_Entity (To), Ent);
11851 Set_Last_Entity (To, Last_Entity (From));
11853 while Present (Ent) loop
11854 Set_Scope (Ent, To);
11856 if not Is_Public (Ent) then
11857 Set_Public_Status (Ent);
11860 and then Ekind (Ent) = E_Record_Subtype
11863 -- The components of the propagated Itype must be public
11869 Comp := First_Entity (Ent);
11870 while Present (Comp) loop
11871 Set_Is_Public (Comp);
11872 Next_Entity (Comp);
11881 Set_First_Entity (From, Empty);
11882 Set_Last_Entity (From, Empty);
11883 end Transfer_Entities;
11885 -----------------------
11886 -- Type_Access_Level --
11887 -----------------------
11889 function Type_Access_Level (Typ : Entity_Id) return Uint is
11893 Btyp := Base_Type (Typ);
11895 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
11896 -- simply use the level where the type is declared. This is true for
11897 -- stand-alone object declarations, and for anonymous access types
11898 -- associated with components the level is the same as that of the
11899 -- enclosing composite type. However, special treatment is needed for
11900 -- the cases of access parameters, return objects of an anonymous access
11901 -- type, and, in Ada 95, access discriminants of limited types.
11903 if Ekind (Btyp) in Access_Kind then
11904 if Ekind (Btyp) = E_Anonymous_Access_Type then
11906 -- If the type is a nonlocal anonymous access type (such as for
11907 -- an access parameter) we treat it as being declared at the
11908 -- library level to ensure that names such as X.all'access don't
11909 -- fail static accessibility checks.
11911 if not Is_Local_Anonymous_Access (Typ) then
11912 return Scope_Depth (Standard_Standard);
11914 -- If this is a return object, the accessibility level is that of
11915 -- the result subtype of the enclosing function. The test here is
11916 -- little complicated, because we have to account for extended
11917 -- return statements that have been rewritten as blocks, in which
11918 -- case we have to find and the Is_Return_Object attribute of the
11919 -- itype's associated object. It would be nice to find a way to
11920 -- simplify this test, but it doesn't seem worthwhile to add a new
11921 -- flag just for purposes of this test. ???
11923 elsif Ekind (Scope (Btyp)) = E_Return_Statement
11926 and then Nkind (Associated_Node_For_Itype (Btyp)) =
11927 N_Object_Declaration
11928 and then Is_Return_Object
11929 (Defining_Identifier
11930 (Associated_Node_For_Itype (Btyp))))
11936 Scop := Scope (Scope (Btyp));
11937 while Present (Scop) loop
11938 exit when Ekind (Scop) = E_Function;
11939 Scop := Scope (Scop);
11942 -- Treat the return object's type as having the level of the
11943 -- function's result subtype (as per RM05-6.5(5.3/2)).
11945 return Type_Access_Level (Etype (Scop));
11950 Btyp := Root_Type (Btyp);
11952 -- The accessibility level of anonymous access types associated with
11953 -- discriminants is that of the current instance of the type, and
11954 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
11956 -- AI-402: access discriminants have accessibility based on the
11957 -- object rather than the type in Ada 2005, so the above paragraph
11960 -- ??? Needs completion with rules from AI-416
11962 if Ada_Version <= Ada_95
11963 and then Ekind (Typ) = E_Anonymous_Access_Type
11964 and then Present (Associated_Node_For_Itype (Typ))
11965 and then Nkind (Associated_Node_For_Itype (Typ)) =
11966 N_Discriminant_Specification
11968 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
11972 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
11973 end Type_Access_Level;
11975 --------------------------
11976 -- Unit_Declaration_Node --
11977 --------------------------
11979 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
11980 N : Node_Id := Parent (Unit_Id);
11983 -- Predefined operators do not have a full function declaration
11985 if Ekind (Unit_Id) = E_Operator then
11989 -- Isn't there some better way to express the following ???
11991 while Nkind (N) /= N_Abstract_Subprogram_Declaration
11992 and then Nkind (N) /= N_Formal_Package_Declaration
11993 and then Nkind (N) /= N_Function_Instantiation
11994 and then Nkind (N) /= N_Generic_Package_Declaration
11995 and then Nkind (N) /= N_Generic_Subprogram_Declaration
11996 and then Nkind (N) /= N_Package_Declaration
11997 and then Nkind (N) /= N_Package_Body
11998 and then Nkind (N) /= N_Package_Instantiation
11999 and then Nkind (N) /= N_Package_Renaming_Declaration
12000 and then Nkind (N) /= N_Procedure_Instantiation
12001 and then Nkind (N) /= N_Protected_Body
12002 and then Nkind (N) /= N_Subprogram_Declaration
12003 and then Nkind (N) /= N_Subprogram_Body
12004 and then Nkind (N) /= N_Subprogram_Body_Stub
12005 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
12006 and then Nkind (N) /= N_Task_Body
12007 and then Nkind (N) /= N_Task_Type_Declaration
12008 and then Nkind (N) not in N_Formal_Subprogram_Declaration
12009 and then Nkind (N) not in N_Generic_Renaming_Declaration
12012 pragma Assert (Present (N));
12016 end Unit_Declaration_Node;
12018 ---------------------
12019 -- Unit_Is_Visible --
12020 ---------------------
12022 function Unit_Is_Visible (U : Entity_Id) return Boolean is
12023 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
12024 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
12026 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
12027 -- For a child unit, check whether unit appears in a with_clause
12030 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
12031 -- Scan the context clause of one compilation unit looking for a
12032 -- with_clause for the unit in question.
12034 ----------------------------
12035 -- Unit_In_Parent_Context --
12036 ----------------------------
12038 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
12040 if Unit_In_Context (Par_Unit) then
12043 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
12044 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
12049 end Unit_In_Parent_Context;
12051 ---------------------
12052 -- Unit_In_Context --
12053 ---------------------
12055 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
12059 Clause := First (Context_Items (Comp_Unit));
12060 while Present (Clause) loop
12061 if Nkind (Clause) = N_With_Clause then
12062 if Library_Unit (Clause) = U then
12065 -- The with_clause may denote a renaming of the unit we are
12066 -- looking for, eg. Text_IO which renames Ada.Text_IO.
12069 Renamed_Entity (Entity (Name (Clause))) =
12070 Defining_Entity (Unit (U))
12080 end Unit_In_Context;
12082 -- Start of processing for Unit_Is_Visible
12085 -- The currrent unit is directly visible.
12090 elsif Unit_In_Context (Curr) then
12093 -- If the current unit is a body, check the context of the spec.
12095 elsif Nkind (Unit (Curr)) = N_Package_Body
12097 (Nkind (Unit (Curr)) = N_Subprogram_Body
12098 and then not Acts_As_Spec (Unit (Curr)))
12100 if Unit_In_Context (Library_Unit (Curr)) then
12105 -- If the spec is a child unit, examine the parents.
12107 if Is_Child_Unit (Curr_Entity) then
12108 if Nkind (Unit (Curr)) in N_Unit_Body then
12110 Unit_In_Parent_Context
12111 (Parent_Spec (Unit (Library_Unit (Curr))));
12113 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
12119 end Unit_Is_Visible;
12121 ------------------------------
12122 -- Universal_Interpretation --
12123 ------------------------------
12125 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
12126 Index : Interp_Index;
12130 -- The argument may be a formal parameter of an operator or subprogram
12131 -- with multiple interpretations, or else an expression for an actual.
12133 if Nkind (Opnd) = N_Defining_Identifier
12134 or else not Is_Overloaded (Opnd)
12136 if Etype (Opnd) = Universal_Integer
12137 or else Etype (Opnd) = Universal_Real
12139 return Etype (Opnd);
12145 Get_First_Interp (Opnd, Index, It);
12146 while Present (It.Typ) loop
12147 if It.Typ = Universal_Integer
12148 or else It.Typ = Universal_Real
12153 Get_Next_Interp (Index, It);
12158 end Universal_Interpretation;
12164 function Unqualify (Expr : Node_Id) return Node_Id is
12166 -- Recurse to handle unlikely case of multiple levels of qualification
12168 if Nkind (Expr) = N_Qualified_Expression then
12169 return Unqualify (Expression (Expr));
12171 -- Normal case, not a qualified expression
12178 -----------------------
12179 -- Visible_Ancestors --
12180 -----------------------
12182 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
12188 pragma Assert (Is_Record_Type (Typ)
12189 and then Is_Tagged_Type (Typ));
12191 -- Collect all the parents and progenitors of Typ. If the full-view of
12192 -- private parents and progenitors is available then it is used to
12193 -- generate the list of visible ancestors; otherwise their partial
12194 -- view is added to the resulting list.
12199 Use_Full_View => True);
12203 Ifaces_List => List_2,
12204 Exclude_Parents => True,
12205 Use_Full_View => True);
12207 -- Join the two lists. Avoid duplications because an interface may
12208 -- simultaneously be parent and progenitor of a type.
12210 Elmt := First_Elmt (List_2);
12211 while Present (Elmt) loop
12212 Append_Unique_Elmt (Node (Elmt), List_1);
12217 end Visible_Ancestors;
12219 ----------------------
12220 -- Within_Init_Proc --
12221 ----------------------
12223 function Within_Init_Proc return Boolean is
12227 S := Current_Scope;
12228 while not Is_Overloadable (S) loop
12229 if S = Standard_Standard then
12236 return Is_Init_Proc (S);
12237 end Within_Init_Proc;
12243 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
12244 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
12245 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
12247 function Has_One_Matching_Field return Boolean;
12248 -- Determines if Expec_Type is a record type with a single component or
12249 -- discriminant whose type matches the found type or is one dimensional
12250 -- array whose component type matches the found type.
12252 ----------------------------
12253 -- Has_One_Matching_Field --
12254 ----------------------------
12256 function Has_One_Matching_Field return Boolean is
12260 if Is_Array_Type (Expec_Type)
12261 and then Number_Dimensions (Expec_Type) = 1
12263 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
12267 elsif not Is_Record_Type (Expec_Type) then
12271 E := First_Entity (Expec_Type);
12276 elsif (Ekind (E) /= E_Discriminant
12277 and then Ekind (E) /= E_Component)
12278 or else (Chars (E) = Name_uTag
12279 or else Chars (E) = Name_uParent)
12288 if not Covers (Etype (E), Found_Type) then
12291 elsif Present (Next_Entity (E)) then
12298 end Has_One_Matching_Field;
12300 -- Start of processing for Wrong_Type
12303 -- Don't output message if either type is Any_Type, or if a message
12304 -- has already been posted for this node. We need to do the latter
12305 -- check explicitly (it is ordinarily done in Errout), because we
12306 -- are using ! to force the output of the error messages.
12308 if Expec_Type = Any_Type
12309 or else Found_Type = Any_Type
12310 or else Error_Posted (Expr)
12314 -- In an instance, there is an ongoing problem with completion of
12315 -- type derived from private types. Their structure is what Gigi
12316 -- expects, but the Etype is the parent type rather than the
12317 -- derived private type itself. Do not flag error in this case. The
12318 -- private completion is an entity without a parent, like an Itype.
12319 -- Similarly, full and partial views may be incorrect in the instance.
12320 -- There is no simple way to insure that it is consistent ???
12322 elsif In_Instance then
12323 if Etype (Etype (Expr)) = Etype (Expected_Type)
12325 (Has_Private_Declaration (Expected_Type)
12326 or else Has_Private_Declaration (Etype (Expr)))
12327 and then No (Parent (Expected_Type))
12333 -- An interesting special check. If the expression is parenthesized
12334 -- and its type corresponds to the type of the sole component of the
12335 -- expected record type, or to the component type of the expected one
12336 -- dimensional array type, then assume we have a bad aggregate attempt.
12338 if Nkind (Expr) in N_Subexpr
12339 and then Paren_Count (Expr) /= 0
12340 and then Has_One_Matching_Field
12342 Error_Msg_N ("positional aggregate cannot have one component", Expr);
12344 -- Another special check, if we are looking for a pool-specific access
12345 -- type and we found an E_Access_Attribute_Type, then we have the case
12346 -- of an Access attribute being used in a context which needs a pool-
12347 -- specific type, which is never allowed. The one extra check we make
12348 -- is that the expected designated type covers the Found_Type.
12350 elsif Is_Access_Type (Expec_Type)
12351 and then Ekind (Found_Type) = E_Access_Attribute_Type
12352 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
12353 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
12355 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
12357 Error_Msg_N -- CODEFIX
12358 ("result must be general access type!", Expr);
12359 Error_Msg_NE -- CODEFIX
12360 ("add ALL to }!", Expr, Expec_Type);
12362 -- Another special check, if the expected type is an integer type,
12363 -- but the expression is of type System.Address, and the parent is
12364 -- an addition or subtraction operation whose left operand is the
12365 -- expression in question and whose right operand is of an integral
12366 -- type, then this is an attempt at address arithmetic, so give
12367 -- appropriate message.
12369 elsif Is_Integer_Type (Expec_Type)
12370 and then Is_RTE (Found_Type, RE_Address)
12371 and then (Nkind (Parent (Expr)) = N_Op_Add
12373 Nkind (Parent (Expr)) = N_Op_Subtract)
12374 and then Expr = Left_Opnd (Parent (Expr))
12375 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
12378 ("address arithmetic not predefined in package System",
12381 ("\possible missing with/use of System.Storage_Elements",
12385 -- If the expected type is an anonymous access type, as for access
12386 -- parameters and discriminants, the error is on the designated types.
12388 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
12389 if Comes_From_Source (Expec_Type) then
12390 Error_Msg_NE ("expected}!", Expr, Expec_Type);
12393 ("expected an access type with designated}",
12394 Expr, Designated_Type (Expec_Type));
12397 if Is_Access_Type (Found_Type)
12398 and then not Comes_From_Source (Found_Type)
12401 ("\\found an access type with designated}!",
12402 Expr, Designated_Type (Found_Type));
12404 if From_With_Type (Found_Type) then
12405 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
12406 Error_Msg_Qual_Level := 99;
12407 Error_Msg_NE -- CODEFIX
12408 ("\\missing `WITH &;", Expr, Scope (Found_Type));
12409 Error_Msg_Qual_Level := 0;
12411 Error_Msg_NE ("found}!", Expr, Found_Type);
12415 -- Normal case of one type found, some other type expected
12418 -- If the names of the two types are the same, see if some number
12419 -- of levels of qualification will help. Don't try more than three
12420 -- levels, and if we get to standard, it's no use (and probably
12421 -- represents an error in the compiler) Also do not bother with
12422 -- internal scope names.
12425 Expec_Scope : Entity_Id;
12426 Found_Scope : Entity_Id;
12429 Expec_Scope := Expec_Type;
12430 Found_Scope := Found_Type;
12432 for Levels in Int range 0 .. 3 loop
12433 if Chars (Expec_Scope) /= Chars (Found_Scope) then
12434 Error_Msg_Qual_Level := Levels;
12438 Expec_Scope := Scope (Expec_Scope);
12439 Found_Scope := Scope (Found_Scope);
12441 exit when Expec_Scope = Standard_Standard
12442 or else Found_Scope = Standard_Standard
12443 or else not Comes_From_Source (Expec_Scope)
12444 or else not Comes_From_Source (Found_Scope);
12448 if Is_Record_Type (Expec_Type)
12449 and then Present (Corresponding_Remote_Type (Expec_Type))
12451 Error_Msg_NE ("expected}!", Expr,
12452 Corresponding_Remote_Type (Expec_Type));
12454 Error_Msg_NE ("expected}!", Expr, Expec_Type);
12457 if Is_Entity_Name (Expr)
12458 and then Is_Package_Or_Generic_Package (Entity (Expr))
12460 Error_Msg_N ("\\found package name!", Expr);
12462 elsif Is_Entity_Name (Expr)
12464 (Ekind (Entity (Expr)) = E_Procedure
12466 Ekind (Entity (Expr)) = E_Generic_Procedure)
12468 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
12470 ("found procedure name, possibly missing Access attribute!",
12474 ("\\found procedure name instead of function!", Expr);
12477 elsif Nkind (Expr) = N_Function_Call
12478 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
12479 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
12480 and then No (Parameter_Associations (Expr))
12483 ("found function name, possibly missing Access attribute!",
12486 -- Catch common error: a prefix or infix operator which is not
12487 -- directly visible because the type isn't.
12489 elsif Nkind (Expr) in N_Op
12490 and then Is_Overloaded (Expr)
12491 and then not Is_Immediately_Visible (Expec_Type)
12492 and then not Is_Potentially_Use_Visible (Expec_Type)
12493 and then not In_Use (Expec_Type)
12494 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
12497 ("operator of the type is not directly visible!", Expr);
12499 elsif Ekind (Found_Type) = E_Void
12500 and then Present (Parent (Found_Type))
12501 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
12503 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
12506 Error_Msg_NE ("\\found}!", Expr, Found_Type);
12509 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
12510 -- of the same modular type, and (M1 and M2) = 0 was intended.
12512 if Expec_Type = Standard_Boolean
12513 and then Is_Modular_Integer_Type (Found_Type)
12514 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
12515 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
12518 Op : constant Node_Id := Right_Opnd (Parent (Expr));
12519 L : constant Node_Id := Left_Opnd (Op);
12520 R : constant Node_Id := Right_Opnd (Op);
12522 -- The case for the message is when the left operand of the
12523 -- comparison is the same modular type, or when it is an
12524 -- integer literal (or other universal integer expression),
12525 -- which would have been typed as the modular type if the
12526 -- parens had been there.
12528 if (Etype (L) = Found_Type
12530 Etype (L) = Universal_Integer)
12531 and then Is_Integer_Type (Etype (R))
12534 ("\\possible missing parens for modular operation", Expr);
12539 -- Reset error message qualification indication
12541 Error_Msg_Qual_Level := 0;