Daily bump.
[official-gcc.git] / gcc / ada / sem_util.adb
blob1be22cf7df0ec4c234d4c2d716c065a0e32fa396
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_Tss; use Exp_Tss;
33 with Exp_Util; use Exp_Util;
34 with Fname; use Fname;
35 with Freeze; use Freeze;
36 with Lib; use Lib;
37 with Lib.Xref; use Lib.Xref;
38 with Nlists; use Nlists;
39 with Output; use Output;
40 with Opt; use Opt;
41 with Rtsfind; use Rtsfind;
42 with Scans; use Scans;
43 with Scn; use Scn;
44 with Sem; use Sem;
45 with Sem_Attr; use Sem_Attr;
46 with Sem_Ch6; use Sem_Ch6;
47 with Sem_Ch8; use Sem_Ch8;
48 with Sem_Eval; use Sem_Eval;
49 with Sem_Res; use Sem_Res;
50 with Sem_Type; use Sem_Type;
51 with Sinfo; use Sinfo;
52 with Sinput; use Sinput;
53 with 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 elsif Ekind (Typ) = E_Record_Type_With_Private then
103 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
104 Nod := Type_Definition (Parent (Typ));
106 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
107 if Present (Full_View (Typ)) then
108 Nod := Type_Definition (Parent (Full_View (Typ)));
110 -- If the full-view is not available we cannot do anything else
111 -- here (the source has errors).
113 else
114 return Empty_List;
115 end if;
117 -- Support for generic formals with interfaces is still missing ???
119 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
120 return Empty_List;
122 else
123 pragma Assert
124 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
125 Nod := Parent (Typ);
126 end if;
128 elsif Ekind (Typ) = E_Record_Subtype then
129 Nod := Type_Definition (Parent (Etype (Typ)));
131 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
133 -- Recurse, because parent may still be a private extension. Also
134 -- note that the full view of the subtype or the full view of its
135 -- base type may (both) be unavailable.
137 return Abstract_Interface_List (Etype (Typ));
139 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
140 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
141 Nod := Formal_Type_Definition (Parent (Typ));
142 else
143 Nod := Type_Definition (Parent (Typ));
144 end if;
145 end if;
147 return Interface_List (Nod);
148 end Abstract_Interface_List;
150 --------------------------------
151 -- Add_Access_Type_To_Process --
152 --------------------------------
154 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
155 L : Elist_Id;
157 begin
158 Ensure_Freeze_Node (E);
159 L := Access_Types_To_Process (Freeze_Node (E));
161 if No (L) then
162 L := New_Elmt_List;
163 Set_Access_Types_To_Process (Freeze_Node (E), L);
164 end if;
166 Append_Elmt (A, L);
167 end Add_Access_Type_To_Process;
169 ----------------------------
170 -- Add_Global_Declaration --
171 ----------------------------
173 procedure Add_Global_Declaration (N : Node_Id) is
174 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
176 begin
177 if No (Declarations (Aux_Node)) then
178 Set_Declarations (Aux_Node, New_List);
179 end if;
181 Append_To (Declarations (Aux_Node), N);
182 Analyze (N);
183 end Add_Global_Declaration;
185 -----------------------
186 -- Alignment_In_Bits --
187 -----------------------
189 function Alignment_In_Bits (E : Entity_Id) return Uint is
190 begin
191 return Alignment (E) * System_Storage_Unit;
192 end Alignment_In_Bits;
194 -----------------------------------------
195 -- Apply_Compile_Time_Constraint_Error --
196 -----------------------------------------
198 procedure Apply_Compile_Time_Constraint_Error
199 (N : Node_Id;
200 Msg : String;
201 Reason : RT_Exception_Code;
202 Ent : Entity_Id := Empty;
203 Typ : Entity_Id := Empty;
204 Loc : Source_Ptr := No_Location;
205 Rep : Boolean := True;
206 Warn : Boolean := False)
208 Stat : constant Boolean := Is_Static_Expression (N);
209 R_Stat : constant Node_Id :=
210 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
211 Rtyp : Entity_Id;
213 begin
214 if No (Typ) then
215 Rtyp := Etype (N);
216 else
217 Rtyp := Typ;
218 end if;
220 Discard_Node
221 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
223 if not Rep then
224 return;
225 end if;
227 -- Now we replace the node by an N_Raise_Constraint_Error node
228 -- This does not need reanalyzing, so set it as analyzed now.
230 Rewrite (N, R_Stat);
231 Set_Analyzed (N, True);
233 Set_Etype (N, Rtyp);
234 Set_Raises_Constraint_Error (N);
236 -- If the original expression was marked as static, the result is
237 -- still marked as static, but the Raises_Constraint_Error flag is
238 -- always set so that further static evaluation is not attempted.
240 if Stat then
241 Set_Is_Static_Expression (N);
242 end if;
243 end Apply_Compile_Time_Constraint_Error;
245 --------------------------
246 -- Build_Actual_Subtype --
247 --------------------------
249 function Build_Actual_Subtype
250 (T : Entity_Id;
251 N : Node_Or_Entity_Id) return Node_Id
253 Loc : Source_Ptr;
254 -- Normally Sloc (N), but may point to corresponding body in some cases
256 Constraints : List_Id;
257 Decl : Node_Id;
258 Discr : Entity_Id;
259 Hi : Node_Id;
260 Lo : Node_Id;
261 Subt : Entity_Id;
262 Disc_Type : Entity_Id;
263 Obj : Node_Id;
265 begin
266 Loc := Sloc (N);
268 if Nkind (N) = N_Defining_Identifier then
269 Obj := New_Reference_To (N, Loc);
271 -- If this is a formal parameter of a subprogram declaration, and
272 -- we are compiling the body, we want the declaration for the
273 -- actual subtype to carry the source position of the body, to
274 -- prevent anomalies in gdb when stepping through the code.
276 if Is_Formal (N) then
277 declare
278 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
279 begin
280 if Nkind (Decl) = N_Subprogram_Declaration
281 and then Present (Corresponding_Body (Decl))
282 then
283 Loc := Sloc (Corresponding_Body (Decl));
284 end if;
285 end;
286 end if;
288 else
289 Obj := N;
290 end if;
292 if Is_Array_Type (T) then
293 Constraints := New_List;
294 for J in 1 .. Number_Dimensions (T) loop
296 -- Build an array subtype declaration with the nominal subtype and
297 -- the bounds of the actual. Add the declaration in front of the
298 -- local declarations for the subprogram, for analysis before any
299 -- reference to the formal in the body.
301 Lo :=
302 Make_Attribute_Reference (Loc,
303 Prefix =>
304 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
305 Attribute_Name => Name_First,
306 Expressions => New_List (
307 Make_Integer_Literal (Loc, J)));
309 Hi :=
310 Make_Attribute_Reference (Loc,
311 Prefix =>
312 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
313 Attribute_Name => Name_Last,
314 Expressions => New_List (
315 Make_Integer_Literal (Loc, J)));
317 Append (Make_Range (Loc, Lo, Hi), Constraints);
318 end loop;
320 -- If the type has unknown discriminants there is no constrained
321 -- subtype to build. This is never called for a formal or for a
322 -- lhs, so returning the type is ok ???
324 elsif Has_Unknown_Discriminants (T) then
325 return T;
327 else
328 Constraints := New_List;
330 -- Type T is a generic derived type, inherit the discriminants from
331 -- the parent type.
333 if Is_Private_Type (T)
334 and then No (Full_View (T))
336 -- T was flagged as an error if it was declared as a formal
337 -- derived type with known discriminants. In this case there
338 -- is no need to look at the parent type since T already carries
339 -- its own discriminants.
341 and then not Error_Posted (T)
342 then
343 Disc_Type := Etype (Base_Type (T));
344 else
345 Disc_Type := T;
346 end if;
348 Discr := First_Discriminant (Disc_Type);
349 while Present (Discr) loop
350 Append_To (Constraints,
351 Make_Selected_Component (Loc,
352 Prefix =>
353 Duplicate_Subexpr_No_Checks (Obj),
354 Selector_Name => New_Occurrence_Of (Discr, Loc)));
355 Next_Discriminant (Discr);
356 end loop;
357 end if;
359 Subt :=
360 Make_Defining_Identifier (Loc,
361 Chars => New_Internal_Name ('S'));
362 Set_Is_Internal (Subt);
364 Decl :=
365 Make_Subtype_Declaration (Loc,
366 Defining_Identifier => Subt,
367 Subtype_Indication =>
368 Make_Subtype_Indication (Loc,
369 Subtype_Mark => New_Reference_To (T, Loc),
370 Constraint =>
371 Make_Index_Or_Discriminant_Constraint (Loc,
372 Constraints => Constraints)));
374 Mark_Rewrite_Insertion (Decl);
375 return Decl;
376 end Build_Actual_Subtype;
378 ---------------------------------------
379 -- Build_Actual_Subtype_Of_Component --
380 ---------------------------------------
382 function Build_Actual_Subtype_Of_Component
383 (T : Entity_Id;
384 N : Node_Id) return Node_Id
386 Loc : constant Source_Ptr := Sloc (N);
387 P : constant Node_Id := Prefix (N);
388 D : Elmt_Id;
389 Id : Node_Id;
390 Indx_Type : Entity_Id;
392 Deaccessed_T : Entity_Id;
393 -- This is either a copy of T, or if T is an access type, then it is
394 -- the directly designated type of this access type.
396 function Build_Actual_Array_Constraint return List_Id;
397 -- If one or more of the bounds of the component depends on
398 -- discriminants, build actual constraint using the discriminants
399 -- of the prefix.
401 function Build_Actual_Record_Constraint return List_Id;
402 -- Similar to previous one, for discriminated components constrained
403 -- by the discriminant of the enclosing object.
405 -----------------------------------
406 -- Build_Actual_Array_Constraint --
407 -----------------------------------
409 function Build_Actual_Array_Constraint return List_Id is
410 Constraints : constant List_Id := New_List;
411 Indx : Node_Id;
412 Hi : Node_Id;
413 Lo : Node_Id;
414 Old_Hi : Node_Id;
415 Old_Lo : Node_Id;
417 begin
418 Indx := First_Index (Deaccessed_T);
419 while Present (Indx) loop
420 Old_Lo := Type_Low_Bound (Etype (Indx));
421 Old_Hi := Type_High_Bound (Etype (Indx));
423 if Denotes_Discriminant (Old_Lo) then
424 Lo :=
425 Make_Selected_Component (Loc,
426 Prefix => New_Copy_Tree (P),
427 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
429 else
430 Lo := New_Copy_Tree (Old_Lo);
432 -- The new bound will be reanalyzed in the enclosing
433 -- declaration. For literal bounds that come from a type
434 -- declaration, the type of the context must be imposed, so
435 -- insure that analysis will take place. For non-universal
436 -- types this is not strictly necessary.
438 Set_Analyzed (Lo, False);
439 end if;
441 if Denotes_Discriminant (Old_Hi) then
442 Hi :=
443 Make_Selected_Component (Loc,
444 Prefix => New_Copy_Tree (P),
445 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
447 else
448 Hi := New_Copy_Tree (Old_Hi);
449 Set_Analyzed (Hi, False);
450 end if;
452 Append (Make_Range (Loc, Lo, Hi), Constraints);
453 Next_Index (Indx);
454 end loop;
456 return Constraints;
457 end Build_Actual_Array_Constraint;
459 ------------------------------------
460 -- Build_Actual_Record_Constraint --
461 ------------------------------------
463 function Build_Actual_Record_Constraint return List_Id is
464 Constraints : constant List_Id := New_List;
465 D : Elmt_Id;
466 D_Val : Node_Id;
468 begin
469 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
470 while Present (D) loop
471 if Denotes_Discriminant (Node (D)) then
472 D_Val := Make_Selected_Component (Loc,
473 Prefix => New_Copy_Tree (P),
474 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
476 else
477 D_Val := New_Copy_Tree (Node (D));
478 end if;
480 Append (D_Val, Constraints);
481 Next_Elmt (D);
482 end loop;
484 return Constraints;
485 end Build_Actual_Record_Constraint;
487 -- Start of processing for Build_Actual_Subtype_Of_Component
489 begin
490 -- Why the test for Spec_Expression mode here???
492 if In_Spec_Expression then
493 return Empty;
495 -- More comments for the rest of this body would be good ???
497 elsif Nkind (N) = N_Explicit_Dereference then
498 if Is_Composite_Type (T)
499 and then not Is_Constrained (T)
500 and then not (Is_Class_Wide_Type (T)
501 and then Is_Constrained (Root_Type (T)))
502 and then not Has_Unknown_Discriminants (T)
503 then
504 -- If the type of the dereference is already constrained, it
505 -- is an actual subtype.
507 if Is_Array_Type (Etype (N))
508 and then Is_Constrained (Etype (N))
509 then
510 return Empty;
511 else
512 Remove_Side_Effects (P);
513 return Build_Actual_Subtype (T, N);
514 end if;
515 else
516 return Empty;
517 end if;
518 end if;
520 if Ekind (T) = E_Access_Subtype then
521 Deaccessed_T := Designated_Type (T);
522 else
523 Deaccessed_T := T;
524 end if;
526 if Ekind (Deaccessed_T) = E_Array_Subtype then
527 Id := First_Index (Deaccessed_T);
528 while Present (Id) loop
529 Indx_Type := Underlying_Type (Etype (Id));
531 if Denotes_Discriminant (Type_Low_Bound (Indx_Type))
532 or else
533 Denotes_Discriminant (Type_High_Bound (Indx_Type))
534 then
535 Remove_Side_Effects (P);
536 return
537 Build_Component_Subtype
538 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
539 end if;
541 Next_Index (Id);
542 end loop;
544 elsif Is_Composite_Type (Deaccessed_T)
545 and then Has_Discriminants (Deaccessed_T)
546 and then not Has_Unknown_Discriminants (Deaccessed_T)
547 then
548 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
549 while Present (D) loop
550 if Denotes_Discriminant (Node (D)) then
551 Remove_Side_Effects (P);
552 return
553 Build_Component_Subtype (
554 Build_Actual_Record_Constraint, Loc, Base_Type (T));
555 end if;
557 Next_Elmt (D);
558 end loop;
559 end if;
561 -- If none of the above, the actual and nominal subtypes are the same
563 return Empty;
564 end Build_Actual_Subtype_Of_Component;
566 -----------------------------
567 -- Build_Component_Subtype --
568 -----------------------------
570 function Build_Component_Subtype
571 (C : List_Id;
572 Loc : Source_Ptr;
573 T : Entity_Id) return Node_Id
575 Subt : Entity_Id;
576 Decl : Node_Id;
578 begin
579 -- Unchecked_Union components do not require component subtypes
581 if Is_Unchecked_Union (T) then
582 return Empty;
583 end if;
585 Subt :=
586 Make_Defining_Identifier (Loc,
587 Chars => New_Internal_Name ('S'));
588 Set_Is_Internal (Subt);
590 Decl :=
591 Make_Subtype_Declaration (Loc,
592 Defining_Identifier => Subt,
593 Subtype_Indication =>
594 Make_Subtype_Indication (Loc,
595 Subtype_Mark => New_Reference_To (Base_Type (T), Loc),
596 Constraint =>
597 Make_Index_Or_Discriminant_Constraint (Loc,
598 Constraints => C)));
600 Mark_Rewrite_Insertion (Decl);
601 return Decl;
602 end Build_Component_Subtype;
604 ---------------------------
605 -- Build_Default_Subtype --
606 ---------------------------
608 function Build_Default_Subtype
609 (T : Entity_Id;
610 N : Node_Id) return Entity_Id
612 Loc : constant Source_Ptr := Sloc (N);
613 Disc : Entity_Id;
615 begin
616 if not Has_Discriminants (T) or else Is_Constrained (T) then
617 return T;
618 end if;
620 Disc := First_Discriminant (T);
622 if No (Discriminant_Default_Value (Disc)) then
623 return T;
624 end if;
626 declare
627 Act : constant Entity_Id :=
628 Make_Defining_Identifier (Loc,
629 Chars => New_Internal_Name ('S'));
631 Constraints : constant List_Id := New_List;
632 Decl : Node_Id;
634 begin
635 while Present (Disc) loop
636 Append_To (Constraints,
637 New_Copy_Tree (Discriminant_Default_Value (Disc)));
638 Next_Discriminant (Disc);
639 end loop;
641 Decl :=
642 Make_Subtype_Declaration (Loc,
643 Defining_Identifier => Act,
644 Subtype_Indication =>
645 Make_Subtype_Indication (Loc,
646 Subtype_Mark => New_Occurrence_Of (T, Loc),
647 Constraint =>
648 Make_Index_Or_Discriminant_Constraint (Loc,
649 Constraints => Constraints)));
651 Insert_Action (N, Decl);
652 Analyze (Decl);
653 return Act;
654 end;
655 end Build_Default_Subtype;
657 --------------------------------------------
658 -- Build_Discriminal_Subtype_Of_Component --
659 --------------------------------------------
661 function Build_Discriminal_Subtype_Of_Component
662 (T : Entity_Id) return Node_Id
664 Loc : constant Source_Ptr := Sloc (T);
665 D : Elmt_Id;
666 Id : Node_Id;
668 function Build_Discriminal_Array_Constraint return List_Id;
669 -- If one or more of the bounds of the component depends on
670 -- discriminants, build actual constraint using the discriminants
671 -- of the prefix.
673 function Build_Discriminal_Record_Constraint return List_Id;
674 -- Similar to previous one, for discriminated components constrained
675 -- by the discriminant of the enclosing object.
677 ----------------------------------------
678 -- Build_Discriminal_Array_Constraint --
679 ----------------------------------------
681 function Build_Discriminal_Array_Constraint return List_Id is
682 Constraints : constant List_Id := New_List;
683 Indx : Node_Id;
684 Hi : Node_Id;
685 Lo : Node_Id;
686 Old_Hi : Node_Id;
687 Old_Lo : Node_Id;
689 begin
690 Indx := First_Index (T);
691 while Present (Indx) loop
692 Old_Lo := Type_Low_Bound (Etype (Indx));
693 Old_Hi := Type_High_Bound (Etype (Indx));
695 if Denotes_Discriminant (Old_Lo) then
696 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
698 else
699 Lo := New_Copy_Tree (Old_Lo);
700 end if;
702 if Denotes_Discriminant (Old_Hi) then
703 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
705 else
706 Hi := New_Copy_Tree (Old_Hi);
707 end if;
709 Append (Make_Range (Loc, Lo, Hi), Constraints);
710 Next_Index (Indx);
711 end loop;
713 return Constraints;
714 end Build_Discriminal_Array_Constraint;
716 -----------------------------------------
717 -- Build_Discriminal_Record_Constraint --
718 -----------------------------------------
720 function Build_Discriminal_Record_Constraint return List_Id is
721 Constraints : constant List_Id := New_List;
722 D : Elmt_Id;
723 D_Val : Node_Id;
725 begin
726 D := First_Elmt (Discriminant_Constraint (T));
727 while Present (D) loop
728 if Denotes_Discriminant (Node (D)) then
729 D_Val :=
730 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
732 else
733 D_Val := New_Copy_Tree (Node (D));
734 end if;
736 Append (D_Val, Constraints);
737 Next_Elmt (D);
738 end loop;
740 return Constraints;
741 end Build_Discriminal_Record_Constraint;
743 -- Start of processing for Build_Discriminal_Subtype_Of_Component
745 begin
746 if Ekind (T) = E_Array_Subtype then
747 Id := First_Index (T);
748 while Present (Id) loop
749 if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) or else
750 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
751 then
752 return Build_Component_Subtype
753 (Build_Discriminal_Array_Constraint, Loc, T);
754 end if;
756 Next_Index (Id);
757 end loop;
759 elsif Ekind (T) = E_Record_Subtype
760 and then Has_Discriminants (T)
761 and then not Has_Unknown_Discriminants (T)
762 then
763 D := First_Elmt (Discriminant_Constraint (T));
764 while Present (D) loop
765 if Denotes_Discriminant (Node (D)) then
766 return Build_Component_Subtype
767 (Build_Discriminal_Record_Constraint, Loc, T);
768 end if;
770 Next_Elmt (D);
771 end loop;
772 end if;
774 -- If none of the above, the actual and nominal subtypes are the same
776 return Empty;
777 end Build_Discriminal_Subtype_Of_Component;
779 ------------------------------
780 -- Build_Elaboration_Entity --
781 ------------------------------
783 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
784 Loc : constant Source_Ptr := Sloc (N);
785 Decl : Node_Id;
786 Elab_Ent : Entity_Id;
788 procedure Set_Package_Name (Ent : Entity_Id);
789 -- Given an entity, sets the fully qualified name of the entity in
790 -- Name_Buffer, with components separated by double underscores. This
791 -- is a recursive routine that climbs the scope chain to Standard.
793 ----------------------
794 -- Set_Package_Name --
795 ----------------------
797 procedure Set_Package_Name (Ent : Entity_Id) is
798 begin
799 if Scope (Ent) /= Standard_Standard then
800 Set_Package_Name (Scope (Ent));
802 declare
803 Nam : constant String := Get_Name_String (Chars (Ent));
804 begin
805 Name_Buffer (Name_Len + 1) := '_';
806 Name_Buffer (Name_Len + 2) := '_';
807 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
808 Name_Len := Name_Len + Nam'Length + 2;
809 end;
811 else
812 Get_Name_String (Chars (Ent));
813 end if;
814 end Set_Package_Name;
816 -- Start of processing for Build_Elaboration_Entity
818 begin
819 -- Ignore if already constructed
821 if Present (Elaboration_Entity (Spec_Id)) then
822 return;
823 end if;
825 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
826 -- name with dots replaced by double underscore. We have to manually
827 -- construct this name, since it will be elaborated in the outer scope,
828 -- and thus will not have the unit name automatically prepended.
830 Set_Package_Name (Spec_Id);
832 -- Append _E
834 Name_Buffer (Name_Len + 1) := '_';
835 Name_Buffer (Name_Len + 2) := 'E';
836 Name_Len := Name_Len + 2;
838 -- Create elaboration flag
840 Elab_Ent :=
841 Make_Defining_Identifier (Loc, Chars => Name_Find);
842 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
844 Decl :=
845 Make_Object_Declaration (Loc,
846 Defining_Identifier => Elab_Ent,
847 Object_Definition =>
848 New_Occurrence_Of (Standard_Boolean, Loc),
849 Expression =>
850 New_Occurrence_Of (Standard_False, Loc));
852 Push_Scope (Standard_Standard);
853 Add_Global_Declaration (Decl);
854 Pop_Scope;
856 -- Reset True_Constant indication, since we will indeed assign a value
857 -- to the variable in the binder main. We also kill the Current_Value
858 -- and Last_Assignment fields for the same reason.
860 Set_Is_True_Constant (Elab_Ent, False);
861 Set_Current_Value (Elab_Ent, Empty);
862 Set_Last_Assignment (Elab_Ent, Empty);
864 -- We do not want any further qualification of the name (if we did
865 -- not do this, we would pick up the name of the generic package
866 -- in the case of a library level generic instantiation).
868 Set_Has_Qualified_Name (Elab_Ent);
869 Set_Has_Fully_Qualified_Name (Elab_Ent);
870 end Build_Elaboration_Entity;
872 -----------------------------------
873 -- Cannot_Raise_Constraint_Error --
874 -----------------------------------
876 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
877 begin
878 if Compile_Time_Known_Value (Expr) then
879 return True;
881 elsif Do_Range_Check (Expr) then
882 return False;
884 elsif Raises_Constraint_Error (Expr) then
885 return False;
887 else
888 case Nkind (Expr) is
889 when N_Identifier =>
890 return True;
892 when N_Expanded_Name =>
893 return True;
895 when N_Selected_Component =>
896 return not Do_Discriminant_Check (Expr);
898 when N_Attribute_Reference =>
899 if Do_Overflow_Check (Expr) then
900 return False;
902 elsif No (Expressions (Expr)) then
903 return True;
905 else
906 declare
907 N : Node_Id;
909 begin
910 N := First (Expressions (Expr));
911 while Present (N) loop
912 if Cannot_Raise_Constraint_Error (N) then
913 Next (N);
914 else
915 return False;
916 end if;
917 end loop;
919 return True;
920 end;
921 end if;
923 when N_Type_Conversion =>
924 if Do_Overflow_Check (Expr)
925 or else Do_Length_Check (Expr)
926 or else Do_Tag_Check (Expr)
927 then
928 return False;
929 else
930 return
931 Cannot_Raise_Constraint_Error (Expression (Expr));
932 end if;
934 when N_Unchecked_Type_Conversion =>
935 return Cannot_Raise_Constraint_Error (Expression (Expr));
937 when N_Unary_Op =>
938 if Do_Overflow_Check (Expr) then
939 return False;
940 else
941 return
942 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
943 end if;
945 when N_Op_Divide |
946 N_Op_Mod |
947 N_Op_Rem
949 if Do_Division_Check (Expr)
950 or else Do_Overflow_Check (Expr)
951 then
952 return False;
953 else
954 return
955 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
956 and then
957 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
958 end if;
960 when N_Op_Add |
961 N_Op_And |
962 N_Op_Concat |
963 N_Op_Eq |
964 N_Op_Expon |
965 N_Op_Ge |
966 N_Op_Gt |
967 N_Op_Le |
968 N_Op_Lt |
969 N_Op_Multiply |
970 N_Op_Ne |
971 N_Op_Or |
972 N_Op_Rotate_Left |
973 N_Op_Rotate_Right |
974 N_Op_Shift_Left |
975 N_Op_Shift_Right |
976 N_Op_Shift_Right_Arithmetic |
977 N_Op_Subtract |
978 N_Op_Xor
980 if Do_Overflow_Check (Expr) then
981 return False;
982 else
983 return
984 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
985 and then
986 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
987 end if;
989 when others =>
990 return False;
991 end case;
992 end if;
993 end Cannot_Raise_Constraint_Error;
995 --------------------------
996 -- Check_Fully_Declared --
997 --------------------------
999 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
1000 begin
1001 if Ekind (T) = E_Incomplete_Type then
1003 -- Ada 2005 (AI-50217): If the type is available through a limited
1004 -- with_clause, verify that its full view has been analyzed.
1006 if From_With_Type (T)
1007 and then Present (Non_Limited_View (T))
1008 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1009 then
1010 -- The non-limited view is fully declared
1011 null;
1013 else
1014 Error_Msg_NE
1015 ("premature usage of incomplete}", N, First_Subtype (T));
1016 end if;
1018 -- Need comments for these tests ???
1020 elsif Has_Private_Component (T)
1021 and then not Is_Generic_Type (Root_Type (T))
1022 and then not In_Spec_Expression
1023 then
1024 -- Special case: if T is the anonymous type created for a single
1025 -- task or protected object, use the name of the source object.
1027 if Is_Concurrent_Type (T)
1028 and then not Comes_From_Source (T)
1029 and then Nkind (N) = N_Object_Declaration
1030 then
1031 Error_Msg_NE ("type of& has incomplete component", N,
1032 Defining_Identifier (N));
1034 else
1035 Error_Msg_NE
1036 ("premature usage of incomplete}", N, First_Subtype (T));
1037 end if;
1038 end if;
1039 end Check_Fully_Declared;
1041 -------------------------
1042 -- Check_Nested_Access --
1043 -------------------------
1045 procedure Check_Nested_Access (Ent : Entity_Id) is
1046 Scop : constant Entity_Id := Current_Scope;
1047 Current_Subp : Entity_Id;
1048 Enclosing : Entity_Id;
1050 begin
1051 -- Currently only enabled for VM back-ends for efficiency, should we
1052 -- enable it more systematically ???
1054 -- Check for Is_Imported needs commenting below ???
1056 if VM_Target /= No_VM
1057 and then (Ekind (Ent) = E_Variable
1058 or else
1059 Ekind (Ent) = E_Constant
1060 or else
1061 Ekind (Ent) = E_Loop_Parameter)
1062 and then Scope (Ent) /= Empty
1063 and then not Is_Library_Level_Entity (Ent)
1064 and then not Is_Imported (Ent)
1065 then
1066 if Is_Subprogram (Scop)
1067 or else Is_Generic_Subprogram (Scop)
1068 or else Is_Entry (Scop)
1069 then
1070 Current_Subp := Scop;
1071 else
1072 Current_Subp := Current_Subprogram;
1073 end if;
1075 Enclosing := Enclosing_Subprogram (Ent);
1077 if Enclosing /= Empty
1078 and then Enclosing /= Current_Subp
1079 then
1080 Set_Has_Up_Level_Access (Ent, True);
1081 end if;
1082 end if;
1083 end Check_Nested_Access;
1085 ------------------------------------------
1086 -- Check_Potentially_Blocking_Operation --
1087 ------------------------------------------
1089 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
1090 S : Entity_Id;
1091 begin
1092 -- N is one of the potentially blocking operations listed in 9.5.1(8).
1093 -- When pragma Detect_Blocking is active, the run time will raise
1094 -- Program_Error. Here we only issue a warning, since we generally
1095 -- support the use of potentially blocking operations in the absence
1096 -- of the pragma.
1098 -- Indirect blocking through a subprogram call cannot be diagnosed
1099 -- statically without interprocedural analysis, so we do not attempt
1100 -- to do it here.
1102 S := Scope (Current_Scope);
1103 while Present (S) and then S /= Standard_Standard loop
1104 if Is_Protected_Type (S) then
1105 Error_Msg_N
1106 ("potentially blocking operation in protected operation?", N);
1108 return;
1109 end if;
1111 S := Scope (S);
1112 end loop;
1113 end Check_Potentially_Blocking_Operation;
1115 ------------------------------
1116 -- Check_Unprotected_Access --
1117 ------------------------------
1119 procedure Check_Unprotected_Access
1120 (Context : Node_Id;
1121 Expr : Node_Id)
1123 Cont_Encl_Typ : Entity_Id;
1124 Pref_Encl_Typ : Entity_Id;
1126 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
1127 -- Check whether Obj is a private component of a protected object.
1128 -- Return the protected type where the component resides, Empty
1129 -- otherwise.
1131 function Is_Public_Operation return Boolean;
1132 -- Verify that the enclosing operation is callable from outside the
1133 -- protected object, to minimize false positives.
1135 ------------------------------
1136 -- Enclosing_Protected_Type --
1137 ------------------------------
1139 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
1140 begin
1141 if Is_Entity_Name (Obj) then
1142 declare
1143 Ent : Entity_Id := Entity (Obj);
1145 begin
1146 -- The object can be a renaming of a private component, use
1147 -- the original record component.
1149 if Is_Prival (Ent) then
1150 Ent := Prival_Link (Ent);
1151 end if;
1153 if Is_Protected_Type (Scope (Ent)) then
1154 return Scope (Ent);
1155 end if;
1156 end;
1157 end if;
1159 -- For indexed and selected components, recursively check the prefix
1161 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
1162 return Enclosing_Protected_Type (Prefix (Obj));
1164 -- The object does not denote a protected component
1166 else
1167 return Empty;
1168 end if;
1169 end Enclosing_Protected_Type;
1171 -------------------------
1172 -- Is_Public_Operation --
1173 -------------------------
1175 function Is_Public_Operation return Boolean is
1176 S : Entity_Id;
1177 E : Entity_Id;
1179 begin
1180 S := Current_Scope;
1181 while Present (S)
1182 and then S /= Pref_Encl_Typ
1183 loop
1184 if Scope (S) = Pref_Encl_Typ then
1185 E := First_Entity (Pref_Encl_Typ);
1186 while Present (E)
1187 and then E /= First_Private_Entity (Pref_Encl_Typ)
1188 loop
1189 if E = S then
1190 return True;
1191 end if;
1192 Next_Entity (E);
1193 end loop;
1194 end if;
1196 S := Scope (S);
1197 end loop;
1199 return False;
1200 end Is_Public_Operation;
1202 -- Start of processing for Check_Unprotected_Access
1204 begin
1205 if Nkind (Expr) = N_Attribute_Reference
1206 and then Attribute_Name (Expr) = Name_Unchecked_Access
1207 then
1208 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
1209 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
1211 -- Check whether we are trying to export a protected component to a
1212 -- context with an equal or lower access level.
1214 if Present (Pref_Encl_Typ)
1215 and then No (Cont_Encl_Typ)
1216 and then Is_Public_Operation
1217 and then Scope_Depth (Pref_Encl_Typ) >=
1218 Object_Access_Level (Context)
1219 then
1220 Error_Msg_N
1221 ("?possible unprotected access to protected data", Expr);
1222 end if;
1223 end if;
1224 end Check_Unprotected_Access;
1226 ---------------
1227 -- Check_VMS --
1228 ---------------
1230 procedure Check_VMS (Construct : Node_Id) is
1231 begin
1232 if not OpenVMS_On_Target then
1233 Error_Msg_N
1234 ("this construct is allowed only in Open'V'M'S", Construct);
1235 end if;
1236 end Check_VMS;
1238 ---------------------------------
1239 -- Collect_Abstract_Interfaces --
1240 ---------------------------------
1242 procedure Collect_Abstract_Interfaces
1243 (T : Entity_Id;
1244 Ifaces_List : out Elist_Id;
1245 Exclude_Parent_Interfaces : Boolean := False;
1246 Use_Full_View : Boolean := True)
1248 procedure Add_Interface (Iface : Entity_Id);
1249 -- Add the interface it if is not already in the list
1251 procedure Collect (Typ : Entity_Id);
1252 -- Subsidiary subprogram used to traverse the whole list
1253 -- of directly and indirectly implemented interfaces
1255 function Interface_Present_In_Parent
1256 (Typ : Entity_Id;
1257 Iface : Entity_Id) return Boolean;
1258 -- Typ must be a tagged record type/subtype and Iface must be an
1259 -- abstract interface type. This function is used to check if Typ
1260 -- or some parent of Typ implements Iface.
1262 -------------------
1263 -- Add_Interface --
1264 -------------------
1266 procedure Add_Interface (Iface : Entity_Id) is
1267 Elmt : Elmt_Id;
1269 begin
1270 Elmt := First_Elmt (Ifaces_List);
1271 while Present (Elmt) and then Node (Elmt) /= Iface loop
1272 Next_Elmt (Elmt);
1273 end loop;
1275 if No (Elmt) then
1276 Append_Elmt (Iface, Ifaces_List);
1277 end if;
1278 end Add_Interface;
1280 -------------
1281 -- Collect --
1282 -------------
1284 procedure Collect (Typ : Entity_Id) is
1285 Ancestor : Entity_Id;
1286 Full_T : Entity_Id;
1287 Iface_List : List_Id;
1288 Id : Node_Id;
1289 Iface : Entity_Id;
1291 begin
1292 Full_T := Typ;
1294 -- Handle private types
1296 if Use_Full_View
1297 and then Is_Private_Type (Typ)
1298 and then Present (Full_View (Typ))
1299 then
1300 Full_T := Full_View (Typ);
1301 end if;
1303 Iface_List := Abstract_Interface_List (Full_T);
1305 -- Include the ancestor if we are generating the whole list of
1306 -- abstract interfaces.
1308 -- In concurrent types the ancestor interface (if any) is the
1309 -- first element of the list of interface types.
1311 if Is_Concurrent_Type (Full_T)
1312 or else Is_Concurrent_Record_Type (Full_T)
1313 then
1314 if Is_Non_Empty_List (Iface_List) then
1315 Ancestor := Etype (First (Iface_List));
1316 Collect (Ancestor);
1318 if not Exclude_Parent_Interfaces then
1319 Add_Interface (Ancestor);
1320 end if;
1321 end if;
1323 elsif Etype (Full_T) /= Typ
1325 -- Protect the frontend against wrong sources. For example:
1327 -- package P is
1328 -- type A is tagged null record;
1329 -- type B is new A with private;
1330 -- type C is new A with private;
1331 -- private
1332 -- type B is new C with null record;
1333 -- type C is new B with null record;
1334 -- end P;
1336 and then Etype (Full_T) /= T
1337 then
1338 Ancestor := Etype (Full_T);
1339 Collect (Ancestor);
1341 if Is_Interface (Ancestor)
1342 and then not Exclude_Parent_Interfaces
1343 then
1344 Add_Interface (Ancestor);
1345 end if;
1346 end if;
1348 -- Traverse the graph of ancestor interfaces
1350 if Is_Non_Empty_List (Iface_List) then
1351 Id := First (Iface_List);
1353 -- In concurrent types the ancestor interface (if any) is the
1354 -- first element of the list of interface types and we have
1355 -- already processed them while climbing to the root type.
1357 if Is_Concurrent_Type (Full_T)
1358 or else Is_Concurrent_Record_Type (Full_T)
1359 then
1360 Next (Id);
1361 end if;
1363 while Present (Id) loop
1364 Iface := Etype (Id);
1366 -- Protect against wrong uses. For example:
1367 -- type I is interface;
1368 -- type O is tagged null record;
1369 -- type Wrong is new I and O with null record; -- ERROR
1371 if Is_Interface (Iface) then
1372 if Exclude_Parent_Interfaces
1373 and then Interface_Present_In_Parent (T, Iface)
1374 then
1375 null;
1376 else
1377 Collect (Iface);
1378 Add_Interface (Iface);
1379 end if;
1380 end if;
1382 Next (Id);
1383 end loop;
1384 end if;
1385 end Collect;
1387 ---------------------------------
1388 -- Interface_Present_In_Parent --
1389 ---------------------------------
1391 function Interface_Present_In_Parent
1392 (Typ : Entity_Id;
1393 Iface : Entity_Id) return Boolean
1395 Aux : Entity_Id := Typ;
1396 Iface_List : List_Id;
1398 begin
1399 if Is_Concurrent_Type (Typ)
1400 or else Is_Concurrent_Record_Type (Typ)
1401 then
1402 Iface_List := Abstract_Interface_List (Typ);
1404 if Is_Non_Empty_List (Iface_List) then
1405 Aux := Etype (First (Iface_List));
1406 else
1407 return False;
1408 end if;
1409 end if;
1411 return Interface_Present_In_Ancestor (Aux, Iface);
1412 end Interface_Present_In_Parent;
1414 -- Start of processing for Collect_Abstract_Interfaces
1416 begin
1417 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
1418 Ifaces_List := New_Elmt_List;
1419 Collect (T);
1420 end Collect_Abstract_Interfaces;
1422 ----------------------------------
1423 -- Collect_Interface_Components --
1424 ----------------------------------
1426 procedure Collect_Interface_Components
1427 (Tagged_Type : Entity_Id;
1428 Components_List : out Elist_Id)
1430 procedure Collect (Typ : Entity_Id);
1431 -- Subsidiary subprogram used to climb to the parents
1433 -------------
1434 -- Collect --
1435 -------------
1437 procedure Collect (Typ : Entity_Id) is
1438 Tag_Comp : Entity_Id;
1440 begin
1441 if Etype (Typ) /= Typ
1443 -- Protect the frontend against wrong sources. For example:
1445 -- package P is
1446 -- type A is tagged null record;
1447 -- type B is new A with private;
1448 -- type C is new A with private;
1449 -- private
1450 -- type B is new C with null record;
1451 -- type C is new B with null record;
1452 -- end P;
1454 and then Etype (Typ) /= Tagged_Type
1455 then
1456 Collect (Etype (Typ));
1457 end if;
1459 -- Collect the components containing tags of secondary dispatch
1460 -- tables.
1462 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
1463 while Present (Tag_Comp) loop
1464 pragma Assert (Present (Related_Type (Tag_Comp)));
1465 Append_Elmt (Tag_Comp, Components_List);
1467 Tag_Comp := Next_Tag_Component (Tag_Comp);
1468 end loop;
1469 end Collect;
1471 -- Start of processing for Collect_Interface_Components
1473 begin
1474 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
1475 and then Is_Tagged_Type (Tagged_Type));
1477 Components_List := New_Elmt_List;
1478 Collect (Tagged_Type);
1479 end Collect_Interface_Components;
1481 -----------------------------
1482 -- Collect_Interfaces_Info --
1483 -----------------------------
1485 procedure Collect_Interfaces_Info
1486 (T : Entity_Id;
1487 Ifaces_List : out Elist_Id;
1488 Components_List : out Elist_Id;
1489 Tags_List : out Elist_Id)
1491 Comps_List : Elist_Id;
1492 Comp_Elmt : Elmt_Id;
1493 Comp_Iface : Entity_Id;
1494 Iface_Elmt : Elmt_Id;
1495 Iface : Entity_Id;
1497 function Search_Tag (Iface : Entity_Id) return Entity_Id;
1498 -- Search for the secondary tag associated with the interface type
1499 -- Iface that is implemented by T.
1501 ----------------
1502 -- Search_Tag --
1503 ----------------
1505 function Search_Tag (Iface : Entity_Id) return Entity_Id is
1506 ADT : Elmt_Id;
1508 begin
1509 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
1510 while Present (ADT)
1511 and then Ekind (Node (ADT)) = E_Constant
1512 and then Related_Type (Node (ADT)) /= Iface
1513 loop
1514 -- Skip the secondary dispatch tables of Iface
1516 Next_Elmt (ADT);
1517 Next_Elmt (ADT);
1518 Next_Elmt (ADT);
1519 Next_Elmt (ADT);
1520 end loop;
1522 pragma Assert (Ekind (Node (ADT)) = E_Constant);
1523 return Node (ADT);
1524 end Search_Tag;
1526 -- Start of processing for Collect_Interfaces_Info
1528 begin
1529 Collect_Abstract_Interfaces (T, Ifaces_List);
1530 Collect_Interface_Components (T, Comps_List);
1532 -- Search for the record component and tag associated with each
1533 -- interface type of T.
1535 Components_List := New_Elmt_List;
1536 Tags_List := New_Elmt_List;
1538 Iface_Elmt := First_Elmt (Ifaces_List);
1539 while Present (Iface_Elmt) loop
1540 Iface := Node (Iface_Elmt);
1542 -- Associate the primary tag component and the primary dispatch table
1543 -- with all the interfaces that are parents of T
1545 if Is_Parent (Iface, T) then
1546 Append_Elmt (First_Tag_Component (T), Components_List);
1547 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
1549 -- Otherwise search for the tag component and secondary dispatch
1550 -- table of Iface
1552 else
1553 Comp_Elmt := First_Elmt (Comps_List);
1554 while Present (Comp_Elmt) loop
1555 Comp_Iface := Related_Type (Node (Comp_Elmt));
1557 if Comp_Iface = Iface
1558 or else Is_Parent (Iface, Comp_Iface)
1559 then
1560 Append_Elmt (Node (Comp_Elmt), Components_List);
1561 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
1562 exit;
1563 end if;
1565 Next_Elmt (Comp_Elmt);
1566 end loop;
1567 pragma Assert (Present (Comp_Elmt));
1568 end if;
1570 Next_Elmt (Iface_Elmt);
1571 end loop;
1572 end Collect_Interfaces_Info;
1574 ----------------------------------
1575 -- Collect_Primitive_Operations --
1576 ----------------------------------
1578 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
1579 B_Type : constant Entity_Id := Base_Type (T);
1580 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
1581 B_Scope : Entity_Id := Scope (B_Type);
1582 Op_List : Elist_Id;
1583 Formal : Entity_Id;
1584 Is_Prim : Boolean;
1585 Formal_Derived : Boolean := False;
1586 Id : Entity_Id;
1588 begin
1589 -- For tagged types, the primitive operations are collected as they
1590 -- are declared, and held in an explicit list which is simply returned.
1592 if Is_Tagged_Type (B_Type) then
1593 return Primitive_Operations (B_Type);
1595 -- An untagged generic type that is a derived type inherits the
1596 -- primitive operations of its parent type. Other formal types only
1597 -- have predefined operators, which are not explicitly represented.
1599 elsif Is_Generic_Type (B_Type) then
1600 if Nkind (B_Decl) = N_Formal_Type_Declaration
1601 and then Nkind (Formal_Type_Definition (B_Decl))
1602 = N_Formal_Derived_Type_Definition
1603 then
1604 Formal_Derived := True;
1605 else
1606 return New_Elmt_List;
1607 end if;
1608 end if;
1610 Op_List := New_Elmt_List;
1612 if B_Scope = Standard_Standard then
1613 if B_Type = Standard_String then
1614 Append_Elmt (Standard_Op_Concat, Op_List);
1616 elsif B_Type = Standard_Wide_String then
1617 Append_Elmt (Standard_Op_Concatw, Op_List);
1619 else
1620 null;
1621 end if;
1623 elsif (Is_Package_Or_Generic_Package (B_Scope)
1624 and then
1625 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
1626 N_Package_Body)
1627 or else Is_Derived_Type (B_Type)
1628 then
1629 -- The primitive operations appear after the base type, except
1630 -- if the derivation happens within the private part of B_Scope
1631 -- and the type is a private type, in which case both the type
1632 -- and some primitive operations may appear before the base
1633 -- type, and the list of candidates starts after the type.
1635 if In_Open_Scopes (B_Scope)
1636 and then Scope (T) = B_Scope
1637 and then In_Private_Part (B_Scope)
1638 then
1639 Id := Next_Entity (T);
1640 else
1641 Id := Next_Entity (B_Type);
1642 end if;
1644 while Present (Id) loop
1646 -- Note that generic formal subprograms are not
1647 -- considered to be primitive operations and thus
1648 -- are never inherited.
1650 if Is_Overloadable (Id)
1651 and then Nkind (Parent (Parent (Id)))
1652 not in N_Formal_Subprogram_Declaration
1653 then
1654 Is_Prim := False;
1656 if Base_Type (Etype (Id)) = B_Type then
1657 Is_Prim := True;
1658 else
1659 Formal := First_Formal (Id);
1660 while Present (Formal) loop
1661 if Base_Type (Etype (Formal)) = B_Type then
1662 Is_Prim := True;
1663 exit;
1665 elsif Ekind (Etype (Formal)) = E_Anonymous_Access_Type
1666 and then Base_Type
1667 (Designated_Type (Etype (Formal))) = B_Type
1668 then
1669 Is_Prim := True;
1670 exit;
1671 end if;
1673 Next_Formal (Formal);
1674 end loop;
1675 end if;
1677 -- For a formal derived type, the only primitives are the
1678 -- ones inherited from the parent type. Operations appearing
1679 -- in the package declaration are not primitive for it.
1681 if Is_Prim
1682 and then (not Formal_Derived
1683 or else Present (Alias (Id)))
1684 then
1685 Append_Elmt (Id, Op_List);
1686 end if;
1687 end if;
1689 Next_Entity (Id);
1691 -- For a type declared in System, some of its operations
1692 -- may appear in the target-specific extension to System.
1694 if No (Id)
1695 and then Chars (B_Scope) = Name_System
1696 and then Scope (B_Scope) = Standard_Standard
1697 and then Present_System_Aux
1698 then
1699 B_Scope := System_Aux_Id;
1700 Id := First_Entity (System_Aux_Id);
1701 end if;
1702 end loop;
1703 end if;
1705 return Op_List;
1706 end Collect_Primitive_Operations;
1708 -----------------------------------
1709 -- Compile_Time_Constraint_Error --
1710 -----------------------------------
1712 function Compile_Time_Constraint_Error
1713 (N : Node_Id;
1714 Msg : String;
1715 Ent : Entity_Id := Empty;
1716 Loc : Source_Ptr := No_Location;
1717 Warn : Boolean := False) return Node_Id
1719 Msgc : String (1 .. Msg'Length + 2);
1720 -- Copy of message, with room for possible ? and ! at end
1722 Msgl : Natural;
1723 Wmsg : Boolean;
1724 P : Node_Id;
1725 OldP : Node_Id;
1726 Msgs : Boolean;
1727 Eloc : Source_Ptr;
1729 begin
1730 -- A static constraint error in an instance body is not a fatal error.
1731 -- we choose to inhibit the message altogether, because there is no
1732 -- obvious node (for now) on which to post it. On the other hand the
1733 -- offending node must be replaced with a constraint_error in any case.
1735 -- No messages are generated if we already posted an error on this node
1737 if not Error_Posted (N) then
1738 if Loc /= No_Location then
1739 Eloc := Loc;
1740 else
1741 Eloc := Sloc (N);
1742 end if;
1744 Msgc (1 .. Msg'Length) := Msg;
1745 Msgl := Msg'Length;
1747 -- Message is a warning, even in Ada 95 case
1749 if Msg (Msg'Last) = '?' then
1750 Wmsg := True;
1752 -- In Ada 83, all messages are warnings. In the private part and
1753 -- the body of an instance, constraint_checks are only warnings.
1754 -- We also make this a warning if the Warn parameter is set.
1756 elsif Warn
1757 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
1758 then
1759 Msgl := Msgl + 1;
1760 Msgc (Msgl) := '?';
1761 Wmsg := True;
1763 elsif In_Instance_Not_Visible then
1764 Msgl := Msgl + 1;
1765 Msgc (Msgl) := '?';
1766 Wmsg := True;
1768 -- Otherwise we have a real error message (Ada 95 static case)
1769 -- and we make this an unconditional message. Note that in the
1770 -- warning case we do not make the message unconditional, it seems
1771 -- quite reasonable to delete messages like this (about exceptions
1772 -- that will be raised) in dead code.
1774 else
1775 Wmsg := False;
1776 Msgl := Msgl + 1;
1777 Msgc (Msgl) := '!';
1778 end if;
1780 -- Should we generate a warning? The answer is not quite yes. The
1781 -- very annoying exception occurs in the case of a short circuit
1782 -- operator where the left operand is static and decisive. Climb
1783 -- parents to see if that is the case we have here. Conditional
1784 -- expressions with decisive conditions are a similar situation.
1786 Msgs := True;
1787 P := N;
1788 loop
1789 OldP := P;
1790 P := Parent (P);
1792 -- And then with False as left operand
1794 if Nkind (P) = N_And_Then
1795 and then Compile_Time_Known_Value (Left_Opnd (P))
1796 and then Is_False (Expr_Value (Left_Opnd (P)))
1797 then
1798 Msgs := False;
1799 exit;
1801 -- OR ELSE with True as left operand
1803 elsif Nkind (P) = N_Or_Else
1804 and then Compile_Time_Known_Value (Left_Opnd (P))
1805 and then Is_True (Expr_Value (Left_Opnd (P)))
1806 then
1807 Msgs := False;
1808 exit;
1810 -- Conditional expression
1812 elsif Nkind (P) = N_Conditional_Expression then
1813 declare
1814 Cond : constant Node_Id := First (Expressions (P));
1815 Texp : constant Node_Id := Next (Cond);
1816 Fexp : constant Node_Id := Next (Texp);
1818 begin
1819 if Compile_Time_Known_Value (Cond) then
1821 -- Condition is True and we are in the right operand
1823 if Is_True (Expr_Value (Cond))
1824 and then OldP = Fexp
1825 then
1826 Msgs := False;
1827 exit;
1829 -- Condition is False and we are in the left operand
1831 elsif Is_False (Expr_Value (Cond))
1832 and then OldP = Texp
1833 then
1834 Msgs := False;
1835 exit;
1836 end if;
1837 end if;
1838 end;
1840 -- Special case for component association in aggregates, where
1841 -- we want to keep climbing up to the parent aggregate.
1843 elsif Nkind (P) = N_Component_Association
1844 and then Nkind (Parent (P)) = N_Aggregate
1845 then
1846 null;
1848 -- Keep going if within subexpression
1850 else
1851 exit when Nkind (P) not in N_Subexpr;
1852 end if;
1853 end loop;
1855 if Msgs then
1856 if Present (Ent) then
1857 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
1858 else
1859 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
1860 end if;
1862 if Wmsg then
1863 if Inside_Init_Proc then
1864 Error_Msg_NEL
1865 ("\?& will be raised for objects of this type",
1866 N, Standard_Constraint_Error, Eloc);
1867 else
1868 Error_Msg_NEL
1869 ("\?& will be raised at run time",
1870 N, Standard_Constraint_Error, Eloc);
1871 end if;
1873 else
1874 Error_Msg
1875 ("\static expression fails Constraint_Check", Eloc);
1876 Set_Error_Posted (N);
1877 end if;
1878 end if;
1879 end if;
1881 return N;
1882 end Compile_Time_Constraint_Error;
1884 -----------------------
1885 -- Conditional_Delay --
1886 -----------------------
1888 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
1889 begin
1890 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
1891 Set_Has_Delayed_Freeze (New_Ent);
1892 end if;
1893 end Conditional_Delay;
1895 -------------------------
1896 -- Copy_Parameter_List --
1897 -------------------------
1899 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
1900 Loc : constant Source_Ptr := Sloc (Subp_Id);
1901 Plist : List_Id;
1902 Formal : Entity_Id;
1904 begin
1905 if No (First_Formal (Subp_Id)) then
1906 return No_List;
1907 else
1908 Plist := New_List;
1909 Formal := First_Formal (Subp_Id);
1910 while Present (Formal) loop
1911 Append
1912 (Make_Parameter_Specification (Loc,
1913 Defining_Identifier =>
1914 Make_Defining_Identifier (Sloc (Formal),
1915 Chars => Chars (Formal)),
1916 In_Present => In_Present (Parent (Formal)),
1917 Out_Present => Out_Present (Parent (Formal)),
1918 Parameter_Type =>
1919 New_Reference_To (Etype (Formal), Loc),
1920 Expression =>
1921 New_Copy_Tree (Expression (Parent (Formal)))),
1922 Plist);
1924 Next_Formal (Formal);
1925 end loop;
1926 end if;
1928 return Plist;
1929 end Copy_Parameter_List;
1931 --------------------
1932 -- Current_Entity --
1933 --------------------
1935 -- The currently visible definition for a given identifier is the
1936 -- one most chained at the start of the visibility chain, i.e. the
1937 -- one that is referenced by the Node_Id value of the name of the
1938 -- given identifier.
1940 function Current_Entity (N : Node_Id) return Entity_Id is
1941 begin
1942 return Get_Name_Entity_Id (Chars (N));
1943 end Current_Entity;
1945 -----------------------------
1946 -- Current_Entity_In_Scope --
1947 -----------------------------
1949 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
1950 E : Entity_Id;
1951 CS : constant Entity_Id := Current_Scope;
1953 Transient_Case : constant Boolean := Scope_Is_Transient;
1955 begin
1956 E := Get_Name_Entity_Id (Chars (N));
1957 while Present (E)
1958 and then Scope (E) /= CS
1959 and then (not Transient_Case or else Scope (E) /= Scope (CS))
1960 loop
1961 E := Homonym (E);
1962 end loop;
1964 return E;
1965 end Current_Entity_In_Scope;
1967 -------------------
1968 -- Current_Scope --
1969 -------------------
1971 function Current_Scope return Entity_Id is
1972 begin
1973 if Scope_Stack.Last = -1 then
1974 return Standard_Standard;
1975 else
1976 declare
1977 C : constant Entity_Id :=
1978 Scope_Stack.Table (Scope_Stack.Last).Entity;
1979 begin
1980 if Present (C) then
1981 return C;
1982 else
1983 return Standard_Standard;
1984 end if;
1985 end;
1986 end if;
1987 end Current_Scope;
1989 ------------------------
1990 -- Current_Subprogram --
1991 ------------------------
1993 function Current_Subprogram return Entity_Id is
1994 Scop : constant Entity_Id := Current_Scope;
1996 begin
1997 if Is_Subprogram (Scop) or else Is_Generic_Subprogram (Scop) then
1998 return Scop;
1999 else
2000 return Enclosing_Subprogram (Scop);
2001 end if;
2002 end Current_Subprogram;
2004 ---------------------
2005 -- Defining_Entity --
2006 ---------------------
2008 function Defining_Entity (N : Node_Id) return Entity_Id is
2009 K : constant Node_Kind := Nkind (N);
2010 Err : Entity_Id := Empty;
2012 begin
2013 case K is
2014 when
2015 N_Subprogram_Declaration |
2016 N_Abstract_Subprogram_Declaration |
2017 N_Subprogram_Body |
2018 N_Package_Declaration |
2019 N_Subprogram_Renaming_Declaration |
2020 N_Subprogram_Body_Stub |
2021 N_Generic_Subprogram_Declaration |
2022 N_Generic_Package_Declaration |
2023 N_Formal_Subprogram_Declaration
2025 return Defining_Entity (Specification (N));
2027 when
2028 N_Component_Declaration |
2029 N_Defining_Program_Unit_Name |
2030 N_Discriminant_Specification |
2031 N_Entry_Body |
2032 N_Entry_Declaration |
2033 N_Entry_Index_Specification |
2034 N_Exception_Declaration |
2035 N_Exception_Renaming_Declaration |
2036 N_Formal_Object_Declaration |
2037 N_Formal_Package_Declaration |
2038 N_Formal_Type_Declaration |
2039 N_Full_Type_Declaration |
2040 N_Implicit_Label_Declaration |
2041 N_Incomplete_Type_Declaration |
2042 N_Loop_Parameter_Specification |
2043 N_Number_Declaration |
2044 N_Object_Declaration |
2045 N_Object_Renaming_Declaration |
2046 N_Package_Body_Stub |
2047 N_Parameter_Specification |
2048 N_Private_Extension_Declaration |
2049 N_Private_Type_Declaration |
2050 N_Protected_Body |
2051 N_Protected_Body_Stub |
2052 N_Protected_Type_Declaration |
2053 N_Single_Protected_Declaration |
2054 N_Single_Task_Declaration |
2055 N_Subtype_Declaration |
2056 N_Task_Body |
2057 N_Task_Body_Stub |
2058 N_Task_Type_Declaration
2060 return Defining_Identifier (N);
2062 when N_Subunit =>
2063 return Defining_Entity (Proper_Body (N));
2065 when
2066 N_Function_Instantiation |
2067 N_Function_Specification |
2068 N_Generic_Function_Renaming_Declaration |
2069 N_Generic_Package_Renaming_Declaration |
2070 N_Generic_Procedure_Renaming_Declaration |
2071 N_Package_Body |
2072 N_Package_Instantiation |
2073 N_Package_Renaming_Declaration |
2074 N_Package_Specification |
2075 N_Procedure_Instantiation |
2076 N_Procedure_Specification
2078 declare
2079 Nam : constant Node_Id := Defining_Unit_Name (N);
2081 begin
2082 if Nkind (Nam) in N_Entity then
2083 return Nam;
2085 -- For Error, make up a name and attach to declaration
2086 -- so we can continue semantic analysis
2088 elsif Nam = Error then
2089 Err :=
2090 Make_Defining_Identifier (Sloc (N),
2091 Chars => New_Internal_Name ('T'));
2092 Set_Defining_Unit_Name (N, Err);
2094 return Err;
2095 -- If not an entity, get defining identifier
2097 else
2098 return Defining_Identifier (Nam);
2099 end if;
2100 end;
2102 when N_Block_Statement =>
2103 return Entity (Identifier (N));
2105 when others =>
2106 raise Program_Error;
2108 end case;
2109 end Defining_Entity;
2111 --------------------------
2112 -- Denotes_Discriminant --
2113 --------------------------
2115 function Denotes_Discriminant
2116 (N : Node_Id;
2117 Check_Concurrent : Boolean := False) return Boolean
2119 E : Entity_Id;
2120 begin
2121 if not Is_Entity_Name (N)
2122 or else No (Entity (N))
2123 then
2124 return False;
2125 else
2126 E := Entity (N);
2127 end if;
2129 -- If we are checking for a protected type, the discriminant may have
2130 -- been rewritten as the corresponding discriminal of the original type
2131 -- or of the corresponding concurrent record, depending on whether we
2132 -- are in the spec or body of the protected type.
2134 return Ekind (E) = E_Discriminant
2135 or else
2136 (Check_Concurrent
2137 and then Ekind (E) = E_In_Parameter
2138 and then Present (Discriminal_Link (E))
2139 and then
2140 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
2141 or else
2142 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
2144 end Denotes_Discriminant;
2146 ----------------------
2147 -- Denotes_Variable --
2148 ----------------------
2150 function Denotes_Variable (N : Node_Id) return Boolean is
2151 begin
2152 return Is_Variable (N) and then Paren_Count (N) = 0;
2153 end Denotes_Variable;
2155 -----------------------------
2156 -- Depends_On_Discriminant --
2157 -----------------------------
2159 function Depends_On_Discriminant (N : Node_Id) return Boolean is
2160 L : Node_Id;
2161 H : Node_Id;
2163 begin
2164 Get_Index_Bounds (N, L, H);
2165 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
2166 end Depends_On_Discriminant;
2168 -------------------------
2169 -- Designate_Same_Unit --
2170 -------------------------
2172 function Designate_Same_Unit
2173 (Name1 : Node_Id;
2174 Name2 : Node_Id) return Boolean
2176 K1 : constant Node_Kind := Nkind (Name1);
2177 K2 : constant Node_Kind := Nkind (Name2);
2179 function Prefix_Node (N : Node_Id) return Node_Id;
2180 -- Returns the parent unit name node of a defining program unit name
2181 -- or the prefix if N is a selected component or an expanded name.
2183 function Select_Node (N : Node_Id) return Node_Id;
2184 -- Returns the defining identifier node of a defining program unit
2185 -- name or the selector node if N is a selected component or an
2186 -- expanded name.
2188 -----------------
2189 -- Prefix_Node --
2190 -----------------
2192 function Prefix_Node (N : Node_Id) return Node_Id is
2193 begin
2194 if Nkind (N) = N_Defining_Program_Unit_Name then
2195 return Name (N);
2197 else
2198 return Prefix (N);
2199 end if;
2200 end Prefix_Node;
2202 -----------------
2203 -- Select_Node --
2204 -----------------
2206 function Select_Node (N : Node_Id) return Node_Id is
2207 begin
2208 if Nkind (N) = N_Defining_Program_Unit_Name then
2209 return Defining_Identifier (N);
2211 else
2212 return Selector_Name (N);
2213 end if;
2214 end Select_Node;
2216 -- Start of processing for Designate_Next_Unit
2218 begin
2219 if (K1 = N_Identifier or else
2220 K1 = N_Defining_Identifier)
2221 and then
2222 (K2 = N_Identifier or else
2223 K2 = N_Defining_Identifier)
2224 then
2225 return Chars (Name1) = Chars (Name2);
2227 elsif
2228 (K1 = N_Expanded_Name or else
2229 K1 = N_Selected_Component or else
2230 K1 = N_Defining_Program_Unit_Name)
2231 and then
2232 (K2 = N_Expanded_Name or else
2233 K2 = N_Selected_Component or else
2234 K2 = N_Defining_Program_Unit_Name)
2235 then
2236 return
2237 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
2238 and then
2239 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
2241 else
2242 return False;
2243 end if;
2244 end Designate_Same_Unit;
2246 ----------------------------
2247 -- Enclosing_Generic_Body --
2248 ----------------------------
2250 function Enclosing_Generic_Body
2251 (N : Node_Id) return Node_Id
2253 P : Node_Id;
2254 Decl : Node_Id;
2255 Spec : Node_Id;
2257 begin
2258 P := Parent (N);
2259 while Present (P) loop
2260 if Nkind (P) = N_Package_Body
2261 or else Nkind (P) = N_Subprogram_Body
2262 then
2263 Spec := Corresponding_Spec (P);
2265 if Present (Spec) then
2266 Decl := Unit_Declaration_Node (Spec);
2268 if Nkind (Decl) = N_Generic_Package_Declaration
2269 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2270 then
2271 return P;
2272 end if;
2273 end if;
2274 end if;
2276 P := Parent (P);
2277 end loop;
2279 return Empty;
2280 end Enclosing_Generic_Body;
2282 ----------------------------
2283 -- Enclosing_Generic_Unit --
2284 ----------------------------
2286 function Enclosing_Generic_Unit
2287 (N : Node_Id) return Node_Id
2289 P : Node_Id;
2290 Decl : Node_Id;
2291 Spec : Node_Id;
2293 begin
2294 P := Parent (N);
2295 while Present (P) loop
2296 if Nkind (P) = N_Generic_Package_Declaration
2297 or else Nkind (P) = N_Generic_Subprogram_Declaration
2298 then
2299 return P;
2301 elsif Nkind (P) = N_Package_Body
2302 or else Nkind (P) = N_Subprogram_Body
2303 then
2304 Spec := Corresponding_Spec (P);
2306 if Present (Spec) then
2307 Decl := Unit_Declaration_Node (Spec);
2309 if Nkind (Decl) = N_Generic_Package_Declaration
2310 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2311 then
2312 return Decl;
2313 end if;
2314 end if;
2315 end if;
2317 P := Parent (P);
2318 end loop;
2320 return Empty;
2321 end Enclosing_Generic_Unit;
2323 -------------------------------
2324 -- Enclosing_Lib_Unit_Entity --
2325 -------------------------------
2327 function Enclosing_Lib_Unit_Entity return Entity_Id is
2328 Unit_Entity : Entity_Id;
2330 begin
2331 -- Look for enclosing library unit entity by following scope links.
2332 -- Equivalent to, but faster than indexing through the scope stack.
2334 Unit_Entity := Current_Scope;
2335 while (Present (Scope (Unit_Entity))
2336 and then Scope (Unit_Entity) /= Standard_Standard)
2337 and not Is_Child_Unit (Unit_Entity)
2338 loop
2339 Unit_Entity := Scope (Unit_Entity);
2340 end loop;
2342 return Unit_Entity;
2343 end Enclosing_Lib_Unit_Entity;
2345 -----------------------------
2346 -- Enclosing_Lib_Unit_Node --
2347 -----------------------------
2349 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
2350 Current_Node : Node_Id;
2352 begin
2353 Current_Node := N;
2354 while Present (Current_Node)
2355 and then Nkind (Current_Node) /= N_Compilation_Unit
2356 loop
2357 Current_Node := Parent (Current_Node);
2358 end loop;
2360 if Nkind (Current_Node) /= N_Compilation_Unit then
2361 return Empty;
2362 end if;
2364 return Current_Node;
2365 end Enclosing_Lib_Unit_Node;
2367 --------------------------
2368 -- Enclosing_Subprogram --
2369 --------------------------
2371 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
2372 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
2374 begin
2375 if Dynamic_Scope = Standard_Standard then
2376 return Empty;
2378 elsif Dynamic_Scope = Empty then
2379 return Empty;
2381 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
2382 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
2384 elsif Ekind (Dynamic_Scope) = E_Block
2385 or else Ekind (Dynamic_Scope) = E_Return_Statement
2386 then
2387 return Enclosing_Subprogram (Dynamic_Scope);
2389 elsif Ekind (Dynamic_Scope) = E_Task_Type then
2390 return Get_Task_Body_Procedure (Dynamic_Scope);
2392 elsif Convention (Dynamic_Scope) = Convention_Protected then
2393 return Protected_Body_Subprogram (Dynamic_Scope);
2395 else
2396 return Dynamic_Scope;
2397 end if;
2398 end Enclosing_Subprogram;
2400 ------------------------
2401 -- Ensure_Freeze_Node --
2402 ------------------------
2404 procedure Ensure_Freeze_Node (E : Entity_Id) is
2405 FN : Node_Id;
2407 begin
2408 if No (Freeze_Node (E)) then
2409 FN := Make_Freeze_Entity (Sloc (E));
2410 Set_Has_Delayed_Freeze (E);
2411 Set_Freeze_Node (E, FN);
2412 Set_Access_Types_To_Process (FN, No_Elist);
2413 Set_TSS_Elist (FN, No_Elist);
2414 Set_Entity (FN, E);
2415 end if;
2416 end Ensure_Freeze_Node;
2418 ----------------
2419 -- Enter_Name --
2420 ----------------
2422 procedure Enter_Name (Def_Id : Entity_Id) is
2423 C : constant Entity_Id := Current_Entity (Def_Id);
2424 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
2425 S : constant Entity_Id := Current_Scope;
2427 begin
2428 Generate_Definition (Def_Id);
2430 -- Add new name to current scope declarations. Check for duplicate
2431 -- declaration, which may or may not be a genuine error.
2433 if Present (E) then
2435 -- Case of previous entity entered because of a missing declaration
2436 -- or else a bad subtype indication. Best is to use the new entity,
2437 -- and make the previous one invisible.
2439 if Etype (E) = Any_Type then
2440 Set_Is_Immediately_Visible (E, False);
2442 -- Case of renaming declaration constructed for package instances.
2443 -- if there is an explicit declaration with the same identifier,
2444 -- the renaming is not immediately visible any longer, but remains
2445 -- visible through selected component notation.
2447 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
2448 and then not Comes_From_Source (E)
2449 then
2450 Set_Is_Immediately_Visible (E, False);
2452 -- The new entity may be the package renaming, which has the same
2453 -- same name as a generic formal which has been seen already.
2455 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
2456 and then not Comes_From_Source (Def_Id)
2457 then
2458 Set_Is_Immediately_Visible (E, False);
2460 -- For a fat pointer corresponding to a remote access to subprogram,
2461 -- we use the same identifier as the RAS type, so that the proper
2462 -- name appears in the stub. This type is only retrieved through
2463 -- the RAS type and never by visibility, and is not added to the
2464 -- visibility list (see below).
2466 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
2467 and then Present (Corresponding_Remote_Type (Def_Id))
2468 then
2469 null;
2471 -- A controller component for a type extension overrides the
2472 -- inherited component.
2474 elsif Chars (E) = Name_uController then
2475 null;
2477 -- Case of an implicit operation or derived literal. The new entity
2478 -- hides the implicit one, which is removed from all visibility,
2479 -- i.e. the entity list of its scope, and homonym chain of its name.
2481 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
2482 or else Is_Internal (E)
2483 then
2484 declare
2485 Prev : Entity_Id;
2486 Prev_Vis : Entity_Id;
2487 Decl : constant Node_Id := Parent (E);
2489 begin
2490 -- If E is an implicit declaration, it cannot be the first
2491 -- entity in the scope.
2493 Prev := First_Entity (Current_Scope);
2494 while Present (Prev)
2495 and then Next_Entity (Prev) /= E
2496 loop
2497 Next_Entity (Prev);
2498 end loop;
2500 if No (Prev) then
2502 -- If E is not on the entity chain of the current scope,
2503 -- it is an implicit declaration in the generic formal
2504 -- part of a generic subprogram. When analyzing the body,
2505 -- the generic formals are visible but not on the entity
2506 -- chain of the subprogram. The new entity will become
2507 -- the visible one in the body.
2509 pragma Assert
2510 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
2511 null;
2513 else
2514 Set_Next_Entity (Prev, Next_Entity (E));
2516 if No (Next_Entity (Prev)) then
2517 Set_Last_Entity (Current_Scope, Prev);
2518 end if;
2520 if E = Current_Entity (E) then
2521 Prev_Vis := Empty;
2523 else
2524 Prev_Vis := Current_Entity (E);
2525 while Homonym (Prev_Vis) /= E loop
2526 Prev_Vis := Homonym (Prev_Vis);
2527 end loop;
2528 end if;
2530 if Present (Prev_Vis) then
2532 -- Skip E in the visibility chain
2534 Set_Homonym (Prev_Vis, Homonym (E));
2536 else
2537 Set_Name_Entity_Id (Chars (E), Homonym (E));
2538 end if;
2539 end if;
2540 end;
2542 -- This section of code could use a comment ???
2544 elsif Present (Etype (E))
2545 and then Is_Concurrent_Type (Etype (E))
2546 and then E = Def_Id
2547 then
2548 return;
2550 -- If the homograph is a protected component renaming, it should not
2551 -- be hiding the current entity. Such renamings are treated as weak
2552 -- declarations.
2554 elsif Is_Prival (E) then
2555 Set_Is_Immediately_Visible (E, False);
2557 -- In this case the current entity is a protected component renaming.
2558 -- Perform minimal decoration by setting the scope and return since
2559 -- the prival should not be hiding other visible entities.
2561 elsif Is_Prival (Def_Id) then
2562 Set_Scope (Def_Id, Current_Scope);
2563 return;
2565 -- Analogous to privals, the discriminal generated for an entry
2566 -- index parameter acts as a weak declaration. Perform minimal
2567 -- decoration to avoid bogus errors.
2569 elsif Is_Discriminal (Def_Id)
2570 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
2571 then
2572 Set_Scope (Def_Id, Current_Scope);
2573 return;
2575 -- In the body or private part of an instance, a type extension
2576 -- may introduce a component with the same name as that of an
2577 -- actual. The legality rule is not enforced, but the semantics
2578 -- of the full type with two components of the same name are not
2579 -- clear at this point ???
2581 elsif In_Instance_Not_Visible then
2582 null;
2584 -- When compiling a package body, some child units may have become
2585 -- visible. They cannot conflict with local entities that hide them.
2587 elsif Is_Child_Unit (E)
2588 and then In_Open_Scopes (Scope (E))
2589 and then not Is_Immediately_Visible (E)
2590 then
2591 null;
2593 -- Conversely, with front-end inlining we may compile the parent
2594 -- body first, and a child unit subsequently. The context is now
2595 -- the parent spec, and body entities are not visible.
2597 elsif Is_Child_Unit (Def_Id)
2598 and then Is_Package_Body_Entity (E)
2599 and then not In_Package_Body (Current_Scope)
2600 then
2601 null;
2603 -- Case of genuine duplicate declaration
2605 else
2606 Error_Msg_Sloc := Sloc (E);
2608 -- If the previous declaration is an incomplete type declaration
2609 -- this may be an attempt to complete it with a private type.
2610 -- The following avoids confusing cascaded errors.
2612 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
2613 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
2614 then
2615 Error_Msg_N
2616 ("incomplete type cannot be completed with a private " &
2617 "declaration", Parent (Def_Id));
2618 Set_Is_Immediately_Visible (E, False);
2619 Set_Full_View (E, Def_Id);
2621 -- An inherited component of a record conflicts with a new
2622 -- discriminant. The discriminant is inserted first in the scope,
2623 -- but the error should be posted on it, not on the component.
2625 elsif Ekind (E) = E_Discriminant
2626 and then Present (Scope (Def_Id))
2627 and then Scope (Def_Id) /= Current_Scope
2628 then
2629 Error_Msg_Sloc := Sloc (Def_Id);
2630 Error_Msg_N ("& conflicts with declaration#", E);
2631 return;
2633 -- If the name of the unit appears in its own context clause,
2634 -- a dummy package with the name has already been created, and
2635 -- the error emitted. Try to continue quietly.
2637 elsif Error_Posted (E)
2638 and then Sloc (E) = No_Location
2639 and then Nkind (Parent (E)) = N_Package_Specification
2640 and then Current_Scope = Standard_Standard
2641 then
2642 Set_Scope (Def_Id, Current_Scope);
2643 return;
2645 else
2646 Error_Msg_N ("& conflicts with declaration#", Def_Id);
2648 -- Avoid cascaded messages with duplicate components in
2649 -- derived types.
2651 if Ekind (E) = E_Component
2652 or else Ekind (E) = E_Discriminant
2653 then
2654 return;
2655 end if;
2656 end if;
2658 if Nkind (Parent (Parent (Def_Id))) =
2659 N_Generic_Subprogram_Declaration
2660 and then Def_Id =
2661 Defining_Entity (Specification (Parent (Parent (Def_Id))))
2662 then
2663 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
2664 end if;
2666 -- If entity is in standard, then we are in trouble, because
2667 -- it means that we have a library package with a duplicated
2668 -- name. That's hard to recover from, so abort!
2670 if S = Standard_Standard then
2671 raise Unrecoverable_Error;
2673 -- Otherwise we continue with the declaration. Having two
2674 -- identical declarations should not cause us too much trouble!
2676 else
2677 null;
2678 end if;
2679 end if;
2680 end if;
2682 -- If we fall through, declaration is OK , or OK enough to continue
2684 -- If Def_Id is a discriminant or a record component we are in the
2685 -- midst of inheriting components in a derived record definition.
2686 -- Preserve their Ekind and Etype.
2688 if Ekind (Def_Id) = E_Discriminant
2689 or else Ekind (Def_Id) = E_Component
2690 then
2691 null;
2693 -- If a type is already set, leave it alone (happens whey a type
2694 -- declaration is reanalyzed following a call to the optimizer)
2696 elsif Present (Etype (Def_Id)) then
2697 null;
2699 -- Otherwise, the kind E_Void insures that premature uses of the entity
2700 -- will be detected. Any_Type insures that no cascaded errors will occur
2702 else
2703 Set_Ekind (Def_Id, E_Void);
2704 Set_Etype (Def_Id, Any_Type);
2705 end if;
2707 -- Inherited discriminants and components in derived record types are
2708 -- immediately visible. Itypes are not.
2710 if Ekind (Def_Id) = E_Discriminant
2711 or else Ekind (Def_Id) = E_Component
2712 or else (No (Corresponding_Remote_Type (Def_Id))
2713 and then not Is_Itype (Def_Id))
2714 then
2715 Set_Is_Immediately_Visible (Def_Id);
2716 Set_Current_Entity (Def_Id);
2717 end if;
2719 Set_Homonym (Def_Id, C);
2720 Append_Entity (Def_Id, S);
2721 Set_Public_Status (Def_Id);
2723 -- Warn if new entity hides an old one
2725 if Warn_On_Hiding and then Present (C)
2727 -- Don't warn for record components since they always have a well
2728 -- defined scope which does not confuse other uses. Note that in
2729 -- some cases, Ekind has not been set yet.
2731 and then Ekind (C) /= E_Component
2732 and then Ekind (C) /= E_Discriminant
2733 and then Nkind (Parent (C)) /= N_Component_Declaration
2734 and then Ekind (Def_Id) /= E_Component
2735 and then Ekind (Def_Id) /= E_Discriminant
2736 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
2738 -- Don't warn for one character variables. It is too common to use
2739 -- such variables as locals and will just cause too many false hits.
2741 and then Length_Of_Name (Chars (C)) /= 1
2743 -- Don't warn for non-source entities
2745 and then Comes_From_Source (C)
2746 and then Comes_From_Source (Def_Id)
2748 -- Don't warn unless entity in question is in extended main source
2750 and then In_Extended_Main_Source_Unit (Def_Id)
2752 -- Finally, the hidden entity must be either immediately visible
2753 -- or use visible (from a used package)
2755 and then
2756 (Is_Immediately_Visible (C)
2757 or else
2758 Is_Potentially_Use_Visible (C))
2759 then
2760 Error_Msg_Sloc := Sloc (C);
2761 Error_Msg_N ("declaration hides &#?", Def_Id);
2762 end if;
2763 end Enter_Name;
2765 --------------------------
2766 -- Explain_Limited_Type --
2767 --------------------------
2769 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
2770 C : Entity_Id;
2772 begin
2773 -- For array, component type must be limited
2775 if Is_Array_Type (T) then
2776 Error_Msg_Node_2 := T;
2777 Error_Msg_NE
2778 ("\component type& of type& is limited", N, Component_Type (T));
2779 Explain_Limited_Type (Component_Type (T), N);
2781 elsif Is_Record_Type (T) then
2783 -- No need for extra messages if explicit limited record
2785 if Is_Limited_Record (Base_Type (T)) then
2786 return;
2787 end if;
2789 -- Otherwise find a limited component. Check only components that
2790 -- come from source, or inherited components that appear in the
2791 -- source of the ancestor.
2793 C := First_Component (T);
2794 while Present (C) loop
2795 if Is_Limited_Type (Etype (C))
2796 and then
2797 (Comes_From_Source (C)
2798 or else
2799 (Present (Original_Record_Component (C))
2800 and then
2801 Comes_From_Source (Original_Record_Component (C))))
2802 then
2803 Error_Msg_Node_2 := T;
2804 Error_Msg_NE ("\component& of type& has limited type", N, C);
2805 Explain_Limited_Type (Etype (C), N);
2806 return;
2807 end if;
2809 Next_Component (C);
2810 end loop;
2812 -- The type may be declared explicitly limited, even if no component
2813 -- of it is limited, in which case we fall out of the loop.
2814 return;
2815 end if;
2816 end Explain_Limited_Type;
2818 -----------------
2819 -- Find_Actual --
2820 -----------------
2822 procedure Find_Actual
2823 (N : Node_Id;
2824 Formal : out Entity_Id;
2825 Call : out Node_Id)
2827 Parnt : constant Node_Id := Parent (N);
2828 Actual : Node_Id;
2830 begin
2831 if (Nkind (Parnt) = N_Indexed_Component
2832 or else
2833 Nkind (Parnt) = N_Selected_Component)
2834 and then N = Prefix (Parnt)
2835 then
2836 Find_Actual (Parnt, Formal, Call);
2837 return;
2839 elsif Nkind (Parnt) = N_Parameter_Association
2840 and then N = Explicit_Actual_Parameter (Parnt)
2841 then
2842 Call := Parent (Parnt);
2844 elsif Nkind (Parnt) = N_Procedure_Call_Statement then
2845 Call := Parnt;
2847 else
2848 Formal := Empty;
2849 Call := Empty;
2850 return;
2851 end if;
2853 -- If we have a call to a subprogram look for the parameter. Note that
2854 -- we exclude overloaded calls, since we don't know enough to be sure
2855 -- of giving the right answer in this case.
2857 if Is_Entity_Name (Name (Call))
2858 and then Present (Entity (Name (Call)))
2859 and then Is_Overloadable (Entity (Name (Call)))
2860 and then not Is_Overloaded (Name (Call))
2861 then
2862 -- Fall here if we are definitely a parameter
2864 Actual := First_Actual (Call);
2865 Formal := First_Formal (Entity (Name (Call)));
2866 while Present (Formal) and then Present (Actual) loop
2867 if Actual = N then
2868 return;
2869 else
2870 Actual := Next_Actual (Actual);
2871 Formal := Next_Formal (Formal);
2872 end if;
2873 end loop;
2874 end if;
2876 -- Fall through here if we did not find matching actual
2878 Formal := Empty;
2879 Call := Empty;
2880 end Find_Actual;
2882 -------------------------------------
2883 -- Find_Corresponding_Discriminant --
2884 -------------------------------------
2886 function Find_Corresponding_Discriminant
2887 (Id : Node_Id;
2888 Typ : Entity_Id) return Entity_Id
2890 Par_Disc : Entity_Id;
2891 Old_Disc : Entity_Id;
2892 New_Disc : Entity_Id;
2894 begin
2895 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
2897 -- The original type may currently be private, and the discriminant
2898 -- only appear on its full view.
2900 if Is_Private_Type (Scope (Par_Disc))
2901 and then not Has_Discriminants (Scope (Par_Disc))
2902 and then Present (Full_View (Scope (Par_Disc)))
2903 then
2904 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
2905 else
2906 Old_Disc := First_Discriminant (Scope (Par_Disc));
2907 end if;
2909 if Is_Class_Wide_Type (Typ) then
2910 New_Disc := First_Discriminant (Root_Type (Typ));
2911 else
2912 New_Disc := First_Discriminant (Typ);
2913 end if;
2915 while Present (Old_Disc) and then Present (New_Disc) loop
2916 if Old_Disc = Par_Disc then
2917 return New_Disc;
2918 else
2919 Next_Discriminant (Old_Disc);
2920 Next_Discriminant (New_Disc);
2921 end if;
2922 end loop;
2924 -- Should always find it
2926 raise Program_Error;
2927 end Find_Corresponding_Discriminant;
2929 --------------------------
2930 -- Find_Overlaid_Object --
2931 --------------------------
2933 function Find_Overlaid_Object (N : Node_Id) return Entity_Id is
2934 Expr : Node_Id;
2936 begin
2937 -- We are looking for one of the two following forms:
2939 -- for X'Address use Y'Address
2941 -- or
2943 -- Const : constant Address := expr;
2944 -- ...
2945 -- for X'Address use Const;
2947 -- In the second case, the expr is either Y'Address, or recursively a
2948 -- constant that eventually references Y'Address.
2950 if Nkind (N) = N_Attribute_Definition_Clause
2951 and then Chars (N) = Name_Address
2952 then
2953 -- This loop checks the form of the expression for Y'Address where Y
2954 -- is an object entity name. The first loop checks the original
2955 -- expression in the attribute definition clause. Subsequent loops
2956 -- check referenced constants.
2958 Expr := Expression (N);
2959 loop
2960 -- Check for Y'Address where Y is an object entity
2962 if Nkind (Expr) = N_Attribute_Reference
2963 and then Attribute_Name (Expr) = Name_Address
2964 and then Is_Entity_Name (Prefix (Expr))
2965 and then Is_Object (Entity (Prefix (Expr)))
2966 then
2967 return Entity (Prefix (Expr));
2969 -- Check for Const where Const is a constant entity
2971 elsif Is_Entity_Name (Expr)
2972 and then Ekind (Entity (Expr)) = E_Constant
2973 then
2974 Expr := Constant_Value (Entity (Expr));
2976 -- Anything else does not need checking
2978 else
2979 exit;
2980 end if;
2981 end loop;
2982 end if;
2984 return Empty;
2985 end Find_Overlaid_Object;
2987 --------------------------------------------
2988 -- Find_Overridden_Synchronized_Primitive --
2989 --------------------------------------------
2991 function Find_Overridden_Synchronized_Primitive
2992 (Def_Id : Entity_Id;
2993 First_Hom : Entity_Id;
2994 Ifaces_List : Elist_Id;
2995 In_Scope : Boolean) return Entity_Id
2997 Candidate : Entity_Id := Empty;
2998 Hom : Entity_Id := Empty;
2999 Iface_Typ : Entity_Id;
3000 Subp : Entity_Id := Empty;
3001 Tag_Typ : Entity_Id;
3003 function Has_Correct_Formal_Mode (Subp : Entity_Id) return Boolean;
3004 -- For an overridden subprogram Subp, check whether the mode of its
3005 -- first parameter is correct depending on the kind of Tag_Typ.
3007 function Matches_Prefixed_View_Profile
3008 (Prim_Params : List_Id;
3009 Iface_Params : List_Id) return Boolean;
3010 -- Determine whether a subprogram's parameter profile Prim_Params
3011 -- matches that of a potentially overridden interface subprogram
3012 -- Iface_Params. Also determine if the type of first parameter of
3013 -- Iface_Params is an implemented interface.
3015 -----------------------------
3016 -- Has_Correct_Formal_Mode --
3017 -----------------------------
3019 function Has_Correct_Formal_Mode (Subp : Entity_Id) return Boolean is
3020 Param : Node_Id;
3022 begin
3023 Param := First_Formal (Subp);
3025 -- In order for an entry or a protected procedure to override, the
3026 -- first parameter of the overridden routine must be of mode "out",
3027 -- "in out" or access-to-variable.
3029 if (Ekind (Subp) = E_Entry
3030 or else Ekind (Subp) = E_Procedure)
3031 and then Is_Protected_Type (Tag_Typ)
3032 and then Ekind (Param) /= E_In_Out_Parameter
3033 and then Ekind (Param) /= E_Out_Parameter
3034 and then Nkind (Parameter_Type (Parent (Param))) /=
3035 N_Access_Definition
3036 then
3037 return False;
3038 end if;
3040 -- All other cases are OK since a task entry or routine does not
3041 -- have a restriction on the mode of the first parameter of the
3042 -- overridden interface routine.
3044 return True;
3045 end Has_Correct_Formal_Mode;
3047 -----------------------------------
3048 -- Matches_Prefixed_View_Profile --
3049 -----------------------------------
3051 function Matches_Prefixed_View_Profile
3052 (Prim_Params : List_Id;
3053 Iface_Params : List_Id) return Boolean
3055 Iface_Id : Entity_Id;
3056 Iface_Param : Node_Id;
3057 Iface_Typ : Entity_Id;
3058 Prim_Id : Entity_Id;
3059 Prim_Param : Node_Id;
3060 Prim_Typ : Entity_Id;
3062 function Is_Implemented (Iface : Entity_Id) return Boolean;
3063 -- Determine if Iface is implemented by the current task or
3064 -- protected type.
3066 --------------------
3067 -- Is_Implemented --
3068 --------------------
3070 function Is_Implemented (Iface : Entity_Id) return Boolean is
3071 Iface_Elmt : Elmt_Id;
3073 begin
3074 Iface_Elmt := First_Elmt (Ifaces_List);
3075 while Present (Iface_Elmt) loop
3076 if Node (Iface_Elmt) = Iface then
3077 return True;
3078 end if;
3080 Next_Elmt (Iface_Elmt);
3081 end loop;
3083 return False;
3084 end Is_Implemented;
3086 -- Start of processing for Matches_Prefixed_View_Profile
3088 begin
3089 Iface_Param := First (Iface_Params);
3091 if Nkind (Parameter_Type (Iface_Param)) = N_Access_Definition then
3092 Iface_Typ :=
3093 Designated_Type (Etype (Defining_Identifier (Iface_Param)));
3094 else
3095 Iface_Typ := Etype (Defining_Identifier (Iface_Param));
3096 end if;
3098 Prim_Param := First (Prim_Params);
3100 -- The first parameter of the potentially overridden subprogram
3101 -- must be an interface implemented by Prim.
3103 if not Is_Interface (Iface_Typ)
3104 or else not Is_Implemented (Iface_Typ)
3105 then
3106 return False;
3107 end if;
3109 -- The checks on the object parameters are done, move onto the rest
3110 -- of the parameters.
3112 if not In_Scope then
3113 Prim_Param := Next (Prim_Param);
3114 end if;
3116 Iface_Param := Next (Iface_Param);
3117 while Present (Iface_Param) and then Present (Prim_Param) loop
3118 Iface_Id := Defining_Identifier (Iface_Param);
3119 Iface_Typ := Find_Parameter_Type (Iface_Param);
3120 Prim_Id := Defining_Identifier (Prim_Param);
3121 Prim_Typ := Find_Parameter_Type (Prim_Param);
3123 -- Case of multiple interface types inside a parameter profile
3125 -- (Obj_Param : in out Iface; ...; Param : Iface)
3127 -- If the interface type is implemented, then the matching type
3128 -- in the primitive should be the implementing record type.
3130 if Ekind (Iface_Typ) = E_Record_Type
3131 and then Is_Interface (Iface_Typ)
3132 and then Is_Implemented (Iface_Typ)
3133 then
3134 if Prim_Typ /= Tag_Typ then
3135 return False;
3136 end if;
3138 -- The two parameters must be both mode and subtype conformant
3140 elsif Ekind (Iface_Id) /= Ekind (Prim_Id)
3141 or else
3142 not Conforming_Types (Iface_Typ, Prim_Typ, Subtype_Conformant)
3143 then
3144 return False;
3145 end if;
3147 Next (Iface_Param);
3148 Next (Prim_Param);
3149 end loop;
3151 -- One of the two lists contains more parameters than the other
3153 if Present (Iface_Param) or else Present (Prim_Param) then
3154 return False;
3155 end if;
3157 return True;
3158 end Matches_Prefixed_View_Profile;
3160 -- Start of processing for Find_Overridden_Synchronized_Primitive
3162 begin
3163 -- At this point the caller should have collected the interfaces
3164 -- implemented by the synchronized type.
3166 pragma Assert (Present (Ifaces_List));
3168 -- Find the tagged type to which subprogram Def_Id is primitive. If the
3169 -- subprogram was declared within a protected or a task type, the type
3170 -- is the scope itself, otherwise it is the type of the first parameter.
3172 if In_Scope then
3173 Tag_Typ := Scope (Def_Id);
3175 elsif Present (First_Formal (Def_Id)) then
3176 Tag_Typ := Find_Parameter_Type (Parent (First_Formal (Def_Id)));
3178 -- A parameterless subprogram which is declared outside a synchronized
3179 -- type cannot act as a primitive, thus it cannot override anything.
3181 else
3182 return Empty;
3183 end if;
3185 -- Traverse the homonym chain, looking at a potentially overridden
3186 -- subprogram that belongs to an implemented interface.
3188 Hom := First_Hom;
3189 while Present (Hom) loop
3190 Subp := Hom;
3192 -- Entries can override abstract or null interface procedures
3194 if Ekind (Def_Id) = E_Entry
3195 and then Ekind (Subp) = E_Procedure
3196 and then Nkind (Parent (Subp)) = N_Procedure_Specification
3197 and then (Is_Abstract_Subprogram (Subp)
3198 or else Null_Present (Parent (Subp)))
3199 then
3200 while Present (Alias (Subp)) loop
3201 Subp := Alias (Subp);
3202 end loop;
3204 if Matches_Prefixed_View_Profile
3205 (Parameter_Specifications (Parent (Def_Id)),
3206 Parameter_Specifications (Parent (Subp)))
3207 then
3208 Candidate := Subp;
3210 -- Absolute match
3212 if Has_Correct_Formal_Mode (Candidate) then
3213 return Candidate;
3214 end if;
3215 end if;
3217 -- Procedures can override abstract or null interface procedures
3219 elsif Ekind (Def_Id) = E_Procedure
3220 and then Ekind (Subp) = E_Procedure
3221 and then Nkind (Parent (Subp)) = N_Procedure_Specification
3222 and then (Is_Abstract_Subprogram (Subp)
3223 or else Null_Present (Parent (Subp)))
3224 and then Matches_Prefixed_View_Profile
3225 (Parameter_Specifications (Parent (Def_Id)),
3226 Parameter_Specifications (Parent (Subp)))
3227 then
3228 Candidate := Subp;
3230 -- Absolute match
3232 if Has_Correct_Formal_Mode (Candidate) then
3233 return Candidate;
3234 end if;
3236 -- Functions can override abstract interface functions
3238 elsif Ekind (Def_Id) = E_Function
3239 and then Ekind (Subp) = E_Function
3240 and then Nkind (Parent (Subp)) = N_Function_Specification
3241 and then Is_Abstract_Subprogram (Subp)
3242 and then Matches_Prefixed_View_Profile
3243 (Parameter_Specifications (Parent (Def_Id)),
3244 Parameter_Specifications (Parent (Subp)))
3245 and then Etype (Result_Definition (Parent (Def_Id))) =
3246 Etype (Result_Definition (Parent (Subp)))
3247 then
3248 return Subp;
3249 end if;
3251 Hom := Homonym (Hom);
3252 end loop;
3254 -- After examining all candidates for overriding, we are left with
3255 -- the best match which is a mode incompatible interface routine.
3256 -- Do not emit an error if the Expander is active since this error
3257 -- will be detected later on after all concurrent types are expanded
3258 -- and all wrappers are built. This check is meant for spec-only
3259 -- compilations.
3261 if Present (Candidate)
3262 and then not Expander_Active
3263 then
3264 Iface_Typ := Find_Parameter_Type (Parent (First_Formal (Candidate)));
3266 -- Def_Id is primitive of a protected type, declared inside the type,
3267 -- and the candidate is primitive of a limited or synchronized
3268 -- interface.
3270 if In_Scope
3271 and then Is_Protected_Type (Tag_Typ)
3272 and then
3273 (Is_Limited_Interface (Iface_Typ)
3274 or else Is_Protected_Interface (Iface_Typ)
3275 or else Is_Synchronized_Interface (Iface_Typ)
3276 or else Is_Task_Interface (Iface_Typ))
3277 then
3278 -- Must reword this message, comma before to in -gnatj mode ???
3280 Error_Msg_NE
3281 ("first formal of & must be of mode `OUT`, `IN OUT` or " &
3282 "access-to-variable", Tag_Typ, Candidate);
3283 Error_Msg_N
3284 ("\to be overridden by protected procedure or entry " &
3285 "(RM 9.4(11.9/2))", Tag_Typ);
3286 end if;
3287 end if;
3289 return Candidate;
3290 end Find_Overridden_Synchronized_Primitive;
3292 -------------------------
3293 -- Find_Parameter_Type --
3294 -------------------------
3296 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
3297 begin
3298 if Nkind (Param) /= N_Parameter_Specification then
3299 return Empty;
3301 -- For an access parameter, obtain the type from the formal entity
3302 -- itself, because access to subprogram nodes do not carry a type.
3303 -- Shouldn't we always use the formal entity ???
3305 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
3306 return Etype (Defining_Identifier (Param));
3308 else
3309 return Etype (Parameter_Type (Param));
3310 end if;
3311 end Find_Parameter_Type;
3313 -----------------------------
3314 -- Find_Static_Alternative --
3315 -----------------------------
3317 function Find_Static_Alternative (N : Node_Id) return Node_Id is
3318 Expr : constant Node_Id := Expression (N);
3319 Val : constant Uint := Expr_Value (Expr);
3320 Alt : Node_Id;
3321 Choice : Node_Id;
3323 begin
3324 Alt := First (Alternatives (N));
3326 Search : loop
3327 if Nkind (Alt) /= N_Pragma then
3328 Choice := First (Discrete_Choices (Alt));
3329 while Present (Choice) loop
3331 -- Others choice, always matches
3333 if Nkind (Choice) = N_Others_Choice then
3334 exit Search;
3336 -- Range, check if value is in the range
3338 elsif Nkind (Choice) = N_Range then
3339 exit Search when
3340 Val >= Expr_Value (Low_Bound (Choice))
3341 and then
3342 Val <= Expr_Value (High_Bound (Choice));
3344 -- Choice is a subtype name. Note that we know it must
3345 -- be a static subtype, since otherwise it would have
3346 -- been diagnosed as illegal.
3348 elsif Is_Entity_Name (Choice)
3349 and then Is_Type (Entity (Choice))
3350 then
3351 exit Search when Is_In_Range (Expr, Etype (Choice));
3353 -- Choice is a subtype indication
3355 elsif Nkind (Choice) = N_Subtype_Indication then
3356 declare
3357 C : constant Node_Id := Constraint (Choice);
3358 R : constant Node_Id := Range_Expression (C);
3360 begin
3361 exit Search when
3362 Val >= Expr_Value (Low_Bound (R))
3363 and then
3364 Val <= Expr_Value (High_Bound (R));
3365 end;
3367 -- Choice is a simple expression
3369 else
3370 exit Search when Val = Expr_Value (Choice);
3371 end if;
3373 Next (Choice);
3374 end loop;
3375 end if;
3377 Next (Alt);
3378 pragma Assert (Present (Alt));
3379 end loop Search;
3381 -- The above loop *must* terminate by finding a match, since
3382 -- we know the case statement is valid, and the value of the
3383 -- expression is known at compile time. When we fall out of
3384 -- the loop, Alt points to the alternative that we know will
3385 -- be selected at run time.
3387 return Alt;
3388 end Find_Static_Alternative;
3390 ------------------
3391 -- First_Actual --
3392 ------------------
3394 function First_Actual (Node : Node_Id) return Node_Id is
3395 N : Node_Id;
3397 begin
3398 if No (Parameter_Associations (Node)) then
3399 return Empty;
3400 end if;
3402 N := First (Parameter_Associations (Node));
3404 if Nkind (N) = N_Parameter_Association then
3405 return First_Named_Actual (Node);
3406 else
3407 return N;
3408 end if;
3409 end First_Actual;
3411 -------------------------
3412 -- Full_Qualified_Name --
3413 -------------------------
3415 function Full_Qualified_Name (E : Entity_Id) return String_Id is
3416 Res : String_Id;
3417 pragma Warnings (Off, Res);
3419 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id;
3420 -- Compute recursively the qualified name without NUL at the end
3422 ----------------------------------
3423 -- Internal_Full_Qualified_Name --
3424 ----------------------------------
3426 function Internal_Full_Qualified_Name (E : Entity_Id) return String_Id is
3427 Ent : Entity_Id := E;
3428 Parent_Name : String_Id := No_String;
3430 begin
3431 -- Deals properly with child units
3433 if Nkind (Ent) = N_Defining_Program_Unit_Name then
3434 Ent := Defining_Identifier (Ent);
3435 end if;
3437 -- Compute qualification recursively (only "Standard" has no scope)
3439 if Present (Scope (Scope (Ent))) then
3440 Parent_Name := Internal_Full_Qualified_Name (Scope (Ent));
3441 end if;
3443 -- Every entity should have a name except some expanded blocks
3444 -- don't bother about those.
3446 if Chars (Ent) = No_Name then
3447 return Parent_Name;
3448 end if;
3450 -- Add a period between Name and qualification
3452 if Parent_Name /= No_String then
3453 Start_String (Parent_Name);
3454 Store_String_Char (Get_Char_Code ('.'));
3456 else
3457 Start_String;
3458 end if;
3460 -- Generates the entity name in upper case
3462 Get_Decoded_Name_String (Chars (Ent));
3463 Set_All_Upper_Case;
3464 Store_String_Chars (Name_Buffer (1 .. Name_Len));
3465 return End_String;
3466 end Internal_Full_Qualified_Name;
3468 -- Start of processing for Full_Qualified_Name
3470 begin
3471 Res := Internal_Full_Qualified_Name (E);
3472 Store_String_Char (Get_Char_Code (ASCII.NUL));
3473 return End_String;
3474 end Full_Qualified_Name;
3476 -----------------------
3477 -- Gather_Components --
3478 -----------------------
3480 procedure Gather_Components
3481 (Typ : Entity_Id;
3482 Comp_List : Node_Id;
3483 Governed_By : List_Id;
3484 Into : Elist_Id;
3485 Report_Errors : out Boolean)
3487 Assoc : Node_Id;
3488 Variant : Node_Id;
3489 Discrete_Choice : Node_Id;
3490 Comp_Item : Node_Id;
3492 Discrim : Entity_Id;
3493 Discrim_Name : Node_Id;
3494 Discrim_Value : Node_Id;
3496 begin
3497 Report_Errors := False;
3499 if No (Comp_List) or else Null_Present (Comp_List) then
3500 return;
3502 elsif Present (Component_Items (Comp_List)) then
3503 Comp_Item := First (Component_Items (Comp_List));
3505 else
3506 Comp_Item := Empty;
3507 end if;
3509 while Present (Comp_Item) loop
3511 -- Skip the tag of a tagged record, the interface tags, as well
3512 -- as all items that are not user components (anonymous types,
3513 -- rep clauses, Parent field, controller field).
3515 if Nkind (Comp_Item) = N_Component_Declaration then
3516 declare
3517 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
3518 begin
3519 if not Is_Tag (Comp)
3520 and then Chars (Comp) /= Name_uParent
3521 and then Chars (Comp) /= Name_uController
3522 then
3523 Append_Elmt (Comp, Into);
3524 end if;
3525 end;
3526 end if;
3528 Next (Comp_Item);
3529 end loop;
3531 if No (Variant_Part (Comp_List)) then
3532 return;
3533 else
3534 Discrim_Name := Name (Variant_Part (Comp_List));
3535 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
3536 end if;
3538 -- Look for the discriminant that governs this variant part.
3539 -- The discriminant *must* be in the Governed_By List
3541 Assoc := First (Governed_By);
3542 Find_Constraint : loop
3543 Discrim := First (Choices (Assoc));
3544 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
3545 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
3546 and then
3547 Chars (Corresponding_Discriminant (Entity (Discrim)))
3548 = Chars (Discrim_Name))
3549 or else Chars (Original_Record_Component (Entity (Discrim)))
3550 = Chars (Discrim_Name);
3552 if No (Next (Assoc)) then
3553 if not Is_Constrained (Typ)
3554 and then Is_Derived_Type (Typ)
3555 and then Present (Stored_Constraint (Typ))
3556 then
3557 -- If the type is a tagged type with inherited discriminants,
3558 -- use the stored constraint on the parent in order to find
3559 -- the values of discriminants that are otherwise hidden by an
3560 -- explicit constraint. Renamed discriminants are handled in
3561 -- the code above.
3563 -- If several parent discriminants are renamed by a single
3564 -- discriminant of the derived type, the call to obtain the
3565 -- Corresponding_Discriminant field only retrieves the last
3566 -- of them. We recover the constraint on the others from the
3567 -- Stored_Constraint as well.
3569 declare
3570 D : Entity_Id;
3571 C : Elmt_Id;
3573 begin
3574 D := First_Discriminant (Etype (Typ));
3575 C := First_Elmt (Stored_Constraint (Typ));
3576 while Present (D) and then Present (C) loop
3577 if Chars (Discrim_Name) = Chars (D) then
3578 if Is_Entity_Name (Node (C))
3579 and then Entity (Node (C)) = Entity (Discrim)
3580 then
3581 -- D is renamed by Discrim, whose value is given in
3582 -- Assoc.
3584 null;
3586 else
3587 Assoc :=
3588 Make_Component_Association (Sloc (Typ),
3589 New_List
3590 (New_Occurrence_Of (D, Sloc (Typ))),
3591 Duplicate_Subexpr_No_Checks (Node (C)));
3592 end if;
3593 exit Find_Constraint;
3594 end if;
3596 Next_Discriminant (D);
3597 Next_Elmt (C);
3598 end loop;
3599 end;
3600 end if;
3601 end if;
3603 if No (Next (Assoc)) then
3604 Error_Msg_NE (" missing value for discriminant&",
3605 First (Governed_By), Discrim_Name);
3606 Report_Errors := True;
3607 return;
3608 end if;
3610 Next (Assoc);
3611 end loop Find_Constraint;
3613 Discrim_Value := Expression (Assoc);
3615 if not Is_OK_Static_Expression (Discrim_Value) then
3616 Error_Msg_FE
3617 ("value for discriminant & must be static!",
3618 Discrim_Value, Discrim);
3619 Why_Not_Static (Discrim_Value);
3620 Report_Errors := True;
3621 return;
3622 end if;
3624 Search_For_Discriminant_Value : declare
3625 Low : Node_Id;
3626 High : Node_Id;
3628 UI_High : Uint;
3629 UI_Low : Uint;
3630 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
3632 begin
3633 Find_Discrete_Value : while Present (Variant) loop
3634 Discrete_Choice := First (Discrete_Choices (Variant));
3635 while Present (Discrete_Choice) loop
3637 exit Find_Discrete_Value when
3638 Nkind (Discrete_Choice) = N_Others_Choice;
3640 Get_Index_Bounds (Discrete_Choice, Low, High);
3642 UI_Low := Expr_Value (Low);
3643 UI_High := Expr_Value (High);
3645 exit Find_Discrete_Value when
3646 UI_Low <= UI_Discrim_Value
3647 and then
3648 UI_High >= UI_Discrim_Value;
3650 Next (Discrete_Choice);
3651 end loop;
3653 Next_Non_Pragma (Variant);
3654 end loop Find_Discrete_Value;
3655 end Search_For_Discriminant_Value;
3657 if No (Variant) then
3658 Error_Msg_NE
3659 ("value of discriminant & is out of range", Discrim_Value, Discrim);
3660 Report_Errors := True;
3661 return;
3662 end if;
3664 -- If we have found the corresponding choice, recursively add its
3665 -- components to the Into list.
3667 Gather_Components (Empty,
3668 Component_List (Variant), Governed_By, Into, Report_Errors);
3669 end Gather_Components;
3671 ------------------------
3672 -- Get_Actual_Subtype --
3673 ------------------------
3675 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
3676 Typ : constant Entity_Id := Etype (N);
3677 Utyp : Entity_Id := Underlying_Type (Typ);
3678 Decl : Node_Id;
3679 Atyp : Entity_Id;
3681 begin
3682 if No (Utyp) then
3683 Utyp := Typ;
3684 end if;
3686 -- If what we have is an identifier that references a subprogram
3687 -- formal, or a variable or constant object, then we get the actual
3688 -- subtype from the referenced entity if one has been built.
3690 if Nkind (N) = N_Identifier
3691 and then
3692 (Is_Formal (Entity (N))
3693 or else Ekind (Entity (N)) = E_Constant
3694 or else Ekind (Entity (N)) = E_Variable)
3695 and then Present (Actual_Subtype (Entity (N)))
3696 then
3697 return Actual_Subtype (Entity (N));
3699 -- Actual subtype of unchecked union is always itself. We never need
3700 -- the "real" actual subtype. If we did, we couldn't get it anyway
3701 -- because the discriminant is not available. The restrictions on
3702 -- Unchecked_Union are designed to make sure that this is OK.
3704 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
3705 return Typ;
3707 -- Here for the unconstrained case, we must find actual subtype
3708 -- No actual subtype is available, so we must build it on the fly.
3710 -- Checking the type, not the underlying type, for constrainedness
3711 -- seems to be necessary. Maybe all the tests should be on the type???
3713 elsif (not Is_Constrained (Typ))
3714 and then (Is_Array_Type (Utyp)
3715 or else (Is_Record_Type (Utyp)
3716 and then Has_Discriminants (Utyp)))
3717 and then not Has_Unknown_Discriminants (Utyp)
3718 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
3719 then
3720 -- Nothing to do if in spec expression (why not???)
3722 if In_Spec_Expression then
3723 return Typ;
3725 elsif Is_Private_Type (Typ)
3726 and then not Has_Discriminants (Typ)
3727 then
3728 -- If the type has no discriminants, there is no subtype to
3729 -- build, even if the underlying type is discriminated.
3731 return Typ;
3733 -- Else build the actual subtype
3735 else
3736 Decl := Build_Actual_Subtype (Typ, N);
3737 Atyp := Defining_Identifier (Decl);
3739 -- If Build_Actual_Subtype generated a new declaration then use it
3741 if Atyp /= Typ then
3743 -- The actual subtype is an Itype, so analyze the declaration,
3744 -- but do not attach it to the tree, to get the type defined.
3746 Set_Parent (Decl, N);
3747 Set_Is_Itype (Atyp);
3748 Analyze (Decl, Suppress => All_Checks);
3749 Set_Associated_Node_For_Itype (Atyp, N);
3750 Set_Has_Delayed_Freeze (Atyp, False);
3752 -- We need to freeze the actual subtype immediately. This is
3753 -- needed, because otherwise this Itype will not get frozen
3754 -- at all, and it is always safe to freeze on creation because
3755 -- any associated types must be frozen at this point.
3757 Freeze_Itype (Atyp, N);
3758 return Atyp;
3760 -- Otherwise we did not build a declaration, so return original
3762 else
3763 return Typ;
3764 end if;
3765 end if;
3767 -- For all remaining cases, the actual subtype is the same as
3768 -- the nominal type.
3770 else
3771 return Typ;
3772 end if;
3773 end Get_Actual_Subtype;
3775 -------------------------------------
3776 -- Get_Actual_Subtype_If_Available --
3777 -------------------------------------
3779 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
3780 Typ : constant Entity_Id := Etype (N);
3782 begin
3783 -- If what we have is an identifier that references a subprogram
3784 -- formal, or a variable or constant object, then we get the actual
3785 -- subtype from the referenced entity if one has been built.
3787 if Nkind (N) = N_Identifier
3788 and then
3789 (Is_Formal (Entity (N))
3790 or else Ekind (Entity (N)) = E_Constant
3791 or else Ekind (Entity (N)) = E_Variable)
3792 and then Present (Actual_Subtype (Entity (N)))
3793 then
3794 return Actual_Subtype (Entity (N));
3796 -- Otherwise the Etype of N is returned unchanged
3798 else
3799 return Typ;
3800 end if;
3801 end Get_Actual_Subtype_If_Available;
3803 -------------------------------
3804 -- Get_Default_External_Name --
3805 -------------------------------
3807 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
3808 begin
3809 Get_Decoded_Name_String (Chars (E));
3811 if Opt.External_Name_Imp_Casing = Uppercase then
3812 Set_Casing (All_Upper_Case);
3813 else
3814 Set_Casing (All_Lower_Case);
3815 end if;
3817 return
3818 Make_String_Literal (Sloc (E),
3819 Strval => String_From_Name_Buffer);
3820 end Get_Default_External_Name;
3822 ---------------------------
3823 -- Get_Enum_Lit_From_Pos --
3824 ---------------------------
3826 function Get_Enum_Lit_From_Pos
3827 (T : Entity_Id;
3828 Pos : Uint;
3829 Loc : Source_Ptr) return Node_Id
3831 Lit : Node_Id;
3833 begin
3834 -- In the case where the literal is of type Character, Wide_Character
3835 -- or Wide_Wide_Character or of a type derived from them, there needs
3836 -- to be some special handling since there is no explicit chain of
3837 -- literals to search. Instead, an N_Character_Literal node is created
3838 -- with the appropriate Char_Code and Chars fields.
3840 if Is_Standard_Character_Type (T) then
3841 Set_Character_Literal_Name (UI_To_CC (Pos));
3842 return
3843 Make_Character_Literal (Loc,
3844 Chars => Name_Find,
3845 Char_Literal_Value => Pos);
3847 -- For all other cases, we have a complete table of literals, and
3848 -- we simply iterate through the chain of literal until the one
3849 -- with the desired position value is found.
3852 else
3853 Lit := First_Literal (Base_Type (T));
3854 for J in 1 .. UI_To_Int (Pos) loop
3855 Next_Literal (Lit);
3856 end loop;
3858 return New_Occurrence_Of (Lit, Loc);
3859 end if;
3860 end Get_Enum_Lit_From_Pos;
3862 ------------------------
3863 -- Get_Generic_Entity --
3864 ------------------------
3866 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
3867 Ent : constant Entity_Id := Entity (Name (N));
3868 begin
3869 if Present (Renamed_Object (Ent)) then
3870 return Renamed_Object (Ent);
3871 else
3872 return Ent;
3873 end if;
3874 end Get_Generic_Entity;
3876 ----------------------
3877 -- Get_Index_Bounds --
3878 ----------------------
3880 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
3881 Kind : constant Node_Kind := Nkind (N);
3882 R : Node_Id;
3884 begin
3885 if Kind = N_Range then
3886 L := Low_Bound (N);
3887 H := High_Bound (N);
3889 elsif Kind = N_Subtype_Indication then
3890 R := Range_Expression (Constraint (N));
3892 if R = Error then
3893 L := Error;
3894 H := Error;
3895 return;
3897 else
3898 L := Low_Bound (Range_Expression (Constraint (N)));
3899 H := High_Bound (Range_Expression (Constraint (N)));
3900 end if;
3902 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
3903 if Error_Posted (Scalar_Range (Entity (N))) then
3904 L := Error;
3905 H := Error;
3907 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
3908 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
3910 else
3911 L := Low_Bound (Scalar_Range (Entity (N)));
3912 H := High_Bound (Scalar_Range (Entity (N)));
3913 end if;
3915 else
3916 -- N is an expression, indicating a range with one value
3918 L := N;
3919 H := N;
3920 end if;
3921 end Get_Index_Bounds;
3923 ----------------------------------
3924 -- Get_Library_Unit_Name_string --
3925 ----------------------------------
3927 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
3928 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
3930 begin
3931 Get_Unit_Name_String (Unit_Name_Id);
3933 -- Remove seven last character (" (spec)" or " (body)")
3935 Name_Len := Name_Len - 7;
3936 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
3937 end Get_Library_Unit_Name_String;
3939 ------------------------
3940 -- Get_Name_Entity_Id --
3941 ------------------------
3943 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
3944 begin
3945 return Entity_Id (Get_Name_Table_Info (Id));
3946 end Get_Name_Entity_Id;
3948 -------------------
3949 -- Get_Pragma_Id --
3950 -------------------
3952 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
3953 begin
3954 return Get_Pragma_Id (Pragma_Name (N));
3955 end Get_Pragma_Id;
3957 ---------------------------
3958 -- Get_Referenced_Object --
3959 ---------------------------
3961 function Get_Referenced_Object (N : Node_Id) return Node_Id is
3962 R : Node_Id;
3964 begin
3965 R := N;
3966 while Is_Entity_Name (R)
3967 and then Present (Renamed_Object (Entity (R)))
3968 loop
3969 R := Renamed_Object (Entity (R));
3970 end loop;
3972 return R;
3973 end Get_Referenced_Object;
3975 ------------------------
3976 -- Get_Renamed_Entity --
3977 ------------------------
3979 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
3980 R : Entity_Id;
3982 begin
3983 R := E;
3984 while Present (Renamed_Entity (R)) loop
3985 R := Renamed_Entity (R);
3986 end loop;
3988 return R;
3989 end Get_Renamed_Entity;
3991 -------------------------
3992 -- Get_Subprogram_Body --
3993 -------------------------
3995 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
3996 Decl : Node_Id;
3998 begin
3999 Decl := Unit_Declaration_Node (E);
4001 if Nkind (Decl) = N_Subprogram_Body then
4002 return Decl;
4004 -- The below comment is bad, because it is possible for
4005 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
4007 else -- Nkind (Decl) = N_Subprogram_Declaration
4009 if Present (Corresponding_Body (Decl)) then
4010 return Unit_Declaration_Node (Corresponding_Body (Decl));
4012 -- Imported subprogram case
4014 else
4015 return Empty;
4016 end if;
4017 end if;
4018 end Get_Subprogram_Body;
4020 ---------------------------
4021 -- Get_Subprogram_Entity --
4022 ---------------------------
4024 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
4025 Nam : Node_Id;
4026 Proc : Entity_Id;
4028 begin
4029 if Nkind (Nod) = N_Accept_Statement then
4030 Nam := Entry_Direct_Name (Nod);
4032 -- For an entry call, the prefix of the call is a selected component.
4033 -- Need additional code for internal calls ???
4035 elsif Nkind (Nod) = N_Entry_Call_Statement then
4036 if Nkind (Name (Nod)) = N_Selected_Component then
4037 Nam := Entity (Selector_Name (Name (Nod)));
4038 else
4039 Nam := Empty;
4040 end if;
4042 else
4043 Nam := Name (Nod);
4044 end if;
4046 if Nkind (Nam) = N_Explicit_Dereference then
4047 Proc := Etype (Prefix (Nam));
4048 elsif Is_Entity_Name (Nam) then
4049 Proc := Entity (Nam);
4050 else
4051 return Empty;
4052 end if;
4054 if Is_Object (Proc) then
4055 Proc := Etype (Proc);
4056 end if;
4058 if Ekind (Proc) = E_Access_Subprogram_Type then
4059 Proc := Directly_Designated_Type (Proc);
4060 end if;
4062 if not Is_Subprogram (Proc)
4063 and then Ekind (Proc) /= E_Subprogram_Type
4064 then
4065 return Empty;
4066 else
4067 return Proc;
4068 end if;
4069 end Get_Subprogram_Entity;
4071 -----------------------------
4072 -- Get_Task_Body_Procedure --
4073 -----------------------------
4075 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
4076 begin
4077 -- Note: A task type may be the completion of a private type with
4078 -- discriminants. When performing elaboration checks on a task
4079 -- declaration, the current view of the type may be the private one,
4080 -- and the procedure that holds the body of the task is held in its
4081 -- underlying type.
4083 -- This is an odd function, why not have Task_Body_Procedure do
4084 -- the following digging???
4086 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
4087 end Get_Task_Body_Procedure;
4089 -----------------------------
4090 -- Has_Abstract_Interfaces --
4091 -----------------------------
4093 function Has_Abstract_Interfaces
4094 (T : Entity_Id;
4095 Use_Full_View : Boolean := True) return Boolean
4097 Typ : Entity_Id;
4099 begin
4100 -- Handle concurrent types
4102 if Is_Concurrent_Type (T) then
4103 Typ := Corresponding_Record_Type (T);
4104 else
4105 Typ := T;
4106 end if;
4108 if not Present (Typ)
4109 or else not Is_Tagged_Type (Typ)
4110 then
4111 return False;
4112 end if;
4114 pragma Assert (Is_Record_Type (Typ));
4116 -- Handle private types
4118 if Use_Full_View
4119 and then Present (Full_View (Typ))
4120 then
4121 Typ := Full_View (Typ);
4122 end if;
4124 -- Handle concurrent record types
4126 if Is_Concurrent_Record_Type (Typ)
4127 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
4128 then
4129 return True;
4130 end if;
4132 loop
4133 if Is_Interface (Typ)
4134 or else
4135 (Is_Record_Type (Typ)
4136 and then Present (Abstract_Interfaces (Typ))
4137 and then not Is_Empty_Elmt_List (Abstract_Interfaces (Typ)))
4138 then
4139 return True;
4140 end if;
4142 exit when Etype (Typ) = Typ
4144 -- Handle private types
4146 or else (Present (Full_View (Etype (Typ)))
4147 and then Full_View (Etype (Typ)) = Typ)
4149 -- Protect the frontend against wrong source with cyclic
4150 -- derivations
4152 or else Etype (Typ) = T;
4154 -- Climb to the ancestor type handling private types
4156 if Present (Full_View (Etype (Typ))) then
4157 Typ := Full_View (Etype (Typ));
4158 else
4159 Typ := Etype (Typ);
4160 end if;
4161 end loop;
4163 return False;
4164 end Has_Abstract_Interfaces;
4166 -----------------------
4167 -- Has_Access_Values --
4168 -----------------------
4170 function Has_Access_Values (T : Entity_Id) return Boolean is
4171 Typ : constant Entity_Id := Underlying_Type (T);
4173 begin
4174 -- Case of a private type which is not completed yet. This can only
4175 -- happen in the case of a generic format type appearing directly, or
4176 -- as a component of the type to which this function is being applied
4177 -- at the top level. Return False in this case, since we certainly do
4178 -- not know that the type contains access types.
4180 if No (Typ) then
4181 return False;
4183 elsif Is_Access_Type (Typ) then
4184 return True;
4186 elsif Is_Array_Type (Typ) then
4187 return Has_Access_Values (Component_Type (Typ));
4189 elsif Is_Record_Type (Typ) then
4190 declare
4191 Comp : Entity_Id;
4193 begin
4194 -- Loop to Check components
4196 Comp := First_Component_Or_Discriminant (Typ);
4197 while Present (Comp) loop
4199 -- Check for access component, tag field does not count, even
4200 -- though it is implemented internally using an access type.
4202 if Has_Access_Values (Etype (Comp))
4203 and then Chars (Comp) /= Name_uTag
4204 then
4205 return True;
4206 end if;
4208 Next_Component_Or_Discriminant (Comp);
4209 end loop;
4210 end;
4212 return False;
4214 else
4215 return False;
4216 end if;
4217 end Has_Access_Values;
4219 ------------------------------
4220 -- Has_Compatible_Alignment --
4221 ------------------------------
4223 function Has_Compatible_Alignment
4224 (Obj : Entity_Id;
4225 Expr : Node_Id) return Alignment_Result
4227 function Has_Compatible_Alignment_Internal
4228 (Obj : Entity_Id;
4229 Expr : Node_Id;
4230 Default : Alignment_Result) return Alignment_Result;
4231 -- This is the internal recursive function that actually does the work.
4232 -- There is one additional parameter, which says what the result should
4233 -- be if no alignment information is found, and there is no definite
4234 -- indication of compatible alignments. At the outer level, this is set
4235 -- to Unknown, but for internal recursive calls in the case where types
4236 -- are known to be correct, it is set to Known_Compatible.
4238 ---------------------------------------
4239 -- Has_Compatible_Alignment_Internal --
4240 ---------------------------------------
4242 function Has_Compatible_Alignment_Internal
4243 (Obj : Entity_Id;
4244 Expr : Node_Id;
4245 Default : Alignment_Result) return Alignment_Result
4247 Result : Alignment_Result := Known_Compatible;
4248 -- Set to result if Problem_Prefix or Problem_Offset returns True.
4249 -- Note that once a value of Known_Incompatible is set, it is sticky
4250 -- and does not get changed to Unknown (the value in Result only gets
4251 -- worse as we go along, never better).
4253 procedure Check_Offset (Offs : Uint);
4254 -- Called when Expr is a selected or indexed component with Offs set
4255 -- to resp Component_First_Bit or Component_Size. Checks that if the
4256 -- offset is specified it is compatible with the object alignment
4257 -- requirements. The value in Result is modified accordingly.
4259 procedure Check_Prefix;
4260 -- Checks the prefix recursively in the case where the expression
4261 -- is an indexed or selected component.
4263 procedure Set_Result (R : Alignment_Result);
4264 -- If R represents a worse outcome (unknown instead of known
4265 -- compatible, or known incompatible), then set Result to R.
4267 ------------------
4268 -- Check_Offset --
4269 ------------------
4271 procedure Check_Offset (Offs : Uint) is
4272 begin
4273 -- Unspecified or zero offset is always OK
4275 if Offs = No_Uint or else Offs = Uint_0 then
4276 null;
4278 -- If we do not know required alignment, any non-zero offset is
4279 -- a potential problem (but certainly may be OK, so result is
4280 -- unknown).
4282 elsif Unknown_Alignment (Obj) then
4283 Set_Result (Unknown);
4285 -- If we know the required alignment, see if offset is compatible
4287 else
4288 if Offs mod (System_Storage_Unit * Alignment (Obj)) /= 0 then
4289 Set_Result (Known_Incompatible);
4290 end if;
4291 end if;
4292 end Check_Offset;
4294 ------------------
4295 -- Check_Prefix --
4296 ------------------
4298 procedure Check_Prefix is
4299 begin
4300 -- The subtlety here is that in doing a recursive call to check
4301 -- the prefix, we have to decide what to do in the case where we
4302 -- don't find any specific indication of an alignment problem.
4304 -- At the outer level, we normally set Unknown as the result in
4305 -- this case, since we can only set Known_Compatible if we really
4306 -- know that the alignment value is OK, but for the recursive
4307 -- call, in the case where the types match, and we have not
4308 -- specified a peculiar alignment for the object, we are only
4309 -- concerned about suspicious rep clauses, the default case does
4310 -- not affect us, since the compiler will, in the absence of such
4311 -- rep clauses, ensure that the alignment is correct.
4313 if Default = Known_Compatible
4314 or else
4315 (Etype (Obj) = Etype (Expr)
4316 and then (Unknown_Alignment (Obj)
4317 or else
4318 Alignment (Obj) = Alignment (Etype (Obj))))
4319 then
4320 Set_Result
4321 (Has_Compatible_Alignment_Internal
4322 (Obj, Prefix (Expr), Known_Compatible));
4324 -- In all other cases, we need a full check on the prefix
4326 else
4327 Set_Result
4328 (Has_Compatible_Alignment_Internal
4329 (Obj, Prefix (Expr), Unknown));
4330 end if;
4331 end Check_Prefix;
4333 ----------------
4334 -- Set_Result --
4335 ----------------
4337 procedure Set_Result (R : Alignment_Result) is
4338 begin
4339 if R > Result then
4340 Result := R;
4341 end if;
4342 end Set_Result;
4344 -- Start of processing for Has_Compatible_Alignment_Internal
4346 begin
4347 -- If Expr is a selected component, we must make sure there is no
4348 -- potentially troublesome component clause, and that the record is
4349 -- not packed.
4351 if Nkind (Expr) = N_Selected_Component then
4353 -- Packed record always generate unknown alignment
4355 if Is_Packed (Etype (Prefix (Expr))) then
4356 Set_Result (Unknown);
4357 end if;
4359 -- Check possible bad component offset and check prefix
4361 Check_Offset
4362 (Component_Bit_Offset (Entity (Selector_Name (Expr))));
4363 Check_Prefix;
4365 -- If Expr is an indexed component, we must make sure there is no
4366 -- potentially troublesome Component_Size clause and that the array
4367 -- is not bit-packed.
4369 elsif Nkind (Expr) = N_Indexed_Component then
4371 -- Bit packed array always generates unknown alignment
4373 if Is_Bit_Packed_Array (Etype (Prefix (Expr))) then
4374 Set_Result (Unknown);
4375 end if;
4377 -- Check possible bad component size and check prefix
4379 Check_Offset (Component_Size (Etype (Prefix (Expr))));
4380 Check_Prefix;
4381 end if;
4383 -- Case where we know the alignment of the object
4385 if Known_Alignment (Obj) then
4386 declare
4387 ObjA : constant Uint := Alignment (Obj);
4388 ExpA : Uint := No_Uint;
4389 SizA : Uint := No_Uint;
4391 begin
4392 -- If alignment of Obj is 1, then we are always OK
4394 if ObjA = 1 then
4395 Set_Result (Known_Compatible);
4397 -- Alignment of Obj is greater than 1, so we need to check
4399 else
4400 -- See if Expr is an object with known alignment
4402 if Is_Entity_Name (Expr)
4403 and then Known_Alignment (Entity (Expr))
4404 then
4405 ExpA := Alignment (Entity (Expr));
4407 -- Otherwise, we can use the alignment of the type of
4408 -- Expr given that we already checked for
4409 -- discombobulating rep clauses for the cases of indexed
4410 -- and selected components above.
4412 elsif Known_Alignment (Etype (Expr)) then
4413 ExpA := Alignment (Etype (Expr));
4414 end if;
4416 -- If we got an alignment, see if it is acceptable
4418 if ExpA /= No_Uint then
4419 if ExpA < ObjA then
4420 Set_Result (Known_Incompatible);
4421 end if;
4423 -- Case of Expr alignment unknown
4425 else
4426 Set_Result (Default);
4427 end if;
4429 -- See if size is given. If so, check that it is not too
4430 -- small for the required alignment.
4431 -- See if Expr is an object with known alignment
4433 if Is_Entity_Name (Expr)
4434 and then Known_Static_Esize (Entity (Expr))
4435 then
4436 SizA := Esize (Entity (Expr));
4438 -- Otherwise, we check the object size of the Expr type
4440 elsif Known_Static_Esize (Etype (Expr)) then
4441 SizA := Esize (Etype (Expr));
4442 end if;
4444 -- If we got a size, see if it is a multiple of the Obj
4445 -- alignment, if not, then the alignment cannot be
4446 -- acceptable, since the size is always a multiple of the
4447 -- alignment.
4449 if SizA /= No_Uint then
4450 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
4451 Set_Result (Known_Incompatible);
4452 end if;
4453 end if;
4454 end if;
4455 end;
4457 -- If we can't find the result by direct comparison of alignment
4458 -- values, then there is still one case that we can determine known
4459 -- result, and that is when we can determine that the types are the
4460 -- same, and no alignments are specified. Then we known that the
4461 -- alignments are compatible, even if we don't know the alignment
4462 -- value in the front end.
4464 elsif Etype (Obj) = Etype (Expr) then
4466 -- Types are the same, but we have to check for possible size
4467 -- and alignments on the Expr object that may make the alignment
4468 -- different, even though the types are the same.
4470 if Is_Entity_Name (Expr) then
4472 -- First check alignment of the Expr object. Any alignment less
4473 -- than Maximum_Alignment is worrisome since this is the case
4474 -- where we do not know the alignment of Obj.
4476 if Known_Alignment (Entity (Expr))
4477 and then
4478 UI_To_Int (Alignment (Entity (Expr)))
4479 < Ttypes.Maximum_Alignment
4480 then
4481 Set_Result (Unknown);
4483 -- Now check size of Expr object. Any size that is not an
4484 -- even multiple of Maximum_Alignment is also worrisome
4485 -- since it may cause the alignment of the object to be less
4486 -- than the alignment of the type.
4488 elsif Known_Static_Esize (Entity (Expr))
4489 and then
4490 (UI_To_Int (Esize (Entity (Expr))) mod
4491 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
4492 /= 0
4493 then
4494 Set_Result (Unknown);
4496 -- Otherwise same type is decisive
4498 else
4499 Set_Result (Known_Compatible);
4500 end if;
4501 end if;
4503 -- Another case to deal with is when there is an explicit size or
4504 -- alignment clause when the types are not the same. If so, then the
4505 -- result is Unknown. We don't need to do this test if the Default is
4506 -- Unknown, since that result will be set in any case.
4508 elsif Default /= Unknown
4509 and then (Has_Size_Clause (Etype (Expr))
4510 or else
4511 Has_Alignment_Clause (Etype (Expr)))
4512 then
4513 Set_Result (Unknown);
4515 -- If no indication found, set default
4517 else
4518 Set_Result (Default);
4519 end if;
4521 -- Return worst result found
4523 return Result;
4524 end Has_Compatible_Alignment_Internal;
4526 -- Start of processing for Has_Compatible_Alignment
4528 begin
4529 -- If Obj has no specified alignment, then set alignment from the type
4530 -- alignment. Perhaps we should always do this, but for sure we should
4531 -- do it when there is an address clause since we can do more if the
4532 -- alignment is known.
4534 if Unknown_Alignment (Obj) then
4535 Set_Alignment (Obj, Alignment (Etype (Obj)));
4536 end if;
4538 -- Now do the internal call that does all the work
4540 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
4541 end Has_Compatible_Alignment;
4543 ----------------------
4544 -- Has_Declarations --
4545 ----------------------
4547 function Has_Declarations (N : Node_Id) return Boolean is
4548 K : constant Node_Kind := Nkind (N);
4549 begin
4550 return K = N_Accept_Statement
4551 or else K = N_Block_Statement
4552 or else K = N_Compilation_Unit_Aux
4553 or else K = N_Entry_Body
4554 or else K = N_Package_Body
4555 or else K = N_Protected_Body
4556 or else K = N_Subprogram_Body
4557 or else K = N_Task_Body
4558 or else K = N_Package_Specification;
4559 end Has_Declarations;
4561 -------------------------------------------
4562 -- Has_Discriminant_Dependent_Constraint --
4563 -------------------------------------------
4565 function Has_Discriminant_Dependent_Constraint
4566 (Comp : Entity_Id) return Boolean
4568 Comp_Decl : constant Node_Id := Parent (Comp);
4569 Subt_Indic : constant Node_Id :=
4570 Subtype_Indication (Component_Definition (Comp_Decl));
4571 Constr : Node_Id;
4572 Assn : Node_Id;
4574 begin
4575 if Nkind (Subt_Indic) = N_Subtype_Indication then
4576 Constr := Constraint (Subt_Indic);
4578 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
4579 Assn := First (Constraints (Constr));
4580 while Present (Assn) loop
4581 case Nkind (Assn) is
4582 when N_Subtype_Indication |
4583 N_Range |
4584 N_Identifier
4586 if Depends_On_Discriminant (Assn) then
4587 return True;
4588 end if;
4590 when N_Discriminant_Association =>
4591 if Depends_On_Discriminant (Expression (Assn)) then
4592 return True;
4593 end if;
4595 when others =>
4596 null;
4598 end case;
4600 Next (Assn);
4601 end loop;
4602 end if;
4603 end if;
4605 return False;
4606 end Has_Discriminant_Dependent_Constraint;
4608 --------------------
4609 -- Has_Infinities --
4610 --------------------
4612 function Has_Infinities (E : Entity_Id) return Boolean is
4613 begin
4614 return
4615 Is_Floating_Point_Type (E)
4616 and then Nkind (Scalar_Range (E)) = N_Range
4617 and then Includes_Infinities (Scalar_Range (E));
4618 end Has_Infinities;
4620 ------------------------
4621 -- Has_Null_Exclusion --
4622 ------------------------
4624 function Has_Null_Exclusion (N : Node_Id) return Boolean is
4625 begin
4626 case Nkind (N) is
4627 when N_Access_Definition |
4628 N_Access_Function_Definition |
4629 N_Access_Procedure_Definition |
4630 N_Access_To_Object_Definition |
4631 N_Allocator |
4632 N_Derived_Type_Definition |
4633 N_Function_Specification |
4634 N_Subtype_Declaration =>
4635 return Null_Exclusion_Present (N);
4637 when N_Component_Definition |
4638 N_Formal_Object_Declaration |
4639 N_Object_Renaming_Declaration =>
4640 if Present (Subtype_Mark (N)) then
4641 return Null_Exclusion_Present (N);
4642 else pragma Assert (Present (Access_Definition (N)));
4643 return Null_Exclusion_Present (Access_Definition (N));
4644 end if;
4646 when N_Discriminant_Specification =>
4647 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
4648 return Null_Exclusion_Present (Discriminant_Type (N));
4649 else
4650 return Null_Exclusion_Present (N);
4651 end if;
4653 when N_Object_Declaration =>
4654 if Nkind (Object_Definition (N)) = N_Access_Definition then
4655 return Null_Exclusion_Present (Object_Definition (N));
4656 else
4657 return Null_Exclusion_Present (N);
4658 end if;
4660 when N_Parameter_Specification =>
4661 if Nkind (Parameter_Type (N)) = N_Access_Definition then
4662 return Null_Exclusion_Present (Parameter_Type (N));
4663 else
4664 return Null_Exclusion_Present (N);
4665 end if;
4667 when others =>
4668 return False;
4670 end case;
4671 end Has_Null_Exclusion;
4673 ------------------------
4674 -- Has_Null_Extension --
4675 ------------------------
4677 function Has_Null_Extension (T : Entity_Id) return Boolean is
4678 B : constant Entity_Id := Base_Type (T);
4679 Comps : Node_Id;
4680 Ext : Node_Id;
4682 begin
4683 if Nkind (Parent (B)) = N_Full_Type_Declaration
4684 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
4685 then
4686 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
4688 if Present (Ext) then
4689 if Null_Present (Ext) then
4690 return True;
4691 else
4692 Comps := Component_List (Ext);
4694 -- The null component list is rewritten during analysis to
4695 -- include the parent component. Any other component indicates
4696 -- that the extension was not originally null.
4698 return Null_Present (Comps)
4699 or else No (Next (First (Component_Items (Comps))));
4700 end if;
4701 else
4702 return False;
4703 end if;
4705 else
4706 return False;
4707 end if;
4708 end Has_Null_Extension;
4710 -------------------------------
4711 -- Has_Overriding_Initialize --
4712 -------------------------------
4714 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
4715 BT : constant Entity_Id := Base_Type (T);
4716 Comp : Entity_Id;
4717 P : Elmt_Id;
4719 begin
4720 if Is_Controlled (BT) then
4722 -- For derived types, check immediate ancestor, excluding
4723 -- Controlled itself.
4725 if Is_Derived_Type (BT)
4726 and then not In_Predefined_Unit (Etype (BT))
4727 and then Has_Overriding_Initialize (Etype (BT))
4728 then
4729 return True;
4731 elsif Present (Primitive_Operations (BT)) then
4732 P := First_Elmt (Primitive_Operations (BT));
4733 while Present (P) loop
4734 if Chars (Node (P)) = Name_Initialize
4735 and then Comes_From_Source (Node (P))
4736 then
4737 return True;
4738 end if;
4740 Next_Elmt (P);
4741 end loop;
4742 end if;
4744 return False;
4746 elsif Has_Controlled_Component (BT) then
4747 Comp := First_Component (BT);
4748 while Present (Comp) loop
4749 if Has_Overriding_Initialize (Etype (Comp)) then
4750 return True;
4751 end if;
4753 Next_Component (Comp);
4754 end loop;
4756 return False;
4758 else
4759 return False;
4760 end if;
4761 end Has_Overriding_Initialize;
4763 --------------------------------------
4764 -- Has_Preelaborable_Initialization --
4765 --------------------------------------
4767 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
4768 Has_PE : Boolean;
4770 procedure Check_Components (E : Entity_Id);
4771 -- Check component/discriminant chain, sets Has_PE False if a component
4772 -- or discriminant does not meet the preelaborable initialization rules.
4774 ----------------------
4775 -- Check_Components --
4776 ----------------------
4778 procedure Check_Components (E : Entity_Id) is
4779 Ent : Entity_Id;
4780 Exp : Node_Id;
4782 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
4783 -- Returns True if and only if the expression denoted by N does not
4784 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
4786 ---------------------------------
4787 -- Is_Preelaborable_Expression --
4788 ---------------------------------
4790 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
4791 Exp : Node_Id;
4792 Assn : Node_Id;
4793 Choice : Node_Id;
4794 Comp_Type : Entity_Id;
4795 Is_Array_Aggr : Boolean;
4797 begin
4798 if Is_Static_Expression (N) then
4799 return True;
4801 elsif Nkind (N) = N_Null then
4802 return True;
4804 -- Attributes are allowed in general, even if their prefix is a
4805 -- formal type. (It seems that certain attributes known not to be
4806 -- static might not be allowed, but there are no rules to prevent
4807 -- them.)
4809 elsif Nkind (N) = N_Attribute_Reference then
4810 return True;
4812 -- The name of a discriminant evaluated within its parent type is
4813 -- defined to be preelaborable (10.2.1(8)). Note that we test for
4814 -- names that denote discriminals as well as discriminants to
4815 -- catch references occurring within init procs.
4817 elsif Is_Entity_Name (N)
4818 and then
4819 (Ekind (Entity (N)) = E_Discriminant
4820 or else
4821 ((Ekind (Entity (N)) = E_Constant
4822 or else Ekind (Entity (N)) = E_In_Parameter)
4823 and then Present (Discriminal_Link (Entity (N)))))
4824 then
4825 return True;
4827 elsif Nkind (N) = N_Qualified_Expression then
4828 return Is_Preelaborable_Expression (Expression (N));
4830 -- For aggregates we have to check that each of the associations
4831 -- is preelaborable.
4833 elsif Nkind (N) = N_Aggregate
4834 or else Nkind (N) = N_Extension_Aggregate
4835 then
4836 Is_Array_Aggr := Is_Array_Type (Etype (N));
4838 if Is_Array_Aggr then
4839 Comp_Type := Component_Type (Etype (N));
4840 end if;
4842 -- Check the ancestor part of extension aggregates, which must
4843 -- be either the name of a type that has preelaborable init or
4844 -- an expression that is preelaborable.
4846 if Nkind (N) = N_Extension_Aggregate then
4847 declare
4848 Anc_Part : constant Node_Id := Ancestor_Part (N);
4850 begin
4851 if Is_Entity_Name (Anc_Part)
4852 and then Is_Type (Entity (Anc_Part))
4853 then
4854 if not Has_Preelaborable_Initialization
4855 (Entity (Anc_Part))
4856 then
4857 return False;
4858 end if;
4860 elsif not Is_Preelaborable_Expression (Anc_Part) then
4861 return False;
4862 end if;
4863 end;
4864 end if;
4866 -- Check positional associations
4868 Exp := First (Expressions (N));
4869 while Present (Exp) loop
4870 if not Is_Preelaborable_Expression (Exp) then
4871 return False;
4872 end if;
4874 Next (Exp);
4875 end loop;
4877 -- Check named associations
4879 Assn := First (Component_Associations (N));
4880 while Present (Assn) loop
4881 Choice := First (Choices (Assn));
4882 while Present (Choice) loop
4883 if Is_Array_Aggr then
4884 if Nkind (Choice) = N_Others_Choice then
4885 null;
4887 elsif Nkind (Choice) = N_Range then
4888 if not Is_Static_Range (Choice) then
4889 return False;
4890 end if;
4892 elsif not Is_Static_Expression (Choice) then
4893 return False;
4894 end if;
4896 else
4897 Comp_Type := Etype (Choice);
4898 end if;
4900 Next (Choice);
4901 end loop;
4903 -- If the association has a <> at this point, then we have
4904 -- to check whether the component's type has preelaborable
4905 -- initialization. Note that this only occurs when the
4906 -- association's corresponding component does not have a
4907 -- default expression, the latter case having already been
4908 -- expanded as an expression for the association.
4910 if Box_Present (Assn) then
4911 if not Has_Preelaborable_Initialization (Comp_Type) then
4912 return False;
4913 end if;
4915 -- In the expression case we check whether the expression
4916 -- is preelaborable.
4918 elsif
4919 not Is_Preelaborable_Expression (Expression (Assn))
4920 then
4921 return False;
4922 end if;
4924 Next (Assn);
4925 end loop;
4927 -- If we get here then aggregate as a whole is preelaborable
4929 return True;
4931 -- All other cases are not preelaborable
4933 else
4934 return False;
4935 end if;
4936 end Is_Preelaborable_Expression;
4938 -- Start of processing for Check_Components
4940 begin
4941 -- Loop through entities of record or protected type
4943 Ent := E;
4944 while Present (Ent) loop
4946 -- We are interested only in components and discriminants
4948 if Ekind (Ent) = E_Component
4949 or else
4950 Ekind (Ent) = E_Discriminant
4951 then
4952 -- Get default expression if any. If there is no declaration
4953 -- node, it means we have an internal entity. The parent and
4954 -- tag fields are examples of such entities. For these cases,
4955 -- we just test the type of the entity.
4957 if Present (Declaration_Node (Ent)) then
4958 Exp := Expression (Declaration_Node (Ent));
4959 else
4960 Exp := Empty;
4961 end if;
4963 -- A component has PI if it has no default expression and the
4964 -- component type has PI.
4966 if No (Exp) then
4967 if not Has_Preelaborable_Initialization (Etype (Ent)) then
4968 Has_PE := False;
4969 exit;
4970 end if;
4972 -- Require the default expression to be preelaborable
4974 elsif not Is_Preelaborable_Expression (Exp) then
4975 Has_PE := False;
4976 exit;
4977 end if;
4978 end if;
4980 Next_Entity (Ent);
4981 end loop;
4982 end Check_Components;
4984 -- Start of processing for Has_Preelaborable_Initialization
4986 begin
4987 -- Immediate return if already marked as known preelaborable init. This
4988 -- covers types for which this function has already been called once
4989 -- and returned True (in which case the result is cached), and also
4990 -- types to which a pragma Preelaborable_Initialization applies.
4992 if Known_To_Have_Preelab_Init (E) then
4993 return True;
4994 end if;
4996 -- If the type is a subtype representing a generic actual type, then
4997 -- test whether its base type has preelaborable initialization since
4998 -- the subtype representing the actual does not inherit this attribute
4999 -- from the actual or formal. (but maybe it should???)
5001 if Is_Generic_Actual_Type (E) then
5002 return Has_Preelaborable_Initialization (Base_Type (E));
5003 end if;
5005 -- Other private types never have preelaborable initialization
5007 if Is_Private_Type (E) then
5008 return False;
5009 end if;
5011 -- Here for all non-private view
5013 -- All elementary types have preelaborable initialization
5015 if Is_Elementary_Type (E) then
5016 Has_PE := True;
5018 -- Array types have PI if the component type has PI
5020 elsif Is_Array_Type (E) then
5021 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
5023 -- A derived type has preelaborable initialization if its parent type
5024 -- has preelaborable initialization and (in the case of a derived record
5025 -- extension) if the non-inherited components all have preelaborable
5026 -- initialization. However, a user-defined controlled type with an
5027 -- overriding Initialize procedure does not have preelaborable
5028 -- initialization.
5030 elsif Is_Derived_Type (E) then
5032 -- First check whether ancestor type has preelaborable initialization
5034 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
5036 -- If OK, check extension components (if any)
5038 if Has_PE and then Is_Record_Type (E) then
5039 Check_Components (First_Entity (E));
5040 end if;
5042 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
5043 -- with a user defined Initialize procedure does not have PI.
5045 if Has_PE
5046 and then Is_Controlled (E)
5047 and then Has_Overriding_Initialize (E)
5048 then
5049 Has_PE := False;
5050 end if;
5052 -- Record type has PI if it is non private and all components have PI
5054 elsif Is_Record_Type (E) then
5055 Has_PE := True;
5056 Check_Components (First_Entity (E));
5058 -- Protected types must not have entries, and components must meet
5059 -- same set of rules as for record components.
5061 elsif Is_Protected_Type (E) then
5062 if Has_Entries (E) then
5063 Has_PE := False;
5064 else
5065 Has_PE := True;
5066 Check_Components (First_Entity (E));
5067 Check_Components (First_Private_Entity (E));
5068 end if;
5070 -- Type System.Address always has preelaborable initialization
5072 elsif Is_RTE (E, RE_Address) then
5073 Has_PE := True;
5075 -- In all other cases, type does not have preelaborable initialization
5077 else
5078 return False;
5079 end if;
5081 -- If type has preelaborable initialization, cache result
5083 if Has_PE then
5084 Set_Known_To_Have_Preelab_Init (E);
5085 end if;
5087 return Has_PE;
5088 end Has_Preelaborable_Initialization;
5090 ---------------------------
5091 -- Has_Private_Component --
5092 ---------------------------
5094 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
5095 Btype : Entity_Id := Base_Type (Type_Id);
5096 Component : Entity_Id;
5098 begin
5099 if Error_Posted (Type_Id)
5100 or else Error_Posted (Btype)
5101 then
5102 return False;
5103 end if;
5105 if Is_Class_Wide_Type (Btype) then
5106 Btype := Root_Type (Btype);
5107 end if;
5109 if Is_Private_Type (Btype) then
5110 declare
5111 UT : constant Entity_Id := Underlying_Type (Btype);
5112 begin
5113 if No (UT) then
5114 if No (Full_View (Btype)) then
5115 return not Is_Generic_Type (Btype)
5116 and then not Is_Generic_Type (Root_Type (Btype));
5117 else
5118 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
5119 end if;
5120 else
5121 return not Is_Frozen (UT) and then Has_Private_Component (UT);
5122 end if;
5123 end;
5125 elsif Is_Array_Type (Btype) then
5126 return Has_Private_Component (Component_Type (Btype));
5128 elsif Is_Record_Type (Btype) then
5129 Component := First_Component (Btype);
5130 while Present (Component) loop
5131 if Has_Private_Component (Etype (Component)) then
5132 return True;
5133 end if;
5135 Next_Component (Component);
5136 end loop;
5138 return False;
5140 elsif Is_Protected_Type (Btype)
5141 and then Present (Corresponding_Record_Type (Btype))
5142 then
5143 return Has_Private_Component (Corresponding_Record_Type (Btype));
5145 else
5146 return False;
5147 end if;
5148 end Has_Private_Component;
5150 ----------------
5151 -- Has_Stream --
5152 ----------------
5154 function Has_Stream (T : Entity_Id) return Boolean is
5155 E : Entity_Id;
5157 begin
5158 if No (T) then
5159 return False;
5161 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
5162 return True;
5164 elsif Is_Array_Type (T) then
5165 return Has_Stream (Component_Type (T));
5167 elsif Is_Record_Type (T) then
5168 E := First_Component (T);
5169 while Present (E) loop
5170 if Has_Stream (Etype (E)) then
5171 return True;
5172 else
5173 Next_Component (E);
5174 end if;
5175 end loop;
5177 return False;
5179 elsif Is_Private_Type (T) then
5180 return Has_Stream (Underlying_Type (T));
5182 else
5183 return False;
5184 end if;
5185 end Has_Stream;
5187 --------------------------
5188 -- Has_Tagged_Component --
5189 --------------------------
5191 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
5192 Comp : Entity_Id;
5194 begin
5195 if Is_Private_Type (Typ)
5196 and then Present (Underlying_Type (Typ))
5197 then
5198 return Has_Tagged_Component (Underlying_Type (Typ));
5200 elsif Is_Array_Type (Typ) then
5201 return Has_Tagged_Component (Component_Type (Typ));
5203 elsif Is_Tagged_Type (Typ) then
5204 return True;
5206 elsif Is_Record_Type (Typ) then
5207 Comp := First_Component (Typ);
5208 while Present (Comp) loop
5209 if Has_Tagged_Component (Etype (Comp)) then
5210 return True;
5211 end if;
5213 Comp := Next_Component (Typ);
5214 end loop;
5216 return False;
5218 else
5219 return False;
5220 end if;
5221 end Has_Tagged_Component;
5223 -----------------
5224 -- In_Instance --
5225 -----------------
5227 function In_Instance return Boolean is
5228 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
5229 S : Entity_Id;
5231 begin
5232 S := Current_Scope;
5233 while Present (S)
5234 and then S /= Standard_Standard
5235 loop
5236 if (Ekind (S) = E_Function
5237 or else Ekind (S) = E_Package
5238 or else Ekind (S) = E_Procedure)
5239 and then Is_Generic_Instance (S)
5240 then
5241 -- A child instance is always compiled in the context of a parent
5242 -- instance. Nevertheless, the actuals are not analyzed in an
5243 -- instance context. We detect this case by examining the current
5244 -- compilation unit, which must be a child instance, and checking
5245 -- that it is not currently on the scope stack.
5247 if Is_Child_Unit (Curr_Unit)
5248 and then
5249 Nkind (Unit (Cunit (Current_Sem_Unit)))
5250 = N_Package_Instantiation
5251 and then not In_Open_Scopes (Curr_Unit)
5252 then
5253 return False;
5254 else
5255 return True;
5256 end if;
5257 end if;
5259 S := Scope (S);
5260 end loop;
5262 return False;
5263 end In_Instance;
5265 ----------------------
5266 -- In_Instance_Body --
5267 ----------------------
5269 function In_Instance_Body return Boolean is
5270 S : Entity_Id;
5272 begin
5273 S := Current_Scope;
5274 while Present (S)
5275 and then S /= Standard_Standard
5276 loop
5277 if (Ekind (S) = E_Function
5278 or else Ekind (S) = E_Procedure)
5279 and then Is_Generic_Instance (S)
5280 then
5281 return True;
5283 elsif Ekind (S) = E_Package
5284 and then In_Package_Body (S)
5285 and then Is_Generic_Instance (S)
5286 then
5287 return True;
5288 end if;
5290 S := Scope (S);
5291 end loop;
5293 return False;
5294 end In_Instance_Body;
5296 -----------------------------
5297 -- In_Instance_Not_Visible --
5298 -----------------------------
5300 function In_Instance_Not_Visible return Boolean is
5301 S : Entity_Id;
5303 begin
5304 S := Current_Scope;
5305 while Present (S)
5306 and then S /= Standard_Standard
5307 loop
5308 if (Ekind (S) = E_Function
5309 or else Ekind (S) = E_Procedure)
5310 and then Is_Generic_Instance (S)
5311 then
5312 return True;
5314 elsif Ekind (S) = E_Package
5315 and then (In_Package_Body (S) or else In_Private_Part (S))
5316 and then Is_Generic_Instance (S)
5317 then
5318 return True;
5319 end if;
5321 S := Scope (S);
5322 end loop;
5324 return False;
5325 end In_Instance_Not_Visible;
5327 ------------------------------
5328 -- In_Instance_Visible_Part --
5329 ------------------------------
5331 function In_Instance_Visible_Part return Boolean is
5332 S : Entity_Id;
5334 begin
5335 S := Current_Scope;
5336 while Present (S)
5337 and then S /= Standard_Standard
5338 loop
5339 if Ekind (S) = E_Package
5340 and then Is_Generic_Instance (S)
5341 and then not In_Package_Body (S)
5342 and then not In_Private_Part (S)
5343 then
5344 return True;
5345 end if;
5347 S := Scope (S);
5348 end loop;
5350 return False;
5351 end In_Instance_Visible_Part;
5353 ---------------------
5354 -- In_Package_Body --
5355 ---------------------
5357 function In_Package_Body return Boolean is
5358 S : Entity_Id;
5360 begin
5361 S := Current_Scope;
5362 while Present (S)
5363 and then S /= Standard_Standard
5364 loop
5365 if Ekind (S) = E_Package
5366 and then In_Package_Body (S)
5367 then
5368 return True;
5369 else
5370 S := Scope (S);
5371 end if;
5372 end loop;
5374 return False;
5375 end In_Package_Body;
5377 --------------------------------------
5378 -- In_Subprogram_Or_Concurrent_Unit --
5379 --------------------------------------
5381 function In_Subprogram_Or_Concurrent_Unit return Boolean is
5382 E : Entity_Id;
5383 K : Entity_Kind;
5385 begin
5386 -- Use scope chain to check successively outer scopes
5388 E := Current_Scope;
5389 loop
5390 K := Ekind (E);
5392 if K in Subprogram_Kind
5393 or else K in Concurrent_Kind
5394 or else K in Generic_Subprogram_Kind
5395 then
5396 return True;
5398 elsif E = Standard_Standard then
5399 return False;
5400 end if;
5402 E := Scope (E);
5403 end loop;
5404 end In_Subprogram_Or_Concurrent_Unit;
5406 ---------------------
5407 -- In_Visible_Part --
5408 ---------------------
5410 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
5411 begin
5412 return
5413 Is_Package_Or_Generic_Package (Scope_Id)
5414 and then In_Open_Scopes (Scope_Id)
5415 and then not In_Package_Body (Scope_Id)
5416 and then not In_Private_Part (Scope_Id);
5417 end In_Visible_Part;
5419 ---------------------------------
5420 -- Insert_Explicit_Dereference --
5421 ---------------------------------
5423 procedure Insert_Explicit_Dereference (N : Node_Id) is
5424 New_Prefix : constant Node_Id := Relocate_Node (N);
5425 Ent : Entity_Id := Empty;
5426 Pref : Node_Id;
5427 I : Interp_Index;
5428 It : Interp;
5429 T : Entity_Id;
5431 begin
5432 Save_Interps (N, New_Prefix);
5433 Rewrite (N,
5434 Make_Explicit_Dereference (Sloc (N),
5435 Prefix => New_Prefix));
5437 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
5439 if Is_Overloaded (New_Prefix) then
5441 -- The deference is also overloaded, and its interpretations are the
5442 -- designated types of the interpretations of the original node.
5444 Set_Etype (N, Any_Type);
5446 Get_First_Interp (New_Prefix, I, It);
5447 while Present (It.Nam) loop
5448 T := It.Typ;
5450 if Is_Access_Type (T) then
5451 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
5452 end if;
5454 Get_Next_Interp (I, It);
5455 end loop;
5457 End_Interp_List;
5459 else
5460 -- Prefix is unambiguous: mark the original prefix (which might
5461 -- Come_From_Source) as a reference, since the new (relocated) one
5462 -- won't be taken into account.
5464 if Is_Entity_Name (New_Prefix) then
5465 Ent := Entity (New_Prefix);
5467 -- For a retrieval of a subcomponent of some composite object,
5468 -- retrieve the ultimate entity if there is one.
5470 elsif Nkind (New_Prefix) = N_Selected_Component
5471 or else Nkind (New_Prefix) = N_Indexed_Component
5472 then
5473 Pref := Prefix (New_Prefix);
5474 while Present (Pref)
5475 and then
5476 (Nkind (Pref) = N_Selected_Component
5477 or else Nkind (Pref) = N_Indexed_Component)
5478 loop
5479 Pref := Prefix (Pref);
5480 end loop;
5482 if Present (Pref) and then Is_Entity_Name (Pref) then
5483 Ent := Entity (Pref);
5484 end if;
5485 end if;
5487 if Present (Ent) then
5488 Generate_Reference (Ent, New_Prefix);
5489 end if;
5490 end if;
5491 end Insert_Explicit_Dereference;
5493 -------------------
5494 -- Is_AAMP_Float --
5495 -------------------
5497 function Is_AAMP_Float (E : Entity_Id) return Boolean is
5498 pragma Assert (Is_Type (E));
5499 begin
5500 return AAMP_On_Target
5501 and then Is_Floating_Point_Type (E)
5502 and then E = Base_Type (E);
5503 end Is_AAMP_Float;
5505 -------------------------
5506 -- Is_Actual_Parameter --
5507 -------------------------
5509 function Is_Actual_Parameter (N : Node_Id) return Boolean is
5510 PK : constant Node_Kind := Nkind (Parent (N));
5512 begin
5513 case PK is
5514 when N_Parameter_Association =>
5515 return N = Explicit_Actual_Parameter (Parent (N));
5517 when N_Function_Call | N_Procedure_Call_Statement =>
5518 return Is_List_Member (N)
5519 and then
5520 List_Containing (N) = Parameter_Associations (Parent (N));
5522 when others =>
5523 return False;
5524 end case;
5525 end Is_Actual_Parameter;
5527 ---------------------
5528 -- Is_Aliased_View --
5529 ---------------------
5531 function Is_Aliased_View (Obj : Node_Id) return Boolean is
5532 E : Entity_Id;
5534 begin
5535 if Is_Entity_Name (Obj) then
5537 E := Entity (Obj);
5539 return
5540 (Is_Object (E)
5541 and then
5542 (Is_Aliased (E)
5543 or else (Present (Renamed_Object (E))
5544 and then Is_Aliased_View (Renamed_Object (E)))))
5546 or else ((Is_Formal (E)
5547 or else Ekind (E) = E_Generic_In_Out_Parameter
5548 or else Ekind (E) = E_Generic_In_Parameter)
5549 and then Is_Tagged_Type (Etype (E)))
5551 or else (Is_Concurrent_Type (E)
5552 and then In_Open_Scopes (E))
5554 -- Current instance of type, either directly or as rewritten
5555 -- reference to the current object.
5557 or else (Is_Entity_Name (Original_Node (Obj))
5558 and then Present (Entity (Original_Node (Obj)))
5559 and then Is_Type (Entity (Original_Node (Obj))))
5561 or else (Is_Type (E) and then E = Current_Scope)
5563 or else (Is_Incomplete_Or_Private_Type (E)
5564 and then Full_View (E) = Current_Scope);
5566 elsif Nkind (Obj) = N_Selected_Component then
5567 return Is_Aliased (Entity (Selector_Name (Obj)));
5569 elsif Nkind (Obj) = N_Indexed_Component then
5570 return Has_Aliased_Components (Etype (Prefix (Obj)))
5571 or else
5572 (Is_Access_Type (Etype (Prefix (Obj)))
5573 and then
5574 Has_Aliased_Components
5575 (Designated_Type (Etype (Prefix (Obj)))));
5577 elsif Nkind (Obj) = N_Unchecked_Type_Conversion
5578 or else Nkind (Obj) = N_Type_Conversion
5579 then
5580 return Is_Tagged_Type (Etype (Obj))
5581 and then Is_Aliased_View (Expression (Obj));
5583 elsif Nkind (Obj) = N_Explicit_Dereference then
5584 return Nkind (Original_Node (Obj)) /= N_Function_Call;
5586 else
5587 return False;
5588 end if;
5589 end Is_Aliased_View;
5591 -------------------------
5592 -- Is_Ancestor_Package --
5593 -------------------------
5595 function Is_Ancestor_Package
5596 (E1 : Entity_Id;
5597 E2 : Entity_Id) return Boolean
5599 Par : Entity_Id;
5601 begin
5602 Par := E2;
5603 while Present (Par)
5604 and then Par /= Standard_Standard
5605 loop
5606 if Par = E1 then
5607 return True;
5608 end if;
5610 Par := Scope (Par);
5611 end loop;
5613 return False;
5614 end Is_Ancestor_Package;
5616 ----------------------
5617 -- Is_Atomic_Object --
5618 ----------------------
5620 function Is_Atomic_Object (N : Node_Id) return Boolean is
5622 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
5623 -- Determines if given object has atomic components
5625 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
5626 -- If prefix is an implicit dereference, examine designated type
5628 ----------------------
5629 -- Is_Atomic_Prefix --
5630 ----------------------
5632 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
5633 begin
5634 if Is_Access_Type (Etype (N)) then
5635 return
5636 Has_Atomic_Components (Designated_Type (Etype (N)));
5637 else
5638 return Object_Has_Atomic_Components (N);
5639 end if;
5640 end Is_Atomic_Prefix;
5642 ----------------------------------
5643 -- Object_Has_Atomic_Components --
5644 ----------------------------------
5646 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
5647 begin
5648 if Has_Atomic_Components (Etype (N))
5649 or else Is_Atomic (Etype (N))
5650 then
5651 return True;
5653 elsif Is_Entity_Name (N)
5654 and then (Has_Atomic_Components (Entity (N))
5655 or else Is_Atomic (Entity (N)))
5656 then
5657 return True;
5659 elsif Nkind (N) = N_Indexed_Component
5660 or else Nkind (N) = N_Selected_Component
5661 then
5662 return Is_Atomic_Prefix (Prefix (N));
5664 else
5665 return False;
5666 end if;
5667 end Object_Has_Atomic_Components;
5669 -- Start of processing for Is_Atomic_Object
5671 begin
5672 if Is_Atomic (Etype (N))
5673 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
5674 then
5675 return True;
5677 elsif Nkind (N) = N_Indexed_Component
5678 or else Nkind (N) = N_Selected_Component
5679 then
5680 return Is_Atomic_Prefix (Prefix (N));
5682 else
5683 return False;
5684 end if;
5685 end Is_Atomic_Object;
5687 -------------------------
5688 -- Is_Coextension_Root --
5689 -------------------------
5691 function Is_Coextension_Root (N : Node_Id) return Boolean is
5692 begin
5693 return
5694 Nkind (N) = N_Allocator
5695 and then Present (Coextensions (N))
5697 -- Anonymous access discriminants carry a list of all nested
5698 -- controlled coextensions.
5700 and then not Is_Dynamic_Coextension (N)
5701 and then not Is_Static_Coextension (N);
5702 end Is_Coextension_Root;
5704 -----------------------------
5705 -- Is_Concurrent_Interface --
5706 -----------------------------
5708 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
5709 begin
5710 return
5711 Is_Interface (T)
5712 and then
5713 (Is_Protected_Interface (T)
5714 or else Is_Synchronized_Interface (T)
5715 or else Is_Task_Interface (T));
5716 end Is_Concurrent_Interface;
5718 --------------------------------------
5719 -- Is_Controlling_Limited_Procedure --
5720 --------------------------------------
5722 function Is_Controlling_Limited_Procedure
5723 (Proc_Nam : Entity_Id) return Boolean
5725 Param_Typ : Entity_Id := Empty;
5727 begin
5728 if Ekind (Proc_Nam) = E_Procedure
5729 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
5730 then
5731 Param_Typ := Etype (Parameter_Type (First (
5732 Parameter_Specifications (Parent (Proc_Nam)))));
5734 -- In this case where an Itype was created, the procedure call has been
5735 -- rewritten.
5737 elsif Present (Associated_Node_For_Itype (Proc_Nam))
5738 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
5739 and then
5740 Present (Parameter_Associations
5741 (Associated_Node_For_Itype (Proc_Nam)))
5742 then
5743 Param_Typ :=
5744 Etype (First (Parameter_Associations
5745 (Associated_Node_For_Itype (Proc_Nam))));
5746 end if;
5748 if Present (Param_Typ) then
5749 return
5750 Is_Interface (Param_Typ)
5751 and then Is_Limited_Record (Param_Typ);
5752 end if;
5754 return False;
5755 end Is_Controlling_Limited_Procedure;
5757 ----------------------------------------------
5758 -- Is_Dependent_Component_Of_Mutable_Object --
5759 ----------------------------------------------
5761 function Is_Dependent_Component_Of_Mutable_Object
5762 (Object : Node_Id) return Boolean
5764 P : Node_Id;
5765 Prefix_Type : Entity_Id;
5766 P_Aliased : Boolean := False;
5767 Comp : Entity_Id;
5769 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
5770 -- Returns True if and only if Comp is declared within a variant part
5772 --------------------------------
5773 -- Is_Declared_Within_Variant --
5774 --------------------------------
5776 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
5777 Comp_Decl : constant Node_Id := Parent (Comp);
5778 Comp_List : constant Node_Id := Parent (Comp_Decl);
5779 begin
5780 return Nkind (Parent (Comp_List)) = N_Variant;
5781 end Is_Declared_Within_Variant;
5783 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
5785 begin
5786 if Is_Variable (Object) then
5788 if Nkind (Object) = N_Selected_Component then
5789 P := Prefix (Object);
5790 Prefix_Type := Etype (P);
5792 if Is_Entity_Name (P) then
5794 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
5795 Prefix_Type := Base_Type (Prefix_Type);
5796 end if;
5798 if Is_Aliased (Entity (P)) then
5799 P_Aliased := True;
5800 end if;
5802 -- A discriminant check on a selected component may be
5803 -- expanded into a dereference when removing side-effects.
5804 -- Recover the original node and its type, which may be
5805 -- unconstrained.
5807 elsif Nkind (P) = N_Explicit_Dereference
5808 and then not (Comes_From_Source (P))
5809 then
5810 P := Original_Node (P);
5811 Prefix_Type := Etype (P);
5813 else
5814 -- Check for prefix being an aliased component ???
5815 null;
5817 end if;
5819 -- A heap object is constrained by its initial value
5821 -- Ada 2005 (AI-363): Always assume the object could be mutable in
5822 -- the dereferenced case, since the access value might denote an
5823 -- unconstrained aliased object, whereas in Ada 95 the designated
5824 -- object is guaranteed to be constrained. A worst-case assumption
5825 -- has to apply in Ada 2005 because we can't tell at compile time
5826 -- whether the object is "constrained by its initial value"
5827 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
5828 -- semantic rules -- these rules are acknowledged to need fixing).
5830 if Ada_Version < Ada_05 then
5831 if Is_Access_Type (Prefix_Type)
5832 or else Nkind (P) = N_Explicit_Dereference
5833 then
5834 return False;
5835 end if;
5837 elsif Ada_Version >= Ada_05 then
5838 if Is_Access_Type (Prefix_Type) then
5840 -- If the access type is pool-specific, and there is no
5841 -- constrained partial view of the designated type, then the
5842 -- designated object is known to be constrained.
5844 if Ekind (Prefix_Type) = E_Access_Type
5845 and then not Has_Constrained_Partial_View
5846 (Designated_Type (Prefix_Type))
5847 then
5848 return False;
5850 -- Otherwise (general access type, or there is a constrained
5851 -- partial view of the designated type), we need to check
5852 -- based on the designated type.
5854 else
5855 Prefix_Type := Designated_Type (Prefix_Type);
5856 end if;
5857 end if;
5858 end if;
5860 Comp :=
5861 Original_Record_Component (Entity (Selector_Name (Object)));
5863 -- As per AI-0017, the renaming is illegal in a generic body,
5864 -- even if the subtype is indefinite.
5866 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
5868 if not Is_Constrained (Prefix_Type)
5869 and then (not Is_Indefinite_Subtype (Prefix_Type)
5870 or else
5871 (Is_Generic_Type (Prefix_Type)
5872 and then Ekind (Current_Scope) = E_Generic_Package
5873 and then In_Package_Body (Current_Scope)))
5875 and then (Is_Declared_Within_Variant (Comp)
5876 or else Has_Discriminant_Dependent_Constraint (Comp))
5877 and then (not P_Aliased or else Ada_Version >= Ada_05)
5878 then
5879 return True;
5881 else
5882 return
5883 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
5885 end if;
5887 elsif Nkind (Object) = N_Indexed_Component
5888 or else Nkind (Object) = N_Slice
5889 then
5890 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
5892 -- A type conversion that Is_Variable is a view conversion:
5893 -- go back to the denoted object.
5895 elsif Nkind (Object) = N_Type_Conversion then
5896 return
5897 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
5898 end if;
5899 end if;
5901 return False;
5902 end Is_Dependent_Component_Of_Mutable_Object;
5904 ---------------------
5905 -- Is_Dereferenced --
5906 ---------------------
5908 function Is_Dereferenced (N : Node_Id) return Boolean is
5909 P : constant Node_Id := Parent (N);
5910 begin
5911 return
5912 (Nkind (P) = N_Selected_Component
5913 or else
5914 Nkind (P) = N_Explicit_Dereference
5915 or else
5916 Nkind (P) = N_Indexed_Component
5917 or else
5918 Nkind (P) = N_Slice)
5919 and then Prefix (P) = N;
5920 end Is_Dereferenced;
5922 ----------------------
5923 -- Is_Descendent_Of --
5924 ----------------------
5926 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
5927 T : Entity_Id;
5928 Etyp : Entity_Id;
5930 begin
5931 pragma Assert (Nkind (T1) in N_Entity);
5932 pragma Assert (Nkind (T2) in N_Entity);
5934 T := Base_Type (T1);
5936 -- Immediate return if the types match
5938 if T = T2 then
5939 return True;
5941 -- Comment needed here ???
5943 elsif Ekind (T) = E_Class_Wide_Type then
5944 return Etype (T) = T2;
5946 -- All other cases
5948 else
5949 loop
5950 Etyp := Etype (T);
5952 -- Done if we found the type we are looking for
5954 if Etyp = T2 then
5955 return True;
5957 -- Done if no more derivations to check
5959 elsif T = T1
5960 or else T = Etyp
5961 then
5962 return False;
5964 -- Following test catches error cases resulting from prev errors
5966 elsif No (Etyp) then
5967 return False;
5969 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
5970 return False;
5972 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
5973 return False;
5974 end if;
5976 T := Base_Type (Etyp);
5977 end loop;
5978 end if;
5979 end Is_Descendent_Of;
5981 --------------
5982 -- Is_False --
5983 --------------
5985 function Is_False (U : Uint) return Boolean is
5986 begin
5987 return (U = 0);
5988 end Is_False;
5990 ---------------------------
5991 -- Is_Fixed_Model_Number --
5992 ---------------------------
5994 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
5995 S : constant Ureal := Small_Value (T);
5996 M : Urealp.Save_Mark;
5997 R : Boolean;
5998 begin
5999 M := Urealp.Mark;
6000 R := (U = UR_Trunc (U / S) * S);
6001 Urealp.Release (M);
6002 return R;
6003 end Is_Fixed_Model_Number;
6005 -------------------------------
6006 -- Is_Fully_Initialized_Type --
6007 -------------------------------
6009 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
6010 begin
6011 if Is_Scalar_Type (Typ) then
6012 return False;
6014 elsif Is_Access_Type (Typ) then
6015 return True;
6017 elsif Is_Array_Type (Typ) then
6018 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
6019 return True;
6020 end if;
6022 -- An interesting case, if we have a constrained type one of whose
6023 -- bounds is known to be null, then there are no elements to be
6024 -- initialized, so all the elements are initialized!
6026 if Is_Constrained (Typ) then
6027 declare
6028 Indx : Node_Id;
6029 Indx_Typ : Entity_Id;
6030 Lbd, Hbd : Node_Id;
6032 begin
6033 Indx := First_Index (Typ);
6034 while Present (Indx) loop
6035 if Etype (Indx) = Any_Type then
6036 return False;
6038 -- If index is a range, use directly
6040 elsif Nkind (Indx) = N_Range then
6041 Lbd := Low_Bound (Indx);
6042 Hbd := High_Bound (Indx);
6044 else
6045 Indx_Typ := Etype (Indx);
6047 if Is_Private_Type (Indx_Typ) then
6048 Indx_Typ := Full_View (Indx_Typ);
6049 end if;
6051 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
6052 return False;
6053 else
6054 Lbd := Type_Low_Bound (Indx_Typ);
6055 Hbd := Type_High_Bound (Indx_Typ);
6056 end if;
6057 end if;
6059 if Compile_Time_Known_Value (Lbd)
6060 and then Compile_Time_Known_Value (Hbd)
6061 then
6062 if Expr_Value (Hbd) < Expr_Value (Lbd) then
6063 return True;
6064 end if;
6065 end if;
6067 Next_Index (Indx);
6068 end loop;
6069 end;
6070 end if;
6072 -- If no null indexes, then type is not fully initialized
6074 return False;
6076 -- Record types
6078 elsif Is_Record_Type (Typ) then
6079 if Has_Discriminants (Typ)
6080 and then
6081 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
6082 and then Is_Fully_Initialized_Variant (Typ)
6083 then
6084 return True;
6085 end if;
6087 -- Controlled records are considered to be fully initialized if
6088 -- there is a user defined Initialize routine. This may not be
6089 -- entirely correct, but as the spec notes, we are guessing here
6090 -- what is best from the point of view of issuing warnings.
6092 if Is_Controlled (Typ) then
6093 declare
6094 Utyp : constant Entity_Id := Underlying_Type (Typ);
6096 begin
6097 if Present (Utyp) then
6098 declare
6099 Init : constant Entity_Id :=
6100 (Find_Prim_Op
6101 (Underlying_Type (Typ), Name_Initialize));
6103 begin
6104 if Present (Init)
6105 and then Comes_From_Source (Init)
6106 and then not
6107 Is_Predefined_File_Name
6108 (File_Name (Get_Source_File_Index (Sloc (Init))))
6109 then
6110 return True;
6112 elsif Has_Null_Extension (Typ)
6113 and then
6114 Is_Fully_Initialized_Type
6115 (Etype (Base_Type (Typ)))
6116 then
6117 return True;
6118 end if;
6119 end;
6120 end if;
6121 end;
6122 end if;
6124 -- Otherwise see if all record components are initialized
6126 declare
6127 Ent : Entity_Id;
6129 begin
6130 Ent := First_Entity (Typ);
6131 while Present (Ent) loop
6132 if Chars (Ent) = Name_uController then
6133 null;
6135 elsif Ekind (Ent) = E_Component
6136 and then (No (Parent (Ent))
6137 or else No (Expression (Parent (Ent))))
6138 and then not Is_Fully_Initialized_Type (Etype (Ent))
6140 -- Special VM case for tag components, which need to be
6141 -- defined in this case, but are never initialized as VMs
6142 -- are using other dispatching mechanisms. Ignore this
6143 -- uninitialized case. Note that this applies both to the
6144 -- uTag entry and the main vtable pointer (CPP_Class case).
6146 and then (VM_Target = No_VM or else not Is_Tag (Ent))
6147 then
6148 return False;
6149 end if;
6151 Next_Entity (Ent);
6152 end loop;
6153 end;
6155 -- No uninitialized components, so type is fully initialized.
6156 -- Note that this catches the case of no components as well.
6158 return True;
6160 elsif Is_Concurrent_Type (Typ) then
6161 return True;
6163 elsif Is_Private_Type (Typ) then
6164 declare
6165 U : constant Entity_Id := Underlying_Type (Typ);
6167 begin
6168 if No (U) then
6169 return False;
6170 else
6171 return Is_Fully_Initialized_Type (U);
6172 end if;
6173 end;
6175 else
6176 return False;
6177 end if;
6178 end Is_Fully_Initialized_Type;
6180 ----------------------------------
6181 -- Is_Fully_Initialized_Variant --
6182 ----------------------------------
6184 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
6185 Loc : constant Source_Ptr := Sloc (Typ);
6186 Constraints : constant List_Id := New_List;
6187 Components : constant Elist_Id := New_Elmt_List;
6188 Comp_Elmt : Elmt_Id;
6189 Comp_Id : Node_Id;
6190 Comp_List : Node_Id;
6191 Discr : Entity_Id;
6192 Discr_Val : Node_Id;
6194 Report_Errors : Boolean;
6195 pragma Warnings (Off, Report_Errors);
6197 begin
6198 if Serious_Errors_Detected > 0 then
6199 return False;
6200 end if;
6202 if Is_Record_Type (Typ)
6203 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
6204 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
6205 then
6206 Comp_List := Component_List (Type_Definition (Parent (Typ)));
6208 Discr := First_Discriminant (Typ);
6209 while Present (Discr) loop
6210 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
6211 Discr_Val := Expression (Parent (Discr));
6213 if Present (Discr_Val)
6214 and then Is_OK_Static_Expression (Discr_Val)
6215 then
6216 Append_To (Constraints,
6217 Make_Component_Association (Loc,
6218 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
6219 Expression => New_Copy (Discr_Val)));
6220 else
6221 return False;
6222 end if;
6223 else
6224 return False;
6225 end if;
6227 Next_Discriminant (Discr);
6228 end loop;
6230 Gather_Components
6231 (Typ => Typ,
6232 Comp_List => Comp_List,
6233 Governed_By => Constraints,
6234 Into => Components,
6235 Report_Errors => Report_Errors);
6237 -- Check that each component present is fully initialized
6239 Comp_Elmt := First_Elmt (Components);
6240 while Present (Comp_Elmt) loop
6241 Comp_Id := Node (Comp_Elmt);
6243 if Ekind (Comp_Id) = E_Component
6244 and then (No (Parent (Comp_Id))
6245 or else No (Expression (Parent (Comp_Id))))
6246 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
6247 then
6248 return False;
6249 end if;
6251 Next_Elmt (Comp_Elmt);
6252 end loop;
6254 return True;
6256 elsif Is_Private_Type (Typ) then
6257 declare
6258 U : constant Entity_Id := Underlying_Type (Typ);
6260 begin
6261 if No (U) then
6262 return False;
6263 else
6264 return Is_Fully_Initialized_Variant (U);
6265 end if;
6266 end;
6267 else
6268 return False;
6269 end if;
6270 end Is_Fully_Initialized_Variant;
6272 ----------------------------
6273 -- Is_Inherited_Operation --
6274 ----------------------------
6276 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
6277 Kind : constant Node_Kind := Nkind (Parent (E));
6278 begin
6279 pragma Assert (Is_Overloadable (E));
6280 return Kind = N_Full_Type_Declaration
6281 or else Kind = N_Private_Extension_Declaration
6282 or else Kind = N_Subtype_Declaration
6283 or else (Ekind (E) = E_Enumeration_Literal
6284 and then Is_Derived_Type (Etype (E)));
6285 end Is_Inherited_Operation;
6287 -----------------------------
6288 -- Is_Library_Level_Entity --
6289 -----------------------------
6291 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
6292 begin
6293 -- The following is a small optimization, and it also properly handles
6294 -- discriminals, which in task bodies might appear in expressions before
6295 -- the corresponding procedure has been created, and which therefore do
6296 -- not have an assigned scope.
6298 if Ekind (E) in Formal_Kind then
6299 return False;
6300 end if;
6302 -- Normal test is simply that the enclosing dynamic scope is Standard
6304 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
6305 end Is_Library_Level_Entity;
6307 ---------------------------------
6308 -- Is_Local_Variable_Reference --
6309 ---------------------------------
6311 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
6312 begin
6313 if not Is_Entity_Name (Expr) then
6314 return False;
6316 else
6317 declare
6318 Ent : constant Entity_Id := Entity (Expr);
6319 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
6320 begin
6321 if Ekind (Ent) /= E_Variable
6322 and then
6323 Ekind (Ent) /= E_In_Out_Parameter
6324 then
6325 return False;
6326 else
6327 return Present (Sub) and then Sub = Current_Subprogram;
6328 end if;
6329 end;
6330 end if;
6331 end Is_Local_Variable_Reference;
6333 -------------------------
6334 -- Is_Object_Reference --
6335 -------------------------
6337 function Is_Object_Reference (N : Node_Id) return Boolean is
6338 begin
6339 if Is_Entity_Name (N) then
6340 return Present (Entity (N)) and then Is_Object (Entity (N));
6342 else
6343 case Nkind (N) is
6344 when N_Indexed_Component | N_Slice =>
6345 return
6346 Is_Object_Reference (Prefix (N))
6347 or else Is_Access_Type (Etype (Prefix (N)));
6349 -- In Ada95, a function call is a constant object; a procedure
6350 -- call is not.
6352 when N_Function_Call =>
6353 return Etype (N) /= Standard_Void_Type;
6355 -- A reference to the stream attribute Input is a function call
6357 when N_Attribute_Reference =>
6358 return Attribute_Name (N) = Name_Input;
6360 when N_Selected_Component =>
6361 return
6362 Is_Object_Reference (Selector_Name (N))
6363 and then
6364 (Is_Object_Reference (Prefix (N))
6365 or else Is_Access_Type (Etype (Prefix (N))));
6367 when N_Explicit_Dereference =>
6368 return True;
6370 -- A view conversion of a tagged object is an object reference
6372 when N_Type_Conversion =>
6373 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
6374 and then Is_Tagged_Type (Etype (Expression (N)))
6375 and then Is_Object_Reference (Expression (N));
6377 -- An unchecked type conversion is considered to be an object if
6378 -- the operand is an object (this construction arises only as a
6379 -- result of expansion activities).
6381 when N_Unchecked_Type_Conversion =>
6382 return True;
6384 when others =>
6385 return False;
6386 end case;
6387 end if;
6388 end Is_Object_Reference;
6390 -----------------------------------
6391 -- Is_OK_Variable_For_Out_Formal --
6392 -----------------------------------
6394 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
6395 begin
6396 Note_Possible_Modification (AV, Sure => True);
6398 -- We must reject parenthesized variable names. The check for
6399 -- Comes_From_Source is present because there are currently
6400 -- cases where the compiler violates this rule (e.g. passing
6401 -- a task object to its controlled Initialize routine).
6403 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
6404 return False;
6406 -- A variable is always allowed
6408 elsif Is_Variable (AV) then
6409 return True;
6411 -- Unchecked conversions are allowed only if they come from the
6412 -- generated code, which sometimes uses unchecked conversions for out
6413 -- parameters in cases where code generation is unaffected. We tell
6414 -- source unchecked conversions by seeing if they are rewrites of an
6415 -- original Unchecked_Conversion function call, or of an explicit
6416 -- conversion of a function call.
6418 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
6419 if Nkind (Original_Node (AV)) = N_Function_Call then
6420 return False;
6422 elsif Comes_From_Source (AV)
6423 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
6424 then
6425 return False;
6427 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
6428 return Is_OK_Variable_For_Out_Formal (Expression (AV));
6430 else
6431 return True;
6432 end if;
6434 -- Normal type conversions are allowed if argument is a variable
6436 elsif Nkind (AV) = N_Type_Conversion then
6437 if Is_Variable (Expression (AV))
6438 and then Paren_Count (Expression (AV)) = 0
6439 then
6440 Note_Possible_Modification (Expression (AV), Sure => True);
6441 return True;
6443 -- We also allow a non-parenthesized expression that raises
6444 -- constraint error if it rewrites what used to be a variable
6446 elsif Raises_Constraint_Error (Expression (AV))
6447 and then Paren_Count (Expression (AV)) = 0
6448 and then Is_Variable (Original_Node (Expression (AV)))
6449 then
6450 return True;
6452 -- Type conversion of something other than a variable
6454 else
6455 return False;
6456 end if;
6458 -- If this node is rewritten, then test the original form, if that is
6459 -- OK, then we consider the rewritten node OK (for example, if the
6460 -- original node is a conversion, then Is_Variable will not be true
6461 -- but we still want to allow the conversion if it converts a variable).
6463 elsif Original_Node (AV) /= AV then
6464 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
6466 -- All other non-variables are rejected
6468 else
6469 return False;
6470 end if;
6471 end Is_OK_Variable_For_Out_Formal;
6473 ---------------
6474 -- Is_Parent --
6475 ---------------
6477 function Is_Parent
6478 (E1 : Entity_Id;
6479 E2 : Entity_Id) return Boolean
6481 Iface_List : List_Id;
6482 T : Entity_Id := E2;
6484 begin
6485 if Is_Concurrent_Type (T)
6486 or else Is_Concurrent_Record_Type (T)
6487 then
6488 Iface_List := Abstract_Interface_List (E2);
6490 if Is_Empty_List (Iface_List) then
6491 return False;
6492 end if;
6494 T := Etype (First (Iface_List));
6495 end if;
6497 return Is_Ancestor (E1, T);
6498 end Is_Parent;
6500 -----------------------------------
6501 -- Is_Partially_Initialized_Type --
6502 -----------------------------------
6504 function Is_Partially_Initialized_Type (Typ : Entity_Id) return Boolean is
6505 begin
6506 if Is_Scalar_Type (Typ) then
6507 return False;
6509 elsif Is_Access_Type (Typ) then
6510 return True;
6512 elsif Is_Array_Type (Typ) then
6514 -- If component type is partially initialized, so is array type
6516 if Is_Partially_Initialized_Type (Component_Type (Typ)) then
6517 return True;
6519 -- Otherwise we are only partially initialized if we are fully
6520 -- initialized (this is the empty array case, no point in us
6521 -- duplicating that code here).
6523 else
6524 return Is_Fully_Initialized_Type (Typ);
6525 end if;
6527 elsif Is_Record_Type (Typ) then
6529 -- A discriminated type is always partially initialized
6531 if Has_Discriminants (Typ) then
6532 return True;
6534 -- A tagged type is always partially initialized
6536 elsif Is_Tagged_Type (Typ) then
6537 return True;
6539 -- Case of non-discriminated record
6541 else
6542 declare
6543 Ent : Entity_Id;
6545 Component_Present : Boolean := False;
6546 -- Set True if at least one component is present. If no
6547 -- components are present, then record type is fully
6548 -- initialized (another odd case, like the null array).
6550 begin
6551 -- Loop through components
6553 Ent := First_Entity (Typ);
6554 while Present (Ent) loop
6555 if Ekind (Ent) = E_Component then
6556 Component_Present := True;
6558 -- If a component has an initialization expression then
6559 -- the enclosing record type is partially initialized
6561 if Present (Parent (Ent))
6562 and then Present (Expression (Parent (Ent)))
6563 then
6564 return True;
6566 -- If a component is of a type which is itself partially
6567 -- initialized, then the enclosing record type is also.
6569 elsif Is_Partially_Initialized_Type (Etype (Ent)) then
6570 return True;
6571 end if;
6572 end if;
6574 Next_Entity (Ent);
6575 end loop;
6577 -- No initialized components found. If we found any components
6578 -- they were all uninitialized so the result is false.
6580 if Component_Present then
6581 return False;
6583 -- But if we found no components, then all the components are
6584 -- initialized so we consider the type to be initialized.
6586 else
6587 return True;
6588 end if;
6589 end;
6590 end if;
6592 -- Concurrent types are always fully initialized
6594 elsif Is_Concurrent_Type (Typ) then
6595 return True;
6597 -- For a private type, go to underlying type. If there is no underlying
6598 -- type then just assume this partially initialized. Not clear if this
6599 -- can happen in a non-error case, but no harm in testing for this.
6601 elsif Is_Private_Type (Typ) then
6602 declare
6603 U : constant Entity_Id := Underlying_Type (Typ);
6604 begin
6605 if No (U) then
6606 return True;
6607 else
6608 return Is_Partially_Initialized_Type (U);
6609 end if;
6610 end;
6612 -- For any other type (are there any?) assume partially initialized
6614 else
6615 return True;
6616 end if;
6617 end Is_Partially_Initialized_Type;
6619 ------------------------------------
6620 -- Is_Potentially_Persistent_Type --
6621 ------------------------------------
6623 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
6624 Comp : Entity_Id;
6625 Indx : Node_Id;
6627 begin
6628 -- For private type, test corresponding full type
6630 if Is_Private_Type (T) then
6631 return Is_Potentially_Persistent_Type (Full_View (T));
6633 -- Scalar types are potentially persistent
6635 elsif Is_Scalar_Type (T) then
6636 return True;
6638 -- Record type is potentially persistent if not tagged and the types of
6639 -- all it components are potentially persistent, and no component has
6640 -- an initialization expression.
6642 elsif Is_Record_Type (T)
6643 and then not Is_Tagged_Type (T)
6644 and then not Is_Partially_Initialized_Type (T)
6645 then
6646 Comp := First_Component (T);
6647 while Present (Comp) loop
6648 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
6649 return False;
6650 else
6651 Next_Entity (Comp);
6652 end if;
6653 end loop;
6655 return True;
6657 -- Array type is potentially persistent if its component type is
6658 -- potentially persistent and if all its constraints are static.
6660 elsif Is_Array_Type (T) then
6661 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
6662 return False;
6663 end if;
6665 Indx := First_Index (T);
6666 while Present (Indx) loop
6667 if not Is_OK_Static_Subtype (Etype (Indx)) then
6668 return False;
6669 else
6670 Next_Index (Indx);
6671 end if;
6672 end loop;
6674 return True;
6676 -- All other types are not potentially persistent
6678 else
6679 return False;
6680 end if;
6681 end Is_Potentially_Persistent_Type;
6683 -----------------------------
6684 -- Is_RCI_Pkg_Spec_Or_Body --
6685 -----------------------------
6687 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
6689 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
6690 -- Return True if the unit of Cunit is an RCI package declaration
6692 ---------------------------
6693 -- Is_RCI_Pkg_Decl_Cunit --
6694 ---------------------------
6696 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
6697 The_Unit : constant Node_Id := Unit (Cunit);
6699 begin
6700 if Nkind (The_Unit) /= N_Package_Declaration then
6701 return False;
6702 end if;
6704 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
6705 end Is_RCI_Pkg_Decl_Cunit;
6707 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
6709 begin
6710 return Is_RCI_Pkg_Decl_Cunit (Cunit)
6711 or else
6712 (Nkind (Unit (Cunit)) = N_Package_Body
6713 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
6714 end Is_RCI_Pkg_Spec_Or_Body;
6716 -----------------------------------------
6717 -- Is_Remote_Access_To_Class_Wide_Type --
6718 -----------------------------------------
6720 function Is_Remote_Access_To_Class_Wide_Type
6721 (E : Entity_Id) return Boolean
6723 D : Entity_Id;
6725 function Comes_From_Limited_Private_Type_Declaration
6726 (E : Entity_Id) return Boolean;
6727 -- Check that the type is declared by a limited type declaration,
6728 -- or else is derived from a Remote_Type ancestor through private
6729 -- extensions.
6731 -------------------------------------------------
6732 -- Comes_From_Limited_Private_Type_Declaration --
6733 -------------------------------------------------
6735 function Comes_From_Limited_Private_Type_Declaration
6736 (E : Entity_Id) return Boolean
6738 N : constant Node_Id := Declaration_Node (E);
6740 begin
6741 if Nkind (N) = N_Private_Type_Declaration
6742 and then Limited_Present (N)
6743 then
6744 return True;
6745 end if;
6747 if Nkind (N) = N_Private_Extension_Declaration then
6748 return
6749 Comes_From_Limited_Private_Type_Declaration (Etype (E))
6750 or else
6751 (Is_Remote_Types (Etype (E))
6752 and then Is_Limited_Record (Etype (E))
6753 and then Has_Private_Declaration (Etype (E)));
6754 end if;
6756 return False;
6757 end Comes_From_Limited_Private_Type_Declaration;
6759 -- Start of processing for Is_Remote_Access_To_Class_Wide_Type
6761 begin
6762 if not (Is_Remote_Call_Interface (E)
6763 or else Is_Remote_Types (E))
6764 or else Ekind (E) /= E_General_Access_Type
6765 then
6766 return False;
6767 end if;
6769 D := Designated_Type (E);
6771 if Ekind (D) /= E_Class_Wide_Type then
6772 return False;
6773 end if;
6775 return Comes_From_Limited_Private_Type_Declaration
6776 (Defining_Identifier (Parent (D)));
6777 end Is_Remote_Access_To_Class_Wide_Type;
6779 -----------------------------------------
6780 -- Is_Remote_Access_To_Subprogram_Type --
6781 -----------------------------------------
6783 function Is_Remote_Access_To_Subprogram_Type
6784 (E : Entity_Id) return Boolean
6786 begin
6787 return (Ekind (E) = E_Access_Subprogram_Type
6788 or else (Ekind (E) = E_Record_Type
6789 and then Present (Corresponding_Remote_Type (E))))
6790 and then (Is_Remote_Call_Interface (E)
6791 or else Is_Remote_Types (E));
6792 end Is_Remote_Access_To_Subprogram_Type;
6794 --------------------
6795 -- Is_Remote_Call --
6796 --------------------
6798 function Is_Remote_Call (N : Node_Id) return Boolean is
6799 begin
6800 if Nkind (N) /= N_Procedure_Call_Statement
6801 and then Nkind (N) /= N_Function_Call
6802 then
6803 -- An entry call cannot be remote
6805 return False;
6807 elsif Nkind (Name (N)) in N_Has_Entity
6808 and then Is_Remote_Call_Interface (Entity (Name (N)))
6809 then
6810 -- A subprogram declared in the spec of a RCI package is remote
6812 return True;
6814 elsif Nkind (Name (N)) = N_Explicit_Dereference
6815 and then Is_Remote_Access_To_Subprogram_Type
6816 (Etype (Prefix (Name (N))))
6817 then
6818 -- The dereference of a RAS is a remote call
6820 return True;
6822 elsif Present (Controlling_Argument (N))
6823 and then Is_Remote_Access_To_Class_Wide_Type
6824 (Etype (Controlling_Argument (N)))
6825 then
6826 -- Any primitive operation call with a controlling argument of
6827 -- a RACW type is a remote call.
6829 return True;
6830 end if;
6832 -- All other calls are local calls
6834 return False;
6835 end Is_Remote_Call;
6837 ----------------------
6838 -- Is_Renamed_Entry --
6839 ----------------------
6841 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
6842 Orig_Node : Node_Id := Empty;
6843 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
6845 function Is_Entry (Nam : Node_Id) return Boolean;
6846 -- Determine whether Nam is an entry. Traverse selectors
6847 -- if there are nested selected components.
6849 --------------
6850 -- Is_Entry --
6851 --------------
6853 function Is_Entry (Nam : Node_Id) return Boolean is
6854 begin
6855 if Nkind (Nam) = N_Selected_Component then
6856 return Is_Entry (Selector_Name (Nam));
6857 end if;
6859 return Ekind (Entity (Nam)) = E_Entry;
6860 end Is_Entry;
6862 -- Start of processing for Is_Renamed_Entry
6864 begin
6865 if Present (Alias (Proc_Nam)) then
6866 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
6867 end if;
6869 -- Look for a rewritten subprogram renaming declaration
6871 if Nkind (Subp_Decl) = N_Subprogram_Declaration
6872 and then Present (Original_Node (Subp_Decl))
6873 then
6874 Orig_Node := Original_Node (Subp_Decl);
6875 end if;
6877 -- The rewritten subprogram is actually an entry
6879 if Present (Orig_Node)
6880 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
6881 and then Is_Entry (Name (Orig_Node))
6882 then
6883 return True;
6884 end if;
6886 return False;
6887 end Is_Renamed_Entry;
6889 ----------------------
6890 -- Is_Selector_Name --
6891 ----------------------
6893 function Is_Selector_Name (N : Node_Id) return Boolean is
6894 begin
6895 if not Is_List_Member (N) then
6896 declare
6897 P : constant Node_Id := Parent (N);
6898 K : constant Node_Kind := Nkind (P);
6899 begin
6900 return
6901 (K = N_Expanded_Name or else
6902 K = N_Generic_Association or else
6903 K = N_Parameter_Association or else
6904 K = N_Selected_Component)
6905 and then Selector_Name (P) = N;
6906 end;
6908 else
6909 declare
6910 L : constant List_Id := List_Containing (N);
6911 P : constant Node_Id := Parent (L);
6912 begin
6913 return (Nkind (P) = N_Discriminant_Association
6914 and then Selector_Names (P) = L)
6915 or else
6916 (Nkind (P) = N_Component_Association
6917 and then Choices (P) = L);
6918 end;
6919 end if;
6920 end Is_Selector_Name;
6922 ------------------
6923 -- Is_Statement --
6924 ------------------
6926 function Is_Statement (N : Node_Id) return Boolean is
6927 begin
6928 return
6929 Nkind (N) in N_Statement_Other_Than_Procedure_Call
6930 or else Nkind (N) = N_Procedure_Call_Statement;
6931 end Is_Statement;
6933 ---------------------------------
6934 -- Is_Synchronized_Tagged_Type --
6935 ---------------------------------
6937 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
6938 Kind : constant Entity_Kind := Ekind (Base_Type (E));
6940 begin
6941 -- A task or protected type derived from an interface is a tagged type.
6942 -- Such a tagged type is called a synchronized tagged type, as are
6943 -- synchronized interfaces and private extensions whose declaration
6944 -- includes the reserved word synchronized.
6946 return (Is_Tagged_Type (E)
6947 and then (Kind = E_Task_Type
6948 or else Kind = E_Protected_Type))
6949 or else
6950 (Is_Interface (E)
6951 and then Is_Synchronized_Interface (E))
6952 or else
6953 (Ekind (E) = E_Record_Type_With_Private
6954 and then (Synchronized_Present (Parent (E))
6955 or else Is_Synchronized_Interface (Etype (E))));
6956 end Is_Synchronized_Tagged_Type;
6958 -----------------
6959 -- Is_Transfer --
6960 -----------------
6962 function Is_Transfer (N : Node_Id) return Boolean is
6963 Kind : constant Node_Kind := Nkind (N);
6965 begin
6966 if Kind = N_Simple_Return_Statement
6967 or else
6968 Kind = N_Extended_Return_Statement
6969 or else
6970 Kind = N_Goto_Statement
6971 or else
6972 Kind = N_Raise_Statement
6973 or else
6974 Kind = N_Requeue_Statement
6975 then
6976 return True;
6978 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
6979 and then No (Condition (N))
6980 then
6981 return True;
6983 elsif Kind = N_Procedure_Call_Statement
6984 and then Is_Entity_Name (Name (N))
6985 and then Present (Entity (Name (N)))
6986 and then No_Return (Entity (Name (N)))
6987 then
6988 return True;
6990 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
6991 return True;
6993 else
6994 return False;
6995 end if;
6996 end Is_Transfer;
6998 -------------
6999 -- Is_True --
7000 -------------
7002 function Is_True (U : Uint) return Boolean is
7003 begin
7004 return (U /= 0);
7005 end Is_True;
7007 -------------------
7008 -- Is_Value_Type --
7009 -------------------
7011 function Is_Value_Type (T : Entity_Id) return Boolean is
7012 begin
7013 return VM_Target = CLI_Target
7014 and then Chars (T) /= No_Name
7015 and then Get_Name_String (Chars (T)) = "valuetype";
7016 end Is_Value_Type;
7018 -----------------
7019 -- Is_Variable --
7020 -----------------
7022 function Is_Variable (N : Node_Id) return Boolean is
7024 Orig_Node : constant Node_Id := Original_Node (N);
7025 -- We do the test on the original node, since this is basically a
7026 -- test of syntactic categories, so it must not be disturbed by
7027 -- whatever rewriting might have occurred. For example, an aggregate,
7028 -- which is certainly NOT a variable, could be turned into a variable
7029 -- by expansion.
7031 function In_Protected_Function (E : Entity_Id) return Boolean;
7032 -- Within a protected function, the private components of the
7033 -- enclosing protected type are constants. A function nested within
7034 -- a (protected) procedure is not itself protected.
7036 function Is_Variable_Prefix (P : Node_Id) return Boolean;
7037 -- Prefixes can involve implicit dereferences, in which case we
7038 -- must test for the case of a reference of a constant access
7039 -- type, which can never be a variable.
7041 ---------------------------
7042 -- In_Protected_Function --
7043 ---------------------------
7045 function In_Protected_Function (E : Entity_Id) return Boolean is
7046 Prot : constant Entity_Id := Scope (E);
7047 S : Entity_Id;
7049 begin
7050 if not Is_Protected_Type (Prot) then
7051 return False;
7052 else
7053 S := Current_Scope;
7054 while Present (S) and then S /= Prot loop
7055 if Ekind (S) = E_Function
7056 and then Scope (S) = Prot
7057 then
7058 return True;
7059 end if;
7061 S := Scope (S);
7062 end loop;
7064 return False;
7065 end if;
7066 end In_Protected_Function;
7068 ------------------------
7069 -- Is_Variable_Prefix --
7070 ------------------------
7072 function Is_Variable_Prefix (P : Node_Id) return Boolean is
7073 begin
7074 if Is_Access_Type (Etype (P)) then
7075 return not Is_Access_Constant (Root_Type (Etype (P)));
7077 -- For the case of an indexed component whose prefix has a packed
7078 -- array type, the prefix has been rewritten into a type conversion.
7079 -- Determine variable-ness from the converted expression.
7081 elsif Nkind (P) = N_Type_Conversion
7082 and then not Comes_From_Source (P)
7083 and then Is_Array_Type (Etype (P))
7084 and then Is_Packed (Etype (P))
7085 then
7086 return Is_Variable (Expression (P));
7088 else
7089 return Is_Variable (P);
7090 end if;
7091 end Is_Variable_Prefix;
7093 -- Start of processing for Is_Variable
7095 begin
7096 -- Definitely OK if Assignment_OK is set. Since this is something that
7097 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
7099 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
7100 return True;
7102 -- Normally we go to the original node, but there is one exception
7103 -- where we use the rewritten node, namely when it is an explicit
7104 -- dereference. The generated code may rewrite a prefix which is an
7105 -- access type with an explicit dereference. The dereference is a
7106 -- variable, even though the original node may not be (since it could
7107 -- be a constant of the access type).
7109 -- In Ada 2005 we have a further case to consider: the prefix may be
7110 -- a function call given in prefix notation. The original node appears
7111 -- to be a selected component, but we need to examine the call.
7113 elsif Nkind (N) = N_Explicit_Dereference
7114 and then Nkind (Orig_Node) /= N_Explicit_Dereference
7115 and then Present (Etype (Orig_Node))
7116 and then Is_Access_Type (Etype (Orig_Node))
7117 then
7118 return Is_Variable_Prefix (Original_Node (Prefix (N)))
7119 or else
7120 (Nkind (Orig_Node) = N_Function_Call
7121 and then not Is_Access_Constant (Etype (Prefix (N))));
7123 -- A function call is never a variable
7125 elsif Nkind (N) = N_Function_Call then
7126 return False;
7128 -- All remaining checks use the original node
7130 elsif Is_Entity_Name (Orig_Node)
7131 and then Present (Entity (Orig_Node))
7132 then
7133 declare
7134 E : constant Entity_Id := Entity (Orig_Node);
7135 K : constant Entity_Kind := Ekind (E);
7137 begin
7138 return (K = E_Variable
7139 and then Nkind (Parent (E)) /= N_Exception_Handler)
7140 or else (K = E_Component
7141 and then not In_Protected_Function (E))
7142 or else K = E_Out_Parameter
7143 or else K = E_In_Out_Parameter
7144 or else K = E_Generic_In_Out_Parameter
7146 -- Current instance of type:
7148 or else (Is_Type (E) and then In_Open_Scopes (E))
7149 or else (Is_Incomplete_Or_Private_Type (E)
7150 and then In_Open_Scopes (Full_View (E)));
7151 end;
7153 else
7154 case Nkind (Orig_Node) is
7155 when N_Indexed_Component | N_Slice =>
7156 return Is_Variable_Prefix (Prefix (Orig_Node));
7158 when N_Selected_Component =>
7159 return Is_Variable_Prefix (Prefix (Orig_Node))
7160 and then Is_Variable (Selector_Name (Orig_Node));
7162 -- For an explicit dereference, the type of the prefix cannot
7163 -- be an access to constant or an access to subprogram.
7165 when N_Explicit_Dereference =>
7166 declare
7167 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
7168 begin
7169 return Is_Access_Type (Typ)
7170 and then not Is_Access_Constant (Root_Type (Typ))
7171 and then Ekind (Typ) /= E_Access_Subprogram_Type;
7172 end;
7174 -- The type conversion is the case where we do not deal with the
7175 -- context dependent special case of an actual parameter. Thus
7176 -- the type conversion is only considered a variable for the
7177 -- purposes of this routine if the target type is tagged. However,
7178 -- a type conversion is considered to be a variable if it does not
7179 -- come from source (this deals for example with the conversions
7180 -- of expressions to their actual subtypes).
7182 when N_Type_Conversion =>
7183 return Is_Variable (Expression (Orig_Node))
7184 and then
7185 (not Comes_From_Source (Orig_Node)
7186 or else
7187 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
7188 and then
7189 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
7191 -- GNAT allows an unchecked type conversion as a variable. This
7192 -- only affects the generation of internal expanded code, since
7193 -- calls to instantiations of Unchecked_Conversion are never
7194 -- considered variables (since they are function calls).
7195 -- This is also true for expression actions.
7197 when N_Unchecked_Type_Conversion =>
7198 return Is_Variable (Expression (Orig_Node));
7200 when others =>
7201 return False;
7202 end case;
7203 end if;
7204 end Is_Variable;
7206 ------------------------
7207 -- Is_Volatile_Object --
7208 ------------------------
7210 function Is_Volatile_Object (N : Node_Id) return Boolean is
7212 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
7213 -- Determines if given object has volatile components
7215 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
7216 -- If prefix is an implicit dereference, examine designated type
7218 ------------------------
7219 -- Is_Volatile_Prefix --
7220 ------------------------
7222 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
7223 Typ : constant Entity_Id := Etype (N);
7225 begin
7226 if Is_Access_Type (Typ) then
7227 declare
7228 Dtyp : constant Entity_Id := Designated_Type (Typ);
7230 begin
7231 return Is_Volatile (Dtyp)
7232 or else Has_Volatile_Components (Dtyp);
7233 end;
7235 else
7236 return Object_Has_Volatile_Components (N);
7237 end if;
7238 end Is_Volatile_Prefix;
7240 ------------------------------------
7241 -- Object_Has_Volatile_Components --
7242 ------------------------------------
7244 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
7245 Typ : constant Entity_Id := Etype (N);
7247 begin
7248 if Is_Volatile (Typ)
7249 or else Has_Volatile_Components (Typ)
7250 then
7251 return True;
7253 elsif Is_Entity_Name (N)
7254 and then (Has_Volatile_Components (Entity (N))
7255 or else Is_Volatile (Entity (N)))
7256 then
7257 return True;
7259 elsif Nkind (N) = N_Indexed_Component
7260 or else Nkind (N) = N_Selected_Component
7261 then
7262 return Is_Volatile_Prefix (Prefix (N));
7264 else
7265 return False;
7266 end if;
7267 end Object_Has_Volatile_Components;
7269 -- Start of processing for Is_Volatile_Object
7271 begin
7272 if Is_Volatile (Etype (N))
7273 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
7274 then
7275 return True;
7277 elsif Nkind (N) = N_Indexed_Component
7278 or else Nkind (N) = N_Selected_Component
7279 then
7280 return Is_Volatile_Prefix (Prefix (N));
7282 else
7283 return False;
7284 end if;
7285 end Is_Volatile_Object;
7287 -------------------------
7288 -- Kill_Current_Values --
7289 -------------------------
7291 procedure Kill_Current_Values
7292 (Ent : Entity_Id;
7293 Last_Assignment_Only : Boolean := False)
7295 begin
7296 if Is_Assignable (Ent) then
7297 Set_Last_Assignment (Ent, Empty);
7298 end if;
7300 if not Last_Assignment_Only and then Is_Object (Ent) then
7301 Kill_Checks (Ent);
7302 Set_Current_Value (Ent, Empty);
7304 if not Can_Never_Be_Null (Ent) then
7305 Set_Is_Known_Non_Null (Ent, False);
7306 end if;
7308 Set_Is_Known_Null (Ent, False);
7309 end if;
7310 end Kill_Current_Values;
7312 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
7313 S : Entity_Id;
7315 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
7316 -- Clear current value for entity E and all entities chained to E
7318 ------------------------------------------
7319 -- Kill_Current_Values_For_Entity_Chain --
7320 ------------------------------------------
7322 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
7323 Ent : Entity_Id;
7324 begin
7325 Ent := E;
7326 while Present (Ent) loop
7327 Kill_Current_Values (Ent, Last_Assignment_Only);
7328 Next_Entity (Ent);
7329 end loop;
7330 end Kill_Current_Values_For_Entity_Chain;
7332 -- Start of processing for Kill_Current_Values
7334 begin
7335 -- Kill all saved checks, a special case of killing saved values
7337 if not Last_Assignment_Only then
7338 Kill_All_Checks;
7339 end if;
7341 -- Loop through relevant scopes, which includes the current scope and
7342 -- any parent scopes if the current scope is a block or a package.
7344 S := Current_Scope;
7345 Scope_Loop : loop
7347 -- Clear current values of all entities in current scope
7349 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
7351 -- If scope is a package, also clear current values of all
7352 -- private entities in the scope.
7354 if Ekind (S) = E_Package
7355 or else
7356 Ekind (S) = E_Generic_Package
7357 or else
7358 Is_Concurrent_Type (S)
7359 then
7360 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
7361 end if;
7363 -- If this is a not a subprogram, deal with parents
7365 if not Is_Subprogram (S) then
7366 S := Scope (S);
7367 exit Scope_Loop when S = Standard_Standard;
7368 else
7369 exit Scope_Loop;
7370 end if;
7371 end loop Scope_Loop;
7372 end Kill_Current_Values;
7374 --------------------------
7375 -- Kill_Size_Check_Code --
7376 --------------------------
7378 procedure Kill_Size_Check_Code (E : Entity_Id) is
7379 begin
7380 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7381 and then Present (Size_Check_Code (E))
7382 then
7383 Remove (Size_Check_Code (E));
7384 Set_Size_Check_Code (E, Empty);
7385 end if;
7386 end Kill_Size_Check_Code;
7388 --------------------------
7389 -- Known_To_Be_Assigned --
7390 --------------------------
7392 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
7393 P : constant Node_Id := Parent (N);
7395 begin
7396 case Nkind (P) is
7398 -- Test left side of assignment
7400 when N_Assignment_Statement =>
7401 return N = Name (P);
7403 -- Function call arguments are never lvalues
7405 when N_Function_Call =>
7406 return False;
7408 -- Positional parameter for procedure or accept call
7410 when N_Procedure_Call_Statement |
7411 N_Accept_Statement
7413 declare
7414 Proc : Entity_Id;
7415 Form : Entity_Id;
7416 Act : Node_Id;
7418 begin
7419 Proc := Get_Subprogram_Entity (P);
7421 if No (Proc) then
7422 return False;
7423 end if;
7425 -- If we are not a list member, something is strange, so
7426 -- be conservative and return False.
7428 if not Is_List_Member (N) then
7429 return False;
7430 end if;
7432 -- We are going to find the right formal by stepping forward
7433 -- through the formals, as we step backwards in the actuals.
7435 Form := First_Formal (Proc);
7436 Act := N;
7437 loop
7438 -- If no formal, something is weird, so be conservative
7439 -- and return False.
7441 if No (Form) then
7442 return False;
7443 end if;
7445 Prev (Act);
7446 exit when No (Act);
7447 Next_Formal (Form);
7448 end loop;
7450 return Ekind (Form) /= E_In_Parameter;
7451 end;
7453 -- Named parameter for procedure or accept call
7455 when N_Parameter_Association =>
7456 declare
7457 Proc : Entity_Id;
7458 Form : Entity_Id;
7460 begin
7461 Proc := Get_Subprogram_Entity (Parent (P));
7463 if No (Proc) then
7464 return False;
7465 end if;
7467 -- Loop through formals to find the one that matches
7469 Form := First_Formal (Proc);
7470 loop
7471 -- If no matching formal, that's peculiar, some kind of
7472 -- previous error, so return False to be conservative.
7474 if No (Form) then
7475 return False;
7476 end if;
7478 -- Else test for match
7480 if Chars (Form) = Chars (Selector_Name (P)) then
7481 return Ekind (Form) /= E_In_Parameter;
7482 end if;
7484 Next_Formal (Form);
7485 end loop;
7486 end;
7488 -- Test for appearing in a conversion that itself appears
7489 -- in an lvalue context, since this should be an lvalue.
7491 when N_Type_Conversion =>
7492 return Known_To_Be_Assigned (P);
7494 -- All other references are definitely not known to be modifications
7496 when others =>
7497 return False;
7499 end case;
7500 end Known_To_Be_Assigned;
7502 -------------------
7503 -- May_Be_Lvalue --
7504 -------------------
7506 function May_Be_Lvalue (N : Node_Id) return Boolean is
7507 P : constant Node_Id := Parent (N);
7509 begin
7510 case Nkind (P) is
7512 -- Test left side of assignment
7514 when N_Assignment_Statement =>
7515 return N = Name (P);
7517 -- Test prefix of component or attribute
7519 when N_Attribute_Reference =>
7520 return N = Prefix (P)
7521 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
7523 when N_Expanded_Name |
7524 N_Explicit_Dereference |
7525 N_Indexed_Component |
7526 N_Reference |
7527 N_Selected_Component |
7528 N_Slice =>
7529 return N = Prefix (P);
7531 -- Function call arguments are never lvalues
7533 when N_Function_Call =>
7534 return False;
7536 -- Positional parameter for procedure, entry, or accept call
7538 when N_Procedure_Call_Statement |
7539 N_Entry_Call_Statement |
7540 N_Accept_Statement
7542 declare
7543 Proc : Entity_Id;
7544 Form : Entity_Id;
7545 Act : Node_Id;
7547 begin
7548 Proc := Get_Subprogram_Entity (P);
7550 if No (Proc) then
7551 return True;
7552 end if;
7554 -- If we are not a list member, something is strange, so
7555 -- be conservative and return True.
7557 if not Is_List_Member (N) then
7558 return True;
7559 end if;
7561 -- We are going to find the right formal by stepping forward
7562 -- through the formals, as we step backwards in the actuals.
7564 Form := First_Formal (Proc);
7565 Act := N;
7566 loop
7567 -- If no formal, something is weird, so be conservative
7568 -- and return True.
7570 if No (Form) then
7571 return True;
7572 end if;
7574 Prev (Act);
7575 exit when No (Act);
7576 Next_Formal (Form);
7577 end loop;
7579 return Ekind (Form) /= E_In_Parameter;
7580 end;
7582 -- Named parameter for procedure or accept call
7584 when N_Parameter_Association =>
7585 declare
7586 Proc : Entity_Id;
7587 Form : Entity_Id;
7589 begin
7590 Proc := Get_Subprogram_Entity (Parent (P));
7592 if No (Proc) then
7593 return True;
7594 end if;
7596 -- Loop through formals to find the one that matches
7598 Form := First_Formal (Proc);
7599 loop
7600 -- If no matching formal, that's peculiar, some kind of
7601 -- previous error, so return True to be conservative.
7603 if No (Form) then
7604 return True;
7605 end if;
7607 -- Else test for match
7609 if Chars (Form) = Chars (Selector_Name (P)) then
7610 return Ekind (Form) /= E_In_Parameter;
7611 end if;
7613 Next_Formal (Form);
7614 end loop;
7615 end;
7617 -- Test for appearing in a conversion that itself appears in an
7618 -- lvalue context, since this should be an lvalue.
7620 when N_Type_Conversion =>
7621 return May_Be_Lvalue (P);
7623 -- Test for appearance in object renaming declaration
7625 when N_Object_Renaming_Declaration =>
7626 return True;
7628 -- All other references are definitely not Lvalues
7630 when others =>
7631 return False;
7633 end case;
7634 end May_Be_Lvalue;
7636 -----------------------
7637 -- Mark_Coextensions --
7638 -----------------------
7640 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
7641 Is_Dynamic : Boolean;
7642 -- Indicates whether the context causes nested coextensions to be
7643 -- dynamic or static
7645 function Mark_Allocator (N : Node_Id) return Traverse_Result;
7646 -- Recognize an allocator node and label it as a dynamic coextension
7648 --------------------
7649 -- Mark_Allocator --
7650 --------------------
7652 function Mark_Allocator (N : Node_Id) return Traverse_Result is
7653 begin
7654 if Nkind (N) = N_Allocator then
7655 if Is_Dynamic then
7656 Set_Is_Dynamic_Coextension (N);
7657 else
7658 Set_Is_Static_Coextension (N);
7659 end if;
7660 end if;
7662 return OK;
7663 end Mark_Allocator;
7665 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
7667 -- Start of processing Mark_Coextensions
7669 begin
7670 case Nkind (Context_Nod) is
7671 when N_Assignment_Statement |
7672 N_Simple_Return_Statement =>
7673 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
7675 when N_Object_Declaration =>
7676 Is_Dynamic := Nkind (Root_Nod) = N_Allocator;
7678 -- This routine should not be called for constructs which may not
7679 -- contain coextensions.
7681 when others =>
7682 raise Program_Error;
7683 end case;
7685 Mark_Allocators (Root_Nod);
7686 end Mark_Coextensions;
7688 ----------------------
7689 -- Needs_One_Actual --
7690 ----------------------
7692 function Needs_One_Actual (E : Entity_Id) return Boolean is
7693 Formal : Entity_Id;
7695 begin
7696 if Ada_Version >= Ada_05
7697 and then Present (First_Formal (E))
7698 then
7699 Formal := Next_Formal (First_Formal (E));
7700 while Present (Formal) loop
7701 if No (Default_Value (Formal)) then
7702 return False;
7703 end if;
7705 Next_Formal (Formal);
7706 end loop;
7708 return True;
7710 else
7711 return False;
7712 end if;
7713 end Needs_One_Actual;
7715 -------------------------
7716 -- New_External_Entity --
7717 -------------------------
7719 function New_External_Entity
7720 (Kind : Entity_Kind;
7721 Scope_Id : Entity_Id;
7722 Sloc_Value : Source_Ptr;
7723 Related_Id : Entity_Id;
7724 Suffix : Character;
7725 Suffix_Index : Nat := 0;
7726 Prefix : Character := ' ') return Entity_Id
7728 N : constant Entity_Id :=
7729 Make_Defining_Identifier (Sloc_Value,
7730 New_External_Name
7731 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
7733 begin
7734 Set_Ekind (N, Kind);
7735 Set_Is_Internal (N, True);
7736 Append_Entity (N, Scope_Id);
7737 Set_Public_Status (N);
7739 if Kind in Type_Kind then
7740 Init_Size_Align (N);
7741 end if;
7743 return N;
7744 end New_External_Entity;
7746 -------------------------
7747 -- New_Internal_Entity --
7748 -------------------------
7750 function New_Internal_Entity
7751 (Kind : Entity_Kind;
7752 Scope_Id : Entity_Id;
7753 Sloc_Value : Source_Ptr;
7754 Id_Char : Character) return Entity_Id
7756 N : constant Entity_Id :=
7757 Make_Defining_Identifier (Sloc_Value, New_Internal_Name (Id_Char));
7759 begin
7760 Set_Ekind (N, Kind);
7761 Set_Is_Internal (N, True);
7762 Append_Entity (N, Scope_Id);
7764 if Kind in Type_Kind then
7765 Init_Size_Align (N);
7766 end if;
7768 return N;
7769 end New_Internal_Entity;
7771 -----------------
7772 -- Next_Actual --
7773 -----------------
7775 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
7776 N : Node_Id;
7778 begin
7779 -- If we are pointing at a positional parameter, it is a member of a
7780 -- node list (the list of parameters), and the next parameter is the
7781 -- next node on the list, unless we hit a parameter association, then
7782 -- we shift to using the chain whose head is the First_Named_Actual in
7783 -- the parent, and then is threaded using the Next_Named_Actual of the
7784 -- Parameter_Association. All this fiddling is because the original node
7785 -- list is in the textual call order, and what we need is the
7786 -- declaration order.
7788 if Is_List_Member (Actual_Id) then
7789 N := Next (Actual_Id);
7791 if Nkind (N) = N_Parameter_Association then
7792 return First_Named_Actual (Parent (Actual_Id));
7793 else
7794 return N;
7795 end if;
7797 else
7798 return Next_Named_Actual (Parent (Actual_Id));
7799 end if;
7800 end Next_Actual;
7802 procedure Next_Actual (Actual_Id : in out Node_Id) is
7803 begin
7804 Actual_Id := Next_Actual (Actual_Id);
7805 end Next_Actual;
7807 -----------------------
7808 -- Normalize_Actuals --
7809 -----------------------
7811 -- Chain actuals according to formals of subprogram. If there are no named
7812 -- associations, the chain is simply the list of Parameter Associations,
7813 -- since the order is the same as the declaration order. If there are named
7814 -- associations, then the First_Named_Actual field in the N_Function_Call
7815 -- or N_Procedure_Call_Statement node points to the Parameter_Association
7816 -- node for the parameter that comes first in declaration order. The
7817 -- remaining named parameters are then chained in declaration order using
7818 -- Next_Named_Actual.
7820 -- This routine also verifies that the number of actuals is compatible with
7821 -- the number and default values of formals, but performs no type checking
7822 -- (type checking is done by the caller).
7824 -- If the matching succeeds, Success is set to True and the caller proceeds
7825 -- with type-checking. If the match is unsuccessful, then Success is set to
7826 -- False, and the caller attempts a different interpretation, if there is
7827 -- one.
7829 -- If the flag Report is on, the call is not overloaded, and a failure to
7830 -- match can be reported here, rather than in the caller.
7832 procedure Normalize_Actuals
7833 (N : Node_Id;
7834 S : Entity_Id;
7835 Report : Boolean;
7836 Success : out Boolean)
7838 Actuals : constant List_Id := Parameter_Associations (N);
7839 Actual : Node_Id := Empty;
7840 Formal : Entity_Id;
7841 Last : Node_Id := Empty;
7842 First_Named : Node_Id := Empty;
7843 Found : Boolean;
7845 Formals_To_Match : Integer := 0;
7846 Actuals_To_Match : Integer := 0;
7848 procedure Chain (A : Node_Id);
7849 -- Add named actual at the proper place in the list, using the
7850 -- Next_Named_Actual link.
7852 function Reporting return Boolean;
7853 -- Determines if an error is to be reported. To report an error, we
7854 -- need Report to be True, and also we do not report errors caused
7855 -- by calls to init procs that occur within other init procs. Such
7856 -- errors must always be cascaded errors, since if all the types are
7857 -- declared correctly, the compiler will certainly build decent calls!
7859 -----------
7860 -- Chain --
7861 -----------
7863 procedure Chain (A : Node_Id) is
7864 begin
7865 if No (Last) then
7867 -- Call node points to first actual in list
7869 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
7871 else
7872 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
7873 end if;
7875 Last := A;
7876 Set_Next_Named_Actual (Last, Empty);
7877 end Chain;
7879 ---------------
7880 -- Reporting --
7881 ---------------
7883 function Reporting return Boolean is
7884 begin
7885 if not Report then
7886 return False;
7888 elsif not Within_Init_Proc then
7889 return True;
7891 elsif Is_Init_Proc (Entity (Name (N))) then
7892 return False;
7894 else
7895 return True;
7896 end if;
7897 end Reporting;
7899 -- Start of processing for Normalize_Actuals
7901 begin
7902 if Is_Access_Type (S) then
7904 -- The name in the call is a function call that returns an access
7905 -- to subprogram. The designated type has the list of formals.
7907 Formal := First_Formal (Designated_Type (S));
7908 else
7909 Formal := First_Formal (S);
7910 end if;
7912 while Present (Formal) loop
7913 Formals_To_Match := Formals_To_Match + 1;
7914 Next_Formal (Formal);
7915 end loop;
7917 -- Find if there is a named association, and verify that no positional
7918 -- associations appear after named ones.
7920 if Present (Actuals) then
7921 Actual := First (Actuals);
7922 end if;
7924 while Present (Actual)
7925 and then Nkind (Actual) /= N_Parameter_Association
7926 loop
7927 Actuals_To_Match := Actuals_To_Match + 1;
7928 Next (Actual);
7929 end loop;
7931 if No (Actual) and Actuals_To_Match = Formals_To_Match then
7933 -- Most common case: positional notation, no defaults
7935 Success := True;
7936 return;
7938 elsif Actuals_To_Match > Formals_To_Match then
7940 -- Too many actuals: will not work
7942 if Reporting then
7943 if Is_Entity_Name (Name (N)) then
7944 Error_Msg_N ("too many arguments in call to&", Name (N));
7945 else
7946 Error_Msg_N ("too many arguments in call", N);
7947 end if;
7948 end if;
7950 Success := False;
7951 return;
7952 end if;
7954 First_Named := Actual;
7956 while Present (Actual) loop
7957 if Nkind (Actual) /= N_Parameter_Association then
7958 Error_Msg_N
7959 ("positional parameters not allowed after named ones", Actual);
7960 Success := False;
7961 return;
7963 else
7964 Actuals_To_Match := Actuals_To_Match + 1;
7965 end if;
7967 Next (Actual);
7968 end loop;
7970 if Present (Actuals) then
7971 Actual := First (Actuals);
7972 end if;
7974 Formal := First_Formal (S);
7975 while Present (Formal) loop
7977 -- Match the formals in order. If the corresponding actual is
7978 -- positional, nothing to do. Else scan the list of named actuals
7979 -- to find the one with the right name.
7981 if Present (Actual)
7982 and then Nkind (Actual) /= N_Parameter_Association
7983 then
7984 Next (Actual);
7985 Actuals_To_Match := Actuals_To_Match - 1;
7986 Formals_To_Match := Formals_To_Match - 1;
7988 else
7989 -- For named parameters, search the list of actuals to find
7990 -- one that matches the next formal name.
7992 Actual := First_Named;
7993 Found := False;
7994 while Present (Actual) loop
7995 if Chars (Selector_Name (Actual)) = Chars (Formal) then
7996 Found := True;
7997 Chain (Actual);
7998 Actuals_To_Match := Actuals_To_Match - 1;
7999 Formals_To_Match := Formals_To_Match - 1;
8000 exit;
8001 end if;
8003 Next (Actual);
8004 end loop;
8006 if not Found then
8007 if Ekind (Formal) /= E_In_Parameter
8008 or else No (Default_Value (Formal))
8009 then
8010 if Reporting then
8011 if (Comes_From_Source (S)
8012 or else Sloc (S) = Standard_Location)
8013 and then Is_Overloadable (S)
8014 then
8015 if No (Actuals)
8016 and then
8017 (Nkind (Parent (N)) = N_Procedure_Call_Statement
8018 or else
8019 (Nkind (Parent (N)) = N_Function_Call
8020 or else
8021 Nkind (Parent (N)) = N_Parameter_Association))
8022 and then Ekind (S) /= E_Function
8023 then
8024 Set_Etype (N, Etype (S));
8025 else
8026 Error_Msg_Name_1 := Chars (S);
8027 Error_Msg_Sloc := Sloc (S);
8028 Error_Msg_NE
8029 ("missing argument for parameter & " &
8030 "in call to % declared #", N, Formal);
8031 end if;
8033 elsif Is_Overloadable (S) then
8034 Error_Msg_Name_1 := Chars (S);
8036 -- Point to type derivation that generated the
8037 -- operation.
8039 Error_Msg_Sloc := Sloc (Parent (S));
8041 Error_Msg_NE
8042 ("missing argument for parameter & " &
8043 "in call to % (inherited) #", N, Formal);
8045 else
8046 Error_Msg_NE
8047 ("missing argument for parameter &", N, Formal);
8048 end if;
8049 end if;
8051 Success := False;
8052 return;
8054 else
8055 Formals_To_Match := Formals_To_Match - 1;
8056 end if;
8057 end if;
8058 end if;
8060 Next_Formal (Formal);
8061 end loop;
8063 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
8064 Success := True;
8065 return;
8067 else
8068 if Reporting then
8070 -- Find some superfluous named actual that did not get
8071 -- attached to the list of associations.
8073 Actual := First (Actuals);
8074 while Present (Actual) loop
8075 if Nkind (Actual) = N_Parameter_Association
8076 and then Actual /= Last
8077 and then No (Next_Named_Actual (Actual))
8078 then
8079 Error_Msg_N ("unmatched actual & in call",
8080 Selector_Name (Actual));
8081 exit;
8082 end if;
8084 Next (Actual);
8085 end loop;
8086 end if;
8088 Success := False;
8089 return;
8090 end if;
8091 end Normalize_Actuals;
8093 --------------------------------
8094 -- Note_Possible_Modification --
8095 --------------------------------
8097 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
8098 Modification_Comes_From_Source : constant Boolean :=
8099 Comes_From_Source (Parent (N));
8101 Ent : Entity_Id;
8102 Exp : Node_Id;
8104 begin
8105 -- Loop to find referenced entity, if there is one
8107 Exp := N;
8108 loop
8109 <<Continue>>
8110 Ent := Empty;
8112 if Is_Entity_Name (Exp) then
8113 Ent := Entity (Exp);
8115 -- If the entity is missing, it is an undeclared identifier,
8116 -- and there is nothing to annotate.
8118 if No (Ent) then
8119 return;
8120 end if;
8122 elsif Nkind (Exp) = N_Explicit_Dereference then
8123 declare
8124 P : constant Node_Id := Prefix (Exp);
8126 begin
8127 if Nkind (P) = N_Selected_Component
8128 and then Present (
8129 Entry_Formal (Entity (Selector_Name (P))))
8130 then
8131 -- Case of a reference to an entry formal
8133 Ent := Entry_Formal (Entity (Selector_Name (P)));
8135 elsif Nkind (P) = N_Identifier
8136 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
8137 and then Present (Expression (Parent (Entity (P))))
8138 and then Nkind (Expression (Parent (Entity (P))))
8139 = N_Reference
8140 then
8141 -- Case of a reference to a value on which side effects have
8142 -- been removed.
8144 Exp := Prefix (Expression (Parent (Entity (P))));
8145 goto Continue;
8147 else
8148 return;
8150 end if;
8151 end;
8153 elsif Nkind (Exp) = N_Type_Conversion
8154 or else Nkind (Exp) = N_Unchecked_Type_Conversion
8155 then
8156 Exp := Expression (Exp);
8157 goto Continue;
8159 elsif Nkind (Exp) = N_Slice
8160 or else Nkind (Exp) = N_Indexed_Component
8161 or else Nkind (Exp) = N_Selected_Component
8162 then
8163 Exp := Prefix (Exp);
8164 goto Continue;
8166 else
8167 return;
8168 end if;
8170 -- Now look for entity being referenced
8172 if Present (Ent) then
8173 if Is_Object (Ent) then
8174 if Comes_From_Source (Exp)
8175 or else Modification_Comes_From_Source
8176 then
8177 if Has_Pragma_Unmodified (Ent) then
8178 Error_Msg_NE ("?pragma Unmodified given for &!", N, Ent);
8179 end if;
8181 Set_Never_Set_In_Source (Ent, False);
8182 end if;
8184 Set_Is_True_Constant (Ent, False);
8185 Set_Current_Value (Ent, Empty);
8186 Set_Is_Known_Null (Ent, False);
8188 if not Can_Never_Be_Null (Ent) then
8189 Set_Is_Known_Non_Null (Ent, False);
8190 end if;
8192 -- Follow renaming chain
8194 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
8195 and then Present (Renamed_Object (Ent))
8196 then
8197 Exp := Renamed_Object (Ent);
8198 goto Continue;
8199 end if;
8201 -- Generate a reference only if the assignment comes from
8202 -- source. This excludes, for example, calls to a dispatching
8203 -- assignment operation when the left-hand side is tagged.
8205 if Modification_Comes_From_Source then
8206 Generate_Reference (Ent, Exp, 'm');
8207 end if;
8209 Check_Nested_Access (Ent);
8210 end if;
8212 Kill_Checks (Ent);
8214 -- If we are sure this is a modification from source, and we know
8215 -- this modifies a constant, then give an appropriate warning.
8217 if Overlays_Constant (Ent)
8218 and then Modification_Comes_From_Source
8219 and then Sure
8220 then
8221 declare
8222 A : constant Node_Id := Address_Clause (Ent);
8223 begin
8224 if Present (A) then
8225 declare
8226 Exp : constant Node_Id := Expression (A);
8227 begin
8228 if Nkind (Exp) = N_Attribute_Reference
8229 and then Attribute_Name (Exp) = Name_Address
8230 and then Is_Entity_Name (Prefix (Exp))
8231 then
8232 Error_Msg_Sloc := Sloc (A);
8233 Error_Msg_NE
8234 ("constant& may be modified via address clause#?",
8235 N, Entity (Prefix (Exp)));
8236 end if;
8237 end;
8238 end if;
8239 end;
8240 end if;
8242 return;
8243 end if;
8244 end loop;
8245 end Note_Possible_Modification;
8247 -------------------------
8248 -- Object_Access_Level --
8249 -------------------------
8251 function Object_Access_Level (Obj : Node_Id) return Uint is
8252 E : Entity_Id;
8254 -- Returns the static accessibility level of the view denoted by Obj. Note
8255 -- that the value returned is the result of a call to Scope_Depth. Only
8256 -- scope depths associated with dynamic scopes can actually be returned.
8257 -- Since only relative levels matter for accessibility checking, the fact
8258 -- that the distance between successive levels of accessibility is not
8259 -- always one is immaterial (invariant: if level(E2) is deeper than
8260 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
8262 function Reference_To (Obj : Node_Id) return Node_Id;
8263 -- An explicit dereference is created when removing side-effects from
8264 -- expressions for constraint checking purposes. In this case a local
8265 -- access type is created for it. The correct access level is that of
8266 -- the original source node. We detect this case by noting that the
8267 -- prefix of the dereference is created by an object declaration whose
8268 -- initial expression is a reference.
8270 ------------------
8271 -- Reference_To --
8272 ------------------
8274 function Reference_To (Obj : Node_Id) return Node_Id is
8275 Pref : constant Node_Id := Prefix (Obj);
8276 begin
8277 if Is_Entity_Name (Pref)
8278 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
8279 and then Present (Expression (Parent (Entity (Pref))))
8280 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
8281 then
8282 return (Prefix (Expression (Parent (Entity (Pref)))));
8283 else
8284 return Empty;
8285 end if;
8286 end Reference_To;
8288 -- Start of processing for Object_Access_Level
8290 begin
8291 if Is_Entity_Name (Obj) then
8292 E := Entity (Obj);
8294 if Is_Prival (E) then
8295 E := Prival_Link (E);
8296 end if;
8298 -- If E is a type then it denotes a current instance. For this case
8299 -- we add one to the normal accessibility level of the type to ensure
8300 -- that current instances are treated as always being deeper than
8301 -- than the level of any visible named access type (see 3.10.2(21)).
8303 if Is_Type (E) then
8304 return Type_Access_Level (E) + 1;
8306 elsif Present (Renamed_Object (E)) then
8307 return Object_Access_Level (Renamed_Object (E));
8309 -- Similarly, if E is a component of the current instance of a
8310 -- protected type, any instance of it is assumed to be at a deeper
8311 -- level than the type. For a protected object (whose type is an
8312 -- anonymous protected type) its components are at the same level
8313 -- as the type itself.
8315 elsif not Is_Overloadable (E)
8316 and then Ekind (Scope (E)) = E_Protected_Type
8317 and then Comes_From_Source (Scope (E))
8318 then
8319 return Type_Access_Level (Scope (E)) + 1;
8321 else
8322 return Scope_Depth (Enclosing_Dynamic_Scope (E));
8323 end if;
8325 elsif Nkind (Obj) = N_Selected_Component then
8326 if Is_Access_Type (Etype (Prefix (Obj))) then
8327 return Type_Access_Level (Etype (Prefix (Obj)));
8328 else
8329 return Object_Access_Level (Prefix (Obj));
8330 end if;
8332 elsif Nkind (Obj) = N_Indexed_Component then
8333 if Is_Access_Type (Etype (Prefix (Obj))) then
8334 return Type_Access_Level (Etype (Prefix (Obj)));
8335 else
8336 return Object_Access_Level (Prefix (Obj));
8337 end if;
8339 elsif Nkind (Obj) = N_Explicit_Dereference then
8341 -- If the prefix is a selected access discriminant then we make a
8342 -- recursive call on the prefix, which will in turn check the level
8343 -- of the prefix object of the selected discriminant.
8345 if Nkind (Prefix (Obj)) = N_Selected_Component
8346 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
8347 and then
8348 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
8349 then
8350 return Object_Access_Level (Prefix (Obj));
8352 elsif not (Comes_From_Source (Obj)) then
8353 declare
8354 Ref : constant Node_Id := Reference_To (Obj);
8355 begin
8356 if Present (Ref) then
8357 return Object_Access_Level (Ref);
8358 else
8359 return Type_Access_Level (Etype (Prefix (Obj)));
8360 end if;
8361 end;
8363 else
8364 return Type_Access_Level (Etype (Prefix (Obj)));
8365 end if;
8367 elsif Nkind (Obj) = N_Type_Conversion
8368 or else Nkind (Obj) = N_Unchecked_Type_Conversion
8369 then
8370 return Object_Access_Level (Expression (Obj));
8372 -- Function results are objects, so we get either the access level of
8373 -- the function or, in the case of an indirect call, the level of of the
8374 -- access-to-subprogram type.
8376 elsif Nkind (Obj) = N_Function_Call then
8377 if Is_Entity_Name (Name (Obj)) then
8378 return Subprogram_Access_Level (Entity (Name (Obj)));
8379 else
8380 return Type_Access_Level (Etype (Prefix (Name (Obj))));
8381 end if;
8383 -- For convenience we handle qualified expressions, even though
8384 -- they aren't technically object names.
8386 elsif Nkind (Obj) = N_Qualified_Expression then
8387 return Object_Access_Level (Expression (Obj));
8389 -- Otherwise return the scope level of Standard.
8390 -- (If there are cases that fall through
8391 -- to this point they will be treated as
8392 -- having global accessibility for now. ???)
8394 else
8395 return Scope_Depth (Standard_Standard);
8396 end if;
8397 end Object_Access_Level;
8399 -----------------------
8400 -- Private_Component --
8401 -----------------------
8403 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
8404 Ancestor : constant Entity_Id := Base_Type (Type_Id);
8406 function Trace_Components
8407 (T : Entity_Id;
8408 Check : Boolean) return Entity_Id;
8409 -- Recursive function that does the work, and checks against circular
8410 -- definition for each subcomponent type.
8412 ----------------------
8413 -- Trace_Components --
8414 ----------------------
8416 function Trace_Components
8417 (T : Entity_Id;
8418 Check : Boolean) return Entity_Id
8420 Btype : constant Entity_Id := Base_Type (T);
8421 Component : Entity_Id;
8422 P : Entity_Id;
8423 Candidate : Entity_Id := Empty;
8425 begin
8426 if Check and then Btype = Ancestor then
8427 Error_Msg_N ("circular type definition", Type_Id);
8428 return Any_Type;
8429 end if;
8431 if Is_Private_Type (Btype)
8432 and then not Is_Generic_Type (Btype)
8433 then
8434 if Present (Full_View (Btype))
8435 and then Is_Record_Type (Full_View (Btype))
8436 and then not Is_Frozen (Btype)
8437 then
8438 -- To indicate that the ancestor depends on a private type, the
8439 -- current Btype is sufficient. However, to check for circular
8440 -- definition we must recurse on the full view.
8442 Candidate := Trace_Components (Full_View (Btype), True);
8444 if Candidate = Any_Type then
8445 return Any_Type;
8446 else
8447 return Btype;
8448 end if;
8450 else
8451 return Btype;
8452 end if;
8454 elsif Is_Array_Type (Btype) then
8455 return Trace_Components (Component_Type (Btype), True);
8457 elsif Is_Record_Type (Btype) then
8458 Component := First_Entity (Btype);
8459 while Present (Component) loop
8461 -- Skip anonymous types generated by constrained components
8463 if not Is_Type (Component) then
8464 P := Trace_Components (Etype (Component), True);
8466 if Present (P) then
8467 if P = Any_Type then
8468 return P;
8469 else
8470 Candidate := P;
8471 end if;
8472 end if;
8473 end if;
8475 Next_Entity (Component);
8476 end loop;
8478 return Candidate;
8480 else
8481 return Empty;
8482 end if;
8483 end Trace_Components;
8485 -- Start of processing for Private_Component
8487 begin
8488 return Trace_Components (Type_Id, False);
8489 end Private_Component;
8491 -----------------------
8492 -- Process_End_Label --
8493 -----------------------
8495 procedure Process_End_Label
8496 (N : Node_Id;
8497 Typ : Character;
8498 Ent : Entity_Id)
8500 Loc : Source_Ptr;
8501 Nam : Node_Id;
8502 Scop : Entity_Id;
8504 Label_Ref : Boolean;
8505 -- Set True if reference to end label itself is required
8507 Endl : Node_Id;
8508 -- Gets set to the operator symbol or identifier that references the
8509 -- entity Ent. For the child unit case, this is the identifier from the
8510 -- designator. For other cases, this is simply Endl.
8512 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
8513 -- N is an identifier node that appears as a parent unit reference in
8514 -- the case where Ent is a child unit. This procedure generates an
8515 -- appropriate cross-reference entry. E is the corresponding entity.
8517 -------------------------
8518 -- Generate_Parent_Ref --
8519 -------------------------
8521 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
8522 begin
8523 -- If names do not match, something weird, skip reference
8525 if Chars (E) = Chars (N) then
8527 -- Generate the reference. We do NOT consider this as a reference
8528 -- for unreferenced symbol purposes.
8530 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
8532 if Style_Check then
8533 Style.Check_Identifier (N, E);
8534 end if;
8535 end if;
8536 end Generate_Parent_Ref;
8538 -- Start of processing for Process_End_Label
8540 begin
8541 -- If no node, ignore. This happens in some error situations, and
8542 -- also for some internally generated structures where no end label
8543 -- references are required in any case.
8545 if No (N) then
8546 return;
8547 end if;
8549 -- Nothing to do if no End_Label, happens for internally generated
8550 -- constructs where we don't want an end label reference anyway. Also
8551 -- nothing to do if Endl is a string literal, which means there was
8552 -- some prior error (bad operator symbol)
8554 Endl := End_Label (N);
8556 if No (Endl) or else Nkind (Endl) = N_String_Literal then
8557 return;
8558 end if;
8560 -- Reference node is not in extended main source unit
8562 if not In_Extended_Main_Source_Unit (N) then
8564 -- Generally we do not collect references except for the extended
8565 -- main source unit. The one exception is the 'e' entry for a
8566 -- package spec, where it is useful for a client to have the
8567 -- ending information to define scopes.
8569 if Typ /= 'e' then
8570 return;
8572 else
8573 Label_Ref := False;
8575 -- For this case, we can ignore any parent references, but we
8576 -- need the package name itself for the 'e' entry.
8578 if Nkind (Endl) = N_Designator then
8579 Endl := Identifier (Endl);
8580 end if;
8581 end if;
8583 -- Reference is in extended main source unit
8585 else
8586 Label_Ref := True;
8588 -- For designator, generate references for the parent entries
8590 if Nkind (Endl) = N_Designator then
8592 -- Generate references for the prefix if the END line comes from
8593 -- source (otherwise we do not need these references) We climb the
8594 -- scope stack to find the expected entities.
8596 if Comes_From_Source (Endl) then
8597 Nam := Name (Endl);
8598 Scop := Current_Scope;
8599 while Nkind (Nam) = N_Selected_Component loop
8600 Scop := Scope (Scop);
8601 exit when No (Scop);
8602 Generate_Parent_Ref (Selector_Name (Nam), Scop);
8603 Nam := Prefix (Nam);
8604 end loop;
8606 if Present (Scop) then
8607 Generate_Parent_Ref (Nam, Scope (Scop));
8608 end if;
8609 end if;
8611 Endl := Identifier (Endl);
8612 end if;
8613 end if;
8615 -- If the end label is not for the given entity, then either we have
8616 -- some previous error, or this is a generic instantiation for which
8617 -- we do not need to make a cross-reference in this case anyway. In
8618 -- either case we simply ignore the call.
8620 if Chars (Ent) /= Chars (Endl) then
8621 return;
8622 end if;
8624 -- If label was really there, then generate a normal reference and then
8625 -- adjust the location in the end label to point past the name (which
8626 -- should almost always be the semicolon).
8628 Loc := Sloc (Endl);
8630 if Comes_From_Source (Endl) then
8632 -- If a label reference is required, then do the style check and
8633 -- generate an l-type cross-reference entry for the label
8635 if Label_Ref then
8636 if Style_Check then
8637 Style.Check_Identifier (Endl, Ent);
8638 end if;
8640 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
8641 end if;
8643 -- Set the location to point past the label (normally this will
8644 -- mean the semicolon immediately following the label). This is
8645 -- done for the sake of the 'e' or 't' entry generated below.
8647 Get_Decoded_Name_String (Chars (Endl));
8648 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
8649 end if;
8651 -- Now generate the e/t reference
8653 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
8655 -- Restore Sloc, in case modified above, since we have an identifier
8656 -- and the normal Sloc should be left set in the tree.
8658 Set_Sloc (Endl, Loc);
8659 end Process_End_Label;
8661 ------------------
8662 -- Real_Convert --
8663 ------------------
8665 -- We do the conversion to get the value of the real string by using
8666 -- the scanner, see Sinput for details on use of the internal source
8667 -- buffer for scanning internal strings.
8669 function Real_Convert (S : String) return Node_Id is
8670 Save_Src : constant Source_Buffer_Ptr := Source;
8671 Negative : Boolean;
8673 begin
8674 Source := Internal_Source_Ptr;
8675 Scan_Ptr := 1;
8677 for J in S'Range loop
8678 Source (Source_Ptr (J)) := S (J);
8679 end loop;
8681 Source (S'Length + 1) := EOF;
8683 if Source (Scan_Ptr) = '-' then
8684 Negative := True;
8685 Scan_Ptr := Scan_Ptr + 1;
8686 else
8687 Negative := False;
8688 end if;
8690 Scan;
8692 if Negative then
8693 Set_Realval (Token_Node, UR_Negate (Realval (Token_Node)));
8694 end if;
8696 Source := Save_Src;
8697 return Token_Node;
8698 end Real_Convert;
8700 ---------------------
8701 -- Rep_To_Pos_Flag --
8702 ---------------------
8704 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
8705 begin
8706 return New_Occurrence_Of
8707 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
8708 end Rep_To_Pos_Flag;
8710 --------------------
8711 -- Require_Entity --
8712 --------------------
8714 procedure Require_Entity (N : Node_Id) is
8715 begin
8716 if Is_Entity_Name (N) and then No (Entity (N)) then
8717 if Total_Errors_Detected /= 0 then
8718 Set_Entity (N, Any_Id);
8719 else
8720 raise Program_Error;
8721 end if;
8722 end if;
8723 end Require_Entity;
8725 ------------------------------
8726 -- Requires_Transient_Scope --
8727 ------------------------------
8729 -- A transient scope is required when variable-sized temporaries are
8730 -- allocated in the primary or secondary stack, or when finalization
8731 -- actions must be generated before the next instruction.
8733 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
8734 Typ : constant Entity_Id := Underlying_Type (Id);
8736 -- Start of processing for Requires_Transient_Scope
8738 begin
8739 -- This is a private type which is not completed yet. This can only
8740 -- happen in a default expression (of a formal parameter or of a
8741 -- record component). Do not expand transient scope in this case
8743 if No (Typ) then
8744 return False;
8746 -- Do not expand transient scope for non-existent procedure return
8748 elsif Typ = Standard_Void_Type then
8749 return False;
8751 -- Elementary types do not require a transient scope
8753 elsif Is_Elementary_Type (Typ) then
8754 return False;
8756 -- Generally, indefinite subtypes require a transient scope, since the
8757 -- back end cannot generate temporaries, since this is not a valid type
8758 -- for declaring an object. It might be possible to relax this in the
8759 -- future, e.g. by declaring the maximum possible space for the type.
8761 elsif Is_Indefinite_Subtype (Typ) then
8762 return True;
8764 -- Functions returning tagged types may dispatch on result so their
8765 -- returned value is allocated on the secondary stack. Controlled
8766 -- type temporaries need finalization.
8768 elsif Is_Tagged_Type (Typ)
8769 or else Has_Controlled_Component (Typ)
8770 then
8771 return not Is_Value_Type (Typ);
8773 -- Record type
8775 elsif Is_Record_Type (Typ) then
8776 declare
8777 Comp : Entity_Id;
8778 begin
8779 Comp := First_Entity (Typ);
8780 while Present (Comp) loop
8781 if Ekind (Comp) = E_Component
8782 and then Requires_Transient_Scope (Etype (Comp))
8783 then
8784 return True;
8785 else
8786 Next_Entity (Comp);
8787 end if;
8788 end loop;
8789 end;
8791 return False;
8793 -- String literal types never require transient scope
8795 elsif Ekind (Typ) = E_String_Literal_Subtype then
8796 return False;
8798 -- Array type. Note that we already know that this is a constrained
8799 -- array, since unconstrained arrays will fail the indefinite test.
8801 elsif Is_Array_Type (Typ) then
8803 -- If component type requires a transient scope, the array does too
8805 if Requires_Transient_Scope (Component_Type (Typ)) then
8806 return True;
8808 -- Otherwise, we only need a transient scope if the size is not
8809 -- known at compile time.
8811 else
8812 return not Size_Known_At_Compile_Time (Typ);
8813 end if;
8815 -- All other cases do not require a transient scope
8817 else
8818 return False;
8819 end if;
8820 end Requires_Transient_Scope;
8822 --------------------------
8823 -- Reset_Analyzed_Flags --
8824 --------------------------
8826 procedure Reset_Analyzed_Flags (N : Node_Id) is
8828 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
8829 -- Function used to reset Analyzed flags in tree. Note that we do
8830 -- not reset Analyzed flags in entities, since there is no need to
8831 -- reanalyze entities, and indeed, it is wrong to do so, since it
8832 -- can result in generating auxiliary stuff more than once.
8834 --------------------
8835 -- Clear_Analyzed --
8836 --------------------
8838 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
8839 begin
8840 if not Has_Extension (N) then
8841 Set_Analyzed (N, False);
8842 end if;
8844 return OK;
8845 end Clear_Analyzed;
8847 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
8849 -- Start of processing for Reset_Analyzed_Flags
8851 begin
8852 Reset_Analyzed (N);
8853 end Reset_Analyzed_Flags;
8855 ---------------------------
8856 -- Safe_To_Capture_Value --
8857 ---------------------------
8859 function Safe_To_Capture_Value
8860 (N : Node_Id;
8861 Ent : Entity_Id;
8862 Cond : Boolean := False) return Boolean
8864 begin
8865 -- The only entities for which we track constant values are variables
8866 -- which are not renamings, constants, out parameters, and in out
8867 -- parameters, so check if we have this case.
8869 -- Note: it may seem odd to track constant values for constants, but in
8870 -- fact this routine is used for other purposes than simply capturing
8871 -- the value. In particular, the setting of Known[_Non]_Null.
8873 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
8874 or else
8875 Ekind (Ent) = E_Constant
8876 or else
8877 Ekind (Ent) = E_Out_Parameter
8878 or else
8879 Ekind (Ent) = E_In_Out_Parameter
8880 then
8881 null;
8883 -- For conditionals, we also allow loop parameters and all formals,
8884 -- including in parameters.
8886 elsif Cond
8887 and then
8888 (Ekind (Ent) = E_Loop_Parameter
8889 or else
8890 Ekind (Ent) = E_In_Parameter)
8891 then
8892 null;
8894 -- For all other cases, not just unsafe, but impossible to capture
8895 -- Current_Value, since the above are the only entities which have
8896 -- Current_Value fields.
8898 else
8899 return False;
8900 end if;
8902 -- Skip if volatile or aliased, since funny things might be going on in
8903 -- these cases which we cannot necessarily track. Also skip any variable
8904 -- for which an address clause is given, or whose address is taken. Also
8905 -- never capture value of library level variables (an attempt to do so
8906 -- can occur in the case of package elaboration code).
8908 if Treat_As_Volatile (Ent)
8909 or else Is_Aliased (Ent)
8910 or else Present (Address_Clause (Ent))
8911 or else Address_Taken (Ent)
8912 or else (Is_Library_Level_Entity (Ent)
8913 and then Ekind (Ent) = E_Variable)
8914 then
8915 return False;
8916 end if;
8918 -- OK, all above conditions are met. We also require that the scope of
8919 -- the reference be the same as the scope of the entity, not counting
8920 -- packages and blocks and loops.
8922 declare
8923 E_Scope : constant Entity_Id := Scope (Ent);
8924 R_Scope : Entity_Id;
8926 begin
8927 R_Scope := Current_Scope;
8928 while R_Scope /= Standard_Standard loop
8929 exit when R_Scope = E_Scope;
8931 if Ekind (R_Scope) /= E_Package
8932 and then
8933 Ekind (R_Scope) /= E_Block
8934 and then
8935 Ekind (R_Scope) /= E_Loop
8936 then
8937 return False;
8938 else
8939 R_Scope := Scope (R_Scope);
8940 end if;
8941 end loop;
8942 end;
8944 -- We also require that the reference does not appear in a context
8945 -- where it is not sure to be executed (i.e. a conditional context
8946 -- or an exception handler). We skip this if Cond is True, since the
8947 -- capturing of values from conditional tests handles this ok.
8949 if Cond then
8950 return True;
8951 end if;
8953 declare
8954 Desc : Node_Id;
8955 P : Node_Id;
8957 begin
8958 Desc := N;
8960 P := Parent (N);
8961 while Present (P) loop
8962 if Nkind (P) = N_If_Statement
8963 or else Nkind (P) = N_Case_Statement
8964 or else (Nkind (P) = N_And_Then and then Desc = Right_Opnd (P))
8965 or else (Nkind (P) = N_Or_Else and then Desc = Right_Opnd (P))
8966 or else Nkind (P) = N_Exception_Handler
8967 or else Nkind (P) = N_Selective_Accept
8968 or else Nkind (P) = N_Conditional_Entry_Call
8969 or else Nkind (P) = N_Timed_Entry_Call
8970 or else Nkind (P) = N_Asynchronous_Select
8971 then
8972 return False;
8973 else
8974 Desc := P;
8975 P := Parent (P);
8976 end if;
8977 end loop;
8978 end;
8980 -- OK, looks safe to set value
8982 return True;
8983 end Safe_To_Capture_Value;
8985 ---------------
8986 -- Same_Name --
8987 ---------------
8989 function Same_Name (N1, N2 : Node_Id) return Boolean is
8990 K1 : constant Node_Kind := Nkind (N1);
8991 K2 : constant Node_Kind := Nkind (N2);
8993 begin
8994 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
8995 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
8996 then
8997 return Chars (N1) = Chars (N2);
8999 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
9000 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
9001 then
9002 return Same_Name (Selector_Name (N1), Selector_Name (N2))
9003 and then Same_Name (Prefix (N1), Prefix (N2));
9005 else
9006 return False;
9007 end if;
9008 end Same_Name;
9010 -----------------
9011 -- Same_Object --
9012 -----------------
9014 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
9015 N1 : constant Node_Id := Original_Node (Node1);
9016 N2 : constant Node_Id := Original_Node (Node2);
9017 -- We do the tests on original nodes, since we are most interested
9018 -- in the original source, not any expansion that got in the way.
9020 K1 : constant Node_Kind := Nkind (N1);
9021 K2 : constant Node_Kind := Nkind (N2);
9023 begin
9024 -- First case, both are entities with same entity
9026 if K1 in N_Has_Entity
9027 and then K2 in N_Has_Entity
9028 and then Present (Entity (N1))
9029 and then Present (Entity (N2))
9030 and then (Ekind (Entity (N1)) = E_Variable
9031 or else
9032 Ekind (Entity (N1)) = E_Constant)
9033 and then Entity (N1) = Entity (N2)
9034 then
9035 return True;
9037 -- Second case, selected component with same selector, same record
9039 elsif K1 = N_Selected_Component
9040 and then K2 = N_Selected_Component
9041 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
9042 then
9043 return Same_Object (Prefix (N1), Prefix (N2));
9045 -- Third case, indexed component with same subscripts, same array
9047 elsif K1 = N_Indexed_Component
9048 and then K2 = N_Indexed_Component
9049 and then Same_Object (Prefix (N1), Prefix (N2))
9050 then
9051 declare
9052 E1, E2 : Node_Id;
9053 begin
9054 E1 := First (Expressions (N1));
9055 E2 := First (Expressions (N2));
9056 while Present (E1) loop
9057 if not Same_Value (E1, E2) then
9058 return False;
9059 else
9060 Next (E1);
9061 Next (E2);
9062 end if;
9063 end loop;
9065 return True;
9066 end;
9068 -- Fourth case, slice of same array with same bounds
9070 elsif K1 = N_Slice
9071 and then K2 = N_Slice
9072 and then Nkind (Discrete_Range (N1)) = N_Range
9073 and then Nkind (Discrete_Range (N2)) = N_Range
9074 and then Same_Value (Low_Bound (Discrete_Range (N1)),
9075 Low_Bound (Discrete_Range (N2)))
9076 and then Same_Value (High_Bound (Discrete_Range (N1)),
9077 High_Bound (Discrete_Range (N2)))
9078 then
9079 return Same_Name (Prefix (N1), Prefix (N2));
9081 -- All other cases, not clearly the same object
9083 else
9084 return False;
9085 end if;
9086 end Same_Object;
9088 ---------------
9089 -- Same_Type --
9090 ---------------
9092 function Same_Type (T1, T2 : Entity_Id) return Boolean is
9093 begin
9094 if T1 = T2 then
9095 return True;
9097 elsif not Is_Constrained (T1)
9098 and then not Is_Constrained (T2)
9099 and then Base_Type (T1) = Base_Type (T2)
9100 then
9101 return True;
9103 -- For now don't bother with case of identical constraints, to be
9104 -- fiddled with later on perhaps (this is only used for optimization
9105 -- purposes, so it is not critical to do a best possible job)
9107 else
9108 return False;
9109 end if;
9110 end Same_Type;
9112 ----------------
9113 -- Same_Value --
9114 ----------------
9116 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
9117 begin
9118 if Compile_Time_Known_Value (Node1)
9119 and then Compile_Time_Known_Value (Node2)
9120 and then Expr_Value (Node1) = Expr_Value (Node2)
9121 then
9122 return True;
9123 elsif Same_Object (Node1, Node2) then
9124 return True;
9125 else
9126 return False;
9127 end if;
9128 end Same_Value;
9130 ------------------------
9131 -- Scope_Is_Transient --
9132 ------------------------
9134 function Scope_Is_Transient return Boolean is
9135 begin
9136 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
9137 end Scope_Is_Transient;
9139 ------------------
9140 -- Scope_Within --
9141 ------------------
9143 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
9144 Scop : Entity_Id;
9146 begin
9147 Scop := Scope1;
9148 while Scop /= Standard_Standard loop
9149 Scop := Scope (Scop);
9151 if Scop = Scope2 then
9152 return True;
9153 end if;
9154 end loop;
9156 return False;
9157 end Scope_Within;
9159 --------------------------
9160 -- Scope_Within_Or_Same --
9161 --------------------------
9163 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
9164 Scop : Entity_Id;
9166 begin
9167 Scop := Scope1;
9168 while Scop /= Standard_Standard loop
9169 if Scop = Scope2 then
9170 return True;
9171 else
9172 Scop := Scope (Scop);
9173 end if;
9174 end loop;
9176 return False;
9177 end Scope_Within_Or_Same;
9179 --------------------
9180 -- Set_Convention --
9181 --------------------
9183 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
9184 begin
9185 Basic_Set_Convention (E, Val);
9187 if Is_Type (E)
9188 and then Is_Access_Subprogram_Type (Base_Type (E))
9189 and then Has_Foreign_Convention (E)
9190 then
9191 Set_Can_Use_Internal_Rep (E, False);
9192 end if;
9193 end Set_Convention;
9195 ------------------------
9196 -- Set_Current_Entity --
9197 ------------------------
9199 -- The given entity is to be set as the currently visible definition
9200 -- of its associated name (i.e. the Node_Id associated with its name).
9201 -- All we have to do is to get the name from the identifier, and
9202 -- then set the associated Node_Id to point to the given entity.
9204 procedure Set_Current_Entity (E : Entity_Id) is
9205 begin
9206 Set_Name_Entity_Id (Chars (E), E);
9207 end Set_Current_Entity;
9209 ---------------------------
9210 -- Set_Debug_Info_Needed --
9211 ---------------------------
9213 procedure Set_Debug_Info_Needed (T : Entity_Id) is
9215 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
9216 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
9217 -- Used to set debug info in a related node if not set already
9219 --------------------------------------
9220 -- Set_Debug_Info_Needed_If_Not_Set --
9221 --------------------------------------
9223 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
9224 begin
9225 if Present (E)
9226 and then not Needs_Debug_Info (E)
9227 then
9228 Set_Debug_Info_Needed (E);
9229 end if;
9230 end Set_Debug_Info_Needed_If_Not_Set;
9232 -- Start of processing for Set_Debug_Info_Needed
9234 begin
9235 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
9236 -- indicates that Debug_Info_Needed is never required for the entity.
9238 if No (T)
9239 or else Debug_Info_Off (T)
9240 then
9241 return;
9242 end if;
9244 -- Set flag in entity itself. Note that we will go through the following
9245 -- circuitry even if the flag is already set on T. That's intentional,
9246 -- it makes sure that the flag will be set in subsidiary entities.
9248 Set_Needs_Debug_Info (T);
9250 -- Set flag on subsidiary entities if not set already
9252 if Is_Object (T) then
9253 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
9255 elsif Is_Type (T) then
9256 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
9258 if Is_Record_Type (T) then
9259 declare
9260 Ent : Entity_Id := First_Entity (T);
9261 begin
9262 while Present (Ent) loop
9263 Set_Debug_Info_Needed_If_Not_Set (Ent);
9264 Next_Entity (Ent);
9265 end loop;
9266 end;
9268 elsif Is_Array_Type (T) then
9269 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
9271 declare
9272 Indx : Node_Id := First_Index (T);
9273 begin
9274 while Present (Indx) loop
9275 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
9276 Indx := Next_Index (Indx);
9277 end loop;
9278 end;
9280 if Is_Packed (T) then
9281 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Type (T));
9282 end if;
9284 elsif Is_Access_Type (T) then
9285 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
9287 elsif Is_Private_Type (T) then
9288 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
9290 elsif Is_Protected_Type (T) then
9291 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
9292 end if;
9293 end if;
9294 end Set_Debug_Info_Needed;
9296 ---------------------------------
9297 -- Set_Entity_With_Style_Check --
9298 ---------------------------------
9300 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
9301 Val_Actual : Entity_Id;
9302 Nod : Node_Id;
9304 begin
9305 Set_Entity (N, Val);
9307 if Style_Check
9308 and then not Suppress_Style_Checks (Val)
9309 and then not In_Instance
9310 then
9311 if Nkind (N) = N_Identifier then
9312 Nod := N;
9313 elsif Nkind (N) = N_Expanded_Name then
9314 Nod := Selector_Name (N);
9315 else
9316 return;
9317 end if;
9319 -- A special situation arises for derived operations, where we want
9320 -- to do the check against the parent (since the Sloc of the derived
9321 -- operation points to the derived type declaration itself).
9323 Val_Actual := Val;
9324 while not Comes_From_Source (Val_Actual)
9325 and then Nkind (Val_Actual) in N_Entity
9326 and then (Ekind (Val_Actual) = E_Enumeration_Literal
9327 or else Is_Subprogram (Val_Actual)
9328 or else Is_Generic_Subprogram (Val_Actual))
9329 and then Present (Alias (Val_Actual))
9330 loop
9331 Val_Actual := Alias (Val_Actual);
9332 end loop;
9334 -- Renaming declarations for generic actuals do not come from source,
9335 -- and have a different name from that of the entity they rename, so
9336 -- there is no style check to perform here.
9338 if Chars (Nod) = Chars (Val_Actual) then
9339 Style.Check_Identifier (Nod, Val_Actual);
9340 end if;
9341 end if;
9343 Set_Entity (N, Val);
9344 end Set_Entity_With_Style_Check;
9346 ------------------------
9347 -- Set_Name_Entity_Id --
9348 ------------------------
9350 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
9351 begin
9352 Set_Name_Table_Info (Id, Int (Val));
9353 end Set_Name_Entity_Id;
9355 ---------------------
9356 -- Set_Next_Actual --
9357 ---------------------
9359 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
9360 begin
9361 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
9362 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
9363 end if;
9364 end Set_Next_Actual;
9366 ----------------------------------
9367 -- Set_Optimize_Alignment_Flags --
9368 ----------------------------------
9370 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
9371 begin
9372 if Optimize_Alignment = 'S' then
9373 Set_Optimize_Alignment_Space (E);
9374 elsif Optimize_Alignment = 'T' then
9375 Set_Optimize_Alignment_Time (E);
9376 end if;
9377 end Set_Optimize_Alignment_Flags;
9379 -----------------------
9380 -- Set_Public_Status --
9381 -----------------------
9383 procedure Set_Public_Status (Id : Entity_Id) is
9384 S : constant Entity_Id := Current_Scope;
9386 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
9387 -- Determines if E is defined within handled statement sequence or
9388 -- an if statement, returns True if so, False otherwise.
9390 ----------------------
9391 -- Within_HSS_Or_If --
9392 ----------------------
9394 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
9395 N : Node_Id;
9396 begin
9397 N := Declaration_Node (E);
9398 loop
9399 N := Parent (N);
9401 if No (N) then
9402 return False;
9404 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
9405 N_If_Statement)
9406 then
9407 return True;
9408 end if;
9409 end loop;
9410 end Within_HSS_Or_If;
9412 -- Start of processing for Set_Public_Status
9414 begin
9415 -- Everything in the scope of Standard is public
9417 if S = Standard_Standard then
9418 Set_Is_Public (Id);
9420 -- Entity is definitely not public if enclosing scope is not public
9422 elsif not Is_Public (S) then
9423 return;
9425 -- An object or function declaration that occurs in a handled sequence
9426 -- of statements or within an if statement is the declaration for a
9427 -- temporary object or local subprogram generated by the expander. It
9428 -- never needs to be made public and furthermore, making it public can
9429 -- cause back end problems.
9431 elsif Nkind_In (Parent (Id), N_Object_Declaration,
9432 N_Function_Specification)
9433 and then Within_HSS_Or_If (Id)
9434 then
9435 return;
9437 -- Entities in public packages or records are public
9439 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
9440 Set_Is_Public (Id);
9442 -- The bounds of an entry family declaration can generate object
9443 -- declarations that are visible to the back-end, e.g. in the
9444 -- the declaration of a composite type that contains tasks.
9446 elsif Is_Concurrent_Type (S)
9447 and then not Has_Completion (S)
9448 and then Nkind (Parent (Id)) = N_Object_Declaration
9449 then
9450 Set_Is_Public (Id);
9451 end if;
9452 end Set_Public_Status;
9454 -----------------------------
9455 -- Set_Referenced_Modified --
9456 -----------------------------
9458 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
9459 Pref : Node_Id;
9461 begin
9462 -- Deal with indexed or selected component where prefix is modified
9464 if Nkind (N) = N_Indexed_Component
9465 or else
9466 Nkind (N) = N_Selected_Component
9467 then
9468 Pref := Prefix (N);
9470 -- If prefix is access type, then it is the designated object that is
9471 -- being modified, which means we have no entity to set the flag on.
9473 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
9474 return;
9476 -- Otherwise chase the prefix
9478 else
9479 Set_Referenced_Modified (Pref, Out_Param);
9480 end if;
9482 -- Otherwise see if we have an entity name (only other case to process)
9484 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
9485 Set_Referenced_As_LHS (Entity (N), not Out_Param);
9486 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
9487 end if;
9488 end Set_Referenced_Modified;
9490 ----------------------------
9491 -- Set_Scope_Is_Transient --
9492 ----------------------------
9494 procedure Set_Scope_Is_Transient (V : Boolean := True) is
9495 begin
9496 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
9497 end Set_Scope_Is_Transient;
9499 -------------------
9500 -- Set_Size_Info --
9501 -------------------
9503 procedure Set_Size_Info (T1, T2 : Entity_Id) is
9504 begin
9505 -- We copy Esize, but not RM_Size, since in general RM_Size is
9506 -- subtype specific and does not get inherited by all subtypes.
9508 Set_Esize (T1, Esize (T2));
9509 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
9511 if Is_Discrete_Or_Fixed_Point_Type (T1)
9512 and then
9513 Is_Discrete_Or_Fixed_Point_Type (T2)
9514 then
9515 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
9516 end if;
9518 Set_Alignment (T1, Alignment (T2));
9519 end Set_Size_Info;
9521 --------------------
9522 -- Static_Integer --
9523 --------------------
9525 function Static_Integer (N : Node_Id) return Uint is
9526 begin
9527 Analyze_And_Resolve (N, Any_Integer);
9529 if N = Error
9530 or else Error_Posted (N)
9531 or else Etype (N) = Any_Type
9532 then
9533 return No_Uint;
9534 end if;
9536 if Is_Static_Expression (N) then
9537 if not Raises_Constraint_Error (N) then
9538 return Expr_Value (N);
9539 else
9540 return No_Uint;
9541 end if;
9543 elsif Etype (N) = Any_Type then
9544 return No_Uint;
9546 else
9547 Flag_Non_Static_Expr
9548 ("static integer expression required here", N);
9549 return No_Uint;
9550 end if;
9551 end Static_Integer;
9553 --------------------------
9554 -- Statically_Different --
9555 --------------------------
9557 function Statically_Different (E1, E2 : Node_Id) return Boolean is
9558 R1 : constant Node_Id := Get_Referenced_Object (E1);
9559 R2 : constant Node_Id := Get_Referenced_Object (E2);
9560 begin
9561 return Is_Entity_Name (R1)
9562 and then Is_Entity_Name (R2)
9563 and then Entity (R1) /= Entity (R2)
9564 and then not Is_Formal (Entity (R1))
9565 and then not Is_Formal (Entity (R2));
9566 end Statically_Different;
9568 -----------------------------
9569 -- Subprogram_Access_Level --
9570 -----------------------------
9572 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
9573 begin
9574 if Present (Alias (Subp)) then
9575 return Subprogram_Access_Level (Alias (Subp));
9576 else
9577 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
9578 end if;
9579 end Subprogram_Access_Level;
9581 -----------------
9582 -- Trace_Scope --
9583 -----------------
9585 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
9586 begin
9587 if Debug_Flag_W then
9588 for J in 0 .. Scope_Stack.Last loop
9589 Write_Str (" ");
9590 end loop;
9592 Write_Str (Msg);
9593 Write_Name (Chars (E));
9594 Write_Str (" from ");
9595 Write_Location (Sloc (N));
9596 Write_Eol;
9597 end if;
9598 end Trace_Scope;
9600 -----------------------
9601 -- Transfer_Entities --
9602 -----------------------
9604 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
9605 Ent : Entity_Id := First_Entity (From);
9607 begin
9608 if No (Ent) then
9609 return;
9610 end if;
9612 if (Last_Entity (To)) = Empty then
9613 Set_First_Entity (To, Ent);
9614 else
9615 Set_Next_Entity (Last_Entity (To), Ent);
9616 end if;
9618 Set_Last_Entity (To, Last_Entity (From));
9620 while Present (Ent) loop
9621 Set_Scope (Ent, To);
9623 if not Is_Public (Ent) then
9624 Set_Public_Status (Ent);
9626 if Is_Public (Ent)
9627 and then Ekind (Ent) = E_Record_Subtype
9629 then
9630 -- The components of the propagated Itype must be public
9631 -- as well.
9633 declare
9634 Comp : Entity_Id;
9635 begin
9636 Comp := First_Entity (Ent);
9637 while Present (Comp) loop
9638 Set_Is_Public (Comp);
9639 Next_Entity (Comp);
9640 end loop;
9641 end;
9642 end if;
9643 end if;
9645 Next_Entity (Ent);
9646 end loop;
9648 Set_First_Entity (From, Empty);
9649 Set_Last_Entity (From, Empty);
9650 end Transfer_Entities;
9652 -----------------------
9653 -- Type_Access_Level --
9654 -----------------------
9656 function Type_Access_Level (Typ : Entity_Id) return Uint is
9657 Btyp : Entity_Id;
9659 begin
9660 Btyp := Base_Type (Typ);
9662 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
9663 -- simply use the level where the type is declared. This is true for
9664 -- stand-alone object declarations, and for anonymous access types
9665 -- associated with components the level is the same as that of the
9666 -- enclosing composite type. However, special treatment is needed for
9667 -- the cases of access parameters, return objects of an anonymous access
9668 -- type, and, in Ada 95, access discriminants of limited types.
9670 if Ekind (Btyp) in Access_Kind then
9671 if Ekind (Btyp) = E_Anonymous_Access_Type then
9673 -- If the type is a nonlocal anonymous access type (such as for
9674 -- an access parameter) we treat it as being declared at the
9675 -- library level to ensure that names such as X.all'access don't
9676 -- fail static accessibility checks.
9678 if not Is_Local_Anonymous_Access (Typ) then
9679 return Scope_Depth (Standard_Standard);
9681 -- If this is a return object, the accessibility level is that of
9682 -- the result subtype of the enclosing function. The test here is
9683 -- little complicated, because we have to account for extended
9684 -- return statements that have been rewritten as blocks, in which
9685 -- case we have to find and the Is_Return_Object attribute of the
9686 -- itype's associated object. It would be nice to find a way to
9687 -- simplify this test, but it doesn't seem worthwhile to add a new
9688 -- flag just for purposes of this test. ???
9690 elsif Ekind (Scope (Btyp)) = E_Return_Statement
9691 or else
9692 (Is_Itype (Btyp)
9693 and then Nkind (Associated_Node_For_Itype (Btyp)) =
9694 N_Object_Declaration
9695 and then Is_Return_Object
9696 (Defining_Identifier
9697 (Associated_Node_For_Itype (Btyp))))
9698 then
9699 declare
9700 Scop : Entity_Id;
9702 begin
9703 Scop := Scope (Scope (Btyp));
9704 while Present (Scop) loop
9705 exit when Ekind (Scop) = E_Function;
9706 Scop := Scope (Scop);
9707 end loop;
9709 -- Treat the return object's type as having the level of the
9710 -- function's result subtype (as per RM05-6.5(5.3/2)).
9712 return Type_Access_Level (Etype (Scop));
9713 end;
9714 end if;
9715 end if;
9717 Btyp := Root_Type (Btyp);
9719 -- The accessibility level of anonymous access types associated with
9720 -- discriminants is that of the current instance of the type, and
9721 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
9723 -- AI-402: access discriminants have accessibility based on the
9724 -- object rather than the type in Ada 2005, so the above paragraph
9725 -- doesn't apply.
9727 -- ??? Needs completion with rules from AI-416
9729 if Ada_Version <= Ada_95
9730 and then Ekind (Typ) = E_Anonymous_Access_Type
9731 and then Present (Associated_Node_For_Itype (Typ))
9732 and then Nkind (Associated_Node_For_Itype (Typ)) =
9733 N_Discriminant_Specification
9734 then
9735 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
9736 end if;
9737 end if;
9739 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
9740 end Type_Access_Level;
9742 --------------------------
9743 -- Unit_Declaration_Node --
9744 --------------------------
9746 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
9747 N : Node_Id := Parent (Unit_Id);
9749 begin
9750 -- Predefined operators do not have a full function declaration
9752 if Ekind (Unit_Id) = E_Operator then
9753 return N;
9754 end if;
9756 -- Isn't there some better way to express the following ???
9758 while Nkind (N) /= N_Abstract_Subprogram_Declaration
9759 and then Nkind (N) /= N_Formal_Package_Declaration
9760 and then Nkind (N) /= N_Function_Instantiation
9761 and then Nkind (N) /= N_Generic_Package_Declaration
9762 and then Nkind (N) /= N_Generic_Subprogram_Declaration
9763 and then Nkind (N) /= N_Package_Declaration
9764 and then Nkind (N) /= N_Package_Body
9765 and then Nkind (N) /= N_Package_Instantiation
9766 and then Nkind (N) /= N_Package_Renaming_Declaration
9767 and then Nkind (N) /= N_Procedure_Instantiation
9768 and then Nkind (N) /= N_Protected_Body
9769 and then Nkind (N) /= N_Subprogram_Declaration
9770 and then Nkind (N) /= N_Subprogram_Body
9771 and then Nkind (N) /= N_Subprogram_Body_Stub
9772 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
9773 and then Nkind (N) /= N_Task_Body
9774 and then Nkind (N) /= N_Task_Type_Declaration
9775 and then Nkind (N) not in N_Formal_Subprogram_Declaration
9776 and then Nkind (N) not in N_Generic_Renaming_Declaration
9777 loop
9778 N := Parent (N);
9779 pragma Assert (Present (N));
9780 end loop;
9782 return N;
9783 end Unit_Declaration_Node;
9785 ------------------------------
9786 -- Universal_Interpretation --
9787 ------------------------------
9789 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
9790 Index : Interp_Index;
9791 It : Interp;
9793 begin
9794 -- The argument may be a formal parameter of an operator or subprogram
9795 -- with multiple interpretations, or else an expression for an actual.
9797 if Nkind (Opnd) = N_Defining_Identifier
9798 or else not Is_Overloaded (Opnd)
9799 then
9800 if Etype (Opnd) = Universal_Integer
9801 or else Etype (Opnd) = Universal_Real
9802 then
9803 return Etype (Opnd);
9804 else
9805 return Empty;
9806 end if;
9808 else
9809 Get_First_Interp (Opnd, Index, It);
9810 while Present (It.Typ) loop
9811 if It.Typ = Universal_Integer
9812 or else It.Typ = Universal_Real
9813 then
9814 return It.Typ;
9815 end if;
9817 Get_Next_Interp (Index, It);
9818 end loop;
9820 return Empty;
9821 end if;
9822 end Universal_Interpretation;
9824 ---------------
9825 -- Unqualify --
9826 ---------------
9828 function Unqualify (Expr : Node_Id) return Node_Id is
9829 begin
9830 -- Recurse to handle unlikely case of multiple levels of qualification
9832 if Nkind (Expr) = N_Qualified_Expression then
9833 return Unqualify (Expression (Expr));
9835 -- Normal case, not a qualified expression
9837 else
9838 return Expr;
9839 end if;
9840 end Unqualify;
9842 ----------------------
9843 -- Within_Init_Proc --
9844 ----------------------
9846 function Within_Init_Proc return Boolean is
9847 S : Entity_Id;
9849 begin
9850 S := Current_Scope;
9851 while not Is_Overloadable (S) loop
9852 if S = Standard_Standard then
9853 return False;
9854 else
9855 S := Scope (S);
9856 end if;
9857 end loop;
9859 return Is_Init_Proc (S);
9860 end Within_Init_Proc;
9862 ----------------
9863 -- Wrong_Type --
9864 ----------------
9866 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
9867 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
9868 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
9870 function Has_One_Matching_Field return Boolean;
9871 -- Determines if Expec_Type is a record type with a single component or
9872 -- discriminant whose type matches the found type or is one dimensional
9873 -- array whose component type matches the found type.
9875 ----------------------------
9876 -- Has_One_Matching_Field --
9877 ----------------------------
9879 function Has_One_Matching_Field return Boolean is
9880 E : Entity_Id;
9882 begin
9883 if Is_Array_Type (Expec_Type)
9884 and then Number_Dimensions (Expec_Type) = 1
9885 and then
9886 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
9887 then
9888 return True;
9890 elsif not Is_Record_Type (Expec_Type) then
9891 return False;
9893 else
9894 E := First_Entity (Expec_Type);
9895 loop
9896 if No (E) then
9897 return False;
9899 elsif (Ekind (E) /= E_Discriminant
9900 and then Ekind (E) /= E_Component)
9901 or else (Chars (E) = Name_uTag
9902 or else Chars (E) = Name_uParent)
9903 then
9904 Next_Entity (E);
9906 else
9907 exit;
9908 end if;
9909 end loop;
9911 if not Covers (Etype (E), Found_Type) then
9912 return False;
9914 elsif Present (Next_Entity (E)) then
9915 return False;
9917 else
9918 return True;
9919 end if;
9920 end if;
9921 end Has_One_Matching_Field;
9923 -- Start of processing for Wrong_Type
9925 begin
9926 -- Don't output message if either type is Any_Type, or if a message
9927 -- has already been posted for this node. We need to do the latter
9928 -- check explicitly (it is ordinarily done in Errout), because we
9929 -- are using ! to force the output of the error messages.
9931 if Expec_Type = Any_Type
9932 or else Found_Type = Any_Type
9933 or else Error_Posted (Expr)
9934 then
9935 return;
9937 -- In an instance, there is an ongoing problem with completion of
9938 -- type derived from private types. Their structure is what Gigi
9939 -- expects, but the Etype is the parent type rather than the
9940 -- derived private type itself. Do not flag error in this case. The
9941 -- private completion is an entity without a parent, like an Itype.
9942 -- Similarly, full and partial views may be incorrect in the instance.
9943 -- There is no simple way to insure that it is consistent ???
9945 elsif In_Instance then
9946 if Etype (Etype (Expr)) = Etype (Expected_Type)
9947 and then
9948 (Has_Private_Declaration (Expected_Type)
9949 or else Has_Private_Declaration (Etype (Expr)))
9950 and then No (Parent (Expected_Type))
9951 then
9952 return;
9953 end if;
9954 end if;
9956 -- An interesting special check. If the expression is parenthesized
9957 -- and its type corresponds to the type of the sole component of the
9958 -- expected record type, or to the component type of the expected one
9959 -- dimensional array type, then assume we have a bad aggregate attempt.
9961 if Nkind (Expr) in N_Subexpr
9962 and then Paren_Count (Expr) /= 0
9963 and then Has_One_Matching_Field
9964 then
9965 Error_Msg_N ("positional aggregate cannot have one component", Expr);
9967 -- Another special check, if we are looking for a pool-specific access
9968 -- type and we found an E_Access_Attribute_Type, then we have the case
9969 -- of an Access attribute being used in a context which needs a pool-
9970 -- specific type, which is never allowed. The one extra check we make
9971 -- is that the expected designated type covers the Found_Type.
9973 elsif Is_Access_Type (Expec_Type)
9974 and then Ekind (Found_Type) = E_Access_Attribute_Type
9975 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
9976 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
9977 and then Covers
9978 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
9979 then
9980 Error_Msg_N ("result must be general access type!", Expr);
9981 Error_Msg_NE ("add ALL to }!", Expr, Expec_Type);
9983 -- Another special check, if the expected type is an integer type,
9984 -- but the expression is of type System.Address, and the parent is
9985 -- an addition or subtraction operation whose left operand is the
9986 -- expression in question and whose right operand is of an integral
9987 -- type, then this is an attempt at address arithmetic, so give
9988 -- appropriate message.
9990 elsif Is_Integer_Type (Expec_Type)
9991 and then Is_RTE (Found_Type, RE_Address)
9992 and then (Nkind (Parent (Expr)) = N_Op_Add
9993 or else
9994 Nkind (Parent (Expr)) = N_Op_Subtract)
9995 and then Expr = Left_Opnd (Parent (Expr))
9996 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
9997 then
9998 Error_Msg_N
9999 ("address arithmetic not predefined in package System",
10000 Parent (Expr));
10001 Error_Msg_N
10002 ("\possible missing with/use of System.Storage_Elements",
10003 Parent (Expr));
10004 return;
10006 -- If the expected type is an anonymous access type, as for access
10007 -- parameters and discriminants, the error is on the designated types.
10009 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
10010 if Comes_From_Source (Expec_Type) then
10011 Error_Msg_NE ("expected}!", Expr, Expec_Type);
10012 else
10013 Error_Msg_NE
10014 ("expected an access type with designated}",
10015 Expr, Designated_Type (Expec_Type));
10016 end if;
10018 if Is_Access_Type (Found_Type)
10019 and then not Comes_From_Source (Found_Type)
10020 then
10021 Error_Msg_NE
10022 ("\\found an access type with designated}!",
10023 Expr, Designated_Type (Found_Type));
10024 else
10025 if From_With_Type (Found_Type) then
10026 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
10027 Error_Msg_Qual_Level := 99;
10028 Error_Msg_NE ("\\missing `WITH &;", Expr, Scope (Found_Type));
10029 Error_Msg_Qual_Level := 0;
10030 else
10031 Error_Msg_NE ("found}!", Expr, Found_Type);
10032 end if;
10033 end if;
10035 -- Normal case of one type found, some other type expected
10037 else
10038 -- If the names of the two types are the same, see if some number
10039 -- of levels of qualification will help. Don't try more than three
10040 -- levels, and if we get to standard, it's no use (and probably
10041 -- represents an error in the compiler) Also do not bother with
10042 -- internal scope names.
10044 declare
10045 Expec_Scope : Entity_Id;
10046 Found_Scope : Entity_Id;
10048 begin
10049 Expec_Scope := Expec_Type;
10050 Found_Scope := Found_Type;
10052 for Levels in Int range 0 .. 3 loop
10053 if Chars (Expec_Scope) /= Chars (Found_Scope) then
10054 Error_Msg_Qual_Level := Levels;
10055 exit;
10056 end if;
10058 Expec_Scope := Scope (Expec_Scope);
10059 Found_Scope := Scope (Found_Scope);
10061 exit when Expec_Scope = Standard_Standard
10062 or else Found_Scope = Standard_Standard
10063 or else not Comes_From_Source (Expec_Scope)
10064 or else not Comes_From_Source (Found_Scope);
10065 end loop;
10066 end;
10068 if Is_Record_Type (Expec_Type)
10069 and then Present (Corresponding_Remote_Type (Expec_Type))
10070 then
10071 Error_Msg_NE ("expected}!", Expr,
10072 Corresponding_Remote_Type (Expec_Type));
10073 else
10074 Error_Msg_NE ("expected}!", Expr, Expec_Type);
10075 end if;
10077 if Is_Entity_Name (Expr)
10078 and then Is_Package_Or_Generic_Package (Entity (Expr))
10079 then
10080 Error_Msg_N ("\\found package name!", Expr);
10082 elsif Is_Entity_Name (Expr)
10083 and then
10084 (Ekind (Entity (Expr)) = E_Procedure
10085 or else
10086 Ekind (Entity (Expr)) = E_Generic_Procedure)
10087 then
10088 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
10089 Error_Msg_N
10090 ("found procedure name, possibly missing Access attribute!",
10091 Expr);
10092 else
10093 Error_Msg_N
10094 ("\\found procedure name instead of function!", Expr);
10095 end if;
10097 elsif Nkind (Expr) = N_Function_Call
10098 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
10099 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
10100 and then No (Parameter_Associations (Expr))
10101 then
10102 Error_Msg_N
10103 ("found function name, possibly missing Access attribute!",
10104 Expr);
10106 -- Catch common error: a prefix or infix operator which is not
10107 -- directly visible because the type isn't.
10109 elsif Nkind (Expr) in N_Op
10110 and then Is_Overloaded (Expr)
10111 and then not Is_Immediately_Visible (Expec_Type)
10112 and then not Is_Potentially_Use_Visible (Expec_Type)
10113 and then not In_Use (Expec_Type)
10114 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
10115 then
10116 Error_Msg_N
10117 ("operator of the type is not directly visible!", Expr);
10119 elsif Ekind (Found_Type) = E_Void
10120 and then Present (Parent (Found_Type))
10121 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
10122 then
10123 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
10125 else
10126 Error_Msg_NE ("\\found}!", Expr, Found_Type);
10127 end if;
10129 Error_Msg_Qual_Level := 0;
10130 end if;
10131 end Wrong_Type;
10133 end Sem_Util;