* c-common.c (get_priority): Add check for
[official-gcc.git] / gcc / ada / sem_util.adb
blob96378f66961f8dd45b5803a9f58130d451c15736
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ U T I L --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2006, Free Software Foundation, Inc. --
10 -- --
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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
21 -- --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 -- --
25 ------------------------------------------------------------------------------
27 with Atree; use Atree;
28 with Casing; use Casing;
29 with Checks; use Checks;
30 with Debug; use Debug;
31 with Errout; use Errout;
32 with Elists; use Elists;
33 with Exp_Tss; use Exp_Tss;
34 with Exp_Util; use Exp_Util;
35 with Fname; use Fname;
36 with Freeze; use Freeze;
37 with Lib; use Lib;
38 with Lib.Xref; use Lib.Xref;
39 with Namet; use Namet;
40 with Nlists; use Nlists;
41 with Nmake; use Nmake;
42 with Output; use Output;
43 with Opt; use Opt;
44 with Rtsfind; use Rtsfind;
45 with Scans; use Scans;
46 with Scn; use Scn;
47 with Sem; use Sem;
48 with Sem_Ch8; use Sem_Ch8;
49 with Sem_Eval; use Sem_Eval;
50 with Sem_Res; use Sem_Res;
51 with Sem_Type; use Sem_Type;
52 with Sinfo; use Sinfo;
53 with Sinput; use Sinput;
54 with Snames; use Snames;
55 with Stand; use Stand;
56 with Style;
57 with Stringt; use Stringt;
58 with Targparm; use Targparm;
59 with Tbuild; use Tbuild;
60 with Ttypes; use Ttypes;
61 with Uname; use Uname;
63 package body Sem_Util is
65 -----------------------
66 -- Local Subprograms --
67 -----------------------
69 function Build_Component_Subtype
70 (C : List_Id;
71 Loc : Source_Ptr;
72 T : Entity_Id) return Node_Id;
73 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
74 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
75 -- Loc is the source location, T is the original subtype.
77 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
78 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
79 -- with discriminants whose default values are static, examine only the
80 -- components in the selected variant to determine whether all of them
81 -- have a default.
83 function Has_Null_Extension (T : Entity_Id) return Boolean;
84 -- T is a derived tagged type. Check whether the type extension is null.
85 -- If the parent type is fully initialized, T can be treated as such.
87 --------------------------------
88 -- Add_Access_Type_To_Process --
89 --------------------------------
91 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
92 L : Elist_Id;
94 begin
95 Ensure_Freeze_Node (E);
96 L := Access_Types_To_Process (Freeze_Node (E));
98 if No (L) then
99 L := New_Elmt_List;
100 Set_Access_Types_To_Process (Freeze_Node (E), L);
101 end if;
103 Append_Elmt (A, L);
104 end Add_Access_Type_To_Process;
106 -----------------------
107 -- Alignment_In_Bits --
108 -----------------------
110 function Alignment_In_Bits (E : Entity_Id) return Uint is
111 begin
112 return Alignment (E) * System_Storage_Unit;
113 end Alignment_In_Bits;
115 -----------------------------------------
116 -- Apply_Compile_Time_Constraint_Error --
117 -----------------------------------------
119 procedure Apply_Compile_Time_Constraint_Error
120 (N : Node_Id;
121 Msg : String;
122 Reason : RT_Exception_Code;
123 Ent : Entity_Id := Empty;
124 Typ : Entity_Id := Empty;
125 Loc : Source_Ptr := No_Location;
126 Rep : Boolean := True;
127 Warn : Boolean := False)
129 Stat : constant Boolean := Is_Static_Expression (N);
130 Rtyp : Entity_Id;
132 begin
133 if No (Typ) then
134 Rtyp := Etype (N);
135 else
136 Rtyp := Typ;
137 end if;
139 Discard_Node
140 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
142 if not Rep then
143 return;
144 end if;
146 -- Now we replace the node by an N_Raise_Constraint_Error node
147 -- This does not need reanalyzing, so set it as analyzed now.
149 Rewrite (N,
150 Make_Raise_Constraint_Error (Sloc (N),
151 Reason => Reason));
152 Set_Analyzed (N, True);
153 Set_Etype (N, Rtyp);
154 Set_Raises_Constraint_Error (N);
156 -- If the original expression was marked as static, the result is
157 -- still marked as static, but the Raises_Constraint_Error flag is
158 -- always set so that further static evaluation is not attempted.
160 if Stat then
161 Set_Is_Static_Expression (N);
162 end if;
163 end Apply_Compile_Time_Constraint_Error;
165 --------------------------
166 -- Build_Actual_Subtype --
167 --------------------------
169 function Build_Actual_Subtype
170 (T : Entity_Id;
171 N : Node_Or_Entity_Id) return Node_Id
173 Loc : constant Source_Ptr := Sloc (N);
174 Constraints : List_Id;
175 Decl : Node_Id;
176 Discr : Entity_Id;
177 Hi : Node_Id;
178 Lo : Node_Id;
179 Subt : Entity_Id;
180 Disc_Type : Entity_Id;
181 Obj : Node_Id;
183 begin
184 if Nkind (N) = N_Defining_Identifier then
185 Obj := New_Reference_To (N, Loc);
186 else
187 Obj := N;
188 end if;
190 if Is_Array_Type (T) then
191 Constraints := New_List;
192 for J in 1 .. Number_Dimensions (T) loop
194 -- Build an array subtype declaration with the nominal subtype and
195 -- the bounds of the actual. Add the declaration in front of the
196 -- local declarations for the subprogram, for analysis before any
197 -- reference to the formal in the body.
199 Lo :=
200 Make_Attribute_Reference (Loc,
201 Prefix =>
202 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
203 Attribute_Name => Name_First,
204 Expressions => New_List (
205 Make_Integer_Literal (Loc, J)));
207 Hi :=
208 Make_Attribute_Reference (Loc,
209 Prefix =>
210 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
211 Attribute_Name => Name_Last,
212 Expressions => New_List (
213 Make_Integer_Literal (Loc, J)));
215 Append (Make_Range (Loc, Lo, Hi), Constraints);
216 end loop;
218 -- If the type has unknown discriminants there is no constrained
219 -- subtype to build. This is never called for a formal or for a
220 -- lhs, so returning the type is ok ???
222 elsif Has_Unknown_Discriminants (T) then
223 return T;
225 else
226 Constraints := New_List;
228 if Is_Private_Type (T) and then No (Full_View (T)) then
230 -- Type is a generic derived type. Inherit discriminants from
231 -- Parent type.
233 Disc_Type := Etype (Base_Type (T));
234 else
235 Disc_Type := T;
236 end if;
238 Discr := First_Discriminant (Disc_Type);
239 while Present (Discr) loop
240 Append_To (Constraints,
241 Make_Selected_Component (Loc,
242 Prefix =>
243 Duplicate_Subexpr_No_Checks (Obj),
244 Selector_Name => New_Occurrence_Of (Discr, Loc)));
245 Next_Discriminant (Discr);
246 end loop;
247 end if;
249 Subt :=
250 Make_Defining_Identifier (Loc,
251 Chars => New_Internal_Name ('S'));
252 Set_Is_Internal (Subt);
254 Decl :=
255 Make_Subtype_Declaration (Loc,
256 Defining_Identifier => Subt,
257 Subtype_Indication =>
258 Make_Subtype_Indication (Loc,
259 Subtype_Mark => New_Reference_To (T, Loc),
260 Constraint =>
261 Make_Index_Or_Discriminant_Constraint (Loc,
262 Constraints => Constraints)));
264 Mark_Rewrite_Insertion (Decl);
265 return Decl;
266 end Build_Actual_Subtype;
268 ---------------------------------------
269 -- Build_Actual_Subtype_Of_Component --
270 ---------------------------------------
272 function Build_Actual_Subtype_Of_Component
273 (T : Entity_Id;
274 N : Node_Id) return Node_Id
276 Loc : constant Source_Ptr := Sloc (N);
277 P : constant Node_Id := Prefix (N);
278 D : Elmt_Id;
279 Id : Node_Id;
280 Indx_Type : Entity_Id;
282 Deaccessed_T : Entity_Id;
283 -- This is either a copy of T, or if T is an access type, then it is
284 -- the directly designated type of this access type.
286 function Build_Actual_Array_Constraint return List_Id;
287 -- If one or more of the bounds of the component depends on
288 -- discriminants, build actual constraint using the discriminants
289 -- of the prefix.
291 function Build_Actual_Record_Constraint return List_Id;
292 -- Similar to previous one, for discriminated components constrained
293 -- by the discriminant of the enclosing object.
295 -----------------------------------
296 -- Build_Actual_Array_Constraint --
297 -----------------------------------
299 function Build_Actual_Array_Constraint return List_Id is
300 Constraints : constant List_Id := New_List;
301 Indx : Node_Id;
302 Hi : Node_Id;
303 Lo : Node_Id;
304 Old_Hi : Node_Id;
305 Old_Lo : Node_Id;
307 begin
308 Indx := First_Index (Deaccessed_T);
309 while Present (Indx) loop
310 Old_Lo := Type_Low_Bound (Etype (Indx));
311 Old_Hi := Type_High_Bound (Etype (Indx));
313 if Denotes_Discriminant (Old_Lo) then
314 Lo :=
315 Make_Selected_Component (Loc,
316 Prefix => New_Copy_Tree (P),
317 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
319 else
320 Lo := New_Copy_Tree (Old_Lo);
322 -- The new bound will be reanalyzed in the enclosing
323 -- declaration. For literal bounds that come from a type
324 -- declaration, the type of the context must be imposed, so
325 -- insure that analysis will take place. For non-universal
326 -- types this is not strictly necessary.
328 Set_Analyzed (Lo, False);
329 end if;
331 if Denotes_Discriminant (Old_Hi) then
332 Hi :=
333 Make_Selected_Component (Loc,
334 Prefix => New_Copy_Tree (P),
335 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
337 else
338 Hi := New_Copy_Tree (Old_Hi);
339 Set_Analyzed (Hi, False);
340 end if;
342 Append (Make_Range (Loc, Lo, Hi), Constraints);
343 Next_Index (Indx);
344 end loop;
346 return Constraints;
347 end Build_Actual_Array_Constraint;
349 ------------------------------------
350 -- Build_Actual_Record_Constraint --
351 ------------------------------------
353 function Build_Actual_Record_Constraint return List_Id is
354 Constraints : constant List_Id := New_List;
355 D : Elmt_Id;
356 D_Val : Node_Id;
358 begin
359 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
360 while Present (D) loop
361 if Denotes_Discriminant (Node (D)) then
362 D_Val := Make_Selected_Component (Loc,
363 Prefix => New_Copy_Tree (P),
364 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
366 else
367 D_Val := New_Copy_Tree (Node (D));
368 end if;
370 Append (D_Val, Constraints);
371 Next_Elmt (D);
372 end loop;
374 return Constraints;
375 end Build_Actual_Record_Constraint;
377 -- Start of processing for Build_Actual_Subtype_Of_Component
379 begin
380 if In_Default_Expression then
381 return Empty;
383 elsif Nkind (N) = N_Explicit_Dereference then
384 if Is_Composite_Type (T)
385 and then not Is_Constrained (T)
386 and then not (Is_Class_Wide_Type (T)
387 and then Is_Constrained (Root_Type (T)))
388 and then not Has_Unknown_Discriminants (T)
389 then
390 -- If the type of the dereference is already constrained, it
391 -- is an actual subtype.
393 if Is_Array_Type (Etype (N))
394 and then Is_Constrained (Etype (N))
395 then
396 return Empty;
397 else
398 Remove_Side_Effects (P);
399 return Build_Actual_Subtype (T, N);
400 end if;
401 else
402 return Empty;
403 end if;
404 end if;
406 if Ekind (T) = E_Access_Subtype then
407 Deaccessed_T := Designated_Type (T);
408 else
409 Deaccessed_T := T;
410 end if;
412 if Ekind (Deaccessed_T) = E_Array_Subtype then
413 Id := First_Index (Deaccessed_T);
414 while Present (Id) loop
415 Indx_Type := Underlying_Type (Etype (Id));
417 if Denotes_Discriminant (Type_Low_Bound (Indx_Type)) or else
418 Denotes_Discriminant (Type_High_Bound (Indx_Type))
419 then
420 Remove_Side_Effects (P);
421 return
422 Build_Component_Subtype (
423 Build_Actual_Array_Constraint, Loc, Base_Type (T));
424 end if;
426 Next_Index (Id);
427 end loop;
429 elsif Is_Composite_Type (Deaccessed_T)
430 and then Has_Discriminants (Deaccessed_T)
431 and then not Has_Unknown_Discriminants (Deaccessed_T)
432 then
433 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
434 while Present (D) loop
435 if Denotes_Discriminant (Node (D)) then
436 Remove_Side_Effects (P);
437 return
438 Build_Component_Subtype (
439 Build_Actual_Record_Constraint, Loc, Base_Type (T));
440 end if;
442 Next_Elmt (D);
443 end loop;
444 end if;
446 -- If none of the above, the actual and nominal subtypes are the same
448 return Empty;
449 end Build_Actual_Subtype_Of_Component;
451 -----------------------------
452 -- Build_Component_Subtype --
453 -----------------------------
455 function Build_Component_Subtype
456 (C : List_Id;
457 Loc : Source_Ptr;
458 T : Entity_Id) return Node_Id
460 Subt : Entity_Id;
461 Decl : Node_Id;
463 begin
464 -- Unchecked_Union components do not require component subtypes
466 if Is_Unchecked_Union (T) then
467 return Empty;
468 end if;
470 Subt :=
471 Make_Defining_Identifier (Loc,
472 Chars => New_Internal_Name ('S'));
473 Set_Is_Internal (Subt);
475 Decl :=
476 Make_Subtype_Declaration (Loc,
477 Defining_Identifier => Subt,
478 Subtype_Indication =>
479 Make_Subtype_Indication (Loc,
480 Subtype_Mark => New_Reference_To (Base_Type (T), Loc),
481 Constraint =>
482 Make_Index_Or_Discriminant_Constraint (Loc,
483 Constraints => C)));
485 Mark_Rewrite_Insertion (Decl);
486 return Decl;
487 end Build_Component_Subtype;
489 ---------------------------
490 -- Build_Default_Subtype --
491 ---------------------------
493 function Build_Default_Subtype
494 (T : Entity_Id;
495 N : Node_Id) return Entity_Id
497 Loc : constant Source_Ptr := Sloc (N);
498 Disc : Entity_Id;
500 begin
501 if not Has_Discriminants (T) or else Is_Constrained (T) then
502 return T;
503 end if;
505 Disc := First_Discriminant (T);
507 if No (Discriminant_Default_Value (Disc)) then
508 return T;
509 end if;
511 declare
512 Act : constant Entity_Id :=
513 Make_Defining_Identifier (Loc,
514 Chars => New_Internal_Name ('S'));
516 Constraints : constant List_Id := New_List;
517 Decl : Node_Id;
519 begin
520 while Present (Disc) loop
521 Append_To (Constraints,
522 New_Copy_Tree (Discriminant_Default_Value (Disc)));
523 Next_Discriminant (Disc);
524 end loop;
526 Decl :=
527 Make_Subtype_Declaration (Loc,
528 Defining_Identifier => Act,
529 Subtype_Indication =>
530 Make_Subtype_Indication (Loc,
531 Subtype_Mark => New_Occurrence_Of (T, Loc),
532 Constraint =>
533 Make_Index_Or_Discriminant_Constraint (Loc,
534 Constraints => Constraints)));
536 Insert_Action (N, Decl);
537 Analyze (Decl);
538 return Act;
539 end;
540 end Build_Default_Subtype;
542 --------------------------------------------
543 -- Build_Discriminal_Subtype_Of_Component --
544 --------------------------------------------
546 function Build_Discriminal_Subtype_Of_Component
547 (T : Entity_Id) return Node_Id
549 Loc : constant Source_Ptr := Sloc (T);
550 D : Elmt_Id;
551 Id : Node_Id;
553 function Build_Discriminal_Array_Constraint return List_Id;
554 -- If one or more of the bounds of the component depends on
555 -- discriminants, build actual constraint using the discriminants
556 -- of the prefix.
558 function Build_Discriminal_Record_Constraint return List_Id;
559 -- Similar to previous one, for discriminated components constrained
560 -- by the discriminant of the enclosing object.
562 ----------------------------------------
563 -- Build_Discriminal_Array_Constraint --
564 ----------------------------------------
566 function Build_Discriminal_Array_Constraint return List_Id is
567 Constraints : constant List_Id := New_List;
568 Indx : Node_Id;
569 Hi : Node_Id;
570 Lo : Node_Id;
571 Old_Hi : Node_Id;
572 Old_Lo : Node_Id;
574 begin
575 Indx := First_Index (T);
576 while Present (Indx) loop
577 Old_Lo := Type_Low_Bound (Etype (Indx));
578 Old_Hi := Type_High_Bound (Etype (Indx));
580 if Denotes_Discriminant (Old_Lo) then
581 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
583 else
584 Lo := New_Copy_Tree (Old_Lo);
585 end if;
587 if Denotes_Discriminant (Old_Hi) then
588 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
590 else
591 Hi := New_Copy_Tree (Old_Hi);
592 end if;
594 Append (Make_Range (Loc, Lo, Hi), Constraints);
595 Next_Index (Indx);
596 end loop;
598 return Constraints;
599 end Build_Discriminal_Array_Constraint;
601 -----------------------------------------
602 -- Build_Discriminal_Record_Constraint --
603 -----------------------------------------
605 function Build_Discriminal_Record_Constraint return List_Id is
606 Constraints : constant List_Id := New_List;
607 D : Elmt_Id;
608 D_Val : Node_Id;
610 begin
611 D := First_Elmt (Discriminant_Constraint (T));
612 while Present (D) loop
613 if Denotes_Discriminant (Node (D)) then
614 D_Val :=
615 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
617 else
618 D_Val := New_Copy_Tree (Node (D));
619 end if;
621 Append (D_Val, Constraints);
622 Next_Elmt (D);
623 end loop;
625 return Constraints;
626 end Build_Discriminal_Record_Constraint;
628 -- Start of processing for Build_Discriminal_Subtype_Of_Component
630 begin
631 if Ekind (T) = E_Array_Subtype then
632 Id := First_Index (T);
633 while Present (Id) loop
634 if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) or else
635 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
636 then
637 return Build_Component_Subtype
638 (Build_Discriminal_Array_Constraint, Loc, T);
639 end if;
641 Next_Index (Id);
642 end loop;
644 elsif Ekind (T) = E_Record_Subtype
645 and then Has_Discriminants (T)
646 and then not Has_Unknown_Discriminants (T)
647 then
648 D := First_Elmt (Discriminant_Constraint (T));
649 while Present (D) loop
650 if Denotes_Discriminant (Node (D)) then
651 return Build_Component_Subtype
652 (Build_Discriminal_Record_Constraint, Loc, T);
653 end if;
655 Next_Elmt (D);
656 end loop;
657 end if;
659 -- If none of the above, the actual and nominal subtypes are the same
661 return Empty;
662 end Build_Discriminal_Subtype_Of_Component;
664 ------------------------------
665 -- Build_Elaboration_Entity --
666 ------------------------------
668 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
669 Loc : constant Source_Ptr := Sloc (N);
670 Unum : constant Unit_Number_Type := Get_Source_Unit (Loc);
671 Decl : Node_Id;
672 P : Natural;
673 Elab_Ent : Entity_Id;
675 begin
676 -- Ignore if already constructed
678 if Present (Elaboration_Entity (Spec_Id)) then
679 return;
680 end if;
682 -- Construct name of elaboration entity as xxx_E, where xxx
683 -- is the unit name with dots replaced by double underscore.
684 -- We have to manually construct this name, since it will
685 -- be elaborated in the outer scope, and thus will not have
686 -- the unit name automatically prepended.
688 Get_Name_String (Unit_Name (Unum));
690 -- Replace the %s by _E
692 Name_Buffer (Name_Len - 1 .. Name_Len) := "_E";
694 -- Replace dots by double underscore
696 P := 2;
697 while P < Name_Len - 2 loop
698 if Name_Buffer (P) = '.' then
699 Name_Buffer (P + 2 .. Name_Len + 1) :=
700 Name_Buffer (P + 1 .. Name_Len);
701 Name_Len := Name_Len + 1;
702 Name_Buffer (P) := '_';
703 Name_Buffer (P + 1) := '_';
704 P := P + 3;
705 else
706 P := P + 1;
707 end if;
708 end loop;
710 -- Create elaboration flag
712 Elab_Ent :=
713 Make_Defining_Identifier (Loc, Chars => Name_Find);
714 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
716 if No (Declarations (Aux_Decls_Node (N))) then
717 Set_Declarations (Aux_Decls_Node (N), New_List);
718 end if;
720 Decl :=
721 Make_Object_Declaration (Loc,
722 Defining_Identifier => Elab_Ent,
723 Object_Definition =>
724 New_Occurrence_Of (Standard_Boolean, Loc),
725 Expression =>
726 New_Occurrence_Of (Standard_False, Loc));
728 Append_To (Declarations (Aux_Decls_Node (N)), Decl);
729 Analyze (Decl);
731 -- Reset True_Constant indication, since we will indeed assign a value
732 -- to the variable in the binder main. We also kill the Current_Value
733 -- and Last_Assignment fields for the same reason.
735 Set_Is_True_Constant (Elab_Ent, False);
736 Set_Current_Value (Elab_Ent, Empty);
737 Set_Last_Assignment (Elab_Ent, Empty);
739 -- We do not want any further qualification of the name (if we did
740 -- not do this, we would pick up the name of the generic package
741 -- in the case of a library level generic instantiation).
743 Set_Has_Qualified_Name (Elab_Ent);
744 Set_Has_Fully_Qualified_Name (Elab_Ent);
745 end Build_Elaboration_Entity;
747 -----------------------------------
748 -- Cannot_Raise_Constraint_Error --
749 -----------------------------------
751 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
752 begin
753 if Compile_Time_Known_Value (Expr) then
754 return True;
756 elsif Do_Range_Check (Expr) then
757 return False;
759 elsif Raises_Constraint_Error (Expr) then
760 return False;
762 else
763 case Nkind (Expr) is
764 when N_Identifier =>
765 return True;
767 when N_Expanded_Name =>
768 return True;
770 when N_Selected_Component =>
771 return not Do_Discriminant_Check (Expr);
773 when N_Attribute_Reference =>
774 if Do_Overflow_Check (Expr) then
775 return False;
777 elsif No (Expressions (Expr)) then
778 return True;
780 else
781 declare
782 N : Node_Id;
784 begin
785 N := First (Expressions (Expr));
786 while Present (N) loop
787 if Cannot_Raise_Constraint_Error (N) then
788 Next (N);
789 else
790 return False;
791 end if;
792 end loop;
794 return True;
795 end;
796 end if;
798 when N_Type_Conversion =>
799 if Do_Overflow_Check (Expr)
800 or else Do_Length_Check (Expr)
801 or else Do_Tag_Check (Expr)
802 then
803 return False;
804 else
805 return
806 Cannot_Raise_Constraint_Error (Expression (Expr));
807 end if;
809 when N_Unchecked_Type_Conversion =>
810 return Cannot_Raise_Constraint_Error (Expression (Expr));
812 when N_Unary_Op =>
813 if Do_Overflow_Check (Expr) then
814 return False;
815 else
816 return
817 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
818 end if;
820 when N_Op_Divide |
821 N_Op_Mod |
822 N_Op_Rem
824 if Do_Division_Check (Expr)
825 or else Do_Overflow_Check (Expr)
826 then
827 return False;
828 else
829 return
830 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
831 and then
832 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
833 end if;
835 when N_Op_Add |
836 N_Op_And |
837 N_Op_Concat |
838 N_Op_Eq |
839 N_Op_Expon |
840 N_Op_Ge |
841 N_Op_Gt |
842 N_Op_Le |
843 N_Op_Lt |
844 N_Op_Multiply |
845 N_Op_Ne |
846 N_Op_Or |
847 N_Op_Rotate_Left |
848 N_Op_Rotate_Right |
849 N_Op_Shift_Left |
850 N_Op_Shift_Right |
851 N_Op_Shift_Right_Arithmetic |
852 N_Op_Subtract |
853 N_Op_Xor
855 if Do_Overflow_Check (Expr) then
856 return False;
857 else
858 return
859 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
860 and then
861 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
862 end if;
864 when others =>
865 return False;
866 end case;
867 end if;
868 end Cannot_Raise_Constraint_Error;
870 --------------------------
871 -- Check_Fully_Declared --
872 --------------------------
874 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
875 begin
876 if Ekind (T) = E_Incomplete_Type then
878 -- Ada 2005 (AI-50217): If the type is available through a limited
879 -- with_clause, verify that its full view has been analyzed.
881 if From_With_Type (T)
882 and then Present (Non_Limited_View (T))
883 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
884 then
885 -- The non-limited view is fully declared
886 null;
888 else
889 Error_Msg_NE
890 ("premature usage of incomplete}", N, First_Subtype (T));
891 end if;
893 elsif Has_Private_Component (T)
894 and then not Is_Generic_Type (Root_Type (T))
895 and then not In_Default_Expression
896 then
898 -- Special case: if T is the anonymous type created for a single
899 -- task or protected object, use the name of the source object.
901 if Is_Concurrent_Type (T)
902 and then not Comes_From_Source (T)
903 and then Nkind (N) = N_Object_Declaration
904 then
905 Error_Msg_NE ("type of& has incomplete component", N,
906 Defining_Identifier (N));
908 else
909 Error_Msg_NE
910 ("premature usage of incomplete}", N, First_Subtype (T));
911 end if;
912 end if;
913 end Check_Fully_Declared;
915 ------------------------------------------
916 -- Check_Potentially_Blocking_Operation --
917 ------------------------------------------
919 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
920 S : Entity_Id;
922 begin
923 -- N is one of the potentially blocking operations listed in 9.5.1(8).
924 -- When pragma Detect_Blocking is active, the run time will raise
925 -- Program_Error. Here we only issue a warning, since we generally
926 -- support the use of potentially blocking operations in the absence
927 -- of the pragma.
929 -- Indirect blocking through a subprogram call cannot be diagnosed
930 -- statically without interprocedural analysis, so we do not attempt
931 -- to do it here.
933 S := Scope (Current_Scope);
934 while Present (S) and then S /= Standard_Standard loop
935 if Is_Protected_Type (S) then
936 Error_Msg_N
937 ("potentially blocking operation in protected operation?", N);
939 return;
940 end if;
942 S := Scope (S);
943 end loop;
944 end Check_Potentially_Blocking_Operation;
946 ---------------
947 -- Check_VMS --
948 ---------------
950 procedure Check_VMS (Construct : Node_Id) is
951 begin
952 if not OpenVMS_On_Target then
953 Error_Msg_N
954 ("this construct is allowed only in Open'V'M'S", Construct);
955 end if;
956 end Check_VMS;
958 ---------------------------------
959 -- Collect_Abstract_Interfaces --
960 ---------------------------------
962 procedure Collect_Abstract_Interfaces
963 (T : Entity_Id;
964 Ifaces_List : out Elist_Id;
965 Exclude_Parent_Interfaces : Boolean := False)
967 procedure Add_Interface (Iface : Entity_Id);
968 -- Add the interface it if is not already in the list
970 procedure Collect (Typ : Entity_Id);
971 -- Subsidiary subprogram used to traverse the whole list
972 -- of directly and indirectly implemented interfaces
974 -------------------
975 -- Add_Interface --
976 -------------------
978 procedure Add_Interface (Iface : Entity_Id) is
979 Elmt : Elmt_Id;
981 begin
982 Elmt := First_Elmt (Ifaces_List);
983 while Present (Elmt) and then Node (Elmt) /= Iface loop
984 Next_Elmt (Elmt);
985 end loop;
987 if No (Elmt) then
988 Append_Elmt (Iface, Ifaces_List);
989 end if;
990 end Add_Interface;
992 -------------
993 -- Collect --
994 -------------
996 procedure Collect (Typ : Entity_Id) is
997 Ancestor : Entity_Id;
998 Id : Node_Id;
999 Iface : Entity_Id;
1000 Nod : Node_Id;
1002 begin
1003 if Ekind (Typ) = E_Record_Type_With_Private then
1004 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
1005 Nod := Type_Definition (Parent (Typ));
1007 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
1008 if Present (Full_View (Typ)) then
1009 Nod := Type_Definition (Parent (Full_View (Typ)));
1011 -- If the full-view is not available we cannot do anything
1012 -- else here (the source has errors)
1014 else
1015 return;
1016 end if;
1018 -- The support for generic formals with interfaces is still
1019 -- missing???
1021 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
1022 return;
1024 else
1025 pragma Assert
1026 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
1027 Nod := Parent (Typ);
1028 end if;
1030 elsif Ekind (Typ) = E_Record_Subtype then
1031 Nod := Type_Definition (Parent (Etype (Typ)));
1033 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
1034 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
1035 Nod := Formal_Type_Definition (Parent (Typ));
1036 else
1037 Nod := Type_Definition (Parent (Typ));
1038 end if;
1039 end if;
1041 -- Include the ancestor if we are generating the whole list of
1042 -- abstract interfaces.
1044 if Etype (Typ) /= Typ
1046 -- Protect the frontend against wrong sources. For example:
1048 -- package P is
1049 -- type A is tagged null record;
1050 -- type B is new A with private;
1051 -- type C is new A with private;
1052 -- private
1053 -- type B is new C with null record;
1054 -- type C is new B with null record;
1055 -- end P;
1057 and then Etype (Typ) /= T
1058 then
1059 Ancestor := Etype (Typ);
1060 Collect (Ancestor);
1062 if Is_Interface (Ancestor)
1063 and then not Exclude_Parent_Interfaces
1064 then
1065 Add_Interface (Ancestor);
1066 end if;
1067 end if;
1069 -- Traverse the graph of ancestor interfaces
1071 if Is_Non_Empty_List (Interface_List (Nod)) then
1072 Id := First (Interface_List (Nod));
1073 while Present (Id) loop
1074 Iface := Etype (Id);
1076 -- Protect against wrong uses. For example:
1077 -- type I is interface;
1078 -- type O is tagged null record;
1079 -- type Wrong is new I and O with null record; -- ERROR
1081 if Is_Interface (Iface) then
1082 if Exclude_Parent_Interfaces
1083 and then Interface_Present_In_Ancestor (T, Iface)
1084 then
1085 null;
1086 else
1087 Collect (Iface);
1088 Add_Interface (Iface);
1089 end if;
1090 end if;
1092 Next (Id);
1093 end loop;
1094 end if;
1095 end Collect;
1097 -- Start of processing for Collect_Abstract_Interfaces
1099 begin
1100 pragma Assert (Is_Tagged_Type (T));
1101 Ifaces_List := New_Elmt_List;
1102 Collect (T);
1103 end Collect_Abstract_Interfaces;
1105 ----------------------------------
1106 -- Collect_Primitive_Operations --
1107 ----------------------------------
1109 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
1110 B_Type : constant Entity_Id := Base_Type (T);
1111 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
1112 B_Scope : Entity_Id := Scope (B_Type);
1113 Op_List : Elist_Id;
1114 Formal : Entity_Id;
1115 Is_Prim : Boolean;
1116 Formal_Derived : Boolean := False;
1117 Id : Entity_Id;
1119 begin
1120 -- For tagged types, the primitive operations are collected as they
1121 -- are declared, and held in an explicit list which is simply returned.
1123 if Is_Tagged_Type (B_Type) then
1124 return Primitive_Operations (B_Type);
1126 -- An untagged generic type that is a derived type inherits the
1127 -- primitive operations of its parent type. Other formal types only
1128 -- have predefined operators, which are not explicitly represented.
1130 elsif Is_Generic_Type (B_Type) then
1131 if Nkind (B_Decl) = N_Formal_Type_Declaration
1132 and then Nkind (Formal_Type_Definition (B_Decl))
1133 = N_Formal_Derived_Type_Definition
1134 then
1135 Formal_Derived := True;
1136 else
1137 return New_Elmt_List;
1138 end if;
1139 end if;
1141 Op_List := New_Elmt_List;
1143 if B_Scope = Standard_Standard then
1144 if B_Type = Standard_String then
1145 Append_Elmt (Standard_Op_Concat, Op_List);
1147 elsif B_Type = Standard_Wide_String then
1148 Append_Elmt (Standard_Op_Concatw, Op_List);
1150 else
1151 null;
1152 end if;
1154 elsif (Is_Package_Or_Generic_Package (B_Scope)
1155 and then
1156 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
1157 N_Package_Body)
1158 or else Is_Derived_Type (B_Type)
1159 then
1160 -- The primitive operations appear after the base type, except
1161 -- if the derivation happens within the private part of B_Scope
1162 -- and the type is a private type, in which case both the type
1163 -- and some primitive operations may appear before the base
1164 -- type, and the list of candidates starts after the type.
1166 if In_Open_Scopes (B_Scope)
1167 and then Scope (T) = B_Scope
1168 and then In_Private_Part (B_Scope)
1169 then
1170 Id := Next_Entity (T);
1171 else
1172 Id := Next_Entity (B_Type);
1173 end if;
1175 while Present (Id) loop
1177 -- Note that generic formal subprograms are not
1178 -- considered to be primitive operations and thus
1179 -- are never inherited.
1181 if Is_Overloadable (Id)
1182 and then Nkind (Parent (Parent (Id)))
1183 not in N_Formal_Subprogram_Declaration
1184 then
1185 Is_Prim := False;
1187 if Base_Type (Etype (Id)) = B_Type then
1188 Is_Prim := True;
1189 else
1190 Formal := First_Formal (Id);
1191 while Present (Formal) loop
1192 if Base_Type (Etype (Formal)) = B_Type then
1193 Is_Prim := True;
1194 exit;
1196 elsif Ekind (Etype (Formal)) = E_Anonymous_Access_Type
1197 and then Base_Type
1198 (Designated_Type (Etype (Formal))) = B_Type
1199 then
1200 Is_Prim := True;
1201 exit;
1202 end if;
1204 Next_Formal (Formal);
1205 end loop;
1206 end if;
1208 -- For a formal derived type, the only primitives are the
1209 -- ones inherited from the parent type. Operations appearing
1210 -- in the package declaration are not primitive for it.
1212 if Is_Prim
1213 and then (not Formal_Derived
1214 or else Present (Alias (Id)))
1215 then
1216 Append_Elmt (Id, Op_List);
1217 end if;
1218 end if;
1220 Next_Entity (Id);
1222 -- For a type declared in System, some of its operations
1223 -- may appear in the target-specific extension to System.
1225 if No (Id)
1226 and then Chars (B_Scope) = Name_System
1227 and then Scope (B_Scope) = Standard_Standard
1228 and then Present_System_Aux
1229 then
1230 B_Scope := System_Aux_Id;
1231 Id := First_Entity (System_Aux_Id);
1232 end if;
1233 end loop;
1234 end if;
1236 return Op_List;
1237 end Collect_Primitive_Operations;
1239 -------------------------------------
1240 -- Collect_Synchronized_Interfaces --
1241 -------------------------------------
1243 procedure Collect_Synchronized_Interfaces
1244 (Typ : Entity_Id;
1245 Ifaces_List : out Elist_Id)
1247 Iface : Entity_Id;
1249 procedure Collect (Typ : Entity_Id);
1250 -- Gather any parent or progenitor interfaces of type Typ
1252 -------------
1253 -- Collect --
1254 -------------
1256 procedure Collect (Typ : Entity_Id) is
1257 Iface_Elmt : Elmt_Id;
1259 procedure Add (Iface : Entity_Id);
1260 -- Add a single interface to list Ifaces if the interface is
1261 -- not already in the list.
1263 ---------
1264 -- Add --
1265 ---------
1267 procedure Add (Iface : Entity_Id) is
1268 Iface_Elmt : Elmt_Id;
1270 begin
1271 Iface_Elmt := First_Elmt (Ifaces_List);
1272 while Present (Iface_Elmt)
1273 and then Node (Iface_Elmt) /= Iface
1274 loop
1275 Next_Elmt (Iface_Elmt);
1276 end loop;
1278 if No (Iface_Elmt) then
1279 Append_Elmt (Iface, Ifaces_List);
1280 end if;
1281 end Add;
1283 -- Start of processing for Collect
1285 begin
1286 if Is_Interface (Typ) then
1288 -- Potential parent interface
1290 if Etype (Typ) /= Typ then
1291 Collect (Etype (Typ));
1292 end if;
1294 -- Progenitors
1296 if Present (Abstract_Interfaces (Typ)) then
1297 Iface_Elmt := First_Elmt (Abstract_Interfaces (Typ));
1298 while Present (Iface_Elmt) loop
1299 Collect (Node (Iface_Elmt));
1300 Next_Elmt (Iface_Elmt);
1301 end loop;
1302 end if;
1304 Add (Typ);
1305 end if;
1306 end Collect;
1308 -- Start of processing for Collect_Synchronized_Interfaces
1310 begin
1311 pragma Assert (Is_Concurrent_Type (Typ));
1313 Ifaces_List := New_Elmt_List;
1315 if Present (Interface_List (Parent (Typ))) then
1316 Iface := First (Interface_List (Parent (Typ)));
1317 while Present (Iface) loop
1318 Collect (Etype (Iface));
1320 Next (Iface);
1321 end loop;
1322 end if;
1323 end Collect_Synchronized_Interfaces;
1325 -----------------------------------
1326 -- Compile_Time_Constraint_Error --
1327 -----------------------------------
1329 function Compile_Time_Constraint_Error
1330 (N : Node_Id;
1331 Msg : String;
1332 Ent : Entity_Id := Empty;
1333 Loc : Source_Ptr := No_Location;
1334 Warn : Boolean := False) return Node_Id
1336 Msgc : String (1 .. Msg'Length + 2);
1337 Msgl : Natural;
1338 Wmsg : Boolean;
1339 P : Node_Id;
1340 OldP : Node_Id;
1341 Msgs : Boolean;
1342 Eloc : Source_Ptr;
1344 begin
1345 -- A static constraint error in an instance body is not a fatal error.
1346 -- we choose to inhibit the message altogether, because there is no
1347 -- obvious node (for now) on which to post it. On the other hand the
1348 -- offending node must be replaced with a constraint_error in any case.
1350 -- No messages are generated if we already posted an error on this node
1352 if not Error_Posted (N) then
1353 if Loc /= No_Location then
1354 Eloc := Loc;
1355 else
1356 Eloc := Sloc (N);
1357 end if;
1359 -- Make all such messages unconditional
1361 Msgc (1 .. Msg'Length) := Msg;
1362 Msgc (Msg'Length + 1) := '!';
1363 Msgl := Msg'Length + 1;
1365 -- Message is a warning, even in Ada 95 case
1367 if Msg (Msg'Last) = '?' then
1368 Wmsg := True;
1370 -- In Ada 83, all messages are warnings. In the private part and
1371 -- the body of an instance, constraint_checks are only warnings.
1372 -- We also make this a warning if the Warn parameter is set.
1374 elsif Warn
1375 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
1376 then
1377 Msgl := Msgl + 1;
1378 Msgc (Msgl) := '?';
1379 Wmsg := True;
1381 elsif In_Instance_Not_Visible then
1382 Msgl := Msgl + 1;
1383 Msgc (Msgl) := '?';
1384 Wmsg := True;
1386 -- Otherwise we have a real error message (Ada 95 static case)
1388 else
1389 Wmsg := False;
1390 end if;
1392 -- Should we generate a warning? The answer is not quite yes. The
1393 -- very annoying exception occurs in the case of a short circuit
1394 -- operator where the left operand is static and decisive. Climb
1395 -- parents to see if that is the case we have here. Conditional
1396 -- expressions with decisive conditions are a similar situation.
1398 Msgs := True;
1399 P := N;
1400 loop
1401 OldP := P;
1402 P := Parent (P);
1404 -- And then with False as left operand
1406 if Nkind (P) = N_And_Then
1407 and then Compile_Time_Known_Value (Left_Opnd (P))
1408 and then Is_False (Expr_Value (Left_Opnd (P)))
1409 then
1410 Msgs := False;
1411 exit;
1413 -- OR ELSE with True as left operand
1415 elsif Nkind (P) = N_Or_Else
1416 and then Compile_Time_Known_Value (Left_Opnd (P))
1417 and then Is_True (Expr_Value (Left_Opnd (P)))
1418 then
1419 Msgs := False;
1420 exit;
1422 -- Conditional expression
1424 elsif Nkind (P) = N_Conditional_Expression then
1425 declare
1426 Cond : constant Node_Id := First (Expressions (P));
1427 Texp : constant Node_Id := Next (Cond);
1428 Fexp : constant Node_Id := Next (Texp);
1430 begin
1431 if Compile_Time_Known_Value (Cond) then
1433 -- Condition is True and we are in the right operand
1435 if Is_True (Expr_Value (Cond))
1436 and then OldP = Fexp
1437 then
1438 Msgs := False;
1439 exit;
1441 -- Condition is False and we are in the left operand
1443 elsif Is_False (Expr_Value (Cond))
1444 and then OldP = Texp
1445 then
1446 Msgs := False;
1447 exit;
1448 end if;
1449 end if;
1450 end;
1452 -- Special case for component association in aggregates, where
1453 -- we want to keep climbing up to the parent aggregate.
1455 elsif Nkind (P) = N_Component_Association
1456 and then Nkind (Parent (P)) = N_Aggregate
1457 then
1458 null;
1460 -- Keep going if within subexpression
1462 else
1463 exit when Nkind (P) not in N_Subexpr;
1464 end if;
1465 end loop;
1467 if Msgs then
1468 if Present (Ent) then
1469 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
1470 else
1471 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
1472 end if;
1474 if Wmsg then
1475 if Inside_Init_Proc then
1476 Error_Msg_NEL
1477 ("\?& will be raised for objects of this type",
1478 N, Standard_Constraint_Error, Eloc);
1479 else
1480 Error_Msg_NEL
1481 ("\?& will be raised at run time",
1482 N, Standard_Constraint_Error, Eloc);
1483 end if;
1485 else
1486 Error_Msg
1487 ("\static expression fails Constraint_Check", Eloc);
1488 Set_Error_Posted (N);
1489 end if;
1490 end if;
1491 end if;
1493 return N;
1494 end Compile_Time_Constraint_Error;
1496 -----------------------
1497 -- Conditional_Delay --
1498 -----------------------
1500 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
1501 begin
1502 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
1503 Set_Has_Delayed_Freeze (New_Ent);
1504 end if;
1505 end Conditional_Delay;
1507 --------------------
1508 -- Current_Entity --
1509 --------------------
1511 -- The currently visible definition for a given identifier is the
1512 -- one most chained at the start of the visibility chain, i.e. the
1513 -- one that is referenced by the Node_Id value of the name of the
1514 -- given identifier.
1516 function Current_Entity (N : Node_Id) return Entity_Id is
1517 begin
1518 return Get_Name_Entity_Id (Chars (N));
1519 end Current_Entity;
1521 -----------------------------
1522 -- Current_Entity_In_Scope --
1523 -----------------------------
1525 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
1526 E : Entity_Id;
1527 CS : constant Entity_Id := Current_Scope;
1529 Transient_Case : constant Boolean := Scope_Is_Transient;
1531 begin
1532 E := Get_Name_Entity_Id (Chars (N));
1533 while Present (E)
1534 and then Scope (E) /= CS
1535 and then (not Transient_Case or else Scope (E) /= Scope (CS))
1536 loop
1537 E := Homonym (E);
1538 end loop;
1540 return E;
1541 end Current_Entity_In_Scope;
1543 -------------------
1544 -- Current_Scope --
1545 -------------------
1547 function Current_Scope return Entity_Id is
1548 begin
1549 if Scope_Stack.Last = -1 then
1550 return Standard_Standard;
1551 else
1552 declare
1553 C : constant Entity_Id :=
1554 Scope_Stack.Table (Scope_Stack.Last).Entity;
1555 begin
1556 if Present (C) then
1557 return C;
1558 else
1559 return Standard_Standard;
1560 end if;
1561 end;
1562 end if;
1563 end Current_Scope;
1565 ------------------------
1566 -- Current_Subprogram --
1567 ------------------------
1569 function Current_Subprogram return Entity_Id is
1570 Scop : constant Entity_Id := Current_Scope;
1572 begin
1573 if Is_Subprogram (Scop) or else Is_Generic_Subprogram (Scop) then
1574 return Scop;
1575 else
1576 return Enclosing_Subprogram (Scop);
1577 end if;
1578 end Current_Subprogram;
1580 ---------------------
1581 -- Defining_Entity --
1582 ---------------------
1584 function Defining_Entity (N : Node_Id) return Entity_Id is
1585 K : constant Node_Kind := Nkind (N);
1586 Err : Entity_Id := Empty;
1588 begin
1589 case K is
1590 when
1591 N_Subprogram_Declaration |
1592 N_Abstract_Subprogram_Declaration |
1593 N_Subprogram_Body |
1594 N_Package_Declaration |
1595 N_Subprogram_Renaming_Declaration |
1596 N_Subprogram_Body_Stub |
1597 N_Generic_Subprogram_Declaration |
1598 N_Generic_Package_Declaration |
1599 N_Formal_Subprogram_Declaration
1601 return Defining_Entity (Specification (N));
1603 when
1604 N_Component_Declaration |
1605 N_Defining_Program_Unit_Name |
1606 N_Discriminant_Specification |
1607 N_Entry_Body |
1608 N_Entry_Declaration |
1609 N_Entry_Index_Specification |
1610 N_Exception_Declaration |
1611 N_Exception_Renaming_Declaration |
1612 N_Formal_Object_Declaration |
1613 N_Formal_Package_Declaration |
1614 N_Formal_Type_Declaration |
1615 N_Full_Type_Declaration |
1616 N_Implicit_Label_Declaration |
1617 N_Incomplete_Type_Declaration |
1618 N_Loop_Parameter_Specification |
1619 N_Number_Declaration |
1620 N_Object_Declaration |
1621 N_Object_Renaming_Declaration |
1622 N_Package_Body_Stub |
1623 N_Parameter_Specification |
1624 N_Private_Extension_Declaration |
1625 N_Private_Type_Declaration |
1626 N_Protected_Body |
1627 N_Protected_Body_Stub |
1628 N_Protected_Type_Declaration |
1629 N_Single_Protected_Declaration |
1630 N_Single_Task_Declaration |
1631 N_Subtype_Declaration |
1632 N_Task_Body |
1633 N_Task_Body_Stub |
1634 N_Task_Type_Declaration
1636 return Defining_Identifier (N);
1638 when N_Subunit =>
1639 return Defining_Entity (Proper_Body (N));
1641 when
1642 N_Function_Instantiation |
1643 N_Function_Specification |
1644 N_Generic_Function_Renaming_Declaration |
1645 N_Generic_Package_Renaming_Declaration |
1646 N_Generic_Procedure_Renaming_Declaration |
1647 N_Package_Body |
1648 N_Package_Instantiation |
1649 N_Package_Renaming_Declaration |
1650 N_Package_Specification |
1651 N_Procedure_Instantiation |
1652 N_Procedure_Specification
1654 declare
1655 Nam : constant Node_Id := Defining_Unit_Name (N);
1657 begin
1658 if Nkind (Nam) in N_Entity then
1659 return Nam;
1661 -- For Error, make up a name and attach to declaration
1662 -- so we can continue semantic analysis
1664 elsif Nam = Error then
1665 Err :=
1666 Make_Defining_Identifier (Sloc (N),
1667 Chars => New_Internal_Name ('T'));
1668 Set_Defining_Unit_Name (N, Err);
1670 return Err;
1671 -- If not an entity, get defining identifier
1673 else
1674 return Defining_Identifier (Nam);
1675 end if;
1676 end;
1678 when N_Block_Statement =>
1679 return Entity (Identifier (N));
1681 when others =>
1682 raise Program_Error;
1684 end case;
1685 end Defining_Entity;
1687 --------------------------
1688 -- Denotes_Discriminant --
1689 --------------------------
1691 function Denotes_Discriminant
1692 (N : Node_Id;
1693 Check_Concurrent : Boolean := False) return Boolean
1695 E : Entity_Id;
1696 begin
1697 if not Is_Entity_Name (N)
1698 or else No (Entity (N))
1699 then
1700 return False;
1701 else
1702 E := Entity (N);
1703 end if;
1705 -- If we are checking for a protected type, the discriminant may have
1706 -- been rewritten as the corresponding discriminal of the original type
1707 -- or of the corresponding concurrent record, depending on whether we
1708 -- are in the spec or body of the protected type.
1710 return Ekind (E) = E_Discriminant
1711 or else
1712 (Check_Concurrent
1713 and then Ekind (E) = E_In_Parameter
1714 and then Present (Discriminal_Link (E))
1715 and then
1716 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
1717 or else
1718 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
1720 end Denotes_Discriminant;
1722 -----------------------------
1723 -- Depends_On_Discriminant --
1724 -----------------------------
1726 function Depends_On_Discriminant (N : Node_Id) return Boolean is
1727 L : Node_Id;
1728 H : Node_Id;
1730 begin
1731 Get_Index_Bounds (N, L, H);
1732 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
1733 end Depends_On_Discriminant;
1735 -------------------------
1736 -- Designate_Same_Unit --
1737 -------------------------
1739 function Designate_Same_Unit
1740 (Name1 : Node_Id;
1741 Name2 : Node_Id) return Boolean
1743 K1 : constant Node_Kind := Nkind (Name1);
1744 K2 : constant Node_Kind := Nkind (Name2);
1746 function Prefix_Node (N : Node_Id) return Node_Id;
1747 -- Returns the parent unit name node of a defining program unit name
1748 -- or the prefix if N is a selected component or an expanded name.
1750 function Select_Node (N : Node_Id) return Node_Id;
1751 -- Returns the defining identifier node of a defining program unit
1752 -- name or the selector node if N is a selected component or an
1753 -- expanded name.
1755 -----------------
1756 -- Prefix_Node --
1757 -----------------
1759 function Prefix_Node (N : Node_Id) return Node_Id is
1760 begin
1761 if Nkind (N) = N_Defining_Program_Unit_Name then
1762 return Name (N);
1764 else
1765 return Prefix (N);
1766 end if;
1767 end Prefix_Node;
1769 -----------------
1770 -- Select_Node --
1771 -----------------
1773 function Select_Node (N : Node_Id) return Node_Id is
1774 begin
1775 if Nkind (N) = N_Defining_Program_Unit_Name then
1776 return Defining_Identifier (N);
1778 else
1779 return Selector_Name (N);
1780 end if;
1781 end Select_Node;
1783 -- Start of processing for Designate_Next_Unit
1785 begin
1786 if (K1 = N_Identifier or else
1787 K1 = N_Defining_Identifier)
1788 and then
1789 (K2 = N_Identifier or else
1790 K2 = N_Defining_Identifier)
1791 then
1792 return Chars (Name1) = Chars (Name2);
1794 elsif
1795 (K1 = N_Expanded_Name or else
1796 K1 = N_Selected_Component or else
1797 K1 = N_Defining_Program_Unit_Name)
1798 and then
1799 (K2 = N_Expanded_Name or else
1800 K2 = N_Selected_Component or else
1801 K2 = N_Defining_Program_Unit_Name)
1802 then
1803 return
1804 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
1805 and then
1806 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
1808 else
1809 return False;
1810 end if;
1811 end Designate_Same_Unit;
1813 ----------------------------
1814 -- Enclosing_Generic_Body --
1815 ----------------------------
1817 function Enclosing_Generic_Body
1818 (N : Node_Id) return Node_Id
1820 P : Node_Id;
1821 Decl : Node_Id;
1822 Spec : Node_Id;
1824 begin
1825 P := Parent (N);
1826 while Present (P) loop
1827 if Nkind (P) = N_Package_Body
1828 or else Nkind (P) = N_Subprogram_Body
1829 then
1830 Spec := Corresponding_Spec (P);
1832 if Present (Spec) then
1833 Decl := Unit_Declaration_Node (Spec);
1835 if Nkind (Decl) = N_Generic_Package_Declaration
1836 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
1837 then
1838 return P;
1839 end if;
1840 end if;
1841 end if;
1843 P := Parent (P);
1844 end loop;
1846 return Empty;
1847 end Enclosing_Generic_Body;
1849 ----------------------------
1850 -- Enclosing_Generic_Unit --
1851 ----------------------------
1853 function Enclosing_Generic_Unit
1854 (N : Node_Id) return Node_Id
1856 P : Node_Id;
1857 Decl : Node_Id;
1858 Spec : Node_Id;
1860 begin
1861 P := Parent (N);
1862 while Present (P) loop
1863 if Nkind (P) = N_Generic_Package_Declaration
1864 or else Nkind (P) = N_Generic_Subprogram_Declaration
1865 then
1866 return P;
1868 elsif Nkind (P) = N_Package_Body
1869 or else Nkind (P) = N_Subprogram_Body
1870 then
1871 Spec := Corresponding_Spec (P);
1873 if Present (Spec) then
1874 Decl := Unit_Declaration_Node (Spec);
1876 if Nkind (Decl) = N_Generic_Package_Declaration
1877 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
1878 then
1879 return Decl;
1880 end if;
1881 end if;
1882 end if;
1884 P := Parent (P);
1885 end loop;
1887 return Empty;
1888 end Enclosing_Generic_Unit;
1890 -------------------------------
1891 -- Enclosing_Lib_Unit_Entity --
1892 -------------------------------
1894 function Enclosing_Lib_Unit_Entity return Entity_Id is
1895 Unit_Entity : Entity_Id;
1897 begin
1898 -- Look for enclosing library unit entity by following scope links.
1899 -- Equivalent to, but faster than indexing through the scope stack.
1901 Unit_Entity := Current_Scope;
1902 while (Present (Scope (Unit_Entity))
1903 and then Scope (Unit_Entity) /= Standard_Standard)
1904 and not Is_Child_Unit (Unit_Entity)
1905 loop
1906 Unit_Entity := Scope (Unit_Entity);
1907 end loop;
1909 return Unit_Entity;
1910 end Enclosing_Lib_Unit_Entity;
1912 -----------------------------
1913 -- Enclosing_Lib_Unit_Node --
1914 -----------------------------
1916 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
1917 Current_Node : Node_Id;
1919 begin
1920 Current_Node := N;
1921 while Present (Current_Node)
1922 and then Nkind (Current_Node) /= N_Compilation_Unit
1923 loop
1924 Current_Node := Parent (Current_Node);
1925 end loop;
1927 if Nkind (Current_Node) /= N_Compilation_Unit then
1928 return Empty;
1929 end if;
1931 return Current_Node;
1932 end Enclosing_Lib_Unit_Node;
1934 --------------------------
1935 -- Enclosing_Subprogram --
1936 --------------------------
1938 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
1939 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
1941 begin
1942 if Dynamic_Scope = Standard_Standard then
1943 return Empty;
1945 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
1946 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
1948 elsif Ekind (Dynamic_Scope) = E_Block then
1949 return Enclosing_Subprogram (Dynamic_Scope);
1951 elsif Ekind (Dynamic_Scope) = E_Task_Type then
1952 return Get_Task_Body_Procedure (Dynamic_Scope);
1954 elsif Convention (Dynamic_Scope) = Convention_Protected then
1955 return Protected_Body_Subprogram (Dynamic_Scope);
1957 else
1958 return Dynamic_Scope;
1959 end if;
1960 end Enclosing_Subprogram;
1962 ------------------------
1963 -- Ensure_Freeze_Node --
1964 ------------------------
1966 procedure Ensure_Freeze_Node (E : Entity_Id) is
1967 FN : Node_Id;
1969 begin
1970 if No (Freeze_Node (E)) then
1971 FN := Make_Freeze_Entity (Sloc (E));
1972 Set_Has_Delayed_Freeze (E);
1973 Set_Freeze_Node (E, FN);
1974 Set_Access_Types_To_Process (FN, No_Elist);
1975 Set_TSS_Elist (FN, No_Elist);
1976 Set_Entity (FN, E);
1977 end if;
1978 end Ensure_Freeze_Node;
1980 ----------------
1981 -- Enter_Name --
1982 ----------------
1984 procedure Enter_Name (Def_Id : Entity_Id) is
1985 C : constant Entity_Id := Current_Entity (Def_Id);
1986 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
1987 S : constant Entity_Id := Current_Scope;
1989 function Is_Private_Component_Renaming (N : Node_Id) return Boolean;
1990 -- Recognize a renaming declaration that is introduced for private
1991 -- components of a protected type. We treat these as weak declarations
1992 -- so that they are overridden by entities with the same name that
1993 -- come from source, such as formals or local variables of a given
1994 -- protected declaration.
1996 -----------------------------------
1997 -- Is_Private_Component_Renaming --
1998 -----------------------------------
2000 function Is_Private_Component_Renaming (N : Node_Id) return Boolean is
2001 begin
2002 return not Comes_From_Source (N)
2003 and then not Comes_From_Source (Current_Scope)
2004 and then Nkind (N) = N_Object_Renaming_Declaration;
2005 end Is_Private_Component_Renaming;
2007 -- Start of processing for Enter_Name
2009 begin
2010 Generate_Definition (Def_Id);
2012 -- Add new name to current scope declarations. Check for duplicate
2013 -- declaration, which may or may not be a genuine error.
2015 if Present (E) then
2017 -- Case of previous entity entered because of a missing declaration
2018 -- or else a bad subtype indication. Best is to use the new entity,
2019 -- and make the previous one invisible.
2021 if Etype (E) = Any_Type then
2022 Set_Is_Immediately_Visible (E, False);
2024 -- Case of renaming declaration constructed for package instances.
2025 -- if there is an explicit declaration with the same identifier,
2026 -- the renaming is not immediately visible any longer, but remains
2027 -- visible through selected component notation.
2029 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
2030 and then not Comes_From_Source (E)
2031 then
2032 Set_Is_Immediately_Visible (E, False);
2034 -- The new entity may be the package renaming, which has the same
2035 -- same name as a generic formal which has been seen already.
2037 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
2038 and then not Comes_From_Source (Def_Id)
2039 then
2040 Set_Is_Immediately_Visible (E, False);
2042 -- For a fat pointer corresponding to a remote access to subprogram,
2043 -- we use the same identifier as the RAS type, so that the proper
2044 -- name appears in the stub. This type is only retrieved through
2045 -- the RAS type and never by visibility, and is not added to the
2046 -- visibility list (see below).
2048 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
2049 and then Present (Corresponding_Remote_Type (Def_Id))
2050 then
2051 null;
2053 -- A controller component for a type extension overrides the
2054 -- inherited component.
2056 elsif Chars (E) = Name_uController then
2057 null;
2059 -- Case of an implicit operation or derived literal. The new entity
2060 -- hides the implicit one, which is removed from all visibility,
2061 -- i.e. the entity list of its scope, and homonym chain of its name.
2063 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
2064 or else Is_Internal (E)
2065 then
2066 declare
2067 Prev : Entity_Id;
2068 Prev_Vis : Entity_Id;
2069 Decl : constant Node_Id := Parent (E);
2071 begin
2072 -- If E is an implicit declaration, it cannot be the first
2073 -- entity in the scope.
2075 Prev := First_Entity (Current_Scope);
2076 while Present (Prev)
2077 and then Next_Entity (Prev) /= E
2078 loop
2079 Next_Entity (Prev);
2080 end loop;
2082 if No (Prev) then
2084 -- If E is not on the entity chain of the current scope,
2085 -- it is an implicit declaration in the generic formal
2086 -- part of a generic subprogram. When analyzing the body,
2087 -- the generic formals are visible but not on the entity
2088 -- chain of the subprogram. The new entity will become
2089 -- the visible one in the body.
2091 pragma Assert
2092 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
2093 null;
2095 else
2096 Set_Next_Entity (Prev, Next_Entity (E));
2098 if No (Next_Entity (Prev)) then
2099 Set_Last_Entity (Current_Scope, Prev);
2100 end if;
2102 if E = Current_Entity (E) then
2103 Prev_Vis := Empty;
2105 else
2106 Prev_Vis := Current_Entity (E);
2107 while Homonym (Prev_Vis) /= E loop
2108 Prev_Vis := Homonym (Prev_Vis);
2109 end loop;
2110 end if;
2112 if Present (Prev_Vis) then
2114 -- Skip E in the visibility chain
2116 Set_Homonym (Prev_Vis, Homonym (E));
2118 else
2119 Set_Name_Entity_Id (Chars (E), Homonym (E));
2120 end if;
2121 end if;
2122 end;
2124 -- This section of code could use a comment ???
2126 elsif Present (Etype (E))
2127 and then Is_Concurrent_Type (Etype (E))
2128 and then E = Def_Id
2129 then
2130 return;
2132 elsif Is_Private_Component_Renaming (Parent (Def_Id)) then
2133 return;
2135 -- In the body or private part of an instance, a type extension
2136 -- may introduce a component with the same name as that of an
2137 -- actual. The legality rule is not enforced, but the semantics
2138 -- of the full type with two components of the same name are not
2139 -- clear at this point ???
2141 elsif In_Instance_Not_Visible then
2142 null;
2144 -- When compiling a package body, some child units may have become
2145 -- visible. They cannot conflict with local entities that hide them.
2147 elsif Is_Child_Unit (E)
2148 and then In_Open_Scopes (Scope (E))
2149 and then not Is_Immediately_Visible (E)
2150 then
2151 null;
2153 -- Conversely, with front-end inlining we may compile the parent
2154 -- body first, and a child unit subsequently. The context is now
2155 -- the parent spec, and body entities are not visible.
2157 elsif Is_Child_Unit (Def_Id)
2158 and then Is_Package_Body_Entity (E)
2159 and then not In_Package_Body (Current_Scope)
2160 then
2161 null;
2163 -- Case of genuine duplicate declaration
2165 else
2166 Error_Msg_Sloc := Sloc (E);
2168 -- If the previous declaration is an incomplete type declaration
2169 -- this may be an attempt to complete it with a private type.
2170 -- The following avoids confusing cascaded errors.
2172 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
2173 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
2174 then
2175 Error_Msg_N
2176 ("incomplete type cannot be completed" &
2177 " with a private declaration",
2178 Parent (Def_Id));
2179 Set_Is_Immediately_Visible (E, False);
2180 Set_Full_View (E, Def_Id);
2182 elsif Ekind (E) = E_Discriminant
2183 and then Present (Scope (Def_Id))
2184 and then Scope (Def_Id) /= Current_Scope
2185 then
2186 -- An inherited component of a record conflicts with
2187 -- a new discriminant. The discriminant is inserted first
2188 -- in the scope, but the error should be posted on it, not
2189 -- on the component.
2191 Error_Msg_Sloc := Sloc (Def_Id);
2192 Error_Msg_N ("& conflicts with declaration#", E);
2193 return;
2195 -- If the name of the unit appears in its own context clause,
2196 -- a dummy package with the name has already been created, and
2197 -- the error emitted. Try to continue quietly.
2199 elsif Error_Posted (E)
2200 and then Sloc (E) = No_Location
2201 and then Nkind (Parent (E)) = N_Package_Specification
2202 and then Current_Scope = Standard_Standard
2203 then
2204 Set_Scope (Def_Id, Current_Scope);
2205 return;
2207 else
2208 Error_Msg_N ("& conflicts with declaration#", Def_Id);
2210 -- Avoid cascaded messages with duplicate components in
2211 -- derived types.
2213 if Ekind (E) = E_Component
2214 or else Ekind (E) = E_Discriminant
2215 then
2216 return;
2217 end if;
2218 end if;
2220 if Nkind (Parent (Parent (Def_Id)))
2221 = N_Generic_Subprogram_Declaration
2222 and then Def_Id =
2223 Defining_Entity (Specification (Parent (Parent (Def_Id))))
2224 then
2225 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
2226 end if;
2228 -- If entity is in standard, then we are in trouble, because
2229 -- it means that we have a library package with a duplicated
2230 -- name. That's hard to recover from, so abort!
2232 if S = Standard_Standard then
2233 raise Unrecoverable_Error;
2235 -- Otherwise we continue with the declaration. Having two
2236 -- identical declarations should not cause us too much trouble!
2238 else
2239 null;
2240 end if;
2241 end if;
2242 end if;
2244 -- If we fall through, declaration is OK , or OK enough to continue
2246 -- If Def_Id is a discriminant or a record component we are in the
2247 -- midst of inheriting components in a derived record definition.
2248 -- Preserve their Ekind and Etype.
2250 if Ekind (Def_Id) = E_Discriminant
2251 or else Ekind (Def_Id) = E_Component
2252 then
2253 null;
2255 -- If a type is already set, leave it alone (happens whey a type
2256 -- declaration is reanalyzed following a call to the optimizer)
2258 elsif Present (Etype (Def_Id)) then
2259 null;
2261 -- Otherwise, the kind E_Void insures that premature uses of the entity
2262 -- will be detected. Any_Type insures that no cascaded errors will occur
2264 else
2265 Set_Ekind (Def_Id, E_Void);
2266 Set_Etype (Def_Id, Any_Type);
2267 end if;
2269 -- Inherited discriminants and components in derived record types are
2270 -- immediately visible. Itypes are not.
2272 if Ekind (Def_Id) = E_Discriminant
2273 or else Ekind (Def_Id) = E_Component
2274 or else (No (Corresponding_Remote_Type (Def_Id))
2275 and then not Is_Itype (Def_Id))
2276 then
2277 Set_Is_Immediately_Visible (Def_Id);
2278 Set_Current_Entity (Def_Id);
2279 end if;
2281 Set_Homonym (Def_Id, C);
2282 Append_Entity (Def_Id, S);
2283 Set_Public_Status (Def_Id);
2285 -- Warn if new entity hides an old one
2287 if Warn_On_Hiding and then Present (C)
2289 -- Don't warn for one character variables. It is too common to use
2290 -- such variables as locals and will just cause too many false hits.
2292 and then Length_Of_Name (Chars (C)) /= 1
2294 -- Don't warn for non-source eneities
2296 and then Comes_From_Source (C)
2297 and then Comes_From_Source (Def_Id)
2299 -- Don't warn unless entity in question is in extended main source
2301 and then In_Extended_Main_Source_Unit (Def_Id)
2303 -- Finally, the hidden entity must be either immediately visible
2304 -- or use visible (from a used package)
2306 and then
2307 (Is_Immediately_Visible (C)
2308 or else
2309 Is_Potentially_Use_Visible (C))
2310 then
2311 Error_Msg_Sloc := Sloc (C);
2312 Error_Msg_N ("declaration hides &#?", Def_Id);
2313 end if;
2314 end Enter_Name;
2316 --------------------------
2317 -- Explain_Limited_Type --
2318 --------------------------
2320 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
2321 C : Entity_Id;
2323 begin
2324 -- For array, component type must be limited
2326 if Is_Array_Type (T) then
2327 Error_Msg_Node_2 := T;
2328 Error_Msg_NE
2329 ("\component type& of type& is limited", N, Component_Type (T));
2330 Explain_Limited_Type (Component_Type (T), N);
2332 elsif Is_Record_Type (T) then
2334 -- No need for extra messages if explicit limited record
2336 if Is_Limited_Record (Base_Type (T)) then
2337 return;
2338 end if;
2340 -- Otherwise find a limited component. Check only components that
2341 -- come from source, or inherited components that appear in the
2342 -- source of the ancestor.
2344 C := First_Component (T);
2345 while Present (C) loop
2346 if Is_Limited_Type (Etype (C))
2347 and then
2348 (Comes_From_Source (C)
2349 or else
2350 (Present (Original_Record_Component (C))
2351 and then
2352 Comes_From_Source (Original_Record_Component (C))))
2353 then
2354 Error_Msg_Node_2 := T;
2355 Error_Msg_NE ("\component& of type& has limited type", N, C);
2356 Explain_Limited_Type (Etype (C), N);
2357 return;
2358 end if;
2360 Next_Component (C);
2361 end loop;
2363 -- The type may be declared explicitly limited, even if no component
2364 -- of it is limited, in which case we fall out of the loop.
2365 return;
2366 end if;
2367 end Explain_Limited_Type;
2369 -------------------------------------
2370 -- Find_Corresponding_Discriminant --
2371 -------------------------------------
2373 function Find_Corresponding_Discriminant
2374 (Id : Node_Id;
2375 Typ : Entity_Id) return Entity_Id
2377 Par_Disc : Entity_Id;
2378 Old_Disc : Entity_Id;
2379 New_Disc : Entity_Id;
2381 begin
2382 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
2384 -- The original type may currently be private, and the discriminant
2385 -- only appear on its full view.
2387 if Is_Private_Type (Scope (Par_Disc))
2388 and then not Has_Discriminants (Scope (Par_Disc))
2389 and then Present (Full_View (Scope (Par_Disc)))
2390 then
2391 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
2392 else
2393 Old_Disc := First_Discriminant (Scope (Par_Disc));
2394 end if;
2396 if Is_Class_Wide_Type (Typ) then
2397 New_Disc := First_Discriminant (Root_Type (Typ));
2398 else
2399 New_Disc := First_Discriminant (Typ);
2400 end if;
2402 while Present (Old_Disc) and then Present (New_Disc) loop
2403 if Old_Disc = Par_Disc then
2404 return New_Disc;
2405 else
2406 Next_Discriminant (Old_Disc);
2407 Next_Discriminant (New_Disc);
2408 end if;
2409 end loop;
2411 -- Should always find it
2413 raise Program_Error;
2414 end Find_Corresponding_Discriminant;
2416 -----------------------------
2417 -- Find_Static_Alternative --
2418 -----------------------------
2420 function Find_Static_Alternative (N : Node_Id) return Node_Id is
2421 Expr : constant Node_Id := Expression (N);
2422 Val : constant Uint := Expr_Value (Expr);
2423 Alt : Node_Id;
2424 Choice : Node_Id;
2426 begin
2427 Alt := First (Alternatives (N));
2429 Search : loop
2430 if Nkind (Alt) /= N_Pragma then
2431 Choice := First (Discrete_Choices (Alt));
2432 while Present (Choice) loop
2434 -- Others choice, always matches
2436 if Nkind (Choice) = N_Others_Choice then
2437 exit Search;
2439 -- Range, check if value is in the range
2441 elsif Nkind (Choice) = N_Range then
2442 exit Search when
2443 Val >= Expr_Value (Low_Bound (Choice))
2444 and then
2445 Val <= Expr_Value (High_Bound (Choice));
2447 -- Choice is a subtype name. Note that we know it must
2448 -- be a static subtype, since otherwise it would have
2449 -- been diagnosed as illegal.
2451 elsif Is_Entity_Name (Choice)
2452 and then Is_Type (Entity (Choice))
2453 then
2454 exit Search when Is_In_Range (Expr, Etype (Choice));
2456 -- Choice is a subtype indication
2458 elsif Nkind (Choice) = N_Subtype_Indication then
2459 declare
2460 C : constant Node_Id := Constraint (Choice);
2461 R : constant Node_Id := Range_Expression (C);
2463 begin
2464 exit Search when
2465 Val >= Expr_Value (Low_Bound (R))
2466 and then
2467 Val <= Expr_Value (High_Bound (R));
2468 end;
2470 -- Choice is a simple expression
2472 else
2473 exit Search when Val = Expr_Value (Choice);
2474 end if;
2476 Next (Choice);
2477 end loop;
2478 end if;
2480 Next (Alt);
2481 pragma Assert (Present (Alt));
2482 end loop Search;
2484 -- The above loop *must* terminate by finding a match, since
2485 -- we know the case statement is valid, and the value of the
2486 -- expression is known at compile time. When we fall out of
2487 -- the loop, Alt points to the alternative that we know will
2488 -- be selected at run time.
2490 return Alt;
2491 end Find_Static_Alternative;
2493 ------------------
2494 -- First_Actual --
2495 ------------------
2497 function First_Actual (Node : Node_Id) return Node_Id is
2498 N : Node_Id;
2500 begin
2501 if No (Parameter_Associations (Node)) then
2502 return Empty;
2503 end if;
2505 N := First (Parameter_Associations (Node));
2507 if Nkind (N) = N_Parameter_Association then
2508 return First_Named_Actual (Node);
2509 else
2510 return N;
2511 end if;
2512 end First_Actual;
2514 -------------------------
2515 -- Full_Qualified_Name --
2516 -------------------------
2518 function Full_Qualified_Name (E : Entity_Id) return String_Id is
2519 Res : String_Id;
2520 pragma Warnings (Off, Res);
2522 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id;
2523 -- Compute recursively the qualified name without NUL at the end
2525 ----------------------------------
2526 -- Internal_Full_Qualified_Name --
2527 ----------------------------------
2529 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id is
2530 Ent : Entity_Id := E;
2531 Parent_Name : String_Id := No_String;
2533 begin
2534 -- Deals properly with child units
2536 if Nkind (Ent) = N_Defining_Program_Unit_Name then
2537 Ent := Defining_Identifier (Ent);
2538 end if;
2540 -- Compute qualification recursively (only "Standard" has no scope)
2542 if Present (Scope (Scope (Ent))) then
2543 Parent_Name := Internal_Full_Qualified_Name (Scope (Ent));
2544 end if;
2546 -- Every entity should have a name except some expanded blocks
2547 -- don't bother about those.
2549 if Chars (Ent) = No_Name then
2550 return Parent_Name;
2551 end if;
2553 -- Add a period between Name and qualification
2555 if Parent_Name /= No_String then
2556 Start_String (Parent_Name);
2557 Store_String_Char (Get_Char_Code ('.'));
2559 else
2560 Start_String;
2561 end if;
2563 -- Generates the entity name in upper case
2565 Get_Decoded_Name_String (Chars (Ent));
2566 Set_All_Upper_Case;
2567 Store_String_Chars (Name_Buffer (1 .. Name_Len));
2568 return End_String;
2569 end Internal_Full_Qualified_Name;
2571 -- Start of processing for Full_Qualified_Name
2573 begin
2574 Res := Internal_Full_Qualified_Name (E);
2575 Store_String_Char (Get_Char_Code (ASCII.nul));
2576 return End_String;
2577 end Full_Qualified_Name;
2579 -----------------------
2580 -- Gather_Components --
2581 -----------------------
2583 procedure Gather_Components
2584 (Typ : Entity_Id;
2585 Comp_List : Node_Id;
2586 Governed_By : List_Id;
2587 Into : Elist_Id;
2588 Report_Errors : out Boolean)
2590 Assoc : Node_Id;
2591 Variant : Node_Id;
2592 Discrete_Choice : Node_Id;
2593 Comp_Item : Node_Id;
2595 Discrim : Entity_Id;
2596 Discrim_Name : Node_Id;
2597 Discrim_Value : Node_Id;
2599 begin
2600 Report_Errors := False;
2602 if No (Comp_List) or else Null_Present (Comp_List) then
2603 return;
2605 elsif Present (Component_Items (Comp_List)) then
2606 Comp_Item := First (Component_Items (Comp_List));
2608 else
2609 Comp_Item := Empty;
2610 end if;
2612 while Present (Comp_Item) loop
2614 -- Skip the tag of a tagged record, the interface tags, as well
2615 -- as all items that are not user components (anonymous types,
2616 -- rep clauses, Parent field, controller field).
2618 if Nkind (Comp_Item) = N_Component_Declaration then
2619 declare
2620 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
2621 begin
2622 if not Is_Tag (Comp)
2623 and then Chars (Comp) /= Name_uParent
2624 and then Chars (Comp) /= Name_uController
2625 then
2626 Append_Elmt (Comp, Into);
2627 end if;
2628 end;
2629 end if;
2631 Next (Comp_Item);
2632 end loop;
2634 if No (Variant_Part (Comp_List)) then
2635 return;
2636 else
2637 Discrim_Name := Name (Variant_Part (Comp_List));
2638 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
2639 end if;
2641 -- Look for the discriminant that governs this variant part.
2642 -- The discriminant *must* be in the Governed_By List
2644 Assoc := First (Governed_By);
2645 Find_Constraint : loop
2646 Discrim := First (Choices (Assoc));
2647 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
2648 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
2649 and then
2650 Chars (Corresponding_Discriminant (Entity (Discrim)))
2651 = Chars (Discrim_Name))
2652 or else Chars (Original_Record_Component (Entity (Discrim)))
2653 = Chars (Discrim_Name);
2655 if No (Next (Assoc)) then
2656 if not Is_Constrained (Typ)
2657 and then Is_Derived_Type (Typ)
2658 and then Present (Stored_Constraint (Typ))
2659 then
2660 -- If the type is a tagged type with inherited discriminants,
2661 -- use the stored constraint on the parent in order to find
2662 -- the values of discriminants that are otherwise hidden by an
2663 -- explicit constraint. Renamed discriminants are handled in
2664 -- the code above.
2666 -- If several parent discriminants are renamed by a single
2667 -- discriminant of the derived type, the call to obtain the
2668 -- Corresponding_Discriminant field only retrieves the last
2669 -- of them. We recover the constraint on the others from the
2670 -- Stored_Constraint as well.
2672 declare
2673 D : Entity_Id;
2674 C : Elmt_Id;
2676 begin
2677 D := First_Discriminant (Etype (Typ));
2678 C := First_Elmt (Stored_Constraint (Typ));
2679 while Present (D) and then Present (C) loop
2680 if Chars (Discrim_Name) = Chars (D) then
2681 if Is_Entity_Name (Node (C))
2682 and then Entity (Node (C)) = Entity (Discrim)
2683 then
2684 -- D is renamed by Discrim, whose value is given in
2685 -- Assoc.
2687 null;
2689 else
2690 Assoc :=
2691 Make_Component_Association (Sloc (Typ),
2692 New_List
2693 (New_Occurrence_Of (D, Sloc (Typ))),
2694 Duplicate_Subexpr_No_Checks (Node (C)));
2695 end if;
2696 exit Find_Constraint;
2697 end if;
2699 Next_Discriminant (D);
2700 Next_Elmt (C);
2701 end loop;
2702 end;
2703 end if;
2704 end if;
2706 if No (Next (Assoc)) then
2707 Error_Msg_NE (" missing value for discriminant&",
2708 First (Governed_By), Discrim_Name);
2709 Report_Errors := True;
2710 return;
2711 end if;
2713 Next (Assoc);
2714 end loop Find_Constraint;
2716 Discrim_Value := Expression (Assoc);
2718 if not Is_OK_Static_Expression (Discrim_Value) then
2719 Error_Msg_FE
2720 ("value for discriminant & must be static!",
2721 Discrim_Value, Discrim);
2722 Why_Not_Static (Discrim_Value);
2723 Report_Errors := True;
2724 return;
2725 end if;
2727 Search_For_Discriminant_Value : declare
2728 Low : Node_Id;
2729 High : Node_Id;
2731 UI_High : Uint;
2732 UI_Low : Uint;
2733 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
2735 begin
2736 Find_Discrete_Value : while Present (Variant) loop
2737 Discrete_Choice := First (Discrete_Choices (Variant));
2738 while Present (Discrete_Choice) loop
2740 exit Find_Discrete_Value when
2741 Nkind (Discrete_Choice) = N_Others_Choice;
2743 Get_Index_Bounds (Discrete_Choice, Low, High);
2745 UI_Low := Expr_Value (Low);
2746 UI_High := Expr_Value (High);
2748 exit Find_Discrete_Value when
2749 UI_Low <= UI_Discrim_Value
2750 and then
2751 UI_High >= UI_Discrim_Value;
2753 Next (Discrete_Choice);
2754 end loop;
2756 Next_Non_Pragma (Variant);
2757 end loop Find_Discrete_Value;
2758 end Search_For_Discriminant_Value;
2760 if No (Variant) then
2761 Error_Msg_NE
2762 ("value of discriminant & is out of range", Discrim_Value, Discrim);
2763 Report_Errors := True;
2764 return;
2765 end if;
2767 -- If we have found the corresponding choice, recursively add its
2768 -- components to the Into list.
2770 Gather_Components (Empty,
2771 Component_List (Variant), Governed_By, Into, Report_Errors);
2772 end Gather_Components;
2774 ------------------------
2775 -- Get_Actual_Subtype --
2776 ------------------------
2778 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
2779 Typ : constant Entity_Id := Etype (N);
2780 Utyp : Entity_Id := Underlying_Type (Typ);
2781 Decl : Node_Id;
2782 Atyp : Entity_Id;
2784 begin
2785 if No (Utyp) then
2786 Utyp := Typ;
2787 end if;
2789 -- If what we have is an identifier that references a subprogram
2790 -- formal, or a variable or constant object, then we get the actual
2791 -- subtype from the referenced entity if one has been built.
2793 if Nkind (N) = N_Identifier
2794 and then
2795 (Is_Formal (Entity (N))
2796 or else Ekind (Entity (N)) = E_Constant
2797 or else Ekind (Entity (N)) = E_Variable)
2798 and then Present (Actual_Subtype (Entity (N)))
2799 then
2800 return Actual_Subtype (Entity (N));
2802 -- Actual subtype of unchecked union is always itself. We never need
2803 -- the "real" actual subtype. If we did, we couldn't get it anyway
2804 -- because the discriminant is not available. The restrictions on
2805 -- Unchecked_Union are designed to make sure that this is OK.
2807 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
2808 return Typ;
2810 -- Here for the unconstrained case, we must find actual subtype
2811 -- No actual subtype is available, so we must build it on the fly.
2813 -- Checking the type, not the underlying type, for constrainedness
2814 -- seems to be necessary. Maybe all the tests should be on the type???
2816 elsif (not Is_Constrained (Typ))
2817 and then (Is_Array_Type (Utyp)
2818 or else (Is_Record_Type (Utyp)
2819 and then Has_Discriminants (Utyp)))
2820 and then not Has_Unknown_Discriminants (Utyp)
2821 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
2822 then
2823 -- Nothing to do if in default expression
2825 if In_Default_Expression then
2826 return Typ;
2828 elsif Is_Private_Type (Typ)
2829 and then not Has_Discriminants (Typ)
2830 then
2831 -- If the type has no discriminants, there is no subtype to
2832 -- build, even if the underlying type is discriminated.
2834 return Typ;
2836 -- Else build the actual subtype
2838 else
2839 Decl := Build_Actual_Subtype (Typ, N);
2840 Atyp := Defining_Identifier (Decl);
2842 -- If Build_Actual_Subtype generated a new declaration then use it
2844 if Atyp /= Typ then
2846 -- The actual subtype is an Itype, so analyze the declaration,
2847 -- but do not attach it to the tree, to get the type defined.
2849 Set_Parent (Decl, N);
2850 Set_Is_Itype (Atyp);
2851 Analyze (Decl, Suppress => All_Checks);
2852 Set_Associated_Node_For_Itype (Atyp, N);
2853 Set_Has_Delayed_Freeze (Atyp, False);
2855 -- We need to freeze the actual subtype immediately. This is
2856 -- needed, because otherwise this Itype will not get frozen
2857 -- at all, and it is always safe to freeze on creation because
2858 -- any associated types must be frozen at this point.
2860 Freeze_Itype (Atyp, N);
2861 return Atyp;
2863 -- Otherwise we did not build a declaration, so return original
2865 else
2866 return Typ;
2867 end if;
2868 end if;
2870 -- For all remaining cases, the actual subtype is the same as
2871 -- the nominal type.
2873 else
2874 return Typ;
2875 end if;
2876 end Get_Actual_Subtype;
2878 -------------------------------------
2879 -- Get_Actual_Subtype_If_Available --
2880 -------------------------------------
2882 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
2883 Typ : constant Entity_Id := Etype (N);
2885 begin
2886 -- If what we have is an identifier that references a subprogram
2887 -- formal, or a variable or constant object, then we get the actual
2888 -- subtype from the referenced entity if one has been built.
2890 if Nkind (N) = N_Identifier
2891 and then
2892 (Is_Formal (Entity (N))
2893 or else Ekind (Entity (N)) = E_Constant
2894 or else Ekind (Entity (N)) = E_Variable)
2895 and then Present (Actual_Subtype (Entity (N)))
2896 then
2897 return Actual_Subtype (Entity (N));
2899 -- Otherwise the Etype of N is returned unchanged
2901 else
2902 return Typ;
2903 end if;
2904 end Get_Actual_Subtype_If_Available;
2906 -------------------------------
2907 -- Get_Default_External_Name --
2908 -------------------------------
2910 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
2911 begin
2912 Get_Decoded_Name_String (Chars (E));
2914 if Opt.External_Name_Imp_Casing = Uppercase then
2915 Set_Casing (All_Upper_Case);
2916 else
2917 Set_Casing (All_Lower_Case);
2918 end if;
2920 return
2921 Make_String_Literal (Sloc (E),
2922 Strval => String_From_Name_Buffer);
2923 end Get_Default_External_Name;
2925 ---------------------------
2926 -- Get_Enum_Lit_From_Pos --
2927 ---------------------------
2929 function Get_Enum_Lit_From_Pos
2930 (T : Entity_Id;
2931 Pos : Uint;
2932 Loc : Source_Ptr) return Node_Id
2934 Lit : Node_Id;
2936 begin
2937 -- In the case where the literal is of type Character, Wide_Character
2938 -- or Wide_Wide_Character or of a type derived from them, there needs
2939 -- to be some special handling since there is no explicit chain of
2940 -- literals to search. Instead, an N_Character_Literal node is created
2941 -- with the appropriate Char_Code and Chars fields.
2943 if Root_Type (T) = Standard_Character
2944 or else Root_Type (T) = Standard_Wide_Character
2945 or else Root_Type (T) = Standard_Wide_Wide_Character
2946 then
2947 Set_Character_Literal_Name (UI_To_CC (Pos));
2948 return
2949 Make_Character_Literal (Loc,
2950 Chars => Name_Find,
2951 Char_Literal_Value => Pos);
2953 -- For all other cases, we have a complete table of literals, and
2954 -- we simply iterate through the chain of literal until the one
2955 -- with the desired position value is found.
2958 else
2959 Lit := First_Literal (Base_Type (T));
2960 for J in 1 .. UI_To_Int (Pos) loop
2961 Next_Literal (Lit);
2962 end loop;
2964 return New_Occurrence_Of (Lit, Loc);
2965 end if;
2966 end Get_Enum_Lit_From_Pos;
2968 ------------------------
2969 -- Get_Generic_Entity --
2970 ------------------------
2972 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
2973 Ent : constant Entity_Id := Entity (Name (N));
2974 begin
2975 if Present (Renamed_Object (Ent)) then
2976 return Renamed_Object (Ent);
2977 else
2978 return Ent;
2979 end if;
2980 end Get_Generic_Entity;
2982 ----------------------
2983 -- Get_Index_Bounds --
2984 ----------------------
2986 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
2987 Kind : constant Node_Kind := Nkind (N);
2988 R : Node_Id;
2990 begin
2991 if Kind = N_Range then
2992 L := Low_Bound (N);
2993 H := High_Bound (N);
2995 elsif Kind = N_Subtype_Indication then
2996 R := Range_Expression (Constraint (N));
2998 if R = Error then
2999 L := Error;
3000 H := Error;
3001 return;
3003 else
3004 L := Low_Bound (Range_Expression (Constraint (N)));
3005 H := High_Bound (Range_Expression (Constraint (N)));
3006 end if;
3008 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
3009 if Error_Posted (Scalar_Range (Entity (N))) then
3010 L := Error;
3011 H := Error;
3013 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
3014 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
3016 else
3017 L := Low_Bound (Scalar_Range (Entity (N)));
3018 H := High_Bound (Scalar_Range (Entity (N)));
3019 end if;
3021 else
3022 -- N is an expression, indicating a range with one value
3024 L := N;
3025 H := N;
3026 end if;
3027 end Get_Index_Bounds;
3029 ----------------------------------
3030 -- Get_Library_Unit_Name_string --
3031 ----------------------------------
3033 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
3034 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
3036 begin
3037 Get_Unit_Name_String (Unit_Name_Id);
3039 -- Remove seven last character (" (spec)" or " (body)")
3041 Name_Len := Name_Len - 7;
3042 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
3043 end Get_Library_Unit_Name_String;
3045 ------------------------
3046 -- Get_Name_Entity_Id --
3047 ------------------------
3049 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
3050 begin
3051 return Entity_Id (Get_Name_Table_Info (Id));
3052 end Get_Name_Entity_Id;
3054 ---------------------------
3055 -- Get_Subprogram_Entity --
3056 ---------------------------
3058 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
3059 Nam : Node_Id;
3060 Proc : Entity_Id;
3062 begin
3063 if Nkind (Nod) = N_Accept_Statement then
3064 Nam := Entry_Direct_Name (Nod);
3065 else
3066 Nam := Name (Nod);
3067 end if;
3069 if Nkind (Nam) = N_Explicit_Dereference then
3070 Proc := Etype (Prefix (Nam));
3071 elsif Is_Entity_Name (Nam) then
3072 Proc := Entity (Nam);
3073 else
3074 return Empty;
3075 end if;
3077 if Is_Object (Proc) then
3078 Proc := Etype (Proc);
3079 end if;
3081 if Ekind (Proc) = E_Access_Subprogram_Type then
3082 Proc := Directly_Designated_Type (Proc);
3083 end if;
3085 if not Is_Subprogram (Proc)
3086 and then Ekind (Proc) /= E_Subprogram_Type
3087 then
3088 return Empty;
3089 else
3090 return Proc;
3091 end if;
3092 end Get_Subprogram_Entity;
3094 ---------------------------
3095 -- Get_Referenced_Object --
3096 ---------------------------
3098 function Get_Referenced_Object (N : Node_Id) return Node_Id is
3099 R : Node_Id;
3101 begin
3102 R := N;
3103 while Is_Entity_Name (R)
3104 and then Present (Renamed_Object (Entity (R)))
3105 loop
3106 R := Renamed_Object (Entity (R));
3107 end loop;
3109 return R;
3110 end Get_Referenced_Object;
3112 -------------------------
3113 -- Get_Subprogram_Body --
3114 -------------------------
3116 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
3117 Decl : Node_Id;
3119 begin
3120 Decl := Unit_Declaration_Node (E);
3122 if Nkind (Decl) = N_Subprogram_Body then
3123 return Decl;
3125 -- The below comment is bad, because it is possible for
3126 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
3128 else -- Nkind (Decl) = N_Subprogram_Declaration
3130 if Present (Corresponding_Body (Decl)) then
3131 return Unit_Declaration_Node (Corresponding_Body (Decl));
3133 -- Imported subprogram case
3135 else
3136 return Empty;
3137 end if;
3138 end if;
3139 end Get_Subprogram_Body;
3141 -----------------------------
3142 -- Get_Task_Body_Procedure --
3143 -----------------------------
3145 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
3146 begin
3147 -- Note: A task type may be the completion of a private type with
3148 -- discriminants. when performing elaboration checks on a task
3149 -- declaration, the current view of the type may be the private one,
3150 -- and the procedure that holds the body of the task is held in its
3151 -- underlying type.
3153 -- This is an odd function, why not have Task_Body_Procedure do
3154 -- the following digging???
3156 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
3157 end Get_Task_Body_Procedure;
3159 -----------------------------
3160 -- Has_Abstract_Interfaces --
3161 -----------------------------
3163 function Has_Abstract_Interfaces (Tagged_Type : Entity_Id) return Boolean is
3164 Typ : Entity_Id;
3166 begin
3167 pragma Assert (Is_Record_Type (Tagged_Type)
3168 and then Is_Tagged_Type (Tagged_Type));
3170 -- Handle private types
3172 if Present (Full_View (Tagged_Type)) then
3173 Typ := Full_View (Tagged_Type);
3174 else
3175 Typ := Tagged_Type;
3176 end if;
3178 loop
3179 if Is_Interface (Typ)
3180 or else (Present (Abstract_Interfaces (Typ))
3181 and then
3182 not Is_Empty_Elmt_List (Abstract_Interfaces (Typ)))
3183 then
3184 return True;
3185 end if;
3187 exit when Etype (Typ) = Typ
3189 -- Handle private types
3191 or else (Present (Full_View (Etype (Typ)))
3192 and then Full_View (Etype (Typ)) = Typ)
3194 -- Protect the frontend against wrong source with cyclic
3195 -- derivations
3197 or else Etype (Typ) = Tagged_Type;
3199 -- Climb to the ancestor type handling private types
3201 if Present (Full_View (Etype (Typ))) then
3202 Typ := Full_View (Etype (Typ));
3203 else
3204 Typ := Etype (Typ);
3205 end if;
3206 end loop;
3208 return False;
3209 end Has_Abstract_Interfaces;
3211 -----------------------
3212 -- Has_Access_Values --
3213 -----------------------
3215 function Has_Access_Values (T : Entity_Id) return Boolean is
3216 Typ : constant Entity_Id := Underlying_Type (T);
3218 begin
3219 -- Case of a private type which is not completed yet. This can only
3220 -- happen in the case of a generic format type appearing directly, or
3221 -- as a component of the type to which this function is being applied
3222 -- at the top level. Return False in this case, since we certainly do
3223 -- not know that the type contains access types.
3225 if No (Typ) then
3226 return False;
3228 elsif Is_Access_Type (Typ) then
3229 return True;
3231 elsif Is_Array_Type (Typ) then
3232 return Has_Access_Values (Component_Type (Typ));
3234 elsif Is_Record_Type (Typ) then
3235 declare
3236 Comp : Entity_Id;
3238 begin
3239 Comp := First_Entity (Typ);
3240 while Present (Comp) loop
3241 if (Ekind (Comp) = E_Component
3242 or else
3243 Ekind (Comp) = E_Discriminant)
3244 and then Has_Access_Values (Etype (Comp))
3245 then
3246 return True;
3247 end if;
3249 Next_Entity (Comp);
3250 end loop;
3251 end;
3253 return False;
3255 else
3256 return False;
3257 end if;
3258 end Has_Access_Values;
3260 ------------------------------
3261 -- Has_Compatible_Alignment --
3262 ------------------------------
3264 function Has_Compatible_Alignment
3265 (Obj : Entity_Id;
3266 Expr : Node_Id) return Alignment_Result
3268 function Has_Compatible_Alignment_Internal
3269 (Obj : Entity_Id;
3270 Expr : Node_Id;
3271 Default : Alignment_Result) return Alignment_Result;
3272 -- This is the internal recursive function that actually does the work.
3273 -- There is one additional parameter, which says what the result should
3274 -- be if no alignment information is found, and there is no definite
3275 -- indication of compatible alignments. At the outer level, this is set
3276 -- to Unknown, but for internal recursive calls in the case where types
3277 -- are known to be correct, it is set to Known_Compatible.
3279 ---------------------------------------
3280 -- Has_Compatible_Alignment_Internal --
3281 ---------------------------------------
3283 function Has_Compatible_Alignment_Internal
3284 (Obj : Entity_Id;
3285 Expr : Node_Id;
3286 Default : Alignment_Result) return Alignment_Result
3288 Result : Alignment_Result := Known_Compatible;
3289 -- Set to result if Problem_Prefix or Problem_Offset returns True.
3290 -- Note that once a value of Known_Incompatible is set, it is sticky
3291 -- and does not get changed to Unknown (the value in Result only gets
3292 -- worse as we go along, never better).
3294 procedure Check_Offset (Offs : Uint);
3295 -- Called when Expr is a selected or indexed component with Offs set
3296 -- to resp Component_First_Bit or Component_Size. Checks that if the
3297 -- offset is specified it is compatible with the object alignment
3298 -- requirements. The value in Result is modified accordingly.
3300 procedure Check_Prefix;
3301 -- Checks the prefix recursively in the case where the expression
3302 -- is an indexed or selected component.
3304 procedure Set_Result (R : Alignment_Result);
3305 -- If R represents a worse outcome (unknown instead of known
3306 -- compatible, or known incompatible), then set Result to R.
3308 ------------------
3309 -- Check_Offset --
3310 ------------------
3312 procedure Check_Offset (Offs : Uint) is
3313 begin
3314 -- Unspecified or zero offset is always OK
3316 if Offs = No_Uint or else Offs = Uint_0 then
3317 null;
3319 -- If we do not know required alignment, any non-zero offset is
3320 -- a potential problem (but certainly may be OK, so result is
3321 -- unknown).
3323 elsif Unknown_Alignment (Obj) then
3324 Set_Result (Unknown);
3326 -- If we know the required alignment, see if offset is compatible
3328 else
3329 if Offs mod (System_Storage_Unit * Alignment (Obj)) /= 0 then
3330 Set_Result (Known_Incompatible);
3331 end if;
3332 end if;
3333 end Check_Offset;
3335 ------------------
3336 -- Check_Prefix --
3337 ------------------
3339 procedure Check_Prefix is
3340 begin
3341 -- The subtlety here is that in doing a recursive call to check
3342 -- the prefix, we have to decide what to do in the case where we
3343 -- don't find any specific indication of an alignment problem.
3345 -- At the outer level, we normally set Unknown as the result in
3346 -- this case, since we can only set Known_Compatible if we really
3347 -- know that the alignment value is OK, but for the recursive
3348 -- call, in the case where the types match, and we have not
3349 -- specified a peculiar alignment for the object, we are only
3350 -- concerned about suspicious rep clauses, the default case does
3351 -- not affect us, since the compiler will, in the absence of such
3352 -- rep clauses, ensure that the alignment is correct.
3354 if Default = Known_Compatible
3355 or else
3356 (Etype (Obj) = Etype (Expr)
3357 and then (Unknown_Alignment (Obj)
3358 or else
3359 Alignment (Obj) = Alignment (Etype (Obj))))
3360 then
3361 Set_Result
3362 (Has_Compatible_Alignment_Internal
3363 (Obj, Prefix (Expr), Known_Compatible));
3365 -- In all other cases, we need a full check on the prefix
3367 else
3368 Set_Result
3369 (Has_Compatible_Alignment_Internal
3370 (Obj, Prefix (Expr), Unknown));
3371 end if;
3372 end Check_Prefix;
3374 ----------------
3375 -- Set_Result --
3376 ----------------
3378 procedure Set_Result (R : Alignment_Result) is
3379 begin
3380 if R > Result then
3381 Result := R;
3382 end if;
3383 end Set_Result;
3385 -- Start of processing for Has_Compatible_Alignment_Internal
3387 begin
3388 -- If Expr is a selected component, we must make sure there is no
3389 -- potentially troublesome component clause, and that the record is
3390 -- not packed.
3392 if Nkind (Expr) = N_Selected_Component then
3394 -- Packed record always generate unknown alignment
3396 if Is_Packed (Etype (Prefix (Expr))) then
3397 Set_Result (Unknown);
3398 end if;
3400 -- Check possible bad component offset and check prefix
3402 Check_Offset
3403 (Component_Bit_Offset (Entity (Selector_Name (Expr))));
3404 Check_Prefix;
3406 -- If Expr is an indexed component, we must make sure there is no
3407 -- potentially troublesome Component_Size clause and that the array
3408 -- is not bit-packed.
3410 elsif Nkind (Expr) = N_Indexed_Component then
3412 -- Bit packed array always generates unknown alignment
3414 if Is_Bit_Packed_Array (Etype (Prefix (Expr))) then
3415 Set_Result (Unknown);
3416 end if;
3418 -- Check possible bad component size and check prefix
3420 Check_Offset (Component_Size (Etype (Prefix (Expr))));
3421 Check_Prefix;
3422 end if;
3424 -- Case where we know the alignment of the object
3426 if Known_Alignment (Obj) then
3427 declare
3428 ObjA : constant Uint := Alignment (Obj);
3429 ExpA : Uint := No_Uint;
3430 SizA : Uint := No_Uint;
3432 begin
3433 -- If alignment of Obj is 1, then we are always OK
3435 if ObjA = 1 then
3436 Set_Result (Known_Compatible);
3438 -- Alignment of Obj is greater than 1, so we need to check
3440 else
3441 -- See if Expr is an object with known alignment
3443 if Is_Entity_Name (Expr)
3444 and then Known_Alignment (Entity (Expr))
3445 then
3446 ExpA := Alignment (Entity (Expr));
3448 -- Otherwise, we can use the alignment of the type of
3449 -- Expr given that we already checked for
3450 -- discombobulating rep clauses for the cases of indexed
3451 -- and selected components above.
3453 elsif Known_Alignment (Etype (Expr)) then
3454 ExpA := Alignment (Etype (Expr));
3455 end if;
3457 -- If we got an alignment, see if it is acceptable
3459 if ExpA /= No_Uint then
3460 if ExpA < ObjA then
3461 Set_Result (Known_Incompatible);
3462 end if;
3464 -- Case of Expr alignment unknown
3466 else
3467 Set_Result (Default);
3468 end if;
3470 -- See if size is given. If so, check that it is not too
3471 -- small for the required alignment.
3472 -- See if Expr is an object with known alignment
3474 if Is_Entity_Name (Expr)
3475 and then Known_Static_Esize (Entity (Expr))
3476 then
3477 SizA := Esize (Entity (Expr));
3479 -- Otherwise, we check the object size of the Expr type
3481 elsif Known_Static_Esize (Etype (Expr)) then
3482 SizA := Esize (Etype (Expr));
3483 end if;
3485 -- If we got a size, see if it is a multiple of the Obj
3486 -- alignment, if not, then the alignment cannot be
3487 -- acceptable, since the size is always a multiple of the
3488 -- alignment.
3490 if SizA /= No_Uint then
3491 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
3492 Set_Result (Known_Incompatible);
3493 end if;
3494 end if;
3495 end if;
3496 end;
3498 -- If we can't find the result by direct comparison of alignment
3499 -- values, then there is still one case that we can determine known
3500 -- result, and that is when we can determine that the types are the
3501 -- same, and no alignments are specified. Then we known that the
3502 -- alignments are compatible, even if we don't know the alignment
3503 -- value in the front end.
3505 elsif Etype (Obj) = Etype (Expr) then
3507 -- Types are the same, but we have to check for possible size
3508 -- and alignments on the Expr object that may make the alignment
3509 -- different, even though the types are the same.
3511 if Is_Entity_Name (Expr) then
3513 -- First check alignment of the Expr object. Any alignment less
3514 -- than Maximum_Alignment is worrisome since this is the case
3515 -- where we do not know the alignment of Obj.
3517 if Known_Alignment (Entity (Expr))
3518 and then
3519 UI_To_Int (Alignment (Entity (Expr)))
3520 < Ttypes.Maximum_Alignment
3521 then
3522 Set_Result (Unknown);
3524 -- Now check size of Expr object. Any size that is not an
3525 -- even multiple of Maxiumum_Alignment is also worrisome
3526 -- since it may cause the alignment of the object to be less
3527 -- than the alignment of the type.
3529 elsif Known_Static_Esize (Entity (Expr))
3530 and then
3531 (UI_To_Int (Esize (Entity (Expr))) mod
3532 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
3533 /= 0
3534 then
3535 Set_Result (Unknown);
3537 -- Otherwise same type is decisive
3539 else
3540 Set_Result (Known_Compatible);
3541 end if;
3542 end if;
3544 -- Another case to deal with is when there is an explicit size or
3545 -- alignment clause when the types are not the same. If so, then the
3546 -- result is Unknown. We don't need to do this test if the Default is
3547 -- Unknown, since that result will be set in any case.
3549 elsif Default /= Unknown
3550 and then (Has_Size_Clause (Etype (Expr))
3551 or else
3552 Has_Alignment_Clause (Etype (Expr)))
3553 then
3554 Set_Result (Unknown);
3556 -- If no indication found, set default
3558 else
3559 Set_Result (Default);
3560 end if;
3562 -- Return worst result found
3564 return Result;
3565 end Has_Compatible_Alignment_Internal;
3567 -- Start of processing for Has_Compatible_Alignment
3569 begin
3570 -- If Obj has no specified alignment, then set alignment from the type
3571 -- alignment. Perhaps we should always do this, but for sure we should
3572 -- do it when there is an address clause since we can do more if the
3573 -- alignment is known.
3575 if Unknown_Alignment (Obj) then
3576 Set_Alignment (Obj, Alignment (Etype (Obj)));
3577 end if;
3579 -- Now do the internal call that does all the work
3581 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
3582 end Has_Compatible_Alignment;
3584 ----------------------
3585 -- Has_Declarations --
3586 ----------------------
3588 function Has_Declarations (N : Node_Id) return Boolean is
3589 K : constant Node_Kind := Nkind (N);
3590 begin
3591 return K = N_Accept_Statement
3592 or else K = N_Block_Statement
3593 or else K = N_Compilation_Unit_Aux
3594 or else K = N_Entry_Body
3595 or else K = N_Package_Body
3596 or else K = N_Protected_Body
3597 or else K = N_Subprogram_Body
3598 or else K = N_Task_Body
3599 or else K = N_Package_Specification;
3600 end Has_Declarations;
3602 -------------------------------------------
3603 -- Has_Discriminant_Dependent_Constraint --
3604 -------------------------------------------
3606 function Has_Discriminant_Dependent_Constraint
3607 (Comp : Entity_Id) return Boolean
3609 Comp_Decl : constant Node_Id := Parent (Comp);
3610 Subt_Indic : constant Node_Id :=
3611 Subtype_Indication (Component_Definition (Comp_Decl));
3612 Constr : Node_Id;
3613 Assn : Node_Id;
3615 begin
3616 if Nkind (Subt_Indic) = N_Subtype_Indication then
3617 Constr := Constraint (Subt_Indic);
3619 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
3620 Assn := First (Constraints (Constr));
3621 while Present (Assn) loop
3622 case Nkind (Assn) is
3623 when N_Subtype_Indication |
3624 N_Range |
3625 N_Identifier
3627 if Depends_On_Discriminant (Assn) then
3628 return True;
3629 end if;
3631 when N_Discriminant_Association =>
3632 if Depends_On_Discriminant (Expression (Assn)) then
3633 return True;
3634 end if;
3636 when others =>
3637 null;
3639 end case;
3641 Next (Assn);
3642 end loop;
3643 end if;
3644 end if;
3646 return False;
3647 end Has_Discriminant_Dependent_Constraint;
3649 --------------------
3650 -- Has_Infinities --
3651 --------------------
3653 function Has_Infinities (E : Entity_Id) return Boolean is
3654 begin
3655 return
3656 Is_Floating_Point_Type (E)
3657 and then Nkind (Scalar_Range (E)) = N_Range
3658 and then Includes_Infinities (Scalar_Range (E));
3659 end Has_Infinities;
3661 ------------------------
3662 -- Has_Null_Exclusion --
3663 ------------------------
3665 function Has_Null_Exclusion (N : Node_Id) return Boolean is
3666 begin
3667 case Nkind (N) is
3668 when N_Access_Definition |
3669 N_Access_Function_Definition |
3670 N_Access_Procedure_Definition |
3671 N_Access_To_Object_Definition |
3672 N_Allocator |
3673 N_Derived_Type_Definition |
3674 N_Function_Specification |
3675 N_Subtype_Declaration =>
3676 return Null_Exclusion_Present (N);
3678 when N_Component_Definition |
3679 N_Formal_Object_Declaration |
3680 N_Object_Renaming_Declaration =>
3681 if Present (Subtype_Mark (N)) then
3682 return Null_Exclusion_Present (N);
3683 else pragma Assert (Present (Access_Definition (N)));
3684 return Null_Exclusion_Present (Access_Definition (N));
3685 end if;
3687 when N_Discriminant_Specification =>
3688 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
3689 return Null_Exclusion_Present (Discriminant_Type (N));
3690 else
3691 return Null_Exclusion_Present (N);
3692 end if;
3694 when N_Object_Declaration =>
3695 if Nkind (Object_Definition (N)) = N_Access_Definition then
3696 return Null_Exclusion_Present (Object_Definition (N));
3697 else
3698 return Null_Exclusion_Present (N);
3699 end if;
3701 when N_Parameter_Specification =>
3702 if Nkind (Parameter_Type (N)) = N_Access_Definition then
3703 return Null_Exclusion_Present (Parameter_Type (N));
3704 else
3705 return Null_Exclusion_Present (N);
3706 end if;
3708 when others =>
3709 return False;
3711 end case;
3712 end Has_Null_Exclusion;
3714 ------------------------
3715 -- Has_Null_Extension --
3716 ------------------------
3718 function Has_Null_Extension (T : Entity_Id) return Boolean is
3719 B : constant Entity_Id := Base_Type (T);
3720 Comps : Node_Id;
3721 Ext : Node_Id;
3723 begin
3724 if Nkind (Parent (B)) = N_Full_Type_Declaration
3725 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
3726 then
3727 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
3729 if Present (Ext) then
3730 if Null_Present (Ext) then
3731 return True;
3732 else
3733 Comps := Component_List (Ext);
3735 -- The null component list is rewritten during analysis to
3736 -- include the parent component. Any other component indicates
3737 -- that the extension was not originally null.
3739 return Null_Present (Comps)
3740 or else No (Next (First (Component_Items (Comps))));
3741 end if;
3742 else
3743 return False;
3744 end if;
3746 else
3747 return False;
3748 end if;
3749 end Has_Null_Extension;
3751 --------------------------------------
3752 -- Has_Preelaborable_Initialization --
3753 --------------------------------------
3755 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
3756 Has_PE : Boolean;
3758 procedure Check_Components (E : Entity_Id);
3759 -- Check component/discriminant chain, sets Has_PE False if a component
3760 -- or discriminant does not meet the preelaborable initialization rules.
3762 ----------------------
3763 -- Check_Components --
3764 ----------------------
3766 procedure Check_Components (E : Entity_Id) is
3767 Ent : Entity_Id;
3768 Exp : Node_Id;
3770 begin
3771 -- Loop through entities of record or protected type
3773 Ent := E;
3774 while Present (Ent) loop
3776 -- We are interested only in components and discriminants
3778 if Ekind (Ent) = E_Component
3779 or else
3780 Ekind (Ent) = E_Discriminant
3781 then
3782 -- Get default expression if any. If there is no declaration
3783 -- node, it means we have an internal entity. The parent and
3784 -- tag fields are examples of such entitires. For these
3785 -- cases, we just test the type of the entity.
3787 if Present (Declaration_Node (Ent)) then
3788 Exp := Expression (Declaration_Node (Ent));
3789 else
3790 Exp := Empty;
3791 end if;
3793 -- A component has PI if it has no default expression and
3794 -- the component type has PI.
3796 if No (Exp) then
3797 if not Has_Preelaborable_Initialization (Etype (Ent)) then
3798 Has_PE := False;
3799 exit;
3800 end if;
3802 -- Or if expression obeys rules for preelaboration. For
3803 -- now we approximate this by testing if the default
3804 -- expression is a static expression or if it is an
3805 -- access attribute reference.
3807 -- This is an approximation, it is probably incomplete???
3809 elsif Is_Static_Expression (Exp) then
3810 null;
3812 elsif Nkind (Exp) = N_Attribute_Reference
3813 and then (Attribute_Name (Exp) = Name_Access
3814 or else
3815 Attribute_Name (Exp) = Name_Unchecked_Access
3816 or else
3817 Attribute_Name (Exp) = Name_Unrestricted_Access)
3818 then
3819 null;
3821 else
3822 Has_PE := False;
3823 exit;
3824 end if;
3825 end if;
3827 Next_Entity (Ent);
3828 end loop;
3829 end Check_Components;
3831 -- Start of processing for Has_Preelaborable_Initialization
3833 begin
3834 -- Immediate return if already marked as known preelaborable init
3836 if Known_To_Have_Preelab_Init (E) then
3837 return True;
3838 end if;
3840 -- All elementary types have preelaborable initialization
3842 if Is_Elementary_Type (E) then
3843 Has_PE := True;
3845 -- Array types have PI if the component type has PI
3847 elsif Is_Array_Type (E) then
3848 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
3850 -- Record types have PI if all components have PI
3852 elsif Is_Record_Type (E) then
3853 Has_PE := True;
3854 Check_Components (First_Entity (E));
3856 -- Another check here, if this is a controlled type, see if it has a
3857 -- user defined Initialize procedure. If so, then there is a special
3858 -- rule that means this type does not have PI.
3860 if Is_Controlled (E)
3861 and then Present (Primitive_Operations (E))
3862 then
3863 declare
3864 P : Elmt_Id;
3866 begin
3867 P := First_Elmt (Primitive_Operations (E));
3868 while Present (P) loop
3869 if Chars (Node (P)) = Name_Initialize
3870 and then Comes_From_Source (Node (P))
3871 then
3872 Has_PE := False;
3873 exit;
3874 end if;
3876 Next_Elmt (P);
3877 end loop;
3878 end;
3879 end if;
3881 -- Protected types, must not have entries, and components must meet
3882 -- same set of rules as for record components.
3884 elsif Is_Protected_Type (E) then
3885 if Has_Entries (E) then
3886 Has_PE := False;
3887 else
3888 Has_PE := True;
3889 Check_Components (First_Entity (E));
3890 Check_Components (First_Private_Entity (E));
3891 end if;
3893 -- A derived type has preelaborable initialization if its parent type
3894 -- has preelaborable initialization and (in the case of a derived record
3895 -- extension) if the non-inherited components all have preelaborable
3896 -- initialization. However, a user-defined controlled type with an
3897 -- overriding Initialize procedure does not have preelaborable
3898 -- initialization.
3900 -- TBD ???
3902 -- Type System.Address always has preelaborable initialization
3904 elsif Is_RTE (E, RE_Address) then
3905 Has_PE := True;
3907 -- In all other cases, type does not have preelaborable init
3909 else
3910 return False;
3911 end if;
3913 if Has_PE then
3914 Set_Known_To_Have_Preelab_Init (E);
3915 end if;
3917 return Has_PE;
3918 end Has_Preelaborable_Initialization;
3920 ---------------------------
3921 -- Has_Private_Component --
3922 ---------------------------
3924 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
3925 Btype : Entity_Id := Base_Type (Type_Id);
3926 Component : Entity_Id;
3928 begin
3929 if Error_Posted (Type_Id)
3930 or else Error_Posted (Btype)
3931 then
3932 return False;
3933 end if;
3935 if Is_Class_Wide_Type (Btype) then
3936 Btype := Root_Type (Btype);
3937 end if;
3939 if Is_Private_Type (Btype) then
3940 declare
3941 UT : constant Entity_Id := Underlying_Type (Btype);
3942 begin
3943 if No (UT) then
3945 if No (Full_View (Btype)) then
3946 return not Is_Generic_Type (Btype)
3947 and then not Is_Generic_Type (Root_Type (Btype));
3949 else
3950 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
3951 end if;
3953 else
3954 return not Is_Frozen (UT) and then Has_Private_Component (UT);
3955 end if;
3956 end;
3957 elsif Is_Array_Type (Btype) then
3958 return Has_Private_Component (Component_Type (Btype));
3960 elsif Is_Record_Type (Btype) then
3962 Component := First_Component (Btype);
3963 while Present (Component) loop
3964 if Has_Private_Component (Etype (Component)) then
3965 return True;
3966 end if;
3968 Next_Component (Component);
3969 end loop;
3971 return False;
3973 elsif Is_Protected_Type (Btype)
3974 and then Present (Corresponding_Record_Type (Btype))
3975 then
3976 return Has_Private_Component (Corresponding_Record_Type (Btype));
3978 else
3979 return False;
3980 end if;
3981 end Has_Private_Component;
3983 ----------------
3984 -- Has_Stream --
3985 ----------------
3987 function Has_Stream (T : Entity_Id) return Boolean is
3988 E : Entity_Id;
3990 begin
3991 if No (T) then
3992 return False;
3994 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
3995 return True;
3997 elsif Is_Array_Type (T) then
3998 return Has_Stream (Component_Type (T));
4000 elsif Is_Record_Type (T) then
4001 E := First_Component (T);
4002 while Present (E) loop
4003 if Has_Stream (Etype (E)) then
4004 return True;
4005 else
4006 Next_Component (E);
4007 end if;
4008 end loop;
4010 return False;
4012 elsif Is_Private_Type (T) then
4013 return Has_Stream (Underlying_Type (T));
4015 else
4016 return False;
4017 end if;
4018 end Has_Stream;
4020 --------------------------
4021 -- Has_Tagged_Component --
4022 --------------------------
4024 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
4025 Comp : Entity_Id;
4027 begin
4028 if Is_Private_Type (Typ)
4029 and then Present (Underlying_Type (Typ))
4030 then
4031 return Has_Tagged_Component (Underlying_Type (Typ));
4033 elsif Is_Array_Type (Typ) then
4034 return Has_Tagged_Component (Component_Type (Typ));
4036 elsif Is_Tagged_Type (Typ) then
4037 return True;
4039 elsif Is_Record_Type (Typ) then
4040 Comp := First_Component (Typ);
4041 while Present (Comp) loop
4042 if Has_Tagged_Component (Etype (Comp)) then
4043 return True;
4044 end if;
4046 Comp := Next_Component (Typ);
4047 end loop;
4049 return False;
4051 else
4052 return False;
4053 end if;
4054 end Has_Tagged_Component;
4056 -----------------
4057 -- In_Instance --
4058 -----------------
4060 function In_Instance return Boolean is
4061 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
4062 S : Entity_Id;
4064 begin
4065 S := Current_Scope;
4066 while Present (S)
4067 and then S /= Standard_Standard
4068 loop
4069 if (Ekind (S) = E_Function
4070 or else Ekind (S) = E_Package
4071 or else Ekind (S) = E_Procedure)
4072 and then Is_Generic_Instance (S)
4073 then
4075 -- A child instance is always compiled in the context of a parent
4076 -- instance. Nevertheless, the actuals are not analyzed in an
4077 -- instance context. We detect this case by examining the current
4078 -- compilation unit, which must be a child instance, and checking
4079 -- that it is not currently on the scope stack.
4081 if Is_Child_Unit (Curr_Unit)
4082 and then
4083 Nkind (Unit (Cunit (Current_Sem_Unit)))
4084 = N_Package_Instantiation
4085 and then not In_Open_Scopes (Curr_Unit)
4086 then
4087 return False;
4088 else
4089 return True;
4090 end if;
4091 end if;
4093 S := Scope (S);
4094 end loop;
4096 return False;
4097 end In_Instance;
4099 ----------------------
4100 -- In_Instance_Body --
4101 ----------------------
4103 function In_Instance_Body return Boolean is
4104 S : Entity_Id;
4106 begin
4107 S := Current_Scope;
4108 while Present (S)
4109 and then S /= Standard_Standard
4110 loop
4111 if (Ekind (S) = E_Function
4112 or else Ekind (S) = E_Procedure)
4113 and then Is_Generic_Instance (S)
4114 then
4115 return True;
4117 elsif Ekind (S) = E_Package
4118 and then In_Package_Body (S)
4119 and then Is_Generic_Instance (S)
4120 then
4121 return True;
4122 end if;
4124 S := Scope (S);
4125 end loop;
4127 return False;
4128 end In_Instance_Body;
4130 -----------------------------
4131 -- In_Instance_Not_Visible --
4132 -----------------------------
4134 function In_Instance_Not_Visible return Boolean is
4135 S : Entity_Id;
4137 begin
4138 S := Current_Scope;
4139 while Present (S)
4140 and then S /= Standard_Standard
4141 loop
4142 if (Ekind (S) = E_Function
4143 or else Ekind (S) = E_Procedure)
4144 and then Is_Generic_Instance (S)
4145 then
4146 return True;
4148 elsif Ekind (S) = E_Package
4149 and then (In_Package_Body (S) or else In_Private_Part (S))
4150 and then Is_Generic_Instance (S)
4151 then
4152 return True;
4153 end if;
4155 S := Scope (S);
4156 end loop;
4158 return False;
4159 end In_Instance_Not_Visible;
4161 ------------------------------
4162 -- In_Instance_Visible_Part --
4163 ------------------------------
4165 function In_Instance_Visible_Part return Boolean is
4166 S : Entity_Id;
4168 begin
4169 S := Current_Scope;
4170 while Present (S)
4171 and then S /= Standard_Standard
4172 loop
4173 if Ekind (S) = E_Package
4174 and then Is_Generic_Instance (S)
4175 and then not In_Package_Body (S)
4176 and then not In_Private_Part (S)
4177 then
4178 return True;
4179 end if;
4181 S := Scope (S);
4182 end loop;
4184 return False;
4185 end In_Instance_Visible_Part;
4187 ----------------------
4188 -- In_Packiage_Body --
4189 ----------------------
4191 function In_Package_Body return Boolean is
4192 S : Entity_Id;
4194 begin
4195 S := Current_Scope;
4196 while Present (S)
4197 and then S /= Standard_Standard
4198 loop
4199 if Ekind (S) = E_Package
4200 and then In_Package_Body (S)
4201 then
4202 return True;
4203 else
4204 S := Scope (S);
4205 end if;
4206 end loop;
4208 return False;
4209 end In_Package_Body;
4211 --------------------------------------
4212 -- In_Subprogram_Or_Concurrent_Unit --
4213 --------------------------------------
4215 function In_Subprogram_Or_Concurrent_Unit return Boolean is
4216 E : Entity_Id;
4217 K : Entity_Kind;
4219 begin
4220 -- Use scope chain to check successively outer scopes
4222 E := Current_Scope;
4223 loop
4224 K := Ekind (E);
4226 if K in Subprogram_Kind
4227 or else K in Concurrent_Kind
4228 or else K in Generic_Subprogram_Kind
4229 then
4230 return True;
4232 elsif E = Standard_Standard then
4233 return False;
4234 end if;
4236 E := Scope (E);
4237 end loop;
4238 end In_Subprogram_Or_Concurrent_Unit;
4240 ---------------------
4241 -- In_Visible_Part --
4242 ---------------------
4244 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
4245 begin
4246 return
4247 Is_Package_Or_Generic_Package (Scope_Id)
4248 and then In_Open_Scopes (Scope_Id)
4249 and then not In_Package_Body (Scope_Id)
4250 and then not In_Private_Part (Scope_Id);
4251 end In_Visible_Part;
4253 ---------------------------------
4254 -- Insert_Explicit_Dereference --
4255 ---------------------------------
4257 procedure Insert_Explicit_Dereference (N : Node_Id) is
4258 New_Prefix : constant Node_Id := Relocate_Node (N);
4259 Ent : Entity_Id := Empty;
4260 Pref : Node_Id;
4261 I : Interp_Index;
4262 It : Interp;
4263 T : Entity_Id;
4265 begin
4266 Save_Interps (N, New_Prefix);
4267 Rewrite (N,
4268 Make_Explicit_Dereference (Sloc (N), Prefix => New_Prefix));
4270 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
4272 if Is_Overloaded (New_Prefix) then
4274 -- The deference is also overloaded, and its interpretations are the
4275 -- designated types of the interpretations of the original node.
4277 Set_Etype (N, Any_Type);
4279 Get_First_Interp (New_Prefix, I, It);
4280 while Present (It.Nam) loop
4281 T := It.Typ;
4283 if Is_Access_Type (T) then
4284 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
4285 end if;
4287 Get_Next_Interp (I, It);
4288 end loop;
4290 End_Interp_List;
4292 else
4293 -- Prefix is unambiguous: mark the original prefix (which might
4294 -- Come_From_Source) as a reference, since the new (relocated) one
4295 -- won't be taken into account.
4297 if Is_Entity_Name (New_Prefix) then
4298 Ent := Entity (New_Prefix);
4300 -- For a retrieval of a subcomponent of some composite object,
4301 -- retrieve the ultimate entity if there is one.
4303 elsif Nkind (New_Prefix) = N_Selected_Component
4304 or else Nkind (New_Prefix) = N_Indexed_Component
4305 then
4306 Pref := Prefix (New_Prefix);
4307 while Present (Pref)
4308 and then
4309 (Nkind (Pref) = N_Selected_Component
4310 or else Nkind (Pref) = N_Indexed_Component)
4311 loop
4312 Pref := Prefix (Pref);
4313 end loop;
4315 if Present (Pref) and then Is_Entity_Name (Pref) then
4316 Ent := Entity (Pref);
4317 end if;
4318 end if;
4320 if Present (Ent) then
4321 Generate_Reference (Ent, New_Prefix);
4322 end if;
4323 end if;
4324 end Insert_Explicit_Dereference;
4326 -------------------
4327 -- Is_AAMP_Float --
4328 -------------------
4330 function Is_AAMP_Float (E : Entity_Id) return Boolean is
4331 begin
4332 pragma Assert (Is_Type (E));
4334 return AAMP_On_Target
4335 and then Is_Floating_Point_Type (E)
4336 and then E = Base_Type (E);
4337 end Is_AAMP_Float;
4339 -------------------------
4340 -- Is_Actual_Parameter --
4341 -------------------------
4343 function Is_Actual_Parameter (N : Node_Id) return Boolean is
4344 PK : constant Node_Kind := Nkind (Parent (N));
4346 begin
4347 case PK is
4348 when N_Parameter_Association =>
4349 return N = Explicit_Actual_Parameter (Parent (N));
4351 when N_Function_Call | N_Procedure_Call_Statement =>
4352 return Is_List_Member (N)
4353 and then
4354 List_Containing (N) = Parameter_Associations (Parent (N));
4356 when others =>
4357 return False;
4358 end case;
4359 end Is_Actual_Parameter;
4361 ---------------------
4362 -- Is_Aliased_View --
4363 ---------------------
4365 function Is_Aliased_View (Obj : Node_Id) return Boolean is
4366 E : Entity_Id;
4368 begin
4369 if Is_Entity_Name (Obj) then
4371 E := Entity (Obj);
4373 return
4374 (Is_Object (E)
4375 and then
4376 (Is_Aliased (E)
4377 or else (Present (Renamed_Object (E))
4378 and then Is_Aliased_View (Renamed_Object (E)))))
4380 or else ((Is_Formal (E)
4381 or else Ekind (E) = E_Generic_In_Out_Parameter
4382 or else Ekind (E) = E_Generic_In_Parameter)
4383 and then Is_Tagged_Type (Etype (E)))
4385 or else ((Ekind (E) = E_Task_Type
4386 or else Ekind (E) = E_Protected_Type)
4387 and then In_Open_Scopes (E))
4389 -- Current instance of type, either directly or as rewritten
4390 -- reference to the current object.
4392 or else (Is_Entity_Name (Original_Node (Obj))
4393 and then Present (Entity (Original_Node (Obj)))
4394 and then Is_Type (Entity (Original_Node (Obj))))
4396 or else (Is_Type (E) and then E = Current_Scope)
4397 or else (Is_Incomplete_Or_Private_Type (E)
4398 and then Full_View (E) = Current_Scope);
4400 elsif Nkind (Obj) = N_Selected_Component then
4401 return Is_Aliased (Entity (Selector_Name (Obj)));
4403 elsif Nkind (Obj) = N_Indexed_Component then
4404 return Has_Aliased_Components (Etype (Prefix (Obj)))
4405 or else
4406 (Is_Access_Type (Etype (Prefix (Obj)))
4407 and then
4408 Has_Aliased_Components
4409 (Designated_Type (Etype (Prefix (Obj)))));
4411 elsif Nkind (Obj) = N_Unchecked_Type_Conversion
4412 or else Nkind (Obj) = N_Type_Conversion
4413 then
4414 return Is_Tagged_Type (Etype (Obj))
4415 and then Is_Aliased_View (Expression (Obj));
4417 elsif Nkind (Obj) = N_Explicit_Dereference then
4418 return Nkind (Original_Node (Obj)) /= N_Function_Call;
4420 else
4421 return False;
4422 end if;
4423 end Is_Aliased_View;
4425 -------------------------
4426 -- Is_Ancestor_Package --
4427 -------------------------
4429 function Is_Ancestor_Package
4430 (E1 : Entity_Id;
4431 E2 : Entity_Id) return Boolean
4433 Par : Entity_Id;
4435 begin
4436 Par := E2;
4437 while Present (Par)
4438 and then Par /= Standard_Standard
4439 loop
4440 if Par = E1 then
4441 return True;
4442 end if;
4444 Par := Scope (Par);
4445 end loop;
4447 return False;
4448 end Is_Ancestor_Package;
4450 ----------------------
4451 -- Is_Atomic_Object --
4452 ----------------------
4454 function Is_Atomic_Object (N : Node_Id) return Boolean is
4456 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
4457 -- Determines if given object has atomic components
4459 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
4460 -- If prefix is an implicit dereference, examine designated type
4462 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
4463 begin
4464 if Is_Access_Type (Etype (N)) then
4465 return
4466 Has_Atomic_Components (Designated_Type (Etype (N)));
4467 else
4468 return Object_Has_Atomic_Components (N);
4469 end if;
4470 end Is_Atomic_Prefix;
4472 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
4473 begin
4474 if Has_Atomic_Components (Etype (N))
4475 or else Is_Atomic (Etype (N))
4476 then
4477 return True;
4479 elsif Is_Entity_Name (N)
4480 and then (Has_Atomic_Components (Entity (N))
4481 or else Is_Atomic (Entity (N)))
4482 then
4483 return True;
4485 elsif Nkind (N) = N_Indexed_Component
4486 or else Nkind (N) = N_Selected_Component
4487 then
4488 return Is_Atomic_Prefix (Prefix (N));
4490 else
4491 return False;
4492 end if;
4493 end Object_Has_Atomic_Components;
4495 -- Start of processing for Is_Atomic_Object
4497 begin
4498 if Is_Atomic (Etype (N))
4499 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
4500 then
4501 return True;
4503 elsif Nkind (N) = N_Indexed_Component
4504 or else Nkind (N) = N_Selected_Component
4505 then
4506 return Is_Atomic_Prefix (Prefix (N));
4508 else
4509 return False;
4510 end if;
4511 end Is_Atomic_Object;
4513 --------------------------------------
4514 -- Is_Controlling_Limited_Procedure --
4515 --------------------------------------
4517 function Is_Controlling_Limited_Procedure
4518 (Proc_Nam : Entity_Id) return Boolean
4520 Param_Typ : Entity_Id := Empty;
4522 begin
4523 if Ekind (Proc_Nam) = E_Procedure
4524 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
4525 then
4526 Param_Typ := Etype (Parameter_Type (First (
4527 Parameter_Specifications (Parent (Proc_Nam)))));
4529 -- In this case where an Itype was created, the procedure call has been
4530 -- rewritten.
4532 elsif Present (Associated_Node_For_Itype (Proc_Nam))
4533 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
4534 and then
4535 Present (Parameter_Associations
4536 (Associated_Node_For_Itype (Proc_Nam)))
4537 then
4538 Param_Typ :=
4539 Etype (First (Parameter_Associations
4540 (Associated_Node_For_Itype (Proc_Nam))));
4541 end if;
4543 if Present (Param_Typ) then
4544 return
4545 Is_Interface (Param_Typ)
4546 and then Is_Limited_Record (Param_Typ);
4547 end if;
4549 return False;
4550 end Is_Controlling_Limited_Procedure;
4552 ----------------------------------------------
4553 -- Is_Dependent_Component_Of_Mutable_Object --
4554 ----------------------------------------------
4556 function Is_Dependent_Component_Of_Mutable_Object
4557 (Object : Node_Id) return Boolean
4559 P : Node_Id;
4560 Prefix_Type : Entity_Id;
4561 P_Aliased : Boolean := False;
4562 Comp : Entity_Id;
4564 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
4565 -- Returns True if and only if Comp is declared within a variant part
4567 --------------------------------
4568 -- Is_Declared_Within_Variant --
4569 --------------------------------
4571 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
4572 Comp_Decl : constant Node_Id := Parent (Comp);
4573 Comp_List : constant Node_Id := Parent (Comp_Decl);
4574 begin
4575 return Nkind (Parent (Comp_List)) = N_Variant;
4576 end Is_Declared_Within_Variant;
4578 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
4580 begin
4581 if Is_Variable (Object) then
4583 if Nkind (Object) = N_Selected_Component then
4584 P := Prefix (Object);
4585 Prefix_Type := Etype (P);
4587 if Is_Entity_Name (P) then
4589 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
4590 Prefix_Type := Base_Type (Prefix_Type);
4591 end if;
4593 if Is_Aliased (Entity (P)) then
4594 P_Aliased := True;
4595 end if;
4597 -- A discriminant check on a selected component may be
4598 -- expanded into a dereference when removing side-effects.
4599 -- Recover the original node and its type, which may be
4600 -- unconstrained.
4602 elsif Nkind (P) = N_Explicit_Dereference
4603 and then not (Comes_From_Source (P))
4604 then
4605 P := Original_Node (P);
4606 Prefix_Type := Etype (P);
4608 else
4609 -- Check for prefix being an aliased component ???
4610 null;
4612 end if;
4614 -- A heap object is constrained by its initial value
4616 -- Ada 2005 (AI-363): Always assume the object could be mutable in
4617 -- the dereferenced case, since the access value might denote an
4618 -- unconstrained aliased object, whereas in Ada 95 the designated
4619 -- object is guaranteed to be constrained. A worst-case assumption
4620 -- has to apply in Ada 2005 because we can't tell at compile time
4621 -- whether the object is "constrained by its initial value"
4622 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
4623 -- semantic rules -- these rules are acknowledged to need fixing).
4625 if Ada_Version < Ada_05 then
4626 if Is_Access_Type (Prefix_Type)
4627 or else Nkind (P) = N_Explicit_Dereference
4628 then
4629 return False;
4630 end if;
4632 elsif Ada_Version >= Ada_05 then
4633 if Is_Access_Type (Prefix_Type) then
4634 Prefix_Type := Designated_Type (Prefix_Type);
4635 end if;
4636 end if;
4638 Comp :=
4639 Original_Record_Component (Entity (Selector_Name (Object)));
4641 -- As per AI-0017, the renaming is illegal in a generic body,
4642 -- even if the subtype is indefinite.
4644 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
4646 if not Is_Constrained (Prefix_Type)
4647 and then (not Is_Indefinite_Subtype (Prefix_Type)
4648 or else
4649 (Is_Generic_Type (Prefix_Type)
4650 and then Ekind (Current_Scope) = E_Generic_Package
4651 and then In_Package_Body (Current_Scope)))
4653 and then (Is_Declared_Within_Variant (Comp)
4654 or else Has_Discriminant_Dependent_Constraint (Comp))
4655 and then (not P_Aliased or else Ada_Version >= Ada_05)
4656 then
4657 return True;
4659 else
4660 return
4661 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
4663 end if;
4665 elsif Nkind (Object) = N_Indexed_Component
4666 or else Nkind (Object) = N_Slice
4667 then
4668 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
4670 -- A type conversion that Is_Variable is a view conversion:
4671 -- go back to the denoted object.
4673 elsif Nkind (Object) = N_Type_Conversion then
4674 return
4675 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
4676 end if;
4677 end if;
4679 return False;
4680 end Is_Dependent_Component_Of_Mutable_Object;
4682 ---------------------
4683 -- Is_Dereferenced --
4684 ---------------------
4686 function Is_Dereferenced (N : Node_Id) return Boolean is
4687 P : constant Node_Id := Parent (N);
4688 begin
4689 return
4690 (Nkind (P) = N_Selected_Component
4691 or else
4692 Nkind (P) = N_Explicit_Dereference
4693 or else
4694 Nkind (P) = N_Indexed_Component
4695 or else
4696 Nkind (P) = N_Slice)
4697 and then Prefix (P) = N;
4698 end Is_Dereferenced;
4700 ----------------------
4701 -- Is_Descendent_Of --
4702 ----------------------
4704 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
4705 T : Entity_Id;
4706 Etyp : Entity_Id;
4708 begin
4709 pragma Assert (Nkind (T1) in N_Entity);
4710 pragma Assert (Nkind (T2) in N_Entity);
4712 T := Base_Type (T1);
4714 -- Immediate return if the types match
4716 if T = T2 then
4717 return True;
4719 -- Comment needed here ???
4721 elsif Ekind (T) = E_Class_Wide_Type then
4722 return Etype (T) = T2;
4724 -- All other cases
4726 else
4727 loop
4728 Etyp := Etype (T);
4730 -- Done if we found the type we are looking for
4732 if Etyp = T2 then
4733 return True;
4735 -- Done if no more derivations to check
4737 elsif T = T1
4738 or else T = Etyp
4739 then
4740 return False;
4742 -- Following test catches error cases resulting from prev errors
4744 elsif No (Etyp) then
4745 return False;
4747 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
4748 return False;
4750 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
4751 return False;
4752 end if;
4754 T := Base_Type (Etyp);
4755 end loop;
4756 end if;
4758 raise Program_Error;
4759 end Is_Descendent_Of;
4761 ------------------------------
4762 -- Is_Descendent_Of_Address --
4763 ------------------------------
4765 function Is_Descendent_Of_Address (T1 : Entity_Id) return Boolean is
4766 begin
4767 -- If Address has not been loaded, answer must be False
4769 if not RTU_Loaded (System) then
4770 return False;
4772 -- Otherwise we can get the entity we are interested in without
4773 -- causing an unwanted dependency on System, and do the test.
4775 else
4776 return Is_Descendent_Of (T1, Base_Type (RTE (RE_Address)));
4777 end if;
4778 end Is_Descendent_Of_Address;
4780 --------------
4781 -- Is_False --
4782 --------------
4784 function Is_False (U : Uint) return Boolean is
4785 begin
4786 return (U = 0);
4787 end Is_False;
4789 ---------------------------
4790 -- Is_Fixed_Model_Number --
4791 ---------------------------
4793 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
4794 S : constant Ureal := Small_Value (T);
4795 M : Urealp.Save_Mark;
4796 R : Boolean;
4797 begin
4798 M := Urealp.Mark;
4799 R := (U = UR_Trunc (U / S) * S);
4800 Urealp.Release (M);
4801 return R;
4802 end Is_Fixed_Model_Number;
4804 -------------------------------
4805 -- Is_Fully_Initialized_Type --
4806 -------------------------------
4808 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
4809 begin
4810 if Is_Scalar_Type (Typ) then
4811 return False;
4813 elsif Is_Access_Type (Typ) then
4814 return True;
4816 elsif Is_Array_Type (Typ) then
4817 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
4818 return True;
4819 end if;
4821 -- An interesting case, if we have a constrained type one of whose
4822 -- bounds is known to be null, then there are no elements to be
4823 -- initialized, so all the elements are initialized!
4825 if Is_Constrained (Typ) then
4826 declare
4827 Indx : Node_Id;
4828 Indx_Typ : Entity_Id;
4829 Lbd, Hbd : Node_Id;
4831 begin
4832 Indx := First_Index (Typ);
4833 while Present (Indx) loop
4834 if Etype (Indx) = Any_Type then
4835 return False;
4837 -- If index is a range, use directly
4839 elsif Nkind (Indx) = N_Range then
4840 Lbd := Low_Bound (Indx);
4841 Hbd := High_Bound (Indx);
4843 else
4844 Indx_Typ := Etype (Indx);
4846 if Is_Private_Type (Indx_Typ) then
4847 Indx_Typ := Full_View (Indx_Typ);
4848 end if;
4850 if No (Indx_Typ) then
4851 return False;
4852 else
4853 Lbd := Type_Low_Bound (Indx_Typ);
4854 Hbd := Type_High_Bound (Indx_Typ);
4855 end if;
4856 end if;
4858 if Compile_Time_Known_Value (Lbd)
4859 and then Compile_Time_Known_Value (Hbd)
4860 then
4861 if Expr_Value (Hbd) < Expr_Value (Lbd) then
4862 return True;
4863 end if;
4864 end if;
4866 Next_Index (Indx);
4867 end loop;
4868 end;
4869 end if;
4871 -- If no null indexes, then type is not fully initialized
4873 return False;
4875 -- Record types
4877 elsif Is_Record_Type (Typ) then
4878 if Has_Discriminants (Typ)
4879 and then
4880 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
4881 and then Is_Fully_Initialized_Variant (Typ)
4882 then
4883 return True;
4884 end if;
4886 -- Controlled records are considered to be fully initialized if
4887 -- there is a user defined Initialize routine. This may not be
4888 -- entirely correct, but as the spec notes, we are guessing here
4889 -- what is best from the point of view of issuing warnings.
4891 if Is_Controlled (Typ) then
4892 declare
4893 Utyp : constant Entity_Id := Underlying_Type (Typ);
4895 begin
4896 if Present (Utyp) then
4897 declare
4898 Init : constant Entity_Id :=
4899 (Find_Prim_Op
4900 (Underlying_Type (Typ), Name_Initialize));
4902 begin
4903 if Present (Init)
4904 and then Comes_From_Source (Init)
4905 and then not
4906 Is_Predefined_File_Name
4907 (File_Name (Get_Source_File_Index (Sloc (Init))))
4908 then
4909 return True;
4911 elsif Has_Null_Extension (Typ)
4912 and then
4913 Is_Fully_Initialized_Type
4914 (Etype (Base_Type (Typ)))
4915 then
4916 return True;
4917 end if;
4918 end;
4919 end if;
4920 end;
4921 end if;
4923 -- Otherwise see if all record components are initialized
4925 declare
4926 Ent : Entity_Id;
4928 begin
4929 Ent := First_Entity (Typ);
4930 while Present (Ent) loop
4931 if Chars (Ent) = Name_uController then
4932 null;
4934 elsif Ekind (Ent) = E_Component
4935 and then (No (Parent (Ent))
4936 or else No (Expression (Parent (Ent))))
4937 and then not Is_Fully_Initialized_Type (Etype (Ent))
4938 then
4939 return False;
4940 end if;
4942 Next_Entity (Ent);
4943 end loop;
4944 end;
4946 -- No uninitialized components, so type is fully initialized.
4947 -- Note that this catches the case of no components as well.
4949 return True;
4951 elsif Is_Concurrent_Type (Typ) then
4952 return True;
4954 elsif Is_Private_Type (Typ) then
4955 declare
4956 U : constant Entity_Id := Underlying_Type (Typ);
4958 begin
4959 if No (U) then
4960 return False;
4961 else
4962 return Is_Fully_Initialized_Type (U);
4963 end if;
4964 end;
4966 else
4967 return False;
4968 end if;
4969 end Is_Fully_Initialized_Type;
4971 ----------------------------------
4972 -- Is_Fully_Initialized_Variant --
4973 ----------------------------------
4975 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
4976 Loc : constant Source_Ptr := Sloc (Typ);
4977 Constraints : constant List_Id := New_List;
4978 Components : constant Elist_Id := New_Elmt_List;
4979 Comp_Elmt : Elmt_Id;
4980 Comp_Id : Node_Id;
4981 Comp_List : Node_Id;
4982 Discr : Entity_Id;
4983 Discr_Val : Node_Id;
4984 Report_Errors : Boolean;
4986 begin
4987 if Serious_Errors_Detected > 0 then
4988 return False;
4989 end if;
4991 if Is_Record_Type (Typ)
4992 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
4993 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
4994 then
4995 Comp_List := Component_List (Type_Definition (Parent (Typ)));
4997 Discr := First_Discriminant (Typ);
4998 while Present (Discr) loop
4999 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
5000 Discr_Val := Expression (Parent (Discr));
5002 if Present (Discr_Val)
5003 and then Is_OK_Static_Expression (Discr_Val)
5004 then
5005 Append_To (Constraints,
5006 Make_Component_Association (Loc,
5007 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
5008 Expression => New_Copy (Discr_Val)));
5009 else
5010 return False;
5011 end if;
5012 else
5013 return False;
5014 end if;
5016 Next_Discriminant (Discr);
5017 end loop;
5019 Gather_Components
5020 (Typ => Typ,
5021 Comp_List => Comp_List,
5022 Governed_By => Constraints,
5023 Into => Components,
5024 Report_Errors => Report_Errors);
5026 -- Check that each component present is fully initialized
5028 Comp_Elmt := First_Elmt (Components);
5029 while Present (Comp_Elmt) loop
5030 Comp_Id := Node (Comp_Elmt);
5032 if Ekind (Comp_Id) = E_Component
5033 and then (No (Parent (Comp_Id))
5034 or else No (Expression (Parent (Comp_Id))))
5035 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
5036 then
5037 return False;
5038 end if;
5040 Next_Elmt (Comp_Elmt);
5041 end loop;
5043 return True;
5045 elsif Is_Private_Type (Typ) then
5046 declare
5047 U : constant Entity_Id := Underlying_Type (Typ);
5049 begin
5050 if No (U) then
5051 return False;
5052 else
5053 return Is_Fully_Initialized_Variant (U);
5054 end if;
5055 end;
5056 else
5057 return False;
5058 end if;
5059 end Is_Fully_Initialized_Variant;
5061 ----------------------------
5062 -- Is_Inherited_Operation --
5063 ----------------------------
5065 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
5066 Kind : constant Node_Kind := Nkind (Parent (E));
5067 begin
5068 pragma Assert (Is_Overloadable (E));
5069 return Kind = N_Full_Type_Declaration
5070 or else Kind = N_Private_Extension_Declaration
5071 or else Kind = N_Subtype_Declaration
5072 or else (Ekind (E) = E_Enumeration_Literal
5073 and then Is_Derived_Type (Etype (E)));
5074 end Is_Inherited_Operation;
5076 -----------------------------
5077 -- Is_Library_Level_Entity --
5078 -----------------------------
5080 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
5081 begin
5082 -- The following is a small optimization, and it also handles
5083 -- properly discriminals, which in task bodies might appear in
5084 -- expressions before the corresponding procedure has been
5085 -- created, and which therefore do not have an assigned scope.
5087 if Ekind (E) in Formal_Kind then
5088 return False;
5089 end if;
5091 -- Normal test is simply that the enclosing dynamic scope is Standard
5093 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
5094 end Is_Library_Level_Entity;
5096 ---------------------------------
5097 -- Is_Local_Variable_Reference --
5098 ---------------------------------
5100 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
5101 begin
5102 if not Is_Entity_Name (Expr) then
5103 return False;
5105 else
5106 declare
5107 Ent : constant Entity_Id := Entity (Expr);
5108 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
5109 begin
5110 if Ekind (Ent) /= E_Variable
5111 and then
5112 Ekind (Ent) /= E_In_Out_Parameter
5113 then
5114 return False;
5115 else
5116 return Present (Sub) and then Sub = Current_Subprogram;
5117 end if;
5118 end;
5119 end if;
5120 end Is_Local_Variable_Reference;
5122 -------------------------
5123 -- Is_Object_Reference --
5124 -------------------------
5126 function Is_Object_Reference (N : Node_Id) return Boolean is
5127 begin
5128 if Is_Entity_Name (N) then
5129 return Is_Object (Entity (N));
5131 else
5132 case Nkind (N) is
5133 when N_Indexed_Component | N_Slice =>
5134 return
5135 Is_Object_Reference (Prefix (N))
5136 or else Is_Access_Type (Etype (Prefix (N)));
5138 -- In Ada95, a function call is a constant object; a procedure
5139 -- call is not.
5141 when N_Function_Call =>
5142 return Etype (N) /= Standard_Void_Type;
5144 -- A reference to the stream attribute Input is a function call
5146 when N_Attribute_Reference =>
5147 return Attribute_Name (N) = Name_Input;
5149 when N_Selected_Component =>
5150 return
5151 Is_Object_Reference (Selector_Name (N))
5152 and then
5153 (Is_Object_Reference (Prefix (N))
5154 or else Is_Access_Type (Etype (Prefix (N))));
5156 when N_Explicit_Dereference =>
5157 return True;
5159 -- A view conversion of a tagged object is an object reference
5161 when N_Type_Conversion =>
5162 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
5163 and then Is_Tagged_Type (Etype (Expression (N)))
5164 and then Is_Object_Reference (Expression (N));
5166 -- An unchecked type conversion is considered to be an object if
5167 -- the operand is an object (this construction arises only as a
5168 -- result of expansion activities).
5170 when N_Unchecked_Type_Conversion =>
5171 return True;
5173 when others =>
5174 return False;
5175 end case;
5176 end if;
5177 end Is_Object_Reference;
5179 -----------------------------------
5180 -- Is_OK_Variable_For_Out_Formal --
5181 -----------------------------------
5183 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
5184 begin
5185 Note_Possible_Modification (AV);
5187 -- We must reject parenthesized variable names. The check for
5188 -- Comes_From_Source is present because there are currently
5189 -- cases where the compiler violates this rule (e.g. passing
5190 -- a task object to its controlled Initialize routine).
5192 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
5193 return False;
5195 -- A variable is always allowed
5197 elsif Is_Variable (AV) then
5198 return True;
5200 -- Unchecked conversions are allowed only if they come from the
5201 -- generated code, which sometimes uses unchecked conversions for out
5202 -- parameters in cases where code generation is unaffected. We tell
5203 -- source unchecked conversions by seeing if they are rewrites of an
5204 -- original Unchecked_Conversion function call, or of an explicit
5205 -- conversion of a function call.
5207 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
5208 if Nkind (Original_Node (AV)) = N_Function_Call then
5209 return False;
5211 elsif Comes_From_Source (AV)
5212 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
5213 then
5214 return False;
5216 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
5217 return Is_OK_Variable_For_Out_Formal (Expression (AV));
5219 else
5220 return True;
5221 end if;
5223 -- Normal type conversions are allowed if argument is a variable
5225 elsif Nkind (AV) = N_Type_Conversion then
5226 if Is_Variable (Expression (AV))
5227 and then Paren_Count (Expression (AV)) = 0
5228 then
5229 Note_Possible_Modification (Expression (AV));
5230 return True;
5232 -- We also allow a non-parenthesized expression that raises
5233 -- constraint error if it rewrites what used to be a variable
5235 elsif Raises_Constraint_Error (Expression (AV))
5236 and then Paren_Count (Expression (AV)) = 0
5237 and then Is_Variable (Original_Node (Expression (AV)))
5238 then
5239 return True;
5241 -- Type conversion of something other than a variable
5243 else
5244 return False;
5245 end if;
5247 -- If this node is rewritten, then test the original form, if that is
5248 -- OK, then we consider the rewritten node OK (for example, if the
5249 -- original node is a conversion, then Is_Variable will not be true
5250 -- but we still want to allow the conversion if it converts a variable).
5252 elsif Original_Node (AV) /= AV then
5253 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
5255 -- All other non-variables are rejected
5257 else
5258 return False;
5259 end if;
5260 end Is_OK_Variable_For_Out_Formal;
5262 -----------------------------------
5263 -- Is_Partially_Initialized_Type --
5264 -----------------------------------
5266 function Is_Partially_Initialized_Type (Typ : Entity_Id) return Boolean is
5267 begin
5268 if Is_Scalar_Type (Typ) then
5269 return False;
5271 elsif Is_Access_Type (Typ) then
5272 return True;
5274 elsif Is_Array_Type (Typ) then
5276 -- If component type is partially initialized, so is array type
5278 if Is_Partially_Initialized_Type (Component_Type (Typ)) then
5279 return True;
5281 -- Otherwise we are only partially initialized if we are fully
5282 -- initialized (this is the empty array case, no point in us
5283 -- duplicating that code here).
5285 else
5286 return Is_Fully_Initialized_Type (Typ);
5287 end if;
5289 elsif Is_Record_Type (Typ) then
5291 -- A discriminated type is always partially initialized
5293 if Has_Discriminants (Typ) then
5294 return True;
5296 -- A tagged type is always partially initialized
5298 elsif Is_Tagged_Type (Typ) then
5299 return True;
5301 -- Case of non-discriminated record
5303 else
5304 declare
5305 Ent : Entity_Id;
5307 Component_Present : Boolean := False;
5308 -- Set True if at least one component is present. If no
5309 -- components are present, then record type is fully
5310 -- initialized (another odd case, like the null array).
5312 begin
5313 -- Loop through components
5315 Ent := First_Entity (Typ);
5316 while Present (Ent) loop
5317 if Ekind (Ent) = E_Component then
5318 Component_Present := True;
5320 -- If a component has an initialization expression then
5321 -- the enclosing record type is partially initialized
5323 if Present (Parent (Ent))
5324 and then Present (Expression (Parent (Ent)))
5325 then
5326 return True;
5328 -- If a component is of a type which is itself partially
5329 -- initialized, then the enclosing record type is also.
5331 elsif Is_Partially_Initialized_Type (Etype (Ent)) then
5332 return True;
5333 end if;
5334 end if;
5336 Next_Entity (Ent);
5337 end loop;
5339 -- No initialized components found. If we found any components
5340 -- they were all uninitialized so the result is false.
5342 if Component_Present then
5343 return False;
5345 -- But if we found no components, then all the components are
5346 -- initialized so we consider the type to be initialized.
5348 else
5349 return True;
5350 end if;
5351 end;
5352 end if;
5354 -- Concurrent types are always fully initialized
5356 elsif Is_Concurrent_Type (Typ) then
5357 return True;
5359 -- For a private type, go to underlying type. If there is no underlying
5360 -- type then just assume this partially initialized. Not clear if this
5361 -- can happen in a non-error case, but no harm in testing for this.
5363 elsif Is_Private_Type (Typ) then
5364 declare
5365 U : constant Entity_Id := Underlying_Type (Typ);
5366 begin
5367 if No (U) then
5368 return True;
5369 else
5370 return Is_Partially_Initialized_Type (U);
5371 end if;
5372 end;
5374 -- For any other type (are there any?) assume partially initialized
5376 else
5377 return True;
5378 end if;
5379 end Is_Partially_Initialized_Type;
5381 ------------------------------------
5382 -- Is_Potentially_Persistent_Type --
5383 ------------------------------------
5385 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
5386 Comp : Entity_Id;
5387 Indx : Node_Id;
5389 begin
5390 -- For private type, test corrresponding full type
5392 if Is_Private_Type (T) then
5393 return Is_Potentially_Persistent_Type (Full_View (T));
5395 -- Scalar types are potentially persistent
5397 elsif Is_Scalar_Type (T) then
5398 return True;
5400 -- Record type is potentially persistent if not tagged and the types of
5401 -- all it components are potentially persistent, and no component has
5402 -- an initialization expression.
5404 elsif Is_Record_Type (T)
5405 and then not Is_Tagged_Type (T)
5406 and then not Is_Partially_Initialized_Type (T)
5407 then
5408 Comp := First_Component (T);
5409 while Present (Comp) loop
5410 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
5411 return False;
5412 else
5413 Next_Entity (Comp);
5414 end if;
5415 end loop;
5417 return True;
5419 -- Array type is potentially persistent if its component type is
5420 -- potentially persistent and if all its constraints are static.
5422 elsif Is_Array_Type (T) then
5423 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
5424 return False;
5425 end if;
5427 Indx := First_Index (T);
5428 while Present (Indx) loop
5429 if not Is_OK_Static_Subtype (Etype (Indx)) then
5430 return False;
5431 else
5432 Next_Index (Indx);
5433 end if;
5434 end loop;
5436 return True;
5438 -- All other types are not potentially persistent
5440 else
5441 return False;
5442 end if;
5443 end Is_Potentially_Persistent_Type;
5445 -----------------------------
5446 -- Is_RCI_Pkg_Spec_Or_Body --
5447 -----------------------------
5449 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
5451 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
5452 -- Return True if the unit of Cunit is an RCI package declaration
5454 ---------------------------
5455 -- Is_RCI_Pkg_Decl_Cunit --
5456 ---------------------------
5458 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
5459 The_Unit : constant Node_Id := Unit (Cunit);
5461 begin
5462 if Nkind (The_Unit) /= N_Package_Declaration then
5463 return False;
5464 end if;
5466 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
5467 end Is_RCI_Pkg_Decl_Cunit;
5469 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
5471 begin
5472 return Is_RCI_Pkg_Decl_Cunit (Cunit)
5473 or else
5474 (Nkind (Unit (Cunit)) = N_Package_Body
5475 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
5476 end Is_RCI_Pkg_Spec_Or_Body;
5478 -----------------------------------------
5479 -- Is_Remote_Access_To_Class_Wide_Type --
5480 -----------------------------------------
5482 function Is_Remote_Access_To_Class_Wide_Type
5483 (E : Entity_Id) return Boolean
5485 D : Entity_Id;
5487 function Comes_From_Limited_Private_Type_Declaration
5488 (E : Entity_Id) return Boolean;
5489 -- Check that the type is declared by a limited type declaration,
5490 -- or else is derived from a Remote_Type ancestor through private
5491 -- extensions.
5493 -------------------------------------------------
5494 -- Comes_From_Limited_Private_Type_Declaration --
5495 -------------------------------------------------
5497 function Comes_From_Limited_Private_Type_Declaration
5498 (E : Entity_Id) return Boolean
5500 N : constant Node_Id := Declaration_Node (E);
5502 begin
5503 if Nkind (N) = N_Private_Type_Declaration
5504 and then Limited_Present (N)
5505 then
5506 return True;
5507 end if;
5509 if Nkind (N) = N_Private_Extension_Declaration then
5510 return
5511 Comes_From_Limited_Private_Type_Declaration (Etype (E))
5512 or else
5513 (Is_Remote_Types (Etype (E))
5514 and then Is_Limited_Record (Etype (E))
5515 and then Has_Private_Declaration (Etype (E)));
5516 end if;
5518 return False;
5519 end Comes_From_Limited_Private_Type_Declaration;
5521 -- Start of processing for Is_Remote_Access_To_Class_Wide_Type
5523 begin
5524 if not (Is_Remote_Call_Interface (E)
5525 or else Is_Remote_Types (E))
5526 or else Ekind (E) /= E_General_Access_Type
5527 then
5528 return False;
5529 end if;
5531 D := Designated_Type (E);
5533 if Ekind (D) /= E_Class_Wide_Type then
5534 return False;
5535 end if;
5537 return Comes_From_Limited_Private_Type_Declaration
5538 (Defining_Identifier (Parent (D)));
5539 end Is_Remote_Access_To_Class_Wide_Type;
5541 -----------------------------------------
5542 -- Is_Remote_Access_To_Subprogram_Type --
5543 -----------------------------------------
5545 function Is_Remote_Access_To_Subprogram_Type
5546 (E : Entity_Id) return Boolean
5548 begin
5549 return (Ekind (E) = E_Access_Subprogram_Type
5550 or else (Ekind (E) = E_Record_Type
5551 and then Present (Corresponding_Remote_Type (E))))
5552 and then (Is_Remote_Call_Interface (E)
5553 or else Is_Remote_Types (E));
5554 end Is_Remote_Access_To_Subprogram_Type;
5556 --------------------
5557 -- Is_Remote_Call --
5558 --------------------
5560 function Is_Remote_Call (N : Node_Id) return Boolean is
5561 begin
5562 if Nkind (N) /= N_Procedure_Call_Statement
5563 and then Nkind (N) /= N_Function_Call
5564 then
5565 -- An entry call cannot be remote
5567 return False;
5569 elsif Nkind (Name (N)) in N_Has_Entity
5570 and then Is_Remote_Call_Interface (Entity (Name (N)))
5571 then
5572 -- A subprogram declared in the spec of a RCI package is remote
5574 return True;
5576 elsif Nkind (Name (N)) = N_Explicit_Dereference
5577 and then Is_Remote_Access_To_Subprogram_Type
5578 (Etype (Prefix (Name (N))))
5579 then
5580 -- The dereference of a RAS is a remote call
5582 return True;
5584 elsif Present (Controlling_Argument (N))
5585 and then Is_Remote_Access_To_Class_Wide_Type
5586 (Etype (Controlling_Argument (N)))
5587 then
5588 -- Any primitive operation call with a controlling argument of
5589 -- a RACW type is a remote call.
5591 return True;
5592 end if;
5594 -- All other calls are local calls
5596 return False;
5597 end Is_Remote_Call;
5599 ----------------------
5600 -- Is_Renamed_Entry --
5601 ----------------------
5603 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
5604 Orig_Node : Node_Id := Empty;
5605 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
5607 function Is_Entry (Nam : Node_Id) return Boolean;
5608 -- Determine whether Nam is an entry. Traverse selectors
5609 -- if there are nested selected components.
5611 --------------
5612 -- Is_Entry --
5613 --------------
5615 function Is_Entry (Nam : Node_Id) return Boolean is
5616 begin
5617 if Nkind (Nam) = N_Selected_Component then
5618 return Is_Entry (Selector_Name (Nam));
5619 end if;
5621 return Ekind (Entity (Nam)) = E_Entry;
5622 end Is_Entry;
5624 -- Start of processing for Is_Renamed_Entry
5626 begin
5627 if Present (Alias (Proc_Nam)) then
5628 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
5629 end if;
5631 -- Look for a rewritten subprogram renaming declaration
5633 if Nkind (Subp_Decl) = N_Subprogram_Declaration
5634 and then Present (Original_Node (Subp_Decl))
5635 then
5636 Orig_Node := Original_Node (Subp_Decl);
5637 end if;
5639 -- The rewritten subprogram is actually an entry
5641 if Present (Orig_Node)
5642 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
5643 and then Is_Entry (Name (Orig_Node))
5644 then
5645 return True;
5646 end if;
5648 return False;
5649 end Is_Renamed_Entry;
5651 ----------------------
5652 -- Is_Selector_Name --
5653 ----------------------
5655 function Is_Selector_Name (N : Node_Id) return Boolean is
5656 begin
5657 if not Is_List_Member (N) then
5658 declare
5659 P : constant Node_Id := Parent (N);
5660 K : constant Node_Kind := Nkind (P);
5661 begin
5662 return
5663 (K = N_Expanded_Name or else
5664 K = N_Generic_Association or else
5665 K = N_Parameter_Association or else
5666 K = N_Selected_Component)
5667 and then Selector_Name (P) = N;
5668 end;
5670 else
5671 declare
5672 L : constant List_Id := List_Containing (N);
5673 P : constant Node_Id := Parent (L);
5674 begin
5675 return (Nkind (P) = N_Discriminant_Association
5676 and then Selector_Names (P) = L)
5677 or else
5678 (Nkind (P) = N_Component_Association
5679 and then Choices (P) = L);
5680 end;
5681 end if;
5682 end Is_Selector_Name;
5684 ------------------
5685 -- Is_Statement --
5686 ------------------
5688 function Is_Statement (N : Node_Id) return Boolean is
5689 begin
5690 return
5691 Nkind (N) in N_Statement_Other_Than_Procedure_Call
5692 or else Nkind (N) = N_Procedure_Call_Statement;
5693 end Is_Statement;
5695 -----------------
5696 -- Is_Transfer --
5697 -----------------
5699 function Is_Transfer (N : Node_Id) return Boolean is
5700 Kind : constant Node_Kind := Nkind (N);
5702 begin
5703 if Kind = N_Return_Statement
5704 or else
5705 Kind = N_Extended_Return_Statement
5706 or else
5707 Kind = N_Goto_Statement
5708 or else
5709 Kind = N_Raise_Statement
5710 or else
5711 Kind = N_Requeue_Statement
5712 then
5713 return True;
5715 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
5716 and then No (Condition (N))
5717 then
5718 return True;
5720 elsif Kind = N_Procedure_Call_Statement
5721 and then Is_Entity_Name (Name (N))
5722 and then Present (Entity (Name (N)))
5723 and then No_Return (Entity (Name (N)))
5724 then
5725 return True;
5727 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
5728 return True;
5730 else
5731 return False;
5732 end if;
5733 end Is_Transfer;
5735 -------------
5736 -- Is_True --
5737 -------------
5739 function Is_True (U : Uint) return Boolean is
5740 begin
5741 return (U /= 0);
5742 end Is_True;
5744 -----------------
5745 -- Is_Variable --
5746 -----------------
5748 function Is_Variable (N : Node_Id) return Boolean is
5750 Orig_Node : constant Node_Id := Original_Node (N);
5751 -- We do the test on the original node, since this is basically a
5752 -- test of syntactic categories, so it must not be disturbed by
5753 -- whatever rewriting might have occurred. For example, an aggregate,
5754 -- which is certainly NOT a variable, could be turned into a variable
5755 -- by expansion.
5757 function In_Protected_Function (E : Entity_Id) return Boolean;
5758 -- Within a protected function, the private components of the
5759 -- enclosing protected type are constants. A function nested within
5760 -- a (protected) procedure is not itself protected.
5762 function Is_Variable_Prefix (P : Node_Id) return Boolean;
5763 -- Prefixes can involve implicit dereferences, in which case we
5764 -- must test for the case of a reference of a constant access
5765 -- type, which can never be a variable.
5767 ---------------------------
5768 -- In_Protected_Function --
5769 ---------------------------
5771 function In_Protected_Function (E : Entity_Id) return Boolean is
5772 Prot : constant Entity_Id := Scope (E);
5773 S : Entity_Id;
5775 begin
5776 if not Is_Protected_Type (Prot) then
5777 return False;
5778 else
5779 S := Current_Scope;
5780 while Present (S) and then S /= Prot loop
5781 if Ekind (S) = E_Function
5782 and then Scope (S) = Prot
5783 then
5784 return True;
5785 end if;
5787 S := Scope (S);
5788 end loop;
5790 return False;
5791 end if;
5792 end In_Protected_Function;
5794 ------------------------
5795 -- Is_Variable_Prefix --
5796 ------------------------
5798 function Is_Variable_Prefix (P : Node_Id) return Boolean is
5799 begin
5800 if Is_Access_Type (Etype (P)) then
5801 return not Is_Access_Constant (Root_Type (Etype (P)));
5803 -- For the case of an indexed component whose prefix has a packed
5804 -- array type, the prefix has been rewritten into a type conversion.
5805 -- Determine variable-ness from the converted expression.
5807 elsif Nkind (P) = N_Type_Conversion
5808 and then not Comes_From_Source (P)
5809 and then Is_Array_Type (Etype (P))
5810 and then Is_Packed (Etype (P))
5811 then
5812 return Is_Variable (Expression (P));
5814 else
5815 return Is_Variable (P);
5816 end if;
5817 end Is_Variable_Prefix;
5819 -- Start of processing for Is_Variable
5821 begin
5822 -- Definitely OK if Assignment_OK is set. Since this is something that
5823 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
5825 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
5826 return True;
5828 -- Normally we go to the original node, but there is one exception
5829 -- where we use the rewritten node, namely when it is an explicit
5830 -- dereference. The generated code may rewrite a prefix which is an
5831 -- access type with an explicit dereference. The dereference is a
5832 -- variable, even though the original node may not be (since it could
5833 -- be a constant of the access type).
5835 elsif Nkind (N) = N_Explicit_Dereference
5836 and then Nkind (Orig_Node) /= N_Explicit_Dereference
5837 and then Is_Access_Type (Etype (Orig_Node))
5838 then
5839 return Is_Variable_Prefix (Original_Node (Prefix (N)));
5841 -- A function call is never a variable
5843 elsif Nkind (N) = N_Function_Call then
5844 return False;
5846 -- All remaining checks use the original node
5848 elsif Is_Entity_Name (Orig_Node) then
5849 declare
5850 E : constant Entity_Id := Entity (Orig_Node);
5851 K : constant Entity_Kind := Ekind (E);
5853 begin
5854 return (K = E_Variable
5855 and then Nkind (Parent (E)) /= N_Exception_Handler)
5856 or else (K = E_Component
5857 and then not In_Protected_Function (E))
5858 or else K = E_Out_Parameter
5859 or else K = E_In_Out_Parameter
5860 or else K = E_Generic_In_Out_Parameter
5862 -- Current instance of type:
5864 or else (Is_Type (E) and then In_Open_Scopes (E))
5865 or else (Is_Incomplete_Or_Private_Type (E)
5866 and then In_Open_Scopes (Full_View (E)));
5867 end;
5869 else
5870 case Nkind (Orig_Node) is
5871 when N_Indexed_Component | N_Slice =>
5872 return Is_Variable_Prefix (Prefix (Orig_Node));
5874 when N_Selected_Component =>
5875 return Is_Variable_Prefix (Prefix (Orig_Node))
5876 and then Is_Variable (Selector_Name (Orig_Node));
5878 -- For an explicit dereference, the type of the prefix cannot
5879 -- be an access to constant or an access to subprogram.
5881 when N_Explicit_Dereference =>
5882 declare
5883 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
5884 begin
5885 return Is_Access_Type (Typ)
5886 and then not Is_Access_Constant (Root_Type (Typ))
5887 and then Ekind (Typ) /= E_Access_Subprogram_Type;
5888 end;
5890 -- The type conversion is the case where we do not deal with the
5891 -- context dependent special case of an actual parameter. Thus
5892 -- the type conversion is only considered a variable for the
5893 -- purposes of this routine if the target type is tagged. However,
5894 -- a type conversion is considered to be a variable if it does not
5895 -- come from source (this deals for example with the conversions
5896 -- of expressions to their actual subtypes).
5898 when N_Type_Conversion =>
5899 return Is_Variable (Expression (Orig_Node))
5900 and then
5901 (not Comes_From_Source (Orig_Node)
5902 or else
5903 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
5904 and then
5905 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
5907 -- GNAT allows an unchecked type conversion as a variable. This
5908 -- only affects the generation of internal expanded code, since
5909 -- calls to instantiations of Unchecked_Conversion are never
5910 -- considered variables (since they are function calls).
5911 -- This is also true for expression actions.
5913 when N_Unchecked_Type_Conversion =>
5914 return Is_Variable (Expression (Orig_Node));
5916 when others =>
5917 return False;
5918 end case;
5919 end if;
5920 end Is_Variable;
5922 ------------------------
5923 -- Is_Volatile_Object --
5924 ------------------------
5926 function Is_Volatile_Object (N : Node_Id) return Boolean is
5928 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
5929 -- Determines if given object has volatile components
5931 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
5932 -- If prefix is an implicit dereference, examine designated type
5934 ------------------------
5935 -- Is_Volatile_Prefix --
5936 ------------------------
5938 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
5939 Typ : constant Entity_Id := Etype (N);
5941 begin
5942 if Is_Access_Type (Typ) then
5943 declare
5944 Dtyp : constant Entity_Id := Designated_Type (Typ);
5946 begin
5947 return Is_Volatile (Dtyp)
5948 or else Has_Volatile_Components (Dtyp);
5949 end;
5951 else
5952 return Object_Has_Volatile_Components (N);
5953 end if;
5954 end Is_Volatile_Prefix;
5956 ------------------------------------
5957 -- Object_Has_Volatile_Components --
5958 ------------------------------------
5960 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
5961 Typ : constant Entity_Id := Etype (N);
5963 begin
5964 if Is_Volatile (Typ)
5965 or else Has_Volatile_Components (Typ)
5966 then
5967 return True;
5969 elsif Is_Entity_Name (N)
5970 and then (Has_Volatile_Components (Entity (N))
5971 or else Is_Volatile (Entity (N)))
5972 then
5973 return True;
5975 elsif Nkind (N) = N_Indexed_Component
5976 or else Nkind (N) = N_Selected_Component
5977 then
5978 return Is_Volatile_Prefix (Prefix (N));
5980 else
5981 return False;
5982 end if;
5983 end Object_Has_Volatile_Components;
5985 -- Start of processing for Is_Volatile_Object
5987 begin
5988 if Is_Volatile (Etype (N))
5989 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
5990 then
5991 return True;
5993 elsif Nkind (N) = N_Indexed_Component
5994 or else Nkind (N) = N_Selected_Component
5995 then
5996 return Is_Volatile_Prefix (Prefix (N));
5998 else
5999 return False;
6000 end if;
6001 end Is_Volatile_Object;
6003 -------------------------
6004 -- Kill_Current_Values --
6005 -------------------------
6007 procedure Kill_Current_Values (Ent : Entity_Id) is
6008 begin
6009 if Is_Object (Ent) then
6010 Kill_Checks (Ent);
6011 Set_Current_Value (Ent, Empty);
6013 if Ekind (Ent) = E_Variable then
6014 Set_Last_Assignment (Ent, Empty);
6015 end if;
6017 if not Can_Never_Be_Null (Ent) then
6018 Set_Is_Known_Non_Null (Ent, False);
6019 end if;
6021 Set_Is_Known_Null (Ent, False);
6022 end if;
6023 end Kill_Current_Values;
6025 procedure Kill_Current_Values is
6026 S : Entity_Id;
6028 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
6029 -- Clear current value for entity E and all entities chained to E
6031 ------------------------------------------
6032 -- Kill_Current_Values_For_Entity_Chain --
6033 ------------------------------------------
6035 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
6036 Ent : Entity_Id;
6037 begin
6038 Ent := E;
6039 while Present (Ent) loop
6040 Kill_Current_Values (Ent);
6041 Next_Entity (Ent);
6042 end loop;
6043 end Kill_Current_Values_For_Entity_Chain;
6045 -- Start of processing for Kill_Current_Values
6047 begin
6048 -- Kill all saved checks, a special case of killing saved values
6050 Kill_All_Checks;
6052 -- Loop through relevant scopes, which includes the current scope and
6053 -- any parent scopes if the current scope is a block or a package.
6055 S := Current_Scope;
6056 Scope_Loop : loop
6058 -- Clear current values of all entities in current scope
6060 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
6062 -- If scope is a package, also clear current values of all
6063 -- private entities in the scope.
6065 if Ekind (S) = E_Package
6066 or else
6067 Ekind (S) = E_Generic_Package
6068 or else
6069 Is_Concurrent_Type (S)
6070 then
6071 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
6072 end if;
6074 -- If this is a not a subprogram, deal with parents
6076 if not Is_Subprogram (S) then
6077 S := Scope (S);
6078 exit Scope_Loop when S = Standard_Standard;
6079 else
6080 exit Scope_Loop;
6081 end if;
6082 end loop Scope_Loop;
6083 end Kill_Current_Values;
6085 --------------------------
6086 -- Kill_Size_Check_Code --
6087 --------------------------
6089 procedure Kill_Size_Check_Code (E : Entity_Id) is
6090 begin
6091 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6092 and then Present (Size_Check_Code (E))
6093 then
6094 Remove (Size_Check_Code (E));
6095 Set_Size_Check_Code (E, Empty);
6096 end if;
6097 end Kill_Size_Check_Code;
6099 --------------------------
6100 -- Known_To_Be_Assigned --
6101 --------------------------
6103 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
6104 P : constant Node_Id := Parent (N);
6106 begin
6107 case Nkind (P) is
6109 -- Test left side of assignment
6111 when N_Assignment_Statement =>
6112 return N = Name (P);
6114 -- Function call arguments are never lvalues
6116 when N_Function_Call =>
6117 return False;
6119 -- Positional parameter for procedure or accept call
6121 when N_Procedure_Call_Statement |
6122 N_Accept_Statement
6124 declare
6125 Proc : Entity_Id;
6126 Form : Entity_Id;
6127 Act : Node_Id;
6129 begin
6130 Proc := Get_Subprogram_Entity (P);
6132 if No (Proc) then
6133 return False;
6134 end if;
6136 -- If we are not a list member, something is strange, so
6137 -- be conservative and return False.
6139 if not Is_List_Member (N) then
6140 return False;
6141 end if;
6143 -- We are going to find the right formal by stepping forward
6144 -- through the formals, as we step backwards in the actuals.
6146 Form := First_Formal (Proc);
6147 Act := N;
6148 loop
6149 -- If no formal, something is weird, so be conservative
6150 -- and return False.
6152 if No (Form) then
6153 return False;
6154 end if;
6156 Prev (Act);
6157 exit when No (Act);
6158 Next_Formal (Form);
6159 end loop;
6161 return Ekind (Form) /= E_In_Parameter;
6162 end;
6164 -- Named parameter for procedure or accept call
6166 when N_Parameter_Association =>
6167 declare
6168 Proc : Entity_Id;
6169 Form : Entity_Id;
6171 begin
6172 Proc := Get_Subprogram_Entity (Parent (P));
6174 if No (Proc) then
6175 return False;
6176 end if;
6178 -- Loop through formals to find the one that matches
6180 Form := First_Formal (Proc);
6181 loop
6182 -- If no matching formal, that's peculiar, some kind of
6183 -- previous error, so return False to be conservative.
6185 if No (Form) then
6186 return False;
6187 end if;
6189 -- Else test for match
6191 if Chars (Form) = Chars (Selector_Name (P)) then
6192 return Ekind (Form) /= E_In_Parameter;
6193 end if;
6195 Next_Formal (Form);
6196 end loop;
6197 end;
6199 -- Test for appearing in a conversion that itself appears
6200 -- in an lvalue context, since this should be an lvalue.
6202 when N_Type_Conversion =>
6203 return Known_To_Be_Assigned (P);
6205 -- All other references are definitely not knwon to be modifications
6207 when others =>
6208 return False;
6210 end case;
6211 end Known_To_Be_Assigned;
6213 -------------------
6214 -- May_Be_Lvalue --
6215 -------------------
6217 function May_Be_Lvalue (N : Node_Id) return Boolean is
6218 P : constant Node_Id := Parent (N);
6220 begin
6221 case Nkind (P) is
6223 -- Test left side of assignment
6225 when N_Assignment_Statement =>
6226 return N = Name (P);
6228 -- Test prefix of component or attribute
6230 when N_Attribute_Reference |
6231 N_Expanded_Name |
6232 N_Explicit_Dereference |
6233 N_Indexed_Component |
6234 N_Reference |
6235 N_Selected_Component |
6236 N_Slice =>
6237 return N = Prefix (P);
6239 -- Function call arguments are never lvalues
6241 when N_Function_Call =>
6242 return False;
6244 -- Positional parameter for procedure or accept call
6246 when N_Procedure_Call_Statement |
6247 N_Accept_Statement
6249 declare
6250 Proc : Entity_Id;
6251 Form : Entity_Id;
6252 Act : Node_Id;
6254 begin
6255 Proc := Get_Subprogram_Entity (P);
6257 if No (Proc) then
6258 return True;
6259 end if;
6261 -- If we are not a list member, something is strange, so
6262 -- be conservative and return True.
6264 if not Is_List_Member (N) then
6265 return True;
6266 end if;
6268 -- We are going to find the right formal by stepping forward
6269 -- through the formals, as we step backwards in the actuals.
6271 Form := First_Formal (Proc);
6272 Act := N;
6273 loop
6274 -- If no formal, something is weird, so be conservative
6275 -- and return True.
6277 if No (Form) then
6278 return True;
6279 end if;
6281 Prev (Act);
6282 exit when No (Act);
6283 Next_Formal (Form);
6284 end loop;
6286 return Ekind (Form) /= E_In_Parameter;
6287 end;
6289 -- Named parameter for procedure or accept call
6291 when N_Parameter_Association =>
6292 declare
6293 Proc : Entity_Id;
6294 Form : Entity_Id;
6296 begin
6297 Proc := Get_Subprogram_Entity (Parent (P));
6299 if No (Proc) then
6300 return True;
6301 end if;
6303 -- Loop through formals to find the one that matches
6305 Form := First_Formal (Proc);
6306 loop
6307 -- If no matching formal, that's peculiar, some kind of
6308 -- previous error, so return True to be conservative.
6310 if No (Form) then
6311 return True;
6312 end if;
6314 -- Else test for match
6316 if Chars (Form) = Chars (Selector_Name (P)) then
6317 return Ekind (Form) /= E_In_Parameter;
6318 end if;
6320 Next_Formal (Form);
6321 end loop;
6322 end;
6324 -- Test for appearing in a conversion that itself appears
6325 -- in an lvalue context, since this should be an lvalue.
6327 when N_Type_Conversion =>
6328 return May_Be_Lvalue (P);
6330 -- Test for appearence in object renaming declaration
6332 when N_Object_Renaming_Declaration =>
6333 return True;
6335 -- All other references are definitely not Lvalues
6337 when others =>
6338 return False;
6340 end case;
6341 end May_Be_Lvalue;
6343 -------------------------
6344 -- New_External_Entity --
6345 -------------------------
6347 function New_External_Entity
6348 (Kind : Entity_Kind;
6349 Scope_Id : Entity_Id;
6350 Sloc_Value : Source_Ptr;
6351 Related_Id : Entity_Id;
6352 Suffix : Character;
6353 Suffix_Index : Nat := 0;
6354 Prefix : Character := ' ') return Entity_Id
6356 N : constant Entity_Id :=
6357 Make_Defining_Identifier (Sloc_Value,
6358 New_External_Name
6359 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
6361 begin
6362 Set_Ekind (N, Kind);
6363 Set_Is_Internal (N, True);
6364 Append_Entity (N, Scope_Id);
6365 Set_Public_Status (N);
6367 if Kind in Type_Kind then
6368 Init_Size_Align (N);
6369 end if;
6371 return N;
6372 end New_External_Entity;
6374 -------------------------
6375 -- New_Internal_Entity --
6376 -------------------------
6378 function New_Internal_Entity
6379 (Kind : Entity_Kind;
6380 Scope_Id : Entity_Id;
6381 Sloc_Value : Source_Ptr;
6382 Id_Char : Character) return Entity_Id
6384 N : constant Entity_Id :=
6385 Make_Defining_Identifier (Sloc_Value, New_Internal_Name (Id_Char));
6387 begin
6388 Set_Ekind (N, Kind);
6389 Set_Is_Internal (N, True);
6390 Append_Entity (N, Scope_Id);
6392 if Kind in Type_Kind then
6393 Init_Size_Align (N);
6394 end if;
6396 return N;
6397 end New_Internal_Entity;
6399 -----------------
6400 -- Next_Actual --
6401 -----------------
6403 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
6404 N : Node_Id;
6406 begin
6407 -- If we are pointing at a positional parameter, it is a member of
6408 -- a node list (the list of parameters), and the next parameter
6409 -- is the next node on the list, unless we hit a parameter
6410 -- association, in which case we shift to using the chain whose
6411 -- head is the First_Named_Actual in the parent, and then is
6412 -- threaded using the Next_Named_Actual of the Parameter_Association.
6413 -- All this fiddling is because the original node list is in the
6414 -- textual call order, and what we need is the declaration order.
6416 if Is_List_Member (Actual_Id) then
6417 N := Next (Actual_Id);
6419 if Nkind (N) = N_Parameter_Association then
6420 return First_Named_Actual (Parent (Actual_Id));
6421 else
6422 return N;
6423 end if;
6425 else
6426 return Next_Named_Actual (Parent (Actual_Id));
6427 end if;
6428 end Next_Actual;
6430 procedure Next_Actual (Actual_Id : in out Node_Id) is
6431 begin
6432 Actual_Id := Next_Actual (Actual_Id);
6433 end Next_Actual;
6435 -----------------------
6436 -- Normalize_Actuals --
6437 -----------------------
6439 -- Chain actuals according to formals of subprogram. If there are no named
6440 -- associations, the chain is simply the list of Parameter Associations,
6441 -- since the order is the same as the declaration order. If there are named
6442 -- associations, then the First_Named_Actual field in the N_Function_Call
6443 -- or N_Procedure_Call_Statement node points to the Parameter_Association
6444 -- node for the parameter that comes first in declaration order. The
6445 -- remaining named parameters are then chained in declaration order using
6446 -- Next_Named_Actual.
6448 -- This routine also verifies that the number of actuals is compatible with
6449 -- the number and default values of formals, but performs no type checking
6450 -- (type checking is done by the caller).
6452 -- If the matching succeeds, Success is set to True and the caller proceeds
6453 -- with type-checking. If the match is unsuccessful, then Success is set to
6454 -- False, and the caller attempts a different interpretation, if there is
6455 -- one.
6457 -- If the flag Report is on, the call is not overloaded, and a failure to
6458 -- match can be reported here, rather than in the caller.
6460 procedure Normalize_Actuals
6461 (N : Node_Id;
6462 S : Entity_Id;
6463 Report : Boolean;
6464 Success : out Boolean)
6466 Actuals : constant List_Id := Parameter_Associations (N);
6467 Actual : Node_Id := Empty;
6468 Formal : Entity_Id;
6469 Last : Node_Id := Empty;
6470 First_Named : Node_Id := Empty;
6471 Found : Boolean;
6473 Formals_To_Match : Integer := 0;
6474 Actuals_To_Match : Integer := 0;
6476 procedure Chain (A : Node_Id);
6477 -- Add named actual at the proper place in the list, using the
6478 -- Next_Named_Actual link.
6480 function Reporting return Boolean;
6481 -- Determines if an error is to be reported. To report an error, we
6482 -- need Report to be True, and also we do not report errors caused
6483 -- by calls to init procs that occur within other init procs. Such
6484 -- errors must always be cascaded errors, since if all the types are
6485 -- declared correctly, the compiler will certainly build decent calls!
6487 -----------
6488 -- Chain --
6489 -----------
6491 procedure Chain (A : Node_Id) is
6492 begin
6493 if No (Last) then
6495 -- Call node points to first actual in list
6497 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
6499 else
6500 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
6501 end if;
6503 Last := A;
6504 Set_Next_Named_Actual (Last, Empty);
6505 end Chain;
6507 ---------------
6508 -- Reporting --
6509 ---------------
6511 function Reporting return Boolean is
6512 begin
6513 if not Report then
6514 return False;
6516 elsif not Within_Init_Proc then
6517 return True;
6519 elsif Is_Init_Proc (Entity (Name (N))) then
6520 return False;
6522 else
6523 return True;
6524 end if;
6525 end Reporting;
6527 -- Start of processing for Normalize_Actuals
6529 begin
6530 if Is_Access_Type (S) then
6532 -- The name in the call is a function call that returns an access
6533 -- to subprogram. The designated type has the list of formals.
6535 Formal := First_Formal (Designated_Type (S));
6536 else
6537 Formal := First_Formal (S);
6538 end if;
6540 while Present (Formal) loop
6541 Formals_To_Match := Formals_To_Match + 1;
6542 Next_Formal (Formal);
6543 end loop;
6545 -- Find if there is a named association, and verify that no positional
6546 -- associations appear after named ones.
6548 if Present (Actuals) then
6549 Actual := First (Actuals);
6550 end if;
6552 while Present (Actual)
6553 and then Nkind (Actual) /= N_Parameter_Association
6554 loop
6555 Actuals_To_Match := Actuals_To_Match + 1;
6556 Next (Actual);
6557 end loop;
6559 if No (Actual) and Actuals_To_Match = Formals_To_Match then
6561 -- Most common case: positional notation, no defaults
6563 Success := True;
6564 return;
6566 elsif Actuals_To_Match > Formals_To_Match then
6568 -- Too many actuals: will not work
6570 if Reporting then
6571 if Is_Entity_Name (Name (N)) then
6572 Error_Msg_N ("too many arguments in call to&", Name (N));
6573 else
6574 Error_Msg_N ("too many arguments in call", N);
6575 end if;
6576 end if;
6578 Success := False;
6579 return;
6580 end if;
6582 First_Named := Actual;
6584 while Present (Actual) loop
6585 if Nkind (Actual) /= N_Parameter_Association then
6586 Error_Msg_N
6587 ("positional parameters not allowed after named ones", Actual);
6588 Success := False;
6589 return;
6591 else
6592 Actuals_To_Match := Actuals_To_Match + 1;
6593 end if;
6595 Next (Actual);
6596 end loop;
6598 if Present (Actuals) then
6599 Actual := First (Actuals);
6600 end if;
6602 Formal := First_Formal (S);
6603 while Present (Formal) loop
6605 -- Match the formals in order. If the corresponding actual
6606 -- is positional, nothing to do. Else scan the list of named
6607 -- actuals to find the one with the right name.
6609 if Present (Actual)
6610 and then Nkind (Actual) /= N_Parameter_Association
6611 then
6612 Next (Actual);
6613 Actuals_To_Match := Actuals_To_Match - 1;
6614 Formals_To_Match := Formals_To_Match - 1;
6616 else
6617 -- For named parameters, search the list of actuals to find
6618 -- one that matches the next formal name.
6620 Actual := First_Named;
6621 Found := False;
6622 while Present (Actual) loop
6623 if Chars (Selector_Name (Actual)) = Chars (Formal) then
6624 Found := True;
6625 Chain (Actual);
6626 Actuals_To_Match := Actuals_To_Match - 1;
6627 Formals_To_Match := Formals_To_Match - 1;
6628 exit;
6629 end if;
6631 Next (Actual);
6632 end loop;
6634 if not Found then
6635 if Ekind (Formal) /= E_In_Parameter
6636 or else No (Default_Value (Formal))
6637 then
6638 if Reporting then
6639 if (Comes_From_Source (S)
6640 or else Sloc (S) = Standard_Location)
6641 and then Is_Overloadable (S)
6642 then
6643 if No (Actuals)
6644 and then
6645 (Nkind (Parent (N)) = N_Procedure_Call_Statement
6646 or else
6647 (Nkind (Parent (N)) = N_Function_Call
6648 or else
6649 Nkind (Parent (N)) = N_Parameter_Association))
6650 and then Ekind (S) /= E_Function
6651 then
6652 Set_Etype (N, Etype (S));
6653 else
6654 Error_Msg_Name_1 := Chars (S);
6655 Error_Msg_Sloc := Sloc (S);
6656 Error_Msg_NE
6657 ("missing argument for parameter & " &
6658 "in call to % declared #", N, Formal);
6659 end if;
6661 elsif Is_Overloadable (S) then
6662 Error_Msg_Name_1 := Chars (S);
6664 -- Point to type derivation that generated the
6665 -- operation.
6667 Error_Msg_Sloc := Sloc (Parent (S));
6669 Error_Msg_NE
6670 ("missing argument for parameter & " &
6671 "in call to % (inherited) #", N, Formal);
6673 else
6674 Error_Msg_NE
6675 ("missing argument for parameter &", N, Formal);
6676 end if;
6677 end if;
6679 Success := False;
6680 return;
6682 else
6683 Formals_To_Match := Formals_To_Match - 1;
6684 end if;
6685 end if;
6686 end if;
6688 Next_Formal (Formal);
6689 end loop;
6691 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
6692 Success := True;
6693 return;
6695 else
6696 if Reporting then
6698 -- Find some superfluous named actual that did not get
6699 -- attached to the list of associations.
6701 Actual := First (Actuals);
6702 while Present (Actual) loop
6703 if Nkind (Actual) = N_Parameter_Association
6704 and then Actual /= Last
6705 and then No (Next_Named_Actual (Actual))
6706 then
6707 Error_Msg_N ("unmatched actual & in call",
6708 Selector_Name (Actual));
6709 exit;
6710 end if;
6712 Next (Actual);
6713 end loop;
6714 end if;
6716 Success := False;
6717 return;
6718 end if;
6719 end Normalize_Actuals;
6721 --------------------------------
6722 -- Note_Possible_Modification --
6723 --------------------------------
6725 procedure Note_Possible_Modification (N : Node_Id) is
6726 Modification_Comes_From_Source : constant Boolean :=
6727 Comes_From_Source (Parent (N));
6729 Ent : Entity_Id;
6730 Exp : Node_Id;
6732 begin
6733 -- Loop to find referenced entity, if there is one
6735 Exp := N;
6736 loop
6737 <<Continue>>
6738 Ent := Empty;
6740 if Is_Entity_Name (Exp) then
6741 Ent := Entity (Exp);
6743 -- If the entity is missing, it is an undeclared identifier,
6744 -- and there is nothing to annotate.
6746 if No (Ent) then
6747 return;
6748 end if;
6750 elsif Nkind (Exp) = N_Explicit_Dereference then
6751 declare
6752 P : constant Node_Id := Prefix (Exp);
6754 begin
6755 if Nkind (P) = N_Selected_Component
6756 and then Present (
6757 Entry_Formal (Entity (Selector_Name (P))))
6758 then
6759 -- Case of a reference to an entry formal
6761 Ent := Entry_Formal (Entity (Selector_Name (P)));
6763 elsif Nkind (P) = N_Identifier
6764 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
6765 and then Present (Expression (Parent (Entity (P))))
6766 and then Nkind (Expression (Parent (Entity (P))))
6767 = N_Reference
6768 then
6769 -- Case of a reference to a value on which
6770 -- side effects have been removed.
6772 Exp := Prefix (Expression (Parent (Entity (P))));
6773 goto Continue;
6775 else
6776 return;
6778 end if;
6779 end;
6781 elsif Nkind (Exp) = N_Type_Conversion
6782 or else Nkind (Exp) = N_Unchecked_Type_Conversion
6783 then
6784 Exp := Expression (Exp);
6785 goto Continue;
6787 elsif Nkind (Exp) = N_Slice
6788 or else Nkind (Exp) = N_Indexed_Component
6789 or else Nkind (Exp) = N_Selected_Component
6790 then
6791 Exp := Prefix (Exp);
6792 goto Continue;
6794 else
6795 return;
6796 end if;
6798 -- Now look for entity being referenced
6800 if Present (Ent) then
6801 if Is_Object (Ent) then
6802 if Comes_From_Source (Exp)
6803 or else Modification_Comes_From_Source
6804 then
6805 Set_Never_Set_In_Source (Ent, False);
6806 end if;
6808 Set_Is_True_Constant (Ent, False);
6809 Set_Current_Value (Ent, Empty);
6810 Set_Is_Known_Null (Ent, False);
6812 if not Can_Never_Be_Null (Ent) then
6813 Set_Is_Known_Non_Null (Ent, False);
6814 end if;
6816 -- Follow renaming chain
6818 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
6819 and then Present (Renamed_Object (Ent))
6820 then
6821 Exp := Renamed_Object (Ent);
6822 goto Continue;
6823 end if;
6825 -- Generate a reference only if the assignment comes from
6826 -- source. This excludes, for example, calls to a dispatching
6827 -- assignment operation when the left-hand side is tagged.
6829 if Modification_Comes_From_Source then
6830 Generate_Reference (Ent, Exp, 'm');
6831 end if;
6832 end if;
6834 Kill_Checks (Ent);
6835 return;
6836 end if;
6837 end loop;
6838 end Note_Possible_Modification;
6840 -------------------------
6841 -- Object_Access_Level --
6842 -------------------------
6844 function Object_Access_Level (Obj : Node_Id) return Uint is
6845 E : Entity_Id;
6847 -- Returns the static accessibility level of the view denoted
6848 -- by Obj. Note that the value returned is the result of a
6849 -- call to Scope_Depth. Only scope depths associated with
6850 -- dynamic scopes can actually be returned. Since only
6851 -- relative levels matter for accessibility checking, the fact
6852 -- that the distance between successive levels of accessibility
6853 -- is not always one is immaterial (invariant: if level(E2) is
6854 -- deeper than level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
6856 begin
6857 if Is_Entity_Name (Obj) then
6858 E := Entity (Obj);
6860 -- If E is a type then it denotes a current instance.
6861 -- For this case we add one to the normal accessibility
6862 -- level of the type to ensure that current instances
6863 -- are treated as always being deeper than than the level
6864 -- of any visible named access type (see 3.10.2(21)).
6866 if Is_Type (E) then
6867 return Type_Access_Level (E) + 1;
6869 elsif Present (Renamed_Object (E)) then
6870 return Object_Access_Level (Renamed_Object (E));
6872 -- Similarly, if E is a component of the current instance of a
6873 -- protected type, any instance of it is assumed to be at a deeper
6874 -- level than the type. For a protected object (whose type is an
6875 -- anonymous protected type) its components are at the same level
6876 -- as the type itself.
6878 elsif not Is_Overloadable (E)
6879 and then Ekind (Scope (E)) = E_Protected_Type
6880 and then Comes_From_Source (Scope (E))
6881 then
6882 return Type_Access_Level (Scope (E)) + 1;
6884 else
6885 return Scope_Depth (Enclosing_Dynamic_Scope (E));
6886 end if;
6888 elsif Nkind (Obj) = N_Selected_Component then
6889 if Is_Access_Type (Etype (Prefix (Obj))) then
6890 return Type_Access_Level (Etype (Prefix (Obj)));
6891 else
6892 return Object_Access_Level (Prefix (Obj));
6893 end if;
6895 elsif Nkind (Obj) = N_Indexed_Component then
6896 if Is_Access_Type (Etype (Prefix (Obj))) then
6897 return Type_Access_Level (Etype (Prefix (Obj)));
6898 else
6899 return Object_Access_Level (Prefix (Obj));
6900 end if;
6902 elsif Nkind (Obj) = N_Explicit_Dereference then
6904 -- If the prefix is a selected access discriminant then
6905 -- we make a recursive call on the prefix, which will
6906 -- in turn check the level of the prefix object of
6907 -- the selected discriminant.
6909 if Nkind (Prefix (Obj)) = N_Selected_Component
6910 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
6911 and then
6912 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
6913 then
6914 return Object_Access_Level (Prefix (Obj));
6915 else
6916 return Type_Access_Level (Etype (Prefix (Obj)));
6917 end if;
6919 elsif Nkind (Obj) = N_Type_Conversion
6920 or else Nkind (Obj) = N_Unchecked_Type_Conversion
6921 then
6922 return Object_Access_Level (Expression (Obj));
6924 -- Function results are objects, so we get either the access level
6925 -- of the function or, in the case of an indirect call, the level of
6926 -- of the access-to-subprogram type.
6928 elsif Nkind (Obj) = N_Function_Call then
6929 if Is_Entity_Name (Name (Obj)) then
6930 return Subprogram_Access_Level (Entity (Name (Obj)));
6931 else
6932 return Type_Access_Level (Etype (Prefix (Name (Obj))));
6933 end if;
6935 -- For convenience we handle qualified expressions, even though
6936 -- they aren't technically object names.
6938 elsif Nkind (Obj) = N_Qualified_Expression then
6939 return Object_Access_Level (Expression (Obj));
6941 -- Otherwise return the scope level of Standard.
6942 -- (If there are cases that fall through
6943 -- to this point they will be treated as
6944 -- having global accessibility for now. ???)
6946 else
6947 return Scope_Depth (Standard_Standard);
6948 end if;
6949 end Object_Access_Level;
6951 --------------------------------------
6952 -- Overrides_Synchronized_Primitive --
6953 --------------------------------------
6955 function Overrides_Synchronized_Primitive
6956 (Def_Id : Entity_Id;
6957 First_Hom : Entity_Id;
6958 Ifaces_List : Elist_Id;
6959 In_Scope : Boolean := True) return Entity_Id
6961 Candidate : Entity_Id;
6962 Hom : Entity_Id;
6964 function Matches_Prefixed_View_Profile
6965 (Subp_Params : List_Id;
6966 Over_Params : List_Id) return Boolean;
6967 -- Determine if a subprogram parameter profile (Subp_Params)
6968 -- matches that of a potentially overriden subprogram (Over_Params).
6969 -- Determine if the type of first parameter in the list Over_Params
6970 -- is an implemented interface, that is to say, the interface is in
6971 -- Ifaces_List.
6973 -----------------------------------
6974 -- Matches_Prefixed_View_Profile --
6975 -----------------------------------
6977 function Matches_Prefixed_View_Profile
6978 (Subp_Params : List_Id;
6979 Over_Params : List_Id) return Boolean
6981 Subp_Param : Node_Id;
6982 Over_Param : Node_Id;
6983 Over_Param_Typ : Entity_Id;
6985 function Is_Implemented (Iface : Entity_Id) return Boolean;
6986 -- Determine if Iface is implemented by the current task or
6987 -- protected type.
6989 --------------------
6990 -- Is_Implemented --
6991 --------------------
6993 function Is_Implemented (Iface : Entity_Id) return Boolean is
6994 Iface_Elmt : Elmt_Id;
6996 begin
6997 Iface_Elmt := First_Elmt (Ifaces_List);
6998 while Present (Iface_Elmt) loop
6999 if Node (Iface_Elmt) = Iface then
7000 return True;
7001 end if;
7003 Next_Elmt (Iface_Elmt);
7004 end loop;
7006 return False;
7007 end Is_Implemented;
7009 -- Start of processing for Matches_Prefixed_View_Profile
7011 begin
7012 Subp_Param := First (Subp_Params);
7013 Over_Param := First (Over_Params);
7015 if Nkind (Parameter_Type (Over_Param)) = N_Access_Definition then
7016 Over_Param_Typ :=
7017 Etype (Subtype_Mark (Parameter_Type (Over_Param)));
7018 else
7019 Over_Param_Typ := Etype (Parameter_Type (Over_Param));
7020 end if;
7022 -- The first parameter of the potentially overriden subprogram
7023 -- must be an interface implemented by Def_Id.
7025 if not Is_Interface (Over_Param_Typ)
7026 or else not Is_Implemented (Over_Param_Typ)
7027 then
7028 return False;
7029 end if;
7031 -- This may be a primitive declared after a task or protected type.
7032 -- We need to skip the first parameter since it is irrelevant.
7034 if not In_Scope then
7035 Subp_Param := Next (Subp_Param);
7036 end if;
7037 Over_Param := Next (Over_Param);
7039 while Present (Subp_Param) and then Present (Over_Param) loop
7041 -- The two parameters must be mode conformant and both types
7042 -- must be the same.
7044 if Ekind (Defining_Identifier (Subp_Param)) /=
7045 Ekind (Defining_Identifier (Over_Param))
7046 or else
7047 Etype (Parameter_Type (Subp_Param)) /=
7048 Etype (Parameter_Type (Over_Param))
7049 then
7050 return False;
7051 end if;
7053 Next (Subp_Param);
7054 Next (Over_Param);
7055 end loop;
7057 -- One of the two lists contains more parameters than the other
7059 if Present (Subp_Param) or else Present (Over_Param) then
7060 return False;
7061 end if;
7063 return True;
7064 end Matches_Prefixed_View_Profile;
7066 -- Start of processing for Overrides_Synchronized_Primitive
7068 begin
7069 -- At this point the caller should have collected the interfaces
7070 -- implemented by the synchronized type.
7072 pragma Assert (Present (Ifaces_List));
7074 -- Traverse the homonym chain, looking at a potentially overriden
7075 -- subprogram that belongs to an implemented interface.
7077 Hom := First_Hom;
7078 while Present (Hom) loop
7079 Candidate := Hom;
7081 -- Entries can override abstract or null interface procedures
7083 if Ekind (Def_Id) = E_Entry
7084 and then Ekind (Candidate) = E_Procedure
7085 and then Nkind (Parent (Candidate)) = N_Procedure_Specification
7086 and then (Is_Abstract (Candidate)
7087 or else Null_Present (Parent (Candidate)))
7088 then
7089 while Present (Alias (Candidate)) loop
7090 Candidate := Alias (Candidate);
7091 end loop;
7093 if Matches_Prefixed_View_Profile
7094 (Parameter_Specifications (Parent (Def_Id)),
7095 Parameter_Specifications (Parent (Candidate)))
7096 then
7097 return Candidate;
7098 end if;
7100 -- Procedure can override abstract or null interface procedures
7102 elsif Ekind (Def_Id) = E_Procedure
7103 and then Ekind (Candidate) = E_Procedure
7104 and then Nkind (Parent (Candidate)) = N_Procedure_Specification
7105 and then (Is_Abstract (Candidate)
7106 or else Null_Present (Parent (Candidate)))
7107 and then Matches_Prefixed_View_Profile
7108 (Parameter_Specifications (Parent (Def_Id)),
7109 Parameter_Specifications (Parent (Candidate)))
7110 then
7111 return Candidate;
7113 -- Function can override abstract interface functions
7115 elsif Ekind (Def_Id) = E_Function
7116 and then Ekind (Candidate) = E_Function
7117 and then Nkind (Parent (Candidate)) = N_Function_Specification
7118 and then Is_Abstract (Candidate)
7119 and then Matches_Prefixed_View_Profile
7120 (Parameter_Specifications (Parent (Def_Id)),
7121 Parameter_Specifications (Parent (Candidate)))
7122 and then Etype (Result_Definition (Parent (Def_Id))) =
7123 Etype (Result_Definition (Parent (Candidate)))
7124 then
7125 return Candidate;
7126 end if;
7128 Hom := Homonym (Hom);
7129 end loop;
7131 return Empty;
7132 end Overrides_Synchronized_Primitive;
7134 -----------------------
7135 -- Private_Component --
7136 -----------------------
7138 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
7139 Ancestor : constant Entity_Id := Base_Type (Type_Id);
7141 function Trace_Components
7142 (T : Entity_Id;
7143 Check : Boolean) return Entity_Id;
7144 -- Recursive function that does the work, and checks against circular
7145 -- definition for each subcomponent type.
7147 ----------------------
7148 -- Trace_Components --
7149 ----------------------
7151 function Trace_Components
7152 (T : Entity_Id;
7153 Check : Boolean) return Entity_Id
7155 Btype : constant Entity_Id := Base_Type (T);
7156 Component : Entity_Id;
7157 P : Entity_Id;
7158 Candidate : Entity_Id := Empty;
7160 begin
7161 if Check and then Btype = Ancestor then
7162 Error_Msg_N ("circular type definition", Type_Id);
7163 return Any_Type;
7164 end if;
7166 if Is_Private_Type (Btype)
7167 and then not Is_Generic_Type (Btype)
7168 then
7169 if Present (Full_View (Btype))
7170 and then Is_Record_Type (Full_View (Btype))
7171 and then not Is_Frozen (Btype)
7172 then
7173 -- To indicate that the ancestor depends on a private type,
7174 -- the current Btype is sufficient. However, to check for
7175 -- circular definition we must recurse on the full view.
7177 Candidate := Trace_Components (Full_View (Btype), True);
7179 if Candidate = Any_Type then
7180 return Any_Type;
7181 else
7182 return Btype;
7183 end if;
7185 else
7186 return Btype;
7187 end if;
7189 elsif Is_Array_Type (Btype) then
7190 return Trace_Components (Component_Type (Btype), True);
7192 elsif Is_Record_Type (Btype) then
7193 Component := First_Entity (Btype);
7194 while Present (Component) loop
7196 -- Skip anonymous types generated by constrained components
7198 if not Is_Type (Component) then
7199 P := Trace_Components (Etype (Component), True);
7201 if Present (P) then
7202 if P = Any_Type then
7203 return P;
7204 else
7205 Candidate := P;
7206 end if;
7207 end if;
7208 end if;
7210 Next_Entity (Component);
7211 end loop;
7213 return Candidate;
7215 else
7216 return Empty;
7217 end if;
7218 end Trace_Components;
7220 -- Start of processing for Private_Component
7222 begin
7223 return Trace_Components (Type_Id, False);
7224 end Private_Component;
7226 -----------------------
7227 -- Process_End_Label --
7228 -----------------------
7230 procedure Process_End_Label
7231 (N : Node_Id;
7232 Typ : Character;
7233 Ent : Entity_Id)
7235 Loc : Source_Ptr;
7236 Nam : Node_Id;
7238 Label_Ref : Boolean;
7239 -- Set True if reference to end label itself is required
7241 Endl : Node_Id;
7242 -- Gets set to the operator symbol or identifier that references
7243 -- the entity Ent. For the child unit case, this is the identifier
7244 -- from the designator. For other cases, this is simply Endl.
7246 procedure Generate_Parent_Ref (N : Node_Id);
7247 -- N is an identifier node that appears as a parent unit reference
7248 -- in the case where Ent is a child unit. This procedure generates
7249 -- an appropriate cross-reference entry.
7251 -------------------------
7252 -- Generate_Parent_Ref --
7253 -------------------------
7255 procedure Generate_Parent_Ref (N : Node_Id) is
7256 Parent_Ent : Entity_Id;
7258 begin
7259 -- Search up scope stack. The reason we do this is that normal
7260 -- visibility analysis would not work for two reasons. First in
7261 -- some subunit cases, the entry for the parent unit may not be
7262 -- visible, and in any case there can be a local entity that
7263 -- hides the scope entity.
7265 Parent_Ent := Current_Scope;
7266 while Present (Parent_Ent) loop
7267 if Chars (Parent_Ent) = Chars (N) then
7269 -- Generate the reference. We do NOT consider this as a
7270 -- reference for unreferenced symbol purposes, but we do
7271 -- force a cross-reference even if the end line does not
7272 -- come from source (the caller already generated the
7273 -- appropriate Typ for this situation).
7275 Generate_Reference
7276 (Parent_Ent, N, 'r', Set_Ref => False, Force => True);
7277 Style.Check_Identifier (N, Parent_Ent);
7278 return;
7279 end if;
7281 Parent_Ent := Scope (Parent_Ent);
7282 end loop;
7284 -- Fall through means entity was not found -- that's odd, but
7285 -- the appropriate thing is simply to ignore and not generate
7286 -- any cross-reference for this entry.
7288 return;
7289 end Generate_Parent_Ref;
7291 -- Start of processing for Process_End_Label
7293 begin
7294 -- If no node, ignore. This happens in some error situations,
7295 -- and also for some internally generated structures where no
7296 -- end label references are required in any case.
7298 if No (N) then
7299 return;
7300 end if;
7302 -- Nothing to do if no End_Label, happens for internally generated
7303 -- constructs where we don't want an end label reference anyway.
7304 -- Also nothing to do if Endl is a string literal, which means
7305 -- there was some prior error (bad operator symbol)
7307 Endl := End_Label (N);
7309 if No (Endl) or else Nkind (Endl) = N_String_Literal then
7310 return;
7311 end if;
7313 -- Reference node is not in extended main source unit
7315 if not In_Extended_Main_Source_Unit (N) then
7317 -- Generally we do not collect references except for the
7318 -- extended main source unit. The one exception is the 'e'
7319 -- entry for a package spec, where it is useful for a client
7320 -- to have the ending information to define scopes.
7322 if Typ /= 'e' then
7323 return;
7325 else
7326 Label_Ref := False;
7328 -- For this case, we can ignore any parent references,
7329 -- but we need the package name itself for the 'e' entry.
7331 if Nkind (Endl) = N_Designator then
7332 Endl := Identifier (Endl);
7333 end if;
7334 end if;
7336 -- Reference is in extended main source unit
7338 else
7339 Label_Ref := True;
7341 -- For designator, generate references for the parent entries
7343 if Nkind (Endl) = N_Designator then
7345 -- Generate references for the prefix if the END line comes
7346 -- from source (otherwise we do not need these references)
7348 if Comes_From_Source (Endl) then
7349 Nam := Name (Endl);
7350 while Nkind (Nam) = N_Selected_Component loop
7351 Generate_Parent_Ref (Selector_Name (Nam));
7352 Nam := Prefix (Nam);
7353 end loop;
7355 Generate_Parent_Ref (Nam);
7356 end if;
7358 Endl := Identifier (Endl);
7359 end if;
7360 end if;
7362 -- If the end label is not for the given entity, then either we have
7363 -- some previous error, or this is a generic instantiation for which
7364 -- we do not need to make a cross-reference in this case anyway. In
7365 -- either case we simply ignore the call.
7367 if Chars (Ent) /= Chars (Endl) then
7368 return;
7369 end if;
7371 -- If label was really there, then generate a normal reference
7372 -- and then adjust the location in the end label to point past
7373 -- the name (which should almost always be the semicolon).
7375 Loc := Sloc (Endl);
7377 if Comes_From_Source (Endl) then
7379 -- If a label reference is required, then do the style check
7380 -- and generate an l-type cross-reference entry for the label
7382 if Label_Ref then
7383 if Style_Check then
7384 Style.Check_Identifier (Endl, Ent);
7385 end if;
7386 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
7387 end if;
7389 -- Set the location to point past the label (normally this will
7390 -- mean the semicolon immediately following the label). This is
7391 -- done for the sake of the 'e' or 't' entry generated below.
7393 Get_Decoded_Name_String (Chars (Endl));
7394 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
7395 end if;
7397 -- Now generate the e/t reference
7399 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
7401 -- Restore Sloc, in case modified above, since we have an identifier
7402 -- and the normal Sloc should be left set in the tree.
7404 Set_Sloc (Endl, Loc);
7405 end Process_End_Label;
7407 ------------------
7408 -- Real_Convert --
7409 ------------------
7411 -- We do the conversion to get the value of the real string by using
7412 -- the scanner, see Sinput for details on use of the internal source
7413 -- buffer for scanning internal strings.
7415 function Real_Convert (S : String) return Node_Id is
7416 Save_Src : constant Source_Buffer_Ptr := Source;
7417 Negative : Boolean;
7419 begin
7420 Source := Internal_Source_Ptr;
7421 Scan_Ptr := 1;
7423 for J in S'Range loop
7424 Source (Source_Ptr (J)) := S (J);
7425 end loop;
7427 Source (S'Length + 1) := EOF;
7429 if Source (Scan_Ptr) = '-' then
7430 Negative := True;
7431 Scan_Ptr := Scan_Ptr + 1;
7432 else
7433 Negative := False;
7434 end if;
7436 Scan;
7438 if Negative then
7439 Set_Realval (Token_Node, UR_Negate (Realval (Token_Node)));
7440 end if;
7442 Source := Save_Src;
7443 return Token_Node;
7444 end Real_Convert;
7446 ---------------------
7447 -- Rep_To_Pos_Flag --
7448 ---------------------
7450 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
7451 begin
7452 return New_Occurrence_Of
7453 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
7454 end Rep_To_Pos_Flag;
7456 --------------------
7457 -- Require_Entity --
7458 --------------------
7460 procedure Require_Entity (N : Node_Id) is
7461 begin
7462 if Is_Entity_Name (N) and then No (Entity (N)) then
7463 if Total_Errors_Detected /= 0 then
7464 Set_Entity (N, Any_Id);
7465 else
7466 raise Program_Error;
7467 end if;
7468 end if;
7469 end Require_Entity;
7471 ------------------------------
7472 -- Requires_Transient_Scope --
7473 ------------------------------
7475 -- A transient scope is required when variable-sized temporaries are
7476 -- allocated in the primary or secondary stack, or when finalization
7477 -- actions must be generated before the next instruction.
7479 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
7480 Typ : constant Entity_Id := Underlying_Type (Id);
7482 -- Start of processing for Requires_Transient_Scope
7484 begin
7485 -- This is a private type which is not completed yet. This can only
7486 -- happen in a default expression (of a formal parameter or of a
7487 -- record component). Do not expand transient scope in this case
7489 if No (Typ) then
7490 return False;
7492 -- Do not expand transient scope for non-existent procedure return
7494 elsif Typ = Standard_Void_Type then
7495 return False;
7497 -- Elementary types do not require a transient scope
7499 elsif Is_Elementary_Type (Typ) then
7500 return False;
7502 -- Generally, indefinite subtypes require a transient scope, since the
7503 -- back end cannot generate temporaries, since this is not a valid type
7504 -- for declaring an object. It might be possible to relax this in the
7505 -- future, e.g. by declaring the maximum possible space for the type.
7507 elsif Is_Indefinite_Subtype (Typ) then
7508 return True;
7510 -- Functions returning tagged types may dispatch on result so their
7511 -- returned value is allocated on the secondary stack. Controlled
7512 -- type temporaries need finalization.
7514 elsif Is_Tagged_Type (Typ)
7515 or else Has_Controlled_Component (Typ)
7516 then
7517 return True;
7519 -- Record type
7521 elsif Is_Record_Type (Typ) then
7523 -- In GCC 2, discriminated records always require a transient
7524 -- scope because the back end otherwise tries to allocate a
7525 -- variable length temporary for the particular variant.
7527 if Opt.GCC_Version = 2
7528 and then Has_Discriminants (Typ)
7529 then
7530 return True;
7532 -- For GCC 3, or for a non-discriminated record in GCC 2, we are
7533 -- OK if none of the component types requires a transient scope.
7534 -- Note that we already know that this is a definite type (i.e.
7535 -- has discriminant defaults if it is a discriminated record).
7537 else
7538 declare
7539 Comp : Entity_Id;
7540 begin
7541 Comp := First_Entity (Typ);
7542 while Present (Comp) loop
7543 if Ekind (Comp) = E_Component
7544 and then Requires_Transient_Scope (Etype (Comp))
7545 then
7546 return True;
7547 else
7548 Next_Entity (Comp);
7549 end if;
7550 end loop;
7551 end;
7553 return False;
7554 end if;
7556 -- String literal types never require transient scope
7558 elsif Ekind (Typ) = E_String_Literal_Subtype then
7559 return False;
7561 -- Array type. Note that we already know that this is a constrained
7562 -- array, since unconstrained arrays will fail the indefinite test.
7564 elsif Is_Array_Type (Typ) then
7566 -- If component type requires a transient scope, the array does too
7568 if Requires_Transient_Scope (Component_Type (Typ)) then
7569 return True;
7571 -- Otherwise, we only need a transient scope if the size is not
7572 -- known at compile time.
7574 else
7575 return not Size_Known_At_Compile_Time (Typ);
7576 end if;
7578 -- All other cases do not require a transient scope
7580 else
7581 return False;
7582 end if;
7583 end Requires_Transient_Scope;
7585 --------------------------
7586 -- Reset_Analyzed_Flags --
7587 --------------------------
7589 procedure Reset_Analyzed_Flags (N : Node_Id) is
7591 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
7592 -- Function used to reset Analyzed flags in tree. Note that we do
7593 -- not reset Analyzed flags in entities, since there is no need to
7594 -- renalalyze entities, and indeed, it is wrong to do so, since it
7595 -- can result in generating auxiliary stuff more than once.
7597 --------------------
7598 -- Clear_Analyzed --
7599 --------------------
7601 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
7602 begin
7603 if not Has_Extension (N) then
7604 Set_Analyzed (N, False);
7605 end if;
7607 return OK;
7608 end Clear_Analyzed;
7610 function Reset_Analyzed is
7611 new Traverse_Func (Clear_Analyzed);
7613 Discard : Traverse_Result;
7614 pragma Warnings (Off, Discard);
7616 -- Start of processing for Reset_Analyzed_Flags
7618 begin
7619 Discard := Reset_Analyzed (N);
7620 end Reset_Analyzed_Flags;
7622 ---------------------------
7623 -- Safe_To_Capture_Value --
7624 ---------------------------
7626 function Safe_To_Capture_Value
7627 (N : Node_Id;
7628 Ent : Entity_Id;
7629 Cond : Boolean := False) return Boolean
7631 begin
7632 -- The only entities for which we track constant values are variables,
7633 -- which are not renamings, out parameters and in out parameters, so
7634 -- check if we have this case.
7636 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
7637 or else
7638 Ekind (Ent) = E_Out_Parameter
7639 or else
7640 Ekind (Ent) = E_In_Out_Parameter
7641 then
7642 null;
7644 -- For conditionals, we also allow constants, loop parameters and all
7645 -- formals, including in parameters.
7647 elsif Cond
7648 and then
7649 (Ekind (Ent) = E_Constant
7650 or else
7651 Ekind (Ent) = E_Loop_Parameter
7652 or else
7653 Ekind (Ent) = E_In_Parameter)
7654 then
7655 null;
7657 -- For all other cases, not just unsafe, but impossible to capture
7658 -- Current_Value, since the above are the only entities which have
7659 -- Current_Value fields.
7661 else
7662 return False;
7663 end if;
7665 -- Skip volatile and aliased variables, since funny things might
7666 -- be going on in these cases which we cannot necessarily track.
7667 -- Also skip any variable for which an address clause is given.
7669 if Treat_As_Volatile (Ent)
7670 or else Is_Aliased (Ent)
7671 or else Present (Address_Clause (Ent))
7672 then
7673 return False;
7674 end if;
7676 -- OK, all above conditions are met. We also require that the scope
7677 -- of the reference be the same as the scope of the entity, not
7678 -- counting packages and blocks and loops.
7680 declare
7681 E_Scope : constant Entity_Id := Scope (Ent);
7682 R_Scope : Entity_Id;
7684 begin
7685 R_Scope := Current_Scope;
7686 while R_Scope /= Standard_Standard loop
7687 exit when R_Scope = E_Scope;
7689 if Ekind (R_Scope) /= E_Package
7690 and then
7691 Ekind (R_Scope) /= E_Block
7692 and then
7693 Ekind (R_Scope) /= E_Loop
7694 then
7695 return False;
7696 else
7697 R_Scope := Scope (R_Scope);
7698 end if;
7699 end loop;
7700 end;
7702 -- We also require that the reference does not appear in a context
7703 -- where it is not sure to be executed (i.e. a conditional context
7704 -- or an exception handler). We skip this if Cond is True, since the
7705 -- capturing of values from conditional tests handles this ok.
7707 if Cond then
7708 return True;
7709 end if;
7711 declare
7712 Desc : Node_Id;
7713 P : Node_Id;
7715 begin
7716 Desc := N;
7718 P := Parent (N);
7719 while Present (P) loop
7720 if Nkind (P) = N_If_Statement
7721 or else Nkind (P) = N_Case_Statement
7722 or else (Nkind (P) = N_And_Then and then Desc = Right_Opnd (P))
7723 or else (Nkind (P) = N_Or_Else and then Desc = Right_Opnd (P))
7724 or else Nkind (P) = N_Exception_Handler
7725 or else Nkind (P) = N_Selective_Accept
7726 or else Nkind (P) = N_Conditional_Entry_Call
7727 or else Nkind (P) = N_Timed_Entry_Call
7728 or else Nkind (P) = N_Asynchronous_Select
7729 then
7730 return False;
7731 else
7732 Desc := P;
7733 P := Parent (P);
7734 end if;
7735 end loop;
7736 end;
7738 -- OK, looks safe to set value
7740 return True;
7741 end Safe_To_Capture_Value;
7743 ---------------
7744 -- Same_Name --
7745 ---------------
7747 function Same_Name (N1, N2 : Node_Id) return Boolean is
7748 K1 : constant Node_Kind := Nkind (N1);
7749 K2 : constant Node_Kind := Nkind (N2);
7751 begin
7752 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
7753 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
7754 then
7755 return Chars (N1) = Chars (N2);
7757 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
7758 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
7759 then
7760 return Same_Name (Selector_Name (N1), Selector_Name (N2))
7761 and then Same_Name (Prefix (N1), Prefix (N2));
7763 else
7764 return False;
7765 end if;
7766 end Same_Name;
7768 ---------------
7769 -- Same_Type --
7770 ---------------
7772 function Same_Type (T1, T2 : Entity_Id) return Boolean is
7773 begin
7774 if T1 = T2 then
7775 return True;
7777 elsif not Is_Constrained (T1)
7778 and then not Is_Constrained (T2)
7779 and then Base_Type (T1) = Base_Type (T2)
7780 then
7781 return True;
7783 -- For now don't bother with case of identical constraints, to be
7784 -- fiddled with later on perhaps (this is only used for optimization
7785 -- purposes, so it is not critical to do a best possible job)
7787 else
7788 return False;
7789 end if;
7790 end Same_Type;
7792 ------------------------
7793 -- Scope_Is_Transient --
7794 ------------------------
7796 function Scope_Is_Transient return Boolean is
7797 begin
7798 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
7799 end Scope_Is_Transient;
7801 ------------------
7802 -- Scope_Within --
7803 ------------------
7805 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
7806 Scop : Entity_Id;
7808 begin
7809 Scop := Scope1;
7810 while Scop /= Standard_Standard loop
7811 Scop := Scope (Scop);
7813 if Scop = Scope2 then
7814 return True;
7815 end if;
7816 end loop;
7818 return False;
7819 end Scope_Within;
7821 --------------------------
7822 -- Scope_Within_Or_Same --
7823 --------------------------
7825 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
7826 Scop : Entity_Id;
7828 begin
7829 Scop := Scope1;
7830 while Scop /= Standard_Standard loop
7831 if Scop = Scope2 then
7832 return True;
7833 else
7834 Scop := Scope (Scop);
7835 end if;
7836 end loop;
7838 return False;
7839 end Scope_Within_Or_Same;
7841 ------------------------
7842 -- Set_Current_Entity --
7843 ------------------------
7845 -- The given entity is to be set as the currently visible definition
7846 -- of its associated name (i.e. the Node_Id associated with its name).
7847 -- All we have to do is to get the name from the identifier, and
7848 -- then set the associated Node_Id to point to the given entity.
7850 procedure Set_Current_Entity (E : Entity_Id) is
7851 begin
7852 Set_Name_Entity_Id (Chars (E), E);
7853 end Set_Current_Entity;
7855 ---------------------------------
7856 -- Set_Entity_With_Style_Check --
7857 ---------------------------------
7859 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
7860 Val_Actual : Entity_Id;
7861 Nod : Node_Id;
7863 begin
7864 Set_Entity (N, Val);
7866 if Style_Check
7867 and then not Suppress_Style_Checks (Val)
7868 and then not In_Instance
7869 then
7870 if Nkind (N) = N_Identifier then
7871 Nod := N;
7872 elsif Nkind (N) = N_Expanded_Name then
7873 Nod := Selector_Name (N);
7874 else
7875 return;
7876 end if;
7878 -- A special situation arises for derived operations, where we want
7879 -- to do the check against the parent (since the Sloc of the derived
7880 -- operation points to the derived type declaration itself).
7882 Val_Actual := Val;
7883 while not Comes_From_Source (Val_Actual)
7884 and then Nkind (Val_Actual) in N_Entity
7885 and then (Ekind (Val_Actual) = E_Enumeration_Literal
7886 or else Is_Subprogram (Val_Actual)
7887 or else Is_Generic_Subprogram (Val_Actual))
7888 and then Present (Alias (Val_Actual))
7889 loop
7890 Val_Actual := Alias (Val_Actual);
7891 end loop;
7893 -- Renaming declarations for generic actuals do not come from source,
7894 -- and have a different name from that of the entity they rename, so
7895 -- there is no style check to perform here.
7897 if Chars (Nod) = Chars (Val_Actual) then
7898 Style.Check_Identifier (Nod, Val_Actual);
7899 end if;
7900 end if;
7902 Set_Entity (N, Val);
7903 end Set_Entity_With_Style_Check;
7905 ------------------------
7906 -- Set_Name_Entity_Id --
7907 ------------------------
7909 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
7910 begin
7911 Set_Name_Table_Info (Id, Int (Val));
7912 end Set_Name_Entity_Id;
7914 ---------------------
7915 -- Set_Next_Actual --
7916 ---------------------
7918 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
7919 begin
7920 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
7921 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
7922 end if;
7923 end Set_Next_Actual;
7925 -----------------------
7926 -- Set_Public_Status --
7927 -----------------------
7929 procedure Set_Public_Status (Id : Entity_Id) is
7930 S : constant Entity_Id := Current_Scope;
7932 begin
7933 -- Everything in the scope of Standard is public
7935 if S = Standard_Standard then
7936 Set_Is_Public (Id);
7938 -- Entity is definitely not public if enclosing scope is not public
7940 elsif not Is_Public (S) then
7941 return;
7943 -- An object declaration that occurs in a handled sequence of statements
7944 -- is the declaration for a temporary object generated by the expander.
7945 -- It never needs to be made public and furthermore, making it public
7946 -- can cause back end problems if it is of variable size.
7948 elsif Nkind (Parent (Id)) = N_Object_Declaration
7949 and then
7950 Nkind (Parent (Parent (Id))) = N_Handled_Sequence_Of_Statements
7951 then
7952 return;
7954 -- Entities in public packages or records are public
7956 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
7957 Set_Is_Public (Id);
7959 -- The bounds of an entry family declaration can generate object
7960 -- declarations that are visible to the back-end, e.g. in the
7961 -- the declaration of a composite type that contains tasks.
7963 elsif Is_Concurrent_Type (S)
7964 and then not Has_Completion (S)
7965 and then Nkind (Parent (Id)) = N_Object_Declaration
7966 then
7967 Set_Is_Public (Id);
7968 end if;
7969 end Set_Public_Status;
7971 ----------------------------
7972 -- Set_Scope_Is_Transient --
7973 ----------------------------
7975 procedure Set_Scope_Is_Transient (V : Boolean := True) is
7976 begin
7977 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
7978 end Set_Scope_Is_Transient;
7980 -------------------
7981 -- Set_Size_Info --
7982 -------------------
7984 procedure Set_Size_Info (T1, T2 : Entity_Id) is
7985 begin
7986 -- We copy Esize, but not RM_Size, since in general RM_Size is
7987 -- subtype specific and does not get inherited by all subtypes.
7989 Set_Esize (T1, Esize (T2));
7990 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
7992 if Is_Discrete_Or_Fixed_Point_Type (T1)
7993 and then
7994 Is_Discrete_Or_Fixed_Point_Type (T2)
7995 then
7996 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
7997 end if;
7998 Set_Alignment (T1, Alignment (T2));
7999 end Set_Size_Info;
8001 --------------------
8002 -- Static_Integer --
8003 --------------------
8005 function Static_Integer (N : Node_Id) return Uint is
8006 begin
8007 Analyze_And_Resolve (N, Any_Integer);
8009 if N = Error
8010 or else Error_Posted (N)
8011 or else Etype (N) = Any_Type
8012 then
8013 return No_Uint;
8014 end if;
8016 if Is_Static_Expression (N) then
8017 if not Raises_Constraint_Error (N) then
8018 return Expr_Value (N);
8019 else
8020 return No_Uint;
8021 end if;
8023 elsif Etype (N) = Any_Type then
8024 return No_Uint;
8026 else
8027 Flag_Non_Static_Expr
8028 ("static integer expression required here", N);
8029 return No_Uint;
8030 end if;
8031 end Static_Integer;
8033 --------------------------
8034 -- Statically_Different --
8035 --------------------------
8037 function Statically_Different (E1, E2 : Node_Id) return Boolean is
8038 R1 : constant Node_Id := Get_Referenced_Object (E1);
8039 R2 : constant Node_Id := Get_Referenced_Object (E2);
8040 begin
8041 return Is_Entity_Name (R1)
8042 and then Is_Entity_Name (R2)
8043 and then Entity (R1) /= Entity (R2)
8044 and then not Is_Formal (Entity (R1))
8045 and then not Is_Formal (Entity (R2));
8046 end Statically_Different;
8048 -----------------------------
8049 -- Subprogram_Access_Level --
8050 -----------------------------
8052 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
8053 begin
8054 if Present (Alias (Subp)) then
8055 return Subprogram_Access_Level (Alias (Subp));
8056 else
8057 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
8058 end if;
8059 end Subprogram_Access_Level;
8061 -----------------
8062 -- Trace_Scope --
8063 -----------------
8065 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
8066 begin
8067 if Debug_Flag_W then
8068 for J in 0 .. Scope_Stack.Last loop
8069 Write_Str (" ");
8070 end loop;
8072 Write_Str (Msg);
8073 Write_Name (Chars (E));
8074 Write_Str (" line ");
8075 Write_Int (Int (Get_Logical_Line_Number (Sloc (N))));
8076 Write_Eol;
8077 end if;
8078 end Trace_Scope;
8080 -----------------------
8081 -- Transfer_Entities --
8082 -----------------------
8084 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
8085 Ent : Entity_Id := First_Entity (From);
8087 begin
8088 if No (Ent) then
8089 return;
8090 end if;
8092 if (Last_Entity (To)) = Empty then
8093 Set_First_Entity (To, Ent);
8094 else
8095 Set_Next_Entity (Last_Entity (To), Ent);
8096 end if;
8098 Set_Last_Entity (To, Last_Entity (From));
8100 while Present (Ent) loop
8101 Set_Scope (Ent, To);
8103 if not Is_Public (Ent) then
8104 Set_Public_Status (Ent);
8106 if Is_Public (Ent)
8107 and then Ekind (Ent) = E_Record_Subtype
8109 then
8110 -- The components of the propagated Itype must be public
8111 -- as well.
8113 declare
8114 Comp : Entity_Id;
8115 begin
8116 Comp := First_Entity (Ent);
8117 while Present (Comp) loop
8118 Set_Is_Public (Comp);
8119 Next_Entity (Comp);
8120 end loop;
8121 end;
8122 end if;
8123 end if;
8125 Next_Entity (Ent);
8126 end loop;
8128 Set_First_Entity (From, Empty);
8129 Set_Last_Entity (From, Empty);
8130 end Transfer_Entities;
8132 -----------------------
8133 -- Type_Access_Level --
8134 -----------------------
8136 function Type_Access_Level (Typ : Entity_Id) return Uint is
8137 Btyp : Entity_Id;
8139 begin
8140 -- If the type is an anonymous access type we treat it as being
8141 -- declared at the library level to ensure that names such as
8142 -- X.all'access don't fail static accessibility checks.
8144 -- Ada 2005 (AI-230): In case of anonymous access types that are
8145 -- component_definition or discriminants of a nonlimited type,
8146 -- the level is the same as that of the enclosing component type.
8148 Btyp := Base_Type (Typ);
8150 if Ekind (Btyp) in Access_Kind then
8151 if Ekind (Btyp) = E_Anonymous_Access_Type
8152 and then not Is_Local_Anonymous_Access (Typ) -- Ada 2005 (AI-230)
8153 then
8155 -- If this is a return_subtype, the accessibility level is that
8156 -- of the result subtype of the enclosing function.
8158 if Ekind (Scope (Btyp)) = E_Return_Statement then
8159 declare
8160 Scop : Entity_Id;
8161 begin
8162 Scop := Scope (Scope (Btyp));
8163 while Present (Scop) loop
8164 exit when Ekind (Scop) = E_Function;
8165 Scop := Scope (Scop);
8166 end loop;
8168 return Scope_Depth (Scope (Scop));
8169 end;
8171 else
8172 return Scope_Depth (Standard_Standard);
8173 end if;
8174 end if;
8176 Btyp := Root_Type (Btyp);
8178 -- The accessibility level of anonymous acccess types associated with
8179 -- discriminants is that of the current instance of the type, and
8180 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
8182 -- AI-402: access discriminants have accessibility based on the
8183 -- object rather than the type in Ada2005, so the above
8184 -- paragraph doesn't apply
8186 -- ??? Needs completion with rules from AI-416
8188 if Ada_Version <= Ada_95
8189 and then Ekind (Typ) = E_Anonymous_Access_Type
8190 and then Present (Associated_Node_For_Itype (Typ))
8191 and then Nkind (Associated_Node_For_Itype (Typ)) =
8192 N_Discriminant_Specification
8193 then
8194 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
8195 end if;
8196 end if;
8198 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
8199 end Type_Access_Level;
8201 --------------------------
8202 -- Unit_Declaration_Node --
8203 --------------------------
8205 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
8206 N : Node_Id := Parent (Unit_Id);
8208 begin
8209 -- Predefined operators do not have a full function declaration
8211 if Ekind (Unit_Id) = E_Operator then
8212 return N;
8213 end if;
8215 -- Isn't there some better way to express the following ???
8217 while Nkind (N) /= N_Abstract_Subprogram_Declaration
8218 and then Nkind (N) /= N_Formal_Package_Declaration
8219 and then Nkind (N) /= N_Function_Instantiation
8220 and then Nkind (N) /= N_Generic_Package_Declaration
8221 and then Nkind (N) /= N_Generic_Subprogram_Declaration
8222 and then Nkind (N) /= N_Package_Declaration
8223 and then Nkind (N) /= N_Package_Body
8224 and then Nkind (N) /= N_Package_Instantiation
8225 and then Nkind (N) /= N_Package_Renaming_Declaration
8226 and then Nkind (N) /= N_Procedure_Instantiation
8227 and then Nkind (N) /= N_Protected_Body
8228 and then Nkind (N) /= N_Subprogram_Declaration
8229 and then Nkind (N) /= N_Subprogram_Body
8230 and then Nkind (N) /= N_Subprogram_Body_Stub
8231 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
8232 and then Nkind (N) /= N_Task_Body
8233 and then Nkind (N) /= N_Task_Type_Declaration
8234 and then Nkind (N) not in N_Formal_Subprogram_Declaration
8235 and then Nkind (N) not in N_Generic_Renaming_Declaration
8236 loop
8237 N := Parent (N);
8238 pragma Assert (Present (N));
8239 end loop;
8241 return N;
8242 end Unit_Declaration_Node;
8244 ------------------------------
8245 -- Universal_Interpretation --
8246 ------------------------------
8248 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
8249 Index : Interp_Index;
8250 It : Interp;
8252 begin
8253 -- The argument may be a formal parameter of an operator or subprogram
8254 -- with multiple interpretations, or else an expression for an actual.
8256 if Nkind (Opnd) = N_Defining_Identifier
8257 or else not Is_Overloaded (Opnd)
8258 then
8259 if Etype (Opnd) = Universal_Integer
8260 or else Etype (Opnd) = Universal_Real
8261 then
8262 return Etype (Opnd);
8263 else
8264 return Empty;
8265 end if;
8267 else
8268 Get_First_Interp (Opnd, Index, It);
8269 while Present (It.Typ) loop
8270 if It.Typ = Universal_Integer
8271 or else It.Typ = Universal_Real
8272 then
8273 return It.Typ;
8274 end if;
8276 Get_Next_Interp (Index, It);
8277 end loop;
8279 return Empty;
8280 end if;
8281 end Universal_Interpretation;
8283 ---------------
8284 -- Unqualify --
8285 ---------------
8287 function Unqualify (Expr : Node_Id) return Node_Id is
8288 begin
8289 -- Recurse to handle unlikely case of multiple levels of qualification
8291 if Nkind (Expr) = N_Qualified_Expression then
8292 return Unqualify (Expression (Expr));
8294 -- Normal case, not a qualified expression
8296 else
8297 return Expr;
8298 end if;
8299 end Unqualify;
8301 ----------------------
8302 -- Within_Init_Proc --
8303 ----------------------
8305 function Within_Init_Proc return Boolean is
8306 S : Entity_Id;
8308 begin
8309 S := Current_Scope;
8310 while not Is_Overloadable (S) loop
8311 if S = Standard_Standard then
8312 return False;
8313 else
8314 S := Scope (S);
8315 end if;
8316 end loop;
8318 return Is_Init_Proc (S);
8319 end Within_Init_Proc;
8321 ----------------
8322 -- Wrong_Type --
8323 ----------------
8325 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
8326 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
8327 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
8329 function Has_One_Matching_Field return Boolean;
8330 -- Determines if Expec_Type is a record type with a single component or
8331 -- discriminant whose type matches the found type or is one dimensional
8332 -- array whose component type matches the found type.
8334 ----------------------------
8335 -- Has_One_Matching_Field --
8336 ----------------------------
8338 function Has_One_Matching_Field return Boolean is
8339 E : Entity_Id;
8341 begin
8342 if Is_Array_Type (Expec_Type)
8343 and then Number_Dimensions (Expec_Type) = 1
8344 and then
8345 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
8346 then
8347 return True;
8349 elsif not Is_Record_Type (Expec_Type) then
8350 return False;
8352 else
8353 E := First_Entity (Expec_Type);
8354 loop
8355 if No (E) then
8356 return False;
8358 elsif (Ekind (E) /= E_Discriminant
8359 and then Ekind (E) /= E_Component)
8360 or else (Chars (E) = Name_uTag
8361 or else Chars (E) = Name_uParent)
8362 then
8363 Next_Entity (E);
8365 else
8366 exit;
8367 end if;
8368 end loop;
8370 if not Covers (Etype (E), Found_Type) then
8371 return False;
8373 elsif Present (Next_Entity (E)) then
8374 return False;
8376 else
8377 return True;
8378 end if;
8379 end if;
8380 end Has_One_Matching_Field;
8382 -- Start of processing for Wrong_Type
8384 begin
8385 -- Don't output message if either type is Any_Type, or if a message
8386 -- has already been posted for this node. We need to do the latter
8387 -- check explicitly (it is ordinarily done in Errout), because we
8388 -- are using ! to force the output of the error messages.
8390 if Expec_Type = Any_Type
8391 or else Found_Type = Any_Type
8392 or else Error_Posted (Expr)
8393 then
8394 return;
8396 -- In an instance, there is an ongoing problem with completion of
8397 -- type derived from private types. Their structure is what Gigi
8398 -- expects, but the Etype is the parent type rather than the
8399 -- derived private type itself. Do not flag error in this case. The
8400 -- private completion is an entity without a parent, like an Itype.
8401 -- Similarly, full and partial views may be incorrect in the instance.
8402 -- There is no simple way to insure that it is consistent ???
8404 elsif In_Instance then
8406 if Etype (Etype (Expr)) = Etype (Expected_Type)
8407 and then
8408 (Has_Private_Declaration (Expected_Type)
8409 or else Has_Private_Declaration (Etype (Expr)))
8410 and then No (Parent (Expected_Type))
8411 then
8412 return;
8413 end if;
8414 end if;
8416 -- An interesting special check. If the expression is parenthesized
8417 -- and its type corresponds to the type of the sole component of the
8418 -- expected record type, or to the component type of the expected one
8419 -- dimensional array type, then assume we have a bad aggregate attempt.
8421 if Nkind (Expr) in N_Subexpr
8422 and then Paren_Count (Expr) /= 0
8423 and then Has_One_Matching_Field
8424 then
8425 Error_Msg_N ("positional aggregate cannot have one component", Expr);
8427 -- Another special check, if we are looking for a pool-specific access
8428 -- type and we found an E_Access_Attribute_Type, then we have the case
8429 -- of an Access attribute being used in a context which needs a pool-
8430 -- specific type, which is never allowed. The one extra check we make
8431 -- is that the expected designated type covers the Found_Type.
8433 elsif Is_Access_Type (Expec_Type)
8434 and then Ekind (Found_Type) = E_Access_Attribute_Type
8435 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
8436 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
8437 and then Covers
8438 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
8439 then
8440 Error_Msg_N ("result must be general access type!", Expr);
8441 Error_Msg_NE ("add ALL to }!", Expr, Expec_Type);
8443 -- If the expected type is an anonymous access type, as for access
8444 -- parameters and discriminants, the error is on the designated types.
8446 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
8447 if Comes_From_Source (Expec_Type) then
8448 Error_Msg_NE ("expected}!", Expr, Expec_Type);
8449 else
8450 Error_Msg_NE
8451 ("expected an access type with designated}",
8452 Expr, Designated_Type (Expec_Type));
8453 end if;
8455 if Is_Access_Type (Found_Type)
8456 and then not Comes_From_Source (Found_Type)
8457 then
8458 Error_Msg_NE
8459 ("\\found an access type with designated}!",
8460 Expr, Designated_Type (Found_Type));
8461 else
8462 if From_With_Type (Found_Type) then
8463 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
8464 Error_Msg_NE
8465 ("\possibly missing with_clause on&", Expr,
8466 Scope (Found_Type));
8467 else
8468 Error_Msg_NE ("found}!", Expr, Found_Type);
8469 end if;
8470 end if;
8472 -- Normal case of one type found, some other type expected
8474 else
8475 -- If the names of the two types are the same, see if some number
8476 -- of levels of qualification will help. Don't try more than three
8477 -- levels, and if we get to standard, it's no use (and probably
8478 -- represents an error in the compiler) Also do not bother with
8479 -- internal scope names.
8481 declare
8482 Expec_Scope : Entity_Id;
8483 Found_Scope : Entity_Id;
8485 begin
8486 Expec_Scope := Expec_Type;
8487 Found_Scope := Found_Type;
8489 for Levels in Int range 0 .. 3 loop
8490 if Chars (Expec_Scope) /= Chars (Found_Scope) then
8491 Error_Msg_Qual_Level := Levels;
8492 exit;
8493 end if;
8495 Expec_Scope := Scope (Expec_Scope);
8496 Found_Scope := Scope (Found_Scope);
8498 exit when Expec_Scope = Standard_Standard
8499 or else Found_Scope = Standard_Standard
8500 or else not Comes_From_Source (Expec_Scope)
8501 or else not Comes_From_Source (Found_Scope);
8502 end loop;
8503 end;
8505 if Is_Record_Type (Expec_Type)
8506 and then Present (Corresponding_Remote_Type (Expec_Type))
8507 then
8508 Error_Msg_NE ("expected}!", Expr,
8509 Corresponding_Remote_Type (Expec_Type));
8510 else
8511 Error_Msg_NE ("expected}!", Expr, Expec_Type);
8512 end if;
8514 if Is_Entity_Name (Expr)
8515 and then Is_Package_Or_Generic_Package (Entity (Expr))
8516 then
8517 Error_Msg_N ("\\found package name!", Expr);
8519 elsif Is_Entity_Name (Expr)
8520 and then
8521 (Ekind (Entity (Expr)) = E_Procedure
8522 or else
8523 Ekind (Entity (Expr)) = E_Generic_Procedure)
8524 then
8525 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
8526 Error_Msg_N
8527 ("found procedure name, possibly missing Access attribute!",
8528 Expr);
8529 else
8530 Error_Msg_N
8531 ("\\found procedure name instead of function!", Expr);
8532 end if;
8534 elsif Nkind (Expr) = N_Function_Call
8535 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
8536 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
8537 and then No (Parameter_Associations (Expr))
8538 then
8539 Error_Msg_N
8540 ("found function name, possibly missing Access attribute!",
8541 Expr);
8543 -- Catch common error: a prefix or infix operator which is not
8544 -- directly visible because the type isn't.
8546 elsif Nkind (Expr) in N_Op
8547 and then Is_Overloaded (Expr)
8548 and then not Is_Immediately_Visible (Expec_Type)
8549 and then not Is_Potentially_Use_Visible (Expec_Type)
8550 and then not In_Use (Expec_Type)
8551 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
8552 then
8553 Error_Msg_N
8554 ("operator of the type is not directly visible!", Expr);
8556 elsif Ekind (Found_Type) = E_Void
8557 and then Present (Parent (Found_Type))
8558 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
8559 then
8560 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
8562 else
8563 Error_Msg_NE ("\\found}!", Expr, Found_Type);
8564 end if;
8566 Error_Msg_Qual_Level := 0;
8567 end if;
8568 end Wrong_Type;
8570 end Sem_Util;