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;
67 package body Sem_Util is
69 ----------------------------------------
70 -- Global_Variables for New_Copy_Tree --
71 ----------------------------------------
73 -- These global variables are used by New_Copy_Tree. See description
74 -- of the body of this subprogram for details. Global variables can be
75 -- safely used by New_Copy_Tree, since there is no case of a recursive
76 -- call from the processing inside New_Copy_Tree.
78 NCT_Hash_Threshhold : constant := 20;
79 -- If there are more than this number of pairs of entries in the
80 -- map, then Hash_Tables_Used will be set, and the hash tables will
81 -- be initialized and used for the searches.
83 NCT_Hash_Tables_Used : Boolean := False;
84 -- Set to True if hash tables are in use
86 NCT_Table_Entries : Nat;
87 -- Count entries in table to see if threshhold is reached
89 NCT_Hash_Table_Setup : Boolean := False;
90 -- Set to True if hash table contains data. We set this True if we
91 -- setup the hash table with data, and leave it set permanently
92 -- from then on, this is a signal that second and subsequent users
93 -- of the hash table must clear the old entries before reuse.
95 subtype NCT_Header_Num is Int range 0 .. 511;
96 -- Defines range of headers in hash tables (512 headers)
98 ----------------------------------
99 -- Order Dependence (AI05-0144) --
100 ----------------------------------
102 -- Each actual in a call is entered into the table below. A flag indicates
103 -- whether the corresponding formal is OUT or IN OUT. Each top-level call
104 -- (procedure call, condition, assignment) examines all the actuals for a
105 -- possible order dependence. The table is reset after each such check.
107 type Actual_Name is record
109 Is_Writable : Boolean;
110 -- Comments needed???
114 package Actuals_In_Call is new Table.Table (
115 Table_Component_Type => Actual_Name,
116 Table_Index_Type => Int,
117 Table_Low_Bound => 0,
119 Table_Increment => 100,
120 Table_Name => "Actuals");
122 -----------------------
123 -- Local Subprograms --
124 -----------------------
126 function Build_Component_Subtype
129 T : Entity_Id) return Node_Id;
130 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
131 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
132 -- Loc is the source location, T is the original subtype.
134 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
135 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
136 -- with discriminants whose default values are static, examine only the
137 -- components in the selected variant to determine whether all of them
140 function Has_Null_Extension (T : Entity_Id) return Boolean;
141 -- T is a derived tagged type. Check whether the type extension is null.
142 -- If the parent type is fully initialized, T can be treated as such.
144 ------------------------------
145 -- Abstract_Interface_List --
146 ------------------------------
148 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
152 if Is_Concurrent_Type (Typ) then
154 -- If we are dealing with a synchronized subtype, go to the base
155 -- type, whose declaration has the interface list.
157 -- Shouldn't this be Declaration_Node???
159 Nod := Parent (Base_Type (Typ));
161 if Nkind (Nod) = N_Full_Type_Declaration then
165 elsif Ekind (Typ) = E_Record_Type_With_Private then
166 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
167 Nod := Type_Definition (Parent (Typ));
169 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
170 if Present (Full_View (Typ)) then
171 Nod := Type_Definition (Parent (Full_View (Typ)));
173 -- If the full-view is not available we cannot do anything else
174 -- here (the source has errors).
180 -- Support for generic formals with interfaces is still missing ???
182 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
187 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
191 elsif Ekind (Typ) = E_Record_Subtype then
192 Nod := Type_Definition (Parent (Etype (Typ)));
194 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
196 -- Recurse, because parent may still be a private extension. Also
197 -- note that the full view of the subtype or the full view of its
198 -- base type may (both) be unavailable.
200 return Abstract_Interface_List (Etype (Typ));
202 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
203 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
204 Nod := Formal_Type_Definition (Parent (Typ));
206 Nod := Type_Definition (Parent (Typ));
210 return Interface_List (Nod);
211 end Abstract_Interface_List;
213 --------------------------------
214 -- Add_Access_Type_To_Process --
215 --------------------------------
217 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
221 Ensure_Freeze_Node (E);
222 L := Access_Types_To_Process (Freeze_Node (E));
226 Set_Access_Types_To_Process (Freeze_Node (E), L);
230 end Add_Access_Type_To_Process;
232 ----------------------------
233 -- Add_Global_Declaration --
234 ----------------------------
236 procedure Add_Global_Declaration (N : Node_Id) is
237 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
240 if No (Declarations (Aux_Node)) then
241 Set_Declarations (Aux_Node, New_List);
244 Append_To (Declarations (Aux_Node), N);
246 end Add_Global_Declaration;
248 -----------------------
249 -- Alignment_In_Bits --
250 -----------------------
252 function Alignment_In_Bits (E : Entity_Id) return Uint is
254 return Alignment (E) * System_Storage_Unit;
255 end Alignment_In_Bits;
257 -----------------------------------------
258 -- Apply_Compile_Time_Constraint_Error --
259 -----------------------------------------
261 procedure Apply_Compile_Time_Constraint_Error
264 Reason : RT_Exception_Code;
265 Ent : Entity_Id := Empty;
266 Typ : Entity_Id := Empty;
267 Loc : Source_Ptr := No_Location;
268 Rep : Boolean := True;
269 Warn : Boolean := False)
271 Stat : constant Boolean := Is_Static_Expression (N);
272 R_Stat : constant Node_Id :=
273 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
284 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
290 -- Now we replace the node by an N_Raise_Constraint_Error node
291 -- This does not need reanalyzing, so set it as analyzed now.
294 Set_Analyzed (N, True);
297 Set_Raises_Constraint_Error (N);
299 -- Now deal with possible local raise handling
301 Possible_Local_Raise (N, Standard_Constraint_Error);
303 -- If the original expression was marked as static, the result is
304 -- still marked as static, but the Raises_Constraint_Error flag is
305 -- always set so that further static evaluation is not attempted.
308 Set_Is_Static_Expression (N);
310 end Apply_Compile_Time_Constraint_Error;
312 --------------------------
313 -- Build_Actual_Subtype --
314 --------------------------
316 function Build_Actual_Subtype
318 N : Node_Or_Entity_Id) return Node_Id
321 -- Normally Sloc (N), but may point to corresponding body in some cases
323 Constraints : List_Id;
329 Disc_Type : Entity_Id;
335 if Nkind (N) = N_Defining_Identifier then
336 Obj := New_Reference_To (N, Loc);
338 -- If this is a formal parameter of a subprogram declaration, and
339 -- we are compiling the body, we want the declaration for the
340 -- actual subtype to carry the source position of the body, to
341 -- prevent anomalies in gdb when stepping through the code.
343 if Is_Formal (N) then
345 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
347 if Nkind (Decl) = N_Subprogram_Declaration
348 and then Present (Corresponding_Body (Decl))
350 Loc := Sloc (Corresponding_Body (Decl));
359 if Is_Array_Type (T) then
360 Constraints := New_List;
361 for J in 1 .. Number_Dimensions (T) loop
363 -- Build an array subtype declaration with the nominal subtype and
364 -- the bounds of the actual. Add the declaration in front of the
365 -- local declarations for the subprogram, for analysis before any
366 -- reference to the formal in the body.
369 Make_Attribute_Reference (Loc,
371 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
372 Attribute_Name => Name_First,
373 Expressions => New_List (
374 Make_Integer_Literal (Loc, J)));
377 Make_Attribute_Reference (Loc,
379 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
380 Attribute_Name => Name_Last,
381 Expressions => New_List (
382 Make_Integer_Literal (Loc, J)));
384 Append (Make_Range (Loc, Lo, Hi), Constraints);
387 -- If the type has unknown discriminants there is no constrained
388 -- subtype to build. This is never called for a formal or for a
389 -- lhs, so returning the type is ok ???
391 elsif Has_Unknown_Discriminants (T) then
395 Constraints := New_List;
397 -- Type T is a generic derived type, inherit the discriminants from
400 if Is_Private_Type (T)
401 and then No (Full_View (T))
403 -- T was flagged as an error if it was declared as a formal
404 -- derived type with known discriminants. In this case there
405 -- is no need to look at the parent type since T already carries
406 -- its own discriminants.
408 and then not Error_Posted (T)
410 Disc_Type := Etype (Base_Type (T));
415 Discr := First_Discriminant (Disc_Type);
416 while Present (Discr) loop
417 Append_To (Constraints,
418 Make_Selected_Component (Loc,
420 Duplicate_Subexpr_No_Checks (Obj),
421 Selector_Name => New_Occurrence_Of (Discr, Loc)));
422 Next_Discriminant (Discr);
426 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
427 Set_Is_Internal (Subt);
430 Make_Subtype_Declaration (Loc,
431 Defining_Identifier => Subt,
432 Subtype_Indication =>
433 Make_Subtype_Indication (Loc,
434 Subtype_Mark => New_Reference_To (T, Loc),
436 Make_Index_Or_Discriminant_Constraint (Loc,
437 Constraints => Constraints)));
439 Mark_Rewrite_Insertion (Decl);
441 end Build_Actual_Subtype;
443 ---------------------------------------
444 -- Build_Actual_Subtype_Of_Component --
445 ---------------------------------------
447 function Build_Actual_Subtype_Of_Component
449 N : Node_Id) return Node_Id
451 Loc : constant Source_Ptr := Sloc (N);
452 P : constant Node_Id := Prefix (N);
455 Indx_Type : Entity_Id;
457 Deaccessed_T : Entity_Id;
458 -- This is either a copy of T, or if T is an access type, then it is
459 -- the directly designated type of this access type.
461 function Build_Actual_Array_Constraint return List_Id;
462 -- If one or more of the bounds of the component depends on
463 -- discriminants, build actual constraint using the discriminants
466 function Build_Actual_Record_Constraint return List_Id;
467 -- Similar to previous one, for discriminated components constrained
468 -- by the discriminant of the enclosing object.
470 -----------------------------------
471 -- Build_Actual_Array_Constraint --
472 -----------------------------------
474 function Build_Actual_Array_Constraint return List_Id is
475 Constraints : constant List_Id := New_List;
483 Indx := First_Index (Deaccessed_T);
484 while Present (Indx) loop
485 Old_Lo := Type_Low_Bound (Etype (Indx));
486 Old_Hi := Type_High_Bound (Etype (Indx));
488 if Denotes_Discriminant (Old_Lo) then
490 Make_Selected_Component (Loc,
491 Prefix => New_Copy_Tree (P),
492 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
495 Lo := New_Copy_Tree (Old_Lo);
497 -- The new bound will be reanalyzed in the enclosing
498 -- declaration. For literal bounds that come from a type
499 -- declaration, the type of the context must be imposed, so
500 -- insure that analysis will take place. For non-universal
501 -- types this is not strictly necessary.
503 Set_Analyzed (Lo, False);
506 if Denotes_Discriminant (Old_Hi) then
508 Make_Selected_Component (Loc,
509 Prefix => New_Copy_Tree (P),
510 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
513 Hi := New_Copy_Tree (Old_Hi);
514 Set_Analyzed (Hi, False);
517 Append (Make_Range (Loc, Lo, Hi), Constraints);
522 end Build_Actual_Array_Constraint;
524 ------------------------------------
525 -- Build_Actual_Record_Constraint --
526 ------------------------------------
528 function Build_Actual_Record_Constraint return List_Id is
529 Constraints : constant List_Id := New_List;
534 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
535 while Present (D) loop
536 if Denotes_Discriminant (Node (D)) then
537 D_Val := Make_Selected_Component (Loc,
538 Prefix => New_Copy_Tree (P),
539 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
542 D_Val := New_Copy_Tree (Node (D));
545 Append (D_Val, Constraints);
550 end Build_Actual_Record_Constraint;
552 -- Start of processing for Build_Actual_Subtype_Of_Component
555 -- Why the test for Spec_Expression mode here???
557 if In_Spec_Expression then
560 -- More comments for the rest of this body would be good ???
562 elsif Nkind (N) = N_Explicit_Dereference then
563 if Is_Composite_Type (T)
564 and then not Is_Constrained (T)
565 and then not (Is_Class_Wide_Type (T)
566 and then Is_Constrained (Root_Type (T)))
567 and then not Has_Unknown_Discriminants (T)
569 -- If the type of the dereference is already constrained, it is an
572 if Is_Array_Type (Etype (N))
573 and then Is_Constrained (Etype (N))
577 Remove_Side_Effects (P);
578 return Build_Actual_Subtype (T, N);
585 if Ekind (T) = E_Access_Subtype then
586 Deaccessed_T := Designated_Type (T);
591 if Ekind (Deaccessed_T) = E_Array_Subtype then
592 Id := First_Index (Deaccessed_T);
593 while Present (Id) loop
594 Indx_Type := Underlying_Type (Etype (Id));
596 if Denotes_Discriminant (Type_Low_Bound (Indx_Type))
598 Denotes_Discriminant (Type_High_Bound (Indx_Type))
600 Remove_Side_Effects (P);
602 Build_Component_Subtype
603 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
609 elsif Is_Composite_Type (Deaccessed_T)
610 and then Has_Discriminants (Deaccessed_T)
611 and then not Has_Unknown_Discriminants (Deaccessed_T)
613 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
614 while Present (D) loop
615 if Denotes_Discriminant (Node (D)) then
616 Remove_Side_Effects (P);
618 Build_Component_Subtype (
619 Build_Actual_Record_Constraint, Loc, Base_Type (T));
626 -- If none of the above, the actual and nominal subtypes are the same
629 end Build_Actual_Subtype_Of_Component;
631 -----------------------------
632 -- Build_Component_Subtype --
633 -----------------------------
635 function Build_Component_Subtype
638 T : Entity_Id) return Node_Id
644 -- Unchecked_Union components do not require component subtypes
646 if Is_Unchecked_Union (T) then
650 Subt := Make_Temporary (Loc, 'S');
651 Set_Is_Internal (Subt);
654 Make_Subtype_Declaration (Loc,
655 Defining_Identifier => Subt,
656 Subtype_Indication =>
657 Make_Subtype_Indication (Loc,
658 Subtype_Mark => New_Reference_To (Base_Type (T), Loc),
660 Make_Index_Or_Discriminant_Constraint (Loc,
663 Mark_Rewrite_Insertion (Decl);
665 end Build_Component_Subtype;
667 ---------------------------
668 -- Build_Default_Subtype --
669 ---------------------------
671 function Build_Default_Subtype
673 N : Node_Id) return Entity_Id
675 Loc : constant Source_Ptr := Sloc (N);
679 if not Has_Discriminants (T) or else Is_Constrained (T) then
683 Disc := First_Discriminant (T);
685 if No (Discriminant_Default_Value (Disc)) then
690 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
691 Constraints : constant List_Id := New_List;
695 while Present (Disc) loop
696 Append_To (Constraints,
697 New_Copy_Tree (Discriminant_Default_Value (Disc)));
698 Next_Discriminant (Disc);
702 Make_Subtype_Declaration (Loc,
703 Defining_Identifier => Act,
704 Subtype_Indication =>
705 Make_Subtype_Indication (Loc,
706 Subtype_Mark => New_Occurrence_Of (T, Loc),
708 Make_Index_Or_Discriminant_Constraint (Loc,
709 Constraints => Constraints)));
711 Insert_Action (N, Decl);
715 end Build_Default_Subtype;
717 --------------------------------------------
718 -- Build_Discriminal_Subtype_Of_Component --
719 --------------------------------------------
721 function Build_Discriminal_Subtype_Of_Component
722 (T : Entity_Id) return Node_Id
724 Loc : constant Source_Ptr := Sloc (T);
728 function Build_Discriminal_Array_Constraint return List_Id;
729 -- If one or more of the bounds of the component depends on
730 -- discriminants, build actual constraint using the discriminants
733 function Build_Discriminal_Record_Constraint return List_Id;
734 -- Similar to previous one, for discriminated components constrained
735 -- by the discriminant of the enclosing object.
737 ----------------------------------------
738 -- Build_Discriminal_Array_Constraint --
739 ----------------------------------------
741 function Build_Discriminal_Array_Constraint return List_Id is
742 Constraints : constant List_Id := New_List;
750 Indx := First_Index (T);
751 while Present (Indx) loop
752 Old_Lo := Type_Low_Bound (Etype (Indx));
753 Old_Hi := Type_High_Bound (Etype (Indx));
755 if Denotes_Discriminant (Old_Lo) then
756 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
759 Lo := New_Copy_Tree (Old_Lo);
762 if Denotes_Discriminant (Old_Hi) then
763 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
766 Hi := New_Copy_Tree (Old_Hi);
769 Append (Make_Range (Loc, Lo, Hi), Constraints);
774 end Build_Discriminal_Array_Constraint;
776 -----------------------------------------
777 -- Build_Discriminal_Record_Constraint --
778 -----------------------------------------
780 function Build_Discriminal_Record_Constraint return List_Id is
781 Constraints : constant List_Id := New_List;
786 D := First_Elmt (Discriminant_Constraint (T));
787 while Present (D) loop
788 if Denotes_Discriminant (Node (D)) then
790 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
793 D_Val := New_Copy_Tree (Node (D));
796 Append (D_Val, Constraints);
801 end Build_Discriminal_Record_Constraint;
803 -- Start of processing for Build_Discriminal_Subtype_Of_Component
806 if Ekind (T) = E_Array_Subtype then
807 Id := First_Index (T);
808 while Present (Id) loop
809 if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) or else
810 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
812 return Build_Component_Subtype
813 (Build_Discriminal_Array_Constraint, Loc, T);
819 elsif Ekind (T) = E_Record_Subtype
820 and then Has_Discriminants (T)
821 and then not Has_Unknown_Discriminants (T)
823 D := First_Elmt (Discriminant_Constraint (T));
824 while Present (D) loop
825 if Denotes_Discriminant (Node (D)) then
826 return Build_Component_Subtype
827 (Build_Discriminal_Record_Constraint, Loc, T);
834 -- If none of the above, the actual and nominal subtypes are the same
837 end Build_Discriminal_Subtype_Of_Component;
839 ------------------------------
840 -- Build_Elaboration_Entity --
841 ------------------------------
843 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
844 Loc : constant Source_Ptr := Sloc (N);
846 Elab_Ent : Entity_Id;
848 procedure Set_Package_Name (Ent : Entity_Id);
849 -- Given an entity, sets the fully qualified name of the entity in
850 -- Name_Buffer, with components separated by double underscores. This
851 -- is a recursive routine that climbs the scope chain to Standard.
853 ----------------------
854 -- Set_Package_Name --
855 ----------------------
857 procedure Set_Package_Name (Ent : Entity_Id) is
859 if Scope (Ent) /= Standard_Standard then
860 Set_Package_Name (Scope (Ent));
863 Nam : constant String := Get_Name_String (Chars (Ent));
865 Name_Buffer (Name_Len + 1) := '_';
866 Name_Buffer (Name_Len + 2) := '_';
867 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
868 Name_Len := Name_Len + Nam'Length + 2;
872 Get_Name_String (Chars (Ent));
874 end Set_Package_Name;
876 -- Start of processing for Build_Elaboration_Entity
879 -- Ignore if already constructed
881 if Present (Elaboration_Entity (Spec_Id)) then
885 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
886 -- name with dots replaced by double underscore. We have to manually
887 -- construct this name, since it will be elaborated in the outer scope,
888 -- and thus will not have the unit name automatically prepended.
890 Set_Package_Name (Spec_Id);
894 Name_Buffer (Name_Len + 1) := '_';
895 Name_Buffer (Name_Len + 2) := 'E';
896 Name_Len := Name_Len + 2;
898 -- Create elaboration flag
901 Make_Defining_Identifier (Loc, Chars => Name_Find);
902 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
905 Make_Object_Declaration (Loc,
906 Defining_Identifier => Elab_Ent,
908 New_Occurrence_Of (Standard_Boolean, Loc),
910 New_Occurrence_Of (Standard_False, Loc));
912 Push_Scope (Standard_Standard);
913 Add_Global_Declaration (Decl);
916 -- Reset True_Constant indication, since we will indeed assign a value
917 -- to the variable in the binder main. We also kill the Current_Value
918 -- and Last_Assignment fields for the same reason.
920 Set_Is_True_Constant (Elab_Ent, False);
921 Set_Current_Value (Elab_Ent, Empty);
922 Set_Last_Assignment (Elab_Ent, Empty);
924 -- We do not want any further qualification of the name (if we did
925 -- not do this, we would pick up the name of the generic package
926 -- in the case of a library level generic instantiation).
928 Set_Has_Qualified_Name (Elab_Ent);
929 Set_Has_Fully_Qualified_Name (Elab_Ent);
930 end Build_Elaboration_Entity;
932 -----------------------------------
933 -- Cannot_Raise_Constraint_Error --
934 -----------------------------------
936 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
938 if Compile_Time_Known_Value (Expr) then
941 elsif Do_Range_Check (Expr) then
944 elsif Raises_Constraint_Error (Expr) then
952 when N_Expanded_Name =>
955 when N_Selected_Component =>
956 return not Do_Discriminant_Check (Expr);
958 when N_Attribute_Reference =>
959 if Do_Overflow_Check (Expr) then
962 elsif No (Expressions (Expr)) then
970 N := First (Expressions (Expr));
971 while Present (N) loop
972 if Cannot_Raise_Constraint_Error (N) then
983 when N_Type_Conversion =>
984 if Do_Overflow_Check (Expr)
985 or else Do_Length_Check (Expr)
986 or else Do_Tag_Check (Expr)
991 Cannot_Raise_Constraint_Error (Expression (Expr));
994 when N_Unchecked_Type_Conversion =>
995 return Cannot_Raise_Constraint_Error (Expression (Expr));
998 if Do_Overflow_Check (Expr) then
1002 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1009 if Do_Division_Check (Expr)
1010 or else Do_Overflow_Check (Expr)
1015 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1017 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1036 N_Op_Shift_Right_Arithmetic |
1040 if Do_Overflow_Check (Expr) then
1044 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1046 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1053 end Cannot_Raise_Constraint_Error;
1055 -----------------------------------------
1056 -- Check_Dynamically_Tagged_Expression --
1057 -----------------------------------------
1059 procedure Check_Dynamically_Tagged_Expression
1062 Related_Nod : Node_Id)
1065 pragma Assert (Is_Tagged_Type (Typ));
1067 -- In order to avoid spurious errors when analyzing the expanded code,
1068 -- this check is done only for nodes that come from source and for
1069 -- actuals of generic instantiations.
1071 if (Comes_From_Source (Related_Nod)
1072 or else In_Generic_Actual (Expr))
1073 and then (Is_Class_Wide_Type (Etype (Expr))
1074 or else Is_Dynamically_Tagged (Expr))
1075 and then Is_Tagged_Type (Typ)
1076 and then not Is_Class_Wide_Type (Typ)
1078 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
1080 end Check_Dynamically_Tagged_Expression;
1082 --------------------------
1083 -- Check_Fully_Declared --
1084 --------------------------
1086 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
1088 if Ekind (T) = E_Incomplete_Type then
1090 -- Ada 2005 (AI-50217): If the type is available through a limited
1091 -- with_clause, verify that its full view has been analyzed.
1093 if From_With_Type (T)
1094 and then Present (Non_Limited_View (T))
1095 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1097 -- The non-limited view is fully declared
1102 ("premature usage of incomplete}", N, First_Subtype (T));
1105 -- Need comments for these tests ???
1107 elsif Has_Private_Component (T)
1108 and then not Is_Generic_Type (Root_Type (T))
1109 and then not In_Spec_Expression
1111 -- Special case: if T is the anonymous type created for a single
1112 -- task or protected object, use the name of the source object.
1114 if Is_Concurrent_Type (T)
1115 and then not Comes_From_Source (T)
1116 and then Nkind (N) = N_Object_Declaration
1118 Error_Msg_NE ("type of& has incomplete component", N,
1119 Defining_Identifier (N));
1123 ("premature usage of incomplete}", N, First_Subtype (T));
1126 end Check_Fully_Declared;
1128 -------------------------
1129 -- Check_Nested_Access --
1130 -------------------------
1132 procedure Check_Nested_Access (Ent : Entity_Id) is
1133 Scop : constant Entity_Id := Current_Scope;
1134 Current_Subp : Entity_Id;
1135 Enclosing : Entity_Id;
1138 -- Currently only enabled for VM back-ends for efficiency, should we
1139 -- enable it more systematically ???
1141 -- Check for Is_Imported needs commenting below ???
1143 if VM_Target /= No_VM
1144 and then (Ekind (Ent) = E_Variable
1146 Ekind (Ent) = E_Constant
1148 Ekind (Ent) = E_Loop_Parameter)
1149 and then Scope (Ent) /= Empty
1150 and then not Is_Library_Level_Entity (Ent)
1151 and then not Is_Imported (Ent)
1153 if Is_Subprogram (Scop)
1154 or else Is_Generic_Subprogram (Scop)
1155 or else Is_Entry (Scop)
1157 Current_Subp := Scop;
1159 Current_Subp := Current_Subprogram;
1162 Enclosing := Enclosing_Subprogram (Ent);
1164 if Enclosing /= Empty
1165 and then Enclosing /= Current_Subp
1167 Set_Has_Up_Level_Access (Ent, True);
1170 end Check_Nested_Access;
1172 ----------------------------
1173 -- Check_Order_Dependence --
1174 ----------------------------
1176 procedure Check_Order_Dependence is
1181 -- This could use comments ???
1183 for J in 0 .. Actuals_In_Call.Last loop
1184 if Actuals_In_Call.Table (J).Is_Writable then
1185 Act1 := Actuals_In_Call.Table (J).Act;
1187 if Nkind (Act1) = N_Attribute_Reference then
1188 Act1 := Prefix (Act1);
1191 for K in 0 .. Actuals_In_Call.Last loop
1193 Act2 := Actuals_In_Call.Table (K).Act;
1195 if Nkind (Act2) = N_Attribute_Reference then
1196 Act2 := Prefix (Act2);
1199 if Actuals_In_Call.Table (K).Is_Writable
1206 elsif Denotes_Same_Object (Act1, Act2)
1209 Error_Msg_N ("?,mighty suspicious!!!", Act1);
1216 Actuals_In_Call.Set_Last (0);
1217 end Check_Order_Dependence;
1219 ------------------------------------------
1220 -- Check_Potentially_Blocking_Operation --
1221 ------------------------------------------
1223 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
1226 -- N is one of the potentially blocking operations listed in 9.5.1(8).
1227 -- When pragma Detect_Blocking is active, the run time will raise
1228 -- Program_Error. Here we only issue a warning, since we generally
1229 -- support the use of potentially blocking operations in the absence
1232 -- Indirect blocking through a subprogram call cannot be diagnosed
1233 -- statically without interprocedural analysis, so we do not attempt
1236 S := Scope (Current_Scope);
1237 while Present (S) and then S /= Standard_Standard loop
1238 if Is_Protected_Type (S) then
1240 ("potentially blocking operation in protected operation?", N);
1247 end Check_Potentially_Blocking_Operation;
1249 ------------------------------
1250 -- Check_Unprotected_Access --
1251 ------------------------------
1253 procedure Check_Unprotected_Access
1257 Cont_Encl_Typ : Entity_Id;
1258 Pref_Encl_Typ : Entity_Id;
1260 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
1261 -- Check whether Obj is a private component of a protected object.
1262 -- Return the protected type where the component resides, Empty
1265 function Is_Public_Operation return Boolean;
1266 -- Verify that the enclosing operation is callable from outside the
1267 -- protected object, to minimize false positives.
1269 ------------------------------
1270 -- Enclosing_Protected_Type --
1271 ------------------------------
1273 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
1275 if Is_Entity_Name (Obj) then
1277 Ent : Entity_Id := Entity (Obj);
1280 -- The object can be a renaming of a private component, use
1281 -- the original record component.
1283 if Is_Prival (Ent) then
1284 Ent := Prival_Link (Ent);
1287 if Is_Protected_Type (Scope (Ent)) then
1293 -- For indexed and selected components, recursively check the prefix
1295 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
1296 return Enclosing_Protected_Type (Prefix (Obj));
1298 -- The object does not denote a protected component
1303 end Enclosing_Protected_Type;
1305 -------------------------
1306 -- Is_Public_Operation --
1307 -------------------------
1309 function Is_Public_Operation return Boolean is
1316 and then S /= Pref_Encl_Typ
1318 if Scope (S) = Pref_Encl_Typ then
1319 E := First_Entity (Pref_Encl_Typ);
1321 and then E /= First_Private_Entity (Pref_Encl_Typ)
1334 end Is_Public_Operation;
1336 -- Start of processing for Check_Unprotected_Access
1339 if Nkind (Expr) = N_Attribute_Reference
1340 and then Attribute_Name (Expr) = Name_Unchecked_Access
1342 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
1343 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
1345 -- Check whether we are trying to export a protected component to a
1346 -- context with an equal or lower access level.
1348 if Present (Pref_Encl_Typ)
1349 and then No (Cont_Encl_Typ)
1350 and then Is_Public_Operation
1351 and then Scope_Depth (Pref_Encl_Typ) >=
1352 Object_Access_Level (Context)
1355 ("?possible unprotected access to protected data", Expr);
1358 end Check_Unprotected_Access;
1364 procedure Check_VMS (Construct : Node_Id) is
1366 if not OpenVMS_On_Target then
1368 ("this construct is allowed only in Open'V'M'S", Construct);
1372 ------------------------
1373 -- Collect_Interfaces --
1374 ------------------------
1376 procedure Collect_Interfaces
1378 Ifaces_List : out Elist_Id;
1379 Exclude_Parents : Boolean := False;
1380 Use_Full_View : Boolean := True)
1382 procedure Collect (Typ : Entity_Id);
1383 -- Subsidiary subprogram used to traverse the whole list
1384 -- of directly and indirectly implemented interfaces
1390 procedure Collect (Typ : Entity_Id) is
1391 Ancestor : Entity_Id;
1399 -- Handle private types
1402 and then Is_Private_Type (Typ)
1403 and then Present (Full_View (Typ))
1405 Full_T := Full_View (Typ);
1408 -- Include the ancestor if we are generating the whole list of
1409 -- abstract interfaces.
1411 if Etype (Full_T) /= Typ
1413 -- Protect the frontend against wrong sources. For example:
1416 -- type A is tagged null record;
1417 -- type B is new A with private;
1418 -- type C is new A with private;
1420 -- type B is new C with null record;
1421 -- type C is new B with null record;
1424 and then Etype (Full_T) /= T
1426 Ancestor := Etype (Full_T);
1429 if Is_Interface (Ancestor)
1430 and then not Exclude_Parents
1432 Append_Unique_Elmt (Ancestor, Ifaces_List);
1436 -- Traverse the graph of ancestor interfaces
1438 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
1439 Id := First (Abstract_Interface_List (Full_T));
1440 while Present (Id) loop
1441 Iface := Etype (Id);
1443 -- Protect against wrong uses. For example:
1444 -- type I is interface;
1445 -- type O is tagged null record;
1446 -- type Wrong is new I and O with null record; -- ERROR
1448 if Is_Interface (Iface) then
1450 and then Etype (T) /= T
1451 and then Interface_Present_In_Ancestor (Etype (T), Iface)
1456 Append_Unique_Elmt (Iface, Ifaces_List);
1465 -- Start of processing for Collect_Interfaces
1468 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
1469 Ifaces_List := New_Elmt_List;
1471 end Collect_Interfaces;
1473 ----------------------------------
1474 -- Collect_Interface_Components --
1475 ----------------------------------
1477 procedure Collect_Interface_Components
1478 (Tagged_Type : Entity_Id;
1479 Components_List : out Elist_Id)
1481 procedure Collect (Typ : Entity_Id);
1482 -- Subsidiary subprogram used to climb to the parents
1488 procedure Collect (Typ : Entity_Id) is
1489 Tag_Comp : Entity_Id;
1490 Parent_Typ : Entity_Id;
1493 -- Handle private types
1495 if Present (Full_View (Etype (Typ))) then
1496 Parent_Typ := Full_View (Etype (Typ));
1498 Parent_Typ := Etype (Typ);
1501 if Parent_Typ /= Typ
1503 -- Protect the frontend against wrong sources. For example:
1506 -- type A is tagged null record;
1507 -- type B is new A with private;
1508 -- type C is new A with private;
1510 -- type B is new C with null record;
1511 -- type C is new B with null record;
1514 and then Parent_Typ /= Tagged_Type
1516 Collect (Parent_Typ);
1519 -- Collect the components containing tags of secondary dispatch
1522 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
1523 while Present (Tag_Comp) loop
1524 pragma Assert (Present (Related_Type (Tag_Comp)));
1525 Append_Elmt (Tag_Comp, Components_List);
1527 Tag_Comp := Next_Tag_Component (Tag_Comp);
1531 -- Start of processing for Collect_Interface_Components
1534 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
1535 and then Is_Tagged_Type (Tagged_Type));
1537 Components_List := New_Elmt_List;
1538 Collect (Tagged_Type);
1539 end Collect_Interface_Components;
1541 -----------------------------
1542 -- Collect_Interfaces_Info --
1543 -----------------------------
1545 procedure Collect_Interfaces_Info
1547 Ifaces_List : out Elist_Id;
1548 Components_List : out Elist_Id;
1549 Tags_List : out Elist_Id)
1551 Comps_List : Elist_Id;
1552 Comp_Elmt : Elmt_Id;
1553 Comp_Iface : Entity_Id;
1554 Iface_Elmt : Elmt_Id;
1557 function Search_Tag (Iface : Entity_Id) return Entity_Id;
1558 -- Search for the secondary tag associated with the interface type
1559 -- Iface that is implemented by T.
1565 function Search_Tag (Iface : Entity_Id) return Entity_Id is
1569 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
1571 and then Ekind (Node (ADT)) = E_Constant
1572 and then Related_Type (Node (ADT)) /= Iface
1574 -- Skip the secondary dispatch tables of Iface
1582 pragma Assert (Ekind (Node (ADT)) = E_Constant);
1586 -- Start of processing for Collect_Interfaces_Info
1589 Collect_Interfaces (T, Ifaces_List);
1590 Collect_Interface_Components (T, Comps_List);
1592 -- Search for the record component and tag associated with each
1593 -- interface type of T.
1595 Components_List := New_Elmt_List;
1596 Tags_List := New_Elmt_List;
1598 Iface_Elmt := First_Elmt (Ifaces_List);
1599 while Present (Iface_Elmt) loop
1600 Iface := Node (Iface_Elmt);
1602 -- Associate the primary tag component and the primary dispatch table
1603 -- with all the interfaces that are parents of T
1605 if Is_Ancestor (Iface, T) then
1606 Append_Elmt (First_Tag_Component (T), Components_List);
1607 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
1609 -- Otherwise search for the tag component and secondary dispatch
1613 Comp_Elmt := First_Elmt (Comps_List);
1614 while Present (Comp_Elmt) loop
1615 Comp_Iface := Related_Type (Node (Comp_Elmt));
1617 if Comp_Iface = Iface
1618 or else Is_Ancestor (Iface, Comp_Iface)
1620 Append_Elmt (Node (Comp_Elmt), Components_List);
1621 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
1625 Next_Elmt (Comp_Elmt);
1627 pragma Assert (Present (Comp_Elmt));
1630 Next_Elmt (Iface_Elmt);
1632 end Collect_Interfaces_Info;
1634 ----------------------------------
1635 -- Collect_Primitive_Operations --
1636 ----------------------------------
1638 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
1639 B_Type : constant Entity_Id := Base_Type (T);
1640 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
1641 B_Scope : Entity_Id := Scope (B_Type);
1645 Formal_Derived : Boolean := False;
1649 -- For tagged types, the primitive operations are collected as they
1650 -- are declared, and held in an explicit list which is simply returned.
1652 if Is_Tagged_Type (B_Type) then
1653 return Primitive_Operations (B_Type);
1655 -- An untagged generic type that is a derived type inherits the
1656 -- primitive operations of its parent type. Other formal types only
1657 -- have predefined operators, which are not explicitly represented.
1659 elsif Is_Generic_Type (B_Type) then
1660 if Nkind (B_Decl) = N_Formal_Type_Declaration
1661 and then Nkind (Formal_Type_Definition (B_Decl))
1662 = N_Formal_Derived_Type_Definition
1664 Formal_Derived := True;
1666 return New_Elmt_List;
1670 Op_List := New_Elmt_List;
1672 if B_Scope = Standard_Standard then
1673 if B_Type = Standard_String then
1674 Append_Elmt (Standard_Op_Concat, Op_List);
1676 elsif B_Type = Standard_Wide_String then
1677 Append_Elmt (Standard_Op_Concatw, Op_List);
1683 elsif (Is_Package_Or_Generic_Package (B_Scope)
1685 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
1687 or else Is_Derived_Type (B_Type)
1689 -- The primitive operations appear after the base type, except
1690 -- if the derivation happens within the private part of B_Scope
1691 -- and the type is a private type, in which case both the type
1692 -- and some primitive operations may appear before the base
1693 -- type, and the list of candidates starts after the type.
1695 if In_Open_Scopes (B_Scope)
1696 and then Scope (T) = B_Scope
1697 and then In_Private_Part (B_Scope)
1699 Id := Next_Entity (T);
1701 Id := Next_Entity (B_Type);
1704 while Present (Id) loop
1706 -- Note that generic formal subprograms are not
1707 -- considered to be primitive operations and thus
1708 -- are never inherited.
1710 if Is_Overloadable (Id)
1711 and then Nkind (Parent (Parent (Id)))
1712 not in N_Formal_Subprogram_Declaration
1716 if Base_Type (Etype (Id)) = B_Type then
1719 Formal := First_Formal (Id);
1720 while Present (Formal) loop
1721 if Base_Type (Etype (Formal)) = B_Type then
1725 elsif Ekind (Etype (Formal)) = E_Anonymous_Access_Type
1727 (Designated_Type (Etype (Formal))) = B_Type
1733 Next_Formal (Formal);
1737 -- For a formal derived type, the only primitives are the
1738 -- ones inherited from the parent type. Operations appearing
1739 -- in the package declaration are not primitive for it.
1742 and then (not Formal_Derived
1743 or else Present (Alias (Id)))
1745 -- In the special case of an equality operator aliased to
1746 -- an overriding dispatching equality belonging to the same
1747 -- type, we don't include it in the list of primitives.
1748 -- This avoids inheriting multiple equality operators when
1749 -- deriving from untagged private types whose full type is
1750 -- tagged, which can otherwise cause ambiguities. Note that
1751 -- this should only happen for this kind of untagged parent
1752 -- type, since normally dispatching operations are inherited
1753 -- using the type's Primitive_Operations list.
1755 if Chars (Id) = Name_Op_Eq
1756 and then Is_Dispatching_Operation (Id)
1757 and then Present (Alias (Id))
1758 and then Is_Overriding_Operation (Alias (Id))
1759 and then Base_Type (Etype (First_Entity (Id))) =
1760 Base_Type (Etype (First_Entity (Alias (Id))))
1764 -- Include the subprogram in the list of primitives
1767 Append_Elmt (Id, Op_List);
1774 -- For a type declared in System, some of its operations may
1775 -- appear in the target-specific extension to System.
1778 and then B_Scope = RTU_Entity (System)
1779 and then Present_System_Aux
1781 B_Scope := System_Aux_Id;
1782 Id := First_Entity (System_Aux_Id);
1788 end Collect_Primitive_Operations;
1790 -----------------------------------
1791 -- Compile_Time_Constraint_Error --
1792 -----------------------------------
1794 function Compile_Time_Constraint_Error
1797 Ent : Entity_Id := Empty;
1798 Loc : Source_Ptr := No_Location;
1799 Warn : Boolean := False) return Node_Id
1801 Msgc : String (1 .. Msg'Length + 2);
1802 -- Copy of message, with room for possible ? and ! at end
1812 -- A static constraint error in an instance body is not a fatal error.
1813 -- we choose to inhibit the message altogether, because there is no
1814 -- obvious node (for now) on which to post it. On the other hand the
1815 -- offending node must be replaced with a constraint_error in any case.
1817 -- No messages are generated if we already posted an error on this node
1819 if not Error_Posted (N) then
1820 if Loc /= No_Location then
1826 Msgc (1 .. Msg'Length) := Msg;
1829 -- Message is a warning, even in Ada 95 case
1831 if Msg (Msg'Last) = '?' then
1834 -- In Ada 83, all messages are warnings. In the private part and
1835 -- the body of an instance, constraint_checks are only warnings.
1836 -- We also make this a warning if the Warn parameter is set.
1839 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
1845 elsif In_Instance_Not_Visible then
1850 -- Otherwise we have a real error message (Ada 95 static case)
1851 -- and we make this an unconditional message. Note that in the
1852 -- warning case we do not make the message unconditional, it seems
1853 -- quite reasonable to delete messages like this (about exceptions
1854 -- that will be raised) in dead code.
1862 -- Should we generate a warning? The answer is not quite yes. The
1863 -- very annoying exception occurs in the case of a short circuit
1864 -- operator where the left operand is static and decisive. Climb
1865 -- parents to see if that is the case we have here. Conditional
1866 -- expressions with decisive conditions are a similar situation.
1874 -- And then with False as left operand
1876 if Nkind (P) = N_And_Then
1877 and then Compile_Time_Known_Value (Left_Opnd (P))
1878 and then Is_False (Expr_Value (Left_Opnd (P)))
1883 -- OR ELSE with True as left operand
1885 elsif Nkind (P) = N_Or_Else
1886 and then Compile_Time_Known_Value (Left_Opnd (P))
1887 and then Is_True (Expr_Value (Left_Opnd (P)))
1892 -- Conditional expression
1894 elsif Nkind (P) = N_Conditional_Expression then
1896 Cond : constant Node_Id := First (Expressions (P));
1897 Texp : constant Node_Id := Next (Cond);
1898 Fexp : constant Node_Id := Next (Texp);
1901 if Compile_Time_Known_Value (Cond) then
1903 -- Condition is True and we are in the right operand
1905 if Is_True (Expr_Value (Cond))
1906 and then OldP = Fexp
1911 -- Condition is False and we are in the left operand
1913 elsif Is_False (Expr_Value (Cond))
1914 and then OldP = Texp
1922 -- Special case for component association in aggregates, where
1923 -- we want to keep climbing up to the parent aggregate.
1925 elsif Nkind (P) = N_Component_Association
1926 and then Nkind (Parent (P)) = N_Aggregate
1930 -- Keep going if within subexpression
1933 exit when Nkind (P) not in N_Subexpr;
1938 if Present (Ent) then
1939 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
1941 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
1945 if Inside_Init_Proc then
1947 ("\?& will be raised for objects of this type",
1948 N, Standard_Constraint_Error, Eloc);
1951 ("\?& will be raised at run time",
1952 N, Standard_Constraint_Error, Eloc);
1957 ("\static expression fails Constraint_Check", Eloc);
1958 Set_Error_Posted (N);
1964 end Compile_Time_Constraint_Error;
1966 -----------------------
1967 -- Conditional_Delay --
1968 -----------------------
1970 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
1972 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
1973 Set_Has_Delayed_Freeze (New_Ent);
1975 end Conditional_Delay;
1977 -------------------------
1978 -- Copy_Parameter_List --
1979 -------------------------
1981 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
1982 Loc : constant Source_Ptr := Sloc (Subp_Id);
1987 if No (First_Formal (Subp_Id)) then
1991 Formal := First_Formal (Subp_Id);
1992 while Present (Formal) loop
1994 (Make_Parameter_Specification (Loc,
1995 Defining_Identifier =>
1996 Make_Defining_Identifier (Sloc (Formal),
1997 Chars => Chars (Formal)),
1998 In_Present => In_Present (Parent (Formal)),
1999 Out_Present => Out_Present (Parent (Formal)),
2001 New_Reference_To (Etype (Formal), Loc),
2003 New_Copy_Tree (Expression (Parent (Formal)))),
2006 Next_Formal (Formal);
2011 end Copy_Parameter_List;
2013 --------------------
2014 -- Current_Entity --
2015 --------------------
2017 -- The currently visible definition for a given identifier is the
2018 -- one most chained at the start of the visibility chain, i.e. the
2019 -- one that is referenced by the Node_Id value of the name of the
2020 -- given identifier.
2022 function Current_Entity (N : Node_Id) return Entity_Id is
2024 return Get_Name_Entity_Id (Chars (N));
2027 -----------------------------
2028 -- Current_Entity_In_Scope --
2029 -----------------------------
2031 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
2033 CS : constant Entity_Id := Current_Scope;
2035 Transient_Case : constant Boolean := Scope_Is_Transient;
2038 E := Get_Name_Entity_Id (Chars (N));
2040 and then Scope (E) /= CS
2041 and then (not Transient_Case or else Scope (E) /= Scope (CS))
2047 end Current_Entity_In_Scope;
2053 function Current_Scope return Entity_Id is
2055 if Scope_Stack.Last = -1 then
2056 return Standard_Standard;
2059 C : constant Entity_Id :=
2060 Scope_Stack.Table (Scope_Stack.Last).Entity;
2065 return Standard_Standard;
2071 ------------------------
2072 -- Current_Subprogram --
2073 ------------------------
2075 function Current_Subprogram return Entity_Id is
2076 Scop : constant Entity_Id := Current_Scope;
2078 if Is_Subprogram (Scop) or else Is_Generic_Subprogram (Scop) then
2081 return Enclosing_Subprogram (Scop);
2083 end Current_Subprogram;
2085 ---------------------
2086 -- Defining_Entity --
2087 ---------------------
2089 function Defining_Entity (N : Node_Id) return Entity_Id is
2090 K : constant Node_Kind := Nkind (N);
2091 Err : Entity_Id := Empty;
2096 N_Subprogram_Declaration |
2097 N_Abstract_Subprogram_Declaration |
2099 N_Package_Declaration |
2100 N_Subprogram_Renaming_Declaration |
2101 N_Subprogram_Body_Stub |
2102 N_Generic_Subprogram_Declaration |
2103 N_Generic_Package_Declaration |
2104 N_Formal_Subprogram_Declaration
2106 return Defining_Entity (Specification (N));
2109 N_Component_Declaration |
2110 N_Defining_Program_Unit_Name |
2111 N_Discriminant_Specification |
2113 N_Entry_Declaration |
2114 N_Entry_Index_Specification |
2115 N_Exception_Declaration |
2116 N_Exception_Renaming_Declaration |
2117 N_Formal_Object_Declaration |
2118 N_Formal_Package_Declaration |
2119 N_Formal_Type_Declaration |
2120 N_Full_Type_Declaration |
2121 N_Implicit_Label_Declaration |
2122 N_Incomplete_Type_Declaration |
2123 N_Loop_Parameter_Specification |
2124 N_Number_Declaration |
2125 N_Object_Declaration |
2126 N_Object_Renaming_Declaration |
2127 N_Package_Body_Stub |
2128 N_Parameter_Specification |
2129 N_Private_Extension_Declaration |
2130 N_Private_Type_Declaration |
2132 N_Protected_Body_Stub |
2133 N_Protected_Type_Declaration |
2134 N_Single_Protected_Declaration |
2135 N_Single_Task_Declaration |
2136 N_Subtype_Declaration |
2139 N_Task_Type_Declaration
2141 return Defining_Identifier (N);
2144 return Defining_Entity (Proper_Body (N));
2147 N_Function_Instantiation |
2148 N_Function_Specification |
2149 N_Generic_Function_Renaming_Declaration |
2150 N_Generic_Package_Renaming_Declaration |
2151 N_Generic_Procedure_Renaming_Declaration |
2153 N_Package_Instantiation |
2154 N_Package_Renaming_Declaration |
2155 N_Package_Specification |
2156 N_Procedure_Instantiation |
2157 N_Procedure_Specification
2160 Nam : constant Node_Id := Defining_Unit_Name (N);
2163 if Nkind (Nam) in N_Entity then
2166 -- For Error, make up a name and attach to declaration
2167 -- so we can continue semantic analysis
2169 elsif Nam = Error then
2170 Err := Make_Temporary (Sloc (N), 'T');
2171 Set_Defining_Unit_Name (N, Err);
2174 -- If not an entity, get defining identifier
2177 return Defining_Identifier (Nam);
2181 when N_Block_Statement =>
2182 return Entity (Identifier (N));
2185 raise Program_Error;
2188 end Defining_Entity;
2190 --------------------------
2191 -- Denotes_Discriminant --
2192 --------------------------
2194 function Denotes_Discriminant
2196 Check_Concurrent : Boolean := False) return Boolean
2200 if not Is_Entity_Name (N)
2201 or else No (Entity (N))
2208 -- If we are checking for a protected type, the discriminant may have
2209 -- been rewritten as the corresponding discriminal of the original type
2210 -- or of the corresponding concurrent record, depending on whether we
2211 -- are in the spec or body of the protected type.
2213 return Ekind (E) = E_Discriminant
2216 and then Ekind (E) = E_In_Parameter
2217 and then Present (Discriminal_Link (E))
2219 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
2221 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
2223 end Denotes_Discriminant;
2225 -------------------------
2226 -- Denotes_Same_Object --
2227 -------------------------
2229 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
2231 -- If we have entity names, then must be same entity
2233 if Is_Entity_Name (A1) then
2234 if Is_Entity_Name (A2) then
2235 return Entity (A1) = Entity (A2);
2240 -- No match if not same node kind
2242 elsif Nkind (A1) /= Nkind (A2) then
2245 -- For selected components, must have same prefix and selector
2247 elsif Nkind (A1) = N_Selected_Component then
2248 return Denotes_Same_Object (Prefix (A1), Prefix (A2))
2250 Entity (Selector_Name (A1)) = Entity (Selector_Name (A2));
2252 -- For explicit dereferences, prefixes must be same
2254 elsif Nkind (A1) = N_Explicit_Dereference then
2255 return Denotes_Same_Object (Prefix (A1), Prefix (A2));
2257 -- For indexed components, prefixes and all subscripts must be the same
2259 elsif Nkind (A1) = N_Indexed_Component then
2260 if Denotes_Same_Object (Prefix (A1), Prefix (A2)) then
2266 Indx1 := First (Expressions (A1));
2267 Indx2 := First (Expressions (A2));
2268 while Present (Indx1) loop
2270 -- Shouldn't we be checking that values are the same???
2272 if not Denotes_Same_Object (Indx1, Indx2) then
2286 -- For slices, prefixes must match and bounds must match
2288 elsif Nkind (A1) = N_Slice
2289 and then Denotes_Same_Object (Prefix (A1), Prefix (A2))
2292 Lo1, Lo2, Hi1, Hi2 : Node_Id;
2295 Get_Index_Bounds (Etype (A1), Lo1, Hi1);
2296 Get_Index_Bounds (Etype (A2), Lo2, Hi2);
2298 -- Check whether bounds are statically identical. There is no
2299 -- attempt to detect partial overlap of slices.
2301 -- What about an array and a slice of an array???
2303 return Denotes_Same_Object (Lo1, Lo2)
2304 and then Denotes_Same_Object (Hi1, Hi2);
2307 -- Literals will appear as indices. Isn't this where we should check
2308 -- Known_At_Compile_Time at least if we are generating warnings ???
2310 elsif Nkind (A1) = N_Integer_Literal then
2311 return Intval (A1) = Intval (A2);
2316 end Denotes_Same_Object;
2318 -------------------------
2319 -- Denotes_Same_Prefix --
2320 -------------------------
2322 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
2325 if Is_Entity_Name (A1) then
2326 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
2327 and then not Is_Access_Type (Etype (A1))
2329 return Denotes_Same_Object (A1, Prefix (A2))
2330 or else Denotes_Same_Prefix (A1, Prefix (A2));
2335 elsif Is_Entity_Name (A2) then
2336 return Denotes_Same_Prefix (A2, A1);
2338 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
2340 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
2343 Root1, Root2 : Node_Id;
2344 Depth1, Depth2 : Int := 0;
2347 Root1 := Prefix (A1);
2348 while not Is_Entity_Name (Root1) loop
2350 (Root1, N_Selected_Component, N_Indexed_Component)
2354 Root1 := Prefix (Root1);
2357 Depth1 := Depth1 + 1;
2360 Root2 := Prefix (A2);
2361 while not Is_Entity_Name (Root2) loop
2363 (Root2, N_Selected_Component, N_Indexed_Component)
2367 Root2 := Prefix (Root2);
2370 Depth2 := Depth2 + 1;
2373 -- If both have the same depth and they do not denote the same
2374 -- object, they are disjoint and not warning is needed.
2376 if Depth1 = Depth2 then
2379 elsif Depth1 > Depth2 then
2380 Root1 := Prefix (A1);
2381 for I in 1 .. Depth1 - Depth2 - 1 loop
2382 Root1 := Prefix (Root1);
2385 return Denotes_Same_Object (Root1, A2);
2388 Root2 := Prefix (A2);
2389 for I in 1 .. Depth2 - Depth1 - 1 loop
2390 Root2 := Prefix (Root2);
2393 return Denotes_Same_Object (A1, Root2);
2400 end Denotes_Same_Prefix;
2402 ----------------------
2403 -- Denotes_Variable --
2404 ----------------------
2406 function Denotes_Variable (N : Node_Id) return Boolean is
2408 return Is_Variable (N) and then Paren_Count (N) = 0;
2409 end Denotes_Variable;
2411 -----------------------------
2412 -- Depends_On_Discriminant --
2413 -----------------------------
2415 function Depends_On_Discriminant (N : Node_Id) return Boolean is
2420 Get_Index_Bounds (N, L, H);
2421 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
2422 end Depends_On_Discriminant;
2424 -------------------------
2425 -- Designate_Same_Unit --
2426 -------------------------
2428 function Designate_Same_Unit
2430 Name2 : Node_Id) return Boolean
2432 K1 : constant Node_Kind := Nkind (Name1);
2433 K2 : constant Node_Kind := Nkind (Name2);
2435 function Prefix_Node (N : Node_Id) return Node_Id;
2436 -- Returns the parent unit name node of a defining program unit name
2437 -- or the prefix if N is a selected component or an expanded name.
2439 function Select_Node (N : Node_Id) return Node_Id;
2440 -- Returns the defining identifier node of a defining program unit
2441 -- name or the selector node if N is a selected component or an
2448 function Prefix_Node (N : Node_Id) return Node_Id is
2450 if Nkind (N) = N_Defining_Program_Unit_Name then
2462 function Select_Node (N : Node_Id) return Node_Id is
2464 if Nkind (N) = N_Defining_Program_Unit_Name then
2465 return Defining_Identifier (N);
2468 return Selector_Name (N);
2472 -- Start of processing for Designate_Next_Unit
2475 if (K1 = N_Identifier or else
2476 K1 = N_Defining_Identifier)
2478 (K2 = N_Identifier or else
2479 K2 = N_Defining_Identifier)
2481 return Chars (Name1) = Chars (Name2);
2484 (K1 = N_Expanded_Name or else
2485 K1 = N_Selected_Component or else
2486 K1 = N_Defining_Program_Unit_Name)
2488 (K2 = N_Expanded_Name or else
2489 K2 = N_Selected_Component or else
2490 K2 = N_Defining_Program_Unit_Name)
2493 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
2495 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
2500 end Designate_Same_Unit;
2502 ----------------------------
2503 -- Enclosing_Generic_Body --
2504 ----------------------------
2506 function Enclosing_Generic_Body
2507 (N : Node_Id) return Node_Id
2515 while Present (P) loop
2516 if Nkind (P) = N_Package_Body
2517 or else Nkind (P) = N_Subprogram_Body
2519 Spec := Corresponding_Spec (P);
2521 if Present (Spec) then
2522 Decl := Unit_Declaration_Node (Spec);
2524 if Nkind (Decl) = N_Generic_Package_Declaration
2525 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2536 end Enclosing_Generic_Body;
2538 ----------------------------
2539 -- Enclosing_Generic_Unit --
2540 ----------------------------
2542 function Enclosing_Generic_Unit
2543 (N : Node_Id) return Node_Id
2551 while Present (P) loop
2552 if Nkind (P) = N_Generic_Package_Declaration
2553 or else Nkind (P) = N_Generic_Subprogram_Declaration
2557 elsif Nkind (P) = N_Package_Body
2558 or else Nkind (P) = N_Subprogram_Body
2560 Spec := Corresponding_Spec (P);
2562 if Present (Spec) then
2563 Decl := Unit_Declaration_Node (Spec);
2565 if Nkind (Decl) = N_Generic_Package_Declaration
2566 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2577 end Enclosing_Generic_Unit;
2579 -------------------------------
2580 -- Enclosing_Lib_Unit_Entity --
2581 -------------------------------
2583 function Enclosing_Lib_Unit_Entity return Entity_Id is
2584 Unit_Entity : Entity_Id;
2587 -- Look for enclosing library unit entity by following scope links.
2588 -- Equivalent to, but faster than indexing through the scope stack.
2590 Unit_Entity := Current_Scope;
2591 while (Present (Scope (Unit_Entity))
2592 and then Scope (Unit_Entity) /= Standard_Standard)
2593 and not Is_Child_Unit (Unit_Entity)
2595 Unit_Entity := Scope (Unit_Entity);
2599 end Enclosing_Lib_Unit_Entity;
2601 -----------------------------
2602 -- Enclosing_Lib_Unit_Node --
2603 -----------------------------
2605 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
2606 Current_Node : Node_Id;
2610 while Present (Current_Node)
2611 and then Nkind (Current_Node) /= N_Compilation_Unit
2613 Current_Node := Parent (Current_Node);
2616 if Nkind (Current_Node) /= N_Compilation_Unit then
2620 return Current_Node;
2621 end Enclosing_Lib_Unit_Node;
2623 --------------------------
2624 -- Enclosing_Subprogram --
2625 --------------------------
2627 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
2628 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
2631 if Dynamic_Scope = Standard_Standard then
2634 elsif Dynamic_Scope = Empty then
2637 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
2638 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
2640 elsif Ekind (Dynamic_Scope) = E_Block
2641 or else Ekind (Dynamic_Scope) = E_Return_Statement
2643 return Enclosing_Subprogram (Dynamic_Scope);
2645 elsif Ekind (Dynamic_Scope) = E_Task_Type then
2646 return Get_Task_Body_Procedure (Dynamic_Scope);
2648 -- No body is generated if the protected operation is eliminated
2650 elsif Convention (Dynamic_Scope) = Convention_Protected
2651 and then not Is_Eliminated (Dynamic_Scope)
2652 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
2654 return Protected_Body_Subprogram (Dynamic_Scope);
2657 return Dynamic_Scope;
2659 end Enclosing_Subprogram;
2661 ------------------------
2662 -- Ensure_Freeze_Node --
2663 ------------------------
2665 procedure Ensure_Freeze_Node (E : Entity_Id) is
2669 if No (Freeze_Node (E)) then
2670 FN := Make_Freeze_Entity (Sloc (E));
2671 Set_Has_Delayed_Freeze (E);
2672 Set_Freeze_Node (E, FN);
2673 Set_Access_Types_To_Process (FN, No_Elist);
2674 Set_TSS_Elist (FN, No_Elist);
2677 end Ensure_Freeze_Node;
2683 procedure Enter_Name (Def_Id : Entity_Id) is
2684 C : constant Entity_Id := Current_Entity (Def_Id);
2685 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
2686 S : constant Entity_Id := Current_Scope;
2689 Generate_Definition (Def_Id);
2691 -- Add new name to current scope declarations. Check for duplicate
2692 -- declaration, which may or may not be a genuine error.
2696 -- Case of previous entity entered because of a missing declaration
2697 -- or else a bad subtype indication. Best is to use the new entity,
2698 -- and make the previous one invisible.
2700 if Etype (E) = Any_Type then
2701 Set_Is_Immediately_Visible (E, False);
2703 -- Case of renaming declaration constructed for package instances.
2704 -- if there is an explicit declaration with the same identifier,
2705 -- the renaming is not immediately visible any longer, but remains
2706 -- visible through selected component notation.
2708 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
2709 and then not Comes_From_Source (E)
2711 Set_Is_Immediately_Visible (E, False);
2713 -- The new entity may be the package renaming, which has the same
2714 -- same name as a generic formal which has been seen already.
2716 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
2717 and then not Comes_From_Source (Def_Id)
2719 Set_Is_Immediately_Visible (E, False);
2721 -- For a fat pointer corresponding to a remote access to subprogram,
2722 -- we use the same identifier as the RAS type, so that the proper
2723 -- name appears in the stub. This type is only retrieved through
2724 -- the RAS type and never by visibility, and is not added to the
2725 -- visibility list (see below).
2727 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
2728 and then Present (Corresponding_Remote_Type (Def_Id))
2732 -- A controller component for a type extension overrides the
2733 -- inherited component.
2735 elsif Chars (E) = Name_uController then
2738 -- Case of an implicit operation or derived literal. The new entity
2739 -- hides the implicit one, which is removed from all visibility,
2740 -- i.e. the entity list of its scope, and homonym chain of its name.
2742 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
2743 or else Is_Internal (E)
2747 Prev_Vis : Entity_Id;
2748 Decl : constant Node_Id := Parent (E);
2751 -- If E is an implicit declaration, it cannot be the first
2752 -- entity in the scope.
2754 Prev := First_Entity (Current_Scope);
2755 while Present (Prev)
2756 and then Next_Entity (Prev) /= E
2763 -- If E is not on the entity chain of the current scope,
2764 -- it is an implicit declaration in the generic formal
2765 -- part of a generic subprogram. When analyzing the body,
2766 -- the generic formals are visible but not on the entity
2767 -- chain of the subprogram. The new entity will become
2768 -- the visible one in the body.
2771 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
2775 Set_Next_Entity (Prev, Next_Entity (E));
2777 if No (Next_Entity (Prev)) then
2778 Set_Last_Entity (Current_Scope, Prev);
2781 if E = Current_Entity (E) then
2785 Prev_Vis := Current_Entity (E);
2786 while Homonym (Prev_Vis) /= E loop
2787 Prev_Vis := Homonym (Prev_Vis);
2791 if Present (Prev_Vis) then
2793 -- Skip E in the visibility chain
2795 Set_Homonym (Prev_Vis, Homonym (E));
2798 Set_Name_Entity_Id (Chars (E), Homonym (E));
2803 -- This section of code could use a comment ???
2805 elsif Present (Etype (E))
2806 and then Is_Concurrent_Type (Etype (E))
2811 -- If the homograph is a protected component renaming, it should not
2812 -- be hiding the current entity. Such renamings are treated as weak
2815 elsif Is_Prival (E) then
2816 Set_Is_Immediately_Visible (E, False);
2818 -- In this case the current entity is a protected component renaming.
2819 -- Perform minimal decoration by setting the scope and return since
2820 -- the prival should not be hiding other visible entities.
2822 elsif Is_Prival (Def_Id) then
2823 Set_Scope (Def_Id, Current_Scope);
2826 -- Analogous to privals, the discriminal generated for an entry
2827 -- index parameter acts as a weak declaration. Perform minimal
2828 -- decoration to avoid bogus errors.
2830 elsif Is_Discriminal (Def_Id)
2831 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
2833 Set_Scope (Def_Id, Current_Scope);
2836 -- In the body or private part of an instance, a type extension
2837 -- may introduce a component with the same name as that of an
2838 -- actual. The legality rule is not enforced, but the semantics
2839 -- of the full type with two components of the same name are not
2840 -- clear at this point ???
2842 elsif In_Instance_Not_Visible then
2845 -- When compiling a package body, some child units may have become
2846 -- visible. They cannot conflict with local entities that hide them.
2848 elsif Is_Child_Unit (E)
2849 and then In_Open_Scopes (Scope (E))
2850 and then not Is_Immediately_Visible (E)
2854 -- Conversely, with front-end inlining we may compile the parent
2855 -- body first, and a child unit subsequently. The context is now
2856 -- the parent spec, and body entities are not visible.
2858 elsif Is_Child_Unit (Def_Id)
2859 and then Is_Package_Body_Entity (E)
2860 and then not In_Package_Body (Current_Scope)
2864 -- Case of genuine duplicate declaration
2867 Error_Msg_Sloc := Sloc (E);
2869 -- If the previous declaration is an incomplete type declaration
2870 -- this may be an attempt to complete it with a private type.
2871 -- The following avoids confusing cascaded errors.
2873 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
2874 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
2877 ("incomplete type cannot be completed with a private " &
2878 "declaration", Parent (Def_Id));
2879 Set_Is_Immediately_Visible (E, False);
2880 Set_Full_View (E, Def_Id);
2882 -- An inherited component of a record conflicts with a new
2883 -- discriminant. The discriminant is inserted first in the scope,
2884 -- but the error should be posted on it, not on the component.
2886 elsif Ekind (E) = E_Discriminant
2887 and then Present (Scope (Def_Id))
2888 and then Scope (Def_Id) /= Current_Scope
2890 Error_Msg_Sloc := Sloc (Def_Id);
2891 Error_Msg_N ("& conflicts with declaration#", E);
2894 -- If the name of the unit appears in its own context clause,
2895 -- a dummy package with the name has already been created, and
2896 -- the error emitted. Try to continue quietly.
2898 elsif Error_Posted (E)
2899 and then Sloc (E) = No_Location
2900 and then Nkind (Parent (E)) = N_Package_Specification
2901 and then Current_Scope = Standard_Standard
2903 Set_Scope (Def_Id, Current_Scope);
2907 Error_Msg_N ("& conflicts with declaration#", Def_Id);
2909 -- Avoid cascaded messages with duplicate components in
2912 if Ekind_In (E, E_Component, E_Discriminant) then
2917 if Nkind (Parent (Parent (Def_Id))) =
2918 N_Generic_Subprogram_Declaration
2920 Defining_Entity (Specification (Parent (Parent (Def_Id))))
2922 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
2925 -- If entity is in standard, then we are in trouble, because
2926 -- it means that we have a library package with a duplicated
2927 -- name. That's hard to recover from, so abort!
2929 if S = Standard_Standard then
2930 raise Unrecoverable_Error;
2932 -- Otherwise we continue with the declaration. Having two
2933 -- identical declarations should not cause us too much trouble!
2941 -- If we fall through, declaration is OK , or OK enough to continue
2943 -- If Def_Id is a discriminant or a record component we are in the
2944 -- midst of inheriting components in a derived record definition.
2945 -- Preserve their Ekind and Etype.
2947 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
2950 -- If a type is already set, leave it alone (happens whey a type
2951 -- declaration is reanalyzed following a call to the optimizer)
2953 elsif Present (Etype (Def_Id)) then
2956 -- Otherwise, the kind E_Void insures that premature uses of the entity
2957 -- will be detected. Any_Type insures that no cascaded errors will occur
2960 Set_Ekind (Def_Id, E_Void);
2961 Set_Etype (Def_Id, Any_Type);
2964 -- Inherited discriminants and components in derived record types are
2965 -- immediately visible. Itypes are not.
2967 if Ekind_In (Def_Id, E_Discriminant, E_Component)
2968 or else (No (Corresponding_Remote_Type (Def_Id))
2969 and then not Is_Itype (Def_Id))
2971 Set_Is_Immediately_Visible (Def_Id);
2972 Set_Current_Entity (Def_Id);
2975 Set_Homonym (Def_Id, C);
2976 Append_Entity (Def_Id, S);
2977 Set_Public_Status (Def_Id);
2979 -- Warn if new entity hides an old one
2981 if Warn_On_Hiding and then Present (C)
2983 -- Don't warn for record components since they always have a well
2984 -- defined scope which does not confuse other uses. Note that in
2985 -- some cases, Ekind has not been set yet.
2987 and then Ekind (C) /= E_Component
2988 and then Ekind (C) /= E_Discriminant
2989 and then Nkind (Parent (C)) /= N_Component_Declaration
2990 and then Ekind (Def_Id) /= E_Component
2991 and then Ekind (Def_Id) /= E_Discriminant
2992 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
2994 -- Don't warn for one character variables. It is too common to use
2995 -- such variables as locals and will just cause too many false hits.
2997 and then Length_Of_Name (Chars (C)) /= 1
2999 -- Don't warn for non-source entities
3001 and then Comes_From_Source (C)
3002 and then Comes_From_Source (Def_Id)
3004 -- Don't warn unless entity in question is in extended main source
3006 and then In_Extended_Main_Source_Unit (Def_Id)
3008 -- Finally, the hidden entity must be either immediately visible
3009 -- or use visible (from a used package)
3012 (Is_Immediately_Visible (C)
3014 Is_Potentially_Use_Visible (C))
3016 Error_Msg_Sloc := Sloc (C);
3017 Error_Msg_N ("declaration hides &#?", Def_Id);
3021 --------------------------
3022 -- Explain_Limited_Type --
3023 --------------------------
3025 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
3029 -- For array, component type must be limited
3031 if Is_Array_Type (T) then
3032 Error_Msg_Node_2 := T;
3034 ("\component type& of type& is limited", N, Component_Type (T));
3035 Explain_Limited_Type (Component_Type (T), N);
3037 elsif Is_Record_Type (T) then
3039 -- No need for extra messages if explicit limited record
3041 if Is_Limited_Record (Base_Type (T)) then
3045 -- Otherwise find a limited component. Check only components that
3046 -- come from source, or inherited components that appear in the
3047 -- source of the ancestor.
3049 C := First_Component (T);
3050 while Present (C) loop
3051 if Is_Limited_Type (Etype (C))
3053 (Comes_From_Source (C)
3055 (Present (Original_Record_Component (C))
3057 Comes_From_Source (Original_Record_Component (C))))
3059 Error_Msg_Node_2 := T;
3060 Error_Msg_NE ("\component& of type& has limited type", N, C);
3061 Explain_Limited_Type (Etype (C), N);
3068 -- The type may be declared explicitly limited, even if no component
3069 -- of it is limited, in which case we fall out of the loop.
3072 end Explain_Limited_Type;
3078 procedure Find_Actual
3080 Formal : out Entity_Id;
3083 Parnt : constant Node_Id := Parent (N);
3087 if (Nkind (Parnt) = N_Indexed_Component
3089 Nkind (Parnt) = N_Selected_Component)
3090 and then N = Prefix (Parnt)
3092 Find_Actual (Parnt, Formal, Call);
3095 elsif Nkind (Parnt) = N_Parameter_Association
3096 and then N = Explicit_Actual_Parameter (Parnt)
3098 Call := Parent (Parnt);
3100 elsif Nkind (Parnt) = N_Procedure_Call_Statement then
3109 -- If we have a call to a subprogram look for the parameter. Note that
3110 -- we exclude overloaded calls, since we don't know enough to be sure
3111 -- of giving the right answer in this case.
3113 if Is_Entity_Name (Name (Call))
3114 and then Present (Entity (Name (Call)))
3115 and then Is_Overloadable (Entity (Name (Call)))
3116 and then not Is_Overloaded (Name (Call))
3118 -- Fall here if we are definitely a parameter
3120 Actual := First_Actual (Call);
3121 Formal := First_Formal (Entity (Name (Call)));
3122 while Present (Formal) and then Present (Actual) loop
3126 Actual := Next_Actual (Actual);
3127 Formal := Next_Formal (Formal);
3132 -- Fall through here if we did not find matching actual
3138 ---------------------------
3139 -- Find_Body_Discriminal --
3140 ---------------------------
3142 function Find_Body_Discriminal
3143 (Spec_Discriminant : Entity_Id) return Entity_Id
3145 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
3147 Tsk : constant Entity_Id :=
3148 Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
3152 -- Find discriminant of original concurrent type, and use its current
3153 -- discriminal, which is the renaming within the task/protected body.
3155 Disc := First_Discriminant (Tsk);
3156 while Present (Disc) loop
3157 if Chars (Disc) = Chars (Spec_Discriminant) then
3158 return Discriminal (Disc);
3161 Next_Discriminant (Disc);
3164 -- That loop should always succeed in finding a matching entry and
3165 -- returning. Fatal error if not.
3167 raise Program_Error;
3168 end Find_Body_Discriminal;
3170 -------------------------------------
3171 -- Find_Corresponding_Discriminant --
3172 -------------------------------------
3174 function Find_Corresponding_Discriminant
3176 Typ : Entity_Id) return Entity_Id
3178 Par_Disc : Entity_Id;
3179 Old_Disc : Entity_Id;
3180 New_Disc : Entity_Id;
3183 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
3185 -- The original type may currently be private, and the discriminant
3186 -- only appear on its full view.
3188 if Is_Private_Type (Scope (Par_Disc))
3189 and then not Has_Discriminants (Scope (Par_Disc))
3190 and then Present (Full_View (Scope (Par_Disc)))
3192 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
3194 Old_Disc := First_Discriminant (Scope (Par_Disc));
3197 if Is_Class_Wide_Type (Typ) then
3198 New_Disc := First_Discriminant (Root_Type (Typ));
3200 New_Disc := First_Discriminant (Typ);
3203 while Present (Old_Disc) and then Present (New_Disc) loop
3204 if Old_Disc = Par_Disc then
3207 Next_Discriminant (Old_Disc);
3208 Next_Discriminant (New_Disc);
3212 -- Should always find it
3214 raise Program_Error;
3215 end Find_Corresponding_Discriminant;
3217 --------------------------
3218 -- Find_Overlaid_Entity --
3219 --------------------------
3221 procedure Find_Overlaid_Entity
3223 Ent : out Entity_Id;
3229 -- We are looking for one of the two following forms:
3231 -- for X'Address use Y'Address
3235 -- Const : constant Address := expr;
3237 -- for X'Address use Const;
3239 -- In the second case, the expr is either Y'Address, or recursively a
3240 -- constant that eventually references Y'Address.
3245 if Nkind (N) = N_Attribute_Definition_Clause
3246 and then Chars (N) = Name_Address
3248 Expr := Expression (N);
3250 -- This loop checks the form of the expression for Y'Address,
3251 -- using recursion to deal with intermediate constants.
3254 -- Check for Y'Address
3256 if Nkind (Expr) = N_Attribute_Reference
3257 and then Attribute_Name (Expr) = Name_Address
3259 Expr := Prefix (Expr);
3262 -- Check for Const where Const is a constant entity
3264 elsif Is_Entity_Name (Expr)
3265 and then Ekind (Entity (Expr)) = E_Constant
3267 Expr := Constant_Value (Entity (Expr));
3269 -- Anything else does not need checking
3276 -- This loop checks the form of the prefix for an entity,
3277 -- using recursion to deal with intermediate components.
3280 -- Check for Y where Y is an entity
3282 if Is_Entity_Name (Expr) then
3283 Ent := Entity (Expr);
3286 -- Check for components
3289 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component) then
3291 Expr := Prefix (Expr);
3294 -- Anything else does not need checking
3301 end Find_Overlaid_Entity;
3303 -------------------------
3304 -- Find_Parameter_Type --
3305 -------------------------
3307 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
3309 if Nkind (Param) /= N_Parameter_Specification then
3312 -- For an access parameter, obtain the type from the formal entity
3313 -- itself, because access to subprogram nodes do not carry a type.
3314 -- Shouldn't we always use the formal entity ???
3316 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
3317 return Etype (Defining_Identifier (Param));
3320 return Etype (Parameter_Type (Param));
3322 end Find_Parameter_Type;
3324 -----------------------------
3325 -- Find_Static_Alternative --
3326 -----------------------------
3328 function Find_Static_Alternative (N : Node_Id) return Node_Id is
3329 Expr : constant Node_Id := Expression (N);
3330 Val : constant Uint := Expr_Value (Expr);
3335 Alt := First (Alternatives (N));
3338 if Nkind (Alt) /= N_Pragma then
3339 Choice := First (Discrete_Choices (Alt));
3340 while Present (Choice) loop
3342 -- Others choice, always matches
3344 if Nkind (Choice) = N_Others_Choice then
3347 -- Range, check if value is in the range
3349 elsif Nkind (Choice) = N_Range then
3351 Val >= Expr_Value (Low_Bound (Choice))
3353 Val <= Expr_Value (High_Bound (Choice));
3355 -- Choice is a subtype name. Note that we know it must
3356 -- be a static subtype, since otherwise it would have
3357 -- been diagnosed as illegal.
3359 elsif Is_Entity_Name (Choice)
3360 and then Is_Type (Entity (Choice))
3362 exit Search when Is_In_Range (Expr, Etype (Choice),
3363 Assume_Valid => False);
3365 -- Choice is a subtype indication
3367 elsif Nkind (Choice) = N_Subtype_Indication then
3369 C : constant Node_Id := Constraint (Choice);
3370 R : constant Node_Id := Range_Expression (C);
3374 Val >= Expr_Value (Low_Bound (R))
3376 Val <= Expr_Value (High_Bound (R));
3379 -- Choice is a simple expression
3382 exit Search when Val = Expr_Value (Choice);
3390 pragma Assert (Present (Alt));
3393 -- The above loop *must* terminate by finding a match, since
3394 -- we know the case statement is valid, and the value of the
3395 -- expression is known at compile time. When we fall out of
3396 -- the loop, Alt points to the alternative that we know will
3397 -- be selected at run time.
3400 end Find_Static_Alternative;
3406 function First_Actual (Node : Node_Id) return Node_Id is
3410 if No (Parameter_Associations (Node)) then
3414 N := First (Parameter_Associations (Node));
3416 if Nkind (N) = N_Parameter_Association then
3417 return First_Named_Actual (Node);
3423 -------------------------
3424 -- Full_Qualified_Name --
3425 -------------------------
3427 function Full_Qualified_Name (E : Entity_Id) return String_Id is
3429 pragma Warnings (Off, Res);
3431 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id;
3432 -- Compute recursively the qualified name without NUL at the end
3434 ----------------------------------
3435 -- Internal_Full_Qualified_Name --
3436 ----------------------------------
3438 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id is
3439 Ent : Entity_Id := E;
3440 Parent_Name : String_Id := No_String;
3443 -- Deals properly with child units
3445 if Nkind (Ent) = N_Defining_Program_Unit_Name then
3446 Ent := Defining_Identifier (Ent);
3449 -- Compute qualification recursively (only "Standard" has no scope)
3451 if Present (Scope (Scope (Ent))) then
3452 Parent_Name := Internal_Full_Qualified_Name (Scope (Ent));
3455 -- Every entity should have a name except some expanded blocks
3456 -- don't bother about those.
3458 if Chars (Ent) = No_Name then
3462 -- Add a period between Name and qualification
3464 if Parent_Name /= No_String then
3465 Start_String (Parent_Name);
3466 Store_String_Char (Get_Char_Code ('.'));
3472 -- Generates the entity name in upper case
3474 Get_Decoded_Name_String (Chars (Ent));
3476 Store_String_Chars (Name_Buffer (1 .. Name_Len));
3478 end Internal_Full_Qualified_Name;
3480 -- Start of processing for Full_Qualified_Name
3483 Res := Internal_Full_Qualified_Name (E);
3484 Store_String_Char (Get_Char_Code (ASCII.NUL));
3486 end Full_Qualified_Name;
3488 -----------------------
3489 -- Gather_Components --
3490 -----------------------
3492 procedure Gather_Components
3494 Comp_List : Node_Id;
3495 Governed_By : List_Id;
3497 Report_Errors : out Boolean)
3501 Discrete_Choice : Node_Id;
3502 Comp_Item : Node_Id;
3504 Discrim : Entity_Id;
3505 Discrim_Name : Node_Id;
3506 Discrim_Value : Node_Id;
3509 Report_Errors := False;
3511 if No (Comp_List) or else Null_Present (Comp_List) then
3514 elsif Present (Component_Items (Comp_List)) then
3515 Comp_Item := First (Component_Items (Comp_List));
3521 while Present (Comp_Item) loop
3523 -- Skip the tag of a tagged record, the interface tags, as well
3524 -- as all items that are not user components (anonymous types,
3525 -- rep clauses, Parent field, controller field).
3527 if Nkind (Comp_Item) = N_Component_Declaration then
3529 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
3531 if not Is_Tag (Comp)
3532 and then Chars (Comp) /= Name_uParent
3533 and then Chars (Comp) /= Name_uController
3535 Append_Elmt (Comp, Into);
3543 if No (Variant_Part (Comp_List)) then
3546 Discrim_Name := Name (Variant_Part (Comp_List));
3547 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
3550 -- Look for the discriminant that governs this variant part.
3551 -- The discriminant *must* be in the Governed_By List
3553 Assoc := First (Governed_By);
3554 Find_Constraint : loop
3555 Discrim := First (Choices (Assoc));
3556 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
3557 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
3559 Chars (Corresponding_Discriminant (Entity (Discrim)))
3560 = Chars (Discrim_Name))
3561 or else Chars (Original_Record_Component (Entity (Discrim)))
3562 = Chars (Discrim_Name);
3564 if No (Next (Assoc)) then
3565 if not Is_Constrained (Typ)
3566 and then Is_Derived_Type (Typ)
3567 and then Present (Stored_Constraint (Typ))
3569 -- If the type is a tagged type with inherited discriminants,
3570 -- use the stored constraint on the parent in order to find
3571 -- the values of discriminants that are otherwise hidden by an
3572 -- explicit constraint. Renamed discriminants are handled in
3575 -- If several parent discriminants are renamed by a single
3576 -- discriminant of the derived type, the call to obtain the
3577 -- Corresponding_Discriminant field only retrieves the last
3578 -- of them. We recover the constraint on the others from the
3579 -- Stored_Constraint as well.
3586 D := First_Discriminant (Etype (Typ));
3587 C := First_Elmt (Stored_Constraint (Typ));
3588 while Present (D) and then Present (C) loop
3589 if Chars (Discrim_Name) = Chars (D) then
3590 if Is_Entity_Name (Node (C))
3591 and then Entity (Node (C)) = Entity (Discrim)
3593 -- D is renamed by Discrim, whose value is given in
3600 Make_Component_Association (Sloc (Typ),
3602 (New_Occurrence_Of (D, Sloc (Typ))),
3603 Duplicate_Subexpr_No_Checks (Node (C)));
3605 exit Find_Constraint;
3608 Next_Discriminant (D);
3615 if No (Next (Assoc)) then
3616 Error_Msg_NE (" missing value for discriminant&",
3617 First (Governed_By), Discrim_Name);
3618 Report_Errors := True;
3623 end loop Find_Constraint;
3625 Discrim_Value := Expression (Assoc);
3627 if not Is_OK_Static_Expression (Discrim_Value) then
3629 ("value for discriminant & must be static!",
3630 Discrim_Value, Discrim);
3631 Why_Not_Static (Discrim_Value);
3632 Report_Errors := True;
3636 Search_For_Discriminant_Value : declare
3642 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
3645 Find_Discrete_Value : while Present (Variant) loop
3646 Discrete_Choice := First (Discrete_Choices (Variant));
3647 while Present (Discrete_Choice) loop
3649 exit Find_Discrete_Value when
3650 Nkind (Discrete_Choice) = N_Others_Choice;
3652 Get_Index_Bounds (Discrete_Choice, Low, High);
3654 UI_Low := Expr_Value (Low);
3655 UI_High := Expr_Value (High);
3657 exit Find_Discrete_Value when
3658 UI_Low <= UI_Discrim_Value
3660 UI_High >= UI_Discrim_Value;
3662 Next (Discrete_Choice);
3665 Next_Non_Pragma (Variant);
3666 end loop Find_Discrete_Value;
3667 end Search_For_Discriminant_Value;
3669 if No (Variant) then
3671 ("value of discriminant & is out of range", Discrim_Value, Discrim);
3672 Report_Errors := True;
3676 -- If we have found the corresponding choice, recursively add its
3677 -- components to the Into list.
3679 Gather_Components (Empty,
3680 Component_List (Variant), Governed_By, Into, Report_Errors);
3681 end Gather_Components;
3683 ------------------------
3684 -- Get_Actual_Subtype --
3685 ------------------------
3687 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
3688 Typ : constant Entity_Id := Etype (N);
3689 Utyp : Entity_Id := Underlying_Type (Typ);
3698 -- If what we have is an identifier that references a subprogram
3699 -- formal, or a variable or constant object, then we get the actual
3700 -- subtype from the referenced entity if one has been built.
3702 if Nkind (N) = N_Identifier
3704 (Is_Formal (Entity (N))
3705 or else Ekind (Entity (N)) = E_Constant
3706 or else Ekind (Entity (N)) = E_Variable)
3707 and then Present (Actual_Subtype (Entity (N)))
3709 return Actual_Subtype (Entity (N));
3711 -- Actual subtype of unchecked union is always itself. We never need
3712 -- the "real" actual subtype. If we did, we couldn't get it anyway
3713 -- because the discriminant is not available. The restrictions on
3714 -- Unchecked_Union are designed to make sure that this is OK.
3716 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
3719 -- Here for the unconstrained case, we must find actual subtype
3720 -- No actual subtype is available, so we must build it on the fly.
3722 -- Checking the type, not the underlying type, for constrainedness
3723 -- seems to be necessary. Maybe all the tests should be on the type???
3725 elsif (not Is_Constrained (Typ))
3726 and then (Is_Array_Type (Utyp)
3727 or else (Is_Record_Type (Utyp)
3728 and then Has_Discriminants (Utyp)))
3729 and then not Has_Unknown_Discriminants (Utyp)
3730 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
3732 -- Nothing to do if in spec expression (why not???)
3734 if In_Spec_Expression then
3737 elsif Is_Private_Type (Typ)
3738 and then not Has_Discriminants (Typ)
3740 -- If the type has no discriminants, there is no subtype to
3741 -- build, even if the underlying type is discriminated.
3745 -- Else build the actual subtype
3748 Decl := Build_Actual_Subtype (Typ, N);
3749 Atyp := Defining_Identifier (Decl);
3751 -- If Build_Actual_Subtype generated a new declaration then use it
3755 -- The actual subtype is an Itype, so analyze the declaration,
3756 -- but do not attach it to the tree, to get the type defined.
3758 Set_Parent (Decl, N);
3759 Set_Is_Itype (Atyp);
3760 Analyze (Decl, Suppress => All_Checks);
3761 Set_Associated_Node_For_Itype (Atyp, N);
3762 Set_Has_Delayed_Freeze (Atyp, False);
3764 -- We need to freeze the actual subtype immediately. This is
3765 -- needed, because otherwise this Itype will not get frozen
3766 -- at all, and it is always safe to freeze on creation because
3767 -- any associated types must be frozen at this point.
3769 Freeze_Itype (Atyp, N);
3772 -- Otherwise we did not build a declaration, so return original
3779 -- For all remaining cases, the actual subtype is the same as
3780 -- the nominal type.
3785 end Get_Actual_Subtype;
3787 -------------------------------------
3788 -- Get_Actual_Subtype_If_Available --
3789 -------------------------------------
3791 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
3792 Typ : constant Entity_Id := Etype (N);
3795 -- If what we have is an identifier that references a subprogram
3796 -- formal, or a variable or constant object, then we get the actual
3797 -- subtype from the referenced entity if one has been built.
3799 if Nkind (N) = N_Identifier
3801 (Is_Formal (Entity (N))
3802 or else Ekind (Entity (N)) = E_Constant
3803 or else Ekind (Entity (N)) = E_Variable)
3804 and then Present (Actual_Subtype (Entity (N)))
3806 return Actual_Subtype (Entity (N));
3808 -- Otherwise the Etype of N is returned unchanged
3813 end Get_Actual_Subtype_If_Available;
3815 -------------------------------
3816 -- Get_Default_External_Name --
3817 -------------------------------
3819 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
3821 Get_Decoded_Name_String (Chars (E));
3823 if Opt.External_Name_Imp_Casing = Uppercase then
3824 Set_Casing (All_Upper_Case);
3826 Set_Casing (All_Lower_Case);
3830 Make_String_Literal (Sloc (E),
3831 Strval => String_From_Name_Buffer);
3832 end Get_Default_External_Name;
3834 ---------------------------
3835 -- Get_Enum_Lit_From_Pos --
3836 ---------------------------
3838 function Get_Enum_Lit_From_Pos
3841 Loc : Source_Ptr) return Node_Id
3846 -- In the case where the literal is of type Character, Wide_Character
3847 -- or Wide_Wide_Character or of a type derived from them, there needs
3848 -- to be some special handling since there is no explicit chain of
3849 -- literals to search. Instead, an N_Character_Literal node is created
3850 -- with the appropriate Char_Code and Chars fields.
3852 if Is_Standard_Character_Type (T) then
3853 Set_Character_Literal_Name (UI_To_CC (Pos));
3855 Make_Character_Literal (Loc,
3857 Char_Literal_Value => Pos);
3859 -- For all other cases, we have a complete table of literals, and
3860 -- we simply iterate through the chain of literal until the one
3861 -- with the desired position value is found.
3865 Lit := First_Literal (Base_Type (T));
3866 for J in 1 .. UI_To_Int (Pos) loop
3870 return New_Occurrence_Of (Lit, Loc);
3872 end Get_Enum_Lit_From_Pos;
3874 ------------------------
3875 -- Get_Generic_Entity --
3876 ------------------------
3878 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
3879 Ent : constant Entity_Id := Entity (Name (N));
3881 if Present (Renamed_Object (Ent)) then
3882 return Renamed_Object (Ent);
3886 end Get_Generic_Entity;
3888 ----------------------
3889 -- Get_Index_Bounds --
3890 ----------------------
3892 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
3893 Kind : constant Node_Kind := Nkind (N);
3897 if Kind = N_Range then
3899 H := High_Bound (N);
3901 elsif Kind = N_Subtype_Indication then
3902 R := Range_Expression (Constraint (N));
3910 L := Low_Bound (Range_Expression (Constraint (N)));
3911 H := High_Bound (Range_Expression (Constraint (N)));
3914 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
3915 if Error_Posted (Scalar_Range (Entity (N))) then
3919 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
3920 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
3923 L := Low_Bound (Scalar_Range (Entity (N)));
3924 H := High_Bound (Scalar_Range (Entity (N)));
3928 -- N is an expression, indicating a range with one value
3933 end Get_Index_Bounds;
3935 ----------------------------------
3936 -- Get_Library_Unit_Name_string --
3937 ----------------------------------
3939 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
3940 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
3943 Get_Unit_Name_String (Unit_Name_Id);
3945 -- Remove seven last character (" (spec)" or " (body)")
3947 Name_Len := Name_Len - 7;
3948 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
3949 end Get_Library_Unit_Name_String;
3951 ------------------------
3952 -- Get_Name_Entity_Id --
3953 ------------------------
3955 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
3957 return Entity_Id (Get_Name_Table_Info (Id));
3958 end Get_Name_Entity_Id;
3964 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
3966 return Get_Pragma_Id (Pragma_Name (N));
3969 ---------------------------
3970 -- Get_Referenced_Object --
3971 ---------------------------
3973 function Get_Referenced_Object (N : Node_Id) return Node_Id is
3978 while Is_Entity_Name (R)
3979 and then Present (Renamed_Object (Entity (R)))
3981 R := Renamed_Object (Entity (R));
3985 end Get_Referenced_Object;
3987 ------------------------
3988 -- Get_Renamed_Entity --
3989 ------------------------
3991 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
3996 while Present (Renamed_Entity (R)) loop
3997 R := Renamed_Entity (R);
4001 end Get_Renamed_Entity;
4003 -------------------------
4004 -- Get_Subprogram_Body --
4005 -------------------------
4007 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
4011 Decl := Unit_Declaration_Node (E);
4013 if Nkind (Decl) = N_Subprogram_Body then
4016 -- The below comment is bad, because it is possible for
4017 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
4019 else -- Nkind (Decl) = N_Subprogram_Declaration
4021 if Present (Corresponding_Body (Decl)) then
4022 return Unit_Declaration_Node (Corresponding_Body (Decl));
4024 -- Imported subprogram case
4030 end Get_Subprogram_Body;
4032 ---------------------------
4033 -- Get_Subprogram_Entity --
4034 ---------------------------
4036 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
4041 if Nkind (Nod) = N_Accept_Statement then
4042 Nam := Entry_Direct_Name (Nod);
4044 -- For an entry call, the prefix of the call is a selected component.
4045 -- Need additional code for internal calls ???
4047 elsif Nkind (Nod) = N_Entry_Call_Statement then
4048 if Nkind (Name (Nod)) = N_Selected_Component then
4049 Nam := Entity (Selector_Name (Name (Nod)));
4058 if Nkind (Nam) = N_Explicit_Dereference then
4059 Proc := Etype (Prefix (Nam));
4060 elsif Is_Entity_Name (Nam) then
4061 Proc := Entity (Nam);
4066 if Is_Object (Proc) then
4067 Proc := Etype (Proc);
4070 if Ekind (Proc) = E_Access_Subprogram_Type then
4071 Proc := Directly_Designated_Type (Proc);
4074 if not Is_Subprogram (Proc)
4075 and then Ekind (Proc) /= E_Subprogram_Type
4081 end Get_Subprogram_Entity;
4083 -----------------------------
4084 -- Get_Task_Body_Procedure --
4085 -----------------------------
4087 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
4089 -- Note: A task type may be the completion of a private type with
4090 -- discriminants. When performing elaboration checks on a task
4091 -- declaration, the current view of the type may be the private one,
4092 -- and the procedure that holds the body of the task is held in its
4095 -- This is an odd function, why not have Task_Body_Procedure do
4096 -- the following digging???
4098 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
4099 end Get_Task_Body_Procedure;
4101 -----------------------
4102 -- Has_Access_Values --
4103 -----------------------
4105 function Has_Access_Values (T : Entity_Id) return Boolean is
4106 Typ : constant Entity_Id := Underlying_Type (T);
4109 -- Case of a private type which is not completed yet. This can only
4110 -- happen in the case of a generic format type appearing directly, or
4111 -- as a component of the type to which this function is being applied
4112 -- at the top level. Return False in this case, since we certainly do
4113 -- not know that the type contains access types.
4118 elsif Is_Access_Type (Typ) then
4121 elsif Is_Array_Type (Typ) then
4122 return Has_Access_Values (Component_Type (Typ));
4124 elsif Is_Record_Type (Typ) then
4129 -- Loop to Check components
4131 Comp := First_Component_Or_Discriminant (Typ);
4132 while Present (Comp) loop
4134 -- Check for access component, tag field does not count, even
4135 -- though it is implemented internally using an access type.
4137 if Has_Access_Values (Etype (Comp))
4138 and then Chars (Comp) /= Name_uTag
4143 Next_Component_Or_Discriminant (Comp);
4152 end Has_Access_Values;
4154 ------------------------------
4155 -- Has_Compatible_Alignment --
4156 ------------------------------
4158 function Has_Compatible_Alignment
4160 Expr : Node_Id) return Alignment_Result
4162 function Has_Compatible_Alignment_Internal
4165 Default : Alignment_Result) return Alignment_Result;
4166 -- This is the internal recursive function that actually does the work.
4167 -- There is one additional parameter, which says what the result should
4168 -- be if no alignment information is found, and there is no definite
4169 -- indication of compatible alignments. At the outer level, this is set
4170 -- to Unknown, but for internal recursive calls in the case where types
4171 -- are known to be correct, it is set to Known_Compatible.
4173 ---------------------------------------
4174 -- Has_Compatible_Alignment_Internal --
4175 ---------------------------------------
4177 function Has_Compatible_Alignment_Internal
4180 Default : Alignment_Result) return Alignment_Result
4182 Result : Alignment_Result := Known_Compatible;
4183 -- Holds the current status of the result. Note that once a value of
4184 -- Known_Incompatible is set, it is sticky and does not get changed
4185 -- to Unknown (the value in Result only gets worse as we go along,
4188 Offs : Uint := No_Uint;
4189 -- Set to a factor of the offset from the base object when Expr is a
4190 -- selected or indexed component, based on Component_Bit_Offset and
4191 -- Component_Size respectively. A negative value is used to represent
4192 -- a value which is not known at compile time.
4194 procedure Check_Prefix;
4195 -- Checks the prefix recursively in the case where the expression
4196 -- is an indexed or selected component.
4198 procedure Set_Result (R : Alignment_Result);
4199 -- If R represents a worse outcome (unknown instead of known
4200 -- compatible, or known incompatible), then set Result to R.
4206 procedure Check_Prefix is
4208 -- The subtlety here is that in doing a recursive call to check
4209 -- the prefix, we have to decide what to do in the case where we
4210 -- don't find any specific indication of an alignment problem.
4212 -- At the outer level, we normally set Unknown as the result in
4213 -- this case, since we can only set Known_Compatible if we really
4214 -- know that the alignment value is OK, but for the recursive
4215 -- call, in the case where the types match, and we have not
4216 -- specified a peculiar alignment for the object, we are only
4217 -- concerned about suspicious rep clauses, the default case does
4218 -- not affect us, since the compiler will, in the absence of such
4219 -- rep clauses, ensure that the alignment is correct.
4221 if Default = Known_Compatible
4223 (Etype (Obj) = Etype (Expr)
4224 and then (Unknown_Alignment (Obj)
4226 Alignment (Obj) = Alignment (Etype (Obj))))
4229 (Has_Compatible_Alignment_Internal
4230 (Obj, Prefix (Expr), Known_Compatible));
4232 -- In all other cases, we need a full check on the prefix
4236 (Has_Compatible_Alignment_Internal
4237 (Obj, Prefix (Expr), Unknown));
4245 procedure Set_Result (R : Alignment_Result) is
4252 -- Start of processing for Has_Compatible_Alignment_Internal
4255 -- If Expr is a selected component, we must make sure there is no
4256 -- potentially troublesome component clause, and that the record is
4259 if Nkind (Expr) = N_Selected_Component then
4261 -- Packed record always generate unknown alignment
4263 if Is_Packed (Etype (Prefix (Expr))) then
4264 Set_Result (Unknown);
4267 -- Check prefix and component offset
4270 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
4272 -- If Expr is an indexed component, we must make sure there is no
4273 -- potentially troublesome Component_Size clause and that the array
4274 -- is not bit-packed.
4276 elsif Nkind (Expr) = N_Indexed_Component then
4278 Typ : constant Entity_Id := Etype (Prefix (Expr));
4279 Ind : constant Node_Id := First_Index (Typ);
4282 -- Bit packed array always generates unknown alignment
4284 if Is_Bit_Packed_Array (Typ) then
4285 Set_Result (Unknown);
4288 -- Check prefix and component offset
4291 Offs := Component_Size (Typ);
4293 -- Small optimization: compute the full offset when possible
4296 and then Offs > Uint_0
4297 and then Present (Ind)
4298 and then Nkind (Ind) = N_Range
4299 and then Compile_Time_Known_Value (Low_Bound (Ind))
4300 and then Compile_Time_Known_Value (First (Expressions (Expr)))
4302 Offs := Offs * (Expr_Value (First (Expressions (Expr)))
4303 - Expr_Value (Low_Bound ((Ind))));
4308 -- If we have a null offset, the result is entirely determined by
4309 -- the base object and has already been computed recursively.
4311 if Offs = Uint_0 then
4314 -- Case where we know the alignment of the object
4316 elsif Known_Alignment (Obj) then
4318 ObjA : constant Uint := Alignment (Obj);
4319 ExpA : Uint := No_Uint;
4320 SizA : Uint := No_Uint;
4323 -- If alignment of Obj is 1, then we are always OK
4326 Set_Result (Known_Compatible);
4328 -- Alignment of Obj is greater than 1, so we need to check
4331 -- If we have an offset, see if it is compatible
4333 if Offs /= No_Uint and Offs > Uint_0 then
4334 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
4335 Set_Result (Known_Incompatible);
4338 -- See if Expr is an object with known alignment
4340 elsif Is_Entity_Name (Expr)
4341 and then Known_Alignment (Entity (Expr))
4343 ExpA := Alignment (Entity (Expr));
4345 -- Otherwise, we can use the alignment of the type of
4346 -- Expr given that we already checked for
4347 -- discombobulating rep clauses for the cases of indexed
4348 -- and selected components above.
4350 elsif Known_Alignment (Etype (Expr)) then
4351 ExpA := Alignment (Etype (Expr));
4353 -- Otherwise the alignment is unknown
4356 Set_Result (Default);
4359 -- If we got an alignment, see if it is acceptable
4361 if ExpA /= No_Uint and then ExpA < ObjA then
4362 Set_Result (Known_Incompatible);
4365 -- If Expr is not a piece of a larger object, see if size
4366 -- is given. If so, check that it is not too small for the
4367 -- required alignment.
4369 if Offs /= No_Uint then
4372 -- See if Expr is an object with known size
4374 elsif Is_Entity_Name (Expr)
4375 and then Known_Static_Esize (Entity (Expr))
4377 SizA := Esize (Entity (Expr));
4379 -- Otherwise, we check the object size of the Expr type
4381 elsif Known_Static_Esize (Etype (Expr)) then
4382 SizA := Esize (Etype (Expr));
4385 -- If we got a size, see if it is a multiple of the Obj
4386 -- alignment, if not, then the alignment cannot be
4387 -- acceptable, since the size is always a multiple of the
4390 if SizA /= No_Uint then
4391 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
4392 Set_Result (Known_Incompatible);
4398 -- If we do not know required alignment, any non-zero offset is a
4399 -- potential problem (but certainly may be OK, so result is unknown).
4401 elsif Offs /= No_Uint then
4402 Set_Result (Unknown);
4404 -- If we can't find the result by direct comparison of alignment
4405 -- values, then there is still one case that we can determine known
4406 -- result, and that is when we can determine that the types are the
4407 -- same, and no alignments are specified. Then we known that the
4408 -- alignments are compatible, even if we don't know the alignment
4409 -- value in the front end.
4411 elsif Etype (Obj) = Etype (Expr) then
4413 -- Types are the same, but we have to check for possible size
4414 -- and alignments on the Expr object that may make the alignment
4415 -- different, even though the types are the same.
4417 if Is_Entity_Name (Expr) then
4419 -- First check alignment of the Expr object. Any alignment less
4420 -- than Maximum_Alignment is worrisome since this is the case
4421 -- where we do not know the alignment of Obj.
4423 if Known_Alignment (Entity (Expr))
4425 UI_To_Int (Alignment (Entity (Expr))) <
4426 Ttypes.Maximum_Alignment
4428 Set_Result (Unknown);
4430 -- Now check size of Expr object. Any size that is not an
4431 -- even multiple of Maximum_Alignment is also worrisome
4432 -- since it may cause the alignment of the object to be less
4433 -- than the alignment of the type.
4435 elsif Known_Static_Esize (Entity (Expr))
4437 (UI_To_Int (Esize (Entity (Expr))) mod
4438 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
4441 Set_Result (Unknown);
4443 -- Otherwise same type is decisive
4446 Set_Result (Known_Compatible);
4450 -- Another case to deal with is when there is an explicit size or
4451 -- alignment clause when the types are not the same. If so, then the
4452 -- result is Unknown. We don't need to do this test if the Default is
4453 -- Unknown, since that result will be set in any case.
4455 elsif Default /= Unknown
4456 and then (Has_Size_Clause (Etype (Expr))
4458 Has_Alignment_Clause (Etype (Expr)))
4460 Set_Result (Unknown);
4462 -- If no indication found, set default
4465 Set_Result (Default);
4468 -- Return worst result found
4471 end Has_Compatible_Alignment_Internal;
4473 -- Start of processing for Has_Compatible_Alignment
4476 -- If Obj has no specified alignment, then set alignment from the type
4477 -- alignment. Perhaps we should always do this, but for sure we should
4478 -- do it when there is an address clause since we can do more if the
4479 -- alignment is known.
4481 if Unknown_Alignment (Obj) then
4482 Set_Alignment (Obj, Alignment (Etype (Obj)));
4485 -- Now do the internal call that does all the work
4487 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
4488 end Has_Compatible_Alignment;
4490 ----------------------
4491 -- Has_Declarations --
4492 ----------------------
4494 function Has_Declarations (N : Node_Id) return Boolean is
4496 return Nkind_In (Nkind (N), N_Accept_Statement,
4498 N_Compilation_Unit_Aux,
4504 N_Package_Specification);
4505 end Has_Declarations;
4507 -------------------------------------------
4508 -- Has_Discriminant_Dependent_Constraint --
4509 -------------------------------------------
4511 function Has_Discriminant_Dependent_Constraint
4512 (Comp : Entity_Id) return Boolean
4514 Comp_Decl : constant Node_Id := Parent (Comp);
4515 Subt_Indic : constant Node_Id :=
4516 Subtype_Indication (Component_Definition (Comp_Decl));
4521 if Nkind (Subt_Indic) = N_Subtype_Indication then
4522 Constr := Constraint (Subt_Indic);
4524 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
4525 Assn := First (Constraints (Constr));
4526 while Present (Assn) loop
4527 case Nkind (Assn) is
4528 when N_Subtype_Indication |
4532 if Depends_On_Discriminant (Assn) then
4536 when N_Discriminant_Association =>
4537 if Depends_On_Discriminant (Expression (Assn)) then
4552 end Has_Discriminant_Dependent_Constraint;
4554 --------------------
4555 -- Has_Infinities --
4556 --------------------
4558 function Has_Infinities (E : Entity_Id) return Boolean is
4561 Is_Floating_Point_Type (E)
4562 and then Nkind (Scalar_Range (E)) = N_Range
4563 and then Includes_Infinities (Scalar_Range (E));
4566 --------------------
4567 -- Has_Interfaces --
4568 --------------------
4570 function Has_Interfaces
4572 Use_Full_View : Boolean := True) return Boolean
4574 Typ : Entity_Id := Base_Type (T);
4577 -- Handle concurrent types
4579 if Is_Concurrent_Type (Typ) then
4580 Typ := Corresponding_Record_Type (Typ);
4583 if not Present (Typ)
4584 or else not Is_Record_Type (Typ)
4585 or else not Is_Tagged_Type (Typ)
4590 -- Handle private types
4593 and then Present (Full_View (Typ))
4595 Typ := Full_View (Typ);
4598 -- Handle concurrent record types
4600 if Is_Concurrent_Record_Type (Typ)
4601 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
4607 if Is_Interface (Typ)
4609 (Is_Record_Type (Typ)
4610 and then Present (Interfaces (Typ))
4611 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
4616 exit when Etype (Typ) = Typ
4618 -- Handle private types
4620 or else (Present (Full_View (Etype (Typ)))
4621 and then Full_View (Etype (Typ)) = Typ)
4623 -- Protect the frontend against wrong source with cyclic
4626 or else Etype (Typ) = T;
4628 -- Climb to the ancestor type handling private types
4630 if Present (Full_View (Etype (Typ))) then
4631 Typ := Full_View (Etype (Typ));
4640 ------------------------
4641 -- Has_Null_Exclusion --
4642 ------------------------
4644 function Has_Null_Exclusion (N : Node_Id) return Boolean is
4647 when N_Access_Definition |
4648 N_Access_Function_Definition |
4649 N_Access_Procedure_Definition |
4650 N_Access_To_Object_Definition |
4652 N_Derived_Type_Definition |
4653 N_Function_Specification |
4654 N_Subtype_Declaration =>
4655 return Null_Exclusion_Present (N);
4657 when N_Component_Definition |
4658 N_Formal_Object_Declaration |
4659 N_Object_Renaming_Declaration =>
4660 if Present (Subtype_Mark (N)) then
4661 return Null_Exclusion_Present (N);
4662 else pragma Assert (Present (Access_Definition (N)));
4663 return Null_Exclusion_Present (Access_Definition (N));
4666 when N_Discriminant_Specification =>
4667 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
4668 return Null_Exclusion_Present (Discriminant_Type (N));
4670 return Null_Exclusion_Present (N);
4673 when N_Object_Declaration =>
4674 if Nkind (Object_Definition (N)) = N_Access_Definition then
4675 return Null_Exclusion_Present (Object_Definition (N));
4677 return Null_Exclusion_Present (N);
4680 when N_Parameter_Specification =>
4681 if Nkind (Parameter_Type (N)) = N_Access_Definition then
4682 return Null_Exclusion_Present (Parameter_Type (N));
4684 return Null_Exclusion_Present (N);
4691 end Has_Null_Exclusion;
4693 ------------------------
4694 -- Has_Null_Extension --
4695 ------------------------
4697 function Has_Null_Extension (T : Entity_Id) return Boolean is
4698 B : constant Entity_Id := Base_Type (T);
4703 if Nkind (Parent (B)) = N_Full_Type_Declaration
4704 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
4706 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
4708 if Present (Ext) then
4709 if Null_Present (Ext) then
4712 Comps := Component_List (Ext);
4714 -- The null component list is rewritten during analysis to
4715 -- include the parent component. Any other component indicates
4716 -- that the extension was not originally null.
4718 return Null_Present (Comps)
4719 or else No (Next (First (Component_Items (Comps))));
4728 end Has_Null_Extension;
4730 -------------------------------
4731 -- Has_Overriding_Initialize --
4732 -------------------------------
4734 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
4735 BT : constant Entity_Id := Base_Type (T);
4740 if Is_Controlled (BT) then
4742 -- For derived types, check immediate ancestor, excluding
4743 -- Controlled itself.
4745 if Is_Derived_Type (BT)
4746 and then not In_Predefined_Unit (Etype (BT))
4747 and then Has_Overriding_Initialize (Etype (BT))
4751 elsif Present (Primitive_Operations (BT)) then
4752 P := First_Elmt (Primitive_Operations (BT));
4753 while Present (P) loop
4754 if Chars (Node (P)) = Name_Initialize
4755 and then Comes_From_Source (Node (P))
4766 elsif Has_Controlled_Component (BT) then
4767 Comp := First_Component (BT);
4768 while Present (Comp) loop
4769 if Has_Overriding_Initialize (Etype (Comp)) then
4773 Next_Component (Comp);
4781 end Has_Overriding_Initialize;
4783 --------------------------------------
4784 -- Has_Preelaborable_Initialization --
4785 --------------------------------------
4787 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
4790 procedure Check_Components (E : Entity_Id);
4791 -- Check component/discriminant chain, sets Has_PE False if a component
4792 -- or discriminant does not meet the preelaborable initialization rules.
4794 ----------------------
4795 -- Check_Components --
4796 ----------------------
4798 procedure Check_Components (E : Entity_Id) is
4802 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
4803 -- Returns True if and only if the expression denoted by N does not
4804 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
4806 ---------------------------------
4807 -- Is_Preelaborable_Expression --
4808 ---------------------------------
4810 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
4814 Comp_Type : Entity_Id;
4815 Is_Array_Aggr : Boolean;
4818 if Is_Static_Expression (N) then
4821 elsif Nkind (N) = N_Null then
4824 -- Attributes are allowed in general, even if their prefix is a
4825 -- formal type. (It seems that certain attributes known not to be
4826 -- static might not be allowed, but there are no rules to prevent
4829 elsif Nkind (N) = N_Attribute_Reference then
4832 -- The name of a discriminant evaluated within its parent type is
4833 -- defined to be preelaborable (10.2.1(8)). Note that we test for
4834 -- names that denote discriminals as well as discriminants to
4835 -- catch references occurring within init procs.
4837 elsif Is_Entity_Name (N)
4839 (Ekind (Entity (N)) = E_Discriminant
4841 ((Ekind (Entity (N)) = E_Constant
4842 or else Ekind (Entity (N)) = E_In_Parameter)
4843 and then Present (Discriminal_Link (Entity (N)))))
4847 elsif Nkind (N) = N_Qualified_Expression then
4848 return Is_Preelaborable_Expression (Expression (N));
4850 -- For aggregates we have to check that each of the associations
4851 -- is preelaborable.
4853 elsif Nkind (N) = N_Aggregate
4854 or else Nkind (N) = N_Extension_Aggregate
4856 Is_Array_Aggr := Is_Array_Type (Etype (N));
4858 if Is_Array_Aggr then
4859 Comp_Type := Component_Type (Etype (N));
4862 -- Check the ancestor part of extension aggregates, which must
4863 -- be either the name of a type that has preelaborable init or
4864 -- an expression that is preelaborable.
4866 if Nkind (N) = N_Extension_Aggregate then
4868 Anc_Part : constant Node_Id := Ancestor_Part (N);
4871 if Is_Entity_Name (Anc_Part)
4872 and then Is_Type (Entity (Anc_Part))
4874 if not Has_Preelaborable_Initialization
4880 elsif not Is_Preelaborable_Expression (Anc_Part) then
4886 -- Check positional associations
4888 Exp := First (Expressions (N));
4889 while Present (Exp) loop
4890 if not Is_Preelaborable_Expression (Exp) then
4897 -- Check named associations
4899 Assn := First (Component_Associations (N));
4900 while Present (Assn) loop
4901 Choice := First (Choices (Assn));
4902 while Present (Choice) loop
4903 if Is_Array_Aggr then
4904 if Nkind (Choice) = N_Others_Choice then
4907 elsif Nkind (Choice) = N_Range then
4908 if not Is_Static_Range (Choice) then
4912 elsif not Is_Static_Expression (Choice) then
4917 Comp_Type := Etype (Choice);
4923 -- If the association has a <> at this point, then we have
4924 -- to check whether the component's type has preelaborable
4925 -- initialization. Note that this only occurs when the
4926 -- association's corresponding component does not have a
4927 -- default expression, the latter case having already been
4928 -- expanded as an expression for the association.
4930 if Box_Present (Assn) then
4931 if not Has_Preelaborable_Initialization (Comp_Type) then
4935 -- In the expression case we check whether the expression
4936 -- is preelaborable.
4939 not Is_Preelaborable_Expression (Expression (Assn))
4947 -- If we get here then aggregate as a whole is preelaborable
4951 -- All other cases are not preelaborable
4956 end Is_Preelaborable_Expression;
4958 -- Start of processing for Check_Components
4961 -- Loop through entities of record or protected type
4964 while Present (Ent) loop
4966 -- We are interested only in components and discriminants
4968 if Ekind_In (Ent, E_Component, E_Discriminant) then
4970 -- Get default expression if any. If there is no declaration
4971 -- node, it means we have an internal entity. The parent and
4972 -- tag fields are examples of such entities. For these cases,
4973 -- we just test the type of the entity.
4975 if Present (Declaration_Node (Ent)) then
4976 Exp := Expression (Declaration_Node (Ent));
4981 -- A component has PI if it has no default expression and the
4982 -- component type has PI.
4985 if not Has_Preelaborable_Initialization (Etype (Ent)) then
4990 -- Require the default expression to be preelaborable
4992 elsif not Is_Preelaborable_Expression (Exp) then
5000 end Check_Components;
5002 -- Start of processing for Has_Preelaborable_Initialization
5005 -- Immediate return if already marked as known preelaborable init. This
5006 -- covers types for which this function has already been called once
5007 -- and returned True (in which case the result is cached), and also
5008 -- types to which a pragma Preelaborable_Initialization applies.
5010 if Known_To_Have_Preelab_Init (E) then
5014 -- If the type is a subtype representing a generic actual type, then
5015 -- test whether its base type has preelaborable initialization since
5016 -- the subtype representing the actual does not inherit this attribute
5017 -- from the actual or formal. (but maybe it should???)
5019 if Is_Generic_Actual_Type (E) then
5020 return Has_Preelaborable_Initialization (Base_Type (E));
5023 -- All elementary types have preelaborable initialization
5025 if Is_Elementary_Type (E) then
5028 -- Array types have PI if the component type has PI
5030 elsif Is_Array_Type (E) then
5031 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
5033 -- A derived type has preelaborable initialization if its parent type
5034 -- has preelaborable initialization and (in the case of a derived record
5035 -- extension) if the non-inherited components all have preelaborable
5036 -- initialization. However, a user-defined controlled type with an
5037 -- overriding Initialize procedure does not have preelaborable
5040 elsif Is_Derived_Type (E) then
5042 -- If the derived type is a private extension then it doesn't have
5043 -- preelaborable initialization.
5045 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
5049 -- First check whether ancestor type has preelaborable initialization
5051 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
5053 -- If OK, check extension components (if any)
5055 if Has_PE and then Is_Record_Type (E) then
5056 Check_Components (First_Entity (E));
5059 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
5060 -- with a user defined Initialize procedure does not have PI.
5063 and then Is_Controlled (E)
5064 and then Has_Overriding_Initialize (E)
5069 -- Private types not derived from a type having preelaborable init and
5070 -- that are not marked with pragma Preelaborable_Initialization do not
5071 -- have preelaborable initialization.
5073 elsif Is_Private_Type (E) then
5076 -- Record type has PI if it is non private and all components have PI
5078 elsif Is_Record_Type (E) then
5080 Check_Components (First_Entity (E));
5082 -- Protected types must not have entries, and components must meet
5083 -- same set of rules as for record components.
5085 elsif Is_Protected_Type (E) then
5086 if Has_Entries (E) then
5090 Check_Components (First_Entity (E));
5091 Check_Components (First_Private_Entity (E));
5094 -- Type System.Address always has preelaborable initialization
5096 elsif Is_RTE (E, RE_Address) then
5099 -- In all other cases, type does not have preelaborable initialization
5105 -- If type has preelaborable initialization, cache result
5108 Set_Known_To_Have_Preelab_Init (E);
5112 end Has_Preelaborable_Initialization;
5114 ---------------------------
5115 -- Has_Private_Component --
5116 ---------------------------
5118 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
5119 Btype : Entity_Id := Base_Type (Type_Id);
5120 Component : Entity_Id;
5123 if Error_Posted (Type_Id)
5124 or else Error_Posted (Btype)
5129 if Is_Class_Wide_Type (Btype) then
5130 Btype := Root_Type (Btype);
5133 if Is_Private_Type (Btype) then
5135 UT : constant Entity_Id := Underlying_Type (Btype);
5138 if No (Full_View (Btype)) then
5139 return not Is_Generic_Type (Btype)
5140 and then not Is_Generic_Type (Root_Type (Btype));
5142 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
5145 return not Is_Frozen (UT) and then Has_Private_Component (UT);
5149 elsif Is_Array_Type (Btype) then
5150 return Has_Private_Component (Component_Type (Btype));
5152 elsif Is_Record_Type (Btype) then
5153 Component := First_Component (Btype);
5154 while Present (Component) loop
5155 if Has_Private_Component (Etype (Component)) then
5159 Next_Component (Component);
5164 elsif Is_Protected_Type (Btype)
5165 and then Present (Corresponding_Record_Type (Btype))
5167 return Has_Private_Component (Corresponding_Record_Type (Btype));
5172 end Has_Private_Component;
5178 function Has_Stream (T : Entity_Id) return Boolean is
5185 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
5188 elsif Is_Array_Type (T) then
5189 return Has_Stream (Component_Type (T));
5191 elsif Is_Record_Type (T) then
5192 E := First_Component (T);
5193 while Present (E) loop
5194 if Has_Stream (Etype (E)) then
5203 elsif Is_Private_Type (T) then
5204 return Has_Stream (Underlying_Type (T));
5211 --------------------------
5212 -- Has_Tagged_Component --
5213 --------------------------
5215 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
5219 if Is_Private_Type (Typ)
5220 and then Present (Underlying_Type (Typ))
5222 return Has_Tagged_Component (Underlying_Type (Typ));
5224 elsif Is_Array_Type (Typ) then
5225 return Has_Tagged_Component (Component_Type (Typ));
5227 elsif Is_Tagged_Type (Typ) then
5230 elsif Is_Record_Type (Typ) then
5231 Comp := First_Component (Typ);
5232 while Present (Comp) loop
5233 if Has_Tagged_Component (Etype (Comp)) then
5237 Next_Component (Comp);
5245 end Has_Tagged_Component;
5247 --------------------------
5248 -- Implements_Interface --
5249 --------------------------
5251 function Implements_Interface
5252 (Typ_Ent : Entity_Id;
5253 Iface_Ent : Entity_Id;
5254 Exclude_Parents : Boolean := False) return Boolean
5256 Ifaces_List : Elist_Id;
5258 Iface : Entity_Id := Base_Type (Iface_Ent);
5259 Typ : Entity_Id := Base_Type (Typ_Ent);
5262 if Is_Class_Wide_Type (Typ) then
5263 Typ := Root_Type (Typ);
5266 if not Has_Interfaces (Typ) then
5270 if Is_Class_Wide_Type (Iface) then
5271 Iface := Root_Type (Iface);
5274 Collect_Interfaces (Typ, Ifaces_List);
5276 Elmt := First_Elmt (Ifaces_List);
5277 while Present (Elmt) loop
5278 if Is_Ancestor (Node (Elmt), Typ)
5279 and then Exclude_Parents
5283 elsif Node (Elmt) = Iface then
5291 end Implements_Interface;
5297 function In_Instance return Boolean is
5298 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
5304 and then S /= Standard_Standard
5306 if (Ekind (S) = E_Function
5307 or else Ekind (S) = E_Package
5308 or else Ekind (S) = E_Procedure)
5309 and then Is_Generic_Instance (S)
5311 -- A child instance is always compiled in the context of a parent
5312 -- instance. Nevertheless, the actuals are not analyzed in an
5313 -- instance context. We detect this case by examining the current
5314 -- compilation unit, which must be a child instance, and checking
5315 -- that it is not currently on the scope stack.
5317 if Is_Child_Unit (Curr_Unit)
5319 Nkind (Unit (Cunit (Current_Sem_Unit)))
5320 = N_Package_Instantiation
5321 and then not In_Open_Scopes (Curr_Unit)
5335 ----------------------
5336 -- In_Instance_Body --
5337 ----------------------
5339 function In_Instance_Body return Boolean is
5345 and then S /= Standard_Standard
5347 if (Ekind (S) = E_Function
5348 or else Ekind (S) = E_Procedure)
5349 and then Is_Generic_Instance (S)
5353 elsif Ekind (S) = E_Package
5354 and then In_Package_Body (S)
5355 and then Is_Generic_Instance (S)
5364 end In_Instance_Body;
5366 -----------------------------
5367 -- In_Instance_Not_Visible --
5368 -----------------------------
5370 function In_Instance_Not_Visible return Boolean is
5376 and then S /= Standard_Standard
5378 if (Ekind (S) = E_Function
5379 or else Ekind (S) = E_Procedure)
5380 and then Is_Generic_Instance (S)
5384 elsif Ekind (S) = E_Package
5385 and then (In_Package_Body (S) or else In_Private_Part (S))
5386 and then Is_Generic_Instance (S)
5395 end In_Instance_Not_Visible;
5397 ------------------------------
5398 -- In_Instance_Visible_Part --
5399 ------------------------------
5401 function In_Instance_Visible_Part return Boolean is
5407 and then S /= Standard_Standard
5409 if Ekind (S) = E_Package
5410 and then Is_Generic_Instance (S)
5411 and then not In_Package_Body (S)
5412 and then not In_Private_Part (S)
5421 end In_Instance_Visible_Part;
5423 ---------------------
5424 -- In_Package_Body --
5425 ---------------------
5427 function In_Package_Body return Boolean is
5433 and then S /= Standard_Standard
5435 if Ekind (S) = E_Package
5436 and then In_Package_Body (S)
5445 end In_Package_Body;
5447 --------------------------------
5448 -- In_Parameter_Specification --
5449 --------------------------------
5451 function In_Parameter_Specification (N : Node_Id) return Boolean is
5456 while Present (PN) loop
5457 if Nkind (PN) = N_Parameter_Specification then
5465 end In_Parameter_Specification;
5467 --------------------------------------
5468 -- In_Subprogram_Or_Concurrent_Unit --
5469 --------------------------------------
5471 function In_Subprogram_Or_Concurrent_Unit return Boolean is
5476 -- Use scope chain to check successively outer scopes
5482 if K in Subprogram_Kind
5483 or else K in Concurrent_Kind
5484 or else K in Generic_Subprogram_Kind
5488 elsif E = Standard_Standard then
5494 end In_Subprogram_Or_Concurrent_Unit;
5496 ---------------------
5497 -- In_Visible_Part --
5498 ---------------------
5500 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
5503 Is_Package_Or_Generic_Package (Scope_Id)
5504 and then In_Open_Scopes (Scope_Id)
5505 and then not In_Package_Body (Scope_Id)
5506 and then not In_Private_Part (Scope_Id);
5507 end In_Visible_Part;
5509 ---------------------------------
5510 -- Insert_Explicit_Dereference --
5511 ---------------------------------
5513 procedure Insert_Explicit_Dereference (N : Node_Id) is
5514 New_Prefix : constant Node_Id := Relocate_Node (N);
5515 Ent : Entity_Id := Empty;
5522 Save_Interps (N, New_Prefix);
5524 Rewrite (N, Make_Explicit_Dereference (Sloc (N), Prefix => New_Prefix));
5526 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
5528 if Is_Overloaded (New_Prefix) then
5530 -- The dereference is also overloaded, and its interpretations are
5531 -- the designated types of the interpretations of the original node.
5533 Set_Etype (N, Any_Type);
5535 Get_First_Interp (New_Prefix, I, It);
5536 while Present (It.Nam) loop
5539 if Is_Access_Type (T) then
5540 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
5543 Get_Next_Interp (I, It);
5549 -- Prefix is unambiguous: mark the original prefix (which might
5550 -- Come_From_Source) as a reference, since the new (relocated) one
5551 -- won't be taken into account.
5553 if Is_Entity_Name (New_Prefix) then
5554 Ent := Entity (New_Prefix);
5556 -- For a retrieval of a subcomponent of some composite object,
5557 -- retrieve the ultimate entity if there is one.
5559 elsif Nkind (New_Prefix) = N_Selected_Component
5560 or else Nkind (New_Prefix) = N_Indexed_Component
5562 Pref := Prefix (New_Prefix);
5563 while Present (Pref)
5565 (Nkind (Pref) = N_Selected_Component
5566 or else Nkind (Pref) = N_Indexed_Component)
5568 Pref := Prefix (Pref);
5571 if Present (Pref) and then Is_Entity_Name (Pref) then
5572 Ent := Entity (Pref);
5576 if Present (Ent) then
5577 Generate_Reference (Ent, New_Prefix);
5580 end Insert_Explicit_Dereference;
5582 ------------------------------------------
5583 -- Inspect_Deferred_Constant_Completion --
5584 ------------------------------------------
5586 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
5590 Decl := First (Decls);
5591 while Present (Decl) loop
5593 -- Deferred constant signature
5595 if Nkind (Decl) = N_Object_Declaration
5596 and then Constant_Present (Decl)
5597 and then No (Expression (Decl))
5599 -- No need to check internally generated constants
5601 and then Comes_From_Source (Decl)
5603 -- The constant is not completed. A full object declaration
5604 -- or a pragma Import complete a deferred constant.
5606 and then not Has_Completion (Defining_Identifier (Decl))
5609 ("constant declaration requires initialization expression",
5610 Defining_Identifier (Decl));
5613 Decl := Next (Decl);
5615 end Inspect_Deferred_Constant_Completion;
5621 function Is_AAMP_Float (E : Entity_Id) return Boolean is
5622 pragma Assert (Is_Type (E));
5624 return AAMP_On_Target
5625 and then Is_Floating_Point_Type (E)
5626 and then E = Base_Type (E);
5629 -----------------------------
5630 -- Is_Actual_Out_Parameter --
5631 -----------------------------
5633 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
5637 Find_Actual (N, Formal, Call);
5638 return Present (Formal)
5639 and then Ekind (Formal) = E_Out_Parameter;
5640 end Is_Actual_Out_Parameter;
5642 -------------------------
5643 -- Is_Actual_Parameter --
5644 -------------------------
5646 function Is_Actual_Parameter (N : Node_Id) return Boolean is
5647 PK : constant Node_Kind := Nkind (Parent (N));
5651 when N_Parameter_Association =>
5652 return N = Explicit_Actual_Parameter (Parent (N));
5654 when N_Function_Call | N_Procedure_Call_Statement =>
5655 return Is_List_Member (N)
5657 List_Containing (N) = Parameter_Associations (Parent (N));
5662 end Is_Actual_Parameter;
5664 ---------------------
5665 -- Is_Aliased_View --
5666 ---------------------
5668 function Is_Aliased_View (Obj : Node_Id) return Boolean is
5672 if Is_Entity_Name (Obj) then
5680 or else (Present (Renamed_Object (E))
5681 and then Is_Aliased_View (Renamed_Object (E)))))
5683 or else ((Is_Formal (E)
5684 or else Ekind (E) = E_Generic_In_Out_Parameter
5685 or else Ekind (E) = E_Generic_In_Parameter)
5686 and then Is_Tagged_Type (Etype (E)))
5688 or else (Is_Concurrent_Type (E)
5689 and then In_Open_Scopes (E))
5691 -- Current instance of type, either directly or as rewritten
5692 -- reference to the current object.
5694 or else (Is_Entity_Name (Original_Node (Obj))
5695 and then Present (Entity (Original_Node (Obj)))
5696 and then Is_Type (Entity (Original_Node (Obj))))
5698 or else (Is_Type (E) and then E = Current_Scope)
5700 or else (Is_Incomplete_Or_Private_Type (E)
5701 and then Full_View (E) = Current_Scope);
5703 elsif Nkind (Obj) = N_Selected_Component then
5704 return Is_Aliased (Entity (Selector_Name (Obj)));
5706 elsif Nkind (Obj) = N_Indexed_Component then
5707 return Has_Aliased_Components (Etype (Prefix (Obj)))
5709 (Is_Access_Type (Etype (Prefix (Obj)))
5711 Has_Aliased_Components
5712 (Designated_Type (Etype (Prefix (Obj)))));
5714 elsif Nkind (Obj) = N_Unchecked_Type_Conversion
5715 or else Nkind (Obj) = N_Type_Conversion
5717 return Is_Tagged_Type (Etype (Obj))
5718 and then Is_Aliased_View (Expression (Obj));
5720 elsif Nkind (Obj) = N_Explicit_Dereference then
5721 return Nkind (Original_Node (Obj)) /= N_Function_Call;
5726 end Is_Aliased_View;
5728 -------------------------
5729 -- Is_Ancestor_Package --
5730 -------------------------
5732 function Is_Ancestor_Package
5734 E2 : Entity_Id) return Boolean
5741 and then Par /= Standard_Standard
5751 end Is_Ancestor_Package;
5753 ----------------------
5754 -- Is_Atomic_Object --
5755 ----------------------
5757 function Is_Atomic_Object (N : Node_Id) return Boolean is
5759 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
5760 -- Determines if given object has atomic components
5762 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
5763 -- If prefix is an implicit dereference, examine designated type
5765 ----------------------
5766 -- Is_Atomic_Prefix --
5767 ----------------------
5769 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
5771 if Is_Access_Type (Etype (N)) then
5773 Has_Atomic_Components (Designated_Type (Etype (N)));
5775 return Object_Has_Atomic_Components (N);
5777 end Is_Atomic_Prefix;
5779 ----------------------------------
5780 -- Object_Has_Atomic_Components --
5781 ----------------------------------
5783 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
5785 if Has_Atomic_Components (Etype (N))
5786 or else Is_Atomic (Etype (N))
5790 elsif Is_Entity_Name (N)
5791 and then (Has_Atomic_Components (Entity (N))
5792 or else Is_Atomic (Entity (N)))
5796 elsif Nkind (N) = N_Indexed_Component
5797 or else Nkind (N) = N_Selected_Component
5799 return Is_Atomic_Prefix (Prefix (N));
5804 end Object_Has_Atomic_Components;
5806 -- Start of processing for Is_Atomic_Object
5809 -- Predicate is not relevant to subprograms
5811 if Is_Entity_Name (N)
5812 and then Is_Overloadable (Entity (N))
5816 elsif Is_Atomic (Etype (N))
5817 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
5821 elsif Nkind (N) = N_Indexed_Component
5822 or else Nkind (N) = N_Selected_Component
5824 return Is_Atomic_Prefix (Prefix (N));
5829 end Is_Atomic_Object;
5831 -------------------------
5832 -- Is_Coextension_Root --
5833 -------------------------
5835 function Is_Coextension_Root (N : Node_Id) return Boolean is
5838 Nkind (N) = N_Allocator
5839 and then Present (Coextensions (N))
5841 -- Anonymous access discriminants carry a list of all nested
5842 -- controlled coextensions.
5844 and then not Is_Dynamic_Coextension (N)
5845 and then not Is_Static_Coextension (N);
5846 end Is_Coextension_Root;
5848 -----------------------------
5849 -- Is_Concurrent_Interface --
5850 -----------------------------
5852 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
5857 (Is_Protected_Interface (T)
5858 or else Is_Synchronized_Interface (T)
5859 or else Is_Task_Interface (T));
5860 end Is_Concurrent_Interface;
5862 --------------------------------------
5863 -- Is_Controlling_Limited_Procedure --
5864 --------------------------------------
5866 function Is_Controlling_Limited_Procedure
5867 (Proc_Nam : Entity_Id) return Boolean
5869 Param_Typ : Entity_Id := Empty;
5872 if Ekind (Proc_Nam) = E_Procedure
5873 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
5875 Param_Typ := Etype (Parameter_Type (First (
5876 Parameter_Specifications (Parent (Proc_Nam)))));
5878 -- In this case where an Itype was created, the procedure call has been
5881 elsif Present (Associated_Node_For_Itype (Proc_Nam))
5882 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
5884 Present (Parameter_Associations
5885 (Associated_Node_For_Itype (Proc_Nam)))
5888 Etype (First (Parameter_Associations
5889 (Associated_Node_For_Itype (Proc_Nam))));
5892 if Present (Param_Typ) then
5894 Is_Interface (Param_Typ)
5895 and then Is_Limited_Record (Param_Typ);
5899 end Is_Controlling_Limited_Procedure;
5901 -----------------------------
5902 -- Is_CPP_Constructor_Call --
5903 -----------------------------
5905 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
5907 return Nkind (N) = N_Function_Call
5908 and then Is_CPP_Class (Etype (Etype (N)))
5909 and then Is_Constructor (Entity (Name (N)))
5910 and then Is_Imported (Entity (Name (N)));
5911 end Is_CPP_Constructor_Call;
5917 function Is_Delegate (T : Entity_Id) return Boolean is
5918 Desig_Type : Entity_Id;
5921 if VM_Target /= CLI_Target then
5925 -- Access-to-subprograms are delegates in CIL
5927 if Ekind (T) = E_Access_Subprogram_Type then
5931 if Ekind (T) not in Access_Kind then
5933 -- A delegate is a managed pointer. If no designated type is defined
5934 -- it means that it's not a delegate.
5939 Desig_Type := Etype (Directly_Designated_Type (T));
5941 if not Is_Tagged_Type (Desig_Type) then
5945 -- Test if the type is inherited from [mscorlib]System.Delegate
5947 while Etype (Desig_Type) /= Desig_Type loop
5948 if Chars (Scope (Desig_Type)) /= No_Name
5949 and then Is_Imported (Scope (Desig_Type))
5950 and then Get_Name_String (Chars (Scope (Desig_Type))) = "delegate"
5955 Desig_Type := Etype (Desig_Type);
5961 ----------------------------------------------
5962 -- Is_Dependent_Component_Of_Mutable_Object --
5963 ----------------------------------------------
5965 function Is_Dependent_Component_Of_Mutable_Object
5966 (Object : Node_Id) return Boolean
5969 Prefix_Type : Entity_Id;
5970 P_Aliased : Boolean := False;
5973 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
5974 -- Returns True if and only if Comp is declared within a variant part
5976 --------------------------------
5977 -- Is_Declared_Within_Variant --
5978 --------------------------------
5980 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
5981 Comp_Decl : constant Node_Id := Parent (Comp);
5982 Comp_List : constant Node_Id := Parent (Comp_Decl);
5984 return Nkind (Parent (Comp_List)) = N_Variant;
5985 end Is_Declared_Within_Variant;
5987 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
5990 if Is_Variable (Object) then
5992 if Nkind (Object) = N_Selected_Component then
5993 P := Prefix (Object);
5994 Prefix_Type := Etype (P);
5996 if Is_Entity_Name (P) then
5998 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
5999 Prefix_Type := Base_Type (Prefix_Type);
6002 if Is_Aliased (Entity (P)) then
6006 -- A discriminant check on a selected component may be
6007 -- expanded into a dereference when removing side-effects.
6008 -- Recover the original node and its type, which may be
6011 elsif Nkind (P) = N_Explicit_Dereference
6012 and then not (Comes_From_Source (P))
6014 P := Original_Node (P);
6015 Prefix_Type := Etype (P);
6018 -- Check for prefix being an aliased component ???
6023 -- A heap object is constrained by its initial value
6025 -- Ada 2005 (AI-363): Always assume the object could be mutable in
6026 -- the dereferenced case, since the access value might denote an
6027 -- unconstrained aliased object, whereas in Ada 95 the designated
6028 -- object is guaranteed to be constrained. A worst-case assumption
6029 -- has to apply in Ada 2005 because we can't tell at compile time
6030 -- whether the object is "constrained by its initial value"
6031 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
6032 -- semantic rules -- these rules are acknowledged to need fixing).
6034 if Ada_Version < Ada_05 then
6035 if Is_Access_Type (Prefix_Type)
6036 or else Nkind (P) = N_Explicit_Dereference
6041 elsif Ada_Version >= Ada_05 then
6042 if Is_Access_Type (Prefix_Type) then
6044 -- If the access type is pool-specific, and there is no
6045 -- constrained partial view of the designated type, then the
6046 -- designated object is known to be constrained.
6048 if Ekind (Prefix_Type) = E_Access_Type
6049 and then not Has_Constrained_Partial_View
6050 (Designated_Type (Prefix_Type))
6054 -- Otherwise (general access type, or there is a constrained
6055 -- partial view of the designated type), we need to check
6056 -- based on the designated type.
6059 Prefix_Type := Designated_Type (Prefix_Type);
6065 Original_Record_Component (Entity (Selector_Name (Object)));
6067 -- As per AI-0017, the renaming is illegal in a generic body,
6068 -- even if the subtype is indefinite.
6070 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
6072 if not Is_Constrained (Prefix_Type)
6073 and then (not Is_Indefinite_Subtype (Prefix_Type)
6075 (Is_Generic_Type (Prefix_Type)
6076 and then Ekind (Current_Scope) = E_Generic_Package
6077 and then In_Package_Body (Current_Scope)))
6079 and then (Is_Declared_Within_Variant (Comp)
6080 or else Has_Discriminant_Dependent_Constraint (Comp))
6081 and then (not P_Aliased or else Ada_Version >= Ada_05)
6087 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
6091 elsif Nkind (Object) = N_Indexed_Component
6092 or else Nkind (Object) = N_Slice
6094 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
6096 -- A type conversion that Is_Variable is a view conversion:
6097 -- go back to the denoted object.
6099 elsif Nkind (Object) = N_Type_Conversion then
6101 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
6106 end Is_Dependent_Component_Of_Mutable_Object;
6108 ---------------------
6109 -- Is_Dereferenced --
6110 ---------------------
6112 function Is_Dereferenced (N : Node_Id) return Boolean is
6113 P : constant Node_Id := Parent (N);
6116 (Nkind (P) = N_Selected_Component
6118 Nkind (P) = N_Explicit_Dereference
6120 Nkind (P) = N_Indexed_Component
6122 Nkind (P) = N_Slice)
6123 and then Prefix (P) = N;
6124 end Is_Dereferenced;
6126 ----------------------
6127 -- Is_Descendent_Of --
6128 ----------------------
6130 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
6135 pragma Assert (Nkind (T1) in N_Entity);
6136 pragma Assert (Nkind (T2) in N_Entity);
6138 T := Base_Type (T1);
6140 -- Immediate return if the types match
6145 -- Comment needed here ???
6147 elsif Ekind (T) = E_Class_Wide_Type then
6148 return Etype (T) = T2;
6156 -- Done if we found the type we are looking for
6161 -- Done if no more derivations to check
6168 -- Following test catches error cases resulting from prev errors
6170 elsif No (Etyp) then
6173 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
6176 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
6180 T := Base_Type (Etyp);
6183 end Is_Descendent_Of;
6189 function Is_False (U : Uint) return Boolean is
6194 ---------------------------
6195 -- Is_Fixed_Model_Number --
6196 ---------------------------
6198 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
6199 S : constant Ureal := Small_Value (T);
6200 M : Urealp.Save_Mark;
6204 R := (U = UR_Trunc (U / S) * S);
6207 end Is_Fixed_Model_Number;
6209 -------------------------------
6210 -- Is_Fully_Initialized_Type --
6211 -------------------------------
6213 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
6215 if Is_Scalar_Type (Typ) then
6218 elsif Is_Access_Type (Typ) then
6221 elsif Is_Array_Type (Typ) then
6222 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
6226 -- An interesting case, if we have a constrained type one of whose
6227 -- bounds is known to be null, then there are no elements to be
6228 -- initialized, so all the elements are initialized!
6230 if Is_Constrained (Typ) then
6233 Indx_Typ : Entity_Id;
6237 Indx := First_Index (Typ);
6238 while Present (Indx) loop
6239 if Etype (Indx) = Any_Type then
6242 -- If index is a range, use directly
6244 elsif Nkind (Indx) = N_Range then
6245 Lbd := Low_Bound (Indx);
6246 Hbd := High_Bound (Indx);
6249 Indx_Typ := Etype (Indx);
6251 if Is_Private_Type (Indx_Typ) then
6252 Indx_Typ := Full_View (Indx_Typ);
6255 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
6258 Lbd := Type_Low_Bound (Indx_Typ);
6259 Hbd := Type_High_Bound (Indx_Typ);
6263 if Compile_Time_Known_Value (Lbd)
6264 and then Compile_Time_Known_Value (Hbd)
6266 if Expr_Value (Hbd) < Expr_Value (Lbd) then
6276 -- If no null indexes, then type is not fully initialized
6282 elsif Is_Record_Type (Typ) then
6283 if Has_Discriminants (Typ)
6285 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
6286 and then Is_Fully_Initialized_Variant (Typ)
6291 -- Controlled records are considered to be fully initialized if
6292 -- there is a user defined Initialize routine. This may not be
6293 -- entirely correct, but as the spec notes, we are guessing here
6294 -- what is best from the point of view of issuing warnings.
6296 if Is_Controlled (Typ) then
6298 Utyp : constant Entity_Id := Underlying_Type (Typ);
6301 if Present (Utyp) then
6303 Init : constant Entity_Id :=
6305 (Underlying_Type (Typ), Name_Initialize));
6309 and then Comes_From_Source (Init)
6311 Is_Predefined_File_Name
6312 (File_Name (Get_Source_File_Index (Sloc (Init))))
6316 elsif Has_Null_Extension (Typ)
6318 Is_Fully_Initialized_Type
6319 (Etype (Base_Type (Typ)))
6328 -- Otherwise see if all record components are initialized
6334 Ent := First_Entity (Typ);
6335 while Present (Ent) loop
6336 if Chars (Ent) = Name_uController then
6339 elsif Ekind (Ent) = E_Component
6340 and then (No (Parent (Ent))
6341 or else No (Expression (Parent (Ent))))
6342 and then not Is_Fully_Initialized_Type (Etype (Ent))
6344 -- Special VM case for tag components, which need to be
6345 -- defined in this case, but are never initialized as VMs
6346 -- are using other dispatching mechanisms. Ignore this
6347 -- uninitialized case. Note that this applies both to the
6348 -- uTag entry and the main vtable pointer (CPP_Class case).
6350 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
6359 -- No uninitialized components, so type is fully initialized.
6360 -- Note that this catches the case of no components as well.
6364 elsif Is_Concurrent_Type (Typ) then
6367 elsif Is_Private_Type (Typ) then
6369 U : constant Entity_Id := Underlying_Type (Typ);
6375 return Is_Fully_Initialized_Type (U);
6382 end Is_Fully_Initialized_Type;
6384 ----------------------------------
6385 -- Is_Fully_Initialized_Variant --
6386 ----------------------------------
6388 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
6389 Loc : constant Source_Ptr := Sloc (Typ);
6390 Constraints : constant List_Id := New_List;
6391 Components : constant Elist_Id := New_Elmt_List;
6392 Comp_Elmt : Elmt_Id;
6394 Comp_List : Node_Id;
6396 Discr_Val : Node_Id;
6398 Report_Errors : Boolean;
6399 pragma Warnings (Off, Report_Errors);
6402 if Serious_Errors_Detected > 0 then
6406 if Is_Record_Type (Typ)
6407 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
6408 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
6410 Comp_List := Component_List (Type_Definition (Parent (Typ)));
6412 Discr := First_Discriminant (Typ);
6413 while Present (Discr) loop
6414 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
6415 Discr_Val := Expression (Parent (Discr));
6417 if Present (Discr_Val)
6418 and then Is_OK_Static_Expression (Discr_Val)
6420 Append_To (Constraints,
6421 Make_Component_Association (Loc,
6422 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
6423 Expression => New_Copy (Discr_Val)));
6431 Next_Discriminant (Discr);
6436 Comp_List => Comp_List,
6437 Governed_By => Constraints,
6439 Report_Errors => Report_Errors);
6441 -- Check that each component present is fully initialized
6443 Comp_Elmt := First_Elmt (Components);
6444 while Present (Comp_Elmt) loop
6445 Comp_Id := Node (Comp_Elmt);
6447 if Ekind (Comp_Id) = E_Component
6448 and then (No (Parent (Comp_Id))
6449 or else No (Expression (Parent (Comp_Id))))
6450 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
6455 Next_Elmt (Comp_Elmt);
6460 elsif Is_Private_Type (Typ) then
6462 U : constant Entity_Id := Underlying_Type (Typ);
6468 return Is_Fully_Initialized_Variant (U);
6474 end Is_Fully_Initialized_Variant;
6480 -- We seem to have a lot of overlapping functions that do similar things
6481 -- (testing for left hand sides or lvalues???). Anyway, since this one is
6482 -- purely syntactic, it should be in Sem_Aux I would think???
6484 function Is_LHS (N : Node_Id) return Boolean is
6485 P : constant Node_Id := Parent (N);
6487 return Nkind (P) = N_Assignment_Statement
6488 and then Name (P) = N;
6491 ----------------------------
6492 -- Is_Inherited_Operation --
6493 ----------------------------
6495 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
6496 Kind : constant Node_Kind := Nkind (Parent (E));
6498 pragma Assert (Is_Overloadable (E));
6499 return Kind = N_Full_Type_Declaration
6500 or else Kind = N_Private_Extension_Declaration
6501 or else Kind = N_Subtype_Declaration
6502 or else (Ekind (E) = E_Enumeration_Literal
6503 and then Is_Derived_Type (Etype (E)));
6504 end Is_Inherited_Operation;
6506 -----------------------------
6507 -- Is_Library_Level_Entity --
6508 -----------------------------
6510 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
6512 -- The following is a small optimization, and it also properly handles
6513 -- discriminals, which in task bodies might appear in expressions before
6514 -- the corresponding procedure has been created, and which therefore do
6515 -- not have an assigned scope.
6517 if Ekind (E) in Formal_Kind then
6521 -- Normal test is simply that the enclosing dynamic scope is Standard
6523 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
6524 end Is_Library_Level_Entity;
6526 ---------------------------------
6527 -- Is_Local_Variable_Reference --
6528 ---------------------------------
6530 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
6532 if not Is_Entity_Name (Expr) then
6537 Ent : constant Entity_Id := Entity (Expr);
6538 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
6540 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
6543 return Present (Sub) and then Sub = Current_Subprogram;
6547 end Is_Local_Variable_Reference;
6549 -------------------------
6550 -- Is_Object_Reference --
6551 -------------------------
6553 function Is_Object_Reference (N : Node_Id) return Boolean is
6555 if Is_Entity_Name (N) then
6556 return Present (Entity (N)) and then Is_Object (Entity (N));
6560 when N_Indexed_Component | N_Slice =>
6562 Is_Object_Reference (Prefix (N))
6563 or else Is_Access_Type (Etype (Prefix (N)));
6565 -- In Ada95, a function call is a constant object; a procedure
6568 when N_Function_Call =>
6569 return Etype (N) /= Standard_Void_Type;
6571 -- A reference to the stream attribute Input is a function call
6573 when N_Attribute_Reference =>
6574 return Attribute_Name (N) = Name_Input;
6576 when N_Selected_Component =>
6578 Is_Object_Reference (Selector_Name (N))
6580 (Is_Object_Reference (Prefix (N))
6581 or else Is_Access_Type (Etype (Prefix (N))));
6583 when N_Explicit_Dereference =>
6586 -- A view conversion of a tagged object is an object reference
6588 when N_Type_Conversion =>
6589 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
6590 and then Is_Tagged_Type (Etype (Expression (N)))
6591 and then Is_Object_Reference (Expression (N));
6593 -- An unchecked type conversion is considered to be an object if
6594 -- the operand is an object (this construction arises only as a
6595 -- result of expansion activities).
6597 when N_Unchecked_Type_Conversion =>
6604 end Is_Object_Reference;
6606 -----------------------------------
6607 -- Is_OK_Variable_For_Out_Formal --
6608 -----------------------------------
6610 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
6612 Note_Possible_Modification (AV, Sure => True);
6614 -- We must reject parenthesized variable names. The check for
6615 -- Comes_From_Source is present because there are currently
6616 -- cases where the compiler violates this rule (e.g. passing
6617 -- a task object to its controlled Initialize routine).
6619 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
6622 -- A variable is always allowed
6624 elsif Is_Variable (AV) then
6627 -- Unchecked conversions are allowed only if they come from the
6628 -- generated code, which sometimes uses unchecked conversions for out
6629 -- parameters in cases where code generation is unaffected. We tell
6630 -- source unchecked conversions by seeing if they are rewrites of an
6631 -- original Unchecked_Conversion function call, or of an explicit
6632 -- conversion of a function call.
6634 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
6635 if Nkind (Original_Node (AV)) = N_Function_Call then
6638 elsif Comes_From_Source (AV)
6639 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
6643 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
6644 return Is_OK_Variable_For_Out_Formal (Expression (AV));
6650 -- Normal type conversions are allowed if argument is a variable
6652 elsif Nkind (AV) = N_Type_Conversion then
6653 if Is_Variable (Expression (AV))
6654 and then Paren_Count (Expression (AV)) = 0
6656 Note_Possible_Modification (Expression (AV), Sure => True);
6659 -- We also allow a non-parenthesized expression that raises
6660 -- constraint error if it rewrites what used to be a variable
6662 elsif Raises_Constraint_Error (Expression (AV))
6663 and then Paren_Count (Expression (AV)) = 0
6664 and then Is_Variable (Original_Node (Expression (AV)))
6668 -- Type conversion of something other than a variable
6674 -- If this node is rewritten, then test the original form, if that is
6675 -- OK, then we consider the rewritten node OK (for example, if the
6676 -- original node is a conversion, then Is_Variable will not be true
6677 -- but we still want to allow the conversion if it converts a variable).
6679 elsif Original_Node (AV) /= AV then
6680 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
6682 -- All other non-variables are rejected
6687 end Is_OK_Variable_For_Out_Formal;
6689 -----------------------------------
6690 -- Is_Partially_Initialized_Type --
6691 -----------------------------------
6693 function Is_Partially_Initialized_Type (Typ : Entity_Id) return Boolean is
6695 if Is_Scalar_Type (Typ) then
6698 elsif Is_Access_Type (Typ) then
6701 elsif Is_Array_Type (Typ) then
6703 -- If component type is partially initialized, so is array type
6705 if Is_Partially_Initialized_Type (Component_Type (Typ)) then
6708 -- Otherwise we are only partially initialized if we are fully
6709 -- initialized (this is the empty array case, no point in us
6710 -- duplicating that code here).
6713 return Is_Fully_Initialized_Type (Typ);
6716 elsif Is_Record_Type (Typ) then
6718 -- A discriminated type is always partially initialized
6720 if Has_Discriminants (Typ) then
6723 -- A tagged type is always partially initialized
6725 elsif Is_Tagged_Type (Typ) then
6728 -- Case of non-discriminated record
6734 Component_Present : Boolean := False;
6735 -- Set True if at least one component is present. If no
6736 -- components are present, then record type is fully
6737 -- initialized (another odd case, like the null array).
6740 -- Loop through components
6742 Ent := First_Entity (Typ);
6743 while Present (Ent) loop
6744 if Ekind (Ent) = E_Component then
6745 Component_Present := True;
6747 -- If a component has an initialization expression then
6748 -- the enclosing record type is partially initialized
6750 if Present (Parent (Ent))
6751 and then Present (Expression (Parent (Ent)))
6755 -- If a component is of a type which is itself partially
6756 -- initialized, then the enclosing record type is also.
6758 elsif Is_Partially_Initialized_Type (Etype (Ent)) then
6766 -- No initialized components found. If we found any components
6767 -- they were all uninitialized so the result is false.
6769 if Component_Present then
6772 -- But if we found no components, then all the components are
6773 -- initialized so we consider the type to be initialized.
6781 -- Concurrent types are always fully initialized
6783 elsif Is_Concurrent_Type (Typ) then
6786 -- For a private type, go to underlying type. If there is no underlying
6787 -- type then just assume this partially initialized. Not clear if this
6788 -- can happen in a non-error case, but no harm in testing for this.
6790 elsif Is_Private_Type (Typ) then
6792 U : constant Entity_Id := Underlying_Type (Typ);
6797 return Is_Partially_Initialized_Type (U);
6801 -- For any other type (are there any?) assume partially initialized
6806 end Is_Partially_Initialized_Type;
6808 ------------------------------------
6809 -- Is_Potentially_Persistent_Type --
6810 ------------------------------------
6812 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
6817 -- For private type, test corresponding full type
6819 if Is_Private_Type (T) then
6820 return Is_Potentially_Persistent_Type (Full_View (T));
6822 -- Scalar types are potentially persistent
6824 elsif Is_Scalar_Type (T) then
6827 -- Record type is potentially persistent if not tagged and the types of
6828 -- all it components are potentially persistent, and no component has
6829 -- an initialization expression.
6831 elsif Is_Record_Type (T)
6832 and then not Is_Tagged_Type (T)
6833 and then not Is_Partially_Initialized_Type (T)
6835 Comp := First_Component (T);
6836 while Present (Comp) loop
6837 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
6846 -- Array type is potentially persistent if its component type is
6847 -- potentially persistent and if all its constraints are static.
6849 elsif Is_Array_Type (T) then
6850 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
6854 Indx := First_Index (T);
6855 while Present (Indx) loop
6856 if not Is_OK_Static_Subtype (Etype (Indx)) then
6865 -- All other types are not potentially persistent
6870 end Is_Potentially_Persistent_Type;
6872 ---------------------------------
6873 -- Is_Protected_Self_Reference --
6874 ---------------------------------
6876 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
6878 function In_Access_Definition (N : Node_Id) return Boolean;
6879 -- Returns true if N belongs to an access definition
6881 --------------------------
6882 -- In_Access_Definition --
6883 --------------------------
6885 function In_Access_Definition (N : Node_Id) return Boolean is
6890 while Present (P) loop
6891 if Nkind (P) = N_Access_Definition then
6899 end In_Access_Definition;
6901 -- Start of processing for Is_Protected_Self_Reference
6904 -- Verify that prefix is analyzed and has the proper form. Note that
6905 -- the attributes Elab_Spec, Elab_Body, and UET_Address, which also
6906 -- produce the address of an entity, do not analyze their prefix
6907 -- because they denote entities that are not necessarily visible.
6908 -- Neither of them can apply to a protected type.
6910 return Ada_Version >= Ada_05
6911 and then Is_Entity_Name (N)
6912 and then Present (Entity (N))
6913 and then Is_Protected_Type (Entity (N))
6914 and then In_Open_Scopes (Entity (N))
6915 and then not In_Access_Definition (N);
6916 end Is_Protected_Self_Reference;
6918 -----------------------------
6919 -- Is_RCI_Pkg_Spec_Or_Body --
6920 -----------------------------
6922 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
6924 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
6925 -- Return True if the unit of Cunit is an RCI package declaration
6927 ---------------------------
6928 -- Is_RCI_Pkg_Decl_Cunit --
6929 ---------------------------
6931 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
6932 The_Unit : constant Node_Id := Unit (Cunit);
6935 if Nkind (The_Unit) /= N_Package_Declaration then
6939 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
6940 end Is_RCI_Pkg_Decl_Cunit;
6942 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
6945 return Is_RCI_Pkg_Decl_Cunit (Cunit)
6947 (Nkind (Unit (Cunit)) = N_Package_Body
6948 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
6949 end Is_RCI_Pkg_Spec_Or_Body;
6951 -----------------------------------------
6952 -- Is_Remote_Access_To_Class_Wide_Type --
6953 -----------------------------------------
6955 function Is_Remote_Access_To_Class_Wide_Type
6956 (E : Entity_Id) return Boolean
6959 -- A remote access to class-wide type is a general access to object type
6960 -- declared in the visible part of a Remote_Types or Remote_Call_
6963 return Ekind (E) = E_General_Access_Type
6964 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
6965 end Is_Remote_Access_To_Class_Wide_Type;
6967 -----------------------------------------
6968 -- Is_Remote_Access_To_Subprogram_Type --
6969 -----------------------------------------
6971 function Is_Remote_Access_To_Subprogram_Type
6972 (E : Entity_Id) return Boolean
6975 return (Ekind (E) = E_Access_Subprogram_Type
6976 or else (Ekind (E) = E_Record_Type
6977 and then Present (Corresponding_Remote_Type (E))))
6978 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
6979 end Is_Remote_Access_To_Subprogram_Type;
6981 --------------------
6982 -- Is_Remote_Call --
6983 --------------------
6985 function Is_Remote_Call (N : Node_Id) return Boolean is
6987 if Nkind (N) /= N_Procedure_Call_Statement
6988 and then Nkind (N) /= N_Function_Call
6990 -- An entry call cannot be remote
6994 elsif Nkind (Name (N)) in N_Has_Entity
6995 and then Is_Remote_Call_Interface (Entity (Name (N)))
6997 -- A subprogram declared in the spec of a RCI package is remote
7001 elsif Nkind (Name (N)) = N_Explicit_Dereference
7002 and then Is_Remote_Access_To_Subprogram_Type
7003 (Etype (Prefix (Name (N))))
7005 -- The dereference of a RAS is a remote call
7009 elsif Present (Controlling_Argument (N))
7010 and then Is_Remote_Access_To_Class_Wide_Type
7011 (Etype (Controlling_Argument (N)))
7013 -- Any primitive operation call with a controlling argument of
7014 -- a RACW type is a remote call.
7019 -- All other calls are local calls
7024 ----------------------
7025 -- Is_Renamed_Entry --
7026 ----------------------
7028 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
7029 Orig_Node : Node_Id := Empty;
7030 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
7032 function Is_Entry (Nam : Node_Id) return Boolean;
7033 -- Determine whether Nam is an entry. Traverse selectors if there are
7034 -- nested selected components.
7040 function Is_Entry (Nam : Node_Id) return Boolean is
7042 if Nkind (Nam) = N_Selected_Component then
7043 return Is_Entry (Selector_Name (Nam));
7046 return Ekind (Entity (Nam)) = E_Entry;
7049 -- Start of processing for Is_Renamed_Entry
7052 if Present (Alias (Proc_Nam)) then
7053 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
7056 -- Look for a rewritten subprogram renaming declaration
7058 if Nkind (Subp_Decl) = N_Subprogram_Declaration
7059 and then Present (Original_Node (Subp_Decl))
7061 Orig_Node := Original_Node (Subp_Decl);
7064 -- The rewritten subprogram is actually an entry
7066 if Present (Orig_Node)
7067 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
7068 and then Is_Entry (Name (Orig_Node))
7074 end Is_Renamed_Entry;
7076 ----------------------
7077 -- Is_Selector_Name --
7078 ----------------------
7080 function Is_Selector_Name (N : Node_Id) return Boolean is
7082 if not Is_List_Member (N) then
7084 P : constant Node_Id := Parent (N);
7085 K : constant Node_Kind := Nkind (P);
7088 (K = N_Expanded_Name or else
7089 K = N_Generic_Association or else
7090 K = N_Parameter_Association or else
7091 K = N_Selected_Component)
7092 and then Selector_Name (P) = N;
7097 L : constant List_Id := List_Containing (N);
7098 P : constant Node_Id := Parent (L);
7100 return (Nkind (P) = N_Discriminant_Association
7101 and then Selector_Names (P) = L)
7103 (Nkind (P) = N_Component_Association
7104 and then Choices (P) = L);
7107 end Is_Selector_Name;
7113 function Is_Statement (N : Node_Id) return Boolean is
7116 Nkind (N) in N_Statement_Other_Than_Procedure_Call
7117 or else Nkind (N) = N_Procedure_Call_Statement;
7120 ---------------------------------
7121 -- Is_Synchronized_Tagged_Type --
7122 ---------------------------------
7124 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
7125 Kind : constant Entity_Kind := Ekind (Base_Type (E));
7128 -- A task or protected type derived from an interface is a tagged type.
7129 -- Such a tagged type is called a synchronized tagged type, as are
7130 -- synchronized interfaces and private extensions whose declaration
7131 -- includes the reserved word synchronized.
7133 return (Is_Tagged_Type (E)
7134 and then (Kind = E_Task_Type
7135 or else Kind = E_Protected_Type))
7138 and then Is_Synchronized_Interface (E))
7140 (Ekind (E) = E_Record_Type_With_Private
7141 and then (Synchronized_Present (Parent (E))
7142 or else Is_Synchronized_Interface (Etype (E))));
7143 end Is_Synchronized_Tagged_Type;
7149 function Is_Transfer (N : Node_Id) return Boolean is
7150 Kind : constant Node_Kind := Nkind (N);
7153 if Kind = N_Simple_Return_Statement
7155 Kind = N_Extended_Return_Statement
7157 Kind = N_Goto_Statement
7159 Kind = N_Raise_Statement
7161 Kind = N_Requeue_Statement
7165 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
7166 and then No (Condition (N))
7170 elsif Kind = N_Procedure_Call_Statement
7171 and then Is_Entity_Name (Name (N))
7172 and then Present (Entity (Name (N)))
7173 and then No_Return (Entity (Name (N)))
7177 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
7189 function Is_True (U : Uint) return Boolean is
7194 -------------------------------
7195 -- Is_Universal_Numeric_Type --
7196 -------------------------------
7198 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
7200 return T = Universal_Integer or else T = Universal_Real;
7201 end Is_Universal_Numeric_Type;
7207 function Is_Value_Type (T : Entity_Id) return Boolean is
7209 return VM_Target = CLI_Target
7210 and then Nkind (T) in N_Has_Chars
7211 and then Chars (T) /= No_Name
7212 and then Get_Name_String (Chars (T)) = "valuetype";
7215 ---------------------
7216 -- Is_VMS_Operator --
7217 ---------------------
7219 function Is_VMS_Operator (Op : Entity_Id) return Boolean is
7221 -- The VMS operators are declared in a child of System that is loaded
7222 -- through pragma Extend_System. In some rare cases a program is run
7223 -- with this extension but without indicating that the target is VMS.
7225 return Ekind (Op) = E_Function
7226 and then Is_Intrinsic_Subprogram (Op)
7228 ((Present_System_Aux
7229 and then Scope (Op) = System_Aux_Id)
7232 and then Scope (Scope (Op)) = RTU_Entity (System)));
7233 end Is_VMS_Operator;
7239 function Is_Variable (N : Node_Id) return Boolean is
7241 Orig_Node : constant Node_Id := Original_Node (N);
7242 -- We do the test on the original node, since this is basically a test
7243 -- of syntactic categories, so it must not be disturbed by whatever
7244 -- rewriting might have occurred. For example, an aggregate, which is
7245 -- certainly NOT a variable, could be turned into a variable by
7248 function In_Protected_Function (E : Entity_Id) return Boolean;
7249 -- Within a protected function, the private components of the enclosing
7250 -- protected type are constants. A function nested within a (protected)
7251 -- procedure is not itself protected.
7253 function Is_Variable_Prefix (P : Node_Id) return Boolean;
7254 -- Prefixes can involve implicit dereferences, in which case we must
7255 -- test for the case of a reference of a constant access type, which can
7256 -- can never be a variable.
7258 ---------------------------
7259 -- In_Protected_Function --
7260 ---------------------------
7262 function In_Protected_Function (E : Entity_Id) return Boolean is
7263 Prot : constant Entity_Id := Scope (E);
7267 if not Is_Protected_Type (Prot) then
7271 while Present (S) and then S /= Prot loop
7272 if Ekind (S) = E_Function and then Scope (S) = Prot then
7281 end In_Protected_Function;
7283 ------------------------
7284 -- Is_Variable_Prefix --
7285 ------------------------
7287 function Is_Variable_Prefix (P : Node_Id) return Boolean is
7289 if Is_Access_Type (Etype (P)) then
7290 return not Is_Access_Constant (Root_Type (Etype (P)));
7292 -- For the case of an indexed component whose prefix has a packed
7293 -- array type, the prefix has been rewritten into a type conversion.
7294 -- Determine variable-ness from the converted expression.
7296 elsif Nkind (P) = N_Type_Conversion
7297 and then not Comes_From_Source (P)
7298 and then Is_Array_Type (Etype (P))
7299 and then Is_Packed (Etype (P))
7301 return Is_Variable (Expression (P));
7304 return Is_Variable (P);
7306 end Is_Variable_Prefix;
7308 -- Start of processing for Is_Variable
7311 -- Definitely OK if Assignment_OK is set. Since this is something that
7312 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
7314 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
7317 -- Normally we go to the original node, but there is one exception where
7318 -- we use the rewritten node, namely when it is an explicit dereference.
7319 -- The generated code may rewrite a prefix which is an access type with
7320 -- an explicit dereference. The dereference is a variable, even though
7321 -- the original node may not be (since it could be a constant of the
7324 -- In Ada 2005 we have a further case to consider: the prefix may be a
7325 -- function call given in prefix notation. The original node appears to
7326 -- be a selected component, but we need to examine the call.
7328 elsif Nkind (N) = N_Explicit_Dereference
7329 and then Nkind (Orig_Node) /= N_Explicit_Dereference
7330 and then Present (Etype (Orig_Node))
7331 and then Is_Access_Type (Etype (Orig_Node))
7333 -- Note that if the prefix is an explicit dereference that does not
7334 -- come from source, we must check for a rewritten function call in
7335 -- prefixed notation before other forms of rewriting, to prevent a
7339 (Nkind (Orig_Node) = N_Function_Call
7340 and then not Is_Access_Constant (Etype (Prefix (N))))
7342 Is_Variable_Prefix (Original_Node (Prefix (N)));
7344 -- A function call is never a variable
7346 elsif Nkind (N) = N_Function_Call then
7349 -- All remaining checks use the original node
7351 elsif Is_Entity_Name (Orig_Node)
7352 and then Present (Entity (Orig_Node))
7355 E : constant Entity_Id := Entity (Orig_Node);
7356 K : constant Entity_Kind := Ekind (E);
7359 return (K = E_Variable
7360 and then Nkind (Parent (E)) /= N_Exception_Handler)
7361 or else (K = E_Component
7362 and then not In_Protected_Function (E))
7363 or else K = E_Out_Parameter
7364 or else K = E_In_Out_Parameter
7365 or else K = E_Generic_In_Out_Parameter
7367 -- Current instance of type:
7369 or else (Is_Type (E) and then In_Open_Scopes (E))
7370 or else (Is_Incomplete_Or_Private_Type (E)
7371 and then In_Open_Scopes (Full_View (E)));
7375 case Nkind (Orig_Node) is
7376 when N_Indexed_Component | N_Slice =>
7377 return Is_Variable_Prefix (Prefix (Orig_Node));
7379 when N_Selected_Component =>
7380 return Is_Variable_Prefix (Prefix (Orig_Node))
7381 and then Is_Variable (Selector_Name (Orig_Node));
7383 -- For an explicit dereference, the type of the prefix cannot
7384 -- be an access to constant or an access to subprogram.
7386 when N_Explicit_Dereference =>
7388 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
7390 return Is_Access_Type (Typ)
7391 and then not Is_Access_Constant (Root_Type (Typ))
7392 and then Ekind (Typ) /= E_Access_Subprogram_Type;
7395 -- The type conversion is the case where we do not deal with the
7396 -- context dependent special case of an actual parameter. Thus
7397 -- the type conversion is only considered a variable for the
7398 -- purposes of this routine if the target type is tagged. However,
7399 -- a type conversion is considered to be a variable if it does not
7400 -- come from source (this deals for example with the conversions
7401 -- of expressions to their actual subtypes).
7403 when N_Type_Conversion =>
7404 return Is_Variable (Expression (Orig_Node))
7406 (not Comes_From_Source (Orig_Node)
7408 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
7410 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
7412 -- GNAT allows an unchecked type conversion as a variable. This
7413 -- only affects the generation of internal expanded code, since
7414 -- calls to instantiations of Unchecked_Conversion are never
7415 -- considered variables (since they are function calls).
7416 -- This is also true for expression actions.
7418 when N_Unchecked_Type_Conversion =>
7419 return Is_Variable (Expression (Orig_Node));
7427 ---------------------------
7428 -- Is_Visibly_Controlled --
7429 ---------------------------
7431 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
7432 Root : constant Entity_Id := Root_Type (T);
7434 return Chars (Scope (Root)) = Name_Finalization
7435 and then Chars (Scope (Scope (Root))) = Name_Ada
7436 and then Scope (Scope (Scope (Root))) = Standard_Standard;
7437 end Is_Visibly_Controlled;
7439 ------------------------
7440 -- Is_Volatile_Object --
7441 ------------------------
7443 function Is_Volatile_Object (N : Node_Id) return Boolean is
7445 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
7446 -- Determines if given object has volatile components
7448 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
7449 -- If prefix is an implicit dereference, examine designated type
7451 ------------------------
7452 -- Is_Volatile_Prefix --
7453 ------------------------
7455 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
7456 Typ : constant Entity_Id := Etype (N);
7459 if Is_Access_Type (Typ) then
7461 Dtyp : constant Entity_Id := Designated_Type (Typ);
7464 return Is_Volatile (Dtyp)
7465 or else Has_Volatile_Components (Dtyp);
7469 return Object_Has_Volatile_Components (N);
7471 end Is_Volatile_Prefix;
7473 ------------------------------------
7474 -- Object_Has_Volatile_Components --
7475 ------------------------------------
7477 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
7478 Typ : constant Entity_Id := Etype (N);
7481 if Is_Volatile (Typ)
7482 or else Has_Volatile_Components (Typ)
7486 elsif Is_Entity_Name (N)
7487 and then (Has_Volatile_Components (Entity (N))
7488 or else Is_Volatile (Entity (N)))
7492 elsif Nkind (N) = N_Indexed_Component
7493 or else Nkind (N) = N_Selected_Component
7495 return Is_Volatile_Prefix (Prefix (N));
7500 end Object_Has_Volatile_Components;
7502 -- Start of processing for Is_Volatile_Object
7505 if Is_Volatile (Etype (N))
7506 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
7510 elsif Nkind (N) = N_Indexed_Component
7511 or else Nkind (N) = N_Selected_Component
7513 return Is_Volatile_Prefix (Prefix (N));
7518 end Is_Volatile_Object;
7520 -------------------------
7521 -- Kill_Current_Values --
7522 -------------------------
7524 procedure Kill_Current_Values
7526 Last_Assignment_Only : Boolean := False)
7529 -- ??? do we have to worry about clearing cached checks?
7531 if Is_Assignable (Ent) then
7532 Set_Last_Assignment (Ent, Empty);
7535 if Is_Object (Ent) then
7536 if not Last_Assignment_Only then
7538 Set_Current_Value (Ent, Empty);
7540 if not Can_Never_Be_Null (Ent) then
7541 Set_Is_Known_Non_Null (Ent, False);
7544 Set_Is_Known_Null (Ent, False);
7546 -- Reset Is_Known_Valid unless type is always valid, or if we have
7547 -- a loop parameter (loop parameters are always valid, since their
7548 -- bounds are defined by the bounds given in the loop header).
7550 if not Is_Known_Valid (Etype (Ent))
7551 and then Ekind (Ent) /= E_Loop_Parameter
7553 Set_Is_Known_Valid (Ent, False);
7557 end Kill_Current_Values;
7559 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
7562 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
7563 -- Clear current value for entity E and all entities chained to E
7565 ------------------------------------------
7566 -- Kill_Current_Values_For_Entity_Chain --
7567 ------------------------------------------
7569 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
7573 while Present (Ent) loop
7574 Kill_Current_Values (Ent, Last_Assignment_Only);
7577 end Kill_Current_Values_For_Entity_Chain;
7579 -- Start of processing for Kill_Current_Values
7582 -- Kill all saved checks, a special case of killing saved values
7584 if not Last_Assignment_Only then
7588 -- Loop through relevant scopes, which includes the current scope and
7589 -- any parent scopes if the current scope is a block or a package.
7594 -- Clear current values of all entities in current scope
7596 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
7598 -- If scope is a package, also clear current values of all
7599 -- private entities in the scope.
7601 if Is_Package_Or_Generic_Package (S)
7602 or else Is_Concurrent_Type (S)
7604 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
7607 -- If this is a not a subprogram, deal with parents
7609 if not Is_Subprogram (S) then
7611 exit Scope_Loop when S = Standard_Standard;
7615 end loop Scope_Loop;
7616 end Kill_Current_Values;
7618 --------------------------
7619 -- Kill_Size_Check_Code --
7620 --------------------------
7622 procedure Kill_Size_Check_Code (E : Entity_Id) is
7624 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7625 and then Present (Size_Check_Code (E))
7627 Remove (Size_Check_Code (E));
7628 Set_Size_Check_Code (E, Empty);
7630 end Kill_Size_Check_Code;
7632 --------------------------
7633 -- Known_To_Be_Assigned --
7634 --------------------------
7636 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
7637 P : constant Node_Id := Parent (N);
7642 -- Test left side of assignment
7644 when N_Assignment_Statement =>
7645 return N = Name (P);
7647 -- Function call arguments are never lvalues
7649 when N_Function_Call =>
7652 -- Positional parameter for procedure or accept call
7654 when N_Procedure_Call_Statement |
7663 Proc := Get_Subprogram_Entity (P);
7669 -- If we are not a list member, something is strange, so
7670 -- be conservative and return False.
7672 if not Is_List_Member (N) then
7676 -- We are going to find the right formal by stepping forward
7677 -- through the formals, as we step backwards in the actuals.
7679 Form := First_Formal (Proc);
7682 -- If no formal, something is weird, so be conservative
7683 -- and return False.
7694 return Ekind (Form) /= E_In_Parameter;
7697 -- Named parameter for procedure or accept call
7699 when N_Parameter_Association =>
7705 Proc := Get_Subprogram_Entity (Parent (P));
7711 -- Loop through formals to find the one that matches
7713 Form := First_Formal (Proc);
7715 -- If no matching formal, that's peculiar, some kind of
7716 -- previous error, so return False to be conservative.
7722 -- Else test for match
7724 if Chars (Form) = Chars (Selector_Name (P)) then
7725 return Ekind (Form) /= E_In_Parameter;
7732 -- Test for appearing in a conversion that itself appears
7733 -- in an lvalue context, since this should be an lvalue.
7735 when N_Type_Conversion =>
7736 return Known_To_Be_Assigned (P);
7738 -- All other references are definitely not known to be modifications
7744 end Known_To_Be_Assigned;
7750 function May_Be_Lvalue (N : Node_Id) return Boolean is
7751 P : constant Node_Id := Parent (N);
7756 -- Test left side of assignment
7758 when N_Assignment_Statement =>
7759 return N = Name (P);
7761 -- Test prefix of component or attribute. Note that the prefix of an
7762 -- explicit or implicit dereference cannot be an l-value.
7764 when N_Attribute_Reference =>
7765 return N = Prefix (P)
7766 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
7768 -- For an expanded name, the name is an lvalue if the expanded name
7769 -- is an lvalue, but the prefix is never an lvalue, since it is just
7770 -- the scope where the name is found.
7772 when N_Expanded_Name =>
7773 if N = Prefix (P) then
7774 return May_Be_Lvalue (P);
7779 -- For a selected component A.B, A is certainly an lvalue if A.B is.
7780 -- B is a little interesting, if we have A.B := 3, there is some
7781 -- discussion as to whether B is an lvalue or not, we choose to say
7782 -- it is. Note however that A is not an lvalue if it is of an access
7783 -- type since this is an implicit dereference.
7785 when N_Selected_Component =>
7787 and then Present (Etype (N))
7788 and then Is_Access_Type (Etype (N))
7792 return May_Be_Lvalue (P);
7795 -- For an indexed component or slice, the index or slice bounds is
7796 -- never an lvalue. The prefix is an lvalue if the indexed component
7797 -- or slice is an lvalue, except if it is an access type, where we
7798 -- have an implicit dereference.
7800 when N_Indexed_Component =>
7802 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
7806 return May_Be_Lvalue (P);
7809 -- Prefix of a reference is an lvalue if the reference is an lvalue
7812 return May_Be_Lvalue (P);
7814 -- Prefix of explicit dereference is never an lvalue
7816 when N_Explicit_Dereference =>
7819 -- Function call arguments are never lvalues
7821 when N_Function_Call =>
7824 -- Positional parameter for procedure, entry, or accept call
7826 when N_Procedure_Call_Statement |
7827 N_Entry_Call_Statement |
7836 Proc := Get_Subprogram_Entity (P);
7842 -- If we are not a list member, something is strange, so
7843 -- be conservative and return True.
7845 if not Is_List_Member (N) then
7849 -- We are going to find the right formal by stepping forward
7850 -- through the formals, as we step backwards in the actuals.
7852 Form := First_Formal (Proc);
7855 -- If no formal, something is weird, so be conservative
7867 return Ekind (Form) /= E_In_Parameter;
7870 -- Named parameter for procedure or accept call
7872 when N_Parameter_Association =>
7878 Proc := Get_Subprogram_Entity (Parent (P));
7884 -- Loop through formals to find the one that matches
7886 Form := First_Formal (Proc);
7888 -- If no matching formal, that's peculiar, some kind of
7889 -- previous error, so return True to be conservative.
7895 -- Else test for match
7897 if Chars (Form) = Chars (Selector_Name (P)) then
7898 return Ekind (Form) /= E_In_Parameter;
7905 -- Test for appearing in a conversion that itself appears in an
7906 -- lvalue context, since this should be an lvalue.
7908 when N_Type_Conversion =>
7909 return May_Be_Lvalue (P);
7911 -- Test for appearance in object renaming declaration
7913 when N_Object_Renaming_Declaration =>
7916 -- All other references are definitely not lvalues
7924 -----------------------
7925 -- Mark_Coextensions --
7926 -----------------------
7928 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
7929 Is_Dynamic : Boolean;
7930 -- Indicates whether the context causes nested coextensions to be
7931 -- dynamic or static
7933 function Mark_Allocator (N : Node_Id) return Traverse_Result;
7934 -- Recognize an allocator node and label it as a dynamic coextension
7936 --------------------
7937 -- Mark_Allocator --
7938 --------------------
7940 function Mark_Allocator (N : Node_Id) return Traverse_Result is
7942 if Nkind (N) = N_Allocator then
7944 Set_Is_Dynamic_Coextension (N);
7946 -- If the allocator expression is potentially dynamic, it may
7947 -- be expanded out of order and require dynamic allocation
7948 -- anyway, so we treat the coextension itself as dynamic.
7949 -- Potential optimization ???
7951 elsif Nkind (Expression (N)) = N_Qualified_Expression
7952 and then Nkind (Expression (Expression (N))) = N_Op_Concat
7954 Set_Is_Dynamic_Coextension (N);
7957 Set_Is_Static_Coextension (N);
7964 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
7966 -- Start of processing Mark_Coextensions
7969 case Nkind (Context_Nod) is
7970 when N_Assignment_Statement |
7971 N_Simple_Return_Statement =>
7972 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
7974 when N_Object_Declaration =>
7975 Is_Dynamic := Nkind (Root_Nod) = N_Allocator;
7977 -- This routine should not be called for constructs which may not
7978 -- contain coextensions.
7981 raise Program_Error;
7984 Mark_Allocators (Root_Nod);
7985 end Mark_Coextensions;
7987 ----------------------
7988 -- Needs_One_Actual --
7989 ----------------------
7991 function Needs_One_Actual (E : Entity_Id) return Boolean is
7995 if Ada_Version >= Ada_05
7996 and then Present (First_Formal (E))
7998 Formal := Next_Formal (First_Formal (E));
7999 while Present (Formal) loop
8000 if No (Default_Value (Formal)) then
8004 Next_Formal (Formal);
8012 end Needs_One_Actual;
8014 ------------------------
8015 -- New_Copy_List_Tree --
8016 ------------------------
8018 function New_Copy_List_Tree (List : List_Id) return List_Id is
8023 if List = No_List then
8030 while Present (E) loop
8031 Append (New_Copy_Tree (E), NL);
8037 end New_Copy_List_Tree;
8043 use Atree.Unchecked_Access;
8044 use Atree_Private_Part;
8046 -- Our approach here requires a two pass traversal of the tree. The
8047 -- first pass visits all nodes that eventually will be copied looking
8048 -- for defining Itypes. If any defining Itypes are found, then they are
8049 -- copied, and an entry is added to the replacement map. In the second
8050 -- phase, the tree is copied, using the replacement map to replace any
8051 -- Itype references within the copied tree.
8053 -- The following hash tables are used if the Map supplied has more
8054 -- than hash threshhold entries to speed up access to the map. If
8055 -- there are fewer entries, then the map is searched sequentially
8056 -- (because setting up a hash table for only a few entries takes
8057 -- more time than it saves.
8059 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
8060 -- Hash function used for hash operations
8066 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
8068 return Nat (E) mod (NCT_Header_Num'Last + 1);
8075 -- The hash table NCT_Assoc associates old entities in the table
8076 -- with their corresponding new entities (i.e. the pairs of entries
8077 -- presented in the original Map argument are Key-Element pairs).
8079 package NCT_Assoc is new Simple_HTable (
8080 Header_Num => NCT_Header_Num,
8081 Element => Entity_Id,
8082 No_Element => Empty,
8084 Hash => New_Copy_Hash,
8085 Equal => Types."=");
8087 ---------------------
8088 -- NCT_Itype_Assoc --
8089 ---------------------
8091 -- The hash table NCT_Itype_Assoc contains entries only for those
8092 -- old nodes which have a non-empty Associated_Node_For_Itype set.
8093 -- The key is the associated node, and the element is the new node
8094 -- itself (NOT the associated node for the new node).
8096 package NCT_Itype_Assoc is new Simple_HTable (
8097 Header_Num => NCT_Header_Num,
8098 Element => Entity_Id,
8099 No_Element => Empty,
8101 Hash => New_Copy_Hash,
8102 Equal => Types."=");
8104 -- Start of processing for New_Copy_Tree function
8106 function New_Copy_Tree
8108 Map : Elist_Id := No_Elist;
8109 New_Sloc : Source_Ptr := No_Location;
8110 New_Scope : Entity_Id := Empty) return Node_Id
8112 Actual_Map : Elist_Id := Map;
8113 -- This is the actual map for the copy. It is initialized with the
8114 -- given elements, and then enlarged as required for Itypes that are
8115 -- copied during the first phase of the copy operation. The visit
8116 -- procedures add elements to this map as Itypes are encountered.
8117 -- The reason we cannot use Map directly, is that it may well be
8118 -- (and normally is) initialized to No_Elist, and if we have mapped
8119 -- entities, we have to reset it to point to a real Elist.
8121 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
8122 -- Called during second phase to map entities into their corresponding
8123 -- copies using Actual_Map. If the argument is not an entity, or is not
8124 -- in Actual_Map, then it is returned unchanged.
8126 procedure Build_NCT_Hash_Tables;
8127 -- Builds hash tables (number of elements >= threshold value)
8129 function Copy_Elist_With_Replacement
8130 (Old_Elist : Elist_Id) return Elist_Id;
8131 -- Called during second phase to copy element list doing replacements
8133 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
8134 -- Called during the second phase to process a copied Itype. The actual
8135 -- copy happened during the first phase (so that we could make the entry
8136 -- in the mapping), but we still have to deal with the descendents of
8137 -- the copied Itype and copy them where necessary.
8139 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
8140 -- Called during second phase to copy list doing replacements
8142 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
8143 -- Called during second phase to copy node doing replacements
8145 procedure Visit_Elist (E : Elist_Id);
8146 -- Called during first phase to visit all elements of an Elist
8148 procedure Visit_Field (F : Union_Id; N : Node_Id);
8149 -- Visit a single field, recursing to call Visit_Node or Visit_List
8150 -- if the field is a syntactic descendent of the current node (i.e.
8151 -- its parent is Node N).
8153 procedure Visit_Itype (Old_Itype : Entity_Id);
8154 -- Called during first phase to visit subsidiary fields of a defining
8155 -- Itype, and also create a copy and make an entry in the replacement
8156 -- map for the new copy.
8158 procedure Visit_List (L : List_Id);
8159 -- Called during first phase to visit all elements of a List
8161 procedure Visit_Node (N : Node_Or_Entity_Id);
8162 -- Called during first phase to visit a node and all its subtrees
8168 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
8173 if not Has_Extension (N) or else No (Actual_Map) then
8176 elsif NCT_Hash_Tables_Used then
8177 Ent := NCT_Assoc.Get (Entity_Id (N));
8179 if Present (Ent) then
8185 -- No hash table used, do serial search
8188 E := First_Elmt (Actual_Map);
8189 while Present (E) loop
8190 if Node (E) = N then
8191 return Node (Next_Elmt (E));
8193 E := Next_Elmt (Next_Elmt (E));
8201 ---------------------------
8202 -- Build_NCT_Hash_Tables --
8203 ---------------------------
8205 procedure Build_NCT_Hash_Tables is
8209 if NCT_Hash_Table_Setup then
8211 NCT_Itype_Assoc.Reset;
8214 Elmt := First_Elmt (Actual_Map);
8215 while Present (Elmt) loop
8218 -- Get new entity, and associate old and new
8221 NCT_Assoc.Set (Ent, Node (Elmt));
8223 if Is_Type (Ent) then
8225 Anode : constant Entity_Id :=
8226 Associated_Node_For_Itype (Ent);
8229 if Present (Anode) then
8231 -- Enter a link between the associated node of the
8232 -- old Itype and the new Itype, for updating later
8233 -- when node is copied.
8235 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
8243 NCT_Hash_Tables_Used := True;
8244 NCT_Hash_Table_Setup := True;
8245 end Build_NCT_Hash_Tables;
8247 ---------------------------------
8248 -- Copy_Elist_With_Replacement --
8249 ---------------------------------
8251 function Copy_Elist_With_Replacement
8252 (Old_Elist : Elist_Id) return Elist_Id
8255 New_Elist : Elist_Id;
8258 if No (Old_Elist) then
8262 New_Elist := New_Elmt_List;
8264 M := First_Elmt (Old_Elist);
8265 while Present (M) loop
8266 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
8272 end Copy_Elist_With_Replacement;
8274 ---------------------------------
8275 -- Copy_Itype_With_Replacement --
8276 ---------------------------------
8278 -- This routine exactly parallels its phase one analog Visit_Itype,
8280 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
8282 -- Translate Next_Entity, Scope and Etype fields, in case they
8283 -- reference entities that have been mapped into copies.
8285 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
8286 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
8288 if Present (New_Scope) then
8289 Set_Scope (New_Itype, New_Scope);
8291 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
8294 -- Copy referenced fields
8296 if Is_Discrete_Type (New_Itype) then
8297 Set_Scalar_Range (New_Itype,
8298 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
8300 elsif Has_Discriminants (Base_Type (New_Itype)) then
8301 Set_Discriminant_Constraint (New_Itype,
8302 Copy_Elist_With_Replacement
8303 (Discriminant_Constraint (New_Itype)));
8305 elsif Is_Array_Type (New_Itype) then
8306 if Present (First_Index (New_Itype)) then
8307 Set_First_Index (New_Itype,
8308 First (Copy_List_With_Replacement
8309 (List_Containing (First_Index (New_Itype)))));
8312 if Is_Packed (New_Itype) then
8313 Set_Packed_Array_Type (New_Itype,
8314 Copy_Node_With_Replacement
8315 (Packed_Array_Type (New_Itype)));
8318 end Copy_Itype_With_Replacement;
8320 --------------------------------
8321 -- Copy_List_With_Replacement --
8322 --------------------------------
8324 function Copy_List_With_Replacement
8325 (Old_List : List_Id) return List_Id
8331 if Old_List = No_List then
8335 New_List := Empty_List;
8337 E := First (Old_List);
8338 while Present (E) loop
8339 Append (Copy_Node_With_Replacement (E), New_List);
8345 end Copy_List_With_Replacement;
8347 --------------------------------
8348 -- Copy_Node_With_Replacement --
8349 --------------------------------
8351 function Copy_Node_With_Replacement
8352 (Old_Node : Node_Id) return Node_Id
8356 procedure Adjust_Named_Associations
8357 (Old_Node : Node_Id;
8358 New_Node : Node_Id);
8359 -- If a call node has named associations, these are chained through
8360 -- the First_Named_Actual, Next_Named_Actual links. These must be
8361 -- propagated separately to the new parameter list, because these
8362 -- are not syntactic fields.
8364 function Copy_Field_With_Replacement
8365 (Field : Union_Id) return Union_Id;
8366 -- Given Field, which is a field of Old_Node, return a copy of it
8367 -- if it is a syntactic field (i.e. its parent is Node), setting
8368 -- the parent of the copy to poit to New_Node. Otherwise returns
8369 -- the field (possibly mapped if it is an entity).
8371 -------------------------------
8372 -- Adjust_Named_Associations --
8373 -------------------------------
8375 procedure Adjust_Named_Associations
8376 (Old_Node : Node_Id;
8386 Old_E := First (Parameter_Associations (Old_Node));
8387 New_E := First (Parameter_Associations (New_Node));
8388 while Present (Old_E) loop
8389 if Nkind (Old_E) = N_Parameter_Association
8390 and then Present (Next_Named_Actual (Old_E))
8392 if First_Named_Actual (Old_Node)
8393 = Explicit_Actual_Parameter (Old_E)
8395 Set_First_Named_Actual
8396 (New_Node, Explicit_Actual_Parameter (New_E));
8399 -- Now scan parameter list from the beginning,to locate
8400 -- next named actual, which can be out of order.
8402 Old_Next := First (Parameter_Associations (Old_Node));
8403 New_Next := First (Parameter_Associations (New_Node));
8405 while Nkind (Old_Next) /= N_Parameter_Association
8406 or else Explicit_Actual_Parameter (Old_Next)
8407 /= Next_Named_Actual (Old_E)
8413 Set_Next_Named_Actual
8414 (New_E, Explicit_Actual_Parameter (New_Next));
8420 end Adjust_Named_Associations;
8422 ---------------------------------
8423 -- Copy_Field_With_Replacement --
8424 ---------------------------------
8426 function Copy_Field_With_Replacement
8427 (Field : Union_Id) return Union_Id
8430 if Field = Union_Id (Empty) then
8433 elsif Field in Node_Range then
8435 Old_N : constant Node_Id := Node_Id (Field);
8439 -- If syntactic field, as indicated by the parent pointer
8440 -- being set, then copy the referenced node recursively.
8442 if Parent (Old_N) = Old_Node then
8443 New_N := Copy_Node_With_Replacement (Old_N);
8445 if New_N /= Old_N then
8446 Set_Parent (New_N, New_Node);
8449 -- For semantic fields, update possible entity reference
8450 -- from the replacement map.
8453 New_N := Assoc (Old_N);
8456 return Union_Id (New_N);
8459 elsif Field in List_Range then
8461 Old_L : constant List_Id := List_Id (Field);
8465 -- If syntactic field, as indicated by the parent pointer,
8466 -- then recursively copy the entire referenced list.
8468 if Parent (Old_L) = Old_Node then
8469 New_L := Copy_List_With_Replacement (Old_L);
8470 Set_Parent (New_L, New_Node);
8472 -- For semantic list, just returned unchanged
8478 return Union_Id (New_L);
8481 -- Anything other than a list or a node is returned unchanged
8486 end Copy_Field_With_Replacement;
8488 -- Start of processing for Copy_Node_With_Replacement
8491 if Old_Node <= Empty_Or_Error then
8494 elsif Has_Extension (Old_Node) then
8495 return Assoc (Old_Node);
8498 New_Node := New_Copy (Old_Node);
8500 -- If the node we are copying is the associated node of a
8501 -- previously copied Itype, then adjust the associated node
8502 -- of the copy of that Itype accordingly.
8504 if Present (Actual_Map) then
8510 -- Case of hash table used
8512 if NCT_Hash_Tables_Used then
8513 Ent := NCT_Itype_Assoc.Get (Old_Node);
8515 if Present (Ent) then
8516 Set_Associated_Node_For_Itype (Ent, New_Node);
8519 -- Case of no hash table used
8522 E := First_Elmt (Actual_Map);
8523 while Present (E) loop
8524 if Is_Itype (Node (E))
8526 Old_Node = Associated_Node_For_Itype (Node (E))
8528 Set_Associated_Node_For_Itype
8529 (Node (Next_Elmt (E)), New_Node);
8532 E := Next_Elmt (Next_Elmt (E));
8538 -- Recursively copy descendents
8541 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
8543 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
8545 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
8547 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
8549 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
8551 -- Adjust Sloc of new node if necessary
8553 if New_Sloc /= No_Location then
8554 Set_Sloc (New_Node, New_Sloc);
8556 -- If we adjust the Sloc, then we are essentially making
8557 -- a completely new node, so the Comes_From_Source flag
8558 -- should be reset to the proper default value.
8560 Nodes.Table (New_Node).Comes_From_Source :=
8561 Default_Node.Comes_From_Source;
8564 -- If the node is call and has named associations,
8565 -- set the corresponding links in the copy.
8567 if (Nkind (Old_Node) = N_Function_Call
8568 or else Nkind (Old_Node) = N_Entry_Call_Statement
8570 Nkind (Old_Node) = N_Procedure_Call_Statement)
8571 and then Present (First_Named_Actual (Old_Node))
8573 Adjust_Named_Associations (Old_Node, New_Node);
8576 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
8577 -- The replacement mechanism applies to entities, and is not used
8578 -- here. Eventually we may need a more general graph-copying
8579 -- routine. For now, do a sequential search to find desired node.
8581 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
8582 and then Present (First_Real_Statement (Old_Node))
8585 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
8589 N1 := First (Statements (Old_Node));
8590 N2 := First (Statements (New_Node));
8592 while N1 /= Old_F loop
8597 Set_First_Real_Statement (New_Node, N2);
8602 -- All done, return copied node
8605 end Copy_Node_With_Replacement;
8611 procedure Visit_Elist (E : Elist_Id) is
8615 Elmt := First_Elmt (E);
8617 while Elmt /= No_Elmt loop
8618 Visit_Node (Node (Elmt));
8628 procedure Visit_Field (F : Union_Id; N : Node_Id) is
8630 if F = Union_Id (Empty) then
8633 elsif F in Node_Range then
8635 -- Copy node if it is syntactic, i.e. its parent pointer is
8636 -- set to point to the field that referenced it (certain
8637 -- Itypes will also meet this criterion, which is fine, since
8638 -- these are clearly Itypes that do need to be copied, since
8639 -- we are copying their parent.)
8641 if Parent (Node_Id (F)) = N then
8642 Visit_Node (Node_Id (F));
8645 -- Another case, if we are pointing to an Itype, then we want
8646 -- to copy it if its associated node is somewhere in the tree
8649 -- Note: the exclusion of self-referential copies is just an
8650 -- optimization, since the search of the already copied list
8651 -- would catch it, but it is a common case (Etype pointing
8652 -- to itself for an Itype that is a base type).
8654 elsif Has_Extension (Node_Id (F))
8655 and then Is_Itype (Entity_Id (F))
8656 and then Node_Id (F) /= N
8662 P := Associated_Node_For_Itype (Node_Id (F));
8663 while Present (P) loop
8665 Visit_Node (Node_Id (F));
8672 -- An Itype whose parent is not being copied definitely
8673 -- should NOT be copied, since it does not belong in any
8674 -- sense to the copied subtree.
8680 elsif F in List_Range
8681 and then Parent (List_Id (F)) = N
8683 Visit_List (List_Id (F));
8692 procedure Visit_Itype (Old_Itype : Entity_Id) is
8693 New_Itype : Entity_Id;
8698 -- Itypes that describe the designated type of access to subprograms
8699 -- have the structure of subprogram declarations, with signatures,
8700 -- etc. Either we duplicate the signatures completely, or choose to
8701 -- share such itypes, which is fine because their elaboration will
8702 -- have no side effects.
8704 if Ekind (Old_Itype) = E_Subprogram_Type then
8708 New_Itype := New_Copy (Old_Itype);
8710 -- The new Itype has all the attributes of the old one, and
8711 -- we just copy the contents of the entity. However, the back-end
8712 -- needs different names for debugging purposes, so we create a
8713 -- new internal name for it in all cases.
8715 Set_Chars (New_Itype, New_Internal_Name ('T'));
8717 -- If our associated node is an entity that has already been copied,
8718 -- then set the associated node of the copy to point to the right
8719 -- copy. If we have copied an Itype that is itself the associated
8720 -- node of some previously copied Itype, then we set the right
8721 -- pointer in the other direction.
8723 if Present (Actual_Map) then
8725 -- Case of hash tables used
8727 if NCT_Hash_Tables_Used then
8729 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
8731 if Present (Ent) then
8732 Set_Associated_Node_For_Itype (New_Itype, Ent);
8735 Ent := NCT_Itype_Assoc.Get (Old_Itype);
8736 if Present (Ent) then
8737 Set_Associated_Node_For_Itype (Ent, New_Itype);
8739 -- If the hash table has no association for this Itype and
8740 -- its associated node, enter one now.
8744 (Associated_Node_For_Itype (Old_Itype), New_Itype);
8747 -- Case of hash tables not used
8750 E := First_Elmt (Actual_Map);
8751 while Present (E) loop
8752 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
8753 Set_Associated_Node_For_Itype
8754 (New_Itype, Node (Next_Elmt (E)));
8757 if Is_Type (Node (E))
8759 Old_Itype = Associated_Node_For_Itype (Node (E))
8761 Set_Associated_Node_For_Itype
8762 (Node (Next_Elmt (E)), New_Itype);
8765 E := Next_Elmt (Next_Elmt (E));
8770 if Present (Freeze_Node (New_Itype)) then
8771 Set_Is_Frozen (New_Itype, False);
8772 Set_Freeze_Node (New_Itype, Empty);
8775 -- Add new association to map
8777 if No (Actual_Map) then
8778 Actual_Map := New_Elmt_List;
8781 Append_Elmt (Old_Itype, Actual_Map);
8782 Append_Elmt (New_Itype, Actual_Map);
8784 if NCT_Hash_Tables_Used then
8785 NCT_Assoc.Set (Old_Itype, New_Itype);
8788 NCT_Table_Entries := NCT_Table_Entries + 1;
8790 if NCT_Table_Entries > NCT_Hash_Threshhold then
8791 Build_NCT_Hash_Tables;
8795 -- If a record subtype is simply copied, the entity list will be
8796 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
8798 if Ekind_In (Old_Itype, E_Record_Subtype, E_Class_Wide_Subtype) then
8799 Set_Cloned_Subtype (New_Itype, Old_Itype);
8802 -- Visit descendents that eventually get copied
8804 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
8806 if Is_Discrete_Type (Old_Itype) then
8807 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
8809 elsif Has_Discriminants (Base_Type (Old_Itype)) then
8810 -- ??? This should involve call to Visit_Field
8811 Visit_Elist (Discriminant_Constraint (Old_Itype));
8813 elsif Is_Array_Type (Old_Itype) then
8814 if Present (First_Index (Old_Itype)) then
8815 Visit_Field (Union_Id (List_Containing
8816 (First_Index (Old_Itype))),
8820 if Is_Packed (Old_Itype) then
8821 Visit_Field (Union_Id (Packed_Array_Type (Old_Itype)),
8831 procedure Visit_List (L : List_Id) is
8834 if L /= No_List then
8837 while Present (N) loop
8848 procedure Visit_Node (N : Node_Or_Entity_Id) is
8850 -- Start of processing for Visit_Node
8853 -- Handle case of an Itype, which must be copied
8855 if Has_Extension (N)
8856 and then Is_Itype (N)
8858 -- Nothing to do if already in the list. This can happen with an
8859 -- Itype entity that appears more than once in the tree.
8860 -- Note that we do not want to visit descendents in this case.
8862 -- Test for already in list when hash table is used
8864 if NCT_Hash_Tables_Used then
8865 if Present (NCT_Assoc.Get (Entity_Id (N))) then
8869 -- Test for already in list when hash table not used
8875 if Present (Actual_Map) then
8876 E := First_Elmt (Actual_Map);
8877 while Present (E) loop
8878 if Node (E) = N then
8881 E := Next_Elmt (Next_Elmt (E));
8891 -- Visit descendents
8893 Visit_Field (Field1 (N), N);
8894 Visit_Field (Field2 (N), N);
8895 Visit_Field (Field3 (N), N);
8896 Visit_Field (Field4 (N), N);
8897 Visit_Field (Field5 (N), N);
8900 -- Start of processing for New_Copy_Tree
8905 -- See if we should use hash table
8907 if No (Actual_Map) then
8908 NCT_Hash_Tables_Used := False;
8915 NCT_Table_Entries := 0;
8917 Elmt := First_Elmt (Actual_Map);
8918 while Present (Elmt) loop
8919 NCT_Table_Entries := NCT_Table_Entries + 1;
8924 if NCT_Table_Entries > NCT_Hash_Threshhold then
8925 Build_NCT_Hash_Tables;
8927 NCT_Hash_Tables_Used := False;
8932 -- Hash table set up if required, now start phase one by visiting
8933 -- top node (we will recursively visit the descendents).
8935 Visit_Node (Source);
8937 -- Now the second phase of the copy can start. First we process
8938 -- all the mapped entities, copying their descendents.
8940 if Present (Actual_Map) then
8943 New_Itype : Entity_Id;
8945 Elmt := First_Elmt (Actual_Map);
8946 while Present (Elmt) loop
8948 New_Itype := Node (Elmt);
8949 Copy_Itype_With_Replacement (New_Itype);
8955 -- Now we can copy the actual tree
8957 return Copy_Node_With_Replacement (Source);
8960 -------------------------
8961 -- New_External_Entity --
8962 -------------------------
8964 function New_External_Entity
8965 (Kind : Entity_Kind;
8966 Scope_Id : Entity_Id;
8967 Sloc_Value : Source_Ptr;
8968 Related_Id : Entity_Id;
8970 Suffix_Index : Nat := 0;
8971 Prefix : Character := ' ') return Entity_Id
8973 N : constant Entity_Id :=
8974 Make_Defining_Identifier (Sloc_Value,
8976 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
8979 Set_Ekind (N, Kind);
8980 Set_Is_Internal (N, True);
8981 Append_Entity (N, Scope_Id);
8982 Set_Public_Status (N);
8984 if Kind in Type_Kind then
8985 Init_Size_Align (N);
8989 end New_External_Entity;
8991 -------------------------
8992 -- New_Internal_Entity --
8993 -------------------------
8995 function New_Internal_Entity
8996 (Kind : Entity_Kind;
8997 Scope_Id : Entity_Id;
8998 Sloc_Value : Source_Ptr;
8999 Id_Char : Character) return Entity_Id
9001 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
9004 Set_Ekind (N, Kind);
9005 Set_Is_Internal (N, True);
9006 Append_Entity (N, Scope_Id);
9008 if Kind in Type_Kind then
9009 Init_Size_Align (N);
9013 end New_Internal_Entity;
9019 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
9023 -- If we are pointing at a positional parameter, it is a member of a
9024 -- node list (the list of parameters), and the next parameter is the
9025 -- next node on the list, unless we hit a parameter association, then
9026 -- we shift to using the chain whose head is the First_Named_Actual in
9027 -- the parent, and then is threaded using the Next_Named_Actual of the
9028 -- Parameter_Association. All this fiddling is because the original node
9029 -- list is in the textual call order, and what we need is the
9030 -- declaration order.
9032 if Is_List_Member (Actual_Id) then
9033 N := Next (Actual_Id);
9035 if Nkind (N) = N_Parameter_Association then
9036 return First_Named_Actual (Parent (Actual_Id));
9042 return Next_Named_Actual (Parent (Actual_Id));
9046 procedure Next_Actual (Actual_Id : in out Node_Id) is
9048 Actual_Id := Next_Actual (Actual_Id);
9051 -----------------------
9052 -- Normalize_Actuals --
9053 -----------------------
9055 -- Chain actuals according to formals of subprogram. If there are no named
9056 -- associations, the chain is simply the list of Parameter Associations,
9057 -- since the order is the same as the declaration order. If there are named
9058 -- associations, then the First_Named_Actual field in the N_Function_Call
9059 -- or N_Procedure_Call_Statement node points to the Parameter_Association
9060 -- node for the parameter that comes first in declaration order. The
9061 -- remaining named parameters are then chained in declaration order using
9062 -- Next_Named_Actual.
9064 -- This routine also verifies that the number of actuals is compatible with
9065 -- the number and default values of formals, but performs no type checking
9066 -- (type checking is done by the caller).
9068 -- If the matching succeeds, Success is set to True and the caller proceeds
9069 -- with type-checking. If the match is unsuccessful, then Success is set to
9070 -- False, and the caller attempts a different interpretation, if there is
9073 -- If the flag Report is on, the call is not overloaded, and a failure to
9074 -- match can be reported here, rather than in the caller.
9076 procedure Normalize_Actuals
9080 Success : out Boolean)
9082 Actuals : constant List_Id := Parameter_Associations (N);
9083 Actual : Node_Id := Empty;
9085 Last : Node_Id := Empty;
9086 First_Named : Node_Id := Empty;
9089 Formals_To_Match : Integer := 0;
9090 Actuals_To_Match : Integer := 0;
9092 procedure Chain (A : Node_Id);
9093 -- Add named actual at the proper place in the list, using the
9094 -- Next_Named_Actual link.
9096 function Reporting return Boolean;
9097 -- Determines if an error is to be reported. To report an error, we
9098 -- need Report to be True, and also we do not report errors caused
9099 -- by calls to init procs that occur within other init procs. Such
9100 -- errors must always be cascaded errors, since if all the types are
9101 -- declared correctly, the compiler will certainly build decent calls!
9107 procedure Chain (A : Node_Id) is
9111 -- Call node points to first actual in list
9113 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
9116 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
9120 Set_Next_Named_Actual (Last, Empty);
9127 function Reporting return Boolean is
9132 elsif not Within_Init_Proc then
9135 elsif Is_Init_Proc (Entity (Name (N))) then
9143 -- Start of processing for Normalize_Actuals
9146 if Is_Access_Type (S) then
9148 -- The name in the call is a function call that returns an access
9149 -- to subprogram. The designated type has the list of formals.
9151 Formal := First_Formal (Designated_Type (S));
9153 Formal := First_Formal (S);
9156 while Present (Formal) loop
9157 Formals_To_Match := Formals_To_Match + 1;
9158 Next_Formal (Formal);
9161 -- Find if there is a named association, and verify that no positional
9162 -- associations appear after named ones.
9164 if Present (Actuals) then
9165 Actual := First (Actuals);
9168 while Present (Actual)
9169 and then Nkind (Actual) /= N_Parameter_Association
9171 Actuals_To_Match := Actuals_To_Match + 1;
9175 if No (Actual) and Actuals_To_Match = Formals_To_Match then
9177 -- Most common case: positional notation, no defaults
9182 elsif Actuals_To_Match > Formals_To_Match then
9184 -- Too many actuals: will not work
9187 if Is_Entity_Name (Name (N)) then
9188 Error_Msg_N ("too many arguments in call to&", Name (N));
9190 Error_Msg_N ("too many arguments in call", N);
9198 First_Named := Actual;
9200 while Present (Actual) loop
9201 if Nkind (Actual) /= N_Parameter_Association then
9203 ("positional parameters not allowed after named ones", Actual);
9208 Actuals_To_Match := Actuals_To_Match + 1;
9214 if Present (Actuals) then
9215 Actual := First (Actuals);
9218 Formal := First_Formal (S);
9219 while Present (Formal) loop
9221 -- Match the formals in order. If the corresponding actual is
9222 -- positional, nothing to do. Else scan the list of named actuals
9223 -- to find the one with the right name.
9226 and then Nkind (Actual) /= N_Parameter_Association
9229 Actuals_To_Match := Actuals_To_Match - 1;
9230 Formals_To_Match := Formals_To_Match - 1;
9233 -- For named parameters, search the list of actuals to find
9234 -- one that matches the next formal name.
9236 Actual := First_Named;
9238 while Present (Actual) loop
9239 if Chars (Selector_Name (Actual)) = Chars (Formal) then
9242 Actuals_To_Match := Actuals_To_Match - 1;
9243 Formals_To_Match := Formals_To_Match - 1;
9251 if Ekind (Formal) /= E_In_Parameter
9252 or else No (Default_Value (Formal))
9255 if (Comes_From_Source (S)
9256 or else Sloc (S) = Standard_Location)
9257 and then Is_Overloadable (S)
9261 (Nkind (Parent (N)) = N_Procedure_Call_Statement
9263 (Nkind (Parent (N)) = N_Function_Call
9265 Nkind (Parent (N)) = N_Parameter_Association))
9266 and then Ekind (S) /= E_Function
9268 Set_Etype (N, Etype (S));
9270 Error_Msg_Name_1 := Chars (S);
9271 Error_Msg_Sloc := Sloc (S);
9273 ("missing argument for parameter & " &
9274 "in call to % declared #", N, Formal);
9277 elsif Is_Overloadable (S) then
9278 Error_Msg_Name_1 := Chars (S);
9280 -- Point to type derivation that generated the
9283 Error_Msg_Sloc := Sloc (Parent (S));
9286 ("missing argument for parameter & " &
9287 "in call to % (inherited) #", N, Formal);
9291 ("missing argument for parameter &", N, Formal);
9299 Formals_To_Match := Formals_To_Match - 1;
9304 Next_Formal (Formal);
9307 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
9314 -- Find some superfluous named actual that did not get
9315 -- attached to the list of associations.
9317 Actual := First (Actuals);
9318 while Present (Actual) loop
9319 if Nkind (Actual) = N_Parameter_Association
9320 and then Actual /= Last
9321 and then No (Next_Named_Actual (Actual))
9323 Error_Msg_N ("unmatched actual & in call",
9324 Selector_Name (Actual));
9335 end Normalize_Actuals;
9337 --------------------------------
9338 -- Note_Possible_Modification --
9339 --------------------------------
9341 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
9342 Modification_Comes_From_Source : constant Boolean :=
9343 Comes_From_Source (Parent (N));
9349 -- Loop to find referenced entity, if there is one
9356 if Is_Entity_Name (Exp) then
9357 Ent := Entity (Exp);
9359 -- If the entity is missing, it is an undeclared identifier,
9360 -- and there is nothing to annotate.
9366 elsif Nkind (Exp) = N_Explicit_Dereference then
9368 P : constant Node_Id := Prefix (Exp);
9371 if Nkind (P) = N_Selected_Component
9373 Entry_Formal (Entity (Selector_Name (P))))
9375 -- Case of a reference to an entry formal
9377 Ent := Entry_Formal (Entity (Selector_Name (P)));
9379 elsif Nkind (P) = N_Identifier
9380 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
9381 and then Present (Expression (Parent (Entity (P))))
9382 and then Nkind (Expression (Parent (Entity (P))))
9385 -- Case of a reference to a value on which side effects have
9388 Exp := Prefix (Expression (Parent (Entity (P))));
9397 elsif Nkind (Exp) = N_Type_Conversion
9398 or else Nkind (Exp) = N_Unchecked_Type_Conversion
9400 Exp := Expression (Exp);
9403 elsif Nkind (Exp) = N_Slice
9404 or else Nkind (Exp) = N_Indexed_Component
9405 or else Nkind (Exp) = N_Selected_Component
9407 Exp := Prefix (Exp);
9414 -- Now look for entity being referenced
9416 if Present (Ent) then
9417 if Is_Object (Ent) then
9418 if Comes_From_Source (Exp)
9419 or else Modification_Comes_From_Source
9421 if Has_Pragma_Unmodified (Ent) then
9422 Error_Msg_NE ("?pragma Unmodified given for &!", N, Ent);
9425 Set_Never_Set_In_Source (Ent, False);
9428 Set_Is_True_Constant (Ent, False);
9429 Set_Current_Value (Ent, Empty);
9430 Set_Is_Known_Null (Ent, False);
9432 if not Can_Never_Be_Null (Ent) then
9433 Set_Is_Known_Non_Null (Ent, False);
9436 -- Follow renaming chain
9438 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
9439 and then Present (Renamed_Object (Ent))
9441 Exp := Renamed_Object (Ent);
9445 -- Generate a reference only if the assignment comes from
9446 -- source. This excludes, for example, calls to a dispatching
9447 -- assignment operation when the left-hand side is tagged.
9449 if Modification_Comes_From_Source then
9450 Generate_Reference (Ent, Exp, 'm');
9453 Check_Nested_Access (Ent);
9458 -- If we are sure this is a modification from source, and we know
9459 -- this modifies a constant, then give an appropriate warning.
9461 if Overlays_Constant (Ent)
9462 and then Modification_Comes_From_Source
9466 A : constant Node_Id := Address_Clause (Ent);
9470 Exp : constant Node_Id := Expression (A);
9472 if Nkind (Exp) = N_Attribute_Reference
9473 and then Attribute_Name (Exp) = Name_Address
9474 and then Is_Entity_Name (Prefix (Exp))
9476 Error_Msg_Sloc := Sloc (A);
9478 ("constant& may be modified via address clause#?",
9479 N, Entity (Prefix (Exp)));
9489 end Note_Possible_Modification;
9491 -------------------------
9492 -- Object_Access_Level --
9493 -------------------------
9495 function Object_Access_Level (Obj : Node_Id) return Uint is
9498 -- Returns the static accessibility level of the view denoted by Obj. Note
9499 -- that the value returned is the result of a call to Scope_Depth. Only
9500 -- scope depths associated with dynamic scopes can actually be returned.
9501 -- Since only relative levels matter for accessibility checking, the fact
9502 -- that the distance between successive levels of accessibility is not
9503 -- always one is immaterial (invariant: if level(E2) is deeper than
9504 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
9506 function Reference_To (Obj : Node_Id) return Node_Id;
9507 -- An explicit dereference is created when removing side-effects from
9508 -- expressions for constraint checking purposes. In this case a local
9509 -- access type is created for it. The correct access level is that of
9510 -- the original source node. We detect this case by noting that the
9511 -- prefix of the dereference is created by an object declaration whose
9512 -- initial expression is a reference.
9518 function Reference_To (Obj : Node_Id) return Node_Id is
9519 Pref : constant Node_Id := Prefix (Obj);
9521 if Is_Entity_Name (Pref)
9522 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
9523 and then Present (Expression (Parent (Entity (Pref))))
9524 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
9526 return (Prefix (Expression (Parent (Entity (Pref)))));
9532 -- Start of processing for Object_Access_Level
9535 if Is_Entity_Name (Obj) then
9538 if Is_Prival (E) then
9539 E := Prival_Link (E);
9542 -- If E is a type then it denotes a current instance. For this case
9543 -- we add one to the normal accessibility level of the type to ensure
9544 -- that current instances are treated as always being deeper than
9545 -- than the level of any visible named access type (see 3.10.2(21)).
9548 return Type_Access_Level (E) + 1;
9550 elsif Present (Renamed_Object (E)) then
9551 return Object_Access_Level (Renamed_Object (E));
9553 -- Similarly, if E is a component of the current instance of a
9554 -- protected type, any instance of it is assumed to be at a deeper
9555 -- level than the type. For a protected object (whose type is an
9556 -- anonymous protected type) its components are at the same level
9557 -- as the type itself.
9559 elsif not Is_Overloadable (E)
9560 and then Ekind (Scope (E)) = E_Protected_Type
9561 and then Comes_From_Source (Scope (E))
9563 return Type_Access_Level (Scope (E)) + 1;
9566 return Scope_Depth (Enclosing_Dynamic_Scope (E));
9569 elsif Nkind (Obj) = N_Selected_Component then
9570 if Is_Access_Type (Etype (Prefix (Obj))) then
9571 return Type_Access_Level (Etype (Prefix (Obj)));
9573 return Object_Access_Level (Prefix (Obj));
9576 elsif Nkind (Obj) = N_Indexed_Component then
9577 if Is_Access_Type (Etype (Prefix (Obj))) then
9578 return Type_Access_Level (Etype (Prefix (Obj)));
9580 return Object_Access_Level (Prefix (Obj));
9583 elsif Nkind (Obj) = N_Explicit_Dereference then
9585 -- If the prefix is a selected access discriminant then we make a
9586 -- recursive call on the prefix, which will in turn check the level
9587 -- of the prefix object of the selected discriminant.
9589 if Nkind (Prefix (Obj)) = N_Selected_Component
9590 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
9592 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
9594 return Object_Access_Level (Prefix (Obj));
9596 elsif not (Comes_From_Source (Obj)) then
9598 Ref : constant Node_Id := Reference_To (Obj);
9600 if Present (Ref) then
9601 return Object_Access_Level (Ref);
9603 return Type_Access_Level (Etype (Prefix (Obj)));
9608 return Type_Access_Level (Etype (Prefix (Obj)));
9611 elsif Nkind (Obj) = N_Type_Conversion
9612 or else Nkind (Obj) = N_Unchecked_Type_Conversion
9614 return Object_Access_Level (Expression (Obj));
9616 elsif Nkind (Obj) = N_Function_Call then
9618 -- Function results are objects, so we get either the access level of
9619 -- the function or, in the case of an indirect call, the level of the
9620 -- access-to-subprogram type. (This code is used for Ada 95, but it
9621 -- looks wrong, because it seems that we should be checking the level
9622 -- of the call itself, even for Ada 95. However, using the Ada 2005
9623 -- version of the code causes regressions in several tests that are
9624 -- compiled with -gnat95. ???)
9626 if Ada_Version < Ada_05 then
9627 if Is_Entity_Name (Name (Obj)) then
9628 return Subprogram_Access_Level (Entity (Name (Obj)));
9630 return Type_Access_Level (Etype (Prefix (Name (Obj))));
9633 -- For Ada 2005, the level of the result object of a function call is
9634 -- defined to be the level of the call's innermost enclosing master.
9635 -- We determine that by querying the depth of the innermost enclosing
9639 Return_Master_Scope_Depth_Of_Call : declare
9641 function Innermost_Master_Scope_Depth
9642 (N : Node_Id) return Uint;
9643 -- Returns the scope depth of the given node's innermost
9644 -- enclosing dynamic scope (effectively the accessibility
9645 -- level of the innermost enclosing master).
9647 ----------------------------------
9648 -- Innermost_Master_Scope_Depth --
9649 ----------------------------------
9651 function Innermost_Master_Scope_Depth
9652 (N : Node_Id) return Uint
9654 Node_Par : Node_Id := Parent (N);
9657 -- Locate the nearest enclosing node (by traversing Parents)
9658 -- that Defining_Entity can be applied to, and return the
9659 -- depth of that entity's nearest enclosing dynamic scope.
9661 while Present (Node_Par) loop
9662 case Nkind (Node_Par) is
9663 when N_Component_Declaration |
9664 N_Entry_Declaration |
9665 N_Formal_Object_Declaration |
9666 N_Formal_Type_Declaration |
9667 N_Full_Type_Declaration |
9668 N_Incomplete_Type_Declaration |
9669 N_Loop_Parameter_Specification |
9670 N_Object_Declaration |
9671 N_Protected_Type_Declaration |
9672 N_Private_Extension_Declaration |
9673 N_Private_Type_Declaration |
9674 N_Subtype_Declaration |
9675 N_Function_Specification |
9676 N_Procedure_Specification |
9677 N_Task_Type_Declaration |
9679 N_Generic_Instantiation |
9681 N_Implicit_Label_Declaration |
9682 N_Package_Declaration |
9683 N_Single_Task_Declaration |
9684 N_Subprogram_Declaration |
9685 N_Generic_Declaration |
9686 N_Renaming_Declaration |
9688 N_Formal_Subprogram_Declaration |
9689 N_Abstract_Subprogram_Declaration |
9691 N_Exception_Declaration |
9692 N_Formal_Package_Declaration |
9693 N_Number_Declaration |
9694 N_Package_Specification |
9695 N_Parameter_Specification |
9696 N_Single_Protected_Declaration |
9700 (Nearest_Dynamic_Scope
9701 (Defining_Entity (Node_Par)));
9707 Node_Par := Parent (Node_Par);
9710 pragma Assert (False);
9712 -- Should never reach the following return
9714 return Scope_Depth (Current_Scope) + 1;
9715 end Innermost_Master_Scope_Depth;
9717 -- Start of processing for Return_Master_Scope_Depth_Of_Call
9720 return Innermost_Master_Scope_Depth (Obj);
9721 end Return_Master_Scope_Depth_Of_Call;
9724 -- For convenience we handle qualified expressions, even though
9725 -- they aren't technically object names.
9727 elsif Nkind (Obj) = N_Qualified_Expression then
9728 return Object_Access_Level (Expression (Obj));
9730 -- Otherwise return the scope level of Standard.
9731 -- (If there are cases that fall through
9732 -- to this point they will be treated as
9733 -- having global accessibility for now. ???)
9736 return Scope_Depth (Standard_Standard);
9738 end Object_Access_Level;
9740 -----------------------
9741 -- Private_Component --
9742 -----------------------
9744 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
9745 Ancestor : constant Entity_Id := Base_Type (Type_Id);
9747 function Trace_Components
9749 Check : Boolean) return Entity_Id;
9750 -- Recursive function that does the work, and checks against circular
9751 -- definition for each subcomponent type.
9753 ----------------------
9754 -- Trace_Components --
9755 ----------------------
9757 function Trace_Components
9759 Check : Boolean) return Entity_Id
9761 Btype : constant Entity_Id := Base_Type (T);
9762 Component : Entity_Id;
9764 Candidate : Entity_Id := Empty;
9767 if Check and then Btype = Ancestor then
9768 Error_Msg_N ("circular type definition", Type_Id);
9772 if Is_Private_Type (Btype)
9773 and then not Is_Generic_Type (Btype)
9775 if Present (Full_View (Btype))
9776 and then Is_Record_Type (Full_View (Btype))
9777 and then not Is_Frozen (Btype)
9779 -- To indicate that the ancestor depends on a private type, the
9780 -- current Btype is sufficient. However, to check for circular
9781 -- definition we must recurse on the full view.
9783 Candidate := Trace_Components (Full_View (Btype), True);
9785 if Candidate = Any_Type then
9795 elsif Is_Array_Type (Btype) then
9796 return Trace_Components (Component_Type (Btype), True);
9798 elsif Is_Record_Type (Btype) then
9799 Component := First_Entity (Btype);
9800 while Present (Component) loop
9802 -- Skip anonymous types generated by constrained components
9804 if not Is_Type (Component) then
9805 P := Trace_Components (Etype (Component), True);
9808 if P = Any_Type then
9816 Next_Entity (Component);
9824 end Trace_Components;
9826 -- Start of processing for Private_Component
9829 return Trace_Components (Type_Id, False);
9830 end Private_Component;
9832 ---------------------------
9833 -- Primitive_Names_Match --
9834 ---------------------------
9836 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
9838 function Non_Internal_Name (E : Entity_Id) return Name_Id;
9839 -- Given an internal name, returns the corresponding non-internal name
9841 ------------------------
9842 -- Non_Internal_Name --
9843 ------------------------
9845 function Non_Internal_Name (E : Entity_Id) return Name_Id is
9847 Get_Name_String (Chars (E));
9848 Name_Len := Name_Len - 1;
9850 end Non_Internal_Name;
9852 -- Start of processing for Primitive_Names_Match
9855 pragma Assert (Present (E1) and then Present (E2));
9857 return Chars (E1) = Chars (E2)
9859 (not Is_Internal_Name (Chars (E1))
9860 and then Is_Internal_Name (Chars (E2))
9861 and then Non_Internal_Name (E2) = Chars (E1))
9863 (not Is_Internal_Name (Chars (E2))
9864 and then Is_Internal_Name (Chars (E1))
9865 and then Non_Internal_Name (E1) = Chars (E2))
9867 (Is_Predefined_Dispatching_Operation (E1)
9868 and then Is_Predefined_Dispatching_Operation (E2)
9869 and then Same_TSS (E1, E2))
9871 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
9872 end Primitive_Names_Match;
9874 -----------------------
9875 -- Process_End_Label --
9876 -----------------------
9878 procedure Process_End_Label
9887 Label_Ref : Boolean;
9888 -- Set True if reference to end label itself is required
9891 -- Gets set to the operator symbol or identifier that references the
9892 -- entity Ent. For the child unit case, this is the identifier from the
9893 -- designator. For other cases, this is simply Endl.
9895 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
9896 -- N is an identifier node that appears as a parent unit reference in
9897 -- the case where Ent is a child unit. This procedure generates an
9898 -- appropriate cross-reference entry. E is the corresponding entity.
9900 -------------------------
9901 -- Generate_Parent_Ref --
9902 -------------------------
9904 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
9906 -- If names do not match, something weird, skip reference
9908 if Chars (E) = Chars (N) then
9910 -- Generate the reference. We do NOT consider this as a reference
9911 -- for unreferenced symbol purposes.
9913 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
9916 Style.Check_Identifier (N, E);
9919 end Generate_Parent_Ref;
9921 -- Start of processing for Process_End_Label
9924 -- If no node, ignore. This happens in some error situations, and
9925 -- also for some internally generated structures where no end label
9926 -- references are required in any case.
9932 -- Nothing to do if no End_Label, happens for internally generated
9933 -- constructs where we don't want an end label reference anyway. Also
9934 -- nothing to do if Endl is a string literal, which means there was
9935 -- some prior error (bad operator symbol)
9937 Endl := End_Label (N);
9939 if No (Endl) or else Nkind (Endl) = N_String_Literal then
9943 -- Reference node is not in extended main source unit
9945 if not In_Extended_Main_Source_Unit (N) then
9947 -- Generally we do not collect references except for the extended
9948 -- main source unit. The one exception is the 'e' entry for a
9949 -- package spec, where it is useful for a client to have the
9950 -- ending information to define scopes.
9958 -- For this case, we can ignore any parent references, but we
9959 -- need the package name itself for the 'e' entry.
9961 if Nkind (Endl) = N_Designator then
9962 Endl := Identifier (Endl);
9966 -- Reference is in extended main source unit
9971 -- For designator, generate references for the parent entries
9973 if Nkind (Endl) = N_Designator then
9975 -- Generate references for the prefix if the END line comes from
9976 -- source (otherwise we do not need these references) We climb the
9977 -- scope stack to find the expected entities.
9979 if Comes_From_Source (Endl) then
9981 Scop := Current_Scope;
9982 while Nkind (Nam) = N_Selected_Component loop
9983 Scop := Scope (Scop);
9984 exit when No (Scop);
9985 Generate_Parent_Ref (Selector_Name (Nam), Scop);
9986 Nam := Prefix (Nam);
9989 if Present (Scop) then
9990 Generate_Parent_Ref (Nam, Scope (Scop));
9994 Endl := Identifier (Endl);
9998 -- If the end label is not for the given entity, then either we have
9999 -- some previous error, or this is a generic instantiation for which
10000 -- we do not need to make a cross-reference in this case anyway. In
10001 -- either case we simply ignore the call.
10003 if Chars (Ent) /= Chars (Endl) then
10007 -- If label was really there, then generate a normal reference and then
10008 -- adjust the location in the end label to point past the name (which
10009 -- should almost always be the semicolon).
10011 Loc := Sloc (Endl);
10013 if Comes_From_Source (Endl) then
10015 -- If a label reference is required, then do the style check and
10016 -- generate an l-type cross-reference entry for the label
10019 if Style_Check then
10020 Style.Check_Identifier (Endl, Ent);
10023 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
10026 -- Set the location to point past the label (normally this will
10027 -- mean the semicolon immediately following the label). This is
10028 -- done for the sake of the 'e' or 't' entry generated below.
10030 Get_Decoded_Name_String (Chars (Endl));
10031 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
10034 -- Now generate the e/t reference
10036 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
10038 -- Restore Sloc, in case modified above, since we have an identifier
10039 -- and the normal Sloc should be left set in the tree.
10041 Set_Sloc (Endl, Loc);
10042 end Process_End_Label;
10048 -- We do the conversion to get the value of the real string by using
10049 -- the scanner, see Sinput for details on use of the internal source
10050 -- buffer for scanning internal strings.
10052 function Real_Convert (S : String) return Node_Id is
10053 Save_Src : constant Source_Buffer_Ptr := Source;
10054 Negative : Boolean;
10057 Source := Internal_Source_Ptr;
10060 for J in S'Range loop
10061 Source (Source_Ptr (J)) := S (J);
10064 Source (S'Length + 1) := EOF;
10066 if Source (Scan_Ptr) = '-' then
10068 Scan_Ptr := Scan_Ptr + 1;
10076 Set_Realval (Token_Node, UR_Negate (Realval (Token_Node)));
10079 Source := Save_Src;
10083 ------------------------------------
10084 -- References_Generic_Formal_Type --
10085 ------------------------------------
10087 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
10089 function Process (N : Node_Id) return Traverse_Result;
10090 -- Process one node in search for generic formal type
10096 function Process (N : Node_Id) return Traverse_Result is
10098 if Nkind (N) in N_Has_Entity then
10100 E : constant Entity_Id := Entity (N);
10102 if Present (E) then
10103 if Is_Generic_Type (E) then
10105 elsif Present (Etype (E))
10106 and then Is_Generic_Type (Etype (E))
10117 function Traverse is new Traverse_Func (Process);
10118 -- Traverse tree to look for generic type
10121 if Inside_A_Generic then
10122 return Traverse (N) = Abandon;
10126 end References_Generic_Formal_Type;
10128 --------------------
10129 -- Remove_Homonym --
10130 --------------------
10132 procedure Remove_Homonym (E : Entity_Id) is
10133 Prev : Entity_Id := Empty;
10137 if E = Current_Entity (E) then
10138 if Present (Homonym (E)) then
10139 Set_Current_Entity (Homonym (E));
10141 Set_Name_Entity_Id (Chars (E), Empty);
10144 H := Current_Entity (E);
10145 while Present (H) and then H /= E loop
10150 Set_Homonym (Prev, Homonym (E));
10152 end Remove_Homonym;
10154 ---------------------
10155 -- Rep_To_Pos_Flag --
10156 ---------------------
10158 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
10160 return New_Occurrence_Of
10161 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
10162 end Rep_To_Pos_Flag;
10164 --------------------
10165 -- Require_Entity --
10166 --------------------
10168 procedure Require_Entity (N : Node_Id) is
10170 if Is_Entity_Name (N) and then No (Entity (N)) then
10171 if Total_Errors_Detected /= 0 then
10172 Set_Entity (N, Any_Id);
10174 raise Program_Error;
10177 end Require_Entity;
10179 ------------------------------
10180 -- Requires_Transient_Scope --
10181 ------------------------------
10183 -- A transient scope is required when variable-sized temporaries are
10184 -- allocated in the primary or secondary stack, or when finalization
10185 -- actions must be generated before the next instruction.
10187 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
10188 Typ : constant Entity_Id := Underlying_Type (Id);
10190 -- Start of processing for Requires_Transient_Scope
10193 -- This is a private type which is not completed yet. This can only
10194 -- happen in a default expression (of a formal parameter or of a
10195 -- record component). Do not expand transient scope in this case
10200 -- Do not expand transient scope for non-existent procedure return
10202 elsif Typ = Standard_Void_Type then
10205 -- Elementary types do not require a transient scope
10207 elsif Is_Elementary_Type (Typ) then
10210 -- Generally, indefinite subtypes require a transient scope, since the
10211 -- back end cannot generate temporaries, since this is not a valid type
10212 -- for declaring an object. It might be possible to relax this in the
10213 -- future, e.g. by declaring the maximum possible space for the type.
10215 elsif Is_Indefinite_Subtype (Typ) then
10218 -- Functions returning tagged types may dispatch on result so their
10219 -- returned value is allocated on the secondary stack. Controlled
10220 -- type temporaries need finalization.
10222 elsif Is_Tagged_Type (Typ)
10223 or else Has_Controlled_Component (Typ)
10225 return not Is_Value_Type (Typ);
10229 elsif Is_Record_Type (Typ) then
10233 Comp := First_Entity (Typ);
10234 while Present (Comp) loop
10235 if Ekind (Comp) = E_Component
10236 and then Requires_Transient_Scope (Etype (Comp))
10240 Next_Entity (Comp);
10247 -- String literal types never require transient scope
10249 elsif Ekind (Typ) = E_String_Literal_Subtype then
10252 -- Array type. Note that we already know that this is a constrained
10253 -- array, since unconstrained arrays will fail the indefinite test.
10255 elsif Is_Array_Type (Typ) then
10257 -- If component type requires a transient scope, the array does too
10259 if Requires_Transient_Scope (Component_Type (Typ)) then
10262 -- Otherwise, we only need a transient scope if the size is not
10263 -- known at compile time.
10266 return not Size_Known_At_Compile_Time (Typ);
10269 -- All other cases do not require a transient scope
10274 end Requires_Transient_Scope;
10276 --------------------------
10277 -- Reset_Analyzed_Flags --
10278 --------------------------
10280 procedure Reset_Analyzed_Flags (N : Node_Id) is
10282 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
10283 -- Function used to reset Analyzed flags in tree. Note that we do
10284 -- not reset Analyzed flags in entities, since there is no need to
10285 -- reanalyze entities, and indeed, it is wrong to do so, since it
10286 -- can result in generating auxiliary stuff more than once.
10288 --------------------
10289 -- Clear_Analyzed --
10290 --------------------
10292 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
10294 if not Has_Extension (N) then
10295 Set_Analyzed (N, False);
10299 end Clear_Analyzed;
10301 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
10303 -- Start of processing for Reset_Analyzed_Flags
10306 Reset_Analyzed (N);
10307 end Reset_Analyzed_Flags;
10309 ---------------------------
10310 -- Safe_To_Capture_Value --
10311 ---------------------------
10313 function Safe_To_Capture_Value
10316 Cond : Boolean := False) return Boolean
10319 -- The only entities for which we track constant values are variables
10320 -- which are not renamings, constants, out parameters, and in out
10321 -- parameters, so check if we have this case.
10323 -- Note: it may seem odd to track constant values for constants, but in
10324 -- fact this routine is used for other purposes than simply capturing
10325 -- the value. In particular, the setting of Known[_Non]_Null.
10327 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
10329 Ekind (Ent) = E_Constant
10331 Ekind (Ent) = E_Out_Parameter
10333 Ekind (Ent) = E_In_Out_Parameter
10337 -- For conditionals, we also allow loop parameters and all formals,
10338 -- including in parameters.
10342 (Ekind (Ent) = E_Loop_Parameter
10344 Ekind (Ent) = E_In_Parameter)
10348 -- For all other cases, not just unsafe, but impossible to capture
10349 -- Current_Value, since the above are the only entities which have
10350 -- Current_Value fields.
10356 -- Skip if volatile or aliased, since funny things might be going on in
10357 -- these cases which we cannot necessarily track. Also skip any variable
10358 -- for which an address clause is given, or whose address is taken. Also
10359 -- never capture value of library level variables (an attempt to do so
10360 -- can occur in the case of package elaboration code).
10362 if Treat_As_Volatile (Ent)
10363 or else Is_Aliased (Ent)
10364 or else Present (Address_Clause (Ent))
10365 or else Address_Taken (Ent)
10366 or else (Is_Library_Level_Entity (Ent)
10367 and then Ekind (Ent) = E_Variable)
10372 -- OK, all above conditions are met. We also require that the scope of
10373 -- the reference be the same as the scope of the entity, not counting
10374 -- packages and blocks and loops.
10377 E_Scope : constant Entity_Id := Scope (Ent);
10378 R_Scope : Entity_Id;
10381 R_Scope := Current_Scope;
10382 while R_Scope /= Standard_Standard loop
10383 exit when R_Scope = E_Scope;
10385 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
10388 R_Scope := Scope (R_Scope);
10393 -- We also require that the reference does not appear in a context
10394 -- where it is not sure to be executed (i.e. a conditional context
10395 -- or an exception handler). We skip this if Cond is True, since the
10396 -- capturing of values from conditional tests handles this ok.
10410 while Present (P) loop
10411 if Nkind (P) = N_If_Statement
10412 or else Nkind (P) = N_Case_Statement
10413 or else (Nkind (P) in N_Short_Circuit
10414 and then Desc = Right_Opnd (P))
10415 or else (Nkind (P) = N_Conditional_Expression
10416 and then Desc /= First (Expressions (P)))
10417 or else Nkind (P) = N_Exception_Handler
10418 or else Nkind (P) = N_Selective_Accept
10419 or else Nkind (P) = N_Conditional_Entry_Call
10420 or else Nkind (P) = N_Timed_Entry_Call
10421 or else Nkind (P) = N_Asynchronous_Select
10431 -- OK, looks safe to set value
10434 end Safe_To_Capture_Value;
10440 function Same_Name (N1, N2 : Node_Id) return Boolean is
10441 K1 : constant Node_Kind := Nkind (N1);
10442 K2 : constant Node_Kind := Nkind (N2);
10445 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
10446 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
10448 return Chars (N1) = Chars (N2);
10450 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
10451 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
10453 return Same_Name (Selector_Name (N1), Selector_Name (N2))
10454 and then Same_Name (Prefix (N1), Prefix (N2));
10465 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
10466 N1 : constant Node_Id := Original_Node (Node1);
10467 N2 : constant Node_Id := Original_Node (Node2);
10468 -- We do the tests on original nodes, since we are most interested
10469 -- in the original source, not any expansion that got in the way.
10471 K1 : constant Node_Kind := Nkind (N1);
10472 K2 : constant Node_Kind := Nkind (N2);
10475 -- First case, both are entities with same entity
10477 if K1 in N_Has_Entity
10478 and then K2 in N_Has_Entity
10479 and then Present (Entity (N1))
10480 and then Present (Entity (N2))
10481 and then (Ekind (Entity (N1)) = E_Variable
10483 Ekind (Entity (N1)) = E_Constant)
10484 and then Entity (N1) = Entity (N2)
10488 -- Second case, selected component with same selector, same record
10490 elsif K1 = N_Selected_Component
10491 and then K2 = N_Selected_Component
10492 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
10494 return Same_Object (Prefix (N1), Prefix (N2));
10496 -- Third case, indexed component with same subscripts, same array
10498 elsif K1 = N_Indexed_Component
10499 and then K2 = N_Indexed_Component
10500 and then Same_Object (Prefix (N1), Prefix (N2))
10505 E1 := First (Expressions (N1));
10506 E2 := First (Expressions (N2));
10507 while Present (E1) loop
10508 if not Same_Value (E1, E2) then
10519 -- Fourth case, slice of same array with same bounds
10522 and then K2 = N_Slice
10523 and then Nkind (Discrete_Range (N1)) = N_Range
10524 and then Nkind (Discrete_Range (N2)) = N_Range
10525 and then Same_Value (Low_Bound (Discrete_Range (N1)),
10526 Low_Bound (Discrete_Range (N2)))
10527 and then Same_Value (High_Bound (Discrete_Range (N1)),
10528 High_Bound (Discrete_Range (N2)))
10530 return Same_Name (Prefix (N1), Prefix (N2));
10532 -- All other cases, not clearly the same object
10543 function Same_Type (T1, T2 : Entity_Id) return Boolean is
10548 elsif not Is_Constrained (T1)
10549 and then not Is_Constrained (T2)
10550 and then Base_Type (T1) = Base_Type (T2)
10554 -- For now don't bother with case of identical constraints, to be
10555 -- fiddled with later on perhaps (this is only used for optimization
10556 -- purposes, so it is not critical to do a best possible job)
10567 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
10569 if Compile_Time_Known_Value (Node1)
10570 and then Compile_Time_Known_Value (Node2)
10571 and then Expr_Value (Node1) = Expr_Value (Node2)
10574 elsif Same_Object (Node1, Node2) then
10585 procedure Save_Actual (N : Node_Id; Writable : Boolean := False) is
10587 if Is_Entity_Name (N)
10589 Nkind_In (N, N_Indexed_Component, N_Selected_Component, N_Slice)
10591 (Nkind (N) = N_Attribute_Reference
10592 and then Attribute_Name (N) = Name_Access)
10595 -- We are only interested in IN OUT parameters of inner calls
10598 or else Nkind (Parent (N)) = N_Function_Call
10599 or else Nkind (Parent (N)) in N_Op
10601 Actuals_In_Call.Increment_Last;
10602 Actuals_In_Call.Table (Actuals_In_Call.Last) := (N, Writable);
10607 ------------------------
10608 -- Scope_Is_Transient --
10609 ------------------------
10611 function Scope_Is_Transient return Boolean is
10613 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
10614 end Scope_Is_Transient;
10620 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
10625 while Scop /= Standard_Standard loop
10626 Scop := Scope (Scop);
10628 if Scop = Scope2 then
10636 --------------------------
10637 -- Scope_Within_Or_Same --
10638 --------------------------
10640 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
10645 while Scop /= Standard_Standard loop
10646 if Scop = Scope2 then
10649 Scop := Scope (Scop);
10654 end Scope_Within_Or_Same;
10656 --------------------
10657 -- Set_Convention --
10658 --------------------
10660 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
10662 Basic_Set_Convention (E, Val);
10665 and then Is_Access_Subprogram_Type (Base_Type (E))
10666 and then Has_Foreign_Convention (E)
10668 Set_Can_Use_Internal_Rep (E, False);
10670 end Set_Convention;
10672 ------------------------
10673 -- Set_Current_Entity --
10674 ------------------------
10676 -- The given entity is to be set as the currently visible definition
10677 -- of its associated name (i.e. the Node_Id associated with its name).
10678 -- All we have to do is to get the name from the identifier, and
10679 -- then set the associated Node_Id to point to the given entity.
10681 procedure Set_Current_Entity (E : Entity_Id) is
10683 Set_Name_Entity_Id (Chars (E), E);
10684 end Set_Current_Entity;
10686 ---------------------------
10687 -- Set_Debug_Info_Needed --
10688 ---------------------------
10690 procedure Set_Debug_Info_Needed (T : Entity_Id) is
10692 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
10693 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
10694 -- Used to set debug info in a related node if not set already
10696 --------------------------------------
10697 -- Set_Debug_Info_Needed_If_Not_Set --
10698 --------------------------------------
10700 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
10703 and then not Needs_Debug_Info (E)
10705 Set_Debug_Info_Needed (E);
10707 -- For a private type, indicate that the full view also needs
10708 -- debug information.
10711 and then Is_Private_Type (E)
10712 and then Present (Full_View (E))
10714 Set_Debug_Info_Needed (Full_View (E));
10717 end Set_Debug_Info_Needed_If_Not_Set;
10719 -- Start of processing for Set_Debug_Info_Needed
10722 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
10723 -- indicates that Debug_Info_Needed is never required for the entity.
10726 or else Debug_Info_Off (T)
10731 -- Set flag in entity itself. Note that we will go through the following
10732 -- circuitry even if the flag is already set on T. That's intentional,
10733 -- it makes sure that the flag will be set in subsidiary entities.
10735 Set_Needs_Debug_Info (T);
10737 -- Set flag on subsidiary entities if not set already
10739 if Is_Object (T) then
10740 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
10742 elsif Is_Type (T) then
10743 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
10745 if Is_Record_Type (T) then
10747 Ent : Entity_Id := First_Entity (T);
10749 while Present (Ent) loop
10750 Set_Debug_Info_Needed_If_Not_Set (Ent);
10755 -- For a class wide subtype, we also need debug information
10756 -- for the equivalent type.
10758 if Ekind (T) = E_Class_Wide_Subtype then
10759 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
10762 elsif Is_Array_Type (T) then
10763 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
10766 Indx : Node_Id := First_Index (T);
10768 while Present (Indx) loop
10769 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
10770 Indx := Next_Index (Indx);
10774 if Is_Packed (T) then
10775 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Type (T));
10778 elsif Is_Access_Type (T) then
10779 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
10781 elsif Is_Private_Type (T) then
10782 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
10784 elsif Is_Protected_Type (T) then
10785 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
10788 end Set_Debug_Info_Needed;
10790 ---------------------------------
10791 -- Set_Entity_With_Style_Check --
10792 ---------------------------------
10794 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
10795 Val_Actual : Entity_Id;
10799 Set_Entity (N, Val);
10802 and then not Suppress_Style_Checks (Val)
10803 and then not In_Instance
10805 if Nkind (N) = N_Identifier then
10807 elsif Nkind (N) = N_Expanded_Name then
10808 Nod := Selector_Name (N);
10813 -- A special situation arises for derived operations, where we want
10814 -- to do the check against the parent (since the Sloc of the derived
10815 -- operation points to the derived type declaration itself).
10818 while not Comes_From_Source (Val_Actual)
10819 and then Nkind (Val_Actual) in N_Entity
10820 and then (Ekind (Val_Actual) = E_Enumeration_Literal
10821 or else Is_Subprogram (Val_Actual)
10822 or else Is_Generic_Subprogram (Val_Actual))
10823 and then Present (Alias (Val_Actual))
10825 Val_Actual := Alias (Val_Actual);
10828 -- Renaming declarations for generic actuals do not come from source,
10829 -- and have a different name from that of the entity they rename, so
10830 -- there is no style check to perform here.
10832 if Chars (Nod) = Chars (Val_Actual) then
10833 Style.Check_Identifier (Nod, Val_Actual);
10837 Set_Entity (N, Val);
10838 end Set_Entity_With_Style_Check;
10840 ------------------------
10841 -- Set_Name_Entity_Id --
10842 ------------------------
10844 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
10846 Set_Name_Table_Info (Id, Int (Val));
10847 end Set_Name_Entity_Id;
10849 ---------------------
10850 -- Set_Next_Actual --
10851 ---------------------
10853 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
10855 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
10856 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
10858 end Set_Next_Actual;
10860 ----------------------------------
10861 -- Set_Optimize_Alignment_Flags --
10862 ----------------------------------
10864 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
10866 if Optimize_Alignment = 'S' then
10867 Set_Optimize_Alignment_Space (E);
10868 elsif Optimize_Alignment = 'T' then
10869 Set_Optimize_Alignment_Time (E);
10871 end Set_Optimize_Alignment_Flags;
10873 -----------------------
10874 -- Set_Public_Status --
10875 -----------------------
10877 procedure Set_Public_Status (Id : Entity_Id) is
10878 S : constant Entity_Id := Current_Scope;
10880 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
10881 -- Determines if E is defined within handled statement sequence or
10882 -- an if statement, returns True if so, False otherwise.
10884 ----------------------
10885 -- Within_HSS_Or_If --
10886 ----------------------
10888 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
10891 N := Declaration_Node (E);
10898 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
10904 end Within_HSS_Or_If;
10906 -- Start of processing for Set_Public_Status
10909 -- Everything in the scope of Standard is public
10911 if S = Standard_Standard then
10912 Set_Is_Public (Id);
10914 -- Entity is definitely not public if enclosing scope is not public
10916 elsif not Is_Public (S) then
10919 -- An object or function declaration that occurs in a handled sequence
10920 -- of statements or within an if statement is the declaration for a
10921 -- temporary object or local subprogram generated by the expander. It
10922 -- never needs to be made public and furthermore, making it public can
10923 -- cause back end problems.
10925 elsif Nkind_In (Parent (Id), N_Object_Declaration,
10926 N_Function_Specification)
10927 and then Within_HSS_Or_If (Id)
10931 -- Entities in public packages or records are public
10933 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
10934 Set_Is_Public (Id);
10936 -- The bounds of an entry family declaration can generate object
10937 -- declarations that are visible to the back-end, e.g. in the
10938 -- the declaration of a composite type that contains tasks.
10940 elsif Is_Concurrent_Type (S)
10941 and then not Has_Completion (S)
10942 and then Nkind (Parent (Id)) = N_Object_Declaration
10944 Set_Is_Public (Id);
10946 end Set_Public_Status;
10948 -----------------------------
10949 -- Set_Referenced_Modified --
10950 -----------------------------
10952 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
10956 -- Deal with indexed or selected component where prefix is modified
10958 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
10959 Pref := Prefix (N);
10961 -- If prefix is access type, then it is the designated object that is
10962 -- being modified, which means we have no entity to set the flag on.
10964 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
10967 -- Otherwise chase the prefix
10970 Set_Referenced_Modified (Pref, Out_Param);
10973 -- Otherwise see if we have an entity name (only other case to process)
10975 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
10976 Set_Referenced_As_LHS (Entity (N), not Out_Param);
10977 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
10979 end Set_Referenced_Modified;
10981 ----------------------------
10982 -- Set_Scope_Is_Transient --
10983 ----------------------------
10985 procedure Set_Scope_Is_Transient (V : Boolean := True) is
10987 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
10988 end Set_Scope_Is_Transient;
10990 -------------------
10991 -- Set_Size_Info --
10992 -------------------
10994 procedure Set_Size_Info (T1, T2 : Entity_Id) is
10996 -- We copy Esize, but not RM_Size, since in general RM_Size is
10997 -- subtype specific and does not get inherited by all subtypes.
10999 Set_Esize (T1, Esize (T2));
11000 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
11002 if Is_Discrete_Or_Fixed_Point_Type (T1)
11004 Is_Discrete_Or_Fixed_Point_Type (T2)
11006 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
11009 Set_Alignment (T1, Alignment (T2));
11012 --------------------
11013 -- Static_Integer --
11014 --------------------
11016 function Static_Integer (N : Node_Id) return Uint is
11018 Analyze_And_Resolve (N, Any_Integer);
11021 or else Error_Posted (N)
11022 or else Etype (N) = Any_Type
11027 if Is_Static_Expression (N) then
11028 if not Raises_Constraint_Error (N) then
11029 return Expr_Value (N);
11034 elsif Etype (N) = Any_Type then
11038 Flag_Non_Static_Expr
11039 ("static integer expression required here", N);
11042 end Static_Integer;
11044 --------------------------
11045 -- Statically_Different --
11046 --------------------------
11048 function Statically_Different (E1, E2 : Node_Id) return Boolean is
11049 R1 : constant Node_Id := Get_Referenced_Object (E1);
11050 R2 : constant Node_Id := Get_Referenced_Object (E2);
11052 return Is_Entity_Name (R1)
11053 and then Is_Entity_Name (R2)
11054 and then Entity (R1) /= Entity (R2)
11055 and then not Is_Formal (Entity (R1))
11056 and then not Is_Formal (Entity (R2));
11057 end Statically_Different;
11059 -----------------------------
11060 -- Subprogram_Access_Level --
11061 -----------------------------
11063 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
11065 if Present (Alias (Subp)) then
11066 return Subprogram_Access_Level (Alias (Subp));
11068 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
11070 end Subprogram_Access_Level;
11076 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
11078 if Debug_Flag_W then
11079 for J in 0 .. Scope_Stack.Last loop
11084 Write_Name (Chars (E));
11085 Write_Str (" from ");
11086 Write_Location (Sloc (N));
11091 -----------------------
11092 -- Transfer_Entities --
11093 -----------------------
11095 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
11096 Ent : Entity_Id := First_Entity (From);
11103 if (Last_Entity (To)) = Empty then
11104 Set_First_Entity (To, Ent);
11106 Set_Next_Entity (Last_Entity (To), Ent);
11109 Set_Last_Entity (To, Last_Entity (From));
11111 while Present (Ent) loop
11112 Set_Scope (Ent, To);
11114 if not Is_Public (Ent) then
11115 Set_Public_Status (Ent);
11118 and then Ekind (Ent) = E_Record_Subtype
11121 -- The components of the propagated Itype must be public
11127 Comp := First_Entity (Ent);
11128 while Present (Comp) loop
11129 Set_Is_Public (Comp);
11130 Next_Entity (Comp);
11139 Set_First_Entity (From, Empty);
11140 Set_Last_Entity (From, Empty);
11141 end Transfer_Entities;
11143 -----------------------
11144 -- Type_Access_Level --
11145 -----------------------
11147 function Type_Access_Level (Typ : Entity_Id) return Uint is
11151 Btyp := Base_Type (Typ);
11153 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
11154 -- simply use the level where the type is declared. This is true for
11155 -- stand-alone object declarations, and for anonymous access types
11156 -- associated with components the level is the same as that of the
11157 -- enclosing composite type. However, special treatment is needed for
11158 -- the cases of access parameters, return objects of an anonymous access
11159 -- type, and, in Ada 95, access discriminants of limited types.
11161 if Ekind (Btyp) in Access_Kind then
11162 if Ekind (Btyp) = E_Anonymous_Access_Type then
11164 -- If the type is a nonlocal anonymous access type (such as for
11165 -- an access parameter) we treat it as being declared at the
11166 -- library level to ensure that names such as X.all'access don't
11167 -- fail static accessibility checks.
11169 if not Is_Local_Anonymous_Access (Typ) then
11170 return Scope_Depth (Standard_Standard);
11172 -- If this is a return object, the accessibility level is that of
11173 -- the result subtype of the enclosing function. The test here is
11174 -- little complicated, because we have to account for extended
11175 -- return statements that have been rewritten as blocks, in which
11176 -- case we have to find and the Is_Return_Object attribute of the
11177 -- itype's associated object. It would be nice to find a way to
11178 -- simplify this test, but it doesn't seem worthwhile to add a new
11179 -- flag just for purposes of this test. ???
11181 elsif Ekind (Scope (Btyp)) = E_Return_Statement
11184 and then Nkind (Associated_Node_For_Itype (Btyp)) =
11185 N_Object_Declaration
11186 and then Is_Return_Object
11187 (Defining_Identifier
11188 (Associated_Node_For_Itype (Btyp))))
11194 Scop := Scope (Scope (Btyp));
11195 while Present (Scop) loop
11196 exit when Ekind (Scop) = E_Function;
11197 Scop := Scope (Scop);
11200 -- Treat the return object's type as having the level of the
11201 -- function's result subtype (as per RM05-6.5(5.3/2)).
11203 return Type_Access_Level (Etype (Scop));
11208 Btyp := Root_Type (Btyp);
11210 -- The accessibility level of anonymous access types associated with
11211 -- discriminants is that of the current instance of the type, and
11212 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
11214 -- AI-402: access discriminants have accessibility based on the
11215 -- object rather than the type in Ada 2005, so the above paragraph
11218 -- ??? Needs completion with rules from AI-416
11220 if Ada_Version <= Ada_95
11221 and then Ekind (Typ) = E_Anonymous_Access_Type
11222 and then Present (Associated_Node_For_Itype (Typ))
11223 and then Nkind (Associated_Node_For_Itype (Typ)) =
11224 N_Discriminant_Specification
11226 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
11230 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
11231 end Type_Access_Level;
11233 --------------------------
11234 -- Unit_Declaration_Node --
11235 --------------------------
11237 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
11238 N : Node_Id := Parent (Unit_Id);
11241 -- Predefined operators do not have a full function declaration
11243 if Ekind (Unit_Id) = E_Operator then
11247 -- Isn't there some better way to express the following ???
11249 while Nkind (N) /= N_Abstract_Subprogram_Declaration
11250 and then Nkind (N) /= N_Formal_Package_Declaration
11251 and then Nkind (N) /= N_Function_Instantiation
11252 and then Nkind (N) /= N_Generic_Package_Declaration
11253 and then Nkind (N) /= N_Generic_Subprogram_Declaration
11254 and then Nkind (N) /= N_Package_Declaration
11255 and then Nkind (N) /= N_Package_Body
11256 and then Nkind (N) /= N_Package_Instantiation
11257 and then Nkind (N) /= N_Package_Renaming_Declaration
11258 and then Nkind (N) /= N_Procedure_Instantiation
11259 and then Nkind (N) /= N_Protected_Body
11260 and then Nkind (N) /= N_Subprogram_Declaration
11261 and then Nkind (N) /= N_Subprogram_Body
11262 and then Nkind (N) /= N_Subprogram_Body_Stub
11263 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
11264 and then Nkind (N) /= N_Task_Body
11265 and then Nkind (N) /= N_Task_Type_Declaration
11266 and then Nkind (N) not in N_Formal_Subprogram_Declaration
11267 and then Nkind (N) not in N_Generic_Renaming_Declaration
11270 pragma Assert (Present (N));
11274 end Unit_Declaration_Node;
11276 ------------------------------
11277 -- Universal_Interpretation --
11278 ------------------------------
11280 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
11281 Index : Interp_Index;
11285 -- The argument may be a formal parameter of an operator or subprogram
11286 -- with multiple interpretations, or else an expression for an actual.
11288 if Nkind (Opnd) = N_Defining_Identifier
11289 or else not Is_Overloaded (Opnd)
11291 if Etype (Opnd) = Universal_Integer
11292 or else Etype (Opnd) = Universal_Real
11294 return Etype (Opnd);
11300 Get_First_Interp (Opnd, Index, It);
11301 while Present (It.Typ) loop
11302 if It.Typ = Universal_Integer
11303 or else It.Typ = Universal_Real
11308 Get_Next_Interp (Index, It);
11313 end Universal_Interpretation;
11319 function Unqualify (Expr : Node_Id) return Node_Id is
11321 -- Recurse to handle unlikely case of multiple levels of qualification
11323 if Nkind (Expr) = N_Qualified_Expression then
11324 return Unqualify (Expression (Expr));
11326 -- Normal case, not a qualified expression
11333 ----------------------
11334 -- Within_Init_Proc --
11335 ----------------------
11337 function Within_Init_Proc return Boolean is
11341 S := Current_Scope;
11342 while not Is_Overloadable (S) loop
11343 if S = Standard_Standard then
11350 return Is_Init_Proc (S);
11351 end Within_Init_Proc;
11357 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
11358 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
11359 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
11361 function Has_One_Matching_Field return Boolean;
11362 -- Determines if Expec_Type is a record type with a single component or
11363 -- discriminant whose type matches the found type or is one dimensional
11364 -- array whose component type matches the found type.
11366 ----------------------------
11367 -- Has_One_Matching_Field --
11368 ----------------------------
11370 function Has_One_Matching_Field return Boolean is
11374 if Is_Array_Type (Expec_Type)
11375 and then Number_Dimensions (Expec_Type) = 1
11377 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
11381 elsif not Is_Record_Type (Expec_Type) then
11385 E := First_Entity (Expec_Type);
11390 elsif (Ekind (E) /= E_Discriminant
11391 and then Ekind (E) /= E_Component)
11392 or else (Chars (E) = Name_uTag
11393 or else Chars (E) = Name_uParent)
11402 if not Covers (Etype (E), Found_Type) then
11405 elsif Present (Next_Entity (E)) then
11412 end Has_One_Matching_Field;
11414 -- Start of processing for Wrong_Type
11417 -- Don't output message if either type is Any_Type, or if a message
11418 -- has already been posted for this node. We need to do the latter
11419 -- check explicitly (it is ordinarily done in Errout), because we
11420 -- are using ! to force the output of the error messages.
11422 if Expec_Type = Any_Type
11423 or else Found_Type = Any_Type
11424 or else Error_Posted (Expr)
11428 -- In an instance, there is an ongoing problem with completion of
11429 -- type derived from private types. Their structure is what Gigi
11430 -- expects, but the Etype is the parent type rather than the
11431 -- derived private type itself. Do not flag error in this case. The
11432 -- private completion is an entity without a parent, like an Itype.
11433 -- Similarly, full and partial views may be incorrect in the instance.
11434 -- There is no simple way to insure that it is consistent ???
11436 elsif In_Instance then
11437 if Etype (Etype (Expr)) = Etype (Expected_Type)
11439 (Has_Private_Declaration (Expected_Type)
11440 or else Has_Private_Declaration (Etype (Expr)))
11441 and then No (Parent (Expected_Type))
11447 -- An interesting special check. If the expression is parenthesized
11448 -- and its type corresponds to the type of the sole component of the
11449 -- expected record type, or to the component type of the expected one
11450 -- dimensional array type, then assume we have a bad aggregate attempt.
11452 if Nkind (Expr) in N_Subexpr
11453 and then Paren_Count (Expr) /= 0
11454 and then Has_One_Matching_Field
11456 Error_Msg_N ("positional aggregate cannot have one component", Expr);
11458 -- Another special check, if we are looking for a pool-specific access
11459 -- type and we found an E_Access_Attribute_Type, then we have the case
11460 -- of an Access attribute being used in a context which needs a pool-
11461 -- specific type, which is never allowed. The one extra check we make
11462 -- is that the expected designated type covers the Found_Type.
11464 elsif Is_Access_Type (Expec_Type)
11465 and then Ekind (Found_Type) = E_Access_Attribute_Type
11466 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
11467 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
11469 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
11471 Error_Msg_N -- CODEFIX
11472 ("result must be general access type!", Expr);
11473 Error_Msg_NE -- CODEFIX
11474 ("add ALL to }!", Expr, Expec_Type);
11476 -- Another special check, if the expected type is an integer type,
11477 -- but the expression is of type System.Address, and the parent is
11478 -- an addition or subtraction operation whose left operand is the
11479 -- expression in question and whose right operand is of an integral
11480 -- type, then this is an attempt at address arithmetic, so give
11481 -- appropriate message.
11483 elsif Is_Integer_Type (Expec_Type)
11484 and then Is_RTE (Found_Type, RE_Address)
11485 and then (Nkind (Parent (Expr)) = N_Op_Add
11487 Nkind (Parent (Expr)) = N_Op_Subtract)
11488 and then Expr = Left_Opnd (Parent (Expr))
11489 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
11492 ("address arithmetic not predefined in package System",
11495 ("\possible missing with/use of System.Storage_Elements",
11499 -- If the expected type is an anonymous access type, as for access
11500 -- parameters and discriminants, the error is on the designated types.
11502 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
11503 if Comes_From_Source (Expec_Type) then
11504 Error_Msg_NE ("expected}!", Expr, Expec_Type);
11507 ("expected an access type with designated}",
11508 Expr, Designated_Type (Expec_Type));
11511 if Is_Access_Type (Found_Type)
11512 and then not Comes_From_Source (Found_Type)
11515 ("\\found an access type with designated}!",
11516 Expr, Designated_Type (Found_Type));
11518 if From_With_Type (Found_Type) then
11519 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
11520 Error_Msg_Qual_Level := 99;
11521 Error_Msg_NE -- CODEFIX
11522 ("\\missing `WITH &;", Expr, Scope (Found_Type));
11523 Error_Msg_Qual_Level := 0;
11525 Error_Msg_NE ("found}!", Expr, Found_Type);
11529 -- Normal case of one type found, some other type expected
11532 -- If the names of the two types are the same, see if some number
11533 -- of levels of qualification will help. Don't try more than three
11534 -- levels, and if we get to standard, it's no use (and probably
11535 -- represents an error in the compiler) Also do not bother with
11536 -- internal scope names.
11539 Expec_Scope : Entity_Id;
11540 Found_Scope : Entity_Id;
11543 Expec_Scope := Expec_Type;
11544 Found_Scope := Found_Type;
11546 for Levels in Int range 0 .. 3 loop
11547 if Chars (Expec_Scope) /= Chars (Found_Scope) then
11548 Error_Msg_Qual_Level := Levels;
11552 Expec_Scope := Scope (Expec_Scope);
11553 Found_Scope := Scope (Found_Scope);
11555 exit when Expec_Scope = Standard_Standard
11556 or else Found_Scope = Standard_Standard
11557 or else not Comes_From_Source (Expec_Scope)
11558 or else not Comes_From_Source (Found_Scope);
11562 if Is_Record_Type (Expec_Type)
11563 and then Present (Corresponding_Remote_Type (Expec_Type))
11565 Error_Msg_NE ("expected}!", Expr,
11566 Corresponding_Remote_Type (Expec_Type));
11568 Error_Msg_NE ("expected}!", Expr, Expec_Type);
11571 if Is_Entity_Name (Expr)
11572 and then Is_Package_Or_Generic_Package (Entity (Expr))
11574 Error_Msg_N ("\\found package name!", Expr);
11576 elsif Is_Entity_Name (Expr)
11578 (Ekind (Entity (Expr)) = E_Procedure
11580 Ekind (Entity (Expr)) = E_Generic_Procedure)
11582 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
11584 ("found procedure name, possibly missing Access attribute!",
11588 ("\\found procedure name instead of function!", Expr);
11591 elsif Nkind (Expr) = N_Function_Call
11592 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
11593 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
11594 and then No (Parameter_Associations (Expr))
11597 ("found function name, possibly missing Access attribute!",
11600 -- Catch common error: a prefix or infix operator which is not
11601 -- directly visible because the type isn't.
11603 elsif Nkind (Expr) in N_Op
11604 and then Is_Overloaded (Expr)
11605 and then not Is_Immediately_Visible (Expec_Type)
11606 and then not Is_Potentially_Use_Visible (Expec_Type)
11607 and then not In_Use (Expec_Type)
11608 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
11611 ("operator of the type is not directly visible!", Expr);
11613 elsif Ekind (Found_Type) = E_Void
11614 and then Present (Parent (Found_Type))
11615 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
11617 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
11620 Error_Msg_NE ("\\found}!", Expr, Found_Type);
11623 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
11624 -- of the same modular type, and (M1 and M2) = 0 was intended.
11626 if Expec_Type = Standard_Boolean
11627 and then Is_Modular_Integer_Type (Found_Type)
11628 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
11629 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
11632 Op : constant Node_Id := Right_Opnd (Parent (Expr));
11633 L : constant Node_Id := Left_Opnd (Op);
11634 R : constant Node_Id := Right_Opnd (Op);
11636 -- The case for the message is when the left operand of the
11637 -- comparison is the same modular type, or when it is an
11638 -- integer literal (or other universal integer expression),
11639 -- which would have been typed as the modular type if the
11640 -- parens had been there.
11642 if (Etype (L) = Found_Type
11644 Etype (L) = Universal_Integer)
11645 and then Is_Integer_Type (Etype (R))
11648 ("\\possible missing parens for modular operation", Expr);
11653 -- Reset error message qualification indication
11655 Error_Msg_Qual_Level := 0;