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