2008-05-30 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / ada / sem_util.adb
blobe8823b6164fa32a76398f28564d4426bb7d443b5
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-2008, 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_Disp; use Exp_Disp;
33 with Exp_Tss; use Exp_Tss;
34 with Exp_Util; use Exp_Util;
35 with Fname; use Fname;
36 with Freeze; use Freeze;
37 with Lib; use Lib;
38 with Lib.Xref; use Lib.Xref;
39 with Nlists; use Nlists;
40 with Output; use Output;
41 with Opt; use Opt;
42 with Rtsfind; use Rtsfind;
43 with Scans; use Scans;
44 with Scn; use Scn;
45 with Sem; use Sem;
46 with Sem_Attr; use Sem_Attr;
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 Stand; use Stand;
54 with Style;
55 with Stringt; use Stringt;
56 with Targparm; use Targparm;
57 with Tbuild; use Tbuild;
58 with Ttypes; use Ttypes;
59 with Uname; use Uname;
61 package body Sem_Util is
63 -----------------------
64 -- Local Subprograms --
65 -----------------------
67 function Build_Component_Subtype
68 (C : List_Id;
69 Loc : Source_Ptr;
70 T : Entity_Id) return Node_Id;
71 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
72 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
73 -- Loc is the source location, T is the original subtype.
75 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
76 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
77 -- with discriminants whose default values are static, examine only the
78 -- components in the selected variant to determine whether all of them
79 -- have a default.
81 function Has_Null_Extension (T : Entity_Id) return Boolean;
82 -- T is a derived tagged type. Check whether the type extension is null.
83 -- If the parent type is fully initialized, T can be treated as such.
85 ------------------------------
86 -- Abstract_Interface_List --
87 ------------------------------
89 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
90 Nod : Node_Id;
92 begin
93 if Is_Concurrent_Type (Typ) then
95 -- If we are dealing with a synchronized subtype, go to the base
96 -- type, whose declaration has the interface list.
98 -- Shouldn't this be Declaration_Node???
100 Nod := Parent (Base_Type (Typ));
102 if Nkind (Nod) = N_Full_Type_Declaration then
103 return Empty_List;
104 end if;
106 elsif Ekind (Typ) = E_Record_Type_With_Private then
107 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
108 Nod := Type_Definition (Parent (Typ));
110 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
111 if Present (Full_View (Typ)) then
112 Nod := Type_Definition (Parent (Full_View (Typ)));
114 -- If the full-view is not available we cannot do anything else
115 -- here (the source has errors).
117 else
118 return Empty_List;
119 end if;
121 -- Support for generic formals with interfaces is still missing ???
123 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
124 return Empty_List;
126 else
127 pragma Assert
128 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
129 Nod := Parent (Typ);
130 end if;
132 elsif Ekind (Typ) = E_Record_Subtype then
133 Nod := Type_Definition (Parent (Etype (Typ)));
135 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
137 -- Recurse, because parent may still be a private extension. Also
138 -- note that the full view of the subtype or the full view of its
139 -- base type may (both) be unavailable.
141 return Abstract_Interface_List (Etype (Typ));
143 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
144 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
145 Nod := Formal_Type_Definition (Parent (Typ));
146 else
147 Nod := Type_Definition (Parent (Typ));
148 end if;
149 end if;
151 return Interface_List (Nod);
152 end Abstract_Interface_List;
154 --------------------------------
155 -- Add_Access_Type_To_Process --
156 --------------------------------
158 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
159 L : Elist_Id;
161 begin
162 Ensure_Freeze_Node (E);
163 L := Access_Types_To_Process (Freeze_Node (E));
165 if No (L) then
166 L := New_Elmt_List;
167 Set_Access_Types_To_Process (Freeze_Node (E), L);
168 end if;
170 Append_Elmt (A, L);
171 end Add_Access_Type_To_Process;
173 ----------------------------
174 -- Add_Global_Declaration --
175 ----------------------------
177 procedure Add_Global_Declaration (N : Node_Id) is
178 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
180 begin
181 if No (Declarations (Aux_Node)) then
182 Set_Declarations (Aux_Node, New_List);
183 end if;
185 Append_To (Declarations (Aux_Node), N);
186 Analyze (N);
187 end Add_Global_Declaration;
189 -----------------------
190 -- Alignment_In_Bits --
191 -----------------------
193 function Alignment_In_Bits (E : Entity_Id) return Uint is
194 begin
195 return Alignment (E) * System_Storage_Unit;
196 end Alignment_In_Bits;
198 -----------------------------------------
199 -- Apply_Compile_Time_Constraint_Error --
200 -----------------------------------------
202 procedure Apply_Compile_Time_Constraint_Error
203 (N : Node_Id;
204 Msg : String;
205 Reason : RT_Exception_Code;
206 Ent : Entity_Id := Empty;
207 Typ : Entity_Id := Empty;
208 Loc : Source_Ptr := No_Location;
209 Rep : Boolean := True;
210 Warn : Boolean := False)
212 Stat : constant Boolean := Is_Static_Expression (N);
213 R_Stat : constant Node_Id :=
214 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
215 Rtyp : Entity_Id;
217 begin
218 if No (Typ) then
219 Rtyp := Etype (N);
220 else
221 Rtyp := Typ;
222 end if;
224 Discard_Node
225 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
227 if not Rep then
228 return;
229 end if;
231 -- Now we replace the node by an N_Raise_Constraint_Error node
232 -- This does not need reanalyzing, so set it as analyzed now.
234 Rewrite (N, R_Stat);
235 Set_Analyzed (N, True);
237 Set_Etype (N, Rtyp);
238 Set_Raises_Constraint_Error (N);
240 -- If the original expression was marked as static, the result is
241 -- still marked as static, but the Raises_Constraint_Error flag is
242 -- always set so that further static evaluation is not attempted.
244 if Stat then
245 Set_Is_Static_Expression (N);
246 end if;
247 end Apply_Compile_Time_Constraint_Error;
249 --------------------------
250 -- Build_Actual_Subtype --
251 --------------------------
253 function Build_Actual_Subtype
254 (T : Entity_Id;
255 N : Node_Or_Entity_Id) return Node_Id
257 Loc : Source_Ptr;
258 -- Normally Sloc (N), but may point to corresponding body in some cases
260 Constraints : List_Id;
261 Decl : Node_Id;
262 Discr : Entity_Id;
263 Hi : Node_Id;
264 Lo : Node_Id;
265 Subt : Entity_Id;
266 Disc_Type : Entity_Id;
267 Obj : Node_Id;
269 begin
270 Loc := Sloc (N);
272 if Nkind (N) = N_Defining_Identifier then
273 Obj := New_Reference_To (N, Loc);
275 -- If this is a formal parameter of a subprogram declaration, and
276 -- we are compiling the body, we want the declaration for the
277 -- actual subtype to carry the source position of the body, to
278 -- prevent anomalies in gdb when stepping through the code.
280 if Is_Formal (N) then
281 declare
282 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
283 begin
284 if Nkind (Decl) = N_Subprogram_Declaration
285 and then Present (Corresponding_Body (Decl))
286 then
287 Loc := Sloc (Corresponding_Body (Decl));
288 end if;
289 end;
290 end if;
292 else
293 Obj := N;
294 end if;
296 if Is_Array_Type (T) then
297 Constraints := New_List;
298 for J in 1 .. Number_Dimensions (T) loop
300 -- Build an array subtype declaration with the nominal subtype and
301 -- the bounds of the actual. Add the declaration in front of the
302 -- local declarations for the subprogram, for analysis before any
303 -- reference to the formal in the body.
305 Lo :=
306 Make_Attribute_Reference (Loc,
307 Prefix =>
308 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
309 Attribute_Name => Name_First,
310 Expressions => New_List (
311 Make_Integer_Literal (Loc, J)));
313 Hi :=
314 Make_Attribute_Reference (Loc,
315 Prefix =>
316 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
317 Attribute_Name => Name_Last,
318 Expressions => New_List (
319 Make_Integer_Literal (Loc, J)));
321 Append (Make_Range (Loc, Lo, Hi), Constraints);
322 end loop;
324 -- If the type has unknown discriminants there is no constrained
325 -- subtype to build. This is never called for a formal or for a
326 -- lhs, so returning the type is ok ???
328 elsif Has_Unknown_Discriminants (T) then
329 return T;
331 else
332 Constraints := New_List;
334 -- Type T is a generic derived type, inherit the discriminants from
335 -- the parent type.
337 if Is_Private_Type (T)
338 and then No (Full_View (T))
340 -- T was flagged as an error if it was declared as a formal
341 -- derived type with known discriminants. In this case there
342 -- is no need to look at the parent type since T already carries
343 -- its own discriminants.
345 and then not Error_Posted (T)
346 then
347 Disc_Type := Etype (Base_Type (T));
348 else
349 Disc_Type := T;
350 end if;
352 Discr := First_Discriminant (Disc_Type);
353 while Present (Discr) loop
354 Append_To (Constraints,
355 Make_Selected_Component (Loc,
356 Prefix =>
357 Duplicate_Subexpr_No_Checks (Obj),
358 Selector_Name => New_Occurrence_Of (Discr, Loc)));
359 Next_Discriminant (Discr);
360 end loop;
361 end if;
363 Subt :=
364 Make_Defining_Identifier (Loc,
365 Chars => New_Internal_Name ('S'));
366 Set_Is_Internal (Subt);
368 Decl :=
369 Make_Subtype_Declaration (Loc,
370 Defining_Identifier => Subt,
371 Subtype_Indication =>
372 Make_Subtype_Indication (Loc,
373 Subtype_Mark => New_Reference_To (T, Loc),
374 Constraint =>
375 Make_Index_Or_Discriminant_Constraint (Loc,
376 Constraints => Constraints)));
378 Mark_Rewrite_Insertion (Decl);
379 return Decl;
380 end Build_Actual_Subtype;
382 ---------------------------------------
383 -- Build_Actual_Subtype_Of_Component --
384 ---------------------------------------
386 function Build_Actual_Subtype_Of_Component
387 (T : Entity_Id;
388 N : Node_Id) return Node_Id
390 Loc : constant Source_Ptr := Sloc (N);
391 P : constant Node_Id := Prefix (N);
392 D : Elmt_Id;
393 Id : Node_Id;
394 Indx_Type : Entity_Id;
396 Deaccessed_T : Entity_Id;
397 -- This is either a copy of T, or if T is an access type, then it is
398 -- the directly designated type of this access type.
400 function Build_Actual_Array_Constraint return List_Id;
401 -- If one or more of the bounds of the component depends on
402 -- discriminants, build actual constraint using the discriminants
403 -- of the prefix.
405 function Build_Actual_Record_Constraint return List_Id;
406 -- Similar to previous one, for discriminated components constrained
407 -- by the discriminant of the enclosing object.
409 -----------------------------------
410 -- Build_Actual_Array_Constraint --
411 -----------------------------------
413 function Build_Actual_Array_Constraint return List_Id is
414 Constraints : constant List_Id := New_List;
415 Indx : Node_Id;
416 Hi : Node_Id;
417 Lo : Node_Id;
418 Old_Hi : Node_Id;
419 Old_Lo : Node_Id;
421 begin
422 Indx := First_Index (Deaccessed_T);
423 while Present (Indx) loop
424 Old_Lo := Type_Low_Bound (Etype (Indx));
425 Old_Hi := Type_High_Bound (Etype (Indx));
427 if Denotes_Discriminant (Old_Lo) then
428 Lo :=
429 Make_Selected_Component (Loc,
430 Prefix => New_Copy_Tree (P),
431 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
433 else
434 Lo := New_Copy_Tree (Old_Lo);
436 -- The new bound will be reanalyzed in the enclosing
437 -- declaration. For literal bounds that come from a type
438 -- declaration, the type of the context must be imposed, so
439 -- insure that analysis will take place. For non-universal
440 -- types this is not strictly necessary.
442 Set_Analyzed (Lo, False);
443 end if;
445 if Denotes_Discriminant (Old_Hi) then
446 Hi :=
447 Make_Selected_Component (Loc,
448 Prefix => New_Copy_Tree (P),
449 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
451 else
452 Hi := New_Copy_Tree (Old_Hi);
453 Set_Analyzed (Hi, False);
454 end if;
456 Append (Make_Range (Loc, Lo, Hi), Constraints);
457 Next_Index (Indx);
458 end loop;
460 return Constraints;
461 end Build_Actual_Array_Constraint;
463 ------------------------------------
464 -- Build_Actual_Record_Constraint --
465 ------------------------------------
467 function Build_Actual_Record_Constraint return List_Id is
468 Constraints : constant List_Id := New_List;
469 D : Elmt_Id;
470 D_Val : Node_Id;
472 begin
473 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
474 while Present (D) loop
475 if Denotes_Discriminant (Node (D)) then
476 D_Val := Make_Selected_Component (Loc,
477 Prefix => New_Copy_Tree (P),
478 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
480 else
481 D_Val := New_Copy_Tree (Node (D));
482 end if;
484 Append (D_Val, Constraints);
485 Next_Elmt (D);
486 end loop;
488 return Constraints;
489 end Build_Actual_Record_Constraint;
491 -- Start of processing for Build_Actual_Subtype_Of_Component
493 begin
494 -- Why the test for Spec_Expression mode here???
496 if In_Spec_Expression then
497 return Empty;
499 -- More comments for the rest of this body would be good ???
501 elsif Nkind (N) = N_Explicit_Dereference then
502 if Is_Composite_Type (T)
503 and then not Is_Constrained (T)
504 and then not (Is_Class_Wide_Type (T)
505 and then Is_Constrained (Root_Type (T)))
506 and then not Has_Unknown_Discriminants (T)
507 then
508 -- If the type of the dereference is already constrained, it
509 -- is an actual subtype.
511 if Is_Array_Type (Etype (N))
512 and then Is_Constrained (Etype (N))
513 then
514 return Empty;
515 else
516 Remove_Side_Effects (P);
517 return Build_Actual_Subtype (T, N);
518 end if;
519 else
520 return Empty;
521 end if;
522 end if;
524 if Ekind (T) = E_Access_Subtype then
525 Deaccessed_T := Designated_Type (T);
526 else
527 Deaccessed_T := T;
528 end if;
530 if Ekind (Deaccessed_T) = E_Array_Subtype then
531 Id := First_Index (Deaccessed_T);
532 while Present (Id) loop
533 Indx_Type := Underlying_Type (Etype (Id));
535 if Denotes_Discriminant (Type_Low_Bound (Indx_Type))
536 or else
537 Denotes_Discriminant (Type_High_Bound (Indx_Type))
538 then
539 Remove_Side_Effects (P);
540 return
541 Build_Component_Subtype
542 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
543 end if;
545 Next_Index (Id);
546 end loop;
548 elsif Is_Composite_Type (Deaccessed_T)
549 and then Has_Discriminants (Deaccessed_T)
550 and then not Has_Unknown_Discriminants (Deaccessed_T)
551 then
552 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
553 while Present (D) loop
554 if Denotes_Discriminant (Node (D)) then
555 Remove_Side_Effects (P);
556 return
557 Build_Component_Subtype (
558 Build_Actual_Record_Constraint, Loc, Base_Type (T));
559 end if;
561 Next_Elmt (D);
562 end loop;
563 end if;
565 -- If none of the above, the actual and nominal subtypes are the same
567 return Empty;
568 end Build_Actual_Subtype_Of_Component;
570 -----------------------------
571 -- Build_Component_Subtype --
572 -----------------------------
574 function Build_Component_Subtype
575 (C : List_Id;
576 Loc : Source_Ptr;
577 T : Entity_Id) return Node_Id
579 Subt : Entity_Id;
580 Decl : Node_Id;
582 begin
583 -- Unchecked_Union components do not require component subtypes
585 if Is_Unchecked_Union (T) then
586 return Empty;
587 end if;
589 Subt :=
590 Make_Defining_Identifier (Loc,
591 Chars => New_Internal_Name ('S'));
592 Set_Is_Internal (Subt);
594 Decl :=
595 Make_Subtype_Declaration (Loc,
596 Defining_Identifier => Subt,
597 Subtype_Indication =>
598 Make_Subtype_Indication (Loc,
599 Subtype_Mark => New_Reference_To (Base_Type (T), Loc),
600 Constraint =>
601 Make_Index_Or_Discriminant_Constraint (Loc,
602 Constraints => C)));
604 Mark_Rewrite_Insertion (Decl);
605 return Decl;
606 end Build_Component_Subtype;
608 ---------------------------
609 -- Build_Default_Subtype --
610 ---------------------------
612 function Build_Default_Subtype
613 (T : Entity_Id;
614 N : Node_Id) return Entity_Id
616 Loc : constant Source_Ptr := Sloc (N);
617 Disc : Entity_Id;
619 begin
620 if not Has_Discriminants (T) or else Is_Constrained (T) then
621 return T;
622 end if;
624 Disc := First_Discriminant (T);
626 if No (Discriminant_Default_Value (Disc)) then
627 return T;
628 end if;
630 declare
631 Act : constant Entity_Id :=
632 Make_Defining_Identifier (Loc,
633 Chars => New_Internal_Name ('S'));
635 Constraints : constant List_Id := New_List;
636 Decl : Node_Id;
638 begin
639 while Present (Disc) loop
640 Append_To (Constraints,
641 New_Copy_Tree (Discriminant_Default_Value (Disc)));
642 Next_Discriminant (Disc);
643 end loop;
645 Decl :=
646 Make_Subtype_Declaration (Loc,
647 Defining_Identifier => Act,
648 Subtype_Indication =>
649 Make_Subtype_Indication (Loc,
650 Subtype_Mark => New_Occurrence_Of (T, Loc),
651 Constraint =>
652 Make_Index_Or_Discriminant_Constraint (Loc,
653 Constraints => Constraints)));
655 Insert_Action (N, Decl);
656 Analyze (Decl);
657 return Act;
658 end;
659 end Build_Default_Subtype;
661 --------------------------------------------
662 -- Build_Discriminal_Subtype_Of_Component --
663 --------------------------------------------
665 function Build_Discriminal_Subtype_Of_Component
666 (T : Entity_Id) return Node_Id
668 Loc : constant Source_Ptr := Sloc (T);
669 D : Elmt_Id;
670 Id : Node_Id;
672 function Build_Discriminal_Array_Constraint return List_Id;
673 -- If one or more of the bounds of the component depends on
674 -- discriminants, build actual constraint using the discriminants
675 -- of the prefix.
677 function Build_Discriminal_Record_Constraint return List_Id;
678 -- Similar to previous one, for discriminated components constrained
679 -- by the discriminant of the enclosing object.
681 ----------------------------------------
682 -- Build_Discriminal_Array_Constraint --
683 ----------------------------------------
685 function Build_Discriminal_Array_Constraint return List_Id is
686 Constraints : constant List_Id := New_List;
687 Indx : Node_Id;
688 Hi : Node_Id;
689 Lo : Node_Id;
690 Old_Hi : Node_Id;
691 Old_Lo : Node_Id;
693 begin
694 Indx := First_Index (T);
695 while Present (Indx) loop
696 Old_Lo := Type_Low_Bound (Etype (Indx));
697 Old_Hi := Type_High_Bound (Etype (Indx));
699 if Denotes_Discriminant (Old_Lo) then
700 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
702 else
703 Lo := New_Copy_Tree (Old_Lo);
704 end if;
706 if Denotes_Discriminant (Old_Hi) then
707 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
709 else
710 Hi := New_Copy_Tree (Old_Hi);
711 end if;
713 Append (Make_Range (Loc, Lo, Hi), Constraints);
714 Next_Index (Indx);
715 end loop;
717 return Constraints;
718 end Build_Discriminal_Array_Constraint;
720 -----------------------------------------
721 -- Build_Discriminal_Record_Constraint --
722 -----------------------------------------
724 function Build_Discriminal_Record_Constraint return List_Id is
725 Constraints : constant List_Id := New_List;
726 D : Elmt_Id;
727 D_Val : Node_Id;
729 begin
730 D := First_Elmt (Discriminant_Constraint (T));
731 while Present (D) loop
732 if Denotes_Discriminant (Node (D)) then
733 D_Val :=
734 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
736 else
737 D_Val := New_Copy_Tree (Node (D));
738 end if;
740 Append (D_Val, Constraints);
741 Next_Elmt (D);
742 end loop;
744 return Constraints;
745 end Build_Discriminal_Record_Constraint;
747 -- Start of processing for Build_Discriminal_Subtype_Of_Component
749 begin
750 if Ekind (T) = E_Array_Subtype then
751 Id := First_Index (T);
752 while Present (Id) loop
753 if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) or else
754 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
755 then
756 return Build_Component_Subtype
757 (Build_Discriminal_Array_Constraint, Loc, T);
758 end if;
760 Next_Index (Id);
761 end loop;
763 elsif Ekind (T) = E_Record_Subtype
764 and then Has_Discriminants (T)
765 and then not Has_Unknown_Discriminants (T)
766 then
767 D := First_Elmt (Discriminant_Constraint (T));
768 while Present (D) loop
769 if Denotes_Discriminant (Node (D)) then
770 return Build_Component_Subtype
771 (Build_Discriminal_Record_Constraint, Loc, T);
772 end if;
774 Next_Elmt (D);
775 end loop;
776 end if;
778 -- If none of the above, the actual and nominal subtypes are the same
780 return Empty;
781 end Build_Discriminal_Subtype_Of_Component;
783 ------------------------------
784 -- Build_Elaboration_Entity --
785 ------------------------------
787 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
788 Loc : constant Source_Ptr := Sloc (N);
789 Decl : Node_Id;
790 Elab_Ent : Entity_Id;
792 procedure Set_Package_Name (Ent : Entity_Id);
793 -- Given an entity, sets the fully qualified name of the entity in
794 -- Name_Buffer, with components separated by double underscores. This
795 -- is a recursive routine that climbs the scope chain to Standard.
797 ----------------------
798 -- Set_Package_Name --
799 ----------------------
801 procedure Set_Package_Name (Ent : Entity_Id) is
802 begin
803 if Scope (Ent) /= Standard_Standard then
804 Set_Package_Name (Scope (Ent));
806 declare
807 Nam : constant String := Get_Name_String (Chars (Ent));
808 begin
809 Name_Buffer (Name_Len + 1) := '_';
810 Name_Buffer (Name_Len + 2) := '_';
811 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
812 Name_Len := Name_Len + Nam'Length + 2;
813 end;
815 else
816 Get_Name_String (Chars (Ent));
817 end if;
818 end Set_Package_Name;
820 -- Start of processing for Build_Elaboration_Entity
822 begin
823 -- Ignore if already constructed
825 if Present (Elaboration_Entity (Spec_Id)) then
826 return;
827 end if;
829 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
830 -- name with dots replaced by double underscore. We have to manually
831 -- construct this name, since it will be elaborated in the outer scope,
832 -- and thus will not have the unit name automatically prepended.
834 Set_Package_Name (Spec_Id);
836 -- Append _E
838 Name_Buffer (Name_Len + 1) := '_';
839 Name_Buffer (Name_Len + 2) := 'E';
840 Name_Len := Name_Len + 2;
842 -- Create elaboration flag
844 Elab_Ent :=
845 Make_Defining_Identifier (Loc, Chars => Name_Find);
846 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
848 Decl :=
849 Make_Object_Declaration (Loc,
850 Defining_Identifier => Elab_Ent,
851 Object_Definition =>
852 New_Occurrence_Of (Standard_Boolean, Loc),
853 Expression =>
854 New_Occurrence_Of (Standard_False, Loc));
856 Push_Scope (Standard_Standard);
857 Add_Global_Declaration (Decl);
858 Pop_Scope;
860 -- Reset True_Constant indication, since we will indeed assign a value
861 -- to the variable in the binder main. We also kill the Current_Value
862 -- and Last_Assignment fields for the same reason.
864 Set_Is_True_Constant (Elab_Ent, False);
865 Set_Current_Value (Elab_Ent, Empty);
866 Set_Last_Assignment (Elab_Ent, Empty);
868 -- We do not want any further qualification of the name (if we did
869 -- not do this, we would pick up the name of the generic package
870 -- in the case of a library level generic instantiation).
872 Set_Has_Qualified_Name (Elab_Ent);
873 Set_Has_Fully_Qualified_Name (Elab_Ent);
874 end Build_Elaboration_Entity;
876 -----------------------------------
877 -- Cannot_Raise_Constraint_Error --
878 -----------------------------------
880 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
881 begin
882 if Compile_Time_Known_Value (Expr) then
883 return True;
885 elsif Do_Range_Check (Expr) then
886 return False;
888 elsif Raises_Constraint_Error (Expr) then
889 return False;
891 else
892 case Nkind (Expr) is
893 when N_Identifier =>
894 return True;
896 when N_Expanded_Name =>
897 return True;
899 when N_Selected_Component =>
900 return not Do_Discriminant_Check (Expr);
902 when N_Attribute_Reference =>
903 if Do_Overflow_Check (Expr) then
904 return False;
906 elsif No (Expressions (Expr)) then
907 return True;
909 else
910 declare
911 N : Node_Id;
913 begin
914 N := First (Expressions (Expr));
915 while Present (N) loop
916 if Cannot_Raise_Constraint_Error (N) then
917 Next (N);
918 else
919 return False;
920 end if;
921 end loop;
923 return True;
924 end;
925 end if;
927 when N_Type_Conversion =>
928 if Do_Overflow_Check (Expr)
929 or else Do_Length_Check (Expr)
930 or else Do_Tag_Check (Expr)
931 then
932 return False;
933 else
934 return
935 Cannot_Raise_Constraint_Error (Expression (Expr));
936 end if;
938 when N_Unchecked_Type_Conversion =>
939 return Cannot_Raise_Constraint_Error (Expression (Expr));
941 when N_Unary_Op =>
942 if Do_Overflow_Check (Expr) then
943 return False;
944 else
945 return
946 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
947 end if;
949 when N_Op_Divide |
950 N_Op_Mod |
951 N_Op_Rem
953 if Do_Division_Check (Expr)
954 or else Do_Overflow_Check (Expr)
955 then
956 return False;
957 else
958 return
959 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
960 and then
961 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
962 end if;
964 when N_Op_Add |
965 N_Op_And |
966 N_Op_Concat |
967 N_Op_Eq |
968 N_Op_Expon |
969 N_Op_Ge |
970 N_Op_Gt |
971 N_Op_Le |
972 N_Op_Lt |
973 N_Op_Multiply |
974 N_Op_Ne |
975 N_Op_Or |
976 N_Op_Rotate_Left |
977 N_Op_Rotate_Right |
978 N_Op_Shift_Left |
979 N_Op_Shift_Right |
980 N_Op_Shift_Right_Arithmetic |
981 N_Op_Subtract |
982 N_Op_Xor
984 if Do_Overflow_Check (Expr) then
985 return False;
986 else
987 return
988 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
989 and then
990 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
991 end if;
993 when others =>
994 return False;
995 end case;
996 end if;
997 end Cannot_Raise_Constraint_Error;
999 --------------------------
1000 -- Check_Fully_Declared --
1001 --------------------------
1003 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
1004 begin
1005 if Ekind (T) = E_Incomplete_Type then
1007 -- Ada 2005 (AI-50217): If the type is available through a limited
1008 -- with_clause, verify that its full view has been analyzed.
1010 if From_With_Type (T)
1011 and then Present (Non_Limited_View (T))
1012 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1013 then
1014 -- The non-limited view is fully declared
1015 null;
1017 else
1018 Error_Msg_NE
1019 ("premature usage of incomplete}", N, First_Subtype (T));
1020 end if;
1022 -- Need comments for these tests ???
1024 elsif Has_Private_Component (T)
1025 and then not Is_Generic_Type (Root_Type (T))
1026 and then not In_Spec_Expression
1027 then
1028 -- Special case: if T is the anonymous type created for a single
1029 -- task or protected object, use the name of the source object.
1031 if Is_Concurrent_Type (T)
1032 and then not Comes_From_Source (T)
1033 and then Nkind (N) = N_Object_Declaration
1034 then
1035 Error_Msg_NE ("type of& has incomplete component", N,
1036 Defining_Identifier (N));
1038 else
1039 Error_Msg_NE
1040 ("premature usage of incomplete}", N, First_Subtype (T));
1041 end if;
1042 end if;
1043 end Check_Fully_Declared;
1045 -------------------------
1046 -- Check_Nested_Access --
1047 -------------------------
1049 procedure Check_Nested_Access (Ent : Entity_Id) is
1050 Scop : constant Entity_Id := Current_Scope;
1051 Current_Subp : Entity_Id;
1052 Enclosing : Entity_Id;
1054 begin
1055 -- Currently only enabled for VM back-ends for efficiency, should we
1056 -- enable it more systematically ???
1058 -- Check for Is_Imported needs commenting below ???
1060 if VM_Target /= No_VM
1061 and then (Ekind (Ent) = E_Variable
1062 or else
1063 Ekind (Ent) = E_Constant
1064 or else
1065 Ekind (Ent) = E_Loop_Parameter)
1066 and then Scope (Ent) /= Empty
1067 and then not Is_Library_Level_Entity (Ent)
1068 and then not Is_Imported (Ent)
1069 then
1070 if Is_Subprogram (Scop)
1071 or else Is_Generic_Subprogram (Scop)
1072 or else Is_Entry (Scop)
1073 then
1074 Current_Subp := Scop;
1075 else
1076 Current_Subp := Current_Subprogram;
1077 end if;
1079 Enclosing := Enclosing_Subprogram (Ent);
1081 if Enclosing /= Empty
1082 and then Enclosing /= Current_Subp
1083 then
1084 Set_Has_Up_Level_Access (Ent, True);
1085 end if;
1086 end if;
1087 end Check_Nested_Access;
1089 ------------------------------------------
1090 -- Check_Potentially_Blocking_Operation --
1091 ------------------------------------------
1093 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
1094 S : Entity_Id;
1095 begin
1096 -- N is one of the potentially blocking operations listed in 9.5.1(8).
1097 -- When pragma Detect_Blocking is active, the run time will raise
1098 -- Program_Error. Here we only issue a warning, since we generally
1099 -- support the use of potentially blocking operations in the absence
1100 -- of the pragma.
1102 -- Indirect blocking through a subprogram call cannot be diagnosed
1103 -- statically without interprocedural analysis, so we do not attempt
1104 -- to do it here.
1106 S := Scope (Current_Scope);
1107 while Present (S) and then S /= Standard_Standard loop
1108 if Is_Protected_Type (S) then
1109 Error_Msg_N
1110 ("potentially blocking operation in protected operation?", N);
1112 return;
1113 end if;
1115 S := Scope (S);
1116 end loop;
1117 end Check_Potentially_Blocking_Operation;
1119 ------------------------------
1120 -- Check_Unprotected_Access --
1121 ------------------------------
1123 procedure Check_Unprotected_Access
1124 (Context : Node_Id;
1125 Expr : Node_Id)
1127 Cont_Encl_Typ : Entity_Id;
1128 Pref_Encl_Typ : Entity_Id;
1130 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
1131 -- Check whether Obj is a private component of a protected object.
1132 -- Return the protected type where the component resides, Empty
1133 -- otherwise.
1135 function Is_Public_Operation return Boolean;
1136 -- Verify that the enclosing operation is callable from outside the
1137 -- protected object, to minimize false positives.
1139 ------------------------------
1140 -- Enclosing_Protected_Type --
1141 ------------------------------
1143 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
1144 begin
1145 if Is_Entity_Name (Obj) then
1146 declare
1147 Ent : Entity_Id := Entity (Obj);
1149 begin
1150 -- The object can be a renaming of a private component, use
1151 -- the original record component.
1153 if Is_Prival (Ent) then
1154 Ent := Prival_Link (Ent);
1155 end if;
1157 if Is_Protected_Type (Scope (Ent)) then
1158 return Scope (Ent);
1159 end if;
1160 end;
1161 end if;
1163 -- For indexed and selected components, recursively check the prefix
1165 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
1166 return Enclosing_Protected_Type (Prefix (Obj));
1168 -- The object does not denote a protected component
1170 else
1171 return Empty;
1172 end if;
1173 end Enclosing_Protected_Type;
1175 -------------------------
1176 -- Is_Public_Operation --
1177 -------------------------
1179 function Is_Public_Operation return Boolean is
1180 S : Entity_Id;
1181 E : Entity_Id;
1183 begin
1184 S := Current_Scope;
1185 while Present (S)
1186 and then S /= Pref_Encl_Typ
1187 loop
1188 if Scope (S) = Pref_Encl_Typ then
1189 E := First_Entity (Pref_Encl_Typ);
1190 while Present (E)
1191 and then E /= First_Private_Entity (Pref_Encl_Typ)
1192 loop
1193 if E = S then
1194 return True;
1195 end if;
1196 Next_Entity (E);
1197 end loop;
1198 end if;
1200 S := Scope (S);
1201 end loop;
1203 return False;
1204 end Is_Public_Operation;
1206 -- Start of processing for Check_Unprotected_Access
1208 begin
1209 if Nkind (Expr) = N_Attribute_Reference
1210 and then Attribute_Name (Expr) = Name_Unchecked_Access
1211 then
1212 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
1213 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
1215 -- Check whether we are trying to export a protected component to a
1216 -- context with an equal or lower access level.
1218 if Present (Pref_Encl_Typ)
1219 and then No (Cont_Encl_Typ)
1220 and then Is_Public_Operation
1221 and then Scope_Depth (Pref_Encl_Typ) >=
1222 Object_Access_Level (Context)
1223 then
1224 Error_Msg_N
1225 ("?possible unprotected access to protected data", Expr);
1226 end if;
1227 end if;
1228 end Check_Unprotected_Access;
1230 ---------------
1231 -- Check_VMS --
1232 ---------------
1234 procedure Check_VMS (Construct : Node_Id) is
1235 begin
1236 if not OpenVMS_On_Target then
1237 Error_Msg_N
1238 ("this construct is allowed only in Open'V'M'S", Construct);
1239 end if;
1240 end Check_VMS;
1242 ------------------------
1243 -- Collect_Interfaces --
1244 ------------------------
1246 procedure Collect_Interfaces
1247 (T : Entity_Id;
1248 Ifaces_List : out Elist_Id;
1249 Exclude_Parents : Boolean := False;
1250 Use_Full_View : Boolean := True)
1252 procedure Collect (Typ : Entity_Id);
1253 -- Subsidiary subprogram used to traverse the whole list
1254 -- of directly and indirectly implemented interfaces
1256 -------------
1257 -- Collect --
1258 -------------
1260 procedure Collect (Typ : Entity_Id) is
1261 Ancestor : Entity_Id;
1262 Full_T : Entity_Id;
1263 Id : Node_Id;
1264 Iface : Entity_Id;
1266 begin
1267 Full_T := Typ;
1269 -- Handle private types
1271 if Use_Full_View
1272 and then Is_Private_Type (Typ)
1273 and then Present (Full_View (Typ))
1274 then
1275 Full_T := Full_View (Typ);
1276 end if;
1278 -- Include the ancestor if we are generating the whole list of
1279 -- abstract interfaces.
1281 if Etype (Full_T) /= Typ
1283 -- Protect the frontend against wrong sources. For example:
1285 -- package P is
1286 -- type A is tagged null record;
1287 -- type B is new A with private;
1288 -- type C is new A with private;
1289 -- private
1290 -- type B is new C with null record;
1291 -- type C is new B with null record;
1292 -- end P;
1294 and then Etype (Full_T) /= T
1295 then
1296 Ancestor := Etype (Full_T);
1297 Collect (Ancestor);
1299 if Is_Interface (Ancestor)
1300 and then not Exclude_Parents
1301 then
1302 Append_Unique_Elmt (Ancestor, Ifaces_List);
1303 end if;
1304 end if;
1306 -- Traverse the graph of ancestor interfaces
1308 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
1309 Id := First (Abstract_Interface_List (Full_T));
1310 while Present (Id) loop
1311 Iface := Etype (Id);
1313 -- Protect against wrong uses. For example:
1314 -- type I is interface;
1315 -- type O is tagged null record;
1316 -- type Wrong is new I and O with null record; -- ERROR
1318 if Is_Interface (Iface) then
1319 if Exclude_Parents
1320 and then Etype (T) /= T
1321 and then Interface_Present_In_Ancestor (Etype (T), Iface)
1322 then
1323 null;
1324 else
1325 Collect (Iface);
1326 Append_Unique_Elmt (Iface, Ifaces_List);
1327 end if;
1328 end if;
1330 Next (Id);
1331 end loop;
1332 end if;
1333 end Collect;
1335 -- Start of processing for Collect_Interfaces
1337 begin
1338 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
1339 Ifaces_List := New_Elmt_List;
1340 Collect (T);
1341 end Collect_Interfaces;
1343 ----------------------------------
1344 -- Collect_Interface_Components --
1345 ----------------------------------
1347 procedure Collect_Interface_Components
1348 (Tagged_Type : Entity_Id;
1349 Components_List : out Elist_Id)
1351 procedure Collect (Typ : Entity_Id);
1352 -- Subsidiary subprogram used to climb to the parents
1354 -------------
1355 -- Collect --
1356 -------------
1358 procedure Collect (Typ : Entity_Id) is
1359 Tag_Comp : Entity_Id;
1361 begin
1362 if Etype (Typ) /= Typ
1364 -- Protect the frontend against wrong sources. For example:
1366 -- package P is
1367 -- type A is tagged null record;
1368 -- type B is new A with private;
1369 -- type C is new A with private;
1370 -- private
1371 -- type B is new C with null record;
1372 -- type C is new B with null record;
1373 -- end P;
1375 and then Etype (Typ) /= Tagged_Type
1376 then
1377 Collect (Etype (Typ));
1378 end if;
1380 -- Collect the components containing tags of secondary dispatch
1381 -- tables.
1383 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
1384 while Present (Tag_Comp) loop
1385 pragma Assert (Present (Related_Type (Tag_Comp)));
1386 Append_Elmt (Tag_Comp, Components_List);
1388 Tag_Comp := Next_Tag_Component (Tag_Comp);
1389 end loop;
1390 end Collect;
1392 -- Start of processing for Collect_Interface_Components
1394 begin
1395 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
1396 and then Is_Tagged_Type (Tagged_Type));
1398 Components_List := New_Elmt_List;
1399 Collect (Tagged_Type);
1400 end Collect_Interface_Components;
1402 -----------------------------
1403 -- Collect_Interfaces_Info --
1404 -----------------------------
1406 procedure Collect_Interfaces_Info
1407 (T : Entity_Id;
1408 Ifaces_List : out Elist_Id;
1409 Components_List : out Elist_Id;
1410 Tags_List : out Elist_Id)
1412 Comps_List : Elist_Id;
1413 Comp_Elmt : Elmt_Id;
1414 Comp_Iface : Entity_Id;
1415 Iface_Elmt : Elmt_Id;
1416 Iface : Entity_Id;
1418 function Search_Tag (Iface : Entity_Id) return Entity_Id;
1419 -- Search for the secondary tag associated with the interface type
1420 -- Iface that is implemented by T.
1422 ----------------
1423 -- Search_Tag --
1424 ----------------
1426 function Search_Tag (Iface : Entity_Id) return Entity_Id is
1427 ADT : Elmt_Id;
1429 begin
1430 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
1431 while Present (ADT)
1432 and then Ekind (Node (ADT)) = E_Constant
1433 and then Related_Type (Node (ADT)) /= Iface
1434 loop
1435 -- Skip the secondary dispatch tables of Iface
1437 Next_Elmt (ADT);
1438 Next_Elmt (ADT);
1439 Next_Elmt (ADT);
1440 Next_Elmt (ADT);
1441 end loop;
1443 pragma Assert (Ekind (Node (ADT)) = E_Constant);
1444 return Node (ADT);
1445 end Search_Tag;
1447 -- Start of processing for Collect_Interfaces_Info
1449 begin
1450 Collect_Interfaces (T, Ifaces_List);
1451 Collect_Interface_Components (T, Comps_List);
1453 -- Search for the record component and tag associated with each
1454 -- interface type of T.
1456 Components_List := New_Elmt_List;
1457 Tags_List := New_Elmt_List;
1459 Iface_Elmt := First_Elmt (Ifaces_List);
1460 while Present (Iface_Elmt) loop
1461 Iface := Node (Iface_Elmt);
1463 -- Associate the primary tag component and the primary dispatch table
1464 -- with all the interfaces that are parents of T
1466 if Is_Ancestor (Iface, T) then
1467 Append_Elmt (First_Tag_Component (T), Components_List);
1468 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
1470 -- Otherwise search for the tag component and secondary dispatch
1471 -- table of Iface
1473 else
1474 Comp_Elmt := First_Elmt (Comps_List);
1475 while Present (Comp_Elmt) loop
1476 Comp_Iface := Related_Type (Node (Comp_Elmt));
1478 if Comp_Iface = Iface
1479 or else Is_Ancestor (Iface, Comp_Iface)
1480 then
1481 Append_Elmt (Node (Comp_Elmt), Components_List);
1482 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
1483 exit;
1484 end if;
1486 Next_Elmt (Comp_Elmt);
1487 end loop;
1488 pragma Assert (Present (Comp_Elmt));
1489 end if;
1491 Next_Elmt (Iface_Elmt);
1492 end loop;
1493 end Collect_Interfaces_Info;
1495 ----------------------------------
1496 -- Collect_Primitive_Operations --
1497 ----------------------------------
1499 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
1500 B_Type : constant Entity_Id := Base_Type (T);
1501 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
1502 B_Scope : Entity_Id := Scope (B_Type);
1503 Op_List : Elist_Id;
1504 Formal : Entity_Id;
1505 Is_Prim : Boolean;
1506 Formal_Derived : Boolean := False;
1507 Id : Entity_Id;
1509 begin
1510 -- For tagged types, the primitive operations are collected as they
1511 -- are declared, and held in an explicit list which is simply returned.
1513 if Is_Tagged_Type (B_Type) then
1514 return Primitive_Operations (B_Type);
1516 -- An untagged generic type that is a derived type inherits the
1517 -- primitive operations of its parent type. Other formal types only
1518 -- have predefined operators, which are not explicitly represented.
1520 elsif Is_Generic_Type (B_Type) then
1521 if Nkind (B_Decl) = N_Formal_Type_Declaration
1522 and then Nkind (Formal_Type_Definition (B_Decl))
1523 = N_Formal_Derived_Type_Definition
1524 then
1525 Formal_Derived := True;
1526 else
1527 return New_Elmt_List;
1528 end if;
1529 end if;
1531 Op_List := New_Elmt_List;
1533 if B_Scope = Standard_Standard then
1534 if B_Type = Standard_String then
1535 Append_Elmt (Standard_Op_Concat, Op_List);
1537 elsif B_Type = Standard_Wide_String then
1538 Append_Elmt (Standard_Op_Concatw, Op_List);
1540 else
1541 null;
1542 end if;
1544 elsif (Is_Package_Or_Generic_Package (B_Scope)
1545 and then
1546 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
1547 N_Package_Body)
1548 or else Is_Derived_Type (B_Type)
1549 then
1550 -- The primitive operations appear after the base type, except
1551 -- if the derivation happens within the private part of B_Scope
1552 -- and the type is a private type, in which case both the type
1553 -- and some primitive operations may appear before the base
1554 -- type, and the list of candidates starts after the type.
1556 if In_Open_Scopes (B_Scope)
1557 and then Scope (T) = B_Scope
1558 and then In_Private_Part (B_Scope)
1559 then
1560 Id := Next_Entity (T);
1561 else
1562 Id := Next_Entity (B_Type);
1563 end if;
1565 while Present (Id) loop
1567 -- Note that generic formal subprograms are not
1568 -- considered to be primitive operations and thus
1569 -- are never inherited.
1571 if Is_Overloadable (Id)
1572 and then Nkind (Parent (Parent (Id)))
1573 not in N_Formal_Subprogram_Declaration
1574 then
1575 Is_Prim := False;
1577 if Base_Type (Etype (Id)) = B_Type then
1578 Is_Prim := True;
1579 else
1580 Formal := First_Formal (Id);
1581 while Present (Formal) loop
1582 if Base_Type (Etype (Formal)) = B_Type then
1583 Is_Prim := True;
1584 exit;
1586 elsif Ekind (Etype (Formal)) = E_Anonymous_Access_Type
1587 and then Base_Type
1588 (Designated_Type (Etype (Formal))) = B_Type
1589 then
1590 Is_Prim := True;
1591 exit;
1592 end if;
1594 Next_Formal (Formal);
1595 end loop;
1596 end if;
1598 -- For a formal derived type, the only primitives are the
1599 -- ones inherited from the parent type. Operations appearing
1600 -- in the package declaration are not primitive for it.
1602 if Is_Prim
1603 and then (not Formal_Derived
1604 or else Present (Alias (Id)))
1605 then
1606 Append_Elmt (Id, Op_List);
1607 end if;
1608 end if;
1610 Next_Entity (Id);
1612 -- For a type declared in System, some of its operations
1613 -- may appear in the target-specific extension to System.
1615 if No (Id)
1616 and then Chars (B_Scope) = Name_System
1617 and then Scope (B_Scope) = Standard_Standard
1618 and then Present_System_Aux
1619 then
1620 B_Scope := System_Aux_Id;
1621 Id := First_Entity (System_Aux_Id);
1622 end if;
1623 end loop;
1624 end if;
1626 return Op_List;
1627 end Collect_Primitive_Operations;
1629 -----------------------------------
1630 -- Compile_Time_Constraint_Error --
1631 -----------------------------------
1633 function Compile_Time_Constraint_Error
1634 (N : Node_Id;
1635 Msg : String;
1636 Ent : Entity_Id := Empty;
1637 Loc : Source_Ptr := No_Location;
1638 Warn : Boolean := False) return Node_Id
1640 Msgc : String (1 .. Msg'Length + 2);
1641 -- Copy of message, with room for possible ? and ! at end
1643 Msgl : Natural;
1644 Wmsg : Boolean;
1645 P : Node_Id;
1646 OldP : Node_Id;
1647 Msgs : Boolean;
1648 Eloc : Source_Ptr;
1650 begin
1651 -- A static constraint error in an instance body is not a fatal error.
1652 -- we choose to inhibit the message altogether, because there is no
1653 -- obvious node (for now) on which to post it. On the other hand the
1654 -- offending node must be replaced with a constraint_error in any case.
1656 -- No messages are generated if we already posted an error on this node
1658 if not Error_Posted (N) then
1659 if Loc /= No_Location then
1660 Eloc := Loc;
1661 else
1662 Eloc := Sloc (N);
1663 end if;
1665 Msgc (1 .. Msg'Length) := Msg;
1666 Msgl := Msg'Length;
1668 -- Message is a warning, even in Ada 95 case
1670 if Msg (Msg'Last) = '?' then
1671 Wmsg := True;
1673 -- In Ada 83, all messages are warnings. In the private part and
1674 -- the body of an instance, constraint_checks are only warnings.
1675 -- We also make this a warning if the Warn parameter is set.
1677 elsif Warn
1678 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
1679 then
1680 Msgl := Msgl + 1;
1681 Msgc (Msgl) := '?';
1682 Wmsg := True;
1684 elsif In_Instance_Not_Visible then
1685 Msgl := Msgl + 1;
1686 Msgc (Msgl) := '?';
1687 Wmsg := True;
1689 -- Otherwise we have a real error message (Ada 95 static case)
1690 -- and we make this an unconditional message. Note that in the
1691 -- warning case we do not make the message unconditional, it seems
1692 -- quite reasonable to delete messages like this (about exceptions
1693 -- that will be raised) in dead code.
1695 else
1696 Wmsg := False;
1697 Msgl := Msgl + 1;
1698 Msgc (Msgl) := '!';
1699 end if;
1701 -- Should we generate a warning? The answer is not quite yes. The
1702 -- very annoying exception occurs in the case of a short circuit
1703 -- operator where the left operand is static and decisive. Climb
1704 -- parents to see if that is the case we have here. Conditional
1705 -- expressions with decisive conditions are a similar situation.
1707 Msgs := True;
1708 P := N;
1709 loop
1710 OldP := P;
1711 P := Parent (P);
1713 -- And then with False as left operand
1715 if Nkind (P) = N_And_Then
1716 and then Compile_Time_Known_Value (Left_Opnd (P))
1717 and then Is_False (Expr_Value (Left_Opnd (P)))
1718 then
1719 Msgs := False;
1720 exit;
1722 -- OR ELSE with True as left operand
1724 elsif Nkind (P) = N_Or_Else
1725 and then Compile_Time_Known_Value (Left_Opnd (P))
1726 and then Is_True (Expr_Value (Left_Opnd (P)))
1727 then
1728 Msgs := False;
1729 exit;
1731 -- Conditional expression
1733 elsif Nkind (P) = N_Conditional_Expression then
1734 declare
1735 Cond : constant Node_Id := First (Expressions (P));
1736 Texp : constant Node_Id := Next (Cond);
1737 Fexp : constant Node_Id := Next (Texp);
1739 begin
1740 if Compile_Time_Known_Value (Cond) then
1742 -- Condition is True and we are in the right operand
1744 if Is_True (Expr_Value (Cond))
1745 and then OldP = Fexp
1746 then
1747 Msgs := False;
1748 exit;
1750 -- Condition is False and we are in the left operand
1752 elsif Is_False (Expr_Value (Cond))
1753 and then OldP = Texp
1754 then
1755 Msgs := False;
1756 exit;
1757 end if;
1758 end if;
1759 end;
1761 -- Special case for component association in aggregates, where
1762 -- we want to keep climbing up to the parent aggregate.
1764 elsif Nkind (P) = N_Component_Association
1765 and then Nkind (Parent (P)) = N_Aggregate
1766 then
1767 null;
1769 -- Keep going if within subexpression
1771 else
1772 exit when Nkind (P) not in N_Subexpr;
1773 end if;
1774 end loop;
1776 if Msgs then
1777 if Present (Ent) then
1778 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
1779 else
1780 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
1781 end if;
1783 if Wmsg then
1784 if Inside_Init_Proc then
1785 Error_Msg_NEL
1786 ("\?& will be raised for objects of this type",
1787 N, Standard_Constraint_Error, Eloc);
1788 else
1789 Error_Msg_NEL
1790 ("\?& will be raised at run time",
1791 N, Standard_Constraint_Error, Eloc);
1792 end if;
1794 else
1795 Error_Msg
1796 ("\static expression fails Constraint_Check", Eloc);
1797 Set_Error_Posted (N);
1798 end if;
1799 end if;
1800 end if;
1802 return N;
1803 end Compile_Time_Constraint_Error;
1805 -----------------------
1806 -- Conditional_Delay --
1807 -----------------------
1809 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
1810 begin
1811 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
1812 Set_Has_Delayed_Freeze (New_Ent);
1813 end if;
1814 end Conditional_Delay;
1816 -------------------------
1817 -- Copy_Parameter_List --
1818 -------------------------
1820 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
1821 Loc : constant Source_Ptr := Sloc (Subp_Id);
1822 Plist : List_Id;
1823 Formal : Entity_Id;
1825 begin
1826 if No (First_Formal (Subp_Id)) then
1827 return No_List;
1828 else
1829 Plist := New_List;
1830 Formal := First_Formal (Subp_Id);
1831 while Present (Formal) loop
1832 Append
1833 (Make_Parameter_Specification (Loc,
1834 Defining_Identifier =>
1835 Make_Defining_Identifier (Sloc (Formal),
1836 Chars => Chars (Formal)),
1837 In_Present => In_Present (Parent (Formal)),
1838 Out_Present => Out_Present (Parent (Formal)),
1839 Parameter_Type =>
1840 New_Reference_To (Etype (Formal), Loc),
1841 Expression =>
1842 New_Copy_Tree (Expression (Parent (Formal)))),
1843 Plist);
1845 Next_Formal (Formal);
1846 end loop;
1847 end if;
1849 return Plist;
1850 end Copy_Parameter_List;
1852 --------------------
1853 -- Current_Entity --
1854 --------------------
1856 -- The currently visible definition for a given identifier is the
1857 -- one most chained at the start of the visibility chain, i.e. the
1858 -- one that is referenced by the Node_Id value of the name of the
1859 -- given identifier.
1861 function Current_Entity (N : Node_Id) return Entity_Id is
1862 begin
1863 return Get_Name_Entity_Id (Chars (N));
1864 end Current_Entity;
1866 -----------------------------
1867 -- Current_Entity_In_Scope --
1868 -----------------------------
1870 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
1871 E : Entity_Id;
1872 CS : constant Entity_Id := Current_Scope;
1874 Transient_Case : constant Boolean := Scope_Is_Transient;
1876 begin
1877 E := Get_Name_Entity_Id (Chars (N));
1878 while Present (E)
1879 and then Scope (E) /= CS
1880 and then (not Transient_Case or else Scope (E) /= Scope (CS))
1881 loop
1882 E := Homonym (E);
1883 end loop;
1885 return E;
1886 end Current_Entity_In_Scope;
1888 -------------------
1889 -- Current_Scope --
1890 -------------------
1892 function Current_Scope return Entity_Id is
1893 begin
1894 if Scope_Stack.Last = -1 then
1895 return Standard_Standard;
1896 else
1897 declare
1898 C : constant Entity_Id :=
1899 Scope_Stack.Table (Scope_Stack.Last).Entity;
1900 begin
1901 if Present (C) then
1902 return C;
1903 else
1904 return Standard_Standard;
1905 end if;
1906 end;
1907 end if;
1908 end Current_Scope;
1910 ------------------------
1911 -- Current_Subprogram --
1912 ------------------------
1914 function Current_Subprogram return Entity_Id is
1915 Scop : constant Entity_Id := Current_Scope;
1916 begin
1917 if Is_Subprogram (Scop) or else Is_Generic_Subprogram (Scop) then
1918 return Scop;
1919 else
1920 return Enclosing_Subprogram (Scop);
1921 end if;
1922 end Current_Subprogram;
1924 ---------------------
1925 -- Defining_Entity --
1926 ---------------------
1928 function Defining_Entity (N : Node_Id) return Entity_Id is
1929 K : constant Node_Kind := Nkind (N);
1930 Err : Entity_Id := Empty;
1932 begin
1933 case K is
1934 when
1935 N_Subprogram_Declaration |
1936 N_Abstract_Subprogram_Declaration |
1937 N_Subprogram_Body |
1938 N_Package_Declaration |
1939 N_Subprogram_Renaming_Declaration |
1940 N_Subprogram_Body_Stub |
1941 N_Generic_Subprogram_Declaration |
1942 N_Generic_Package_Declaration |
1943 N_Formal_Subprogram_Declaration
1945 return Defining_Entity (Specification (N));
1947 when
1948 N_Component_Declaration |
1949 N_Defining_Program_Unit_Name |
1950 N_Discriminant_Specification |
1951 N_Entry_Body |
1952 N_Entry_Declaration |
1953 N_Entry_Index_Specification |
1954 N_Exception_Declaration |
1955 N_Exception_Renaming_Declaration |
1956 N_Formal_Object_Declaration |
1957 N_Formal_Package_Declaration |
1958 N_Formal_Type_Declaration |
1959 N_Full_Type_Declaration |
1960 N_Implicit_Label_Declaration |
1961 N_Incomplete_Type_Declaration |
1962 N_Loop_Parameter_Specification |
1963 N_Number_Declaration |
1964 N_Object_Declaration |
1965 N_Object_Renaming_Declaration |
1966 N_Package_Body_Stub |
1967 N_Parameter_Specification |
1968 N_Private_Extension_Declaration |
1969 N_Private_Type_Declaration |
1970 N_Protected_Body |
1971 N_Protected_Body_Stub |
1972 N_Protected_Type_Declaration |
1973 N_Single_Protected_Declaration |
1974 N_Single_Task_Declaration |
1975 N_Subtype_Declaration |
1976 N_Task_Body |
1977 N_Task_Body_Stub |
1978 N_Task_Type_Declaration
1980 return Defining_Identifier (N);
1982 when N_Subunit =>
1983 return Defining_Entity (Proper_Body (N));
1985 when
1986 N_Function_Instantiation |
1987 N_Function_Specification |
1988 N_Generic_Function_Renaming_Declaration |
1989 N_Generic_Package_Renaming_Declaration |
1990 N_Generic_Procedure_Renaming_Declaration |
1991 N_Package_Body |
1992 N_Package_Instantiation |
1993 N_Package_Renaming_Declaration |
1994 N_Package_Specification |
1995 N_Procedure_Instantiation |
1996 N_Procedure_Specification
1998 declare
1999 Nam : constant Node_Id := Defining_Unit_Name (N);
2001 begin
2002 if Nkind (Nam) in N_Entity then
2003 return Nam;
2005 -- For Error, make up a name and attach to declaration
2006 -- so we can continue semantic analysis
2008 elsif Nam = Error then
2009 Err :=
2010 Make_Defining_Identifier (Sloc (N),
2011 Chars => New_Internal_Name ('T'));
2012 Set_Defining_Unit_Name (N, Err);
2014 return Err;
2015 -- If not an entity, get defining identifier
2017 else
2018 return Defining_Identifier (Nam);
2019 end if;
2020 end;
2022 when N_Block_Statement =>
2023 return Entity (Identifier (N));
2025 when others =>
2026 raise Program_Error;
2028 end case;
2029 end Defining_Entity;
2031 --------------------------
2032 -- Denotes_Discriminant --
2033 --------------------------
2035 function Denotes_Discriminant
2036 (N : Node_Id;
2037 Check_Concurrent : Boolean := False) return Boolean
2039 E : Entity_Id;
2040 begin
2041 if not Is_Entity_Name (N)
2042 or else No (Entity (N))
2043 then
2044 return False;
2045 else
2046 E := Entity (N);
2047 end if;
2049 -- If we are checking for a protected type, the discriminant may have
2050 -- been rewritten as the corresponding discriminal of the original type
2051 -- or of the corresponding concurrent record, depending on whether we
2052 -- are in the spec or body of the protected type.
2054 return Ekind (E) = E_Discriminant
2055 or else
2056 (Check_Concurrent
2057 and then Ekind (E) = E_In_Parameter
2058 and then Present (Discriminal_Link (E))
2059 and then
2060 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
2061 or else
2062 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
2064 end Denotes_Discriminant;
2066 ----------------------
2067 -- Denotes_Variable --
2068 ----------------------
2070 function Denotes_Variable (N : Node_Id) return Boolean is
2071 begin
2072 return Is_Variable (N) and then Paren_Count (N) = 0;
2073 end Denotes_Variable;
2075 -----------------------------
2076 -- Depends_On_Discriminant --
2077 -----------------------------
2079 function Depends_On_Discriminant (N : Node_Id) return Boolean is
2080 L : Node_Id;
2081 H : Node_Id;
2083 begin
2084 Get_Index_Bounds (N, L, H);
2085 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
2086 end Depends_On_Discriminant;
2088 -------------------------
2089 -- Designate_Same_Unit --
2090 -------------------------
2092 function Designate_Same_Unit
2093 (Name1 : Node_Id;
2094 Name2 : Node_Id) return Boolean
2096 K1 : constant Node_Kind := Nkind (Name1);
2097 K2 : constant Node_Kind := Nkind (Name2);
2099 function Prefix_Node (N : Node_Id) return Node_Id;
2100 -- Returns the parent unit name node of a defining program unit name
2101 -- or the prefix if N is a selected component or an expanded name.
2103 function Select_Node (N : Node_Id) return Node_Id;
2104 -- Returns the defining identifier node of a defining program unit
2105 -- name or the selector node if N is a selected component or an
2106 -- expanded name.
2108 -----------------
2109 -- Prefix_Node --
2110 -----------------
2112 function Prefix_Node (N : Node_Id) return Node_Id is
2113 begin
2114 if Nkind (N) = N_Defining_Program_Unit_Name then
2115 return Name (N);
2117 else
2118 return Prefix (N);
2119 end if;
2120 end Prefix_Node;
2122 -----------------
2123 -- Select_Node --
2124 -----------------
2126 function Select_Node (N : Node_Id) return Node_Id is
2127 begin
2128 if Nkind (N) = N_Defining_Program_Unit_Name then
2129 return Defining_Identifier (N);
2131 else
2132 return Selector_Name (N);
2133 end if;
2134 end Select_Node;
2136 -- Start of processing for Designate_Next_Unit
2138 begin
2139 if (K1 = N_Identifier or else
2140 K1 = N_Defining_Identifier)
2141 and then
2142 (K2 = N_Identifier or else
2143 K2 = N_Defining_Identifier)
2144 then
2145 return Chars (Name1) = Chars (Name2);
2147 elsif
2148 (K1 = N_Expanded_Name or else
2149 K1 = N_Selected_Component or else
2150 K1 = N_Defining_Program_Unit_Name)
2151 and then
2152 (K2 = N_Expanded_Name or else
2153 K2 = N_Selected_Component or else
2154 K2 = N_Defining_Program_Unit_Name)
2155 then
2156 return
2157 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
2158 and then
2159 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
2161 else
2162 return False;
2163 end if;
2164 end Designate_Same_Unit;
2166 ----------------------------
2167 -- Enclosing_Generic_Body --
2168 ----------------------------
2170 function Enclosing_Generic_Body
2171 (N : Node_Id) return Node_Id
2173 P : Node_Id;
2174 Decl : Node_Id;
2175 Spec : Node_Id;
2177 begin
2178 P := Parent (N);
2179 while Present (P) loop
2180 if Nkind (P) = N_Package_Body
2181 or else Nkind (P) = N_Subprogram_Body
2182 then
2183 Spec := Corresponding_Spec (P);
2185 if Present (Spec) then
2186 Decl := Unit_Declaration_Node (Spec);
2188 if Nkind (Decl) = N_Generic_Package_Declaration
2189 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2190 then
2191 return P;
2192 end if;
2193 end if;
2194 end if;
2196 P := Parent (P);
2197 end loop;
2199 return Empty;
2200 end Enclosing_Generic_Body;
2202 ----------------------------
2203 -- Enclosing_Generic_Unit --
2204 ----------------------------
2206 function Enclosing_Generic_Unit
2207 (N : Node_Id) return Node_Id
2209 P : Node_Id;
2210 Decl : Node_Id;
2211 Spec : Node_Id;
2213 begin
2214 P := Parent (N);
2215 while Present (P) loop
2216 if Nkind (P) = N_Generic_Package_Declaration
2217 or else Nkind (P) = N_Generic_Subprogram_Declaration
2218 then
2219 return P;
2221 elsif Nkind (P) = N_Package_Body
2222 or else Nkind (P) = N_Subprogram_Body
2223 then
2224 Spec := Corresponding_Spec (P);
2226 if Present (Spec) then
2227 Decl := Unit_Declaration_Node (Spec);
2229 if Nkind (Decl) = N_Generic_Package_Declaration
2230 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2231 then
2232 return Decl;
2233 end if;
2234 end if;
2235 end if;
2237 P := Parent (P);
2238 end loop;
2240 return Empty;
2241 end Enclosing_Generic_Unit;
2243 -------------------------------
2244 -- Enclosing_Lib_Unit_Entity --
2245 -------------------------------
2247 function Enclosing_Lib_Unit_Entity return Entity_Id is
2248 Unit_Entity : Entity_Id;
2250 begin
2251 -- Look for enclosing library unit entity by following scope links.
2252 -- Equivalent to, but faster than indexing through the scope stack.
2254 Unit_Entity := Current_Scope;
2255 while (Present (Scope (Unit_Entity))
2256 and then Scope (Unit_Entity) /= Standard_Standard)
2257 and not Is_Child_Unit (Unit_Entity)
2258 loop
2259 Unit_Entity := Scope (Unit_Entity);
2260 end loop;
2262 return Unit_Entity;
2263 end Enclosing_Lib_Unit_Entity;
2265 -----------------------------
2266 -- Enclosing_Lib_Unit_Node --
2267 -----------------------------
2269 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
2270 Current_Node : Node_Id;
2272 begin
2273 Current_Node := N;
2274 while Present (Current_Node)
2275 and then Nkind (Current_Node) /= N_Compilation_Unit
2276 loop
2277 Current_Node := Parent (Current_Node);
2278 end loop;
2280 if Nkind (Current_Node) /= N_Compilation_Unit then
2281 return Empty;
2282 end if;
2284 return Current_Node;
2285 end Enclosing_Lib_Unit_Node;
2287 --------------------------
2288 -- Enclosing_Subprogram --
2289 --------------------------
2291 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
2292 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
2294 begin
2295 if Dynamic_Scope = Standard_Standard then
2296 return Empty;
2298 elsif Dynamic_Scope = Empty then
2299 return Empty;
2301 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
2302 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
2304 elsif Ekind (Dynamic_Scope) = E_Block
2305 or else Ekind (Dynamic_Scope) = E_Return_Statement
2306 then
2307 return Enclosing_Subprogram (Dynamic_Scope);
2309 elsif Ekind (Dynamic_Scope) = E_Task_Type then
2310 return Get_Task_Body_Procedure (Dynamic_Scope);
2312 elsif Convention (Dynamic_Scope) = Convention_Protected then
2313 return Protected_Body_Subprogram (Dynamic_Scope);
2315 else
2316 return Dynamic_Scope;
2317 end if;
2318 end Enclosing_Subprogram;
2320 ------------------------
2321 -- Ensure_Freeze_Node --
2322 ------------------------
2324 procedure Ensure_Freeze_Node (E : Entity_Id) is
2325 FN : Node_Id;
2327 begin
2328 if No (Freeze_Node (E)) then
2329 FN := Make_Freeze_Entity (Sloc (E));
2330 Set_Has_Delayed_Freeze (E);
2331 Set_Freeze_Node (E, FN);
2332 Set_Access_Types_To_Process (FN, No_Elist);
2333 Set_TSS_Elist (FN, No_Elist);
2334 Set_Entity (FN, E);
2335 end if;
2336 end Ensure_Freeze_Node;
2338 ----------------
2339 -- Enter_Name --
2340 ----------------
2342 procedure Enter_Name (Def_Id : Entity_Id) is
2343 C : constant Entity_Id := Current_Entity (Def_Id);
2344 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
2345 S : constant Entity_Id := Current_Scope;
2347 begin
2348 Generate_Definition (Def_Id);
2350 -- Add new name to current scope declarations. Check for duplicate
2351 -- declaration, which may or may not be a genuine error.
2353 if Present (E) then
2355 -- Case of previous entity entered because of a missing declaration
2356 -- or else a bad subtype indication. Best is to use the new entity,
2357 -- and make the previous one invisible.
2359 if Etype (E) = Any_Type then
2360 Set_Is_Immediately_Visible (E, False);
2362 -- Case of renaming declaration constructed for package instances.
2363 -- if there is an explicit declaration with the same identifier,
2364 -- the renaming is not immediately visible any longer, but remains
2365 -- visible through selected component notation.
2367 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
2368 and then not Comes_From_Source (E)
2369 then
2370 Set_Is_Immediately_Visible (E, False);
2372 -- The new entity may be the package renaming, which has the same
2373 -- same name as a generic formal which has been seen already.
2375 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
2376 and then not Comes_From_Source (Def_Id)
2377 then
2378 Set_Is_Immediately_Visible (E, False);
2380 -- For a fat pointer corresponding to a remote access to subprogram,
2381 -- we use the same identifier as the RAS type, so that the proper
2382 -- name appears in the stub. This type is only retrieved through
2383 -- the RAS type and never by visibility, and is not added to the
2384 -- visibility list (see below).
2386 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
2387 and then Present (Corresponding_Remote_Type (Def_Id))
2388 then
2389 null;
2391 -- A controller component for a type extension overrides the
2392 -- inherited component.
2394 elsif Chars (E) = Name_uController then
2395 null;
2397 -- Case of an implicit operation or derived literal. The new entity
2398 -- hides the implicit one, which is removed from all visibility,
2399 -- i.e. the entity list of its scope, and homonym chain of its name.
2401 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
2402 or else Is_Internal (E)
2403 then
2404 declare
2405 Prev : Entity_Id;
2406 Prev_Vis : Entity_Id;
2407 Decl : constant Node_Id := Parent (E);
2409 begin
2410 -- If E is an implicit declaration, it cannot be the first
2411 -- entity in the scope.
2413 Prev := First_Entity (Current_Scope);
2414 while Present (Prev)
2415 and then Next_Entity (Prev) /= E
2416 loop
2417 Next_Entity (Prev);
2418 end loop;
2420 if No (Prev) then
2422 -- If E is not on the entity chain of the current scope,
2423 -- it is an implicit declaration in the generic formal
2424 -- part of a generic subprogram. When analyzing the body,
2425 -- the generic formals are visible but not on the entity
2426 -- chain of the subprogram. The new entity will become
2427 -- the visible one in the body.
2429 pragma Assert
2430 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
2431 null;
2433 else
2434 Set_Next_Entity (Prev, Next_Entity (E));
2436 if No (Next_Entity (Prev)) then
2437 Set_Last_Entity (Current_Scope, Prev);
2438 end if;
2440 if E = Current_Entity (E) then
2441 Prev_Vis := Empty;
2443 else
2444 Prev_Vis := Current_Entity (E);
2445 while Homonym (Prev_Vis) /= E loop
2446 Prev_Vis := Homonym (Prev_Vis);
2447 end loop;
2448 end if;
2450 if Present (Prev_Vis) then
2452 -- Skip E in the visibility chain
2454 Set_Homonym (Prev_Vis, Homonym (E));
2456 else
2457 Set_Name_Entity_Id (Chars (E), Homonym (E));
2458 end if;
2459 end if;
2460 end;
2462 -- This section of code could use a comment ???
2464 elsif Present (Etype (E))
2465 and then Is_Concurrent_Type (Etype (E))
2466 and then E = Def_Id
2467 then
2468 return;
2470 -- If the homograph is a protected component renaming, it should not
2471 -- be hiding the current entity. Such renamings are treated as weak
2472 -- declarations.
2474 elsif Is_Prival (E) then
2475 Set_Is_Immediately_Visible (E, False);
2477 -- In this case the current entity is a protected component renaming.
2478 -- Perform minimal decoration by setting the scope and return since
2479 -- the prival should not be hiding other visible entities.
2481 elsif Is_Prival (Def_Id) then
2482 Set_Scope (Def_Id, Current_Scope);
2483 return;
2485 -- Analogous to privals, the discriminal generated for an entry
2486 -- index parameter acts as a weak declaration. Perform minimal
2487 -- decoration to avoid bogus errors.
2489 elsif Is_Discriminal (Def_Id)
2490 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
2491 then
2492 Set_Scope (Def_Id, Current_Scope);
2493 return;
2495 -- In the body or private part of an instance, a type extension
2496 -- may introduce a component with the same name as that of an
2497 -- actual. The legality rule is not enforced, but the semantics
2498 -- of the full type with two components of the same name are not
2499 -- clear at this point ???
2501 elsif In_Instance_Not_Visible then
2502 null;
2504 -- When compiling a package body, some child units may have become
2505 -- visible. They cannot conflict with local entities that hide them.
2507 elsif Is_Child_Unit (E)
2508 and then In_Open_Scopes (Scope (E))
2509 and then not Is_Immediately_Visible (E)
2510 then
2511 null;
2513 -- Conversely, with front-end inlining we may compile the parent
2514 -- body first, and a child unit subsequently. The context is now
2515 -- the parent spec, and body entities are not visible.
2517 elsif Is_Child_Unit (Def_Id)
2518 and then Is_Package_Body_Entity (E)
2519 and then not In_Package_Body (Current_Scope)
2520 then
2521 null;
2523 -- Case of genuine duplicate declaration
2525 else
2526 Error_Msg_Sloc := Sloc (E);
2528 -- If the previous declaration is an incomplete type declaration
2529 -- this may be an attempt to complete it with a private type.
2530 -- The following avoids confusing cascaded errors.
2532 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
2533 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
2534 then
2535 Error_Msg_N
2536 ("incomplete type cannot be completed with a private " &
2537 "declaration", Parent (Def_Id));
2538 Set_Is_Immediately_Visible (E, False);
2539 Set_Full_View (E, Def_Id);
2541 -- An inherited component of a record conflicts with a new
2542 -- discriminant. The discriminant is inserted first in the scope,
2543 -- but the error should be posted on it, not on the component.
2545 elsif Ekind (E) = E_Discriminant
2546 and then Present (Scope (Def_Id))
2547 and then Scope (Def_Id) /= Current_Scope
2548 then
2549 Error_Msg_Sloc := Sloc (Def_Id);
2550 Error_Msg_N ("& conflicts with declaration#", E);
2551 return;
2553 -- If the name of the unit appears in its own context clause,
2554 -- a dummy package with the name has already been created, and
2555 -- the error emitted. Try to continue quietly.
2557 elsif Error_Posted (E)
2558 and then Sloc (E) = No_Location
2559 and then Nkind (Parent (E)) = N_Package_Specification
2560 and then Current_Scope = Standard_Standard
2561 then
2562 Set_Scope (Def_Id, Current_Scope);
2563 return;
2565 else
2566 Error_Msg_N ("& conflicts with declaration#", Def_Id);
2568 -- Avoid cascaded messages with duplicate components in
2569 -- derived types.
2571 if Ekind (E) = E_Component
2572 or else Ekind (E) = E_Discriminant
2573 then
2574 return;
2575 end if;
2576 end if;
2578 if Nkind (Parent (Parent (Def_Id))) =
2579 N_Generic_Subprogram_Declaration
2580 and then Def_Id =
2581 Defining_Entity (Specification (Parent (Parent (Def_Id))))
2582 then
2583 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
2584 end if;
2586 -- If entity is in standard, then we are in trouble, because
2587 -- it means that we have a library package with a duplicated
2588 -- name. That's hard to recover from, so abort!
2590 if S = Standard_Standard then
2591 raise Unrecoverable_Error;
2593 -- Otherwise we continue with the declaration. Having two
2594 -- identical declarations should not cause us too much trouble!
2596 else
2597 null;
2598 end if;
2599 end if;
2600 end if;
2602 -- If we fall through, declaration is OK , or OK enough to continue
2604 -- If Def_Id is a discriminant or a record component we are in the
2605 -- midst of inheriting components in a derived record definition.
2606 -- Preserve their Ekind and Etype.
2608 if Ekind (Def_Id) = E_Discriminant
2609 or else Ekind (Def_Id) = E_Component
2610 then
2611 null;
2613 -- If a type is already set, leave it alone (happens whey a type
2614 -- declaration is reanalyzed following a call to the optimizer)
2616 elsif Present (Etype (Def_Id)) then
2617 null;
2619 -- Otherwise, the kind E_Void insures that premature uses of the entity
2620 -- will be detected. Any_Type insures that no cascaded errors will occur
2622 else
2623 Set_Ekind (Def_Id, E_Void);
2624 Set_Etype (Def_Id, Any_Type);
2625 end if;
2627 -- Inherited discriminants and components in derived record types are
2628 -- immediately visible. Itypes are not.
2630 if Ekind (Def_Id) = E_Discriminant
2631 or else Ekind (Def_Id) = E_Component
2632 or else (No (Corresponding_Remote_Type (Def_Id))
2633 and then not Is_Itype (Def_Id))
2634 then
2635 Set_Is_Immediately_Visible (Def_Id);
2636 Set_Current_Entity (Def_Id);
2637 end if;
2639 Set_Homonym (Def_Id, C);
2640 Append_Entity (Def_Id, S);
2641 Set_Public_Status (Def_Id);
2643 -- Warn if new entity hides an old one
2645 if Warn_On_Hiding and then Present (C)
2647 -- Don't warn for record components since they always have a well
2648 -- defined scope which does not confuse other uses. Note that in
2649 -- some cases, Ekind has not been set yet.
2651 and then Ekind (C) /= E_Component
2652 and then Ekind (C) /= E_Discriminant
2653 and then Nkind (Parent (C)) /= N_Component_Declaration
2654 and then Ekind (Def_Id) /= E_Component
2655 and then Ekind (Def_Id) /= E_Discriminant
2656 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
2658 -- Don't warn for one character variables. It is too common to use
2659 -- such variables as locals and will just cause too many false hits.
2661 and then Length_Of_Name (Chars (C)) /= 1
2663 -- Don't warn for non-source entities
2665 and then Comes_From_Source (C)
2666 and then Comes_From_Source (Def_Id)
2668 -- Don't warn unless entity in question is in extended main source
2670 and then In_Extended_Main_Source_Unit (Def_Id)
2672 -- Finally, the hidden entity must be either immediately visible
2673 -- or use visible (from a used package)
2675 and then
2676 (Is_Immediately_Visible (C)
2677 or else
2678 Is_Potentially_Use_Visible (C))
2679 then
2680 Error_Msg_Sloc := Sloc (C);
2681 Error_Msg_N ("declaration hides &#?", Def_Id);
2682 end if;
2683 end Enter_Name;
2685 --------------------------
2686 -- Explain_Limited_Type --
2687 --------------------------
2689 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
2690 C : Entity_Id;
2692 begin
2693 -- For array, component type must be limited
2695 if Is_Array_Type (T) then
2696 Error_Msg_Node_2 := T;
2697 Error_Msg_NE
2698 ("\component type& of type& is limited", N, Component_Type (T));
2699 Explain_Limited_Type (Component_Type (T), N);
2701 elsif Is_Record_Type (T) then
2703 -- No need for extra messages if explicit limited record
2705 if Is_Limited_Record (Base_Type (T)) then
2706 return;
2707 end if;
2709 -- Otherwise find a limited component. Check only components that
2710 -- come from source, or inherited components that appear in the
2711 -- source of the ancestor.
2713 C := First_Component (T);
2714 while Present (C) loop
2715 if Is_Limited_Type (Etype (C))
2716 and then
2717 (Comes_From_Source (C)
2718 or else
2719 (Present (Original_Record_Component (C))
2720 and then
2721 Comes_From_Source (Original_Record_Component (C))))
2722 then
2723 Error_Msg_Node_2 := T;
2724 Error_Msg_NE ("\component& of type& has limited type", N, C);
2725 Explain_Limited_Type (Etype (C), N);
2726 return;
2727 end if;
2729 Next_Component (C);
2730 end loop;
2732 -- The type may be declared explicitly limited, even if no component
2733 -- of it is limited, in which case we fall out of the loop.
2734 return;
2735 end if;
2736 end Explain_Limited_Type;
2738 -----------------
2739 -- Find_Actual --
2740 -----------------
2742 procedure Find_Actual
2743 (N : Node_Id;
2744 Formal : out Entity_Id;
2745 Call : out Node_Id)
2747 Parnt : constant Node_Id := Parent (N);
2748 Actual : Node_Id;
2750 begin
2751 if (Nkind (Parnt) = N_Indexed_Component
2752 or else
2753 Nkind (Parnt) = N_Selected_Component)
2754 and then N = Prefix (Parnt)
2755 then
2756 Find_Actual (Parnt, Formal, Call);
2757 return;
2759 elsif Nkind (Parnt) = N_Parameter_Association
2760 and then N = Explicit_Actual_Parameter (Parnt)
2761 then
2762 Call := Parent (Parnt);
2764 elsif Nkind (Parnt) = N_Procedure_Call_Statement then
2765 Call := Parnt;
2767 else
2768 Formal := Empty;
2769 Call := Empty;
2770 return;
2771 end if;
2773 -- If we have a call to a subprogram look for the parameter. Note that
2774 -- we exclude overloaded calls, since we don't know enough to be sure
2775 -- of giving the right answer in this case.
2777 if Is_Entity_Name (Name (Call))
2778 and then Present (Entity (Name (Call)))
2779 and then Is_Overloadable (Entity (Name (Call)))
2780 and then not Is_Overloaded (Name (Call))
2781 then
2782 -- Fall here if we are definitely a parameter
2784 Actual := First_Actual (Call);
2785 Formal := First_Formal (Entity (Name (Call)));
2786 while Present (Formal) and then Present (Actual) loop
2787 if Actual = N then
2788 return;
2789 else
2790 Actual := Next_Actual (Actual);
2791 Formal := Next_Formal (Formal);
2792 end if;
2793 end loop;
2794 end if;
2796 -- Fall through here if we did not find matching actual
2798 Formal := Empty;
2799 Call := Empty;
2800 end Find_Actual;
2802 -------------------------------------
2803 -- Find_Corresponding_Discriminant --
2804 -------------------------------------
2806 function Find_Corresponding_Discriminant
2807 (Id : Node_Id;
2808 Typ : Entity_Id) return Entity_Id
2810 Par_Disc : Entity_Id;
2811 Old_Disc : Entity_Id;
2812 New_Disc : Entity_Id;
2814 begin
2815 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
2817 -- The original type may currently be private, and the discriminant
2818 -- only appear on its full view.
2820 if Is_Private_Type (Scope (Par_Disc))
2821 and then not Has_Discriminants (Scope (Par_Disc))
2822 and then Present (Full_View (Scope (Par_Disc)))
2823 then
2824 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
2825 else
2826 Old_Disc := First_Discriminant (Scope (Par_Disc));
2827 end if;
2829 if Is_Class_Wide_Type (Typ) then
2830 New_Disc := First_Discriminant (Root_Type (Typ));
2831 else
2832 New_Disc := First_Discriminant (Typ);
2833 end if;
2835 while Present (Old_Disc) and then Present (New_Disc) loop
2836 if Old_Disc = Par_Disc then
2837 return New_Disc;
2838 else
2839 Next_Discriminant (Old_Disc);
2840 Next_Discriminant (New_Disc);
2841 end if;
2842 end loop;
2844 -- Should always find it
2846 raise Program_Error;
2847 end Find_Corresponding_Discriminant;
2849 --------------------------
2850 -- Find_Overlaid_Object --
2851 --------------------------
2853 function Find_Overlaid_Object (N : Node_Id) return Entity_Id is
2854 Expr : Node_Id;
2856 begin
2857 -- We are looking for one of the two following forms:
2859 -- for X'Address use Y'Address
2861 -- or
2863 -- Const : constant Address := expr;
2864 -- ...
2865 -- for X'Address use Const;
2867 -- In the second case, the expr is either Y'Address, or recursively a
2868 -- constant that eventually references Y'Address.
2870 if Nkind (N) = N_Attribute_Definition_Clause
2871 and then Chars (N) = Name_Address
2872 then
2873 -- This loop checks the form of the expression for Y'Address where Y
2874 -- is an object entity name. The first loop checks the original
2875 -- expression in the attribute definition clause. Subsequent loops
2876 -- check referenced constants.
2878 Expr := Expression (N);
2879 loop
2880 -- Check for Y'Address where Y is an object entity
2882 if Nkind (Expr) = N_Attribute_Reference
2883 and then Attribute_Name (Expr) = Name_Address
2884 and then Is_Entity_Name (Prefix (Expr))
2885 and then Is_Object (Entity (Prefix (Expr)))
2886 then
2887 return Entity (Prefix (Expr));
2889 -- Check for Const where Const is a constant entity
2891 elsif Is_Entity_Name (Expr)
2892 and then Ekind (Entity (Expr)) = E_Constant
2893 then
2894 Expr := Constant_Value (Entity (Expr));
2896 -- Anything else does not need checking
2898 else
2899 exit;
2900 end if;
2901 end loop;
2902 end if;
2904 return Empty;
2905 end Find_Overlaid_Object;
2907 -------------------------
2908 -- Find_Parameter_Type --
2909 -------------------------
2911 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
2912 begin
2913 if Nkind (Param) /= N_Parameter_Specification then
2914 return Empty;
2916 -- For an access parameter, obtain the type from the formal entity
2917 -- itself, because access to subprogram nodes do not carry a type.
2918 -- Shouldn't we always use the formal entity ???
2920 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
2921 return Etype (Defining_Identifier (Param));
2923 else
2924 return Etype (Parameter_Type (Param));
2925 end if;
2926 end Find_Parameter_Type;
2928 -----------------------------
2929 -- Find_Static_Alternative --
2930 -----------------------------
2932 function Find_Static_Alternative (N : Node_Id) return Node_Id is
2933 Expr : constant Node_Id := Expression (N);
2934 Val : constant Uint := Expr_Value (Expr);
2935 Alt : Node_Id;
2936 Choice : Node_Id;
2938 begin
2939 Alt := First (Alternatives (N));
2941 Search : loop
2942 if Nkind (Alt) /= N_Pragma then
2943 Choice := First (Discrete_Choices (Alt));
2944 while Present (Choice) loop
2946 -- Others choice, always matches
2948 if Nkind (Choice) = N_Others_Choice then
2949 exit Search;
2951 -- Range, check if value is in the range
2953 elsif Nkind (Choice) = N_Range then
2954 exit Search when
2955 Val >= Expr_Value (Low_Bound (Choice))
2956 and then
2957 Val <= Expr_Value (High_Bound (Choice));
2959 -- Choice is a subtype name. Note that we know it must
2960 -- be a static subtype, since otherwise it would have
2961 -- been diagnosed as illegal.
2963 elsif Is_Entity_Name (Choice)
2964 and then Is_Type (Entity (Choice))
2965 then
2966 exit Search when Is_In_Range (Expr, Etype (Choice));
2968 -- Choice is a subtype indication
2970 elsif Nkind (Choice) = N_Subtype_Indication then
2971 declare
2972 C : constant Node_Id := Constraint (Choice);
2973 R : constant Node_Id := Range_Expression (C);
2975 begin
2976 exit Search when
2977 Val >= Expr_Value (Low_Bound (R))
2978 and then
2979 Val <= Expr_Value (High_Bound (R));
2980 end;
2982 -- Choice is a simple expression
2984 else
2985 exit Search when Val = Expr_Value (Choice);
2986 end if;
2988 Next (Choice);
2989 end loop;
2990 end if;
2992 Next (Alt);
2993 pragma Assert (Present (Alt));
2994 end loop Search;
2996 -- The above loop *must* terminate by finding a match, since
2997 -- we know the case statement is valid, and the value of the
2998 -- expression is known at compile time. When we fall out of
2999 -- the loop, Alt points to the alternative that we know will
3000 -- be selected at run time.
3002 return Alt;
3003 end Find_Static_Alternative;
3005 ------------------
3006 -- First_Actual --
3007 ------------------
3009 function First_Actual (Node : Node_Id) return Node_Id is
3010 N : Node_Id;
3012 begin
3013 if No (Parameter_Associations (Node)) then
3014 return Empty;
3015 end if;
3017 N := First (Parameter_Associations (Node));
3019 if Nkind (N) = N_Parameter_Association then
3020 return First_Named_Actual (Node);
3021 else
3022 return N;
3023 end if;
3024 end First_Actual;
3026 -------------------------
3027 -- Full_Qualified_Name --
3028 -------------------------
3030 function Full_Qualified_Name (E : Entity_Id) return String_Id is
3031 Res : String_Id;
3032 pragma Warnings (Off, Res);
3034 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id;
3035 -- Compute recursively the qualified name without NUL at the end
3037 ----------------------------------
3038 -- Internal_Full_Qualified_Name --
3039 ----------------------------------
3041 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id is
3042 Ent : Entity_Id := E;
3043 Parent_Name : String_Id := No_String;
3045 begin
3046 -- Deals properly with child units
3048 if Nkind (Ent) = N_Defining_Program_Unit_Name then
3049 Ent := Defining_Identifier (Ent);
3050 end if;
3052 -- Compute qualification recursively (only "Standard" has no scope)
3054 if Present (Scope (Scope (Ent))) then
3055 Parent_Name := Internal_Full_Qualified_Name (Scope (Ent));
3056 end if;
3058 -- Every entity should have a name except some expanded blocks
3059 -- don't bother about those.
3061 if Chars (Ent) = No_Name then
3062 return Parent_Name;
3063 end if;
3065 -- Add a period between Name and qualification
3067 if Parent_Name /= No_String then
3068 Start_String (Parent_Name);
3069 Store_String_Char (Get_Char_Code ('.'));
3071 else
3072 Start_String;
3073 end if;
3075 -- Generates the entity name in upper case
3077 Get_Decoded_Name_String (Chars (Ent));
3078 Set_All_Upper_Case;
3079 Store_String_Chars (Name_Buffer (1 .. Name_Len));
3080 return End_String;
3081 end Internal_Full_Qualified_Name;
3083 -- Start of processing for Full_Qualified_Name
3085 begin
3086 Res := Internal_Full_Qualified_Name (E);
3087 Store_String_Char (Get_Char_Code (ASCII.NUL));
3088 return End_String;
3089 end Full_Qualified_Name;
3091 -----------------------
3092 -- Gather_Components --
3093 -----------------------
3095 procedure Gather_Components
3096 (Typ : Entity_Id;
3097 Comp_List : Node_Id;
3098 Governed_By : List_Id;
3099 Into : Elist_Id;
3100 Report_Errors : out Boolean)
3102 Assoc : Node_Id;
3103 Variant : Node_Id;
3104 Discrete_Choice : Node_Id;
3105 Comp_Item : Node_Id;
3107 Discrim : Entity_Id;
3108 Discrim_Name : Node_Id;
3109 Discrim_Value : Node_Id;
3111 begin
3112 Report_Errors := False;
3114 if No (Comp_List) or else Null_Present (Comp_List) then
3115 return;
3117 elsif Present (Component_Items (Comp_List)) then
3118 Comp_Item := First (Component_Items (Comp_List));
3120 else
3121 Comp_Item := Empty;
3122 end if;
3124 while Present (Comp_Item) loop
3126 -- Skip the tag of a tagged record, the interface tags, as well
3127 -- as all items that are not user components (anonymous types,
3128 -- rep clauses, Parent field, controller field).
3130 if Nkind (Comp_Item) = N_Component_Declaration then
3131 declare
3132 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
3133 begin
3134 if not Is_Tag (Comp)
3135 and then Chars (Comp) /= Name_uParent
3136 and then Chars (Comp) /= Name_uController
3137 then
3138 Append_Elmt (Comp, Into);
3139 end if;
3140 end;
3141 end if;
3143 Next (Comp_Item);
3144 end loop;
3146 if No (Variant_Part (Comp_List)) then
3147 return;
3148 else
3149 Discrim_Name := Name (Variant_Part (Comp_List));
3150 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
3151 end if;
3153 -- Look for the discriminant that governs this variant part.
3154 -- The discriminant *must* be in the Governed_By List
3156 Assoc := First (Governed_By);
3157 Find_Constraint : loop
3158 Discrim := First (Choices (Assoc));
3159 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
3160 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
3161 and then
3162 Chars (Corresponding_Discriminant (Entity (Discrim)))
3163 = Chars (Discrim_Name))
3164 or else Chars (Original_Record_Component (Entity (Discrim)))
3165 = Chars (Discrim_Name);
3167 if No (Next (Assoc)) then
3168 if not Is_Constrained (Typ)
3169 and then Is_Derived_Type (Typ)
3170 and then Present (Stored_Constraint (Typ))
3171 then
3172 -- If the type is a tagged type with inherited discriminants,
3173 -- use the stored constraint on the parent in order to find
3174 -- the values of discriminants that are otherwise hidden by an
3175 -- explicit constraint. Renamed discriminants are handled in
3176 -- the code above.
3178 -- If several parent discriminants are renamed by a single
3179 -- discriminant of the derived type, the call to obtain the
3180 -- Corresponding_Discriminant field only retrieves the last
3181 -- of them. We recover the constraint on the others from the
3182 -- Stored_Constraint as well.
3184 declare
3185 D : Entity_Id;
3186 C : Elmt_Id;
3188 begin
3189 D := First_Discriminant (Etype (Typ));
3190 C := First_Elmt (Stored_Constraint (Typ));
3191 while Present (D) and then Present (C) loop
3192 if Chars (Discrim_Name) = Chars (D) then
3193 if Is_Entity_Name (Node (C))
3194 and then Entity (Node (C)) = Entity (Discrim)
3195 then
3196 -- D is renamed by Discrim, whose value is given in
3197 -- Assoc.
3199 null;
3201 else
3202 Assoc :=
3203 Make_Component_Association (Sloc (Typ),
3204 New_List
3205 (New_Occurrence_Of (D, Sloc (Typ))),
3206 Duplicate_Subexpr_No_Checks (Node (C)));
3207 end if;
3208 exit Find_Constraint;
3209 end if;
3211 Next_Discriminant (D);
3212 Next_Elmt (C);
3213 end loop;
3214 end;
3215 end if;
3216 end if;
3218 if No (Next (Assoc)) then
3219 Error_Msg_NE (" missing value for discriminant&",
3220 First (Governed_By), Discrim_Name);
3221 Report_Errors := True;
3222 return;
3223 end if;
3225 Next (Assoc);
3226 end loop Find_Constraint;
3228 Discrim_Value := Expression (Assoc);
3230 if not Is_OK_Static_Expression (Discrim_Value) then
3231 Error_Msg_FE
3232 ("value for discriminant & must be static!",
3233 Discrim_Value, Discrim);
3234 Why_Not_Static (Discrim_Value);
3235 Report_Errors := True;
3236 return;
3237 end if;
3239 Search_For_Discriminant_Value : declare
3240 Low : Node_Id;
3241 High : Node_Id;
3243 UI_High : Uint;
3244 UI_Low : Uint;
3245 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
3247 begin
3248 Find_Discrete_Value : while Present (Variant) loop
3249 Discrete_Choice := First (Discrete_Choices (Variant));
3250 while Present (Discrete_Choice) loop
3252 exit Find_Discrete_Value when
3253 Nkind (Discrete_Choice) = N_Others_Choice;
3255 Get_Index_Bounds (Discrete_Choice, Low, High);
3257 UI_Low := Expr_Value (Low);
3258 UI_High := Expr_Value (High);
3260 exit Find_Discrete_Value when
3261 UI_Low <= UI_Discrim_Value
3262 and then
3263 UI_High >= UI_Discrim_Value;
3265 Next (Discrete_Choice);
3266 end loop;
3268 Next_Non_Pragma (Variant);
3269 end loop Find_Discrete_Value;
3270 end Search_For_Discriminant_Value;
3272 if No (Variant) then
3273 Error_Msg_NE
3274 ("value of discriminant & is out of range", Discrim_Value, Discrim);
3275 Report_Errors := True;
3276 return;
3277 end if;
3279 -- If we have found the corresponding choice, recursively add its
3280 -- components to the Into list.
3282 Gather_Components (Empty,
3283 Component_List (Variant), Governed_By, Into, Report_Errors);
3284 end Gather_Components;
3286 ------------------------
3287 -- Get_Actual_Subtype --
3288 ------------------------
3290 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
3291 Typ : constant Entity_Id := Etype (N);
3292 Utyp : Entity_Id := Underlying_Type (Typ);
3293 Decl : Node_Id;
3294 Atyp : Entity_Id;
3296 begin
3297 if No (Utyp) then
3298 Utyp := Typ;
3299 end if;
3301 -- If what we have is an identifier that references a subprogram
3302 -- formal, or a variable or constant object, then we get the actual
3303 -- subtype from the referenced entity if one has been built.
3305 if Nkind (N) = N_Identifier
3306 and then
3307 (Is_Formal (Entity (N))
3308 or else Ekind (Entity (N)) = E_Constant
3309 or else Ekind (Entity (N)) = E_Variable)
3310 and then Present (Actual_Subtype (Entity (N)))
3311 then
3312 return Actual_Subtype (Entity (N));
3314 -- Actual subtype of unchecked union is always itself. We never need
3315 -- the "real" actual subtype. If we did, we couldn't get it anyway
3316 -- because the discriminant is not available. The restrictions on
3317 -- Unchecked_Union are designed to make sure that this is OK.
3319 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
3320 return Typ;
3322 -- Here for the unconstrained case, we must find actual subtype
3323 -- No actual subtype is available, so we must build it on the fly.
3325 -- Checking the type, not the underlying type, for constrainedness
3326 -- seems to be necessary. Maybe all the tests should be on the type???
3328 elsif (not Is_Constrained (Typ))
3329 and then (Is_Array_Type (Utyp)
3330 or else (Is_Record_Type (Utyp)
3331 and then Has_Discriminants (Utyp)))
3332 and then not Has_Unknown_Discriminants (Utyp)
3333 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
3334 then
3335 -- Nothing to do if in spec expression (why not???)
3337 if In_Spec_Expression then
3338 return Typ;
3340 elsif Is_Private_Type (Typ)
3341 and then not Has_Discriminants (Typ)
3342 then
3343 -- If the type has no discriminants, there is no subtype to
3344 -- build, even if the underlying type is discriminated.
3346 return Typ;
3348 -- Else build the actual subtype
3350 else
3351 Decl := Build_Actual_Subtype (Typ, N);
3352 Atyp := Defining_Identifier (Decl);
3354 -- If Build_Actual_Subtype generated a new declaration then use it
3356 if Atyp /= Typ then
3358 -- The actual subtype is an Itype, so analyze the declaration,
3359 -- but do not attach it to the tree, to get the type defined.
3361 Set_Parent (Decl, N);
3362 Set_Is_Itype (Atyp);
3363 Analyze (Decl, Suppress => All_Checks);
3364 Set_Associated_Node_For_Itype (Atyp, N);
3365 Set_Has_Delayed_Freeze (Atyp, False);
3367 -- We need to freeze the actual subtype immediately. This is
3368 -- needed, because otherwise this Itype will not get frozen
3369 -- at all, and it is always safe to freeze on creation because
3370 -- any associated types must be frozen at this point.
3372 Freeze_Itype (Atyp, N);
3373 return Atyp;
3375 -- Otherwise we did not build a declaration, so return original
3377 else
3378 return Typ;
3379 end if;
3380 end if;
3382 -- For all remaining cases, the actual subtype is the same as
3383 -- the nominal type.
3385 else
3386 return Typ;
3387 end if;
3388 end Get_Actual_Subtype;
3390 -------------------------------------
3391 -- Get_Actual_Subtype_If_Available --
3392 -------------------------------------
3394 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
3395 Typ : constant Entity_Id := Etype (N);
3397 begin
3398 -- If what we have is an identifier that references a subprogram
3399 -- formal, or a variable or constant object, then we get the actual
3400 -- subtype from the referenced entity if one has been built.
3402 if Nkind (N) = N_Identifier
3403 and then
3404 (Is_Formal (Entity (N))
3405 or else Ekind (Entity (N)) = E_Constant
3406 or else Ekind (Entity (N)) = E_Variable)
3407 and then Present (Actual_Subtype (Entity (N)))
3408 then
3409 return Actual_Subtype (Entity (N));
3411 -- Otherwise the Etype of N is returned unchanged
3413 else
3414 return Typ;
3415 end if;
3416 end Get_Actual_Subtype_If_Available;
3418 -------------------------------
3419 -- Get_Default_External_Name --
3420 -------------------------------
3422 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
3423 begin
3424 Get_Decoded_Name_String (Chars (E));
3426 if Opt.External_Name_Imp_Casing = Uppercase then
3427 Set_Casing (All_Upper_Case);
3428 else
3429 Set_Casing (All_Lower_Case);
3430 end if;
3432 return
3433 Make_String_Literal (Sloc (E),
3434 Strval => String_From_Name_Buffer);
3435 end Get_Default_External_Name;
3437 ---------------------------
3438 -- Get_Enum_Lit_From_Pos --
3439 ---------------------------
3441 function Get_Enum_Lit_From_Pos
3442 (T : Entity_Id;
3443 Pos : Uint;
3444 Loc : Source_Ptr) return Node_Id
3446 Lit : Node_Id;
3448 begin
3449 -- In the case where the literal is of type Character, Wide_Character
3450 -- or Wide_Wide_Character or of a type derived from them, there needs
3451 -- to be some special handling since there is no explicit chain of
3452 -- literals to search. Instead, an N_Character_Literal node is created
3453 -- with the appropriate Char_Code and Chars fields.
3455 if Is_Standard_Character_Type (T) then
3456 Set_Character_Literal_Name (UI_To_CC (Pos));
3457 return
3458 Make_Character_Literal (Loc,
3459 Chars => Name_Find,
3460 Char_Literal_Value => Pos);
3462 -- For all other cases, we have a complete table of literals, and
3463 -- we simply iterate through the chain of literal until the one
3464 -- with the desired position value is found.
3467 else
3468 Lit := First_Literal (Base_Type (T));
3469 for J in 1 .. UI_To_Int (Pos) loop
3470 Next_Literal (Lit);
3471 end loop;
3473 return New_Occurrence_Of (Lit, Loc);
3474 end if;
3475 end Get_Enum_Lit_From_Pos;
3477 ------------------------
3478 -- Get_Generic_Entity --
3479 ------------------------
3481 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
3482 Ent : constant Entity_Id := Entity (Name (N));
3483 begin
3484 if Present (Renamed_Object (Ent)) then
3485 return Renamed_Object (Ent);
3486 else
3487 return Ent;
3488 end if;
3489 end Get_Generic_Entity;
3491 ----------------------
3492 -- Get_Index_Bounds --
3493 ----------------------
3495 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
3496 Kind : constant Node_Kind := Nkind (N);
3497 R : Node_Id;
3499 begin
3500 if Kind = N_Range then
3501 L := Low_Bound (N);
3502 H := High_Bound (N);
3504 elsif Kind = N_Subtype_Indication then
3505 R := Range_Expression (Constraint (N));
3507 if R = Error then
3508 L := Error;
3509 H := Error;
3510 return;
3512 else
3513 L := Low_Bound (Range_Expression (Constraint (N)));
3514 H := High_Bound (Range_Expression (Constraint (N)));
3515 end if;
3517 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
3518 if Error_Posted (Scalar_Range (Entity (N))) then
3519 L := Error;
3520 H := Error;
3522 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
3523 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
3525 else
3526 L := Low_Bound (Scalar_Range (Entity (N)));
3527 H := High_Bound (Scalar_Range (Entity (N)));
3528 end if;
3530 else
3531 -- N is an expression, indicating a range with one value
3533 L := N;
3534 H := N;
3535 end if;
3536 end Get_Index_Bounds;
3538 ----------------------------------
3539 -- Get_Library_Unit_Name_string --
3540 ----------------------------------
3542 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
3543 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
3545 begin
3546 Get_Unit_Name_String (Unit_Name_Id);
3548 -- Remove seven last character (" (spec)" or " (body)")
3550 Name_Len := Name_Len - 7;
3551 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
3552 end Get_Library_Unit_Name_String;
3554 ------------------------
3555 -- Get_Name_Entity_Id --
3556 ------------------------
3558 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
3559 begin
3560 return Entity_Id (Get_Name_Table_Info (Id));
3561 end Get_Name_Entity_Id;
3563 -------------------
3564 -- Get_Pragma_Id --
3565 -------------------
3567 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
3568 begin
3569 return Get_Pragma_Id (Pragma_Name (N));
3570 end Get_Pragma_Id;
3572 ---------------------------
3573 -- Get_Referenced_Object --
3574 ---------------------------
3576 function Get_Referenced_Object (N : Node_Id) return Node_Id is
3577 R : Node_Id;
3579 begin
3580 R := N;
3581 while Is_Entity_Name (R)
3582 and then Present (Renamed_Object (Entity (R)))
3583 loop
3584 R := Renamed_Object (Entity (R));
3585 end loop;
3587 return R;
3588 end Get_Referenced_Object;
3590 ------------------------
3591 -- Get_Renamed_Entity --
3592 ------------------------
3594 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
3595 R : Entity_Id;
3597 begin
3598 R := E;
3599 while Present (Renamed_Entity (R)) loop
3600 R := Renamed_Entity (R);
3601 end loop;
3603 return R;
3604 end Get_Renamed_Entity;
3606 -------------------------
3607 -- Get_Subprogram_Body --
3608 -------------------------
3610 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
3611 Decl : Node_Id;
3613 begin
3614 Decl := Unit_Declaration_Node (E);
3616 if Nkind (Decl) = N_Subprogram_Body then
3617 return Decl;
3619 -- The below comment is bad, because it is possible for
3620 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
3622 else -- Nkind (Decl) = N_Subprogram_Declaration
3624 if Present (Corresponding_Body (Decl)) then
3625 return Unit_Declaration_Node (Corresponding_Body (Decl));
3627 -- Imported subprogram case
3629 else
3630 return Empty;
3631 end if;
3632 end if;
3633 end Get_Subprogram_Body;
3635 ---------------------------
3636 -- Get_Subprogram_Entity --
3637 ---------------------------
3639 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
3640 Nam : Node_Id;
3641 Proc : Entity_Id;
3643 begin
3644 if Nkind (Nod) = N_Accept_Statement then
3645 Nam := Entry_Direct_Name (Nod);
3647 -- For an entry call, the prefix of the call is a selected component.
3648 -- Need additional code for internal calls ???
3650 elsif Nkind (Nod) = N_Entry_Call_Statement then
3651 if Nkind (Name (Nod)) = N_Selected_Component then
3652 Nam := Entity (Selector_Name (Name (Nod)));
3653 else
3654 Nam := Empty;
3655 end if;
3657 else
3658 Nam := Name (Nod);
3659 end if;
3661 if Nkind (Nam) = N_Explicit_Dereference then
3662 Proc := Etype (Prefix (Nam));
3663 elsif Is_Entity_Name (Nam) then
3664 Proc := Entity (Nam);
3665 else
3666 return Empty;
3667 end if;
3669 if Is_Object (Proc) then
3670 Proc := Etype (Proc);
3671 end if;
3673 if Ekind (Proc) = E_Access_Subprogram_Type then
3674 Proc := Directly_Designated_Type (Proc);
3675 end if;
3677 if not Is_Subprogram (Proc)
3678 and then Ekind (Proc) /= E_Subprogram_Type
3679 then
3680 return Empty;
3681 else
3682 return Proc;
3683 end if;
3684 end Get_Subprogram_Entity;
3686 -----------------------------
3687 -- Get_Task_Body_Procedure --
3688 -----------------------------
3690 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
3691 begin
3692 -- Note: A task type may be the completion of a private type with
3693 -- discriminants. When performing elaboration checks on a task
3694 -- declaration, the current view of the type may be the private one,
3695 -- and the procedure that holds the body of the task is held in its
3696 -- underlying type.
3698 -- This is an odd function, why not have Task_Body_Procedure do
3699 -- the following digging???
3701 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
3702 end Get_Task_Body_Procedure;
3704 -----------------------
3705 -- Has_Access_Values --
3706 -----------------------
3708 function Has_Access_Values (T : Entity_Id) return Boolean is
3709 Typ : constant Entity_Id := Underlying_Type (T);
3711 begin
3712 -- Case of a private type which is not completed yet. This can only
3713 -- happen in the case of a generic format type appearing directly, or
3714 -- as a component of the type to which this function is being applied
3715 -- at the top level. Return False in this case, since we certainly do
3716 -- not know that the type contains access types.
3718 if No (Typ) then
3719 return False;
3721 elsif Is_Access_Type (Typ) then
3722 return True;
3724 elsif Is_Array_Type (Typ) then
3725 return Has_Access_Values (Component_Type (Typ));
3727 elsif Is_Record_Type (Typ) then
3728 declare
3729 Comp : Entity_Id;
3731 begin
3732 -- Loop to Check components
3734 Comp := First_Component_Or_Discriminant (Typ);
3735 while Present (Comp) loop
3737 -- Check for access component, tag field does not count, even
3738 -- though it is implemented internally using an access type.
3740 if Has_Access_Values (Etype (Comp))
3741 and then Chars (Comp) /= Name_uTag
3742 then
3743 return True;
3744 end if;
3746 Next_Component_Or_Discriminant (Comp);
3747 end loop;
3748 end;
3750 return False;
3752 else
3753 return False;
3754 end if;
3755 end Has_Access_Values;
3757 ------------------------------
3758 -- Has_Compatible_Alignment --
3759 ------------------------------
3761 function Has_Compatible_Alignment
3762 (Obj : Entity_Id;
3763 Expr : Node_Id) return Alignment_Result
3765 function Has_Compatible_Alignment_Internal
3766 (Obj : Entity_Id;
3767 Expr : Node_Id;
3768 Default : Alignment_Result) return Alignment_Result;
3769 -- This is the internal recursive function that actually does the work.
3770 -- There is one additional parameter, which says what the result should
3771 -- be if no alignment information is found, and there is no definite
3772 -- indication of compatible alignments. At the outer level, this is set
3773 -- to Unknown, but for internal recursive calls in the case where types
3774 -- are known to be correct, it is set to Known_Compatible.
3776 ---------------------------------------
3777 -- Has_Compatible_Alignment_Internal --
3778 ---------------------------------------
3780 function Has_Compatible_Alignment_Internal
3781 (Obj : Entity_Id;
3782 Expr : Node_Id;
3783 Default : Alignment_Result) return Alignment_Result
3785 Result : Alignment_Result := Known_Compatible;
3786 -- Set to result if Problem_Prefix or Problem_Offset returns True.
3787 -- Note that once a value of Known_Incompatible is set, it is sticky
3788 -- and does not get changed to Unknown (the value in Result only gets
3789 -- worse as we go along, never better).
3791 procedure Check_Offset (Offs : Uint);
3792 -- Called when Expr is a selected or indexed component with Offs set
3793 -- to resp Component_First_Bit or Component_Size. Checks that if the
3794 -- offset is specified it is compatible with the object alignment
3795 -- requirements. The value in Result is modified accordingly.
3797 procedure Check_Prefix;
3798 -- Checks the prefix recursively in the case where the expression
3799 -- is an indexed or selected component.
3801 procedure Set_Result (R : Alignment_Result);
3802 -- If R represents a worse outcome (unknown instead of known
3803 -- compatible, or known incompatible), then set Result to R.
3805 ------------------
3806 -- Check_Offset --
3807 ------------------
3809 procedure Check_Offset (Offs : Uint) is
3810 begin
3811 -- Unspecified or zero offset is always OK
3813 if Offs = No_Uint or else Offs = Uint_0 then
3814 null;
3816 -- If we do not know required alignment, any non-zero offset is
3817 -- a potential problem (but certainly may be OK, so result is
3818 -- unknown).
3820 elsif Unknown_Alignment (Obj) then
3821 Set_Result (Unknown);
3823 -- If we know the required alignment, see if offset is compatible
3825 else
3826 if Offs mod (System_Storage_Unit * Alignment (Obj)) /= 0 then
3827 Set_Result (Known_Incompatible);
3828 end if;
3829 end if;
3830 end Check_Offset;
3832 ------------------
3833 -- Check_Prefix --
3834 ------------------
3836 procedure Check_Prefix is
3837 begin
3838 -- The subtlety here is that in doing a recursive call to check
3839 -- the prefix, we have to decide what to do in the case where we
3840 -- don't find any specific indication of an alignment problem.
3842 -- At the outer level, we normally set Unknown as the result in
3843 -- this case, since we can only set Known_Compatible if we really
3844 -- know that the alignment value is OK, but for the recursive
3845 -- call, in the case where the types match, and we have not
3846 -- specified a peculiar alignment for the object, we are only
3847 -- concerned about suspicious rep clauses, the default case does
3848 -- not affect us, since the compiler will, in the absence of such
3849 -- rep clauses, ensure that the alignment is correct.
3851 if Default = Known_Compatible
3852 or else
3853 (Etype (Obj) = Etype (Expr)
3854 and then (Unknown_Alignment (Obj)
3855 or else
3856 Alignment (Obj) = Alignment (Etype (Obj))))
3857 then
3858 Set_Result
3859 (Has_Compatible_Alignment_Internal
3860 (Obj, Prefix (Expr), Known_Compatible));
3862 -- In all other cases, we need a full check on the prefix
3864 else
3865 Set_Result
3866 (Has_Compatible_Alignment_Internal
3867 (Obj, Prefix (Expr), Unknown));
3868 end if;
3869 end Check_Prefix;
3871 ----------------
3872 -- Set_Result --
3873 ----------------
3875 procedure Set_Result (R : Alignment_Result) is
3876 begin
3877 if R > Result then
3878 Result := R;
3879 end if;
3880 end Set_Result;
3882 -- Start of processing for Has_Compatible_Alignment_Internal
3884 begin
3885 -- If Expr is a selected component, we must make sure there is no
3886 -- potentially troublesome component clause, and that the record is
3887 -- not packed.
3889 if Nkind (Expr) = N_Selected_Component then
3891 -- Packed record always generate unknown alignment
3893 if Is_Packed (Etype (Prefix (Expr))) then
3894 Set_Result (Unknown);
3895 end if;
3897 -- Check possible bad component offset and check prefix
3899 Check_Offset
3900 (Component_Bit_Offset (Entity (Selector_Name (Expr))));
3901 Check_Prefix;
3903 -- If Expr is an indexed component, we must make sure there is no
3904 -- potentially troublesome Component_Size clause and that the array
3905 -- is not bit-packed.
3907 elsif Nkind (Expr) = N_Indexed_Component then
3909 -- Bit packed array always generates unknown alignment
3911 if Is_Bit_Packed_Array (Etype (Prefix (Expr))) then
3912 Set_Result (Unknown);
3913 end if;
3915 -- Check possible bad component size and check prefix
3917 Check_Offset (Component_Size (Etype (Prefix (Expr))));
3918 Check_Prefix;
3919 end if;
3921 -- Case where we know the alignment of the object
3923 if Known_Alignment (Obj) then
3924 declare
3925 ObjA : constant Uint := Alignment (Obj);
3926 ExpA : Uint := No_Uint;
3927 SizA : Uint := No_Uint;
3929 begin
3930 -- If alignment of Obj is 1, then we are always OK
3932 if ObjA = 1 then
3933 Set_Result (Known_Compatible);
3935 -- Alignment of Obj is greater than 1, so we need to check
3937 else
3938 -- See if Expr is an object with known alignment
3940 if Is_Entity_Name (Expr)
3941 and then Known_Alignment (Entity (Expr))
3942 then
3943 ExpA := Alignment (Entity (Expr));
3945 -- Otherwise, we can use the alignment of the type of
3946 -- Expr given that we already checked for
3947 -- discombobulating rep clauses for the cases of indexed
3948 -- and selected components above.
3950 elsif Known_Alignment (Etype (Expr)) then
3951 ExpA := Alignment (Etype (Expr));
3952 end if;
3954 -- If we got an alignment, see if it is acceptable
3956 if ExpA /= No_Uint then
3957 if ExpA < ObjA then
3958 Set_Result (Known_Incompatible);
3959 end if;
3961 -- Case of Expr alignment unknown
3963 else
3964 Set_Result (Default);
3965 end if;
3967 -- See if size is given. If so, check that it is not too
3968 -- small for the required alignment.
3969 -- See if Expr is an object with known alignment
3971 if Is_Entity_Name (Expr)
3972 and then Known_Static_Esize (Entity (Expr))
3973 then
3974 SizA := Esize (Entity (Expr));
3976 -- Otherwise, we check the object size of the Expr type
3978 elsif Known_Static_Esize (Etype (Expr)) then
3979 SizA := Esize (Etype (Expr));
3980 end if;
3982 -- If we got a size, see if it is a multiple of the Obj
3983 -- alignment, if not, then the alignment cannot be
3984 -- acceptable, since the size is always a multiple of the
3985 -- alignment.
3987 if SizA /= No_Uint then
3988 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
3989 Set_Result (Known_Incompatible);
3990 end if;
3991 end if;
3992 end if;
3993 end;
3995 -- If we can't find the result by direct comparison of alignment
3996 -- values, then there is still one case that we can determine known
3997 -- result, and that is when we can determine that the types are the
3998 -- same, and no alignments are specified. Then we known that the
3999 -- alignments are compatible, even if we don't know the alignment
4000 -- value in the front end.
4002 elsif Etype (Obj) = Etype (Expr) then
4004 -- Types are the same, but we have to check for possible size
4005 -- and alignments on the Expr object that may make the alignment
4006 -- different, even though the types are the same.
4008 if Is_Entity_Name (Expr) then
4010 -- First check alignment of the Expr object. Any alignment less
4011 -- than Maximum_Alignment is worrisome since this is the case
4012 -- where we do not know the alignment of Obj.
4014 if Known_Alignment (Entity (Expr))
4015 and then
4016 UI_To_Int (Alignment (Entity (Expr)))
4017 < Ttypes.Maximum_Alignment
4018 then
4019 Set_Result (Unknown);
4021 -- Now check size of Expr object. Any size that is not an
4022 -- even multiple of Maximum_Alignment is also worrisome
4023 -- since it may cause the alignment of the object to be less
4024 -- than the alignment of the type.
4026 elsif Known_Static_Esize (Entity (Expr))
4027 and then
4028 (UI_To_Int (Esize (Entity (Expr))) mod
4029 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
4030 /= 0
4031 then
4032 Set_Result (Unknown);
4034 -- Otherwise same type is decisive
4036 else
4037 Set_Result (Known_Compatible);
4038 end if;
4039 end if;
4041 -- Another case to deal with is when there is an explicit size or
4042 -- alignment clause when the types are not the same. If so, then the
4043 -- result is Unknown. We don't need to do this test if the Default is
4044 -- Unknown, since that result will be set in any case.
4046 elsif Default /= Unknown
4047 and then (Has_Size_Clause (Etype (Expr))
4048 or else
4049 Has_Alignment_Clause (Etype (Expr)))
4050 then
4051 Set_Result (Unknown);
4053 -- If no indication found, set default
4055 else
4056 Set_Result (Default);
4057 end if;
4059 -- Return worst result found
4061 return Result;
4062 end Has_Compatible_Alignment_Internal;
4064 -- Start of processing for Has_Compatible_Alignment
4066 begin
4067 -- If Obj has no specified alignment, then set alignment from the type
4068 -- alignment. Perhaps we should always do this, but for sure we should
4069 -- do it when there is an address clause since we can do more if the
4070 -- alignment is known.
4072 if Unknown_Alignment (Obj) then
4073 Set_Alignment (Obj, Alignment (Etype (Obj)));
4074 end if;
4076 -- Now do the internal call that does all the work
4078 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
4079 end Has_Compatible_Alignment;
4081 ----------------------
4082 -- Has_Declarations --
4083 ----------------------
4085 function Has_Declarations (N : Node_Id) return Boolean is
4086 K : constant Node_Kind := Nkind (N);
4087 begin
4088 return K = N_Accept_Statement
4089 or else K = N_Block_Statement
4090 or else K = N_Compilation_Unit_Aux
4091 or else K = N_Entry_Body
4092 or else K = N_Package_Body
4093 or else K = N_Protected_Body
4094 or else K = N_Subprogram_Body
4095 or else K = N_Task_Body
4096 or else K = N_Package_Specification;
4097 end Has_Declarations;
4099 -------------------------------------------
4100 -- Has_Discriminant_Dependent_Constraint --
4101 -------------------------------------------
4103 function Has_Discriminant_Dependent_Constraint
4104 (Comp : Entity_Id) return Boolean
4106 Comp_Decl : constant Node_Id := Parent (Comp);
4107 Subt_Indic : constant Node_Id :=
4108 Subtype_Indication (Component_Definition (Comp_Decl));
4109 Constr : Node_Id;
4110 Assn : Node_Id;
4112 begin
4113 if Nkind (Subt_Indic) = N_Subtype_Indication then
4114 Constr := Constraint (Subt_Indic);
4116 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
4117 Assn := First (Constraints (Constr));
4118 while Present (Assn) loop
4119 case Nkind (Assn) is
4120 when N_Subtype_Indication |
4121 N_Range |
4122 N_Identifier
4124 if Depends_On_Discriminant (Assn) then
4125 return True;
4126 end if;
4128 when N_Discriminant_Association =>
4129 if Depends_On_Discriminant (Expression (Assn)) then
4130 return True;
4131 end if;
4133 when others =>
4134 null;
4136 end case;
4138 Next (Assn);
4139 end loop;
4140 end if;
4141 end if;
4143 return False;
4144 end Has_Discriminant_Dependent_Constraint;
4146 --------------------
4147 -- Has_Infinities --
4148 --------------------
4150 function Has_Infinities (E : Entity_Id) return Boolean is
4151 begin
4152 return
4153 Is_Floating_Point_Type (E)
4154 and then Nkind (Scalar_Range (E)) = N_Range
4155 and then Includes_Infinities (Scalar_Range (E));
4156 end Has_Infinities;
4158 --------------------
4159 -- Has_Interfaces --
4160 --------------------
4162 function Has_Interfaces
4163 (T : Entity_Id;
4164 Use_Full_View : Boolean := True) return Boolean
4166 Typ : Entity_Id;
4168 begin
4169 -- Handle concurrent types
4171 if Is_Concurrent_Type (T) then
4172 Typ := Corresponding_Record_Type (T);
4173 else
4174 Typ := T;
4175 end if;
4177 if not Present (Typ)
4178 or else not Is_Record_Type (Typ)
4179 or else not Is_Tagged_Type (Typ)
4180 then
4181 return False;
4182 end if;
4184 -- Handle private types
4186 if Use_Full_View
4187 and then Present (Full_View (Typ))
4188 then
4189 Typ := Full_View (Typ);
4190 end if;
4192 -- Handle concurrent record types
4194 if Is_Concurrent_Record_Type (Typ)
4195 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
4196 then
4197 return True;
4198 end if;
4200 loop
4201 if Is_Interface (Typ)
4202 or else
4203 (Is_Record_Type (Typ)
4204 and then Present (Interfaces (Typ))
4205 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
4206 then
4207 return True;
4208 end if;
4210 exit when Etype (Typ) = Typ
4212 -- Handle private types
4214 or else (Present (Full_View (Etype (Typ)))
4215 and then Full_View (Etype (Typ)) = Typ)
4217 -- Protect the frontend against wrong source with cyclic
4218 -- derivations
4220 or else Etype (Typ) = T;
4222 -- Climb to the ancestor type handling private types
4224 if Present (Full_View (Etype (Typ))) then
4225 Typ := Full_View (Etype (Typ));
4226 else
4227 Typ := Etype (Typ);
4228 end if;
4229 end loop;
4231 return False;
4232 end Has_Interfaces;
4234 ------------------------
4235 -- Has_Null_Exclusion --
4236 ------------------------
4238 function Has_Null_Exclusion (N : Node_Id) return Boolean is
4239 begin
4240 case Nkind (N) is
4241 when N_Access_Definition |
4242 N_Access_Function_Definition |
4243 N_Access_Procedure_Definition |
4244 N_Access_To_Object_Definition |
4245 N_Allocator |
4246 N_Derived_Type_Definition |
4247 N_Function_Specification |
4248 N_Subtype_Declaration =>
4249 return Null_Exclusion_Present (N);
4251 when N_Component_Definition |
4252 N_Formal_Object_Declaration |
4253 N_Object_Renaming_Declaration =>
4254 if Present (Subtype_Mark (N)) then
4255 return Null_Exclusion_Present (N);
4256 else pragma Assert (Present (Access_Definition (N)));
4257 return Null_Exclusion_Present (Access_Definition (N));
4258 end if;
4260 when N_Discriminant_Specification =>
4261 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
4262 return Null_Exclusion_Present (Discriminant_Type (N));
4263 else
4264 return Null_Exclusion_Present (N);
4265 end if;
4267 when N_Object_Declaration =>
4268 if Nkind (Object_Definition (N)) = N_Access_Definition then
4269 return Null_Exclusion_Present (Object_Definition (N));
4270 else
4271 return Null_Exclusion_Present (N);
4272 end if;
4274 when N_Parameter_Specification =>
4275 if Nkind (Parameter_Type (N)) = N_Access_Definition then
4276 return Null_Exclusion_Present (Parameter_Type (N));
4277 else
4278 return Null_Exclusion_Present (N);
4279 end if;
4281 when others =>
4282 return False;
4284 end case;
4285 end Has_Null_Exclusion;
4287 ------------------------
4288 -- Has_Null_Extension --
4289 ------------------------
4291 function Has_Null_Extension (T : Entity_Id) return Boolean is
4292 B : constant Entity_Id := Base_Type (T);
4293 Comps : Node_Id;
4294 Ext : Node_Id;
4296 begin
4297 if Nkind (Parent (B)) = N_Full_Type_Declaration
4298 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
4299 then
4300 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
4302 if Present (Ext) then
4303 if Null_Present (Ext) then
4304 return True;
4305 else
4306 Comps := Component_List (Ext);
4308 -- The null component list is rewritten during analysis to
4309 -- include the parent component. Any other component indicates
4310 -- that the extension was not originally null.
4312 return Null_Present (Comps)
4313 or else No (Next (First (Component_Items (Comps))));
4314 end if;
4315 else
4316 return False;
4317 end if;
4319 else
4320 return False;
4321 end if;
4322 end Has_Null_Extension;
4324 -------------------------------
4325 -- Has_Overriding_Initialize --
4326 -------------------------------
4328 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
4329 BT : constant Entity_Id := Base_Type (T);
4330 Comp : Entity_Id;
4331 P : Elmt_Id;
4333 begin
4334 if Is_Controlled (BT) then
4336 -- For derived types, check immediate ancestor, excluding
4337 -- Controlled itself.
4339 if Is_Derived_Type (BT)
4340 and then not In_Predefined_Unit (Etype (BT))
4341 and then Has_Overriding_Initialize (Etype (BT))
4342 then
4343 return True;
4345 elsif Present (Primitive_Operations (BT)) then
4346 P := First_Elmt (Primitive_Operations (BT));
4347 while Present (P) loop
4348 if Chars (Node (P)) = Name_Initialize
4349 and then Comes_From_Source (Node (P))
4350 then
4351 return True;
4352 end if;
4354 Next_Elmt (P);
4355 end loop;
4356 end if;
4358 return False;
4360 elsif Has_Controlled_Component (BT) then
4361 Comp := First_Component (BT);
4362 while Present (Comp) loop
4363 if Has_Overriding_Initialize (Etype (Comp)) then
4364 return True;
4365 end if;
4367 Next_Component (Comp);
4368 end loop;
4370 return False;
4372 else
4373 return False;
4374 end if;
4375 end Has_Overriding_Initialize;
4377 --------------------------------------
4378 -- Has_Preelaborable_Initialization --
4379 --------------------------------------
4381 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
4382 Has_PE : Boolean;
4384 procedure Check_Components (E : Entity_Id);
4385 -- Check component/discriminant chain, sets Has_PE False if a component
4386 -- or discriminant does not meet the preelaborable initialization rules.
4388 ----------------------
4389 -- Check_Components --
4390 ----------------------
4392 procedure Check_Components (E : Entity_Id) is
4393 Ent : Entity_Id;
4394 Exp : Node_Id;
4396 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
4397 -- Returns True if and only if the expression denoted by N does not
4398 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
4400 ---------------------------------
4401 -- Is_Preelaborable_Expression --
4402 ---------------------------------
4404 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
4405 Exp : Node_Id;
4406 Assn : Node_Id;
4407 Choice : Node_Id;
4408 Comp_Type : Entity_Id;
4409 Is_Array_Aggr : Boolean;
4411 begin
4412 if Is_Static_Expression (N) then
4413 return True;
4415 elsif Nkind (N) = N_Null then
4416 return True;
4418 -- Attributes are allowed in general, even if their prefix is a
4419 -- formal type. (It seems that certain attributes known not to be
4420 -- static might not be allowed, but there are no rules to prevent
4421 -- them.)
4423 elsif Nkind (N) = N_Attribute_Reference then
4424 return True;
4426 -- The name of a discriminant evaluated within its parent type is
4427 -- defined to be preelaborable (10.2.1(8)). Note that we test for
4428 -- names that denote discriminals as well as discriminants to
4429 -- catch references occurring within init procs.
4431 elsif Is_Entity_Name (N)
4432 and then
4433 (Ekind (Entity (N)) = E_Discriminant
4434 or else
4435 ((Ekind (Entity (N)) = E_Constant
4436 or else Ekind (Entity (N)) = E_In_Parameter)
4437 and then Present (Discriminal_Link (Entity (N)))))
4438 then
4439 return True;
4441 elsif Nkind (N) = N_Qualified_Expression then
4442 return Is_Preelaborable_Expression (Expression (N));
4444 -- For aggregates we have to check that each of the associations
4445 -- is preelaborable.
4447 elsif Nkind (N) = N_Aggregate
4448 or else Nkind (N) = N_Extension_Aggregate
4449 then
4450 Is_Array_Aggr := Is_Array_Type (Etype (N));
4452 if Is_Array_Aggr then
4453 Comp_Type := Component_Type (Etype (N));
4454 end if;
4456 -- Check the ancestor part of extension aggregates, which must
4457 -- be either the name of a type that has preelaborable init or
4458 -- an expression that is preelaborable.
4460 if Nkind (N) = N_Extension_Aggregate then
4461 declare
4462 Anc_Part : constant Node_Id := Ancestor_Part (N);
4464 begin
4465 if Is_Entity_Name (Anc_Part)
4466 and then Is_Type (Entity (Anc_Part))
4467 then
4468 if not Has_Preelaborable_Initialization
4469 (Entity (Anc_Part))
4470 then
4471 return False;
4472 end if;
4474 elsif not Is_Preelaborable_Expression (Anc_Part) then
4475 return False;
4476 end if;
4477 end;
4478 end if;
4480 -- Check positional associations
4482 Exp := First (Expressions (N));
4483 while Present (Exp) loop
4484 if not Is_Preelaborable_Expression (Exp) then
4485 return False;
4486 end if;
4488 Next (Exp);
4489 end loop;
4491 -- Check named associations
4493 Assn := First (Component_Associations (N));
4494 while Present (Assn) loop
4495 Choice := First (Choices (Assn));
4496 while Present (Choice) loop
4497 if Is_Array_Aggr then
4498 if Nkind (Choice) = N_Others_Choice then
4499 null;
4501 elsif Nkind (Choice) = N_Range then
4502 if not Is_Static_Range (Choice) then
4503 return False;
4504 end if;
4506 elsif not Is_Static_Expression (Choice) then
4507 return False;
4508 end if;
4510 else
4511 Comp_Type := Etype (Choice);
4512 end if;
4514 Next (Choice);
4515 end loop;
4517 -- If the association has a <> at this point, then we have
4518 -- to check whether the component's type has preelaborable
4519 -- initialization. Note that this only occurs when the
4520 -- association's corresponding component does not have a
4521 -- default expression, the latter case having already been
4522 -- expanded as an expression for the association.
4524 if Box_Present (Assn) then
4525 if not Has_Preelaborable_Initialization (Comp_Type) then
4526 return False;
4527 end if;
4529 -- In the expression case we check whether the expression
4530 -- is preelaborable.
4532 elsif
4533 not Is_Preelaborable_Expression (Expression (Assn))
4534 then
4535 return False;
4536 end if;
4538 Next (Assn);
4539 end loop;
4541 -- If we get here then aggregate as a whole is preelaborable
4543 return True;
4545 -- All other cases are not preelaborable
4547 else
4548 return False;
4549 end if;
4550 end Is_Preelaborable_Expression;
4552 -- Start of processing for Check_Components
4554 begin
4555 -- Loop through entities of record or protected type
4557 Ent := E;
4558 while Present (Ent) loop
4560 -- We are interested only in components and discriminants
4562 if Ekind (Ent) = E_Component
4563 or else
4564 Ekind (Ent) = E_Discriminant
4565 then
4566 -- Get default expression if any. If there is no declaration
4567 -- node, it means we have an internal entity. The parent and
4568 -- tag fields are examples of such entities. For these cases,
4569 -- we just test the type of the entity.
4571 if Present (Declaration_Node (Ent)) then
4572 Exp := Expression (Declaration_Node (Ent));
4573 else
4574 Exp := Empty;
4575 end if;
4577 -- A component has PI if it has no default expression and the
4578 -- component type has PI.
4580 if No (Exp) then
4581 if not Has_Preelaborable_Initialization (Etype (Ent)) then
4582 Has_PE := False;
4583 exit;
4584 end if;
4586 -- Require the default expression to be preelaborable
4588 elsif not Is_Preelaborable_Expression (Exp) then
4589 Has_PE := False;
4590 exit;
4591 end if;
4592 end if;
4594 Next_Entity (Ent);
4595 end loop;
4596 end Check_Components;
4598 -- Start of processing for Has_Preelaborable_Initialization
4600 begin
4601 -- Immediate return if already marked as known preelaborable init. This
4602 -- covers types for which this function has already been called once
4603 -- and returned True (in which case the result is cached), and also
4604 -- types to which a pragma Preelaborable_Initialization applies.
4606 if Known_To_Have_Preelab_Init (E) then
4607 return True;
4608 end if;
4610 -- If the type is a subtype representing a generic actual type, then
4611 -- test whether its base type has preelaborable initialization since
4612 -- the subtype representing the actual does not inherit this attribute
4613 -- from the actual or formal. (but maybe it should???)
4615 if Is_Generic_Actual_Type (E) then
4616 return Has_Preelaborable_Initialization (Base_Type (E));
4617 end if;
4619 -- Other private types never have preelaborable initialization
4621 if Is_Private_Type (E) then
4622 return False;
4623 end if;
4625 -- Here for all non-private view
4627 -- All elementary types have preelaborable initialization
4629 if Is_Elementary_Type (E) then
4630 Has_PE := True;
4632 -- Array types have PI if the component type has PI
4634 elsif Is_Array_Type (E) then
4635 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
4637 -- A derived type has preelaborable initialization if its parent type
4638 -- has preelaborable initialization and (in the case of a derived record
4639 -- extension) if the non-inherited components all have preelaborable
4640 -- initialization. However, a user-defined controlled type with an
4641 -- overriding Initialize procedure does not have preelaborable
4642 -- initialization.
4644 elsif Is_Derived_Type (E) then
4646 -- First check whether ancestor type has preelaborable initialization
4648 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
4650 -- If OK, check extension components (if any)
4652 if Has_PE and then Is_Record_Type (E) then
4653 Check_Components (First_Entity (E));
4654 end if;
4656 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
4657 -- with a user defined Initialize procedure does not have PI.
4659 if Has_PE
4660 and then Is_Controlled (E)
4661 and then Has_Overriding_Initialize (E)
4662 then
4663 Has_PE := False;
4664 end if;
4666 -- Record type has PI if it is non private and all components have PI
4668 elsif Is_Record_Type (E) then
4669 Has_PE := True;
4670 Check_Components (First_Entity (E));
4672 -- Protected types must not have entries, and components must meet
4673 -- same set of rules as for record components.
4675 elsif Is_Protected_Type (E) then
4676 if Has_Entries (E) then
4677 Has_PE := False;
4678 else
4679 Has_PE := True;
4680 Check_Components (First_Entity (E));
4681 Check_Components (First_Private_Entity (E));
4682 end if;
4684 -- Type System.Address always has preelaborable initialization
4686 elsif Is_RTE (E, RE_Address) then
4687 Has_PE := True;
4689 -- In all other cases, type does not have preelaborable initialization
4691 else
4692 return False;
4693 end if;
4695 -- If type has preelaborable initialization, cache result
4697 if Has_PE then
4698 Set_Known_To_Have_Preelab_Init (E);
4699 end if;
4701 return Has_PE;
4702 end Has_Preelaborable_Initialization;
4704 ---------------------------
4705 -- Has_Private_Component --
4706 ---------------------------
4708 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
4709 Btype : Entity_Id := Base_Type (Type_Id);
4710 Component : Entity_Id;
4712 begin
4713 if Error_Posted (Type_Id)
4714 or else Error_Posted (Btype)
4715 then
4716 return False;
4717 end if;
4719 if Is_Class_Wide_Type (Btype) then
4720 Btype := Root_Type (Btype);
4721 end if;
4723 if Is_Private_Type (Btype) then
4724 declare
4725 UT : constant Entity_Id := Underlying_Type (Btype);
4726 begin
4727 if No (UT) then
4728 if No (Full_View (Btype)) then
4729 return not Is_Generic_Type (Btype)
4730 and then not Is_Generic_Type (Root_Type (Btype));
4731 else
4732 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
4733 end if;
4734 else
4735 return not Is_Frozen (UT) and then Has_Private_Component (UT);
4736 end if;
4737 end;
4739 elsif Is_Array_Type (Btype) then
4740 return Has_Private_Component (Component_Type (Btype));
4742 elsif Is_Record_Type (Btype) then
4743 Component := First_Component (Btype);
4744 while Present (Component) loop
4745 if Has_Private_Component (Etype (Component)) then
4746 return True;
4747 end if;
4749 Next_Component (Component);
4750 end loop;
4752 return False;
4754 elsif Is_Protected_Type (Btype)
4755 and then Present (Corresponding_Record_Type (Btype))
4756 then
4757 return Has_Private_Component (Corresponding_Record_Type (Btype));
4759 else
4760 return False;
4761 end if;
4762 end Has_Private_Component;
4764 ----------------
4765 -- Has_Stream --
4766 ----------------
4768 function Has_Stream (T : Entity_Id) return Boolean is
4769 E : Entity_Id;
4771 begin
4772 if No (T) then
4773 return False;
4775 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
4776 return True;
4778 elsif Is_Array_Type (T) then
4779 return Has_Stream (Component_Type (T));
4781 elsif Is_Record_Type (T) then
4782 E := First_Component (T);
4783 while Present (E) loop
4784 if Has_Stream (Etype (E)) then
4785 return True;
4786 else
4787 Next_Component (E);
4788 end if;
4789 end loop;
4791 return False;
4793 elsif Is_Private_Type (T) then
4794 return Has_Stream (Underlying_Type (T));
4796 else
4797 return False;
4798 end if;
4799 end Has_Stream;
4801 --------------------------
4802 -- Has_Tagged_Component --
4803 --------------------------
4805 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
4806 Comp : Entity_Id;
4808 begin
4809 if Is_Private_Type (Typ)
4810 and then Present (Underlying_Type (Typ))
4811 then
4812 return Has_Tagged_Component (Underlying_Type (Typ));
4814 elsif Is_Array_Type (Typ) then
4815 return Has_Tagged_Component (Component_Type (Typ));
4817 elsif Is_Tagged_Type (Typ) then
4818 return True;
4820 elsif Is_Record_Type (Typ) then
4821 Comp := First_Component (Typ);
4822 while Present (Comp) loop
4823 if Has_Tagged_Component (Etype (Comp)) then
4824 return True;
4825 end if;
4827 Comp := Next_Component (Typ);
4828 end loop;
4830 return False;
4832 else
4833 return False;
4834 end if;
4835 end Has_Tagged_Component;
4837 --------------------------
4838 -- Implements_Interface --
4839 --------------------------
4841 function Implements_Interface
4842 (Typ_Ent : Entity_Id;
4843 Iface_Ent : Entity_Id;
4844 Exclude_Parents : Boolean := False) return Boolean
4846 Ifaces_List : Elist_Id;
4847 Elmt : Elmt_Id;
4848 Iface : Entity_Id;
4849 Typ : Entity_Id;
4851 begin
4852 if Is_Class_Wide_Type (Typ_Ent) then
4853 Typ := Etype (Typ_Ent);
4854 else
4855 Typ := Typ_Ent;
4856 end if;
4858 if Is_Class_Wide_Type (Iface_Ent) then
4859 Iface := Etype (Iface_Ent);
4860 else
4861 Iface := Iface_Ent;
4862 end if;
4864 if not Has_Interfaces (Typ) then
4865 return False;
4866 end if;
4868 Collect_Interfaces (Typ, Ifaces_List);
4870 Elmt := First_Elmt (Ifaces_List);
4871 while Present (Elmt) loop
4872 if Is_Ancestor (Node (Elmt), Typ)
4873 and then Exclude_Parents
4874 then
4875 null;
4877 elsif Node (Elmt) = Iface then
4878 return True;
4879 end if;
4881 Next_Elmt (Elmt);
4882 end loop;
4884 return False;
4885 end Implements_Interface;
4887 -----------------
4888 -- In_Instance --
4889 -----------------
4891 function In_Instance return Boolean is
4892 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
4893 S : Entity_Id;
4895 begin
4896 S := Current_Scope;
4897 while Present (S)
4898 and then S /= Standard_Standard
4899 loop
4900 if (Ekind (S) = E_Function
4901 or else Ekind (S) = E_Package
4902 or else Ekind (S) = E_Procedure)
4903 and then Is_Generic_Instance (S)
4904 then
4905 -- A child instance is always compiled in the context of a parent
4906 -- instance. Nevertheless, the actuals are not analyzed in an
4907 -- instance context. We detect this case by examining the current
4908 -- compilation unit, which must be a child instance, and checking
4909 -- that it is not currently on the scope stack.
4911 if Is_Child_Unit (Curr_Unit)
4912 and then
4913 Nkind (Unit (Cunit (Current_Sem_Unit)))
4914 = N_Package_Instantiation
4915 and then not In_Open_Scopes (Curr_Unit)
4916 then
4917 return False;
4918 else
4919 return True;
4920 end if;
4921 end if;
4923 S := Scope (S);
4924 end loop;
4926 return False;
4927 end In_Instance;
4929 ----------------------
4930 -- In_Instance_Body --
4931 ----------------------
4933 function In_Instance_Body return Boolean is
4934 S : Entity_Id;
4936 begin
4937 S := Current_Scope;
4938 while Present (S)
4939 and then S /= Standard_Standard
4940 loop
4941 if (Ekind (S) = E_Function
4942 or else Ekind (S) = E_Procedure)
4943 and then Is_Generic_Instance (S)
4944 then
4945 return True;
4947 elsif Ekind (S) = E_Package
4948 and then In_Package_Body (S)
4949 and then Is_Generic_Instance (S)
4950 then
4951 return True;
4952 end if;
4954 S := Scope (S);
4955 end loop;
4957 return False;
4958 end In_Instance_Body;
4960 -----------------------------
4961 -- In_Instance_Not_Visible --
4962 -----------------------------
4964 function In_Instance_Not_Visible return Boolean is
4965 S : Entity_Id;
4967 begin
4968 S := Current_Scope;
4969 while Present (S)
4970 and then S /= Standard_Standard
4971 loop
4972 if (Ekind (S) = E_Function
4973 or else Ekind (S) = E_Procedure)
4974 and then Is_Generic_Instance (S)
4975 then
4976 return True;
4978 elsif Ekind (S) = E_Package
4979 and then (In_Package_Body (S) or else In_Private_Part (S))
4980 and then Is_Generic_Instance (S)
4981 then
4982 return True;
4983 end if;
4985 S := Scope (S);
4986 end loop;
4988 return False;
4989 end In_Instance_Not_Visible;
4991 ------------------------------
4992 -- In_Instance_Visible_Part --
4993 ------------------------------
4995 function In_Instance_Visible_Part return Boolean is
4996 S : Entity_Id;
4998 begin
4999 S := Current_Scope;
5000 while Present (S)
5001 and then S /= Standard_Standard
5002 loop
5003 if Ekind (S) = E_Package
5004 and then Is_Generic_Instance (S)
5005 and then not In_Package_Body (S)
5006 and then not In_Private_Part (S)
5007 then
5008 return True;
5009 end if;
5011 S := Scope (S);
5012 end loop;
5014 return False;
5015 end In_Instance_Visible_Part;
5017 ---------------------
5018 -- In_Package_Body --
5019 ---------------------
5021 function In_Package_Body return Boolean is
5022 S : Entity_Id;
5024 begin
5025 S := Current_Scope;
5026 while Present (S)
5027 and then S /= Standard_Standard
5028 loop
5029 if Ekind (S) = E_Package
5030 and then In_Package_Body (S)
5031 then
5032 return True;
5033 else
5034 S := Scope (S);
5035 end if;
5036 end loop;
5038 return False;
5039 end In_Package_Body;
5041 --------------------------------
5042 -- In_Parameter_Specification --
5043 --------------------------------
5045 function In_Parameter_Specification (N : Node_Id) return Boolean is
5046 PN : Node_Id;
5048 begin
5049 PN := Parent (N);
5050 while Present (PN) loop
5051 if Nkind (PN) = N_Parameter_Specification then
5052 return True;
5053 end if;
5055 PN := Parent (PN);
5056 end loop;
5058 return False;
5059 end In_Parameter_Specification;
5061 --------------------------------------
5062 -- In_Subprogram_Or_Concurrent_Unit --
5063 --------------------------------------
5065 function In_Subprogram_Or_Concurrent_Unit return Boolean is
5066 E : Entity_Id;
5067 K : Entity_Kind;
5069 begin
5070 -- Use scope chain to check successively outer scopes
5072 E := Current_Scope;
5073 loop
5074 K := Ekind (E);
5076 if K in Subprogram_Kind
5077 or else K in Concurrent_Kind
5078 or else K in Generic_Subprogram_Kind
5079 then
5080 return True;
5082 elsif E = Standard_Standard then
5083 return False;
5084 end if;
5086 E := Scope (E);
5087 end loop;
5088 end In_Subprogram_Or_Concurrent_Unit;
5090 ---------------------
5091 -- In_Visible_Part --
5092 ---------------------
5094 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
5095 begin
5096 return
5097 Is_Package_Or_Generic_Package (Scope_Id)
5098 and then In_Open_Scopes (Scope_Id)
5099 and then not In_Package_Body (Scope_Id)
5100 and then not In_Private_Part (Scope_Id);
5101 end In_Visible_Part;
5103 ---------------------------------
5104 -- Insert_Explicit_Dereference --
5105 ---------------------------------
5107 procedure Insert_Explicit_Dereference (N : Node_Id) is
5108 New_Prefix : constant Node_Id := Relocate_Node (N);
5109 Ent : Entity_Id := Empty;
5110 Pref : Node_Id;
5111 I : Interp_Index;
5112 It : Interp;
5113 T : Entity_Id;
5115 begin
5116 Save_Interps (N, New_Prefix);
5117 Rewrite (N,
5118 Make_Explicit_Dereference (Sloc (N),
5119 Prefix => New_Prefix));
5121 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
5123 if Is_Overloaded (New_Prefix) then
5125 -- The deference is also overloaded, and its interpretations are the
5126 -- designated types of the interpretations of the original node.
5128 Set_Etype (N, Any_Type);
5130 Get_First_Interp (New_Prefix, I, It);
5131 while Present (It.Nam) loop
5132 T := It.Typ;
5134 if Is_Access_Type (T) then
5135 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
5136 end if;
5138 Get_Next_Interp (I, It);
5139 end loop;
5141 End_Interp_List;
5143 else
5144 -- Prefix is unambiguous: mark the original prefix (which might
5145 -- Come_From_Source) as a reference, since the new (relocated) one
5146 -- won't be taken into account.
5148 if Is_Entity_Name (New_Prefix) then
5149 Ent := Entity (New_Prefix);
5151 -- For a retrieval of a subcomponent of some composite object,
5152 -- retrieve the ultimate entity if there is one.
5154 elsif Nkind (New_Prefix) = N_Selected_Component
5155 or else Nkind (New_Prefix) = N_Indexed_Component
5156 then
5157 Pref := Prefix (New_Prefix);
5158 while Present (Pref)
5159 and then
5160 (Nkind (Pref) = N_Selected_Component
5161 or else Nkind (Pref) = N_Indexed_Component)
5162 loop
5163 Pref := Prefix (Pref);
5164 end loop;
5166 if Present (Pref) and then Is_Entity_Name (Pref) then
5167 Ent := Entity (Pref);
5168 end if;
5169 end if;
5171 if Present (Ent) then
5172 Generate_Reference (Ent, New_Prefix);
5173 end if;
5174 end if;
5175 end Insert_Explicit_Dereference;
5177 ------------------------------------------
5178 -- Inspect_Deferred_Constant_Completion --
5179 ------------------------------------------
5181 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
5182 Decl : Node_Id;
5184 begin
5185 Decl := First (Decls);
5186 while Present (Decl) loop
5188 -- Deferred constant signature
5190 if Nkind (Decl) = N_Object_Declaration
5191 and then Constant_Present (Decl)
5192 and then No (Expression (Decl))
5194 -- No need to check internally generated constants
5196 and then Comes_From_Source (Decl)
5198 -- The constant is not completed. A full object declaration
5199 -- or a pragma Import complete a deferred constant.
5201 and then not Has_Completion (Defining_Identifier (Decl))
5202 then
5203 Error_Msg_N
5204 ("constant declaration requires initialization expression",
5205 Defining_Identifier (Decl));
5206 end if;
5208 Decl := Next (Decl);
5209 end loop;
5210 end Inspect_Deferred_Constant_Completion;
5212 -------------------
5213 -- Is_AAMP_Float --
5214 -------------------
5216 function Is_AAMP_Float (E : Entity_Id) return Boolean is
5217 pragma Assert (Is_Type (E));
5218 begin
5219 return AAMP_On_Target
5220 and then Is_Floating_Point_Type (E)
5221 and then E = Base_Type (E);
5222 end Is_AAMP_Float;
5224 -------------------------
5225 -- Is_Actual_Parameter --
5226 -------------------------
5228 function Is_Actual_Parameter (N : Node_Id) return Boolean is
5229 PK : constant Node_Kind := Nkind (Parent (N));
5231 begin
5232 case PK is
5233 when N_Parameter_Association =>
5234 return N = Explicit_Actual_Parameter (Parent (N));
5236 when N_Function_Call | N_Procedure_Call_Statement =>
5237 return Is_List_Member (N)
5238 and then
5239 List_Containing (N) = Parameter_Associations (Parent (N));
5241 when others =>
5242 return False;
5243 end case;
5244 end Is_Actual_Parameter;
5246 ---------------------
5247 -- Is_Aliased_View --
5248 ---------------------
5250 function Is_Aliased_View (Obj : Node_Id) return Boolean is
5251 E : Entity_Id;
5253 begin
5254 if Is_Entity_Name (Obj) then
5256 E := Entity (Obj);
5258 return
5259 (Is_Object (E)
5260 and then
5261 (Is_Aliased (E)
5262 or else (Present (Renamed_Object (E))
5263 and then Is_Aliased_View (Renamed_Object (E)))))
5265 or else ((Is_Formal (E)
5266 or else Ekind (E) = E_Generic_In_Out_Parameter
5267 or else Ekind (E) = E_Generic_In_Parameter)
5268 and then Is_Tagged_Type (Etype (E)))
5270 or else (Is_Concurrent_Type (E)
5271 and then In_Open_Scopes (E))
5273 -- Current instance of type, either directly or as rewritten
5274 -- reference to the current object.
5276 or else (Is_Entity_Name (Original_Node (Obj))
5277 and then Present (Entity (Original_Node (Obj)))
5278 and then Is_Type (Entity (Original_Node (Obj))))
5280 or else (Is_Type (E) and then E = Current_Scope)
5282 or else (Is_Incomplete_Or_Private_Type (E)
5283 and then Full_View (E) = Current_Scope);
5285 elsif Nkind (Obj) = N_Selected_Component then
5286 return Is_Aliased (Entity (Selector_Name (Obj)));
5288 elsif Nkind (Obj) = N_Indexed_Component then
5289 return Has_Aliased_Components (Etype (Prefix (Obj)))
5290 or else
5291 (Is_Access_Type (Etype (Prefix (Obj)))
5292 and then
5293 Has_Aliased_Components
5294 (Designated_Type (Etype (Prefix (Obj)))));
5296 elsif Nkind (Obj) = N_Unchecked_Type_Conversion
5297 or else Nkind (Obj) = N_Type_Conversion
5298 then
5299 return Is_Tagged_Type (Etype (Obj))
5300 and then Is_Aliased_View (Expression (Obj));
5302 elsif Nkind (Obj) = N_Explicit_Dereference then
5303 return Nkind (Original_Node (Obj)) /= N_Function_Call;
5305 else
5306 return False;
5307 end if;
5308 end Is_Aliased_View;
5310 -------------------------
5311 -- Is_Ancestor_Package --
5312 -------------------------
5314 function Is_Ancestor_Package
5315 (E1 : Entity_Id;
5316 E2 : Entity_Id) return Boolean
5318 Par : Entity_Id;
5320 begin
5321 Par := E2;
5322 while Present (Par)
5323 and then Par /= Standard_Standard
5324 loop
5325 if Par = E1 then
5326 return True;
5327 end if;
5329 Par := Scope (Par);
5330 end loop;
5332 return False;
5333 end Is_Ancestor_Package;
5335 ----------------------
5336 -- Is_Atomic_Object --
5337 ----------------------
5339 function Is_Atomic_Object (N : Node_Id) return Boolean is
5341 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
5342 -- Determines if given object has atomic components
5344 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
5345 -- If prefix is an implicit dereference, examine designated type
5347 ----------------------
5348 -- Is_Atomic_Prefix --
5349 ----------------------
5351 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
5352 begin
5353 if Is_Access_Type (Etype (N)) then
5354 return
5355 Has_Atomic_Components (Designated_Type (Etype (N)));
5356 else
5357 return Object_Has_Atomic_Components (N);
5358 end if;
5359 end Is_Atomic_Prefix;
5361 ----------------------------------
5362 -- Object_Has_Atomic_Components --
5363 ----------------------------------
5365 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
5366 begin
5367 if Has_Atomic_Components (Etype (N))
5368 or else Is_Atomic (Etype (N))
5369 then
5370 return True;
5372 elsif Is_Entity_Name (N)
5373 and then (Has_Atomic_Components (Entity (N))
5374 or else Is_Atomic (Entity (N)))
5375 then
5376 return True;
5378 elsif Nkind (N) = N_Indexed_Component
5379 or else Nkind (N) = N_Selected_Component
5380 then
5381 return Is_Atomic_Prefix (Prefix (N));
5383 else
5384 return False;
5385 end if;
5386 end Object_Has_Atomic_Components;
5388 -- Start of processing for Is_Atomic_Object
5390 begin
5391 if Is_Atomic (Etype (N))
5392 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
5393 then
5394 return True;
5396 elsif Nkind (N) = N_Indexed_Component
5397 or else Nkind (N) = N_Selected_Component
5398 then
5399 return Is_Atomic_Prefix (Prefix (N));
5401 else
5402 return False;
5403 end if;
5404 end Is_Atomic_Object;
5406 -------------------------
5407 -- Is_Coextension_Root --
5408 -------------------------
5410 function Is_Coextension_Root (N : Node_Id) return Boolean is
5411 begin
5412 return
5413 Nkind (N) = N_Allocator
5414 and then Present (Coextensions (N))
5416 -- Anonymous access discriminants carry a list of all nested
5417 -- controlled coextensions.
5419 and then not Is_Dynamic_Coextension (N)
5420 and then not Is_Static_Coextension (N);
5421 end Is_Coextension_Root;
5423 -----------------------------
5424 -- Is_Concurrent_Interface --
5425 -----------------------------
5427 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
5428 begin
5429 return
5430 Is_Interface (T)
5431 and then
5432 (Is_Protected_Interface (T)
5433 or else Is_Synchronized_Interface (T)
5434 or else Is_Task_Interface (T));
5435 end Is_Concurrent_Interface;
5437 --------------------------------------
5438 -- Is_Controlling_Limited_Procedure --
5439 --------------------------------------
5441 function Is_Controlling_Limited_Procedure
5442 (Proc_Nam : Entity_Id) return Boolean
5444 Param_Typ : Entity_Id := Empty;
5446 begin
5447 if Ekind (Proc_Nam) = E_Procedure
5448 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
5449 then
5450 Param_Typ := Etype (Parameter_Type (First (
5451 Parameter_Specifications (Parent (Proc_Nam)))));
5453 -- In this case where an Itype was created, the procedure call has been
5454 -- rewritten.
5456 elsif Present (Associated_Node_For_Itype (Proc_Nam))
5457 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
5458 and then
5459 Present (Parameter_Associations
5460 (Associated_Node_For_Itype (Proc_Nam)))
5461 then
5462 Param_Typ :=
5463 Etype (First (Parameter_Associations
5464 (Associated_Node_For_Itype (Proc_Nam))));
5465 end if;
5467 if Present (Param_Typ) then
5468 return
5469 Is_Interface (Param_Typ)
5470 and then Is_Limited_Record (Param_Typ);
5471 end if;
5473 return False;
5474 end Is_Controlling_Limited_Procedure;
5476 ----------------------------------------------
5477 -- Is_Dependent_Component_Of_Mutable_Object --
5478 ----------------------------------------------
5480 function Is_Dependent_Component_Of_Mutable_Object
5481 (Object : Node_Id) return Boolean
5483 P : Node_Id;
5484 Prefix_Type : Entity_Id;
5485 P_Aliased : Boolean := False;
5486 Comp : Entity_Id;
5488 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
5489 -- Returns True if and only if Comp is declared within a variant part
5491 --------------------------------
5492 -- Is_Declared_Within_Variant --
5493 --------------------------------
5495 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
5496 Comp_Decl : constant Node_Id := Parent (Comp);
5497 Comp_List : constant Node_Id := Parent (Comp_Decl);
5498 begin
5499 return Nkind (Parent (Comp_List)) = N_Variant;
5500 end Is_Declared_Within_Variant;
5502 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
5504 begin
5505 if Is_Variable (Object) then
5507 if Nkind (Object) = N_Selected_Component then
5508 P := Prefix (Object);
5509 Prefix_Type := Etype (P);
5511 if Is_Entity_Name (P) then
5513 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
5514 Prefix_Type := Base_Type (Prefix_Type);
5515 end if;
5517 if Is_Aliased (Entity (P)) then
5518 P_Aliased := True;
5519 end if;
5521 -- A discriminant check on a selected component may be
5522 -- expanded into a dereference when removing side-effects.
5523 -- Recover the original node and its type, which may be
5524 -- unconstrained.
5526 elsif Nkind (P) = N_Explicit_Dereference
5527 and then not (Comes_From_Source (P))
5528 then
5529 P := Original_Node (P);
5530 Prefix_Type := Etype (P);
5532 else
5533 -- Check for prefix being an aliased component ???
5534 null;
5536 end if;
5538 -- A heap object is constrained by its initial value
5540 -- Ada 2005 (AI-363): Always assume the object could be mutable in
5541 -- the dereferenced case, since the access value might denote an
5542 -- unconstrained aliased object, whereas in Ada 95 the designated
5543 -- object is guaranteed to be constrained. A worst-case assumption
5544 -- has to apply in Ada 2005 because we can't tell at compile time
5545 -- whether the object is "constrained by its initial value"
5546 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
5547 -- semantic rules -- these rules are acknowledged to need fixing).
5549 if Ada_Version < Ada_05 then
5550 if Is_Access_Type (Prefix_Type)
5551 or else Nkind (P) = N_Explicit_Dereference
5552 then
5553 return False;
5554 end if;
5556 elsif Ada_Version >= Ada_05 then
5557 if Is_Access_Type (Prefix_Type) then
5559 -- If the access type is pool-specific, and there is no
5560 -- constrained partial view of the designated type, then the
5561 -- designated object is known to be constrained.
5563 if Ekind (Prefix_Type) = E_Access_Type
5564 and then not Has_Constrained_Partial_View
5565 (Designated_Type (Prefix_Type))
5566 then
5567 return False;
5569 -- Otherwise (general access type, or there is a constrained
5570 -- partial view of the designated type), we need to check
5571 -- based on the designated type.
5573 else
5574 Prefix_Type := Designated_Type (Prefix_Type);
5575 end if;
5576 end if;
5577 end if;
5579 Comp :=
5580 Original_Record_Component (Entity (Selector_Name (Object)));
5582 -- As per AI-0017, the renaming is illegal in a generic body,
5583 -- even if the subtype is indefinite.
5585 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
5587 if not Is_Constrained (Prefix_Type)
5588 and then (not Is_Indefinite_Subtype (Prefix_Type)
5589 or else
5590 (Is_Generic_Type (Prefix_Type)
5591 and then Ekind (Current_Scope) = E_Generic_Package
5592 and then In_Package_Body (Current_Scope)))
5594 and then (Is_Declared_Within_Variant (Comp)
5595 or else Has_Discriminant_Dependent_Constraint (Comp))
5596 and then (not P_Aliased or else Ada_Version >= Ada_05)
5597 then
5598 return True;
5600 else
5601 return
5602 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
5604 end if;
5606 elsif Nkind (Object) = N_Indexed_Component
5607 or else Nkind (Object) = N_Slice
5608 then
5609 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
5611 -- A type conversion that Is_Variable is a view conversion:
5612 -- go back to the denoted object.
5614 elsif Nkind (Object) = N_Type_Conversion then
5615 return
5616 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
5617 end if;
5618 end if;
5620 return False;
5621 end Is_Dependent_Component_Of_Mutable_Object;
5623 ---------------------
5624 -- Is_Dereferenced --
5625 ---------------------
5627 function Is_Dereferenced (N : Node_Id) return Boolean is
5628 P : constant Node_Id := Parent (N);
5629 begin
5630 return
5631 (Nkind (P) = N_Selected_Component
5632 or else
5633 Nkind (P) = N_Explicit_Dereference
5634 or else
5635 Nkind (P) = N_Indexed_Component
5636 or else
5637 Nkind (P) = N_Slice)
5638 and then Prefix (P) = N;
5639 end Is_Dereferenced;
5641 ----------------------
5642 -- Is_Descendent_Of --
5643 ----------------------
5645 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
5646 T : Entity_Id;
5647 Etyp : Entity_Id;
5649 begin
5650 pragma Assert (Nkind (T1) in N_Entity);
5651 pragma Assert (Nkind (T2) in N_Entity);
5653 T := Base_Type (T1);
5655 -- Immediate return if the types match
5657 if T = T2 then
5658 return True;
5660 -- Comment needed here ???
5662 elsif Ekind (T) = E_Class_Wide_Type then
5663 return Etype (T) = T2;
5665 -- All other cases
5667 else
5668 loop
5669 Etyp := Etype (T);
5671 -- Done if we found the type we are looking for
5673 if Etyp = T2 then
5674 return True;
5676 -- Done if no more derivations to check
5678 elsif T = T1
5679 or else T = Etyp
5680 then
5681 return False;
5683 -- Following test catches error cases resulting from prev errors
5685 elsif No (Etyp) then
5686 return False;
5688 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
5689 return False;
5691 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
5692 return False;
5693 end if;
5695 T := Base_Type (Etyp);
5696 end loop;
5697 end if;
5698 end Is_Descendent_Of;
5700 --------------
5701 -- Is_False --
5702 --------------
5704 function Is_False (U : Uint) return Boolean is
5705 begin
5706 return (U = 0);
5707 end Is_False;
5709 ---------------------------
5710 -- Is_Fixed_Model_Number --
5711 ---------------------------
5713 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
5714 S : constant Ureal := Small_Value (T);
5715 M : Urealp.Save_Mark;
5716 R : Boolean;
5717 begin
5718 M := Urealp.Mark;
5719 R := (U = UR_Trunc (U / S) * S);
5720 Urealp.Release (M);
5721 return R;
5722 end Is_Fixed_Model_Number;
5724 -------------------------------
5725 -- Is_Fully_Initialized_Type --
5726 -------------------------------
5728 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
5729 begin
5730 if Is_Scalar_Type (Typ) then
5731 return False;
5733 elsif Is_Access_Type (Typ) then
5734 return True;
5736 elsif Is_Array_Type (Typ) then
5737 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
5738 return True;
5739 end if;
5741 -- An interesting case, if we have a constrained type one of whose
5742 -- bounds is known to be null, then there are no elements to be
5743 -- initialized, so all the elements are initialized!
5745 if Is_Constrained (Typ) then
5746 declare
5747 Indx : Node_Id;
5748 Indx_Typ : Entity_Id;
5749 Lbd, Hbd : Node_Id;
5751 begin
5752 Indx := First_Index (Typ);
5753 while Present (Indx) loop
5754 if Etype (Indx) = Any_Type then
5755 return False;
5757 -- If index is a range, use directly
5759 elsif Nkind (Indx) = N_Range then
5760 Lbd := Low_Bound (Indx);
5761 Hbd := High_Bound (Indx);
5763 else
5764 Indx_Typ := Etype (Indx);
5766 if Is_Private_Type (Indx_Typ) then
5767 Indx_Typ := Full_View (Indx_Typ);
5768 end if;
5770 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
5771 return False;
5772 else
5773 Lbd := Type_Low_Bound (Indx_Typ);
5774 Hbd := Type_High_Bound (Indx_Typ);
5775 end if;
5776 end if;
5778 if Compile_Time_Known_Value (Lbd)
5779 and then Compile_Time_Known_Value (Hbd)
5780 then
5781 if Expr_Value (Hbd) < Expr_Value (Lbd) then
5782 return True;
5783 end if;
5784 end if;
5786 Next_Index (Indx);
5787 end loop;
5788 end;
5789 end if;
5791 -- If no null indexes, then type is not fully initialized
5793 return False;
5795 -- Record types
5797 elsif Is_Record_Type (Typ) then
5798 if Has_Discriminants (Typ)
5799 and then
5800 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
5801 and then Is_Fully_Initialized_Variant (Typ)
5802 then
5803 return True;
5804 end if;
5806 -- Controlled records are considered to be fully initialized if
5807 -- there is a user defined Initialize routine. This may not be
5808 -- entirely correct, but as the spec notes, we are guessing here
5809 -- what is best from the point of view of issuing warnings.
5811 if Is_Controlled (Typ) then
5812 declare
5813 Utyp : constant Entity_Id := Underlying_Type (Typ);
5815 begin
5816 if Present (Utyp) then
5817 declare
5818 Init : constant Entity_Id :=
5819 (Find_Prim_Op
5820 (Underlying_Type (Typ), Name_Initialize));
5822 begin
5823 if Present (Init)
5824 and then Comes_From_Source (Init)
5825 and then not
5826 Is_Predefined_File_Name
5827 (File_Name (Get_Source_File_Index (Sloc (Init))))
5828 then
5829 return True;
5831 elsif Has_Null_Extension (Typ)
5832 and then
5833 Is_Fully_Initialized_Type
5834 (Etype (Base_Type (Typ)))
5835 then
5836 return True;
5837 end if;
5838 end;
5839 end if;
5840 end;
5841 end if;
5843 -- Otherwise see if all record components are initialized
5845 declare
5846 Ent : Entity_Id;
5848 begin
5849 Ent := First_Entity (Typ);
5850 while Present (Ent) loop
5851 if Chars (Ent) = Name_uController then
5852 null;
5854 elsif Ekind (Ent) = E_Component
5855 and then (No (Parent (Ent))
5856 or else No (Expression (Parent (Ent))))
5857 and then not Is_Fully_Initialized_Type (Etype (Ent))
5859 -- Special VM case for tag components, which need to be
5860 -- defined in this case, but are never initialized as VMs
5861 -- are using other dispatching mechanisms. Ignore this
5862 -- uninitialized case. Note that this applies both to the
5863 -- uTag entry and the main vtable pointer (CPP_Class case).
5865 and then (VM_Target = No_VM or else not Is_Tag (Ent))
5866 then
5867 return False;
5868 end if;
5870 Next_Entity (Ent);
5871 end loop;
5872 end;
5874 -- No uninitialized components, so type is fully initialized.
5875 -- Note that this catches the case of no components as well.
5877 return True;
5879 elsif Is_Concurrent_Type (Typ) then
5880 return True;
5882 elsif Is_Private_Type (Typ) then
5883 declare
5884 U : constant Entity_Id := Underlying_Type (Typ);
5886 begin
5887 if No (U) then
5888 return False;
5889 else
5890 return Is_Fully_Initialized_Type (U);
5891 end if;
5892 end;
5894 else
5895 return False;
5896 end if;
5897 end Is_Fully_Initialized_Type;
5899 ----------------------------------
5900 -- Is_Fully_Initialized_Variant --
5901 ----------------------------------
5903 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
5904 Loc : constant Source_Ptr := Sloc (Typ);
5905 Constraints : constant List_Id := New_List;
5906 Components : constant Elist_Id := New_Elmt_List;
5907 Comp_Elmt : Elmt_Id;
5908 Comp_Id : Node_Id;
5909 Comp_List : Node_Id;
5910 Discr : Entity_Id;
5911 Discr_Val : Node_Id;
5913 Report_Errors : Boolean;
5914 pragma Warnings (Off, Report_Errors);
5916 begin
5917 if Serious_Errors_Detected > 0 then
5918 return False;
5919 end if;
5921 if Is_Record_Type (Typ)
5922 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
5923 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
5924 then
5925 Comp_List := Component_List (Type_Definition (Parent (Typ)));
5927 Discr := First_Discriminant (Typ);
5928 while Present (Discr) loop
5929 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
5930 Discr_Val := Expression (Parent (Discr));
5932 if Present (Discr_Val)
5933 and then Is_OK_Static_Expression (Discr_Val)
5934 then
5935 Append_To (Constraints,
5936 Make_Component_Association (Loc,
5937 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
5938 Expression => New_Copy (Discr_Val)));
5939 else
5940 return False;
5941 end if;
5942 else
5943 return False;
5944 end if;
5946 Next_Discriminant (Discr);
5947 end loop;
5949 Gather_Components
5950 (Typ => Typ,
5951 Comp_List => Comp_List,
5952 Governed_By => Constraints,
5953 Into => Components,
5954 Report_Errors => Report_Errors);
5956 -- Check that each component present is fully initialized
5958 Comp_Elmt := First_Elmt (Components);
5959 while Present (Comp_Elmt) loop
5960 Comp_Id := Node (Comp_Elmt);
5962 if Ekind (Comp_Id) = E_Component
5963 and then (No (Parent (Comp_Id))
5964 or else No (Expression (Parent (Comp_Id))))
5965 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
5966 then
5967 return False;
5968 end if;
5970 Next_Elmt (Comp_Elmt);
5971 end loop;
5973 return True;
5975 elsif Is_Private_Type (Typ) then
5976 declare
5977 U : constant Entity_Id := Underlying_Type (Typ);
5979 begin
5980 if No (U) then
5981 return False;
5982 else
5983 return Is_Fully_Initialized_Variant (U);
5984 end if;
5985 end;
5986 else
5987 return False;
5988 end if;
5989 end Is_Fully_Initialized_Variant;
5991 ----------------------------
5992 -- Is_Inherited_Operation --
5993 ----------------------------
5995 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
5996 Kind : constant Node_Kind := Nkind (Parent (E));
5997 begin
5998 pragma Assert (Is_Overloadable (E));
5999 return Kind = N_Full_Type_Declaration
6000 or else Kind = N_Private_Extension_Declaration
6001 or else Kind = N_Subtype_Declaration
6002 or else (Ekind (E) = E_Enumeration_Literal
6003 and then Is_Derived_Type (Etype (E)));
6004 end Is_Inherited_Operation;
6006 -----------------------------
6007 -- Is_Library_Level_Entity --
6008 -----------------------------
6010 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
6011 begin
6012 -- The following is a small optimization, and it also properly handles
6013 -- discriminals, which in task bodies might appear in expressions before
6014 -- the corresponding procedure has been created, and which therefore do
6015 -- not have an assigned scope.
6017 if Ekind (E) in Formal_Kind then
6018 return False;
6019 end if;
6021 -- Normal test is simply that the enclosing dynamic scope is Standard
6023 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
6024 end Is_Library_Level_Entity;
6026 ---------------------------------
6027 -- Is_Local_Variable_Reference --
6028 ---------------------------------
6030 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
6031 begin
6032 if not Is_Entity_Name (Expr) then
6033 return False;
6035 else
6036 declare
6037 Ent : constant Entity_Id := Entity (Expr);
6038 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
6039 begin
6040 if Ekind (Ent) /= E_Variable
6041 and then
6042 Ekind (Ent) /= E_In_Out_Parameter
6043 then
6044 return False;
6045 else
6046 return Present (Sub) and then Sub = Current_Subprogram;
6047 end if;
6048 end;
6049 end if;
6050 end Is_Local_Variable_Reference;
6052 -------------------------
6053 -- Is_Object_Reference --
6054 -------------------------
6056 function Is_Object_Reference (N : Node_Id) return Boolean is
6057 begin
6058 if Is_Entity_Name (N) then
6059 return Present (Entity (N)) and then Is_Object (Entity (N));
6061 else
6062 case Nkind (N) is
6063 when N_Indexed_Component | N_Slice =>
6064 return
6065 Is_Object_Reference (Prefix (N))
6066 or else Is_Access_Type (Etype (Prefix (N)));
6068 -- In Ada95, a function call is a constant object; a procedure
6069 -- call is not.
6071 when N_Function_Call =>
6072 return Etype (N) /= Standard_Void_Type;
6074 -- A reference to the stream attribute Input is a function call
6076 when N_Attribute_Reference =>
6077 return Attribute_Name (N) = Name_Input;
6079 when N_Selected_Component =>
6080 return
6081 Is_Object_Reference (Selector_Name (N))
6082 and then
6083 (Is_Object_Reference (Prefix (N))
6084 or else Is_Access_Type (Etype (Prefix (N))));
6086 when N_Explicit_Dereference =>
6087 return True;
6089 -- A view conversion of a tagged object is an object reference
6091 when N_Type_Conversion =>
6092 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
6093 and then Is_Tagged_Type (Etype (Expression (N)))
6094 and then Is_Object_Reference (Expression (N));
6096 -- An unchecked type conversion is considered to be an object if
6097 -- the operand is an object (this construction arises only as a
6098 -- result of expansion activities).
6100 when N_Unchecked_Type_Conversion =>
6101 return True;
6103 when others =>
6104 return False;
6105 end case;
6106 end if;
6107 end Is_Object_Reference;
6109 -----------------------------------
6110 -- Is_OK_Variable_For_Out_Formal --
6111 -----------------------------------
6113 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
6114 begin
6115 Note_Possible_Modification (AV, Sure => True);
6117 -- We must reject parenthesized variable names. The check for
6118 -- Comes_From_Source is present because there are currently
6119 -- cases where the compiler violates this rule (e.g. passing
6120 -- a task object to its controlled Initialize routine).
6122 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
6123 return False;
6125 -- A variable is always allowed
6127 elsif Is_Variable (AV) then
6128 return True;
6130 -- Unchecked conversions are allowed only if they come from the
6131 -- generated code, which sometimes uses unchecked conversions for out
6132 -- parameters in cases where code generation is unaffected. We tell
6133 -- source unchecked conversions by seeing if they are rewrites of an
6134 -- original Unchecked_Conversion function call, or of an explicit
6135 -- conversion of a function call.
6137 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
6138 if Nkind (Original_Node (AV)) = N_Function_Call then
6139 return False;
6141 elsif Comes_From_Source (AV)
6142 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
6143 then
6144 return False;
6146 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
6147 return Is_OK_Variable_For_Out_Formal (Expression (AV));
6149 else
6150 return True;
6151 end if;
6153 -- Normal type conversions are allowed if argument is a variable
6155 elsif Nkind (AV) = N_Type_Conversion then
6156 if Is_Variable (Expression (AV))
6157 and then Paren_Count (Expression (AV)) = 0
6158 then
6159 Note_Possible_Modification (Expression (AV), Sure => True);
6160 return True;
6162 -- We also allow a non-parenthesized expression that raises
6163 -- constraint error if it rewrites what used to be a variable
6165 elsif Raises_Constraint_Error (Expression (AV))
6166 and then Paren_Count (Expression (AV)) = 0
6167 and then Is_Variable (Original_Node (Expression (AV)))
6168 then
6169 return True;
6171 -- Type conversion of something other than a variable
6173 else
6174 return False;
6175 end if;
6177 -- If this node is rewritten, then test the original form, if that is
6178 -- OK, then we consider the rewritten node OK (for example, if the
6179 -- original node is a conversion, then Is_Variable will not be true
6180 -- but we still want to allow the conversion if it converts a variable).
6182 elsif Original_Node (AV) /= AV then
6183 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
6185 -- All other non-variables are rejected
6187 else
6188 return False;
6189 end if;
6190 end Is_OK_Variable_For_Out_Formal;
6192 -----------------------------------
6193 -- Is_Partially_Initialized_Type --
6194 -----------------------------------
6196 function Is_Partially_Initialized_Type (Typ : Entity_Id) return Boolean is
6197 begin
6198 if Is_Scalar_Type (Typ) then
6199 return False;
6201 elsif Is_Access_Type (Typ) then
6202 return True;
6204 elsif Is_Array_Type (Typ) then
6206 -- If component type is partially initialized, so is array type
6208 if Is_Partially_Initialized_Type (Component_Type (Typ)) then
6209 return True;
6211 -- Otherwise we are only partially initialized if we are fully
6212 -- initialized (this is the empty array case, no point in us
6213 -- duplicating that code here).
6215 else
6216 return Is_Fully_Initialized_Type (Typ);
6217 end if;
6219 elsif Is_Record_Type (Typ) then
6221 -- A discriminated type is always partially initialized
6223 if Has_Discriminants (Typ) then
6224 return True;
6226 -- A tagged type is always partially initialized
6228 elsif Is_Tagged_Type (Typ) then
6229 return True;
6231 -- Case of non-discriminated record
6233 else
6234 declare
6235 Ent : Entity_Id;
6237 Component_Present : Boolean := False;
6238 -- Set True if at least one component is present. If no
6239 -- components are present, then record type is fully
6240 -- initialized (another odd case, like the null array).
6242 begin
6243 -- Loop through components
6245 Ent := First_Entity (Typ);
6246 while Present (Ent) loop
6247 if Ekind (Ent) = E_Component then
6248 Component_Present := True;
6250 -- If a component has an initialization expression then
6251 -- the enclosing record type is partially initialized
6253 if Present (Parent (Ent))
6254 and then Present (Expression (Parent (Ent)))
6255 then
6256 return True;
6258 -- If a component is of a type which is itself partially
6259 -- initialized, then the enclosing record type is also.
6261 elsif Is_Partially_Initialized_Type (Etype (Ent)) then
6262 return True;
6263 end if;
6264 end if;
6266 Next_Entity (Ent);
6267 end loop;
6269 -- No initialized components found. If we found any components
6270 -- they were all uninitialized so the result is false.
6272 if Component_Present then
6273 return False;
6275 -- But if we found no components, then all the components are
6276 -- initialized so we consider the type to be initialized.
6278 else
6279 return True;
6280 end if;
6281 end;
6282 end if;
6284 -- Concurrent types are always fully initialized
6286 elsif Is_Concurrent_Type (Typ) then
6287 return True;
6289 -- For a private type, go to underlying type. If there is no underlying
6290 -- type then just assume this partially initialized. Not clear if this
6291 -- can happen in a non-error case, but no harm in testing for this.
6293 elsif Is_Private_Type (Typ) then
6294 declare
6295 U : constant Entity_Id := Underlying_Type (Typ);
6296 begin
6297 if No (U) then
6298 return True;
6299 else
6300 return Is_Partially_Initialized_Type (U);
6301 end if;
6302 end;
6304 -- For any other type (are there any?) assume partially initialized
6306 else
6307 return True;
6308 end if;
6309 end Is_Partially_Initialized_Type;
6311 ------------------------------------
6312 -- Is_Potentially_Persistent_Type --
6313 ------------------------------------
6315 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
6316 Comp : Entity_Id;
6317 Indx : Node_Id;
6319 begin
6320 -- For private type, test corresponding full type
6322 if Is_Private_Type (T) then
6323 return Is_Potentially_Persistent_Type (Full_View (T));
6325 -- Scalar types are potentially persistent
6327 elsif Is_Scalar_Type (T) then
6328 return True;
6330 -- Record type is potentially persistent if not tagged and the types of
6331 -- all it components are potentially persistent, and no component has
6332 -- an initialization expression.
6334 elsif Is_Record_Type (T)
6335 and then not Is_Tagged_Type (T)
6336 and then not Is_Partially_Initialized_Type (T)
6337 then
6338 Comp := First_Component (T);
6339 while Present (Comp) loop
6340 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
6341 return False;
6342 else
6343 Next_Entity (Comp);
6344 end if;
6345 end loop;
6347 return True;
6349 -- Array type is potentially persistent if its component type is
6350 -- potentially persistent and if all its constraints are static.
6352 elsif Is_Array_Type (T) then
6353 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
6354 return False;
6355 end if;
6357 Indx := First_Index (T);
6358 while Present (Indx) loop
6359 if not Is_OK_Static_Subtype (Etype (Indx)) then
6360 return False;
6361 else
6362 Next_Index (Indx);
6363 end if;
6364 end loop;
6366 return True;
6368 -- All other types are not potentially persistent
6370 else
6371 return False;
6372 end if;
6373 end Is_Potentially_Persistent_Type;
6375 -----------------------------
6376 -- Is_RCI_Pkg_Spec_Or_Body --
6377 -----------------------------
6379 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
6381 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
6382 -- Return True if the unit of Cunit is an RCI package declaration
6384 ---------------------------
6385 -- Is_RCI_Pkg_Decl_Cunit --
6386 ---------------------------
6388 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
6389 The_Unit : constant Node_Id := Unit (Cunit);
6391 begin
6392 if Nkind (The_Unit) /= N_Package_Declaration then
6393 return False;
6394 end if;
6396 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
6397 end Is_RCI_Pkg_Decl_Cunit;
6399 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
6401 begin
6402 return Is_RCI_Pkg_Decl_Cunit (Cunit)
6403 or else
6404 (Nkind (Unit (Cunit)) = N_Package_Body
6405 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
6406 end Is_RCI_Pkg_Spec_Or_Body;
6408 -----------------------------------------
6409 -- Is_Remote_Access_To_Class_Wide_Type --
6410 -----------------------------------------
6412 function Is_Remote_Access_To_Class_Wide_Type
6413 (E : Entity_Id) return Boolean
6415 begin
6416 -- A remote access to class-wide type is a general access to object type
6417 -- declared in the visible part of a Remote_Types or Remote_Call_
6418 -- Interface unit.
6420 return Ekind (E) = E_General_Access_Type
6421 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
6422 end Is_Remote_Access_To_Class_Wide_Type;
6424 -----------------------------------------
6425 -- Is_Remote_Access_To_Subprogram_Type --
6426 -----------------------------------------
6428 function Is_Remote_Access_To_Subprogram_Type
6429 (E : Entity_Id) return Boolean
6431 begin
6432 return (Ekind (E) = E_Access_Subprogram_Type
6433 or else (Ekind (E) = E_Record_Type
6434 and then Present (Corresponding_Remote_Type (E))))
6435 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
6436 end Is_Remote_Access_To_Subprogram_Type;
6438 --------------------
6439 -- Is_Remote_Call --
6440 --------------------
6442 function Is_Remote_Call (N : Node_Id) return Boolean is
6443 begin
6444 if Nkind (N) /= N_Procedure_Call_Statement
6445 and then Nkind (N) /= N_Function_Call
6446 then
6447 -- An entry call cannot be remote
6449 return False;
6451 elsif Nkind (Name (N)) in N_Has_Entity
6452 and then Is_Remote_Call_Interface (Entity (Name (N)))
6453 then
6454 -- A subprogram declared in the spec of a RCI package is remote
6456 return True;
6458 elsif Nkind (Name (N)) = N_Explicit_Dereference
6459 and then Is_Remote_Access_To_Subprogram_Type
6460 (Etype (Prefix (Name (N))))
6461 then
6462 -- The dereference of a RAS is a remote call
6464 return True;
6466 elsif Present (Controlling_Argument (N))
6467 and then Is_Remote_Access_To_Class_Wide_Type
6468 (Etype (Controlling_Argument (N)))
6469 then
6470 -- Any primitive operation call with a controlling argument of
6471 -- a RACW type is a remote call.
6473 return True;
6474 end if;
6476 -- All other calls are local calls
6478 return False;
6479 end Is_Remote_Call;
6481 ----------------------
6482 -- Is_Renamed_Entry --
6483 ----------------------
6485 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
6486 Orig_Node : Node_Id := Empty;
6487 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
6489 function Is_Entry (Nam : Node_Id) return Boolean;
6490 -- Determine whether Nam is an entry. Traverse selectors if there are
6491 -- nested selected components.
6493 --------------
6494 -- Is_Entry --
6495 --------------
6497 function Is_Entry (Nam : Node_Id) return Boolean is
6498 begin
6499 if Nkind (Nam) = N_Selected_Component then
6500 return Is_Entry (Selector_Name (Nam));
6501 end if;
6503 return Ekind (Entity (Nam)) = E_Entry;
6504 end Is_Entry;
6506 -- Start of processing for Is_Renamed_Entry
6508 begin
6509 if Present (Alias (Proc_Nam)) then
6510 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
6511 end if;
6513 -- Look for a rewritten subprogram renaming declaration
6515 if Nkind (Subp_Decl) = N_Subprogram_Declaration
6516 and then Present (Original_Node (Subp_Decl))
6517 then
6518 Orig_Node := Original_Node (Subp_Decl);
6519 end if;
6521 -- The rewritten subprogram is actually an entry
6523 if Present (Orig_Node)
6524 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
6525 and then Is_Entry (Name (Orig_Node))
6526 then
6527 return True;
6528 end if;
6530 return False;
6531 end Is_Renamed_Entry;
6533 ----------------------
6534 -- Is_Selector_Name --
6535 ----------------------
6537 function Is_Selector_Name (N : Node_Id) return Boolean is
6538 begin
6539 if not Is_List_Member (N) then
6540 declare
6541 P : constant Node_Id := Parent (N);
6542 K : constant Node_Kind := Nkind (P);
6543 begin
6544 return
6545 (K = N_Expanded_Name or else
6546 K = N_Generic_Association or else
6547 K = N_Parameter_Association or else
6548 K = N_Selected_Component)
6549 and then Selector_Name (P) = N;
6550 end;
6552 else
6553 declare
6554 L : constant List_Id := List_Containing (N);
6555 P : constant Node_Id := Parent (L);
6556 begin
6557 return (Nkind (P) = N_Discriminant_Association
6558 and then Selector_Names (P) = L)
6559 or else
6560 (Nkind (P) = N_Component_Association
6561 and then Choices (P) = L);
6562 end;
6563 end if;
6564 end Is_Selector_Name;
6566 ------------------
6567 -- Is_Statement --
6568 ------------------
6570 function Is_Statement (N : Node_Id) return Boolean is
6571 begin
6572 return
6573 Nkind (N) in N_Statement_Other_Than_Procedure_Call
6574 or else Nkind (N) = N_Procedure_Call_Statement;
6575 end Is_Statement;
6577 ---------------------------------
6578 -- Is_Synchronized_Tagged_Type --
6579 ---------------------------------
6581 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
6582 Kind : constant Entity_Kind := Ekind (Base_Type (E));
6584 begin
6585 -- A task or protected type derived from an interface is a tagged type.
6586 -- Such a tagged type is called a synchronized tagged type, as are
6587 -- synchronized interfaces and private extensions whose declaration
6588 -- includes the reserved word synchronized.
6590 return (Is_Tagged_Type (E)
6591 and then (Kind = E_Task_Type
6592 or else Kind = E_Protected_Type))
6593 or else
6594 (Is_Interface (E)
6595 and then Is_Synchronized_Interface (E))
6596 or else
6597 (Ekind (E) = E_Record_Type_With_Private
6598 and then (Synchronized_Present (Parent (E))
6599 or else Is_Synchronized_Interface (Etype (E))));
6600 end Is_Synchronized_Tagged_Type;
6602 -----------------
6603 -- Is_Transfer --
6604 -----------------
6606 function Is_Transfer (N : Node_Id) return Boolean is
6607 Kind : constant Node_Kind := Nkind (N);
6609 begin
6610 if Kind = N_Simple_Return_Statement
6611 or else
6612 Kind = N_Extended_Return_Statement
6613 or else
6614 Kind = N_Goto_Statement
6615 or else
6616 Kind = N_Raise_Statement
6617 or else
6618 Kind = N_Requeue_Statement
6619 then
6620 return True;
6622 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
6623 and then No (Condition (N))
6624 then
6625 return True;
6627 elsif Kind = N_Procedure_Call_Statement
6628 and then Is_Entity_Name (Name (N))
6629 and then Present (Entity (Name (N)))
6630 and then No_Return (Entity (Name (N)))
6631 then
6632 return True;
6634 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
6635 return True;
6637 else
6638 return False;
6639 end if;
6640 end Is_Transfer;
6642 -------------
6643 -- Is_True --
6644 -------------
6646 function Is_True (U : Uint) return Boolean is
6647 begin
6648 return (U /= 0);
6649 end Is_True;
6651 -------------------
6652 -- Is_Value_Type --
6653 -------------------
6655 function Is_Value_Type (T : Entity_Id) return Boolean is
6656 begin
6657 return VM_Target = CLI_Target
6658 and then Chars (T) /= No_Name
6659 and then Get_Name_String (Chars (T)) = "valuetype";
6660 end Is_Value_Type;
6662 -----------------
6663 -- Is_Variable --
6664 -----------------
6666 function Is_Variable (N : Node_Id) return Boolean is
6668 Orig_Node : constant Node_Id := Original_Node (N);
6669 -- We do the test on the original node, since this is basically a
6670 -- test of syntactic categories, so it must not be disturbed by
6671 -- whatever rewriting might have occurred. For example, an aggregate,
6672 -- which is certainly NOT a variable, could be turned into a variable
6673 -- by expansion.
6675 function In_Protected_Function (E : Entity_Id) return Boolean;
6676 -- Within a protected function, the private components of the
6677 -- enclosing protected type are constants. A function nested within
6678 -- a (protected) procedure is not itself protected.
6680 function Is_Variable_Prefix (P : Node_Id) return Boolean;
6681 -- Prefixes can involve implicit dereferences, in which case we
6682 -- must test for the case of a reference of a constant access
6683 -- type, which can never be a variable.
6685 ---------------------------
6686 -- In_Protected_Function --
6687 ---------------------------
6689 function In_Protected_Function (E : Entity_Id) return Boolean is
6690 Prot : constant Entity_Id := Scope (E);
6691 S : Entity_Id;
6693 begin
6694 if not Is_Protected_Type (Prot) then
6695 return False;
6696 else
6697 S := Current_Scope;
6698 while Present (S) and then S /= Prot loop
6699 if Ekind (S) = E_Function
6700 and then Scope (S) = Prot
6701 then
6702 return True;
6703 end if;
6705 S := Scope (S);
6706 end loop;
6708 return False;
6709 end if;
6710 end In_Protected_Function;
6712 ------------------------
6713 -- Is_Variable_Prefix --
6714 ------------------------
6716 function Is_Variable_Prefix (P : Node_Id) return Boolean is
6717 begin
6718 if Is_Access_Type (Etype (P)) then
6719 return not Is_Access_Constant (Root_Type (Etype (P)));
6721 -- For the case of an indexed component whose prefix has a packed
6722 -- array type, the prefix has been rewritten into a type conversion.
6723 -- Determine variable-ness from the converted expression.
6725 elsif Nkind (P) = N_Type_Conversion
6726 and then not Comes_From_Source (P)
6727 and then Is_Array_Type (Etype (P))
6728 and then Is_Packed (Etype (P))
6729 then
6730 return Is_Variable (Expression (P));
6732 else
6733 return Is_Variable (P);
6734 end if;
6735 end Is_Variable_Prefix;
6737 -- Start of processing for Is_Variable
6739 begin
6740 -- Definitely OK if Assignment_OK is set. Since this is something that
6741 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
6743 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
6744 return True;
6746 -- Normally we go to the original node, but there is one exception
6747 -- where we use the rewritten node, namely when it is an explicit
6748 -- dereference. The generated code may rewrite a prefix which is an
6749 -- access type with an explicit dereference. The dereference is a
6750 -- variable, even though the original node may not be (since it could
6751 -- be a constant of the access type).
6753 -- In Ada 2005 we have a further case to consider: the prefix may be
6754 -- a function call given in prefix notation. The original node appears
6755 -- to be a selected component, but we need to examine the call.
6757 elsif Nkind (N) = N_Explicit_Dereference
6758 and then Nkind (Orig_Node) /= N_Explicit_Dereference
6759 and then Present (Etype (Orig_Node))
6760 and then Is_Access_Type (Etype (Orig_Node))
6761 then
6762 return Is_Variable_Prefix (Original_Node (Prefix (N)))
6763 or else
6764 (Nkind (Orig_Node) = N_Function_Call
6765 and then not Is_Access_Constant (Etype (Prefix (N))));
6767 -- A function call is never a variable
6769 elsif Nkind (N) = N_Function_Call then
6770 return False;
6772 -- All remaining checks use the original node
6774 elsif Is_Entity_Name (Orig_Node)
6775 and then Present (Entity (Orig_Node))
6776 then
6777 declare
6778 E : constant Entity_Id := Entity (Orig_Node);
6779 K : constant Entity_Kind := Ekind (E);
6781 begin
6782 return (K = E_Variable
6783 and then Nkind (Parent (E)) /= N_Exception_Handler)
6784 or else (K = E_Component
6785 and then not In_Protected_Function (E))
6786 or else K = E_Out_Parameter
6787 or else K = E_In_Out_Parameter
6788 or else K = E_Generic_In_Out_Parameter
6790 -- Current instance of type:
6792 or else (Is_Type (E) and then In_Open_Scopes (E))
6793 or else (Is_Incomplete_Or_Private_Type (E)
6794 and then In_Open_Scopes (Full_View (E)));
6795 end;
6797 else
6798 case Nkind (Orig_Node) is
6799 when N_Indexed_Component | N_Slice =>
6800 return Is_Variable_Prefix (Prefix (Orig_Node));
6802 when N_Selected_Component =>
6803 return Is_Variable_Prefix (Prefix (Orig_Node))
6804 and then Is_Variable (Selector_Name (Orig_Node));
6806 -- For an explicit dereference, the type of the prefix cannot
6807 -- be an access to constant or an access to subprogram.
6809 when N_Explicit_Dereference =>
6810 declare
6811 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
6812 begin
6813 return Is_Access_Type (Typ)
6814 and then not Is_Access_Constant (Root_Type (Typ))
6815 and then Ekind (Typ) /= E_Access_Subprogram_Type;
6816 end;
6818 -- The type conversion is the case where we do not deal with the
6819 -- context dependent special case of an actual parameter. Thus
6820 -- the type conversion is only considered a variable for the
6821 -- purposes of this routine if the target type is tagged. However,
6822 -- a type conversion is considered to be a variable if it does not
6823 -- come from source (this deals for example with the conversions
6824 -- of expressions to their actual subtypes).
6826 when N_Type_Conversion =>
6827 return Is_Variable (Expression (Orig_Node))
6828 and then
6829 (not Comes_From_Source (Orig_Node)
6830 or else
6831 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
6832 and then
6833 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
6835 -- GNAT allows an unchecked type conversion as a variable. This
6836 -- only affects the generation of internal expanded code, since
6837 -- calls to instantiations of Unchecked_Conversion are never
6838 -- considered variables (since they are function calls).
6839 -- This is also true for expression actions.
6841 when N_Unchecked_Type_Conversion =>
6842 return Is_Variable (Expression (Orig_Node));
6844 when others =>
6845 return False;
6846 end case;
6847 end if;
6848 end Is_Variable;
6850 ------------------------
6851 -- Is_Volatile_Object --
6852 ------------------------
6854 function Is_Volatile_Object (N : Node_Id) return Boolean is
6856 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
6857 -- Determines if given object has volatile components
6859 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
6860 -- If prefix is an implicit dereference, examine designated type
6862 ------------------------
6863 -- Is_Volatile_Prefix --
6864 ------------------------
6866 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
6867 Typ : constant Entity_Id := Etype (N);
6869 begin
6870 if Is_Access_Type (Typ) then
6871 declare
6872 Dtyp : constant Entity_Id := Designated_Type (Typ);
6874 begin
6875 return Is_Volatile (Dtyp)
6876 or else Has_Volatile_Components (Dtyp);
6877 end;
6879 else
6880 return Object_Has_Volatile_Components (N);
6881 end if;
6882 end Is_Volatile_Prefix;
6884 ------------------------------------
6885 -- Object_Has_Volatile_Components --
6886 ------------------------------------
6888 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
6889 Typ : constant Entity_Id := Etype (N);
6891 begin
6892 if Is_Volatile (Typ)
6893 or else Has_Volatile_Components (Typ)
6894 then
6895 return True;
6897 elsif Is_Entity_Name (N)
6898 and then (Has_Volatile_Components (Entity (N))
6899 or else Is_Volatile (Entity (N)))
6900 then
6901 return True;
6903 elsif Nkind (N) = N_Indexed_Component
6904 or else Nkind (N) = N_Selected_Component
6905 then
6906 return Is_Volatile_Prefix (Prefix (N));
6908 else
6909 return False;
6910 end if;
6911 end Object_Has_Volatile_Components;
6913 -- Start of processing for Is_Volatile_Object
6915 begin
6916 if Is_Volatile (Etype (N))
6917 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
6918 then
6919 return True;
6921 elsif Nkind (N) = N_Indexed_Component
6922 or else Nkind (N) = N_Selected_Component
6923 then
6924 return Is_Volatile_Prefix (Prefix (N));
6926 else
6927 return False;
6928 end if;
6929 end Is_Volatile_Object;
6931 -------------------------
6932 -- Kill_Current_Values --
6933 -------------------------
6935 procedure Kill_Current_Values
6936 (Ent : Entity_Id;
6937 Last_Assignment_Only : Boolean := False)
6939 begin
6940 if Is_Assignable (Ent) then
6941 Set_Last_Assignment (Ent, Empty);
6942 end if;
6944 if not Last_Assignment_Only and then Is_Object (Ent) then
6945 Kill_Checks (Ent);
6946 Set_Current_Value (Ent, Empty);
6948 if not Can_Never_Be_Null (Ent) then
6949 Set_Is_Known_Non_Null (Ent, False);
6950 end if;
6952 Set_Is_Known_Null (Ent, False);
6953 end if;
6954 end Kill_Current_Values;
6956 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
6957 S : Entity_Id;
6959 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
6960 -- Clear current value for entity E and all entities chained to E
6962 ------------------------------------------
6963 -- Kill_Current_Values_For_Entity_Chain --
6964 ------------------------------------------
6966 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
6967 Ent : Entity_Id;
6968 begin
6969 Ent := E;
6970 while Present (Ent) loop
6971 Kill_Current_Values (Ent, Last_Assignment_Only);
6972 Next_Entity (Ent);
6973 end loop;
6974 end Kill_Current_Values_For_Entity_Chain;
6976 -- Start of processing for Kill_Current_Values
6978 begin
6979 -- Kill all saved checks, a special case of killing saved values
6981 if not Last_Assignment_Only then
6982 Kill_All_Checks;
6983 end if;
6985 -- Loop through relevant scopes, which includes the current scope and
6986 -- any parent scopes if the current scope is a block or a package.
6988 S := Current_Scope;
6989 Scope_Loop : loop
6991 -- Clear current values of all entities in current scope
6993 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
6995 -- If scope is a package, also clear current values of all
6996 -- private entities in the scope.
6998 if Ekind (S) = E_Package
6999 or else
7000 Ekind (S) = E_Generic_Package
7001 or else
7002 Is_Concurrent_Type (S)
7003 then
7004 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
7005 end if;
7007 -- If this is a not a subprogram, deal with parents
7009 if not Is_Subprogram (S) then
7010 S := Scope (S);
7011 exit Scope_Loop when S = Standard_Standard;
7012 else
7013 exit Scope_Loop;
7014 end if;
7015 end loop Scope_Loop;
7016 end Kill_Current_Values;
7018 --------------------------
7019 -- Kill_Size_Check_Code --
7020 --------------------------
7022 procedure Kill_Size_Check_Code (E : Entity_Id) is
7023 begin
7024 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7025 and then Present (Size_Check_Code (E))
7026 then
7027 Remove (Size_Check_Code (E));
7028 Set_Size_Check_Code (E, Empty);
7029 end if;
7030 end Kill_Size_Check_Code;
7032 --------------------------
7033 -- Known_To_Be_Assigned --
7034 --------------------------
7036 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
7037 P : constant Node_Id := Parent (N);
7039 begin
7040 case Nkind (P) is
7042 -- Test left side of assignment
7044 when N_Assignment_Statement =>
7045 return N = Name (P);
7047 -- Function call arguments are never lvalues
7049 when N_Function_Call =>
7050 return False;
7052 -- Positional parameter for procedure or accept call
7054 when N_Procedure_Call_Statement |
7055 N_Accept_Statement
7057 declare
7058 Proc : Entity_Id;
7059 Form : Entity_Id;
7060 Act : Node_Id;
7062 begin
7063 Proc := Get_Subprogram_Entity (P);
7065 if No (Proc) then
7066 return False;
7067 end if;
7069 -- If we are not a list member, something is strange, so
7070 -- be conservative and return False.
7072 if not Is_List_Member (N) then
7073 return False;
7074 end if;
7076 -- We are going to find the right formal by stepping forward
7077 -- through the formals, as we step backwards in the actuals.
7079 Form := First_Formal (Proc);
7080 Act := N;
7081 loop
7082 -- If no formal, something is weird, so be conservative
7083 -- and return False.
7085 if No (Form) then
7086 return False;
7087 end if;
7089 Prev (Act);
7090 exit when No (Act);
7091 Next_Formal (Form);
7092 end loop;
7094 return Ekind (Form) /= E_In_Parameter;
7095 end;
7097 -- Named parameter for procedure or accept call
7099 when N_Parameter_Association =>
7100 declare
7101 Proc : Entity_Id;
7102 Form : Entity_Id;
7104 begin
7105 Proc := Get_Subprogram_Entity (Parent (P));
7107 if No (Proc) then
7108 return False;
7109 end if;
7111 -- Loop through formals to find the one that matches
7113 Form := First_Formal (Proc);
7114 loop
7115 -- If no matching formal, that's peculiar, some kind of
7116 -- previous error, so return False to be conservative.
7118 if No (Form) then
7119 return False;
7120 end if;
7122 -- Else test for match
7124 if Chars (Form) = Chars (Selector_Name (P)) then
7125 return Ekind (Form) /= E_In_Parameter;
7126 end if;
7128 Next_Formal (Form);
7129 end loop;
7130 end;
7132 -- Test for appearing in a conversion that itself appears
7133 -- in an lvalue context, since this should be an lvalue.
7135 when N_Type_Conversion =>
7136 return Known_To_Be_Assigned (P);
7138 -- All other references are definitely not known to be modifications
7140 when others =>
7141 return False;
7143 end case;
7144 end Known_To_Be_Assigned;
7146 -------------------
7147 -- May_Be_Lvalue --
7148 -------------------
7150 function May_Be_Lvalue (N : Node_Id) return Boolean is
7151 P : constant Node_Id := Parent (N);
7153 begin
7154 case Nkind (P) is
7156 -- Test left side of assignment
7158 when N_Assignment_Statement =>
7159 return N = Name (P);
7161 -- Test prefix of component or attribute
7163 when N_Attribute_Reference =>
7164 return N = Prefix (P)
7165 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
7167 when N_Expanded_Name |
7168 N_Explicit_Dereference |
7169 N_Indexed_Component |
7170 N_Reference |
7171 N_Selected_Component |
7172 N_Slice =>
7173 return N = Prefix (P);
7175 -- Function call arguments are never lvalues
7177 when N_Function_Call =>
7178 return False;
7180 -- Positional parameter for procedure, entry, or accept call
7182 when N_Procedure_Call_Statement |
7183 N_Entry_Call_Statement |
7184 N_Accept_Statement
7186 declare
7187 Proc : Entity_Id;
7188 Form : Entity_Id;
7189 Act : Node_Id;
7191 begin
7192 Proc := Get_Subprogram_Entity (P);
7194 if No (Proc) then
7195 return True;
7196 end if;
7198 -- If we are not a list member, something is strange, so
7199 -- be conservative and return True.
7201 if not Is_List_Member (N) then
7202 return True;
7203 end if;
7205 -- We are going to find the right formal by stepping forward
7206 -- through the formals, as we step backwards in the actuals.
7208 Form := First_Formal (Proc);
7209 Act := N;
7210 loop
7211 -- If no formal, something is weird, so be conservative
7212 -- and return True.
7214 if No (Form) then
7215 return True;
7216 end if;
7218 Prev (Act);
7219 exit when No (Act);
7220 Next_Formal (Form);
7221 end loop;
7223 return Ekind (Form) /= E_In_Parameter;
7224 end;
7226 -- Named parameter for procedure or accept call
7228 when N_Parameter_Association =>
7229 declare
7230 Proc : Entity_Id;
7231 Form : Entity_Id;
7233 begin
7234 Proc := Get_Subprogram_Entity (Parent (P));
7236 if No (Proc) then
7237 return True;
7238 end if;
7240 -- Loop through formals to find the one that matches
7242 Form := First_Formal (Proc);
7243 loop
7244 -- If no matching formal, that's peculiar, some kind of
7245 -- previous error, so return True to be conservative.
7247 if No (Form) then
7248 return True;
7249 end if;
7251 -- Else test for match
7253 if Chars (Form) = Chars (Selector_Name (P)) then
7254 return Ekind (Form) /= E_In_Parameter;
7255 end if;
7257 Next_Formal (Form);
7258 end loop;
7259 end;
7261 -- Test for appearing in a conversion that itself appears in an
7262 -- lvalue context, since this should be an lvalue.
7264 when N_Type_Conversion =>
7265 return May_Be_Lvalue (P);
7267 -- Test for appearance in object renaming declaration
7269 when N_Object_Renaming_Declaration =>
7270 return True;
7272 -- All other references are definitely not Lvalues
7274 when others =>
7275 return False;
7277 end case;
7278 end May_Be_Lvalue;
7280 -----------------------
7281 -- Mark_Coextensions --
7282 -----------------------
7284 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
7285 Is_Dynamic : Boolean;
7286 -- Indicates whether the context causes nested coextensions to be
7287 -- dynamic or static
7289 function Mark_Allocator (N : Node_Id) return Traverse_Result;
7290 -- Recognize an allocator node and label it as a dynamic coextension
7292 --------------------
7293 -- Mark_Allocator --
7294 --------------------
7296 function Mark_Allocator (N : Node_Id) return Traverse_Result is
7297 begin
7298 if Nkind (N) = N_Allocator then
7299 if Is_Dynamic then
7300 Set_Is_Dynamic_Coextension (N);
7301 else
7302 Set_Is_Static_Coextension (N);
7303 end if;
7304 end if;
7306 return OK;
7307 end Mark_Allocator;
7309 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
7311 -- Start of processing Mark_Coextensions
7313 begin
7314 case Nkind (Context_Nod) is
7315 when N_Assignment_Statement |
7316 N_Simple_Return_Statement =>
7317 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
7319 when N_Object_Declaration =>
7320 Is_Dynamic := Nkind (Root_Nod) = N_Allocator;
7322 -- This routine should not be called for constructs which may not
7323 -- contain coextensions.
7325 when others =>
7326 raise Program_Error;
7327 end case;
7329 Mark_Allocators (Root_Nod);
7330 end Mark_Coextensions;
7332 ----------------------
7333 -- Needs_One_Actual --
7334 ----------------------
7336 function Needs_One_Actual (E : Entity_Id) return Boolean is
7337 Formal : Entity_Id;
7339 begin
7340 if Ada_Version >= Ada_05
7341 and then Present (First_Formal (E))
7342 then
7343 Formal := Next_Formal (First_Formal (E));
7344 while Present (Formal) loop
7345 if No (Default_Value (Formal)) then
7346 return False;
7347 end if;
7349 Next_Formal (Formal);
7350 end loop;
7352 return True;
7354 else
7355 return False;
7356 end if;
7357 end Needs_One_Actual;
7359 -------------------------
7360 -- New_External_Entity --
7361 -------------------------
7363 function New_External_Entity
7364 (Kind : Entity_Kind;
7365 Scope_Id : Entity_Id;
7366 Sloc_Value : Source_Ptr;
7367 Related_Id : Entity_Id;
7368 Suffix : Character;
7369 Suffix_Index : Nat := 0;
7370 Prefix : Character := ' ') return Entity_Id
7372 N : constant Entity_Id :=
7373 Make_Defining_Identifier (Sloc_Value,
7374 New_External_Name
7375 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
7377 begin
7378 Set_Ekind (N, Kind);
7379 Set_Is_Internal (N, True);
7380 Append_Entity (N, Scope_Id);
7381 Set_Public_Status (N);
7383 if Kind in Type_Kind then
7384 Init_Size_Align (N);
7385 end if;
7387 return N;
7388 end New_External_Entity;
7390 -------------------------
7391 -- New_Internal_Entity --
7392 -------------------------
7394 function New_Internal_Entity
7395 (Kind : Entity_Kind;
7396 Scope_Id : Entity_Id;
7397 Sloc_Value : Source_Ptr;
7398 Id_Char : Character) return Entity_Id
7400 N : constant Entity_Id :=
7401 Make_Defining_Identifier (Sloc_Value, New_Internal_Name (Id_Char));
7403 begin
7404 Set_Ekind (N, Kind);
7405 Set_Is_Internal (N, True);
7406 Append_Entity (N, Scope_Id);
7408 if Kind in Type_Kind then
7409 Init_Size_Align (N);
7410 end if;
7412 return N;
7413 end New_Internal_Entity;
7415 -----------------
7416 -- Next_Actual --
7417 -----------------
7419 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
7420 N : Node_Id;
7422 begin
7423 -- If we are pointing at a positional parameter, it is a member of a
7424 -- node list (the list of parameters), and the next parameter is the
7425 -- next node on the list, unless we hit a parameter association, then
7426 -- we shift to using the chain whose head is the First_Named_Actual in
7427 -- the parent, and then is threaded using the Next_Named_Actual of the
7428 -- Parameter_Association. All this fiddling is because the original node
7429 -- list is in the textual call order, and what we need is the
7430 -- declaration order.
7432 if Is_List_Member (Actual_Id) then
7433 N := Next (Actual_Id);
7435 if Nkind (N) = N_Parameter_Association then
7436 return First_Named_Actual (Parent (Actual_Id));
7437 else
7438 return N;
7439 end if;
7441 else
7442 return Next_Named_Actual (Parent (Actual_Id));
7443 end if;
7444 end Next_Actual;
7446 procedure Next_Actual (Actual_Id : in out Node_Id) is
7447 begin
7448 Actual_Id := Next_Actual (Actual_Id);
7449 end Next_Actual;
7451 -----------------------
7452 -- Normalize_Actuals --
7453 -----------------------
7455 -- Chain actuals according to formals of subprogram. If there are no named
7456 -- associations, the chain is simply the list of Parameter Associations,
7457 -- since the order is the same as the declaration order. If there are named
7458 -- associations, then the First_Named_Actual field in the N_Function_Call
7459 -- or N_Procedure_Call_Statement node points to the Parameter_Association
7460 -- node for the parameter that comes first in declaration order. The
7461 -- remaining named parameters are then chained in declaration order using
7462 -- Next_Named_Actual.
7464 -- This routine also verifies that the number of actuals is compatible with
7465 -- the number and default values of formals, but performs no type checking
7466 -- (type checking is done by the caller).
7468 -- If the matching succeeds, Success is set to True and the caller proceeds
7469 -- with type-checking. If the match is unsuccessful, then Success is set to
7470 -- False, and the caller attempts a different interpretation, if there is
7471 -- one.
7473 -- If the flag Report is on, the call is not overloaded, and a failure to
7474 -- match can be reported here, rather than in the caller.
7476 procedure Normalize_Actuals
7477 (N : Node_Id;
7478 S : Entity_Id;
7479 Report : Boolean;
7480 Success : out Boolean)
7482 Actuals : constant List_Id := Parameter_Associations (N);
7483 Actual : Node_Id := Empty;
7484 Formal : Entity_Id;
7485 Last : Node_Id := Empty;
7486 First_Named : Node_Id := Empty;
7487 Found : Boolean;
7489 Formals_To_Match : Integer := 0;
7490 Actuals_To_Match : Integer := 0;
7492 procedure Chain (A : Node_Id);
7493 -- Add named actual at the proper place in the list, using the
7494 -- Next_Named_Actual link.
7496 function Reporting return Boolean;
7497 -- Determines if an error is to be reported. To report an error, we
7498 -- need Report to be True, and also we do not report errors caused
7499 -- by calls to init procs that occur within other init procs. Such
7500 -- errors must always be cascaded errors, since if all the types are
7501 -- declared correctly, the compiler will certainly build decent calls!
7503 -----------
7504 -- Chain --
7505 -----------
7507 procedure Chain (A : Node_Id) is
7508 begin
7509 if No (Last) then
7511 -- Call node points to first actual in list
7513 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
7515 else
7516 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
7517 end if;
7519 Last := A;
7520 Set_Next_Named_Actual (Last, Empty);
7521 end Chain;
7523 ---------------
7524 -- Reporting --
7525 ---------------
7527 function Reporting return Boolean is
7528 begin
7529 if not Report then
7530 return False;
7532 elsif not Within_Init_Proc then
7533 return True;
7535 elsif Is_Init_Proc (Entity (Name (N))) then
7536 return False;
7538 else
7539 return True;
7540 end if;
7541 end Reporting;
7543 -- Start of processing for Normalize_Actuals
7545 begin
7546 if Is_Access_Type (S) then
7548 -- The name in the call is a function call that returns an access
7549 -- to subprogram. The designated type has the list of formals.
7551 Formal := First_Formal (Designated_Type (S));
7552 else
7553 Formal := First_Formal (S);
7554 end if;
7556 while Present (Formal) loop
7557 Formals_To_Match := Formals_To_Match + 1;
7558 Next_Formal (Formal);
7559 end loop;
7561 -- Find if there is a named association, and verify that no positional
7562 -- associations appear after named ones.
7564 if Present (Actuals) then
7565 Actual := First (Actuals);
7566 end if;
7568 while Present (Actual)
7569 and then Nkind (Actual) /= N_Parameter_Association
7570 loop
7571 Actuals_To_Match := Actuals_To_Match + 1;
7572 Next (Actual);
7573 end loop;
7575 if No (Actual) and Actuals_To_Match = Formals_To_Match then
7577 -- Most common case: positional notation, no defaults
7579 Success := True;
7580 return;
7582 elsif Actuals_To_Match > Formals_To_Match then
7584 -- Too many actuals: will not work
7586 if Reporting then
7587 if Is_Entity_Name (Name (N)) then
7588 Error_Msg_N ("too many arguments in call to&", Name (N));
7589 else
7590 Error_Msg_N ("too many arguments in call", N);
7591 end if;
7592 end if;
7594 Success := False;
7595 return;
7596 end if;
7598 First_Named := Actual;
7600 while Present (Actual) loop
7601 if Nkind (Actual) /= N_Parameter_Association then
7602 Error_Msg_N
7603 ("positional parameters not allowed after named ones", Actual);
7604 Success := False;
7605 return;
7607 else
7608 Actuals_To_Match := Actuals_To_Match + 1;
7609 end if;
7611 Next (Actual);
7612 end loop;
7614 if Present (Actuals) then
7615 Actual := First (Actuals);
7616 end if;
7618 Formal := First_Formal (S);
7619 while Present (Formal) loop
7621 -- Match the formals in order. If the corresponding actual is
7622 -- positional, nothing to do. Else scan the list of named actuals
7623 -- to find the one with the right name.
7625 if Present (Actual)
7626 and then Nkind (Actual) /= N_Parameter_Association
7627 then
7628 Next (Actual);
7629 Actuals_To_Match := Actuals_To_Match - 1;
7630 Formals_To_Match := Formals_To_Match - 1;
7632 else
7633 -- For named parameters, search the list of actuals to find
7634 -- one that matches the next formal name.
7636 Actual := First_Named;
7637 Found := False;
7638 while Present (Actual) loop
7639 if Chars (Selector_Name (Actual)) = Chars (Formal) then
7640 Found := True;
7641 Chain (Actual);
7642 Actuals_To_Match := Actuals_To_Match - 1;
7643 Formals_To_Match := Formals_To_Match - 1;
7644 exit;
7645 end if;
7647 Next (Actual);
7648 end loop;
7650 if not Found then
7651 if Ekind (Formal) /= E_In_Parameter
7652 or else No (Default_Value (Formal))
7653 then
7654 if Reporting then
7655 if (Comes_From_Source (S)
7656 or else Sloc (S) = Standard_Location)
7657 and then Is_Overloadable (S)
7658 then
7659 if No (Actuals)
7660 and then
7661 (Nkind (Parent (N)) = N_Procedure_Call_Statement
7662 or else
7663 (Nkind (Parent (N)) = N_Function_Call
7664 or else
7665 Nkind (Parent (N)) = N_Parameter_Association))
7666 and then Ekind (S) /= E_Function
7667 then
7668 Set_Etype (N, Etype (S));
7669 else
7670 Error_Msg_Name_1 := Chars (S);
7671 Error_Msg_Sloc := Sloc (S);
7672 Error_Msg_NE
7673 ("missing argument for parameter & " &
7674 "in call to % declared #", N, Formal);
7675 end if;
7677 elsif Is_Overloadable (S) then
7678 Error_Msg_Name_1 := Chars (S);
7680 -- Point to type derivation that generated the
7681 -- operation.
7683 Error_Msg_Sloc := Sloc (Parent (S));
7685 Error_Msg_NE
7686 ("missing argument for parameter & " &
7687 "in call to % (inherited) #", N, Formal);
7689 else
7690 Error_Msg_NE
7691 ("missing argument for parameter &", N, Formal);
7692 end if;
7693 end if;
7695 Success := False;
7696 return;
7698 else
7699 Formals_To_Match := Formals_To_Match - 1;
7700 end if;
7701 end if;
7702 end if;
7704 Next_Formal (Formal);
7705 end loop;
7707 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
7708 Success := True;
7709 return;
7711 else
7712 if Reporting then
7714 -- Find some superfluous named actual that did not get
7715 -- attached to the list of associations.
7717 Actual := First (Actuals);
7718 while Present (Actual) loop
7719 if Nkind (Actual) = N_Parameter_Association
7720 and then Actual /= Last
7721 and then No (Next_Named_Actual (Actual))
7722 then
7723 Error_Msg_N ("unmatched actual & in call",
7724 Selector_Name (Actual));
7725 exit;
7726 end if;
7728 Next (Actual);
7729 end loop;
7730 end if;
7732 Success := False;
7733 return;
7734 end if;
7735 end Normalize_Actuals;
7737 --------------------------------
7738 -- Note_Possible_Modification --
7739 --------------------------------
7741 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
7742 Modification_Comes_From_Source : constant Boolean :=
7743 Comes_From_Source (Parent (N));
7745 Ent : Entity_Id;
7746 Exp : Node_Id;
7748 begin
7749 -- Loop to find referenced entity, if there is one
7751 Exp := N;
7752 loop
7753 <<Continue>>
7754 Ent := Empty;
7756 if Is_Entity_Name (Exp) then
7757 Ent := Entity (Exp);
7759 -- If the entity is missing, it is an undeclared identifier,
7760 -- and there is nothing to annotate.
7762 if No (Ent) then
7763 return;
7764 end if;
7766 elsif Nkind (Exp) = N_Explicit_Dereference then
7767 declare
7768 P : constant Node_Id := Prefix (Exp);
7770 begin
7771 if Nkind (P) = N_Selected_Component
7772 and then Present (
7773 Entry_Formal (Entity (Selector_Name (P))))
7774 then
7775 -- Case of a reference to an entry formal
7777 Ent := Entry_Formal (Entity (Selector_Name (P)));
7779 elsif Nkind (P) = N_Identifier
7780 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
7781 and then Present (Expression (Parent (Entity (P))))
7782 and then Nkind (Expression (Parent (Entity (P))))
7783 = N_Reference
7784 then
7785 -- Case of a reference to a value on which side effects have
7786 -- been removed.
7788 Exp := Prefix (Expression (Parent (Entity (P))));
7789 goto Continue;
7791 else
7792 return;
7794 end if;
7795 end;
7797 elsif Nkind (Exp) = N_Type_Conversion
7798 or else Nkind (Exp) = N_Unchecked_Type_Conversion
7799 then
7800 Exp := Expression (Exp);
7801 goto Continue;
7803 elsif Nkind (Exp) = N_Slice
7804 or else Nkind (Exp) = N_Indexed_Component
7805 or else Nkind (Exp) = N_Selected_Component
7806 then
7807 Exp := Prefix (Exp);
7808 goto Continue;
7810 else
7811 return;
7812 end if;
7814 -- Now look for entity being referenced
7816 if Present (Ent) then
7817 if Is_Object (Ent) then
7818 if Comes_From_Source (Exp)
7819 or else Modification_Comes_From_Source
7820 then
7821 if Has_Pragma_Unmodified (Ent) then
7822 Error_Msg_NE ("?pragma Unmodified given for &!", N, Ent);
7823 end if;
7825 Set_Never_Set_In_Source (Ent, False);
7826 end if;
7828 Set_Is_True_Constant (Ent, False);
7829 Set_Current_Value (Ent, Empty);
7830 Set_Is_Known_Null (Ent, False);
7832 if not Can_Never_Be_Null (Ent) then
7833 Set_Is_Known_Non_Null (Ent, False);
7834 end if;
7836 -- Follow renaming chain
7838 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
7839 and then Present (Renamed_Object (Ent))
7840 then
7841 Exp := Renamed_Object (Ent);
7842 goto Continue;
7843 end if;
7845 -- Generate a reference only if the assignment comes from
7846 -- source. This excludes, for example, calls to a dispatching
7847 -- assignment operation when the left-hand side is tagged.
7849 if Modification_Comes_From_Source then
7850 Generate_Reference (Ent, Exp, 'm');
7851 end if;
7853 Check_Nested_Access (Ent);
7854 end if;
7856 Kill_Checks (Ent);
7858 -- If we are sure this is a modification from source, and we know
7859 -- this modifies a constant, then give an appropriate warning.
7861 if Overlays_Constant (Ent)
7862 and then Modification_Comes_From_Source
7863 and then Sure
7864 then
7865 declare
7866 A : constant Node_Id := Address_Clause (Ent);
7867 begin
7868 if Present (A) then
7869 declare
7870 Exp : constant Node_Id := Expression (A);
7871 begin
7872 if Nkind (Exp) = N_Attribute_Reference
7873 and then Attribute_Name (Exp) = Name_Address
7874 and then Is_Entity_Name (Prefix (Exp))
7875 then
7876 Error_Msg_Sloc := Sloc (A);
7877 Error_Msg_NE
7878 ("constant& may be modified via address clause#?",
7879 N, Entity (Prefix (Exp)));
7880 end if;
7881 end;
7882 end if;
7883 end;
7884 end if;
7886 return;
7887 end if;
7888 end loop;
7889 end Note_Possible_Modification;
7891 -------------------------
7892 -- Object_Access_Level --
7893 -------------------------
7895 function Object_Access_Level (Obj : Node_Id) return Uint is
7896 E : Entity_Id;
7898 -- Returns the static accessibility level of the view denoted by Obj. Note
7899 -- that the value returned is the result of a call to Scope_Depth. Only
7900 -- scope depths associated with dynamic scopes can actually be returned.
7901 -- Since only relative levels matter for accessibility checking, the fact
7902 -- that the distance between successive levels of accessibility is not
7903 -- always one is immaterial (invariant: if level(E2) is deeper than
7904 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
7906 function Reference_To (Obj : Node_Id) return Node_Id;
7907 -- An explicit dereference is created when removing side-effects from
7908 -- expressions for constraint checking purposes. In this case a local
7909 -- access type is created for it. The correct access level is that of
7910 -- the original source node. We detect this case by noting that the
7911 -- prefix of the dereference is created by an object declaration whose
7912 -- initial expression is a reference.
7914 ------------------
7915 -- Reference_To --
7916 ------------------
7918 function Reference_To (Obj : Node_Id) return Node_Id is
7919 Pref : constant Node_Id := Prefix (Obj);
7920 begin
7921 if Is_Entity_Name (Pref)
7922 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
7923 and then Present (Expression (Parent (Entity (Pref))))
7924 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
7925 then
7926 return (Prefix (Expression (Parent (Entity (Pref)))));
7927 else
7928 return Empty;
7929 end if;
7930 end Reference_To;
7932 -- Start of processing for Object_Access_Level
7934 begin
7935 if Is_Entity_Name (Obj) then
7936 E := Entity (Obj);
7938 if Is_Prival (E) then
7939 E := Prival_Link (E);
7940 end if;
7942 -- If E is a type then it denotes a current instance. For this case
7943 -- we add one to the normal accessibility level of the type to ensure
7944 -- that current instances are treated as always being deeper than
7945 -- than the level of any visible named access type (see 3.10.2(21)).
7947 if Is_Type (E) then
7948 return Type_Access_Level (E) + 1;
7950 elsif Present (Renamed_Object (E)) then
7951 return Object_Access_Level (Renamed_Object (E));
7953 -- Similarly, if E is a component of the current instance of a
7954 -- protected type, any instance of it is assumed to be at a deeper
7955 -- level than the type. For a protected object (whose type is an
7956 -- anonymous protected type) its components are at the same level
7957 -- as the type itself.
7959 elsif not Is_Overloadable (E)
7960 and then Ekind (Scope (E)) = E_Protected_Type
7961 and then Comes_From_Source (Scope (E))
7962 then
7963 return Type_Access_Level (Scope (E)) + 1;
7965 else
7966 return Scope_Depth (Enclosing_Dynamic_Scope (E));
7967 end if;
7969 elsif Nkind (Obj) = N_Selected_Component then
7970 if Is_Access_Type (Etype (Prefix (Obj))) then
7971 return Type_Access_Level (Etype (Prefix (Obj)));
7972 else
7973 return Object_Access_Level (Prefix (Obj));
7974 end if;
7976 elsif Nkind (Obj) = N_Indexed_Component then
7977 if Is_Access_Type (Etype (Prefix (Obj))) then
7978 return Type_Access_Level (Etype (Prefix (Obj)));
7979 else
7980 return Object_Access_Level (Prefix (Obj));
7981 end if;
7983 elsif Nkind (Obj) = N_Explicit_Dereference then
7985 -- If the prefix is a selected access discriminant then we make a
7986 -- recursive call on the prefix, which will in turn check the level
7987 -- of the prefix object of the selected discriminant.
7989 if Nkind (Prefix (Obj)) = N_Selected_Component
7990 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
7991 and then
7992 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
7993 then
7994 return Object_Access_Level (Prefix (Obj));
7996 elsif not (Comes_From_Source (Obj)) then
7997 declare
7998 Ref : constant Node_Id := Reference_To (Obj);
7999 begin
8000 if Present (Ref) then
8001 return Object_Access_Level (Ref);
8002 else
8003 return Type_Access_Level (Etype (Prefix (Obj)));
8004 end if;
8005 end;
8007 else
8008 return Type_Access_Level (Etype (Prefix (Obj)));
8009 end if;
8011 elsif Nkind (Obj) = N_Type_Conversion
8012 or else Nkind (Obj) = N_Unchecked_Type_Conversion
8013 then
8014 return Object_Access_Level (Expression (Obj));
8016 -- Function results are objects, so we get either the access level of
8017 -- the function or, in the case of an indirect call, the level of of the
8018 -- access-to-subprogram type.
8020 elsif Nkind (Obj) = N_Function_Call then
8021 if Is_Entity_Name (Name (Obj)) then
8022 return Subprogram_Access_Level (Entity (Name (Obj)));
8023 else
8024 return Type_Access_Level (Etype (Prefix (Name (Obj))));
8025 end if;
8027 -- For convenience we handle qualified expressions, even though
8028 -- they aren't technically object names.
8030 elsif Nkind (Obj) = N_Qualified_Expression then
8031 return Object_Access_Level (Expression (Obj));
8033 -- Otherwise return the scope level of Standard.
8034 -- (If there are cases that fall through
8035 -- to this point they will be treated as
8036 -- having global accessibility for now. ???)
8038 else
8039 return Scope_Depth (Standard_Standard);
8040 end if;
8041 end Object_Access_Level;
8043 -----------------------
8044 -- Private_Component --
8045 -----------------------
8047 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
8048 Ancestor : constant Entity_Id := Base_Type (Type_Id);
8050 function Trace_Components
8051 (T : Entity_Id;
8052 Check : Boolean) return Entity_Id;
8053 -- Recursive function that does the work, and checks against circular
8054 -- definition for each subcomponent type.
8056 ----------------------
8057 -- Trace_Components --
8058 ----------------------
8060 function Trace_Components
8061 (T : Entity_Id;
8062 Check : Boolean) return Entity_Id
8064 Btype : constant Entity_Id := Base_Type (T);
8065 Component : Entity_Id;
8066 P : Entity_Id;
8067 Candidate : Entity_Id := Empty;
8069 begin
8070 if Check and then Btype = Ancestor then
8071 Error_Msg_N ("circular type definition", Type_Id);
8072 return Any_Type;
8073 end if;
8075 if Is_Private_Type (Btype)
8076 and then not Is_Generic_Type (Btype)
8077 then
8078 if Present (Full_View (Btype))
8079 and then Is_Record_Type (Full_View (Btype))
8080 and then not Is_Frozen (Btype)
8081 then
8082 -- To indicate that the ancestor depends on a private type, the
8083 -- current Btype is sufficient. However, to check for circular
8084 -- definition we must recurse on the full view.
8086 Candidate := Trace_Components (Full_View (Btype), True);
8088 if Candidate = Any_Type then
8089 return Any_Type;
8090 else
8091 return Btype;
8092 end if;
8094 else
8095 return Btype;
8096 end if;
8098 elsif Is_Array_Type (Btype) then
8099 return Trace_Components (Component_Type (Btype), True);
8101 elsif Is_Record_Type (Btype) then
8102 Component := First_Entity (Btype);
8103 while Present (Component) loop
8105 -- Skip anonymous types generated by constrained components
8107 if not Is_Type (Component) then
8108 P := Trace_Components (Etype (Component), True);
8110 if Present (P) then
8111 if P = Any_Type then
8112 return P;
8113 else
8114 Candidate := P;
8115 end if;
8116 end if;
8117 end if;
8119 Next_Entity (Component);
8120 end loop;
8122 return Candidate;
8124 else
8125 return Empty;
8126 end if;
8127 end Trace_Components;
8129 -- Start of processing for Private_Component
8131 begin
8132 return Trace_Components (Type_Id, False);
8133 end Private_Component;
8135 ---------------------------
8136 -- Primitive_Names_Match --
8137 ---------------------------
8139 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
8141 function Non_Internal_Name (E : Entity_Id) return Name_Id;
8142 -- Given an internal name, returns the corresponding non-internal name
8144 ------------------------
8145 -- Non_Internal_Name --
8146 ------------------------
8148 function Non_Internal_Name (E : Entity_Id) return Name_Id is
8149 begin
8150 Get_Name_String (Chars (E));
8151 Name_Len := Name_Len - 1;
8152 return Name_Find;
8153 end Non_Internal_Name;
8155 -- Start of processing for Primitive_Names_Match
8157 begin
8158 pragma Assert (Present (E1) and then Present (E2));
8160 return Chars (E1) = Chars (E2)
8161 or else
8162 (not Is_Internal_Name (Chars (E1))
8163 and then Is_Internal_Name (Chars (E2))
8164 and then Non_Internal_Name (E2) = Chars (E1))
8165 or else
8166 (not Is_Internal_Name (Chars (E2))
8167 and then Is_Internal_Name (Chars (E1))
8168 and then Non_Internal_Name (E1) = Chars (E2))
8169 or else
8170 (Is_Predefined_Dispatching_Operation (E1)
8171 and then Is_Predefined_Dispatching_Operation (E2)
8172 and then Same_TSS (E1, E2))
8173 or else
8174 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
8175 end Primitive_Names_Match;
8177 -----------------------
8178 -- Process_End_Label --
8179 -----------------------
8181 procedure Process_End_Label
8182 (N : Node_Id;
8183 Typ : Character;
8184 Ent : Entity_Id)
8186 Loc : Source_Ptr;
8187 Nam : Node_Id;
8188 Scop : Entity_Id;
8190 Label_Ref : Boolean;
8191 -- Set True if reference to end label itself is required
8193 Endl : Node_Id;
8194 -- Gets set to the operator symbol or identifier that references the
8195 -- entity Ent. For the child unit case, this is the identifier from the
8196 -- designator. For other cases, this is simply Endl.
8198 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
8199 -- N is an identifier node that appears as a parent unit reference in
8200 -- the case where Ent is a child unit. This procedure generates an
8201 -- appropriate cross-reference entry. E is the corresponding entity.
8203 -------------------------
8204 -- Generate_Parent_Ref --
8205 -------------------------
8207 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
8208 begin
8209 -- If names do not match, something weird, skip reference
8211 if Chars (E) = Chars (N) then
8213 -- Generate the reference. We do NOT consider this as a reference
8214 -- for unreferenced symbol purposes.
8216 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
8218 if Style_Check then
8219 Style.Check_Identifier (N, E);
8220 end if;
8221 end if;
8222 end Generate_Parent_Ref;
8224 -- Start of processing for Process_End_Label
8226 begin
8227 -- If no node, ignore. This happens in some error situations, and
8228 -- also for some internally generated structures where no end label
8229 -- references are required in any case.
8231 if No (N) then
8232 return;
8233 end if;
8235 -- Nothing to do if no End_Label, happens for internally generated
8236 -- constructs where we don't want an end label reference anyway. Also
8237 -- nothing to do if Endl is a string literal, which means there was
8238 -- some prior error (bad operator symbol)
8240 Endl := End_Label (N);
8242 if No (Endl) or else Nkind (Endl) = N_String_Literal then
8243 return;
8244 end if;
8246 -- Reference node is not in extended main source unit
8248 if not In_Extended_Main_Source_Unit (N) then
8250 -- Generally we do not collect references except for the extended
8251 -- main source unit. The one exception is the 'e' entry for a
8252 -- package spec, where it is useful for a client to have the
8253 -- ending information to define scopes.
8255 if Typ /= 'e' then
8256 return;
8258 else
8259 Label_Ref := False;
8261 -- For this case, we can ignore any parent references, but we
8262 -- need the package name itself for the 'e' entry.
8264 if Nkind (Endl) = N_Designator then
8265 Endl := Identifier (Endl);
8266 end if;
8267 end if;
8269 -- Reference is in extended main source unit
8271 else
8272 Label_Ref := True;
8274 -- For designator, generate references for the parent entries
8276 if Nkind (Endl) = N_Designator then
8278 -- Generate references for the prefix if the END line comes from
8279 -- source (otherwise we do not need these references) We climb the
8280 -- scope stack to find the expected entities.
8282 if Comes_From_Source (Endl) then
8283 Nam := Name (Endl);
8284 Scop := Current_Scope;
8285 while Nkind (Nam) = N_Selected_Component loop
8286 Scop := Scope (Scop);
8287 exit when No (Scop);
8288 Generate_Parent_Ref (Selector_Name (Nam), Scop);
8289 Nam := Prefix (Nam);
8290 end loop;
8292 if Present (Scop) then
8293 Generate_Parent_Ref (Nam, Scope (Scop));
8294 end if;
8295 end if;
8297 Endl := Identifier (Endl);
8298 end if;
8299 end if;
8301 -- If the end label is not for the given entity, then either we have
8302 -- some previous error, or this is a generic instantiation for which
8303 -- we do not need to make a cross-reference in this case anyway. In
8304 -- either case we simply ignore the call.
8306 if Chars (Ent) /= Chars (Endl) then
8307 return;
8308 end if;
8310 -- If label was really there, then generate a normal reference and then
8311 -- adjust the location in the end label to point past the name (which
8312 -- should almost always be the semicolon).
8314 Loc := Sloc (Endl);
8316 if Comes_From_Source (Endl) then
8318 -- If a label reference is required, then do the style check and
8319 -- generate an l-type cross-reference entry for the label
8321 if Label_Ref then
8322 if Style_Check then
8323 Style.Check_Identifier (Endl, Ent);
8324 end if;
8326 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
8327 end if;
8329 -- Set the location to point past the label (normally this will
8330 -- mean the semicolon immediately following the label). This is
8331 -- done for the sake of the 'e' or 't' entry generated below.
8333 Get_Decoded_Name_String (Chars (Endl));
8334 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
8335 end if;
8337 -- Now generate the e/t reference
8339 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
8341 -- Restore Sloc, in case modified above, since we have an identifier
8342 -- and the normal Sloc should be left set in the tree.
8344 Set_Sloc (Endl, Loc);
8345 end Process_End_Label;
8347 ------------------
8348 -- Real_Convert --
8349 ------------------
8351 -- We do the conversion to get the value of the real string by using
8352 -- the scanner, see Sinput for details on use of the internal source
8353 -- buffer for scanning internal strings.
8355 function Real_Convert (S : String) return Node_Id is
8356 Save_Src : constant Source_Buffer_Ptr := Source;
8357 Negative : Boolean;
8359 begin
8360 Source := Internal_Source_Ptr;
8361 Scan_Ptr := 1;
8363 for J in S'Range loop
8364 Source (Source_Ptr (J)) := S (J);
8365 end loop;
8367 Source (S'Length + 1) := EOF;
8369 if Source (Scan_Ptr) = '-' then
8370 Negative := True;
8371 Scan_Ptr := Scan_Ptr + 1;
8372 else
8373 Negative := False;
8374 end if;
8376 Scan;
8378 if Negative then
8379 Set_Realval (Token_Node, UR_Negate (Realval (Token_Node)));
8380 end if;
8382 Source := Save_Src;
8383 return Token_Node;
8384 end Real_Convert;
8386 --------------------
8387 -- Remove_Homonym --
8388 --------------------
8390 procedure Remove_Homonym (E : Entity_Id) is
8391 Prev : Entity_Id := Empty;
8392 H : Entity_Id;
8394 begin
8395 if E = Current_Entity (E) then
8396 if Present (Homonym (E)) then
8397 Set_Current_Entity (Homonym (E));
8398 else
8399 Set_Name_Entity_Id (Chars (E), Empty);
8400 end if;
8401 else
8402 H := Current_Entity (E);
8403 while Present (H) and then H /= E loop
8404 Prev := H;
8405 H := Homonym (H);
8406 end loop;
8408 Set_Homonym (Prev, Homonym (E));
8409 end if;
8410 end Remove_Homonym;
8412 ---------------------
8413 -- Rep_To_Pos_Flag --
8414 ---------------------
8416 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
8417 begin
8418 return New_Occurrence_Of
8419 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
8420 end Rep_To_Pos_Flag;
8422 --------------------
8423 -- Require_Entity --
8424 --------------------
8426 procedure Require_Entity (N : Node_Id) is
8427 begin
8428 if Is_Entity_Name (N) and then No (Entity (N)) then
8429 if Total_Errors_Detected /= 0 then
8430 Set_Entity (N, Any_Id);
8431 else
8432 raise Program_Error;
8433 end if;
8434 end if;
8435 end Require_Entity;
8437 ------------------------------
8438 -- Requires_Transient_Scope --
8439 ------------------------------
8441 -- A transient scope is required when variable-sized temporaries are
8442 -- allocated in the primary or secondary stack, or when finalization
8443 -- actions must be generated before the next instruction.
8445 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
8446 Typ : constant Entity_Id := Underlying_Type (Id);
8448 -- Start of processing for Requires_Transient_Scope
8450 begin
8451 -- This is a private type which is not completed yet. This can only
8452 -- happen in a default expression (of a formal parameter or of a
8453 -- record component). Do not expand transient scope in this case
8455 if No (Typ) then
8456 return False;
8458 -- Do not expand transient scope for non-existent procedure return
8460 elsif Typ = Standard_Void_Type then
8461 return False;
8463 -- Elementary types do not require a transient scope
8465 elsif Is_Elementary_Type (Typ) then
8466 return False;
8468 -- Generally, indefinite subtypes require a transient scope, since the
8469 -- back end cannot generate temporaries, since this is not a valid type
8470 -- for declaring an object. It might be possible to relax this in the
8471 -- future, e.g. by declaring the maximum possible space for the type.
8473 elsif Is_Indefinite_Subtype (Typ) then
8474 return True;
8476 -- Functions returning tagged types may dispatch on result so their
8477 -- returned value is allocated on the secondary stack. Controlled
8478 -- type temporaries need finalization.
8480 elsif Is_Tagged_Type (Typ)
8481 or else Has_Controlled_Component (Typ)
8482 then
8483 return not Is_Value_Type (Typ);
8485 -- Record type
8487 elsif Is_Record_Type (Typ) then
8488 declare
8489 Comp : Entity_Id;
8490 begin
8491 Comp := First_Entity (Typ);
8492 while Present (Comp) loop
8493 if Ekind (Comp) = E_Component
8494 and then Requires_Transient_Scope (Etype (Comp))
8495 then
8496 return True;
8497 else
8498 Next_Entity (Comp);
8499 end if;
8500 end loop;
8501 end;
8503 return False;
8505 -- String literal types never require transient scope
8507 elsif Ekind (Typ) = E_String_Literal_Subtype then
8508 return False;
8510 -- Array type. Note that we already know that this is a constrained
8511 -- array, since unconstrained arrays will fail the indefinite test.
8513 elsif Is_Array_Type (Typ) then
8515 -- If component type requires a transient scope, the array does too
8517 if Requires_Transient_Scope (Component_Type (Typ)) then
8518 return True;
8520 -- Otherwise, we only need a transient scope if the size is not
8521 -- known at compile time.
8523 else
8524 return not Size_Known_At_Compile_Time (Typ);
8525 end if;
8527 -- All other cases do not require a transient scope
8529 else
8530 return False;
8531 end if;
8532 end Requires_Transient_Scope;
8534 --------------------------
8535 -- Reset_Analyzed_Flags --
8536 --------------------------
8538 procedure Reset_Analyzed_Flags (N : Node_Id) is
8540 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
8541 -- Function used to reset Analyzed flags in tree. Note that we do
8542 -- not reset Analyzed flags in entities, since there is no need to
8543 -- reanalyze entities, and indeed, it is wrong to do so, since it
8544 -- can result in generating auxiliary stuff more than once.
8546 --------------------
8547 -- Clear_Analyzed --
8548 --------------------
8550 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
8551 begin
8552 if not Has_Extension (N) then
8553 Set_Analyzed (N, False);
8554 end if;
8556 return OK;
8557 end Clear_Analyzed;
8559 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
8561 -- Start of processing for Reset_Analyzed_Flags
8563 begin
8564 Reset_Analyzed (N);
8565 end Reset_Analyzed_Flags;
8567 ---------------------------
8568 -- Safe_To_Capture_Value --
8569 ---------------------------
8571 function Safe_To_Capture_Value
8572 (N : Node_Id;
8573 Ent : Entity_Id;
8574 Cond : Boolean := False) return Boolean
8576 begin
8577 -- The only entities for which we track constant values are variables
8578 -- which are not renamings, constants, out parameters, and in out
8579 -- parameters, so check if we have this case.
8581 -- Note: it may seem odd to track constant values for constants, but in
8582 -- fact this routine is used for other purposes than simply capturing
8583 -- the value. In particular, the setting of Known[_Non]_Null.
8585 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
8586 or else
8587 Ekind (Ent) = E_Constant
8588 or else
8589 Ekind (Ent) = E_Out_Parameter
8590 or else
8591 Ekind (Ent) = E_In_Out_Parameter
8592 then
8593 null;
8595 -- For conditionals, we also allow loop parameters and all formals,
8596 -- including in parameters.
8598 elsif Cond
8599 and then
8600 (Ekind (Ent) = E_Loop_Parameter
8601 or else
8602 Ekind (Ent) = E_In_Parameter)
8603 then
8604 null;
8606 -- For all other cases, not just unsafe, but impossible to capture
8607 -- Current_Value, since the above are the only entities which have
8608 -- Current_Value fields.
8610 else
8611 return False;
8612 end if;
8614 -- Skip if volatile or aliased, since funny things might be going on in
8615 -- these cases which we cannot necessarily track. Also skip any variable
8616 -- for which an address clause is given, or whose address is taken. Also
8617 -- never capture value of library level variables (an attempt to do so
8618 -- can occur in the case of package elaboration code).
8620 if Treat_As_Volatile (Ent)
8621 or else Is_Aliased (Ent)
8622 or else Present (Address_Clause (Ent))
8623 or else Address_Taken (Ent)
8624 or else (Is_Library_Level_Entity (Ent)
8625 and then Ekind (Ent) = E_Variable)
8626 then
8627 return False;
8628 end if;
8630 -- OK, all above conditions are met. We also require that the scope of
8631 -- the reference be the same as the scope of the entity, not counting
8632 -- packages and blocks and loops.
8634 declare
8635 E_Scope : constant Entity_Id := Scope (Ent);
8636 R_Scope : Entity_Id;
8638 begin
8639 R_Scope := Current_Scope;
8640 while R_Scope /= Standard_Standard loop
8641 exit when R_Scope = E_Scope;
8643 if Ekind (R_Scope) /= E_Package
8644 and then
8645 Ekind (R_Scope) /= E_Block
8646 and then
8647 Ekind (R_Scope) /= E_Loop
8648 then
8649 return False;
8650 else
8651 R_Scope := Scope (R_Scope);
8652 end if;
8653 end loop;
8654 end;
8656 -- We also require that the reference does not appear in a context
8657 -- where it is not sure to be executed (i.e. a conditional context
8658 -- or an exception handler). We skip this if Cond is True, since the
8659 -- capturing of values from conditional tests handles this ok.
8661 if Cond then
8662 return True;
8663 end if;
8665 declare
8666 Desc : Node_Id;
8667 P : Node_Id;
8669 begin
8670 Desc := N;
8672 P := Parent (N);
8673 while Present (P) loop
8674 if Nkind (P) = N_If_Statement
8675 or else Nkind (P) = N_Case_Statement
8676 or else (Nkind (P) = N_And_Then and then Desc = Right_Opnd (P))
8677 or else (Nkind (P) = N_Or_Else and then Desc = Right_Opnd (P))
8678 or else Nkind (P) = N_Exception_Handler
8679 or else Nkind (P) = N_Selective_Accept
8680 or else Nkind (P) = N_Conditional_Entry_Call
8681 or else Nkind (P) = N_Timed_Entry_Call
8682 or else Nkind (P) = N_Asynchronous_Select
8683 then
8684 return False;
8685 else
8686 Desc := P;
8687 P := Parent (P);
8688 end if;
8689 end loop;
8690 end;
8692 -- OK, looks safe to set value
8694 return True;
8695 end Safe_To_Capture_Value;
8697 ---------------
8698 -- Same_Name --
8699 ---------------
8701 function Same_Name (N1, N2 : Node_Id) return Boolean is
8702 K1 : constant Node_Kind := Nkind (N1);
8703 K2 : constant Node_Kind := Nkind (N2);
8705 begin
8706 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
8707 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
8708 then
8709 return Chars (N1) = Chars (N2);
8711 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
8712 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
8713 then
8714 return Same_Name (Selector_Name (N1), Selector_Name (N2))
8715 and then Same_Name (Prefix (N1), Prefix (N2));
8717 else
8718 return False;
8719 end if;
8720 end Same_Name;
8722 -----------------
8723 -- Same_Object --
8724 -----------------
8726 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
8727 N1 : constant Node_Id := Original_Node (Node1);
8728 N2 : constant Node_Id := Original_Node (Node2);
8729 -- We do the tests on original nodes, since we are most interested
8730 -- in the original source, not any expansion that got in the way.
8732 K1 : constant Node_Kind := Nkind (N1);
8733 K2 : constant Node_Kind := Nkind (N2);
8735 begin
8736 -- First case, both are entities with same entity
8738 if K1 in N_Has_Entity
8739 and then K2 in N_Has_Entity
8740 and then Present (Entity (N1))
8741 and then Present (Entity (N2))
8742 and then (Ekind (Entity (N1)) = E_Variable
8743 or else
8744 Ekind (Entity (N1)) = E_Constant)
8745 and then Entity (N1) = Entity (N2)
8746 then
8747 return True;
8749 -- Second case, selected component with same selector, same record
8751 elsif K1 = N_Selected_Component
8752 and then K2 = N_Selected_Component
8753 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
8754 then
8755 return Same_Object (Prefix (N1), Prefix (N2));
8757 -- Third case, indexed component with same subscripts, same array
8759 elsif K1 = N_Indexed_Component
8760 and then K2 = N_Indexed_Component
8761 and then Same_Object (Prefix (N1), Prefix (N2))
8762 then
8763 declare
8764 E1, E2 : Node_Id;
8765 begin
8766 E1 := First (Expressions (N1));
8767 E2 := First (Expressions (N2));
8768 while Present (E1) loop
8769 if not Same_Value (E1, E2) then
8770 return False;
8771 else
8772 Next (E1);
8773 Next (E2);
8774 end if;
8775 end loop;
8777 return True;
8778 end;
8780 -- Fourth case, slice of same array with same bounds
8782 elsif K1 = N_Slice
8783 and then K2 = N_Slice
8784 and then Nkind (Discrete_Range (N1)) = N_Range
8785 and then Nkind (Discrete_Range (N2)) = N_Range
8786 and then Same_Value (Low_Bound (Discrete_Range (N1)),
8787 Low_Bound (Discrete_Range (N2)))
8788 and then Same_Value (High_Bound (Discrete_Range (N1)),
8789 High_Bound (Discrete_Range (N2)))
8790 then
8791 return Same_Name (Prefix (N1), Prefix (N2));
8793 -- All other cases, not clearly the same object
8795 else
8796 return False;
8797 end if;
8798 end Same_Object;
8800 ---------------
8801 -- Same_Type --
8802 ---------------
8804 function Same_Type (T1, T2 : Entity_Id) return Boolean is
8805 begin
8806 if T1 = T2 then
8807 return True;
8809 elsif not Is_Constrained (T1)
8810 and then not Is_Constrained (T2)
8811 and then Base_Type (T1) = Base_Type (T2)
8812 then
8813 return True;
8815 -- For now don't bother with case of identical constraints, to be
8816 -- fiddled with later on perhaps (this is only used for optimization
8817 -- purposes, so it is not critical to do a best possible job)
8819 else
8820 return False;
8821 end if;
8822 end Same_Type;
8824 ----------------
8825 -- Same_Value --
8826 ----------------
8828 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
8829 begin
8830 if Compile_Time_Known_Value (Node1)
8831 and then Compile_Time_Known_Value (Node2)
8832 and then Expr_Value (Node1) = Expr_Value (Node2)
8833 then
8834 return True;
8835 elsif Same_Object (Node1, Node2) then
8836 return True;
8837 else
8838 return False;
8839 end if;
8840 end Same_Value;
8842 ------------------------
8843 -- Scope_Is_Transient --
8844 ------------------------
8846 function Scope_Is_Transient return Boolean is
8847 begin
8848 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
8849 end Scope_Is_Transient;
8851 ------------------
8852 -- Scope_Within --
8853 ------------------
8855 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
8856 Scop : Entity_Id;
8858 begin
8859 Scop := Scope1;
8860 while Scop /= Standard_Standard loop
8861 Scop := Scope (Scop);
8863 if Scop = Scope2 then
8864 return True;
8865 end if;
8866 end loop;
8868 return False;
8869 end Scope_Within;
8871 --------------------------
8872 -- Scope_Within_Or_Same --
8873 --------------------------
8875 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
8876 Scop : Entity_Id;
8878 begin
8879 Scop := Scope1;
8880 while Scop /= Standard_Standard loop
8881 if Scop = Scope2 then
8882 return True;
8883 else
8884 Scop := Scope (Scop);
8885 end if;
8886 end loop;
8888 return False;
8889 end Scope_Within_Or_Same;
8891 --------------------
8892 -- Set_Convention --
8893 --------------------
8895 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
8896 begin
8897 Basic_Set_Convention (E, Val);
8899 if Is_Type (E)
8900 and then Is_Access_Subprogram_Type (Base_Type (E))
8901 and then Has_Foreign_Convention (E)
8902 then
8903 Set_Can_Use_Internal_Rep (E, False);
8904 end if;
8905 end Set_Convention;
8907 ------------------------
8908 -- Set_Current_Entity --
8909 ------------------------
8911 -- The given entity is to be set as the currently visible definition
8912 -- of its associated name (i.e. the Node_Id associated with its name).
8913 -- All we have to do is to get the name from the identifier, and
8914 -- then set the associated Node_Id to point to the given entity.
8916 procedure Set_Current_Entity (E : Entity_Id) is
8917 begin
8918 Set_Name_Entity_Id (Chars (E), E);
8919 end Set_Current_Entity;
8921 ---------------------------
8922 -- Set_Debug_Info_Needed --
8923 ---------------------------
8925 procedure Set_Debug_Info_Needed (T : Entity_Id) is
8927 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
8928 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
8929 -- Used to set debug info in a related node if not set already
8931 --------------------------------------
8932 -- Set_Debug_Info_Needed_If_Not_Set --
8933 --------------------------------------
8935 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
8936 begin
8937 if Present (E)
8938 and then not Needs_Debug_Info (E)
8939 then
8940 Set_Debug_Info_Needed (E);
8941 end if;
8942 end Set_Debug_Info_Needed_If_Not_Set;
8944 -- Start of processing for Set_Debug_Info_Needed
8946 begin
8947 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
8948 -- indicates that Debug_Info_Needed is never required for the entity.
8950 if No (T)
8951 or else Debug_Info_Off (T)
8952 then
8953 return;
8954 end if;
8956 -- Set flag in entity itself. Note that we will go through the following
8957 -- circuitry even if the flag is already set on T. That's intentional,
8958 -- it makes sure that the flag will be set in subsidiary entities.
8960 Set_Needs_Debug_Info (T);
8962 -- Set flag on subsidiary entities if not set already
8964 if Is_Object (T) then
8965 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
8967 elsif Is_Type (T) then
8968 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
8970 if Is_Record_Type (T) then
8971 declare
8972 Ent : Entity_Id := First_Entity (T);
8973 begin
8974 while Present (Ent) loop
8975 Set_Debug_Info_Needed_If_Not_Set (Ent);
8976 Next_Entity (Ent);
8977 end loop;
8978 end;
8980 elsif Is_Array_Type (T) then
8981 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
8983 declare
8984 Indx : Node_Id := First_Index (T);
8985 begin
8986 while Present (Indx) loop
8987 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
8988 Indx := Next_Index (Indx);
8989 end loop;
8990 end;
8992 if Is_Packed (T) then
8993 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Type (T));
8994 end if;
8996 elsif Is_Access_Type (T) then
8997 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
8999 elsif Is_Private_Type (T) then
9000 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
9002 elsif Is_Protected_Type (T) then
9003 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
9004 end if;
9005 end if;
9006 end Set_Debug_Info_Needed;
9008 ---------------------------------
9009 -- Set_Entity_With_Style_Check --
9010 ---------------------------------
9012 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
9013 Val_Actual : Entity_Id;
9014 Nod : Node_Id;
9016 begin
9017 Set_Entity (N, Val);
9019 if Style_Check
9020 and then not Suppress_Style_Checks (Val)
9021 and then not In_Instance
9022 then
9023 if Nkind (N) = N_Identifier then
9024 Nod := N;
9025 elsif Nkind (N) = N_Expanded_Name then
9026 Nod := Selector_Name (N);
9027 else
9028 return;
9029 end if;
9031 -- A special situation arises for derived operations, where we want
9032 -- to do the check against the parent (since the Sloc of the derived
9033 -- operation points to the derived type declaration itself).
9035 Val_Actual := Val;
9036 while not Comes_From_Source (Val_Actual)
9037 and then Nkind (Val_Actual) in N_Entity
9038 and then (Ekind (Val_Actual) = E_Enumeration_Literal
9039 or else Is_Subprogram (Val_Actual)
9040 or else Is_Generic_Subprogram (Val_Actual))
9041 and then Present (Alias (Val_Actual))
9042 loop
9043 Val_Actual := Alias (Val_Actual);
9044 end loop;
9046 -- Renaming declarations for generic actuals do not come from source,
9047 -- and have a different name from that of the entity they rename, so
9048 -- there is no style check to perform here.
9050 if Chars (Nod) = Chars (Val_Actual) then
9051 Style.Check_Identifier (Nod, Val_Actual);
9052 end if;
9053 end if;
9055 Set_Entity (N, Val);
9056 end Set_Entity_With_Style_Check;
9058 ------------------------
9059 -- Set_Name_Entity_Id --
9060 ------------------------
9062 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
9063 begin
9064 Set_Name_Table_Info (Id, Int (Val));
9065 end Set_Name_Entity_Id;
9067 ---------------------
9068 -- Set_Next_Actual --
9069 ---------------------
9071 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
9072 begin
9073 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
9074 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
9075 end if;
9076 end Set_Next_Actual;
9078 ----------------------------------
9079 -- Set_Optimize_Alignment_Flags --
9080 ----------------------------------
9082 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
9083 begin
9084 if Optimize_Alignment = 'S' then
9085 Set_Optimize_Alignment_Space (E);
9086 elsif Optimize_Alignment = 'T' then
9087 Set_Optimize_Alignment_Time (E);
9088 end if;
9089 end Set_Optimize_Alignment_Flags;
9091 -----------------------
9092 -- Set_Public_Status --
9093 -----------------------
9095 procedure Set_Public_Status (Id : Entity_Id) is
9096 S : constant Entity_Id := Current_Scope;
9098 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
9099 -- Determines if E is defined within handled statement sequence or
9100 -- an if statement, returns True if so, False otherwise.
9102 ----------------------
9103 -- Within_HSS_Or_If --
9104 ----------------------
9106 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
9107 N : Node_Id;
9108 begin
9109 N := Declaration_Node (E);
9110 loop
9111 N := Parent (N);
9113 if No (N) then
9114 return False;
9116 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
9117 N_If_Statement)
9118 then
9119 return True;
9120 end if;
9121 end loop;
9122 end Within_HSS_Or_If;
9124 -- Start of processing for Set_Public_Status
9126 begin
9127 -- Everything in the scope of Standard is public
9129 if S = Standard_Standard then
9130 Set_Is_Public (Id);
9132 -- Entity is definitely not public if enclosing scope is not public
9134 elsif not Is_Public (S) then
9135 return;
9137 -- An object or function declaration that occurs in a handled sequence
9138 -- of statements or within an if statement is the declaration for a
9139 -- temporary object or local subprogram generated by the expander. It
9140 -- never needs to be made public and furthermore, making it public can
9141 -- cause back end problems.
9143 elsif Nkind_In (Parent (Id), N_Object_Declaration,
9144 N_Function_Specification)
9145 and then Within_HSS_Or_If (Id)
9146 then
9147 return;
9149 -- Entities in public packages or records are public
9151 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
9152 Set_Is_Public (Id);
9154 -- The bounds of an entry family declaration can generate object
9155 -- declarations that are visible to the back-end, e.g. in the
9156 -- the declaration of a composite type that contains tasks.
9158 elsif Is_Concurrent_Type (S)
9159 and then not Has_Completion (S)
9160 and then Nkind (Parent (Id)) = N_Object_Declaration
9161 then
9162 Set_Is_Public (Id);
9163 end if;
9164 end Set_Public_Status;
9166 -----------------------------
9167 -- Set_Referenced_Modified --
9168 -----------------------------
9170 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
9171 Pref : Node_Id;
9173 begin
9174 -- Deal with indexed or selected component where prefix is modified
9176 if Nkind (N) = N_Indexed_Component
9177 or else
9178 Nkind (N) = N_Selected_Component
9179 then
9180 Pref := Prefix (N);
9182 -- If prefix is access type, then it is the designated object that is
9183 -- being modified, which means we have no entity to set the flag on.
9185 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
9186 return;
9188 -- Otherwise chase the prefix
9190 else
9191 Set_Referenced_Modified (Pref, Out_Param);
9192 end if;
9194 -- Otherwise see if we have an entity name (only other case to process)
9196 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
9197 Set_Referenced_As_LHS (Entity (N), not Out_Param);
9198 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
9199 end if;
9200 end Set_Referenced_Modified;
9202 ----------------------------
9203 -- Set_Scope_Is_Transient --
9204 ----------------------------
9206 procedure Set_Scope_Is_Transient (V : Boolean := True) is
9207 begin
9208 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
9209 end Set_Scope_Is_Transient;
9211 -------------------
9212 -- Set_Size_Info --
9213 -------------------
9215 procedure Set_Size_Info (T1, T2 : Entity_Id) is
9216 begin
9217 -- We copy Esize, but not RM_Size, since in general RM_Size is
9218 -- subtype specific and does not get inherited by all subtypes.
9220 Set_Esize (T1, Esize (T2));
9221 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
9223 if Is_Discrete_Or_Fixed_Point_Type (T1)
9224 and then
9225 Is_Discrete_Or_Fixed_Point_Type (T2)
9226 then
9227 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
9228 end if;
9230 Set_Alignment (T1, Alignment (T2));
9231 end Set_Size_Info;
9233 --------------------
9234 -- Static_Integer --
9235 --------------------
9237 function Static_Integer (N : Node_Id) return Uint is
9238 begin
9239 Analyze_And_Resolve (N, Any_Integer);
9241 if N = Error
9242 or else Error_Posted (N)
9243 or else Etype (N) = Any_Type
9244 then
9245 return No_Uint;
9246 end if;
9248 if Is_Static_Expression (N) then
9249 if not Raises_Constraint_Error (N) then
9250 return Expr_Value (N);
9251 else
9252 return No_Uint;
9253 end if;
9255 elsif Etype (N) = Any_Type then
9256 return No_Uint;
9258 else
9259 Flag_Non_Static_Expr
9260 ("static integer expression required here", N);
9261 return No_Uint;
9262 end if;
9263 end Static_Integer;
9265 --------------------------
9266 -- Statically_Different --
9267 --------------------------
9269 function Statically_Different (E1, E2 : Node_Id) return Boolean is
9270 R1 : constant Node_Id := Get_Referenced_Object (E1);
9271 R2 : constant Node_Id := Get_Referenced_Object (E2);
9272 begin
9273 return Is_Entity_Name (R1)
9274 and then Is_Entity_Name (R2)
9275 and then Entity (R1) /= Entity (R2)
9276 and then not Is_Formal (Entity (R1))
9277 and then not Is_Formal (Entity (R2));
9278 end Statically_Different;
9280 -----------------------------
9281 -- Subprogram_Access_Level --
9282 -----------------------------
9284 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
9285 begin
9286 if Present (Alias (Subp)) then
9287 return Subprogram_Access_Level (Alias (Subp));
9288 else
9289 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
9290 end if;
9291 end Subprogram_Access_Level;
9293 -----------------
9294 -- Trace_Scope --
9295 -----------------
9297 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
9298 begin
9299 if Debug_Flag_W then
9300 for J in 0 .. Scope_Stack.Last loop
9301 Write_Str (" ");
9302 end loop;
9304 Write_Str (Msg);
9305 Write_Name (Chars (E));
9306 Write_Str (" from ");
9307 Write_Location (Sloc (N));
9308 Write_Eol;
9309 end if;
9310 end Trace_Scope;
9312 -----------------------
9313 -- Transfer_Entities --
9314 -----------------------
9316 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
9317 Ent : Entity_Id := First_Entity (From);
9319 begin
9320 if No (Ent) then
9321 return;
9322 end if;
9324 if (Last_Entity (To)) = Empty then
9325 Set_First_Entity (To, Ent);
9326 else
9327 Set_Next_Entity (Last_Entity (To), Ent);
9328 end if;
9330 Set_Last_Entity (To, Last_Entity (From));
9332 while Present (Ent) loop
9333 Set_Scope (Ent, To);
9335 if not Is_Public (Ent) then
9336 Set_Public_Status (Ent);
9338 if Is_Public (Ent)
9339 and then Ekind (Ent) = E_Record_Subtype
9341 then
9342 -- The components of the propagated Itype must be public
9343 -- as well.
9345 declare
9346 Comp : Entity_Id;
9347 begin
9348 Comp := First_Entity (Ent);
9349 while Present (Comp) loop
9350 Set_Is_Public (Comp);
9351 Next_Entity (Comp);
9352 end loop;
9353 end;
9354 end if;
9355 end if;
9357 Next_Entity (Ent);
9358 end loop;
9360 Set_First_Entity (From, Empty);
9361 Set_Last_Entity (From, Empty);
9362 end Transfer_Entities;
9364 -----------------------
9365 -- Type_Access_Level --
9366 -----------------------
9368 function Type_Access_Level (Typ : Entity_Id) return Uint is
9369 Btyp : Entity_Id;
9371 begin
9372 Btyp := Base_Type (Typ);
9374 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
9375 -- simply use the level where the type is declared. This is true for
9376 -- stand-alone object declarations, and for anonymous access types
9377 -- associated with components the level is the same as that of the
9378 -- enclosing composite type. However, special treatment is needed for
9379 -- the cases of access parameters, return objects of an anonymous access
9380 -- type, and, in Ada 95, access discriminants of limited types.
9382 if Ekind (Btyp) in Access_Kind then
9383 if Ekind (Btyp) = E_Anonymous_Access_Type then
9385 -- If the type is a nonlocal anonymous access type (such as for
9386 -- an access parameter) we treat it as being declared at the
9387 -- library level to ensure that names such as X.all'access don't
9388 -- fail static accessibility checks.
9390 if not Is_Local_Anonymous_Access (Typ) then
9391 return Scope_Depth (Standard_Standard);
9393 -- If this is a return object, the accessibility level is that of
9394 -- the result subtype of the enclosing function. The test here is
9395 -- little complicated, because we have to account for extended
9396 -- return statements that have been rewritten as blocks, in which
9397 -- case we have to find and the Is_Return_Object attribute of the
9398 -- itype's associated object. It would be nice to find a way to
9399 -- simplify this test, but it doesn't seem worthwhile to add a new
9400 -- flag just for purposes of this test. ???
9402 elsif Ekind (Scope (Btyp)) = E_Return_Statement
9403 or else
9404 (Is_Itype (Btyp)
9405 and then Nkind (Associated_Node_For_Itype (Btyp)) =
9406 N_Object_Declaration
9407 and then Is_Return_Object
9408 (Defining_Identifier
9409 (Associated_Node_For_Itype (Btyp))))
9410 then
9411 declare
9412 Scop : Entity_Id;
9414 begin
9415 Scop := Scope (Scope (Btyp));
9416 while Present (Scop) loop
9417 exit when Ekind (Scop) = E_Function;
9418 Scop := Scope (Scop);
9419 end loop;
9421 -- Treat the return object's type as having the level of the
9422 -- function's result subtype (as per RM05-6.5(5.3/2)).
9424 return Type_Access_Level (Etype (Scop));
9425 end;
9426 end if;
9427 end if;
9429 Btyp := Root_Type (Btyp);
9431 -- The accessibility level of anonymous access types associated with
9432 -- discriminants is that of the current instance of the type, and
9433 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
9435 -- AI-402: access discriminants have accessibility based on the
9436 -- object rather than the type in Ada 2005, so the above paragraph
9437 -- doesn't apply.
9439 -- ??? Needs completion with rules from AI-416
9441 if Ada_Version <= Ada_95
9442 and then Ekind (Typ) = E_Anonymous_Access_Type
9443 and then Present (Associated_Node_For_Itype (Typ))
9444 and then Nkind (Associated_Node_For_Itype (Typ)) =
9445 N_Discriminant_Specification
9446 then
9447 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
9448 end if;
9449 end if;
9451 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
9452 end Type_Access_Level;
9454 --------------------
9455 -- Ultimate_Alias --
9456 --------------------
9457 -- To do: add occurrences calling this new subprogram
9459 function Ultimate_Alias (Prim : Entity_Id) return Entity_Id is
9460 E : Entity_Id := Prim;
9462 begin
9463 while Present (Alias (E)) loop
9464 E := Alias (E);
9465 end loop;
9467 return E;
9468 end Ultimate_Alias;
9470 --------------------------
9471 -- Unit_Declaration_Node --
9472 --------------------------
9474 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
9475 N : Node_Id := Parent (Unit_Id);
9477 begin
9478 -- Predefined operators do not have a full function declaration
9480 if Ekind (Unit_Id) = E_Operator then
9481 return N;
9482 end if;
9484 -- Isn't there some better way to express the following ???
9486 while Nkind (N) /= N_Abstract_Subprogram_Declaration
9487 and then Nkind (N) /= N_Formal_Package_Declaration
9488 and then Nkind (N) /= N_Function_Instantiation
9489 and then Nkind (N) /= N_Generic_Package_Declaration
9490 and then Nkind (N) /= N_Generic_Subprogram_Declaration
9491 and then Nkind (N) /= N_Package_Declaration
9492 and then Nkind (N) /= N_Package_Body
9493 and then Nkind (N) /= N_Package_Instantiation
9494 and then Nkind (N) /= N_Package_Renaming_Declaration
9495 and then Nkind (N) /= N_Procedure_Instantiation
9496 and then Nkind (N) /= N_Protected_Body
9497 and then Nkind (N) /= N_Subprogram_Declaration
9498 and then Nkind (N) /= N_Subprogram_Body
9499 and then Nkind (N) /= N_Subprogram_Body_Stub
9500 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
9501 and then Nkind (N) /= N_Task_Body
9502 and then Nkind (N) /= N_Task_Type_Declaration
9503 and then Nkind (N) not in N_Formal_Subprogram_Declaration
9504 and then Nkind (N) not in N_Generic_Renaming_Declaration
9505 loop
9506 N := Parent (N);
9507 pragma Assert (Present (N));
9508 end loop;
9510 return N;
9511 end Unit_Declaration_Node;
9513 ------------------------------
9514 -- Universal_Interpretation --
9515 ------------------------------
9517 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
9518 Index : Interp_Index;
9519 It : Interp;
9521 begin
9522 -- The argument may be a formal parameter of an operator or subprogram
9523 -- with multiple interpretations, or else an expression for an actual.
9525 if Nkind (Opnd) = N_Defining_Identifier
9526 or else not Is_Overloaded (Opnd)
9527 then
9528 if Etype (Opnd) = Universal_Integer
9529 or else Etype (Opnd) = Universal_Real
9530 then
9531 return Etype (Opnd);
9532 else
9533 return Empty;
9534 end if;
9536 else
9537 Get_First_Interp (Opnd, Index, It);
9538 while Present (It.Typ) loop
9539 if It.Typ = Universal_Integer
9540 or else It.Typ = Universal_Real
9541 then
9542 return It.Typ;
9543 end if;
9545 Get_Next_Interp (Index, It);
9546 end loop;
9548 return Empty;
9549 end if;
9550 end Universal_Interpretation;
9552 ---------------
9553 -- Unqualify --
9554 ---------------
9556 function Unqualify (Expr : Node_Id) return Node_Id is
9557 begin
9558 -- Recurse to handle unlikely case of multiple levels of qualification
9560 if Nkind (Expr) = N_Qualified_Expression then
9561 return Unqualify (Expression (Expr));
9563 -- Normal case, not a qualified expression
9565 else
9566 return Expr;
9567 end if;
9568 end Unqualify;
9570 ----------------------
9571 -- Within_Init_Proc --
9572 ----------------------
9574 function Within_Init_Proc return Boolean is
9575 S : Entity_Id;
9577 begin
9578 S := Current_Scope;
9579 while not Is_Overloadable (S) loop
9580 if S = Standard_Standard then
9581 return False;
9582 else
9583 S := Scope (S);
9584 end if;
9585 end loop;
9587 return Is_Init_Proc (S);
9588 end Within_Init_Proc;
9590 ----------------
9591 -- Wrong_Type --
9592 ----------------
9594 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
9595 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
9596 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
9598 function Has_One_Matching_Field return Boolean;
9599 -- Determines if Expec_Type is a record type with a single component or
9600 -- discriminant whose type matches the found type or is one dimensional
9601 -- array whose component type matches the found type.
9603 ----------------------------
9604 -- Has_One_Matching_Field --
9605 ----------------------------
9607 function Has_One_Matching_Field return Boolean is
9608 E : Entity_Id;
9610 begin
9611 if Is_Array_Type (Expec_Type)
9612 and then Number_Dimensions (Expec_Type) = 1
9613 and then
9614 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
9615 then
9616 return True;
9618 elsif not Is_Record_Type (Expec_Type) then
9619 return False;
9621 else
9622 E := First_Entity (Expec_Type);
9623 loop
9624 if No (E) then
9625 return False;
9627 elsif (Ekind (E) /= E_Discriminant
9628 and then Ekind (E) /= E_Component)
9629 or else (Chars (E) = Name_uTag
9630 or else Chars (E) = Name_uParent)
9631 then
9632 Next_Entity (E);
9634 else
9635 exit;
9636 end if;
9637 end loop;
9639 if not Covers (Etype (E), Found_Type) then
9640 return False;
9642 elsif Present (Next_Entity (E)) then
9643 return False;
9645 else
9646 return True;
9647 end if;
9648 end if;
9649 end Has_One_Matching_Field;
9651 -- Start of processing for Wrong_Type
9653 begin
9654 -- Don't output message if either type is Any_Type, or if a message
9655 -- has already been posted for this node. We need to do the latter
9656 -- check explicitly (it is ordinarily done in Errout), because we
9657 -- are using ! to force the output of the error messages.
9659 if Expec_Type = Any_Type
9660 or else Found_Type = Any_Type
9661 or else Error_Posted (Expr)
9662 then
9663 return;
9665 -- In an instance, there is an ongoing problem with completion of
9666 -- type derived from private types. Their structure is what Gigi
9667 -- expects, but the Etype is the parent type rather than the
9668 -- derived private type itself. Do not flag error in this case. The
9669 -- private completion is an entity without a parent, like an Itype.
9670 -- Similarly, full and partial views may be incorrect in the instance.
9671 -- There is no simple way to insure that it is consistent ???
9673 elsif In_Instance then
9674 if Etype (Etype (Expr)) = Etype (Expected_Type)
9675 and then
9676 (Has_Private_Declaration (Expected_Type)
9677 or else Has_Private_Declaration (Etype (Expr)))
9678 and then No (Parent (Expected_Type))
9679 then
9680 return;
9681 end if;
9682 end if;
9684 -- An interesting special check. If the expression is parenthesized
9685 -- and its type corresponds to the type of the sole component of the
9686 -- expected record type, or to the component type of the expected one
9687 -- dimensional array type, then assume we have a bad aggregate attempt.
9689 if Nkind (Expr) in N_Subexpr
9690 and then Paren_Count (Expr) /= 0
9691 and then Has_One_Matching_Field
9692 then
9693 Error_Msg_N ("positional aggregate cannot have one component", Expr);
9695 -- Another special check, if we are looking for a pool-specific access
9696 -- type and we found an E_Access_Attribute_Type, then we have the case
9697 -- of an Access attribute being used in a context which needs a pool-
9698 -- specific type, which is never allowed. The one extra check we make
9699 -- is that the expected designated type covers the Found_Type.
9701 elsif Is_Access_Type (Expec_Type)
9702 and then Ekind (Found_Type) = E_Access_Attribute_Type
9703 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
9704 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
9705 and then Covers
9706 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
9707 then
9708 Error_Msg_N ("result must be general access type!", Expr);
9709 Error_Msg_NE ("add ALL to }!", Expr, Expec_Type);
9711 -- Another special check, if the expected type is an integer type,
9712 -- but the expression is of type System.Address, and the parent is
9713 -- an addition or subtraction operation whose left operand is the
9714 -- expression in question and whose right operand is of an integral
9715 -- type, then this is an attempt at address arithmetic, so give
9716 -- appropriate message.
9718 elsif Is_Integer_Type (Expec_Type)
9719 and then Is_RTE (Found_Type, RE_Address)
9720 and then (Nkind (Parent (Expr)) = N_Op_Add
9721 or else
9722 Nkind (Parent (Expr)) = N_Op_Subtract)
9723 and then Expr = Left_Opnd (Parent (Expr))
9724 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
9725 then
9726 Error_Msg_N
9727 ("address arithmetic not predefined in package System",
9728 Parent (Expr));
9729 Error_Msg_N
9730 ("\possible missing with/use of System.Storage_Elements",
9731 Parent (Expr));
9732 return;
9734 -- If the expected type is an anonymous access type, as for access
9735 -- parameters and discriminants, the error is on the designated types.
9737 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
9738 if Comes_From_Source (Expec_Type) then
9739 Error_Msg_NE ("expected}!", Expr, Expec_Type);
9740 else
9741 Error_Msg_NE
9742 ("expected an access type with designated}",
9743 Expr, Designated_Type (Expec_Type));
9744 end if;
9746 if Is_Access_Type (Found_Type)
9747 and then not Comes_From_Source (Found_Type)
9748 then
9749 Error_Msg_NE
9750 ("\\found an access type with designated}!",
9751 Expr, Designated_Type (Found_Type));
9752 else
9753 if From_With_Type (Found_Type) then
9754 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
9755 Error_Msg_Qual_Level := 99;
9756 Error_Msg_NE ("\\missing `WITH &;", Expr, Scope (Found_Type));
9757 Error_Msg_Qual_Level := 0;
9758 else
9759 Error_Msg_NE ("found}!", Expr, Found_Type);
9760 end if;
9761 end if;
9763 -- Normal case of one type found, some other type expected
9765 else
9766 -- If the names of the two types are the same, see if some number
9767 -- of levels of qualification will help. Don't try more than three
9768 -- levels, and if we get to standard, it's no use (and probably
9769 -- represents an error in the compiler) Also do not bother with
9770 -- internal scope names.
9772 declare
9773 Expec_Scope : Entity_Id;
9774 Found_Scope : Entity_Id;
9776 begin
9777 Expec_Scope := Expec_Type;
9778 Found_Scope := Found_Type;
9780 for Levels in Int range 0 .. 3 loop
9781 if Chars (Expec_Scope) /= Chars (Found_Scope) then
9782 Error_Msg_Qual_Level := Levels;
9783 exit;
9784 end if;
9786 Expec_Scope := Scope (Expec_Scope);
9787 Found_Scope := Scope (Found_Scope);
9789 exit when Expec_Scope = Standard_Standard
9790 or else Found_Scope = Standard_Standard
9791 or else not Comes_From_Source (Expec_Scope)
9792 or else not Comes_From_Source (Found_Scope);
9793 end loop;
9794 end;
9796 if Is_Record_Type (Expec_Type)
9797 and then Present (Corresponding_Remote_Type (Expec_Type))
9798 then
9799 Error_Msg_NE ("expected}!", Expr,
9800 Corresponding_Remote_Type (Expec_Type));
9801 else
9802 Error_Msg_NE ("expected}!", Expr, Expec_Type);
9803 end if;
9805 if Is_Entity_Name (Expr)
9806 and then Is_Package_Or_Generic_Package (Entity (Expr))
9807 then
9808 Error_Msg_N ("\\found package name!", Expr);
9810 elsif Is_Entity_Name (Expr)
9811 and then
9812 (Ekind (Entity (Expr)) = E_Procedure
9813 or else
9814 Ekind (Entity (Expr)) = E_Generic_Procedure)
9815 then
9816 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
9817 Error_Msg_N
9818 ("found procedure name, possibly missing Access attribute!",
9819 Expr);
9820 else
9821 Error_Msg_N
9822 ("\\found procedure name instead of function!", Expr);
9823 end if;
9825 elsif Nkind (Expr) = N_Function_Call
9826 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
9827 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
9828 and then No (Parameter_Associations (Expr))
9829 then
9830 Error_Msg_N
9831 ("found function name, possibly missing Access attribute!",
9832 Expr);
9834 -- Catch common error: a prefix or infix operator which is not
9835 -- directly visible because the type isn't.
9837 elsif Nkind (Expr) in N_Op
9838 and then Is_Overloaded (Expr)
9839 and then not Is_Immediately_Visible (Expec_Type)
9840 and then not Is_Potentially_Use_Visible (Expec_Type)
9841 and then not In_Use (Expec_Type)
9842 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
9843 then
9844 Error_Msg_N
9845 ("operator of the type is not directly visible!", Expr);
9847 elsif Ekind (Found_Type) = E_Void
9848 and then Present (Parent (Found_Type))
9849 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
9850 then
9851 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
9853 else
9854 Error_Msg_NE ("\\found}!", Expr, Found_Type);
9855 end if;
9857 Error_Msg_Qual_Level := 0;
9858 end if;
9859 end Wrong_Type;
9861 end Sem_Util;