1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, 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 Rtsfind; use Rtsfind;
44 with Scans; use Scans;
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;
66 package body Sem_Util is
68 ----------------------------------------
69 -- Global_Variables for New_Copy_Tree --
70 ----------------------------------------
72 -- These global variables are used by New_Copy_Tree. See description
73 -- of the body of this subprogram for details. Global variables can be
74 -- safely used by New_Copy_Tree, since there is no case of a recursive
75 -- call from the processing inside New_Copy_Tree.
77 NCT_Hash_Threshhold : constant := 20;
78 -- If there are more than this number of pairs of entries in the
79 -- map, then Hash_Tables_Used will be set, and the hash tables will
80 -- be initialized and used for the searches.
82 NCT_Hash_Tables_Used : Boolean := False;
83 -- Set to True if hash tables are in use
85 NCT_Table_Entries : Nat;
86 -- Count entries in table to see if threshhold is reached
88 NCT_Hash_Table_Setup : Boolean := False;
89 -- Set to True if hash table contains data. We set this True if we
90 -- setup the hash table with data, and leave it set permanently
91 -- from then on, this is a signal that second and subsequent users
92 -- of the hash table must clear the old entries before reuse.
94 subtype NCT_Header_Num is Int range 0 .. 511;
95 -- Defines range of headers in hash tables (512 headers)
97 -----------------------------------
98 -- Order dependence : AI05-0144 --
99 -----------------------------------
101 -- Each actual in a call is entered into the table below. A flag
102 -- indicates whether the corresponding formal is out or in out.
103 -- Each top-level call (procedure call, condition, assignment)
104 -- examines all the actuals for a possible order dependence.
105 -- The table is reset after each such check.
107 type Actual_Name is record
109 Is_Writable : Boolean;
112 package Actuals_In_Call is new Table.Table (
113 Table_Component_Type => Actual_Name,
114 Table_Index_Type => Int,
115 Table_Low_Bound => 0,
117 Table_Increment => 10,
118 Table_Name => "Actuals");
120 procedure Save_Actual (N : Node_Id; Writable : Boolean := False) is
122 if Is_Entity_Name (N)
124 N_Indexed_Component, N_Selected_Component, N_Slice)
125 or else (Nkind (N) = N_Attribute_Reference
126 and then Attribute_Name (N) = Name_Access)
129 -- We are only interested in in out parameters of inner calls.
132 or else Nkind (Parent (N)) = N_Function_Call
133 or else Nkind (Parent (N)) in N_Op
135 Actuals_In_Call.Increment_Last;
136 Actuals_In_Call.Table (Actuals_In_Call.Last) := (N, Writable);
141 procedure Check_Order_Dependence is
142 Act1, Act2 : Node_Id;
144 for J in 0 .. Actuals_In_Call.Last loop
146 if Actuals_In_Call.Table (J).Is_Writable then
147 Act1 := Actuals_In_Call.Table (J).Act;
149 if Nkind (Act1) = N_Attribute_Reference then
150 Act1 := Prefix (Act1);
153 for K in 0 .. Actuals_In_Call.Last loop
155 Act2 := Actuals_In_Call.Table (K).Act;
156 if Nkind (Act2) = N_Attribute_Reference then
157 Act2 := Prefix (Act2);
160 if Actuals_In_Call.Table (K).Is_Writable
166 elsif Denotes_Same_Object (Act1, Act2)
169 Error_Msg_N ("?,mighty suspicious!!!", Act1);
176 Actuals_In_Call.Set_Last (0);
177 end Check_Order_Dependence;
179 -----------------------
180 -- Local Subprograms --
181 -----------------------
183 function Build_Component_Subtype
186 T : Entity_Id) return Node_Id;
187 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
188 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
189 -- Loc is the source location, T is the original subtype.
191 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
192 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
193 -- with discriminants whose default values are static, examine only the
194 -- components in the selected variant to determine whether all of them
197 function Has_Null_Extension (T : Entity_Id) return Boolean;
198 -- T is a derived tagged type. Check whether the type extension is null.
199 -- If the parent type is fully initialized, T can be treated as such.
201 ------------------------------
202 -- Abstract_Interface_List --
203 ------------------------------
205 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
209 if Is_Concurrent_Type (Typ) then
211 -- If we are dealing with a synchronized subtype, go to the base
212 -- type, whose declaration has the interface list.
214 -- Shouldn't this be Declaration_Node???
216 Nod := Parent (Base_Type (Typ));
218 if Nkind (Nod) = N_Full_Type_Declaration then
222 elsif Ekind (Typ) = E_Record_Type_With_Private then
223 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
224 Nod := Type_Definition (Parent (Typ));
226 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
227 if Present (Full_View (Typ)) then
228 Nod := Type_Definition (Parent (Full_View (Typ)));
230 -- If the full-view is not available we cannot do anything else
231 -- here (the source has errors).
237 -- Support for generic formals with interfaces is still missing ???
239 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
244 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
248 elsif Ekind (Typ) = E_Record_Subtype then
249 Nod := Type_Definition (Parent (Etype (Typ)));
251 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
253 -- Recurse, because parent may still be a private extension. Also
254 -- note that the full view of the subtype or the full view of its
255 -- base type may (both) be unavailable.
257 return Abstract_Interface_List (Etype (Typ));
259 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
260 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
261 Nod := Formal_Type_Definition (Parent (Typ));
263 Nod := Type_Definition (Parent (Typ));
267 return Interface_List (Nod);
268 end Abstract_Interface_List;
270 --------------------------------
271 -- Add_Access_Type_To_Process --
272 --------------------------------
274 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
278 Ensure_Freeze_Node (E);
279 L := Access_Types_To_Process (Freeze_Node (E));
283 Set_Access_Types_To_Process (Freeze_Node (E), L);
287 end Add_Access_Type_To_Process;
289 ----------------------------
290 -- Add_Global_Declaration --
291 ----------------------------
293 procedure Add_Global_Declaration (N : Node_Id) is
294 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
297 if No (Declarations (Aux_Node)) then
298 Set_Declarations (Aux_Node, New_List);
301 Append_To (Declarations (Aux_Node), N);
303 end Add_Global_Declaration;
305 -----------------------
306 -- Alignment_In_Bits --
307 -----------------------
309 function Alignment_In_Bits (E : Entity_Id) return Uint is
311 return Alignment (E) * System_Storage_Unit;
312 end Alignment_In_Bits;
314 -----------------------------------------
315 -- Apply_Compile_Time_Constraint_Error --
316 -----------------------------------------
318 procedure Apply_Compile_Time_Constraint_Error
321 Reason : RT_Exception_Code;
322 Ent : Entity_Id := Empty;
323 Typ : Entity_Id := Empty;
324 Loc : Source_Ptr := No_Location;
325 Rep : Boolean := True;
326 Warn : Boolean := False)
328 Stat : constant Boolean := Is_Static_Expression (N);
329 R_Stat : constant Node_Id :=
330 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
341 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
347 -- Now we replace the node by an N_Raise_Constraint_Error node
348 -- This does not need reanalyzing, so set it as analyzed now.
351 Set_Analyzed (N, True);
354 Set_Raises_Constraint_Error (N);
356 -- Now deal with possible local raise handling
358 Possible_Local_Raise (N, Standard_Constraint_Error);
360 -- If the original expression was marked as static, the result is
361 -- still marked as static, but the Raises_Constraint_Error flag is
362 -- always set so that further static evaluation is not attempted.
365 Set_Is_Static_Expression (N);
367 end Apply_Compile_Time_Constraint_Error;
369 --------------------------
370 -- Build_Actual_Subtype --
371 --------------------------
373 function Build_Actual_Subtype
375 N : Node_Or_Entity_Id) return Node_Id
378 -- Normally Sloc (N), but may point to corresponding body in some cases
380 Constraints : List_Id;
386 Disc_Type : Entity_Id;
392 if Nkind (N) = N_Defining_Identifier then
393 Obj := New_Reference_To (N, Loc);
395 -- If this is a formal parameter of a subprogram declaration, and
396 -- we are compiling the body, we want the declaration for the
397 -- actual subtype to carry the source position of the body, to
398 -- prevent anomalies in gdb when stepping through the code.
400 if Is_Formal (N) then
402 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
404 if Nkind (Decl) = N_Subprogram_Declaration
405 and then Present (Corresponding_Body (Decl))
407 Loc := Sloc (Corresponding_Body (Decl));
416 if Is_Array_Type (T) then
417 Constraints := New_List;
418 for J in 1 .. Number_Dimensions (T) loop
420 -- Build an array subtype declaration with the nominal subtype and
421 -- the bounds of the actual. Add the declaration in front of the
422 -- local declarations for the subprogram, for analysis before any
423 -- reference to the formal in the body.
426 Make_Attribute_Reference (Loc,
428 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
429 Attribute_Name => Name_First,
430 Expressions => New_List (
431 Make_Integer_Literal (Loc, J)));
434 Make_Attribute_Reference (Loc,
436 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
437 Attribute_Name => Name_Last,
438 Expressions => New_List (
439 Make_Integer_Literal (Loc, J)));
441 Append (Make_Range (Loc, Lo, Hi), Constraints);
444 -- If the type has unknown discriminants there is no constrained
445 -- subtype to build. This is never called for a formal or for a
446 -- lhs, so returning the type is ok ???
448 elsif Has_Unknown_Discriminants (T) then
452 Constraints := New_List;
454 -- Type T is a generic derived type, inherit the discriminants from
457 if Is_Private_Type (T)
458 and then No (Full_View (T))
460 -- T was flagged as an error if it was declared as a formal
461 -- derived type with known discriminants. In this case there
462 -- is no need to look at the parent type since T already carries
463 -- its own discriminants.
465 and then not Error_Posted (T)
467 Disc_Type := Etype (Base_Type (T));
472 Discr := First_Discriminant (Disc_Type);
473 while Present (Discr) loop
474 Append_To (Constraints,
475 Make_Selected_Component (Loc,
477 Duplicate_Subexpr_No_Checks (Obj),
478 Selector_Name => New_Occurrence_Of (Discr, Loc)));
479 Next_Discriminant (Discr);
483 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
484 Set_Is_Internal (Subt);
487 Make_Subtype_Declaration (Loc,
488 Defining_Identifier => Subt,
489 Subtype_Indication =>
490 Make_Subtype_Indication (Loc,
491 Subtype_Mark => New_Reference_To (T, Loc),
493 Make_Index_Or_Discriminant_Constraint (Loc,
494 Constraints => Constraints)));
496 Mark_Rewrite_Insertion (Decl);
498 end Build_Actual_Subtype;
500 ---------------------------------------
501 -- Build_Actual_Subtype_Of_Component --
502 ---------------------------------------
504 function Build_Actual_Subtype_Of_Component
506 N : Node_Id) return Node_Id
508 Loc : constant Source_Ptr := Sloc (N);
509 P : constant Node_Id := Prefix (N);
512 Indx_Type : Entity_Id;
514 Deaccessed_T : Entity_Id;
515 -- This is either a copy of T, or if T is an access type, then it is
516 -- the directly designated type of this access type.
518 function Build_Actual_Array_Constraint return List_Id;
519 -- If one or more of the bounds of the component depends on
520 -- discriminants, build actual constraint using the discriminants
523 function Build_Actual_Record_Constraint return List_Id;
524 -- Similar to previous one, for discriminated components constrained
525 -- by the discriminant of the enclosing object.
527 -----------------------------------
528 -- Build_Actual_Array_Constraint --
529 -----------------------------------
531 function Build_Actual_Array_Constraint return List_Id is
532 Constraints : constant List_Id := New_List;
540 Indx := First_Index (Deaccessed_T);
541 while Present (Indx) loop
542 Old_Lo := Type_Low_Bound (Etype (Indx));
543 Old_Hi := Type_High_Bound (Etype (Indx));
545 if Denotes_Discriminant (Old_Lo) then
547 Make_Selected_Component (Loc,
548 Prefix => New_Copy_Tree (P),
549 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
552 Lo := New_Copy_Tree (Old_Lo);
554 -- The new bound will be reanalyzed in the enclosing
555 -- declaration. For literal bounds that come from a type
556 -- declaration, the type of the context must be imposed, so
557 -- insure that analysis will take place. For non-universal
558 -- types this is not strictly necessary.
560 Set_Analyzed (Lo, False);
563 if Denotes_Discriminant (Old_Hi) then
565 Make_Selected_Component (Loc,
566 Prefix => New_Copy_Tree (P),
567 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
570 Hi := New_Copy_Tree (Old_Hi);
571 Set_Analyzed (Hi, False);
574 Append (Make_Range (Loc, Lo, Hi), Constraints);
579 end Build_Actual_Array_Constraint;
581 ------------------------------------
582 -- Build_Actual_Record_Constraint --
583 ------------------------------------
585 function Build_Actual_Record_Constraint return List_Id is
586 Constraints : constant List_Id := New_List;
591 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
592 while Present (D) loop
593 if Denotes_Discriminant (Node (D)) then
594 D_Val := Make_Selected_Component (Loc,
595 Prefix => New_Copy_Tree (P),
596 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
599 D_Val := New_Copy_Tree (Node (D));
602 Append (D_Val, Constraints);
607 end Build_Actual_Record_Constraint;
609 -- Start of processing for Build_Actual_Subtype_Of_Component
612 -- Why the test for Spec_Expression mode here???
614 if In_Spec_Expression then
617 -- More comments for the rest of this body would be good ???
619 elsif Nkind (N) = N_Explicit_Dereference then
620 if Is_Composite_Type (T)
621 and then not Is_Constrained (T)
622 and then not (Is_Class_Wide_Type (T)
623 and then Is_Constrained (Root_Type (T)))
624 and then not Has_Unknown_Discriminants (T)
626 -- If the type of the dereference is already constrained, it is an
629 if Is_Array_Type (Etype (N))
630 and then Is_Constrained (Etype (N))
634 Remove_Side_Effects (P);
635 return Build_Actual_Subtype (T, N);
642 if Ekind (T) = E_Access_Subtype then
643 Deaccessed_T := Designated_Type (T);
648 if Ekind (Deaccessed_T) = E_Array_Subtype then
649 Id := First_Index (Deaccessed_T);
650 while Present (Id) loop
651 Indx_Type := Underlying_Type (Etype (Id));
653 if Denotes_Discriminant (Type_Low_Bound (Indx_Type))
655 Denotes_Discriminant (Type_High_Bound (Indx_Type))
657 Remove_Side_Effects (P);
659 Build_Component_Subtype
660 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
666 elsif Is_Composite_Type (Deaccessed_T)
667 and then Has_Discriminants (Deaccessed_T)
668 and then not Has_Unknown_Discriminants (Deaccessed_T)
670 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
671 while Present (D) loop
672 if Denotes_Discriminant (Node (D)) then
673 Remove_Side_Effects (P);
675 Build_Component_Subtype (
676 Build_Actual_Record_Constraint, Loc, Base_Type (T));
683 -- If none of the above, the actual and nominal subtypes are the same
686 end Build_Actual_Subtype_Of_Component;
688 -----------------------------
689 -- Build_Component_Subtype --
690 -----------------------------
692 function Build_Component_Subtype
695 T : Entity_Id) return Node_Id
701 -- Unchecked_Union components do not require component subtypes
703 if Is_Unchecked_Union (T) then
707 Subt := Make_Temporary (Loc, 'S');
708 Set_Is_Internal (Subt);
711 Make_Subtype_Declaration (Loc,
712 Defining_Identifier => Subt,
713 Subtype_Indication =>
714 Make_Subtype_Indication (Loc,
715 Subtype_Mark => New_Reference_To (Base_Type (T), Loc),
717 Make_Index_Or_Discriminant_Constraint (Loc,
720 Mark_Rewrite_Insertion (Decl);
722 end Build_Component_Subtype;
724 ---------------------------
725 -- Build_Default_Subtype --
726 ---------------------------
728 function Build_Default_Subtype
730 N : Node_Id) return Entity_Id
732 Loc : constant Source_Ptr := Sloc (N);
736 if not Has_Discriminants (T) or else Is_Constrained (T) then
740 Disc := First_Discriminant (T);
742 if No (Discriminant_Default_Value (Disc)) then
747 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
748 Constraints : constant List_Id := New_List;
752 while Present (Disc) loop
753 Append_To (Constraints,
754 New_Copy_Tree (Discriminant_Default_Value (Disc)));
755 Next_Discriminant (Disc);
759 Make_Subtype_Declaration (Loc,
760 Defining_Identifier => Act,
761 Subtype_Indication =>
762 Make_Subtype_Indication (Loc,
763 Subtype_Mark => New_Occurrence_Of (T, Loc),
765 Make_Index_Or_Discriminant_Constraint (Loc,
766 Constraints => Constraints)));
768 Insert_Action (N, Decl);
772 end Build_Default_Subtype;
774 --------------------------------------------
775 -- Build_Discriminal_Subtype_Of_Component --
776 --------------------------------------------
778 function Build_Discriminal_Subtype_Of_Component
779 (T : Entity_Id) return Node_Id
781 Loc : constant Source_Ptr := Sloc (T);
785 function Build_Discriminal_Array_Constraint return List_Id;
786 -- If one or more of the bounds of the component depends on
787 -- discriminants, build actual constraint using the discriminants
790 function Build_Discriminal_Record_Constraint return List_Id;
791 -- Similar to previous one, for discriminated components constrained
792 -- by the discriminant of the enclosing object.
794 ----------------------------------------
795 -- Build_Discriminal_Array_Constraint --
796 ----------------------------------------
798 function Build_Discriminal_Array_Constraint return List_Id is
799 Constraints : constant List_Id := New_List;
807 Indx := First_Index (T);
808 while Present (Indx) loop
809 Old_Lo := Type_Low_Bound (Etype (Indx));
810 Old_Hi := Type_High_Bound (Etype (Indx));
812 if Denotes_Discriminant (Old_Lo) then
813 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
816 Lo := New_Copy_Tree (Old_Lo);
819 if Denotes_Discriminant (Old_Hi) then
820 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
823 Hi := New_Copy_Tree (Old_Hi);
826 Append (Make_Range (Loc, Lo, Hi), Constraints);
831 end Build_Discriminal_Array_Constraint;
833 -----------------------------------------
834 -- Build_Discriminal_Record_Constraint --
835 -----------------------------------------
837 function Build_Discriminal_Record_Constraint return List_Id is
838 Constraints : constant List_Id := New_List;
843 D := First_Elmt (Discriminant_Constraint (T));
844 while Present (D) loop
845 if Denotes_Discriminant (Node (D)) then
847 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
850 D_Val := New_Copy_Tree (Node (D));
853 Append (D_Val, Constraints);
858 end Build_Discriminal_Record_Constraint;
860 -- Start of processing for Build_Discriminal_Subtype_Of_Component
863 if Ekind (T) = E_Array_Subtype then
864 Id := First_Index (T);
865 while Present (Id) loop
866 if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) or else
867 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
869 return Build_Component_Subtype
870 (Build_Discriminal_Array_Constraint, Loc, T);
876 elsif Ekind (T) = E_Record_Subtype
877 and then Has_Discriminants (T)
878 and then not Has_Unknown_Discriminants (T)
880 D := First_Elmt (Discriminant_Constraint (T));
881 while Present (D) loop
882 if Denotes_Discriminant (Node (D)) then
883 return Build_Component_Subtype
884 (Build_Discriminal_Record_Constraint, Loc, T);
891 -- If none of the above, the actual and nominal subtypes are the same
894 end Build_Discriminal_Subtype_Of_Component;
896 ------------------------------
897 -- Build_Elaboration_Entity --
898 ------------------------------
900 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
901 Loc : constant Source_Ptr := Sloc (N);
903 Elab_Ent : Entity_Id;
905 procedure Set_Package_Name (Ent : Entity_Id);
906 -- Given an entity, sets the fully qualified name of the entity in
907 -- Name_Buffer, with components separated by double underscores. This
908 -- is a recursive routine that climbs the scope chain to Standard.
910 ----------------------
911 -- Set_Package_Name --
912 ----------------------
914 procedure Set_Package_Name (Ent : Entity_Id) is
916 if Scope (Ent) /= Standard_Standard then
917 Set_Package_Name (Scope (Ent));
920 Nam : constant String := Get_Name_String (Chars (Ent));
922 Name_Buffer (Name_Len + 1) := '_';
923 Name_Buffer (Name_Len + 2) := '_';
924 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
925 Name_Len := Name_Len + Nam'Length + 2;
929 Get_Name_String (Chars (Ent));
931 end Set_Package_Name;
933 -- Start of processing for Build_Elaboration_Entity
936 -- Ignore if already constructed
938 if Present (Elaboration_Entity (Spec_Id)) then
942 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
943 -- name with dots replaced by double underscore. We have to manually
944 -- construct this name, since it will be elaborated in the outer scope,
945 -- and thus will not have the unit name automatically prepended.
947 Set_Package_Name (Spec_Id);
951 Name_Buffer (Name_Len + 1) := '_';
952 Name_Buffer (Name_Len + 2) := 'E';
953 Name_Len := Name_Len + 2;
955 -- Create elaboration flag
958 Make_Defining_Identifier (Loc, Chars => Name_Find);
959 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
962 Make_Object_Declaration (Loc,
963 Defining_Identifier => Elab_Ent,
965 New_Occurrence_Of (Standard_Boolean, Loc),
967 New_Occurrence_Of (Standard_False, Loc));
969 Push_Scope (Standard_Standard);
970 Add_Global_Declaration (Decl);
973 -- Reset True_Constant indication, since we will indeed assign a value
974 -- to the variable in the binder main. We also kill the Current_Value
975 -- and Last_Assignment fields for the same reason.
977 Set_Is_True_Constant (Elab_Ent, False);
978 Set_Current_Value (Elab_Ent, Empty);
979 Set_Last_Assignment (Elab_Ent, Empty);
981 -- We do not want any further qualification of the name (if we did
982 -- not do this, we would pick up the name of the generic package
983 -- in the case of a library level generic instantiation).
985 Set_Has_Qualified_Name (Elab_Ent);
986 Set_Has_Fully_Qualified_Name (Elab_Ent);
987 end Build_Elaboration_Entity;
989 -----------------------------------
990 -- Cannot_Raise_Constraint_Error --
991 -----------------------------------
993 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
995 if Compile_Time_Known_Value (Expr) then
998 elsif Do_Range_Check (Expr) then
1001 elsif Raises_Constraint_Error (Expr) then
1005 case Nkind (Expr) is
1006 when N_Identifier =>
1009 when N_Expanded_Name =>
1012 when N_Selected_Component =>
1013 return not Do_Discriminant_Check (Expr);
1015 when N_Attribute_Reference =>
1016 if Do_Overflow_Check (Expr) then
1019 elsif No (Expressions (Expr)) then
1027 N := First (Expressions (Expr));
1028 while Present (N) loop
1029 if Cannot_Raise_Constraint_Error (N) then
1040 when N_Type_Conversion =>
1041 if Do_Overflow_Check (Expr)
1042 or else Do_Length_Check (Expr)
1043 or else Do_Tag_Check (Expr)
1048 Cannot_Raise_Constraint_Error (Expression (Expr));
1051 when N_Unchecked_Type_Conversion =>
1052 return Cannot_Raise_Constraint_Error (Expression (Expr));
1055 if Do_Overflow_Check (Expr) then
1059 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1066 if Do_Division_Check (Expr)
1067 or else Do_Overflow_Check (Expr)
1072 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1074 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1093 N_Op_Shift_Right_Arithmetic |
1097 if Do_Overflow_Check (Expr) then
1101 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1103 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1110 end Cannot_Raise_Constraint_Error;
1112 -----------------------------------------
1113 -- Check_Dynamically_Tagged_Expression --
1114 -----------------------------------------
1116 procedure Check_Dynamically_Tagged_Expression
1119 Related_Nod : Node_Id)
1122 pragma Assert (Is_Tagged_Type (Typ));
1124 -- In order to avoid spurious errors when analyzing the expanded code,
1125 -- this check is done only for nodes that come from source and for
1126 -- actuals of generic instantiations.
1128 if (Comes_From_Source (Related_Nod)
1129 or else In_Generic_Actual (Expr))
1130 and then (Is_Class_Wide_Type (Etype (Expr))
1131 or else Is_Dynamically_Tagged (Expr))
1132 and then Is_Tagged_Type (Typ)
1133 and then not Is_Class_Wide_Type (Typ)
1135 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
1137 end Check_Dynamically_Tagged_Expression;
1139 --------------------------
1140 -- Check_Fully_Declared --
1141 --------------------------
1143 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
1145 if Ekind (T) = E_Incomplete_Type then
1147 -- Ada 2005 (AI-50217): If the type is available through a limited
1148 -- with_clause, verify that its full view has been analyzed.
1150 if From_With_Type (T)
1151 and then Present (Non_Limited_View (T))
1152 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1154 -- The non-limited view is fully declared
1159 ("premature usage of incomplete}", N, First_Subtype (T));
1162 -- Need comments for these tests ???
1164 elsif Has_Private_Component (T)
1165 and then not Is_Generic_Type (Root_Type (T))
1166 and then not In_Spec_Expression
1168 -- Special case: if T is the anonymous type created for a single
1169 -- task or protected object, use the name of the source object.
1171 if Is_Concurrent_Type (T)
1172 and then not Comes_From_Source (T)
1173 and then Nkind (N) = N_Object_Declaration
1175 Error_Msg_NE ("type of& has incomplete component", N,
1176 Defining_Identifier (N));
1180 ("premature usage of incomplete}", N, First_Subtype (T));
1183 end Check_Fully_Declared;
1185 -------------------------
1186 -- Check_Nested_Access --
1187 -------------------------
1189 procedure Check_Nested_Access (Ent : Entity_Id) is
1190 Scop : constant Entity_Id := Current_Scope;
1191 Current_Subp : Entity_Id;
1192 Enclosing : Entity_Id;
1195 -- Currently only enabled for VM back-ends for efficiency, should we
1196 -- enable it more systematically ???
1198 -- Check for Is_Imported needs commenting below ???
1200 if VM_Target /= No_VM
1201 and then (Ekind (Ent) = E_Variable
1203 Ekind (Ent) = E_Constant
1205 Ekind (Ent) = E_Loop_Parameter)
1206 and then Scope (Ent) /= Empty
1207 and then not Is_Library_Level_Entity (Ent)
1208 and then not Is_Imported (Ent)
1210 if Is_Subprogram (Scop)
1211 or else Is_Generic_Subprogram (Scop)
1212 or else Is_Entry (Scop)
1214 Current_Subp := Scop;
1216 Current_Subp := Current_Subprogram;
1219 Enclosing := Enclosing_Subprogram (Ent);
1221 if Enclosing /= Empty
1222 and then Enclosing /= Current_Subp
1224 Set_Has_Up_Level_Access (Ent, True);
1227 end Check_Nested_Access;
1229 ------------------------------------------
1230 -- Check_Potentially_Blocking_Operation --
1231 ------------------------------------------
1233 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
1236 -- N is one of the potentially blocking operations listed in 9.5.1(8).
1237 -- When pragma Detect_Blocking is active, the run time will raise
1238 -- Program_Error. Here we only issue a warning, since we generally
1239 -- support the use of potentially blocking operations in the absence
1242 -- Indirect blocking through a subprogram call cannot be diagnosed
1243 -- statically without interprocedural analysis, so we do not attempt
1246 S := Scope (Current_Scope);
1247 while Present (S) and then S /= Standard_Standard loop
1248 if Is_Protected_Type (S) then
1250 ("potentially blocking operation in protected operation?", N);
1257 end Check_Potentially_Blocking_Operation;
1259 ------------------------------
1260 -- Check_Unprotected_Access --
1261 ------------------------------
1263 procedure Check_Unprotected_Access
1267 Cont_Encl_Typ : Entity_Id;
1268 Pref_Encl_Typ : Entity_Id;
1270 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
1271 -- Check whether Obj is a private component of a protected object.
1272 -- Return the protected type where the component resides, Empty
1275 function Is_Public_Operation return Boolean;
1276 -- Verify that the enclosing operation is callable from outside the
1277 -- protected object, to minimize false positives.
1279 ------------------------------
1280 -- Enclosing_Protected_Type --
1281 ------------------------------
1283 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
1285 if Is_Entity_Name (Obj) then
1287 Ent : Entity_Id := Entity (Obj);
1290 -- The object can be a renaming of a private component, use
1291 -- the original record component.
1293 if Is_Prival (Ent) then
1294 Ent := Prival_Link (Ent);
1297 if Is_Protected_Type (Scope (Ent)) then
1303 -- For indexed and selected components, recursively check the prefix
1305 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
1306 return Enclosing_Protected_Type (Prefix (Obj));
1308 -- The object does not denote a protected component
1313 end Enclosing_Protected_Type;
1315 -------------------------
1316 -- Is_Public_Operation --
1317 -------------------------
1319 function Is_Public_Operation return Boolean is
1326 and then S /= Pref_Encl_Typ
1328 if Scope (S) = Pref_Encl_Typ then
1329 E := First_Entity (Pref_Encl_Typ);
1331 and then E /= First_Private_Entity (Pref_Encl_Typ)
1344 end Is_Public_Operation;
1346 -- Start of processing for Check_Unprotected_Access
1349 if Nkind (Expr) = N_Attribute_Reference
1350 and then Attribute_Name (Expr) = Name_Unchecked_Access
1352 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
1353 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
1355 -- Check whether we are trying to export a protected component to a
1356 -- context with an equal or lower access level.
1358 if Present (Pref_Encl_Typ)
1359 and then No (Cont_Encl_Typ)
1360 and then Is_Public_Operation
1361 and then Scope_Depth (Pref_Encl_Typ) >=
1362 Object_Access_Level (Context)
1365 ("?possible unprotected access to protected data", Expr);
1368 end Check_Unprotected_Access;
1374 procedure Check_VMS (Construct : Node_Id) is
1376 if not OpenVMS_On_Target then
1378 ("this construct is allowed only in Open'V'M'S", Construct);
1382 ------------------------
1383 -- Collect_Interfaces --
1384 ------------------------
1386 procedure Collect_Interfaces
1388 Ifaces_List : out Elist_Id;
1389 Exclude_Parents : Boolean := False;
1390 Use_Full_View : Boolean := True)
1392 procedure Collect (Typ : Entity_Id);
1393 -- Subsidiary subprogram used to traverse the whole list
1394 -- of directly and indirectly implemented interfaces
1400 procedure Collect (Typ : Entity_Id) is
1401 Ancestor : Entity_Id;
1409 -- Handle private types
1412 and then Is_Private_Type (Typ)
1413 and then Present (Full_View (Typ))
1415 Full_T := Full_View (Typ);
1418 -- Include the ancestor if we are generating the whole list of
1419 -- abstract interfaces.
1421 if Etype (Full_T) /= Typ
1423 -- Protect the frontend against wrong sources. For example:
1426 -- type A is tagged null record;
1427 -- type B is new A with private;
1428 -- type C is new A with private;
1430 -- type B is new C with null record;
1431 -- type C is new B with null record;
1434 and then Etype (Full_T) /= T
1436 Ancestor := Etype (Full_T);
1439 if Is_Interface (Ancestor)
1440 and then not Exclude_Parents
1442 Append_Unique_Elmt (Ancestor, Ifaces_List);
1446 -- Traverse the graph of ancestor interfaces
1448 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
1449 Id := First (Abstract_Interface_List (Full_T));
1450 while Present (Id) loop
1451 Iface := Etype (Id);
1453 -- Protect against wrong uses. For example:
1454 -- type I is interface;
1455 -- type O is tagged null record;
1456 -- type Wrong is new I and O with null record; -- ERROR
1458 if Is_Interface (Iface) then
1460 and then Etype (T) /= T
1461 and then Interface_Present_In_Ancestor (Etype (T), Iface)
1466 Append_Unique_Elmt (Iface, Ifaces_List);
1475 -- Start of processing for Collect_Interfaces
1478 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
1479 Ifaces_List := New_Elmt_List;
1481 end Collect_Interfaces;
1483 ----------------------------------
1484 -- Collect_Interface_Components --
1485 ----------------------------------
1487 procedure Collect_Interface_Components
1488 (Tagged_Type : Entity_Id;
1489 Components_List : out Elist_Id)
1491 procedure Collect (Typ : Entity_Id);
1492 -- Subsidiary subprogram used to climb to the parents
1498 procedure Collect (Typ : Entity_Id) is
1499 Tag_Comp : Entity_Id;
1500 Parent_Typ : Entity_Id;
1503 -- Handle private types
1505 if Present (Full_View (Etype (Typ))) then
1506 Parent_Typ := Full_View (Etype (Typ));
1508 Parent_Typ := Etype (Typ);
1511 if Parent_Typ /= Typ
1513 -- Protect the frontend against wrong sources. For example:
1516 -- type A is tagged null record;
1517 -- type B is new A with private;
1518 -- type C is new A with private;
1520 -- type B is new C with null record;
1521 -- type C is new B with null record;
1524 and then Parent_Typ /= Tagged_Type
1526 Collect (Parent_Typ);
1529 -- Collect the components containing tags of secondary dispatch
1532 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
1533 while Present (Tag_Comp) loop
1534 pragma Assert (Present (Related_Type (Tag_Comp)));
1535 Append_Elmt (Tag_Comp, Components_List);
1537 Tag_Comp := Next_Tag_Component (Tag_Comp);
1541 -- Start of processing for Collect_Interface_Components
1544 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
1545 and then Is_Tagged_Type (Tagged_Type));
1547 Components_List := New_Elmt_List;
1548 Collect (Tagged_Type);
1549 end Collect_Interface_Components;
1551 -----------------------------
1552 -- Collect_Interfaces_Info --
1553 -----------------------------
1555 procedure Collect_Interfaces_Info
1557 Ifaces_List : out Elist_Id;
1558 Components_List : out Elist_Id;
1559 Tags_List : out Elist_Id)
1561 Comps_List : Elist_Id;
1562 Comp_Elmt : Elmt_Id;
1563 Comp_Iface : Entity_Id;
1564 Iface_Elmt : Elmt_Id;
1567 function Search_Tag (Iface : Entity_Id) return Entity_Id;
1568 -- Search for the secondary tag associated with the interface type
1569 -- Iface that is implemented by T.
1575 function Search_Tag (Iface : Entity_Id) return Entity_Id is
1579 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
1581 and then Ekind (Node (ADT)) = E_Constant
1582 and then Related_Type (Node (ADT)) /= Iface
1584 -- Skip the secondary dispatch tables of Iface
1592 pragma Assert (Ekind (Node (ADT)) = E_Constant);
1596 -- Start of processing for Collect_Interfaces_Info
1599 Collect_Interfaces (T, Ifaces_List);
1600 Collect_Interface_Components (T, Comps_List);
1602 -- Search for the record component and tag associated with each
1603 -- interface type of T.
1605 Components_List := New_Elmt_List;
1606 Tags_List := New_Elmt_List;
1608 Iface_Elmt := First_Elmt (Ifaces_List);
1609 while Present (Iface_Elmt) loop
1610 Iface := Node (Iface_Elmt);
1612 -- Associate the primary tag component and the primary dispatch table
1613 -- with all the interfaces that are parents of T
1615 if Is_Ancestor (Iface, T) then
1616 Append_Elmt (First_Tag_Component (T), Components_List);
1617 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
1619 -- Otherwise search for the tag component and secondary dispatch
1623 Comp_Elmt := First_Elmt (Comps_List);
1624 while Present (Comp_Elmt) loop
1625 Comp_Iface := Related_Type (Node (Comp_Elmt));
1627 if Comp_Iface = Iface
1628 or else Is_Ancestor (Iface, Comp_Iface)
1630 Append_Elmt (Node (Comp_Elmt), Components_List);
1631 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
1635 Next_Elmt (Comp_Elmt);
1637 pragma Assert (Present (Comp_Elmt));
1640 Next_Elmt (Iface_Elmt);
1642 end Collect_Interfaces_Info;
1644 ----------------------------------
1645 -- Collect_Primitive_Operations --
1646 ----------------------------------
1648 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
1649 B_Type : constant Entity_Id := Base_Type (T);
1650 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
1651 B_Scope : Entity_Id := Scope (B_Type);
1655 Formal_Derived : Boolean := False;
1659 -- For tagged types, the primitive operations are collected as they
1660 -- are declared, and held in an explicit list which is simply returned.
1662 if Is_Tagged_Type (B_Type) then
1663 return Primitive_Operations (B_Type);
1665 -- An untagged generic type that is a derived type inherits the
1666 -- primitive operations of its parent type. Other formal types only
1667 -- have predefined operators, which are not explicitly represented.
1669 elsif Is_Generic_Type (B_Type) then
1670 if Nkind (B_Decl) = N_Formal_Type_Declaration
1671 and then Nkind (Formal_Type_Definition (B_Decl))
1672 = N_Formal_Derived_Type_Definition
1674 Formal_Derived := True;
1676 return New_Elmt_List;
1680 Op_List := New_Elmt_List;
1682 if B_Scope = Standard_Standard then
1683 if B_Type = Standard_String then
1684 Append_Elmt (Standard_Op_Concat, Op_List);
1686 elsif B_Type = Standard_Wide_String then
1687 Append_Elmt (Standard_Op_Concatw, Op_List);
1693 elsif (Is_Package_Or_Generic_Package (B_Scope)
1695 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
1697 or else Is_Derived_Type (B_Type)
1699 -- The primitive operations appear after the base type, except
1700 -- if the derivation happens within the private part of B_Scope
1701 -- and the type is a private type, in which case both the type
1702 -- and some primitive operations may appear before the base
1703 -- type, and the list of candidates starts after the type.
1705 if In_Open_Scopes (B_Scope)
1706 and then Scope (T) = B_Scope
1707 and then In_Private_Part (B_Scope)
1709 Id := Next_Entity (T);
1711 Id := Next_Entity (B_Type);
1714 while Present (Id) loop
1716 -- Note that generic formal subprograms are not
1717 -- considered to be primitive operations and thus
1718 -- are never inherited.
1720 if Is_Overloadable (Id)
1721 and then Nkind (Parent (Parent (Id)))
1722 not in N_Formal_Subprogram_Declaration
1726 if Base_Type (Etype (Id)) = B_Type then
1729 Formal := First_Formal (Id);
1730 while Present (Formal) loop
1731 if Base_Type (Etype (Formal)) = B_Type then
1735 elsif Ekind (Etype (Formal)) = E_Anonymous_Access_Type
1737 (Designated_Type (Etype (Formal))) = B_Type
1743 Next_Formal (Formal);
1747 -- For a formal derived type, the only primitives are the
1748 -- ones inherited from the parent type. Operations appearing
1749 -- in the package declaration are not primitive for it.
1752 and then (not Formal_Derived
1753 or else Present (Alias (Id)))
1755 -- In the special case of an equality operator aliased to
1756 -- an overriding dispatching equality belonging to the same
1757 -- type, we don't include it in the list of primitives.
1758 -- This avoids inheriting multiple equality operators when
1759 -- deriving from untagged private types whose full type is
1760 -- tagged, which can otherwise cause ambiguities. Note that
1761 -- this should only happen for this kind of untagged parent
1762 -- type, since normally dispatching operations are inherited
1763 -- using the type's Primitive_Operations list.
1765 if Chars (Id) = Name_Op_Eq
1766 and then Is_Dispatching_Operation (Id)
1767 and then Present (Alias (Id))
1768 and then Is_Overriding_Operation (Alias (Id))
1769 and then Base_Type (Etype (First_Entity (Id))) =
1770 Base_Type (Etype (First_Entity (Alias (Id))))
1774 -- Include the subprogram in the list of primitives
1777 Append_Elmt (Id, Op_List);
1784 -- For a type declared in System, some of its operations may
1785 -- appear in the target-specific extension to System.
1788 and then Chars (B_Scope) = Name_System
1789 and then Scope (B_Scope) = Standard_Standard
1790 and then Present_System_Aux
1792 B_Scope := System_Aux_Id;
1793 Id := First_Entity (System_Aux_Id);
1799 end Collect_Primitive_Operations;
1801 -----------------------------------
1802 -- Compile_Time_Constraint_Error --
1803 -----------------------------------
1805 function Compile_Time_Constraint_Error
1808 Ent : Entity_Id := Empty;
1809 Loc : Source_Ptr := No_Location;
1810 Warn : Boolean := False) return Node_Id
1812 Msgc : String (1 .. Msg'Length + 2);
1813 -- Copy of message, with room for possible ? and ! at end
1823 -- A static constraint error in an instance body is not a fatal error.
1824 -- we choose to inhibit the message altogether, because there is no
1825 -- obvious node (for now) on which to post it. On the other hand the
1826 -- offending node must be replaced with a constraint_error in any case.
1828 -- No messages are generated if we already posted an error on this node
1830 if not Error_Posted (N) then
1831 if Loc /= No_Location then
1837 Msgc (1 .. Msg'Length) := Msg;
1840 -- Message is a warning, even in Ada 95 case
1842 if Msg (Msg'Last) = '?' then
1845 -- In Ada 83, all messages are warnings. In the private part and
1846 -- the body of an instance, constraint_checks are only warnings.
1847 -- We also make this a warning if the Warn parameter is set.
1850 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
1856 elsif In_Instance_Not_Visible then
1861 -- Otherwise we have a real error message (Ada 95 static case)
1862 -- and we make this an unconditional message. Note that in the
1863 -- warning case we do not make the message unconditional, it seems
1864 -- quite reasonable to delete messages like this (about exceptions
1865 -- that will be raised) in dead code.
1873 -- Should we generate a warning? The answer is not quite yes. The
1874 -- very annoying exception occurs in the case of a short circuit
1875 -- operator where the left operand is static and decisive. Climb
1876 -- parents to see if that is the case we have here. Conditional
1877 -- expressions with decisive conditions are a similar situation.
1885 -- And then with False as left operand
1887 if Nkind (P) = N_And_Then
1888 and then Compile_Time_Known_Value (Left_Opnd (P))
1889 and then Is_False (Expr_Value (Left_Opnd (P)))
1894 -- OR ELSE with True as left operand
1896 elsif Nkind (P) = N_Or_Else
1897 and then Compile_Time_Known_Value (Left_Opnd (P))
1898 and then Is_True (Expr_Value (Left_Opnd (P)))
1903 -- Conditional expression
1905 elsif Nkind (P) = N_Conditional_Expression then
1907 Cond : constant Node_Id := First (Expressions (P));
1908 Texp : constant Node_Id := Next (Cond);
1909 Fexp : constant Node_Id := Next (Texp);
1912 if Compile_Time_Known_Value (Cond) then
1914 -- Condition is True and we are in the right operand
1916 if Is_True (Expr_Value (Cond))
1917 and then OldP = Fexp
1922 -- Condition is False and we are in the left operand
1924 elsif Is_False (Expr_Value (Cond))
1925 and then OldP = Texp
1933 -- Special case for component association in aggregates, where
1934 -- we want to keep climbing up to the parent aggregate.
1936 elsif Nkind (P) = N_Component_Association
1937 and then Nkind (Parent (P)) = N_Aggregate
1941 -- Keep going if within subexpression
1944 exit when Nkind (P) not in N_Subexpr;
1949 if Present (Ent) then
1950 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
1952 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
1956 if Inside_Init_Proc then
1958 ("\?& will be raised for objects of this type",
1959 N, Standard_Constraint_Error, Eloc);
1962 ("\?& will be raised at run time",
1963 N, Standard_Constraint_Error, Eloc);
1968 ("\static expression fails Constraint_Check", Eloc);
1969 Set_Error_Posted (N);
1975 end Compile_Time_Constraint_Error;
1977 -----------------------
1978 -- Conditional_Delay --
1979 -----------------------
1981 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
1983 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
1984 Set_Has_Delayed_Freeze (New_Ent);
1986 end Conditional_Delay;
1988 -------------------------
1989 -- Copy_Parameter_List --
1990 -------------------------
1992 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
1993 Loc : constant Source_Ptr := Sloc (Subp_Id);
1998 if No (First_Formal (Subp_Id)) then
2002 Formal := First_Formal (Subp_Id);
2003 while Present (Formal) loop
2005 (Make_Parameter_Specification (Loc,
2006 Defining_Identifier =>
2007 Make_Defining_Identifier (Sloc (Formal),
2008 Chars => Chars (Formal)),
2009 In_Present => In_Present (Parent (Formal)),
2010 Out_Present => Out_Present (Parent (Formal)),
2012 New_Reference_To (Etype (Formal), Loc),
2014 New_Copy_Tree (Expression (Parent (Formal)))),
2017 Next_Formal (Formal);
2022 end Copy_Parameter_List;
2024 --------------------
2025 -- Current_Entity --
2026 --------------------
2028 -- The currently visible definition for a given identifier is the
2029 -- one most chained at the start of the visibility chain, i.e. the
2030 -- one that is referenced by the Node_Id value of the name of the
2031 -- given identifier.
2033 function Current_Entity (N : Node_Id) return Entity_Id is
2035 return Get_Name_Entity_Id (Chars (N));
2038 -----------------------------
2039 -- Current_Entity_In_Scope --
2040 -----------------------------
2042 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
2044 CS : constant Entity_Id := Current_Scope;
2046 Transient_Case : constant Boolean := Scope_Is_Transient;
2049 E := Get_Name_Entity_Id (Chars (N));
2051 and then Scope (E) /= CS
2052 and then (not Transient_Case or else Scope (E) /= Scope (CS))
2058 end Current_Entity_In_Scope;
2064 function Current_Scope return Entity_Id is
2066 if Scope_Stack.Last = -1 then
2067 return Standard_Standard;
2070 C : constant Entity_Id :=
2071 Scope_Stack.Table (Scope_Stack.Last).Entity;
2076 return Standard_Standard;
2082 ------------------------
2083 -- Current_Subprogram --
2084 ------------------------
2086 function Current_Subprogram return Entity_Id is
2087 Scop : constant Entity_Id := Current_Scope;
2089 if Is_Subprogram (Scop) or else Is_Generic_Subprogram (Scop) then
2092 return Enclosing_Subprogram (Scop);
2094 end Current_Subprogram;
2096 ---------------------
2097 -- Defining_Entity --
2098 ---------------------
2100 function Defining_Entity (N : Node_Id) return Entity_Id is
2101 K : constant Node_Kind := Nkind (N);
2102 Err : Entity_Id := Empty;
2107 N_Subprogram_Declaration |
2108 N_Abstract_Subprogram_Declaration |
2110 N_Package_Declaration |
2111 N_Subprogram_Renaming_Declaration |
2112 N_Subprogram_Body_Stub |
2113 N_Generic_Subprogram_Declaration |
2114 N_Generic_Package_Declaration |
2115 N_Formal_Subprogram_Declaration
2117 return Defining_Entity (Specification (N));
2120 N_Component_Declaration |
2121 N_Defining_Program_Unit_Name |
2122 N_Discriminant_Specification |
2124 N_Entry_Declaration |
2125 N_Entry_Index_Specification |
2126 N_Exception_Declaration |
2127 N_Exception_Renaming_Declaration |
2128 N_Formal_Object_Declaration |
2129 N_Formal_Package_Declaration |
2130 N_Formal_Type_Declaration |
2131 N_Full_Type_Declaration |
2132 N_Implicit_Label_Declaration |
2133 N_Incomplete_Type_Declaration |
2134 N_Loop_Parameter_Specification |
2135 N_Number_Declaration |
2136 N_Object_Declaration |
2137 N_Object_Renaming_Declaration |
2138 N_Package_Body_Stub |
2139 N_Parameter_Specification |
2140 N_Private_Extension_Declaration |
2141 N_Private_Type_Declaration |
2143 N_Protected_Body_Stub |
2144 N_Protected_Type_Declaration |
2145 N_Single_Protected_Declaration |
2146 N_Single_Task_Declaration |
2147 N_Subtype_Declaration |
2150 N_Task_Type_Declaration
2152 return Defining_Identifier (N);
2155 return Defining_Entity (Proper_Body (N));
2158 N_Function_Instantiation |
2159 N_Function_Specification |
2160 N_Generic_Function_Renaming_Declaration |
2161 N_Generic_Package_Renaming_Declaration |
2162 N_Generic_Procedure_Renaming_Declaration |
2164 N_Package_Instantiation |
2165 N_Package_Renaming_Declaration |
2166 N_Package_Specification |
2167 N_Procedure_Instantiation |
2168 N_Procedure_Specification
2171 Nam : constant Node_Id := Defining_Unit_Name (N);
2174 if Nkind (Nam) in N_Entity then
2177 -- For Error, make up a name and attach to declaration
2178 -- so we can continue semantic analysis
2180 elsif Nam = Error then
2181 Err := Make_Temporary (Sloc (N), 'T');
2182 Set_Defining_Unit_Name (N, Err);
2185 -- If not an entity, get defining identifier
2188 return Defining_Identifier (Nam);
2192 when N_Block_Statement =>
2193 return Entity (Identifier (N));
2196 raise Program_Error;
2199 end Defining_Entity;
2201 --------------------------
2202 -- Denotes_Discriminant --
2203 --------------------------
2205 function Denotes_Discriminant
2207 Check_Concurrent : Boolean := False) return Boolean
2211 if not Is_Entity_Name (N)
2212 or else No (Entity (N))
2219 -- If we are checking for a protected type, the discriminant may have
2220 -- been rewritten as the corresponding discriminal of the original type
2221 -- or of the corresponding concurrent record, depending on whether we
2222 -- are in the spec or body of the protected type.
2224 return Ekind (E) = E_Discriminant
2227 and then Ekind (E) = E_In_Parameter
2228 and then Present (Discriminal_Link (E))
2230 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
2232 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
2234 end Denotes_Discriminant;
2236 -------------------------
2237 -- Denotes_Same_Object --
2238 -------------------------
2240 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
2242 -- If we have entity names, then must be same entity
2244 if Is_Entity_Name (A1) then
2245 if Is_Entity_Name (A2) then
2246 return Entity (A1) = Entity (A2);
2251 -- No match if not same node kind
2253 elsif Nkind (A1) /= Nkind (A2) then
2256 -- For selected components, must have same prefix and selector
2258 elsif Nkind (A1) = N_Selected_Component then
2259 return Denotes_Same_Object (Prefix (A1), Prefix (A2))
2261 Entity (Selector_Name (A1)) = Entity (Selector_Name (A2));
2263 -- For explicit dereferences, prefixes must be same
2265 elsif Nkind (A1) = N_Explicit_Dereference then
2266 return Denotes_Same_Object (Prefix (A1), Prefix (A2));
2268 -- For indexed components, prefixes and all subscripts must be the same
2270 elsif Nkind (A1) = N_Indexed_Component then
2271 if Denotes_Same_Object (Prefix (A1), Prefix (A2)) then
2277 Indx1 := First (Expressions (A1));
2278 Indx2 := First (Expressions (A2));
2279 while Present (Indx1) loop
2281 -- Shouldn't we be checking that values are the same???
2283 if not Denotes_Same_Object (Indx1, Indx2) then
2297 -- For slices, prefixes must match and bounds must match
2299 elsif Nkind (A1) = N_Slice
2300 and then Denotes_Same_Object (Prefix (A1), Prefix (A2))
2303 Lo1, Lo2, Hi1, Hi2 : Node_Id;
2306 Get_Index_Bounds (Etype (A1), Lo1, Hi1);
2307 Get_Index_Bounds (Etype (A2), Lo2, Hi2);
2309 -- Check whether bounds are statically identical. There is no
2310 -- attempt to detect partial overlap of slices.
2312 -- What about an array and a slice of an array???
2314 return Denotes_Same_Object (Lo1, Lo2)
2315 and then Denotes_Same_Object (Hi1, Hi2);
2318 -- Literals will appear as indices. Isn't this where we should check
2319 -- Known_At_Compile_Time at least if we are generating warnings ???
2321 elsif Nkind (A1) = N_Integer_Literal then
2322 return Intval (A1) = Intval (A2);
2327 end Denotes_Same_Object;
2329 -------------------------
2330 -- Denotes_Same_Prefix --
2331 -------------------------
2333 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
2336 if Is_Entity_Name (A1) then
2337 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
2338 and then not Is_Access_Type (Etype (A1))
2340 return Denotes_Same_Object (A1, Prefix (A2))
2341 or else Denotes_Same_Prefix (A1, Prefix (A2));
2346 elsif Is_Entity_Name (A2) then
2347 return Denotes_Same_Prefix (A2, A1);
2349 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
2351 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
2354 Root1, Root2 : Node_Id;
2355 Depth1, Depth2 : Int := 0;
2358 Root1 := Prefix (A1);
2359 while not Is_Entity_Name (Root1) loop
2361 (Root1, N_Selected_Component, N_Indexed_Component)
2365 Root1 := Prefix (Root1);
2368 Depth1 := Depth1 + 1;
2371 Root2 := Prefix (A2);
2372 while not Is_Entity_Name (Root2) loop
2374 (Root2, N_Selected_Component, N_Indexed_Component)
2378 Root2 := Prefix (Root2);
2381 Depth2 := Depth2 + 1;
2384 -- If both have the same depth and they do not denote the same
2385 -- object, they are disjoint and not warning is needed.
2387 if Depth1 = Depth2 then
2390 elsif Depth1 > Depth2 then
2391 Root1 := Prefix (A1);
2392 for I in 1 .. Depth1 - Depth2 - 1 loop
2393 Root1 := Prefix (Root1);
2396 return Denotes_Same_Object (Root1, A2);
2399 Root2 := Prefix (A2);
2400 for I in 1 .. Depth2 - Depth1 - 1 loop
2401 Root2 := Prefix (Root2);
2404 return Denotes_Same_Object (A1, Root2);
2411 end Denotes_Same_Prefix;
2413 ----------------------
2414 -- Denotes_Variable --
2415 ----------------------
2417 function Denotes_Variable (N : Node_Id) return Boolean is
2419 return Is_Variable (N) and then Paren_Count (N) = 0;
2420 end Denotes_Variable;
2422 -----------------------------
2423 -- Depends_On_Discriminant --
2424 -----------------------------
2426 function Depends_On_Discriminant (N : Node_Id) return Boolean is
2431 Get_Index_Bounds (N, L, H);
2432 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
2433 end Depends_On_Discriminant;
2435 -------------------------
2436 -- Designate_Same_Unit --
2437 -------------------------
2439 function Designate_Same_Unit
2441 Name2 : Node_Id) return Boolean
2443 K1 : constant Node_Kind := Nkind (Name1);
2444 K2 : constant Node_Kind := Nkind (Name2);
2446 function Prefix_Node (N : Node_Id) return Node_Id;
2447 -- Returns the parent unit name node of a defining program unit name
2448 -- or the prefix if N is a selected component or an expanded name.
2450 function Select_Node (N : Node_Id) return Node_Id;
2451 -- Returns the defining identifier node of a defining program unit
2452 -- name or the selector node if N is a selected component or an
2459 function Prefix_Node (N : Node_Id) return Node_Id is
2461 if Nkind (N) = N_Defining_Program_Unit_Name then
2473 function Select_Node (N : Node_Id) return Node_Id is
2475 if Nkind (N) = N_Defining_Program_Unit_Name then
2476 return Defining_Identifier (N);
2479 return Selector_Name (N);
2483 -- Start of processing for Designate_Next_Unit
2486 if (K1 = N_Identifier or else
2487 K1 = N_Defining_Identifier)
2489 (K2 = N_Identifier or else
2490 K2 = N_Defining_Identifier)
2492 return Chars (Name1) = Chars (Name2);
2495 (K1 = N_Expanded_Name or else
2496 K1 = N_Selected_Component or else
2497 K1 = N_Defining_Program_Unit_Name)
2499 (K2 = N_Expanded_Name or else
2500 K2 = N_Selected_Component or else
2501 K2 = N_Defining_Program_Unit_Name)
2504 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
2506 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
2511 end Designate_Same_Unit;
2513 ----------------------------
2514 -- Enclosing_Generic_Body --
2515 ----------------------------
2517 function Enclosing_Generic_Body
2518 (N : Node_Id) return Node_Id
2526 while Present (P) loop
2527 if Nkind (P) = N_Package_Body
2528 or else Nkind (P) = N_Subprogram_Body
2530 Spec := Corresponding_Spec (P);
2532 if Present (Spec) then
2533 Decl := Unit_Declaration_Node (Spec);
2535 if Nkind (Decl) = N_Generic_Package_Declaration
2536 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2547 end Enclosing_Generic_Body;
2549 ----------------------------
2550 -- Enclosing_Generic_Unit --
2551 ----------------------------
2553 function Enclosing_Generic_Unit
2554 (N : Node_Id) return Node_Id
2562 while Present (P) loop
2563 if Nkind (P) = N_Generic_Package_Declaration
2564 or else Nkind (P) = N_Generic_Subprogram_Declaration
2568 elsif Nkind (P) = N_Package_Body
2569 or else Nkind (P) = N_Subprogram_Body
2571 Spec := Corresponding_Spec (P);
2573 if Present (Spec) then
2574 Decl := Unit_Declaration_Node (Spec);
2576 if Nkind (Decl) = N_Generic_Package_Declaration
2577 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2588 end Enclosing_Generic_Unit;
2590 -------------------------------
2591 -- Enclosing_Lib_Unit_Entity --
2592 -------------------------------
2594 function Enclosing_Lib_Unit_Entity return Entity_Id is
2595 Unit_Entity : Entity_Id;
2598 -- Look for enclosing library unit entity by following scope links.
2599 -- Equivalent to, but faster than indexing through the scope stack.
2601 Unit_Entity := Current_Scope;
2602 while (Present (Scope (Unit_Entity))
2603 and then Scope (Unit_Entity) /= Standard_Standard)
2604 and not Is_Child_Unit (Unit_Entity)
2606 Unit_Entity := Scope (Unit_Entity);
2610 end Enclosing_Lib_Unit_Entity;
2612 -----------------------------
2613 -- Enclosing_Lib_Unit_Node --
2614 -----------------------------
2616 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
2617 Current_Node : Node_Id;
2621 while Present (Current_Node)
2622 and then Nkind (Current_Node) /= N_Compilation_Unit
2624 Current_Node := Parent (Current_Node);
2627 if Nkind (Current_Node) /= N_Compilation_Unit then
2631 return Current_Node;
2632 end Enclosing_Lib_Unit_Node;
2634 --------------------------
2635 -- Enclosing_Subprogram --
2636 --------------------------
2638 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
2639 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
2642 if Dynamic_Scope = Standard_Standard then
2645 elsif Dynamic_Scope = Empty then
2648 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
2649 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
2651 elsif Ekind (Dynamic_Scope) = E_Block
2652 or else Ekind (Dynamic_Scope) = E_Return_Statement
2654 return Enclosing_Subprogram (Dynamic_Scope);
2656 elsif Ekind (Dynamic_Scope) = E_Task_Type then
2657 return Get_Task_Body_Procedure (Dynamic_Scope);
2659 -- No body is generated if the protected operation is eliminated
2661 elsif Convention (Dynamic_Scope) = Convention_Protected
2662 and then not Is_Eliminated (Dynamic_Scope)
2663 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
2665 return Protected_Body_Subprogram (Dynamic_Scope);
2668 return Dynamic_Scope;
2670 end Enclosing_Subprogram;
2672 ------------------------
2673 -- Ensure_Freeze_Node --
2674 ------------------------
2676 procedure Ensure_Freeze_Node (E : Entity_Id) is
2680 if No (Freeze_Node (E)) then
2681 FN := Make_Freeze_Entity (Sloc (E));
2682 Set_Has_Delayed_Freeze (E);
2683 Set_Freeze_Node (E, FN);
2684 Set_Access_Types_To_Process (FN, No_Elist);
2685 Set_TSS_Elist (FN, No_Elist);
2688 end Ensure_Freeze_Node;
2694 procedure Enter_Name (Def_Id : Entity_Id) is
2695 C : constant Entity_Id := Current_Entity (Def_Id);
2696 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
2697 S : constant Entity_Id := Current_Scope;
2700 Generate_Definition (Def_Id);
2702 -- Add new name to current scope declarations. Check for duplicate
2703 -- declaration, which may or may not be a genuine error.
2707 -- Case of previous entity entered because of a missing declaration
2708 -- or else a bad subtype indication. Best is to use the new entity,
2709 -- and make the previous one invisible.
2711 if Etype (E) = Any_Type then
2712 Set_Is_Immediately_Visible (E, False);
2714 -- Case of renaming declaration constructed for package instances.
2715 -- if there is an explicit declaration with the same identifier,
2716 -- the renaming is not immediately visible any longer, but remains
2717 -- visible through selected component notation.
2719 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
2720 and then not Comes_From_Source (E)
2722 Set_Is_Immediately_Visible (E, False);
2724 -- The new entity may be the package renaming, which has the same
2725 -- same name as a generic formal which has been seen already.
2727 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
2728 and then not Comes_From_Source (Def_Id)
2730 Set_Is_Immediately_Visible (E, False);
2732 -- For a fat pointer corresponding to a remote access to subprogram,
2733 -- we use the same identifier as the RAS type, so that the proper
2734 -- name appears in the stub. This type is only retrieved through
2735 -- the RAS type and never by visibility, and is not added to the
2736 -- visibility list (see below).
2738 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
2739 and then Present (Corresponding_Remote_Type (Def_Id))
2743 -- A controller component for a type extension overrides the
2744 -- inherited component.
2746 elsif Chars (E) = Name_uController then
2749 -- Case of an implicit operation or derived literal. The new entity
2750 -- hides the implicit one, which is removed from all visibility,
2751 -- i.e. the entity list of its scope, and homonym chain of its name.
2753 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
2754 or else Is_Internal (E)
2758 Prev_Vis : Entity_Id;
2759 Decl : constant Node_Id := Parent (E);
2762 -- If E is an implicit declaration, it cannot be the first
2763 -- entity in the scope.
2765 Prev := First_Entity (Current_Scope);
2766 while Present (Prev)
2767 and then Next_Entity (Prev) /= E
2774 -- If E is not on the entity chain of the current scope,
2775 -- it is an implicit declaration in the generic formal
2776 -- part of a generic subprogram. When analyzing the body,
2777 -- the generic formals are visible but not on the entity
2778 -- chain of the subprogram. The new entity will become
2779 -- the visible one in the body.
2782 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
2786 Set_Next_Entity (Prev, Next_Entity (E));
2788 if No (Next_Entity (Prev)) then
2789 Set_Last_Entity (Current_Scope, Prev);
2792 if E = Current_Entity (E) then
2796 Prev_Vis := Current_Entity (E);
2797 while Homonym (Prev_Vis) /= E loop
2798 Prev_Vis := Homonym (Prev_Vis);
2802 if Present (Prev_Vis) then
2804 -- Skip E in the visibility chain
2806 Set_Homonym (Prev_Vis, Homonym (E));
2809 Set_Name_Entity_Id (Chars (E), Homonym (E));
2814 -- This section of code could use a comment ???
2816 elsif Present (Etype (E))
2817 and then Is_Concurrent_Type (Etype (E))
2822 -- If the homograph is a protected component renaming, it should not
2823 -- be hiding the current entity. Such renamings are treated as weak
2826 elsif Is_Prival (E) then
2827 Set_Is_Immediately_Visible (E, False);
2829 -- In this case the current entity is a protected component renaming.
2830 -- Perform minimal decoration by setting the scope and return since
2831 -- the prival should not be hiding other visible entities.
2833 elsif Is_Prival (Def_Id) then
2834 Set_Scope (Def_Id, Current_Scope);
2837 -- Analogous to privals, the discriminal generated for an entry
2838 -- index parameter acts as a weak declaration. Perform minimal
2839 -- decoration to avoid bogus errors.
2841 elsif Is_Discriminal (Def_Id)
2842 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
2844 Set_Scope (Def_Id, Current_Scope);
2847 -- In the body or private part of an instance, a type extension
2848 -- may introduce a component with the same name as that of an
2849 -- actual. The legality rule is not enforced, but the semantics
2850 -- of the full type with two components of the same name are not
2851 -- clear at this point ???
2853 elsif In_Instance_Not_Visible then
2856 -- When compiling a package body, some child units may have become
2857 -- visible. They cannot conflict with local entities that hide them.
2859 elsif Is_Child_Unit (E)
2860 and then In_Open_Scopes (Scope (E))
2861 and then not Is_Immediately_Visible (E)
2865 -- Conversely, with front-end inlining we may compile the parent
2866 -- body first, and a child unit subsequently. The context is now
2867 -- the parent spec, and body entities are not visible.
2869 elsif Is_Child_Unit (Def_Id)
2870 and then Is_Package_Body_Entity (E)
2871 and then not In_Package_Body (Current_Scope)
2875 -- Case of genuine duplicate declaration
2878 Error_Msg_Sloc := Sloc (E);
2880 -- If the previous declaration is an incomplete type declaration
2881 -- this may be an attempt to complete it with a private type.
2882 -- The following avoids confusing cascaded errors.
2884 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
2885 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
2888 ("incomplete type cannot be completed with a private " &
2889 "declaration", Parent (Def_Id));
2890 Set_Is_Immediately_Visible (E, False);
2891 Set_Full_View (E, Def_Id);
2893 -- An inherited component of a record conflicts with a new
2894 -- discriminant. The discriminant is inserted first in the scope,
2895 -- but the error should be posted on it, not on the component.
2897 elsif Ekind (E) = E_Discriminant
2898 and then Present (Scope (Def_Id))
2899 and then Scope (Def_Id) /= Current_Scope
2901 Error_Msg_Sloc := Sloc (Def_Id);
2902 Error_Msg_N ("& conflicts with declaration#", E);
2905 -- If the name of the unit appears in its own context clause,
2906 -- a dummy package with the name has already been created, and
2907 -- the error emitted. Try to continue quietly.
2909 elsif Error_Posted (E)
2910 and then Sloc (E) = No_Location
2911 and then Nkind (Parent (E)) = N_Package_Specification
2912 and then Current_Scope = Standard_Standard
2914 Set_Scope (Def_Id, Current_Scope);
2918 Error_Msg_N ("& conflicts with declaration#", Def_Id);
2920 -- Avoid cascaded messages with duplicate components in
2923 if Ekind_In (E, E_Component, E_Discriminant) then
2928 if Nkind (Parent (Parent (Def_Id))) =
2929 N_Generic_Subprogram_Declaration
2931 Defining_Entity (Specification (Parent (Parent (Def_Id))))
2933 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
2936 -- If entity is in standard, then we are in trouble, because
2937 -- it means that we have a library package with a duplicated
2938 -- name. That's hard to recover from, so abort!
2940 if S = Standard_Standard then
2941 raise Unrecoverable_Error;
2943 -- Otherwise we continue with the declaration. Having two
2944 -- identical declarations should not cause us too much trouble!
2952 -- If we fall through, declaration is OK , or OK enough to continue
2954 -- If Def_Id is a discriminant or a record component we are in the
2955 -- midst of inheriting components in a derived record definition.
2956 -- Preserve their Ekind and Etype.
2958 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
2961 -- If a type is already set, leave it alone (happens whey a type
2962 -- declaration is reanalyzed following a call to the optimizer)
2964 elsif Present (Etype (Def_Id)) then
2967 -- Otherwise, the kind E_Void insures that premature uses of the entity
2968 -- will be detected. Any_Type insures that no cascaded errors will occur
2971 Set_Ekind (Def_Id, E_Void);
2972 Set_Etype (Def_Id, Any_Type);
2975 -- Inherited discriminants and components in derived record types are
2976 -- immediately visible. Itypes are not.
2978 if Ekind_In (Def_Id, E_Discriminant, E_Component)
2979 or else (No (Corresponding_Remote_Type (Def_Id))
2980 and then not Is_Itype (Def_Id))
2982 Set_Is_Immediately_Visible (Def_Id);
2983 Set_Current_Entity (Def_Id);
2986 Set_Homonym (Def_Id, C);
2987 Append_Entity (Def_Id, S);
2988 Set_Public_Status (Def_Id);
2990 -- Warn if new entity hides an old one
2992 if Warn_On_Hiding and then Present (C)
2994 -- Don't warn for record components since they always have a well
2995 -- defined scope which does not confuse other uses. Note that in
2996 -- some cases, Ekind has not been set yet.
2998 and then Ekind (C) /= E_Component
2999 and then Ekind (C) /= E_Discriminant
3000 and then Nkind (Parent (C)) /= N_Component_Declaration
3001 and then Ekind (Def_Id) /= E_Component
3002 and then Ekind (Def_Id) /= E_Discriminant
3003 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
3005 -- Don't warn for one character variables. It is too common to use
3006 -- such variables as locals and will just cause too many false hits.
3008 and then Length_Of_Name (Chars (C)) /= 1
3010 -- Don't warn for non-source entities
3012 and then Comes_From_Source (C)
3013 and then Comes_From_Source (Def_Id)
3015 -- Don't warn unless entity in question is in extended main source
3017 and then In_Extended_Main_Source_Unit (Def_Id)
3019 -- Finally, the hidden entity must be either immediately visible
3020 -- or use visible (from a used package)
3023 (Is_Immediately_Visible (C)
3025 Is_Potentially_Use_Visible (C))
3027 Error_Msg_Sloc := Sloc (C);
3028 Error_Msg_N ("declaration hides &#?", Def_Id);
3032 --------------------------
3033 -- Explain_Limited_Type --
3034 --------------------------
3036 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
3040 -- For array, component type must be limited
3042 if Is_Array_Type (T) then
3043 Error_Msg_Node_2 := T;
3045 ("\component type& of type& is limited", N, Component_Type (T));
3046 Explain_Limited_Type (Component_Type (T), N);
3048 elsif Is_Record_Type (T) then
3050 -- No need for extra messages if explicit limited record
3052 if Is_Limited_Record (Base_Type (T)) then
3056 -- Otherwise find a limited component. Check only components that
3057 -- come from source, or inherited components that appear in the
3058 -- source of the ancestor.
3060 C := First_Component (T);
3061 while Present (C) loop
3062 if Is_Limited_Type (Etype (C))
3064 (Comes_From_Source (C)
3066 (Present (Original_Record_Component (C))
3068 Comes_From_Source (Original_Record_Component (C))))
3070 Error_Msg_Node_2 := T;
3071 Error_Msg_NE ("\component& of type& has limited type", N, C);
3072 Explain_Limited_Type (Etype (C), N);
3079 -- The type may be declared explicitly limited, even if no component
3080 -- of it is limited, in which case we fall out of the loop.
3083 end Explain_Limited_Type;
3089 procedure Find_Actual
3091 Formal : out Entity_Id;
3094 Parnt : constant Node_Id := Parent (N);
3098 if (Nkind (Parnt) = N_Indexed_Component
3100 Nkind (Parnt) = N_Selected_Component)
3101 and then N = Prefix (Parnt)
3103 Find_Actual (Parnt, Formal, Call);
3106 elsif Nkind (Parnt) = N_Parameter_Association
3107 and then N = Explicit_Actual_Parameter (Parnt)
3109 Call := Parent (Parnt);
3111 elsif Nkind (Parnt) = N_Procedure_Call_Statement then
3120 -- If we have a call to a subprogram look for the parameter. Note that
3121 -- we exclude overloaded calls, since we don't know enough to be sure
3122 -- of giving the right answer in this case.
3124 if Is_Entity_Name (Name (Call))
3125 and then Present (Entity (Name (Call)))
3126 and then Is_Overloadable (Entity (Name (Call)))
3127 and then not Is_Overloaded (Name (Call))
3129 -- Fall here if we are definitely a parameter
3131 Actual := First_Actual (Call);
3132 Formal := First_Formal (Entity (Name (Call)));
3133 while Present (Formal) and then Present (Actual) loop
3137 Actual := Next_Actual (Actual);
3138 Formal := Next_Formal (Formal);
3143 -- Fall through here if we did not find matching actual
3149 ---------------------------
3150 -- Find_Body_Discriminal --
3151 ---------------------------
3153 function Find_Body_Discriminal
3154 (Spec_Discriminant : Entity_Id) return Entity_Id
3156 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
3158 Tsk : constant Entity_Id :=
3159 Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
3163 -- Find discriminant of original concurrent type, and use its current
3164 -- discriminal, which is the renaming within the task/protected body.
3166 Disc := First_Discriminant (Tsk);
3167 while Present (Disc) loop
3168 if Chars (Disc) = Chars (Spec_Discriminant) then
3169 return Discriminal (Disc);
3172 Next_Discriminant (Disc);
3175 -- That loop should always succeed in finding a matching entry and
3176 -- returning. Fatal error if not.
3178 raise Program_Error;
3179 end Find_Body_Discriminal;
3181 -------------------------------------
3182 -- Find_Corresponding_Discriminant --
3183 -------------------------------------
3185 function Find_Corresponding_Discriminant
3187 Typ : Entity_Id) return Entity_Id
3189 Par_Disc : Entity_Id;
3190 Old_Disc : Entity_Id;
3191 New_Disc : Entity_Id;
3194 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
3196 -- The original type may currently be private, and the discriminant
3197 -- only appear on its full view.
3199 if Is_Private_Type (Scope (Par_Disc))
3200 and then not Has_Discriminants (Scope (Par_Disc))
3201 and then Present (Full_View (Scope (Par_Disc)))
3203 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
3205 Old_Disc := First_Discriminant (Scope (Par_Disc));
3208 if Is_Class_Wide_Type (Typ) then
3209 New_Disc := First_Discriminant (Root_Type (Typ));
3211 New_Disc := First_Discriminant (Typ);
3214 while Present (Old_Disc) and then Present (New_Disc) loop
3215 if Old_Disc = Par_Disc then
3218 Next_Discriminant (Old_Disc);
3219 Next_Discriminant (New_Disc);
3223 -- Should always find it
3225 raise Program_Error;
3226 end Find_Corresponding_Discriminant;
3228 --------------------------
3229 -- Find_Overlaid_Entity --
3230 --------------------------
3232 procedure Find_Overlaid_Entity
3234 Ent : out Entity_Id;
3240 -- We are looking for one of the two following forms:
3242 -- for X'Address use Y'Address
3246 -- Const : constant Address := expr;
3248 -- for X'Address use Const;
3250 -- In the second case, the expr is either Y'Address, or recursively a
3251 -- constant that eventually references Y'Address.
3256 if Nkind (N) = N_Attribute_Definition_Clause
3257 and then Chars (N) = Name_Address
3259 Expr := Expression (N);
3261 -- This loop checks the form of the expression for Y'Address,
3262 -- using recursion to deal with intermediate constants.
3265 -- Check for Y'Address
3267 if Nkind (Expr) = N_Attribute_Reference
3268 and then Attribute_Name (Expr) = Name_Address
3270 Expr := Prefix (Expr);
3273 -- Check for Const where Const is a constant entity
3275 elsif Is_Entity_Name (Expr)
3276 and then Ekind (Entity (Expr)) = E_Constant
3278 Expr := Constant_Value (Entity (Expr));
3280 -- Anything else does not need checking
3287 -- This loop checks the form of the prefix for an entity,
3288 -- using recursion to deal with intermediate components.
3291 -- Check for Y where Y is an entity
3293 if Is_Entity_Name (Expr) then
3294 Ent := Entity (Expr);
3297 -- Check for components
3300 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component) then
3302 Expr := Prefix (Expr);
3305 -- Anything else does not need checking
3312 end Find_Overlaid_Entity;
3314 -------------------------
3315 -- Find_Parameter_Type --
3316 -------------------------
3318 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
3320 if Nkind (Param) /= N_Parameter_Specification then
3323 -- For an access parameter, obtain the type from the formal entity
3324 -- itself, because access to subprogram nodes do not carry a type.
3325 -- Shouldn't we always use the formal entity ???
3327 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
3328 return Etype (Defining_Identifier (Param));
3331 return Etype (Parameter_Type (Param));
3333 end Find_Parameter_Type;
3335 -----------------------------
3336 -- Find_Static_Alternative --
3337 -----------------------------
3339 function Find_Static_Alternative (N : Node_Id) return Node_Id is
3340 Expr : constant Node_Id := Expression (N);
3341 Val : constant Uint := Expr_Value (Expr);
3346 Alt := First (Alternatives (N));
3349 if Nkind (Alt) /= N_Pragma then
3350 Choice := First (Discrete_Choices (Alt));
3351 while Present (Choice) loop
3353 -- Others choice, always matches
3355 if Nkind (Choice) = N_Others_Choice then
3358 -- Range, check if value is in the range
3360 elsif Nkind (Choice) = N_Range then
3362 Val >= Expr_Value (Low_Bound (Choice))
3364 Val <= Expr_Value (High_Bound (Choice));
3366 -- Choice is a subtype name. Note that we know it must
3367 -- be a static subtype, since otherwise it would have
3368 -- been diagnosed as illegal.
3370 elsif Is_Entity_Name (Choice)
3371 and then Is_Type (Entity (Choice))
3373 exit Search when Is_In_Range (Expr, Etype (Choice),
3374 Assume_Valid => False);
3376 -- Choice is a subtype indication
3378 elsif Nkind (Choice) = N_Subtype_Indication then
3380 C : constant Node_Id := Constraint (Choice);
3381 R : constant Node_Id := Range_Expression (C);
3385 Val >= Expr_Value (Low_Bound (R))
3387 Val <= Expr_Value (High_Bound (R));
3390 -- Choice is a simple expression
3393 exit Search when Val = Expr_Value (Choice);
3401 pragma Assert (Present (Alt));
3404 -- The above loop *must* terminate by finding a match, since
3405 -- we know the case statement is valid, and the value of the
3406 -- expression is known at compile time. When we fall out of
3407 -- the loop, Alt points to the alternative that we know will
3408 -- be selected at run time.
3411 end Find_Static_Alternative;
3417 function First_Actual (Node : Node_Id) return Node_Id is
3421 if No (Parameter_Associations (Node)) then
3425 N := First (Parameter_Associations (Node));
3427 if Nkind (N) = N_Parameter_Association then
3428 return First_Named_Actual (Node);
3434 -------------------------
3435 -- Full_Qualified_Name --
3436 -------------------------
3438 function Full_Qualified_Name (E : Entity_Id) return String_Id is
3440 pragma Warnings (Off, Res);
3442 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id;
3443 -- Compute recursively the qualified name without NUL at the end
3445 ----------------------------------
3446 -- Internal_Full_Qualified_Name --
3447 ----------------------------------
3449 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id is
3450 Ent : Entity_Id := E;
3451 Parent_Name : String_Id := No_String;
3454 -- Deals properly with child units
3456 if Nkind (Ent) = N_Defining_Program_Unit_Name then
3457 Ent := Defining_Identifier (Ent);
3460 -- Compute qualification recursively (only "Standard" has no scope)
3462 if Present (Scope (Scope (Ent))) then
3463 Parent_Name := Internal_Full_Qualified_Name (Scope (Ent));
3466 -- Every entity should have a name except some expanded blocks
3467 -- don't bother about those.
3469 if Chars (Ent) = No_Name then
3473 -- Add a period between Name and qualification
3475 if Parent_Name /= No_String then
3476 Start_String (Parent_Name);
3477 Store_String_Char (Get_Char_Code ('.'));
3483 -- Generates the entity name in upper case
3485 Get_Decoded_Name_String (Chars (Ent));
3487 Store_String_Chars (Name_Buffer (1 .. Name_Len));
3489 end Internal_Full_Qualified_Name;
3491 -- Start of processing for Full_Qualified_Name
3494 Res := Internal_Full_Qualified_Name (E);
3495 Store_String_Char (Get_Char_Code (ASCII.NUL));
3497 end Full_Qualified_Name;
3499 -----------------------
3500 -- Gather_Components --
3501 -----------------------
3503 procedure Gather_Components
3505 Comp_List : Node_Id;
3506 Governed_By : List_Id;
3508 Report_Errors : out Boolean)
3512 Discrete_Choice : Node_Id;
3513 Comp_Item : Node_Id;
3515 Discrim : Entity_Id;
3516 Discrim_Name : Node_Id;
3517 Discrim_Value : Node_Id;
3520 Report_Errors := False;
3522 if No (Comp_List) or else Null_Present (Comp_List) then
3525 elsif Present (Component_Items (Comp_List)) then
3526 Comp_Item := First (Component_Items (Comp_List));
3532 while Present (Comp_Item) loop
3534 -- Skip the tag of a tagged record, the interface tags, as well
3535 -- as all items that are not user components (anonymous types,
3536 -- rep clauses, Parent field, controller field).
3538 if Nkind (Comp_Item) = N_Component_Declaration then
3540 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
3542 if not Is_Tag (Comp)
3543 and then Chars (Comp) /= Name_uParent
3544 and then Chars (Comp) /= Name_uController
3546 Append_Elmt (Comp, Into);
3554 if No (Variant_Part (Comp_List)) then
3557 Discrim_Name := Name (Variant_Part (Comp_List));
3558 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
3561 -- Look for the discriminant that governs this variant part.
3562 -- The discriminant *must* be in the Governed_By List
3564 Assoc := First (Governed_By);
3565 Find_Constraint : loop
3566 Discrim := First (Choices (Assoc));
3567 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
3568 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
3570 Chars (Corresponding_Discriminant (Entity (Discrim)))
3571 = Chars (Discrim_Name))
3572 or else Chars (Original_Record_Component (Entity (Discrim)))
3573 = Chars (Discrim_Name);
3575 if No (Next (Assoc)) then
3576 if not Is_Constrained (Typ)
3577 and then Is_Derived_Type (Typ)
3578 and then Present (Stored_Constraint (Typ))
3580 -- If the type is a tagged type with inherited discriminants,
3581 -- use the stored constraint on the parent in order to find
3582 -- the values of discriminants that are otherwise hidden by an
3583 -- explicit constraint. Renamed discriminants are handled in
3586 -- If several parent discriminants are renamed by a single
3587 -- discriminant of the derived type, the call to obtain the
3588 -- Corresponding_Discriminant field only retrieves the last
3589 -- of them. We recover the constraint on the others from the
3590 -- Stored_Constraint as well.
3597 D := First_Discriminant (Etype (Typ));
3598 C := First_Elmt (Stored_Constraint (Typ));
3599 while Present (D) and then Present (C) loop
3600 if Chars (Discrim_Name) = Chars (D) then
3601 if Is_Entity_Name (Node (C))
3602 and then Entity (Node (C)) = Entity (Discrim)
3604 -- D is renamed by Discrim, whose value is given in
3611 Make_Component_Association (Sloc (Typ),
3613 (New_Occurrence_Of (D, Sloc (Typ))),
3614 Duplicate_Subexpr_No_Checks (Node (C)));
3616 exit Find_Constraint;
3619 Next_Discriminant (D);
3626 if No (Next (Assoc)) then
3627 Error_Msg_NE (" missing value for discriminant&",
3628 First (Governed_By), Discrim_Name);
3629 Report_Errors := True;
3634 end loop Find_Constraint;
3636 Discrim_Value := Expression (Assoc);
3638 if not Is_OK_Static_Expression (Discrim_Value) then
3640 ("value for discriminant & must be static!",
3641 Discrim_Value, Discrim);
3642 Why_Not_Static (Discrim_Value);
3643 Report_Errors := True;
3647 Search_For_Discriminant_Value : declare
3653 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
3656 Find_Discrete_Value : while Present (Variant) loop
3657 Discrete_Choice := First (Discrete_Choices (Variant));
3658 while Present (Discrete_Choice) loop
3660 exit Find_Discrete_Value when
3661 Nkind (Discrete_Choice) = N_Others_Choice;
3663 Get_Index_Bounds (Discrete_Choice, Low, High);
3665 UI_Low := Expr_Value (Low);
3666 UI_High := Expr_Value (High);
3668 exit Find_Discrete_Value when
3669 UI_Low <= UI_Discrim_Value
3671 UI_High >= UI_Discrim_Value;
3673 Next (Discrete_Choice);
3676 Next_Non_Pragma (Variant);
3677 end loop Find_Discrete_Value;
3678 end Search_For_Discriminant_Value;
3680 if No (Variant) then
3682 ("value of discriminant & is out of range", Discrim_Value, Discrim);
3683 Report_Errors := True;
3687 -- If we have found the corresponding choice, recursively add its
3688 -- components to the Into list.
3690 Gather_Components (Empty,
3691 Component_List (Variant), Governed_By, Into, Report_Errors);
3692 end Gather_Components;
3694 ------------------------
3695 -- Get_Actual_Subtype --
3696 ------------------------
3698 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
3699 Typ : constant Entity_Id := Etype (N);
3700 Utyp : Entity_Id := Underlying_Type (Typ);
3709 -- If what we have is an identifier that references a subprogram
3710 -- formal, or a variable or constant object, then we get the actual
3711 -- subtype from the referenced entity if one has been built.
3713 if Nkind (N) = N_Identifier
3715 (Is_Formal (Entity (N))
3716 or else Ekind (Entity (N)) = E_Constant
3717 or else Ekind (Entity (N)) = E_Variable)
3718 and then Present (Actual_Subtype (Entity (N)))
3720 return Actual_Subtype (Entity (N));
3722 -- Actual subtype of unchecked union is always itself. We never need
3723 -- the "real" actual subtype. If we did, we couldn't get it anyway
3724 -- because the discriminant is not available. The restrictions on
3725 -- Unchecked_Union are designed to make sure that this is OK.
3727 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
3730 -- Here for the unconstrained case, we must find actual subtype
3731 -- No actual subtype is available, so we must build it on the fly.
3733 -- Checking the type, not the underlying type, for constrainedness
3734 -- seems to be necessary. Maybe all the tests should be on the type???
3736 elsif (not Is_Constrained (Typ))
3737 and then (Is_Array_Type (Utyp)
3738 or else (Is_Record_Type (Utyp)
3739 and then Has_Discriminants (Utyp)))
3740 and then not Has_Unknown_Discriminants (Utyp)
3741 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
3743 -- Nothing to do if in spec expression (why not???)
3745 if In_Spec_Expression then
3748 elsif Is_Private_Type (Typ)
3749 and then not Has_Discriminants (Typ)
3751 -- If the type has no discriminants, there is no subtype to
3752 -- build, even if the underlying type is discriminated.
3756 -- Else build the actual subtype
3759 Decl := Build_Actual_Subtype (Typ, N);
3760 Atyp := Defining_Identifier (Decl);
3762 -- If Build_Actual_Subtype generated a new declaration then use it
3766 -- The actual subtype is an Itype, so analyze the declaration,
3767 -- but do not attach it to the tree, to get the type defined.
3769 Set_Parent (Decl, N);
3770 Set_Is_Itype (Atyp);
3771 Analyze (Decl, Suppress => All_Checks);
3772 Set_Associated_Node_For_Itype (Atyp, N);
3773 Set_Has_Delayed_Freeze (Atyp, False);
3775 -- We need to freeze the actual subtype immediately. This is
3776 -- needed, because otherwise this Itype will not get frozen
3777 -- at all, and it is always safe to freeze on creation because
3778 -- any associated types must be frozen at this point.
3780 Freeze_Itype (Atyp, N);
3783 -- Otherwise we did not build a declaration, so return original
3790 -- For all remaining cases, the actual subtype is the same as
3791 -- the nominal type.
3796 end Get_Actual_Subtype;
3798 -------------------------------------
3799 -- Get_Actual_Subtype_If_Available --
3800 -------------------------------------
3802 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
3803 Typ : constant Entity_Id := Etype (N);
3806 -- If what we have is an identifier that references a subprogram
3807 -- formal, or a variable or constant object, then we get the actual
3808 -- subtype from the referenced entity if one has been built.
3810 if Nkind (N) = N_Identifier
3812 (Is_Formal (Entity (N))
3813 or else Ekind (Entity (N)) = E_Constant
3814 or else Ekind (Entity (N)) = E_Variable)
3815 and then Present (Actual_Subtype (Entity (N)))
3817 return Actual_Subtype (Entity (N));
3819 -- Otherwise the Etype of N is returned unchanged
3824 end Get_Actual_Subtype_If_Available;
3826 -------------------------------
3827 -- Get_Default_External_Name --
3828 -------------------------------
3830 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
3832 Get_Decoded_Name_String (Chars (E));
3834 if Opt.External_Name_Imp_Casing = Uppercase then
3835 Set_Casing (All_Upper_Case);
3837 Set_Casing (All_Lower_Case);
3841 Make_String_Literal (Sloc (E),
3842 Strval => String_From_Name_Buffer);
3843 end Get_Default_External_Name;
3845 ---------------------------
3846 -- Get_Enum_Lit_From_Pos --
3847 ---------------------------
3849 function Get_Enum_Lit_From_Pos
3852 Loc : Source_Ptr) return Node_Id
3857 -- In the case where the literal is of type Character, Wide_Character
3858 -- or Wide_Wide_Character or of a type derived from them, there needs
3859 -- to be some special handling since there is no explicit chain of
3860 -- literals to search. Instead, an N_Character_Literal node is created
3861 -- with the appropriate Char_Code and Chars fields.
3863 if Is_Standard_Character_Type (T) then
3864 Set_Character_Literal_Name (UI_To_CC (Pos));
3866 Make_Character_Literal (Loc,
3868 Char_Literal_Value => Pos);
3870 -- For all other cases, we have a complete table of literals, and
3871 -- we simply iterate through the chain of literal until the one
3872 -- with the desired position value is found.
3876 Lit := First_Literal (Base_Type (T));
3877 for J in 1 .. UI_To_Int (Pos) loop
3881 return New_Occurrence_Of (Lit, Loc);
3883 end Get_Enum_Lit_From_Pos;
3885 ------------------------
3886 -- Get_Generic_Entity --
3887 ------------------------
3889 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
3890 Ent : constant Entity_Id := Entity (Name (N));
3892 if Present (Renamed_Object (Ent)) then
3893 return Renamed_Object (Ent);
3897 end Get_Generic_Entity;
3899 ----------------------
3900 -- Get_Index_Bounds --
3901 ----------------------
3903 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
3904 Kind : constant Node_Kind := Nkind (N);
3908 if Kind = N_Range then
3910 H := High_Bound (N);
3912 elsif Kind = N_Subtype_Indication then
3913 R := Range_Expression (Constraint (N));
3921 L := Low_Bound (Range_Expression (Constraint (N)));
3922 H := High_Bound (Range_Expression (Constraint (N)));
3925 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
3926 if Error_Posted (Scalar_Range (Entity (N))) then
3930 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
3931 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
3934 L := Low_Bound (Scalar_Range (Entity (N)));
3935 H := High_Bound (Scalar_Range (Entity (N)));
3939 -- N is an expression, indicating a range with one value
3944 end Get_Index_Bounds;
3946 ----------------------------------
3947 -- Get_Library_Unit_Name_string --
3948 ----------------------------------
3950 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
3951 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
3954 Get_Unit_Name_String (Unit_Name_Id);
3956 -- Remove seven last character (" (spec)" or " (body)")
3958 Name_Len := Name_Len - 7;
3959 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
3960 end Get_Library_Unit_Name_String;
3962 ------------------------
3963 -- Get_Name_Entity_Id --
3964 ------------------------
3966 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
3968 return Entity_Id (Get_Name_Table_Info (Id));
3969 end Get_Name_Entity_Id;
3975 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
3977 return Get_Pragma_Id (Pragma_Name (N));
3980 ---------------------------
3981 -- Get_Referenced_Object --
3982 ---------------------------
3984 function Get_Referenced_Object (N : Node_Id) return Node_Id is
3989 while Is_Entity_Name (R)
3990 and then Present (Renamed_Object (Entity (R)))
3992 R := Renamed_Object (Entity (R));
3996 end Get_Referenced_Object;
3998 ------------------------
3999 -- Get_Renamed_Entity --
4000 ------------------------
4002 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
4007 while Present (Renamed_Entity (R)) loop
4008 R := Renamed_Entity (R);
4012 end Get_Renamed_Entity;
4014 -------------------------
4015 -- Get_Subprogram_Body --
4016 -------------------------
4018 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
4022 Decl := Unit_Declaration_Node (E);
4024 if Nkind (Decl) = N_Subprogram_Body then
4027 -- The below comment is bad, because it is possible for
4028 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
4030 else -- Nkind (Decl) = N_Subprogram_Declaration
4032 if Present (Corresponding_Body (Decl)) then
4033 return Unit_Declaration_Node (Corresponding_Body (Decl));
4035 -- Imported subprogram case
4041 end Get_Subprogram_Body;
4043 ---------------------------
4044 -- Get_Subprogram_Entity --
4045 ---------------------------
4047 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
4052 if Nkind (Nod) = N_Accept_Statement then
4053 Nam := Entry_Direct_Name (Nod);
4055 -- For an entry call, the prefix of the call is a selected component.
4056 -- Need additional code for internal calls ???
4058 elsif Nkind (Nod) = N_Entry_Call_Statement then
4059 if Nkind (Name (Nod)) = N_Selected_Component then
4060 Nam := Entity (Selector_Name (Name (Nod)));
4069 if Nkind (Nam) = N_Explicit_Dereference then
4070 Proc := Etype (Prefix (Nam));
4071 elsif Is_Entity_Name (Nam) then
4072 Proc := Entity (Nam);
4077 if Is_Object (Proc) then
4078 Proc := Etype (Proc);
4081 if Ekind (Proc) = E_Access_Subprogram_Type then
4082 Proc := Directly_Designated_Type (Proc);
4085 if not Is_Subprogram (Proc)
4086 and then Ekind (Proc) /= E_Subprogram_Type
4092 end Get_Subprogram_Entity;
4094 -----------------------------
4095 -- Get_Task_Body_Procedure --
4096 -----------------------------
4098 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
4100 -- Note: A task type may be the completion of a private type with
4101 -- discriminants. When performing elaboration checks on a task
4102 -- declaration, the current view of the type may be the private one,
4103 -- and the procedure that holds the body of the task is held in its
4106 -- This is an odd function, why not have Task_Body_Procedure do
4107 -- the following digging???
4109 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
4110 end Get_Task_Body_Procedure;
4112 -----------------------
4113 -- Has_Access_Values --
4114 -----------------------
4116 function Has_Access_Values (T : Entity_Id) return Boolean is
4117 Typ : constant Entity_Id := Underlying_Type (T);
4120 -- Case of a private type which is not completed yet. This can only
4121 -- happen in the case of a generic format type appearing directly, or
4122 -- as a component of the type to which this function is being applied
4123 -- at the top level. Return False in this case, since we certainly do
4124 -- not know that the type contains access types.
4129 elsif Is_Access_Type (Typ) then
4132 elsif Is_Array_Type (Typ) then
4133 return Has_Access_Values (Component_Type (Typ));
4135 elsif Is_Record_Type (Typ) then
4140 -- Loop to Check components
4142 Comp := First_Component_Or_Discriminant (Typ);
4143 while Present (Comp) loop
4145 -- Check for access component, tag field does not count, even
4146 -- though it is implemented internally using an access type.
4148 if Has_Access_Values (Etype (Comp))
4149 and then Chars (Comp) /= Name_uTag
4154 Next_Component_Or_Discriminant (Comp);
4163 end Has_Access_Values;
4165 ------------------------------
4166 -- Has_Compatible_Alignment --
4167 ------------------------------
4169 function Has_Compatible_Alignment
4171 Expr : Node_Id) return Alignment_Result
4173 function Has_Compatible_Alignment_Internal
4176 Default : Alignment_Result) return Alignment_Result;
4177 -- This is the internal recursive function that actually does the work.
4178 -- There is one additional parameter, which says what the result should
4179 -- be if no alignment information is found, and there is no definite
4180 -- indication of compatible alignments. At the outer level, this is set
4181 -- to Unknown, but for internal recursive calls in the case where types
4182 -- are known to be correct, it is set to Known_Compatible.
4184 ---------------------------------------
4185 -- Has_Compatible_Alignment_Internal --
4186 ---------------------------------------
4188 function Has_Compatible_Alignment_Internal
4191 Default : Alignment_Result) return Alignment_Result
4193 Result : Alignment_Result := Known_Compatible;
4194 -- Holds the current status of the result. Note that once a value of
4195 -- Known_Incompatible is set, it is sticky and does not get changed
4196 -- to Unknown (the value in Result only gets worse as we go along,
4199 Offs : Uint := No_Uint;
4200 -- Set to a factor of the offset from the base object when Expr is a
4201 -- selected or indexed component, based on Component_Bit_Offset and
4202 -- Component_Size respectively. A negative value is used to represent
4203 -- a value which is not known at compile time.
4205 procedure Check_Prefix;
4206 -- Checks the prefix recursively in the case where the expression
4207 -- is an indexed or selected component.
4209 procedure Set_Result (R : Alignment_Result);
4210 -- If R represents a worse outcome (unknown instead of known
4211 -- compatible, or known incompatible), then set Result to R.
4217 procedure Check_Prefix is
4219 -- The subtlety here is that in doing a recursive call to check
4220 -- the prefix, we have to decide what to do in the case where we
4221 -- don't find any specific indication of an alignment problem.
4223 -- At the outer level, we normally set Unknown as the result in
4224 -- this case, since we can only set Known_Compatible if we really
4225 -- know that the alignment value is OK, but for the recursive
4226 -- call, in the case where the types match, and we have not
4227 -- specified a peculiar alignment for the object, we are only
4228 -- concerned about suspicious rep clauses, the default case does
4229 -- not affect us, since the compiler will, in the absence of such
4230 -- rep clauses, ensure that the alignment is correct.
4232 if Default = Known_Compatible
4234 (Etype (Obj) = Etype (Expr)
4235 and then (Unknown_Alignment (Obj)
4237 Alignment (Obj) = Alignment (Etype (Obj))))
4240 (Has_Compatible_Alignment_Internal
4241 (Obj, Prefix (Expr), Known_Compatible));
4243 -- In all other cases, we need a full check on the prefix
4247 (Has_Compatible_Alignment_Internal
4248 (Obj, Prefix (Expr), Unknown));
4256 procedure Set_Result (R : Alignment_Result) is
4263 -- Start of processing for Has_Compatible_Alignment_Internal
4266 -- If Expr is a selected component, we must make sure there is no
4267 -- potentially troublesome component clause, and that the record is
4270 if Nkind (Expr) = N_Selected_Component then
4272 -- Packed record always generate unknown alignment
4274 if Is_Packed (Etype (Prefix (Expr))) then
4275 Set_Result (Unknown);
4278 -- Check prefix and component offset
4281 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
4283 -- If Expr is an indexed component, we must make sure there is no
4284 -- potentially troublesome Component_Size clause and that the array
4285 -- is not bit-packed.
4287 elsif Nkind (Expr) = N_Indexed_Component then
4289 Typ : constant Entity_Id := Etype (Prefix (Expr));
4290 Ind : constant Node_Id := First_Index (Typ);
4293 -- Bit packed array always generates unknown alignment
4295 if Is_Bit_Packed_Array (Typ) then
4296 Set_Result (Unknown);
4299 -- Check prefix and component offset
4302 Offs := Component_Size (Typ);
4304 -- Small optimization: compute the full offset when possible
4307 and then Offs > Uint_0
4308 and then Present (Ind)
4309 and then Nkind (Ind) = N_Range
4310 and then Compile_Time_Known_Value (Low_Bound (Ind))
4311 and then Compile_Time_Known_Value (First (Expressions (Expr)))
4313 Offs := Offs * (Expr_Value (First (Expressions (Expr)))
4314 - Expr_Value (Low_Bound ((Ind))));
4319 -- If we have a null offset, the result is entirely determined by
4320 -- the base object and has already been computed recursively.
4322 if Offs = Uint_0 then
4325 -- Case where we know the alignment of the object
4327 elsif Known_Alignment (Obj) then
4329 ObjA : constant Uint := Alignment (Obj);
4330 ExpA : Uint := No_Uint;
4331 SizA : Uint := No_Uint;
4334 -- If alignment of Obj is 1, then we are always OK
4337 Set_Result (Known_Compatible);
4339 -- Alignment of Obj is greater than 1, so we need to check
4342 -- If we have an offset, see if it is compatible
4344 if Offs /= No_Uint and Offs > Uint_0 then
4345 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
4346 Set_Result (Known_Incompatible);
4349 -- See if Expr is an object with known alignment
4351 elsif Is_Entity_Name (Expr)
4352 and then Known_Alignment (Entity (Expr))
4354 ExpA := Alignment (Entity (Expr));
4356 -- Otherwise, we can use the alignment of the type of
4357 -- Expr given that we already checked for
4358 -- discombobulating rep clauses for the cases of indexed
4359 -- and selected components above.
4361 elsif Known_Alignment (Etype (Expr)) then
4362 ExpA := Alignment (Etype (Expr));
4364 -- Otherwise the alignment is unknown
4367 Set_Result (Default);
4370 -- If we got an alignment, see if it is acceptable
4372 if ExpA /= No_Uint and then ExpA < ObjA then
4373 Set_Result (Known_Incompatible);
4376 -- If Expr is not a piece of a larger object, see if size
4377 -- is given. If so, check that it is not too small for the
4378 -- required alignment.
4380 if Offs /= No_Uint then
4383 -- See if Expr is an object with known size
4385 elsif Is_Entity_Name (Expr)
4386 and then Known_Static_Esize (Entity (Expr))
4388 SizA := Esize (Entity (Expr));
4390 -- Otherwise, we check the object size of the Expr type
4392 elsif Known_Static_Esize (Etype (Expr)) then
4393 SizA := Esize (Etype (Expr));
4396 -- If we got a size, see if it is a multiple of the Obj
4397 -- alignment, if not, then the alignment cannot be
4398 -- acceptable, since the size is always a multiple of the
4401 if SizA /= No_Uint then
4402 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
4403 Set_Result (Known_Incompatible);
4409 -- If we do not know required alignment, any non-zero offset is a
4410 -- potential problem (but certainly may be OK, so result is unknown).
4412 elsif Offs /= No_Uint then
4413 Set_Result (Unknown);
4415 -- If we can't find the result by direct comparison of alignment
4416 -- values, then there is still one case that we can determine known
4417 -- result, and that is when we can determine that the types are the
4418 -- same, and no alignments are specified. Then we known that the
4419 -- alignments are compatible, even if we don't know the alignment
4420 -- value in the front end.
4422 elsif Etype (Obj) = Etype (Expr) then
4424 -- Types are the same, but we have to check for possible size
4425 -- and alignments on the Expr object that may make the alignment
4426 -- different, even though the types are the same.
4428 if Is_Entity_Name (Expr) then
4430 -- First check alignment of the Expr object. Any alignment less
4431 -- than Maximum_Alignment is worrisome since this is the case
4432 -- where we do not know the alignment of Obj.
4434 if Known_Alignment (Entity (Expr))
4436 UI_To_Int (Alignment (Entity (Expr))) <
4437 Ttypes.Maximum_Alignment
4439 Set_Result (Unknown);
4441 -- Now check size of Expr object. Any size that is not an
4442 -- even multiple of Maximum_Alignment is also worrisome
4443 -- since it may cause the alignment of the object to be less
4444 -- than the alignment of the type.
4446 elsif Known_Static_Esize (Entity (Expr))
4448 (UI_To_Int (Esize (Entity (Expr))) mod
4449 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
4452 Set_Result (Unknown);
4454 -- Otherwise same type is decisive
4457 Set_Result (Known_Compatible);
4461 -- Another case to deal with is when there is an explicit size or
4462 -- alignment clause when the types are not the same. If so, then the
4463 -- result is Unknown. We don't need to do this test if the Default is
4464 -- Unknown, since that result will be set in any case.
4466 elsif Default /= Unknown
4467 and then (Has_Size_Clause (Etype (Expr))
4469 Has_Alignment_Clause (Etype (Expr)))
4471 Set_Result (Unknown);
4473 -- If no indication found, set default
4476 Set_Result (Default);
4479 -- Return worst result found
4482 end Has_Compatible_Alignment_Internal;
4484 -- Start of processing for Has_Compatible_Alignment
4487 -- If Obj has no specified alignment, then set alignment from the type
4488 -- alignment. Perhaps we should always do this, but for sure we should
4489 -- do it when there is an address clause since we can do more if the
4490 -- alignment is known.
4492 if Unknown_Alignment (Obj) then
4493 Set_Alignment (Obj, Alignment (Etype (Obj)));
4496 -- Now do the internal call that does all the work
4498 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
4499 end Has_Compatible_Alignment;
4501 ----------------------
4502 -- Has_Declarations --
4503 ----------------------
4505 function Has_Declarations (N : Node_Id) return Boolean is
4507 return Nkind_In (Nkind (N), N_Accept_Statement,
4509 N_Compilation_Unit_Aux,
4515 N_Package_Specification);
4516 end Has_Declarations;
4518 -------------------------------------------
4519 -- Has_Discriminant_Dependent_Constraint --
4520 -------------------------------------------
4522 function Has_Discriminant_Dependent_Constraint
4523 (Comp : Entity_Id) return Boolean
4525 Comp_Decl : constant Node_Id := Parent (Comp);
4526 Subt_Indic : constant Node_Id :=
4527 Subtype_Indication (Component_Definition (Comp_Decl));
4532 if Nkind (Subt_Indic) = N_Subtype_Indication then
4533 Constr := Constraint (Subt_Indic);
4535 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
4536 Assn := First (Constraints (Constr));
4537 while Present (Assn) loop
4538 case Nkind (Assn) is
4539 when N_Subtype_Indication |
4543 if Depends_On_Discriminant (Assn) then
4547 when N_Discriminant_Association =>
4548 if Depends_On_Discriminant (Expression (Assn)) then
4563 end Has_Discriminant_Dependent_Constraint;
4565 --------------------
4566 -- Has_Infinities --
4567 --------------------
4569 function Has_Infinities (E : Entity_Id) return Boolean is
4572 Is_Floating_Point_Type (E)
4573 and then Nkind (Scalar_Range (E)) = N_Range
4574 and then Includes_Infinities (Scalar_Range (E));
4577 --------------------
4578 -- Has_Interfaces --
4579 --------------------
4581 function Has_Interfaces
4583 Use_Full_View : Boolean := True) return Boolean
4585 Typ : Entity_Id := Base_Type (T);
4588 -- Handle concurrent types
4590 if Is_Concurrent_Type (Typ) then
4591 Typ := Corresponding_Record_Type (Typ);
4594 if not Present (Typ)
4595 or else not Is_Record_Type (Typ)
4596 or else not Is_Tagged_Type (Typ)
4601 -- Handle private types
4604 and then Present (Full_View (Typ))
4606 Typ := Full_View (Typ);
4609 -- Handle concurrent record types
4611 if Is_Concurrent_Record_Type (Typ)
4612 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
4618 if Is_Interface (Typ)
4620 (Is_Record_Type (Typ)
4621 and then Present (Interfaces (Typ))
4622 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
4627 exit when Etype (Typ) = Typ
4629 -- Handle private types
4631 or else (Present (Full_View (Etype (Typ)))
4632 and then Full_View (Etype (Typ)) = Typ)
4634 -- Protect the frontend against wrong source with cyclic
4637 or else Etype (Typ) = T;
4639 -- Climb to the ancestor type handling private types
4641 if Present (Full_View (Etype (Typ))) then
4642 Typ := Full_View (Etype (Typ));
4651 ------------------------
4652 -- Has_Null_Exclusion --
4653 ------------------------
4655 function Has_Null_Exclusion (N : Node_Id) return Boolean is
4658 when N_Access_Definition |
4659 N_Access_Function_Definition |
4660 N_Access_Procedure_Definition |
4661 N_Access_To_Object_Definition |
4663 N_Derived_Type_Definition |
4664 N_Function_Specification |
4665 N_Subtype_Declaration =>
4666 return Null_Exclusion_Present (N);
4668 when N_Component_Definition |
4669 N_Formal_Object_Declaration |
4670 N_Object_Renaming_Declaration =>
4671 if Present (Subtype_Mark (N)) then
4672 return Null_Exclusion_Present (N);
4673 else pragma Assert (Present (Access_Definition (N)));
4674 return Null_Exclusion_Present (Access_Definition (N));
4677 when N_Discriminant_Specification =>
4678 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
4679 return Null_Exclusion_Present (Discriminant_Type (N));
4681 return Null_Exclusion_Present (N);
4684 when N_Object_Declaration =>
4685 if Nkind (Object_Definition (N)) = N_Access_Definition then
4686 return Null_Exclusion_Present (Object_Definition (N));
4688 return Null_Exclusion_Present (N);
4691 when N_Parameter_Specification =>
4692 if Nkind (Parameter_Type (N)) = N_Access_Definition then
4693 return Null_Exclusion_Present (Parameter_Type (N));
4695 return Null_Exclusion_Present (N);
4702 end Has_Null_Exclusion;
4704 ------------------------
4705 -- Has_Null_Extension --
4706 ------------------------
4708 function Has_Null_Extension (T : Entity_Id) return Boolean is
4709 B : constant Entity_Id := Base_Type (T);
4714 if Nkind (Parent (B)) = N_Full_Type_Declaration
4715 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
4717 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
4719 if Present (Ext) then
4720 if Null_Present (Ext) then
4723 Comps := Component_List (Ext);
4725 -- The null component list is rewritten during analysis to
4726 -- include the parent component. Any other component indicates
4727 -- that the extension was not originally null.
4729 return Null_Present (Comps)
4730 or else No (Next (First (Component_Items (Comps))));
4739 end Has_Null_Extension;
4741 -------------------------------
4742 -- Has_Overriding_Initialize --
4743 -------------------------------
4745 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
4746 BT : constant Entity_Id := Base_Type (T);
4751 if Is_Controlled (BT) then
4753 -- For derived types, check immediate ancestor, excluding
4754 -- Controlled itself.
4756 if Is_Derived_Type (BT)
4757 and then not In_Predefined_Unit (Etype (BT))
4758 and then Has_Overriding_Initialize (Etype (BT))
4762 elsif Present (Primitive_Operations (BT)) then
4763 P := First_Elmt (Primitive_Operations (BT));
4764 while Present (P) loop
4765 if Chars (Node (P)) = Name_Initialize
4766 and then Comes_From_Source (Node (P))
4777 elsif Has_Controlled_Component (BT) then
4778 Comp := First_Component (BT);
4779 while Present (Comp) loop
4780 if Has_Overriding_Initialize (Etype (Comp)) then
4784 Next_Component (Comp);
4792 end Has_Overriding_Initialize;
4794 --------------------------------------
4795 -- Has_Preelaborable_Initialization --
4796 --------------------------------------
4798 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
4801 procedure Check_Components (E : Entity_Id);
4802 -- Check component/discriminant chain, sets Has_PE False if a component
4803 -- or discriminant does not meet the preelaborable initialization rules.
4805 ----------------------
4806 -- Check_Components --
4807 ----------------------
4809 procedure Check_Components (E : Entity_Id) is
4813 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
4814 -- Returns True if and only if the expression denoted by N does not
4815 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
4817 ---------------------------------
4818 -- Is_Preelaborable_Expression --
4819 ---------------------------------
4821 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
4825 Comp_Type : Entity_Id;
4826 Is_Array_Aggr : Boolean;
4829 if Is_Static_Expression (N) then
4832 elsif Nkind (N) = N_Null then
4835 -- Attributes are allowed in general, even if their prefix is a
4836 -- formal type. (It seems that certain attributes known not to be
4837 -- static might not be allowed, but there are no rules to prevent
4840 elsif Nkind (N) = N_Attribute_Reference then
4843 -- The name of a discriminant evaluated within its parent type is
4844 -- defined to be preelaborable (10.2.1(8)). Note that we test for
4845 -- names that denote discriminals as well as discriminants to
4846 -- catch references occurring within init procs.
4848 elsif Is_Entity_Name (N)
4850 (Ekind (Entity (N)) = E_Discriminant
4852 ((Ekind (Entity (N)) = E_Constant
4853 or else Ekind (Entity (N)) = E_In_Parameter)
4854 and then Present (Discriminal_Link (Entity (N)))))
4858 elsif Nkind (N) = N_Qualified_Expression then
4859 return Is_Preelaborable_Expression (Expression (N));
4861 -- For aggregates we have to check that each of the associations
4862 -- is preelaborable.
4864 elsif Nkind (N) = N_Aggregate
4865 or else Nkind (N) = N_Extension_Aggregate
4867 Is_Array_Aggr := Is_Array_Type (Etype (N));
4869 if Is_Array_Aggr then
4870 Comp_Type := Component_Type (Etype (N));
4873 -- Check the ancestor part of extension aggregates, which must
4874 -- be either the name of a type that has preelaborable init or
4875 -- an expression that is preelaborable.
4877 if Nkind (N) = N_Extension_Aggregate then
4879 Anc_Part : constant Node_Id := Ancestor_Part (N);
4882 if Is_Entity_Name (Anc_Part)
4883 and then Is_Type (Entity (Anc_Part))
4885 if not Has_Preelaborable_Initialization
4891 elsif not Is_Preelaborable_Expression (Anc_Part) then
4897 -- Check positional associations
4899 Exp := First (Expressions (N));
4900 while Present (Exp) loop
4901 if not Is_Preelaborable_Expression (Exp) then
4908 -- Check named associations
4910 Assn := First (Component_Associations (N));
4911 while Present (Assn) loop
4912 Choice := First (Choices (Assn));
4913 while Present (Choice) loop
4914 if Is_Array_Aggr then
4915 if Nkind (Choice) = N_Others_Choice then
4918 elsif Nkind (Choice) = N_Range then
4919 if not Is_Static_Range (Choice) then
4923 elsif not Is_Static_Expression (Choice) then
4928 Comp_Type := Etype (Choice);
4934 -- If the association has a <> at this point, then we have
4935 -- to check whether the component's type has preelaborable
4936 -- initialization. Note that this only occurs when the
4937 -- association's corresponding component does not have a
4938 -- default expression, the latter case having already been
4939 -- expanded as an expression for the association.
4941 if Box_Present (Assn) then
4942 if not Has_Preelaborable_Initialization (Comp_Type) then
4946 -- In the expression case we check whether the expression
4947 -- is preelaborable.
4950 not Is_Preelaborable_Expression (Expression (Assn))
4958 -- If we get here then aggregate as a whole is preelaborable
4962 -- All other cases are not preelaborable
4967 end Is_Preelaborable_Expression;
4969 -- Start of processing for Check_Components
4972 -- Loop through entities of record or protected type
4975 while Present (Ent) loop
4977 -- We are interested only in components and discriminants
4979 if Ekind_In (Ent, E_Component, E_Discriminant) then
4981 -- Get default expression if any. If there is no declaration
4982 -- node, it means we have an internal entity. The parent and
4983 -- tag fields are examples of such entities. For these cases,
4984 -- we just test the type of the entity.
4986 if Present (Declaration_Node (Ent)) then
4987 Exp := Expression (Declaration_Node (Ent));
4992 -- A component has PI if it has no default expression and the
4993 -- component type has PI.
4996 if not Has_Preelaborable_Initialization (Etype (Ent)) then
5001 -- Require the default expression to be preelaborable
5003 elsif not Is_Preelaborable_Expression (Exp) then
5011 end Check_Components;
5013 -- Start of processing for Has_Preelaborable_Initialization
5016 -- Immediate return if already marked as known preelaborable init. This
5017 -- covers types for which this function has already been called once
5018 -- and returned True (in which case the result is cached), and also
5019 -- types to which a pragma Preelaborable_Initialization applies.
5021 if Known_To_Have_Preelab_Init (E) then
5025 -- If the type is a subtype representing a generic actual type, then
5026 -- test whether its base type has preelaborable initialization since
5027 -- the subtype representing the actual does not inherit this attribute
5028 -- from the actual or formal. (but maybe it should???)
5030 if Is_Generic_Actual_Type (E) then
5031 return Has_Preelaborable_Initialization (Base_Type (E));
5034 -- All elementary types have preelaborable initialization
5036 if Is_Elementary_Type (E) then
5039 -- Array types have PI if the component type has PI
5041 elsif Is_Array_Type (E) then
5042 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
5044 -- A derived type has preelaborable initialization if its parent type
5045 -- has preelaborable initialization and (in the case of a derived record
5046 -- extension) if the non-inherited components all have preelaborable
5047 -- initialization. However, a user-defined controlled type with an
5048 -- overriding Initialize procedure does not have preelaborable
5051 elsif Is_Derived_Type (E) then
5053 -- If the derived type is a private extension then it doesn't have
5054 -- preelaborable initialization.
5056 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
5060 -- First check whether ancestor type has preelaborable initialization
5062 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
5064 -- If OK, check extension components (if any)
5066 if Has_PE and then Is_Record_Type (E) then
5067 Check_Components (First_Entity (E));
5070 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
5071 -- with a user defined Initialize procedure does not have PI.
5074 and then Is_Controlled (E)
5075 and then Has_Overriding_Initialize (E)
5080 -- Private types not derived from a type having preelaborable init and
5081 -- that are not marked with pragma Preelaborable_Initialization do not
5082 -- have preelaborable initialization.
5084 elsif Is_Private_Type (E) then
5087 -- Record type has PI if it is non private and all components have PI
5089 elsif Is_Record_Type (E) then
5091 Check_Components (First_Entity (E));
5093 -- Protected types must not have entries, and components must meet
5094 -- same set of rules as for record components.
5096 elsif Is_Protected_Type (E) then
5097 if Has_Entries (E) then
5101 Check_Components (First_Entity (E));
5102 Check_Components (First_Private_Entity (E));
5105 -- Type System.Address always has preelaborable initialization
5107 elsif Is_RTE (E, RE_Address) then
5110 -- In all other cases, type does not have preelaborable initialization
5116 -- If type has preelaborable initialization, cache result
5119 Set_Known_To_Have_Preelab_Init (E);
5123 end Has_Preelaborable_Initialization;
5125 ---------------------------
5126 -- Has_Private_Component --
5127 ---------------------------
5129 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
5130 Btype : Entity_Id := Base_Type (Type_Id);
5131 Component : Entity_Id;
5134 if Error_Posted (Type_Id)
5135 or else Error_Posted (Btype)
5140 if Is_Class_Wide_Type (Btype) then
5141 Btype := Root_Type (Btype);
5144 if Is_Private_Type (Btype) then
5146 UT : constant Entity_Id := Underlying_Type (Btype);
5149 if No (Full_View (Btype)) then
5150 return not Is_Generic_Type (Btype)
5151 and then not Is_Generic_Type (Root_Type (Btype));
5153 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
5156 return not Is_Frozen (UT) and then Has_Private_Component (UT);
5160 elsif Is_Array_Type (Btype) then
5161 return Has_Private_Component (Component_Type (Btype));
5163 elsif Is_Record_Type (Btype) then
5164 Component := First_Component (Btype);
5165 while Present (Component) loop
5166 if Has_Private_Component (Etype (Component)) then
5170 Next_Component (Component);
5175 elsif Is_Protected_Type (Btype)
5176 and then Present (Corresponding_Record_Type (Btype))
5178 return Has_Private_Component (Corresponding_Record_Type (Btype));
5183 end Has_Private_Component;
5189 function Has_Stream (T : Entity_Id) return Boolean is
5196 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
5199 elsif Is_Array_Type (T) then
5200 return Has_Stream (Component_Type (T));
5202 elsif Is_Record_Type (T) then
5203 E := First_Component (T);
5204 while Present (E) loop
5205 if Has_Stream (Etype (E)) then
5214 elsif Is_Private_Type (T) then
5215 return Has_Stream (Underlying_Type (T));
5222 --------------------------
5223 -- Has_Tagged_Component --
5224 --------------------------
5226 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
5230 if Is_Private_Type (Typ)
5231 and then Present (Underlying_Type (Typ))
5233 return Has_Tagged_Component (Underlying_Type (Typ));
5235 elsif Is_Array_Type (Typ) then
5236 return Has_Tagged_Component (Component_Type (Typ));
5238 elsif Is_Tagged_Type (Typ) then
5241 elsif Is_Record_Type (Typ) then
5242 Comp := First_Component (Typ);
5243 while Present (Comp) loop
5244 if Has_Tagged_Component (Etype (Comp)) then
5248 Next_Component (Comp);
5256 end Has_Tagged_Component;
5258 --------------------------
5259 -- Implements_Interface --
5260 --------------------------
5262 function Implements_Interface
5263 (Typ_Ent : Entity_Id;
5264 Iface_Ent : Entity_Id;
5265 Exclude_Parents : Boolean := False) return Boolean
5267 Ifaces_List : Elist_Id;
5269 Iface : Entity_Id := Base_Type (Iface_Ent);
5270 Typ : Entity_Id := Base_Type (Typ_Ent);
5273 if Is_Class_Wide_Type (Typ) then
5274 Typ := Root_Type (Typ);
5277 if not Has_Interfaces (Typ) then
5281 if Is_Class_Wide_Type (Iface) then
5282 Iface := Root_Type (Iface);
5285 Collect_Interfaces (Typ, Ifaces_List);
5287 Elmt := First_Elmt (Ifaces_List);
5288 while Present (Elmt) loop
5289 if Is_Ancestor (Node (Elmt), Typ)
5290 and then Exclude_Parents
5294 elsif Node (Elmt) = Iface then
5302 end Implements_Interface;
5308 function In_Instance return Boolean is
5309 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
5315 and then S /= Standard_Standard
5317 if (Ekind (S) = E_Function
5318 or else Ekind (S) = E_Package
5319 or else Ekind (S) = E_Procedure)
5320 and then Is_Generic_Instance (S)
5322 -- A child instance is always compiled in the context of a parent
5323 -- instance. Nevertheless, the actuals are not analyzed in an
5324 -- instance context. We detect this case by examining the current
5325 -- compilation unit, which must be a child instance, and checking
5326 -- that it is not currently on the scope stack.
5328 if Is_Child_Unit (Curr_Unit)
5330 Nkind (Unit (Cunit (Current_Sem_Unit)))
5331 = N_Package_Instantiation
5332 and then not In_Open_Scopes (Curr_Unit)
5346 ----------------------
5347 -- In_Instance_Body --
5348 ----------------------
5350 function In_Instance_Body return Boolean is
5356 and then S /= Standard_Standard
5358 if (Ekind (S) = E_Function
5359 or else Ekind (S) = E_Procedure)
5360 and then Is_Generic_Instance (S)
5364 elsif Ekind (S) = E_Package
5365 and then In_Package_Body (S)
5366 and then Is_Generic_Instance (S)
5375 end In_Instance_Body;
5377 -----------------------------
5378 -- In_Instance_Not_Visible --
5379 -----------------------------
5381 function In_Instance_Not_Visible return Boolean is
5387 and then S /= Standard_Standard
5389 if (Ekind (S) = E_Function
5390 or else Ekind (S) = E_Procedure)
5391 and then Is_Generic_Instance (S)
5395 elsif Ekind (S) = E_Package
5396 and then (In_Package_Body (S) or else In_Private_Part (S))
5397 and then Is_Generic_Instance (S)
5406 end In_Instance_Not_Visible;
5408 ------------------------------
5409 -- In_Instance_Visible_Part --
5410 ------------------------------
5412 function In_Instance_Visible_Part return Boolean is
5418 and then S /= Standard_Standard
5420 if Ekind (S) = E_Package
5421 and then Is_Generic_Instance (S)
5422 and then not In_Package_Body (S)
5423 and then not In_Private_Part (S)
5432 end In_Instance_Visible_Part;
5434 ---------------------
5435 -- In_Package_Body --
5436 ---------------------
5438 function In_Package_Body return Boolean is
5444 and then S /= Standard_Standard
5446 if Ekind (S) = E_Package
5447 and then In_Package_Body (S)
5456 end In_Package_Body;
5458 --------------------------------
5459 -- In_Parameter_Specification --
5460 --------------------------------
5462 function In_Parameter_Specification (N : Node_Id) return Boolean is
5467 while Present (PN) loop
5468 if Nkind (PN) = N_Parameter_Specification then
5476 end In_Parameter_Specification;
5478 --------------------------------------
5479 -- In_Subprogram_Or_Concurrent_Unit --
5480 --------------------------------------
5482 function In_Subprogram_Or_Concurrent_Unit return Boolean is
5487 -- Use scope chain to check successively outer scopes
5493 if K in Subprogram_Kind
5494 or else K in Concurrent_Kind
5495 or else K in Generic_Subprogram_Kind
5499 elsif E = Standard_Standard then
5505 end In_Subprogram_Or_Concurrent_Unit;
5507 ---------------------
5508 -- In_Visible_Part --
5509 ---------------------
5511 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
5514 Is_Package_Or_Generic_Package (Scope_Id)
5515 and then In_Open_Scopes (Scope_Id)
5516 and then not In_Package_Body (Scope_Id)
5517 and then not In_Private_Part (Scope_Id);
5518 end In_Visible_Part;
5520 ---------------------------------
5521 -- Insert_Explicit_Dereference --
5522 ---------------------------------
5524 procedure Insert_Explicit_Dereference (N : Node_Id) is
5525 New_Prefix : constant Node_Id := Relocate_Node (N);
5526 Ent : Entity_Id := Empty;
5533 Save_Interps (N, New_Prefix);
5535 Rewrite (N, Make_Explicit_Dereference (Sloc (N), Prefix => New_Prefix));
5537 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
5539 if Is_Overloaded (New_Prefix) then
5541 -- The dereference is also overloaded, and its interpretations are
5542 -- the designated types of the interpretations of the original node.
5544 Set_Etype (N, Any_Type);
5546 Get_First_Interp (New_Prefix, I, It);
5547 while Present (It.Nam) loop
5550 if Is_Access_Type (T) then
5551 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
5554 Get_Next_Interp (I, It);
5560 -- Prefix is unambiguous: mark the original prefix (which might
5561 -- Come_From_Source) as a reference, since the new (relocated) one
5562 -- won't be taken into account.
5564 if Is_Entity_Name (New_Prefix) then
5565 Ent := Entity (New_Prefix);
5567 -- For a retrieval of a subcomponent of some composite object,
5568 -- retrieve the ultimate entity if there is one.
5570 elsif Nkind (New_Prefix) = N_Selected_Component
5571 or else Nkind (New_Prefix) = N_Indexed_Component
5573 Pref := Prefix (New_Prefix);
5574 while Present (Pref)
5576 (Nkind (Pref) = N_Selected_Component
5577 or else Nkind (Pref) = N_Indexed_Component)
5579 Pref := Prefix (Pref);
5582 if Present (Pref) and then Is_Entity_Name (Pref) then
5583 Ent := Entity (Pref);
5587 if Present (Ent) then
5588 Generate_Reference (Ent, New_Prefix);
5591 end Insert_Explicit_Dereference;
5593 ------------------------------------------
5594 -- Inspect_Deferred_Constant_Completion --
5595 ------------------------------------------
5597 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
5601 Decl := First (Decls);
5602 while Present (Decl) loop
5604 -- Deferred constant signature
5606 if Nkind (Decl) = N_Object_Declaration
5607 and then Constant_Present (Decl)
5608 and then No (Expression (Decl))
5610 -- No need to check internally generated constants
5612 and then Comes_From_Source (Decl)
5614 -- The constant is not completed. A full object declaration
5615 -- or a pragma Import complete a deferred constant.
5617 and then not Has_Completion (Defining_Identifier (Decl))
5620 ("constant declaration requires initialization expression",
5621 Defining_Identifier (Decl));
5624 Decl := Next (Decl);
5626 end Inspect_Deferred_Constant_Completion;
5632 function Is_AAMP_Float (E : Entity_Id) return Boolean is
5633 pragma Assert (Is_Type (E));
5635 return AAMP_On_Target
5636 and then Is_Floating_Point_Type (E)
5637 and then E = Base_Type (E);
5640 -----------------------------
5641 -- Is_Actual_Out_Parameter --
5642 -----------------------------
5644 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
5648 Find_Actual (N, Formal, Call);
5649 return Present (Formal)
5650 and then Ekind (Formal) = E_Out_Parameter;
5651 end Is_Actual_Out_Parameter;
5653 -------------------------
5654 -- Is_Actual_Parameter --
5655 -------------------------
5657 function Is_Actual_Parameter (N : Node_Id) return Boolean is
5658 PK : constant Node_Kind := Nkind (Parent (N));
5662 when N_Parameter_Association =>
5663 return N = Explicit_Actual_Parameter (Parent (N));
5665 when N_Function_Call | N_Procedure_Call_Statement =>
5666 return Is_List_Member (N)
5668 List_Containing (N) = Parameter_Associations (Parent (N));
5673 end Is_Actual_Parameter;
5675 ---------------------
5676 -- Is_Aliased_View --
5677 ---------------------
5679 function Is_Aliased_View (Obj : Node_Id) return Boolean is
5683 if Is_Entity_Name (Obj) then
5691 or else (Present (Renamed_Object (E))
5692 and then Is_Aliased_View (Renamed_Object (E)))))
5694 or else ((Is_Formal (E)
5695 or else Ekind (E) = E_Generic_In_Out_Parameter
5696 or else Ekind (E) = E_Generic_In_Parameter)
5697 and then Is_Tagged_Type (Etype (E)))
5699 or else (Is_Concurrent_Type (E)
5700 and then In_Open_Scopes (E))
5702 -- Current instance of type, either directly or as rewritten
5703 -- reference to the current object.
5705 or else (Is_Entity_Name (Original_Node (Obj))
5706 and then Present (Entity (Original_Node (Obj)))
5707 and then Is_Type (Entity (Original_Node (Obj))))
5709 or else (Is_Type (E) and then E = Current_Scope)
5711 or else (Is_Incomplete_Or_Private_Type (E)
5712 and then Full_View (E) = Current_Scope);
5714 elsif Nkind (Obj) = N_Selected_Component then
5715 return Is_Aliased (Entity (Selector_Name (Obj)));
5717 elsif Nkind (Obj) = N_Indexed_Component then
5718 return Has_Aliased_Components (Etype (Prefix (Obj)))
5720 (Is_Access_Type (Etype (Prefix (Obj)))
5722 Has_Aliased_Components
5723 (Designated_Type (Etype (Prefix (Obj)))));
5725 elsif Nkind (Obj) = N_Unchecked_Type_Conversion
5726 or else Nkind (Obj) = N_Type_Conversion
5728 return Is_Tagged_Type (Etype (Obj))
5729 and then Is_Aliased_View (Expression (Obj));
5731 elsif Nkind (Obj) = N_Explicit_Dereference then
5732 return Nkind (Original_Node (Obj)) /= N_Function_Call;
5737 end Is_Aliased_View;
5739 -------------------------
5740 -- Is_Ancestor_Package --
5741 -------------------------
5743 function Is_Ancestor_Package
5745 E2 : Entity_Id) return Boolean
5752 and then Par /= Standard_Standard
5762 end Is_Ancestor_Package;
5764 ----------------------
5765 -- Is_Atomic_Object --
5766 ----------------------
5768 function Is_Atomic_Object (N : Node_Id) return Boolean is
5770 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
5771 -- Determines if given object has atomic components
5773 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
5774 -- If prefix is an implicit dereference, examine designated type
5776 ----------------------
5777 -- Is_Atomic_Prefix --
5778 ----------------------
5780 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
5782 if Is_Access_Type (Etype (N)) then
5784 Has_Atomic_Components (Designated_Type (Etype (N)));
5786 return Object_Has_Atomic_Components (N);
5788 end Is_Atomic_Prefix;
5790 ----------------------------------
5791 -- Object_Has_Atomic_Components --
5792 ----------------------------------
5794 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
5796 if Has_Atomic_Components (Etype (N))
5797 or else Is_Atomic (Etype (N))
5801 elsif Is_Entity_Name (N)
5802 and then (Has_Atomic_Components (Entity (N))
5803 or else Is_Atomic (Entity (N)))
5807 elsif Nkind (N) = N_Indexed_Component
5808 or else Nkind (N) = N_Selected_Component
5810 return Is_Atomic_Prefix (Prefix (N));
5815 end Object_Has_Atomic_Components;
5817 -- Start of processing for Is_Atomic_Object
5820 -- Predicate is not relevant to subprograms
5822 if Is_Entity_Name (N)
5823 and then Is_Overloadable (Entity (N))
5827 elsif Is_Atomic (Etype (N))
5828 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
5832 elsif Nkind (N) = N_Indexed_Component
5833 or else Nkind (N) = N_Selected_Component
5835 return Is_Atomic_Prefix (Prefix (N));
5840 end Is_Atomic_Object;
5842 -------------------------
5843 -- Is_Coextension_Root --
5844 -------------------------
5846 function Is_Coextension_Root (N : Node_Id) return Boolean is
5849 Nkind (N) = N_Allocator
5850 and then Present (Coextensions (N))
5852 -- Anonymous access discriminants carry a list of all nested
5853 -- controlled coextensions.
5855 and then not Is_Dynamic_Coextension (N)
5856 and then not Is_Static_Coextension (N);
5857 end Is_Coextension_Root;
5859 -----------------------------
5860 -- Is_Concurrent_Interface --
5861 -----------------------------
5863 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
5868 (Is_Protected_Interface (T)
5869 or else Is_Synchronized_Interface (T)
5870 or else Is_Task_Interface (T));
5871 end Is_Concurrent_Interface;
5873 --------------------------------------
5874 -- Is_Controlling_Limited_Procedure --
5875 --------------------------------------
5877 function Is_Controlling_Limited_Procedure
5878 (Proc_Nam : Entity_Id) return Boolean
5880 Param_Typ : Entity_Id := Empty;
5883 if Ekind (Proc_Nam) = E_Procedure
5884 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
5886 Param_Typ := Etype (Parameter_Type (First (
5887 Parameter_Specifications (Parent (Proc_Nam)))));
5889 -- In this case where an Itype was created, the procedure call has been
5892 elsif Present (Associated_Node_For_Itype (Proc_Nam))
5893 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
5895 Present (Parameter_Associations
5896 (Associated_Node_For_Itype (Proc_Nam)))
5899 Etype (First (Parameter_Associations
5900 (Associated_Node_For_Itype (Proc_Nam))));
5903 if Present (Param_Typ) then
5905 Is_Interface (Param_Typ)
5906 and then Is_Limited_Record (Param_Typ);
5910 end Is_Controlling_Limited_Procedure;
5912 -----------------------------
5913 -- Is_CPP_Constructor_Call --
5914 -----------------------------
5916 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
5918 return Nkind (N) = N_Function_Call
5919 and then Is_CPP_Class (Etype (Etype (N)))
5920 and then Is_Constructor (Entity (Name (N)))
5921 and then Is_Imported (Entity (Name (N)));
5922 end Is_CPP_Constructor_Call;
5928 function Is_Delegate (T : Entity_Id) return Boolean is
5929 Desig_Type : Entity_Id;
5932 if VM_Target /= CLI_Target then
5936 -- Access-to-subprograms are delegates in CIL
5938 if Ekind (T) = E_Access_Subprogram_Type then
5942 if Ekind (T) not in Access_Kind then
5944 -- A delegate is a managed pointer. If no designated type is defined
5945 -- it means that it's not a delegate.
5950 Desig_Type := Etype (Directly_Designated_Type (T));
5952 if not Is_Tagged_Type (Desig_Type) then
5956 -- Test if the type is inherited from [mscorlib]System.Delegate
5958 while Etype (Desig_Type) /= Desig_Type loop
5959 if Chars (Scope (Desig_Type)) /= No_Name
5960 and then Is_Imported (Scope (Desig_Type))
5961 and then Get_Name_String (Chars (Scope (Desig_Type))) = "delegate"
5966 Desig_Type := Etype (Desig_Type);
5972 ----------------------------------------------
5973 -- Is_Dependent_Component_Of_Mutable_Object --
5974 ----------------------------------------------
5976 function Is_Dependent_Component_Of_Mutable_Object
5977 (Object : Node_Id) return Boolean
5980 Prefix_Type : Entity_Id;
5981 P_Aliased : Boolean := False;
5984 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
5985 -- Returns True if and only if Comp is declared within a variant part
5987 --------------------------------
5988 -- Is_Declared_Within_Variant --
5989 --------------------------------
5991 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
5992 Comp_Decl : constant Node_Id := Parent (Comp);
5993 Comp_List : constant Node_Id := Parent (Comp_Decl);
5995 return Nkind (Parent (Comp_List)) = N_Variant;
5996 end Is_Declared_Within_Variant;
5998 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
6001 if Is_Variable (Object) then
6003 if Nkind (Object) = N_Selected_Component then
6004 P := Prefix (Object);
6005 Prefix_Type := Etype (P);
6007 if Is_Entity_Name (P) then
6009 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
6010 Prefix_Type := Base_Type (Prefix_Type);
6013 if Is_Aliased (Entity (P)) then
6017 -- A discriminant check on a selected component may be
6018 -- expanded into a dereference when removing side-effects.
6019 -- Recover the original node and its type, which may be
6022 elsif Nkind (P) = N_Explicit_Dereference
6023 and then not (Comes_From_Source (P))
6025 P := Original_Node (P);
6026 Prefix_Type := Etype (P);
6029 -- Check for prefix being an aliased component ???
6034 -- A heap object is constrained by its initial value
6036 -- Ada 2005 (AI-363): Always assume the object could be mutable in
6037 -- the dereferenced case, since the access value might denote an
6038 -- unconstrained aliased object, whereas in Ada 95 the designated
6039 -- object is guaranteed to be constrained. A worst-case assumption
6040 -- has to apply in Ada 2005 because we can't tell at compile time
6041 -- whether the object is "constrained by its initial value"
6042 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
6043 -- semantic rules -- these rules are acknowledged to need fixing).
6045 if Ada_Version < Ada_05 then
6046 if Is_Access_Type (Prefix_Type)
6047 or else Nkind (P) = N_Explicit_Dereference
6052 elsif Ada_Version >= Ada_05 then
6053 if Is_Access_Type (Prefix_Type) then
6055 -- If the access type is pool-specific, and there is no
6056 -- constrained partial view of the designated type, then the
6057 -- designated object is known to be constrained.
6059 if Ekind (Prefix_Type) = E_Access_Type
6060 and then not Has_Constrained_Partial_View
6061 (Designated_Type (Prefix_Type))
6065 -- Otherwise (general access type, or there is a constrained
6066 -- partial view of the designated type), we need to check
6067 -- based on the designated type.
6070 Prefix_Type := Designated_Type (Prefix_Type);
6076 Original_Record_Component (Entity (Selector_Name (Object)));
6078 -- As per AI-0017, the renaming is illegal in a generic body,
6079 -- even if the subtype is indefinite.
6081 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
6083 if not Is_Constrained (Prefix_Type)
6084 and then (not Is_Indefinite_Subtype (Prefix_Type)
6086 (Is_Generic_Type (Prefix_Type)
6087 and then Ekind (Current_Scope) = E_Generic_Package
6088 and then In_Package_Body (Current_Scope)))
6090 and then (Is_Declared_Within_Variant (Comp)
6091 or else Has_Discriminant_Dependent_Constraint (Comp))
6092 and then (not P_Aliased or else Ada_Version >= Ada_05)
6098 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
6102 elsif Nkind (Object) = N_Indexed_Component
6103 or else Nkind (Object) = N_Slice
6105 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
6107 -- A type conversion that Is_Variable is a view conversion:
6108 -- go back to the denoted object.
6110 elsif Nkind (Object) = N_Type_Conversion then
6112 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
6117 end Is_Dependent_Component_Of_Mutable_Object;
6119 ---------------------
6120 -- Is_Dereferenced --
6121 ---------------------
6123 function Is_Dereferenced (N : Node_Id) return Boolean is
6124 P : constant Node_Id := Parent (N);
6127 (Nkind (P) = N_Selected_Component
6129 Nkind (P) = N_Explicit_Dereference
6131 Nkind (P) = N_Indexed_Component
6133 Nkind (P) = N_Slice)
6134 and then Prefix (P) = N;
6135 end Is_Dereferenced;
6137 ----------------------
6138 -- Is_Descendent_Of --
6139 ----------------------
6141 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
6146 pragma Assert (Nkind (T1) in N_Entity);
6147 pragma Assert (Nkind (T2) in N_Entity);
6149 T := Base_Type (T1);
6151 -- Immediate return if the types match
6156 -- Comment needed here ???
6158 elsif Ekind (T) = E_Class_Wide_Type then
6159 return Etype (T) = T2;
6167 -- Done if we found the type we are looking for
6172 -- Done if no more derivations to check
6179 -- Following test catches error cases resulting from prev errors
6181 elsif No (Etyp) then
6184 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
6187 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
6191 T := Base_Type (Etyp);
6194 end Is_Descendent_Of;
6200 function Is_False (U : Uint) return Boolean is
6205 ---------------------------
6206 -- Is_Fixed_Model_Number --
6207 ---------------------------
6209 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
6210 S : constant Ureal := Small_Value (T);
6211 M : Urealp.Save_Mark;
6215 R := (U = UR_Trunc (U / S) * S);
6218 end Is_Fixed_Model_Number;
6220 -------------------------------
6221 -- Is_Fully_Initialized_Type --
6222 -------------------------------
6224 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
6226 if Is_Scalar_Type (Typ) then
6229 elsif Is_Access_Type (Typ) then
6232 elsif Is_Array_Type (Typ) then
6233 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
6237 -- An interesting case, if we have a constrained type one of whose
6238 -- bounds is known to be null, then there are no elements to be
6239 -- initialized, so all the elements are initialized!
6241 if Is_Constrained (Typ) then
6244 Indx_Typ : Entity_Id;
6248 Indx := First_Index (Typ);
6249 while Present (Indx) loop
6250 if Etype (Indx) = Any_Type then
6253 -- If index is a range, use directly
6255 elsif Nkind (Indx) = N_Range then
6256 Lbd := Low_Bound (Indx);
6257 Hbd := High_Bound (Indx);
6260 Indx_Typ := Etype (Indx);
6262 if Is_Private_Type (Indx_Typ) then
6263 Indx_Typ := Full_View (Indx_Typ);
6266 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
6269 Lbd := Type_Low_Bound (Indx_Typ);
6270 Hbd := Type_High_Bound (Indx_Typ);
6274 if Compile_Time_Known_Value (Lbd)
6275 and then Compile_Time_Known_Value (Hbd)
6277 if Expr_Value (Hbd) < Expr_Value (Lbd) then
6287 -- If no null indexes, then type is not fully initialized
6293 elsif Is_Record_Type (Typ) then
6294 if Has_Discriminants (Typ)
6296 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
6297 and then Is_Fully_Initialized_Variant (Typ)
6302 -- Controlled records are considered to be fully initialized if
6303 -- there is a user defined Initialize routine. This may not be
6304 -- entirely correct, but as the spec notes, we are guessing here
6305 -- what is best from the point of view of issuing warnings.
6307 if Is_Controlled (Typ) then
6309 Utyp : constant Entity_Id := Underlying_Type (Typ);
6312 if Present (Utyp) then
6314 Init : constant Entity_Id :=
6316 (Underlying_Type (Typ), Name_Initialize));
6320 and then Comes_From_Source (Init)
6322 Is_Predefined_File_Name
6323 (File_Name (Get_Source_File_Index (Sloc (Init))))
6327 elsif Has_Null_Extension (Typ)
6329 Is_Fully_Initialized_Type
6330 (Etype (Base_Type (Typ)))
6339 -- Otherwise see if all record components are initialized
6345 Ent := First_Entity (Typ);
6346 while Present (Ent) loop
6347 if Chars (Ent) = Name_uController then
6350 elsif Ekind (Ent) = E_Component
6351 and then (No (Parent (Ent))
6352 or else No (Expression (Parent (Ent))))
6353 and then not Is_Fully_Initialized_Type (Etype (Ent))
6355 -- Special VM case for tag components, which need to be
6356 -- defined in this case, but are never initialized as VMs
6357 -- are using other dispatching mechanisms. Ignore this
6358 -- uninitialized case. Note that this applies both to the
6359 -- uTag entry and the main vtable pointer (CPP_Class case).
6361 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
6370 -- No uninitialized components, so type is fully initialized.
6371 -- Note that this catches the case of no components as well.
6375 elsif Is_Concurrent_Type (Typ) then
6378 elsif Is_Private_Type (Typ) then
6380 U : constant Entity_Id := Underlying_Type (Typ);
6386 return Is_Fully_Initialized_Type (U);
6393 end Is_Fully_Initialized_Type;
6395 ----------------------------------
6396 -- Is_Fully_Initialized_Variant --
6397 ----------------------------------
6399 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
6400 Loc : constant Source_Ptr := Sloc (Typ);
6401 Constraints : constant List_Id := New_List;
6402 Components : constant Elist_Id := New_Elmt_List;
6403 Comp_Elmt : Elmt_Id;
6405 Comp_List : Node_Id;
6407 Discr_Val : Node_Id;
6409 Report_Errors : Boolean;
6410 pragma Warnings (Off, Report_Errors);
6413 if Serious_Errors_Detected > 0 then
6417 if Is_Record_Type (Typ)
6418 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
6419 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
6421 Comp_List := Component_List (Type_Definition (Parent (Typ)));
6423 Discr := First_Discriminant (Typ);
6424 while Present (Discr) loop
6425 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
6426 Discr_Val := Expression (Parent (Discr));
6428 if Present (Discr_Val)
6429 and then Is_OK_Static_Expression (Discr_Val)
6431 Append_To (Constraints,
6432 Make_Component_Association (Loc,
6433 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
6434 Expression => New_Copy (Discr_Val)));
6442 Next_Discriminant (Discr);
6447 Comp_List => Comp_List,
6448 Governed_By => Constraints,
6450 Report_Errors => Report_Errors);
6452 -- Check that each component present is fully initialized
6454 Comp_Elmt := First_Elmt (Components);
6455 while Present (Comp_Elmt) loop
6456 Comp_Id := Node (Comp_Elmt);
6458 if Ekind (Comp_Id) = E_Component
6459 and then (No (Parent (Comp_Id))
6460 or else No (Expression (Parent (Comp_Id))))
6461 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
6466 Next_Elmt (Comp_Elmt);
6471 elsif Is_Private_Type (Typ) then
6473 U : constant Entity_Id := Underlying_Type (Typ);
6479 return Is_Fully_Initialized_Variant (U);
6485 end Is_Fully_Initialized_Variant;
6491 -- We seem to have a lot of overlapping functions that do similar things
6492 -- (testing for left hand sides or lvalues???). Anyway, since this one is
6493 -- purely syntactic, it should be in Sem_Aux I would think???
6495 function Is_LHS (N : Node_Id) return Boolean is
6496 P : constant Node_Id := Parent (N);
6498 return Nkind (P) = N_Assignment_Statement
6499 and then Name (P) = N;
6502 ----------------------------
6503 -- Is_Inherited_Operation --
6504 ----------------------------
6506 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
6507 Kind : constant Node_Kind := Nkind (Parent (E));
6509 pragma Assert (Is_Overloadable (E));
6510 return Kind = N_Full_Type_Declaration
6511 or else Kind = N_Private_Extension_Declaration
6512 or else Kind = N_Subtype_Declaration
6513 or else (Ekind (E) = E_Enumeration_Literal
6514 and then Is_Derived_Type (Etype (E)));
6515 end Is_Inherited_Operation;
6517 -----------------------------
6518 -- Is_Library_Level_Entity --
6519 -----------------------------
6521 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
6523 -- The following is a small optimization, and it also properly handles
6524 -- discriminals, which in task bodies might appear in expressions before
6525 -- the corresponding procedure has been created, and which therefore do
6526 -- not have an assigned scope.
6528 if Ekind (E) in Formal_Kind then
6532 -- Normal test is simply that the enclosing dynamic scope is Standard
6534 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
6535 end Is_Library_Level_Entity;
6537 ---------------------------------
6538 -- Is_Local_Variable_Reference --
6539 ---------------------------------
6541 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
6543 if not Is_Entity_Name (Expr) then
6548 Ent : constant Entity_Id := Entity (Expr);
6549 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
6551 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
6554 return Present (Sub) and then Sub = Current_Subprogram;
6558 end Is_Local_Variable_Reference;
6560 -------------------------
6561 -- Is_Object_Reference --
6562 -------------------------
6564 function Is_Object_Reference (N : Node_Id) return Boolean is
6566 if Is_Entity_Name (N) then
6567 return Present (Entity (N)) and then Is_Object (Entity (N));
6571 when N_Indexed_Component | N_Slice =>
6573 Is_Object_Reference (Prefix (N))
6574 or else Is_Access_Type (Etype (Prefix (N)));
6576 -- In Ada95, a function call is a constant object; a procedure
6579 when N_Function_Call =>
6580 return Etype (N) /= Standard_Void_Type;
6582 -- A reference to the stream attribute Input is a function call
6584 when N_Attribute_Reference =>
6585 return Attribute_Name (N) = Name_Input;
6587 when N_Selected_Component =>
6589 Is_Object_Reference (Selector_Name (N))
6591 (Is_Object_Reference (Prefix (N))
6592 or else Is_Access_Type (Etype (Prefix (N))));
6594 when N_Explicit_Dereference =>
6597 -- A view conversion of a tagged object is an object reference
6599 when N_Type_Conversion =>
6600 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
6601 and then Is_Tagged_Type (Etype (Expression (N)))
6602 and then Is_Object_Reference (Expression (N));
6604 -- An unchecked type conversion is considered to be an object if
6605 -- the operand is an object (this construction arises only as a
6606 -- result of expansion activities).
6608 when N_Unchecked_Type_Conversion =>
6615 end Is_Object_Reference;
6617 -----------------------------------
6618 -- Is_OK_Variable_For_Out_Formal --
6619 -----------------------------------
6621 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
6623 Note_Possible_Modification (AV, Sure => True);
6625 -- We must reject parenthesized variable names. The check for
6626 -- Comes_From_Source is present because there are currently
6627 -- cases where the compiler violates this rule (e.g. passing
6628 -- a task object to its controlled Initialize routine).
6630 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
6633 -- A variable is always allowed
6635 elsif Is_Variable (AV) then
6638 -- Unchecked conversions are allowed only if they come from the
6639 -- generated code, which sometimes uses unchecked conversions for out
6640 -- parameters in cases where code generation is unaffected. We tell
6641 -- source unchecked conversions by seeing if they are rewrites of an
6642 -- original Unchecked_Conversion function call, or of an explicit
6643 -- conversion of a function call.
6645 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
6646 if Nkind (Original_Node (AV)) = N_Function_Call then
6649 elsif Comes_From_Source (AV)
6650 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
6654 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
6655 return Is_OK_Variable_For_Out_Formal (Expression (AV));
6661 -- Normal type conversions are allowed if argument is a variable
6663 elsif Nkind (AV) = N_Type_Conversion then
6664 if Is_Variable (Expression (AV))
6665 and then Paren_Count (Expression (AV)) = 0
6667 Note_Possible_Modification (Expression (AV), Sure => True);
6670 -- We also allow a non-parenthesized expression that raises
6671 -- constraint error if it rewrites what used to be a variable
6673 elsif Raises_Constraint_Error (Expression (AV))
6674 and then Paren_Count (Expression (AV)) = 0
6675 and then Is_Variable (Original_Node (Expression (AV)))
6679 -- Type conversion of something other than a variable
6685 -- If this node is rewritten, then test the original form, if that is
6686 -- OK, then we consider the rewritten node OK (for example, if the
6687 -- original node is a conversion, then Is_Variable will not be true
6688 -- but we still want to allow the conversion if it converts a variable).
6690 elsif Original_Node (AV) /= AV then
6691 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
6693 -- All other non-variables are rejected
6698 end Is_OK_Variable_For_Out_Formal;
6700 -----------------------------------
6701 -- Is_Partially_Initialized_Type --
6702 -----------------------------------
6704 function Is_Partially_Initialized_Type (Typ : Entity_Id) return Boolean is
6706 if Is_Scalar_Type (Typ) then
6709 elsif Is_Access_Type (Typ) then
6712 elsif Is_Array_Type (Typ) then
6714 -- If component type is partially initialized, so is array type
6716 if Is_Partially_Initialized_Type (Component_Type (Typ)) then
6719 -- Otherwise we are only partially initialized if we are fully
6720 -- initialized (this is the empty array case, no point in us
6721 -- duplicating that code here).
6724 return Is_Fully_Initialized_Type (Typ);
6727 elsif Is_Record_Type (Typ) then
6729 -- A discriminated type is always partially initialized
6731 if Has_Discriminants (Typ) then
6734 -- A tagged type is always partially initialized
6736 elsif Is_Tagged_Type (Typ) then
6739 -- Case of non-discriminated record
6745 Component_Present : Boolean := False;
6746 -- Set True if at least one component is present. If no
6747 -- components are present, then record type is fully
6748 -- initialized (another odd case, like the null array).
6751 -- Loop through components
6753 Ent := First_Entity (Typ);
6754 while Present (Ent) loop
6755 if Ekind (Ent) = E_Component then
6756 Component_Present := True;
6758 -- If a component has an initialization expression then
6759 -- the enclosing record type is partially initialized
6761 if Present (Parent (Ent))
6762 and then Present (Expression (Parent (Ent)))
6766 -- If a component is of a type which is itself partially
6767 -- initialized, then the enclosing record type is also.
6769 elsif Is_Partially_Initialized_Type (Etype (Ent)) then
6777 -- No initialized components found. If we found any components
6778 -- they were all uninitialized so the result is false.
6780 if Component_Present then
6783 -- But if we found no components, then all the components are
6784 -- initialized so we consider the type to be initialized.
6792 -- Concurrent types are always fully initialized
6794 elsif Is_Concurrent_Type (Typ) then
6797 -- For a private type, go to underlying type. If there is no underlying
6798 -- type then just assume this partially initialized. Not clear if this
6799 -- can happen in a non-error case, but no harm in testing for this.
6801 elsif Is_Private_Type (Typ) then
6803 U : constant Entity_Id := Underlying_Type (Typ);
6808 return Is_Partially_Initialized_Type (U);
6812 -- For any other type (are there any?) assume partially initialized
6817 end Is_Partially_Initialized_Type;
6819 ------------------------------------
6820 -- Is_Potentially_Persistent_Type --
6821 ------------------------------------
6823 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
6828 -- For private type, test corresponding full type
6830 if Is_Private_Type (T) then
6831 return Is_Potentially_Persistent_Type (Full_View (T));
6833 -- Scalar types are potentially persistent
6835 elsif Is_Scalar_Type (T) then
6838 -- Record type is potentially persistent if not tagged and the types of
6839 -- all it components are potentially persistent, and no component has
6840 -- an initialization expression.
6842 elsif Is_Record_Type (T)
6843 and then not Is_Tagged_Type (T)
6844 and then not Is_Partially_Initialized_Type (T)
6846 Comp := First_Component (T);
6847 while Present (Comp) loop
6848 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
6857 -- Array type is potentially persistent if its component type is
6858 -- potentially persistent and if all its constraints are static.
6860 elsif Is_Array_Type (T) then
6861 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
6865 Indx := First_Index (T);
6866 while Present (Indx) loop
6867 if not Is_OK_Static_Subtype (Etype (Indx)) then
6876 -- All other types are not potentially persistent
6881 end Is_Potentially_Persistent_Type;
6883 ---------------------------------
6884 -- Is_Protected_Self_Reference --
6885 ---------------------------------
6887 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
6889 function In_Access_Definition (N : Node_Id) return Boolean;
6890 -- Returns true if N belongs to an access definition
6892 --------------------------
6893 -- In_Access_Definition --
6894 --------------------------
6896 function In_Access_Definition (N : Node_Id) return Boolean is
6901 while Present (P) loop
6902 if Nkind (P) = N_Access_Definition then
6910 end In_Access_Definition;
6912 -- Start of processing for Is_Protected_Self_Reference
6915 -- Verify that prefix is analyzed and has the proper form. Note that
6916 -- the attributes Elab_Spec, Elab_Body, and UET_Address, which also
6917 -- produce the address of an entity, do not analyze their prefix
6918 -- because they denote entities that are not necessarily visible.
6919 -- Neither of them can apply to a protected type.
6921 return Ada_Version >= Ada_05
6922 and then Is_Entity_Name (N)
6923 and then Present (Entity (N))
6924 and then Is_Protected_Type (Entity (N))
6925 and then In_Open_Scopes (Entity (N))
6926 and then not In_Access_Definition (N);
6927 end Is_Protected_Self_Reference;
6929 -----------------------------
6930 -- Is_RCI_Pkg_Spec_Or_Body --
6931 -----------------------------
6933 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
6935 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
6936 -- Return True if the unit of Cunit is an RCI package declaration
6938 ---------------------------
6939 -- Is_RCI_Pkg_Decl_Cunit --
6940 ---------------------------
6942 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
6943 The_Unit : constant Node_Id := Unit (Cunit);
6946 if Nkind (The_Unit) /= N_Package_Declaration then
6950 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
6951 end Is_RCI_Pkg_Decl_Cunit;
6953 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
6956 return Is_RCI_Pkg_Decl_Cunit (Cunit)
6958 (Nkind (Unit (Cunit)) = N_Package_Body
6959 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
6960 end Is_RCI_Pkg_Spec_Or_Body;
6962 -----------------------------------------
6963 -- Is_Remote_Access_To_Class_Wide_Type --
6964 -----------------------------------------
6966 function Is_Remote_Access_To_Class_Wide_Type
6967 (E : Entity_Id) return Boolean
6970 -- A remote access to class-wide type is a general access to object type
6971 -- declared in the visible part of a Remote_Types or Remote_Call_
6974 return Ekind (E) = E_General_Access_Type
6975 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
6976 end Is_Remote_Access_To_Class_Wide_Type;
6978 -----------------------------------------
6979 -- Is_Remote_Access_To_Subprogram_Type --
6980 -----------------------------------------
6982 function Is_Remote_Access_To_Subprogram_Type
6983 (E : Entity_Id) return Boolean
6986 return (Ekind (E) = E_Access_Subprogram_Type
6987 or else (Ekind (E) = E_Record_Type
6988 and then Present (Corresponding_Remote_Type (E))))
6989 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
6990 end Is_Remote_Access_To_Subprogram_Type;
6992 --------------------
6993 -- Is_Remote_Call --
6994 --------------------
6996 function Is_Remote_Call (N : Node_Id) return Boolean is
6998 if Nkind (N) /= N_Procedure_Call_Statement
6999 and then Nkind (N) /= N_Function_Call
7001 -- An entry call cannot be remote
7005 elsif Nkind (Name (N)) in N_Has_Entity
7006 and then Is_Remote_Call_Interface (Entity (Name (N)))
7008 -- A subprogram declared in the spec of a RCI package is remote
7012 elsif Nkind (Name (N)) = N_Explicit_Dereference
7013 and then Is_Remote_Access_To_Subprogram_Type
7014 (Etype (Prefix (Name (N))))
7016 -- The dereference of a RAS is a remote call
7020 elsif Present (Controlling_Argument (N))
7021 and then Is_Remote_Access_To_Class_Wide_Type
7022 (Etype (Controlling_Argument (N)))
7024 -- Any primitive operation call with a controlling argument of
7025 -- a RACW type is a remote call.
7030 -- All other calls are local calls
7035 ----------------------
7036 -- Is_Renamed_Entry --
7037 ----------------------
7039 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
7040 Orig_Node : Node_Id := Empty;
7041 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
7043 function Is_Entry (Nam : Node_Id) return Boolean;
7044 -- Determine whether Nam is an entry. Traverse selectors if there are
7045 -- nested selected components.
7051 function Is_Entry (Nam : Node_Id) return Boolean is
7053 if Nkind (Nam) = N_Selected_Component then
7054 return Is_Entry (Selector_Name (Nam));
7057 return Ekind (Entity (Nam)) = E_Entry;
7060 -- Start of processing for Is_Renamed_Entry
7063 if Present (Alias (Proc_Nam)) then
7064 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
7067 -- Look for a rewritten subprogram renaming declaration
7069 if Nkind (Subp_Decl) = N_Subprogram_Declaration
7070 and then Present (Original_Node (Subp_Decl))
7072 Orig_Node := Original_Node (Subp_Decl);
7075 -- The rewritten subprogram is actually an entry
7077 if Present (Orig_Node)
7078 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
7079 and then Is_Entry (Name (Orig_Node))
7085 end Is_Renamed_Entry;
7087 ----------------------
7088 -- Is_Selector_Name --
7089 ----------------------
7091 function Is_Selector_Name (N : Node_Id) return Boolean is
7093 if not Is_List_Member (N) then
7095 P : constant Node_Id := Parent (N);
7096 K : constant Node_Kind := Nkind (P);
7099 (K = N_Expanded_Name or else
7100 K = N_Generic_Association or else
7101 K = N_Parameter_Association or else
7102 K = N_Selected_Component)
7103 and then Selector_Name (P) = N;
7108 L : constant List_Id := List_Containing (N);
7109 P : constant Node_Id := Parent (L);
7111 return (Nkind (P) = N_Discriminant_Association
7112 and then Selector_Names (P) = L)
7114 (Nkind (P) = N_Component_Association
7115 and then Choices (P) = L);
7118 end Is_Selector_Name;
7124 function Is_Statement (N : Node_Id) return Boolean is
7127 Nkind (N) in N_Statement_Other_Than_Procedure_Call
7128 or else Nkind (N) = N_Procedure_Call_Statement;
7131 ---------------------------------
7132 -- Is_Synchronized_Tagged_Type --
7133 ---------------------------------
7135 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
7136 Kind : constant Entity_Kind := Ekind (Base_Type (E));
7139 -- A task or protected type derived from an interface is a tagged type.
7140 -- Such a tagged type is called a synchronized tagged type, as are
7141 -- synchronized interfaces and private extensions whose declaration
7142 -- includes the reserved word synchronized.
7144 return (Is_Tagged_Type (E)
7145 and then (Kind = E_Task_Type
7146 or else Kind = E_Protected_Type))
7149 and then Is_Synchronized_Interface (E))
7151 (Ekind (E) = E_Record_Type_With_Private
7152 and then (Synchronized_Present (Parent (E))
7153 or else Is_Synchronized_Interface (Etype (E))));
7154 end Is_Synchronized_Tagged_Type;
7160 function Is_Transfer (N : Node_Id) return Boolean is
7161 Kind : constant Node_Kind := Nkind (N);
7164 if Kind = N_Simple_Return_Statement
7166 Kind = N_Extended_Return_Statement
7168 Kind = N_Goto_Statement
7170 Kind = N_Raise_Statement
7172 Kind = N_Requeue_Statement
7176 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
7177 and then No (Condition (N))
7181 elsif Kind = N_Procedure_Call_Statement
7182 and then Is_Entity_Name (Name (N))
7183 and then Present (Entity (Name (N)))
7184 and then No_Return (Entity (Name (N)))
7188 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
7200 function Is_True (U : Uint) return Boolean is
7205 -------------------------------
7206 -- Is_Universal_Numeric_Type --
7207 -------------------------------
7209 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
7211 return T = Universal_Integer or else T = Universal_Real;
7212 end Is_Universal_Numeric_Type;
7218 function Is_Value_Type (T : Entity_Id) return Boolean is
7220 return VM_Target = CLI_Target
7221 and then Nkind (T) in N_Has_Chars
7222 and then Chars (T) /= No_Name
7223 and then Get_Name_String (Chars (T)) = "valuetype";
7226 ---------------------
7227 -- Is_VMS_Operator --
7228 ---------------------
7230 function Is_VMS_Operator (Op : Entity_Id) return Boolean is
7232 return Ekind (Op) = E_Function
7233 and then Is_Intrinsic_Subprogram (Op)
7234 and then Chars (Scope (Scope (Op))) = Name_System
7235 and then OpenVMS_On_Target;
7236 end Is_VMS_Operator;
7242 function Is_Variable (N : Node_Id) return Boolean is
7244 Orig_Node : constant Node_Id := Original_Node (N);
7245 -- We do the test on the original node, since this is basically a test
7246 -- of syntactic categories, so it must not be disturbed by whatever
7247 -- rewriting might have occurred. For example, an aggregate, which is
7248 -- certainly NOT a variable, could be turned into a variable by
7251 function In_Protected_Function (E : Entity_Id) return Boolean;
7252 -- Within a protected function, the private components of the
7253 -- enclosing protected type are constants. A function nested within
7254 -- a (protected) procedure is not itself protected.
7256 function Is_Variable_Prefix (P : Node_Id) return Boolean;
7257 -- Prefixes can involve implicit dereferences, in which case we
7258 -- must test for the case of a reference of a constant access
7259 -- type, which can never be a variable.
7261 ---------------------------
7262 -- In_Protected_Function --
7263 ---------------------------
7265 function In_Protected_Function (E : Entity_Id) return Boolean is
7266 Prot : constant Entity_Id := Scope (E);
7270 if not Is_Protected_Type (Prot) then
7274 while Present (S) and then S /= Prot loop
7275 if Ekind (S) = E_Function
7276 and then Scope (S) = Prot
7286 end In_Protected_Function;
7288 ------------------------
7289 -- Is_Variable_Prefix --
7290 ------------------------
7292 function Is_Variable_Prefix (P : Node_Id) return Boolean is
7294 if Is_Access_Type (Etype (P)) then
7295 return not Is_Access_Constant (Root_Type (Etype (P)));
7297 -- For the case of an indexed component whose prefix has a packed
7298 -- array type, the prefix has been rewritten into a type conversion.
7299 -- Determine variable-ness from the converted expression.
7301 elsif Nkind (P) = N_Type_Conversion
7302 and then not Comes_From_Source (P)
7303 and then Is_Array_Type (Etype (P))
7304 and then Is_Packed (Etype (P))
7306 return Is_Variable (Expression (P));
7309 return Is_Variable (P);
7311 end Is_Variable_Prefix;
7313 -- Start of processing for Is_Variable
7316 -- Definitely OK if Assignment_OK is set. Since this is something that
7317 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
7319 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
7322 -- Normally we go to the original node, but there is one exception
7323 -- where we use the rewritten node, namely when it is an explicit
7324 -- dereference. The generated code may rewrite a prefix which is an
7325 -- access type with an explicit dereference. The dereference is a
7326 -- variable, even though the original node may not be (since it could
7327 -- be a constant of the access type).
7329 -- In Ada 2005 we have a further case to consider: the prefix may be
7330 -- a function call given in prefix notation. The original node appears
7331 -- to be a selected component, but we need to examine the call.
7333 elsif Nkind (N) = N_Explicit_Dereference
7334 and then Nkind (Orig_Node) /= N_Explicit_Dereference
7335 and then Present (Etype (Orig_Node))
7336 and then Is_Access_Type (Etype (Orig_Node))
7338 -- Note that if the prefix is an explicit dereference that does not
7339 -- come from source, we must check for a rewritten function call in
7340 -- prefixed notation before other forms of rewriting, to prevent a
7344 (Nkind (Orig_Node) = N_Function_Call
7345 and then not Is_Access_Constant (Etype (Prefix (N))))
7347 Is_Variable_Prefix (Original_Node (Prefix (N)));
7349 -- A function call is never a variable
7351 elsif Nkind (N) = N_Function_Call then
7354 -- All remaining checks use the original node
7356 elsif Is_Entity_Name (Orig_Node)
7357 and then Present (Entity (Orig_Node))
7360 E : constant Entity_Id := Entity (Orig_Node);
7361 K : constant Entity_Kind := Ekind (E);
7364 return (K = E_Variable
7365 and then Nkind (Parent (E)) /= N_Exception_Handler)
7366 or else (K = E_Component
7367 and then not In_Protected_Function (E))
7368 or else K = E_Out_Parameter
7369 or else K = E_In_Out_Parameter
7370 or else K = E_Generic_In_Out_Parameter
7372 -- Current instance of type:
7374 or else (Is_Type (E) and then In_Open_Scopes (E))
7375 or else (Is_Incomplete_Or_Private_Type (E)
7376 and then In_Open_Scopes (Full_View (E)));
7380 case Nkind (Orig_Node) is
7381 when N_Indexed_Component | N_Slice =>
7382 return Is_Variable_Prefix (Prefix (Orig_Node));
7384 when N_Selected_Component =>
7385 return Is_Variable_Prefix (Prefix (Orig_Node))
7386 and then Is_Variable (Selector_Name (Orig_Node));
7388 -- For an explicit dereference, the type of the prefix cannot
7389 -- be an access to constant or an access to subprogram.
7391 when N_Explicit_Dereference =>
7393 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
7395 return Is_Access_Type (Typ)
7396 and then not Is_Access_Constant (Root_Type (Typ))
7397 and then Ekind (Typ) /= E_Access_Subprogram_Type;
7400 -- The type conversion is the case where we do not deal with the
7401 -- context dependent special case of an actual parameter. Thus
7402 -- the type conversion is only considered a variable for the
7403 -- purposes of this routine if the target type is tagged. However,
7404 -- a type conversion is considered to be a variable if it does not
7405 -- come from source (this deals for example with the conversions
7406 -- of expressions to their actual subtypes).
7408 when N_Type_Conversion =>
7409 return Is_Variable (Expression (Orig_Node))
7411 (not Comes_From_Source (Orig_Node)
7413 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
7415 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
7417 -- GNAT allows an unchecked type conversion as a variable. This
7418 -- only affects the generation of internal expanded code, since
7419 -- calls to instantiations of Unchecked_Conversion are never
7420 -- considered variables (since they are function calls).
7421 -- This is also true for expression actions.
7423 when N_Unchecked_Type_Conversion =>
7424 return Is_Variable (Expression (Orig_Node));
7432 ---------------------------
7433 -- Is_Visibly_Controlled --
7434 ---------------------------
7436 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
7437 Root : constant Entity_Id := Root_Type (T);
7439 return Chars (Scope (Root)) = Name_Finalization
7440 and then Chars (Scope (Scope (Root))) = Name_Ada
7441 and then Scope (Scope (Scope (Root))) = Standard_Standard;
7442 end Is_Visibly_Controlled;
7444 ------------------------
7445 -- Is_Volatile_Object --
7446 ------------------------
7448 function Is_Volatile_Object (N : Node_Id) return Boolean is
7450 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
7451 -- Determines if given object has volatile components
7453 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
7454 -- If prefix is an implicit dereference, examine designated type
7456 ------------------------
7457 -- Is_Volatile_Prefix --
7458 ------------------------
7460 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
7461 Typ : constant Entity_Id := Etype (N);
7464 if Is_Access_Type (Typ) then
7466 Dtyp : constant Entity_Id := Designated_Type (Typ);
7469 return Is_Volatile (Dtyp)
7470 or else Has_Volatile_Components (Dtyp);
7474 return Object_Has_Volatile_Components (N);
7476 end Is_Volatile_Prefix;
7478 ------------------------------------
7479 -- Object_Has_Volatile_Components --
7480 ------------------------------------
7482 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
7483 Typ : constant Entity_Id := Etype (N);
7486 if Is_Volatile (Typ)
7487 or else Has_Volatile_Components (Typ)
7491 elsif Is_Entity_Name (N)
7492 and then (Has_Volatile_Components (Entity (N))
7493 or else Is_Volatile (Entity (N)))
7497 elsif Nkind (N) = N_Indexed_Component
7498 or else Nkind (N) = N_Selected_Component
7500 return Is_Volatile_Prefix (Prefix (N));
7505 end Object_Has_Volatile_Components;
7507 -- Start of processing for Is_Volatile_Object
7510 if Is_Volatile (Etype (N))
7511 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
7515 elsif Nkind (N) = N_Indexed_Component
7516 or else Nkind (N) = N_Selected_Component
7518 return Is_Volatile_Prefix (Prefix (N));
7523 end Is_Volatile_Object;
7525 -------------------------
7526 -- Kill_Current_Values --
7527 -------------------------
7529 procedure Kill_Current_Values
7531 Last_Assignment_Only : Boolean := False)
7534 -- ??? do we have to worry about clearing cached checks?
7536 if Is_Assignable (Ent) then
7537 Set_Last_Assignment (Ent, Empty);
7540 if Is_Object (Ent) then
7541 if not Last_Assignment_Only then
7543 Set_Current_Value (Ent, Empty);
7545 if not Can_Never_Be_Null (Ent) then
7546 Set_Is_Known_Non_Null (Ent, False);
7549 Set_Is_Known_Null (Ent, False);
7551 -- Reset Is_Known_Valid unless type is always valid, or if we have
7552 -- a loop parameter (loop parameters are always valid, since their
7553 -- bounds are defined by the bounds given in the loop header).
7555 if not Is_Known_Valid (Etype (Ent))
7556 and then Ekind (Ent) /= E_Loop_Parameter
7558 Set_Is_Known_Valid (Ent, False);
7562 end Kill_Current_Values;
7564 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
7567 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
7568 -- Clear current value for entity E and all entities chained to E
7570 ------------------------------------------
7571 -- Kill_Current_Values_For_Entity_Chain --
7572 ------------------------------------------
7574 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
7578 while Present (Ent) loop
7579 Kill_Current_Values (Ent, Last_Assignment_Only);
7582 end Kill_Current_Values_For_Entity_Chain;
7584 -- Start of processing for Kill_Current_Values
7587 -- Kill all saved checks, a special case of killing saved values
7589 if not Last_Assignment_Only then
7593 -- Loop through relevant scopes, which includes the current scope and
7594 -- any parent scopes if the current scope is a block or a package.
7599 -- Clear current values of all entities in current scope
7601 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
7603 -- If scope is a package, also clear current values of all
7604 -- private entities in the scope.
7606 if Is_Package_Or_Generic_Package (S)
7607 or else Is_Concurrent_Type (S)
7609 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
7612 -- If this is a not a subprogram, deal with parents
7614 if not Is_Subprogram (S) then
7616 exit Scope_Loop when S = Standard_Standard;
7620 end loop Scope_Loop;
7621 end Kill_Current_Values;
7623 --------------------------
7624 -- Kill_Size_Check_Code --
7625 --------------------------
7627 procedure Kill_Size_Check_Code (E : Entity_Id) is
7629 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7630 and then Present (Size_Check_Code (E))
7632 Remove (Size_Check_Code (E));
7633 Set_Size_Check_Code (E, Empty);
7635 end Kill_Size_Check_Code;
7637 --------------------------
7638 -- Known_To_Be_Assigned --
7639 --------------------------
7641 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
7642 P : constant Node_Id := Parent (N);
7647 -- Test left side of assignment
7649 when N_Assignment_Statement =>
7650 return N = Name (P);
7652 -- Function call arguments are never lvalues
7654 when N_Function_Call =>
7657 -- Positional parameter for procedure or accept call
7659 when N_Procedure_Call_Statement |
7668 Proc := Get_Subprogram_Entity (P);
7674 -- If we are not a list member, something is strange, so
7675 -- be conservative and return False.
7677 if not Is_List_Member (N) then
7681 -- We are going to find the right formal by stepping forward
7682 -- through the formals, as we step backwards in the actuals.
7684 Form := First_Formal (Proc);
7687 -- If no formal, something is weird, so be conservative
7688 -- and return False.
7699 return Ekind (Form) /= E_In_Parameter;
7702 -- Named parameter for procedure or accept call
7704 when N_Parameter_Association =>
7710 Proc := Get_Subprogram_Entity (Parent (P));
7716 -- Loop through formals to find the one that matches
7718 Form := First_Formal (Proc);
7720 -- If no matching formal, that's peculiar, some kind of
7721 -- previous error, so return False to be conservative.
7727 -- Else test for match
7729 if Chars (Form) = Chars (Selector_Name (P)) then
7730 return Ekind (Form) /= E_In_Parameter;
7737 -- Test for appearing in a conversion that itself appears
7738 -- in an lvalue context, since this should be an lvalue.
7740 when N_Type_Conversion =>
7741 return Known_To_Be_Assigned (P);
7743 -- All other references are definitely not known to be modifications
7749 end Known_To_Be_Assigned;
7755 function May_Be_Lvalue (N : Node_Id) return Boolean is
7756 P : constant Node_Id := Parent (N);
7761 -- Test left side of assignment
7763 when N_Assignment_Statement =>
7764 return N = Name (P);
7766 -- Test prefix of component or attribute. Note that the prefix of an
7767 -- explicit or implicit dereference cannot be an l-value.
7769 when N_Attribute_Reference =>
7770 return N = Prefix (P)
7771 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
7773 -- For an expanded name, the name is an lvalue if the expanded name
7774 -- is an lvalue, but the prefix is never an lvalue, since it is just
7775 -- the scope where the name is found.
7777 when N_Expanded_Name =>
7778 if N = Prefix (P) then
7779 return May_Be_Lvalue (P);
7784 -- For a selected component A.B, A is certainly an lvalue if A.B is.
7785 -- B is a little interesting, if we have A.B := 3, there is some
7786 -- discussion as to whether B is an lvalue or not, we choose to say
7787 -- it is. Note however that A is not an lvalue if it is of an access
7788 -- type since this is an implicit dereference.
7790 when N_Selected_Component =>
7792 and then Present (Etype (N))
7793 and then Is_Access_Type (Etype (N))
7797 return May_Be_Lvalue (P);
7800 -- For an indexed component or slice, the index or slice bounds is
7801 -- never an lvalue. The prefix is an lvalue if the indexed component
7802 -- or slice is an lvalue, except if it is an access type, where we
7803 -- have an implicit dereference.
7805 when N_Indexed_Component =>
7807 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
7811 return May_Be_Lvalue (P);
7814 -- Prefix of a reference is an lvalue if the reference is an lvalue
7817 return May_Be_Lvalue (P);
7819 -- Prefix of explicit dereference is never an lvalue
7821 when N_Explicit_Dereference =>
7824 -- Function call arguments are never lvalues
7826 when N_Function_Call =>
7829 -- Positional parameter for procedure, entry, or accept call
7831 when N_Procedure_Call_Statement |
7832 N_Entry_Call_Statement |
7841 Proc := Get_Subprogram_Entity (P);
7847 -- If we are not a list member, something is strange, so
7848 -- be conservative and return True.
7850 if not Is_List_Member (N) then
7854 -- We are going to find the right formal by stepping forward
7855 -- through the formals, as we step backwards in the actuals.
7857 Form := First_Formal (Proc);
7860 -- If no formal, something is weird, so be conservative
7872 return Ekind (Form) /= E_In_Parameter;
7875 -- Named parameter for procedure or accept call
7877 when N_Parameter_Association =>
7883 Proc := Get_Subprogram_Entity (Parent (P));
7889 -- Loop through formals to find the one that matches
7891 Form := First_Formal (Proc);
7893 -- If no matching formal, that's peculiar, some kind of
7894 -- previous error, so return True to be conservative.
7900 -- Else test for match
7902 if Chars (Form) = Chars (Selector_Name (P)) then
7903 return Ekind (Form) /= E_In_Parameter;
7910 -- Test for appearing in a conversion that itself appears in an
7911 -- lvalue context, since this should be an lvalue.
7913 when N_Type_Conversion =>
7914 return May_Be_Lvalue (P);
7916 -- Test for appearance in object renaming declaration
7918 when N_Object_Renaming_Declaration =>
7921 -- All other references are definitely not lvalues
7929 -----------------------
7930 -- Mark_Coextensions --
7931 -----------------------
7933 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
7934 Is_Dynamic : Boolean;
7935 -- Indicates whether the context causes nested coextensions to be
7936 -- dynamic or static
7938 function Mark_Allocator (N : Node_Id) return Traverse_Result;
7939 -- Recognize an allocator node and label it as a dynamic coextension
7941 --------------------
7942 -- Mark_Allocator --
7943 --------------------
7945 function Mark_Allocator (N : Node_Id) return Traverse_Result is
7947 if Nkind (N) = N_Allocator then
7949 Set_Is_Dynamic_Coextension (N);
7951 -- If the allocator expression is potentially dynamic, it may
7952 -- be expanded out of order and require dynamic allocation
7953 -- anyway, so we treat the coextension itself as dynamic.
7954 -- Potential optimization ???
7956 elsif Nkind (Expression (N)) = N_Qualified_Expression
7957 and then Nkind (Expression (Expression (N))) = N_Op_Concat
7959 Set_Is_Dynamic_Coextension (N);
7962 Set_Is_Static_Coextension (N);
7969 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
7971 -- Start of processing Mark_Coextensions
7974 case Nkind (Context_Nod) is
7975 when N_Assignment_Statement |
7976 N_Simple_Return_Statement =>
7977 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
7979 when N_Object_Declaration =>
7980 Is_Dynamic := Nkind (Root_Nod) = N_Allocator;
7982 -- This routine should not be called for constructs which may not
7983 -- contain coextensions.
7986 raise Program_Error;
7989 Mark_Allocators (Root_Nod);
7990 end Mark_Coextensions;
7992 ----------------------
7993 -- Needs_One_Actual --
7994 ----------------------
7996 function Needs_One_Actual (E : Entity_Id) return Boolean is
8000 if Ada_Version >= Ada_05
8001 and then Present (First_Formal (E))
8003 Formal := Next_Formal (First_Formal (E));
8004 while Present (Formal) loop
8005 if No (Default_Value (Formal)) then
8009 Next_Formal (Formal);
8017 end Needs_One_Actual;
8019 ------------------------
8020 -- New_Copy_List_Tree --
8021 ------------------------
8023 function New_Copy_List_Tree (List : List_Id) return List_Id is
8028 if List = No_List then
8035 while Present (E) loop
8036 Append (New_Copy_Tree (E), NL);
8042 end New_Copy_List_Tree;
8048 use Atree.Unchecked_Access;
8049 use Atree_Private_Part;
8051 -- Our approach here requires a two pass traversal of the tree. The
8052 -- first pass visits all nodes that eventually will be copied looking
8053 -- for defining Itypes. If any defining Itypes are found, then they are
8054 -- copied, and an entry is added to the replacement map. In the second
8055 -- phase, the tree is copied, using the replacement map to replace any
8056 -- Itype references within the copied tree.
8058 -- The following hash tables are used if the Map supplied has more
8059 -- than hash threshhold entries to speed up access to the map. If
8060 -- there are fewer entries, then the map is searched sequentially
8061 -- (because setting up a hash table for only a few entries takes
8062 -- more time than it saves.
8064 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
8065 -- Hash function used for hash operations
8071 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
8073 return Nat (E) mod (NCT_Header_Num'Last + 1);
8080 -- The hash table NCT_Assoc associates old entities in the table
8081 -- with their corresponding new entities (i.e. the pairs of entries
8082 -- presented in the original Map argument are Key-Element pairs).
8084 package NCT_Assoc is new Simple_HTable (
8085 Header_Num => NCT_Header_Num,
8086 Element => Entity_Id,
8087 No_Element => Empty,
8089 Hash => New_Copy_Hash,
8090 Equal => Types."=");
8092 ---------------------
8093 -- NCT_Itype_Assoc --
8094 ---------------------
8096 -- The hash table NCT_Itype_Assoc contains entries only for those
8097 -- old nodes which have a non-empty Associated_Node_For_Itype set.
8098 -- The key is the associated node, and the element is the new node
8099 -- itself (NOT the associated node for the new node).
8101 package NCT_Itype_Assoc is new Simple_HTable (
8102 Header_Num => NCT_Header_Num,
8103 Element => Entity_Id,
8104 No_Element => Empty,
8106 Hash => New_Copy_Hash,
8107 Equal => Types."=");
8109 -- Start of processing for New_Copy_Tree function
8111 function New_Copy_Tree
8113 Map : Elist_Id := No_Elist;
8114 New_Sloc : Source_Ptr := No_Location;
8115 New_Scope : Entity_Id := Empty) return Node_Id
8117 Actual_Map : Elist_Id := Map;
8118 -- This is the actual map for the copy. It is initialized with the
8119 -- given elements, and then enlarged as required for Itypes that are
8120 -- copied during the first phase of the copy operation. The visit
8121 -- procedures add elements to this map as Itypes are encountered.
8122 -- The reason we cannot use Map directly, is that it may well be
8123 -- (and normally is) initialized to No_Elist, and if we have mapped
8124 -- entities, we have to reset it to point to a real Elist.
8126 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
8127 -- Called during second phase to map entities into their corresponding
8128 -- copies using Actual_Map. If the argument is not an entity, or is not
8129 -- in Actual_Map, then it is returned unchanged.
8131 procedure Build_NCT_Hash_Tables;
8132 -- Builds hash tables (number of elements >= threshold value)
8134 function Copy_Elist_With_Replacement
8135 (Old_Elist : Elist_Id) return Elist_Id;
8136 -- Called during second phase to copy element list doing replacements
8138 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
8139 -- Called during the second phase to process a copied Itype. The actual
8140 -- copy happened during the first phase (so that we could make the entry
8141 -- in the mapping), but we still have to deal with the descendents of
8142 -- the copied Itype and copy them where necessary.
8144 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
8145 -- Called during second phase to copy list doing replacements
8147 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
8148 -- Called during second phase to copy node doing replacements
8150 procedure Visit_Elist (E : Elist_Id);
8151 -- Called during first phase to visit all elements of an Elist
8153 procedure Visit_Field (F : Union_Id; N : Node_Id);
8154 -- Visit a single field, recursing to call Visit_Node or Visit_List
8155 -- if the field is a syntactic descendent of the current node (i.e.
8156 -- its parent is Node N).
8158 procedure Visit_Itype (Old_Itype : Entity_Id);
8159 -- Called during first phase to visit subsidiary fields of a defining
8160 -- Itype, and also create a copy and make an entry in the replacement
8161 -- map for the new copy.
8163 procedure Visit_List (L : List_Id);
8164 -- Called during first phase to visit all elements of a List
8166 procedure Visit_Node (N : Node_Or_Entity_Id);
8167 -- Called during first phase to visit a node and all its subtrees
8173 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
8178 if not Has_Extension (N) or else No (Actual_Map) then
8181 elsif NCT_Hash_Tables_Used then
8182 Ent := NCT_Assoc.Get (Entity_Id (N));
8184 if Present (Ent) then
8190 -- No hash table used, do serial search
8193 E := First_Elmt (Actual_Map);
8194 while Present (E) loop
8195 if Node (E) = N then
8196 return Node (Next_Elmt (E));
8198 E := Next_Elmt (Next_Elmt (E));
8206 ---------------------------
8207 -- Build_NCT_Hash_Tables --
8208 ---------------------------
8210 procedure Build_NCT_Hash_Tables is
8214 if NCT_Hash_Table_Setup then
8216 NCT_Itype_Assoc.Reset;
8219 Elmt := First_Elmt (Actual_Map);
8220 while Present (Elmt) loop
8223 -- Get new entity, and associate old and new
8226 NCT_Assoc.Set (Ent, Node (Elmt));
8228 if Is_Type (Ent) then
8230 Anode : constant Entity_Id :=
8231 Associated_Node_For_Itype (Ent);
8234 if Present (Anode) then
8236 -- Enter a link between the associated node of the
8237 -- old Itype and the new Itype, for updating later
8238 -- when node is copied.
8240 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
8248 NCT_Hash_Tables_Used := True;
8249 NCT_Hash_Table_Setup := True;
8250 end Build_NCT_Hash_Tables;
8252 ---------------------------------
8253 -- Copy_Elist_With_Replacement --
8254 ---------------------------------
8256 function Copy_Elist_With_Replacement
8257 (Old_Elist : Elist_Id) return Elist_Id
8260 New_Elist : Elist_Id;
8263 if No (Old_Elist) then
8267 New_Elist := New_Elmt_List;
8269 M := First_Elmt (Old_Elist);
8270 while Present (M) loop
8271 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
8277 end Copy_Elist_With_Replacement;
8279 ---------------------------------
8280 -- Copy_Itype_With_Replacement --
8281 ---------------------------------
8283 -- This routine exactly parallels its phase one analog Visit_Itype,
8285 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
8287 -- Translate Next_Entity, Scope and Etype fields, in case they
8288 -- reference entities that have been mapped into copies.
8290 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
8291 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
8293 if Present (New_Scope) then
8294 Set_Scope (New_Itype, New_Scope);
8296 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
8299 -- Copy referenced fields
8301 if Is_Discrete_Type (New_Itype) then
8302 Set_Scalar_Range (New_Itype,
8303 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
8305 elsif Has_Discriminants (Base_Type (New_Itype)) then
8306 Set_Discriminant_Constraint (New_Itype,
8307 Copy_Elist_With_Replacement
8308 (Discriminant_Constraint (New_Itype)));
8310 elsif Is_Array_Type (New_Itype) then
8311 if Present (First_Index (New_Itype)) then
8312 Set_First_Index (New_Itype,
8313 First (Copy_List_With_Replacement
8314 (List_Containing (First_Index (New_Itype)))));
8317 if Is_Packed (New_Itype) then
8318 Set_Packed_Array_Type (New_Itype,
8319 Copy_Node_With_Replacement
8320 (Packed_Array_Type (New_Itype)));
8323 end Copy_Itype_With_Replacement;
8325 --------------------------------
8326 -- Copy_List_With_Replacement --
8327 --------------------------------
8329 function Copy_List_With_Replacement
8330 (Old_List : List_Id) return List_Id
8336 if Old_List = No_List then
8340 New_List := Empty_List;
8342 E := First (Old_List);
8343 while Present (E) loop
8344 Append (Copy_Node_With_Replacement (E), New_List);
8350 end Copy_List_With_Replacement;
8352 --------------------------------
8353 -- Copy_Node_With_Replacement --
8354 --------------------------------
8356 function Copy_Node_With_Replacement
8357 (Old_Node : Node_Id) return Node_Id
8361 procedure Adjust_Named_Associations
8362 (Old_Node : Node_Id;
8363 New_Node : Node_Id);
8364 -- If a call node has named associations, these are chained through
8365 -- the First_Named_Actual, Next_Named_Actual links. These must be
8366 -- propagated separately to the new parameter list, because these
8367 -- are not syntactic fields.
8369 function Copy_Field_With_Replacement
8370 (Field : Union_Id) return Union_Id;
8371 -- Given Field, which is a field of Old_Node, return a copy of it
8372 -- if it is a syntactic field (i.e. its parent is Node), setting
8373 -- the parent of the copy to poit to New_Node. Otherwise returns
8374 -- the field (possibly mapped if it is an entity).
8376 -------------------------------
8377 -- Adjust_Named_Associations --
8378 -------------------------------
8380 procedure Adjust_Named_Associations
8381 (Old_Node : Node_Id;
8391 Old_E := First (Parameter_Associations (Old_Node));
8392 New_E := First (Parameter_Associations (New_Node));
8393 while Present (Old_E) loop
8394 if Nkind (Old_E) = N_Parameter_Association
8395 and then Present (Next_Named_Actual (Old_E))
8397 if First_Named_Actual (Old_Node)
8398 = Explicit_Actual_Parameter (Old_E)
8400 Set_First_Named_Actual
8401 (New_Node, Explicit_Actual_Parameter (New_E));
8404 -- Now scan parameter list from the beginning,to locate
8405 -- next named actual, which can be out of order.
8407 Old_Next := First (Parameter_Associations (Old_Node));
8408 New_Next := First (Parameter_Associations (New_Node));
8410 while Nkind (Old_Next) /= N_Parameter_Association
8411 or else Explicit_Actual_Parameter (Old_Next)
8412 /= Next_Named_Actual (Old_E)
8418 Set_Next_Named_Actual
8419 (New_E, Explicit_Actual_Parameter (New_Next));
8425 end Adjust_Named_Associations;
8427 ---------------------------------
8428 -- Copy_Field_With_Replacement --
8429 ---------------------------------
8431 function Copy_Field_With_Replacement
8432 (Field : Union_Id) return Union_Id
8435 if Field = Union_Id (Empty) then
8438 elsif Field in Node_Range then
8440 Old_N : constant Node_Id := Node_Id (Field);
8444 -- If syntactic field, as indicated by the parent pointer
8445 -- being set, then copy the referenced node recursively.
8447 if Parent (Old_N) = Old_Node then
8448 New_N := Copy_Node_With_Replacement (Old_N);
8450 if New_N /= Old_N then
8451 Set_Parent (New_N, New_Node);
8454 -- For semantic fields, update possible entity reference
8455 -- from the replacement map.
8458 New_N := Assoc (Old_N);
8461 return Union_Id (New_N);
8464 elsif Field in List_Range then
8466 Old_L : constant List_Id := List_Id (Field);
8470 -- If syntactic field, as indicated by the parent pointer,
8471 -- then recursively copy the entire referenced list.
8473 if Parent (Old_L) = Old_Node then
8474 New_L := Copy_List_With_Replacement (Old_L);
8475 Set_Parent (New_L, New_Node);
8477 -- For semantic list, just returned unchanged
8483 return Union_Id (New_L);
8486 -- Anything other than a list or a node is returned unchanged
8491 end Copy_Field_With_Replacement;
8493 -- Start of processing for Copy_Node_With_Replacement
8496 if Old_Node <= Empty_Or_Error then
8499 elsif Has_Extension (Old_Node) then
8500 return Assoc (Old_Node);
8503 New_Node := New_Copy (Old_Node);
8505 -- If the node we are copying is the associated node of a
8506 -- previously copied Itype, then adjust the associated node
8507 -- of the copy of that Itype accordingly.
8509 if Present (Actual_Map) then
8515 -- Case of hash table used
8517 if NCT_Hash_Tables_Used then
8518 Ent := NCT_Itype_Assoc.Get (Old_Node);
8520 if Present (Ent) then
8521 Set_Associated_Node_For_Itype (Ent, New_Node);
8524 -- Case of no hash table used
8527 E := First_Elmt (Actual_Map);
8528 while Present (E) loop
8529 if Is_Itype (Node (E))
8531 Old_Node = Associated_Node_For_Itype (Node (E))
8533 Set_Associated_Node_For_Itype
8534 (Node (Next_Elmt (E)), New_Node);
8537 E := Next_Elmt (Next_Elmt (E));
8543 -- Recursively copy descendents
8546 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
8548 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
8550 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
8552 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
8554 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
8556 -- Adjust Sloc of new node if necessary
8558 if New_Sloc /= No_Location then
8559 Set_Sloc (New_Node, New_Sloc);
8561 -- If we adjust the Sloc, then we are essentially making
8562 -- a completely new node, so the Comes_From_Source flag
8563 -- should be reset to the proper default value.
8565 Nodes.Table (New_Node).Comes_From_Source :=
8566 Default_Node.Comes_From_Source;
8569 -- If the node is call and has named associations,
8570 -- set the corresponding links in the copy.
8572 if (Nkind (Old_Node) = N_Function_Call
8573 or else Nkind (Old_Node) = N_Entry_Call_Statement
8575 Nkind (Old_Node) = N_Procedure_Call_Statement)
8576 and then Present (First_Named_Actual (Old_Node))
8578 Adjust_Named_Associations (Old_Node, New_Node);
8581 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
8582 -- The replacement mechanism applies to entities, and is not used
8583 -- here. Eventually we may need a more general graph-copying
8584 -- routine. For now, do a sequential search to find desired node.
8586 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
8587 and then Present (First_Real_Statement (Old_Node))
8590 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
8594 N1 := First (Statements (Old_Node));
8595 N2 := First (Statements (New_Node));
8597 while N1 /= Old_F loop
8602 Set_First_Real_Statement (New_Node, N2);
8607 -- All done, return copied node
8610 end Copy_Node_With_Replacement;
8616 procedure Visit_Elist (E : Elist_Id) is
8620 Elmt := First_Elmt (E);
8622 while Elmt /= No_Elmt loop
8623 Visit_Node (Node (Elmt));
8633 procedure Visit_Field (F : Union_Id; N : Node_Id) is
8635 if F = Union_Id (Empty) then
8638 elsif F in Node_Range then
8640 -- Copy node if it is syntactic, i.e. its parent pointer is
8641 -- set to point to the field that referenced it (certain
8642 -- Itypes will also meet this criterion, which is fine, since
8643 -- these are clearly Itypes that do need to be copied, since
8644 -- we are copying their parent.)
8646 if Parent (Node_Id (F)) = N then
8647 Visit_Node (Node_Id (F));
8650 -- Another case, if we are pointing to an Itype, then we want
8651 -- to copy it if its associated node is somewhere in the tree
8654 -- Note: the exclusion of self-referential copies is just an
8655 -- optimization, since the search of the already copied list
8656 -- would catch it, but it is a common case (Etype pointing
8657 -- to itself for an Itype that is a base type).
8659 elsif Has_Extension (Node_Id (F))
8660 and then Is_Itype (Entity_Id (F))
8661 and then Node_Id (F) /= N
8667 P := Associated_Node_For_Itype (Node_Id (F));
8668 while Present (P) loop
8670 Visit_Node (Node_Id (F));
8677 -- An Itype whose parent is not being copied definitely
8678 -- should NOT be copied, since it does not belong in any
8679 -- sense to the copied subtree.
8685 elsif F in List_Range
8686 and then Parent (List_Id (F)) = N
8688 Visit_List (List_Id (F));
8697 procedure Visit_Itype (Old_Itype : Entity_Id) is
8698 New_Itype : Entity_Id;
8703 -- Itypes that describe the designated type of access to subprograms
8704 -- have the structure of subprogram declarations, with signatures,
8705 -- etc. Either we duplicate the signatures completely, or choose to
8706 -- share such itypes, which is fine because their elaboration will
8707 -- have no side effects.
8709 if Ekind (Old_Itype) = E_Subprogram_Type then
8713 New_Itype := New_Copy (Old_Itype);
8715 -- The new Itype has all the attributes of the old one, and
8716 -- we just copy the contents of the entity. However, the back-end
8717 -- needs different names for debugging purposes, so we create a
8718 -- new internal name for it in all cases.
8720 Set_Chars (New_Itype, New_Internal_Name ('T'));
8722 -- If our associated node is an entity that has already been copied,
8723 -- then set the associated node of the copy to point to the right
8724 -- copy. If we have copied an Itype that is itself the associated
8725 -- node of some previously copied Itype, then we set the right
8726 -- pointer in the other direction.
8728 if Present (Actual_Map) then
8730 -- Case of hash tables used
8732 if NCT_Hash_Tables_Used then
8734 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
8736 if Present (Ent) then
8737 Set_Associated_Node_For_Itype (New_Itype, Ent);
8740 Ent := NCT_Itype_Assoc.Get (Old_Itype);
8741 if Present (Ent) then
8742 Set_Associated_Node_For_Itype (Ent, New_Itype);
8744 -- If the hash table has no association for this Itype and
8745 -- its associated node, enter one now.
8749 (Associated_Node_For_Itype (Old_Itype), New_Itype);
8752 -- Case of hash tables not used
8755 E := First_Elmt (Actual_Map);
8756 while Present (E) loop
8757 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
8758 Set_Associated_Node_For_Itype
8759 (New_Itype, Node (Next_Elmt (E)));
8762 if Is_Type (Node (E))
8764 Old_Itype = Associated_Node_For_Itype (Node (E))
8766 Set_Associated_Node_For_Itype
8767 (Node (Next_Elmt (E)), New_Itype);
8770 E := Next_Elmt (Next_Elmt (E));
8775 if Present (Freeze_Node (New_Itype)) then
8776 Set_Is_Frozen (New_Itype, False);
8777 Set_Freeze_Node (New_Itype, Empty);
8780 -- Add new association to map
8782 if No (Actual_Map) then
8783 Actual_Map := New_Elmt_List;
8786 Append_Elmt (Old_Itype, Actual_Map);
8787 Append_Elmt (New_Itype, Actual_Map);
8789 if NCT_Hash_Tables_Used then
8790 NCT_Assoc.Set (Old_Itype, New_Itype);
8793 NCT_Table_Entries := NCT_Table_Entries + 1;
8795 if NCT_Table_Entries > NCT_Hash_Threshhold then
8796 Build_NCT_Hash_Tables;
8800 -- If a record subtype is simply copied, the entity list will be
8801 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
8803 if Ekind_In (Old_Itype, E_Record_Subtype, E_Class_Wide_Subtype) then
8804 Set_Cloned_Subtype (New_Itype, Old_Itype);
8807 -- Visit descendents that eventually get copied
8809 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
8811 if Is_Discrete_Type (Old_Itype) then
8812 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
8814 elsif Has_Discriminants (Base_Type (Old_Itype)) then
8815 -- ??? This should involve call to Visit_Field
8816 Visit_Elist (Discriminant_Constraint (Old_Itype));
8818 elsif Is_Array_Type (Old_Itype) then
8819 if Present (First_Index (Old_Itype)) then
8820 Visit_Field (Union_Id (List_Containing
8821 (First_Index (Old_Itype))),
8825 if Is_Packed (Old_Itype) then
8826 Visit_Field (Union_Id (Packed_Array_Type (Old_Itype)),
8836 procedure Visit_List (L : List_Id) is
8839 if L /= No_List then
8842 while Present (N) loop
8853 procedure Visit_Node (N : Node_Or_Entity_Id) is
8855 -- Start of processing for Visit_Node
8858 -- Handle case of an Itype, which must be copied
8860 if Has_Extension (N)
8861 and then Is_Itype (N)
8863 -- Nothing to do if already in the list. This can happen with an
8864 -- Itype entity that appears more than once in the tree.
8865 -- Note that we do not want to visit descendents in this case.
8867 -- Test for already in list when hash table is used
8869 if NCT_Hash_Tables_Used then
8870 if Present (NCT_Assoc.Get (Entity_Id (N))) then
8874 -- Test for already in list when hash table not used
8880 if Present (Actual_Map) then
8881 E := First_Elmt (Actual_Map);
8882 while Present (E) loop
8883 if Node (E) = N then
8886 E := Next_Elmt (Next_Elmt (E));
8896 -- Visit descendents
8898 Visit_Field (Field1 (N), N);
8899 Visit_Field (Field2 (N), N);
8900 Visit_Field (Field3 (N), N);
8901 Visit_Field (Field4 (N), N);
8902 Visit_Field (Field5 (N), N);
8905 -- Start of processing for New_Copy_Tree
8910 -- See if we should use hash table
8912 if No (Actual_Map) then
8913 NCT_Hash_Tables_Used := False;
8920 NCT_Table_Entries := 0;
8922 Elmt := First_Elmt (Actual_Map);
8923 while Present (Elmt) loop
8924 NCT_Table_Entries := NCT_Table_Entries + 1;
8929 if NCT_Table_Entries > NCT_Hash_Threshhold then
8930 Build_NCT_Hash_Tables;
8932 NCT_Hash_Tables_Used := False;
8937 -- Hash table set up if required, now start phase one by visiting
8938 -- top node (we will recursively visit the descendents).
8940 Visit_Node (Source);
8942 -- Now the second phase of the copy can start. First we process
8943 -- all the mapped entities, copying their descendents.
8945 if Present (Actual_Map) then
8948 New_Itype : Entity_Id;
8950 Elmt := First_Elmt (Actual_Map);
8951 while Present (Elmt) loop
8953 New_Itype := Node (Elmt);
8954 Copy_Itype_With_Replacement (New_Itype);
8960 -- Now we can copy the actual tree
8962 return Copy_Node_With_Replacement (Source);
8965 -------------------------
8966 -- New_External_Entity --
8967 -------------------------
8969 function New_External_Entity
8970 (Kind : Entity_Kind;
8971 Scope_Id : Entity_Id;
8972 Sloc_Value : Source_Ptr;
8973 Related_Id : Entity_Id;
8975 Suffix_Index : Nat := 0;
8976 Prefix : Character := ' ') return Entity_Id
8978 N : constant Entity_Id :=
8979 Make_Defining_Identifier (Sloc_Value,
8981 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
8984 Set_Ekind (N, Kind);
8985 Set_Is_Internal (N, True);
8986 Append_Entity (N, Scope_Id);
8987 Set_Public_Status (N);
8989 if Kind in Type_Kind then
8990 Init_Size_Align (N);
8994 end New_External_Entity;
8996 -------------------------
8997 -- New_Internal_Entity --
8998 -------------------------
9000 function New_Internal_Entity
9001 (Kind : Entity_Kind;
9002 Scope_Id : Entity_Id;
9003 Sloc_Value : Source_Ptr;
9004 Id_Char : Character) return Entity_Id
9006 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
9009 Set_Ekind (N, Kind);
9010 Set_Is_Internal (N, True);
9011 Append_Entity (N, Scope_Id);
9013 if Kind in Type_Kind then
9014 Init_Size_Align (N);
9018 end New_Internal_Entity;
9024 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
9028 -- If we are pointing at a positional parameter, it is a member of a
9029 -- node list (the list of parameters), and the next parameter is the
9030 -- next node on the list, unless we hit a parameter association, then
9031 -- we shift to using the chain whose head is the First_Named_Actual in
9032 -- the parent, and then is threaded using the Next_Named_Actual of the
9033 -- Parameter_Association. All this fiddling is because the original node
9034 -- list is in the textual call order, and what we need is the
9035 -- declaration order.
9037 if Is_List_Member (Actual_Id) then
9038 N := Next (Actual_Id);
9040 if Nkind (N) = N_Parameter_Association then
9041 return First_Named_Actual (Parent (Actual_Id));
9047 return Next_Named_Actual (Parent (Actual_Id));
9051 procedure Next_Actual (Actual_Id : in out Node_Id) is
9053 Actual_Id := Next_Actual (Actual_Id);
9056 -----------------------
9057 -- Normalize_Actuals --
9058 -----------------------
9060 -- Chain actuals according to formals of subprogram. If there are no named
9061 -- associations, the chain is simply the list of Parameter Associations,
9062 -- since the order is the same as the declaration order. If there are named
9063 -- associations, then the First_Named_Actual field in the N_Function_Call
9064 -- or N_Procedure_Call_Statement node points to the Parameter_Association
9065 -- node for the parameter that comes first in declaration order. The
9066 -- remaining named parameters are then chained in declaration order using
9067 -- Next_Named_Actual.
9069 -- This routine also verifies that the number of actuals is compatible with
9070 -- the number and default values of formals, but performs no type checking
9071 -- (type checking is done by the caller).
9073 -- If the matching succeeds, Success is set to True and the caller proceeds
9074 -- with type-checking. If the match is unsuccessful, then Success is set to
9075 -- False, and the caller attempts a different interpretation, if there is
9078 -- If the flag Report is on, the call is not overloaded, and a failure to
9079 -- match can be reported here, rather than in the caller.
9081 procedure Normalize_Actuals
9085 Success : out Boolean)
9087 Actuals : constant List_Id := Parameter_Associations (N);
9088 Actual : Node_Id := Empty;
9090 Last : Node_Id := Empty;
9091 First_Named : Node_Id := Empty;
9094 Formals_To_Match : Integer := 0;
9095 Actuals_To_Match : Integer := 0;
9097 procedure Chain (A : Node_Id);
9098 -- Add named actual at the proper place in the list, using the
9099 -- Next_Named_Actual link.
9101 function Reporting return Boolean;
9102 -- Determines if an error is to be reported. To report an error, we
9103 -- need Report to be True, and also we do not report errors caused
9104 -- by calls to init procs that occur within other init procs. Such
9105 -- errors must always be cascaded errors, since if all the types are
9106 -- declared correctly, the compiler will certainly build decent calls!
9112 procedure Chain (A : Node_Id) is
9116 -- Call node points to first actual in list
9118 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
9121 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
9125 Set_Next_Named_Actual (Last, Empty);
9132 function Reporting return Boolean is
9137 elsif not Within_Init_Proc then
9140 elsif Is_Init_Proc (Entity (Name (N))) then
9148 -- Start of processing for Normalize_Actuals
9151 if Is_Access_Type (S) then
9153 -- The name in the call is a function call that returns an access
9154 -- to subprogram. The designated type has the list of formals.
9156 Formal := First_Formal (Designated_Type (S));
9158 Formal := First_Formal (S);
9161 while Present (Formal) loop
9162 Formals_To_Match := Formals_To_Match + 1;
9163 Next_Formal (Formal);
9166 -- Find if there is a named association, and verify that no positional
9167 -- associations appear after named ones.
9169 if Present (Actuals) then
9170 Actual := First (Actuals);
9173 while Present (Actual)
9174 and then Nkind (Actual) /= N_Parameter_Association
9176 Actuals_To_Match := Actuals_To_Match + 1;
9180 if No (Actual) and Actuals_To_Match = Formals_To_Match then
9182 -- Most common case: positional notation, no defaults
9187 elsif Actuals_To_Match > Formals_To_Match then
9189 -- Too many actuals: will not work
9192 if Is_Entity_Name (Name (N)) then
9193 Error_Msg_N ("too many arguments in call to&", Name (N));
9195 Error_Msg_N ("too many arguments in call", N);
9203 First_Named := Actual;
9205 while Present (Actual) loop
9206 if Nkind (Actual) /= N_Parameter_Association then
9208 ("positional parameters not allowed after named ones", Actual);
9213 Actuals_To_Match := Actuals_To_Match + 1;
9219 if Present (Actuals) then
9220 Actual := First (Actuals);
9223 Formal := First_Formal (S);
9224 while Present (Formal) loop
9226 -- Match the formals in order. If the corresponding actual is
9227 -- positional, nothing to do. Else scan the list of named actuals
9228 -- to find the one with the right name.
9231 and then Nkind (Actual) /= N_Parameter_Association
9234 Actuals_To_Match := Actuals_To_Match - 1;
9235 Formals_To_Match := Formals_To_Match - 1;
9238 -- For named parameters, search the list of actuals to find
9239 -- one that matches the next formal name.
9241 Actual := First_Named;
9243 while Present (Actual) loop
9244 if Chars (Selector_Name (Actual)) = Chars (Formal) then
9247 Actuals_To_Match := Actuals_To_Match - 1;
9248 Formals_To_Match := Formals_To_Match - 1;
9256 if Ekind (Formal) /= E_In_Parameter
9257 or else No (Default_Value (Formal))
9260 if (Comes_From_Source (S)
9261 or else Sloc (S) = Standard_Location)
9262 and then Is_Overloadable (S)
9266 (Nkind (Parent (N)) = N_Procedure_Call_Statement
9268 (Nkind (Parent (N)) = N_Function_Call
9270 Nkind (Parent (N)) = N_Parameter_Association))
9271 and then Ekind (S) /= E_Function
9273 Set_Etype (N, Etype (S));
9275 Error_Msg_Name_1 := Chars (S);
9276 Error_Msg_Sloc := Sloc (S);
9278 ("missing argument for parameter & " &
9279 "in call to % declared #", N, Formal);
9282 elsif Is_Overloadable (S) then
9283 Error_Msg_Name_1 := Chars (S);
9285 -- Point to type derivation that generated the
9288 Error_Msg_Sloc := Sloc (Parent (S));
9291 ("missing argument for parameter & " &
9292 "in call to % (inherited) #", N, Formal);
9296 ("missing argument for parameter &", N, Formal);
9304 Formals_To_Match := Formals_To_Match - 1;
9309 Next_Formal (Formal);
9312 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
9319 -- Find some superfluous named actual that did not get
9320 -- attached to the list of associations.
9322 Actual := First (Actuals);
9323 while Present (Actual) loop
9324 if Nkind (Actual) = N_Parameter_Association
9325 and then Actual /= Last
9326 and then No (Next_Named_Actual (Actual))
9328 Error_Msg_N ("unmatched actual & in call",
9329 Selector_Name (Actual));
9340 end Normalize_Actuals;
9342 --------------------------------
9343 -- Note_Possible_Modification --
9344 --------------------------------
9346 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
9347 Modification_Comes_From_Source : constant Boolean :=
9348 Comes_From_Source (Parent (N));
9354 -- Loop to find referenced entity, if there is one
9361 if Is_Entity_Name (Exp) then
9362 Ent := Entity (Exp);
9364 -- If the entity is missing, it is an undeclared identifier,
9365 -- and there is nothing to annotate.
9371 elsif Nkind (Exp) = N_Explicit_Dereference then
9373 P : constant Node_Id := Prefix (Exp);
9376 if Nkind (P) = N_Selected_Component
9378 Entry_Formal (Entity (Selector_Name (P))))
9380 -- Case of a reference to an entry formal
9382 Ent := Entry_Formal (Entity (Selector_Name (P)));
9384 elsif Nkind (P) = N_Identifier
9385 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
9386 and then Present (Expression (Parent (Entity (P))))
9387 and then Nkind (Expression (Parent (Entity (P))))
9390 -- Case of a reference to a value on which side effects have
9393 Exp := Prefix (Expression (Parent (Entity (P))));
9402 elsif Nkind (Exp) = N_Type_Conversion
9403 or else Nkind (Exp) = N_Unchecked_Type_Conversion
9405 Exp := Expression (Exp);
9408 elsif Nkind (Exp) = N_Slice
9409 or else Nkind (Exp) = N_Indexed_Component
9410 or else Nkind (Exp) = N_Selected_Component
9412 Exp := Prefix (Exp);
9419 -- Now look for entity being referenced
9421 if Present (Ent) then
9422 if Is_Object (Ent) then
9423 if Comes_From_Source (Exp)
9424 or else Modification_Comes_From_Source
9426 if Has_Pragma_Unmodified (Ent) then
9427 Error_Msg_NE ("?pragma Unmodified given for &!", N, Ent);
9430 Set_Never_Set_In_Source (Ent, False);
9433 Set_Is_True_Constant (Ent, False);
9434 Set_Current_Value (Ent, Empty);
9435 Set_Is_Known_Null (Ent, False);
9437 if not Can_Never_Be_Null (Ent) then
9438 Set_Is_Known_Non_Null (Ent, False);
9441 -- Follow renaming chain
9443 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
9444 and then Present (Renamed_Object (Ent))
9446 Exp := Renamed_Object (Ent);
9450 -- Generate a reference only if the assignment comes from
9451 -- source. This excludes, for example, calls to a dispatching
9452 -- assignment operation when the left-hand side is tagged.
9454 if Modification_Comes_From_Source then
9455 Generate_Reference (Ent, Exp, 'm');
9458 Check_Nested_Access (Ent);
9463 -- If we are sure this is a modification from source, and we know
9464 -- this modifies a constant, then give an appropriate warning.
9466 if Overlays_Constant (Ent)
9467 and then Modification_Comes_From_Source
9471 A : constant Node_Id := Address_Clause (Ent);
9475 Exp : constant Node_Id := Expression (A);
9477 if Nkind (Exp) = N_Attribute_Reference
9478 and then Attribute_Name (Exp) = Name_Address
9479 and then Is_Entity_Name (Prefix (Exp))
9481 Error_Msg_Sloc := Sloc (A);
9483 ("constant& may be modified via address clause#?",
9484 N, Entity (Prefix (Exp)));
9494 end Note_Possible_Modification;
9496 -------------------------
9497 -- Object_Access_Level --
9498 -------------------------
9500 function Object_Access_Level (Obj : Node_Id) return Uint is
9503 -- Returns the static accessibility level of the view denoted by Obj. Note
9504 -- that the value returned is the result of a call to Scope_Depth. Only
9505 -- scope depths associated with dynamic scopes can actually be returned.
9506 -- Since only relative levels matter for accessibility checking, the fact
9507 -- that the distance between successive levels of accessibility is not
9508 -- always one is immaterial (invariant: if level(E2) is deeper than
9509 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
9511 function Reference_To (Obj : Node_Id) return Node_Id;
9512 -- An explicit dereference is created when removing side-effects from
9513 -- expressions for constraint checking purposes. In this case a local
9514 -- access type is created for it. The correct access level is that of
9515 -- the original source node. We detect this case by noting that the
9516 -- prefix of the dereference is created by an object declaration whose
9517 -- initial expression is a reference.
9523 function Reference_To (Obj : Node_Id) return Node_Id is
9524 Pref : constant Node_Id := Prefix (Obj);
9526 if Is_Entity_Name (Pref)
9527 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
9528 and then Present (Expression (Parent (Entity (Pref))))
9529 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
9531 return (Prefix (Expression (Parent (Entity (Pref)))));
9537 -- Start of processing for Object_Access_Level
9540 if Is_Entity_Name (Obj) then
9543 if Is_Prival (E) then
9544 E := Prival_Link (E);
9547 -- If E is a type then it denotes a current instance. For this case
9548 -- we add one to the normal accessibility level of the type to ensure
9549 -- that current instances are treated as always being deeper than
9550 -- than the level of any visible named access type (see 3.10.2(21)).
9553 return Type_Access_Level (E) + 1;
9555 elsif Present (Renamed_Object (E)) then
9556 return Object_Access_Level (Renamed_Object (E));
9558 -- Similarly, if E is a component of the current instance of a
9559 -- protected type, any instance of it is assumed to be at a deeper
9560 -- level than the type. For a protected object (whose type is an
9561 -- anonymous protected type) its components are at the same level
9562 -- as the type itself.
9564 elsif not Is_Overloadable (E)
9565 and then Ekind (Scope (E)) = E_Protected_Type
9566 and then Comes_From_Source (Scope (E))
9568 return Type_Access_Level (Scope (E)) + 1;
9571 return Scope_Depth (Enclosing_Dynamic_Scope (E));
9574 elsif Nkind (Obj) = N_Selected_Component then
9575 if Is_Access_Type (Etype (Prefix (Obj))) then
9576 return Type_Access_Level (Etype (Prefix (Obj)));
9578 return Object_Access_Level (Prefix (Obj));
9581 elsif Nkind (Obj) = N_Indexed_Component then
9582 if Is_Access_Type (Etype (Prefix (Obj))) then
9583 return Type_Access_Level (Etype (Prefix (Obj)));
9585 return Object_Access_Level (Prefix (Obj));
9588 elsif Nkind (Obj) = N_Explicit_Dereference then
9590 -- If the prefix is a selected access discriminant then we make a
9591 -- recursive call on the prefix, which will in turn check the level
9592 -- of the prefix object of the selected discriminant.
9594 if Nkind (Prefix (Obj)) = N_Selected_Component
9595 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
9597 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
9599 return Object_Access_Level (Prefix (Obj));
9601 elsif not (Comes_From_Source (Obj)) then
9603 Ref : constant Node_Id := Reference_To (Obj);
9605 if Present (Ref) then
9606 return Object_Access_Level (Ref);
9608 return Type_Access_Level (Etype (Prefix (Obj)));
9613 return Type_Access_Level (Etype (Prefix (Obj)));
9616 elsif Nkind (Obj) = N_Type_Conversion
9617 or else Nkind (Obj) = N_Unchecked_Type_Conversion
9619 return Object_Access_Level (Expression (Obj));
9621 elsif Nkind (Obj) = N_Function_Call then
9623 -- Function results are objects, so we get either the access level of
9624 -- the function or, in the case of an indirect call, the level of the
9625 -- access-to-subprogram type. (This code is used for Ada 95, but it
9626 -- looks wrong, because it seems that we should be checking the level
9627 -- of the call itself, even for Ada 95. However, using the Ada 2005
9628 -- version of the code causes regressions in several tests that are
9629 -- compiled with -gnat95. ???)
9631 if Ada_Version < Ada_05 then
9632 if Is_Entity_Name (Name (Obj)) then
9633 return Subprogram_Access_Level (Entity (Name (Obj)));
9635 return Type_Access_Level (Etype (Prefix (Name (Obj))));
9638 -- For Ada 2005, the level of the result object of a function call is
9639 -- defined to be the level of the call's innermost enclosing master.
9640 -- We determine that by querying the depth of the innermost enclosing
9644 Return_Master_Scope_Depth_Of_Call : declare
9646 function Innermost_Master_Scope_Depth
9647 (N : Node_Id) return Uint;
9648 -- Returns the scope depth of the given node's innermost
9649 -- enclosing dynamic scope (effectively the accessibility
9650 -- level of the innermost enclosing master).
9652 ----------------------------------
9653 -- Innermost_Master_Scope_Depth --
9654 ----------------------------------
9656 function Innermost_Master_Scope_Depth
9657 (N : Node_Id) return Uint
9659 Node_Par : Node_Id := Parent (N);
9662 -- Locate the nearest enclosing node (by traversing Parents)
9663 -- that Defining_Entity can be applied to, and return the
9664 -- depth of that entity's nearest enclosing dynamic scope.
9666 while Present (Node_Par) loop
9667 case Nkind (Node_Par) is
9668 when N_Component_Declaration |
9669 N_Entry_Declaration |
9670 N_Formal_Object_Declaration |
9671 N_Formal_Type_Declaration |
9672 N_Full_Type_Declaration |
9673 N_Incomplete_Type_Declaration |
9674 N_Loop_Parameter_Specification |
9675 N_Object_Declaration |
9676 N_Protected_Type_Declaration |
9677 N_Private_Extension_Declaration |
9678 N_Private_Type_Declaration |
9679 N_Subtype_Declaration |
9680 N_Function_Specification |
9681 N_Procedure_Specification |
9682 N_Task_Type_Declaration |
9684 N_Generic_Instantiation |
9686 N_Implicit_Label_Declaration |
9687 N_Package_Declaration |
9688 N_Single_Task_Declaration |
9689 N_Subprogram_Declaration |
9690 N_Generic_Declaration |
9691 N_Renaming_Declaration |
9693 N_Formal_Subprogram_Declaration |
9694 N_Abstract_Subprogram_Declaration |
9696 N_Exception_Declaration |
9697 N_Formal_Package_Declaration |
9698 N_Number_Declaration |
9699 N_Package_Specification |
9700 N_Parameter_Specification |
9701 N_Single_Protected_Declaration |
9705 (Nearest_Dynamic_Scope
9706 (Defining_Entity (Node_Par)));
9712 Node_Par := Parent (Node_Par);
9715 pragma Assert (False);
9717 -- Should never reach the following return
9719 return Scope_Depth (Current_Scope) + 1;
9720 end Innermost_Master_Scope_Depth;
9722 -- Start of processing for Return_Master_Scope_Depth_Of_Call
9725 return Innermost_Master_Scope_Depth (Obj);
9726 end Return_Master_Scope_Depth_Of_Call;
9729 -- For convenience we handle qualified expressions, even though
9730 -- they aren't technically object names.
9732 elsif Nkind (Obj) = N_Qualified_Expression then
9733 return Object_Access_Level (Expression (Obj));
9735 -- Otherwise return the scope level of Standard.
9736 -- (If there are cases that fall through
9737 -- to this point they will be treated as
9738 -- having global accessibility for now. ???)
9741 return Scope_Depth (Standard_Standard);
9743 end Object_Access_Level;
9745 -----------------------
9746 -- Private_Component --
9747 -----------------------
9749 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
9750 Ancestor : constant Entity_Id := Base_Type (Type_Id);
9752 function Trace_Components
9754 Check : Boolean) return Entity_Id;
9755 -- Recursive function that does the work, and checks against circular
9756 -- definition for each subcomponent type.
9758 ----------------------
9759 -- Trace_Components --
9760 ----------------------
9762 function Trace_Components
9764 Check : Boolean) return Entity_Id
9766 Btype : constant Entity_Id := Base_Type (T);
9767 Component : Entity_Id;
9769 Candidate : Entity_Id := Empty;
9772 if Check and then Btype = Ancestor then
9773 Error_Msg_N ("circular type definition", Type_Id);
9777 if Is_Private_Type (Btype)
9778 and then not Is_Generic_Type (Btype)
9780 if Present (Full_View (Btype))
9781 and then Is_Record_Type (Full_View (Btype))
9782 and then not Is_Frozen (Btype)
9784 -- To indicate that the ancestor depends on a private type, the
9785 -- current Btype is sufficient. However, to check for circular
9786 -- definition we must recurse on the full view.
9788 Candidate := Trace_Components (Full_View (Btype), True);
9790 if Candidate = Any_Type then
9800 elsif Is_Array_Type (Btype) then
9801 return Trace_Components (Component_Type (Btype), True);
9803 elsif Is_Record_Type (Btype) then
9804 Component := First_Entity (Btype);
9805 while Present (Component) loop
9807 -- Skip anonymous types generated by constrained components
9809 if not Is_Type (Component) then
9810 P := Trace_Components (Etype (Component), True);
9813 if P = Any_Type then
9821 Next_Entity (Component);
9829 end Trace_Components;
9831 -- Start of processing for Private_Component
9834 return Trace_Components (Type_Id, False);
9835 end Private_Component;
9837 ---------------------------
9838 -- Primitive_Names_Match --
9839 ---------------------------
9841 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
9843 function Non_Internal_Name (E : Entity_Id) return Name_Id;
9844 -- Given an internal name, returns the corresponding non-internal name
9846 ------------------------
9847 -- Non_Internal_Name --
9848 ------------------------
9850 function Non_Internal_Name (E : Entity_Id) return Name_Id is
9852 Get_Name_String (Chars (E));
9853 Name_Len := Name_Len - 1;
9855 end Non_Internal_Name;
9857 -- Start of processing for Primitive_Names_Match
9860 pragma Assert (Present (E1) and then Present (E2));
9862 return Chars (E1) = Chars (E2)
9864 (not Is_Internal_Name (Chars (E1))
9865 and then Is_Internal_Name (Chars (E2))
9866 and then Non_Internal_Name (E2) = Chars (E1))
9868 (not Is_Internal_Name (Chars (E2))
9869 and then Is_Internal_Name (Chars (E1))
9870 and then Non_Internal_Name (E1) = Chars (E2))
9872 (Is_Predefined_Dispatching_Operation (E1)
9873 and then Is_Predefined_Dispatching_Operation (E2)
9874 and then Same_TSS (E1, E2))
9876 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
9877 end Primitive_Names_Match;
9879 -----------------------
9880 -- Process_End_Label --
9881 -----------------------
9883 procedure Process_End_Label
9892 Label_Ref : Boolean;
9893 -- Set True if reference to end label itself is required
9896 -- Gets set to the operator symbol or identifier that references the
9897 -- entity Ent. For the child unit case, this is the identifier from the
9898 -- designator. For other cases, this is simply Endl.
9900 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
9901 -- N is an identifier node that appears as a parent unit reference in
9902 -- the case where Ent is a child unit. This procedure generates an
9903 -- appropriate cross-reference entry. E is the corresponding entity.
9905 -------------------------
9906 -- Generate_Parent_Ref --
9907 -------------------------
9909 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
9911 -- If names do not match, something weird, skip reference
9913 if Chars (E) = Chars (N) then
9915 -- Generate the reference. We do NOT consider this as a reference
9916 -- for unreferenced symbol purposes.
9918 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
9921 Style.Check_Identifier (N, E);
9924 end Generate_Parent_Ref;
9926 -- Start of processing for Process_End_Label
9929 -- If no node, ignore. This happens in some error situations, and
9930 -- also for some internally generated structures where no end label
9931 -- references are required in any case.
9937 -- Nothing to do if no End_Label, happens for internally generated
9938 -- constructs where we don't want an end label reference anyway. Also
9939 -- nothing to do if Endl is a string literal, which means there was
9940 -- some prior error (bad operator symbol)
9942 Endl := End_Label (N);
9944 if No (Endl) or else Nkind (Endl) = N_String_Literal then
9948 -- Reference node is not in extended main source unit
9950 if not In_Extended_Main_Source_Unit (N) then
9952 -- Generally we do not collect references except for the extended
9953 -- main source unit. The one exception is the 'e' entry for a
9954 -- package spec, where it is useful for a client to have the
9955 -- ending information to define scopes.
9963 -- For this case, we can ignore any parent references, but we
9964 -- need the package name itself for the 'e' entry.
9966 if Nkind (Endl) = N_Designator then
9967 Endl := Identifier (Endl);
9971 -- Reference is in extended main source unit
9976 -- For designator, generate references for the parent entries
9978 if Nkind (Endl) = N_Designator then
9980 -- Generate references for the prefix if the END line comes from
9981 -- source (otherwise we do not need these references) We climb the
9982 -- scope stack to find the expected entities.
9984 if Comes_From_Source (Endl) then
9986 Scop := Current_Scope;
9987 while Nkind (Nam) = N_Selected_Component loop
9988 Scop := Scope (Scop);
9989 exit when No (Scop);
9990 Generate_Parent_Ref (Selector_Name (Nam), Scop);
9991 Nam := Prefix (Nam);
9994 if Present (Scop) then
9995 Generate_Parent_Ref (Nam, Scope (Scop));
9999 Endl := Identifier (Endl);
10003 -- If the end label is not for the given entity, then either we have
10004 -- some previous error, or this is a generic instantiation for which
10005 -- we do not need to make a cross-reference in this case anyway. In
10006 -- either case we simply ignore the call.
10008 if Chars (Ent) /= Chars (Endl) then
10012 -- If label was really there, then generate a normal reference and then
10013 -- adjust the location in the end label to point past the name (which
10014 -- should almost always be the semicolon).
10016 Loc := Sloc (Endl);
10018 if Comes_From_Source (Endl) then
10020 -- If a label reference is required, then do the style check and
10021 -- generate an l-type cross-reference entry for the label
10024 if Style_Check then
10025 Style.Check_Identifier (Endl, Ent);
10028 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
10031 -- Set the location to point past the label (normally this will
10032 -- mean the semicolon immediately following the label). This is
10033 -- done for the sake of the 'e' or 't' entry generated below.
10035 Get_Decoded_Name_String (Chars (Endl));
10036 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
10039 -- Now generate the e/t reference
10041 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
10043 -- Restore Sloc, in case modified above, since we have an identifier
10044 -- and the normal Sloc should be left set in the tree.
10046 Set_Sloc (Endl, Loc);
10047 end Process_End_Label;
10053 -- We do the conversion to get the value of the real string by using
10054 -- the scanner, see Sinput for details on use of the internal source
10055 -- buffer for scanning internal strings.
10057 function Real_Convert (S : String) return Node_Id is
10058 Save_Src : constant Source_Buffer_Ptr := Source;
10059 Negative : Boolean;
10062 Source := Internal_Source_Ptr;
10065 for J in S'Range loop
10066 Source (Source_Ptr (J)) := S (J);
10069 Source (S'Length + 1) := EOF;
10071 if Source (Scan_Ptr) = '-' then
10073 Scan_Ptr := Scan_Ptr + 1;
10081 Set_Realval (Token_Node, UR_Negate (Realval (Token_Node)));
10084 Source := Save_Src;
10088 ------------------------------------
10089 -- References_Generic_Formal_Type --
10090 ------------------------------------
10092 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
10094 function Process (N : Node_Id) return Traverse_Result;
10095 -- Process one node in search for generic formal type
10101 function Process (N : Node_Id) return Traverse_Result is
10103 if Nkind (N) in N_Has_Entity then
10105 E : constant Entity_Id := Entity (N);
10107 if Present (E) then
10108 if Is_Generic_Type (E) then
10110 elsif Present (Etype (E))
10111 and then Is_Generic_Type (Etype (E))
10122 function Traverse is new Traverse_Func (Process);
10123 -- Traverse tree to look for generic type
10126 if Inside_A_Generic then
10127 return Traverse (N) = Abandon;
10131 end References_Generic_Formal_Type;
10133 --------------------
10134 -- Remove_Homonym --
10135 --------------------
10137 procedure Remove_Homonym (E : Entity_Id) is
10138 Prev : Entity_Id := Empty;
10142 if E = Current_Entity (E) then
10143 if Present (Homonym (E)) then
10144 Set_Current_Entity (Homonym (E));
10146 Set_Name_Entity_Id (Chars (E), Empty);
10149 H := Current_Entity (E);
10150 while Present (H) and then H /= E loop
10155 Set_Homonym (Prev, Homonym (E));
10157 end Remove_Homonym;
10159 ---------------------
10160 -- Rep_To_Pos_Flag --
10161 ---------------------
10163 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
10165 return New_Occurrence_Of
10166 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
10167 end Rep_To_Pos_Flag;
10169 --------------------
10170 -- Require_Entity --
10171 --------------------
10173 procedure Require_Entity (N : Node_Id) is
10175 if Is_Entity_Name (N) and then No (Entity (N)) then
10176 if Total_Errors_Detected /= 0 then
10177 Set_Entity (N, Any_Id);
10179 raise Program_Error;
10182 end Require_Entity;
10184 ------------------------------
10185 -- Requires_Transient_Scope --
10186 ------------------------------
10188 -- A transient scope is required when variable-sized temporaries are
10189 -- allocated in the primary or secondary stack, or when finalization
10190 -- actions must be generated before the next instruction.
10192 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
10193 Typ : constant Entity_Id := Underlying_Type (Id);
10195 -- Start of processing for Requires_Transient_Scope
10198 -- This is a private type which is not completed yet. This can only
10199 -- happen in a default expression (of a formal parameter or of a
10200 -- record component). Do not expand transient scope in this case
10205 -- Do not expand transient scope for non-existent procedure return
10207 elsif Typ = Standard_Void_Type then
10210 -- Elementary types do not require a transient scope
10212 elsif Is_Elementary_Type (Typ) then
10215 -- Generally, indefinite subtypes require a transient scope, since the
10216 -- back end cannot generate temporaries, since this is not a valid type
10217 -- for declaring an object. It might be possible to relax this in the
10218 -- future, e.g. by declaring the maximum possible space for the type.
10220 elsif Is_Indefinite_Subtype (Typ) then
10223 -- Functions returning tagged types may dispatch on result so their
10224 -- returned value is allocated on the secondary stack. Controlled
10225 -- type temporaries need finalization.
10227 elsif Is_Tagged_Type (Typ)
10228 or else Has_Controlled_Component (Typ)
10230 return not Is_Value_Type (Typ);
10234 elsif Is_Record_Type (Typ) then
10238 Comp := First_Entity (Typ);
10239 while Present (Comp) loop
10240 if Ekind (Comp) = E_Component
10241 and then Requires_Transient_Scope (Etype (Comp))
10245 Next_Entity (Comp);
10252 -- String literal types never require transient scope
10254 elsif Ekind (Typ) = E_String_Literal_Subtype then
10257 -- Array type. Note that we already know that this is a constrained
10258 -- array, since unconstrained arrays will fail the indefinite test.
10260 elsif Is_Array_Type (Typ) then
10262 -- If component type requires a transient scope, the array does too
10264 if Requires_Transient_Scope (Component_Type (Typ)) then
10267 -- Otherwise, we only need a transient scope if the size is not
10268 -- known at compile time.
10271 return not Size_Known_At_Compile_Time (Typ);
10274 -- All other cases do not require a transient scope
10279 end Requires_Transient_Scope;
10281 --------------------------
10282 -- Reset_Analyzed_Flags --
10283 --------------------------
10285 procedure Reset_Analyzed_Flags (N : Node_Id) is
10287 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
10288 -- Function used to reset Analyzed flags in tree. Note that we do
10289 -- not reset Analyzed flags in entities, since there is no need to
10290 -- reanalyze entities, and indeed, it is wrong to do so, since it
10291 -- can result in generating auxiliary stuff more than once.
10293 --------------------
10294 -- Clear_Analyzed --
10295 --------------------
10297 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
10299 if not Has_Extension (N) then
10300 Set_Analyzed (N, False);
10304 end Clear_Analyzed;
10306 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
10308 -- Start of processing for Reset_Analyzed_Flags
10311 Reset_Analyzed (N);
10312 end Reset_Analyzed_Flags;
10314 ---------------------------
10315 -- Safe_To_Capture_Value --
10316 ---------------------------
10318 function Safe_To_Capture_Value
10321 Cond : Boolean := False) return Boolean
10324 -- The only entities for which we track constant values are variables
10325 -- which are not renamings, constants, out parameters, and in out
10326 -- parameters, so check if we have this case.
10328 -- Note: it may seem odd to track constant values for constants, but in
10329 -- fact this routine is used for other purposes than simply capturing
10330 -- the value. In particular, the setting of Known[_Non]_Null.
10332 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
10334 Ekind (Ent) = E_Constant
10336 Ekind (Ent) = E_Out_Parameter
10338 Ekind (Ent) = E_In_Out_Parameter
10342 -- For conditionals, we also allow loop parameters and all formals,
10343 -- including in parameters.
10347 (Ekind (Ent) = E_Loop_Parameter
10349 Ekind (Ent) = E_In_Parameter)
10353 -- For all other cases, not just unsafe, but impossible to capture
10354 -- Current_Value, since the above are the only entities which have
10355 -- Current_Value fields.
10361 -- Skip if volatile or aliased, since funny things might be going on in
10362 -- these cases which we cannot necessarily track. Also skip any variable
10363 -- for which an address clause is given, or whose address is taken. Also
10364 -- never capture value of library level variables (an attempt to do so
10365 -- can occur in the case of package elaboration code).
10367 if Treat_As_Volatile (Ent)
10368 or else Is_Aliased (Ent)
10369 or else Present (Address_Clause (Ent))
10370 or else Address_Taken (Ent)
10371 or else (Is_Library_Level_Entity (Ent)
10372 and then Ekind (Ent) = E_Variable)
10377 -- OK, all above conditions are met. We also require that the scope of
10378 -- the reference be the same as the scope of the entity, not counting
10379 -- packages and blocks and loops.
10382 E_Scope : constant Entity_Id := Scope (Ent);
10383 R_Scope : Entity_Id;
10386 R_Scope := Current_Scope;
10387 while R_Scope /= Standard_Standard loop
10388 exit when R_Scope = E_Scope;
10390 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
10393 R_Scope := Scope (R_Scope);
10398 -- We also require that the reference does not appear in a context
10399 -- where it is not sure to be executed (i.e. a conditional context
10400 -- or an exception handler). We skip this if Cond is True, since the
10401 -- capturing of values from conditional tests handles this ok.
10415 while Present (P) loop
10416 if Nkind (P) = N_If_Statement
10417 or else Nkind (P) = N_Case_Statement
10418 or else (Nkind (P) in N_Short_Circuit
10419 and then Desc = Right_Opnd (P))
10420 or else (Nkind (P) = N_Conditional_Expression
10421 and then Desc /= First (Expressions (P)))
10422 or else Nkind (P) = N_Exception_Handler
10423 or else Nkind (P) = N_Selective_Accept
10424 or else Nkind (P) = N_Conditional_Entry_Call
10425 or else Nkind (P) = N_Timed_Entry_Call
10426 or else Nkind (P) = N_Asynchronous_Select
10436 -- OK, looks safe to set value
10439 end Safe_To_Capture_Value;
10445 function Same_Name (N1, N2 : Node_Id) return Boolean is
10446 K1 : constant Node_Kind := Nkind (N1);
10447 K2 : constant Node_Kind := Nkind (N2);
10450 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
10451 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
10453 return Chars (N1) = Chars (N2);
10455 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
10456 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
10458 return Same_Name (Selector_Name (N1), Selector_Name (N2))
10459 and then Same_Name (Prefix (N1), Prefix (N2));
10470 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
10471 N1 : constant Node_Id := Original_Node (Node1);
10472 N2 : constant Node_Id := Original_Node (Node2);
10473 -- We do the tests on original nodes, since we are most interested
10474 -- in the original source, not any expansion that got in the way.
10476 K1 : constant Node_Kind := Nkind (N1);
10477 K2 : constant Node_Kind := Nkind (N2);
10480 -- First case, both are entities with same entity
10482 if K1 in N_Has_Entity
10483 and then K2 in N_Has_Entity
10484 and then Present (Entity (N1))
10485 and then Present (Entity (N2))
10486 and then (Ekind (Entity (N1)) = E_Variable
10488 Ekind (Entity (N1)) = E_Constant)
10489 and then Entity (N1) = Entity (N2)
10493 -- Second case, selected component with same selector, same record
10495 elsif K1 = N_Selected_Component
10496 and then K2 = N_Selected_Component
10497 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
10499 return Same_Object (Prefix (N1), Prefix (N2));
10501 -- Third case, indexed component with same subscripts, same array
10503 elsif K1 = N_Indexed_Component
10504 and then K2 = N_Indexed_Component
10505 and then Same_Object (Prefix (N1), Prefix (N2))
10510 E1 := First (Expressions (N1));
10511 E2 := First (Expressions (N2));
10512 while Present (E1) loop
10513 if not Same_Value (E1, E2) then
10524 -- Fourth case, slice of same array with same bounds
10527 and then K2 = N_Slice
10528 and then Nkind (Discrete_Range (N1)) = N_Range
10529 and then Nkind (Discrete_Range (N2)) = N_Range
10530 and then Same_Value (Low_Bound (Discrete_Range (N1)),
10531 Low_Bound (Discrete_Range (N2)))
10532 and then Same_Value (High_Bound (Discrete_Range (N1)),
10533 High_Bound (Discrete_Range (N2)))
10535 return Same_Name (Prefix (N1), Prefix (N2));
10537 -- All other cases, not clearly the same object
10548 function Same_Type (T1, T2 : Entity_Id) return Boolean is
10553 elsif not Is_Constrained (T1)
10554 and then not Is_Constrained (T2)
10555 and then Base_Type (T1) = Base_Type (T2)
10559 -- For now don't bother with case of identical constraints, to be
10560 -- fiddled with later on perhaps (this is only used for optimization
10561 -- purposes, so it is not critical to do a best possible job)
10572 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
10574 if Compile_Time_Known_Value (Node1)
10575 and then Compile_Time_Known_Value (Node2)
10576 and then Expr_Value (Node1) = Expr_Value (Node2)
10579 elsif Same_Object (Node1, Node2) then
10586 ------------------------
10587 -- Scope_Is_Transient --
10588 ------------------------
10590 function Scope_Is_Transient return Boolean is
10592 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
10593 end Scope_Is_Transient;
10599 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
10604 while Scop /= Standard_Standard loop
10605 Scop := Scope (Scop);
10607 if Scop = Scope2 then
10615 --------------------------
10616 -- Scope_Within_Or_Same --
10617 --------------------------
10619 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
10624 while Scop /= Standard_Standard loop
10625 if Scop = Scope2 then
10628 Scop := Scope (Scop);
10633 end Scope_Within_Or_Same;
10635 --------------------
10636 -- Set_Convention --
10637 --------------------
10639 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
10641 Basic_Set_Convention (E, Val);
10644 and then Is_Access_Subprogram_Type (Base_Type (E))
10645 and then Has_Foreign_Convention (E)
10647 Set_Can_Use_Internal_Rep (E, False);
10649 end Set_Convention;
10651 ------------------------
10652 -- Set_Current_Entity --
10653 ------------------------
10655 -- The given entity is to be set as the currently visible definition
10656 -- of its associated name (i.e. the Node_Id associated with its name).
10657 -- All we have to do is to get the name from the identifier, and
10658 -- then set the associated Node_Id to point to the given entity.
10660 procedure Set_Current_Entity (E : Entity_Id) is
10662 Set_Name_Entity_Id (Chars (E), E);
10663 end Set_Current_Entity;
10665 ---------------------------
10666 -- Set_Debug_Info_Needed --
10667 ---------------------------
10669 procedure Set_Debug_Info_Needed (T : Entity_Id) is
10671 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
10672 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
10673 -- Used to set debug info in a related node if not set already
10675 --------------------------------------
10676 -- Set_Debug_Info_Needed_If_Not_Set --
10677 --------------------------------------
10679 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
10682 and then not Needs_Debug_Info (E)
10684 Set_Debug_Info_Needed (E);
10686 -- For a private type, indicate that the full view also needs
10687 -- debug information.
10690 and then Is_Private_Type (E)
10691 and then Present (Full_View (E))
10693 Set_Debug_Info_Needed (Full_View (E));
10696 end Set_Debug_Info_Needed_If_Not_Set;
10698 -- Start of processing for Set_Debug_Info_Needed
10701 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
10702 -- indicates that Debug_Info_Needed is never required for the entity.
10705 or else Debug_Info_Off (T)
10710 -- Set flag in entity itself. Note that we will go through the following
10711 -- circuitry even if the flag is already set on T. That's intentional,
10712 -- it makes sure that the flag will be set in subsidiary entities.
10714 Set_Needs_Debug_Info (T);
10716 -- Set flag on subsidiary entities if not set already
10718 if Is_Object (T) then
10719 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
10721 elsif Is_Type (T) then
10722 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
10724 if Is_Record_Type (T) then
10726 Ent : Entity_Id := First_Entity (T);
10728 while Present (Ent) loop
10729 Set_Debug_Info_Needed_If_Not_Set (Ent);
10734 -- For a class wide subtype, we also need debug information
10735 -- for the equivalent type.
10737 if Ekind (T) = E_Class_Wide_Subtype then
10738 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
10741 elsif Is_Array_Type (T) then
10742 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
10745 Indx : Node_Id := First_Index (T);
10747 while Present (Indx) loop
10748 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
10749 Indx := Next_Index (Indx);
10753 if Is_Packed (T) then
10754 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Type (T));
10757 elsif Is_Access_Type (T) then
10758 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
10760 elsif Is_Private_Type (T) then
10761 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
10763 elsif Is_Protected_Type (T) then
10764 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
10767 end Set_Debug_Info_Needed;
10769 ---------------------------------
10770 -- Set_Entity_With_Style_Check --
10771 ---------------------------------
10773 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
10774 Val_Actual : Entity_Id;
10778 Set_Entity (N, Val);
10781 and then not Suppress_Style_Checks (Val)
10782 and then not In_Instance
10784 if Nkind (N) = N_Identifier then
10786 elsif Nkind (N) = N_Expanded_Name then
10787 Nod := Selector_Name (N);
10792 -- A special situation arises for derived operations, where we want
10793 -- to do the check against the parent (since the Sloc of the derived
10794 -- operation points to the derived type declaration itself).
10797 while not Comes_From_Source (Val_Actual)
10798 and then Nkind (Val_Actual) in N_Entity
10799 and then (Ekind (Val_Actual) = E_Enumeration_Literal
10800 or else Is_Subprogram (Val_Actual)
10801 or else Is_Generic_Subprogram (Val_Actual))
10802 and then Present (Alias (Val_Actual))
10804 Val_Actual := Alias (Val_Actual);
10807 -- Renaming declarations for generic actuals do not come from source,
10808 -- and have a different name from that of the entity they rename, so
10809 -- there is no style check to perform here.
10811 if Chars (Nod) = Chars (Val_Actual) then
10812 Style.Check_Identifier (Nod, Val_Actual);
10816 Set_Entity (N, Val);
10817 end Set_Entity_With_Style_Check;
10819 ------------------------
10820 -- Set_Name_Entity_Id --
10821 ------------------------
10823 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
10825 Set_Name_Table_Info (Id, Int (Val));
10826 end Set_Name_Entity_Id;
10828 ---------------------
10829 -- Set_Next_Actual --
10830 ---------------------
10832 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
10834 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
10835 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
10837 end Set_Next_Actual;
10839 ----------------------------------
10840 -- Set_Optimize_Alignment_Flags --
10841 ----------------------------------
10843 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
10845 if Optimize_Alignment = 'S' then
10846 Set_Optimize_Alignment_Space (E);
10847 elsif Optimize_Alignment = 'T' then
10848 Set_Optimize_Alignment_Time (E);
10850 end Set_Optimize_Alignment_Flags;
10852 -----------------------
10853 -- Set_Public_Status --
10854 -----------------------
10856 procedure Set_Public_Status (Id : Entity_Id) is
10857 S : constant Entity_Id := Current_Scope;
10859 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
10860 -- Determines if E is defined within handled statement sequence or
10861 -- an if statement, returns True if so, False otherwise.
10863 ----------------------
10864 -- Within_HSS_Or_If --
10865 ----------------------
10867 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
10870 N := Declaration_Node (E);
10877 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
10883 end Within_HSS_Or_If;
10885 -- Start of processing for Set_Public_Status
10888 -- Everything in the scope of Standard is public
10890 if S = Standard_Standard then
10891 Set_Is_Public (Id);
10893 -- Entity is definitely not public if enclosing scope is not public
10895 elsif not Is_Public (S) then
10898 -- An object or function declaration that occurs in a handled sequence
10899 -- of statements or within an if statement is the declaration for a
10900 -- temporary object or local subprogram generated by the expander. It
10901 -- never needs to be made public and furthermore, making it public can
10902 -- cause back end problems.
10904 elsif Nkind_In (Parent (Id), N_Object_Declaration,
10905 N_Function_Specification)
10906 and then Within_HSS_Or_If (Id)
10910 -- Entities in public packages or records are public
10912 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
10913 Set_Is_Public (Id);
10915 -- The bounds of an entry family declaration can generate object
10916 -- declarations that are visible to the back-end, e.g. in the
10917 -- the declaration of a composite type that contains tasks.
10919 elsif Is_Concurrent_Type (S)
10920 and then not Has_Completion (S)
10921 and then Nkind (Parent (Id)) = N_Object_Declaration
10923 Set_Is_Public (Id);
10925 end Set_Public_Status;
10927 -----------------------------
10928 -- Set_Referenced_Modified --
10929 -----------------------------
10931 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
10935 -- Deal with indexed or selected component where prefix is modified
10937 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
10938 Pref := Prefix (N);
10940 -- If prefix is access type, then it is the designated object that is
10941 -- being modified, which means we have no entity to set the flag on.
10943 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
10946 -- Otherwise chase the prefix
10949 Set_Referenced_Modified (Pref, Out_Param);
10952 -- Otherwise see if we have an entity name (only other case to process)
10954 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
10955 Set_Referenced_As_LHS (Entity (N), not Out_Param);
10956 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
10958 end Set_Referenced_Modified;
10960 ----------------------------
10961 -- Set_Scope_Is_Transient --
10962 ----------------------------
10964 procedure Set_Scope_Is_Transient (V : Boolean := True) is
10966 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
10967 end Set_Scope_Is_Transient;
10969 -------------------
10970 -- Set_Size_Info --
10971 -------------------
10973 procedure Set_Size_Info (T1, T2 : Entity_Id) is
10975 -- We copy Esize, but not RM_Size, since in general RM_Size is
10976 -- subtype specific and does not get inherited by all subtypes.
10978 Set_Esize (T1, Esize (T2));
10979 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
10981 if Is_Discrete_Or_Fixed_Point_Type (T1)
10983 Is_Discrete_Or_Fixed_Point_Type (T2)
10985 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
10988 Set_Alignment (T1, Alignment (T2));
10991 --------------------
10992 -- Static_Integer --
10993 --------------------
10995 function Static_Integer (N : Node_Id) return Uint is
10997 Analyze_And_Resolve (N, Any_Integer);
11000 or else Error_Posted (N)
11001 or else Etype (N) = Any_Type
11006 if Is_Static_Expression (N) then
11007 if not Raises_Constraint_Error (N) then
11008 return Expr_Value (N);
11013 elsif Etype (N) = Any_Type then
11017 Flag_Non_Static_Expr
11018 ("static integer expression required here", N);
11021 end Static_Integer;
11023 --------------------------
11024 -- Statically_Different --
11025 --------------------------
11027 function Statically_Different (E1, E2 : Node_Id) return Boolean is
11028 R1 : constant Node_Id := Get_Referenced_Object (E1);
11029 R2 : constant Node_Id := Get_Referenced_Object (E2);
11031 return Is_Entity_Name (R1)
11032 and then Is_Entity_Name (R2)
11033 and then Entity (R1) /= Entity (R2)
11034 and then not Is_Formal (Entity (R1))
11035 and then not Is_Formal (Entity (R2));
11036 end Statically_Different;
11038 -----------------------------
11039 -- Subprogram_Access_Level --
11040 -----------------------------
11042 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
11044 if Present (Alias (Subp)) then
11045 return Subprogram_Access_Level (Alias (Subp));
11047 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
11049 end Subprogram_Access_Level;
11055 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
11057 if Debug_Flag_W then
11058 for J in 0 .. Scope_Stack.Last loop
11063 Write_Name (Chars (E));
11064 Write_Str (" from ");
11065 Write_Location (Sloc (N));
11070 -----------------------
11071 -- Transfer_Entities --
11072 -----------------------
11074 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
11075 Ent : Entity_Id := First_Entity (From);
11082 if (Last_Entity (To)) = Empty then
11083 Set_First_Entity (To, Ent);
11085 Set_Next_Entity (Last_Entity (To), Ent);
11088 Set_Last_Entity (To, Last_Entity (From));
11090 while Present (Ent) loop
11091 Set_Scope (Ent, To);
11093 if not Is_Public (Ent) then
11094 Set_Public_Status (Ent);
11097 and then Ekind (Ent) = E_Record_Subtype
11100 -- The components of the propagated Itype must be public
11106 Comp := First_Entity (Ent);
11107 while Present (Comp) loop
11108 Set_Is_Public (Comp);
11109 Next_Entity (Comp);
11118 Set_First_Entity (From, Empty);
11119 Set_Last_Entity (From, Empty);
11120 end Transfer_Entities;
11122 -----------------------
11123 -- Type_Access_Level --
11124 -----------------------
11126 function Type_Access_Level (Typ : Entity_Id) return Uint is
11130 Btyp := Base_Type (Typ);
11132 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
11133 -- simply use the level where the type is declared. This is true for
11134 -- stand-alone object declarations, and for anonymous access types
11135 -- associated with components the level is the same as that of the
11136 -- enclosing composite type. However, special treatment is needed for
11137 -- the cases of access parameters, return objects of an anonymous access
11138 -- type, and, in Ada 95, access discriminants of limited types.
11140 if Ekind (Btyp) in Access_Kind then
11141 if Ekind (Btyp) = E_Anonymous_Access_Type then
11143 -- If the type is a nonlocal anonymous access type (such as for
11144 -- an access parameter) we treat it as being declared at the
11145 -- library level to ensure that names such as X.all'access don't
11146 -- fail static accessibility checks.
11148 if not Is_Local_Anonymous_Access (Typ) then
11149 return Scope_Depth (Standard_Standard);
11151 -- If this is a return object, the accessibility level is that of
11152 -- the result subtype of the enclosing function. The test here is
11153 -- little complicated, because we have to account for extended
11154 -- return statements that have been rewritten as blocks, in which
11155 -- case we have to find and the Is_Return_Object attribute of the
11156 -- itype's associated object. It would be nice to find a way to
11157 -- simplify this test, but it doesn't seem worthwhile to add a new
11158 -- flag just for purposes of this test. ???
11160 elsif Ekind (Scope (Btyp)) = E_Return_Statement
11163 and then Nkind (Associated_Node_For_Itype (Btyp)) =
11164 N_Object_Declaration
11165 and then Is_Return_Object
11166 (Defining_Identifier
11167 (Associated_Node_For_Itype (Btyp))))
11173 Scop := Scope (Scope (Btyp));
11174 while Present (Scop) loop
11175 exit when Ekind (Scop) = E_Function;
11176 Scop := Scope (Scop);
11179 -- Treat the return object's type as having the level of the
11180 -- function's result subtype (as per RM05-6.5(5.3/2)).
11182 return Type_Access_Level (Etype (Scop));
11187 Btyp := Root_Type (Btyp);
11189 -- The accessibility level of anonymous access types associated with
11190 -- discriminants is that of the current instance of the type, and
11191 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
11193 -- AI-402: access discriminants have accessibility based on the
11194 -- object rather than the type in Ada 2005, so the above paragraph
11197 -- ??? Needs completion with rules from AI-416
11199 if Ada_Version <= Ada_95
11200 and then Ekind (Typ) = E_Anonymous_Access_Type
11201 and then Present (Associated_Node_For_Itype (Typ))
11202 and then Nkind (Associated_Node_For_Itype (Typ)) =
11203 N_Discriminant_Specification
11205 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
11209 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
11210 end Type_Access_Level;
11212 --------------------------
11213 -- Unit_Declaration_Node --
11214 --------------------------
11216 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
11217 N : Node_Id := Parent (Unit_Id);
11220 -- Predefined operators do not have a full function declaration
11222 if Ekind (Unit_Id) = E_Operator then
11226 -- Isn't there some better way to express the following ???
11228 while Nkind (N) /= N_Abstract_Subprogram_Declaration
11229 and then Nkind (N) /= N_Formal_Package_Declaration
11230 and then Nkind (N) /= N_Function_Instantiation
11231 and then Nkind (N) /= N_Generic_Package_Declaration
11232 and then Nkind (N) /= N_Generic_Subprogram_Declaration
11233 and then Nkind (N) /= N_Package_Declaration
11234 and then Nkind (N) /= N_Package_Body
11235 and then Nkind (N) /= N_Package_Instantiation
11236 and then Nkind (N) /= N_Package_Renaming_Declaration
11237 and then Nkind (N) /= N_Procedure_Instantiation
11238 and then Nkind (N) /= N_Protected_Body
11239 and then Nkind (N) /= N_Subprogram_Declaration
11240 and then Nkind (N) /= N_Subprogram_Body
11241 and then Nkind (N) /= N_Subprogram_Body_Stub
11242 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
11243 and then Nkind (N) /= N_Task_Body
11244 and then Nkind (N) /= N_Task_Type_Declaration
11245 and then Nkind (N) not in N_Formal_Subprogram_Declaration
11246 and then Nkind (N) not in N_Generic_Renaming_Declaration
11249 pragma Assert (Present (N));
11253 end Unit_Declaration_Node;
11255 ------------------------------
11256 -- Universal_Interpretation --
11257 ------------------------------
11259 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
11260 Index : Interp_Index;
11264 -- The argument may be a formal parameter of an operator or subprogram
11265 -- with multiple interpretations, or else an expression for an actual.
11267 if Nkind (Opnd) = N_Defining_Identifier
11268 or else not Is_Overloaded (Opnd)
11270 if Etype (Opnd) = Universal_Integer
11271 or else Etype (Opnd) = Universal_Real
11273 return Etype (Opnd);
11279 Get_First_Interp (Opnd, Index, It);
11280 while Present (It.Typ) loop
11281 if It.Typ = Universal_Integer
11282 or else It.Typ = Universal_Real
11287 Get_Next_Interp (Index, It);
11292 end Universal_Interpretation;
11298 function Unqualify (Expr : Node_Id) return Node_Id is
11300 -- Recurse to handle unlikely case of multiple levels of qualification
11302 if Nkind (Expr) = N_Qualified_Expression then
11303 return Unqualify (Expression (Expr));
11305 -- Normal case, not a qualified expression
11312 ----------------------
11313 -- Within_Init_Proc --
11314 ----------------------
11316 function Within_Init_Proc return Boolean is
11320 S := Current_Scope;
11321 while not Is_Overloadable (S) loop
11322 if S = Standard_Standard then
11329 return Is_Init_Proc (S);
11330 end Within_Init_Proc;
11336 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
11337 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
11338 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
11340 function Has_One_Matching_Field return Boolean;
11341 -- Determines if Expec_Type is a record type with a single component or
11342 -- discriminant whose type matches the found type or is one dimensional
11343 -- array whose component type matches the found type.
11345 ----------------------------
11346 -- Has_One_Matching_Field --
11347 ----------------------------
11349 function Has_One_Matching_Field return Boolean is
11353 if Is_Array_Type (Expec_Type)
11354 and then Number_Dimensions (Expec_Type) = 1
11356 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
11360 elsif not Is_Record_Type (Expec_Type) then
11364 E := First_Entity (Expec_Type);
11369 elsif (Ekind (E) /= E_Discriminant
11370 and then Ekind (E) /= E_Component)
11371 or else (Chars (E) = Name_uTag
11372 or else Chars (E) = Name_uParent)
11381 if not Covers (Etype (E), Found_Type) then
11384 elsif Present (Next_Entity (E)) then
11391 end Has_One_Matching_Field;
11393 -- Start of processing for Wrong_Type
11396 -- Don't output message if either type is Any_Type, or if a message
11397 -- has already been posted for this node. We need to do the latter
11398 -- check explicitly (it is ordinarily done in Errout), because we
11399 -- are using ! to force the output of the error messages.
11401 if Expec_Type = Any_Type
11402 or else Found_Type = Any_Type
11403 or else Error_Posted (Expr)
11407 -- In an instance, there is an ongoing problem with completion of
11408 -- type derived from private types. Their structure is what Gigi
11409 -- expects, but the Etype is the parent type rather than the
11410 -- derived private type itself. Do not flag error in this case. The
11411 -- private completion is an entity without a parent, like an Itype.
11412 -- Similarly, full and partial views may be incorrect in the instance.
11413 -- There is no simple way to insure that it is consistent ???
11415 elsif In_Instance then
11416 if Etype (Etype (Expr)) = Etype (Expected_Type)
11418 (Has_Private_Declaration (Expected_Type)
11419 or else Has_Private_Declaration (Etype (Expr)))
11420 and then No (Parent (Expected_Type))
11426 -- An interesting special check. If the expression is parenthesized
11427 -- and its type corresponds to the type of the sole component of the
11428 -- expected record type, or to the component type of the expected one
11429 -- dimensional array type, then assume we have a bad aggregate attempt.
11431 if Nkind (Expr) in N_Subexpr
11432 and then Paren_Count (Expr) /= 0
11433 and then Has_One_Matching_Field
11435 Error_Msg_N ("positional aggregate cannot have one component", Expr);
11437 -- Another special check, if we are looking for a pool-specific access
11438 -- type and we found an E_Access_Attribute_Type, then we have the case
11439 -- of an Access attribute being used in a context which needs a pool-
11440 -- specific type, which is never allowed. The one extra check we make
11441 -- is that the expected designated type covers the Found_Type.
11443 elsif Is_Access_Type (Expec_Type)
11444 and then Ekind (Found_Type) = E_Access_Attribute_Type
11445 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
11446 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
11448 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
11450 Error_Msg_N -- CODEFIX
11451 ("result must be general access type!", Expr);
11452 Error_Msg_NE -- CODEFIX
11453 ("add ALL to }!", Expr, Expec_Type);
11455 -- Another special check, if the expected type is an integer type,
11456 -- but the expression is of type System.Address, and the parent is
11457 -- an addition or subtraction operation whose left operand is the
11458 -- expression in question and whose right operand is of an integral
11459 -- type, then this is an attempt at address arithmetic, so give
11460 -- appropriate message.
11462 elsif Is_Integer_Type (Expec_Type)
11463 and then Is_RTE (Found_Type, RE_Address)
11464 and then (Nkind (Parent (Expr)) = N_Op_Add
11466 Nkind (Parent (Expr)) = N_Op_Subtract)
11467 and then Expr = Left_Opnd (Parent (Expr))
11468 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
11471 ("address arithmetic not predefined in package System",
11474 ("\possible missing with/use of System.Storage_Elements",
11478 -- If the expected type is an anonymous access type, as for access
11479 -- parameters and discriminants, the error is on the designated types.
11481 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
11482 if Comes_From_Source (Expec_Type) then
11483 Error_Msg_NE ("expected}!", Expr, Expec_Type);
11486 ("expected an access type with designated}",
11487 Expr, Designated_Type (Expec_Type));
11490 if Is_Access_Type (Found_Type)
11491 and then not Comes_From_Source (Found_Type)
11494 ("\\found an access type with designated}!",
11495 Expr, Designated_Type (Found_Type));
11497 if From_With_Type (Found_Type) then
11498 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
11499 Error_Msg_Qual_Level := 99;
11500 Error_Msg_NE -- CODEFIX
11501 ("\\missing `WITH &;", Expr, Scope (Found_Type));
11502 Error_Msg_Qual_Level := 0;
11504 Error_Msg_NE ("found}!", Expr, Found_Type);
11508 -- Normal case of one type found, some other type expected
11511 -- If the names of the two types are the same, see if some number
11512 -- of levels of qualification will help. Don't try more than three
11513 -- levels, and if we get to standard, it's no use (and probably
11514 -- represents an error in the compiler) Also do not bother with
11515 -- internal scope names.
11518 Expec_Scope : Entity_Id;
11519 Found_Scope : Entity_Id;
11522 Expec_Scope := Expec_Type;
11523 Found_Scope := Found_Type;
11525 for Levels in Int range 0 .. 3 loop
11526 if Chars (Expec_Scope) /= Chars (Found_Scope) then
11527 Error_Msg_Qual_Level := Levels;
11531 Expec_Scope := Scope (Expec_Scope);
11532 Found_Scope := Scope (Found_Scope);
11534 exit when Expec_Scope = Standard_Standard
11535 or else Found_Scope = Standard_Standard
11536 or else not Comes_From_Source (Expec_Scope)
11537 or else not Comes_From_Source (Found_Scope);
11541 if Is_Record_Type (Expec_Type)
11542 and then Present (Corresponding_Remote_Type (Expec_Type))
11544 Error_Msg_NE ("expected}!", Expr,
11545 Corresponding_Remote_Type (Expec_Type));
11547 Error_Msg_NE ("expected}!", Expr, Expec_Type);
11550 if Is_Entity_Name (Expr)
11551 and then Is_Package_Or_Generic_Package (Entity (Expr))
11553 Error_Msg_N ("\\found package name!", Expr);
11555 elsif Is_Entity_Name (Expr)
11557 (Ekind (Entity (Expr)) = E_Procedure
11559 Ekind (Entity (Expr)) = E_Generic_Procedure)
11561 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
11563 ("found procedure name, possibly missing Access attribute!",
11567 ("\\found procedure name instead of function!", Expr);
11570 elsif Nkind (Expr) = N_Function_Call
11571 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
11572 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
11573 and then No (Parameter_Associations (Expr))
11576 ("found function name, possibly missing Access attribute!",
11579 -- Catch common error: a prefix or infix operator which is not
11580 -- directly visible because the type isn't.
11582 elsif Nkind (Expr) in N_Op
11583 and then Is_Overloaded (Expr)
11584 and then not Is_Immediately_Visible (Expec_Type)
11585 and then not Is_Potentially_Use_Visible (Expec_Type)
11586 and then not In_Use (Expec_Type)
11587 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
11590 ("operator of the type is not directly visible!", Expr);
11592 elsif Ekind (Found_Type) = E_Void
11593 and then Present (Parent (Found_Type))
11594 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
11596 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
11599 Error_Msg_NE ("\\found}!", Expr, Found_Type);
11602 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
11603 -- of the same modular type, and (M1 and M2) = 0 was intended.
11605 if Expec_Type = Standard_Boolean
11606 and then Is_Modular_Integer_Type (Found_Type)
11607 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
11608 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
11611 Op : constant Node_Id := Right_Opnd (Parent (Expr));
11612 L : constant Node_Id := Left_Opnd (Op);
11613 R : constant Node_Id := Right_Opnd (Op);
11615 -- The case for the message is when the left operand of the
11616 -- comparison is the same modular type, or when it is an
11617 -- integer literal (or other universal integer expression),
11618 -- which would have been typed as the modular type if the
11619 -- parens had been there.
11621 if (Etype (L) = Found_Type
11623 Etype (L) = Universal_Integer)
11624 and then Is_Integer_Type (Etype (R))
11627 ("\\possible missing parens for modular operation", Expr);
11632 -- Reset error message qualification indication
11634 Error_Msg_Qual_Level := 0;