sem_ch5.adb (Analyze_Iteration_Scheme): Fix typo.
[gcc.git] / gcc / ada / sem_util.adb
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-2011, 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 ------------------------------------------------------------------------------
25
26 with Atree; use Atree;
27 with Casing; use Casing;
28 with Checks; use Checks;
29 with Debug; use Debug;
30 with Errout; use Errout;
31 with Elists; use Elists;
32 with Exp_Ch11; use Exp_Ch11;
33 with Exp_Disp; use Exp_Disp;
34 with Exp_Tss; use Exp_Tss;
35 with Exp_Util; use Exp_Util;
36 with Fname; use Fname;
37 with Freeze; use Freeze;
38 with Lib; use Lib;
39 with Lib.Xref; use Lib.Xref;
40 with Nlists; use Nlists;
41 with Output; use Output;
42 with Opt; use Opt;
43 with Restrict; use Restrict;
44 with Rtsfind; use Rtsfind;
45 with Sem; use Sem;
46 with Sem_Aux; use Sem_Aux;
47 with Sem_Attr; use Sem_Attr;
48 with Sem_Ch8; use Sem_Ch8;
49 with Sem_Disp; use Sem_Disp;
50 with Sem_Eval; use Sem_Eval;
51 with Sem_Res; use Sem_Res;
52 with Sem_Type; use Sem_Type;
53 with Sinfo; use Sinfo;
54 with Sinput; use Sinput;
55 with Stand; use Stand;
56 with Style;
57 with Stringt; use Stringt;
58 with Table;
59 with Targparm; use Targparm;
60 with Tbuild; use Tbuild;
61 with Ttypes; use Ttypes;
62 with Uname; use Uname;
63
64 with GNAT.HTable; use GNAT.HTable;
65
66 package body Sem_Util is
67
68 ----------------------------------------
69 -- Global_Variables for New_Copy_Tree --
70 ----------------------------------------
71
72 -- These global variables are used by New_Copy_Tree. See description
73 -- of the body of this subprogram for details. Global variables can be
74 -- safely used by New_Copy_Tree, since there is no case of a recursive
75 -- call from the processing inside New_Copy_Tree.
76
77 NCT_Hash_Threshold : constant := 20;
78 -- If there are more than this number of pairs of entries in the
79 -- map, then Hash_Tables_Used will be set, and the hash tables will
80 -- be initialized and used for the searches.
81
82 NCT_Hash_Tables_Used : Boolean := False;
83 -- Set to True if hash tables are in use
84
85 NCT_Table_Entries : Nat;
86 -- Count entries in table to see if threshold is reached
87
88 NCT_Hash_Table_Setup : Boolean := False;
89 -- Set to True if hash table contains data. We set this True if we
90 -- setup the hash table with data, and leave it set permanently
91 -- from then on, this is a signal that second and subsequent users
92 -- of the hash table must clear the old entries before reuse.
93
94 subtype NCT_Header_Num is Int range 0 .. 511;
95 -- Defines range of headers in hash tables (512 headers)
96
97 ----------------------------------
98 -- Order Dependence (AI05-0144) --
99 ----------------------------------
100
101 -- Each actual in a call is entered into the table below. A flag indicates
102 -- whether the corresponding formal is OUT or IN OUT. Each top-level call
103 -- (procedure call, condition, assignment) examines all the actuals for a
104 -- possible order dependence. The table is reset after each such check.
105 -- The actuals to be checked in a call to Check_Order_Dependence are at
106 -- positions 1 .. Last.
107
108 type Actual_Name is record
109 Act : Node_Id;
110 Is_Writable : Boolean;
111 end record;
112
113 package Actuals_In_Call is new Table.Table (
114 Table_Component_Type => Actual_Name,
115 Table_Index_Type => Int,
116 Table_Low_Bound => 0,
117 Table_Initial => 10,
118 Table_Increment => 100,
119 Table_Name => "Actuals");
120
121 -----------------------
122 -- Local Subprograms --
123 -----------------------
124
125 function Build_Component_Subtype
126 (C : List_Id;
127 Loc : Source_Ptr;
128 T : Entity_Id) return Node_Id;
129 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
130 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
131 -- Loc is the source location, T is the original subtype.
132
133 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
134 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
135 -- with discriminants whose default values are static, examine only the
136 -- components in the selected variant to determine whether all of them
137 -- have a default.
138
139 function Has_Null_Extension (T : Entity_Id) return Boolean;
140 -- T is a derived tagged type. Check whether the type extension is null.
141 -- If the parent type is fully initialized, T can be treated as such.
142
143 ------------------------------
144 -- Abstract_Interface_List --
145 ------------------------------
146
147 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
148 Nod : Node_Id;
149
150 begin
151 if Is_Concurrent_Type (Typ) then
152
153 -- If we are dealing with a synchronized subtype, go to the base
154 -- type, whose declaration has the interface list.
155
156 -- Shouldn't this be Declaration_Node???
157
158 Nod := Parent (Base_Type (Typ));
159
160 if Nkind (Nod) = N_Full_Type_Declaration then
161 return Empty_List;
162 end if;
163
164 elsif Ekind (Typ) = E_Record_Type_With_Private then
165 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
166 Nod := Type_Definition (Parent (Typ));
167
168 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
169 if Present (Full_View (Typ))
170 and then Nkind (Parent (Full_View (Typ)))
171 = N_Full_Type_Declaration
172 then
173 Nod := Type_Definition (Parent (Full_View (Typ)));
174
175 -- If the full-view is not available we cannot do anything else
176 -- here (the source has errors).
177
178 else
179 return Empty_List;
180 end if;
181
182 -- Support for generic formals with interfaces is still missing ???
183
184 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
185 return Empty_List;
186
187 else
188 pragma Assert
189 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
190 Nod := Parent (Typ);
191 end if;
192
193 elsif Ekind (Typ) = E_Record_Subtype then
194 Nod := Type_Definition (Parent (Etype (Typ)));
195
196 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
197
198 -- Recurse, because parent may still be a private extension. Also
199 -- note that the full view of the subtype or the full view of its
200 -- base type may (both) be unavailable.
201
202 return Abstract_Interface_List (Etype (Typ));
203
204 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
205 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
206 Nod := Formal_Type_Definition (Parent (Typ));
207 else
208 Nod := Type_Definition (Parent (Typ));
209 end if;
210 end if;
211
212 return Interface_List (Nod);
213 end Abstract_Interface_List;
214
215 --------------------------------
216 -- Add_Access_Type_To_Process --
217 --------------------------------
218
219 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
220 L : Elist_Id;
221
222 begin
223 Ensure_Freeze_Node (E);
224 L := Access_Types_To_Process (Freeze_Node (E));
225
226 if No (L) then
227 L := New_Elmt_List;
228 Set_Access_Types_To_Process (Freeze_Node (E), L);
229 end if;
230
231 Append_Elmt (A, L);
232 end Add_Access_Type_To_Process;
233
234 ----------------------------
235 -- Add_Global_Declaration --
236 ----------------------------
237
238 procedure Add_Global_Declaration (N : Node_Id) is
239 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
240
241 begin
242 if No (Declarations (Aux_Node)) then
243 Set_Declarations (Aux_Node, New_List);
244 end if;
245
246 Append_To (Declarations (Aux_Node), N);
247 Analyze (N);
248 end Add_Global_Declaration;
249
250 -----------------
251 -- Addressable --
252 -----------------
253
254 -- For now, just 8/16/32/64. but analyze later if AAMP is special???
255
256 function Addressable (V : Uint) return Boolean is
257 begin
258 return V = Uint_8 or else
259 V = Uint_16 or else
260 V = Uint_32 or else
261 V = Uint_64;
262 end Addressable;
263
264 function Addressable (V : Int) return Boolean is
265 begin
266 return V = 8 or else
267 V = 16 or else
268 V = 32 or else
269 V = 64;
270 end Addressable;
271
272 -----------------------
273 -- Alignment_In_Bits --
274 -----------------------
275
276 function Alignment_In_Bits (E : Entity_Id) return Uint is
277 begin
278 return Alignment (E) * System_Storage_Unit;
279 end Alignment_In_Bits;
280
281 -----------------------------------------
282 -- Apply_Compile_Time_Constraint_Error --
283 -----------------------------------------
284
285 procedure Apply_Compile_Time_Constraint_Error
286 (N : Node_Id;
287 Msg : String;
288 Reason : RT_Exception_Code;
289 Ent : Entity_Id := Empty;
290 Typ : Entity_Id := Empty;
291 Loc : Source_Ptr := No_Location;
292 Rep : Boolean := True;
293 Warn : Boolean := False)
294 is
295 Stat : constant Boolean := Is_Static_Expression (N);
296 R_Stat : constant Node_Id :=
297 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
298 Rtyp : Entity_Id;
299
300 begin
301 if No (Typ) then
302 Rtyp := Etype (N);
303 else
304 Rtyp := Typ;
305 end if;
306
307 Discard_Node
308 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
309
310 if not Rep then
311 return;
312 end if;
313
314 -- Now we replace the node by an N_Raise_Constraint_Error node
315 -- This does not need reanalyzing, so set it as analyzed now.
316
317 Rewrite (N, R_Stat);
318 Set_Analyzed (N, True);
319
320 Set_Etype (N, Rtyp);
321 Set_Raises_Constraint_Error (N);
322
323 -- Now deal with possible local raise handling
324
325 Possible_Local_Raise (N, Standard_Constraint_Error);
326
327 -- If the original expression was marked as static, the result is
328 -- still marked as static, but the Raises_Constraint_Error flag is
329 -- always set so that further static evaluation is not attempted.
330
331 if Stat then
332 Set_Is_Static_Expression (N);
333 end if;
334 end Apply_Compile_Time_Constraint_Error;
335
336 --------------------------------
337 -- Bad_Predicated_Subtype_Use --
338 --------------------------------
339
340 procedure Bad_Predicated_Subtype_Use
341 (Msg : String;
342 N : Node_Id;
343 Typ : Entity_Id)
344 is
345 begin
346 if Has_Predicates (Typ) then
347 if Is_Generic_Actual_Type (Typ) then
348 Error_Msg_FE (Msg & '?', N, Typ);
349 Error_Msg_F ("\Program_Error will be raised at run time?", N);
350 Insert_Action (N,
351 Make_Raise_Program_Error (Sloc (N),
352 Reason => PE_Bad_Predicated_Generic_Type));
353
354 else
355 Error_Msg_FE (Msg, N, Typ);
356 end if;
357 end if;
358 end Bad_Predicated_Subtype_Use;
359
360 --------------------------
361 -- Build_Actual_Subtype --
362 --------------------------
363
364 function Build_Actual_Subtype
365 (T : Entity_Id;
366 N : Node_Or_Entity_Id) return Node_Id
367 is
368 Loc : Source_Ptr;
369 -- Normally Sloc (N), but may point to corresponding body in some cases
370
371 Constraints : List_Id;
372 Decl : Node_Id;
373 Discr : Entity_Id;
374 Hi : Node_Id;
375 Lo : Node_Id;
376 Subt : Entity_Id;
377 Disc_Type : Entity_Id;
378 Obj : Node_Id;
379
380 begin
381 Loc := Sloc (N);
382
383 if Nkind (N) = N_Defining_Identifier then
384 Obj := New_Reference_To (N, Loc);
385
386 -- If this is a formal parameter of a subprogram declaration, and
387 -- we are compiling the body, we want the declaration for the
388 -- actual subtype to carry the source position of the body, to
389 -- prevent anomalies in gdb when stepping through the code.
390
391 if Is_Formal (N) then
392 declare
393 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
394 begin
395 if Nkind (Decl) = N_Subprogram_Declaration
396 and then Present (Corresponding_Body (Decl))
397 then
398 Loc := Sloc (Corresponding_Body (Decl));
399 end if;
400 end;
401 end if;
402
403 else
404 Obj := N;
405 end if;
406
407 if Is_Array_Type (T) then
408 Constraints := New_List;
409 for J in 1 .. Number_Dimensions (T) loop
410
411 -- Build an array subtype declaration with the nominal subtype and
412 -- the bounds of the actual. Add the declaration in front of the
413 -- local declarations for the subprogram, for analysis before any
414 -- reference to the formal in the body.
415
416 Lo :=
417 Make_Attribute_Reference (Loc,
418 Prefix =>
419 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
420 Attribute_Name => Name_First,
421 Expressions => New_List (
422 Make_Integer_Literal (Loc, J)));
423
424 Hi :=
425 Make_Attribute_Reference (Loc,
426 Prefix =>
427 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
428 Attribute_Name => Name_Last,
429 Expressions => New_List (
430 Make_Integer_Literal (Loc, J)));
431
432 Append (Make_Range (Loc, Lo, Hi), Constraints);
433 end loop;
434
435 -- If the type has unknown discriminants there is no constrained
436 -- subtype to build. This is never called for a formal or for a
437 -- lhs, so returning the type is ok ???
438
439 elsif Has_Unknown_Discriminants (T) then
440 return T;
441
442 else
443 Constraints := New_List;
444
445 -- Type T is a generic derived type, inherit the discriminants from
446 -- the parent type.
447
448 if Is_Private_Type (T)
449 and then No (Full_View (T))
450
451 -- T was flagged as an error if it was declared as a formal
452 -- derived type with known discriminants. In this case there
453 -- is no need to look at the parent type since T already carries
454 -- its own discriminants.
455
456 and then not Error_Posted (T)
457 then
458 Disc_Type := Etype (Base_Type (T));
459 else
460 Disc_Type := T;
461 end if;
462
463 Discr := First_Discriminant (Disc_Type);
464 while Present (Discr) loop
465 Append_To (Constraints,
466 Make_Selected_Component (Loc,
467 Prefix =>
468 Duplicate_Subexpr_No_Checks (Obj),
469 Selector_Name => New_Occurrence_Of (Discr, Loc)));
470 Next_Discriminant (Discr);
471 end loop;
472 end if;
473
474 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
475 Set_Is_Internal (Subt);
476
477 Decl :=
478 Make_Subtype_Declaration (Loc,
479 Defining_Identifier => Subt,
480 Subtype_Indication =>
481 Make_Subtype_Indication (Loc,
482 Subtype_Mark => New_Reference_To (T, Loc),
483 Constraint =>
484 Make_Index_Or_Discriminant_Constraint (Loc,
485 Constraints => Constraints)));
486
487 Mark_Rewrite_Insertion (Decl);
488 return Decl;
489 end Build_Actual_Subtype;
490
491 ---------------------------------------
492 -- Build_Actual_Subtype_Of_Component --
493 ---------------------------------------
494
495 function Build_Actual_Subtype_Of_Component
496 (T : Entity_Id;
497 N : Node_Id) return Node_Id
498 is
499 Loc : constant Source_Ptr := Sloc (N);
500 P : constant Node_Id := Prefix (N);
501 D : Elmt_Id;
502 Id : Node_Id;
503 Indx_Type : Entity_Id;
504
505 Deaccessed_T : Entity_Id;
506 -- This is either a copy of T, or if T is an access type, then it is
507 -- the directly designated type of this access type.
508
509 function Build_Actual_Array_Constraint return List_Id;
510 -- If one or more of the bounds of the component depends on
511 -- discriminants, build actual constraint using the discriminants
512 -- of the prefix.
513
514 function Build_Actual_Record_Constraint return List_Id;
515 -- Similar to previous one, for discriminated components constrained
516 -- by the discriminant of the enclosing object.
517
518 -----------------------------------
519 -- Build_Actual_Array_Constraint --
520 -----------------------------------
521
522 function Build_Actual_Array_Constraint return List_Id is
523 Constraints : constant List_Id := New_List;
524 Indx : Node_Id;
525 Hi : Node_Id;
526 Lo : Node_Id;
527 Old_Hi : Node_Id;
528 Old_Lo : Node_Id;
529
530 begin
531 Indx := First_Index (Deaccessed_T);
532 while Present (Indx) loop
533 Old_Lo := Type_Low_Bound (Etype (Indx));
534 Old_Hi := Type_High_Bound (Etype (Indx));
535
536 if Denotes_Discriminant (Old_Lo) then
537 Lo :=
538 Make_Selected_Component (Loc,
539 Prefix => New_Copy_Tree (P),
540 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
541
542 else
543 Lo := New_Copy_Tree (Old_Lo);
544
545 -- The new bound will be reanalyzed in the enclosing
546 -- declaration. For literal bounds that come from a type
547 -- declaration, the type of the context must be imposed, so
548 -- insure that analysis will take place. For non-universal
549 -- types this is not strictly necessary.
550
551 Set_Analyzed (Lo, False);
552 end if;
553
554 if Denotes_Discriminant (Old_Hi) then
555 Hi :=
556 Make_Selected_Component (Loc,
557 Prefix => New_Copy_Tree (P),
558 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
559
560 else
561 Hi := New_Copy_Tree (Old_Hi);
562 Set_Analyzed (Hi, False);
563 end if;
564
565 Append (Make_Range (Loc, Lo, Hi), Constraints);
566 Next_Index (Indx);
567 end loop;
568
569 return Constraints;
570 end Build_Actual_Array_Constraint;
571
572 ------------------------------------
573 -- Build_Actual_Record_Constraint --
574 ------------------------------------
575
576 function Build_Actual_Record_Constraint return List_Id is
577 Constraints : constant List_Id := New_List;
578 D : Elmt_Id;
579 D_Val : Node_Id;
580
581 begin
582 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
583 while Present (D) loop
584 if Denotes_Discriminant (Node (D)) then
585 D_Val := Make_Selected_Component (Loc,
586 Prefix => New_Copy_Tree (P),
587 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
588
589 else
590 D_Val := New_Copy_Tree (Node (D));
591 end if;
592
593 Append (D_Val, Constraints);
594 Next_Elmt (D);
595 end loop;
596
597 return Constraints;
598 end Build_Actual_Record_Constraint;
599
600 -- Start of processing for Build_Actual_Subtype_Of_Component
601
602 begin
603 -- Why the test for Spec_Expression mode here???
604
605 if In_Spec_Expression then
606 return Empty;
607
608 -- More comments for the rest of this body would be good ???
609
610 elsif Nkind (N) = N_Explicit_Dereference then
611 if Is_Composite_Type (T)
612 and then not Is_Constrained (T)
613 and then not (Is_Class_Wide_Type (T)
614 and then Is_Constrained (Root_Type (T)))
615 and then not Has_Unknown_Discriminants (T)
616 then
617 -- If the type of the dereference is already constrained, it is an
618 -- actual subtype.
619
620 if Is_Array_Type (Etype (N))
621 and then Is_Constrained (Etype (N))
622 then
623 return Empty;
624 else
625 Remove_Side_Effects (P);
626 return Build_Actual_Subtype (T, N);
627 end if;
628 else
629 return Empty;
630 end if;
631 end if;
632
633 if Ekind (T) = E_Access_Subtype then
634 Deaccessed_T := Designated_Type (T);
635 else
636 Deaccessed_T := T;
637 end if;
638
639 if Ekind (Deaccessed_T) = E_Array_Subtype then
640 Id := First_Index (Deaccessed_T);
641 while Present (Id) loop
642 Indx_Type := Underlying_Type (Etype (Id));
643
644 if Denotes_Discriminant (Type_Low_Bound (Indx_Type))
645 or else
646 Denotes_Discriminant (Type_High_Bound (Indx_Type))
647 then
648 Remove_Side_Effects (P);
649 return
650 Build_Component_Subtype
651 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
652 end if;
653
654 Next_Index (Id);
655 end loop;
656
657 elsif Is_Composite_Type (Deaccessed_T)
658 and then Has_Discriminants (Deaccessed_T)
659 and then not Has_Unknown_Discriminants (Deaccessed_T)
660 then
661 D := First_Elmt (Discriminant_Constraint (Deaccessed_T));
662 while Present (D) loop
663 if Denotes_Discriminant (Node (D)) then
664 Remove_Side_Effects (P);
665 return
666 Build_Component_Subtype (
667 Build_Actual_Record_Constraint, Loc, Base_Type (T));
668 end if;
669
670 Next_Elmt (D);
671 end loop;
672 end if;
673
674 -- If none of the above, the actual and nominal subtypes are the same
675
676 return Empty;
677 end Build_Actual_Subtype_Of_Component;
678
679 -----------------------------
680 -- Build_Component_Subtype --
681 -----------------------------
682
683 function Build_Component_Subtype
684 (C : List_Id;
685 Loc : Source_Ptr;
686 T : Entity_Id) return Node_Id
687 is
688 Subt : Entity_Id;
689 Decl : Node_Id;
690
691 begin
692 -- Unchecked_Union components do not require component subtypes
693
694 if Is_Unchecked_Union (T) then
695 return Empty;
696 end if;
697
698 Subt := Make_Temporary (Loc, 'S');
699 Set_Is_Internal (Subt);
700
701 Decl :=
702 Make_Subtype_Declaration (Loc,
703 Defining_Identifier => Subt,
704 Subtype_Indication =>
705 Make_Subtype_Indication (Loc,
706 Subtype_Mark => New_Reference_To (Base_Type (T), Loc),
707 Constraint =>
708 Make_Index_Or_Discriminant_Constraint (Loc,
709 Constraints => C)));
710
711 Mark_Rewrite_Insertion (Decl);
712 return Decl;
713 end Build_Component_Subtype;
714
715 ---------------------------
716 -- Build_Default_Subtype --
717 ---------------------------
718
719 function Build_Default_Subtype
720 (T : Entity_Id;
721 N : Node_Id) return Entity_Id
722 is
723 Loc : constant Source_Ptr := Sloc (N);
724 Disc : Entity_Id;
725
726 begin
727 if not Has_Discriminants (T) or else Is_Constrained (T) then
728 return T;
729 end if;
730
731 Disc := First_Discriminant (T);
732
733 if No (Discriminant_Default_Value (Disc)) then
734 return T;
735 end if;
736
737 declare
738 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
739 Constraints : constant List_Id := New_List;
740 Decl : Node_Id;
741
742 begin
743 while Present (Disc) loop
744 Append_To (Constraints,
745 New_Copy_Tree (Discriminant_Default_Value (Disc)));
746 Next_Discriminant (Disc);
747 end loop;
748
749 Decl :=
750 Make_Subtype_Declaration (Loc,
751 Defining_Identifier => Act,
752 Subtype_Indication =>
753 Make_Subtype_Indication (Loc,
754 Subtype_Mark => New_Occurrence_Of (T, Loc),
755 Constraint =>
756 Make_Index_Or_Discriminant_Constraint (Loc,
757 Constraints => Constraints)));
758
759 Insert_Action (N, Decl);
760 Analyze (Decl);
761 return Act;
762 end;
763 end Build_Default_Subtype;
764
765 --------------------------------------------
766 -- Build_Discriminal_Subtype_Of_Component --
767 --------------------------------------------
768
769 function Build_Discriminal_Subtype_Of_Component
770 (T : Entity_Id) return Node_Id
771 is
772 Loc : constant Source_Ptr := Sloc (T);
773 D : Elmt_Id;
774 Id : Node_Id;
775
776 function Build_Discriminal_Array_Constraint return List_Id;
777 -- If one or more of the bounds of the component depends on
778 -- discriminants, build actual constraint using the discriminants
779 -- of the prefix.
780
781 function Build_Discriminal_Record_Constraint return List_Id;
782 -- Similar to previous one, for discriminated components constrained
783 -- by the discriminant of the enclosing object.
784
785 ----------------------------------------
786 -- Build_Discriminal_Array_Constraint --
787 ----------------------------------------
788
789 function Build_Discriminal_Array_Constraint return List_Id is
790 Constraints : constant List_Id := New_List;
791 Indx : Node_Id;
792 Hi : Node_Id;
793 Lo : Node_Id;
794 Old_Hi : Node_Id;
795 Old_Lo : Node_Id;
796
797 begin
798 Indx := First_Index (T);
799 while Present (Indx) loop
800 Old_Lo := Type_Low_Bound (Etype (Indx));
801 Old_Hi := Type_High_Bound (Etype (Indx));
802
803 if Denotes_Discriminant (Old_Lo) then
804 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
805
806 else
807 Lo := New_Copy_Tree (Old_Lo);
808 end if;
809
810 if Denotes_Discriminant (Old_Hi) then
811 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
812
813 else
814 Hi := New_Copy_Tree (Old_Hi);
815 end if;
816
817 Append (Make_Range (Loc, Lo, Hi), Constraints);
818 Next_Index (Indx);
819 end loop;
820
821 return Constraints;
822 end Build_Discriminal_Array_Constraint;
823
824 -----------------------------------------
825 -- Build_Discriminal_Record_Constraint --
826 -----------------------------------------
827
828 function Build_Discriminal_Record_Constraint return List_Id is
829 Constraints : constant List_Id := New_List;
830 D : Elmt_Id;
831 D_Val : Node_Id;
832
833 begin
834 D := First_Elmt (Discriminant_Constraint (T));
835 while Present (D) loop
836 if Denotes_Discriminant (Node (D)) then
837 D_Val :=
838 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
839
840 else
841 D_Val := New_Copy_Tree (Node (D));
842 end if;
843
844 Append (D_Val, Constraints);
845 Next_Elmt (D);
846 end loop;
847
848 return Constraints;
849 end Build_Discriminal_Record_Constraint;
850
851 -- Start of processing for Build_Discriminal_Subtype_Of_Component
852
853 begin
854 if Ekind (T) = E_Array_Subtype then
855 Id := First_Index (T);
856 while Present (Id) loop
857 if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) or else
858 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
859 then
860 return Build_Component_Subtype
861 (Build_Discriminal_Array_Constraint, Loc, T);
862 end if;
863
864 Next_Index (Id);
865 end loop;
866
867 elsif Ekind (T) = E_Record_Subtype
868 and then Has_Discriminants (T)
869 and then not Has_Unknown_Discriminants (T)
870 then
871 D := First_Elmt (Discriminant_Constraint (T));
872 while Present (D) loop
873 if Denotes_Discriminant (Node (D)) then
874 return Build_Component_Subtype
875 (Build_Discriminal_Record_Constraint, Loc, T);
876 end if;
877
878 Next_Elmt (D);
879 end loop;
880 end if;
881
882 -- If none of the above, the actual and nominal subtypes are the same
883
884 return Empty;
885 end Build_Discriminal_Subtype_Of_Component;
886
887 ------------------------------
888 -- Build_Elaboration_Entity --
889 ------------------------------
890
891 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
892 Loc : constant Source_Ptr := Sloc (N);
893 Decl : Node_Id;
894 Elab_Ent : Entity_Id;
895
896 procedure Set_Package_Name (Ent : Entity_Id);
897 -- Given an entity, sets the fully qualified name of the entity in
898 -- Name_Buffer, with components separated by double underscores. This
899 -- is a recursive routine that climbs the scope chain to Standard.
900
901 ----------------------
902 -- Set_Package_Name --
903 ----------------------
904
905 procedure Set_Package_Name (Ent : Entity_Id) is
906 begin
907 if Scope (Ent) /= Standard_Standard then
908 Set_Package_Name (Scope (Ent));
909
910 declare
911 Nam : constant String := Get_Name_String (Chars (Ent));
912 begin
913 Name_Buffer (Name_Len + 1) := '_';
914 Name_Buffer (Name_Len + 2) := '_';
915 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
916 Name_Len := Name_Len + Nam'Length + 2;
917 end;
918
919 else
920 Get_Name_String (Chars (Ent));
921 end if;
922 end Set_Package_Name;
923
924 -- Start of processing for Build_Elaboration_Entity
925
926 begin
927 -- Ignore if already constructed
928
929 if Present (Elaboration_Entity (Spec_Id)) then
930 return;
931 end if;
932
933 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
934 -- name with dots replaced by double underscore. We have to manually
935 -- construct this name, since it will be elaborated in the outer scope,
936 -- and thus will not have the unit name automatically prepended.
937
938 Set_Package_Name (Spec_Id);
939
940 -- Append _E
941
942 Name_Buffer (Name_Len + 1) := '_';
943 Name_Buffer (Name_Len + 2) := 'E';
944 Name_Len := Name_Len + 2;
945
946 -- Create elaboration flag
947
948 Elab_Ent :=
949 Make_Defining_Identifier (Loc, Chars => Name_Find);
950 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
951
952 Decl :=
953 Make_Object_Declaration (Loc,
954 Defining_Identifier => Elab_Ent,
955 Object_Definition =>
956 New_Occurrence_Of (Standard_Boolean, Loc),
957 Expression =>
958 New_Occurrence_Of (Standard_False, Loc));
959
960 Push_Scope (Standard_Standard);
961 Add_Global_Declaration (Decl);
962 Pop_Scope;
963
964 -- Reset True_Constant indication, since we will indeed assign a value
965 -- to the variable in the binder main. We also kill the Current_Value
966 -- and Last_Assignment fields for the same reason.
967
968 Set_Is_True_Constant (Elab_Ent, False);
969 Set_Current_Value (Elab_Ent, Empty);
970 Set_Last_Assignment (Elab_Ent, Empty);
971
972 -- We do not want any further qualification of the name (if we did
973 -- not do this, we would pick up the name of the generic package
974 -- in the case of a library level generic instantiation).
975
976 Set_Has_Qualified_Name (Elab_Ent);
977 Set_Has_Fully_Qualified_Name (Elab_Ent);
978 end Build_Elaboration_Entity;
979
980 -----------------------------------
981 -- Cannot_Raise_Constraint_Error --
982 -----------------------------------
983
984 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
985 begin
986 if Compile_Time_Known_Value (Expr) then
987 return True;
988
989 elsif Do_Range_Check (Expr) then
990 return False;
991
992 elsif Raises_Constraint_Error (Expr) then
993 return False;
994
995 else
996 case Nkind (Expr) is
997 when N_Identifier =>
998 return True;
999
1000 when N_Expanded_Name =>
1001 return True;
1002
1003 when N_Selected_Component =>
1004 return not Do_Discriminant_Check (Expr);
1005
1006 when N_Attribute_Reference =>
1007 if Do_Overflow_Check (Expr) then
1008 return False;
1009
1010 elsif No (Expressions (Expr)) then
1011 return True;
1012
1013 else
1014 declare
1015 N : Node_Id;
1016
1017 begin
1018 N := First (Expressions (Expr));
1019 while Present (N) loop
1020 if Cannot_Raise_Constraint_Error (N) then
1021 Next (N);
1022 else
1023 return False;
1024 end if;
1025 end loop;
1026
1027 return True;
1028 end;
1029 end if;
1030
1031 when N_Type_Conversion =>
1032 if Do_Overflow_Check (Expr)
1033 or else Do_Length_Check (Expr)
1034 or else Do_Tag_Check (Expr)
1035 then
1036 return False;
1037 else
1038 return
1039 Cannot_Raise_Constraint_Error (Expression (Expr));
1040 end if;
1041
1042 when N_Unchecked_Type_Conversion =>
1043 return Cannot_Raise_Constraint_Error (Expression (Expr));
1044
1045 when N_Unary_Op =>
1046 if Do_Overflow_Check (Expr) then
1047 return False;
1048 else
1049 return
1050 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1051 end if;
1052
1053 when N_Op_Divide |
1054 N_Op_Mod |
1055 N_Op_Rem
1056 =>
1057 if Do_Division_Check (Expr)
1058 or else Do_Overflow_Check (Expr)
1059 then
1060 return False;
1061 else
1062 return
1063 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1064 and then
1065 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1066 end if;
1067
1068 when N_Op_Add |
1069 N_Op_And |
1070 N_Op_Concat |
1071 N_Op_Eq |
1072 N_Op_Expon |
1073 N_Op_Ge |
1074 N_Op_Gt |
1075 N_Op_Le |
1076 N_Op_Lt |
1077 N_Op_Multiply |
1078 N_Op_Ne |
1079 N_Op_Or |
1080 N_Op_Rotate_Left |
1081 N_Op_Rotate_Right |
1082 N_Op_Shift_Left |
1083 N_Op_Shift_Right |
1084 N_Op_Shift_Right_Arithmetic |
1085 N_Op_Subtract |
1086 N_Op_Xor
1087 =>
1088 if Do_Overflow_Check (Expr) then
1089 return False;
1090 else
1091 return
1092 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1093 and then
1094 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1095 end if;
1096
1097 when others =>
1098 return False;
1099 end case;
1100 end if;
1101 end Cannot_Raise_Constraint_Error;
1102
1103 -----------------------------------------
1104 -- Check_Dynamically_Tagged_Expression --
1105 -----------------------------------------
1106
1107 procedure Check_Dynamically_Tagged_Expression
1108 (Expr : Node_Id;
1109 Typ : Entity_Id;
1110 Related_Nod : Node_Id)
1111 is
1112 begin
1113 pragma Assert (Is_Tagged_Type (Typ));
1114
1115 -- In order to avoid spurious errors when analyzing the expanded code,
1116 -- this check is done only for nodes that come from source and for
1117 -- actuals of generic instantiations.
1118
1119 if (Comes_From_Source (Related_Nod)
1120 or else In_Generic_Actual (Expr))
1121 and then (Is_Class_Wide_Type (Etype (Expr))
1122 or else Is_Dynamically_Tagged (Expr))
1123 and then Is_Tagged_Type (Typ)
1124 and then not Is_Class_Wide_Type (Typ)
1125 then
1126 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
1127 end if;
1128 end Check_Dynamically_Tagged_Expression;
1129
1130 --------------------------
1131 -- Check_Fully_Declared --
1132 --------------------------
1133
1134 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
1135 begin
1136 if Ekind (T) = E_Incomplete_Type then
1137
1138 -- Ada 2005 (AI-50217): If the type is available through a limited
1139 -- with_clause, verify that its full view has been analyzed.
1140
1141 if From_With_Type (T)
1142 and then Present (Non_Limited_View (T))
1143 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1144 then
1145 -- The non-limited view is fully declared
1146 null;
1147
1148 else
1149 Error_Msg_NE
1150 ("premature usage of incomplete}", N, First_Subtype (T));
1151 end if;
1152
1153 -- Need comments for these tests ???
1154
1155 elsif Has_Private_Component (T)
1156 and then not Is_Generic_Type (Root_Type (T))
1157 and then not In_Spec_Expression
1158 then
1159 -- Special case: if T is the anonymous type created for a single
1160 -- task or protected object, use the name of the source object.
1161
1162 if Is_Concurrent_Type (T)
1163 and then not Comes_From_Source (T)
1164 and then Nkind (N) = N_Object_Declaration
1165 then
1166 Error_Msg_NE ("type of& has incomplete component", N,
1167 Defining_Identifier (N));
1168
1169 else
1170 Error_Msg_NE
1171 ("premature usage of incomplete}", N, First_Subtype (T));
1172 end if;
1173 end if;
1174 end Check_Fully_Declared;
1175
1176 -------------------------
1177 -- Check_Nested_Access --
1178 -------------------------
1179
1180 procedure Check_Nested_Access (Ent : Entity_Id) is
1181 Scop : constant Entity_Id := Current_Scope;
1182 Current_Subp : Entity_Id;
1183 Enclosing : Entity_Id;
1184
1185 begin
1186 -- Currently only enabled for VM back-ends for efficiency, should we
1187 -- enable it more systematically ???
1188
1189 -- Check for Is_Imported needs commenting below ???
1190
1191 if VM_Target /= No_VM
1192 and then (Ekind (Ent) = E_Variable
1193 or else
1194 Ekind (Ent) = E_Constant
1195 or else
1196 Ekind (Ent) = E_Loop_Parameter)
1197 and then Scope (Ent) /= Empty
1198 and then not Is_Library_Level_Entity (Ent)
1199 and then not Is_Imported (Ent)
1200 then
1201 if Is_Subprogram (Scop)
1202 or else Is_Generic_Subprogram (Scop)
1203 or else Is_Entry (Scop)
1204 then
1205 Current_Subp := Scop;
1206 else
1207 Current_Subp := Current_Subprogram;
1208 end if;
1209
1210 Enclosing := Enclosing_Subprogram (Ent);
1211
1212 if Enclosing /= Empty
1213 and then Enclosing /= Current_Subp
1214 then
1215 Set_Has_Up_Level_Access (Ent, True);
1216 end if;
1217 end if;
1218 end Check_Nested_Access;
1219
1220 ----------------------------
1221 -- Check_Order_Dependence --
1222 ----------------------------
1223
1224 procedure Check_Order_Dependence is
1225 Act1 : Node_Id;
1226 Act2 : Node_Id;
1227
1228 begin
1229 if Ada_Version < Ada_2012 then
1230 return;
1231 end if;
1232
1233 -- Ada 2012 AI04-0144-2: Dangerous order dependence. Actuals in nested
1234 -- calls within a construct have been collected. If one of them is
1235 -- writable and overlaps with another one, evaluation of the enclosing
1236 -- construct is nondeterministic. This is illegal in Ada 2012, but is
1237 -- treated as a warning for now.
1238
1239 for J in 1 .. Actuals_In_Call.Last loop
1240 if Actuals_In_Call.Table (J).Is_Writable then
1241 Act1 := Actuals_In_Call.Table (J).Act;
1242
1243 if Nkind (Act1) = N_Attribute_Reference then
1244 Act1 := Prefix (Act1);
1245 end if;
1246
1247 for K in 1 .. Actuals_In_Call.Last loop
1248 if K /= J then
1249 Act2 := Actuals_In_Call.Table (K).Act;
1250
1251 if Nkind (Act2) = N_Attribute_Reference then
1252 Act2 := Prefix (Act2);
1253 end if;
1254
1255 if Actuals_In_Call.Table (K).Is_Writable
1256 and then K < J
1257 then
1258 -- Already checked
1259
1260 null;
1261
1262 elsif Denotes_Same_Object (Act1, Act2)
1263 and then Parent (Act1) /= Parent (Act2)
1264 then
1265 Error_Msg_N
1266 ("result may differ if evaluated "
1267 & "after other actual in expression?", Act1);
1268 end if;
1269 end if;
1270 end loop;
1271 end if;
1272 end loop;
1273
1274 -- Remove checked actuals from table
1275
1276 Actuals_In_Call.Set_Last (0);
1277 end Check_Order_Dependence;
1278
1279 ------------------------------------------
1280 -- Check_Potentially_Blocking_Operation --
1281 ------------------------------------------
1282
1283 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
1284 S : Entity_Id;
1285
1286 begin
1287 -- N is one of the potentially blocking operations listed in 9.5.1(8).
1288 -- When pragma Detect_Blocking is active, the run time will raise
1289 -- Program_Error. Here we only issue a warning, since we generally
1290 -- support the use of potentially blocking operations in the absence
1291 -- of the pragma.
1292
1293 -- Indirect blocking through a subprogram call cannot be diagnosed
1294 -- statically without interprocedural analysis, so we do not attempt
1295 -- to do it here.
1296
1297 S := Scope (Current_Scope);
1298 while Present (S) and then S /= Standard_Standard loop
1299 if Is_Protected_Type (S) then
1300 Error_Msg_N
1301 ("potentially blocking operation in protected operation?", N);
1302 return;
1303 end if;
1304
1305 S := Scope (S);
1306 end loop;
1307 end Check_Potentially_Blocking_Operation;
1308
1309 ------------------------------
1310 -- Check_Unprotected_Access --
1311 ------------------------------
1312
1313 procedure Check_Unprotected_Access
1314 (Context : Node_Id;
1315 Expr : Node_Id)
1316 is
1317 Cont_Encl_Typ : Entity_Id;
1318 Pref_Encl_Typ : Entity_Id;
1319
1320 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
1321 -- Check whether Obj is a private component of a protected object.
1322 -- Return the protected type where the component resides, Empty
1323 -- otherwise.
1324
1325 function Is_Public_Operation return Boolean;
1326 -- Verify that the enclosing operation is callable from outside the
1327 -- protected object, to minimize false positives.
1328
1329 ------------------------------
1330 -- Enclosing_Protected_Type --
1331 ------------------------------
1332
1333 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
1334 begin
1335 if Is_Entity_Name (Obj) then
1336 declare
1337 Ent : Entity_Id := Entity (Obj);
1338
1339 begin
1340 -- The object can be a renaming of a private component, use
1341 -- the original record component.
1342
1343 if Is_Prival (Ent) then
1344 Ent := Prival_Link (Ent);
1345 end if;
1346
1347 if Is_Protected_Type (Scope (Ent)) then
1348 return Scope (Ent);
1349 end if;
1350 end;
1351 end if;
1352
1353 -- For indexed and selected components, recursively check the prefix
1354
1355 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
1356 return Enclosing_Protected_Type (Prefix (Obj));
1357
1358 -- The object does not denote a protected component
1359
1360 else
1361 return Empty;
1362 end if;
1363 end Enclosing_Protected_Type;
1364
1365 -------------------------
1366 -- Is_Public_Operation --
1367 -------------------------
1368
1369 function Is_Public_Operation return Boolean is
1370 S : Entity_Id;
1371 E : Entity_Id;
1372
1373 begin
1374 S := Current_Scope;
1375 while Present (S)
1376 and then S /= Pref_Encl_Typ
1377 loop
1378 if Scope (S) = Pref_Encl_Typ then
1379 E := First_Entity (Pref_Encl_Typ);
1380 while Present (E)
1381 and then E /= First_Private_Entity (Pref_Encl_Typ)
1382 loop
1383 if E = S then
1384 return True;
1385 end if;
1386 Next_Entity (E);
1387 end loop;
1388 end if;
1389
1390 S := Scope (S);
1391 end loop;
1392
1393 return False;
1394 end Is_Public_Operation;
1395
1396 -- Start of processing for Check_Unprotected_Access
1397
1398 begin
1399 if Nkind (Expr) = N_Attribute_Reference
1400 and then Attribute_Name (Expr) = Name_Unchecked_Access
1401 then
1402 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
1403 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
1404
1405 -- Check whether we are trying to export a protected component to a
1406 -- context with an equal or lower access level.
1407
1408 if Present (Pref_Encl_Typ)
1409 and then No (Cont_Encl_Typ)
1410 and then Is_Public_Operation
1411 and then Scope_Depth (Pref_Encl_Typ) >=
1412 Object_Access_Level (Context)
1413 then
1414 Error_Msg_N
1415 ("?possible unprotected access to protected data", Expr);
1416 end if;
1417 end if;
1418 end Check_Unprotected_Access;
1419
1420 ---------------
1421 -- Check_VMS --
1422 ---------------
1423
1424 procedure Check_VMS (Construct : Node_Id) is
1425 begin
1426 if not OpenVMS_On_Target then
1427 Error_Msg_N
1428 ("this construct is allowed only in Open'V'M'S", Construct);
1429 end if;
1430 end Check_VMS;
1431
1432 ------------------------
1433 -- Collect_Interfaces --
1434 ------------------------
1435
1436 procedure Collect_Interfaces
1437 (T : Entity_Id;
1438 Ifaces_List : out Elist_Id;
1439 Exclude_Parents : Boolean := False;
1440 Use_Full_View : Boolean := True)
1441 is
1442 procedure Collect (Typ : Entity_Id);
1443 -- Subsidiary subprogram used to traverse the whole list
1444 -- of directly and indirectly implemented interfaces
1445
1446 -------------
1447 -- Collect --
1448 -------------
1449
1450 procedure Collect (Typ : Entity_Id) is
1451 Ancestor : Entity_Id;
1452 Full_T : Entity_Id;
1453 Id : Node_Id;
1454 Iface : Entity_Id;
1455
1456 begin
1457 Full_T := Typ;
1458
1459 -- Handle private types
1460
1461 if Use_Full_View
1462 and then Is_Private_Type (Typ)
1463 and then Present (Full_View (Typ))
1464 then
1465 Full_T := Full_View (Typ);
1466 end if;
1467
1468 -- Include the ancestor if we are generating the whole list of
1469 -- abstract interfaces.
1470
1471 if Etype (Full_T) /= Typ
1472
1473 -- Protect the frontend against wrong sources. For example:
1474
1475 -- package P is
1476 -- type A is tagged null record;
1477 -- type B is new A with private;
1478 -- type C is new A with private;
1479 -- private
1480 -- type B is new C with null record;
1481 -- type C is new B with null record;
1482 -- end P;
1483
1484 and then Etype (Full_T) /= T
1485 then
1486 Ancestor := Etype (Full_T);
1487 Collect (Ancestor);
1488
1489 if Is_Interface (Ancestor)
1490 and then not Exclude_Parents
1491 then
1492 Append_Unique_Elmt (Ancestor, Ifaces_List);
1493 end if;
1494 end if;
1495
1496 -- Traverse the graph of ancestor interfaces
1497
1498 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
1499 Id := First (Abstract_Interface_List (Full_T));
1500 while Present (Id) loop
1501 Iface := Etype (Id);
1502
1503 -- Protect against wrong uses. For example:
1504 -- type I is interface;
1505 -- type O is tagged null record;
1506 -- type Wrong is new I and O with null record; -- ERROR
1507
1508 if Is_Interface (Iface) then
1509 if Exclude_Parents
1510 and then Etype (T) /= T
1511 and then Interface_Present_In_Ancestor (Etype (T), Iface)
1512 then
1513 null;
1514 else
1515 Collect (Iface);
1516 Append_Unique_Elmt (Iface, Ifaces_List);
1517 end if;
1518 end if;
1519
1520 Next (Id);
1521 end loop;
1522 end if;
1523 end Collect;
1524
1525 -- Start of processing for Collect_Interfaces
1526
1527 begin
1528 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
1529 Ifaces_List := New_Elmt_List;
1530 Collect (T);
1531 end Collect_Interfaces;
1532
1533 ----------------------------------
1534 -- Collect_Interface_Components --
1535 ----------------------------------
1536
1537 procedure Collect_Interface_Components
1538 (Tagged_Type : Entity_Id;
1539 Components_List : out Elist_Id)
1540 is
1541 procedure Collect (Typ : Entity_Id);
1542 -- Subsidiary subprogram used to climb to the parents
1543
1544 -------------
1545 -- Collect --
1546 -------------
1547
1548 procedure Collect (Typ : Entity_Id) is
1549 Tag_Comp : Entity_Id;
1550 Parent_Typ : Entity_Id;
1551
1552 begin
1553 -- Handle private types
1554
1555 if Present (Full_View (Etype (Typ))) then
1556 Parent_Typ := Full_View (Etype (Typ));
1557 else
1558 Parent_Typ := Etype (Typ);
1559 end if;
1560
1561 if Parent_Typ /= Typ
1562
1563 -- Protect the frontend against wrong sources. For example:
1564
1565 -- package P is
1566 -- type A is tagged null record;
1567 -- type B is new A with private;
1568 -- type C is new A with private;
1569 -- private
1570 -- type B is new C with null record;
1571 -- type C is new B with null record;
1572 -- end P;
1573
1574 and then Parent_Typ /= Tagged_Type
1575 then
1576 Collect (Parent_Typ);
1577 end if;
1578
1579 -- Collect the components containing tags of secondary dispatch
1580 -- tables.
1581
1582 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
1583 while Present (Tag_Comp) loop
1584 pragma Assert (Present (Related_Type (Tag_Comp)));
1585 Append_Elmt (Tag_Comp, Components_List);
1586
1587 Tag_Comp := Next_Tag_Component (Tag_Comp);
1588 end loop;
1589 end Collect;
1590
1591 -- Start of processing for Collect_Interface_Components
1592
1593 begin
1594 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
1595 and then Is_Tagged_Type (Tagged_Type));
1596
1597 Components_List := New_Elmt_List;
1598 Collect (Tagged_Type);
1599 end Collect_Interface_Components;
1600
1601 -----------------------------
1602 -- Collect_Interfaces_Info --
1603 -----------------------------
1604
1605 procedure Collect_Interfaces_Info
1606 (T : Entity_Id;
1607 Ifaces_List : out Elist_Id;
1608 Components_List : out Elist_Id;
1609 Tags_List : out Elist_Id)
1610 is
1611 Comps_List : Elist_Id;
1612 Comp_Elmt : Elmt_Id;
1613 Comp_Iface : Entity_Id;
1614 Iface_Elmt : Elmt_Id;
1615 Iface : Entity_Id;
1616
1617 function Search_Tag (Iface : Entity_Id) return Entity_Id;
1618 -- Search for the secondary tag associated with the interface type
1619 -- Iface that is implemented by T.
1620
1621 ----------------
1622 -- Search_Tag --
1623 ----------------
1624
1625 function Search_Tag (Iface : Entity_Id) return Entity_Id is
1626 ADT : Elmt_Id;
1627 begin
1628 if not Is_CPP_Class (T) then
1629 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
1630 else
1631 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
1632 end if;
1633
1634 while Present (ADT)
1635 and then Is_Tag (Node (ADT))
1636 and then Related_Type (Node (ADT)) /= Iface
1637 loop
1638 -- Skip secondary dispatch table referencing thunks to user
1639 -- defined primitives covered by this interface.
1640
1641 pragma Assert (Has_Suffix (Node (ADT), 'P'));
1642 Next_Elmt (ADT);
1643
1644 -- Skip secondary dispatch tables of Ada types
1645
1646 if not Is_CPP_Class (T) then
1647
1648 -- Skip secondary dispatch table referencing thunks to
1649 -- predefined primitives.
1650
1651 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
1652 Next_Elmt (ADT);
1653
1654 -- Skip secondary dispatch table referencing user-defined
1655 -- primitives covered by this interface.
1656
1657 pragma Assert (Has_Suffix (Node (ADT), 'D'));
1658 Next_Elmt (ADT);
1659
1660 -- Skip secondary dispatch table referencing predefined
1661 -- primitives.
1662
1663 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
1664 Next_Elmt (ADT);
1665 end if;
1666 end loop;
1667
1668 pragma Assert (Is_Tag (Node (ADT)));
1669 return Node (ADT);
1670 end Search_Tag;
1671
1672 -- Start of processing for Collect_Interfaces_Info
1673
1674 begin
1675 Collect_Interfaces (T, Ifaces_List);
1676 Collect_Interface_Components (T, Comps_List);
1677
1678 -- Search for the record component and tag associated with each
1679 -- interface type of T.
1680
1681 Components_List := New_Elmt_List;
1682 Tags_List := New_Elmt_List;
1683
1684 Iface_Elmt := First_Elmt (Ifaces_List);
1685 while Present (Iface_Elmt) loop
1686 Iface := Node (Iface_Elmt);
1687
1688 -- Associate the primary tag component and the primary dispatch table
1689 -- with all the interfaces that are parents of T
1690
1691 if Is_Ancestor (Iface, T, Use_Full_View => True) then
1692 Append_Elmt (First_Tag_Component (T), Components_List);
1693 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
1694
1695 -- Otherwise search for the tag component and secondary dispatch
1696 -- table of Iface
1697
1698 else
1699 Comp_Elmt := First_Elmt (Comps_List);
1700 while Present (Comp_Elmt) loop
1701 Comp_Iface := Related_Type (Node (Comp_Elmt));
1702
1703 if Comp_Iface = Iface
1704 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
1705 then
1706 Append_Elmt (Node (Comp_Elmt), Components_List);
1707 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
1708 exit;
1709 end if;
1710
1711 Next_Elmt (Comp_Elmt);
1712 end loop;
1713 pragma Assert (Present (Comp_Elmt));
1714 end if;
1715
1716 Next_Elmt (Iface_Elmt);
1717 end loop;
1718 end Collect_Interfaces_Info;
1719
1720 ---------------------
1721 -- Collect_Parents --
1722 ---------------------
1723
1724 procedure Collect_Parents
1725 (T : Entity_Id;
1726 List : out Elist_Id;
1727 Use_Full_View : Boolean := True)
1728 is
1729 Current_Typ : Entity_Id := T;
1730 Parent_Typ : Entity_Id;
1731
1732 begin
1733 List := New_Elmt_List;
1734
1735 -- No action if the if the type has no parents
1736
1737 if T = Etype (T) then
1738 return;
1739 end if;
1740
1741 loop
1742 Parent_Typ := Etype (Current_Typ);
1743
1744 if Is_Private_Type (Parent_Typ)
1745 and then Present (Full_View (Parent_Typ))
1746 and then Use_Full_View
1747 then
1748 Parent_Typ := Full_View (Base_Type (Parent_Typ));
1749 end if;
1750
1751 Append_Elmt (Parent_Typ, List);
1752
1753 exit when Parent_Typ = Current_Typ;
1754 Current_Typ := Parent_Typ;
1755 end loop;
1756 end Collect_Parents;
1757
1758 ----------------------------------
1759 -- Collect_Primitive_Operations --
1760 ----------------------------------
1761
1762 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
1763 B_Type : constant Entity_Id := Base_Type (T);
1764 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
1765 B_Scope : Entity_Id := Scope (B_Type);
1766 Op_List : Elist_Id;
1767 Formal : Entity_Id;
1768 Is_Prim : Boolean;
1769 Formal_Derived : Boolean := False;
1770 Id : Entity_Id;
1771
1772 function Match (E : Entity_Id) return Boolean;
1773 -- True if E's base type is B_Type, or E is of an anonymous access type
1774 -- and the base type of its designated type is B_Type.
1775
1776 -----------
1777 -- Match --
1778 -----------
1779
1780 function Match (E : Entity_Id) return Boolean is
1781 Etyp : Entity_Id := Etype (E);
1782
1783 begin
1784 if Ekind (Etyp) = E_Anonymous_Access_Type then
1785 Etyp := Designated_Type (Etyp);
1786 end if;
1787
1788 return Base_Type (Etyp) = B_Type;
1789 end Match;
1790
1791 -- Start of processing for Collect_Primitive_Operations
1792
1793 begin
1794 -- For tagged types, the primitive operations are collected as they
1795 -- are declared, and held in an explicit list which is simply returned.
1796
1797 if Is_Tagged_Type (B_Type) then
1798 return Primitive_Operations (B_Type);
1799
1800 -- An untagged generic type that is a derived type inherits the
1801 -- primitive operations of its parent type. Other formal types only
1802 -- have predefined operators, which are not explicitly represented.
1803
1804 elsif Is_Generic_Type (B_Type) then
1805 if Nkind (B_Decl) = N_Formal_Type_Declaration
1806 and then Nkind (Formal_Type_Definition (B_Decl))
1807 = N_Formal_Derived_Type_Definition
1808 then
1809 Formal_Derived := True;
1810 else
1811 return New_Elmt_List;
1812 end if;
1813 end if;
1814
1815 Op_List := New_Elmt_List;
1816
1817 if B_Scope = Standard_Standard then
1818 if B_Type = Standard_String then
1819 Append_Elmt (Standard_Op_Concat, Op_List);
1820
1821 elsif B_Type = Standard_Wide_String then
1822 Append_Elmt (Standard_Op_Concatw, Op_List);
1823
1824 else
1825 null;
1826 end if;
1827
1828 elsif (Is_Package_Or_Generic_Package (B_Scope)
1829 and then
1830 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
1831 N_Package_Body)
1832 or else Is_Derived_Type (B_Type)
1833 then
1834 -- The primitive operations appear after the base type, except
1835 -- if the derivation happens within the private part of B_Scope
1836 -- and the type is a private type, in which case both the type
1837 -- and some primitive operations may appear before the base
1838 -- type, and the list of candidates starts after the type.
1839
1840 if In_Open_Scopes (B_Scope)
1841 and then Scope (T) = B_Scope
1842 and then In_Private_Part (B_Scope)
1843 then
1844 Id := Next_Entity (T);
1845 else
1846 Id := Next_Entity (B_Type);
1847 end if;
1848
1849 while Present (Id) loop
1850
1851 -- Note that generic formal subprograms are not
1852 -- considered to be primitive operations and thus
1853 -- are never inherited.
1854
1855 if Is_Overloadable (Id)
1856 and then Nkind (Parent (Parent (Id)))
1857 not in N_Formal_Subprogram_Declaration
1858 then
1859 Is_Prim := False;
1860
1861 if Match (Id) then
1862 Is_Prim := True;
1863
1864 else
1865 Formal := First_Formal (Id);
1866 while Present (Formal) loop
1867 if Match (Formal) then
1868 Is_Prim := True;
1869 exit;
1870 end if;
1871
1872 Next_Formal (Formal);
1873 end loop;
1874 end if;
1875
1876 -- For a formal derived type, the only primitives are the
1877 -- ones inherited from the parent type. Operations appearing
1878 -- in the package declaration are not primitive for it.
1879
1880 if Is_Prim
1881 and then (not Formal_Derived
1882 or else Present (Alias (Id)))
1883 then
1884 -- In the special case of an equality operator aliased to
1885 -- an overriding dispatching equality belonging to the same
1886 -- type, we don't include it in the list of primitives.
1887 -- This avoids inheriting multiple equality operators when
1888 -- deriving from untagged private types whose full type is
1889 -- tagged, which can otherwise cause ambiguities. Note that
1890 -- this should only happen for this kind of untagged parent
1891 -- type, since normally dispatching operations are inherited
1892 -- using the type's Primitive_Operations list.
1893
1894 if Chars (Id) = Name_Op_Eq
1895 and then Is_Dispatching_Operation (Id)
1896 and then Present (Alias (Id))
1897 and then Present (Overridden_Operation (Alias (Id)))
1898 and then Base_Type (Etype (First_Entity (Id))) =
1899 Base_Type (Etype (First_Entity (Alias (Id))))
1900 then
1901 null;
1902
1903 -- Include the subprogram in the list of primitives
1904
1905 else
1906 Append_Elmt (Id, Op_List);
1907 end if;
1908 end if;
1909 end if;
1910
1911 Next_Entity (Id);
1912
1913 -- For a type declared in System, some of its operations may
1914 -- appear in the target-specific extension to System.
1915
1916 if No (Id)
1917 and then B_Scope = RTU_Entity (System)
1918 and then Present_System_Aux
1919 then
1920 B_Scope := System_Aux_Id;
1921 Id := First_Entity (System_Aux_Id);
1922 end if;
1923 end loop;
1924 end if;
1925
1926 return Op_List;
1927 end Collect_Primitive_Operations;
1928
1929 -----------------------------------
1930 -- Compile_Time_Constraint_Error --
1931 -----------------------------------
1932
1933 function Compile_Time_Constraint_Error
1934 (N : Node_Id;
1935 Msg : String;
1936 Ent : Entity_Id := Empty;
1937 Loc : Source_Ptr := No_Location;
1938 Warn : Boolean := False) return Node_Id
1939 is
1940 Msgc : String (1 .. Msg'Length + 2);
1941 -- Copy of message, with room for possible ? and ! at end
1942
1943 Msgl : Natural;
1944 Wmsg : Boolean;
1945 P : Node_Id;
1946 OldP : Node_Id;
1947 Msgs : Boolean;
1948 Eloc : Source_Ptr;
1949
1950 begin
1951 -- A static constraint error in an instance body is not a fatal error.
1952 -- we choose to inhibit the message altogether, because there is no
1953 -- obvious node (for now) on which to post it. On the other hand the
1954 -- offending node must be replaced with a constraint_error in any case.
1955
1956 -- No messages are generated if we already posted an error on this node
1957
1958 if not Error_Posted (N) then
1959 if Loc /= No_Location then
1960 Eloc := Loc;
1961 else
1962 Eloc := Sloc (N);
1963 end if;
1964
1965 Msgc (1 .. Msg'Length) := Msg;
1966 Msgl := Msg'Length;
1967
1968 -- Message is a warning, even in Ada 95 case
1969
1970 if Msg (Msg'Last) = '?' then
1971 Wmsg := True;
1972
1973 -- In Ada 83, all messages are warnings. In the private part and
1974 -- the body of an instance, constraint_checks are only warnings.
1975 -- We also make this a warning if the Warn parameter is set.
1976
1977 elsif Warn
1978 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
1979 then
1980 Msgl := Msgl + 1;
1981 Msgc (Msgl) := '?';
1982 Wmsg := True;
1983
1984 elsif In_Instance_Not_Visible then
1985 Msgl := Msgl + 1;
1986 Msgc (Msgl) := '?';
1987 Wmsg := True;
1988
1989 -- Otherwise we have a real error message (Ada 95 static case)
1990 -- and we make this an unconditional message. Note that in the
1991 -- warning case we do not make the message unconditional, it seems
1992 -- quite reasonable to delete messages like this (about exceptions
1993 -- that will be raised) in dead code.
1994
1995 else
1996 Wmsg := False;
1997 Msgl := Msgl + 1;
1998 Msgc (Msgl) := '!';
1999 end if;
2000
2001 -- Should we generate a warning? The answer is not quite yes. The
2002 -- very annoying exception occurs in the case of a short circuit
2003 -- operator where the left operand is static and decisive. Climb
2004 -- parents to see if that is the case we have here. Conditional
2005 -- expressions with decisive conditions are a similar situation.
2006
2007 Msgs := True;
2008 P := N;
2009 loop
2010 OldP := P;
2011 P := Parent (P);
2012
2013 -- And then with False as left operand
2014
2015 if Nkind (P) = N_And_Then
2016 and then Compile_Time_Known_Value (Left_Opnd (P))
2017 and then Is_False (Expr_Value (Left_Opnd (P)))
2018 then
2019 Msgs := False;
2020 exit;
2021
2022 -- OR ELSE with True as left operand
2023
2024 elsif Nkind (P) = N_Or_Else
2025 and then Compile_Time_Known_Value (Left_Opnd (P))
2026 and then Is_True (Expr_Value (Left_Opnd (P)))
2027 then
2028 Msgs := False;
2029 exit;
2030
2031 -- Conditional expression
2032
2033 elsif Nkind (P) = N_Conditional_Expression then
2034 declare
2035 Cond : constant Node_Id := First (Expressions (P));
2036 Texp : constant Node_Id := Next (Cond);
2037 Fexp : constant Node_Id := Next (Texp);
2038
2039 begin
2040 if Compile_Time_Known_Value (Cond) then
2041
2042 -- Condition is True and we are in the right operand
2043
2044 if Is_True (Expr_Value (Cond))
2045 and then OldP = Fexp
2046 then
2047 Msgs := False;
2048 exit;
2049
2050 -- Condition is False and we are in the left operand
2051
2052 elsif Is_False (Expr_Value (Cond))
2053 and then OldP = Texp
2054 then
2055 Msgs := False;
2056 exit;
2057 end if;
2058 end if;
2059 end;
2060
2061 -- Special case for component association in aggregates, where
2062 -- we want to keep climbing up to the parent aggregate.
2063
2064 elsif Nkind (P) = N_Component_Association
2065 and then Nkind (Parent (P)) = N_Aggregate
2066 then
2067 null;
2068
2069 -- Keep going if within subexpression
2070
2071 else
2072 exit when Nkind (P) not in N_Subexpr;
2073 end if;
2074 end loop;
2075
2076 if Msgs then
2077 if Present (Ent) then
2078 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
2079 else
2080 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
2081 end if;
2082
2083 if Wmsg then
2084 if Inside_Init_Proc then
2085 Error_Msg_NEL
2086 ("\?& will be raised for objects of this type",
2087 N, Standard_Constraint_Error, Eloc);
2088 else
2089 Error_Msg_NEL
2090 ("\?& will be raised at run time",
2091 N, Standard_Constraint_Error, Eloc);
2092 end if;
2093
2094 else
2095 Error_Msg
2096 ("\static expression fails Constraint_Check", Eloc);
2097 Set_Error_Posted (N);
2098 end if;
2099 end if;
2100 end if;
2101
2102 return N;
2103 end Compile_Time_Constraint_Error;
2104
2105 -----------------------
2106 -- Conditional_Delay --
2107 -----------------------
2108
2109 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
2110 begin
2111 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
2112 Set_Has_Delayed_Freeze (New_Ent);
2113 end if;
2114 end Conditional_Delay;
2115
2116 -------------------------
2117 -- Copy_Parameter_List --
2118 -------------------------
2119
2120 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
2121 Loc : constant Source_Ptr := Sloc (Subp_Id);
2122 Plist : List_Id;
2123 Formal : Entity_Id;
2124
2125 begin
2126 if No (First_Formal (Subp_Id)) then
2127 return No_List;
2128 else
2129 Plist := New_List;
2130 Formal := First_Formal (Subp_Id);
2131 while Present (Formal) loop
2132 Append
2133 (Make_Parameter_Specification (Loc,
2134 Defining_Identifier =>
2135 Make_Defining_Identifier (Sloc (Formal),
2136 Chars => Chars (Formal)),
2137 In_Present => In_Present (Parent (Formal)),
2138 Out_Present => Out_Present (Parent (Formal)),
2139 Parameter_Type =>
2140 New_Reference_To (Etype (Formal), Loc),
2141 Expression =>
2142 New_Copy_Tree (Expression (Parent (Formal)))),
2143 Plist);
2144
2145 Next_Formal (Formal);
2146 end loop;
2147 end if;
2148
2149 return Plist;
2150 end Copy_Parameter_List;
2151
2152 --------------------
2153 -- Current_Entity --
2154 --------------------
2155
2156 -- The currently visible definition for a given identifier is the
2157 -- one most chained at the start of the visibility chain, i.e. the
2158 -- one that is referenced by the Node_Id value of the name of the
2159 -- given identifier.
2160
2161 function Current_Entity (N : Node_Id) return Entity_Id is
2162 begin
2163 return Get_Name_Entity_Id (Chars (N));
2164 end Current_Entity;
2165
2166 -----------------------------
2167 -- Current_Entity_In_Scope --
2168 -----------------------------
2169
2170 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
2171 E : Entity_Id;
2172 CS : constant Entity_Id := Current_Scope;
2173
2174 Transient_Case : constant Boolean := Scope_Is_Transient;
2175
2176 begin
2177 E := Get_Name_Entity_Id (Chars (N));
2178 while Present (E)
2179 and then Scope (E) /= CS
2180 and then (not Transient_Case or else Scope (E) /= Scope (CS))
2181 loop
2182 E := Homonym (E);
2183 end loop;
2184
2185 return E;
2186 end Current_Entity_In_Scope;
2187
2188 -------------------
2189 -- Current_Scope --
2190 -------------------
2191
2192 function Current_Scope return Entity_Id is
2193 begin
2194 if Scope_Stack.Last = -1 then
2195 return Standard_Standard;
2196 else
2197 declare
2198 C : constant Entity_Id :=
2199 Scope_Stack.Table (Scope_Stack.Last).Entity;
2200 begin
2201 if Present (C) then
2202 return C;
2203 else
2204 return Standard_Standard;
2205 end if;
2206 end;
2207 end if;
2208 end Current_Scope;
2209
2210 ------------------------
2211 -- Current_Subprogram --
2212 ------------------------
2213
2214 function Current_Subprogram return Entity_Id is
2215 Scop : constant Entity_Id := Current_Scope;
2216 begin
2217 if Is_Subprogram (Scop) or else Is_Generic_Subprogram (Scop) then
2218 return Scop;
2219 else
2220 return Enclosing_Subprogram (Scop);
2221 end if;
2222 end Current_Subprogram;
2223
2224 ---------------------
2225 -- Defining_Entity --
2226 ---------------------
2227
2228 function Defining_Entity (N : Node_Id) return Entity_Id is
2229 K : constant Node_Kind := Nkind (N);
2230 Err : Entity_Id := Empty;
2231
2232 begin
2233 case K is
2234 when
2235 N_Subprogram_Declaration |
2236 N_Abstract_Subprogram_Declaration |
2237 N_Subprogram_Body |
2238 N_Package_Declaration |
2239 N_Subprogram_Renaming_Declaration |
2240 N_Subprogram_Body_Stub |
2241 N_Generic_Subprogram_Declaration |
2242 N_Generic_Package_Declaration |
2243 N_Formal_Subprogram_Declaration
2244 =>
2245 return Defining_Entity (Specification (N));
2246
2247 when
2248 N_Component_Declaration |
2249 N_Defining_Program_Unit_Name |
2250 N_Discriminant_Specification |
2251 N_Entry_Body |
2252 N_Entry_Declaration |
2253 N_Entry_Index_Specification |
2254 N_Exception_Declaration |
2255 N_Exception_Renaming_Declaration |
2256 N_Formal_Object_Declaration |
2257 N_Formal_Package_Declaration |
2258 N_Formal_Type_Declaration |
2259 N_Full_Type_Declaration |
2260 N_Implicit_Label_Declaration |
2261 N_Incomplete_Type_Declaration |
2262 N_Loop_Parameter_Specification |
2263 N_Number_Declaration |
2264 N_Object_Declaration |
2265 N_Object_Renaming_Declaration |
2266 N_Package_Body_Stub |
2267 N_Parameter_Specification |
2268 N_Private_Extension_Declaration |
2269 N_Private_Type_Declaration |
2270 N_Protected_Body |
2271 N_Protected_Body_Stub |
2272 N_Protected_Type_Declaration |
2273 N_Single_Protected_Declaration |
2274 N_Single_Task_Declaration |
2275 N_Subtype_Declaration |
2276 N_Task_Body |
2277 N_Task_Body_Stub |
2278 N_Task_Type_Declaration
2279 =>
2280 return Defining_Identifier (N);
2281
2282 when N_Subunit =>
2283 return Defining_Entity (Proper_Body (N));
2284
2285 when
2286 N_Function_Instantiation |
2287 N_Function_Specification |
2288 N_Generic_Function_Renaming_Declaration |
2289 N_Generic_Package_Renaming_Declaration |
2290 N_Generic_Procedure_Renaming_Declaration |
2291 N_Package_Body |
2292 N_Package_Instantiation |
2293 N_Package_Renaming_Declaration |
2294 N_Package_Specification |
2295 N_Procedure_Instantiation |
2296 N_Procedure_Specification
2297 =>
2298 declare
2299 Nam : constant Node_Id := Defining_Unit_Name (N);
2300
2301 begin
2302 if Nkind (Nam) in N_Entity then
2303 return Nam;
2304
2305 -- For Error, make up a name and attach to declaration
2306 -- so we can continue semantic analysis
2307
2308 elsif Nam = Error then
2309 Err := Make_Temporary (Sloc (N), 'T');
2310 Set_Defining_Unit_Name (N, Err);
2311
2312 return Err;
2313 -- If not an entity, get defining identifier
2314
2315 else
2316 return Defining_Identifier (Nam);
2317 end if;
2318 end;
2319
2320 when N_Block_Statement =>
2321 return Entity (Identifier (N));
2322
2323 when others =>
2324 raise Program_Error;
2325
2326 end case;
2327 end Defining_Entity;
2328
2329 --------------------------
2330 -- Denotes_Discriminant --
2331 --------------------------
2332
2333 function Denotes_Discriminant
2334 (N : Node_Id;
2335 Check_Concurrent : Boolean := False) return Boolean
2336 is
2337 E : Entity_Id;
2338 begin
2339 if not Is_Entity_Name (N)
2340 or else No (Entity (N))
2341 then
2342 return False;
2343 else
2344 E := Entity (N);
2345 end if;
2346
2347 -- If we are checking for a protected type, the discriminant may have
2348 -- been rewritten as the corresponding discriminal of the original type
2349 -- or of the corresponding concurrent record, depending on whether we
2350 -- are in the spec or body of the protected type.
2351
2352 return Ekind (E) = E_Discriminant
2353 or else
2354 (Check_Concurrent
2355 and then Ekind (E) = E_In_Parameter
2356 and then Present (Discriminal_Link (E))
2357 and then
2358 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
2359 or else
2360 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
2361
2362 end Denotes_Discriminant;
2363
2364 -------------------------
2365 -- Denotes_Same_Object --
2366 -------------------------
2367
2368 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
2369 Obj1 : Node_Id := A1;
2370 Obj2 : Node_Id := A2;
2371
2372 procedure Check_Renaming (Obj : in out Node_Id);
2373 -- If an object is a renaming, examine renamed object. If it is a
2374 -- dereference of a variable, or an indexed expression with non-constant
2375 -- indexes, no overlap check can be reported.
2376
2377 --------------------
2378 -- Check_Renaming --
2379 --------------------
2380
2381 procedure Check_Renaming (Obj : in out Node_Id) is
2382 begin
2383 if Is_Entity_Name (Obj)
2384 and then Present (Renamed_Entity (Entity (Obj)))
2385 then
2386 Obj := Renamed_Entity (Entity (Obj));
2387 if Nkind (Obj) = N_Explicit_Dereference
2388 and then Is_Variable (Prefix (Obj))
2389 then
2390 Obj := Empty;
2391
2392 elsif Nkind (Obj) = N_Indexed_Component then
2393 declare
2394 Indx : Node_Id;
2395
2396 begin
2397 Indx := First (Expressions (Obj));
2398 while Present (Indx) loop
2399 if not Is_OK_Static_Expression (Indx) then
2400 Obj := Empty;
2401 exit;
2402 end if;
2403
2404 Next_Index (Indx);
2405 end loop;
2406 end;
2407 end if;
2408 end if;
2409 end Check_Renaming;
2410
2411 -- Start of processing for Denotes_Same_Object
2412
2413 begin
2414 Check_Renaming (Obj1);
2415 Check_Renaming (Obj2);
2416
2417 if No (Obj1)
2418 or else No (Obj2)
2419 then
2420 return False;
2421 end if;
2422
2423 -- If we have entity names, then must be same entity
2424
2425 if Is_Entity_Name (Obj1) then
2426 if Is_Entity_Name (Obj2) then
2427 return Entity (Obj1) = Entity (Obj2);
2428 else
2429 return False;
2430 end if;
2431
2432 -- No match if not same node kind
2433
2434 elsif Nkind (Obj1) /= Nkind (Obj2) then
2435 return False;
2436
2437 -- For selected components, must have same prefix and selector
2438
2439 elsif Nkind (Obj1) = N_Selected_Component then
2440 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
2441 and then
2442 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
2443
2444 -- For explicit dereferences, prefixes must be same
2445
2446 elsif Nkind (Obj1) = N_Explicit_Dereference then
2447 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
2448
2449 -- For indexed components, prefixes and all subscripts must be the same
2450
2451 elsif Nkind (Obj1) = N_Indexed_Component then
2452 if Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
2453 declare
2454 Indx1 : Node_Id;
2455 Indx2 : Node_Id;
2456
2457 begin
2458 Indx1 := First (Expressions (Obj1));
2459 Indx2 := First (Expressions (Obj2));
2460 while Present (Indx1) loop
2461
2462 -- Indexes must denote the same static value or same object
2463
2464 if Is_OK_Static_Expression (Indx1) then
2465 if not Is_OK_Static_Expression (Indx2) then
2466 return False;
2467
2468 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
2469 return False;
2470 end if;
2471
2472 elsif not Denotes_Same_Object (Indx1, Indx2) then
2473 return False;
2474 end if;
2475
2476 Next (Indx1);
2477 Next (Indx2);
2478 end loop;
2479
2480 return True;
2481 end;
2482 else
2483 return False;
2484 end if;
2485
2486 -- For slices, prefixes must match and bounds must match
2487
2488 elsif Nkind (Obj1) = N_Slice
2489 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
2490 then
2491 declare
2492 Lo1, Lo2, Hi1, Hi2 : Node_Id;
2493
2494 begin
2495 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
2496 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
2497
2498 -- Check whether bounds are statically identical. There is no
2499 -- attempt to detect partial overlap of slices.
2500
2501 return Denotes_Same_Object (Lo1, Lo2)
2502 and then Denotes_Same_Object (Hi1, Hi2);
2503 end;
2504
2505 -- Literals will appear as indexes. Isn't this where we should check
2506 -- Known_At_Compile_Time at least if we are generating warnings ???
2507
2508 elsif Nkind (Obj1) = N_Integer_Literal then
2509 return Intval (Obj1) = Intval (Obj2);
2510
2511 else
2512 return False;
2513 end if;
2514 end Denotes_Same_Object;
2515
2516 -------------------------
2517 -- Denotes_Same_Prefix --
2518 -------------------------
2519
2520 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
2521
2522 begin
2523 if Is_Entity_Name (A1) then
2524 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
2525 and then not Is_Access_Type (Etype (A1))
2526 then
2527 return Denotes_Same_Object (A1, Prefix (A2))
2528 or else Denotes_Same_Prefix (A1, Prefix (A2));
2529 else
2530 return False;
2531 end if;
2532
2533 elsif Is_Entity_Name (A2) then
2534 return Denotes_Same_Prefix (A2, A1);
2535
2536 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
2537 and then
2538 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
2539 then
2540 declare
2541 Root1, Root2 : Node_Id;
2542 Depth1, Depth2 : Int := 0;
2543
2544 begin
2545 Root1 := Prefix (A1);
2546 while not Is_Entity_Name (Root1) loop
2547 if not Nkind_In
2548 (Root1, N_Selected_Component, N_Indexed_Component)
2549 then
2550 return False;
2551 else
2552 Root1 := Prefix (Root1);
2553 end if;
2554
2555 Depth1 := Depth1 + 1;
2556 end loop;
2557
2558 Root2 := Prefix (A2);
2559 while not Is_Entity_Name (Root2) loop
2560 if not Nkind_In
2561 (Root2, N_Selected_Component, N_Indexed_Component)
2562 then
2563 return False;
2564 else
2565 Root2 := Prefix (Root2);
2566 end if;
2567
2568 Depth2 := Depth2 + 1;
2569 end loop;
2570
2571 -- If both have the same depth and they do not denote the same
2572 -- object, they are disjoint and not warning is needed.
2573
2574 if Depth1 = Depth2 then
2575 return False;
2576
2577 elsif Depth1 > Depth2 then
2578 Root1 := Prefix (A1);
2579 for I in 1 .. Depth1 - Depth2 - 1 loop
2580 Root1 := Prefix (Root1);
2581 end loop;
2582
2583 return Denotes_Same_Object (Root1, A2);
2584
2585 else
2586 Root2 := Prefix (A2);
2587 for I in 1 .. Depth2 - Depth1 - 1 loop
2588 Root2 := Prefix (Root2);
2589 end loop;
2590
2591 return Denotes_Same_Object (A1, Root2);
2592 end if;
2593 end;
2594
2595 else
2596 return False;
2597 end if;
2598 end Denotes_Same_Prefix;
2599
2600 ----------------------
2601 -- Denotes_Variable --
2602 ----------------------
2603
2604 function Denotes_Variable (N : Node_Id) return Boolean is
2605 begin
2606 return Is_Variable (N) and then Paren_Count (N) = 0;
2607 end Denotes_Variable;
2608
2609 -----------------------------
2610 -- Depends_On_Discriminant --
2611 -----------------------------
2612
2613 function Depends_On_Discriminant (N : Node_Id) return Boolean is
2614 L : Node_Id;
2615 H : Node_Id;
2616
2617 begin
2618 Get_Index_Bounds (N, L, H);
2619 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
2620 end Depends_On_Discriminant;
2621
2622 -------------------------
2623 -- Designate_Same_Unit --
2624 -------------------------
2625
2626 function Designate_Same_Unit
2627 (Name1 : Node_Id;
2628 Name2 : Node_Id) return Boolean
2629 is
2630 K1 : constant Node_Kind := Nkind (Name1);
2631 K2 : constant Node_Kind := Nkind (Name2);
2632
2633 function Prefix_Node (N : Node_Id) return Node_Id;
2634 -- Returns the parent unit name node of a defining program unit name
2635 -- or the prefix if N is a selected component or an expanded name.
2636
2637 function Select_Node (N : Node_Id) return Node_Id;
2638 -- Returns the defining identifier node of a defining program unit
2639 -- name or the selector node if N is a selected component or an
2640 -- expanded name.
2641
2642 -----------------
2643 -- Prefix_Node --
2644 -----------------
2645
2646 function Prefix_Node (N : Node_Id) return Node_Id is
2647 begin
2648 if Nkind (N) = N_Defining_Program_Unit_Name then
2649 return Name (N);
2650
2651 else
2652 return Prefix (N);
2653 end if;
2654 end Prefix_Node;
2655
2656 -----------------
2657 -- Select_Node --
2658 -----------------
2659
2660 function Select_Node (N : Node_Id) return Node_Id is
2661 begin
2662 if Nkind (N) = N_Defining_Program_Unit_Name then
2663 return Defining_Identifier (N);
2664
2665 else
2666 return Selector_Name (N);
2667 end if;
2668 end Select_Node;
2669
2670 -- Start of processing for Designate_Next_Unit
2671
2672 begin
2673 if (K1 = N_Identifier or else
2674 K1 = N_Defining_Identifier)
2675 and then
2676 (K2 = N_Identifier or else
2677 K2 = N_Defining_Identifier)
2678 then
2679 return Chars (Name1) = Chars (Name2);
2680
2681 elsif
2682 (K1 = N_Expanded_Name or else
2683 K1 = N_Selected_Component or else
2684 K1 = N_Defining_Program_Unit_Name)
2685 and then
2686 (K2 = N_Expanded_Name or else
2687 K2 = N_Selected_Component or else
2688 K2 = N_Defining_Program_Unit_Name)
2689 then
2690 return
2691 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
2692 and then
2693 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
2694
2695 else
2696 return False;
2697 end if;
2698 end Designate_Same_Unit;
2699
2700 --------------------------
2701 -- Enclosing_CPP_Parent --
2702 --------------------------
2703
2704 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
2705 Parent_Typ : Entity_Id := Typ;
2706
2707 begin
2708 while not Is_CPP_Class (Parent_Typ)
2709 and then Etype (Parent_Typ) /= Parent_Typ
2710 loop
2711 Parent_Typ := Etype (Parent_Typ);
2712
2713 if Is_Private_Type (Parent_Typ) then
2714 Parent_Typ := Full_View (Base_Type (Parent_Typ));
2715 end if;
2716 end loop;
2717
2718 pragma Assert (Is_CPP_Class (Parent_Typ));
2719 return Parent_Typ;
2720 end Enclosing_CPP_Parent;
2721
2722 ----------------------------
2723 -- Enclosing_Generic_Body --
2724 ----------------------------
2725
2726 function Enclosing_Generic_Body
2727 (N : Node_Id) return Node_Id
2728 is
2729 P : Node_Id;
2730 Decl : Node_Id;
2731 Spec : Node_Id;
2732
2733 begin
2734 P := Parent (N);
2735 while Present (P) loop
2736 if Nkind (P) = N_Package_Body
2737 or else Nkind (P) = N_Subprogram_Body
2738 then
2739 Spec := Corresponding_Spec (P);
2740
2741 if Present (Spec) then
2742 Decl := Unit_Declaration_Node (Spec);
2743
2744 if Nkind (Decl) = N_Generic_Package_Declaration
2745 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2746 then
2747 return P;
2748 end if;
2749 end if;
2750 end if;
2751
2752 P := Parent (P);
2753 end loop;
2754
2755 return Empty;
2756 end Enclosing_Generic_Body;
2757
2758 ----------------------------
2759 -- Enclosing_Generic_Unit --
2760 ----------------------------
2761
2762 function Enclosing_Generic_Unit
2763 (N : Node_Id) return Node_Id
2764 is
2765 P : Node_Id;
2766 Decl : Node_Id;
2767 Spec : Node_Id;
2768
2769 begin
2770 P := Parent (N);
2771 while Present (P) loop
2772 if Nkind (P) = N_Generic_Package_Declaration
2773 or else Nkind (P) = N_Generic_Subprogram_Declaration
2774 then
2775 return P;
2776
2777 elsif Nkind (P) = N_Package_Body
2778 or else Nkind (P) = N_Subprogram_Body
2779 then
2780 Spec := Corresponding_Spec (P);
2781
2782 if Present (Spec) then
2783 Decl := Unit_Declaration_Node (Spec);
2784
2785 if Nkind (Decl) = N_Generic_Package_Declaration
2786 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
2787 then
2788 return Decl;
2789 end if;
2790 end if;
2791 end if;
2792
2793 P := Parent (P);
2794 end loop;
2795
2796 return Empty;
2797 end Enclosing_Generic_Unit;
2798
2799 -------------------------------
2800 -- Enclosing_Lib_Unit_Entity --
2801 -------------------------------
2802
2803 function Enclosing_Lib_Unit_Entity return Entity_Id is
2804 Unit_Entity : Entity_Id;
2805
2806 begin
2807 -- Look for enclosing library unit entity by following scope links.
2808 -- Equivalent to, but faster than indexing through the scope stack.
2809
2810 Unit_Entity := Current_Scope;
2811 while (Present (Scope (Unit_Entity))
2812 and then Scope (Unit_Entity) /= Standard_Standard)
2813 and not Is_Child_Unit (Unit_Entity)
2814 loop
2815 Unit_Entity := Scope (Unit_Entity);
2816 end loop;
2817
2818 return Unit_Entity;
2819 end Enclosing_Lib_Unit_Entity;
2820
2821 -----------------------------
2822 -- Enclosing_Lib_Unit_Node --
2823 -----------------------------
2824
2825 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
2826 Current_Node : Node_Id;
2827
2828 begin
2829 Current_Node := N;
2830 while Present (Current_Node)
2831 and then Nkind (Current_Node) /= N_Compilation_Unit
2832 loop
2833 Current_Node := Parent (Current_Node);
2834 end loop;
2835
2836 if Nkind (Current_Node) /= N_Compilation_Unit then
2837 return Empty;
2838 end if;
2839
2840 return Current_Node;
2841 end Enclosing_Lib_Unit_Node;
2842
2843 --------------------------
2844 -- Enclosing_Subprogram --
2845 --------------------------
2846
2847 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
2848 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
2849
2850 begin
2851 if Dynamic_Scope = Standard_Standard then
2852 return Empty;
2853
2854 elsif Dynamic_Scope = Empty then
2855 return Empty;
2856
2857 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
2858 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
2859
2860 elsif Ekind (Dynamic_Scope) = E_Block
2861 or else Ekind (Dynamic_Scope) = E_Return_Statement
2862 then
2863 return Enclosing_Subprogram (Dynamic_Scope);
2864
2865 elsif Ekind (Dynamic_Scope) = E_Task_Type then
2866 return Get_Task_Body_Procedure (Dynamic_Scope);
2867
2868 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
2869 and then Present (Full_View (Dynamic_Scope))
2870 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
2871 then
2872 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
2873
2874 -- No body is generated if the protected operation is eliminated
2875
2876 elsif Convention (Dynamic_Scope) = Convention_Protected
2877 and then not Is_Eliminated (Dynamic_Scope)
2878 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
2879 then
2880 return Protected_Body_Subprogram (Dynamic_Scope);
2881
2882 else
2883 return Dynamic_Scope;
2884 end if;
2885 end Enclosing_Subprogram;
2886
2887 ------------------------
2888 -- Ensure_Freeze_Node --
2889 ------------------------
2890
2891 procedure Ensure_Freeze_Node (E : Entity_Id) is
2892 FN : Node_Id;
2893
2894 begin
2895 if No (Freeze_Node (E)) then
2896 FN := Make_Freeze_Entity (Sloc (E));
2897 Set_Has_Delayed_Freeze (E);
2898 Set_Freeze_Node (E, FN);
2899 Set_Access_Types_To_Process (FN, No_Elist);
2900 Set_TSS_Elist (FN, No_Elist);
2901 Set_Entity (FN, E);
2902 end if;
2903 end Ensure_Freeze_Node;
2904
2905 ----------------
2906 -- Enter_Name --
2907 ----------------
2908
2909 procedure Enter_Name (Def_Id : Entity_Id) is
2910 C : constant Entity_Id := Current_Entity (Def_Id);
2911 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
2912 S : constant Entity_Id := Current_Scope;
2913
2914 begin
2915 Generate_Definition (Def_Id);
2916
2917 -- Add new name to current scope declarations. Check for duplicate
2918 -- declaration, which may or may not be a genuine error.
2919
2920 if Present (E) then
2921
2922 -- Case of previous entity entered because of a missing declaration
2923 -- or else a bad subtype indication. Best is to use the new entity,
2924 -- and make the previous one invisible.
2925
2926 if Etype (E) = Any_Type then
2927 Set_Is_Immediately_Visible (E, False);
2928
2929 -- Case of renaming declaration constructed for package instances.
2930 -- if there is an explicit declaration with the same identifier,
2931 -- the renaming is not immediately visible any longer, but remains
2932 -- visible through selected component notation.
2933
2934 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
2935 and then not Comes_From_Source (E)
2936 then
2937 Set_Is_Immediately_Visible (E, False);
2938
2939 -- The new entity may be the package renaming, which has the same
2940 -- same name as a generic formal which has been seen already.
2941
2942 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
2943 and then not Comes_From_Source (Def_Id)
2944 then
2945 Set_Is_Immediately_Visible (E, False);
2946
2947 -- For a fat pointer corresponding to a remote access to subprogram,
2948 -- we use the same identifier as the RAS type, so that the proper
2949 -- name appears in the stub. This type is only retrieved through
2950 -- the RAS type and never by visibility, and is not added to the
2951 -- visibility list (see below).
2952
2953 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
2954 and then Present (Corresponding_Remote_Type (Def_Id))
2955 then
2956 null;
2957
2958 -- A controller component for a type extension overrides the
2959 -- inherited component.
2960
2961 elsif Chars (E) = Name_uController then
2962 null;
2963
2964 -- Case of an implicit operation or derived literal. The new entity
2965 -- hides the implicit one, which is removed from all visibility,
2966 -- i.e. the entity list of its scope, and homonym chain of its name.
2967
2968 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
2969 or else Is_Internal (E)
2970 then
2971 declare
2972 Prev : Entity_Id;
2973 Prev_Vis : Entity_Id;
2974 Decl : constant Node_Id := Parent (E);
2975
2976 begin
2977 -- If E is an implicit declaration, it cannot be the first
2978 -- entity in the scope.
2979
2980 Prev := First_Entity (Current_Scope);
2981 while Present (Prev)
2982 and then Next_Entity (Prev) /= E
2983 loop
2984 Next_Entity (Prev);
2985 end loop;
2986
2987 if No (Prev) then
2988
2989 -- If E is not on the entity chain of the current scope,
2990 -- it is an implicit declaration in the generic formal
2991 -- part of a generic subprogram. When analyzing the body,
2992 -- the generic formals are visible but not on the entity
2993 -- chain of the subprogram. The new entity will become
2994 -- the visible one in the body.
2995
2996 pragma Assert
2997 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
2998 null;
2999
3000 else
3001 Set_Next_Entity (Prev, Next_Entity (E));
3002
3003 if No (Next_Entity (Prev)) then
3004 Set_Last_Entity (Current_Scope, Prev);
3005 end if;
3006
3007 if E = Current_Entity (E) then
3008 Prev_Vis := Empty;
3009
3010 else
3011 Prev_Vis := Current_Entity (E);
3012 while Homonym (Prev_Vis) /= E loop
3013 Prev_Vis := Homonym (Prev_Vis);
3014 end loop;
3015 end if;
3016
3017 if Present (Prev_Vis) then
3018
3019 -- Skip E in the visibility chain
3020
3021 Set_Homonym (Prev_Vis, Homonym (E));
3022
3023 else
3024 Set_Name_Entity_Id (Chars (E), Homonym (E));
3025 end if;
3026 end if;
3027 end;
3028
3029 -- This section of code could use a comment ???
3030
3031 elsif Present (Etype (E))
3032 and then Is_Concurrent_Type (Etype (E))
3033 and then E = Def_Id
3034 then
3035 return;
3036
3037 -- If the homograph is a protected component renaming, it should not
3038 -- be hiding the current entity. Such renamings are treated as weak
3039 -- declarations.
3040
3041 elsif Is_Prival (E) then
3042 Set_Is_Immediately_Visible (E, False);
3043
3044 -- In this case the current entity is a protected component renaming.
3045 -- Perform minimal decoration by setting the scope and return since
3046 -- the prival should not be hiding other visible entities.
3047
3048 elsif Is_Prival (Def_Id) then
3049 Set_Scope (Def_Id, Current_Scope);
3050 return;
3051
3052 -- Analogous to privals, the discriminal generated for an entry index
3053 -- parameter acts as a weak declaration. Perform minimal decoration
3054 -- to avoid bogus errors.
3055
3056 elsif Is_Discriminal (Def_Id)
3057 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
3058 then
3059 Set_Scope (Def_Id, Current_Scope);
3060 return;
3061
3062 -- In the body or private part of an instance, a type extension may
3063 -- introduce a component with the same name as that of an actual. The
3064 -- legality rule is not enforced, but the semantics of the full type
3065 -- with two components of same name are not clear at this point???
3066
3067 elsif In_Instance_Not_Visible then
3068 null;
3069
3070 -- When compiling a package body, some child units may have become
3071 -- visible. They cannot conflict with local entities that hide them.
3072
3073 elsif Is_Child_Unit (E)
3074 and then In_Open_Scopes (Scope (E))
3075 and then not Is_Immediately_Visible (E)
3076 then
3077 null;
3078
3079 -- Conversely, with front-end inlining we may compile the parent body
3080 -- first, and a child unit subsequently. The context is now the
3081 -- parent spec, and body entities are not visible.
3082
3083 elsif Is_Child_Unit (Def_Id)
3084 and then Is_Package_Body_Entity (E)
3085 and then not In_Package_Body (Current_Scope)
3086 then
3087 null;
3088
3089 -- Case of genuine duplicate declaration
3090
3091 else
3092 Error_Msg_Sloc := Sloc (E);
3093
3094 -- If the previous declaration is an incomplete type declaration
3095 -- this may be an attempt to complete it with a private type. The
3096 -- following avoids confusing cascaded errors.
3097
3098 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
3099 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
3100 then
3101 Error_Msg_N
3102 ("incomplete type cannot be completed with a private " &
3103 "declaration", Parent (Def_Id));
3104 Set_Is_Immediately_Visible (E, False);
3105 Set_Full_View (E, Def_Id);
3106
3107 -- An inherited component of a record conflicts with a new
3108 -- discriminant. The discriminant is inserted first in the scope,
3109 -- but the error should be posted on it, not on the component.
3110
3111 elsif Ekind (E) = E_Discriminant
3112 and then Present (Scope (Def_Id))
3113 and then Scope (Def_Id) /= Current_Scope
3114 then
3115 Error_Msg_Sloc := Sloc (Def_Id);
3116 Error_Msg_N ("& conflicts with declaration#", E);
3117 return;
3118
3119 -- If the name of the unit appears in its own context clause, a
3120 -- dummy package with the name has already been created, and the
3121 -- error emitted. Try to continue quietly.
3122
3123 elsif Error_Posted (E)
3124 and then Sloc (E) = No_Location
3125 and then Nkind (Parent (E)) = N_Package_Specification
3126 and then Current_Scope = Standard_Standard
3127 then
3128 Set_Scope (Def_Id, Current_Scope);
3129 return;
3130
3131 else
3132 Error_Msg_N ("& conflicts with declaration#", Def_Id);
3133
3134 -- Avoid cascaded messages with duplicate components in
3135 -- derived types.
3136
3137 if Ekind_In (E, E_Component, E_Discriminant) then
3138 return;
3139 end if;
3140 end if;
3141
3142 if Nkind (Parent (Parent (Def_Id))) =
3143 N_Generic_Subprogram_Declaration
3144 and then Def_Id =
3145 Defining_Entity (Specification (Parent (Parent (Def_Id))))
3146 then
3147 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
3148 end if;
3149
3150 -- If entity is in standard, then we are in trouble, because it
3151 -- means that we have a library package with a duplicated name.
3152 -- That's hard to recover from, so abort!
3153
3154 if S = Standard_Standard then
3155 raise Unrecoverable_Error;
3156
3157 -- Otherwise we continue with the declaration. Having two
3158 -- identical declarations should not cause us too much trouble!
3159
3160 else
3161 null;
3162 end if;
3163 end if;
3164 end if;
3165
3166 -- If we fall through, declaration is OK, at least OK enough to continue
3167
3168 -- If Def_Id is a discriminant or a record component we are in the midst
3169 -- of inheriting components in a derived record definition. Preserve
3170 -- their Ekind and Etype.
3171
3172 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
3173 null;
3174
3175 -- If a type is already set, leave it alone (happens when a type
3176 -- declaration is reanalyzed following a call to the optimizer).
3177
3178 elsif Present (Etype (Def_Id)) then
3179 null;
3180
3181 -- Otherwise, the kind E_Void insures that premature uses of the entity
3182 -- will be detected. Any_Type insures that no cascaded errors will occur
3183
3184 else
3185 Set_Ekind (Def_Id, E_Void);
3186 Set_Etype (Def_Id, Any_Type);
3187 end if;
3188
3189 -- Inherited discriminants and components in derived record types are
3190 -- immediately visible. Itypes are not.
3191
3192 if Ekind_In (Def_Id, E_Discriminant, E_Component)
3193 or else (No (Corresponding_Remote_Type (Def_Id))
3194 and then not Is_Itype (Def_Id))
3195 then
3196 Set_Is_Immediately_Visible (Def_Id);
3197 Set_Current_Entity (Def_Id);
3198 end if;
3199
3200 Set_Homonym (Def_Id, C);
3201 Append_Entity (Def_Id, S);
3202 Set_Public_Status (Def_Id);
3203
3204 -- Declaring a homonym is not allowed in SPARK or ALFA ...
3205
3206 if Present (C)
3207
3208 -- ... unless the new declaration is in a subprogram, and the visible
3209 -- declaration is a variable declaration or a parameter specification
3210 -- outside that subprogram.
3211
3212 and then not
3213 (Nkind_In (Parent (Parent (Def_Id)), N_Subprogram_Body,
3214 N_Function_Specification,
3215 N_Procedure_Specification)
3216 and then
3217 Nkind_In (Parent (C), N_Object_Declaration,
3218 N_Parameter_Specification))
3219
3220 -- ... or the new declaration is in a package, and the visible
3221 -- declaration occurs outside that package.
3222
3223 and then not
3224 Nkind_In (Parent (Parent (Def_Id)), N_Package_Specification,
3225 N_Package_Body)
3226
3227 -- ... or the new declaration is a component declaration in a record
3228 -- type definition.
3229
3230 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
3231
3232 -- Don't issue error for non-source entities
3233
3234 and then Comes_From_Source (Def_Id)
3235 and then Comes_From_Source (C)
3236 then
3237 Error_Msg_Sloc := Sloc (C);
3238 Check_Formal_Restriction ("redeclaration of identifier &#", Def_Id);
3239 end if;
3240
3241 -- Warn if new entity hides an old one
3242
3243 if Warn_On_Hiding and then Present (C)
3244
3245 -- Don't warn for record components since they always have a well
3246 -- defined scope which does not confuse other uses. Note that in
3247 -- some cases, Ekind has not been set yet.
3248
3249 and then Ekind (C) /= E_Component
3250 and then Ekind (C) /= E_Discriminant
3251 and then Nkind (Parent (C)) /= N_Component_Declaration
3252 and then Ekind (Def_Id) /= E_Component
3253 and then Ekind (Def_Id) /= E_Discriminant
3254 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
3255
3256 -- Don't warn for one character variables. It is too common to use
3257 -- such variables as locals and will just cause too many false hits.
3258
3259 and then Length_Of_Name (Chars (C)) /= 1
3260
3261 -- Don't warn for non-source entities
3262
3263 and then Comes_From_Source (C)
3264 and then Comes_From_Source (Def_Id)
3265
3266 -- Don't warn unless entity in question is in extended main source
3267
3268 and then In_Extended_Main_Source_Unit (Def_Id)
3269
3270 -- Finally, the hidden entity must be either immediately visible or
3271 -- use visible (i.e. from a used package).
3272
3273 and then
3274 (Is_Immediately_Visible (C)
3275 or else
3276 Is_Potentially_Use_Visible (C))
3277 then
3278 Error_Msg_Sloc := Sloc (C);
3279 Error_Msg_N ("declaration hides &#?", Def_Id);
3280 end if;
3281 end Enter_Name;
3282
3283 --------------------------
3284 -- Explain_Limited_Type --
3285 --------------------------
3286
3287 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
3288 C : Entity_Id;
3289
3290 begin
3291 -- For array, component type must be limited
3292
3293 if Is_Array_Type (T) then
3294 Error_Msg_Node_2 := T;
3295 Error_Msg_NE
3296 ("\component type& of type& is limited", N, Component_Type (T));
3297 Explain_Limited_Type (Component_Type (T), N);
3298
3299 elsif Is_Record_Type (T) then
3300
3301 -- No need for extra messages if explicit limited record
3302
3303 if Is_Limited_Record (Base_Type (T)) then
3304 return;
3305 end if;
3306
3307 -- Otherwise find a limited component. Check only components that
3308 -- come from source, or inherited components that appear in the
3309 -- source of the ancestor.
3310
3311 C := First_Component (T);
3312 while Present (C) loop
3313 if Is_Limited_Type (Etype (C))
3314 and then
3315 (Comes_From_Source (C)
3316 or else
3317 (Present (Original_Record_Component (C))
3318 and then
3319 Comes_From_Source (Original_Record_Component (C))))
3320 then
3321 Error_Msg_Node_2 := T;
3322 Error_Msg_NE ("\component& of type& has limited type", N, C);
3323 Explain_Limited_Type (Etype (C), N);
3324 return;
3325 end if;
3326
3327 Next_Component (C);
3328 end loop;
3329
3330 -- The type may be declared explicitly limited, even if no component
3331 -- of it is limited, in which case we fall out of the loop.
3332 return;
3333 end if;
3334 end Explain_Limited_Type;
3335
3336 -----------------
3337 -- Find_Actual --
3338 -----------------
3339
3340 procedure Find_Actual
3341 (N : Node_Id;
3342 Formal : out Entity_Id;
3343 Call : out Node_Id)
3344 is
3345 Parnt : constant Node_Id := Parent (N);
3346 Actual : Node_Id;
3347
3348 begin
3349 if (Nkind (Parnt) = N_Indexed_Component
3350 or else
3351 Nkind (Parnt) = N_Selected_Component)
3352 and then N = Prefix (Parnt)
3353 then
3354 Find_Actual (Parnt, Formal, Call);
3355 return;
3356
3357 elsif Nkind (Parnt) = N_Parameter_Association
3358 and then N = Explicit_Actual_Parameter (Parnt)
3359 then
3360 Call := Parent (Parnt);
3361
3362 elsif Nkind_In (Parnt, N_Procedure_Call_Statement, N_Function_Call) then
3363 Call := Parnt;
3364
3365 else
3366 Formal := Empty;
3367 Call := Empty;
3368 return;
3369 end if;
3370
3371 -- If we have a call to a subprogram look for the parameter. Note that
3372 -- we exclude overloaded calls, since we don't know enough to be sure
3373 -- of giving the right answer in this case.
3374
3375 if Is_Entity_Name (Name (Call))
3376 and then Present (Entity (Name (Call)))
3377 and then Is_Overloadable (Entity (Name (Call)))
3378 and then not Is_Overloaded (Name (Call))
3379 then
3380 -- Fall here if we are definitely a parameter
3381
3382 Actual := First_Actual (Call);
3383 Formal := First_Formal (Entity (Name (Call)));
3384 while Present (Formal) and then Present (Actual) loop
3385 if Actual = N then
3386 return;
3387 else
3388 Actual := Next_Actual (Actual);
3389 Formal := Next_Formal (Formal);
3390 end if;
3391 end loop;
3392 end if;
3393
3394 -- Fall through here if we did not find matching actual
3395
3396 Formal := Empty;
3397 Call := Empty;
3398 end Find_Actual;
3399
3400 ---------------------------
3401 -- Find_Body_Discriminal --
3402 ---------------------------
3403
3404 function Find_Body_Discriminal
3405 (Spec_Discriminant : Entity_Id) return Entity_Id
3406 is
3407 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
3408
3409 Tsk : constant Entity_Id :=
3410 Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
3411 Disc : Entity_Id;
3412
3413 begin
3414 -- Find discriminant of original concurrent type, and use its current
3415 -- discriminal, which is the renaming within the task/protected body.
3416
3417 Disc := First_Discriminant (Tsk);
3418 while Present (Disc) loop
3419 if Chars (Disc) = Chars (Spec_Discriminant) then
3420 return Discriminal (Disc);
3421 end if;
3422
3423 Next_Discriminant (Disc);
3424 end loop;
3425
3426 -- That loop should always succeed in finding a matching entry and
3427 -- returning. Fatal error if not.
3428
3429 raise Program_Error;
3430 end Find_Body_Discriminal;
3431
3432 -------------------------------------
3433 -- Find_Corresponding_Discriminant --
3434 -------------------------------------
3435
3436 function Find_Corresponding_Discriminant
3437 (Id : Node_Id;
3438 Typ : Entity_Id) return Entity_Id
3439 is
3440 Par_Disc : Entity_Id;
3441 Old_Disc : Entity_Id;
3442 New_Disc : Entity_Id;
3443
3444 begin
3445 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
3446
3447 -- The original type may currently be private, and the discriminant
3448 -- only appear on its full view.
3449
3450 if Is_Private_Type (Scope (Par_Disc))
3451 and then not Has_Discriminants (Scope (Par_Disc))
3452 and then Present (Full_View (Scope (Par_Disc)))
3453 then
3454 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
3455 else
3456 Old_Disc := First_Discriminant (Scope (Par_Disc));
3457 end if;
3458
3459 if Is_Class_Wide_Type (Typ) then
3460 New_Disc := First_Discriminant (Root_Type (Typ));
3461 else
3462 New_Disc := First_Discriminant (Typ);
3463 end if;
3464
3465 while Present (Old_Disc) and then Present (New_Disc) loop
3466 if Old_Disc = Par_Disc then
3467 return New_Disc;
3468 else
3469 Next_Discriminant (Old_Disc);
3470 Next_Discriminant (New_Disc);
3471 end if;
3472 end loop;
3473
3474 -- Should always find it
3475
3476 raise Program_Error;
3477 end Find_Corresponding_Discriminant;
3478
3479 --------------------------
3480 -- Find_Overlaid_Entity --
3481 --------------------------
3482
3483 procedure Find_Overlaid_Entity
3484 (N : Node_Id;
3485 Ent : out Entity_Id;
3486 Off : out Boolean)
3487 is
3488 Expr : Node_Id;
3489
3490 begin
3491 -- We are looking for one of the two following forms:
3492
3493 -- for X'Address use Y'Address
3494
3495 -- or
3496
3497 -- Const : constant Address := expr;
3498 -- ...
3499 -- for X'Address use Const;
3500
3501 -- In the second case, the expr is either Y'Address, or recursively a
3502 -- constant that eventually references Y'Address.
3503
3504 Ent := Empty;
3505 Off := False;
3506
3507 if Nkind (N) = N_Attribute_Definition_Clause
3508 and then Chars (N) = Name_Address
3509 then
3510 Expr := Expression (N);
3511
3512 -- This loop checks the form of the expression for Y'Address,
3513 -- using recursion to deal with intermediate constants.
3514
3515 loop
3516 -- Check for Y'Address
3517
3518 if Nkind (Expr) = N_Attribute_Reference
3519 and then Attribute_Name (Expr) = Name_Address
3520 then
3521 Expr := Prefix (Expr);
3522 exit;
3523
3524 -- Check for Const where Const is a constant entity
3525
3526 elsif Is_Entity_Name (Expr)
3527 and then Ekind (Entity (Expr)) = E_Constant
3528 then
3529 Expr := Constant_Value (Entity (Expr));
3530
3531 -- Anything else does not need checking
3532
3533 else
3534 return;
3535 end if;
3536 end loop;
3537
3538 -- This loop checks the form of the prefix for an entity,
3539 -- using recursion to deal with intermediate components.
3540
3541 loop
3542 -- Check for Y where Y is an entity
3543
3544 if Is_Entity_Name (Expr) then
3545 Ent := Entity (Expr);
3546 return;
3547
3548 -- Check for components
3549
3550 elsif
3551 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component) then
3552
3553 Expr := Prefix (Expr);
3554 Off := True;
3555
3556 -- Anything else does not need checking
3557
3558 else
3559 return;
3560 end if;
3561 end loop;
3562 end if;
3563 end Find_Overlaid_Entity;
3564
3565 -------------------------
3566 -- Find_Parameter_Type --
3567 -------------------------
3568
3569 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
3570 begin
3571 if Nkind (Param) /= N_Parameter_Specification then
3572 return Empty;
3573
3574 -- For an access parameter, obtain the type from the formal entity
3575 -- itself, because access to subprogram nodes do not carry a type.
3576 -- Shouldn't we always use the formal entity ???
3577
3578 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
3579 return Etype (Defining_Identifier (Param));
3580
3581 else
3582 return Etype (Parameter_Type (Param));
3583 end if;
3584 end Find_Parameter_Type;
3585
3586 -----------------------------
3587 -- Find_Static_Alternative --
3588 -----------------------------
3589
3590 function Find_Static_Alternative (N : Node_Id) return Node_Id is
3591 Expr : constant Node_Id := Expression (N);
3592 Val : constant Uint := Expr_Value (Expr);
3593 Alt : Node_Id;
3594 Choice : Node_Id;
3595
3596 begin
3597 Alt := First (Alternatives (N));
3598
3599 Search : loop
3600 if Nkind (Alt) /= N_Pragma then
3601 Choice := First (Discrete_Choices (Alt));
3602 while Present (Choice) loop
3603
3604 -- Others choice, always matches
3605
3606 if Nkind (Choice) = N_Others_Choice then
3607 exit Search;
3608
3609 -- Range, check if value is in the range
3610
3611 elsif Nkind (Choice) = N_Range then
3612 exit Search when
3613 Val >= Expr_Value (Low_Bound (Choice))
3614 and then
3615 Val <= Expr_Value (High_Bound (Choice));
3616
3617 -- Choice is a subtype name. Note that we know it must
3618 -- be a static subtype, since otherwise it would have
3619 -- been diagnosed as illegal.
3620
3621 elsif Is_Entity_Name (Choice)
3622 and then Is_Type (Entity (Choice))
3623 then
3624 exit Search when Is_In_Range (Expr, Etype (Choice),
3625 Assume_Valid => False);
3626
3627 -- Choice is a subtype indication
3628
3629 elsif Nkind (Choice) = N_Subtype_Indication then
3630 declare
3631 C : constant Node_Id := Constraint (Choice);
3632 R : constant Node_Id := Range_Expression (C);
3633
3634 begin
3635 exit Search when
3636 Val >= Expr_Value (Low_Bound (R))
3637 and then
3638 Val <= Expr_Value (High_Bound (R));
3639 end;
3640
3641 -- Choice is a simple expression
3642
3643 else
3644 exit Search when Val = Expr_Value (Choice);
3645 end if;
3646
3647 Next (Choice);
3648 end loop;
3649 end if;
3650
3651 Next (Alt);
3652 pragma Assert (Present (Alt));
3653 end loop Search;
3654
3655 -- The above loop *must* terminate by finding a match, since
3656 -- we know the case statement is valid, and the value of the
3657 -- expression is known at compile time. When we fall out of
3658 -- the loop, Alt points to the alternative that we know will
3659 -- be selected at run time.
3660
3661 return Alt;
3662 end Find_Static_Alternative;
3663
3664 ------------------
3665 -- First_Actual --
3666 ------------------
3667
3668 function First_Actual (Node : Node_Id) return Node_Id is
3669 N : Node_Id;
3670
3671 begin
3672 if No (Parameter_Associations (Node)) then
3673 return Empty;
3674 end if;
3675
3676 N := First (Parameter_Associations (Node));
3677
3678 if Nkind (N) = N_Parameter_Association then
3679 return First_Named_Actual (Node);
3680 else
3681 return N;
3682 end if;
3683 end First_Actual;
3684
3685 -----------------------
3686 -- Gather_Components --
3687 -----------------------
3688
3689 procedure Gather_Components
3690 (Typ : Entity_Id;
3691 Comp_List : Node_Id;
3692 Governed_By : List_Id;
3693 Into : Elist_Id;
3694 Report_Errors : out Boolean)
3695 is
3696 Assoc : Node_Id;
3697 Variant : Node_Id;
3698 Discrete_Choice : Node_Id;
3699 Comp_Item : Node_Id;
3700
3701 Discrim : Entity_Id;
3702 Discrim_Name : Node_Id;
3703 Discrim_Value : Node_Id;
3704
3705 begin
3706 Report_Errors := False;
3707
3708 if No (Comp_List) or else Null_Present (Comp_List) then
3709 return;
3710
3711 elsif Present (Component_Items (Comp_List)) then
3712 Comp_Item := First (Component_Items (Comp_List));
3713
3714 else
3715 Comp_Item := Empty;
3716 end if;
3717
3718 while Present (Comp_Item) loop
3719
3720 -- Skip the tag of a tagged record, the interface tags, as well
3721 -- as all items that are not user components (anonymous types,
3722 -- rep clauses, Parent field, controller field).
3723
3724 if Nkind (Comp_Item) = N_Component_Declaration then
3725 declare
3726 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
3727 begin
3728 if not Is_Tag (Comp)
3729 and then Chars (Comp) /= Name_uParent
3730 and then Chars (Comp) /= Name_uController
3731 then
3732 Append_Elmt (Comp, Into);
3733 end if;
3734 end;
3735 end if;
3736
3737 Next (Comp_Item);
3738 end loop;
3739
3740 if No (Variant_Part (Comp_List)) then
3741 return;
3742 else
3743 Discrim_Name := Name (Variant_Part (Comp_List));
3744 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
3745 end if;
3746
3747 -- Look for the discriminant that governs this variant part.
3748 -- The discriminant *must* be in the Governed_By List
3749
3750 Assoc := First (Governed_By);
3751 Find_Constraint : loop
3752 Discrim := First (Choices (Assoc));
3753 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
3754 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
3755 and then
3756 Chars (Corresponding_Discriminant (Entity (Discrim)))
3757 = Chars (Discrim_Name))
3758 or else Chars (Original_Record_Component (Entity (Discrim)))
3759 = Chars (Discrim_Name);
3760
3761 if No (Next (Assoc)) then
3762 if not Is_Constrained (Typ)
3763 and then Is_Derived_Type (Typ)
3764 and then Present (Stored_Constraint (Typ))
3765 then
3766 -- If the type is a tagged type with inherited discriminants,
3767 -- use the stored constraint on the parent in order to find
3768 -- the values of discriminants that are otherwise hidden by an
3769 -- explicit constraint. Renamed discriminants are handled in
3770 -- the code above.
3771
3772 -- If several parent discriminants are renamed by a single
3773 -- discriminant of the derived type, the call to obtain the
3774 -- Corresponding_Discriminant field only retrieves the last
3775 -- of them. We recover the constraint on the others from the
3776 -- Stored_Constraint as well.
3777
3778 declare
3779 D : Entity_Id;
3780 C : Elmt_Id;
3781
3782 begin
3783 D := First_Discriminant (Etype (Typ));
3784 C := First_Elmt (Stored_Constraint (Typ));
3785 while Present (D) and then Present (C) loop
3786 if Chars (Discrim_Name) = Chars (D) then
3787 if Is_Entity_Name (Node (C))
3788 and then Entity (Node (C)) = Entity (Discrim)
3789 then
3790 -- D is renamed by Discrim, whose value is given in
3791 -- Assoc.
3792
3793 null;
3794
3795 else
3796 Assoc :=
3797 Make_Component_Association (Sloc (Typ),
3798 New_List
3799 (New_Occurrence_Of (D, Sloc (Typ))),
3800 Duplicate_Subexpr_No_Checks (Node (C)));
3801 end if;
3802 exit Find_Constraint;
3803 end if;
3804
3805 Next_Discriminant (D);
3806 Next_Elmt (C);
3807 end loop;
3808 end;
3809 end if;
3810 end if;
3811
3812 if No (Next (Assoc)) then
3813 Error_Msg_NE (" missing value for discriminant&",
3814 First (Governed_By), Discrim_Name);
3815 Report_Errors := True;
3816 return;
3817 end if;
3818
3819 Next (Assoc);
3820 end loop Find_Constraint;
3821
3822 Discrim_Value := Expression (Assoc);
3823
3824 if not Is_OK_Static_Expression (Discrim_Value) then
3825 Error_Msg_FE
3826 ("value for discriminant & must be static!",
3827 Discrim_Value, Discrim);
3828 Why_Not_Static (Discrim_Value);
3829 Report_Errors := True;
3830 return;
3831 end if;
3832
3833 Search_For_Discriminant_Value : declare
3834 Low : Node_Id;
3835 High : Node_Id;
3836
3837 UI_High : Uint;
3838 UI_Low : Uint;
3839 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
3840
3841 begin
3842 Find_Discrete_Value : while Present (Variant) loop
3843 Discrete_Choice := First (Discrete_Choices (Variant));
3844 while Present (Discrete_Choice) loop
3845
3846 exit Find_Discrete_Value when
3847 Nkind (Discrete_Choice) = N_Others_Choice;
3848
3849 Get_Index_Bounds (Discrete_Choice, Low, High);
3850
3851 UI_Low := Expr_Value (Low);
3852 UI_High := Expr_Value (High);
3853
3854 exit Find_Discrete_Value when
3855 UI_Low <= UI_Discrim_Value
3856 and then
3857 UI_High >= UI_Discrim_Value;
3858
3859 Next (Discrete_Choice);
3860 end loop;
3861
3862 Next_Non_Pragma (Variant);
3863 end loop Find_Discrete_Value;
3864 end Search_For_Discriminant_Value;
3865
3866 if No (Variant) then
3867 Error_Msg_NE
3868 ("value of discriminant & is out of range", Discrim_Value, Discrim);
3869 Report_Errors := True;
3870 return;
3871 end if;
3872
3873 -- If we have found the corresponding choice, recursively add its
3874 -- components to the Into list.
3875
3876 Gather_Components (Empty,
3877 Component_List (Variant), Governed_By, Into, Report_Errors);
3878 end Gather_Components;
3879
3880 ------------------------
3881 -- Get_Actual_Subtype --
3882 ------------------------
3883
3884 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
3885 Typ : constant Entity_Id := Etype (N);
3886 Utyp : Entity_Id := Underlying_Type (Typ);
3887 Decl : Node_Id;
3888 Atyp : Entity_Id;
3889
3890 begin
3891 if No (Utyp) then
3892 Utyp := Typ;
3893 end if;
3894
3895 -- If what we have is an identifier that references a subprogram
3896 -- formal, or a variable or constant object, then we get the actual
3897 -- subtype from the referenced entity if one has been built.
3898
3899 if Nkind (N) = N_Identifier
3900 and then
3901 (Is_Formal (Entity (N))
3902 or else Ekind (Entity (N)) = E_Constant
3903 or else Ekind (Entity (N)) = E_Variable)
3904 and then Present (Actual_Subtype (Entity (N)))
3905 then
3906 return Actual_Subtype (Entity (N));
3907
3908 -- Actual subtype of unchecked union is always itself. We never need
3909 -- the "real" actual subtype. If we did, we couldn't get it anyway
3910 -- because the discriminant is not available. The restrictions on
3911 -- Unchecked_Union are designed to make sure that this is OK.
3912
3913 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
3914 return Typ;
3915
3916 -- Here for the unconstrained case, we must find actual subtype
3917 -- No actual subtype is available, so we must build it on the fly.
3918
3919 -- Checking the type, not the underlying type, for constrainedness
3920 -- seems to be necessary. Maybe all the tests should be on the type???
3921
3922 elsif (not Is_Constrained (Typ))
3923 and then (Is_Array_Type (Utyp)
3924 or else (Is_Record_Type (Utyp)
3925 and then Has_Discriminants (Utyp)))
3926 and then not Has_Unknown_Discriminants (Utyp)
3927 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
3928 then
3929 -- Nothing to do if in spec expression (why not???)
3930
3931 if In_Spec_Expression then
3932 return Typ;
3933
3934 elsif Is_Private_Type (Typ)
3935 and then not Has_Discriminants (Typ)
3936 then
3937 -- If the type has no discriminants, there is no subtype to
3938 -- build, even if the underlying type is discriminated.
3939
3940 return Typ;
3941
3942 -- Else build the actual subtype
3943
3944 else
3945 Decl := Build_Actual_Subtype (Typ, N);
3946 Atyp := Defining_Identifier (Decl);
3947
3948 -- If Build_Actual_Subtype generated a new declaration then use it
3949
3950 if Atyp /= Typ then
3951
3952 -- The actual subtype is an Itype, so analyze the declaration,
3953 -- but do not attach it to the tree, to get the type defined.
3954
3955 Set_Parent (Decl, N);
3956 Set_Is_Itype (Atyp);
3957 Analyze (Decl, Suppress => All_Checks);
3958 Set_Associated_Node_For_Itype (Atyp, N);
3959 Set_Has_Delayed_Freeze (Atyp, False);
3960
3961 -- We need to freeze the actual subtype immediately. This is
3962 -- needed, because otherwise this Itype will not get frozen
3963 -- at all, and it is always safe to freeze on creation because
3964 -- any associated types must be frozen at this point.
3965
3966 Freeze_Itype (Atyp, N);
3967 return Atyp;
3968
3969 -- Otherwise we did not build a declaration, so return original
3970
3971 else
3972 return Typ;
3973 end if;
3974 end if;
3975
3976 -- For all remaining cases, the actual subtype is the same as
3977 -- the nominal type.
3978
3979 else
3980 return Typ;
3981 end if;
3982 end Get_Actual_Subtype;
3983
3984 -------------------------------------
3985 -- Get_Actual_Subtype_If_Available --
3986 -------------------------------------
3987
3988 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
3989 Typ : constant Entity_Id := Etype (N);
3990
3991 begin
3992 -- If what we have is an identifier that references a subprogram
3993 -- formal, or a variable or constant object, then we get the actual
3994 -- subtype from the referenced entity if one has been built.
3995
3996 if Nkind (N) = N_Identifier
3997 and then
3998 (Is_Formal (Entity (N))
3999 or else Ekind (Entity (N)) = E_Constant
4000 or else Ekind (Entity (N)) = E_Variable)
4001 and then Present (Actual_Subtype (Entity (N)))
4002 then
4003 return Actual_Subtype (Entity (N));
4004
4005 -- Otherwise the Etype of N is returned unchanged
4006
4007 else
4008 return Typ;
4009 end if;
4010 end Get_Actual_Subtype_If_Available;
4011
4012 -------------------------------
4013 -- Get_Default_External_Name --
4014 -------------------------------
4015
4016 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
4017 begin
4018 Get_Decoded_Name_String (Chars (E));
4019
4020 if Opt.External_Name_Imp_Casing = Uppercase then
4021 Set_Casing (All_Upper_Case);
4022 else
4023 Set_Casing (All_Lower_Case);
4024 end if;
4025
4026 return
4027 Make_String_Literal (Sloc (E),
4028 Strval => String_From_Name_Buffer);
4029 end Get_Default_External_Name;
4030
4031 ---------------------------
4032 -- Get_Enum_Lit_From_Pos --
4033 ---------------------------
4034
4035 function Get_Enum_Lit_From_Pos
4036 (T : Entity_Id;
4037 Pos : Uint;
4038 Loc : Source_Ptr) return Node_Id
4039 is
4040 Lit : Node_Id;
4041
4042 begin
4043 -- In the case where the literal is of type Character, Wide_Character
4044 -- or Wide_Wide_Character or of a type derived from them, there needs
4045 -- to be some special handling since there is no explicit chain of
4046 -- literals to search. Instead, an N_Character_Literal node is created
4047 -- with the appropriate Char_Code and Chars fields.
4048
4049 if Is_Standard_Character_Type (T) then
4050 Set_Character_Literal_Name (UI_To_CC (Pos));
4051 return
4052 Make_Character_Literal (Loc,
4053 Chars => Name_Find,
4054 Char_Literal_Value => Pos);
4055
4056 -- For all other cases, we have a complete table of literals, and
4057 -- we simply iterate through the chain of literal until the one
4058 -- with the desired position value is found.
4059 --
4060
4061 else
4062 Lit := First_Literal (Base_Type (T));
4063 for J in 1 .. UI_To_Int (Pos) loop
4064 Next_Literal (Lit);
4065 end loop;
4066
4067 return New_Occurrence_Of (Lit, Loc);
4068 end if;
4069 end Get_Enum_Lit_From_Pos;
4070
4071 ------------------------
4072 -- Get_Generic_Entity --
4073 ------------------------
4074
4075 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
4076 Ent : constant Entity_Id := Entity (Name (N));
4077 begin
4078 if Present (Renamed_Object (Ent)) then
4079 return Renamed_Object (Ent);
4080 else
4081 return Ent;
4082 end if;
4083 end Get_Generic_Entity;
4084
4085 ----------------------
4086 -- Get_Index_Bounds --
4087 ----------------------
4088
4089 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
4090 Kind : constant Node_Kind := Nkind (N);
4091 R : Node_Id;
4092
4093 begin
4094 if Kind = N_Range then
4095 L := Low_Bound (N);
4096 H := High_Bound (N);
4097
4098 elsif Kind = N_Subtype_Indication then
4099 R := Range_Expression (Constraint (N));
4100
4101 if R = Error then
4102 L := Error;
4103 H := Error;
4104 return;
4105
4106 else
4107 L := Low_Bound (Range_Expression (Constraint (N)));
4108 H := High_Bound (Range_Expression (Constraint (N)));
4109 end if;
4110
4111 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
4112 if Error_Posted (Scalar_Range (Entity (N))) then
4113 L := Error;
4114 H := Error;
4115
4116 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
4117 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
4118
4119 else
4120 L := Low_Bound (Scalar_Range (Entity (N)));
4121 H := High_Bound (Scalar_Range (Entity (N)));
4122 end if;
4123
4124 else
4125 -- N is an expression, indicating a range with one value
4126
4127 L := N;
4128 H := N;
4129 end if;
4130 end Get_Index_Bounds;
4131
4132 ----------------------------------
4133 -- Get_Library_Unit_Name_string --
4134 ----------------------------------
4135
4136 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
4137 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
4138
4139 begin
4140 Get_Unit_Name_String (Unit_Name_Id);
4141
4142 -- Remove seven last character (" (spec)" or " (body)")
4143
4144 Name_Len := Name_Len - 7;
4145 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
4146 end Get_Library_Unit_Name_String;
4147
4148 ------------------------
4149 -- Get_Name_Entity_Id --
4150 ------------------------
4151
4152 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
4153 begin
4154 return Entity_Id (Get_Name_Table_Info (Id));
4155 end Get_Name_Entity_Id;
4156
4157 -------------------
4158 -- Get_Pragma_Id --
4159 -------------------
4160
4161 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
4162 begin
4163 return Get_Pragma_Id (Pragma_Name (N));
4164 end Get_Pragma_Id;
4165
4166 ---------------------------
4167 -- Get_Referenced_Object --
4168 ---------------------------
4169
4170 function Get_Referenced_Object (N : Node_Id) return Node_Id is
4171 R : Node_Id;
4172
4173 begin
4174 R := N;
4175 while Is_Entity_Name (R)
4176 and then Present (Renamed_Object (Entity (R)))
4177 loop
4178 R := Renamed_Object (Entity (R));
4179 end loop;
4180
4181 return R;
4182 end Get_Referenced_Object;
4183
4184 ------------------------
4185 -- Get_Renamed_Entity --
4186 ------------------------
4187
4188 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
4189 R : Entity_Id;
4190
4191 begin
4192 R := E;
4193 while Present (Renamed_Entity (R)) loop
4194 R := Renamed_Entity (R);
4195 end loop;
4196
4197 return R;
4198 end Get_Renamed_Entity;
4199
4200 -------------------------
4201 -- Get_Subprogram_Body --
4202 -------------------------
4203
4204 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
4205 Decl : Node_Id;
4206
4207 begin
4208 Decl := Unit_Declaration_Node (E);
4209
4210 if Nkind (Decl) = N_Subprogram_Body then
4211 return Decl;
4212
4213 -- The below comment is bad, because it is possible for
4214 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
4215
4216 else -- Nkind (Decl) = N_Subprogram_Declaration
4217
4218 if Present (Corresponding_Body (Decl)) then
4219 return Unit_Declaration_Node (Corresponding_Body (Decl));
4220
4221 -- Imported subprogram case
4222
4223 else
4224 return Empty;
4225 end if;
4226 end if;
4227 end Get_Subprogram_Body;
4228
4229 ---------------------------
4230 -- Get_Subprogram_Entity --
4231 ---------------------------
4232
4233 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
4234 Nam : Node_Id;
4235 Proc : Entity_Id;
4236
4237 begin
4238 if Nkind (Nod) = N_Accept_Statement then
4239 Nam := Entry_Direct_Name (Nod);
4240
4241 -- For an entry call, the prefix of the call is a selected component.
4242 -- Need additional code for internal calls ???
4243
4244 elsif Nkind (Nod) = N_Entry_Call_Statement then
4245 if Nkind (Name (Nod)) = N_Selected_Component then
4246 Nam := Entity (Selector_Name (Name (Nod)));
4247 else
4248 Nam := Empty;
4249 end if;
4250
4251 else
4252 Nam := Name (Nod);
4253 end if;
4254
4255 if Nkind (Nam) = N_Explicit_Dereference then
4256 Proc := Etype (Prefix (Nam));
4257 elsif Is_Entity_Name (Nam) then
4258 Proc := Entity (Nam);
4259 else
4260 return Empty;
4261 end if;
4262
4263 if Is_Object (Proc) then
4264 Proc := Etype (Proc);
4265 end if;
4266
4267 if Ekind (Proc) = E_Access_Subprogram_Type then
4268 Proc := Directly_Designated_Type (Proc);
4269 end if;
4270
4271 if not Is_Subprogram (Proc)
4272 and then Ekind (Proc) /= E_Subprogram_Type
4273 then
4274 return Empty;
4275 else
4276 return Proc;
4277 end if;
4278 end Get_Subprogram_Entity;
4279
4280 -----------------------------
4281 -- Get_Task_Body_Procedure --
4282 -----------------------------
4283
4284 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
4285 begin
4286 -- Note: A task type may be the completion of a private type with
4287 -- discriminants. When performing elaboration checks on a task
4288 -- declaration, the current view of the type may be the private one,
4289 -- and the procedure that holds the body of the task is held in its
4290 -- underlying type.
4291
4292 -- This is an odd function, why not have Task_Body_Procedure do
4293 -- the following digging???
4294
4295 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
4296 end Get_Task_Body_Procedure;
4297
4298 -----------------------
4299 -- Has_Access_Values --
4300 -----------------------
4301
4302 function Has_Access_Values (T : Entity_Id) return Boolean is
4303 Typ : constant Entity_Id := Underlying_Type (T);
4304
4305 begin
4306 -- Case of a private type which is not completed yet. This can only
4307 -- happen in the case of a generic format type appearing directly, or
4308 -- as a component of the type to which this function is being applied
4309 -- at the top level. Return False in this case, since we certainly do
4310 -- not know that the type contains access types.
4311
4312 if No (Typ) then
4313 return False;
4314
4315 elsif Is_Access_Type (Typ) then
4316 return True;
4317
4318 elsif Is_Array_Type (Typ) then
4319 return Has_Access_Values (Component_Type (Typ));
4320
4321 elsif Is_Record_Type (Typ) then
4322 declare
4323 Comp : Entity_Id;
4324
4325 begin
4326 -- Loop to Check components
4327
4328 Comp := First_Component_Or_Discriminant (Typ);
4329 while Present (Comp) loop
4330
4331 -- Check for access component, tag field does not count, even
4332 -- though it is implemented internally using an access type.
4333
4334 if Has_Access_Values (Etype (Comp))
4335 and then Chars (Comp) /= Name_uTag
4336 then
4337 return True;
4338 end if;
4339
4340 Next_Component_Or_Discriminant (Comp);
4341 end loop;
4342 end;
4343
4344 return False;
4345
4346 else
4347 return False;
4348 end if;
4349 end Has_Access_Values;
4350
4351 ------------------------------
4352 -- Has_Compatible_Alignment --
4353 ------------------------------
4354
4355 function Has_Compatible_Alignment
4356 (Obj : Entity_Id;
4357 Expr : Node_Id) return Alignment_Result
4358 is
4359 function Has_Compatible_Alignment_Internal
4360 (Obj : Entity_Id;
4361 Expr : Node_Id;
4362 Default : Alignment_Result) return Alignment_Result;
4363 -- This is the internal recursive function that actually does the work.
4364 -- There is one additional parameter, which says what the result should
4365 -- be if no alignment information is found, and there is no definite
4366 -- indication of compatible alignments. At the outer level, this is set
4367 -- to Unknown, but for internal recursive calls in the case where types
4368 -- are known to be correct, it is set to Known_Compatible.
4369
4370 ---------------------------------------
4371 -- Has_Compatible_Alignment_Internal --
4372 ---------------------------------------
4373
4374 function Has_Compatible_Alignment_Internal
4375 (Obj : Entity_Id;
4376 Expr : Node_Id;
4377 Default : Alignment_Result) return Alignment_Result
4378 is
4379 Result : Alignment_Result := Known_Compatible;
4380 -- Holds the current status of the result. Note that once a value of
4381 -- Known_Incompatible is set, it is sticky and does not get changed
4382 -- to Unknown (the value in Result only gets worse as we go along,
4383 -- never better).
4384
4385 Offs : Uint := No_Uint;
4386 -- Set to a factor of the offset from the base object when Expr is a
4387 -- selected or indexed component, based on Component_Bit_Offset and
4388 -- Component_Size respectively. A negative value is used to represent
4389 -- a value which is not known at compile time.
4390
4391 procedure Check_Prefix;
4392 -- Checks the prefix recursively in the case where the expression
4393 -- is an indexed or selected component.
4394
4395 procedure Set_Result (R : Alignment_Result);
4396 -- If R represents a worse outcome (unknown instead of known
4397 -- compatible, or known incompatible), then set Result to R.
4398
4399 ------------------
4400 -- Check_Prefix --
4401 ------------------
4402
4403 procedure Check_Prefix is
4404 begin
4405 -- The subtlety here is that in doing a recursive call to check
4406 -- the prefix, we have to decide what to do in the case where we
4407 -- don't find any specific indication of an alignment problem.
4408
4409 -- At the outer level, we normally set Unknown as the result in
4410 -- this case, since we can only set Known_Compatible if we really
4411 -- know that the alignment value is OK, but for the recursive
4412 -- call, in the case where the types match, and we have not
4413 -- specified a peculiar alignment for the object, we are only
4414 -- concerned about suspicious rep clauses, the default case does
4415 -- not affect us, since the compiler will, in the absence of such
4416 -- rep clauses, ensure that the alignment is correct.
4417
4418 if Default = Known_Compatible
4419 or else
4420 (Etype (Obj) = Etype (Expr)
4421 and then (Unknown_Alignment (Obj)
4422 or else
4423 Alignment (Obj) = Alignment (Etype (Obj))))
4424 then
4425 Set_Result
4426 (Has_Compatible_Alignment_Internal
4427 (Obj, Prefix (Expr), Known_Compatible));
4428
4429 -- In all other cases, we need a full check on the prefix
4430
4431 else
4432 Set_Result
4433 (Has_Compatible_Alignment_Internal
4434 (Obj, Prefix (Expr), Unknown));
4435 end if;
4436 end Check_Prefix;
4437
4438 ----------------
4439 -- Set_Result --
4440 ----------------
4441
4442 procedure Set_Result (R : Alignment_Result) is
4443 begin
4444 if R > Result then
4445 Result := R;
4446 end if;
4447 end Set_Result;
4448
4449 -- Start of processing for Has_Compatible_Alignment_Internal
4450
4451 begin
4452 -- If Expr is a selected component, we must make sure there is no
4453 -- potentially troublesome component clause, and that the record is
4454 -- not packed.
4455
4456 if Nkind (Expr) = N_Selected_Component then
4457
4458 -- Packed record always generate unknown alignment
4459
4460 if Is_Packed (Etype (Prefix (Expr))) then
4461 Set_Result (Unknown);
4462 end if;
4463
4464 -- Check prefix and component offset
4465
4466 Check_Prefix;
4467 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
4468
4469 -- If Expr is an indexed component, we must make sure there is no
4470 -- potentially troublesome Component_Size clause and that the array
4471 -- is not bit-packed.
4472
4473 elsif Nkind (Expr) = N_Indexed_Component then
4474 declare
4475 Typ : constant Entity_Id := Etype (Prefix (Expr));
4476 Ind : constant Node_Id := First_Index (Typ);
4477
4478 begin
4479 -- Bit packed array always generates unknown alignment
4480
4481 if Is_Bit_Packed_Array (Typ) then
4482 Set_Result (Unknown);
4483 end if;
4484
4485 -- Check prefix and component offset
4486
4487 Check_Prefix;
4488 Offs := Component_Size (Typ);
4489
4490 -- Small optimization: compute the full offset when possible
4491
4492 if Offs /= No_Uint
4493 and then Offs > Uint_0
4494 and then Present (Ind)
4495 and then Nkind (Ind) = N_Range
4496 and then Compile_Time_Known_Value (Low_Bound (Ind))
4497 and then Compile_Time_Known_Value (First (Expressions (Expr)))
4498 then
4499 Offs := Offs * (Expr_Value (First (Expressions (Expr)))
4500 - Expr_Value (Low_Bound ((Ind))));
4501 end if;
4502 end;
4503 end if;
4504
4505 -- If we have a null offset, the result is entirely determined by
4506 -- the base object and has already been computed recursively.
4507
4508 if Offs = Uint_0 then
4509 null;
4510
4511 -- Case where we know the alignment of the object
4512
4513 elsif Known_Alignment (Obj) then
4514 declare
4515 ObjA : constant Uint := Alignment (Obj);
4516 ExpA : Uint := No_Uint;
4517 SizA : Uint := No_Uint;
4518
4519 begin
4520 -- If alignment of Obj is 1, then we are always OK
4521
4522 if ObjA = 1 then
4523 Set_Result (Known_Compatible);
4524
4525 -- Alignment of Obj is greater than 1, so we need to check
4526
4527 else
4528 -- If we have an offset, see if it is compatible
4529
4530 if Offs /= No_Uint and Offs > Uint_0 then
4531 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
4532 Set_Result (Known_Incompatible);
4533 end if;
4534
4535 -- See if Expr is an object with known alignment
4536
4537 elsif Is_Entity_Name (Expr)
4538 and then Known_Alignment (Entity (Expr))
4539 then
4540 ExpA := Alignment (Entity (Expr));
4541
4542 -- Otherwise, we can use the alignment of the type of
4543 -- Expr given that we already checked for
4544 -- discombobulating rep clauses for the cases of indexed
4545 -- and selected components above.
4546
4547 elsif Known_Alignment (Etype (Expr)) then
4548 ExpA := Alignment (Etype (Expr));
4549
4550 -- Otherwise the alignment is unknown
4551
4552 else
4553 Set_Result (Default);
4554 end if;
4555
4556 -- If we got an alignment, see if it is acceptable
4557
4558 if ExpA /= No_Uint and then ExpA < ObjA then
4559 Set_Result (Known_Incompatible);
4560 end if;
4561
4562 -- If Expr is not a piece of a larger object, see if size
4563 -- is given. If so, check that it is not too small for the
4564 -- required alignment.
4565
4566 if Offs /= No_Uint then
4567 null;
4568
4569 -- See if Expr is an object with known size
4570
4571 elsif Is_Entity_Name (Expr)
4572 and then Known_Static_Esize (Entity (Expr))
4573 then
4574 SizA := Esize (Entity (Expr));
4575
4576 -- Otherwise, we check the object size of the Expr type
4577
4578 elsif Known_Static_Esize (Etype (Expr)) then
4579 SizA := Esize (Etype (Expr));
4580 end if;
4581
4582 -- If we got a size, see if it is a multiple of the Obj
4583 -- alignment, if not, then the alignment cannot be
4584 -- acceptable, since the size is always a multiple of the
4585 -- alignment.
4586
4587 if SizA /= No_Uint then
4588 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
4589 Set_Result (Known_Incompatible);
4590 end if;
4591 end if;
4592 end if;
4593 end;
4594
4595 -- If we do not know required alignment, any non-zero offset is a
4596 -- potential problem (but certainly may be OK, so result is unknown).
4597
4598 elsif Offs /= No_Uint then
4599 Set_Result (Unknown);
4600
4601 -- If we can't find the result by direct comparison of alignment
4602 -- values, then there is still one case that we can determine known
4603 -- result, and that is when we can determine that the types are the
4604 -- same, and no alignments are specified. Then we known that the
4605 -- alignments are compatible, even if we don't know the alignment
4606 -- value in the front end.
4607
4608 elsif Etype (Obj) = Etype (Expr) then
4609
4610 -- Types are the same, but we have to check for possible size
4611 -- and alignments on the Expr object that may make the alignment
4612 -- different, even though the types are the same.
4613
4614 if Is_Entity_Name (Expr) then
4615
4616 -- First check alignment of the Expr object. Any alignment less
4617 -- than Maximum_Alignment is worrisome since this is the case
4618 -- where we do not know the alignment of Obj.
4619
4620 if Known_Alignment (Entity (Expr))
4621 and then
4622 UI_To_Int (Alignment (Entity (Expr))) <
4623 Ttypes.Maximum_Alignment
4624 then
4625 Set_Result (Unknown);
4626
4627 -- Now check size of Expr object. Any size that is not an
4628 -- even multiple of Maximum_Alignment is also worrisome
4629 -- since it may cause the alignment of the object to be less
4630 -- than the alignment of the type.
4631
4632 elsif Known_Static_Esize (Entity (Expr))
4633 and then
4634 (UI_To_Int (Esize (Entity (Expr))) mod
4635 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
4636 /= 0
4637 then
4638 Set_Result (Unknown);
4639
4640 -- Otherwise same type is decisive
4641
4642 else
4643 Set_Result (Known_Compatible);
4644 end if;
4645 end if;
4646
4647 -- Another case to deal with is when there is an explicit size or
4648 -- alignment clause when the types are not the same. If so, then the
4649 -- result is Unknown. We don't need to do this test if the Default is
4650 -- Unknown, since that result will be set in any case.
4651
4652 elsif Default /= Unknown
4653 and then (Has_Size_Clause (Etype (Expr))
4654 or else
4655 Has_Alignment_Clause (Etype (Expr)))
4656 then
4657 Set_Result (Unknown);
4658
4659 -- If no indication found, set default
4660
4661 else
4662 Set_Result (Default);
4663 end if;
4664
4665 -- Return worst result found
4666
4667 return Result;
4668 end Has_Compatible_Alignment_Internal;
4669
4670 -- Start of processing for Has_Compatible_Alignment
4671
4672 begin
4673 -- If Obj has no specified alignment, then set alignment from the type
4674 -- alignment. Perhaps we should always do this, but for sure we should
4675 -- do it when there is an address clause since we can do more if the
4676 -- alignment is known.
4677
4678 if Unknown_Alignment (Obj) then
4679 Set_Alignment (Obj, Alignment (Etype (Obj)));
4680 end if;
4681
4682 -- Now do the internal call that does all the work
4683
4684 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
4685 end Has_Compatible_Alignment;
4686
4687 ----------------------
4688 -- Has_Declarations --
4689 ----------------------
4690
4691 function Has_Declarations (N : Node_Id) return Boolean is
4692 begin
4693 return Nkind_In (Nkind (N), N_Accept_Statement,
4694 N_Block_Statement,
4695 N_Compilation_Unit_Aux,
4696 N_Entry_Body,
4697 N_Package_Body,
4698 N_Protected_Body,
4699 N_Subprogram_Body,
4700 N_Task_Body,
4701 N_Package_Specification);
4702 end Has_Declarations;
4703
4704 -------------------------------------------
4705 -- Has_Discriminant_Dependent_Constraint --
4706 -------------------------------------------
4707
4708 function Has_Discriminant_Dependent_Constraint
4709 (Comp : Entity_Id) return Boolean
4710 is
4711 Comp_Decl : constant Node_Id := Parent (Comp);
4712 Subt_Indic : constant Node_Id :=
4713 Subtype_Indication (Component_Definition (Comp_Decl));
4714 Constr : Node_Id;
4715 Assn : Node_Id;
4716
4717 begin
4718 if Nkind (Subt_Indic) = N_Subtype_Indication then
4719 Constr := Constraint (Subt_Indic);
4720
4721 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
4722 Assn := First (Constraints (Constr));
4723 while Present (Assn) loop
4724 case Nkind (Assn) is
4725 when N_Subtype_Indication |
4726 N_Range |
4727 N_Identifier
4728 =>
4729 if Depends_On_Discriminant (Assn) then
4730 return True;
4731 end if;
4732
4733 when N_Discriminant_Association =>
4734 if Depends_On_Discriminant (Expression (Assn)) then
4735 return True;
4736 end if;
4737
4738 when others =>
4739 null;
4740
4741 end case;
4742
4743 Next (Assn);
4744 end loop;
4745 end if;
4746 end if;
4747
4748 return False;
4749 end Has_Discriminant_Dependent_Constraint;
4750
4751 --------------------
4752 -- Has_Infinities --
4753 --------------------
4754
4755 function Has_Infinities (E : Entity_Id) return Boolean is
4756 begin
4757 return
4758 Is_Floating_Point_Type (E)
4759 and then Nkind (Scalar_Range (E)) = N_Range
4760 and then Includes_Infinities (Scalar_Range (E));
4761 end Has_Infinities;
4762
4763 --------------------
4764 -- Has_Interfaces --
4765 --------------------
4766
4767 function Has_Interfaces
4768 (T : Entity_Id;
4769 Use_Full_View : Boolean := True) return Boolean
4770 is
4771 Typ : Entity_Id := Base_Type (T);
4772
4773 begin
4774 -- Handle concurrent types
4775
4776 if Is_Concurrent_Type (Typ) then
4777 Typ := Corresponding_Record_Type (Typ);
4778 end if;
4779
4780 if not Present (Typ)
4781 or else not Is_Record_Type (Typ)
4782 or else not Is_Tagged_Type (Typ)
4783 then
4784 return False;
4785 end if;
4786
4787 -- Handle private types
4788
4789 if Use_Full_View
4790 and then Present (Full_View (Typ))
4791 then
4792 Typ := Full_View (Typ);
4793 end if;
4794
4795 -- Handle concurrent record types
4796
4797 if Is_Concurrent_Record_Type (Typ)
4798 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
4799 then
4800 return True;
4801 end if;
4802
4803 loop
4804 if Is_Interface (Typ)
4805 or else
4806 (Is_Record_Type (Typ)
4807 and then Present (Interfaces (Typ))
4808 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
4809 then
4810 return True;
4811 end if;
4812
4813 exit when Etype (Typ) = Typ
4814
4815 -- Handle private types
4816
4817 or else (Present (Full_View (Etype (Typ)))
4818 and then Full_View (Etype (Typ)) = Typ)
4819
4820 -- Protect the frontend against wrong source with cyclic
4821 -- derivations
4822
4823 or else Etype (Typ) = T;
4824
4825 -- Climb to the ancestor type handling private types
4826
4827 if Present (Full_View (Etype (Typ))) then
4828 Typ := Full_View (Etype (Typ));
4829 else
4830 Typ := Etype (Typ);
4831 end if;
4832 end loop;
4833
4834 return False;
4835 end Has_Interfaces;
4836
4837 ------------------------
4838 -- Has_Null_Exclusion --
4839 ------------------------
4840
4841 function Has_Null_Exclusion (N : Node_Id) return Boolean is
4842 begin
4843 case Nkind (N) is
4844 when N_Access_Definition |
4845 N_Access_Function_Definition |
4846 N_Access_Procedure_Definition |
4847 N_Access_To_Object_Definition |
4848 N_Allocator |
4849 N_Derived_Type_Definition |
4850 N_Function_Specification |
4851 N_Subtype_Declaration =>
4852 return Null_Exclusion_Present (N);
4853
4854 when N_Component_Definition |
4855 N_Formal_Object_Declaration |
4856 N_Object_Renaming_Declaration =>
4857 if Present (Subtype_Mark (N)) then
4858 return Null_Exclusion_Present (N);
4859 else pragma Assert (Present (Access_Definition (N)));
4860 return Null_Exclusion_Present (Access_Definition (N));
4861 end if;
4862
4863 when N_Discriminant_Specification =>
4864 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
4865 return Null_Exclusion_Present (Discriminant_Type (N));
4866 else
4867 return Null_Exclusion_Present (N);
4868 end if;
4869
4870 when N_Object_Declaration =>
4871 if Nkind (Object_Definition (N)) = N_Access_Definition then
4872 return Null_Exclusion_Present (Object_Definition (N));
4873 else
4874 return Null_Exclusion_Present (N);
4875 end if;
4876
4877 when N_Parameter_Specification =>
4878 if Nkind (Parameter_Type (N)) = N_Access_Definition then
4879 return Null_Exclusion_Present (Parameter_Type (N));
4880 else
4881 return Null_Exclusion_Present (N);
4882 end if;
4883
4884 when others =>
4885 return False;
4886
4887 end case;
4888 end Has_Null_Exclusion;
4889
4890 ------------------------
4891 -- Has_Null_Extension --
4892 ------------------------
4893
4894 function Has_Null_Extension (T : Entity_Id) return Boolean is
4895 B : constant Entity_Id := Base_Type (T);
4896 Comps : Node_Id;
4897 Ext : Node_Id;
4898
4899 begin
4900 if Nkind (Parent (B)) = N_Full_Type_Declaration
4901 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
4902 then
4903 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
4904
4905 if Present (Ext) then
4906 if Null_Present (Ext) then
4907 return True;
4908 else
4909 Comps := Component_List (Ext);
4910
4911 -- The null component list is rewritten during analysis to
4912 -- include the parent component. Any other component indicates
4913 -- that the extension was not originally null.
4914
4915 return Null_Present (Comps)
4916 or else No (Next (First (Component_Items (Comps))));
4917 end if;
4918 else
4919 return False;
4920 end if;
4921
4922 else
4923 return False;
4924 end if;
4925 end Has_Null_Extension;
4926
4927 -------------------------------
4928 -- Has_Overriding_Initialize --
4929 -------------------------------
4930
4931 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
4932 BT : constant Entity_Id := Base_Type (T);
4933 P : Elmt_Id;
4934
4935 begin
4936 if Is_Controlled (BT) then
4937 if Is_RTU (Scope (BT), Ada_Finalization) then
4938 return False;
4939
4940 elsif Present (Primitive_Operations (BT)) then
4941 P := First_Elmt (Primitive_Operations (BT));
4942 while Present (P) loop
4943 declare
4944 Init : constant Entity_Id := Node (P);
4945 Formal : constant Entity_Id := First_Formal (Init);
4946 begin
4947 if Ekind (Init) = E_Procedure
4948 and then Chars (Init) = Name_Initialize
4949 and then Comes_From_Source (Init)
4950 and then Present (Formal)
4951 and then Etype (Formal) = BT
4952 and then No (Next_Formal (Formal))
4953 and then (Ada_Version < Ada_2012
4954 or else not Null_Present (Parent (Init)))
4955 then
4956 return True;
4957 end if;
4958 end;
4959
4960 Next_Elmt (P);
4961 end loop;
4962 end if;
4963
4964 -- Here if type itself does not have a non-null Initialize operation:
4965 -- check immediate ancestor.
4966
4967 if Is_Derived_Type (BT)
4968 and then Has_Overriding_Initialize (Etype (BT))
4969 then
4970 return True;
4971 end if;
4972 end if;
4973
4974 return False;
4975 end Has_Overriding_Initialize;
4976
4977 --------------------------------------
4978 -- Has_Preelaborable_Initialization --
4979 --------------------------------------
4980
4981 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
4982 Has_PE : Boolean;
4983
4984 procedure Check_Components (E : Entity_Id);
4985 -- Check component/discriminant chain, sets Has_PE False if a component
4986 -- or discriminant does not meet the preelaborable initialization rules.
4987
4988 ----------------------
4989 -- Check_Components --
4990 ----------------------
4991
4992 procedure Check_Components (E : Entity_Id) is
4993 Ent : Entity_Id;
4994 Exp : Node_Id;
4995
4996 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
4997 -- Returns True if and only if the expression denoted by N does not
4998 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
4999
5000 ---------------------------------
5001 -- Is_Preelaborable_Expression --
5002 ---------------------------------
5003
5004 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
5005 Exp : Node_Id;
5006 Assn : Node_Id;
5007 Choice : Node_Id;
5008 Comp_Type : Entity_Id;
5009 Is_Array_Aggr : Boolean;
5010
5011 begin
5012 if Is_Static_Expression (N) then
5013 return True;
5014
5015 elsif Nkind (N) = N_Null then
5016 return True;
5017
5018 -- Attributes are allowed in general, even if their prefix is a
5019 -- formal type. (It seems that certain attributes known not to be
5020 -- static might not be allowed, but there are no rules to prevent
5021 -- them.)
5022
5023 elsif Nkind (N) = N_Attribute_Reference then
5024 return True;
5025
5026 -- The name of a discriminant evaluated within its parent type is
5027 -- defined to be preelaborable (10.2.1(8)). Note that we test for
5028 -- names that denote discriminals as well as discriminants to
5029 -- catch references occurring within init procs.
5030
5031 elsif Is_Entity_Name (N)
5032 and then
5033 (Ekind (Entity (N)) = E_Discriminant
5034 or else
5035 ((Ekind (Entity (N)) = E_Constant
5036 or else Ekind (Entity (N)) = E_In_Parameter)
5037 and then Present (Discriminal_Link (Entity (N)))))
5038 then
5039 return True;
5040
5041 elsif Nkind (N) = N_Qualified_Expression then
5042 return Is_Preelaborable_Expression (Expression (N));
5043
5044 -- For aggregates we have to check that each of the associations
5045 -- is preelaborable.
5046
5047 elsif Nkind (N) = N_Aggregate
5048 or else Nkind (N) = N_Extension_Aggregate
5049 then
5050 Is_Array_Aggr := Is_Array_Type (Etype (N));
5051
5052 if Is_Array_Aggr then
5053 Comp_Type := Component_Type (Etype (N));
5054 end if;
5055
5056 -- Check the ancestor part of extension aggregates, which must
5057 -- be either the name of a type that has preelaborable init or
5058 -- an expression that is preelaborable.
5059
5060 if Nkind (N) = N_Extension_Aggregate then
5061 declare
5062 Anc_Part : constant Node_Id := Ancestor_Part (N);
5063
5064 begin
5065 if Is_Entity_Name (Anc_Part)
5066 and then Is_Type (Entity (Anc_Part))
5067 then
5068 if not Has_Preelaborable_Initialization
5069 (Entity (Anc_Part))
5070 then
5071 return False;
5072 end if;
5073
5074 elsif not Is_Preelaborable_Expression (Anc_Part) then
5075 return False;
5076 end if;
5077 end;
5078 end if;
5079
5080 -- Check positional associations
5081
5082 Exp := First (Expressions (N));
5083 while Present (Exp) loop
5084 if not Is_Preelaborable_Expression (Exp) then
5085 return False;
5086 end if;
5087
5088 Next (Exp);
5089 end loop;
5090
5091 -- Check named associations
5092
5093 Assn := First (Component_Associations (N));
5094 while Present (Assn) loop
5095 Choice := First (Choices (Assn));
5096 while Present (Choice) loop
5097 if Is_Array_Aggr then
5098 if Nkind (Choice) = N_Others_Choice then
5099 null;
5100
5101 elsif Nkind (Choice) = N_Range then
5102 if not Is_Static_Range (Choice) then
5103 return False;
5104 end if;
5105
5106 elsif not Is_Static_Expression (Choice) then
5107 return False;
5108 end if;
5109
5110 else
5111 Comp_Type := Etype (Choice);
5112 end if;
5113
5114 Next (Choice);
5115 end loop;
5116
5117 -- If the association has a <> at this point, then we have
5118 -- to check whether the component's type has preelaborable
5119 -- initialization. Note that this only occurs when the
5120 -- association's corresponding component does not have a
5121 -- default expression, the latter case having already been
5122 -- expanded as an expression for the association.
5123
5124 if Box_Present (Assn) then
5125 if not Has_Preelaborable_Initialization (Comp_Type) then
5126 return False;
5127 end if;
5128
5129 -- In the expression case we check whether the expression
5130 -- is preelaborable.
5131
5132 elsif
5133 not Is_Preelaborable_Expression (Expression (Assn))
5134 then
5135 return False;
5136 end if;
5137
5138 Next (Assn);
5139 end loop;
5140
5141 -- If we get here then aggregate as a whole is preelaborable
5142
5143 return True;
5144
5145 -- All other cases are not preelaborable
5146
5147 else
5148 return False;
5149 end if;
5150 end Is_Preelaborable_Expression;
5151
5152 -- Start of processing for Check_Components
5153
5154 begin
5155 -- Loop through entities of record or protected type
5156
5157 Ent := E;
5158 while Present (Ent) loop
5159
5160 -- We are interested only in components and discriminants
5161
5162 Exp := Empty;
5163
5164 case Ekind (Ent) is
5165 when E_Component =>
5166
5167 -- Get default expression if any. If there is no declaration
5168 -- node, it means we have an internal entity. The parent and
5169 -- tag fields are examples of such entities. For such cases,
5170 -- we just test the type of the entity.
5171
5172 if Present (Declaration_Node (Ent)) then
5173 Exp := Expression (Declaration_Node (Ent));
5174 end if;
5175
5176 when E_Discriminant =>
5177
5178 -- Note: for a renamed discriminant, the Declaration_Node
5179 -- may point to the one from the ancestor, and have a
5180 -- different expression, so use the proper attribute to
5181 -- retrieve the expression from the derived constraint.
5182
5183 Exp := Discriminant_Default_Value (Ent);
5184
5185 when others =>
5186 goto Check_Next_Entity;
5187 end case;
5188
5189 -- A component has PI if it has no default expression and the
5190 -- component type has PI.
5191
5192 if No (Exp) then
5193 if not Has_Preelaborable_Initialization (Etype (Ent)) then
5194 Has_PE := False;
5195 exit;
5196 end if;
5197
5198 -- Require the default expression to be preelaborable
5199
5200 elsif not Is_Preelaborable_Expression (Exp) then
5201 Has_PE := False;
5202 exit;
5203 end if;
5204
5205 <<Check_Next_Entity>>
5206 Next_Entity (Ent);
5207 end loop;
5208 end Check_Components;
5209
5210 -- Start of processing for Has_Preelaborable_Initialization
5211
5212 begin
5213 -- Immediate return if already marked as known preelaborable init. This
5214 -- covers types for which this function has already been called once
5215 -- and returned True (in which case the result is cached), and also
5216 -- types to which a pragma Preelaborable_Initialization applies.
5217
5218 if Known_To_Have_Preelab_Init (E) then
5219 return True;
5220 end if;
5221
5222 -- If the type is a subtype representing a generic actual type, then
5223 -- test whether its base type has preelaborable initialization since
5224 -- the subtype representing the actual does not inherit this attribute
5225 -- from the actual or formal. (but maybe it should???)
5226
5227 if Is_Generic_Actual_Type (E) then
5228 return Has_Preelaborable_Initialization (Base_Type (E));
5229 end if;
5230
5231 -- All elementary types have preelaborable initialization
5232
5233 if Is_Elementary_Type (E) then
5234 Has_PE := True;
5235
5236 -- Array types have PI if the component type has PI
5237
5238 elsif Is_Array_Type (E) then
5239 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
5240
5241 -- A derived type has preelaborable initialization if its parent type
5242 -- has preelaborable initialization and (in the case of a derived record
5243 -- extension) if the non-inherited components all have preelaborable
5244 -- initialization. However, a user-defined controlled type with an
5245 -- overriding Initialize procedure does not have preelaborable
5246 -- initialization.
5247
5248 elsif Is_Derived_Type (E) then
5249
5250 -- If the derived type is a private extension then it doesn't have
5251 -- preelaborable initialization.
5252
5253 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
5254 return False;
5255 end if;
5256
5257 -- First check whether ancestor type has preelaborable initialization
5258
5259 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
5260
5261 -- If OK, check extension components (if any)
5262
5263 if Has_PE and then Is_Record_Type (E) then
5264 Check_Components (First_Entity (E));
5265 end if;
5266
5267 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
5268 -- with a user defined Initialize procedure does not have PI.
5269
5270 if Has_PE
5271 and then Is_Controlled (E)
5272 and then Has_Overriding_Initialize (E)
5273 then
5274 Has_PE := False;
5275 end if;
5276
5277 -- Private types not derived from a type having preelaborable init and
5278 -- that are not marked with pragma Preelaborable_Initialization do not
5279 -- have preelaborable initialization.
5280
5281 elsif Is_Private_Type (E) then
5282 return False;
5283
5284 -- Record type has PI if it is non private and all components have PI
5285
5286 elsif Is_Record_Type (E) then
5287 Has_PE := True;
5288 Check_Components (First_Entity (E));
5289
5290 -- Protected types must not have entries, and components must meet
5291 -- same set of rules as for record components.
5292
5293 elsif Is_Protected_Type (E) then
5294 if Has_Entries (E) then
5295 Has_PE := False;
5296 else
5297 Has_PE := True;
5298 Check_Components (First_Entity (E));
5299 Check_Components (First_Private_Entity (E));
5300 end if;
5301
5302 -- Type System.Address always has preelaborable initialization
5303
5304 elsif Is_RTE (E, RE_Address) then
5305 Has_PE := True;
5306
5307 -- In all other cases, type does not have preelaborable initialization
5308
5309 else
5310 return False;
5311 end if;
5312
5313 -- If type has preelaborable initialization, cache result
5314
5315 if Has_PE then
5316 Set_Known_To_Have_Preelab_Init (E);
5317 end if;
5318
5319 return Has_PE;
5320 end Has_Preelaborable_Initialization;
5321
5322 ---------------------------
5323 -- Has_Private_Component --
5324 ---------------------------
5325
5326 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
5327 Btype : Entity_Id := Base_Type (Type_Id);
5328 Component : Entity_Id;
5329
5330 begin
5331 if Error_Posted (Type_Id)
5332 or else Error_Posted (Btype)
5333 then
5334 return False;
5335 end if;
5336
5337 if Is_Class_Wide_Type (Btype) then
5338 Btype := Root_Type (Btype);
5339 end if;
5340
5341 if Is_Private_Type (Btype) then
5342 declare
5343 UT : constant Entity_Id := Underlying_Type (Btype);
5344 begin
5345 if No (UT) then
5346 if No (Full_View (Btype)) then
5347 return not Is_Generic_Type (Btype)
5348 and then not Is_Generic_Type (Root_Type (Btype));
5349 else
5350 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
5351 end if;
5352 else
5353 return not Is_Frozen (UT) and then Has_Private_Component (UT);
5354 end if;
5355 end;
5356
5357 elsif Is_Array_Type (Btype) then
5358 return Has_Private_Component (Component_Type (Btype));
5359
5360 elsif Is_Record_Type (Btype) then
5361 Component := First_Component (Btype);
5362 while Present (Component) loop
5363 if Has_Private_Component (Etype (Component)) then
5364 return True;
5365 end if;
5366
5367 Next_Component (Component);
5368 end loop;
5369
5370 return False;
5371
5372 elsif Is_Protected_Type (Btype)
5373 and then Present (Corresponding_Record_Type (Btype))
5374 then
5375 return Has_Private_Component (Corresponding_Record_Type (Btype));
5376
5377 else
5378 return False;
5379 end if;
5380 end Has_Private_Component;
5381
5382 ----------------
5383 -- Has_Stream --
5384 ----------------
5385
5386 function Has_Stream (T : Entity_Id) return Boolean is
5387 E : Entity_Id;
5388
5389 begin
5390 if No (T) then
5391 return False;
5392
5393 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
5394 return True;
5395
5396 elsif Is_Array_Type (T) then
5397 return Has_Stream (Component_Type (T));
5398
5399 elsif Is_Record_Type (T) then
5400 E := First_Component (T);
5401 while Present (E) loop
5402 if Has_Stream (Etype (E)) then
5403 return True;
5404 else
5405 Next_Component (E);
5406 end if;
5407 end loop;
5408
5409 return False;
5410
5411 elsif Is_Private_Type (T) then
5412 return Has_Stream (Underlying_Type (T));
5413
5414 else
5415 return False;
5416 end if;
5417 end Has_Stream;
5418
5419 ----------------
5420 -- Has_Suffix --
5421 ----------------
5422
5423 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
5424 begin
5425 Get_Name_String (Chars (E));
5426 return Name_Buffer (Name_Len) = Suffix;
5427 end Has_Suffix;
5428
5429 --------------------------
5430 -- Has_Tagged_Component --
5431 --------------------------
5432
5433 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
5434 Comp : Entity_Id;
5435
5436 begin
5437 if Is_Private_Type (Typ)
5438 and then Present (Underlying_Type (Typ))
5439 then
5440 return Has_Tagged_Component (Underlying_Type (Typ));
5441
5442 elsif Is_Array_Type (Typ) then
5443 return Has_Tagged_Component (Component_Type (Typ));
5444
5445 elsif Is_Tagged_Type (Typ) then
5446 return True;
5447
5448 elsif Is_Record_Type (Typ) then
5449 Comp := First_Component (Typ);
5450 while Present (Comp) loop
5451 if Has_Tagged_Component (Etype (Comp)) then
5452 return True;
5453 end if;
5454
5455 Next_Component (Comp);
5456 end loop;
5457
5458 return False;
5459
5460 else
5461 return False;
5462 end if;
5463 end Has_Tagged_Component;
5464
5465 -------------------------
5466 -- Implementation_Kind --
5467 -------------------------
5468
5469 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
5470 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
5471 begin
5472 pragma Assert (Present (Impl_Prag));
5473 return
5474 Chars (Expression (Last (Pragma_Argument_Associations (Impl_Prag))));
5475 end Implementation_Kind;
5476
5477 --------------------------
5478 -- Implements_Interface --
5479 --------------------------
5480
5481 function Implements_Interface
5482 (Typ_Ent : Entity_Id;
5483 Iface_Ent : Entity_Id;
5484 Exclude_Parents : Boolean := False) return Boolean
5485 is
5486 Ifaces_List : Elist_Id;
5487 Elmt : Elmt_Id;
5488 Iface : Entity_Id := Base_Type (Iface_Ent);
5489 Typ : Entity_Id := Base_Type (Typ_Ent);
5490
5491 begin
5492 if Is_Class_Wide_Type (Typ) then
5493 Typ := Root_Type (Typ);
5494 end if;
5495
5496 if not Has_Interfaces (Typ) then
5497 return False;
5498 end if;
5499
5500 if Is_Class_Wide_Type (Iface) then
5501 Iface := Root_Type (Iface);
5502 end if;
5503
5504 Collect_Interfaces (Typ, Ifaces_List);
5505
5506 Elmt := First_Elmt (Ifaces_List);
5507 while Present (Elmt) loop
5508 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
5509 and then Exclude_Parents
5510 then
5511 null;
5512
5513 elsif Node (Elmt) = Iface then
5514 return True;
5515 end if;
5516
5517 Next_Elmt (Elmt);
5518 end loop;
5519
5520 return False;
5521 end Implements_Interface;
5522
5523 -----------------
5524 -- In_Instance --
5525 -----------------
5526
5527 function In_Instance return Boolean is
5528 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
5529 S : Entity_Id;
5530
5531 begin
5532 S := Current_Scope;
5533 while Present (S)
5534 and then S /= Standard_Standard
5535 loop
5536 if (Ekind (S) = E_Function
5537 or else Ekind (S) = E_Package
5538 or else Ekind (S) = E_Procedure)
5539 and then Is_Generic_Instance (S)
5540 then
5541 -- A child instance is always compiled in the context of a parent
5542 -- instance. Nevertheless, the actuals are not analyzed in an
5543 -- instance context. We detect this case by examining the current
5544 -- compilation unit, which must be a child instance, and checking
5545 -- that it is not currently on the scope stack.
5546
5547 if Is_Child_Unit (Curr_Unit)
5548 and then
5549 Nkind (Unit (Cunit (Current_Sem_Unit)))
5550 = N_Package_Instantiation
5551 and then not In_Open_Scopes (Curr_Unit)
5552 then
5553 return False;
5554 else
5555 return True;
5556 end if;
5557 end if;
5558
5559 S := Scope (S);
5560 end loop;
5561
5562 return False;
5563 end In_Instance;
5564
5565 ----------------------
5566 -- In_Instance_Body --
5567 ----------------------
5568
5569 function In_Instance_Body return Boolean is
5570 S : Entity_Id;
5571
5572 begin
5573 S := Current_Scope;
5574 while Present (S)
5575 and then S /= Standard_Standard
5576 loop
5577 if (Ekind (S) = E_Function
5578 or else Ekind (S) = E_Procedure)
5579 and then Is_Generic_Instance (S)
5580 then
5581 return True;
5582
5583 elsif Ekind (S) = E_Package
5584 and then In_Package_Body (S)
5585 and then Is_Generic_Instance (S)
5586 then
5587 return True;
5588 end if;
5589
5590 S := Scope (S);
5591 end loop;
5592
5593 return False;
5594 end In_Instance_Body;
5595
5596 -----------------------------
5597 -- In_Instance_Not_Visible --
5598 -----------------------------
5599
5600 function In_Instance_Not_Visible return Boolean is
5601 S : Entity_Id;
5602
5603 begin
5604 S := Current_Scope;
5605 while Present (S)
5606 and then S /= Standard_Standard
5607 loop
5608 if (Ekind (S) = E_Function
5609 or else Ekind (S) = E_Procedure)
5610 and then Is_Generic_Instance (S)
5611 then
5612 return True;
5613
5614 elsif Ekind (S) = E_Package
5615 and then (In_Package_Body (S) or else In_Private_Part (S))
5616 and then Is_Generic_Instance (S)
5617 then
5618 return True;
5619 end if;
5620
5621 S := Scope (S);
5622 end loop;
5623
5624 return False;
5625 end In_Instance_Not_Visible;
5626
5627 ------------------------------
5628 -- In_Instance_Visible_Part --
5629 ------------------------------
5630
5631 function In_Instance_Visible_Part return Boolean is
5632 S : Entity_Id;
5633
5634 begin
5635 S := Current_Scope;
5636 while Present (S)
5637 and then S /= Standard_Standard
5638 loop
5639 if Ekind (S) = E_Package
5640 and then Is_Generic_Instance (S)
5641 and then not In_Package_Body (S)
5642 and then not In_Private_Part (S)
5643 then
5644 return True;
5645 end if;
5646
5647 S := Scope (S);
5648 end loop;
5649
5650 return False;
5651 end In_Instance_Visible_Part;
5652
5653 ---------------------
5654 -- In_Package_Body --
5655 ---------------------
5656
5657 function In_Package_Body return Boolean is
5658 S : Entity_Id;
5659
5660 begin
5661 S := Current_Scope;
5662 while Present (S)
5663 and then S /= Standard_Standard
5664 loop
5665 if Ekind (S) = E_Package
5666 and then In_Package_Body (S)
5667 then
5668 return True;
5669 else
5670 S := Scope (S);
5671 end if;
5672 end loop;
5673
5674 return False;
5675 end In_Package_Body;
5676
5677 --------------------------------
5678 -- In_Parameter_Specification --
5679 --------------------------------
5680
5681 function In_Parameter_Specification (N : Node_Id) return Boolean is
5682 PN : Node_Id;
5683
5684 begin
5685 PN := Parent (N);
5686 while Present (PN) loop
5687 if Nkind (PN) = N_Parameter_Specification then
5688 return True;
5689 end if;
5690
5691 PN := Parent (PN);
5692 end loop;
5693
5694 return False;
5695 end In_Parameter_Specification;
5696
5697 --------------------------------------
5698 -- In_Subprogram_Or_Concurrent_Unit --
5699 --------------------------------------
5700
5701 function In_Subprogram_Or_Concurrent_Unit return Boolean is
5702 E : Entity_Id;
5703 K : Entity_Kind;
5704
5705 begin
5706 -- Use scope chain to check successively outer scopes
5707
5708 E := Current_Scope;
5709 loop
5710 K := Ekind (E);
5711
5712 if K in Subprogram_Kind
5713 or else K in Concurrent_Kind
5714 or else K in Generic_Subprogram_Kind
5715 then
5716 return True;
5717
5718 elsif E = Standard_Standard then
5719 return False;
5720 end if;
5721
5722 E := Scope (E);
5723 end loop;
5724 end In_Subprogram_Or_Concurrent_Unit;
5725
5726 ---------------------
5727 -- In_Visible_Part --
5728 ---------------------
5729
5730 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
5731 begin
5732 return
5733 Is_Package_Or_Generic_Package (Scope_Id)
5734 and then In_Open_Scopes (Scope_Id)
5735 and then not In_Package_Body (Scope_Id)
5736 and then not In_Private_Part (Scope_Id);
5737 end In_Visible_Part;
5738
5739 ---------------------------------
5740 -- Insert_Explicit_Dereference --
5741 ---------------------------------
5742
5743 procedure Insert_Explicit_Dereference (N : Node_Id) is
5744 New_Prefix : constant Node_Id := Relocate_Node (N);
5745 Ent : Entity_Id := Empty;
5746 Pref : Node_Id;
5747 I : Interp_Index;
5748 It : Interp;
5749 T : Entity_Id;
5750
5751 begin
5752 Save_Interps (N, New_Prefix);
5753
5754 Rewrite (N,
5755 Make_Explicit_Dereference (Sloc (Parent (N)),
5756 Prefix => New_Prefix));
5757
5758 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
5759
5760 if Is_Overloaded (New_Prefix) then
5761
5762 -- The dereference is also overloaded, and its interpretations are
5763 -- the designated types of the interpretations of the original node.
5764
5765 Set_Etype (N, Any_Type);
5766
5767 Get_First_Interp (New_Prefix, I, It);
5768 while Present (It.Nam) loop
5769 T := It.Typ;
5770
5771 if Is_Access_Type (T) then
5772 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
5773 end if;
5774
5775 Get_Next_Interp (I, It);
5776 end loop;
5777
5778 End_Interp_List;
5779
5780 else
5781 -- Prefix is unambiguous: mark the original prefix (which might
5782 -- Come_From_Source) as a reference, since the new (relocated) one
5783 -- won't be taken into account.
5784
5785 if Is_Entity_Name (New_Prefix) then
5786 Ent := Entity (New_Prefix);
5787 Pref := New_Prefix;
5788
5789 -- For a retrieval of a subcomponent of some composite object,
5790 -- retrieve the ultimate entity if there is one.
5791
5792 elsif Nkind (New_Prefix) = N_Selected_Component
5793 or else Nkind (New_Prefix) = N_Indexed_Component
5794 then
5795 Pref := Prefix (New_Prefix);
5796 while Present (Pref)
5797 and then
5798 (Nkind (Pref) = N_Selected_Component
5799 or else Nkind (Pref) = N_Indexed_Component)
5800 loop
5801 Pref := Prefix (Pref);
5802 end loop;
5803
5804 if Present (Pref) and then Is_Entity_Name (Pref) then
5805 Ent := Entity (Pref);
5806 end if;
5807 end if;
5808
5809 -- Place the reference on the entity node
5810
5811 if Present (Ent) then
5812 Generate_Reference (Ent, Pref);
5813 end if;
5814 end if;
5815 end Insert_Explicit_Dereference;
5816
5817 ------------------------------------------
5818 -- Inspect_Deferred_Constant_Completion --
5819 ------------------------------------------
5820
5821 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
5822 Decl : Node_Id;
5823
5824 begin
5825 Decl := First (Decls);
5826 while Present (Decl) loop
5827
5828 -- Deferred constant signature
5829
5830 if Nkind (Decl) = N_Object_Declaration
5831 and then Constant_Present (Decl)
5832 and then No (Expression (Decl))
5833
5834 -- No need to check internally generated constants
5835
5836 and then Comes_From_Source (Decl)
5837
5838 -- The constant is not completed. A full object declaration or a
5839 -- pragma Import complete a deferred constant.
5840
5841 and then not Has_Completion (Defining_Identifier (Decl))
5842 then
5843 Error_Msg_N
5844 ("constant declaration requires initialization expression",
5845 Defining_Identifier (Decl));
5846 end if;
5847
5848 Decl := Next (Decl);
5849 end loop;
5850 end Inspect_Deferred_Constant_Completion;
5851
5852 -----------------------------
5853 -- Is_Actual_Out_Parameter --
5854 -----------------------------
5855
5856 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
5857 Formal : Entity_Id;
5858 Call : Node_Id;
5859 begin
5860 Find_Actual (N, Formal, Call);
5861 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
5862 end Is_Actual_Out_Parameter;
5863
5864 -------------------------
5865 -- Is_Actual_Parameter --
5866 -------------------------
5867
5868 function Is_Actual_Parameter (N : Node_Id) return Boolean is
5869 PK : constant Node_Kind := Nkind (Parent (N));
5870
5871 begin
5872 case PK is
5873 when N_Parameter_Association =>
5874 return N = Explicit_Actual_Parameter (Parent (N));
5875
5876 when N_Function_Call | N_Procedure_Call_Statement =>
5877 return Is_List_Member (N)
5878 and then
5879 List_Containing (N) = Parameter_Associations (Parent (N));
5880
5881 when others =>
5882 return False;
5883 end case;
5884 end Is_Actual_Parameter;
5885
5886 --------------------------------
5887 -- Is_Actual_Tagged_Parameter --
5888 --------------------------------
5889
5890 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
5891 Formal : Entity_Id;
5892 Call : Node_Id;
5893 begin
5894 Find_Actual (N, Formal, Call);
5895 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
5896 end Is_Actual_Tagged_Parameter;
5897
5898 ---------------------
5899 -- Is_Aliased_View --
5900 ---------------------
5901
5902 function Is_Aliased_View (Obj : Node_Id) return Boolean is
5903 E : Entity_Id;
5904
5905 begin
5906 if Is_Entity_Name (Obj) then
5907
5908 E := Entity (Obj);
5909
5910 return
5911 (Is_Object (E)
5912 and then
5913 (Is_Aliased (E)
5914 or else (Present (Renamed_Object (E))
5915 and then Is_Aliased_View (Renamed_Object (E)))))
5916
5917 or else ((Is_Formal (E)
5918 or else Ekind (E) = E_Generic_In_Out_Parameter
5919 or else Ekind (E) = E_Generic_In_Parameter)
5920 and then Is_Tagged_Type (Etype (E)))
5921
5922 or else (Is_Concurrent_Type (E)
5923 and then In_Open_Scopes (E))
5924
5925 -- Current instance of type, either directly or as rewritten
5926 -- reference to the current object.
5927
5928 or else (Is_Entity_Name (Original_Node (Obj))
5929 and then Present (Entity (Original_Node (Obj)))
5930 and then Is_Type (Entity (Original_Node (Obj))))
5931
5932 or else (Is_Type (E) and then E = Current_Scope)
5933
5934 or else (Is_Incomplete_Or_Private_Type (E)
5935 and then Full_View (E) = Current_Scope);
5936
5937 elsif Nkind (Obj) = N_Selected_Component then
5938 return Is_Aliased (Entity (Selector_Name (Obj)));
5939
5940 elsif Nkind (Obj) = N_Indexed_Component then
5941 return Has_Aliased_Components (Etype (Prefix (Obj)))
5942 or else
5943 (Is_Access_Type (Etype (Prefix (Obj)))
5944 and then
5945 Has_Aliased_Components
5946 (Designated_Type (Etype (Prefix (Obj)))));
5947
5948 elsif Nkind (Obj) = N_Unchecked_Type_Conversion
5949 or else Nkind (Obj) = N_Type_Conversion
5950 then
5951 return Is_Tagged_Type (Etype (Obj))
5952 and then Is_Aliased_View (Expression (Obj));
5953
5954 elsif Nkind (Obj) = N_Explicit_Dereference then
5955 return Nkind (Original_Node (Obj)) /= N_Function_Call;
5956
5957 else
5958 return False;
5959 end if;
5960 end Is_Aliased_View;
5961
5962 -------------------------
5963 -- Is_Ancestor_Package --
5964 -------------------------
5965
5966 function Is_Ancestor_Package
5967 (E1 : Entity_Id;
5968 E2 : Entity_Id) return Boolean
5969 is
5970 Par : Entity_Id;
5971
5972 begin
5973 Par := E2;
5974 while Present (Par)
5975 and then Par /= Standard_Standard
5976 loop
5977 if Par = E1 then
5978 return True;
5979 end if;
5980
5981 Par := Scope (Par);
5982 end loop;
5983
5984 return False;
5985 end Is_Ancestor_Package;
5986
5987 ----------------------
5988 -- Is_Atomic_Object --
5989 ----------------------
5990
5991 function Is_Atomic_Object (N : Node_Id) return Boolean is
5992
5993 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
5994 -- Determines if given object has atomic components
5995
5996 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
5997 -- If prefix is an implicit dereference, examine designated type
5998
5999 ----------------------
6000 -- Is_Atomic_Prefix --
6001 ----------------------
6002
6003 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
6004 begin
6005 if Is_Access_Type (Etype (N)) then
6006 return
6007 Has_Atomic_Components (Designated_Type (Etype (N)));
6008 else
6009 return Object_Has_Atomic_Components (N);
6010 end if;
6011 end Is_Atomic_Prefix;
6012
6013 ----------------------------------
6014 -- Object_Has_Atomic_Components --
6015 ----------------------------------
6016
6017 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
6018 begin
6019 if Has_Atomic_Components (Etype (N))
6020 or else Is_Atomic (Etype (N))
6021 then
6022 return True;
6023
6024 elsif Is_Entity_Name (N)
6025 and then (Has_Atomic_Components (Entity (N))
6026 or else Is_Atomic (Entity (N)))
6027 then
6028 return True;
6029
6030 elsif Nkind (N) = N_Indexed_Component
6031 or else Nkind (N) = N_Selected_Component
6032 then
6033 return Is_Atomic_Prefix (Prefix (N));
6034
6035 else
6036 return False;
6037 end if;
6038 end Object_Has_Atomic_Components;
6039
6040 -- Start of processing for Is_Atomic_Object
6041
6042 begin
6043 -- Predicate is not relevant to subprograms
6044
6045 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
6046 return False;
6047
6048 elsif Is_Atomic (Etype (N))
6049 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
6050 then
6051 return True;
6052
6053 elsif Nkind (N) = N_Indexed_Component
6054 or else Nkind (N) = N_Selected_Component
6055 then
6056 return Is_Atomic_Prefix (Prefix (N));
6057
6058 else
6059 return False;
6060 end if;
6061 end Is_Atomic_Object;
6062
6063 -------------------------
6064 -- Is_Coextension_Root --
6065 -------------------------
6066
6067 function Is_Coextension_Root (N : Node_Id) return Boolean is
6068 begin
6069 return
6070 Nkind (N) = N_Allocator
6071 and then Present (Coextensions (N))
6072
6073 -- Anonymous access discriminants carry a list of all nested
6074 -- controlled coextensions.
6075
6076 and then not Is_Dynamic_Coextension (N)
6077 and then not Is_Static_Coextension (N);
6078 end Is_Coextension_Root;
6079
6080 -----------------------------
6081 -- Is_Concurrent_Interface --
6082 -----------------------------
6083
6084 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
6085 begin
6086 return
6087 Is_Interface (T)
6088 and then
6089 (Is_Protected_Interface (T)
6090 or else Is_Synchronized_Interface (T)
6091 or else Is_Task_Interface (T));
6092 end Is_Concurrent_Interface;
6093
6094 --------------------------------------
6095 -- Is_Controlling_Limited_Procedure --
6096 --------------------------------------
6097
6098 function Is_Controlling_Limited_Procedure
6099 (Proc_Nam : Entity_Id) return Boolean
6100 is
6101 Param_Typ : Entity_Id := Empty;
6102
6103 begin
6104 if Ekind (Proc_Nam) = E_Procedure
6105 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
6106 then
6107 Param_Typ := Etype (Parameter_Type (First (
6108 Parameter_Specifications (Parent (Proc_Nam)))));
6109
6110 -- In this case where an Itype was created, the procedure call has been
6111 -- rewritten.
6112
6113 elsif Present (Associated_Node_For_Itype (Proc_Nam))
6114 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
6115 and then
6116 Present (Parameter_Associations
6117 (Associated_Node_For_Itype (Proc_Nam)))
6118 then
6119 Param_Typ :=
6120 Etype (First (Parameter_Associations
6121 (Associated_Node_For_Itype (Proc_Nam))));
6122 end if;
6123
6124 if Present (Param_Typ) then
6125 return
6126 Is_Interface (Param_Typ)
6127 and then Is_Limited_Record (Param_Typ);
6128 end if;
6129
6130 return False;
6131 end Is_Controlling_Limited_Procedure;
6132
6133 -----------------------------
6134 -- Is_CPP_Constructor_Call --
6135 -----------------------------
6136
6137 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
6138 begin
6139 return Nkind (N) = N_Function_Call
6140 and then Is_CPP_Class (Etype (Etype (N)))
6141 and then Is_Constructor (Entity (Name (N)))
6142 and then Is_Imported (Entity (Name (N)));
6143 end Is_CPP_Constructor_Call;
6144
6145 -----------------
6146 -- Is_Delegate --
6147 -----------------
6148
6149 function Is_Delegate (T : Entity_Id) return Boolean is
6150 Desig_Type : Entity_Id;
6151
6152 begin
6153 if VM_Target /= CLI_Target then
6154 return False;
6155 end if;
6156
6157 -- Access-to-subprograms are delegates in CIL
6158
6159 if Ekind (T) = E_Access_Subprogram_Type then
6160 return True;
6161 end if;
6162
6163 if Ekind (T) not in Access_Kind then
6164
6165 -- A delegate is a managed pointer. If no designated type is defined
6166 -- it means that it's not a delegate.
6167
6168 return False;
6169 end if;
6170
6171 Desig_Type := Etype (Directly_Designated_Type (T));
6172
6173 if not Is_Tagged_Type (Desig_Type) then
6174 return False;
6175 end if;
6176
6177 -- Test if the type is inherited from [mscorlib]System.Delegate
6178
6179 while Etype (Desig_Type) /= Desig_Type loop
6180 if Chars (Scope (Desig_Type)) /= No_Name
6181 and then Is_Imported (Scope (Desig_Type))
6182 and then Get_Name_String (Chars (Scope (Desig_Type))) = "delegate"
6183 then
6184 return True;
6185 end if;
6186
6187 Desig_Type := Etype (Desig_Type);
6188 end loop;
6189
6190 return False;
6191 end Is_Delegate;
6192
6193 ----------------------------------------------
6194 -- Is_Dependent_Component_Of_Mutable_Object --
6195 ----------------------------------------------
6196
6197 function Is_Dependent_Component_Of_Mutable_Object
6198 (Object : Node_Id) return Boolean
6199 is
6200 P : Node_Id;
6201 Prefix_Type : Entity_Id;
6202 P_Aliased : Boolean := False;
6203 Comp : Entity_Id;
6204
6205 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
6206 -- Returns True if and only if Comp is declared within a variant part
6207
6208 --------------------------------
6209 -- Is_Declared_Within_Variant --
6210 --------------------------------
6211
6212 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
6213 Comp_Decl : constant Node_Id := Parent (Comp);
6214 Comp_List : constant Node_Id := Parent (Comp_Decl);
6215 begin
6216 return Nkind (Parent (Comp_List)) = N_Variant;
6217 end Is_Declared_Within_Variant;
6218
6219 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
6220
6221 begin
6222 if Is_Variable (Object) then
6223
6224 if Nkind (Object) = N_Selected_Component then
6225 P := Prefix (Object);
6226 Prefix_Type := Etype (P);
6227
6228 if Is_Entity_Name (P) then
6229
6230 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
6231 Prefix_Type := Base_Type (Prefix_Type);
6232 end if;
6233
6234 if Is_Aliased (Entity (P)) then
6235 P_Aliased := True;
6236 end if;
6237
6238 -- A discriminant check on a selected component may be expanded
6239 -- into a dereference when removing side-effects. Recover the
6240 -- original node and its type, which may be unconstrained.
6241
6242 elsif Nkind (P) = N_Explicit_Dereference
6243 and then not (Comes_From_Source (P))
6244 then
6245 P := Original_Node (P);
6246 Prefix_Type := Etype (P);
6247
6248 else
6249 -- Check for prefix being an aliased component???
6250
6251 null;
6252
6253 end if;
6254
6255 -- A heap object is constrained by its initial value
6256
6257 -- Ada 2005 (AI-363): Always assume the object could be mutable in
6258 -- the dereferenced case, since the access value might denote an
6259 -- unconstrained aliased object, whereas in Ada 95 the designated
6260 -- object is guaranteed to be constrained. A worst-case assumption
6261 -- has to apply in Ada 2005 because we can't tell at compile time
6262 -- whether the object is "constrained by its initial value"
6263 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
6264 -- semantic rules -- these rules are acknowledged to need fixing).
6265
6266 if Ada_Version < Ada_2005 then
6267 if Is_Access_Type (Prefix_Type)
6268 or else Nkind (P) = N_Explicit_Dereference
6269 then
6270 return False;
6271 end if;
6272
6273 elsif Ada_Version >= Ada_2005 then
6274 if Is_Access_Type (Prefix_Type) then
6275
6276 -- If the access type is pool-specific, and there is no
6277 -- constrained partial view of the designated type, then the
6278 -- designated object is known to be constrained.
6279
6280 if Ekind (Prefix_Type) = E_Access_Type
6281 and then not Has_Constrained_Partial_View
6282 (Designated_Type (Prefix_Type))
6283 then
6284 return False;
6285
6286 -- Otherwise (general access type, or there is a constrained
6287 -- partial view of the designated type), we need to check
6288 -- based on the designated type.
6289
6290 else
6291 Prefix_Type := Designated_Type (Prefix_Type);
6292 end if;
6293 end if;
6294 end if;
6295
6296 Comp :=
6297 Original_Record_Component (Entity (Selector_Name (Object)));
6298
6299 -- As per AI-0017, the renaming is illegal in a generic body, even
6300 -- if the subtype is indefinite.
6301
6302 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
6303
6304 if not Is_Constrained (Prefix_Type)
6305 and then (not Is_Indefinite_Subtype (Prefix_Type)
6306 or else
6307 (Is_Generic_Type (Prefix_Type)
6308 and then Ekind (Current_Scope) = E_Generic_Package
6309 and then In_Package_Body (Current_Scope)))
6310
6311 and then (Is_Declared_Within_Variant (Comp)
6312 or else Has_Discriminant_Dependent_Constraint (Comp))
6313 and then (not P_Aliased or else Ada_Version >= Ada_2005)
6314 then
6315 return True;
6316
6317 else
6318 return
6319 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
6320
6321 end if;
6322
6323 elsif Nkind (Object) = N_Indexed_Component
6324 or else Nkind (Object) = N_Slice
6325 then
6326 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
6327
6328 -- A type conversion that Is_Variable is a view conversion:
6329 -- go back to the denoted object.
6330
6331 elsif Nkind (Object) = N_Type_Conversion then
6332 return
6333 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
6334 end if;
6335 end if;
6336
6337 return False;
6338 end Is_Dependent_Component_Of_Mutable_Object;
6339
6340 ---------------------
6341 -- Is_Dereferenced --
6342 ---------------------
6343
6344 function Is_Dereferenced (N : Node_Id) return Boolean is
6345 P : constant Node_Id := Parent (N);
6346 begin
6347 return
6348 (Nkind (P) = N_Selected_Component
6349 or else
6350 Nkind (P) = N_Explicit_Dereference
6351 or else
6352 Nkind (P) = N_Indexed_Component
6353 or else
6354 Nkind (P) = N_Slice)
6355 and then Prefix (P) = N;
6356 end Is_Dereferenced;
6357
6358 ----------------------
6359 -- Is_Descendent_Of --
6360 ----------------------
6361
6362 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
6363 T : Entity_Id;
6364 Etyp : Entity_Id;
6365
6366 begin
6367 pragma Assert (Nkind (T1) in N_Entity);
6368 pragma Assert (Nkind (T2) in N_Entity);
6369
6370 T := Base_Type (T1);
6371
6372 -- Immediate return if the types match
6373
6374 if T = T2 then
6375 return True;
6376
6377 -- Comment needed here ???
6378
6379 elsif Ekind (T) = E_Class_Wide_Type then
6380 return Etype (T) = T2;
6381
6382 -- All other cases
6383
6384 else
6385 loop
6386 Etyp := Etype (T);
6387
6388 -- Done if we found the type we are looking for
6389
6390 if Etyp = T2 then
6391 return True;
6392
6393 -- Done if no more derivations to check
6394
6395 elsif T = T1
6396 or else T = Etyp
6397 then
6398 return False;
6399
6400 -- Following test catches error cases resulting from prev errors
6401
6402 elsif No (Etyp) then
6403 return False;
6404
6405 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
6406 return False;
6407
6408 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
6409 return False;
6410 end if;
6411
6412 T := Base_Type (Etyp);
6413 end loop;
6414 end if;
6415 end Is_Descendent_Of;
6416
6417 --------------
6418 -- Is_False --
6419 --------------
6420
6421 function Is_False (U : Uint) return Boolean is
6422 begin
6423 return (U = 0);
6424 end Is_False;
6425
6426 ---------------------------
6427 -- Is_Fixed_Model_Number --
6428 ---------------------------
6429
6430 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
6431 S : constant Ureal := Small_Value (T);
6432 M : Urealp.Save_Mark;
6433 R : Boolean;
6434 begin
6435 M := Urealp.Mark;
6436 R := (U = UR_Trunc (U / S) * S);
6437 Urealp.Release (M);
6438 return R;
6439 end Is_Fixed_Model_Number;
6440
6441 -------------------------------
6442 -- Is_Fully_Initialized_Type --
6443 -------------------------------
6444
6445 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
6446 begin
6447 if Is_Scalar_Type (Typ) then
6448 return False;
6449
6450 elsif Is_Access_Type (Typ) then
6451 return True;
6452
6453 elsif Is_Array_Type (Typ) then
6454 if Is_Fully_Initialized_Type (Component_Type (Typ)) then
6455 return True;
6456 end if;
6457
6458 -- An interesting case, if we have a constrained type one of whose
6459 -- bounds is known to be null, then there are no elements to be
6460 -- initialized, so all the elements are initialized!
6461
6462 if Is_Constrained (Typ) then
6463 declare
6464 Indx : Node_Id;
6465 Indx_Typ : Entity_Id;
6466 Lbd, Hbd : Node_Id;
6467
6468 begin
6469 Indx := First_Index (Typ);
6470 while Present (Indx) loop
6471 if Etype (Indx) = Any_Type then
6472 return False;
6473
6474 -- If index is a range, use directly
6475
6476 elsif Nkind (Indx) = N_Range then
6477 Lbd := Low_Bound (Indx);
6478 Hbd := High_Bound (Indx);
6479
6480 else
6481 Indx_Typ := Etype (Indx);
6482
6483 if Is_Private_Type (Indx_Typ) then
6484 Indx_Typ := Full_View (Indx_Typ);
6485 end if;
6486
6487 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
6488 return False;
6489 else
6490 Lbd := Type_Low_Bound (Indx_Typ);
6491 Hbd := Type_High_Bound (Indx_Typ);
6492 end if;
6493 end if;
6494
6495 if Compile_Time_Known_Value (Lbd)
6496 and then Compile_Time_Known_Value (Hbd)
6497 then
6498 if Expr_Value (Hbd) < Expr_Value (Lbd) then
6499 return True;
6500 end if;
6501 end if;
6502
6503 Next_Index (Indx);
6504 end loop;
6505 end;
6506 end if;
6507
6508 -- If no null indexes, then type is not fully initialized
6509
6510 return False;
6511
6512 -- Record types
6513
6514 elsif Is_Record_Type (Typ) then
6515 if Has_Discriminants (Typ)
6516 and then
6517 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
6518 and then Is_Fully_Initialized_Variant (Typ)
6519 then
6520 return True;
6521 end if;
6522
6523 -- Controlled records are considered to be fully initialized if
6524 -- there is a user defined Initialize routine. This may not be
6525 -- entirely correct, but as the spec notes, we are guessing here
6526 -- what is best from the point of view of issuing warnings.
6527
6528 if Is_Controlled (Typ) then
6529 declare
6530 Utyp : constant Entity_Id := Underlying_Type (Typ);
6531
6532 begin
6533 if Present (Utyp) then
6534 declare
6535 Init : constant Entity_Id :=
6536 (Find_Prim_Op
6537 (Underlying_Type (Typ), Name_Initialize));
6538
6539 begin
6540 if Present (Init)
6541 and then Comes_From_Source (Init)
6542 and then not
6543 Is_Predefined_File_Name
6544 (File_Name (Get_Source_File_Index (Sloc (Init))))
6545 then
6546 return True;
6547
6548 elsif Has_Null_Extension (Typ)
6549 and then
6550 Is_Fully_Initialized_Type
6551 (Etype (Base_Type (Typ)))
6552 then
6553 return True;
6554 end if;
6555 end;
6556 end if;
6557 end;
6558 end if;
6559
6560 -- Otherwise see if all record components are initialized
6561
6562 declare
6563 Ent : Entity_Id;
6564
6565 begin
6566 Ent := First_Entity (Typ);
6567 while Present (Ent) loop
6568 if Chars (Ent) = Name_uController then
6569 null;
6570
6571 elsif Ekind (Ent) = E_Component
6572 and then (No (Parent (Ent))
6573 or else No (Expression (Parent (Ent))))
6574 and then not Is_Fully_Initialized_Type (Etype (Ent))
6575
6576 -- Special VM case for tag components, which need to be
6577 -- defined in this case, but are never initialized as VMs
6578 -- are using other dispatching mechanisms. Ignore this
6579 -- uninitialized case. Note that this applies both to the
6580 -- uTag entry and the main vtable pointer (CPP_Class case).
6581
6582 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
6583 then
6584 return False;
6585 end if;
6586
6587 Next_Entity (Ent);
6588 end loop;
6589 end;
6590
6591 -- No uninitialized components, so type is fully initialized.
6592 -- Note that this catches the case of no components as well.
6593
6594 return True;
6595
6596 elsif Is_Concurrent_Type (Typ) then
6597 return True;
6598
6599 elsif Is_Private_Type (Typ) then
6600 declare
6601 U : constant Entity_Id := Underlying_Type (Typ);
6602
6603 begin
6604 if No (U) then
6605 return False;
6606 else
6607 return Is_Fully_Initialized_Type (U);
6608 end if;
6609 end;
6610
6611 else
6612 return False;
6613 end if;
6614 end Is_Fully_Initialized_Type;
6615
6616 ----------------------------------
6617 -- Is_Fully_Initialized_Variant --
6618 ----------------------------------
6619
6620 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
6621 Loc : constant Source_Ptr := Sloc (Typ);
6622 Constraints : constant List_Id := New_List;
6623 Components : constant Elist_Id := New_Elmt_List;
6624 Comp_Elmt : Elmt_Id;
6625 Comp_Id : Node_Id;
6626 Comp_List : Node_Id;
6627 Discr : Entity_Id;
6628 Discr_Val : Node_Id;
6629
6630 Report_Errors : Boolean;
6631 pragma Warnings (Off, Report_Errors);
6632
6633 begin
6634 if Serious_Errors_Detected > 0 then
6635 return False;
6636 end if;
6637
6638 if Is_Record_Type (Typ)
6639 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
6640 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
6641 then
6642 Comp_List := Component_List (Type_Definition (Parent (Typ)));
6643
6644 Discr := First_Discriminant (Typ);
6645 while Present (Discr) loop
6646 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
6647 Discr_Val := Expression (Parent (Discr));
6648
6649 if Present (Discr_Val)
6650 and then Is_OK_Static_Expression (Discr_Val)
6651 then
6652 Append_To (Constraints,
6653 Make_Component_Association (Loc,
6654 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
6655 Expression => New_Copy (Discr_Val)));
6656 else
6657 return False;
6658 end if;
6659 else
6660 return False;
6661 end if;
6662
6663 Next_Discriminant (Discr);
6664 end loop;
6665
6666 Gather_Components
6667 (Typ => Typ,
6668 Comp_List => Comp_List,
6669 Governed_By => Constraints,
6670 Into => Components,
6671 Report_Errors => Report_Errors);
6672
6673 -- Check that each component present is fully initialized
6674
6675 Comp_Elmt := First_Elmt (Components);
6676 while Present (Comp_Elmt) loop
6677 Comp_Id := Node (Comp_Elmt);
6678
6679 if Ekind (Comp_Id) = E_Component
6680 and then (No (Parent (Comp_Id))
6681 or else No (Expression (Parent (Comp_Id))))
6682 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
6683 then
6684 return False;
6685 end if;
6686
6687 Next_Elmt (Comp_Elmt);
6688 end loop;
6689
6690 return True;
6691
6692 elsif Is_Private_Type (Typ) then
6693 declare
6694 U : constant Entity_Id := Underlying_Type (Typ);
6695
6696 begin
6697 if No (U) then
6698 return False;
6699 else
6700 return Is_Fully_Initialized_Variant (U);
6701 end if;
6702 end;
6703 else
6704 return False;
6705 end if;
6706 end Is_Fully_Initialized_Variant;
6707
6708 ------------
6709 -- Is_LHS --
6710 ------------
6711
6712 -- We seem to have a lot of overlapping functions that do similar things
6713 -- (testing for left hand sides or lvalues???). Anyway, since this one is
6714 -- purely syntactic, it should be in Sem_Aux I would think???
6715
6716 function Is_LHS (N : Node_Id) return Boolean is
6717 P : constant Node_Id := Parent (N);
6718
6719 begin
6720 if Nkind (P) = N_Assignment_Statement then
6721 return Name (P) = N;
6722
6723 elsif
6724 Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
6725 then
6726 return N = Prefix (P) and then Is_LHS (P);
6727
6728 else
6729 return False;
6730 end if;
6731 end Is_LHS;
6732
6733 ----------------------------
6734 -- Is_Inherited_Operation --
6735 ----------------------------
6736
6737 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
6738 Kind : constant Node_Kind := Nkind (Parent (E));
6739 begin
6740 pragma Assert (Is_Overloadable (E));
6741 return Kind = N_Full_Type_Declaration
6742 or else Kind = N_Private_Extension_Declaration
6743 or else Kind = N_Subtype_Declaration
6744 or else (Ekind (E) = E_Enumeration_Literal
6745 and then Is_Derived_Type (Etype (E)));
6746 end Is_Inherited_Operation;
6747
6748 -----------------------------
6749 -- Is_Library_Level_Entity --
6750 -----------------------------
6751
6752 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
6753 begin
6754 -- The following is a small optimization, and it also properly handles
6755 -- discriminals, which in task bodies might appear in expressions before
6756 -- the corresponding procedure has been created, and which therefore do
6757 -- not have an assigned scope.
6758
6759 if Is_Formal (E) then
6760 return False;
6761 end if;
6762
6763 -- Normal test is simply that the enclosing dynamic scope is Standard
6764
6765 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
6766 end Is_Library_Level_Entity;
6767
6768 ---------------------------------
6769 -- Is_Local_Variable_Reference --
6770 ---------------------------------
6771
6772 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
6773 begin
6774 if not Is_Entity_Name (Expr) then
6775 return False;
6776
6777 else
6778 declare
6779 Ent : constant Entity_Id := Entity (Expr);
6780 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
6781 begin
6782 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
6783 return False;
6784 else
6785 return Present (Sub) and then Sub = Current_Subprogram;
6786 end if;
6787 end;
6788 end if;
6789 end Is_Local_Variable_Reference;
6790
6791 -------------------------
6792 -- Is_Object_Reference --
6793 -------------------------
6794
6795 function Is_Object_Reference (N : Node_Id) return Boolean is
6796 begin
6797 if Is_Entity_Name (N) then
6798 return Present (Entity (N)) and then Is_Object (Entity (N));
6799
6800 else
6801 case Nkind (N) is
6802 when N_Indexed_Component | N_Slice =>
6803 return
6804 Is_Object_Reference (Prefix (N))
6805 or else Is_Access_Type (Etype (Prefix (N)));
6806
6807 -- In Ada95, a function call is a constant object; a procedure
6808 -- call is not.
6809
6810 when N_Function_Call =>
6811 return Etype (N) /= Standard_Void_Type;
6812
6813 -- A reference to the stream attribute Input is a function call
6814
6815 when N_Attribute_Reference =>
6816 return Attribute_Name (N) = Name_Input;
6817
6818 when N_Selected_Component =>
6819 return
6820 Is_Object_Reference (Selector_Name (N))
6821 and then
6822 (Is_Object_Reference (Prefix (N))
6823 or else Is_Access_Type (Etype (Prefix (N))));
6824
6825 when N_Explicit_Dereference =>
6826 return True;
6827
6828 -- A view conversion of a tagged object is an object reference
6829
6830 when N_Type_Conversion =>
6831 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
6832 and then Is_Tagged_Type (Etype (Expression (N)))
6833 and then Is_Object_Reference (Expression (N));
6834
6835 -- An unchecked type conversion is considered to be an object if
6836 -- the operand is an object (this construction arises only as a
6837 -- result of expansion activities).
6838
6839 when N_Unchecked_Type_Conversion =>
6840 return True;
6841
6842 when others =>
6843 return False;
6844 end case;
6845 end if;
6846 end Is_Object_Reference;
6847
6848 -------------------------------
6849 -- Is_SPARK_Object_Reference --
6850 -------------------------------
6851
6852 function Is_SPARK_Object_Reference (N : Node_Id) return Boolean is
6853 begin
6854 if Is_Entity_Name (N) then
6855 return Present (Entity (N))
6856 and then
6857 (Ekind_In (Entity (N), E_Constant, E_Variable)
6858 or else Ekind (Entity (N)) in Formal_Kind);
6859
6860 else
6861 if Nkind (N) = N_Selected_Component then
6862 return Is_SPARK_Object_Reference (Prefix (N));
6863 else
6864 return False;
6865 end if;
6866 end if;
6867 end Is_SPARK_Object_Reference;
6868
6869 -----------------------------------
6870 -- Is_OK_Variable_For_Out_Formal --
6871 -----------------------------------
6872
6873 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
6874 begin
6875 Note_Possible_Modification (AV, Sure => True);
6876
6877 -- We must reject parenthesized variable names. The check for
6878 -- Comes_From_Source is present because there are currently
6879 -- cases where the compiler violates this rule (e.g. passing
6880 -- a task object to its controlled Initialize routine).
6881
6882 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
6883 return False;
6884
6885 -- A variable is always allowed
6886
6887 elsif Is_Variable (AV) then
6888 return True;
6889
6890 -- Unchecked conversions are allowed only if they come from the
6891 -- generated code, which sometimes uses unchecked conversions for out
6892 -- parameters in cases where code generation is unaffected. We tell
6893 -- source unchecked conversions by seeing if they are rewrites of an
6894 -- original Unchecked_Conversion function call, or of an explicit
6895 -- conversion of a function call.
6896
6897 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
6898 if Nkind (Original_Node (AV)) = N_Function_Call then
6899 return False;
6900
6901 elsif Comes_From_Source (AV)
6902 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
6903 then
6904 return False;
6905
6906 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
6907 return Is_OK_Variable_For_Out_Formal (Expression (AV));
6908
6909 else
6910 return True;
6911 end if;
6912
6913 -- Normal type conversions are allowed if argument is a variable
6914
6915 elsif Nkind (AV) = N_Type_Conversion then
6916 if Is_Variable (Expression (AV))
6917 and then Paren_Count (Expression (AV)) = 0
6918 then
6919 Note_Possible_Modification (Expression (AV), Sure => True);
6920 return True;
6921
6922 -- We also allow a non-parenthesized expression that raises
6923 -- constraint error if it rewrites what used to be a variable
6924
6925 elsif Raises_Constraint_Error (Expression (AV))
6926 and then Paren_Count (Expression (AV)) = 0
6927 and then Is_Variable (Original_Node (Expression (AV)))
6928 then
6929 return True;
6930
6931 -- Type conversion of something other than a variable
6932
6933 else
6934 return False;
6935 end if;
6936
6937 -- If this node is rewritten, then test the original form, if that is
6938 -- OK, then we consider the rewritten node OK (for example, if the
6939 -- original node is a conversion, then Is_Variable will not be true
6940 -- but we still want to allow the conversion if it converts a variable).
6941
6942 elsif Original_Node (AV) /= AV then
6943 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
6944
6945 -- All other non-variables are rejected
6946
6947 else
6948 return False;
6949 end if;
6950 end Is_OK_Variable_For_Out_Formal;
6951
6952 -----------------------------------
6953 -- Is_Partially_Initialized_Type --
6954 -----------------------------------
6955
6956 function Is_Partially_Initialized_Type
6957 (Typ : Entity_Id;
6958 Include_Implicit : Boolean := True) return Boolean
6959 is
6960 begin
6961 if Is_Scalar_Type (Typ) then
6962 return False;
6963
6964 elsif Is_Access_Type (Typ) then
6965 return Include_Implicit;
6966
6967 elsif Is_Array_Type (Typ) then
6968
6969 -- If component type is partially initialized, so is array type
6970
6971 if Is_Partially_Initialized_Type
6972 (Component_Type (Typ), Include_Implicit)
6973 then
6974 return True;
6975
6976 -- Otherwise we are only partially initialized if we are fully
6977 -- initialized (this is the empty array case, no point in us
6978 -- duplicating that code here).
6979
6980 else
6981 return Is_Fully_Initialized_Type (Typ);
6982 end if;
6983
6984 elsif Is_Record_Type (Typ) then
6985
6986 -- A discriminated type is always partially initialized if in
6987 -- all mode
6988
6989 if Has_Discriminants (Typ) and then Include_Implicit then
6990 return True;
6991
6992 -- A tagged type is always partially initialized
6993
6994 elsif Is_Tagged_Type (Typ) then
6995 return True;
6996
6997 -- Case of non-discriminated record
6998
6999 else
7000 declare
7001 Ent : Entity_Id;
7002
7003 Component_Present : Boolean := False;
7004 -- Set True if at least one component is present. If no
7005 -- components are present, then record type is fully
7006 -- initialized (another odd case, like the null array).
7007
7008 begin
7009 -- Loop through components
7010
7011 Ent := First_Entity (Typ);
7012 while Present (Ent) loop
7013 if Ekind (Ent) = E_Component then
7014 Component_Present := True;
7015
7016 -- If a component has an initialization expression then
7017 -- the enclosing record type is partially initialized
7018
7019 if Present (Parent (Ent))
7020 and then Present (Expression (Parent (Ent)))
7021 then
7022 return True;
7023
7024 -- If a component is of a type which is itself partially
7025 -- initialized, then the enclosing record type is also.
7026
7027 elsif Is_Partially_Initialized_Type
7028 (Etype (Ent), Include_Implicit)
7029 then
7030 return True;
7031 end if;
7032 end if;
7033
7034 Next_Entity (Ent);
7035 end loop;
7036
7037 -- No initialized components found. If we found any components
7038 -- they were all uninitialized so the result is false.
7039
7040 if Component_Present then
7041 return False;
7042
7043 -- But if we found no components, then all the components are
7044 -- initialized so we consider the type to be initialized.
7045
7046 else
7047 return True;
7048 end if;
7049 end;
7050 end if;
7051
7052 -- Concurrent types are always fully initialized
7053
7054 elsif Is_Concurrent_Type (Typ) then
7055 return True;
7056
7057 -- For a private type, go to underlying type. If there is no underlying
7058 -- type then just assume this partially initialized. Not clear if this
7059 -- can happen in a non-error case, but no harm in testing for this.
7060
7061 elsif Is_Private_Type (Typ) then
7062 declare
7063 U : constant Entity_Id := Underlying_Type (Typ);
7064 begin
7065 if No (U) then
7066 return True;
7067 else
7068 return Is_Partially_Initialized_Type (U, Include_Implicit);
7069 end if;
7070 end;
7071
7072 -- For any other type (are there any?) assume partially initialized
7073
7074 else
7075 return True;
7076 end if;
7077 end Is_Partially_Initialized_Type;
7078
7079 ------------------------------------
7080 -- Is_Potentially_Persistent_Type --
7081 ------------------------------------
7082
7083 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
7084 Comp : Entity_Id;
7085 Indx : Node_Id;
7086
7087 begin
7088 -- For private type, test corresponding full type
7089
7090 if Is_Private_Type (T) then
7091 return Is_Potentially_Persistent_Type (Full_View (T));
7092
7093 -- Scalar types are potentially persistent
7094
7095 elsif Is_Scalar_Type (T) then
7096 return True;
7097
7098 -- Record type is potentially persistent if not tagged and the types of
7099 -- all it components are potentially persistent, and no component has
7100 -- an initialization expression.
7101
7102 elsif Is_Record_Type (T)
7103 and then not Is_Tagged_Type (T)
7104 and then not Is_Partially_Initialized_Type (T)
7105 then
7106 Comp := First_Component (T);
7107 while Present (Comp) loop
7108 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
7109 return False;
7110 else
7111 Next_Entity (Comp);
7112 end if;
7113 end loop;
7114
7115 return True;
7116
7117 -- Array type is potentially persistent if its component type is
7118 -- potentially persistent and if all its constraints are static.
7119
7120 elsif Is_Array_Type (T) then
7121 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
7122 return False;
7123 end if;
7124
7125 Indx := First_Index (T);
7126 while Present (Indx) loop
7127 if not Is_OK_Static_Subtype (Etype (Indx)) then
7128 return False;
7129 else
7130 Next_Index (Indx);
7131 end if;
7132 end loop;
7133
7134 return True;
7135
7136 -- All other types are not potentially persistent
7137
7138 else
7139 return False;
7140 end if;
7141 end Is_Potentially_Persistent_Type;
7142
7143 ---------------------------------
7144 -- Is_Protected_Self_Reference --
7145 ---------------------------------
7146
7147 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
7148
7149 function In_Access_Definition (N : Node_Id) return Boolean;
7150 -- Returns true if N belongs to an access definition
7151
7152 --------------------------
7153 -- In_Access_Definition --
7154 --------------------------
7155
7156 function In_Access_Definition (N : Node_Id) return Boolean is
7157 P : Node_Id;
7158
7159 begin
7160 P := Parent (N);
7161 while Present (P) loop
7162 if Nkind (P) = N_Access_Definition then
7163 return True;
7164 end if;
7165
7166 P := Parent (P);
7167 end loop;
7168
7169 return False;
7170 end In_Access_Definition;
7171
7172 -- Start of processing for Is_Protected_Self_Reference
7173
7174 begin
7175 -- Verify that prefix is analyzed and has the proper form. Note that
7176 -- the attributes Elab_Spec, Elab_Body, and UET_Address, which also
7177 -- produce the address of an entity, do not analyze their prefix
7178 -- because they denote entities that are not necessarily visible.
7179 -- Neither of them can apply to a protected type.
7180
7181 return Ada_Version >= Ada_2005
7182 and then Is_Entity_Name (N)
7183 and then Present (Entity (N))
7184 and then Is_Protected_Type (Entity (N))
7185 and then In_Open_Scopes (Entity (N))
7186 and then not In_Access_Definition (N);
7187 end Is_Protected_Self_Reference;
7188
7189 -----------------------------
7190 -- Is_RCI_Pkg_Spec_Or_Body --
7191 -----------------------------
7192
7193 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
7194
7195 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
7196 -- Return True if the unit of Cunit is an RCI package declaration
7197
7198 ---------------------------
7199 -- Is_RCI_Pkg_Decl_Cunit --
7200 ---------------------------
7201
7202 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
7203 The_Unit : constant Node_Id := Unit (Cunit);
7204
7205 begin
7206 if Nkind (The_Unit) /= N_Package_Declaration then
7207 return False;
7208 end if;
7209
7210 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
7211 end Is_RCI_Pkg_Decl_Cunit;
7212
7213 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
7214
7215 begin
7216 return Is_RCI_Pkg_Decl_Cunit (Cunit)
7217 or else
7218 (Nkind (Unit (Cunit)) = N_Package_Body
7219 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
7220 end Is_RCI_Pkg_Spec_Or_Body;
7221
7222 -----------------------------------------
7223 -- Is_Remote_Access_To_Class_Wide_Type --
7224 -----------------------------------------
7225
7226 function Is_Remote_Access_To_Class_Wide_Type
7227 (E : Entity_Id) return Boolean
7228 is
7229 begin
7230 -- A remote access to class-wide type is a general access to object type
7231 -- declared in the visible part of a Remote_Types or Remote_Call_
7232 -- Interface unit.
7233
7234 return Ekind (E) = E_General_Access_Type
7235 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
7236 end Is_Remote_Access_To_Class_Wide_Type;
7237
7238 -----------------------------------------
7239 -- Is_Remote_Access_To_Subprogram_Type --
7240 -----------------------------------------
7241
7242 function Is_Remote_Access_To_Subprogram_Type
7243 (E : Entity_Id) return Boolean
7244 is
7245 begin
7246 return (Ekind (E) = E_Access_Subprogram_Type
7247 or else (Ekind (E) = E_Record_Type
7248 and then Present (Corresponding_Remote_Type (E))))
7249 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
7250 end Is_Remote_Access_To_Subprogram_Type;
7251
7252 --------------------
7253 -- Is_Remote_Call --
7254 --------------------
7255
7256 function Is_Remote_Call (N : Node_Id) return Boolean is
7257 begin
7258 if Nkind (N) /= N_Procedure_Call_Statement
7259 and then Nkind (N) /= N_Function_Call
7260 then
7261 -- An entry call cannot be remote
7262
7263 return False;
7264
7265 elsif Nkind (Name (N)) in N_Has_Entity
7266 and then Is_Remote_Call_Interface (Entity (Name (N)))
7267 then
7268 -- A subprogram declared in the spec of a RCI package is remote
7269
7270 return True;
7271
7272 elsif Nkind (Name (N)) = N_Explicit_Dereference
7273 and then Is_Remote_Access_To_Subprogram_Type
7274 (Etype (Prefix (Name (N))))
7275 then
7276 -- The dereference of a RAS is a remote call
7277
7278 return True;
7279
7280 elsif Present (Controlling_Argument (N))
7281 and then Is_Remote_Access_To_Class_Wide_Type
7282 (Etype (Controlling_Argument (N)))
7283 then
7284 -- Any primitive operation call with a controlling argument of
7285 -- a RACW type is a remote call.
7286
7287 return True;
7288 end if;
7289
7290 -- All other calls are local calls
7291
7292 return False;
7293 end Is_Remote_Call;
7294
7295 ----------------------
7296 -- Is_Renamed_Entry --
7297 ----------------------
7298
7299 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
7300 Orig_Node : Node_Id := Empty;
7301 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
7302
7303 function Is_Entry (Nam : Node_Id) return Boolean;
7304 -- Determine whether Nam is an entry. Traverse selectors if there are
7305 -- nested selected components.
7306
7307 --------------
7308 -- Is_Entry --
7309 --------------
7310
7311 function Is_Entry (Nam : Node_Id) return Boolean is
7312 begin
7313 if Nkind (Nam) = N_Selected_Component then
7314 return Is_Entry (Selector_Name (Nam));
7315 end if;
7316
7317 return Ekind (Entity (Nam)) = E_Entry;
7318 end Is_Entry;
7319
7320 -- Start of processing for Is_Renamed_Entry
7321
7322 begin
7323 if Present (Alias (Proc_Nam)) then
7324 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
7325 end if;
7326
7327 -- Look for a rewritten subprogram renaming declaration
7328
7329 if Nkind (Subp_Decl) = N_Subprogram_Declaration
7330 and then Present (Original_Node (Subp_Decl))
7331 then
7332 Orig_Node := Original_Node (Subp_Decl);
7333 end if;
7334
7335 -- The rewritten subprogram is actually an entry
7336
7337 if Present (Orig_Node)
7338 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
7339 and then Is_Entry (Name (Orig_Node))
7340 then
7341 return True;
7342 end if;
7343
7344 return False;
7345 end Is_Renamed_Entry;
7346
7347 ----------------------
7348 -- Is_Selector_Name --
7349 ----------------------
7350
7351 function Is_Selector_Name (N : Node_Id) return Boolean is
7352 begin
7353 if not Is_List_Member (N) then
7354 declare
7355 P : constant Node_Id := Parent (N);
7356 K : constant Node_Kind := Nkind (P);
7357 begin
7358 return
7359 (K = N_Expanded_Name or else
7360 K = N_Generic_Association or else
7361 K = N_Parameter_Association or else
7362 K = N_Selected_Component)
7363 and then Selector_Name (P) = N;
7364 end;
7365
7366 else
7367 declare
7368 L : constant List_Id := List_Containing (N);
7369 P : constant Node_Id := Parent (L);
7370 begin
7371 return (Nkind (P) = N_Discriminant_Association
7372 and then Selector_Names (P) = L)
7373 or else
7374 (Nkind (P) = N_Component_Association
7375 and then Choices (P) = L);
7376 end;
7377 end if;
7378 end Is_Selector_Name;
7379
7380 ------------------
7381 -- Is_Statement --
7382 ------------------
7383
7384 function Is_Statement (N : Node_Id) return Boolean is
7385 begin
7386 return
7387 Nkind (N) in N_Statement_Other_Than_Procedure_Call
7388 or else Nkind (N) = N_Procedure_Call_Statement;
7389 end Is_Statement;
7390
7391 ---------------------------------
7392 -- Is_Synchronized_Tagged_Type --
7393 ---------------------------------
7394
7395 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
7396 Kind : constant Entity_Kind := Ekind (Base_Type (E));
7397
7398 begin
7399 -- A task or protected type derived from an interface is a tagged type.
7400 -- Such a tagged type is called a synchronized tagged type, as are
7401 -- synchronized interfaces and private extensions whose declaration
7402 -- includes the reserved word synchronized.
7403
7404 return (Is_Tagged_Type (E)
7405 and then (Kind = E_Task_Type
7406 or else Kind = E_Protected_Type))
7407 or else
7408 (Is_Interface (E)
7409 and then Is_Synchronized_Interface (E))
7410 or else
7411 (Ekind (E) = E_Record_Type_With_Private
7412 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
7413 and then (Synchronized_Present (Parent (E))
7414 or else Is_Synchronized_Interface (Etype (E))));
7415 end Is_Synchronized_Tagged_Type;
7416
7417 -----------------
7418 -- Is_Transfer --
7419 -----------------
7420
7421 function Is_Transfer (N : Node_Id) return Boolean is
7422 Kind : constant Node_Kind := Nkind (N);
7423
7424 begin
7425 if Kind = N_Simple_Return_Statement
7426 or else
7427 Kind = N_Extended_Return_Statement
7428 or else
7429 Kind = N_Goto_Statement
7430 or else
7431 Kind = N_Raise_Statement
7432 or else
7433 Kind = N_Requeue_Statement
7434 then
7435 return True;
7436
7437 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
7438 and then No (Condition (N))
7439 then
7440 return True;
7441
7442 elsif Kind = N_Procedure_Call_Statement
7443 and then Is_Entity_Name (Name (N))
7444 and then Present (Entity (Name (N)))
7445 and then No_Return (Entity (Name (N)))
7446 then
7447 return True;
7448
7449 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
7450 return True;
7451
7452 else
7453 return False;
7454 end if;
7455 end Is_Transfer;
7456
7457 -------------
7458 -- Is_True --
7459 -------------
7460
7461 function Is_True (U : Uint) return Boolean is
7462 begin
7463 return (U /= 0);
7464 end Is_True;
7465
7466 -------------------------------
7467 -- Is_Universal_Numeric_Type --
7468 -------------------------------
7469
7470 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
7471 begin
7472 return T = Universal_Integer or else T = Universal_Real;
7473 end Is_Universal_Numeric_Type;
7474
7475 -------------------
7476 -- Is_Value_Type --
7477 -------------------
7478
7479 function Is_Value_Type (T : Entity_Id) return Boolean is
7480 begin
7481 return VM_Target = CLI_Target
7482 and then Nkind (T) in N_Has_Chars
7483 and then Chars (T) /= No_Name
7484 and then Get_Name_String (Chars (T)) = "valuetype";
7485 end Is_Value_Type;
7486
7487 ---------------------
7488 -- Is_VMS_Operator --
7489 ---------------------
7490
7491 function Is_VMS_Operator (Op : Entity_Id) return Boolean is
7492 begin
7493 -- The VMS operators are declared in a child of System that is loaded
7494 -- through pragma Extend_System. In some rare cases a program is run
7495 -- with this extension but without indicating that the target is VMS.
7496
7497 return Ekind (Op) = E_Function
7498 and then Is_Intrinsic_Subprogram (Op)
7499 and then
7500 ((Present_System_Aux
7501 and then Scope (Op) = System_Aux_Id)
7502 or else
7503 (True_VMS_Target
7504 and then Scope (Scope (Op)) = RTU_Entity (System)));
7505 end Is_VMS_Operator;
7506
7507 -----------------
7508 -- Is_Variable --
7509 -----------------
7510
7511 function Is_Variable
7512 (N : Node_Id;
7513 Use_Original_Node : Boolean := True) return Boolean
7514 is
7515 Orig_Node : Node_Id;
7516
7517 function In_Protected_Function (E : Entity_Id) return Boolean;
7518 -- Within a protected function, the private components of the enclosing
7519 -- protected type are constants. A function nested within a (protected)
7520 -- procedure is not itself protected.
7521
7522 function Is_Variable_Prefix (P : Node_Id) return Boolean;
7523 -- Prefixes can involve implicit dereferences, in which case we must
7524 -- test for the case of a reference of a constant access type, which can
7525 -- can never be a variable.
7526
7527 ---------------------------
7528 -- In_Protected_Function --
7529 ---------------------------
7530
7531 function In_Protected_Function (E : Entity_Id) return Boolean is
7532 Prot : constant Entity_Id := Scope (E);
7533 S : Entity_Id;
7534
7535 begin
7536 if not Is_Protected_Type (Prot) then
7537 return False;
7538 else
7539 S := Current_Scope;
7540 while Present (S) and then S /= Prot loop
7541 if Ekind (S) = E_Function and then Scope (S) = Prot then
7542 return True;
7543 end if;
7544
7545 S := Scope (S);
7546 end loop;
7547
7548 return False;
7549 end if;
7550 end In_Protected_Function;
7551
7552 ------------------------
7553 -- Is_Variable_Prefix --
7554 ------------------------
7555
7556 function Is_Variable_Prefix (P : Node_Id) return Boolean is
7557 begin
7558 if Is_Access_Type (Etype (P)) then
7559 return not Is_Access_Constant (Root_Type (Etype (P)));
7560
7561 -- For the case of an indexed component whose prefix has a packed
7562 -- array type, the prefix has been rewritten into a type conversion.
7563 -- Determine variable-ness from the converted expression.
7564
7565 elsif Nkind (P) = N_Type_Conversion
7566 and then not Comes_From_Source (P)
7567 and then Is_Array_Type (Etype (P))
7568 and then Is_Packed (Etype (P))
7569 then
7570 return Is_Variable (Expression (P));
7571
7572 else
7573 return Is_Variable (P);
7574 end if;
7575 end Is_Variable_Prefix;
7576
7577 -- Start of processing for Is_Variable
7578
7579 begin
7580 -- Check if we perform the test on the original node since this may be a
7581 -- test of syntactic categories which must not be disturbed by whatever
7582 -- rewriting might have occurred. For example, an aggregate, which is
7583 -- certainly NOT a variable, could be turned into a variable by
7584 -- expansion.
7585
7586 if Use_Original_Node then
7587 Orig_Node := Original_Node (N);
7588 else
7589 Orig_Node := N;
7590 end if;
7591
7592 -- Definitely OK if Assignment_OK is set. Since this is something that
7593 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
7594
7595 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
7596 return True;
7597
7598 -- Normally we go to the original node, but there is one exception where
7599 -- we use the rewritten node, namely when it is an explicit dereference.
7600 -- The generated code may rewrite a prefix which is an access type with
7601 -- an explicit dereference. The dereference is a variable, even though
7602 -- the original node may not be (since it could be a constant of the
7603 -- access type).
7604
7605 -- In Ada 2005 we have a further case to consider: the prefix may be a
7606 -- function call given in prefix notation. The original node appears to
7607 -- be a selected component, but we need to examine the call.
7608
7609 elsif Nkind (N) = N_Explicit_Dereference
7610 and then Nkind (Orig_Node) /= N_Explicit_Dereference
7611 and then Present (Etype (Orig_Node))
7612 and then Is_Access_Type (Etype (Orig_Node))
7613 then
7614 -- Note that if the prefix is an explicit dereference that does not
7615 -- come from source, we must check for a rewritten function call in
7616 -- prefixed notation before other forms of rewriting, to prevent a
7617 -- compiler crash.
7618
7619 return
7620 (Nkind (Orig_Node) = N_Function_Call
7621 and then not Is_Access_Constant (Etype (Prefix (N))))
7622 or else
7623 Is_Variable_Prefix (Original_Node (Prefix (N)));
7624
7625 -- A function call is never a variable
7626
7627 elsif Nkind (N) = N_Function_Call then
7628 return False;
7629
7630 -- All remaining checks use the original node
7631
7632 elsif Is_Entity_Name (Orig_Node)
7633 and then Present (Entity (Orig_Node))
7634 then
7635 declare
7636 E : constant Entity_Id := Entity (Orig_Node);
7637 K : constant Entity_Kind := Ekind (E);
7638
7639 begin
7640 return (K = E_Variable
7641 and then Nkind (Parent (E)) /= N_Exception_Handler)
7642 or else (K = E_Component
7643 and then not In_Protected_Function (E))
7644 or else K = E_Out_Parameter
7645 or else K = E_In_Out_Parameter
7646 or else K = E_Generic_In_Out_Parameter
7647
7648 -- Current instance of type:
7649
7650 or else (Is_Type (E) and then In_Open_Scopes (E))
7651 or else (Is_Incomplete_Or_Private_Type (E)
7652 and then In_Open_Scopes (Full_View (E)));
7653 end;
7654
7655 else
7656 case Nkind (Orig_Node) is
7657 when N_Indexed_Component | N_Slice =>
7658 return Is_Variable_Prefix (Prefix (Orig_Node));
7659
7660 when N_Selected_Component =>
7661 return Is_Variable_Prefix (Prefix (Orig_Node))
7662 and then Is_Variable (Selector_Name (Orig_Node));
7663
7664 -- For an explicit dereference, the type of the prefix cannot
7665 -- be an access to constant or an access to subprogram.
7666
7667 when N_Explicit_Dereference =>
7668 declare
7669 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
7670 begin
7671 return Is_Access_Type (Typ)
7672 and then not Is_Access_Constant (Root_Type (Typ))
7673 and then Ekind (Typ) /= E_Access_Subprogram_Type;
7674 end;
7675
7676 -- The type conversion is the case where we do not deal with the
7677 -- context dependent special case of an actual parameter. Thus
7678 -- the type conversion is only considered a variable for the
7679 -- purposes of this routine if the target type is tagged. However,
7680 -- a type conversion is considered to be a variable if it does not
7681 -- come from source (this deals for example with the conversions
7682 -- of expressions to their actual subtypes).
7683
7684 when N_Type_Conversion =>
7685 return Is_Variable (Expression (Orig_Node))
7686 and then
7687 (not Comes_From_Source (Orig_Node)
7688 or else
7689 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
7690 and then
7691 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
7692
7693 -- GNAT allows an unchecked type conversion as a variable. This
7694 -- only affects the generation of internal expanded code, since
7695 -- calls to instantiations of Unchecked_Conversion are never
7696 -- considered variables (since they are function calls).
7697 -- This is also true for expression actions.
7698
7699 when N_Unchecked_Type_Conversion =>
7700 return Is_Variable (Expression (Orig_Node));
7701
7702 when others =>
7703 return False;
7704 end case;
7705 end if;
7706 end Is_Variable;
7707
7708 ---------------------------
7709 -- Is_Visibly_Controlled --
7710 ---------------------------
7711
7712 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
7713 Root : constant Entity_Id := Root_Type (T);
7714 begin
7715 return Chars (Scope (Root)) = Name_Finalization
7716 and then Chars (Scope (Scope (Root))) = Name_Ada
7717 and then Scope (Scope (Scope (Root))) = Standard_Standard;
7718 end Is_Visibly_Controlled;
7719
7720 ------------------------
7721 -- Is_Volatile_Object --
7722 ------------------------
7723
7724 function Is_Volatile_Object (N : Node_Id) return Boolean is
7725
7726 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
7727 -- Determines if given object has volatile components
7728
7729 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
7730 -- If prefix is an implicit dereference, examine designated type
7731
7732 ------------------------
7733 -- Is_Volatile_Prefix --
7734 ------------------------
7735
7736 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
7737 Typ : constant Entity_Id := Etype (N);
7738
7739 begin
7740 if Is_Access_Type (Typ) then
7741 declare
7742 Dtyp : constant Entity_Id := Designated_Type (Typ);
7743
7744 begin
7745 return Is_Volatile (Dtyp)
7746 or else Has_Volatile_Components (Dtyp);
7747 end;
7748
7749 else
7750 return Object_Has_Volatile_Components (N);
7751 end if;
7752 end Is_Volatile_Prefix;
7753
7754 ------------------------------------
7755 -- Object_Has_Volatile_Components --
7756 ------------------------------------
7757
7758 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
7759 Typ : constant Entity_Id := Etype (N);
7760
7761 begin
7762 if Is_Volatile (Typ)
7763 or else Has_Volatile_Components (Typ)
7764 then
7765 return True;
7766
7767 elsif Is_Entity_Name (N)
7768 and then (Has_Volatile_Components (Entity (N))
7769 or else Is_Volatile (Entity (N)))
7770 then
7771 return True;
7772
7773 elsif Nkind (N) = N_Indexed_Component
7774 or else Nkind (N) = N_Selected_Component
7775 then
7776 return Is_Volatile_Prefix (Prefix (N));
7777
7778 else
7779 return False;
7780 end if;
7781 end Object_Has_Volatile_Components;
7782
7783 -- Start of processing for Is_Volatile_Object
7784
7785 begin
7786 if Is_Volatile (Etype (N))
7787 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
7788 then
7789 return True;
7790
7791 elsif Nkind (N) = N_Indexed_Component
7792 or else Nkind (N) = N_Selected_Component
7793 then
7794 return Is_Volatile_Prefix (Prefix (N));
7795
7796 else
7797 return False;
7798 end if;
7799 end Is_Volatile_Object;
7800
7801 -------------------------
7802 -- Kill_Current_Values --
7803 -------------------------
7804
7805 procedure Kill_Current_Values
7806 (Ent : Entity_Id;
7807 Last_Assignment_Only : Boolean := False)
7808 is
7809 begin
7810 -- ??? do we have to worry about clearing cached checks?
7811
7812 if Is_Assignable (Ent) then
7813 Set_Last_Assignment (Ent, Empty);
7814 end if;
7815
7816 if Is_Object (Ent) then
7817 if not Last_Assignment_Only then
7818 Kill_Checks (Ent);
7819 Set_Current_Value (Ent, Empty);
7820
7821 if not Can_Never_Be_Null (Ent) then
7822 Set_Is_Known_Non_Null (Ent, False);
7823 end if;
7824
7825 Set_Is_Known_Null (Ent, False);
7826
7827 -- Reset Is_Known_Valid unless type is always valid, or if we have
7828 -- a loop parameter (loop parameters are always valid, since their
7829 -- bounds are defined by the bounds given in the loop header).
7830
7831 if not Is_Known_Valid (Etype (Ent))
7832 and then Ekind (Ent) /= E_Loop_Parameter
7833 then
7834 Set_Is_Known_Valid (Ent, False);
7835 end if;
7836 end if;
7837 end if;
7838 end Kill_Current_Values;
7839
7840 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
7841 S : Entity_Id;
7842
7843 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
7844 -- Clear current value for entity E and all entities chained to E
7845
7846 ------------------------------------------
7847 -- Kill_Current_Values_For_Entity_Chain --
7848 ------------------------------------------
7849
7850 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
7851 Ent : Entity_Id;
7852 begin
7853 Ent := E;
7854 while Present (Ent) loop
7855 Kill_Current_Values (Ent, Last_Assignment_Only);
7856 Next_Entity (Ent);
7857 end loop;
7858 end Kill_Current_Values_For_Entity_Chain;
7859
7860 -- Start of processing for Kill_Current_Values
7861
7862 begin
7863 -- Kill all saved checks, a special case of killing saved values
7864
7865 if not Last_Assignment_Only then
7866 Kill_All_Checks;
7867 end if;
7868
7869 -- Loop through relevant scopes, which includes the current scope and
7870 -- any parent scopes if the current scope is a block or a package.
7871
7872 S := Current_Scope;
7873 Scope_Loop : loop
7874
7875 -- Clear current values of all entities in current scope
7876
7877 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
7878
7879 -- If scope is a package, also clear current values of all
7880 -- private entities in the scope.
7881
7882 if Is_Package_Or_Generic_Package (S)
7883 or else Is_Concurrent_Type (S)
7884 then
7885 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
7886 end if;
7887
7888 -- If this is a not a subprogram, deal with parents
7889
7890 if not Is_Subprogram (S) then
7891 S := Scope (S);
7892 exit Scope_Loop when S = Standard_Standard;
7893 else
7894 exit Scope_Loop;
7895 end if;
7896 end loop Scope_Loop;
7897 end Kill_Current_Values;
7898
7899 --------------------------
7900 -- Kill_Size_Check_Code --
7901 --------------------------
7902
7903 procedure Kill_Size_Check_Code (E : Entity_Id) is
7904 begin
7905 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7906 and then Present (Size_Check_Code (E))
7907 then
7908 Remove (Size_Check_Code (E));
7909 Set_Size_Check_Code (E, Empty);
7910 end if;
7911 end Kill_Size_Check_Code;
7912
7913 --------------------------
7914 -- Known_To_Be_Assigned --
7915 --------------------------
7916
7917 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
7918 P : constant Node_Id := Parent (N);
7919
7920 begin
7921 case Nkind (P) is
7922
7923 -- Test left side of assignment
7924
7925 when N_Assignment_Statement =>
7926 return N = Name (P);
7927
7928 -- Function call arguments are never lvalues
7929
7930 when N_Function_Call =>
7931 return False;
7932
7933 -- Positional parameter for procedure or accept call
7934
7935 when N_Procedure_Call_Statement |
7936 N_Accept_Statement
7937 =>
7938 declare
7939 Proc : Entity_Id;
7940 Form : Entity_Id;
7941 Act : Node_Id;
7942
7943 begin
7944 Proc := Get_Subprogram_Entity (P);
7945
7946 if No (Proc) then
7947 return False;
7948 end if;
7949
7950 -- If we are not a list member, something is strange, so
7951 -- be conservative and return False.
7952
7953 if not Is_List_Member (N) then
7954 return False;
7955 end if;
7956
7957 -- We are going to find the right formal by stepping forward
7958 -- through the formals, as we step backwards in the actuals.
7959
7960 Form := First_Formal (Proc);
7961 Act := N;
7962 loop
7963 -- If no formal, something is weird, so be conservative
7964 -- and return False.
7965
7966 if No (Form) then
7967 return False;
7968 end if;
7969
7970 Prev (Act);
7971 exit when No (Act);
7972 Next_Formal (Form);
7973 end loop;
7974
7975 return Ekind (Form) /= E_In_Parameter;
7976 end;
7977
7978 -- Named parameter for procedure or accept call
7979
7980 when N_Parameter_Association =>
7981 declare
7982 Proc : Entity_Id;
7983 Form : Entity_Id;
7984
7985 begin
7986 Proc := Get_Subprogram_Entity (Parent (P));
7987
7988 if No (Proc) then
7989 return False;
7990 end if;
7991
7992 -- Loop through formals to find the one that matches
7993
7994 Form := First_Formal (Proc);
7995 loop
7996 -- If no matching formal, that's peculiar, some kind of
7997 -- previous error, so return False to be conservative.
7998
7999 if No (Form) then
8000 return False;
8001 end if;
8002
8003 -- Else test for match
8004
8005 if Chars (Form) = Chars (Selector_Name (P)) then
8006 return Ekind (Form) /= E_In_Parameter;
8007 end if;
8008
8009 Next_Formal (Form);
8010 end loop;
8011 end;
8012
8013 -- Test for appearing in a conversion that itself appears
8014 -- in an lvalue context, since this should be an lvalue.
8015
8016 when N_Type_Conversion =>
8017 return Known_To_Be_Assigned (P);
8018
8019 -- All other references are definitely not known to be modifications
8020
8021 when others =>
8022 return False;
8023
8024 end case;
8025 end Known_To_Be_Assigned;
8026
8027 ---------------------------
8028 -- Last_Source_Statement --
8029 ---------------------------
8030
8031 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
8032 N : Node_Id;
8033
8034 begin
8035 N := Last (Statements (HSS));
8036 while Present (N) loop
8037 exit when Comes_From_Source (N);
8038 Prev (N);
8039 end loop;
8040
8041 return N;
8042 end Last_Source_Statement;
8043
8044 ----------------------------------
8045 -- Matching_Static_Array_Bounds --
8046 ----------------------------------
8047
8048 function Matching_Static_Array_Bounds
8049 (L_Typ : Node_Id;
8050 R_Typ : Node_Id) return Boolean
8051 is
8052 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
8053 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
8054
8055 L_Index : Node_Id;
8056 R_Index : Node_Id;
8057 L_Low : Node_Id;
8058 L_High : Node_Id;
8059 L_Len : Uint;
8060 R_Low : Node_Id;
8061 R_High : Node_Id;
8062 R_Len : Uint;
8063
8064 begin
8065 if L_Ndims /= R_Ndims then
8066 return False;
8067 end if;
8068
8069 -- Unconstrained types do not have static bounds
8070
8071 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
8072 return False;
8073 end if;
8074
8075 -- First treat specially the first dimension, as the lower bound and
8076 -- length of string literals are not stored like those of arrays.
8077
8078 if Ekind (L_Typ) = E_String_Literal_Subtype then
8079 L_Low := String_Literal_Low_Bound (L_Typ);
8080 L_Len := String_Literal_Length (L_Typ);
8081 else
8082 L_Index := First_Index (L_Typ);
8083 Get_Index_Bounds (L_Index, L_Low, L_High);
8084
8085 if Is_OK_Static_Expression (L_Low)
8086 and then Is_OK_Static_Expression (L_High)
8087 then
8088 if Expr_Value (L_High) < Expr_Value (L_Low) then
8089 L_Len := Uint_0;
8090 else
8091 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
8092 end if;
8093 else
8094 return False;
8095 end if;
8096 end if;
8097
8098 if Ekind (R_Typ) = E_String_Literal_Subtype then
8099 R_Low := String_Literal_Low_Bound (R_Typ);
8100 R_Len := String_Literal_Length (R_Typ);
8101 else
8102 R_Index := First_Index (R_Typ);
8103 Get_Index_Bounds (R_Index, R_Low, R_High);
8104
8105 if Is_OK_Static_Expression (R_Low)
8106 and then Is_OK_Static_Expression (R_High)
8107 then
8108 if Expr_Value (R_High) < Expr_Value (R_Low) then
8109 R_Len := Uint_0;
8110 else
8111 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
8112 end if;
8113 else
8114 return False;
8115 end if;
8116 end if;
8117
8118 if Is_OK_Static_Expression (L_Low)
8119 and then Is_OK_Static_Expression (R_Low)
8120 and then Expr_Value (L_Low) = Expr_Value (R_Low)
8121 and then L_Len = R_Len
8122 then
8123 null;
8124 else
8125 return False;
8126 end if;
8127
8128 -- Then treat all other dimensions
8129
8130 for Indx in 2 .. L_Ndims loop
8131 Next (L_Index);
8132 Next (R_Index);
8133
8134 Get_Index_Bounds (L_Index, L_Low, L_High);
8135 Get_Index_Bounds (R_Index, R_Low, R_High);
8136
8137 if Is_OK_Static_Expression (L_Low)
8138 and then Is_OK_Static_Expression (L_High)
8139 and then Is_OK_Static_Expression (R_Low)
8140 and then Is_OK_Static_Expression (R_High)
8141 and then Expr_Value (L_Low) = Expr_Value (R_Low)
8142 and then Expr_Value (L_High) = Expr_Value (R_High)
8143 then
8144 null;
8145 else
8146 return False;
8147 end if;
8148 end loop;
8149
8150 -- If we fall through the loop, all indexes matched
8151
8152 return True;
8153 end Matching_Static_Array_Bounds;
8154
8155 -------------------
8156 -- May_Be_Lvalue --
8157 -------------------
8158
8159 function May_Be_Lvalue (N : Node_Id) return Boolean is
8160 P : constant Node_Id := Parent (N);
8161
8162 begin
8163 case Nkind (P) is
8164
8165 -- Test left side of assignment
8166
8167 when N_Assignment_Statement =>
8168 return N = Name (P);
8169
8170 -- Test prefix of component or attribute. Note that the prefix of an
8171 -- explicit or implicit dereference cannot be an l-value.
8172
8173 when N_Attribute_Reference =>
8174 return N = Prefix (P)
8175 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
8176
8177 -- For an expanded name, the name is an lvalue if the expanded name
8178 -- is an lvalue, but the prefix is never an lvalue, since it is just
8179 -- the scope where the name is found.
8180
8181 when N_Expanded_Name =>
8182 if N = Prefix (P) then
8183 return May_Be_Lvalue (P);
8184 else
8185 return False;
8186 end if;
8187
8188 -- For a selected component A.B, A is certainly an lvalue if A.B is.
8189 -- B is a little interesting, if we have A.B := 3, there is some
8190 -- discussion as to whether B is an lvalue or not, we choose to say
8191 -- it is. Note however that A is not an lvalue if it is of an access
8192 -- type since this is an implicit dereference.
8193
8194 when N_Selected_Component =>
8195 if N = Prefix (P)
8196 and then Present (Etype (N))
8197 and then Is_Access_Type (Etype (N))
8198 then
8199 return False;
8200 else
8201 return May_Be_Lvalue (P);
8202 end if;
8203
8204 -- For an indexed component or slice, the index or slice bounds is
8205 -- never an lvalue. The prefix is an lvalue if the indexed component
8206 -- or slice is an lvalue, except if it is an access type, where we
8207 -- have an implicit dereference.
8208
8209 when N_Indexed_Component =>
8210 if N /= Prefix (P)
8211 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
8212 then
8213 return False;
8214 else
8215 return May_Be_Lvalue (P);
8216 end if;
8217
8218 -- Prefix of a reference is an lvalue if the reference is an lvalue
8219
8220 when N_Reference =>
8221 return May_Be_Lvalue (P);
8222
8223 -- Prefix of explicit dereference is never an lvalue
8224
8225 when N_Explicit_Dereference =>
8226 return False;
8227
8228 -- Positional parameter for subprogram, entry, or accept call.
8229 -- In older versions of Ada function call arguments are never
8230 -- lvalues. In Ada 2012 functions can have in-out parameters.
8231
8232 when N_Function_Call |
8233 N_Procedure_Call_Statement |
8234 N_Entry_Call_Statement |
8235 N_Accept_Statement
8236 =>
8237 if Nkind (P) = N_Function_Call
8238 and then Ada_Version < Ada_2012
8239 then
8240 return False;
8241 end if;
8242
8243 -- The following mechanism is clumsy and fragile. A single
8244 -- flag set in Resolve_Actuals would be preferable ???
8245
8246 declare
8247 Proc : Entity_Id;
8248 Form : Entity_Id;
8249 Act : Node_Id;
8250
8251 begin
8252 Proc := Get_Subprogram_Entity (P);
8253
8254 if No (Proc) then
8255 return True;
8256 end if;
8257
8258 -- If we are not a list member, something is strange, so
8259 -- be conservative and return True.
8260
8261 if not Is_List_Member (N) then
8262 return True;
8263 end if;
8264
8265 -- We are going to find the right formal by stepping forward
8266 -- through the formals, as we step backwards in the actuals.
8267
8268 Form := First_Formal (Proc);
8269 Act := N;
8270 loop
8271 -- If no formal, something is weird, so be conservative
8272 -- and return True.
8273
8274 if No (Form) then
8275 return True;
8276 end if;
8277
8278 Prev (Act);
8279 exit when No (Act);
8280 Next_Formal (Form);
8281 end loop;
8282
8283 return Ekind (Form) /= E_In_Parameter;
8284 end;
8285
8286 -- Named parameter for procedure or accept call
8287
8288 when N_Parameter_Association =>
8289 declare
8290 Proc : Entity_Id;
8291 Form : Entity_Id;
8292
8293 begin
8294 Proc := Get_Subprogram_Entity (Parent (P));
8295
8296 if No (Proc) then
8297 return True;
8298 end if;
8299
8300 -- Loop through formals to find the one that matches
8301
8302 Form := First_Formal (Proc);
8303 loop
8304 -- If no matching formal, that's peculiar, some kind of
8305 -- previous error, so return True to be conservative.
8306
8307 if No (Form) then
8308 return True;
8309 end if;
8310
8311 -- Else test for match
8312
8313 if Chars (Form) = Chars (Selector_Name (P)) then
8314 return Ekind (Form) /= E_In_Parameter;
8315 end if;
8316
8317 Next_Formal (Form);
8318 end loop;
8319 end;
8320
8321 -- Test for appearing in a conversion that itself appears in an
8322 -- lvalue context, since this should be an lvalue.
8323
8324 when N_Type_Conversion =>
8325 return May_Be_Lvalue (P);
8326
8327 -- Test for appearance in object renaming declaration
8328
8329 when N_Object_Renaming_Declaration =>
8330 return True;
8331
8332 -- All other references are definitely not lvalues
8333
8334 when others =>
8335 return False;
8336
8337 end case;
8338 end May_Be_Lvalue;
8339
8340 -----------------------
8341 -- Mark_Coextensions --
8342 -----------------------
8343
8344 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
8345 Is_Dynamic : Boolean;
8346 -- Indicates whether the context causes nested coextensions to be
8347 -- dynamic or static
8348
8349 function Mark_Allocator (N : Node_Id) return Traverse_Result;
8350 -- Recognize an allocator node and label it as a dynamic coextension
8351
8352 --------------------
8353 -- Mark_Allocator --
8354 --------------------
8355
8356 function Mark_Allocator (N : Node_Id) return Traverse_Result is
8357 begin
8358 if Nkind (N) = N_Allocator then
8359 if Is_Dynamic then
8360 Set_Is_Dynamic_Coextension (N);
8361
8362 -- If the allocator expression is potentially dynamic, it may
8363 -- be expanded out of order and require dynamic allocation
8364 -- anyway, so we treat the coextension itself as dynamic.
8365 -- Potential optimization ???
8366
8367 elsif Nkind (Expression (N)) = N_Qualified_Expression
8368 and then Nkind (Expression (Expression (N))) = N_Op_Concat
8369 then
8370 Set_Is_Dynamic_Coextension (N);
8371
8372 else
8373 Set_Is_Static_Coextension (N);
8374 end if;
8375 end if;
8376
8377 return OK;
8378 end Mark_Allocator;
8379
8380 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
8381
8382 -- Start of processing Mark_Coextensions
8383
8384 begin
8385 case Nkind (Context_Nod) is
8386 when N_Assignment_Statement |
8387 N_Simple_Return_Statement =>
8388 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
8389
8390 when N_Object_Declaration =>
8391 Is_Dynamic := Nkind (Root_Nod) = N_Allocator;
8392
8393 -- This routine should not be called for constructs which may not
8394 -- contain coextensions.
8395
8396 when others =>
8397 raise Program_Error;
8398 end case;
8399
8400 Mark_Allocators (Root_Nod);
8401 end Mark_Coextensions;
8402
8403 ----------------------
8404 -- Needs_One_Actual --
8405 ----------------------
8406
8407 function Needs_One_Actual (E : Entity_Id) return Boolean is
8408 Formal : Entity_Id;
8409
8410 begin
8411 if Ada_Version >= Ada_2005
8412 and then Present (First_Formal (E))
8413 then
8414 Formal := Next_Formal (First_Formal (E));
8415 while Present (Formal) loop
8416 if No (Default_Value (Formal)) then
8417 return False;
8418 end if;
8419
8420 Next_Formal (Formal);
8421 end loop;
8422
8423 return True;
8424
8425 else
8426 return False;
8427 end if;
8428 end Needs_One_Actual;
8429
8430 ------------------------
8431 -- New_Copy_List_Tree --
8432 ------------------------
8433
8434 function New_Copy_List_Tree (List : List_Id) return List_Id is
8435 NL : List_Id;
8436 E : Node_Id;
8437
8438 begin
8439 if List = No_List then
8440 return No_List;
8441
8442 else
8443 NL := New_List;
8444 E := First (List);
8445
8446 while Present (E) loop
8447 Append (New_Copy_Tree (E), NL);
8448 E := Next (E);
8449 end loop;
8450
8451 return NL;
8452 end if;
8453 end New_Copy_List_Tree;
8454
8455 -------------------
8456 -- New_Copy_Tree --
8457 -------------------
8458
8459 use Atree.Unchecked_Access;
8460 use Atree_Private_Part;
8461
8462 -- Our approach here requires a two pass traversal of the tree. The
8463 -- first pass visits all nodes that eventually will be copied looking
8464 -- for defining Itypes. If any defining Itypes are found, then they are
8465 -- copied, and an entry is added to the replacement map. In the second
8466 -- phase, the tree is copied, using the replacement map to replace any
8467 -- Itype references within the copied tree.
8468
8469 -- The following hash tables are used if the Map supplied has more
8470 -- than hash threshold entries to speed up access to the map. If
8471 -- there are fewer entries, then the map is searched sequentially
8472 -- (because setting up a hash table for only a few entries takes
8473 -- more time than it saves.
8474
8475 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
8476 -- Hash function used for hash operations
8477
8478 -------------------
8479 -- New_Copy_Hash --
8480 -------------------
8481
8482 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
8483 begin
8484 return Nat (E) mod (NCT_Header_Num'Last + 1);
8485 end New_Copy_Hash;
8486
8487 ---------------
8488 -- NCT_Assoc --
8489 ---------------
8490
8491 -- The hash table NCT_Assoc associates old entities in the table
8492 -- with their corresponding new entities (i.e. the pairs of entries
8493 -- presented in the original Map argument are Key-Element pairs).
8494
8495 package NCT_Assoc is new Simple_HTable (
8496 Header_Num => NCT_Header_Num,
8497 Element => Entity_Id,
8498 No_Element => Empty,
8499 Key => Entity_Id,
8500 Hash => New_Copy_Hash,
8501 Equal => Types."=");
8502
8503 ---------------------
8504 -- NCT_Itype_Assoc --
8505 ---------------------
8506
8507 -- The hash table NCT_Itype_Assoc contains entries only for those
8508 -- old nodes which have a non-empty Associated_Node_For_Itype set.
8509 -- The key is the associated node, and the element is the new node
8510 -- itself (NOT the associated node for the new node).
8511
8512 package NCT_Itype_Assoc is new Simple_HTable (
8513 Header_Num => NCT_Header_Num,
8514 Element => Entity_Id,
8515 No_Element => Empty,
8516 Key => Entity_Id,
8517 Hash => New_Copy_Hash,
8518 Equal => Types."=");
8519
8520 -- Start of processing for New_Copy_Tree function
8521
8522 function New_Copy_Tree
8523 (Source : Node_Id;
8524 Map : Elist_Id := No_Elist;
8525 New_Sloc : Source_Ptr := No_Location;
8526 New_Scope : Entity_Id := Empty) return Node_Id
8527 is
8528 Actual_Map : Elist_Id := Map;
8529 -- This is the actual map for the copy. It is initialized with the
8530 -- given elements, and then enlarged as required for Itypes that are
8531 -- copied during the first phase of the copy operation. The visit
8532 -- procedures add elements to this map as Itypes are encountered.
8533 -- The reason we cannot use Map directly, is that it may well be
8534 -- (and normally is) initialized to No_Elist, and if we have mapped
8535 -- entities, we have to reset it to point to a real Elist.
8536
8537 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
8538 -- Called during second phase to map entities into their corresponding
8539 -- copies using Actual_Map. If the argument is not an entity, or is not
8540 -- in Actual_Map, then it is returned unchanged.
8541
8542 procedure Build_NCT_Hash_Tables;
8543 -- Builds hash tables (number of elements >= threshold value)
8544
8545 function Copy_Elist_With_Replacement
8546 (Old_Elist : Elist_Id) return Elist_Id;
8547 -- Called during second phase to copy element list doing replacements
8548
8549 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
8550 -- Called during the second phase to process a copied Itype. The actual
8551 -- copy happened during the first phase (so that we could make the entry
8552 -- in the mapping), but we still have to deal with the descendents of
8553 -- the copied Itype and copy them where necessary.
8554
8555 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
8556 -- Called during second phase to copy list doing replacements
8557
8558 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
8559 -- Called during second phase to copy node doing replacements
8560
8561 procedure Visit_Elist (E : Elist_Id);
8562 -- Called during first phase to visit all elements of an Elist
8563
8564 procedure Visit_Field (F : Union_Id; N : Node_Id);
8565 -- Visit a single field, recursing to call Visit_Node or Visit_List
8566 -- if the field is a syntactic descendent of the current node (i.e.
8567 -- its parent is Node N).
8568
8569 procedure Visit_Itype (Old_Itype : Entity_Id);
8570 -- Called during first phase to visit subsidiary fields of a defining
8571 -- Itype, and also create a copy and make an entry in the replacement
8572 -- map for the new copy.
8573
8574 procedure Visit_List (L : List_Id);
8575 -- Called during first phase to visit all elements of a List
8576
8577 procedure Visit_Node (N : Node_Or_Entity_Id);
8578 -- Called during first phase to visit a node and all its subtrees
8579
8580 -----------
8581 -- Assoc --
8582 -----------
8583
8584 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
8585 E : Elmt_Id;
8586 Ent : Entity_Id;
8587
8588 begin
8589 if not Has_Extension (N) or else No (Actual_Map) then
8590 return N;
8591
8592 elsif NCT_Hash_Tables_Used then
8593 Ent := NCT_Assoc.Get (Entity_Id (N));
8594
8595 if Present (Ent) then
8596 return Ent;
8597 else
8598 return N;
8599 end if;
8600
8601 -- No hash table used, do serial search
8602
8603 else
8604 E := First_Elmt (Actual_Map);
8605 while Present (E) loop
8606 if Node (E) = N then
8607 return Node (Next_Elmt (E));
8608 else
8609 E := Next_Elmt (Next_Elmt (E));
8610 end if;
8611 end loop;
8612 end if;
8613
8614 return N;
8615 end Assoc;
8616
8617 ---------------------------
8618 -- Build_NCT_Hash_Tables --
8619 ---------------------------
8620
8621 procedure Build_NCT_Hash_Tables is
8622 Elmt : Elmt_Id;
8623 Ent : Entity_Id;
8624 begin
8625 if NCT_Hash_Table_Setup then
8626 NCT_Assoc.Reset;
8627 NCT_Itype_Assoc.Reset;
8628 end if;
8629
8630 Elmt := First_Elmt (Actual_Map);
8631 while Present (Elmt) loop
8632 Ent := Node (Elmt);
8633
8634 -- Get new entity, and associate old and new
8635
8636 Next_Elmt (Elmt);
8637 NCT_Assoc.Set (Ent, Node (Elmt));
8638
8639 if Is_Type (Ent) then
8640 declare
8641 Anode : constant Entity_Id :=
8642 Associated_Node_For_Itype (Ent);
8643
8644 begin
8645 if Present (Anode) then
8646
8647 -- Enter a link between the associated node of the
8648 -- old Itype and the new Itype, for updating later
8649 -- when node is copied.
8650
8651 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
8652 end if;
8653 end;
8654 end if;
8655
8656 Next_Elmt (Elmt);
8657 end loop;
8658
8659 NCT_Hash_Tables_Used := True;
8660 NCT_Hash_Table_Setup := True;
8661 end Build_NCT_Hash_Tables;
8662
8663 ---------------------------------
8664 -- Copy_Elist_With_Replacement --
8665 ---------------------------------
8666
8667 function Copy_Elist_With_Replacement
8668 (Old_Elist : Elist_Id) return Elist_Id
8669 is
8670 M : Elmt_Id;
8671 New_Elist : Elist_Id;
8672
8673 begin
8674 if No (Old_Elist) then
8675 return No_Elist;
8676
8677 else
8678 New_Elist := New_Elmt_List;
8679
8680 M := First_Elmt (Old_Elist);
8681 while Present (M) loop
8682 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
8683 Next_Elmt (M);
8684 end loop;
8685 end if;
8686
8687 return New_Elist;
8688 end Copy_Elist_With_Replacement;
8689
8690 ---------------------------------
8691 -- Copy_Itype_With_Replacement --
8692 ---------------------------------
8693
8694 -- This routine exactly parallels its phase one analog Visit_Itype,
8695
8696 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
8697 begin
8698 -- Translate Next_Entity, Scope and Etype fields, in case they
8699 -- reference entities that have been mapped into copies.
8700
8701 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
8702 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
8703
8704 if Present (New_Scope) then
8705 Set_Scope (New_Itype, New_Scope);
8706 else
8707 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
8708 end if;
8709
8710 -- Copy referenced fields
8711
8712 if Is_Discrete_Type (New_Itype) then
8713 Set_Scalar_Range (New_Itype,
8714 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
8715
8716 elsif Has_Discriminants (Base_Type (New_Itype)) then
8717 Set_Discriminant_Constraint (New_Itype,
8718 Copy_Elist_With_Replacement
8719 (Discriminant_Constraint (New_Itype)));
8720
8721 elsif Is_Array_Type (New_Itype) then
8722 if Present (First_Index (New_Itype)) then
8723 Set_First_Index (New_Itype,
8724 First (Copy_List_With_Replacement
8725 (List_Containing (First_Index (New_Itype)))));
8726 end if;
8727
8728 if Is_Packed (New_Itype) then
8729 Set_Packed_Array_Type (New_Itype,
8730 Copy_Node_With_Replacement
8731 (Packed_Array_Type (New_Itype)));
8732 end if;
8733 end if;
8734 end Copy_Itype_With_Replacement;
8735
8736 --------------------------------
8737 -- Copy_List_With_Replacement --
8738 --------------------------------
8739
8740 function Copy_List_With_Replacement
8741 (Old_List : List_Id) return List_Id
8742 is
8743 New_List : List_Id;
8744 E : Node_Id;
8745
8746 begin
8747 if Old_List = No_List then
8748 return No_List;
8749
8750 else
8751 New_List := Empty_List;
8752
8753 E := First (Old_List);
8754 while Present (E) loop
8755 Append (Copy_Node_With_Replacement (E), New_List);
8756 Next (E);
8757 end loop;
8758
8759 return New_List;
8760 end if;
8761 end Copy_List_With_Replacement;
8762
8763 --------------------------------
8764 -- Copy_Node_With_Replacement --
8765 --------------------------------
8766
8767 function Copy_Node_With_Replacement
8768 (Old_Node : Node_Id) return Node_Id
8769 is
8770 New_Node : Node_Id;
8771
8772 procedure Adjust_Named_Associations
8773 (Old_Node : Node_Id;
8774 New_Node : Node_Id);
8775 -- If a call node has named associations, these are chained through
8776 -- the First_Named_Actual, Next_Named_Actual links. These must be
8777 -- propagated separately to the new parameter list, because these
8778 -- are not syntactic fields.
8779
8780 function Copy_Field_With_Replacement
8781 (Field : Union_Id) return Union_Id;
8782 -- Given Field, which is a field of Old_Node, return a copy of it
8783 -- if it is a syntactic field (i.e. its parent is Node), setting
8784 -- the parent of the copy to poit to New_Node. Otherwise returns
8785 -- the field (possibly mapped if it is an entity).
8786
8787 -------------------------------
8788 -- Adjust_Named_Associations --
8789 -------------------------------
8790
8791 procedure Adjust_Named_Associations
8792 (Old_Node : Node_Id;
8793 New_Node : Node_Id)
8794 is
8795 Old_E : Node_Id;
8796 New_E : Node_Id;
8797
8798 Old_Next : Node_Id;
8799 New_Next : Node_Id;
8800
8801 begin
8802 Old_E := First (Parameter_Associations (Old_Node));
8803 New_E := First (Parameter_Associations (New_Node));
8804 while Present (Old_E) loop
8805 if Nkind (Old_E) = N_Parameter_Association
8806 and then Present (Next_Named_Actual (Old_E))
8807 then
8808 if First_Named_Actual (Old_Node)
8809 = Explicit_Actual_Parameter (Old_E)
8810 then
8811 Set_First_Named_Actual
8812 (New_Node, Explicit_Actual_Parameter (New_E));
8813 end if;
8814
8815 -- Now scan parameter list from the beginning,to locate
8816 -- next named actual, which can be out of order.
8817
8818 Old_Next := First (Parameter_Associations (Old_Node));
8819 New_Next := First (Parameter_Associations (New_Node));
8820
8821 while Nkind (Old_Next) /= N_Parameter_Association
8822 or else Explicit_Actual_Parameter (Old_Next)
8823 /= Next_Named_Actual (Old_E)
8824 loop
8825 Next (Old_Next);
8826 Next (New_Next);
8827 end loop;
8828
8829 Set_Next_Named_Actual
8830 (New_E, Explicit_Actual_Parameter (New_Next));
8831 end if;
8832
8833 Next (Old_E);
8834 Next (New_E);
8835 end loop;
8836 end Adjust_Named_Associations;
8837
8838 ---------------------------------
8839 -- Copy_Field_With_Replacement --
8840 ---------------------------------
8841
8842 function Copy_Field_With_Replacement
8843 (Field : Union_Id) return Union_Id
8844 is
8845 begin
8846 if Field = Union_Id (Empty) then
8847 return Field;
8848
8849 elsif Field in Node_Range then
8850 declare
8851 Old_N : constant Node_Id := Node_Id (Field);
8852 New_N : Node_Id;
8853
8854 begin
8855 -- If syntactic field, as indicated by the parent pointer
8856 -- being set, then copy the referenced node recursively.
8857
8858 if Parent (Old_N) = Old_Node then
8859 New_N := Copy_Node_With_Replacement (Old_N);
8860
8861 if New_N /= Old_N then
8862 Set_Parent (New_N, New_Node);
8863 end if;
8864
8865 -- For semantic fields, update possible entity reference
8866 -- from the replacement map.
8867
8868 else
8869 New_N := Assoc (Old_N);
8870 end if;
8871
8872 return Union_Id (New_N);
8873 end;
8874
8875 elsif Field in List_Range then
8876 declare
8877 Old_L : constant List_Id := List_Id (Field);
8878 New_L : List_Id;
8879
8880 begin
8881 -- If syntactic field, as indicated by the parent pointer,
8882 -- then recursively copy the entire referenced list.
8883
8884 if Parent (Old_L) = Old_Node then
8885 New_L := Copy_List_With_Replacement (Old_L);
8886 Set_Parent (New_L, New_Node);
8887
8888 -- For semantic list, just returned unchanged
8889
8890 else
8891 New_L := Old_L;
8892 end if;
8893
8894 return Union_Id (New_L);
8895 end;
8896
8897 -- Anything other than a list or a node is returned unchanged
8898
8899 else
8900 return Field;
8901 end if;
8902 end Copy_Field_With_Replacement;
8903
8904 -- Start of processing for Copy_Node_With_Replacement
8905
8906 begin
8907 if Old_Node <= Empty_Or_Error then
8908 return Old_Node;
8909
8910 elsif Has_Extension (Old_Node) then
8911 return Assoc (Old_Node);
8912
8913 else
8914 New_Node := New_Copy (Old_Node);
8915
8916 -- If the node we are copying is the associated node of a
8917 -- previously copied Itype, then adjust the associated node
8918 -- of the copy of that Itype accordingly.
8919
8920 if Present (Actual_Map) then
8921 declare
8922 E : Elmt_Id;
8923 Ent : Entity_Id;
8924
8925 begin
8926 -- Case of hash table used
8927
8928 if NCT_Hash_Tables_Used then
8929 Ent := NCT_Itype_Assoc.Get (Old_Node);
8930
8931 if Present (Ent) then
8932 Set_Associated_Node_For_Itype (Ent, New_Node);
8933 end if;
8934
8935 -- Case of no hash table used
8936
8937 else
8938 E := First_Elmt (Actual_Map);
8939 while Present (E) loop
8940 if Is_Itype (Node (E))
8941 and then
8942 Old_Node = Associated_Node_For_Itype (Node (E))
8943 then
8944 Set_Associated_Node_For_Itype
8945 (Node (Next_Elmt (E)), New_Node);
8946 end if;
8947
8948 E := Next_Elmt (Next_Elmt (E));
8949 end loop;
8950 end if;
8951 end;
8952 end if;
8953
8954 -- Recursively copy descendents
8955
8956 Set_Field1
8957 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
8958 Set_Field2
8959 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
8960 Set_Field3
8961 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
8962 Set_Field4
8963 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
8964 Set_Field5
8965 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
8966
8967 -- Adjust Sloc of new node if necessary
8968
8969 if New_Sloc /= No_Location then
8970 Set_Sloc (New_Node, New_Sloc);
8971
8972 -- If we adjust the Sloc, then we are essentially making
8973 -- a completely new node, so the Comes_From_Source flag
8974 -- should be reset to the proper default value.
8975
8976 Nodes.Table (New_Node).Comes_From_Source :=
8977 Default_Node.Comes_From_Source;
8978 end if;
8979
8980 -- If the node is call and has named associations,
8981 -- set the corresponding links in the copy.
8982
8983 if (Nkind (Old_Node) = N_Function_Call
8984 or else Nkind (Old_Node) = N_Entry_Call_Statement
8985 or else
8986 Nkind (Old_Node) = N_Procedure_Call_Statement)
8987 and then Present (First_Named_Actual (Old_Node))
8988 then
8989 Adjust_Named_Associations (Old_Node, New_Node);
8990 end if;
8991
8992 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
8993 -- The replacement mechanism applies to entities, and is not used
8994 -- here. Eventually we may need a more general graph-copying
8995 -- routine. For now, do a sequential search to find desired node.
8996
8997 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
8998 and then Present (First_Real_Statement (Old_Node))
8999 then
9000 declare
9001 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
9002 N1, N2 : Node_Id;
9003
9004 begin
9005 N1 := First (Statements (Old_Node));
9006 N2 := First (Statements (New_Node));
9007
9008 while N1 /= Old_F loop
9009 Next (N1);
9010 Next (N2);
9011 end loop;
9012
9013 Set_First_Real_Statement (New_Node, N2);
9014 end;
9015 end if;
9016 end if;
9017
9018 -- All done, return copied node
9019
9020 return New_Node;
9021 end Copy_Node_With_Replacement;
9022
9023 -----------------
9024 -- Visit_Elist --
9025 -----------------
9026
9027 procedure Visit_Elist (E : Elist_Id) is
9028 Elmt : Elmt_Id;
9029 begin
9030 if Present (E) then
9031 Elmt := First_Elmt (E);
9032
9033 while Elmt /= No_Elmt loop
9034 Visit_Node (Node (Elmt));
9035 Next_Elmt (Elmt);
9036 end loop;
9037 end if;
9038 end Visit_Elist;
9039
9040 -----------------
9041 -- Visit_Field --
9042 -----------------
9043
9044 procedure Visit_Field (F : Union_Id; N : Node_Id) is
9045 begin
9046 if F = Union_Id (Empty) then
9047 return;
9048
9049 elsif F in Node_Range then
9050
9051 -- Copy node if it is syntactic, i.e. its parent pointer is
9052 -- set to point to the field that referenced it (certain
9053 -- Itypes will also meet this criterion, which is fine, since
9054 -- these are clearly Itypes that do need to be copied, since
9055 -- we are copying their parent.)
9056
9057 if Parent (Node_Id (F)) = N then
9058 Visit_Node (Node_Id (F));
9059 return;
9060
9061 -- Another case, if we are pointing to an Itype, then we want
9062 -- to copy it if its associated node is somewhere in the tree
9063 -- being copied.
9064
9065 -- Note: the exclusion of self-referential copies is just an
9066 -- optimization, since the search of the already copied list
9067 -- would catch it, but it is a common case (Etype pointing
9068 -- to itself for an Itype that is a base type).
9069
9070 elsif Has_Extension (Node_Id (F))
9071 and then Is_Itype (Entity_Id (F))
9072 and then Node_Id (F) /= N
9073 then
9074 declare
9075 P : Node_Id;
9076
9077 begin
9078 P := Associated_Node_For_Itype (Node_Id (F));
9079 while Present (P) loop
9080 if P = Source then
9081 Visit_Node (Node_Id (F));
9082 return;
9083 else
9084 P := Parent (P);
9085 end if;
9086 end loop;
9087
9088 -- An Itype whose parent is not being copied definitely
9089 -- should NOT be copied, since it does not belong in any
9090 -- sense to the copied subtree.
9091
9092 return;
9093 end;
9094 end if;
9095
9096 elsif F in List_Range
9097 and then Parent (List_Id (F)) = N
9098 then
9099 Visit_List (List_Id (F));
9100 return;
9101 end if;
9102 end Visit_Field;
9103
9104 -----------------
9105 -- Visit_Itype --
9106 -----------------
9107
9108 procedure Visit_Itype (Old_Itype : Entity_Id) is
9109 New_Itype : Entity_Id;
9110 E : Elmt_Id;
9111 Ent : Entity_Id;
9112
9113 begin
9114 -- Itypes that describe the designated type of access to subprograms
9115 -- have the structure of subprogram declarations, with signatures,
9116 -- etc. Either we duplicate the signatures completely, or choose to
9117 -- share such itypes, which is fine because their elaboration will
9118 -- have no side effects.
9119
9120 if Ekind (Old_Itype) = E_Subprogram_Type then
9121 return;
9122 end if;
9123
9124 New_Itype := New_Copy (Old_Itype);
9125
9126 -- The new Itype has all the attributes of the old one, and
9127 -- we just copy the contents of the entity. However, the back-end
9128 -- needs different names for debugging purposes, so we create a
9129 -- new internal name for it in all cases.
9130
9131 Set_Chars (New_Itype, New_Internal_Name ('T'));
9132
9133 -- If our associated node is an entity that has already been copied,
9134 -- then set the associated node of the copy to point to the right
9135 -- copy. If we have copied an Itype that is itself the associated
9136 -- node of some previously copied Itype, then we set the right
9137 -- pointer in the other direction.
9138
9139 if Present (Actual_Map) then
9140
9141 -- Case of hash tables used
9142
9143 if NCT_Hash_Tables_Used then
9144
9145 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
9146
9147 if Present (Ent) then
9148 Set_Associated_Node_For_Itype (New_Itype, Ent);
9149 end if;
9150
9151 Ent := NCT_Itype_Assoc.Get (Old_Itype);
9152 if Present (Ent) then
9153 Set_Associated_Node_For_Itype (Ent, New_Itype);
9154
9155 -- If the hash table has no association for this Itype and
9156 -- its associated node, enter one now.
9157
9158 else
9159 NCT_Itype_Assoc.Set
9160 (Associated_Node_For_Itype (Old_Itype), New_Itype);
9161 end if;
9162
9163 -- Case of hash tables not used
9164
9165 else
9166 E := First_Elmt (Actual_Map);
9167 while Present (E) loop
9168 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
9169 Set_Associated_Node_For_Itype
9170 (New_Itype, Node (Next_Elmt (E)));
9171 end if;
9172
9173 if Is_Type (Node (E))
9174 and then
9175 Old_Itype = Associated_Node_For_Itype (Node (E))
9176 then
9177 Set_Associated_Node_For_Itype
9178 (Node (Next_Elmt (E)), New_Itype);
9179 end if;
9180
9181 E := Next_Elmt (Next_Elmt (E));
9182 end loop;
9183 end if;
9184 end if;
9185
9186 if Present (Freeze_Node (New_Itype)) then
9187 Set_Is_Frozen (New_Itype, False);
9188 Set_Freeze_Node (New_Itype, Empty);
9189 end if;
9190
9191 -- Add new association to map
9192
9193 if No (Actual_Map) then
9194 Actual_Map := New_Elmt_List;
9195 end if;
9196
9197 Append_Elmt (Old_Itype, Actual_Map);
9198 Append_Elmt (New_Itype, Actual_Map);
9199
9200 if NCT_Hash_Tables_Used then
9201 NCT_Assoc.Set (Old_Itype, New_Itype);
9202
9203 else
9204 NCT_Table_Entries := NCT_Table_Entries + 1;
9205
9206 if NCT_Table_Entries > NCT_Hash_Threshold then
9207 Build_NCT_Hash_Tables;
9208 end if;
9209 end if;
9210
9211 -- If a record subtype is simply copied, the entity list will be
9212 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
9213
9214 if Ekind_In (Old_Itype, E_Record_Subtype, E_Class_Wide_Subtype) then
9215 Set_Cloned_Subtype (New_Itype, Old_Itype);
9216 end if;
9217
9218 -- Visit descendents that eventually get copied
9219
9220 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
9221
9222 if Is_Discrete_Type (Old_Itype) then
9223 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
9224
9225 elsif Has_Discriminants (Base_Type (Old_Itype)) then
9226 -- ??? This should involve call to Visit_Field
9227 Visit_Elist (Discriminant_Constraint (Old_Itype));
9228
9229 elsif Is_Array_Type (Old_Itype) then
9230 if Present (First_Index (Old_Itype)) then
9231 Visit_Field (Union_Id (List_Containing
9232 (First_Index (Old_Itype))),
9233 Old_Itype);
9234 end if;
9235
9236 if Is_Packed (Old_Itype) then
9237 Visit_Field (Union_Id (Packed_Array_Type (Old_Itype)),
9238 Old_Itype);
9239 end if;
9240 end if;
9241 end Visit_Itype;
9242
9243 ----------------
9244 -- Visit_List --
9245 ----------------
9246
9247 procedure Visit_List (L : List_Id) is
9248 N : Node_Id;
9249 begin
9250 if L /= No_List then
9251 N := First (L);
9252
9253 while Present (N) loop
9254 Visit_Node (N);
9255 Next (N);
9256 end loop;
9257 end if;
9258 end Visit_List;
9259
9260 ----------------
9261 -- Visit_Node --
9262 ----------------
9263
9264 procedure Visit_Node (N : Node_Or_Entity_Id) is
9265
9266 -- Start of processing for Visit_Node
9267
9268 begin
9269 -- Handle case of an Itype, which must be copied
9270
9271 if Has_Extension (N)
9272 and then Is_Itype (N)
9273 then
9274 -- Nothing to do if already in the list. This can happen with an
9275 -- Itype entity that appears more than once in the tree.
9276 -- Note that we do not want to visit descendents in this case.
9277
9278 -- Test for already in list when hash table is used
9279
9280 if NCT_Hash_Tables_Used then
9281 if Present (NCT_Assoc.Get (Entity_Id (N))) then
9282 return;
9283 end if;
9284
9285 -- Test for already in list when hash table not used
9286
9287 else
9288 declare
9289 E : Elmt_Id;
9290 begin
9291 if Present (Actual_Map) then
9292 E := First_Elmt (Actual_Map);
9293 while Present (E) loop
9294 if Node (E) = N then
9295 return;
9296 else
9297 E := Next_Elmt (Next_Elmt (E));
9298 end if;
9299 end loop;
9300 end if;
9301 end;
9302 end if;
9303
9304 Visit_Itype (N);
9305 end if;
9306
9307 -- Visit descendents
9308
9309 Visit_Field (Field1 (N), N);
9310 Visit_Field (Field2 (N), N);
9311 Visit_Field (Field3 (N), N);
9312 Visit_Field (Field4 (N), N);
9313 Visit_Field (Field5 (N), N);
9314 end Visit_Node;
9315
9316 -- Start of processing for New_Copy_Tree
9317
9318 begin
9319 Actual_Map := Map;
9320
9321 -- See if we should use hash table
9322
9323 if No (Actual_Map) then
9324 NCT_Hash_Tables_Used := False;
9325
9326 else
9327 declare
9328 Elmt : Elmt_Id;
9329
9330 begin
9331 NCT_Table_Entries := 0;
9332
9333 Elmt := First_Elmt (Actual_Map);
9334 while Present (Elmt) loop
9335 NCT_Table_Entries := NCT_Table_Entries + 1;
9336 Next_Elmt (Elmt);
9337 Next_Elmt (Elmt);
9338 end loop;
9339
9340 if NCT_Table_Entries > NCT_Hash_Threshold then
9341 Build_NCT_Hash_Tables;
9342 else
9343 NCT_Hash_Tables_Used := False;
9344 end if;
9345 end;
9346 end if;
9347
9348 -- Hash table set up if required, now start phase one by visiting
9349 -- top node (we will recursively visit the descendents).
9350
9351 Visit_Node (Source);
9352
9353 -- Now the second phase of the copy can start. First we process
9354 -- all the mapped entities, copying their descendents.
9355
9356 if Present (Actual_Map) then
9357 declare
9358 Elmt : Elmt_Id;
9359 New_Itype : Entity_Id;
9360 begin
9361 Elmt := First_Elmt (Actual_Map);
9362 while Present (Elmt) loop
9363 Next_Elmt (Elmt);
9364 New_Itype := Node (Elmt);
9365 Copy_Itype_With_Replacement (New_Itype);
9366 Next_Elmt (Elmt);
9367 end loop;
9368 end;
9369 end if;
9370
9371 -- Now we can copy the actual tree
9372
9373 return Copy_Node_With_Replacement (Source);
9374 end New_Copy_Tree;
9375
9376 -------------------------
9377 -- New_External_Entity --
9378 -------------------------
9379
9380 function New_External_Entity
9381 (Kind : Entity_Kind;
9382 Scope_Id : Entity_Id;
9383 Sloc_Value : Source_Ptr;
9384 Related_Id : Entity_Id;
9385 Suffix : Character;
9386 Suffix_Index : Nat := 0;
9387 Prefix : Character := ' ') return Entity_Id
9388 is
9389 N : constant Entity_Id :=
9390 Make_Defining_Identifier (Sloc_Value,
9391 New_External_Name
9392 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
9393
9394 begin
9395 Set_Ekind (N, Kind);
9396 Set_Is_Internal (N, True);
9397 Append_Entity (N, Scope_Id);
9398 Set_Public_Status (N);
9399
9400 if Kind in Type_Kind then
9401 Init_Size_Align (N);
9402 end if;
9403
9404 return N;
9405 end New_External_Entity;
9406
9407 -------------------------
9408 -- New_Internal_Entity --
9409 -------------------------
9410
9411 function New_Internal_Entity
9412 (Kind : Entity_Kind;
9413 Scope_Id : Entity_Id;
9414 Sloc_Value : Source_Ptr;
9415 Id_Char : Character) return Entity_Id
9416 is
9417 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
9418
9419 begin
9420 Set_Ekind (N, Kind);
9421 Set_Is_Internal (N, True);
9422 Append_Entity (N, Scope_Id);
9423
9424 if Kind in Type_Kind then
9425 Init_Size_Align (N);
9426 end if;
9427
9428 return N;
9429 end New_Internal_Entity;
9430
9431 -----------------
9432 -- Next_Actual --
9433 -----------------
9434
9435 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
9436 N : Node_Id;
9437
9438 begin
9439 -- If we are pointing at a positional parameter, it is a member of a
9440 -- node list (the list of parameters), and the next parameter is the
9441 -- next node on the list, unless we hit a parameter association, then
9442 -- we shift to using the chain whose head is the First_Named_Actual in
9443 -- the parent, and then is threaded using the Next_Named_Actual of the
9444 -- Parameter_Association. All this fiddling is because the original node
9445 -- list is in the textual call order, and what we need is the
9446 -- declaration order.
9447
9448 if Is_List_Member (Actual_Id) then
9449 N := Next (Actual_Id);
9450
9451 if Nkind (N) = N_Parameter_Association then
9452 return First_Named_Actual (Parent (Actual_Id));
9453 else
9454 return N;
9455 end if;
9456
9457 else
9458 return Next_Named_Actual (Parent (Actual_Id));
9459 end if;
9460 end Next_Actual;
9461
9462 procedure Next_Actual (Actual_Id : in out Node_Id) is
9463 begin
9464 Actual_Id := Next_Actual (Actual_Id);
9465 end Next_Actual;
9466
9467 -----------------------
9468 -- Normalize_Actuals --
9469 -----------------------
9470
9471 -- Chain actuals according to formals of subprogram. If there are no named
9472 -- associations, the chain is simply the list of Parameter Associations,
9473 -- since the order is the same as the declaration order. If there are named
9474 -- associations, then the First_Named_Actual field in the N_Function_Call
9475 -- or N_Procedure_Call_Statement node points to the Parameter_Association
9476 -- node for the parameter that comes first in declaration order. The
9477 -- remaining named parameters are then chained in declaration order using
9478 -- Next_Named_Actual.
9479
9480 -- This routine also verifies that the number of actuals is compatible with
9481 -- the number and default values of formals, but performs no type checking
9482 -- (type checking is done by the caller).
9483
9484 -- If the matching succeeds, Success is set to True and the caller proceeds
9485 -- with type-checking. If the match is unsuccessful, then Success is set to
9486 -- False, and the caller attempts a different interpretation, if there is
9487 -- one.
9488
9489 -- If the flag Report is on, the call is not overloaded, and a failure to
9490 -- match can be reported here, rather than in the caller.
9491
9492 procedure Normalize_Actuals
9493 (N : Node_Id;
9494 S : Entity_Id;
9495 Report : Boolean;
9496 Success : out Boolean)
9497 is
9498 Actuals : constant List_Id := Parameter_Associations (N);
9499 Actual : Node_Id := Empty;
9500 Formal : Entity_Id;
9501 Last : Node_Id := Empty;
9502 First_Named : Node_Id := Empty;
9503 Found : Boolean;
9504
9505 Formals_To_Match : Integer := 0;
9506 Actuals_To_Match : Integer := 0;
9507
9508 procedure Chain (A : Node_Id);
9509 -- Add named actual at the proper place in the list, using the
9510 -- Next_Named_Actual link.
9511
9512 function Reporting return Boolean;
9513 -- Determines if an error is to be reported. To report an error, we
9514 -- need Report to be True, and also we do not report errors caused
9515 -- by calls to init procs that occur within other init procs. Such
9516 -- errors must always be cascaded errors, since if all the types are
9517 -- declared correctly, the compiler will certainly build decent calls!
9518
9519 -----------
9520 -- Chain --
9521 -----------
9522
9523 procedure Chain (A : Node_Id) is
9524 begin
9525 if No (Last) then
9526
9527 -- Call node points to first actual in list
9528
9529 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
9530
9531 else
9532 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
9533 end if;
9534
9535 Last := A;
9536 Set_Next_Named_Actual (Last, Empty);
9537 end Chain;
9538
9539 ---------------
9540 -- Reporting --
9541 ---------------
9542
9543 function Reporting return Boolean is
9544 begin
9545 if not Report then
9546 return False;
9547
9548 elsif not Within_Init_Proc then
9549 return True;
9550
9551 elsif Is_Init_Proc (Entity (Name (N))) then
9552 return False;
9553
9554 else
9555 return True;
9556 end if;
9557 end Reporting;
9558
9559 -- Start of processing for Normalize_Actuals
9560
9561 begin
9562 if Is_Access_Type (S) then
9563
9564 -- The name in the call is a function call that returns an access
9565 -- to subprogram. The designated type has the list of formals.
9566
9567 Formal := First_Formal (Designated_Type (S));
9568 else
9569 Formal := First_Formal (S);
9570 end if;
9571
9572 while Present (Formal) loop
9573 Formals_To_Match := Formals_To_Match + 1;
9574 Next_Formal (Formal);
9575 end loop;
9576
9577 -- Find if there is a named association, and verify that no positional
9578 -- associations appear after named ones.
9579
9580 if Present (Actuals) then
9581 Actual := First (Actuals);
9582 end if;
9583
9584 while Present (Actual)
9585 and then Nkind (Actual) /= N_Parameter_Association
9586 loop
9587 Actuals_To_Match := Actuals_To_Match + 1;
9588 Next (Actual);
9589 end loop;
9590
9591 if No (Actual) and Actuals_To_Match = Formals_To_Match then
9592
9593 -- Most common case: positional notation, no defaults
9594
9595 Success := True;
9596 return;
9597
9598 elsif Actuals_To_Match > Formals_To_Match then
9599
9600 -- Too many actuals: will not work
9601
9602 if Reporting then
9603 if Is_Entity_Name (Name (N)) then
9604 Error_Msg_N ("too many arguments in call to&", Name (N));
9605 else
9606 Error_Msg_N ("too many arguments in call", N);
9607 end if;
9608 end if;
9609
9610 Success := False;
9611 return;
9612 end if;
9613
9614 First_Named := Actual;
9615
9616 while Present (Actual) loop
9617 if Nkind (Actual) /= N_Parameter_Association then
9618 Error_Msg_N
9619 ("positional parameters not allowed after named ones", Actual);
9620 Success := False;
9621 return;
9622
9623 else
9624 Actuals_To_Match := Actuals_To_Match + 1;
9625 end if;
9626
9627 Next (Actual);
9628 end loop;
9629
9630 if Present (Actuals) then
9631 Actual := First (Actuals);
9632 end if;
9633
9634 Formal := First_Formal (S);
9635 while Present (Formal) loop
9636
9637 -- Match the formals in order. If the corresponding actual is
9638 -- positional, nothing to do. Else scan the list of named actuals
9639 -- to find the one with the right name.
9640
9641 if Present (Actual)
9642 and then Nkind (Actual) /= N_Parameter_Association
9643 then
9644 Next (Actual);
9645 Actuals_To_Match := Actuals_To_Match - 1;
9646 Formals_To_Match := Formals_To_Match - 1;
9647
9648 else
9649 -- For named parameters, search the list of actuals to find
9650 -- one that matches the next formal name.
9651
9652 Actual := First_Named;
9653 Found := False;
9654 while Present (Actual) loop
9655 if Chars (Selector_Name (Actual)) = Chars (Formal) then
9656 Found := True;
9657 Chain (Actual);
9658 Actuals_To_Match := Actuals_To_Match - 1;
9659 Formals_To_Match := Formals_To_Match - 1;
9660 exit;
9661 end if;
9662
9663 Next (Actual);
9664 end loop;
9665
9666 if not Found then
9667 if Ekind (Formal) /= E_In_Parameter
9668 or else No (Default_Value (Formal))
9669 then
9670 if Reporting then
9671 if (Comes_From_Source (S)
9672 or else Sloc (S) = Standard_Location)
9673 and then Is_Overloadable (S)
9674 then
9675 if No (Actuals)
9676 and then
9677 (Nkind (Parent (N)) = N_Procedure_Call_Statement
9678 or else
9679 (Nkind (Parent (N)) = N_Function_Call
9680 or else
9681 Nkind (Parent (N)) = N_Parameter_Association))
9682 and then Ekind (S) /= E_Function
9683 then
9684 Set_Etype (N, Etype (S));
9685 else
9686 Error_Msg_Name_1 := Chars (S);
9687 Error_Msg_Sloc := Sloc (S);
9688 Error_Msg_NE
9689 ("missing argument for parameter & " &
9690 "in call to % declared #", N, Formal);
9691 end if;
9692
9693 elsif Is_Overloadable (S) then
9694 Error_Msg_Name_1 := Chars (S);
9695
9696 -- Point to type derivation that generated the
9697 -- operation.
9698
9699 Error_Msg_Sloc := Sloc (Parent (S));
9700
9701 Error_Msg_NE
9702 ("missing argument for parameter & " &
9703 "in call to % (inherited) #", N, Formal);
9704
9705 else
9706 Error_Msg_NE
9707 ("missing argument for parameter &", N, Formal);
9708 end if;
9709 end if;
9710
9711 Success := False;
9712 return;
9713
9714 else
9715 Formals_To_Match := Formals_To_Match - 1;
9716 end if;
9717 end if;
9718 end if;
9719
9720 Next_Formal (Formal);
9721 end loop;
9722
9723 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
9724 Success := True;
9725 return;
9726
9727 else
9728 if Reporting then
9729
9730 -- Find some superfluous named actual that did not get
9731 -- attached to the list of associations.
9732
9733 Actual := First (Actuals);
9734 while Present (Actual) loop
9735 if Nkind (Actual) = N_Parameter_Association
9736 and then Actual /= Last
9737 and then No (Next_Named_Actual (Actual))
9738 then
9739 Error_Msg_N ("unmatched actual & in call",
9740 Selector_Name (Actual));
9741 exit;
9742 end if;
9743
9744 Next (Actual);
9745 end loop;
9746 end if;
9747
9748 Success := False;
9749 return;
9750 end if;
9751 end Normalize_Actuals;
9752
9753 --------------------------------
9754 -- Note_Possible_Modification --
9755 --------------------------------
9756
9757 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
9758 Modification_Comes_From_Source : constant Boolean :=
9759 Comes_From_Source (Parent (N));
9760
9761 Ent : Entity_Id;
9762 Exp : Node_Id;
9763
9764 begin
9765 -- Loop to find referenced entity, if there is one
9766
9767 Exp := N;
9768 loop
9769 <<Continue>>
9770 Ent := Empty;
9771
9772 if Is_Entity_Name (Exp) then
9773 Ent := Entity (Exp);
9774
9775 -- If the entity is missing, it is an undeclared identifier,
9776 -- and there is nothing to annotate.
9777
9778 if No (Ent) then
9779 return;
9780 end if;
9781
9782 elsif Nkind (Exp) = N_Explicit_Dereference then
9783 declare
9784 P : constant Node_Id := Prefix (Exp);
9785
9786 begin
9787 if Nkind (P) = N_Selected_Component
9788 and then Present (
9789 Entry_Formal (Entity (Selector_Name (P))))
9790 then
9791 -- Case of a reference to an entry formal
9792
9793 Ent := Entry_Formal (Entity (Selector_Name (P)));
9794
9795 elsif Nkind (P) = N_Identifier
9796 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
9797 and then Present (Expression (Parent (Entity (P))))
9798 and then Nkind (Expression (Parent (Entity (P))))
9799 = N_Reference
9800 then
9801 -- Case of a reference to a value on which side effects have
9802 -- been removed.
9803
9804 Exp := Prefix (Expression (Parent (Entity (P))));
9805 goto Continue;
9806
9807 else
9808 return;
9809
9810 end if;
9811 end;
9812
9813 elsif Nkind (Exp) = N_Type_Conversion
9814 or else Nkind (Exp) = N_Unchecked_Type_Conversion
9815 then
9816 Exp := Expression (Exp);
9817 goto Continue;
9818
9819 elsif Nkind (Exp) = N_Slice
9820 or else Nkind (Exp) = N_Indexed_Component
9821 or else Nkind (Exp) = N_Selected_Component
9822 then
9823 Exp := Prefix (Exp);
9824 goto Continue;
9825
9826 else
9827 return;
9828 end if;
9829
9830 -- Now look for entity being referenced
9831
9832 if Present (Ent) then
9833 if Is_Object (Ent) then
9834 if Comes_From_Source (Exp)
9835 or else Modification_Comes_From_Source
9836 then
9837 -- Give warning if pragma unmodified given and we are
9838 -- sure this is a modification.
9839
9840 if Has_Pragma_Unmodified (Ent) and then Sure then
9841 Error_Msg_NE ("?pragma Unmodified given for &!", N, Ent);
9842 end if;
9843
9844 Set_Never_Set_In_Source (Ent, False);
9845 end if;
9846
9847 Set_Is_True_Constant (Ent, False);
9848 Set_Current_Value (Ent, Empty);
9849 Set_Is_Known_Null (Ent, False);
9850
9851 if not Can_Never_Be_Null (Ent) then
9852 Set_Is_Known_Non_Null (Ent, False);
9853 end if;
9854
9855 -- Follow renaming chain
9856
9857 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
9858 and then Present (Renamed_Object (Ent))
9859 then
9860 Exp := Renamed_Object (Ent);
9861 goto Continue;
9862 end if;
9863
9864 -- Generate a reference only if the assignment comes from
9865 -- source. This excludes, for example, calls to a dispatching
9866 -- assignment operation when the left-hand side is tagged.
9867
9868 if Modification_Comes_From_Source then
9869 Generate_Reference (Ent, Exp, 'm');
9870
9871 -- If the target of the assignment is the bound variable
9872 -- in an iterator, indicate that the corresponding array
9873 -- or container is also modified.
9874
9875 if Ada_Version >= Ada_2012
9876 and then
9877 Nkind (Parent (Ent)) = N_Iterator_Specification
9878 then
9879 declare
9880 Domain : constant Node_Id := Name (Parent (Ent));
9881
9882 begin
9883 -- TBD : in the full version of the construct, the
9884 -- domain of iteration can be given by an expression.
9885
9886 if Is_Entity_Name (Domain) then
9887 Generate_Reference (Entity (Domain), Exp, 'm');
9888 Set_Is_True_Constant (Entity (Domain), False);
9889 Set_Never_Set_In_Source (Entity (Domain), False);
9890 end if;
9891 end;
9892 end if;
9893 end if;
9894
9895 Check_Nested_Access (Ent);
9896 end if;
9897
9898 Kill_Checks (Ent);
9899
9900 -- If we are sure this is a modification from source, and we know
9901 -- this modifies a constant, then give an appropriate warning.
9902
9903 if Overlays_Constant (Ent)
9904 and then Modification_Comes_From_Source
9905 and then Sure
9906 then
9907 declare
9908 A : constant Node_Id := Address_Clause (Ent);
9909 begin
9910 if Present (A) then
9911 declare
9912 Exp : constant Node_Id := Expression (A);
9913 begin
9914 if Nkind (Exp) = N_Attribute_Reference
9915 and then Attribute_Name (Exp) = Name_Address
9916 and then Is_Entity_Name (Prefix (Exp))
9917 then
9918 Error_Msg_Sloc := Sloc (A);
9919 Error_Msg_NE
9920 ("constant& may be modified via address clause#?",
9921 N, Entity (Prefix (Exp)));
9922 end if;
9923 end;
9924 end if;
9925 end;
9926 end if;
9927
9928 return;
9929 end if;
9930 end loop;
9931 end Note_Possible_Modification;
9932
9933 -------------------------
9934 -- Object_Access_Level --
9935 -------------------------
9936
9937 function Object_Access_Level (Obj : Node_Id) return Uint is
9938 E : Entity_Id;
9939
9940 -- Returns the static accessibility level of the view denoted by Obj. Note
9941 -- that the value returned is the result of a call to Scope_Depth. Only
9942 -- scope depths associated with dynamic scopes can actually be returned.
9943 -- Since only relative levels matter for accessibility checking, the fact
9944 -- that the distance between successive levels of accessibility is not
9945 -- always one is immaterial (invariant: if level(E2) is deeper than
9946 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
9947
9948 function Reference_To (Obj : Node_Id) return Node_Id;
9949 -- An explicit dereference is created when removing side-effects from
9950 -- expressions for constraint checking purposes. In this case a local
9951 -- access type is created for it. The correct access level is that of
9952 -- the original source node. We detect this case by noting that the
9953 -- prefix of the dereference is created by an object declaration whose
9954 -- initial expression is a reference.
9955
9956 ------------------
9957 -- Reference_To --
9958 ------------------
9959
9960 function Reference_To (Obj : Node_Id) return Node_Id is
9961 Pref : constant Node_Id := Prefix (Obj);
9962 begin
9963 if Is_Entity_Name (Pref)
9964 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
9965 and then Present (Expression (Parent (Entity (Pref))))
9966 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
9967 then
9968 return (Prefix (Expression (Parent (Entity (Pref)))));
9969 else
9970 return Empty;
9971 end if;
9972 end Reference_To;
9973
9974 -- Start of processing for Object_Access_Level
9975
9976 begin
9977 if Is_Entity_Name (Obj) then
9978 E := Entity (Obj);
9979
9980 if Is_Prival (E) then
9981 E := Prival_Link (E);
9982 end if;
9983
9984 -- If E is a type then it denotes a current instance. For this case
9985 -- we add one to the normal accessibility level of the type to ensure
9986 -- that current instances are treated as always being deeper than
9987 -- than the level of any visible named access type (see 3.10.2(21)).
9988
9989 if Is_Type (E) then
9990 return Type_Access_Level (E) + 1;
9991
9992 elsif Present (Renamed_Object (E)) then
9993 return Object_Access_Level (Renamed_Object (E));
9994
9995 -- Similarly, if E is a component of the current instance of a
9996 -- protected type, any instance of it is assumed to be at a deeper
9997 -- level than the type. For a protected object (whose type is an
9998 -- anonymous protected type) its components are at the same level
9999 -- as the type itself.
10000
10001 elsif not Is_Overloadable (E)
10002 and then Ekind (Scope (E)) = E_Protected_Type
10003 and then Comes_From_Source (Scope (E))
10004 then
10005 return Type_Access_Level (Scope (E)) + 1;
10006
10007 else
10008 return Scope_Depth (Enclosing_Dynamic_Scope (E));
10009 end if;
10010
10011 elsif Nkind (Obj) = N_Selected_Component then
10012 if Is_Access_Type (Etype (Prefix (Obj))) then
10013 return Type_Access_Level (Etype (Prefix (Obj)));
10014 else
10015 return Object_Access_Level (Prefix (Obj));
10016 end if;
10017
10018 elsif Nkind (Obj) = N_Indexed_Component then
10019 if Is_Access_Type (Etype (Prefix (Obj))) then
10020 return Type_Access_Level (Etype (Prefix (Obj)));
10021 else
10022 return Object_Access_Level (Prefix (Obj));
10023 end if;
10024
10025 elsif Nkind (Obj) = N_Explicit_Dereference then
10026
10027 -- If the prefix is a selected access discriminant then we make a
10028 -- recursive call on the prefix, which will in turn check the level
10029 -- of the prefix object of the selected discriminant.
10030
10031 if Nkind (Prefix (Obj)) = N_Selected_Component
10032 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
10033 and then
10034 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
10035 then
10036 return Object_Access_Level (Prefix (Obj));
10037
10038 elsif not (Comes_From_Source (Obj)) then
10039 declare
10040 Ref : constant Node_Id := Reference_To (Obj);
10041 begin
10042 if Present (Ref) then
10043 return Object_Access_Level (Ref);
10044 else
10045 return Type_Access_Level (Etype (Prefix (Obj)));
10046 end if;
10047 end;
10048
10049 else
10050 return Type_Access_Level (Etype (Prefix (Obj)));
10051 end if;
10052
10053 elsif Nkind (Obj) = N_Type_Conversion
10054 or else Nkind (Obj) = N_Unchecked_Type_Conversion
10055 then
10056 return Object_Access_Level (Expression (Obj));
10057
10058 elsif Nkind (Obj) = N_Function_Call then
10059
10060 -- Function results are objects, so we get either the access level of
10061 -- the function or, in the case of an indirect call, the level of the
10062 -- access-to-subprogram type. (This code is used for Ada 95, but it
10063 -- looks wrong, because it seems that we should be checking the level
10064 -- of the call itself, even for Ada 95. However, using the Ada 2005
10065 -- version of the code causes regressions in several tests that are
10066 -- compiled with -gnat95. ???)
10067
10068 if Ada_Version < Ada_2005 then
10069 if Is_Entity_Name (Name (Obj)) then
10070 return Subprogram_Access_Level (Entity (Name (Obj)));
10071 else
10072 return Type_Access_Level (Etype (Prefix (Name (Obj))));
10073 end if;
10074
10075 -- For Ada 2005, the level of the result object of a function call is
10076 -- defined to be the level of the call's innermost enclosing master.
10077 -- We determine that by querying the depth of the innermost enclosing
10078 -- dynamic scope.
10079
10080 else
10081 Return_Master_Scope_Depth_Of_Call : declare
10082
10083 function Innermost_Master_Scope_Depth
10084 (N : Node_Id) return Uint;
10085 -- Returns the scope depth of the given node's innermost
10086 -- enclosing dynamic scope (effectively the accessibility
10087 -- level of the innermost enclosing master).
10088
10089 ----------------------------------
10090 -- Innermost_Master_Scope_Depth --
10091 ----------------------------------
10092
10093 function Innermost_Master_Scope_Depth
10094 (N : Node_Id) return Uint
10095 is
10096 Node_Par : Node_Id := Parent (N);
10097
10098 begin
10099 -- Locate the nearest enclosing node (by traversing Parents)
10100 -- that Defining_Entity can be applied to, and return the
10101 -- depth of that entity's nearest enclosing dynamic scope.
10102
10103 while Present (Node_Par) loop
10104 case Nkind (Node_Par) is
10105 when N_Component_Declaration |
10106 N_Entry_Declaration |
10107 N_Formal_Object_Declaration |
10108 N_Formal_Type_Declaration |
10109 N_Full_Type_Declaration |
10110 N_Incomplete_Type_Declaration |
10111 N_Loop_Parameter_Specification |
10112 N_Object_Declaration |
10113 N_Protected_Type_Declaration |
10114 N_Private_Extension_Declaration |
10115 N_Private_Type_Declaration |
10116 N_Subtype_Declaration |
10117 N_Function_Specification |
10118 N_Procedure_Specification |
10119 N_Task_Type_Declaration |
10120 N_Body_Stub |
10121 N_Generic_Instantiation |
10122 N_Proper_Body |
10123 N_Implicit_Label_Declaration |
10124 N_Package_Declaration |
10125 N_Single_Task_Declaration |
10126 N_Subprogram_Declaration |
10127 N_Generic_Declaration |
10128 N_Renaming_Declaration |
10129 N_Block_Statement |
10130 N_Formal_Subprogram_Declaration |
10131 N_Abstract_Subprogram_Declaration |
10132 N_Entry_Body |
10133 N_Exception_Declaration |
10134 N_Formal_Package_Declaration |
10135 N_Number_Declaration |
10136 N_Package_Specification |
10137 N_Parameter_Specification |
10138 N_Single_Protected_Declaration |
10139 N_Subunit =>
10140
10141 return Scope_Depth
10142 (Nearest_Dynamic_Scope
10143 (Defining_Entity (Node_Par)));
10144
10145 when others =>
10146 null;
10147 end case;
10148
10149 Node_Par := Parent (Node_Par);
10150 end loop;
10151
10152 pragma Assert (False);
10153
10154 -- Should never reach the following return
10155
10156 return Scope_Depth (Current_Scope) + 1;
10157 end Innermost_Master_Scope_Depth;
10158
10159 -- Start of processing for Return_Master_Scope_Depth_Of_Call
10160
10161 begin
10162 return Innermost_Master_Scope_Depth (Obj);
10163 end Return_Master_Scope_Depth_Of_Call;
10164 end if;
10165
10166 -- For convenience we handle qualified expressions, even though
10167 -- they aren't technically object names.
10168
10169 elsif Nkind (Obj) = N_Qualified_Expression then
10170 return Object_Access_Level (Expression (Obj));
10171
10172 -- Otherwise return the scope level of Standard.
10173 -- (If there are cases that fall through
10174 -- to this point they will be treated as
10175 -- having global accessibility for now. ???)
10176
10177 else
10178 return Scope_Depth (Standard_Standard);
10179 end if;
10180 end Object_Access_Level;
10181
10182 --------------------------------------
10183 -- Original_Corresponding_Operation --
10184 --------------------------------------
10185
10186 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
10187 is
10188 Typ : constant Entity_Id := Find_Dispatching_Type (S);
10189
10190 begin
10191 -- If S is an inherited primitive S2 the original corresponding
10192 -- operation of S is the original corresponding operation of S2
10193
10194 if Present (Alias (S))
10195 and then Find_Dispatching_Type (Alias (S)) /= Typ
10196 then
10197 return Original_Corresponding_Operation (Alias (S));
10198
10199 -- If S overrides an inherited subprogram S2 the original corresponding
10200 -- operation of S is the original corresponding operation of S2
10201
10202 elsif Present (Overridden_Operation (S)) then
10203 return Original_Corresponding_Operation (Overridden_Operation (S));
10204
10205 -- otherwise it is S itself
10206
10207 else
10208 return S;
10209 end if;
10210 end Original_Corresponding_Operation;
10211
10212 -----------------------
10213 -- Private_Component --
10214 -----------------------
10215
10216 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
10217 Ancestor : constant Entity_Id := Base_Type (Type_Id);
10218
10219 function Trace_Components
10220 (T : Entity_Id;
10221 Check : Boolean) return Entity_Id;
10222 -- Recursive function that does the work, and checks against circular
10223 -- definition for each subcomponent type.
10224
10225 ----------------------
10226 -- Trace_Components --
10227 ----------------------
10228
10229 function Trace_Components
10230 (T : Entity_Id;
10231 Check : Boolean) return Entity_Id
10232 is
10233 Btype : constant Entity_Id := Base_Type (T);
10234 Component : Entity_Id;
10235 P : Entity_Id;
10236 Candidate : Entity_Id := Empty;
10237
10238 begin
10239 if Check and then Btype = Ancestor then
10240 Error_Msg_N ("circular type definition", Type_Id);
10241 return Any_Type;
10242 end if;
10243
10244 if Is_Private_Type (Btype)
10245 and then not Is_Generic_Type (Btype)
10246 then
10247 if Present (Full_View (Btype))
10248 and then Is_Record_Type (Full_View (Btype))
10249 and then not Is_Frozen (Btype)
10250 then
10251 -- To indicate that the ancestor depends on a private type, the
10252 -- current Btype is sufficient. However, to check for circular
10253 -- definition we must recurse on the full view.
10254
10255 Candidate := Trace_Components (Full_View (Btype), True);
10256
10257 if Candidate = Any_Type then
10258 return Any_Type;
10259 else
10260 return Btype;
10261 end if;
10262
10263 else
10264 return Btype;
10265 end if;
10266
10267 elsif Is_Array_Type (Btype) then
10268 return Trace_Components (Component_Type (Btype), True);
10269
10270 elsif Is_Record_Type (Btype) then
10271 Component := First_Entity (Btype);
10272 while Present (Component) loop
10273
10274 -- Skip anonymous types generated by constrained components
10275
10276 if not Is_Type (Component) then
10277 P := Trace_Components (Etype (Component), True);
10278
10279 if Present (P) then
10280 if P = Any_Type then
10281 return P;
10282 else
10283 Candidate := P;
10284 end if;
10285 end if;
10286 end if;
10287
10288 Next_Entity (Component);
10289 end loop;
10290
10291 return Candidate;
10292
10293 else
10294 return Empty;
10295 end if;
10296 end Trace_Components;
10297
10298 -- Start of processing for Private_Component
10299
10300 begin
10301 return Trace_Components (Type_Id, False);
10302 end Private_Component;
10303
10304 ---------------------------
10305 -- Primitive_Names_Match --
10306 ---------------------------
10307
10308 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
10309
10310 function Non_Internal_Name (E : Entity_Id) return Name_Id;
10311 -- Given an internal name, returns the corresponding non-internal name
10312
10313 ------------------------
10314 -- Non_Internal_Name --
10315 ------------------------
10316
10317 function Non_Internal_Name (E : Entity_Id) return Name_Id is
10318 begin
10319 Get_Name_String (Chars (E));
10320 Name_Len := Name_Len - 1;
10321 return Name_Find;
10322 end Non_Internal_Name;
10323
10324 -- Start of processing for Primitive_Names_Match
10325
10326 begin
10327 pragma Assert (Present (E1) and then Present (E2));
10328
10329 return Chars (E1) = Chars (E2)
10330 or else
10331 (not Is_Internal_Name (Chars (E1))
10332 and then Is_Internal_Name (Chars (E2))
10333 and then Non_Internal_Name (E2) = Chars (E1))
10334 or else
10335 (not Is_Internal_Name (Chars (E2))
10336 and then Is_Internal_Name (Chars (E1))
10337 and then Non_Internal_Name (E1) = Chars (E2))
10338 or else
10339 (Is_Predefined_Dispatching_Operation (E1)
10340 and then Is_Predefined_Dispatching_Operation (E2)
10341 and then Same_TSS (E1, E2))
10342 or else
10343 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
10344 end Primitive_Names_Match;
10345
10346 -----------------------
10347 -- Process_End_Label --
10348 -----------------------
10349
10350 procedure Process_End_Label
10351 (N : Node_Id;
10352 Typ : Character;
10353 Ent : Entity_Id)
10354 is
10355 Loc : Source_Ptr;
10356 Nam : Node_Id;
10357 Scop : Entity_Id;
10358
10359 Label_Ref : Boolean;
10360 -- Set True if reference to end label itself is required
10361
10362 Endl : Node_Id;
10363 -- Gets set to the operator symbol or identifier that references the
10364 -- entity Ent. For the child unit case, this is the identifier from the
10365 -- designator. For other cases, this is simply Endl.
10366
10367 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
10368 -- N is an identifier node that appears as a parent unit reference in
10369 -- the case where Ent is a child unit. This procedure generates an
10370 -- appropriate cross-reference entry. E is the corresponding entity.
10371
10372 -------------------------
10373 -- Generate_Parent_Ref --
10374 -------------------------
10375
10376 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
10377 begin
10378 -- If names do not match, something weird, skip reference
10379
10380 if Chars (E) = Chars (N) then
10381
10382 -- Generate the reference. We do NOT consider this as a reference
10383 -- for unreferenced symbol purposes.
10384
10385 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
10386
10387 if Style_Check then
10388 Style.Check_Identifier (N, E);
10389 end if;
10390 end if;
10391 end Generate_Parent_Ref;
10392
10393 -- Start of processing for Process_End_Label
10394
10395 begin
10396 -- If no node, ignore. This happens in some error situations, and
10397 -- also for some internally generated structures where no end label
10398 -- references are required in any case.
10399
10400 if No (N) then
10401 return;
10402 end if;
10403
10404 -- Nothing to do if no End_Label, happens for internally generated
10405 -- constructs where we don't want an end label reference anyway. Also
10406 -- nothing to do if Endl is a string literal, which means there was
10407 -- some prior error (bad operator symbol)
10408
10409 Endl := End_Label (N);
10410
10411 if No (Endl) or else Nkind (Endl) = N_String_Literal then
10412 return;
10413 end if;
10414
10415 -- Reference node is not in extended main source unit
10416
10417 if not In_Extended_Main_Source_Unit (N) then
10418
10419 -- Generally we do not collect references except for the extended
10420 -- main source unit. The one exception is the 'e' entry for a
10421 -- package spec, where it is useful for a client to have the
10422 -- ending information to define scopes.
10423
10424 if Typ /= 'e' then
10425 return;
10426
10427 else
10428 Label_Ref := False;
10429
10430 -- For this case, we can ignore any parent references, but we
10431 -- need the package name itself for the 'e' entry.
10432
10433 if Nkind (Endl) = N_Designator then
10434 Endl := Identifier (Endl);
10435 end if;
10436 end if;
10437
10438 -- Reference is in extended main source unit
10439
10440 else
10441 Label_Ref := True;
10442
10443 -- For designator, generate references for the parent entries
10444
10445 if Nkind (Endl) = N_Designator then
10446
10447 -- Generate references for the prefix if the END line comes from
10448 -- source (otherwise we do not need these references) We climb the
10449 -- scope stack to find the expected entities.
10450
10451 if Comes_From_Source (Endl) then
10452 Nam := Name (Endl);
10453 Scop := Current_Scope;
10454 while Nkind (Nam) = N_Selected_Component loop
10455 Scop := Scope (Scop);
10456 exit when No (Scop);
10457 Generate_Parent_Ref (Selector_Name (Nam), Scop);
10458 Nam := Prefix (Nam);
10459 end loop;
10460
10461 if Present (Scop) then
10462 Generate_Parent_Ref (Nam, Scope (Scop));
10463 end if;
10464 end if;
10465
10466 Endl := Identifier (Endl);
10467 end if;
10468 end if;
10469
10470 -- If the end label is not for the given entity, then either we have
10471 -- some previous error, or this is a generic instantiation for which
10472 -- we do not need to make a cross-reference in this case anyway. In
10473 -- either case we simply ignore the call.
10474
10475 if Chars (Ent) /= Chars (Endl) then
10476 return;
10477 end if;
10478
10479 -- If label was really there, then generate a normal reference and then
10480 -- adjust the location in the end label to point past the name (which
10481 -- should almost always be the semicolon).
10482
10483 Loc := Sloc (Endl);
10484
10485 if Comes_From_Source (Endl) then
10486
10487 -- If a label reference is required, then do the style check and
10488 -- generate an l-type cross-reference entry for the label
10489
10490 if Label_Ref then
10491 if Style_Check then
10492 Style.Check_Identifier (Endl, Ent);
10493 end if;
10494
10495 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
10496 end if;
10497
10498 -- Set the location to point past the label (normally this will
10499 -- mean the semicolon immediately following the label). This is
10500 -- done for the sake of the 'e' or 't' entry generated below.
10501
10502 Get_Decoded_Name_String (Chars (Endl));
10503 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
10504 end if;
10505
10506 -- Now generate the e/t reference
10507
10508 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
10509
10510 -- Restore Sloc, in case modified above, since we have an identifier
10511 -- and the normal Sloc should be left set in the tree.
10512
10513 Set_Sloc (Endl, Loc);
10514 end Process_End_Label;
10515
10516 ------------------------------------
10517 -- References_Generic_Formal_Type --
10518 ------------------------------------
10519
10520 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
10521
10522 function Process (N : Node_Id) return Traverse_Result;
10523 -- Process one node in search for generic formal type
10524
10525 -------------
10526 -- Process --
10527 -------------
10528
10529 function Process (N : Node_Id) return Traverse_Result is
10530 begin
10531 if Nkind (N) in N_Has_Entity then
10532 declare
10533 E : constant Entity_Id := Entity (N);
10534 begin
10535 if Present (E) then
10536 if Is_Generic_Type (E) then
10537 return Abandon;
10538 elsif Present (Etype (E))
10539 and then Is_Generic_Type (Etype (E))
10540 then
10541 return Abandon;
10542 end if;
10543 end if;
10544 end;
10545 end if;
10546
10547 return Atree.OK;
10548 end Process;
10549
10550 function Traverse is new Traverse_Func (Process);
10551 -- Traverse tree to look for generic type
10552
10553 begin
10554 if Inside_A_Generic then
10555 return Traverse (N) = Abandon;
10556 else
10557 return False;
10558 end if;
10559 end References_Generic_Formal_Type;
10560
10561 --------------------
10562 -- Remove_Homonym --
10563 --------------------
10564
10565 procedure Remove_Homonym (E : Entity_Id) is
10566 Prev : Entity_Id := Empty;
10567 H : Entity_Id;
10568
10569 begin
10570 if E = Current_Entity (E) then
10571 if Present (Homonym (E)) then
10572 Set_Current_Entity (Homonym (E));
10573 else
10574 Set_Name_Entity_Id (Chars (E), Empty);
10575 end if;
10576 else
10577 H := Current_Entity (E);
10578 while Present (H) and then H /= E loop
10579 Prev := H;
10580 H := Homonym (H);
10581 end loop;
10582
10583 Set_Homonym (Prev, Homonym (E));
10584 end if;
10585 end Remove_Homonym;
10586
10587 ---------------------
10588 -- Rep_To_Pos_Flag --
10589 ---------------------
10590
10591 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
10592 begin
10593 return New_Occurrence_Of
10594 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
10595 end Rep_To_Pos_Flag;
10596
10597 --------------------
10598 -- Require_Entity --
10599 --------------------
10600
10601 procedure Require_Entity (N : Node_Id) is
10602 begin
10603 if Is_Entity_Name (N) and then No (Entity (N)) then
10604 if Total_Errors_Detected /= 0 then
10605 Set_Entity (N, Any_Id);
10606 else
10607 raise Program_Error;
10608 end if;
10609 end if;
10610 end Require_Entity;
10611
10612 ------------------------------
10613 -- Requires_Transient_Scope --
10614 ------------------------------
10615
10616 -- A transient scope is required when variable-sized temporaries are
10617 -- allocated in the primary or secondary stack, or when finalization
10618 -- actions must be generated before the next instruction.
10619
10620 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
10621 Typ : constant Entity_Id := Underlying_Type (Id);
10622
10623 -- Start of processing for Requires_Transient_Scope
10624
10625 begin
10626 -- This is a private type which is not completed yet. This can only
10627 -- happen in a default expression (of a formal parameter or of a
10628 -- record component). Do not expand transient scope in this case
10629
10630 if No (Typ) then
10631 return False;
10632
10633 -- Do not expand transient scope for non-existent procedure return
10634
10635 elsif Typ = Standard_Void_Type then
10636 return False;
10637
10638 -- Elementary types do not require a transient scope
10639
10640 elsif Is_Elementary_Type (Typ) then
10641 return False;
10642
10643 -- Generally, indefinite subtypes require a transient scope, since the
10644 -- back end cannot generate temporaries, since this is not a valid type
10645 -- for declaring an object. It might be possible to relax this in the
10646 -- future, e.g. by declaring the maximum possible space for the type.
10647
10648 elsif Is_Indefinite_Subtype (Typ) then
10649 return True;
10650
10651 -- Functions returning tagged types may dispatch on result so their
10652 -- returned value is allocated on the secondary stack. Controlled
10653 -- type temporaries need finalization.
10654
10655 elsif Is_Tagged_Type (Typ)
10656 or else Has_Controlled_Component (Typ)
10657 then
10658 return not Is_Value_Type (Typ);
10659
10660 -- Record type
10661
10662 elsif Is_Record_Type (Typ) then
10663 declare
10664 Comp : Entity_Id;
10665 begin
10666 Comp := First_Entity (Typ);
10667 while Present (Comp) loop
10668 if Ekind (Comp) = E_Component
10669 and then Requires_Transient_Scope (Etype (Comp))
10670 then
10671 return True;
10672 else
10673 Next_Entity (Comp);
10674 end if;
10675 end loop;
10676 end;
10677
10678 return False;
10679
10680 -- String literal types never require transient scope
10681
10682 elsif Ekind (Typ) = E_String_Literal_Subtype then
10683 return False;
10684
10685 -- Array type. Note that we already know that this is a constrained
10686 -- array, since unconstrained arrays will fail the indefinite test.
10687
10688 elsif Is_Array_Type (Typ) then
10689
10690 -- If component type requires a transient scope, the array does too
10691
10692 if Requires_Transient_Scope (Component_Type (Typ)) then
10693 return True;
10694
10695 -- Otherwise, we only need a transient scope if the size depends on
10696 -- the value of one or more discriminants.
10697
10698 else
10699 return Size_Depends_On_Discriminant (Typ);
10700 end if;
10701
10702 -- All other cases do not require a transient scope
10703
10704 else
10705 return False;
10706 end if;
10707 end Requires_Transient_Scope;
10708
10709 --------------------------
10710 -- Reset_Analyzed_Flags --
10711 --------------------------
10712
10713 procedure Reset_Analyzed_Flags (N : Node_Id) is
10714
10715 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
10716 -- Function used to reset Analyzed flags in tree. Note that we do
10717 -- not reset Analyzed flags in entities, since there is no need to
10718 -- reanalyze entities, and indeed, it is wrong to do so, since it
10719 -- can result in generating auxiliary stuff more than once.
10720
10721 --------------------
10722 -- Clear_Analyzed --
10723 --------------------
10724
10725 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
10726 begin
10727 if not Has_Extension (N) then
10728 Set_Analyzed (N, False);
10729 end if;
10730
10731 return OK;
10732 end Clear_Analyzed;
10733
10734 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
10735
10736 -- Start of processing for Reset_Analyzed_Flags
10737
10738 begin
10739 Reset_Analyzed (N);
10740 end Reset_Analyzed_Flags;
10741
10742 ---------------------------
10743 -- Safe_To_Capture_Value --
10744 ---------------------------
10745
10746 function Safe_To_Capture_Value
10747 (N : Node_Id;
10748 Ent : Entity_Id;
10749 Cond : Boolean := False) return Boolean
10750 is
10751 begin
10752 -- The only entities for which we track constant values are variables
10753 -- which are not renamings, constants, out parameters, and in out
10754 -- parameters, so check if we have this case.
10755
10756 -- Note: it may seem odd to track constant values for constants, but in
10757 -- fact this routine is used for other purposes than simply capturing
10758 -- the value. In particular, the setting of Known[_Non]_Null.
10759
10760 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
10761 or else
10762 Ekind (Ent) = E_Constant
10763 or else
10764 Ekind (Ent) = E_Out_Parameter
10765 or else
10766 Ekind (Ent) = E_In_Out_Parameter
10767 then
10768 null;
10769
10770 -- For conditionals, we also allow loop parameters and all formals,
10771 -- including in parameters.
10772
10773 elsif Cond
10774 and then
10775 (Ekind (Ent) = E_Loop_Parameter
10776 or else
10777 Ekind (Ent) = E_In_Parameter)
10778 then
10779 null;
10780
10781 -- For all other cases, not just unsafe, but impossible to capture
10782 -- Current_Value, since the above are the only entities which have
10783 -- Current_Value fields.
10784
10785 else
10786 return False;
10787 end if;
10788
10789 -- Skip if volatile or aliased, since funny things might be going on in
10790 -- these cases which we cannot necessarily track. Also skip any variable
10791 -- for which an address clause is given, or whose address is taken. Also
10792 -- never capture value of library level variables (an attempt to do so
10793 -- can occur in the case of package elaboration code).
10794
10795 if Treat_As_Volatile (Ent)
10796 or else Is_Aliased (Ent)
10797 or else Present (Address_Clause (Ent))
10798 or else Address_Taken (Ent)
10799 or else (Is_Library_Level_Entity (Ent)
10800 and then Ekind (Ent) = E_Variable)
10801 then
10802 return False;
10803 end if;
10804
10805 -- OK, all above conditions are met. We also require that the scope of
10806 -- the reference be the same as the scope of the entity, not counting
10807 -- packages and blocks and loops.
10808
10809 declare
10810 E_Scope : constant Entity_Id := Scope (Ent);
10811 R_Scope : Entity_Id;
10812
10813 begin
10814 R_Scope := Current_Scope;
10815 while R_Scope /= Standard_Standard loop
10816 exit when R_Scope = E_Scope;
10817
10818 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
10819 return False;
10820 else
10821 R_Scope := Scope (R_Scope);
10822 end if;
10823 end loop;
10824 end;
10825
10826 -- We also require that the reference does not appear in a context
10827 -- where it is not sure to be executed (i.e. a conditional context
10828 -- or an exception handler). We skip this if Cond is True, since the
10829 -- capturing of values from conditional tests handles this ok.
10830
10831 if Cond then
10832 return True;
10833 end if;
10834
10835 declare
10836 Desc : Node_Id;
10837 P : Node_Id;
10838
10839 begin
10840 Desc := N;
10841
10842 P := Parent (N);
10843 while Present (P) loop
10844 if Nkind (P) = N_If_Statement
10845 or else Nkind (P) = N_Case_Statement
10846 or else (Nkind (P) in N_Short_Circuit
10847 and then Desc = Right_Opnd (P))
10848 or else (Nkind (P) = N_Conditional_Expression
10849 and then Desc /= First (Expressions (P)))
10850 or else Nkind (P) = N_Exception_Handler
10851 or else Nkind (P) = N_Selective_Accept
10852 or else Nkind (P) = N_Conditional_Entry_Call
10853 or else Nkind (P) = N_Timed_Entry_Call
10854 or else Nkind (P) = N_Asynchronous_Select
10855 then
10856 return False;
10857 else
10858 Desc := P;
10859 P := Parent (P);
10860 end if;
10861 end loop;
10862 end;
10863
10864 -- OK, looks safe to set value
10865
10866 return True;
10867 end Safe_To_Capture_Value;
10868
10869 ---------------
10870 -- Same_Name --
10871 ---------------
10872
10873 function Same_Name (N1, N2 : Node_Id) return Boolean is
10874 K1 : constant Node_Kind := Nkind (N1);
10875 K2 : constant Node_Kind := Nkind (N2);
10876
10877 begin
10878 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
10879 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
10880 then
10881 return Chars (N1) = Chars (N2);
10882
10883 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
10884 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
10885 then
10886 return Same_Name (Selector_Name (N1), Selector_Name (N2))
10887 and then Same_Name (Prefix (N1), Prefix (N2));
10888
10889 else
10890 return False;
10891 end if;
10892 end Same_Name;
10893
10894 -----------------
10895 -- Same_Object --
10896 -----------------
10897
10898 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
10899 N1 : constant Node_Id := Original_Node (Node1);
10900 N2 : constant Node_Id := Original_Node (Node2);
10901 -- We do the tests on original nodes, since we are most interested
10902 -- in the original source, not any expansion that got in the way.
10903
10904 K1 : constant Node_Kind := Nkind (N1);
10905 K2 : constant Node_Kind := Nkind (N2);
10906
10907 begin
10908 -- First case, both are entities with same entity
10909
10910 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
10911 declare
10912 EN1 : constant Entity_Id := Entity (N1);
10913 EN2 : constant Entity_Id := Entity (N2);
10914 begin
10915 if Present (EN1) and then Present (EN2)
10916 and then (Ekind_In (EN1, E_Variable, E_Constant)
10917 or else Is_Formal (EN1))
10918 and then EN1 = EN2
10919 then
10920 return True;
10921 end if;
10922 end;
10923 end if;
10924
10925 -- Second case, selected component with same selector, same record
10926
10927 if K1 = N_Selected_Component
10928 and then K2 = N_Selected_Component
10929 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
10930 then
10931 return Same_Object (Prefix (N1), Prefix (N2));
10932
10933 -- Third case, indexed component with same subscripts, same array
10934
10935 elsif K1 = N_Indexed_Component
10936 and then K2 = N_Indexed_Component
10937 and then Same_Object (Prefix (N1), Prefix (N2))
10938 then
10939 declare
10940 E1, E2 : Node_Id;
10941 begin
10942 E1 := First (Expressions (N1));
10943 E2 := First (Expressions (N2));
10944 while Present (E1) loop
10945 if not Same_Value (E1, E2) then
10946 return False;
10947 else
10948 Next (E1);
10949 Next (E2);
10950 end if;
10951 end loop;
10952
10953 return True;
10954 end;
10955
10956 -- Fourth case, slice of same array with same bounds
10957
10958 elsif K1 = N_Slice
10959 and then K2 = N_Slice
10960 and then Nkind (Discrete_Range (N1)) = N_Range
10961 and then Nkind (Discrete_Range (N2)) = N_Range
10962 and then Same_Value (Low_Bound (Discrete_Range (N1)),
10963 Low_Bound (Discrete_Range (N2)))
10964 and then Same_Value (High_Bound (Discrete_Range (N1)),
10965 High_Bound (Discrete_Range (N2)))
10966 then
10967 return Same_Name (Prefix (N1), Prefix (N2));
10968
10969 -- All other cases, not clearly the same object
10970
10971 else
10972 return False;
10973 end if;
10974 end Same_Object;
10975
10976 ---------------
10977 -- Same_Type --
10978 ---------------
10979
10980 function Same_Type (T1, T2 : Entity_Id) return Boolean is
10981 begin
10982 if T1 = T2 then
10983 return True;
10984
10985 elsif not Is_Constrained (T1)
10986 and then not Is_Constrained (T2)
10987 and then Base_Type (T1) = Base_Type (T2)
10988 then
10989 return True;
10990
10991 -- For now don't bother with case of identical constraints, to be
10992 -- fiddled with later on perhaps (this is only used for optimization
10993 -- purposes, so it is not critical to do a best possible job)
10994
10995 else
10996 return False;
10997 end if;
10998 end Same_Type;
10999
11000 ----------------
11001 -- Same_Value --
11002 ----------------
11003
11004 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
11005 begin
11006 if Compile_Time_Known_Value (Node1)
11007 and then Compile_Time_Known_Value (Node2)
11008 and then Expr_Value (Node1) = Expr_Value (Node2)
11009 then
11010 return True;
11011 elsif Same_Object (Node1, Node2) then
11012 return True;
11013 else
11014 return False;
11015 end if;
11016 end Same_Value;
11017
11018 -----------------
11019 -- Save_Actual --
11020 -----------------
11021
11022 procedure Save_Actual (N : Node_Id; Writable : Boolean := False) is
11023 begin
11024 if Ada_Version < Ada_2012 then
11025 return;
11026
11027 elsif Is_Entity_Name (N)
11028 or else
11029 Nkind_In (N, N_Indexed_Component, N_Selected_Component, N_Slice)
11030 or else
11031 (Nkind (N) = N_Attribute_Reference
11032 and then Attribute_Name (N) = Name_Access)
11033
11034 then
11035 -- We are only interested in IN OUT parameters of inner calls
11036
11037 if not Writable
11038 or else Nkind (Parent (N)) = N_Function_Call
11039 or else Nkind (Parent (N)) in N_Op
11040 then
11041 Actuals_In_Call.Increment_Last;
11042 Actuals_In_Call.Table (Actuals_In_Call.Last) := (N, Writable);
11043 end if;
11044 end if;
11045 end Save_Actual;
11046
11047 ------------------------
11048 -- Scope_Is_Transient --
11049 ------------------------
11050
11051 function Scope_Is_Transient return Boolean is
11052 begin
11053 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
11054 end Scope_Is_Transient;
11055
11056 ------------------
11057 -- Scope_Within --
11058 ------------------
11059
11060 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
11061 Scop : Entity_Id;
11062
11063 begin
11064 Scop := Scope1;
11065 while Scop /= Standard_Standard loop
11066 Scop := Scope (Scop);
11067
11068 if Scop = Scope2 then
11069 return True;
11070 end if;
11071 end loop;
11072
11073 return False;
11074 end Scope_Within;
11075
11076 --------------------------
11077 -- Scope_Within_Or_Same --
11078 --------------------------
11079
11080 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
11081 Scop : Entity_Id;
11082
11083 begin
11084 Scop := Scope1;
11085 while Scop /= Standard_Standard loop
11086 if Scop = Scope2 then
11087 return True;
11088 else
11089 Scop := Scope (Scop);
11090 end if;
11091 end loop;
11092
11093 return False;
11094 end Scope_Within_Or_Same;
11095
11096 --------------------
11097 -- Set_Convention --
11098 --------------------
11099
11100 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
11101 begin
11102 Basic_Set_Convention (E, Val);
11103
11104 if Is_Type (E)
11105 and then Is_Access_Subprogram_Type (Base_Type (E))
11106 and then Has_Foreign_Convention (E)
11107 then
11108 Set_Can_Use_Internal_Rep (E, False);
11109 end if;
11110 end Set_Convention;
11111
11112 ------------------------
11113 -- Set_Current_Entity --
11114 ------------------------
11115
11116 -- The given entity is to be set as the currently visible definition
11117 -- of its associated name (i.e. the Node_Id associated with its name).
11118 -- All we have to do is to get the name from the identifier, and
11119 -- then set the associated Node_Id to point to the given entity.
11120
11121 procedure Set_Current_Entity (E : Entity_Id) is
11122 begin
11123 Set_Name_Entity_Id (Chars (E), E);
11124 end Set_Current_Entity;
11125
11126 ---------------------------
11127 -- Set_Debug_Info_Needed --
11128 ---------------------------
11129
11130 procedure Set_Debug_Info_Needed (T : Entity_Id) is
11131
11132 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
11133 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
11134 -- Used to set debug info in a related node if not set already
11135
11136 --------------------------------------
11137 -- Set_Debug_Info_Needed_If_Not_Set --
11138 --------------------------------------
11139
11140 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
11141 begin
11142 if Present (E)
11143 and then not Needs_Debug_Info (E)
11144 then
11145 Set_Debug_Info_Needed (E);
11146
11147 -- For a private type, indicate that the full view also needs
11148 -- debug information.
11149
11150 if Is_Type (E)
11151 and then Is_Private_Type (E)
11152 and then Present (Full_View (E))
11153 then
11154 Set_Debug_Info_Needed (Full_View (E));
11155 end if;
11156 end if;
11157 end Set_Debug_Info_Needed_If_Not_Set;
11158
11159 -- Start of processing for Set_Debug_Info_Needed
11160
11161 begin
11162 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
11163 -- indicates that Debug_Info_Needed is never required for the entity.
11164
11165 if No (T)
11166 or else Debug_Info_Off (T)
11167 then
11168 return;
11169 end if;
11170
11171 -- Set flag in entity itself. Note that we will go through the following
11172 -- circuitry even if the flag is already set on T. That's intentional,
11173 -- it makes sure that the flag will be set in subsidiary entities.
11174
11175 Set_Needs_Debug_Info (T);
11176
11177 -- Set flag on subsidiary entities if not set already
11178
11179 if Is_Object (T) then
11180 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
11181
11182 elsif Is_Type (T) then
11183 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
11184
11185 if Is_Record_Type (T) then
11186 declare
11187 Ent : Entity_Id := First_Entity (T);
11188 begin
11189 while Present (Ent) loop
11190 Set_Debug_Info_Needed_If_Not_Set (Ent);
11191 Next_Entity (Ent);
11192 end loop;
11193 end;
11194
11195 -- For a class wide subtype, we also need debug information
11196 -- for the equivalent type.
11197
11198 if Ekind (T) = E_Class_Wide_Subtype then
11199 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
11200 end if;
11201
11202 elsif Is_Array_Type (T) then
11203 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
11204
11205 declare
11206 Indx : Node_Id := First_Index (T);
11207 begin
11208 while Present (Indx) loop
11209 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
11210 Indx := Next_Index (Indx);
11211 end loop;
11212 end;
11213
11214 if Is_Packed (T) then
11215 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Type (T));
11216 end if;
11217
11218 elsif Is_Access_Type (T) then
11219 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
11220
11221 elsif Is_Private_Type (T) then
11222 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
11223
11224 elsif Is_Protected_Type (T) then
11225 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
11226 end if;
11227 end if;
11228 end Set_Debug_Info_Needed;
11229
11230 ---------------------------------
11231 -- Set_Entity_With_Style_Check --
11232 ---------------------------------
11233
11234 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
11235 Val_Actual : Entity_Id;
11236 Nod : Node_Id;
11237
11238 begin
11239 Set_Entity (N, Val);
11240
11241 if Style_Check
11242 and then not Suppress_Style_Checks (Val)
11243 and then not In_Instance
11244 then
11245 if Nkind (N) = N_Identifier then
11246 Nod := N;
11247 elsif Nkind (N) = N_Expanded_Name then
11248 Nod := Selector_Name (N);
11249 else
11250 return;
11251 end if;
11252
11253 -- A special situation arises for derived operations, where we want
11254 -- to do the check against the parent (since the Sloc of the derived
11255 -- operation points to the derived type declaration itself).
11256
11257 Val_Actual := Val;
11258 while not Comes_From_Source (Val_Actual)
11259 and then Nkind (Val_Actual) in N_Entity
11260 and then (Ekind (Val_Actual) = E_Enumeration_Literal
11261 or else Is_Subprogram (Val_Actual)
11262 or else Is_Generic_Subprogram (Val_Actual))
11263 and then Present (Alias (Val_Actual))
11264 loop
11265 Val_Actual := Alias (Val_Actual);
11266 end loop;
11267
11268 -- Renaming declarations for generic actuals do not come from source,
11269 -- and have a different name from that of the entity they rename, so
11270 -- there is no style check to perform here.
11271
11272 if Chars (Nod) = Chars (Val_Actual) then
11273 Style.Check_Identifier (Nod, Val_Actual);
11274 end if;
11275 end if;
11276
11277 Set_Entity (N, Val);
11278 end Set_Entity_With_Style_Check;
11279
11280 ------------------------
11281 -- Set_Name_Entity_Id --
11282 ------------------------
11283
11284 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
11285 begin
11286 Set_Name_Table_Info (Id, Int (Val));
11287 end Set_Name_Entity_Id;
11288
11289 ---------------------
11290 -- Set_Next_Actual --
11291 ---------------------
11292
11293 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
11294 begin
11295 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
11296 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
11297 end if;
11298 end Set_Next_Actual;
11299
11300 ----------------------------------
11301 -- Set_Optimize_Alignment_Flags --
11302 ----------------------------------
11303
11304 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
11305 begin
11306 if Optimize_Alignment = 'S' then
11307 Set_Optimize_Alignment_Space (E);
11308 elsif Optimize_Alignment = 'T' then
11309 Set_Optimize_Alignment_Time (E);
11310 end if;
11311 end Set_Optimize_Alignment_Flags;
11312
11313 -----------------------
11314 -- Set_Public_Status --
11315 -----------------------
11316
11317 procedure Set_Public_Status (Id : Entity_Id) is
11318 S : constant Entity_Id := Current_Scope;
11319
11320 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
11321 -- Determines if E is defined within handled statement sequence or
11322 -- an if statement, returns True if so, False otherwise.
11323
11324 ----------------------
11325 -- Within_HSS_Or_If --
11326 ----------------------
11327
11328 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
11329 N : Node_Id;
11330 begin
11331 N := Declaration_Node (E);
11332 loop
11333 N := Parent (N);
11334
11335 if No (N) then
11336 return False;
11337
11338 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
11339 N_If_Statement)
11340 then
11341 return True;
11342 end if;
11343 end loop;
11344 end Within_HSS_Or_If;
11345
11346 -- Start of processing for Set_Public_Status
11347
11348 begin
11349 -- Everything in the scope of Standard is public
11350
11351 if S = Standard_Standard then
11352 Set_Is_Public (Id);
11353
11354 -- Entity is definitely not public if enclosing scope is not public
11355
11356 elsif not Is_Public (S) then
11357 return;
11358
11359 -- An object or function declaration that occurs in a handled sequence
11360 -- of statements or within an if statement is the declaration for a
11361 -- temporary object or local subprogram generated by the expander. It
11362 -- never needs to be made public and furthermore, making it public can
11363 -- cause back end problems.
11364
11365 elsif Nkind_In (Parent (Id), N_Object_Declaration,
11366 N_Function_Specification)
11367 and then Within_HSS_Or_If (Id)
11368 then
11369 return;
11370
11371 -- Entities in public packages or records are public
11372
11373 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
11374 Set_Is_Public (Id);
11375
11376 -- The bounds of an entry family declaration can generate object
11377 -- declarations that are visible to the back-end, e.g. in the
11378 -- the declaration of a composite type that contains tasks.
11379
11380 elsif Is_Concurrent_Type (S)
11381 and then not Has_Completion (S)
11382 and then Nkind (Parent (Id)) = N_Object_Declaration
11383 then
11384 Set_Is_Public (Id);
11385 end if;
11386 end Set_Public_Status;
11387
11388 -----------------------------
11389 -- Set_Referenced_Modified --
11390 -----------------------------
11391
11392 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
11393 Pref : Node_Id;
11394
11395 begin
11396 -- Deal with indexed or selected component where prefix is modified
11397
11398 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
11399 Pref := Prefix (N);
11400
11401 -- If prefix is access type, then it is the designated object that is
11402 -- being modified, which means we have no entity to set the flag on.
11403
11404 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
11405 return;
11406
11407 -- Otherwise chase the prefix
11408
11409 else
11410 Set_Referenced_Modified (Pref, Out_Param);
11411 end if;
11412
11413 -- Otherwise see if we have an entity name (only other case to process)
11414
11415 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
11416 Set_Referenced_As_LHS (Entity (N), not Out_Param);
11417 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
11418 end if;
11419 end Set_Referenced_Modified;
11420
11421 ----------------------------
11422 -- Set_Scope_Is_Transient --
11423 ----------------------------
11424
11425 procedure Set_Scope_Is_Transient (V : Boolean := True) is
11426 begin
11427 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
11428 end Set_Scope_Is_Transient;
11429
11430 -------------------
11431 -- Set_Size_Info --
11432 -------------------
11433
11434 procedure Set_Size_Info (T1, T2 : Entity_Id) is
11435 begin
11436 -- We copy Esize, but not RM_Size, since in general RM_Size is
11437 -- subtype specific and does not get inherited by all subtypes.
11438
11439 Set_Esize (T1, Esize (T2));
11440 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
11441
11442 if Is_Discrete_Or_Fixed_Point_Type (T1)
11443 and then
11444 Is_Discrete_Or_Fixed_Point_Type (T2)
11445 then
11446 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
11447 end if;
11448
11449 Set_Alignment (T1, Alignment (T2));
11450 end Set_Size_Info;
11451
11452 --------------------
11453 -- Static_Boolean --
11454 --------------------
11455
11456 function Static_Boolean (N : Node_Id) return Uint is
11457 begin
11458 Analyze_And_Resolve (N, Standard_Boolean);
11459
11460 if N = Error
11461 or else Error_Posted (N)
11462 or else Etype (N) = Any_Type
11463 then
11464 return No_Uint;
11465 end if;
11466
11467 if Is_Static_Expression (N) then
11468 if not Raises_Constraint_Error (N) then
11469 return Expr_Value (N);
11470 else
11471 return No_Uint;
11472 end if;
11473
11474 elsif Etype (N) = Any_Type then
11475 return No_Uint;
11476
11477 else
11478 Flag_Non_Static_Expr
11479 ("static boolean expression required here", N);
11480 return No_Uint;
11481 end if;
11482 end Static_Boolean;
11483
11484 --------------------
11485 -- Static_Integer --
11486 --------------------
11487
11488 function Static_Integer (N : Node_Id) return Uint is
11489 begin
11490 Analyze_And_Resolve (N, Any_Integer);
11491
11492 if N = Error
11493 or else Error_Posted (N)
11494 or else Etype (N) = Any_Type
11495 then
11496 return No_Uint;
11497 end if;
11498
11499 if Is_Static_Expression (N) then
11500 if not Raises_Constraint_Error (N) then
11501 return Expr_Value (N);
11502 else
11503 return No_Uint;
11504 end if;
11505
11506 elsif Etype (N) = Any_Type then
11507 return No_Uint;
11508
11509 else
11510 Flag_Non_Static_Expr
11511 ("static integer expression required here", N);
11512 return No_Uint;
11513 end if;
11514 end Static_Integer;
11515
11516 --------------------------
11517 -- Statically_Different --
11518 --------------------------
11519
11520 function Statically_Different (E1, E2 : Node_Id) return Boolean is
11521 R1 : constant Node_Id := Get_Referenced_Object (E1);
11522 R2 : constant Node_Id := Get_Referenced_Object (E2);
11523 begin
11524 return Is_Entity_Name (R1)
11525 and then Is_Entity_Name (R2)
11526 and then Entity (R1) /= Entity (R2)
11527 and then not Is_Formal (Entity (R1))
11528 and then not Is_Formal (Entity (R2));
11529 end Statically_Different;
11530
11531 -----------------------------
11532 -- Subprogram_Access_Level --
11533 -----------------------------
11534
11535 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
11536 begin
11537 if Present (Alias (Subp)) then
11538 return Subprogram_Access_Level (Alias (Subp));
11539 else
11540 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
11541 end if;
11542 end Subprogram_Access_Level;
11543
11544 -----------------
11545 -- Trace_Scope --
11546 -----------------
11547
11548 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
11549 begin
11550 if Debug_Flag_W then
11551 for J in 0 .. Scope_Stack.Last loop
11552 Write_Str (" ");
11553 end loop;
11554
11555 Write_Str (Msg);
11556 Write_Name (Chars (E));
11557 Write_Str (" from ");
11558 Write_Location (Sloc (N));
11559 Write_Eol;
11560 end if;
11561 end Trace_Scope;
11562
11563 -----------------------
11564 -- Transfer_Entities --
11565 -----------------------
11566
11567 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
11568 Ent : Entity_Id := First_Entity (From);
11569
11570 begin
11571 if No (Ent) then
11572 return;
11573 end if;
11574
11575 if (Last_Entity (To)) = Empty then
11576 Set_First_Entity (To, Ent);
11577 else
11578 Set_Next_Entity (Last_Entity (To), Ent);
11579 end if;
11580
11581 Set_Last_Entity (To, Last_Entity (From));
11582
11583 while Present (Ent) loop
11584 Set_Scope (Ent, To);
11585
11586 if not Is_Public (Ent) then
11587 Set_Public_Status (Ent);
11588
11589 if Is_Public (Ent)
11590 and then Ekind (Ent) = E_Record_Subtype
11591
11592 then
11593 -- The components of the propagated Itype must be public
11594 -- as well.
11595
11596 declare
11597 Comp : Entity_Id;
11598 begin
11599 Comp := First_Entity (Ent);
11600 while Present (Comp) loop
11601 Set_Is_Public (Comp);
11602 Next_Entity (Comp);
11603 end loop;
11604 end;
11605 end if;
11606 end if;
11607
11608 Next_Entity (Ent);
11609 end loop;
11610
11611 Set_First_Entity (From, Empty);
11612 Set_Last_Entity (From, Empty);
11613 end Transfer_Entities;
11614
11615 -----------------------
11616 -- Type_Access_Level --
11617 -----------------------
11618
11619 function Type_Access_Level (Typ : Entity_Id) return Uint is
11620 Btyp : Entity_Id;
11621
11622 begin
11623 Btyp := Base_Type (Typ);
11624
11625 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
11626 -- simply use the level where the type is declared. This is true for
11627 -- stand-alone object declarations, and for anonymous access types
11628 -- associated with components the level is the same as that of the
11629 -- enclosing composite type. However, special treatment is needed for
11630 -- the cases of access parameters, return objects of an anonymous access
11631 -- type, and, in Ada 95, access discriminants of limited types.
11632
11633 if Ekind (Btyp) in Access_Kind then
11634 if Ekind (Btyp) = E_Anonymous_Access_Type then
11635
11636 -- If the type is a nonlocal anonymous access type (such as for
11637 -- an access parameter) we treat it as being declared at the
11638 -- library level to ensure that names such as X.all'access don't
11639 -- fail static accessibility checks.
11640
11641 if not Is_Local_Anonymous_Access (Typ) then
11642 return Scope_Depth (Standard_Standard);
11643
11644 -- If this is a return object, the accessibility level is that of
11645 -- the result subtype of the enclosing function. The test here is
11646 -- little complicated, because we have to account for extended
11647 -- return statements that have been rewritten as blocks, in which
11648 -- case we have to find and the Is_Return_Object attribute of the
11649 -- itype's associated object. It would be nice to find a way to
11650 -- simplify this test, but it doesn't seem worthwhile to add a new
11651 -- flag just for purposes of this test. ???
11652
11653 elsif Ekind (Scope (Btyp)) = E_Return_Statement
11654 or else
11655 (Is_Itype (Btyp)
11656 and then Nkind (Associated_Node_For_Itype (Btyp)) =
11657 N_Object_Declaration
11658 and then Is_Return_Object
11659 (Defining_Identifier
11660 (Associated_Node_For_Itype (Btyp))))
11661 then
11662 declare
11663 Scop : Entity_Id;
11664
11665 begin
11666 Scop := Scope (Scope (Btyp));
11667 while Present (Scop) loop
11668 exit when Ekind (Scop) = E_Function;
11669 Scop := Scope (Scop);
11670 end loop;
11671
11672 -- Treat the return object's type as having the level of the
11673 -- function's result subtype (as per RM05-6.5(5.3/2)).
11674
11675 return Type_Access_Level (Etype (Scop));
11676 end;
11677 end if;
11678 end if;
11679
11680 Btyp := Root_Type (Btyp);
11681
11682 -- The accessibility level of anonymous access types associated with
11683 -- discriminants is that of the current instance of the type, and
11684 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
11685
11686 -- AI-402: access discriminants have accessibility based on the
11687 -- object rather than the type in Ada 2005, so the above paragraph
11688 -- doesn't apply.
11689
11690 -- ??? Needs completion with rules from AI-416
11691
11692 if Ada_Version <= Ada_95
11693 and then Ekind (Typ) = E_Anonymous_Access_Type
11694 and then Present (Associated_Node_For_Itype (Typ))
11695 and then Nkind (Associated_Node_For_Itype (Typ)) =
11696 N_Discriminant_Specification
11697 then
11698 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
11699 end if;
11700 end if;
11701
11702 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
11703 end Type_Access_Level;
11704
11705 --------------------------
11706 -- Unit_Declaration_Node --
11707 --------------------------
11708
11709 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is
11710 N : Node_Id := Parent (Unit_Id);
11711
11712 begin
11713 -- Predefined operators do not have a full function declaration
11714
11715 if Ekind (Unit_Id) = E_Operator then
11716 return N;
11717 end if;
11718
11719 -- Isn't there some better way to express the following ???
11720
11721 while Nkind (N) /= N_Abstract_Subprogram_Declaration
11722 and then Nkind (N) /= N_Formal_Package_Declaration
11723 and then Nkind (N) /= N_Function_Instantiation
11724 and then Nkind (N) /= N_Generic_Package_Declaration
11725 and then Nkind (N) /= N_Generic_Subprogram_Declaration
11726 and then Nkind (N) /= N_Package_Declaration
11727 and then Nkind (N) /= N_Package_Body
11728 and then Nkind (N) /= N_Package_Instantiation
11729 and then Nkind (N) /= N_Package_Renaming_Declaration
11730 and then Nkind (N) /= N_Procedure_Instantiation
11731 and then Nkind (N) /= N_Protected_Body
11732 and then Nkind (N) /= N_Subprogram_Declaration
11733 and then Nkind (N) /= N_Subprogram_Body
11734 and then Nkind (N) /= N_Subprogram_Body_Stub
11735 and then Nkind (N) /= N_Subprogram_Renaming_Declaration
11736 and then Nkind (N) /= N_Task_Body
11737 and then Nkind (N) /= N_Task_Type_Declaration
11738 and then Nkind (N) not in N_Formal_Subprogram_Declaration
11739 and then Nkind (N) not in N_Generic_Renaming_Declaration
11740 loop
11741 N := Parent (N);
11742 pragma Assert (Present (N));
11743 end loop;
11744
11745 return N;
11746 end Unit_Declaration_Node;
11747
11748 ---------------------
11749 -- Unit_Is_Visible --
11750 ---------------------
11751
11752 function Unit_Is_Visible (U : Entity_Id) return Boolean is
11753 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
11754 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
11755
11756 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
11757 -- For a child unit, check whether unit appears in a with_clause
11758 -- of a parent.
11759
11760 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
11761 -- Scan the context clause of one compilation unit looking for a
11762 -- with_clause for the unit in question.
11763
11764 ----------------------------
11765 -- Unit_In_Parent_Context --
11766 ----------------------------
11767
11768 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
11769 begin
11770 if Unit_In_Context (Par_Unit) then
11771 return True;
11772
11773 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
11774 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
11775
11776 else
11777 return False;
11778 end if;
11779 end Unit_In_Parent_Context;
11780
11781 ---------------------
11782 -- Unit_In_Context --
11783 ---------------------
11784
11785 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
11786 Clause : Node_Id;
11787
11788 begin
11789 Clause := First (Context_Items (Comp_Unit));
11790 while Present (Clause) loop
11791 if Nkind (Clause) = N_With_Clause then
11792 if Library_Unit (Clause) = U then
11793 return True;
11794
11795 -- The with_clause may denote a renaming of the unit we are
11796 -- looking for, eg. Text_IO which renames Ada.Text_IO.
11797
11798 elsif
11799 Renamed_Entity (Entity (Name (Clause))) =
11800 Defining_Entity (Unit (U))
11801 then
11802 return True;
11803 end if;
11804 end if;
11805
11806 Next (Clause);
11807 end loop;
11808
11809 return False;
11810 end Unit_In_Context;
11811
11812 -- Start of processing for Unit_Is_Visible
11813
11814 begin
11815 -- The currrent unit is directly visible.
11816
11817 if Curr = U then
11818 return True;
11819
11820 elsif Unit_In_Context (Curr) then
11821 return True;
11822
11823 -- If the current unit is a body, check the context of the spec.
11824
11825 elsif Nkind (Unit (Curr)) = N_Package_Body
11826 or else
11827 (Nkind (Unit (Curr)) = N_Subprogram_Body
11828 and then not Acts_As_Spec (Unit (Curr)))
11829 then
11830 if Unit_In_Context (Library_Unit (Curr)) then
11831 return True;
11832 end if;
11833 end if;
11834
11835 -- If the spec is a child unit, examine the parents.
11836
11837 if Is_Child_Unit (Curr_Entity) then
11838 if Nkind (Unit (Curr)) in N_Unit_Body then
11839 return
11840 Unit_In_Parent_Context
11841 (Parent_Spec (Unit (Library_Unit (Curr))));
11842 else
11843 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
11844 end if;
11845
11846 else
11847 return False;
11848 end if;
11849 end Unit_Is_Visible;
11850
11851 ------------------------------
11852 -- Universal_Interpretation --
11853 ------------------------------
11854
11855 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
11856 Index : Interp_Index;
11857 It : Interp;
11858
11859 begin
11860 -- The argument may be a formal parameter of an operator or subprogram
11861 -- with multiple interpretations, or else an expression for an actual.
11862
11863 if Nkind (Opnd) = N_Defining_Identifier
11864 or else not Is_Overloaded (Opnd)
11865 then
11866 if Etype (Opnd) = Universal_Integer
11867 or else Etype (Opnd) = Universal_Real
11868 then
11869 return Etype (Opnd);
11870 else
11871 return Empty;
11872 end if;
11873
11874 else
11875 Get_First_Interp (Opnd, Index, It);
11876 while Present (It.Typ) loop
11877 if It.Typ = Universal_Integer
11878 or else It.Typ = Universal_Real
11879 then
11880 return It.Typ;
11881 end if;
11882
11883 Get_Next_Interp (Index, It);
11884 end loop;
11885
11886 return Empty;
11887 end if;
11888 end Universal_Interpretation;
11889
11890 ---------------
11891 -- Unqualify --
11892 ---------------
11893
11894 function Unqualify (Expr : Node_Id) return Node_Id is
11895 begin
11896 -- Recurse to handle unlikely case of multiple levels of qualification
11897
11898 if Nkind (Expr) = N_Qualified_Expression then
11899 return Unqualify (Expression (Expr));
11900
11901 -- Normal case, not a qualified expression
11902
11903 else
11904 return Expr;
11905 end if;
11906 end Unqualify;
11907
11908 -----------------------
11909 -- Visible_Ancestors --
11910 -----------------------
11911
11912 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
11913 List_1 : Elist_Id;
11914 List_2 : Elist_Id;
11915 Elmt : Elmt_Id;
11916
11917 begin
11918 pragma Assert (Is_Record_Type (Typ)
11919 and then Is_Tagged_Type (Typ));
11920
11921 -- Collect all the parents and progenitors of Typ. If the full-view of
11922 -- private parents and progenitors is available then it is used to
11923 -- generate the list of visible ancestors; otherwise their partial
11924 -- view is added to the resulting list.
11925
11926 Collect_Parents
11927 (T => Typ,
11928 List => List_1,
11929 Use_Full_View => True);
11930
11931 Collect_Interfaces
11932 (T => Typ,
11933 Ifaces_List => List_2,
11934 Exclude_Parents => True,
11935 Use_Full_View => True);
11936
11937 -- Join the two lists. Avoid duplications because an interface may
11938 -- simultaneously be parent and progenitor of a type.
11939
11940 Elmt := First_Elmt (List_2);
11941 while Present (Elmt) loop
11942 Append_Unique_Elmt (Node (Elmt), List_1);
11943 Next_Elmt (Elmt);
11944 end loop;
11945
11946 return List_1;
11947 end Visible_Ancestors;
11948
11949 ----------------------
11950 -- Within_Init_Proc --
11951 ----------------------
11952
11953 function Within_Init_Proc return Boolean is
11954 S : Entity_Id;
11955
11956 begin
11957 S := Current_Scope;
11958 while not Is_Overloadable (S) loop
11959 if S = Standard_Standard then
11960 return False;
11961 else
11962 S := Scope (S);
11963 end if;
11964 end loop;
11965
11966 return Is_Init_Proc (S);
11967 end Within_Init_Proc;
11968
11969 ----------------
11970 -- Wrong_Type --
11971 ----------------
11972
11973 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
11974 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
11975 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
11976
11977 function Has_One_Matching_Field return Boolean;
11978 -- Determines if Expec_Type is a record type with a single component or
11979 -- discriminant whose type matches the found type or is one dimensional
11980 -- array whose component type matches the found type.
11981
11982 ----------------------------
11983 -- Has_One_Matching_Field --
11984 ----------------------------
11985
11986 function Has_One_Matching_Field return Boolean is
11987 E : Entity_Id;
11988
11989 begin
11990 if Is_Array_Type (Expec_Type)
11991 and then Number_Dimensions (Expec_Type) = 1
11992 and then
11993 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
11994 then
11995 return True;
11996
11997 elsif not Is_Record_Type (Expec_Type) then
11998 return False;
11999
12000 else
12001 E := First_Entity (Expec_Type);
12002 loop
12003 if No (E) then
12004 return False;
12005
12006 elsif (Ekind (E) /= E_Discriminant
12007 and then Ekind (E) /= E_Component)
12008 or else (Chars (E) = Name_uTag
12009 or else Chars (E) = Name_uParent)
12010 then
12011 Next_Entity (E);
12012
12013 else
12014 exit;
12015 end if;
12016 end loop;
12017
12018 if not Covers (Etype (E), Found_Type) then
12019 return False;
12020
12021 elsif Present (Next_Entity (E)) then
12022 return False;
12023
12024 else
12025 return True;
12026 end if;
12027 end if;
12028 end Has_One_Matching_Field;
12029
12030 -- Start of processing for Wrong_Type
12031
12032 begin
12033 -- Don't output message if either type is Any_Type, or if a message
12034 -- has already been posted for this node. We need to do the latter
12035 -- check explicitly (it is ordinarily done in Errout), because we
12036 -- are using ! to force the output of the error messages.
12037
12038 if Expec_Type = Any_Type
12039 or else Found_Type = Any_Type
12040 or else Error_Posted (Expr)
12041 then
12042 return;
12043
12044 -- In an instance, there is an ongoing problem with completion of
12045 -- type derived from private types. Their structure is what Gigi
12046 -- expects, but the Etype is the parent type rather than the
12047 -- derived private type itself. Do not flag error in this case. The
12048 -- private completion is an entity without a parent, like an Itype.
12049 -- Similarly, full and partial views may be incorrect in the instance.
12050 -- There is no simple way to insure that it is consistent ???
12051
12052 elsif In_Instance then
12053 if Etype (Etype (Expr)) = Etype (Expected_Type)
12054 and then
12055 (Has_Private_Declaration (Expected_Type)
12056 or else Has_Private_Declaration (Etype (Expr)))
12057 and then No (Parent (Expected_Type))
12058 then
12059 return;
12060 end if;
12061 end if;
12062
12063 -- An interesting special check. If the expression is parenthesized
12064 -- and its type corresponds to the type of the sole component of the
12065 -- expected record type, or to the component type of the expected one
12066 -- dimensional array type, then assume we have a bad aggregate attempt.
12067
12068 if Nkind (Expr) in N_Subexpr
12069 and then Paren_Count (Expr) /= 0
12070 and then Has_One_Matching_Field
12071 then
12072 Error_Msg_N ("positional aggregate cannot have one component", Expr);
12073
12074 -- Another special check, if we are looking for a pool-specific access
12075 -- type and we found an E_Access_Attribute_Type, then we have the case
12076 -- of an Access attribute being used in a context which needs a pool-
12077 -- specific type, which is never allowed. The one extra check we make
12078 -- is that the expected designated type covers the Found_Type.
12079
12080 elsif Is_Access_Type (Expec_Type)
12081 and then Ekind (Found_Type) = E_Access_Attribute_Type
12082 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
12083 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
12084 and then Covers
12085 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
12086 then
12087 Error_Msg_N -- CODEFIX
12088 ("result must be general access type!", Expr);
12089 Error_Msg_NE -- CODEFIX
12090 ("add ALL to }!", Expr, Expec_Type);
12091
12092 -- Another special check, if the expected type is an integer type,
12093 -- but the expression is of type System.Address, and the parent is
12094 -- an addition or subtraction operation whose left operand is the
12095 -- expression in question and whose right operand is of an integral
12096 -- type, then this is an attempt at address arithmetic, so give
12097 -- appropriate message.
12098
12099 elsif Is_Integer_Type (Expec_Type)
12100 and then Is_RTE (Found_Type, RE_Address)
12101 and then (Nkind (Parent (Expr)) = N_Op_Add
12102 or else
12103 Nkind (Parent (Expr)) = N_Op_Subtract)
12104 and then Expr = Left_Opnd (Parent (Expr))
12105 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
12106 then
12107 Error_Msg_N
12108 ("address arithmetic not predefined in package System",
12109 Parent (Expr));
12110 Error_Msg_N
12111 ("\possible missing with/use of System.Storage_Elements",
12112 Parent (Expr));
12113 return;
12114
12115 -- If the expected type is an anonymous access type, as for access
12116 -- parameters and discriminants, the error is on the designated types.
12117
12118 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
12119 if Comes_From_Source (Expec_Type) then
12120 Error_Msg_NE ("expected}!", Expr, Expec_Type);
12121 else
12122 Error_Msg_NE
12123 ("expected an access type with designated}",
12124 Expr, Designated_Type (Expec_Type));
12125 end if;
12126
12127 if Is_Access_Type (Found_Type)
12128 and then not Comes_From_Source (Found_Type)
12129 then
12130 Error_Msg_NE
12131 ("\\found an access type with designated}!",
12132 Expr, Designated_Type (Found_Type));
12133 else
12134 if From_With_Type (Found_Type) then
12135 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
12136 Error_Msg_Qual_Level := 99;
12137 Error_Msg_NE -- CODEFIX
12138 ("\\missing `WITH &;", Expr, Scope (Found_Type));
12139 Error_Msg_Qual_Level := 0;
12140 else
12141 Error_Msg_NE ("found}!", Expr, Found_Type);
12142 end if;
12143 end if;
12144
12145 -- Normal case of one type found, some other type expected
12146
12147 else
12148 -- If the names of the two types are the same, see if some number
12149 -- of levels of qualification will help. Don't try more than three
12150 -- levels, and if we get to standard, it's no use (and probably
12151 -- represents an error in the compiler) Also do not bother with
12152 -- internal scope names.
12153
12154 declare
12155 Expec_Scope : Entity_Id;
12156 Found_Scope : Entity_Id;
12157
12158 begin
12159 Expec_Scope := Expec_Type;
12160 Found_Scope := Found_Type;
12161
12162 for Levels in Int range 0 .. 3 loop
12163 if Chars (Expec_Scope) /= Chars (Found_Scope) then
12164 Error_Msg_Qual_Level := Levels;
12165 exit;
12166 end if;
12167
12168 Expec_Scope := Scope (Expec_Scope);
12169 Found_Scope := Scope (Found_Scope);
12170
12171 exit when Expec_Scope = Standard_Standard
12172 or else Found_Scope = Standard_Standard
12173 or else not Comes_From_Source (Expec_Scope)
12174 or else not Comes_From_Source (Found_Scope);
12175 end loop;
12176 end;
12177
12178 if Is_Record_Type (Expec_Type)
12179 and then Present (Corresponding_Remote_Type (Expec_Type))
12180 then
12181 Error_Msg_NE ("expected}!", Expr,
12182 Corresponding_Remote_Type (Expec_Type));
12183 else
12184 Error_Msg_NE ("expected}!", Expr, Expec_Type);
12185 end if;
12186
12187 if Is_Entity_Name (Expr)
12188 and then Is_Package_Or_Generic_Package (Entity (Expr))
12189 then
12190 Error_Msg_N ("\\found package name!", Expr);
12191
12192 elsif Is_Entity_Name (Expr)
12193 and then
12194 (Ekind (Entity (Expr)) = E_Procedure
12195 or else
12196 Ekind (Entity (Expr)) = E_Generic_Procedure)
12197 then
12198 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
12199 Error_Msg_N
12200 ("found procedure name, possibly missing Access attribute!",
12201 Expr);
12202 else
12203 Error_Msg_N
12204 ("\\found procedure name instead of function!", Expr);
12205 end if;
12206
12207 elsif Nkind (Expr) = N_Function_Call
12208 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
12209 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
12210 and then No (Parameter_Associations (Expr))
12211 then
12212 Error_Msg_N
12213 ("found function name, possibly missing Access attribute!",
12214 Expr);
12215
12216 -- Catch common error: a prefix or infix operator which is not
12217 -- directly visible because the type isn't.
12218
12219 elsif Nkind (Expr) in N_Op
12220 and then Is_Overloaded (Expr)
12221 and then not Is_Immediately_Visible (Expec_Type)
12222 and then not Is_Potentially_Use_Visible (Expec_Type)
12223 and then not In_Use (Expec_Type)
12224 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
12225 then
12226 Error_Msg_N
12227 ("operator of the type is not directly visible!", Expr);
12228
12229 elsif Ekind (Found_Type) = E_Void
12230 and then Present (Parent (Found_Type))
12231 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
12232 then
12233 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
12234
12235 else
12236 Error_Msg_NE ("\\found}!", Expr, Found_Type);
12237 end if;
12238
12239 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
12240 -- of the same modular type, and (M1 and M2) = 0 was intended.
12241
12242 if Expec_Type = Standard_Boolean
12243 and then Is_Modular_Integer_Type (Found_Type)
12244 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
12245 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
12246 then
12247 declare
12248 Op : constant Node_Id := Right_Opnd (Parent (Expr));
12249 L : constant Node_Id := Left_Opnd (Op);
12250 R : constant Node_Id := Right_Opnd (Op);
12251 begin
12252 -- The case for the message is when the left operand of the
12253 -- comparison is the same modular type, or when it is an
12254 -- integer literal (or other universal integer expression),
12255 -- which would have been typed as the modular type if the
12256 -- parens had been there.
12257
12258 if (Etype (L) = Found_Type
12259 or else
12260 Etype (L) = Universal_Integer)
12261 and then Is_Integer_Type (Etype (R))
12262 then
12263 Error_Msg_N
12264 ("\\possible missing parens for modular operation", Expr);
12265 end if;
12266 end;
12267 end if;
12268
12269 -- Reset error message qualification indication
12270
12271 Error_Msg_Qual_Level := 0;
12272 end if;
12273 end Wrong_Type;
12274
12275 end Sem_Util;