Merged with mainline at revision 128810.
[official-gcc.git] / gcc / ada / sem_util.adb
bloba9d4aec18c63520d0d6aed4cd5ccd51d75c30833
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-2007, 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 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Casing; use Casing;
28 with Checks; use Checks;
29 with Debug; use Debug;
30 with Errout; use Errout;
31 with Elists; use Elists;
32 with Exp_Tss; use Exp_Tss;
33 with Exp_Util; use Exp_Util;
34 with Fname; use Fname;
35 with Freeze; use Freeze;
36 with Lib; use Lib;
37 with Lib.Xref; use Lib.Xref;
38 with Nlists; use Nlists;
39 with Output; use Output;
40 with Opt; use Opt;
41 with Rtsfind; use Rtsfind;
42 with Scans; use Scans;
43 with Scn; use Scn;
44 with Sem; use Sem;
45 with Sem_Attr; use Sem_Attr;
46 with Sem_Ch6; use Sem_Ch6;
47 with Sem_Ch8; use Sem_Ch8;
48 with Sem_Eval; use Sem_Eval;
49 with Sem_Res; use Sem_Res;
50 with Sem_Type; use Sem_Type;
51 with Sinfo; use Sinfo;
52 with Sinput; use Sinput;
53 with Snames; use Snames;
54 with Stand; use Stand;
55 with Style;
56 with Stringt; use Stringt;
57 with Targparm; use Targparm;
58 with Tbuild; use Tbuild;
59 with Ttypes; use Ttypes;
60 with Uname; use Uname;
62 package body Sem_Util is
64 use Nmake;
66 -----------------------
67 -- Local Subprograms --
68 -----------------------
70 function Build_Component_Subtype
71 (C : List_Id;
72 Loc : Source_Ptr;
73 T : Entity_Id) return Node_Id;
74 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
75 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
76 -- Loc is the source location, T is the original subtype.
78 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
79 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
80 -- with discriminants whose default values are static, examine only the
81 -- components in the selected variant to determine whether all of them
82 -- have a default.
84 function Has_Null_Extension (T : Entity_Id) return Boolean;
85 -- T is a derived tagged type. Check whether the type extension is null.
86 -- If the parent type is fully initialized, T can be treated as such.
88 ------------------------------
89 -- Abstract_Interface_List --
90 ------------------------------
92 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
93 Nod : Node_Id;
95 begin
96 if Is_Concurrent_Type (Typ) then
98 -- If we are dealing with a synchronized subtype, go to the base
99 -- type, whose declaration has the interface list.
101 -- Shouldn't this be Declaration_Node???
103 Nod := Parent (Base_Type (Typ));
105 elsif Ekind (Typ) = E_Record_Type_With_Private then
106 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
107 Nod := Type_Definition (Parent (Typ));
109 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
110 if Present (Full_View (Typ)) then
111 Nod := Type_Definition (Parent (Full_View (Typ)));
113 -- If the full-view is not available we cannot do anything else
114 -- here (the source has errors).
116 else
117 return Empty_List;
118 end if;
120 -- Support for generic formals with interfaces is still missing ???
122 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
123 return Empty_List;
125 else
126 pragma Assert
127 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
128 Nod := Parent (Typ);
129 end if;
131 elsif Ekind (Typ) = E_Record_Subtype then
132 Nod := Type_Definition (Parent (Etype (Typ)));
134 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
136 -- Recurse, because parent may still be a private extension
138 return Abstract_Interface_List (Etype (Full_View (Typ)));
140 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
141 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
142 Nod := Formal_Type_Definition (Parent (Typ));
143 else
144 Nod := Type_Definition (Parent (Typ));
145 end if;
146 end if;
148 return Interface_List (Nod);
149 end Abstract_Interface_List;
151 --------------------------------
152 -- Add_Access_Type_To_Process --
153 --------------------------------
155 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
156 L : Elist_Id;
158 begin
159 Ensure_Freeze_Node (E);
160 L := Access_Types_To_Process (Freeze_Node (E));
162 if No (L) then
163 L := New_Elmt_List;
164 Set_Access_Types_To_Process (Freeze_Node (E), L);
165 end if;
167 Append_Elmt (A, L);
168 end Add_Access_Type_To_Process;
170 ----------------------------
171 -- Add_Global_Declaration --
172 ----------------------------
174 procedure Add_Global_Declaration (N : Node_Id) is
175 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
177 begin
178 if No (Declarations (Aux_Node)) then
179 Set_Declarations (Aux_Node, New_List);
180 end if;
182 Append_To (Declarations (Aux_Node), N);
183 Analyze (N);
184 end Add_Global_Declaration;
186 -----------------------
187 -- Alignment_In_Bits --
188 -----------------------
190 function Alignment_In_Bits (E : Entity_Id) return Uint is
191 begin
192 return Alignment (E) * System_Storage_Unit;
193 end Alignment_In_Bits;
195 -----------------------------------------
196 -- Apply_Compile_Time_Constraint_Error --
197 -----------------------------------------
199 procedure Apply_Compile_Time_Constraint_Error
200 (N : Node_Id;
201 Msg : String;
202 Reason : RT_Exception_Code;
203 Ent : Entity_Id := Empty;
204 Typ : Entity_Id := Empty;
205 Loc : Source_Ptr := No_Location;
206 Rep : Boolean := True;
207 Warn : Boolean := False)
209 Stat : constant Boolean := Is_Static_Expression (N);
210 Rtyp : Entity_Id;
212 begin
213 if No (Typ) then
214 Rtyp := Etype (N);
215 else
216 Rtyp := Typ;
217 end if;
219 Discard_Node
220 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
222 if not Rep then
223 return;
224 end if;
226 -- Now we replace the node by an N_Raise_Constraint_Error node
227 -- This does not need reanalyzing, so set it as analyzed now.
229 Rewrite (N,
230 Make_Raise_Constraint_Error (Sloc (N),
231 Reason => Reason));
232 Set_Analyzed (N, True);
233 Set_Etype (N, Rtyp);
234 Set_Raises_Constraint_Error (N);
236 -- If the original expression was marked as static, the result is
237 -- still marked as static, but the Raises_Constraint_Error flag is
238 -- always set so that further static evaluation is not attempted.
240 if Stat then
241 Set_Is_Static_Expression (N);
242 end if;
243 end Apply_Compile_Time_Constraint_Error;
245 --------------------------
246 -- Build_Actual_Subtype --
247 --------------------------
249 function Build_Actual_Subtype
250 (T : Entity_Id;
251 N : Node_Or_Entity_Id) return Node_Id
253 Loc : Source_Ptr;
254 -- Normally Sloc (N), but may point to corresponding body in some cases
256 Constraints : List_Id;
257 Decl : Node_Id;
258 Discr : Entity_Id;
259 Hi : Node_Id;
260 Lo : Node_Id;
261 Subt : Entity_Id;
262 Disc_Type : Entity_Id;
263 Obj : Node_Id;
265 begin
266 Loc := Sloc (N);
268 if Nkind (N) = N_Defining_Identifier then
269 Obj := New_Reference_To (N, Loc);
271 -- If this is a formal parameter of a subprogram declaration, and
272 -- we are compiling the body, we want the declaration for the
273 -- actual subtype to carry the source position of the body, to
274 -- prevent anomalies in gdb when stepping through the code.
276 if Is_Formal (N) then
277 declare
278 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
279 begin
280 if Nkind (Decl) = N_Subprogram_Declaration
281 and then Present (Corresponding_Body (Decl))
282 then
283 Loc := Sloc (Corresponding_Body (Decl));
284 end if;
285 end;
286 end if;
288 else
289 Obj := N;
290 end if;
292 if Is_Array_Type (T) then
293 Constraints := New_List;
294 for J in 1 .. Number_Dimensions (T) loop
296 -- Build an array subtype declaration with the nominal subtype and
297 -- the bounds of the actual. Add the declaration in front of the
298 -- local declarations for the subprogram, for analysis before any
299 -- reference to the formal in the body.
301 Lo :=
302 Make_Attribute_Reference (Loc,
303 Prefix =>
304 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
305 Attribute_Name => Name_First,
306 Expressions => New_List (
307 Make_Integer_Literal (Loc, J)));
309 Hi :=
310 Make_Attribute_Reference (Loc,
311 Prefix =>
312 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
313 Attribute_Name => Name_Last,
314 Expressions => New_List (
315 Make_Integer_Literal (Loc, J)));
317 Append (Make_Range (Loc, Lo, Hi), Constraints);
318 end loop;
320 -- If the type has unknown discriminants there is no constrained
321 -- subtype to build. This is never called for a formal or for a
322 -- lhs, so returning the type is ok ???
324 elsif Has_Unknown_Discriminants (T) then
325 return T;
327 else
328 Constraints := New_List;
330 if Is_Private_Type (T) and then No (Full_View (T)) then
332 -- Type is a generic derived type. Inherit discriminants from
333 -- Parent type.
335 Disc_Type := Etype (Base_Type (T));
336 else
337 Disc_Type := T;
338 end if;
340 Discr := First_Discriminant (Disc_Type);
341 while Present (Discr) loop
342 Append_To (Constraints,
343 Make_Selected_Component (Loc,
344 Prefix =>
345 Duplicate_Subexpr_No_Checks (Obj),
346 Selector_Name => New_Occurrence_Of (Discr, Loc)));
347 Next_Discriminant (Discr);
348 end loop;
349 end if;
351 Subt :=
352 Make_Defining_Identifier (Loc,
353 Chars => New_Internal_Name ('S'));
354 Set_Is_Internal (Subt);
356 Decl :=
357 Make_Subtype_Declaration (Loc,
358 Defining_Identifier => Subt,
359 Subtype_Indication =>
360 Make_Subtype_Indication (Loc,
361 Subtype_Mark => New_Reference_To (T, Loc),
362 Constraint =>
363 Make_Index_Or_Discriminant_Constraint (Loc,
364 Constraints => Constraints)));
366 Mark_Rewrite_Insertion (Decl);
367 return Decl;
368 end Build_Actual_Subtype;
370 ---------------------------------------
371 -- Build_Actual_Subtype_Of_Component --
372 ---------------------------------------
374 function Build_Actual_Subtype_Of_Component
375 (T : Entity_Id;
376 N : Node_Id) return Node_Id
378 Loc : constant Source_Ptr := Sloc (N);
379 P : constant Node_Id := Prefix (N);
380 D : Elmt_Id;
381 Id : Node_Id;
382 Indx_Type : Entity_Id;
384 Deaccessed_T : Entity_Id;
385 -- This is either a copy of T, or if T is an access type, then it is
386 -- the directly designated type of this access type.
388 function Build_Actual_Array_Constraint return List_Id;
389 -- If one or more of the bounds of the component depends on
390 -- discriminants, build actual constraint using the discriminants
391 -- of the prefix.
393 function Build_Actual_Record_Constraint return List_Id;
394 -- Similar to previous one, for discriminated components constrained
395 -- by the discriminant of the enclosing object.
397 -----------------------------------
398 -- Build_Actual_Array_Constraint --
399 -----------------------------------
401 function Build_Actual_Array_Constraint return List_Id is
402 Constraints : constant List_Id := New_List;
403 Indx : Node_Id;
404 Hi : Node_Id;
405 Lo : Node_Id;
406 Old_Hi : Node_Id;
407 Old_Lo : Node_Id;
409 begin
410 Indx := First_Index (Deaccessed_T);
411 while Present (Indx) loop
412 Old_Lo := Type_Low_Bound (Etype (Indx));
413 Old_Hi := Type_High_Bound (Etype (Indx));
415 if Denotes_Discriminant (Old_Lo) then
416 Lo :=
417 Make_Selected_Component (Loc,
418 Prefix => New_Copy_Tree (P),
419 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
421 else
422 Lo := New_Copy_Tree (Old_Lo);
424 -- The new bound will be reanalyzed in the enclosing
425 -- declaration. For literal bounds that come from a type
426 -- declaration, the type of the context must be imposed, so
427 -- insure that analysis will take place. For non-universal
428 -- types this is not strictly necessary.
430 Set_Analyzed (Lo, False);
431 end if;
433 if Denotes_Discriminant (Old_Hi) then
434 Hi :=
435 Make_Selected_Component (Loc,
436 Prefix => New_Copy_Tree (P),
437 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
439 else
440 Hi := New_Copy_Tree (Old_Hi);
441 Set_Analyzed (Hi, False);
442 end if;
444 Append (Make_Range (Loc, Lo, Hi), Constraints);
445 Next_Index (Indx);
446 end loop;
448 return Constraints;
449 end Build_Actual_Array_Constraint;
451 ------------------------------------
452 -- Build_Actual_Record_Constraint --
453 ------------------------------------
455 function Build_Actual_Record_Constraint return List_Id is
456 Constraints : constant List_Id := New_List;
457 D : Elmt_Id;
458 D_Val : Node_Id;
460 begin
461 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
462 while Present (D) loop
463 if Denotes_Discriminant (Node (D)) then
464 D_Val := Make_Selected_Component (Loc,
465 Prefix => New_Copy_Tree (P),
466 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
468 else
469 D_Val := New_Copy_Tree (Node (D));
470 end if;
472 Append (D_Val, Constraints);
473 Next_Elmt (D);
474 end loop;
476 return Constraints;
477 end Build_Actual_Record_Constraint;
479 -- Start of processing for Build_Actual_Subtype_Of_Component
481 begin
482 if In_Default_Expression then
483 return Empty;
485 elsif Nkind (N) = N_Explicit_Dereference then
486 if Is_Composite_Type (T)
487 and then not Is_Constrained (T)
488 and then not (Is_Class_Wide_Type (T)
489 and then Is_Constrained (Root_Type (T)))
490 and then not Has_Unknown_Discriminants (T)
491 then
492 -- If the type of the dereference is already constrained, it
493 -- is an actual subtype.
495 if Is_Array_Type (Etype (N))
496 and then Is_Constrained (Etype (N))
497 then
498 return Empty;
499 else
500 Remove_Side_Effects (P);
501 return Build_Actual_Subtype (T, N);
502 end if;
503 else
504 return Empty;
505 end if;
506 end if;
508 if Ekind (T) = E_Access_Subtype then
509 Deaccessed_T := Designated_Type (T);
510 else
511 Deaccessed_T := T;
512 end if;
514 if Ekind (Deaccessed_T) = E_Array_Subtype then
515 Id := First_Index (Deaccessed_T);
516 while Present (Id) loop
517 Indx_Type := Underlying_Type (Etype (Id));
519 if Denotes_Discriminant (Type_Low_Bound (Indx_Type)) or else
520 Denotes_Discriminant (Type_High_Bound (Indx_Type))
521 then
522 Remove_Side_Effects (P);
523 return
524 Build_Component_Subtype (
525 Build_Actual_Array_Constraint, Loc, Base_Type (T));
526 end if;
528 Next_Index (Id);
529 end loop;
531 elsif Is_Composite_Type (Deaccessed_T)
532 and then Has_Discriminants (Deaccessed_T)
533 and then not Has_Unknown_Discriminants (Deaccessed_T)
534 then
535 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
536 while Present (D) loop
537 if Denotes_Discriminant (Node (D)) then
538 Remove_Side_Effects (P);
539 return
540 Build_Component_Subtype (
541 Build_Actual_Record_Constraint, Loc, Base_Type (T));
542 end if;
544 Next_Elmt (D);
545 end loop;
546 end if;
548 -- If none of the above, the actual and nominal subtypes are the same
550 return Empty;
551 end Build_Actual_Subtype_Of_Component;
553 -----------------------------
554 -- Build_Component_Subtype --
555 -----------------------------
557 function Build_Component_Subtype
558 (C : List_Id;
559 Loc : Source_Ptr;
560 T : Entity_Id) return Node_Id
562 Subt : Entity_Id;
563 Decl : Node_Id;
565 begin
566 -- Unchecked_Union components do not require component subtypes
568 if Is_Unchecked_Union (T) then
569 return Empty;
570 end if;
572 Subt :=
573 Make_Defining_Identifier (Loc,
574 Chars => New_Internal_Name ('S'));
575 Set_Is_Internal (Subt);
577 Decl :=
578 Make_Subtype_Declaration (Loc,
579 Defining_Identifier => Subt,
580 Subtype_Indication =>
581 Make_Subtype_Indication (Loc,
582 Subtype_Mark => New_Reference_To (Base_Type (T), Loc),
583 Constraint =>
584 Make_Index_Or_Discriminant_Constraint (Loc,
585 Constraints => C)));
587 Mark_Rewrite_Insertion (Decl);
588 return Decl;
589 end Build_Component_Subtype;
591 ---------------------------
592 -- Build_Default_Subtype --
593 ---------------------------
595 function Build_Default_Subtype
596 (T : Entity_Id;
597 N : Node_Id) return Entity_Id
599 Loc : constant Source_Ptr := Sloc (N);
600 Disc : Entity_Id;
602 begin
603 if not Has_Discriminants (T) or else Is_Constrained (T) then
604 return T;
605 end if;
607 Disc := First_Discriminant (T);
609 if No (Discriminant_Default_Value (Disc)) then
610 return T;
611 end if;
613 declare
614 Act : constant Entity_Id :=
615 Make_Defining_Identifier (Loc,
616 Chars => New_Internal_Name ('S'));
618 Constraints : constant List_Id := New_List;
619 Decl : Node_Id;
621 begin
622 while Present (Disc) loop
623 Append_To (Constraints,
624 New_Copy_Tree (Discriminant_Default_Value (Disc)));
625 Next_Discriminant (Disc);
626 end loop;
628 Decl :=
629 Make_Subtype_Declaration (Loc,
630 Defining_Identifier => Act,
631 Subtype_Indication =>
632 Make_Subtype_Indication (Loc,
633 Subtype_Mark => New_Occurrence_Of (T, Loc),
634 Constraint =>
635 Make_Index_Or_Discriminant_Constraint (Loc,
636 Constraints => Constraints)));
638 Insert_Action (N, Decl);
639 Analyze (Decl);
640 return Act;
641 end;
642 end Build_Default_Subtype;
644 --------------------------------------------
645 -- Build_Discriminal_Subtype_Of_Component --
646 --------------------------------------------
648 function Build_Discriminal_Subtype_Of_Component
649 (T : Entity_Id) return Node_Id
651 Loc : constant Source_Ptr := Sloc (T);
652 D : Elmt_Id;
653 Id : Node_Id;
655 function Build_Discriminal_Array_Constraint return List_Id;
656 -- If one or more of the bounds of the component depends on
657 -- discriminants, build actual constraint using the discriminants
658 -- of the prefix.
660 function Build_Discriminal_Record_Constraint return List_Id;
661 -- Similar to previous one, for discriminated components constrained
662 -- by the discriminant of the enclosing object.
664 ----------------------------------------
665 -- Build_Discriminal_Array_Constraint --
666 ----------------------------------------
668 function Build_Discriminal_Array_Constraint return List_Id is
669 Constraints : constant List_Id := New_List;
670 Indx : Node_Id;
671 Hi : Node_Id;
672 Lo : Node_Id;
673 Old_Hi : Node_Id;
674 Old_Lo : Node_Id;
676 begin
677 Indx := First_Index (T);
678 while Present (Indx) loop
679 Old_Lo := Type_Low_Bound (Etype (Indx));
680 Old_Hi := Type_High_Bound (Etype (Indx));
682 if Denotes_Discriminant (Old_Lo) then
683 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
685 else
686 Lo := New_Copy_Tree (Old_Lo);
687 end if;
689 if Denotes_Discriminant (Old_Hi) then
690 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
692 else
693 Hi := New_Copy_Tree (Old_Hi);
694 end if;
696 Append (Make_Range (Loc, Lo, Hi), Constraints);
697 Next_Index (Indx);
698 end loop;
700 return Constraints;
701 end Build_Discriminal_Array_Constraint;
703 -----------------------------------------
704 -- Build_Discriminal_Record_Constraint --
705 -----------------------------------------
707 function Build_Discriminal_Record_Constraint return List_Id is
708 Constraints : constant List_Id := New_List;
709 D : Elmt_Id;
710 D_Val : Node_Id;
712 begin
713 D := First_Elmt (Discriminant_Constraint (T));
714 while Present (D) loop
715 if Denotes_Discriminant (Node (D)) then
716 D_Val :=
717 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
719 else
720 D_Val := New_Copy_Tree (Node (D));
721 end if;
723 Append (D_Val, Constraints);
724 Next_Elmt (D);
725 end loop;
727 return Constraints;
728 end Build_Discriminal_Record_Constraint;
730 -- Start of processing for Build_Discriminal_Subtype_Of_Component
732 begin
733 if Ekind (T) = E_Array_Subtype then
734 Id := First_Index (T);
735 while Present (Id) loop
736 if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) or else
737 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
738 then
739 return Build_Component_Subtype
740 (Build_Discriminal_Array_Constraint, Loc, T);
741 end if;
743 Next_Index (Id);
744 end loop;
746 elsif Ekind (T) = E_Record_Subtype
747 and then Has_Discriminants (T)
748 and then not Has_Unknown_Discriminants (T)
749 then
750 D := First_Elmt (Discriminant_Constraint (T));
751 while Present (D) loop
752 if Denotes_Discriminant (Node (D)) then
753 return Build_Component_Subtype
754 (Build_Discriminal_Record_Constraint, Loc, T);
755 end if;
757 Next_Elmt (D);
758 end loop;
759 end if;
761 -- If none of the above, the actual and nominal subtypes are the same
763 return Empty;
764 end Build_Discriminal_Subtype_Of_Component;
766 ------------------------------
767 -- Build_Elaboration_Entity --
768 ------------------------------
770 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
771 Loc : constant Source_Ptr := Sloc (N);
772 Decl : Node_Id;
773 Elab_Ent : Entity_Id;
775 procedure Set_Package_Name (Ent : Entity_Id);
776 -- Given an entity, sets the fully qualified name of the entity in
777 -- Name_Buffer, with components separated by double underscores. This
778 -- is a recursive routine that climbs the scope chain to Standard.
780 ----------------------
781 -- Set_Package_Name --
782 ----------------------
784 procedure Set_Package_Name (Ent : Entity_Id) is
785 begin
786 if Scope (Ent) /= Standard_Standard then
787 Set_Package_Name (Scope (Ent));
789 declare
790 Nam : constant String := Get_Name_String (Chars (Ent));
791 begin
792 Name_Buffer (Name_Len + 1) := '_';
793 Name_Buffer (Name_Len + 2) := '_';
794 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
795 Name_Len := Name_Len + Nam'Length + 2;
796 end;
798 else
799 Get_Name_String (Chars (Ent));
800 end if;
801 end Set_Package_Name;
803 -- Start of processing for Build_Elaboration_Entity
805 begin
806 -- Ignore if already constructed
808 if Present (Elaboration_Entity (Spec_Id)) then
809 return;
810 end if;
812 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
813 -- name with dots replaced by double underscore. We have to manually
814 -- construct this name, since it will be elaborated in the outer scope,
815 -- and thus will not have the unit name automatically prepended.
817 Set_Package_Name (Spec_Id);
819 -- Append _E
821 Name_Buffer (Name_Len + 1) := '_';
822 Name_Buffer (Name_Len + 2) := 'E';
823 Name_Len := Name_Len + 2;
825 -- Create elaboration flag
827 Elab_Ent :=
828 Make_Defining_Identifier (Loc, Chars => Name_Find);
829 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
831 Decl :=
832 Make_Object_Declaration (Loc,
833 Defining_Identifier => Elab_Ent,
834 Object_Definition =>
835 New_Occurrence_Of (Standard_Boolean, Loc),
836 Expression =>
837 New_Occurrence_Of (Standard_False, Loc));
839 Push_Scope (Standard_Standard);
840 Add_Global_Declaration (Decl);
841 Pop_Scope;
843 -- Reset True_Constant indication, since we will indeed assign a value
844 -- to the variable in the binder main. We also kill the Current_Value
845 -- and Last_Assignment fields for the same reason.
847 Set_Is_True_Constant (Elab_Ent, False);
848 Set_Current_Value (Elab_Ent, Empty);
849 Set_Last_Assignment (Elab_Ent, Empty);
851 -- We do not want any further qualification of the name (if we did
852 -- not do this, we would pick up the name of the generic package
853 -- in the case of a library level generic instantiation).
855 Set_Has_Qualified_Name (Elab_Ent);
856 Set_Has_Fully_Qualified_Name (Elab_Ent);
857 end Build_Elaboration_Entity;
859 -----------------------------------
860 -- Cannot_Raise_Constraint_Error --
861 -----------------------------------
863 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
864 begin
865 if Compile_Time_Known_Value (Expr) then
866 return True;
868 elsif Do_Range_Check (Expr) then
869 return False;
871 elsif Raises_Constraint_Error (Expr) then
872 return False;
874 else
875 case Nkind (Expr) is
876 when N_Identifier =>
877 return True;
879 when N_Expanded_Name =>
880 return True;
882 when N_Selected_Component =>
883 return not Do_Discriminant_Check (Expr);
885 when N_Attribute_Reference =>
886 if Do_Overflow_Check (Expr) then
887 return False;
889 elsif No (Expressions (Expr)) then
890 return True;
892 else
893 declare
894 N : Node_Id;
896 begin
897 N := First (Expressions (Expr));
898 while Present (N) loop
899 if Cannot_Raise_Constraint_Error (N) then
900 Next (N);
901 else
902 return False;
903 end if;
904 end loop;
906 return True;
907 end;
908 end if;
910 when N_Type_Conversion =>
911 if Do_Overflow_Check (Expr)
912 or else Do_Length_Check (Expr)
913 or else Do_Tag_Check (Expr)
914 then
915 return False;
916 else
917 return
918 Cannot_Raise_Constraint_Error (Expression (Expr));
919 end if;
921 when N_Unchecked_Type_Conversion =>
922 return Cannot_Raise_Constraint_Error (Expression (Expr));
924 when N_Unary_Op =>
925 if Do_Overflow_Check (Expr) then
926 return False;
927 else
928 return
929 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
930 end if;
932 when N_Op_Divide |
933 N_Op_Mod |
934 N_Op_Rem
936 if Do_Division_Check (Expr)
937 or else Do_Overflow_Check (Expr)
938 then
939 return False;
940 else
941 return
942 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
943 and then
944 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
945 end if;
947 when N_Op_Add |
948 N_Op_And |
949 N_Op_Concat |
950 N_Op_Eq |
951 N_Op_Expon |
952 N_Op_Ge |
953 N_Op_Gt |
954 N_Op_Le |
955 N_Op_Lt |
956 N_Op_Multiply |
957 N_Op_Ne |
958 N_Op_Or |
959 N_Op_Rotate_Left |
960 N_Op_Rotate_Right |
961 N_Op_Shift_Left |
962 N_Op_Shift_Right |
963 N_Op_Shift_Right_Arithmetic |
964 N_Op_Subtract |
965 N_Op_Xor
967 if Do_Overflow_Check (Expr) then
968 return False;
969 else
970 return
971 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
972 and then
973 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
974 end if;
976 when others =>
977 return False;
978 end case;
979 end if;
980 end Cannot_Raise_Constraint_Error;
982 --------------------------
983 -- Check_Fully_Declared --
984 --------------------------
986 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
987 begin
988 if Ekind (T) = E_Incomplete_Type then
990 -- Ada 2005 (AI-50217): If the type is available through a limited
991 -- with_clause, verify that its full view has been analyzed.
993 if From_With_Type (T)
994 and then Present (Non_Limited_View (T))
995 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
996 then
997 -- The non-limited view is fully declared
998 null;
1000 else
1001 Error_Msg_NE
1002 ("premature usage of incomplete}", N, First_Subtype (T));
1003 end if;
1005 elsif Has_Private_Component (T)
1006 and then not Is_Generic_Type (Root_Type (T))
1007 and then not In_Default_Expression
1008 then
1010 -- Special case: if T is the anonymous type created for a single
1011 -- task or protected object, use the name of the source object.
1013 if Is_Concurrent_Type (T)
1014 and then not Comes_From_Source (T)
1015 and then Nkind (N) = N_Object_Declaration
1016 then
1017 Error_Msg_NE ("type of& has incomplete component", N,
1018 Defining_Identifier (N));
1020 else
1021 Error_Msg_NE
1022 ("premature usage of incomplete}", N, First_Subtype (T));
1023 end if;
1024 end if;
1025 end Check_Fully_Declared;
1027 -------------------------
1028 -- Check_Nested_Access --
1029 -------------------------
1031 procedure Check_Nested_Access (Ent : Entity_Id) is
1032 Scop : constant Entity_Id := Current_Scope;
1033 Current_Subp : Entity_Id;
1035 begin
1036 -- Currently only enabled for VM back-ends for efficiency, should we
1037 -- enable it more systematically ???
1039 if VM_Target /= No_VM
1040 and then (Ekind (Ent) = E_Variable
1041 or else
1042 Ekind (Ent) = E_Constant
1043 or else
1044 Ekind (Ent) = E_Loop_Parameter)
1045 and then Scope (Ent) /= Empty
1046 and then not Is_Library_Level_Entity (Ent)
1047 then
1048 if Is_Subprogram (Scop)
1049 or else Is_Generic_Subprogram (Scop)
1050 or else Is_Entry (Scop)
1051 then
1052 Current_Subp := Scop;
1053 else
1054 Current_Subp := Current_Subprogram;
1055 end if;
1057 if Enclosing_Subprogram (Ent) /= Current_Subp then
1058 Set_Has_Up_Level_Access (Ent, True);
1059 end if;
1060 end if;
1061 end Check_Nested_Access;
1063 ------------------------------------------
1064 -- Check_Potentially_Blocking_Operation --
1065 ------------------------------------------
1067 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
1068 S : Entity_Id;
1069 begin
1070 -- N is one of the potentially blocking operations listed in 9.5.1(8).
1071 -- When pragma Detect_Blocking is active, the run time will raise
1072 -- Program_Error. Here we only issue a warning, since we generally
1073 -- support the use of potentially blocking operations in the absence
1074 -- of the pragma.
1076 -- Indirect blocking through a subprogram call cannot be diagnosed
1077 -- statically without interprocedural analysis, so we do not attempt
1078 -- to do it here.
1080 S := Scope (Current_Scope);
1081 while Present (S) and then S /= Standard_Standard loop
1082 if Is_Protected_Type (S) then
1083 Error_Msg_N
1084 ("potentially blocking operation in protected operation?", N);
1086 return;
1087 end if;
1089 S := Scope (S);
1090 end loop;
1091 end Check_Potentially_Blocking_Operation;
1093 ---------------
1094 -- Check_VMS --
1095 ---------------
1097 procedure Check_VMS (Construct : Node_Id) is
1098 begin
1099 if not OpenVMS_On_Target then
1100 Error_Msg_N
1101 ("this construct is allowed only in Open'V'M'S", Construct);
1102 end if;
1103 end Check_VMS;
1105 ---------------------------------
1106 -- Collect_Abstract_Interfaces --
1107 ---------------------------------
1109 procedure Collect_Abstract_Interfaces
1110 (T : Entity_Id;
1111 Ifaces_List : out Elist_Id;
1112 Exclude_Parent_Interfaces : Boolean := False;
1113 Use_Full_View : Boolean := True)
1115 procedure Add_Interface (Iface : Entity_Id);
1116 -- Add the interface it if is not already in the list
1118 procedure Collect (Typ : Entity_Id);
1119 -- Subsidiary subprogram used to traverse the whole list
1120 -- of directly and indirectly implemented interfaces
1122 function Interface_Present_In_Parent
1123 (Typ : Entity_Id;
1124 Iface : Entity_Id) return Boolean;
1125 -- Typ must be a tagged record type/subtype and Iface must be an
1126 -- abstract interface type. This function is used to check if Typ
1127 -- or some parent of Typ implements Iface.
1129 -------------------
1130 -- Add_Interface --
1131 -------------------
1133 procedure Add_Interface (Iface : Entity_Id) is
1134 Elmt : Elmt_Id;
1136 begin
1137 Elmt := First_Elmt (Ifaces_List);
1138 while Present (Elmt) and then Node (Elmt) /= Iface loop
1139 Next_Elmt (Elmt);
1140 end loop;
1142 if No (Elmt) then
1143 Append_Elmt (Iface, Ifaces_List);
1144 end if;
1145 end Add_Interface;
1147 -------------
1148 -- Collect --
1149 -------------
1151 procedure Collect (Typ : Entity_Id) is
1152 Ancestor : Entity_Id;
1153 Full_T : Entity_Id;
1154 Iface_List : List_Id;
1155 Id : Node_Id;
1156 Iface : Entity_Id;
1158 begin
1159 Full_T := Typ;
1161 -- Handle private types
1163 if Use_Full_View
1164 and then Is_Private_Type (Typ)
1165 and then Present (Full_View (Typ))
1166 then
1167 Full_T := Full_View (Typ);
1168 end if;
1170 Iface_List := Abstract_Interface_List (Full_T);
1172 -- Include the ancestor if we are generating the whole list of
1173 -- abstract interfaces.
1175 -- In concurrent types the ancestor interface (if any) is the
1176 -- first element of the list of interface types.
1178 if Is_Concurrent_Type (Full_T)
1179 or else Is_Concurrent_Record_Type (Full_T)
1180 then
1181 if Is_Non_Empty_List (Iface_List) then
1182 Ancestor := Etype (First (Iface_List));
1183 Collect (Ancestor);
1185 if not Exclude_Parent_Interfaces then
1186 Add_Interface (Ancestor);
1187 end if;
1188 end if;
1190 elsif Etype (Full_T) /= Typ
1192 -- Protect the frontend against wrong sources. For example:
1194 -- package P is
1195 -- type A is tagged null record;
1196 -- type B is new A with private;
1197 -- type C is new A with private;
1198 -- private
1199 -- type B is new C with null record;
1200 -- type C is new B with null record;
1201 -- end P;
1203 and then Etype (Full_T) /= T
1204 then
1205 Ancestor := Etype (Full_T);
1206 Collect (Ancestor);
1208 if Is_Interface (Ancestor)
1209 and then not Exclude_Parent_Interfaces
1210 then
1211 Add_Interface (Ancestor);
1212 end if;
1213 end if;
1215 -- Traverse the graph of ancestor interfaces
1217 if Is_Non_Empty_List (Iface_List) then
1218 Id := First (Iface_List);
1220 -- In concurrent types the ancestor interface (if any) is the
1221 -- first element of the list of interface types and we have
1222 -- already processed them while climbing to the root type.
1224 if Is_Concurrent_Type (Full_T)
1225 or else Is_Concurrent_Record_Type (Full_T)
1226 then
1227 Next (Id);
1228 end if;
1230 while Present (Id) loop
1231 Iface := Etype (Id);
1233 -- Protect against wrong uses. For example:
1234 -- type I is interface;
1235 -- type O is tagged null record;
1236 -- type Wrong is new I and O with null record; -- ERROR
1238 if Is_Interface (Iface) then
1239 if Exclude_Parent_Interfaces
1240 and then Interface_Present_In_Parent (T, Iface)
1241 then
1242 null;
1243 else
1244 Collect (Iface);
1245 Add_Interface (Iface);
1246 end if;
1247 end if;
1249 Next (Id);
1250 end loop;
1251 end if;
1252 end Collect;
1254 ---------------------------------
1255 -- Interface_Present_In_Parent --
1256 ---------------------------------
1258 function Interface_Present_In_Parent
1259 (Typ : Entity_Id;
1260 Iface : Entity_Id) return Boolean
1262 Aux : Entity_Id := Typ;
1263 Iface_List : List_Id;
1265 begin
1266 if Is_Concurrent_Type (Typ)
1267 or else Is_Concurrent_Record_Type (Typ)
1268 then
1269 Iface_List := Abstract_Interface_List (Typ);
1271 if Is_Non_Empty_List (Iface_List) then
1272 Aux := Etype (First (Iface_List));
1273 else
1274 return False;
1275 end if;
1276 end if;
1278 return Interface_Present_In_Ancestor (Aux, Iface);
1279 end Interface_Present_In_Parent;
1281 -- Start of processing for Collect_Abstract_Interfaces
1283 begin
1284 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
1285 Ifaces_List := New_Elmt_List;
1286 Collect (T);
1287 end Collect_Abstract_Interfaces;
1289 ----------------------------------
1290 -- Collect_Interface_Components --
1291 ----------------------------------
1293 procedure Collect_Interface_Components
1294 (Tagged_Type : Entity_Id;
1295 Components_List : out Elist_Id)
1297 procedure Collect (Typ : Entity_Id);
1298 -- Subsidiary subprogram used to climb to the parents
1300 -------------
1301 -- Collect --
1302 -------------
1304 procedure Collect (Typ : Entity_Id) is
1305 Tag_Comp : Entity_Id;
1307 begin
1308 if Etype (Typ) /= Typ
1310 -- Protect the frontend against wrong sources. For example:
1312 -- package P is
1313 -- type A is tagged null record;
1314 -- type B is new A with private;
1315 -- type C is new A with private;
1316 -- private
1317 -- type B is new C with null record;
1318 -- type C is new B with null record;
1319 -- end P;
1321 and then Etype (Typ) /= Tagged_Type
1322 then
1323 Collect (Etype (Typ));
1324 end if;
1326 -- Collect the components containing tags of secondary dispatch
1327 -- tables.
1329 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
1330 while Present (Tag_Comp) loop
1331 pragma Assert (Present (Related_Interface (Tag_Comp)));
1332 Append_Elmt (Tag_Comp, Components_List);
1334 Tag_Comp := Next_Tag_Component (Tag_Comp);
1335 end loop;
1336 end Collect;
1338 -- Start of processing for Collect_Interface_Components
1340 begin
1341 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
1342 and then Is_Tagged_Type (Tagged_Type));
1344 Components_List := New_Elmt_List;
1345 Collect (Tagged_Type);
1346 end Collect_Interface_Components;
1348 -----------------------------
1349 -- Collect_Interfaces_Info --
1350 -----------------------------
1352 procedure Collect_Interfaces_Info
1353 (T : Entity_Id;
1354 Ifaces_List : out Elist_Id;
1355 Components_List : out Elist_Id;
1356 Tags_List : out Elist_Id)
1358 Comps_List : Elist_Id;
1359 Comp_Elmt : Elmt_Id;
1360 Comp_Iface : Entity_Id;
1361 Iface_Elmt : Elmt_Id;
1362 Iface : Entity_Id;
1364 function Search_Tag (Iface : Entity_Id) return Entity_Id;
1365 -- Search for the secondary tag associated with the interface type
1366 -- Iface that is implemented by T.
1368 ----------------
1369 -- Search_Tag --
1370 ----------------
1372 function Search_Tag (Iface : Entity_Id) return Entity_Id is
1373 ADT : Elmt_Id;
1375 begin
1376 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
1377 while Present (ADT)
1378 and then Ekind (Node (ADT)) = E_Constant
1379 and then Related_Interface (Node (ADT)) /= Iface
1380 loop
1381 Next_Elmt (ADT);
1382 end loop;
1384 pragma Assert (Ekind (Node (ADT)) = E_Constant);
1385 return Node (ADT);
1386 end Search_Tag;
1388 -- Start of processing for Collect_Interfaces_Info
1390 begin
1391 Collect_Abstract_Interfaces (T, Ifaces_List);
1392 Collect_Interface_Components (T, Comps_List);
1394 -- Search for the record component and tag associated with each
1395 -- interface type of T.
1397 Components_List := New_Elmt_List;
1398 Tags_List := New_Elmt_List;
1400 Iface_Elmt := First_Elmt (Ifaces_List);
1401 while Present (Iface_Elmt) loop
1402 Iface := Node (Iface_Elmt);
1404 -- Associate the primary tag component and the primary dispatch table
1405 -- with all the interfaces that are parents of T
1407 if Is_Parent (Iface, T) then
1408 Append_Elmt (First_Tag_Component (T), Components_List);
1409 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
1411 -- Otherwise search for the tag component and secondary dispatch
1412 -- table of Iface
1414 else
1415 Comp_Elmt := First_Elmt (Comps_List);
1416 while Present (Comp_Elmt) loop
1417 Comp_Iface := Related_Interface (Node (Comp_Elmt));
1419 if Comp_Iface = Iface
1420 or else Is_Parent (Iface, Comp_Iface)
1421 then
1422 Append_Elmt (Node (Comp_Elmt), Components_List);
1423 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
1424 exit;
1425 end if;
1427 Next_Elmt (Comp_Elmt);
1428 end loop;
1429 pragma Assert (Present (Comp_Elmt));
1430 end if;
1432 Next_Elmt (Iface_Elmt);
1433 end loop;
1434 end Collect_Interfaces_Info;
1436 ----------------------------------
1437 -- Collect_Primitive_Operations --
1438 ----------------------------------
1440 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
1441 B_Type : constant Entity_Id := Base_Type (T);
1442 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
1443 B_Scope : Entity_Id := Scope (B_Type);
1444 Op_List : Elist_Id;
1445 Formal : Entity_Id;
1446 Is_Prim : Boolean;
1447 Formal_Derived : Boolean := False;
1448 Id : Entity_Id;
1450 begin
1451 -- For tagged types, the primitive operations are collected as they
1452 -- are declared, and held in an explicit list which is simply returned.
1454 if Is_Tagged_Type (B_Type) then
1455 return Primitive_Operations (B_Type);
1457 -- An untagged generic type that is a derived type inherits the
1458 -- primitive operations of its parent type. Other formal types only
1459 -- have predefined operators, which are not explicitly represented.
1461 elsif Is_Generic_Type (B_Type) then
1462 if Nkind (B_Decl) = N_Formal_Type_Declaration
1463 and then Nkind (Formal_Type_Definition (B_Decl))
1464 = N_Formal_Derived_Type_Definition
1465 then
1466 Formal_Derived := True;
1467 else
1468 return New_Elmt_List;
1469 end if;
1470 end if;
1472 Op_List := New_Elmt_List;
1474 if B_Scope = Standard_Standard then
1475 if B_Type = Standard_String then
1476 Append_Elmt (Standard_Op_Concat, Op_List);
1478 elsif B_Type = Standard_Wide_String then
1479 Append_Elmt (Standard_Op_Concatw, Op_List);
1481 else
1482 null;
1483 end if;
1485 elsif (Is_Package_Or_Generic_Package (B_Scope)
1486 and then
1487 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
1488 N_Package_Body)
1489 or else Is_Derived_Type (B_Type)
1490 then
1491 -- The primitive operations appear after the base type, except
1492 -- if the derivation happens within the private part of B_Scope
1493 -- and the type is a private type, in which case both the type
1494 -- and some primitive operations may appear before the base
1495 -- type, and the list of candidates starts after the type.
1497 if In_Open_Scopes (B_Scope)
1498 and then Scope (T) = B_Scope
1499 and then In_Private_Part (B_Scope)
1500 then
1501 Id := Next_Entity (T);
1502 else
1503 Id := Next_Entity (B_Type);
1504 end if;
1506 while Present (Id) loop
1508 -- Note that generic formal subprograms are not
1509 -- considered to be primitive operations and thus
1510 -- are never inherited.
1512 if Is_Overloadable (Id)
1513 and then Nkind (Parent (Parent (Id)))
1514 not in N_Formal_Subprogram_Declaration
1515 then
1516 Is_Prim := False;
1518 if Base_Type (Etype (Id)) = B_Type then
1519 Is_Prim := True;
1520 else
1521 Formal := First_Formal (Id);
1522 while Present (Formal) loop
1523 if Base_Type (Etype (Formal)) = B_Type then
1524 Is_Prim := True;
1525 exit;
1527 elsif Ekind (Etype (Formal)) = E_Anonymous_Access_Type
1528 and then Base_Type
1529 (Designated_Type (Etype (Formal))) = B_Type
1530 then
1531 Is_Prim := True;
1532 exit;
1533 end if;
1535 Next_Formal (Formal);
1536 end loop;
1537 end if;
1539 -- For a formal derived type, the only primitives are the
1540 -- ones inherited from the parent type. Operations appearing
1541 -- in the package declaration are not primitive for it.
1543 if Is_Prim
1544 and then (not Formal_Derived
1545 or else Present (Alias (Id)))
1546 then
1547 Append_Elmt (Id, Op_List);
1548 end if;
1549 end if;
1551 Next_Entity (Id);
1553 -- For a type declared in System, some of its operations
1554 -- may appear in the target-specific extension to System.
1556 if No (Id)
1557 and then Chars (B_Scope) = Name_System
1558 and then Scope (B_Scope) = Standard_Standard
1559 and then Present_System_Aux
1560 then
1561 B_Scope := System_Aux_Id;
1562 Id := First_Entity (System_Aux_Id);
1563 end if;
1564 end loop;
1565 end if;
1567 return Op_List;
1568 end Collect_Primitive_Operations;
1570 -----------------------------------
1571 -- Compile_Time_Constraint_Error --
1572 -----------------------------------
1574 function Compile_Time_Constraint_Error
1575 (N : Node_Id;
1576 Msg : String;
1577 Ent : Entity_Id := Empty;
1578 Loc : Source_Ptr := No_Location;
1579 Warn : Boolean := False) return Node_Id
1581 Msgc : String (1 .. Msg'Length + 2);
1582 -- Copy of message, with room for possible ? and ! at end
1584 Msgl : Natural;
1585 Wmsg : Boolean;
1586 P : Node_Id;
1587 OldP : Node_Id;
1588 Msgs : Boolean;
1589 Eloc : Source_Ptr;
1591 begin
1592 -- A static constraint error in an instance body is not a fatal error.
1593 -- we choose to inhibit the message altogether, because there is no
1594 -- obvious node (for now) on which to post it. On the other hand the
1595 -- offending node must be replaced with a constraint_error in any case.
1597 -- No messages are generated if we already posted an error on this node
1599 if not Error_Posted (N) then
1600 if Loc /= No_Location then
1601 Eloc := Loc;
1602 else
1603 Eloc := Sloc (N);
1604 end if;
1606 Msgc (1 .. Msg'Length) := Msg;
1607 Msgl := Msg'Length;
1609 -- Message is a warning, even in Ada 95 case
1611 if Msg (Msg'Last) = '?' then
1612 Wmsg := True;
1614 -- In Ada 83, all messages are warnings. In the private part and
1615 -- the body of an instance, constraint_checks are only warnings.
1616 -- We also make this a warning if the Warn parameter is set.
1618 elsif Warn
1619 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
1620 then
1621 Msgl := Msgl + 1;
1622 Msgc (Msgl) := '?';
1623 Wmsg := True;
1625 elsif In_Instance_Not_Visible then
1626 Msgl := Msgl + 1;
1627 Msgc (Msgl) := '?';
1628 Wmsg := True;
1630 -- Otherwise we have a real error message (Ada 95 static case)
1631 -- and we make this an unconditional message. Note that in the
1632 -- warning case we do not make the message unconditional, it seems
1633 -- quite reasonable to delete messages like this (about exceptions
1634 -- that will be raised) in dead code.
1636 else
1637 Wmsg := False;
1638 Msgl := Msgl + 1;
1639 Msgc (Msgl) := '!';
1640 end if;
1642 -- Should we generate a warning? The answer is not quite yes. The
1643 -- very annoying exception occurs in the case of a short circuit
1644 -- operator where the left operand is static and decisive. Climb
1645 -- parents to see if that is the case we have here. Conditional
1646 -- expressions with decisive conditions are a similar situation.
1648 Msgs := True;
1649 P := N;
1650 loop
1651 OldP := P;
1652 P := Parent (P);
1654 -- And then with False as left operand
1656 if Nkind (P) = N_And_Then
1657 and then Compile_Time_Known_Value (Left_Opnd (P))
1658 and then Is_False (Expr_Value (Left_Opnd (P)))
1659 then
1660 Msgs := False;
1661 exit;
1663 -- OR ELSE with True as left operand
1665 elsif Nkind (P) = N_Or_Else
1666 and then Compile_Time_Known_Value (Left_Opnd (P))
1667 and then Is_True (Expr_Value (Left_Opnd (P)))
1668 then
1669 Msgs := False;
1670 exit;
1672 -- Conditional expression
1674 elsif Nkind (P) = N_Conditional_Expression then
1675 declare
1676 Cond : constant Node_Id := First (Expressions (P));
1677 Texp : constant Node_Id := Next (Cond);
1678 Fexp : constant Node_Id := Next (Texp);
1680 begin
1681 if Compile_Time_Known_Value (Cond) then
1683 -- Condition is True and we are in the right operand
1685 if Is_True (Expr_Value (Cond))
1686 and then OldP = Fexp
1687 then
1688 Msgs := False;
1689 exit;
1691 -- Condition is False and we are in the left operand
1693 elsif Is_False (Expr_Value (Cond))
1694 and then OldP = Texp
1695 then
1696 Msgs := False;
1697 exit;
1698 end if;
1699 end if;
1700 end;
1702 -- Special case for component association in aggregates, where
1703 -- we want to keep climbing up to the parent aggregate.
1705 elsif Nkind (P) = N_Component_Association
1706 and then Nkind (Parent (P)) = N_Aggregate
1707 then
1708 null;
1710 -- Keep going if within subexpression
1712 else
1713 exit when Nkind (P) not in N_Subexpr;
1714 end if;
1715 end loop;
1717 if Msgs then
1718 if Present (Ent) then
1719 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
1720 else
1721 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
1722 end if;
1724 if Wmsg then
1725 if Inside_Init_Proc then
1726 Error_Msg_NEL
1727 ("\?& will be raised for objects of this type",
1728 N, Standard_Constraint_Error, Eloc);
1729 else
1730 Error_Msg_NEL
1731 ("\?& will be raised at run time",
1732 N, Standard_Constraint_Error, Eloc);
1733 end if;
1735 else
1736 Error_Msg
1737 ("\static expression fails Constraint_Check", Eloc);
1738 Set_Error_Posted (N);
1739 end if;
1740 end if;
1741 end if;
1743 return N;
1744 end Compile_Time_Constraint_Error;
1746 -----------------------
1747 -- Conditional_Delay --
1748 -----------------------
1750 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
1751 begin
1752 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
1753 Set_Has_Delayed_Freeze (New_Ent);
1754 end if;
1755 end Conditional_Delay;
1757 --------------------
1758 -- Current_Entity --
1759 --------------------
1761 -- The currently visible definition for a given identifier is the
1762 -- one most chained at the start of the visibility chain, i.e. the
1763 -- one that is referenced by the Node_Id value of the name of the
1764 -- given identifier.
1766 function Current_Entity (N : Node_Id) return Entity_Id is
1767 begin
1768 return Get_Name_Entity_Id (Chars (N));
1769 end Current_Entity;
1771 -----------------------------
1772 -- Current_Entity_In_Scope --
1773 -----------------------------
1775 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
1776 E : Entity_Id;
1777 CS : constant Entity_Id := Current_Scope;
1779 Transient_Case : constant Boolean := Scope_Is_Transient;
1781 begin
1782 E := Get_Name_Entity_Id (Chars (N));
1783 while Present (E)
1784 and then Scope (E) /= CS
1785 and then (not Transient_Case or else Scope (E) /= Scope (CS))
1786 loop
1787 E := Homonym (E);
1788 end loop;
1790 return E;
1791 end Current_Entity_In_Scope;
1793 -------------------
1794 -- Current_Scope --
1795 -------------------
1797 function Current_Scope return Entity_Id is
1798 begin
1799 if Scope_Stack.Last = -1 then
1800 return Standard_Standard;
1801 else
1802 declare
1803 C : constant Entity_Id :=
1804 Scope_Stack.Table (Scope_Stack.Last).Entity;
1805 begin
1806 if Present (C) then
1807 return C;
1808 else
1809 return Standard_Standard;
1810 end if;
1811 end;
1812 end if;
1813 end Current_Scope;
1815 ------------------------
1816 -- Current_Subprogram --
1817 ------------------------
1819 function Current_Subprogram return Entity_Id is
1820 Scop : constant Entity_Id := Current_Scope;
1822 begin
1823 if Is_Subprogram (Scop) or else Is_Generic_Subprogram (Scop) then
1824 return Scop;
1825 else
1826 return Enclosing_Subprogram (Scop);
1827 end if;
1828 end Current_Subprogram;
1830 ---------------------
1831 -- Defining_Entity --
1832 ---------------------
1834 function Defining_Entity (N : Node_Id) return Entity_Id is
1835 K : constant Node_Kind := Nkind (N);
1836 Err : Entity_Id := Empty;
1838 begin
1839 case K is
1840 when
1841 N_Subprogram_Declaration |
1842 N_Abstract_Subprogram_Declaration |
1843 N_Subprogram_Body |
1844 N_Package_Declaration |
1845 N_Subprogram_Renaming_Declaration |
1846 N_Subprogram_Body_Stub |
1847 N_Generic_Subprogram_Declaration |
1848 N_Generic_Package_Declaration |
1849 N_Formal_Subprogram_Declaration
1851 return Defining_Entity (Specification (N));
1853 when
1854 N_Component_Declaration |
1855 N_Defining_Program_Unit_Name |
1856 N_Discriminant_Specification |
1857 N_Entry_Body |
1858 N_Entry_Declaration |
1859 N_Entry_Index_Specification |
1860 N_Exception_Declaration |
1861 N_Exception_Renaming_Declaration |
1862 N_Formal_Object_Declaration |
1863 N_Formal_Package_Declaration |
1864 N_Formal_Type_Declaration |
1865 N_Full_Type_Declaration |
1866 N_Implicit_Label_Declaration |
1867 N_Incomplete_Type_Declaration |
1868 N_Loop_Parameter_Specification |
1869 N_Number_Declaration |
1870 N_Object_Declaration |
1871 N_Object_Renaming_Declaration |
1872 N_Package_Body_Stub |
1873 N_Parameter_Specification |
1874 N_Private_Extension_Declaration |
1875 N_Private_Type_Declaration |
1876 N_Protected_Body |
1877 N_Protected_Body_Stub |
1878 N_Protected_Type_Declaration |
1879 N_Single_Protected_Declaration |
1880 N_Single_Task_Declaration |
1881 N_Subtype_Declaration |
1882 N_Task_Body |
1883 N_Task_Body_Stub |
1884 N_Task_Type_Declaration
1886 return Defining_Identifier (N);
1888 when N_Subunit =>
1889 return Defining_Entity (Proper_Body (N));
1891 when
1892 N_Function_Instantiation |
1893 N_Function_Specification |
1894 N_Generic_Function_Renaming_Declaration |
1895 N_Generic_Package_Renaming_Declaration |
1896 N_Generic_Procedure_Renaming_Declaration |
1897 N_Package_Body |
1898 N_Package_Instantiation |
1899 N_Package_Renaming_Declaration |
1900 N_Package_Specification |
1901 N_Procedure_Instantiation |
1902 N_Procedure_Specification
1904 declare
1905 Nam : constant Node_Id := Defining_Unit_Name (N);
1907 begin
1908 if Nkind (Nam) in N_Entity then
1909 return Nam;
1911 -- For Error, make up a name and attach to declaration
1912 -- so we can continue semantic analysis
1914 elsif Nam = Error then
1915 Err :=
1916 Make_Defining_Identifier (Sloc (N),
1917 Chars => New_Internal_Name ('T'));
1918 Set_Defining_Unit_Name (N, Err);
1920 return Err;
1921 -- If not an entity, get defining identifier
1923 else
1924 return Defining_Identifier (Nam);
1925 end if;
1926 end;
1928 when N_Block_Statement =>
1929 return Entity (Identifier (N));
1931 when others =>
1932 raise Program_Error;
1934 end case;
1935 end Defining_Entity;
1937 --------------------------
1938 -- Denotes_Discriminant --
1939 --------------------------
1941 function Denotes_Discriminant
1942 (N : Node_Id;
1943 Check_Concurrent : Boolean := False) return Boolean
1945 E : Entity_Id;
1946 begin
1947 if not Is_Entity_Name (N)
1948 or else No (Entity (N))
1949 then
1950 return False;
1951 else
1952 E := Entity (N);
1953 end if;
1955 -- If we are checking for a protected type, the discriminant may have
1956 -- been rewritten as the corresponding discriminal of the original type
1957 -- or of the corresponding concurrent record, depending on whether we
1958 -- are in the spec or body of the protected type.
1960 return Ekind (E) = E_Discriminant
1961 or else
1962 (Check_Concurrent
1963 and then Ekind (E) = E_In_Parameter
1964 and then Present (Discriminal_Link (E))
1965 and then
1966 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
1967 or else
1968 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
1970 end Denotes_Discriminant;
1972 -----------------------------
1973 -- Depends_On_Discriminant --
1974 -----------------------------
1976 function Depends_On_Discriminant (N : Node_Id) return Boolean is
1977 L : Node_Id;
1978 H : Node_Id;
1980 begin
1981 Get_Index_Bounds (N, L, H);
1982 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
1983 end Depends_On_Discriminant;
1985 -------------------------
1986 -- Designate_Same_Unit --
1987 -------------------------
1989 function Designate_Same_Unit
1990 (Name1 : Node_Id;
1991 Name2 : Node_Id) return Boolean
1993 K1 : constant Node_Kind := Nkind (Name1);
1994 K2 : constant Node_Kind := Nkind (Name2);
1996 function Prefix_Node (N : Node_Id) return Node_Id;
1997 -- Returns the parent unit name node of a defining program unit name
1998 -- or the prefix if N is a selected component or an expanded name.
2000 function Select_Node (N : Node_Id) return Node_Id;
2001 -- Returns the defining identifier node of a defining program unit
2002 -- name or the selector node if N is a selected component or an
2003 -- expanded name.
2005 -----------------
2006 -- Prefix_Node --
2007 -----------------
2009 function Prefix_Node (N : Node_Id) return Node_Id is
2010 begin
2011 if Nkind (N) = N_Defining_Program_Unit_Name then
2012 return Name (N);
2014 else
2015 return Prefix (N);
2016 end if;
2017 end Prefix_Node;
2019 -----------------
2020 -- Select_Node --
2021 -----------------
2023 function Select_Node (N : Node_Id) return Node_Id is
2024 begin
2025 if Nkind (N) = N_Defining_Program_Unit_Name then
2026 return Defining_Identifier (N);
2028 else
2029 return Selector_Name (N);
2030 end if;
2031 end Select_Node;
2033 -- Start of processing for Designate_Next_Unit
2035 begin
2036 if (K1 = N_Identifier or else
2037 K1 = N_Defining_Identifier)
2038 and then
2039 (K2 = N_Identifier or else
2040 K2 = N_Defining_Identifier)
2041 then
2042 return Chars (Name1) = Chars (Name2);
2044 elsif
2045 (K1 = N_Expanded_Name or else
2046 K1 = N_Selected_Component or else
2047 K1 = N_Defining_Program_Unit_Name)
2048 and then
2049 (K2 = N_Expanded_Name or else
2050 K2 = N_Selected_Component or else
2051 K2 = N_Defining_Program_Unit_Name)
2052 then
2053 return
2054 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
2055 and then
2056 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
2058 else
2059 return False;
2060 end if;
2061 end Designate_Same_Unit;
2063 ----------------------------
2064 -- Enclosing_Generic_Body --
2065 ----------------------------
2067 function Enclosing_Generic_Body
2068 (N : Node_Id) return Node_Id
2070 P : Node_Id;
2071 Decl : Node_Id;
2072 Spec : Node_Id;
2074 begin
2075 P := Parent (N);
2076 while Present (P) loop
2077 if Nkind (P) = N_Package_Body
2078 or else Nkind (P) = N_Subprogram_Body
2079 then
2080 Spec := Corresponding_Spec (P);
2082 if Present (Spec) then
2083 Decl := Unit_Declaration_Node (Spec);
2085 if Nkind (Decl) = N_Generic_Package_Declaration
2086 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2087 then
2088 return P;
2089 end if;
2090 end if;
2091 end if;
2093 P := Parent (P);
2094 end loop;
2096 return Empty;
2097 end Enclosing_Generic_Body;
2099 ----------------------------
2100 -- Enclosing_Generic_Unit --
2101 ----------------------------
2103 function Enclosing_Generic_Unit
2104 (N : Node_Id) return Node_Id
2106 P : Node_Id;
2107 Decl : Node_Id;
2108 Spec : Node_Id;
2110 begin
2111 P := Parent (N);
2112 while Present (P) loop
2113 if Nkind (P) = N_Generic_Package_Declaration
2114 or else Nkind (P) = N_Generic_Subprogram_Declaration
2115 then
2116 return P;
2118 elsif Nkind (P) = N_Package_Body
2119 or else Nkind (P) = N_Subprogram_Body
2120 then
2121 Spec := Corresponding_Spec (P);
2123 if Present (Spec) then
2124 Decl := Unit_Declaration_Node (Spec);
2126 if Nkind (Decl) = N_Generic_Package_Declaration
2127 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2128 then
2129 return Decl;
2130 end if;
2131 end if;
2132 end if;
2134 P := Parent (P);
2135 end loop;
2137 return Empty;
2138 end Enclosing_Generic_Unit;
2140 -------------------------------
2141 -- Enclosing_Lib_Unit_Entity --
2142 -------------------------------
2144 function Enclosing_Lib_Unit_Entity return Entity_Id is
2145 Unit_Entity : Entity_Id;
2147 begin
2148 -- Look for enclosing library unit entity by following scope links.
2149 -- Equivalent to, but faster than indexing through the scope stack.
2151 Unit_Entity := Current_Scope;
2152 while (Present (Scope (Unit_Entity))
2153 and then Scope (Unit_Entity) /= Standard_Standard)
2154 and not Is_Child_Unit (Unit_Entity)
2155 loop
2156 Unit_Entity := Scope (Unit_Entity);
2157 end loop;
2159 return Unit_Entity;
2160 end Enclosing_Lib_Unit_Entity;
2162 -----------------------------
2163 -- Enclosing_Lib_Unit_Node --
2164 -----------------------------
2166 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
2167 Current_Node : Node_Id;
2169 begin
2170 Current_Node := N;
2171 while Present (Current_Node)
2172 and then Nkind (Current_Node) /= N_Compilation_Unit
2173 loop
2174 Current_Node := Parent (Current_Node);
2175 end loop;
2177 if Nkind (Current_Node) /= N_Compilation_Unit then
2178 return Empty;
2179 end if;
2181 return Current_Node;
2182 end Enclosing_Lib_Unit_Node;
2184 --------------------------
2185 -- Enclosing_Subprogram --
2186 --------------------------
2188 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
2189 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
2191 begin
2192 if Dynamic_Scope = Standard_Standard then
2193 return Empty;
2195 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
2196 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
2198 elsif Ekind (Dynamic_Scope) = E_Block
2199 or else Ekind (Dynamic_Scope) = E_Return_Statement
2200 then
2201 return Enclosing_Subprogram (Dynamic_Scope);
2203 elsif Ekind (Dynamic_Scope) = E_Task_Type then
2204 return Get_Task_Body_Procedure (Dynamic_Scope);
2206 elsif Convention (Dynamic_Scope) = Convention_Protected then
2207 return Protected_Body_Subprogram (Dynamic_Scope);
2209 else
2210 return Dynamic_Scope;
2211 end if;
2212 end Enclosing_Subprogram;
2214 ------------------------
2215 -- Ensure_Freeze_Node --
2216 ------------------------
2218 procedure Ensure_Freeze_Node (E : Entity_Id) is
2219 FN : Node_Id;
2221 begin
2222 if No (Freeze_Node (E)) then
2223 FN := Make_Freeze_Entity (Sloc (E));
2224 Set_Has_Delayed_Freeze (E);
2225 Set_Freeze_Node (E, FN);
2226 Set_Access_Types_To_Process (FN, No_Elist);
2227 Set_TSS_Elist (FN, No_Elist);
2228 Set_Entity (FN, E);
2229 end if;
2230 end Ensure_Freeze_Node;
2232 ----------------
2233 -- Enter_Name --
2234 ----------------
2236 procedure Enter_Name (Def_Id : Entity_Id) is
2237 C : constant Entity_Id := Current_Entity (Def_Id);
2238 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
2239 S : constant Entity_Id := Current_Scope;
2241 function Is_Private_Component_Renaming (N : Node_Id) return Boolean;
2242 -- Recognize a renaming declaration that is introduced for private
2243 -- components of a protected type. We treat these as weak declarations
2244 -- so that they are overridden by entities with the same name that
2245 -- come from source, such as formals or local variables of a given
2246 -- protected declaration.
2248 -----------------------------------
2249 -- Is_Private_Component_Renaming --
2250 -----------------------------------
2252 function Is_Private_Component_Renaming (N : Node_Id) return Boolean is
2253 begin
2254 return not Comes_From_Source (N)
2255 and then not Comes_From_Source (Current_Scope)
2256 and then Nkind (N) = N_Object_Renaming_Declaration;
2257 end Is_Private_Component_Renaming;
2259 -- Start of processing for Enter_Name
2261 begin
2262 Generate_Definition (Def_Id);
2264 -- Add new name to current scope declarations. Check for duplicate
2265 -- declaration, which may or may not be a genuine error.
2267 if Present (E) then
2269 -- Case of previous entity entered because of a missing declaration
2270 -- or else a bad subtype indication. Best is to use the new entity,
2271 -- and make the previous one invisible.
2273 if Etype (E) = Any_Type then
2274 Set_Is_Immediately_Visible (E, False);
2276 -- Case of renaming declaration constructed for package instances.
2277 -- if there is an explicit declaration with the same identifier,
2278 -- the renaming is not immediately visible any longer, but remains
2279 -- visible through selected component notation.
2281 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
2282 and then not Comes_From_Source (E)
2283 then
2284 Set_Is_Immediately_Visible (E, False);
2286 -- The new entity may be the package renaming, which has the same
2287 -- same name as a generic formal which has been seen already.
2289 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
2290 and then not Comes_From_Source (Def_Id)
2291 then
2292 Set_Is_Immediately_Visible (E, False);
2294 -- For a fat pointer corresponding to a remote access to subprogram,
2295 -- we use the same identifier as the RAS type, so that the proper
2296 -- name appears in the stub. This type is only retrieved through
2297 -- the RAS type and never by visibility, and is not added to the
2298 -- visibility list (see below).
2300 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
2301 and then Present (Corresponding_Remote_Type (Def_Id))
2302 then
2303 null;
2305 -- A controller component for a type extension overrides the
2306 -- inherited component.
2308 elsif Chars (E) = Name_uController then
2309 null;
2311 -- Case of an implicit operation or derived literal. The new entity
2312 -- hides the implicit one, which is removed from all visibility,
2313 -- i.e. the entity list of its scope, and homonym chain of its name.
2315 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
2316 or else Is_Internal (E)
2317 then
2318 declare
2319 Prev : Entity_Id;
2320 Prev_Vis : Entity_Id;
2321 Decl : constant Node_Id := Parent (E);
2323 begin
2324 -- If E is an implicit declaration, it cannot be the first
2325 -- entity in the scope.
2327 Prev := First_Entity (Current_Scope);
2328 while Present (Prev)
2329 and then Next_Entity (Prev) /= E
2330 loop
2331 Next_Entity (Prev);
2332 end loop;
2334 if No (Prev) then
2336 -- If E is not on the entity chain of the current scope,
2337 -- it is an implicit declaration in the generic formal
2338 -- part of a generic subprogram. When analyzing the body,
2339 -- the generic formals are visible but not on the entity
2340 -- chain of the subprogram. The new entity will become
2341 -- the visible one in the body.
2343 pragma Assert
2344 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
2345 null;
2347 else
2348 Set_Next_Entity (Prev, Next_Entity (E));
2350 if No (Next_Entity (Prev)) then
2351 Set_Last_Entity (Current_Scope, Prev);
2352 end if;
2354 if E = Current_Entity (E) then
2355 Prev_Vis := Empty;
2357 else
2358 Prev_Vis := Current_Entity (E);
2359 while Homonym (Prev_Vis) /= E loop
2360 Prev_Vis := Homonym (Prev_Vis);
2361 end loop;
2362 end if;
2364 if Present (Prev_Vis) then
2366 -- Skip E in the visibility chain
2368 Set_Homonym (Prev_Vis, Homonym (E));
2370 else
2371 Set_Name_Entity_Id (Chars (E), Homonym (E));
2372 end if;
2373 end if;
2374 end;
2376 -- This section of code could use a comment ???
2378 elsif Present (Etype (E))
2379 and then Is_Concurrent_Type (Etype (E))
2380 and then E = Def_Id
2381 then
2382 return;
2384 elsif Is_Private_Component_Renaming (Parent (Def_Id)) then
2385 return;
2387 -- In the body or private part of an instance, a type extension
2388 -- may introduce a component with the same name as that of an
2389 -- actual. The legality rule is not enforced, but the semantics
2390 -- of the full type with two components of the same name are not
2391 -- clear at this point ???
2393 elsif In_Instance_Not_Visible then
2394 null;
2396 -- When compiling a package body, some child units may have become
2397 -- visible. They cannot conflict with local entities that hide them.
2399 elsif Is_Child_Unit (E)
2400 and then In_Open_Scopes (Scope (E))
2401 and then not Is_Immediately_Visible (E)
2402 then
2403 null;
2405 -- Conversely, with front-end inlining we may compile the parent
2406 -- body first, and a child unit subsequently. The context is now
2407 -- the parent spec, and body entities are not visible.
2409 elsif Is_Child_Unit (Def_Id)
2410 and then Is_Package_Body_Entity (E)
2411 and then not In_Package_Body (Current_Scope)
2412 then
2413 null;
2415 -- Case of genuine duplicate declaration
2417 else
2418 Error_Msg_Sloc := Sloc (E);
2420 -- If the previous declaration is an incomplete type declaration
2421 -- this may be an attempt to complete it with a private type.
2422 -- The following avoids confusing cascaded errors.
2424 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
2425 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
2426 then
2427 Error_Msg_N
2428 ("incomplete type cannot be completed" &
2429 " with a private declaration",
2430 Parent (Def_Id));
2431 Set_Is_Immediately_Visible (E, False);
2432 Set_Full_View (E, Def_Id);
2434 elsif Ekind (E) = E_Discriminant
2435 and then Present (Scope (Def_Id))
2436 and then Scope (Def_Id) /= Current_Scope
2437 then
2438 -- An inherited component of a record conflicts with
2439 -- a new discriminant. The discriminant is inserted first
2440 -- in the scope, but the error should be posted on it, not
2441 -- on the component.
2443 Error_Msg_Sloc := Sloc (Def_Id);
2444 Error_Msg_N ("& conflicts with declaration#", E);
2445 return;
2447 -- If the name of the unit appears in its own context clause,
2448 -- a dummy package with the name has already been created, and
2449 -- the error emitted. Try to continue quietly.
2451 elsif Error_Posted (E)
2452 and then Sloc (E) = No_Location
2453 and then Nkind (Parent (E)) = N_Package_Specification
2454 and then Current_Scope = Standard_Standard
2455 then
2456 Set_Scope (Def_Id, Current_Scope);
2457 return;
2459 else
2460 Error_Msg_N ("& conflicts with declaration#", Def_Id);
2462 -- Avoid cascaded messages with duplicate components in
2463 -- derived types.
2465 if Ekind (E) = E_Component
2466 or else Ekind (E) = E_Discriminant
2467 then
2468 return;
2469 end if;
2470 end if;
2472 if Nkind (Parent (Parent (Def_Id)))
2473 = N_Generic_Subprogram_Declaration
2474 and then Def_Id =
2475 Defining_Entity (Specification (Parent (Parent (Def_Id))))
2476 then
2477 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
2478 end if;
2480 -- If entity is in standard, then we are in trouble, because
2481 -- it means that we have a library package with a duplicated
2482 -- name. That's hard to recover from, so abort!
2484 if S = Standard_Standard then
2485 raise Unrecoverable_Error;
2487 -- Otherwise we continue with the declaration. Having two
2488 -- identical declarations should not cause us too much trouble!
2490 else
2491 null;
2492 end if;
2493 end if;
2494 end if;
2496 -- If we fall through, declaration is OK , or OK enough to continue
2498 -- If Def_Id is a discriminant or a record component we are in the
2499 -- midst of inheriting components in a derived record definition.
2500 -- Preserve their Ekind and Etype.
2502 if Ekind (Def_Id) = E_Discriminant
2503 or else Ekind (Def_Id) = E_Component
2504 then
2505 null;
2507 -- If a type is already set, leave it alone (happens whey a type
2508 -- declaration is reanalyzed following a call to the optimizer)
2510 elsif Present (Etype (Def_Id)) then
2511 null;
2513 -- Otherwise, the kind E_Void insures that premature uses of the entity
2514 -- will be detected. Any_Type insures that no cascaded errors will occur
2516 else
2517 Set_Ekind (Def_Id, E_Void);
2518 Set_Etype (Def_Id, Any_Type);
2519 end if;
2521 -- Inherited discriminants and components in derived record types are
2522 -- immediately visible. Itypes are not.
2524 if Ekind (Def_Id) = E_Discriminant
2525 or else Ekind (Def_Id) = E_Component
2526 or else (No (Corresponding_Remote_Type (Def_Id))
2527 and then not Is_Itype (Def_Id))
2528 then
2529 Set_Is_Immediately_Visible (Def_Id);
2530 Set_Current_Entity (Def_Id);
2531 end if;
2533 Set_Homonym (Def_Id, C);
2534 Append_Entity (Def_Id, S);
2535 Set_Public_Status (Def_Id);
2537 -- Warn if new entity hides an old one
2539 if Warn_On_Hiding and then Present (C)
2541 -- Don't warn for record components since they always have a well
2542 -- defined scope which does not confuse other uses. Note that in
2543 -- some cases, Ekind has not been set yet.
2545 and then Ekind (C) /= E_Component
2546 and then Ekind (C) /= E_Discriminant
2547 and then Nkind (Parent (C)) /= N_Component_Declaration
2548 and then Ekind (Def_Id) /= E_Component
2549 and then Ekind (Def_Id) /= E_Discriminant
2550 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
2552 -- Don't warn for one character variables. It is too common to use
2553 -- such variables as locals and will just cause too many false hits.
2555 and then Length_Of_Name (Chars (C)) /= 1
2557 -- Don't warn for non-source eneities
2559 and then Comes_From_Source (C)
2560 and then Comes_From_Source (Def_Id)
2562 -- Don't warn unless entity in question is in extended main source
2564 and then In_Extended_Main_Source_Unit (Def_Id)
2566 -- Finally, the hidden entity must be either immediately visible
2567 -- or use visible (from a used package)
2569 and then
2570 (Is_Immediately_Visible (C)
2571 or else
2572 Is_Potentially_Use_Visible (C))
2573 then
2574 Error_Msg_Sloc := Sloc (C);
2575 Error_Msg_N ("declaration hides &#?", Def_Id);
2576 end if;
2577 end Enter_Name;
2579 --------------------------
2580 -- Explain_Limited_Type --
2581 --------------------------
2583 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
2584 C : Entity_Id;
2586 begin
2587 -- For array, component type must be limited
2589 if Is_Array_Type (T) then
2590 Error_Msg_Node_2 := T;
2591 Error_Msg_NE
2592 ("\component type& of type& is limited", N, Component_Type (T));
2593 Explain_Limited_Type (Component_Type (T), N);
2595 elsif Is_Record_Type (T) then
2597 -- No need for extra messages if explicit limited record
2599 if Is_Limited_Record (Base_Type (T)) then
2600 return;
2601 end if;
2603 -- Otherwise find a limited component. Check only components that
2604 -- come from source, or inherited components that appear in the
2605 -- source of the ancestor.
2607 C := First_Component (T);
2608 while Present (C) loop
2609 if Is_Limited_Type (Etype (C))
2610 and then
2611 (Comes_From_Source (C)
2612 or else
2613 (Present (Original_Record_Component (C))
2614 and then
2615 Comes_From_Source (Original_Record_Component (C))))
2616 then
2617 Error_Msg_Node_2 := T;
2618 Error_Msg_NE ("\component& of type& has limited type", N, C);
2619 Explain_Limited_Type (Etype (C), N);
2620 return;
2621 end if;
2623 Next_Component (C);
2624 end loop;
2626 -- The type may be declared explicitly limited, even if no component
2627 -- of it is limited, in which case we fall out of the loop.
2628 return;
2629 end if;
2630 end Explain_Limited_Type;
2632 -------------------------------------
2633 -- Find_Corresponding_Discriminant --
2634 -------------------------------------
2636 function Find_Corresponding_Discriminant
2637 (Id : Node_Id;
2638 Typ : Entity_Id) return Entity_Id
2640 Par_Disc : Entity_Id;
2641 Old_Disc : Entity_Id;
2642 New_Disc : Entity_Id;
2644 begin
2645 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
2647 -- The original type may currently be private, and the discriminant
2648 -- only appear on its full view.
2650 if Is_Private_Type (Scope (Par_Disc))
2651 and then not Has_Discriminants (Scope (Par_Disc))
2652 and then Present (Full_View (Scope (Par_Disc)))
2653 then
2654 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
2655 else
2656 Old_Disc := First_Discriminant (Scope (Par_Disc));
2657 end if;
2659 if Is_Class_Wide_Type (Typ) then
2660 New_Disc := First_Discriminant (Root_Type (Typ));
2661 else
2662 New_Disc := First_Discriminant (Typ);
2663 end if;
2665 while Present (Old_Disc) and then Present (New_Disc) loop
2666 if Old_Disc = Par_Disc then
2667 return New_Disc;
2668 else
2669 Next_Discriminant (Old_Disc);
2670 Next_Discriminant (New_Disc);
2671 end if;
2672 end loop;
2674 -- Should always find it
2676 raise Program_Error;
2677 end Find_Corresponding_Discriminant;
2679 --------------------------
2680 -- Find_Overlaid_Object --
2681 --------------------------
2683 function Find_Overlaid_Object (N : Node_Id) return Entity_Id is
2684 Expr : Node_Id;
2686 begin
2687 -- We are looking for one of the two following forms:
2689 -- for X'Address use Y'Address
2691 -- or
2693 -- Const : constant Address := expr;
2694 -- ...
2695 -- for X'Address use Const;
2697 -- In the second case, the expr is either Y'Address, or recursively a
2698 -- constant that eventually references Y'Address.
2700 if Nkind (N) = N_Attribute_Definition_Clause
2701 and then Chars (N) = Name_Address
2702 then
2703 -- This loop checks the form of the expression for Y'Address where Y
2704 -- is an object entity name. The first loop checks the original
2705 -- expression in the attribute definition clause. Subsequent loops
2706 -- check referenced constants.
2708 Expr := Expression (N);
2709 loop
2710 -- Check for Y'Address where Y is an object entity
2712 if Nkind (Expr) = N_Attribute_Reference
2713 and then Attribute_Name (Expr) = Name_Address
2714 and then Is_Entity_Name (Prefix (Expr))
2715 and then Is_Object (Entity (Prefix (Expr)))
2716 then
2717 return Entity (Prefix (Expr));
2719 -- Check for Const where Const is a constant entity
2721 elsif Is_Entity_Name (Expr)
2722 and then Ekind (Entity (Expr)) = E_Constant
2723 then
2724 Expr := Constant_Value (Entity (Expr));
2726 -- Anything else does not need checking
2728 else
2729 exit;
2730 end if;
2731 end loop;
2732 end if;
2734 return Empty;
2735 end Find_Overlaid_Object;
2737 --------------------------------------------
2738 -- Find_Overridden_Synchronized_Primitive --
2739 --------------------------------------------
2741 function Find_Overridden_Synchronized_Primitive
2742 (Def_Id : Entity_Id;
2743 First_Hom : Entity_Id;
2744 Ifaces_List : Elist_Id;
2745 In_Scope : Boolean) return Entity_Id
2747 Candidate : Entity_Id := Empty;
2748 Hom : Entity_Id := Empty;
2749 Iface_Typ : Entity_Id;
2750 Subp : Entity_Id := Empty;
2751 Tag_Typ : Entity_Id;
2753 function Find_Parameter_Type (Param : Node_Id) return Entity_Id;
2754 -- Return the type of a formal parameter as determined by its
2755 -- specification.
2757 function Has_Correct_Formal_Mode (Subp : Entity_Id) return Boolean;
2758 -- For an overridden subprogram Subp, check whether the mode of its
2759 -- first parameter is correct depending on the kind of Tag_Typ.
2761 function Matches_Prefixed_View_Profile
2762 (Prim_Params : List_Id;
2763 Iface_Params : List_Id) return Boolean;
2764 -- Determine whether a subprogram's parameter profile Prim_Params
2765 -- matches that of a potentially overriden interface subprogram
2766 -- Iface_Params. Also determine if the type of first parameter of
2767 -- Iface_Params is an implemented interface.
2769 -------------------------
2770 -- Find_Parameter_Type --
2771 -------------------------
2773 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
2774 begin
2775 pragma Assert (Nkind (Param) = N_Parameter_Specification);
2777 if Nkind (Parameter_Type (Param)) = N_Access_Definition then
2778 return Etype (Subtype_Mark (Parameter_Type (Param)));
2780 else
2781 return Etype (Parameter_Type (Param));
2782 end if;
2783 end Find_Parameter_Type;
2785 -----------------------------
2786 -- Has_Correct_Formal_Mode --
2787 -----------------------------
2789 function Has_Correct_Formal_Mode (Subp : Entity_Id) return Boolean is
2790 Param : Node_Id;
2792 begin
2793 Param := First_Formal (Subp);
2795 -- In order for an entry or a protected procedure to override, the
2796 -- first parameter of the overridden routine must be of mode "out",
2797 -- "in out" or access-to-variable.
2799 if (Ekind (Subp) = E_Entry
2800 or else Ekind (Subp) = E_Procedure)
2801 and then Is_Protected_Type (Tag_Typ)
2802 and then Ekind (Param) /= E_In_Out_Parameter
2803 and then Ekind (Param) /= E_Out_Parameter
2804 and then Nkind (Parameter_Type (Parent (Param))) /=
2805 N_Access_Definition
2806 then
2807 return False;
2808 end if;
2810 -- All other cases are OK since a task entry or routine does not
2811 -- have a restriction on the mode of the first parameter of the
2812 -- overridden interface routine.
2814 return True;
2815 end Has_Correct_Formal_Mode;
2817 -----------------------------------
2818 -- Matches_Prefixed_View_Profile --
2819 -----------------------------------
2821 function Matches_Prefixed_View_Profile
2822 (Prim_Params : List_Id;
2823 Iface_Params : List_Id) return Boolean
2825 Iface_Id : Entity_Id;
2826 Iface_Param : Node_Id;
2827 Iface_Typ : Entity_Id;
2828 Prim_Id : Entity_Id;
2829 Prim_Param : Node_Id;
2830 Prim_Typ : Entity_Id;
2832 function Is_Implemented (Iface : Entity_Id) return Boolean;
2833 -- Determine if Iface is implemented by the current task or
2834 -- protected type.
2836 --------------------
2837 -- Is_Implemented --
2838 --------------------
2840 function Is_Implemented (Iface : Entity_Id) return Boolean is
2841 Iface_Elmt : Elmt_Id;
2843 begin
2844 Iface_Elmt := First_Elmt (Ifaces_List);
2845 while Present (Iface_Elmt) loop
2846 if Node (Iface_Elmt) = Iface then
2847 return True;
2848 end if;
2850 Next_Elmt (Iface_Elmt);
2851 end loop;
2853 return False;
2854 end Is_Implemented;
2856 -- Start of processing for Matches_Prefixed_View_Profile
2858 begin
2859 Iface_Param := First (Iface_Params);
2860 Iface_Typ := Find_Parameter_Type (Iface_Param);
2861 Prim_Param := First (Prim_Params);
2863 -- The first parameter of the potentially overriden subprogram
2864 -- must be an interface implemented by Prim.
2866 if not Is_Interface (Iface_Typ)
2867 or else not Is_Implemented (Iface_Typ)
2868 then
2869 return False;
2870 end if;
2872 -- The checks on the object parameters are done, move onto the rest
2873 -- of the parameters.
2875 if not In_Scope then
2876 Prim_Param := Next (Prim_Param);
2877 end if;
2879 Iface_Param := Next (Iface_Param);
2880 while Present (Iface_Param) and then Present (Prim_Param) loop
2881 Iface_Id := Defining_Identifier (Iface_Param);
2882 Iface_Typ := Find_Parameter_Type (Iface_Param);
2883 Prim_Id := Defining_Identifier (Prim_Param);
2884 Prim_Typ := Find_Parameter_Type (Prim_Param);
2886 -- Case of multiple interface types inside a parameter profile
2888 -- (Obj_Param : in out Iface; ...; Param : Iface)
2890 -- If the interface type is implemented, then the matching type
2891 -- in the primitive should be the implementing record type.
2893 if Ekind (Iface_Typ) = E_Record_Type
2894 and then Is_Interface (Iface_Typ)
2895 and then Is_Implemented (Iface_Typ)
2896 then
2897 if Prim_Typ /= Tag_Typ then
2898 return False;
2899 end if;
2901 -- The two parameters must be both mode and subtype conformant
2903 elsif Ekind (Iface_Id) /= Ekind (Prim_Id)
2904 or else
2905 not Conforming_Types (Iface_Typ, Prim_Typ, Subtype_Conformant)
2906 then
2907 return False;
2908 end if;
2910 Next (Iface_Param);
2911 Next (Prim_Param);
2912 end loop;
2914 -- One of the two lists contains more parameters than the other
2916 if Present (Iface_Param) or else Present (Prim_Param) then
2917 return False;
2918 end if;
2920 return True;
2921 end Matches_Prefixed_View_Profile;
2923 -- Start of processing for Find_Overridden_Synchronized_Primitive
2925 begin
2926 -- At this point the caller should have collected the interfaces
2927 -- implemented by the synchronized type.
2929 pragma Assert (Present (Ifaces_List));
2931 -- Find the tagged type to which subprogram Def_Id is primitive. If the
2932 -- subprogram was declared within a protected or a task type, the type
2933 -- is the scope itself, otherwise it is the type of the first parameter.
2935 if In_Scope then
2936 Tag_Typ := Scope (Def_Id);
2938 elsif Present (First_Formal (Def_Id)) then
2939 Tag_Typ := Find_Parameter_Type (Parent (First_Formal (Def_Id)));
2941 -- A parameterless subprogram which is declared outside a synchronized
2942 -- type cannot act as a primitive, thus it cannot override anything.
2944 else
2945 return Empty;
2946 end if;
2948 -- Traverse the homonym chain, looking at a potentially overriden
2949 -- subprogram that belongs to an implemented interface.
2951 Hom := First_Hom;
2952 while Present (Hom) loop
2953 Subp := Hom;
2955 -- Entries can override abstract or null interface procedures
2957 if Ekind (Def_Id) = E_Entry
2958 and then Ekind (Subp) = E_Procedure
2959 and then Nkind (Parent (Subp)) = N_Procedure_Specification
2960 and then (Is_Abstract_Subprogram (Subp)
2961 or else Null_Present (Parent (Subp)))
2962 then
2963 while Present (Alias (Subp)) loop
2964 Subp := Alias (Subp);
2965 end loop;
2967 if Matches_Prefixed_View_Profile
2968 (Parameter_Specifications (Parent (Def_Id)),
2969 Parameter_Specifications (Parent (Subp)))
2970 then
2971 Candidate := Subp;
2973 -- Absolute match
2975 if Has_Correct_Formal_Mode (Candidate) then
2976 return Candidate;
2977 end if;
2978 end if;
2980 -- Procedures can override abstract or null interface procedures
2982 elsif Ekind (Def_Id) = E_Procedure
2983 and then Ekind (Subp) = E_Procedure
2984 and then Nkind (Parent (Subp)) = N_Procedure_Specification
2985 and then (Is_Abstract_Subprogram (Subp)
2986 or else Null_Present (Parent (Subp)))
2987 and then Matches_Prefixed_View_Profile
2988 (Parameter_Specifications (Parent (Def_Id)),
2989 Parameter_Specifications (Parent (Subp)))
2990 then
2991 Candidate := Subp;
2993 -- Absolute match
2995 if Has_Correct_Formal_Mode (Candidate) then
2996 return Candidate;
2997 end if;
2999 -- Functions can override abstract interface functions
3001 elsif Ekind (Def_Id) = E_Function
3002 and then Ekind (Subp) = E_Function
3003 and then Nkind (Parent (Subp)) = N_Function_Specification
3004 and then Is_Abstract_Subprogram (Subp)
3005 and then Matches_Prefixed_View_Profile
3006 (Parameter_Specifications (Parent (Def_Id)),
3007 Parameter_Specifications (Parent (Subp)))
3008 and then Etype (Result_Definition (Parent (Def_Id))) =
3009 Etype (Result_Definition (Parent (Subp)))
3010 then
3011 return Subp;
3012 end if;
3014 Hom := Homonym (Hom);
3015 end loop;
3017 -- After examining all candidates for overriding, we are left with
3018 -- the best match which is a mode incompatible interface routine.
3019 -- Do not emit an error if the Expander is active since this error
3020 -- will be detected later on after all concurrent types are expanded
3021 -- and all wrappers are built. This check is meant for spec-only
3022 -- compilations.
3024 if Present (Candidate)
3025 and then not Expander_Active
3026 then
3027 Iface_Typ := Find_Parameter_Type (Parent (First_Formal (Candidate)));
3029 -- Def_Id is primitive of a protected type, declared inside the type,
3030 -- and the candidate is primitive of a limited or synchronized
3031 -- interface.
3033 if In_Scope
3034 and then Is_Protected_Type (Tag_Typ)
3035 and then
3036 (Is_Limited_Interface (Iface_Typ)
3037 or else Is_Protected_Interface (Iface_Typ)
3038 or else Is_Synchronized_Interface (Iface_Typ)
3039 or else Is_Task_Interface (Iface_Typ))
3040 then
3041 -- Must reword this message, comma before to in -gnatj mode ???
3043 Error_Msg_NE
3044 ("first formal of & must be of mode `OUT`, `IN OUT` or " &
3045 "access-to-variable", Tag_Typ, Candidate);
3046 Error_Msg_N
3047 ("\to be overridden by protected procedure or entry " &
3048 "(RM 9.4(11.9/2))", Tag_Typ);
3049 end if;
3050 end if;
3052 return Candidate;
3053 end Find_Overridden_Synchronized_Primitive;
3055 -----------------------------
3056 -- Find_Static_Alternative --
3057 -----------------------------
3059 function Find_Static_Alternative (N : Node_Id) return Node_Id is
3060 Expr : constant Node_Id := Expression (N);
3061 Val : constant Uint := Expr_Value (Expr);
3062 Alt : Node_Id;
3063 Choice : Node_Id;
3065 begin
3066 Alt := First (Alternatives (N));
3068 Search : loop
3069 if Nkind (Alt) /= N_Pragma then
3070 Choice := First (Discrete_Choices (Alt));
3071 while Present (Choice) loop
3073 -- Others choice, always matches
3075 if Nkind (Choice) = N_Others_Choice then
3076 exit Search;
3078 -- Range, check if value is in the range
3080 elsif Nkind (Choice) = N_Range then
3081 exit Search when
3082 Val >= Expr_Value (Low_Bound (Choice))
3083 and then
3084 Val <= Expr_Value (High_Bound (Choice));
3086 -- Choice is a subtype name. Note that we know it must
3087 -- be a static subtype, since otherwise it would have
3088 -- been diagnosed as illegal.
3090 elsif Is_Entity_Name (Choice)
3091 and then Is_Type (Entity (Choice))
3092 then
3093 exit Search when Is_In_Range (Expr, Etype (Choice));
3095 -- Choice is a subtype indication
3097 elsif Nkind (Choice) = N_Subtype_Indication then
3098 declare
3099 C : constant Node_Id := Constraint (Choice);
3100 R : constant Node_Id := Range_Expression (C);
3102 begin
3103 exit Search when
3104 Val >= Expr_Value (Low_Bound (R))
3105 and then
3106 Val <= Expr_Value (High_Bound (R));
3107 end;
3109 -- Choice is a simple expression
3111 else
3112 exit Search when Val = Expr_Value (Choice);
3113 end if;
3115 Next (Choice);
3116 end loop;
3117 end if;
3119 Next (Alt);
3120 pragma Assert (Present (Alt));
3121 end loop Search;
3123 -- The above loop *must* terminate by finding a match, since
3124 -- we know the case statement is valid, and the value of the
3125 -- expression is known at compile time. When we fall out of
3126 -- the loop, Alt points to the alternative that we know will
3127 -- be selected at run time.
3129 return Alt;
3130 end Find_Static_Alternative;
3132 ------------------
3133 -- First_Actual --
3134 ------------------
3136 function First_Actual (Node : Node_Id) return Node_Id is
3137 N : Node_Id;
3139 begin
3140 if No (Parameter_Associations (Node)) then
3141 return Empty;
3142 end if;
3144 N := First (Parameter_Associations (Node));
3146 if Nkind (N) = N_Parameter_Association then
3147 return First_Named_Actual (Node);
3148 else
3149 return N;
3150 end if;
3151 end First_Actual;
3153 -------------------------
3154 -- Full_Qualified_Name --
3155 -------------------------
3157 function Full_Qualified_Name (E : Entity_Id) return String_Id is
3158 Res : String_Id;
3159 pragma Warnings (Off, Res);
3161 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id;
3162 -- Compute recursively the qualified name without NUL at the end
3164 ----------------------------------
3165 -- Internal_Full_Qualified_Name --
3166 ----------------------------------
3168 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id is
3169 Ent : Entity_Id := E;
3170 Parent_Name : String_Id := No_String;
3172 begin
3173 -- Deals properly with child units
3175 if Nkind (Ent) = N_Defining_Program_Unit_Name then
3176 Ent := Defining_Identifier (Ent);
3177 end if;
3179 -- Compute qualification recursively (only "Standard" has no scope)
3181 if Present (Scope (Scope (Ent))) then
3182 Parent_Name := Internal_Full_Qualified_Name (Scope (Ent));
3183 end if;
3185 -- Every entity should have a name except some expanded blocks
3186 -- don't bother about those.
3188 if Chars (Ent) = No_Name then
3189 return Parent_Name;
3190 end if;
3192 -- Add a period between Name and qualification
3194 if Parent_Name /= No_String then
3195 Start_String (Parent_Name);
3196 Store_String_Char (Get_Char_Code ('.'));
3198 else
3199 Start_String;
3200 end if;
3202 -- Generates the entity name in upper case
3204 Get_Decoded_Name_String (Chars (Ent));
3205 Set_All_Upper_Case;
3206 Store_String_Chars (Name_Buffer (1 .. Name_Len));
3207 return End_String;
3208 end Internal_Full_Qualified_Name;
3210 -- Start of processing for Full_Qualified_Name
3212 begin
3213 Res := Internal_Full_Qualified_Name (E);
3214 Store_String_Char (Get_Char_Code (ASCII.nul));
3215 return End_String;
3216 end Full_Qualified_Name;
3218 -----------------------
3219 -- Gather_Components --
3220 -----------------------
3222 procedure Gather_Components
3223 (Typ : Entity_Id;
3224 Comp_List : Node_Id;
3225 Governed_By : List_Id;
3226 Into : Elist_Id;
3227 Report_Errors : out Boolean)
3229 Assoc : Node_Id;
3230 Variant : Node_Id;
3231 Discrete_Choice : Node_Id;
3232 Comp_Item : Node_Id;
3234 Discrim : Entity_Id;
3235 Discrim_Name : Node_Id;
3236 Discrim_Value : Node_Id;
3238 begin
3239 Report_Errors := False;
3241 if No (Comp_List) or else Null_Present (Comp_List) then
3242 return;
3244 elsif Present (Component_Items (Comp_List)) then
3245 Comp_Item := First (Component_Items (Comp_List));
3247 else
3248 Comp_Item := Empty;
3249 end if;
3251 while Present (Comp_Item) loop
3253 -- Skip the tag of a tagged record, the interface tags, as well
3254 -- as all items that are not user components (anonymous types,
3255 -- rep clauses, Parent field, controller field).
3257 if Nkind (Comp_Item) = N_Component_Declaration then
3258 declare
3259 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
3260 begin
3261 if not Is_Tag (Comp)
3262 and then Chars (Comp) /= Name_uParent
3263 and then Chars (Comp) /= Name_uController
3264 then
3265 Append_Elmt (Comp, Into);
3266 end if;
3267 end;
3268 end if;
3270 Next (Comp_Item);
3271 end loop;
3273 if No (Variant_Part (Comp_List)) then
3274 return;
3275 else
3276 Discrim_Name := Name (Variant_Part (Comp_List));
3277 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
3278 end if;
3280 -- Look for the discriminant that governs this variant part.
3281 -- The discriminant *must* be in the Governed_By List
3283 Assoc := First (Governed_By);
3284 Find_Constraint : loop
3285 Discrim := First (Choices (Assoc));
3286 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
3287 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
3288 and then
3289 Chars (Corresponding_Discriminant (Entity (Discrim)))
3290 = Chars (Discrim_Name))
3291 or else Chars (Original_Record_Component (Entity (Discrim)))
3292 = Chars (Discrim_Name);
3294 if No (Next (Assoc)) then
3295 if not Is_Constrained (Typ)
3296 and then Is_Derived_Type (Typ)
3297 and then Present (Stored_Constraint (Typ))
3298 then
3299 -- If the type is a tagged type with inherited discriminants,
3300 -- use the stored constraint on the parent in order to find
3301 -- the values of discriminants that are otherwise hidden by an
3302 -- explicit constraint. Renamed discriminants are handled in
3303 -- the code above.
3305 -- If several parent discriminants are renamed by a single
3306 -- discriminant of the derived type, the call to obtain the
3307 -- Corresponding_Discriminant field only retrieves the last
3308 -- of them. We recover the constraint on the others from the
3309 -- Stored_Constraint as well.
3311 declare
3312 D : Entity_Id;
3313 C : Elmt_Id;
3315 begin
3316 D := First_Discriminant (Etype (Typ));
3317 C := First_Elmt (Stored_Constraint (Typ));
3318 while Present (D) and then Present (C) loop
3319 if Chars (Discrim_Name) = Chars (D) then
3320 if Is_Entity_Name (Node (C))
3321 and then Entity (Node (C)) = Entity (Discrim)
3322 then
3323 -- D is renamed by Discrim, whose value is given in
3324 -- Assoc.
3326 null;
3328 else
3329 Assoc :=
3330 Make_Component_Association (Sloc (Typ),
3331 New_List
3332 (New_Occurrence_Of (D, Sloc (Typ))),
3333 Duplicate_Subexpr_No_Checks (Node (C)));
3334 end if;
3335 exit Find_Constraint;
3336 end if;
3338 Next_Discriminant (D);
3339 Next_Elmt (C);
3340 end loop;
3341 end;
3342 end if;
3343 end if;
3345 if No (Next (Assoc)) then
3346 Error_Msg_NE (" missing value for discriminant&",
3347 First (Governed_By), Discrim_Name);
3348 Report_Errors := True;
3349 return;
3350 end if;
3352 Next (Assoc);
3353 end loop Find_Constraint;
3355 Discrim_Value := Expression (Assoc);
3357 if not Is_OK_Static_Expression (Discrim_Value) then
3358 Error_Msg_FE
3359 ("value for discriminant & must be static!",
3360 Discrim_Value, Discrim);
3361 Why_Not_Static (Discrim_Value);
3362 Report_Errors := True;
3363 return;
3364 end if;
3366 Search_For_Discriminant_Value : declare
3367 Low : Node_Id;
3368 High : Node_Id;
3370 UI_High : Uint;
3371 UI_Low : Uint;
3372 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
3374 begin
3375 Find_Discrete_Value : while Present (Variant) loop
3376 Discrete_Choice := First (Discrete_Choices (Variant));
3377 while Present (Discrete_Choice) loop
3379 exit Find_Discrete_Value when
3380 Nkind (Discrete_Choice) = N_Others_Choice;
3382 Get_Index_Bounds (Discrete_Choice, Low, High);
3384 UI_Low := Expr_Value (Low);
3385 UI_High := Expr_Value (High);
3387 exit Find_Discrete_Value when
3388 UI_Low <= UI_Discrim_Value
3389 and then
3390 UI_High >= UI_Discrim_Value;
3392 Next (Discrete_Choice);
3393 end loop;
3395 Next_Non_Pragma (Variant);
3396 end loop Find_Discrete_Value;
3397 end Search_For_Discriminant_Value;
3399 if No (Variant) then
3400 Error_Msg_NE
3401 ("value of discriminant & is out of range", Discrim_Value, Discrim);
3402 Report_Errors := True;
3403 return;
3404 end if;
3406 -- If we have found the corresponding choice, recursively add its
3407 -- components to the Into list.
3409 Gather_Components (Empty,
3410 Component_List (Variant), Governed_By, Into, Report_Errors);
3411 end Gather_Components;
3413 ------------------------
3414 -- Get_Actual_Subtype --
3415 ------------------------
3417 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
3418 Typ : constant Entity_Id := Etype (N);
3419 Utyp : Entity_Id := Underlying_Type (Typ);
3420 Decl : Node_Id;
3421 Atyp : Entity_Id;
3423 begin
3424 if No (Utyp) then
3425 Utyp := Typ;
3426 end if;
3428 -- If what we have is an identifier that references a subprogram
3429 -- formal, or a variable or constant object, then we get the actual
3430 -- subtype from the referenced entity if one has been built.
3432 if Nkind (N) = N_Identifier
3433 and then
3434 (Is_Formal (Entity (N))
3435 or else Ekind (Entity (N)) = E_Constant
3436 or else Ekind (Entity (N)) = E_Variable)
3437 and then Present (Actual_Subtype (Entity (N)))
3438 then
3439 return Actual_Subtype (Entity (N));
3441 -- Actual subtype of unchecked union is always itself. We never need
3442 -- the "real" actual subtype. If we did, we couldn't get it anyway
3443 -- because the discriminant is not available. The restrictions on
3444 -- Unchecked_Union are designed to make sure that this is OK.
3446 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
3447 return Typ;
3449 -- Here for the unconstrained case, we must find actual subtype
3450 -- No actual subtype is available, so we must build it on the fly.
3452 -- Checking the type, not the underlying type, for constrainedness
3453 -- seems to be necessary. Maybe all the tests should be on the type???
3455 elsif (not Is_Constrained (Typ))
3456 and then (Is_Array_Type (Utyp)
3457 or else (Is_Record_Type (Utyp)
3458 and then Has_Discriminants (Utyp)))
3459 and then not Has_Unknown_Discriminants (Utyp)
3460 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
3461 then
3462 -- Nothing to do if in default expression
3464 if In_Default_Expression then
3465 return Typ;
3467 elsif Is_Private_Type (Typ)
3468 and then not Has_Discriminants (Typ)
3469 then
3470 -- If the type has no discriminants, there is no subtype to
3471 -- build, even if the underlying type is discriminated.
3473 return Typ;
3475 -- Else build the actual subtype
3477 else
3478 Decl := Build_Actual_Subtype (Typ, N);
3479 Atyp := Defining_Identifier (Decl);
3481 -- If Build_Actual_Subtype generated a new declaration then use it
3483 if Atyp /= Typ then
3485 -- The actual subtype is an Itype, so analyze the declaration,
3486 -- but do not attach it to the tree, to get the type defined.
3488 Set_Parent (Decl, N);
3489 Set_Is_Itype (Atyp);
3490 Analyze (Decl, Suppress => All_Checks);
3491 Set_Associated_Node_For_Itype (Atyp, N);
3492 Set_Has_Delayed_Freeze (Atyp, False);
3494 -- We need to freeze the actual subtype immediately. This is
3495 -- needed, because otherwise this Itype will not get frozen
3496 -- at all, and it is always safe to freeze on creation because
3497 -- any associated types must be frozen at this point.
3499 Freeze_Itype (Atyp, N);
3500 return Atyp;
3502 -- Otherwise we did not build a declaration, so return original
3504 else
3505 return Typ;
3506 end if;
3507 end if;
3509 -- For all remaining cases, the actual subtype is the same as
3510 -- the nominal type.
3512 else
3513 return Typ;
3514 end if;
3515 end Get_Actual_Subtype;
3517 -------------------------------------
3518 -- Get_Actual_Subtype_If_Available --
3519 -------------------------------------
3521 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
3522 Typ : constant Entity_Id := Etype (N);
3524 begin
3525 -- If what we have is an identifier that references a subprogram
3526 -- formal, or a variable or constant object, then we get the actual
3527 -- subtype from the referenced entity if one has been built.
3529 if Nkind (N) = N_Identifier
3530 and then
3531 (Is_Formal (Entity (N))
3532 or else Ekind (Entity (N)) = E_Constant
3533 or else Ekind (Entity (N)) = E_Variable)
3534 and then Present (Actual_Subtype (Entity (N)))
3535 then
3536 return Actual_Subtype (Entity (N));
3538 -- Otherwise the Etype of N is returned unchanged
3540 else
3541 return Typ;
3542 end if;
3543 end Get_Actual_Subtype_If_Available;
3545 -------------------------------
3546 -- Get_Default_External_Name --
3547 -------------------------------
3549 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
3550 begin
3551 Get_Decoded_Name_String (Chars (E));
3553 if Opt.External_Name_Imp_Casing = Uppercase then
3554 Set_Casing (All_Upper_Case);
3555 else
3556 Set_Casing (All_Lower_Case);
3557 end if;
3559 return
3560 Make_String_Literal (Sloc (E),
3561 Strval => String_From_Name_Buffer);
3562 end Get_Default_External_Name;
3564 ---------------------------
3565 -- Get_Enum_Lit_From_Pos --
3566 ---------------------------
3568 function Get_Enum_Lit_From_Pos
3569 (T : Entity_Id;
3570 Pos : Uint;
3571 Loc : Source_Ptr) return Node_Id
3573 Lit : Node_Id;
3575 begin
3576 -- In the case where the literal is of type Character, Wide_Character
3577 -- or Wide_Wide_Character or of a type derived from them, there needs
3578 -- to be some special handling since there is no explicit chain of
3579 -- literals to search. Instead, an N_Character_Literal node is created
3580 -- with the appropriate Char_Code and Chars fields.
3582 if Root_Type (T) = Standard_Character
3583 or else Root_Type (T) = Standard_Wide_Character
3584 or else Root_Type (T) = Standard_Wide_Wide_Character
3585 then
3586 Set_Character_Literal_Name (UI_To_CC (Pos));
3587 return
3588 Make_Character_Literal (Loc,
3589 Chars => Name_Find,
3590 Char_Literal_Value => Pos);
3592 -- For all other cases, we have a complete table of literals, and
3593 -- we simply iterate through the chain of literal until the one
3594 -- with the desired position value is found.
3597 else
3598 Lit := First_Literal (Base_Type (T));
3599 for J in 1 .. UI_To_Int (Pos) loop
3600 Next_Literal (Lit);
3601 end loop;
3603 return New_Occurrence_Of (Lit, Loc);
3604 end if;
3605 end Get_Enum_Lit_From_Pos;
3607 ------------------------
3608 -- Get_Generic_Entity --
3609 ------------------------
3611 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
3612 Ent : constant Entity_Id := Entity (Name (N));
3613 begin
3614 if Present (Renamed_Object (Ent)) then
3615 return Renamed_Object (Ent);
3616 else
3617 return Ent;
3618 end if;
3619 end Get_Generic_Entity;
3621 ----------------------
3622 -- Get_Index_Bounds --
3623 ----------------------
3625 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
3626 Kind : constant Node_Kind := Nkind (N);
3627 R : Node_Id;
3629 begin
3630 if Kind = N_Range then
3631 L := Low_Bound (N);
3632 H := High_Bound (N);
3634 elsif Kind = N_Subtype_Indication then
3635 R := Range_Expression (Constraint (N));
3637 if R = Error then
3638 L := Error;
3639 H := Error;
3640 return;
3642 else
3643 L := Low_Bound (Range_Expression (Constraint (N)));
3644 H := High_Bound (Range_Expression (Constraint (N)));
3645 end if;
3647 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
3648 if Error_Posted (Scalar_Range (Entity (N))) then
3649 L := Error;
3650 H := Error;
3652 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
3653 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
3655 else
3656 L := Low_Bound (Scalar_Range (Entity (N)));
3657 H := High_Bound (Scalar_Range (Entity (N)));
3658 end if;
3660 else
3661 -- N is an expression, indicating a range with one value
3663 L := N;
3664 H := N;
3665 end if;
3666 end Get_Index_Bounds;
3668 ----------------------------------
3669 -- Get_Library_Unit_Name_string --
3670 ----------------------------------
3672 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
3673 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
3675 begin
3676 Get_Unit_Name_String (Unit_Name_Id);
3678 -- Remove seven last character (" (spec)" or " (body)")
3680 Name_Len := Name_Len - 7;
3681 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
3682 end Get_Library_Unit_Name_String;
3684 ------------------------
3685 -- Get_Name_Entity_Id --
3686 ------------------------
3688 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
3689 begin
3690 return Entity_Id (Get_Name_Table_Info (Id));
3691 end Get_Name_Entity_Id;
3693 ---------------------------
3694 -- Get_Referenced_Object --
3695 ---------------------------
3697 function Get_Referenced_Object (N : Node_Id) return Node_Id is
3698 R : Node_Id;
3700 begin
3701 R := N;
3702 while Is_Entity_Name (R)
3703 and then Present (Renamed_Object (Entity (R)))
3704 loop
3705 R := Renamed_Object (Entity (R));
3706 end loop;
3708 return R;
3709 end Get_Referenced_Object;
3711 ------------------------
3712 -- Get_Renamed_Entity --
3713 ------------------------
3715 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
3716 R : Entity_Id;
3718 begin
3719 R := E;
3720 while Present (Renamed_Entity (R)) loop
3721 R := Renamed_Entity (R);
3722 end loop;
3724 return R;
3725 end Get_Renamed_Entity;
3727 -------------------------
3728 -- Get_Subprogram_Body --
3729 -------------------------
3731 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
3732 Decl : Node_Id;
3734 begin
3735 Decl := Unit_Declaration_Node (E);
3737 if Nkind (Decl) = N_Subprogram_Body then
3738 return Decl;
3740 -- The below comment is bad, because it is possible for
3741 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
3743 else -- Nkind (Decl) = N_Subprogram_Declaration
3745 if Present (Corresponding_Body (Decl)) then
3746 return Unit_Declaration_Node (Corresponding_Body (Decl));
3748 -- Imported subprogram case
3750 else
3751 return Empty;
3752 end if;
3753 end if;
3754 end Get_Subprogram_Body;
3756 ---------------------------
3757 -- Get_Subprogram_Entity --
3758 ---------------------------
3760 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
3761 Nam : Node_Id;
3762 Proc : Entity_Id;
3764 begin
3765 if Nkind (Nod) = N_Accept_Statement then
3766 Nam := Entry_Direct_Name (Nod);
3768 -- For an entry call, the prefix of the call is a selected component.
3769 -- Need additional code for internal calls ???
3771 elsif Nkind (Nod) = N_Entry_Call_Statement then
3772 if Nkind (Name (Nod)) = N_Selected_Component then
3773 Nam := Entity (Selector_Name (Name (Nod)));
3774 else
3775 Nam := Empty;
3776 end if;
3778 else
3779 Nam := Name (Nod);
3780 end if;
3782 if Nkind (Nam) = N_Explicit_Dereference then
3783 Proc := Etype (Prefix (Nam));
3784 elsif Is_Entity_Name (Nam) then
3785 Proc := Entity (Nam);
3786 else
3787 return Empty;
3788 end if;
3790 if Is_Object (Proc) then
3791 Proc := Etype (Proc);
3792 end if;
3794 if Ekind (Proc) = E_Access_Subprogram_Type then
3795 Proc := Directly_Designated_Type (Proc);
3796 end if;
3798 if not Is_Subprogram (Proc)
3799 and then Ekind (Proc) /= E_Subprogram_Type
3800 then
3801 return Empty;
3802 else
3803 return Proc;
3804 end if;
3805 end Get_Subprogram_Entity;
3807 -----------------------------
3808 -- Get_Task_Body_Procedure --
3809 -----------------------------
3811 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
3812 begin
3813 -- Note: A task type may be the completion of a private type with
3814 -- discriminants. when performing elaboration checks on a task
3815 -- declaration, the current view of the type may be the private one,
3816 -- and the procedure that holds the body of the task is held in its
3817 -- underlying type.
3819 -- This is an odd function, why not have Task_Body_Procedure do
3820 -- the following digging???
3822 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
3823 end Get_Task_Body_Procedure;
3825 -----------------------------
3826 -- Has_Abstract_Interfaces --
3827 -----------------------------
3829 function Has_Abstract_Interfaces
3830 (Tagged_Type : Entity_Id;
3831 Use_Full_View : Boolean := True) return Boolean
3833 Typ : Entity_Id;
3835 begin
3836 pragma Assert (Is_Record_Type (Tagged_Type)
3837 and then Is_Tagged_Type (Tagged_Type));
3839 -- Handle concurrent record types
3841 if Is_Concurrent_Record_Type (Tagged_Type)
3842 and then Is_Non_Empty_List (Abstract_Interface_List (Tagged_Type))
3843 then
3844 return True;
3845 end if;
3847 Typ := Tagged_Type;
3849 -- Handle private types
3851 if Use_Full_View
3852 and then Present (Full_View (Tagged_Type))
3853 then
3854 Typ := Full_View (Tagged_Type);
3855 end if;
3857 loop
3858 if Is_Interface (Typ)
3859 or else
3860 (Is_Record_Type (Typ)
3861 and then Present (Abstract_Interfaces (Typ))
3862 and then not Is_Empty_Elmt_List (Abstract_Interfaces (Typ)))
3863 then
3864 return True;
3865 end if;
3867 exit when Etype (Typ) = Typ
3869 -- Handle private types
3871 or else (Present (Full_View (Etype (Typ)))
3872 and then Full_View (Etype (Typ)) = Typ)
3874 -- Protect the frontend against wrong source with cyclic
3875 -- derivations
3877 or else Etype (Typ) = Tagged_Type;
3879 -- Climb to the ancestor type handling private types
3881 if Present (Full_View (Etype (Typ))) then
3882 Typ := Full_View (Etype (Typ));
3883 else
3884 Typ := Etype (Typ);
3885 end if;
3886 end loop;
3888 return False;
3889 end Has_Abstract_Interfaces;
3891 -----------------------
3892 -- Has_Access_Values --
3893 -----------------------
3895 function Has_Access_Values (T : Entity_Id) return Boolean is
3896 Typ : constant Entity_Id := Underlying_Type (T);
3898 begin
3899 -- Case of a private type which is not completed yet. This can only
3900 -- happen in the case of a generic format type appearing directly, or
3901 -- as a component of the type to which this function is being applied
3902 -- at the top level. Return False in this case, since we certainly do
3903 -- not know that the type contains access types.
3905 if No (Typ) then
3906 return False;
3908 elsif Is_Access_Type (Typ) then
3909 return True;
3911 elsif Is_Array_Type (Typ) then
3912 return Has_Access_Values (Component_Type (Typ));
3914 elsif Is_Record_Type (Typ) then
3915 declare
3916 Comp : Entity_Id;
3918 begin
3919 Comp := First_Component_Or_Discriminant (Typ);
3920 while Present (Comp) loop
3921 if Has_Access_Values (Etype (Comp)) then
3922 return True;
3923 end if;
3925 Next_Component_Or_Discriminant (Comp);
3926 end loop;
3927 end;
3929 return False;
3931 else
3932 return False;
3933 end if;
3934 end Has_Access_Values;
3936 ------------------------------
3937 -- Has_Compatible_Alignment --
3938 ------------------------------
3940 function Has_Compatible_Alignment
3941 (Obj : Entity_Id;
3942 Expr : Node_Id) return Alignment_Result
3944 function Has_Compatible_Alignment_Internal
3945 (Obj : Entity_Id;
3946 Expr : Node_Id;
3947 Default : Alignment_Result) return Alignment_Result;
3948 -- This is the internal recursive function that actually does the work.
3949 -- There is one additional parameter, which says what the result should
3950 -- be if no alignment information is found, and there is no definite
3951 -- indication of compatible alignments. At the outer level, this is set
3952 -- to Unknown, but for internal recursive calls in the case where types
3953 -- are known to be correct, it is set to Known_Compatible.
3955 ---------------------------------------
3956 -- Has_Compatible_Alignment_Internal --
3957 ---------------------------------------
3959 function Has_Compatible_Alignment_Internal
3960 (Obj : Entity_Id;
3961 Expr : Node_Id;
3962 Default : Alignment_Result) return Alignment_Result
3964 Result : Alignment_Result := Known_Compatible;
3965 -- Set to result if Problem_Prefix or Problem_Offset returns True.
3966 -- Note that once a value of Known_Incompatible is set, it is sticky
3967 -- and does not get changed to Unknown (the value in Result only gets
3968 -- worse as we go along, never better).
3970 procedure Check_Offset (Offs : Uint);
3971 -- Called when Expr is a selected or indexed component with Offs set
3972 -- to resp Component_First_Bit or Component_Size. Checks that if the
3973 -- offset is specified it is compatible with the object alignment
3974 -- requirements. The value in Result is modified accordingly.
3976 procedure Check_Prefix;
3977 -- Checks the prefix recursively in the case where the expression
3978 -- is an indexed or selected component.
3980 procedure Set_Result (R : Alignment_Result);
3981 -- If R represents a worse outcome (unknown instead of known
3982 -- compatible, or known incompatible), then set Result to R.
3984 ------------------
3985 -- Check_Offset --
3986 ------------------
3988 procedure Check_Offset (Offs : Uint) is
3989 begin
3990 -- Unspecified or zero offset is always OK
3992 if Offs = No_Uint or else Offs = Uint_0 then
3993 null;
3995 -- If we do not know required alignment, any non-zero offset is
3996 -- a potential problem (but certainly may be OK, so result is
3997 -- unknown).
3999 elsif Unknown_Alignment (Obj) then
4000 Set_Result (Unknown);
4002 -- If we know the required alignment, see if offset is compatible
4004 else
4005 if Offs mod (System_Storage_Unit * Alignment (Obj)) /= 0 then
4006 Set_Result (Known_Incompatible);
4007 end if;
4008 end if;
4009 end Check_Offset;
4011 ------------------
4012 -- Check_Prefix --
4013 ------------------
4015 procedure Check_Prefix is
4016 begin
4017 -- The subtlety here is that in doing a recursive call to check
4018 -- the prefix, we have to decide what to do in the case where we
4019 -- don't find any specific indication of an alignment problem.
4021 -- At the outer level, we normally set Unknown as the result in
4022 -- this case, since we can only set Known_Compatible if we really
4023 -- know that the alignment value is OK, but for the recursive
4024 -- call, in the case where the types match, and we have not
4025 -- specified a peculiar alignment for the object, we are only
4026 -- concerned about suspicious rep clauses, the default case does
4027 -- not affect us, since the compiler will, in the absence of such
4028 -- rep clauses, ensure that the alignment is correct.
4030 if Default = Known_Compatible
4031 or else
4032 (Etype (Obj) = Etype (Expr)
4033 and then (Unknown_Alignment (Obj)
4034 or else
4035 Alignment (Obj) = Alignment (Etype (Obj))))
4036 then
4037 Set_Result
4038 (Has_Compatible_Alignment_Internal
4039 (Obj, Prefix (Expr), Known_Compatible));
4041 -- In all other cases, we need a full check on the prefix
4043 else
4044 Set_Result
4045 (Has_Compatible_Alignment_Internal
4046 (Obj, Prefix (Expr), Unknown));
4047 end if;
4048 end Check_Prefix;
4050 ----------------
4051 -- Set_Result --
4052 ----------------
4054 procedure Set_Result (R : Alignment_Result) is
4055 begin
4056 if R > Result then
4057 Result := R;
4058 end if;
4059 end Set_Result;
4061 -- Start of processing for Has_Compatible_Alignment_Internal
4063 begin
4064 -- If Expr is a selected component, we must make sure there is no
4065 -- potentially troublesome component clause, and that the record is
4066 -- not packed.
4068 if Nkind (Expr) = N_Selected_Component then
4070 -- Packed record always generate unknown alignment
4072 if Is_Packed (Etype (Prefix (Expr))) then
4073 Set_Result (Unknown);
4074 end if;
4076 -- Check possible bad component offset and check prefix
4078 Check_Offset
4079 (Component_Bit_Offset (Entity (Selector_Name (Expr))));
4080 Check_Prefix;
4082 -- If Expr is an indexed component, we must make sure there is no
4083 -- potentially troublesome Component_Size clause and that the array
4084 -- is not bit-packed.
4086 elsif Nkind (Expr) = N_Indexed_Component then
4088 -- Bit packed array always generates unknown alignment
4090 if Is_Bit_Packed_Array (Etype (Prefix (Expr))) then
4091 Set_Result (Unknown);
4092 end if;
4094 -- Check possible bad component size and check prefix
4096 Check_Offset (Component_Size (Etype (Prefix (Expr))));
4097 Check_Prefix;
4098 end if;
4100 -- Case where we know the alignment of the object
4102 if Known_Alignment (Obj) then
4103 declare
4104 ObjA : constant Uint := Alignment (Obj);
4105 ExpA : Uint := No_Uint;
4106 SizA : Uint := No_Uint;
4108 begin
4109 -- If alignment of Obj is 1, then we are always OK
4111 if ObjA = 1 then
4112 Set_Result (Known_Compatible);
4114 -- Alignment of Obj is greater than 1, so we need to check
4116 else
4117 -- See if Expr is an object with known alignment
4119 if Is_Entity_Name (Expr)
4120 and then Known_Alignment (Entity (Expr))
4121 then
4122 ExpA := Alignment (Entity (Expr));
4124 -- Otherwise, we can use the alignment of the type of
4125 -- Expr given that we already checked for
4126 -- discombobulating rep clauses for the cases of indexed
4127 -- and selected components above.
4129 elsif Known_Alignment (Etype (Expr)) then
4130 ExpA := Alignment (Etype (Expr));
4131 end if;
4133 -- If we got an alignment, see if it is acceptable
4135 if ExpA /= No_Uint then
4136 if ExpA < ObjA then
4137 Set_Result (Known_Incompatible);
4138 end if;
4140 -- Case of Expr alignment unknown
4142 else
4143 Set_Result (Default);
4144 end if;
4146 -- See if size is given. If so, check that it is not too
4147 -- small for the required alignment.
4148 -- See if Expr is an object with known alignment
4150 if Is_Entity_Name (Expr)
4151 and then Known_Static_Esize (Entity (Expr))
4152 then
4153 SizA := Esize (Entity (Expr));
4155 -- Otherwise, we check the object size of the Expr type
4157 elsif Known_Static_Esize (Etype (Expr)) then
4158 SizA := Esize (Etype (Expr));
4159 end if;
4161 -- If we got a size, see if it is a multiple of the Obj
4162 -- alignment, if not, then the alignment cannot be
4163 -- acceptable, since the size is always a multiple of the
4164 -- alignment.
4166 if SizA /= No_Uint then
4167 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
4168 Set_Result (Known_Incompatible);
4169 end if;
4170 end if;
4171 end if;
4172 end;
4174 -- If we can't find the result by direct comparison of alignment
4175 -- values, then there is still one case that we can determine known
4176 -- result, and that is when we can determine that the types are the
4177 -- same, and no alignments are specified. Then we known that the
4178 -- alignments are compatible, even if we don't know the alignment
4179 -- value in the front end.
4181 elsif Etype (Obj) = Etype (Expr) then
4183 -- Types are the same, but we have to check for possible size
4184 -- and alignments on the Expr object that may make the alignment
4185 -- different, even though the types are the same.
4187 if Is_Entity_Name (Expr) then
4189 -- First check alignment of the Expr object. Any alignment less
4190 -- than Maximum_Alignment is worrisome since this is the case
4191 -- where we do not know the alignment of Obj.
4193 if Known_Alignment (Entity (Expr))
4194 and then
4195 UI_To_Int (Alignment (Entity (Expr)))
4196 < Ttypes.Maximum_Alignment
4197 then
4198 Set_Result (Unknown);
4200 -- Now check size of Expr object. Any size that is not an
4201 -- even multiple of Maxiumum_Alignment is also worrisome
4202 -- since it may cause the alignment of the object to be less
4203 -- than the alignment of the type.
4205 elsif Known_Static_Esize (Entity (Expr))
4206 and then
4207 (UI_To_Int (Esize (Entity (Expr))) mod
4208 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
4209 /= 0
4210 then
4211 Set_Result (Unknown);
4213 -- Otherwise same type is decisive
4215 else
4216 Set_Result (Known_Compatible);
4217 end if;
4218 end if;
4220 -- Another case to deal with is when there is an explicit size or
4221 -- alignment clause when the types are not the same. If so, then the
4222 -- result is Unknown. We don't need to do this test if the Default is
4223 -- Unknown, since that result will be set in any case.
4225 elsif Default /= Unknown
4226 and then (Has_Size_Clause (Etype (Expr))
4227 or else
4228 Has_Alignment_Clause (Etype (Expr)))
4229 then
4230 Set_Result (Unknown);
4232 -- If no indication found, set default
4234 else
4235 Set_Result (Default);
4236 end if;
4238 -- Return worst result found
4240 return Result;
4241 end Has_Compatible_Alignment_Internal;
4243 -- Start of processing for Has_Compatible_Alignment
4245 begin
4246 -- If Obj has no specified alignment, then set alignment from the type
4247 -- alignment. Perhaps we should always do this, but for sure we should
4248 -- do it when there is an address clause since we can do more if the
4249 -- alignment is known.
4251 if Unknown_Alignment (Obj) then
4252 Set_Alignment (Obj, Alignment (Etype (Obj)));
4253 end if;
4255 -- Now do the internal call that does all the work
4257 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
4258 end Has_Compatible_Alignment;
4260 ----------------------
4261 -- Has_Declarations --
4262 ----------------------
4264 function Has_Declarations (N : Node_Id) return Boolean is
4265 K : constant Node_Kind := Nkind (N);
4266 begin
4267 return K = N_Accept_Statement
4268 or else K = N_Block_Statement
4269 or else K = N_Compilation_Unit_Aux
4270 or else K = N_Entry_Body
4271 or else K = N_Package_Body
4272 or else K = N_Protected_Body
4273 or else K = N_Subprogram_Body
4274 or else K = N_Task_Body
4275 or else K = N_Package_Specification;
4276 end Has_Declarations;
4278 -------------------------------------------
4279 -- Has_Discriminant_Dependent_Constraint --
4280 -------------------------------------------
4282 function Has_Discriminant_Dependent_Constraint
4283 (Comp : Entity_Id) return Boolean
4285 Comp_Decl : constant Node_Id := Parent (Comp);
4286 Subt_Indic : constant Node_Id :=
4287 Subtype_Indication (Component_Definition (Comp_Decl));
4288 Constr : Node_Id;
4289 Assn : Node_Id;
4291 begin
4292 if Nkind (Subt_Indic) = N_Subtype_Indication then
4293 Constr := Constraint (Subt_Indic);
4295 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
4296 Assn := First (Constraints (Constr));
4297 while Present (Assn) loop
4298 case Nkind (Assn) is
4299 when N_Subtype_Indication |
4300 N_Range |
4301 N_Identifier
4303 if Depends_On_Discriminant (Assn) then
4304 return True;
4305 end if;
4307 when N_Discriminant_Association =>
4308 if Depends_On_Discriminant (Expression (Assn)) then
4309 return True;
4310 end if;
4312 when others =>
4313 null;
4315 end case;
4317 Next (Assn);
4318 end loop;
4319 end if;
4320 end if;
4322 return False;
4323 end Has_Discriminant_Dependent_Constraint;
4325 --------------------
4326 -- Has_Infinities --
4327 --------------------
4329 function Has_Infinities (E : Entity_Id) return Boolean is
4330 begin
4331 return
4332 Is_Floating_Point_Type (E)
4333 and then Nkind (Scalar_Range (E)) = N_Range
4334 and then Includes_Infinities (Scalar_Range (E));
4335 end Has_Infinities;
4337 ------------------------
4338 -- Has_Null_Exclusion --
4339 ------------------------
4341 function Has_Null_Exclusion (N : Node_Id) return Boolean is
4342 begin
4343 case Nkind (N) is
4344 when N_Access_Definition |
4345 N_Access_Function_Definition |
4346 N_Access_Procedure_Definition |
4347 N_Access_To_Object_Definition |
4348 N_Allocator |
4349 N_Derived_Type_Definition |
4350 N_Function_Specification |
4351 N_Subtype_Declaration =>
4352 return Null_Exclusion_Present (N);
4354 when N_Component_Definition |
4355 N_Formal_Object_Declaration |
4356 N_Object_Renaming_Declaration =>
4357 if Present (Subtype_Mark (N)) then
4358 return Null_Exclusion_Present (N);
4359 else pragma Assert (Present (Access_Definition (N)));
4360 return Null_Exclusion_Present (Access_Definition (N));
4361 end if;
4363 when N_Discriminant_Specification =>
4364 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
4365 return Null_Exclusion_Present (Discriminant_Type (N));
4366 else
4367 return Null_Exclusion_Present (N);
4368 end if;
4370 when N_Object_Declaration =>
4371 if Nkind (Object_Definition (N)) = N_Access_Definition then
4372 return Null_Exclusion_Present (Object_Definition (N));
4373 else
4374 return Null_Exclusion_Present (N);
4375 end if;
4377 when N_Parameter_Specification =>
4378 if Nkind (Parameter_Type (N)) = N_Access_Definition then
4379 return Null_Exclusion_Present (Parameter_Type (N));
4380 else
4381 return Null_Exclusion_Present (N);
4382 end if;
4384 when others =>
4385 return False;
4387 end case;
4388 end Has_Null_Exclusion;
4390 ------------------------
4391 -- Has_Null_Extension --
4392 ------------------------
4394 function Has_Null_Extension (T : Entity_Id) return Boolean is
4395 B : constant Entity_Id := Base_Type (T);
4396 Comps : Node_Id;
4397 Ext : Node_Id;
4399 begin
4400 if Nkind (Parent (B)) = N_Full_Type_Declaration
4401 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
4402 then
4403 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
4405 if Present (Ext) then
4406 if Null_Present (Ext) then
4407 return True;
4408 else
4409 Comps := Component_List (Ext);
4411 -- The null component list is rewritten during analysis to
4412 -- include the parent component. Any other component indicates
4413 -- that the extension was not originally null.
4415 return Null_Present (Comps)
4416 or else No (Next (First (Component_Items (Comps))));
4417 end if;
4418 else
4419 return False;
4420 end if;
4422 else
4423 return False;
4424 end if;
4425 end Has_Null_Extension;
4427 --------------------------------------
4428 -- Has_Preelaborable_Initialization --
4429 --------------------------------------
4431 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
4432 Has_PE : Boolean;
4434 procedure Check_Components (E : Entity_Id);
4435 -- Check component/discriminant chain, sets Has_PE False if a component
4436 -- or discriminant does not meet the preelaborable initialization rules.
4438 ----------------------
4439 -- Check_Components --
4440 ----------------------
4442 procedure Check_Components (E : Entity_Id) is
4443 Ent : Entity_Id;
4444 Exp : Node_Id;
4446 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
4447 -- Returns True if and only if the expression denoted by N does not
4448 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
4450 ---------------------------------
4451 -- Is_Preelaborable_Expression --
4452 ---------------------------------
4454 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
4455 Exp : Node_Id;
4456 Assn : Node_Id;
4457 Choice : Node_Id;
4458 Comp_Type : Entity_Id;
4459 Is_Array_Aggr : Boolean;
4461 begin
4462 if Is_Static_Expression (N) then
4463 return True;
4465 elsif Nkind (N) = N_Null then
4466 return True;
4468 elsif Nkind (N) = N_Attribute_Reference
4469 and then
4470 (Attribute_Name (N) = Name_Access
4471 or else
4472 Attribute_Name (N) = Name_Unchecked_Access
4473 or else
4474 Attribute_Name (N) = Name_Unrestricted_Access)
4475 then
4476 return True;
4478 elsif Nkind (N) = N_Qualified_Expression then
4479 return Is_Preelaborable_Expression (Expression (N));
4481 -- For aggregates we have to check that each of the associations
4482 -- is preelaborable.
4484 elsif Nkind (N) = N_Aggregate
4485 or else Nkind (N) = N_Extension_Aggregate
4486 then
4487 Is_Array_Aggr := Is_Array_Type (Etype (N));
4489 if Is_Array_Aggr then
4490 Comp_Type := Component_Type (Etype (N));
4491 end if;
4493 -- Check the ancestor part of extension aggregates, which must
4494 -- be either the name of a type that has preelaborable init or
4495 -- an expression that is preelaborable.
4497 if Nkind (N) = N_Extension_Aggregate then
4498 declare
4499 Anc_Part : constant Node_Id := Ancestor_Part (N);
4501 begin
4502 if Is_Entity_Name (Anc_Part)
4503 and then Is_Type (Entity (Anc_Part))
4504 then
4505 if not Has_Preelaborable_Initialization
4506 (Entity (Anc_Part))
4507 then
4508 return False;
4509 end if;
4511 elsif not Is_Preelaborable_Expression (Anc_Part) then
4512 return False;
4513 end if;
4514 end;
4515 end if;
4517 -- Check positional associations
4519 Exp := First (Expressions (N));
4520 while Present (Exp) loop
4521 if not Is_Preelaborable_Expression (Exp) then
4522 return False;
4523 end if;
4525 Next (Exp);
4526 end loop;
4528 -- Check named associations
4530 Assn := First (Component_Associations (N));
4531 while Present (Assn) loop
4532 Choice := First (Choices (Assn));
4533 while Present (Choice) loop
4534 if Is_Array_Aggr then
4535 if Nkind (Choice) = N_Others_Choice then
4536 null;
4538 elsif Nkind (Choice) = N_Range then
4539 if not Is_Static_Range (Choice) then
4540 return False;
4541 end if;
4543 elsif not Is_Static_Expression (Choice) then
4544 return False;
4545 end if;
4547 else
4548 Comp_Type := Etype (Choice);
4549 end if;
4551 Next (Choice);
4552 end loop;
4554 -- If the association has a <> at this point, then we have
4555 -- to check whether the component's type has preelaborable
4556 -- initialization. Note that this only occurs when the
4557 -- association's corresponding component does not have a
4558 -- default expression, the latter case having already been
4559 -- expanded as an expression for the association.
4561 if Box_Present (Assn) then
4562 if not Has_Preelaborable_Initialization (Comp_Type) then
4563 return False;
4564 end if;
4566 -- In the expression case we check whether the expression
4567 -- is preelaborable.
4569 elsif
4570 not Is_Preelaborable_Expression (Expression (Assn))
4571 then
4572 return False;
4573 end if;
4575 Next (Assn);
4576 end loop;
4578 -- If we get here then aggregate as a whole is preelaborable
4580 return True;
4582 -- All other cases are not preelaborable
4584 else
4585 return False;
4586 end if;
4587 end Is_Preelaborable_Expression;
4589 -- Start of processing for Check_Components
4591 begin
4592 -- Loop through entities of record or protected type
4594 Ent := E;
4595 while Present (Ent) loop
4597 -- We are interested only in components and discriminants
4599 if Ekind (Ent) = E_Component
4600 or else
4601 Ekind (Ent) = E_Discriminant
4602 then
4603 -- Get default expression if any. If there is no declaration
4604 -- node, it means we have an internal entity. The parent and
4605 -- tag fields are examples of such entitires. For these cases,
4606 -- we just test the type of the entity.
4608 if Present (Declaration_Node (Ent)) then
4609 Exp := Expression (Declaration_Node (Ent));
4610 else
4611 Exp := Empty;
4612 end if;
4614 -- A component has PI if it has no default expression and the
4615 -- component type has PI.
4617 if No (Exp) then
4618 if not Has_Preelaborable_Initialization (Etype (Ent)) then
4619 Has_PE := False;
4620 exit;
4621 end if;
4623 -- Require the default expression to be preelaborable
4625 elsif not Is_Preelaborable_Expression (Exp) then
4626 Has_PE := False;
4627 exit;
4628 end if;
4629 end if;
4631 Next_Entity (Ent);
4632 end loop;
4633 end Check_Components;
4635 -- Start of processing for Has_Preelaborable_Initialization
4637 begin
4638 -- Immediate return if already marked as known preelaborable init. This
4639 -- covers types for which this function has already been called once
4640 -- and returned True (in which case the result is cached), and also
4641 -- types to which a pragma Preelaborable_Initialization applies.
4643 if Known_To_Have_Preelab_Init (E) then
4644 return True;
4645 end if;
4647 -- If the type is a subtype representing a generic actual type, then
4648 -- test whether its base type has preelaborable initialization since
4649 -- the subtype representing the actual does not inherit this attribute
4650 -- from the actual or formal. (but maybe it should???)
4652 if Is_Generic_Actual_Type (E) then
4653 return Has_Preelaborable_Initialization (Base_Type (E));
4654 end if;
4656 -- Other private types never have preelaborable initialization
4658 if Is_Private_Type (E) then
4659 return False;
4660 end if;
4662 -- Here for all non-private view
4664 -- All elementary types have preelaborable initialization
4666 if Is_Elementary_Type (E) then
4667 Has_PE := True;
4669 -- Array types have PI if the component type has PI
4671 elsif Is_Array_Type (E) then
4672 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
4674 -- A derived type has preelaborable initialization if its parent type
4675 -- has preelaborable initialization and (in the case of a derived record
4676 -- extension) if the non-inherited components all have preelaborable
4677 -- initialization. However, a user-defined controlled type with an
4678 -- overriding Initialize procedure does not have preelaborable
4679 -- initialization.
4681 elsif Is_Derived_Type (E) then
4683 -- First check whether ancestor type has preelaborable initialization
4685 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
4687 -- If OK, check extension components (if any)
4689 if Has_PE and then Is_Record_Type (E) then
4690 Check_Components (First_Entity (E));
4691 end if;
4693 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
4694 -- with a user defined Initialize procedure does not have PI.
4696 if Has_PE
4697 and then Is_Controlled (E)
4698 and then Present (Primitive_Operations (E))
4699 then
4700 declare
4701 P : Elmt_Id;
4703 begin
4704 P := First_Elmt (Primitive_Operations (E));
4705 while Present (P) loop
4706 if Chars (Node (P)) = Name_Initialize
4707 and then Comes_From_Source (Node (P))
4708 then
4709 Has_PE := False;
4710 exit;
4711 end if;
4713 Next_Elmt (P);
4714 end loop;
4715 end;
4716 end if;
4718 -- Record type has PI if it is non private and all components have PI
4720 elsif Is_Record_Type (E) then
4721 Has_PE := True;
4722 Check_Components (First_Entity (E));
4724 -- Protected types must not have entries, and components must meet
4725 -- same set of rules as for record components.
4727 elsif Is_Protected_Type (E) then
4728 if Has_Entries (E) then
4729 Has_PE := False;
4730 else
4731 Has_PE := True;
4732 Check_Components (First_Entity (E));
4733 Check_Components (First_Private_Entity (E));
4734 end if;
4736 -- Type System.Address always has preelaborable initialization
4738 elsif Is_RTE (E, RE_Address) then
4739 Has_PE := True;
4741 -- In all other cases, type does not have preelaborable initialization
4743 else
4744 return False;
4745 end if;
4747 -- If type has preelaborable initialization, cache result
4749 if Has_PE then
4750 Set_Known_To_Have_Preelab_Init (E);
4751 end if;
4753 return Has_PE;
4754 end Has_Preelaborable_Initialization;
4756 ---------------------------
4757 -- Has_Private_Component --
4758 ---------------------------
4760 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
4761 Btype : Entity_Id := Base_Type (Type_Id);
4762 Component : Entity_Id;
4764 begin
4765 if Error_Posted (Type_Id)
4766 or else Error_Posted (Btype)
4767 then
4768 return False;
4769 end if;
4771 if Is_Class_Wide_Type (Btype) then
4772 Btype := Root_Type (Btype);
4773 end if;
4775 if Is_Private_Type (Btype) then
4776 declare
4777 UT : constant Entity_Id := Underlying_Type (Btype);
4778 begin
4779 if No (UT) then
4780 if No (Full_View (Btype)) then
4781 return not Is_Generic_Type (Btype)
4782 and then not Is_Generic_Type (Root_Type (Btype));
4783 else
4784 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
4785 end if;
4786 else
4787 return not Is_Frozen (UT) and then Has_Private_Component (UT);
4788 end if;
4789 end;
4791 elsif Is_Array_Type (Btype) then
4792 return Has_Private_Component (Component_Type (Btype));
4794 elsif Is_Record_Type (Btype) then
4795 Component := First_Component (Btype);
4796 while Present (Component) loop
4797 if Has_Private_Component (Etype (Component)) then
4798 return True;
4799 end if;
4801 Next_Component (Component);
4802 end loop;
4804 return False;
4806 elsif Is_Protected_Type (Btype)
4807 and then Present (Corresponding_Record_Type (Btype))
4808 then
4809 return Has_Private_Component (Corresponding_Record_Type (Btype));
4811 else
4812 return False;
4813 end if;
4814 end Has_Private_Component;
4816 ----------------
4817 -- Has_Stream --
4818 ----------------
4820 function Has_Stream (T : Entity_Id) return Boolean is
4821 E : Entity_Id;
4823 begin
4824 if No (T) then
4825 return False;
4827 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
4828 return True;
4830 elsif Is_Array_Type (T) then
4831 return Has_Stream (Component_Type (T));
4833 elsif Is_Record_Type (T) then
4834 E := First_Component (T);
4835 while Present (E) loop
4836 if Has_Stream (Etype (E)) then
4837 return True;
4838 else
4839 Next_Component (E);
4840 end if;
4841 end loop;
4843 return False;
4845 elsif Is_Private_Type (T) then
4846 return Has_Stream (Underlying_Type (T));
4848 else
4849 return False;
4850 end if;
4851 end Has_Stream;
4853 --------------------------
4854 -- Has_Tagged_Component --
4855 --------------------------
4857 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
4858 Comp : Entity_Id;
4860 begin
4861 if Is_Private_Type (Typ)
4862 and then Present (Underlying_Type (Typ))
4863 then
4864 return Has_Tagged_Component (Underlying_Type (Typ));
4866 elsif Is_Array_Type (Typ) then
4867 return Has_Tagged_Component (Component_Type (Typ));
4869 elsif Is_Tagged_Type (Typ) then
4870 return True;
4872 elsif Is_Record_Type (Typ) then
4873 Comp := First_Component (Typ);
4874 while Present (Comp) loop
4875 if Has_Tagged_Component (Etype (Comp)) then
4876 return True;
4877 end if;
4879 Comp := Next_Component (Typ);
4880 end loop;
4882 return False;
4884 else
4885 return False;
4886 end if;
4887 end Has_Tagged_Component;
4889 -----------------
4890 -- In_Instance --
4891 -----------------
4893 function In_Instance return Boolean is
4894 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
4895 S : Entity_Id;
4897 begin
4898 S := Current_Scope;
4899 while Present (S)
4900 and then S /= Standard_Standard
4901 loop
4902 if (Ekind (S) = E_Function
4903 or else Ekind (S) = E_Package
4904 or else Ekind (S) = E_Procedure)
4905 and then Is_Generic_Instance (S)
4906 then
4907 -- A child instance is always compiled in the context of a parent
4908 -- instance. Nevertheless, the actuals are not analyzed in an
4909 -- instance context. We detect this case by examining the current
4910 -- compilation unit, which must be a child instance, and checking
4911 -- that it is not currently on the scope stack.
4913 if Is_Child_Unit (Curr_Unit)
4914 and then
4915 Nkind (Unit (Cunit (Current_Sem_Unit)))
4916 = N_Package_Instantiation
4917 and then not In_Open_Scopes (Curr_Unit)
4918 then
4919 return False;
4920 else
4921 return True;
4922 end if;
4923 end if;
4925 S := Scope (S);
4926 end loop;
4928 return False;
4929 end In_Instance;
4931 ----------------------
4932 -- In_Instance_Body --
4933 ----------------------
4935 function In_Instance_Body return Boolean is
4936 S : Entity_Id;
4938 begin
4939 S := Current_Scope;
4940 while Present (S)
4941 and then S /= Standard_Standard
4942 loop
4943 if (Ekind (S) = E_Function
4944 or else Ekind (S) = E_Procedure)
4945 and then Is_Generic_Instance (S)
4946 then
4947 return True;
4949 elsif Ekind (S) = E_Package
4950 and then In_Package_Body (S)
4951 and then Is_Generic_Instance (S)
4952 then
4953 return True;
4954 end if;
4956 S := Scope (S);
4957 end loop;
4959 return False;
4960 end In_Instance_Body;
4962 -----------------------------
4963 -- In_Instance_Not_Visible --
4964 -----------------------------
4966 function In_Instance_Not_Visible return Boolean is
4967 S : Entity_Id;
4969 begin
4970 S := Current_Scope;
4971 while Present (S)
4972 and then S /= Standard_Standard
4973 loop
4974 if (Ekind (S) = E_Function
4975 or else Ekind (S) = E_Procedure)
4976 and then Is_Generic_Instance (S)
4977 then
4978 return True;
4980 elsif Ekind (S) = E_Package
4981 and then (In_Package_Body (S) or else In_Private_Part (S))
4982 and then Is_Generic_Instance (S)
4983 then
4984 return True;
4985 end if;
4987 S := Scope (S);
4988 end loop;
4990 return False;
4991 end In_Instance_Not_Visible;
4993 ------------------------------
4994 -- In_Instance_Visible_Part --
4995 ------------------------------
4997 function In_Instance_Visible_Part return Boolean is
4998 S : Entity_Id;
5000 begin
5001 S := Current_Scope;
5002 while Present (S)
5003 and then S /= Standard_Standard
5004 loop
5005 if Ekind (S) = E_Package
5006 and then Is_Generic_Instance (S)
5007 and then not In_Package_Body (S)
5008 and then not In_Private_Part (S)
5009 then
5010 return True;
5011 end if;
5013 S := Scope (S);
5014 end loop;
5016 return False;
5017 end In_Instance_Visible_Part;
5019 ----------------------
5020 -- In_Packiage_Body --
5021 ----------------------
5023 function In_Package_Body return Boolean is
5024 S : Entity_Id;
5026 begin
5027 S := Current_Scope;
5028 while Present (S)
5029 and then S /= Standard_Standard
5030 loop
5031 if Ekind (S) = E_Package
5032 and then In_Package_Body (S)
5033 then
5034 return True;
5035 else
5036 S := Scope (S);
5037 end if;
5038 end loop;
5040 return False;
5041 end In_Package_Body;
5043 --------------------------------------
5044 -- In_Subprogram_Or_Concurrent_Unit --
5045 --------------------------------------
5047 function In_Subprogram_Or_Concurrent_Unit return Boolean is
5048 E : Entity_Id;
5049 K : Entity_Kind;
5051 begin
5052 -- Use scope chain to check successively outer scopes
5054 E := Current_Scope;
5055 loop
5056 K := Ekind (E);
5058 if K in Subprogram_Kind
5059 or else K in Concurrent_Kind
5060 or else K in Generic_Subprogram_Kind
5061 then
5062 return True;
5064 elsif E = Standard_Standard then
5065 return False;
5066 end if;
5068 E := Scope (E);
5069 end loop;
5070 end In_Subprogram_Or_Concurrent_Unit;
5072 ---------------------
5073 -- In_Visible_Part --
5074 ---------------------
5076 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
5077 begin
5078 return
5079 Is_Package_Or_Generic_Package (Scope_Id)
5080 and then In_Open_Scopes (Scope_Id)
5081 and then not In_Package_Body (Scope_Id)
5082 and then not In_Private_Part (Scope_Id);
5083 end In_Visible_Part;
5085 ---------------------------------
5086 -- Insert_Explicit_Dereference --
5087 ---------------------------------
5089 procedure Insert_Explicit_Dereference (N : Node_Id) is
5090 New_Prefix : constant Node_Id := Relocate_Node (N);
5091 Ent : Entity_Id := Empty;
5092 Pref : Node_Id;
5093 I : Interp_Index;
5094 It : Interp;
5095 T : Entity_Id;
5097 begin
5098 Save_Interps (N, New_Prefix);
5099 Rewrite (N,
5100 Make_Explicit_Dereference (Sloc (N),
5101 Prefix => New_Prefix));
5103 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
5105 if Is_Overloaded (New_Prefix) then
5107 -- The deference is also overloaded, and its interpretations are the
5108 -- designated types of the interpretations of the original node.
5110 Set_Etype (N, Any_Type);
5112 Get_First_Interp (New_Prefix, I, It);
5113 while Present (It.Nam) loop
5114 T := It.Typ;
5116 if Is_Access_Type (T) then
5117 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
5118 end if;
5120 Get_Next_Interp (I, It);
5121 end loop;
5123 End_Interp_List;
5125 else
5126 -- Prefix is unambiguous: mark the original prefix (which might
5127 -- Come_From_Source) as a reference, since the new (relocated) one
5128 -- won't be taken into account.
5130 if Is_Entity_Name (New_Prefix) then
5131 Ent := Entity (New_Prefix);
5133 -- For a retrieval of a subcomponent of some composite object,
5134 -- retrieve the ultimate entity if there is one.
5136 elsif Nkind (New_Prefix) = N_Selected_Component
5137 or else Nkind (New_Prefix) = N_Indexed_Component
5138 then
5139 Pref := Prefix (New_Prefix);
5140 while Present (Pref)
5141 and then
5142 (Nkind (Pref) = N_Selected_Component
5143 or else Nkind (Pref) = N_Indexed_Component)
5144 loop
5145 Pref := Prefix (Pref);
5146 end loop;
5148 if Present (Pref) and then Is_Entity_Name (Pref) then
5149 Ent := Entity (Pref);
5150 end if;
5151 end if;
5153 if Present (Ent) then
5154 Generate_Reference (Ent, New_Prefix);
5155 end if;
5156 end if;
5157 end Insert_Explicit_Dereference;
5159 -------------------
5160 -- Is_AAMP_Float --
5161 -------------------
5163 function Is_AAMP_Float (E : Entity_Id) return Boolean is
5164 pragma Assert (Is_Type (E));
5165 begin
5166 return AAMP_On_Target
5167 and then Is_Floating_Point_Type (E)
5168 and then E = Base_Type (E);
5169 end Is_AAMP_Float;
5171 -------------------------
5172 -- Is_Actual_Parameter --
5173 -------------------------
5175 function Is_Actual_Parameter (N : Node_Id) return Boolean is
5176 PK : constant Node_Kind := Nkind (Parent (N));
5178 begin
5179 case PK is
5180 when N_Parameter_Association =>
5181 return N = Explicit_Actual_Parameter (Parent (N));
5183 when N_Function_Call | N_Procedure_Call_Statement =>
5184 return Is_List_Member (N)
5185 and then
5186 List_Containing (N) = Parameter_Associations (Parent (N));
5188 when others =>
5189 return False;
5190 end case;
5191 end Is_Actual_Parameter;
5193 ---------------------
5194 -- Is_Aliased_View --
5195 ---------------------
5197 function Is_Aliased_View (Obj : Node_Id) return Boolean is
5198 E : Entity_Id;
5200 begin
5201 if Is_Entity_Name (Obj) then
5203 E := Entity (Obj);
5205 return
5206 (Is_Object (E)
5207 and then
5208 (Is_Aliased (E)
5209 or else (Present (Renamed_Object (E))
5210 and then Is_Aliased_View (Renamed_Object (E)))))
5212 or else ((Is_Formal (E)
5213 or else Ekind (E) = E_Generic_In_Out_Parameter
5214 or else Ekind (E) = E_Generic_In_Parameter)
5215 and then Is_Tagged_Type (Etype (E)))
5217 or else (Is_Concurrent_Type (E)
5218 and then In_Open_Scopes (E))
5220 -- Current instance of type, either directly or as rewritten
5221 -- reference to the current object.
5223 or else (Is_Entity_Name (Original_Node (Obj))
5224 and then Present (Entity (Original_Node (Obj)))
5225 and then Is_Type (Entity (Original_Node (Obj))))
5227 or else (Is_Type (E) and then E = Current_Scope)
5229 or else (Is_Incomplete_Or_Private_Type (E)
5230 and then Full_View (E) = Current_Scope);
5232 elsif Nkind (Obj) = N_Selected_Component then
5233 return Is_Aliased (Entity (Selector_Name (Obj)));
5235 elsif Nkind (Obj) = N_Indexed_Component then
5236 return Has_Aliased_Components (Etype (Prefix (Obj)))
5237 or else
5238 (Is_Access_Type (Etype (Prefix (Obj)))
5239 and then
5240 Has_Aliased_Components
5241 (Designated_Type (Etype (Prefix (Obj)))));
5243 elsif Nkind (Obj) = N_Unchecked_Type_Conversion
5244 or else Nkind (Obj) = N_Type_Conversion
5245 then
5246 return Is_Tagged_Type (Etype (Obj))
5247 and then Is_Aliased_View (Expression (Obj));
5249 elsif Nkind (Obj) = N_Explicit_Dereference then
5250 return Nkind (Original_Node (Obj)) /= N_Function_Call;
5252 else
5253 return False;
5254 end if;
5255 end Is_Aliased_View;
5257 -------------------------
5258 -- Is_Ancestor_Package --
5259 -------------------------
5261 function Is_Ancestor_Package
5262 (E1 : Entity_Id;
5263 E2 : Entity_Id) return Boolean
5265 Par : Entity_Id;
5267 begin
5268 Par := E2;
5269 while Present (Par)
5270 and then Par /= Standard_Standard
5271 loop
5272 if Par = E1 then
5273 return True;
5274 end if;
5276 Par := Scope (Par);
5277 end loop;
5279 return False;
5280 end Is_Ancestor_Package;
5282 ----------------------
5283 -- Is_Atomic_Object --
5284 ----------------------
5286 function Is_Atomic_Object (N : Node_Id) return Boolean is
5288 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
5289 -- Determines if given object has atomic components
5291 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
5292 -- If prefix is an implicit dereference, examine designated type
5294 ----------------------
5295 -- Is_Atomic_Prefix --
5296 ----------------------
5298 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
5299 begin
5300 if Is_Access_Type (Etype (N)) then
5301 return
5302 Has_Atomic_Components (Designated_Type (Etype (N)));
5303 else
5304 return Object_Has_Atomic_Components (N);
5305 end if;
5306 end Is_Atomic_Prefix;
5308 ----------------------------------
5309 -- Object_Has_Atomic_Components --
5310 ----------------------------------
5312 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
5313 begin
5314 if Has_Atomic_Components (Etype (N))
5315 or else Is_Atomic (Etype (N))
5316 then
5317 return True;
5319 elsif Is_Entity_Name (N)
5320 and then (Has_Atomic_Components (Entity (N))
5321 or else Is_Atomic (Entity (N)))
5322 then
5323 return True;
5325 elsif Nkind (N) = N_Indexed_Component
5326 or else Nkind (N) = N_Selected_Component
5327 then
5328 return Is_Atomic_Prefix (Prefix (N));
5330 else
5331 return False;
5332 end if;
5333 end Object_Has_Atomic_Components;
5335 -- Start of processing for Is_Atomic_Object
5337 begin
5338 if Is_Atomic (Etype (N))
5339 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
5340 then
5341 return True;
5343 elsif Nkind (N) = N_Indexed_Component
5344 or else Nkind (N) = N_Selected_Component
5345 then
5346 return Is_Atomic_Prefix (Prefix (N));
5348 else
5349 return False;
5350 end if;
5351 end Is_Atomic_Object;
5353 -------------------------
5354 -- Is_Coextension_Root --
5355 -------------------------
5357 function Is_Coextension_Root (N : Node_Id) return Boolean is
5358 begin
5359 return
5360 Nkind (N) = N_Allocator
5361 and then Present (Coextensions (N))
5363 -- Anonymous access discriminants carry a list of all nested
5364 -- controlled coextensions.
5366 and then not Is_Dynamic_Coextension (N)
5367 and then not Is_Static_Coextension (N);
5368 end Is_Coextension_Root;
5370 --------------------------------------
5371 -- Is_Controlling_Limited_Procedure --
5372 --------------------------------------
5374 function Is_Controlling_Limited_Procedure
5375 (Proc_Nam : Entity_Id) return Boolean
5377 Param_Typ : Entity_Id := Empty;
5379 begin
5380 if Ekind (Proc_Nam) = E_Procedure
5381 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
5382 then
5383 Param_Typ := Etype (Parameter_Type (First (
5384 Parameter_Specifications (Parent (Proc_Nam)))));
5386 -- In this case where an Itype was created, the procedure call has been
5387 -- rewritten.
5389 elsif Present (Associated_Node_For_Itype (Proc_Nam))
5390 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
5391 and then
5392 Present (Parameter_Associations
5393 (Associated_Node_For_Itype (Proc_Nam)))
5394 then
5395 Param_Typ :=
5396 Etype (First (Parameter_Associations
5397 (Associated_Node_For_Itype (Proc_Nam))));
5398 end if;
5400 if Present (Param_Typ) then
5401 return
5402 Is_Interface (Param_Typ)
5403 and then Is_Limited_Record (Param_Typ);
5404 end if;
5406 return False;
5407 end Is_Controlling_Limited_Procedure;
5409 ----------------------------------------------
5410 -- Is_Dependent_Component_Of_Mutable_Object --
5411 ----------------------------------------------
5413 function Is_Dependent_Component_Of_Mutable_Object
5414 (Object : Node_Id) return Boolean
5416 P : Node_Id;
5417 Prefix_Type : Entity_Id;
5418 P_Aliased : Boolean := False;
5419 Comp : Entity_Id;
5421 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
5422 -- Returns True if and only if Comp is declared within a variant part
5424 --------------------------------
5425 -- Is_Declared_Within_Variant --
5426 --------------------------------
5428 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
5429 Comp_Decl : constant Node_Id := Parent (Comp);
5430 Comp_List : constant Node_Id := Parent (Comp_Decl);
5431 begin
5432 return Nkind (Parent (Comp_List)) = N_Variant;
5433 end Is_Declared_Within_Variant;
5435 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
5437 begin
5438 if Is_Variable (Object) then
5440 if Nkind (Object) = N_Selected_Component then
5441 P := Prefix (Object);
5442 Prefix_Type := Etype (P);
5444 if Is_Entity_Name (P) then
5446 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
5447 Prefix_Type := Base_Type (Prefix_Type);
5448 end if;
5450 if Is_Aliased (Entity (P)) then
5451 P_Aliased := True;
5452 end if;
5454 -- A discriminant check on a selected component may be
5455 -- expanded into a dereference when removing side-effects.
5456 -- Recover the original node and its type, which may be
5457 -- unconstrained.
5459 elsif Nkind (P) = N_Explicit_Dereference
5460 and then not (Comes_From_Source (P))
5461 then
5462 P := Original_Node (P);
5463 Prefix_Type := Etype (P);
5465 else
5466 -- Check for prefix being an aliased component ???
5467 null;
5469 end if;
5471 -- A heap object is constrained by its initial value
5473 -- Ada 2005 (AI-363): Always assume the object could be mutable in
5474 -- the dereferenced case, since the access value might denote an
5475 -- unconstrained aliased object, whereas in Ada 95 the designated
5476 -- object is guaranteed to be constrained. A worst-case assumption
5477 -- has to apply in Ada 2005 because we can't tell at compile time
5478 -- whether the object is "constrained by its initial value"
5479 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
5480 -- semantic rules -- these rules are acknowledged to need fixing).
5482 if Ada_Version < Ada_05 then
5483 if Is_Access_Type (Prefix_Type)
5484 or else Nkind (P) = N_Explicit_Dereference
5485 then
5486 return False;
5487 end if;
5489 elsif Ada_Version >= Ada_05 then
5490 if Is_Access_Type (Prefix_Type) then
5491 Prefix_Type := Designated_Type (Prefix_Type);
5492 end if;
5493 end if;
5495 Comp :=
5496 Original_Record_Component (Entity (Selector_Name (Object)));
5498 -- As per AI-0017, the renaming is illegal in a generic body,
5499 -- even if the subtype is indefinite.
5501 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
5503 if not Is_Constrained (Prefix_Type)
5504 and then (not Is_Indefinite_Subtype (Prefix_Type)
5505 or else
5506 (Is_Generic_Type (Prefix_Type)
5507 and then Ekind (Current_Scope) = E_Generic_Package
5508 and then In_Package_Body (Current_Scope)))
5510 and then (Is_Declared_Within_Variant (Comp)
5511 or else Has_Discriminant_Dependent_Constraint (Comp))
5512 and then (not P_Aliased or else Ada_Version >= Ada_05)
5513 then
5514 return True;
5516 else
5517 return
5518 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
5520 end if;
5522 elsif Nkind (Object) = N_Indexed_Component
5523 or else Nkind (Object) = N_Slice
5524 then
5525 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
5527 -- A type conversion that Is_Variable is a view conversion:
5528 -- go back to the denoted object.
5530 elsif Nkind (Object) = N_Type_Conversion then
5531 return
5532 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
5533 end if;
5534 end if;
5536 return False;
5537 end Is_Dependent_Component_Of_Mutable_Object;
5539 ---------------------
5540 -- Is_Dereferenced --
5541 ---------------------
5543 function Is_Dereferenced (N : Node_Id) return Boolean is
5544 P : constant Node_Id := Parent (N);
5545 begin
5546 return
5547 (Nkind (P) = N_Selected_Component
5548 or else
5549 Nkind (P) = N_Explicit_Dereference
5550 or else
5551 Nkind (P) = N_Indexed_Component
5552 or else
5553 Nkind (P) = N_Slice)
5554 and then Prefix (P) = N;
5555 end Is_Dereferenced;
5557 ----------------------
5558 -- Is_Descendent_Of --
5559 ----------------------
5561 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
5562 T : Entity_Id;
5563 Etyp : Entity_Id;
5565 begin
5566 pragma Assert (Nkind (T1) in N_Entity);
5567 pragma Assert (Nkind (T2) in N_Entity);
5569 T := Base_Type (T1);
5571 -- Immediate return if the types match
5573 if T = T2 then
5574 return True;
5576 -- Comment needed here ???
5578 elsif Ekind (T) = E_Class_Wide_Type then
5579 return Etype (T) = T2;
5581 -- All other cases
5583 else
5584 loop
5585 Etyp := Etype (T);
5587 -- Done if we found the type we are looking for
5589 if Etyp = T2 then
5590 return True;
5592 -- Done if no more derivations to check
5594 elsif T = T1
5595 or else T = Etyp
5596 then
5597 return False;
5599 -- Following test catches error cases resulting from prev errors
5601 elsif No (Etyp) then
5602 return False;
5604 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
5605 return False;
5607 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
5608 return False;
5609 end if;
5611 T := Base_Type (Etyp);
5612 end loop;
5613 end if;
5615 raise Program_Error;
5616 end Is_Descendent_Of;
5618 --------------
5619 -- Is_False --
5620 --------------
5622 function Is_False (U : Uint) return Boolean is
5623 begin
5624 return (U = 0);
5625 end Is_False;
5627 ---------------------------
5628 -- Is_Fixed_Model_Number --
5629 ---------------------------
5631 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
5632 S : constant Ureal := Small_Value (T);
5633 M : Urealp.Save_Mark;
5634 R : Boolean;
5635 begin
5636 M := Urealp.Mark;
5637 R := (U = UR_Trunc (U / S) * S);
5638 Urealp.Release (M);
5639 return R;
5640 end Is_Fixed_Model_Number;
5642 -------------------------------
5643 -- Is_Fully_Initialized_Type --
5644 -------------------------------
5646 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
5647 begin
5648 if Is_Scalar_Type (Typ) then
5649 return False;
5651 elsif Is_Access_Type (Typ) then
5652 return True;
5654 elsif Is_Array_Type (Typ) then
5655 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
5656 return True;
5657 end if;
5659 -- An interesting case, if we have a constrained type one of whose
5660 -- bounds is known to be null, then there are no elements to be
5661 -- initialized, so all the elements are initialized!
5663 if Is_Constrained (Typ) then
5664 declare
5665 Indx : Node_Id;
5666 Indx_Typ : Entity_Id;
5667 Lbd, Hbd : Node_Id;
5669 begin
5670 Indx := First_Index (Typ);
5671 while Present (Indx) loop
5672 if Etype (Indx) = Any_Type then
5673 return False;
5675 -- If index is a range, use directly
5677 elsif Nkind (Indx) = N_Range then
5678 Lbd := Low_Bound (Indx);
5679 Hbd := High_Bound (Indx);
5681 else
5682 Indx_Typ := Etype (Indx);
5684 if Is_Private_Type (Indx_Typ) then
5685 Indx_Typ := Full_View (Indx_Typ);
5686 end if;
5688 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
5689 return False;
5690 else
5691 Lbd := Type_Low_Bound (Indx_Typ);
5692 Hbd := Type_High_Bound (Indx_Typ);
5693 end if;
5694 end if;
5696 if Compile_Time_Known_Value (Lbd)
5697 and then Compile_Time_Known_Value (Hbd)
5698 then
5699 if Expr_Value (Hbd) < Expr_Value (Lbd) then
5700 return True;
5701 end if;
5702 end if;
5704 Next_Index (Indx);
5705 end loop;
5706 end;
5707 end if;
5709 -- If no null indexes, then type is not fully initialized
5711 return False;
5713 -- Record types
5715 elsif Is_Record_Type (Typ) then
5716 if Has_Discriminants (Typ)
5717 and then
5718 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
5719 and then Is_Fully_Initialized_Variant (Typ)
5720 then
5721 return True;
5722 end if;
5724 -- Controlled records are considered to be fully initialized if
5725 -- there is a user defined Initialize routine. This may not be
5726 -- entirely correct, but as the spec notes, we are guessing here
5727 -- what is best from the point of view of issuing warnings.
5729 if Is_Controlled (Typ) then
5730 declare
5731 Utyp : constant Entity_Id := Underlying_Type (Typ);
5733 begin
5734 if Present (Utyp) then
5735 declare
5736 Init : constant Entity_Id :=
5737 (Find_Prim_Op
5738 (Underlying_Type (Typ), Name_Initialize));
5740 begin
5741 if Present (Init)
5742 and then Comes_From_Source (Init)
5743 and then not
5744 Is_Predefined_File_Name
5745 (File_Name (Get_Source_File_Index (Sloc (Init))))
5746 then
5747 return True;
5749 elsif Has_Null_Extension (Typ)
5750 and then
5751 Is_Fully_Initialized_Type
5752 (Etype (Base_Type (Typ)))
5753 then
5754 return True;
5755 end if;
5756 end;
5757 end if;
5758 end;
5759 end if;
5761 -- Otherwise see if all record components are initialized
5763 declare
5764 Ent : Entity_Id;
5766 begin
5767 Ent := First_Entity (Typ);
5768 while Present (Ent) loop
5769 if Chars (Ent) = Name_uController then
5770 null;
5772 elsif Ekind (Ent) = E_Component
5773 and then (No (Parent (Ent))
5774 or else No (Expression (Parent (Ent))))
5775 and then not Is_Fully_Initialized_Type (Etype (Ent))
5777 -- Special VM case for uTag component, which needs to be
5778 -- defined in this case, but is never initialized as VMs
5779 -- are using other dispatching mechanisms. Ignore this
5780 -- uninitialized case.
5782 and then (VM_Target = No_VM
5783 or else Chars (Ent) /= Name_uTag)
5784 then
5785 return False;
5786 end if;
5788 Next_Entity (Ent);
5789 end loop;
5790 end;
5792 -- No uninitialized components, so type is fully initialized.
5793 -- Note that this catches the case of no components as well.
5795 return True;
5797 elsif Is_Concurrent_Type (Typ) then
5798 return True;
5800 elsif Is_Private_Type (Typ) then
5801 declare
5802 U : constant Entity_Id := Underlying_Type (Typ);
5804 begin
5805 if No (U) then
5806 return False;
5807 else
5808 return Is_Fully_Initialized_Type (U);
5809 end if;
5810 end;
5812 else
5813 return False;
5814 end if;
5815 end Is_Fully_Initialized_Type;
5817 ----------------------------------
5818 -- Is_Fully_Initialized_Variant --
5819 ----------------------------------
5821 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
5822 Loc : constant Source_Ptr := Sloc (Typ);
5823 Constraints : constant List_Id := New_List;
5824 Components : constant Elist_Id := New_Elmt_List;
5825 Comp_Elmt : Elmt_Id;
5826 Comp_Id : Node_Id;
5827 Comp_List : Node_Id;
5828 Discr : Entity_Id;
5829 Discr_Val : Node_Id;
5830 Report_Errors : Boolean;
5832 begin
5833 if Serious_Errors_Detected > 0 then
5834 return False;
5835 end if;
5837 if Is_Record_Type (Typ)
5838 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
5839 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
5840 then
5841 Comp_List := Component_List (Type_Definition (Parent (Typ)));
5843 Discr := First_Discriminant (Typ);
5844 while Present (Discr) loop
5845 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
5846 Discr_Val := Expression (Parent (Discr));
5848 if Present (Discr_Val)
5849 and then Is_OK_Static_Expression (Discr_Val)
5850 then
5851 Append_To (Constraints,
5852 Make_Component_Association (Loc,
5853 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
5854 Expression => New_Copy (Discr_Val)));
5855 else
5856 return False;
5857 end if;
5858 else
5859 return False;
5860 end if;
5862 Next_Discriminant (Discr);
5863 end loop;
5865 Gather_Components
5866 (Typ => Typ,
5867 Comp_List => Comp_List,
5868 Governed_By => Constraints,
5869 Into => Components,
5870 Report_Errors => Report_Errors);
5872 -- Check that each component present is fully initialized
5874 Comp_Elmt := First_Elmt (Components);
5875 while Present (Comp_Elmt) loop
5876 Comp_Id := Node (Comp_Elmt);
5878 if Ekind (Comp_Id) = E_Component
5879 and then (No (Parent (Comp_Id))
5880 or else No (Expression (Parent (Comp_Id))))
5881 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
5882 then
5883 return False;
5884 end if;
5886 Next_Elmt (Comp_Elmt);
5887 end loop;
5889 return True;
5891 elsif Is_Private_Type (Typ) then
5892 declare
5893 U : constant Entity_Id := Underlying_Type (Typ);
5895 begin
5896 if No (U) then
5897 return False;
5898 else
5899 return Is_Fully_Initialized_Variant (U);
5900 end if;
5901 end;
5902 else
5903 return False;
5904 end if;
5905 end Is_Fully_Initialized_Variant;
5907 ----------------------------
5908 -- Is_Inherited_Operation --
5909 ----------------------------
5911 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
5912 Kind : constant Node_Kind := Nkind (Parent (E));
5913 begin
5914 pragma Assert (Is_Overloadable (E));
5915 return Kind = N_Full_Type_Declaration
5916 or else Kind = N_Private_Extension_Declaration
5917 or else Kind = N_Subtype_Declaration
5918 or else (Ekind (E) = E_Enumeration_Literal
5919 and then Is_Derived_Type (Etype (E)));
5920 end Is_Inherited_Operation;
5922 -----------------------------
5923 -- Is_Library_Level_Entity --
5924 -----------------------------
5926 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
5927 begin
5928 -- The following is a small optimization, and it also properly handles
5929 -- discriminals, which in task bodies might appear in expressions before
5930 -- the corresponding procedure has been created, and which therefore do
5931 -- not have an assigned scope.
5933 if Ekind (E) in Formal_Kind then
5934 return False;
5935 end if;
5937 -- Normal test is simply that the enclosing dynamic scope is Standard
5939 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
5940 end Is_Library_Level_Entity;
5942 ---------------------------------
5943 -- Is_Local_Variable_Reference --
5944 ---------------------------------
5946 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
5947 begin
5948 if not Is_Entity_Name (Expr) then
5949 return False;
5951 else
5952 declare
5953 Ent : constant Entity_Id := Entity (Expr);
5954 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
5955 begin
5956 if Ekind (Ent) /= E_Variable
5957 and then
5958 Ekind (Ent) /= E_In_Out_Parameter
5959 then
5960 return False;
5961 else
5962 return Present (Sub) and then Sub = Current_Subprogram;
5963 end if;
5964 end;
5965 end if;
5966 end Is_Local_Variable_Reference;
5968 -------------------------
5969 -- Is_Object_Reference --
5970 -------------------------
5972 function Is_Object_Reference (N : Node_Id) return Boolean is
5973 begin
5974 if Is_Entity_Name (N) then
5975 return Present (Entity (N)) and then Is_Object (Entity (N));
5977 else
5978 case Nkind (N) is
5979 when N_Indexed_Component | N_Slice =>
5980 return
5981 Is_Object_Reference (Prefix (N))
5982 or else Is_Access_Type (Etype (Prefix (N)));
5984 -- In Ada95, a function call is a constant object; a procedure
5985 -- call is not.
5987 when N_Function_Call =>
5988 return Etype (N) /= Standard_Void_Type;
5990 -- A reference to the stream attribute Input is a function call
5992 when N_Attribute_Reference =>
5993 return Attribute_Name (N) = Name_Input;
5995 when N_Selected_Component =>
5996 return
5997 Is_Object_Reference (Selector_Name (N))
5998 and then
5999 (Is_Object_Reference (Prefix (N))
6000 or else Is_Access_Type (Etype (Prefix (N))));
6002 when N_Explicit_Dereference =>
6003 return True;
6005 -- A view conversion of a tagged object is an object reference
6007 when N_Type_Conversion =>
6008 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
6009 and then Is_Tagged_Type (Etype (Expression (N)))
6010 and then Is_Object_Reference (Expression (N));
6012 -- An unchecked type conversion is considered to be an object if
6013 -- the operand is an object (this construction arises only as a
6014 -- result of expansion activities).
6016 when N_Unchecked_Type_Conversion =>
6017 return True;
6019 when others =>
6020 return False;
6021 end case;
6022 end if;
6023 end Is_Object_Reference;
6025 -----------------------------------
6026 -- Is_OK_Variable_For_Out_Formal --
6027 -----------------------------------
6029 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
6030 begin
6031 Note_Possible_Modification (AV);
6033 -- We must reject parenthesized variable names. The check for
6034 -- Comes_From_Source is present because there are currently
6035 -- cases where the compiler violates this rule (e.g. passing
6036 -- a task object to its controlled Initialize routine).
6038 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
6039 return False;
6041 -- A variable is always allowed
6043 elsif Is_Variable (AV) then
6044 return True;
6046 -- Unchecked conversions are allowed only if they come from the
6047 -- generated code, which sometimes uses unchecked conversions for out
6048 -- parameters in cases where code generation is unaffected. We tell
6049 -- source unchecked conversions by seeing if they are rewrites of an
6050 -- original Unchecked_Conversion function call, or of an explicit
6051 -- conversion of a function call.
6053 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
6054 if Nkind (Original_Node (AV)) = N_Function_Call then
6055 return False;
6057 elsif Comes_From_Source (AV)
6058 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
6059 then
6060 return False;
6062 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
6063 return Is_OK_Variable_For_Out_Formal (Expression (AV));
6065 else
6066 return True;
6067 end if;
6069 -- Normal type conversions are allowed if argument is a variable
6071 elsif Nkind (AV) = N_Type_Conversion then
6072 if Is_Variable (Expression (AV))
6073 and then Paren_Count (Expression (AV)) = 0
6074 then
6075 Note_Possible_Modification (Expression (AV));
6076 return True;
6078 -- We also allow a non-parenthesized expression that raises
6079 -- constraint error if it rewrites what used to be a variable
6081 elsif Raises_Constraint_Error (Expression (AV))
6082 and then Paren_Count (Expression (AV)) = 0
6083 and then Is_Variable (Original_Node (Expression (AV)))
6084 then
6085 return True;
6087 -- Type conversion of something other than a variable
6089 else
6090 return False;
6091 end if;
6093 -- If this node is rewritten, then test the original form, if that is
6094 -- OK, then we consider the rewritten node OK (for example, if the
6095 -- original node is a conversion, then Is_Variable will not be true
6096 -- but we still want to allow the conversion if it converts a variable).
6098 elsif Original_Node (AV) /= AV then
6099 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
6101 -- All other non-variables are rejected
6103 else
6104 return False;
6105 end if;
6106 end Is_OK_Variable_For_Out_Formal;
6108 ---------------
6109 -- Is_Parent --
6110 ---------------
6112 function Is_Parent
6113 (E1 : Entity_Id;
6114 E2 : Entity_Id) return Boolean
6116 Iface_List : List_Id;
6117 T : Entity_Id := E2;
6119 begin
6120 if Is_Concurrent_Type (T)
6121 or else Is_Concurrent_Record_Type (T)
6122 then
6123 Iface_List := Abstract_Interface_List (E2);
6125 if Is_Empty_List (Iface_List) then
6126 return False;
6127 end if;
6129 T := Etype (First (Iface_List));
6130 end if;
6132 return Is_Ancestor (E1, T);
6133 end Is_Parent;
6135 -----------------------------------
6136 -- Is_Partially_Initialized_Type --
6137 -----------------------------------
6139 function Is_Partially_Initialized_Type (Typ : Entity_Id) return Boolean is
6140 begin
6141 if Is_Scalar_Type (Typ) then
6142 return False;
6144 elsif Is_Access_Type (Typ) then
6145 return True;
6147 elsif Is_Array_Type (Typ) then
6149 -- If component type is partially initialized, so is array type
6151 if Is_Partially_Initialized_Type (Component_Type (Typ)) then
6152 return True;
6154 -- Otherwise we are only partially initialized if we are fully
6155 -- initialized (this is the empty array case, no point in us
6156 -- duplicating that code here).
6158 else
6159 return Is_Fully_Initialized_Type (Typ);
6160 end if;
6162 elsif Is_Record_Type (Typ) then
6164 -- A discriminated type is always partially initialized
6166 if Has_Discriminants (Typ) then
6167 return True;
6169 -- A tagged type is always partially initialized
6171 elsif Is_Tagged_Type (Typ) then
6172 return True;
6174 -- Case of non-discriminated record
6176 else
6177 declare
6178 Ent : Entity_Id;
6180 Component_Present : Boolean := False;
6181 -- Set True if at least one component is present. If no
6182 -- components are present, then record type is fully
6183 -- initialized (another odd case, like the null array).
6185 begin
6186 -- Loop through components
6188 Ent := First_Entity (Typ);
6189 while Present (Ent) loop
6190 if Ekind (Ent) = E_Component then
6191 Component_Present := True;
6193 -- If a component has an initialization expression then
6194 -- the enclosing record type is partially initialized
6196 if Present (Parent (Ent))
6197 and then Present (Expression (Parent (Ent)))
6198 then
6199 return True;
6201 -- If a component is of a type which is itself partially
6202 -- initialized, then the enclosing record type is also.
6204 elsif Is_Partially_Initialized_Type (Etype (Ent)) then
6205 return True;
6206 end if;
6207 end if;
6209 Next_Entity (Ent);
6210 end loop;
6212 -- No initialized components found. If we found any components
6213 -- they were all uninitialized so the result is false.
6215 if Component_Present then
6216 return False;
6218 -- But if we found no components, then all the components are
6219 -- initialized so we consider the type to be initialized.
6221 else
6222 return True;
6223 end if;
6224 end;
6225 end if;
6227 -- Concurrent types are always fully initialized
6229 elsif Is_Concurrent_Type (Typ) then
6230 return True;
6232 -- For a private type, go to underlying type. If there is no underlying
6233 -- type then just assume this partially initialized. Not clear if this
6234 -- can happen in a non-error case, but no harm in testing for this.
6236 elsif Is_Private_Type (Typ) then
6237 declare
6238 U : constant Entity_Id := Underlying_Type (Typ);
6239 begin
6240 if No (U) then
6241 return True;
6242 else
6243 return Is_Partially_Initialized_Type (U);
6244 end if;
6245 end;
6247 -- For any other type (are there any?) assume partially initialized
6249 else
6250 return True;
6251 end if;
6252 end Is_Partially_Initialized_Type;
6254 ------------------------------------
6255 -- Is_Potentially_Persistent_Type --
6256 ------------------------------------
6258 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
6259 Comp : Entity_Id;
6260 Indx : Node_Id;
6262 begin
6263 -- For private type, test corrresponding full type
6265 if Is_Private_Type (T) then
6266 return Is_Potentially_Persistent_Type (Full_View (T));
6268 -- Scalar types are potentially persistent
6270 elsif Is_Scalar_Type (T) then
6271 return True;
6273 -- Record type is potentially persistent if not tagged and the types of
6274 -- all it components are potentially persistent, and no component has
6275 -- an initialization expression.
6277 elsif Is_Record_Type (T)
6278 and then not Is_Tagged_Type (T)
6279 and then not Is_Partially_Initialized_Type (T)
6280 then
6281 Comp := First_Component (T);
6282 while Present (Comp) loop
6283 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
6284 return False;
6285 else
6286 Next_Entity (Comp);
6287 end if;
6288 end loop;
6290 return True;
6292 -- Array type is potentially persistent if its component type is
6293 -- potentially persistent and if all its constraints are static.
6295 elsif Is_Array_Type (T) then
6296 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
6297 return False;
6298 end if;
6300 Indx := First_Index (T);
6301 while Present (Indx) loop
6302 if not Is_OK_Static_Subtype (Etype (Indx)) then
6303 return False;
6304 else
6305 Next_Index (Indx);
6306 end if;
6307 end loop;
6309 return True;
6311 -- All other types are not potentially persistent
6313 else
6314 return False;
6315 end if;
6316 end Is_Potentially_Persistent_Type;
6318 -----------------------------
6319 -- Is_RCI_Pkg_Spec_Or_Body --
6320 -----------------------------
6322 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
6324 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
6325 -- Return True if the unit of Cunit is an RCI package declaration
6327 ---------------------------
6328 -- Is_RCI_Pkg_Decl_Cunit --
6329 ---------------------------
6331 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
6332 The_Unit : constant Node_Id := Unit (Cunit);
6334 begin
6335 if Nkind (The_Unit) /= N_Package_Declaration then
6336 return False;
6337 end if;
6339 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
6340 end Is_RCI_Pkg_Decl_Cunit;
6342 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
6344 begin
6345 return Is_RCI_Pkg_Decl_Cunit (Cunit)
6346 or else
6347 (Nkind (Unit (Cunit)) = N_Package_Body
6348 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
6349 end Is_RCI_Pkg_Spec_Or_Body;
6351 -----------------------------------------
6352 -- Is_Remote_Access_To_Class_Wide_Type --
6353 -----------------------------------------
6355 function Is_Remote_Access_To_Class_Wide_Type
6356 (E : Entity_Id) return Boolean
6358 D : Entity_Id;
6360 function Comes_From_Limited_Private_Type_Declaration
6361 (E : Entity_Id) return Boolean;
6362 -- Check that the type is declared by a limited type declaration,
6363 -- or else is derived from a Remote_Type ancestor through private
6364 -- extensions.
6366 -------------------------------------------------
6367 -- Comes_From_Limited_Private_Type_Declaration --
6368 -------------------------------------------------
6370 function Comes_From_Limited_Private_Type_Declaration
6371 (E : Entity_Id) return Boolean
6373 N : constant Node_Id := Declaration_Node (E);
6375 begin
6376 if Nkind (N) = N_Private_Type_Declaration
6377 and then Limited_Present (N)
6378 then
6379 return True;
6380 end if;
6382 if Nkind (N) = N_Private_Extension_Declaration then
6383 return
6384 Comes_From_Limited_Private_Type_Declaration (Etype (E))
6385 or else
6386 (Is_Remote_Types (Etype (E))
6387 and then Is_Limited_Record (Etype (E))
6388 and then Has_Private_Declaration (Etype (E)));
6389 end if;
6391 return False;
6392 end Comes_From_Limited_Private_Type_Declaration;
6394 -- Start of processing for Is_Remote_Access_To_Class_Wide_Type
6396 begin
6397 if not (Is_Remote_Call_Interface (E)
6398 or else Is_Remote_Types (E))
6399 or else Ekind (E) /= E_General_Access_Type
6400 then
6401 return False;
6402 end if;
6404 D := Designated_Type (E);
6406 if Ekind (D) /= E_Class_Wide_Type then
6407 return False;
6408 end if;
6410 return Comes_From_Limited_Private_Type_Declaration
6411 (Defining_Identifier (Parent (D)));
6412 end Is_Remote_Access_To_Class_Wide_Type;
6414 -----------------------------------------
6415 -- Is_Remote_Access_To_Subprogram_Type --
6416 -----------------------------------------
6418 function Is_Remote_Access_To_Subprogram_Type
6419 (E : Entity_Id) return Boolean
6421 begin
6422 return (Ekind (E) = E_Access_Subprogram_Type
6423 or else (Ekind (E) = E_Record_Type
6424 and then Present (Corresponding_Remote_Type (E))))
6425 and then (Is_Remote_Call_Interface (E)
6426 or else Is_Remote_Types (E));
6427 end Is_Remote_Access_To_Subprogram_Type;
6429 --------------------
6430 -- Is_Remote_Call --
6431 --------------------
6433 function Is_Remote_Call (N : Node_Id) return Boolean is
6434 begin
6435 if Nkind (N) /= N_Procedure_Call_Statement
6436 and then Nkind (N) /= N_Function_Call
6437 then
6438 -- An entry call cannot be remote
6440 return False;
6442 elsif Nkind (Name (N)) in N_Has_Entity
6443 and then Is_Remote_Call_Interface (Entity (Name (N)))
6444 then
6445 -- A subprogram declared in the spec of a RCI package is remote
6447 return True;
6449 elsif Nkind (Name (N)) = N_Explicit_Dereference
6450 and then Is_Remote_Access_To_Subprogram_Type
6451 (Etype (Prefix (Name (N))))
6452 then
6453 -- The dereference of a RAS is a remote call
6455 return True;
6457 elsif Present (Controlling_Argument (N))
6458 and then Is_Remote_Access_To_Class_Wide_Type
6459 (Etype (Controlling_Argument (N)))
6460 then
6461 -- Any primitive operation call with a controlling argument of
6462 -- a RACW type is a remote call.
6464 return True;
6465 end if;
6467 -- All other calls are local calls
6469 return False;
6470 end Is_Remote_Call;
6472 ----------------------
6473 -- Is_Renamed_Entry --
6474 ----------------------
6476 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
6477 Orig_Node : Node_Id := Empty;
6478 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
6480 function Is_Entry (Nam : Node_Id) return Boolean;
6481 -- Determine whether Nam is an entry. Traverse selectors
6482 -- if there are nested selected components.
6484 --------------
6485 -- Is_Entry --
6486 --------------
6488 function Is_Entry (Nam : Node_Id) return Boolean is
6489 begin
6490 if Nkind (Nam) = N_Selected_Component then
6491 return Is_Entry (Selector_Name (Nam));
6492 end if;
6494 return Ekind (Entity (Nam)) = E_Entry;
6495 end Is_Entry;
6497 -- Start of processing for Is_Renamed_Entry
6499 begin
6500 if Present (Alias (Proc_Nam)) then
6501 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
6502 end if;
6504 -- Look for a rewritten subprogram renaming declaration
6506 if Nkind (Subp_Decl) = N_Subprogram_Declaration
6507 and then Present (Original_Node (Subp_Decl))
6508 then
6509 Orig_Node := Original_Node (Subp_Decl);
6510 end if;
6512 -- The rewritten subprogram is actually an entry
6514 if Present (Orig_Node)
6515 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
6516 and then Is_Entry (Name (Orig_Node))
6517 then
6518 return True;
6519 end if;
6521 return False;
6522 end Is_Renamed_Entry;
6524 ----------------------
6525 -- Is_Selector_Name --
6526 ----------------------
6528 function Is_Selector_Name (N : Node_Id) return Boolean is
6529 begin
6530 if not Is_List_Member (N) then
6531 declare
6532 P : constant Node_Id := Parent (N);
6533 K : constant Node_Kind := Nkind (P);
6534 begin
6535 return
6536 (K = N_Expanded_Name or else
6537 K = N_Generic_Association or else
6538 K = N_Parameter_Association or else
6539 K = N_Selected_Component)
6540 and then Selector_Name (P) = N;
6541 end;
6543 else
6544 declare
6545 L : constant List_Id := List_Containing (N);
6546 P : constant Node_Id := Parent (L);
6547 begin
6548 return (Nkind (P) = N_Discriminant_Association
6549 and then Selector_Names (P) = L)
6550 or else
6551 (Nkind (P) = N_Component_Association
6552 and then Choices (P) = L);
6553 end;
6554 end if;
6555 end Is_Selector_Name;
6557 ------------------
6558 -- Is_Statement --
6559 ------------------
6561 function Is_Statement (N : Node_Id) return Boolean is
6562 begin
6563 return
6564 Nkind (N) in N_Statement_Other_Than_Procedure_Call
6565 or else Nkind (N) = N_Procedure_Call_Statement;
6566 end Is_Statement;
6568 ---------------------------------
6569 -- Is_Synchronized_Tagged_Type --
6570 ---------------------------------
6572 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
6573 Kind : constant Entity_Kind := Ekind (Base_Type (E));
6575 begin
6576 -- A task or protected type derived from an interface is a tagged type.
6577 -- Such a tagged type is called a synchronized tagged type, as are
6578 -- synchronized interfaces and private extensions whose declaration
6579 -- includes the reserved word synchronized.
6581 return (Is_Tagged_Type (E)
6582 and then (Kind = E_Task_Type
6583 or else Kind = E_Protected_Type))
6584 or else
6585 (Is_Interface (E)
6586 and then Is_Synchronized_Interface (E))
6587 or else
6588 (Ekind (E) = E_Record_Type_With_Private
6589 and then (Synchronized_Present (Parent (E))
6590 or else Is_Synchronized_Interface (Etype (E))));
6591 end Is_Synchronized_Tagged_Type;
6593 -----------------
6594 -- Is_Transfer --
6595 -----------------
6597 function Is_Transfer (N : Node_Id) return Boolean is
6598 Kind : constant Node_Kind := Nkind (N);
6600 begin
6601 if Kind = N_Simple_Return_Statement
6602 or else
6603 Kind = N_Extended_Return_Statement
6604 or else
6605 Kind = N_Goto_Statement
6606 or else
6607 Kind = N_Raise_Statement
6608 or else
6609 Kind = N_Requeue_Statement
6610 then
6611 return True;
6613 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
6614 and then No (Condition (N))
6615 then
6616 return True;
6618 elsif Kind = N_Procedure_Call_Statement
6619 and then Is_Entity_Name (Name (N))
6620 and then Present (Entity (Name (N)))
6621 and then No_Return (Entity (Name (N)))
6622 then
6623 return True;
6625 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
6626 return True;
6628 else
6629 return False;
6630 end if;
6631 end Is_Transfer;
6633 -------------
6634 -- Is_True --
6635 -------------
6637 function Is_True (U : Uint) return Boolean is
6638 begin
6639 return (U /= 0);
6640 end Is_True;
6642 -------------------
6643 -- Is_Value_Type --
6644 -------------------
6646 function Is_Value_Type (T : Entity_Id) return Boolean is
6647 begin
6648 return VM_Target = CLI_Target
6649 and then Chars (T) /= No_Name
6650 and then Get_Name_String (Chars (T)) = "valuetype";
6651 end Is_Value_Type;
6653 -----------------
6654 -- Is_Variable --
6655 -----------------
6657 function Is_Variable (N : Node_Id) return Boolean is
6659 Orig_Node : constant Node_Id := Original_Node (N);
6660 -- We do the test on the original node, since this is basically a
6661 -- test of syntactic categories, so it must not be disturbed by
6662 -- whatever rewriting might have occurred. For example, an aggregate,
6663 -- which is certainly NOT a variable, could be turned into a variable
6664 -- by expansion.
6666 function In_Protected_Function (E : Entity_Id) return Boolean;
6667 -- Within a protected function, the private components of the
6668 -- enclosing protected type are constants. A function nested within
6669 -- a (protected) procedure is not itself protected.
6671 function Is_Variable_Prefix (P : Node_Id) return Boolean;
6672 -- Prefixes can involve implicit dereferences, in which case we
6673 -- must test for the case of a reference of a constant access
6674 -- type, which can never be a variable.
6676 ---------------------------
6677 -- In_Protected_Function --
6678 ---------------------------
6680 function In_Protected_Function (E : Entity_Id) return Boolean is
6681 Prot : constant Entity_Id := Scope (E);
6682 S : Entity_Id;
6684 begin
6685 if not Is_Protected_Type (Prot) then
6686 return False;
6687 else
6688 S := Current_Scope;
6689 while Present (S) and then S /= Prot loop
6690 if Ekind (S) = E_Function
6691 and then Scope (S) = Prot
6692 then
6693 return True;
6694 end if;
6696 S := Scope (S);
6697 end loop;
6699 return False;
6700 end if;
6701 end In_Protected_Function;
6703 ------------------------
6704 -- Is_Variable_Prefix --
6705 ------------------------
6707 function Is_Variable_Prefix (P : Node_Id) return Boolean is
6708 begin
6709 if Is_Access_Type (Etype (P)) then
6710 return not Is_Access_Constant (Root_Type (Etype (P)));
6712 -- For the case of an indexed component whose prefix has a packed
6713 -- array type, the prefix has been rewritten into a type conversion.
6714 -- Determine variable-ness from the converted expression.
6716 elsif Nkind (P) = N_Type_Conversion
6717 and then not Comes_From_Source (P)
6718 and then Is_Array_Type (Etype (P))
6719 and then Is_Packed (Etype (P))
6720 then
6721 return Is_Variable (Expression (P));
6723 else
6724 return Is_Variable (P);
6725 end if;
6726 end Is_Variable_Prefix;
6728 -- Start of processing for Is_Variable
6730 begin
6731 -- Definitely OK if Assignment_OK is set. Since this is something that
6732 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
6734 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
6735 return True;
6737 -- Normally we go to the original node, but there is one exception
6738 -- where we use the rewritten node, namely when it is an explicit
6739 -- dereference. The generated code may rewrite a prefix which is an
6740 -- access type with an explicit dereference. The dereference is a
6741 -- variable, even though the original node may not be (since it could
6742 -- be a constant of the access type).
6744 -- In Ada 2005 we have a further case to consider: the prefix may be
6745 -- a function call given in prefix notation. The original node appears
6746 -- to be a selected component, but we need to examine the call.
6748 elsif Nkind (N) = N_Explicit_Dereference
6749 and then Nkind (Orig_Node) /= N_Explicit_Dereference
6750 and then Present (Etype (Orig_Node))
6751 and then Is_Access_Type (Etype (Orig_Node))
6752 then
6753 return Is_Variable_Prefix (Original_Node (Prefix (N)))
6754 or else
6755 (Nkind (Orig_Node) = N_Function_Call
6756 and then not Is_Access_Constant (Etype (Prefix (N))));
6758 -- A function call is never a variable
6760 elsif Nkind (N) = N_Function_Call then
6761 return False;
6763 -- All remaining checks use the original node
6765 elsif Is_Entity_Name (Orig_Node)
6766 and then Present (Entity (Orig_Node))
6767 then
6768 declare
6769 E : constant Entity_Id := Entity (Orig_Node);
6770 K : constant Entity_Kind := Ekind (E);
6772 begin
6773 return (K = E_Variable
6774 and then Nkind (Parent (E)) /= N_Exception_Handler)
6775 or else (K = E_Component
6776 and then not In_Protected_Function (E))
6777 or else K = E_Out_Parameter
6778 or else K = E_In_Out_Parameter
6779 or else K = E_Generic_In_Out_Parameter
6781 -- Current instance of type:
6783 or else (Is_Type (E) and then In_Open_Scopes (E))
6784 or else (Is_Incomplete_Or_Private_Type (E)
6785 and then In_Open_Scopes (Full_View (E)));
6786 end;
6788 else
6789 case Nkind (Orig_Node) is
6790 when N_Indexed_Component | N_Slice =>
6791 return Is_Variable_Prefix (Prefix (Orig_Node));
6793 when N_Selected_Component =>
6794 return Is_Variable_Prefix (Prefix (Orig_Node))
6795 and then Is_Variable (Selector_Name (Orig_Node));
6797 -- For an explicit dereference, the type of the prefix cannot
6798 -- be an access to constant or an access to subprogram.
6800 when N_Explicit_Dereference =>
6801 declare
6802 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
6803 begin
6804 return Is_Access_Type (Typ)
6805 and then not Is_Access_Constant (Root_Type (Typ))
6806 and then Ekind (Typ) /= E_Access_Subprogram_Type;
6807 end;
6809 -- The type conversion is the case where we do not deal with the
6810 -- context dependent special case of an actual parameter. Thus
6811 -- the type conversion is only considered a variable for the
6812 -- purposes of this routine if the target type is tagged. However,
6813 -- a type conversion is considered to be a variable if it does not
6814 -- come from source (this deals for example with the conversions
6815 -- of expressions to their actual subtypes).
6817 when N_Type_Conversion =>
6818 return Is_Variable (Expression (Orig_Node))
6819 and then
6820 (not Comes_From_Source (Orig_Node)
6821 or else
6822 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
6823 and then
6824 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
6826 -- GNAT allows an unchecked type conversion as a variable. This
6827 -- only affects the generation of internal expanded code, since
6828 -- calls to instantiations of Unchecked_Conversion are never
6829 -- considered variables (since they are function calls).
6830 -- This is also true for expression actions.
6832 when N_Unchecked_Type_Conversion =>
6833 return Is_Variable (Expression (Orig_Node));
6835 when others =>
6836 return False;
6837 end case;
6838 end if;
6839 end Is_Variable;
6841 ------------------------
6842 -- Is_Volatile_Object --
6843 ------------------------
6845 function Is_Volatile_Object (N : Node_Id) return Boolean is
6847 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
6848 -- Determines if given object has volatile components
6850 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
6851 -- If prefix is an implicit dereference, examine designated type
6853 ------------------------
6854 -- Is_Volatile_Prefix --
6855 ------------------------
6857 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
6858 Typ : constant Entity_Id := Etype (N);
6860 begin
6861 if Is_Access_Type (Typ) then
6862 declare
6863 Dtyp : constant Entity_Id := Designated_Type (Typ);
6865 begin
6866 return Is_Volatile (Dtyp)
6867 or else Has_Volatile_Components (Dtyp);
6868 end;
6870 else
6871 return Object_Has_Volatile_Components (N);
6872 end if;
6873 end Is_Volatile_Prefix;
6875 ------------------------------------
6876 -- Object_Has_Volatile_Components --
6877 ------------------------------------
6879 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
6880 Typ : constant Entity_Id := Etype (N);
6882 begin
6883 if Is_Volatile (Typ)
6884 or else Has_Volatile_Components (Typ)
6885 then
6886 return True;
6888 elsif Is_Entity_Name (N)
6889 and then (Has_Volatile_Components (Entity (N))
6890 or else Is_Volatile (Entity (N)))
6891 then
6892 return True;
6894 elsif Nkind (N) = N_Indexed_Component
6895 or else Nkind (N) = N_Selected_Component
6896 then
6897 return Is_Volatile_Prefix (Prefix (N));
6899 else
6900 return False;
6901 end if;
6902 end Object_Has_Volatile_Components;
6904 -- Start of processing for Is_Volatile_Object
6906 begin
6907 if Is_Volatile (Etype (N))
6908 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
6909 then
6910 return True;
6912 elsif Nkind (N) = N_Indexed_Component
6913 or else Nkind (N) = N_Selected_Component
6914 then
6915 return Is_Volatile_Prefix (Prefix (N));
6917 else
6918 return False;
6919 end if;
6920 end Is_Volatile_Object;
6922 -------------------------
6923 -- Kill_Current_Values --
6924 -------------------------
6926 procedure Kill_Current_Values (Ent : Entity_Id) is
6927 begin
6928 if Is_Object (Ent) then
6929 Kill_Checks (Ent);
6930 Set_Current_Value (Ent, Empty);
6932 if Ekind (Ent) = E_Variable then
6933 Set_Last_Assignment (Ent, Empty);
6934 end if;
6936 if not Can_Never_Be_Null (Ent) then
6937 Set_Is_Known_Non_Null (Ent, False);
6938 end if;
6940 Set_Is_Known_Null (Ent, False);
6941 end if;
6942 end Kill_Current_Values;
6944 procedure Kill_Current_Values is
6945 S : Entity_Id;
6947 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
6948 -- Clear current value for entity E and all entities chained to E
6950 ------------------------------------------
6951 -- Kill_Current_Values_For_Entity_Chain --
6952 ------------------------------------------
6954 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
6955 Ent : Entity_Id;
6956 begin
6957 Ent := E;
6958 while Present (Ent) loop
6959 Kill_Current_Values (Ent);
6960 Next_Entity (Ent);
6961 end loop;
6962 end Kill_Current_Values_For_Entity_Chain;
6964 -- Start of processing for Kill_Current_Values
6966 begin
6967 -- Kill all saved checks, a special case of killing saved values
6969 Kill_All_Checks;
6971 -- Loop through relevant scopes, which includes the current scope and
6972 -- any parent scopes if the current scope is a block or a package.
6974 S := Current_Scope;
6975 Scope_Loop : loop
6977 -- Clear current values of all entities in current scope
6979 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
6981 -- If scope is a package, also clear current values of all
6982 -- private entities in the scope.
6984 if Ekind (S) = E_Package
6985 or else
6986 Ekind (S) = E_Generic_Package
6987 or else
6988 Is_Concurrent_Type (S)
6989 then
6990 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
6991 end if;
6993 -- If this is a not a subprogram, deal with parents
6995 if not Is_Subprogram (S) then
6996 S := Scope (S);
6997 exit Scope_Loop when S = Standard_Standard;
6998 else
6999 exit Scope_Loop;
7000 end if;
7001 end loop Scope_Loop;
7002 end Kill_Current_Values;
7004 --------------------------
7005 -- Kill_Size_Check_Code --
7006 --------------------------
7008 procedure Kill_Size_Check_Code (E : Entity_Id) is
7009 begin
7010 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7011 and then Present (Size_Check_Code (E))
7012 then
7013 Remove (Size_Check_Code (E));
7014 Set_Size_Check_Code (E, Empty);
7015 end if;
7016 end Kill_Size_Check_Code;
7018 --------------------------
7019 -- Known_To_Be_Assigned --
7020 --------------------------
7022 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
7023 P : constant Node_Id := Parent (N);
7025 begin
7026 case Nkind (P) is
7028 -- Test left side of assignment
7030 when N_Assignment_Statement =>
7031 return N = Name (P);
7033 -- Function call arguments are never lvalues
7035 when N_Function_Call =>
7036 return False;
7038 -- Positional parameter for procedure or accept call
7040 when N_Procedure_Call_Statement |
7041 N_Accept_Statement
7043 declare
7044 Proc : Entity_Id;
7045 Form : Entity_Id;
7046 Act : Node_Id;
7048 begin
7049 Proc := Get_Subprogram_Entity (P);
7051 if No (Proc) then
7052 return False;
7053 end if;
7055 -- If we are not a list member, something is strange, so
7056 -- be conservative and return False.
7058 if not Is_List_Member (N) then
7059 return False;
7060 end if;
7062 -- We are going to find the right formal by stepping forward
7063 -- through the formals, as we step backwards in the actuals.
7065 Form := First_Formal (Proc);
7066 Act := N;
7067 loop
7068 -- If no formal, something is weird, so be conservative
7069 -- and return False.
7071 if No (Form) then
7072 return False;
7073 end if;
7075 Prev (Act);
7076 exit when No (Act);
7077 Next_Formal (Form);
7078 end loop;
7080 return Ekind (Form) /= E_In_Parameter;
7081 end;
7083 -- Named parameter for procedure or accept call
7085 when N_Parameter_Association =>
7086 declare
7087 Proc : Entity_Id;
7088 Form : Entity_Id;
7090 begin
7091 Proc := Get_Subprogram_Entity (Parent (P));
7093 if No (Proc) then
7094 return False;
7095 end if;
7097 -- Loop through formals to find the one that matches
7099 Form := First_Formal (Proc);
7100 loop
7101 -- If no matching formal, that's peculiar, some kind of
7102 -- previous error, so return False to be conservative.
7104 if No (Form) then
7105 return False;
7106 end if;
7108 -- Else test for match
7110 if Chars (Form) = Chars (Selector_Name (P)) then
7111 return Ekind (Form) /= E_In_Parameter;
7112 end if;
7114 Next_Formal (Form);
7115 end loop;
7116 end;
7118 -- Test for appearing in a conversion that itself appears
7119 -- in an lvalue context, since this should be an lvalue.
7121 when N_Type_Conversion =>
7122 return Known_To_Be_Assigned (P);
7124 -- All other references are definitely not knwon to be modifications
7126 when others =>
7127 return False;
7129 end case;
7130 end Known_To_Be_Assigned;
7132 -------------------
7133 -- May_Be_Lvalue --
7134 -------------------
7136 function May_Be_Lvalue (N : Node_Id) return Boolean is
7137 P : constant Node_Id := Parent (N);
7139 begin
7140 case Nkind (P) is
7142 -- Test left side of assignment
7144 when N_Assignment_Statement =>
7145 return N = Name (P);
7147 -- Test prefix of component or attribute
7149 when N_Attribute_Reference =>
7150 return N = Prefix (P)
7151 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
7153 when N_Expanded_Name |
7154 N_Explicit_Dereference |
7155 N_Indexed_Component |
7156 N_Reference |
7157 N_Selected_Component |
7158 N_Slice =>
7159 return N = Prefix (P);
7161 -- Function call arguments are never lvalues
7163 when N_Function_Call =>
7164 return False;
7166 -- Positional parameter for procedure, entry, or accept call
7168 when N_Procedure_Call_Statement |
7169 N_Entry_Call_Statement |
7170 N_Accept_Statement
7172 declare
7173 Proc : Entity_Id;
7174 Form : Entity_Id;
7175 Act : Node_Id;
7177 begin
7178 Proc := Get_Subprogram_Entity (P);
7180 if No (Proc) then
7181 return True;
7182 end if;
7184 -- If we are not a list member, something is strange, so
7185 -- be conservative and return True.
7187 if not Is_List_Member (N) then
7188 return True;
7189 end if;
7191 -- We are going to find the right formal by stepping forward
7192 -- through the formals, as we step backwards in the actuals.
7194 Form := First_Formal (Proc);
7195 Act := N;
7196 loop
7197 -- If no formal, something is weird, so be conservative
7198 -- and return True.
7200 if No (Form) then
7201 return True;
7202 end if;
7204 Prev (Act);
7205 exit when No (Act);
7206 Next_Formal (Form);
7207 end loop;
7209 return Ekind (Form) /= E_In_Parameter;
7210 end;
7212 -- Named parameter for procedure or accept call
7214 when N_Parameter_Association =>
7215 declare
7216 Proc : Entity_Id;
7217 Form : Entity_Id;
7219 begin
7220 Proc := Get_Subprogram_Entity (Parent (P));
7222 if No (Proc) then
7223 return True;
7224 end if;
7226 -- Loop through formals to find the one that matches
7228 Form := First_Formal (Proc);
7229 loop
7230 -- If no matching formal, that's peculiar, some kind of
7231 -- previous error, so return True to be conservative.
7233 if No (Form) then
7234 return True;
7235 end if;
7237 -- Else test for match
7239 if Chars (Form) = Chars (Selector_Name (P)) then
7240 return Ekind (Form) /= E_In_Parameter;
7241 end if;
7243 Next_Formal (Form);
7244 end loop;
7245 end;
7247 -- Test for appearing in a conversion that itself appears
7248 -- in an lvalue context, since this should be an lvalue.
7250 when N_Type_Conversion =>
7251 return May_Be_Lvalue (P);
7253 -- Test for appearence in object renaming declaration
7255 when N_Object_Renaming_Declaration =>
7256 return True;
7258 -- All other references are definitely not Lvalues
7260 when others =>
7261 return False;
7263 end case;
7264 end May_Be_Lvalue;
7266 -----------------------
7267 -- Mark_Coextensions --
7268 -----------------------
7270 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
7271 Is_Dynamic : Boolean := False;
7273 function Mark_Allocator (N : Node_Id) return Traverse_Result;
7274 -- Recognize an allocator node and label it as a dynamic coextension
7276 --------------------
7277 -- Mark_Allocator --
7278 --------------------
7280 function Mark_Allocator (N : Node_Id) return Traverse_Result is
7281 begin
7282 if Nkind (N) = N_Allocator then
7283 if Is_Dynamic then
7284 Set_Is_Dynamic_Coextension (N);
7285 else
7286 Set_Is_Static_Coextension (N);
7287 end if;
7288 end if;
7290 return OK;
7291 end Mark_Allocator;
7293 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
7295 -- Start of processing Mark_Coextensions
7297 begin
7298 case Nkind (Context_Nod) is
7299 when N_Assignment_Statement |
7300 N_Simple_Return_Statement =>
7301 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
7303 when N_Object_Declaration =>
7304 Is_Dynamic := Nkind (Root_Nod) = N_Allocator;
7306 -- This routine should not be called for constructs which may not
7307 -- contain coextensions.
7309 when others =>
7310 raise Program_Error;
7311 end case;
7313 Mark_Allocators (Root_Nod);
7314 end Mark_Coextensions;
7316 ----------------------
7317 -- Needs_One_Actual --
7318 ----------------------
7320 function Needs_One_Actual (E : Entity_Id) return Boolean is
7321 Formal : Entity_Id;
7323 begin
7324 if Ada_Version >= Ada_05
7325 and then Present (First_Formal (E))
7326 then
7327 Formal := Next_Formal (First_Formal (E));
7328 while Present (Formal) loop
7329 if No (Default_Value (Formal)) then
7330 return False;
7331 end if;
7333 Next_Formal (Formal);
7334 end loop;
7336 return True;
7338 else
7339 return False;
7340 end if;
7341 end Needs_One_Actual;
7343 -------------------------
7344 -- New_External_Entity --
7345 -------------------------
7347 function New_External_Entity
7348 (Kind : Entity_Kind;
7349 Scope_Id : Entity_Id;
7350 Sloc_Value : Source_Ptr;
7351 Related_Id : Entity_Id;
7352 Suffix : Character;
7353 Suffix_Index : Nat := 0;
7354 Prefix : Character := ' ') return Entity_Id
7356 N : constant Entity_Id :=
7357 Make_Defining_Identifier (Sloc_Value,
7358 New_External_Name
7359 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
7361 begin
7362 Set_Ekind (N, Kind);
7363 Set_Is_Internal (N, True);
7364 Append_Entity (N, Scope_Id);
7365 Set_Public_Status (N);
7367 if Kind in Type_Kind then
7368 Init_Size_Align (N);
7369 end if;
7371 return N;
7372 end New_External_Entity;
7374 -------------------------
7375 -- New_Internal_Entity --
7376 -------------------------
7378 function New_Internal_Entity
7379 (Kind : Entity_Kind;
7380 Scope_Id : Entity_Id;
7381 Sloc_Value : Source_Ptr;
7382 Id_Char : Character) return Entity_Id
7384 N : constant Entity_Id :=
7385 Make_Defining_Identifier (Sloc_Value, New_Internal_Name (Id_Char));
7387 begin
7388 Set_Ekind (N, Kind);
7389 Set_Is_Internal (N, True);
7390 Append_Entity (N, Scope_Id);
7392 if Kind in Type_Kind then
7393 Init_Size_Align (N);
7394 end if;
7396 return N;
7397 end New_Internal_Entity;
7399 -----------------
7400 -- Next_Actual --
7401 -----------------
7403 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
7404 N : Node_Id;
7406 begin
7407 -- If we are pointing at a positional parameter, it is a member of
7408 -- a node list (the list of parameters), and the next parameter
7409 -- is the next node on the list, unless we hit a parameter
7410 -- association, in which case we shift to using the chain whose
7411 -- head is the First_Named_Actual in the parent, and then is
7412 -- threaded using the Next_Named_Actual of the Parameter_Association.
7413 -- All this fiddling is because the original node list is in the
7414 -- textual call order, and what we need is the declaration order.
7416 if Is_List_Member (Actual_Id) then
7417 N := Next (Actual_Id);
7419 if Nkind (N) = N_Parameter_Association then
7420 return First_Named_Actual (Parent (Actual_Id));
7421 else
7422 return N;
7423 end if;
7425 else
7426 return Next_Named_Actual (Parent (Actual_Id));
7427 end if;
7428 end Next_Actual;
7430 procedure Next_Actual (Actual_Id : in out Node_Id) is
7431 begin
7432 Actual_Id := Next_Actual (Actual_Id);
7433 end Next_Actual;
7435 -----------------------
7436 -- Normalize_Actuals --
7437 -----------------------
7439 -- Chain actuals according to formals of subprogram. If there are no named
7440 -- associations, the chain is simply the list of Parameter Associations,
7441 -- since the order is the same as the declaration order. If there are named
7442 -- associations, then the First_Named_Actual field in the N_Function_Call
7443 -- or N_Procedure_Call_Statement node points to the Parameter_Association
7444 -- node for the parameter that comes first in declaration order. The
7445 -- remaining named parameters are then chained in declaration order using
7446 -- Next_Named_Actual.
7448 -- This routine also verifies that the number of actuals is compatible with
7449 -- the number and default values of formals, but performs no type checking
7450 -- (type checking is done by the caller).
7452 -- If the matching succeeds, Success is set to True and the caller proceeds
7453 -- with type-checking. If the match is unsuccessful, then Success is set to
7454 -- False, and the caller attempts a different interpretation, if there is
7455 -- one.
7457 -- If the flag Report is on, the call is not overloaded, and a failure to
7458 -- match can be reported here, rather than in the caller.
7460 procedure Normalize_Actuals
7461 (N : Node_Id;
7462 S : Entity_Id;
7463 Report : Boolean;
7464 Success : out Boolean)
7466 Actuals : constant List_Id := Parameter_Associations (N);
7467 Actual : Node_Id := Empty;
7468 Formal : Entity_Id;
7469 Last : Node_Id := Empty;
7470 First_Named : Node_Id := Empty;
7471 Found : Boolean;
7473 Formals_To_Match : Integer := 0;
7474 Actuals_To_Match : Integer := 0;
7476 procedure Chain (A : Node_Id);
7477 -- Add named actual at the proper place in the list, using the
7478 -- Next_Named_Actual link.
7480 function Reporting return Boolean;
7481 -- Determines if an error is to be reported. To report an error, we
7482 -- need Report to be True, and also we do not report errors caused
7483 -- by calls to init procs that occur within other init procs. Such
7484 -- errors must always be cascaded errors, since if all the types are
7485 -- declared correctly, the compiler will certainly build decent calls!
7487 -----------
7488 -- Chain --
7489 -----------
7491 procedure Chain (A : Node_Id) is
7492 begin
7493 if No (Last) then
7495 -- Call node points to first actual in list
7497 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
7499 else
7500 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
7501 end if;
7503 Last := A;
7504 Set_Next_Named_Actual (Last, Empty);
7505 end Chain;
7507 ---------------
7508 -- Reporting --
7509 ---------------
7511 function Reporting return Boolean is
7512 begin
7513 if not Report then
7514 return False;
7516 elsif not Within_Init_Proc then
7517 return True;
7519 elsif Is_Init_Proc (Entity (Name (N))) then
7520 return False;
7522 else
7523 return True;
7524 end if;
7525 end Reporting;
7527 -- Start of processing for Normalize_Actuals
7529 begin
7530 if Is_Access_Type (S) then
7532 -- The name in the call is a function call that returns an access
7533 -- to subprogram. The designated type has the list of formals.
7535 Formal := First_Formal (Designated_Type (S));
7536 else
7537 Formal := First_Formal (S);
7538 end if;
7540 while Present (Formal) loop
7541 Formals_To_Match := Formals_To_Match + 1;
7542 Next_Formal (Formal);
7543 end loop;
7545 -- Find if there is a named association, and verify that no positional
7546 -- associations appear after named ones.
7548 if Present (Actuals) then
7549 Actual := First (Actuals);
7550 end if;
7552 while Present (Actual)
7553 and then Nkind (Actual) /= N_Parameter_Association
7554 loop
7555 Actuals_To_Match := Actuals_To_Match + 1;
7556 Next (Actual);
7557 end loop;
7559 if No (Actual) and Actuals_To_Match = Formals_To_Match then
7561 -- Most common case: positional notation, no defaults
7563 Success := True;
7564 return;
7566 elsif Actuals_To_Match > Formals_To_Match then
7568 -- Too many actuals: will not work
7570 if Reporting then
7571 if Is_Entity_Name (Name (N)) then
7572 Error_Msg_N ("too many arguments in call to&", Name (N));
7573 else
7574 Error_Msg_N ("too many arguments in call", N);
7575 end if;
7576 end if;
7578 Success := False;
7579 return;
7580 end if;
7582 First_Named := Actual;
7584 while Present (Actual) loop
7585 if Nkind (Actual) /= N_Parameter_Association then
7586 Error_Msg_N
7587 ("positional parameters not allowed after named ones", Actual);
7588 Success := False;
7589 return;
7591 else
7592 Actuals_To_Match := Actuals_To_Match + 1;
7593 end if;
7595 Next (Actual);
7596 end loop;
7598 if Present (Actuals) then
7599 Actual := First (Actuals);
7600 end if;
7602 Formal := First_Formal (S);
7603 while Present (Formal) loop
7605 -- Match the formals in order. If the corresponding actual
7606 -- is positional, nothing to do. Else scan the list of named
7607 -- actuals to find the one with the right name.
7609 if Present (Actual)
7610 and then Nkind (Actual) /= N_Parameter_Association
7611 then
7612 Next (Actual);
7613 Actuals_To_Match := Actuals_To_Match - 1;
7614 Formals_To_Match := Formals_To_Match - 1;
7616 else
7617 -- For named parameters, search the list of actuals to find
7618 -- one that matches the next formal name.
7620 Actual := First_Named;
7621 Found := False;
7622 while Present (Actual) loop
7623 if Chars (Selector_Name (Actual)) = Chars (Formal) then
7624 Found := True;
7625 Chain (Actual);
7626 Actuals_To_Match := Actuals_To_Match - 1;
7627 Formals_To_Match := Formals_To_Match - 1;
7628 exit;
7629 end if;
7631 Next (Actual);
7632 end loop;
7634 if not Found then
7635 if Ekind (Formal) /= E_In_Parameter
7636 or else No (Default_Value (Formal))
7637 then
7638 if Reporting then
7639 if (Comes_From_Source (S)
7640 or else Sloc (S) = Standard_Location)
7641 and then Is_Overloadable (S)
7642 then
7643 if No (Actuals)
7644 and then
7645 (Nkind (Parent (N)) = N_Procedure_Call_Statement
7646 or else
7647 (Nkind (Parent (N)) = N_Function_Call
7648 or else
7649 Nkind (Parent (N)) = N_Parameter_Association))
7650 and then Ekind (S) /= E_Function
7651 then
7652 Set_Etype (N, Etype (S));
7653 else
7654 Error_Msg_Name_1 := Chars (S);
7655 Error_Msg_Sloc := Sloc (S);
7656 Error_Msg_NE
7657 ("missing argument for parameter & " &
7658 "in call to % declared #", N, Formal);
7659 end if;
7661 elsif Is_Overloadable (S) then
7662 Error_Msg_Name_1 := Chars (S);
7664 -- Point to type derivation that generated the
7665 -- operation.
7667 Error_Msg_Sloc := Sloc (Parent (S));
7669 Error_Msg_NE
7670 ("missing argument for parameter & " &
7671 "in call to % (inherited) #", N, Formal);
7673 else
7674 Error_Msg_NE
7675 ("missing argument for parameter &", N, Formal);
7676 end if;
7677 end if;
7679 Success := False;
7680 return;
7682 else
7683 Formals_To_Match := Formals_To_Match - 1;
7684 end if;
7685 end if;
7686 end if;
7688 Next_Formal (Formal);
7689 end loop;
7691 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
7692 Success := True;
7693 return;
7695 else
7696 if Reporting then
7698 -- Find some superfluous named actual that did not get
7699 -- attached to the list of associations.
7701 Actual := First (Actuals);
7702 while Present (Actual) loop
7703 if Nkind (Actual) = N_Parameter_Association
7704 and then Actual /= Last
7705 and then No (Next_Named_Actual (Actual))
7706 then
7707 Error_Msg_N ("unmatched actual & in call",
7708 Selector_Name (Actual));
7709 exit;
7710 end if;
7712 Next (Actual);
7713 end loop;
7714 end if;
7716 Success := False;
7717 return;
7718 end if;
7719 end Normalize_Actuals;
7721 --------------------------------
7722 -- Note_Possible_Modification --
7723 --------------------------------
7725 procedure Note_Possible_Modification (N : Node_Id) is
7726 Modification_Comes_From_Source : constant Boolean :=
7727 Comes_From_Source (Parent (N));
7729 Ent : Entity_Id;
7730 Exp : Node_Id;
7732 begin
7733 -- Loop to find referenced entity, if there is one
7735 Exp := N;
7736 loop
7737 <<Continue>>
7738 Ent := Empty;
7740 if Is_Entity_Name (Exp) then
7741 Ent := Entity (Exp);
7743 -- If the entity is missing, it is an undeclared identifier,
7744 -- and there is nothing to annotate.
7746 if No (Ent) then
7747 return;
7748 end if;
7750 elsif Nkind (Exp) = N_Explicit_Dereference then
7751 declare
7752 P : constant Node_Id := Prefix (Exp);
7754 begin
7755 if Nkind (P) = N_Selected_Component
7756 and then Present (
7757 Entry_Formal (Entity (Selector_Name (P))))
7758 then
7759 -- Case of a reference to an entry formal
7761 Ent := Entry_Formal (Entity (Selector_Name (P)));
7763 elsif Nkind (P) = N_Identifier
7764 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
7765 and then Present (Expression (Parent (Entity (P))))
7766 and then Nkind (Expression (Parent (Entity (P))))
7767 = N_Reference
7768 then
7769 -- Case of a reference to a value on which
7770 -- side effects have been removed.
7772 Exp := Prefix (Expression (Parent (Entity (P))));
7773 goto Continue;
7775 else
7776 return;
7778 end if;
7779 end;
7781 elsif Nkind (Exp) = N_Type_Conversion
7782 or else Nkind (Exp) = N_Unchecked_Type_Conversion
7783 then
7784 Exp := Expression (Exp);
7785 goto Continue;
7787 elsif Nkind (Exp) = N_Slice
7788 or else Nkind (Exp) = N_Indexed_Component
7789 or else Nkind (Exp) = N_Selected_Component
7790 then
7791 Exp := Prefix (Exp);
7792 goto Continue;
7794 else
7795 return;
7796 end if;
7798 -- Now look for entity being referenced
7800 if Present (Ent) then
7801 if Is_Object (Ent) then
7802 if Comes_From_Source (Exp)
7803 or else Modification_Comes_From_Source
7804 then
7805 Set_Never_Set_In_Source (Ent, False);
7806 end if;
7808 Set_Is_True_Constant (Ent, False);
7809 Set_Current_Value (Ent, Empty);
7810 Set_Is_Known_Null (Ent, False);
7812 if not Can_Never_Be_Null (Ent) then
7813 Set_Is_Known_Non_Null (Ent, False);
7814 end if;
7816 -- Follow renaming chain
7818 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
7819 and then Present (Renamed_Object (Ent))
7820 then
7821 Exp := Renamed_Object (Ent);
7822 goto Continue;
7823 end if;
7825 -- Generate a reference only if the assignment comes from
7826 -- source. This excludes, for example, calls to a dispatching
7827 -- assignment operation when the left-hand side is tagged.
7829 if Modification_Comes_From_Source then
7830 Generate_Reference (Ent, Exp, 'm');
7831 end if;
7833 Check_Nested_Access (Ent);
7834 end if;
7836 Kill_Checks (Ent);
7837 return;
7838 end if;
7839 end loop;
7840 end Note_Possible_Modification;
7842 -------------------------
7843 -- Object_Access_Level --
7844 -------------------------
7846 function Object_Access_Level (Obj : Node_Id) return Uint is
7847 E : Entity_Id;
7849 -- Returns the static accessibility level of the view denoted
7850 -- by Obj. Note that the value returned is the result of a
7851 -- call to Scope_Depth. Only scope depths associated with
7852 -- dynamic scopes can actually be returned. Since only
7853 -- relative levels matter for accessibility checking, the fact
7854 -- that the distance between successive levels of accessibility
7855 -- is not always one is immaterial (invariant: if level(E2) is
7856 -- deeper than level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
7858 function Reference_To (Obj : Node_Id) return Node_Id;
7859 -- An explicit dereference is created when removing side-effects
7860 -- from expressions for constraint checking purposes. In this case
7861 -- a local access type is created for it. The correct access level
7862 -- is that of the original source node. We detect this case by
7863 -- noting that the prefix of the dereference is created by an object
7864 -- declaration whose initial expression is a reference.
7866 ------------------
7867 -- Reference_To --
7868 ------------------
7870 function Reference_To (Obj : Node_Id) return Node_Id is
7871 Pref : constant Node_Id := Prefix (Obj);
7872 begin
7873 if Is_Entity_Name (Pref)
7874 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
7875 and then Present (Expression (Parent (Entity (Pref))))
7876 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
7877 then
7878 return (Prefix (Expression (Parent (Entity (Pref)))));
7879 else
7880 return Empty;
7881 end if;
7882 end Reference_To;
7884 -- Start of processing for Object_Access_Level
7886 begin
7887 if Is_Entity_Name (Obj) then
7888 E := Entity (Obj);
7890 -- If E is a type then it denotes a current instance.
7891 -- For this case we add one to the normal accessibility
7892 -- level of the type to ensure that current instances
7893 -- are treated as always being deeper than than the level
7894 -- of any visible named access type (see 3.10.2(21)).
7896 if Is_Type (E) then
7897 return Type_Access_Level (E) + 1;
7899 elsif Present (Renamed_Object (E)) then
7900 return Object_Access_Level (Renamed_Object (E));
7902 -- Similarly, if E is a component of the current instance of a
7903 -- protected type, any instance of it is assumed to be at a deeper
7904 -- level than the type. For a protected object (whose type is an
7905 -- anonymous protected type) its components are at the same level
7906 -- as the type itself.
7908 elsif not Is_Overloadable (E)
7909 and then Ekind (Scope (E)) = E_Protected_Type
7910 and then Comes_From_Source (Scope (E))
7911 then
7912 return Type_Access_Level (Scope (E)) + 1;
7914 else
7915 return Scope_Depth (Enclosing_Dynamic_Scope (E));
7916 end if;
7918 elsif Nkind (Obj) = N_Selected_Component then
7919 if Is_Access_Type (Etype (Prefix (Obj))) then
7920 return Type_Access_Level (Etype (Prefix (Obj)));
7921 else
7922 return Object_Access_Level (Prefix (Obj));
7923 end if;
7925 elsif Nkind (Obj) = N_Indexed_Component then
7926 if Is_Access_Type (Etype (Prefix (Obj))) then
7927 return Type_Access_Level (Etype (Prefix (Obj)));
7928 else
7929 return Object_Access_Level (Prefix (Obj));
7930 end if;
7932 elsif Nkind (Obj) = N_Explicit_Dereference then
7934 -- If the prefix is a selected access discriminant then
7935 -- we make a recursive call on the prefix, which will
7936 -- in turn check the level of the prefix object of
7937 -- the selected discriminant.
7939 if Nkind (Prefix (Obj)) = N_Selected_Component
7940 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
7941 and then
7942 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
7943 then
7944 return Object_Access_Level (Prefix (Obj));
7946 elsif not (Comes_From_Source (Obj)) then
7947 declare
7948 Ref : constant Node_Id := Reference_To (Obj);
7949 begin
7950 if Present (Ref) then
7951 return Object_Access_Level (Ref);
7952 else
7953 return Type_Access_Level (Etype (Prefix (Obj)));
7954 end if;
7955 end;
7957 else
7958 return Type_Access_Level (Etype (Prefix (Obj)));
7959 end if;
7961 elsif Nkind (Obj) = N_Type_Conversion
7962 or else Nkind (Obj) = N_Unchecked_Type_Conversion
7963 then
7964 return Object_Access_Level (Expression (Obj));
7966 -- Function results are objects, so we get either the access level
7967 -- of the function or, in the case of an indirect call, the level of
7968 -- of the access-to-subprogram type.
7970 elsif Nkind (Obj) = N_Function_Call then
7971 if Is_Entity_Name (Name (Obj)) then
7972 return Subprogram_Access_Level (Entity (Name (Obj)));
7973 else
7974 return Type_Access_Level (Etype (Prefix (Name (Obj))));
7975 end if;
7977 -- For convenience we handle qualified expressions, even though
7978 -- they aren't technically object names.
7980 elsif Nkind (Obj) = N_Qualified_Expression then
7981 return Object_Access_Level (Expression (Obj));
7983 -- Otherwise return the scope level of Standard.
7984 -- (If there are cases that fall through
7985 -- to this point they will be treated as
7986 -- having global accessibility for now. ???)
7988 else
7989 return Scope_Depth (Standard_Standard);
7990 end if;
7991 end Object_Access_Level;
7993 -----------------------
7994 -- Private_Component --
7995 -----------------------
7997 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
7998 Ancestor : constant Entity_Id := Base_Type (Type_Id);
8000 function Trace_Components
8001 (T : Entity_Id;
8002 Check : Boolean) return Entity_Id;
8003 -- Recursive function that does the work, and checks against circular
8004 -- definition for each subcomponent type.
8006 ----------------------
8007 -- Trace_Components --
8008 ----------------------
8010 function Trace_Components
8011 (T : Entity_Id;
8012 Check : Boolean) return Entity_Id
8014 Btype : constant Entity_Id := Base_Type (T);
8015 Component : Entity_Id;
8016 P : Entity_Id;
8017 Candidate : Entity_Id := Empty;
8019 begin
8020 if Check and then Btype = Ancestor then
8021 Error_Msg_N ("circular type definition", Type_Id);
8022 return Any_Type;
8023 end if;
8025 if Is_Private_Type (Btype)
8026 and then not Is_Generic_Type (Btype)
8027 then
8028 if Present (Full_View (Btype))
8029 and then Is_Record_Type (Full_View (Btype))
8030 and then not Is_Frozen (Btype)
8031 then
8032 -- To indicate that the ancestor depends on a private type,
8033 -- the current Btype is sufficient. However, to check for
8034 -- circular definition we must recurse on the full view.
8036 Candidate := Trace_Components (Full_View (Btype), True);
8038 if Candidate = Any_Type then
8039 return Any_Type;
8040 else
8041 return Btype;
8042 end if;
8044 else
8045 return Btype;
8046 end if;
8048 elsif Is_Array_Type (Btype) then
8049 return Trace_Components (Component_Type (Btype), True);
8051 elsif Is_Record_Type (Btype) then
8052 Component := First_Entity (Btype);
8053 while Present (Component) loop
8055 -- Skip anonymous types generated by constrained components
8057 if not Is_Type (Component) then
8058 P := Trace_Components (Etype (Component), True);
8060 if Present (P) then
8061 if P = Any_Type then
8062 return P;
8063 else
8064 Candidate := P;
8065 end if;
8066 end if;
8067 end if;
8069 Next_Entity (Component);
8070 end loop;
8072 return Candidate;
8074 else
8075 return Empty;
8076 end if;
8077 end Trace_Components;
8079 -- Start of processing for Private_Component
8081 begin
8082 return Trace_Components (Type_Id, False);
8083 end Private_Component;
8085 -----------------------
8086 -- Process_End_Label --
8087 -----------------------
8089 procedure Process_End_Label
8090 (N : Node_Id;
8091 Typ : Character;
8092 Ent : Entity_Id)
8094 Loc : Source_Ptr;
8095 Nam : Node_Id;
8097 Label_Ref : Boolean;
8098 -- Set True if reference to end label itself is required
8100 Endl : Node_Id;
8101 -- Gets set to the operator symbol or identifier that references
8102 -- the entity Ent. For the child unit case, this is the identifier
8103 -- from the designator. For other cases, this is simply Endl.
8105 procedure Generate_Parent_Ref (N : Node_Id);
8106 -- N is an identifier node that appears as a parent unit reference
8107 -- in the case where Ent is a child unit. This procedure generates
8108 -- an appropriate cross-reference entry.
8110 -------------------------
8111 -- Generate_Parent_Ref --
8112 -------------------------
8114 procedure Generate_Parent_Ref (N : Node_Id) is
8115 Parent_Ent : Entity_Id;
8117 begin
8118 -- Search up scope stack. The reason we do this is that normal
8119 -- visibility analysis would not work for two reasons. First in
8120 -- some subunit cases, the entry for the parent unit may not be
8121 -- visible, and in any case there can be a local entity that
8122 -- hides the scope entity.
8124 Parent_Ent := Current_Scope;
8125 while Present (Parent_Ent) loop
8126 if Chars (Parent_Ent) = Chars (N) then
8128 -- Generate the reference. We do NOT consider this as a
8129 -- reference for unreferenced symbol purposes, but we do
8130 -- force a cross-reference even if the end line does not
8131 -- come from source (the caller already generated the
8132 -- appropriate Typ for this situation).
8134 Generate_Reference
8135 (Parent_Ent, N, 'r', Set_Ref => False, Force => True);
8136 Style.Check_Identifier (N, Parent_Ent);
8137 return;
8138 end if;
8140 Parent_Ent := Scope (Parent_Ent);
8141 end loop;
8143 -- Fall through means entity was not found -- that's odd, but
8144 -- the appropriate thing is simply to ignore and not generate
8145 -- any cross-reference for this entry.
8147 return;
8148 end Generate_Parent_Ref;
8150 -- Start of processing for Process_End_Label
8152 begin
8153 -- If no node, ignore. This happens in some error situations,
8154 -- and also for some internally generated structures where no
8155 -- end label references are required in any case.
8157 if No (N) then
8158 return;
8159 end if;
8161 -- Nothing to do if no End_Label, happens for internally generated
8162 -- constructs where we don't want an end label reference anyway.
8163 -- Also nothing to do if Endl is a string literal, which means
8164 -- there was some prior error (bad operator symbol)
8166 Endl := End_Label (N);
8168 if No (Endl) or else Nkind (Endl) = N_String_Literal then
8169 return;
8170 end if;
8172 -- Reference node is not in extended main source unit
8174 if not In_Extended_Main_Source_Unit (N) then
8176 -- Generally we do not collect references except for the
8177 -- extended main source unit. The one exception is the 'e'
8178 -- entry for a package spec, where it is useful for a client
8179 -- to have the ending information to define scopes.
8181 if Typ /= 'e' then
8182 return;
8184 else
8185 Label_Ref := False;
8187 -- For this case, we can ignore any parent references,
8188 -- but we need the package name itself for the 'e' entry.
8190 if Nkind (Endl) = N_Designator then
8191 Endl := Identifier (Endl);
8192 end if;
8193 end if;
8195 -- Reference is in extended main source unit
8197 else
8198 Label_Ref := True;
8200 -- For designator, generate references for the parent entries
8202 if Nkind (Endl) = N_Designator then
8204 -- Generate references for the prefix if the END line comes
8205 -- from source (otherwise we do not need these references)
8207 if Comes_From_Source (Endl) then
8208 Nam := Name (Endl);
8209 while Nkind (Nam) = N_Selected_Component loop
8210 Generate_Parent_Ref (Selector_Name (Nam));
8211 Nam := Prefix (Nam);
8212 end loop;
8214 Generate_Parent_Ref (Nam);
8215 end if;
8217 Endl := Identifier (Endl);
8218 end if;
8219 end if;
8221 -- If the end label is not for the given entity, then either we have
8222 -- some previous error, or this is a generic instantiation for which
8223 -- we do not need to make a cross-reference in this case anyway. In
8224 -- either case we simply ignore the call.
8226 if Chars (Ent) /= Chars (Endl) then
8227 return;
8228 end if;
8230 -- If label was really there, then generate a normal reference
8231 -- and then adjust the location in the end label to point past
8232 -- the name (which should almost always be the semicolon).
8234 Loc := Sloc (Endl);
8236 if Comes_From_Source (Endl) then
8238 -- If a label reference is required, then do the style check
8239 -- and generate an l-type cross-reference entry for the label
8241 if Label_Ref then
8242 if Style_Check then
8243 Style.Check_Identifier (Endl, Ent);
8244 end if;
8245 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
8246 end if;
8248 -- Set the location to point past the label (normally this will
8249 -- mean the semicolon immediately following the label). This is
8250 -- done for the sake of the 'e' or 't' entry generated below.
8252 Get_Decoded_Name_String (Chars (Endl));
8253 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
8254 end if;
8256 -- Now generate the e/t reference
8258 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
8260 -- Restore Sloc, in case modified above, since we have an identifier
8261 -- and the normal Sloc should be left set in the tree.
8263 Set_Sloc (Endl, Loc);
8264 end Process_End_Label;
8266 ------------------
8267 -- Real_Convert --
8268 ------------------
8270 -- We do the conversion to get the value of the real string by using
8271 -- the scanner, see Sinput for details on use of the internal source
8272 -- buffer for scanning internal strings.
8274 function Real_Convert (S : String) return Node_Id is
8275 Save_Src : constant Source_Buffer_Ptr := Source;
8276 Negative : Boolean;
8278 begin
8279 Source := Internal_Source_Ptr;
8280 Scan_Ptr := 1;
8282 for J in S'Range loop
8283 Source (Source_Ptr (J)) := S (J);
8284 end loop;
8286 Source (S'Length + 1) := EOF;
8288 if Source (Scan_Ptr) = '-' then
8289 Negative := True;
8290 Scan_Ptr := Scan_Ptr + 1;
8291 else
8292 Negative := False;
8293 end if;
8295 Scan;
8297 if Negative then
8298 Set_Realval (Token_Node, UR_Negate (Realval (Token_Node)));
8299 end if;
8301 Source := Save_Src;
8302 return Token_Node;
8303 end Real_Convert;
8305 ---------------------
8306 -- Rep_To_Pos_Flag --
8307 ---------------------
8309 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
8310 begin
8311 return New_Occurrence_Of
8312 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
8313 end Rep_To_Pos_Flag;
8315 --------------------
8316 -- Require_Entity --
8317 --------------------
8319 procedure Require_Entity (N : Node_Id) is
8320 begin
8321 if Is_Entity_Name (N) and then No (Entity (N)) then
8322 if Total_Errors_Detected /= 0 then
8323 Set_Entity (N, Any_Id);
8324 else
8325 raise Program_Error;
8326 end if;
8327 end if;
8328 end Require_Entity;
8330 ------------------------------
8331 -- Requires_Transient_Scope --
8332 ------------------------------
8334 -- A transient scope is required when variable-sized temporaries are
8335 -- allocated in the primary or secondary stack, or when finalization
8336 -- actions must be generated before the next instruction.
8338 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
8339 Typ : constant Entity_Id := Underlying_Type (Id);
8341 -- Start of processing for Requires_Transient_Scope
8343 begin
8344 -- This is a private type which is not completed yet. This can only
8345 -- happen in a default expression (of a formal parameter or of a
8346 -- record component). Do not expand transient scope in this case
8348 if No (Typ) then
8349 return False;
8351 -- Do not expand transient scope for non-existent procedure return
8353 elsif Typ = Standard_Void_Type then
8354 return False;
8356 -- Elementary types do not require a transient scope
8358 elsif Is_Elementary_Type (Typ) then
8359 return False;
8361 -- Generally, indefinite subtypes require a transient scope, since the
8362 -- back end cannot generate temporaries, since this is not a valid type
8363 -- for declaring an object. It might be possible to relax this in the
8364 -- future, e.g. by declaring the maximum possible space for the type.
8366 elsif Is_Indefinite_Subtype (Typ) then
8367 return True;
8369 -- Functions returning tagged types may dispatch on result so their
8370 -- returned value is allocated on the secondary stack. Controlled
8371 -- type temporaries need finalization.
8373 elsif Is_Tagged_Type (Typ)
8374 or else Has_Controlled_Component (Typ)
8375 then
8376 return not Is_Value_Type (Typ);
8378 -- Record type
8380 elsif Is_Record_Type (Typ) then
8381 declare
8382 Comp : Entity_Id;
8383 begin
8384 Comp := First_Entity (Typ);
8385 while Present (Comp) loop
8386 if Ekind (Comp) = E_Component
8387 and then Requires_Transient_Scope (Etype (Comp))
8388 then
8389 return True;
8390 else
8391 Next_Entity (Comp);
8392 end if;
8393 end loop;
8394 end;
8396 return False;
8398 -- String literal types never require transient scope
8400 elsif Ekind (Typ) = E_String_Literal_Subtype then
8401 return False;
8403 -- Array type. Note that we already know that this is a constrained
8404 -- array, since unconstrained arrays will fail the indefinite test.
8406 elsif Is_Array_Type (Typ) then
8408 -- If component type requires a transient scope, the array does too
8410 if Requires_Transient_Scope (Component_Type (Typ)) then
8411 return True;
8413 -- Otherwise, we only need a transient scope if the size is not
8414 -- known at compile time.
8416 else
8417 return not Size_Known_At_Compile_Time (Typ);
8418 end if;
8420 -- All other cases do not require a transient scope
8422 else
8423 return False;
8424 end if;
8425 end Requires_Transient_Scope;
8427 --------------------------
8428 -- Reset_Analyzed_Flags --
8429 --------------------------
8431 procedure Reset_Analyzed_Flags (N : Node_Id) is
8433 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
8434 -- Function used to reset Analyzed flags in tree. Note that we do
8435 -- not reset Analyzed flags in entities, since there is no need to
8436 -- renalalyze entities, and indeed, it is wrong to do so, since it
8437 -- can result in generating auxiliary stuff more than once.
8439 --------------------
8440 -- Clear_Analyzed --
8441 --------------------
8443 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
8444 begin
8445 if not Has_Extension (N) then
8446 Set_Analyzed (N, False);
8447 end if;
8449 return OK;
8450 end Clear_Analyzed;
8452 function Reset_Analyzed is
8453 new Traverse_Func (Clear_Analyzed);
8455 Discard : Traverse_Result;
8456 pragma Warnings (Off, Discard);
8458 -- Start of processing for Reset_Analyzed_Flags
8460 begin
8461 Discard := Reset_Analyzed (N);
8462 end Reset_Analyzed_Flags;
8464 ---------------------------
8465 -- Safe_To_Capture_Value --
8466 ---------------------------
8468 function Safe_To_Capture_Value
8469 (N : Node_Id;
8470 Ent : Entity_Id;
8471 Cond : Boolean := False) return Boolean
8473 begin
8474 -- The only entities for which we track constant values are variables
8475 -- which are not renamings, constants, out parameters, and in out
8476 -- parameters, so check if we have this case.
8478 -- Note: it may seem odd to track constant values for constants, but in
8479 -- fact this routine is used for other purposes than simply capturing
8480 -- the value. In particular, the setting of Known[_Non]_Null.
8482 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
8483 or else
8484 Ekind (Ent) = E_Constant
8485 or else
8486 Ekind (Ent) = E_Out_Parameter
8487 or else
8488 Ekind (Ent) = E_In_Out_Parameter
8489 then
8490 null;
8492 -- For conditionals, we also allow loop parameters and all formals,
8493 -- including in parameters.
8495 elsif Cond
8496 and then
8497 (Ekind (Ent) = E_Loop_Parameter
8498 or else
8499 Ekind (Ent) = E_In_Parameter)
8500 then
8501 null;
8503 -- For all other cases, not just unsafe, but impossible to capture
8504 -- Current_Value, since the above are the only entities which have
8505 -- Current_Value fields.
8507 else
8508 return False;
8509 end if;
8511 -- Skip if volatile or aliased, since funny things might be going on in
8512 -- these cases which we cannot necessarily track. Also skip any variable
8513 -- for which an address clause is given, or whose address is taken.
8515 if Treat_As_Volatile (Ent)
8516 or else Is_Aliased (Ent)
8517 or else Present (Address_Clause (Ent))
8518 or else Address_Taken (Ent)
8519 then
8520 return False;
8521 end if;
8523 -- OK, all above conditions are met. We also require that the scope of
8524 -- the reference be the same as the scope of the entity, not counting
8525 -- packages and blocks and loops.
8527 declare
8528 E_Scope : constant Entity_Id := Scope (Ent);
8529 R_Scope : Entity_Id;
8531 begin
8532 R_Scope := Current_Scope;
8533 while R_Scope /= Standard_Standard loop
8534 exit when R_Scope = E_Scope;
8536 if Ekind (R_Scope) /= E_Package
8537 and then
8538 Ekind (R_Scope) /= E_Block
8539 and then
8540 Ekind (R_Scope) /= E_Loop
8541 then
8542 return False;
8543 else
8544 R_Scope := Scope (R_Scope);
8545 end if;
8546 end loop;
8547 end;
8549 -- We also require that the reference does not appear in a context
8550 -- where it is not sure to be executed (i.e. a conditional context
8551 -- or an exception handler). We skip this if Cond is True, since the
8552 -- capturing of values from conditional tests handles this ok.
8554 if Cond then
8555 return True;
8556 end if;
8558 declare
8559 Desc : Node_Id;
8560 P : Node_Id;
8562 begin
8563 Desc := N;
8565 P := Parent (N);
8566 while Present (P) loop
8567 if Nkind (P) = N_If_Statement
8568 or else Nkind (P) = N_Case_Statement
8569 or else (Nkind (P) = N_And_Then and then Desc = Right_Opnd (P))
8570 or else (Nkind (P) = N_Or_Else and then Desc = Right_Opnd (P))
8571 or else Nkind (P) = N_Exception_Handler
8572 or else Nkind (P) = N_Selective_Accept
8573 or else Nkind (P) = N_Conditional_Entry_Call
8574 or else Nkind (P) = N_Timed_Entry_Call
8575 or else Nkind (P) = N_Asynchronous_Select
8576 then
8577 return False;
8578 else
8579 Desc := P;
8580 P := Parent (P);
8581 end if;
8582 end loop;
8583 end;
8585 -- OK, looks safe to set value
8587 return True;
8588 end Safe_To_Capture_Value;
8590 ---------------
8591 -- Same_Name --
8592 ---------------
8594 function Same_Name (N1, N2 : Node_Id) return Boolean is
8595 K1 : constant Node_Kind := Nkind (N1);
8596 K2 : constant Node_Kind := Nkind (N2);
8598 begin
8599 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
8600 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
8601 then
8602 return Chars (N1) = Chars (N2);
8604 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
8605 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
8606 then
8607 return Same_Name (Selector_Name (N1), Selector_Name (N2))
8608 and then Same_Name (Prefix (N1), Prefix (N2));
8610 else
8611 return False;
8612 end if;
8613 end Same_Name;
8615 -----------------
8616 -- Same_Object --
8617 -----------------
8619 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
8620 N1 : constant Node_Id := Original_Node (Node1);
8621 N2 : constant Node_Id := Original_Node (Node2);
8622 -- We do the tests on original nodes, since we are most interested
8623 -- in the original source, not any expansion that got in the way.
8625 K1 : constant Node_Kind := Nkind (N1);
8626 K2 : constant Node_Kind := Nkind (N2);
8628 begin
8629 -- First case, both are entities with same entity
8631 if K1 in N_Has_Entity
8632 and then K2 in N_Has_Entity
8633 and then Present (Entity (N1))
8634 and then Present (Entity (N2))
8635 and then (Ekind (Entity (N1)) = E_Variable
8636 or else
8637 Ekind (Entity (N1)) = E_Constant)
8638 and then Entity (N1) = Entity (N2)
8639 then
8640 return True;
8642 -- Second case, selected component with same selector, same record
8644 elsif K1 = N_Selected_Component
8645 and then K2 = N_Selected_Component
8646 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
8647 then
8648 return Same_Object (Prefix (N1), Prefix (N2));
8650 -- Third case, indexed component with same subscripts, same array
8652 elsif K1 = N_Indexed_Component
8653 and then K2 = N_Indexed_Component
8654 and then Same_Object (Prefix (N1), Prefix (N2))
8655 then
8656 declare
8657 E1, E2 : Node_Id;
8658 begin
8659 E1 := First (Expressions (N1));
8660 E2 := First (Expressions (N2));
8661 while Present (E1) loop
8662 if not Same_Value (E1, E2) then
8663 return False;
8664 else
8665 Next (E1);
8666 Next (E2);
8667 end if;
8668 end loop;
8670 return True;
8671 end;
8673 -- Fourth case, slice of same array with same bounds
8675 elsif K1 = N_Slice
8676 and then K2 = N_Slice
8677 and then Nkind (Discrete_Range (N1)) = N_Range
8678 and then Nkind (Discrete_Range (N2)) = N_Range
8679 and then Same_Value (Low_Bound (Discrete_Range (N1)),
8680 Low_Bound (Discrete_Range (N2)))
8681 and then Same_Value (High_Bound (Discrete_Range (N1)),
8682 High_Bound (Discrete_Range (N2)))
8683 then
8684 return Same_Name (Prefix (N1), Prefix (N2));
8686 -- All other cases, not clearly the same object
8688 else
8689 return False;
8690 end if;
8691 end Same_Object;
8693 ---------------
8694 -- Same_Type --
8695 ---------------
8697 function Same_Type (T1, T2 : Entity_Id) return Boolean is
8698 begin
8699 if T1 = T2 then
8700 return True;
8702 elsif not Is_Constrained (T1)
8703 and then not Is_Constrained (T2)
8704 and then Base_Type (T1) = Base_Type (T2)
8705 then
8706 return True;
8708 -- For now don't bother with case of identical constraints, to be
8709 -- fiddled with later on perhaps (this is only used for optimization
8710 -- purposes, so it is not critical to do a best possible job)
8712 else
8713 return False;
8714 end if;
8715 end Same_Type;
8717 ----------------
8718 -- Same_Value --
8719 ----------------
8721 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
8722 begin
8723 if Compile_Time_Known_Value (Node1)
8724 and then Compile_Time_Known_Value (Node2)
8725 and then Expr_Value (Node1) = Expr_Value (Node2)
8726 then
8727 return True;
8728 elsif Same_Object (Node1, Node2) then
8729 return True;
8730 else
8731 return False;
8732 end if;
8733 end Same_Value;
8735 ------------------------
8736 -- Scope_Is_Transient --
8737 ------------------------
8739 function Scope_Is_Transient return Boolean is
8740 begin
8741 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
8742 end Scope_Is_Transient;
8744 ------------------
8745 -- Scope_Within --
8746 ------------------
8748 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
8749 Scop : Entity_Id;
8751 begin
8752 Scop := Scope1;
8753 while Scop /= Standard_Standard loop
8754 Scop := Scope (Scop);
8756 if Scop = Scope2 then
8757 return True;
8758 end if;
8759 end loop;
8761 return False;
8762 end Scope_Within;
8764 --------------------------
8765 -- Scope_Within_Or_Same --
8766 --------------------------
8768 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
8769 Scop : Entity_Id;
8771 begin
8772 Scop := Scope1;
8773 while Scop /= Standard_Standard loop
8774 if Scop = Scope2 then
8775 return True;
8776 else
8777 Scop := Scope (Scop);
8778 end if;
8779 end loop;
8781 return False;
8782 end Scope_Within_Or_Same;
8784 ------------------------
8785 -- Set_Current_Entity --
8786 ------------------------
8788 -- The given entity is to be set as the currently visible definition
8789 -- of its associated name (i.e. the Node_Id associated with its name).
8790 -- All we have to do is to get the name from the identifier, and
8791 -- then set the associated Node_Id to point to the given entity.
8793 procedure Set_Current_Entity (E : Entity_Id) is
8794 begin
8795 Set_Name_Entity_Id (Chars (E), E);
8796 end Set_Current_Entity;
8798 ---------------------------------
8799 -- Set_Entity_With_Style_Check --
8800 ---------------------------------
8802 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
8803 Val_Actual : Entity_Id;
8804 Nod : Node_Id;
8806 begin
8807 Set_Entity (N, Val);
8809 if Style_Check
8810 and then not Suppress_Style_Checks (Val)
8811 and then not In_Instance
8812 then
8813 if Nkind (N) = N_Identifier then
8814 Nod := N;
8815 elsif Nkind (N) = N_Expanded_Name then
8816 Nod := Selector_Name (N);
8817 else
8818 return;
8819 end if;
8821 -- A special situation arises for derived operations, where we want
8822 -- to do the check against the parent (since the Sloc of the derived
8823 -- operation points to the derived type declaration itself).
8825 Val_Actual := Val;
8826 while not Comes_From_Source (Val_Actual)
8827 and then Nkind (Val_Actual) in N_Entity
8828 and then (Ekind (Val_Actual) = E_Enumeration_Literal
8829 or else Is_Subprogram (Val_Actual)
8830 or else Is_Generic_Subprogram (Val_Actual))
8831 and then Present (Alias (Val_Actual))
8832 loop
8833 Val_Actual := Alias (Val_Actual);
8834 end loop;
8836 -- Renaming declarations for generic actuals do not come from source,
8837 -- and have a different name from that of the entity they rename, so
8838 -- there is no style check to perform here.
8840 if Chars (Nod) = Chars (Val_Actual) then
8841 Style.Check_Identifier (Nod, Val_Actual);
8842 end if;
8843 end if;
8845 Set_Entity (N, Val);
8846 end Set_Entity_With_Style_Check;
8848 ------------------------
8849 -- Set_Name_Entity_Id --
8850 ------------------------
8852 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
8853 begin
8854 Set_Name_Table_Info (Id, Int (Val));
8855 end Set_Name_Entity_Id;
8857 ---------------------
8858 -- Set_Next_Actual --
8859 ---------------------
8861 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
8862 begin
8863 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
8864 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
8865 end if;
8866 end Set_Next_Actual;
8868 -----------------------
8869 -- Set_Public_Status --
8870 -----------------------
8872 procedure Set_Public_Status (Id : Entity_Id) is
8873 S : constant Entity_Id := Current_Scope;
8875 begin
8876 -- Everything in the scope of Standard is public
8878 if S = Standard_Standard then
8879 Set_Is_Public (Id);
8881 -- Entity is definitely not public if enclosing scope is not public
8883 elsif not Is_Public (S) then
8884 return;
8886 -- An object declaration that occurs in a handled sequence of statements
8887 -- is the declaration for a temporary object generated by the expander.
8888 -- It never needs to be made public and furthermore, making it public
8889 -- can cause back end problems if it is of variable size.
8891 elsif Nkind (Parent (Id)) = N_Object_Declaration
8892 and then
8893 Nkind (Parent (Parent (Id))) = N_Handled_Sequence_Of_Statements
8894 then
8895 return;
8897 -- Entities in public packages or records are public
8899 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
8900 Set_Is_Public (Id);
8902 -- The bounds of an entry family declaration can generate object
8903 -- declarations that are visible to the back-end, e.g. in the
8904 -- the declaration of a composite type that contains tasks.
8906 elsif Is_Concurrent_Type (S)
8907 and then not Has_Completion (S)
8908 and then Nkind (Parent (Id)) = N_Object_Declaration
8909 then
8910 Set_Is_Public (Id);
8911 end if;
8912 end Set_Public_Status;
8914 ----------------------------
8915 -- Set_Scope_Is_Transient --
8916 ----------------------------
8918 procedure Set_Scope_Is_Transient (V : Boolean := True) is
8919 begin
8920 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
8921 end Set_Scope_Is_Transient;
8923 -------------------
8924 -- Set_Size_Info --
8925 -------------------
8927 procedure Set_Size_Info (T1, T2 : Entity_Id) is
8928 begin
8929 -- We copy Esize, but not RM_Size, since in general RM_Size is
8930 -- subtype specific and does not get inherited by all subtypes.
8932 Set_Esize (T1, Esize (T2));
8933 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
8935 if Is_Discrete_Or_Fixed_Point_Type (T1)
8936 and then
8937 Is_Discrete_Or_Fixed_Point_Type (T2)
8938 then
8939 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
8940 end if;
8942 Set_Alignment (T1, Alignment (T2));
8943 end Set_Size_Info;
8945 --------------------
8946 -- Static_Integer --
8947 --------------------
8949 function Static_Integer (N : Node_Id) return Uint is
8950 begin
8951 Analyze_And_Resolve (N, Any_Integer);
8953 if N = Error
8954 or else Error_Posted (N)
8955 or else Etype (N) = Any_Type
8956 then
8957 return No_Uint;
8958 end if;
8960 if Is_Static_Expression (N) then
8961 if not Raises_Constraint_Error (N) then
8962 return Expr_Value (N);
8963 else
8964 return No_Uint;
8965 end if;
8967 elsif Etype (N) = Any_Type then
8968 return No_Uint;
8970 else
8971 Flag_Non_Static_Expr
8972 ("static integer expression required here", N);
8973 return No_Uint;
8974 end if;
8975 end Static_Integer;
8977 --------------------------
8978 -- Statically_Different --
8979 --------------------------
8981 function Statically_Different (E1, E2 : Node_Id) return Boolean is
8982 R1 : constant Node_Id := Get_Referenced_Object (E1);
8983 R2 : constant Node_Id := Get_Referenced_Object (E2);
8984 begin
8985 return Is_Entity_Name (R1)
8986 and then Is_Entity_Name (R2)
8987 and then Entity (R1) /= Entity (R2)
8988 and then not Is_Formal (Entity (R1))
8989 and then not Is_Formal (Entity (R2));
8990 end Statically_Different;
8992 -----------------------------
8993 -- Subprogram_Access_Level --
8994 -----------------------------
8996 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
8997 begin
8998 if Present (Alias (Subp)) then
8999 return Subprogram_Access_Level (Alias (Subp));
9000 else
9001 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
9002 end if;
9003 end Subprogram_Access_Level;
9005 -----------------
9006 -- Trace_Scope --
9007 -----------------
9009 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
9010 begin
9011 if Debug_Flag_W then
9012 for J in 0 .. Scope_Stack.Last loop
9013 Write_Str (" ");
9014 end loop;
9016 Write_Str (Msg);
9017 Write_Name (Chars (E));
9018 Write_Str (" line ");
9019 Write_Int (Int (Get_Logical_Line_Number (Sloc (N))));
9020 Write_Eol;
9021 end if;
9022 end Trace_Scope;
9024 -----------------------
9025 -- Transfer_Entities --
9026 -----------------------
9028 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
9029 Ent : Entity_Id := First_Entity (From);
9031 begin
9032 if No (Ent) then
9033 return;
9034 end if;
9036 if (Last_Entity (To)) = Empty then
9037 Set_First_Entity (To, Ent);
9038 else
9039 Set_Next_Entity (Last_Entity (To), Ent);
9040 end if;
9042 Set_Last_Entity (To, Last_Entity (From));
9044 while Present (Ent) loop
9045 Set_Scope (Ent, To);
9047 if not Is_Public (Ent) then
9048 Set_Public_Status (Ent);
9050 if Is_Public (Ent)
9051 and then Ekind (Ent) = E_Record_Subtype
9053 then
9054 -- The components of the propagated Itype must be public
9055 -- as well.
9057 declare
9058 Comp : Entity_Id;
9059 begin
9060 Comp := First_Entity (Ent);
9061 while Present (Comp) loop
9062 Set_Is_Public (Comp);
9063 Next_Entity (Comp);
9064 end loop;
9065 end;
9066 end if;
9067 end if;
9069 Next_Entity (Ent);
9070 end loop;
9072 Set_First_Entity (From, Empty);
9073 Set_Last_Entity (From, Empty);
9074 end Transfer_Entities;
9076 -----------------------
9077 -- Type_Access_Level --
9078 -----------------------
9080 function Type_Access_Level (Typ : Entity_Id) return Uint is
9081 Btyp : Entity_Id;
9083 begin
9084 Btyp := Base_Type (Typ);
9086 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
9087 -- simply use the level where the type is declared. This is true for
9088 -- stand-alone object declarations, and for anonymous access types
9089 -- associated with components the level is the same as that of the
9090 -- enclosing composite type. However, special treatment is needed for
9091 -- the cases of access parameters, return objects of an anonymous access
9092 -- type, and, in Ada 95, access discriminants of limited types.
9094 if Ekind (Btyp) in Access_Kind then
9095 if Ekind (Btyp) = E_Anonymous_Access_Type then
9097 -- If the type is a nonlocal anonymous access type (such as for
9098 -- an access parameter) we treat it as being declared at the
9099 -- library level to ensure that names such as X.all'access don't
9100 -- fail static accessibility checks.
9102 if not Is_Local_Anonymous_Access (Typ) then
9103 return Scope_Depth (Standard_Standard);
9105 -- If this is a return object, the accessibility level is that of
9106 -- the result subtype of the enclosing function. The test here is
9107 -- little complicated, because we have to account for extended
9108 -- return statements that have been rewritten as blocks, in which
9109 -- case we have to find and the Is_Return_Object attribute of the
9110 -- itype's associated object. It would be nice to find a way to
9111 -- simplify this test, but it doesn't seem worthwhile to add a new
9112 -- flag just for purposes of this test. ???
9114 elsif Ekind (Scope (Btyp)) = E_Return_Statement
9115 or else
9116 (Is_Itype (Btyp)
9117 and then Nkind (Associated_Node_For_Itype (Btyp)) =
9118 N_Object_Declaration
9119 and then Is_Return_Object
9120 (Defining_Identifier
9121 (Associated_Node_For_Itype (Btyp))))
9122 then
9123 declare
9124 Scop : Entity_Id;
9126 begin
9127 Scop := Scope (Scope (Btyp));
9128 while Present (Scop) loop
9129 exit when Ekind (Scop) = E_Function;
9130 Scop := Scope (Scop);
9131 end loop;
9133 -- Treat the return object's type as having the level of the
9134 -- function's result subtype (as per RM05-6.5(5.3/2)).
9136 return Type_Access_Level (Etype (Scop));
9137 end;
9138 end if;
9139 end if;
9141 Btyp := Root_Type (Btyp);
9143 -- The accessibility level of anonymous acccess types associated with
9144 -- discriminants is that of the current instance of the type, and
9145 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
9147 -- AI-402: access discriminants have accessibility based on the
9148 -- object rather than the type in Ada 2005, so the above paragraph
9149 -- doesn't apply.
9151 -- ??? Needs completion with rules from AI-416
9153 if Ada_Version <= Ada_95
9154 and then Ekind (Typ) = E_Anonymous_Access_Type
9155 and then Present (Associated_Node_For_Itype (Typ))
9156 and then Nkind (Associated_Node_For_Itype (Typ)) =
9157 N_Discriminant_Specification
9158 then
9159 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
9160 end if;
9161 end if;
9163 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
9164 end Type_Access_Level;
9166 --------------------------
9167 -- Unit_Declaration_Node --
9168 --------------------------
9170 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
9171 N : Node_Id := Parent (Unit_Id);
9173 begin
9174 -- Predefined operators do not have a full function declaration
9176 if Ekind (Unit_Id) = E_Operator then
9177 return N;
9178 end if;
9180 -- Isn't there some better way to express the following ???
9182 while Nkind (N) /= N_Abstract_Subprogram_Declaration
9183 and then Nkind (N) /= N_Formal_Package_Declaration
9184 and then Nkind (N) /= N_Function_Instantiation
9185 and then Nkind (N) /= N_Generic_Package_Declaration
9186 and then Nkind (N) /= N_Generic_Subprogram_Declaration
9187 and then Nkind (N) /= N_Package_Declaration
9188 and then Nkind (N) /= N_Package_Body
9189 and then Nkind (N) /= N_Package_Instantiation
9190 and then Nkind (N) /= N_Package_Renaming_Declaration
9191 and then Nkind (N) /= N_Procedure_Instantiation
9192 and then Nkind (N) /= N_Protected_Body
9193 and then Nkind (N) /= N_Subprogram_Declaration
9194 and then Nkind (N) /= N_Subprogram_Body
9195 and then Nkind (N) /= N_Subprogram_Body_Stub
9196 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
9197 and then Nkind (N) /= N_Task_Body
9198 and then Nkind (N) /= N_Task_Type_Declaration
9199 and then Nkind (N) not in N_Formal_Subprogram_Declaration
9200 and then Nkind (N) not in N_Generic_Renaming_Declaration
9201 loop
9202 N := Parent (N);
9203 pragma Assert (Present (N));
9204 end loop;
9206 return N;
9207 end Unit_Declaration_Node;
9209 ------------------------------
9210 -- Universal_Interpretation --
9211 ------------------------------
9213 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
9214 Index : Interp_Index;
9215 It : Interp;
9217 begin
9218 -- The argument may be a formal parameter of an operator or subprogram
9219 -- with multiple interpretations, or else an expression for an actual.
9221 if Nkind (Opnd) = N_Defining_Identifier
9222 or else not Is_Overloaded (Opnd)
9223 then
9224 if Etype (Opnd) = Universal_Integer
9225 or else Etype (Opnd) = Universal_Real
9226 then
9227 return Etype (Opnd);
9228 else
9229 return Empty;
9230 end if;
9232 else
9233 Get_First_Interp (Opnd, Index, It);
9234 while Present (It.Typ) loop
9235 if It.Typ = Universal_Integer
9236 or else It.Typ = Universal_Real
9237 then
9238 return It.Typ;
9239 end if;
9241 Get_Next_Interp (Index, It);
9242 end loop;
9244 return Empty;
9245 end if;
9246 end Universal_Interpretation;
9248 ---------------
9249 -- Unqualify --
9250 ---------------
9252 function Unqualify (Expr : Node_Id) return Node_Id is
9253 begin
9254 -- Recurse to handle unlikely case of multiple levels of qualification
9256 if Nkind (Expr) = N_Qualified_Expression then
9257 return Unqualify (Expression (Expr));
9259 -- Normal case, not a qualified expression
9261 else
9262 return Expr;
9263 end if;
9264 end Unqualify;
9266 ----------------------
9267 -- Within_Init_Proc --
9268 ----------------------
9270 function Within_Init_Proc return Boolean is
9271 S : Entity_Id;
9273 begin
9274 S := Current_Scope;
9275 while not Is_Overloadable (S) loop
9276 if S = Standard_Standard then
9277 return False;
9278 else
9279 S := Scope (S);
9280 end if;
9281 end loop;
9283 return Is_Init_Proc (S);
9284 end Within_Init_Proc;
9286 ----------------
9287 -- Wrong_Type --
9288 ----------------
9290 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
9291 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
9292 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
9294 function Has_One_Matching_Field return Boolean;
9295 -- Determines if Expec_Type is a record type with a single component or
9296 -- discriminant whose type matches the found type or is one dimensional
9297 -- array whose component type matches the found type.
9299 ----------------------------
9300 -- Has_One_Matching_Field --
9301 ----------------------------
9303 function Has_One_Matching_Field return Boolean is
9304 E : Entity_Id;
9306 begin
9307 if Is_Array_Type (Expec_Type)
9308 and then Number_Dimensions (Expec_Type) = 1
9309 and then
9310 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
9311 then
9312 return True;
9314 elsif not Is_Record_Type (Expec_Type) then
9315 return False;
9317 else
9318 E := First_Entity (Expec_Type);
9319 loop
9320 if No (E) then
9321 return False;
9323 elsif (Ekind (E) /= E_Discriminant
9324 and then Ekind (E) /= E_Component)
9325 or else (Chars (E) = Name_uTag
9326 or else Chars (E) = Name_uParent)
9327 then
9328 Next_Entity (E);
9330 else
9331 exit;
9332 end if;
9333 end loop;
9335 if not Covers (Etype (E), Found_Type) then
9336 return False;
9338 elsif Present (Next_Entity (E)) then
9339 return False;
9341 else
9342 return True;
9343 end if;
9344 end if;
9345 end Has_One_Matching_Field;
9347 -- Start of processing for Wrong_Type
9349 begin
9350 -- Don't output message if either type is Any_Type, or if a message
9351 -- has already been posted for this node. We need to do the latter
9352 -- check explicitly (it is ordinarily done in Errout), because we
9353 -- are using ! to force the output of the error messages.
9355 if Expec_Type = Any_Type
9356 or else Found_Type = Any_Type
9357 or else Error_Posted (Expr)
9358 then
9359 return;
9361 -- In an instance, there is an ongoing problem with completion of
9362 -- type derived from private types. Their structure is what Gigi
9363 -- expects, but the Etype is the parent type rather than the
9364 -- derived private type itself. Do not flag error in this case. The
9365 -- private completion is an entity without a parent, like an Itype.
9366 -- Similarly, full and partial views may be incorrect in the instance.
9367 -- There is no simple way to insure that it is consistent ???
9369 elsif In_Instance then
9370 if Etype (Etype (Expr)) = Etype (Expected_Type)
9371 and then
9372 (Has_Private_Declaration (Expected_Type)
9373 or else Has_Private_Declaration (Etype (Expr)))
9374 and then No (Parent (Expected_Type))
9375 then
9376 return;
9377 end if;
9378 end if;
9380 -- An interesting special check. If the expression is parenthesized
9381 -- and its type corresponds to the type of the sole component of the
9382 -- expected record type, or to the component type of the expected one
9383 -- dimensional array type, then assume we have a bad aggregate attempt.
9385 if Nkind (Expr) in N_Subexpr
9386 and then Paren_Count (Expr) /= 0
9387 and then Has_One_Matching_Field
9388 then
9389 Error_Msg_N ("positional aggregate cannot have one component", Expr);
9391 -- Another special check, if we are looking for a pool-specific access
9392 -- type and we found an E_Access_Attribute_Type, then we have the case
9393 -- of an Access attribute being used in a context which needs a pool-
9394 -- specific type, which is never allowed. The one extra check we make
9395 -- is that the expected designated type covers the Found_Type.
9397 elsif Is_Access_Type (Expec_Type)
9398 and then Ekind (Found_Type) = E_Access_Attribute_Type
9399 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
9400 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
9401 and then Covers
9402 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
9403 then
9404 Error_Msg_N ("result must be general access type!", Expr);
9405 Error_Msg_NE ("add ALL to }!", Expr, Expec_Type);
9407 -- Another special check, if the expected type is an integer type,
9408 -- but the expression is of type System.Address, and the parent is
9409 -- an addition or subtraction operation whose left operand is the
9410 -- expression in question and whose right operand is of an integral
9411 -- type, then this is an attempt at address arithmetic, so give
9412 -- appropriate message.
9414 elsif Is_Integer_Type (Expec_Type)
9415 and then Is_RTE (Found_Type, RE_Address)
9416 and then (Nkind (Parent (Expr)) = N_Op_Add
9417 or else
9418 Nkind (Parent (Expr)) = N_Op_Subtract)
9419 and then Expr = Left_Opnd (Parent (Expr))
9420 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
9421 then
9422 Error_Msg_N
9423 ("address arithmetic not predefined in package System",
9424 Parent (Expr));
9425 Error_Msg_N
9426 ("\possible missing with/use of System.Storage_Elements",
9427 Parent (Expr));
9428 return;
9430 -- If the expected type is an anonymous access type, as for access
9431 -- parameters and discriminants, the error is on the designated types.
9433 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
9434 if Comes_From_Source (Expec_Type) then
9435 Error_Msg_NE ("expected}!", Expr, Expec_Type);
9436 else
9437 Error_Msg_NE
9438 ("expected an access type with designated}",
9439 Expr, Designated_Type (Expec_Type));
9440 end if;
9442 if Is_Access_Type (Found_Type)
9443 and then not Comes_From_Source (Found_Type)
9444 then
9445 Error_Msg_NE
9446 ("\\found an access type with designated}!",
9447 Expr, Designated_Type (Found_Type));
9448 else
9449 if From_With_Type (Found_Type) then
9450 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
9451 Error_Msg_Qual_Level := 99;
9452 Error_Msg_NE ("\\missing `WITH &;", Expr, Scope (Found_Type));
9453 Error_Msg_Qual_Level := 0;
9454 else
9455 Error_Msg_NE ("found}!", Expr, Found_Type);
9456 end if;
9457 end if;
9459 -- Normal case of one type found, some other type expected
9461 else
9462 -- If the names of the two types are the same, see if some number
9463 -- of levels of qualification will help. Don't try more than three
9464 -- levels, and if we get to standard, it's no use (and probably
9465 -- represents an error in the compiler) Also do not bother with
9466 -- internal scope names.
9468 declare
9469 Expec_Scope : Entity_Id;
9470 Found_Scope : Entity_Id;
9472 begin
9473 Expec_Scope := Expec_Type;
9474 Found_Scope := Found_Type;
9476 for Levels in Int range 0 .. 3 loop
9477 if Chars (Expec_Scope) /= Chars (Found_Scope) then
9478 Error_Msg_Qual_Level := Levels;
9479 exit;
9480 end if;
9482 Expec_Scope := Scope (Expec_Scope);
9483 Found_Scope := Scope (Found_Scope);
9485 exit when Expec_Scope = Standard_Standard
9486 or else Found_Scope = Standard_Standard
9487 or else not Comes_From_Source (Expec_Scope)
9488 or else not Comes_From_Source (Found_Scope);
9489 end loop;
9490 end;
9492 if Is_Record_Type (Expec_Type)
9493 and then Present (Corresponding_Remote_Type (Expec_Type))
9494 then
9495 Error_Msg_NE ("expected}!", Expr,
9496 Corresponding_Remote_Type (Expec_Type));
9497 else
9498 Error_Msg_NE ("expected}!", Expr, Expec_Type);
9499 end if;
9501 if Is_Entity_Name (Expr)
9502 and then Is_Package_Or_Generic_Package (Entity (Expr))
9503 then
9504 Error_Msg_N ("\\found package name!", Expr);
9506 elsif Is_Entity_Name (Expr)
9507 and then
9508 (Ekind (Entity (Expr)) = E_Procedure
9509 or else
9510 Ekind (Entity (Expr)) = E_Generic_Procedure)
9511 then
9512 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
9513 Error_Msg_N
9514 ("found procedure name, possibly missing Access attribute!",
9515 Expr);
9516 else
9517 Error_Msg_N
9518 ("\\found procedure name instead of function!", Expr);
9519 end if;
9521 elsif Nkind (Expr) = N_Function_Call
9522 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
9523 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
9524 and then No (Parameter_Associations (Expr))
9525 then
9526 Error_Msg_N
9527 ("found function name, possibly missing Access attribute!",
9528 Expr);
9530 -- Catch common error: a prefix or infix operator which is not
9531 -- directly visible because the type isn't.
9533 elsif Nkind (Expr) in N_Op
9534 and then Is_Overloaded (Expr)
9535 and then not Is_Immediately_Visible (Expec_Type)
9536 and then not Is_Potentially_Use_Visible (Expec_Type)
9537 and then not In_Use (Expec_Type)
9538 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
9539 then
9540 Error_Msg_N
9541 ("operator of the type is not directly visible!", Expr);
9543 elsif Ekind (Found_Type) = E_Void
9544 and then Present (Parent (Found_Type))
9545 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
9546 then
9547 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
9549 else
9550 Error_Msg_NE ("\\found}!", Expr, Found_Type);
9551 end if;
9553 Error_Msg_Qual_Level := 0;
9554 end if;
9555 end Wrong_Type;
9557 end Sem_Util;